Lexical version: 0.33.1
Steps To Reproduce
- Override the CSS variable
--lexical-indent-base-value to 2em.
- Create a paragraph node and set its
indent value to 2.
- Export the node to DOM using exportDOM. The resulting DOM has
padding-inline-start: calc(2 * 2em) = 4em.
- Import the DOM back into the editor using importDOM. The
indent value on the imported LexicalParagraphNode becomes 0 (expected: 2)
Link to code example:
no
The current behavior
importDOM does not correctly infer the indent value from the padding-inline-start style or from the computed --lexical-indent-base-value. The imported node always falls back to indent = 0.
The expected behavior
When importing a DOM node with padding-inline-start: 4em and --lexical-indent-base-value: 2em, Lexical should correctly calculate and set indent = 2 on the resulting LexicalParagraphNode
Root Cause
In the LexicalParagraphNode.ts file, the importDOM method uses $convertParagraphElement to handle some import transformations. Among them, the setNodeIndentFromDOM function is responsible for processing the indentation level.
Inside the setNodeIndentFromDOM function, it determines the paragraph's indent level by dividing the element's paddingInlineStart by 40. However, this value 40 is hardcoded and does not change based on the --lexical-indent-base-value CSS variable.
position:facebook/lexical/packages/lexical/src/LexicalUtils.ts 1981:1
Impact of fix
- Affects all users relying on accurate round-trip import/export of indentation styles
Lexical version: 0.33.1
Steps To Reproduce
--lexical-indent-base-valueto2em.indentvalue to2.padding-inline-start: calc(2 * 2em) = 4em.indentvalue on the importedLexicalParagraphNodebecomes0 (expected: 2)Link to code example:
no
The current behavior
importDOM does not correctly infer the indent value from the
padding-inline-startstyle or from the computed--lexical-indent-base-value. The imported node always falls back toindent = 0.The expected behavior
When importing a DOM node with
padding-inline-start: 4emand--lexical-indent-base-value: 2em, Lexical should correctly calculate and setindent = 2on the resultingLexicalParagraphNodeRoot Cause
In the
LexicalParagraphNode.tsfile, theimportDOMmethod uses$convertParagraphElementto handle some import transformations. Among them, thesetNodeIndentFromDOMfunction is responsible for processing the indentation level.Inside the
setNodeIndentFromDOMfunction, it determines the paragraph's indent level by dividing the element's paddingInlineStart by40. However, this value40is hardcoded and does not change based on the--lexical-indent-base-valueCSS variable.position:facebook/lexical/packages/lexical/src/LexicalUtils.ts 1981:1
Impact of fix