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.

Drop legacy text editor (#416)

Bogdan Chadkina6f7a451bf81
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/config.ts b/apps/designer/app/canvas/features/wrapper-component/text-editor/config.ts
deleted file mode 100644
index d1c1b9adaf..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/config.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { InstanceNode } from "./nodes/node-instance";
-
-export const config = {
- namespace: "WsTextEditor",
- onError(error: Error) {
- throw error;
- },
- nodes: [InstanceNode],
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/editor-lazy.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/editor-lazy.tsx
deleted file mode 100644
index 83d1fbce93..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/editor-lazy.tsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import { memo, lazy, Suspense } from "react";
-import type { EditorProps } from "./editor";
-
-const EditorLazy = lazy(() => import("./editor"));
-
-type EditorWithSuspenseProps = EditorProps & {
- fallback: JSX.Element;
-};
-
-const EditorWithSuspense = ({
- fallback,
- ...props
-}: EditorWithSuspenseProps) => {
- return (
- <Suspense fallback={fallback}>
- <EditorLazy {...props} />
- </Suspense>
- );
-};
-
-// Prevent rerender because in editing mode Editor controls the node.
-export const Editor = memo(EditorWithSuspense, () => true);
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/editor.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/editor.tsx
deleted file mode 100644
index 5f6daa1a78..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/editor.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import type { ChildrenUpdates, Instance } from "@webstudio-is/react-sdk";
-import {
- RichTextPlugin,
- HistoryPlugin,
- LexicalComposer,
- LexicalErrorBoundary,
- useLexicalComposerContext,
-} from "./lexical";
-import { InstancePlugin } from "./plugins/plugin-instance";
-import { ToolbarConnectorPlugin } from "./plugins/plugin-toolbar-connector";
-import { OnChangePlugin } from "./plugins/plugin-on-change";
-import { config } from "./config";
-import { useCallback } from "react";
-
-type InstanceRenderProps = {
- ref: (element: HTMLElement | null) => void;
- contentEditable: boolean;
-};
-
-export type EditorProps = {
- renderInstance: (renderProps: InstanceRenderProps) => JSX.Element;
- instance: Instance;
- onChange: (updates: ChildrenUpdates) => void;
-};
-
-const useSetElement = () => {
- const [editor] = useLexicalComposerContext();
- return useCallback(
- (element) => {
- editor.setRootElement(element);
- },
- [editor]
- );
-};
-
-const Editor = ({ instance, renderInstance, onChange }: EditorProps) => {
- const ref = useSetElement();
- const editable = renderInstance({ ref, contentEditable: true });
- return (
- <>
- <RichTextPlugin
- ErrorBoundary={LexicalErrorBoundary}
- contentEditable={editable}
- placeholder=""
- />
- <OnChangePlugin onChange={onChange} />
- <HistoryPlugin />
- <InstancePlugin>{instance.children}</InstancePlugin>
- <ToolbarConnectorPlugin />
- </>
- );
-};
-
-const EditorConfigured = (props: EditorProps) => {
- return (
- <LexicalComposer initialConfig={config}>
- <Editor {...props} />
- </LexicalComposer>
- );
-};
-
-export default EditorConfigured;
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsx
deleted file mode 100644
index 0bdd910c6c..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.stories.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import type { ComponentStory, ComponentMeta } from "@storybook/react";
-import { action } from "@storybook/addon-actions";
-import { ExampleTextEditor } from "./example-text-editor";
-
-export default {
- title: "Text Editor",
- component: ExampleTextEditor,
-} as ComponentMeta<typeof ExampleTextEditor>;
-
-export const TextEditor: ComponentStory<typeof ExampleTextEditor> = (args) => {
- return <ExampleTextEditor {...args} />;
-};
-
-TextEditor.args = {
- onChange: action("onChange"),
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx
deleted file mode 100644
index 24cf26ebec..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/example-text-editor.tsx
+++ /dev/null
@@ -1,141 +0,0 @@
-import {
- type ChildrenUpdates,
- useAllUserProps,
- type Instance,
-} from "@webstudio-is/react-sdk";
-import { createInstance } from "~/shared/tree-utils";
-import { Box, Button } from "@webstudio-is/design-system";
-import { LexicalComposer, ContentEditable } from "./lexical";
-import { TreeViewPlugin } from "./plugins/tree-view-plugin";
-import { config } from "./config";
-import Editor from "./editor";
-import { publish } from "~/shared/pubsub";
-
-type ExampleTextEditorProps = {
- onChange: (state: ChildrenUpdates) => void;
-};
-
-const Menu = () => {
- const [, setAllUserProps] = useAllUserProps();
- return (
- <Box
- css={{
- margin: "$2",
- display: "flex",
- gap: "$2",
- }}
- >
- <Button
- onClick={() => {
- publish({
- type: "formatTextToolbar",
- payload: "bold",
- });
- }}
- >
- Bold
- </Button>
- <Button
- onClick={() => {
- publish({
- type: "formatTextToolbar",
- payload: "italic",
- });
- }}
- >
- Italic
- </Button>
- <Button
- onClick={() => {
- const instance = createInstance({ component: "Link" });
- publish({
- type: "formatTextToolbar",
- payload: "link",
- });
- const url = prompt("Enter url");
- if (url === null) return;
- setAllUserProps({
- [instance.id]: {
- id: "1",
- instanceId: instance.id,
- treeId: "3",
- props: [
- {
- id: "4",
- prop: "href",
- value: url,
- },
- ],
- },
- });
- }}
- >
- Link
- </Button>
- </Box>
- );
-};
-
-export const ExampleTextEditor = ({ onChange }: ExampleTextEditorProps) => {
- return (
- <>
- <Menu />
- <LexicalComposer initialConfig={config}>
- <Box
- css={{
- background: "#fff",
- borderRadius: 2,
- maxWidth: 600,
- color: "#000",
- position: "relative",
- lineHeight: 1.5,
- fontWeight: 400,
- textAlign: "left",
- borderTopLeftRadius: "$3",
- borderTopRightRadius: "$3",
- overflow: "hidden",
- "& p": {
- margin: 0,
- },
- }}
- >
- <Editor
- renderInstance={() => (
- <ContentEditable
- style={{
- minHeight: 150,
- resize: "none",
- fontSize: "1em",
- position: "relative",
- tabSize: 1,
- outline: 0,
- padding: "15px 10px",
- caretColor: "#444",
- background: "#eee",
- }}
- />
- )}
- instance={
- {
- component: "Paragraph",
- id: "62bd56ad8f5562223cb85cc2",
- cssRules: [],
- children: [
- "Pragraph you can edit ",
- {
- component: "Bold",
- id: "62bd56ad8f5562223cb85cc2",
- cssRules: [],
- children: ["bold"],
- },
- ],
- } as Instance
- }
- onChange={onChange}
- />
- <TreeViewPlugin />
- </Box>
- </LexicalComposer>
- </>
- );
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/index.ts b/apps/designer/app/canvas/features/wrapper-component/text-editor/index.ts
deleted file mode 100644
index acb2865c26..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { Editor } from "./editor-lazy";
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/lexical.ts b/apps/designer/app/canvas/features/wrapper-component/text-editor/lexical.ts
deleted file mode 100644
index 5564530f0c..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/lexical.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-export type {
- EditorConfig,
- EditorState,
- LexicalCommand,
- LexicalEditor,
- LexicalNode,
- RangeSelection,
- SerializedEditorState,
- SerializedLexicalNode,
- SerializedElementNode,
- SerializedTextNode,
- SerializedRootNode,
- ParagraphNode,
-} from "lexical";
-export {
- ElementNode,
- TextNode,
- RootNode,
- createCommand,
- $isRangeSelection,
- $getSelection,
- $getRoot,
- $getNodeByKey,
- $createTextNode,
- $createParagraphNode,
- COMMAND_PRIORITY_EDITOR,
- SELECTION_CHANGE_COMMAND,
- COMMAND_PRIORITY_LOW,
-} from "lexical";
-export { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
-export { LexicalComposer } from "@lexical/react/LexicalComposer";
-export { default as LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
-export { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
-export { ContentEditable } from "@lexical/react/LexicalContentEditable";
-export { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
-export { OnChangePlugin } from "@lexical/react/LexicalOnChangePlugin";
-export { TreeView } from "@lexical/react/LexicalTreeView";
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/nodes/node-instance.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/nodes/node-instance.tsx
deleted file mode 100644
index 0dccdc5e9c..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/nodes/node-instance.tsx
+++ /dev/null
@@ -1,79 +0,0 @@
-import { render } from "react-dom";
-import { type Instance } from "@webstudio-is/react-sdk";
-import {
- type EditorConfig,
- type SerializedTextNode,
- TextNode,
-} from "../lexical";
-import { InlineWrapperComponentDev } from "../../wrapper-component";
-
-type Options = {
- instance: Instance;
- text: string;
-};
-
-export type SerializedInstanceNode = SerializedTextNode & Options;
-
-export class InstanceNode extends TextNode {
- options: Options;
-
- static getType(): "instance" {
- return "instance";
- }
-
- static clone(node: InstanceNode) {
- return new InstanceNode(node.options);
- }
-
- constructor(options: Options) {
- // This makes sure caret is at the end of the selection after inserting this node instance
- super(options.text);
- this.options = options;
- }
-
- exportJSON(): SerializedInstanceNode {
- const json = super.exportJSON();
- return {
- ...json,
- ...this.options,
- type: InstanceNode.getType(),
- };
- }
-
- createDOM(config: EditorConfig) {
- const container = super.createDOM(config);
- const element = (
- <InlineWrapperComponentDev instance={this.options.instance}>
- {this.options.text}
- </InlineWrapperComponentDev>
- );
- render(element, container);
- return container;
- }
-
- updateDOM(prevNode: TextNode, dom: HTMLElement, config: EditorConfig) {
- const inner = dom.firstChild as HTMLElement;
- if (inner === null) {
- return true;
- }
- super.updateDOM(prevNode, inner, config);
-
- return false;
- }
-
- isInline(): true {
- return true;
- }
-
- canInsertTextBefore(): false {
- return false;
- }
-
- canInsertTextAfter(): false {
- return false;
- }
-}
-
-export const $createInstanceNode = (options: Options) => {
- return new InstanceNode(options);
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-instance.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-instance.tsx
deleted file mode 100644
index c9d24dacfb..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-instance.tsx
+++ /dev/null
@@ -1,91 +0,0 @@
-import { useEffect } from "react";
-import { type Instance } from "@webstudio-is/react-sdk";
-import { useSubscribe } from "~/shared/pubsub";
-import { createInstance } from "~/shared/tree-utils";
-import { $createInstanceNode, InstanceNode } from "../nodes/node-instance";
-import {
- createCommand,
- $isRangeSelection,
- $getSelection,
- $getRoot,
- COMMAND_PRIORITY_EDITOR,
- useLexicalComposerContext,
- type LexicalCommand,
-} from "../lexical";
-import { toLexicalNodes } from "../utils/to-lexical-nodes";
-
-const populateRoot = (children: Instance["children"]) => {
- const nodes = toLexicalNodes(children);
- const root = $getRoot();
- root.clear();
- for (const node of nodes) {
- root.append(node);
- }
- root.selectStart();
-};
-
-const INSERT_INSTANCE_COMMAND: LexicalCommand<Instance> = createCommand();
-
-type InstancePluginProps = {
- children: Instance["children"];
-};
-
-export const InstancePlugin = ({ children }: InstancePluginProps) => {
- const [editor] = useLexicalComposerContext();
- useEffect(() => {
- if (editor.hasNodes([InstanceNode]) === false) {
- throw new Error("InstancePlugin: InstanceNode not registered on editor");
- }
-
- return editor.registerCommand<Instance>(
- INSERT_INSTANCE_COMMAND,
- (instance) => {
- const selection = $getSelection();
- const text = selection?.getTextContent();
- if ($isRangeSelection(selection) && text) {
- const instanceNode = $createInstanceNode({
- instance,
- text,
- });
- selection.insertNodes([instanceNode]);
- // Dirty hack. When clicking on toolbar outside of the iframe, we are loosing focus.
- // For some reason we can only refocus after a delay
- requestAnimationFrame(() => {
- editor.update(() => {
- instanceNode.select();
- });
- });
- }
- return true;
- },
- COMMAND_PRIORITY_EDITOR
- );
- }, [editor]);
-
- useEffect(() => {
- editor.update(() => {
- populateRoot(children);
- });
- }, [editor, children]);
-
- useSubscribe("formatTextToolbar", (type) => {
- let component: null | "Bold" | "Italic" | "Link" = null;
- if (type === "bold") {
- component = "Bold";
- }
- if (type === "italic") {
- component = "Italic";
- }
- if (type === "link") {
- component = "Link";
- }
- if (component) {
- editor.dispatchCommand<LexicalCommand<Instance>>(
- INSERT_INSTANCE_COMMAND,
- createInstance({ component })
- );
- }
- });
-
- return null;
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-on-change.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-on-change.tsx
deleted file mode 100644
index 196693fa9b..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-on-change.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { type ChildrenUpdates } from "@webstudio-is/react-sdk";
-import { useCallback, useEffect, useState } from "react";
-import { useDebounce } from "react-use";
-import {
- OnChangePlugin as LexicalOnChangePlugin,
- type EditorState,
-} from "../lexical";
-import { toUpdates } from "../utils/to-updates";
-
-export const OnChangePlugin = ({
- onChange,
-}: {
- onChange: (updates: ChildrenUpdates) => void;
-}) => {
- const [editorState, setEditorState] = useState<EditorState>();
-
- const handleChange = useCallback(() => {
- if (editorState === undefined) return;
- editorState.read(() => {
- const updates = toUpdates(editorState.toJSON().root);
- onChange(updates);
- });
- }, [editorState, onChange]);
-
- // When we quit editing mode, we need to safe again otherwise it can happen before debounce calls.
- useEffect(() => handleChange);
-
- useDebounce(handleChange, 1000, [handleChange]);
-
- return <LexicalOnChangePlugin onChange={setEditorState} />;
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-toolbar-connector.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-toolbar-connector.tsx
deleted file mode 100644
index beac9f26b5..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/plugin-toolbar-connector.tsx
+++ /dev/null
@@ -1,63 +0,0 @@
-import { useCallback, useEffect, useRef } from "react";
-
-import {
- $isRangeSelection,
- $getSelection,
- SELECTION_CHANGE_COMMAND,
- COMMAND_PRIORITY_LOW,
- useLexicalComposerContext,
-} from "../lexical";
-import { publish } from "~/shared/pubsub";
-
-export const ToolbarConnectorPlugin = () => {
- const [editor] = useLexicalComposerContext();
- const lastSelectionRef = useRef<unknown>();
-
- const clearSelectionRect = () => {
- if (lastSelectionRef.current) {
- // Undefined Rect will hide toolbar
- publish({ type: "hideTextToolbar" });
- lastSelectionRef.current = undefined;
- }
- };
-
- const publishSelectionRect = useCallback(() => {
- const selection = $getSelection();
- const text = selection?.getTextContent();
- const nativeSelection = window.getSelection();
- const isTextSelected =
- $isRangeSelection(selection) && Boolean(text) && nativeSelection !== null;
-
- if (isTextSelected) {
- const domRange = nativeSelection.getRangeAt(0);
- const selectionRect = domRange.getBoundingClientRect();
- publish({
- type: "showTextToolbar",
- payload: {
- selectionRect,
- isBold: false,
- isItalic: false,
- isLink: false,
- },
- });
- lastSelectionRef.current = selection;
- return true;
- }
-
- clearSelectionRect();
-
- return true;
- }, []);
-
- useEffect(() => {
- editor.registerCommand(
- SELECTION_CHANGE_COMMAND,
- publishSelectionRect,
- COMMAND_PRIORITY_LOW
- );
- }, [editor, publishSelectionRect]);
-
- useEffect(() => clearSelectionRect, []);
-
- return null;
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.css b/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.css
deleted file mode 100644
index a2203f4a70..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.css
+++ /dev/null
@@ -1,55 +0,0 @@
-.tree-view-output {
- display: block;
- background: #222;
- color: #fff;
- padding: 5px;
- font-size: 12px;
- white-space: pre-wrap;
- margin: 1px auto 10px auto;
- max-height: 250px;
- position: relative;
- border-bottom-left-radius: 10px;
- border-bottom-right-radius: 10px;
- overflow: hidden;
- line-height: 14px;
-}
-
-.debug-timetravel-panel {
- overflow: hidden;
- padding: 0 0 10px 0;
- margin: auto;
- display: flex;
-}
-
-.debug-timetravel-panel-slider {
- padding: 0;
- flex: 8;
-}
-
-.debug-timetravel-panel-button {
- padding: 0;
- border: 0;
- background: none;
- flex: 1;
- color: #fff;
- font-size: 12px;
-}
-
-.debug-timetravel-panel-button:hover {
- text-decoration: underline;
-}
-
-.debug-timetravel-button {
- border: 0;
- padding: 0;
- font-size: 12px;
- top: 10px;
- right: 15px;
- position: absolute;
- background: none;
- color: #fff;
-}
-
-.debug-timetravel-button:hover {
- text-decoration: underline;
-}
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsx
deleted file mode 100644
index 2e2a23f730..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/plugins/tree-view-plugin.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import { useLexicalComposerContext, TreeView } from "../lexical";
-import "./tree-view-plugin.css";
-
-// Only used in the storybook
-export const TreeViewPlugin = () => {
- const [editor] = useLexicalComposerContext();
- return (
- <TreeView
- viewClassName="tree-view-output"
- timeTravelPanelClassName="debug-timetravel-panel"
- timeTravelButtonClassName="debug-timetravel-button"
- timeTravelPanelSliderClassName="debug-timetravel-panel-slider"
- timeTravelPanelButtonClassName="debug-timetravel-panel-button"
- editor={editor}
- />
- );
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-lexical-nodes.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-lexical-nodes.tsx
deleted file mode 100644
index 9ae80c7ea3..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-lexical-nodes.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import { type Instance } from "@webstudio-is/react-sdk";
-import { $createInstanceNode } from "../nodes/node-instance";
-import {
- $createTextNode,
- $createParagraphNode,
- type ParagraphNode,
-} from "../lexical";
-
-export const toLexicalNodes = (children: Instance["children"]) => {
- const nodes: Array<ParagraphNode> = [];
-
- let p = $createParagraphNode();
- nodes.push(p);
-
- for (const child of children) {
- if (child === "\n") {
- p = $createParagraphNode();
- nodes.push(p);
- continue;
- }
-
- if (typeof child === "string") {
- const textNode = $createTextNode(child);
- p.append(textNode);
- continue;
- }
-
- // Inline components should always have a single child string
- const text = typeof child.children[0] === "string" ? child.children[0] : "";
- const paragraph = nodes[nodes.length - 1];
- const instanceNode = $createInstanceNode({
- instance: child,
- text,
- });
- paragraph.append(instanceNode);
- }
-
- return nodes;
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-updates.test.ts b/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-updates.test.ts
deleted file mode 100644
index 8ca263911d..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-updates.test.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-import { toUpdates } from "./to-updates";
-
-describe("toUpdates", () => {
- test("two lines of text", () => {
- const state = {
- root: {
- children: [
- {
- children: [
- {
- detail: 0,
- format: 0,
- mode: "normal",
- style: "",
- text: "a",
- type: "text",
- version: 1,
- },
- ],
- direction: "ltr",
- format: "",
- indent: 0,
- type: "paragraph",
- version: 1,
- },
- {
- children: [
- {
- detail: 0,
- format: 0,
- mode: "normal",
- style: "",
- text: "b",
- type: "text",
- version: 1,
- },
- ],
- direction: "ltr",
- format: "",
- indent: 0,
- type: "paragraph",
- version: 1,
- },
- ],
- direction: "ltr",
- format: "",
- indent: 0,
- type: "root",
- version: 1,
- },
- } as const;
- const updates = toUpdates(state.root);
- expect(updates).toStrictEqual(["a", "\n", "b"]);
- });
-
- test("text and instance", () => {
- const state = {
- root: {
- children: [
- {
- children: [
- {
- detail: 0,
- format: 0,
- mode: "normal",
- style: "",
- text: "a ",
- type: "text",
- version: 1,
- },
- {
- detail: 0,
- format: 0,
- mode: "normal",
- style: "",
- text: "b",
- type: "instance",
- version: 1,
- instance: {
- component: "Bold",
- id: "62bcc02160a439686c7eabde",
- cssRules: [],
- children: [],
- },
- },
- {
- detail: 0,
- format: 0,
- mode: "normal",
- style: "",
- text: "c",
- type: "text",
- version: 1,
- },
- ],
- direction: "ltr",
- format: "",
- indent: 0,
- type: "paragraph",
- version: 1,
- },
- ],
- direction: "ltr",
- format: "",
- indent: 0,
- type: "root",
- version: 1,
- },
- } as const;
-
- const updates = toUpdates(state.root);
- expect(updates).toStrictEqual([
- "a ",
- {
- id: "62bcc02160a439686c7eabde",
- component: "Bold",
- text: "b",
- },
- "c",
- ]);
- });
-});
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-updates.ts b/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-updates.ts
deleted file mode 100644
index c6170f53ca..0000000000
--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/utils/to-updates.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { type ChildrenUpdates } from "@webstudio-is/react-sdk";
-import {
- type SerializedTextNode,
- type SerializedElementNode,
- type SerializedRootNode,
- type SerializedLexicalNode,
-} from "../lexical";
-import { type SerializedInstanceNode } from "../nodes/node-instance";
-
-type Node =
- | SerializedRootNode
- | SerializedElementNode
- | SerializedTextNode
- | SerializedLexicalNode
- | SerializedInstanceNode;
-
-export const toUpdates = (
- node: Node,
- updates: ChildrenUpdates = []
-): ChildrenUpdates => {
- if (node.type === "text" && "text" in node) {
- updates.push(node.text);
- }
-
- if (node.type === "instance" && "instance" in node) {
- updates.push({
- id: node.instance.id,
- text: node.text,
- component: node.instance.component,
- });
- }
-
- if ("children" in node) {
- for (const child of node.children) {
- if (child.type === "paragraph" && updates.length !== 0) {
- updates.push("\n");
- }
-
- toUpdates(child, updates);
- }
- }
-
- return updates;
-};
diff --git a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
index d79d96c4a7..962509087e 100644
--- a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
+++ b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
@@ -1,16 +1,15 @@
import { MouseEvent, FormEvent } from "react";
-import { Suspense, lazy, useCallback, useMemo } from "react";
+import { Suspense, lazy, useCallback } from "react";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import {
type Instance,
type CSS,
type OnChangeChildren,
- toCss,
useUserProps,
renderWrapperComponentChildren,
components,
} from "@webstudio-is/react-sdk";
-import { useBreakpoints, useTextEditingInstanceId } from "~/shared/nano-states";
+import { useTextEditingInstanceId } from "~/shared/nano-states";
import { useCss } from "./use-css";
import noop from "lodash.noop";
import { useSelectedElement } from "~/canvas/shared/nano-states";
@@ -121,34 +120,3 @@ export const WrapperComponentDev = ({
</Suspense>
);
};
-
-// Only used for instances inside text editor.
-export const InlineWrapperComponentDev = ({
- instance,
- ...rest
-}: {
- instance: Instance;
- children: string;
-}) => {
- const [breakpoints] = useBreakpoints();
- const css = useMemo(
- () => toCss(instance.cssRules, breakpoints),
- [instance, breakpoints]
- );
- const className = useCss({ instance, css });
- const userProps = useUserProps(instance.id);
- const { Component } = components[instance.component];
-
- return (
- <Component
- {...rest}
- {...userProps}
- data-outline-disabled
- key={instance.id}
- // @todo stop using id to free it up to the user
- id={instance.id}
- // @todo merge className with props
- className={className}
- />
- );
-};