@tiptap/core 3.0.0 → 3.0.2
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 +5169 -4654
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3356 -0
- package/dist/index.d.ts +3356 -0
- package/dist/index.js +5051 -4561
- 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-dev-runtime/index.cjs +1 -0
- package/jsx-dev-runtime/index.d.cts +1 -0
- package/jsx-dev-runtime/index.d.ts +1 -0
- package/jsx-dev-runtime/index.js +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 +30 -10
- package/src/CommandManager.ts +4 -11
- package/src/Editor.ts +273 -100
- package/src/EventEmitter.ts +16 -10
- package/src/Extendable.ts +484 -0
- package/src/Extension.ts +29 -493
- package/src/ExtensionManager.ts +100 -143
- package/src/InputRule.ts +28 -24
- package/src/Mark.ts +157 -624
- package/src/MarkView.ts +122 -0
- package/src/Node.ts +343 -807
- package/src/NodePos.ts +18 -9
- package/src/NodeView.ts +58 -35
- package/src/PasteRule.ts +68 -24
- 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 +51 -53
- package/src/commands/forEach.ts +3 -3
- package/src/commands/insertContent.ts +8 -10
- package/src/commands/insertContentAt.ts +131 -76
- 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 +15 -8
- 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 +37 -40
- package/src/commands/setMark.ts +58 -60
- package/src/commands/setMeta.ts +10 -6
- package/src/commands/setNode.ts +36 -27
- 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 +60 -68
- package/src/commands/splitListItem.ts +99 -101
- package/src/commands/toggleList.ts +76 -74
- package/src/commands/toggleMark.ts +13 -11
- package/src/commands/toggleNode.ts +22 -11
- 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 +97 -45
- 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/drop.ts +26 -0
- package/src/extensions/focusEvents.ts +5 -7
- package/src/extensions/index.ts +4 -1
- package/src/extensions/keymap.ts +63 -52
- package/src/extensions/paste.ts +25 -0
- 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 +3 -3
- package/src/helpers/createNodeFromContent.ts +37 -25
- 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 +36 -19
- package/src/helpers/getMarkType.ts +2 -4
- package/src/helpers/getMarksBetween.ts +3 -3
- 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 -2
- package/src/helpers/getSchema.ts +5 -5
- package/src/helpers/getSchemaByResolvedExtensions.ts +49 -79
- 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 +4 -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 +56 -5
- 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 +149 -0
- 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 +6 -9
- package/src/inputRules/nodeInputRule.ts +7 -13
- package/src/inputRules/textInputRule.ts +4 -6
- package/src/inputRules/textblockTypeInputRule.ts +7 -12
- package/src/inputRules/wrappingInputRule.ts +19 -24
- package/src/jsx-runtime.ts +64 -0
- package/src/pasteRules/markPasteRule.ts +6 -7
- package/src/pasteRules/nodePasteRule.ts +15 -11
- package/src/pasteRules/textPasteRule.ts +4 -6
- package/src/style.ts +2 -6
- package/src/types.ts +513 -58
- package/src/utilities/callOrReturn.ts +1 -1
- package/src/utilities/canInsertNode.ts +30 -0
- 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 +5 -2
- package/src/utilities/index.ts +2 -0
- package/src/utilities/isFunction.ts +1 -0
- package/src/utilities/isMacOS.ts +1 -3
- package/src/utilities/isiOS.ts +5 -10
- package/src/utilities/mergeAttributes.ts +32 -5
- package/src/utilities/removeDuplicates.ts +1 -3
- package/dist/index.umd.js +0 -5098
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
package/src/ExtensionManager.ts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import { keymap } from '@tiptap/pm/keymap'
|
|
2
|
-
import {
|
|
3
|
-
import { Plugin } from '@tiptap/pm/state'
|
|
4
|
-
import {
|
|
2
|
+
import type { Schema } from '@tiptap/pm/model'
|
|
3
|
+
import type { Plugin } from '@tiptap/pm/state'
|
|
4
|
+
import type { MarkViewConstructor, NodeViewConstructor } from '@tiptap/pm/view'
|
|
5
5
|
|
|
6
6
|
import type { Editor } from './Editor.js'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
import {
|
|
8
|
+
flattenExtensions,
|
|
9
|
+
getAttributesFromExtensions,
|
|
10
|
+
getExtensionField,
|
|
11
|
+
getNodeType,
|
|
12
|
+
getRenderedAttributes,
|
|
13
|
+
getSchemaByResolvedExtensions,
|
|
14
|
+
getSchemaTypeByName,
|
|
15
|
+
isExtensionRulesEnabled,
|
|
16
|
+
resolveExtensions,
|
|
17
|
+
sortExtensions,
|
|
18
|
+
splitExtensions,
|
|
19
|
+
} from './helpers/index.js'
|
|
20
|
+
import { type MarkConfig, type NodeConfig, type Storage, getMarkType, updateMarkViewAttributes } from './index.js'
|
|
21
|
+
import type { InputRule } from './InputRule.js'
|
|
22
|
+
import { inputRulesPlugin } from './InputRule.js'
|
|
23
|
+
import { Mark } from './Mark.js'
|
|
24
|
+
import type { PasteRule } from './PasteRule.js'
|
|
25
|
+
import { pasteRulesPlugin } from './PasteRule.js'
|
|
26
|
+
import type { AnyConfig, Extensions, RawCommands } from './types.js'
|
|
19
27
|
import { callOrReturn } from './utilities/callOrReturn.js'
|
|
20
|
-
import { findDuplicates } from './utilities/findDuplicates.js'
|
|
21
28
|
|
|
22
29
|
export class ExtensionManager {
|
|
23
30
|
editor: Editor
|
|
@@ -30,87 +37,16 @@ export class ExtensionManager {
|
|
|
30
37
|
|
|
31
38
|
constructor(extensions: Extensions, editor: Editor) {
|
|
32
39
|
this.editor = editor
|
|
33
|
-
this.extensions =
|
|
40
|
+
this.extensions = resolveExtensions(extensions)
|
|
34
41
|
this.schema = getSchemaByResolvedExtensions(this.extensions, editor)
|
|
35
42
|
this.setupExtensions()
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
|
|
39
|
-
* Returns a flattened and sorted extension list while
|
|
40
|
-
* also checking for duplicated extensions and warns the user.
|
|
41
|
-
* @param extensions An array of Tiptap extensions
|
|
42
|
-
* @returns An flattened and sorted array of Tiptap extensions
|
|
43
|
-
*/
|
|
44
|
-
static resolve(extensions: Extensions): Extensions {
|
|
45
|
-
const resolvedExtensions = ExtensionManager.sort(ExtensionManager.flatten(extensions))
|
|
46
|
-
const duplicatedNames = findDuplicates(resolvedExtensions.map(extension => extension.name))
|
|
47
|
-
|
|
48
|
-
if (duplicatedNames.length) {
|
|
49
|
-
console.warn(
|
|
50
|
-
`[tiptap warn]: Duplicate extension names found: [${duplicatedNames
|
|
51
|
-
.map(item => `'${item}'`)
|
|
52
|
-
.join(', ')}]. This can lead to issues.`,
|
|
53
|
-
)
|
|
54
|
-
}
|
|
45
|
+
static resolve = resolveExtensions
|
|
55
46
|
|
|
56
|
-
|
|
57
|
-
}
|
|
47
|
+
static sort = sortExtensions
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
* Create a flattened array of extensions by traversing the `addExtensions` field.
|
|
61
|
-
* @param extensions An array of Tiptap extensions
|
|
62
|
-
* @returns A flattened array of Tiptap extensions
|
|
63
|
-
*/
|
|
64
|
-
static flatten(extensions: Extensions): Extensions {
|
|
65
|
-
return (
|
|
66
|
-
extensions
|
|
67
|
-
.map(extension => {
|
|
68
|
-
const context = {
|
|
69
|
-
name: extension.name,
|
|
70
|
-
options: extension.options,
|
|
71
|
-
storage: extension.storage,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const addExtensions = getExtensionField<AnyConfig['addExtensions']>(
|
|
75
|
-
extension,
|
|
76
|
-
'addExtensions',
|
|
77
|
-
context,
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
if (addExtensions) {
|
|
81
|
-
return [extension, ...this.flatten(addExtensions())]
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return extension
|
|
85
|
-
})
|
|
86
|
-
// `Infinity` will break TypeScript so we set a number that is probably high enough
|
|
87
|
-
.flat(10)
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Sort extensions by priority.
|
|
93
|
-
* @param extensions An array of Tiptap extensions
|
|
94
|
-
* @returns A sorted array of Tiptap extensions by priority
|
|
95
|
-
*/
|
|
96
|
-
static sort(extensions: Extensions): Extensions {
|
|
97
|
-
const defaultPriority = 100
|
|
98
|
-
|
|
99
|
-
return extensions.sort((a, b) => {
|
|
100
|
-
const priorityA = getExtensionField<AnyConfig['priority']>(a, 'priority') || defaultPriority
|
|
101
|
-
const priorityB = getExtensionField<AnyConfig['priority']>(b, 'priority') || defaultPriority
|
|
102
|
-
|
|
103
|
-
if (priorityA > priorityB) {
|
|
104
|
-
return -1
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (priorityA < priorityB) {
|
|
108
|
-
return 1
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return 0
|
|
112
|
-
})
|
|
113
|
-
}
|
|
49
|
+
static flatten = flattenExtensions
|
|
114
50
|
|
|
115
51
|
/**
|
|
116
52
|
* Get all commands from the extensions.
|
|
@@ -121,16 +57,12 @@ export class ExtensionManager {
|
|
|
121
57
|
const context = {
|
|
122
58
|
name: extension.name,
|
|
123
59
|
options: extension.options,
|
|
124
|
-
storage: extension.
|
|
60
|
+
storage: this.editor.extensionStorage[extension.name as keyof Storage],
|
|
125
61
|
editor: this.editor,
|
|
126
62
|
type: getSchemaTypeByName(extension.name, this.schema),
|
|
127
63
|
}
|
|
128
64
|
|
|
129
|
-
const addCommands = getExtensionField<AnyConfig['addCommands']>(
|
|
130
|
-
extension,
|
|
131
|
-
'addCommands',
|
|
132
|
-
context,
|
|
133
|
-
)
|
|
65
|
+
const addCommands = getExtensionField<AnyConfig['addCommands']>(extension, 'addCommands', context)
|
|
134
66
|
|
|
135
67
|
if (!addCommands) {
|
|
136
68
|
return commands
|
|
@@ -155,7 +87,7 @@ export class ExtensionManager {
|
|
|
155
87
|
// so it feels more natural to run plugins at the end of an array first.
|
|
156
88
|
// That’s why we have to reverse the `extensions` array and sort again
|
|
157
89
|
// based on the `priority` option.
|
|
158
|
-
const extensions =
|
|
90
|
+
const extensions = sortExtensions([...this.extensions].reverse())
|
|
159
91
|
|
|
160
92
|
const inputRules: InputRule[] = []
|
|
161
93
|
const pasteRules: PasteRule[] = []
|
|
@@ -165,7 +97,7 @@ export class ExtensionManager {
|
|
|
165
97
|
const context = {
|
|
166
98
|
name: extension.name,
|
|
167
99
|
options: extension.options,
|
|
168
|
-
storage: extension.
|
|
100
|
+
storage: this.editor.extensionStorage[extension.name as keyof Storage],
|
|
169
101
|
editor,
|
|
170
102
|
type: getSchemaTypeByName(extension.name, this.schema),
|
|
171
103
|
}
|
|
@@ -181,7 +113,7 @@ export class ExtensionManager {
|
|
|
181
113
|
let defaultBindings: Record<string, () => boolean> = {}
|
|
182
114
|
|
|
183
115
|
// bind exit handling
|
|
184
|
-
if (extension.type === 'mark' && getExtensionField<
|
|
116
|
+
if (extension.type === 'mark' && getExtensionField<MarkConfig['exitable']>(extension, 'exitable', context)) {
|
|
185
117
|
defaultBindings.ArrowRight = () => Mark.handleExit({ editor, mark: extension as Mark })
|
|
186
118
|
}
|
|
187
119
|
|
|
@@ -199,21 +131,13 @@ export class ExtensionManager {
|
|
|
199
131
|
|
|
200
132
|
plugins.push(keyMapPlugin)
|
|
201
133
|
|
|
202
|
-
const addInputRules = getExtensionField<AnyConfig['addInputRules']>(
|
|
203
|
-
extension,
|
|
204
|
-
'addInputRules',
|
|
205
|
-
context,
|
|
206
|
-
)
|
|
134
|
+
const addInputRules = getExtensionField<AnyConfig['addInputRules']>(extension, 'addInputRules', context)
|
|
207
135
|
|
|
208
136
|
if (isExtensionRulesEnabled(extension, editor.options.enableInputRules) && addInputRules) {
|
|
209
137
|
inputRules.push(...addInputRules())
|
|
210
138
|
}
|
|
211
139
|
|
|
212
|
-
const addPasteRules = getExtensionField<AnyConfig['addPasteRules']>(
|
|
213
|
-
extension,
|
|
214
|
-
'addPasteRules',
|
|
215
|
-
context,
|
|
216
|
-
)
|
|
140
|
+
const addPasteRules = getExtensionField<AnyConfig['addPasteRules']>(extension, 'addPasteRules', context)
|
|
217
141
|
|
|
218
142
|
if (isExtensionRulesEnabled(extension, editor.options.enablePasteRules) && addPasteRules) {
|
|
219
143
|
pasteRules.push(...addPasteRules())
|
|
@@ -260,7 +184,7 @@ export class ExtensionManager {
|
|
|
260
184
|
* Get all node views from the extensions.
|
|
261
185
|
* @returns An object with all node views where the key is the node name and the value is the node view function
|
|
262
186
|
*/
|
|
263
|
-
get nodeViews() {
|
|
187
|
+
get nodeViews(): Record<string, NodeViewConstructor> {
|
|
264
188
|
const { editor } = this
|
|
265
189
|
const { nodeExtensions } = splitExtensions(this.extensions)
|
|
266
190
|
|
|
@@ -268,41 +192,34 @@ export class ExtensionManager {
|
|
|
268
192
|
nodeExtensions
|
|
269
193
|
.filter(extension => !!getExtensionField(extension, 'addNodeView'))
|
|
270
194
|
.map(extension => {
|
|
271
|
-
const extensionAttributes = this.attributes.filter(
|
|
272
|
-
attribute => attribute.type === extension.name,
|
|
273
|
-
)
|
|
195
|
+
const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)
|
|
274
196
|
const context = {
|
|
275
197
|
name: extension.name,
|
|
276
198
|
options: extension.options,
|
|
277
|
-
storage: extension.
|
|
199
|
+
storage: this.editor.extensionStorage[extension.name as keyof Storage],
|
|
278
200
|
editor,
|
|
279
201
|
type: getNodeType(extension.name, this.schema),
|
|
280
202
|
}
|
|
281
|
-
const addNodeView = getExtensionField<NodeConfig['addNodeView']>(
|
|
282
|
-
extension,
|
|
283
|
-
'addNodeView',
|
|
284
|
-
context,
|
|
285
|
-
)
|
|
203
|
+
const addNodeView = getExtensionField<NodeConfig['addNodeView']>(extension, 'addNodeView', context)
|
|
286
204
|
|
|
287
205
|
if (!addNodeView) {
|
|
288
206
|
return []
|
|
289
207
|
}
|
|
290
208
|
|
|
291
|
-
const nodeview = (
|
|
292
|
-
node: ProsemirrorNode,
|
|
293
|
-
view: EditorView,
|
|
294
|
-
getPos: (() => number) | boolean,
|
|
295
|
-
decorations: Decoration[],
|
|
296
|
-
) => {
|
|
209
|
+
const nodeview: NodeViewConstructor = (node, view, getPos, decorations, innerDecorations) => {
|
|
297
210
|
const HTMLAttributes = getRenderedAttributes(node, extensionAttributes)
|
|
298
211
|
|
|
299
212
|
return addNodeView()({
|
|
300
|
-
|
|
213
|
+
// pass-through
|
|
301
214
|
node,
|
|
302
|
-
|
|
215
|
+
view,
|
|
216
|
+
getPos: getPos as () => number,
|
|
303
217
|
decorations,
|
|
304
|
-
|
|
218
|
+
innerDecorations,
|
|
219
|
+
// tiptap-specific
|
|
220
|
+
editor,
|
|
305
221
|
extension,
|
|
222
|
+
HTMLAttributes,
|
|
306
223
|
})
|
|
307
224
|
}
|
|
308
225
|
|
|
@@ -311,19 +228,67 @@ export class ExtensionManager {
|
|
|
311
228
|
)
|
|
312
229
|
}
|
|
313
230
|
|
|
231
|
+
get markViews(): Record<string, MarkViewConstructor> {
|
|
232
|
+
const { editor } = this
|
|
233
|
+
const { markExtensions } = splitExtensions(this.extensions)
|
|
234
|
+
|
|
235
|
+
return Object.fromEntries(
|
|
236
|
+
markExtensions
|
|
237
|
+
.filter(extension => !!getExtensionField(extension, 'addMarkView'))
|
|
238
|
+
.map(extension => {
|
|
239
|
+
const extensionAttributes = this.attributes.filter(attribute => attribute.type === extension.name)
|
|
240
|
+
const context = {
|
|
241
|
+
name: extension.name,
|
|
242
|
+
options: extension.options,
|
|
243
|
+
storage: this.editor.extensionStorage[extension.name as keyof Storage],
|
|
244
|
+
editor,
|
|
245
|
+
type: getMarkType(extension.name, this.schema),
|
|
246
|
+
}
|
|
247
|
+
const addMarkView = getExtensionField<MarkConfig['addMarkView']>(extension, 'addMarkView', context)
|
|
248
|
+
|
|
249
|
+
if (!addMarkView) {
|
|
250
|
+
return []
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const markView: MarkViewConstructor = (mark, view, inline) => {
|
|
254
|
+
const HTMLAttributes = getRenderedAttributes(mark, extensionAttributes)
|
|
255
|
+
|
|
256
|
+
return addMarkView()({
|
|
257
|
+
// pass-through
|
|
258
|
+
mark,
|
|
259
|
+
view,
|
|
260
|
+
inline,
|
|
261
|
+
// tiptap-specific
|
|
262
|
+
editor,
|
|
263
|
+
extension,
|
|
264
|
+
HTMLAttributes,
|
|
265
|
+
updateAttributes: (attrs: Record<string, any>) => {
|
|
266
|
+
updateMarkViewAttributes(mark, editor, attrs)
|
|
267
|
+
},
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return [extension.name, markView]
|
|
272
|
+
}),
|
|
273
|
+
)
|
|
274
|
+
}
|
|
275
|
+
|
|
314
276
|
/**
|
|
315
277
|
* Go through all extensions, create extension storages & setup marks
|
|
316
278
|
* & bind editor event listener.
|
|
317
279
|
*/
|
|
318
280
|
private setupExtensions() {
|
|
319
|
-
this.extensions
|
|
320
|
-
|
|
321
|
-
|
|
281
|
+
const extensions = this.extensions
|
|
282
|
+
// re-initialize the extension storage object instance
|
|
283
|
+
this.editor.extensionStorage = Object.fromEntries(
|
|
284
|
+
extensions.map(extension => [extension.name, extension.storage]),
|
|
285
|
+
) as unknown as Storage
|
|
322
286
|
|
|
287
|
+
extensions.forEach(extension => {
|
|
323
288
|
const context = {
|
|
324
289
|
name: extension.name,
|
|
325
290
|
options: extension.options,
|
|
326
|
-
storage: extension.
|
|
291
|
+
storage: this.editor.extensionStorage[extension.name as keyof Storage],
|
|
327
292
|
editor: this.editor,
|
|
328
293
|
type: getSchemaTypeByName(extension.name, this.schema),
|
|
329
294
|
}
|
|
@@ -336,11 +301,7 @@ export class ExtensionManager {
|
|
|
336
301
|
}
|
|
337
302
|
}
|
|
338
303
|
|
|
339
|
-
const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(
|
|
340
|
-
extension,
|
|
341
|
-
'onBeforeCreate',
|
|
342
|
-
context,
|
|
343
|
-
)
|
|
304
|
+
const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(extension, 'onBeforeCreate', context)
|
|
344
305
|
const onCreate = getExtensionField<AnyConfig['onCreate']>(extension, 'onCreate', context)
|
|
345
306
|
const onUpdate = getExtensionField<AnyConfig['onUpdate']>(extension, 'onUpdate', context)
|
|
346
307
|
const onSelectionUpdate = getExtensionField<AnyConfig['onSelectionUpdate']>(
|
|
@@ -348,11 +309,7 @@ export class ExtensionManager {
|
|
|
348
309
|
'onSelectionUpdate',
|
|
349
310
|
context,
|
|
350
311
|
)
|
|
351
|
-
const onTransaction = getExtensionField<AnyConfig['onTransaction']>(
|
|
352
|
-
extension,
|
|
353
|
-
'onTransaction',
|
|
354
|
-
context,
|
|
355
|
-
)
|
|
312
|
+
const onTransaction = getExtensionField<AnyConfig['onTransaction']>(extension, 'onTransaction', context)
|
|
356
313
|
const onFocus = getExtensionField<AnyConfig['onFocus']>(extension, 'onFocus', context)
|
|
357
314
|
const onBlur = getExtensionField<AnyConfig['onBlur']>(extension, 'onBlur', context)
|
|
358
315
|
const onDestroy = getExtensionField<AnyConfig['onDestroy']>(extension, 'onDestroy', context)
|
package/src/InputRule.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
2
|
+
import { Fragment } from '@tiptap/pm/model'
|
|
3
|
+
import type { EditorState, TextSelection } from '@tiptap/pm/state'
|
|
4
|
+
import { Plugin } from '@tiptap/pm/state'
|
|
2
5
|
|
|
3
6
|
import { CommandManager } from './CommandManager.js'
|
|
4
|
-
import { Editor } from './Editor.js'
|
|
7
|
+
import type { Editor } from './Editor.js'
|
|
5
8
|
import { createChainableState } from './helpers/createChainableState.js'
|
|
9
|
+
import { getHTMLFromFragment } from './helpers/getHTMLFromFragment.js'
|
|
6
10
|
import { getTextContentFromNodes } from './helpers/getTextContentFromNodes.js'
|
|
7
|
-
import {
|
|
8
|
-
CanCommands,
|
|
9
|
-
ChainedCommands,
|
|
10
|
-
ExtendedRegExpMatchArray,
|
|
11
|
-
Range,
|
|
12
|
-
SingleCommands,
|
|
13
|
-
} from './types.js'
|
|
11
|
+
import type { CanCommands, ChainedCommands, ExtendedRegExpMatchArray, Range, SingleCommands } from './types.js'
|
|
14
12
|
import { isRegExp } from './utilities/isRegExp.js'
|
|
15
13
|
|
|
16
14
|
export type InputRuleMatch = {
|
|
@@ -51,10 +49,7 @@ export class InputRule {
|
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
const inputRuleMatcherHandler = (
|
|
55
|
-
text: string,
|
|
56
|
-
find: InputRuleFinder,
|
|
57
|
-
): ExtendedRegExpMatchArray | null => {
|
|
52
|
+
const inputRuleMatcherHandler = (text: string, find: InputRuleFinder): ExtendedRegExpMatchArray | null => {
|
|
58
53
|
if (isRegExp(find)) {
|
|
59
54
|
return find.exec(text)
|
|
60
55
|
}
|
|
@@ -73,9 +68,7 @@ const inputRuleMatcherHandler = (
|
|
|
73
68
|
|
|
74
69
|
if (inputRuleMatch.replaceWith) {
|
|
75
70
|
if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
|
|
76
|
-
console.warn(
|
|
77
|
-
'[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".',
|
|
78
|
-
)
|
|
71
|
+
console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".')
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
result.push(inputRuleMatch.replaceWith)
|
|
@@ -92,9 +85,7 @@ function run(config: {
|
|
|
92
85
|
rules: InputRule[]
|
|
93
86
|
plugin: Plugin
|
|
94
87
|
}): boolean {
|
|
95
|
-
const {
|
|
96
|
-
editor, from, to, text, rules, plugin,
|
|
97
|
-
} = config
|
|
88
|
+
const { editor, from, to, text, rules, plugin } = config
|
|
98
89
|
const { view } = editor
|
|
99
90
|
|
|
100
91
|
if (view.composing) {
|
|
@@ -105,9 +96,9 @@ function run(config: {
|
|
|
105
96
|
|
|
106
97
|
if (
|
|
107
98
|
// check for code node
|
|
108
|
-
$from.parent.type.spec.code
|
|
99
|
+
$from.parent.type.spec.code ||
|
|
109
100
|
// check for code mark
|
|
110
|
-
|
|
101
|
+
!!($from.nodeBefore || $from.nodeAfter)?.marks.find(mark => mark.type.spec.code)
|
|
111
102
|
) {
|
|
112
103
|
return false
|
|
113
104
|
}
|
|
@@ -184,7 +175,7 @@ export function inputRulesPlugin(props: { editor: Editor; rules: InputRule[] }):
|
|
|
184
175
|
init() {
|
|
185
176
|
return null
|
|
186
177
|
},
|
|
187
|
-
apply(tr, prev) {
|
|
178
|
+
apply(tr, prev, state) {
|
|
188
179
|
const stored = tr.getMeta(plugin)
|
|
189
180
|
|
|
190
181
|
if (stored) {
|
|
@@ -192,12 +183,25 @@ export function inputRulesPlugin(props: { editor: Editor; rules: InputRule[] }):
|
|
|
192
183
|
}
|
|
193
184
|
|
|
194
185
|
// if InputRule is triggered by insertContent()
|
|
195
|
-
const simulatedInputMeta = tr.getMeta('applyInputRules')
|
|
186
|
+
const simulatedInputMeta = tr.getMeta('applyInputRules') as
|
|
187
|
+
| undefined
|
|
188
|
+
| {
|
|
189
|
+
from: number
|
|
190
|
+
text: string | ProseMirrorNode | Fragment
|
|
191
|
+
}
|
|
196
192
|
const isSimulatedInput = !!simulatedInputMeta
|
|
197
193
|
|
|
198
194
|
if (isSimulatedInput) {
|
|
199
195
|
setTimeout(() => {
|
|
200
|
-
|
|
196
|
+
let { text } = simulatedInputMeta
|
|
197
|
+
|
|
198
|
+
if (typeof text === 'string') {
|
|
199
|
+
text = text as string
|
|
200
|
+
} else {
|
|
201
|
+
text = getHTMLFromFragment(Fragment.from(text), state.schema)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const { from } = simulatedInputMeta
|
|
201
205
|
const to = from + text.length
|
|
202
206
|
|
|
203
207
|
run({
|