@tiptap/extension-list 3.20.1 → 3.20.3

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