@tiptap/core 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +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
|
@@ -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,14 +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
|
-
|
|
32
|
-
return commands.setNode(toggleType)
|
|
33
|
-
}
|
|
33
|
+
let attributesToCopy: Record<string, any> | undefined
|
|
34
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
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isActive) {
|
|
41
|
+
return commands.setNode(toggleType, attributesToCopy)
|
|
42
|
+
}
|
|
43
|
+
|
|
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
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RawCommands } from '../types.js'
|
|
1
|
+
import type { RawCommands } from '../types.js'
|
|
2
2
|
|
|
3
3
|
declare module '@tiptap/core' {
|
|
4
4
|
interface Commands<ReturnType> {
|
|
@@ -7,24 +7,26 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Remove all marks in the current selection.
|
|
8
8
|
* @example editor.commands.unsetAllMarks()
|
|
9
9
|
*/
|
|
10
|
-
unsetAllMarks: () => ReturnType
|
|
10
|
+
unsetAllMarks: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const unsetAllMarks: RawCommands['unsetAllMarks'] =
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
export const unsetAllMarks: RawCommands['unsetAllMarks'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ tr, dispatch }) => {
|
|
18
|
+
const { selection } = tr
|
|
19
|
+
const { empty, ranges } = selection
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (empty) {
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if (dispatch) {
|
|
26
|
+
ranges.forEach(range => {
|
|
27
|
+
tr.removeMark(range.$from.pos, range.$to.pos)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MarkType } from '@tiptap/pm/model'
|
|
1
|
+
import type { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarkRange } from '../helpers/getMarkRange.js'
|
|
4
4
|
import { getMarkType } from '../helpers/getMarkType.js'
|
|
5
|
-
import { RawCommands } from '../types.js'
|
|
5
|
+
import type { RawCommands } from '../types.js'
|
|
6
6
|
|
|
7
7
|
declare module '@tiptap/core' {
|
|
8
8
|
interface Commands<ReturnType> {
|
|
@@ -30,34 +30,36 @@ declare module '@tiptap/core' {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const unsetMark: RawCommands['unsetMark'] =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
export const unsetMark: RawCommands['unsetMark'] =
|
|
34
|
+
(typeOrName, options = {}) =>
|
|
35
|
+
({ tr, state, dispatch }) => {
|
|
36
|
+
const { extendEmptyMarkRange = false } = options
|
|
37
|
+
const { selection } = tr
|
|
38
|
+
const type = getMarkType(typeOrName, state.schema)
|
|
39
|
+
const { $from, empty, ranges } = selection
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (!dispatch) {
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (empty && extendEmptyMarkRange) {
|
|
46
|
+
let { from, to } = selection
|
|
47
|
+
const attrs = $from.marks().find(mark => mark.type === type)?.attrs
|
|
48
|
+
const range = getMarkRange($from, type, attrs)
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (range) {
|
|
51
|
+
from = range.from
|
|
52
|
+
to = range.to
|
|
53
|
+
}
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
tr.removeMark(from, to, type)
|
|
56
|
+
} else {
|
|
57
|
+
ranges.forEach(range => {
|
|
58
|
+
tr.removeMark(range.$from.pos, range.$to.pos, type)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
tr.removeStoredMark(type)
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { MarkType, NodeType } from '@tiptap/pm/model'
|
|
1
|
+
import type { Mark, MarkType, Node, NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import type { SelectionRange } from '@tiptap/pm/state'
|
|
2
3
|
|
|
3
4
|
import { getMarkType } from '../helpers/getMarkType.js'
|
|
4
5
|
import { getNodeType } from '../helpers/getNodeType.js'
|
|
5
6
|
import { getSchemaTypeNameByName } from '../helpers/getSchemaTypeNameByName.js'
|
|
6
|
-
import { RawCommands } from '../types.js'
|
|
7
|
+
import type { RawCommands } from '../types.js'
|
|
7
8
|
|
|
8
9
|
declare module '@tiptap/core' {
|
|
9
10
|
interface Commands<ReturnType> {
|
|
@@ -29,60 +30,111 @@ declare module '@tiptap/core' {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
export const updateAttributes: RawCommands['updateAttributes'] =
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
export const updateAttributes: RawCommands['updateAttributes'] =
|
|
34
|
+
(typeOrName, attributes = {}) =>
|
|
35
|
+
({ tr, state, dispatch }) => {
|
|
36
|
+
let nodeType: NodeType | null = null
|
|
37
|
+
let markType: MarkType | null = null
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const schemaType = getSchemaTypeNameByName(
|
|
40
|
+
typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
|
|
41
|
+
state.schema,
|
|
42
|
+
)
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
if (!schemaType) {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (schemaType === 'node') {
|
|
49
|
+
nodeType = getNodeType(typeOrName as NodeType, state.schema)
|
|
50
|
+
}
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
if (schemaType === 'mark') {
|
|
53
|
+
markType = getMarkType(typeOrName as MarkType, state.schema)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (dispatch) {
|
|
57
|
+
tr.selection.ranges.forEach((range: SelectionRange) => {
|
|
58
|
+
const from = range.$from.pos
|
|
59
|
+
const to = range.$to.pos
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
let lastPos: number | undefined
|
|
62
|
+
let lastNode: Node | undefined
|
|
63
|
+
let trimmedFrom: number
|
|
64
|
+
let trimmedTo: number
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
if (tr.selection.empty) {
|
|
67
|
+
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
68
|
+
if (nodeType && nodeType === node.type) {
|
|
69
|
+
trimmedFrom = Math.max(pos, from)
|
|
70
|
+
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
71
|
+
lastPos = pos
|
|
72
|
+
lastNode = node
|
|
73
|
+
}
|
|
63
74
|
})
|
|
64
|
-
}
|
|
75
|
+
} else {
|
|
76
|
+
state.doc.nodesBetween(from, to, (node: Node, pos: number) => {
|
|
77
|
+
if (pos < from && nodeType && nodeType === node.type) {
|
|
78
|
+
trimmedFrom = Math.max(pos, from)
|
|
79
|
+
trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
80
|
+
lastPos = pos
|
|
81
|
+
lastNode = node
|
|
82
|
+
}
|
|
65
83
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
71
|
-
|
|
72
|
-
tr.addMark(
|
|
73
|
-
trimmedFrom,
|
|
74
|
-
trimmedTo,
|
|
75
|
-
markType.create({
|
|
76
|
-
...mark.attrs,
|
|
84
|
+
if (pos >= from && pos <= to) {
|
|
85
|
+
if (nodeType && nodeType === node.type) {
|
|
86
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
87
|
+
...node.attrs,
|
|
77
88
|
...attributes,
|
|
78
|
-
})
|
|
79
|
-
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (markType && node.marks.length) {
|
|
93
|
+
node.marks.forEach((mark: Mark) => {
|
|
94
|
+
if (markType === mark.type) {
|
|
95
|
+
const trimmedFrom2 = Math.max(pos, from)
|
|
96
|
+
const trimmedTo2 = Math.min(pos + node.nodeSize, to)
|
|
97
|
+
|
|
98
|
+
tr.addMark(
|
|
99
|
+
trimmedFrom2,
|
|
100
|
+
trimmedTo2,
|
|
101
|
+
markType.create({
|
|
102
|
+
...mark.attrs,
|
|
103
|
+
...attributes,
|
|
104
|
+
}),
|
|
105
|
+
)
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
80
109
|
}
|
|
81
110
|
})
|
|
82
111
|
}
|
|
112
|
+
|
|
113
|
+
if (lastNode) {
|
|
114
|
+
if (lastPos !== undefined) {
|
|
115
|
+
tr.setNodeMarkup(lastPos, undefined, {
|
|
116
|
+
...lastNode.attrs,
|
|
117
|
+
...attributes,
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (markType && lastNode.marks.length) {
|
|
122
|
+
lastNode.marks.forEach((mark: Mark) => {
|
|
123
|
+
if (markType === mark.type) {
|
|
124
|
+
tr.addMark(
|
|
125
|
+
trimmedFrom,
|
|
126
|
+
trimmedTo,
|
|
127
|
+
markType.create({
|
|
128
|
+
...mark.attrs,
|
|
129
|
+
...attributes,
|
|
130
|
+
}),
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
}
|
|
83
136
|
})
|
|
84
|
-
}
|
|
85
|
-
}
|
|
137
|
+
}
|
|
86
138
|
|
|
87
|
-
|
|
88
|
-
}
|
|
139
|
+
return true
|
|
140
|
+
}
|