@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,126 @@
|
|
|
1
|
+
import { EditorState, type Text, type Extension, StateField, EditorSelection as CodeMirrorSelection } from "@codemirror/state";
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
import type { TFile } from "./storage/fs";
|
|
4
|
+
import { EventDispatcher } from "./events";
|
|
5
|
+
import type { App } from "./context.svelte";
|
|
6
|
+
export type EditorPosition = {
|
|
7
|
+
line: number;
|
|
8
|
+
ch: number;
|
|
9
|
+
};
|
|
10
|
+
export interface EditorRange {
|
|
11
|
+
from: EditorPosition;
|
|
12
|
+
to: EditorPosition;
|
|
13
|
+
}
|
|
14
|
+
export interface EditorRangeOrCaret {
|
|
15
|
+
from: EditorPosition;
|
|
16
|
+
to?: EditorPosition;
|
|
17
|
+
}
|
|
18
|
+
export interface EditorChange extends EditorRangeOrCaret {
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
export type EditorCommandName = "goUp" | "goDown" | "goLeft" | "goRight" | "goStart" | "goEnd" | "goWordLeft" | "goWordRight" | "indentMore" | "indentLess" | "newlineAndIndent" | "swapLineUp" | "swapLineDown" | "deleteLine" | "toggleFold" | "foldAll" | "unfoldAll";
|
|
22
|
+
export interface EditorScrollInfo {
|
|
23
|
+
left: number;
|
|
24
|
+
top: number;
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
clientWidth: number;
|
|
28
|
+
clientHeight: number;
|
|
29
|
+
}
|
|
30
|
+
export interface EditorSelection {
|
|
31
|
+
anchor: EditorPosition;
|
|
32
|
+
head: EditorPosition;
|
|
33
|
+
}
|
|
34
|
+
export interface EditorSelectionOrCaret {
|
|
35
|
+
anchor: EditorPosition;
|
|
36
|
+
head?: EditorPosition;
|
|
37
|
+
}
|
|
38
|
+
export interface EditorTransaction {
|
|
39
|
+
replaceSelection?: string;
|
|
40
|
+
changes?: EditorChange[];
|
|
41
|
+
selections?: EditorRangeOrCaret[];
|
|
42
|
+
selection?: EditorRangeOrCaret;
|
|
43
|
+
}
|
|
44
|
+
/** Controls whether an editor persists its own debounced document changes. */
|
|
45
|
+
export type EditorPersistence = "vault" | "external";
|
|
46
|
+
export interface MarkdownFileInfo {
|
|
47
|
+
/** @public */
|
|
48
|
+
app: App;
|
|
49
|
+
/** @public */
|
|
50
|
+
get file(): TFile | null;
|
|
51
|
+
/** @public */
|
|
52
|
+
editor?: Editor;
|
|
53
|
+
}
|
|
54
|
+
export declare const editorViewField: StateField<MarkdownFileInfo>;
|
|
55
|
+
export declare const editorInfoField: StateField<MarkdownFileInfo>;
|
|
56
|
+
export declare const editorEditorField: StateField<EditorView | null>;
|
|
57
|
+
export declare const editorLivePreviewField: StateField<boolean>;
|
|
58
|
+
export declare function fromPosition(doc: Text, pos: EditorPosition): number;
|
|
59
|
+
export declare function toPosition(doc: Text, pos: number): EditorPosition;
|
|
60
|
+
export declare function createEditorState(editor: Editor, doc: string, extensions?: Extension[], selection?: CodeMirrorSelection): EditorState;
|
|
61
|
+
export declare function createEditor(editor: Editor, doc: string, ...extensions: Extension[]): EditorView;
|
|
62
|
+
export declare class Editor extends EventDispatcher<{
|
|
63
|
+
change: [data: string];
|
|
64
|
+
}> {
|
|
65
|
+
data: string;
|
|
66
|
+
extensions: Extension[];
|
|
67
|
+
view: EditorView;
|
|
68
|
+
file: TFile | null;
|
|
69
|
+
persistence: EditorPersistence;
|
|
70
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
71
|
+
private destroyed;
|
|
72
|
+
private application;
|
|
73
|
+
private readonly pendingChange;
|
|
74
|
+
constructor(data?: string, extensions?: Extension[], application?: App);
|
|
75
|
+
/** Bind this editor to the application that owns its view. */
|
|
76
|
+
bindApplication(application: App): this;
|
|
77
|
+
/** The owning application, with the global alias retained as fallback. */
|
|
78
|
+
get app(): App;
|
|
79
|
+
readonly save: import("lodash-es").DebouncedFunc<() => Promise<void>>;
|
|
80
|
+
get cm(): EditorView;
|
|
81
|
+
onChange(data: string): void;
|
|
82
|
+
/** Queue the latest editor contents for persistence/change notification. */
|
|
83
|
+
queueChange(data: string): void;
|
|
84
|
+
/** Flush the latest queued change before a view or embedded surface closes. */
|
|
85
|
+
flushChanges(): Promise<void>;
|
|
86
|
+
/** Cancel a queued change when the owning document is intentionally reset. */
|
|
87
|
+
cancelPendingChanges(): void;
|
|
88
|
+
getValue(): string;
|
|
89
|
+
refresh(): void;
|
|
90
|
+
destroy(): void;
|
|
91
|
+
trackChanges(callback?: (data: string, editor: Editor) => void): () => void;
|
|
92
|
+
updateExtensions(extensions: Extension[], context?: Record<string, any>): this;
|
|
93
|
+
setValue(content: string): void;
|
|
94
|
+
replaceContent(content: string, options?: {
|
|
95
|
+
userEvent?: string;
|
|
96
|
+
}): void;
|
|
97
|
+
getLine(line: number): string;
|
|
98
|
+
somethingSelected(): boolean;
|
|
99
|
+
getRange(from: EditorPosition, to: EditorPosition): string;
|
|
100
|
+
replaceSelection(replacement: string, origin?: string): void;
|
|
101
|
+
getCursor(side?: "from" | "to" | "head" | "anchor"): EditorPosition;
|
|
102
|
+
listSelections(): EditorSelection[];
|
|
103
|
+
setCursor(pos: EditorPosition | number, ch?: number): void;
|
|
104
|
+
setSelection(anchor: EditorPosition, head?: EditorPosition): void;
|
|
105
|
+
setSelections(ranges: EditorSelectionOrCaret[], main?: number): void;
|
|
106
|
+
replaceRange(replacement: string, from: EditorPosition, to?: EditorPosition, origin?: string): void;
|
|
107
|
+
focus(): void;
|
|
108
|
+
blur(): void;
|
|
109
|
+
hasFocus(): boolean;
|
|
110
|
+
getScrollInfo(): EditorScrollInfo;
|
|
111
|
+
scrollTo(x?: number | null, y?: number | null): void;
|
|
112
|
+
scrollIntoView(range: EditorRange, center?: boolean): void;
|
|
113
|
+
undo(): void;
|
|
114
|
+
redo(): void;
|
|
115
|
+
exec(command: EditorCommandName): void;
|
|
116
|
+
transaction(tx: EditorTransaction, origin?: string): void;
|
|
117
|
+
wordAt(pos: EditorPosition): EditorRange | null;
|
|
118
|
+
posToOffset(pos: EditorPosition): number;
|
|
119
|
+
offsetToPos(offset: number): EditorPosition;
|
|
120
|
+
processLines<T>(read: (line: number, lineText: string) => T | null, write: (line: number, lineText: string, value: T | null) => EditorChange | void, ignoreEmpty?: boolean): void;
|
|
121
|
+
lastLine(): number;
|
|
122
|
+
setLine(n: number, text: string): void;
|
|
123
|
+
lineCount(): number;
|
|
124
|
+
getSelection(): string;
|
|
125
|
+
getDoc(): this;
|
|
126
|
+
}
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { Annotation, EditorState, Transaction, StateField, EditorSelection as CodeMirrorSelection, } from "@codemirror/state";
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
import { redo as redoCommand, undo as undoCommand } from "@codemirror/commands";
|
|
4
|
+
import { EventDispatcher } from "./events";
|
|
5
|
+
import debounce from "lodash-es/debounce";
|
|
6
|
+
import { resolveApplication } from "./application-compatibility";
|
|
7
|
+
export const editorViewField = StateField.define({
|
|
8
|
+
create() {
|
|
9
|
+
return {
|
|
10
|
+
get app() {
|
|
11
|
+
return resolveApplication();
|
|
12
|
+
},
|
|
13
|
+
file: null,
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
update(state) {
|
|
17
|
+
return state;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
export const editorInfoField = editorViewField;
|
|
21
|
+
export const editorEditorField = StateField.define({
|
|
22
|
+
create() {
|
|
23
|
+
return null;
|
|
24
|
+
},
|
|
25
|
+
update(value) {
|
|
26
|
+
return value;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
export const editorLivePreviewField = StateField.define({
|
|
30
|
+
create() {
|
|
31
|
+
return false;
|
|
32
|
+
},
|
|
33
|
+
update(value) {
|
|
34
|
+
return value;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
export function fromPosition(doc, pos) {
|
|
38
|
+
return doc.line(pos.line + 1).from + pos.ch;
|
|
39
|
+
}
|
|
40
|
+
export function toPosition(doc, pos) {
|
|
41
|
+
const line = doc.lineAt(pos);
|
|
42
|
+
return {
|
|
43
|
+
line: line.number - 1,
|
|
44
|
+
ch: pos - line.from,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const syncAnnotation = Annotation.define();
|
|
48
|
+
export function createEditorState(editor, doc, extensions = [], selection) {
|
|
49
|
+
return EditorState.create({
|
|
50
|
+
doc,
|
|
51
|
+
selection,
|
|
52
|
+
extensions: [
|
|
53
|
+
editorViewField.init(() => ({
|
|
54
|
+
get app() {
|
|
55
|
+
return editor.app;
|
|
56
|
+
},
|
|
57
|
+
editor,
|
|
58
|
+
get file() {
|
|
59
|
+
return editor.file;
|
|
60
|
+
},
|
|
61
|
+
})),
|
|
62
|
+
EditorView.updateListener.of((v) => {
|
|
63
|
+
if (v.docChanged &&
|
|
64
|
+
!v.transactions.some((it) => it.annotation(syncAnnotation))) {
|
|
65
|
+
editor.queueChange(v.state.doc.toString());
|
|
66
|
+
}
|
|
67
|
+
}),
|
|
68
|
+
...extensions,
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function createEditor(editor, doc, ...extensions) {
|
|
73
|
+
return new EditorView({
|
|
74
|
+
doc,
|
|
75
|
+
dispatchTransactions: (trs, view) => {
|
|
76
|
+
view.update(trs);
|
|
77
|
+
const specs = [];
|
|
78
|
+
let selectionChanged = false;
|
|
79
|
+
for (let tr of trs) {
|
|
80
|
+
selectionChanged ||= tr.selection !== undefined;
|
|
81
|
+
if (!tr.changes.empty && !tr.annotation(syncAnnotation)) {
|
|
82
|
+
let annotations = [syncAnnotation.of(true)];
|
|
83
|
+
let userEvent = tr.annotation(Transaction.userEvent);
|
|
84
|
+
if (userEvent)
|
|
85
|
+
annotations.push(Transaction.userEvent.of(userEvent));
|
|
86
|
+
specs.push({ changes: tr.changes, annotations });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (specs.length || selectionChanged) {
|
|
90
|
+
editor.app.workspace.dispatch("editor-updated", editor, specs);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
state: createEditorState(editor, doc, extensions),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export class Editor extends EventDispatcher {
|
|
97
|
+
data;
|
|
98
|
+
extensions;
|
|
99
|
+
view;
|
|
100
|
+
file = $state(null);
|
|
101
|
+
persistence = "vault";
|
|
102
|
+
id = crypto.randomUUID();
|
|
103
|
+
destroyed = false;
|
|
104
|
+
application;
|
|
105
|
+
pendingChange = debounce(async (content) => {
|
|
106
|
+
if (this.data === content) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (this.file && this.persistence === "vault") {
|
|
110
|
+
await this.app.vault.modify(this.file, content);
|
|
111
|
+
}
|
|
112
|
+
this.data = content;
|
|
113
|
+
this.onChange(content);
|
|
114
|
+
}, 500);
|
|
115
|
+
constructor(data = "", extensions = [], application) {
|
|
116
|
+
super();
|
|
117
|
+
this.data = data;
|
|
118
|
+
this.extensions = extensions;
|
|
119
|
+
this.application = application;
|
|
120
|
+
this.view = createEditor(this, data, extensions);
|
|
121
|
+
}
|
|
122
|
+
/** Bind this editor to the application that owns its view. */
|
|
123
|
+
bindApplication(application) {
|
|
124
|
+
this.application = application;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
/** The owning application, with the global alias retained as fallback. */
|
|
128
|
+
get app() {
|
|
129
|
+
return resolveApplication(this.application);
|
|
130
|
+
}
|
|
131
|
+
save = debounce(() => {
|
|
132
|
+
if (this.file) {
|
|
133
|
+
return this.app.vault.modify(this.file, this.getValue());
|
|
134
|
+
}
|
|
135
|
+
return Promise.resolve();
|
|
136
|
+
}, 500);
|
|
137
|
+
get cm() {
|
|
138
|
+
return this.view;
|
|
139
|
+
}
|
|
140
|
+
onChange(data) {
|
|
141
|
+
this.trigger("change", data);
|
|
142
|
+
}
|
|
143
|
+
/** Queue the latest editor contents for persistence/change notification. */
|
|
144
|
+
queueChange(data) {
|
|
145
|
+
this.pendingChange(data);
|
|
146
|
+
}
|
|
147
|
+
/** Flush the latest queued change before a view or embedded surface closes. */
|
|
148
|
+
flushChanges() {
|
|
149
|
+
return Promise.resolve(this.pendingChange.flush()).then(() => undefined);
|
|
150
|
+
}
|
|
151
|
+
/** Cancel a queued change when the owning document is intentionally reset. */
|
|
152
|
+
cancelPendingChanges() {
|
|
153
|
+
this.pendingChange.cancel();
|
|
154
|
+
}
|
|
155
|
+
getValue() {
|
|
156
|
+
return this.view.state.doc.toString();
|
|
157
|
+
}
|
|
158
|
+
refresh() {
|
|
159
|
+
this.view.requestMeasure();
|
|
160
|
+
}
|
|
161
|
+
destroy() {
|
|
162
|
+
if (this.destroyed) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this.destroyed = true;
|
|
166
|
+
this.pendingChange.cancel();
|
|
167
|
+
this.save.cancel();
|
|
168
|
+
this.view.destroy();
|
|
169
|
+
}
|
|
170
|
+
trackChanges(callback) {
|
|
171
|
+
const editorUpdated = this.app.workspace.on("editor-updated", (editor, transactions) => {
|
|
172
|
+
if (editor.id !== this.id && editor.file?.path === this.file?.path) {
|
|
173
|
+
if (this.getValue() !== editor.getValue()) {
|
|
174
|
+
this.view.dispatch(...transactions);
|
|
175
|
+
this.onChange(this.getValue());
|
|
176
|
+
callback?.(this.getValue(), this);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
const fileChanged = this.app.workspace.on("file-change", (file, event) => {
|
|
181
|
+
if (file.path === this.file?.path) {
|
|
182
|
+
if (event !== "delete" && file) {
|
|
183
|
+
this.app.vault.read(file).then((contents) => {
|
|
184
|
+
if (this.getValue() !== contents) {
|
|
185
|
+
this.replaceContent(contents);
|
|
186
|
+
this.onChange(this.getValue());
|
|
187
|
+
callback?.(this.getValue(), this);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return () => {
|
|
194
|
+
this.app.workspace.offref(editorUpdated);
|
|
195
|
+
this.app.workspace.offref(fileChanged);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
updateExtensions(extensions, context) {
|
|
199
|
+
return this.app.telemetry.measure("editor.update_extensions", (span) => {
|
|
200
|
+
const ext = this.file?.extension;
|
|
201
|
+
let editorExtensions = extensions.flat();
|
|
202
|
+
if (!extensions.length && ext) {
|
|
203
|
+
editorExtensions = this.app.editorExtensions(ext, context);
|
|
204
|
+
}
|
|
205
|
+
span.setAttribute("editor.extension_count", editorExtensions.length);
|
|
206
|
+
span.setAttribute("file.extension", ext ?? "");
|
|
207
|
+
const content = this.getValue();
|
|
208
|
+
const selection = this.view.state.selection;
|
|
209
|
+
this.extensions = editorExtensions;
|
|
210
|
+
this.data = content;
|
|
211
|
+
this.view.setState(createEditorState(this, content, this.extensions, selection));
|
|
212
|
+
return this;
|
|
213
|
+
}, {
|
|
214
|
+
attributes: { "file.extension": this.file?.extension ?? "" },
|
|
215
|
+
slowThresholdMs: 50,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
setValue(content) {
|
|
219
|
+
this.app.telemetry.measure("editor.set_value", (span) => {
|
|
220
|
+
span.setAttribute("editor.content_length", content.length);
|
|
221
|
+
span.setAttribute("file.extension", this.file?.extension ?? "");
|
|
222
|
+
this.data = content;
|
|
223
|
+
this.view.setState(createEditorState(this, content, this.extensions));
|
|
224
|
+
}, {
|
|
225
|
+
attributes: { "file.extension": this.file?.extension ?? "" },
|
|
226
|
+
slowThresholdMs: 50,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
replaceContent(content, options = {}) {
|
|
230
|
+
this.data = content;
|
|
231
|
+
const annotations = [syncAnnotation.of(true)];
|
|
232
|
+
this.view.dispatch({
|
|
233
|
+
changes: {
|
|
234
|
+
from: 0,
|
|
235
|
+
to: this.view.state.doc.length,
|
|
236
|
+
insert: content,
|
|
237
|
+
},
|
|
238
|
+
annotations,
|
|
239
|
+
...(options.userEvent ? { userEvent: options.userEvent } : {}),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
getLine(line) {
|
|
243
|
+
return this.view.state.doc.line(line + 1)?.text ?? "";
|
|
244
|
+
}
|
|
245
|
+
somethingSelected() {
|
|
246
|
+
return !this.view.state.selection.main.empty;
|
|
247
|
+
}
|
|
248
|
+
getRange(from, to) {
|
|
249
|
+
return this.view.state.sliceDoc(this.posToOffset(from), this.posToOffset(to));
|
|
250
|
+
}
|
|
251
|
+
replaceSelection(replacement, origin) {
|
|
252
|
+
this.view.dispatch(this.view.state.replaceSelection(replacement), origin ? { userEvent: origin } : {});
|
|
253
|
+
}
|
|
254
|
+
getCursor(side = "head") {
|
|
255
|
+
const selection = this.view.state.selection.main;
|
|
256
|
+
const pos = side === "from"
|
|
257
|
+
? selection.from
|
|
258
|
+
: side === "to"
|
|
259
|
+
? selection.to
|
|
260
|
+
: side === "anchor"
|
|
261
|
+
? selection.anchor
|
|
262
|
+
: selection.head;
|
|
263
|
+
return toPosition(this.view.state.doc, pos);
|
|
264
|
+
}
|
|
265
|
+
listSelections() {
|
|
266
|
+
return this.view.state.selection.ranges.map((range) => ({
|
|
267
|
+
anchor: toPosition(this.view.state.doc, range.anchor),
|
|
268
|
+
head: toPosition(this.view.state.doc, range.head),
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
setCursor(pos, ch) {
|
|
272
|
+
const cursor = typeof pos === "number" ? { line: pos, ch: ch ?? 0 } : pos;
|
|
273
|
+
this.setSelection(cursor, cursor);
|
|
274
|
+
}
|
|
275
|
+
setSelection(anchor, head) {
|
|
276
|
+
this.view.dispatch({
|
|
277
|
+
selection: {
|
|
278
|
+
anchor: fromPosition(this.view.state.doc, anchor),
|
|
279
|
+
head: head ? fromPosition(this.view.state.doc, head) : undefined,
|
|
280
|
+
},
|
|
281
|
+
scrollIntoView: true,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
setSelections(ranges, main = 0) {
|
|
285
|
+
const cmRanges = ranges.map((range) => CodeMirrorSelection.range(this.posToOffset(range.anchor), this.posToOffset(range.head ?? range.anchor)));
|
|
286
|
+
this.view.dispatch({
|
|
287
|
+
selection: CodeMirrorSelection.create(cmRanges, main),
|
|
288
|
+
scrollIntoView: true,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
replaceRange(replacement, from, to, origin) {
|
|
292
|
+
this.view.dispatch({
|
|
293
|
+
userEvent: origin,
|
|
294
|
+
changes: {
|
|
295
|
+
from: fromPosition(this.view.state.doc, from),
|
|
296
|
+
to: to ? fromPosition(this.view.state.doc, to) : undefined,
|
|
297
|
+
insert: replacement,
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
focus() {
|
|
302
|
+
this.view.focus();
|
|
303
|
+
}
|
|
304
|
+
blur() {
|
|
305
|
+
this.view.contentDOM.blur();
|
|
306
|
+
}
|
|
307
|
+
hasFocus() {
|
|
308
|
+
return this.view.hasFocus;
|
|
309
|
+
}
|
|
310
|
+
getScrollInfo() {
|
|
311
|
+
const el = this.view.scrollDOM;
|
|
312
|
+
return {
|
|
313
|
+
left: el.scrollLeft,
|
|
314
|
+
top: el.scrollTop,
|
|
315
|
+
width: el.scrollWidth,
|
|
316
|
+
height: el.scrollHeight,
|
|
317
|
+
clientWidth: el.clientWidth,
|
|
318
|
+
clientHeight: el.clientHeight,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
scrollTo(x, y) {
|
|
322
|
+
this.view.scrollDOM.scrollTo({
|
|
323
|
+
left: x ?? this.view.scrollDOM.scrollLeft,
|
|
324
|
+
top: y ?? this.view.scrollDOM.scrollTop,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
scrollIntoView(range, center) {
|
|
328
|
+
this.view.dispatch({
|
|
329
|
+
effects: EditorView.scrollIntoView(this.posToOffset(range.from), {
|
|
330
|
+
y: center ? "center" : "nearest",
|
|
331
|
+
}),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
undo() {
|
|
335
|
+
undoCommand(this.view);
|
|
336
|
+
}
|
|
337
|
+
redo() {
|
|
338
|
+
redoCommand(this.view);
|
|
339
|
+
}
|
|
340
|
+
exec(command) {
|
|
341
|
+
const commands = {
|
|
342
|
+
goUp: () => this.view.dispatch({ selection: { anchor: 0 } }),
|
|
343
|
+
goStart: () => this.view.dispatch({ selection: { anchor: 0 } }),
|
|
344
|
+
goEnd: () => this.view.dispatch({
|
|
345
|
+
selection: { anchor: this.view.state.doc.length },
|
|
346
|
+
}),
|
|
347
|
+
deleteLine: () => {
|
|
348
|
+
const line = this.view.state.doc.lineAt(this.view.state.selection.main.head);
|
|
349
|
+
this.view.dispatch({
|
|
350
|
+
changes: {
|
|
351
|
+
from: line.from,
|
|
352
|
+
to: Math.min(line.to + 1, this.view.state.doc.length),
|
|
353
|
+
insert: "",
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
commands[command]?.();
|
|
359
|
+
}
|
|
360
|
+
transaction(tx, origin) {
|
|
361
|
+
const specs = [];
|
|
362
|
+
if (tx.replaceSelection !== undefined) {
|
|
363
|
+
specs.push(this.view.state.replaceSelection(tx.replaceSelection));
|
|
364
|
+
}
|
|
365
|
+
if (tx.changes) {
|
|
366
|
+
specs.push(...tx.changes.map((change) => ({
|
|
367
|
+
changes: {
|
|
368
|
+
from: this.posToOffset(change.from),
|
|
369
|
+
to: this.posToOffset(change.to ?? change.from),
|
|
370
|
+
insert: change.text,
|
|
371
|
+
},
|
|
372
|
+
})));
|
|
373
|
+
}
|
|
374
|
+
if (tx.selection) {
|
|
375
|
+
specs.push({
|
|
376
|
+
selection: {
|
|
377
|
+
anchor: this.posToOffset(tx.selection.from),
|
|
378
|
+
head: this.posToOffset(tx.selection.to ?? tx.selection.from),
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
if (tx.selections) {
|
|
383
|
+
specs.push({
|
|
384
|
+
selection: CodeMirrorSelection.create(tx.selections.map((selection) => CodeMirrorSelection.range(this.posToOffset(selection.from), this.posToOffset(selection.to ?? selection.from)))),
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
if (origin) {
|
|
388
|
+
specs.push({ userEvent: origin });
|
|
389
|
+
}
|
|
390
|
+
if (specs.length) {
|
|
391
|
+
this.view.dispatch(...specs);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
wordAt(pos) {
|
|
395
|
+
const lineText = this.getLine(pos.line);
|
|
396
|
+
const wordPattern = /[\p{L}\p{N}_-]+/gu;
|
|
397
|
+
for (const match of lineText.matchAll(wordPattern)) {
|
|
398
|
+
const start = match.index ?? 0;
|
|
399
|
+
const end = start + match[0].length;
|
|
400
|
+
if (pos.ch >= start && pos.ch <= end) {
|
|
401
|
+
return {
|
|
402
|
+
from: { line: pos.line, ch: start },
|
|
403
|
+
to: { line: pos.line, ch: end },
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
posToOffset(pos) {
|
|
410
|
+
return fromPosition(this.view.state.doc, pos);
|
|
411
|
+
}
|
|
412
|
+
offsetToPos(offset) {
|
|
413
|
+
return toPosition(this.view.state.doc, offset);
|
|
414
|
+
}
|
|
415
|
+
processLines(read, write, ignoreEmpty) {
|
|
416
|
+
const changes = [];
|
|
417
|
+
for (let line = 0; line < this.lineCount(); line++) {
|
|
418
|
+
const lineText = this.getLine(line);
|
|
419
|
+
if (ignoreEmpty && !lineText.trim()) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const value = read(line, lineText);
|
|
423
|
+
const change = write(line, lineText, value);
|
|
424
|
+
if (change) {
|
|
425
|
+
changes.push(change);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
this.transaction({ changes });
|
|
429
|
+
}
|
|
430
|
+
lastLine() {
|
|
431
|
+
return this.view.state.doc.lines - 1;
|
|
432
|
+
}
|
|
433
|
+
setLine(n, text) {
|
|
434
|
+
const line = this.view.state.doc.line(n + 1);
|
|
435
|
+
if (line) {
|
|
436
|
+
this.view.dispatch({
|
|
437
|
+
changes: { from: line.from, to: line.to, insert: text },
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
lineCount() {
|
|
442
|
+
return this.view.state.doc.lines;
|
|
443
|
+
}
|
|
444
|
+
getSelection() {
|
|
445
|
+
const selection = this.view.state.selection.main;
|
|
446
|
+
if (selection) {
|
|
447
|
+
return this.view.state.sliceDoc(selection.from, selection.to);
|
|
448
|
+
}
|
|
449
|
+
return "";
|
|
450
|
+
}
|
|
451
|
+
getDoc() {
|
|
452
|
+
return this;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { App } from "./context.svelte";
|
|
2
|
+
export type EmbedViewHandle = {
|
|
3
|
+
destroy?: () => void | Promise<void>;
|
|
4
|
+
};
|
|
5
|
+
export type EmbedView = (props: {
|
|
6
|
+
app: App;
|
|
7
|
+
containerEl: HTMLElement;
|
|
8
|
+
state: Record<string, any>;
|
|
9
|
+
}) => void | EmbedViewHandle;
|
|
10
|
+
export declare class EmbedRegistry {
|
|
11
|
+
readonly embedByExtension: Record<string, EmbedView>;
|
|
12
|
+
constructor();
|
|
13
|
+
register(extension: string, view: EmbedView): () => void;
|
|
14
|
+
get(extension: string): EmbedView | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class EmbedRegistry {
|
|
2
|
+
embedByExtension = {};
|
|
3
|
+
constructor() { }
|
|
4
|
+
register(extension, view) {
|
|
5
|
+
const normalizedExtension = extension.toLowerCase();
|
|
6
|
+
this.embedByExtension[normalizedExtension] = view;
|
|
7
|
+
return () => {
|
|
8
|
+
if (this.embedByExtension[normalizedExtension] === view) {
|
|
9
|
+
delete this.embedByExtension[normalizedExtension];
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
get(extension) {
|
|
14
|
+
return this.embedByExtension[extension.toLowerCase()] ?? null;
|
|
15
|
+
}
|
|
16
|
+
}
|