@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
package/dist/links.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { basename, dirname } from "./storage/path";
|
|
2
|
+
import { stripHeadingForLink } from "./utils";
|
|
3
|
+
export const defaultLinkSettings = {
|
|
4
|
+
newLinkFormat: "shortest",
|
|
5
|
+
useWikilinks: true,
|
|
6
|
+
omitMarkdownExtension: true,
|
|
7
|
+
useShortestUniqueSuffix: false,
|
|
8
|
+
};
|
|
9
|
+
function splitVaultPath(path) {
|
|
10
|
+
return normalizeVaultPath(path).split("/").filter(Boolean);
|
|
11
|
+
}
|
|
12
|
+
function isMarkdownExtension(extension) {
|
|
13
|
+
return /^(md|markdown)$/i.test(extension);
|
|
14
|
+
}
|
|
15
|
+
function getFileExtension(path) {
|
|
16
|
+
const name = basename(normalizeVaultPath(path));
|
|
17
|
+
const lastDot = name.lastIndexOf(".");
|
|
18
|
+
if (lastDot <= 0) {
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
return name.slice(lastDot + 1);
|
|
22
|
+
}
|
|
23
|
+
function getFileBasename(path) {
|
|
24
|
+
const name = basename(normalizeVaultPath(path));
|
|
25
|
+
const lastDot = name.lastIndexOf(".");
|
|
26
|
+
if (lastDot <= 0) {
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
return name.slice(0, lastDot);
|
|
30
|
+
}
|
|
31
|
+
function getMarkdownBasename(path) {
|
|
32
|
+
return basename(normalizeVaultPath(path)).replace(/\.(md|markdown)$/i, "");
|
|
33
|
+
}
|
|
34
|
+
function getPathSuffix(path, segmentCount) {
|
|
35
|
+
const parts = splitVaultPath(path);
|
|
36
|
+
return parts.slice(-segmentCount).join("/");
|
|
37
|
+
}
|
|
38
|
+
function getSourceDirectory(sourcePath) {
|
|
39
|
+
const normalized = normalizeVaultPath(sourcePath);
|
|
40
|
+
if (!normalized.length) {
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
const directory = dirname(normalized);
|
|
44
|
+
return directory === "/" ? "" : normalizeVaultPath(directory);
|
|
45
|
+
}
|
|
46
|
+
function applyMarkdownExtensionPreference(path, settings) {
|
|
47
|
+
if (!settings.omitMarkdownExtension) {
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
return normalizeVaultPath(path).replace(/\.(md|markdown)$/i, "");
|
|
51
|
+
}
|
|
52
|
+
function getAbsoluteLinkPath(targetPath, settings) {
|
|
53
|
+
return applyMarkdownExtensionPreference(targetPath, settings);
|
|
54
|
+
}
|
|
55
|
+
function getRelativeLinkPath(targetPath, sourcePath, settings) {
|
|
56
|
+
const targetParts = splitVaultPath(targetPath);
|
|
57
|
+
const sourceParts = splitVaultPath(getSourceDirectory(sourcePath));
|
|
58
|
+
let sharedLength = 0;
|
|
59
|
+
while (sharedLength < sourceParts.length &&
|
|
60
|
+
sharedLength < targetParts.length &&
|
|
61
|
+
sourceParts[sharedLength] === targetParts[sharedLength]) {
|
|
62
|
+
sharedLength += 1;
|
|
63
|
+
}
|
|
64
|
+
const relativeParts = [
|
|
65
|
+
...sourceParts.slice(sharedLength).map(() => ".."),
|
|
66
|
+
...targetParts.slice(sharedLength),
|
|
67
|
+
];
|
|
68
|
+
const relativePath = relativeParts.join("/");
|
|
69
|
+
return applyMarkdownExtensionPreference(relativePath, settings);
|
|
70
|
+
}
|
|
71
|
+
function getObsidianCompatibleShortestPath(targetPath, settings, vaultIndex) {
|
|
72
|
+
const normalizedTarget = normalizeVaultPath(targetPath);
|
|
73
|
+
const targetExtension = getFileExtension(normalizedTarget);
|
|
74
|
+
const targetBase = isMarkdownExtension(targetExtension)
|
|
75
|
+
? getMarkdownBasename(normalizedTarget)
|
|
76
|
+
: getFileBasename(normalizedTarget);
|
|
77
|
+
const matches = vaultIndex
|
|
78
|
+
.getFiles()
|
|
79
|
+
.filter((file) => file.basename === targetBase &&
|
|
80
|
+
file.extension.toLowerCase() === targetExtension.toLowerCase());
|
|
81
|
+
if (matches.length === 1) {
|
|
82
|
+
if (!targetExtension) {
|
|
83
|
+
return targetBase;
|
|
84
|
+
}
|
|
85
|
+
return applyMarkdownExtensionPreference(`${targetBase}.${targetExtension}`, settings);
|
|
86
|
+
}
|
|
87
|
+
return getAbsoluteLinkPath(normalizedTarget, settings);
|
|
88
|
+
}
|
|
89
|
+
function getShortestUniqueSuffixPath(targetPath, settings, vaultIndex) {
|
|
90
|
+
const normalizedTarget = normalizeVaultPath(targetPath);
|
|
91
|
+
const targetExtension = getFileExtension(normalizedTarget);
|
|
92
|
+
const targetBase = isMarkdownExtension(targetExtension)
|
|
93
|
+
? getMarkdownBasename(normalizedTarget)
|
|
94
|
+
: getFileBasename(normalizedTarget);
|
|
95
|
+
const matches = vaultIndex
|
|
96
|
+
.getFiles()
|
|
97
|
+
.filter((file) => file.basename === targetBase &&
|
|
98
|
+
file.extension.toLowerCase() === targetExtension.toLowerCase());
|
|
99
|
+
if (matches.length <= 1) {
|
|
100
|
+
return getObsidianCompatibleShortestPath(normalizedTarget, settings, vaultIndex);
|
|
101
|
+
}
|
|
102
|
+
const targetParts = splitVaultPath(normalizedTarget);
|
|
103
|
+
for (let segmentCount = 1; segmentCount <= targetParts.length; segmentCount += 1) {
|
|
104
|
+
const suffix = getPathSuffix(normalizedTarget, segmentCount);
|
|
105
|
+
const collisions = matches.filter((file) => getPathSuffix(file.path, segmentCount) === suffix);
|
|
106
|
+
if (collisions.length === 1) {
|
|
107
|
+
return applyMarkdownExtensionPreference(suffix, settings);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return getAbsoluteLinkPath(normalizedTarget, settings);
|
|
111
|
+
}
|
|
112
|
+
function getResolvedSettings(settings) {
|
|
113
|
+
return {
|
|
114
|
+
...defaultLinkSettings,
|
|
115
|
+
...settings,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function getLabelFromTargetPath(targetPath) {
|
|
119
|
+
const normalized = normalizeVaultPath(targetPath);
|
|
120
|
+
const extension = getFileExtension(normalized);
|
|
121
|
+
if (isMarkdownExtension(extension)) {
|
|
122
|
+
return getMarkdownBasename(normalized);
|
|
123
|
+
}
|
|
124
|
+
return basename(normalized);
|
|
125
|
+
}
|
|
126
|
+
function getLinkFragment(options) {
|
|
127
|
+
if (options.blockId?.trim()) {
|
|
128
|
+
return `#^${options.blockId.trim()}`;
|
|
129
|
+
}
|
|
130
|
+
if (options.heading?.trim()) {
|
|
131
|
+
return `#${stripHeadingForLink(options.heading)}`;
|
|
132
|
+
}
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
function escapeRegexChar(char) {
|
|
136
|
+
return `\\${char}`;
|
|
137
|
+
}
|
|
138
|
+
export function normalizeVaultPath(path) {
|
|
139
|
+
return path.replaceAll("\\", "/").replace(/^\/+/, "").replace(/\/$/, "");
|
|
140
|
+
}
|
|
141
|
+
export function escapeWikilinkPath(path) {
|
|
142
|
+
return path.replace(/[\\#[\]|]/g, escapeRegexChar);
|
|
143
|
+
}
|
|
144
|
+
export function escapeWikilinkAlias(alias) {
|
|
145
|
+
return alias.replace(/[\\[\]|]/g, escapeRegexChar);
|
|
146
|
+
}
|
|
147
|
+
export function encodeMarkdownLinkDestination(path) {
|
|
148
|
+
const [rawPath, rawFragment] = path.split("#", 2);
|
|
149
|
+
const encodedPath = splitVaultPath(rawPath)
|
|
150
|
+
.map((part) => encodeURIComponent(part))
|
|
151
|
+
.join("/");
|
|
152
|
+
if (rawFragment === undefined) {
|
|
153
|
+
return encodedPath;
|
|
154
|
+
}
|
|
155
|
+
return `${encodedPath}#${encodeURIComponent(rawFragment)}`;
|
|
156
|
+
}
|
|
157
|
+
export function escapeMarkdownLabel(label) {
|
|
158
|
+
return label.replace(/[\\\[\]]/g, escapeRegexChar);
|
|
159
|
+
}
|
|
160
|
+
export function getLinkPath(targetPath, sourcePath, settings, vaultIndex) {
|
|
161
|
+
const normalizedTarget = normalizeVaultPath(targetPath);
|
|
162
|
+
const normalizedSource = normalizeVaultPath(sourcePath);
|
|
163
|
+
switch (settings.newLinkFormat) {
|
|
164
|
+
case "absolute":
|
|
165
|
+
return getAbsoluteLinkPath(normalizedTarget, settings);
|
|
166
|
+
case "relative":
|
|
167
|
+
return getRelativeLinkPath(normalizedTarget, normalizedSource, settings);
|
|
168
|
+
case "shortest":
|
|
169
|
+
default:
|
|
170
|
+
if (settings.useShortestUniqueSuffix) {
|
|
171
|
+
return getShortestUniqueSuffixPath(normalizedTarget, settings, vaultIndex);
|
|
172
|
+
}
|
|
173
|
+
return getObsidianCompatibleShortestPath(normalizedTarget, settings, vaultIndex);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export function generateInternalLink(options) {
|
|
177
|
+
const settings = getResolvedSettings(options.settings);
|
|
178
|
+
const targetPath = normalizeVaultPath(options.targetPath);
|
|
179
|
+
const linkPath = getLinkPath(targetPath, options.sourcePath, settings, options.vaultIndex ?? { getFiles: () => [] });
|
|
180
|
+
const fragment = getLinkFragment(options);
|
|
181
|
+
if (settings.useWikilinks) {
|
|
182
|
+
const target = `${escapeWikilinkPath(linkPath)}${fragment}`;
|
|
183
|
+
const alias = options.alias?.trim();
|
|
184
|
+
const display = alias ? `|${escapeWikilinkAlias(alias)}` : "";
|
|
185
|
+
return `${options.embed ? "!" : ""}[[${target}${display}]]`;
|
|
186
|
+
}
|
|
187
|
+
const alias = options.alias?.trim();
|
|
188
|
+
const label = escapeMarkdownLabel(alias || getLabelFromTargetPath(targetPath));
|
|
189
|
+
const destination = encodeMarkdownLinkDestination(`${linkPath}${fragment}`);
|
|
190
|
+
return `${options.embed ? "!" : ""}[${label}](${destination})`;
|
|
191
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function getLanguage(): string;
|
|
2
|
+
export declare function loadMathJax(): Promise<void>;
|
|
3
|
+
export declare function loadMermaid(): Promise<any>;
|
|
4
|
+
export declare function loadPdfJs(): Promise<any>;
|
|
5
|
+
export declare function loadPrism(): Promise<any>;
|
|
6
|
+
export declare function renderMath(source: string, display: boolean): HTMLElement;
|
|
7
|
+
export declare function finishRenderMath(): void;
|
|
8
|
+
export declare function sanitizeHTMLString(html: string): string;
|
|
9
|
+
export declare function sanitizeHTMLToDom(html: string): DocumentFragment;
|
package/dist/loaders.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function getLanguage() {
|
|
2
|
+
return navigator.language || "en";
|
|
3
|
+
}
|
|
4
|
+
export async function loadMathJax() { }
|
|
5
|
+
export async function loadMermaid() {
|
|
6
|
+
return globalThis.mermaid ?? {};
|
|
7
|
+
}
|
|
8
|
+
export async function loadPdfJs() {
|
|
9
|
+
return globalThis.pdfjsLib ?? {};
|
|
10
|
+
}
|
|
11
|
+
export async function loadPrism() {
|
|
12
|
+
return globalThis.Prism ?? {};
|
|
13
|
+
}
|
|
14
|
+
export function renderMath(source, display) {
|
|
15
|
+
const el = document.createElement(display ? "div" : "span");
|
|
16
|
+
el.className = display ? "math math-block" : "math math-inline";
|
|
17
|
+
el.textContent = source;
|
|
18
|
+
return el;
|
|
19
|
+
}
|
|
20
|
+
export function finishRenderMath() { }
|
|
21
|
+
const unsafeElementSelector = "script, iframe, object, embed";
|
|
22
|
+
const urlAttributes = new Set([
|
|
23
|
+
"href",
|
|
24
|
+
"src",
|
|
25
|
+
"xlink:href",
|
|
26
|
+
"formaction",
|
|
27
|
+
"poster",
|
|
28
|
+
]);
|
|
29
|
+
function isUnsafeUrl(value) {
|
|
30
|
+
return /^\s*(?:javascript:|vbscript:|data:text\/html)/i.test(value);
|
|
31
|
+
}
|
|
32
|
+
function sanitizeDomTree(root) {
|
|
33
|
+
root
|
|
34
|
+
.querySelectorAll(unsafeElementSelector)
|
|
35
|
+
.forEach((element) => element.remove());
|
|
36
|
+
root.querySelectorAll("*").forEach((element) => {
|
|
37
|
+
for (const attr of [...element.attributes]) {
|
|
38
|
+
const name = attr.name.toLowerCase();
|
|
39
|
+
if (name.startsWith("on")) {
|
|
40
|
+
element.removeAttribute(attr.name);
|
|
41
|
+
}
|
|
42
|
+
else if (urlAttributes.has(name) && isUnsafeUrl(attr.value)) {
|
|
43
|
+
element.removeAttribute(attr.name);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function sanitizeHTMLString(html) {
|
|
49
|
+
return html
|
|
50
|
+
.replace(/<\s*(script|iframe|object|embed)\b[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, "")
|
|
51
|
+
.replace(/\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "")
|
|
52
|
+
.replace(/\s+(href|src|xlink:href|formaction|poster)\s*=\s*(["']?)\s*(?:javascript:|vbscript:|data:text\/html)[\s\S]*?\2/gi, "");
|
|
53
|
+
}
|
|
54
|
+
export function sanitizeHTMLToDom(html) {
|
|
55
|
+
const template = document.createElement("template");
|
|
56
|
+
template.innerHTML = sanitizeHTMLString(html);
|
|
57
|
+
sanitizeDomTree(template.content);
|
|
58
|
+
return template.content;
|
|
59
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface LocaleData {
|
|
2
|
+
[key: string]: string | LocaleData;
|
|
3
|
+
}
|
|
4
|
+
export interface I18nConfig {
|
|
5
|
+
defaultLocale: string;
|
|
6
|
+
locales: string[];
|
|
7
|
+
fallbackLocale?: string;
|
|
8
|
+
interpolation?: {
|
|
9
|
+
prefix?: string;
|
|
10
|
+
suffix?: string;
|
|
11
|
+
escapeValue?: boolean;
|
|
12
|
+
};
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type TranslateArgs = [namespace: string, key: string, params?: Record<string, string | number>] | [key: string, params?: Record<string, string | number>];
|
|
16
|
+
export declare class LocalizationManager {
|
|
17
|
+
private currentLocale;
|
|
18
|
+
private initialized;
|
|
19
|
+
private availableLocales;
|
|
20
|
+
constructor();
|
|
21
|
+
get locale(): string;
|
|
22
|
+
get locales(): string[];
|
|
23
|
+
get instance(): import("i18next").i18n;
|
|
24
|
+
private initializeI18next;
|
|
25
|
+
setConfig(config: Partial<I18nConfig>): Promise<void>;
|
|
26
|
+
setLocale(locale: string): Promise<void>;
|
|
27
|
+
addResourceBundle(ns: string, locale: string, translations: LocaleData, deep?: boolean, overwrite?: boolean): Promise<() => void>;
|
|
28
|
+
private extractParams;
|
|
29
|
+
t(namespace: string, key: string, params?: Record<string, string | number>): string;
|
|
30
|
+
t(namespace: string, key: string): string;
|
|
31
|
+
t(key: string, params?: Record<string, string | number>): string;
|
|
32
|
+
t(...args: TranslateArgs): string;
|
|
33
|
+
plural(count: number, namespace: string, key: string, params?: Record<string, string | number>): string;
|
|
34
|
+
plural(count: number, namespace: string, key: string): string;
|
|
35
|
+
plural(count: number, key: string, params?: Record<string, string | number>): string;
|
|
36
|
+
plural(count: number, ...args: TranslateArgs): string;
|
|
37
|
+
exists(key: string, locale?: string, namespace?: string): boolean;
|
|
38
|
+
}
|
|
39
|
+
declare const localeManager: LocalizationManager;
|
|
40
|
+
declare const t: {
|
|
41
|
+
(namespace: string, key: string, params?: Record<string, string | number>): string;
|
|
42
|
+
(namespace: string, key: string): string;
|
|
43
|
+
(key: string, params?: Record<string, string | number>): string;
|
|
44
|
+
(...args: TranslateArgs): string;
|
|
45
|
+
};
|
|
46
|
+
declare const plural: {
|
|
47
|
+
(count: number, namespace: string, key: string, params?: Record<string, string | number>): string;
|
|
48
|
+
(count: number, namespace: string, key: string): string;
|
|
49
|
+
(count: number, key: string, params?: Record<string, string | number>): string;
|
|
50
|
+
(count: number, ...args: TranslateArgs): string;
|
|
51
|
+
};
|
|
52
|
+
export declare function useLocale(namespace?: string): {
|
|
53
|
+
t(key: string, params?: Record<string, string | number>): string;
|
|
54
|
+
plural(key: string, count: number, params?: Record<string, string | number>): string;
|
|
55
|
+
};
|
|
56
|
+
export { localeManager, localeManager as i18n, t, plural };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import i18next, {} from "i18next";
|
|
2
|
+
export class LocalizationManager {
|
|
3
|
+
currentLocale = $state("en");
|
|
4
|
+
initialized = false;
|
|
5
|
+
availableLocales = $state(["en"]);
|
|
6
|
+
constructor() {
|
|
7
|
+
this.initializeI18next();
|
|
8
|
+
}
|
|
9
|
+
get locale() {
|
|
10
|
+
return this.currentLocale;
|
|
11
|
+
}
|
|
12
|
+
get locales() {
|
|
13
|
+
return this.availableLocales;
|
|
14
|
+
}
|
|
15
|
+
get instance() {
|
|
16
|
+
return i18next;
|
|
17
|
+
}
|
|
18
|
+
async initializeI18next() {
|
|
19
|
+
const config = {
|
|
20
|
+
lng: "en",
|
|
21
|
+
fallbackLng: "en",
|
|
22
|
+
debug: false,
|
|
23
|
+
interpolation: {
|
|
24
|
+
escapeValue: false,
|
|
25
|
+
prefix: "{{",
|
|
26
|
+
suffix: "}}",
|
|
27
|
+
},
|
|
28
|
+
resources: {},
|
|
29
|
+
defaultNS: "base",
|
|
30
|
+
ns: ["base"],
|
|
31
|
+
returnEmptyString: false,
|
|
32
|
+
returnNull: false,
|
|
33
|
+
returnObjects: false,
|
|
34
|
+
keySeparator: ".",
|
|
35
|
+
nsSeparator: ":",
|
|
36
|
+
};
|
|
37
|
+
await i18next.init(config);
|
|
38
|
+
this.initialized = true;
|
|
39
|
+
this.currentLocale = i18next.language;
|
|
40
|
+
}
|
|
41
|
+
async setConfig(config) {
|
|
42
|
+
if (!this.initialized) {
|
|
43
|
+
await this.initializeI18next();
|
|
44
|
+
}
|
|
45
|
+
const i18nextConfig = {
|
|
46
|
+
lng: config.defaultLocale,
|
|
47
|
+
fallbackLng: config.fallbackLocale || config.defaultLocale,
|
|
48
|
+
debug: config.debug || false,
|
|
49
|
+
interpolation: config.interpolation
|
|
50
|
+
? {
|
|
51
|
+
escapeValue: config.interpolation.escapeValue ?? false,
|
|
52
|
+
prefix: config.interpolation.prefix || "{{",
|
|
53
|
+
suffix: config.interpolation.suffix || "}}",
|
|
54
|
+
}
|
|
55
|
+
: undefined,
|
|
56
|
+
};
|
|
57
|
+
await i18next.init(i18nextConfig);
|
|
58
|
+
if (config.locales) {
|
|
59
|
+
this.availableLocales = config.locales;
|
|
60
|
+
}
|
|
61
|
+
if (config.defaultLocale) {
|
|
62
|
+
this.currentLocale = config.defaultLocale;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async setLocale(locale) {
|
|
66
|
+
if (!this.availableLocales.includes(locale)) {
|
|
67
|
+
console.warn(`Locale ${locale} not supported. Available locales: ${this.availableLocales.join(", ")}`);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
await i18next.changeLanguage(locale);
|
|
71
|
+
this.currentLocale = locale;
|
|
72
|
+
}
|
|
73
|
+
async addResourceBundle(ns, locale, translations, deep = true, overwrite = true) {
|
|
74
|
+
if (!this.initialized) {
|
|
75
|
+
await this.initializeI18next();
|
|
76
|
+
}
|
|
77
|
+
i18next.addResourceBundle(locale, ns, translations, deep, overwrite);
|
|
78
|
+
return () => {
|
|
79
|
+
i18next.removeResourceBundle(locale, ns);
|
|
80
|
+
const currentNamespaces = i18next.options.ns;
|
|
81
|
+
i18next.options.ns = currentNamespaces.filter((namespace) => namespace !== ns);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
extractParams(...args) {
|
|
85
|
+
let key;
|
|
86
|
+
let namespace;
|
|
87
|
+
let params;
|
|
88
|
+
if (typeof args[0] !== "string") {
|
|
89
|
+
throw new Error("Expected a string as the first argument in i18n.t");
|
|
90
|
+
}
|
|
91
|
+
if (args.length === 3) {
|
|
92
|
+
if (typeof args[1] !== "string") {
|
|
93
|
+
throw new Error("Expected a string as the second argument for key in i18n.t");
|
|
94
|
+
}
|
|
95
|
+
namespace = args[0];
|
|
96
|
+
key = args[1];
|
|
97
|
+
params = args[2];
|
|
98
|
+
}
|
|
99
|
+
else if (args.length == 2) {
|
|
100
|
+
if (typeof args[1] === "string") {
|
|
101
|
+
namespace = args[0];
|
|
102
|
+
key = args[1];
|
|
103
|
+
}
|
|
104
|
+
else if (typeof args[1] === "object") {
|
|
105
|
+
key = args[0];
|
|
106
|
+
params = args[1];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw new Error("Expected a string | object as the second argument in i18n.t");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
key = args[0];
|
|
114
|
+
}
|
|
115
|
+
return [key, namespace, params];
|
|
116
|
+
}
|
|
117
|
+
t(...args) {
|
|
118
|
+
const [key, namespace, params] = this.extractParams(...args);
|
|
119
|
+
const id = namespace ? `${namespace}:${key}` : key;
|
|
120
|
+
const options = params ? { ...params } : {};
|
|
121
|
+
const translation = i18next.t(id, options);
|
|
122
|
+
return translation || key;
|
|
123
|
+
}
|
|
124
|
+
plural(count, ...args) {
|
|
125
|
+
const [key, namespace, params] = this.extractParams(...args);
|
|
126
|
+
if (!this.initialized) {
|
|
127
|
+
console.warn("i18n not initialized yet");
|
|
128
|
+
return key;
|
|
129
|
+
}
|
|
130
|
+
const id = namespace ? `${namespace}:${key}` : key;
|
|
131
|
+
const options = { count, ...params };
|
|
132
|
+
const translation = i18next.t(id, options);
|
|
133
|
+
return translation || key;
|
|
134
|
+
}
|
|
135
|
+
exists(key, locale, namespace) {
|
|
136
|
+
if (!this.initialized) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const id = namespace ? `${namespace}:${key}` : key;
|
|
140
|
+
const targetLocale = locale || this.currentLocale;
|
|
141
|
+
return i18next.exists(id, { lng: targetLocale });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const localeManager = new LocalizationManager();
|
|
145
|
+
const t = localeManager.t.bind(localeManager);
|
|
146
|
+
const plural = localeManager.plural.bind(localeManager);
|
|
147
|
+
export function useLocale(namespace = "base") {
|
|
148
|
+
return {
|
|
149
|
+
t(key, params) {
|
|
150
|
+
return t(namespace, key, params);
|
|
151
|
+
},
|
|
152
|
+
plural(key, count, params) {
|
|
153
|
+
return plural(count, namespace, key, params);
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export { localeManager, localeManager as i18n, t, plural };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { EventDispatcher } from "./events";
|
|
2
|
+
import { Plugin } from "./plugin";
|
|
3
|
+
/**
|
|
4
|
+
* All possible log levels
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface ILogLevel {
|
|
9
|
+
1: "trace";
|
|
10
|
+
2: "debug";
|
|
11
|
+
3: "info";
|
|
12
|
+
4: "warn";
|
|
13
|
+
5: "error";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Logger class to handle consistency of logs across the plugin.
|
|
17
|
+
*
|
|
18
|
+
* @interface LogEntry
|
|
19
|
+
*/
|
|
20
|
+
export interface LogEntry {
|
|
21
|
+
traceId?: string;
|
|
22
|
+
level: string;
|
|
23
|
+
module: string;
|
|
24
|
+
location?: string;
|
|
25
|
+
message: string;
|
|
26
|
+
objects: any;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Logging options structure.
|
|
30
|
+
*
|
|
31
|
+
* @interface LogOptions
|
|
32
|
+
*/
|
|
33
|
+
export interface LogOptions {
|
|
34
|
+
minLevels: {
|
|
35
|
+
[module: string]: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Log level IDs (1 - 5)
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export type TLogLevelId = keyof ILogLevel;
|
|
44
|
+
/**
|
|
45
|
+
* Log level names (trace - error)
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export type TLogLevelName = ILogLevel[TLogLevelId];
|
|
50
|
+
type LogEvents = {
|
|
51
|
+
log: [logEntry: LogEntry];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Logger class to handle consistency of logs across the plugin.
|
|
55
|
+
*
|
|
56
|
+
* @class LogManager
|
|
57
|
+
* @extends {EventDispatcher}
|
|
58
|
+
*/
|
|
59
|
+
export declare class LogManager extends EventDispatcher<LogEvents> {
|
|
60
|
+
private options;
|
|
61
|
+
private consoleLoggerRegistered;
|
|
62
|
+
/**
|
|
63
|
+
* Set the minimum log levels for the module name or global.
|
|
64
|
+
*
|
|
65
|
+
* @param {LogOptions} options
|
|
66
|
+
* @returns {any} {LogManager}
|
|
67
|
+
*/
|
|
68
|
+
configure(options: LogOptions): LogManager;
|
|
69
|
+
setLevel(module: string, level: TLogLevelName): void;
|
|
70
|
+
/**
|
|
71
|
+
* Returns a logger instance for the given module name.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} module
|
|
74
|
+
* @returns {any} {Logger}
|
|
75
|
+
*/
|
|
76
|
+
getLogger(module: string): Logger;
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
*
|
|
80
|
+
* @param {(logEntry: LogEntry) => void} listener
|
|
81
|
+
* @returns {any} {LogManager}
|
|
82
|
+
*/
|
|
83
|
+
onLogEntry(listener: (logEntry: LogEntry) => void): LogManager;
|
|
84
|
+
arrAvg: (arr: number[]) => number;
|
|
85
|
+
/**
|
|
86
|
+
* Registers a logger that write to the console.
|
|
87
|
+
*
|
|
88
|
+
* @returns {any} {LogManager}
|
|
89
|
+
*/
|
|
90
|
+
registerConsoleLogger(props?: Partial<{
|
|
91
|
+
color: boolean;
|
|
92
|
+
}>): LogManager;
|
|
93
|
+
}
|
|
94
|
+
export declare const logging: LogManager;
|
|
95
|
+
/**
|
|
96
|
+
* Main logging library, to view the logs a logger listener must be added. The
|
|
97
|
+
* Console Logger is already implemented for this project.
|
|
98
|
+
*
|
|
99
|
+
* @class Logger
|
|
100
|
+
*/
|
|
101
|
+
export declare class Logger {
|
|
102
|
+
readonly getLevel: () => string;
|
|
103
|
+
private logManager;
|
|
104
|
+
private module;
|
|
105
|
+
private readonly levels;
|
|
106
|
+
/**
|
|
107
|
+
* Creates an instance of Logger.
|
|
108
|
+
*
|
|
109
|
+
* @param {EventEmitter2} logManager
|
|
110
|
+
* @param {string} module
|
|
111
|
+
* @param {string} minLevel
|
|
112
|
+
*/
|
|
113
|
+
constructor(logManager: EventDispatcher<LogEvents>, module: string, getLevel: () => string);
|
|
114
|
+
get minLevel(): number;
|
|
115
|
+
/**
|
|
116
|
+
* Converts a string level (trace/debug/info/warn/error) into a number
|
|
117
|
+
*
|
|
118
|
+
* @param minLevel
|
|
119
|
+
*/
|
|
120
|
+
private levelToInt;
|
|
121
|
+
/**
|
|
122
|
+
* Central logging method.
|
|
123
|
+
*
|
|
124
|
+
* @param logLevel
|
|
125
|
+
* @param message
|
|
126
|
+
*/
|
|
127
|
+
log(logLevel: string, message: string, objects?: any): void;
|
|
128
|
+
trace(message: string, objects?: any): void;
|
|
129
|
+
debug(message: string, objects?: any): void;
|
|
130
|
+
info(message: string, objects?: any): void;
|
|
131
|
+
warn(message: string, objects?: any): void;
|
|
132
|
+
error(message: string, objects?: any): void;
|
|
133
|
+
/**
|
|
134
|
+
* Central logging method with a trace ID to track calls between
|
|
135
|
+
* modules/components.
|
|
136
|
+
*
|
|
137
|
+
* @param logLevel
|
|
138
|
+
* @param message
|
|
139
|
+
*/
|
|
140
|
+
logWithId(logLevel: string, traceId: string, message: string, objects?: any): void;
|
|
141
|
+
traceWithId(traceId: string, message: string, objects?: any): void;
|
|
142
|
+
debugWithId(traceId: string, message: string, objects?: any): void;
|
|
143
|
+
infoWithId(traceId: string, message: string, objects?: any): void;
|
|
144
|
+
warnWithId(traceId: string, message: string, objects?: any): void;
|
|
145
|
+
errorWithId(traceId: string, message: string, objects?: any): void;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* This deceleration will log the time taken to run the function it is attached
|
|
149
|
+
* to. Be careful where it is added as it increases the output.
|
|
150
|
+
*
|
|
151
|
+
* @returns {any}
|
|
152
|
+
*/
|
|
153
|
+
export declare const logCall: (target: Object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
154
|
+
export declare function logCallDetails(): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
155
|
+
/**
|
|
156
|
+
* Provides a simple log function that can be used to log messages against
|
|
157
|
+
* default module.
|
|
158
|
+
*
|
|
159
|
+
* @param {TLogLevelName} logLevel
|
|
160
|
+
* @param {string} message
|
|
161
|
+
*/
|
|
162
|
+
export declare function log(logLevel: TLogLevelName, message: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* This allows the plugin to be debugged in a mobile application add it when
|
|
165
|
+
* debugging on a device. Not meant to be used by end users. Add it into main.ts
|
|
166
|
+
* and remove before you commit.
|
|
167
|
+
*
|
|
168
|
+
* @param {Plugin} plugin
|
|
169
|
+
* @returns {any}
|
|
170
|
+
*/
|
|
171
|
+
export declare function monkeyPatchConsole(plugin: Plugin): void;
|
|
172
|
+
export {};
|