From ed3770792a7a9ce698999de42ebb6150f5ee5e9e Mon Sep 17 00:00:00 2001 From: lishid Date: Sun, 25 Oct 2020 16:55:59 -0400 Subject: [PATCH] Initial commit! --- .gitignore | 11 + README.md | 35 ++ main.ts | 77 +++ manifest.json | 8 + obsidian.d.ts | 1453 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 18 + styles.css | 4 + tsconfig.json | 21 + 8 files changed, 1627 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 main.ts create mode 100644 manifest.json create mode 100644 obsidian.d.ts create mode 100644 package.json create mode 100644 styles.css create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7b7242 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Intellij +*.iml +.idea + +# npm +node_modules +package-lock.json + +# build +main.js +*.js.map \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8adca48 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +### Obsidian Sample Plugin + +This is a sample plugin for Obsidian (https://obsidian.md). + +This project uses Typescript to provide type checking and documentation. +The repo contains the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains JSDoc comments describing what it does. + +#### How to use + +- Clone this repo. +- `npm i` or `yarn` to install dependencies +- `npm run dev` to start compilation in watch mode. + +#### How to install the plugin + +- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `vault/.obsidian/plugins/plugin-id/`. + +#### Plugin structure + +`manifest.json` + + - `id` the ID of your plugin. + - `name` the display name of your plugin. + - `description` the long description of your plugin. + - `isDesktopOnly` whether your plugin uses NodeJS or Electron APIs. + - `js` (optional) an alternative js entry point. Defaults to `main.js` + - `css` (optional) a css file that should be injected. Defaults to `styles.css` + + `main.js` + + - This is the main entry point of your plugin. + - Import any Obsidian API using `require('obsidian')` + - Import NodeJS or Electron API using `require('fs')` or `require('electron')` + - Must export a default class which extends `CustomPlugin` + \ No newline at end of file diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..575b955 --- /dev/null +++ b/main.ts @@ -0,0 +1,77 @@ +import { App, CustomPlugin, Modal, Notice, PluginSettingTab, Setting } from 'obsidian'; + +export default class MyPlugin extends CustomPlugin { + onInit() { + + } + + onload() { + console.log('loading plugin'); + + this.addRibbonIcon('dice', 'Sample Plugin', () => { + new Notice('This is a notice!'); + }); + + this.addStatusBarItem().setText('Status Bar Text'); + + this.addCommand({ + id: 'open-sample-modal', + name: 'Open Sample Modal', + // callback: () => { + // console.log('Simple Callback'); + // }, + checkCallback: (checking: boolean) => { + let leaf = this.app.workspace.activeLeaf; + if (leaf) { + if (!checking) { + new SampleModal(this.app).open(); + } + return true; + } + return false; + } + }); + + this.addSettingTab(new SampleSettingTab(this.app, this)); + } + + onunload() { + console.log('unloading plugin'); + } +} + +class SampleModal extends Modal { + constructor(app: App) { + super(app); + } + + onOpen() { + let {contentEl} = this; + contentEl.setText('Woah!'); + } + + onClose() { + let {contentEl} = this; + contentEl.empty(); + } +} + +class SampleSettingTab extends PluginSettingTab { + display(): void { + let {containerEl} = this; + + containerEl.empty(); + + containerEl.createEl('h2', {text: 'Settings for my awesome plugin.'}); + + new Setting(containerEl) + .setName('Setting #1') + .setDesc('It\'s a secret') + .addText(text => text.setPlaceholder('Enter your secret') + .setValue('') + .onChange((value) => { + console.log('Secret: ' + value); + })); + + } +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..ea4bf3d --- /dev/null +++ b/manifest.json @@ -0,0 +1,8 @@ +{ + "id": "obsidian-sample-plugin", + "name": "Sample Plugin", + "description": "This is a sample plugin for Obsidian (https://obsidian.md)", + "isDesktopOnly": false, + "js": "main.js", + "css": "styles.css" +} \ No newline at end of file diff --git a/obsidian.d.ts b/obsidian.d.ts new file mode 100644 index 0000000..7edabc1 --- /dev/null +++ b/obsidian.d.ts @@ -0,0 +1,1453 @@ +import * as CodeMirror from 'codemirror'; + +declare global { + interface ObjectConstructor { + isEmpty(object: Record): boolean; + each(object: { + [key: string]: T; + }, callback: (value: T, key?: string) => boolean | void, context?: any): boolean; + assign(target: any, ...sources: any): any; + entries(obj: any): any[]; + } +} +declare global { + interface Array { + first(): T; + last(): T; + contains(target: T): boolean; + remove(target: T): void; + } +} +declare global { + interface Math { + clamp(value: number, min: number, max: number): number; + square(value: number): number; + } +} +declare global { + interface StringConstructor { + isString(obj: any): obj is string; + } + interface String { + contains(target: string): boolean; + startsWith(searchString: string, position?: number): boolean; + endsWith(target: string, length?: number): boolean; + format(...args: string[]): string; + } +} +declare global { + interface NumberConstructor { + isNumber(obj: any): obj is number; + } +} +declare global { + interface Window { + isBoolean(obj: any): obj is boolean; + } + function isBoolean(obj: any): obj is boolean; +} +declare global { + interface Element { + getText(): string; + setText(val: string): void; + } +} +declare global { + interface Element { + addClass(...classes: string[]): void; + addClasses(classes: string[]): void; + removeClass(...classes: string[]): void; + removeClasses(classes: string[]): void; + toggleClass(classes: string | string[], value: boolean): void; + hasClass(cls: string): boolean; + } +} +declare global { + interface Node { + detach(): void; + empty(): void; + insertAfter(other: Node): void; + indexOf(other: Node): number; + setChildrenInPlace(children: Node[]): void; + appendText(val: string): void; + } +} +declare global { + interface Element extends Node { + setAttr(qualifiedName: string, value: string | number | boolean): void; + setAttrs(obj: { + [key: string]: string | number | boolean; + }): void; + getAttr(qualifiedName: string): string; + matchParent(selector: string, lastParent?: Element): Element | null; + } +} +declare global { + interface HTMLElement extends Element { + show(): void; + hide(): void; + toggle(show: boolean): void; + } +} +declare global { + function fish(selector: string): HTMLElement; + function fishAll(selector: string): HTMLElement[]; + interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandlers, WindowEventHandlers, WindowLocalStorage, WindowOrWorkerGlobalScope, WindowSessionStorage { + fish(selector: string): HTMLElement; + fishAll(selector: string): HTMLElement[]; + ElementList: any; + } + interface Element extends Node { + find(selector: string): Element; + findAll(selector: string): HTMLElement[]; + findAllSelf(selector: string): HTMLElement[]; + } + interface HTMLElement extends Element { + find(selector: string): HTMLElement; + findAll(selector: string): HTMLElement[]; + findAllSelf(selector: string): HTMLElement[]; + } +} +declare global { + interface DomElementInfo { + /** + * The class to be assigned. Can be a space-separated string or an array of strings. + */ + cls?: string | string[]; + /** + * The textContent to be assigned. + */ + text?: string; + /** + * HTML attributes to be added. + */ + attr?: { + [key: string]: string | number | boolean; + }; + /** + * HTML title (for hover tooltip). + */ + title?: string; + /** + * The parent element to be assigned to. + */ + parent?: Node; + value?: string; + type?: string; + prepend?: boolean; + href?: string; + } + interface Node { + /** + * Create an element and append it to this node. + */ + createEl(tag: K, o?: DomElementInfo, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K]; + } + function createEl(tag: K, o?: DomElementInfo, callback?: (el: HTMLElementTagNameMap[K]) => void): HTMLElementTagNameMap[K]; +} +interface EventListenerInfo { + selector: string; + listener: Function; + options?: boolean | AddEventListenerOptions; + callback: Function; +} +declare global { + interface HTMLElement extends Element { + _EVENTS?: { + [K in keyof HTMLElementEventMap]?: EventListenerInfo[]; + }; + on(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; + off(this: HTMLElement, type: K, selector: string, listener: (this: HTMLElement, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; + onClickEvent(this: HTMLElement, listener: (this: HTMLElement, ev: MouseEvent) => any, options?: boolean | AddEventListenerOptions): void; + trigger(eventType: string): void; + } + interface Document { + _EVENTS?: { + [K in keyof HTMLElementEventMap]?: EventListenerInfo[]; + }; + on(this: Document, type: K, selector: string, listener: (this: Document, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; + off(this: Document, type: K, selector: string, listener: (this: Document, ev: HTMLElementEventMap[K], delegateTarget: HTMLElement) => any, options?: boolean | AddEventListenerOptions): void; + } +} +export interface AjaxOptions { + method?: 'GET' | 'POST'; + url: string; + success?: (response: any, req: XMLHttpRequest) => any; + error?: (error: any, req: XMLHttpRequest) => any; + data?: object | string | ArrayBuffer; + headers?: Record; + withCredentials?: boolean; +} +declare global { + function ajax(options: AjaxOptions): void; + function ajaxPromise(options: AjaxOptions): Promise; + function ready(fn: () => any): void; +} +//# sourceMappingURL=enhance.d.ts.map +/** + * @public + */ +export class AbstractTextComponent extends ValueComponent { + /** + * @public + */ + inputEl: T; + + /** + * @public + */ + constructor(setting: Setting, inputEl: T); + /** + * @public + */ + getValue(): string; + /** + * @public + */ + setValue(value: string): this; + /** + * @public + */ + setPlaceholder(placeholder: string): this; + /** + * @public + */ + onChanged(): void; + /** + * @public + */ + onChange(callback: (value: string) => any): this; +} + +/** + * @public + */ +export class App extends Events { + + /** + * @public + */ + workspace: Workspace; + + /** + * @public + */ + vault: Vault; + /** + * @public + */ + metadataCache: MetadataCache; + + /** + * @public + */ + on(name: 'codemirror', callback: (cm: CodeMirror.Editor) => any, ctx?: any): EventRef; +} + +/** + * @public + */ +export abstract class BaseComponent { + /** + * @public + */ + setting: Setting; + /** + * @public + */ + constructor(setting: Setting); + /** + * Facilitates chaining + * @public + */ + then(cb: (component: this) => any): this; +} + +/** + * @public + */ +export interface BlockCache { + +} + +/** + * @public + */ +export class ButtonComponent extends BaseComponent { + /** + * @public + */ + buttonEl: HTMLButtonElement; + + /** + * @public + */ + constructor(setting: Setting); + /** + * @public + */ + setCta(): this; + /** + * @public + */ + setButtonText(name: string): this; + /** + * @public + */ + setIcon(icon: string): this; + /** + * @public + */ + setClass(cls: string): this; + /** + * @public + */ + onClick(callback: () => any): this; +} + +/** + * @public + */ +export interface CachedMetadata { + +} + +/** + * @public + */ +export interface Command { + /** + * Globally unique ID to identify this command. + * @public + */ + id: string; + /** + * Human friendly name for searching. + * @public + */ + name: string; + /** + * Simple callback, triggered globally. + * @public + */ + callback?: () => any; + /** + * Complex callback, overrides the simple callback. + * If checking is true, then this should not perform any action. + * If checking is false, then it should check and perform the action. + * Must return whether this command can be executed at the moment. + * @public + */ + checkCallback?: (checking: boolean) => boolean; + /** + * Sets the default hotkey + * @public + */ + hotkeys?: Hotkey[]; +} + +/** + * @public + */ +export class Component { + + /** + * @public + */ + load(): void; + /** + * @public + * @virtual + */ + onload(): void; + /** + * @public + */ + unload(): void; + /** + * @public + * @virtual + */ + onunload(): void; + +} + +/** + * @public + */ +export abstract class CustomPlugin extends Component { + /** + * @public + */ + app: App; + /** + * @public + */ + manifest: PluginManifest; + /** + * @public + */ + constructor(app: App, manifest: PluginManifest); + /** + * @public + * @virtual + */ + onInit(): void; + /** + * @public + */ + addRibbonIcon(icon: string, title: string, callback: (evt: MouseEvent) => any): HTMLElement; + /** + * @public + */ + addStatusBarItem(): HTMLElement; + /** + * Register a command globally. The command id and name will be automatically prefixed with this plugin's id and name. + * @public + */ + addCommand(command: Command): Command; + /** + * @public + */ + addSettingTab(settingTab: PluginSettingTab): void; + /** + * @public + */ + registerView(type: string, viewCreator: ViewCreator): void; + /** + * @public + */ + registerExtensions(extensions: string[], viewType: string): void; + /** + * @public + */ + loadData(): Promise; + /** + * @public + */ + saveData(data: any): Promise; + +} + +/** + * @public + */ +export class DropdownComponent extends ValueComponent { + /** + * @public + */ + selectEl: HTMLSelectElement; + + /** + * @public + */ + constructor(setting: Setting); + /** + * @public + */ + addOption(value: string, display: string): this; + /** + * @public + */ + addOptions(options: Record): this; + /** + * @public + */ + getValue(): string; + /** + * @public + */ + setValue(value: string): this; + /** + * @public + */ + onChange(callback: (value: string) => any): this; +} + +/** + * @public + */ +export interface EmbedCache extends ReferenceCache { +} + +/** + * @public + */ +export interface EventRef { + +} + +/** + * @public + */ +export class Events { + + /** + * @public + */ + on(name: string, callback: (...data: any) => any, ctx?: any): EventRef; + /** + * @public + */ + off(name: string, callback: (...data: any) => any): void; + /** + * @public + */ + offref(ref: EventRef): void; + /** + * @public + */ + trigger(name: string, ...data: any[]): void; + /** + * @public + */ + tryTrigger(evt: EventRef, args: any[]): void; +} + +/** + * @public + */ +export class ExtraButtonComponent extends BaseComponent { + /** + * @public + */ + extraSettingsEl: HTMLElement; + + /** + * @public + */ + constructor(setting: Setting); + /** + * @public + */ + onClick(callback: () => any): this; +} + +/** + * @public + */ +export interface FileStats { + +} + +/** + * @public + */ +export interface HeadingCache { + +} + +/** + * @public + */ +export interface Hotkey { + +} + +/** + * @public + */ +export interface LinkCache extends ReferenceCache { +} + +/** + * @public + */ +export interface Loc { + +} + +/** + * @public + */ +export interface MarkdownPostProcessor { + +} + +/** + * @public + */ +export interface MarkdownPostProcessorContext { + +} + +/** + * @public + */ +export class MarkdownPreviewRenderer { + + /** + * @public + */ + static registerPostProcessor(postProcessor: MarkdownPostProcessor): void; + /** + * @public + */ + static unregisterPostProcessor(postProcessor: MarkdownPostProcessor): void; + +} + +/** + * @public + */ +export class MenuGroupDom { + + /** + * @public + */ + constructor(); + /** + * @public + */ + addItem(name: string, callback?: (evt: MouseEvent) => any, icon?: string): MenuItemDom; +} + +/** + * @public + */ +export class MenuItemDom { + + /** + * @public + */ + constructor(name: string, callback?: (evt: MouseEvent) => any, icon?: string); + /** + * @public + */ + setDisabled(disabled: boolean): void; + /** + * @public + */ + setActive(active: boolean): void; +} + +/** + * @public + */ +export class MetadataCache extends Events { + + /** + * @public + */ + getFileCache(file: TFile): CachedMetadata; + /** + * @public + */ + getCache(path: string): CachedMetadata; + +} + +/** + * @public + */ +export class Modal { + /** + * @public + */ + app: App; + + /** + * @public + */ + containerEl: HTMLElement; + + /** + * @public + */ + contentEl: HTMLElement; + /** + * @public + */ + constructor(app: App); + /** + * @public + */ + open(): void; + /** + * @public + */ + close(): void; + /** + * @public + */ + onOpen(): void; + /** + * @public + */ + onClose(): void; +} + +/** + * @public + */ +export class MomentFormatComponent extends TextComponent { + /** + * @public + */ + sampleEl: HTMLElement; + + /** + * @public + */ + constructor(setting: Setting); + /** + * Sets the default format when input is cleared. Also used for placeholder. + * @public + */ + setDefaultFormat(defaultFormat: string): this; + /** + * @public + */ + setSampleEl(sampleEl: HTMLElement): this; + /** + * @public + */ + setValue(value: string): this; + /** + * @public + */ + onChanged(): void; + /** + * @public + */ + updateSample(): void; +} + +/** + * @public + */ +export class Notice { + + /** + * @public + */ + constructor(message: string); +} + +/** + * @public + */ +export interface OpenViewState { + +} + +/** + * @public + */ +export interface PluginManifest { + +} + +/** + * @public + */ +export abstract class PluginSettingTab extends SettingTab { + + /** + * @public + */ + constructor(app: App, plugin: CustomPlugin); + /** + * @public + */ + load(): void; +} + +/** + * @public + */ +export interface Pos { + +} + +/** + * @public + */ +export interface ReferenceCache { + +} + +/** + * @public + */ +export class Scope { + +} + +/** + * @public + */ +export class Setting { + /** + * @public + */ + settingEl: HTMLElement; + /** + * @public + */ + infoEl: HTMLElement; + /** + * @public + */ + nameEl: HTMLElement; + /** + * @public + */ + descEl: HTMLElement; + /** + * @public + */ + controlEl: HTMLElement; + /** + * @public + */ + constructor(containerEl: HTMLElement); + /** + * @public + */ + setName(name: string): this; + /** + * @public + */ + setDesc(desc: string | DocumentFragment): this; + /** + * @public + */ + setClass(cls: string): this; + /** + * @public + */ + setTooltip(tooltip: string): this; + /** + * @public + */ + addButton(cb: (component: ButtonComponent) => any): this; + /** + * @public + */ + addExtraSetting(cb: (component: ExtraButtonComponent) => any): this; + /** + * @public + */ + addToggle(cb: (component: ToggleComponent) => any): this; + /** + * @public + */ + addText(cb: (component: TextComponent) => any): this; + /** + * @public + */ + addTextArea(cb: (component: TextAreaComponent) => any): this; + /** + * @public + */ + addMomentFormat(cb: (component: MomentFormatComponent) => any): this; + /** + * @public + */ + addDropdown(cb: (component: DropdownComponent) => any): this; + /** + * @public + */ + addSlider(cb: (component: SliderComponent) => any): this; +} + +/** + * @public + */ +export abstract class SettingTab { + + /** + * @public + */ + app: App; + + /** + * @public + */ + containerEl: HTMLElement; + + /** + * @public + */ + load(): void; + /** + * @public + */ + unload(): void; + /** + * @public + */ + open(): void; + /** + * @public + */ + close(): void; + /** + * @public + */ + abstract display(): void; +} + +/** + * @public + */ +export class SliderComponent extends ValueComponent { + /** + * @public + */ + sliderEl: HTMLInputElement; + + /** + * @public + */ + constructor(setting: Setting); + /** + * @public + */ + setLimits(min: number, max: number, step: number | 'any'): this; + /** + * @public + */ + getValue(): number; + /** + * @public + */ + setValue(value: number): this; + /** + * @public + */ + getValuePretty(): string; + /** + * @public + */ + setDynamicTooltip(): this; + /** + * @public + */ + showTooltip(): void; + /** + * @public + */ + onChange(callback: (value: number) => any): this; +} + +/** + * @public + */ +export type SplitDirection = 'vertical' | 'horizontal'; + +/** + * @public + */ +export abstract class TAbstractFile { + /** + * @public + */ + vault: Vault; + /** + * @public + */ + path: string; + /** + * @public + */ + name: string; + /** + * @public + */ + parent: TFolder; + +} + +/** + * @public + */ +export interface TagCache { + +} + +/** + * @public + */ +export class TextAreaComponent extends AbstractTextComponent { + /** + * @public + */ + constructor(setting: Setting); +} + +/** + * @public + */ +export class TextComponent extends AbstractTextComponent { + /** + * @public + */ + constructor(setting: Setting); +} + +/** + * @public + */ +export class TFile extends TAbstractFile { + /** + * @public + */ + stat: FileStats; + /** + * @public + */ + basename: string; + /** + * @public + */ + extension: string; + +} + +/** + * @public + */ +export class TFolder extends TAbstractFile { + /** + * @public + */ + children: TAbstractFile[]; + + /** + * @public + */ + isRoot(): boolean; + +} + +/** + * @public + */ +export class ToggleComponent extends ValueComponent { + /** + * @public + */ + toggleEl: HTMLElement; + + /** + * @public + */ + constructor(setting: Setting); + /** + * @public + */ + getValue(): boolean; + /** + * @public + */ + setValue(on: boolean): this; + /** + * @public + */ + onClick(): void; + /** + * @public + */ + onChange(callback: (value: boolean) => any): this; +} + +/** + * @public + */ +export abstract class ValueComponent extends BaseComponent { + /** + * @public + */ + registerOptionListener(listeners: Record T>, key: string): this; + /** + * @public + */ + abstract getValue(): T; + /** + * @public + */ + abstract setValue(value: T): this; +} + +/** + * @public + */ +export class Vault extends Events { + + /** + * @public + */ + getAbstractFileByPath(path: string): TAbstractFile; + + /** + * @public + */ + getRoot(): TFolder; + + /** + * @public + */ + create(normalizedPath: string, data: string): Promise; + /** + * @public + */ + createBinary(normalizedPath: string, data: ArrayBuffer): Promise; + /** + * @public + */ + createFolder(normalizedPath: string): Promise; + /** + * @public + */ + read(file: TFile): Promise; + /** + * @public + */ + cachedRead(file: TFile): Promise; + /** + * @public + */ + readBinary(file: TFile): Promise; + + /** + * @public + */ + getResourcePath(file: TFile): string; + /** + * @param file + * @param force Should attempt to delete folder even if it has hidden children + * @public + */ + delete(file: TAbstractFile, force?: boolean): Promise; + /** + * Tries to move to system trash. If that isn't successful/allowed, use local trash + * @param file + * @param system + * @public + */ + trash(file: TAbstractFile, system: boolean): Promise; + /** + * @public + */ + rename(file: TAbstractFile, normalizedNewPath: string): Promise; + /** + * @public + */ + modify(file: TFile, data: string): Promise; + /** + * @public + */ + modifyBinary(file: TFile, data: ArrayBuffer): Promise; + + /** + * @public + */ + copy(file: TFile, normalizedNewPath: string): Promise; + + /** + * @public + */ + getAllLoadedFiles(): TAbstractFile[]; + + /** + * @public + */ + static recurseChildren(root: TFolder, cb: (file: TAbstractFile) => any): void; + /** + * @public + */ + getMarkdownFiles(): TFile[]; + /** + * @public + */ + getFiles(): TFile[]; + + /** + * @public + */ + on(name: 'create', callback: (file: TAbstractFile) => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'modify', callback: (file: TAbstractFile) => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'delete', callback: (file: TAbstractFile) => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'rename', callback: (file: TAbstractFile, oldPath: string) => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'closed', callback: () => any, ctx?: any): EventRef; +} + +/** + * @public + */ +export abstract class View extends Component { + /** + * @public + */ + app: App; + /** + * @public + */ + icon: string; + /** + * @public + */ + navigation: boolean; + /** + * @public + */ + leaf: WorkspaceLeaf; + /** + * @public + */ + containerEl: HTMLElement; + /** + * @public + */ + constructor(leaf: WorkspaceLeaf); + /** + * @public + */ + open(containerEl: HTMLElement): Promise; + /** + * @public + */ + close(): Promise; + /** + * @public + */ + protected onOpen(): Promise; + /** + * @public + */ + protected onClose(): Promise; + /** + * @public + */ + abstract getViewType(): string; + /** + * @public + */ + getState(): any; + /** + * @public + */ + setState(state: any, result: ViewStateResult): Promise; + /** + * @public + */ + getEphemeralState(): any; + /** + * @public + */ + setEphemeralState(state: any): void; + /** + * @public + */ + getIcon(): string; + /** + * @public + */ + onResize(): void; + /** + * @public + */ + abstract getDisplayText(): string; + /** + * @public + */ + onHeaderMenu(menuGroup: MenuGroupDom): void; +} + +/** + * @public + */ +export type ViewCreator = (leaf: WorkspaceLeaf) => View; + +/** + * @public + */ +export interface ViewStateResult { + +} + +/** + * @public + */ +export class Workspace extends Events { + + /** + * @public + */ + activeLeaf: WorkspaceLeaf; + + /** + * @public + */ + requestSaveLayout: () => void; + /** + * @public + */ + requestSaveHistory: () => void; + + /** + * @public + */ + changeLayout(workspace: any): Promise; + + /** + * @public + */ + getLayout(): any; + + /** + * @public + */ + splitLeaf(source: WorkspaceItem, newLeaf: WorkspaceItem, direction?: SplitDirection, before?: boolean): void; + /** + * @public + */ + createLeafBySplit(leaf: WorkspaceLeaf, direction?: SplitDirection, before?: boolean): WorkspaceLeaf; + /** + * @public + */ + splitActiveLeaf(direction?: SplitDirection): WorkspaceLeaf; + /** + * @public + */ + splitLeafOrActive(leaf?: WorkspaceLeaf, direction?: SplitDirection): WorkspaceLeaf; + /** + * @public + */ + duplicateLeaf(leaf: WorkspaceLeaf, direction?: SplitDirection): Promise; + /** + * @public + */ + getUnpinnedLeaf(type?: string): WorkspaceLeaf; + /** + * @public + */ + getLeaf(newLeaf?: boolean): WorkspaceLeaf; + /** + * @public + */ + openLinkText(linktext: string, sourcePath: string, newLeaf?: boolean, openViewState?: OpenViewState): Promise; + + /** + * @public + */ + getLeafById(id: string): WorkspaceLeaf; + /** + * @public + */ + getGroupLeaves(group: string): WorkspaceLeaf[]; + /** + * @public + */ + getMostRecentLeaf(): WorkspaceLeaf; + /** + * @public + */ + getLeftLeaf(shouldSplit: boolean): WorkspaceLeaf; + /** + * @public + */ + getRightLeaf(shouldSplit: boolean): WorkspaceLeaf; + + /** + * @public + */ + iterateRootLeaves(callback: (leaf: WorkspaceLeaf) => any): void; + /** + * @public + */ + iterateAllLeaves(callback: (leaf: WorkspaceLeaf) => any): void; + /** + * @public + */ + getLeavesOfType(viewType: string): WorkspaceLeaf[]; + /** + * @public + */ + detachLeavesOfType(viewType: string): void; + + /** + * @public + */ + revealLeaf(leaf: WorkspaceLeaf): void; + /** + * @public + */ + getLastOpenFiles(): string[]; + + /** + * @public + */ + on(name: 'quick-preview', callback: (file: TFile, data: string) => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'resize', callback: () => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'click', callback: () => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'file-open', callback: (file: TFile) => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'layout-ready', callback: () => any, ctx?: any): EventRef; + /** + * @public + */ + on(name: 'css-change', callback: () => any, ctx?: any): EventRef; +} + +/** + * @public + */ +export abstract class WorkspaceItem extends Events { + +} + +/** + * @public + */ +export class WorkspaceLeaf extends WorkspaceItem { + +} + +/** + * @public + */ +export abstract class WorkspaceParent extends WorkspaceItem { + +} + +/** + * @public + */ +export class WorkspaceSidedock extends WorkspaceSplit { + +} + +/** + * @public + */ +export class WorkspaceSplit extends WorkspaceParent { + +} + +export { } diff --git a/package.json b/package.json new file mode 100644 index 0000000..ed9d8fa --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "obsidian-sample-plugin", + "version": "0.9.7", + "description": "This is a sample plugin for Obsidian (https://obsidian.md)", + "main": "main.js", + "scripts": { + "dev": "tsc --project tsconfig.json -w", + "build": "tsc --project tsconfig.json" + }, + "keywords": [], + "author": "", + "license": "MIT", + "devDependencies": { + "@types/codemirror": "0.0.98", + "@types/node": "^14.14.2", + "typescript": "^4.0.3" + } +} diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..cfd0fd7 --- /dev/null +++ b/styles.css @@ -0,0 +1,4 @@ +/* Sets all the text color to red! */ +body { + color: red; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..b13c45f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "CommonJS", + "target": "es5", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "lib": [ + "dom", + "es5", + "scripthost", + "es2015" + ] + }, + "include": [ + "**/*.ts" + ] +}