diff --git a/cspell.json b/cspell.json index 4f793bc2..97aec715 100644 --- a/cspell.json +++ b/cspell.json @@ -8,6 +8,7 @@ "autocompletions", "backlink", "backlinks", + "blinkfetch", "bodgy", "btime", "Callout", @@ -17,6 +18,7 @@ "csscache", "datetime", "Debouncer", + "dompurify", "dprint", "dragevent", "emacsy", @@ -26,17 +28,21 @@ "flexgrow", "Frameless", "Frontmatter", + "Haverbeke", "HTMLI", "Keydown", "Keymap", "keyof", "Keyscope", "lezer", + "linewise", "linkpath", "linktext", "localgraph", "localstorage", "Lucide", + "mapclear", + "Marijn", "mathjax", "metadatacache", "minifier", @@ -45,9 +51,11 @@ "Naumov", "nocheck", "nodenext", + "noremap", "obsdmd", "onunload", "Parens", + "PIXI", "Popout", "preapproved", "precompute", @@ -57,12 +65,14 @@ "reparent", "Sidedock", "tablecell", + "titlebar", "toggleable", "tsdoc", "Uncollapse", "uncollapsed", "unfocus", "Unindents", + "unmap", "Watchpath", "wikilink", "Wikilinks" diff --git a/package-lock.json b/package-lock.json index 7d4f33ec..11786fb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,14 +9,19 @@ "version": "2.2.1-beta.15", "license": "MIT", "devDependencies": { + "@capacitor/core": "^6.1.2", + "@codemirror/search": "^6.5.6", + "@codemirror/state": "^6.4.1", "@microsoft/api-extractor": "^7.47.9", "@tsconfig/strictest": "^2.0.5", "@types/node": "^18.17.0 || >=20.1.0", + "@types/turndown": "^5.0.5", "builtin-modules": "^4.0.0", "cspell": "^8.14.2", "dprint": "^0.47.2", "dts-bundle-generator": "^9.5.1", "esbuild": "^0.23.1", + "i18next": "^23.15.1", "npm-run-all": "^4.1.5", "ts-morph": "^23.0.0" }, @@ -26,17 +31,51 @@ "obsidian": "^1.6.6" } }, + "node_modules/@babel/runtime": { + "version": "7.25.6", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.25.6.tgz", + "integrity": "sha512-VBj9MYyDb9tuLq7yzqjgzt6Q+IBQLrGZfdjOekyEirZPHxXWoTSGUTMrpsfi58Up73d13NfYLv8HT9vmznjzhQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@capacitor/core": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/@capacitor/core/-/core-6.1.2.tgz", + "integrity": "sha512-xFy1/4qLFLp5WCIzIhtwUuVNNoz36+V7/BzHmLqgVJcvotc4MMjswW/TshnPQaLLujEOaLkA4h8ZJ0uoK3ImGg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tslib": "^2.1.0" + } + }, + "node_modules/@codemirror/search": { + "version": "6.5.6", + "resolved": "https://registry.npmjs.org/@codemirror/search/-/search-6.5.6.tgz", + "integrity": "sha512-rpMgcsh7o0GuCDUXKPvww+muLA1pDJaFrpq/CCHtpQJYz8xopu4D1hPcKRoDD0YlF8gZaqTNIRa4VRBWyhyy7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@codemirror/state": "^6.0.0", + "@codemirror/view": "^6.0.0", + "crelt": "^1.0.5" + } + }, "node_modules/@codemirror/state": { "version": "6.4.1", "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.4.1.tgz", "integrity": "sha512-QkEyUiLhsJoZkbumGZlswmAhA7CBU02Wrz7zvH4SrcifbsqwlXShVXg65f3v/ts57W3dqyamEriMhij1Z3Zz4A==", - "peer": true + "license": "MIT" }, "node_modules/@codemirror/view": { "version": "6.29.1", "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.29.1.tgz", "integrity": "sha512-7r+DlO/QFwPqKp73uq5mmrS4TuLPUVotbNOKYzN3OLP5ScrOVXcm4g13/48b6ZXGhdmzMinzFYqH0vo+qihIkQ==", - "peer": true, "dependencies": { "@codemirror/state": "^6.4.0", "style-mod": "^4.1.0", @@ -1567,6 +1606,13 @@ "@types/estree": "*" } }, + "node_modules/@types/turndown": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@types/turndown/-/turndown-5.0.5.tgz", + "integrity": "sha512-TL2IgGgc7B5j78rIccBtlYAnkuv8nUQqhQc+DSYV5j9Be9XOcm/SKOVRuA47xAVI3680Tk9B1d8flK2GWT2+4w==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/yauzl": { "version": "2.10.3", "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz", @@ -1991,6 +2037,13 @@ "dev": true, "license": "MIT" }, + "node_modules/crelt": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz", + "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==", + "dev": true, + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -3147,6 +3200,30 @@ "node": ">=10.19.0" } }, + "node_modules/i18next": { + "version": "23.15.1", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.15.1.tgz", + "integrity": "sha512-wB4abZ3uK7EWodYisHl/asf8UYEhrI/vj/8aoSsrj/ZDxj4/UXPOa1KvFt1Fq5hkUHquNqwFlDprmjZ8iySgYA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://locize.com" + }, + { + "type": "individual", + "url": "https://locize.com/i18next.html" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + } + ], + "license": "MIT", + "dependencies": { + "@babel/runtime": "^7.23.2" + } + }, "node_modules/import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", @@ -4035,6 +4112,13 @@ "node": ">=4" } }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "dev": true, + "license": "MIT" + }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -4529,8 +4613,7 @@ "node_modules/style-mod": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.2.tgz", - "integrity": "sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==", - "peer": true + "integrity": "sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==" }, "node_modules/sumchecker": { "version": "3.0.1", @@ -4591,6 +4674,13 @@ "code-block-writer": "^13.0.1" } }, + "node_modules/tslib": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "dev": true, + "license": "0BSD" + }, "node_modules/type-fest": { "version": "0.13.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", @@ -4756,8 +4846,7 @@ "node_modules/w3c-keyname": { "version": "2.2.8", "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", - "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", - "peer": true + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==" }, "node_modules/which": { "version": "1.3.1", diff --git a/package.json b/package.json index b0184d65..3fe08381 100644 --- a/package.json +++ b/package.json @@ -48,14 +48,19 @@ "obsidian": "^1.6.6" }, "devDependencies": { + "@capacitor/core": "^6.1.2", + "@codemirror/search": "^6.5.6", + "@codemirror/state": "^6.4.1", "@microsoft/api-extractor": "^7.47.9", "@tsconfig/strictest": "^2.0.5", "@types/node": "^18.17.0 || >=20.1.0", + "@types/turndown": "^5.0.5", "builtin-modules": "^4.0.0", "cspell": "^8.14.2", "dprint": "^0.47.2", "dts-bundle-generator": "^9.5.1", "esbuild": "^0.23.1", + "i18next": "^23.15.1", "npm-run-all": "^4.1.5", "ts-morph": "^23.0.0" }, diff --git a/src/@codemirror__view/internals/Bookmark.d.ts b/src/@codemirror__view/internals/Bookmark.d.ts new file mode 100644 index 00000000..7df21e16 --- /dev/null +++ b/src/@codemirror__view/internals/Bookmark.d.ts @@ -0,0 +1,17 @@ +import { ChangeDesc } from '@codemirror/state'; +import type { EditorPosition } from 'obsidian'; +import type { CodeMirrorEditor } from './CodeMirrorEditor.js'; + +/** + * @public + */ +export interface Bookmark { + cm: CodeMirrorEditor; + id: number; + offset: number; + assoc: number; + + clear(): void; + find(): EditorPosition | null; + update(changeDesc: ChangeDesc): void; +} diff --git a/src/@codemirror__view/internals/CodeMirrorAdapter2.d.ts b/src/@codemirror__view/internals/CodeMirrorAdapter2.d.ts new file mode 100644 index 00000000..002013c8 --- /dev/null +++ b/src/@codemirror__view/internals/CodeMirrorAdapter2.d.ts @@ -0,0 +1,71 @@ +import type { + EditorPosition, + Pos +} from 'obsidian'; +import type { CodeMirrorEditor } from './CodeMirrorEditor.js'; +import type { EditorRange2 } from './EditorRange2.js'; +import type { VimApi } from './VimApi.js'; +import type { VimEditor } from './VimEditor.js'; + +/** + * @public + */ +export interface CodeMirrorAdapter2 { + new(cm6: VimEditor): CodeMirrorEditor; + + Vim: VimApi; + + isMac: boolean; + + Pos: new(line: number, ch: number) => EditorPosition; + + StringStream: unknown; + + commands: { + cursorCharLeft: (editor: CodeMirrorEditor) => void; + redo: (editor: CodeMirrorEditor) => void; + undo: (editor: CodeMirrorEditor) => void; + newlineAndIndent: (editor: CodeMirrorEditor) => void; + newlineAndIndentBefore: (editor: CodeMirrorEditor) => void; + indentAuto: (editor: CodeMirrorEditor) => void; + }; + + defineOption(option: string, defaultValue: unknown, handler: () => void): void; + + isWordChar(char: string): boolean; + + keys: Record; + + keyMap: Record; + + addClass(element: HTMLElement, className: string): void; + + rmClass(element: HTMLElement, className: string): void; + + e_preventDefault(event: Event): void; + + e_stop(event: Event): void; + + keyName(event: KeyboardEvent): string; + + vimKey(event: KeyboardEvent): string; + + lookupKey( + key: string, + context: unknown, + callback: (action: (codeMirrorAdapter: CodeMirrorAdapter2) => boolean) => void + ): void; + + on(event: string, listener: EventListenerOrEventListenerObject): void; + + off(event: string, listener: EventListenerOrEventListenerObject): void; + + signal(target: unknown, type: string, ...values: unknown[]): void; + + findMatchingTag(doc: CodeMirrorAdapter2, pos: EditorPosition): void; + + findEnclosingTag(doc: CodeMirrorAdapter2, pos: EditorPosition): { + open: EditorRange2; + close: EditorRange2; + } | undefined; +} diff --git a/src/@codemirror__view/internals/CodeMirrorEditor.d.ts b/src/@codemirror__view/internals/CodeMirrorEditor.d.ts new file mode 100644 index 00000000..f9cedce8 --- /dev/null +++ b/src/@codemirror__view/internals/CodeMirrorEditor.d.ts @@ -0,0 +1,216 @@ +import type { SearchQuery } from '@codemirror/search'; +import type { ChangeDesc } from '@codemirror/state'; +import type { EditorPosition } from 'obsidian'; +import type { Bookmark } from './Bookmark.js'; +import type { EditorSelection } from './EditorSelection.js'; +import type { LineHandle } from './LineHandle.js'; +import type { OpenDialogOptions } from './OpenDialogOptions.js'; + +/** + * @public + */ +interface CodeMirrorEditor { + $lineHandleChanges: { changes: ChangeDesc }[] | undefined; + + openDialog( + template: string, + keyValidator: (keyValue: string) => boolean, + options?: Partial + ): void; + + openNotification( + message: string, + options?: { duration?: number; bottom?: boolean } + ): () => void; + + on(event: string, listener: EventListenerOrEventListenerObject): void; + + off(event: string, listener: EventListenerOrEventListenerObject): void; + + signal(event: string, ...args: unknown[]): void; + + indexFromPos(pos: EditorPosition): number; + + posFromIndex(index: number): EditorPosition; + + foldCode(line: number): void; + + firstLine(): number; + + lastLine(): number; + + lineCount(): number; + + setCursor(line: number, ch: number): void; + + getCursor( + type?: 'head' | 'anchor' | 'start' | 'end' + ): EditorPosition; + + listSelections(): Array<{ + anchor: EditorPosition; + head: EditorPosition; + }>; + + getMainSelection(): EditorSelection; + + setSelections( + selections: EditorSelection[], + primaryIndex?: number + ): void; + + setSelection( + anchor: EditorPosition, + head: EditorPosition, + options?: { origin?: string } + ): void; + + getLine(line: number): string; + + getLineHandle(line: number): LineHandle; + + getLineNumber(handle: LineHandle): number | null; + + releaseLineHandles(): void; + + getRange(from: EditorPosition, to: EditorPosition): string; + + replaceRange( + text: string, + from: EditorPosition, + to?: EditorPosition + ): void; + + replaceSelection(text: string): void; + + replaceSelections(texts: string[]): void; + + getSelection(): string; + + getSelections(): string[]; + + somethingSelected(): boolean; + + getInputField(): HTMLElement; + + clipPos(pos: EditorPosition): EditorPosition; + + getValue(): string; + + setValue(content: string): void; + + focus(): void; + + blur(): void; + + defaultTextHeight(): number; + + findMatchingBracket(pos: EditorPosition): { to?: EditorPosition }; + + scanForBracket( + from: EditorPosition, + direction: number, + style?: string + ): { pos: EditorPosition; ch: string } | null; + + indentLine(line: number, more?: boolean): void; + + indentMore(): void; + + indentLess(): void; + + execCommand(command: string): void; + + setBookmark(pos: EditorPosition, options?: { insertLeft?: boolean }): Bookmark; + + addOverlay(options: { query: RegExp }): SearchQuery | undefined; + + removeOverlay(overlay?: SearchQuery): void; + + getSearchCursor(query: RegExp, pos: EditorPosition): { + findNext(): boolean; + findPrevious(): boolean; + find(reverse?: boolean): boolean; + from(): EditorPosition | void; + to(): EditorPosition | void; + replace(text: string): void; + }; + + moveByChar(pos: EditorPosition, dir: 'left' | 'right', unit: number): EditorPosition; + + findPosV( + start: EditorPosition, + amount: number, + unit: 'line' | 'page', + goalColumn: number + ): EditorPosition; + + charCoords( + pos: EditorPosition, + mode: 'local' | 'page' | 'window' | 'div' + ): { left: number; top: number; bottom: number }; + + coordsChar(coords: { left: number; top: number }, mode: 'local' | 'page' | 'window' | 'div'): EditorPosition; + + getScrollInfo(): { + left: number; + top: number; + height: number; + width: number; + clientHeight: number; + clientWidth: number; + }; + + scrollTo(x?: number, y?: number): void; + + scrollInfo(): { + left: number; + top: number; + height: number; + width: number; + clientHeight: number; + clientWidth: number; + }; + + scrollIntoView(pos?: EditorPosition, margin?: number): void; + + getWrapperElement(): HTMLElement; + + getMode(): { name: string }; + + setSize(width: number, height: number): void; + + refresh(): void; + + destroy(): void; + + getLastEditEnd(): EditorPosition; + + onChange(lineHandleChange: { changes: ChangeDesc }): void; + + onSelectionChange(): void; + + operation(fn: () => T): T; + + onBeforeEndOperation(): void; + + moveH(dir: number, unit: string): void; + + setOption(option: string, value: unknown): void; + + getOption(option: string): unknown; + + toggleOverwrite(overwrite: boolean): void; + + getTokenTypeAt(pos: EditorPosition): string; + + overWriteSelection(text: string): void; + + isInMultiSelectMode(): boolean; + + virtualSelectionMode(): boolean; + + forEachSelection(fn: () => void): void; + + hardWrap(options: { column?: number; from?: number; to?: number; allowMerge?: boolean }): void; +} diff --git a/src/@codemirror__view/internals/EditorRange2.d.ts b/src/@codemirror__view/internals/EditorRange2.d.ts new file mode 100644 index 00000000..0e62b1e3 --- /dev/null +++ b/src/@codemirror__view/internals/EditorRange2.d.ts @@ -0,0 +1,9 @@ +import type { EditorPosition } from 'obsidian'; + +/** + * @public + */ +export interface EditorRange2 { + from: EditorPosition | null; + to: EditorPosition | null; +} diff --git a/src/@codemirror__view/internals/EditorSelection.d.ts b/src/@codemirror__view/internals/EditorSelection.d.ts new file mode 100644 index 00000000..88114481 --- /dev/null +++ b/src/@codemirror__view/internals/EditorSelection.d.ts @@ -0,0 +1,9 @@ +import type { EditorPosition } from 'obsidian'; + +/** + * @public + */ +export interface EditorSelection { + anchor: EditorPosition; + head: EditorPosition; +} diff --git a/src/@codemirror__view/internals/LineHandle.d.ts b/src/@codemirror__view/internals/LineHandle.d.ts new file mode 100644 index 00000000..abe03de2 --- /dev/null +++ b/src/@codemirror__view/internals/LineHandle.d.ts @@ -0,0 +1,7 @@ +/** + * @public + */ +export interface LineHandle { + row: number; + index: number; +} diff --git a/src/@codemirror__view/internals/OpenDialogOptions.d.ts b/src/@codemirror__view/internals/OpenDialogOptions.d.ts new file mode 100644 index 00000000..05b4190c --- /dev/null +++ b/src/@codemirror__view/internals/OpenDialogOptions.d.ts @@ -0,0 +1,14 @@ +/** + * @public + */ +export interface OpenDialogOptions { + bottom: number; + onClose(div: HTMLDivElement): void; + value: string; + selectValueOnOpen: boolean; + onInput(e: KeyboardEvent, value: string, callback: (value: unknown) => void): void; + onKeyUp(e: KeyboardEvent, value: string, callback: (value: unknown) => void): void; + onKeyDown(e: KeyboardEvent, value: string, callback: (value: unknown) => void): void; + closeOnEnter: boolean; + closeOnBlur: boolean; +} diff --git a/src/@codemirror__view/internals/VimApi.d.ts b/src/@codemirror__view/internals/VimApi.d.ts new file mode 100644 index 00000000..907202b0 --- /dev/null +++ b/src/@codemirror__view/internals/VimApi.d.ts @@ -0,0 +1,38 @@ +import type { VimEditor } from './VimEditor.js'; +import type { VimState } from './VimState.js'; + +/** + * @public + */ +export interface VimApi { + InsertModeKey(keyName: string): void; + buildKeyMap(): void; + defineAction(name: string, fn: (cm: VimEditor, actionArgs: unknown, vim: VimState['vim']) => void): void; + defineEx(name: unknown, prefix: unknown, func: unknown): unknown; + defineMotion(name: unknown, fn: unknown): unknown; + defineOperator(name: unknown, fn: unknown): unknown; + defineOption(name: unknown, defaultValue: unknown, type: unknown, aliases: unknown, callback: unknown): unknown; + defineRegister(name: unknown, register: unknown): unknown; + enterInsertMode(cm: unknown): unknown; + enterVimMode(cm: unknown): unknown; + exitInsertMode(cm: unknown, keepCursor: unknown): unknown; + exitVisualMode(cm: unknown, moveHead: unknown): unknown; + findKey(cm: unknown, key: unknown, origin: unknown): unknown; + getOption(name: unknown, cm: unknown, cfg: unknown): unknown; + getRegisterController(): unknown; + getVimGlobalState_(): unknown; + handleEx(cm: unknown, input: unknown): unknown; + handleKey(cm: unknown, key: unknown, origin: unknown): unknown; + leaveVimMode(cm: unknown): unknown; + map(lhs: unknown, rhs: unknown, ctx: unknown): unknown; + mapCommand(keys: unknown, type: unknown, name: unknown, args: unknown, extra: unknown): unknown; + mapclear(ctx: unknown): unknown; + maybeInitVimState_(cm: unknown): unknown; + multiSelectHandleKey(cm: unknown, key: unknown, origin: unknown): unknown; + noremap(lhs: unknown, rhs: unknown, ctx: unknown): unknown; + resetVimGlobalState_(): unknown; + setOption(name: unknown, value: unknown, cm: unknown, cfg: unknown): unknown; + suppressErrorLogging: boolean; + unmap(lhs: unknown, ctx: unknown): unknown; + _mapCommand(command: unknown): unknown; +} diff --git a/src/global/vars.d.ts b/src/global/vars.d.ts new file mode 100644 index 00000000..662b5787 --- /dev/null +++ b/src/global/vars.d.ts @@ -0,0 +1,306 @@ +import { + Capacitor as _Capacitor, + CapacitorPlatforms as _CapacitorPlatforms +} from '@capacitor/core'; +import _i18next from 'i18next'; +import type { + App, + Notice as _Notice, + ObsidianProtocolData, + request as _request, + requestUrl as _requestUrl +} from 'obsidian'; +import _TurndownService from 'turndown'; +import type { CodeMirrorAdapter2 } from '../@codemirror__view/internals/CodeMirrorAdapter2.js'; +import type { VimApi } from '../@codemirror__view/internals/VimApi.js'; +import type { CapacitorAdapterFs } from '../obsidian/internals/CapacitorAdapterFs.js'; +import type { ElectronWindow } from '../obsidian/internals/ElectronWindow.js'; +import type { FrameDom } from '../obsidian/internals/FrameDom.js'; +import type { Localization } from '../obsidian/internals/Localization.js'; +import type { Database } from '../obsidian/internals/WebSQL/Database.js'; + +declare global { + /** + * Global reference to the app + * @public + * @deprecated - Prefer not to use this value directly. + */ + var app: App; + + /** + * @public + */ + var bl: typeof Object.hasOwnProperty; + + /** + * @public + */ + var blinkfetch: typeof fetch; + + /** + * @public + */ + var blinkFormData: typeof FormData; + + /** + * @public + */ + var blinkHeaders: typeof Headers; + + /** + * @public + */ + var blinkRequest: typeof Request; + + /** + * @public + */ + var blinkResponse: typeof Response; + + /** + * @public + */ + var Capacitor: typeof _Capacitor; + + /** + * @public + */ + var CapacitorPlatforms: typeof _CapacitorPlatforms; + + /** + * @public + */ + var Cf: typeof Object.getOwnPropertyDescriptors; + + /** + * @public + * + * Commented out because the global variable is already declared in the `@types/codemirror` package. + */ + // var CodeMirror: typeof import('codemirror'); + + /** + * @public + */ + var CodeMirrorAdapter: CodeMirrorAdapter2; + + /** + * DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML and SVG. + * @public + * + * Commented out because the global variable is already declared in the `@types/dompurify` package. + */ + // var DOMPurify: typeof import('dompurify); + + /** + * @public + */ + var El: typeof Object.propertyIsEnumerable; + + /** + * @public + */ + var electron: typeof import('electron'); + + /** + * @public + */ + var electronWindow: ElectronWindow; + + /** + * @public + */ + var frameDom: FrameDom; + + /** + * Constructor for the Capacitor file system adapter. + * @public + */ + var FS: new(dir: string) => CapacitorAdapterFs; + + /** + * @public + */ + var globalEnhance: () => void; + + /** + * @public + */ + var i18next: typeof _i18next & { + observers: object; + isLanguageChangingTo: string | undefined; + logger: unknown; + translator: unknown; + }; + + /** + * vim.js based on https://github.com/codemirror/CodeMirror/commit/793c9e65e09ec7fba3f4f5aaf366b3d36e1a709e (2021-12-04) + * + * Modified from https://github.com/nightwing/cm6-vim-mode-experiment/blob/master/src/vim.js 103a9b5 2021-12-03 + * + * CodeMirror, copyright (c) by Marijn Haverbeke and others + * + * Distributed under an MIT license: https://codemirror.net/5/LICENSE + * + * Supported keybindings: + * Too many to list. Refer to defaultKeymap below. + * + * Supported Ex commands: + * Refer to defaultExCommandMap below. + * + * Registers: unnamed, -, ., :, /, _, a-z, A-Z, 0-9 + * (Does not respect the special case for number registers when delete + * operator is made with these commands: %, (, ), , /, ?, n, N, {, } ) + * TODO: Implement the remaining registers. + * + * Marks: a-z, A-Z, and 0-9 + * TODO: Implement the remaining special marks. They have more complex + * behavior. + * + * Events: + * 'vim-mode-change' - raised on the editor anytime the current mode changes, + * Event object: {mode: "visual", subMode: "linewise"} + * + * Code structure: + * 1. Default keymap + * 2. Variable declarations and short basic helpers + * 3. Instance (External API) implementation + * 4. Internal state tracking objects (input state, counter) implementation + * and instantiation + * 5. Key handler (the main command dispatcher) implementation + * 6. Motion, operator, and action implementations + * 7. Helper functions for the key handler, motions, operators, and actions + * 8. Set up Vim to work as a keymap for CodeMirror. + * 9. Ex command implementations. + * + * @public + */ + var initVimMode: (CodeMirror: CodeMirrorAdapter2) => VimApi; + + /** + * @public + */ + var li: (target: object, source: object) => object; + + /** + * @public + */ + var mo: (target: object, propertyNames: string[]) => object; + + /** + * Parse, validate, manipulate, and display dates in javascript. + * @public + * + * Commented out because the global variable is already declared in the `moment` package. + */ + // var moment: typeof import('moment'); + + /** + * @public + */ + var mr: typeof Object.getOwnPropertySymbols; + + /** + * Notification component. Use to present timely, high-value information. + * @public + */ + /** + * @public + */ + var Notice: typeof _Notice; + + /** + * Invoke obsidian protocol action. + * @public + */ + var OBS_ACT: (obsidianProtocolData: ObsidianProtocolData) => void; + + /** + * @public + */ + var OBSIDIAN_DEFAULT_I18N: Localization; + + /** + * @public + */ + var openDatabase: ( + name: string, + version: string, + displayName: string, + estimatedSize: number, + creationCallback?: (database: Database) => void + ) => Database; + + /** + * @public + * + * Commented out because the global variable is already declared in the `@types/pixi.js` package. + */ + // var PIXI: typeof import('pixi.js'); + + /** + * Similar to `fetch()`, request a URL using HTTP/HTTPS, without any CORS restrictions. + * Returns the text value of the response. + * @public + */ + var request: typeof _request; + + /** + * Similar to `fetch()`, request a URL using HTTP/HTTPS, without any CORS restrictions. + * @public + */ + var requestUrl: typeof _requestUrl; + + /** + * @public + * + * Commented out because the global variable is already declared in the `scrypt-js` package. + */ + // var scrypt: typeof import('scrypt-js'); + + /** + * Select a language file location. + * @public + */ + var selectLanguageFileLocation: () => void; + + /** + * @public + */ + var Sf: typeof Object.defineProperties; + + /** + * @public + */ + var St: (target: object, source: object | undefined) => object; + + /** + * @public + */ + var temp1: Database['changeVersion']; + + /** + * @public + */ + var titlebarStyle: string; + + /** + * @public + */ + var Tl: (target: object, propertyName: string, propertyValue: unknown) => unknown; + + /** + * @public + */ + var TurndownService: typeof _TurndownService; + + /** + * @public + */ + var WebView: HTMLElement & { new(): HTMLElement }; + + /** + * @public + */ + var wf: typeof Object.defineProperty; +} diff --git a/src/obsidian/augmentations/CapacitorAdapter.d.ts b/src/obsidian/augmentations/CapacitorAdapter.d.ts index b084c7f5..8833a402 100644 --- a/src/obsidian/augmentations/CapacitorAdapter.d.ts +++ b/src/obsidian/augmentations/CapacitorAdapter.d.ts @@ -1,12 +1,13 @@ -import type { CapacitorAdapterFs } from "../internals/CapacitorAdapterFs.js"; -import type { FileEntry } from "../internals/FileEntry.js"; +import type { CapacitorAdapterFs } from '../internals/CapacitorAdapterFs.js'; +import type { FileEntry } from '../internals/FileEntry.js'; -export { }; +export {}; declare module 'obsidian' { interface CapacitorAdapter extends DataAdapter { fs: CapacitorAdapterFs; + _exists(normalizedPath: string, sensitive?: boolean): Promise; getNativePath(normalizedPath: string): string; getRealPath(normalizedPath: string): string; onFileChange(normalizedPath: string): void; @@ -18,6 +19,5 @@ declare module 'obsidian' { testInsensitive(): Promise; update(normalizedPath: string): Promise; watchAndList(): Promise; - _exists(normalizedPath: string, sensitive?: boolean): Promise; } } diff --git a/src/obsidian/augmentations/DataAdapter.d.ts b/src/obsidian/augmentations/DataAdapter.d.ts index d8632b59..0eea8115 100644 --- a/src/obsidian/augmentations/DataAdapter.d.ts +++ b/src/obsidian/augmentations/DataAdapter.d.ts @@ -2,7 +2,7 @@ import type { DataAdapterFilesRecord } from '../internals/DataAdapterRecords/Dat import type { FileSystemWatchHandler } from '../internals/FileSystemWatchHandler.js'; import type { PromisedQueue } from '../internals/PromisedQueue.js'; -export { }; +export {}; declare module 'obsidian' { /** @todo Documentation incomplete */ @@ -19,11 +19,11 @@ declare module 'obsidian' { handler: FileSystemWatchHandler | null; /** @internal */ insensitive: boolean; + /** @internal */ + promise: Promise; /** @internal Triggers handler for vault events */ trigger: FileSystemWatchHandler; - /** @internal */ - promise: Promise; /** * Get full path of file (OS path) * diff --git a/src/obsidian/augmentations/FileSystemAdapter.d.ts b/src/obsidian/augmentations/FileSystemAdapter.d.ts index 0a4cf580..84ab698f 100644 --- a/src/obsidian/augmentations/FileSystemAdapter.d.ts +++ b/src/obsidian/augmentations/FileSystemAdapter.d.ts @@ -1,10 +1,10 @@ import type { IpcRenderer } from 'electron'; -import * as path from 'node:path'; import * as fs from 'node:fs'; import * as fsPromises from 'node:fs/promises'; +import * as path from 'node:path'; import type { DataAdapterWatchersRecord } from '../internals/DataAdapterRecords/DataAdapterWatchersRecord.js'; -export { }; +export {}; declare module 'obsidian' { interface FileSystemAdapter extends DataAdapter { @@ -34,6 +34,7 @@ declare module 'obsidian' { watcher: unknown; /** @internal */ watchers: DataAdapterWatchersRecord; + /** * @param normalizedPath Path to file * @param options Data write options diff --git a/src/obsidian/augmentations/MarkdownPreviewSection.d.ts b/src/obsidian/augmentations/MarkdownPreviewSection.d.ts index a19cb3e0..7549a535 100644 --- a/src/obsidian/augmentations/MarkdownPreviewSection.d.ts +++ b/src/obsidian/augmentations/MarkdownPreviewSection.d.ts @@ -10,8 +10,8 @@ declare module 'obsidian' { html: string; level: number; lineEnd: number; - lineStart: number lines: number; + lineStart: number; rendered: boolean; shown: boolean; used: boolean; diff --git a/src/obsidian/global.d.ts b/src/obsidian/global.d.ts deleted file mode 100644 index a52b214b..00000000 --- a/src/obsidian/global.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { App } from 'obsidian'; -import type { CapacitorAdapterFs } from './internals/CapacitorAdapterFs.js'; - -declare global { - /** Global reference to the app - * @public - * @deprecated - Prefer not to use this value directly. - */ - var app: App; - - /** @public - * Constructor for the Capacitor file system adapter - */ - var FS: new () => CapacitorAdapterFs; -} diff --git a/src/obsidian/internals/CapacitorAdapterFs.d.ts b/src/obsidian/internals/CapacitorAdapterFs.d.ts index 474a4cef..1deff295 100644 --- a/src/obsidian/internals/CapacitorAdapterFs.d.ts +++ b/src/obsidian/internals/CapacitorAdapterFs.d.ts @@ -1,4 +1,4 @@ -import type { FileEntry } from "./FileEntry.js"; +import type { FileEntry } from './FileEntry.js'; /** @public */ export interface CapacitorAdapterFs { diff --git a/src/obsidian/internals/ElectronWindow.d.ts b/src/obsidian/internals/ElectronWindow.d.ts new file mode 100644 index 00000000..6f1cd0d6 --- /dev/null +++ b/src/obsidian/internals/ElectronWindow.d.ts @@ -0,0 +1,11 @@ +import type { BrowserWindow } from 'electron'; + +/** + * @public + */ +export interface ElectronWindow extends BrowserWindow { + devToolsWebContents: unknown; + _browserViews: unknown; + _events: unknown; + _eventsCount: unknown; +} diff --git a/src/obsidian/internals/FileEntry.d.ts b/src/obsidian/internals/FileEntry.d.ts index 014c83a0..6356dd1d 100644 --- a/src/obsidian/internals/FileEntry.d.ts +++ b/src/obsidian/internals/FileEntry.d.ts @@ -1,4 +1,4 @@ -import type { FileStats } from "obsidian"; +import type { FileStats } from 'obsidian'; /** @public */ export interface FileEntry extends Partial { diff --git a/src/obsidian/internals/FrameDom.d.ts b/src/obsidian/internals/FrameDom.d.ts new file mode 100644 index 00000000..3c426fa1 --- /dev/null +++ b/src/obsidian/internals/FrameDom.d.ts @@ -0,0 +1,15 @@ +/** + * @public + */ +export interface FrameDom { + eWin: Electron.BrowserWindow; + isMac: boolean; + leftButtonContainerEl: HTMLDivElement; + titleBarEl: HTMLDivElement; + titleBarInnerEl: HTMLDivElement; + titleBarTextEl: HTMLDivElement; + win: Window; + + updateStatus(): void; + updateTitle(): void; +} diff --git a/src/obsidian/internals/Localization.d.ts b/src/obsidian/internals/Localization.d.ts new file mode 100644 index 00000000..0366a255 --- /dev/null +++ b/src/obsidian/internals/Localization.d.ts @@ -0,0 +1,6 @@ +/** + * @public + */ +export interface Localization { + [key: string]: string | Localization; +} diff --git a/src/obsidian/internals/WebSQL/Database.d.ts b/src/obsidian/internals/WebSQL/Database.d.ts new file mode 100644 index 00000000..916cbfef --- /dev/null +++ b/src/obsidian/internals/WebSQL/Database.d.ts @@ -0,0 +1,29 @@ +import type { SQLError } from './SQLError.js'; +import type { SQLTransaction } from './SQLTransaction.js'; + +/** + * @public + */ +export interface Database { + version: string; + + transaction( + callback: (transaction: SQLTransaction) => void, + errorCallback?: (error: SQLError) => void, + successCallback?: () => void + ): void; + + readTransaction( + callback: (transaction: SQLTransaction) => void, + errorCallback?: (error: SQLError) => void, + successCallback?: () => void + ): void; + + changeVersion( + oldVersion: string, + newVersion: string, + callback?: (transaction: SQLTransaction) => void, + errorCallback?: (error: SQLError) => void, + successCallback?: () => void + ): void; +} diff --git a/src/obsidian/internals/WebSQL/SQLError.d.ts b/src/obsidian/internals/WebSQL/SQLError.d.ts new file mode 100644 index 00000000..57d16518 --- /dev/null +++ b/src/obsidian/internals/WebSQL/SQLError.d.ts @@ -0,0 +1,7 @@ +/** + * @public + */ +export interface SQLError { + code: number; + message: string; +} diff --git a/src/obsidian/internals/WebSQL/SQLResultSet.d.ts b/src/obsidian/internals/WebSQL/SQLResultSet.d.ts new file mode 100644 index 00000000..fd78e793 --- /dev/null +++ b/src/obsidian/internals/WebSQL/SQLResultSet.d.ts @@ -0,0 +1,10 @@ +import type { SQLResultSetRowList } from './SQLResultSetRowList.js'; + +/** + * @public + */ +export interface SQLResultSet { + insertId: number; + rowsAffected: number; + rows: SQLResultSetRowList; +} diff --git a/src/obsidian/internals/WebSQL/SQLResultSetRowList.d.ts b/src/obsidian/internals/WebSQL/SQLResultSetRowList.d.ts new file mode 100644 index 00000000..31511a0c --- /dev/null +++ b/src/obsidian/internals/WebSQL/SQLResultSetRowList.d.ts @@ -0,0 +1,7 @@ +/** + * @public + */ +export interface SQLResultSetRowList { + length: number; + item(index: number): any; +} diff --git a/src/obsidian/internals/WebSQL/SQLTransaction.d.ts b/src/obsidian/internals/WebSQL/SQLTransaction.d.ts new file mode 100644 index 00000000..77ce332d --- /dev/null +++ b/src/obsidian/internals/WebSQL/SQLTransaction.d.ts @@ -0,0 +1,14 @@ +import type { SQLError } from './SQLError.js'; +import type { SQLResultSet } from './SQLResultSet.js'; + +/** + * @public + */ +export interface SQLTransaction { + executeSql( + sqlStatement: string, + arguments?: unknown[], + callback?: (transaction: SQLTransaction, resultSet: SQLResultSet) => void, + errorCallback?: (transaction: SQLTransaction, error: SQLError) => boolean + ): void; +}