@tiptap/extension-ordered-list 3.0.0-next.3 → 3.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +10 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -52
- package/dist/index.d.ts +2 -52
- package/dist/index.js +6 -87
- package/dist/index.js.map +1 -1
- package/package.json +10 -6
- package/src/index.ts +2 -2
- package/src/ordered-list.ts +0 -150
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Tiptap GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
# @tiptap/extension-ordered-list
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/@tiptap/extension-ordered-list)
|
|
3
4
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
5
|
[](https://www.npmjs.com/package/@tiptap/extension-ordered-list)
|
|
5
6
|
[](https://github.com/sponsors/ueberdosis)
|
|
6
7
|
|
|
7
8
|
## Introduction
|
|
8
|
-
|
|
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_.
|
|
9
11
|
|
|
10
12
|
## Official Documentation
|
|
13
|
+
|
|
11
14
|
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
12
15
|
|
|
13
16
|
## License
|
|
17
|
+
|
|
14
18
|
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
package/dist/index.cjs
CHANGED
|
@@ -18,102 +18,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
OrderedList: () => OrderedList,
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
OrderedList: () => import_extension_list2.OrderedList,
|
|
24
|
+
OrderedListOptions: () => import_extension_list2.OrderedListOptions,
|
|
25
|
+
default: () => index_default
|
|
26
26
|
});
|
|
27
|
-
module.exports = __toCommonJS(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var
|
|
31
|
-
var ListItemName = "listItem";
|
|
32
|
-
var TextStyleName = "textStyle";
|
|
33
|
-
var inputRegex = /^(\d+)\.\s$/;
|
|
34
|
-
var OrderedList = import_core.Node.create({
|
|
35
|
-
name: "orderedList",
|
|
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
|
-
addAttributes() {
|
|
49
|
-
return {
|
|
50
|
-
start: {
|
|
51
|
-
default: 1,
|
|
52
|
-
parseHTML: (element) => {
|
|
53
|
-
return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
type: {
|
|
57
|
-
default: void 0,
|
|
58
|
-
parseHTML: (element) => element.getAttribute("type")
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
},
|
|
62
|
-
parseHTML() {
|
|
63
|
-
return [
|
|
64
|
-
{
|
|
65
|
-
tag: "ol"
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
},
|
|
69
|
-
renderHTML({ HTMLAttributes }) {
|
|
70
|
-
const { start, ...attributesWithoutStart } = HTMLAttributes;
|
|
71
|
-
return start === 1 ? ["ol", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", (0, import_core.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
72
|
-
},
|
|
73
|
-
addCommands() {
|
|
74
|
-
return {
|
|
75
|
-
toggleOrderedList: () => ({ commands, chain }) => {
|
|
76
|
-
if (this.options.keepAttributes) {
|
|
77
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
78
|
-
}
|
|
79
|
-
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
addKeyboardShortcuts() {
|
|
84
|
-
return {
|
|
85
|
-
"Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
|
|
86
|
-
};
|
|
87
|
-
},
|
|
88
|
-
addInputRules() {
|
|
89
|
-
let inputRule = (0, import_core.wrappingInputRule)({
|
|
90
|
-
find: inputRegex,
|
|
91
|
-
type: this.type,
|
|
92
|
-
getAttributes: (match) => ({ start: +match[1] }),
|
|
93
|
-
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1]
|
|
94
|
-
});
|
|
95
|
-
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
96
|
-
inputRule = (0, import_core.wrappingInputRule)({
|
|
97
|
-
find: inputRegex,
|
|
98
|
-
type: this.type,
|
|
99
|
-
keepMarks: this.options.keepMarks,
|
|
100
|
-
keepAttributes: this.options.keepAttributes,
|
|
101
|
-
getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
102
|
-
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
103
|
-
editor: this.editor
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return [
|
|
107
|
-
inputRule
|
|
108
|
-
];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// src/index.ts
|
|
113
|
-
var src_default = OrderedList;
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_extension_list = require("@tiptap/extension-list");
|
|
29
|
+
var import_extension_list2 = require("@tiptap/extension-list");
|
|
30
|
+
var index_default = import_extension_list.OrderedList;
|
|
114
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
115
32
|
0 && (module.exports = {
|
|
116
33
|
OrderedList,
|
|
117
|
-
|
|
34
|
+
OrderedListOptions
|
|
118
35
|
});
|
|
119
36
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { OrderedList } from '@tiptap/extension-list'\n\nexport { OrderedList, OrderedListOptions } from '@tiptap/extension-list'\n\nexport default OrderedList\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;AAE5B,IAAAA,yBAAgD;AAEhD,IAAO,gBAAQ;","names":["import_extension_list"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,52 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface OrderedListOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The node type name for list items.
|
|
6
|
-
* @default 'listItem'
|
|
7
|
-
* @example 'myListItem'
|
|
8
|
-
*/
|
|
9
|
-
itemTypeName: string;
|
|
10
|
-
/**
|
|
11
|
-
* The HTML attributes for an ordered list node.
|
|
12
|
-
* @default {}
|
|
13
|
-
* @example { class: 'foo' }
|
|
14
|
-
*/
|
|
15
|
-
HTMLAttributes: Record<string, any>;
|
|
16
|
-
/**
|
|
17
|
-
* Keep the marks when splitting a list item.
|
|
18
|
-
* @default false
|
|
19
|
-
* @example true
|
|
20
|
-
*/
|
|
21
|
-
keepMarks: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Keep the attributes when splitting a list item.
|
|
24
|
-
* @default false
|
|
25
|
-
* @example true
|
|
26
|
-
*/
|
|
27
|
-
keepAttributes: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare module '@tiptap/core' {
|
|
30
|
-
interface Commands<ReturnType> {
|
|
31
|
-
orderedList: {
|
|
32
|
-
/**
|
|
33
|
-
* Toggle an ordered list
|
|
34
|
-
* @example editor.commands.toggleOrderedList()
|
|
35
|
-
*/
|
|
36
|
-
toggleOrderedList: () => ReturnType;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Matches an ordered list to a 1. on input (or any number followed by a dot).
|
|
42
|
-
*/
|
|
43
|
-
declare const inputRegex: RegExp;
|
|
44
|
-
/**
|
|
45
|
-
* This extension allows you to create ordered lists.
|
|
46
|
-
* This requires the ListItem extension
|
|
47
|
-
* @see https://www.tiptap.dev/api/nodes/ordered-list
|
|
48
|
-
* @see https://www.tiptap.dev/api/nodes/list-item
|
|
49
|
-
*/
|
|
50
|
-
declare const OrderedList: Node<OrderedListOptions, any>;
|
|
51
|
-
|
|
52
|
-
export { OrderedList, type OrderedListOptions, OrderedList as default, inputRegex };
|
|
1
|
+
import { OrderedList } from '@tiptap/extension-list';
|
|
2
|
+
export { OrderedList, OrderedListOptions, OrderedList as default } from '@tiptap/extension-list';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,52 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface OrderedListOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The node type name for list items.
|
|
6
|
-
* @default 'listItem'
|
|
7
|
-
* @example 'myListItem'
|
|
8
|
-
*/
|
|
9
|
-
itemTypeName: string;
|
|
10
|
-
/**
|
|
11
|
-
* The HTML attributes for an ordered list node.
|
|
12
|
-
* @default {}
|
|
13
|
-
* @example { class: 'foo' }
|
|
14
|
-
*/
|
|
15
|
-
HTMLAttributes: Record<string, any>;
|
|
16
|
-
/**
|
|
17
|
-
* Keep the marks when splitting a list item.
|
|
18
|
-
* @default false
|
|
19
|
-
* @example true
|
|
20
|
-
*/
|
|
21
|
-
keepMarks: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Keep the attributes when splitting a list item.
|
|
24
|
-
* @default false
|
|
25
|
-
* @example true
|
|
26
|
-
*/
|
|
27
|
-
keepAttributes: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare module '@tiptap/core' {
|
|
30
|
-
interface Commands<ReturnType> {
|
|
31
|
-
orderedList: {
|
|
32
|
-
/**
|
|
33
|
-
* Toggle an ordered list
|
|
34
|
-
* @example editor.commands.toggleOrderedList()
|
|
35
|
-
*/
|
|
36
|
-
toggleOrderedList: () => ReturnType;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Matches an ordered list to a 1. on input (or any number followed by a dot).
|
|
42
|
-
*/
|
|
43
|
-
declare const inputRegex: RegExp;
|
|
44
|
-
/**
|
|
45
|
-
* This extension allows you to create ordered lists.
|
|
46
|
-
* This requires the ListItem extension
|
|
47
|
-
* @see https://www.tiptap.dev/api/nodes/ordered-list
|
|
48
|
-
* @see https://www.tiptap.dev/api/nodes/list-item
|
|
49
|
-
*/
|
|
50
|
-
declare const OrderedList: Node<OrderedListOptions, any>;
|
|
51
|
-
|
|
52
|
-
export { OrderedList, type OrderedListOptions, OrderedList as default, inputRegex };
|
|
1
|
+
import { OrderedList } from '@tiptap/extension-list';
|
|
2
|
+
export { OrderedList, OrderedListOptions, OrderedList as default } from '@tiptap/extension-list';
|
package/dist/index.js
CHANGED
|
@@ -1,91 +1,10 @@
|
|
|
1
|
-
// src/ordered-list.ts
|
|
2
|
-
import { mergeAttributes, Node, wrappingInputRule } from "@tiptap/core";
|
|
3
|
-
var ListItemName = "listItem";
|
|
4
|
-
var TextStyleName = "textStyle";
|
|
5
|
-
var inputRegex = /^(\d+)\.\s$/;
|
|
6
|
-
var OrderedList = Node.create({
|
|
7
|
-
name: "orderedList",
|
|
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
|
-
addAttributes() {
|
|
21
|
-
return {
|
|
22
|
-
start: {
|
|
23
|
-
default: 1,
|
|
24
|
-
parseHTML: (element) => {
|
|
25
|
-
return element.hasAttribute("start") ? parseInt(element.getAttribute("start") || "", 10) : 1;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
type: {
|
|
29
|
-
default: void 0,
|
|
30
|
-
parseHTML: (element) => element.getAttribute("type")
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
parseHTML() {
|
|
35
|
-
return [
|
|
36
|
-
{
|
|
37
|
-
tag: "ol"
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
},
|
|
41
|
-
renderHTML({ HTMLAttributes }) {
|
|
42
|
-
const { start, ...attributesWithoutStart } = HTMLAttributes;
|
|
43
|
-
return start === 1 ? ["ol", mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0] : ["ol", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
44
|
-
},
|
|
45
|
-
addCommands() {
|
|
46
|
-
return {
|
|
47
|
-
toggleOrderedList: () => ({ commands, chain }) => {
|
|
48
|
-
if (this.options.keepAttributes) {
|
|
49
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
50
|
-
}
|
|
51
|
-
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
addKeyboardShortcuts() {
|
|
56
|
-
return {
|
|
57
|
-
"Mod-Shift-7": () => this.editor.commands.toggleOrderedList()
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
addInputRules() {
|
|
61
|
-
let inputRule = wrappingInputRule({
|
|
62
|
-
find: inputRegex,
|
|
63
|
-
type: this.type,
|
|
64
|
-
getAttributes: (match) => ({ start: +match[1] }),
|
|
65
|
-
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1]
|
|
66
|
-
});
|
|
67
|
-
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
68
|
-
inputRule = wrappingInputRule({
|
|
69
|
-
find: inputRegex,
|
|
70
|
-
type: this.type,
|
|
71
|
-
keepMarks: this.options.keepMarks,
|
|
72
|
-
keepAttributes: this.options.keepAttributes,
|
|
73
|
-
getAttributes: (match) => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
74
|
-
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
75
|
-
editor: this.editor
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return [
|
|
79
|
-
inputRule
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
1
|
// src/index.ts
|
|
85
|
-
|
|
2
|
+
import { OrderedList } from "@tiptap/extension-list";
|
|
3
|
+
import { OrderedList as OrderedList2, OrderedListOptions } from "@tiptap/extension-list";
|
|
4
|
+
var index_default = OrderedList;
|
|
86
5
|
export {
|
|
87
|
-
OrderedList,
|
|
88
|
-
|
|
89
|
-
|
|
6
|
+
OrderedList2 as OrderedList,
|
|
7
|
+
OrderedListOptions,
|
|
8
|
+
index_default as default
|
|
90
9
|
};
|
|
91
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { OrderedList } from '@tiptap/extension-list'\n\nexport { OrderedList, OrderedListOptions } from '@tiptap/extension-list'\n\nexport default OrderedList\n"],"mappings":";AAAA,SAAS,mBAAmB;AAE5B,SAAS,eAAAA,cAAa,0BAA0B;AAEhD,IAAO,gBAAQ;","names":["OrderedList"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-ordered-list",
|
|
3
3
|
"description": "ordered list extension for tiptap",
|
|
4
|
-
"version": "3.0.0-next.
|
|
4
|
+
"version": "3.0.0-next.5",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types":
|
|
18
|
+
"types": {
|
|
19
|
+
"import": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.d.cts"
|
|
21
|
+
},
|
|
19
22
|
"import": "./dist/index.js",
|
|
20
23
|
"require": "./dist/index.cjs"
|
|
21
24
|
}
|
|
@@ -28,10 +31,10 @@
|
|
|
28
31
|
"dist"
|
|
29
32
|
],
|
|
30
33
|
"devDependencies": {
|
|
31
|
-
"@tiptap/
|
|
34
|
+
"@tiptap/extension-list": "^3.0.0-next.5"
|
|
32
35
|
},
|
|
33
36
|
"peerDependencies": {
|
|
34
|
-
"@tiptap/
|
|
37
|
+
"@tiptap/extension-list": "^3.0.0-next.4"
|
|
35
38
|
},
|
|
36
39
|
"repository": {
|
|
37
40
|
"type": "git",
|
|
@@ -39,6 +42,7 @@
|
|
|
39
42
|
"directory": "packages/extension-ordered-list"
|
|
40
43
|
},
|
|
41
44
|
"scripts": {
|
|
42
|
-
"build": "tsup"
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
|
|
43
47
|
}
|
|
44
|
-
}
|
|
48
|
+
}
|
package/src/index.ts
CHANGED
package/src/ordered-list.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
|
|
2
|
-
|
|
3
|
-
const ListItemName = 'listItem'
|
|
4
|
-
const TextStyleName = 'textStyle'
|
|
5
|
-
|
|
6
|
-
export interface OrderedListOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The node type name for list items.
|
|
9
|
-
* @default 'listItem'
|
|
10
|
-
* @example 'myListItem'
|
|
11
|
-
*/
|
|
12
|
-
itemTypeName: string,
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The HTML attributes for an ordered list node.
|
|
16
|
-
* @default {}
|
|
17
|
-
* @example { class: 'foo' }
|
|
18
|
-
*/
|
|
19
|
-
HTMLAttributes: Record<string, any>,
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Keep the marks when splitting a list item.
|
|
23
|
-
* @default false
|
|
24
|
-
* @example true
|
|
25
|
-
*/
|
|
26
|
-
keepMarks: boolean,
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Keep the attributes when splitting a list item.
|
|
30
|
-
* @default false
|
|
31
|
-
* @example true
|
|
32
|
-
*/
|
|
33
|
-
keepAttributes: boolean,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
declare module '@tiptap/core' {
|
|
37
|
-
interface Commands<ReturnType> {
|
|
38
|
-
orderedList: {
|
|
39
|
-
/**
|
|
40
|
-
* Toggle an ordered list
|
|
41
|
-
* @example editor.commands.toggleOrderedList()
|
|
42
|
-
*/
|
|
43
|
-
toggleOrderedList: () => ReturnType,
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Matches an ordered list to a 1. on input (or any number followed by a dot).
|
|
50
|
-
*/
|
|
51
|
-
export const inputRegex = /^(\d+)\.\s$/
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* This extension allows you to create ordered lists.
|
|
55
|
-
* This requires the ListItem extension
|
|
56
|
-
* @see https://www.tiptap.dev/api/nodes/ordered-list
|
|
57
|
-
* @see https://www.tiptap.dev/api/nodes/list-item
|
|
58
|
-
*/
|
|
59
|
-
export const OrderedList = Node.create<OrderedListOptions>({
|
|
60
|
-
name: 'orderedList',
|
|
61
|
-
|
|
62
|
-
addOptions() {
|
|
63
|
-
return {
|
|
64
|
-
itemTypeName: 'listItem',
|
|
65
|
-
HTMLAttributes: {},
|
|
66
|
-
keepMarks: false,
|
|
67
|
-
keepAttributes: false,
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
group: 'block list',
|
|
72
|
-
|
|
73
|
-
content() {
|
|
74
|
-
return `${this.options.itemTypeName}+`
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
addAttributes() {
|
|
78
|
-
return {
|
|
79
|
-
start: {
|
|
80
|
-
default: 1,
|
|
81
|
-
parseHTML: element => {
|
|
82
|
-
return element.hasAttribute('start')
|
|
83
|
-
? parseInt(element.getAttribute('start') || '', 10)
|
|
84
|
-
: 1
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
type: {
|
|
88
|
-
default: undefined,
|
|
89
|
-
parseHTML: element => element.getAttribute('type'),
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
parseHTML() {
|
|
95
|
-
return [
|
|
96
|
-
{
|
|
97
|
-
tag: 'ol',
|
|
98
|
-
},
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
renderHTML({ HTMLAttributes }) {
|
|
103
|
-
const { start, ...attributesWithoutStart } = HTMLAttributes
|
|
104
|
-
|
|
105
|
-
return start === 1
|
|
106
|
-
? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]
|
|
107
|
-
: ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
addCommands() {
|
|
111
|
-
return {
|
|
112
|
-
toggleOrderedList: () => ({ commands, chain }) => {
|
|
113
|
-
if (this.options.keepAttributes) {
|
|
114
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run()
|
|
115
|
-
}
|
|
116
|
-
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
|
|
117
|
-
},
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
addKeyboardShortcuts() {
|
|
122
|
-
return {
|
|
123
|
-
'Mod-Shift-7': () => this.editor.commands.toggleOrderedList(),
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
addInputRules() {
|
|
128
|
-
let inputRule = wrappingInputRule({
|
|
129
|
-
find: inputRegex,
|
|
130
|
-
type: this.type,
|
|
131
|
-
getAttributes: match => ({ start: +match[1] }),
|
|
132
|
-
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
if (this.options.keepMarks || this.options.keepAttributes) {
|
|
136
|
-
inputRule = wrappingInputRule({
|
|
137
|
-
find: inputRegex,
|
|
138
|
-
type: this.type,
|
|
139
|
-
keepMarks: this.options.keepMarks,
|
|
140
|
-
keepAttributes: this.options.keepAttributes,
|
|
141
|
-
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
142
|
-
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
143
|
-
editor: this.editor,
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
return [
|
|
147
|
-
inputRule,
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
|
-
})
|