@tiptap/core 2.11.7 → 3.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +5046 -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 +4930 -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 +14 -26
- 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,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,24 +7,26 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Remove all marks in the current selection.
|
|
8
8
|
* @example editor.commands.unsetAllMarks()
|
|
9
9
|
*/
|
|
10
|
-
unsetAllMarks: () => ReturnType
|
|
10
|
+
unsetAllMarks: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const unsetAllMarks: RawCommands['unsetAllMarks'] =
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export const unsetAllMarks: RawCommands['unsetAllMarks'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ tr, dispatch }) => {
|
|
18
|
+
const { selection } = tr
|
|
19
|
+
const { empty, ranges } = selection
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (empty) {
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (dispatch) {
|
|
26
|
+
ranges.forEach(range => {
|
|
27
|
+
tr.removeMark(range.$from.pos, range.$to.pos)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarkRange } from '../helpers/getMarkRange.js'
|
|
4
4
|
import { getMarkType } from '../helpers/getMarkType.js'
|
|
5
|
-
import { RawCommands } from '../types.js'
|
|
5
|
+
import type { RawCommands } from '../types.js'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -30,34 +30,36 @@ declare module '@tiptap/core' {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const unsetMark: RawCommands['unsetMark'] =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
export const unsetMark: RawCommands['unsetMark'] =
|
|
34
|
+
(typeOrName, options = {}) =>
|
|
35
|
+
({ tr, state, dispatch }) => {
|
|
36
|
+
const { extendEmptyMarkRange = false } = options
|
|
37
|
+
const { selection } = tr
|
|
38
|
+
const type = getMarkType(typeOrName, state.schema)
|
|
39
|
+
const { $from, empty, ranges } = selection
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (!dispatch) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (empty && extendEmptyMarkRange) {
|
|
46
|
+
let { from, to } = selection
|
|
47
|
+
const attrs = $from.marks().find(mark => mark.type === type)?.attrs
|
|
48
|
+
const range = getMarkRange($from, type, attrs)
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (range) {
|
|
51
|
+
from = range.from
|
|
52
|
+
to = range.to
|
|
53
|
+
}
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
tr.removeMark(from, to, type)
|
|
56
|
+
} else {
|
|
57
|
+
ranges.forEach(range => {
|
|
58
|
+
tr.removeMark(range.$from.pos, range.$to.pos, type)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
tr.removeStoredMark(type)
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '@tiptap/pm/model'
|
|
4
|
-
import { SelectionRange } from '@tiptap/pm/state'
|
|
1
|
+
import type { Mark, MarkType, Node, NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import type { SelectionRange } from '@tiptap/pm/state'
|
|
5
3
|
|
|
6
4
|
import { getMarkType } from '../helpers/getMarkType.js'
|
|
7
5
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
8
6
|
import { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName.js'
|
|
9
|
-
import { RawCommands } from '../types.js'
|
|
7
|
+
import type { RawCommands } from '../types.js'
|
|
10
8
|
|
|
11
9
|
declare module '@tiptap/core' {
|
|
12
10
|
interface Commands<ReturnType> {
|
|
@@ -32,117 +30,111 @@ declare module '@tiptap/core' {
|
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
export const updateAttributes: RawCommands['updateAttributes'] =
|
|
33
|
+
export const updateAttributes: RawCommands['updateAttributes'] =
|
|
34
|
+
(typeOrName, attributes = {}) =>
|
|
35
|
+
({ tr, state, dispatch }) => {
|
|
36
|
+
let nodeType: NodeType | null = null
|
|
37
|
+
let markType: MarkType | null = null
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const schemaType = getSchemaTypeNameByName(
|
|
40
|
+
typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
|
|
41
|
+
state.schema,
|
|
42
|
+
)
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
if (!schemaType) {
|
|
46
|
-
return false
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (schemaType === 'node') {
|
|
50
|
-
nodeType = getNodeType(typeOrName as NodeType, state.schema)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (schemaType === 'mark') {
|
|
54
|
-
markType = getMarkType(typeOrName as MarkType, state.schema)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (dispatch) {
|
|
58
|
-
tr.selection.ranges.forEach((range: SelectionRange) => {
|
|
44
|
+
if (!schemaType) {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
59
47
|
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
if (schemaType === 'node') {
|
|
49
|
+
nodeType = getNodeType(typeOrName as NodeType, state.schema)
|
|
50
|
+
}
|
|
62
51
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let trimmedTo: number
|
|
52
|
+
if (schemaType === 'mark') {
|
|
53
|
+
markType = getMarkType(typeOrName as MarkType, state.schema)
|
|
54
|
+
}
|
|
67
55
|
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
if (dispatch) {
|
|
57
|
+
tr.selection.ranges.forEach((range: SelectionRange) => {
|
|
58
|
+
const from = range.$from.pos
|
|
59
|
+
const to = range.$to.pos
|
|
70
60
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
lastNode = node
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
} else {
|
|
79
|
-
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
80
|
-
|
|
81
|
-
if (pos < from && nodeType && nodeType === node.type) {
|
|
82
|
-
trimmedFrom = Math.max(pos, from)
|
|
83
|
-
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
84
|
-
lastPos = pos
|
|
85
|
-
lastNode = node
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (pos >= from && pos <= to) {
|
|
61
|
+
let lastPos: number | undefined
|
|
62
|
+
let lastNode: Node | undefined
|
|
63
|
+
let trimmedFrom: number
|
|
64
|
+
let trimmedTo: number
|
|
89
65
|
|
|
66
|
+
if (tr.selection.empty) {
|
|
67
|
+
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
90
68
|
if (nodeType && nodeType === node.type) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
69
|
+
trimmedFrom = Math.max(pos, from)
|
|
70
|
+
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
71
|
+
lastPos = pos
|
|
72
|
+
lastNode = node
|
|
95
73
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
tr.addMark(
|
|
105
|
-
trimmedFrom2,
|
|
106
|
-
trimmedTo2,
|
|
107
|
-
markType.create({
|
|
108
|
-
...mark.attrs,
|
|
109
|
-
...attributes,
|
|
110
|
-
}),
|
|
111
|
-
)
|
|
112
|
-
}
|
|
113
|
-
})
|
|
74
|
+
})
|
|
75
|
+
} else {
|
|
76
|
+
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
77
|
+
if (pos < from && nodeType && nodeType === node.type) {
|
|
78
|
+
trimmedFrom = Math.max(pos, from)
|
|
79
|
+
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
80
|
+
lastPos = pos
|
|
81
|
+
lastNode = node
|
|
114
82
|
}
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
}
|
|
118
83
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
84
|
+
if (pos >= from && pos <= to) {
|
|
85
|
+
if (nodeType && nodeType === node.type) {
|
|
86
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
87
|
+
...node.attrs,
|
|
88
|
+
...attributes,
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (markType && node.marks.length) {
|
|
93
|
+
node.marks.forEach((mark: Mark) => {
|
|
94
|
+
if (markType === mark.type) {
|
|
95
|
+
const trimmedFrom2 = Math.max(pos, from)
|
|
96
|
+
const trimmedTo2 = Math.min(pos + node.nodeSize, to)
|
|
97
|
+
|
|
98
|
+
tr.addMark(
|
|
99
|
+
trimmedFrom2,
|
|
100
|
+
trimmedTo2,
|
|
101
|
+
markType.create({
|
|
102
|
+
...mark.attrs,
|
|
103
|
+
...attributes,
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|
|
125
110
|
})
|
|
126
111
|
}
|
|
127
112
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
113
|
+
if (lastNode) {
|
|
114
|
+
if (lastPos !== undefined) {
|
|
115
|
+
tr.setNodeMarkup(lastPos, undefined, {
|
|
116
|
+
...lastNode.attrs,
|
|
117
|
+
...attributes,
|
|
118
|
+
})
|
|
119
|
+
}
|
|
130
120
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
if (markType && lastNode.marks.length) {
|
|
122
|
+
lastNode.marks.forEach((mark: Mark) => {
|
|
123
|
+
if (markType === mark.type) {
|
|
124
|
+
tr.addMark(
|
|
125
|
+
trimmedFrom,
|
|
126
|
+
trimmedTo,
|
|
127
|
+
markType.create({
|
|
128
|
+
...mark.attrs,
|
|
129
|
+
...attributes,
|
|
130
|
+
}),
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
142
135
|
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
146
138
|
|
|
147
|
-
|
|
148
|
-
}
|
|
139
|
+
return true
|
|
140
|
+
}
|
package/src/commands/wrapIn.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { wrapIn as originalWrapIn } from '@tiptap/pm/commands'
|
|
2
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
5
|
-
import { RawCommands } from '../types.js'
|
|
5
|
+
import type { RawCommands } from '../types.js'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -18,8 +18,10 @@ declare module '@tiptap/core' {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const wrapIn: RawCommands['wrapIn'] =
|
|
22
|
-
|
|
21
|
+
export const wrapIn: RawCommands['wrapIn'] =
|
|
22
|
+
(typeOrName, attributes = {}) =>
|
|
23
|
+
({ state, dispatch }) => {
|
|
24
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return originalWrapIn(type, attributes)(state, dispatch)
|
|
27
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
import { wrapInList as originalWrapInList } from '@tiptap/pm/schema-list'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
5
|
-
import { RawCommands } from '../types.js'
|
|
5
|
+
import type { RawCommands } from '../types.js'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -18,8 +18,10 @@ declare module '@tiptap/core' {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const wrapInList: RawCommands['wrapInList'] =
|
|
22
|
-
|
|
21
|
+
export const wrapInList: RawCommands['wrapInList'] =
|
|
22
|
+
(typeOrName, attributes = {}) =>
|
|
23
|
+
({ state, dispatch }) => {
|
|
24
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return originalWrapInList(type, attributes)(state, dispatch)
|
|
27
|
+
}
|
|
@@ -5,7 +5,7 @@ import { getTextBetween } from '../helpers/getTextBetween.js'
|
|
|
5
5
|
import { getTextSerializersFromSchema } from '../helpers/getTextSerializersFromSchema.js'
|
|
6
6
|
|
|
7
7
|
export type ClipboardTextSerializerOptions = {
|
|
8
|
-
blockSeparator?: string
|
|
8
|
+
blockSeparator?: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const ClipboardTextSerializer = Extension.create<ClipboardTextSerializerOptions>({
|
|
@@ -33,9 +33,7 @@ export const ClipboardTextSerializer = Extension.create<ClipboardTextSerializerO
|
|
|
33
33
|
const range = { from, to }
|
|
34
34
|
|
|
35
35
|
return getTextBetween(doc, range, {
|
|
36
|
-
...(this.options.blockSeparator !== undefined
|
|
37
|
-
? { blockSeparator: this.options.blockSeparator }
|
|
38
|
-
: {}),
|
|
36
|
+
...(this.options.blockSeparator !== undefined ? { blockSeparator: this.options.blockSeparator } : {}),
|
|
39
37
|
textSerializers,
|
|
40
38
|
})
|
|
41
39
|
},
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { RemoveMarkStep } from '@tiptap/pm/transform'
|
|
2
|
+
|
|
3
|
+
import { Extension } from '../Extension.js'
|
|
4
|
+
import { combineTransactionSteps, getChangedRanges } from '../helpers/index.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This extension allows you to be notified when the user deletes content you are interested in.
|
|
8
|
+
*/
|
|
9
|
+
export const Delete = Extension.create({
|
|
10
|
+
name: 'delete',
|
|
11
|
+
|
|
12
|
+
onUpdate({ transaction, appendedTransactions }) {
|
|
13
|
+
const callback = () => {
|
|
14
|
+
if (
|
|
15
|
+
this.editor.options.coreExtensionOptions?.delete?.filterTransaction?.(transaction) ??
|
|
16
|
+
transaction.getMeta('y-sync$')
|
|
17
|
+
) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
const nextTransaction = combineTransactionSteps(transaction.before, [transaction, ...appendedTransactions])
|
|
21
|
+
const changes = getChangedRanges(nextTransaction)
|
|
22
|
+
|
|
23
|
+
changes.forEach(change => {
|
|
24
|
+
if (
|
|
25
|
+
nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter &&
|
|
26
|
+
nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore
|
|
27
|
+
) {
|
|
28
|
+
nextTransaction.before.nodesBetween(change.oldRange.from, change.oldRange.to, (node, from) => {
|
|
29
|
+
const to = from + node.nodeSize - 2
|
|
30
|
+
const isFullyWithinRange = change.oldRange.from <= from && to <= change.oldRange.to
|
|
31
|
+
|
|
32
|
+
this.editor.emit('delete', {
|
|
33
|
+
type: 'node',
|
|
34
|
+
node,
|
|
35
|
+
from,
|
|
36
|
+
to,
|
|
37
|
+
newFrom: nextTransaction.mapping.map(from),
|
|
38
|
+
newTo: nextTransaction.mapping.map(to),
|
|
39
|
+
deletedRange: change.oldRange,
|
|
40
|
+
newRange: change.newRange,
|
|
41
|
+
partial: !isFullyWithinRange,
|
|
42
|
+
editor: this.editor,
|
|
43
|
+
transaction,
|
|
44
|
+
combinedTransform: nextTransaction,
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const mapping = nextTransaction.mapping
|
|
51
|
+
nextTransaction.steps.forEach((step, index) => {
|
|
52
|
+
if (step instanceof RemoveMarkStep) {
|
|
53
|
+
const newStart = mapping.slice(index).map(step.from, -1)
|
|
54
|
+
const newEnd = mapping.slice(index).map(step.to)
|
|
55
|
+
const oldStart = mapping.invert().map(newStart, -1)
|
|
56
|
+
const oldEnd = mapping.invert().map(newEnd)
|
|
57
|
+
|
|
58
|
+
const foundBeforeMark = nextTransaction.doc.nodeAt(newStart - 1)?.marks.some(mark => mark.eq(step.mark))
|
|
59
|
+
const foundAfterMark = nextTransaction.doc.nodeAt(newEnd)?.marks.some(mark => mark.eq(step.mark))
|
|
60
|
+
|
|
61
|
+
this.editor.emit('delete', {
|
|
62
|
+
type: 'mark',
|
|
63
|
+
mark: step.mark,
|
|
64
|
+
from: step.from,
|
|
65
|
+
to: step.to,
|
|
66
|
+
deletedRange: {
|
|
67
|
+
from: oldStart,
|
|
68
|
+
to: oldEnd,
|
|
69
|
+
},
|
|
70
|
+
newRange: {
|
|
71
|
+
from: newStart,
|
|
72
|
+
to: newEnd,
|
|
73
|
+
},
|
|
74
|
+
partial: Boolean(foundAfterMark || foundBeforeMark),
|
|
75
|
+
editor: this.editor,
|
|
76
|
+
transaction,
|
|
77
|
+
combinedTransform: nextTransaction,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.editor.options.coreExtensionOptions?.delete?.async ?? true) {
|
|
84
|
+
setTimeout(callback, 0)
|
|
85
|
+
} else {
|
|
86
|
+
callback()
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
})
|
|
@@ -18,9 +18,7 @@ export const FocusEvents = Extension.create({
|
|
|
18
18
|
focus: (view, event: Event) => {
|
|
19
19
|
editor.isFocused = true
|
|
20
20
|
|
|
21
|
-
const transaction = editor.state.tr
|
|
22
|
-
.setMeta('focus', { event })
|
|
23
|
-
.setMeta('addToHistory', false)
|
|
21
|
+
const transaction = editor.state.tr.setMeta('focus', { event }).setMeta('addToHistory', false)
|
|
24
22
|
|
|
25
23
|
view.dispatch(transaction)
|
|
26
24
|
|
|
@@ -29,9 +27,7 @@ export const FocusEvents = Extension.create({
|
|
|
29
27
|
blur: (view, event: Event) => {
|
|
30
28
|
editor.isFocused = false
|
|
31
29
|
|
|
32
|
-
const transaction = editor.state.tr
|
|
33
|
-
.setMeta('blur', { event })
|
|
34
|
-
.setMeta('addToHistory', false)
|
|
30
|
+
const transaction = editor.state.tr.setMeta('blur', { event }).setMeta('addToHistory', false)
|
|
35
31
|
|
|
36
32
|
view.dispatch(transaction)
|
|
37
33
|
|
package/src/extensions/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ClipboardTextSerializer } from './clipboardTextSerializer.js'
|
|
2
2
|
export { Commands } from './commands.js'
|
|
3
|
+
export { Delete } from './delete.js'
|
|
3
4
|
export { Drop } from './drop.js'
|
|
4
5
|
export { Editable } from './editable.js'
|
|
5
6
|
export { FocusEvents, focusEventsPluginKey } from './focusEvents.js'
|
package/src/extensions/keymap.ts
CHANGED
|
@@ -11,54 +11,59 @@ export const Keymap = Extension.create({
|
|
|
11
11
|
name: 'keymap',
|
|
12
12
|
|
|
13
13
|
addKeyboardShortcuts() {
|
|
14
|
-
const handleBackspace = () =>
|
|
15
|
-
() =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
() =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
14
|
+
const handleBackspace = () =>
|
|
15
|
+
this.editor.commands.first(({ commands }) => [
|
|
16
|
+
() => commands.undoInputRule(),
|
|
17
|
+
|
|
18
|
+
// maybe convert first text block node to default node
|
|
19
|
+
() =>
|
|
20
|
+
commands.command(({ tr }) => {
|
|
21
|
+
const { selection, doc } = tr
|
|
22
|
+
const { empty, $anchor } = selection
|
|
23
|
+
const { pos, parent } = $anchor
|
|
24
|
+
const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor
|
|
25
|
+
const parentIsIsolating = $parentPos.parent.type.spec.isolating
|
|
26
|
+
|
|
27
|
+
const parentPos = $anchor.pos - $anchor.parentOffset
|
|
28
|
+
|
|
29
|
+
const isAtStart =
|
|
30
|
+
parentIsIsolating && $parentPos.parent.childCount === 1
|
|
31
|
+
? parentPos === $anchor.pos
|
|
32
|
+
: Selection.atStart(doc).from === pos
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
!empty ||
|
|
36
|
+
!parent.type.isTextblock ||
|
|
37
|
+
parent.textContent.length ||
|
|
38
|
+
!isAtStart ||
|
|
39
|
+
(isAtStart && $anchor.parent.type.name === 'paragraph') // prevent clearNodes when no nodes to clear, otherwise history stack is appended
|
|
40
|
+
) {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return commands.clearNodes()
|
|
45
|
+
}),
|
|
46
|
+
|
|
47
|
+
() => commands.deleteSelection(),
|
|
48
|
+
() => commands.joinBackward(),
|
|
49
|
+
() => commands.selectNodeBackward(),
|
|
50
|
+
])
|
|
51
|
+
|
|
52
|
+
const handleDelete = () =>
|
|
53
|
+
this.editor.commands.first(({ commands }) => [
|
|
54
|
+
() => commands.deleteSelection(),
|
|
55
|
+
() => commands.deleteCurrentNode(),
|
|
56
|
+
() => commands.joinForward(),
|
|
57
|
+
() => commands.selectNodeForward(),
|
|
58
|
+
])
|
|
59
|
+
|
|
60
|
+
const handleEnter = () =>
|
|
61
|
+
this.editor.commands.first(({ commands }) => [
|
|
62
|
+
() => commands.newlineInCode(),
|
|
63
|
+
() => commands.createParagraphNear(),
|
|
64
|
+
() => commands.liftEmptyBlock(),
|
|
65
|
+
() => commands.splitBlock(),
|
|
66
|
+
])
|
|
62
67
|
|
|
63
68
|
const baseKeymap = {
|
|
64
69
|
Enter: handleEnter,
|
|
@@ -108,8 +113,7 @@ export const Keymap = Extension.create({
|
|
|
108
113
|
return
|
|
109
114
|
}
|
|
110
115
|
|
|
111
|
-
const docChanges = transactions.some(transaction => transaction.docChanged)
|
|
112
|
-
&& !oldState.doc.eq(newState.doc)
|
|
116
|
+
const docChanges = transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)
|
|
113
117
|
|
|
114
118
|
const ignoreTr = transactions.some(transaction => transaction.getMeta('preventClearDocument'))
|
|
115
119
|
|