@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,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkSpec, NodeSpec, TagParseRule } from '@tiptap/pm/model'
|
|
2
|
+
import { Schema } from '@tiptap/pm/model'
|
|
4
3
|
|
|
5
|
-
import { Editor, MarkConfig, NodeConfig } from '../index.js'
|
|
6
|
-
import { AnyConfig, Extensions } from '../types.js'
|
|
4
|
+
import type { Editor, MarkConfig, NodeConfig } from '../index.js'
|
|
5
|
+
import type { AnyConfig, Extensions } from '../types.js'
|
|
7
6
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
8
7
|
import { isEmptyObject } from '../utilities/isEmptyObject.js'
|
|
9
8
|
import { getAttributesFromExtensions } from './getAttributesFromExtensions.js'
|
|
@@ -38,9 +37,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
38
37
|
|
|
39
38
|
const nodes = Object.fromEntries(
|
|
40
39
|
nodeExtensions.map(extension => {
|
|
41
|
-
const extensionAttributes = allAttributes.filter(
|
|
42
|
-
attribute => attribute.type === extension.name,
|
|
43
|
-
)
|
|
40
|
+
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
|
44
41
|
const context = {
|
|
45
42
|
name: extension.name,
|
|
46
43
|
options: extension.options,
|
|
@@ -49,11 +46,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
const extraNodeFields = extensions.reduce((fields, e) => {
|
|
52
|
-
const extendNodeSchema = getExtensionField<AnyConfig['extendNodeSchema']>(
|
|
53
|
-
e,
|
|
54
|
-
'extendNodeSchema',
|
|
55
|
-
context,
|
|
56
|
-
)
|
|
49
|
+
const extendNodeSchema = getExtensionField<AnyConfig['extendNodeSchema']>(e, 'extendNodeSchema', context)
|
|
57
50
|
|
|
58
51
|
return {
|
|
59
52
|
...fields,
|
|
@@ -63,61 +56,49 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
63
56
|
|
|
64
57
|
const schema: NodeSpec = cleanUpSchemaItem({
|
|
65
58
|
...extraNodeFields,
|
|
66
|
-
content: callOrReturn(
|
|
67
|
-
getExtensionField<NodeConfig['content']>(extension, 'content', context),
|
|
68
|
-
),
|
|
59
|
+
content: callOrReturn(getExtensionField<NodeConfig['content']>(extension, 'content', context)),
|
|
69
60
|
marks: callOrReturn(getExtensionField<NodeConfig['marks']>(extension, 'marks', context)),
|
|
70
61
|
group: callOrReturn(getExtensionField<NodeConfig['group']>(extension, 'group', context)),
|
|
71
62
|
inline: callOrReturn(getExtensionField<NodeConfig['inline']>(extension, 'inline', context)),
|
|
72
63
|
atom: callOrReturn(getExtensionField<NodeConfig['atom']>(extension, 'atom', context)),
|
|
73
|
-
selectable: callOrReturn(
|
|
74
|
-
|
|
75
|
-
),
|
|
76
|
-
draggable: callOrReturn(
|
|
77
|
-
getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context),
|
|
78
|
-
),
|
|
64
|
+
selectable: callOrReturn(getExtensionField<NodeConfig['selectable']>(extension, 'selectable', context)),
|
|
65
|
+
draggable: callOrReturn(getExtensionField<NodeConfig['draggable']>(extension, 'draggable', context)),
|
|
79
66
|
code: callOrReturn(getExtensionField<NodeConfig['code']>(extension, 'code', context)),
|
|
80
67
|
whitespace: callOrReturn(getExtensionField<NodeConfig['whitespace']>(extension, 'whitespace', context)),
|
|
81
|
-
linebreakReplacement: callOrReturn(
|
|
82
|
-
|
|
83
|
-
getExtensionField<NodeConfig['defining']>(extension, 'defining', context),
|
|
84
|
-
),
|
|
85
|
-
isolating: callOrReturn(
|
|
86
|
-
getExtensionField<NodeConfig['isolating']>(extension, 'isolating', context),
|
|
68
|
+
linebreakReplacement: callOrReturn(
|
|
69
|
+
getExtensionField<NodeConfig['linebreakReplacement']>(extension, 'linebreakReplacement', context),
|
|
87
70
|
),
|
|
71
|
+
defining: callOrReturn(getExtensionField<NodeConfig['defining']>(extension, 'defining', context)),
|
|
72
|
+
isolating: callOrReturn(getExtensionField<NodeConfig['isolating']>(extension, 'isolating', context)),
|
|
88
73
|
attrs: Object.fromEntries(
|
|
89
74
|
extensionAttributes.map(extensionAttribute => {
|
|
90
|
-
return [
|
|
75
|
+
return [
|
|
76
|
+
extensionAttribute.name,
|
|
77
|
+
{ default: extensionAttribute?.attribute?.default, validate: extensionAttribute?.attribute?.validate },
|
|
78
|
+
]
|
|
91
79
|
}),
|
|
92
80
|
),
|
|
93
81
|
})
|
|
94
82
|
|
|
95
|
-
const parseHTML = callOrReturn(
|
|
96
|
-
getExtensionField<NodeConfig['parseHTML']>(extension, 'parseHTML', context),
|
|
97
|
-
)
|
|
83
|
+
const parseHTML = callOrReturn(getExtensionField<NodeConfig['parseHTML']>(extension, 'parseHTML', context))
|
|
98
84
|
|
|
99
85
|
if (parseHTML) {
|
|
100
|
-
schema.parseDOM = parseHTML.map(parseRule =>
|
|
86
|
+
schema.parseDOM = parseHTML.map(parseRule =>
|
|
87
|
+
injectExtensionAttributesToParseRule(parseRule, extensionAttributes),
|
|
88
|
+
) as TagParseRule[]
|
|
101
89
|
}
|
|
102
90
|
|
|
103
|
-
const renderHTML = getExtensionField<NodeConfig['renderHTML']>(
|
|
104
|
-
extension,
|
|
105
|
-
'renderHTML',
|
|
106
|
-
context,
|
|
107
|
-
)
|
|
91
|
+
const renderHTML = getExtensionField<NodeConfig['renderHTML']>(extension, 'renderHTML', context)
|
|
108
92
|
|
|
109
93
|
if (renderHTML) {
|
|
110
|
-
schema.toDOM = node =>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
94
|
+
schema.toDOM = node =>
|
|
95
|
+
renderHTML({
|
|
96
|
+
node,
|
|
97
|
+
HTMLAttributes: getRenderedAttributes(node, extensionAttributes),
|
|
98
|
+
})
|
|
114
99
|
}
|
|
115
100
|
|
|
116
|
-
const renderText = getExtensionField<NodeConfig['renderText']>(
|
|
117
|
-
extension,
|
|
118
|
-
'renderText',
|
|
119
|
-
context,
|
|
120
|
-
)
|
|
101
|
+
const renderText = getExtensionField<NodeConfig['renderText']>(extension, 'renderText', context)
|
|
121
102
|
|
|
122
103
|
if (renderText) {
|
|
123
104
|
schema.toText = renderText
|
|
@@ -129,9 +110,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
129
110
|
|
|
130
111
|
const marks = Object.fromEntries(
|
|
131
112
|
markExtensions.map(extension => {
|
|
132
|
-
const extensionAttributes = allAttributes.filter(
|
|
133
|
-
attribute => attribute.type === extension.name,
|
|
134
|
-
)
|
|
113
|
+
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
|
135
114
|
const context = {
|
|
136
115
|
name: extension.name,
|
|
137
116
|
options: extension.options,
|
|
@@ -140,11 +119,7 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
140
119
|
}
|
|
141
120
|
|
|
142
121
|
const extraMarkFields = extensions.reduce((fields, e) => {
|
|
143
|
-
const extendMarkSchema = getExtensionField<AnyConfig['extendMarkSchema']>(
|
|
144
|
-
e,
|
|
145
|
-
'extendMarkSchema',
|
|
146
|
-
context,
|
|
147
|
-
)
|
|
122
|
+
const extendMarkSchema = getExtensionField<AnyConfig['extendMarkSchema']>(e, 'extendMarkSchema', context)
|
|
148
123
|
|
|
149
124
|
return {
|
|
150
125
|
...fields,
|
|
@@ -154,43 +129,37 @@ export function getSchemaByResolvedExtensions(extensions: Extensions, editor?: E
|
|
|
154
129
|
|
|
155
130
|
const schema: MarkSpec = cleanUpSchemaItem({
|
|
156
131
|
...extraMarkFields,
|
|
157
|
-
inclusive: callOrReturn(
|
|
158
|
-
|
|
159
|
-
),
|
|
160
|
-
excludes: callOrReturn(
|
|
161
|
-
getExtensionField<MarkConfig['excludes']>(extension, 'excludes', context),
|
|
162
|
-
),
|
|
132
|
+
inclusive: callOrReturn(getExtensionField<MarkConfig['inclusive']>(extension, 'inclusive', context)),
|
|
133
|
+
excludes: callOrReturn(getExtensionField<MarkConfig['excludes']>(extension, 'excludes', context)),
|
|
163
134
|
group: callOrReturn(getExtensionField<MarkConfig['group']>(extension, 'group', context)),
|
|
164
|
-
spanning: callOrReturn(
|
|
165
|
-
getExtensionField<MarkConfig['spanning']>(extension, 'spanning', context),
|
|
166
|
-
),
|
|
135
|
+
spanning: callOrReturn(getExtensionField<MarkConfig['spanning']>(extension, 'spanning', context)),
|
|
167
136
|
code: callOrReturn(getExtensionField<MarkConfig['code']>(extension, 'code', context)),
|
|
168
137
|
attrs: Object.fromEntries(
|
|
169
138
|
extensionAttributes.map(extensionAttribute => {
|
|
170
|
-
return [
|
|
139
|
+
return [
|
|
140
|
+
extensionAttribute.name,
|
|
141
|
+
{ default: extensionAttribute?.attribute?.default, validate: extensionAttribute?.attribute?.validate },
|
|
142
|
+
]
|
|
171
143
|
}),
|
|
172
144
|
),
|
|
173
145
|
})
|
|
174
146
|
|
|
175
|
-
const parseHTML = callOrReturn(
|
|
176
|
-
getExtensionField<MarkConfig['parseHTML']>(extension, 'parseHTML', context),
|
|
177
|
-
)
|
|
147
|
+
const parseHTML = callOrReturn(getExtensionField<MarkConfig['parseHTML']>(extension, 'parseHTML', context))
|
|
178
148
|
|
|
179
149
|
if (parseHTML) {
|
|
180
|
-
schema.parseDOM = parseHTML.map(parseRule =>
|
|
150
|
+
schema.parseDOM = parseHTML.map(parseRule =>
|
|
151
|
+
injectExtensionAttributesToParseRule(parseRule, extensionAttributes),
|
|
152
|
+
)
|
|
181
153
|
}
|
|
182
154
|
|
|
183
|
-
const renderHTML = getExtensionField<MarkConfig['renderHTML']>(
|
|
184
|
-
extension,
|
|
185
|
-
'renderHTML',
|
|
186
|
-
context,
|
|
187
|
-
)
|
|
155
|
+
const renderHTML = getExtensionField<MarkConfig['renderHTML']>(extension, 'renderHTML', context)
|
|
188
156
|
|
|
189
157
|
if (renderHTML) {
|
|
190
|
-
schema.toDOM = mark =>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
158
|
+
schema.toDOM = mark =>
|
|
159
|
+
renderHTML({
|
|
160
|
+
mark,
|
|
161
|
+
HTMLAttributes: getRenderedAttributes(mark, extensionAttributes),
|
|
162
|
+
})
|
|
194
163
|
}
|
|
195
164
|
|
|
196
165
|
return [extension.name, schema]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtensionAttribute } from '../types.js'
|
|
1
|
+
import type { ExtensionAttribute } from '../types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Return attributes of an extension that should be splitted by keepOnSplit flag
|
|
@@ -12,9 +12,8 @@ export function getSplittedAttributes(
|
|
|
12
12
|
typeName: string,
|
|
13
13
|
attributes: Record<string, any>,
|
|
14
14
|
): Record<string, any> {
|
|
15
|
-
return Object.fromEntries(
|
|
16
|
-
.entries(attributes)
|
|
17
|
-
.filter(([name]) => {
|
|
15
|
+
return Object.fromEntries(
|
|
16
|
+
Object.entries(attributes).filter(([name]) => {
|
|
18
17
|
const extensionAttribute = extensionAttributes.find(item => {
|
|
19
18
|
return item.type === typeName && item.name === name
|
|
20
19
|
})
|
|
@@ -24,5 +23,6 @@ export function getSplittedAttributes(
|
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
return extensionAttribute.attribute.keepOnSplit
|
|
27
|
-
})
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
28
|
}
|
package/src/helpers/getText.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { TextSerializer } from '../types.js'
|
|
3
|
+
import type { TextSerializer } from '../types.js'
|
|
4
4
|
import { getTextBetween } from './getTextBetween.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { Range, TextSerializer } from '../types.js'
|
|
3
|
+
import type { Range, TextSerializer } from '../types.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Gets the text between two positions in a Prosemirror node
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedPos } from '@tiptap/pm/model'
|
|
1
|
+
import type { ResolvedPos } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns the text content of a resolved prosemirror position
|
|
@@ -11,22 +11,19 @@ export const getTextContentFromNodes = ($from: ResolvedPos, maxMatch = 500) => {
|
|
|
11
11
|
|
|
12
12
|
const sliceEndPos = $from.parentOffset
|
|
13
13
|
|
|
14
|
-
$from.parent.nodesBetween(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(node, pos, parent, index) => {
|
|
18
|
-
const chunk = node.type.spec.toText?.({
|
|
14
|
+
$from.parent.nodesBetween(Math.max(0, sliceEndPos - maxMatch), sliceEndPos, (node, pos, parent, index) => {
|
|
15
|
+
const chunk =
|
|
16
|
+
node.type.spec.toText?.({
|
|
19
17
|
node,
|
|
20
18
|
pos,
|
|
21
19
|
parent,
|
|
22
20
|
index,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
}) ||
|
|
22
|
+
node.textContent ||
|
|
23
|
+
'%leaf%'
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
25
|
+
textBefore += node.isAtom && !node.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos))
|
|
26
|
+
})
|
|
30
27
|
|
|
31
28
|
return textBefore
|
|
32
29
|
}
|
package/src/helpers/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from './findChildren.js'
|
|
|
7
7
|
export * from './findChildrenInRange.js'
|
|
8
8
|
export * from './findParentNode.js'
|
|
9
9
|
export * from './findParentNodeClosestToPos.js'
|
|
10
|
+
export * from './flattenExtensions.js'
|
|
10
11
|
export * from './generateHTML.js'
|
|
11
12
|
export * from './generateJSON.js'
|
|
12
13
|
export * from './generateText.js'
|
|
@@ -45,7 +46,9 @@ export * from './isNodeEmpty.js'
|
|
|
45
46
|
export * from './isNodeSelection.js'
|
|
46
47
|
export * from './isTextSelection.js'
|
|
47
48
|
export * from './posToDOMRect.js'
|
|
49
|
+
export * from './resolveExtensions.js'
|
|
48
50
|
export * from './resolveFocusPosition.js'
|
|
49
51
|
export * from './rewriteUnknownContent.js'
|
|
50
52
|
export * from './selectionToInsertionEnd.js'
|
|
53
|
+
export * from './sortExtensions.js'
|
|
51
54
|
export * from './splitExtensions.js'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ParseRule } from '@tiptap/pm/model'
|
|
1
|
+
import type { ParseRule } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { ExtensionAttribute } from '../types.js'
|
|
3
|
+
import type { ExtensionAttribute } from '../types.js'
|
|
4
4
|
import { fromString } from '../utilities/fromString.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -29,7 +29,7 @@ export function injectExtensionAttributesToParseRule(
|
|
|
29
29
|
const newAttributes = extensionAttributes.reduce((items, item) => {
|
|
30
30
|
const value = item.attribute.parseHTML
|
|
31
31
|
? item.attribute.parseHTML(node)
|
|
32
|
-
: fromString(
|
|
32
|
+
: fromString(node.getAttribute(item.name))
|
|
33
33
|
|
|
34
34
|
if (value === null || value === undefined) {
|
|
35
35
|
return items
|
package/src/helpers/isActive.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { EditorState } from '@tiptap/pm/state'
|
|
1
|
+
import type { EditorState } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
import { getSchemaTypeNameByName } from './getSchemaTypeNameByName.js'
|
|
4
4
|
import { isMarkActive } from './isMarkActive.js'
|
|
5
5
|
import { isNodeActive } from './isNodeActive.js'
|
|
6
6
|
|
|
7
|
-
export function isActive(
|
|
8
|
-
state: EditorState,
|
|
9
|
-
name: string | null,
|
|
10
|
-
attributes: Record<string, any> = {},
|
|
11
|
-
): boolean {
|
|
7
|
+
export function isActive(state: EditorState, name: string | null, attributes: Record<string, any> = {}): boolean {
|
|
12
8
|
if (!name) {
|
|
13
9
|
return isNodeActive(state, null, attributes) || isMarkActive(state, null, attributes)
|
|
14
10
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { AnyExtension, EnableRules } from '../types.js'
|
|
1
|
+
import type { AnyExtension, EnableRules } from '../types.js'
|
|
2
2
|
|
|
3
3
|
export function isExtensionRulesEnabled(extension: AnyExtension, enabled: EnableRules): boolean {
|
|
4
4
|
if (Array.isArray(enabled)) {
|
|
5
5
|
return enabled.some(enabledExtension => {
|
|
6
|
-
const name = typeof enabledExtension === 'string'
|
|
7
|
-
? enabledExtension
|
|
8
|
-
: enabledExtension.name
|
|
6
|
+
const name = typeof enabledExtension === 'string' ? enabledExtension : enabledExtension.name
|
|
9
7
|
|
|
10
8
|
return name === extension.name
|
|
11
9
|
})
|
package/src/helpers/isList.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getExtensionField } from '../helpers/getExtensionField.js'
|
|
2
|
-
import { NodeConfig } from '../index.js'
|
|
3
|
-
import { Extensions } from '../types.js'
|
|
2
|
+
import type { NodeConfig } from '../index.js'
|
|
3
|
+
import type { Extensions } from '../types.js'
|
|
4
4
|
import { callOrReturn } from '../utilities/callOrReturn.js'
|
|
5
5
|
import { splitExtensions } from './splitExtensions.js'
|
|
6
6
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
2
|
-
import { EditorState } from '@tiptap/pm/state'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
|
+
import type { EditorState } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
|
-
import { MarkRange } from '../types.js'
|
|
4
|
+
import type { MarkRange } from '../types.js'
|
|
5
5
|
import { objectIncludes } from '../utilities/objectIncludes.js'
|
|
6
6
|
import { getMarkType } from './getMarkType.js'
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
-
import { EditorState } from '@tiptap/pm/state'
|
|
1
|
+
import type { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import type { EditorState } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
|
-
import { NodeRange } from '../types.js'
|
|
4
|
+
import type { NodeRange } from '../types.js'
|
|
5
5
|
import { objectIncludes } from '../utilities/objectIncludes.js'
|
|
6
6
|
import { getNodeType } from './getNodeType.js'
|
|
7
7
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Returns true if the given prosemirror node is empty.
|
|
@@ -12,11 +12,11 @@ export function isNodeEmpty(
|
|
|
12
12
|
/**
|
|
13
13
|
* When true (default), it will also check if all children are empty.
|
|
14
14
|
*/
|
|
15
|
-
checkChildren?: boolean
|
|
15
|
+
checkChildren?: boolean
|
|
16
16
|
/**
|
|
17
17
|
* When true, it will ignore whitespace when checking for emptiness.
|
|
18
18
|
*/
|
|
19
|
-
ignoreWhitespace?: boolean
|
|
19
|
+
ignoreWhitespace?: boolean
|
|
20
20
|
} = {},
|
|
21
21
|
): boolean {
|
|
22
22
|
if (ignoreWhitespace) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Extensions } from '../types.js'
|
|
2
|
+
import { findDuplicates } from '../utilities/findDuplicates.js'
|
|
3
|
+
import { flattenExtensions } from './flattenExtensions.js'
|
|
4
|
+
import { sortExtensions } from './sortExtensions.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns a flattened and sorted extension list while
|
|
8
|
+
* also checking for duplicated extensions and warns the user.
|
|
9
|
+
* @param extensions An array of Tiptap extensions
|
|
10
|
+
* @returns An flattened and sorted array of Tiptap extensions
|
|
11
|
+
*/
|
|
12
|
+
export function resolveExtensions(extensions: Extensions): Extensions {
|
|
13
|
+
const resolvedExtensions = sortExtensions(flattenExtensions(extensions))
|
|
14
|
+
const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name))
|
|
15
|
+
|
|
16
|
+
if (duplicatedNames.length) {
|
|
17
|
+
console.warn(
|
|
18
|
+
`[tiptap warn]: Duplicate extension names found: [${duplicatedNames
|
|
19
|
+
.map(item => `'${item}'`)
|
|
20
|
+
.join(', ')}]. This can lead to issues.`,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return resolvedExtensions
|
|
25
|
+
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
2
|
import { Selection, TextSelection } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
|
-
import { FocusPosition } from '../types.js'
|
|
4
|
+
import type { FocusPosition } from '../types.js'
|
|
5
5
|
import { minMax } from '../utilities/minMax.js'
|
|
6
6
|
|
|
7
|
-
export function resolveFocusPosition(
|
|
8
|
-
doc: ProseMirrorNode,
|
|
9
|
-
position: FocusPosition = null,
|
|
10
|
-
): Selection | null {
|
|
7
|
+
export function resolveFocusPosition(doc: ProseMirrorNode, position: FocusPosition = null): Selection | null {
|
|
11
8
|
if (!position) {
|
|
12
9
|
return null
|
|
13
10
|
}
|
|
@@ -27,16 +24,8 @@ export function resolveFocusPosition(
|
|
|
27
24
|
const maxPos = selectionAtEnd.to
|
|
28
25
|
|
|
29
26
|
if (position === 'all') {
|
|
30
|
-
return TextSelection.create(
|
|
31
|
-
doc,
|
|
32
|
-
minMax(0, minPos, maxPos),
|
|
33
|
-
minMax(doc.content.size, minPos, maxPos),
|
|
34
|
-
)
|
|
27
|
+
return TextSelection.create(doc, minMax(0, minPos, maxPos), minMax(doc.content.size, minPos, maxPos))
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
return TextSelection.create(
|
|
38
|
-
doc,
|
|
39
|
-
minMax(position, minPos, maxPos),
|
|
40
|
-
minMax(position, minPos, maxPos),
|
|
41
|
-
)
|
|
30
|
+
return TextSelection.create(doc, minMax(position, minPos, maxPos), minMax(position, minPos, maxPos))
|
|
42
31
|
}
|
|
@@ -7,19 +7,19 @@ type RewriteUnknownContentOptions = {
|
|
|
7
7
|
* If true, unknown nodes will be treated as paragraphs
|
|
8
8
|
* @default true
|
|
9
9
|
*/
|
|
10
|
-
fallbackToParagraph?: boolean
|
|
11
|
-
}
|
|
10
|
+
fallbackToParagraph?: boolean
|
|
11
|
+
}
|
|
12
12
|
|
|
13
13
|
type RewrittenContent = {
|
|
14
14
|
/**
|
|
15
15
|
* The original JSON content that was rewritten
|
|
16
16
|
*/
|
|
17
|
-
original: JSONContent
|
|
17
|
+
original: JSONContent
|
|
18
18
|
/**
|
|
19
19
|
* The name of the node or mark that was unsupported
|
|
20
20
|
*/
|
|
21
|
-
unsupported: string
|
|
22
|
-
}[]
|
|
21
|
+
unsupported: string
|
|
22
|
+
}[]
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* The actual implementation of the rewriteUnknownContent function
|
|
@@ -31,20 +31,20 @@ function rewriteUnknownContentInner({
|
|
|
31
31
|
options,
|
|
32
32
|
rewrittenContent = [],
|
|
33
33
|
}: {
|
|
34
|
-
json: JSONContent
|
|
35
|
-
validMarks: Set<string
|
|
36
|
-
validNodes: Set<string
|
|
37
|
-
options?: RewriteUnknownContentOptions
|
|
38
|
-
rewrittenContent?: RewrittenContent
|
|
34
|
+
json: JSONContent
|
|
35
|
+
validMarks: Set<string>
|
|
36
|
+
validNodes: Set<string>
|
|
37
|
+
options?: RewriteUnknownContentOptions
|
|
38
|
+
rewrittenContent?: RewrittenContent
|
|
39
39
|
}): {
|
|
40
40
|
/**
|
|
41
41
|
* The cleaned JSON content
|
|
42
42
|
*/
|
|
43
|
-
json: JSONContent | null
|
|
43
|
+
json: JSONContent | null
|
|
44
44
|
/**
|
|
45
45
|
* The array of nodes and marks that were rewritten
|
|
46
46
|
*/
|
|
47
|
-
rewrittenContent: RewrittenContent
|
|
47
|
+
rewrittenContent: RewrittenContent
|
|
48
48
|
} {
|
|
49
49
|
if (json.marks && Array.isArray(json.marks)) {
|
|
50
50
|
json.marks = json.marks.filter(mark => {
|
|
@@ -66,13 +66,14 @@ function rewriteUnknownContentInner({
|
|
|
66
66
|
if (json.content && Array.isArray(json.content)) {
|
|
67
67
|
json.content = json.content
|
|
68
68
|
.map(
|
|
69
|
-
value =>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
value =>
|
|
70
|
+
rewriteUnknownContentInner({
|
|
71
|
+
json: value,
|
|
72
|
+
validMarks,
|
|
73
|
+
validNodes,
|
|
74
|
+
options,
|
|
75
|
+
rewrittenContent,
|
|
76
|
+
}).json,
|
|
76
77
|
)
|
|
77
78
|
.filter(a => a !== null && a !== undefined)
|
|
78
79
|
}
|
|
@@ -83,7 +84,7 @@ function rewriteUnknownContentInner({
|
|
|
83
84
|
unsupported: json.type,
|
|
84
85
|
})
|
|
85
86
|
|
|
86
|
-
if (json.content && Array.isArray(json.content) &&
|
|
87
|
+
if (json.content && Array.isArray(json.content) && options?.fallbackToParagraph !== false) {
|
|
87
88
|
// Just treat it like a paragraph and hope for the best
|
|
88
89
|
json.type = 'paragraph'
|
|
89
90
|
|
|
@@ -124,7 +125,7 @@ export function rewriteUnknownContent(
|
|
|
124
125
|
/**
|
|
125
126
|
* The cleaned JSON content
|
|
126
127
|
*/
|
|
127
|
-
json: JSONContent | null
|
|
128
|
+
json: JSONContent | null
|
|
128
129
|
/**
|
|
129
130
|
* The array of nodes and marks that were rewritten
|
|
130
131
|
*/
|
|
@@ -132,12 +133,12 @@ export function rewriteUnknownContent(
|
|
|
132
133
|
/**
|
|
133
134
|
* The original JSON content that was rewritten
|
|
134
135
|
*/
|
|
135
|
-
original: JSONContent
|
|
136
|
+
original: JSONContent
|
|
136
137
|
/**
|
|
137
138
|
* The name of the node or mark that was unsupported
|
|
138
139
|
*/
|
|
139
|
-
unsupported: string
|
|
140
|
-
}[]
|
|
140
|
+
unsupported: string
|
|
141
|
+
}[]
|
|
141
142
|
} {
|
|
142
143
|
return rewriteUnknownContentInner({
|
|
143
144
|
json,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
2
|
+
import { Selection } from '@tiptap/pm/state'
|
|
2
3
|
import { ReplaceAroundStep, ReplaceStep } from '@tiptap/pm/transform'
|
|
3
4
|
|
|
4
5
|
// source: https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|