@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,209 @@
|
|
|
1
|
+
import { EventDispatcher } from "./events";
|
|
2
|
+
import type { AppDatabaseNotificationRecord, AppDatabaseNotificationSeverity } from "./storage/app-database";
|
|
3
|
+
export type NotificationSeverity = AppDatabaseNotificationSeverity;
|
|
4
|
+
export type NotificationLocation = "status" | "notification" | "silent";
|
|
5
|
+
export type NotificationProgressStatus = "running" | "cancelling" | "completed" | "failed" | "cancelled";
|
|
6
|
+
/**
|
|
7
|
+
* Options for creating a one-shot notification record.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface NotifyOptions {
|
|
12
|
+
id?: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
message: string;
|
|
15
|
+
severity?: NotificationSeverity;
|
|
16
|
+
source?: string;
|
|
17
|
+
persist?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for creating a long-running progress item.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface NotificationProgressOptions {
|
|
25
|
+
id?: string;
|
|
26
|
+
title: string;
|
|
27
|
+
message?: string;
|
|
28
|
+
source?: string;
|
|
29
|
+
location?: NotificationLocation;
|
|
30
|
+
cancellable?: boolean;
|
|
31
|
+
persistOnComplete?: boolean;
|
|
32
|
+
persistOnError?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Incremental progress update payload passed to a running progress handle.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export interface NotificationProgressReport {
|
|
40
|
+
message?: string;
|
|
41
|
+
current?: number;
|
|
42
|
+
total?: number;
|
|
43
|
+
increment?: number;
|
|
44
|
+
indeterminate?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Serializable view of the current progress state.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export interface NotificationProgressSnapshot {
|
|
52
|
+
id: string;
|
|
53
|
+
title: string;
|
|
54
|
+
message?: string;
|
|
55
|
+
source?: string;
|
|
56
|
+
location: NotificationLocation;
|
|
57
|
+
status: NotificationProgressStatus;
|
|
58
|
+
cancellable: boolean;
|
|
59
|
+
cancelRequested: boolean;
|
|
60
|
+
current?: number;
|
|
61
|
+
total?: number;
|
|
62
|
+
percent?: number;
|
|
63
|
+
indeterminate: boolean;
|
|
64
|
+
startedAt: number;
|
|
65
|
+
updatedAt: number;
|
|
66
|
+
error?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Cancellation token exposed to long-running tasks started through the
|
|
70
|
+
* notification progress API.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
export interface NotificationProgressToken {
|
|
75
|
+
readonly signal: AbortSignal;
|
|
76
|
+
readonly isCancellationRequested: boolean;
|
|
77
|
+
throwIfCancellationRequested(): void;
|
|
78
|
+
}
|
|
79
|
+
type NotificationEvents = {
|
|
80
|
+
changed: [];
|
|
81
|
+
notify: [record: AppDatabaseNotificationRecord];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Mutable handle returned for a running progress item.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export declare class NotificationProgressHandle implements NotificationProgressToken {
|
|
89
|
+
private readonly manager;
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly signal: AbortSignal;
|
|
92
|
+
private controller;
|
|
93
|
+
private snapshot;
|
|
94
|
+
private completed;
|
|
95
|
+
constructor(manager: NotificationManager, options: NotificationProgressOptions);
|
|
96
|
+
get isCancellationRequested(): boolean;
|
|
97
|
+
get currentSnapshot(): NotificationProgressSnapshot;
|
|
98
|
+
/**
|
|
99
|
+
* Update the current progress state.
|
|
100
|
+
*
|
|
101
|
+
* @param report - Partial progress information to merge into the live state.
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
report(report: NotificationProgressReport): void;
|
|
105
|
+
/**
|
|
106
|
+
* Alias for {@link report}.
|
|
107
|
+
*
|
|
108
|
+
* @param report - Partial progress information to merge into the live state.
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
update(report: NotificationProgressReport): void;
|
|
112
|
+
/**
|
|
113
|
+
* Request cancellation for the running progress item.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
cancel(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Mark the progress item as completed.
|
|
120
|
+
*
|
|
121
|
+
* @param message - Optional terminal message shown to the user.
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
complete(message?: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* Mark the progress item as failed.
|
|
127
|
+
*
|
|
128
|
+
* @param error - Failure value to surface in the final progress state.
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
fail(error: unknown): void;
|
|
132
|
+
/**
|
|
133
|
+
* Mark the progress item as cancelled.
|
|
134
|
+
*
|
|
135
|
+
* @param message - Optional terminal message shown after cancellation.
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
cancelled(message?: string): void;
|
|
139
|
+
/**
|
|
140
|
+
* Throw an abort error when cancellation has been requested.
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
*/
|
|
144
|
+
throwIfCancellationRequested(): void;
|
|
145
|
+
private finish;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Records user-visible notifications and tracks live progress handles.
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
*/
|
|
152
|
+
export declare class NotificationManager extends EventDispatcher<NotificationEvents> {
|
|
153
|
+
private readonly database;
|
|
154
|
+
records: AppDatabaseNotificationRecord[];
|
|
155
|
+
activeProgress: NotificationProgressSnapshot[];
|
|
156
|
+
private progressHandles;
|
|
157
|
+
constructor(database: {
|
|
158
|
+
listNotifications(): Promise<AppDatabaseNotificationRecord[]>;
|
|
159
|
+
upsertNotification(record: AppDatabaseNotificationRecord): Promise<void>;
|
|
160
|
+
markNotificationRead(id: string): Promise<void>;
|
|
161
|
+
clearNotification(id: string): Promise<void>;
|
|
162
|
+
clearAllNotifications(): Promise<void>;
|
|
163
|
+
});
|
|
164
|
+
/**
|
|
165
|
+
* Load persisted notification history for the current vault.
|
|
166
|
+
*
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
loadPersisted(): Promise<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Return the current persisted notification history.
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/
|
|
175
|
+
list(): AppDatabaseNotificationRecord[];
|
|
176
|
+
/**
|
|
177
|
+
* Record a notification and optionally persist it to history.
|
|
178
|
+
*
|
|
179
|
+
* @param options - Notification payload or a shorthand message string.
|
|
180
|
+
* @returns The recorded notification snapshot.
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
notify(options: NotifyOptions | string): AppDatabaseNotificationRecord;
|
|
184
|
+
/**
|
|
185
|
+
* Create a mutable progress handle for a long-running task.
|
|
186
|
+
*
|
|
187
|
+
* @param options - Progress metadata shown to the user.
|
|
188
|
+
* @returns The new progress handle.
|
|
189
|
+
* @public
|
|
190
|
+
*/
|
|
191
|
+
createProgress(options: NotificationProgressOptions): NotificationProgressHandle;
|
|
192
|
+
/**
|
|
193
|
+
* Run a task with a managed progress handle.
|
|
194
|
+
*
|
|
195
|
+
* @param options - Progress metadata shown to the user.
|
|
196
|
+
* @param task - Task that receives the progress handle and cancellation
|
|
197
|
+
* token.
|
|
198
|
+
* @returns The task result.
|
|
199
|
+
* @public
|
|
200
|
+
*/
|
|
201
|
+
withProgress<T>(options: NotificationProgressOptions, task: (progress: NotificationProgressHandle, token: NotificationProgressToken) => Promise<T> | T): Promise<T>;
|
|
202
|
+
cancel(id: string): void;
|
|
203
|
+
markRead(id: string): Promise<void>;
|
|
204
|
+
clear(id: string): Promise<void>;
|
|
205
|
+
clearAll(): Promise<void>;
|
|
206
|
+
updateProgress(snapshot: NotificationProgressSnapshot): void;
|
|
207
|
+
finishProgress(snapshot: NotificationProgressSnapshot): void;
|
|
208
|
+
}
|
|
209
|
+
export {};
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { EventDispatcher } from "./events";
|
|
2
|
+
function createNotificationId(prefix = "notification") {
|
|
3
|
+
if (typeof crypto !== "undefined" && "randomUUID" in crypto) {
|
|
4
|
+
return `${prefix}-${crypto.randomUUID()}`;
|
|
5
|
+
}
|
|
6
|
+
return `${prefix}-${Date.now().toString(36)}-${Math.random()
|
|
7
|
+
.toString(36)
|
|
8
|
+
.slice(2)}`;
|
|
9
|
+
}
|
|
10
|
+
function cloneRecord(record) {
|
|
11
|
+
return { ...record };
|
|
12
|
+
}
|
|
13
|
+
function errorMessage(error) {
|
|
14
|
+
return error instanceof Error ? error.message : String(error);
|
|
15
|
+
}
|
|
16
|
+
class CancellationError extends Error {
|
|
17
|
+
constructor() {
|
|
18
|
+
super("Operation cancelled");
|
|
19
|
+
this.name = "AbortError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Mutable handle returned for a running progress item.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export class NotificationProgressHandle {
|
|
28
|
+
manager;
|
|
29
|
+
id;
|
|
30
|
+
signal;
|
|
31
|
+
controller;
|
|
32
|
+
snapshot;
|
|
33
|
+
completed = false;
|
|
34
|
+
constructor(manager, options) {
|
|
35
|
+
this.manager = manager;
|
|
36
|
+
this.id = options.id ?? createNotificationId("progress");
|
|
37
|
+
this.controller = new AbortController();
|
|
38
|
+
this.signal = this.controller.signal;
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
this.snapshot = {
|
|
41
|
+
id: this.id,
|
|
42
|
+
title: options.title,
|
|
43
|
+
message: options.message,
|
|
44
|
+
source: options.source,
|
|
45
|
+
location: options.location ?? "status",
|
|
46
|
+
status: "running",
|
|
47
|
+
cancellable: options.cancellable === true,
|
|
48
|
+
cancelRequested: false,
|
|
49
|
+
indeterminate: true,
|
|
50
|
+
startedAt: now,
|
|
51
|
+
updatedAt: now,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
get isCancellationRequested() {
|
|
55
|
+
return this.signal.aborted;
|
|
56
|
+
}
|
|
57
|
+
get currentSnapshot() {
|
|
58
|
+
return { ...this.snapshot };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Update the current progress state.
|
|
62
|
+
*
|
|
63
|
+
* @param report - Partial progress information to merge into the live state.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
report(report) {
|
|
67
|
+
if (this.completed) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const next = {
|
|
71
|
+
...this.snapshot,
|
|
72
|
+
updatedAt: Date.now(),
|
|
73
|
+
};
|
|
74
|
+
if (report.message !== undefined) {
|
|
75
|
+
next.message = report.message;
|
|
76
|
+
}
|
|
77
|
+
if (typeof report.increment === "number") {
|
|
78
|
+
const previous = next.percent ?? 0;
|
|
79
|
+
next.percent = Math.max(0, Math.min(100, previous + report.increment));
|
|
80
|
+
next.current = next.percent;
|
|
81
|
+
next.total = 100;
|
|
82
|
+
next.indeterminate = false;
|
|
83
|
+
}
|
|
84
|
+
if (typeof report.current === "number" ||
|
|
85
|
+
typeof report.total === "number") {
|
|
86
|
+
next.current = report.current ?? next.current;
|
|
87
|
+
next.total = report.total ?? next.total;
|
|
88
|
+
if (typeof next.current === "number" && typeof next.total === "number") {
|
|
89
|
+
next.percent =
|
|
90
|
+
next.total > 0
|
|
91
|
+
? Math.max(0, Math.min(100, (next.current / next.total) * 100))
|
|
92
|
+
: 0;
|
|
93
|
+
}
|
|
94
|
+
next.indeterminate = false;
|
|
95
|
+
}
|
|
96
|
+
if (report.indeterminate === true) {
|
|
97
|
+
delete next.current;
|
|
98
|
+
delete next.total;
|
|
99
|
+
delete next.percent;
|
|
100
|
+
next.indeterminate = true;
|
|
101
|
+
}
|
|
102
|
+
this.snapshot = next;
|
|
103
|
+
this.manager.updateProgress(this.snapshot);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Alias for {@link report}.
|
|
107
|
+
*
|
|
108
|
+
* @param report - Partial progress information to merge into the live state.
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
update(report) {
|
|
112
|
+
this.report(report);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Request cancellation for the running progress item.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
cancel() {
|
|
120
|
+
if (this.completed || !this.snapshot.cancellable) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.snapshot = {
|
|
124
|
+
...this.snapshot,
|
|
125
|
+
status: "cancelling",
|
|
126
|
+
cancelRequested: true,
|
|
127
|
+
updatedAt: Date.now(),
|
|
128
|
+
};
|
|
129
|
+
this.controller.abort();
|
|
130
|
+
this.manager.updateProgress(this.snapshot);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Mark the progress item as completed.
|
|
134
|
+
*
|
|
135
|
+
* @param message - Optional terminal message shown to the user.
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
complete(message) {
|
|
139
|
+
this.finish("completed", message);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Mark the progress item as failed.
|
|
143
|
+
*
|
|
144
|
+
* @param error - Failure value to surface in the final progress state.
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
fail(error) {
|
|
148
|
+
this.finish("failed", errorMessage(error), errorMessage(error));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Mark the progress item as cancelled.
|
|
152
|
+
*
|
|
153
|
+
* @param message - Optional terminal message shown after cancellation.
|
|
154
|
+
* @public
|
|
155
|
+
*/
|
|
156
|
+
cancelled(message = "Cancelled") {
|
|
157
|
+
this.finish("cancelled", message);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Throw an abort error when cancellation has been requested.
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
throwIfCancellationRequested() {
|
|
165
|
+
if (this.signal.aborted) {
|
|
166
|
+
throw new CancellationError();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
finish(status, message, error) {
|
|
170
|
+
if (this.completed) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this.completed = true;
|
|
174
|
+
this.snapshot = {
|
|
175
|
+
...this.snapshot,
|
|
176
|
+
status,
|
|
177
|
+
message: message ?? this.snapshot.message,
|
|
178
|
+
error,
|
|
179
|
+
updatedAt: Date.now(),
|
|
180
|
+
};
|
|
181
|
+
this.manager.finishProgress(this.snapshot);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Records user-visible notifications and tracks live progress handles.
|
|
186
|
+
*
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
export class NotificationManager extends EventDispatcher {
|
|
190
|
+
database;
|
|
191
|
+
records = [];
|
|
192
|
+
activeProgress = [];
|
|
193
|
+
progressHandles = new Map();
|
|
194
|
+
constructor(database) {
|
|
195
|
+
super();
|
|
196
|
+
this.database = database;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Load persisted notification history for the current vault.
|
|
200
|
+
*
|
|
201
|
+
* @public
|
|
202
|
+
*/
|
|
203
|
+
async loadPersisted() {
|
|
204
|
+
this.records = await this.database.listNotifications();
|
|
205
|
+
this.trigger("changed");
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Return the current persisted notification history.
|
|
209
|
+
*
|
|
210
|
+
* @public
|
|
211
|
+
*/
|
|
212
|
+
list() {
|
|
213
|
+
return this.records.map(cloneRecord);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Record a notification and optionally persist it to history.
|
|
217
|
+
*
|
|
218
|
+
* @param options - Notification payload or a shorthand message string.
|
|
219
|
+
* @returns The recorded notification snapshot.
|
|
220
|
+
* @public
|
|
221
|
+
*/
|
|
222
|
+
notify(options) {
|
|
223
|
+
const normalized = typeof options === "string" ? { message: options } : options;
|
|
224
|
+
const now = Date.now();
|
|
225
|
+
const record = {
|
|
226
|
+
id: normalized.id ?? createNotificationId(),
|
|
227
|
+
title: normalized.title,
|
|
228
|
+
message: normalized.message,
|
|
229
|
+
severity: normalized.severity ?? "info",
|
|
230
|
+
source: normalized.source,
|
|
231
|
+
createdAt: now,
|
|
232
|
+
updatedAt: now,
|
|
233
|
+
read: false,
|
|
234
|
+
cleared: false,
|
|
235
|
+
};
|
|
236
|
+
if (normalized.persist) {
|
|
237
|
+
this.records = [
|
|
238
|
+
record,
|
|
239
|
+
...this.records.filter((it) => it.id !== record.id),
|
|
240
|
+
];
|
|
241
|
+
void this.database.upsertNotification(record).catch((error) => {
|
|
242
|
+
console.warn("Failed to persist notification", error);
|
|
243
|
+
});
|
|
244
|
+
this.trigger("changed");
|
|
245
|
+
}
|
|
246
|
+
this.trigger("notify", cloneRecord(record));
|
|
247
|
+
return cloneRecord(record);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Create a mutable progress handle for a long-running task.
|
|
251
|
+
*
|
|
252
|
+
* @param options - Progress metadata shown to the user.
|
|
253
|
+
* @returns The new progress handle.
|
|
254
|
+
* @public
|
|
255
|
+
*/
|
|
256
|
+
createProgress(options) {
|
|
257
|
+
const handle = new NotificationProgressHandle(this, options);
|
|
258
|
+
this.progressHandles.set(handle.id, handle);
|
|
259
|
+
this.updateProgress(handle.currentSnapshot);
|
|
260
|
+
return handle;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Run a task with a managed progress handle.
|
|
264
|
+
*
|
|
265
|
+
* @param options - Progress metadata shown to the user.
|
|
266
|
+
* @param task - Task that receives the progress handle and cancellation
|
|
267
|
+
* token.
|
|
268
|
+
* @returns The task result.
|
|
269
|
+
* @public
|
|
270
|
+
*/
|
|
271
|
+
async withProgress(options, task) {
|
|
272
|
+
const progress = this.createProgress(options);
|
|
273
|
+
try {
|
|
274
|
+
const result = await task(progress, progress);
|
|
275
|
+
progress.complete();
|
|
276
|
+
if (options.persistOnComplete) {
|
|
277
|
+
this.notify({
|
|
278
|
+
title: options.title,
|
|
279
|
+
message: progress.currentSnapshot.message ?? "Completed",
|
|
280
|
+
severity: "info",
|
|
281
|
+
source: options.source,
|
|
282
|
+
persist: true,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (progress.signal.aborted) {
|
|
289
|
+
progress.cancelled();
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
progress.fail(error);
|
|
293
|
+
if (options.persistOnError !== false) {
|
|
294
|
+
this.notify({
|
|
295
|
+
title: options.title,
|
|
296
|
+
message: errorMessage(error),
|
|
297
|
+
severity: "error",
|
|
298
|
+
source: options.source,
|
|
299
|
+
persist: true,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
cancel(id) {
|
|
307
|
+
this.progressHandles.get(id)?.cancel();
|
|
308
|
+
}
|
|
309
|
+
async markRead(id) {
|
|
310
|
+
this.records = this.records.map((record) => record.id === id
|
|
311
|
+
? { ...record, read: true, updatedAt: Date.now() }
|
|
312
|
+
: record);
|
|
313
|
+
this.trigger("changed");
|
|
314
|
+
await this.database.markNotificationRead(id);
|
|
315
|
+
}
|
|
316
|
+
async clear(id) {
|
|
317
|
+
this.records = this.records.filter((record) => record.id !== id);
|
|
318
|
+
this.trigger("changed");
|
|
319
|
+
await this.database.clearNotification(id);
|
|
320
|
+
}
|
|
321
|
+
async clearAll() {
|
|
322
|
+
this.records = [];
|
|
323
|
+
this.trigger("changed");
|
|
324
|
+
await this.database.clearAllNotifications();
|
|
325
|
+
}
|
|
326
|
+
updateProgress(snapshot) {
|
|
327
|
+
this.activeProgress = [
|
|
328
|
+
snapshot,
|
|
329
|
+
...this.activeProgress.filter((entry) => entry.id !== snapshot.id),
|
|
330
|
+
];
|
|
331
|
+
this.trigger("changed");
|
|
332
|
+
}
|
|
333
|
+
finishProgress(snapshot) {
|
|
334
|
+
this.progressHandles.delete(snapshot.id);
|
|
335
|
+
this.activeProgress = this.activeProgress.filter((entry) => entry.id !== snapshot.id);
|
|
336
|
+
this.trigger("changed");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { TFile } from "./storage";
|
|
2
|
+
import type { View, ViewState } from "./view.svelte";
|
|
3
|
+
import { type OpenViewState, type WorkspaceLeaf } from "./workspace.svelte";
|
|
4
|
+
type LeafLike = {
|
|
5
|
+
view: unknown;
|
|
6
|
+
};
|
|
7
|
+
type OpenFileWorkspaceLike<Leaf extends LeafLike> = {
|
|
8
|
+
getFocusedCommandHostId(): string;
|
|
9
|
+
getCommandHostIdForLeaf(target: Leaf | null): string;
|
|
10
|
+
iterateAllLeaves<T>(callback: (leaf: Leaf) => T): T | void;
|
|
11
|
+
};
|
|
12
|
+
export declare function leafFilePath(leaf: LeafLike | null | undefined): string | null;
|
|
13
|
+
export declare function findOpenFileLeaf<Leaf extends LeafLike>(workspace: OpenFileWorkspaceLike<Leaf>, file: TFile): Leaf | null;
|
|
14
|
+
type LeafViewStateCapture = {
|
|
15
|
+
state: ViewState;
|
|
16
|
+
view?: View;
|
|
17
|
+
};
|
|
18
|
+
export declare function captureLeafViewState(leaf: LeafViewStateCapture): ViewState;
|
|
19
|
+
export declare function cloneViewState(state: ViewState): ViewState;
|
|
20
|
+
export declare function historyFilePathForViewState(state: ViewState): string | null;
|
|
21
|
+
export declare function resolveViewForOpenFile(leaf: WorkspaceLeaf, file: TFile, explicitView?: View): View | undefined;
|
|
22
|
+
export declare function applyOpenViewStateToLeaf(leaf: WorkspaceLeaf, openState?: OpenViewState): Promise<void>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ON_DEMAND_PLUGIN_INSTALL_VIEW_TYPE, } from "./workspace.svelte";
|
|
2
|
+
function isFileView(view) {
|
|
3
|
+
return typeof view.canAcceptExtension === "function";
|
|
4
|
+
}
|
|
5
|
+
function filePathFromView(view) {
|
|
6
|
+
if (!view || typeof view !== "object" || !("file" in view)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const file = view.file;
|
|
10
|
+
return typeof file?.path === "string" ? file.path : null;
|
|
11
|
+
}
|
|
12
|
+
export function leafFilePath(leaf) {
|
|
13
|
+
return filePathFromView(leaf?.view);
|
|
14
|
+
}
|
|
15
|
+
export function findOpenFileLeaf(workspace, file) {
|
|
16
|
+
const focusedHostId = workspace.getFocusedCommandHostId();
|
|
17
|
+
let fallbackLeaf = null;
|
|
18
|
+
const matchingLeaf = workspace.iterateAllLeaves((leaf) => {
|
|
19
|
+
if (leafFilePath(leaf) !== file.path) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (workspace.getCommandHostIdForLeaf(leaf) === focusedHostId) {
|
|
23
|
+
return leaf;
|
|
24
|
+
}
|
|
25
|
+
fallbackLeaf ??= leaf;
|
|
26
|
+
return undefined;
|
|
27
|
+
}) ?? fallbackLeaf;
|
|
28
|
+
return matchingLeaf ?? null;
|
|
29
|
+
}
|
|
30
|
+
export function captureLeafViewState(leaf) {
|
|
31
|
+
const view = leaf.view;
|
|
32
|
+
if (!view) {
|
|
33
|
+
return cloneViewState(leaf.state);
|
|
34
|
+
}
|
|
35
|
+
return cloneViewState({
|
|
36
|
+
...leaf.state,
|
|
37
|
+
type: view.getViewType(),
|
|
38
|
+
state: {
|
|
39
|
+
...(leaf.state.state ?? {}),
|
|
40
|
+
...view.getState(),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function cloneViewState(state) {
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
state: { ...(state.state ?? {}) },
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const NON_FILE_HISTORY_VIEW_TYPES = new Set(["empty", "graph", "graph-local"]);
|
|
51
|
+
export function historyFilePathForViewState(state) {
|
|
52
|
+
if (NON_FILE_HISTORY_VIEW_TYPES.has(state.type)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const filePath = state.state?.["file"]?.toString();
|
|
56
|
+
return filePath?.length ? filePath : null;
|
|
57
|
+
}
|
|
58
|
+
export function resolveViewForOpenFile(leaf, file, explicitView) {
|
|
59
|
+
if (explicitView) {
|
|
60
|
+
return explicitView;
|
|
61
|
+
}
|
|
62
|
+
const currentView = leaf.view;
|
|
63
|
+
if (currentView &&
|
|
64
|
+
isFileView(currentView) &&
|
|
65
|
+
currentView.getViewType() === ON_DEMAND_PLUGIN_INSTALL_VIEW_TYPE &&
|
|
66
|
+
filePathFromView(currentView) === file.path &&
|
|
67
|
+
!leaf.app.workspace.viewCreator(file)) {
|
|
68
|
+
return currentView;
|
|
69
|
+
}
|
|
70
|
+
if (currentView &&
|
|
71
|
+
isFileView(currentView) &&
|
|
72
|
+
currentView.canAcceptExtension(file.extension)) {
|
|
73
|
+
const workspace = leaf.app.workspace;
|
|
74
|
+
const targetViewType = workspace.determineViewTypeForPath(file.path) ??
|
|
75
|
+
workspace.determineViewType(file.extension);
|
|
76
|
+
if (targetViewType && currentView.getViewType() === targetViewType) {
|
|
77
|
+
return currentView;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return leaf.app.workspace.viewCreator(file)?.(leaf);
|
|
81
|
+
}
|
|
82
|
+
export async function applyOpenViewStateToLeaf(leaf, openState) {
|
|
83
|
+
if (!openState?.state || Object.keys(openState.state).length === 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const view = leaf.view;
|
|
87
|
+
if (!view || typeof view.setState !== "function") {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const mergedState = {
|
|
91
|
+
...(typeof view.getState === "function" ? view.getState() : {}),
|
|
92
|
+
...openState.state,
|
|
93
|
+
};
|
|
94
|
+
await view.setState(mergedState);
|
|
95
|
+
leaf.state = {
|
|
96
|
+
...leaf.state,
|
|
97
|
+
state: {
|
|
98
|
+
...(leaf.state.state ?? {}),
|
|
99
|
+
...openState.state,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|