@tiptap/core 2.11.6 → 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 -5069
- 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 -4975
- 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 -5524
- 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,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode, NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { Fragment, Slice } from '@tiptap/pm/model'
|
|
4
3
|
import { TextSelection } from '@tiptap/pm/state'
|
|
5
4
|
import { canSplit } from '@tiptap/pm/transform'
|
|
6
5
|
|
|
7
6
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
8
7
|
import { getSplittedAttributes } from '../helpers/getSplittedAttributes.js'
|
|
9
|
-
import { RawCommands } from '../types.js'
|
|
8
|
+
import type { RawCommands } from '../types.js'
|
|
10
9
|
|
|
11
10
|
declare module '@tiptap/core' {
|
|
12
11
|
interface Commands<ReturnType> {
|
|
@@ -22,140 +21,129 @@ declare module '@tiptap/core' {
|
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
export const splitListItem: RawCommands['splitListItem'] =
|
|
26
|
-
|
|
27
|
-
}) => {
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
export const splitListItem: RawCommands['splitListItem'] =
|
|
25
|
+
(typeOrName, overrideAttrs = {}) =>
|
|
26
|
+
({ tr, state, dispatch, editor }) => {
|
|
27
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
28
|
+
const { $from, $to } = state.selection
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
// eslint-disable-next-line
|
|
33
32
|
const node: ProseMirrorNode = state.selection.node
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const grandParent = $from.node(-1)
|
|
34
|
+
if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
38
|
+
const grandParent = $from.node(-1)
|
|
44
39
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {
|
|
48
|
-
// In an empty block. If this is a nested list, the wrapping
|
|
49
|
-
// list item should be split. Otherwise, bail out and let next
|
|
50
|
-
// command handle lifting.
|
|
51
|
-
if (
|
|
52
|
-
$from.depth === 2
|
|
53
|
-
|| $from.node(-3).type !== type
|
|
54
|
-
|| $from.index(-2) !== $from.node(-2).childCount - 1
|
|
55
|
-
) {
|
|
40
|
+
if (grandParent.type !== type) {
|
|
56
41
|
return false
|
|
57
42
|
}
|
|
58
43
|
|
|
59
|
-
|
|
60
|
-
let wrap = Fragment.empty
|
|
61
|
-
// eslint-disable-next-line
|
|
62
|
-
const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3
|
|
44
|
+
const extensionAttributes = editor.extensionManager.attributes
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {
|
|
47
|
+
// In an empty block. If this is a nested list, the wrapping
|
|
48
|
+
// list item should be split. Otherwise, bail out and let next
|
|
49
|
+
// command handle lifting.
|
|
50
|
+
if ($from.depth === 2 || $from.node(-3).type !== type || $from.index(-2) !== $from.node(-2).childCount - 1) {
|
|
51
|
+
return false
|
|
68
52
|
}
|
|
69
53
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const newNextTypeAttributes = {
|
|
75
|
-
...getSplittedAttributes(
|
|
76
|
-
extensionAttributes,
|
|
77
|
-
$from.node().type.name,
|
|
78
|
-
$from.node().attrs,
|
|
79
|
-
),
|
|
80
|
-
...overrideAttrs,
|
|
81
|
-
}
|
|
82
|
-
const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined
|
|
54
|
+
if (dispatch) {
|
|
55
|
+
let wrap = Fragment.empty
|
|
56
|
+
// eslint-disable-next-line
|
|
57
|
+
const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3
|
|
83
58
|
|
|
84
|
-
|
|
59
|
+
// Build a fragment containing empty versions of the structure
|
|
60
|
+
// from the outer list item to the parent node of the cursor
|
|
61
|
+
for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d -= 1) {
|
|
62
|
+
wrap = Fragment.from($from.node(d).copy(wrap))
|
|
63
|
+
}
|
|
85
64
|
|
|
86
|
-
|
|
65
|
+
const depthAfter =
|
|
66
|
+
// eslint-disable-next-line no-nested-ternary
|
|
67
|
+
$from.indexAfter(-1) < $from.node(-2).childCount
|
|
68
|
+
? 1
|
|
69
|
+
: $from.indexAfter(-2) < $from.node(-3).childCount
|
|
70
|
+
? 2
|
|
71
|
+
: 3
|
|
72
|
+
|
|
73
|
+
// Add a second list item with an empty default start node
|
|
74
|
+
const newNextTypeAttributes = {
|
|
75
|
+
...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
|
|
76
|
+
...overrideAttrs,
|
|
77
|
+
}
|
|
78
|
+
const nextType = type.contentMatch.defaultType?.createAndFill(newNextTypeAttributes) || undefined
|
|
87
79
|
|
|
88
|
-
|
|
80
|
+
wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType) || undefined))
|
|
89
81
|
|
|
90
|
-
|
|
82
|
+
const start = $from.before($from.depth - (depthBefore - 1))
|
|
91
83
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
84
|
+
tr.replace(start, $from.after(-depthAfter), new Slice(wrap, 4 - depthBefore, 0))
|
|
85
|
+
|
|
86
|
+
let sel = -1
|
|
96
87
|
|
|
97
|
-
|
|
98
|
-
sel
|
|
88
|
+
tr.doc.nodesBetween(start, tr.doc.content.size, (n, pos) => {
|
|
89
|
+
if (sel > -1) {
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (n.isTextblock && n.content.size === 0) {
|
|
94
|
+
sel = pos + 1
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
if (sel > -1) {
|
|
99
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(sel)))
|
|
99
100
|
}
|
|
100
|
-
})
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
tr.setSelection(TextSelection.near(tr.doc.resolve(sel)))
|
|
102
|
+
tr.scrollIntoView()
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
return true
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
|
|
110
|
-
}
|
|
108
|
+
const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null
|
|
111
109
|
|
|
112
|
-
|
|
110
|
+
const newTypeAttributes = {
|
|
111
|
+
...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),
|
|
112
|
+
...overrideAttrs,
|
|
113
|
+
}
|
|
114
|
+
const newNextTypeAttributes = {
|
|
115
|
+
...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
|
|
116
|
+
...overrideAttrs,
|
|
117
|
+
}
|
|
113
118
|
|
|
114
|
-
|
|
115
|
-
...getSplittedAttributes(
|
|
116
|
-
extensionAttributes,
|
|
117
|
-
grandParent.type.name,
|
|
118
|
-
grandParent.attrs,
|
|
119
|
-
),
|
|
120
|
-
...overrideAttrs,
|
|
121
|
-
}
|
|
122
|
-
const newNextTypeAttributes = {
|
|
123
|
-
...getSplittedAttributes(
|
|
124
|
-
extensionAttributes,
|
|
125
|
-
$from.node().type.name,
|
|
126
|
-
$from.node().attrs,
|
|
127
|
-
),
|
|
128
|
-
...overrideAttrs,
|
|
129
|
-
}
|
|
119
|
+
tr.delete($from.pos, $to.pos)
|
|
130
120
|
|
|
131
|
-
|
|
121
|
+
const types = nextType
|
|
122
|
+
? [
|
|
123
|
+
{ type, attrs: newTypeAttributes },
|
|
124
|
+
{ type: nextType, attrs: newNextTypeAttributes },
|
|
125
|
+
]
|
|
126
|
+
: [{ type, attrs: newTypeAttributes }]
|
|
132
127
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
{ type: nextType, attrs: newNextTypeAttributes },
|
|
137
|
-
]
|
|
138
|
-
: [{ type, attrs: newTypeAttributes }]
|
|
128
|
+
if (!canSplit(tr.doc, $from.pos, 2)) {
|
|
129
|
+
return false
|
|
130
|
+
}
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
if (dispatch) {
|
|
133
|
+
const { selection, storedMarks } = state
|
|
134
|
+
const { splittableMarks } = editor.extensionManager
|
|
135
|
+
const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())
|
|
143
136
|
|
|
144
|
-
|
|
145
|
-
const { selection, storedMarks } = state
|
|
146
|
-
const { splittableMarks } = editor.extensionManager
|
|
147
|
-
const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())
|
|
137
|
+
tr.split($from.pos, 2, types).scrollIntoView()
|
|
148
138
|
|
|
149
|
-
|
|
139
|
+
if (!marks || !dispatch) {
|
|
140
|
+
return true
|
|
141
|
+
}
|
|
150
142
|
|
|
151
|
-
|
|
152
|
-
return true
|
|
153
|
-
}
|
|
143
|
+
const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))
|
|
154
144
|
|
|
155
|
-
|
|
145
|
+
tr.ensureMarks(filteredMarks)
|
|
146
|
+
}
|
|
156
147
|
|
|
157
|
-
|
|
148
|
+
return true
|
|
158
149
|
}
|
|
159
|
-
|
|
160
|
-
return true
|
|
161
|
-
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
-
import { Transaction } from '@tiptap/pm/state'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
3
3
|
import { canJoin } from '@tiptap/pm/transform'
|
|
4
4
|
|
|
5
5
|
import { findParentNode } from '../helpers/findParentNode.js'
|
|
6
6
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
7
7
|
import { isList } from '../helpers/isList.js'
|
|
8
|
-
import { RawCommands } from '../types.js'
|
|
8
|
+
import type { RawCommands } from '../types.js'
|
|
9
9
|
|
|
10
10
|
const joinListBackwards = (tr: Transaction, listType: NodeType): boolean => {
|
|
11
11
|
const list = findParentNode(node => node.type === listType)(tr.selection)
|
|
@@ -68,90 +68,92 @@ declare module '@tiptap/core' {
|
|
|
68
68
|
* @param attributes Attributes for the new list.
|
|
69
69
|
* @example editor.commands.toggleList('bulletList', 'listItem')
|
|
70
70
|
*/
|
|
71
|
-
toggleList: (
|
|
71
|
+
toggleList: (
|
|
72
|
+
listTypeOrName: string | NodeType,
|
|
73
|
+
itemTypeOrName: string | NodeType,
|
|
74
|
+
keepMarks?: boolean,
|
|
75
|
+
attributes?: Record<string, any>,
|
|
76
|
+
) => ReturnType
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
}
|
|
75
80
|
|
|
76
|
-
export const toggleList: RawCommands['toggleList'] =
|
|
77
|
-
|
|
78
|
-
}) => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
export const toggleList: RawCommands['toggleList'] =
|
|
82
|
+
(listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>
|
|
83
|
+
({ editor, tr, state, dispatch, chain, commands, can }) => {
|
|
84
|
+
const { extensions, splittableMarks } = editor.extensionManager
|
|
85
|
+
const listType = getNodeType(listTypeOrName, state.schema)
|
|
86
|
+
const itemType = getNodeType(itemTypeOrName, state.schema)
|
|
87
|
+
const { selection, storedMarks } = state
|
|
88
|
+
const { $from, $to } = selection
|
|
89
|
+
const range = $from.blockRange($to)
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
const marks = storedMarks || (selection.$to.parentOffset && selection.$from.marks())
|
|
87
92
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const parentList = findParentNode(node => isList(node.type.name, extensions))(selection)
|
|
93
|
+
if (!range) {
|
|
94
|
+
return false
|
|
95
|
+
}
|
|
93
96
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (parentList.
|
|
97
|
-
|
|
97
|
+
const parentList = findParentNode(node => isList(node.type.name, extensions))(selection)
|
|
98
|
+
|
|
99
|
+
if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
|
|
100
|
+
// remove list
|
|
101
|
+
if (parentList.node.type === listType) {
|
|
102
|
+
return commands.liftListItem(itemType)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// change list type
|
|
106
|
+
if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {
|
|
107
|
+
return chain()
|
|
108
|
+
.command(() => {
|
|
109
|
+
tr.setNodeMarkup(parentList.pos, listType)
|
|
110
|
+
|
|
111
|
+
return true
|
|
112
|
+
})
|
|
113
|
+
.command(() => joinListBackwards(tr, listType))
|
|
114
|
+
.command(() => joinListForwards(tr, listType))
|
|
115
|
+
.run()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!keepMarks || !marks || !dispatch) {
|
|
119
|
+
return (
|
|
120
|
+
chain()
|
|
121
|
+
// try to convert node to default node if needed
|
|
122
|
+
.command(() => {
|
|
123
|
+
const canWrapInList = can().wrapInList(listType, attributes)
|
|
124
|
+
|
|
125
|
+
if (canWrapInList) {
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return commands.clearNodes()
|
|
130
|
+
})
|
|
131
|
+
.wrapInList(listType, attributes)
|
|
132
|
+
.command(() => joinListBackwards(tr, listType))
|
|
133
|
+
.command(() => joinListForwards(tr, listType))
|
|
134
|
+
.run()
|
|
135
|
+
)
|
|
98
136
|
}
|
|
99
137
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
&& listType.validContent(parentList.node.content)
|
|
104
|
-
&& dispatch
|
|
105
|
-
) {
|
|
106
|
-
return chain()
|
|
138
|
+
return (
|
|
139
|
+
chain()
|
|
140
|
+
// try to convert node to default node if needed
|
|
107
141
|
.command(() => {
|
|
108
|
-
|
|
142
|
+
const canWrapInList = can().wrapInList(listType, attributes)
|
|
109
143
|
|
|
110
|
-
|
|
144
|
+
const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))
|
|
145
|
+
|
|
146
|
+
tr.ensureMarks(filteredMarks)
|
|
147
|
+
|
|
148
|
+
if (canWrapInList) {
|
|
149
|
+
return true
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return commands.clearNodes()
|
|
111
153
|
})
|
|
154
|
+
.wrapInList(listType, attributes)
|
|
112
155
|
.command(() => joinListBackwards(tr, listType))
|
|
113
156
|
.command(() => joinListForwards(tr, listType))
|
|
114
157
|
.run()
|
|
115
|
-
|
|
158
|
+
)
|
|
116
159
|
}
|
|
117
|
-
if (!keepMarks || !marks || !dispatch) {
|
|
118
|
-
|
|
119
|
-
return chain()
|
|
120
|
-
// try to convert node to default node if needed
|
|
121
|
-
.command(() => {
|
|
122
|
-
const canWrapInList = can().wrapInList(listType, attributes)
|
|
123
|
-
|
|
124
|
-
if (canWrapInList) {
|
|
125
|
-
return true
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return commands.clearNodes()
|
|
129
|
-
})
|
|
130
|
-
.wrapInList(listType, attributes)
|
|
131
|
-
.command(() => joinListBackwards(tr, listType))
|
|
132
|
-
.command(() => joinListForwards(tr, listType))
|
|
133
|
-
.run()
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
chain()
|
|
138
|
-
// try to convert node to default node if needed
|
|
139
|
-
.command(() => {
|
|
140
|
-
const canWrapInList = can().wrapInList(listType, attributes)
|
|
141
|
-
|
|
142
|
-
const filteredMarks = marks.filter(mark => splittableMarks.includes(mark.type.name))
|
|
143
|
-
|
|
144
|
-
tr.ensureMarks(filteredMarks)
|
|
145
|
-
|
|
146
|
-
if (canWrapInList) {
|
|
147
|
-
return true
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return commands.clearNodes()
|
|
151
|
-
})
|
|
152
|
-
.wrapInList(listType, attributes)
|
|
153
|
-
.command(() => joinListBackwards(tr, listType))
|
|
154
|
-
.command(() => joinListForwards(tr, listType))
|
|
155
|
-
.run()
|
|
156
|
-
)
|
|
157
|
-
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarkType } from '../helpers/getMarkType.js'
|
|
4
4
|
import { isMarkActive } from '../helpers/isMarkActive.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> {
|
|
@@ -36,14 +36,16 @@ declare module '@tiptap/core' {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export const toggleMark: RawCommands['toggleMark'] =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
export const toggleMark: RawCommands['toggleMark'] =
|
|
40
|
+
(typeOrName, attributes = {}, options = {}) =>
|
|
41
|
+
({ state, commands }) => {
|
|
42
|
+
const { extendEmptyMarkRange = false } = options
|
|
43
|
+
const type = getMarkType(typeOrName, state.schema)
|
|
44
|
+
const isActive = isMarkActive(state, type, attributes)
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if (isActive) {
|
|
47
|
+
return commands.unsetMark(type, { extendEmptyMarkRange })
|
|
48
|
+
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
+
return commands.setMark(type, attributes)
|
|
51
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
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
4
|
import { isNodeActive } from '../helpers/isNodeActive.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> {
|
|
@@ -23,23 +23,25 @@ declare module '@tiptap/core' {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export const toggleNode: RawCommands['toggleNode'] =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
export const toggleNode: RawCommands['toggleNode'] =
|
|
27
|
+
(typeOrName, toggleTypeOrName, attributes = {}) =>
|
|
28
|
+
({ state, commands }) => {
|
|
29
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
30
|
+
const toggleType = getNodeType(toggleTypeOrName, state.schema)
|
|
31
|
+
const isActive = isNodeActive(state, type, attributes)
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
let attributesToCopy: Record<string, any> | undefined
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
if (state.selection.$anchor.sameParent(state.selection.$head)) {
|
|
36
|
+
// only copy attributes if the selection is pointing to a node of the same type
|
|
37
|
+
attributesToCopy = state.selection.$anchor.parent.attrs
|
|
38
|
+
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
if (isActive) {
|
|
41
|
+
return commands.setNode(toggleType, attributesToCopy)
|
|
42
|
+
}
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
44
|
+
// If the node is not active, we want to set the new node type with the given attributes
|
|
45
|
+
// Copying over the attributes from the current node if the selection is pointing to a node of the same type
|
|
46
|
+
return commands.setNode(type, { ...attributesToCopy, ...attributes })
|
|
47
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
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
4
|
import { isNodeActive } from '../helpers/isNodeActive.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,13 +18,15 @@ declare module '@tiptap/core' {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export const toggleWrap: RawCommands['toggleWrap'] =
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
export const toggleWrap: RawCommands['toggleWrap'] =
|
|
22
|
+
(typeOrName, attributes = {}) =>
|
|
23
|
+
({ state, commands }) => {
|
|
24
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
25
|
+
const isActive = isNodeActive(state, type, attributes)
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (isActive) {
|
|
28
|
+
return commands.lift(type)
|
|
29
|
+
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
+
return commands.wrapIn(type, attributes)
|
|
32
|
+
}
|
|
@@ -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,41 +7,43 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Undo an input rule.
|
|
8
8
|
* @example editor.commands.undoInputRule()
|
|
9
9
|
*/
|
|
10
|
-
undoInputRule: () => ReturnType
|
|
10
|
+
undoInputRule: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const undoInputRule: RawCommands['undoInputRule'] =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
export const undoInputRule: RawCommands['undoInputRule'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ state, dispatch }) => {
|
|
18
|
+
const plugins = state.plugins
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < plugins.length; i += 1) {
|
|
21
|
+
const plugin = plugins[i]
|
|
22
|
+
let undoable
|
|
23
|
+
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
// eslint-disable-next-line
|
|
26
|
+
if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
|
|
27
|
+
if (dispatch) {
|
|
28
|
+
const tr = state.tr
|
|
29
|
+
const toUndo = undoable.transform
|
|
30
|
+
|
|
31
|
+
for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
|
|
32
|
+
tr.step(toUndo.steps[j].invert(toUndo.docs[j]))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (undoable.text) {
|
|
36
|
+
const marks = tr.doc.resolve(undoable.from).marks()
|
|
37
|
+
|
|
38
|
+
tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))
|
|
39
|
+
} else {
|
|
40
|
+
tr.delete(undoable.from, undoable.to)
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
const marks = tr.doc.resolve(undoable.from).marks()
|
|
35
|
-
|
|
36
|
-
tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks))
|
|
37
|
-
} else {
|
|
38
|
-
tr.delete(undoable.from, undoable.to)
|
|
39
|
-
}
|
|
44
|
+
return true
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
return true
|
|
43
46
|
}
|
|
44
|
-
}
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
+
return false
|
|
49
|
+
}
|