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