@tiptap/extension-list 3.20.3 → 3.20.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.
Files changed (49) hide show
  1. package/dist/bullet-list/index.cjs +112 -0
  2. package/dist/bullet-list/index.cjs.map +1 -0
  3. package/dist/bullet-list/index.d.cts +51 -0
  4. package/dist/bullet-list/index.d.ts +51 -0
  5. package/dist/bullet-list/index.js +84 -0
  6. package/dist/bullet-list/index.js.map +1 -0
  7. package/dist/index.cjs +1130 -0
  8. package/dist/index.cjs.map +1 -0
  9. package/dist/index.d.cts +300 -0
  10. package/dist/index.d.ts +300 -0
  11. package/dist/index.js +1105 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/item/index.cjs +125 -0
  14. package/dist/item/index.cjs.map +1 -0
  15. package/dist/item/index.d.cts +29 -0
  16. package/dist/item/index.d.ts +29 -0
  17. package/dist/item/index.js +98 -0
  18. package/dist/item/index.js.map +1 -0
  19. package/dist/keymap/index.cjs +308 -0
  20. package/dist/keymap/index.cjs.map +1 -0
  21. package/dist/keymap/index.d.cts +63 -0
  22. package/dist/keymap/index.d.ts +63 -0
  23. package/dist/keymap/index.js +286 -0
  24. package/dist/keymap/index.js.map +1 -0
  25. package/dist/kit/index.cjs +1108 -0
  26. package/dist/kit/index.cjs.map +1 -0
  27. package/dist/kit/index.d.cts +212 -0
  28. package/dist/kit/index.d.ts +212 -0
  29. package/dist/kit/index.js +1095 -0
  30. package/dist/kit/index.js.map +1 -0
  31. package/dist/ordered-list/index.cjs +302 -0
  32. package/dist/ordered-list/index.cjs.map +1 -0
  33. package/dist/ordered-list/index.d.cts +52 -0
  34. package/dist/ordered-list/index.d.ts +52 -0
  35. package/dist/ordered-list/index.js +274 -0
  36. package/dist/ordered-list/index.js.map +1 -0
  37. package/dist/task-item/index.cjs +231 -0
  38. package/dist/task-item/index.cjs.map +1 -0
  39. package/dist/task-item/index.d.cts +53 -0
  40. package/dist/task-item/index.d.ts +53 -0
  41. package/dist/task-item/index.js +209 -0
  42. package/dist/task-item/index.js.map +1 -0
  43. package/dist/task-list/index.cjs +160 -0
  44. package/dist/task-list/index.cjs.map +1 -0
  45. package/dist/task-list/index.d.cts +34 -0
  46. package/dist/task-list/index.d.ts +34 -0
  47. package/dist/task-list/index.js +133 -0
  48. package/dist/task-list/index.js.map +1 -0
  49. package/package.json +5 -5
package/dist/index.js ADDED
@@ -0,0 +1,1105 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/bullet-list/bullet-list.ts
8
+ import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
9
+ var ListItemName = "listItem";
10
+ var TextStyleName = "textStyle";
11
+ var bulletListInputRegex = /^\s*([-+*])\s$/;
12
+ var BulletList = Node.create({
13
+ name: "bulletList",
14
+ addOptions() {
15
+ return {
16
+ itemTypeName: "listItem",
17
+ HTMLAttributes: {},
18
+ keepMarks: false,
19
+ keepAttributes: false
20
+ };
21
+ },
22
+ group: "block list",
23
+ content() {
24
+ return `${this.options.itemTypeName}+`;
25
+ },
26
+ parseHTML() {
27
+ return [{ tag: "ul" }];
28
+ },
29
+ renderHTML({ HTMLAttributes }) {
30
+ return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
31
+ },
32
+ markdownTokenName: "list",
33
+ parseMarkdown: (token, helpers) => {
34
+ if (token.type !== "list" || token.ordered) {
35
+ return [];
36
+ }
37
+ return {
38
+ type: "bulletList",
39
+ content: token.items ? helpers.parseChildren(token.items) : []
40
+ };
41
+ },
42
+ renderMarkdown: (node, h) => {
43
+ if (!node.content) {
44
+ return "";
45
+ }
46
+ return h.renderChildren(node.content, "\n");
47
+ },
48
+ markdownOptions: {
49
+ indentsContent: true
50
+ },
51
+ addCommands() {
52
+ return {
53
+ toggleBulletList: () => ({ commands, chain }) => {
54
+ if (this.options.keepAttributes) {
55
+ return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
56
+ }
57
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
58
+ }
59
+ };
60
+ },
61
+ addKeyboardShortcuts() {
62
+ return {
63
+ "Mod-Shift-8": () => this.editor.commands.toggleBulletList()
64
+ };
65
+ },
66
+ addInputRules() {
67
+ let inputRule = wrappingInputRule({
68
+ find: bulletListInputRegex,
69
+ type: this.type
70
+ });
71
+ if (this.options.keepMarks || this.options.keepAttributes) {
72
+ inputRule = wrappingInputRule({
73
+ find: bulletListInputRegex,
74
+ type: this.type,
75
+ keepMarks: this.options.keepMarks,
76
+ keepAttributes: this.options.keepAttributes,
77
+ getAttributes: () => {
78
+ return this.editor.getAttributes(TextStyleName);
79
+ },
80
+ editor: this.editor
81
+ });
82
+ }
83
+ return [inputRule];
84
+ }
85
+ });
86
+
87
+ // src/item/list-item.ts
88
+ import { mergeAttributes as mergeAttributes2, Node as Node2, renderNestedMarkdownContent } from "@tiptap/core";
89
+ var ListItem = Node2.create({
90
+ name: "listItem",
91
+ addOptions() {
92
+ return {
93
+ HTMLAttributes: {},
94
+ bulletListTypeName: "bulletList",
95
+ orderedListTypeName: "orderedList"
96
+ };
97
+ },
98
+ content: "paragraph block*",
99
+ defining: true,
100
+ parseHTML() {
101
+ return [
102
+ {
103
+ tag: "li"
104
+ }
105
+ ];
106
+ },
107
+ renderHTML({ HTMLAttributes }) {
108
+ return ["li", mergeAttributes2(this.options.HTMLAttributes, HTMLAttributes), 0];
109
+ },
110
+ markdownTokenName: "list_item",
111
+ parseMarkdown: (token, helpers) => {
112
+ var _a;
113
+ if (token.type !== "list_item") {
114
+ return [];
115
+ }
116
+ const parseBlockChildren = (_a = helpers.parseBlockChildren) != null ? _a : helpers.parseChildren;
117
+ let content = [];
118
+ if (token.tokens && token.tokens.length > 0) {
119
+ const hasParagraphTokens = token.tokens.some((t) => t.type === "paragraph");
120
+ if (hasParagraphTokens) {
121
+ content = parseBlockChildren(token.tokens);
122
+ } else {
123
+ const firstToken = token.tokens[0];
124
+ if (firstToken && firstToken.type === "text" && firstToken.tokens && firstToken.tokens.length > 0) {
125
+ const inlineContent = helpers.parseInline(firstToken.tokens);
126
+ content = [
127
+ {
128
+ type: "paragraph",
129
+ content: inlineContent
130
+ }
131
+ ];
132
+ if (token.tokens.length > 1) {
133
+ const remainingTokens = token.tokens.slice(1);
134
+ const additionalContent = parseBlockChildren(remainingTokens);
135
+ content.push(...additionalContent);
136
+ }
137
+ } else {
138
+ content = parseBlockChildren(token.tokens);
139
+ }
140
+ }
141
+ }
142
+ if (content.length === 0) {
143
+ content = [
144
+ {
145
+ type: "paragraph",
146
+ content: []
147
+ }
148
+ ];
149
+ }
150
+ return {
151
+ type: "listItem",
152
+ content
153
+ };
154
+ },
155
+ renderMarkdown: (node, h, ctx) => {
156
+ return renderNestedMarkdownContent(
157
+ node,
158
+ h,
159
+ (context) => {
160
+ var _a, _b;
161
+ if (context.parentType === "bulletList") {
162
+ return "- ";
163
+ }
164
+ if (context.parentType === "orderedList") {
165
+ const start = ((_b = (_a = context.meta) == null ? void 0 : _a.parentAttrs) == null ? void 0 : _b.start) || 1;
166
+ return `${start + context.index}. `;
167
+ }
168
+ return "- ";
169
+ },
170
+ ctx
171
+ );
172
+ },
173
+ addKeyboardShortcuts() {
174
+ return {
175
+ Enter: () => this.editor.commands.splitListItem(this.name),
176
+ Tab: () => this.editor.commands.sinkListItem(this.name),
177
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
178
+ };
179
+ }
180
+ });
181
+
182
+ // src/keymap/list-keymap.ts
183
+ import { Extension } from "@tiptap/core";
184
+
185
+ // src/keymap/listHelpers/index.ts
186
+ var listHelpers_exports = {};
187
+ __export(listHelpers_exports, {
188
+ findListItemPos: () => findListItemPos,
189
+ getNextListDepth: () => getNextListDepth,
190
+ handleBackspace: () => handleBackspace,
191
+ handleDelete: () => handleDelete,
192
+ hasListBefore: () => hasListBefore,
193
+ hasListItemAfter: () => hasListItemAfter,
194
+ hasListItemBefore: () => hasListItemBefore,
195
+ listItemHasSubList: () => listItemHasSubList,
196
+ nextListIsDeeper: () => nextListIsDeeper,
197
+ nextListIsHigher: () => nextListIsHigher
198
+ });
199
+
200
+ // src/keymap/listHelpers/findListItemPos.ts
201
+ import { getNodeType } from "@tiptap/core";
202
+ var findListItemPos = (typeOrName, state) => {
203
+ const { $from } = state.selection;
204
+ const nodeType = getNodeType(typeOrName, state.schema);
205
+ let currentNode = null;
206
+ let currentDepth = $from.depth;
207
+ let currentPos = $from.pos;
208
+ let targetDepth = null;
209
+ while (currentDepth > 0 && targetDepth === null) {
210
+ currentNode = $from.node(currentDepth);
211
+ if (currentNode.type === nodeType) {
212
+ targetDepth = currentDepth;
213
+ } else {
214
+ currentDepth -= 1;
215
+ currentPos -= 1;
216
+ }
217
+ }
218
+ if (targetDepth === null) {
219
+ return null;
220
+ }
221
+ return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
222
+ };
223
+
224
+ // src/keymap/listHelpers/getNextListDepth.ts
225
+ import { getNodeAtPosition } from "@tiptap/core";
226
+ var getNextListDepth = (typeOrName, state) => {
227
+ const listItemPos = findListItemPos(typeOrName, state);
228
+ if (!listItemPos) {
229
+ return false;
230
+ }
231
+ const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
232
+ return depth;
233
+ };
234
+
235
+ // src/keymap/listHelpers/handleBackspace.ts
236
+ import { isAtStartOfNode, isNodeActive } from "@tiptap/core";
237
+
238
+ // src/keymap/listHelpers/hasListBefore.ts
239
+ var hasListBefore = (editorState, name, parentListTypes) => {
240
+ const { $anchor } = editorState.selection;
241
+ const previousNodePos = Math.max(0, $anchor.pos - 2);
242
+ const previousNode = editorState.doc.resolve(previousNodePos).node();
243
+ if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
244
+ return false;
245
+ }
246
+ return true;
247
+ };
248
+
249
+ // src/keymap/listHelpers/hasListItemBefore.ts
250
+ var hasListItemBefore = (typeOrName, state) => {
251
+ var _a;
252
+ const { $anchor } = state.selection;
253
+ const $targetPos = state.doc.resolve($anchor.pos - 2);
254
+ if ($targetPos.index() === 0) {
255
+ return false;
256
+ }
257
+ if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
258
+ return false;
259
+ }
260
+ return true;
261
+ };
262
+
263
+ // src/keymap/listHelpers/listItemHasSubList.ts
264
+ import { getNodeType as getNodeType2 } from "@tiptap/core";
265
+ var listItemHasSubList = (typeOrName, state, node) => {
266
+ if (!node) {
267
+ return false;
268
+ }
269
+ const nodeType = getNodeType2(typeOrName, state.schema);
270
+ let hasSubList = false;
271
+ node.descendants((child) => {
272
+ if (child.type === nodeType) {
273
+ hasSubList = true;
274
+ }
275
+ });
276
+ return hasSubList;
277
+ };
278
+
279
+ // src/keymap/listHelpers/handleBackspace.ts
280
+ var handleBackspace = (editor, name, parentListTypes) => {
281
+ if (editor.commands.undoInputRule()) {
282
+ return true;
283
+ }
284
+ if (editor.state.selection.from !== editor.state.selection.to) {
285
+ return false;
286
+ }
287
+ if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
288
+ const { $anchor } = editor.state.selection;
289
+ const $listPos = editor.state.doc.resolve($anchor.before() - 1);
290
+ const listDescendants = [];
291
+ $listPos.node().descendants((node, pos) => {
292
+ if (node.type.name === name) {
293
+ listDescendants.push({ node, pos });
294
+ }
295
+ });
296
+ const lastItem = listDescendants.at(-1);
297
+ if (!lastItem) {
298
+ return false;
299
+ }
300
+ const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
301
+ return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
302
+ }
303
+ if (!isNodeActive(editor.state, name)) {
304
+ return false;
305
+ }
306
+ if (!isAtStartOfNode(editor.state)) {
307
+ return false;
308
+ }
309
+ const listItemPos = findListItemPos(name, editor.state);
310
+ if (!listItemPos) {
311
+ return false;
312
+ }
313
+ const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
314
+ const prevNode = $prev.node(listItemPos.depth);
315
+ const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
316
+ if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
317
+ return editor.commands.joinItemBackward();
318
+ }
319
+ return editor.chain().liftListItem(name).run();
320
+ };
321
+
322
+ // src/keymap/listHelpers/handleDelete.ts
323
+ import { isAtEndOfNode, isNodeActive as isNodeActive2 } from "@tiptap/core";
324
+
325
+ // src/keymap/listHelpers/nextListIsDeeper.ts
326
+ var nextListIsDeeper = (typeOrName, state) => {
327
+ const listDepth = getNextListDepth(typeOrName, state);
328
+ const listItemPos = findListItemPos(typeOrName, state);
329
+ if (!listItemPos || !listDepth) {
330
+ return false;
331
+ }
332
+ if (listDepth > listItemPos.depth) {
333
+ return true;
334
+ }
335
+ return false;
336
+ };
337
+
338
+ // src/keymap/listHelpers/nextListIsHigher.ts
339
+ var nextListIsHigher = (typeOrName, state) => {
340
+ const listDepth = getNextListDepth(typeOrName, state);
341
+ const listItemPos = findListItemPos(typeOrName, state);
342
+ if (!listItemPos || !listDepth) {
343
+ return false;
344
+ }
345
+ if (listDepth < listItemPos.depth) {
346
+ return true;
347
+ }
348
+ return false;
349
+ };
350
+
351
+ // src/keymap/listHelpers/handleDelete.ts
352
+ var handleDelete = (editor, name) => {
353
+ if (!isNodeActive2(editor.state, name)) {
354
+ return false;
355
+ }
356
+ if (!isAtEndOfNode(editor.state, name)) {
357
+ return false;
358
+ }
359
+ const { selection } = editor.state;
360
+ const { $from, $to } = selection;
361
+ if (!selection.empty && $from.sameParent($to)) {
362
+ return false;
363
+ }
364
+ if (nextListIsDeeper(name, editor.state)) {
365
+ return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
366
+ }
367
+ if (nextListIsHigher(name, editor.state)) {
368
+ return editor.chain().joinForward().joinBackward().run();
369
+ }
370
+ return editor.commands.joinItemForward();
371
+ };
372
+
373
+ // src/keymap/listHelpers/hasListItemAfter.ts
374
+ var hasListItemAfter = (typeOrName, state) => {
375
+ var _a;
376
+ const { $anchor } = state.selection;
377
+ const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
378
+ if ($targetPos.index() === $targetPos.parent.childCount - 1) {
379
+ return false;
380
+ }
381
+ if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) {
382
+ return false;
383
+ }
384
+ return true;
385
+ };
386
+
387
+ // src/keymap/list-keymap.ts
388
+ var ListKeymap = Extension.create({
389
+ name: "listKeymap",
390
+ addOptions() {
391
+ return {
392
+ listTypes: [
393
+ {
394
+ itemName: "listItem",
395
+ wrapperNames: ["bulletList", "orderedList"]
396
+ },
397
+ {
398
+ itemName: "taskItem",
399
+ wrapperNames: ["taskList"]
400
+ }
401
+ ]
402
+ };
403
+ },
404
+ addKeyboardShortcuts() {
405
+ return {
406
+ Delete: ({ editor }) => {
407
+ let handled = false;
408
+ this.options.listTypes.forEach(({ itemName }) => {
409
+ if (editor.state.schema.nodes[itemName] === void 0) {
410
+ return;
411
+ }
412
+ if (handleDelete(editor, itemName)) {
413
+ handled = true;
414
+ }
415
+ });
416
+ return handled;
417
+ },
418
+ "Mod-Delete": ({ editor }) => {
419
+ let handled = false;
420
+ this.options.listTypes.forEach(({ itemName }) => {
421
+ if (editor.state.schema.nodes[itemName] === void 0) {
422
+ return;
423
+ }
424
+ if (handleDelete(editor, itemName)) {
425
+ handled = true;
426
+ }
427
+ });
428
+ return handled;
429
+ },
430
+ Backspace: ({ editor }) => {
431
+ let handled = false;
432
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
433
+ if (editor.state.schema.nodes[itemName] === void 0) {
434
+ return;
435
+ }
436
+ if (handleBackspace(editor, itemName, wrapperNames)) {
437
+ handled = true;
438
+ }
439
+ });
440
+ return handled;
441
+ },
442
+ "Mod-Backspace": ({ editor }) => {
443
+ let handled = false;
444
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
445
+ if (editor.state.schema.nodes[itemName] === void 0) {
446
+ return;
447
+ }
448
+ if (handleBackspace(editor, itemName, wrapperNames)) {
449
+ handled = true;
450
+ }
451
+ });
452
+ return handled;
453
+ }
454
+ };
455
+ }
456
+ });
457
+
458
+ // src/kit/index.ts
459
+ import { Extension as Extension2 } from "@tiptap/core";
460
+
461
+ // src/ordered-list/ordered-list.ts
462
+ import { mergeAttributes as mergeAttributes3, Node as Node3, wrappingInputRule as wrappingInputRule2 } from "@tiptap/core";
463
+
464
+ // src/ordered-list/utils.ts
465
+ var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
466
+ var INDENTED_LINE_REGEX = /^\s/;
467
+ function collectOrderedListItems(lines) {
468
+ const listItems = [];
469
+ let currentLineIndex = 0;
470
+ let consumed = 0;
471
+ while (currentLineIndex < lines.length) {
472
+ const line = lines[currentLineIndex];
473
+ const match = line.match(ORDERED_LIST_ITEM_REGEX);
474
+ if (!match) {
475
+ break;
476
+ }
477
+ const [, indent, number, content] = match;
478
+ const indentLevel = indent.length;
479
+ let itemContent = content;
480
+ let nextLineIndex = currentLineIndex + 1;
481
+ const itemLines = [line];
482
+ while (nextLineIndex < lines.length) {
483
+ const nextLine = lines[nextLineIndex];
484
+ const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX);
485
+ if (nextMatch) {
486
+ break;
487
+ }
488
+ if (nextLine.trim() === "") {
489
+ itemLines.push(nextLine);
490
+ itemContent += "\n";
491
+ nextLineIndex += 1;
492
+ } else if (nextLine.match(INDENTED_LINE_REGEX)) {
493
+ itemLines.push(nextLine);
494
+ itemContent += `
495
+ ${nextLine.slice(indentLevel + 2)}`;
496
+ nextLineIndex += 1;
497
+ } else {
498
+ break;
499
+ }
500
+ }
501
+ listItems.push({
502
+ indent: indentLevel,
503
+ number: parseInt(number, 10),
504
+ content: itemContent.trim(),
505
+ raw: itemLines.join("\n")
506
+ });
507
+ consumed = nextLineIndex;
508
+ currentLineIndex = nextLineIndex;
509
+ }
510
+ return [listItems, consumed];
511
+ }
512
+ function buildNestedStructure(items, baseIndent, lexer) {
513
+ var _a;
514
+ const result = [];
515
+ let currentIndex = 0;
516
+ while (currentIndex < items.length) {
517
+ const item = items[currentIndex];
518
+ if (item.indent === baseIndent) {
519
+ const contentLines = item.content.split("\n");
520
+ const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || "";
521
+ const tokens = [];
522
+ if (mainText) {
523
+ tokens.push({
524
+ type: "paragraph",
525
+ raw: mainText,
526
+ tokens: lexer.inlineTokens(mainText)
527
+ });
528
+ }
529
+ const additionalContent = contentLines.slice(1).join("\n").trim();
530
+ if (additionalContent) {
531
+ const blockTokens = lexer.blockTokens(additionalContent);
532
+ tokens.push(...blockTokens);
533
+ }
534
+ let lookAheadIndex = currentIndex + 1;
535
+ const nestedItems = [];
536
+ while (lookAheadIndex < items.length && items[lookAheadIndex].indent > baseIndent) {
537
+ nestedItems.push(items[lookAheadIndex]);
538
+ lookAheadIndex += 1;
539
+ }
540
+ if (nestedItems.length > 0) {
541
+ const nextIndent = Math.min(...nestedItems.map((nestedItem) => nestedItem.indent));
542
+ const nestedListItems = buildNestedStructure(nestedItems, nextIndent, lexer);
543
+ tokens.push({
544
+ type: "list",
545
+ ordered: true,
546
+ start: nestedItems[0].number,
547
+ items: nestedListItems,
548
+ raw: nestedItems.map((nestedItem) => nestedItem.raw).join("\n")
549
+ });
550
+ }
551
+ result.push({
552
+ type: "list_item",
553
+ raw: item.raw,
554
+ tokens
555
+ });
556
+ currentIndex = lookAheadIndex;
557
+ } else {
558
+ currentIndex += 1;
559
+ }
560
+ }
561
+ return result;
562
+ }
563
+ function parseListItems(items, helpers) {
564
+ return items.map((item) => {
565
+ if (item.type !== "list_item") {
566
+ return helpers.parseChildren([item])[0];
567
+ }
568
+ const content = [];
569
+ if (item.tokens && item.tokens.length > 0) {
570
+ item.tokens.forEach((itemToken) => {
571
+ if (itemToken.type === "paragraph" || itemToken.type === "list" || itemToken.type === "blockquote" || itemToken.type === "code") {
572
+ content.push(...helpers.parseChildren([itemToken]));
573
+ } else if (itemToken.type === "text" && itemToken.tokens) {
574
+ const inlineContent = helpers.parseChildren([itemToken]);
575
+ content.push({
576
+ type: "paragraph",
577
+ content: inlineContent
578
+ });
579
+ } else {
580
+ const parsed = helpers.parseChildren([itemToken]);
581
+ if (parsed.length > 0) {
582
+ content.push(...parsed);
583
+ }
584
+ }
585
+ });
586
+ }
587
+ return {
588
+ type: "listItem",
589
+ content
590
+ };
591
+ });
592
+ }
593
+
594
+ // src/ordered-list/ordered-list.ts
595
+ var ListItemName2 = "listItem";
596
+ var TextStyleName2 = "textStyle";
597
+ var orderedListInputRegex = /^(\d+)\.\s$/;
598
+ var OrderedList = Node3.create({
599
+ name: "orderedList",
600
+ addOptions() {
601
+ return {
602
+ itemTypeName: "listItem",
603
+ HTMLAttributes: {},
604
+ keepMarks: false,
605
+ keepAttributes: false
606
+ };
607
+ },
608
+ group: "block list",
609
+ content() {
610
+ return `${this.options.itemTypeName}+`;
611
+ },
612
+ addAttributes() {
613
+ return {
614
+ start: {
615
+ default: 1,
616
+ parseHTML: (element) => {
617
+ return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1;
618
+ }
619
+ },
620
+ type: {
621
+ default: null,
622
+ parseHTML: (element) => element.getAttribute("type")
623
+ }
624
+ };
625
+ },
626
+ parseHTML() {
627
+ return [
628
+ {
629
+ tag: "ol"
630
+ }
631
+ ];
632
+ },
633
+ renderHTML({ HTMLAttributes }) {
634
+ const { start, ...attributesWithoutStart } = HTMLAttributes;
635
+ return start === 1 ? ["ol", mergeAttributes3(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", mergeAttributes3(this.options.HTMLAttributes, HTMLAttributes), 0];
636
+ },
637
+ markdownTokenName: "list",
638
+ parseMarkdown: (token, helpers) => {
639
+ if (token.type !== "list" || !token.ordered) {
640
+ return [];
641
+ }
642
+ const startValue = token.start || 1;
643
+ const content = token.items ? parseListItems(token.items, helpers) : [];
644
+ if (startValue !== 1) {
645
+ return {
646
+ type: "orderedList",
647
+ attrs: { start: startValue },
648
+ content
649
+ };
650
+ }
651
+ return {
652
+ type: "orderedList",
653
+ content
654
+ };
655
+ },
656
+ renderMarkdown: (node, h) => {
657
+ if (!node.content) {
658
+ return "";
659
+ }
660
+ return h.renderChildren(node.content, "\n");
661
+ },
662
+ markdownTokenizer: {
663
+ name: "orderedList",
664
+ level: "block",
665
+ start: (src) => {
666
+ const match = src.match(/^(\s*)(\d+)\.\s+/);
667
+ const index = match == null ? void 0 : match.index;
668
+ return index !== void 0 ? index : -1;
669
+ },
670
+ tokenize: (src, _tokens, lexer) => {
671
+ var _a;
672
+ const lines = src.split("\n");
673
+ const [listItems, consumed] = collectOrderedListItems(lines);
674
+ if (listItems.length === 0) {
675
+ return void 0;
676
+ }
677
+ const items = buildNestedStructure(listItems, 0, lexer);
678
+ if (items.length === 0) {
679
+ return void 0;
680
+ }
681
+ const startValue = ((_a = listItems[0]) == null ? void 0 : _a.number) || 1;
682
+ return {
683
+ type: "list",
684
+ ordered: true,
685
+ start: startValue,
686
+ items,
687
+ raw: lines.slice(0, consumed).join("\n")
688
+ };
689
+ }
690
+ },
691
+ markdownOptions: {
692
+ indentsContent: true
693
+ },
694
+ addCommands() {
695
+ return {
696
+ toggleOrderedList: () => ({ commands, chain }) => {
697
+ if (this.options.keepAttributes) {
698
+ return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName2, this.editor.getAttributes(TextStyleName2)).run();
699
+ }
700
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
701
+ }
702
+ };
703
+ },
704
+ addKeyboardShortcuts() {
705
+ return {
706
+ "Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
707
+ };
708
+ },
709
+ addInputRules() {
710
+ let inputRule = wrappingInputRule2({
711
+ find: orderedListInputRegex,
712
+ type: this.type,
713
+ getAttributes: (match) => ({ start: +match[1] }),
714
+ joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1]
715
+ });
716
+ if (this.options.keepMarks || this.options.keepAttributes) {
717
+ inputRule = wrappingInputRule2({
718
+ find: orderedListInputRegex,
719
+ type: this.type,
720
+ keepMarks: this.options.keepMarks,
721
+ keepAttributes: this.options.keepAttributes,
722
+ getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName2) }),
723
+ joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
724
+ editor: this.editor
725
+ });
726
+ }
727
+ return [inputRule];
728
+ }
729
+ });
730
+
731
+ // src/task-item/task-item.ts
732
+ import {
733
+ getRenderedAttributes,
734
+ mergeAttributes as mergeAttributes4,
735
+ Node as Node4,
736
+ renderNestedMarkdownContent as renderNestedMarkdownContent2,
737
+ wrappingInputRule as wrappingInputRule3
738
+ } from "@tiptap/core";
739
+ var inputRegex = /^\s*(\[([( |x])?\])\s$/;
740
+ var TaskItem = Node4.create({
741
+ name: "taskItem",
742
+ addOptions() {
743
+ return {
744
+ nested: false,
745
+ HTMLAttributes: {},
746
+ taskListTypeName: "taskList",
747
+ a11y: void 0
748
+ };
749
+ },
750
+ content() {
751
+ return this.options.nested ? "paragraph block*" : "paragraph+";
752
+ },
753
+ defining: true,
754
+ addAttributes() {
755
+ return {
756
+ checked: {
757
+ default: false,
758
+ keepOnSplit: false,
759
+ parseHTML: (element) => {
760
+ const dataChecked = element.getAttribute("data-checked");
761
+ return dataChecked === "" || dataChecked === "true";
762
+ },
763
+ renderHTML: (attributes) => ({
764
+ "data-checked": attributes.checked
765
+ })
766
+ }
767
+ };
768
+ },
769
+ parseHTML() {
770
+ return [
771
+ {
772
+ tag: `li[data-type="${this.name}"]`,
773
+ priority: 51
774
+ }
775
+ ];
776
+ },
777
+ renderHTML({ node, HTMLAttributes }) {
778
+ return [
779
+ "li",
780
+ mergeAttributes4(this.options.HTMLAttributes, HTMLAttributes, {
781
+ "data-type": this.name
782
+ }),
783
+ [
784
+ "label",
785
+ [
786
+ "input",
787
+ {
788
+ type: "checkbox",
789
+ checked: node.attrs.checked ? "checked" : null
790
+ }
791
+ ],
792
+ ["span"]
793
+ ],
794
+ ["div", 0]
795
+ ];
796
+ },
797
+ parseMarkdown: (token, h) => {
798
+ const content = [];
799
+ if (token.tokens && token.tokens.length > 0) {
800
+ content.push(h.createNode("paragraph", {}, h.parseInline(token.tokens)));
801
+ } else if (token.text) {
802
+ content.push(h.createNode("paragraph", {}, [h.createNode("text", { text: token.text })]));
803
+ } else {
804
+ content.push(h.createNode("paragraph", {}, []));
805
+ }
806
+ if (token.nestedTokens && token.nestedTokens.length > 0) {
807
+ const nestedContent = h.parseChildren(token.nestedTokens);
808
+ content.push(...nestedContent);
809
+ }
810
+ return h.createNode("taskItem", { checked: token.checked || false }, content);
811
+ },
812
+ renderMarkdown: (node, h) => {
813
+ var _a;
814
+ const checkedChar = ((_a = node.attrs) == null ? void 0 : _a.checked) ? "x" : " ";
815
+ const prefix = `- [${checkedChar}] `;
816
+ return renderNestedMarkdownContent2(node, h, prefix);
817
+ },
818
+ addKeyboardShortcuts() {
819
+ const shortcuts = {
820
+ Enter: () => this.editor.commands.splitListItem(this.name),
821
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
822
+ };
823
+ if (!this.options.nested) {
824
+ return shortcuts;
825
+ }
826
+ return {
827
+ ...shortcuts,
828
+ Tab: () => this.editor.commands.sinkListItem(this.name)
829
+ };
830
+ },
831
+ addNodeView() {
832
+ return ({ node, HTMLAttributes, getPos, editor }) => {
833
+ const listItem = document.createElement("li");
834
+ const checkboxWrapper = document.createElement("label");
835
+ const checkboxStyler = document.createElement("span");
836
+ const checkbox = document.createElement("input");
837
+ const content = document.createElement("div");
838
+ const updateA11Y = (currentNode) => {
839
+ var _a, _b;
840
+ checkbox.ariaLabel = ((_b = (_a = this.options.a11y) == null ? void 0 : _a.checkboxLabel) == null ? void 0 : _b.call(_a, currentNode, checkbox.checked)) || `Task item checkbox for ${currentNode.textContent || "empty task item"}`;
841
+ };
842
+ updateA11Y(node);
843
+ checkboxWrapper.contentEditable = "false";
844
+ checkbox.type = "checkbox";
845
+ checkbox.addEventListener("mousedown", (event) => event.preventDefault());
846
+ checkbox.addEventListener("change", (event) => {
847
+ if (!editor.isEditable && !this.options.onReadOnlyChecked) {
848
+ checkbox.checked = !checkbox.checked;
849
+ return;
850
+ }
851
+ const { checked } = event.target;
852
+ if (editor.isEditable && typeof getPos === "function") {
853
+ editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr }) => {
854
+ const position = getPos();
855
+ if (typeof position !== "number") {
856
+ return false;
857
+ }
858
+ const currentNode = tr.doc.nodeAt(position);
859
+ tr.setNodeMarkup(position, void 0, {
860
+ ...currentNode == null ? void 0 : currentNode.attrs,
861
+ checked
862
+ });
863
+ return true;
864
+ }).run();
865
+ }
866
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
867
+ if (!this.options.onReadOnlyChecked(node, checked)) {
868
+ checkbox.checked = !checkbox.checked;
869
+ }
870
+ }
871
+ });
872
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
873
+ listItem.setAttribute(key, value);
874
+ });
875
+ listItem.dataset.checked = node.attrs.checked;
876
+ checkbox.checked = node.attrs.checked;
877
+ checkboxWrapper.append(checkbox, checkboxStyler);
878
+ listItem.append(checkboxWrapper, content);
879
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
880
+ listItem.setAttribute(key, value);
881
+ });
882
+ let prevRenderedAttributeKeys = new Set(Object.keys(HTMLAttributes));
883
+ return {
884
+ dom: listItem,
885
+ contentDOM: content,
886
+ update: (updatedNode) => {
887
+ if (updatedNode.type !== this.type) {
888
+ return false;
889
+ }
890
+ listItem.dataset.checked = updatedNode.attrs.checked;
891
+ checkbox.checked = updatedNode.attrs.checked;
892
+ updateA11Y(updatedNode);
893
+ const extensionAttributes = editor.extensionManager.attributes;
894
+ const newHTMLAttributes = getRenderedAttributes(updatedNode, extensionAttributes);
895
+ const newKeys = new Set(Object.keys(newHTMLAttributes));
896
+ const staticAttrs = this.options.HTMLAttributes;
897
+ prevRenderedAttributeKeys.forEach((key) => {
898
+ if (!newKeys.has(key)) {
899
+ if (key in staticAttrs) {
900
+ listItem.setAttribute(key, staticAttrs[key]);
901
+ } else {
902
+ listItem.removeAttribute(key);
903
+ }
904
+ }
905
+ });
906
+ Object.entries(newHTMLAttributes).forEach(([key, value]) => {
907
+ if (value === null || value === void 0) {
908
+ if (key in staticAttrs) {
909
+ listItem.setAttribute(key, staticAttrs[key]);
910
+ } else {
911
+ listItem.removeAttribute(key);
912
+ }
913
+ } else {
914
+ listItem.setAttribute(key, value);
915
+ }
916
+ });
917
+ prevRenderedAttributeKeys = newKeys;
918
+ return true;
919
+ }
920
+ };
921
+ };
922
+ },
923
+ addInputRules() {
924
+ return [
925
+ wrappingInputRule3({
926
+ find: inputRegex,
927
+ type: this.type,
928
+ getAttributes: (match) => ({
929
+ checked: match[match.length - 1] === "x"
930
+ })
931
+ })
932
+ ];
933
+ }
934
+ });
935
+
936
+ // src/task-list/task-list.ts
937
+ import { mergeAttributes as mergeAttributes5, Node as Node5, parseIndentedBlocks } from "@tiptap/core";
938
+ var TaskList = Node5.create({
939
+ name: "taskList",
940
+ addOptions() {
941
+ return {
942
+ itemTypeName: "taskItem",
943
+ HTMLAttributes: {}
944
+ };
945
+ },
946
+ group: "block list",
947
+ content() {
948
+ return `${this.options.itemTypeName}+`;
949
+ },
950
+ parseHTML() {
951
+ return [
952
+ {
953
+ tag: `ul[data-type="${this.name}"]`,
954
+ priority: 51
955
+ }
956
+ ];
957
+ },
958
+ renderHTML({ HTMLAttributes }) {
959
+ return ["ul", mergeAttributes5(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
960
+ },
961
+ parseMarkdown: (token, h) => {
962
+ return h.createNode("taskList", {}, h.parseChildren(token.items || []));
963
+ },
964
+ renderMarkdown: (node, h) => {
965
+ if (!node.content) {
966
+ return "";
967
+ }
968
+ return h.renderChildren(node.content, "\n");
969
+ },
970
+ markdownTokenizer: {
971
+ name: "taskList",
972
+ level: "block",
973
+ start(src) {
974
+ var _a;
975
+ const index = (_a = src.match(/^\s*[-+*]\s+\[([ xX])\]\s+/)) == null ? void 0 : _a.index;
976
+ return index !== void 0 ? index : -1;
977
+ },
978
+ tokenize(src, tokens, lexer) {
979
+ const parseTaskListContent = (content) => {
980
+ const nestedResult = parseIndentedBlocks(
981
+ content,
982
+ {
983
+ itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
984
+ extractItemData: (match) => ({
985
+ indentLevel: match[1].length,
986
+ mainContent: match[4],
987
+ checked: match[3].toLowerCase() === "x"
988
+ }),
989
+ createToken: (data, nestedTokens) => ({
990
+ type: "taskItem",
991
+ raw: "",
992
+ mainContent: data.mainContent,
993
+ indentLevel: data.indentLevel,
994
+ checked: data.checked,
995
+ text: data.mainContent,
996
+ tokens: lexer.inlineTokens(data.mainContent),
997
+ nestedTokens
998
+ }),
999
+ // Allow recursive nesting
1000
+ customNestedParser: parseTaskListContent
1001
+ },
1002
+ lexer
1003
+ );
1004
+ if (nestedResult) {
1005
+ return [
1006
+ {
1007
+ type: "taskList",
1008
+ raw: nestedResult.raw,
1009
+ items: nestedResult.items
1010
+ }
1011
+ ];
1012
+ }
1013
+ return lexer.blockTokens(content);
1014
+ };
1015
+ const result = parseIndentedBlocks(
1016
+ src,
1017
+ {
1018
+ itemPattern: /^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,
1019
+ extractItemData: (match) => ({
1020
+ indentLevel: match[1].length,
1021
+ mainContent: match[4],
1022
+ checked: match[3].toLowerCase() === "x"
1023
+ }),
1024
+ createToken: (data, nestedTokens) => ({
1025
+ type: "taskItem",
1026
+ raw: "",
1027
+ mainContent: data.mainContent,
1028
+ indentLevel: data.indentLevel,
1029
+ checked: data.checked,
1030
+ text: data.mainContent,
1031
+ tokens: lexer.inlineTokens(data.mainContent),
1032
+ nestedTokens
1033
+ }),
1034
+ // Use the recursive parser for nested content
1035
+ customNestedParser: parseTaskListContent
1036
+ },
1037
+ lexer
1038
+ );
1039
+ if (!result) {
1040
+ return void 0;
1041
+ }
1042
+ return {
1043
+ type: "taskList",
1044
+ raw: result.raw,
1045
+ items: result.items
1046
+ };
1047
+ }
1048
+ },
1049
+ markdownOptions: {
1050
+ indentsContent: true
1051
+ },
1052
+ addCommands() {
1053
+ return {
1054
+ toggleTaskList: () => ({ commands }) => {
1055
+ return commands.toggleList(this.name, this.options.itemTypeName);
1056
+ }
1057
+ };
1058
+ },
1059
+ addKeyboardShortcuts() {
1060
+ return {
1061
+ "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
1062
+ };
1063
+ }
1064
+ });
1065
+
1066
+ // src/kit/index.ts
1067
+ var ListKit = Extension2.create({
1068
+ name: "listKit",
1069
+ addExtensions() {
1070
+ const extensions = [];
1071
+ if (this.options.bulletList !== false) {
1072
+ extensions.push(BulletList.configure(this.options.bulletList));
1073
+ }
1074
+ if (this.options.listItem !== false) {
1075
+ extensions.push(ListItem.configure(this.options.listItem));
1076
+ }
1077
+ if (this.options.listKeymap !== false) {
1078
+ extensions.push(ListKeymap.configure(this.options.listKeymap));
1079
+ }
1080
+ if (this.options.orderedList !== false) {
1081
+ extensions.push(OrderedList.configure(this.options.orderedList));
1082
+ }
1083
+ if (this.options.taskItem !== false) {
1084
+ extensions.push(TaskItem.configure(this.options.taskItem));
1085
+ }
1086
+ if (this.options.taskList !== false) {
1087
+ extensions.push(TaskList.configure(this.options.taskList));
1088
+ }
1089
+ return extensions;
1090
+ }
1091
+ });
1092
+ export {
1093
+ BulletList,
1094
+ ListItem,
1095
+ ListKeymap,
1096
+ ListKit,
1097
+ OrderedList,
1098
+ TaskItem,
1099
+ TaskList,
1100
+ bulletListInputRegex,
1101
+ inputRegex,
1102
+ listHelpers_exports as listHelpers,
1103
+ orderedListInputRegex
1104
+ };
1105
+ //# sourceMappingURL=index.js.map