@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.
- package/LICENSE.md +21 -0
- package/README.md +18 -0
- package/dist/bullet-list/index.cjs +93 -0
- package/dist/bullet-list/index.cjs.map +1 -0
- package/dist/bullet-list/index.d.cts +51 -0
- package/dist/bullet-list/index.d.ts +51 -0
- package/dist/bullet-list/index.js +65 -0
- package/dist/bullet-list/index.js.map +1 -0
- package/dist/index.cjs +714 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +288 -0
- package/dist/index.d.ts +288 -0
- package/dist/index.js +683 -0
- package/dist/index.js.map +1 -0
- package/dist/item/index.cjs +62 -0
- package/dist/item/index.cjs.map +1 -0
- package/dist/item/index.d.cts +29 -0
- package/dist/item/index.d.ts +29 -0
- package/dist/item/index.js +35 -0
- package/dist/item/index.js.map +1 -0
- package/dist/keymap/index.cjs +308 -0
- package/dist/keymap/index.cjs.map +1 -0
- package/dist/keymap/index.d.cts +63 -0
- package/dist/keymap/index.d.ts +63 -0
- package/dist/keymap/index.js +286 -0
- package/dist/keymap/index.js.map +1 -0
- package/dist/kit/index.cjs +692 -0
- package/dist/kit/index.cjs.map +1 -0
- package/dist/kit/index.d.cts +200 -0
- package/dist/kit/index.d.ts +200 -0
- package/dist/kit/index.js +673 -0
- package/dist/kit/index.js.map +1 -0
- package/dist/ordered-list/index.cjs +113 -0
- package/dist/ordered-list/index.cjs.map +1 -0
- package/dist/ordered-list/index.d.cts +52 -0
- package/dist/ordered-list/index.d.ts +52 -0
- package/dist/ordered-list/index.js +85 -0
- package/dist/ordered-list/index.js.map +1 -0
- package/dist/task-item/index.cjs +177 -0
- package/dist/task-item/index.cjs.map +1 -0
- package/dist/task-item/index.d.cts +41 -0
- package/dist/task-item/index.d.ts +41 -0
- package/dist/task-item/index.js +149 -0
- package/dist/task-item/index.js.map +1 -0
- package/dist/task-list/index.cjs +69 -0
- package/dist/task-list/index.cjs.map +1 -0
- package/dist/task-list/index.d.cts +34 -0
- package/dist/task-list/index.d.ts +34 -0
- package/dist/task-list/index.js +42 -0
- package/dist/task-list/index.js.map +1 -0
- package/package.json +106 -0
- package/src/bullet-list/bullet-list.ts +126 -0
- package/src/bullet-list/index.ts +1 -0
- package/src/index.ts +7 -0
- package/src/item/index.ts +1 -0
- package/src/item/list-item.ts +64 -0
- package/src/keymap/index.ts +2 -0
- package/src/keymap/list-keymap.ts +106 -0
- package/src/keymap/listHelpers/findListItemPos.ts +30 -0
- package/src/keymap/listHelpers/getNextListDepth.ts +16 -0
- package/src/keymap/listHelpers/handleBackspace.ts +85 -0
- package/src/keymap/listHelpers/handleDelete.ts +44 -0
- package/src/keymap/listHelpers/hasListBefore.ts +15 -0
- package/src/keymap/listHelpers/hasListItemAfter.ts +17 -0
- package/src/keymap/listHelpers/hasListItemBefore.ts +17 -0
- package/src/keymap/listHelpers/index.ts +10 -0
- package/src/keymap/listHelpers/listItemHasSubList.ts +21 -0
- package/src/keymap/listHelpers/nextListIsDeeper.ts +19 -0
- package/src/keymap/listHelpers/nextListIsHigher.ts +19 -0
- package/src/kit/index.ts +81 -0
- package/src/ordered-list/index.ts +1 -0
- package/src/ordered-list/ordered-list.ts +151 -0
- package/src/task-item/index.ts +1 -0
- package/src/task-item/task-item.ts +220 -0
- package/src/task-list/index.ts +1 -0
- package/src/task-list/task-list.ts +79 -0
|
@@ -0,0 +1,673 @@
|
|
|
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/kit/index.ts
|
|
8
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
9
|
+
|
|
10
|
+
// src/bullet-list/bullet-list.ts
|
|
11
|
+
import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
|
|
12
|
+
var ListItemName = "listItem";
|
|
13
|
+
var TextStyleName = "textStyle";
|
|
14
|
+
var bulletListInputRegex = /^\s*([-+*])\s$/;
|
|
15
|
+
var BulletList = Node.create({
|
|
16
|
+
name: "bulletList",
|
|
17
|
+
addOptions() {
|
|
18
|
+
return {
|
|
19
|
+
itemTypeName: "listItem",
|
|
20
|
+
HTMLAttributes: {},
|
|
21
|
+
keepMarks: false,
|
|
22
|
+
keepAttributes: false
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
group: "block list",
|
|
26
|
+
content() {
|
|
27
|
+
return `${this.options.itemTypeName}+`;
|
|
28
|
+
},
|
|
29
|
+
parseHTML() {
|
|
30
|
+
return [{ tag: "ul" }];
|
|
31
|
+
},
|
|
32
|
+
renderHTML({ HTMLAttributes }) {
|
|
33
|
+
return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
34
|
+
},
|
|
35
|
+
addCommands() {
|
|
36
|
+
return {
|
|
37
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
38
|
+
if (this.options.keepAttributes) {
|
|
39
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
40
|
+
}
|
|
41
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
addKeyboardShortcuts() {
|
|
46
|
+
return {
|
|
47
|
+
"Mod-Shift-8": () => this.editor.commands.toggleBulletList()
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
addInputRules() {
|
|
51
|
+
let inputRule = wrappingInputRule({
|
|
52
|
+
find: bulletListInputRegex,
|
|
53
|
+
type: this.type
|
|
54
|
+
});
|
|
55
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
56
|
+
inputRule = wrappingInputRule({
|
|
57
|
+
find: bulletListInputRegex,
|
|
58
|
+
type: this.type,
|
|
59
|
+
keepMarks: this.options.keepMarks,
|
|
60
|
+
keepAttributes: this.options.keepAttributes,
|
|
61
|
+
getAttributes: () => {
|
|
62
|
+
return this.editor.getAttributes(TextStyleName);
|
|
63
|
+
},
|
|
64
|
+
editor: this.editor
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return [inputRule];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// src/item/list-item.ts
|
|
72
|
+
import { mergeAttributes as mergeAttributes2, Node as Node2 } from "@tiptap/core";
|
|
73
|
+
var ListItem = Node2.create({
|
|
74
|
+
name: "listItem",
|
|
75
|
+
addOptions() {
|
|
76
|
+
return {
|
|
77
|
+
HTMLAttributes: {},
|
|
78
|
+
bulletListTypeName: "bulletList",
|
|
79
|
+
orderedListTypeName: "orderedList"
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
content: "paragraph block*",
|
|
83
|
+
defining: true,
|
|
84
|
+
parseHTML() {
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
tag: "li"
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
},
|
|
91
|
+
renderHTML({ HTMLAttributes }) {
|
|
92
|
+
return ["li", mergeAttributes2(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
93
|
+
},
|
|
94
|
+
addKeyboardShortcuts() {
|
|
95
|
+
return {
|
|
96
|
+
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
97
|
+
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
98
|
+
"Shift-Tab": () => this.editor.commands.liftListItem(this.name)
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// src/keymap/list-keymap.ts
|
|
104
|
+
import { Extension } from "@tiptap/core";
|
|
105
|
+
|
|
106
|
+
// src/keymap/listHelpers/index.ts
|
|
107
|
+
var listHelpers_exports = {};
|
|
108
|
+
__export(listHelpers_exports, {
|
|
109
|
+
findListItemPos: () => findListItemPos,
|
|
110
|
+
getNextListDepth: () => getNextListDepth,
|
|
111
|
+
handleBackspace: () => handleBackspace,
|
|
112
|
+
handleDelete: () => handleDelete,
|
|
113
|
+
hasListBefore: () => hasListBefore,
|
|
114
|
+
hasListItemAfter: () => hasListItemAfter,
|
|
115
|
+
hasListItemBefore: () => hasListItemBefore,
|
|
116
|
+
listItemHasSubList: () => listItemHasSubList,
|
|
117
|
+
nextListIsDeeper: () => nextListIsDeeper,
|
|
118
|
+
nextListIsHigher: () => nextListIsHigher
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// src/keymap/listHelpers/findListItemPos.ts
|
|
122
|
+
import { getNodeType } from "@tiptap/core";
|
|
123
|
+
var findListItemPos = (typeOrName, state) => {
|
|
124
|
+
const { $from } = state.selection;
|
|
125
|
+
const nodeType = getNodeType(typeOrName, state.schema);
|
|
126
|
+
let currentNode = null;
|
|
127
|
+
let currentDepth = $from.depth;
|
|
128
|
+
let currentPos = $from.pos;
|
|
129
|
+
let targetDepth = null;
|
|
130
|
+
while (currentDepth > 0 && targetDepth === null) {
|
|
131
|
+
currentNode = $from.node(currentDepth);
|
|
132
|
+
if (currentNode.type === nodeType) {
|
|
133
|
+
targetDepth = currentDepth;
|
|
134
|
+
} else {
|
|
135
|
+
currentDepth -= 1;
|
|
136
|
+
currentPos -= 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (targetDepth === null) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/keymap/listHelpers/getNextListDepth.ts
|
|
146
|
+
import { getNodeAtPosition } from "@tiptap/core";
|
|
147
|
+
var getNextListDepth = (typeOrName, state) => {
|
|
148
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
149
|
+
if (!listItemPos) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const [, depth] = getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
|
|
153
|
+
return depth;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// src/keymap/listHelpers/handleBackspace.ts
|
|
157
|
+
import { isAtStartOfNode, isNodeActive } from "@tiptap/core";
|
|
158
|
+
|
|
159
|
+
// src/keymap/listHelpers/hasListBefore.ts
|
|
160
|
+
var hasListBefore = (editorState, name, parentListTypes) => {
|
|
161
|
+
const { $anchor } = editorState.selection;
|
|
162
|
+
const previousNodePos = Math.max(0, $anchor.pos - 2);
|
|
163
|
+
const previousNode = editorState.doc.resolve(previousNodePos).node();
|
|
164
|
+
if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/keymap/listHelpers/hasListItemBefore.ts
|
|
171
|
+
var hasListItemBefore = (typeOrName, state) => {
|
|
172
|
+
var _a;
|
|
173
|
+
const { $anchor } = state.selection;
|
|
174
|
+
const $targetPos = state.doc.resolve($anchor.pos - 2);
|
|
175
|
+
if ($targetPos.index() === 0) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (((_a = $targetPos.nodeBefore) == null ? void 0 : _a.type.name) !== typeOrName) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/keymap/listHelpers/listItemHasSubList.ts
|
|
185
|
+
import { getNodeType as getNodeType2 } from "@tiptap/core";
|
|
186
|
+
var listItemHasSubList = (typeOrName, state, node) => {
|
|
187
|
+
if (!node) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
const nodeType = getNodeType2(typeOrName, state.schema);
|
|
191
|
+
let hasSubList = false;
|
|
192
|
+
node.descendants((child) => {
|
|
193
|
+
if (child.type === nodeType) {
|
|
194
|
+
hasSubList = true;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
return hasSubList;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/keymap/listHelpers/handleBackspace.ts
|
|
201
|
+
var handleBackspace = (editor, name, parentListTypes) => {
|
|
202
|
+
if (editor.commands.undoInputRule()) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
if (editor.state.selection.from !== editor.state.selection.to) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if (!isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
|
|
209
|
+
const { $anchor } = editor.state.selection;
|
|
210
|
+
const $listPos = editor.state.doc.resolve($anchor.before() - 1);
|
|
211
|
+
const listDescendants = [];
|
|
212
|
+
$listPos.node().descendants((node, pos) => {
|
|
213
|
+
if (node.type.name === name) {
|
|
214
|
+
listDescendants.push({ node, pos });
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
const lastItem = listDescendants.at(-1);
|
|
218
|
+
if (!lastItem) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
|
|
222
|
+
return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
|
|
223
|
+
}
|
|
224
|
+
if (!isNodeActive(editor.state, name)) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
if (!isAtStartOfNode(editor.state)) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const listItemPos = findListItemPos(name, editor.state);
|
|
231
|
+
if (!listItemPos) {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
|
|
235
|
+
const prevNode = $prev.node(listItemPos.depth);
|
|
236
|
+
const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
|
|
237
|
+
if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
|
|
238
|
+
return editor.commands.joinItemBackward();
|
|
239
|
+
}
|
|
240
|
+
return editor.chain().liftListItem(name).run();
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/keymap/listHelpers/handleDelete.ts
|
|
244
|
+
import { isAtEndOfNode, isNodeActive as isNodeActive2 } from "@tiptap/core";
|
|
245
|
+
|
|
246
|
+
// src/keymap/listHelpers/nextListIsDeeper.ts
|
|
247
|
+
var nextListIsDeeper = (typeOrName, state) => {
|
|
248
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
249
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
250
|
+
if (!listItemPos || !listDepth) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (listDepth > listItemPos.depth) {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// src/keymap/listHelpers/nextListIsHigher.ts
|
|
260
|
+
var nextListIsHigher = (typeOrName, state) => {
|
|
261
|
+
const listDepth = getNextListDepth(typeOrName, state);
|
|
262
|
+
const listItemPos = findListItemPos(typeOrName, state);
|
|
263
|
+
if (!listItemPos || !listDepth) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
if (listDepth < listItemPos.depth) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
return false;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// src/keymap/listHelpers/handleDelete.ts
|
|
273
|
+
var handleDelete = (editor, name) => {
|
|
274
|
+
if (!isNodeActive2(editor.state, name)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
if (!isAtEndOfNode(editor.state, name)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
const { selection } = editor.state;
|
|
281
|
+
const { $from, $to } = selection;
|
|
282
|
+
if (!selection.empty && $from.sameParent($to)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
if (nextListIsDeeper(name, editor.state)) {
|
|
286
|
+
return editor.chain().focus(editor.state.selection.from + 4).lift(name).joinBackward().run();
|
|
287
|
+
}
|
|
288
|
+
if (nextListIsHigher(name, editor.state)) {
|
|
289
|
+
return editor.chain().joinForward().joinBackward().run();
|
|
290
|
+
}
|
|
291
|
+
return editor.commands.joinItemForward();
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/keymap/listHelpers/hasListItemAfter.ts
|
|
295
|
+
var hasListItemAfter = (typeOrName, state) => {
|
|
296
|
+
var _a;
|
|
297
|
+
const { $anchor } = state.selection;
|
|
298
|
+
const $targetPos = state.doc.resolve($anchor.pos - $anchor.parentOffset - 2);
|
|
299
|
+
if ($targetPos.index() === $targetPos.parent.childCount - 1) {
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
if (((_a = $targetPos.nodeAfter) == null ? void 0 : _a.type.name) !== typeOrName) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
return true;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// src/keymap/list-keymap.ts
|
|
309
|
+
var ListKeymap = Extension.create({
|
|
310
|
+
name: "listKeymap",
|
|
311
|
+
addOptions() {
|
|
312
|
+
return {
|
|
313
|
+
listTypes: [
|
|
314
|
+
{
|
|
315
|
+
itemName: "listItem",
|
|
316
|
+
wrapperNames: ["bulletList", "orderedList"]
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
itemName: "taskItem",
|
|
320
|
+
wrapperNames: ["taskList"]
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
addKeyboardShortcuts() {
|
|
326
|
+
return {
|
|
327
|
+
Delete: ({ editor }) => {
|
|
328
|
+
let handled = false;
|
|
329
|
+
this.options.listTypes.forEach(({ itemName }) => {
|
|
330
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (handleDelete(editor, itemName)) {
|
|
334
|
+
handled = true;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return handled;
|
|
338
|
+
},
|
|
339
|
+
"Mod-Delete": ({ editor }) => {
|
|
340
|
+
let handled = false;
|
|
341
|
+
this.options.listTypes.forEach(({ itemName }) => {
|
|
342
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (handleDelete(editor, itemName)) {
|
|
346
|
+
handled = true;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return handled;
|
|
350
|
+
},
|
|
351
|
+
Backspace: ({ editor }) => {
|
|
352
|
+
let handled = false;
|
|
353
|
+
this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
|
|
354
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (handleBackspace(editor, itemName, wrapperNames)) {
|
|
358
|
+
handled = true;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
return handled;
|
|
362
|
+
},
|
|
363
|
+
"Mod-Backspace": ({ editor }) => {
|
|
364
|
+
let handled = false;
|
|
365
|
+
this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
|
|
366
|
+
if (editor.state.schema.nodes[itemName] === void 0) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (handleBackspace(editor, itemName, wrapperNames)) {
|
|
370
|
+
handled = true;
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
return handled;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
});
|
|
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
|
+
ListKit
|
|
672
|
+
};
|
|
673
|
+
//# sourceMappingURL=index.js.map
|