@@ -14,14 +14,15 @@ declare module '@tiptap/core' {
14
14
/**
15
15
* Splits one list item into two list items.
16
16
* @param typeOrName The type or name of the node.
17
+ * @param overrideAttrs The attributes to ensure on the new node.
17
18
* @example editor.commands.splitListItem('listItem')
18
19
*/
19
- splitListItem : ( typeOrName : string | NodeType ) => ReturnType
20
+ splitListItem : ( typeOrName : string | NodeType , overrideAttrs ?: Record < string , any > ) => ReturnType
20
21
}
21
22
}
22
23
}
23
24
24
- export const splitListItem : RawCommands [ 'splitListItem' ] = typeOrName => ( {
25
+ export const splitListItem : RawCommands [ 'splitListItem' ] = ( typeOrName , overrideAttrs = { } ) => ( {
25
26
tr, state, dispatch, editor,
26
27
} ) => {
27
28
const type = getNodeType ( typeOrName , state . schema )
@@ -70,11 +71,14 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
70
71
const depthAfter = $from . indexAfter ( - 1 ) < $from . node ( - 2 ) . childCount ? 1 : $from . indexAfter ( - 2 ) < $from . node ( - 3 ) . childCount ? 2 : 3
71
72
72
73
// Add a second list item with an empty default start node
73
- const newNextTypeAttributes = getSplittedAttributes (
74
- extensionAttributes ,
75
- $from . node ( ) . type . name ,
76
- $from . node ( ) . attrs ,
77
- )
74
+ const newNextTypeAttributes = {
75
+ ...getSplittedAttributes (
76
+ extensionAttributes ,
77
+ $from . node ( ) . type . name ,
78
+ $from . node ( ) . attrs ,
79
+ ) ,
80
+ ...overrideAttrs ,
81
+ }
78
82
const nextType = type . contentMatch . defaultType ?. createAndFill ( newNextTypeAttributes ) || undefined
79
83
80
84
wrap = wrap . append ( Fragment . from ( type . createAndFill ( null , nextType ) || undefined ) )
@@ -107,16 +111,22 @@ export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
107
111
108
112
const nextType = $to . pos === $from . end ( ) ? grandParent . contentMatchAt ( 0 ) . defaultType : null
109
113
110
- const newTypeAttributes = getSplittedAttributes (
111
- extensionAttributes ,
112
- grandParent . type . name ,
113
- grandParent . attrs ,
114
- )
115
- const newNextTypeAttributes = getSplittedAttributes (
116
- extensionAttributes ,
117
- $from . node ( ) . type . name ,
118
- $from . node ( ) . attrs ,
119
- )
114
+ const newTypeAttributes = {
115
+ ...getSplittedAttributes (
116
+ extensionAttributes ,
117
+ grandParent . type . name ,
118
+ grandParent . attrs ,
119
+ ) ,
120
+ ...overrideAttrs ,
121
+ }
122
+ const newNextTypeAttributes = {
123
+ ...getSplittedAttributes (
124
+ extensionAttributes ,
125
+ $from . node ( ) . type . name ,
126
+ $from . node ( ) . attrs ,
127
+ ) ,
128
+ ...overrideAttrs ,
129
+ }
120
130
121
131
tr . delete ( $from . pos , $to . pos )
122
132
0 commit comments