@mnaoumov/obsidian-lib 10.11.0 → 11.0.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/README.md +26 -0
- package/components/all-windows-status-bar-item-component/package.json +6 -0
- package/components/shared-component-pool-component/package.json +6 -0
- package/components/worker-component/package.json +6 -0
- package/components/worker-pool-component/package.json +6 -0
- package/components/workspace-layout-state-component/package.json +6 -0
- package/dist/lib/cjs/__merged.cjs +477 -285
- package/dist/lib/cjs/__merged.d.cts +26 -10
- package/dist/lib/cjs/anchored-suggest.cjs +1 -1
- package/dist/lib/cjs/app.cjs +2 -2
- package/dist/lib/cjs/async-with-notice.cjs +4 -4
- package/dist/lib/cjs/attachment-path.cjs +9 -9
- package/dist/lib/cjs/attachment-path.d.cts +3 -3
- package/dist/lib/cjs/attachment-unit-folder.cjs +2 -2
- package/dist/lib/cjs/backlink-index.cjs +5 -5
- package/dist/lib/cjs/backlink.cjs +7 -7
- package/dist/lib/cjs/bases-view-registrar.cjs +1 -1
- package/dist/lib/cjs/broken-link-candidates.cjs +1 -1
- package/dist/lib/cjs/bug-report-diagnostics.cjs +222 -0
- package/dist/lib/cjs/bug-report-diagnostics.d.cts +186 -0
- package/dist/lib/cjs/bug-report.cjs +38 -12
- package/dist/lib/cjs/bug-report.d.cts +65 -0
- package/dist/lib/cjs/bulk-operation-progress.cjs +1 -1
- package/dist/lib/cjs/bulk-operation.cjs +2 -2
- package/dist/lib/cjs/callout.cjs +6 -6
- package/dist/lib/cjs/canvas.cjs +11 -9
- package/dist/lib/cjs/canvas.d.cts +13 -0
- package/dist/lib/cjs/case-insensitive-file-index.cjs +3 -3
- package/dist/lib/cjs/code-block-render-handoff.cjs +5 -5
- package/dist/lib/cjs/codemirror/editor-mode-extension.cjs +4 -4
- package/dist/lib/cjs/codemirror/incremental-parse-state-field.cjs +2 -2
- package/dist/lib/cjs/codemirror/index.cjs +7 -7
- package/dist/lib/cjs/codemirror/inline-token-widgets.cjs +5 -5
- package/dist/lib/cjs/codemirror/markdown-editor-views.cjs +2 -2
- package/dist/lib/cjs/codemirror/settings-facet.cjs +1 -1
- package/dist/lib/cjs/command-handlers/abstract-file-command-handler.cjs +17 -17
- package/dist/lib/cjs/command-handlers/abstract-file-command-handler.d.cts +13 -13
- package/dist/lib/cjs/command-handlers/command-handler-component.cjs +2 -2
- package/dist/lib/cjs/command-handlers/command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/editor-command-handler.cjs +10 -10
- package/dist/lib/cjs/command-handlers/editor-command-handler.d.cts +7 -7
- package/dist/lib/cjs/command-handlers/file-command-handler.cjs +3 -3
- package/dist/lib/cjs/command-handlers/folder-command-handler.cjs +3 -3
- package/dist/lib/cjs/command-handlers/global-command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/index.cjs +15 -15
- package/dist/lib/cjs/command-handlers/open-bug-report-command-handler.cjs +95 -4
- package/dist/lib/cjs/command-handlers/open-bug-report-command-handler.d.cts +34 -2
- package/dist/lib/cjs/command-handlers/open-demo-vault-command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/open-discussion-command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/open-feature-request-command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/open-git-hub-command-handler.cjs +1 -1
- package/dist/lib/cjs/command-handlers/open-settings-command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/undo-bulk-operation-command-handler.cjs +2 -2
- package/dist/lib/cjs/command-handlers/unlock-active-note-command-handler.cjs +1 -1
- package/dist/lib/cjs/community-plugins.cjs +3 -3
- package/dist/lib/cjs/components/abort-signal-component.cjs +2 -2
- package/dist/lib/cjs/components/all-windows-event-component.cjs +5 -5
- package/dist/lib/cjs/components/all-windows-status-bar-item-component.cjs +245 -0
- package/dist/lib/cjs/components/all-windows-status-bar-item-component.d.cts +146 -0
- package/dist/lib/cjs/components/async-error-handler-component.cjs +5 -5
- package/dist/lib/cjs/components/async-events-component.cjs +1 -1
- package/dist/lib/cjs/components/bulk-operation-commit-component.cjs +12 -12
- package/dist/lib/cjs/components/case-insensitive-file-index-component.cjs +2 -2
- package/dist/lib/cjs/components/component-ex.cjs +21 -11
- package/dist/lib/cjs/components/component-ex.d.cts +11 -0
- package/dist/lib/cjs/components/console-debug-component.cjs +2 -2
- package/dist/lib/cjs/components/core-plugin-toggle-component.cjs +2 -2
- package/dist/lib/cjs/components/disposable-component.cjs +2 -2
- package/dist/lib/cjs/components/embed-extensions-component.cjs +21 -4
- package/dist/lib/cjs/components/embed-extensions-component.d.cts +8 -0
- package/dist/lib/cjs/components/embeddable-markdown-editor-component.cjs +24 -10
- package/dist/lib/cjs/components/embeddable-markdown-editor-component.d.cts +9 -0
- package/dist/lib/cjs/components/file-explorer-root-menu-component.cjs +7 -7
- package/dist/lib/cjs/components/generate-markdown-link-default-params-component.cjs +2 -2
- package/dist/lib/cjs/components/incremental-file-index-component.cjs +4 -4
- package/dist/lib/cjs/components/index.cjs +54 -39
- package/dist/lib/cjs/components/index.d.cts +5 -0
- package/dist/lib/cjs/components/layout-ready-component.cjs +3 -3
- package/dist/lib/cjs/components/menu-event-registrar-component.cjs +2 -2
- package/dist/lib/cjs/components/monkey-around-component.cjs +3 -3
- package/dist/lib/cjs/components/notebook-navigator-menu-event-registrar-component.cjs +5 -5
- package/dist/lib/cjs/components/plugin-context-component.cjs +5 -5
- package/dist/lib/cjs/components/plugin-gate-component.cjs +69 -36
- package/dist/lib/cjs/components/plugin-gate-component.d.cts +36 -13
- package/dist/lib/cjs/components/plugin-notice-component.cjs +39 -33
- package/dist/lib/cjs/components/plugin-notice-component.d.cts +4 -3
- package/dist/lib/cjs/components/plugin-settings-component.cjs +119 -18
- package/dist/lib/cjs/components/plugin-settings-component.d.cts +35 -5
- package/dist/lib/cjs/components/plugin-settings-tab-component.cjs +2 -2
- package/dist/lib/cjs/components/plugin-suggestion-component.cjs +8 -8
- package/dist/lib/cjs/components/pointer-position-component.cjs +2 -2
- package/dist/lib/cjs/components/reconfigurable-editor-extension-component.cjs +3 -3
- package/dist/lib/cjs/components/registry-component.cjs +2 -2
- package/dist/lib/cjs/components/release-notes-component.cjs +6 -6
- package/dist/lib/cjs/components/rename-delete-handler-component.cjs +25 -25
- package/dist/lib/cjs/components/rmdir-guard-component.cjs +2 -2
- package/dist/lib/cjs/components/settings-facet-component.cjs +1 -1
- package/dist/lib/cjs/components/settings-migration-component.cjs +5 -5
- package/dist/lib/cjs/components/shared-component-pool-component.cjs +368 -0
- package/dist/lib/cjs/components/shared-component-pool-component.d.cts +129 -0
- package/dist/lib/cjs/components/style-sheet-component.cjs +3 -3
- package/dist/lib/cjs/components/syntax-highlighting-component.cjs +3 -3
- package/dist/lib/cjs/components/templates-language-component.cjs +1 -1
- package/dist/lib/cjs/components/worker-component.cjs +363 -0
- package/dist/lib/cjs/components/worker-component.d.cts +156 -0
- package/dist/lib/cjs/components/worker-pool-component.cjs +185 -0
- package/dist/lib/cjs/components/worker-pool-component.d.cts +102 -0
- package/dist/lib/cjs/components/workspace-layout-state-component.cjs +495 -0
- package/dist/lib/cjs/components/workspace-layout-state-component.d.cts +239 -0
- package/dist/lib/cjs/constructors/get-dom-events-handlers-constructor.cjs +5 -5
- package/dist/lib/cjs/constructors/index.cjs +1 -1
- package/dist/lib/cjs/css-class.cjs +5 -1
- package/dist/lib/cjs/css-class.d.cts +16 -0
- package/dist/lib/cjs/data-handler.cjs +264 -6
- package/dist/lib/cjs/data-handler.d.cts +219 -2
- package/dist/lib/cjs/data-stores/data-store-locations.cjs +82 -24
- package/dist/lib/cjs/data-stores/data-store-locations.d.cts +15 -0
- package/dist/lib/cjs/data-stores/data-store-replica.cjs +33 -5
- package/dist/lib/cjs/data-stores/data-store-seeds.cjs +6 -6
- package/dist/lib/cjs/data-stores/data-store-seeds.d.cts +2 -2
- package/dist/lib/cjs/data-stores/data-store-transport.cjs +81 -8
- package/dist/lib/cjs/data-stores/data-store-transport.d.cts +30 -1
- package/dist/lib/cjs/data-stores/index.cjs +6 -6
- package/dist/lib/cjs/data-stores/local-data-store.cjs +74 -10
- package/dist/lib/cjs/data-stores/local-data-store.d.cts +58 -1
- package/dist/lib/cjs/data-stores/shared-data-store.cjs +76 -19
- package/dist/lib/cjs/data-stores/shared-data-store.d.cts +18 -1
- package/dist/lib/cjs/dataview-link.cjs +2 -2
- package/dist/lib/cjs/dataview.cjs +27 -7
- package/dist/lib/cjs/dataview.d.cts +14 -0
- package/dist/lib/cjs/debug.cjs +3 -3
- package/dist/lib/cjs/demo-vault-helper.cjs +34 -6
- package/dist/lib/cjs/demo-vault-helper.d.cts +6 -2
- package/dist/lib/cjs/desktop-bulk-operation-git.cjs +10 -10
- package/dist/lib/cjs/desktop-demo-vault-opener.cjs +13 -13
- package/dist/lib/cjs/desktop-git-runner.cjs +4 -14
- package/dist/lib/cjs/desktop-git-runner.d.cts +8 -2
- package/dist/lib/cjs/desktop-operating-system.cjs +1 -1
- package/dist/lib/cjs/desktop-request-url-stream.cjs +8 -14
- package/dist/lib/cjs/desktop-trusted-input.cjs +2 -2
- package/dist/lib/cjs/disposable.cjs +150 -0
- package/dist/lib/cjs/disposable.d.cts +39 -0
- package/dist/lib/cjs/editor-extension-registrar.cjs +1 -1
- package/dist/lib/cjs/editor-suggest-registrar.cjs +2 -2
- package/dist/lib/cjs/editor-suggest.cjs +1 -1
- package/dist/lib/cjs/editor.cjs +6 -6
- package/dist/lib/cjs/events.cjs +2 -2
- package/dist/lib/cjs/extensions-registrar.cjs +1 -1
- package/dist/lib/cjs/feature-request.cjs +1 -1
- package/dist/lib/cjs/file-change.cjs +10 -10
- package/dist/lib/cjs/file-explorer.cjs +2 -2
- package/dist/lib/cjs/file-manager.cjs +5 -5
- package/dist/lib/cjs/file-system.cjs +10 -10
- package/dist/lib/cjs/folder-note.cjs +4 -4
- package/dist/lib/cjs/frontmatter-formatting.cjs +7 -6
- package/dist/lib/cjs/frontmatter-link-cache-with-offsets.cjs +1 -1
- package/dist/lib/cjs/frontmatter.cjs +5 -5
- package/dist/lib/cjs/generated-during-build.cjs +2 -2
- package/dist/lib/cjs/git-rename-history.cjs +1 -1
- package/dist/lib/cjs/git-rename-history.d.cts +2 -2
- package/dist/lib/cjs/hotkey.cjs +1 -1
- package/dist/lib/cjs/hover-link-source-registrar.cjs +1 -1
- package/dist/lib/cjs/html-element.cjs +2 -2
- package/dist/lib/cjs/i18n/custom-type-options.cjs +1 -1
- package/dist/lib/cjs/i18n/default-translations.cjs +1 -1
- package/dist/lib/cjs/i18n/i18n.cjs +7 -7
- package/dist/lib/cjs/i18n/index.cjs +4 -4
- package/dist/lib/cjs/i18n/locales/en.cjs +27 -1
- package/dist/lib/cjs/i18n/locales/en.d.cts +26 -0
- package/dist/lib/cjs/i18n/locales/index.cjs +2 -2
- package/dist/lib/cjs/i18n/locales/translations-map.cjs +1 -1
- package/dist/lib/cjs/i18n/locales/translations-map.d.cts +26 -0
- package/dist/lib/cjs/index.cjs +147 -126
- package/dist/lib/cjs/index.d.cts +7 -0
- package/dist/lib/cjs/inline-token-renderer.cjs +2 -2
- package/dist/lib/cjs/is-in-obsidian.cjs +1 -1
- package/dist/lib/cjs/library-styles.cjs +3 -3
- package/dist/lib/cjs/link-and-tag-input-suggest.cjs +2 -2
- package/dist/lib/cjs/link.cjs +76 -56
- package/dist/lib/cjs/link.d.cts +20 -14
- package/dist/lib/cjs/logger.cjs +4 -4
- package/dist/lib/cjs/loop.cjs +10 -16
- package/dist/lib/cjs/markdown-code-block-processor-registrar.cjs +17 -2
- package/dist/lib/cjs/markdown-code-block-processor-registrar.d.cts +7 -0
- package/dist/lib/cjs/markdown-code-block-processor.cjs +13 -13
- package/dist/lib/cjs/markdown-post-processor-registrar.cjs +2 -2
- package/dist/lib/cjs/markdown-view.cjs +191 -3
- package/dist/lib/cjs/markdown-view.d.cts +48 -1
- package/dist/lib/cjs/markdown.cjs +12 -12
- package/dist/lib/cjs/metadata-cache.cjs +23 -23
- package/dist/lib/cjs/metadata-cache.d.cts +5 -4
- package/dist/lib/cjs/misplaced-attachment.cjs +297 -0
- package/dist/lib/cjs/misplaced-attachment.d.cts +228 -0
- package/dist/lib/cjs/mobile-app-info.cjs +1 -1
- package/dist/lib/cjs/modals/alert.cjs +4 -4
- package/dist/lib/cjs/modals/code-block-builder.cjs +7 -7
- package/dist/lib/cjs/modals/confirm.cjs +4 -4
- package/dist/lib/cjs/modals/copy-text-manually.cjs +181 -0
- package/dist/lib/cjs/modals/copy-text-manually.d.cts +38 -0
- package/dist/lib/cjs/modals/index.cjs +17 -11
- package/dist/lib/cjs/modals/index.d.cts +2 -0
- package/dist/lib/cjs/modals/minimizable-modal.cjs +6 -6
- package/dist/lib/cjs/modals/modal-command-builder.cjs +3 -3
- package/dist/lib/cjs/modals/modal.cjs +3 -3
- package/dist/lib/cjs/modals/prompt.cjs +10 -10
- package/dist/lib/cjs/modals/prompt.d.cts +1 -1
- package/dist/lib/cjs/modals/review-bug-report-diagnostics.cjs +202 -0
- package/dist/lib/cjs/modals/review-bug-report-diagnostics.d.cts +30 -0
- package/dist/lib/cjs/modals/select-item.cjs +6 -6
- package/dist/lib/cjs/modals/select-option.cjs +3 -3
- package/dist/lib/cjs/modals/suggest-modal-command-builder.cjs +1 -1
- package/dist/lib/cjs/note-priority.cjs +2 -2
- package/dist/lib/cjs/notebook-navigator.cjs +12 -2
- package/dist/lib/cjs/notebook-navigator.d.cts +6 -0
- package/dist/lib/cjs/obsidian-lib-state.cjs +1 -1
- package/dist/lib/cjs/obsidian-protocol-handler-registrar.cjs +1 -1
- package/dist/lib/cjs/obsidian-settings.cjs +1 -1
- package/dist/lib/cjs/obsidian-word-characters.cjs +1 -1
- package/dist/lib/cjs/parse-link.cjs +14 -14
- package/dist/lib/cjs/path-compatibility.cjs +368 -0
- package/dist/lib/cjs/path-compatibility.d.cts +263 -0
- package/dist/lib/cjs/path-settings.cjs +3 -3
- package/dist/lib/cjs/pdf.cjs +2 -2
- package/dist/lib/cjs/plugin/index.cjs +18 -12
- package/dist/lib/cjs/plugin/index.d.cts +2 -0
- package/dist/lib/cjs/plugin/plugin-api.cjs +21 -12
- package/dist/lib/cjs/plugin/plugin-api.d.cts +5 -1
- package/dist/lib/cjs/plugin/plugin-async-cleanup.cjs +6 -3
- package/dist/lib/cjs/plugin/plugin-async-cleanup.d.cts +5 -0
- package/dist/lib/cjs/plugin/plugin-context.cjs +10 -9
- package/dist/lib/cjs/plugin/plugin-event-source.cjs +1 -1
- package/dist/lib/cjs/plugin/plugin-event-source.d.cts +4 -4
- package/dist/lib/cjs/plugin/plugin-install-state.cjs +49 -4
- package/dist/lib/cjs/plugin/plugin-install-state.d.cts +30 -0
- package/dist/lib/cjs/plugin/plugin-instance.cjs +450 -0
- package/dist/lib/cjs/plugin/plugin-instance.d.cts +258 -0
- package/dist/lib/cjs/plugin/plugin-lifecycle-events.cjs +1 -1
- package/dist/lib/cjs/plugin/plugin-lifecycle-events.d.cts +6 -4
- package/dist/lib/cjs/plugin/plugin-settings-tab.cjs +15 -15
- package/dist/lib/cjs/plugin/plugin.cjs +133 -34
- package/dist/lib/cjs/plugin/plugin.d.cts +35 -5
- package/dist/lib/cjs/plugin/settings-migration-api.cjs +1 -1
- package/dist/lib/cjs/plugin/third-party-plugin.cjs +231 -0
- package/dist/lib/cjs/plugin/third-party-plugin.d.cts +244 -0
- package/dist/lib/cjs/plugin-cli-handler-registrar.cjs +2 -2
- package/dist/lib/cjs/popovers/field-popover.cjs +4 -4
- package/dist/lib/cjs/popovers/index.cjs +3 -3
- package/dist/lib/cjs/popovers/popover-anchor.cjs +1 -1
- package/dist/lib/cjs/popovers/popover.cjs +5 -5
- package/dist/lib/cjs/queue.cjs +8 -8
- package/dist/lib/cjs/react/app-context.cjs +3 -3
- package/dist/lib/cjs/react/index.cjs +1 -1
- package/dist/lib/cjs/reference-definition.cjs +1 -1
- package/dist/lib/cjs/reference.cjs +3 -3
- package/dist/lib/cjs/release-asset.cjs +5 -5
- package/dist/lib/cjs/rendered-markdown.cjs +4 -4
- package/dist/lib/cjs/request-url.cjs +4 -4
- package/dist/lib/cjs/resource-lock.cjs +46 -42
- package/dist/lib/cjs/resource-lock.d.cts +8 -7
- package/dist/lib/cjs/resource-url.cjs +3 -3
- package/dist/lib/cjs/ribbon-icon-registrar.cjs +1 -1
- package/dist/lib/cjs/setting-components/checkbox-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/code-highlighter-component.cjs +7 -7
- package/dist/lib/cjs/setting-components/date-component.cjs +4 -4
- package/dist/lib/cjs/setting-components/date-time-component.cjs +4 -4
- package/dist/lib/cjs/setting-components/email-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/file-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/folder-list-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/hotkey-component.cjs +5 -5
- package/dist/lib/cjs/setting-components/index.cjs +30 -30
- package/dist/lib/cjs/setting-components/list-component.cjs +5 -5
- package/dist/lib/cjs/setting-components/month-component.cjs +4 -4
- package/dist/lib/cjs/setting-components/multiple-dropdown-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/multiple-email-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/multiple-file-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/multiple-text-component.cjs +9 -6
- package/dist/lib/cjs/setting-components/multiple-text-component.d.cts +4 -1
- package/dist/lib/cjs/setting-components/number-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/password-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/setting-component-wrapper.cjs +3 -3
- package/dist/lib/cjs/setting-components/tag-list-component.cjs +4 -4
- package/dist/lib/cjs/setting-components/telephone-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/text-based-component.cjs +1 -1
- package/dist/lib/cjs/setting-components/time-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/tri-state-checkbox-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/typed-dropdown-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/typed-multiple-dropdown-component.cjs +4 -4
- package/dist/lib/cjs/setting-components/typed-range-text-component.cjs +1 -1
- package/dist/lib/cjs/setting-components/typed-text-component.cjs +3 -3
- package/dist/lib/cjs/setting-components/url-component.cjs +2 -2
- package/dist/lib/cjs/setting-components/validator-component.cjs +4 -4
- package/dist/lib/cjs/setting-components/week-component.cjs +4 -4
- package/dist/lib/cjs/setting-ex.cjs +26 -26
- package/dist/lib/cjs/setting-group-ex.cjs +2 -2
- package/dist/lib/cjs/settings-recovery.cjs +217 -0
- package/dist/lib/cjs/settings-recovery.d.cts +178 -0
- package/dist/lib/cjs/settings-tabs.cjs +5 -5
- package/dist/lib/cjs/status-bar-item-registrar.cjs +1 -1
- package/dist/lib/cjs/templater.cjs +14 -4
- package/dist/lib/cjs/templater.d.cts +6 -0
- package/dist/lib/cjs/transformers/duration-transformer.cjs +2 -2
- package/dist/lib/cjs/transformers/index.cjs +1 -1
- package/dist/lib/cjs/trusted-input.cjs +1 -1
- package/dist/lib/cjs/validation.cjs +4 -4
- package/dist/lib/cjs/vault-delete.cjs +6 -6
- package/dist/lib/cjs/vault-transaction.cjs +5 -5
- package/dist/lib/cjs/vault.cjs +12 -12
- package/dist/lib/cjs/view-registrar.cjs +1 -1
- package/dist/lib/cjs/virtual-file.cjs +16 -14
- package/dist/lib/cjs/virtual-file.d.cts +2 -1
- package/dist/lib/cjs/wasm.cjs +119 -0
- package/dist/lib/cjs/wasm.d.cts +54 -0
- package/dist/lib/cjs/worker-protocol.cjs +209 -0
- package/dist/lib/cjs/worker-protocol.d.cts +282 -0
- package/dist/lib/cjs/workspace.cjs +1 -1
- package/dist/lib/esm/__merged.d.mts +26 -10
- package/dist/lib/esm/__merged.mjs +215 -5
- package/dist/lib/esm/app.mjs +2 -2
- package/dist/lib/esm/attachment-path.d.mts +3 -3
- package/dist/lib/esm/attachment-path.mjs +2 -2
- package/dist/lib/esm/backlink-index.mjs +2 -2
- package/dist/lib/esm/bug-report-diagnostics.d.mts +186 -0
- package/dist/lib/esm/bug-report-diagnostics.mjs +127 -0
- package/dist/lib/esm/bug-report.d.mts +65 -0
- package/dist/lib/esm/bug-report.mjs +33 -10
- package/dist/lib/esm/canvas.d.mts +13 -0
- package/dist/lib/esm/canvas.mjs +6 -5
- package/dist/lib/esm/command-handlers/abstract-file-command-handler.d.mts +13 -13
- package/dist/lib/esm/command-handlers/abstract-file-command-handler.mjs +14 -14
- package/dist/lib/esm/command-handlers/editor-command-handler.d.mts +7 -7
- package/dist/lib/esm/command-handlers/editor-command-handler.mjs +8 -8
- package/dist/lib/esm/command-handlers/open-bug-report-command-handler.d.mts +34 -2
- package/dist/lib/esm/command-handlers/open-bug-report-command-handler.mjs +99 -3
- package/dist/lib/esm/components/all-windows-status-bar-item-component.d.mts +146 -0
- package/dist/lib/esm/components/all-windows-status-bar-item-component.mjs +154 -0
- package/dist/lib/esm/components/component-ex.d.mts +11 -0
- package/dist/lib/esm/components/component-ex.mjs +19 -6
- package/dist/lib/esm/components/disposable-component.mjs +1 -1
- package/dist/lib/esm/components/embed-extensions-component.d.mts +8 -0
- package/dist/lib/esm/components/embed-extensions-component.mjs +20 -3
- package/dist/lib/esm/components/embeddable-markdown-editor-component.d.mts +9 -0
- package/dist/lib/esm/components/embeddable-markdown-editor-component.mjs +16 -2
- package/dist/lib/esm/components/index.d.mts +5 -0
- package/dist/lib/esm/components/index.mjs +12 -2
- package/dist/lib/esm/components/plugin-gate-component.d.mts +36 -13
- package/dist/lib/esm/components/plugin-gate-component.mjs +61 -26
- package/dist/lib/esm/components/plugin-notice-component.d.mts +4 -3
- package/dist/lib/esm/components/plugin-notice-component.mjs +30 -21
- package/dist/lib/esm/components/plugin-settings-component.d.mts +35 -5
- package/dist/lib/esm/components/plugin-settings-component.mjs +105 -4
- package/dist/lib/esm/components/rename-delete-handler-component.mjs +2 -2
- package/dist/lib/esm/components/shared-component-pool-component.d.mts +129 -0
- package/dist/lib/esm/components/shared-component-pool-component.mjs +280 -0
- package/dist/lib/esm/components/worker-component.d.mts +156 -0
- package/dist/lib/esm/components/worker-component.mjs +279 -0
- package/dist/lib/esm/components/worker-pool-component.d.mts +102 -0
- package/dist/lib/esm/components/worker-pool-component.mjs +95 -0
- package/dist/lib/esm/components/workspace-layout-state-component.d.mts +239 -0
- package/dist/lib/esm/components/workspace-layout-state-component.mjs +404 -0
- package/dist/lib/esm/css-class.d.mts +16 -0
- package/dist/lib/esm/css-class.mjs +5 -1
- package/dist/lib/esm/data-handler.d.mts +219 -2
- package/dist/lib/esm/data-handler.mjs +262 -5
- package/dist/lib/esm/data-stores/data-store-locations.d.mts +15 -0
- package/dist/lib/esm/data-stores/data-store-locations.mjs +80 -22
- package/dist/lib/esm/data-stores/data-store-replica.mjs +33 -5
- package/dist/lib/esm/data-stores/data-store-seeds.d.mts +2 -2
- package/dist/lib/esm/data-stores/data-store-seeds.mjs +4 -4
- package/dist/lib/esm/data-stores/data-store-transport.d.mts +30 -1
- package/dist/lib/esm/data-stores/data-store-transport.mjs +78 -5
- package/dist/lib/esm/data-stores/local-data-store.d.mts +58 -1
- package/dist/lib/esm/data-stores/local-data-store.mjs +71 -9
- package/dist/lib/esm/data-stores/shared-data-store.d.mts +18 -1
- package/dist/lib/esm/data-stores/shared-data-store.mjs +72 -15
- package/dist/lib/esm/dataview.d.mts +14 -0
- package/dist/lib/esm/dataview.mjs +19 -1
- package/dist/lib/esm/demo-vault-helper.d.mts +6 -2
- package/dist/lib/esm/demo-vault-helper.mjs +29 -1
- package/dist/lib/esm/desktop-demo-vault-opener.mjs +1 -1
- package/dist/lib/esm/desktop-git-runner.d.mts +8 -2
- package/dist/lib/esm/desktop-git-runner.mjs +3 -3
- package/dist/lib/esm/desktop-request-url-stream.mjs +4 -10
- package/dist/lib/esm/disposable.d.mts +39 -0
- package/dist/lib/esm/disposable.mjs +64 -0
- package/dist/lib/esm/file-system.mjs +2 -2
- package/dist/lib/esm/frontmatter-formatting.mjs +2 -1
- package/dist/lib/esm/generated-during-build.mjs +2 -2
- package/dist/lib/esm/git-rename-history.d.mts +2 -2
- package/dist/lib/esm/git-rename-history.mjs +1 -1
- package/dist/lib/esm/i18n/locales/en.d.mts +26 -0
- package/dist/lib/esm/i18n/locales/en.mjs +27 -1
- package/dist/lib/esm/i18n/locales/translations-map.d.mts +26 -0
- package/dist/lib/esm/index.d.mts +7 -0
- package/dist/lib/esm/index.mjs +15 -1
- package/dist/lib/esm/link.d.mts +20 -14
- package/dist/lib/esm/link.mjs +57 -38
- package/dist/lib/esm/loop.mjs +2 -8
- package/dist/lib/esm/markdown-code-block-processor-registrar.d.mts +7 -0
- package/dist/lib/esm/markdown-code-block-processor-registrar.mjs +16 -1
- package/dist/lib/esm/markdown-view.d.mts +48 -1
- package/dist/lib/esm/markdown-view.mjs +192 -2
- package/dist/lib/esm/metadata-cache.d.mts +5 -4
- package/dist/lib/esm/metadata-cache.mjs +6 -6
- package/dist/lib/esm/misplaced-attachment.d.mts +228 -0
- package/dist/lib/esm/misplaced-attachment.mjs +212 -0
- package/dist/lib/esm/modals/copy-text-manually.d.mts +38 -0
- package/dist/lib/esm/modals/copy-text-manually.mjs +99 -0
- package/dist/lib/esm/modals/index.d.mts +2 -0
- package/dist/lib/esm/modals/index.mjs +5 -1
- package/dist/lib/esm/modals/prompt.d.mts +1 -1
- package/dist/lib/esm/modals/prompt.mjs +1 -1
- package/dist/lib/esm/modals/review-bug-report-diagnostics.d.mts +30 -0
- package/dist/lib/esm/modals/review-bug-report-diagnostics.mjs +120 -0
- package/dist/lib/esm/notebook-navigator.d.mts +6 -0
- package/dist/lib/esm/notebook-navigator.mjs +11 -2
- package/dist/lib/esm/parse-link.mjs +4 -4
- package/dist/lib/esm/path-compatibility.d.mts +263 -0
- package/dist/lib/esm/path-compatibility.mjs +277 -0
- package/dist/lib/esm/plugin/index.d.mts +2 -0
- package/dist/lib/esm/plugin/index.mjs +6 -2
- package/dist/lib/esm/plugin/plugin-api.d.mts +5 -1
- package/dist/lib/esm/plugin/plugin-api.mjs +13 -4
- package/dist/lib/esm/plugin/plugin-async-cleanup.d.mts +5 -0
- package/dist/lib/esm/plugin/plugin-async-cleanup.mjs +3 -1
- package/dist/lib/esm/plugin/plugin-context.mjs +2 -1
- package/dist/lib/esm/plugin/plugin-event-source.d.mts +4 -4
- package/dist/lib/esm/plugin/plugin-event-source.mjs +1 -1
- package/dist/lib/esm/plugin/plugin-install-state.d.mts +30 -0
- package/dist/lib/esm/plugin/plugin-install-state.mjs +44 -1
- package/dist/lib/esm/plugin/plugin-instance.d.mts +258 -0
- package/dist/lib/esm/plugin/plugin-instance.mjs +367 -0
- package/dist/lib/esm/plugin/plugin-lifecycle-events.d.mts +6 -4
- package/dist/lib/esm/plugin/plugin-lifecycle-events.mjs +1 -1
- package/dist/lib/esm/plugin/plugin.d.mts +35 -5
- package/dist/lib/esm/plugin/plugin.mjs +118 -9
- package/dist/lib/esm/plugin/third-party-plugin.d.mts +244 -0
- package/dist/lib/esm/plugin/third-party-plugin.mjs +147 -0
- package/dist/lib/esm/release-asset.mjs +1 -1
- package/dist/lib/esm/resource-lock.d.mts +8 -7
- package/dist/lib/esm/resource-lock.mjs +31 -26
- package/dist/lib/esm/setting-components/multiple-text-component.d.mts +4 -1
- package/dist/lib/esm/setting-components/multiple-text-component.mjs +6 -3
- package/dist/lib/esm/settings-recovery.d.mts +178 -0
- package/dist/lib/esm/settings-recovery.mjs +125 -0
- package/dist/lib/esm/settings-tabs.mjs +2 -2
- package/dist/lib/esm/templater.d.mts +6 -0
- package/dist/lib/esm/templater.mjs +11 -2
- package/dist/lib/esm/vault.mjs +1 -1
- package/dist/lib/esm/virtual-file.d.mts +2 -1
- package/dist/lib/esm/virtual-file.mjs +7 -5
- package/dist/lib/esm/wasm.d.mts +54 -0
- package/dist/lib/esm/wasm.mjs +30 -0
- package/dist/lib/esm/worker-protocol.d.mts +282 -0
- package/dist/lib/esm/worker-protocol.mjs +113 -0
- package/dist/styles.css +16 -1
- package/modals/copy-text-manually/package.json +6 -0
- package/modals/review-bug-report-diagnostics/package.json +6 -0
- package/package.json +10 -8
- package/plugin/plugin-instance/package.json +6 -0
- package/plugin/third-party-plugin/package.json +6 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/// <reference path="../library-references.d.mts" />
|
|
2
|
+
/// <reference lib="dom" />
|
|
3
|
+
/**
|
|
4
|
+
* @file
|
|
5
|
+
*
|
|
6
|
+
* A pool that shares one loaded component per caller-defined key among several consumers, and unloads it when the
|
|
7
|
+
* last consumer releases it.
|
|
8
|
+
*/
|
|
9
|
+
import type { DisposableEx } from '@mnaoumov/typescript-lib/disposable';
|
|
10
|
+
import { Component } from 'obsidian';
|
|
11
|
+
import { ComponentEx } from './component-ex.mjs';
|
|
12
|
+
/**
|
|
13
|
+
* One consumer's hold on a shared component.
|
|
14
|
+
*
|
|
15
|
+
* Releasing it is idempotent: the first call drops the hold, and every later call — including the one the consumer
|
|
16
|
+
* link makes when the consumer unloads — does nothing.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam TComponent - The type of the shared component.
|
|
19
|
+
*/
|
|
20
|
+
export interface SharedComponentAcquisition<TComponent extends Component> extends DisposableEx {
|
|
21
|
+
/**
|
|
22
|
+
* The shared component, loaded. Every consumer of the same key receives the same instance.
|
|
23
|
+
*/
|
|
24
|
+
readonly component: TComponent;
|
|
25
|
+
/**
|
|
26
|
+
* Whether this acquisition has been released.
|
|
27
|
+
*/
|
|
28
|
+
readonly isReleased: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Releases this acquisition. The shared component is unloaded when its last acquisition is released.
|
|
31
|
+
*/
|
|
32
|
+
readonly release: () => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Options of {@link SharedComponentPoolComponent.acquire}.
|
|
36
|
+
*/
|
|
37
|
+
export interface SharedComponentPoolComponentAcquireOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Cancels the acquisition while the shared component is still loading. An abort after the acquisition resolved does
|
|
40
|
+
* nothing; release the acquisition instead.
|
|
41
|
+
*/
|
|
42
|
+
readonly abortSignal?: AbortSignal;
|
|
43
|
+
/**
|
|
44
|
+
* A component whose unload releases the acquisition automatically.
|
|
45
|
+
*
|
|
46
|
+
* The link is a child component added to the consumer, so it follows Obsidian's own rules: a consumer that is not
|
|
47
|
+
* loaded yet starts holding the link when it loads, and a {@link ComponentEx} consumer that is already unloaded
|
|
48
|
+
* refuses it with a {@link SilentError}. Releasing the acquisition by hand removes the link again, so a long-lived
|
|
49
|
+
* consumer that acquires and releases many times accumulates nothing.
|
|
50
|
+
*/
|
|
51
|
+
readonly consumer?: Component;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Parameters of {@link SharedComponentPoolComponent}.
|
|
55
|
+
*
|
|
56
|
+
* @typeParam TKey - The type of the resource key.
|
|
57
|
+
* @typeParam TComponent - The type of the shared component.
|
|
58
|
+
*/
|
|
59
|
+
export interface SharedComponentPoolComponentConstructorParams<TKey, TComponent extends Component> {
|
|
60
|
+
/**
|
|
61
|
+
* Creates the component shared under a key. Called once per key each time the key goes from no consumer to one; the
|
|
62
|
+
* pool loads the component itself, so the factory must return it unloaded.
|
|
63
|
+
*
|
|
64
|
+
* @param key - The resource key.
|
|
65
|
+
* @returns The new, not yet loaded component.
|
|
66
|
+
*/
|
|
67
|
+
readonly createComponent: (key: TKey) => TComponent;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Shares one loaded component per caller-defined key among several consumers.
|
|
71
|
+
*
|
|
72
|
+
* The first {@link acquire} of a key creates the component through the factory and loads it; every further acquire of
|
|
73
|
+
* the same key, concurrent or later, receives the same instance; the release of the last acquisition unloads it, and
|
|
74
|
+
* the next acquire creates a fresh one. A {@link ComponentEx} is loaded through {@link ComponentEx.loadWithPromises}, so
|
|
75
|
+
* an acquire resolves only once its `onloadAsync` and children have settled, and a failed load rejects every waiting
|
|
76
|
+
* acquire, unloads the component and leaves the key free for a fresh attempt.
|
|
77
|
+
*
|
|
78
|
+
* The pool is itself a component, and its parent is the owner of every shared instance: add it with `addChild` to the
|
|
79
|
+
* plugin (or any longer-lived component). Unloading the owner unloads every shared component still held, rejects
|
|
80
|
+
* every acquire still waiting with a {@link SilentError}, and refuses later acquires. Keys are compared the way a
|
|
81
|
+
* {@link Map} compares them, so two equal-looking object keys are two resources. The instances live on the pool
|
|
82
|
+
* object only, never in the shared-state bag, so two plugins — or two pools of one plugin — never share anything.
|
|
83
|
+
*
|
|
84
|
+
* Reach for it only when SEVERAL independent consumers want the same expensive component and none of them owns it.
|
|
85
|
+
* A component with a single owner is that owner's child: `addChild` is simpler and already unloads it with its owner.
|
|
86
|
+
*
|
|
87
|
+
* @typeParam TKey - The type of the resource key.
|
|
88
|
+
* @typeParam TComponent - The type of the shared component.
|
|
89
|
+
*/
|
|
90
|
+
export declare class SharedComponentPoolComponent<TKey, TComponent extends Component> extends ComponentEx {
|
|
91
|
+
/**
|
|
92
|
+
* Creates the component shared under a key; see {@link SharedComponentPoolComponentConstructorParams.createComponent}.
|
|
93
|
+
*/
|
|
94
|
+
protected readonly createComponent: (key: TKey) => TComponent;
|
|
95
|
+
private readonly creatingKeys;
|
|
96
|
+
private readonly entries;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new pool.
|
|
99
|
+
*
|
|
100
|
+
* @param params - The pool parameters.
|
|
101
|
+
*/
|
|
102
|
+
constructor(params: SharedComponentPoolComponentConstructorParams<TKey, TComponent>);
|
|
103
|
+
/**
|
|
104
|
+
* Acquires the component shared under a key, creating and loading it when the key has no consumer yet.
|
|
105
|
+
*
|
|
106
|
+
* @param key - The resource key.
|
|
107
|
+
* @param options - The acquisition options.
|
|
108
|
+
* @returns The acquisition, once the shared component has loaded.
|
|
109
|
+
* @throws An {@link Error} when the pool was never loaded, when the factory or the load fails, or when called for a
|
|
110
|
+
* key from inside that key's own factory or synchronous load; a {@link SilentError} when the pool is unloaded, or
|
|
111
|
+
* when the consumer unloads or the acquisition is released before the load completes; the abort reason when
|
|
112
|
+
* `abortSignal` aborts first.
|
|
113
|
+
*/
|
|
114
|
+
acquire(key: TKey, options?: SharedComponentPoolComponentAcquireOptions): Promise<SharedComponentAcquisition<TComponent>>;
|
|
115
|
+
/**
|
|
116
|
+
* Returns how many acquisitions currently hold the component shared under a key, pending ones included.
|
|
117
|
+
*
|
|
118
|
+
* @param key - The resource key.
|
|
119
|
+
* @returns The number of consumers, `0` when the key has no shared component.
|
|
120
|
+
*/
|
|
121
|
+
getConsumerCount(key: TKey): number;
|
|
122
|
+
/**
|
|
123
|
+
* Registers the teardown that unloads every shared component when the pool unloads.
|
|
124
|
+
*/
|
|
125
|
+
onload(): void;
|
|
126
|
+
private createEntry;
|
|
127
|
+
private releaseReference;
|
|
128
|
+
private unloadEntry;
|
|
129
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/*
|
|
2
|
+
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
3
|
+
if you want to view the source, please visit the github repository of this plugin
|
|
4
|
+
*/
|
|
5
|
+
(function () {
|
|
6
|
+
function ensureDisposeSymbols(symbolConstructor = Symbol) {
|
|
7
|
+
symbolConstructor.asyncDispose ??= symbolConstructor.for("Symbol.asyncDispose");
|
|
8
|
+
symbolConstructor.dispose ??= symbolConstructor.for("Symbol.dispose");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function ensureBrowserProcess() {
|
|
12
|
+
const browserProcess = {
|
|
13
|
+
browser: true,
|
|
14
|
+
cwd() {
|
|
15
|
+
return "/";
|
|
16
|
+
},
|
|
17
|
+
env: {},
|
|
18
|
+
platform: "android"
|
|
19
|
+
};
|
|
20
|
+
const existingProcess = globalThis.process;
|
|
21
|
+
if (!existingProcess) {
|
|
22
|
+
globalThis.process = browserProcess;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (existingProcess.versions?.node) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const existingProcessRecord = existingProcess;
|
|
29
|
+
for (const [key, value] of Object.entries(browserProcess)) {
|
|
30
|
+
existingProcessRecord[key] ??= value;
|
|
31
|
+
}
|
|
32
|
+
existingProcessRecord["browser"] = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ensureDisposeSymbols();
|
|
36
|
+
ensureBrowserProcess();
|
|
37
|
+
})();
|
|
38
|
+
|
|
39
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
40
|
+
var __typeError = (msg) => {
|
|
41
|
+
throw TypeError(msg);
|
|
42
|
+
};
|
|
43
|
+
var __using = (stack, value, async) => {
|
|
44
|
+
if (value != null) {
|
|
45
|
+
if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
|
|
46
|
+
var dispose, inner;
|
|
47
|
+
if (async) dispose = value[__knownSymbol("asyncDispose")];
|
|
48
|
+
if (dispose === void 0) {
|
|
49
|
+
dispose = value[__knownSymbol("dispose")];
|
|
50
|
+
if (async) inner = dispose;
|
|
51
|
+
}
|
|
52
|
+
if (typeof dispose !== "function") __typeError("Object not disposable");
|
|
53
|
+
if (inner) dispose = function() {
|
|
54
|
+
try {
|
|
55
|
+
inner.call(this);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return Promise.reject(e);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
stack.push([async, dispose, value]);
|
|
61
|
+
} else if (async) {
|
|
62
|
+
stack.push([async]);
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
};
|
|
66
|
+
var __callDispose = (stack, error, hasError) => {
|
|
67
|
+
var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
|
|
68
|
+
return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
|
|
69
|
+
};
|
|
70
|
+
var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
|
|
71
|
+
var next = (it) => {
|
|
72
|
+
while (it = stack.pop()) {
|
|
73
|
+
try {
|
|
74
|
+
var result = it[1] && it[1].call(it[2]);
|
|
75
|
+
if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
fail(e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (hasError) throw error;
|
|
81
|
+
};
|
|
82
|
+
return next();
|
|
83
|
+
};
|
|
84
|
+
import { onAbort } from "@mnaoumov/typescript-lib/abort-controller";
|
|
85
|
+
import { snapshot } from "@mnaoumov/typescript-lib/array";
|
|
86
|
+
import { SilentError } from "@mnaoumov/typescript-lib/error";
|
|
87
|
+
import { noop } from "@mnaoumov/typescript-lib/function";
|
|
88
|
+
import { Component } from "obsidian";
|
|
89
|
+
import { ComponentEx } from "./component-ex.mjs";
|
|
90
|
+
class SharedComponentAcquisitionImpl {
|
|
91
|
+
constructor(component, onRelease) {
|
|
92
|
+
this.component = component;
|
|
93
|
+
this.onRelease = onRelease;
|
|
94
|
+
}
|
|
95
|
+
component;
|
|
96
|
+
onRelease;
|
|
97
|
+
get isReleased() {
|
|
98
|
+
return this._isReleased;
|
|
99
|
+
}
|
|
100
|
+
_isReleased = false;
|
|
101
|
+
unlinkConsumer = null;
|
|
102
|
+
dispose() {
|
|
103
|
+
this.release();
|
|
104
|
+
}
|
|
105
|
+
linkConsumer(consumer) {
|
|
106
|
+
const consumerLink = new Component();
|
|
107
|
+
consumerLink.register(() => {
|
|
108
|
+
this.unlinkConsumer = null;
|
|
109
|
+
this.release();
|
|
110
|
+
});
|
|
111
|
+
consumer.addChild(consumerLink);
|
|
112
|
+
this.unlinkConsumer = () => {
|
|
113
|
+
consumer.removeChild(consumerLink);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
release() {
|
|
117
|
+
if (this._isReleased) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this._isReleased = true;
|
|
121
|
+
const unlinkConsumer = this.unlinkConsumer;
|
|
122
|
+
this.unlinkConsumer = null;
|
|
123
|
+
unlinkConsumer?.();
|
|
124
|
+
this.onRelease();
|
|
125
|
+
}
|
|
126
|
+
[Symbol.dispose]() {
|
|
127
|
+
this.release();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
class SharedComponentPoolComponent extends ComponentEx {
|
|
131
|
+
/**
|
|
132
|
+
* Creates the component shared under a key; see {@link SharedComponentPoolComponentConstructorParams.createComponent}.
|
|
133
|
+
*/
|
|
134
|
+
createComponent;
|
|
135
|
+
creatingKeys = /* @__PURE__ */ new Set();
|
|
136
|
+
entries = /* @__PURE__ */ new Map();
|
|
137
|
+
/**
|
|
138
|
+
* Creates a new pool.
|
|
139
|
+
*
|
|
140
|
+
* @param params - The pool parameters.
|
|
141
|
+
*/
|
|
142
|
+
constructor(params) {
|
|
143
|
+
super();
|
|
144
|
+
this.createComponent = params.createComponent;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Acquires the component shared under a key, creating and loading it when the key has no consumer yet.
|
|
148
|
+
*
|
|
149
|
+
* @param key - The resource key.
|
|
150
|
+
* @param options - The acquisition options.
|
|
151
|
+
* @returns The acquisition, once the shared component has loaded.
|
|
152
|
+
* @throws An {@link Error} when the pool was never loaded, when the factory or the load fails, or when called for a
|
|
153
|
+
* key from inside that key's own factory or synchronous load; a {@link SilentError} when the pool is unloaded, or
|
|
154
|
+
* when the consumer unloads or the acquisition is released before the load completes; the abort reason when
|
|
155
|
+
* `abortSignal` aborts first.
|
|
156
|
+
*/
|
|
157
|
+
async acquire(key, options = {}) {
|
|
158
|
+
var _stack = [];
|
|
159
|
+
try {
|
|
160
|
+
this.ensureLoaded();
|
|
161
|
+
options.abortSignal?.throwIfAborted();
|
|
162
|
+
if (this.creatingKeys.has(key)) {
|
|
163
|
+
throw new Error("A shared component cannot be acquired from inside its own creation");
|
|
164
|
+
}
|
|
165
|
+
const entry = this.entries.get(key) ?? this.createEntry(key);
|
|
166
|
+
entry.consumerCount++;
|
|
167
|
+
const cancellation = createDeferred();
|
|
168
|
+
const acquisition = new SharedComponentAcquisitionImpl(entry.component, () => {
|
|
169
|
+
cancellation.reject(new SilentError("The shared component acquisition was released"));
|
|
170
|
+
this.releaseReference(entry);
|
|
171
|
+
});
|
|
172
|
+
const _abortListener = __using(_stack, options.abortSignal ? onAbort(options.abortSignal, (abortSignal) => {
|
|
173
|
+
cancellation.reject(abortSignal.reason);
|
|
174
|
+
acquisition.release();
|
|
175
|
+
}) : null);
|
|
176
|
+
try {
|
|
177
|
+
if (options.consumer) {
|
|
178
|
+
acquisition.linkConsumer(options.consumer);
|
|
179
|
+
}
|
|
180
|
+
await Promise.race([entry.ready.promise, cancellation.promise]);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
acquisition.release();
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
if (acquisition.isReleased) {
|
|
186
|
+
throw new SilentError("The shared component acquisition was released");
|
|
187
|
+
}
|
|
188
|
+
return acquisition;
|
|
189
|
+
} catch (_) {
|
|
190
|
+
var _error = _, _hasError = true;
|
|
191
|
+
} finally {
|
|
192
|
+
__callDispose(_stack, _error, _hasError);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns how many acquisitions currently hold the component shared under a key, pending ones included.
|
|
197
|
+
*
|
|
198
|
+
* @param key - The resource key.
|
|
199
|
+
* @returns The number of consumers, `0` when the key has no shared component.
|
|
200
|
+
*/
|
|
201
|
+
getConsumerCount(key) {
|
|
202
|
+
return this.entries.get(key)?.consumerCount ?? 0;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Registers the teardown that unloads every shared component when the pool unloads.
|
|
206
|
+
*/
|
|
207
|
+
onload() {
|
|
208
|
+
this.register(() => {
|
|
209
|
+
for (const entry of snapshot([...this.entries.values()])) {
|
|
210
|
+
this.unloadEntry(entry, new SilentError("The shared component pool is unloaded"));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
createEntry(key) {
|
|
215
|
+
this.creatingKeys.add(key);
|
|
216
|
+
try {
|
|
217
|
+
const component = this.createComponent(key);
|
|
218
|
+
const entry = {
|
|
219
|
+
component,
|
|
220
|
+
consumerCount: 0,
|
|
221
|
+
isUnloaded: false,
|
|
222
|
+
key,
|
|
223
|
+
ready: createDeferred()
|
|
224
|
+
};
|
|
225
|
+
this.entries.set(key, entry);
|
|
226
|
+
let loadPromise = null;
|
|
227
|
+
try {
|
|
228
|
+
if (component instanceof ComponentEx) {
|
|
229
|
+
loadPromise = component.loadWithPromises();
|
|
230
|
+
} else {
|
|
231
|
+
component.load();
|
|
232
|
+
}
|
|
233
|
+
} catch (error) {
|
|
234
|
+
this.unloadEntry(entry, error);
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
if (loadPromise) {
|
|
238
|
+
loadPromise.then(() => {
|
|
239
|
+
entry.ready.resolve();
|
|
240
|
+
}).catch((error) => {
|
|
241
|
+
this.unloadEntry(entry, error);
|
|
242
|
+
});
|
|
243
|
+
} else {
|
|
244
|
+
entry.ready.resolve();
|
|
245
|
+
}
|
|
246
|
+
return entry;
|
|
247
|
+
} finally {
|
|
248
|
+
this.creatingKeys.delete(key);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
releaseReference(entry) {
|
|
252
|
+
entry.consumerCount--;
|
|
253
|
+
if (entry.consumerCount <= 0) {
|
|
254
|
+
this.unloadEntry(entry, new SilentError("The last consumer released the shared component before it loaded"));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
unloadEntry(entry, reason) {
|
|
258
|
+
if (entry.isUnloaded) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
entry.isUnloaded = true;
|
|
262
|
+
this.entries.delete(entry.key);
|
|
263
|
+
entry.ready.reject(reason);
|
|
264
|
+
entry.component.unload();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function createDeferred() {
|
|
268
|
+
let resolve = noop;
|
|
269
|
+
let reject = noop;
|
|
270
|
+
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
271
|
+
resolve = resolvePromise;
|
|
272
|
+
reject = rejectPromise;
|
|
273
|
+
});
|
|
274
|
+
promise.catch(noop);
|
|
275
|
+
return { promise, reject, resolve };
|
|
276
|
+
}
|
|
277
|
+
export {
|
|
278
|
+
SharedComponentPoolComponent
|
|
279
|
+
};
|
|
280
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb21wb25lbnRzL3NoYXJlZC1jb21wb25lbnQtcG9vbC1jb21wb25lbnQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBAZmlsZVxuICpcbiAqIEEgcG9vbCB0aGF0IHNoYXJlcyBvbmUgbG9hZGVkIGNvbXBvbmVudCBwZXIgY2FsbGVyLWRlZmluZWQga2V5IGFtb25nIHNldmVyYWwgY29uc3VtZXJzLCBhbmQgdW5sb2FkcyBpdCB3aGVuIHRoZVxuICogbGFzdCBjb25zdW1lciByZWxlYXNlcyBpdC5cbiAqL1xuXG5pbXBvcnQgdHlwZSB7IERpc3Bvc2FibGVFeCB9IGZyb20gJ0BtbmFvdW1vdi90eXBlc2NyaXB0LWxpYi9kaXNwb3NhYmxlJztcblxuaW1wb3J0IHsgb25BYm9ydCB9IGZyb20gJ0BtbmFvdW1vdi90eXBlc2NyaXB0LWxpYi9hYm9ydC1jb250cm9sbGVyJztcbmltcG9ydCB7IHNuYXBzaG90IH0gZnJvbSAnQG1uYW91bW92L3R5cGVzY3JpcHQtbGliL2FycmF5JztcbmltcG9ydCB7IFNpbGVudEVycm9yIH0gZnJvbSAnQG1uYW91bW92L3R5cGVzY3JpcHQtbGliL2Vycm9yJztcbmltcG9ydCB7IG5vb3AgfSBmcm9tICdAbW5hb3Vtb3YvdHlwZXNjcmlwdC1saWIvZnVuY3Rpb24nO1xuaW1wb3J0IHsgQ29tcG9uZW50IH0gZnJvbSAnb2JzaWRpYW4nO1xuXG5pbXBvcnQgeyBDb21wb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FBUSxRQUFRO0FBQ3BDOyIsIm5hbWVzIjpbXX0=
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/// <reference path="../library-references.d.mts" />
|
|
2
|
+
/// <reference lib="dom" />
|
|
3
|
+
/**
|
|
4
|
+
* @file
|
|
5
|
+
*
|
|
6
|
+
* A component that owns one browser `Worker` built from bundled source and calls it through a typed request/response
|
|
7
|
+
* channel.
|
|
8
|
+
*/
|
|
9
|
+
import type { SerializedWorkerError, WorkerApi, WorkerApiHandlers } from '../worker-protocol.mjs';
|
|
10
|
+
import { ComponentEx } from './component-ex.mjs';
|
|
11
|
+
/**
|
|
12
|
+
* Options of {@link WorkerComponent.call}.
|
|
13
|
+
*/
|
|
14
|
+
export interface WorkerComponentCallOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Cancels the call. The returned promise rejects with the signal's reason at once, and the worker's handler sees its
|
|
17
|
+
* own `this.abortSignal` aborted; whatever it answers afterwards is dropped.
|
|
18
|
+
*/
|
|
19
|
+
readonly abortSignal?: AbortSignal;
|
|
20
|
+
/**
|
|
21
|
+
* Objects inside the arguments to transfer rather than copy. They are unusable on the main thread afterwards.
|
|
22
|
+
*/
|
|
23
|
+
readonly transfer?: readonly Transferable[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parameters of {@link WorkerComponent}.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TApi - The API the worker exposes.
|
|
29
|
+
*/
|
|
30
|
+
export interface WorkerComponentConstructorParams<TApi extends WorkerApi<TApi>> {
|
|
31
|
+
/**
|
|
32
|
+
* The same handlers the worker exposes, run on the main thread when no `Worker` can be created. Without them, a
|
|
33
|
+
* failure to create the worker fails the component's load.
|
|
34
|
+
*/
|
|
35
|
+
readonly fallbackHandlers?: WorkerApiHandlers<TApi>;
|
|
36
|
+
/**
|
|
37
|
+
* The worker's name, shown by the developer tools.
|
|
38
|
+
*/
|
|
39
|
+
readonly name?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The bundled worker source: the string a `*.worker.ts?worker-source` import gives with
|
|
42
|
+
* `@mnaoumov/obsidian-dev-toolkit`'s `workers` feature.
|
|
43
|
+
*/
|
|
44
|
+
readonly source: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The method names of a {@link WorkerApi}.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam TApi - The API type.
|
|
50
|
+
*/
|
|
51
|
+
export type WorkerMethod<TApi> = Extract<keyof TApi, string>;
|
|
52
|
+
/**
|
|
53
|
+
* The resolved result type of a worker method.
|
|
54
|
+
*
|
|
55
|
+
* @typeParam TApi - The API type.
|
|
56
|
+
* @typeParam TMethod - The method.
|
|
57
|
+
*/
|
|
58
|
+
export type WorkerMethodResult<TApi extends WorkerApi<TApi>, TMethod extends WorkerMethod<TApi>> = Awaited<ReturnType<TApi[TMethod]>>;
|
|
59
|
+
/**
|
|
60
|
+
* The error a call rejects with when the worker's handler failed. It carries the worker-side name, message and stack,
|
|
61
|
+
* because an `Error` loses its class across the worker boundary.
|
|
62
|
+
*/
|
|
63
|
+
export declare class WorkerCallError extends Error {
|
|
64
|
+
/**
|
|
65
|
+
* The name of the error thrown in the worker.
|
|
66
|
+
*/
|
|
67
|
+
readonly remoteName: string;
|
|
68
|
+
/**
|
|
69
|
+
* The stack of the error thrown in the worker, when there was one.
|
|
70
|
+
*/
|
|
71
|
+
readonly remoteStack: string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Creates the error.
|
|
74
|
+
*
|
|
75
|
+
* @param error - The serialized worker-side error.
|
|
76
|
+
*/
|
|
77
|
+
constructor(error: SerializedWorkerError);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Owns one `Worker` for the component's lifetime.
|
|
81
|
+
*
|
|
82
|
+
* On load it turns the bundled source into a Blob URL and starts the worker; on unload it terminates the worker,
|
|
83
|
+
* revokes the URL and rejects every pending call. Add it as a child of the plugin (or of any component), so the worker
|
|
84
|
+
* never outlives what uses it.
|
|
85
|
+
*
|
|
86
|
+
* The worker entry point calls `exposeWorkerApi` from `@mnaoumov/obsidian-lib/worker-protocol`, and
|
|
87
|
+
* {@link WorkerComponent.call} reaches its handlers by name, typed by `TApi`.
|
|
88
|
+
*
|
|
89
|
+
* @typeParam TApi - The API the worker exposes.
|
|
90
|
+
*/
|
|
91
|
+
export declare class WorkerComponent<TApi extends WorkerApi<TApi>> extends ComponentEx {
|
|
92
|
+
/**
|
|
93
|
+
* Whether calls run on the main thread, because no `Worker` could be created and fallback handlers were given.
|
|
94
|
+
*
|
|
95
|
+
* @returns Whether the fallback is in use.
|
|
96
|
+
*/
|
|
97
|
+
get isUsingFallback(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* The number of calls that have not settled yet.
|
|
100
|
+
*
|
|
101
|
+
* @returns The count.
|
|
102
|
+
*/
|
|
103
|
+
get pendingCallCount(): number;
|
|
104
|
+
/**
|
|
105
|
+
* The handlers to run on the main thread when no `Worker` can be created, or `null`.
|
|
106
|
+
*/
|
|
107
|
+
protected readonly fallbackHandlers: null | WorkerApiHandlers<TApi>;
|
|
108
|
+
/**
|
|
109
|
+
* The worker's name, or `null`.
|
|
110
|
+
*/
|
|
111
|
+
protected readonly name: null | string;
|
|
112
|
+
/**
|
|
113
|
+
* The bundled worker source.
|
|
114
|
+
*/
|
|
115
|
+
protected readonly source: string;
|
|
116
|
+
private _pendingCallCount;
|
|
117
|
+
private activeFallbackHandlers;
|
|
118
|
+
private lastCallId;
|
|
119
|
+
private readonly pendingCalls;
|
|
120
|
+
private worker;
|
|
121
|
+
private workerUrl;
|
|
122
|
+
/**
|
|
123
|
+
* Creates the component.
|
|
124
|
+
*
|
|
125
|
+
* @param params - The parameters.
|
|
126
|
+
*/
|
|
127
|
+
constructor(params: WorkerComponentConstructorParams<TApi>);
|
|
128
|
+
/**
|
|
129
|
+
* Calls a worker method.
|
|
130
|
+
*
|
|
131
|
+
* @typeParam TMethod - The method.
|
|
132
|
+
* @param method - The method name.
|
|
133
|
+
* @param callArguments - The method's arguments.
|
|
134
|
+
* @param options - The call options.
|
|
135
|
+
* @returns The method's result. Rejects with a {@link WorkerCallError} when the handler failed, with the abort reason
|
|
136
|
+
* when the call was cancelled, and with an `Error` when the worker failed or the component unloaded first.
|
|
137
|
+
*/
|
|
138
|
+
call<TMethod extends WorkerMethod<TApi>>(method: TMethod, callArguments: Parameters<TApi[TMethod]>, options?: WorkerComponentCallOptions): Promise<WorkerMethodResult<TApi, TMethod>>;
|
|
139
|
+
/**
|
|
140
|
+
* Starts the worker.
|
|
141
|
+
*/
|
|
142
|
+
onload(): void;
|
|
143
|
+
/**
|
|
144
|
+
* Terminates the worker and rejects the pending calls.
|
|
145
|
+
*/
|
|
146
|
+
onunload(): void;
|
|
147
|
+
private callWorker;
|
|
148
|
+
private readonly handleError;
|
|
149
|
+
private readonly handleMessage;
|
|
150
|
+
private readonly handleMessageError;
|
|
151
|
+
private rejectAll;
|
|
152
|
+
private revokeWorkerUrl;
|
|
153
|
+
private startWorker;
|
|
154
|
+
private stopWorker;
|
|
155
|
+
private terminateWorker;
|
|
156
|
+
}
|