@lofcz/platejs-list 53.0.2 → 53.4.10
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.js +1 -1
- package/dist/react/index.js +41 -2
- package/dist/{src-B6T8hhDs.js → src-D073vI9-.js} +261 -275
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as getListExpectedListStart, C as setIndentTodoNode, D as indentTodo, E as indentList, F as getSiblingList, I as normalizeListNotIndented, M as ListStyleType, N as ULIST_STYLE_TYPES, O as getNextList, P as getPreviousList, S as setListNodes, T as outdentList, _ as expandListItemsWithChildren, a as withList, b as setListSiblingNodes, c as toggleListByPathUnSet, d as toggleListSet, f as someTodoList, g as getListAbove, h as getSiblingListStyleType, i as BaseListPlugin, j as normalizeListStart, k as withInsertBreakList, l as toggleList, m as isOrderedList, n as OrderedListRules, o as withNormalizeList, p as someList, r as BulletedListRules, s as toggleListByPath, t as TaskListRules, u as toggleListUnset, v as getListChildren, w as setListNode, x as getListSiblings, y as areEqListStyleType } from "./src-D073vI9-.js";
|
|
2
2
|
|
|
3
3
|
export { BaseListPlugin, BulletedListRules, ListStyleType, OrderedListRules, TaskListRules, ULIST_STYLE_TYPES, areEqListStyleType, expandListItemsWithChildren, getListAbove, getListChildren, getListExpectedListStart, getListSiblings, getNextList, getPreviousList, getSiblingList, getSiblingListStyleType, indentList, indentTodo, isOrderedList, normalizeListNotIndented, normalizeListStart, outdentList, setIndentTodoNode, setListNode, setListNodes, setListSiblingNodes, someList, someTodoList, toggleList, toggleListByPath, toggleListByPathUnSet, toggleListSet, toggleListUnset, withInsertBreakList, withList, withNormalizeList };
|
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as ListStyleType, f as someTodoList, i as BaseListPlugin, l as toggleList, m as isOrderedList, p as someList } from "../src-D073vI9-.js";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
+
import React from "react";
|
|
3
4
|
import { toPlatePlugin, useEditorRef, useEditorSelector, useReadOnly } from "platejs/react";
|
|
4
5
|
|
|
5
6
|
//#region src/react/ListPlugin.tsx
|
|
6
7
|
/** Enables support for indented lists with React-specific features. */
|
|
7
|
-
const ListPlugin = toPlatePlugin(BaseListPlugin)
|
|
8
|
+
const ListPlugin = toPlatePlugin(BaseListPlugin, { render: { belowNodes: (props) => {
|
|
9
|
+
if (!props.element.listStyleType) return;
|
|
10
|
+
return (props$1) => /* @__PURE__ */ React.createElement(List, props$1);
|
|
11
|
+
} } });
|
|
12
|
+
function List(props) {
|
|
13
|
+
const $ = c(9);
|
|
14
|
+
const { listStart, listStyleType } = props.element;
|
|
15
|
+
const List$1 = isOrderedList(props.element) ? "ol" : "ul";
|
|
16
|
+
let t0;
|
|
17
|
+
if ($[0] !== listStyleType) {
|
|
18
|
+
t0 = {
|
|
19
|
+
listStyleType,
|
|
20
|
+
margin: 0,
|
|
21
|
+
padding: 0,
|
|
22
|
+
position: "relative"
|
|
23
|
+
};
|
|
24
|
+
$[0] = listStyleType;
|
|
25
|
+
$[1] = t0;
|
|
26
|
+
} else t0 = $[1];
|
|
27
|
+
let t1;
|
|
28
|
+
if ($[2] !== props.children) {
|
|
29
|
+
t1 = /* @__PURE__ */ React.createElement("li", null, props.children);
|
|
30
|
+
$[2] = props.children;
|
|
31
|
+
$[3] = t1;
|
|
32
|
+
} else t1 = $[3];
|
|
33
|
+
let t2;
|
|
34
|
+
if ($[4] !== List$1 || $[5] !== listStart || $[6] !== t0 || $[7] !== t1) {
|
|
35
|
+
t2 = /* @__PURE__ */ React.createElement(List$1, {
|
|
36
|
+
style: t0,
|
|
37
|
+
start: listStart
|
|
38
|
+
}, t1);
|
|
39
|
+
$[4] = List$1;
|
|
40
|
+
$[5] = listStart;
|
|
41
|
+
$[6] = t0;
|
|
42
|
+
$[7] = t1;
|
|
43
|
+
$[8] = t2;
|
|
44
|
+
} else t2 = $[8];
|
|
45
|
+
return t2;
|
|
46
|
+
}
|
|
8
47
|
|
|
9
48
|
//#endregion
|
|
10
49
|
//#region src/react/hooks/useListToolbarButton.ts
|
|
@@ -1,8 +1,87 @@
|
|
|
1
|
-
import { c } from "react-compiler-runtime";
|
|
2
|
-
import React from "react";
|
|
3
1
|
import { KEYS, NodeApi, PathApi, createRuleFactory, createTSlatePlugin, getInjectMatch, isDefined, isHtmlBlockElement, postCleanHtml, traverseHtmlElements } from "platejs";
|
|
4
2
|
import { setIndent } from "@platejs/indent";
|
|
5
3
|
|
|
4
|
+
//#region src/lib/normalizers/normalizeListNotIndented.ts
|
|
5
|
+
/** Unset listStyle, listStart if KEYS.indent is not defined. */
|
|
6
|
+
const normalizeListNotIndented = (editor, [node, path]) => {
|
|
7
|
+
if (!isDefined(node[KEYS.indent]) && (node[KEYS.listType] || node[KEYS.listStart])) {
|
|
8
|
+
editor.tf.unsetNodes([KEYS.listType, KEYS.listStart], { at: path });
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/lib/internal/isSameListSequence.ts
|
|
15
|
+
const getHeadingType = (editor, headingKey) => {
|
|
16
|
+
const getType = editor.getType;
|
|
17
|
+
return typeof getType === "function" ? getType.call(editor, headingKey) : headingKey;
|
|
18
|
+
};
|
|
19
|
+
const isHeadingListNode = (editor, node) => {
|
|
20
|
+
const type = node.type;
|
|
21
|
+
return typeof type === "string" && KEYS.heading.some((headingKey) => type === getHeadingType(editor, headingKey));
|
|
22
|
+
};
|
|
23
|
+
const isSameListSequence = (editor, siblingNode, currentNode) => siblingNode[KEYS.listType] === currentNode[KEYS.listType] && isHeadingListNode(editor, siblingNode) === isHeadingListNode(editor, currentNode);
|
|
24
|
+
const isListSequenceBoundary = (editor, siblingNode, currentNode) => {
|
|
25
|
+
const siblingListType = siblingNode[KEYS.listType];
|
|
26
|
+
return siblingNode[KEYS.indent] === currentNode[KEYS.indent] && siblingListType != null && siblingListType === currentNode[KEYS.listType] && isHeadingListNode(editor, siblingNode) !== isHeadingListNode(editor, currentNode);
|
|
27
|
+
};
|
|
28
|
+
const getListSequenceSiblingOptions = (editor, options) => {
|
|
29
|
+
const { breakQuery, query, ...rest } = options ?? {};
|
|
30
|
+
return {
|
|
31
|
+
...rest,
|
|
32
|
+
breakQuery: (siblingNode, currentNode) => isListSequenceBoundary(editor, siblingNode, currentNode) || !!breakQuery?.(siblingNode, currentNode),
|
|
33
|
+
query: (siblingNode, currentNode) => isSameListSequence(editor, siblingNode, currentNode) && (query ? !!query(siblingNode, currentNode) : true)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/lib/queries/getSiblingList.ts
|
|
39
|
+
/**
|
|
40
|
+
* Get the next sibling indent list node. Default query: the sibling node should
|
|
41
|
+
* have the same listStyleType.
|
|
42
|
+
*/
|
|
43
|
+
const getSiblingList = (_editor, [node, path], { breakOnEqIndentNeqListStyleType = true, breakOnListRestart = false, breakOnLowerIndent = true, breakQuery, eqIndent = true, getNextEntry, getPreviousEntry, query }) => {
|
|
44
|
+
if (!getPreviousEntry && !getNextEntry) return;
|
|
45
|
+
const getSiblingEntry = getNextEntry ?? getPreviousEntry;
|
|
46
|
+
let nextEntry = getSiblingEntry([node, path]);
|
|
47
|
+
while (true) {
|
|
48
|
+
if (!nextEntry) return;
|
|
49
|
+
const [nextNode, nextPath] = nextEntry;
|
|
50
|
+
const indent = node[KEYS.indent];
|
|
51
|
+
const nextIndent = nextNode[KEYS.indent];
|
|
52
|
+
if (breakQuery?.(nextNode, node)) return;
|
|
53
|
+
if (!isDefined(nextIndent)) return;
|
|
54
|
+
if (breakOnListRestart) {
|
|
55
|
+
if (getPreviousEntry && node[KEYS.listRestart]) return;
|
|
56
|
+
if (getNextEntry && nextNode[KEYS.listRestart]) return;
|
|
57
|
+
}
|
|
58
|
+
if (breakOnLowerIndent && nextIndent < indent) return;
|
|
59
|
+
if (breakOnEqIndentNeqListStyleType && nextIndent === indent && nextNode[KEYS.listType] !== node[KEYS.listType]) return;
|
|
60
|
+
let valid = !query || query(nextNode, node);
|
|
61
|
+
if (valid) {
|
|
62
|
+
valid = !eqIndent || nextIndent === indent;
|
|
63
|
+
if (valid) return [nextNode, nextPath];
|
|
64
|
+
}
|
|
65
|
+
nextEntry = getSiblingEntry(nextEntry);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/lib/queries/getPreviousList.ts
|
|
71
|
+
/** Get the previous indent list node. */
|
|
72
|
+
const getPreviousList = (editor, entry, options) => getSiblingList(editor, entry, {
|
|
73
|
+
getPreviousEntry: ([, currPath]) => {
|
|
74
|
+
const prevPath = PathApi.previous(currPath);
|
|
75
|
+
if (!prevPath) return;
|
|
76
|
+
const prevNode = NodeApi.get(editor, prevPath);
|
|
77
|
+
if (!prevNode) return;
|
|
78
|
+
return [prevNode, prevPath];
|
|
79
|
+
},
|
|
80
|
+
...options,
|
|
81
|
+
getNextEntry: void 0
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
6
85
|
//#region src/lib/types.ts
|
|
7
86
|
const ListStyleType = {
|
|
8
87
|
ArabicIndic: "arabic-indic",
|
|
@@ -71,229 +150,6 @@ const ULIST_STYLE_TYPES = [
|
|
|
71
150
|
ListStyleType.DisclosureClosed
|
|
72
151
|
];
|
|
73
152
|
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/lib/queries/areEqListStyleType.ts
|
|
76
|
-
const areEqListStyleType = (_editor, entries, { listStyleType = ListStyleType.Disc }) => {
|
|
77
|
-
let eqListStyleType = true;
|
|
78
|
-
for (const entry of entries) {
|
|
79
|
-
const [block] = entry;
|
|
80
|
-
if (listStyleType === KEYS.listTodo) {
|
|
81
|
-
if (!Object.hasOwn(block, KEYS.listChecked)) {
|
|
82
|
-
eqListStyleType = false;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
if (!block[KEYS.listType] || block[KEYS.listType] !== listStyleType) {
|
|
88
|
-
eqListStyleType = false;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return eqListStyleType;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/lib/queries/getListChildren.ts
|
|
97
|
-
/**
|
|
98
|
-
* Get all list items that are children of the current list item (have bigger
|
|
99
|
-
* indent). Stops when encountering an item with equal or lower indent.
|
|
100
|
-
*/
|
|
101
|
-
const getListChildren = (editor, entry) => {
|
|
102
|
-
const children = [];
|
|
103
|
-
const [node, path] = entry;
|
|
104
|
-
const parentIndent = node[KEYS.indent];
|
|
105
|
-
if (!isDefined(parentIndent) || !isDefined(node[KEYS.listType])) return children;
|
|
106
|
-
let currentPath = path;
|
|
107
|
-
while (true) {
|
|
108
|
-
const nextPath = PathApi.next(currentPath);
|
|
109
|
-
if (!nextPath) break;
|
|
110
|
-
const nextNode = NodeApi.get(editor, nextPath);
|
|
111
|
-
if (!nextNode) break;
|
|
112
|
-
const nextIndent = nextNode[KEYS.indent];
|
|
113
|
-
if (!isDefined(nextIndent) || !isDefined(nextNode[KEYS.listType])) break;
|
|
114
|
-
if (nextIndent <= parentIndent) break;
|
|
115
|
-
children.push([nextNode, nextPath]);
|
|
116
|
-
currentPath = nextPath;
|
|
117
|
-
}
|
|
118
|
-
return children;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
|
-
//#region src/lib/queries/expandListItemsWithChildren.ts
|
|
123
|
-
/**
|
|
124
|
-
* Expands a list of blocks to include list item children. For each list item in
|
|
125
|
-
* the input, adds all its children (items with bigger indent). Non-list blocks
|
|
126
|
-
* are kept as-is. Requires id to be set on the blocks.
|
|
127
|
-
*
|
|
128
|
-
* @returns Array of block entries with list items expanded to include their
|
|
129
|
-
* children
|
|
130
|
-
*/
|
|
131
|
-
const expandListItemsWithChildren = (editor, entries) => {
|
|
132
|
-
const expandedEntries = [];
|
|
133
|
-
const processedIds = /* @__PURE__ */ new Set();
|
|
134
|
-
entries.forEach((entry) => {
|
|
135
|
-
const [node] = entry;
|
|
136
|
-
if (processedIds.has(node.id)) return;
|
|
137
|
-
expandedEntries.push(entry);
|
|
138
|
-
processedIds.add(node.id);
|
|
139
|
-
if (isDefined(node[KEYS.listType]) && isDefined(node[KEYS.indent])) getListChildren(editor, entry).forEach((childEntry) => {
|
|
140
|
-
if (!processedIds.has(childEntry[0].id)) {
|
|
141
|
-
expandedEntries.push(childEntry);
|
|
142
|
-
processedIds.add(childEntry[0].id);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
return expandedEntries;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/lib/queries/getListAbove.ts
|
|
151
|
-
const getListAbove = (editor, options) => editor.api.above({
|
|
152
|
-
...options,
|
|
153
|
-
match: (node) => isDefined(node[KEYS.listType])
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region src/lib/queries/getSiblingList.ts
|
|
158
|
-
/**
|
|
159
|
-
* Get the next sibling indent list node. Default query: the sibling node should
|
|
160
|
-
* have the same listStyleType.
|
|
161
|
-
*/
|
|
162
|
-
const getSiblingList = (_editor, [node, path], { breakOnEqIndentNeqListStyleType = true, breakOnListRestart = false, breakOnLowerIndent = true, breakQuery, eqIndent = true, getNextEntry, getPreviousEntry, query }) => {
|
|
163
|
-
if (!getPreviousEntry && !getNextEntry) return;
|
|
164
|
-
const getSiblingEntry = getNextEntry ?? getPreviousEntry;
|
|
165
|
-
let nextEntry = getSiblingEntry([node, path]);
|
|
166
|
-
while (true) {
|
|
167
|
-
if (!nextEntry) return;
|
|
168
|
-
const [nextNode, nextPath] = nextEntry;
|
|
169
|
-
const indent = node[KEYS.indent];
|
|
170
|
-
const nextIndent = nextNode[KEYS.indent];
|
|
171
|
-
if (breakQuery?.(nextNode, node)) return;
|
|
172
|
-
if (!isDefined(nextIndent)) return;
|
|
173
|
-
if (breakOnListRestart) {
|
|
174
|
-
if (getPreviousEntry && node[KEYS.listRestart]) return;
|
|
175
|
-
if (getNextEntry && nextNode[KEYS.listRestart]) return;
|
|
176
|
-
}
|
|
177
|
-
if (breakOnLowerIndent && nextIndent < indent) return;
|
|
178
|
-
if (breakOnEqIndentNeqListStyleType && nextIndent === indent && nextNode[KEYS.listType] !== node[KEYS.listType]) return;
|
|
179
|
-
let valid = !query || query(nextNode, node);
|
|
180
|
-
if (valid) {
|
|
181
|
-
valid = !eqIndent || nextIndent === indent;
|
|
182
|
-
if (valid) return [nextNode, nextPath];
|
|
183
|
-
}
|
|
184
|
-
nextEntry = getSiblingEntry(nextEntry);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/lib/queries/getNextList.ts
|
|
190
|
-
/** Get the next indent list. */
|
|
191
|
-
const getNextList = (editor, entry, options) => getSiblingList(editor, entry, {
|
|
192
|
-
getNextEntry: ([, currPath]) => {
|
|
193
|
-
const nextPath = PathApi.next(currPath);
|
|
194
|
-
const nextNode = NodeApi.get(editor, nextPath);
|
|
195
|
-
if (!nextNode) return;
|
|
196
|
-
return [nextNode, nextPath];
|
|
197
|
-
},
|
|
198
|
-
...options,
|
|
199
|
-
getPreviousEntry: void 0
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
//#endregion
|
|
203
|
-
//#region src/lib/queries/getPreviousList.ts
|
|
204
|
-
/** Get the previous indent list node. */
|
|
205
|
-
const getPreviousList = (editor, entry, options) => getSiblingList(editor, entry, {
|
|
206
|
-
getPreviousEntry: ([, currPath]) => {
|
|
207
|
-
const prevPath = PathApi.previous(currPath);
|
|
208
|
-
if (!prevPath) return;
|
|
209
|
-
const prevNode = NodeApi.get(editor, prevPath);
|
|
210
|
-
if (!prevNode) return;
|
|
211
|
-
return [prevNode, prevPath];
|
|
212
|
-
},
|
|
213
|
-
...options,
|
|
214
|
-
getNextEntry: void 0
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/lib/queries/getListSiblings.ts
|
|
219
|
-
const getListSiblings = (editor, entry, { current = true, next = true, previous = true, ...options } = {}) => {
|
|
220
|
-
const siblings = [];
|
|
221
|
-
const node = entry[0];
|
|
222
|
-
if (!node[KEYS.listType] && !Object.hasOwn(node, KEYS.listChecked)) return siblings;
|
|
223
|
-
let iterEntry = entry;
|
|
224
|
-
if (previous) while (true) {
|
|
225
|
-
const prevEntry = getPreviousList(editor, iterEntry, options);
|
|
226
|
-
if (!prevEntry) break;
|
|
227
|
-
siblings.push(prevEntry);
|
|
228
|
-
iterEntry = prevEntry;
|
|
229
|
-
}
|
|
230
|
-
if (current) siblings.push(entry);
|
|
231
|
-
if (next) {
|
|
232
|
-
iterEntry = entry;
|
|
233
|
-
while (true) {
|
|
234
|
-
const nextEntry = getNextList(editor, iterEntry, options);
|
|
235
|
-
if (!nextEntry) break;
|
|
236
|
-
siblings.push(nextEntry);
|
|
237
|
-
iterEntry = nextEntry;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return siblings;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/lib/queries/getSiblingListStyleType.ts
|
|
245
|
-
/**
|
|
246
|
-
* Get the first sibling list style type at the given indent. If none, return
|
|
247
|
-
* the entry list style type.
|
|
248
|
-
*/
|
|
249
|
-
const getSiblingListStyleType = (editor, { entry, indent, ...options }) => {
|
|
250
|
-
const siblings = getListSiblings(editor, [{
|
|
251
|
-
...entry[0],
|
|
252
|
-
indent
|
|
253
|
-
}, entry[1]], {
|
|
254
|
-
breakOnEqIndentNeqListStyleType: false,
|
|
255
|
-
current: false,
|
|
256
|
-
eqIndent: true,
|
|
257
|
-
...options
|
|
258
|
-
});
|
|
259
|
-
return siblings.length > 0 ? siblings[0][0][KEYS.listType] : entry[0][KEYS.listType];
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
//#endregion
|
|
263
|
-
//#region src/lib/queries/isOrderedList.ts
|
|
264
|
-
function isOrderedList(element) {
|
|
265
|
-
return !!element.listStyleType && !ULIST_STYLE_TYPES.includes(element.listStyleType);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
//#endregion
|
|
269
|
-
//#region src/lib/queries/someList.ts
|
|
270
|
-
const someList = (editor, type) => !!editor.selection && editor.api.some({ match: (n) => {
|
|
271
|
-
if (Object.hasOwn(n, KEYS.listChecked)) return false;
|
|
272
|
-
const list = n[KEYS.listType];
|
|
273
|
-
return Array.isArray(type) ? type.includes(list) : list === type;
|
|
274
|
-
} });
|
|
275
|
-
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/lib/queries/someTodoList.ts
|
|
278
|
-
const someTodoList = (editor) => editor.api.some({
|
|
279
|
-
at: editor.selection,
|
|
280
|
-
match: (n) => {
|
|
281
|
-
const list = n[KEYS.listType];
|
|
282
|
-
const isHasProperty = Object.hasOwn(n, KEYS.listChecked);
|
|
283
|
-
return n.type === "p" && isHasProperty && list === KEYS.listTodo;
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/lib/normalizers/normalizeListNotIndented.ts
|
|
289
|
-
/** Unset listStyle, listStart if KEYS.indent is not defined. */
|
|
290
|
-
const normalizeListNotIndented = (editor, [node, path]) => {
|
|
291
|
-
if (!isDefined(node[KEYS.indent]) && (node[KEYS.listType] || node[KEYS.listStart])) {
|
|
292
|
-
editor.tf.unsetNodes([KEYS.listType, KEYS.listStart], { at: path });
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
153
|
//#endregion
|
|
298
154
|
//#region src/lib/normalizers/normalizeListStart.ts
|
|
299
155
|
const getListExpectedListStart = (entry, prevEntry) => {
|
|
@@ -318,11 +174,10 @@ const normalizeListStart = (editor, entry, options) => editor.tf.withoutNormaliz
|
|
|
318
174
|
}
|
|
319
175
|
return;
|
|
320
176
|
}
|
|
321
|
-
const expectedListStart = getListExpectedListStart(entry, getPreviousList(editor, entry, {
|
|
177
|
+
const expectedListStart = getListExpectedListStart(entry, getPreviousList(editor, entry, getListSequenceSiblingOptions(editor, {
|
|
322
178
|
breakOnEqIndentNeqListStyleType: false,
|
|
323
|
-
query: (nextNode, curNode) => nextNode[KEYS.listType] === curNode[KEYS.listType],
|
|
324
179
|
...options
|
|
325
|
-
}));
|
|
180
|
+
})));
|
|
326
181
|
if (isDefined(listStart) && expectedListStart === 1) {
|
|
327
182
|
editor.tf.unsetNodes(KEYS.listStart, { at: path });
|
|
328
183
|
return true;
|
|
@@ -348,6 +203,20 @@ const withInsertBreakList = ({ editor, tf: { insertBreak } }) => ({ transforms:
|
|
|
348
203
|
});
|
|
349
204
|
} } });
|
|
350
205
|
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/lib/queries/getNextList.ts
|
|
208
|
+
/** Get the next indent list. */
|
|
209
|
+
const getNextList = (editor, entry, options) => getSiblingList(editor, entry, {
|
|
210
|
+
getNextEntry: ([, currPath]) => {
|
|
211
|
+
const nextPath = PathApi.next(currPath);
|
|
212
|
+
const nextNode = NodeApi.get(editor, nextPath);
|
|
213
|
+
if (!nextNode) return;
|
|
214
|
+
return [nextNode, nextPath];
|
|
215
|
+
},
|
|
216
|
+
...options,
|
|
217
|
+
getPreviousEntry: void 0
|
|
218
|
+
});
|
|
219
|
+
|
|
351
220
|
//#endregion
|
|
352
221
|
//#region src/lib/transforms/indentList.ts
|
|
353
222
|
/** Increase the indentation of the selected blocks. */
|
|
@@ -429,6 +298,32 @@ const setListNodes = (editor, entries, { listStyleType = ListStyleType.Disc }) =
|
|
|
429
298
|
});
|
|
430
299
|
};
|
|
431
300
|
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/lib/queries/getListSiblings.ts
|
|
303
|
+
const getListSiblings = (editor, entry, { current = true, next = true, previous = true, ...options } = {}) => {
|
|
304
|
+
const siblings = [];
|
|
305
|
+
const node = entry[0];
|
|
306
|
+
if (!node[KEYS.listType] && !Object.hasOwn(node, KEYS.listChecked)) return siblings;
|
|
307
|
+
let iterEntry = entry;
|
|
308
|
+
if (previous) while (true) {
|
|
309
|
+
const prevEntry = getPreviousList(editor, iterEntry, options);
|
|
310
|
+
if (!prevEntry) break;
|
|
311
|
+
siblings.push(prevEntry);
|
|
312
|
+
iterEntry = prevEntry;
|
|
313
|
+
}
|
|
314
|
+
if (current) siblings.push(entry);
|
|
315
|
+
if (next) {
|
|
316
|
+
iterEntry = entry;
|
|
317
|
+
while (true) {
|
|
318
|
+
const nextEntry = getNextList(editor, iterEntry, options);
|
|
319
|
+
if (!nextEntry) break;
|
|
320
|
+
siblings.push(nextEntry);
|
|
321
|
+
iterEntry = nextEntry;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
return siblings;
|
|
325
|
+
};
|
|
326
|
+
|
|
432
327
|
//#endregion
|
|
433
328
|
//#region src/lib/transforms/setListSiblingNodes.ts
|
|
434
329
|
/** Set indent list to entry + siblings. */
|
|
@@ -454,6 +349,132 @@ const setListSiblingNodes = (editor, entry, { getSiblingListOptions, listStyleTy
|
|
|
454
349
|
});
|
|
455
350
|
};
|
|
456
351
|
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/lib/queries/areEqListStyleType.ts
|
|
354
|
+
const areEqListStyleType = (_editor, entries, { listStyleType = ListStyleType.Disc }) => {
|
|
355
|
+
let eqListStyleType = true;
|
|
356
|
+
for (const entry of entries) {
|
|
357
|
+
const [block] = entry;
|
|
358
|
+
if (listStyleType === KEYS.listTodo) {
|
|
359
|
+
if (!Object.hasOwn(block, KEYS.listChecked)) {
|
|
360
|
+
eqListStyleType = false;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (!block[KEYS.listType] || block[KEYS.listType] !== listStyleType) {
|
|
366
|
+
eqListStyleType = false;
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return eqListStyleType;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
//#endregion
|
|
374
|
+
//#region src/lib/queries/getListChildren.ts
|
|
375
|
+
/**
|
|
376
|
+
* Get all list items that are children of the current list item (have bigger
|
|
377
|
+
* indent). Stops when encountering an item with equal or lower indent.
|
|
378
|
+
*/
|
|
379
|
+
const getListChildren = (editor, entry) => {
|
|
380
|
+
const children = [];
|
|
381
|
+
const [node, path] = entry;
|
|
382
|
+
const parentIndent = node[KEYS.indent];
|
|
383
|
+
if (!isDefined(parentIndent) || !isDefined(node[KEYS.listType])) return children;
|
|
384
|
+
let currentPath = path;
|
|
385
|
+
while (true) {
|
|
386
|
+
const nextPath = PathApi.next(currentPath);
|
|
387
|
+
if (!nextPath) break;
|
|
388
|
+
const nextNode = NodeApi.get(editor, nextPath);
|
|
389
|
+
if (!nextNode) break;
|
|
390
|
+
const nextIndent = nextNode[KEYS.indent];
|
|
391
|
+
if (!isDefined(nextIndent) || !isDefined(nextNode[KEYS.listType])) break;
|
|
392
|
+
if (nextIndent <= parentIndent) break;
|
|
393
|
+
children.push([nextNode, nextPath]);
|
|
394
|
+
currentPath = nextPath;
|
|
395
|
+
}
|
|
396
|
+
return children;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
//#endregion
|
|
400
|
+
//#region src/lib/queries/expandListItemsWithChildren.ts
|
|
401
|
+
/**
|
|
402
|
+
* Expands a list of blocks to include list item children. For each list item in
|
|
403
|
+
* the input, adds all its children (items with bigger indent). Non-list blocks
|
|
404
|
+
* are kept as-is. Requires id to be set on the blocks.
|
|
405
|
+
*
|
|
406
|
+
* @returns Array of block entries with list items expanded to include their
|
|
407
|
+
* children
|
|
408
|
+
*/
|
|
409
|
+
const expandListItemsWithChildren = (editor, entries) => {
|
|
410
|
+
const expandedEntries = [];
|
|
411
|
+
const processedIds = /* @__PURE__ */ new Set();
|
|
412
|
+
entries.forEach((entry) => {
|
|
413
|
+
const [node] = entry;
|
|
414
|
+
if (processedIds.has(node.id)) return;
|
|
415
|
+
expandedEntries.push(entry);
|
|
416
|
+
processedIds.add(node.id);
|
|
417
|
+
if (isDefined(node[KEYS.listType]) && isDefined(node[KEYS.indent])) getListChildren(editor, entry).forEach((childEntry) => {
|
|
418
|
+
if (!processedIds.has(childEntry[0].id)) {
|
|
419
|
+
expandedEntries.push(childEntry);
|
|
420
|
+
processedIds.add(childEntry[0].id);
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
return expandedEntries;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/lib/queries/getListAbove.ts
|
|
429
|
+
const getListAbove = (editor, options) => editor.api.above({
|
|
430
|
+
...options,
|
|
431
|
+
match: (node) => isDefined(node[KEYS.listType])
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/lib/queries/getSiblingListStyleType.ts
|
|
436
|
+
/**
|
|
437
|
+
* Get the first sibling list style type at the given indent. If none, return
|
|
438
|
+
* the entry list style type.
|
|
439
|
+
*/
|
|
440
|
+
const getSiblingListStyleType = (editor, { entry, indent, ...options }) => {
|
|
441
|
+
const siblings = getListSiblings(editor, [{
|
|
442
|
+
...entry[0],
|
|
443
|
+
indent
|
|
444
|
+
}, entry[1]], {
|
|
445
|
+
breakOnEqIndentNeqListStyleType: false,
|
|
446
|
+
current: false,
|
|
447
|
+
eqIndent: true,
|
|
448
|
+
...options
|
|
449
|
+
});
|
|
450
|
+
return siblings.length > 0 ? siblings[0][0][KEYS.listType] : entry[0][KEYS.listType];
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/lib/queries/isOrderedList.ts
|
|
455
|
+
function isOrderedList(element) {
|
|
456
|
+
return !!element.listStyleType && !ULIST_STYLE_TYPES.includes(element.listStyleType);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/lib/queries/someList.ts
|
|
461
|
+
const someList = (editor, type) => !!editor.selection && editor.api.some({ match: (n) => {
|
|
462
|
+
if (Object.hasOwn(n, KEYS.listChecked)) return false;
|
|
463
|
+
const list = n[KEYS.listType];
|
|
464
|
+
return Array.isArray(type) ? type.includes(list) : list === type;
|
|
465
|
+
} });
|
|
466
|
+
|
|
467
|
+
//#endregion
|
|
468
|
+
//#region src/lib/queries/someTodoList.ts
|
|
469
|
+
const someTodoList = (editor) => editor.api.some({
|
|
470
|
+
at: editor.selection,
|
|
471
|
+
match: (n) => {
|
|
472
|
+
const list = n[KEYS.listType];
|
|
473
|
+
const isHasProperty = Object.hasOwn(n, KEYS.listChecked);
|
|
474
|
+
return n.type === "p" && isHasProperty && list === KEYS.listTodo;
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
457
478
|
//#endregion
|
|
458
479
|
//#region src/lib/transforms/toggleListSet.ts
|
|
459
480
|
/** Set indent list if not set. */
|
|
@@ -491,6 +512,11 @@ const toggleListUnset = (editor, [node, path], { listStyleType = ListStyleType.D
|
|
|
491
512
|
/** Toggle indent list. */
|
|
492
513
|
const toggleList = (editor, options, getSiblingListOptions) => {
|
|
493
514
|
const { listRestart, listRestartPolite, listStyleType } = options;
|
|
515
|
+
const { getSiblingListOptions: pluginGetSiblingListOptions } = editor.getOptions(BaseListPlugin);
|
|
516
|
+
const mergedGetSiblingListOptions = {
|
|
517
|
+
...pluginGetSiblingListOptions,
|
|
518
|
+
...getSiblingListOptions
|
|
519
|
+
};
|
|
494
520
|
/**
|
|
495
521
|
* True - One or more blocks were converted to lists or changed such that they
|
|
496
522
|
* remain lists.
|
|
@@ -500,17 +526,13 @@ const toggleList = (editor, options, getSiblingListOptions) => {
|
|
|
500
526
|
* Null - No action was taken.
|
|
501
527
|
*/
|
|
502
528
|
const setList = (() => {
|
|
503
|
-
const { getSiblingListOptions: _getSiblingListOptions } = editor.getOptions(BaseListPlugin);
|
|
504
529
|
if (editor.api.isCollapsed()) {
|
|
505
530
|
const entry = editor.api.block();
|
|
506
531
|
if (!entry) return null;
|
|
507
532
|
if (toggleListSet(editor, entry, options)) return true;
|
|
508
533
|
if (toggleListUnset(editor, entry, { listStyleType })) return false;
|
|
509
534
|
setListSiblingNodes(editor, entry, {
|
|
510
|
-
getSiblingListOptions:
|
|
511
|
-
..._getSiblingListOptions,
|
|
512
|
-
...getSiblingListOptions
|
|
513
|
-
},
|
|
535
|
+
getSiblingListOptions: mergedGetSiblingListOptions,
|
|
514
536
|
listStyleType
|
|
515
537
|
});
|
|
516
538
|
return true;
|
|
@@ -543,7 +565,10 @@ const toggleList = (editor, options, getSiblingListOptions) => {
|
|
|
543
565
|
if (setList && restartValue) {
|
|
544
566
|
const entry = getListAbove(editor, { at: editor.api.start(editor.selection) });
|
|
545
567
|
if (!entry) return;
|
|
546
|
-
const isFirst = !getPreviousList(editor, entry
|
|
568
|
+
const isFirst = !getPreviousList(editor, entry, getListSequenceSiblingOptions(editor, {
|
|
569
|
+
breakOnEqIndentNeqListStyleType: false,
|
|
570
|
+
...mergedGetSiblingListOptions
|
|
571
|
+
}));
|
|
547
572
|
/**
|
|
548
573
|
* Only apply listRestartPolite if this is the first item and restartValue >
|
|
549
574
|
* 1.
|
|
@@ -671,7 +696,7 @@ const withList = (ctx) => {
|
|
|
671
696
|
};
|
|
672
697
|
|
|
673
698
|
//#endregion
|
|
674
|
-
//#region src/lib/BaseListPlugin.
|
|
699
|
+
//#region src/lib/BaseListPlugin.ts
|
|
675
700
|
const BaseListPlugin = createTSlatePlugin({
|
|
676
701
|
key: KEYS.list,
|
|
677
702
|
inject: {
|
|
@@ -759,10 +784,6 @@ const BaseListPlugin = createTSlatePlugin({
|
|
|
759
784
|
};
|
|
760
785
|
}
|
|
761
786
|
} } },
|
|
762
|
-
render: { belowNodes: (props) => {
|
|
763
|
-
if (!props.element.listStyleType) return;
|
|
764
|
-
return (props$1) => /* @__PURE__ */ React.createElement(List, props$1);
|
|
765
|
-
} },
|
|
766
787
|
rules: {
|
|
767
788
|
break: {
|
|
768
789
|
empty: "reset",
|
|
@@ -773,41 +794,6 @@ const BaseListPlugin = createTSlatePlugin({
|
|
|
773
794
|
match: ({ node }) => isDefined(node[KEYS.listType])
|
|
774
795
|
}
|
|
775
796
|
}).overrideEditor(withList);
|
|
776
|
-
function List(props) {
|
|
777
|
-
const $ = c(9);
|
|
778
|
-
const { listStart, listStyleType } = props.element;
|
|
779
|
-
const List$1 = isOrderedList(props.element) ? "ol" : "ul";
|
|
780
|
-
let t0;
|
|
781
|
-
if ($[0] !== listStyleType) {
|
|
782
|
-
t0 = {
|
|
783
|
-
listStyleType,
|
|
784
|
-
margin: 0,
|
|
785
|
-
padding: 0,
|
|
786
|
-
position: "relative"
|
|
787
|
-
};
|
|
788
|
-
$[0] = listStyleType;
|
|
789
|
-
$[1] = t0;
|
|
790
|
-
} else t0 = $[1];
|
|
791
|
-
let t1;
|
|
792
|
-
if ($[2] !== props.children) {
|
|
793
|
-
t1 = /* @__PURE__ */ React.createElement("li", null, props.children);
|
|
794
|
-
$[2] = props.children;
|
|
795
|
-
$[3] = t1;
|
|
796
|
-
} else t1 = $[3];
|
|
797
|
-
let t2;
|
|
798
|
-
if ($[4] !== List$1 || $[5] !== listStart || $[6] !== t0 || $[7] !== t1) {
|
|
799
|
-
t2 = /* @__PURE__ */ React.createElement(List$1, {
|
|
800
|
-
style: t0,
|
|
801
|
-
start: listStart
|
|
802
|
-
}, t1);
|
|
803
|
-
$[4] = List$1;
|
|
804
|
-
$[5] = listStart;
|
|
805
|
-
$[6] = t0;
|
|
806
|
-
$[7] = t1;
|
|
807
|
-
$[8] = t2;
|
|
808
|
-
} else t2 = $[8];
|
|
809
|
-
return t2;
|
|
810
|
-
}
|
|
811
797
|
|
|
812
798
|
//#endregion
|
|
813
799
|
//#region src/lib/BulletedListRules.ts
|
|
@@ -867,4 +853,4 @@ const TaskListRules = { markdown: createRuleFactory({
|
|
|
867
853
|
}) };
|
|
868
854
|
|
|
869
855
|
//#endregion
|
|
870
|
-
export {
|
|
856
|
+
export { getListExpectedListStart as A, setIndentTodoNode as C, indentTodo as D, indentList as E, getSiblingList as F, normalizeListNotIndented as I, ListStyleType as M, ULIST_STYLE_TYPES as N, getNextList as O, getPreviousList as P, setListNodes as S, outdentList as T, expandListItemsWithChildren as _, withList as a, setListSiblingNodes as b, toggleListByPathUnSet as c, toggleListSet as d, someTodoList as f, getListAbove as g, getSiblingListStyleType as h, BaseListPlugin as i, normalizeListStart as j, withInsertBreakList as k, toggleList as l, isOrderedList as m, OrderedListRules as n, withNormalizeList as o, someList as p, BulletedListRules as r, toggleListByPath as s, TaskListRules as t, toggleListUnset as u, getListChildren as v, setListNode as w, getListSiblings as x, areEqListStyleType as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lofcz/platejs-list",
|
|
3
|
-
"version": "53.
|
|
3
|
+
"version": "53.4.10",
|
|
4
4
|
"description": "List plugin for Plate",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plate",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@plate/scripts": "1.0.0",
|
|
39
|
-
"platejs": "npm:@lofcz/platejs@53.
|
|
39
|
+
"platejs": "npm:@lofcz/platejs@53.4.9"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"platejs": ">=53.0.0",
|