@witchcraft/editor 0.0.1
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/@types/@tiptap/core/index.d.ts +3 -0
- package/README.md +111 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +68 -0
- package/dist/runtime/assets/base.css +1 -0
- package/dist/runtime/assets/handle-arrow.svg +16 -0
- package/dist/runtime/assets/handle-border-circles-single.svg +44 -0
- package/dist/runtime/assets/handle-border-circles.svg +27 -0
- package/dist/runtime/assets/handle-temp.svg +1 -0
- package/dist/runtime/assets/utils.css +1 -0
- package/dist/runtime/components/CodeBlockThemePicker.d.vue.ts +12 -0
- package/dist/runtime/components/CodeBlockThemePicker.vue +123 -0
- package/dist/runtime/components/CodeBlockThemePicker.vue.d.ts +12 -0
- package/dist/runtime/components/Commands.d.vue.ts +10 -0
- package/dist/runtime/components/Commands.vue +60 -0
- package/dist/runtime/components/Commands.vue.d.ts +10 -0
- package/dist/runtime/components/Editor.d.vue.ts +40 -0
- package/dist/runtime/components/Editor.vue +208 -0
- package/dist/runtime/components/Editor.vue.d.ts +40 -0
- package/dist/runtime/components/EditorDemoApp.d.vue.ts +2 -0
- package/dist/runtime/components/EditorDemoApp.vue +104 -0
- package/dist/runtime/components/EditorDemoApp.vue.d.ts +2 -0
- package/dist/runtime/components/EditorDemoControls.d.vue.ts +12 -0
- package/dist/runtime/components/EditorDemoControls.vue +36 -0
- package/dist/runtime/components/EditorDemoControls.vue.d.ts +12 -0
- package/dist/runtime/components/TestWrapper.d.vue.ts +11 -0
- package/dist/runtime/components/TestWrapper.vue +63 -0
- package/dist/runtime/components/TestWrapper.vue.d.ts +11 -0
- package/dist/runtime/composables/useEditor.d.ts +9 -0
- package/dist/runtime/composables/useEditor.js +17 -0
- package/dist/runtime/composables/useWindowDebugging.d.ts +3 -0
- package/dist/runtime/composables/useWindowDebugging.js +16 -0
- package/dist/runtime/demo/App.d.vue.ts +2 -0
- package/dist/runtime/demo/App.vue +101 -0
- package/dist/runtime/demo/App.vue.d.ts +2 -0
- package/dist/runtime/demo/README.md +1 -0
- package/dist/runtime/demo/main.d.ts +1 -0
- package/dist/runtime/demo/main.js +4 -0
- package/dist/runtime/demo/tailwind.css +1 -0
- package/dist/runtime/env.d.ts +2 -0
- package/dist/runtime/injectionKeys.d.ts +6 -0
- package/dist/runtime/injectionKeys.js +3 -0
- package/dist/runtime/main.lib.d.ts +2 -0
- package/dist/runtime/main.lib.js +2 -0
- package/dist/runtime/pm/commands/backspace.d.ts +12 -0
- package/dist/runtime/pm/commands/backspace.js +26 -0
- package/dist/runtime/pm/commands/changeAttrs.d.ts +9 -0
- package/dist/runtime/pm/commands/changeAttrs.js +15 -0
- package/dist/runtime/pm/commands/deleteSelection.d.ts +9 -0
- package/dist/runtime/pm/commands/deleteSelection.js +8 -0
- package/dist/runtime/pm/commands/enter.d.ts +14 -0
- package/dist/runtime/pm/commands/enter.js +9 -0
- package/dist/runtime/pm/commands/insertBreak.d.ts +9 -0
- package/dist/runtime/pm/commands/insertBreak.js +22 -0
- package/dist/runtime/pm/features/Base/Base.d.ts +4 -0
- package/dist/runtime/pm/features/Base/Base.js +32 -0
- package/dist/runtime/pm/features/Base/commands/deleteNodes.d.ts +10 -0
- package/dist/runtime/pm/features/Base/commands/deleteNodes.js +29 -0
- package/dist/runtime/pm/features/Base/commands/setCursorVisible.d.ts +12 -0
- package/dist/runtime/pm/features/Base/commands/setCursorVisible.js +7 -0
- package/dist/runtime/pm/features/Base/plugins/debugSelectionPlugin.d.ts +9 -0
- package/dist/runtime/pm/features/Base/plugins/debugSelectionPlugin.js +48 -0
- package/dist/runtime/pm/features/Base/plugins/isCursorVisiblePlugin.d.ts +3 -0
- package/dist/runtime/pm/features/Base/plugins/isCursorVisiblePlugin.js +26 -0
- package/dist/runtime/pm/features/Base/plugins/isUsingTouchPlugin.d.ts +3 -0
- package/dist/runtime/pm/features/Base/plugins/isUsingTouchPlugin.js +38 -0
- package/dist/runtime/pm/features/Base/plugins/selectingIndicator.d.ts +5 -0
- package/dist/runtime/pm/features/Base/plugins/selectingIndicator.js +35 -0
- package/dist/runtime/pm/features/Base/plugins/unfocusedSelectionIndicatorPlugin.d.ts +33 -0
- package/dist/runtime/pm/features/Base/plugins/unfocusedSelectionIndicatorPlugin.js +66 -0
- package/dist/runtime/pm/features/Base/types.d.ts +3 -0
- package/dist/runtime/pm/features/Base/types.js +0 -0
- package/dist/runtime/pm/features/BaseShortcuts/BaseShortcuts.d.ts +3 -0
- package/dist/runtime/pm/features/BaseShortcuts/BaseShortcuts.js +34 -0
- package/dist/runtime/pm/features/Blockquote/Blockquote.d.ts +5 -0
- package/dist/runtime/pm/features/Blockquote/Blockquote.js +65 -0
- package/dist/runtime/pm/features/Blockquote/commands/blockquoteEnter.d.ts +11 -0
- package/dist/runtime/pm/features/Blockquote/commands/blockquoteEnter.js +31 -0
- package/dist/runtime/pm/features/Blockquote/commands/blockquoteShiftEnter.d.ts +11 -0
- package/dist/runtime/pm/features/Blockquote/commands/blockquoteShiftEnter.js +12 -0
- package/dist/runtime/pm/features/Blocks/Blocks.d.ts +2 -0
- package/dist/runtime/pm/features/Blocks/Blocks.js +2 -0
- package/dist/runtime/pm/features/Blocks/Item.d.ts +11 -0
- package/dist/runtime/pm/features/Blocks/Item.js +157 -0
- package/dist/runtime/pm/features/Blocks/List.d.ts +4 -0
- package/dist/runtime/pm/features/Blocks/List.js +59 -0
- package/dist/runtime/pm/features/Blocks/commands/changeItemType.d.ts +20 -0
- package/dist/runtime/pm/features/Blocks/commands/changeItemType.js +40 -0
- package/dist/runtime/pm/features/Blocks/commands/changeTypeAttr.d.ts +14 -0
- package/dist/runtime/pm/features/Blocks/commands/changeTypeAttr.js +28 -0
- package/dist/runtime/pm/features/Blocks/commands/copyOrMoveItem.d.ts +23 -0
- package/dist/runtime/pm/features/Blocks/commands/copyOrMoveItem.js +124 -0
- package/dist/runtime/pm/features/Blocks/commands/deleteItem.d.ts +12 -0
- package/dist/runtime/pm/features/Blocks/commands/deleteItem.js +8 -0
- package/dist/runtime/pm/features/Blocks/commands/indentItem.d.ts +12 -0
- package/dist/runtime/pm/features/Blocks/commands/indentItem.js +58 -0
- package/dist/runtime/pm/features/Blocks/commands/itemMenuCommands.d.ts +18 -0
- package/dist/runtime/pm/features/Blocks/commands/itemMenuCommands.js +40 -0
- package/dist/runtime/pm/features/Blocks/commands/moveItem.d.ts +12 -0
- package/dist/runtime/pm/features/Blocks/commands/moveItem.js +80 -0
- package/dist/runtime/pm/features/Blocks/commands/setNode.d.ts +20 -0
- package/dist/runtime/pm/features/Blocks/commands/setNode.js +87 -0
- package/dist/runtime/pm/features/Blocks/commands/splitItem.d.ts +17 -0
- package/dist/runtime/pm/features/Blocks/commands/splitItem.js +87 -0
- package/dist/runtime/pm/features/Blocks/commands/unindentItem.d.ts +12 -0
- package/dist/runtime/pm/features/Blocks/commands/unindentItem.js +42 -0
- package/dist/runtime/pm/features/Blocks/components/DragTreeHandle.d.vue.ts +0 -0
- package/dist/runtime/pm/features/Blocks/components/DragTreeHandle.vue +122 -0
- package/dist/runtime/pm/features/Blocks/components/DragTreeHandle.vue.d.ts +0 -0
- package/dist/runtime/pm/features/Blocks/components/ItemMenu.d.vue.ts +6 -0
- package/dist/runtime/pm/features/Blocks/components/ItemMenu.vue +78 -0
- package/dist/runtime/pm/features/Blocks/components/ItemMenu.vue.d.ts +6 -0
- package/dist/runtime/pm/features/Blocks/components/ItemNodeView.d.vue.ts +92 -0
- package/dist/runtime/pm/features/Blocks/components/ItemNodeView.vue +350 -0
- package/dist/runtime/pm/features/Blocks/components/ItemNodeView.vue.d.ts +92 -0
- package/dist/runtime/pm/features/Blocks/components/defaultItemMenu.d.ts +5 -0
- package/dist/runtime/pm/features/Blocks/components/defaultItemMenu.js +42 -0
- package/dist/runtime/pm/features/Blocks/composables/useDragWithThreshold.d.ts +1 -0
- package/dist/runtime/pm/features/Blocks/composables/useDragWithThreshold.js +0 -0
- package/dist/runtime/pm/features/Blocks/composables/useHandleHeight.d.ts +5 -0
- package/dist/runtime/pm/features/Blocks/composables/useHandleHeight.js +22 -0
- package/dist/runtime/pm/features/Blocks/composables/useHasChildren.d.ts +5 -0
- package/dist/runtime/pm/features/Blocks/composables/useHasChildren.js +10 -0
- package/dist/runtime/pm/features/Blocks/composables/useNodeStates.d.ts +7 -0
- package/dist/runtime/pm/features/Blocks/composables/useNodeStates.js +20 -0
- package/dist/runtime/pm/features/Blocks/itemMenuMenuItems.d.ts +20 -0
- package/dist/runtime/pm/features/Blocks/itemMenuMenuItems.js +138 -0
- package/dist/runtime/pm/features/Blocks/plugins/ensureLastItemIsContentPlugin.d.ts +11 -0
- package/dist/runtime/pm/features/Blocks/plugins/ensureLastItemIsContentPlugin.js +36 -0
- package/dist/runtime/pm/features/Blocks/plugins/itemBlockIdPlugin.d.ts +8 -0
- package/dist/runtime/pm/features/Blocks/plugins/itemBlockIdPlugin.js +30 -0
- package/dist/runtime/pm/features/Blocks/plugins/itemHasSingularSelectionPlugin.d.ts +3 -0
- package/dist/runtime/pm/features/Blocks/plugins/itemHasSingularSelectionPlugin.js +30 -0
- package/dist/runtime/pm/features/Blocks/plugins/itemMenuPlugin.d.ts +4 -0
- package/dist/runtime/pm/features/Blocks/plugins/itemMenuPlugin.js +17 -0
- package/dist/runtime/pm/features/Blocks/states/stateful.d.ts +2 -0
- package/dist/runtime/pm/features/Blocks/states/stateful.js +37 -0
- package/dist/runtime/pm/features/Blocks/states/task/cancelled.svg +32 -0
- package/dist/runtime/pm/features/Blocks/states/task/checked.svg +27 -0
- package/dist/runtime/pm/features/Blocks/states/task/checked2.svg +24 -0
- package/dist/runtime/pm/features/Blocks/states/task/partial.svg +24 -0
- package/dist/runtime/pm/features/Blocks/states/task/partial2.svg +31 -0
- package/dist/runtime/pm/features/Blocks/states/task/unchecked.svg +20 -0
- package/dist/runtime/pm/features/Blocks/types.d.ts +43 -0
- package/dist/runtime/pm/features/Blocks/types.js +2 -0
- package/dist/runtime/pm/features/Blocks/utils/createItemMenuCommandExecuter.d.ts +3 -0
- package/dist/runtime/pm/features/Blocks/utils/createItemMenuCommandExecuter.js +24 -0
- package/dist/runtime/pm/features/Blocks/utils/fixBlockIds.d.ts +4 -0
- package/dist/runtime/pm/features/Blocks/utils/fixBlockIds.js +23 -0
- package/dist/runtime/pm/features/Blocks/utils/isValidId.d.ts +2 -0
- package/dist/runtime/pm/features/Blocks/utils/isValidId.js +7 -0
- package/dist/runtime/pm/features/CodeBlock/CodeBlock.d.ts +16 -0
- package/dist/runtime/pm/features/CodeBlock/CodeBlock.js +91 -0
- package/dist/runtime/pm/features/CodeBlock/build/generateHighlightJsInfo.d.ts +1 -0
- package/dist/runtime/pm/features/CodeBlock/build/generateHighlightJsInfo.js +63 -0
- package/dist/runtime/pm/features/CodeBlock/commands/codeBlockEnterOrSplit.d.ts +9 -0
- package/dist/runtime/pm/features/CodeBlock/commands/codeBlockEnterOrSplit.js +28 -0
- package/dist/runtime/pm/features/CodeBlock/commands/codeBlockIndent.d.ts +9 -0
- package/dist/runtime/pm/features/CodeBlock/commands/codeBlockIndent.js +39 -0
- package/dist/runtime/pm/features/CodeBlock/commands/codeBlockUnindent.d.ts +9 -0
- package/dist/runtime/pm/features/CodeBlock/commands/codeBlockUnindent.js +50 -0
- package/dist/runtime/pm/features/CodeBlock/commands/focusCodeBlockLanguage.d.ts +9 -0
- package/dist/runtime/pm/features/CodeBlock/commands/focusCodeBlockLanguage.js +27 -0
- package/dist/runtime/pm/features/CodeBlock/components/CodeBlockView.d.vue.ts +92 -0
- package/dist/runtime/pm/features/CodeBlock/components/CodeBlockView.vue +112 -0
- package/dist/runtime/pm/features/CodeBlock/components/CodeBlockView.vue.d.ts +92 -0
- package/dist/runtime/pm/features/CodeBlock/composables/useAsyncCodeBlockHighlighting.d.ts +28 -0
- package/dist/runtime/pm/features/CodeBlock/composables/useAsyncCodeBlockHighlighting.js +137 -0
- package/dist/runtime/pm/features/CodeBlock/composables/useHighlightJsTheme.d.ts +37 -0
- package/dist/runtime/pm/features/CodeBlock/composables/useHighlightJsTheme.js +101 -0
- package/dist/runtime/pm/features/CodeBlock/highlightJsInfo.d.ts +17 -0
- package/dist/runtime/pm/features/CodeBlock/highlightJsInfo.js +711 -0
- package/dist/runtime/pm/features/CodeBlock/types.d.ts +4 -0
- package/dist/runtime/pm/features/CodeBlock/types.js +2 -0
- package/dist/runtime/pm/features/Collaboration/Collaboration.d.ts +66 -0
- package/dist/runtime/pm/features/Collaboration/Collaboration.js +169 -0
- package/dist/runtime/pm/features/CommandsMenus/CommandBar.d.ts +19 -0
- package/dist/runtime/pm/features/CommandsMenus/CommandBar.js +97 -0
- package/dist/runtime/pm/features/CommandsMenus/commandBarMenuItems.d.ts +20 -0
- package/dist/runtime/pm/features/CommandsMenus/commandBarMenuItems.js +188 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandBar.d.vue.ts +8 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandBar.vue +58 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandBar.vue.d.ts +8 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandBarItem.d.vue.ts +12 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandBarItem.vue +42 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandBarItem.vue.d.ts +12 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.d.vue.ts +10 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.vue +55 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.vue.d.ts +10 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuItem.d.vue.ts +11 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuItem.vue +58 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuItem.vue.d.ts +11 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuList.d.vue.ts +11 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuList.vue +54 -0
- package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuList.vue.d.ts +11 -0
- package/dist/runtime/pm/features/CommandsMenus/components/TextIcon.d.vue.ts +5 -0
- package/dist/runtime/pm/features/CommandsMenus/components/TextIcon.vue +13 -0
- package/dist/runtime/pm/features/CommandsMenus/components/TextIcon.vue.d.ts +5 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/HighlightIcon.d.vue.ts +8 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/HighlightIcon.vue +45 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/HighlightIcon.vue.d.ts +8 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.d.vue.ts +2 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.vue +5 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.vue.d.ts +2 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.d.vue.ts +2 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.vue +5 -0
- package/dist/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.vue.d.ts +2 -0
- package/dist/runtime/pm/features/CommandsMenus/types.d.ts +61 -0
- package/dist/runtime/pm/features/CommandsMenus/types.js +5 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/defaultCommandExecutor.d.ts +3 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/defaultCommandExecutor.js +11 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/findCommand.d.ts +10 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/findCommand.js +16 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/popupPositionModifier.d.ts +5 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/popupPositionModifier.js +9 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/popupVerticalPositioner.d.ts +5 -0
- package/dist/runtime/pm/features/CommandsMenus/utils/popupVerticalPositioner.js +11 -0
- package/dist/runtime/pm/features/Document/Document.d.ts +3 -0
- package/dist/runtime/pm/features/Document/Document.js +6 -0
- package/dist/runtime/pm/features/DocumentApi/DocumentApi.d.ts +85 -0
- package/dist/runtime/pm/features/DocumentApi/DocumentApi.js +161 -0
- package/dist/runtime/pm/features/DocumentApi/composables/useEditorContent.d.ts +13 -0
- package/dist/runtime/pm/features/DocumentApi/composables/useEditorContent.js +76 -0
- package/dist/runtime/pm/features/DocumentApi/composables/useTestDocumentApi.d.ts +23 -0
- package/dist/runtime/pm/features/DocumentApi/composables/useTestDocumentApi.js +70 -0
- package/dist/runtime/pm/features/DocumentApi/types.d.ts +133 -0
- package/dist/runtime/pm/features/DocumentApi/types.js +1 -0
- package/dist/runtime/pm/features/DocumentApi/utils/convertFullTransactionForPartialState.d.ts +3 -0
- package/dist/runtime/pm/features/DocumentApi/utils/convertFullTransactionForPartialState.js +37 -0
- package/dist/runtime/pm/features/DocumentApi/utils/convertTrForInstance.d.ts +4 -0
- package/dist/runtime/pm/features/DocumentApi/utils/convertTrForInstance.js +13 -0
- package/dist/runtime/pm/features/DocumentApi/utils/convertTransactionForFullState.d.ts +2 -0
- package/dist/runtime/pm/features/DocumentApi/utils/convertTransactionForFullState.js +22 -0
- package/dist/runtime/pm/features/DocumentApi/utils/copyMeta.d.ts +2 -0
- package/dist/runtime/pm/features/DocumentApi/utils/copyMeta.js +6 -0
- package/dist/runtime/pm/features/DocumentApi/utils/getEmbedJson.d.ts +1 -0
- package/dist/runtime/pm/features/DocumentApi/utils/getEmbedJson.js +14 -0
- package/dist/runtime/pm/features/DocumentApi/utils/getEmbedNodeFromDoc.d.ts +1 -0
- package/dist/runtime/pm/features/DocumentApi/utils/getEmbedNodeFromDoc.js +14 -0
- package/dist/runtime/pm/features/DocumentApi/utils/getStateEmbedRange.d.ts +9 -0
- package/dist/runtime/pm/features/DocumentApi/utils/getStateEmbedRange.js +19 -0
- package/dist/runtime/pm/features/DocumentApi/utils/isEmbedId.d.ts +2 -0
- package/dist/runtime/pm/features/DocumentApi/utils/isEmbedId.js +3 -0
- package/dist/runtime/pm/features/EmbeddedDocument/Embedded.d.ts +24 -0
- package/dist/runtime/pm/features/EmbeddedDocument/Embedded.js +73 -0
- package/dist/runtime/pm/features/EmbeddedDocument/EmbeddedDocument.d.ts +23 -0
- package/dist/runtime/pm/features/EmbeddedDocument/EmbeddedDocument.js +70 -0
- package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.d.vue.ts +14 -0
- package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.vue +171 -0
- package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.vue.d.ts +14 -0
- package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.d.vue.ts +92 -0
- package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.vue +172 -0
- package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.vue.d.ts +92 -0
- package/dist/runtime/pm/features/EmbeddedDocument/composables/useEmbeddedEditor.d.ts +31 -0
- package/dist/runtime/pm/features/EmbeddedDocument/composables/useEmbeddedEditor.js +199 -0
- package/dist/runtime/pm/features/EmbeddedDocument/types.d.ts +49 -0
- package/dist/runtime/pm/features/EmbeddedDocument/types.js +6 -0
- package/dist/runtime/pm/features/EmbeddedDocument/utils/isEmbeddedBlock.d.ts +9 -0
- package/dist/runtime/pm/features/EmbeddedDocument/utils/isEmbeddedBlock.js +3 -0
- package/dist/runtime/pm/features/EmbeddedDocument/utils/redirectFromEmbedded.d.ts +28 -0
- package/dist/runtime/pm/features/EmbeddedDocument/utils/redirectFromEmbedded.js +17 -0
- package/dist/runtime/pm/features/FileLoader/FileLoader.d.ts +16 -0
- package/dist/runtime/pm/features/FileLoader/FileLoader.js +99 -0
- package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/FileLoaderHandler.d.ts +28 -0
- package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/FileLoaderHandler.js +69 -0
- package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/TestFileLoaderHandler.d.ts +11 -0
- package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/TestFileLoaderHandler.js +49 -0
- package/dist/runtime/pm/features/FileLoader/commands/insertFile.d.ts +17 -0
- package/dist/runtime/pm/features/FileLoader/commands/insertFile.js +39 -0
- package/dist/runtime/pm/features/FileLoader/components/FileLoaderNodeView.d.vue.ts +92 -0
- package/dist/runtime/pm/features/FileLoader/components/FileLoaderNodeView.vue +38 -0
- package/dist/runtime/pm/features/FileLoader/components/FileLoaderNodeView.vue.d.ts +92 -0
- package/dist/runtime/pm/features/FileLoader/plugins/fileLoaderPlugin.d.ts +5 -0
- package/dist/runtime/pm/features/FileLoader/plugins/fileLoaderPlugin.js +61 -0
- package/dist/runtime/pm/features/FileLoader/types.d.ts +73 -0
- package/dist/runtime/pm/features/FileLoader/types.js +0 -0
- package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNode.d.ts +4 -0
- package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNode.js +27 -0
- package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNodes.d.ts +9 -0
- package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNodes.js +22 -0
- package/dist/runtime/pm/features/FileLoader/utils/findLoadingNodePos.d.ts +2 -0
- package/dist/runtime/pm/features/FileLoader/utils/findLoadingNodePos.js +11 -0
- package/dist/runtime/pm/features/FileLoader/utils/optionsCheck.d.ts +3 -0
- package/dist/runtime/pm/features/FileLoader/utils/optionsCheck.js +8 -0
- package/dist/runtime/pm/features/FileLoader/utils/readAsDataUrl.d.ts +1 -0
- package/dist/runtime/pm/features/FileLoader/utils/readAsDataUrl.js +12 -0
- package/dist/runtime/pm/features/HardBreak/HardBreak.d.ts +5 -0
- package/dist/runtime/pm/features/HardBreak/HardBreak.js +14 -0
- package/dist/runtime/pm/features/Heading/Heading.d.ts +24 -0
- package/dist/runtime/pm/features/Heading/Heading.js +85 -0
- package/dist/runtime/pm/features/Heading/commands/changeLevelAttr.d.ts +16 -0
- package/dist/runtime/pm/features/Heading/commands/changeLevelAttr.js +33 -0
- package/dist/runtime/pm/features/Heading/types.d.ts +14 -0
- package/dist/runtime/pm/features/Heading/types.js +0 -0
- package/dist/runtime/pm/features/Highlight/Highlight.d.ts +72 -0
- package/dist/runtime/pm/features/Highlight/Highlight.js +163 -0
- package/dist/runtime/pm/features/Highlight/retyped/tiptapHighlight.d.ts +3 -0
- package/dist/runtime/pm/features/Highlight/retyped/tiptapHighlight.js +5 -0
- package/dist/runtime/pm/features/Highlight/types.d.ts +27 -0
- package/dist/runtime/pm/features/Highlight/types.js +2 -0
- package/dist/runtime/pm/features/History/History.d.ts +35 -0
- package/dist/runtime/pm/features/History/History.js +63 -0
- package/dist/runtime/pm/features/Iframe/Iframe.d.ts +21 -0
- package/dist/runtime/pm/features/Iframe/Iframe.js +127 -0
- package/dist/runtime/pm/features/Iframe/IframeParsers.d.ts +37 -0
- package/dist/runtime/pm/features/Iframe/IframeParsers.js +88 -0
- package/dist/runtime/pm/features/Iframe/components/IframeNodeView.d.vue.ts +92 -0
- package/dist/runtime/pm/features/Iframe/components/IframeNodeView.vue +82 -0
- package/dist/runtime/pm/features/Iframe/components/IframeNodeView.vue.d.ts +92 -0
- package/dist/runtime/pm/features/Iframe/types.d.ts +5 -0
- package/dist/runtime/pm/features/Iframe/types.js +0 -0
- package/dist/runtime/pm/features/Image/Image.d.ts +2 -0
- package/dist/runtime/pm/features/Image/Image.js +13 -0
- package/dist/runtime/pm/features/Link/Link.d.ts +38 -0
- package/dist/runtime/pm/features/Link/Link.js +241 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuExternalLink.d.vue.ts +28 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuExternalLink.vue +114 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuExternalLink.vue.d.ts +28 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuInternalLink.d.vue.ts +29 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuInternalLink.vue +107 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuInternalLink.vue.d.ts +29 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuLink.d.vue.ts +11 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuLink.vue +126 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuLink.vue.d.ts +11 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuLinkActions.d.vue.ts +18 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuLinkActions.vue +57 -0
- package/dist/runtime/pm/features/Link/components/BubbleMenuLinkActions.vue.d.ts +18 -0
- package/dist/runtime/pm/features/Link/types.d.ts +44 -0
- package/dist/runtime/pm/features/Link/types.js +3 -0
- package/dist/runtime/pm/features/Menus/Menus.d.ts +45 -0
- package/dist/runtime/pm/features/Menus/Menus.js +142 -0
- package/dist/runtime/pm/features/Menus/components/MarkMenuManager.d.vue.ts +6 -0
- package/dist/runtime/pm/features/Menus/components/MarkMenuManager.vue +166 -0
- package/dist/runtime/pm/features/Menus/components/MarkMenuManager.vue.d.ts +6 -0
- package/dist/runtime/pm/features/Menus/types.d.ts +51 -0
- package/dist/runtime/pm/features/Menus/types.js +3 -0
- package/dist/runtime/pm/features/Menus/utils/isMarkMenu.d.ts +2 -0
- package/dist/runtime/pm/features/Menus/utils/isMarkMenu.js +3 -0
- package/dist/runtime/pm/features/Tables/commands/tableEnter.d.ts +15 -0
- package/dist/runtime/pm/features/Tables/commands/tableEnter.js +19 -0
- package/dist/runtime/pm/features/Tables/index.d.ts +9 -0
- package/dist/runtime/pm/features/Tables/index.js +44 -0
- package/dist/runtime/pm/schema.d.ts +4 -0
- package/dist/runtime/pm/schema.js +80 -0
- package/dist/runtime/pm/testSchema.d.ts +5 -0
- package/dist/runtime/pm/testSchema.js +30 -0
- package/dist/runtime/pm/utils/createDropIndicator.d.ts +23 -0
- package/dist/runtime/pm/utils/createDropIndicator.js +32 -0
- package/dist/runtime/pm/utils/createStateOnlyPluginApply.d.ts +2 -0
- package/dist/runtime/pm/utils/createStateOnlyPluginApply.js +9 -0
- package/dist/runtime/pm/utils/createStateOnlyPluginObjApply.d.ts +2 -0
- package/dist/runtime/pm/utils/createStateOnlyPluginObjApply.js +14 -0
- package/dist/runtime/pm/utils/dropPointInfo.d.ts +56 -0
- package/dist/runtime/pm/utils/dropPointInfo.js +28 -0
- package/dist/runtime/pm/utils/findUpwards.d.ts +20 -0
- package/dist/runtime/pm/utils/findUpwards.js +18 -0
- package/dist/runtime/pm/utils/getChildChunks.d.ts +3 -0
- package/dist/runtime/pm/utils/getChildChunks.js +15 -0
- package/dist/runtime/pm/utils/getDiffReplacementRange.d.ts +20 -0
- package/dist/runtime/pm/utils/getDiffReplacementRange.js +9 -0
- package/dist/runtime/pm/utils/getElMaxVisualSize.d.ts +9 -0
- package/dist/runtime/pm/utils/getElMaxVisualSize.js +7 -0
- package/dist/runtime/pm/utils/getElPropertyAsInt.d.ts +1 -0
- package/dist/runtime/pm/utils/getElPropertyAsInt.js +8 -0
- package/dist/runtime/pm/utils/getGroupNodeNames.d.ts +2 -0
- package/dist/runtime/pm/utils/getGroupNodeNames.js +7 -0
- package/dist/runtime/pm/utils/getMarkPosition.d.ts +11 -0
- package/dist/runtime/pm/utils/getMarkPosition.js +34 -0
- package/dist/runtime/pm/utils/getMarksInSelection.d.ts +3 -0
- package/dist/runtime/pm/utils/getMarksInSelection.js +16 -0
- package/dist/runtime/pm/utils/getTypeByName.d.ts +2 -0
- package/dist/runtime/pm/utils/getTypeByName.js +5 -0
- package/dist/runtime/pm/utils/index.d.ts +15 -0
- package/dist/runtime/pm/utils/index.js +15 -0
- package/dist/runtime/pm/utils/internal/createNodeTypesList.d.ts +2 -0
- package/dist/runtime/pm/utils/internal/createNodeTypesList.js +17 -0
- package/dist/runtime/pm/utils/internal/debugMap.d.ts +7 -0
- package/dist/runtime/pm/utils/internal/debugMap.js +24 -0
- package/dist/runtime/pm/utils/internal/debugNode.d.ts +2 -0
- package/dist/runtime/pm/utils/internal/debugNode.js +18 -0
- package/dist/runtime/pm/utils/internal/debugSel.d.ts +5 -0
- package/dist/runtime/pm/utils/internal/debugSel.js +8 -0
- package/dist/runtime/pm/utils/internal/recurse.d.ts +2 -0
- package/dist/runtime/pm/utils/internal/recurse.js +39 -0
- package/dist/runtime/pm/utils/internal/stripBlockId.d.ts +2 -0
- package/dist/runtime/pm/utils/internal/stripBlockId.js +9 -0
- package/dist/runtime/pm/utils/mapSelection.d.ts +8 -0
- package/dist/runtime/pm/utils/mapSelection.js +12 -0
- package/dist/runtime/pm/utils/nodesBetween.d.ts +21 -0
- package/dist/runtime/pm/utils/nodesBetween.js +21 -0
- package/dist/runtime/pm/utils/pointToPmPoint.d.ts +2 -0
- package/dist/runtime/pm/utils/pointToPmPoint.js +3 -0
- package/dist/runtime/pm/utils/splitIntoChunks.d.ts +32 -0
- package/dist/runtime/pm/utils/splitIntoChunks.js +31 -0
- package/dist/runtime/testDocuments.d.ts +53 -0
- package/dist/runtime/testDocuments.js +122 -0
- package/dist/runtime/types/index.d.ts +53 -0
- package/dist/runtime/types/index.js +9 -0
- package/dist/types.d.mts +3 -0
- package/package.json +238 -0
- package/src/module.ts +101 -0
- package/src/runtime/assets/base.css +83 -0
- package/src/runtime/assets/handle-arrow.svg +16 -0
- package/src/runtime/assets/handle-border-circles-single.svg +44 -0
- package/src/runtime/assets/handle-border-circles.svg +27 -0
- package/src/runtime/assets/handle-temp.svg +1 -0
- package/src/runtime/assets/utils.css +9 -0
- package/src/runtime/components/CodeBlockThemePicker.vue +125 -0
- package/src/runtime/components/Commands.vue +67 -0
- package/src/runtime/components/Editor.vue +330 -0
- package/src/runtime/components/EditorDemoApp.vue +118 -0
- package/src/runtime/components/EditorDemoControls.vue +38 -0
- package/src/runtime/components/TestWrapper.vue +74 -0
- package/src/runtime/composables/useEditor.ts +29 -0
- package/src/runtime/composables/useWindowDebugging.ts +20 -0
- package/src/runtime/demo/App.vue +114 -0
- package/src/runtime/demo/README.md +1 -0
- package/src/runtime/demo/main.ts +8 -0
- package/src/runtime/demo/tailwind.css +4 -0
- package/src/runtime/env.d.ts +2 -0
- package/src/runtime/injectionKeys.ts +10 -0
- package/src/runtime/main.lib.ts +2 -0
- package/src/runtime/pm/commands/backspace.ts +44 -0
- package/src/runtime/pm/commands/changeAttrs.ts +37 -0
- package/src/runtime/pm/commands/deleteSelection.ts +22 -0
- package/src/runtime/pm/commands/enter.ts +27 -0
- package/src/runtime/pm/commands/insertBreak.ts +40 -0
- package/src/runtime/pm/features/Base/Base.ts +39 -0
- package/src/runtime/pm/features/Base/commands/deleteNodes.ts +54 -0
- package/src/runtime/pm/features/Base/commands/setCursorVisible.ts +24 -0
- package/src/runtime/pm/features/Base/plugins/debugSelectionPlugin.ts +57 -0
- package/src/runtime/pm/features/Base/plugins/isCursorVisiblePlugin.ts +28 -0
- package/src/runtime/pm/features/Base/plugins/isUsingTouchPlugin.ts +40 -0
- package/src/runtime/pm/features/Base/plugins/selectingIndicator.ts +38 -0
- package/src/runtime/pm/features/Base/plugins/unfocusedSelectionIndicatorPlugin.ts +107 -0
- package/src/runtime/pm/features/Base/types.ts +3 -0
- package/src/runtime/pm/features/BaseShortcuts/BaseShortcuts.ts +39 -0
- package/src/runtime/pm/features/Blockquote/Blockquote.ts +75 -0
- package/src/runtime/pm/features/Blockquote/commands/blockquoteEnter.ts +51 -0
- package/src/runtime/pm/features/Blockquote/commands/blockquoteShiftEnter.ts +26 -0
- package/src/runtime/pm/features/Blocks/Blocks.ts +3 -0
- package/src/runtime/pm/features/Blocks/Item.ts +176 -0
- package/src/runtime/pm/features/Blocks/List.ts +67 -0
- package/src/runtime/pm/features/Blocks/commands/changeItemType.ts +64 -0
- package/src/runtime/pm/features/Blocks/commands/changeTypeAttr.ts +47 -0
- package/src/runtime/pm/features/Blocks/commands/copyOrMoveItem.ts +179 -0
- package/src/runtime/pm/features/Blocks/commands/deleteItem.ts +24 -0
- package/src/runtime/pm/features/Blocks/commands/indentItem.ts +105 -0
- package/src/runtime/pm/features/Blocks/commands/itemMenuCommands.ts +62 -0
- package/src/runtime/pm/features/Blocks/commands/moveItem.ts +128 -0
- package/src/runtime/pm/features/Blocks/commands/setNode.ts +186 -0
- package/src/runtime/pm/features/Blocks/commands/splitItem.ts +116 -0
- package/src/runtime/pm/features/Blocks/commands/unindentItem.ts +82 -0
- package/src/runtime/pm/features/Blocks/components/DragTreeHandle.vue +142 -0
- package/src/runtime/pm/features/Blocks/components/ItemMenu.vue +88 -0
- package/src/runtime/pm/features/Blocks/components/ItemNodeView.vue +394 -0
- package/src/runtime/pm/features/Blocks/components/defaultItemMenu.ts +45 -0
- package/src/runtime/pm/features/Blocks/composables/useDragWithThreshold.ts +0 -0
- package/src/runtime/pm/features/Blocks/composables/useHandleHeight.ts +28 -0
- package/src/runtime/pm/features/Blocks/composables/useHasChildren.ts +14 -0
- package/src/runtime/pm/features/Blocks/composables/useNodeStates.ts +29 -0
- package/src/runtime/pm/features/Blocks/itemMenuMenuItems.ts +143 -0
- package/src/runtime/pm/features/Blocks/plugins/ensureLastItemIsContentPlugin.ts +52 -0
- package/src/runtime/pm/features/Blocks/plugins/itemBlockIdPlugin.ts +40 -0
- package/src/runtime/pm/features/Blocks/plugins/itemHasSingularSelectionPlugin.ts +32 -0
- package/src/runtime/pm/features/Blocks/plugins/itemMenuPlugin.ts +21 -0
- package/src/runtime/pm/features/Blocks/states/stateful.ts +41 -0
- package/src/runtime/pm/features/Blocks/states/task/cancelled.svg +32 -0
- package/src/runtime/pm/features/Blocks/states/task/checked.svg +27 -0
- package/src/runtime/pm/features/Blocks/states/task/checked2.svg +24 -0
- package/src/runtime/pm/features/Blocks/states/task/partial.svg +24 -0
- package/src/runtime/pm/features/Blocks/states/task/partial2.svg +31 -0
- package/src/runtime/pm/features/Blocks/states/task/unchecked.svg +20 -0
- package/src/runtime/pm/features/Blocks/types.ts +51 -0
- package/src/runtime/pm/features/Blocks/utils/createItemMenuCommandExecuter.ts +47 -0
- package/src/runtime/pm/features/Blocks/utils/fixBlockIds.ts +28 -0
- package/src/runtime/pm/features/Blocks/utils/isValidId.ts +8 -0
- package/src/runtime/pm/features/CodeBlock/CodeBlock.ts +104 -0
- package/src/runtime/pm/features/CodeBlock/build/generateHighlightJsInfo.js +63 -0
- package/src/runtime/pm/features/CodeBlock/commands/codeBlockEnterOrSplit.ts +55 -0
- package/src/runtime/pm/features/CodeBlock/commands/codeBlockIndent.ts +67 -0
- package/src/runtime/pm/features/CodeBlock/commands/codeBlockUnindent.ts +74 -0
- package/src/runtime/pm/features/CodeBlock/commands/focusCodeBlockLanguage.ts +44 -0
- package/src/runtime/pm/features/CodeBlock/components/CodeBlockView.vue +126 -0
- package/src/runtime/pm/features/CodeBlock/composables/useAsyncCodeBlockHighlighting.ts +185 -0
- package/src/runtime/pm/features/CodeBlock/composables/useHighlightJsTheme.ts +150 -0
- package/src/runtime/pm/features/CodeBlock/highlightJsInfo.ts +733 -0
- package/src/runtime/pm/features/CodeBlock/types.ts +7 -0
- package/src/runtime/pm/features/Collaboration/Collaboration.ts +295 -0
- package/src/runtime/pm/features/CommandsMenus/CommandBar.ts +130 -0
- package/src/runtime/pm/features/CommandsMenus/commandBarMenuItems.ts +209 -0
- package/src/runtime/pm/features/CommandsMenus/components/CommandBar.vue +63 -0
- package/src/runtime/pm/features/CommandsMenus/components/CommandBarItem.vue +48 -0
- package/src/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.vue +59 -0
- package/src/runtime/pm/features/CommandsMenus/components/CommandMenuItem.vue +67 -0
- package/src/runtime/pm/features/CommandsMenus/components/CommandMenuList.vue +60 -0
- package/src/runtime/pm/features/CommandsMenus/components/TextIcon.vue +14 -0
- package/src/runtime/pm/features/CommandsMenus/icons/HighlightIcon.vue +51 -0
- package/src/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.vue +5 -0
- package/src/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.vue +5 -0
- package/src/runtime/pm/features/CommandsMenus/types.ts +73 -0
- package/src/runtime/pm/features/CommandsMenus/utils/defaultCommandExecutor.ts +22 -0
- package/src/runtime/pm/features/CommandsMenus/utils/findCommand.ts +37 -0
- package/src/runtime/pm/features/CommandsMenus/utils/popupPositionModifier.ts +14 -0
- package/src/runtime/pm/features/CommandsMenus/utils/popupVerticalPositioner.ts +16 -0
- package/src/runtime/pm/features/Document/Document.ts +9 -0
- package/src/runtime/pm/features/DocumentApi/DocumentApi.ts +272 -0
- package/src/runtime/pm/features/DocumentApi/composables/useEditorContent.ts +105 -0
- package/src/runtime/pm/features/DocumentApi/composables/useTestDocumentApi.ts +95 -0
- package/src/runtime/pm/features/DocumentApi/types.ts +143 -0
- package/src/runtime/pm/features/DocumentApi/utils/convertFullTransactionForPartialState.ts +54 -0
- package/src/runtime/pm/features/DocumentApi/utils/convertTrForInstance.ts +24 -0
- package/src/runtime/pm/features/DocumentApi/utils/convertTransactionForFullState.ts +39 -0
- package/src/runtime/pm/features/DocumentApi/utils/copyMeta.ts +8 -0
- package/src/runtime/pm/features/DocumentApi/utils/getEmbedJson.ts +16 -0
- package/src/runtime/pm/features/DocumentApi/utils/getEmbedNodeFromDoc.ts +15 -0
- package/src/runtime/pm/features/DocumentApi/utils/getStateEmbedRange.ts +26 -0
- package/src/runtime/pm/features/DocumentApi/utils/isEmbedId.ts +5 -0
- package/src/runtime/pm/features/EmbeddedDocument/Embedded.ts +110 -0
- package/src/runtime/pm/features/EmbeddedDocument/EmbeddedDocument.ts +102 -0
- package/src/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.vue +188 -0
- package/src/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.vue +187 -0
- package/src/runtime/pm/features/EmbeddedDocument/composables/useEmbeddedEditor.ts +302 -0
- package/src/runtime/pm/features/EmbeddedDocument/types.ts +61 -0
- package/src/runtime/pm/features/EmbeddedDocument/utils/isEmbeddedBlock.ts +12 -0
- package/src/runtime/pm/features/EmbeddedDocument/utils/redirectFromEmbedded.ts +48 -0
- package/src/runtime/pm/features/FileLoader/FileLoader.ts +120 -0
- package/src/runtime/pm/features/FileLoader/FileLoaderHandler/FileLoaderHandler.ts +100 -0
- package/src/runtime/pm/features/FileLoader/FileLoaderHandler/TestFileLoaderHandler.ts +61 -0
- package/src/runtime/pm/features/FileLoader/commands/insertFile.ts +87 -0
- package/src/runtime/pm/features/FileLoader/components/FileLoaderNodeView.vue +38 -0
- package/src/runtime/pm/features/FileLoader/plugins/fileLoaderPlugin.ts +70 -0
- package/src/runtime/pm/features/FileLoader/types.ts +91 -0
- package/src/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNode.ts +39 -0
- package/src/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNodes.ts +42 -0
- package/src/runtime/pm/features/FileLoader/utils/findLoadingNodePos.ts +16 -0
- package/src/runtime/pm/features/FileLoader/utils/optionsCheck.ts +16 -0
- package/src/runtime/pm/features/FileLoader/utils/readAsDataUrl.ts +12 -0
- package/src/runtime/pm/features/HardBreak/HardBreak.ts +21 -0
- package/src/runtime/pm/features/Heading/Heading.ts +130 -0
- package/src/runtime/pm/features/Heading/commands/changeLevelAttr.ts +55 -0
- package/src/runtime/pm/features/Heading/types.ts +17 -0
- package/src/runtime/pm/features/Highlight/Highlight.ts +234 -0
- package/src/runtime/pm/features/Highlight/retyped/tiptapHighlight.d.ts +3 -0
- package/src/runtime/pm/features/Highlight/retyped/tiptapHighlight.js +5 -0
- package/src/runtime/pm/features/Highlight/types.ts +25 -0
- package/src/runtime/pm/features/History/History.ts +112 -0
- package/src/runtime/pm/features/Iframe/Iframe.ts +163 -0
- package/src/runtime/pm/features/Iframe/IframeParsers.ts +116 -0
- package/src/runtime/pm/features/Iframe/components/IframeNodeView.vue +83 -0
- package/src/runtime/pm/features/Iframe/types.ts +7 -0
- package/src/runtime/pm/features/Image/Image.ts +16 -0
- package/src/runtime/pm/features/Link/Link.ts +313 -0
- package/src/runtime/pm/features/Link/components/BubbleMenuExternalLink.vue +125 -0
- package/src/runtime/pm/features/Link/components/BubbleMenuInternalLink.vue +130 -0
- package/src/runtime/pm/features/Link/components/BubbleMenuLink.vue +149 -0
- package/src/runtime/pm/features/Link/components/BubbleMenuLinkActions.vue +65 -0
- package/src/runtime/pm/features/Link/types.ts +53 -0
- package/src/runtime/pm/features/Menus/Menus.ts +195 -0
- package/src/runtime/pm/features/Menus/components/MarkMenuManager.vue +203 -0
- package/src/runtime/pm/features/Menus/types.ts +64 -0
- package/src/runtime/pm/features/Menus/utils/isMarkMenu.ts +5 -0
- package/src/runtime/pm/features/Tables/commands/tableEnter.ts +40 -0
- package/src/runtime/pm/features/Tables/index.ts +60 -0
- package/src/runtime/pm/schema.ts +128 -0
- package/src/runtime/pm/testSchema.ts +34 -0
- package/src/runtime/pm/utils/createDropIndicator.ts +61 -0
- package/src/runtime/pm/utils/createStateOnlyPluginApply.ts +11 -0
- package/src/runtime/pm/utils/createStateOnlyPluginObjApply.ts +16 -0
- package/src/runtime/pm/utils/dropPointInfo.ts +85 -0
- package/src/runtime/pm/utils/findUpwards.ts +43 -0
- package/src/runtime/pm/utils/getChildChunks.ts +24 -0
- package/src/runtime/pm/utils/getDiffReplacementRange.ts +32 -0
- package/src/runtime/pm/utils/getElMaxVisualSize.ts +14 -0
- package/src/runtime/pm/utils/getElPropertyAsInt.ts +8 -0
- package/src/runtime/pm/utils/getGroupNodeNames.ts +9 -0
- package/src/runtime/pm/utils/getMarkPosition.ts +57 -0
- package/src/runtime/pm/utils/getMarksInSelection.ts +19 -0
- package/src/runtime/pm/utils/getTypeByName.ts +7 -0
- package/src/runtime/pm/utils/index.ts +17 -0
- package/src/runtime/pm/utils/internal/createNodeTypesList.ts +25 -0
- package/src/runtime/pm/utils/internal/debugMap.ts +36 -0
- package/src/runtime/pm/utils/internal/debugNode.ts +38 -0
- package/src/runtime/pm/utils/internal/debugSel.ts +10 -0
- package/src/runtime/pm/utils/internal/recurse.ts +44 -0
- package/src/runtime/pm/utils/internal/stripBlockId.ts +10 -0
- package/src/runtime/pm/utils/mapSelection.ts +21 -0
- package/src/runtime/pm/utils/nodesBetween.ts +47 -0
- package/src/runtime/pm/utils/pointToPmPoint.ts +5 -0
- package/src/runtime/pm/utils/splitIntoChunks.ts +68 -0
- package/src/runtime/testDocuments.ts +130 -0
- package/src/runtime/types/index.ts +56 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { debounce, type DebounceQueue } from "@alanscodelog/utils/debounce"
|
|
2
|
+
import { unreachable } from "@alanscodelog/utils/unreachable"
|
|
3
|
+
import { type Content, Editor, type EditorOptions } from "@tiptap/core"
|
|
4
|
+
import type { Schema } from "@tiptap/pm/model"
|
|
5
|
+
import type { EditorState, Plugin, Transaction } from "@tiptap/pm/state"
|
|
6
|
+
import { toRaw } from "vue"
|
|
7
|
+
|
|
8
|
+
import type { DocId, DocumentApiInterface, EmbedId, OnSaveDocumentCallback, OnUpdateDocumentCallback } from "./types.js"
|
|
9
|
+
import { convertTransactionForFullState } from "./utils/convertTransactionForFullState.js"
|
|
10
|
+
import { getEmbedJson } from "./utils/getEmbedJson.js"
|
|
11
|
+
import { getEmbedNodeFromDoc } from "./utils/getEmbedNodeFromDoc.js"
|
|
12
|
+
|
|
13
|
+
// IMPORTANT: We must be super careful to unwrap the state proxy with toRaw before passing it to anything or it can create painful to debug errors.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Configures the document api which tells the editor how to load/unload/save/cache documents, including embedded ones.
|
|
17
|
+
*
|
|
18
|
+
* The cache implementation is left up to the user, hence why it's defined as a get/set interface. A load function must be provided for requesting uncached documents.
|
|
19
|
+
*
|
|
20
|
+
* `save` is optional, but you probably want to save. The function is automatically debounced the configured amount.
|
|
21
|
+
*
|
|
22
|
+
* **Any function that needs to return a document should return it unwrapped with toRaw if it was a ref or in a ref or reactive. **
|
|
23
|
+
*
|
|
24
|
+
* A `refCounter` object can be provided with the respective load/unload functions to be notified when embedded views load/unload documents to reference count them and unload them once no editors have them in use.
|
|
25
|
+
*
|
|
26
|
+
* It is safe to call load multiple times for the same document, the actual load function will only be called once per document, but the refCounter will be called multiple times.
|
|
27
|
+
*
|
|
28
|
+
* The `getTitle` function can be provided to customize the title of the embedded document. It's passed the full embed id and returns it as docId#blockId by default.
|
|
29
|
+
*
|
|
30
|
+
* If there are extensions that use onCreate to set state or have plugins that need to change the state on init with appendTransaction, they will not work since there is no view to initialize the plugins. To get around this, plugins can specify a stateInit function that will be called with a transaction from the initial loaded state which it can then modify while having access to `this` and the extension options.
|
|
31
|
+
*
|
|
32
|
+
* The api creates a default instance of the editor to copy plugins from, this can be replaced by passing your own editor instance.
|
|
33
|
+
*
|
|
34
|
+
* See {@link useTestDocumentApi} for an example of how to set things up.
|
|
35
|
+
*/
|
|
36
|
+
export class DocumentApi<
|
|
37
|
+
T extends Record<string, any> = Record<string, any>
|
|
38
|
+
> implements DocumentApiInterface<T> {
|
|
39
|
+
private readonly _callbacks: {
|
|
40
|
+
update: OnUpdateDocumentCallback[]
|
|
41
|
+
saved: OnSaveDocumentCallback[]
|
|
42
|
+
saving: OnSaveDocumentCallback[]
|
|
43
|
+
} = { update: [], saved: [], saving: [] }
|
|
44
|
+
|
|
45
|
+
private readonly _load: (docId: string, schema: Schema, plugins: Plugin[]) => Promise<{ state: EditorState, data?: T }>
|
|
46
|
+
|
|
47
|
+
private readonly _save?: (docId: string) => Promise<void>
|
|
48
|
+
|
|
49
|
+
private readonly _saveQueue: DebounceQueue = {}
|
|
50
|
+
|
|
51
|
+
readonly save: DocumentApiInterface<T>["save"]
|
|
52
|
+
|
|
53
|
+
private readonly _cache: {
|
|
54
|
+
get: (docId: string) => EditorState | undefined
|
|
55
|
+
set: (docId: string, state: EditorState) => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The refCounter is called every time an editor loads or unloads a document. It's used to keep track of the number of editors that are using a document, and to unload it when no editors are using it.
|
|
60
|
+
*
|
|
61
|
+
* Note that you need not immediately unload the cached document. So long as the count is immediatly updated you can set a timeout to actually delete the cache entry (be sure to check the count it still 0 and you can delete it).
|
|
62
|
+
*/
|
|
63
|
+
private readonly _refCounter: {
|
|
64
|
+
load: (docId: string, loaded: { state: EditorState, data?: T }) => void
|
|
65
|
+
unload: (docId: string) => void
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getSuggestions: DocumentApiInterface["getSuggestions"]
|
|
69
|
+
|
|
70
|
+
getEmbedTitle: DocumentApiInterface["getEmbedTitle"]
|
|
71
|
+
|
|
72
|
+
postEditorInit: DocumentApiInterface["postEditorInit"]
|
|
73
|
+
|
|
74
|
+
// editor + updateState does not work :/
|
|
75
|
+
preEditorInit: DocumentApiInterface["preEditorInit"] = (_docId, options, state) => {
|
|
76
|
+
options.content = state.doc.toJSON()
|
|
77
|
+
return options
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
updateFilter?: DocumentApiInterface["updateFilter"] = () => true
|
|
81
|
+
|
|
82
|
+
editor: Editor
|
|
83
|
+
|
|
84
|
+
constructor({
|
|
85
|
+
editorOptions,
|
|
86
|
+
getTitle,
|
|
87
|
+
getSuggestions,
|
|
88
|
+
load,
|
|
89
|
+
save,
|
|
90
|
+
saveDebounce = 1000,
|
|
91
|
+
cache,
|
|
92
|
+
refCounter,
|
|
93
|
+
postEditorInit,
|
|
94
|
+
preEditorInit,
|
|
95
|
+
updateFilter
|
|
96
|
+
}: {
|
|
97
|
+
/**
|
|
98
|
+
* The editor options for the internal instance to use to keep track of the document state. It should include the same extensions as the root editor.
|
|
99
|
+
*/
|
|
100
|
+
editorOptions: Partial<EditorOptions>
|
|
101
|
+
getTitle?: (docId: string, blockId?: string) => string
|
|
102
|
+
getSuggestions: DocumentApiInterface["getSuggestions"]
|
|
103
|
+
load: (docId: string, schema: Schema, plugins: Plugin[]) => Promise<{ state: EditorState, data?: T }>
|
|
104
|
+
save?: DocumentApi["_save"]
|
|
105
|
+
saveDebounce?: number
|
|
106
|
+
cache: DocumentApi["_cache"]
|
|
107
|
+
refCounter: DocumentApi<T>["_refCounter"]
|
|
108
|
+
postEditorInit?: DocumentApi["postEditorInit"]
|
|
109
|
+
preEditorInit?: DocumentApi["preEditorInit"]
|
|
110
|
+
updateFilter?: DocumentApi["updateFilter"]
|
|
111
|
+
}) {
|
|
112
|
+
this.updateFilter = updateFilter
|
|
113
|
+
this.getEmbedTitle = getTitle
|
|
114
|
+
? ({ docId, blockId }: EmbedId) => getTitle(docId, blockId)
|
|
115
|
+
: ({ docId, blockId }: EmbedId) => `${docId}${blockId ? `#${blockId}` : ""}`
|
|
116
|
+
this._load = load
|
|
117
|
+
this._cache = cache
|
|
118
|
+
this._refCounter = refCounter
|
|
119
|
+
this._save = save
|
|
120
|
+
const debouncedSave = debounce(this._saveDocument.bind(this), saveDebounce, {
|
|
121
|
+
queue: this._saveQueue,
|
|
122
|
+
// even though save is async, promisified debounce is slightly more expensive because it creates a new function with every call
|
|
123
|
+
// and we don't really need that
|
|
124
|
+
promisify: false
|
|
125
|
+
}) as any
|
|
126
|
+
|
|
127
|
+
this.save = function save(docId: string): void {
|
|
128
|
+
for (const cb of this._callbacks.saving) {
|
|
129
|
+
cb(docId)
|
|
130
|
+
}
|
|
131
|
+
debouncedSave(docId)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.postEditorInit = postEditorInit ?? (() => {})
|
|
135
|
+
if (preEditorInit) this.preEditorInit = preEditorInit
|
|
136
|
+
this.getSuggestions = getSuggestions
|
|
137
|
+
this.editor = new Editor({
|
|
138
|
+
...editorOptions,
|
|
139
|
+
extensions: [...editorOptions.extensions!],
|
|
140
|
+
injectCSS: false
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
145
|
+
async _saveDocument(docId: string): Promise<void> {
|
|
146
|
+
if (this._save) {
|
|
147
|
+
await this._save(docId)
|
|
148
|
+
for (const cb of this._callbacks.saved) {
|
|
149
|
+
cb(docId)
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
// eslint-disable-next-line no-console
|
|
153
|
+
console.warn("No save function provided, ignoring save request.")
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
updateDocument(
|
|
158
|
+
embedId: DocId,
|
|
159
|
+
tr: Transaction,
|
|
160
|
+
updaterSymbol?: symbol
|
|
161
|
+
): void {
|
|
162
|
+
if (this.updateFilter && this.updateFilter(tr) === false) return
|
|
163
|
+
const stateBefore = this.getFromCache(embedId, { errorIfNotFound: true })
|
|
164
|
+
const modifiedTr = convertTransactionForFullState(stateBefore, tr)
|
|
165
|
+
const newState = stateBefore.apply(modifiedTr)
|
|
166
|
+
this._cache.set(embedId.docId, newState)
|
|
167
|
+
for (const cb of this._callbacks.update) {
|
|
168
|
+
cb(embedId, modifiedTr, toRaw(stateBefore), toRaw(newState), updaterSymbol)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
addEventListener(type: "saving" | "saved", cb: OnSaveDocumentCallback): void
|
|
173
|
+
|
|
174
|
+
addEventListener(type: "update", cb: OnUpdateDocumentCallback): void
|
|
175
|
+
|
|
176
|
+
addEventListener(
|
|
177
|
+
type: "update" | "saving" | "saved",
|
|
178
|
+
cb: OnUpdateDocumentCallback | OnSaveDocumentCallback
|
|
179
|
+
): void {
|
|
180
|
+
this._callbacks[type].push(cb as any)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
removeEventListener(type: "saving" | "saved", cb: OnSaveDocumentCallback): void
|
|
184
|
+
|
|
185
|
+
removeEventListener(type: "update", cb: OnUpdateDocumentCallback): void
|
|
186
|
+
|
|
187
|
+
removeEventListener(
|
|
188
|
+
type: "update" | "saving" | "saved",
|
|
189
|
+
cb: OnUpdateDocumentCallback | OnSaveDocumentCallback
|
|
190
|
+
): void {
|
|
191
|
+
const cbIndex = this._callbacks[type].indexOf(cb as any)
|
|
192
|
+
if (cbIndex === -1) {
|
|
193
|
+
throw new Error("Tried to remove a callback that was not registered.")
|
|
194
|
+
}
|
|
195
|
+
this._callbacks[type].splice(cbIndex, 1)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
unload({ docId }: DocId): void {
|
|
199
|
+
this._refCounter.unload(docId)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private readonly _loading: Record<string, Promise<{ state: EditorState, data?: T }> | undefined> = {}
|
|
203
|
+
|
|
204
|
+
async load({ docId }: DocId): Promise<{ state: EditorState, data?: T }> {
|
|
205
|
+
// prevent double loading of the same document
|
|
206
|
+
// this also prevents issues from non-determenistic plugin stateInit functions
|
|
207
|
+
this._loading[docId] ??= this._loadInternal({ docId })
|
|
208
|
+
|
|
209
|
+
const res = await this._loading[docId]
|
|
210
|
+
if (res === undefined) unreachable()
|
|
211
|
+
this._loading[docId] = undefined
|
|
212
|
+
this._refCounter.load(docId, res)
|
|
213
|
+
this._cache.set(docId, res.state)
|
|
214
|
+
return res
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private async _loadInternal({ docId }: DocId): Promise<{ state: EditorState, data?: T }> {
|
|
218
|
+
const cachedState = this.getFromCache({ docId }, { errorIfNotFound: false })
|
|
219
|
+
if (cachedState) {
|
|
220
|
+
const res = { state: cachedState }
|
|
221
|
+
this._refCounter.load(docId, res)
|
|
222
|
+
return res
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const schema = this.editor.schema
|
|
226
|
+
const loaded = await this._load(
|
|
227
|
+
docId,
|
|
228
|
+
schema,
|
|
229
|
+
[...this.editor.extensionManager.plugins]
|
|
230
|
+
)
|
|
231
|
+
let state = loaded.state
|
|
232
|
+
const tr = state.tr
|
|
233
|
+
|
|
234
|
+
tr.setMeta("addToHistory", false)
|
|
235
|
+
for (const plugin of state.plugins) {
|
|
236
|
+
if (plugin.spec.stateInit) {
|
|
237
|
+
plugin.spec.stateInit(tr)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
state = state.apply(tr)
|
|
242
|
+
return { data: loaded.data, state }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getFullState(docId: DocId): EditorState {
|
|
246
|
+
return this.getFromCache(docId, { errorIfNotFound: true })
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
getFromCache(docId: DocId, options?: { errorIfNotFound: true }): EditorState
|
|
250
|
+
|
|
251
|
+
getFromCache(docId: DocId, options?: { errorIfNotFound?: boolean }): EditorState | undefined
|
|
252
|
+
|
|
253
|
+
getFromCache({ docId }: DocId, options?: { errorIfNotFound?: boolean }): EditorState | undefined {
|
|
254
|
+
const cached = this._cache.get(docId)
|
|
255
|
+
if (cached) return cached
|
|
256
|
+
if (options?.errorIfNotFound) {
|
|
257
|
+
throw new Error(`Could not find cached state for document ${docId}. Expected document to be loaded.`)
|
|
258
|
+
}
|
|
259
|
+
return undefined
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
getEmbeddedContent(embedId: EmbedId): Content | undefined {
|
|
263
|
+
const state = this.getFullState(embedId)
|
|
264
|
+
const json = state.doc.toJSON()
|
|
265
|
+
const nodeWanted = getEmbedNodeFromDoc(json, embedId.blockId)
|
|
266
|
+
if (embedId.blockId && !nodeWanted) {
|
|
267
|
+
return undefined
|
|
268
|
+
} else {
|
|
269
|
+
return getEmbedJson(nodeWanted) ?? json
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Content, Editor, EditorOptions } from "@tiptap/core"
|
|
2
|
+
import type { Transaction } from "@tiptap/pm/state"
|
|
3
|
+
import { nextTick, onBeforeUnmount, type Ref, watch } from "vue"
|
|
4
|
+
|
|
5
|
+
import type { DocumentApiInterface, OnUpdateDocumentCallback } from "../types.js"
|
|
6
|
+
import { convertTrForInstance } from "../utils/convertTrForInstance.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provides two ways to load content into the editor.
|
|
10
|
+
*
|
|
11
|
+
* The simple one, which is just to provide a content ref.
|
|
12
|
+
*
|
|
13
|
+
* And the more advanced one which uses the document api to load the content. This requires passing the embed api and an id to load.
|
|
14
|
+
*
|
|
15
|
+
* The second option is usually the best, as multiple editors can load the same content and it's automatically kept in sync. See {@link DocumentApi} for more info.
|
|
16
|
+
*/
|
|
17
|
+
export function useEditorContent(
|
|
18
|
+
editor: Ref<Editor | undefined>,
|
|
19
|
+
content: Ref<Content | undefined>,
|
|
20
|
+
id: Ref<string | undefined>,
|
|
21
|
+
documentApi: DocumentApiInterface | undefined,
|
|
22
|
+
recreate: (modifyOptions?: (options: Partial<EditorOptions>) => Partial<EditorOptions>) => void
|
|
23
|
+
): void {
|
|
24
|
+
const selfSymbol = Symbol(`self${Math.random()}`)
|
|
25
|
+
function onTransaction({ transaction: tr }: { transaction: Transaction }): void {
|
|
26
|
+
if (!documentApi || !id.value || !tr.docChanged || tr.getMeta("ignore")) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
tr.setMeta("no-step-convert", true)
|
|
30
|
+
documentApi.updateDocument({ docId: id.value }, tr, selfSymbol)
|
|
31
|
+
}
|
|
32
|
+
const onUpdateDocument: OnUpdateDocumentCallback = (embedId, tr, __, ___, symbol) => {
|
|
33
|
+
if (symbol !== selfSymbol
|
|
34
|
+
&& !tr.getMeta("ignore")
|
|
35
|
+
&& tr.docChanged
|
|
36
|
+
&& embedId.docId === id.value
|
|
37
|
+
) {
|
|
38
|
+
tr.setMeta("ignore", true)
|
|
39
|
+
const convertedTr = convertTrForInstance(
|
|
40
|
+
tr,
|
|
41
|
+
editor.value!.state
|
|
42
|
+
)
|
|
43
|
+
editor.value?.view.dispatch(convertedTr)
|
|
44
|
+
}
|
|
45
|
+
if (tr.docChanged) {
|
|
46
|
+
void documentApi?.save(embedId.docId)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let attached = false
|
|
50
|
+
|
|
51
|
+
async function load(changed: boolean): Promise<void> {
|
|
52
|
+
if (content.value) {
|
|
53
|
+
editor.value?.commands.setContent(content.value)
|
|
54
|
+
} else if (documentApi) {
|
|
55
|
+
if (changed && id.value) {
|
|
56
|
+
await documentApi.load({ docId: id.value })
|
|
57
|
+
const state = documentApi.getFullState({ docId: id.value })
|
|
58
|
+
|
|
59
|
+
recreate(options => documentApi.preEditorInit?.(id.value!, { ...options }, state))
|
|
60
|
+
await nextTick(async () => {
|
|
61
|
+
editor.value!.on("transaction", onTransaction)
|
|
62
|
+
documentApi!.addEventListener("update", onUpdateDocument)
|
|
63
|
+
documentApi.postEditorInit(id.value!, editor.value!)
|
|
64
|
+
attached = true
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function unload(oldId: string): void {
|
|
70
|
+
if (oldId !== undefined && documentApi) {
|
|
71
|
+
documentApi.unload({ docId: oldId })
|
|
72
|
+
if (attached) {
|
|
73
|
+
documentApi.removeEventListener("update", onUpdateDocument)
|
|
74
|
+
editor.value?.off("transaction", onTransaction)
|
|
75
|
+
attached = false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
watch([content, id, editor], async ([_newContent, newId], [_oldContent, oldId]) => {
|
|
81
|
+
if (!editor.value) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
if (!content.value && (!id.value || !documentApi)) {
|
|
85
|
+
throw new Error("No content or id and document api provided.")
|
|
86
|
+
}
|
|
87
|
+
if (id.value && !documentApi) {
|
|
88
|
+
throw new Error("Id provided but no document api provided.")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (oldId !== undefined && newId !== oldId && documentApi) {
|
|
92
|
+
unload(oldId)
|
|
93
|
+
await load(true)
|
|
94
|
+
} else if (_newContent) {
|
|
95
|
+
await load(false)
|
|
96
|
+
}
|
|
97
|
+
}, { deep: false })
|
|
98
|
+
|
|
99
|
+
void load(true)
|
|
100
|
+
onBeforeUnmount(() => {
|
|
101
|
+
if (id.value) {
|
|
102
|
+
unload(id.value)
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { delay } from "@alanscodelog/utils/delay"
|
|
2
|
+
import { keys } from "@alanscodelog/utils/keys"
|
|
3
|
+
import { unreachable } from "@alanscodelog/utils/unreachable"
|
|
4
|
+
import type { EditorOptions } from "@tiptap/core"
|
|
5
|
+
import { createDocument, generateJSON } from "@tiptap/core"
|
|
6
|
+
import type { Schema } from "@tiptap/pm/model"
|
|
7
|
+
import type { Plugin } from "@tiptap/pm/state"
|
|
8
|
+
import { EditorState } from "@tiptap/pm/state"
|
|
9
|
+
import { type Ref, ref, toRaw } from "vue"
|
|
10
|
+
|
|
11
|
+
import { testExtensions } from "../../../testSchema.js"
|
|
12
|
+
import { DocumentApi } from "../DocumentApi.js"
|
|
13
|
+
import type { DocumentApiInterface } from "../types.js"
|
|
14
|
+
|
|
15
|
+
type Cache = Record<string, { state?: EditorState, count: number }>
|
|
16
|
+
|
|
17
|
+
/** Creates a simple instance of the DocumentApi for testing purposes. */
|
|
18
|
+
export function useTestDocumentApi(
|
|
19
|
+
editorOptions: Partial<EditorOptions>,
|
|
20
|
+
embeds: Record<string, { content: any, title?: string }>,
|
|
21
|
+
{ loadDelay = 0 }: { loadDelay?: number } = { }
|
|
22
|
+
): {
|
|
23
|
+
cache: Ref<Cache>
|
|
24
|
+
documentApi: DocumentApiInterface
|
|
25
|
+
embeds: Record<string, { content: any, title?: string }>
|
|
26
|
+
} {
|
|
27
|
+
const cache = ref<Cache>({})
|
|
28
|
+
|
|
29
|
+
const documentApi = new DocumentApi({
|
|
30
|
+
editorOptions,
|
|
31
|
+
|
|
32
|
+
getSuggestions: async (searchString: string): Promise<{ title: string, docId: string }[]> => {
|
|
33
|
+
const res = []
|
|
34
|
+
for (const docId of keys(embeds)) {
|
|
35
|
+
const title = embeds[docId].title ?? docId
|
|
36
|
+
if (title.includes(searchString)) {
|
|
37
|
+
res.push({ title, docId })
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (loadDelay) {
|
|
41
|
+
await delay(loadDelay)
|
|
42
|
+
}
|
|
43
|
+
return res
|
|
44
|
+
},
|
|
45
|
+
getTitle: (docId, blockId) => (embeds[docId]?.title ?? docId) + (blockId ? `#${blockId}` : ""),
|
|
46
|
+
cache: {
|
|
47
|
+
get(docId: string): EditorState | undefined {
|
|
48
|
+
return toRaw(cache.value[docId]?.state)
|
|
49
|
+
},
|
|
50
|
+
set(docId: string, state: EditorState): void {
|
|
51
|
+
cache.value[docId].state = state
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
load: async (
|
|
55
|
+
docId: string,
|
|
56
|
+
schema: Schema,
|
|
57
|
+
plugins: Plugin[]
|
|
58
|
+
): Promise<{ state: EditorState }> => {
|
|
59
|
+
if (loadDelay) {
|
|
60
|
+
await delay(loadDelay)
|
|
61
|
+
}
|
|
62
|
+
// just so we catch errors where we're not correctly supplying the needed embeds for testing
|
|
63
|
+
if (!embeds[docId]) {
|
|
64
|
+
throw new Error(`No embed found for docId ${docId} in: ${JSON.stringify(embeds, null, "\t")}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const json = generateJSON(embeds[docId].content as any, testExtensions)
|
|
68
|
+
const doc = createDocument(json, schema)
|
|
69
|
+
const state = EditorState.create({
|
|
70
|
+
doc,
|
|
71
|
+
schema,
|
|
72
|
+
plugins
|
|
73
|
+
})
|
|
74
|
+
return { state }
|
|
75
|
+
},
|
|
76
|
+
refCounter: {
|
|
77
|
+
load(docId: string, loaded) {
|
|
78
|
+
cache.value[docId] ??= { ...loaded, count: 0 }
|
|
79
|
+
cache.value[docId].count++
|
|
80
|
+
},
|
|
81
|
+
unload: (docId: string) => {
|
|
82
|
+
if (cache.value[docId]) {
|
|
83
|
+
if (cache.value[docId].count === 1) {
|
|
84
|
+
delete cache.value[docId]
|
|
85
|
+
} else {
|
|
86
|
+
cache.value[docId].count--
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
unreachable()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
return { documentApi, cache, embeds }
|
|
95
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Content, Editor, EditorOptions } from "@tiptap/core"
|
|
2
|
+
import type { EditorState, Transaction } from "@tiptap/pm/state"
|
|
3
|
+
import type { InjectionKey } from "vue"
|
|
4
|
+
|
|
5
|
+
export const documentApiInjectionKey = Symbol("documentApiInjectionKey") as InjectionKey<DocumentApiInterface>
|
|
6
|
+
|
|
7
|
+
export type DocId = {
|
|
8
|
+
docId: string
|
|
9
|
+
}
|
|
10
|
+
export type BlockId = {
|
|
11
|
+
blockId?: string
|
|
12
|
+
}
|
|
13
|
+
/** When the user initially creates an embed, it's docId will be undefined. */
|
|
14
|
+
export type MaybeEmbedId = Partial<DocId> & BlockId
|
|
15
|
+
export type EmbedId = DocId & BlockId
|
|
16
|
+
|
|
17
|
+
export type OnUpdateDocumentCallback = (
|
|
18
|
+
embedId: DocId,
|
|
19
|
+
tr: Transaction,
|
|
20
|
+
oldEditorState: EditorState,
|
|
21
|
+
newEditorState: EditorState,
|
|
22
|
+
selfSymbol?: symbol
|
|
23
|
+
) => void
|
|
24
|
+
export type OnSaveDocumentCallback = (docId: string) => void
|
|
25
|
+
|
|
26
|
+
// todo separate internal documentation of api from the options that are also used int the default implementation to configure it.
|
|
27
|
+
export type DocumentApiInterface<
|
|
28
|
+
T extends Record<string, any> = Record<string, any>
|
|
29
|
+
> = {
|
|
30
|
+
/** Debounced save (to storage) function. Use the event listeners to get notified when saving finishes. */
|
|
31
|
+
save: (docId: string) => void
|
|
32
|
+
getEmbeddedContent: (embedId: EmbedId) => Content | undefined
|
|
33
|
+
getFromCache: (docId: DocId, options?: { errorIfNotFound?: boolean }) => EditorState | undefined
|
|
34
|
+
/** Load should be called the first time, before attempting to load the state. */
|
|
35
|
+
getFullState: (docId: DocId) => EditorState
|
|
36
|
+
/** Like {@link DocumentApi.preEditorInit}, but after initializing and loading the document (and before the transaction listeners are added). */
|
|
37
|
+
postEditorInit: (docId: string, editor: Editor) => void
|
|
38
|
+
/**
|
|
39
|
+
* Sets options before initializing the editor. By default just does `options.content = state.doc.toJSON()`, but can be useful when managing the document state in some other way (e.g. collab.
|
|
40
|
+
*
|
|
41
|
+
* Also useful for creating per-doc instances for certain extensions, such as Collaboration.
|
|
42
|
+
*
|
|
43
|
+
* This is a bit tricky to do normally since the editor component initializes the editor before the document is loaded and is re-used (the wrapper Editor *component*, not the editor) when the document changes.
|
|
44
|
+
*
|
|
45
|
+
* So this hook can be used to add these additional per-doc instances of extensions. Be sure to clone the properties you are modifying. They are only shallow cloned before being passed to the function.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* preEditorInit(docId, options: Partial<EditorOptions>, state: EditorState) {
|
|
49
|
+
* // we do not need to set options.content when using collab
|
|
50
|
+
* // so no options.content = state.doc.toJSON()
|
|
51
|
+
* const ydoc = cache.value[docId].ydoc
|
|
52
|
+
* // it's suggested you add the collab extension only here
|
|
53
|
+
* // otherwise you would have to initially configure it with a dummy document
|
|
54
|
+
* const collabExt = Collaboration.configure({
|
|
55
|
+
* document: ydoc
|
|
56
|
+
* }) as any
|
|
57
|
+
* options.extensions = [
|
|
58
|
+
* ...(options.extensions ?? []),
|
|
59
|
+
* collabExt
|
|
60
|
+
* ]
|
|
61
|
+
* return options
|
|
62
|
+
* },
|
|
63
|
+
* load: async (
|
|
64
|
+
* docId: string,
|
|
65
|
+
* schema: Schema,
|
|
66
|
+
* plugins: Plugin[],
|
|
67
|
+
* ) => {
|
|
68
|
+
* if (cache.value[docId]?.state) {
|
|
69
|
+
* return { state: toRaw(cache.value[docId].state) }
|
|
70
|
+
* }
|
|
71
|
+
* const doc = getFromYourDb(docId)
|
|
72
|
+
* const decoded = toUint8Array(doc.contentBinary)
|
|
73
|
+
* const yDoc = new Y.Doc()
|
|
74
|
+
* Y.applyUpdate(yDoc, decoded)
|
|
75
|
+
*
|
|
76
|
+
* const yjs = initProseMirrorDoc(yDoc.getXmlFragment("prosemirror"), schema)
|
|
77
|
+
* const state = EditorState.create({
|
|
78
|
+
* doc: yjs.doc,
|
|
79
|
+
* schema,
|
|
80
|
+
* plugins:[
|
|
81
|
+
* ...plugins,
|
|
82
|
+
* // the document api's yjs instance
|
|
83
|
+
* ySyncPlugin(yDoc.getXmlFragment("prosemirror"), {mapping:yjs.mapping}),
|
|
84
|
+
* ]
|
|
85
|
+
* })
|
|
86
|
+
* // return the state and any additional data we want refCounter.load to be called with.
|
|
87
|
+
* return { state, doc, yDoc }
|
|
88
|
+
* },
|
|
89
|
+
* updateFilter(tr:Transaction) {
|
|
90
|
+
* const meta = tr.getMeta(ySyncPluginKey)
|
|
91
|
+
* if (meta) return false
|
|
92
|
+
* return true
|
|
93
|
+
* },
|
|
94
|
+
* ```
|
|
95
|
+
* See {@link DocumentApi.updateFilter} for why yjs (and other syncronization mechanisms) might need to ignore transactions.
|
|
96
|
+
*/
|
|
97
|
+
preEditorInit: (docId: string, options: Partial<EditorOptions>, state: EditorState) => Partial<EditorOptions>
|
|
98
|
+
/**
|
|
99
|
+
* Return false to ignore the transaction.
|
|
100
|
+
*
|
|
101
|
+
* This is useful when using a secondary syncronization mechanism, such as yjs.
|
|
102
|
+
*
|
|
103
|
+
* If you load all editors of a file with yjs's plugin and point to the same ydoc, yjs's plugin will sync them. But that means that when the DocumentApi tries to sync the transactions they will have already been applied and the document update will fail.
|
|
104
|
+
*
|
|
105
|
+
* So we have to ignore all of yjs's transactions, but NOT transactions from partially embedded docs => full state, as these do not pass through yjs.
|
|
106
|
+
*/
|
|
107
|
+
updateFilter?: (tr: Transaction) => boolean | undefined
|
|
108
|
+
updateDocument: (
|
|
109
|
+
embedId: DocId,
|
|
110
|
+
tr: Transaction,
|
|
111
|
+
selfSymbol?: symbol
|
|
112
|
+
) => void
|
|
113
|
+
addEventListener (type: "saving" | "saved", cb: OnSaveDocumentCallback): void
|
|
114
|
+
addEventListener (type: "update", cb: OnUpdateDocumentCallback): void
|
|
115
|
+
removeEventListener (type: "saving" | "saved", cb: OnSaveDocumentCallback): void
|
|
116
|
+
removeEventListener (type: "update", cb: OnUpdateDocumentCallback): void
|
|
117
|
+
|
|
118
|
+
/** For the embedded document picker, should return suggestions for the search string. */
|
|
119
|
+
getSuggestions: (searchString: string) => Promise<{ title: string, docId: string }[]>
|
|
120
|
+
/** How to format the title of the embedded document. Defaults to docId#blockId */
|
|
121
|
+
getEmbedTitle: (embedId: EmbedId) => string
|
|
122
|
+
/**
|
|
123
|
+
* Tells the document api how to load an unloaded document and any additional data. Whatever this function returns will be passed to the refCounter.load option in the default DocumentApi implementation.
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* load: async ( docId: string, schema: Schema, plugins: Plugin[],) => {
|
|
127
|
+
* const dbDoc = getFromYourDb(docId)
|
|
128
|
+
*
|
|
129
|
+
* const state = EditorState.create({
|
|
130
|
+
* doc: yjs.doc,
|
|
131
|
+
* schema,
|
|
132
|
+
* plugins
|
|
133
|
+
* })
|
|
134
|
+
* // return the state and any additional data we want to cache
|
|
135
|
+
* return { state, data: { dbDoc } }
|
|
136
|
+
* },
|
|
137
|
+
* ```
|
|
138
|
+
* See {@link DocumentApi.preEditorInit} for how to set this up with sync (e.g. yjs).
|
|
139
|
+
*/
|
|
140
|
+
load: (docId: DocId) => Promise<{ state: EditorState, data?: T }>
|
|
141
|
+
/** Notifies the document api that an editor has unloaded the document. */
|
|
142
|
+
unload: (docId: DocId) => void
|
|
143
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { EditorState, Transaction } from "@tiptap/pm/state"
|
|
2
|
+
import { type ReplaceStep, Step } from "@tiptap/pm/transform"
|
|
3
|
+
|
|
4
|
+
import { copyMeta } from "./copyMeta.js"
|
|
5
|
+
import { getStateEmbedRange } from "./getStateEmbedRange.js"
|
|
6
|
+
|
|
7
|
+
import { getDiffReplacementRange } from "../../../utils/getDiffReplacementRange.js"
|
|
8
|
+
import type { EmbedId } from "../types.js"
|
|
9
|
+
|
|
10
|
+
export function convertFullTransactionForPartialState(
|
|
11
|
+
state: EditorState,
|
|
12
|
+
tr: Transaction,
|
|
13
|
+
embedId: EmbedId
|
|
14
|
+
): Transaction | undefined {
|
|
15
|
+
const blockId = embedId.blockId
|
|
16
|
+
if (!blockId) {
|
|
17
|
+
// see https://github.com/ueberdosis/tiptap/issues/1883
|
|
18
|
+
// and https://github.com/ueberdosis/tiptap/issues/74#issuecomment-460206175
|
|
19
|
+
const steps: ReplaceStep[] = JSON.parse(
|
|
20
|
+
JSON.stringify(tr.steps)
|
|
21
|
+
).map((step: any) => Step.fromJSON(state.schema, step))
|
|
22
|
+
// the documents are the same
|
|
23
|
+
const intTr = state.tr as Transaction
|
|
24
|
+
copyMeta(tr, intTr)
|
|
25
|
+
intTr.setMeta("ignore", true)
|
|
26
|
+
for (const step of steps) {
|
|
27
|
+
intTr.step(step)
|
|
28
|
+
}
|
|
29
|
+
return intTr
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { start: nodeStartExisting } = getStateEmbedRange(state.doc, embedId)
|
|
33
|
+
const { start: nodeStart } = getStateEmbedRange(
|
|
34
|
+
tr.doc,
|
|
35
|
+
embedId
|
|
36
|
+
)
|
|
37
|
+
if (nodeStart === undefined || nodeStartExisting === undefined) return undefined
|
|
38
|
+
const intTr = state.tr as Transaction
|
|
39
|
+
copyMeta(tr, intTr)
|
|
40
|
+
|
|
41
|
+
intTr.setMeta("ignore", true)
|
|
42
|
+
const existingNode = state.doc.nodeAt(nodeStartExisting)
|
|
43
|
+
const newNode = tr.doc.nodeAt(nodeStart)
|
|
44
|
+
const convertedNewNode = newNode ? state.schema.nodeFromJSON(newNode.toJSON()) : undefined
|
|
45
|
+
if (!existingNode || !convertedNewNode) return undefined
|
|
46
|
+
|
|
47
|
+
// when the change crosses a boundary it's way too hard to find the right steps
|
|
48
|
+
// so we just replace the whole different part
|
|
49
|
+
const diff = getDiffReplacementRange(existingNode, convertedNewNode, nodeStartExisting - 1)
|
|
50
|
+
if (diff) {
|
|
51
|
+
intTr.replace(2 + diff.start, 2 + diff.end, convertedNewNode.slice(diff.sliceStart, diff.sliceEnd))
|
|
52
|
+
}
|
|
53
|
+
return intTr
|
|
54
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { EditorState, Transaction } from "@tiptap/pm/state"
|
|
2
|
+
import { Step } from "@tiptap/pm/transform"
|
|
3
|
+
|
|
4
|
+
import { copyMeta } from "./copyMeta.js"
|
|
5
|
+
|
|
6
|
+
/* The schemas are different between editor states, this converts a transaction for use from one instance to another. */
|
|
7
|
+
export function convertTrForInstance(
|
|
8
|
+
tr: Transaction,
|
|
9
|
+
/** We convert to the schema from this state. */
|
|
10
|
+
otherState: EditorState
|
|
11
|
+
): Transaction {
|
|
12
|
+
const extTr = otherState.tr as Transaction
|
|
13
|
+
copyMeta(tr, extTr)
|
|
14
|
+
// see https://github.com/ueberdosis/tiptap/issues/1883
|
|
15
|
+
// and https://github.com/ueberdosis/tiptap/issues/74#issuecomment-460206175
|
|
16
|
+
const steps = JSON.parse(
|
|
17
|
+
JSON.stringify(tr.steps)
|
|
18
|
+
).map((step: any) => Step.fromJSON(otherState.schema, step))
|
|
19
|
+
for (const step of steps) {
|
|
20
|
+
extTr.step(step)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return extTr
|
|
24
|
+
}
|