@tiptap/extension-bullet-list 2.0.0-beta.217 → 2.0.0-beta.219
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/dist/index.cjs +87 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +88 -6
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +87 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/extension-bullet-list/src/bullet-list.d.ts +2 -0
- package/dist/packages/extension-list-item/src/index.d.ts +3 -0
- package/dist/packages/extension-list-item/src/list-item.d.ts +5 -0
- package/dist/packages/extension-text-style/src/index.d.ts +3 -0
- package/dist/packages/extension-text-style/src/text-style.d.ts +15 -0
- package/package.json +2 -2
- package/src/bullet-list.ts +27 -5
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,72 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@tiptap/core');
|
|
6
6
|
|
|
7
|
+
const ListItem = core.Node.create({
|
|
8
|
+
name: 'listItem',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
HTMLAttributes: {},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
content: 'paragraph block*',
|
|
15
|
+
defining: true,
|
|
16
|
+
parseHTML() {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
tag: 'li',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
},
|
|
23
|
+
renderHTML({ HTMLAttributes }) {
|
|
24
|
+
return ['li', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
25
|
+
},
|
|
26
|
+
addKeyboardShortcuts() {
|
|
27
|
+
return {
|
|
28
|
+
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
29
|
+
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
30
|
+
'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const TextStyle = core.Mark.create({
|
|
36
|
+
name: 'textStyle',
|
|
37
|
+
addOptions() {
|
|
38
|
+
return {
|
|
39
|
+
HTMLAttributes: {},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
parseHTML() {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
tag: 'span',
|
|
46
|
+
getAttrs: element => {
|
|
47
|
+
const hasStyles = element.hasAttribute('style');
|
|
48
|
+
if (!hasStyles) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return {};
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
renderHTML({ HTMLAttributes }) {
|
|
57
|
+
return ['span', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
58
|
+
},
|
|
59
|
+
addCommands() {
|
|
60
|
+
return {
|
|
61
|
+
removeEmptyTextStyle: () => ({ state, commands }) => {
|
|
62
|
+
const attributes = core.getMarkAttributes(state, this.type);
|
|
63
|
+
const hasStyles = Object.entries(attributes).some(([, value]) => !!value);
|
|
64
|
+
if (hasStyles) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return commands.unsetMark(this.name);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
7
73
|
const inputRegex = /^\s*([-+*])\s$/;
|
|
8
74
|
const BulletList = core.Node.create({
|
|
9
75
|
name: 'bulletList',
|
|
@@ -11,6 +77,8 @@ const BulletList = core.Node.create({
|
|
|
11
77
|
return {
|
|
12
78
|
itemTypeName: 'listItem',
|
|
13
79
|
HTMLAttributes: {},
|
|
80
|
+
keepMarks: false,
|
|
81
|
+
keepAttributes: false,
|
|
14
82
|
};
|
|
15
83
|
},
|
|
16
84
|
group: 'block list',
|
|
@@ -27,8 +95,11 @@ const BulletList = core.Node.create({
|
|
|
27
95
|
},
|
|
28
96
|
addCommands() {
|
|
29
97
|
return {
|
|
30
|
-
toggleBulletList: () => ({ commands }) => {
|
|
31
|
-
|
|
98
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
99
|
+
if (this.options.keepAttributes) {
|
|
100
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run();
|
|
101
|
+
}
|
|
102
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
32
103
|
},
|
|
33
104
|
};
|
|
34
105
|
},
|
|
@@ -38,11 +109,22 @@ const BulletList = core.Node.create({
|
|
|
38
109
|
};
|
|
39
110
|
},
|
|
40
111
|
addInputRules() {
|
|
41
|
-
|
|
42
|
-
|
|
112
|
+
let inputRule = core.wrappingInputRule({
|
|
113
|
+
find: inputRegex,
|
|
114
|
+
type: this.type,
|
|
115
|
+
});
|
|
116
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
117
|
+
inputRule = core.wrappingInputRule({
|
|
43
118
|
find: inputRegex,
|
|
44
119
|
type: this.type,
|
|
45
|
-
|
|
120
|
+
keepMarks: this.options.keepMarks,
|
|
121
|
+
keepAttributes: this.options.keepAttributes,
|
|
122
|
+
getAttributes: () => { return this.editor.getAttributes(TextStyle.name); },
|
|
123
|
+
editor: this.editor,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return [
|
|
127
|
+
inputRule,
|
|
46
128
|
];
|
|
47
129
|
},
|
|
48
130
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nexport interface BulletListOptions {\n itemTypeName: string,\n HTMLAttributes: Record<string, any>,\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\nexport const inputRegex = /^\\s*([-+*])\\s$/\n\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [\n { tag: 'ul' },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList: () => ({ commands }) => {\n return commands.toggleList(this.name, this.options.itemTypeName)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../extension-list-item/src/list-item.ts","../../extension-text-style/src/text-style.ts","../src/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface ListItemOptions {\n HTMLAttributes: Record<string, any>,\n}\n\nexport const ListItem = Node.create<ListItemOptions>({\n name: 'listItem',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'paragraph block*',\n\n defining: true,\n\n parseHTML() {\n return [\n {\n tag: 'li',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addKeyboardShortcuts() {\n return {\n Enter: () => this.editor.commands.splitListItem(this.name),\n Tab: () => this.editor.commands.sinkListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n }\n },\n})\n","import {\n getMarkAttributes,\n Mark,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface TextStyleOptions {\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textStyle: {\n /**\n * Remove spans without inline style attributes.\n */\n removeEmptyTextStyle: () => ReturnType,\n }\n }\n}\n\nexport const TextStyle = Mark.create<TextStyleOptions>({\n name: 'textStyle',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span',\n getAttrs: element => {\n const hasStyles = (element as HTMLElement).hasAttribute('style')\n\n if (!hasStyles) {\n return false\n }\n\n return {}\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n removeEmptyTextStyle: () => ({ state, commands }) => {\n const attributes = getMarkAttributes(state, this.type)\n const hasStyles = Object.entries(attributes).some(([, value]) => !!value)\n\n if (hasStyles) {\n return true\n }\n\n return commands.unsetMark(this.name)\n },\n }\n },\n\n})\n","import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nimport ListItem from '../../extension-list-item/src'\nimport TextStyle from '../../extension-text-style/src'\n\nexport interface BulletListOptions {\n itemTypeName: string,\n HTMLAttributes: Record<string, any>,\n keepMarks: boolean,\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\nexport const inputRegex = /^\\s*([-+*])\\s$/\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 [\n { tag: 'ul' },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList: () => ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).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: inputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => { return this.editor.getAttributes(TextStyle.name) },\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})\n"],"names":["Node","mergeAttributes","Mark","getMarkAttributes","wrappingInputRule"],"mappings":";;;;;;AAMO,MAAM,QAAQ,GAAGA,SAAI,CAAC,MAAM,CAAkB;AACnD,IAAA,IAAI,EAAE,UAAU;IAEhB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;AAED,IAAA,OAAO,EAAE,kBAAkB;AAE3B,IAAA,QAAQ,EAAE,IAAI;IAEd,SAAS,GAAA;QACP,OAAO;AACL,YAAA;AACE,gBAAA,GAAG,EAAE,IAAI;AACV,aAAA;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;AAC3B,QAAA,OAAO,CAAC,IAAI,EAAEC,oBAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;KAC/E;IAED,oBAAoB,GAAA;QAClB,OAAO;AACL,YAAA,KAAK,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;AAC1D,YAAA,GAAG,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IA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AC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;aACzF;SACF,CAAA;KACF;IAED,oBAAoB,GAAA;QAClB,OAAO;YACL,aAAa,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE;SAC7D,CAAA;KACF;IAED,aAAa,GAAA;QACX,IAAI,SAAS,GAAGG,sBAAiB,CAAC;AAChC,YAAA,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,IAAI,CAAC,IAAI;AAChB,SAAA,CAAC,CAAA;QAEF,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YACzD,SAAS,GAAGA,sBAAiB,CAAC;AAC5B,gBAAA,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,gBAAA,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;AACjC,gBAAA,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;AAC3C,gBAAA,aAAa,EAAE,MAAQ,EAAA,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA,EAAE;gBACzE,MAAM,EAAE,IAAI,CAAC,MAAM;AACpB,aAAA,CAAC,CAAA;AACH,SAAA;QACD,OAAO;YACL,SAAS;SACV,CAAA;KACF;AACF,CAAA;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,70 @@
|
|
|
1
|
-
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
|
|
1
|
+
import { Node, mergeAttributes, Mark, getMarkAttributes, wrappingInputRule } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
const ListItem = Node.create({
|
|
4
|
+
name: 'listItem',
|
|
5
|
+
addOptions() {
|
|
6
|
+
return {
|
|
7
|
+
HTMLAttributes: {},
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
content: 'paragraph block*',
|
|
11
|
+
defining: true,
|
|
12
|
+
parseHTML() {
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
tag: 'li',
|
|
16
|
+
},
|
|
17
|
+
];
|
|
18
|
+
},
|
|
19
|
+
renderHTML({ HTMLAttributes }) {
|
|
20
|
+
return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
21
|
+
},
|
|
22
|
+
addKeyboardShortcuts() {
|
|
23
|
+
return {
|
|
24
|
+
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
25
|
+
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
26
|
+
'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const TextStyle = Mark.create({
|
|
32
|
+
name: 'textStyle',
|
|
33
|
+
addOptions() {
|
|
34
|
+
return {
|
|
35
|
+
HTMLAttributes: {},
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
parseHTML() {
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
tag: 'span',
|
|
42
|
+
getAttrs: element => {
|
|
43
|
+
const hasStyles = element.hasAttribute('style');
|
|
44
|
+
if (!hasStyles) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return {};
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
renderHTML({ HTMLAttributes }) {
|
|
53
|
+
return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
54
|
+
},
|
|
55
|
+
addCommands() {
|
|
56
|
+
return {
|
|
57
|
+
removeEmptyTextStyle: () => ({ state, commands }) => {
|
|
58
|
+
const attributes = getMarkAttributes(state, this.type);
|
|
59
|
+
const hasStyles = Object.entries(attributes).some(([, value]) => !!value);
|
|
60
|
+
if (hasStyles) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return commands.unsetMark(this.name);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
2
68
|
|
|
3
69
|
const inputRegex = /^\s*([-+*])\s$/;
|
|
4
70
|
const BulletList = Node.create({
|
|
@@ -7,6 +73,8 @@ const BulletList = Node.create({
|
|
|
7
73
|
return {
|
|
8
74
|
itemTypeName: 'listItem',
|
|
9
75
|
HTMLAttributes: {},
|
|
76
|
+
keepMarks: false,
|
|
77
|
+
keepAttributes: false,
|
|
10
78
|
};
|
|
11
79
|
},
|
|
12
80
|
group: 'block list',
|
|
@@ -23,8 +91,11 @@ const BulletList = Node.create({
|
|
|
23
91
|
},
|
|
24
92
|
addCommands() {
|
|
25
93
|
return {
|
|
26
|
-
toggleBulletList: () => ({ commands }) => {
|
|
27
|
-
|
|
94
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
95
|
+
if (this.options.keepAttributes) {
|
|
96
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run();
|
|
97
|
+
}
|
|
98
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
28
99
|
},
|
|
29
100
|
};
|
|
30
101
|
},
|
|
@@ -34,11 +105,22 @@ const BulletList = Node.create({
|
|
|
34
105
|
};
|
|
35
106
|
},
|
|
36
107
|
addInputRules() {
|
|
37
|
-
|
|
38
|
-
|
|
108
|
+
let inputRule = wrappingInputRule({
|
|
109
|
+
find: inputRegex,
|
|
110
|
+
type: this.type,
|
|
111
|
+
});
|
|
112
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
113
|
+
inputRule = wrappingInputRule({
|
|
39
114
|
find: inputRegex,
|
|
40
115
|
type: this.type,
|
|
41
|
-
|
|
116
|
+
keepMarks: this.options.keepMarks,
|
|
117
|
+
keepAttributes: this.options.keepAttributes,
|
|
118
|
+
getAttributes: () => { return this.editor.getAttributes(TextStyle.name); },
|
|
119
|
+
editor: this.editor,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return [
|
|
123
|
+
inputRule,
|
|
42
124
|
];
|
|
43
125
|
},
|
|
44
126
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nexport interface BulletListOptions {\n itemTypeName: string,\n HTMLAttributes: Record<string, any>,\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\nexport const inputRegex = /^\\s*([-+*])\\s$/\n\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [\n { tag: 'ul' },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList: () => ({ commands }) => {\n return commands.toggleList(this.name, this.options.itemTypeName)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../extension-list-item/src/list-item.ts","../../extension-text-style/src/text-style.ts","../src/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface ListItemOptions {\n HTMLAttributes: Record<string, any>,\n}\n\nexport const ListItem = Node.create<ListItemOptions>({\n name: 'listItem',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'paragraph block*',\n\n defining: true,\n\n parseHTML() {\n return [\n {\n tag: 'li',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addKeyboardShortcuts() {\n return {\n Enter: () => this.editor.commands.splitListItem(this.name),\n Tab: () => this.editor.commands.sinkListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n }\n },\n})\n","import {\n getMarkAttributes,\n Mark,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface TextStyleOptions {\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textStyle: {\n /**\n * Remove spans without inline style attributes.\n */\n removeEmptyTextStyle: () => ReturnType,\n }\n }\n}\n\nexport const TextStyle = Mark.create<TextStyleOptions>({\n name: 'textStyle',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span',\n getAttrs: element => {\n const hasStyles = (element as HTMLElement).hasAttribute('style')\n\n if (!hasStyles) {\n return false\n }\n\n return {}\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n removeEmptyTextStyle: () => ({ state, commands }) => {\n const attributes = getMarkAttributes(state, this.type)\n const hasStyles = Object.entries(attributes).some(([, value]) => !!value)\n\n if (hasStyles) {\n return true\n }\n\n return commands.unsetMark(this.name)\n },\n }\n },\n\n})\n","import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nimport ListItem from '../../extension-list-item/src'\nimport TextStyle from '../../extension-text-style/src'\n\nexport interface BulletListOptions {\n itemTypeName: string,\n HTMLAttributes: Record<string, any>,\n keepMarks: boolean,\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\nexport const inputRegex = /^\\s*([-+*])\\s$/\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 [\n { tag: 'ul' },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList: () => ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).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: inputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => { return this.editor.getAttributes(TextStyle.name) },\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})\n"],"names":[],"mappings":";;AAMO,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAkB;AACnD,IAAA,IAAI,EAAE,UAAU;IAEhB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,cAAc,EAAE,EAAE;SACnB,CAAA;KACF;AAED,IAAA,OAAO,EAAE,kBAAkB;AAE3B,IAAA,QAAQ,EAAE,IAAI;IAEd,SAAS,GAAA;QACP,OAAO;AACL,YAAA;AACE,gBAAA,GAAG,EAAE,IAAI;AACV,aAAA;SACF,CAAA;KACF;IAED,UAAU,CAAC,EAAE,cAAc,EAAE,EAAA;AAC3B,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|
package/dist/index.umd.js
CHANGED
|
@@ -4,6 +4,72 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-bullet-list"] = {}, global.core));
|
|
5
5
|
})(this, (function (exports, core) { 'use strict';
|
|
6
6
|
|
|
7
|
+
const ListItem = core.Node.create({
|
|
8
|
+
name: 'listItem',
|
|
9
|
+
addOptions() {
|
|
10
|
+
return {
|
|
11
|
+
HTMLAttributes: {},
|
|
12
|
+
};
|
|
13
|
+
},
|
|
14
|
+
content: 'paragraph block*',
|
|
15
|
+
defining: true,
|
|
16
|
+
parseHTML() {
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
tag: 'li',
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
},
|
|
23
|
+
renderHTML({ HTMLAttributes }) {
|
|
24
|
+
return ['li', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
25
|
+
},
|
|
26
|
+
addKeyboardShortcuts() {
|
|
27
|
+
return {
|
|
28
|
+
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
29
|
+
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
30
|
+
'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const TextStyle = core.Mark.create({
|
|
36
|
+
name: 'textStyle',
|
|
37
|
+
addOptions() {
|
|
38
|
+
return {
|
|
39
|
+
HTMLAttributes: {},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
parseHTML() {
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
tag: 'span',
|
|
46
|
+
getAttrs: element => {
|
|
47
|
+
const hasStyles = element.hasAttribute('style');
|
|
48
|
+
if (!hasStyles) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return {};
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
renderHTML({ HTMLAttributes }) {
|
|
57
|
+
return ['span', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
58
|
+
},
|
|
59
|
+
addCommands() {
|
|
60
|
+
return {
|
|
61
|
+
removeEmptyTextStyle: () => ({ state, commands }) => {
|
|
62
|
+
const attributes = core.getMarkAttributes(state, this.type);
|
|
63
|
+
const hasStyles = Object.entries(attributes).some(([, value]) => !!value);
|
|
64
|
+
if (hasStyles) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return commands.unsetMark(this.name);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
7
73
|
const inputRegex = /^\s*([-+*])\s$/;
|
|
8
74
|
const BulletList = core.Node.create({
|
|
9
75
|
name: 'bulletList',
|
|
@@ -11,6 +77,8 @@
|
|
|
11
77
|
return {
|
|
12
78
|
itemTypeName: 'listItem',
|
|
13
79
|
HTMLAttributes: {},
|
|
80
|
+
keepMarks: false,
|
|
81
|
+
keepAttributes: false,
|
|
14
82
|
};
|
|
15
83
|
},
|
|
16
84
|
group: 'block list',
|
|
@@ -27,8 +95,11 @@
|
|
|
27
95
|
},
|
|
28
96
|
addCommands() {
|
|
29
97
|
return {
|
|
30
|
-
toggleBulletList: () => ({ commands }) => {
|
|
31
|
-
|
|
98
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
99
|
+
if (this.options.keepAttributes) {
|
|
100
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run();
|
|
101
|
+
}
|
|
102
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
32
103
|
},
|
|
33
104
|
};
|
|
34
105
|
},
|
|
@@ -38,11 +109,22 @@
|
|
|
38
109
|
};
|
|
39
110
|
},
|
|
40
111
|
addInputRules() {
|
|
41
|
-
|
|
42
|
-
|
|
112
|
+
let inputRule = core.wrappingInputRule({
|
|
113
|
+
find: inputRegex,
|
|
114
|
+
type: this.type,
|
|
115
|
+
});
|
|
116
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
117
|
+
inputRule = core.wrappingInputRule({
|
|
43
118
|
find: inputRegex,
|
|
44
119
|
type: this.type,
|
|
45
|
-
|
|
120
|
+
keepMarks: this.options.keepMarks,
|
|
121
|
+
keepAttributes: this.options.keepAttributes,
|
|
122
|
+
getAttributes: () => { return this.editor.getAttributes(TextStyle.name); },
|
|
123
|
+
editor: this.editor,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return [
|
|
127
|
+
inputRule,
|
|
46
128
|
];
|
|
47
129
|
},
|
|
48
130
|
});
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nexport interface BulletListOptions {\n itemTypeName: string,\n HTMLAttributes: Record<string, any>,\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\nexport const inputRegex = /^\\s*([-+*])\\s$/\n\nexport const BulletList = Node.create<BulletListOptions>({\n name: 'bulletList',\n\n addOptions() {\n return {\n itemTypeName: 'listItem',\n HTMLAttributes: {},\n }\n },\n\n group: 'block list',\n\n content() {\n return `${this.options.itemTypeName}+`\n },\n\n parseHTML() {\n return [\n { tag: 'ul' },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList: () => ({ commands }) => {\n return commands.toggleList(this.name, this.options.itemTypeName)\n },\n }\n },\n\n addKeyboardShortcuts() {\n return {\n 'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),\n }\n },\n\n addInputRules() {\n
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../../extension-list-item/src/list-item.ts","../../extension-text-style/src/text-style.ts","../src/bullet-list.ts"],"sourcesContent":["import { mergeAttributes, Node } from '@tiptap/core'\n\nexport interface ListItemOptions {\n HTMLAttributes: Record<string, any>,\n}\n\nexport const ListItem = Node.create<ListItemOptions>({\n name: 'listItem',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n content: 'paragraph block*',\n\n defining: true,\n\n parseHTML() {\n return [\n {\n tag: 'li',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['li', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addKeyboardShortcuts() {\n return {\n Enter: () => this.editor.commands.splitListItem(this.name),\n Tab: () => this.editor.commands.sinkListItem(this.name),\n 'Shift-Tab': () => this.editor.commands.liftListItem(this.name),\n }\n },\n})\n","import {\n getMarkAttributes,\n Mark,\n mergeAttributes,\n} from '@tiptap/core'\n\nexport interface TextStyleOptions {\n HTMLAttributes: Record<string, any>,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n textStyle: {\n /**\n * Remove spans without inline style attributes.\n */\n removeEmptyTextStyle: () => ReturnType,\n }\n }\n}\n\nexport const TextStyle = Mark.create<TextStyleOptions>({\n name: 'textStyle',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span',\n getAttrs: element => {\n const hasStyles = (element as HTMLElement).hasAttribute('style')\n\n if (!hasStyles) {\n return false\n }\n\n return {}\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n removeEmptyTextStyle: () => ({ state, commands }) => {\n const attributes = getMarkAttributes(state, this.type)\n const hasStyles = Object.entries(attributes).some(([, value]) => !!value)\n\n if (hasStyles) {\n return true\n }\n\n return commands.unsetMark(this.name)\n },\n }\n },\n\n})\n","import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nimport ListItem from '../../extension-list-item/src'\nimport TextStyle from '../../extension-text-style/src'\n\nexport interface BulletListOptions {\n itemTypeName: string,\n HTMLAttributes: Record<string, any>,\n keepMarks: boolean,\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\nexport const inputRegex = /^\\s*([-+*])\\s$/\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 [\n { tag: 'ul' },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleBulletList: () => ({ commands, chain }) => {\n if (this.options.keepAttributes) {\n return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).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: inputRegex,\n type: this.type,\n })\n\n if (this.options.keepMarks || this.options.keepAttributes) {\n inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n keepMarks: this.options.keepMarks,\n keepAttributes: this.options.keepAttributes,\n getAttributes: () => { return this.editor.getAttributes(TextStyle.name) },\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})\n"],"names":["Node","mergeAttributes","Mark","getMar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IAAI,EAAE,UAAU;kBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;EACf,gBAAA,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;EACjC,gBAAA,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;EAC3C,gBAAA,aAAa,EAAE,MAAQ,EAAA,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA,EAAE;kBACzE,MAAM,EAAE,IAAI,CAAC,MAAM;EACpB,aAAA,CAAC,CAAA;EACH,SAAA;UACD,OAAO;cACL,SAAS;WACV,CAAA;OACF;EACF,CAAA;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Mark } from '@tiptap/core';
|
|
2
|
+
export interface TextStyleOptions {
|
|
3
|
+
HTMLAttributes: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
declare module '@tiptap/core' {
|
|
6
|
+
interface Commands<ReturnType> {
|
|
7
|
+
textStyle: {
|
|
8
|
+
/**
|
|
9
|
+
* Remove spans without inline style attributes.
|
|
10
|
+
*/
|
|
11
|
+
removeEmptyTextStyle: () => ReturnType;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export declare const TextStyle: Mark<TextStyleOptions, any>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-bullet-list",
|
|
3
3
|
"description": "bullet list extension for tiptap",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.219",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@tiptap/core": "^2.0.0-beta.209"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
35
|
+
"@tiptap/core": "^2.0.0-beta.219"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|
package/src/bullet-list.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
|
|
2
2
|
|
|
3
|
+
import ListItem from '../../extension-list-item/src'
|
|
4
|
+
import TextStyle from '../../extension-text-style/src'
|
|
5
|
+
|
|
3
6
|
export interface BulletListOptions {
|
|
4
7
|
itemTypeName: string,
|
|
5
8
|
HTMLAttributes: Record<string, any>,
|
|
9
|
+
keepMarks: boolean,
|
|
10
|
+
keepAttributes: boolean,
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
declare module '@tiptap/core' {
|
|
@@ -25,6 +30,8 @@ export const BulletList = Node.create<BulletListOptions>({
|
|
|
25
30
|
return {
|
|
26
31
|
itemTypeName: 'listItem',
|
|
27
32
|
HTMLAttributes: {},
|
|
33
|
+
keepMarks: false,
|
|
34
|
+
keepAttributes: false,
|
|
28
35
|
}
|
|
29
36
|
},
|
|
30
37
|
|
|
@@ -46,8 +53,11 @@ export const BulletList = Node.create<BulletListOptions>({
|
|
|
46
53
|
|
|
47
54
|
addCommands() {
|
|
48
55
|
return {
|
|
49
|
-
toggleBulletList: () => ({ commands }) => {
|
|
50
|
-
|
|
56
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
57
|
+
if (this.options.keepAttributes) {
|
|
58
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run()
|
|
59
|
+
}
|
|
60
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
|
|
51
61
|
},
|
|
52
62
|
}
|
|
53
63
|
},
|
|
@@ -59,11 +69,23 @@ export const BulletList = Node.create<BulletListOptions>({
|
|
|
59
69
|
},
|
|
60
70
|
|
|
61
71
|
addInputRules() {
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
let inputRule = wrappingInputRule({
|
|
73
|
+
find: inputRegex,
|
|
74
|
+
type: this.type,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
78
|
+
inputRule = wrappingInputRule({
|
|
64
79
|
find: inputRegex,
|
|
65
80
|
type: this.type,
|
|
66
|
-
|
|
81
|
+
keepMarks: this.options.keepMarks,
|
|
82
|
+
keepAttributes: this.options.keepAttributes,
|
|
83
|
+
getAttributes: () => { return this.editor.getAttributes(TextStyle.name) },
|
|
84
|
+
editor: this.editor,
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
return [
|
|
88
|
+
inputRule,
|
|
67
89
|
]
|
|
68
90
|
},
|
|
69
91
|
})
|