@tiptap/extension-list 3.0.0-beta.0

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