diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 3104a06..0cd8a60 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -3,7 +3,7 @@ import process from "process"; import builtins from 'builtin-modules' const banner = -`/* + `/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ @@ -12,31 +12,32 @@ if you want to view the source, please visit the github repository of this plugi const prod = (process.argv[2] === 'production'); esbuild.build({ - banner: { - js: banner, - }, - entryPoints: ['src/floatSearchIndex.ts'], - bundle: true, - external: [ - 'obsidian', - 'electron', - '@codemirror/autocomplete', - '@codemirror/collab', - '@codemirror/commands', - '@codemirror/language', - '@codemirror/lint', - '@codemirror/search', - '@codemirror/state', - '@codemirror/view', - '@lezer/common', - '@lezer/highlight', - '@lezer/lr', - ...builtins], - format: 'cjs', - watch: !prod, - target: 'es2018', - logLevel: "info", - sourcemap: prod ? false : 'inline', - treeShaking: true, - outfile: 'main.js', + banner: { + js: banner, + }, + minify: prod, + entryPoints: ['src/floatSearchIndex.ts'], + bundle: true, + external: [ + 'obsidian', + 'electron', + '@codemirror/autocomplete', + '@codemirror/collab', + '@codemirror/commands', + '@codemirror/language', + '@codemirror/lint', + '@codemirror/search', + '@codemirror/state', + '@codemirror/view', + '@lezer/common', + '@lezer/highlight', + '@lezer/lr', + ...builtins], + format: 'cjs', + watch: !prod, + target: 'es2018', + logLevel: "info", + sourcemap: prod ? false : 'inline', + treeShaking: true, + outfile: 'main.js', }).catch(() => process.exit(1)); diff --git a/manifest.json b/manifest.json index df37de2..69058e2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "float-search", "name": "Floating Search", - "version": "3.3.3", + "version": "3.3.4", "minAppVersion": "0.15.0", "description": "You can use search view in modal/leaf/popout window now.", "author": "Boninall", diff --git a/package.json b/package.json index 03796b0..e9d3a2a 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,27 @@ { - "name": "float-search", - "version": "3.3.3", - "description": "You can use search view in modal/leaf/popout window now.", - "main": "main.js", - "scripts": { - "dev": "node esbuild.config.mjs", - "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json" - }, - "keywords": [], - "author": "Boninall", - "license": "GPL-3.0", - "devDependencies": { - "@types/node": "^16.11.6", - "@typescript-eslint/eslint-plugin": "5.29.0", - "@typescript-eslint/parser": "5.29.0", - "builtin-modules": "3.3.0", - "esbuild": "0.14.47", - "obsidian": "latest", - "tslib": "2.4.0", - "typescript": "4.7.4" - }, - "dependencies": { - "monkey-around": "^2.3.0" - } + "name": "float-search", + "version": "3.3.4", + "description": "You can use search view in modal/leaf/popout window now.", + "main": "main.js", + "scripts": { + "dev": "node esbuild.config.mjs", + "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "version": "node version-bump.mjs && git add manifest.json versions.json" + }, + "keywords": [], + "author": "Boninall", + "license": "GPL-3.0", + "devDependencies": { + "@types/node": "^16.11.6", + "@typescript-eslint/eslint-plugin": "5.29.0", + "@typescript-eslint/parser": "5.29.0", + "builtin-modules": "3.3.0", + "esbuild": "0.14.47", + "obsidian": "latest", + "tslib": "2.4.0", + "typescript": "4.7.4" + }, + "dependencies": { + "monkey-around": "^2.3.0" + } } diff --git a/src/floatSearchIndex.ts b/src/floatSearchIndex.ts index 3458cea..001e8f5 100644 --- a/src/floatSearchIndex.ts +++ b/src/floatSearchIndex.ts @@ -4,7 +4,7 @@ import { Modal, OpenViewState, Plugin, SearchView, TAbstractFile, - TFile, + TFile, ViewState, Workspace, WorkspaceContainer, WorkspaceItem, WorkspaceLeaf @@ -164,6 +164,15 @@ export default class FloatSearchPlugin extends Plugin { return function (event: MouseEvent, leaf: WorkspaceLeaf) { return old.call(this, event, leaf); }; + }, + pushUndoHistory(old: any) { + return function (leaf: WorkspaceLeaf, id: string, ...args: any[]) { + const viewState = leaf.getViewState(); + if (viewState.type === "search") { + return; + } + return old.call(this, leaf, id, ...args); + }; } }); this.register(uninstaller); @@ -238,7 +247,18 @@ export default class FloatSearchPlugin extends Plugin { return view; } - } + }, + // setViewState(old) { + // return function (viewState: ViewState, eState?: any) { + // const result = old.call(this, viewState, eState); + // console.log(viewState); + // if (isEmebeddedLeaf(this)) { + // console.log("hello", viewState); + // console.log(this.app.undoHistory); + // } + // return result; + // } + // } }), ); } @@ -610,7 +630,7 @@ class FloatSearchModal extends Modal { case "g": if (this.fileLeaf && e.ctrlKey) { e.preventDefault(); - app.workspace.setActiveLeaf(this.fileLeaf, { + this.plugin.app.workspace.setActiveLeaf(this.fileLeaf, { focus: true, }); } diff --git a/src/types/types-obsidian.d.ts b/src/types/types-obsidian.d.ts index fa177df..f4999a8 100644 --- a/src/types/types-obsidian.d.ts +++ b/src/types/types-obsidian.d.ts @@ -1,7 +1,7 @@ import "obsidian"; import { EditorPosition, - EphemeralState, + EphemeralState, Loc, MarkdownPreviewRenderer, MarkdownSubView, Plugin, @@ -18,24 +18,31 @@ interface InternalPlugins { "page-preview": InternalPlugin; graph: GraphPlugin; } + interface OpenViewState { - eState?: EphemeralState; - state?: { mode: string }; - active?: boolean; + eState?: EphemeralState; + state?: { mode: string }; + active?: boolean; } declare class QuickSwitcherModal extends SuggestModal { getSuggestions(query: string): TFile[] | Promise; + renderSuggestion(value: TFile, el: HTMLElement): unknown; + onChooseSuggestion(item: TFile, evt: MouseEvent | KeyboardEvent): unknown; } + interface InternalPlugin { disable(): void; + enable(): void; + enabled: boolean; _loaded: boolean; instance: { name: string; id: string }; } + interface GraphPlugin extends InternalPlugin { views: { localgraph: (leaf: WorkspaceLeaf) => GraphView }; } @@ -44,6 +51,7 @@ interface GraphView extends View { engine: typeof Object; renderer: { worker: { terminate(): void } }; } + interface QuickSwitcherPlugin extends InternalPlugin { instance: { name: string; @@ -56,6 +64,7 @@ declare global { const i18next: { t(id: string): string; }; + interface Window { activeWindow: Window; activeDocument: Document; @@ -87,52 +96,75 @@ declare module "obsidian" { }; dom: { appContainerEl: HTMLElement }; viewRegistry: ViewRegistry; + openWithDefaultApp(path: string): void; } + interface ViewRegistry { typeByExtension: Record; // file extensions to view types viewByType: Record View>; // file extensions to view types } + interface CalendarPlugin { view: View; } + interface WorkspaceParent { insertChild(index: number, child: WorkspaceItem, resize?: boolean): void; + replaceChild(index: number, child: WorkspaceItem, resize?: boolean): void; + removeChild(leaf: WorkspaceLeaf, resize?: boolean): void; + containerEl: HTMLElement; children: any; } + interface MarkdownEditView { editorEl: HTMLElement; } + class MarkdownPreviewRendererStatic extends MarkdownPreviewRenderer { static registerDomEvents(el: HTMLElement, handlerInstance: unknown, cb: (el: HTMLElement) => unknown): void; } interface WorkspaceLeaf { openLinkText(linkText: string, path: string, state?: unknown): Promise; + updateHeader(): void; + containerEl: HTMLDivElement; working: boolean; parentSplit: WorkspaceParent; activeTime: number; } + interface Workspace { recordHistory(leaf: WorkspaceLeaf, pushHistory: boolean): void; + iterateLeaves(callback: (item: WorkspaceLeaf) => boolean | void, item: WorkspaceItem | WorkspaceItem[]): boolean; + iterateLeaves(item: WorkspaceItem | WorkspaceItem[], callback: (item: WorkspaceLeaf) => boolean | void): boolean; + getDropLocation(event: MouseEvent): { target: WorkspaceItem; sidedock: boolean; }; + recursiveGetTarget(event: MouseEvent, parent: WorkspaceParent): WorkspaceItem; + recordMostRecentOpenedFile(file: TFile): void; + onDragLeaf(event: MouseEvent, leaf: WorkspaceLeaf): void; + onLayoutChange(): void; // tell Obsidian leaves have been added/removed/etc. activeLeafEvents(): void; + floatingSplit: any; + + pushUndoHistory(leaf: WorkspaceLeaf, id: string, e: any): void; } + interface Editor { getClickableTokenAt(pos: EditorPosition): { text: string; @@ -141,29 +173,42 @@ declare module "obsidian" { end: EditorPosition; }; } + interface View { iconEl: HTMLElement; file: TFile; + setMode(mode: MarkdownSubView): Promise; + followLinkUnderCursor(newLeaf: boolean): void; + modes: Record; + getMode(): string; + headerEl: HTMLElement; contentEl: HTMLElement; } - interface SearchView extends View { - onKeyArrowRightInFocus(e: KeyboardEvent): void; - onKeyArrowLeftInFocus(e: KeyboardEvent): void; - onKeyArrowUpInFocus(e: KeyboardEvent): void; - onKeyArrowDownInFocus(e: KeyboardEvent): void; - onKeyEnterInFocus(e: KeyboardEvent): void; - onKeyShowMoreBefore(e: KeyboardEvent): void; - onKeyShowMoreAfter(e: KeyboardEvent): void; - dom: any; + interface SearchView extends View { + onKeyArrowRightInFocus(e: KeyboardEvent): void; + + onKeyArrowLeftInFocus(e: KeyboardEvent): void; + + onKeyArrowUpInFocus(e: KeyboardEvent): void; + + onKeyArrowDownInFocus(e: KeyboardEvent): void; + + onKeyEnterInFocus(e: KeyboardEvent): void; + + onKeyShowMoreBefore(e: KeyboardEvent): void; + + onKeyShowMoreAfter(e: KeyboardEvent): void; + + dom: any; searchComponent: SearchComponent; headerDom: any; - } + } interface EmptyView extends View { actionListEl: HTMLElement; @@ -173,21 +218,25 @@ declare module "obsidian" { interface FileManager { createNewMarkdownFile(folder: TFolder, fileName: string): Promise; } + enum PopoverState { Showing, Shown, Hiding, Hidden, } + interface Menu { items: MenuItem[]; dom: HTMLElement; hideCallback: () => unknown; } + interface MenuItem { iconEl: HTMLElement; dom: HTMLElement; } + interface EphemeralState { focus?: boolean; subpath?: string; @@ -196,22 +245,32 @@ declare module "obsidian" { endLoc?: Loc; scroll?: number; } + interface HoverParent { type?: string; } + interface HoverPopover { parent: EmbeddedViewParent | null; targetEl: HTMLElement; hoverEl: HTMLElement; + position(pos?: MousePos): void; + hide(): void; + show(): void; + shouldShowSelf(): boolean; + timer: number; waitTime: number; + shouldShow(): boolean; + transition(): void; } + interface MousePos { x: number; y: number; diff --git a/versions.json b/versions.json index 4ed9cc8..428f7a3 100644 --- a/versions.json +++ b/versions.json @@ -16,5 +16,6 @@ "3.3.0": "0.15.0", "3.3.1": "0.15.0", "3.3.2": "0.15.0", - "3.3.3": "0.15.0" + "3.3.3": "0.15.0", + "3.3.4": "0.15.0" } \ No newline at end of file