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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
now works with provider inside the editor
Oleg Isonen6fce218163c5
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/lazy-editor.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/editor-lazy.tsxsimilarity index 81%rename from apps/designer/app/canvas/features/wrapper-component/text-editor/lazy-editor.tsxrename to apps/designer/app/canvas/features/wrapper-component/text-editor/editor-lazy.tsxindex 9ddfbab3a5..0e99b87e13 100644--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/lazy-editor.tsx+++ b/apps/designer/app/canvas/features/wrapper-component/text-editor/editor-lazy.tsx@@ -1,4 +1,4 @@-import { memo, lazy, Suspense, ComponentProps } from "react";+import { memo, lazy, Suspense } from "react";import type { EditorProps } from "./editor";const EditorLazy = lazy(() => import("./editor"));@@ -13,3 +13,4 @@ const EditorWithSuspense = (props: EditorProps) => {// Prevent rerender because in editing mode Editor controls the node.export const Editor = memo(EditorWithSuspense, () => true);+//export const Editor = EditorWithSuspense;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.tsxindex 3f1d2910cf..76b7ce6788 100644--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/editor.tsx+++ b/apps/designer/app/canvas/features/wrapper-component/text-editor/editor.tsx@@ -11,6 +11,7 @@ import { OnChangePlugin } from "./plugins/plugin-on-change";import { config } from "./config";import { useEffect } from "react";import { useSelectedElement } from "~/canvas/shared/nano-states";+import { getInstanceIdFromElement } from "~/shared/dom-utils";export type EditorProps = {editable: JSX.Element;@@ -18,18 +19,18 @@ export type EditorProps = {onChange: (updates: ChildrenUpdates) => void;};-const Editor = ({ instance, editable, onChange }: EditorProps) => {+const useSetElement = (instance: Instance) => {const [editor] = useLexicalComposerContext();const [element] = useSelectedElement();-useEffect(() => {- if (element === undefined) return;- editor.setRootElement(element);- return () => {- editor.setRootElement(null);- };- }, [element]);+ if (element && getInstanceIdFromElement(element) === instance.id) {+ editor.setRootElement(element);+ }+ }, [element, editor, instance]);+};+const Editor = ({ instance, editable, onChange }: EditorProps) => {+ useSetElement(instance);return (<><RichTextPlugin contentEditable={editable} placeholder="" />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.tsindex d442c978f0..acb2865c26 100644--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/index.ts+++ b/apps/designer/app/canvas/features/wrapper-component/text-editor/index.ts@@ -1 +1 @@-export { Editor } from "./lazy-editor";+export { Editor } from "./editor-lazy";diff --git a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsxindex e4921062a0..75b573d53f 100644--- a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx+++ b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx@@ -32,7 +32,6 @@ export const WrapperComponentDev = ({const className = useCss({ instance, css });const [editingInstanceId] = useTextEditingInstanceId();const [, setSelectedElement] = useSelectedElement();- const isEditing = editingInstanceId === instance.id;const focusRefCallback = useEnsureFocus();const refCallback = useCallback(@@ -41,13 +40,12 @@ export const WrapperComponentDev = ({// When entering text editing we unmount the instance element, so we need to update the reference, otherwise we have a detached element referenced and bounding box will be wrong.if (element !== null) setSelectedElement(element);},- [focusRefCallback, setSelectedElement, isEditing]+ [focusRefCallback, setSelectedElement]);const userProps = useUserProps(instance.id);const readonlyProps =instance.component === "Input" ? { readOnly: true } : undefined;- const editableProps = isEditing ? { contentEditable: true } : undefined;const { Component } = components[instance.component];@@ -55,12 +53,13 @@ export const WrapperComponentDev = ({...userProps,...rest,...readonlyProps,- ...editableProps,// @todo merge className with props- className: className,+ className,+ tabIndex: 0,// @todo stop using id to free it up to the user+ // we should replace id, data-component and data-id with "data-ws"=instance.id and grab the rest always over the id+ // for this we need to also make search by id fastid: instance.id,- tabIndex: 0,"data-component": instance.component,"data-id": instance.id,ref: refCallback,@@ -75,11 +74,11 @@ export const WrapperComponentDev = ({},};- if (isEditing) {+ if (editingInstanceId === instance.id) {return (<Editorinstance={instance}- editable={<Component {...props} />}+ editable={<Component {...props} contentEditable={true} />}onChange={(updates) => {onChangeChildren({ instanceId: instance.id, updates });}}