Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix population lexical nodes with ws instnaces

Oleg Isonen8ee88400f45d
diff --git a/app/shared/text-editor/example-text-editor.tsx b/app/shared/text-editor/example-text-editor.tsx
index 5dc0092fcb..7cbc60430d 100644
--- a/app/shared/text-editor/example-text-editor.tsx
+++ b/app/shared/text-editor/example-text-editor.tsx
@@ -87,7 +87,17 @@ export const ExampleTextEditor = ({ onChange }: ExampleTextEditorProps) => {
/>
<OnChangePlugin onChange={onChange} />
<HistoryPlugin />
- <InstancePlugin>{["Something"]}</InstancePlugin>
+ <InstancePlugin>
+ {[
+ "Pragraph you can edit ",
+ {
+ component: "Bold",
+ id: "62bd56ad8f5562223cb85cc2",
+ cssRules: [],
+ children: ["bold"],
+ },
+ ]}
+ </InstancePlugin>
<TreeViewPlugin />
</div>
</LexicalComposer>
diff --git a/app/shared/text-editor/utils/to-lexical-nodes.tsx b/app/shared/text-editor/utils/to-lexical-nodes.tsx
index fb9c09930d..08b53ebd05 100644
--- a/app/shared/text-editor/utils/to-lexical-nodes.tsx
+++ b/app/shared/text-editor/utils/to-lexical-nodes.tsx
@@ -3,20 +3,27 @@ import { $createInstanceNode } from "../nodes/node-instance";
import { $createTextNode, $createParagraphNode } from "../lexical";
export const toLexicalNodes = (children: Instance["children"]) => {
- return children.map((child) => {
+ const nodes = [];
+
+ for (const child of children) {
if (typeof child === "string") {
const paragraph = $createParagraphNode();
- paragraph.append($createTextNode(child));
- return paragraph;
+ const textNode = $createTextNode(child);
+ paragraph.append(textNode);
+ nodes.push(paragraph);
+ continue;
}
// Inline components should always have a single child string
const text = typeof child.children[0] === "string" ? child.children[0] : "";
-
- return $createInstanceNode({
+ const paragraph = nodes[nodes.length - 1];
+ const instanceNode = $createInstanceNode({
instance: child,
text,
isNew: false,
});
- });
+ paragraph.append(instanceNode);
+ }
+
+ return nodes;
};