@webiny/lexical-nodes 6.3.0 → 6.4.0-beta.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/FontColorNode.js +94 -119
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +160 -183
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +101 -131
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +228 -315
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +249 -320
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +174 -223
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +119 -148
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +97 -102
- package/QuoteNode.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +117 -147
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +167 -194
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.js +20 -23
- package/generateInitialLexicalValue.js.map +1 -1
- package/index.js +38 -26
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/prepareLexicalState.js +30 -43
- package/prepareLexicalState.js.map +1 -1
- package/types.js +0 -3
- package/utils/clearNodeFormating.js +14 -15
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +277 -368
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +6 -13
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +6 -7
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +6 -13
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.js +6 -11
- package/utils/getStyleId.js.map +1 -1
- package/utils/listNode.js +60 -84
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +67 -118
- package/utils/toggleLink.js.map +1 -1
- package/types.js.map +0 -1
package/ListItemNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["$isElementNode","$isRangeSelection","ElementNode","addClassNamesToElement","removeClassNamesFromElement","$createListNode","$isListNode","$handleIndent","$handleOutdent","mergeLists","updateChildrenListItemValue","$createParagraphNode","$isParagraphNode","isNestedListNode","LIST_ITEM_TYPE","ListItemNode","getType","clone","node","__value","__checked","__key","constructor","value","checked","key","undefined","createDOM","config","element","document","createElement","parent","getParent","getListType","updateListItemChecked","$setListItemThemeClassNames","theme","updateDOM","prevNode","dom","importDOM","li","conversion","convertListItemElement","priority","importJSON","serializedNode","setFormat","format","setIndent","indent","setDirection","direction","exportJSON","getChecked","type","getValue","append","nodes","i","length","canMergeWith","children","getChildren","remove","replace","replaceWithNode","includeChildren","$isListItemNode","list","getParentOrThrow","__first","getKey","insertBefore","__last","insertAfter","newList","nextSibling","getNextSibling","nodeToAppend","Error","forEach","child","getChildrenSize","listNode","console","log","siblings","getNextSiblings","after","afterListNode","newListNode","sibling","preserveEmptyParent","prevSibling","getPreviousSibling","getFirstChild","insertNewAfter","newElement","$createListItemNode","collapseAtStart","selection","paragraph","listNodeParent","isIndented","select","anchor","focus","getNode","is","set","offset","self","getLatest","setValue","getWritable","setChecked","getIndent","__indent","indentLevel","currentIndent","canIndent","nodeToInsert","canInsertAfter","canReplaceWith","replacement","extractWithChild","anchorNode","focusNode","isParentOf","getTextContent","editorThemeClasses","classesToAdd","classesToRemove","listTheme","listItemClassName","listitem","nestedListItemClassName","nested","listItemClasses","split","push","parentNode","isCheckList","listitemUnchecked","listitemChecked","nestedListItemClasses","some","listItemNode","prevListItemNode","removeAttribute","setAttribute"],"sources":["ListItemNode.ts"],"sourcesContent":["import type {\n DOMConversionMap,\n DOMConversionOutput,\n EditorConfig,\n EditorThemeClasses,\n LexicalNode,\n NodeKey,\n ParagraphNode,\n RangeSelection,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport {\n $isElementNode,\n $isRangeSelection,\n ElementNode,\n addClassNamesToElement,\n removeClassNamesFromElement\n} from \"lexical\";\nimport type { ListNode } from \"~/ListNode.js\";\nimport { $createListNode, $isListNode } from \"~/ListNode.js\";\nimport {\n $handleIndent,\n $handleOutdent,\n mergeLists,\n updateChildrenListItemValue\n} from \"~/utils/formatList.js\";\nimport { $createParagraphNode, $isParagraphNode } from \"~/ParagraphNode.js\";\nimport { isNestedListNode } from \"~/utils/listNode.js\";\n\nexport const LIST_ITEM_TYPE = \"wby-list-item\";\n\nexport type SerializedWebinyListItemNode = Spread<\n {\n checked: boolean | undefined;\n type: typeof LIST_ITEM_TYPE;\n value: number;\n },\n SerializedElementNode\n>;\n\n/** @noInheritDoc */\nexport class ListItemNode extends ElementNode {\n /** @internal */\n __value: number;\n /** @internal */\n __checked?: boolean;\n\n static override getType(): string {\n return LIST_ITEM_TYPE;\n }\n\n static override clone(node: ListItemNode): ListItemNode {\n return new ListItemNode(node.__value, node.__checked, node.__key);\n }\n\n constructor(value?: number, checked?: boolean, key?: NodeKey) {\n super(key);\n this.__value = value === undefined ? 1 : value;\n this.__checked = checked;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = document.createElement(\"li\");\n const parent = this.getParent();\n if ($isListNode(parent) && parent.getListType() === \"check\") {\n updateListItemChecked(element, this, null, parent);\n }\n element.value = this.__value;\n $setListItemThemeClassNames(element, config.theme, this);\n\n return element;\n }\n\n override updateDOM(prevNode: ListItemNode, dom: HTMLElement, config: EditorConfig): boolean {\n const parent = this.getParent();\n if ($isListNode(parent) && parent.getListType() === \"check\") {\n updateListItemChecked(dom, this, prevNode, parent);\n }\n // @ts-expect-error - this is always HTMLListItemElement\n dom.value = this.__value;\n $setListItemThemeClassNames(dom, config.theme, this);\n\n return false;\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n li: () => ({\n conversion: convertListItemElement,\n priority: 0\n })\n };\n }\n\n static override importJSON(serializedNode: SerializedWebinyListItemNode): ListItemNode {\n const node = new ListItemNode(serializedNode.value, serializedNode.checked);\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n return node;\n }\n\n override exportJSON(): SerializedWebinyListItemNode {\n return {\n ...super.exportJSON(),\n checked: this.getChecked(),\n type: LIST_ITEM_TYPE,\n value: this.getValue()\n };\n }\n\n override append(...nodes: LexicalNode[]): this {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n\n if ($isElementNode(node) && this.canMergeWith(node)) {\n const children = node.getChildren();\n this.append(...children);\n node.remove();\n } else {\n super.append(node);\n }\n }\n\n return this;\n }\n\n override replace<N extends LexicalNode>(replaceWithNode: N, includeChildren?: boolean): N {\n if ($isListItemNode(replaceWithNode)) {\n return super.replace(replaceWithNode);\n }\n this.setIndent(0);\n const list = this.getParentOrThrow();\n if (!$isListNode(list)) {\n return replaceWithNode;\n }\n if (list.__first === this.getKey()) {\n list.insertBefore(replaceWithNode);\n } else if (list.__last === this.getKey()) {\n list.insertAfter(replaceWithNode);\n } else {\n // Split the list\n const newList = $createListNode(list.getListType());\n let nextSibling = this.getNextSibling();\n while (nextSibling) {\n const nodeToAppend = nextSibling;\n nextSibling = nextSibling.getNextSibling();\n newList.append(nodeToAppend);\n }\n list.insertAfter(replaceWithNode);\n replaceWithNode.insertAfter(newList);\n }\n if (includeChildren) {\n if (!$isElementNode(replaceWithNode)) {\n throw Error(\"includeChildren should only be true for ElementNodes\");\n }\n\n this.getChildren().forEach((child: LexicalNode) => {\n replaceWithNode.append(child);\n });\n }\n this.remove();\n if (list.getChildrenSize() === 0) {\n list.remove();\n }\n return replaceWithNode;\n }\n\n override insertAfter(node: LexicalNode): LexicalNode {\n const listNode = this.getParentOrThrow();\n\n if (!$isListNode(listNode)) {\n console.log(\"insertAfter: webiny list node is not parent of list item node\");\n return listNode;\n }\n\n const siblings = this.getNextSiblings();\n\n if ($isListItemNode(node)) {\n const after = super.insertAfter(node);\n const afterListNode = node.getParentOrThrow();\n\n if ($isListNode(afterListNode)) {\n updateChildrenListItemValue(afterListNode);\n }\n\n return after;\n }\n\n // Attempt to merge if the list is of the same type.\n\n if ($isListNode(node) && node.getListType() === listNode.getListType()) {\n let child = node;\n const children = node.getChildren<ListNode>();\n\n for (let i = children.length - 1; i >= 0; i--) {\n child = children[i];\n\n this.insertAfter(child);\n }\n\n return child;\n }\n\n // Otherwise, split the list\n // Split the lists and insert the node in between them\n listNode.insertAfter(node);\n\n if (siblings.length !== 0) {\n const newListNode = $createListNode(listNode.getListType());\n\n siblings.forEach(sibling => newListNode.append(sibling));\n\n node.insertAfter(newListNode);\n }\n\n return node;\n }\n\n override remove(preserveEmptyParent?: boolean): void {\n const prevSibling = this.getPreviousSibling();\n const nextSibling = this.getNextSibling();\n super.remove(preserveEmptyParent);\n\n if (\n prevSibling &&\n nextSibling &&\n isNestedListNode(prevSibling) &&\n isNestedListNode(nextSibling)\n ) {\n mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());\n nextSibling.remove();\n } else if (nextSibling) {\n const parent = nextSibling.getParent();\n\n if ($isListNode(parent)) {\n updateChildrenListItemValue(parent);\n }\n }\n }\n\n override insertNewAfter(): ListItemNode | ParagraphNode {\n const newElement = $createListItemNode(this.__checked == null ? undefined : false);\n this.insertAfter(newElement);\n\n return newElement;\n }\n\n override collapseAtStart(selection: RangeSelection): true {\n const paragraph = $createParagraphNode();\n const children = this.getChildren();\n children.forEach(child => paragraph.append(child));\n const listNode = this.getParentOrThrow();\n const listNodeParent = listNode.getParentOrThrow();\n const isIndented = $isListItemNode(listNodeParent);\n\n if (listNode.getChildrenSize() === 1) {\n if (isIndented) {\n // if the list node is nested, we just want to remove it,\n // effectively unindenting it.\n listNode.remove();\n listNodeParent.select();\n } else {\n listNode.replace(paragraph);\n // If we have selection on the list item, we'll need to move it\n // to the paragraph\n const anchor = selection.anchor;\n const focus = selection.focus;\n const key = paragraph.getKey();\n\n if (anchor.type === \"element\" && anchor.getNode().is(this)) {\n anchor.set(key, anchor.offset, \"element\");\n }\n\n if (focus.type === \"element\" && focus.getNode().is(this)) {\n focus.set(key, focus.offset, \"element\");\n }\n }\n } else {\n listNode.insertBefore(paragraph);\n this.remove();\n }\n\n return true;\n }\n\n getValue(): number {\n const self = this.getLatest();\n\n return self.__value;\n }\n\n setValue(value: number): void {\n const self = this.getWritable();\n self.__value = value;\n }\n\n getChecked(): boolean | undefined {\n const self = this.getLatest();\n\n return self.__checked;\n }\n\n setChecked(checked?: boolean): void {\n const self = this.getWritable();\n self.__checked = checked;\n }\n\n override getIndent(): number {\n // If we don't have a parent, we are likely serializing\n const parent = this.getParent();\n if (parent === null) {\n return this.getLatest().__indent;\n }\n // ListItemNode should always have a ListNode for a parent.\n let listNodeParent = parent.getParentOrThrow();\n let indentLevel = 0;\n while ($isListItemNode(listNodeParent)) {\n listNodeParent = listNodeParent.getParentOrThrow().getParentOrThrow();\n indentLevel++;\n }\n\n return indentLevel;\n }\n\n override setIndent(indent: number): this {\n let currentIndent = this.getIndent();\n while (currentIndent !== indent) {\n if (currentIndent < indent) {\n $handleIndent([this]);\n currentIndent++;\n } else {\n $handleOutdent([this]);\n currentIndent--;\n }\n }\n\n return this;\n }\n\n override canIndent(): false {\n // Indent/outdent is handled specifically in the RichText logic.\n\n return false;\n }\n\n override insertBefore(nodeToInsert: LexicalNode): LexicalNode {\n if ($isListItemNode(nodeToInsert)) {\n const parent = this.getParentOrThrow();\n\n if ($isListNode(parent)) {\n const siblings = this.getNextSiblings();\n updateChildrenListItemValue(parent, siblings);\n }\n }\n\n return super.insertBefore(nodeToInsert);\n }\n\n override canInsertAfter(node: LexicalNode): boolean {\n return $isListNode(node);\n }\n\n override canReplaceWith(replacement: LexicalNode): boolean {\n return $isListItemNode(replacement);\n }\n\n override canMergeWith(node: LexicalNode): boolean {\n return $isParagraphNode(node) || $isListItemNode(node);\n }\n\n override extractWithChild(child: LexicalNode, selection: RangeSelection): boolean {\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n const anchorNode = selection.anchor.getNode();\n const focusNode = selection.focus.getNode();\n\n return (\n this.isParentOf(anchorNode) &&\n this.isParentOf(focusNode) &&\n this.getTextContent().length === selection.getTextContent().length\n );\n }\n}\n\nfunction $setListItemThemeClassNames(\n dom: HTMLElement,\n editorThemeClasses: EditorThemeClasses,\n node: ListItemNode\n): void {\n const classesToAdd = [];\n const classesToRemove = [];\n const listTheme = editorThemeClasses.list;\n const listItemClassName = listTheme ? listTheme.listitem : undefined;\n let nestedListItemClassName;\n\n if (listTheme && listTheme.nested) {\n nestedListItemClassName = listTheme.nested.listitem;\n }\n\n if (listItemClassName !== undefined) {\n const listItemClasses = listItemClassName.split(\" \");\n classesToAdd.push(...listItemClasses);\n }\n\n if (listTheme) {\n const parentNode = node.getParent();\n const isCheckList = $isListNode(parentNode) && parentNode?.getListType() === \"check\";\n const checked = node.getChecked();\n\n if (!isCheckList || checked) {\n classesToRemove.push(listTheme.listitemUnchecked);\n }\n\n if (!isCheckList || !checked) {\n classesToRemove.push(listTheme.listitemChecked);\n }\n\n if (isCheckList) {\n classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);\n }\n }\n\n if (nestedListItemClassName !== undefined) {\n const nestedListItemClasses = nestedListItemClassName.split(\" \");\n\n if (node.getChildren().some(child => $isListNode(child))) {\n classesToAdd.push(...nestedListItemClasses);\n } else {\n classesToRemove.push(...nestedListItemClasses);\n }\n }\n\n if (classesToRemove.length > 0) {\n removeClassNamesFromElement(dom, ...classesToRemove);\n }\n\n if (classesToAdd.length > 0) {\n addClassNamesToElement(dom, ...classesToAdd);\n }\n}\n\nfunction updateListItemChecked(\n dom: HTMLElement,\n listItemNode: ListItemNode,\n prevListItemNode: ListItemNode | null,\n listNode: ListNode\n): void {\n const isCheckList = listNode.getListType() === \"check\";\n\n if (isCheckList) {\n // Only add attributes for leaf list items\n if ($isListNode(listItemNode.getFirstChild())) {\n dom.removeAttribute(\"role\");\n dom.removeAttribute(\"tabIndex\");\n dom.removeAttribute(\"aria-checked\");\n } else {\n dom.setAttribute(\"role\", \"checkbox\");\n dom.setAttribute(\"tabIndex\", \"-1\");\n\n if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {\n dom.setAttribute(\"aria-checked\", listItemNode.getChecked() ? \"true\" : \"false\");\n }\n }\n } else {\n // Clean up checked state\n if (listItemNode.getChecked() != null) {\n listItemNode.setChecked(undefined);\n }\n }\n}\n\nfunction convertListItemElement(): DOMConversionOutput {\n return { node: $createListItemNode() };\n}\n\nexport function $createListItemNode(checked?: boolean): ListItemNode {\n return new ListItemNode(undefined, checked);\n}\n\nexport function $isListItemNode(node: LexicalNode | null | undefined): node is ListItemNode {\n return node instanceof ListItemNode;\n}\n"],"mappings":"AAYA,SACIA,cAAc,EACdC,iBAAiB,EACjBC,WAAW,EACXC,sBAAsB,EACtBC,2BAA2B,QACxB,SAAS;AAEhB,SAASC,eAAe,EAAEC,WAAW;AACrC,SACIC,aAAa,EACbC,cAAc,EACdC,UAAU,EACVC,2BAA2B;AAE/B,SAASC,oBAAoB,EAAEC,gBAAgB;AAC/C,SAASC,gBAAgB;AAEzB,OAAO,MAAMC,cAAc,GAAG,eAAe;AAW7C;AACA,OAAO,MAAMC,YAAY,SAASb,WAAW,CAAC;EAC1C;;EAEA;;EAGA,OAAgBc,OAAOA,CAAA,EAAW;IAC9B,OAAOF,cAAc;EACzB;EAEA,OAAgBG,KAAKA,CAACC,IAAkB,EAAgB;IACpD,OAAO,IAAIH,YAAY,CAACG,IAAI,CAACC,OAAO,EAAED,IAAI,CAACE,SAAS,EAAEF,IAAI,CAACG,KAAK,CAAC;EACrE;EAEAC,WAAWA,CAACC,KAAc,EAAEC,OAAiB,EAAEC,GAAa,EAAE;IAC1D,KAAK,CAACA,GAAG,CAAC;IACV,IAAI,CAACN,OAAO,GAAGI,KAAK,KAAKG,SAAS,GAAG,CAAC,GAAGH,KAAK;IAC9C,IAAI,CAACH,SAAS,GAAGI,OAAO;EAC5B;EAESG,SAASA,CAACC,MAAoB,EAAe;IAClD,MAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAC,IAAI,CAAC;IAC5C,MAAMC,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ACJ;AAEA,SAASkB,sBAAsBA,CAAA,EAAwB;EACnD,OAAO;IAAE1B,IAAI,EAAEkF,mBAAmB,CAAC;EAAE,CAAC;AAC1C;AAEA,OAAO,SAASA,mBAAmBA,CAAC5E,OAAiB,EAAgB;EACjE,OAAO,IAAIT,YAAY,CAACW,SAAS,EAAEF,OAAO,CAAC;AAC/C;AAEA,OAAO,SAAS6C,eAAeA,CAACnD,IAAoC,EAAwB;EACxF,OAAOA,IAAI,YAAYH,YAAY;AACvC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ListItemNode.js","sources":["../src/ListItemNode.ts"],"sourcesContent":["import type {\n DOMConversionMap,\n DOMConversionOutput,\n EditorConfig,\n EditorThemeClasses,\n LexicalNode,\n NodeKey,\n ParagraphNode,\n RangeSelection,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport {\n $isElementNode,\n $isRangeSelection,\n ElementNode,\n addClassNamesToElement,\n removeClassNamesFromElement\n} from \"lexical\";\nimport type { ListNode } from \"~/ListNode.js\";\nimport { $createListNode, $isListNode } from \"~/ListNode.js\";\nimport {\n $handleIndent,\n $handleOutdent,\n mergeLists,\n updateChildrenListItemValue\n} from \"~/utils/formatList.js\";\nimport { $createParagraphNode, $isParagraphNode } from \"~/ParagraphNode.js\";\nimport { isNestedListNode } from \"~/utils/listNode.js\";\n\nexport const LIST_ITEM_TYPE = \"wby-list-item\";\n\nexport type SerializedWebinyListItemNode = Spread<\n {\n checked: boolean | undefined;\n type: typeof LIST_ITEM_TYPE;\n value: number;\n },\n SerializedElementNode\n>;\n\n/** @noInheritDoc */\nexport class ListItemNode extends ElementNode {\n /** @internal */\n __value: number;\n /** @internal */\n __checked?: boolean;\n\n static override getType(): string {\n return LIST_ITEM_TYPE;\n }\n\n static override clone(node: ListItemNode): ListItemNode {\n return new ListItemNode(node.__value, node.__checked, node.__key);\n }\n\n constructor(value?: number, checked?: boolean, key?: NodeKey) {\n super(key);\n this.__value = value === undefined ? 1 : value;\n this.__checked = checked;\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const element = document.createElement(\"li\");\n const parent = this.getParent();\n if ($isListNode(parent) && parent.getListType() === \"check\") {\n updateListItemChecked(element, this, null, parent);\n }\n element.value = this.__value;\n $setListItemThemeClassNames(element, config.theme, this);\n\n return element;\n }\n\n override updateDOM(prevNode: ListItemNode, dom: HTMLElement, config: EditorConfig): boolean {\n const parent = this.getParent();\n if ($isListNode(parent) && parent.getListType() === \"check\") {\n updateListItemChecked(dom, this, prevNode, parent);\n }\n // @ts-expect-error - this is always HTMLListItemElement\n dom.value = this.__value;\n $setListItemThemeClassNames(dom, config.theme, this);\n\n return false;\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n li: () => ({\n conversion: convertListItemElement,\n priority: 0\n })\n };\n }\n\n static override importJSON(serializedNode: SerializedWebinyListItemNode): ListItemNode {\n const node = new ListItemNode(serializedNode.value, serializedNode.checked);\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n return node;\n }\n\n override exportJSON(): SerializedWebinyListItemNode {\n return {\n ...super.exportJSON(),\n checked: this.getChecked(),\n type: LIST_ITEM_TYPE,\n value: this.getValue()\n };\n }\n\n override append(...nodes: LexicalNode[]): this {\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n\n if ($isElementNode(node) && this.canMergeWith(node)) {\n const children = node.getChildren();\n this.append(...children);\n node.remove();\n } else {\n super.append(node);\n }\n }\n\n return this;\n }\n\n override replace<N extends LexicalNode>(replaceWithNode: N, includeChildren?: boolean): N {\n if ($isListItemNode(replaceWithNode)) {\n return super.replace(replaceWithNode);\n }\n this.setIndent(0);\n const list = this.getParentOrThrow();\n if (!$isListNode(list)) {\n return replaceWithNode;\n }\n if (list.__first === this.getKey()) {\n list.insertBefore(replaceWithNode);\n } else if (list.__last === this.getKey()) {\n list.insertAfter(replaceWithNode);\n } else {\n // Split the list\n const newList = $createListNode(list.getListType());\n let nextSibling = this.getNextSibling();\n while (nextSibling) {\n const nodeToAppend = nextSibling;\n nextSibling = nextSibling.getNextSibling();\n newList.append(nodeToAppend);\n }\n list.insertAfter(replaceWithNode);\n replaceWithNode.insertAfter(newList);\n }\n if (includeChildren) {\n if (!$isElementNode(replaceWithNode)) {\n throw Error(\"includeChildren should only be true for ElementNodes\");\n }\n\n this.getChildren().forEach((child: LexicalNode) => {\n replaceWithNode.append(child);\n });\n }\n this.remove();\n if (list.getChildrenSize() === 0) {\n list.remove();\n }\n return replaceWithNode;\n }\n\n override insertAfter(node: LexicalNode): LexicalNode {\n const listNode = this.getParentOrThrow();\n\n if (!$isListNode(listNode)) {\n console.log(\"insertAfter: webiny list node is not parent of list item node\");\n return listNode;\n }\n\n const siblings = this.getNextSiblings();\n\n if ($isListItemNode(node)) {\n const after = super.insertAfter(node);\n const afterListNode = node.getParentOrThrow();\n\n if ($isListNode(afterListNode)) {\n updateChildrenListItemValue(afterListNode);\n }\n\n return after;\n }\n\n // Attempt to merge if the list is of the same type.\n\n if ($isListNode(node) && node.getListType() === listNode.getListType()) {\n let child = node;\n const children = node.getChildren<ListNode>();\n\n for (let i = children.length - 1; i >= 0; i--) {\n child = children[i];\n\n this.insertAfter(child);\n }\n\n return child;\n }\n\n // Otherwise, split the list\n // Split the lists and insert the node in between them\n listNode.insertAfter(node);\n\n if (siblings.length !== 0) {\n const newListNode = $createListNode(listNode.getListType());\n\n siblings.forEach(sibling => newListNode.append(sibling));\n\n node.insertAfter(newListNode);\n }\n\n return node;\n }\n\n override remove(preserveEmptyParent?: boolean): void {\n const prevSibling = this.getPreviousSibling();\n const nextSibling = this.getNextSibling();\n super.remove(preserveEmptyParent);\n\n if (\n prevSibling &&\n nextSibling &&\n isNestedListNode(prevSibling) &&\n isNestedListNode(nextSibling)\n ) {\n mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());\n nextSibling.remove();\n } else if (nextSibling) {\n const parent = nextSibling.getParent();\n\n if ($isListNode(parent)) {\n updateChildrenListItemValue(parent);\n }\n }\n }\n\n override insertNewAfter(): ListItemNode | ParagraphNode {\n const newElement = $createListItemNode(this.__checked == null ? undefined : false);\n this.insertAfter(newElement);\n\n return newElement;\n }\n\n override collapseAtStart(selection: RangeSelection): true {\n const paragraph = $createParagraphNode();\n const children = this.getChildren();\n children.forEach(child => paragraph.append(child));\n const listNode = this.getParentOrThrow();\n const listNodeParent = listNode.getParentOrThrow();\n const isIndented = $isListItemNode(listNodeParent);\n\n if (listNode.getChildrenSize() === 1) {\n if (isIndented) {\n // if the list node is nested, we just want to remove it,\n // effectively unindenting it.\n listNode.remove();\n listNodeParent.select();\n } else {\n listNode.replace(paragraph);\n // If we have selection on the list item, we'll need to move it\n // to the paragraph\n const anchor = selection.anchor;\n const focus = selection.focus;\n const key = paragraph.getKey();\n\n if (anchor.type === \"element\" && anchor.getNode().is(this)) {\n anchor.set(key, anchor.offset, \"element\");\n }\n\n if (focus.type === \"element\" && focus.getNode().is(this)) {\n focus.set(key, focus.offset, \"element\");\n }\n }\n } else {\n listNode.insertBefore(paragraph);\n this.remove();\n }\n\n return true;\n }\n\n getValue(): number {\n const self = this.getLatest();\n\n return self.__value;\n }\n\n setValue(value: number): void {\n const self = this.getWritable();\n self.__value = value;\n }\n\n getChecked(): boolean | undefined {\n const self = this.getLatest();\n\n return self.__checked;\n }\n\n setChecked(checked?: boolean): void {\n const self = this.getWritable();\n self.__checked = checked;\n }\n\n override getIndent(): number {\n // If we don't have a parent, we are likely serializing\n const parent = this.getParent();\n if (parent === null) {\n return this.getLatest().__indent;\n }\n // ListItemNode should always have a ListNode for a parent.\n let listNodeParent = parent.getParentOrThrow();\n let indentLevel = 0;\n while ($isListItemNode(listNodeParent)) {\n listNodeParent = listNodeParent.getParentOrThrow().getParentOrThrow();\n indentLevel++;\n }\n\n return indentLevel;\n }\n\n override setIndent(indent: number): this {\n let currentIndent = this.getIndent();\n while (currentIndent !== indent) {\n if (currentIndent < indent) {\n $handleIndent([this]);\n currentIndent++;\n } else {\n $handleOutdent([this]);\n currentIndent--;\n }\n }\n\n return this;\n }\n\n override canIndent(): false {\n // Indent/outdent is handled specifically in the RichText logic.\n\n return false;\n }\n\n override insertBefore(nodeToInsert: LexicalNode): LexicalNode {\n if ($isListItemNode(nodeToInsert)) {\n const parent = this.getParentOrThrow();\n\n if ($isListNode(parent)) {\n const siblings = this.getNextSiblings();\n updateChildrenListItemValue(parent, siblings);\n }\n }\n\n return super.insertBefore(nodeToInsert);\n }\n\n override canInsertAfter(node: LexicalNode): boolean {\n return $isListNode(node);\n }\n\n override canReplaceWith(replacement: LexicalNode): boolean {\n return $isListItemNode(replacement);\n }\n\n override canMergeWith(node: LexicalNode): boolean {\n return $isParagraphNode(node) || $isListItemNode(node);\n }\n\n override extractWithChild(child: LexicalNode, selection: RangeSelection): boolean {\n if (!$isRangeSelection(selection)) {\n return false;\n }\n\n const anchorNode = selection.anchor.getNode();\n const focusNode = selection.focus.getNode();\n\n return (\n this.isParentOf(anchorNode) &&\n this.isParentOf(focusNode) &&\n this.getTextContent().length === selection.getTextContent().length\n );\n }\n}\n\nfunction $setListItemThemeClassNames(\n dom: HTMLElement,\n editorThemeClasses: EditorThemeClasses,\n node: ListItemNode\n): void {\n const classesToAdd = [];\n const classesToRemove = [];\n const listTheme = editorThemeClasses.list;\n const listItemClassName = listTheme ? listTheme.listitem : undefined;\n let nestedListItemClassName;\n\n if (listTheme && listTheme.nested) {\n nestedListItemClassName = listTheme.nested.listitem;\n }\n\n if (listItemClassName !== undefined) {\n const listItemClasses = listItemClassName.split(\" \");\n classesToAdd.push(...listItemClasses);\n }\n\n if (listTheme) {\n const parentNode = node.getParent();\n const isCheckList = $isListNode(parentNode) && parentNode?.getListType() === \"check\";\n const checked = node.getChecked();\n\n if (!isCheckList || checked) {\n classesToRemove.push(listTheme.listitemUnchecked);\n }\n\n if (!isCheckList || !checked) {\n classesToRemove.push(listTheme.listitemChecked);\n }\n\n if (isCheckList) {\n classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);\n }\n }\n\n if (nestedListItemClassName !== undefined) {\n const nestedListItemClasses = nestedListItemClassName.split(\" \");\n\n if (node.getChildren().some(child => $isListNode(child))) {\n classesToAdd.push(...nestedListItemClasses);\n } else {\n classesToRemove.push(...nestedListItemClasses);\n }\n }\n\n if (classesToRemove.length > 0) {\n removeClassNamesFromElement(dom, ...classesToRemove);\n }\n\n if (classesToAdd.length > 0) {\n addClassNamesToElement(dom, ...classesToAdd);\n }\n}\n\nfunction updateListItemChecked(\n dom: HTMLElement,\n listItemNode: ListItemNode,\n prevListItemNode: ListItemNode | null,\n listNode: ListNode\n): void {\n const isCheckList = listNode.getListType() === \"check\";\n\n if (isCheckList) {\n // Only add attributes for leaf list items\n if ($isListNode(listItemNode.getFirstChild())) {\n dom.removeAttribute(\"role\");\n dom.removeAttribute(\"tabIndex\");\n dom.removeAttribute(\"aria-checked\");\n } else {\n dom.setAttribute(\"role\", \"checkbox\");\n dom.setAttribute(\"tabIndex\", \"-1\");\n\n if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {\n dom.setAttribute(\"aria-checked\", listItemNode.getChecked() ? \"true\" : \"false\");\n }\n }\n } else {\n // Clean up checked state\n if (listItemNode.getChecked() != null) {\n listItemNode.setChecked(undefined);\n }\n }\n}\n\nfunction convertListItemElement(): DOMConversionOutput {\n return { node: $createListItemNode() };\n}\n\nexport function $createListItemNode(checked?: boolean): ListItemNode {\n return new ListItemNode(undefined, checked);\n}\n\nexport function $isListItemNode(node: LexicalNode | null | undefined): node is ListItemNode {\n return node instanceof ListItemNode;\n}\n"],"names":["LIST_ITEM_TYPE","ListItemNode","ElementNode","node","value","checked","key","undefined","config","element","document","parent","$isListNode","updateListItemChecked","$setListItemThemeClassNames","prevNode","dom","convertListItemElement","serializedNode","nodes","i","$isElementNode","children","replaceWithNode","includeChildren","$isListItemNode","list","newList","$createListNode","nextSibling","nodeToAppend","Error","child","listNode","console","siblings","after","afterListNode","updateChildrenListItemValue","newListNode","sibling","preserveEmptyParent","prevSibling","isNestedListNode","mergeLists","newElement","$createListItemNode","selection","paragraph","$createParagraphNode","listNodeParent","isIndented","anchor","focus","self","indentLevel","indent","currentIndent","$handleIndent","$handleOutdent","nodeToInsert","replacement","$isParagraphNode","$isRangeSelection","anchorNode","focusNode","editorThemeClasses","classesToAdd","classesToRemove","listTheme","listItemClassName","nestedListItemClassName","listItemClasses","parentNode","isCheckList","nestedListItemClasses","removeClassNamesFromElement","addClassNamesToElement","listItemNode","prevListItemNode"],"mappings":";;;;;AA8BO,MAAMA,iBAAiB;AAYvB,MAAMC,qBAAqBC;IAM9B,OAAgB,UAAkB;QAC9B,OAAOF;IACX;IAEA,OAAgB,MAAMG,IAAkB,EAAgB;QACpD,OAAO,IAAIF,aAAaE,KAAK,OAAO,EAAEA,KAAK,SAAS,EAAEA,KAAK,KAAK;IACpE;IAEA,YAAYC,KAAc,EAAEC,OAAiB,EAAEC,GAAa,CAAE;QAC1D,KAAK,CAACA;QACN,IAAI,CAAC,OAAO,GAAGF,AAAUG,WAAVH,QAAsB,IAAIA;QACzC,IAAI,CAAC,SAAS,GAAGC;IACrB;IAES,UAAUG,MAAoB,EAAe;QAClD,MAAMC,UAAUC,SAAS,aAAa,CAAC;QACvC,MAAMC,SAAS,IAAI,CAAC,SAAS;QAC7B,IAAIC,YAAYD,WAAWA,AAAyB,YAAzBA,OAAO,WAAW,IACzCE,sBAAsBJ,SAAS,IAAI,EAAE,MAAME;QAE/CF,QAAQ,KAAK,GAAG,IAAI,CAAC,OAAO;QAC5BK,4BAA4BL,SAASD,OAAO,KAAK,EAAE,IAAI;QAEvD,OAAOC;IACX;IAES,UAAUM,QAAsB,EAAEC,GAAgB,EAAER,MAAoB,EAAW;QACxF,MAAMG,SAAS,IAAI,CAAC,SAAS;QAC7B,IAAIC,YAAYD,WAAWA,AAAyB,YAAzBA,OAAO,WAAW,IACzCE,sBAAsBG,KAAK,IAAI,EAAED,UAAUJ;QAG/CK,IAAI,KAAK,GAAG,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E,MAAM6B;IAAsB;AACzC;AAEO,SAASA,oBAAoBzC,OAAiB;IACjD,OAAO,IAAIJ,aAAaM,QAAWF;AACvC;AAEO,SAASoB,gBAAgBtB,IAAoC;IAChE,OAAOA,gBAAgBF;AAC3B"}
|
package/ListNode.js
CHANGED
|
@@ -2,242 +2,193 @@ import { ElementNode, addClassNamesToElement, removeClassNamesFromElement } from
|
|
|
2
2
|
import { Theme } from "@webiny/lexical-theme";
|
|
3
3
|
import { $getListDepth, wrapInListItem } from "./utils/listNode.js";
|
|
4
4
|
import { $isListItemNode } from "./ListItemNode.js";
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
5
|
+
class ListNode extends ElementNode {
|
|
6
|
+
constructor(listType, options = {}){
|
|
7
|
+
const { styleId, key, className, start } = options;
|
|
8
|
+
super(key);
|
|
9
|
+
this.__styleId = styleId ?? "";
|
|
10
|
+
this.__className = className;
|
|
11
|
+
const _listType = TAG_TO_WEBINY_LIST_TYPE[listType] || listType;
|
|
12
|
+
this.__listType = _listType;
|
|
13
|
+
this.__tag = "number" === _listType ? "ol" : "ul";
|
|
14
|
+
this.__start = start || 1;
|
|
15
|
+
}
|
|
16
|
+
static getType() {
|
|
17
|
+
return "wby-list";
|
|
18
|
+
}
|
|
19
|
+
createDOM(config) {
|
|
20
|
+
const tag = this.__tag;
|
|
21
|
+
const element = document.createElement(tag);
|
|
22
|
+
if (1 !== this.__start) element.setAttribute("start", String(this.__start));
|
|
23
|
+
this.updateElementWithThemeClasses(element, Theme.from(config.theme));
|
|
24
|
+
element.__lexicalListType = this.__listType;
|
|
25
|
+
const theme = Theme.from(config.theme);
|
|
26
|
+
setListThemeClassNames(element, theme, this, this.__styleId);
|
|
27
|
+
return element;
|
|
28
|
+
}
|
|
29
|
+
exportDOM(editor) {
|
|
30
|
+
const base = super.exportDOM(editor);
|
|
31
|
+
const element = base.element;
|
|
32
|
+
if (element && this.__className) element.classList.add(this.__className);
|
|
33
|
+
return {
|
|
34
|
+
...base,
|
|
35
|
+
element
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
static clone(node) {
|
|
39
|
+
return new ListNode(node.getListType(), {
|
|
40
|
+
className: node.getClassName(),
|
|
41
|
+
styleId: node.getStyleId(),
|
|
42
|
+
start: node.getStart(),
|
|
43
|
+
key: node.getKey()
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
getStyleId() {
|
|
47
|
+
return this.__styleId;
|
|
48
|
+
}
|
|
49
|
+
setStyleId(styleId) {
|
|
50
|
+
this.__styleId = styleId ?? "";
|
|
51
|
+
}
|
|
52
|
+
setClassName(className) {
|
|
53
|
+
this.__className = className;
|
|
54
|
+
}
|
|
55
|
+
getClassName() {
|
|
56
|
+
return this.__className;
|
|
57
|
+
}
|
|
58
|
+
static importJSON(serializedNode) {
|
|
59
|
+
const node = $createListNode(serializedNode.listType, serializedNode.styleId ?? serializedNode.styleId, serializedNode.start);
|
|
60
|
+
node.setFormat(serializedNode.format);
|
|
61
|
+
node.setIndent(serializedNode.indent);
|
|
62
|
+
node.setDirection(serializedNode.direction);
|
|
63
|
+
node.setClassName(serializedNode.className);
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
66
|
+
exportJSON() {
|
|
67
|
+
return {
|
|
68
|
+
...super.exportJSON(),
|
|
69
|
+
styleId: this.__styleId,
|
|
70
|
+
className: this.__className,
|
|
71
|
+
listType: this.getListType(),
|
|
72
|
+
start: this.getStart(),
|
|
73
|
+
tag: this.getTag(),
|
|
74
|
+
type: "wby-list"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static importDomConversionMap() {
|
|
78
|
+
return {
|
|
79
|
+
conversion: convertListNode,
|
|
80
|
+
priority: 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
static importDOM() {
|
|
84
|
+
return {
|
|
85
|
+
ol: ()=>this.importDomConversionMap(),
|
|
86
|
+
ul: ()=>this.importDomConversionMap()
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
updateDOM(prevNode, dom, config) {
|
|
90
|
+
if (prevNode.__tag !== this.__tag) return true;
|
|
91
|
+
setListThemeClassNames(dom, Theme.from(config.theme), this, this.__styleId);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
extractWithChild(child) {
|
|
95
|
+
return $isListItemNode(child);
|
|
96
|
+
}
|
|
97
|
+
getListType() {
|
|
98
|
+
return this.__listType;
|
|
99
|
+
}
|
|
100
|
+
getStart() {
|
|
101
|
+
return this.__start;
|
|
102
|
+
}
|
|
103
|
+
getTag() {
|
|
104
|
+
return this.__tag;
|
|
105
|
+
}
|
|
106
|
+
updateElementWithThemeClasses(element, theme) {
|
|
107
|
+
if (!this.__styleId || !this.__className) this.setDefaultTypography(theme);
|
|
108
|
+
if (this.__className) addClassNamesToElement(element, this.__className);
|
|
109
|
+
return element;
|
|
110
|
+
}
|
|
111
|
+
setDefaultTypography(theme) {
|
|
112
|
+
const typographyStyle = theme.getTypographyByTag(this.getTag());
|
|
113
|
+
if (typographyStyle) {
|
|
114
|
+
this.__styleId = typographyStyle.id;
|
|
115
|
+
this.__className = typographyStyle.className;
|
|
116
|
+
}
|
|
49
117
|
}
|
|
50
|
-
return {
|
|
51
|
-
...base,
|
|
52
|
-
element
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
static clone(node) {
|
|
56
|
-
return new ListNode(node.getListType(), {
|
|
57
|
-
className: node.getClassName(),
|
|
58
|
-
styleId: node.getStyleId(),
|
|
59
|
-
start: node.getStart(),
|
|
60
|
-
key: node.getKey()
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
getStyleId() {
|
|
64
|
-
return this.__styleId;
|
|
65
|
-
}
|
|
66
|
-
setStyleId(styleId) {
|
|
67
|
-
this.__styleId = styleId ?? "";
|
|
68
|
-
}
|
|
69
|
-
setClassName(className) {
|
|
70
|
-
this.__className = className;
|
|
71
|
-
}
|
|
72
|
-
getClassName() {
|
|
73
|
-
return this.__className;
|
|
74
|
-
}
|
|
75
|
-
static importJSON(serializedNode) {
|
|
76
|
-
const node = $createListNode(serializedNode.listType,
|
|
77
|
-
// `styleId` is for backwards compatibility
|
|
78
|
-
serializedNode.styleId ?? serializedNode.styleId, serializedNode.start);
|
|
79
|
-
node.setFormat(serializedNode.format);
|
|
80
|
-
node.setIndent(serializedNode.indent);
|
|
81
|
-
node.setDirection(serializedNode.direction);
|
|
82
|
-
node.setClassName(serializedNode.className);
|
|
83
|
-
return node;
|
|
84
|
-
}
|
|
85
|
-
exportJSON() {
|
|
86
|
-
return {
|
|
87
|
-
...super.exportJSON(),
|
|
88
|
-
styleId: this.__styleId,
|
|
89
|
-
className: this.__className,
|
|
90
|
-
listType: this.getListType(),
|
|
91
|
-
start: this.getStart(),
|
|
92
|
-
tag: this.getTag(),
|
|
93
|
-
type: "wby-list"
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
static importDomConversionMap() {
|
|
97
|
-
return {
|
|
98
|
-
conversion: convertListNode,
|
|
99
|
-
priority: 0
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
static importDOM() {
|
|
103
|
-
return {
|
|
104
|
-
ol: () => {
|
|
105
|
-
return this.importDomConversionMap();
|
|
106
|
-
},
|
|
107
|
-
ul: () => {
|
|
108
|
-
return this.importDomConversionMap();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
updateDOM(prevNode, dom, config) {
|
|
113
|
-
if (prevNode.__tag !== this.__tag) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
setListThemeClassNames(dom, Theme.from(config.theme), this, this.__styleId);
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
extractWithChild(child) {
|
|
120
|
-
return $isListItemNode(child);
|
|
121
|
-
}
|
|
122
|
-
getListType() {
|
|
123
|
-
return this.__listType;
|
|
124
|
-
}
|
|
125
|
-
getStart() {
|
|
126
|
-
return this.__start;
|
|
127
|
-
}
|
|
128
|
-
getTag() {
|
|
129
|
-
return this.__tag;
|
|
130
|
-
}
|
|
131
|
-
updateElementWithThemeClasses(element, theme) {
|
|
132
|
-
if (!this.__styleId || !this.__className) {
|
|
133
|
-
this.setDefaultTypography(theme);
|
|
134
|
-
}
|
|
135
|
-
if (this.__className) {
|
|
136
|
-
addClassNamesToElement(element, this.__className);
|
|
137
|
-
}
|
|
138
|
-
return element;
|
|
139
|
-
}
|
|
140
|
-
setDefaultTypography(theme) {
|
|
141
|
-
const typographyStyle = theme.getTypographyByTag(this.getTag());
|
|
142
|
-
if (typographyStyle) {
|
|
143
|
-
this.__styleId = typographyStyle.id;
|
|
144
|
-
this.__className = typographyStyle.className;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
118
|
}
|
|
148
119
|
function setListThemeClassNames(dom, theme, node, styleId) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (listLevelClassName !== undefined) {
|
|
168
|
-
const listItemClasses = listLevelClassName.split(" ");
|
|
169
|
-
classesToAdd.push(...listItemClasses);
|
|
170
|
-
for (let i = 0; i < listLevelsClassNames.length; i++) {
|
|
171
|
-
if (i !== normalizedListDepth) {
|
|
172
|
-
classesToRemove.push(node.__tag + i);
|
|
120
|
+
const classesToAdd = [];
|
|
121
|
+
const classesToRemove = [];
|
|
122
|
+
const listTheme = theme.tokens.list;
|
|
123
|
+
if (void 0 !== listTheme) {
|
|
124
|
+
const listTypography = theme.getTypographyById(styleId);
|
|
125
|
+
const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];
|
|
126
|
+
const listDepth = $getListDepth(node) - 1;
|
|
127
|
+
const normalizedListDepth = listDepth % listLevelsClassNames.length;
|
|
128
|
+
const listLevelClassName = listLevelsClassNames[normalizedListDepth];
|
|
129
|
+
const listClassName = `${listTheme[node.__tag]} ${listTypography?.className ?? ""}`;
|
|
130
|
+
let nestedListClassName;
|
|
131
|
+
const nestedListTheme = listTheme.nested;
|
|
132
|
+
if (void 0 !== nestedListTheme && nestedListTheme.list) nestedListClassName = nestedListTheme.list;
|
|
133
|
+
if (listClassName) classesToAdd.push(listClassName);
|
|
134
|
+
if (void 0 !== listLevelClassName) {
|
|
135
|
+
const listItemClasses = listLevelClassName.split(" ");
|
|
136
|
+
classesToAdd.push(...listItemClasses);
|
|
137
|
+
for(let i = 0; i < listLevelsClassNames.length; i++)if (i !== normalizedListDepth) classesToRemove.push(node.__tag + i);
|
|
173
138
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (classesToRemove.length > 0) {
|
|
186
|
-
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
187
|
-
}
|
|
188
|
-
if (classesToAdd.length > 0) {
|
|
189
|
-
addClassNamesToElement(dom, ...classesToAdd);
|
|
190
|
-
}
|
|
139
|
+
if (void 0 !== nestedListClassName) {
|
|
140
|
+
const nestedListItemClasses = nestedListClassName.split(" ");
|
|
141
|
+
if (listDepth > 1) classesToAdd.push(...nestedListItemClasses);
|
|
142
|
+
else classesToRemove.push(...nestedListItemClasses);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (classesToRemove.length > 0) removeClassNamesFromElement(dom, ...classesToRemove);
|
|
146
|
+
if (classesToAdd.length > 0) addClassNamesToElement(dom, ...classesToAdd);
|
|
191
147
|
}
|
|
192
|
-
|
|
193
|
-
/*
|
|
194
|
-
* This function normalizes the children of a ListNode after the conversion from HTML,
|
|
195
|
-
* ensuring that they are all ListItemNodes and contain either a single nested ListNode
|
|
196
|
-
* or some other inline content.
|
|
197
|
-
*/
|
|
198
148
|
function normalizeChildren(nodes) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
} else {
|
|
210
|
-
normalizedListItems.push(wrapInListItem(node));
|
|
149
|
+
const normalizedListItems = [];
|
|
150
|
+
for(let i = 0; i < nodes.length; i++){
|
|
151
|
+
const node = nodes[i];
|
|
152
|
+
if ($isListItemNode(node)) {
|
|
153
|
+
normalizedListItems.push(node);
|
|
154
|
+
node.getChildren().forEach((child)=>{
|
|
155
|
+
if ($isListNode(child)) normalizedListItems.push(wrapInListItem(child));
|
|
156
|
+
});
|
|
157
|
+
} else normalizedListItems.push(wrapInListItem(node));
|
|
211
158
|
}
|
|
212
|
-
|
|
213
|
-
return normalizedListItems;
|
|
159
|
+
return normalizedListItems;
|
|
214
160
|
}
|
|
215
161
|
function convertListNode(domNode) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
node = $createListNode("
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
162
|
+
const nodeName = domNode.nodeName.toLowerCase();
|
|
163
|
+
let node = null;
|
|
164
|
+
if ("ol" === nodeName) node = $createListNode("number");
|
|
165
|
+
else if ("ul" === nodeName) node = $createListNode("bullet");
|
|
166
|
+
return {
|
|
167
|
+
after: (nodes)=>{
|
|
168
|
+
const normalized = normalizeChildren(nodes);
|
|
169
|
+
let value = 1;
|
|
170
|
+
for (const item of normalized)if ($isListItemNode(item) && !$isListNode(item.getFirstChild())) {
|
|
171
|
+
item.setValue(value);
|
|
172
|
+
value++;
|
|
173
|
+
}
|
|
174
|
+
return normalized;
|
|
175
|
+
},
|
|
176
|
+
node
|
|
177
|
+
};
|
|
228
178
|
}
|
|
229
179
|
const TAG_TO_WEBINY_LIST_TYPE = {
|
|
230
|
-
|
|
231
|
-
|
|
180
|
+
ol: "number",
|
|
181
|
+
ul: "bullet"
|
|
232
182
|
};
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
183
|
+
function $createListNode(listType, styleId, start = 1) {
|
|
184
|
+
return new ListNode(listType, {
|
|
185
|
+
start,
|
|
186
|
+
styleId
|
|
187
|
+
});
|
|
238
188
|
}
|
|
239
|
-
|
|
240
|
-
|
|
189
|
+
function $isListNode(node) {
|
|
190
|
+
return node instanceof ListNode;
|
|
241
191
|
}
|
|
192
|
+
export { $createListNode, $isListNode, ListNode };
|
|
242
193
|
|
|
243
194
|
//# sourceMappingURL=ListNode.js.map
|
package/ListNode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ElementNode","addClassNamesToElement","removeClassNamesFromElement","Theme","$getListDepth","wrapInListItem","$isListItemNode","ListNode","constructor","listType","options","styleId","key","className","start","__styleId","__className","_listType","TAG_TO_WEBINY_LIST_TYPE","__listType","__tag","__start","getType","createDOM","config","tag","element","document","createElement","setAttribute","String","updateElementWithThemeClasses","from","theme","__lexicalListType","setListThemeClassNames","exportDOM","editor","base","classList","add","clone","node","getListType","getClassName","getStyleId","getStart","getKey","setStyleId","setClassName","importJSON","serializedNode","$createListNode","setFormat","format","setIndent","indent","setDirection","direction","exportJSON","getTag","type","importDomConversionMap","conversion","convertListNode","priority","importDOM","ol","ul","updateDOM","prevNode","dom","extractWithChild","child","setDefaultTypography","typographyStyle","getTypographyByTag","id","classesToAdd","classesToRemove","listTheme","tokens","list","undefined","listTypography","getTypographyById","listLevelsClassNames","listDepth","normalizedListDepth","length","listLevelClassName","listClassName","nestedListClassName","nestedListTheme","nested","push","listItemClasses","split","i","nestedListItemClasses","normalizeChildren","nodes","normalizedListItems","getChildren","forEach","$isListNode","domNode","nodeName","toLowerCase","after"],"sources":["ListNode.ts"],"sourcesContent":["import type {\n DOMConversion,\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport { ElementNode, addClassNamesToElement, removeClassNamesFromElement } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { ListNodeTagType } from \"@lexical/list\";\nimport { $getListDepth, wrapInListItem } from \"~/utils/listNode.js\";\nimport type { ListItemNode } from \"./ListItemNode.js\";\nimport { $isListItemNode } from \"./ListItemNode.js\";\nimport type { ListType } from \"@lexical/list\";\nimport type { TypographyStylesNode } from \"~/types.js\";\n\nexport type SerializedWebinyListNode = Spread<\n {\n styleId?: string;\n className?: string;\n listType: ListType;\n start: number;\n tag: ListNodeTagType;\n type: \"wby-list\";\n },\n SerializedElementNode\n>;\n\ntype ListNodeOptions = {\n styleId?: string;\n className?: string;\n start?: number;\n key?: NodeKey;\n};\n\nexport class ListNode extends ElementNode implements TypographyStylesNode {\n /** @internal */\n __tag: ListNodeTagType;\n /** @internal */\n __start: number;\n /** @internal */\n __listType: ListType;\n\n private __styleId: string;\n private __className: string | undefined;\n\n constructor(listType: ListType, options: ListNodeOptions = {}) {\n const { styleId, key, className, start } = options;\n super(key);\n this.__styleId = styleId ?? \"\";\n this.__className = className;\n const _listType = TAG_TO_WEBINY_LIST_TYPE[listType] || listType;\n this.__listType = _listType;\n this.__tag = _listType === \"number\" ? \"ol\" : \"ul\";\n this.__start = start || 1;\n }\n\n static override getType() {\n return \"wby-list\";\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const tag = this.__tag;\n const element = document.createElement(tag);\n\n if (this.__start !== 1) {\n element.setAttribute(\"start\", String(this.__start));\n }\n\n this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n\n // @ts-expect-error Internal field.\n element.__lexicalListType = this.__listType;\n const theme = Theme.from(config.theme);\n setListThemeClassNames(element, theme, this, this.__styleId);\n return element;\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n static override clone(node: ListNode): ListNode {\n return new ListNode(node.getListType(), {\n className: node.getClassName(),\n styleId: node.getStyleId(),\n start: node.getStart(),\n key: node.getKey()\n });\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId ?? \"\";\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n static override importJSON(serializedNode: SerializedWebinyListNode): ListNode {\n const node = $createListNode(\n serializedNode.listType,\n // `styleId` is for backwards compatibility\n serializedNode.styleId ?? serializedNode.styleId,\n serializedNode.start\n );\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n node.setClassName(serializedNode.className);\n\n return node;\n }\n\n override exportJSON(): SerializedWebinyListNode {\n return {\n ...super.exportJSON(),\n styleId: this.__styleId,\n className: this.__className,\n listType: this.getListType(),\n start: this.getStart(),\n tag: this.getTag(),\n type: \"wby-list\"\n };\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertListNode,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n ol: () => {\n return this.importDomConversionMap();\n },\n ul: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n override updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean {\n if (prevNode.__tag !== this.__tag) {\n return true;\n }\n\n setListThemeClassNames(dom, Theme.from(config.theme), this, this.__styleId);\n return false;\n }\n\n override extractWithChild(child: LexicalNode): boolean {\n return $isListItemNode(child);\n }\n\n public getListType(): ListType {\n return this.__listType;\n }\n\n public getStart(): number {\n return this.__start;\n }\n\n private getTag(): ListNodeTagType {\n return this.__tag;\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n\n private setDefaultTypography(theme: Theme) {\n const typographyStyle = theme.getTypographyByTag(this.getTag());\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n}\n\nfunction setListThemeClassNames(\n dom: HTMLElement,\n theme: Theme,\n node: ListNode,\n styleId: string\n): void {\n const classesToAdd = [];\n const classesToRemove = [];\n const listTheme = theme.tokens.list;\n if (listTheme !== undefined) {\n const listTypography = theme.getTypographyById(styleId);\n const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];\n const listDepth = $getListDepth(node) - 1;\n const normalizedListDepth = listDepth % listLevelsClassNames.length;\n const listLevelClassName = listLevelsClassNames[normalizedListDepth];\n const listClassName = `${listTheme[node.__tag]} ${listTypography?.className ?? \"\"}`;\n let nestedListClassName;\n const nestedListTheme = listTheme.nested;\n\n if (nestedListTheme !== undefined && nestedListTheme.list) {\n nestedListClassName = nestedListTheme.list;\n }\n\n if (listClassName) {\n classesToAdd.push(listClassName);\n }\n\n if (listLevelClassName !== undefined) {\n const listItemClasses = listLevelClassName.split(\" \");\n classesToAdd.push(...listItemClasses);\n for (let i = 0; i < listLevelsClassNames.length; i++) {\n if (i !== normalizedListDepth) {\n classesToRemove.push(node.__tag + i);\n }\n }\n }\n\n if (nestedListClassName !== undefined) {\n const nestedListItemClasses = nestedListClassName.split(\" \");\n\n if (listDepth > 1) {\n classesToAdd.push(...nestedListItemClasses);\n } else {\n classesToRemove.push(...nestedListItemClasses);\n }\n }\n }\n\n if (classesToRemove.length > 0) {\n removeClassNamesFromElement(dom, ...classesToRemove);\n }\n\n if (classesToAdd.length > 0) {\n addClassNamesToElement(dom, ...classesToAdd);\n }\n}\n\n/*\n * This function normalizes the children of a ListNode after the conversion from HTML,\n * ensuring that they are all ListItemNodes and contain either a single nested ListNode\n * or some other inline content.\n */\nfunction normalizeChildren(nodes: Array<ListNode>): Array<ListItemNode> {\n const normalizedListItems: Array<ListItemNode> = [];\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if ($isListItemNode(node)) {\n normalizedListItems.push(node);\n node.getChildren().forEach(child => {\n if ($isListNode(child)) {\n normalizedListItems.push(wrapInListItem(child));\n }\n });\n } else {\n normalizedListItems.push(wrapInListItem(node));\n }\n }\n return normalizedListItems;\n}\n\nfunction convertListNode(domNode: Node): DOMConversionOutput {\n const nodeName = domNode.nodeName.toLowerCase();\n let node = null;\n\n if (nodeName === \"ol\") {\n node = $createListNode(\"number\");\n } else if (nodeName === \"ul\") {\n node = $createListNode(\"bullet\");\n }\n\n return {\n // @ts-expect-error\n after: normalizeChildren,\n node\n };\n}\n\nconst TAG_TO_WEBINY_LIST_TYPE: Record<string, ListType> = {\n ol: \"number\",\n ul: \"bullet\"\n};\n\nexport function $createListNode(listType: ListType, styleId?: string, start = 1): ListNode {\n return new ListNode(listType, {\n start,\n styleId\n });\n}\n\nexport function $isListNode(node: LexicalNode | null | undefined): node is ListNode {\n return node instanceof ListNode;\n}\n"],"mappings":"AAYA,SAASA,WAAW,EAAE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AAC;EAC/C,IAAIlE,IAAI,GAAG,IAAI;EAEf,IAAIiE,QAAQ,KAAK,IAAI,EAAE;IACnBjE,IAAI,GAAGU,eAAe,CAAC,QAAQ,CAAC;EACpC,CAAC,MAAM,IAAIuD,QAAQ,KAAK,IAAI,EAAE;IAC1BjE,IAAI,GAAGU,eAAe,CAAC,QAAQ,CAAC;EACpC;EAEA,OAAO;IACH;IACAyD,KAAK,EAAET,iBAAiB;IACxB1D;EACJ,CAAC;AACL;AAEA,MAAMxB,uBAAiD,GAAG;EACtDiD,EAAE,EAAE,QAAQ;EACZC,EAAE,EAAE;AACR,CAAC;AAED,OAAO,SAAShB,eAAeA,CAAC3C,QAAkB,EAAEE,OAAgB,EAAEG,KAAK,GAAG,CAAC,EAAY;EACvF,OAAO,IAAIP,QAAQ,CAACE,QAAQ,EAAE;IAC1BK,KAAK;IACLH;EACJ,CAAC,CAAC;AACN;AAEA,OAAO,SAAS8F,WAAWA,CAAC/D,IAAoC,EAAoB;EAChF,OAAOA,IAAI,YAAYnC,QAAQ;AACnC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ListNode.js","sources":["../src/ListNode.ts"],"sourcesContent":["import type {\n DOMConversion,\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n EditorConfig,\n LexicalEditor,\n LexicalNode,\n NodeKey,\n SerializedElementNode,\n Spread\n} from \"lexical\";\nimport { ElementNode, addClassNamesToElement, removeClassNamesFromElement } from \"lexical\";\nimport { Theme } from \"@webiny/lexical-theme\";\nimport type { ListNodeTagType } from \"@lexical/list\";\nimport { $getListDepth, wrapInListItem } from \"~/utils/listNode.js\";\nimport type { ListItemNode } from \"./ListItemNode.js\";\nimport { $isListItemNode } from \"./ListItemNode.js\";\nimport type { ListType } from \"@lexical/list\";\nimport type { TypographyStylesNode } from \"~/types.js\";\n\nexport type SerializedWebinyListNode = Spread<\n {\n styleId?: string;\n className?: string;\n listType: ListType;\n start: number;\n tag: ListNodeTagType;\n type: \"wby-list\";\n },\n SerializedElementNode\n>;\n\ntype ListNodeOptions = {\n styleId?: string;\n className?: string;\n start?: number;\n key?: NodeKey;\n};\n\nexport class ListNode extends ElementNode implements TypographyStylesNode {\n /** @internal */\n __tag: ListNodeTagType;\n /** @internal */\n __start: number;\n /** @internal */\n __listType: ListType;\n\n private __styleId: string;\n private __className: string | undefined;\n\n constructor(listType: ListType, options: ListNodeOptions = {}) {\n const { styleId, key, className, start } = options;\n super(key);\n this.__styleId = styleId ?? \"\";\n this.__className = className;\n const _listType = TAG_TO_WEBINY_LIST_TYPE[listType] || listType;\n this.__listType = _listType;\n this.__tag = _listType === \"number\" ? \"ol\" : \"ul\";\n this.__start = start || 1;\n }\n\n static override getType() {\n return \"wby-list\";\n }\n\n override createDOM(config: EditorConfig): HTMLElement {\n const tag = this.__tag;\n const element = document.createElement(tag);\n\n if (this.__start !== 1) {\n element.setAttribute(\"start\", String(this.__start));\n }\n\n this.updateElementWithThemeClasses(element, Theme.from(config.theme));\n\n // @ts-expect-error Internal field.\n element.__lexicalListType = this.__listType;\n const theme = Theme.from(config.theme);\n setListThemeClassNames(element, theme, this, this.__styleId);\n return element;\n }\n\n override exportDOM(editor: LexicalEditor): DOMExportOutput {\n const base = super.exportDOM(editor);\n\n const element = base.element as HTMLElement;\n if (element && this.__className) {\n element.classList.add(this.__className);\n }\n\n return { ...base, element };\n }\n\n static override clone(node: ListNode): ListNode {\n return new ListNode(node.getListType(), {\n className: node.getClassName(),\n styleId: node.getStyleId(),\n start: node.getStart(),\n key: node.getKey()\n });\n }\n\n getStyleId(): string | undefined {\n return this.__styleId;\n }\n\n setStyleId(styleId: string | undefined) {\n this.__styleId = styleId ?? \"\";\n }\n\n setClassName(className: string | undefined) {\n this.__className = className;\n }\n\n getClassName(): string | undefined {\n return this.__className;\n }\n\n static override importJSON(serializedNode: SerializedWebinyListNode): ListNode {\n const node = $createListNode(\n serializedNode.listType,\n // `styleId` is for backwards compatibility\n serializedNode.styleId ?? serializedNode.styleId,\n serializedNode.start\n );\n node.setFormat(serializedNode.format);\n node.setIndent(serializedNode.indent);\n node.setDirection(serializedNode.direction);\n\n node.setClassName(serializedNode.className);\n\n return node;\n }\n\n override exportJSON(): SerializedWebinyListNode {\n return {\n ...super.exportJSON(),\n styleId: this.__styleId,\n className: this.__className,\n listType: this.getListType(),\n start: this.getStart(),\n tag: this.getTag(),\n type: \"wby-list\"\n };\n }\n\n static importDomConversionMap(): DOMConversion<HTMLElement> | null {\n return {\n conversion: convertListNode,\n priority: 0\n };\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n ol: () => {\n return this.importDomConversionMap();\n },\n ul: () => {\n return this.importDomConversionMap();\n }\n };\n }\n\n override updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean {\n if (prevNode.__tag !== this.__tag) {\n return true;\n }\n\n setListThemeClassNames(dom, Theme.from(config.theme), this, this.__styleId);\n return false;\n }\n\n override extractWithChild(child: LexicalNode): boolean {\n return $isListItemNode(child);\n }\n\n public getListType(): ListType {\n return this.__listType;\n }\n\n public getStart(): number {\n return this.__start;\n }\n\n private getTag(): ListNodeTagType {\n return this.__tag;\n }\n\n protected updateElementWithThemeClasses(element: HTMLElement, theme: Theme): HTMLElement {\n if (!this.__styleId || !this.__className) {\n this.setDefaultTypography(theme);\n }\n\n if (this.__className) {\n addClassNamesToElement(element, this.__className);\n }\n\n return element;\n }\n\n private setDefaultTypography(theme: Theme) {\n const typographyStyle = theme.getTypographyByTag(this.getTag());\n if (typographyStyle) {\n this.__styleId = typographyStyle.id;\n this.__className = typographyStyle.className;\n }\n }\n}\n\nfunction setListThemeClassNames(\n dom: HTMLElement,\n theme: Theme,\n node: ListNode,\n styleId: string\n): void {\n const classesToAdd = [];\n const classesToRemove = [];\n const listTheme = theme.tokens.list;\n if (listTheme !== undefined) {\n const listTypography = theme.getTypographyById(styleId);\n const listLevelsClassNames = listTheme[`${node.__tag}Depth`] || [];\n const listDepth = $getListDepth(node) - 1;\n const normalizedListDepth = listDepth % listLevelsClassNames.length;\n const listLevelClassName = listLevelsClassNames[normalizedListDepth];\n const listClassName = `${listTheme[node.__tag]} ${listTypography?.className ?? \"\"}`;\n let nestedListClassName;\n const nestedListTheme = listTheme.nested;\n\n if (nestedListTheme !== undefined && nestedListTheme.list) {\n nestedListClassName = nestedListTheme.list;\n }\n\n if (listClassName) {\n classesToAdd.push(listClassName);\n }\n\n if (listLevelClassName !== undefined) {\n const listItemClasses = listLevelClassName.split(\" \");\n classesToAdd.push(...listItemClasses);\n for (let i = 0; i < listLevelsClassNames.length; i++) {\n if (i !== normalizedListDepth) {\n classesToRemove.push(node.__tag + i);\n }\n }\n }\n\n if (nestedListClassName !== undefined) {\n const nestedListItemClasses = nestedListClassName.split(\" \");\n\n if (listDepth > 1) {\n classesToAdd.push(...nestedListItemClasses);\n } else {\n classesToRemove.push(...nestedListItemClasses);\n }\n }\n }\n\n if (classesToRemove.length > 0) {\n removeClassNamesFromElement(dom, ...classesToRemove);\n }\n\n if (classesToAdd.length > 0) {\n addClassNamesToElement(dom, ...classesToAdd);\n }\n}\n\n/*\n * This function normalizes the children of a ListNode after the conversion from HTML,\n * ensuring that they are all ListItemNodes and contain either a single nested ListNode\n * or some other inline content.\n */\nfunction normalizeChildren(nodes: Array<ListNode>): Array<ListItemNode> {\n const normalizedListItems: Array<ListItemNode> = [];\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n if ($isListItemNode(node)) {\n normalizedListItems.push(node);\n node.getChildren().forEach(child => {\n if ($isListNode(child)) {\n normalizedListItems.push(wrapInListItem(child));\n }\n });\n } else {\n normalizedListItems.push(wrapInListItem(node));\n }\n }\n return normalizedListItems;\n}\n\nfunction convertListNode(domNode: Node): DOMConversionOutput {\n const nodeName = domNode.nodeName.toLowerCase();\n let node = null;\n\n if (nodeName === \"ol\") {\n node = $createListNode(\"number\");\n } else if (nodeName === \"ul\") {\n node = $createListNode(\"bullet\");\n }\n\n return {\n // @ts-expect-error\n after: (nodes: Array<ListNode>) => {\n const normalized = normalizeChildren(nodes);\n let value = 1;\n for (const item of normalized) {\n if ($isListItemNode(item) && !$isListNode(item.getFirstChild())) {\n item.setValue(value);\n value++;\n }\n }\n return normalized;\n },\n node\n };\n}\n\nconst TAG_TO_WEBINY_LIST_TYPE: Record<string, ListType> = {\n ol: \"number\",\n ul: \"bullet\"\n};\n\nexport function $createListNode(listType: ListType, styleId?: string, start = 1): ListNode {\n return new ListNode(listType, {\n start,\n styleId\n });\n}\n\nexport function $isListNode(node: LexicalNode | null | undefined): node is ListNode {\n return node instanceof ListNode;\n}\n"],"names":["ListNode","ElementNode","listType","options","styleId","key","className","start","_listType","TAG_TO_WEBINY_LIST_TYPE","config","tag","element","document","String","Theme","theme","setListThemeClassNames","editor","base","node","serializedNode","$createListNode","convertListNode","prevNode","dom","child","$isListItemNode","addClassNamesToElement","typographyStyle","classesToAdd","classesToRemove","listTheme","undefined","listTypography","listLevelsClassNames","listDepth","$getListDepth","normalizedListDepth","listLevelClassName","listClassName","nestedListClassName","nestedListTheme","listItemClasses","i","nestedListItemClasses","removeClassNamesFromElement","normalizeChildren","nodes","normalizedListItems","$isListNode","wrapInListItem","domNode","nodeName","normalized","value","item"],"mappings":";;;;AAwCO,MAAMA,iBAAiBC;IAW1B,YAAYC,QAAkB,EAAEC,UAA2B,CAAC,CAAC,CAAE;QAC3D,MAAM,EAAEC,OAAO,EAAEC,GAAG,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGJ;QAC3C,KAAK,CAACE;QACN,IAAI,CAAC,SAAS,GAAGD,WAAW;QAC5B,IAAI,CAAC,WAAW,GAAGE;QACnB,MAAME,YAAYC,uBAAuB,CAACP,SAAS,IAAIA;QACvD,IAAI,CAAC,UAAU,GAAGM;QAClB,IAAI,CAAC,KAAK,GAAGA,AAAc,aAAdA,YAAyB,OAAO;QAC7C,IAAI,CAAC,OAAO,GAAGD,SAAS;IAC5B;IAEA,OAAgB,UAAU;QACtB,OAAO;IACX;IAES,UAAUG,MAAo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