Skip to content

Commit

Permalink
Fix importDOM for Layout plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ivailop7 committed Nov 5, 2024
1 parent 86eba22 commit 7bb5ce6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/lexical-playground/src/nodes/LayoutItemNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type {
DOMConversionMap,
DOMConversionOutput,
EditorConfig,
LexicalNode,
SerializedElementNode,
Expand All @@ -18,6 +19,10 @@ import {ElementNode} from 'lexical';

export type SerializedLayoutItemNode = SerializedElementNode;

function $convertLayoutItemElement(): DOMConversionOutput | null {
return {node: $createLayoutItemNode()};
}

export class LayoutItemNode extends ElementNode {
static getType(): string {
return 'layout-item';
Expand All @@ -29,6 +34,7 @@ export class LayoutItemNode extends ElementNode {

createDOM(config: EditorConfig): HTMLElement {
const dom = document.createElement('div');
dom.setAttribute('data-lexical-layout-item', 'true');
if (typeof config.theme.layoutItem === 'string') {
addClassNamesToElement(dom, config.theme.layoutItem);
}
Expand All @@ -40,7 +46,17 @@ export class LayoutItemNode extends ElementNode {
}

static importDOM(): DOMConversionMap | null {
return {};
return {
div: (domNode: HTMLElement) => {
if (!domNode.hasAttribute('data-lexical-layout-item')) {
return null;
}
return {
conversion: $convertLayoutItemElement,
priority: 2,
};
},
};
}

static importJSON(): LayoutItemNode {
Expand Down

0 comments on commit 7bb5ce6

Please sign in to comment.