@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,571 @@
|
|
|
1
|
+
import { EventDispatcher } from "./events";
|
|
2
|
+
import { resolveApplication } from "./application-compatibility";
|
|
3
|
+
const HOTKEYS_PATH = "/.obsidian/hotkeys.json";
|
|
4
|
+
const MODIFIER_ORDER = ["Mod", "Ctrl", "Meta", "Alt", "Shift"];
|
|
5
|
+
const WORKSPACE_ROOT_COMMAND_HOST_ID = "root";
|
|
6
|
+
function isModifierValue(value) {
|
|
7
|
+
return (value === "Mod" ||
|
|
8
|
+
value === "Ctrl" ||
|
|
9
|
+
value === "Meta" ||
|
|
10
|
+
value === "Shift" ||
|
|
11
|
+
value === "Alt");
|
|
12
|
+
}
|
|
13
|
+
function normalizeStoredHotkey(hotkey) {
|
|
14
|
+
const modifiers = Array.from(new Set(hotkey.modifiers.filter(isModifierValue))).sort((a, b) => MODIFIER_ORDER.indexOf(a) - MODIFIER_ORDER.indexOf(b));
|
|
15
|
+
return {
|
|
16
|
+
modifiers,
|
|
17
|
+
key: hotkey.key.length === 1 ? hotkey.key.toUpperCase() : hotkey.key,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function parseHotkey(value) {
|
|
21
|
+
if (!value ||
|
|
22
|
+
typeof value !== "object" ||
|
|
23
|
+
!Array.isArray(value.modifiers) ||
|
|
24
|
+
typeof value.key !== "string" ||
|
|
25
|
+
!value.key.trim()) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return normalizeStoredHotkey({
|
|
29
|
+
modifiers: value.modifiers.filter(isModifierValue),
|
|
30
|
+
key: value.key.trim(),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function getPlatformMod() {
|
|
34
|
+
const navigatorLike = globalThis.navigator;
|
|
35
|
+
const platform = navigatorLike?.userAgentData?.platform ?? navigatorLike?.platform ?? "";
|
|
36
|
+
return /mac/i.test(platform) ? "Meta" : "Ctrl";
|
|
37
|
+
}
|
|
38
|
+
function normalizeHotkey(hotkey) {
|
|
39
|
+
return {
|
|
40
|
+
...hotkey,
|
|
41
|
+
modifiers: hotkey.modifiers.map((modifier) => modifier === "Mod" ? getPlatformMod() : modifier),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function keyId(hotkey) {
|
|
45
|
+
const normalized = normalizeHotkey(hotkey);
|
|
46
|
+
const parts = [];
|
|
47
|
+
parts.push(...normalized.modifiers.slice().sort());
|
|
48
|
+
if (normalized.key) {
|
|
49
|
+
parts.push(normalized.key.length === 1
|
|
50
|
+
? normalized.key.toUpperCase()
|
|
51
|
+
: normalized.key);
|
|
52
|
+
}
|
|
53
|
+
return parts.join("+");
|
|
54
|
+
}
|
|
55
|
+
export function getHotkeyId(hotkey) {
|
|
56
|
+
return keyId(hotkey);
|
|
57
|
+
}
|
|
58
|
+
export class CommandManager extends EventDispatcher {
|
|
59
|
+
app;
|
|
60
|
+
open = $state(false);
|
|
61
|
+
openHostId = $state(WORKSPACE_ROOT_COMMAND_HOST_ID);
|
|
62
|
+
commands = $state({});
|
|
63
|
+
editorCommands = $state({});
|
|
64
|
+
bindings = $state({});
|
|
65
|
+
hotkeyOverrides = $state({});
|
|
66
|
+
constructor(app) {
|
|
67
|
+
super();
|
|
68
|
+
this.app = app;
|
|
69
|
+
}
|
|
70
|
+
currentHostId() {
|
|
71
|
+
return (this.app.workspace?.getFocusedCommandHostId?.() ??
|
|
72
|
+
WORKSPACE_ROOT_COMMAND_HOST_ID);
|
|
73
|
+
}
|
|
74
|
+
isOpenForHost(hostId) {
|
|
75
|
+
return this.open && this.openHostId === hostId;
|
|
76
|
+
}
|
|
77
|
+
resolveExecutionContext(hostId = this.currentHostId()) {
|
|
78
|
+
const activeLeaf = this.app.workspace?.getCommandHostLeaf?.(hostId) ??
|
|
79
|
+
this.app.workspace?.activeLeaf;
|
|
80
|
+
const view = activeLeaf?.view;
|
|
81
|
+
return {
|
|
82
|
+
view,
|
|
83
|
+
editor: view?.editor,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
hasExecutableHandler(command) {
|
|
87
|
+
return Boolean(command.callback ||
|
|
88
|
+
command.checkCallback ||
|
|
89
|
+
command.editorCallback ||
|
|
90
|
+
command.editorCheckCallback);
|
|
91
|
+
}
|
|
92
|
+
toCommandMetadata(command) {
|
|
93
|
+
return {
|
|
94
|
+
id: command.id,
|
|
95
|
+
label: command.name,
|
|
96
|
+
title: command.title ?? command.name,
|
|
97
|
+
category: command.category,
|
|
98
|
+
icon: command.icon,
|
|
99
|
+
hotkeys: this.getEffectiveHotkeys(command.id),
|
|
100
|
+
sourcePlugin: command.sourcePlugin,
|
|
101
|
+
activationEvent: command.activationEvent,
|
|
102
|
+
argumentSchema: command.argumentSchema,
|
|
103
|
+
when: command.when,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
hasHotkeyOverride(commandId) {
|
|
107
|
+
return Object.hasOwn(this.hotkeyOverrides, commandId);
|
|
108
|
+
}
|
|
109
|
+
bindCommandHotkeys(command) {
|
|
110
|
+
if (!this.hasExecutableHandler(command)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
for (const key of this.getEffectiveHotkeys(command.id)) {
|
|
114
|
+
const id = keyId(key);
|
|
115
|
+
this.bindings[id] ||= [];
|
|
116
|
+
this.bindings[id].push(command);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
rebuildBindings() {
|
|
120
|
+
for (const id of Object.keys(this.bindings)) {
|
|
121
|
+
delete this.bindings[id];
|
|
122
|
+
}
|
|
123
|
+
for (const command of this.getAllCommands()) {
|
|
124
|
+
this.bindCommandHotkeys(command);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
readHotkeyOverrideFile() {
|
|
128
|
+
return (this.app.vault?.getFileByPath?.(HOTKEYS_PATH) ?? null);
|
|
129
|
+
}
|
|
130
|
+
normalizeOverrides(value) {
|
|
131
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
const overrides = {};
|
|
135
|
+
for (const [commandId, hotkeys] of Object.entries(value)) {
|
|
136
|
+
if (!Array.isArray(hotkeys)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const parsed = hotkeys
|
|
140
|
+
.map((hotkey) => parseHotkey(hotkey))
|
|
141
|
+
.filter((hotkey) => Boolean(hotkey));
|
|
142
|
+
overrides[commandId] = this.dedupeHotkeys(parsed);
|
|
143
|
+
}
|
|
144
|
+
return overrides;
|
|
145
|
+
}
|
|
146
|
+
dedupeHotkeys(hotkeys) {
|
|
147
|
+
const seen = new Set();
|
|
148
|
+
const deduped = [];
|
|
149
|
+
for (const hotkey of hotkeys.map(normalizeStoredHotkey)) {
|
|
150
|
+
const id = keyId(hotkey);
|
|
151
|
+
if (seen.has(id)) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
seen.add(id);
|
|
155
|
+
deduped.push(hotkey);
|
|
156
|
+
}
|
|
157
|
+
return deduped;
|
|
158
|
+
}
|
|
159
|
+
async loadHotkeys() {
|
|
160
|
+
const file = this.readHotkeyOverrideFile();
|
|
161
|
+
if (!file) {
|
|
162
|
+
this.replaceHotkeyOverrides({});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
const raw = await this.app.vault.read(file);
|
|
167
|
+
this.replaceHotkeyOverrides(this.normalizeOverrides(JSON.parse(raw)));
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.warn("Unable to load hotkeys.json; ignoring custom hotkeys", error);
|
|
171
|
+
this.replaceHotkeyOverrides({});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async saveHotkeys() {
|
|
175
|
+
const data = JSON.stringify(this.hotkeyOverrides, null, 2);
|
|
176
|
+
const file = this.readHotkeyOverrideFile();
|
|
177
|
+
if (file) {
|
|
178
|
+
await this.app.vault.modify(file, data);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
await this.app.vault.mkpath("/.obsidian");
|
|
182
|
+
await this.app.vault.create(HOTKEYS_PATH, data);
|
|
183
|
+
}
|
|
184
|
+
replaceHotkeyOverrides(overrides) {
|
|
185
|
+
for (const id of Object.keys(this.hotkeyOverrides)) {
|
|
186
|
+
delete this.hotkeyOverrides[id];
|
|
187
|
+
}
|
|
188
|
+
for (const [id, hotkeys] of Object.entries(overrides)) {
|
|
189
|
+
this.hotkeyOverrides[id] = this.dedupeHotkeys(hotkeys);
|
|
190
|
+
}
|
|
191
|
+
this.rebuildBindings();
|
|
192
|
+
this.emit("hotkeys-updated", {
|
|
193
|
+
hotkeys: this.hotkeyOverrides,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
getDefaultHotkeys(commandId) {
|
|
197
|
+
return [...(this.commands[commandId]?.hotkeys ?? [])].map(normalizeStoredHotkey);
|
|
198
|
+
}
|
|
199
|
+
getEffectiveHotkeys(commandId) {
|
|
200
|
+
if (this.hasHotkeyOverride(commandId)) {
|
|
201
|
+
return [...this.hotkeyOverrides[commandId]];
|
|
202
|
+
}
|
|
203
|
+
return this.getDefaultHotkeys(commandId);
|
|
204
|
+
}
|
|
205
|
+
isHotkeyCustomized(commandId) {
|
|
206
|
+
return this.hasHotkeyOverride(commandId);
|
|
207
|
+
}
|
|
208
|
+
async setHotkeys(commandId, hotkeys) {
|
|
209
|
+
this.hotkeyOverrides[commandId] = this.dedupeHotkeys(hotkeys);
|
|
210
|
+
this.rebuildBindings();
|
|
211
|
+
this.emit("hotkeys-updated", {
|
|
212
|
+
commandId,
|
|
213
|
+
hotkeys: this.hotkeyOverrides,
|
|
214
|
+
});
|
|
215
|
+
await this.saveHotkeys();
|
|
216
|
+
}
|
|
217
|
+
async addHotkey(commandId, hotkey) {
|
|
218
|
+
await this.setHotkeys(commandId, [
|
|
219
|
+
...this.getEffectiveHotkeys(commandId),
|
|
220
|
+
hotkey,
|
|
221
|
+
]);
|
|
222
|
+
}
|
|
223
|
+
async removeHotkey(commandId, hotkey) {
|
|
224
|
+
const removeId = keyId(hotkey);
|
|
225
|
+
await this.setHotkeys(commandId, this.getEffectiveHotkeys(commandId).filter((candidate) => keyId(candidate) !== removeId));
|
|
226
|
+
}
|
|
227
|
+
async resetHotkeys(commandId) {
|
|
228
|
+
delete this.hotkeyOverrides[commandId];
|
|
229
|
+
this.rebuildBindings();
|
|
230
|
+
this.emit("hotkeys-updated", {
|
|
231
|
+
commandId,
|
|
232
|
+
hotkeys: this.hotkeyOverrides,
|
|
233
|
+
});
|
|
234
|
+
await this.saveHotkeys();
|
|
235
|
+
}
|
|
236
|
+
getHotkeyAssignments() {
|
|
237
|
+
return this.getAllCommands().map((command) => ({
|
|
238
|
+
command,
|
|
239
|
+
commandId: command.id,
|
|
240
|
+
defaultHotkeys: this.getDefaultHotkeys(command.id),
|
|
241
|
+
hotkeys: this.getEffectiveHotkeys(command.id),
|
|
242
|
+
customized: this.isHotkeyCustomized(command.id),
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
getHotkeyConflicts() {
|
|
246
|
+
const byHotkey = new Map();
|
|
247
|
+
for (const assignment of this.getHotkeyAssignments()) {
|
|
248
|
+
for (const hotkey of assignment.hotkeys) {
|
|
249
|
+
const id = keyId(hotkey);
|
|
250
|
+
const existing = byHotkey.get(id);
|
|
251
|
+
if (existing) {
|
|
252
|
+
existing.commandIds.push(assignment.commandId);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
byHotkey.set(id, {
|
|
256
|
+
hotkey,
|
|
257
|
+
commandIds: [assignment.commandId],
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return Array.from(byHotkey.entries())
|
|
263
|
+
.filter(([, conflict]) => conflict.commandIds.length > 1)
|
|
264
|
+
.map(([hotkeyId, conflict]) => ({
|
|
265
|
+
hotkeyId,
|
|
266
|
+
hotkey: conflict.hotkey,
|
|
267
|
+
commandIds: conflict.commandIds,
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
registerCommand(command) {
|
|
271
|
+
if (!this.commands[command.id]) {
|
|
272
|
+
this.commands[command.id] = command;
|
|
273
|
+
if (!this.editorCommands[command.id] &&
|
|
274
|
+
(command.editorCallback || command.editorCheckCallback)) {
|
|
275
|
+
this.editorCommands[command.id] = command;
|
|
276
|
+
}
|
|
277
|
+
this.bindCommandHotkeys(command);
|
|
278
|
+
this.emit("register", command);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
unregisterCommand(id) {
|
|
282
|
+
const cmd = this.commands[id];
|
|
283
|
+
if (cmd) {
|
|
284
|
+
delete this.commands[id];
|
|
285
|
+
if ((cmd.editorCallback || cmd.editorCheckCallback) &&
|
|
286
|
+
this.editorCommands[id]) {
|
|
287
|
+
delete this.editorCommands[id];
|
|
288
|
+
}
|
|
289
|
+
this.rebuildBindings();
|
|
290
|
+
this.emit("unregister", cmd);
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
getCommand(id) {
|
|
296
|
+
return this.commands[id];
|
|
297
|
+
}
|
|
298
|
+
getCommandMetadata(id) {
|
|
299
|
+
const command = this.getCommand(id);
|
|
300
|
+
return command ? this.toCommandMetadata(command) : undefined;
|
|
301
|
+
}
|
|
302
|
+
isCommandAvailable(id, hostId = this.currentHostId()) {
|
|
303
|
+
const command = this.getCommand(id);
|
|
304
|
+
if (!command) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
const context = this.resolveExecutionContext(hostId);
|
|
308
|
+
if (!this.app.contextKeys.evaluate(command.when)) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
if (command.editorCheckCallback) {
|
|
312
|
+
return Boolean(context.editor &&
|
|
313
|
+
command.editorCheckCallback(true, context.editor, context.view));
|
|
314
|
+
}
|
|
315
|
+
if (command.checkCallback) {
|
|
316
|
+
return Boolean(command.checkCallback(true));
|
|
317
|
+
}
|
|
318
|
+
if (command.editorCallback) {
|
|
319
|
+
return Boolean(context.editor);
|
|
320
|
+
}
|
|
321
|
+
return Boolean(command.callback);
|
|
322
|
+
}
|
|
323
|
+
getAvailableCommands(hostId = this.currentHostId()) {
|
|
324
|
+
return this.getAllCommands().filter((command) => this.isCommandAvailable(command.id, hostId));
|
|
325
|
+
}
|
|
326
|
+
getAvailableCommandMetadata(hostId = this.currentHostId()) {
|
|
327
|
+
return this.getAvailableCommands(hostId).map((command) => this.toCommandMetadata(command));
|
|
328
|
+
}
|
|
329
|
+
async executeCommandWithHost(id, hostId, ...rest) {
|
|
330
|
+
const command = this.commands[id];
|
|
331
|
+
if (!command) {
|
|
332
|
+
return Promise.reject(new Error(`Invalid command: '${id}'`));
|
|
333
|
+
}
|
|
334
|
+
const context = this.resolveExecutionContext(hostId);
|
|
335
|
+
let response;
|
|
336
|
+
if (!this.app.contextKeys.evaluate(command.when)) {
|
|
337
|
+
return Promise.reject(new Error(`Command unavailable: '${id}'`));
|
|
338
|
+
}
|
|
339
|
+
if (command.editorCheckCallback) {
|
|
340
|
+
if (!context.editor ||
|
|
341
|
+
!command.editorCheckCallback(true, context.editor, context.view)) {
|
|
342
|
+
return Promise.reject(new Error(`Command unavailable: '${id}'`));
|
|
343
|
+
}
|
|
344
|
+
response = (await command.editorCheckCallback(false, context.editor, context.view));
|
|
345
|
+
}
|
|
346
|
+
else if (command.checkCallback) {
|
|
347
|
+
if (!command.checkCallback(true)) {
|
|
348
|
+
return Promise.reject(new Error(`Command unavailable: '${id}'`));
|
|
349
|
+
}
|
|
350
|
+
response = (await command.checkCallback(false));
|
|
351
|
+
}
|
|
352
|
+
else if (command.editorCallback) {
|
|
353
|
+
if (!context.editor) {
|
|
354
|
+
return Promise.reject(new Error(`Command unavailable: '${id}'`));
|
|
355
|
+
}
|
|
356
|
+
response = (await command.editorCallback(context.editor, context.view));
|
|
357
|
+
}
|
|
358
|
+
else if (command.callback) {
|
|
359
|
+
response = (await command.callback(...rest));
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
return Promise.reject(new Error(`Command unavailable: '${id}'`));
|
|
363
|
+
}
|
|
364
|
+
this.emit("executed", command);
|
|
365
|
+
return response;
|
|
366
|
+
}
|
|
367
|
+
async executeCommand(id, ...rest) {
|
|
368
|
+
return this.executeCommandWithHost(id, this.currentHostId(), ...rest);
|
|
369
|
+
}
|
|
370
|
+
async executeCommandForHost(id, hostId, ...rest) {
|
|
371
|
+
return this.executeCommandWithHost(id, hostId, ...rest);
|
|
372
|
+
}
|
|
373
|
+
show(hostId = this.currentHostId()) {
|
|
374
|
+
this.openHostId = hostId;
|
|
375
|
+
this.open = true;
|
|
376
|
+
}
|
|
377
|
+
hide(hostId) {
|
|
378
|
+
if (hostId && this.openHostId !== hostId) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
this.open = false;
|
|
382
|
+
}
|
|
383
|
+
toggle(hostId = this.currentHostId()) {
|
|
384
|
+
if (this.isOpenForHost(hostId)) {
|
|
385
|
+
this.hide(hostId);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.show(hostId);
|
|
389
|
+
}
|
|
390
|
+
commandsFor(key) {
|
|
391
|
+
const id = keyId(key);
|
|
392
|
+
return this.bindings[id] || [];
|
|
393
|
+
}
|
|
394
|
+
getAllCommands() {
|
|
395
|
+
return Array.from(Object.values(this.commands));
|
|
396
|
+
}
|
|
397
|
+
getAllCommandMetadata() {
|
|
398
|
+
return this.getAllCommands().map((command) => this.toCommandMetadata(command));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
export class Keymap {
|
|
402
|
+
scopes = [];
|
|
403
|
+
constructor(defaultScope) {
|
|
404
|
+
if (defaultScope) {
|
|
405
|
+
this.scopes.push(defaultScope);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
pushScope(scope) {
|
|
409
|
+
if (!this.scopes.includes(scope)) {
|
|
410
|
+
this.scopes.push(scope);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
popScope(scope) {
|
|
414
|
+
this.scopes = this.scopes.filter((item) => item !== scope);
|
|
415
|
+
}
|
|
416
|
+
handleAdditionalScopes(event) {
|
|
417
|
+
for (let i = this.scopes.length - 1; i >= 1; i--) {
|
|
418
|
+
if (this.scopes[i].handleEvent(event)) {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
handleEvent(event) {
|
|
425
|
+
for (let i = this.scopes.length - 1; i >= 0; i--) {
|
|
426
|
+
if (this.scopes[i].handleEvent(event)) {
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
static isModifier(evt, modifier) {
|
|
433
|
+
switch (modifier) {
|
|
434
|
+
case "Mod":
|
|
435
|
+
return Keymap.isModEvent(evt);
|
|
436
|
+
case "Ctrl":
|
|
437
|
+
return evt.ctrlKey;
|
|
438
|
+
case "Meta":
|
|
439
|
+
return evt.metaKey;
|
|
440
|
+
case "Shift":
|
|
441
|
+
return evt.shiftKey;
|
|
442
|
+
case "Alt":
|
|
443
|
+
return evt.altKey;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
static isModEvent(evt) {
|
|
447
|
+
return navigator.platform.toLowerCase().includes("mac")
|
|
448
|
+
? evt.metaKey
|
|
449
|
+
: evt.ctrlKey;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
export class Scope {
|
|
453
|
+
keyBindings = new Map();
|
|
454
|
+
isMacOS = false;
|
|
455
|
+
application;
|
|
456
|
+
/** @public */
|
|
457
|
+
constructor(parent, application) {
|
|
458
|
+
this.application = application ?? parent?.application;
|
|
459
|
+
if (parent) {
|
|
460
|
+
for (const [key, value] of parent.keyBindings.entries()) {
|
|
461
|
+
const handlers = value.map((h) => ({ ...h, scope: this }));
|
|
462
|
+
this.keyBindings.set(key, handlers);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
get keys() {
|
|
467
|
+
return this.keyBindings.keys();
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Add a keymap event handler to this scope.
|
|
471
|
+
*
|
|
472
|
+
* @param modifiers - `Mod`, `Ctrl`, `Meta`, `Shift`, or `Alt`. `Mod`
|
|
473
|
+
* translates to `Meta` on macOS and `Ctrl` otherwise. Pass `null` to
|
|
474
|
+
* capture all events matching the `key`, regardless of modifiers.
|
|
475
|
+
* @param key - Keycode from
|
|
476
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key%5FValues
|
|
477
|
+
* @param func - The callback that will be called when a user triggers the
|
|
478
|
+
* keybind.
|
|
479
|
+
* @public
|
|
480
|
+
*/
|
|
481
|
+
register(modifiers, key, func) {
|
|
482
|
+
const binding = {
|
|
483
|
+
modifiers: modifiers?.sort().join("+") ?? "",
|
|
484
|
+
key,
|
|
485
|
+
scope: this,
|
|
486
|
+
};
|
|
487
|
+
const id = this.getId(binding);
|
|
488
|
+
if (!this.keyBindings.has(id)) {
|
|
489
|
+
this.keyBindings.set(id, []);
|
|
490
|
+
}
|
|
491
|
+
this.keyBindings.get(id).push({ ...binding, handler: func });
|
|
492
|
+
return binding;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Remove an existing keymap event handler.
|
|
496
|
+
*
|
|
497
|
+
* @public
|
|
498
|
+
*/
|
|
499
|
+
unregister(handler) {
|
|
500
|
+
const id = this.getId(handler);
|
|
501
|
+
let handlers = this.keyBindings.get(id);
|
|
502
|
+
if (!handlers) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
handlers = handlers.filter((binding) => {
|
|
506
|
+
!(binding.modifiers === handler.modifiers && binding.key === handler.key);
|
|
507
|
+
});
|
|
508
|
+
handlers.length == 0
|
|
509
|
+
? this.keyBindings.delete(id)
|
|
510
|
+
: this.keyBindings.set(id, handlers);
|
|
511
|
+
}
|
|
512
|
+
handleEvent(event) {
|
|
513
|
+
const hotkey = { modifiers: [], key: "" };
|
|
514
|
+
if (event.ctrlKey)
|
|
515
|
+
hotkey.modifiers.push("Ctrl");
|
|
516
|
+
if (event.altKey)
|
|
517
|
+
hotkey.modifiers.push("Alt");
|
|
518
|
+
if (event.shiftKey)
|
|
519
|
+
hotkey.modifiers.push("Shift");
|
|
520
|
+
if (event.metaKey)
|
|
521
|
+
hotkey.modifiers.push("Meta");
|
|
522
|
+
const key = event.key;
|
|
523
|
+
if (key !== "Control" &&
|
|
524
|
+
key !== "Alt" &&
|
|
525
|
+
key !== "Shift" &&
|
|
526
|
+
key !== "Meta") {
|
|
527
|
+
hotkey.key = key;
|
|
528
|
+
}
|
|
529
|
+
const handlerIds = [
|
|
530
|
+
keyId(hotkey),
|
|
531
|
+
keyId({ modifiers: hotkey.modifiers, key: "" }),
|
|
532
|
+
keyId({ modifiers: [], key: hotkey.key }),
|
|
533
|
+
keyId({ modifiers: [], key: "" }),
|
|
534
|
+
];
|
|
535
|
+
const handlers = handlerIds.flatMap((id) => this.keyBindings.get(id) || []);
|
|
536
|
+
if (handlers.length) {
|
|
537
|
+
for (const handler of handlers) {
|
|
538
|
+
const response = handler.handler(event, { ...handler, vkey: "" });
|
|
539
|
+
if (response === false) {
|
|
540
|
+
event.preventDefault();
|
|
541
|
+
event.stopPropagation();
|
|
542
|
+
}
|
|
543
|
+
if (event.defaultPrevented) {
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
const application = resolveApplication(this.application);
|
|
549
|
+
const commands = application.commands.commandsFor(hotkey);
|
|
550
|
+
for (const command of commands) {
|
|
551
|
+
if (!application.commands.isCommandAvailable(command.id)) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
void application.commands
|
|
555
|
+
.executeCommand(command.id)
|
|
556
|
+
.catch((error) => {
|
|
557
|
+
console.warn(`Unable to execute command hotkey: ${command.id}`, error);
|
|
558
|
+
});
|
|
559
|
+
event.preventDefault();
|
|
560
|
+
event.stopPropagation();
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
getId(handler) {
|
|
566
|
+
return keyId({
|
|
567
|
+
modifiers: (handler.modifiers || "").split("+"),
|
|
568
|
+
key: handler.key || "",
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
}
|
package/dist/compat.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { App } from "./context.svelte";
|
|
2
|
+
import { BaseComponent } from "./settings.svelte";
|
|
3
|
+
export type HexString = string;
|
|
4
|
+
export type Side = "left" | "right";
|
|
5
|
+
export interface CliData {
|
|
6
|
+
[key: string]: string | "true";
|
|
7
|
+
}
|
|
8
|
+
export interface CliFlag {
|
|
9
|
+
value?: string;
|
|
10
|
+
description: string;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export type CliFlags = Record<string, CliFlag>;
|
|
14
|
+
export type CliHandler = (params: CliData) => string | Promise<string>;
|
|
15
|
+
export interface ObsidianProtocolData {
|
|
16
|
+
action: string;
|
|
17
|
+
[key: string]: string | "true";
|
|
18
|
+
}
|
|
19
|
+
export type ObsidianProtocolHandler = (params: ObsidianProtocolData) => unknown;
|
|
20
|
+
export declare const moment: any;
|
|
21
|
+
export declare class SecretComponent extends BaseComponent {
|
|
22
|
+
readonly app: App;
|
|
23
|
+
private readonly input;
|
|
24
|
+
constructor(app: App, containerEl: HTMLElement);
|
|
25
|
+
get disabled(): boolean;
|
|
26
|
+
setDisabled(disabled: boolean): this;
|
|
27
|
+
setValue(value: string): this;
|
|
28
|
+
onChange(cb: (value: string) => unknown): this;
|
|
29
|
+
}
|
package/dist/compat.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseComponent, TextComponent } from "./settings.svelte";
|
|
2
|
+
export const moment = globalThis.moment ??
|
|
3
|
+
((value) => {
|
|
4
|
+
return value;
|
|
5
|
+
});
|
|
6
|
+
export class SecretComponent extends BaseComponent {
|
|
7
|
+
app;
|
|
8
|
+
input;
|
|
9
|
+
constructor(app, containerEl) {
|
|
10
|
+
super();
|
|
11
|
+
this.app = app;
|
|
12
|
+
this.input = new TextComponent(containerEl);
|
|
13
|
+
this.input.setType("password");
|
|
14
|
+
}
|
|
15
|
+
get disabled() {
|
|
16
|
+
return this.input.disabled;
|
|
17
|
+
}
|
|
18
|
+
setDisabled(disabled) {
|
|
19
|
+
this.input.setDisabled(disabled);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
setValue(value) {
|
|
23
|
+
this.input.setValue(value);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
onChange(cb) {
|
|
27
|
+
this.input.onChange(cb);
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
}
|