@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
package/src/NodePos.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Fragment, Node, ResolvedPos,
|
|
3
|
-
} from '@tiptap/pm/model'
|
|
1
|
+
import type { Fragment, Node, ResolvedPos } from '@tiptap/pm/model'
|
|
4
2
|
|
|
5
|
-
import { Editor } from './Editor.js'
|
|
6
|
-
import { Content, Range } from './types.js'
|
|
3
|
+
import type { Editor } from './Editor.js'
|
|
4
|
+
import type { Content, Range } from './types.js'
|
|
7
5
|
|
|
8
6
|
export class NodePos {
|
|
9
7
|
private resolvedPos: ResolvedPos
|
package/src/NodeView.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodeSelection } from '@tiptap/pm/state'
|
|
2
|
-
import { NodeView as ProseMirrorNodeView, ViewMutationRecord } from '@tiptap/pm/view'
|
|
2
|
+
import type { NodeView as ProseMirrorNodeView, ViewMutationRecord } from '@tiptap/pm/view'
|
|
3
3
|
|
|
4
|
-
import { Editor as CoreEditor } from './Editor.js'
|
|
5
|
-
import { DecorationWithType, NodeViewRendererOptions, NodeViewRendererProps } from './types.js'
|
|
4
|
+
import type { Editor as CoreEditor } from './Editor.js'
|
|
5
|
+
import type { DecorationWithType, NodeViewRendererOptions, NodeViewRendererProps } from './types.js'
|
|
6
6
|
import { isAndroid } from './utilities/isAndroid.js'
|
|
7
7
|
import { isiOS } from './utilities/isiOS.js'
|
|
8
8
|
|
|
@@ -14,7 +14,8 @@ export class NodeView<
|
|
|
14
14
|
Component,
|
|
15
15
|
NodeEditor extends CoreEditor = CoreEditor,
|
|
16
16
|
Options extends NodeViewRendererOptions = NodeViewRendererOptions,
|
|
17
|
-
> implements ProseMirrorNodeView
|
|
17
|
+
> implements ProseMirrorNodeView
|
|
18
|
+
{
|
|
18
19
|
component: Component
|
|
19
20
|
|
|
20
21
|
editor: NodeEditor
|
|
@@ -74,9 +75,8 @@ export class NodeView<
|
|
|
74
75
|
|
|
75
76
|
// get the drag handle element
|
|
76
77
|
// `closest` is not available for text nodes so we may have to use its parent
|
|
77
|
-
const dragHandle =
|
|
78
|
-
? target.parentElement?.closest('[data-drag-handle]')
|
|
79
|
-
: target.closest('[data-drag-handle]')
|
|
78
|
+
const dragHandle =
|
|
79
|
+
target.nodeType === 3 ? target.parentElement?.closest('[data-drag-handle]') : target.closest('[data-drag-handle]')
|
|
80
80
|
|
|
81
81
|
if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {
|
|
82
82
|
return
|
|
@@ -197,14 +197,7 @@ export class NodeView<
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
// these events are handled by prosemirror
|
|
200
|
-
if (
|
|
201
|
-
isDragging
|
|
202
|
-
|| isDropEvent
|
|
203
|
-
|| isCopyEvent
|
|
204
|
-
|| isPasteEvent
|
|
205
|
-
|| isCutEvent
|
|
206
|
-
|| (isClickEvent && isSelectable)
|
|
207
|
-
) {
|
|
200
|
+
if (isDragging || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || (isClickEvent && isSelectable)) {
|
|
208
201
|
return false
|
|
209
202
|
}
|
|
210
203
|
|
|
@@ -242,15 +235,12 @@ export class NodeView<
|
|
|
242
235
|
// see: https://github.com/ueberdosis/tiptap/issues/1214
|
|
243
236
|
// see: https://github.com/ueberdosis/tiptap/issues/2534
|
|
244
237
|
if (
|
|
245
|
-
this.dom.contains(mutation.target)
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
238
|
+
this.dom.contains(mutation.target) &&
|
|
239
|
+
mutation.type === 'childList' &&
|
|
240
|
+
(isiOS() || isAndroid()) &&
|
|
241
|
+
this.editor.isFocused
|
|
249
242
|
) {
|
|
250
|
-
const changedNodes = [
|
|
251
|
-
...Array.from(mutation.addedNodes),
|
|
252
|
-
...Array.from(mutation.removedNodes),
|
|
253
|
-
] as HTMLElement[]
|
|
243
|
+
const changedNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)] as HTMLElement[]
|
|
254
244
|
|
|
255
245
|
// we’ll check if every changed node is contentEditable
|
|
256
246
|
// to make sure it’s probably mutated by ProseMirror
|
package/src/PasteRule.ts
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
+
import { Fragment } from '@tiptap/pm/model'
|
|
3
|
+
import type { EditorState } from '@tiptap/pm/state'
|
|
4
|
+
import { Plugin } from '@tiptap/pm/state'
|
|
3
5
|
|
|
4
6
|
import { CommandManager } from './CommandManager.js'
|
|
5
|
-
import { Editor } from './Editor.js'
|
|
7
|
+
import type { Editor } from './Editor.js'
|
|
6
8
|
import { createChainableState } from './helpers/createChainableState.js'
|
|
7
9
|
import { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'
|
|
8
|
-
import {
|
|
9
|
-
CanCommands,
|
|
10
|
-
ChainedCommands,
|
|
11
|
-
ExtendedRegExpMatchArray,
|
|
12
|
-
Range,
|
|
13
|
-
SingleCommands,
|
|
14
|
-
} from './types.js'
|
|
10
|
+
import type { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'
|
|
15
11
|
import { isNumber } from './utilities/isNumber.js'
|
|
16
12
|
import { isRegExp } from './utilities/isRegExp.js'
|
|
17
13
|
|
|
18
14
|
export type PasteRuleMatch = {
|
|
19
|
-
index: number
|
|
20
|
-
text: string
|
|
21
|
-
replaceWith?: string
|
|
22
|
-
match?: RegExpMatchArray
|
|
23
|
-
data?: Record<string, any
|
|
24
|
-
}
|
|
15
|
+
index: number
|
|
16
|
+
text: string
|
|
17
|
+
replaceWith?: string
|
|
18
|
+
match?: RegExpMatchArray
|
|
19
|
+
data?: Record<string, any>
|
|
20
|
+
}
|
|
25
21
|
|
|
26
22
|
export type PasteRuleFinder =
|
|
27
23
|
| RegExp
|
|
28
|
-
| ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)
|
|
24
|
+
| ((text: string, event?: ClipboardEvent | null) => PasteRuleMatch[] | null | undefined)
|
|
29
25
|
|
|
30
26
|
/**
|
|
31
27
|
* Paste rules are used to react to pasted content.
|
|
@@ -35,28 +31,28 @@ export class PasteRule {
|
|
|
35
31
|
find: PasteRuleFinder
|
|
36
32
|
|
|
37
33
|
handler: (props: {
|
|
38
|
-
state: EditorState
|
|
39
|
-
range: Range
|
|
40
|
-
match: ExtendedRegExpMatchArray
|
|
41
|
-
commands: SingleCommands
|
|
42
|
-
chain: () => ChainedCommands
|
|
43
|
-
can: () => CanCommands
|
|
44
|
-
pasteEvent: ClipboardEvent | null
|
|
45
|
-
dropEvent: DragEvent | null
|
|
34
|
+
state: EditorState
|
|
35
|
+
range: Range
|
|
36
|
+
match: ExtendedRegExpMatchArray
|
|
37
|
+
commands: SingleCommands
|
|
38
|
+
chain: () => ChainedCommands
|
|
39
|
+
can: () => CanCommands
|
|
40
|
+
pasteEvent: ClipboardEvent | null
|
|
41
|
+
dropEvent: DragEvent | null
|
|
46
42
|
}) => void | null
|
|
47
43
|
|
|
48
44
|
constructor(config: {
|
|
49
|
-
find: PasteRuleFinder
|
|
45
|
+
find: PasteRuleFinder
|
|
50
46
|
handler: (props: {
|
|
51
|
-
can: () => CanCommands
|
|
52
|
-
chain: () => ChainedCommands
|
|
53
|
-
commands: SingleCommands
|
|
54
|
-
dropEvent: DragEvent | null
|
|
55
|
-
match: ExtendedRegExpMatchArray
|
|
56
|
-
pasteEvent: ClipboardEvent | null
|
|
57
|
-
range: Range
|
|
58
|
-
state: EditorState
|
|
59
|
-
}) => void | null
|
|
47
|
+
can: () => CanCommands
|
|
48
|
+
chain: () => ChainedCommands
|
|
49
|
+
commands: SingleCommands
|
|
50
|
+
dropEvent: DragEvent | null
|
|
51
|
+
match: ExtendedRegExpMatchArray
|
|
52
|
+
pasteEvent: ClipboardEvent | null
|
|
53
|
+
range: Range
|
|
54
|
+
state: EditorState
|
|
55
|
+
}) => void | null
|
|
60
56
|
}) {
|
|
61
57
|
this.find = config.find
|
|
62
58
|
this.handler = config.handler
|
|
@@ -87,9 +83,7 @@ const pasteRuleMatcherHandler = (
|
|
|
87
83
|
|
|
88
84
|
if (pasteRuleMatch.replaceWith) {
|
|
89
85
|
if (!pasteRuleMatch.text.includes(pasteRuleMatch.replaceWith)) {
|
|
90
|
-
console.warn(
|
|
91
|
-
'[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".',
|
|
92
|
-
)
|
|
86
|
+
console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".')
|
|
93
87
|
}
|
|
94
88
|
|
|
95
89
|
result.push(pasteRuleMatch.replaceWith)
|
|
@@ -100,17 +94,15 @@ const pasteRuleMatcherHandler = (
|
|
|
100
94
|
}
|
|
101
95
|
|
|
102
96
|
function run(config: {
|
|
103
|
-
editor: Editor
|
|
104
|
-
state: EditorState
|
|
105
|
-
from: number
|
|
106
|
-
to: number
|
|
107
|
-
rule: PasteRule
|
|
108
|
-
pasteEvent: ClipboardEvent | null
|
|
109
|
-
dropEvent: DragEvent | null
|
|
97
|
+
editor: Editor
|
|
98
|
+
state: EditorState
|
|
99
|
+
from: number
|
|
100
|
+
to: number
|
|
101
|
+
rule: PasteRule
|
|
102
|
+
pasteEvent: ClipboardEvent | null
|
|
103
|
+
dropEvent: DragEvent | null
|
|
110
104
|
}): boolean {
|
|
111
|
-
const {
|
|
112
|
-
editor, state, from, to, rule, pasteEvent, dropEvent,
|
|
113
|
-
} = config
|
|
105
|
+
const { editor, state, from, to, rule, pasteEvent, dropEvent } = config
|
|
114
106
|
|
|
115
107
|
const { commands, chain, can } = new CommandManager({
|
|
116
108
|
editor,
|
|
@@ -201,11 +193,11 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
|
|
|
201
193
|
rule,
|
|
202
194
|
pasteEvt,
|
|
203
195
|
}: {
|
|
204
|
-
state: EditorState
|
|
205
|
-
from: number
|
|
206
|
-
to: { b: number }
|
|
207
|
-
rule: PasteRule
|
|
208
|
-
pasteEvt: ClipboardEvent | null
|
|
196
|
+
state: EditorState
|
|
197
|
+
from: number
|
|
198
|
+
to: { b: number }
|
|
199
|
+
rule: PasteRule
|
|
200
|
+
pasteEvt: ClipboardEvent | null
|
|
209
201
|
}) => {
|
|
210
202
|
const tr = state.tr
|
|
211
203
|
const chainableState = createChainableState({
|
|
@@ -242,9 +234,7 @@ export function pasteRulesPlugin(props: { editor: Editor; rules: PasteRule[] }):
|
|
|
242
234
|
// we register a global drag handler to track the current drag source element
|
|
243
235
|
view(view) {
|
|
244
236
|
const handleDragstart = (event: DragEvent) => {
|
|
245
|
-
dragSourceElement = view.dom.parentElement?.contains(event.target as Element)
|
|
246
|
-
? view.dom.parentElement
|
|
247
|
-
: null
|
|
237
|
+
dragSourceElement = view.dom.parentElement?.contains(event.target as Element) ? view.dom.parentElement : null
|
|
248
238
|
|
|
249
239
|
if (dragSourceElement) {
|
|
250
240
|
tiptapDragFromOtherEditor = editor
|
package/src/Tracker.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction } from '@tiptap/pm/state'
|
|
1
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
export interface TrackerResult {
|
|
4
4
|
position: number
|
|
@@ -18,17 +18,15 @@ export class Tracker {
|
|
|
18
18
|
map(position: number): TrackerResult {
|
|
19
19
|
let deleted = false
|
|
20
20
|
|
|
21
|
-
const mappedPosition = this.transaction.steps
|
|
22
|
-
.
|
|
23
|
-
.reduce((newPosition, step) => {
|
|
24
|
-
const mapResult = step.getMap().mapResult(newPosition)
|
|
21
|
+
const mappedPosition = this.transaction.steps.slice(this.currentStep).reduce((newPosition, step) => {
|
|
22
|
+
const mapResult = step.getMap().mapResult(newPosition)
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (mapResult.deleted) {
|
|
25
|
+
deleted = true
|
|
26
|
+
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
return mapResult.pos
|
|
29
|
+
}, position)
|
|
32
30
|
|
|
33
31
|
return {
|
|
34
32
|
position: mappedPosition,
|
package/src/commands/blur.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,21 +7,23 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Removes focus from the editor.
|
|
8
8
|
* @example editor.commands.blur()
|
|
9
9
|
*/
|
|
10
|
-
blur: () => ReturnType
|
|
10
|
+
blur: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const blur: RawCommands['blur'] =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export const blur: RawCommands['blur'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ editor, view }) => {
|
|
18
|
+
requestAnimationFrame(() => {
|
|
19
|
+
if (!editor.isDestroyed) {
|
|
20
|
+
;(view.dom as HTMLElement).blur()
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
// Browsers should remove the caret on blur but safari does not.
|
|
23
|
+
// See: https://github.com/ueberdosis/tiptap/issues/2405
|
|
24
|
+
window?.getSelection()?.removeAllRanges()
|
|
25
|
+
}
|
|
26
|
+
})
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
+
return true
|
|
29
|
+
}
|
|
@@ -1,18 +1,25 @@
|
|
|
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> {
|
|
5
5
|
clearContent: {
|
|
6
6
|
/**
|
|
7
7
|
* Clear the whole document.
|
|
8
|
-
* @param emitUpdate Whether to emit an update event.
|
|
9
8
|
* @example editor.commands.clearContent()
|
|
10
9
|
*/
|
|
11
|
-
clearContent: (
|
|
10
|
+
clearContent: (
|
|
11
|
+
/**
|
|
12
|
+
* Whether to emit an update event.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
emitUpdate?: boolean,
|
|
16
|
+
) => ReturnType
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
export const clearContent: RawCommands['clearContent'] =
|
|
17
|
-
|
|
18
|
-
}
|
|
21
|
+
export const clearContent: RawCommands['clearContent'] =
|
|
22
|
+
(emitUpdate = true) =>
|
|
23
|
+
({ commands }) => {
|
|
24
|
+
return commands.setContent('', { emitUpdate })
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { liftTarget } 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> {
|
|
@@ -9,47 +9,49 @@ declare module '@tiptap/core' {
|
|
|
9
9
|
* Normalize nodes to a simple paragraph.
|
|
10
10
|
* @example editor.commands.clearNodes()
|
|
11
11
|
*/
|
|
12
|
-
clearNodes: () => ReturnType
|
|
12
|
+
clearNodes: () => ReturnType
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const clearNodes: RawCommands['clearNodes'] =
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export const clearNodes: RawCommands['clearNodes'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, tr, dispatch }) => {
|
|
20
|
+
const { selection } = tr
|
|
21
|
+
const { ranges } = selection
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
if (!dispatch) {
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
ranges.forEach(({ $from, $to }) => {
|
|
28
|
+
state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
|
|
29
|
+
if (node.type.isText) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const { doc, mapping } = tr
|
|
34
|
+
const $mappedFrom = doc.resolve(mapping.map(pos))
|
|
35
|
+
const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize))
|
|
36
|
+
const nodeRange = $mappedFrom.blockRange($mappedTo)
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
if (!nodeRange) {
|
|
39
|
+
return
|
|
40
|
+
}
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
const targetLiftDepth = liftTarget(nodeRange)
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
if (node.type.isTextblock) {
|
|
45
|
+
const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index())
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
tr.setNodeMarkup(nodeRange.start, defaultType)
|
|
48
|
+
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
if (targetLiftDepth || targetLiftDepth === 0) {
|
|
51
|
+
tr.lift(nodeRange, targetLiftDepth)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
51
54
|
})
|
|
52
|
-
})
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
+
return true
|
|
57
|
+
}
|
package/src/commands/command.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, RawCommands } from '../types.js'
|
|
1
|
+
import type { Command, RawCommands } from '../types.js'
|
|
2
2
|
|
|
3
3
|
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
@@ -12,7 +12,7 @@ declare module '@tiptap/core' {
|
|
|
12
12
|
* return true
|
|
13
13
|
* })
|
|
14
14
|
*/
|
|
15
|
-
command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType
|
|
15
|
+
command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createParagraphNear as originalCreateParagraphNear } 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 createParagraphNear: RawCommands['createParagraphNear'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const createParagraphNear: RawCommands['createParagraphNear'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalCreateParagraphNear(state, dispatch)
|
|
21
|
+
}
|
package/src/commands/cut.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TextSelection } from '@tiptap/pm/state'
|
|
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> {
|
|
@@ -13,22 +13,24 @@ declare module '@tiptap/core' {
|
|
|
13
13
|
* @param targetPos The position to insert the content at.
|
|
14
14
|
* @example editor.commands.cut({ from: 1, to: 3 }, 5)
|
|
15
15
|
*/
|
|
16
|
-
cut: ({ from, to }: { from: number
|
|
16
|
+
cut: ({ from, to }: { from: number; to: number }, targetPos: number) => ReturnType
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const cut: RawCommands['cut'] =
|
|
22
|
-
|
|
21
|
+
export const cut: RawCommands['cut'] =
|
|
22
|
+
(originRange, targetPos) =>
|
|
23
|
+
({ editor, tr }) => {
|
|
24
|
+
const { state } = editor
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
const contentSlice = state.doc.slice(originRange.from, originRange.to)
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
tr.deleteRange(originRange.from, originRange.to)
|
|
29
|
+
const newPos = tr.mapping.map(targetPos)
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
tr.insert(newPos, contentSlice.content)
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
tr.setSelection(new TextSelection(tr.doc.resolve(newPos - 1)))
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
@@ -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,36 +7,38 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Delete the node that currently has the selection anchor.
|
|
8
8
|
* @example editor.commands.deleteCurrentNode()
|
|
9
9
|
*/
|
|
10
|
-
deleteCurrentNode: () => ReturnType
|
|
10
|
+
deleteCurrentNode: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const deleteCurrentNode: RawCommands['deleteCurrentNode'] =
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export const deleteCurrentNode: RawCommands['deleteCurrentNode'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ tr, dispatch }) => {
|
|
18
|
+
const { selection } = tr
|
|
19
|
+
const currentNode = selection.$anchor.node()
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// if there is content inside the current node, break out of this command
|
|
22
|
+
if (currentNode.content.size > 0) {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
const $pos = tr.selection.$anchor
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
29
|
+
const node = $pos.node(depth)
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
if (node.type === currentNode.type) {
|
|
32
|
+
if (dispatch) {
|
|
33
|
+
const from = $pos.before(depth)
|
|
34
|
+
const to = $pos.after(depth)
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
tr.delete(from, to).scrollIntoView()
|
|
37
|
+
}
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
return true
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
|
-
}
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
4
|
-
import { RawCommands } from '../types.js'
|
|
4
|
+
import type { RawCommands } from '../types.js'
|
|
5
5
|
|
|
6
6
|
declare module '@tiptap/core' {
|
|
7
7
|
interface Commands<ReturnType> {
|
|
@@ -11,29 +11,31 @@ declare module '@tiptap/core' {
|
|
|
11
11
|
* @param typeOrName The type or name of the node.
|
|
12
12
|
* @example editor.commands.deleteNode('paragraph')
|
|
13
13
|
*/
|
|
14
|
-
deleteNode: (typeOrName: string | NodeType) => ReturnType
|
|
14
|
+
deleteNode: (typeOrName: string | NodeType) => ReturnType
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export const deleteNode: RawCommands['deleteNode'] =
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export const deleteNode: RawCommands['deleteNode'] =
|
|
20
|
+
typeOrName =>
|
|
21
|
+
({ tr, state, dispatch }) => {
|
|
22
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
23
|
+
const $pos = tr.selection.$anchor
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
26
|
+
const node = $pos.node(depth)
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (node.type === type) {
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
const from = $pos.before(depth)
|
|
31
|
+
const to = $pos.after(depth)
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
tr.delete(from, to).scrollIntoView()
|
|
34
|
+
}
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
35
38
|
}
|
|
36
|
-
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Range, RawCommands } from '../types.js'
|
|
1
|
+
import type { Range, RawCommands } from '../types.js'
|
|
2
2
|
|
|
3
3
|
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
@@ -8,17 +8,19 @@ declare module '@tiptap/core' {
|
|
|
8
8
|
* @param range The range to delete.
|
|
9
9
|
* @example editor.commands.deleteRange({ from: 1, to: 3 })
|
|
10
10
|
*/
|
|
11
|
-
deleteRange: (range: Range) => ReturnType
|
|
11
|
+
deleteRange: (range: Range) => ReturnType
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const deleteRange: RawCommands['deleteRange'] =
|
|
17
|
-
|
|
16
|
+
export const deleteRange: RawCommands['deleteRange'] =
|
|
17
|
+
range =>
|
|
18
|
+
({ tr, dispatch }) => {
|
|
19
|
+
const { from, to } = range
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (dispatch) {
|
|
22
|
+
tr.delete(from, to)
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
+
return true
|
|
26
|
+
}
|