@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.
- 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 +109 -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 +84 -0
- package/src/keymap/listHelpers/handleDelete.ts +43 -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 +75 -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 +219 -0
- package/src/task-list/index.ts +1 -0
- package/src/task-list/task-list.ts +79 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @tiptap/extension-list
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tiptap/extension-list)
|
|
4
|
+
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
5
|
+
[](https://www.npmjs.com/package/@tiptap/extension-list)
|
|
6
|
+
[](https://github.com/sponsors/ueberdosis)
|
|
7
|
+
|
|
8
|
+
## Introduction
|
|
9
|
+
|
|
10
|
+
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
|
|
11
|
+
|
|
12
|
+
## Official Documentation
|
|
13
|
+
|
|
14
|
+
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -0,0 +1,93 @@
|
|
|
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/bullet-list/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BulletList: () => BulletList,
|
|
24
|
+
bulletListInputRegex: () => bulletListInputRegex
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
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
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
BulletList,
|
|
91
|
+
bulletListInputRegex
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bullet-list/index.ts","../../src/bullet-list/bullet-list.ts"],"sourcesContent":["export * from './bullet-list.js'\n","import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface BulletListOptions {\n /**\n * The node name for the list items\n * @default 'listItem'\n * @example 'paragraph'\n */\n itemTypeName: string\n\n /**\n * HTML attributes to add to the bullet list element\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting the list\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting the list\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n bulletList: {\n /**\n * Toggle a bullet list\n */\n toggleBulletList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nexport const bulletListInputRegex = /^\\s*([-+*])\\s$/\n\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [{ tag: 'ul' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList:\n () =>\n ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain()\n .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))\n .run()\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => {\n return this.editor.getAttributes(TextStyleName)\n },\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyD;AAEzD,IAAM,eAAe;AACrB,IAAM,gBAAgB;AA8Cf,IAAM,uBAAuB;AAQ7B,IAAM,aAAa,iBAAK,OAA0B;AAAA,EACvD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CAAC;AAAA,MACjB,WAAW;AAAA,MACX,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,UAAU;AACR,WAAO,GAAG,KAAK,QAAQ,YAAY;AAAA,EACrC;AAAA,EAEA,YAAY;AACV,WAAO,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|
+
* The node name for the list items
|
|
6
|
+
* @default 'listItem'
|
|
7
|
+
* @example 'paragraph'
|
|
8
|
+
*/
|
|
9
|
+
itemTypeName: string;
|
|
10
|
+
/**
|
|
11
|
+
* HTML attributes to add to the bullet list element
|
|
12
|
+
* @default {}
|
|
13
|
+
* @example { class: 'foo' }
|
|
14
|
+
*/
|
|
15
|
+
HTMLAttributes: Record<string, any>;
|
|
16
|
+
/**
|
|
17
|
+
* Keep the marks when splitting the list
|
|
18
|
+
* @default false
|
|
19
|
+
* @example true
|
|
20
|
+
*/
|
|
21
|
+
keepMarks: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Keep the attributes when splitting the list
|
|
24
|
+
* @default false
|
|
25
|
+
* @example true
|
|
26
|
+
*/
|
|
27
|
+
keepAttributes: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare module '@tiptap/core' {
|
|
30
|
+
interface Commands<ReturnType> {
|
|
31
|
+
bulletList: {
|
|
32
|
+
/**
|
|
33
|
+
* Toggle a bullet list
|
|
34
|
+
*/
|
|
35
|
+
toggleBulletList: () => ReturnType;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Matches a bullet list to a dash or asterisk.
|
|
41
|
+
*/
|
|
42
|
+
declare const bulletListInputRegex: RegExp;
|
|
43
|
+
/**
|
|
44
|
+
* This extension allows you to create bullet lists.
|
|
45
|
+
* This requires the ListItem extension
|
|
46
|
+
* @see https://tiptap.dev/api/nodes/bullet-list
|
|
47
|
+
* @see https://tiptap.dev/api/nodes/list-item.
|
|
48
|
+
*/
|
|
49
|
+
declare const BulletList: Node<BulletListOptions, any>;
|
|
50
|
+
|
|
51
|
+
export { BulletList, type BulletListOptions, bulletListInputRegex };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface BulletListOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The node name for the list items
|
|
6
|
+
* @default 'listItem'
|
|
7
|
+
* @example 'paragraph'
|
|
8
|
+
*/
|
|
9
|
+
itemTypeName: string;
|
|
10
|
+
/**
|
|
11
|
+
* HTML attributes to add to the bullet list element
|
|
12
|
+
* @default {}
|
|
13
|
+
* @example { class: 'foo' }
|
|
14
|
+
*/
|
|
15
|
+
HTMLAttributes: Record<string, any>;
|
|
16
|
+
/**
|
|
17
|
+
* Keep the marks when splitting the list
|
|
18
|
+
* @default false
|
|
19
|
+
* @example true
|
|
20
|
+
*/
|
|
21
|
+
keepMarks: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Keep the attributes when splitting the list
|
|
24
|
+
* @default false
|
|
25
|
+
* @example true
|
|
26
|
+
*/
|
|
27
|
+
keepAttributes: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare module '@tiptap/core' {
|
|
30
|
+
interface Commands<ReturnType> {
|
|
31
|
+
bulletList: {
|
|
32
|
+
/**
|
|
33
|
+
* Toggle a bullet list
|
|
34
|
+
*/
|
|
35
|
+
toggleBulletList: () => ReturnType;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Matches a bullet list to a dash or asterisk.
|
|
41
|
+
*/
|
|
42
|
+
declare const bulletListInputRegex: RegExp;
|
|
43
|
+
/**
|
|
44
|
+
* This extension allows you to create bullet lists.
|
|
45
|
+
* This requires the ListItem extension
|
|
46
|
+
* @see https://tiptap.dev/api/nodes/bullet-list
|
|
47
|
+
* @see https://tiptap.dev/api/nodes/list-item.
|
|
48
|
+
*/
|
|
49
|
+
declare const BulletList: Node<BulletListOptions, any>;
|
|
50
|
+
|
|
51
|
+
export { BulletList, type BulletListOptions, bulletListInputRegex };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// src/bullet-list/bullet-list.ts
|
|
2
|
+
import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
|
|
3
|
+
var ListItemName = "listItem";
|
|
4
|
+
var TextStyleName = "textStyle";
|
|
5
|
+
var bulletListInputRegex = /^\s*([-+*])\s$/;
|
|
6
|
+
var BulletList = Node.create({
|
|
7
|
+
name: "bulletList",
|
|
8
|
+
addOptions() {
|
|
9
|
+
return {
|
|
10
|
+
itemTypeName: "listItem",
|
|
11
|
+
HTMLAttributes: {},
|
|
12
|
+
keepMarks: false,
|
|
13
|
+
keepAttributes: false
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
group: "block list",
|
|
17
|
+
content() {
|
|
18
|
+
return `${this.options.itemTypeName}+`;
|
|
19
|
+
},
|
|
20
|
+
parseHTML() {
|
|
21
|
+
return [{ tag: "ul" }];
|
|
22
|
+
},
|
|
23
|
+
renderHTML({ HTMLAttributes }) {
|
|
24
|
+
return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
25
|
+
},
|
|
26
|
+
addCommands() {
|
|
27
|
+
return {
|
|
28
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
29
|
+
if (this.options.keepAttributes) {
|
|
30
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
31
|
+
}
|
|
32
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
addKeyboardShortcuts() {
|
|
37
|
+
return {
|
|
38
|
+
"Mod-Shift-8": () => this.editor.commands.toggleBulletList()
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
addInputRules() {
|
|
42
|
+
let inputRule = wrappingInputRule({
|
|
43
|
+
find: bulletListInputRegex,
|
|
44
|
+
type: this.type
|
|
45
|
+
});
|
|
46
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
47
|
+
inputRule = wrappingInputRule({
|
|
48
|
+
find: bulletListInputRegex,
|
|
49
|
+
type: this.type,
|
|
50
|
+
keepMarks: this.options.keepMarks,
|
|
51
|
+
keepAttributes: this.options.keepAttributes,
|
|
52
|
+
getAttributes: () => {
|
|
53
|
+
return this.editor.getAttributes(TextStyleName);
|
|
54
|
+
},
|
|
55
|
+
editor: this.editor
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return [inputRule];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export {
|
|
62
|
+
BulletList,
|
|
63
|
+
bulletListInputRegex
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/bullet-list/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface BulletListOptions {\n /**\n * The node name for the list items\n * @default 'listItem'\n * @example 'paragraph'\n */\n itemTypeName: string\n\n /**\n * HTML attributes to add to the bullet list element\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Keep the marks when splitting the list\n * @default false\n * @example true\n */\n keepMarks: boolean\n\n /**\n * Keep the attributes when splitting the list\n * @default false\n * @example true\n */\n keepAttributes: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n bulletList: {\n /**\n * Toggle a bullet list\n */\n toggleBulletList: () => ReturnType\n }\n }\n}\n\n/**\n * Matches a bullet list to a dash or asterisk.\n */\nexport const bulletListInputRegex = /^\\s*([-+*])\\s$/\n\n/**\n * This extension allows you to create bullet lists.\n * This requires the ListItem extension\n * @see https://tiptap.dev/api/nodes/bullet-list\n * @see https://tiptap.dev/api/nodes/list-item.\n */\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n keepMarks: false,\n keepAttributes: false,\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [{ tag: 'ul' }]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList:\n () =>\n ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain()\n .toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n .updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName))\n .run()\n }\n return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: bulletListInputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => {\n return this.editor.getAttributes(TextStyleName)\n },\n editor: this.editor,\n })\n }\n return [inputRule]\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB,MAAM,yBAAyB;AAEzD,IAAM,eAAe;AACrB,IAAM,gBAAgB;AA8Cf,IAAM,uBAAuB;AAQ7B,IAAM,aAAa,KAAK,OAA0B;AAAA,EACvD,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,cAAc;AAAA,MACd,gBAAgB,CAAC;AAAA,MACjB,WAAW;AAAA,MACX,gBAAgB;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,EAEP,UAAU;AACR,WAAO,GAAG,KAAK,QAAQ,YAAY;AAAA,EACrC;AAAA,EAEA,YAAY;AACV,WAAO,CAAC,EAAE,KAAK,KAAK,CAAC;AAAA,EACvB;AAAA,EAEA,WAAW,EAAE,eAAe,GAAG;AAC7B,WAAO,CAAC,MAAM,gBAAgB,KAAK,QAAQ,gBAAgB,cAAc,GAAG,CAAC;AAAA,EAC/E;AAAA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