mirror of
https://github.com/facebook/lexical.git
synced 2025-05-18 15:46:31 +08:00
Handle bad list item children gracefully (#3226)
This commit is contained in:
@ -369,7 +369,7 @@ export class ListItemNode extends ElementNode {
|
|||||||
const parent = this.getParentOrThrow();
|
const parent = this.getParentOrThrow();
|
||||||
|
|
||||||
if ($isListNode(parent)) {
|
if ($isListNode(parent)) {
|
||||||
const siblings = this.getNextSiblings<ListItemNode>();
|
const siblings = this.getNextSiblings();
|
||||||
updateChildrenListItemValue(parent, siblings);
|
updateChildrenListItemValue(parent, siblings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,16 +270,22 @@ export function removeList(editor: LexicalEditor): void {
|
|||||||
|
|
||||||
export function updateChildrenListItemValue(
|
export function updateChildrenListItemValue(
|
||||||
list: ListNode,
|
list: ListNode,
|
||||||
children?: Array<ListItemNode>,
|
children?: Array<LexicalNode>,
|
||||||
): void {
|
): void {
|
||||||
(children || list.getChildren()).forEach((child: ListItemNode) => {
|
const childrenOrExisting = children || list.getChildren();
|
||||||
|
if (childrenOrExisting !== undefined) {
|
||||||
|
for (let i = 0; i < childrenOrExisting.length; i++) {
|
||||||
|
const child = childrenOrExisting[i];
|
||||||
|
if ($isListItemNode(child)) {
|
||||||
const prevValue = child.getValue();
|
const prevValue = child.getValue();
|
||||||
const nextValue = $getListItemValue(child);
|
const nextValue = $getListItemValue(child);
|
||||||
|
|
||||||
if (prevValue !== nextValue) {
|
if (prevValue !== nextValue) {
|
||||||
child.setValue(nextValue);
|
child.setValue(nextValue);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function $handleIndent(listItemNodes: Array<ListItemNode>): void {
|
export function $handleIndent(listItemNodes: Array<ListItemNode>): void {
|
||||||
|
@ -94,5 +94,6 @@
|
|||||||
"92": "syncChildrenFromYjs: cound not find element node",
|
"92": "syncChildrenFromYjs: cound not find element node",
|
||||||
"93": "syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node",
|
"93": "syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node",
|
||||||
"94": "splice: could not find collab element node",
|
"94": "splice: could not find collab element node",
|
||||||
"95": "splice: expected offset to be greater than zero"
|
"95": "splice: expected offset to be greater than zero",
|
||||||
|
"96": "Expected node %s to have a last child."
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user