phormat 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -0
- package/dist/assets/example-test.svelte +228 -0
- package/dist/debug/JsonDebug.svelte +19 -0
- package/dist/debug/JsonDebug.svelte.d.ts +6 -0
- package/dist/debug/JsonDebugNode.svelte +138 -0
- package/dist/debug/JsonDebugNode.svelte.d.ts +11 -0
- package/dist/demo/documentLifecycle.d.ts +57 -0
- package/dist/demo/documentLifecycle.js +196 -0
- package/dist/demo/index.d.ts +2 -0
- package/dist/demo/index.js +2 -0
- package/dist/editor/BlockEditor.svelte +112 -0
- package/dist/editor/BlockEditor.svelte.d.ts +7 -0
- package/dist/editor/BlockRow.svelte +76 -0
- package/dist/editor/BlockRow.svelte.d.ts +20 -0
- package/dist/editor/Editor.svelte +103 -0
- package/dist/editor/Editor.svelte.d.ts +7 -0
- package/dist/editor/MarkdownEditor.svelte.d.ts +160 -0
- package/dist/editor/MarkdownEditor.svelte.js +1119 -0
- package/dist/editor/NestedRowChrome.svelte +160 -0
- package/dist/editor/NestedRowChrome.svelte.d.ts +20 -0
- package/dist/editor/PhormatEditor.svelte +206 -0
- package/dist/editor/PhormatEditor.svelte.d.ts +26 -0
- package/dist/editor/RawMarkdownPanel.svelte +39 -0
- package/dist/editor/RawMarkdownPanel.svelte.d.ts +6 -0
- package/dist/editor/block-specs/BlockSpecMissing.svelte +12 -0
- package/dist/editor/block-specs/BlockSpecMissing.svelte.d.ts +7 -0
- package/dist/editor/block-specs/blockquote/BlockquoteRenderer.svelte +32 -0
- package/dist/editor/block-specs/blockquote/BlockquoteRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/blockquote/commands.d.ts +2 -0
- package/dist/editor/block-specs/blockquote/commands.js +65 -0
- package/dist/editor/block-specs/blockquote/index.d.ts +6 -0
- package/dist/editor/block-specs/blockquote/index.js +5 -0
- package/dist/editor/block-specs/blockquote/inlineSecondPass.d.ts +6 -0
- package/dist/editor/block-specs/blockquote/inlineSecondPass.js +35 -0
- package/dist/editor/block-specs/blockquote/parse.d.ts +16 -0
- package/dist/editor/block-specs/blockquote/parse.js +188 -0
- package/dist/editor/block-specs/blockquote/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/blockquote/reconcile.js +9 -0
- package/dist/editor/block-specs/blockquote/serialize.d.ts +6 -0
- package/dist/editor/block-specs/blockquote/serialize.js +55 -0
- package/dist/editor/block-specs/blockquote/types.d.ts +20 -0
- package/dist/editor/block-specs/blockquote/types.js +1 -0
- package/dist/editor/block-specs/blockquoteSpec.d.ts +4 -0
- package/dist/editor/block-specs/blockquoteSpec.js +37 -0
- package/dist/editor/block-specs/callout/CalloutRenderer.svelte +38 -0
- package/dist/editor/block-specs/callout/CalloutRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/callout/CalloutTypeIcon.svelte +14 -0
- package/dist/editor/block-specs/callout/CalloutTypeIcon.svelte.d.ts +7 -0
- package/dist/editor/block-specs/callout/commands.d.ts +2 -0
- package/dist/editor/block-specs/callout/commands.js +65 -0
- package/dist/editor/block-specs/callout/icons.d.ts +10 -0
- package/dist/editor/block-specs/callout/icons.js +52 -0
- package/dist/editor/block-specs/callout/index.d.ts +9 -0
- package/dist/editor/block-specs/callout/index.js +7 -0
- package/dist/editor/block-specs/callout/inlineSecondPass.d.ts +6 -0
- package/dist/editor/block-specs/callout/inlineSecondPass.js +9 -0
- package/dist/editor/block-specs/callout/parse.d.ts +9 -0
- package/dist/editor/block-specs/callout/parse.js +83 -0
- package/dist/editor/block-specs/callout/parseBody.d.ts +6 -0
- package/dist/editor/block-specs/callout/parseBody.js +290 -0
- package/dist/editor/block-specs/callout/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/callout/reconcile.js +8 -0
- package/dist/editor/block-specs/callout/serialize.d.ts +5 -0
- package/dist/editor/block-specs/callout/serialize.js +65 -0
- package/dist/editor/block-specs/callout/types.d.ts +7 -0
- package/dist/editor/block-specs/callout/types.js +1 -0
- package/dist/editor/block-specs/calloutSpec.d.ts +2 -0
- package/dist/editor/block-specs/calloutSpec.js +23 -0
- package/dist/editor/block-specs/codeFence/CodeFenceRenderer.svelte +18 -0
- package/dist/editor/block-specs/codeFence/CodeFenceRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/codeFence/commands.d.ts +2 -0
- package/dist/editor/block-specs/codeFence/commands.js +1 -0
- package/dist/editor/block-specs/codeFence/index.d.ts +5 -0
- package/dist/editor/block-specs/codeFence/index.js +4 -0
- package/dist/editor/block-specs/codeFence/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/codeFence/inlineSecondPass.js +5 -0
- package/dist/editor/block-specs/codeFence/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/codeFence/reconcile.js +5 -0
- package/dist/editor/block-specs/codeFence/serialize.d.ts +2 -0
- package/dist/editor/block-specs/codeFence/serialize.js +8 -0
- package/dist/editor/block-specs/codeFence/types.d.ts +6 -0
- package/dist/editor/block-specs/codeFence/types.js +1 -0
- package/dist/editor/block-specs/codeFenceSpec.d.ts +2 -0
- package/dist/editor/block-specs/codeFenceSpec.js +23 -0
- package/dist/editor/block-specs/columns/ColumnsRenderer.svelte +18 -0
- package/dist/editor/block-specs/columns/ColumnsRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/columns/EditableColumns.svelte +16 -0
- package/dist/editor/block-specs/columns/EditableColumns.svelte.d.ts +4 -0
- package/dist/editor/block-specs/columns/commands.d.ts +2 -0
- package/dist/editor/block-specs/columns/commands.js +1 -0
- package/dist/editor/block-specs/columns/index.d.ts +6 -0
- package/dist/editor/block-specs/columns/index.js +5 -0
- package/dist/editor/block-specs/columns/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/columns/inlineSecondPass.js +5 -0
- package/dist/editor/block-specs/columns/parse.d.ts +20 -0
- package/dist/editor/block-specs/columns/parse.js +111 -0
- package/dist/editor/block-specs/columns/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/columns/reconcile.js +6 -0
- package/dist/editor/block-specs/columns/serialize.d.ts +2 -0
- package/dist/editor/block-specs/columns/serialize.js +16 -0
- package/dist/editor/block-specs/columns/types.d.ts +4 -0
- package/dist/editor/block-specs/columns/types.js +1 -0
- package/dist/editor/block-specs/columnsSpec.d.ts +2 -0
- package/dist/editor/block-specs/columnsSpec.js +24 -0
- package/dist/editor/block-specs/heading/HeaderRenderer.svelte +30 -0
- package/dist/editor/block-specs/heading/HeaderRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/heading/commands.d.ts +2 -0
- package/dist/editor/block-specs/heading/commands.js +41 -0
- package/dist/editor/block-specs/heading/edit.d.ts +10 -0
- package/dist/editor/block-specs/heading/edit.js +33 -0
- package/dist/editor/block-specs/heading/index.d.ts +7 -0
- package/dist/editor/block-specs/heading/index.js +6 -0
- package/dist/editor/block-specs/heading/inlineSecondPass.d.ts +4 -0
- package/dist/editor/block-specs/heading/inlineSecondPass.js +20 -0
- package/dist/editor/block-specs/heading/parse.d.ts +5 -0
- package/dist/editor/block-specs/heading/parse.js +18 -0
- package/dist/editor/block-specs/heading/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/heading/reconcile.js +8 -0
- package/dist/editor/block-specs/heading/serialize.d.ts +2 -0
- package/dist/editor/block-specs/heading/serialize.js +9 -0
- package/dist/editor/block-specs/heading/types.d.ts +5 -0
- package/dist/editor/block-specs/heading/types.js +1 -0
- package/dist/editor/block-specs/headingSpec.d.ts +2 -0
- package/dist/editor/block-specs/headingSpec.js +28 -0
- package/dist/editor/block-specs/horizontalRule/HorizontalRuleRenderer.svelte +15 -0
- package/dist/editor/block-specs/horizontalRule/HorizontalRuleRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/horizontalRule/commands.d.ts +2 -0
- package/dist/editor/block-specs/horizontalRule/commands.js +1 -0
- package/dist/editor/block-specs/horizontalRule/index.d.ts +6 -0
- package/dist/editor/block-specs/horizontalRule/index.js +5 -0
- package/dist/editor/block-specs/horizontalRule/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/horizontalRule/inlineSecondPass.js +5 -0
- package/dist/editor/block-specs/horizontalRule/parse.d.ts +2 -0
- package/dist/editor/block-specs/horizontalRule/parse.js +15 -0
- package/dist/editor/block-specs/horizontalRule/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/horizontalRule/reconcile.js +5 -0
- package/dist/editor/block-specs/horizontalRule/serialize.d.ts +2 -0
- package/dist/editor/block-specs/horizontalRule/serialize.js +3 -0
- package/dist/editor/block-specs/horizontalRule/types.d.ts +3 -0
- package/dist/editor/block-specs/horizontalRule/types.js +1 -0
- package/dist/editor/block-specs/horizontalRuleSpec.d.ts +2 -0
- package/dist/editor/block-specs/horizontalRuleSpec.js +24 -0
- package/dist/editor/block-specs/list/ListRenderer.svelte +70 -0
- package/dist/editor/block-specs/list/ListRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/list/commands.d.ts +2 -0
- package/dist/editor/block-specs/list/commands.js +65 -0
- package/dist/editor/block-specs/list/index.d.ts +6 -0
- package/dist/editor/block-specs/list/index.js +5 -0
- package/dist/editor/block-specs/list/inlineSecondPass.d.ts +6 -0
- package/dist/editor/block-specs/list/inlineSecondPass.js +78 -0
- package/dist/editor/block-specs/list/parse.d.ts +11 -0
- package/dist/editor/block-specs/list/parse.js +312 -0
- package/dist/editor/block-specs/list/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/list/reconcile.js +6 -0
- package/dist/editor/block-specs/list/serialize.d.ts +4 -0
- package/dist/editor/block-specs/list/serialize.js +83 -0
- package/dist/editor/block-specs/list/types.d.ts +27 -0
- package/dist/editor/block-specs/list/types.js +1 -0
- package/dist/editor/block-specs/listSpec.d.ts +4 -0
- package/dist/editor/block-specs/listSpec.js +24 -0
- package/dist/editor/block-specs/paragraph/ParagraphRenderer.svelte +22 -0
- package/dist/editor/block-specs/paragraph/ParagraphRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/paragraph/commands.d.ts +2 -0
- package/dist/editor/block-specs/paragraph/commands.js +41 -0
- package/dist/editor/block-specs/paragraph/edit.d.ts +10 -0
- package/dist/editor/block-specs/paragraph/edit.js +69 -0
- package/dist/editor/block-specs/paragraph/index.d.ts +7 -0
- package/dist/editor/block-specs/paragraph/index.js +6 -0
- package/dist/editor/block-specs/paragraph/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/paragraph/inlineSecondPass.js +25 -0
- package/dist/editor/block-specs/paragraph/parse.d.ts +9 -0
- package/dist/editor/block-specs/paragraph/parse.js +76 -0
- package/dist/editor/block-specs/paragraph/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/paragraph/reconcile.js +9 -0
- package/dist/editor/block-specs/paragraph/serialize.d.ts +4 -0
- package/dist/editor/block-specs/paragraph/serialize.js +39 -0
- package/dist/editor/block-specs/paragraph/types.d.ts +10 -0
- package/dist/editor/block-specs/paragraph/types.js +1 -0
- package/dist/editor/block-specs/paragraphSpec.d.ts +2 -0
- package/dist/editor/block-specs/paragraphSpec.js +24 -0
- package/dist/editor/block-specs/registry.d.ts +10 -0
- package/dist/editor/block-specs/registry.js +34 -0
- package/dist/editor/block-specs/table/TableRenderer.svelte +53 -0
- package/dist/editor/block-specs/table/TableRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/table/commands.d.ts +2 -0
- package/dist/editor/block-specs/table/commands.js +1 -0
- package/dist/editor/block-specs/table/edit.d.ts +10 -0
- package/dist/editor/block-specs/table/edit.js +127 -0
- package/dist/editor/block-specs/table/editCommands.d.ts +18 -0
- package/dist/editor/block-specs/table/editCommands.js +87 -0
- package/dist/editor/block-specs/table/index.d.ts +8 -0
- package/dist/editor/block-specs/table/index.js +6 -0
- package/dist/editor/block-specs/table/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/table/inlineSecondPass.js +22 -0
- package/dist/editor/block-specs/table/parse.d.ts +17 -0
- package/dist/editor/block-specs/table/parse.js +181 -0
- package/dist/editor/block-specs/table/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/table/reconcile.js +6 -0
- package/dist/editor/block-specs/table/serialize.d.ts +3 -0
- package/dist/editor/block-specs/table/serialize.js +32 -0
- package/dist/editor/block-specs/table/types.d.ts +11 -0
- package/dist/editor/block-specs/table/types.js +1 -0
- package/dist/editor/block-specs/tableSpec.d.ts +2 -0
- package/dist/editor/block-specs/tableSpec.js +25 -0
- package/dist/editor/block-specs/toc/EditableToc.svelte +16 -0
- package/dist/editor/block-specs/toc/EditableToc.svelte.d.ts +4 -0
- package/dist/editor/block-specs/toc/TocRenderer.svelte +22 -0
- package/dist/editor/block-specs/toc/TocRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/toc/commands.d.ts +2 -0
- package/dist/editor/block-specs/toc/commands.js +1 -0
- package/dist/editor/block-specs/toc/index.d.ts +6 -0
- package/dist/editor/block-specs/toc/index.js +5 -0
- package/dist/editor/block-specs/toc/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/toc/inlineSecondPass.js +5 -0
- package/dist/editor/block-specs/toc/parse.d.ts +10 -0
- package/dist/editor/block-specs/toc/parse.js +43 -0
- package/dist/editor/block-specs/toc/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/toc/reconcile.js +5 -0
- package/dist/editor/block-specs/toc/serialize.d.ts +2 -0
- package/dist/editor/block-specs/toc/serialize.js +6 -0
- package/dist/editor/block-specs/toc/types.d.ts +8 -0
- package/dist/editor/block-specs/toc/types.js +1 -0
- package/dist/editor/block-specs/tocSpec.d.ts +2 -0
- package/dist/editor/block-specs/tocSpec.js +24 -0
- package/dist/editor/block-specs/toggle/ToggleRenderer.svelte +19 -0
- package/dist/editor/block-specs/toggle/ToggleRenderer.svelte.d.ts +21 -0
- package/dist/editor/block-specs/toggle/commands.d.ts +2 -0
- package/dist/editor/block-specs/toggle/commands.js +1 -0
- package/dist/editor/block-specs/toggle/index.d.ts +7 -0
- package/dist/editor/block-specs/toggle/index.js +5 -0
- package/dist/editor/block-specs/toggle/inlineSecondPass.d.ts +3 -0
- package/dist/editor/block-specs/toggle/inlineSecondPass.js +5 -0
- package/dist/editor/block-specs/toggle/parse.d.ts +9 -0
- package/dist/editor/block-specs/toggle/parse.js +78 -0
- package/dist/editor/block-specs/toggle/reconcile.d.ts +2 -0
- package/dist/editor/block-specs/toggle/reconcile.js +6 -0
- package/dist/editor/block-specs/toggle/serialize.d.ts +4 -0
- package/dist/editor/block-specs/toggle/serialize.js +13 -0
- package/dist/editor/block-specs/toggle/types.d.ts +5 -0
- package/dist/editor/block-specs/toggle/types.js +1 -0
- package/dist/editor/block-specs/toggleSpec.d.ts +2 -0
- package/dist/editor/block-specs/toggleSpec.js +24 -0
- package/dist/editor/block-specs/types.d.ts +26 -0
- package/dist/editor/block-specs/types.js +1 -0
- package/dist/editor/blocks/EditableBlockquote.svelte +52 -0
- package/dist/editor/blocks/EditableBlockquote.svelte.d.ts +10 -0
- package/dist/editor/blocks/EditableBlockquoteNodes.svelte +134 -0
- package/dist/editor/blocks/EditableBlockquoteNodes.svelte.d.ts +14 -0
- package/dist/editor/blocks/EditableBlockquoteParagraph.svelte +44 -0
- package/dist/editor/blocks/EditableBlockquoteParagraph.svelte.d.ts +12 -0
- package/dist/editor/blocks/EditableCallout.svelte +182 -0
- package/dist/editor/blocks/EditableCallout.svelte.d.ts +11 -0
- package/dist/editor/blocks/EditableCalloutListItemRow.svelte +169 -0
- package/dist/editor/blocks/EditableCalloutListItemRow.svelte.d.ts +15 -0
- package/dist/editor/blocks/EditableCalloutNodes.svelte +91 -0
- package/dist/editor/blocks/EditableCalloutNodes.svelte.d.ts +13 -0
- package/dist/editor/blocks/EditableCalloutParagraph.svelte +39 -0
- package/dist/editor/blocks/EditableCalloutParagraph.svelte.d.ts +12 -0
- package/dist/editor/blocks/EditableCodeBlock.svelte +43 -0
- package/dist/editor/blocks/EditableCodeBlock.svelte.d.ts +10 -0
- package/dist/editor/blocks/EditableHeading.svelte +161 -0
- package/dist/editor/blocks/EditableHeading.svelte.d.ts +10 -0
- package/dist/editor/blocks/EditableHorizontalRule.svelte +20 -0
- package/dist/editor/blocks/EditableHorizontalRule.svelte.d.ts +10 -0
- package/dist/editor/blocks/EditableInlineSurface.svelte +423 -0
- package/dist/editor/blocks/EditableInlineSurface.svelte.d.ts +26 -0
- package/dist/editor/blocks/EditableList.svelte +77 -0
- package/dist/editor/blocks/EditableList.svelte.d.ts +17 -0
- package/dist/editor/blocks/EditableListItemRow.svelte +231 -0
- package/dist/editor/blocks/EditableListItemRow.svelte.d.ts +19 -0
- package/dist/editor/blocks/EditableParagraph.svelte +208 -0
- package/dist/editor/blocks/EditableParagraph.svelte.d.ts +10 -0
- package/dist/editor/blocks/EditableParagraphNodes.svelte +89 -0
- package/dist/editor/blocks/EditableParagraphNodes.svelte.d.ts +15 -0
- package/dist/editor/blocks/EditableTable.svelte +83 -0
- package/dist/editor/blocks/EditableTable.svelte.d.ts +10 -0
- package/dist/editor/blocks/EditableTableCell.svelte +89 -0
- package/dist/editor/blocks/EditableTableCell.svelte.d.ts +15 -0
- package/dist/editor/blocks/EditableToggle.svelte +94 -0
- package/dist/editor/blocks/EditableToggle.svelte.d.ts +10 -0
- package/dist/editor/commandMenu.d.ts +18 -0
- package/dist/editor/commandMenu.js +83 -0
- package/dist/editor/commandRegistry.d.ts +48 -0
- package/dist/editor/commandRegistry.js +133 -0
- package/dist/editor/context/assetBaseUrl.d.ts +6 -0
- package/dist/editor/context/assetBaseUrl.js +20 -0
- package/dist/editor/dom/editorHistoryKeydown.d.ts +6 -0
- package/dist/editor/dom/editorHistoryKeydown.js +31 -0
- package/dist/editor/dom/plainEnterKeydown.d.ts +12 -0
- package/dist/editor/dom/plainEnterKeydown.js +53 -0
- package/dist/editor/dom/plaintextCaret.d.ts +12 -0
- package/dist/editor/dom/plaintextCaret.js +61 -0
- package/dist/editor/dom/syncDocumentSelectionFocus.d.ts +17 -0
- package/dist/editor/dom/syncDocumentSelectionFocus.js +56 -0
- package/dist/editor/draftPersistence.d.ts +27 -0
- package/dist/editor/draftPersistence.js +83 -0
- package/dist/editor/editorHistoryHandle.d.ts +16 -0
- package/dist/editor/editorHistoryHandle.js +22 -0
- package/dist/editor/inlineChrome/InlineChromeCoordinator.svelte +174 -0
- package/dist/editor/inlineChrome/InlineChromeCoordinator.svelte.d.ts +8 -0
- package/dist/editor/inlineChrome/InlineFormattingToolbar.svelte +181 -0
- package/dist/editor/inlineChrome/InlineFormattingToolbar.svelte.d.ts +3 -0
- package/dist/editor/inlineChrome/inlineChromeActions.d.ts +17 -0
- package/dist/editor/inlineChrome/inlineChromeActions.js +148 -0
- package/dist/editor/inlineChrome/inlineChromeState.svelte.d.ts +23 -0
- package/dist/editor/inlineChrome/inlineChromeState.svelte.js +21 -0
- package/dist/editor/inlineChrome/inlineToolbarIcons.d.ts +14 -0
- package/dist/editor/inlineChrome/inlineToolbarIcons.js +14 -0
- package/dist/editor/inlineChrome/inlineWrapActive.d.ts +3 -0
- package/dist/editor/inlineChrome/inlineWrapActive.js +19 -0
- package/dist/editor/inlineChrome/selectionRect.d.ts +2 -0
- package/dist/editor/inlineChrome/selectionRect.js +23 -0
- package/dist/editor/model/blockEditCommands.d.ts +73 -0
- package/dist/editor/model/blockEditCommands.js +719 -0
- package/dist/editor/model/blockTree.d.ts +39 -0
- package/dist/editor/model/blockTree.js +185 -0
- package/dist/editor/model/blockTreeDrop.d.ts +9 -0
- package/dist/editor/model/blockTreeDrop.js +295 -0
- package/dist/editor/model/blockTreeMutations.d.ts +10 -0
- package/dist/editor/model/blockTreeMutations.js +68 -0
- package/dist/editor/model/calloutEditCommands.d.ts +39 -0
- package/dist/editor/model/calloutEditCommands.js +305 -0
- package/dist/editor/model/documentSelection.d.ts +8 -0
- package/dist/editor/model/documentSelection.js +56 -0
- package/dist/editor/model/documentSelectionFromSource.d.ts +3 -0
- package/dist/editor/model/documentSelectionFromSource.js +45 -0
- package/dist/editor/model/documentToRenderBlocks.d.ts +3 -0
- package/dist/editor/model/documentToRenderBlocks.js +13 -0
- package/dist/editor/model/editorPipeline.bench.d.ts +1 -0
- package/dist/editor/model/editorPipeline.bench.js +27 -0
- package/dist/editor/model/editorTransactions.d.ts +20 -0
- package/dist/editor/model/editorTransactions.js +68 -0
- package/dist/editor/model/emptyParagraph.d.ts +11 -0
- package/dist/editor/model/emptyParagraph.js +25 -0
- package/dist/editor/model/enterCommands.d.ts +16 -0
- package/dist/editor/model/enterCommands.js +288 -0
- package/dist/editor/model/extensionSyntaxWarnings.d.ts +29 -0
- package/dist/editor/model/extensionSyntaxWarnings.js +122 -0
- package/dist/editor/model/findBlockAtSourceOffset.d.ts +3 -0
- package/dist/editor/model/findBlockAtSourceOffset.js +20 -0
- package/dist/editor/model/fixtures/serialization-fidelity/reorder-gaps.svelte +4 -0
- package/dist/editor/model/focusOutcome.d.ts +25 -0
- package/dist/editor/model/focusOutcome.js +1 -0
- package/dist/editor/model/incrementalReparse.d.ts +16 -0
- package/dist/editor/model/incrementalReparse.js +111 -0
- package/dist/editor/model/index.d.ts +22 -0
- package/dist/editor/model/index.js +19 -0
- package/dist/editor/model/inlineDraftCommit.d.ts +17 -0
- package/dist/editor/model/inlineDraftCommit.js +187 -0
- package/dist/editor/model/inlineDraftMerge.d.ts +8 -0
- package/dist/editor/model/inlineDraftMerge.js +81 -0
- package/dist/editor/model/inlineEditCommands.d.ts +28 -0
- package/dist/editor/model/inlineEditCommands.js +581 -0
- package/dist/editor/model/inlinePlain.d.ts +3 -0
- package/dist/editor/model/inlinePlain.js +28 -0
- package/dist/editor/model/inlineSecondPass.d.ts +4 -0
- package/dist/editor/model/inlineSecondPass.js +47 -0
- package/dist/editor/model/line-utils.d.ts +14 -0
- package/dist/editor/model/line-utils.js +38 -0
- package/dist/editor/model/listEditCommands.d.ts +56 -0
- package/dist/editor/model/listEditCommands.js +299 -0
- package/dist/editor/model/nestedContainerTransactions.d.ts +36 -0
- package/dist/editor/model/nestedContainerTransactions.js +336 -0
- package/dist/editor/model/parseMarkdownDocument.d.ts +2 -0
- package/dist/editor/model/parseMarkdownDocument.js +324 -0
- package/dist/editor/model/quoteEditCommands.d.ts +39 -0
- package/dist/editor/model/quoteEditCommands.js +323 -0
- package/dist/editor/model/reconcileBlockIds.d.ts +9 -0
- package/dist/editor/model/reconcileBlockIds.js +297 -0
- package/dist/editor/model/reparseOptions.d.ts +12 -0
- package/dist/editor/model/reparseOptions.js +1 -0
- package/dist/editor/model/resolveEnterPlainSnapshot.d.ts +6 -0
- package/dist/editor/model/resolveEnterPlainSnapshot.js +23 -0
- package/dist/editor/model/richInlines.d.ts +16 -0
- package/dist/editor/model/richInlines.js +494 -0
- package/dist/editor/model/serializeInlineNodes.d.ts +3 -0
- package/dist/editor/model/serializeInlineNodes.js +45 -0
- package/dist/editor/model/serializeMarkdownDocument.d.ts +30 -0
- package/dist/editor/model/serializeMarkdownDocument.js +150 -0
- package/dist/editor/model/structureParseWarnings.d.ts +10 -0
- package/dist/editor/model/structureParseWarnings.js +60 -0
- package/dist/editor/model/syntheticInlineRanges.d.ts +3 -0
- package/dist/editor/model/syntheticInlineRanges.js +36 -0
- package/dist/editor/model/types.d.ts +185 -0
- package/dist/editor/model/types.js +26 -0
- package/dist/editor/plugins/autolinks/AutolinkRenderer.svelte +20 -0
- package/dist/editor/plugins/autolinks/AutolinkRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/autolinks/index.d.ts +2 -0
- package/dist/editor/plugins/autolinks/index.js +4 -0
- package/dist/editor/plugins/autolinks/parse-autolinks.d.ts +2 -0
- package/dist/editor/plugins/autolinks/parse-autolinks.js +68 -0
- package/dist/editor/plugins/autolinks/types.d.ts +6 -0
- package/dist/editor/plugins/autolinks/types.js +1 -0
- package/dist/editor/plugins/emphasis/EmphasisRenderer.svelte +15 -0
- package/dist/editor/plugins/emphasis/EmphasisRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/emphasis/index.d.ts +2 -0
- package/dist/editor/plugins/emphasis/index.js +4 -0
- package/dist/editor/plugins/emphasis/parse-emphasis.d.ts +2 -0
- package/dist/editor/plugins/emphasis/parse-emphasis.js +188 -0
- package/dist/editor/plugins/emphasis/types.d.ts +24 -0
- package/dist/editor/plugins/emphasis/types.js +1 -0
- package/dist/editor/plugins/escaping/EscapingRenderer.svelte +18 -0
- package/dist/editor/plugins/escaping/EscapingRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/escaping/index.d.ts +2 -0
- package/dist/editor/plugins/escaping/index.js +4 -0
- package/dist/editor/plugins/escaping/parse-escaping.d.ts +6 -0
- package/dist/editor/plugins/escaping/parse-escaping.js +26 -0
- package/dist/editor/plugins/escaping/types.d.ts +10 -0
- package/dist/editor/plugins/escaping/types.js +1 -0
- package/dist/editor/plugins/extended-task-list/ExtendedTaskListRenderer.svelte +25 -0
- package/dist/editor/plugins/extended-task-list/ExtendedTaskListRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/extended-task-list/index.d.ts +2 -0
- package/dist/editor/plugins/extended-task-list/index.js +4 -0
- package/dist/editor/plugins/extended-task-list/parse-extended-task-list.d.ts +2 -0
- package/dist/editor/plugins/extended-task-list/parse-extended-task-list.js +35 -0
- package/dist/editor/plugins/extended-task-list/types.d.ts +6 -0
- package/dist/editor/plugins/extended-task-list/types.js +1 -0
- package/dist/editor/plugins/highlight/HighlightRenderer.svelte +16 -0
- package/dist/editor/plugins/highlight/HighlightRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/highlight/index.d.ts +2 -0
- package/dist/editor/plugins/highlight/index.js +4 -0
- package/dist/editor/plugins/highlight/parse-highlights.d.ts +4 -0
- package/dist/editor/plugins/highlight/parse-highlights.js +49 -0
- package/dist/editor/plugins/highlight/types.d.ts +6 -0
- package/dist/editor/plugins/highlight/types.js +1 -0
- package/dist/editor/plugins/index.d.ts +1 -0
- package/dist/editor/plugins/index.js +1 -0
- package/dist/editor/plugins/links-images/LinksImagesRenderer.svelte +53 -0
- package/dist/editor/plugins/links-images/LinksImagesRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/links-images/index.d.ts +2 -0
- package/dist/editor/plugins/links-images/index.js +4 -0
- package/dist/editor/plugins/links-images/parse-image-layout.d.ts +28 -0
- package/dist/editor/plugins/links-images/parse-image-layout.js +147 -0
- package/dist/editor/plugins/links-images/parse-links-images.d.ts +25 -0
- package/dist/editor/plugins/links-images/parse-links-images.js +236 -0
- package/dist/editor/plugins/links-images/resolve-asset-url.d.ts +5 -0
- package/dist/editor/plugins/links-images/resolve-asset-url.js +21 -0
- package/dist/editor/plugins/links-images/types.d.ts +11 -0
- package/dist/editor/plugins/links-images/types.js +1 -0
- package/dist/editor/plugins/mention/MentionRenderer.svelte +18 -0
- package/dist/editor/plugins/mention/MentionRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/mention/index.d.ts +2 -0
- package/dist/editor/plugins/mention/index.js +4 -0
- package/dist/editor/plugins/mention/parse-mentions.d.ts +2 -0
- package/dist/editor/plugins/mention/parse-mentions.js +54 -0
- package/dist/editor/plugins/mention/types.d.ts +14 -0
- package/dist/editor/plugins/mention/types.js +1 -0
- package/dist/editor/plugins/raw-text/RawTextRenderer.svelte +19 -0
- package/dist/editor/plugins/raw-text/RawTextRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/raw-text/index.d.ts +2 -0
- package/dist/editor/plugins/raw-text/index.js +4 -0
- package/dist/editor/plugins/raw-text/types.d.ts +4 -0
- package/dist/editor/plugins/raw-text/types.js +1 -0
- package/dist/editor/plugins/shared/InlineNodes.svelte +113 -0
- package/dist/editor/plugins/shared/InlineNodes.svelte.d.ts +21 -0
- package/dist/editor/plugins/shared/InlineNodesEdit.svelte +78 -0
- package/dist/editor/plugins/shared/InlineNodesEdit.svelte.d.ts +21 -0
- package/dist/editor/plugins/strikethrough/StrikethroughRenderer.svelte +9 -0
- package/dist/editor/plugins/strikethrough/StrikethroughRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/strikethrough/index.d.ts +2 -0
- package/dist/editor/plugins/strikethrough/index.js +4 -0
- package/dist/editor/plugins/strikethrough/parse-strikethrough.d.ts +3 -0
- package/dist/editor/plugins/strikethrough/parse-strikethrough.js +38 -0
- package/dist/editor/plugins/strikethrough/types.d.ts +4 -0
- package/dist/editor/plugins/strikethrough/types.js +1 -0
- package/dist/editor/plugins/synced-block/SyncedBlockRenderer.svelte +16 -0
- package/dist/editor/plugins/synced-block/SyncedBlockRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/synced-block/index.d.ts +2 -0
- package/dist/editor/plugins/synced-block/index.js +4 -0
- package/dist/editor/plugins/synced-block/parse-synced-blocks.d.ts +2 -0
- package/dist/editor/plugins/synced-block/parse-synced-blocks.js +15 -0
- package/dist/editor/plugins/synced-block/types.d.ts +4 -0
- package/dist/editor/plugins/synced-block/types.js +1 -0
- package/dist/editor/plugins/types.d.ts +19 -0
- package/dist/editor/plugins/types.js +1 -0
- package/dist/editor/plugins/wiki-link/WikiLinkRenderer.svelte +15 -0
- package/dist/editor/plugins/wiki-link/WikiLinkRenderer.svelte.d.ts +21 -0
- package/dist/editor/plugins/wiki-link/index.d.ts +2 -0
- package/dist/editor/plugins/wiki-link/index.js +4 -0
- package/dist/editor/plugins/wiki-link/parse-wiki-links.d.ts +2 -0
- package/dist/editor/plugins/wiki-link/parse-wiki-links.js +30 -0
- package/dist/editor/plugins/wiki-link/types.d.ts +8 -0
- package/dist/editor/plugins/wiki-link/types.js +1 -0
- package/dist/editor/taskCheckboxStates.d.ts +5 -0
- package/dist/editor/taskCheckboxStates.js +28 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/styles/index.css +6 -0
- package/package.json +84 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick } from 'svelte';
|
|
3
|
+
import type { MarkdownEditor } from '../MarkdownEditor.svelte';
|
|
4
|
+
import type { EditorBlockType, InlineNode, TableCellAddress, DocumentSelection } from '../model/types';
|
|
5
|
+
import {
|
|
6
|
+
deleteCharAfter,
|
|
7
|
+
deleteCharBefore,
|
|
8
|
+
deletePlainRange,
|
|
9
|
+
draftInlinesFromBlock,
|
|
10
|
+
insertTextAtPlainOffset,
|
|
11
|
+
type InlineWrapKind,
|
|
12
|
+
wrapInlineSelection
|
|
13
|
+
} from '../model/inlineEditCommands';
|
|
14
|
+
import {
|
|
15
|
+
draftInlineMergeFingerprint,
|
|
16
|
+
mergeDraftInlineWithParser
|
|
17
|
+
} from '../model/inlineDraftMerge';
|
|
18
|
+
import { inlineNodesToPlainText } from '../model/inlinePlain';
|
|
19
|
+
import { inlineNodesEditSnippet } from '../plugins/shared/InlineNodesEdit.svelte';
|
|
20
|
+
import { plainOffsets, setCaretPlainOffset } from '../dom/plaintextCaret';
|
|
21
|
+
import { handleEditorUndoRedoKeydown } from '../dom/editorHistoryKeydown';
|
|
22
|
+
import { syncDocumentSelectionFocus } from '../dom/syncDocumentSelectionFocus';
|
|
23
|
+
|
|
24
|
+
let {
|
|
25
|
+
editor,
|
|
26
|
+
blockId,
|
|
27
|
+
surfaceBlockType,
|
|
28
|
+
modelInlines,
|
|
29
|
+
displayPlain,
|
|
30
|
+
singleLine = false,
|
|
31
|
+
ariaLabel,
|
|
32
|
+
ariaMultiline = true,
|
|
33
|
+
class: className = '',
|
|
34
|
+
onFocus,
|
|
35
|
+
onBlur,
|
|
36
|
+
onCommit,
|
|
37
|
+
onDraftChange,
|
|
38
|
+
onKeydownExtra,
|
|
39
|
+
supportsInlineWrap = false,
|
|
40
|
+
suppressEnterCommand = false,
|
|
41
|
+
tableCell,
|
|
42
|
+
onTableCellNavigate
|
|
43
|
+
}: {
|
|
44
|
+
editor: MarkdownEditor;
|
|
45
|
+
blockId: string;
|
|
46
|
+
/** Must match the block's post-command type so a dying surface cannot steal focus. */
|
|
47
|
+
surfaceBlockType?: EditorBlockType;
|
|
48
|
+
modelInlines: InlineNode[] | undefined;
|
|
49
|
+
displayPlain: string;
|
|
50
|
+
singleLine?: boolean;
|
|
51
|
+
ariaLabel: string;
|
|
52
|
+
ariaMultiline?: boolean;
|
|
53
|
+
class?: string;
|
|
54
|
+
onFocus?: () => void;
|
|
55
|
+
onBlur?: () => void;
|
|
56
|
+
onCommit: (inlines: InlineNode[], plainCaret: number) => void;
|
|
57
|
+
onDraftChange?: (plain: string, inlines: InlineNode[], plainCaret: number) => void;
|
|
58
|
+
onKeydownExtra?: (e: KeyboardEvent) => void;
|
|
59
|
+
supportsInlineWrap?: boolean;
|
|
60
|
+
suppressEnterCommand?: boolean;
|
|
61
|
+
tableCell?: TableCellAddress;
|
|
62
|
+
onTableCellNavigate?: (
|
|
63
|
+
direction: 'next' | 'prev' | 'down' | 'up',
|
|
64
|
+
inlines: InlineNode[],
|
|
65
|
+
plainCaret: number
|
|
66
|
+
) => void;
|
|
67
|
+
} = $props();
|
|
68
|
+
|
|
69
|
+
let focused = $state(false);
|
|
70
|
+
let el = $state.raw<HTMLDivElement | null>(null);
|
|
71
|
+
let draftInlines = $state<InlineNode[]>([]);
|
|
72
|
+
/** Bumps only during focused controlled-input re-renders — not on model sync. */
|
|
73
|
+
let draftRenderKey = $state(0);
|
|
74
|
+
let lastCommittedPlain = $state('');
|
|
75
|
+
let mergeRafId = 0;
|
|
76
|
+
let lastMergeFingerprint = '';
|
|
77
|
+
|
|
78
|
+
const committedInlines = $derived(draftInlinesFromBlock(modelInlines, displayPlain));
|
|
79
|
+
|
|
80
|
+
function hydrateDraft(): boolean {
|
|
81
|
+
const next = draftInlinesFromBlock(modelInlines, displayPlain);
|
|
82
|
+
const nextPlain = inlineNodesToPlainText(next);
|
|
83
|
+
const nextFingerprint = draftInlineMergeFingerprint(next);
|
|
84
|
+
const changed =
|
|
85
|
+
inlineNodesToPlainText(draftInlines) !== nextPlain ||
|
|
86
|
+
draftInlineMergeFingerprint(draftInlines) !== nextFingerprint;
|
|
87
|
+
if (changed) draftInlines = next;
|
|
88
|
+
lastCommittedPlain = nextPlain;
|
|
89
|
+
lastMergeFingerprint = nextFingerprint;
|
|
90
|
+
return changed;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function draftPlain(): string {
|
|
94
|
+
return inlineNodesToPlainText(draftInlines);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function rerenderDraft(caret: number) {
|
|
98
|
+
draftRenderKey++;
|
|
99
|
+
await tick();
|
|
100
|
+
const node = el;
|
|
101
|
+
if (node) setCaretPlainOffset(node, caret);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function applyWrap(kind: InlineWrapKind) {
|
|
105
|
+
const node = el;
|
|
106
|
+
if (!node || !supportsInlineWrap) return;
|
|
107
|
+
const { start, end } = plainOffsets(node);
|
|
108
|
+
const wrapped = wrapInlineSelection(draftInlines, start, end, kind);
|
|
109
|
+
if (!wrapped) return;
|
|
110
|
+
draftInlines = wrapped;
|
|
111
|
+
const caret = Math.min(end, draftPlain().length);
|
|
112
|
+
await rerenderDraft(caret);
|
|
113
|
+
onCommit(wrapped, caret);
|
|
114
|
+
lastCommittedPlain = draftPlain();
|
|
115
|
+
syncDocumentSelection();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function selectionPayload(plain: { start: number; end: number }): DocumentSelection {
|
|
119
|
+
return tableCell ? { blockId, plain, tableCell } : { blockId, plain };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function syncDocumentSelection() {
|
|
123
|
+
const node = el;
|
|
124
|
+
if (!node || document.activeElement !== node) return;
|
|
125
|
+
const { start, end } = plainOffsets(node);
|
|
126
|
+
editor.emitDocumentSelection(selectionPayload({ start, end }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function emitDraftChange(inlines: InlineNode[], caret: number) {
|
|
130
|
+
onDraftChange?.(inlineNodesToPlainText(inlines), inlines, caret);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function applyDraftMerge(caret: number) {
|
|
134
|
+
const merged = mergeDraftInlineWithParser(draftInlines);
|
|
135
|
+
const fp = draftInlineMergeFingerprint(merged);
|
|
136
|
+
if (fp !== lastMergeFingerprint) {
|
|
137
|
+
lastMergeFingerprint = fp;
|
|
138
|
+
draftInlines = merged;
|
|
139
|
+
emitDraftChange(merged, caret);
|
|
140
|
+
}
|
|
141
|
+
await rerenderDraft(caret);
|
|
142
|
+
syncDocumentSelection();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function scheduleDraftMerge(caret: number) {
|
|
146
|
+
cancelAnimationFrame(mergeRafId);
|
|
147
|
+
mergeRafId = requestAnimationFrame(() => {
|
|
148
|
+
void applyDraftMerge(caret);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function applyDraftMergeImmediate(caret: number) {
|
|
153
|
+
cancelAnimationFrame(mergeRafId);
|
|
154
|
+
mergeRafId = 0;
|
|
155
|
+
await applyDraftMerge(caret);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function finishControlledEdit(next: InlineNode[], caret: number, immediateMerge: boolean) {
|
|
159
|
+
draftInlines = next;
|
|
160
|
+
emitDraftChange(next, caret);
|
|
161
|
+
if (immediateMerge) await applyDraftMergeImmediate(caret);
|
|
162
|
+
else scheduleDraftMerge(caret);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function handleBeforeInput(e: InputEvent) {
|
|
166
|
+
if (!focused || !el) return;
|
|
167
|
+
const inputType = e.inputType;
|
|
168
|
+
if (inputType === 'insertParagraph' || inputType === 'insertLineBreak') {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
|
|
174
|
+
const { start, end } = plainOffsets(el);
|
|
175
|
+
let next = draftInlines.map((n) => ({ ...n })) as InlineNode[];
|
|
176
|
+
let caret = start;
|
|
177
|
+
|
|
178
|
+
if (inputType === 'insertText' || inputType === 'insertReplacementText') {
|
|
179
|
+
let text = e.data ?? '';
|
|
180
|
+
if (singleLine) text = text.replace(/\n/g, '');
|
|
181
|
+
if (start !== end) next = deletePlainRange(next, start, end);
|
|
182
|
+
next = insertTextAtPlainOffset(next, start, text, { stripNewlines: singleLine });
|
|
183
|
+
caret = start + text.length;
|
|
184
|
+
} else if (inputType === 'deleteContentBackward') {
|
|
185
|
+
if (start !== end) {
|
|
186
|
+
next = deletePlainRange(next, start, end);
|
|
187
|
+
caret = start;
|
|
188
|
+
} else if (start > 0) {
|
|
189
|
+
const deleted = deleteCharBefore(next, start);
|
|
190
|
+
if (deleted) next = deleted;
|
|
191
|
+
caret = start - 1;
|
|
192
|
+
}
|
|
193
|
+
} else if (inputType === 'deleteContentForward') {
|
|
194
|
+
if (start !== end) {
|
|
195
|
+
next = deletePlainRange(next, start, end);
|
|
196
|
+
caret = start;
|
|
197
|
+
} else {
|
|
198
|
+
const deleted = deleteCharAfter(next, start);
|
|
199
|
+
if (deleted) next = deleted;
|
|
200
|
+
caret = start;
|
|
201
|
+
}
|
|
202
|
+
} else if (inputType === 'insertFromPaste') {
|
|
203
|
+
return;
|
|
204
|
+
} else {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
draftInlines = next;
|
|
209
|
+
emitDraftChange(next, caret);
|
|
210
|
+
scheduleDraftMerge(caret);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function onpaste(e: ClipboardEvent) {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
let text = e.clipboardData?.getData('text/plain') ?? '';
|
|
216
|
+
if (singleLine) text = text.replace(/\n/g, '');
|
|
217
|
+
const node = el;
|
|
218
|
+
if (!node || !text) return;
|
|
219
|
+
const { start, end } = plainOffsets(node);
|
|
220
|
+
let next = draftInlines;
|
|
221
|
+
if (start !== end) next = deletePlainRange(next, start, end);
|
|
222
|
+
next = insertTextAtPlainOffset(next, start, text, { stripNewlines: singleLine });
|
|
223
|
+
const caret = start + text.length;
|
|
224
|
+
void finishControlledEdit(next, caret, true);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function onkeydown(e: KeyboardEvent & { currentTarget: HTMLDivElement }) {
|
|
228
|
+
const node = e.currentTarget;
|
|
229
|
+
|
|
230
|
+
if (handleEditorUndoRedoKeydown(editor, e)) {
|
|
231
|
+
queueMicrotask(() => {
|
|
232
|
+
hydrateDraft();
|
|
233
|
+
void rerenderDraft(
|
|
234
|
+
Math.min(editor.documentSelection?.plain?.end ?? 0, draftPlain().length)
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (onTableCellNavigate && e.key === 'Tab') {
|
|
241
|
+
e.preventDefault();
|
|
242
|
+
onTableCellNavigate(
|
|
243
|
+
e.shiftKey ? 'prev' : 'next',
|
|
244
|
+
draftInlines,
|
|
245
|
+
plainOffsets(node).start
|
|
246
|
+
);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (onTableCellNavigate && e.key === 'Enter') {
|
|
251
|
+
e.preventDefault();
|
|
252
|
+
onTableCellNavigate(
|
|
253
|
+
e.shiftKey ? 'up' : 'down',
|
|
254
|
+
draftInlines,
|
|
255
|
+
plainOffsets(node).start
|
|
256
|
+
);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (supportsInlineWrap && (e.metaKey || e.ctrlKey) && !e.altKey) {
|
|
261
|
+
const k = e.key.toLowerCase();
|
|
262
|
+
if (k === 'b') {
|
|
263
|
+
e.preventDefault();
|
|
264
|
+
void applyWrap('strong');
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (k === 'i') {
|
|
268
|
+
e.preventDefault();
|
|
269
|
+
void applyWrap('emphasis');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (k === '`') {
|
|
273
|
+
e.preventDefault();
|
|
274
|
+
void applyWrap('code');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (k === 'k') {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
void applyWrap('link');
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (e.shiftKey && k === 'x') {
|
|
283
|
+
e.preventDefault();
|
|
284
|
+
void applyWrap('strikethrough');
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (e.shiftKey && k === 'h') {
|
|
288
|
+
e.preventDefault();
|
|
289
|
+
void applyWrap('highlight');
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (!suppressEnterCommand && e.key === 'Enter' && e.shiftKey) {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
onKeydownExtra?.(e);
|
|
300
|
+
if (e.defaultPrevented) return;
|
|
301
|
+
|
|
302
|
+
if (!suppressEnterCommand && e.key === 'Enter' && !e.shiftKey) {
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
if (editor.shouldSuppressPlainInputForBlock(blockId)) return;
|
|
305
|
+
const { start, end } = plainOffsets(node);
|
|
306
|
+
const caret = Math.min(start, end);
|
|
307
|
+
onCommit(draftInlines, caret);
|
|
308
|
+
editor.enterAt({ blockId, plainOffset: caret, plainText: draftPlain() });
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function handleFocus() {
|
|
314
|
+
const node = el;
|
|
315
|
+
const wasFocused = focused;
|
|
316
|
+
// Capture click caret before swapping unfocused → focused DOM (that swap destroys selection).
|
|
317
|
+
const clickOffsets = !wasFocused && node ? plainOffsets(node) : null;
|
|
318
|
+
|
|
319
|
+
focused = true;
|
|
320
|
+
if (!wasFocused) {
|
|
321
|
+
hydrateDraft();
|
|
322
|
+
draftRenderKey++;
|
|
323
|
+
}
|
|
324
|
+
onFocus?.();
|
|
325
|
+
|
|
326
|
+
if (clickOffsets) {
|
|
327
|
+
void tick().then(() => {
|
|
328
|
+
const target = el;
|
|
329
|
+
if (!target || document.activeElement !== target) return;
|
|
330
|
+
setCaretPlainOffset(target, clickOffsets.start);
|
|
331
|
+
editor.claimDocumentSelection(
|
|
332
|
+
selectionPayload({ start: clickOffsets.start, end: clickOffsets.end })
|
|
333
|
+
);
|
|
334
|
+
});
|
|
335
|
+
} else if (node) {
|
|
336
|
+
const { start, end } = plainOffsets(node);
|
|
337
|
+
editor.claimDocumentSelection(selectionPayload({ start, end }));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function documentBlockMatchesSurface(): boolean {
|
|
342
|
+
if (!surfaceBlockType) return true;
|
|
343
|
+
return editor.document.blocks.find((b) => b.id === blockId)?.type === surfaceBlockType;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function handleBlur() {
|
|
347
|
+
focused = false;
|
|
348
|
+
editor.clearDocumentSelection(blockId);
|
|
349
|
+
if (editor.shouldSkipTableCellBlurCommit()) {
|
|
350
|
+
onBlur?.();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const plain = draftPlain();
|
|
354
|
+
const node = el;
|
|
355
|
+
const caret = node ? plainOffsets(node).start : plain.length;
|
|
356
|
+
if (plain !== lastCommittedPlain && documentBlockMatchesSurface()) {
|
|
357
|
+
onCommit(draftInlines, caret);
|
|
358
|
+
lastCommittedPlain = plain;
|
|
359
|
+
}
|
|
360
|
+
onBlur?.();
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function resyncDom() {
|
|
364
|
+
if (!focused) return;
|
|
365
|
+
if (hydrateDraft()) draftRenderKey++;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
$effect(() => {
|
|
369
|
+
const sel = editor.documentSelection;
|
|
370
|
+
const node = el;
|
|
371
|
+
if (!sel?.plain || !node) return;
|
|
372
|
+
syncDocumentSelectionFocus({
|
|
373
|
+
blockId,
|
|
374
|
+
tableCell,
|
|
375
|
+
getNode: () => el,
|
|
376
|
+
isFocused: () => focused,
|
|
377
|
+
setFocused: (value) => {
|
|
378
|
+
focused = value;
|
|
379
|
+
},
|
|
380
|
+
getDisplayPlain: () => displayPlain,
|
|
381
|
+
setLocalPlain: () => {},
|
|
382
|
+
resyncDom,
|
|
383
|
+
setCaret: setCaretPlainOffset,
|
|
384
|
+
documentSelection: sel,
|
|
385
|
+
takePendingFocus: (id, cell) =>
|
|
386
|
+
editor.takePendingFocusForBlock(id, cell, surfaceBlockType)
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
$effect(() => {
|
|
391
|
+
const node = el;
|
|
392
|
+
if (!node) return;
|
|
393
|
+
const onSel = () => syncDocumentSelection();
|
|
394
|
+
document.addEventListener('selectionchange', onSel);
|
|
395
|
+
return () => document.removeEventListener('selectionchange', onSel);
|
|
396
|
+
});
|
|
397
|
+
</script>
|
|
398
|
+
|
|
399
|
+
<div
|
|
400
|
+
bind:this={el}
|
|
401
|
+
data-md-inline-surface={blockId}
|
|
402
|
+
role="textbox"
|
|
403
|
+
tabindex={editor.readonly ? -1 : 0}
|
|
404
|
+
aria-multiline={ariaMultiline}
|
|
405
|
+
aria-label={ariaLabel}
|
|
406
|
+
contenteditable={editor.readonly ? 'false' : 'true'}
|
|
407
|
+
draggable="false"
|
|
408
|
+
class="relative z-[1] w-full border-0 bg-transparent px-0 py-0.5 text-base leading-relaxed whitespace-pre-wrap text-txt-primary ring-0 outline-none focus:ring-0 focus-visible:outline focus-visible:outline-1 focus-visible:outline-offset-2 focus-visible:outline-focus-ring {className}"
|
|
409
|
+
onfocus={handleFocus}
|
|
410
|
+
onblur={handleBlur}
|
|
411
|
+
onbeforeinput={handleBeforeInput}
|
|
412
|
+
onkeydown={onkeydown}
|
|
413
|
+
onkeyup={() => syncDocumentSelection()}
|
|
414
|
+
onpaste={onpaste}
|
|
415
|
+
>
|
|
416
|
+
{#if focused}
|
|
417
|
+
{#key draftRenderKey}
|
|
418
|
+
{@render inlineNodesEditSnippet(draftInlines)}
|
|
419
|
+
{/key}
|
|
420
|
+
{:else}
|
|
421
|
+
{@render inlineNodesEditSnippet(committedInlines)}
|
|
422
|
+
{/if}
|
|
423
|
+
</div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { MarkdownEditor } from '../MarkdownEditor.svelte';
|
|
2
|
+
import type { EditorBlockType, InlineNode, TableCellAddress } from '../model/types';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
editor: MarkdownEditor;
|
|
5
|
+
blockId: string;
|
|
6
|
+
/** Must match the block's post-command type so a dying surface cannot steal focus. */
|
|
7
|
+
surfaceBlockType?: EditorBlockType;
|
|
8
|
+
modelInlines: InlineNode[] | undefined;
|
|
9
|
+
displayPlain: string;
|
|
10
|
+
singleLine?: boolean;
|
|
11
|
+
ariaLabel: string;
|
|
12
|
+
ariaMultiline?: boolean;
|
|
13
|
+
class?: string;
|
|
14
|
+
onFocus?: () => void;
|
|
15
|
+
onBlur?: () => void;
|
|
16
|
+
onCommit: (inlines: InlineNode[], plainCaret: number) => void;
|
|
17
|
+
onDraftChange?: (plain: string, inlines: InlineNode[], plainCaret: number) => void;
|
|
18
|
+
onKeydownExtra?: (e: KeyboardEvent) => void;
|
|
19
|
+
supportsInlineWrap?: boolean;
|
|
20
|
+
suppressEnterCommand?: boolean;
|
|
21
|
+
tableCell?: TableCellAddress;
|
|
22
|
+
onTableCellNavigate?: (direction: 'next' | 'prev' | 'down' | 'up', inlines: InlineNode[], plainCaret: number) => void;
|
|
23
|
+
};
|
|
24
|
+
declare const EditableInlineSurface: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
25
|
+
type EditableInlineSurface = ReturnType<typeof EditableInlineSurface>;
|
|
26
|
+
export default EditableInlineSurface;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { InlineNode } from '../model/types';
|
|
3
|
+
import EditableListItemRow from './EditableListItemRow.svelte';
|
|
4
|
+
import type { MarkdownEditor } from '../MarkdownEditor.svelte';
|
|
5
|
+
import type { EditorBlock, ListItemBlockData } from '../model/types';
|
|
6
|
+
|
|
7
|
+
export type ListStructFocusOpts = {
|
|
8
|
+
focusBlockId?: string;
|
|
9
|
+
focusPlain?: { start: number; end: number };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let {
|
|
13
|
+
editor,
|
|
14
|
+
blockIndex,
|
|
15
|
+
block
|
|
16
|
+
}: {
|
|
17
|
+
editor: MarkdownEditor;
|
|
18
|
+
blockIndex: number;
|
|
19
|
+
block: EditorBlock;
|
|
20
|
+
} = $props();
|
|
21
|
+
|
|
22
|
+
let rowFocusCount = $state(0);
|
|
23
|
+
|
|
24
|
+
const itemData = $derived(block.data as ListItemBlockData);
|
|
25
|
+
|
|
26
|
+
const siblingIndex = $derived.by(() => {
|
|
27
|
+
let count = 0;
|
|
28
|
+
for (let i = 0; i < blockIndex; i++) {
|
|
29
|
+
const b = editor.document.blocks[i];
|
|
30
|
+
if (b?.type !== 'listItem') break;
|
|
31
|
+
const d = b.data as ListItemBlockData;
|
|
32
|
+
if (d.ordered !== itemData.ordered) break;
|
|
33
|
+
count++;
|
|
34
|
+
}
|
|
35
|
+
return count;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function applyStruct(
|
|
39
|
+
fn: (blocks: EditorBlock[]) => EditorBlock[] | null,
|
|
40
|
+
opts?: ListStructFocusOpts
|
|
41
|
+
) {
|
|
42
|
+
editor.applyListStructMutation(blockIndex, block.id, fn, opts);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function updateBody(itemId: string, inlines: InlineNode[], caret: number) {
|
|
46
|
+
editor.commitListItemInlineDraftAt(blockIndex, itemId, inlines, caret);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function onRowFocus() {
|
|
50
|
+
rowFocusCount++;
|
|
51
|
+
editor.beginPlainEditSession(blockIndex);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function onRowBlur() {
|
|
55
|
+
rowFocusCount--;
|
|
56
|
+
queueMicrotask(() => {
|
|
57
|
+
if (rowFocusCount <= 0) {
|
|
58
|
+
rowFocusCount = 0;
|
|
59
|
+
editor.commitPlainEditSession();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<EditableListItemRow
|
|
66
|
+
{editor}
|
|
67
|
+
{blockIndex}
|
|
68
|
+
item={block}
|
|
69
|
+
{siblingIndex}
|
|
70
|
+
markerOrdered={itemData.ordered}
|
|
71
|
+
markerStart={itemData.ordinalValue}
|
|
72
|
+
sourceSnapshot={editor.source}
|
|
73
|
+
{applyStruct}
|
|
74
|
+
{updateBody}
|
|
75
|
+
{onRowFocus}
|
|
76
|
+
{onRowBlur}
|
|
77
|
+
/>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MarkdownEditor } from '../MarkdownEditor.svelte';
|
|
2
|
+
import type { EditorBlock } from '../model/types';
|
|
3
|
+
export type ListStructFocusOpts = {
|
|
4
|
+
focusBlockId?: string;
|
|
5
|
+
focusPlain?: {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type $$ComponentProps = {
|
|
11
|
+
editor: MarkdownEditor;
|
|
12
|
+
blockIndex: number;
|
|
13
|
+
block: EditorBlock;
|
|
14
|
+
};
|
|
15
|
+
declare const EditableList: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
16
|
+
type EditableList = ReturnType<typeof EditableList>;
|
|
17
|
+
export default EditableList;
|