@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,661 @@
|
|
|
1
|
+
import { EventDispatcher } from "../events";
|
|
2
|
+
import { hasEditorAssociationGlobMagic, matchesEditorAssociationGlob, normalizeEditorAssociationGlob, validateEditorAssociationGlob, } from "../glob";
|
|
3
|
+
import { FileCache, TFile, TFolder, } from "./fs";
|
|
4
|
+
import { dirname, joinPath, normalizePath } from "./path";
|
|
5
|
+
function Err(name) {
|
|
6
|
+
return class extends Error {
|
|
7
|
+
code = "";
|
|
8
|
+
constructor(...args) {
|
|
9
|
+
super(...args);
|
|
10
|
+
this.code = name;
|
|
11
|
+
if (this.message) {
|
|
12
|
+
this.message = name + ": " + this.message;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.message = name;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export const ENOTDIR = Err("ENOTDIR");
|
|
21
|
+
/**
|
|
22
|
+
* High-level file-system facade for the active vault.
|
|
23
|
+
*
|
|
24
|
+
* `Vault` wraps a {@link DataAdapter}, maintains the in-memory file tree used by
|
|
25
|
+
* the workspace, and emits Obsidian-style file lifecycle events.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export class Vault extends EventDispatcher {
|
|
30
|
+
adapter;
|
|
31
|
+
files = {};
|
|
32
|
+
filesByName = new Map();
|
|
33
|
+
configDir = ".obsidian";
|
|
34
|
+
cache = new FileCache(1024);
|
|
35
|
+
constructor(adapter) {
|
|
36
|
+
super();
|
|
37
|
+
this.adapter = adapter;
|
|
38
|
+
this.load();
|
|
39
|
+
}
|
|
40
|
+
getPath(path) {
|
|
41
|
+
if (path === "/" || !path) {
|
|
42
|
+
return "/";
|
|
43
|
+
}
|
|
44
|
+
return normalizePath(path).replace(/^\/+/, "");
|
|
45
|
+
}
|
|
46
|
+
getName() {
|
|
47
|
+
return this.adapter.getName();
|
|
48
|
+
}
|
|
49
|
+
exists(path, sensitive) {
|
|
50
|
+
return this.adapter.exists(this.getPath(path), sensitive);
|
|
51
|
+
}
|
|
52
|
+
stat(path) {
|
|
53
|
+
return this.adapter.stat(this.getPath(path));
|
|
54
|
+
}
|
|
55
|
+
list(path = "/") {
|
|
56
|
+
return this.adapter.list(this.getPath(path));
|
|
57
|
+
}
|
|
58
|
+
#loaded = null;
|
|
59
|
+
load() {
|
|
60
|
+
if (this.#loaded) {
|
|
61
|
+
return this.#loaded;
|
|
62
|
+
}
|
|
63
|
+
this.#loaded = this.loadPath().then(() => {
|
|
64
|
+
this.rebuildFileNameIndex();
|
|
65
|
+
this.trigger("load");
|
|
66
|
+
});
|
|
67
|
+
return this.#loaded;
|
|
68
|
+
}
|
|
69
|
+
reload() {
|
|
70
|
+
const files = {};
|
|
71
|
+
return this.loadPath("/", files).then(() => {
|
|
72
|
+
this.files = files;
|
|
73
|
+
this.rebuildFileNameIndex();
|
|
74
|
+
this.trigger("load");
|
|
75
|
+
return this.getRoot();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
addToFileNameIndex(file) {
|
|
79
|
+
const paths = this.filesByName.get(file.name) ?? new Set();
|
|
80
|
+
paths.add(file.path);
|
|
81
|
+
this.filesByName.set(file.name, paths);
|
|
82
|
+
}
|
|
83
|
+
removeFromFileNameIndex(file) {
|
|
84
|
+
const paths = this.filesByName.get(file.name);
|
|
85
|
+
if (!paths)
|
|
86
|
+
return;
|
|
87
|
+
paths.delete(file.path);
|
|
88
|
+
if (paths.size === 0)
|
|
89
|
+
this.filesByName.delete(file.name);
|
|
90
|
+
}
|
|
91
|
+
rebuildFileNameIndex() {
|
|
92
|
+
this.filesByName.clear();
|
|
93
|
+
for (const file of Object.values(this.files)) {
|
|
94
|
+
if (file instanceof TFile)
|
|
95
|
+
this.addToFileNameIndex(file);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
loadPath(basePath = "/", sourceFiles = this.files) {
|
|
99
|
+
basePath = this.getPath(basePath);
|
|
100
|
+
Object.keys(sourceFiles)
|
|
101
|
+
.filter((k) => k.startsWith(`${basePath}/`) || basePath === "")
|
|
102
|
+
.forEach((k) => {
|
|
103
|
+
delete sourceFiles[k];
|
|
104
|
+
});
|
|
105
|
+
return this.adapter.list(basePath).then(({ files, folders }) => {
|
|
106
|
+
sourceFiles[basePath] ||= new TFolder(basePath, [], null, this);
|
|
107
|
+
const folder = sourceFiles[basePath];
|
|
108
|
+
folder.parent =
|
|
109
|
+
basePath === "/" ? null : sourceFiles[dirname(basePath)];
|
|
110
|
+
folder.vault = this;
|
|
111
|
+
const promises = [];
|
|
112
|
+
folders.forEach((path) => {
|
|
113
|
+
path = this.getPath(joinPath(basePath, path));
|
|
114
|
+
sourceFiles[path] = new TFolder(path, [], sourceFiles[dirname(path)], this);
|
|
115
|
+
folder.children.push(sourceFiles[path]);
|
|
116
|
+
promises.push(this.loadPath(path, sourceFiles));
|
|
117
|
+
});
|
|
118
|
+
files.forEach((file) => {
|
|
119
|
+
file = this.getPath(joinPath(basePath, file));
|
|
120
|
+
promises.push(this.adapter.stat(file).then((stat) => {
|
|
121
|
+
if (stat) {
|
|
122
|
+
sourceFiles[file] = new TFile(file, stat, folder, this);
|
|
123
|
+
folder.children.push(sourceFiles[file]);
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
return Promise.all(promises).then(() => sourceFiles);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create a new plaintext file inside the vault.
|
|
132
|
+
*
|
|
133
|
+
* @param path - Vault absolute path for the new file, with extension.
|
|
134
|
+
* @param data - Text content for the new file.
|
|
135
|
+
* @param options - (Optional)
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
create(path, data, options) {
|
|
139
|
+
path = this.getPath(path);
|
|
140
|
+
const file = this.getFileByPath(path);
|
|
141
|
+
if (file) {
|
|
142
|
+
return this.modify(file, data, options).then(() => file);
|
|
143
|
+
}
|
|
144
|
+
return this.adapter
|
|
145
|
+
.write(path, data, options)
|
|
146
|
+
.then(() => this.adapter.stat(path))
|
|
147
|
+
.then((stat) => {
|
|
148
|
+
if (!stat) {
|
|
149
|
+
return Promise.reject(`Unable to write file: ${path}`);
|
|
150
|
+
}
|
|
151
|
+
let parent = this.files[dirname(path)];
|
|
152
|
+
const file = new TFile(path, stat, parent, this);
|
|
153
|
+
this.files[path] = file;
|
|
154
|
+
this.addToFileNameIndex(file);
|
|
155
|
+
this.cache.put(path, data);
|
|
156
|
+
parent.children.push(file);
|
|
157
|
+
this.dispatch("create", file);
|
|
158
|
+
this.dispatch("all", "create", file, {});
|
|
159
|
+
return file;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Create a new binary file inside the vault.
|
|
164
|
+
*
|
|
165
|
+
* @param path - Vault absolute path for the new file, with extension.
|
|
166
|
+
* @param data - Content for the new file.
|
|
167
|
+
* @param options - (Optional)
|
|
168
|
+
* @throws Error if file already exists
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
createBinary(path, data, options) {
|
|
172
|
+
path = this.getPath(path);
|
|
173
|
+
return this.adapter
|
|
174
|
+
.writeBinary(path, data, options)
|
|
175
|
+
.then(() => this.adapter.stat(path))
|
|
176
|
+
.then((stat) => {
|
|
177
|
+
if (!stat) {
|
|
178
|
+
return Promise.reject(`Unable to write file: ${path}`);
|
|
179
|
+
}
|
|
180
|
+
let parent = this.files[dirname(path)];
|
|
181
|
+
const file = new TFile(path, stat, parent, this);
|
|
182
|
+
this.files[path] = file;
|
|
183
|
+
this.addToFileNameIndex(file);
|
|
184
|
+
parent.children.push(file);
|
|
185
|
+
this.dispatch("create", file);
|
|
186
|
+
this.dispatch("all", "create", file, {});
|
|
187
|
+
return file;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Create a new folder inside the vault.
|
|
192
|
+
*
|
|
193
|
+
* @param path - Vault absolute path for the new folder.
|
|
194
|
+
* @throws Error if folder already exists
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
async createFolder(path) {
|
|
198
|
+
path = this.getPath(path);
|
|
199
|
+
try {
|
|
200
|
+
const folder = await this.adapter.mkdir(path).then(() => {
|
|
201
|
+
const parent = this.files[dirname(path)];
|
|
202
|
+
if (!parent || !(parent instanceof TFolder)) {
|
|
203
|
+
throw new ENOTDIR(dirname(path));
|
|
204
|
+
}
|
|
205
|
+
const folder = new TFolder(path, [], parent, this);
|
|
206
|
+
this.files[path] = folder;
|
|
207
|
+
parent.children.push(folder);
|
|
208
|
+
this.dispatch("create", folder);
|
|
209
|
+
this.dispatch("all", "create", folder, {});
|
|
210
|
+
return folder;
|
|
211
|
+
});
|
|
212
|
+
return folder;
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
if (err.code !== "EEXIST") {
|
|
216
|
+
throw err;
|
|
217
|
+
}
|
|
218
|
+
const folder = this.files[path];
|
|
219
|
+
if (folder instanceof TFolder) {
|
|
220
|
+
return folder;
|
|
221
|
+
}
|
|
222
|
+
else if (folder instanceof TFile) {
|
|
223
|
+
throw new ENOTDIR(path);
|
|
224
|
+
}
|
|
225
|
+
throw err;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async mkpath(path) {
|
|
229
|
+
path = this.getPath(path);
|
|
230
|
+
const parts = path.split("/");
|
|
231
|
+
let folder;
|
|
232
|
+
let currentPath = "";
|
|
233
|
+
if (path.startsWith("/")) {
|
|
234
|
+
currentPath = "/";
|
|
235
|
+
parts.shift();
|
|
236
|
+
}
|
|
237
|
+
for (const part of parts) {
|
|
238
|
+
if (!part)
|
|
239
|
+
continue;
|
|
240
|
+
currentPath = currentPath ? `${currentPath}/${part}` : part;
|
|
241
|
+
try {
|
|
242
|
+
folder = await this.createFolder(currentPath);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
if (err.code !== "EEXIST" && !err.toString().includes("EEXIST")) {
|
|
246
|
+
throw err;
|
|
247
|
+
}
|
|
248
|
+
if (this.files[currentPath] instanceof TFile) {
|
|
249
|
+
throw new ENOTDIR(currentPath);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return folder;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Deletes the file completely.
|
|
257
|
+
*
|
|
258
|
+
* @param file - The file or folder to be deleted
|
|
259
|
+
* @param force - Should attempt to delete folder even if it has hidden
|
|
260
|
+
* children
|
|
261
|
+
* @public
|
|
262
|
+
*/
|
|
263
|
+
delete(file, force) {
|
|
264
|
+
const remove = file instanceof TFolder
|
|
265
|
+
? this.adapter.rmdir(file.path, force ?? true)
|
|
266
|
+
: this.adapter.remove(file.path);
|
|
267
|
+
return remove.then(() => {
|
|
268
|
+
let parent = this.files[dirname(file.path)];
|
|
269
|
+
Object.keys(this.files)
|
|
270
|
+
.filter((path) => path === file.path || path.startsWith(`${file.path}/`))
|
|
271
|
+
.forEach((path) => {
|
|
272
|
+
const removed = this.files[path];
|
|
273
|
+
if (removed instanceof TFile)
|
|
274
|
+
this.removeFromFileNameIndex(removed);
|
|
275
|
+
delete this.files[path];
|
|
276
|
+
});
|
|
277
|
+
if (parent) {
|
|
278
|
+
const childIndex = parent.children.findIndex((it) => it.path === file.path);
|
|
279
|
+
if (childIndex !== -1) {
|
|
280
|
+
parent.children.splice(childIndex, 1);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
this.cache.invalidate(file.path);
|
|
284
|
+
this.dispatch("delete", file);
|
|
285
|
+
this.dispatch("all", "delete", file, { force });
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
trash(file, system = true) {
|
|
289
|
+
const trash = system
|
|
290
|
+
? this.adapter.trashSystem(file.path)
|
|
291
|
+
: Promise.resolve(false);
|
|
292
|
+
return trash.then((handled) => {
|
|
293
|
+
if (handled) {
|
|
294
|
+
return this.delete(file, true);
|
|
295
|
+
}
|
|
296
|
+
return this.adapter.trashLocal(file.path).then(async () => {
|
|
297
|
+
await this.reload();
|
|
298
|
+
this.dispatch("delete", file);
|
|
299
|
+
this.dispatch("all", "delete", file, { system });
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Read a plaintext file that is stored inside the vault, directly from disk.
|
|
305
|
+
* Use this if you intend to modify the file content afterwards. Use
|
|
306
|
+
* {@link Vault.cachedRead} otherwise for better performance.
|
|
307
|
+
*
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
310
|
+
read(file) {
|
|
311
|
+
return this.adapter.read(file.path).then((data) => {
|
|
312
|
+
this.cache.put(file.path, data);
|
|
313
|
+
return data;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Read the content of a plaintext file stored inside the vault Use this if
|
|
318
|
+
* you only want to display the content to the user. If you want to modify the
|
|
319
|
+
* file content afterward use {@link Vault.read}
|
|
320
|
+
*
|
|
321
|
+
* @public
|
|
322
|
+
*/
|
|
323
|
+
cachedRead(file) {
|
|
324
|
+
if (this.cache.has(file.path)) {
|
|
325
|
+
return Promise.resolve(this.cache.get(file.path));
|
|
326
|
+
}
|
|
327
|
+
return this.read(file);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Read the content of a binary file stored inside the vault.
|
|
331
|
+
*
|
|
332
|
+
* @public
|
|
333
|
+
*/
|
|
334
|
+
readBinary(file) {
|
|
335
|
+
return this.adapter.readBinary(file.path);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Rename or move a file. To ensure links are automatically renamed, use
|
|
339
|
+
* {@link FileManager.renameFile} instead.
|
|
340
|
+
*
|
|
341
|
+
* @param file - The file to rename/move
|
|
342
|
+
* @param newPath - Vault absolute path to move file to.
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
rename(file, newPath) {
|
|
346
|
+
newPath = this.getPath(newPath);
|
|
347
|
+
if (file.path == newPath) {
|
|
348
|
+
return Promise.resolve();
|
|
349
|
+
}
|
|
350
|
+
const oldPath = file.path;
|
|
351
|
+
const paths = new Set();
|
|
352
|
+
if (file instanceof TFile) {
|
|
353
|
+
paths.add(file.parent?.path ?? "/");
|
|
354
|
+
paths.add(dirname(newPath));
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
paths.add(file.path);
|
|
358
|
+
paths.add(newPath);
|
|
359
|
+
}
|
|
360
|
+
return this.adapter.rename(file.path, newPath).then(async () => {
|
|
361
|
+
this.files = await this.loadPath("/", {});
|
|
362
|
+
this.rebuildFileNameIndex();
|
|
363
|
+
let newFile = this.getAbstractFileByPath(newPath);
|
|
364
|
+
if (newFile) {
|
|
365
|
+
this.cache.rename(file.path, newFile.path);
|
|
366
|
+
this.dispatch("rename", newFile, oldPath);
|
|
367
|
+
this.dispatch("all", "rename", file, { oldPath });
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
console.warn(`Failed to rename file: ${file.path}`);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Modify the contents of a plaintext file.
|
|
376
|
+
*
|
|
377
|
+
* @param file - The file
|
|
378
|
+
* @param data - The new file content
|
|
379
|
+
* @param options - (Optional)
|
|
380
|
+
* @public
|
|
381
|
+
*/
|
|
382
|
+
modify(file, data, options) {
|
|
383
|
+
if (!this.getFileByPath(file.path)) {
|
|
384
|
+
return this.create(file.path, data, options).then(() => { });
|
|
385
|
+
}
|
|
386
|
+
const path = file.path;
|
|
387
|
+
return this.adapter
|
|
388
|
+
.write(path, data, options)
|
|
389
|
+
.then(() => this.adapter.stat(path))
|
|
390
|
+
.then((stat) => {
|
|
391
|
+
if (!stat) {
|
|
392
|
+
return Promise.reject(`Unable to write file: ${path}`);
|
|
393
|
+
}
|
|
394
|
+
let parent = this.files[dirname(path)];
|
|
395
|
+
const file = new TFile(path, stat, parent, this);
|
|
396
|
+
this.files[path] = file;
|
|
397
|
+
this.cache.put(path, data);
|
|
398
|
+
this.cache.put(file.path, data);
|
|
399
|
+
this.dispatch("modify", file);
|
|
400
|
+
this.dispatch("all", "modify", file, { data, options });
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Modify the contents of a binary file.
|
|
405
|
+
*
|
|
406
|
+
* @param file - The file
|
|
407
|
+
* @param data - The new file content
|
|
408
|
+
* @param options - (Optional)
|
|
409
|
+
* @public
|
|
410
|
+
*/
|
|
411
|
+
modifyBinary(file, data, options) {
|
|
412
|
+
if (!this.getFileByPath(file.path)) {
|
|
413
|
+
return this.createBinary(file.path, data, options).then(() => { });
|
|
414
|
+
}
|
|
415
|
+
const path = file.path;
|
|
416
|
+
return this.adapter
|
|
417
|
+
.writeBinary(file.path, data, options)
|
|
418
|
+
.then(() => this.adapter.stat(path))
|
|
419
|
+
.then((stat) => {
|
|
420
|
+
if (!stat) {
|
|
421
|
+
return Promise.reject(`Unable to write file: ${path}`);
|
|
422
|
+
}
|
|
423
|
+
let parent = this.files[dirname(path)];
|
|
424
|
+
const file = new TFile(path, stat, parent, this);
|
|
425
|
+
this.files[path] = file;
|
|
426
|
+
this.dispatch("modify", file);
|
|
427
|
+
this.dispatch("all", "modify", file, { data, options });
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Atomically read, modify, and save the contents of a note.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* app.vault.process(file, (data) => {
|
|
436
|
+
* return data.replace('Hello', 'World');
|
|
437
|
+
* });
|
|
438
|
+
* ```;
|
|
439
|
+
*
|
|
440
|
+
* @param file - The file to be read and modified.
|
|
441
|
+
* @param fn - A callback function which returns the new content of the note
|
|
442
|
+
* synchronously.
|
|
443
|
+
* @param options - Write options.
|
|
444
|
+
* @returns String - the text value of the note that was written.
|
|
445
|
+
* @public
|
|
446
|
+
*/
|
|
447
|
+
process(file, fn, options) {
|
|
448
|
+
return this.adapter.process(file.path, fn, options).then((data) => {
|
|
449
|
+
this.cache.put(file.path, data);
|
|
450
|
+
this.dispatch("modify", file);
|
|
451
|
+
this.dispatch("all", "modify", file, { data, options });
|
|
452
|
+
return data;
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
append(file, data, options) {
|
|
456
|
+
return this.adapter
|
|
457
|
+
.append(file.path, data, options)
|
|
458
|
+
.then(() => this.adapter.stat(file.path))
|
|
459
|
+
.then((stat) => {
|
|
460
|
+
if (!stat) {
|
|
461
|
+
return Promise.reject(`Unable to append file: ${file.path}`);
|
|
462
|
+
}
|
|
463
|
+
const parent = this.files[dirname(file.path)];
|
|
464
|
+
const next = new TFile(file.path, stat, parent, this);
|
|
465
|
+
this.files[file.path] = next;
|
|
466
|
+
this.cache.invalidate(file.path);
|
|
467
|
+
this.dispatch("modify", next);
|
|
468
|
+
this.dispatch("all", "modify", next, { data, options });
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
appendBinary(file, data, options) {
|
|
472
|
+
return this.adapter
|
|
473
|
+
.appendBinary(file.path, data, options)
|
|
474
|
+
.then(() => this.adapter.stat(file.path))
|
|
475
|
+
.then((stat) => {
|
|
476
|
+
if (!stat) {
|
|
477
|
+
return Promise.reject(`Unable to append file: ${file.path}`);
|
|
478
|
+
}
|
|
479
|
+
const parent = this.files[dirname(file.path)];
|
|
480
|
+
const next = new TFile(file.path, stat, parent, this);
|
|
481
|
+
this.files[file.path] = next;
|
|
482
|
+
this.cache.invalidate(file.path);
|
|
483
|
+
this.dispatch("modify", next);
|
|
484
|
+
this.dispatch("all", "modify", next, { data, options });
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
async copy(file, newPath) {
|
|
488
|
+
newPath = this.getPath(newPath);
|
|
489
|
+
await this.adapter.copy(file.path, newPath);
|
|
490
|
+
await this.reload();
|
|
491
|
+
const copied = this.getAbstractFileByPath(newPath);
|
|
492
|
+
if (!copied) {
|
|
493
|
+
throw new Error(`Unable to copy file: ${file.path}`);
|
|
494
|
+
}
|
|
495
|
+
this.dispatch("create", copied);
|
|
496
|
+
this.dispatch("all", "create", copied, { originalPath: file.path });
|
|
497
|
+
return copied;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Get a file inside the vault at the given path. Returns `null` if the file
|
|
501
|
+
* does not exist.
|
|
502
|
+
*
|
|
503
|
+
* @param path
|
|
504
|
+
* @public
|
|
505
|
+
*/
|
|
506
|
+
getFileByPath(path) {
|
|
507
|
+
path = this.getPath(path);
|
|
508
|
+
const file = this.files[path];
|
|
509
|
+
if (file instanceof TFile) {
|
|
510
|
+
return file.copy();
|
|
511
|
+
}
|
|
512
|
+
return null;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Get a folder inside the vault at the given path. Returns `null` if the
|
|
516
|
+
* folder does not exist.
|
|
517
|
+
*
|
|
518
|
+
* @param path
|
|
519
|
+
* @public
|
|
520
|
+
*/
|
|
521
|
+
getFolderByPath(path) {
|
|
522
|
+
path = this.getPath(path);
|
|
523
|
+
const file = this.files[path];
|
|
524
|
+
if (file instanceof TFolder) {
|
|
525
|
+
return file.copy();
|
|
526
|
+
}
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Get a file or folder inside the vault at the given path. To check if the
|
|
531
|
+
* return type is a file, use `instanceof TFile`. To check if it is a folder,
|
|
532
|
+
* use `instanceof TFolder`.
|
|
533
|
+
*
|
|
534
|
+
* @param path - Vault absolute path to the folder or file, with extension,
|
|
535
|
+
* case sensitive.
|
|
536
|
+
* @returns The abstract file, if it's found.
|
|
537
|
+
* @public
|
|
538
|
+
*/
|
|
539
|
+
getAbstractFileByPath(path) {
|
|
540
|
+
path = this.getPath(path);
|
|
541
|
+
return this.files[path]?.copy() ?? null;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Get the root folder of the current vault.
|
|
545
|
+
*
|
|
546
|
+
* @public
|
|
547
|
+
*/
|
|
548
|
+
getRoot() {
|
|
549
|
+
return this.files["/"].copy();
|
|
550
|
+
}
|
|
551
|
+
getResourcePath(file) {
|
|
552
|
+
return this.adapter.getResourcePath(file.path);
|
|
553
|
+
}
|
|
554
|
+
getResourceUrl(file) {
|
|
555
|
+
const adapter = this.adapter;
|
|
556
|
+
if (adapter.getResourceUrl) {
|
|
557
|
+
return adapter.getResourceUrl(file.path);
|
|
558
|
+
}
|
|
559
|
+
return Promise.resolve(this.getResourcePath(file));
|
|
560
|
+
}
|
|
561
|
+
revokeResourceUrl(url) {
|
|
562
|
+
const adapter = this.adapter;
|
|
563
|
+
adapter.revokeResourceUrl?.(url);
|
|
564
|
+
}
|
|
565
|
+
getAllLoadedFiles() {
|
|
566
|
+
return Object.values(this.files);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Get all folders in the vault.
|
|
570
|
+
*
|
|
571
|
+
* @param includeRoot - Should the root folder (`/`) be returned
|
|
572
|
+
* @public
|
|
573
|
+
*/
|
|
574
|
+
getAllFolders(includeRoot) {
|
|
575
|
+
return Object.values(this.files).filter((it) => it instanceof TFolder && (includeRoot || it.path !== "/"));
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Get all files in the vault.
|
|
579
|
+
*
|
|
580
|
+
* @public
|
|
581
|
+
*/
|
|
582
|
+
getFiles() {
|
|
583
|
+
return Object.values(this.files).filter((it) => it instanceof TFile);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Iterate loaded files without allocating a second vault-sized collection.
|
|
587
|
+
* The traversal follows the existing folder tree and only retains iterator
|
|
588
|
+
* state proportional to folder depth.
|
|
589
|
+
*
|
|
590
|
+
* @public
|
|
591
|
+
*/
|
|
592
|
+
*iterateFiles() {
|
|
593
|
+
const root = this.files["/"];
|
|
594
|
+
if (!(root instanceof TFolder))
|
|
595
|
+
return;
|
|
596
|
+
function* visit(folder) {
|
|
597
|
+
for (const child of folder.children) {
|
|
598
|
+
if (child instanceof TFile)
|
|
599
|
+
yield child.copy();
|
|
600
|
+
else if (child instanceof TFolder)
|
|
601
|
+
yield* visit(child);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
yield* visit(root);
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Get all files matching a shared editor-association glob.
|
|
608
|
+
*
|
|
609
|
+
* Filename-only patterns match files in every folder. Patterns containing a
|
|
610
|
+
* slash match normalized vault-relative paths. Invalid patterns return no
|
|
611
|
+
* files.
|
|
612
|
+
*
|
|
613
|
+
* @public
|
|
614
|
+
*/
|
|
615
|
+
getFilesByGlob(pattern, options = {}) {
|
|
616
|
+
const normalizedPattern = normalizeEditorAssociationGlob(pattern);
|
|
617
|
+
if (!validateEditorAssociationGlob(normalizedPattern).valid)
|
|
618
|
+
return [];
|
|
619
|
+
const paths = new Set();
|
|
620
|
+
if (!normalizedPattern.includes("/")) {
|
|
621
|
+
if (options.caseSensitive === true &&
|
|
622
|
+
!hasEditorAssociationGlobMagic(normalizedPattern)) {
|
|
623
|
+
for (const path of this.filesByName.get(normalizedPattern) ?? []) {
|
|
624
|
+
paths.add(path);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
for (const [name, matchingPaths] of this.filesByName) {
|
|
629
|
+
if (!matchesEditorAssociationGlob(normalizedPattern, name, options)) {
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
for (const path of matchingPaths)
|
|
633
|
+
paths.add(path);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
else {
|
|
638
|
+
for (const file of Object.values(this.files)) {
|
|
639
|
+
if (file instanceof TFile &&
|
|
640
|
+
matchesEditorAssociationGlob(normalizedPattern, file.path, options)) {
|
|
641
|
+
paths.add(file.path);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return [...paths]
|
|
646
|
+
.map((path) => this.getFileByPath(path))
|
|
647
|
+
.filter((file) => Boolean(file))
|
|
648
|
+
.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
649
|
+
}
|
|
650
|
+
getMarkdownFiles() {
|
|
651
|
+
return this.getFiles().filter((it) => ["md", "markdown"].includes(it.extension.toLowerCase()));
|
|
652
|
+
}
|
|
653
|
+
static recurseChildren(root, cb) {
|
|
654
|
+
for (const child of root.children) {
|
|
655
|
+
cb(child);
|
|
656
|
+
if (child instanceof TFolder) {
|
|
657
|
+
Vault.recurseChildren(child, cb);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|