@tiptap/core 2.0.0-beta.209 → 2.0.0-beta.210
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/dist/index.cjs +4311 -0
- package/dist/index.d.ts +2330 -0
- package/dist/index.js +4311 -0
- package/package.json +24 -23
- package/src/CommandManager.ts +27 -36
- package/src/Editor.ts +27 -37
- package/src/Extension.ts +193 -179
- package/src/ExtensionManager.ts +82 -98
- package/src/InputRule.ts +38 -43
- package/src/Mark.ts +277 -264
- package/src/Node.ts +349 -314
- package/src/NodeView.ts +24 -23
- package/src/PasteRule.ts +37 -44
- package/src/Tracker.ts +4 -8
- package/src/commands/clearNodes.ts +1 -1
- package/src/commands/createParagraphNear.ts +2 -2
- package/src/commands/deleteNode.ts +1 -1
- package/src/commands/deleteSelection.ts +2 -2
- package/src/commands/exitCode.ts +2 -2
- package/src/commands/extendMarkRange.ts +6 -3
- package/src/commands/insertContent.ts +9 -5
- package/src/commands/insertContentAt.ts +10 -24
- package/src/commands/join.ts +9 -6
- package/src/commands/lift.ts +3 -3
- package/src/commands/liftEmptyBlock.ts +1 -1
- package/src/commands/liftListItem.ts +3 -3
- package/src/commands/newlineInCode.ts +2 -2
- package/src/commands/resetAttributes.ts +11 -6
- package/src/commands/selectNodeBackward.ts +2 -2
- package/src/commands/selectNodeForward.ts +2 -2
- package/src/commands/selectParentNode.ts +2 -2
- package/src/commands/selectTextblockEnd.ts +2 -2
- package/src/commands/selectTextblockStart.ts +2 -2
- package/src/commands/setContent.ts +3 -4
- package/src/commands/setMark.ts +26 -16
- package/src/commands/setNode.ts +19 -17
- package/src/commands/setNodeSelection.ts +2 -2
- package/src/commands/setTextSelection.ts +3 -5
- package/src/commands/sinkListItem.ts +3 -3
- package/src/commands/splitBlock.ts +20 -25
- package/src/commands/splitListItem.ts +15 -25
- package/src/commands/toggleList.ts +27 -24
- package/src/commands/toggleMark.ts +3 -3
- package/src/commands/toggleNode.ts +6 -2
- package/src/commands/toggleWrap.ts +2 -2
- package/src/commands/unsetMark.ts +3 -3
- package/src/commands/updateAttributes.ts +14 -9
- package/src/commands/wrapIn.ts +3 -3
- package/src/commands/wrapInList.ts +3 -3
- package/src/extensions/clipboardTextSerializer.ts +1 -1
- package/src/extensions/editable.ts +1 -1
- package/src/extensions/focusEvents.ts +1 -1
- package/src/extensions/keymap.ts +2 -7
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +7 -4
- package/src/helpers/createChainableState.ts +3 -3
- package/src/helpers/createDocument.ts +1 -1
- package/src/helpers/createNodeFromContent.ts +4 -10
- package/src/helpers/defaultBlockAt.ts +1 -1
- package/src/helpers/findChildren.ts +1 -1
- package/src/helpers/findChildrenInRange.ts +6 -2
- package/src/helpers/findParentNode.ts +1 -1
- package/src/helpers/findParentNodeClosestToPos.ts +12 -7
- package/src/helpers/generateHTML.ts +1 -1
- package/src/helpers/generateJSON.ts +2 -4
- package/src/helpers/generateText.ts +4 -7
- package/src/helpers/getAttributes.ts +3 -5
- package/src/helpers/getChangedRanges.ts +1 -1
- package/src/helpers/getDebugJSON.ts +4 -4
- package/src/helpers/getHTMLFromFragment.ts +2 -4
- package/src/helpers/getMarkAttributes.ts +6 -3
- package/src/helpers/getMarkRange.ts +1 -1
- package/src/helpers/getMarkType.ts +4 -2
- package/src/helpers/getMarksBetween.ts +8 -6
- package/src/helpers/getNodeAttributes.ts +7 -6
- package/src/helpers/getNodeType.ts +4 -2
- package/src/helpers/getRenderedAttributes.ts +5 -2
- package/src/helpers/getSchema.ts +1 -1
- package/src/helpers/getSchemaByResolvedExtensions.ts +151 -107
- package/src/helpers/getSchemaTypeByName.ts +1 -1
- package/src/helpers/getSchemaTypeNameByName.ts +1 -1
- package/src/helpers/getText.ts +3 -3
- package/src/helpers/getTextBetween.ts +4 -7
- package/src/helpers/getTextContentFromNodes.ts +8 -3
- package/src/helpers/getTextSerializersFromSchema.ts +6 -5
- package/src/helpers/injectExtensionAttributesToParseRule.ts +6 -5
- package/src/helpers/isActive.ts +6 -2
- package/src/helpers/isMarkActive.ts +12 -15
- package/src/helpers/isNodeActive.ts +4 -7
- package/src/helpers/isNodeEmpty.ts +1 -1
- package/src/helpers/isNodeSelection.ts +1 -1
- package/src/helpers/isTextSelection.ts +1 -1
- package/src/helpers/posToDOMRect.ts +1 -1
- package/src/helpers/resolveFocusPosition.ts +2 -3
- package/src/helpers/selectionToInsertionEnd.ts +2 -2
- package/src/inputRules/markInputRule.ts +3 -4
- package/src/inputRules/nodeInputRule.ts +3 -4
- package/src/inputRules/textblockTypeInputRule.ts +3 -4
- package/src/inputRules/wrappingInputRule.ts +5 -6
- package/src/pasteRules/markPasteRule.ts +3 -4
- package/src/pasteRules/nodePasteRule.ts +8 -10
- package/src/types.ts +109 -125
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -147
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -227
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -18
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -327
- package/dist/packages/core/src/Node.d.ts +0 -397
- package/dist/packages/core/src/NodeView.d.ts +0 -27
- package/dist/packages/core/src/PasteRule.d.ts +0 -42
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -12
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -12
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -12
- package/dist/packages/core/src/commands/command.d.ts +0 -12
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -12
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/enter.d.ts +0 -12
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -12
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -13
- package/dist/packages/core/src/commands/first.d.ts +0 -12
- package/dist/packages/core/src/commands/focus.d.ts +0 -14
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -50
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -16
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -16
- package/dist/packages/core/src/commands/join.d.ts +0 -33
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -12
- package/dist/packages/core/src/commands/lift.d.ts +0 -13
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -12
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -12
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -12
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -12
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -12
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -12
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -12
- package/dist/packages/core/src/commands/setContent.d.ts +0 -13
- package/dist/packages/core/src/commands/setMark.d.ts +0 -13
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -12
- package/dist/packages/core/src/commands/setNode.d.ts +0 -13
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -12
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -14
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -13
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -13
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -12
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -18
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -13
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -13
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -2
- 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 -7
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -5
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -3
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -7
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -2
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -3
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -6
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -8
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -2
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -2
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -5
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -3
- 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 -2
- 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/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 -3
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -2
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -2
- package/dist/packages/core/src/helpers/getText.d.ts +0 -6
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -6
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -2
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -3
- package/dist/packages/core/src/helpers/index.d.ts +0 -33
- 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/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 -23
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -12
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -12
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -9
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -14
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -23
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -12
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -12
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -9
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -214
- 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/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/dist/tiptap-core.cjs +0 -4360
- package/dist/tiptap-core.cjs.map +0 -1
- package/dist/tiptap-core.esm.js +0 -4284
- package/dist/tiptap-core.esm.js.map +0 -1
- package/dist/tiptap-core.umd.js +0 -4358
- package/dist/tiptap-core.umd.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
// TODO: add types to @types/prosemirror-commands
|
|
3
|
-
import { selectTextblockStart as originalSelectTextblockStart } from '
|
|
3
|
+
import { selectTextblockStart as originalSelectTextblockStart } from '@tiptap/pm/commands'
|
|
4
4
|
|
|
5
5
|
import { RawCommands } from '../types'
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Moves the cursor to the start of current text block.
|
|
12
12
|
*/
|
|
13
|
-
selectTextblockStart: () => ReturnType
|
|
13
|
+
selectTextblockStart: () => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParseOptions } from '
|
|
1
|
+
import { ParseOptions } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { createDocument } from '../helpers/createDocument'
|
|
4
4
|
import { Content, RawCommands } from '../types'
|
|
@@ -13,7 +13,7 @@ declare module '@tiptap/core' {
|
|
|
13
13
|
content: Content,
|
|
14
14
|
emitUpdate?: boolean,
|
|
15
15
|
parseOptions?: ParseOptions,
|
|
16
|
-
) => ReturnType
|
|
16
|
+
) => ReturnType
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -23,8 +23,7 @@ export const setContent: RawCommands['setContent'] = (content, emitUpdate = fals
|
|
|
23
23
|
const document = createDocument(content, editor.schema, parseOptions)
|
|
24
24
|
|
|
25
25
|
if (dispatch) {
|
|
26
|
-
tr.replaceWith(0, doc.content.size, document)
|
|
27
|
-
.setMeta('preventUpdate', !emitUpdate)
|
|
26
|
+
tr.replaceWith(0, doc.content.size, document).setMeta('preventUpdate', !emitUpdate)
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
return true
|
package/src/commands/setMark.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MarkType, ResolvedPos } from '
|
|
2
|
-
import { EditorState, Transaction } from '
|
|
1
|
+
import { MarkType, ResolvedPos } from '@tiptap/pm/model'
|
|
2
|
+
import { EditorState, Transaction } from '@tiptap/pm/state'
|
|
3
3
|
|
|
4
4
|
import { isTextSelection } from '../helpers'
|
|
5
5
|
import { getMarkAttributes } from '../helpers/getMarkAttributes'
|
|
@@ -12,7 +12,7 @@ declare module '@tiptap/core' {
|
|
|
12
12
|
/**
|
|
13
13
|
* Add a mark with new attributes.
|
|
14
14
|
*/
|
|
15
|
-
setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType
|
|
15
|
+
setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -29,13 +29,18 @@ function canSetMark(state: EditorState, tr: Transaction, newMarkType: MarkType)
|
|
|
29
29
|
const currentMarks = state.storedMarks ?? cursor.marks()
|
|
30
30
|
|
|
31
31
|
// There can be no current marks that exclude the new mark
|
|
32
|
-
return
|
|
32
|
+
return (
|
|
33
|
+
!!newMarkType.isInSet(currentMarks)
|
|
34
|
+
|| !currentMarks.some(mark => mark.type.excludes(newMarkType))
|
|
35
|
+
)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
const { ranges } = selection
|
|
36
39
|
|
|
37
40
|
return ranges.some(({ $from, $to }) => {
|
|
38
|
-
let someNodeSupportsMark = $from.depth === 0
|
|
41
|
+
let someNodeSupportsMark = $from.depth === 0
|
|
42
|
+
? state.doc.inlineContent && state.doc.type.allowsMarkType(newMarkType)
|
|
43
|
+
: false
|
|
39
44
|
|
|
40
45
|
state.doc.nodesBetween($from.pos, $to.pos, (node, _pos, parent) => {
|
|
41
46
|
// If we already found a mark that we can enable, return false to bypass the remaining search
|
|
@@ -45,7 +50,8 @@ function canSetMark(state: EditorState, tr: Transaction, newMarkType: MarkType)
|
|
|
45
50
|
|
|
46
51
|
if (node.isInline) {
|
|
47
52
|
const parentAllowsMarkType = !parent || parent.type.allowsMarkType(newMarkType)
|
|
48
|
-
const currentMarksAllowMarkType = !!newMarkType.isInSet(node.marks)
|
|
53
|
+
const currentMarksAllowMarkType = !!newMarkType.isInSet(node.marks)
|
|
54
|
+
|| !node.marks.some(otherMark => otherMark.type.excludes(newMarkType))
|
|
49
55
|
|
|
50
56
|
someNodeSupportsMark = parentAllowsMarkType && currentMarksAllowMarkType
|
|
51
57
|
}
|
|
@@ -54,7 +60,6 @@ function canSetMark(state: EditorState, tr: Transaction, newMarkType: MarkType)
|
|
|
54
60
|
|
|
55
61
|
return someNodeSupportsMark
|
|
56
62
|
})
|
|
57
|
-
|
|
58
63
|
}
|
|
59
64
|
export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
|
60
65
|
const { selection } = tr
|
|
@@ -65,10 +70,12 @@ export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) =>
|
|
|
65
70
|
if (empty) {
|
|
66
71
|
const oldAttributes = getMarkAttributes(state, type)
|
|
67
72
|
|
|
68
|
-
tr.addStoredMark(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
tr.addStoredMark(
|
|
74
|
+
type.create({
|
|
75
|
+
...oldAttributes,
|
|
76
|
+
...attributes,
|
|
77
|
+
}),
|
|
78
|
+
)
|
|
72
79
|
} else {
|
|
73
80
|
ranges.forEach(range => {
|
|
74
81
|
const from = range.$from.pos
|
|
@@ -83,13 +90,16 @@ export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) =>
|
|
|
83
90
|
// we know that we have to merge its attributes
|
|
84
91
|
// otherwise we add a fresh new mark
|
|
85
92
|
if (someHasMark) {
|
|
86
|
-
|
|
87
93
|
node.marks.forEach(mark => {
|
|
88
94
|
if (type === mark.type) {
|
|
89
|
-
tr.addMark(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
tr.addMark(
|
|
96
|
+
trimmedFrom,
|
|
97
|
+
trimmedTo,
|
|
98
|
+
type.create({
|
|
99
|
+
...mark.attrs,
|
|
100
|
+
...attributes,
|
|
101
|
+
}),
|
|
102
|
+
)
|
|
93
103
|
}
|
|
94
104
|
})
|
|
95
105
|
} else {
|
package/src/commands/setNode.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setBlockType } from '
|
|
2
|
-
import { NodeType } from '
|
|
1
|
+
import { setBlockType } from '@tiptap/pm/commands'
|
|
2
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType'
|
|
5
5
|
import { RawCommands } from '../types'
|
|
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Replace a given range with a node.
|
|
12
12
|
*/
|
|
13
|
-
setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -25,19 +25,21 @@ export const setNode: RawCommands['setNode'] = (typeOrName, attributes = {}) =>
|
|
|
25
25
|
return false
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return
|
|
28
|
+
return (
|
|
29
|
+
chain()
|
|
29
30
|
// try to convert node to default node if needed
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
.command(({ commands }) => {
|
|
32
|
+
const canSetBlock = setBlockType(type, attributes)(state)
|
|
33
|
+
|
|
34
|
+
if (canSetBlock) {
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return commands.clearNodes()
|
|
39
|
+
})
|
|
40
|
+
.command(({ state: updatedState }) => {
|
|
41
|
+
return setBlockType(type, attributes)(updatedState, dispatch)
|
|
42
|
+
})
|
|
43
|
+
.run()
|
|
44
|
+
)
|
|
43
45
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeSelection } from '
|
|
1
|
+
import { NodeSelection } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
import { RawCommands } from '../types'
|
|
4
4
|
import { minMax } from '../utilities/minMax'
|
|
@@ -9,7 +9,7 @@ declare module '@tiptap/core' {
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a NodeSelection.
|
|
11
11
|
*/
|
|
12
|
-
setNodeSelection: (position: number) => ReturnType
|
|
12
|
+
setNodeSelection: (position: number) => ReturnType
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextSelection } from '
|
|
1
|
+
import { TextSelection } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
3
|
import { Range, RawCommands } from '../types'
|
|
4
4
|
import { minMax } from '../utilities/minMax'
|
|
@@ -9,7 +9,7 @@ declare module '@tiptap/core' {
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a TextSelection.
|
|
11
11
|
*/
|
|
12
|
-
setTextSelection: (position: number | Range) => ReturnType
|
|
12
|
+
setTextSelection: (position: number | Range) => ReturnType
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -17,9 +17,7 @@ declare module '@tiptap/core' {
|
|
|
17
17
|
export const setTextSelection: RawCommands['setTextSelection'] = position => ({ tr, dispatch }) => {
|
|
18
18
|
if (dispatch) {
|
|
19
19
|
const { doc } = tr
|
|
20
|
-
const { from, to } = typeof position === 'number'
|
|
21
|
-
? { from: position, to: position }
|
|
22
|
-
: position
|
|
20
|
+
const { from, to } = typeof position === 'number' ? { from: position, to: position } : position
|
|
23
21
|
const minPos = TextSelection.atStart(doc).from
|
|
24
22
|
const maxPos = TextSelection.atEnd(doc).to
|
|
25
23
|
const resolvedFrom = minMax(from, minPos, maxPos)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NodeType } from '
|
|
2
|
-
import { sinkListItem as originalSinkListItem } from '
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { sinkListItem as originalSinkListItem } from '@tiptap/pm/schema-list'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType'
|
|
5
5
|
import { RawCommands } from '../types'
|
|
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Sink the list item down into an inner list.
|
|
12
12
|
*/
|
|
13
|
-
sinkListItem: (typeOrName: string | NodeType) => ReturnType
|
|
13
|
+
sinkListItem: (typeOrName: string | NodeType) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { EditorState, NodeSelection, TextSelection } from '
|
|
2
|
-
import { canSplit } from '
|
|
1
|
+
import { EditorState, NodeSelection, TextSelection } from '@tiptap/pm/state'
|
|
2
|
+
import { canSplit } from '@tiptap/pm/transform'
|
|
3
3
|
|
|
4
4
|
import { defaultBlockAt } from '../helpers/defaultBlockAt'
|
|
5
5
|
import { getSplittedAttributes } from '../helpers/getSplittedAttributes'
|
|
6
6
|
import { RawCommands } from '../types'
|
|
7
7
|
|
|
8
8
|
function ensureMarks(state: EditorState, splittableMarks?: string[]) {
|
|
9
|
-
const marks = state.storedMarks
|
|
10
|
-
|| (state.selection.$to.parentOffset && state.selection.$from.marks())
|
|
9
|
+
const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks())
|
|
11
10
|
|
|
12
11
|
if (marks) {
|
|
13
12
|
const filteredMarks = marks.filter(mark => splittableMarks?.includes(mark.type.name))
|
|
@@ -22,16 +21,13 @@ declare module '@tiptap/core' {
|
|
|
22
21
|
/**
|
|
23
22
|
* Forks a new node from an existing node.
|
|
24
23
|
*/
|
|
25
|
-
splitBlock: (options?: { keepMarks?: boolean }) => ReturnType
|
|
24
|
+
splitBlock: (options?: { keepMarks?: boolean }) => ReturnType
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {}) => ({
|
|
31
|
-
tr,
|
|
32
|
-
state,
|
|
33
|
-
dispatch,
|
|
34
|
-
editor,
|
|
30
|
+
tr, state, dispatch, editor,
|
|
35
31
|
}) => {
|
|
36
32
|
const { selection, doc } = tr
|
|
37
33
|
const { $from, $to } = selection
|
|
@@ -74,37 +70,36 @@ export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {})
|
|
|
74
70
|
: defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)))
|
|
75
71
|
|
|
76
72
|
let types = atEnd && deflt
|
|
77
|
-
? [
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
? [
|
|
74
|
+
{
|
|
75
|
+
type: deflt,
|
|
76
|
+
attrs: newAttributes,
|
|
77
|
+
},
|
|
78
|
+
]
|
|
81
79
|
: undefined
|
|
82
80
|
|
|
83
81
|
let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types)
|
|
84
82
|
|
|
85
83
|
if (
|
|
86
84
|
!types
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
&& !can
|
|
86
|
+
&& canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : undefined)
|
|
89
87
|
) {
|
|
90
88
|
can = true
|
|
91
89
|
types = deflt
|
|
92
|
-
? [
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
? [
|
|
91
|
+
{
|
|
92
|
+
type: deflt,
|
|
93
|
+
attrs: newAttributes,
|
|
94
|
+
},
|
|
95
|
+
]
|
|
96
96
|
: undefined
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
if (can) {
|
|
100
100
|
tr.split(tr.mapping.map($from.pos), 1, types)
|
|
101
101
|
|
|
102
|
-
if (
|
|
103
|
-
deflt
|
|
104
|
-
&& !atEnd
|
|
105
|
-
&& !$from.parentOffset
|
|
106
|
-
&& $from.parent.type !== deflt
|
|
107
|
-
) {
|
|
102
|
+
if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
|
|
108
103
|
const first = tr.mapping.map($from.before())
|
|
109
104
|
const $first = tr.doc.resolve(first)
|
|
110
105
|
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Fragment,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from 'prosemirror-model'
|
|
7
|
-
import { TextSelection } from 'prosemirror-state'
|
|
8
|
-
import { canSplit } from 'prosemirror-transform'
|
|
2
|
+
Fragment, Node as ProseMirrorNode, NodeType, Slice,
|
|
3
|
+
} from '@tiptap/pm/model'
|
|
4
|
+
import { TextSelection } from '@tiptap/pm/state'
|
|
5
|
+
import { canSplit } from '@tiptap/pm/transform'
|
|
9
6
|
|
|
10
7
|
import { getNodeType } from '../helpers/getNodeType'
|
|
11
8
|
import { getSplittedAttributes } from '../helpers/getSplittedAttributes'
|
|
@@ -17,7 +14,7 @@ declare module '@tiptap/core' {
|
|
|
17
14
|
/**
|
|
18
15
|
* Splits one list item into two list items.
|
|
19
16
|
*/
|
|
20
|
-
splitListItem: (typeOrName: string | NodeType) => ReturnType
|
|
17
|
+
splitListItem: (typeOrName: string | NodeType) => ReturnType
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
20
|
}
|
|
@@ -30,7 +27,7 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
30
27
|
|
|
31
28
|
// @ts-ignore
|
|
32
29
|
// eslint-disable-next-line
|
|
33
|
-
|
|
30
|
+
const node: ProseMirrorNode = state.selection.node
|
|
34
31
|
|
|
35
32
|
if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) {
|
|
36
33
|
return false
|
|
@@ -50,8 +47,8 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
50
47
|
// command handle lifting.
|
|
51
48
|
if (
|
|
52
49
|
$from.depth === 2
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
|| $from.node(-3).type !== type
|
|
51
|
+
|| $from.index(-2) !== $from.node(-2).childCount - 1
|
|
55
52
|
) {
|
|
56
53
|
return false
|
|
57
54
|
}
|
|
@@ -59,11 +56,7 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
59
56
|
if (dispatch) {
|
|
60
57
|
let wrap = Fragment.empty
|
|
61
58
|
// eslint-disable-next-line
|
|
62
|
-
|
|
63
|
-
? 1
|
|
64
|
-
: $from.index(-2)
|
|
65
|
-
? 2
|
|
66
|
-
: 3
|
|
59
|
+
const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3
|
|
67
60
|
|
|
68
61
|
// Build a fragment containing empty versions of the structure
|
|
69
62
|
// from the outer list item to the parent node of the cursor
|
|
@@ -72,11 +65,7 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
72
65
|
}
|
|
73
66
|
|
|
74
67
|
// eslint-disable-next-line
|
|
75
|
-
|
|
76
|
-
? 1
|
|
77
|
-
: $from.indexAfter(-2) < $from.node(-3).childCount
|
|
78
|
-
? 2
|
|
79
|
-
: 3
|
|
68
|
+
const depthAfter = $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3
|
|
80
69
|
|
|
81
70
|
// Add a second list item with an empty default start node
|
|
82
71
|
const newNextTypeAttributes = getSplittedAttributes(
|
|
@@ -114,9 +103,7 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
114
103
|
return true
|
|
115
104
|
}
|
|
116
105
|
|
|
117
|
-
const nextType = $to.pos === $from.end()
|
|
118
|
-
? grandParent.contentMatchAt(0).defaultType
|
|
119
|
-
: null
|
|
106
|
+
const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null
|
|
120
107
|
|
|
121
108
|
const newTypeAttributes = getSplittedAttributes(
|
|
122
109
|
extensionAttributes,
|
|
@@ -132,7 +119,10 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
|
|
132
119
|
tr.delete($from.pos, $to.pos)
|
|
133
120
|
|
|
134
121
|
const types = nextType
|
|
135
|
-
? [
|
|
122
|
+
? [
|
|
123
|
+
{ type, attrs: newTypeAttributes },
|
|
124
|
+
{ type: nextType, attrs: newNextTypeAttributes },
|
|
125
|
+
]
|
|
136
126
|
: [{ type, attrs: newTypeAttributes }]
|
|
137
127
|
|
|
138
128
|
if (!canSplit(tr.doc, $from.pos, 2)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NodeType } from '
|
|
2
|
-
import { Transaction } from '
|
|
3
|
-
import { canJoin } from '
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { Transaction } from '@tiptap/pm/state'
|
|
3
|
+
import { canJoin } from '@tiptap/pm/transform'
|
|
4
4
|
|
|
5
5
|
import { findParentNode } from '../helpers/findParentNode'
|
|
6
6
|
import { getNodeType } from '../helpers/getNodeType'
|
|
@@ -21,8 +21,7 @@ const joinListBackwards = (tr: Transaction, listType: NodeType): boolean => {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const nodeBefore = tr.doc.nodeAt(before)
|
|
24
|
-
const canJoinBackwards = list.node.type === nodeBefore?.type
|
|
25
|
-
&& canJoin(tr.doc, list.pos)
|
|
24
|
+
const canJoinBackwards = list.node.type === nodeBefore?.type && canJoin(tr.doc, list.pos)
|
|
26
25
|
|
|
27
26
|
if (!canJoinBackwards) {
|
|
28
27
|
return true
|
|
@@ -47,8 +46,7 @@ const joinListForwards = (tr: Transaction, listType: NodeType): boolean => {
|
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
const nodeAfter = tr.doc.nodeAt(after)
|
|
50
|
-
const canJoinForwards = list.node.type === nodeAfter?.type
|
|
51
|
-
&& canJoin(tr.doc, after)
|
|
49
|
+
const canJoinForwards = list.node.type === nodeAfter?.type && canJoin(tr.doc, after)
|
|
52
50
|
|
|
53
51
|
if (!canJoinForwards) {
|
|
54
52
|
return true
|
|
@@ -65,7 +63,10 @@ declare module '@tiptap/core' {
|
|
|
65
63
|
/**
|
|
66
64
|
* Toggle between different list types.
|
|
67
65
|
*/
|
|
68
|
-
toggleList: (
|
|
66
|
+
toggleList: (
|
|
67
|
+
listTypeOrName: string | NodeType,
|
|
68
|
+
itemTypeOrName: string | NodeType,
|
|
69
|
+
) => ReturnType
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
}
|
|
@@ -95,8 +96,8 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr
|
|
|
95
96
|
// change list type
|
|
96
97
|
if (
|
|
97
98
|
isList(parentList.node.type.name, extensions)
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
&& listType.validContent(parentList.node.content)
|
|
100
|
+
&& dispatch
|
|
100
101
|
) {
|
|
101
102
|
return chain()
|
|
102
103
|
.command(() => {
|
|
@@ -110,19 +111,21 @@ export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOr
|
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
return
|
|
114
|
+
return (
|
|
115
|
+
chain()
|
|
114
116
|
// try to convert node to default node if needed
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
.command(() => {
|
|
118
|
+
const canWrapInList = can().wrapInList(listType)
|
|
119
|
+
|
|
120
|
+
if (canWrapInList) {
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return commands.clearNodes()
|
|
125
|
+
})
|
|
126
|
+
.wrapInList(listType)
|
|
127
|
+
.command(() => joinListBackwards(tr, listType))
|
|
128
|
+
.command(() => joinListForwards(tr, listType))
|
|
129
|
+
.run()
|
|
130
|
+
)
|
|
128
131
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarkType } from '
|
|
1
|
+
import { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarkType } from '../helpers/getMarkType'
|
|
4
4
|
import { isMarkActive } from '../helpers/isMarkActive'
|
|
@@ -17,9 +17,9 @@ declare module '@tiptap/core' {
|
|
|
17
17
|
/**
|
|
18
18
|
* Removes the mark even across the current selection. Defaults to `false`.
|
|
19
19
|
*/
|
|
20
|
-
extendEmptyMarkRange?: boolean
|
|
20
|
+
extendEmptyMarkRange?: boolean
|
|
21
21
|
},
|
|
22
|
-
) => ReturnType
|
|
22
|
+
) => ReturnType
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeType } from '
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getNodeType } from '../helpers/getNodeType'
|
|
4
4
|
import { isNodeActive } from '../helpers/isNodeActive'
|
|
@@ -10,7 +10,11 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Toggle a node with another node.
|
|
12
12
|
*/
|
|
13
|
-
toggleNode: (
|
|
13
|
+
toggleNode: (
|
|
14
|
+
typeOrName: string | NodeType,
|
|
15
|
+
toggleTypeOrName: string | NodeType,
|
|
16
|
+
attributes?: Record<string, any>,
|
|
17
|
+
) => ReturnType
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeType } from '
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getNodeType } from '../helpers/getNodeType'
|
|
4
4
|
import { isNodeActive } from '../helpers/isNodeActive'
|
|
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Wraps nodes in another node, or removes an existing wrap.
|
|
12
12
|
*/
|
|
13
|
-
toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarkType } from '
|
|
1
|
+
import { MarkType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarkRange } from '../helpers/getMarkRange'
|
|
4
4
|
import { getMarkType } from '../helpers/getMarkType'
|
|
@@ -16,9 +16,9 @@ declare module '@tiptap/core' {
|
|
|
16
16
|
/**
|
|
17
17
|
* Removes the mark even across the current selection. Defaults to `false`.
|
|
18
18
|
*/
|
|
19
|
-
extendEmptyMarkRange?: boolean
|
|
19
|
+
extendEmptyMarkRange?: boolean
|
|
20
20
|
},
|
|
21
|
-
) => ReturnType
|
|
21
|
+
) => ReturnType
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarkType, NodeType } from '
|
|
1
|
+
import { MarkType, NodeType } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
3
|
import { getMarkType } from '../helpers/getMarkType'
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType'
|
|
@@ -11,7 +11,10 @@ declare module '@tiptap/core' {
|
|
|
11
11
|
/**
|
|
12
12
|
* Update attributes of a node or mark.
|
|
13
13
|
*/
|
|
14
|
-
updateAttributes: (
|
|
14
|
+
updateAttributes: (
|
|
15
|
+
typeOrName: string | NodeType | MarkType,
|
|
16
|
+
attributes: Record<string, any>,
|
|
17
|
+
) => ReturnType
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -21,9 +24,7 @@ export const updateAttributes: RawCommands['updateAttributes'] = (typeOrName, at
|
|
|
21
24
|
let markType: MarkType | null = null
|
|
22
25
|
|
|
23
26
|
const schemaType = getSchemaTypeNameByName(
|
|
24
|
-
typeof typeOrName === 'string'
|
|
25
|
-
? typeOrName
|
|
26
|
-
: typeOrName.name,
|
|
27
|
+
typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
|
|
27
28
|
state.schema,
|
|
28
29
|
)
|
|
29
30
|
|
|
@@ -58,10 +59,14 @@ export const updateAttributes: RawCommands['updateAttributes'] = (typeOrName, at
|
|
|
58
59
|
const trimmedFrom = Math.max(pos, from)
|
|
59
60
|
const trimmedTo = Math.min(pos + node.nodeSize, to)
|
|
60
61
|
|
|
61
|
-
tr.addMark(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
tr.addMark(
|
|
63
|
+
trimmedFrom,
|
|
64
|
+
trimmedTo,
|
|
65
|
+
markType.create({
|
|
66
|
+
...mark.attrs,
|
|
67
|
+
...attributes,
|
|
68
|
+
}),
|
|
69
|
+
)
|
|
65
70
|
}
|
|
66
71
|
})
|
|
67
72
|
}
|
package/src/commands/wrapIn.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { wrapIn as originalWrapIn } from '
|
|
2
|
-
import { NodeType } from '
|
|
1
|
+
import { wrapIn as originalWrapIn } from '@tiptap/pm/commands'
|
|
2
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType'
|
|
5
5
|
import { RawCommands } from '../types'
|
|
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Wraps nodes in another node.
|
|
12
12
|
*/
|
|
13
|
-
wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NodeType } from '
|
|
2
|
-
import { wrapInList as originalWrapInList } from '
|
|
1
|
+
import { NodeType } from '@tiptap/pm/model'
|
|
2
|
+
import { wrapInList as originalWrapInList } from '@tiptap/pm/schema-list'
|
|
3
3
|
|
|
4
4
|
import { getNodeType } from '../helpers/getNodeType'
|
|
5
5
|
import { RawCommands } from '../types'
|
|
@@ -10,7 +10,7 @@ declare module '@tiptap/core' {
|
|
|
10
10
|
/**
|
|
11
11
|
* Wrap a node in a list.
|
|
12
12
|
*/
|
|
13
|
-
wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
13
|
+
wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|