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 styles when enter editor mode (#469)

Bogdan Chadkinf4f2a08eb132
diff --git a/apps/designer/app/canvas/features/text-editor/text-editor.tsx b/apps/designer/app/canvas/features/text-editor/text-editor.tsx
index a00aefa459..33414bda18 100644
--- a/apps/designer/app/canvas/features/text-editor/text-editor.tsx
+++ b/apps/designer/app/canvas/features/text-editor/text-editor.tsx
@@ -1,15 +1,32 @@
-import { useState } from "react";
+import { useState, useEffect } from "react";
import { LinkNode } from "@lexical/link";
import { LexicalComposer } from "@lexical/react/LexicalComposer";
+import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
import { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
import type { ChildrenUpdates, Instance } from "@webstudio-is/react-sdk";
+import { idAttribute } from "@webstudio-is/react-sdk";
import { ToolbarConnectorPlugin } from "./toolbar-connector";
import { type Refs, $convertToLexical, $convertToUpdates } from "./interop";
+const BindInstanceToNodePlugin = ({ refs }: { refs: Refs }) => {
+ const [editor] = useLexicalComposerContext();
+ useEffect(() => {
+ for (const [nodeKey, instance] of refs) {
+ // extract key from stored key:style format
+ const [key] = nodeKey.split(":");
+ const element = editor.getElementByKey(key);
+ if (element) {
+ element.setAttribute(idAttribute, instance.id);
+ }
+ }
+ }, [editor, refs]);
+ return null;
+};
+
const onError = (error: Error) => {
throw error;
};
@@ -44,6 +61,7 @@ export const TextEditor = ({
return (
<LexicalComposer initialConfig={initialConfig}>
<ToolbarConnectorPlugin />
+ <BindInstanceToNodePlugin refs={refs} />
<RichTextPlugin
ErrorBoundary={LexicalErrorBoundary}
contentEditable={contentEditable}
diff --git a/apps/designer/app/designer/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx b/apps/designer/app/designer/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx
index df673e234c..a2e59c9c5f 100644
--- a/apps/designer/app/designer/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx
+++ b/apps/designer/app/designer/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx
@@ -142,7 +142,7 @@ const Toolbar = ({ state, onToggle }: ToolbarProps) => {
top: 0,
left: 0,
pointerEvents: "auto",
- background: "white",
+ background: "$loContrast",
}}
>
<ToggleGroupItem value="bold">