@tiptap/extension-list 3.0.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +18 -0
  2. package/dist/bullet-list/index.cjs +93 -0
  3. package/dist/bullet-list/index.cjs.map +1 -0
  4. package/dist/bullet-list/index.d.cts +51 -0
  5. package/dist/bullet-list/index.d.ts +51 -0
  6. package/dist/bullet-list/index.js +65 -0
  7. package/dist/bullet-list/index.js.map +1 -0
  8. package/dist/index.cjs +714 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +288 -0
  11. package/dist/index.d.ts +288 -0
  12. package/dist/index.js +683 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/item/index.cjs +62 -0
  15. package/dist/item/index.cjs.map +1 -0
  16. package/dist/item/index.d.cts +29 -0
  17. package/dist/item/index.d.ts +29 -0
  18. package/dist/item/index.js +35 -0
  19. package/dist/item/index.js.map +1 -0
  20. package/dist/keymap/index.cjs +308 -0
  21. package/dist/keymap/index.cjs.map +1 -0
  22. package/dist/keymap/index.d.cts +63 -0
  23. package/dist/keymap/index.d.ts +63 -0
  24. package/dist/keymap/index.js +286 -0
  25. package/dist/keymap/index.js.map +1 -0
  26. package/dist/kit/index.cjs +692 -0
  27. package/dist/kit/index.cjs.map +1 -0
  28. package/dist/kit/index.d.cts +200 -0
  29. package/dist/kit/index.d.ts +200 -0
  30. package/dist/kit/index.js +673 -0
  31. package/dist/kit/index.js.map +1 -0
  32. package/dist/ordered-list/index.cjs +113 -0
  33. package/dist/ordered-list/index.cjs.map +1 -0
  34. package/dist/ordered-list/index.d.cts +52 -0
  35. package/dist/ordered-list/index.d.ts +52 -0
  36. package/dist/ordered-list/index.js +85 -0
  37. package/dist/ordered-list/index.js.map +1 -0
  38. package/dist/task-item/index.cjs +177 -0
  39. package/dist/task-item/index.cjs.map +1 -0
  40. package/dist/task-item/index.d.cts +41 -0
  41. package/dist/task-item/index.d.ts +41 -0
  42. package/dist/task-item/index.js +149 -0
  43. package/dist/task-item/index.js.map +1 -0
  44. package/dist/task-list/index.cjs +69 -0
  45. package/dist/task-list/index.cjs.map +1 -0
  46. package/dist/task-list/index.d.cts +34 -0
  47. package/dist/task-list/index.d.ts +34 -0
  48. package/dist/task-list/index.js +42 -0
  49. package/dist/task-list/index.js.map +1 -0
  50. package/package.json +109 -0
  51. package/src/bullet-list/bullet-list.ts +126 -0
  52. package/src/bullet-list/index.ts +1 -0
  53. package/src/index.ts +7 -0
  54. package/src/item/index.ts +1 -0
  55. package/src/item/list-item.ts +64 -0
  56. package/src/keymap/index.ts +2 -0
  57. package/src/keymap/list-keymap.ts +106 -0
  58. package/src/keymap/listHelpers/findListItemPos.ts +30 -0
  59. package/src/keymap/listHelpers/getNextListDepth.ts +16 -0
  60. package/src/keymap/listHelpers/handleBackspace.ts +84 -0
  61. package/src/keymap/listHelpers/handleDelete.ts +43 -0
  62. package/src/keymap/listHelpers/hasListBefore.ts +15 -0
  63. package/src/keymap/listHelpers/hasListItemAfter.ts +17 -0
  64. package/src/keymap/listHelpers/hasListItemBefore.ts +17 -0
  65. package/src/keymap/listHelpers/index.ts +10 -0
  66. package/src/keymap/listHelpers/listItemHasSubList.ts +21 -0
  67. package/src/keymap/listHelpers/nextListIsDeeper.ts +19 -0
  68. package/src/keymap/listHelpers/nextListIsHigher.ts +19 -0
  69. package/src/kit/index.ts +75 -0
  70. package/src/ordered-list/index.ts +1 -0
  71. package/src/ordered-list/ordered-list.ts +151 -0
  72. package/src/task-item/index.ts +1 -0
  73. package/src/task-item/task-item.ts +219 -0
  74. package/src/task-list/index.ts +1 -0
  75. package/src/task-list/task-list.ts +79 -0
@@ -0,0 +1,692 @@
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
+ addCommands() {
54
+ return {
55
+ toggleBulletList: () => ({ commands, chain }) => {
56
+ if (this.options.keepAttributes) {
57
+ return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
58
+ }
59
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
60
+ }
61
+ };
62
+ },
63
+ addKeyboardShortcuts() {
64
+ return {
65
+ "Mod-Shift-8": () => this.editor.commands.toggleBulletList()
66
+ };
67
+ },
68
+ addInputRules() {
69
+ let inputRule = (0, import_core.wrappingInputRule)({
70
+ find: bulletListInputRegex,
71
+ type: this.type
72
+ });
73
+ if (this.options.keepMarks || this.options.keepAttributes) {
74
+ inputRule = (0, import_core.wrappingInputRule)({
75
+ find: bulletListInputRegex,
76
+ type: this.type,
77
+ keepMarks: this.options.keepMarks,
78
+ keepAttributes: this.options.keepAttributes,
79
+ getAttributes: () => {
80
+ return this.editor.getAttributes(TextStyleName);
81
+ },
82
+ editor: this.editor
83
+ });
84
+ }
85
+ return [inputRule];
86
+ }
87
+ });
88
+
89
+ // src/item/list-item.ts
90
+ var import_core2 = require("@tiptap/core");
91
+ var ListItem = import_core2.Node.create({
92
+ name: "listItem",
93
+ addOptions() {
94
+ return {
95
+ HTMLAttributes: {},
96
+ bulletListTypeName: "bulletList",
97
+ orderedListTypeName: "orderedList"
98
+ };
99
+ },
100
+ content: "paragraph block*",
101
+ defining: true,
102
+ parseHTML() {
103
+ return [
104
+ {
105
+ tag: "li"
106
+ }
107
+ ];
108
+ },
109
+ renderHTML({ HTMLAttributes }) {
110
+ return ["li", (0, import_core2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
111
+ },
112
+ addKeyboardShortcuts() {
113
+ return {
114
+ Enter: () => this.editor.commands.splitListItem(this.name),
115
+ Tab: () => this.editor.commands.sinkListItem(this.name),
116
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
117
+ };
118
+ }
119
+ });
120
+
121
+ // src/keymap/list-keymap.ts
122
+ var import_core8 = require("@tiptap/core");
123
+
124
+ // src/keymap/listHelpers/index.ts
125
+ var listHelpers_exports = {};
126
+ __export(listHelpers_exports, {
127
+ findListItemPos: () => findListItemPos,
128
+ getNextListDepth: () => getNextListDepth,
129
+ handleBackspace: () => handleBackspace,
130
+ handleDelete: () => handleDelete,
131
+ hasListBefore: () => hasListBefore,
132
+ hasListItemAfter: () => hasListItemAfter,
133
+ hasListItemBefore: () => hasListItemBefore,
134
+ listItemHasSubList: () => listItemHasSubList,
135
+ nextListIsDeeper: () => nextListIsDeeper,
136
+ nextListIsHigher: () => nextListIsHigher
137
+ });
138
+
139
+ // src/keymap/listHelpers/findListItemPos.ts
140
+ var import_core3 = require("@tiptap/core");
141
+ var findListItemPos = (typeOrName, state) => {
142
+ const { $from } = state.selection;
143
+ const nodeType = (0, import_core3.getNodeType)(typeOrName, state.schema);
144
+ let currentNode = null;
145
+ let currentDepth = $from.depth;
146
+ let currentPos = $from.pos;
147
+ let targetDepth = null;
148
+ while (currentDepth > 0 && targetDepth === null) {
149
+ currentNode = $from.node(currentDepth);
150
+ if (currentNode.type === nodeType) {
151
+ targetDepth = currentDepth;
152
+ } else {
153
+ currentDepth -= 1;
154
+ currentPos -= 1;
155
+ }
156
+ }
157
+ if (targetDepth === null) {
158
+ return null;
159
+ }
160
+ return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
161
+ };
162
+
163
+ // src/keymap/listHelpers/getNextListDepth.ts
164
+ var import_core4 = require("@tiptap/core");
165
+ var getNextListDepth = (typeOrName, state) => {
166
+ const listItemPos = findListItemPos(typeOrName, state);
167
+ if (!listItemPos) {
168
+ return false;
169
+ }
170
+ const [, depth] = (0, import_core4.getNodeAtPosition)(state, typeOrName, listItemPos.$pos.pos + 4);
171
+ return depth;
172
+ };
173
+
174
+ // src/keymap/listHelpers/handleBackspace.ts
175
+ var import_core6 = require("@tiptap/core");
176
+
177
+ // src/keymap/listHelpers/hasListBefore.ts
178
+ var hasListBefore = (editorState, name, parentListTypes) => {
179
+ const { $anchor } = editorState.selection;
180
+ const previousNodePos = Math.max(0, $anchor.pos - 2);
181
+ const previousNode = editorState.doc.resolve(previousNodePos).node();
182
+ if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
183
+ return false;
184
+ }
185
+ return true;
186
+ };
187
+
188
+ // src/keymap/listHelpers/hasListItemBefore.ts
189
+ var hasListItemBefore = (typeOrName, state) => {
190
+ var _a;
191
+ const { $anchor } = state.selection;
192
+ const $targetPos = state.doc.resolve($anchor.pos - 2);
193
+ if ($targetPos.index() === 0) {
194
+ return false;
195
+ }
196
+ if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
197
+ return false;
198
+ }
199
+ return true;
200
+ };
201
+
202
+ // src/keymap/listHelpers/listItemHasSubList.ts
203
+ var import_core5 = require("@tiptap/core");
204
+ var listItemHasSubList = (typeOrName, state, node) => {
205
+ if (!node) {
206
+ return false;
207
+ }
208
+ const nodeType = (0, import_core5.getNodeType)(typeOrName, state.schema);
209
+ let hasSubList = false;
210
+ node.descendants((child) => {
211
+ if (child.type === nodeType) {
212
+ hasSubList = true;
213
+ }
214
+ });
215
+ return hasSubList;
216
+ };
217
+
218
+ // src/keymap/listHelpers/handleBackspace.ts
219
+ var handleBackspace = (editor, name, parentListTypes) => {
220
+ if (editor.commands.undoInputRule()) {
221
+ return true;
222
+ }
223
+ if (editor.state.selection.from !== editor.state.selection.to) {
224
+ return false;
225
+ }
226
+ if (!(0, import_core6.isNodeActive)(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
227
+ const { $anchor } = editor.state.selection;
228
+ const $listPos = editor.state.doc.resolve($anchor.before() - 1);
229
+ const listDescendants = [];
230
+ $listPos.node().descendants((node, pos) => {
231
+ if (node.type.name === name) {
232
+ listDescendants.push({ node, pos });
233
+ }
234
+ });
235
+ const lastItem = listDescendants.at(-1);
236
+ if (!lastItem) {
237
+ return false;
238
+ }
239
+ const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
240
+ return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
241
+ }
242
+ if (!(0, import_core6.isNodeActive)(editor.state, name)) {
243
+ return false;
244
+ }
245
+ if (!(0, import_core6.isAtStartOfNode)(editor.state)) {
246
+ return false;
247
+ }
248
+ const listItemPos = findListItemPos(name, editor.state);
249
+ if (!listItemPos) {
250
+ return false;
251
+ }
252
+ const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
253
+ const prevNode = $prev.node(listItemPos.depth);
254
+ const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
255
+ if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
256
+ return editor.commands.joinItemBackward();
257
+ }
258
+ return editor.chain().liftListItem(name).run();
259
+ };
260
+
261
+ // src/keymap/listHelpers/handleDelete.ts
262
+ var import_core7 = require("@tiptap/core");
263
+
264
+ // src/keymap/listHelpers/nextListIsDeeper.ts
265
+ var nextListIsDeeper = (typeOrName, state) => {
266
+ const listDepth = getNextListDepth(typeOrName, state);
267
+ const listItemPos = findListItemPos(typeOrName, state);
268
+ if (!listItemPos || !listDepth) {
269
+ return false;
270
+ }
271
+ if (listDepth > listItemPos.depth) {
272
+ return true;
273
+ }
274
+ return false;
275
+ };
276
+
277
+ // src/keymap/listHelpers/nextListIsHigher.ts
278
+ var nextListIsHigher = (typeOrName, state) => {
279
+ const listDepth = getNextListDepth(typeOrName, state);
280
+ const listItemPos = findListItemPos(typeOrName, state);
281
+ if (!listItemPos || !listDepth) {
282
+ return false;
283
+ }
284
+ if (listDepth < listItemPos.depth) {
285
+ return true;
286
+ }
287
+ return false;
288
+ };
289
+
290
+ // src/keymap/listHelpers/handleDelete.ts
291
+ var handleDelete = (editor, name) => {
292
+ if (!(0, import_core7.isNodeActive)(editor.state, name)) {
293
+ return false;
294
+ }
295
+ if (!(0, import_core7.isAtEndOfNode)(editor.state, name)) {
296
+ return false;
297
+ }
298
+ const { selection } = editor.state;
299
+ const { $from, $to } = selection;
300
+ if (!selection.empty && $from.sameParent($to)) {
301
+ return false;
302
+ }
303
+ if (nextListIsDeeper(name, editor.state)) {
304
+ return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
305
+ }
306
+ if (nextListIsHigher(name, editor.state)) {
307
+ return editor.chain().joinForward().joinBackward().run();
308
+ }
309
+ return editor.commands.joinItemForward();
310
+ };
311
+
312
+ // src/keymap/listHelpers/hasListItemAfter.ts
313
+ var hasListItemAfter = (typeOrName, state) => {
314
+ var _a;
315
+ const { $anchor } = state.selection;
316
+ const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
317
+ if ($targetPos.index() === $targetPos.parent.childCount - 1) {
318
+ return false;
319
+ }
320
+ if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) {
321
+ return false;
322
+ }
323
+ return true;
324
+ };
325
+
326
+ // src/keymap/list-keymap.ts
327
+ var ListKeymap = import_core8.Extension.create({
328
+ name: "listKeymap",
329
+ addOptions() {
330
+ return {
331
+ listTypes: [
332
+ {
333
+ itemName: "listItem",
334
+ wrapperNames: ["bulletList", "orderedList"]
335
+ },
336
+ {
337
+ itemName: "taskItem",
338
+ wrapperNames: ["taskList"]
339
+ }
340
+ ]
341
+ };
342
+ },
343
+ addKeyboardShortcuts() {
344
+ return {
345
+ Delete: ({ editor }) => {
346
+ let handled = false;
347
+ this.options.listTypes.forEach(({ itemName }) => {
348
+ if (editor.state.schema.nodes[itemName] === void 0) {
349
+ return;
350
+ }
351
+ if (handleDelete(editor, itemName)) {
352
+ handled = true;
353
+ }
354
+ });
355
+ return handled;
356
+ },
357
+ "Mod-Delete": ({ editor }) => {
358
+ let handled = false;
359
+ this.options.listTypes.forEach(({ itemName }) => {
360
+ if (editor.state.schema.nodes[itemName] === void 0) {
361
+ return;
362
+ }
363
+ if (handleDelete(editor, itemName)) {
364
+ handled = true;
365
+ }
366
+ });
367
+ return handled;
368
+ },
369
+ Backspace: ({ editor }) => {
370
+ let handled = false;
371
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
372
+ if (editor.state.schema.nodes[itemName] === void 0) {
373
+ return;
374
+ }
375
+ if (handleBackspace(editor, itemName, wrapperNames)) {
376
+ handled = true;
377
+ }
378
+ });
379
+ return handled;
380
+ },
381
+ "Mod-Backspace": ({ editor }) => {
382
+ let handled = false;
383
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
384
+ if (editor.state.schema.nodes[itemName] === void 0) {
385
+ return;
386
+ }
387
+ if (handleBackspace(editor, itemName, wrapperNames)) {
388
+ handled = true;
389
+ }
390
+ });
391
+ return handled;
392
+ }
393
+ };
394
+ }
395
+ });
396
+
397
+ // src/ordered-list/ordered-list.ts
398
+ var import_core9 = require("@tiptap/core");
399
+ var ListItemName2 = "listItem";
400
+ var TextStyleName2 = "textStyle";
401
+ var orderedListInputRegex = /^(\d+)\.\s$/;
402
+ var OrderedList = import_core9.Node.create({
403
+ name: "orderedList",
404
+ addOptions() {
405
+ return {
406
+ itemTypeName: "listItem",
407
+ HTMLAttributes: {},
408
+ keepMarks: false,
409
+ keepAttributes: false
410
+ };
411
+ },
412
+ group: "block list",
413
+ content() {
414
+ return `${this.options.itemTypeName}+`;
415
+ },
416
+ addAttributes() {
417
+ return {
418
+ start: {
419
+ default: 1,
420
+ parseHTML: (element) => {
421
+ return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1;
422
+ }
423
+ },
424
+ type: {
425
+ default: void 0,
426
+ parseHTML: (element) => element.getAttribute("type")
427
+ }
428
+ };
429
+ },
430
+ parseHTML() {
431
+ return [
432
+ {
433
+ tag: "ol"
434
+ }
435
+ ];
436
+ },
437
+ renderHTML({ HTMLAttributes }) {
438
+ const { start, ...attributesWithoutStart } = HTMLAttributes;
439
+ return start === 1 ? ["ol", (0, import_core9.mergeAttributes)(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", (0, import_core9.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
440
+ },
441
+ addCommands() {
442
+ return {
443
+ toggleOrderedList: () => ({ commands, chain }) => {
444
+ if (this.options.keepAttributes) {
445
+ return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName2, this.editor.getAttributes(TextStyleName2)).run();
446
+ }
447
+ return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
448
+ }
449
+ };
450
+ },
451
+ addKeyboardShortcuts() {
452
+ return {
453
+ "Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
454
+ };
455
+ },
456
+ addInputRules() {
457
+ let inputRule = (0, import_core9.wrappingInputRule)({
458
+ find: orderedListInputRegex,
459
+ type: this.type,
460
+ getAttributes: (match) => ({ start: +match[1] }),
461
+ joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1]
462
+ });
463
+ if (this.options.keepMarks || this.options.keepAttributes) {
464
+ inputRule = (0, import_core9.wrappingInputRule)({
465
+ find: orderedListInputRegex,
466
+ type: this.type,
467
+ keepMarks: this.options.keepMarks,
468
+ keepAttributes: this.options.keepAttributes,
469
+ getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName2) }),
470
+ joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
471
+ editor: this.editor
472
+ });
473
+ }
474
+ return [inputRule];
475
+ }
476
+ });
477
+
478
+ // src/task-item/task-item.ts
479
+ var import_core10 = require("@tiptap/core");
480
+ var inputRegex = /^\s*(\[([( |x])?\])\s$/;
481
+ var TaskItem = import_core10.Node.create({
482
+ name: "taskItem",
483
+ addOptions() {
484
+ return {
485
+ nested: false,
486
+ HTMLAttributes: {},
487
+ taskListTypeName: "taskList"
488
+ };
489
+ },
490
+ content() {
491
+ return this.options.nested ? "paragraph block*" : "paragraph+";
492
+ },
493
+ defining: true,
494
+ addAttributes() {
495
+ return {
496
+ checked: {
497
+ default: false,
498
+ keepOnSplit: false,
499
+ parseHTML: (element) => {
500
+ const dataChecked = element.getAttribute("data-checked");
501
+ return dataChecked === "" || dataChecked === "true";
502
+ },
503
+ renderHTML: (attributes) => ({
504
+ "data-checked": attributes.checked
505
+ })
506
+ }
507
+ };
508
+ },
509
+ parseHTML() {
510
+ return [
511
+ {
512
+ tag: `li[data-type="${this.name}"]`,
513
+ priority: 51
514
+ }
515
+ ];
516
+ },
517
+ renderHTML({ node, HTMLAttributes }) {
518
+ return [
519
+ "li",
520
+ (0, import_core10.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
521
+ "data-type": this.name
522
+ }),
523
+ [
524
+ "label",
525
+ [
526
+ "input",
527
+ {
528
+ type: "checkbox",
529
+ checked: node.attrs.checked ? "checked" : null
530
+ }
531
+ ],
532
+ ["span"]
533
+ ],
534
+ ["div", 0]
535
+ ];
536
+ },
537
+ addKeyboardShortcuts() {
538
+ const shortcuts = {
539
+ Enter: () => this.editor.commands.splitListItem(this.name),
540
+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name)
541
+ };
542
+ if (!this.options.nested) {
543
+ return shortcuts;
544
+ }
545
+ return {
546
+ ...shortcuts,
547
+ Tab: () => this.editor.commands.sinkListItem(this.name)
548
+ };
549
+ },
550
+ addNodeView() {
551
+ return ({ node, HTMLAttributes, getPos, editor }) => {
552
+ const listItem = document.createElement("li");
553
+ const checkboxWrapper = document.createElement("label");
554
+ const checkboxStyler = document.createElement("span");
555
+ const checkbox = document.createElement("input");
556
+ const content = document.createElement("div");
557
+ checkboxWrapper.contentEditable = "false";
558
+ checkbox.type = "checkbox";
559
+ checkbox.addEventListener("mousedown", (event) => event.preventDefault());
560
+ checkbox.addEventListener("change", (event) => {
561
+ if (!editor.isEditable && !this.options.onReadOnlyChecked) {
562
+ checkbox.checked = !checkbox.checked;
563
+ return;
564
+ }
565
+ const { checked } = event.target;
566
+ if (editor.isEditable && typeof getPos === "function") {
567
+ editor.chain().focus(void 0, { scrollIntoView: false }).command(({ tr }) => {
568
+ const position = getPos();
569
+ if (typeof position !== "number") {
570
+ return false;
571
+ }
572
+ const currentNode = tr.doc.nodeAt(position);
573
+ tr.setNodeMarkup(position, void 0, {
574
+ ...currentNode == null ? void 0 : currentNode.attrs,
575
+ checked
576
+ });
577
+ return true;
578
+ }).run();
579
+ }
580
+ if (!editor.isEditable && this.options.onReadOnlyChecked) {
581
+ if (!this.options.onReadOnlyChecked(node, checked)) {
582
+ checkbox.checked = !checkbox.checked;
583
+ }
584
+ }
585
+ });
586
+ Object.entries(this.options.HTMLAttributes).forEach(([key, value]) => {
587
+ listItem.setAttribute(key, value);
588
+ });
589
+ listItem.dataset.checked = node.attrs.checked;
590
+ checkbox.checked = node.attrs.checked;
591
+ checkboxWrapper.append(checkbox, checkboxStyler);
592
+ listItem.append(checkboxWrapper, content);
593
+ Object.entries(HTMLAttributes).forEach(([key, value]) => {
594
+ listItem.setAttribute(key, value);
595
+ });
596
+ return {
597
+ dom: listItem,
598
+ contentDOM: content,
599
+ update: (updatedNode) => {
600
+ if (updatedNode.type !== this.type) {
601
+ return false;
602
+ }
603
+ listItem.dataset.checked = updatedNode.attrs.checked;
604
+ checkbox.checked = updatedNode.attrs.checked;
605
+ return true;
606
+ }
607
+ };
608
+ };
609
+ },
610
+ addInputRules() {
611
+ return [
612
+ (0, import_core10.wrappingInputRule)({
613
+ find: inputRegex,
614
+ type: this.type,
615
+ getAttributes: (match) => ({
616
+ checked: match[match.length - 1] === "x"
617
+ })
618
+ })
619
+ ];
620
+ }
621
+ });
622
+
623
+ // src/task-list/task-list.ts
624
+ var import_core11 = require("@tiptap/core");
625
+ var TaskList = import_core11.Node.create({
626
+ name: "taskList",
627
+ addOptions() {
628
+ return {
629
+ itemTypeName: "taskItem",
630
+ HTMLAttributes: {}
631
+ };
632
+ },
633
+ group: "block list",
634
+ content() {
635
+ return `${this.options.itemTypeName}+`;
636
+ },
637
+ parseHTML() {
638
+ return [
639
+ {
640
+ tag: `ul[data-type="${this.name}"]`,
641
+ priority: 51
642
+ }
643
+ ];
644
+ },
645
+ renderHTML({ HTMLAttributes }) {
646
+ return ["ul", (0, import_core11.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, { "data-type": this.name }), 0];
647
+ },
648
+ addCommands() {
649
+ return {
650
+ toggleTaskList: () => ({ commands }) => {
651
+ return commands.toggleList(this.name, this.options.itemTypeName);
652
+ }
653
+ };
654
+ },
655
+ addKeyboardShortcuts() {
656
+ return {
657
+ "Mod-Shift-9": () => this.editor.commands.toggleTaskList()
658
+ };
659
+ }
660
+ });
661
+
662
+ // src/kit/index.ts
663
+ var ListKit = import_core12.Extension.create({
664
+ name: "listKit",
665
+ addExtensions() {
666
+ const extensions = [];
667
+ if (this.options.bulletList !== false) {
668
+ extensions.push(BulletList.configure(this.options.bulletList));
669
+ }
670
+ if (this.options.listItem !== false) {
671
+ extensions.push(ListItem.configure(this.options.listItem));
672
+ }
673
+ if (this.options.listKeymap !== false) {
674
+ extensions.push(ListKeymap.configure(this.options.listKeymap));
675
+ }
676
+ if (this.options.orderedList !== false) {
677
+ extensions.push(OrderedList.configure(this.options.orderedList));
678
+ }
679
+ if (this.options.taskItem !== false) {
680
+ extensions.push(TaskItem.configure(this.options.taskItem));
681
+ }
682
+ if (this.options.taskList !== false) {
683
+ extensions.push(TaskList.configure(this.options.taskList));
684
+ }
685
+ return extensions;
686
+ }
687
+ });
688
+ // Annotate the CommonJS export names for ESM import in node:
689
+ 0 && (module.exports = {
690
+ ListKit
691
+ });
692
+ //# sourceMappingURL=index.cjs.map