@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,63 @@
1
+ import { Extension, Editor } from '@tiptap/core';
2
+ import * as _tiptap_pm_model from '@tiptap/pm/model';
3
+ import { NodeType, Node } from '@tiptap/pm/model';
4
+ import { EditorState } from '@tiptap/pm/state';
5
+
6
+ type ListKeymapOptions = {
7
+ /**
8
+ * An array of list types. This is used for item and wrapper list matching.
9
+ * @default []
10
+ * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]
11
+ */
12
+ listTypes: Array<{
13
+ itemName: string;
14
+ wrapperNames: string[];
15
+ }>;
16
+ };
17
+ /**
18
+ * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.
19
+ * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into
20
+ * the adjacent or previous list item. This extension will prevent this behaviour and instead will
21
+ * try to join paragraphs from two list items into a single list item.
22
+ * @see https://www.tiptap.dev/api/extensions/list-keymap
23
+ */
24
+ declare const ListKeymap: Extension<ListKeymapOptions, any>;
25
+
26
+ declare const findListItemPos: (typeOrName: string | NodeType, state: EditorState) => {
27
+ $pos: _tiptap_pm_model.ResolvedPos;
28
+ depth: number;
29
+ } | null;
30
+
31
+ declare const getNextListDepth: (typeOrName: string, state: EditorState) => number | false;
32
+
33
+ declare const handleBackspace: (editor: Editor, name: string, parentListTypes: string[]) => boolean;
34
+
35
+ declare const handleDelete: (editor: Editor, name: string) => boolean;
36
+
37
+ declare const hasListBefore: (editorState: EditorState, name: string, parentListTypes: string[]) => boolean;
38
+
39
+ declare const hasListItemAfter: (typeOrName: string, state: EditorState) => boolean;
40
+
41
+ declare const hasListItemBefore: (typeOrName: string, state: EditorState) => boolean;
42
+
43
+ declare const listItemHasSubList: (typeOrName: string, state: EditorState, node?: Node) => boolean;
44
+
45
+ declare const nextListIsDeeper: (typeOrName: string, state: EditorState) => boolean;
46
+
47
+ declare const nextListIsHigher: (typeOrName: string, state: EditorState) => boolean;
48
+
49
+ declare const index_findListItemPos: typeof findListItemPos;
50
+ declare const index_getNextListDepth: typeof getNextListDepth;
51
+ declare const index_handleBackspace: typeof handleBackspace;
52
+ declare const index_handleDelete: typeof handleDelete;
53
+ declare const index_hasListBefore: typeof hasListBefore;
54
+ declare const index_hasListItemAfter: typeof hasListItemAfter;
55
+ declare const index_hasListItemBefore: typeof hasListItemBefore;
56
+ declare const index_listItemHasSubList: typeof listItemHasSubList;
57
+ declare const index_nextListIsDeeper: typeof nextListIsDeeper;
58
+ declare const index_nextListIsHigher: typeof nextListIsHigher;
59
+ declare namespace index {
60
+ export { index_findListItemPos as findListItemPos, index_getNextListDepth as getNextListDepth, index_handleBackspace as handleBackspace, index_handleDelete as handleDelete, index_hasListBefore as hasListBefore, index_hasListItemAfter as hasListItemAfter, index_hasListItemBefore as hasListItemBefore, index_listItemHasSubList as listItemHasSubList, index_nextListIsDeeper as nextListIsDeeper, index_nextListIsHigher as nextListIsHigher };
61
+ }
62
+
63
+ export { ListKeymap, type ListKeymapOptions, index as listHelpers };
@@ -0,0 +1,63 @@
1
+ import { Extension, Editor } from '@tiptap/core';
2
+ import * as _tiptap_pm_model from '@tiptap/pm/model';
3
+ import { NodeType, Node } from '@tiptap/pm/model';
4
+ import { EditorState } from '@tiptap/pm/state';
5
+
6
+ type ListKeymapOptions = {
7
+ /**
8
+ * An array of list types. This is used for item and wrapper list matching.
9
+ * @default []
10
+ * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]
11
+ */
12
+ listTypes: Array<{
13
+ itemName: string;
14
+ wrapperNames: string[];
15
+ }>;
16
+ };
17
+ /**
18
+ * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.
19
+ * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into
20
+ * the adjacent or previous list item. This extension will prevent this behaviour and instead will
21
+ * try to join paragraphs from two list items into a single list item.
22
+ * @see https://www.tiptap.dev/api/extensions/list-keymap
23
+ */
24
+ declare const ListKeymap: Extension<ListKeymapOptions, any>;
25
+
26
+ declare const findListItemPos: (typeOrName: string | NodeType, state: EditorState) => {
27
+ $pos: _tiptap_pm_model.ResolvedPos;
28
+ depth: number;
29
+ } | null;
30
+
31
+ declare const getNextListDepth: (typeOrName: string, state: EditorState) => number | false;
32
+
33
+ declare const handleBackspace: (editor: Editor, name: string, parentListTypes: string[]) => boolean;
34
+
35
+ declare const handleDelete: (editor: Editor, name: string) => boolean;
36
+
37
+ declare const hasListBefore: (editorState: EditorState, name: string, parentListTypes: string[]) => boolean;
38
+
39
+ declare const hasListItemAfter: (typeOrName: string, state: EditorState) => boolean;
40
+
41
+ declare const hasListItemBefore: (typeOrName: string, state: EditorState) => boolean;
42
+
43
+ declare const listItemHasSubList: (typeOrName: string, state: EditorState, node?: Node) => boolean;
44
+
45
+ declare const nextListIsDeeper: (typeOrName: string, state: EditorState) => boolean;
46
+
47
+ declare const nextListIsHigher: (typeOrName: string, state: EditorState) => boolean;
48
+
49
+ declare const index_findListItemPos: typeof findListItemPos;
50
+ declare const index_getNextListDepth: typeof getNextListDepth;
51
+ declare const index_handleBackspace: typeof handleBackspace;
52
+ declare const index_handleDelete: typeof handleDelete;
53
+ declare const index_hasListBefore: typeof hasListBefore;
54
+ declare const index_hasListItemAfter: typeof hasListItemAfter;
55
+ declare const index_hasListItemBefore: typeof hasListItemBefore;
56
+ declare const index_listItemHasSubList: typeof listItemHasSubList;
57
+ declare const index_nextListIsDeeper: typeof nextListIsDeeper;
58
+ declare const index_nextListIsHigher: typeof nextListIsHigher;
59
+ declare namespace index {
60
+ export { index_findListItemPos as findListItemPos, index_getNextListDepth as getNextListDepth, index_handleBackspace as handleBackspace, index_handleDelete as handleDelete, index_hasListBefore as hasListBefore, index_hasListItemAfter as hasListItemAfter, index_hasListItemBefore as hasListItemBefore, index_listItemHasSubList as listItemHasSubList, index_nextListIsDeeper as nextListIsDeeper, index_nextListIsHigher as nextListIsHigher };
61
+ }
62
+
63
+ export { ListKeymap, type ListKeymapOptions, index as listHelpers };
@@ -0,0 +1,286 @@
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/keymap/list-keymap.ts
8
+ import { Extension } from "@tiptap/core";
9
+
10
+ // src/keymap/listHelpers/index.ts
11
+ var listHelpers_exports = {};
12
+ __export(listHelpers_exports, {
13
+ findListItemPos: () => findListItemPos,
14
+ getNextListDepth: () => getNextListDepth,
15
+ handleBackspace: () => handleBackspace,
16
+ handleDelete: () => handleDelete,
17
+ hasListBefore: () => hasListBefore,
18
+ hasListItemAfter: () => hasListItemAfter,
19
+ hasListItemBefore: () => hasListItemBefore,
20
+ listItemHasSubList: () => listItemHasSubList,
21
+ nextListIsDeeper: () => nextListIsDeeper,
22
+ nextListIsHigher: () => nextListIsHigher
23
+ });
24
+
25
+ // src/keymap/listHelpers/findListItemPos.ts
26
+ import { getNodeType } from "@tiptap/core";
27
+ var findListItemPos = (typeOrName, state) => {
28
+ const { $from } = state.selection;
29
+ const nodeType = getNodeType(typeOrName, state.schema);
30
+ let currentNode = null;
31
+ let currentDepth = $from.depth;
32
+ let currentPos = $from.pos;
33
+ let targetDepth = null;
34
+ while (currentDepth > 0 && targetDepth === null) {
35
+ currentNode = $from.node(currentDepth);
36
+ if (currentNode.type === nodeType) {
37
+ targetDepth = currentDepth;
38
+ } else {
39
+ currentDepth -= 1;
40
+ currentPos -= 1;
41
+ }
42
+ }
43
+ if (targetDepth === null) {
44
+ return null;
45
+ }
46
+ return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
47
+ };
48
+
49
+ // src/keymap/listHelpers/getNextListDepth.ts
50
+ import { getNodeAtPosition } from "@tiptap/core";
51
+ var getNextListDepth = (typeOrName, state) => {
52
+ const listItemPos = findListItemPos(typeOrName, state);
53
+ if (!listItemPos) {
54
+ return false;
55
+ }
56
+ const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
57
+ return depth;
58
+ };
59
+
60
+ // src/keymap/listHelpers/handleBackspace.ts
61
+ import { isAtStartOfNode, isNodeActive } from "@tiptap/core";
62
+
63
+ // src/keymap/listHelpers/hasListBefore.ts
64
+ var hasListBefore = (editorState, name, parentListTypes) => {
65
+ const { $anchor } = editorState.selection;
66
+ const previousNodePos = Math.max(0, $anchor.pos - 2);
67
+ const previousNode = editorState.doc.resolve(previousNodePos).node();
68
+ if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
69
+ return false;
70
+ }
71
+ return true;
72
+ };
73
+
74
+ // src/keymap/listHelpers/hasListItemBefore.ts
75
+ var hasListItemBefore = (typeOrName, state) => {
76
+ var _a;
77
+ const { $anchor } = state.selection;
78
+ const $targetPos = state.doc.resolve($anchor.pos - 2);
79
+ if ($targetPos.index() === 0) {
80
+ return false;
81
+ }
82
+ if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
83
+ return false;
84
+ }
85
+ return true;
86
+ };
87
+
88
+ // src/keymap/listHelpers/listItemHasSubList.ts
89
+ import { getNodeType as getNodeType2 } from "@tiptap/core";
90
+ var listItemHasSubList = (typeOrName, state, node) => {
91
+ if (!node) {
92
+ return false;
93
+ }
94
+ const nodeType = getNodeType2(typeOrName, state.schema);
95
+ let hasSubList = false;
96
+ node.descendants((child) => {
97
+ if (child.type === nodeType) {
98
+ hasSubList = true;
99
+ }
100
+ });
101
+ return hasSubList;
102
+ };
103
+
104
+ // src/keymap/listHelpers/handleBackspace.ts
105
+ var handleBackspace = (editor, name, parentListTypes) => {
106
+ if (editor.commands.undoInputRule()) {
107
+ return true;
108
+ }
109
+ if (editor.state.selection.from !== editor.state.selection.to) {
110
+ return false;
111
+ }
112
+ if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
113
+ const { $anchor } = editor.state.selection;
114
+ const $listPos = editor.state.doc.resolve($anchor.before() - 1);
115
+ const listDescendants = [];
116
+ $listPos.node().descendants((node, pos) => {
117
+ if (node.type.name === name) {
118
+ listDescendants.push({ node, pos });
119
+ }
120
+ });
121
+ const lastItem = listDescendants.at(-1);
122
+ if (!lastItem) {
123
+ return false;
124
+ }
125
+ const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
126
+ return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
127
+ }
128
+ if (!isNodeActive(editor.state, name)) {
129
+ return false;
130
+ }
131
+ if (!isAtStartOfNode(editor.state)) {
132
+ return false;
133
+ }
134
+ const listItemPos = findListItemPos(name, editor.state);
135
+ if (!listItemPos) {
136
+ return false;
137
+ }
138
+ const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
139
+ const prevNode = $prev.node(listItemPos.depth);
140
+ const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
141
+ if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
142
+ return editor.commands.joinItemBackward();
143
+ }
144
+ return editor.chain().liftListItem(name).run();
145
+ };
146
+
147
+ // src/keymap/listHelpers/handleDelete.ts
148
+ import { isAtEndOfNode, isNodeActive as isNodeActive2 } from "@tiptap/core";
149
+
150
+ // src/keymap/listHelpers/nextListIsDeeper.ts
151
+ var nextListIsDeeper = (typeOrName, state) => {
152
+ const listDepth = getNextListDepth(typeOrName, state);
153
+ const listItemPos = findListItemPos(typeOrName, state);
154
+ if (!listItemPos || !listDepth) {
155
+ return false;
156
+ }
157
+ if (listDepth > listItemPos.depth) {
158
+ return true;
159
+ }
160
+ return false;
161
+ };
162
+
163
+ // src/keymap/listHelpers/nextListIsHigher.ts
164
+ var nextListIsHigher = (typeOrName, state) => {
165
+ const listDepth = getNextListDepth(typeOrName, state);
166
+ const listItemPos = findListItemPos(typeOrName, state);
167
+ if (!listItemPos || !listDepth) {
168
+ return false;
169
+ }
170
+ if (listDepth < listItemPos.depth) {
171
+ return true;
172
+ }
173
+ return false;
174
+ };
175
+
176
+ // src/keymap/listHelpers/handleDelete.ts
177
+ var handleDelete = (editor, name) => {
178
+ if (!isNodeActive2(editor.state, name)) {
179
+ return false;
180
+ }
181
+ if (!isAtEndOfNode(editor.state, name)) {
182
+ return false;
183
+ }
184
+ const { selection } = editor.state;
185
+ const { $from, $to } = selection;
186
+ if (!selection.empty && $from.sameParent($to)) {
187
+ return false;
188
+ }
189
+ if (nextListIsDeeper(name, editor.state)) {
190
+ return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
191
+ }
192
+ if (nextListIsHigher(name, editor.state)) {
193
+ return editor.chain().joinForward().joinBackward().run();
194
+ }
195
+ return editor.commands.joinItemForward();
196
+ };
197
+
198
+ // src/keymap/listHelpers/hasListItemAfter.ts
199
+ var hasListItemAfter = (typeOrName, state) => {
200
+ var _a;
201
+ const { $anchor } = state.selection;
202
+ const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
203
+ if ($targetPos.index() === $targetPos.parent.childCount - 1) {
204
+ return false;
205
+ }
206
+ if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) {
207
+ return false;
208
+ }
209
+ return true;
210
+ };
211
+
212
+ // src/keymap/list-keymap.ts
213
+ var ListKeymap = Extension.create({
214
+ name: "listKeymap",
215
+ addOptions() {
216
+ return {
217
+ listTypes: [
218
+ {
219
+ itemName: "listItem",
220
+ wrapperNames: ["bulletList", "orderedList"]
221
+ },
222
+ {
223
+ itemName: "taskItem",
224
+ wrapperNames: ["taskList"]
225
+ }
226
+ ]
227
+ };
228
+ },
229
+ addKeyboardShortcuts() {
230
+ return {
231
+ Delete: ({ editor }) => {
232
+ let handled = false;
233
+ this.options.listTypes.forEach(({ itemName }) => {
234
+ if (editor.state.schema.nodes[itemName] === void 0) {
235
+ return;
236
+ }
237
+ if (handleDelete(editor, itemName)) {
238
+ handled = true;
239
+ }
240
+ });
241
+ return handled;
242
+ },
243
+ "Mod-Delete": ({ editor }) => {
244
+ let handled = false;
245
+ this.options.listTypes.forEach(({ itemName }) => {
246
+ if (editor.state.schema.nodes[itemName] === void 0) {
247
+ return;
248
+ }
249
+ if (handleDelete(editor, itemName)) {
250
+ handled = true;
251
+ }
252
+ });
253
+ return handled;
254
+ },
255
+ Backspace: ({ editor }) => {
256
+ let handled = false;
257
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
258
+ if (editor.state.schema.nodes[itemName] === void 0) {
259
+ return;
260
+ }
261
+ if (handleBackspace(editor, itemName, wrapperNames)) {
262
+ handled = true;
263
+ }
264
+ });
265
+ return handled;
266
+ },
267
+ "Mod-Backspace": ({ editor }) => {
268
+ let handled = false;
269
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
270
+ if (editor.state.schema.nodes[itemName] === void 0) {
271
+ return;
272
+ }
273
+ if (handleBackspace(editor, itemName, wrapperNames)) {
274
+ handled = true;
275
+ }
276
+ });
277
+ return handled;
278
+ }
279
+ };
280
+ }
281
+ });
282
+ export {
283
+ ListKeymap,
284
+ listHelpers_exports as listHelpers
285
+ };
286
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/keymap/list-keymap.ts","../../src/keymap/listHelpers/index.ts","../../src/keymap/listHelpers/findListItemPos.ts","../../src/keymap/listHelpers/getNextListDepth.ts","../../src/keymap/listHelpers/handleBackspace.ts","../../src/keymap/listHelpers/hasListBefore.ts","../../src/keymap/listHelpers/hasListItemBefore.ts","../../src/keymap/listHelpers/listItemHasSubList.ts","../../src/keymap/listHelpers/handleDelete.ts","../../src/keymap/listHelpers/nextListIsDeeper.ts","../../src/keymap/listHelpers/nextListIsHigher.ts","../../src/keymap/listHelpers/hasListItemAfter.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nimport { handleBackspace, handleDelete } from './listHelpers/index.js'\n\nexport type ListKeymapOptions = {\n /**\n * An array of list types. This is used for item and wrapper list matching.\n * @default []\n * @example [{ itemName: 'listItem', wrapperNames: ['bulletList', 'orderedList'] }]\n */\n listTypes: Array<{\n itemName: string\n wrapperNames: string[]\n }>\n}\n\n/**\n * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.\n * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into\n * the adjacent or previous list item. This extension will prevent this behaviour and instead will\n * try to join paragraphs from two list items into a single list item.\n * @see https://www.tiptap.dev/api/extensions/list-keymap\n */\nexport const ListKeymap = Extension.create<ListKeymapOptions>({\n name: 'listKeymap',\n\n addOptions() {\n return {\n listTypes: [\n {\n itemName: 'listItem',\n wrapperNames: ['bulletList', 'orderedList'],\n },\n {\n itemName: 'taskItem',\n wrapperNames: ['taskList'],\n },\n ],\n }\n },\n\n addKeyboardShortcuts() {\n return {\n Delete: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Delete': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleDelete(editor, itemName)) {\n handled = true\n }\n })\n\n return handled\n },\n Backspace: ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n 'Mod-Backspace': ({ editor }) => {\n let handled = false\n\n this.options.listTypes.forEach(({ itemName, wrapperNames }) => {\n if (editor.state.schema.nodes[itemName] === undefined) {\n return\n }\n\n if (handleBackspace(editor, itemName, wrapperNames)) {\n handled = true\n }\n })\n\n return handled\n },\n }\n },\n})\n","export * from './findListItemPos.js'\nexport * from './getNextListDepth.js'\nexport * from './handleBackspace.js'\nexport * from './handleDelete.js'\nexport * from './hasListBefore.js'\nexport * from './hasListItemAfter.js'\nexport * from './hasListItemBefore.js'\nexport * from './listItemHasSubList.js'\nexport * from './nextListIsDeeper.js'\nexport * from './nextListIsHigher.js'\n","import { getNodeType } from '@tiptap/core'\nimport { NodeType } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const findListItemPos = (typeOrName: string | NodeType, state: EditorState) => {\n const { $from } = state.selection\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let currentNode = null\n let currentDepth = $from.depth\n let currentPos = $from.pos\n let targetDepth: number | null = null\n\n while (currentDepth > 0 && targetDepth === null) {\n currentNode = $from.node(currentDepth)\n\n if (currentNode.type === nodeType) {\n targetDepth = currentDepth\n } else {\n currentDepth -= 1\n currentPos -= 1\n }\n }\n\n if (targetDepth === null) {\n return null\n }\n\n return { $pos: state.doc.resolve(currentPos), depth: targetDepth }\n}\n","import { getNodeAtPosition } from '@tiptap/core'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\n\nexport const getNextListDepth = (typeOrName: string, state: EditorState) => {\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos) {\n return false\n }\n\n const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4)\n\n return depth\n}\n","import { Editor, isAtStartOfNode, isNodeActive } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { hasListBefore } from './hasListBefore.js'\nimport { hasListItemBefore } from './hasListItemBefore.js'\nimport { listItemHasSubList } from './listItemHasSubList.js'\n\nexport const handleBackspace = (editor: Editor, name: string, parentListTypes: string[]) => {\n // this is required to still handle the undo handling\n if (editor.commands.undoInputRule()) {\n return true\n }\n\n // if the selection is not collapsed\n // we can rely on the default backspace behavior\n if (editor.state.selection.from !== editor.state.selection.to) {\n return false\n }\n\n // if the current item is NOT inside a list item &\n // the previous item is a list (orderedList or bulletList)\n // move the cursor into the list and delete the current item\n if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {\n const { $anchor } = editor.state.selection\n\n const $listPos = editor.state.doc.resolve($anchor.before() - 1)\n\n const listDescendants: Array<{ node: Node; pos: number }> = []\n\n $listPos.node().descendants((node, pos) => {\n if (node.type.name === name) {\n listDescendants.push({ node, pos })\n }\n })\n\n const lastItem = listDescendants.at(-1)\n\n if (!lastItem) {\n return false\n }\n\n const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1)\n\n return editor\n .chain()\n .cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end())\n .joinForward()\n .run()\n }\n\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the start of a node\n // do nothing and proceed\n if (!isAtStartOfNode(editor.state)) {\n return false\n }\n\n const listItemPos = findListItemPos(name, editor.state)\n\n if (!listItemPos) {\n return false\n }\n\n const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2)\n const prevNode = $prev.node(listItemPos.depth)\n\n const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode)\n\n // if the previous item is a list item and doesn't have a sublist, join the list items\n if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {\n return editor.commands.joinItemBackward()\n }\n\n // otherwise in the end, a backspace should\n // always just lift the list item if\n // joining / merging is not possible\n return editor.chain().liftListItem(name).run()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListBefore = (editorState: EditorState, name: string, parentListTypes: string[]) => {\n const { $anchor } = editorState.selection\n\n const previousNodePos = Math.max(0, $anchor.pos - 2)\n\n const previousNode = editorState.doc.resolve(previousNodePos).node()\n\n if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {\n return false\n }\n\n return true\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemBefore = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - 2)\n\n if ($targetPos.index() === 0) {\n return false\n }\n\n if ($targetPos.nodeBefore?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n","import { getNodeType } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nexport const listItemHasSubList = (typeOrName: string, state: EditorState, node?: Node) => {\n if (!node) {\n return false\n }\n\n const nodeType = getNodeType(typeOrName, state.schema)\n\n let hasSubList = false\n\n node.descendants(child => {\n if (child.type === nodeType) {\n hasSubList = true\n }\n })\n\n return hasSubList\n}\n","import { Editor, isAtEndOfNode, isNodeActive } from '@tiptap/core'\n\nimport { nextListIsDeeper } from './nextListIsDeeper.js'\nimport { nextListIsHigher } from './nextListIsHigher.js'\n\nexport const handleDelete = (editor: Editor, name: string) => {\n // if the cursor is not inside the current node type\n // do nothing and proceed\n if (!isNodeActive(editor.state, name)) {\n return false\n }\n\n // if the cursor is not at the end of a node\n // do nothing and proceed\n if (!isAtEndOfNode(editor.state, name)) {\n return false\n }\n\n // if the selection is not collapsed, or not within a single node\n // do nothing and proceed\n const { selection } = editor.state\n const { $from, $to } = selection\n\n if (!selection.empty && $from.sameParent($to)) {\n return false\n }\n\n // check if the next node is a list with a deeper depth\n if (nextListIsDeeper(name, editor.state)) {\n return editor\n .chain()\n .focus(editor.state.selection.from + 4)\n .lift(name)\n .joinBackward()\n .run()\n }\n\n if (nextListIsHigher(name, editor.state)) {\n return editor.chain().joinForward().joinBackward().run()\n }\n\n return editor.commands.joinItemForward()\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsDeeper = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth > listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nimport { findListItemPos } from './findListItemPos.js'\nimport { getNextListDepth } from './getNextListDepth.js'\n\nexport const nextListIsHigher = (typeOrName: string, state: EditorState) => {\n const listDepth = getNextListDepth(typeOrName, state)\n const listItemPos = findListItemPos(typeOrName, state)\n\n if (!listItemPos || !listDepth) {\n return false\n }\n\n if (listDepth < listItemPos.depth) {\n return true\n }\n\n return false\n}\n","import { EditorState } from '@tiptap/pm/state'\n\nexport const hasListItemAfter = (typeOrName: string, state: EditorState): boolean => {\n const { $anchor } = state.selection\n\n const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2)\n\n if ($targetPos.index() === $targetPos.parent.childCount - 1) {\n return false\n }\n\n if ($targetPos.nodeAfter?.type.name !== typeOrName) {\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;;;AAAA,SAAS,iBAAiB;;;ACA1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,mBAAmB;AAIrB,IAAM,kBAAkB,CAAC,YAA+B,UAAuB;AACpF,QAAM,EAAE,MAAM,IAAI,MAAM;AACxB,QAAM,WAAW,YAAY,YAAY,MAAM,MAAM;AAErD,MAAI,cAAc;AAClB,MAAI,eAAe,MAAM;AACzB,MAAI,aAAa,MAAM;AACvB,MAAI,cAA6B;AAEjC,SAAO,eAAe,KAAK,gBAAgB,MAAM;AAC/C,kBAAc,MAAM,KAAK,YAAY;AAErC,QAAI,YAAY,SAAS,UAAU;AACjC,oBAAc;AAAA,IAChB,OAAO;AACL,sBAAgB;AAChB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,MAAM,MAAM,IAAI,QAAQ,UAAU,GAAG,OAAO,YAAY;AACnE;;;AC7BA,SAAS,yBAAyB;AAK3B,IAAM,mBAAmB,CAAC,YAAoB,UAAuB;AAC1E,QAAM,cAAc,gBAAgB,YAAY,KAAK;AAErD,MAAI,CAAC,aAAa;AAChB,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,EAAE,KAAK,IAAI,kBAAkB,OAAO,YAAY,YAAY,KAAK,MAAM,CAAC;AAE/E,SAAO;AACT;;;ACfA,SAAiB,iBAAiB,oBAAoB;;;ACE/C,IAAM,gBAAgB,CAAC,aAA0B,MAAc,oBAA8B;AAClG,QAAM,EAAE,QAAQ,IAAI,YAAY;AAEhC,QAAM,k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