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
always require a breakpoint when populating instances
Oleg Isonen1c4dedea9454
diff --git a/apps/designer/app/canvas/features/text-editor/text-editor.tsx b/apps/designer/app/canvas/features/text-editor/text-editor.tsxindex 854ff654d0..a00aefa459 100644--- a/apps/designer/app/canvas/features/text-editor/text-editor.tsx+++ b/apps/designer/app/canvas/features/text-editor/text-editor.tsx@@ -1,58 +1,15 @@-import { useEffect, useState } from "react";-import type { LexicalEditor } from "lexical";+import { useState } 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 { toCss, css } from "@webstudio-is/react-sdk";-import { useBreakpoints } from "~/shared/nano-states";import { ToolbarConnectorPlugin } from "./toolbar-connector";import { type Refs, $convertToLexical, $convertToUpdates } from "./interop";-const NodeConnector = ({- editor,- nodeKey,- instance,-}: {- editor: LexicalEditor;- nodeKey: string;- instance: Instance;-}) => {- const [breakpoints] = useBreakpoints();- useEffect(() => {- // extract key from stored key:style format- const [key] = nodeKey.split(":");- const element = editor.getElementByKey(key);- if (element) {- const className = css(toCss(instance, breakpoints))().toString();- // assume only styles are important while editing text- element.className = className;- }- }, [editor, nodeKey, instance, breakpoints]);- return null;-};--const NodesConnectorPlugin = ({ refs }: { refs: Refs }) => {- const [editor] = useLexicalComposerContext();- return (- <>- {Array.from(refs).map(([nodeKey, instance]) => (- <NodeConnector- key={nodeKey}- editor={editor}- nodeKey={nodeKey}- instance={instance}- />- ))}- </>- );-};-const onError = (error: Error) => {throw error;};@@ -87,7 +44,6 @@ export const TextEditor = ({return (<LexicalComposer initialConfig={initialConfig}><ToolbarConnectorPlugin />- <NodesConnectorPlugin refs={refs} /><RichTextPluginErrorBoundary={LexicalErrorBoundary}contentEditable={contentEditable}diff --git a/apps/designer/app/canvas/shared/instance.ts b/apps/designer/app/canvas/shared/instance.tsindex 78167928fe..0a14b629ee 100644--- a/apps/designer/app/canvas/shared/instance.ts+++ b/apps/designer/app/canvas/shared/instance.ts@@ -33,6 +33,7 @@ import {} from "./nano-states";import {rootInstanceContainer,+ useBreakpoints,useRootInstance,useTextEditingInstanceId,} from "~/shared/nano-states";@@ -99,13 +100,14 @@ export const findInsertLocation = (export const useInsertInstance = () => {const [selectedInstance, setSelectedInstance] = useSelectedInstance();+ const [breakpoints] = useBreakpoints();useSubscribe("insertInstance", ({ instance, dropTarget, props }) => {store.createTransaction([rootInstanceContainer, allUserPropsContainer],(rootInstance, allUserProps) => {if (rootInstance === undefined) return;- const populatedInstance = populateInstance(instance);+ const populatedInstance = populateInstance(instance, breakpoints[0].id);const hasInserted = insertInstanceMutable(rootInstance,populatedInstance,diff --git a/apps/designer/app/shared/tree-utils/populate.ts b/apps/designer/app/shared/tree-utils/populate.tsindex 4e30360c57..403a3e82ce 100644--- a/apps/designer/app/shared/tree-utils/populate.ts+++ b/apps/designer/app/shared/tree-utils/populate.ts@@ -11,7 +11,7 @@ import {*/export const populateInstance = (instance: Instance,- breakpoint: Breakpoint["id"] = ""+ breakpoint: Breakpoint["id"]): Instance => {const populatedInstance = { ...instance };const componentMeta = components[instance.component];diff --git a/packages/css-engine/src/react.ts b/packages/css-engine/src/react.tsindex 0444adfa60..b37f0f1b67 100644--- a/packages/css-engine/src/react.ts+++ b/packages/css-engine/src/react.ts@@ -18,6 +18,7 @@ const useIsomorphicLayoutEffect =// Wrapps a normal StyleValue into a VarStyleValue that uses the previous style value as a fallback and allows// to quickly pass the values over CSS variable witout rerendering the components tree.+// Results in values like this: `var(--namespace, staticValue)`const toVarStyleWithFallback = (instanceId: string, style: Style): Style => {const dynamicStyle: Style = {};let property: StyleProperty;@@ -63,6 +64,7 @@ export const useCssRules = ({useIsomorphicLayoutEffect(() => {for (const cssRule of cssRules) {const key = id + cssRule.breakpoint;+let rule = ruleMap.current.get(key);if (rule === undefined) {const selectorText = `[data-ws-id="${id}"]`;