@lapis-notes/api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE.md +4 -0
- package/README.md +43 -0
- package/dist/__tests__/data-adapter-conformance.js +205 -0
- package/dist/__tests__/lapis-runtime-manifest.js +32 -0
- package/dist/__tests__/svelte-internal-client.d.ts +3 -0
- package/dist/agent-result-views.d.ts +52 -0
- package/dist/agent-result-views.js +89 -0
- package/dist/agent-skills.d.ts +99 -0
- package/dist/agent-skills.js +182 -0
- package/dist/agent-tools.d.ts +92 -0
- package/dist/agent-tools.js +139 -0
- package/dist/app-database-host.d.ts +4 -0
- package/dist/app-database-host.js +4 -0
- package/dist/app-shell-plugin-persistence.d.ts +15 -0
- package/dist/app-shell-plugin-persistence.js +34 -0
- package/dist/app-url.d.ts +54 -0
- package/dist/app-url.js +269 -0
- package/dist/application-compatibility.d.ts +31 -0
- package/dist/application-compatibility.js +64 -0
- package/dist/application-state.svelte.d.ts +14 -0
- package/dist/application-state.svelte.js +30 -0
- package/dist/assets/lapis-logo.svg +471 -0
- package/dist/bases.d.ts +281 -0
- package/dist/bases.js +475 -0
- package/dist/cache.svelte.d.ts +569 -0
- package/dist/cache.svelte.js +1433 -0
- package/dist/command.svelte.d.ts +337 -0
- package/dist/command.svelte.js +571 -0
- package/dist/compat.d.ts +29 -0
- package/dist/compat.js +30 -0
- package/dist/components/configuration/configuration.css +199 -0
- package/dist/components/configuration/date-setting.svelte +71 -0
- package/dist/components/configuration/date-setting.svelte.d.ts +8 -0
- package/dist/components/configuration/list-setting.svelte +128 -0
- package/dist/components/configuration/list-setting.svelte.d.ts +13 -0
- package/dist/components/configuration/object-array-row-grip.svelte +78 -0
- package/dist/components/configuration/object-array-row-grip.svelte.d.ts +9 -0
- package/dist/components/configuration/object-array-row.svelte +163 -0
- package/dist/components/configuration/object-array-row.svelte.d.ts +19 -0
- package/dist/components/configuration/object-array-setting.svelte +196 -0
- package/dist/components/configuration/object-array-setting.svelte.d.ts +15 -0
- package/dist/components/configuration/object-array-table-dnd.d.ts +8 -0
- package/dist/components/configuration/object-array-table-dnd.js +10 -0
- package/dist/components/configuration/object-array-utils.d.ts +11 -0
- package/dist/components/configuration/object-array-utils.js +103 -0
- package/dist/components/configuration/object-grid-setting.svelte +79 -0
- package/dist/components/configuration/object-grid-setting.svelte.d.ts +10 -0
- package/dist/components/configuration/object-map-row.svelte +147 -0
- package/dist/components/configuration/object-map-row.svelte.d.ts +15 -0
- package/dist/components/configuration/object-map-setting.svelte +137 -0
- package/dist/components/configuration/object-map-setting.svelte.d.ts +14 -0
- package/dist/components/configuration/object-map-types.d.ts +5 -0
- package/dist/components/configuration/object-map-types.js +1 -0
- package/dist/components/configuration/options-combobox-setting.svelte +129 -0
- package/dist/components/configuration/options-combobox-setting.svelte.d.ts +12 -0
- package/dist/components/copy-button/button.svelte +93 -0
- package/dist/components/copy-button/button.svelte.d.ts +13 -0
- package/dist/components/copy-button/index.d.ts +2 -0
- package/dist/components/copy-button/index.js +2 -0
- package/dist/components/editor/editor.css +565 -0
- package/dist/components/editor/editor.d.ts +33 -0
- package/dist/components/editor/editor.js +132 -0
- package/dist/components/editor/editor.svelte +176 -0
- package/dist/components/editor/editor.svelte.d.ts +15 -0
- package/dist/components/editor/embedded-editor-surface.d.ts +12 -0
- package/dist/components/editor/embedded-editor-surface.js +22 -0
- package/dist/components/editor/embedded-editor-surface.svelte +115 -0
- package/dist/components/editor/embedded-editor-surface.svelte.d.ts +17 -0
- package/dist/components/editor/extensions/autocomplete/index.d.ts +2 -0
- package/dist/components/editor/extensions/autocomplete/index.js +2 -0
- package/dist/components/editor/extensions/autocomplete/lapis-code-mirror-autocomplete.d.ts +16 -0
- package/dist/components/editor/extensions/autocomplete/lapis-code-mirror-autocomplete.js +34 -0
- package/dist/components/editor/extensions/autocomplete/vault-completion-sources.d.ts +27 -0
- package/dist/components/editor/extensions/autocomplete/vault-completion-sources.js +55 -0
- package/dist/components/editor/extensions/class-highlighter/index.d.ts +1 -0
- package/dist/components/editor/extensions/class-highlighter/index.js +47 -0
- package/dist/components/editor/extensions/fold-gutter/index.d.ts +8 -0
- package/dist/components/editor/extensions/fold-gutter/index.js +40 -0
- package/dist/components/editor/extensions/gutter-line-style-sync/index.d.ts +2 -0
- package/dist/components/editor/extensions/gutter-line-style-sync/index.js +118 -0
- package/dist/components/editor/extensions/lint/index.d.ts +4 -0
- package/dist/components/editor/extensions/lint/index.js +4 -0
- package/dist/components/editor/extensions/lint/lapis-code-mirror-lint.d.ts +26 -0
- package/dist/components/editor/extensions/lint/lapis-code-mirror-lint.js +101 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic-helpers.d.ts +8 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic-helpers.js +7 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic.d.ts +20 -0
- package/dist/components/editor/extensions/lint/lapis-lint-diagnostic.js +47 -0
- package/dist/components/editor/extensions/lint/lapis-lint-hover-tooltip.d.ts +9 -0
- package/dist/components/editor/extensions/lint/lapis-lint-hover-tooltip.js +373 -0
- package/dist/components/editor/extensions/lint/lapis-lint-inline-widget.d.ts +31 -0
- package/dist/components/editor/extensions/lint/lapis-lint-inline-widget.js +191 -0
- package/dist/components/editor/extensions/lint/lapis-lint-tooltip.svelte +176 -0
- package/dist/components/editor/extensions/lint/lapis-lint-tooltip.svelte.d.ts +15 -0
- package/dist/components/editor/extensions/lint/lint-tooltip-actions.d.ts +11 -0
- package/dist/components/editor/extensions/lint/lint-tooltip-actions.js +21 -0
- package/dist/components/editor/extensions/lint/mount-lint-tooltip.d.ts +16 -0
- package/dist/components/editor/extensions/lint/mount-lint-tooltip.js +60 -0
- package/dist/components/editor/extensions/search/dom.d.ts +2 -0
- package/dist/components/editor/extensions/search/dom.js +6 -0
- package/dist/components/editor/extensions/search/index.d.ts +35 -0
- package/dist/components/editor/extensions/search/index.js +44 -0
- package/dist/components/editor/extensions/search/search.svelte +335 -0
- package/dist/components/editor/extensions/search/search.svelte.d.ts +8 -0
- package/dist/components/editor/index.d.ts +9 -0
- package/dist/components/editor/index.js +9 -0
- package/dist/components/editor/language-service/dom.d.ts +1 -0
- package/dist/components/editor/language-service/dom.js +6 -0
- package/dist/components/editor/language-service/index.d.ts +28 -0
- package/dist/components/editor/language-service/index.js +342 -0
- package/dist/components/empty-view/empty-view.css +39 -0
- package/dist/components/empty-view/empty-view.svelte +26 -0
- package/dist/components/empty-view/empty-view.svelte.d.ts +9 -0
- package/dist/components/empty-view/index.d.ts +2 -0
- package/dist/components/empty-view/index.js +2 -0
- package/dist/components/icon/icon-list.css +74 -0
- package/dist/components/icon/icon-list.svelte +213 -0
- package/dist/components/icon/icon-list.svelte.d.ts +11 -0
- package/dist/components/icon/icon.svelte +15 -0
- package/dist/components/icon/icon.svelte.d.ts +7 -0
- package/dist/components/icon/index.d.ts +3 -0
- package/dist/components/icon/index.js +3 -0
- package/dist/components/menu/context-menu.svelte +89 -0
- package/dist/components/menu/context-menu.svelte.d.ts +11 -0
- package/dist/components/menu/drawer-menu.svelte +83 -0
- package/dist/components/menu/drawer-menu.svelte.d.ts +8 -0
- package/dist/components/menu/dropdown-menu.svelte +89 -0
- package/dist/components/menu/dropdown-menu.svelte.d.ts +11 -0
- package/dist/components/menu/index.d.ts +6 -0
- package/dist/components/menu/index.js +6 -0
- package/dist/components/menu/menu.css +139 -0
- package/dist/components/menu/menu.svelte +37 -0
- package/dist/components/menu/menu.svelte.d.ts +11 -0
- package/dist/components/menu/mobile-menu-query.svelte.d.ts +3 -0
- package/dist/components/menu/mobile-menu-query.svelte.js +21 -0
- package/dist/components/menu/popover-menu.svelte +90 -0
- package/dist/components/menu/popover-menu.svelte.d.ts +10 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +2 -0
- package/dist/components/select/select.svelte +72 -0
- package/dist/components/select/select.svelte.d.ts +25 -0
- package/dist/configuration-option-source-providers.d.ts +17 -0
- package/dist/configuration-option-source-providers.js +59 -0
- package/dist/configuration-option-source-registry.d.ts +59 -0
- package/dist/configuration-option-source-registry.js +123 -0
- package/dist/configuration.svelte.d.ts +258 -0
- package/dist/configuration.svelte.js +887 -0
- package/dist/context-keys.svelte.d.ts +42 -0
- package/dist/context-keys.svelte.js +278 -0
- package/dist/context.svelte.d.ts +247 -0
- package/dist/context.svelte.js +540 -0
- package/dist/daily-document-provider.d.ts +38 -0
- package/dist/daily-document-provider.js +176 -0
- package/dist/design-core-button-types.d.ts +7 -0
- package/dist/design-core-button-types.js +1 -0
- package/dist/diagnostics.d.ts +93 -0
- package/dist/diagnostics.js +84 -0
- package/dist/dialog-portal.d.ts +3 -0
- package/dist/dialog-portal.js +3 -0
- package/dist/docs-api.d.ts +44 -0
- package/dist/docs-api.js +29 -0
- package/dist/editor-view-registry.d.ts +35 -0
- package/dist/editor-view-registry.js +112 -0
- package/dist/editor.svelte.d.ts +126 -0
- package/dist/editor.svelte.js +454 -0
- package/dist/embed-registry.d.ts +15 -0
- package/dist/embed-registry.js +16 -0
- package/dist/enhance.d.ts +111 -0
- package/dist/enhance.js +309 -0
- package/dist/events.d.ts +28 -0
- package/dist/events.js +49 -0
- package/dist/file-manager.d.ts +90 -0
- package/dist/file-manager.js +289 -0
- package/dist/file-tools/app-tools.d.ts +3 -0
- package/dist/file-tools/app-tools.js +242 -0
- package/dist/file-tools/index.d.ts +3 -0
- package/dist/file-tools/index.js +3 -0
- package/dist/file-tools/paths.d.ts +14 -0
- package/dist/file-tools/paths.js +33 -0
- package/dist/file-tools/vault-operations.d.ts +3 -0
- package/dist/file-tools/vault-operations.js +60 -0
- package/dist/generated/plugin-host-modules.schema.generated.d.ts +371 -0
- package/dist/generated/plugin-host-modules.schema.generated.js +374 -0
- package/dist/glob.d.ts +15 -0
- package/dist/glob.js +68 -0
- package/dist/history.svelte.d.ts +24 -0
- package/dist/history.svelte.js +74 -0
- package/dist/hooks/createVirtualizer.svelte.d.ts +7 -0
- package/dist/hooks/createVirtualizer.svelte.js +70 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/is-mobile.svelte.d.ts +5 -0
- package/dist/hooks/is-mobile.svelte.js +23 -0
- package/dist/hooks/mountComponent.svelte.d.ts +7 -0
- package/dist/hooks/mountComponent.svelte.js +16 -0
- package/dist/hooks/use-text-highlight.d.ts +17 -0
- package/dist/hooks/use-text-highlight.js +82 -0
- package/dist/hooks/useBoundingRect.svelte.d.ts +11 -0
- package/dist/hooks/useBoundingRect.svelte.js +46 -0
- package/dist/icons/index.d.ts +57 -0
- package/dist/icons/index.js +288 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +87 -0
- package/dist/language-service/index.d.ts +9 -0
- package/dist/language-service/index.js +7 -0
- package/dist/language-service/manager.d.ts +47 -0
- package/dist/language-service/manager.js +404 -0
- package/dist/language-service/types.d.ts +92 -0
- package/dist/language-service/types.js +1 -0
- package/dist/language-service/virtual-document.d.ts +11 -0
- package/dist/language-service/virtual-document.js +45 -0
- package/dist/language-service/worker-protocol.d.ts +63 -0
- package/dist/language-service/worker-protocol.js +1 -0
- package/dist/language-service/worker-provider.d.ts +9 -0
- package/dist/language-service/worker-provider.js +38 -0
- package/dist/lapis-extension.d.ts +244 -0
- package/dist/lapis-extension.js +591 -0
- package/dist/links.d.ts +34 -0
- package/dist/links.js +191 -0
- package/dist/loaders.d.ts +9 -0
- package/dist/loaders.js +59 -0
- package/dist/localization-manager.svelte.d.ts +56 -0
- package/dist/localization-manager.svelte.js +157 -0
- package/dist/logging.d.ts +172 -0
- package/dist/logging.js +352 -0
- package/dist/markdown-extension-registry.d.ts +31 -0
- package/dist/markdown-extension-registry.js +31 -0
- package/dist/markdown-file-surface-registry.d.ts +25 -0
- package/dist/markdown-file-surface-registry.js +23 -0
- package/dist/markdown.d.ts +205 -0
- package/dist/markdown.js +147 -0
- package/dist/menu-utils.d.ts +1 -0
- package/dist/menu-utils.js +47 -0
- package/dist/menu.svelte.d.ts +121 -0
- package/dist/menu.svelte.js +295 -0
- package/dist/metadata-value.d.ts +10 -0
- package/dist/metadata-value.js +173 -0
- package/dist/metadata.svelte.d.ts +106 -0
- package/dist/metadata.svelte.js +608 -0
- package/dist/notifications.d.ts +209 -0
- package/dist/notifications.js +338 -0
- package/dist/open-file.d.ts +23 -0
- package/dist/open-file.js +102 -0
- package/dist/platform.d.ts +86 -0
- package/dist/platform.js +86 -0
- package/dist/plugin-asset-server.d.ts +60 -0
- package/dist/plugin-asset-server.js +222 -0
- package/dist/plugin-assets.d.ts +4 -0
- package/dist/plugin-assets.js +3 -0
- package/dist/plugin-capability-facade.d.ts +104 -0
- package/dist/plugin-capability-facade.js +61 -0
- package/dist/plugin-dependency-resolver.d.ts +36 -0
- package/dist/plugin-dependency-resolver.js +54 -0
- package/dist/plugin-dependency-scanner.d.ts +9 -0
- package/dist/plugin-dependency-scanner.js +274 -0
- package/dist/plugin-distribution/canonical-json.d.ts +1 -0
- package/dist/plugin-distribution/canonical-json.js +40 -0
- package/dist/plugin-distribution/compatibility.d.ts +5 -0
- package/dist/plugin-distribution/compatibility.js +38 -0
- package/dist/plugin-distribution/errors.d.ts +11 -0
- package/dist/plugin-distribution/errors.js +13 -0
- package/dist/plugin-distribution/hashes.d.ts +2 -0
- package/dist/plugin-distribution/hashes.js +17 -0
- package/dist/plugin-distribution/index.d.ts +18 -0
- package/dist/plugin-distribution/index.js +18 -0
- package/dist/plugin-distribution/installed-plugin-state.d.ts +20 -0
- package/dist/plugin-distribution/installed-plugin-state.js +73 -0
- package/dist/plugin-distribution/installer.d.ts +89 -0
- package/dist/plugin-distribution/installer.js +395 -0
- package/dist/plugin-distribution/manager.d.ts +128 -0
- package/dist/plugin-distribution/manager.js +358 -0
- package/dist/plugin-distribution/path-safety.d.ts +2 -0
- package/dist/plugin-distribution/path-safety.js +20 -0
- package/dist/plugin-distribution/plugin-bundle-verifier.d.ts +28 -0
- package/dist/plugin-distribution/plugin-bundle-verifier.js +96 -0
- package/dist/plugin-distribution/plugin-bundle-worker.d.ts +34 -0
- package/dist/plugin-distribution/plugin-bundle-worker.js +99 -0
- package/dist/plugin-distribution/plugin-bundle.d.ts +16 -0
- package/dist/plugin-distribution/plugin-bundle.js +244 -0
- package/dist/plugin-distribution/plugin-bundle.worker.d.ts +1 -0
- package/dist/plugin-distribution/plugin-bundle.worker.js +38 -0
- package/dist/plugin-distribution/registry-cache.d.ts +26 -0
- package/dist/plugin-distribution/registry-cache.js +85 -0
- package/dist/plugin-distribution/registry-client.d.ts +36 -0
- package/dist/plugin-distribution/registry-client.js +115 -0
- package/dist/plugin-distribution/reserved-ids.d.ts +4 -0
- package/dist/plugin-distribution/reserved-ids.js +10 -0
- package/dist/plugin-distribution/runtime-validation.d.ts +14 -0
- package/dist/plugin-distribution/runtime-validation.js +388 -0
- package/dist/plugin-distribution/schemas.d.ts +4895 -0
- package/dist/plugin-distribution/schemas.js +299 -0
- package/dist/plugin-distribution/signing.d.ts +5 -0
- package/dist/plugin-distribution/signing.js +38 -0
- package/dist/plugin-distribution/types.d.ts +217 -0
- package/dist/plugin-distribution/types.js +1 -0
- package/dist/plugin-install-progress.d.ts +15 -0
- package/dist/plugin-install-progress.js +86 -0
- package/dist/plugin-manager.d.ts +306 -0
- package/dist/plugin-manager.js +2848 -0
- package/dist/plugin-runtime-entry.d.ts +19 -0
- package/dist/plugin-runtime-entry.js +135 -0
- package/dist/plugin.d.ts +350 -0
- package/dist/plugin.js +754 -0
- package/dist/popover.d.ts +20 -0
- package/dist/popover.js +32 -0
- package/dist/promise-worker.d.ts +22 -0
- package/dist/promise-worker.js +65 -0
- package/dist/prompt-confirm.d.ts +9 -0
- package/dist/prompt-confirm.js +33 -0
- package/dist/search-document-provider.d.ts +45 -0
- package/dist/search-document-provider.js +54 -0
- package/dist/search-query/index.d.ts +78 -0
- package/dist/search-query/index.js +426 -0
- package/dist/search-query/parser.d.ts +3 -0
- package/dist/search-query/parser.js +16 -0
- package/dist/search-query/parser.terms.js +26 -0
- package/dist/search-query/search-query.grammar +128 -0
- package/dist/search.d.ts +19 -0
- package/dist/search.js +104 -0
- package/dist/setting-section-layout.d.ts +19 -0
- package/dist/setting-section-layout.js +194 -0
- package/dist/settings.svelte.d.ts +474 -0
- package/dist/settings.svelte.js +1421 -0
- package/dist/source-text-file-view.d.ts +25 -0
- package/dist/source-text-file-view.js +78 -0
- package/dist/status-bar.svelte.d.ts +29 -0
- package/dist/status-bar.svelte.js +72 -0
- package/dist/storage/app-database.d.ts +860 -0
- package/dist/storage/app-database.js +2372 -0
- package/dist/storage/blob-store.d.ts +12 -0
- package/dist/storage/blob-store.js +1 -0
- package/dist/storage/browser-app-database-coordination.d.ts +35 -0
- package/dist/storage/browser-app-database-coordination.js +207 -0
- package/dist/storage/browser-coordinated-app-database.d.ts +109 -0
- package/dist/storage/browser-coordinated-app-database.js +704 -0
- package/dist/storage/browser.d.ts +153 -0
- package/dist/storage/browser.js +794 -0
- package/dist/storage/desktop-native.d.ts +184 -0
- package/dist/storage/desktop-native.js +415 -0
- package/dist/storage/fs.d.ts +188 -0
- package/dist/storage/fs.js +307 -0
- package/dist/storage/index-projection.d.ts +236 -0
- package/dist/storage/index-projection.js +402 -0
- package/dist/storage/index.d.ts +17 -0
- package/dist/storage/index.js +17 -0
- package/dist/storage/keyval.d.ts +94 -0
- package/dist/storage/keyval.js +199 -0
- package/dist/storage/memory-vault-adapter.d.ts +44 -0
- package/dist/storage/memory-vault-adapter.js +351 -0
- package/dist/storage/native-vault-bootstrap-kv.d.ts +22 -0
- package/dist/storage/native-vault-bootstrap-kv.js +96 -0
- package/dist/storage/path.d.ts +22 -0
- package/dist/storage/path.js +110 -0
- package/dist/storage/search-embedding-provider.d.ts +75 -0
- package/dist/storage/search-embedding-provider.js +446 -0
- package/dist/storage/search-embedding-worker.d.ts +1 -0
- package/dist/storage/search-embedding-worker.js +63 -0
- package/dist/storage/search-query-evaluator.d.ts +14 -0
- package/dist/storage/search-query-evaluator.js +678 -0
- package/dist/storage/task-projection.d.ts +152 -0
- package/dist/storage/task-projection.js +154 -0
- package/dist/storage/turso-app-database.d.ts +150 -0
- package/dist/storage/turso-app-database.js +2671 -0
- package/dist/storage/vault-session.d.ts +37 -0
- package/dist/storage/vault-session.js +196 -0
- package/dist/storage/vault-state.d.ts +74 -0
- package/dist/storage/vault-state.js +181 -0
- package/dist/storage/vault.svelte.d.ts +257 -0
- package/dist/storage/vault.svelte.js +661 -0
- package/dist/suggest.d.ts +193 -0
- package/dist/suggest.js +391 -0
- package/dist/tasks.d.ts +7 -0
- package/dist/tasks.js +18 -0
- package/dist/telemetry.d.ts +116 -0
- package/dist/telemetry.js +103 -0
- package/dist/utils.d.ts +55 -0
- package/dist/utils.js +314 -0
- package/dist/vault-api.d.ts +5 -0
- package/dist/vault-api.js +3 -0
- package/dist/vault-maintenance-commands.d.ts +5 -0
- package/dist/vault-maintenance-commands.js +32 -0
- package/dist/view.svelte.d.ts +215 -0
- package/dist/view.svelte.js +381 -0
- package/dist/vite-env.d.ts +2 -0
- package/dist/workspace-host-internal.d.ts +7 -0
- package/dist/workspace-host-internal.js +7 -0
- package/dist/workspace-host.d.ts +10 -0
- package/dist/workspace-host.js +14 -0
- package/dist/workspace-layout-commands.d.ts +3 -0
- package/dist/workspace-layout-commands.js +72 -0
- package/dist/workspace-layout-normalizer.d.ts +92 -0
- package/dist/workspace-layout-normalizer.js +301 -0
- package/dist/workspace-layouts.d.ts +7 -0
- package/dist/workspace-layouts.js +23 -0
- package/dist/workspace-trust.d.ts +32 -0
- package/dist/workspace-trust.js +72 -0
- package/dist/workspace.svelte.d.ts +796 -0
- package/dist/workspace.svelte.js +4380 -0
- package/package.json +240 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Scope } from "./command.svelte";
|
|
2
|
+
import type { App } from "./context.svelte";
|
|
3
|
+
import type { Editor, EditorPosition } from "./editor.svelte";
|
|
4
|
+
import type { TFile } from "./storage";
|
|
5
|
+
import { Modal } from "./settings.svelte";
|
|
6
|
+
import { type FuzzyMatch } from "./search";
|
|
7
|
+
export interface CloseableComponent {
|
|
8
|
+
close(): void;
|
|
9
|
+
}
|
|
10
|
+
/** @public */
|
|
11
|
+
export interface ISuggestOwner<T> {
|
|
12
|
+
/**
|
|
13
|
+
* Render the suggestion item into DOM.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
renderSuggestion(value: T, el: HTMLElement): void;
|
|
18
|
+
/**
|
|
19
|
+
* Called when the user makes a selection.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Base class for adding a type-ahead popover.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare abstract class PopoverSuggest<T> implements ISuggestOwner<T>, CloseableComponent {
|
|
31
|
+
readonly app: App;
|
|
32
|
+
readonly scope?: Scope | undefined;
|
|
33
|
+
/** @public */
|
|
34
|
+
constructor(app: App, scope?: Scope | undefined);
|
|
35
|
+
/** @public */
|
|
36
|
+
open(): void;
|
|
37
|
+
/** @public */
|
|
38
|
+
close(): void;
|
|
39
|
+
/**
|
|
40
|
+
* @inheritDoc
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
abstract renderSuggestion(value: T, el: HTMLElement): void;
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
abstract selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void;
|
|
49
|
+
}
|
|
50
|
+
export declare abstract class AbstractInputSuggest<T> extends PopoverSuggest<T> {
|
|
51
|
+
readonly textInputEl: HTMLInputElement | HTMLDivElement;
|
|
52
|
+
limit: number;
|
|
53
|
+
suggestEl: HTMLElement;
|
|
54
|
+
instructionContainerEl: HTMLElement;
|
|
55
|
+
emptyStateEl: HTMLElement;
|
|
56
|
+
private instructions;
|
|
57
|
+
private suggestions;
|
|
58
|
+
private itemElements;
|
|
59
|
+
private activeIndex;
|
|
60
|
+
private isOpen;
|
|
61
|
+
private selectCallback;
|
|
62
|
+
constructor(app: App, textInputEl: HTMLInputElement | HTMLDivElement);
|
|
63
|
+
setValue(value: string): void;
|
|
64
|
+
getValue(): string;
|
|
65
|
+
protected abstract getSuggestions(query: string): T[] | Promise<T[]>;
|
|
66
|
+
open(): void;
|
|
67
|
+
close(): void;
|
|
68
|
+
selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void;
|
|
69
|
+
setInstructions(instructions: Instruction[]): this;
|
|
70
|
+
onSelect(callback: (value: T, evt: MouseEvent | KeyboardEvent) => any): this;
|
|
71
|
+
private readonly onInput;
|
|
72
|
+
private readonly onBlur;
|
|
73
|
+
private readonly onKeyDown;
|
|
74
|
+
private attachSuggestEl;
|
|
75
|
+
private updateSuggestions;
|
|
76
|
+
private renderInstructions;
|
|
77
|
+
private setActiveSuggestion;
|
|
78
|
+
}
|
|
79
|
+
export declare abstract class SuggestModal<T> extends Modal implements ISuggestOwner<T> {
|
|
80
|
+
limit: number;
|
|
81
|
+
emptyStateText: string;
|
|
82
|
+
inputEl: HTMLInputElement;
|
|
83
|
+
instructionContainerEl: HTMLElement;
|
|
84
|
+
resultContainerEl: HTMLElement;
|
|
85
|
+
private instructions;
|
|
86
|
+
private suggestions;
|
|
87
|
+
private itemElements;
|
|
88
|
+
private activeIndex;
|
|
89
|
+
private activeSuggestion;
|
|
90
|
+
constructor(app: App);
|
|
91
|
+
setPlaceholder(placeholder: string): void;
|
|
92
|
+
setInstructions(instructions: Instruction[]): void;
|
|
93
|
+
onNoSuggestion(): void;
|
|
94
|
+
updateSuggestions(): Promise<void>;
|
|
95
|
+
open(): void;
|
|
96
|
+
selectSuggestion(value: T, evt: MouseEvent | KeyboardEvent): void;
|
|
97
|
+
selectActiveSuggestion(evt: MouseEvent | KeyboardEvent): void;
|
|
98
|
+
private renderInstructions;
|
|
99
|
+
private setActiveSuggestion;
|
|
100
|
+
private onKeyDown;
|
|
101
|
+
abstract getSuggestions(query: string): T[] | Promise<T[]>;
|
|
102
|
+
abstract renderSuggestion(value: T, el: HTMLElement): void;
|
|
103
|
+
abstract onChooseSuggestion(item: T, evt: MouseEvent | KeyboardEvent): void;
|
|
104
|
+
}
|
|
105
|
+
export declare abstract class FuzzySuggestModal<T> extends SuggestModal<FuzzyMatch<T>> {
|
|
106
|
+
getSuggestions(query: string): FuzzyMatch<T>[];
|
|
107
|
+
renderSuggestion(item: FuzzyMatch<T>, el: HTMLElement): void;
|
|
108
|
+
onChooseSuggestion(item: FuzzyMatch<T>, evt: MouseEvent | KeyboardEvent): void;
|
|
109
|
+
abstract getItems(): T[];
|
|
110
|
+
abstract getItemText(item: T): string;
|
|
111
|
+
abstract onChooseItem(item: T, evt: MouseEvent | KeyboardEvent): void;
|
|
112
|
+
}
|
|
113
|
+
/** @public */
|
|
114
|
+
export interface EditorSuggestContext extends EditorSuggestTriggerInfo {
|
|
115
|
+
/** @public */
|
|
116
|
+
editor: Editor;
|
|
117
|
+
/** @public */
|
|
118
|
+
file: TFile;
|
|
119
|
+
}
|
|
120
|
+
/** @public */
|
|
121
|
+
export interface EditorSuggestTriggerInfo {
|
|
122
|
+
/**
|
|
123
|
+
* The start position of the triggering text. This is used to position the
|
|
124
|
+
* popover.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
start: EditorPosition;
|
|
129
|
+
/**
|
|
130
|
+
* The end position of the triggering text. This is used to position the
|
|
131
|
+
* popover.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
end: EditorPosition;
|
|
136
|
+
/**
|
|
137
|
+
* They query string (usually the text between start and end) that will be
|
|
138
|
+
* used to generate the suggestion content.
|
|
139
|
+
*
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
query: string;
|
|
143
|
+
}
|
|
144
|
+
export interface Instruction {
|
|
145
|
+
/** @public */
|
|
146
|
+
command: string;
|
|
147
|
+
/** @public */
|
|
148
|
+
purpose: string;
|
|
149
|
+
}
|
|
150
|
+
export declare abstract class EditorSuggest<T> extends PopoverSuggest<T> {
|
|
151
|
+
/**
|
|
152
|
+
* Current suggestion context, containing the result of `onTrigger`. This will
|
|
153
|
+
* be null any time the EditorSuggest is not supposed to run.
|
|
154
|
+
*
|
|
155
|
+
* @public
|
|
156
|
+
*/
|
|
157
|
+
context: EditorSuggestContext | null;
|
|
158
|
+
scope: Scope;
|
|
159
|
+
suggestEl: HTMLElement;
|
|
160
|
+
/**
|
|
161
|
+
* Override this to use a different limit for suggestion items
|
|
162
|
+
*
|
|
163
|
+
* @public
|
|
164
|
+
*/
|
|
165
|
+
limit: number;
|
|
166
|
+
/** @public */
|
|
167
|
+
constructor(app: App);
|
|
168
|
+
/** @public */
|
|
169
|
+
setInstructions(instructions: Instruction[]): void;
|
|
170
|
+
close(): void;
|
|
171
|
+
open(): void;
|
|
172
|
+
/**
|
|
173
|
+
* Based on the editor line and cursor position, determine if this
|
|
174
|
+
* EditorSuggest should be triggered at this moment. Typically, you would run
|
|
175
|
+
* a regular expression on the current line text before the cursor. Return
|
|
176
|
+
* null to indicate that this editor suggest is not supposed to be triggered.
|
|
177
|
+
*
|
|
178
|
+
* Please be mindful of performance when implementing this function, as it
|
|
179
|
+
* will be triggered very often (on each keypress). Keep it simple, and return
|
|
180
|
+
* null as early as possible if you determine that it is not the right time.
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
abstract onTrigger(cursor: EditorPosition, editor: Editor, file: TFile | null): EditorSuggestTriggerInfo | null;
|
|
185
|
+
/**
|
|
186
|
+
* Generate suggestion items based on this context. Can be async, but
|
|
187
|
+
* preferably sync. When generating async suggestions, you should pass the
|
|
188
|
+
* context along.
|
|
189
|
+
*
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
abstract getSuggestions(context: EditorSuggestContext): T[] | Promise<T[]>;
|
|
193
|
+
}
|
package/dist/suggest.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { Scope } from "./command.svelte";
|
|
2
|
+
import { closeCompletion, startCompletion } from "@codemirror/autocomplete";
|
|
3
|
+
import { Modal } from "./settings.svelte";
|
|
4
|
+
import { prepareFuzzySearch, renderMatches } from "./search";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for adding a type-ahead popover.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export class PopoverSuggest {
|
|
11
|
+
app;
|
|
12
|
+
scope;
|
|
13
|
+
/** @public */
|
|
14
|
+
constructor(app, scope) {
|
|
15
|
+
this.app = app;
|
|
16
|
+
this.scope = scope;
|
|
17
|
+
}
|
|
18
|
+
/** @public */
|
|
19
|
+
open() { }
|
|
20
|
+
/** @public */
|
|
21
|
+
close() { }
|
|
22
|
+
}
|
|
23
|
+
export class AbstractInputSuggest extends PopoverSuggest {
|
|
24
|
+
textInputEl;
|
|
25
|
+
limit = 100;
|
|
26
|
+
suggestEl;
|
|
27
|
+
instructionContainerEl;
|
|
28
|
+
emptyStateEl;
|
|
29
|
+
instructions = [];
|
|
30
|
+
suggestions = [];
|
|
31
|
+
itemElements = [];
|
|
32
|
+
activeIndex = -1;
|
|
33
|
+
isOpen = false;
|
|
34
|
+
selectCallback = null;
|
|
35
|
+
constructor(app, textInputEl) {
|
|
36
|
+
super(app);
|
|
37
|
+
this.textInputEl = textInputEl;
|
|
38
|
+
this.suggestEl = createDomElement("div");
|
|
39
|
+
this.instructionContainerEl = createDomElement("div");
|
|
40
|
+
this.emptyStateEl = createDomElement("div");
|
|
41
|
+
this.suggestEl.className = "suggestion-container";
|
|
42
|
+
this.instructionContainerEl.className = "prompt-instructions";
|
|
43
|
+
this.emptyStateEl.className = "suggestion-empty";
|
|
44
|
+
this.emptyStateEl.textContent = "No results found";
|
|
45
|
+
}
|
|
46
|
+
setValue(value) {
|
|
47
|
+
if (isTextInputElement(this.textInputEl)) {
|
|
48
|
+
this.textInputEl.value = value;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.textInputEl.textContent = value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
getValue() {
|
|
55
|
+
return isTextInputElement(this.textInputEl)
|
|
56
|
+
? this.textInputEl.value
|
|
57
|
+
: (this.textInputEl.textContent ?? "");
|
|
58
|
+
}
|
|
59
|
+
open() {
|
|
60
|
+
if (this.isOpen) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.isOpen = true;
|
|
64
|
+
this.attachSuggestEl();
|
|
65
|
+
this.textInputEl.addEventListener("input", this.onInput);
|
|
66
|
+
this.textInputEl.addEventListener("keydown", this.onKeyDown);
|
|
67
|
+
this.textInputEl.addEventListener("blur", this.onBlur);
|
|
68
|
+
void this.updateSuggestions();
|
|
69
|
+
}
|
|
70
|
+
close() {
|
|
71
|
+
if (!this.isOpen) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
this.isOpen = false;
|
|
75
|
+
this.textInputEl.removeEventListener("input", this.onInput);
|
|
76
|
+
this.textInputEl.removeEventListener("keydown", this.onKeyDown);
|
|
77
|
+
this.textInputEl.removeEventListener("blur", this.onBlur);
|
|
78
|
+
this.suggestions = [];
|
|
79
|
+
this.itemElements = [];
|
|
80
|
+
this.activeIndex = -1;
|
|
81
|
+
this.suggestEl.replaceChildren();
|
|
82
|
+
this.suggestEl.remove?.();
|
|
83
|
+
}
|
|
84
|
+
selectSuggestion(value, evt) {
|
|
85
|
+
this.selectCallback?.(value, evt);
|
|
86
|
+
this.close();
|
|
87
|
+
}
|
|
88
|
+
setInstructions(instructions) {
|
|
89
|
+
this.instructions = instructions.slice();
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
onSelect(callback) {
|
|
93
|
+
this.selectCallback = callback;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
onInput = () => {
|
|
97
|
+
void this.updateSuggestions();
|
|
98
|
+
};
|
|
99
|
+
onBlur = () => {
|
|
100
|
+
setTimeout(() => this.close(), 0);
|
|
101
|
+
};
|
|
102
|
+
onKeyDown = (evt) => {
|
|
103
|
+
if (!this.suggestions.length) {
|
|
104
|
+
if (evt.key === "Escape") {
|
|
105
|
+
evt.preventDefault();
|
|
106
|
+
this.close();
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (evt.key === "ArrowDown") {
|
|
111
|
+
evt.preventDefault();
|
|
112
|
+
this.setActiveSuggestion((this.activeIndex + 1) % this.suggestions.length);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (evt.key === "ArrowUp") {
|
|
116
|
+
evt.preventDefault();
|
|
117
|
+
this.setActiveSuggestion((this.activeIndex - 1 + this.suggestions.length) %
|
|
118
|
+
this.suggestions.length);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (evt.key === "Enter" || evt.key === "Tab") {
|
|
122
|
+
evt.preventDefault();
|
|
123
|
+
this.selectSuggestion(this.suggestions[this.activeIndex], evt);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (evt.key === "Escape") {
|
|
127
|
+
evt.preventDefault();
|
|
128
|
+
this.close();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
attachSuggestEl() {
|
|
132
|
+
const parent = this.textInputEl.parentElement ??
|
|
133
|
+
document.body ??
|
|
134
|
+
document.documentElement;
|
|
135
|
+
if (!this.suggestEl.parentElement) {
|
|
136
|
+
parent?.append(this.suggestEl);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async updateSuggestions() {
|
|
140
|
+
const suggestions = await this.getSuggestions(this.getValue());
|
|
141
|
+
const visible = this.limit > 0 ? suggestions.slice(0, this.limit) : suggestions;
|
|
142
|
+
this.suggestions = visible;
|
|
143
|
+
this.itemElements = [];
|
|
144
|
+
this.suggestEl.replaceChildren();
|
|
145
|
+
this.renderInstructions();
|
|
146
|
+
if (!visible.length) {
|
|
147
|
+
this.activeIndex = -1;
|
|
148
|
+
this.suggestEl.append(this.emptyStateEl);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
visible.forEach((suggestion, index) => {
|
|
152
|
+
const itemEl = createDomElement("div");
|
|
153
|
+
itemEl.className = "suggestion-item";
|
|
154
|
+
this.renderSuggestion(suggestion, itemEl);
|
|
155
|
+
itemEl.addEventListener("mousedown", (evt) => {
|
|
156
|
+
evt.preventDefault();
|
|
157
|
+
this.selectSuggestion(suggestion, evt);
|
|
158
|
+
});
|
|
159
|
+
itemEl.addEventListener("mouseenter", () => {
|
|
160
|
+
this.setActiveSuggestion(index);
|
|
161
|
+
});
|
|
162
|
+
this.suggestEl.append(itemEl);
|
|
163
|
+
this.itemElements.push(itemEl);
|
|
164
|
+
});
|
|
165
|
+
this.setActiveSuggestion(0);
|
|
166
|
+
}
|
|
167
|
+
renderInstructions() {
|
|
168
|
+
this.instructionContainerEl.replaceChildren();
|
|
169
|
+
if (!this.instructions.length) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
for (const instruction of this.instructions) {
|
|
173
|
+
const row = createDomElement("div");
|
|
174
|
+
row.className = "prompt-instruction";
|
|
175
|
+
const commandEl = createDomElement("span");
|
|
176
|
+
commandEl.className = "prompt-instruction-command";
|
|
177
|
+
commandEl.textContent = instruction.command;
|
|
178
|
+
const purposeEl = createDomElement("span");
|
|
179
|
+
purposeEl.className = "prompt-instruction-purpose";
|
|
180
|
+
purposeEl.textContent = instruction.purpose;
|
|
181
|
+
row.append(commandEl, purposeEl);
|
|
182
|
+
this.instructionContainerEl.append(row);
|
|
183
|
+
}
|
|
184
|
+
this.suggestEl.append(this.instructionContainerEl);
|
|
185
|
+
}
|
|
186
|
+
setActiveSuggestion(index) {
|
|
187
|
+
this.activeIndex = index;
|
|
188
|
+
this.itemElements.forEach((itemEl, itemIndex) => {
|
|
189
|
+
const active = itemIndex === index;
|
|
190
|
+
itemEl.classList.toggle("is-selected", active);
|
|
191
|
+
itemEl.setAttribute("aria-selected", active ? "true" : "false");
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function createDomElement(tag) {
|
|
196
|
+
return document.createElement(tag);
|
|
197
|
+
}
|
|
198
|
+
function isTextInputElement(element) {
|
|
199
|
+
return ((typeof HTMLInputElement !== "undefined" &&
|
|
200
|
+
element instanceof HTMLInputElement) ||
|
|
201
|
+
("value" in element && typeof element.value === "string"));
|
|
202
|
+
}
|
|
203
|
+
export class SuggestModal extends Modal {
|
|
204
|
+
limit = 100;
|
|
205
|
+
emptyStateText = "No results found";
|
|
206
|
+
inputEl;
|
|
207
|
+
instructionContainerEl;
|
|
208
|
+
resultContainerEl;
|
|
209
|
+
instructions = [];
|
|
210
|
+
suggestions = [];
|
|
211
|
+
itemElements = [];
|
|
212
|
+
activeIndex = -1;
|
|
213
|
+
activeSuggestion = null;
|
|
214
|
+
constructor(app) {
|
|
215
|
+
super(app);
|
|
216
|
+
this.inputEl = createDomElement("input");
|
|
217
|
+
this.instructionContainerEl = createDomElement("div");
|
|
218
|
+
this.resultContainerEl = createDomElement("div");
|
|
219
|
+
this.inputEl.type = "text";
|
|
220
|
+
this.inputEl.className = "prompt-input";
|
|
221
|
+
this.instructionContainerEl.className = "prompt-instructions";
|
|
222
|
+
this.resultContainerEl.className = "suggestion-container";
|
|
223
|
+
this.containerEl?.append(this.inputEl, this.instructionContainerEl, this.resultContainerEl);
|
|
224
|
+
this.inputEl.addEventListener("input", () => {
|
|
225
|
+
void this.updateSuggestions();
|
|
226
|
+
});
|
|
227
|
+
this.inputEl.addEventListener("keydown", (evt) => {
|
|
228
|
+
this.onKeyDown(evt);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
setPlaceholder(placeholder) {
|
|
232
|
+
this.inputEl.placeholder = placeholder;
|
|
233
|
+
}
|
|
234
|
+
setInstructions(instructions) {
|
|
235
|
+
this.instructions = instructions.slice();
|
|
236
|
+
this.renderInstructions();
|
|
237
|
+
}
|
|
238
|
+
onNoSuggestion() {
|
|
239
|
+
this.suggestions = [];
|
|
240
|
+
this.itemElements = [];
|
|
241
|
+
this.activeIndex = -1;
|
|
242
|
+
this.activeSuggestion = null;
|
|
243
|
+
this.resultContainerEl.textContent = this.emptyStateText;
|
|
244
|
+
}
|
|
245
|
+
async updateSuggestions() {
|
|
246
|
+
const suggestions = await this.getSuggestions(this.inputEl.value);
|
|
247
|
+
const visible = this.limit > 0 ? suggestions.slice(0, this.limit) : suggestions;
|
|
248
|
+
this.suggestions = visible;
|
|
249
|
+
this.resultContainerEl.replaceChildren();
|
|
250
|
+
this.itemElements = [];
|
|
251
|
+
if (!visible.length) {
|
|
252
|
+
this.onNoSuggestion();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
visible.forEach((suggestion, index) => {
|
|
256
|
+
const itemEl = createDomElement("div");
|
|
257
|
+
itemEl.className = "suggestion-item";
|
|
258
|
+
this.renderSuggestion(suggestion, itemEl);
|
|
259
|
+
itemEl.addEventListener("click", (evt) => {
|
|
260
|
+
this.selectSuggestion(suggestion, evt);
|
|
261
|
+
});
|
|
262
|
+
itemEl.addEventListener("mouseenter", () => {
|
|
263
|
+
this.setActiveSuggestion(index);
|
|
264
|
+
});
|
|
265
|
+
this.resultContainerEl.append(itemEl);
|
|
266
|
+
this.itemElements.push(itemEl);
|
|
267
|
+
});
|
|
268
|
+
this.setActiveSuggestion(0);
|
|
269
|
+
}
|
|
270
|
+
open() {
|
|
271
|
+
super.open();
|
|
272
|
+
this.inputEl.focus?.();
|
|
273
|
+
void this.updateSuggestions();
|
|
274
|
+
}
|
|
275
|
+
selectSuggestion(value, evt) {
|
|
276
|
+
this.onChooseSuggestion(value, evt);
|
|
277
|
+
this.close();
|
|
278
|
+
}
|
|
279
|
+
selectActiveSuggestion(evt) {
|
|
280
|
+
if (this.activeSuggestion) {
|
|
281
|
+
this.selectSuggestion(this.activeSuggestion, evt);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
renderInstructions() {
|
|
285
|
+
this.instructionContainerEl.replaceChildren();
|
|
286
|
+
if (!this.instructions.length) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
for (const instruction of this.instructions) {
|
|
290
|
+
const row = createDomElement("div");
|
|
291
|
+
row.className = "prompt-instruction";
|
|
292
|
+
const commandEl = createDomElement("span");
|
|
293
|
+
commandEl.className = "prompt-instruction-command";
|
|
294
|
+
commandEl.textContent = instruction.command;
|
|
295
|
+
const purposeEl = createDomElement("span");
|
|
296
|
+
purposeEl.className = "prompt-instruction-purpose";
|
|
297
|
+
purposeEl.textContent = instruction.purpose;
|
|
298
|
+
row.append(commandEl, purposeEl);
|
|
299
|
+
this.instructionContainerEl.append(row);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
setActiveSuggestion(index) {
|
|
303
|
+
this.activeIndex = index;
|
|
304
|
+
this.activeSuggestion = this.suggestions[index] ?? null;
|
|
305
|
+
this.itemElements.forEach((itemEl, itemIndex) => {
|
|
306
|
+
const active = itemIndex === index;
|
|
307
|
+
itemEl.classList.toggle("is-selected", active);
|
|
308
|
+
itemEl.setAttribute("aria-selected", active ? "true" : "false");
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
onKeyDown(evt) {
|
|
312
|
+
if (!this.suggestions.length) {
|
|
313
|
+
if (evt.key === "Escape") {
|
|
314
|
+
evt.preventDefault();
|
|
315
|
+
this.close();
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (evt.key === "ArrowDown") {
|
|
320
|
+
evt.preventDefault();
|
|
321
|
+
this.setActiveSuggestion((this.activeIndex + 1) % this.suggestions.length);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (evt.key === "ArrowUp") {
|
|
325
|
+
evt.preventDefault();
|
|
326
|
+
this.setActiveSuggestion((this.activeIndex - 1 + this.suggestions.length) %
|
|
327
|
+
this.suggestions.length);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (evt.key === "Enter" || evt.key === "Tab") {
|
|
331
|
+
evt.preventDefault();
|
|
332
|
+
this.selectActiveSuggestion(evt);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (evt.key === "Escape") {
|
|
336
|
+
evt.preventDefault();
|
|
337
|
+
this.close();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
export class FuzzySuggestModal extends SuggestModal {
|
|
342
|
+
getSuggestions(query) {
|
|
343
|
+
const search = prepareFuzzySearch(query);
|
|
344
|
+
return this.getItems()
|
|
345
|
+
.map((item) => {
|
|
346
|
+
const match = search(this.getItemText(item));
|
|
347
|
+
return match ? { item, match } : null;
|
|
348
|
+
})
|
|
349
|
+
.filter((item) => !!item)
|
|
350
|
+
.sort((a, b) => b.match.score - a.match.score);
|
|
351
|
+
}
|
|
352
|
+
renderSuggestion(item, el) {
|
|
353
|
+
renderMatches(el, this.getItemText(item.item), item.match.matches);
|
|
354
|
+
}
|
|
355
|
+
onChooseSuggestion(item, evt) {
|
|
356
|
+
this.onChooseItem(item.item, evt);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
export class EditorSuggest extends PopoverSuggest {
|
|
360
|
+
/**
|
|
361
|
+
* Current suggestion context, containing the result of `onTrigger`. This will
|
|
362
|
+
* be null any time the EditorSuggest is not supposed to run.
|
|
363
|
+
*
|
|
364
|
+
* @public
|
|
365
|
+
*/
|
|
366
|
+
context = null;
|
|
367
|
+
scope = new Scope();
|
|
368
|
+
suggestEl = createDiv();
|
|
369
|
+
/**
|
|
370
|
+
* Override this to use a different limit for suggestion items
|
|
371
|
+
*
|
|
372
|
+
* @public
|
|
373
|
+
*/
|
|
374
|
+
limit = -1;
|
|
375
|
+
/** @public */
|
|
376
|
+
constructor(app) {
|
|
377
|
+
super(app);
|
|
378
|
+
}
|
|
379
|
+
/** @public */
|
|
380
|
+
setInstructions(instructions) { }
|
|
381
|
+
close() {
|
|
382
|
+
if (!this.context)
|
|
383
|
+
return;
|
|
384
|
+
closeCompletion(this.context.editor.cm);
|
|
385
|
+
}
|
|
386
|
+
open() {
|
|
387
|
+
if (!this.context)
|
|
388
|
+
return;
|
|
389
|
+
startCompletion(this.context.editor.cm);
|
|
390
|
+
}
|
|
391
|
+
}
|
package/dist/tasks.d.ts
ADDED
package/dist/tasks.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class Tasks {
|
|
2
|
+
tasks = new Set();
|
|
3
|
+
add(callback) {
|
|
4
|
+
this.addPromise(Promise.resolve().then(callback));
|
|
5
|
+
}
|
|
6
|
+
addPromise(promise) {
|
|
7
|
+
const tracked = Promise.resolve(promise).finally(() => {
|
|
8
|
+
this.tasks.delete(tracked);
|
|
9
|
+
});
|
|
10
|
+
this.tasks.add(tracked);
|
|
11
|
+
}
|
|
12
|
+
isEmpty() {
|
|
13
|
+
return this.tasks.size === 0;
|
|
14
|
+
}
|
|
15
|
+
promise() {
|
|
16
|
+
return Promise.all([...this.tasks]);
|
|
17
|
+
}
|
|
18
|
+
}
|