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