@tiptap/extension-list 3.23.6 → 3.25.0
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 +192 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +170 -46
- package/dist/index.js.map +1 -1
- package/dist/item/index.cjs +120 -3
- package/dist/item/index.cjs.map +1 -1
- package/dist/item/index.js +117 -0
- package/dist/item/index.js.map +1 -1
- package/dist/keymap/index.cjs +37 -47
- package/dist/keymap/index.cjs.map +1 -1
- package/dist/keymap/index.js +30 -40
- package/dist/keymap/index.js.map +1 -1
- package/dist/kit/index.cjs +192 -68
- package/dist/kit/index.cjs.map +1 -1
- package/dist/kit/index.js +170 -46
- package/dist/kit/index.js.map +1 -1
- package/dist/ordered-list/index.cjs +8 -1
- package/dist/ordered-list/index.cjs.map +1 -1
- package/dist/ordered-list/index.js +8 -1
- package/dist/ordered-list/index.js.map +1 -1
- package/dist/task-item/index.cjs +120 -5
- package/dist/task-item/index.cjs.map +1 -1
- package/dist/task-item/index.js +115 -0
- package/dist/task-item/index.js.map +1 -1
- package/dist/task-list/index.cjs +5 -1
- package/dist/task-list/index.cjs.map +1 -1
- package/dist/task-list/index.js +5 -1
- package/dist/task-list/index.js.map +1 -1
- package/package.json +19 -20
- package/src/helpers/createBranchingListDeleteKeymap.ts +24 -0
- package/src/helpers/getBranchingNestedListAtCursor.ts +116 -0
- package/src/helpers/handleDeleteBranchingNestedList.ts +25 -0
- package/src/helpers/hasBranchingNestedListAfterCursor.ts +30 -0
- package/src/helpers/hoistBranchingNestedList.ts +56 -0
- package/src/item/list-item.ts +21 -5
- package/src/keymap/listHelpers/handleBackspace.ts +3 -22
- package/src/keymap/listHelpers/hasListBefore.ts +5 -1
- package/src/ordered-list/ordered-list.ts +3 -1
- package/src/ordered-list/utils.ts +15 -2
- package/src/task-item/task-item.ts +10 -0
- package/src/task-list/task-list.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -86,6 +86,115 @@ var BulletList = Node.create({
|
|
|
86
86
|
|
|
87
87
|
// src/item/list-item.ts
|
|
88
88
|
import { mergeAttributes as mergeAttributes2, Node as Node2, renderNestedMarkdownContent } from "@tiptap/core";
|
|
89
|
+
|
|
90
|
+
// src/helpers/createBranchingListDeleteKeymap.ts
|
|
91
|
+
import { Extension } from "@tiptap/core";
|
|
92
|
+
|
|
93
|
+
// src/helpers/hoistBranchingNestedList.ts
|
|
94
|
+
import { Fragment } from "@tiptap/pm/model";
|
|
95
|
+
|
|
96
|
+
// src/helpers/getBranchingNestedListAtCursor.ts
|
|
97
|
+
var getBranchingNestedListAtCursor = (state, itemName, wrapperNames) => {
|
|
98
|
+
const { selection } = state;
|
|
99
|
+
if (!selection.empty) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const { $from } = selection;
|
|
103
|
+
if (!$from.parent.isTextblock) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if ($from.parentOffset !== $from.parent.content.size) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
let listItemDepth = -1;
|
|
110
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
111
|
+
if ($from.node(depth).type.name === itemName) {
|
|
112
|
+
listItemDepth = depth;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (listItemDepth < 0) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const listItem = $from.node(listItemDepth);
|
|
120
|
+
const indexInListItem = $from.index(listItemDepth);
|
|
121
|
+
if (indexInListItem + 1 >= listItem.childCount) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const nextChild = listItem.child(indexInListItem + 1);
|
|
125
|
+
if (!wrapperNames.includes(nextChild.type.name)) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const itemType = state.schema.nodes[itemName];
|
|
129
|
+
let hasBranching = false;
|
|
130
|
+
nextChild.forEach((child) => {
|
|
131
|
+
if (child.type === itemType && child.childCount > 1) {
|
|
132
|
+
hasBranching = true;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (!hasBranching) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
const nodeAfter = state.doc.resolve($from.after()).nodeAfter;
|
|
139
|
+
if (!nodeAfter || !wrapperNames.includes(nodeAfter.type.name)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const items = [];
|
|
143
|
+
nodeAfter.forEach((child) => {
|
|
144
|
+
items.push(child);
|
|
145
|
+
});
|
|
146
|
+
if (items.length === 0) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
listItemDepth,
|
|
151
|
+
nestedList: nodeAfter,
|
|
152
|
+
nestedListPos: $from.after(),
|
|
153
|
+
insertPos: $from.after(listItemDepth),
|
|
154
|
+
items
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/helpers/hoistBranchingNestedList.ts
|
|
159
|
+
var hoistBranchingNestedList = (state, dispatch, itemName, wrapperNames) => {
|
|
160
|
+
const context = getBranchingNestedListAtCursor(state, itemName, wrapperNames);
|
|
161
|
+
if (!context) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const { selection } = state;
|
|
165
|
+
const { nestedList, nestedListPos, insertPos, items } = context;
|
|
166
|
+
const tr = state.tr;
|
|
167
|
+
tr.delete(nestedListPos, nestedListPos + nestedList.nodeSize);
|
|
168
|
+
const mappedInsertPos = tr.mapping.map(insertPos);
|
|
169
|
+
tr.insert(mappedInsertPos, Fragment.from(items));
|
|
170
|
+
tr.setSelection(selection.map(tr.doc, tr.mapping));
|
|
171
|
+
if (dispatch) {
|
|
172
|
+
dispatch(tr);
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// src/helpers/handleDeleteBranchingNestedList.ts
|
|
178
|
+
var handleDeleteBranchingNestedList = (editor, itemName, wrapperNames) => {
|
|
179
|
+
return hoistBranchingNestedList(editor.state, editor.view.dispatch, itemName, wrapperNames);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/helpers/createBranchingListDeleteKeymap.ts
|
|
183
|
+
var createBranchingListDeleteKeymap = (itemName, wrapperNames) => {
|
|
184
|
+
return Extension.create({
|
|
185
|
+
name: `${itemName}BranchingDeleteKeymap`,
|
|
186
|
+
priority: 101,
|
|
187
|
+
addKeyboardShortcuts() {
|
|
188
|
+
const handleDelete2 = () => handleDeleteBranchingNestedList(this.editor, itemName, wrapperNames);
|
|
189
|
+
return {
|
|
190
|
+
Delete: handleDelete2,
|
|
191
|
+
"Mod-Delete": handleDelete2
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/item/list-item.ts
|
|
89
198
|
function isSameLineOrderedListToken(token) {
|
|
90
199
|
var _a, _b;
|
|
91
200
|
const nestedToken = (_a = token.tokens) == null ? void 0 : _a[0];
|
|
@@ -200,6 +309,14 @@ var ListItem = Node2.create({
|
|
|
200
309
|
ctx
|
|
201
310
|
);
|
|
202
311
|
},
|
|
312
|
+
addExtensions() {
|
|
313
|
+
return [
|
|
314
|
+
createBranchingListDeleteKeymap(this.name, [
|
|
315
|
+
this.options.bulletListTypeName,
|
|
316
|
+
this.options.orderedListTypeName
|
|
317
|
+
])
|
|
318
|
+
];
|
|
319
|
+
},
|
|
203
320
|
addKeyboardShortcuts() {
|
|
204
321
|
return {
|
|
205
322
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
@@ -210,7 +327,7 @@ var ListItem = Node2.create({
|
|
|
210
327
|
});
|
|
211
328
|
|
|
212
329
|
// src/keymap/list-keymap.ts
|
|
213
|
-
import { Extension } from "@tiptap/core";
|
|
330
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
214
331
|
|
|
215
332
|
// src/keymap/listHelpers/index.ts
|
|
216
333
|
var listHelpers_exports = {};
|
|
@@ -276,36 +393,6 @@ var hasListBefore = (editorState, name, parentListTypes) => {
|
|
|
276
393
|
return true;
|
|
277
394
|
};
|
|
278
395
|
|
|
279
|
-
// src/keymap/listHelpers/hasListItemBefore.ts
|
|
280
|
-
var hasListItemBefore = (typeOrName, state) => {
|
|
281
|
-
var _a;
|
|
282
|
-
const { $anchor } = state.selection;
|
|
283
|
-
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
284
|
-
if ($targetPos.index() === 0) {
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
return true;
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
// src/keymap/listHelpers/listItemHasSubList.ts
|
|
294
|
-
import { getNodeType as getNodeType2 } from "@tiptap/core";
|
|
295
|
-
var listItemHasSubList = (typeOrName, state, node) => {
|
|
296
|
-
if (!node) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
const nodeType = getNodeType2(typeOrName, state.schema);
|
|
300
|
-
let hasSubList = false;
|
|
301
|
-
node.descendants((child) => {
|
|
302
|
-
if (child.type === nodeType) {
|
|
303
|
-
hasSubList = true;
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
return hasSubList;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
396
|
// src/keymap/listHelpers/handleBackspace.ts
|
|
310
397
|
var handleBackspace = (editor, name, parentListTypes) => {
|
|
311
398
|
if (editor.commands.undoInputRule()) {
|
|
@@ -336,16 +423,6 @@ var handleBackspace = (editor, name, parentListTypes) => {
|
|
|
336
423
|
if (!isAtStartOfNode(editor.state)) {
|
|
337
424
|
return false;
|
|
338
425
|
}
|
|
339
|
-
const listItemPos = findListItemPos(name, editor.state);
|
|
340
|
-
if (!listItemPos) {
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
344
|
-
const prevNode = $prev.node(listItemPos.depth);
|
|
345
|
-
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
346
|
-
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
347
|
-
return editor.commands.joinItemBackward();
|
|
348
|
-
}
|
|
349
426
|
return editor.chain().liftListItem(name).run();
|
|
350
427
|
};
|
|
351
428
|
|
|
@@ -414,8 +491,38 @@ var hasListItemAfter = (typeOrName, state) => {
|
|
|
414
491
|
return true;
|
|
415
492
|
};
|
|
416
493
|
|
|
494
|
+
// src/keymap/listHelpers/hasListItemBefore.ts
|
|
495
|
+
var hasListItemBefore = (typeOrName, state) => {
|
|
496
|
+
var _a;
|
|
497
|
+
const { $anchor } = state.selection;
|
|
498
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
499
|
+
if ($targetPos.index() === 0) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
return true;
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
// src/keymap/listHelpers/listItemHasSubList.ts
|
|
509
|
+
import { getNodeType as getNodeType2 } from "@tiptap/core";
|
|
510
|
+
var listItemHasSubList = (typeOrName, state, node) => {
|
|
511
|
+
if (!node) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
const nodeType = getNodeType2(typeOrName, state.schema);
|
|
515
|
+
let hasSubList = false;
|
|
516
|
+
node.descendants((child) => {
|
|
517
|
+
if (child.type === nodeType) {
|
|
518
|
+
hasSubList = true;
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
return hasSubList;
|
|
522
|
+
};
|
|
523
|
+
|
|
417
524
|
// src/keymap/list-keymap.ts
|
|
418
|
-
var ListKeymap =
|
|
525
|
+
var ListKeymap = Extension2.create({
|
|
419
526
|
name: "listKeymap",
|
|
420
527
|
addOptions() {
|
|
421
528
|
return {
|
|
@@ -486,7 +593,7 @@ var ListKeymap = Extension.create({
|
|
|
486
593
|
});
|
|
487
594
|
|
|
488
595
|
// src/kit/index.ts
|
|
489
|
-
import { Extension as
|
|
596
|
+
import { Extension as Extension3 } from "@tiptap/core";
|
|
490
597
|
|
|
491
598
|
// src/ordered-list/ordered-list.ts
|
|
492
599
|
import { mergeAttributes as mergeAttributes3, Node as Node3, wrappingInputRule as wrappingInputRule2 } from "@tiptap/core";
|
|
@@ -496,7 +603,14 @@ var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
|
|
|
496
603
|
var INDENTED_LINE_REGEX = /^\s/;
|
|
497
604
|
function isBlockContentLine(line) {
|
|
498
605
|
const trimmedLine = line.trimStart();
|
|
499
|
-
return
|
|
606
|
+
return (
|
|
607
|
+
// oxlint-disable-next-line prefer-string-starts-ends-with
|
|
608
|
+
/^[-+*]\s+/.test(trimmedLine) || // oxlint-disable-next-line prefer-string-starts-ends-with
|
|
609
|
+
/^\d+\.\s+/.test(trimmedLine) || // oxlint-disable-next-line prefer-string-starts-ends-with
|
|
610
|
+
/^>\s?/.test(trimmedLine) || // oxlint-disable-next-line prefer-string-starts-ends-with
|
|
611
|
+
/^```/.test(trimmedLine) || // oxlint-disable-next-line prefer-string-starts-ends-with
|
|
612
|
+
/^~~~/.test(trimmedLine)
|
|
613
|
+
);
|
|
500
614
|
}
|
|
501
615
|
function splitItemContent(contentLines) {
|
|
502
616
|
const paragraphLines = [];
|
|
@@ -881,6 +995,12 @@ var TaskItem = Node4.create({
|
|
|
881
995
|
const prefix = `- [${checkedChar}] `;
|
|
882
996
|
return renderNestedMarkdownContent2(node, h, prefix);
|
|
883
997
|
},
|
|
998
|
+
addExtensions() {
|
|
999
|
+
if (!this.options.nested) {
|
|
1000
|
+
return [];
|
|
1001
|
+
}
|
|
1002
|
+
return [createBranchingListDeleteKeymap(this.name, [this.options.taskListTypeName])];
|
|
1003
|
+
},
|
|
884
1004
|
addKeyboardShortcuts() {
|
|
885
1005
|
const shortcuts = {
|
|
886
1006
|
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
@@ -1022,7 +1142,11 @@ var TaskList = Node5.create({
|
|
|
1022
1142
|
];
|
|
1023
1143
|
},
|
|
1024
1144
|
renderHTML({ HTMLAttributes }) {
|
|
1025
|
-
return [
|
|
1145
|
+
return [
|
|
1146
|
+
"ul",
|
|
1147
|
+
mergeAttributes5(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }),
|
|
1148
|
+
0
|
|
1149
|
+
];
|
|
1026
1150
|
},
|
|
1027
1151
|
parseMarkdown: (token, h) => {
|
|
1028
1152
|
return h.createNode("taskList", {}, h.parseChildren(token.items || []));
|
|
@@ -1130,7 +1254,7 @@ var TaskList = Node5.create({
|
|
|
1130
1254
|
});
|
|
1131
1255
|
|
|
1132
1256
|
// src/kit/index.ts
|
|
1133
|
-
var ListKit =
|
|
1257
|
+
var ListKit = Extension3.create({
|
|
1134
1258
|
name: "listKit",
|
|
1135
1259
|
addExtensions() {
|
|
1136
1260
|
const extensions = [];
|