@tiptap/core 2.11.7 → 3.0.0-beta.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/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +5047 -5070
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3326 -0
- package/dist/index.d.ts +3326 -25
- package/dist/index.js +4931 -4976
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime/jsx-runtime.cjs +56 -0
- package/dist/jsx-runtime/jsx-runtime.cjs.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.d.cts +22 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts +22 -0
- package/dist/jsx-runtime/jsx-runtime.js +26 -0
- package/dist/jsx-runtime/jsx-runtime.js.map +1 -0
- package/jsx-runtime/index.cjs +1 -0
- package/jsx-runtime/index.d.cts +1 -0
- package/jsx-runtime/index.d.ts +1 -0
- package/jsx-runtime/index.js +1 -0
- package/package.json +28 -9
- package/src/CommandManager.ts +4 -11
- package/src/Editor.ts +219 -103
- package/src/EventEmitter.ts +7 -10
- package/src/Extendable.ts +484 -0
- package/src/Extension.ts +17 -492
- package/src/ExtensionManager.ts +88 -140
- package/src/InputRule.ts +40 -51
- package/src/Mark.ts +146 -623
- package/src/MarkView.ts +66 -0
- package/src/Node.ts +332 -825
- package/src/NodePos.ts +3 -5
- package/src/NodeView.ts +13 -23
- package/src/PasteRule.ts +46 -56
- package/src/Tracker.ts +8 -10
- package/src/commands/blur.ts +15 -13
- package/src/commands/clearContent.ts +13 -6
- package/src/commands/clearNodes.ts +33 -31
- package/src/commands/command.ts +2 -2
- package/src/commands/createParagraphNear.ts +6 -4
- package/src/commands/cut.ts +13 -11
- package/src/commands/deleteCurrentNode.ts +24 -22
- package/src/commands/deleteNode.ts +20 -18
- package/src/commands/deleteRange.ts +11 -9
- package/src/commands/deleteSelection.ts +6 -4
- package/src/commands/enter.ts +7 -5
- package/src/commands/exitCode.ts +6 -4
- package/src/commands/extendMarkRange.ts +16 -14
- package/src/commands/first.ts +3 -5
- package/src/commands/focus.ts +50 -53
- package/src/commands/forEach.ts +3 -3
- package/src/commands/insertContent.ts +14 -16
- package/src/commands/insertContentAt.ts +111 -95
- package/src/commands/join.ts +21 -13
- package/src/commands/joinItemBackward.ts +17 -19
- package/src/commands/joinItemForward.ts +17 -19
- package/src/commands/joinTextblockBackward.ts +6 -4
- package/src/commands/joinTextblockForward.ts +6 -4
- package/src/commands/keyboardShortcut.ts +30 -35
- package/src/commands/lift.ts +12 -10
- package/src/commands/liftEmptyBlock.ts +7 -5
- package/src/commands/liftListItem.ts +8 -6
- package/src/commands/newlineInCode.ts +6 -4
- package/src/commands/resetAttributes.ts +38 -43
- package/src/commands/scrollIntoView.ts +10 -8
- package/src/commands/selectAll.ts +11 -9
- package/src/commands/selectNodeBackward.ts +6 -4
- package/src/commands/selectNodeForward.ts +6 -4
- package/src/commands/selectParentNode.ts +6 -4
- package/src/commands/selectTextblockEnd.ts +6 -4
- package/src/commands/selectTextblockStart.ts +6 -4
- package/src/commands/setContent.ts +39 -38
- package/src/commands/setMark.ts +58 -60
- package/src/commands/setMeta.ts +8 -6
- package/src/commands/setNode.ts +34 -32
- package/src/commands/setNodeSelection.ts +12 -10
- package/src/commands/setTextSelection.ts +16 -14
- package/src/commands/sinkListItem.ts +8 -6
- package/src/commands/splitBlock.ts +70 -78
- package/src/commands/splitListItem.ts +95 -107
- package/src/commands/toggleList.ts +76 -74
- package/src/commands/toggleMark.ts +13 -11
- package/src/commands/toggleNode.ts +20 -18
- package/src/commands/toggleWrap.ts +12 -10
- package/src/commands/undoInputRule.ts +32 -30
- package/src/commands/unsetAllMarks.ts +17 -15
- package/src/commands/unsetMark.ts +29 -27
- package/src/commands/updateAttributes.ts +94 -102
- package/src/commands/wrapIn.ts +8 -6
- package/src/commands/wrapInList.ts +8 -6
- package/src/extensions/clipboardTextSerializer.ts +2 -4
- package/src/extensions/delete.ts +89 -0
- package/src/extensions/focusEvents.ts +2 -6
- package/src/extensions/index.ts +1 -0
- package/src/extensions/keymap.ts +54 -50
- package/src/extensions/paste.ts +0 -1
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +3 -6
- package/src/helpers/createChainableState.ts +2 -5
- package/src/helpers/createDocument.ts +2 -4
- package/src/helpers/createNodeFromContent.ts +7 -12
- package/src/helpers/defaultBlockAt.ts +1 -1
- package/src/helpers/findChildren.ts +2 -2
- package/src/helpers/findChildrenInRange.ts +3 -7
- package/src/helpers/findParentNode.ts +5 -3
- package/src/helpers/findParentNodeClosestToPos.ts +2 -2
- package/src/helpers/flattenExtensions.ts +30 -0
- package/src/helpers/generateHTML.ts +1 -1
- package/src/helpers/generateJSON.ts +1 -1
- package/src/helpers/generateText.ts +1 -1
- package/src/helpers/getAttributes.ts +3 -6
- package/src/helpers/getAttributesFromExtensions.ts +29 -38
- package/src/helpers/getChangedRanges.ts +15 -13
- package/src/helpers/getDebugJSON.ts +2 -2
- package/src/helpers/getExtensionField.ts +12 -12
- package/src/helpers/getHTMLFromFragment.ts +2 -1
- package/src/helpers/getMarkAttributes.ts +3 -6
- package/src/helpers/getMarkRange.ts +7 -17
- package/src/helpers/getMarkType.ts +2 -4
- package/src/helpers/getMarksBetween.ts +2 -2
- package/src/helpers/getNodeAtPosition.ts +2 -2
- package/src/helpers/getNodeAttributes.ts +3 -6
- package/src/helpers/getNodeType.ts +2 -4
- package/src/helpers/getRenderedAttributes.ts +3 -5
- package/src/helpers/getSchema.ts +5 -5
- package/src/helpers/getSchemaByResolvedExtensions.ts +47 -78
- package/src/helpers/getSchemaTypeByName.ts +1 -1
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getSplittedAttributes.ts +5 -5
- package/src/helpers/getText.ts +2 -2
- package/src/helpers/getTextBetween.ts +2 -2
- package/src/helpers/getTextContentFromNodes.ts +9 -12
- package/src/helpers/getTextSerializersFromSchema.ts +2 -2
- package/src/helpers/index.ts +3 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +3 -3
- package/src/helpers/isActive.ts +2 -6
- package/src/helpers/isAtEndOfNode.ts +1 -1
- package/src/helpers/isAtStartOfNode.ts +1 -1
- package/src/helpers/isExtensionRulesEnabled.ts +2 -4
- package/src/helpers/isList.ts +2 -2
- package/src/helpers/isMarkActive.ts +3 -3
- package/src/helpers/isNodeActive.ts +3 -3
- package/src/helpers/isNodeEmpty.ts +3 -3
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveExtensions.ts +25 -0
- package/src/helpers/resolveFocusPosition.ts +5 -16
- package/src/helpers/rewriteUnknownContent.ts +25 -24
- package/src/helpers/selectionToInsertionEnd.ts +2 -1
- package/src/helpers/sortExtensions.ts +26 -0
- package/src/helpers/splitExtensions.ts +4 -4
- package/src/index.ts +3 -7
- package/src/inputRules/markInputRule.ts +5 -8
- package/src/inputRules/nodeInputRule.ts +6 -12
- package/src/inputRules/textInputRule.ts +3 -5
- package/src/inputRules/textblockTypeInputRule.ts +6 -11
- package/src/inputRules/wrappingInputRule.ts +18 -23
- package/src/jsx-runtime.ts +64 -0
- package/src/pasteRules/markPasteRule.ts +5 -6
- package/src/pasteRules/nodePasteRule.ts +6 -11
- package/src/pasteRules/textPasteRule.ts +3 -5
- package/src/style.ts +0 -4
- package/src/types.ts +534 -179
- package/src/utilities/callOrReturn.ts +1 -1
- package/src/utilities/createStyleTag.ts +3 -1
- package/src/utilities/deleteProps.ts +7 -11
- package/src/utilities/elementFromString.ts +3 -0
- package/src/utilities/findDuplicates.ts +4 -1
- package/src/utilities/index.ts +1 -0
- package/src/utilities/isMacOS.ts +1 -3
- package/src/utilities/isiOS.ts +5 -10
- package/src/utilities/mergeAttributes.ts +16 -6
- package/src/utilities/removeDuplicates.ts +1 -3
- package/dist/CommandManager.d.ts +0 -21
- package/dist/CommandManager.d.ts.map +0 -1
- package/dist/Editor.d.ts +0 -166
- package/dist/Editor.d.ts.map +0 -1
- package/dist/EventEmitter.d.ts +0 -13
- package/dist/EventEmitter.d.ts.map +0 -1
- package/dist/Extension.d.ts +0 -345
- package/dist/Extension.d.ts.map +0 -1
- package/dist/ExtensionManager.d.ts +0 -57
- package/dist/ExtensionManager.d.ts.map +0 -1
- package/dist/InputRule.d.ts +0 -43
- package/dist/InputRule.d.ts.map +0 -1
- package/dist/Mark.d.ts +0 -453
- package/dist/Mark.d.ts.map +0 -1
- package/dist/Node.d.ts +0 -629
- package/dist/Node.d.ts.map +0 -1
- package/dist/NodePos.d.ts +0 -45
- package/dist/NodePos.d.ts.map +0 -1
- package/dist/NodeView.d.ts +0 -41
- package/dist/NodeView.d.ts.map +0 -1
- package/dist/PasteRule.d.ts +0 -51
- package/dist/PasteRule.d.ts.map +0 -1
- package/dist/Tracker.d.ts +0 -12
- package/dist/Tracker.d.ts.map +0 -1
- package/dist/commands/blur.d.ts +0 -14
- package/dist/commands/blur.d.ts.map +0 -1
- package/dist/commands/clearContent.d.ts +0 -15
- package/dist/commands/clearContent.d.ts.map +0 -1
- package/dist/commands/clearNodes.d.ts +0 -14
- package/dist/commands/clearNodes.d.ts.map +0 -1
- package/dist/commands/command.d.ts +0 -19
- package/dist/commands/command.d.ts.map +0 -1
- package/dist/commands/createParagraphNear.d.ts +0 -14
- package/dist/commands/createParagraphNear.d.ts.map +0 -1
- package/dist/commands/cut.d.ts +0 -21
- package/dist/commands/cut.d.ts.map +0 -1
- package/dist/commands/deleteCurrentNode.d.ts +0 -14
- package/dist/commands/deleteCurrentNode.d.ts.map +0 -1
- package/dist/commands/deleteNode.d.ts +0 -16
- package/dist/commands/deleteNode.d.ts.map +0 -1
- package/dist/commands/deleteRange.d.ts +0 -15
- package/dist/commands/deleteRange.d.ts.map +0 -1
- package/dist/commands/deleteSelection.d.ts +0 -14
- package/dist/commands/deleteSelection.d.ts.map +0 -1
- package/dist/commands/enter.d.ts +0 -14
- package/dist/commands/enter.d.ts.map +0 -1
- package/dist/commands/exitCode.d.ts +0 -14
- package/dist/commands/exitCode.d.ts.map +0 -1
- package/dist/commands/extendMarkRange.d.ts +0 -26
- package/dist/commands/extendMarkRange.d.ts.map +0 -1
- package/dist/commands/first.d.ts +0 -15
- package/dist/commands/first.d.ts.map +0 -1
- package/dist/commands/focus.d.ts +0 -28
- package/dist/commands/focus.d.ts.map +0 -1
- package/dist/commands/forEach.d.ts +0 -15
- package/dist/commands/forEach.d.ts.map +0 -1
- package/dist/commands/index.d.ts +0 -56
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/insertContent.d.ts +0 -35
- package/dist/commands/insertContent.d.ts.map +0 -1
- package/dist/commands/insertContentAt.d.ts +0 -48
- package/dist/commands/insertContentAt.d.ts.map +0 -1
- package/dist/commands/join.d.ts +0 -42
- package/dist/commands/join.d.ts.map +0 -1
- package/dist/commands/joinItemBackward.d.ts +0 -14
- package/dist/commands/joinItemBackward.d.ts.map +0 -1
- package/dist/commands/joinItemForward.d.ts +0 -14
- package/dist/commands/joinItemForward.d.ts.map +0 -1
- package/dist/commands/joinTextblockBackward.d.ts +0 -13
- package/dist/commands/joinTextblockBackward.d.ts.map +0 -1
- package/dist/commands/joinTextblockForward.d.ts +0 -13
- package/dist/commands/joinTextblockForward.d.ts.map +0 -1
- package/dist/commands/keyboardShortcut.d.ts +0 -15
- package/dist/commands/keyboardShortcut.d.ts.map +0 -1
- package/dist/commands/lift.d.ts +0 -18
- package/dist/commands/lift.d.ts.map +0 -1
- package/dist/commands/liftEmptyBlock.d.ts +0 -14
- package/dist/commands/liftEmptyBlock.d.ts.map +0 -1
- package/dist/commands/liftListItem.d.ts +0 -16
- package/dist/commands/liftListItem.d.ts.map +0 -1
- package/dist/commands/newlineInCode.d.ts +0 -14
- package/dist/commands/newlineInCode.d.ts.map +0 -1
- package/dist/commands/resetAttributes.d.ts +0 -17
- package/dist/commands/resetAttributes.d.ts.map +0 -1
- package/dist/commands/scrollIntoView.d.ts +0 -14
- package/dist/commands/scrollIntoView.d.ts.map +0 -1
- package/dist/commands/selectAll.d.ts +0 -14
- package/dist/commands/selectAll.d.ts.map +0 -1
- package/dist/commands/selectNodeBackward.d.ts +0 -14
- package/dist/commands/selectNodeBackward.d.ts.map +0 -1
- package/dist/commands/selectNodeForward.d.ts +0 -14
- package/dist/commands/selectNodeForward.d.ts.map +0 -1
- package/dist/commands/selectParentNode.d.ts +0 -14
- package/dist/commands/selectParentNode.d.ts.map +0 -1
- package/dist/commands/selectTextblockEnd.d.ts +0 -14
- package/dist/commands/selectTextblockEnd.d.ts.map +0 -1
- package/dist/commands/selectTextblockStart.d.ts +0 -14
- package/dist/commands/selectTextblockStart.d.ts.map +0 -1
- package/dist/commands/setContent.d.ts +0 -41
- package/dist/commands/setContent.d.ts.map +0 -1
- package/dist/commands/setMark.d.ts +0 -16
- package/dist/commands/setMark.d.ts.map +0 -1
- package/dist/commands/setMeta.d.ts +0 -17
- package/dist/commands/setMeta.d.ts.map +0 -1
- package/dist/commands/setNode.d.ts +0 -17
- package/dist/commands/setNode.d.ts.map +0 -1
- package/dist/commands/setNodeSelection.d.ts +0 -15
- package/dist/commands/setNodeSelection.d.ts.map +0 -1
- package/dist/commands/setTextSelection.d.ts +0 -15
- package/dist/commands/setTextSelection.d.ts.map +0 -1
- package/dist/commands/sinkListItem.d.ts +0 -16
- package/dist/commands/sinkListItem.d.ts.map +0 -1
- package/dist/commands/splitBlock.d.ts +0 -18
- package/dist/commands/splitBlock.d.ts.map +0 -1
- package/dist/commands/splitListItem.d.ts +0 -17
- package/dist/commands/splitListItem.d.ts.map +0 -1
- package/dist/commands/toggleList.d.ts +0 -19
- package/dist/commands/toggleList.d.ts.map +0 -1
- package/dist/commands/toggleMark.d.ts +0 -31
- package/dist/commands/toggleMark.d.ts.map +0 -1
- package/dist/commands/toggleNode.d.ts +0 -18
- package/dist/commands/toggleNode.d.ts.map +0 -1
- package/dist/commands/toggleWrap.d.ts +0 -17
- package/dist/commands/toggleWrap.d.ts.map +0 -1
- package/dist/commands/undoInputRule.d.ts +0 -14
- package/dist/commands/undoInputRule.d.ts.map +0 -1
- package/dist/commands/unsetAllMarks.d.ts +0 -14
- package/dist/commands/unsetAllMarks.d.ts.map +0 -1
- package/dist/commands/unsetMark.d.ts +0 -26
- package/dist/commands/unsetMark.d.ts.map +0 -1
- package/dist/commands/updateAttributes.d.ts +0 -25
- package/dist/commands/updateAttributes.d.ts.map +0 -1
- package/dist/commands/wrapIn.d.ts +0 -17
- package/dist/commands/wrapIn.d.ts.map +0 -1
- package/dist/commands/wrapInList.d.ts +0 -17
- package/dist/commands/wrapInList.d.ts.map +0 -1
- package/dist/extensions/clipboardTextSerializer.d.ts +0 -6
- package/dist/extensions/clipboardTextSerializer.d.ts.map +0 -1
- package/dist/extensions/commands.d.ts +0 -4
- package/dist/extensions/commands.d.ts.map +0 -1
- package/dist/extensions/drop.d.ts +0 -3
- package/dist/extensions/drop.d.ts.map +0 -1
- package/dist/extensions/editable.d.ts +0 -3
- package/dist/extensions/editable.d.ts.map +0 -1
- package/dist/extensions/focusEvents.d.ts +0 -5
- package/dist/extensions/focusEvents.d.ts.map +0 -1
- package/dist/extensions/index.d.ts +0 -9
- package/dist/extensions/index.d.ts.map +0 -1
- package/dist/extensions/keymap.d.ts +0 -3
- package/dist/extensions/keymap.d.ts.map +0 -1
- package/dist/extensions/paste.d.ts +0 -3
- package/dist/extensions/paste.d.ts.map +0 -1
- package/dist/extensions/tabindex.d.ts +0 -3
- package/dist/extensions/tabindex.d.ts.map +0 -1
- package/dist/helpers/combineTransactionSteps.d.ts +0 -11
- package/dist/helpers/combineTransactionSteps.d.ts.map +0 -1
- package/dist/helpers/createChainableState.d.ts +0 -11
- package/dist/helpers/createChainableState.d.ts.map +0 -1
- package/dist/helpers/createDocument.d.ts +0 -13
- package/dist/helpers/createDocument.d.ts.map +0 -1
- package/dist/helpers/createNodeFromContent.d.ts +0 -16
- package/dist/helpers/createNodeFromContent.d.ts.map +0 -1
- package/dist/helpers/defaultBlockAt.d.ts +0 -8
- package/dist/helpers/defaultBlockAt.d.ts.map +0 -1
- package/dist/helpers/findChildren.d.ts +0 -10
- package/dist/helpers/findChildren.d.ts.map +0 -1
- package/dist/helpers/findChildrenInRange.d.ts +0 -11
- package/dist/helpers/findChildrenInRange.d.ts.map +0 -1
- package/dist/helpers/findParentNode.d.ts +0 -17
- package/dist/helpers/findParentNode.d.ts.map +0 -1
- package/dist/helpers/findParentNodeClosestToPos.d.ts +0 -18
- package/dist/helpers/findParentNodeClosestToPos.d.ts.map +0 -1
- package/dist/helpers/generateHTML.d.ts +0 -9
- package/dist/helpers/generateHTML.d.ts.map +0 -1
- package/dist/helpers/generateJSON.d.ts +0 -9
- package/dist/helpers/generateJSON.d.ts.map +0 -1
- package/dist/helpers/generateText.d.ts +0 -13
- package/dist/helpers/generateText.d.ts.map +0 -1
- package/dist/helpers/getAttributes.d.ts +0 -10
- package/dist/helpers/getAttributes.d.ts.map +0 -1
- package/dist/helpers/getAttributesFromExtensions.d.ts +0 -7
- package/dist/helpers/getAttributesFromExtensions.d.ts.map +0 -1
- package/dist/helpers/getChangedRanges.d.ts +0 -12
- package/dist/helpers/getChangedRanges.d.ts.map +0 -1
- package/dist/helpers/getDebugJSON.d.ts +0 -9
- package/dist/helpers/getDebugJSON.d.ts.map +0 -1
- package/dist/helpers/getExtensionField.d.ts +0 -10
- package/dist/helpers/getExtensionField.d.ts.map +0 -1
- package/dist/helpers/getHTMLFromFragment.d.ts +0 -3
- package/dist/helpers/getHTMLFromFragment.d.ts.map +0 -1
- package/dist/helpers/getMarkAttributes.d.ts +0 -4
- package/dist/helpers/getMarkAttributes.d.ts.map +0 -1
- package/dist/helpers/getMarkRange.d.ts +0 -20
- package/dist/helpers/getMarkRange.d.ts.map +0 -1
- package/dist/helpers/getMarkType.d.ts +0 -3
- package/dist/helpers/getMarkType.d.ts.map +0 -1
- package/dist/helpers/getMarksBetween.d.ts +0 -4
- package/dist/helpers/getMarksBetween.d.ts.map +0 -1
- package/dist/helpers/getNodeAtPosition.d.ts +0 -12
- package/dist/helpers/getNodeAtPosition.d.ts.map +0 -1
- package/dist/helpers/getNodeAttributes.d.ts +0 -4
- package/dist/helpers/getNodeAttributes.d.ts.map +0 -1
- package/dist/helpers/getNodeType.d.ts +0 -3
- package/dist/helpers/getNodeType.d.ts.map +0 -1
- package/dist/helpers/getRenderedAttributes.d.ts +0 -4
- package/dist/helpers/getRenderedAttributes.d.ts.map +0 -1
- package/dist/helpers/getSchema.d.ts +0 -5
- package/dist/helpers/getSchema.d.ts.map +0 -1
- package/dist/helpers/getSchemaByResolvedExtensions.d.ts +0 -11
- package/dist/helpers/getSchemaByResolvedExtensions.d.ts.map +0 -1
- package/dist/helpers/getSchemaTypeByName.d.ts +0 -9
- package/dist/helpers/getSchemaTypeByName.d.ts.map +0 -1
- package/dist/helpers/getSchemaTypeNameByName.d.ts +0 -9
- package/dist/helpers/getSchemaTypeNameByName.d.ts.map +0 -1
- package/dist/helpers/getSplittedAttributes.d.ts +0 -10
- package/dist/helpers/getSplittedAttributes.d.ts.map +0 -1
- package/dist/helpers/getText.d.ts +0 -16
- package/dist/helpers/getText.d.ts.map +0 -1
- package/dist/helpers/getTextBetween.d.ts +0 -15
- package/dist/helpers/getTextBetween.d.ts.map +0 -1
- package/dist/helpers/getTextContentFromNodes.d.ts +0 -9
- package/dist/helpers/getTextContentFromNodes.d.ts.map +0 -1
- package/dist/helpers/getTextSerializersFromSchema.d.ts +0 -9
- package/dist/helpers/getTextSerializersFromSchema.d.ts.map +0 -1
- package/dist/helpers/index.d.ts +0 -52
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/injectExtensionAttributesToParseRule.d.ts +0 -10
- package/dist/helpers/injectExtensionAttributesToParseRule.d.ts.map +0 -1
- package/dist/helpers/isActive.d.ts +0 -3
- package/dist/helpers/isActive.d.ts.map +0 -1
- package/dist/helpers/isAtEndOfNode.d.ts +0 -3
- package/dist/helpers/isAtEndOfNode.d.ts.map +0 -1
- package/dist/helpers/isAtStartOfNode.d.ts +0 -3
- package/dist/helpers/isAtStartOfNode.d.ts.map +0 -1
- package/dist/helpers/isExtensionRulesEnabled.d.ts +0 -3
- package/dist/helpers/isExtensionRulesEnabled.d.ts.map +0 -1
- package/dist/helpers/isList.d.ts +0 -3
- package/dist/helpers/isList.d.ts.map +0 -1
- package/dist/helpers/isMarkActive.d.ts +0 -4
- package/dist/helpers/isMarkActive.d.ts.map +0 -1
- package/dist/helpers/isNodeActive.d.ts +0 -4
- package/dist/helpers/isNodeActive.d.ts.map +0 -1
- package/dist/helpers/isNodeEmpty.d.ts +0 -15
- package/dist/helpers/isNodeEmpty.d.ts.map +0 -1
- package/dist/helpers/isNodeSelection.d.ts +0 -3
- package/dist/helpers/isNodeSelection.d.ts.map +0 -1
- package/dist/helpers/isTextSelection.d.ts +0 -3
- package/dist/helpers/isTextSelection.d.ts.map +0 -1
- package/dist/helpers/posToDOMRect.d.ts +0 -3
- package/dist/helpers/posToDOMRect.d.ts.map +0 -1
- package/dist/helpers/resolveFocusPosition.d.ts +0 -5
- package/dist/helpers/resolveFocusPosition.d.ts.map +0 -1
- package/dist/helpers/rewriteUnknownContent.d.ts +0 -46
- package/dist/helpers/rewriteUnknownContent.d.ts.map +0 -1
- package/dist/helpers/selectionToInsertionEnd.d.ts +0 -3
- package/dist/helpers/selectionToInsertionEnd.d.ts.map +0 -1
- package/dist/helpers/splitExtensions.d.ts +0 -10
- package/dist/helpers/splitExtensions.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -5525
- package/dist/index.umd.js.map +0 -1
- package/dist/inputRules/index.d.ts +0 -6
- package/dist/inputRules/index.d.ts.map +0 -1
- package/dist/inputRules/markInputRule.d.ts +0 -14
- package/dist/inputRules/markInputRule.d.ts.map +0 -1
- package/dist/inputRules/nodeInputRule.d.ts +0 -24
- package/dist/inputRules/nodeInputRule.d.ts.map +0 -1
- package/dist/inputRules/textInputRule.d.ts +0 -11
- package/dist/inputRules/textInputRule.d.ts.map +0 -1
- package/dist/inputRules/textblockTypeInputRule.d.ts +0 -16
- package/dist/inputRules/textblockTypeInputRule.d.ts.map +0 -1
- package/dist/inputRules/wrappingInputRule.d.ts +0 -29
- package/dist/inputRules/wrappingInputRule.d.ts.map +0 -1
- package/dist/pasteRules/index.d.ts +0 -4
- package/dist/pasteRules/index.d.ts.map +0 -1
- package/dist/pasteRules/markPasteRule.d.ts +0 -14
- package/dist/pasteRules/markPasteRule.d.ts.map +0 -1
- package/dist/pasteRules/nodePasteRule.d.ts +0 -15
- package/dist/pasteRules/nodePasteRule.d.ts.map +0 -1
- package/dist/pasteRules/textPasteRule.d.ts +0 -11
- package/dist/pasteRules/textPasteRule.d.ts.map +0 -1
- package/dist/style.d.ts +0 -2
- package/dist/style.d.ts.map +0 -1
- package/dist/types.d.ts +0 -323
- package/dist/types.d.ts.map +0 -1
- package/dist/utilities/callOrReturn.d.ts +0 -10
- package/dist/utilities/callOrReturn.d.ts.map +0 -1
- package/dist/utilities/createStyleTag.d.ts +0 -2
- package/dist/utilities/createStyleTag.d.ts.map +0 -1
- package/dist/utilities/deleteProps.d.ts +0 -7
- package/dist/utilities/deleteProps.d.ts.map +0 -1
- package/dist/utilities/elementFromString.d.ts +0 -2
- package/dist/utilities/elementFromString.d.ts.map +0 -1
- package/dist/utilities/escapeForRegEx.d.ts +0 -2
- package/dist/utilities/escapeForRegEx.d.ts.map +0 -1
- package/dist/utilities/findDuplicates.d.ts +0 -2
- package/dist/utilities/findDuplicates.d.ts.map +0 -1
- package/dist/utilities/fromString.d.ts +0 -2
- package/dist/utilities/fromString.d.ts.map +0 -1
- package/dist/utilities/index.d.ts +0 -21
- package/dist/utilities/index.d.ts.map +0 -1
- package/dist/utilities/isAndroid.d.ts +0 -2
- package/dist/utilities/isAndroid.d.ts.map +0 -1
- package/dist/utilities/isEmptyObject.d.ts +0 -2
- package/dist/utilities/isEmptyObject.d.ts.map +0 -1
- package/dist/utilities/isFunction.d.ts +0 -2
- package/dist/utilities/isFunction.d.ts.map +0 -1
- package/dist/utilities/isMacOS.d.ts +0 -2
- package/dist/utilities/isMacOS.d.ts.map +0 -1
- package/dist/utilities/isNumber.d.ts +0 -2
- package/dist/utilities/isNumber.d.ts.map +0 -1
- package/dist/utilities/isPlainObject.d.ts +0 -2
- package/dist/utilities/isPlainObject.d.ts.map +0 -1
- package/dist/utilities/isRegExp.d.ts +0 -2
- package/dist/utilities/isRegExp.d.ts.map +0 -1
- package/dist/utilities/isString.d.ts +0 -2
- package/dist/utilities/isString.d.ts.map +0 -1
- package/dist/utilities/isiOS.d.ts +0 -2
- package/dist/utilities/isiOS.d.ts.map +0 -1
- package/dist/utilities/mergeAttributes.d.ts +0 -2
- package/dist/utilities/mergeAttributes.d.ts.map +0 -1
- package/dist/utilities/mergeDeep.d.ts +0 -2
- package/dist/utilities/mergeDeep.d.ts.map +0 -1
- package/dist/utilities/minMax.d.ts +0 -2
- package/dist/utilities/minMax.d.ts.map +0 -1
- package/dist/utilities/objectIncludes.d.ts +0 -9
- package/dist/utilities/objectIncludes.d.ts.map +0 -1
- package/dist/utilities/removeDuplicates.d.ts +0 -9
- package/dist/utilities/removeDuplicates.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deleteSelection as originalDeleteSelection } from '@tiptap/pm/commands'
|
|
2
2
|
|
|
3
|
-
import { RawCommands } from '../types.js'
|
|
3
|
+
import type { RawCommands } from '../types.js'
|
|
4
4
|
|
|
5
5
|
declare module '@tiptap/core' {
|
|
6
6
|
interface Commands<ReturnType> {
|
|
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const deleteSelection: RawCommands['deleteSelection'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const deleteSelection: RawCommands['deleteSelection'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalDeleteSelection(state, dispatch)
|
|
21
|
+
}
|
package/src/commands/enter.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RawCommands } from '../types.js'
|
|
1
|
+
import type { RawCommands } from '../types.js'
|
|
2
2
|
|
|
3
3
|
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
@@ -7,11 +7,13 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Trigger enter.
|
|
8
8
|
* @example editor.commands.enter()
|
|
9
9
|
*/
|
|
10
|
-
enter: () => ReturnType
|
|
10
|
+
enter: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const enter: RawCommands['enter'] =
|
|
16
|
-
|
|
17
|
-
}
|
|
15
|
+
export const enter: RawCommands['enter'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ commands }) => {
|
|
18
|
+
return commands.keyboardShortcut('Enter')
|
|
19
|
+
}
|
package/src/commands/exitCode.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exitCode as originalExitCode } from '@tiptap/pm/commands'
|
|
2
2
|
|
|
3
|
-
import { RawCommands } from '../types.js'
|
|
3
|
+
import type { RawCommands } from '../types.js'
|
|
4
4
|
|
|
5
5
|
declare module '@tiptap/core' {
|
|
6
6
|
interface Commands<ReturnType> {
|
|
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const exitCode: RawCommands['exitCode'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const exitCode: RawCommands['exitCode'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalExitCode(state, dispatch)
|
|
21
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
import { TextSelection } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
4
|
import { getMarkRange } from '../helpers/getMarkRange.js'
|
|
5
5
|
import { getMarkType } from '../helpers/getMarkType.js'
|
|
6
|
-
import { RawCommands } from '../types.js'
|
|
6
|
+
import type { RawCommands } from '../types.js'
|
|
7
7
|
|
|
8
8
|
declare module '@tiptap/core' {
|
|
9
9
|
interface Commands<ReturnType> {
|
|
@@ -30,20 +30,22 @@ declare module '@tiptap/core' {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const extendMarkRange: RawCommands['extendMarkRange'] =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
export const extendMarkRange: RawCommands['extendMarkRange'] =
|
|
34
|
+
(typeOrName, attributes = {}) =>
|
|
35
|
+
({ tr, state, dispatch }) => {
|
|
36
|
+
const type = getMarkType(typeOrName, state.schema)
|
|
37
|
+
const { doc, selection } = tr
|
|
38
|
+
const { $from, from, to } = selection
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
if (dispatch) {
|
|
41
|
+
const range = getMarkRange($from, type, attributes)
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
if (range && range.from <= from && range.to >= to) {
|
|
44
|
+
const newSelection = TextSelection.create(doc, range.from, range.to)
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
tr.setSelection(newSelection)
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
|
-
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
+
return true
|
|
51
|
+
}
|
package/src/commands/first.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, CommandProps, RawCommands } from '../types.js'
|
|
1
|
+
import type { Command, CommandProps, RawCommands } from '../types.js'
|
|
2
2
|
|
|
3
3
|
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
@@ -8,15 +8,13 @@ declare module '@tiptap/core' {
|
|
|
8
8
|
* @param commands The commands to run.
|
|
9
9
|
* @example editor.commands.first([command1, command2])
|
|
10
10
|
*/
|
|
11
|
-
first: (commands: Command[] | ((props: CommandProps) => Command[])) => ReturnType
|
|
11
|
+
first: (commands: Command[] | ((props: CommandProps) => Command[])) => ReturnType
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const first: RawCommands['first'] = commands => props => {
|
|
17
|
-
const items = typeof commands === 'function'
|
|
18
|
-
? commands(props)
|
|
19
|
-
: commands
|
|
17
|
+
const items = typeof commands === 'function' ? commands(props) : commands
|
|
20
18
|
|
|
21
19
|
for (let i = 0; i < items.length; i += 1) {
|
|
22
20
|
if (items[i](props)) {
|
package/src/commands/focus.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isTextSelection } from '../helpers/isTextSelection.js'
|
|
2
2
|
import { resolveFocusPosition } from '../helpers/resolveFocusPosition.js'
|
|
3
|
-
import { FocusPosition, RawCommands } from '../types.js'
|
|
3
|
+
import type { FocusPosition, RawCommands } from '../types.js'
|
|
4
4
|
import { isAndroid } from '../utilities/isAndroid.js'
|
|
5
5
|
import { isiOS } from '../utilities/isiOS.js'
|
|
6
6
|
|
|
@@ -25,72 +25,69 @@ declare module '@tiptap/core' {
|
|
|
25
25
|
* @default { scrollIntoView: true }
|
|
26
26
|
*/
|
|
27
27
|
options?: {
|
|
28
|
-
scrollIntoView?: boolean
|
|
28
|
+
scrollIntoView?: boolean
|
|
29
29
|
},
|
|
30
|
-
) => ReturnType
|
|
30
|
+
) => ReturnType
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export const focus: RawCommands['focus'] =
|
|
36
|
-
|
|
37
|
-
view,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
options = {
|
|
42
|
-
scrollIntoView: true,
|
|
43
|
-
...options,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const delayedFocus = () => {
|
|
47
|
-
// focus within `requestAnimationFrame` breaks focus on iOS and Android
|
|
48
|
-
// so we have to call this
|
|
49
|
-
if (isiOS() || isAndroid()) {
|
|
50
|
-
(view.dom as HTMLElement).focus()
|
|
35
|
+
export const focus: RawCommands['focus'] =
|
|
36
|
+
(position = null, options = {}) =>
|
|
37
|
+
({ editor, view, tr, dispatch }) => {
|
|
38
|
+
options = {
|
|
39
|
+
scrollIntoView: true,
|
|
40
|
+
...options,
|
|
51
41
|
}
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
view.focus()
|
|
58
|
-
|
|
59
|
-
if (options?.scrollIntoView) {
|
|
60
|
-
editor.commands.scrollIntoView()
|
|
61
|
-
}
|
|
43
|
+
const delayedFocus = () => {
|
|
44
|
+
// focus within `requestAnimationFrame` breaks focus on iOS and Android
|
|
45
|
+
// so we have to call this
|
|
46
|
+
if (isiOS() || isAndroid()) {
|
|
47
|
+
;(view.dom as HTMLElement).focus()
|
|
62
48
|
}
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
49
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
// For React we have to focus asynchronously. Otherwise wild things happen.
|
|
51
|
+
// see: https://github.com/ueberdosis/tiptap/issues/1520
|
|
52
|
+
requestAnimationFrame(() => {
|
|
53
|
+
if (!editor.isDestroyed) {
|
|
54
|
+
view.focus()
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
if (options?.scrollIntoView) {
|
|
57
|
+
editor.commands.scrollIntoView()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
75
62
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const isSameSelection = editor.state.selection.eq(selection)
|
|
63
|
+
if ((view.hasFocus() && position === null) || position === false) {
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
80
66
|
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
|
|
67
|
+
// we don’t try to resolve a NodeSelection or CellSelection
|
|
68
|
+
if (dispatch && position === null && !isTextSelection(editor.state.selection)) {
|
|
69
|
+
delayedFocus()
|
|
70
|
+
return true
|
|
84
71
|
}
|
|
85
72
|
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
|
|
73
|
+
// pass through tr.doc instead of editor.state.doc
|
|
74
|
+
// since transactions could change the editors state before this command has been run
|
|
75
|
+
const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection
|
|
76
|
+
const isSameSelection = editor.state.selection.eq(selection)
|
|
77
|
+
|
|
78
|
+
if (dispatch) {
|
|
79
|
+
if (!isSameSelection) {
|
|
80
|
+
tr.setSelection(selection)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// `tr.setSelection` resets the stored marks
|
|
84
|
+
// so we’ll restore them if the selection is the same as before
|
|
85
|
+
if (isSameSelection && tr.storedMarks) {
|
|
86
|
+
tr.setStoredMarks(tr.storedMarks)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
delayedFocus()
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
return true
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
return true
|
|
96
|
-
}
|
package/src/commands/forEach.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandProps, RawCommands } from '../types.js'
|
|
1
|
+
import type { CommandProps, RawCommands } from '../types.js'
|
|
2
2
|
|
|
3
3
|
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
@@ -11,10 +11,10 @@ declare module '@tiptap/core' {
|
|
|
11
11
|
fn: (
|
|
12
12
|
item: T,
|
|
13
13
|
props: CommandProps & {
|
|
14
|
-
index: number
|
|
14
|
+
index: number
|
|
15
15
|
},
|
|
16
16
|
) => boolean,
|
|
17
|
-
) => ReturnType
|
|
17
|
+
) => ReturnType
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
|
|
1
|
+
import type { Fragment, Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { Content, RawCommands } from '../types.js'
|
|
3
|
+
import type { Content, RawCommands } from '../types.js'
|
|
4
4
|
|
|
5
5
|
declare module '@tiptap/core' {
|
|
6
6
|
interface Commands<ReturnType> {
|
|
@@ -23,24 +23,22 @@ declare module '@tiptap/core' {
|
|
|
23
23
|
/**
|
|
24
24
|
* Options for parsing the content.
|
|
25
25
|
*/
|
|
26
|
-
parseOptions?: ParseOptions
|
|
26
|
+
parseOptions?: ParseOptions
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Whether to update the selection after inserting the content.
|
|
30
30
|
*/
|
|
31
|
-
updateSelection?: boolean
|
|
32
|
-
applyInputRules?: boolean
|
|
33
|
-
applyPasteRules?: boolean
|
|
34
|
-
}
|
|
35
|
-
) => ReturnType
|
|
36
|
-
}
|
|
31
|
+
updateSelection?: boolean
|
|
32
|
+
applyInputRules?: boolean
|
|
33
|
+
applyPasteRules?: boolean
|
|
34
|
+
},
|
|
35
|
+
) => ReturnType
|
|
36
|
+
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export const insertContent: RawCommands['insertContent'] =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
value,
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
}
|
|
40
|
+
export const insertContent: RawCommands['insertContent'] =
|
|
41
|
+
(value, options) =>
|
|
42
|
+
({ tr, commands }) => {
|
|
43
|
+
return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options)
|
|
44
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Node as ProseMirrorNode, ParseOptions } from '@tiptap/pm/model'
|
|
2
|
+
import { Fragment } from '@tiptap/pm/model'
|
|
2
3
|
|
|
3
4
|
import { createNodeFromContent } from '../helpers/createNodeFromContent.js'
|
|
4
5
|
import { selectionToInsertionEnd } from '../helpers/selectionToInsertionEnd.js'
|
|
5
|
-
import { Content, Range, RawCommands } from '../types.js'
|
|
6
|
+
import type { Content, Range, RawCommands } from '../types.js'
|
|
6
7
|
|
|
7
8
|
declare module '@tiptap/core' {
|
|
8
9
|
interface Commands<ReturnType> {
|
|
@@ -60,114 +61,129 @@ const isFragment = (nodeOrFragment: ProseMirrorNode | Fragment): nodeOrFragment
|
|
|
60
61
|
return !('type' in nodeOrFragment)
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
export const insertContentAt: RawCommands['insertContentAt'] =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
export const insertContentAt: RawCommands['insertContentAt'] =
|
|
65
|
+
(position, value, options) =>
|
|
66
|
+
({ tr, dispatch, editor }) => {
|
|
67
|
+
if (dispatch) {
|
|
68
|
+
options = {
|
|
69
|
+
parseOptions: editor.options.parseOptions,
|
|
70
|
+
updateSelection: true,
|
|
71
|
+
applyInputRules: false,
|
|
72
|
+
applyPasteRules: false,
|
|
73
|
+
...options,
|
|
74
|
+
}
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
parseOptions: {
|
|
78
|
-
preserveWhitespace: 'full',
|
|
79
|
-
...options.parseOptions,
|
|
80
|
-
},
|
|
81
|
-
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
82
|
-
})
|
|
83
|
-
} catch (e) {
|
|
84
|
-
editor.emit('contentError', {
|
|
85
|
-
editor,
|
|
86
|
-
error: e as Error,
|
|
87
|
-
disableCollaboration: () => {
|
|
88
|
-
if (editor.storage.collaboration) {
|
|
89
|
-
editor.storage.collaboration.isDisabled = true
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
})
|
|
93
|
-
return false
|
|
94
|
-
}
|
|
76
|
+
let content: Fragment | ProseMirrorNode
|
|
77
|
+
const { selection } = editor.state
|
|
95
78
|
|
|
96
|
-
|
|
79
|
+
try {
|
|
80
|
+
content = createNodeFromContent(value, editor.schema, {
|
|
81
|
+
parseOptions: {
|
|
82
|
+
preserveWhitespace: 'full',
|
|
83
|
+
...options.parseOptions,
|
|
84
|
+
},
|
|
85
|
+
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
86
|
+
})
|
|
87
|
+
} catch (e) {
|
|
88
|
+
editor.emit('contentError', {
|
|
89
|
+
editor,
|
|
90
|
+
error: e as Error,
|
|
91
|
+
disableCollaboration: () => {
|
|
92
|
+
if (
|
|
93
|
+
'collaboration' in editor.storage &&
|
|
94
|
+
typeof editor.storage.collaboration === 'object' &&
|
|
95
|
+
editor.storage.collaboration
|
|
96
|
+
) {
|
|
97
|
+
;(editor.storage.collaboration as any).isDisabled = true
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const nodes = isFragment(content) ? content : [content]
|
|
104
|
+
let { from, to } =
|
|
105
|
+
typeof position === 'number' ? { from: position, to: position } : { from: position.from, to: position.to }
|
|
101
106
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
let isOnlyTextContent = true
|
|
108
|
+
let isOnlyBlockContent = true
|
|
109
|
+
const nodes = isFragment(content) ? content : [content]
|
|
105
110
|
|
|
106
|
-
|
|
111
|
+
nodes.forEach(node => {
|
|
112
|
+
// check if added node is valid
|
|
113
|
+
node.check()
|
|
107
114
|
|
|
108
|
-
|
|
109
|
-
})
|
|
115
|
+
isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// example:
|
|
114
|
-
// replace an empty paragraph by an inserted image
|
|
115
|
-
// instead of inserting the image below the paragraph
|
|
116
|
-
if (from === to && isOnlyBlockContent) {
|
|
117
|
-
const { parent } = tr.doc.resolve(from)
|
|
118
|
-
const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount
|
|
117
|
+
isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false
|
|
118
|
+
})
|
|
119
119
|
|
|
120
|
-
if
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
// check if we can replace the wrapping node by
|
|
121
|
+
// the newly inserted content
|
|
122
|
+
// example:
|
|
123
|
+
// replace an empty paragraph by an inserted image
|
|
124
|
+
// instead of inserting the image below the paragraph
|
|
125
|
+
if (from === to && isOnlyBlockContent) {
|
|
126
|
+
const { parent } = tr.doc.resolve(from)
|
|
127
|
+
const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount
|
|
128
|
+
|
|
129
|
+
if (isEmptyTextBlock) {
|
|
130
|
+
from -= 1
|
|
131
|
+
to += 1
|
|
132
|
+
}
|
|
123
133
|
}
|
|
124
|
-
}
|
|
125
134
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
135
|
+
let newContent
|
|
136
|
+
|
|
137
|
+
// if there is only plain text we have to use `insertText`
|
|
138
|
+
// because this will keep the current marks
|
|
139
|
+
if (isOnlyTextContent) {
|
|
140
|
+
// if value is string, we can use it directly
|
|
141
|
+
// otherwise if it is an array, we have to join it
|
|
142
|
+
if (Array.isArray(value)) {
|
|
143
|
+
newContent = value.map(v => v.text || '').join('')
|
|
144
|
+
} else if (value instanceof Fragment) {
|
|
145
|
+
let text = ''
|
|
146
|
+
|
|
147
|
+
value.forEach(node => {
|
|
148
|
+
if (node.text) {
|
|
149
|
+
text += node.text
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
newContent = text
|
|
154
|
+
} else if (typeof value === 'object' && !!value && !!value.text) {
|
|
155
|
+
newContent = value.text
|
|
156
|
+
} else {
|
|
157
|
+
newContent = value as string
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
tr.insertText(newContent, from, to)
|
|
147
161
|
} else {
|
|
148
|
-
newContent =
|
|
149
|
-
}
|
|
162
|
+
newContent = content
|
|
150
163
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
newContent = content
|
|
164
|
+
const fromSelectionAtStart = selection.$from.parentOffset === 0
|
|
165
|
+
const isTextSelection = selection.$from.node().isText || selection.$from.node().isTextblock
|
|
154
166
|
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
if (fromSelectionAtStart && isTextSelection) {
|
|
168
|
+
from = Math.max(0, from - 1)
|
|
169
|
+
}
|
|
157
170
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
|
|
161
|
-
}
|
|
171
|
+
tr.replaceWith(from, to, newContent)
|
|
172
|
+
}
|
|
162
173
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
// set cursor at end of inserted content
|
|
175
|
+
if (options.updateSelection) {
|
|
176
|
+
selectionToInsertionEnd(tr, tr.steps.length - 1, -1)
|
|
177
|
+
}
|
|
166
178
|
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
if (options.applyInputRules) {
|
|
180
|
+
tr.setMeta('applyInputRules', { from, text: newContent })
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (options.applyPasteRules) {
|
|
184
|
+
tr.setMeta('applyPasteRules', { from, text: newContent })
|
|
185
|
+
}
|
|
169
186
|
}
|
|
170
|
-
}
|
|
171
187
|
|
|
172
|
-
|
|
173
|
-
}
|
|
188
|
+
return true
|
|
189
|
+
}
|
package/src/commands/join.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
joinUp as originalJoinUp,
|
|
6
6
|
} from '@tiptap/pm/commands'
|
|
7
7
|
|
|
8
|
-
import { RawCommands } from '../types.js'
|
|
8
|
+
import type { RawCommands } from '../types.js'
|
|
9
9
|
|
|
10
10
|
declare module '@tiptap/core' {
|
|
11
11
|
interface Commands<ReturnType> {
|
|
@@ -44,18 +44,26 @@ declare module '@tiptap/core' {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const joinUp: RawCommands['joinUp'] =
|
|
48
|
-
|
|
49
|
-
}
|
|
47
|
+
export const joinUp: RawCommands['joinUp'] =
|
|
48
|
+
() =>
|
|
49
|
+
({ state, dispatch }) => {
|
|
50
|
+
return originalJoinUp(state, dispatch)
|
|
51
|
+
}
|
|
50
52
|
|
|
51
|
-
export const joinDown: RawCommands['joinDown'] =
|
|
52
|
-
|
|
53
|
-
}
|
|
53
|
+
export const joinDown: RawCommands['joinDown'] =
|
|
54
|
+
() =>
|
|
55
|
+
({ state, dispatch }) => {
|
|
56
|
+
return originalJoinDown(state, dispatch)
|
|
57
|
+
}
|
|
54
58
|
|
|
55
|
-
export const joinBackward: RawCommands['joinBackward'] =
|
|
56
|
-
|
|
57
|
-
}
|
|
59
|
+
export const joinBackward: RawCommands['joinBackward'] =
|
|
60
|
+
() =>
|
|
61
|
+
({ state, dispatch }) => {
|
|
62
|
+
return originalJoinBackward(state, dispatch)
|
|
63
|
+
}
|
|
58
64
|
|
|
59
|
-
export const joinForward: RawCommands['joinForward'] =
|
|
60
|
-
|
|
61
|
-
}
|
|
65
|
+
export const joinForward: RawCommands['joinForward'] =
|
|
66
|
+
() =>
|
|
67
|
+
({ state, dispatch }) => {
|
|
68
|
+
return originalJoinForward(state, dispatch)
|
|
69
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { joinPoint } from '@tiptap/pm/transform'
|
|
2
2
|
|
|
3
|
-
import { RawCommands } from '../types.js'
|
|
3
|
+
import type { RawCommands } from '../types.js'
|
|
4
4
|
|
|
5
5
|
declare module '@tiptap/core' {
|
|
6
6
|
interface Commands<ReturnType> {
|
|
@@ -14,26 +14,24 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const joinItemBackward: RawCommands['joinItemBackward'] =
|
|
18
|
-
|
|
19
|
-
dispatch,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const point = joinPoint(state.doc, state.selection.$from.pos, -1)
|
|
17
|
+
export const joinItemBackward: RawCommands['joinItemBackward'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch, tr }) => {
|
|
20
|
+
try {
|
|
21
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, -1)
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (point === null || point === undefined) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
tr.join(point, 2)
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
dispatch(tr)
|
|
31
|
+
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
return true
|
|
34
|
+
} catch {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
38
37
|
}
|
|
39
|
-
}
|