@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,373 @@
|
|
|
1
|
+
import { forEachDiagnostic } from "@codemirror/lint";
|
|
2
|
+
import {} from "@codemirror/state";
|
|
3
|
+
import { EditorView, ViewPlugin } from "@codemirror/view";
|
|
4
|
+
import { getLapisLintTooltipPayload, } from "./lapis-lint-diagnostic";
|
|
5
|
+
import { showInlineProblem } from "./lapis-lint-inline-widget";
|
|
6
|
+
import { mountLintMessageDom } from "./mount-lint-tooltip";
|
|
7
|
+
const TOOLTIP_GAP_PX = 6;
|
|
8
|
+
const TOOLTIP_VIEWPORT_MARGIN_PX = 12;
|
|
9
|
+
const TOOLTIP_HIDE_DELAY_MS = 350;
|
|
10
|
+
const TOOLTIP_HANDOFF_MARGIN_PX = 10;
|
|
11
|
+
export function pointerWithinLintTooltipHandoff(point, trigger, tooltip, margin = TOOLTIP_HANDOFF_MARGIN_PX) {
|
|
12
|
+
const left = Math.min(trigger.left, tooltip.left) - margin;
|
|
13
|
+
const right = Math.max(trigger.right, tooltip.right) + margin;
|
|
14
|
+
const top = Math.min(trigger.top, tooltip.top) - margin;
|
|
15
|
+
const bottom = Math.max(trigger.bottom, tooltip.bottom) + margin;
|
|
16
|
+
return (point.x >= left && point.x <= right && point.y >= top && point.y <= bottom);
|
|
17
|
+
}
|
|
18
|
+
export function lapisLintHoverTooltip() {
|
|
19
|
+
return [lapisLintTooltipPlugin];
|
|
20
|
+
}
|
|
21
|
+
const lapisLintTooltipPlugin = ViewPlugin.fromClass(class {
|
|
22
|
+
view;
|
|
23
|
+
tooltip = null;
|
|
24
|
+
activeDiagnostic = null;
|
|
25
|
+
hideTimer = null;
|
|
26
|
+
handleMouseMove = (event) => {
|
|
27
|
+
this.withEditorLayout(() => {
|
|
28
|
+
if (eventTargetIsInsideLapisTooltip(event.target)) {
|
|
29
|
+
this.cancelScheduledHide();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const found = lintMarkerFromEvent(event) != null
|
|
33
|
+
? findDiagnosticNearPointer(this.view, event)
|
|
34
|
+
: findDiagnosticFromLintRange(this.view, event);
|
|
35
|
+
if (found && this.isActiveDiagnostic(found)) {
|
|
36
|
+
this.cancelScheduledHide();
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (this.isPointerInHandoff(event)) {
|
|
40
|
+
this.cancelScheduledHide();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!found) {
|
|
44
|
+
this.scheduleHideTooltip();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.showTooltip(found);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
handleClick = (event) => {
|
|
51
|
+
this.withEditorLayout(() => {
|
|
52
|
+
const marker = lintMarkerFromEvent(event);
|
|
53
|
+
if (!marker) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
event.stopPropagation();
|
|
58
|
+
const found = findDiagnosticNearPointer(this.view, event);
|
|
59
|
+
if (found) {
|
|
60
|
+
this.showTooltip(found);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
handleMouseLeave = (event) => {
|
|
65
|
+
this.withEditorLayout(() => {
|
|
66
|
+
if (eventTargetIsInsideLapisTooltip(event.relatedTarget)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (this.isPointerInHandoff(event)) {
|
|
70
|
+
this.cancelScheduledHide();
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.scheduleHideTooltip();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
handleDocumentMouseMove = (event) => {
|
|
78
|
+
this.withEditorLayout(() => {
|
|
79
|
+
if (eventTargetIsInsideLapisTooltip(event.target) ||
|
|
80
|
+
eventTargetIsInside(this.view.dom, event.target)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (this.isPointerInHandoff(event)) {
|
|
84
|
+
this.cancelScheduledHide();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.scheduleHideTooltip();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
handleTooltipMouseEnter = () => {
|
|
92
|
+
this.cancelScheduledHide();
|
|
93
|
+
};
|
|
94
|
+
handleTooltipMouseLeave = (event) => {
|
|
95
|
+
this.withEditorLayout(() => {
|
|
96
|
+
if (eventTargetIsInside(this.view.dom, event.relatedTarget) ||
|
|
97
|
+
this.isPointerInHandoff(event)) {
|
|
98
|
+
this.cancelScheduledHide();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
this.scheduleHideTooltip();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
get viewDocument() {
|
|
106
|
+
return this.view.dom.ownerDocument;
|
|
107
|
+
}
|
|
108
|
+
get viewWindow() {
|
|
109
|
+
return this.viewDocument.defaultView ?? window;
|
|
110
|
+
}
|
|
111
|
+
constructor(view) {
|
|
112
|
+
this.view = view;
|
|
113
|
+
view.dom.addEventListener("mousemove", this.handleMouseMove);
|
|
114
|
+
view.dom.addEventListener("mouseover", this.handleMouseMove);
|
|
115
|
+
view.dom.addEventListener("click", this.handleClick);
|
|
116
|
+
view.dom.addEventListener("mouseleave", this.handleMouseLeave);
|
|
117
|
+
this.viewDocument.addEventListener("mousemove", this.handleDocumentMouseMove);
|
|
118
|
+
}
|
|
119
|
+
update(update) {
|
|
120
|
+
if (update.transactions.some((transaction) => transaction.effects.some((effect) => effect.is(showInlineProblem)))) {
|
|
121
|
+
this.hideTooltip();
|
|
122
|
+
}
|
|
123
|
+
if (this.activeDiagnostic && update.docChanged) {
|
|
124
|
+
const from = update.changes.mapPos(this.activeDiagnostic.from, 1);
|
|
125
|
+
const to = update.changes.mapPos(this.activeDiagnostic.to, -1);
|
|
126
|
+
if (from > to || from > update.state.doc.length) {
|
|
127
|
+
this.hideTooltip();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.activeDiagnostic = { ...this.activeDiagnostic, from, to };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!this.tooltip || !this.activeDiagnostic) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (update.docChanged ||
|
|
137
|
+
update.geometryChanged ||
|
|
138
|
+
update.viewportChanged) {
|
|
139
|
+
this.schedulePositionTooltip();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
destroy() {
|
|
143
|
+
this.view.dom.removeEventListener("mousemove", this.handleMouseMove);
|
|
144
|
+
this.view.dom.removeEventListener("mouseover", this.handleMouseMove);
|
|
145
|
+
this.view.dom.removeEventListener("click", this.handleClick);
|
|
146
|
+
this.view.dom.removeEventListener("mouseleave", this.handleMouseLeave);
|
|
147
|
+
this.viewDocument.removeEventListener("mousemove", this.handleDocumentMouseMove);
|
|
148
|
+
this.hideTooltip();
|
|
149
|
+
}
|
|
150
|
+
showTooltip(found) {
|
|
151
|
+
this.cancelScheduledHide();
|
|
152
|
+
if (this.isActiveDiagnostic(found)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.hideTooltip();
|
|
156
|
+
this.activeDiagnostic = found;
|
|
157
|
+
this.tooltip = mountLintTooltipForDiagnostic(this.view, found, () => this.hideTooltip());
|
|
158
|
+
this.tooltip.addEventListener("mouseenter", this.handleTooltipMouseEnter);
|
|
159
|
+
this.tooltip.addEventListener("mouseleave", this.handleTooltipMouseLeave);
|
|
160
|
+
this.tooltip.style.position = "fixed";
|
|
161
|
+
this.tooltip.style.zIndex = "500";
|
|
162
|
+
this.tooltip.style.top = "-10000px";
|
|
163
|
+
this.tooltip.style.left = "0";
|
|
164
|
+
this.viewDocument.body?.appendChild(this.tooltip);
|
|
165
|
+
this.schedulePositionTooltip();
|
|
166
|
+
}
|
|
167
|
+
scheduleHideTooltip() {
|
|
168
|
+
if (!this.tooltip || this.hideTimer) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.hideTimer = setTimeout(() => {
|
|
172
|
+
this.hideTimer = null;
|
|
173
|
+
this.hideTooltip();
|
|
174
|
+
}, TOOLTIP_HIDE_DELAY_MS);
|
|
175
|
+
}
|
|
176
|
+
cancelScheduledHide() {
|
|
177
|
+
if (!this.hideTimer) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
clearTimeout(this.hideTimer);
|
|
181
|
+
this.hideTimer = null;
|
|
182
|
+
}
|
|
183
|
+
hideTooltip() {
|
|
184
|
+
this.cancelScheduledHide();
|
|
185
|
+
this.tooltip?.removeEventListener("mouseenter", this.handleTooltipMouseEnter);
|
|
186
|
+
this.tooltip?.removeEventListener("mouseleave", this.handleTooltipMouseLeave);
|
|
187
|
+
this.tooltip?.remove();
|
|
188
|
+
this.tooltip = null;
|
|
189
|
+
this.activeDiagnostic = null;
|
|
190
|
+
}
|
|
191
|
+
isActiveDiagnostic(found) {
|
|
192
|
+
return Boolean(this.activeDiagnostic &&
|
|
193
|
+
this.activeDiagnostic.diagnostic === found.diagnostic &&
|
|
194
|
+
this.activeDiagnostic.from === found.from &&
|
|
195
|
+
this.activeDiagnostic.to === found.to);
|
|
196
|
+
}
|
|
197
|
+
isPointerInHandoff(event) {
|
|
198
|
+
const tooltip = this.tooltip;
|
|
199
|
+
const diagnostic = this.activeDiagnostic;
|
|
200
|
+
if (!tooltip || !diagnostic) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const trigger = this.diagnosticRect(diagnostic);
|
|
204
|
+
if (!trigger) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
return pointerWithinLintTooltipHandoff({ x: event.clientX, y: event.clientY }, trigger, tooltip.getBoundingClientRect());
|
|
208
|
+
}
|
|
209
|
+
diagnosticRect(found) {
|
|
210
|
+
const start = this.view.coordsAtPos(found.from);
|
|
211
|
+
const end = this.view.coordsAtPos(Math.max(found.from, found.to));
|
|
212
|
+
if (!start || !end) {
|
|
213
|
+
return found.anchor ?? null;
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
left: Math.min(start.left, end.left, found.anchor?.left ?? Infinity),
|
|
217
|
+
right: Math.max(start.right, end.right, start.left + 1, found.anchor?.right ?? -Infinity),
|
|
218
|
+
top: Math.min(start.top, end.top, found.anchor?.top ?? Infinity),
|
|
219
|
+
bottom: Math.max(start.bottom, end.bottom, found.anchor?.bottom ?? -Infinity),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
withEditorLayout(run) {
|
|
223
|
+
try {
|
|
224
|
+
run();
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
if (!isEditorLayoutReadError(error)) {
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
schedulePositionTooltip() {
|
|
233
|
+
this.view.requestMeasure({
|
|
234
|
+
key: this,
|
|
235
|
+
read: (view) => {
|
|
236
|
+
const found = this.activeDiagnostic;
|
|
237
|
+
const tooltip = this.tooltip;
|
|
238
|
+
if (!found || !tooltip) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
coords: view.coordsAtPos(found.from) ?? found.anchor ?? null,
|
|
243
|
+
tooltipRect: tooltip.getBoundingClientRect(),
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
write: (measure) => {
|
|
247
|
+
if (!this.tooltip) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (!measure?.coords) {
|
|
251
|
+
this.hideTooltip();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this.applyTooltipPosition(measure.coords, measure.tooltipRect);
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
applyTooltipPosition(coords, tooltipRect) {
|
|
259
|
+
const tooltip = this.tooltip;
|
|
260
|
+
if (!tooltip) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const maxLeft = this.viewWindow.innerWidth -
|
|
264
|
+
tooltipRect.width -
|
|
265
|
+
TOOLTIP_VIEWPORT_MARGIN_PX;
|
|
266
|
+
const left = Math.max(TOOLTIP_VIEWPORT_MARGIN_PX, Math.min(coords.left, maxLeft));
|
|
267
|
+
const top = coords.top - tooltipRect.height - TOOLTIP_GAP_PX >
|
|
268
|
+
TOOLTIP_VIEWPORT_MARGIN_PX
|
|
269
|
+
? coords.top - tooltipRect.height - TOOLTIP_GAP_PX
|
|
270
|
+
: coords.bottom + TOOLTIP_GAP_PX;
|
|
271
|
+
tooltip.style.left = `${left}px`;
|
|
272
|
+
tooltip.style.top = `${top}px`;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
function isEditorLayoutReadError(error) {
|
|
276
|
+
return (error instanceof Error &&
|
|
277
|
+
error.message.includes("Reading the editor layout isn't allowed during an update"));
|
|
278
|
+
}
|
|
279
|
+
function findDiagnosticAt(view, pos, side) {
|
|
280
|
+
let found = null;
|
|
281
|
+
forEachDiagnostic(view.state, (diagnostic, from, to) => {
|
|
282
|
+
if (found) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const start = from - (side < 0 ? 1 : 0);
|
|
286
|
+
const end = to + (side > 0 ? 1 : 0);
|
|
287
|
+
const covers = from === to ? pos === from : pos >= start && pos <= Math.max(start, end);
|
|
288
|
+
if (!covers) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const payload = getLapisLintTooltipPayload(diagnostic);
|
|
292
|
+
if (!payload) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
found = {
|
|
296
|
+
diagnostic,
|
|
297
|
+
from,
|
|
298
|
+
to,
|
|
299
|
+
payload,
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
return found;
|
|
303
|
+
}
|
|
304
|
+
function mountLintTooltipForDiagnostic(view, found, onAction) {
|
|
305
|
+
const dom = mountLintMessageDom(found.diagnostic.message, found.payload.meta, found.payload.includeCopy, {
|
|
306
|
+
view,
|
|
307
|
+
from: found.from,
|
|
308
|
+
to: found.to,
|
|
309
|
+
actions: found.payload.actions,
|
|
310
|
+
onAction,
|
|
311
|
+
});
|
|
312
|
+
dom.classList.add("cm-lapis-tooltip");
|
|
313
|
+
return dom;
|
|
314
|
+
}
|
|
315
|
+
function lintMarkerFromEvent(event) {
|
|
316
|
+
return closestEventTarget(event.target, ".cm-lint-marker");
|
|
317
|
+
}
|
|
318
|
+
function eventTargetIsInsideLapisTooltip(target) {
|
|
319
|
+
return Boolean(closestEventTarget(target, ".cm-lapis-tooltip") ||
|
|
320
|
+
closestEventTarget(target, "[data-lint-quick-fix-menu]"));
|
|
321
|
+
}
|
|
322
|
+
function closestEventTarget(target, selector) {
|
|
323
|
+
if (!target || typeof target.closest !== "function") {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
return target.closest(selector);
|
|
327
|
+
}
|
|
328
|
+
function eventTargetIsInside(container, target) {
|
|
329
|
+
return Boolean(target &&
|
|
330
|
+
typeof target.nodeType === "number" &&
|
|
331
|
+
container.contains(target));
|
|
332
|
+
}
|
|
333
|
+
function findDiagnosticFromLintRange(view, event) {
|
|
334
|
+
const range = closestEventTarget(event.target, ".cm-lintRange");
|
|
335
|
+
if (!range) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const from = view.posAtDOM(range, 0);
|
|
340
|
+
const to = view.posAtDOM(range, range.childNodes.length);
|
|
341
|
+
const found = findDiagnosticAt(view, from, 1) ?? findDiagnosticAt(view, to, -1);
|
|
342
|
+
return found ? { ...found, anchor: range.getBoundingClientRect() } : null;
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function findDiagnosticNearPointer(view, event) {
|
|
349
|
+
const contentRect = view.contentDOM.getBoundingClientRect();
|
|
350
|
+
const pos = view.posAtCoords({
|
|
351
|
+
x: contentRect.left + 1,
|
|
352
|
+
y: event.clientY,
|
|
353
|
+
}, false);
|
|
354
|
+
const line = view.state.doc.lineAt(pos);
|
|
355
|
+
let found = null;
|
|
356
|
+
forEachDiagnostic(view.state, (diagnostic, from, to) => {
|
|
357
|
+
if (found || to < line.from || from > line.to) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const payload = getLapisLintTooltipPayload(diagnostic);
|
|
361
|
+
if (!payload) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
found = {
|
|
365
|
+
diagnostic,
|
|
366
|
+
from,
|
|
367
|
+
to,
|
|
368
|
+
payload,
|
|
369
|
+
anchor: lintMarkerFromEvent(event)?.getBoundingClientRect(),
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
return found;
|
|
373
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { StateField } from "@codemirror/state";
|
|
2
|
+
import { EditorView } from "@codemirror/view";
|
|
3
|
+
export interface InlineProblemSpec {
|
|
4
|
+
/** Start-of-line character position; the block widget renders below this line. */
|
|
5
|
+
lineStart: number;
|
|
6
|
+
/** End-of-line character position; the block widget renders below this line. */
|
|
7
|
+
lineEnd: number;
|
|
8
|
+
/** Approximate character offset of the diagnostic start within the line. */
|
|
9
|
+
column: number;
|
|
10
|
+
message: string;
|
|
11
|
+
sourceLabel?: string;
|
|
12
|
+
ruleId?: string;
|
|
13
|
+
pointerLeftPx: number;
|
|
14
|
+
maxWidthPx: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const showInlineProblem: import("@codemirror/state").StateEffectType<InlineProblemSpec | null>;
|
|
17
|
+
/**
|
|
18
|
+
* StateField that tracks the active inline problem widget.
|
|
19
|
+
*
|
|
20
|
+
* Include this in the editor's extensions (e.g. via `lapisCodeMirrorLint`) so
|
|
21
|
+
* that `toggleInlineProblem` can show or hide the widget.
|
|
22
|
+
*/
|
|
23
|
+
export declare const inlineProblemExtension: StateField<InlineProblemSpec | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Toggle the inline problem widget below the diagnostic's line.
|
|
26
|
+
*
|
|
27
|
+
* Calling with the same position and message a second time dismisses the
|
|
28
|
+
* widget. A no-op when `inlineProblemExtension` is absent from the editor state
|
|
29
|
+
* (the dispatched effect is silently ignored by CodeMirror).
|
|
30
|
+
*/
|
|
31
|
+
export declare function toggleInlineProblem(view: EditorView, from: number, spec: Omit<InlineProblemSpec, "lineStart" | "lineEnd" | "column" | "pointerLeftPx" | "maxWidthPx">): void;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { StateEffect, StateField } from "@codemirror/state";
|
|
2
|
+
import { Decoration, EditorView, WidgetType } from "@codemirror/view";
|
|
3
|
+
export const showInlineProblem = StateEffect.define();
|
|
4
|
+
class InlineProblemWidget extends WidgetType {
|
|
5
|
+
spec;
|
|
6
|
+
constructor(spec) {
|
|
7
|
+
super();
|
|
8
|
+
this.spec = spec;
|
|
9
|
+
}
|
|
10
|
+
eq(other) {
|
|
11
|
+
return (this.spec.lineEnd === other.spec.lineEnd &&
|
|
12
|
+
this.spec.lineStart === other.spec.lineStart &&
|
|
13
|
+
this.spec.column === other.spec.column &&
|
|
14
|
+
this.spec.message === other.spec.message &&
|
|
15
|
+
this.spec.ruleId === other.spec.ruleId);
|
|
16
|
+
}
|
|
17
|
+
toDOM(view) {
|
|
18
|
+
const doc = view.dom.ownerDocument;
|
|
19
|
+
const root = doc.createElement("div");
|
|
20
|
+
root.className = "lapis-inline-problem";
|
|
21
|
+
root.dataset.uiComponent = "editor";
|
|
22
|
+
root.dataset.uiPart = "inline-problem";
|
|
23
|
+
root.style.setProperty("--lapis-inline-problem-pointer-left", `${this.spec.pointerLeftPx}px`);
|
|
24
|
+
root.style.setProperty("--lapis-inline-problem-max-width", `${this.spec.maxWidthPx}px`);
|
|
25
|
+
const pointer = doc.createElement("div");
|
|
26
|
+
pointer.className = "lapis-inline-problem__pointer";
|
|
27
|
+
pointer.dataset.uiComponent = "editor";
|
|
28
|
+
pointer.dataset.uiPart = "inline-problem-pointer";
|
|
29
|
+
pointer.setAttribute("aria-hidden", "true");
|
|
30
|
+
// Header row
|
|
31
|
+
const header = doc.createElement("div");
|
|
32
|
+
header.className = "lapis-inline-problem__header";
|
|
33
|
+
header.dataset.uiComponent = "editor";
|
|
34
|
+
header.dataset.uiPart = "inline-problem-header";
|
|
35
|
+
const title = doc.createElement("span");
|
|
36
|
+
title.className = "lapis-inline-problem__title";
|
|
37
|
+
title.dataset.uiComponent = "editor";
|
|
38
|
+
title.dataset.uiPart = "inline-problem-title";
|
|
39
|
+
const icon = doc.createElement("span");
|
|
40
|
+
icon.className = "lapis-inline-problem__icon";
|
|
41
|
+
icon.dataset.uiComponent = "editor";
|
|
42
|
+
icon.dataset.uiPart = "inline-problem-icon";
|
|
43
|
+
icon.setAttribute("aria-hidden", "true");
|
|
44
|
+
icon.textContent = "⚠";
|
|
45
|
+
const labelEl = doc.createElement("span");
|
|
46
|
+
labelEl.className = "lapis-inline-problem__label";
|
|
47
|
+
labelEl.dataset.uiComponent = "editor";
|
|
48
|
+
labelEl.dataset.uiPart = "inline-problem-label";
|
|
49
|
+
labelEl.textContent = "Problem";
|
|
50
|
+
title.append(icon, labelEl);
|
|
51
|
+
const closeBtn = doc.createElement("button");
|
|
52
|
+
closeBtn.className = "lapis-inline-problem__close";
|
|
53
|
+
closeBtn.dataset.uiComponent = "editor";
|
|
54
|
+
closeBtn.dataset.uiPart = "inline-problem-close";
|
|
55
|
+
closeBtn.setAttribute("type", "button");
|
|
56
|
+
closeBtn.setAttribute("aria-label", "Close problem widget");
|
|
57
|
+
closeBtn.textContent = "×";
|
|
58
|
+
const consume = (event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
};
|
|
62
|
+
const closeInlineProblem = () => {
|
|
63
|
+
view.dispatch({ effects: showInlineProblem.of(null) });
|
|
64
|
+
};
|
|
65
|
+
const dismiss = (event) => {
|
|
66
|
+
consume(event);
|
|
67
|
+
closeInlineProblem();
|
|
68
|
+
};
|
|
69
|
+
const dismissFromMouseUp = (event) => {
|
|
70
|
+
consume(event);
|
|
71
|
+
const suppressClickThrough = (clickEvent) => {
|
|
72
|
+
clickEvent.preventDefault();
|
|
73
|
+
clickEvent.stopImmediatePropagation();
|
|
74
|
+
};
|
|
75
|
+
doc.addEventListener("click", suppressClickThrough, {
|
|
76
|
+
capture: true,
|
|
77
|
+
once: true,
|
|
78
|
+
});
|
|
79
|
+
doc.defaultView?.setTimeout(() => {
|
|
80
|
+
doc.removeEventListener("click", suppressClickThrough, true);
|
|
81
|
+
});
|
|
82
|
+
closeInlineProblem();
|
|
83
|
+
};
|
|
84
|
+
closeBtn.addEventListener("pointerdown", consume);
|
|
85
|
+
closeBtn.addEventListener("pointerup", consume);
|
|
86
|
+
closeBtn.addEventListener("mousedown", consume);
|
|
87
|
+
closeBtn.addEventListener("mouseup", dismissFromMouseUp);
|
|
88
|
+
closeBtn.addEventListener("click", dismiss);
|
|
89
|
+
closeBtn.addEventListener("keydown", (event) => {
|
|
90
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
91
|
+
dismiss(event);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
header.append(title, closeBtn);
|
|
95
|
+
// Body row
|
|
96
|
+
const body = doc.createElement("div");
|
|
97
|
+
body.className = "lapis-inline-problem__body";
|
|
98
|
+
body.dataset.uiComponent = "editor";
|
|
99
|
+
body.dataset.uiPart = "inline-problem-body";
|
|
100
|
+
const msgSpan = doc.createElement("span");
|
|
101
|
+
msgSpan.className = "lapis-inline-problem__message";
|
|
102
|
+
msgSpan.dataset.uiComponent = "editor";
|
|
103
|
+
msgSpan.dataset.uiPart = "inline-problem-message";
|
|
104
|
+
msgSpan.textContent = this.spec.message;
|
|
105
|
+
body.append(msgSpan);
|
|
106
|
+
if (this.spec.sourceLabel != null || this.spec.ruleId != null) {
|
|
107
|
+
const sourceTag = doc.createElement("span");
|
|
108
|
+
sourceTag.className = "lapis-inline-problem__source";
|
|
109
|
+
sourceTag.dataset.uiComponent = "editor";
|
|
110
|
+
sourceTag.dataset.uiPart = "inline-problem-source";
|
|
111
|
+
const src = this.spec.sourceLabel ?? "";
|
|
112
|
+
const ruleParens = this.spec.ruleId != null ? `(${this.spec.ruleId})` : "";
|
|
113
|
+
sourceTag.textContent = `${src}${ruleParens}`;
|
|
114
|
+
body.append(sourceTag);
|
|
115
|
+
}
|
|
116
|
+
root.append(pointer, header, body);
|
|
117
|
+
return root;
|
|
118
|
+
}
|
|
119
|
+
ignoreEvent() {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* StateField that tracks the active inline problem widget.
|
|
125
|
+
*
|
|
126
|
+
* Include this in the editor's extensions (e.g. via `lapisCodeMirrorLint`) so
|
|
127
|
+
* that `toggleInlineProblem` can show or hide the widget.
|
|
128
|
+
*/
|
|
129
|
+
export const inlineProblemExtension = StateField.define({
|
|
130
|
+
create: () => null,
|
|
131
|
+
update(spec, tr) {
|
|
132
|
+
// Keep the anchor position in sync with document edits.
|
|
133
|
+
if (spec != null && tr.docChanged) {
|
|
134
|
+
const mappedStart = tr.changes.mapPos(spec.lineStart, 1);
|
|
135
|
+
const mappedEnd = tr.changes.mapPos(spec.lineEnd, -1);
|
|
136
|
+
spec = { ...spec, lineStart: mappedStart, lineEnd: mappedEnd };
|
|
137
|
+
}
|
|
138
|
+
for (const effect of tr.effects) {
|
|
139
|
+
if (effect.is(showInlineProblem)) {
|
|
140
|
+
return effect.value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return spec;
|
|
144
|
+
},
|
|
145
|
+
provide: (f) => EditorView.decorations.from(f, (spec) => {
|
|
146
|
+
if (spec == null)
|
|
147
|
+
return Decoration.none;
|
|
148
|
+
return Decoration.set([
|
|
149
|
+
Decoration.widget({
|
|
150
|
+
widget: new InlineProblemWidget(spec),
|
|
151
|
+
block: true,
|
|
152
|
+
inlineOrder: true,
|
|
153
|
+
side: 1,
|
|
154
|
+
}).range(spec.lineEnd),
|
|
155
|
+
]);
|
|
156
|
+
}),
|
|
157
|
+
});
|
|
158
|
+
/**
|
|
159
|
+
* Toggle the inline problem widget below the diagnostic's line.
|
|
160
|
+
*
|
|
161
|
+
* Calling with the same position and message a second time dismisses the
|
|
162
|
+
* widget. A no-op when `inlineProblemExtension` is absent from the editor state
|
|
163
|
+
* (the dispatched effect is silently ignored by CodeMirror).
|
|
164
|
+
*/
|
|
165
|
+
export function toggleInlineProblem(view, from, spec) {
|
|
166
|
+
const line = view.state.doc.lineAt(from);
|
|
167
|
+
const current = view.state.field(inlineProblemExtension, false);
|
|
168
|
+
const lineStartCoords = view.coordsAtPos(line.from);
|
|
169
|
+
const lineEndCoords = view.coordsAtPos(line.to);
|
|
170
|
+
const diagnosticCoords = view.coordsAtPos(from);
|
|
171
|
+
const contentRect = view.contentDOM.getBoundingClientRect();
|
|
172
|
+
const lineLeft = lineStartCoords?.left ?? contentRect.left;
|
|
173
|
+
const lineEndLeft = lineEndCoords?.left ?? lineLeft;
|
|
174
|
+
const diagnosticLeft = diagnosticCoords?.left ?? lineLeft;
|
|
175
|
+
const isSameWidget = current != null &&
|
|
176
|
+
current.lineStart === line.from &&
|
|
177
|
+
current.lineEnd === line.to &&
|
|
178
|
+
current.message === spec.message;
|
|
179
|
+
view.dispatch({
|
|
180
|
+
effects: showInlineProblem.of(isSameWidget
|
|
181
|
+
? null
|
|
182
|
+
: {
|
|
183
|
+
...spec,
|
|
184
|
+
lineStart: line.from,
|
|
185
|
+
lineEnd: line.to,
|
|
186
|
+
column: from - line.from,
|
|
187
|
+
pointerLeftPx: Math.max(0, diagnosticLeft - lineEndLeft),
|
|
188
|
+
maxWidthPx: Math.max(240, contentRect.right - lineEndLeft),
|
|
189
|
+
}),
|
|
190
|
+
});
|
|
191
|
+
}
|