@tiptap/extension-bullet-list 2.6.2 → 3.0.0-next.1
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 +95 -150
- package/dist/index.cjs.map +1 -1
- package/dist/{packages/extension-bullet-list/src/bullet-list.d.ts → index.d.cts} +6 -3
- package/dist/index.d.ts +51 -0
- package/dist/index.js +70 -147
- package/dist/index.js.map +1 -1
- package/package.json +6 -8
- package/src/bullet-list.ts +4 -4
- package/dist/index.umd.js +0 -160
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -163
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -344
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -452
- package/dist/packages/core/src/Node.d.ts +0 -612
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -16
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -16
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -14
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -14
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -253
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-bullet-list/src/index.d.ts +0 -3
- package/dist/packages/extension-list-item/src/index.d.ts +0 -3
- package/dist/packages/extension-list-item/src/list-item.d.ts +0 -26
- package/dist/packages/extension-text-style/src/index.d.ts +0 -3
- package/dist/packages/extension-text-style/src/text-style.d.ts +0 -26
package/dist/index.cjs
CHANGED
|
@@ -1,156 +1,101 @@
|
|
|
1
|
-
|
|
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);
|
|
2
19
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @see https://www.tiptap.dev/api/nodes/list-item
|
|
10
|
-
*/
|
|
11
|
-
const ListItem = core.Node.create({
|
|
12
|
-
name: 'listItem',
|
|
13
|
-
addOptions() {
|
|
14
|
-
return {
|
|
15
|
-
HTMLAttributes: {},
|
|
16
|
-
bulletListTypeName: 'bulletList',
|
|
17
|
-
orderedListTypeName: 'orderedList',
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
content: 'paragraph block*',
|
|
21
|
-
defining: true,
|
|
22
|
-
parseHTML() {
|
|
23
|
-
return [
|
|
24
|
-
{
|
|
25
|
-
tag: 'li',
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
},
|
|
29
|
-
renderHTML({ HTMLAttributes }) {
|
|
30
|
-
return ['li', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
31
|
-
},
|
|
32
|
-
addKeyboardShortcuts() {
|
|
33
|
-
return {
|
|
34
|
-
Enter: () => this.editor.commands.splitListItem(this.name),
|
|
35
|
-
Tab: () => this.editor.commands.sinkListItem(this.name),
|
|
36
|
-
'Shift-Tab': () => this.editor.commands.liftListItem(this.name),
|
|
37
|
-
};
|
|
38
|
-
},
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
BulletList: () => BulletList,
|
|
24
|
+
default: () => src_default,
|
|
25
|
+
inputRegex: () => inputRegex
|
|
39
26
|
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
28
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
removeEmptyTextStyle: () => ({ state, commands }) => {
|
|
74
|
-
const attributes = core.getMarkAttributes(state, this.type);
|
|
75
|
-
const hasStyles = Object.entries(attributes).some(([, value]) => !!value);
|
|
76
|
-
if (hasStyles) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
return commands.unsetMark(this.name);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Matches a bullet list to a dash or asterisk.
|
|
87
|
-
*/
|
|
88
|
-
const inputRegex = /^\s*([-+*])\s$/;
|
|
89
|
-
/**
|
|
90
|
-
* This extension allows you to create bullet lists.
|
|
91
|
-
* This requires the ListItem extension
|
|
92
|
-
* @see https://tiptap.dev/api/nodes/bullet-list
|
|
93
|
-
* @see https://tiptap.dev/api/nodes/list-item.
|
|
94
|
-
*/
|
|
95
|
-
const BulletList = core.Node.create({
|
|
96
|
-
name: 'bulletList',
|
|
97
|
-
addOptions() {
|
|
98
|
-
return {
|
|
99
|
-
itemTypeName: 'listItem',
|
|
100
|
-
HTMLAttributes: {},
|
|
101
|
-
keepMarks: false,
|
|
102
|
-
keepAttributes: false,
|
|
103
|
-
};
|
|
104
|
-
},
|
|
105
|
-
group: 'block list',
|
|
106
|
-
content() {
|
|
107
|
-
return `${this.options.itemTypeName}+`;
|
|
108
|
-
},
|
|
109
|
-
parseHTML() {
|
|
110
|
-
return [
|
|
111
|
-
{ tag: 'ul' },
|
|
112
|
-
];
|
|
113
|
-
},
|
|
114
|
-
renderHTML({ HTMLAttributes }) {
|
|
115
|
-
return ['ul', core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
116
|
-
},
|
|
117
|
-
addCommands() {
|
|
118
|
-
return {
|
|
119
|
-
toggleBulletList: () => ({ commands, chain }) => {
|
|
120
|
-
if (this.options.keepAttributes) {
|
|
121
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run();
|
|
122
|
-
}
|
|
123
|
-
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
addKeyboardShortcuts() {
|
|
128
|
-
return {
|
|
129
|
-
'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),
|
|
130
|
-
};
|
|
131
|
-
},
|
|
132
|
-
addInputRules() {
|
|
133
|
-
let inputRule = core.wrappingInputRule({
|
|
134
|
-
find: inputRegex,
|
|
135
|
-
type: this.type,
|
|
136
|
-
});
|
|
137
|
-
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
138
|
-
inputRule = core.wrappingInputRule({
|
|
139
|
-
find: inputRegex,
|
|
140
|
-
type: this.type,
|
|
141
|
-
keepMarks: this.options.keepMarks,
|
|
142
|
-
keepAttributes: this.options.keepAttributes,
|
|
143
|
-
getAttributes: () => { return this.editor.getAttributes(TextStyle.name); },
|
|
144
|
-
editor: this.editor,
|
|
145
|
-
});
|
|
29
|
+
// src/bullet-list.ts
|
|
30
|
+
var import_core = require("@tiptap/core");
|
|
31
|
+
var ListItemName = "listItem";
|
|
32
|
+
var TextStyleName = "textStyle";
|
|
33
|
+
var inputRegex = /^\s*([-+*])\s$/;
|
|
34
|
+
var BulletList = import_core.Node.create({
|
|
35
|
+
name: "bulletList",
|
|
36
|
+
addOptions() {
|
|
37
|
+
return {
|
|
38
|
+
itemTypeName: "listItem",
|
|
39
|
+
HTMLAttributes: {},
|
|
40
|
+
keepMarks: false,
|
|
41
|
+
keepAttributes: false
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
group: "block list",
|
|
45
|
+
content() {
|
|
46
|
+
return `${this.options.itemTypeName}+`;
|
|
47
|
+
},
|
|
48
|
+
parseHTML() {
|
|
49
|
+
return [
|
|
50
|
+
{ tag: "ul" }
|
|
51
|
+
];
|
|
52
|
+
},
|
|
53
|
+
renderHTML({ HTMLAttributes }) {
|
|
54
|
+
return ["ul", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
55
|
+
},
|
|
56
|
+
addCommands() {
|
|
57
|
+
return {
|
|
58
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
59
|
+
if (this.options.keepAttributes) {
|
|
60
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
146
61
|
}
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
62
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
addKeyboardShortcuts() {
|
|
67
|
+
return {
|
|
68
|
+
"Mod-Shift-8": () => this.editor.commands.toggleBulletList()
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
addInputRules() {
|
|
72
|
+
let inputRule = (0, import_core.wrappingInputRule)({
|
|
73
|
+
find: inputRegex,
|
|
74
|
+
type: this.type
|
|
75
|
+
});
|
|
76
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
77
|
+
inputRule = (0, import_core.wrappingInputRule)({
|
|
78
|
+
find: inputRegex,
|
|
79
|
+
type: this.type,
|
|
80
|
+
keepMarks: this.options.keepMarks,
|
|
81
|
+
keepAttributes: this.options.keepAttributes,
|
|
82
|
+
getAttributes: () => {
|
|
83
|
+
return this.editor.getAttributes(TextStyleName);
|
|
84
|
+
},
|
|
85
|
+
editor: this.editor
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return [
|
|
89
|
+
inputRule
|
|
90
|
+
];
|
|
91
|
+
}
|
|
151
92
|
});
|
|
152
93
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
94
|
+
// src/index.ts
|
|
95
|
+
var src_default = BulletList;
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
BulletList,
|
|
99
|
+
inputRegex
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 /**\n * The HTML attributes for a list item node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>,\n\n /**\n * The node type for bulletList nodes\n * @default 'bulletList'\n * @example 'myCustomBulletList'\n */\n bulletListTypeName: string\n\n /**\n * The node type for orderedList nodes\n * @default 'orderedList'\n * @example 'myCustomOrderedList'\n */\n orderedListTypeName: string\n}\n\n/**\n * This extension allows you to create list items.\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nexport const ListItem = Node.create<ListItemOptions>({\n name: 'listItem',\n\n addOptions() {\n return {\n HTMLAttributes: {},\n bulletListTypeName: 'bulletList',\n orderedListTypeName: 'orderedList',\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 /**\n * HTML attributes to add to the span element.\n * @default {}\n * @example { class: 'foo' }\n */\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 * @example editor.commands.removeEmptyTextStyle()\n */\n removeEmptyTextStyle: () => ReturnType,\n }\n }\n}\n\n/**\n * This extension allows you to create text styles. It is required by default\n * for the `textColor` and `backgroundColor` extensions.\n * @see https://www.tiptap.dev/api/marks/text-style\n */\nexport const TextStyle = Mark.create<TextStyleOptions>({\n name: 'textStyle',\n\n priority: 101,\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/index.js'\nimport TextStyle from '../../extension-text-style/src/index.js'\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 inputRegex = /^\\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 [\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":";;;;;;AAyBA;;;AAGG;AACI,MAAM,QAAQ,GAAGA,SAAI,CAAC,MAAM,CAAkB;AACnD,IAAA,IAAI,EAAE,UAAU;IAEhB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,cAAc,EAAE,EAAE;AAClB,YAAA,kBAAkB,EAAE,YAAY;AAChC,YAAA,mBAAmB,EAAE,aAAa;SACnC,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,IAAI,CAAC;AACvD,YAAA,WAAW,EAAE,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;SAChE,CAAA;KACF;AACF,CAAA,CAAC;;ACpCF;;;;AAIG;AACI,MAAM,SAAS,GAAGC,SAAI,CAAC,MAAM,CAAmB;AACrD,IA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AAgB,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;AAEF,QAAA,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;SACH;QACD,OAAO;YACL,SAAS;SACV,CAAA;KACF;AACF,CAAA;;;;;;"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/bullet-list.ts"],"sourcesContent":["import { BulletList } from './bullet-list.js'\n\nexport * from './bullet-list.js'\n\nexport default BulletList\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 inputRegex = /^\\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 [\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(ListItemName, this.editor.getAttributes(TextStyleName)).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(TextStyleName) },\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyD;AAEzD,IAAM,eAAe;AACrB,IAAM,gBAAgB;AA8Cf,IA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gBAAgB,KAAK,QAAQ;AAAA,QAC7B,eAAe,MAAM;AAAE,iBAAO,KAAK,OAAO,cAAc,aAAa;AAAA,QAAE;AAAA,QACvE,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AACA,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;ADtHD,IAAO,cAAQ;","names":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Node } from '@tiptap/core';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
interface BulletListOptions {
|
|
3
4
|
/**
|
|
4
5
|
* The node name for the list items
|
|
5
6
|
* @default 'listItem'
|
|
@@ -38,11 +39,13 @@ declare module '@tiptap/core' {
|
|
|
38
39
|
/**
|
|
39
40
|
* Matches a bullet list to a dash or asterisk.
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
declare const inputRegex: RegExp;
|
|
42
43
|
/**
|
|
43
44
|
* This extension allows you to create bullet lists.
|
|
44
45
|
* This requires the ListItem extension
|
|
45
46
|
* @see https://tiptap.dev/api/nodes/bullet-list
|
|
46
47
|
* @see https://tiptap.dev/api/nodes/list-item.
|
|
47
48
|
*/
|
|
48
|
-
|
|
49
|
+
declare const BulletList: Node<BulletListOptions, any>;
|
|
50
|
+
|
|
51
|
+
export { BulletList, type BulletListOptions, BulletList as default, inputRegex };
|
package/dist/index.d.ts
ADDED
|
@@ -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 inputRegex: 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, BulletList as default, inputRegex };
|
package/dist/index.js
CHANGED
|
@@ -1,150 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* This extension allows you to create text styles. It is required by default
|
|
39
|
-
* for the `textColor` and `backgroundColor` extensions.
|
|
40
|
-
* @see https://www.tiptap.dev/api/marks/text-style
|
|
41
|
-
*/
|
|
42
|
-
const TextStyle = Mark.create({
|
|
43
|
-
name: 'textStyle',
|
|
44
|
-
priority: 101,
|
|
45
|
-
addOptions() {
|
|
46
|
-
return {
|
|
47
|
-
HTMLAttributes: {},
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
parseHTML() {
|
|
51
|
-
return [
|
|
52
|
-
{
|
|
53
|
-
tag: 'span',
|
|
54
|
-
getAttrs: element => {
|
|
55
|
-
const hasStyles = element.hasAttribute('style');
|
|
56
|
-
if (!hasStyles) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
return {};
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
];
|
|
63
|
-
},
|
|
64
|
-
renderHTML({ HTMLAttributes }) {
|
|
65
|
-
return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
66
|
-
},
|
|
67
|
-
addCommands() {
|
|
68
|
-
return {
|
|
69
|
-
removeEmptyTextStyle: () => ({ state, commands }) => {
|
|
70
|
-
const attributes = getMarkAttributes(state, this.type);
|
|
71
|
-
const hasStyles = Object.entries(attributes).some(([, value]) => !!value);
|
|
72
|
-
if (hasStyles) {
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
return commands.unsetMark(this.name);
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Matches a bullet list to a dash or asterisk.
|
|
83
|
-
*/
|
|
84
|
-
const inputRegex = /^\s*([-+*])\s$/;
|
|
85
|
-
/**
|
|
86
|
-
* This extension allows you to create bullet lists.
|
|
87
|
-
* This requires the ListItem extension
|
|
88
|
-
* @see https://tiptap.dev/api/nodes/bullet-list
|
|
89
|
-
* @see https://tiptap.dev/api/nodes/list-item.
|
|
90
|
-
*/
|
|
91
|
-
const BulletList = Node.create({
|
|
92
|
-
name: 'bulletList',
|
|
93
|
-
addOptions() {
|
|
94
|
-
return {
|
|
95
|
-
itemTypeName: 'listItem',
|
|
96
|
-
HTMLAttributes: {},
|
|
97
|
-
keepMarks: false,
|
|
98
|
-
keepAttributes: false,
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
group: 'block list',
|
|
102
|
-
content() {
|
|
103
|
-
return `${this.options.itemTypeName}+`;
|
|
104
|
-
},
|
|
105
|
-
parseHTML() {
|
|
106
|
-
return [
|
|
107
|
-
{ tag: 'ul' },
|
|
108
|
-
];
|
|
109
|
-
},
|
|
110
|
-
renderHTML({ HTMLAttributes }) {
|
|
111
|
-
return ['ul', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
112
|
-
},
|
|
113
|
-
addCommands() {
|
|
114
|
-
return {
|
|
115
|
-
toggleBulletList: () => ({ commands, chain }) => {
|
|
116
|
-
if (this.options.keepAttributes) {
|
|
117
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run();
|
|
118
|
-
}
|
|
119
|
-
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
addKeyboardShortcuts() {
|
|
124
|
-
return {
|
|
125
|
-
'Mod-Shift-8': () => this.editor.commands.toggleBulletList(),
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
addInputRules() {
|
|
129
|
-
let inputRule = wrappingInputRule({
|
|
130
|
-
find: inputRegex,
|
|
131
|
-
type: this.type,
|
|
132
|
-
});
|
|
133
|
-
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
134
|
-
inputRule = wrappingInputRule({
|
|
135
|
-
find: inputRegex,
|
|
136
|
-
type: this.type,
|
|
137
|
-
keepMarks: this.options.keepMarks,
|
|
138
|
-
keepAttributes: this.options.keepAttributes,
|
|
139
|
-
getAttributes: () => { return this.editor.getAttributes(TextStyle.name); },
|
|
140
|
-
editor: this.editor,
|
|
141
|
-
});
|
|
1
|
+
// src/bullet-list.ts
|
|
2
|
+
import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
|
|
3
|
+
var ListItemName = "listItem";
|
|
4
|
+
var TextStyleName = "textStyle";
|
|
5
|
+
var inputRegex = /^\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 [
|
|
22
|
+
{ tag: "ul" }
|
|
23
|
+
];
|
|
24
|
+
},
|
|
25
|
+
renderHTML({ HTMLAttributes }) {
|
|
26
|
+
return ["ul", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
27
|
+
},
|
|
28
|
+
addCommands() {
|
|
29
|
+
return {
|
|
30
|
+
toggleBulletList: () => ({ commands, chain }) => {
|
|
31
|
+
if (this.options.keepAttributes) {
|
|
32
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
142
33
|
}
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
34
|
+
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
addKeyboardShortcuts() {
|
|
39
|
+
return {
|
|
40
|
+
"Mod-Shift-8": () => this.editor.commands.toggleBulletList()
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
addInputRules() {
|
|
44
|
+
let inputRule = wrappingInputRule({
|
|
45
|
+
find: inputRegex,
|
|
46
|
+
type: this.type
|
|
47
|
+
});
|
|
48
|
+
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
49
|
+
inputRule = wrappingInputRule({
|
|
50
|
+
find: inputRegex,
|
|
51
|
+
type: this.type,
|
|
52
|
+
keepMarks: this.options.keepMarks,
|
|
53
|
+
keepAttributes: this.options.keepAttributes,
|
|
54
|
+
getAttributes: () => {
|
|
55
|
+
return this.editor.getAttributes(TextStyleName);
|
|
56
|
+
},
|
|
57
|
+
editor: this.editor
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
inputRule
|
|
62
|
+
];
|
|
63
|
+
}
|
|
147
64
|
});
|
|
148
65
|
|
|
149
|
-
|
|
150
|
-
|
|
66
|
+
// src/index.ts
|
|
67
|
+
var src_default = BulletList;
|
|
68
|
+
export {
|
|
69
|
+
BulletList,
|
|
70
|
+
src_default as default,
|
|
71
|
+
inputRegex
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/bullet-list.ts","../src/index.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 inputRegex = /^\\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 [\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(ListItemName, this.editor.getAttributes(TextStyleName)).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(TextStyleName) },\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})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