@tiptap/core 3.0.0-next.3 → 3.0.0-next.4
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 +2402 -2540
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1355 -1273
- package/dist/index.d.ts +1355 -1273
- package/dist/index.js +2408 -2562
- package/dist/index.js.map +1 -1
- package/package.json +9 -5
- package/src/CommandManager.ts +2 -9
- package/src/Editor.ts +87 -72
- package/src/EventEmitter.ts +7 -10
- package/src/Extension.ts +8 -14
- package/src/ExtensionManager.ts +26 -125
- package/src/InputRule.ts +35 -48
- package/src/Mark.ts +9 -9
- package/src/Node.ts +9 -9
- package/src/NodePos.ts +1 -3
- package/src/NodeView.ts +10 -20
- package/src/PasteRule.ts +43 -55
- package/src/Tracker.ts +7 -9
- package/src/commands/blur.ts +14 -12
- package/src/commands/clearContent.ts +6 -4
- package/src/commands/clearNodes.ts +32 -30
- package/src/commands/command.ts +1 -1
- package/src/commands/createParagraphNear.ts +5 -3
- package/src/commands/cut.ts +12 -10
- package/src/commands/deleteCurrentNode.ts +23 -21
- package/src/commands/deleteNode.ts +18 -16
- package/src/commands/deleteRange.ts +10 -8
- package/src/commands/deleteSelection.ts +5 -3
- package/src/commands/enter.ts +6 -4
- package/src/commands/exitCode.ts +5 -3
- package/src/commands/extendMarkRange.ts +14 -12
- package/src/commands/first.ts +2 -4
- package/src/commands/focus.ts +45 -48
- package/src/commands/forEach.ts +2 -2
- package/src/commands/insertContent.ts +12 -14
- package/src/commands/insertContentAt.ts +101 -98
- package/src/commands/join.ts +20 -12
- package/src/commands/joinItemBackward.ts +16 -18
- package/src/commands/joinItemForward.ts +16 -18
- package/src/commands/joinTextblockBackward.ts +5 -3
- package/src/commands/joinTextblockForward.ts +5 -3
- package/src/commands/keyboardShortcut.ts +29 -34
- package/src/commands/lift.ts +10 -8
- package/src/commands/liftEmptyBlock.ts +6 -4
- package/src/commands/liftListItem.ts +6 -4
- package/src/commands/newlineInCode.ts +5 -3
- package/src/commands/resetAttributes.ts +36 -41
- package/src/commands/scrollIntoView.ts +9 -7
- package/src/commands/selectAll.ts +10 -8
- package/src/commands/selectNodeBackward.ts +5 -3
- package/src/commands/selectNodeForward.ts +5 -3
- package/src/commands/selectParentNode.ts +5 -3
- package/src/commands/selectTextblockEnd.ts +5 -3
- package/src/commands/selectTextblockStart.ts +5 -3
- package/src/commands/setContent.ts +25 -25
- package/src/commands/setMark.ts +55 -57
- package/src/commands/setMeta.ts +7 -5
- package/src/commands/setNode.ts +32 -30
- package/src/commands/setNodeSelection.ts +11 -9
- package/src/commands/setTextSelection.ts +15 -13
- package/src/commands/sinkListItem.ts +6 -4
- package/src/commands/splitBlock.ts +67 -76
- package/src/commands/splitListItem.ts +93 -106
- package/src/commands/toggleList.ts +73 -71
- package/src/commands/toggleMark.ts +11 -9
- package/src/commands/toggleNode.ts +18 -16
- package/src/commands/toggleWrap.ts +10 -8
- package/src/commands/undoInputRule.ts +31 -29
- package/src/commands/unsetAllMarks.ts +16 -14
- package/src/commands/unsetMark.ts +27 -25
- package/src/commands/updateAttributes.ts +92 -100
- package/src/commands/wrapIn.ts +6 -4
- package/src/commands/wrapInList.ts +6 -4
- package/src/extensions/clipboardTextSerializer.ts +2 -4
- package/src/extensions/focusEvents.ts +2 -6
- package/src/extensions/keymap.ts +54 -50
- package/src/extensions/paste.ts +0 -1
- package/src/extensions/tabindex.ts +1 -1
- package/src/helpers/combineTransactionSteps.ts +1 -4
- package/src/helpers/createChainableState.ts +1 -4
- package/src/helpers/createDocument.ts +1 -3
- package/src/helpers/createNodeFromContent.ts +4 -10
- package/src/helpers/findChildrenInRange.ts +1 -5
- package/src/helpers/findParentNode.ts +3 -1
- package/src/helpers/flattenExtensions.ts +30 -0
- package/src/helpers/getAttributes.ts +1 -4
- package/src/helpers/getAttributesFromExtensions.ts +28 -37
- package/src/helpers/getChangedRanges.ts +13 -11
- package/src/helpers/getExtensionField.ts +1 -4
- package/src/helpers/getMarkAttributes.ts +1 -4
- package/src/helpers/getMarkRange.ts +5 -15
- package/src/helpers/getMarkType.ts +1 -3
- package/src/helpers/getNodeAttributes.ts +1 -4
- package/src/helpers/getNodeType.ts +1 -3
- package/src/helpers/getRenderedAttributes.ts +1 -3
- package/src/helpers/getSchema.ts +2 -2
- package/src/helpers/getSchemaByResolvedExtensions.ts +45 -77
- package/src/helpers/getSplittedAttributes.ts +4 -4
- package/src/helpers/getTextContentFromNodes.ts +8 -11
- package/src/helpers/index.ts +4 -0
- package/src/helpers/injectExtensionAttributesToParseRule.ts +1 -1
- package/src/helpers/isActive.ts +1 -5
- package/src/helpers/isExtensionRulesEnabled.ts +1 -3
- package/src/helpers/isNodeEmpty.ts +2 -2
- package/src/helpers/resolveExtensions.ts +25 -0
- package/src/helpers/resolveFocusPosition.ts +3 -14
- package/src/helpers/rewriteUnknownContent.ts +149 -0
- package/src/helpers/sortExtensions.ts +26 -0
- package/src/inputRules/markInputRule.ts +1 -5
- package/src/inputRules/nodeInputRule.ts +2 -9
- package/src/inputRules/textInputRule.ts +1 -4
- package/src/inputRules/textblockTypeInputRule.ts +2 -8
- package/src/inputRules/wrappingInputRule.ts +13 -19
- package/src/pasteRules/markPasteRule.ts +1 -3
- package/src/pasteRules/nodePasteRule.ts +2 -8
- package/src/pasteRules/textPasteRule.ts +1 -4
- package/src/types.ts +212 -172
- package/src/utilities/createStyleTag.ts +3 -1
- package/src/utilities/deleteProps.ts +7 -11
- package/src/utilities/findDuplicates.ts +4 -1
- 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 +16 -6
- package/src/utilities/removeDuplicates.ts +1 -3
|
@@ -14,26 +14,24 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const joinItemBackward: RawCommands['joinItemBackward'] =
|
|
18
|
-
|
|
19
|
-
dispatch,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const point = joinPoint(state.doc, state.selection.$from.pos, -1)
|
|
17
|
+
export const joinItemBackward: RawCommands['joinItemBackward'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch, tr }) => {
|
|
20
|
+
try {
|
|
21
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, -1)
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (point === null || point === undefined) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
tr.join(point, 2)
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
dispatch(tr)
|
|
31
|
+
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
return true
|
|
34
|
+
} catch {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
38
37
|
}
|
|
39
|
-
}
|
|
@@ -14,26 +14,24 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const joinItemForward: RawCommands['joinItemForward'] =
|
|
18
|
-
|
|
19
|
-
dispatch,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
const point = joinPoint(state.doc, state.selection.$from.pos, +1)
|
|
17
|
+
export const joinItemForward: RawCommands['joinItemForward'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch, tr }) => {
|
|
20
|
+
try {
|
|
21
|
+
const point = joinPoint(state.doc, state.selection.$from.pos, +1)
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (point === null || point === undefined) {
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
tr.join(point, 2)
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
dispatch(tr)
|
|
31
|
+
}
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
return true
|
|
34
|
+
} catch {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
38
37
|
}
|
|
39
|
-
}
|
|
@@ -13,6 +13,8 @@ declare module '@tiptap/core' {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const joinTextblockBackward: RawCommands['joinTextblockBackward'] =
|
|
17
|
-
|
|
18
|
-
}
|
|
16
|
+
export const joinTextblockBackward: RawCommands['joinTextblockBackward'] =
|
|
17
|
+
() =>
|
|
18
|
+
({ state, dispatch }) => {
|
|
19
|
+
return originalCommand(state, dispatch)
|
|
20
|
+
}
|
|
@@ -13,6 +13,8 @@ declare module '@tiptap/core' {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const joinTextblockForward: RawCommands['joinTextblockForward'] =
|
|
17
|
-
|
|
18
|
-
}
|
|
16
|
+
export const joinTextblockForward: RawCommands['joinTextblockForward'] =
|
|
17
|
+
() =>
|
|
18
|
+
({ state, dispatch }) => {
|
|
19
|
+
return originalCommand(state, dispatch)
|
|
20
|
+
}
|
|
@@ -64,42 +64,37 @@ declare module '@tiptap/core' {
|
|
|
64
64
|
* @param name The name of the keyboard shortcut.
|
|
65
65
|
* @example editor.commands.keyboardShortcut('Mod-b')
|
|
66
66
|
*/
|
|
67
|
-
keyboardShortcut: (name: string) => ReturnType
|
|
67
|
+
keyboardShortcut: (name: string) => ReturnType
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export const keyboardShortcut: RawCommands['keyboardShortcut'] =
|
|
73
|
-
|
|
74
|
-
view,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
:
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (newStep && dispatch) {
|
|
100
|
-
tr.maybeStep(newStep)
|
|
101
|
-
}
|
|
102
|
-
})
|
|
72
|
+
export const keyboardShortcut: RawCommands['keyboardShortcut'] =
|
|
73
|
+
name =>
|
|
74
|
+
({ editor, view, tr, dispatch }) => {
|
|
75
|
+
const keys = normalizeKeyName(name).split(/-(?!$)/)
|
|
76
|
+
const key = keys.find(item => !['Alt', 'Ctrl', 'Meta', 'Shift'].includes(item))
|
|
77
|
+
const event = new KeyboardEvent('keydown', {
|
|
78
|
+
key: key === 'Space' ? ' ' : key,
|
|
79
|
+
altKey: keys.includes('Alt'),
|
|
80
|
+
ctrlKey: keys.includes('Ctrl'),
|
|
81
|
+
metaKey: keys.includes('Meta'),
|
|
82
|
+
shiftKey: keys.includes('Shift'),
|
|
83
|
+
bubbles: true,
|
|
84
|
+
cancelable: true,
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const capturedTransaction = editor.captureTransaction(() => {
|
|
88
|
+
view.someProp('handleKeyDown', f => f(view, event))
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
capturedTransaction?.steps.forEach(step => {
|
|
92
|
+
const newStep = step.map(tr.mapping)
|
|
93
|
+
|
|
94
|
+
if (newStep && dispatch) {
|
|
95
|
+
tr.maybeStep(newStep)
|
|
96
|
+
}
|
|
97
|
+
})
|
|
103
98
|
|
|
104
|
-
|
|
105
|
-
}
|
|
99
|
+
return true
|
|
100
|
+
}
|
package/src/commands/lift.ts
CHANGED
|
@@ -20,13 +20,15 @@ declare module '@tiptap/core' {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export const lift: RawCommands['lift'] =
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
export const lift: RawCommands['lift'] =
|
|
24
|
+
(typeOrName, attributes = {}) =>
|
|
25
|
+
({ state, dispatch }) => {
|
|
26
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
27
|
+
const isActive = isNodeActive(state, type, attributes)
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (!isActive) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
+
return originalLift(state, dispatch)
|
|
34
|
+
}
|
|
@@ -9,11 +9,13 @@ declare module '@tiptap/core' {
|
|
|
9
9
|
* If the cursor is in an empty textblock that can be lifted, lift the block.
|
|
10
10
|
* @example editor.commands.liftEmptyBlock()
|
|
11
11
|
*/
|
|
12
|
-
liftEmptyBlock: () => ReturnType
|
|
12
|
+
liftEmptyBlock: () => ReturnType
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const liftEmptyBlock: RawCommands['liftEmptyBlock'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const liftEmptyBlock: RawCommands['liftEmptyBlock'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalLiftEmptyBlock(state, dispatch)
|
|
21
|
+
}
|
|
@@ -17,8 +17,10 @@ declare module '@tiptap/core' {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const liftListItem: RawCommands['liftListItem'] =
|
|
21
|
-
|
|
20
|
+
export const liftListItem: RawCommands['liftListItem'] =
|
|
21
|
+
typeOrName =>
|
|
22
|
+
({ state, dispatch }) => {
|
|
23
|
+
const type = getNodeType(typeOrName, state.schema)
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
+
return originalLiftListItem(type)(state, dispatch)
|
|
26
|
+
}
|
|
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const newlineInCode: RawCommands['newlineInCode'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const newlineInCode: RawCommands['newlineInCode'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalNewlineInCode(state, dispatch)
|
|
21
|
+
}
|
|
@@ -15,56 +15,51 @@ declare module '@tiptap/core' {
|
|
|
15
15
|
* @param attributes The attributes of the node to reset.
|
|
16
16
|
* @example editor.commands.resetAttributes('heading', 'level')
|
|
17
17
|
*/
|
|
18
|
-
resetAttributes: (
|
|
19
|
-
typeOrName: string | NodeType | MarkType,
|
|
20
|
-
attributes: string | string[],
|
|
21
|
-
) => ReturnType
|
|
18
|
+
resetAttributes: (typeOrName: string | NodeType | MarkType, attributes: string | string[]) => ReturnType
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
|
|
26
|
-
export const resetAttributes: RawCommands['resetAttributes'] =
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
export const resetAttributes: RawCommands['resetAttributes'] =
|
|
24
|
+
(typeOrName, attributes) =>
|
|
25
|
+
({ tr, state, dispatch }) => {
|
|
26
|
+
let nodeType: NodeType | null = null
|
|
27
|
+
let markType: MarkType | null = null
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
const schemaType = getSchemaTypeNameByName(
|
|
30
|
+
typeof typeOrName === 'string' ? typeOrName : typeOrName.name,
|
|
31
|
+
state.schema,
|
|
32
|
+
)
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (!schemaType) {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
if (schemaType === 'node') {
|
|
39
|
+
nodeType = getNodeType(typeOrName as NodeType, state.schema)
|
|
40
|
+
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (schemaType === 'mark') {
|
|
43
|
+
markType = getMarkType(typeOrName as MarkType, state.schema)
|
|
44
|
+
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
if (dispatch) {
|
|
47
|
+
tr.selection.ranges.forEach(range => {
|
|
48
|
+
state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
|
|
49
|
+
if (nodeType && nodeType === node.type) {
|
|
50
|
+
tr.setNodeMarkup(pos, undefined, deleteProps(node.attrs, attributes))
|
|
51
|
+
}
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
}
|
|
53
|
+
if (markType && node.marks.length) {
|
|
54
|
+
node.marks.forEach(mark => {
|
|
55
|
+
if (markType === mark.type) {
|
|
56
|
+
tr.addMark(pos, pos + node.nodeSize, markType.create(deleteProps(mark.attrs, attributes)))
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
})
|
|
65
61
|
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
62
|
+
}
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
}
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
@@ -7,15 +7,17 @@ declare module '@tiptap/core' {
|
|
|
7
7
|
* Scroll the selection into view.
|
|
8
8
|
* @example editor.commands.scrollIntoView()
|
|
9
9
|
*/
|
|
10
|
-
scrollIntoView: () => ReturnType
|
|
10
|
+
scrollIntoView: () => ReturnType
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const scrollIntoView: RawCommands['scrollIntoView'] =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export const scrollIntoView: RawCommands['scrollIntoView'] =
|
|
16
|
+
() =>
|
|
17
|
+
({ tr, dispatch }) => {
|
|
18
|
+
if (dispatch) {
|
|
19
|
+
tr.scrollIntoView()
|
|
20
|
+
}
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
@@ -9,17 +9,19 @@ declare module '@tiptap/core' {
|
|
|
9
9
|
* Select the whole document.
|
|
10
10
|
* @example editor.commands.selectAll()
|
|
11
11
|
*/
|
|
12
|
-
selectAll: () => ReturnType
|
|
12
|
+
selectAll: () => ReturnType
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const selectAll: RawCommands['selectAll'] =
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
export const selectAll: RawCommands['selectAll'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ tr, dispatch }) => {
|
|
20
|
+
if (dispatch) {
|
|
21
|
+
const selection = new AllSelection(tr.doc)
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
tr.setSelection(selection)
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const selectNodeBackward: RawCommands['selectNodeBackward'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const selectNodeBackward: RawCommands['selectNodeBackward'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalSelectNodeBackward(state, dispatch)
|
|
21
|
+
}
|
|
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const selectNodeForward: RawCommands['selectNodeForward'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const selectNodeForward: RawCommands['selectNodeForward'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalSelectNodeForward(state, dispatch)
|
|
21
|
+
}
|
|
@@ -14,6 +14,8 @@ declare module '@tiptap/core' {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const selectParentNode: RawCommands['selectParentNode'] =
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
export const selectParentNode: RawCommands['selectParentNode'] =
|
|
18
|
+
() =>
|
|
19
|
+
({ state, dispatch }) => {
|
|
20
|
+
return originalSelectParentNode(state, dispatch)
|
|
21
|
+
}
|
|
@@ -16,6 +16,8 @@ declare module '@tiptap/core' {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export const selectTextblockEnd: RawCommands['selectTextblockEnd'] =
|
|
20
|
-
|
|
21
|
-
}
|
|
19
|
+
export const selectTextblockEnd: RawCommands['selectTextblockEnd'] =
|
|
20
|
+
() =>
|
|
21
|
+
({ state, dispatch }) => {
|
|
22
|
+
return originalSelectTextblockEnd(state, dispatch)
|
|
23
|
+
}
|
|
@@ -16,6 +16,8 @@ declare module '@tiptap/core' {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export const selectTextblockStart: RawCommands['selectTextblockStart'] =
|
|
20
|
-
|
|
21
|
-
}
|
|
19
|
+
export const selectTextblockStart: RawCommands['selectTextblockStart'] =
|
|
20
|
+
() =>
|
|
21
|
+
({ state, dispatch }) => {
|
|
22
|
+
return originalSelectTextblockStart(state, dispatch)
|
|
23
|
+
}
|
|
@@ -37,37 +37,37 @@ declare module '@tiptap/core' {
|
|
|
37
37
|
/**
|
|
38
38
|
* Whether to throw an error if the content is invalid.
|
|
39
39
|
*/
|
|
40
|
-
errorOnInvalidContent?: boolean
|
|
41
|
-
}
|
|
42
|
-
) => ReturnType
|
|
43
|
-
}
|
|
40
|
+
errorOnInvalidContent?: boolean
|
|
41
|
+
},
|
|
42
|
+
) => ReturnType
|
|
43
|
+
}
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const setContent: RawCommands['setContent'] =
|
|
48
|
-
|
|
49
|
-
}) => {
|
|
50
|
-
|
|
47
|
+
export const setContent: RawCommands['setContent'] =
|
|
48
|
+
(content, emitUpdate = false, parseOptions = {}, options = {}) =>
|
|
49
|
+
({ editor, tr, dispatch, commands }) => {
|
|
50
|
+
const { doc } = tr
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
// This is to keep backward compatibility with the previous behavior
|
|
53
|
+
// TODO remove this in the next major version
|
|
54
|
+
if (parseOptions.preserveWhitespace !== 'full') {
|
|
55
|
+
const document = createDocument(content, editor.schema, parseOptions, {
|
|
56
|
+
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
if (dispatch) {
|
|
60
|
+
tr.replaceWith(0, doc.content.size, document).setMeta('preventUpdate', !emitUpdate)
|
|
61
|
+
}
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
58
64
|
|
|
59
65
|
if (dispatch) {
|
|
60
|
-
tr.
|
|
66
|
+
tr.setMeta('preventUpdate', !emitUpdate)
|
|
61
67
|
}
|
|
62
|
-
return true
|
|
63
|
-
}
|
|
64
68
|
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {
|
|
70
|
+
parseOptions,
|
|
71
|
+
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
72
|
+
})
|
|
67
73
|
}
|
|
68
|
-
|
|
69
|
-
return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {
|
|
70
|
-
parseOptions,
|
|
71
|
-
errorOnInvalidContent: options.errorOnInvalidContent ?? editor.options.enableContentCheck,
|
|
72
|
-
})
|
|
73
|
-
}
|