@tiptap/extension-ordered-list 2.8.0 → 2.9.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 +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +8 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/ordered-list.d.ts.map +1 -1
- package/package.json +3 -7
- package/src/ordered-list.ts +5 -4
package/dist/index.cjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@tiptap/core');
|
|
6
|
-
var extensionListItem = require('@tiptap/extension-list-item');
|
|
7
|
-
var extensionTextStyle = require('@tiptap/extension-text-style');
|
|
8
6
|
|
|
7
|
+
const ListItemName = 'listItem';
|
|
8
|
+
const TextStyleName = 'textStyle';
|
|
9
9
|
/**
|
|
10
10
|
* Matches an ordered list to a 1. on input (or any number followed by a dot).
|
|
11
11
|
*/
|
|
@@ -63,7 +63,7 @@ const OrderedList = core.Node.create({
|
|
|
63
63
|
return {
|
|
64
64
|
toggleOrderedList: () => ({ commands, chain }) => {
|
|
65
65
|
if (this.options.keepAttributes) {
|
|
66
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(
|
|
66
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
67
67
|
}
|
|
68
68
|
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
69
69
|
},
|
|
@@ -87,7 +87,7 @@ const OrderedList = core.Node.create({
|
|
|
87
87
|
type: this.type,
|
|
88
88
|
keepMarks: this.options.keepMarks,
|
|
89
89
|
keepAttributes: this.options.keepAttributes,
|
|
90
|
-
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(
|
|
90
|
+
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
91
91
|
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
92
92
|
editor: this.editor,
|
|
93
93
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/ordered-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/ordered-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface OrderedListOptions {\n /**\n * The node type name for list items.\n * @default 'listItem'\n * @example 'myListItem'\n */\n itemTypeName: string,\n\n /**\n * The HTML attributes for an ordered list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>,\n\n /**\n * Keep the marks when splitting a list item.\n * @default false\n * @example true\n */\n keepMarks: boolean,\n\n /**\n * Keep the attributes when splitting a list item.\n * @default false\n * @example true\n */\n keepAttributes: boolean,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n orderedList: {\n /**\n * Toggle an ordered list\n * @example editor.commands.toggleOrderedList()\n */\n toggleOrderedList: () => ReturnType,\n }\n }\n}\n\n/**\n * Matches an ordered list to a 1. on input (or any number followed by a dot).\n */\nexport const inputRegex = /^(\\d+)\\.\\s$/\n\n/**\n * This extension allows you to create ordered lists.\n * This requires the ListItem extension\n * @see https://www.tiptap.dev/api/nodes/ordered-list\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nexport const OrderedList = Node.create<OrderedListOptions>({\n name: 'orderedList',\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 addAttributes() {\n return {\n start: {\n default: 1,\n parseHTML: element => {\n return element.hasAttribute('start')\n ? parseInt(element.getAttribute('start') || '', 10)\n : 1\n },\n },\n type: {\n default: undefined,\n parseHTML: element => element.getAttribute('type'),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'ol',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const { start, ...attributesWithoutStart } = HTMLAttributes\n\n return start === 1\n ? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]\n : ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleOrderedList: () => ({ 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-7': () => this.editor.commands.toggleOrderedList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({ start: +match[1] }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\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: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})\n"],"names":["Node","mergeAttributes","wrappingInputRule"],"mappings":";;;;;;AAEA,MAAM,YAAY,GAAG,UAAU,CAAA;AAC/B,MAAM,aAAa,GAAG,WAAW,CAAA;AA4CjC;;AAEG;AACI,MAAM,UAAU,GAAG,cAAa;AAEvC;;;;;AAKG;AACU,MAAA,WAAW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iB,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;gBAC3C,aAAa,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC3F,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBAChF,MAAM,EAAE,IAAI,CAAC,MAAM;AACpB,aAAA,CAAC,CAAA;SACH;QACD,OAAO;YACL,SAAS;SACV,CAAA;KACF;AACF,CAAA;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Node, mergeAttributes, wrappingInputRule } from '@tiptap/core';
|
|
2
|
-
import { ListItem } from '@tiptap/extension-list-item';
|
|
3
|
-
import { TextStyle } from '@tiptap/extension-text-style';
|
|
4
2
|
|
|
3
|
+
const ListItemName = 'listItem';
|
|
4
|
+
const TextStyleName = 'textStyle';
|
|
5
5
|
/**
|
|
6
6
|
* Matches an ordered list to a 1. on input (or any number followed by a dot).
|
|
7
7
|
*/
|
|
@@ -59,7 +59,7 @@ const OrderedList = Node.create({
|
|
|
59
59
|
return {
|
|
60
60
|
toggleOrderedList: () => ({ commands, chain }) => {
|
|
61
61
|
if (this.options.keepAttributes) {
|
|
62
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(
|
|
62
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
63
63
|
}
|
|
64
64
|
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
65
65
|
},
|
|
@@ -83,7 +83,7 @@ const OrderedList = Node.create({
|
|
|
83
83
|
type: this.type,
|
|
84
84
|
keepMarks: this.options.keepMarks,
|
|
85
85
|
keepAttributes: this.options.keepAttributes,
|
|
86
|
-
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(
|
|
86
|
+
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
87
87
|
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
88
88
|
editor: this.editor,
|
|
89
89
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/ordered-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/ordered-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface OrderedListOptions {\n /**\n * The node type name for list items.\n * @default 'listItem'\n * @example 'myListItem'\n */\n itemTypeName: string,\n\n /**\n * The HTML attributes for an ordered list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>,\n\n /**\n * Keep the marks when splitting a list item.\n * @default false\n * @example true\n */\n keepMarks: boolean,\n\n /**\n * Keep the attributes when splitting a list item.\n * @default false\n * @example true\n */\n keepAttributes: boolean,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n orderedList: {\n /**\n * Toggle an ordered list\n * @example editor.commands.toggleOrderedList()\n */\n toggleOrderedList: () => ReturnType,\n }\n }\n}\n\n/**\n * Matches an ordered list to a 1. on input (or any number followed by a dot).\n */\nexport const inputRegex = /^(\\d+)\\.\\s$/\n\n/**\n * This extension allows you to create ordered lists.\n * This requires the ListItem extension\n * @see https://www.tiptap.dev/api/nodes/ordered-list\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nexport const OrderedList = Node.create<OrderedListOptions>({\n name: 'orderedList',\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 addAttributes() {\n return {\n start: {\n default: 1,\n parseHTML: element => {\n return element.hasAttribute('start')\n ? parseInt(element.getAttribute('start') || '', 10)\n : 1\n },\n },\n type: {\n default: undefined,\n parseHTML: element => element.getAttribute('type'),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'ol',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const { start, ...attributesWithoutStart } = HTMLAttributes\n\n return start === 1\n ? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]\n : ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleOrderedList: () => ({ 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-7': () => this.editor.commands.toggleOrderedList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({ start: +match[1] }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\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: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +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U,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACjF,SAAA,CAAC,CAAA;AAEF,QAAA,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YACzD,SAAS,GAAG,iBAAiB,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;gBAC3C,aAAa,EAAE,KAAK,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC3F,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBAChF,MAAM,EAAE,IAAI,CAAC,MAAM;AACpB,aAAA,CAAC,CAAA;SACH;QACD,OAAO;YACL,SAAS;SACV,CAAA;KACF;AACF,CAAA;;;;"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-ordered-list"] = {}, global.core
|
|
5
|
-
})(this, (function (exports, core
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-ordered-list"] = {}, global.core));
|
|
5
|
+
})(this, (function (exports, core) { 'use strict';
|
|
6
6
|
|
|
7
|
+
const ListItemName = 'listItem';
|
|
8
|
+
const TextStyleName = 'textStyle';
|
|
7
9
|
/**
|
|
8
10
|
* Matches an ordered list to a 1. on input (or any number followed by a dot).
|
|
9
11
|
*/
|
|
@@ -61,7 +63,7 @@
|
|
|
61
63
|
return {
|
|
62
64
|
toggleOrderedList: () => ({ commands, chain }) => {
|
|
63
65
|
if (this.options.keepAttributes) {
|
|
64
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(
|
|
66
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run();
|
|
65
67
|
}
|
|
66
68
|
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks);
|
|
67
69
|
},
|
|
@@ -85,7 +87,7 @@
|
|
|
85
87
|
type: this.type,
|
|
86
88
|
keepMarks: this.options.keepMarks,
|
|
87
89
|
keepAttributes: this.options.keepAttributes,
|
|
88
|
-
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(
|
|
90
|
+
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
89
91
|
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
90
92
|
editor: this.editor,
|
|
91
93
|
});
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/ordered-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/ordered-list.ts"],"sourcesContent":["import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'\n\nconst ListItemName = 'listItem'\nconst TextStyleName = 'textStyle'\n\nexport interface OrderedListOptions {\n /**\n * The node type name for list items.\n * @default 'listItem'\n * @example 'myListItem'\n */\n itemTypeName: string,\n\n /**\n * The HTML attributes for an ordered list node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>,\n\n /**\n * Keep the marks when splitting a list item.\n * @default false\n * @example true\n */\n keepMarks: boolean,\n\n /**\n * Keep the attributes when splitting a list item.\n * @default false\n * @example true\n */\n keepAttributes: boolean,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n orderedList: {\n /**\n * Toggle an ordered list\n * @example editor.commands.toggleOrderedList()\n */\n toggleOrderedList: () => ReturnType,\n }\n }\n}\n\n/**\n * Matches an ordered list to a 1. on input (or any number followed by a dot).\n */\nexport const inputRegex = /^(\\d+)\\.\\s$/\n\n/**\n * This extension allows you to create ordered lists.\n * This requires the ListItem extension\n * @see https://www.tiptap.dev/api/nodes/ordered-list\n * @see https://www.tiptap.dev/api/nodes/list-item\n */\nexport const OrderedList = Node.create<OrderedListOptions>({\n name: 'orderedList',\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 addAttributes() {\n return {\n start: {\n default: 1,\n parseHTML: element => {\n return element.hasAttribute('start')\n ? parseInt(element.getAttribute('start') || '', 10)\n : 1\n },\n },\n type: {\n default: undefined,\n parseHTML: element => element.getAttribute('type'),\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'ol',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const { start, ...attributesWithoutStart } = HTMLAttributes\n\n return start === 1\n ? ['ol', mergeAttributes(this.options.HTMLAttributes, attributesWithoutStart), 0]\n : ['ol', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleOrderedList: () => ({ 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-7': () => this.editor.commands.toggleOrderedList(),\n }\n },\n\n addInputRules() {\n let inputRule = wrappingInputRule({\n find: inputRegex,\n type: this.type,\n getAttributes: match => ({ start: +match[1] }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\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: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),\n joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],\n editor: this.editor,\n })\n }\n return [\n inputRule,\n ]\n },\n})\n"],"names":["Node","mergeAttributes","wrappingInputRule"],"mappings":";;;;;;EAEA,MAAM,YAAY,GAAG,UAAU,CAAA;EAC/B,MAAM,aAAa,GAAG,WAAW,CAAA;EA4CjC;;EAEG;AACI,QAAM,UAAU,GAAG,cAAa;EAEvC;;;;;EAKG;AACU,QAAA,WAAW,GAAGA,SAAI,CAAC,MAAM,CAAqB;EACzD,IAAA,IAAI,EAAE,aAAa;MAEnB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,YAAY,EAAE,UAAU;EACxB,YAAA,cAAc,EAAE,EAAE;EAClB,YAAA,SAAS,EAAE,KAAK;EAChB,YAAA,cAAc,EAAE,KAAK;WACtB,CAAA;OACF;EAED,IAAA,KAAK,EAAE,YAAY;MAEnB,OAAO,GAAA;EACL,QAAA,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,GAAG,CAAA;OACvC;MAED,aAAa,GAAA;UACX,OAAO;EACL,YAAA,KAAK,EAAE;EACL,gBAAA,OAAO,EAAE,CAAC;kBACV,S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AC,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;kBAChF,MAAM,EAAE,IAAI,CAAC,MAAM;EACpB,aAAA,CAAC,CAAA;WACH;UACD,OAAO;cACL,SAAS;WACV,CAAA;OACF;EACF,CAAA;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../src/ordered-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAqB,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"ordered-list.d.ts","sourceRoot":"","sources":["../src/ordered-list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,IAAI,EAAqB,MAAM,cAAc,CAAA;AAKvE,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEpC;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,QAAQ,CAAC,UAAU;QAC3B,WAAW,EAAE;YACX;;;eAGG;YACH,iBAAiB,EAAE,MAAM,UAAU,CAAC;SACrC,CAAA;KACF;CACF;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,QAAgB,CAAA;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+BA2FtB,CAAA"}
|
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": "2.
|
|
4
|
+
"version": "2.9.1",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -29,14 +29,10 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tiptap/core": "^2.
|
|
33
|
-
"@tiptap/extension-list-item": "^2.8.0",
|
|
34
|
-
"@tiptap/extension-text-style": "^2.8.0"
|
|
32
|
+
"@tiptap/core": "^2.9.1"
|
|
35
33
|
},
|
|
36
34
|
"peerDependencies": {
|
|
37
|
-
"@tiptap/core": "^2.7.0"
|
|
38
|
-
"@tiptap/extension-list-item": "^2.7.0",
|
|
39
|
-
"@tiptap/extension-text-style": "^2.7.0"
|
|
35
|
+
"@tiptap/core": "^2.7.0"
|
|
40
36
|
},
|
|
41
37
|
"repository": {
|
|
42
38
|
"type": "git",
|
package/src/ordered-list.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core'
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
const ListItemName = 'listItem'
|
|
4
|
+
const TextStyleName = 'textStyle'
|
|
4
5
|
|
|
5
6
|
export interface OrderedListOptions {
|
|
6
7
|
/**
|
|
@@ -110,7 +111,7 @@ export const OrderedList = Node.create<OrderedListOptions>({
|
|
|
110
111
|
return {
|
|
111
112
|
toggleOrderedList: () => ({ commands, chain }) => {
|
|
112
113
|
if (this.options.keepAttributes) {
|
|
113
|
-
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(
|
|
114
|
+
return chain().toggleList(this.name, this.options.itemTypeName, this.options.keepMarks).updateAttributes(ListItemName, this.editor.getAttributes(TextStyleName)).run()
|
|
114
115
|
}
|
|
115
116
|
return commands.toggleList(this.name, this.options.itemTypeName, this.options.keepMarks)
|
|
116
117
|
},
|
|
@@ -137,7 +138,7 @@ export const OrderedList = Node.create<OrderedListOptions>({
|
|
|
137
138
|
type: this.type,
|
|
138
139
|
keepMarks: this.options.keepMarks,
|
|
139
140
|
keepAttributes: this.options.keepAttributes,
|
|
140
|
-
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(
|
|
141
|
+
getAttributes: match => ({ start: +match[1], ...this.editor.getAttributes(TextStyleName) }),
|
|
141
142
|
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1],
|
|
142
143
|
editor: this.editor,
|
|
143
144
|
})
|