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
feat: support multiline string variable (#2954)
Bogdan Chadkin3e1820c55369
diff --git a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx b/apps/builder/app/builder/features/settings-panel/variable-popover.tsxindex 22da55930d..0522731fcc 100644--- a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx+++ b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx@@ -30,6 +30,7 @@ import {Select,SelectItem,Switch,+ TextArea,Tooltip,theme,} from "@webstudio-is/design-system";@@ -57,6 +58,10 @@ import {import { $userPlanFeatures } from "~/builder/shared/nano-states";import { BindingPopoverProvider } from "~/builder/shared/binding-popover";import { useSideOffset } from "~/builder/shared/floating-panel";+import {+ EditorDialog,+ EditorDialogControl,+} from "~/builder/shared/code-editor";import { ResourceForm } from "./resource-panel";/**@@ -195,11 +200,24 @@ const StringForm = forwardRef<return (<Flex direction="column" css={{ gap: theme.spacing[3] }}><Label htmlFor={valueId}>Value</Label>- <InputField- id={valueId}- value={value}- onChange={(event) => setValue(event.target.value)}- />+ <EditorDialogControl>+ <TextArea+ rows={1}+ maxRows={10}+ autoGrow={true}+ id={valueId}+ value={value}+ onChange={setValue}+ />+ <EditorDialog title={`Variable "${nameField.value || "Unnamed"}"`}>+ <TextArea+ grow={true}+ id={valueId}+ value={value}+ onChange={setValue}+ />+ </EditorDialog>+ </EditorDialogControl></Flex>);});diff --git a/apps/builder/app/builder/shared/code-editor.tsx b/apps/builder/app/builder/shared/code-editor.tsxindex fcfde80494..98133fcb2a 100644--- a/apps/builder/app/builder/shared/code-editor.tsx+++ b/apps/builder/app/builder/shared/code-editor.tsx@@ -27,6 +27,9 @@ const ExternalChange = Annotation.define<boolean>();const editorContentStyle = css({...textVariants.mono,+ // fit editor into parent if stretched+ display: "flex",+ minHeight: 0,boxSizing: "border-box",color: theme.colors.foregroundMain,borderRadius: theme.borderRadius[4],@@ -58,6 +61,7 @@ const editorContentStyle = css({padding: 0,},"& .cm-editor": {+ width: "100%",// makes sure you can click to focus when editor content is smaller than the containerheight: "100%",},@@ -171,23 +175,41 @@ const EditorContent = ({);};-const CodeEditorDialog = ({+const editorDialogControlStyle = css({+ position: "relative",+ "&:hover": {+ "--ws-code-editor-maximize-icon-visibility": "visible",+ },+});++export const EditorDialogControl = ({ children }: { children: ReactNode }) => {+ return <div className={editorDialogControlStyle()}>{children}</div>;+};++export const EditorDialog = ({title,- content,children,}: {- title: ReactNode;- content: ReactNode;+ title?: ReactNode;children: ReactNode;}) => {const [isExpanded, setIsExpanded] = useState(false);const width = isExpanded ? "80vw" : "640px";const height = isExpanded ? "80vh" : "480px";const padding = rawTheme.spacing[7];-return (<Dialog>- <DialogTrigger asChild>{children}</DialogTrigger>+ <DialogTrigger asChild>+ <SmallIconButton+ icon={<MaximizeIcon />}+ css={{+ position: "absolute",+ top: 6,+ right: 4,+ visibility: `var(--ws-code-editor-maximize-icon-visibility, hidden)`,+ }}+ />+ </DialogTrigger><DialogContent// Left Aside panels (e.g., Pages, Components) use zIndex: theme.zIndices[1].// For a dialog to appear above these panels, both overlay and content should also have zIndex: theme.zIndices[1].@@ -199,18 +221,16 @@ const CodeEditorDialog = ({overlayCss={{ zIndex: theme.zIndices[1] }}><Grid+ align="stretch"css={{padding,width,height,overflow: "hidden",boxSizing: "content-box",- "& .cm-content": {- maxHeight: `calc(${height} - ${padding})`,- },}}>- {content}+ {children}</Grid>{/* Title is at the end intentionally,* to make the close button last in the tab order@@ -222,9 +242,7 @@ const CodeEditorDialog = ({color="ghost"prefix={isExpanded ? <MinimizeIcon /> : <MaximizeIcon />}aria-label="Expand"- onClick={() => {- setIsExpanded(isExpanded ? false : true);- }}+ onClick={() => setIsExpanded(isExpanded ? false : true)}/><DialogClose asChild><Button@@ -243,13 +261,6 @@ const CodeEditorDialog = ({);};-const codeEditorStyle = css({- position: "relative",- "&:hover": {- "--ws-code-editor-dialog-maximize-icon-display": "block",- },-});-export const CodeEditor = ({title,...editorContentProps@@ -258,19 +269,9 @@ export const CodeEditor = ({}) => {const content = <EditorContent {...editorContentProps} />;return (- <div className={codeEditorStyle()}>+ <EditorDialogControl>{content}- <CodeEditorDialog title={title} content={content}>- <SmallIconButton- icon={<MaximizeIcon />}- css={{- position: "absolute",- top: 6,- right: 4,- display: `var(--ws-code-editor-dialog-maximize-icon-display, none)`,- }}- />- </CodeEditorDialog>- </div>+ <EditorDialog title={title}>{content}</EditorDialog>+ </EditorDialogControl>);};diff --git a/packages/design-system/src/components/text-area.tsx b/packages/design-system/src/components/text-area.tsxindex c631b0a1c3..806113b440 100644--- a/packages/design-system/src/components/text-area.tsx+++ b/packages/design-system/src/components/text-area.tsx@@ -35,7 +35,7 @@ const gridStyle = css({background: theme.colors.backgroundInputDisabled,},variants: {- autoGrow: {+ grow: {true: {resize: "none",},@@ -104,6 +104,7 @@ type Props = Omit<value?: string;defaultValue?: string;onChange?: (value: string) => void;+ grow?: boolean;autoGrow?: boolean;variant?: "regular" | "mono";};@@ -118,6 +119,7 @@ export const TextArea = forwardRef(state,value,onChange,+ grow,autoGrow,variant = "regular",...props@@ -135,7 +137,7 @@ export const TextArea = forwardRef(const minHeight =rows * LINE_HEIGHT + PADDING_TOP + PADDING_BOTTOM + BORDER * 2;- const height = autoGrow ? undefined : minHeight;+ const height = autoGrow || grow ? undefined : minHeight;const maxHeight = maxRows? maxRows * LINE_HEIGHT + PADDING_TOP + PADDING_BOTTOM + BORDER * 2@@ -145,7 +147,7 @@ export const TextArea = forwardRef(<GridclassName={gridStyle({state,- autoGrow,+ grow: grow || autoGrow,variant,css: { height, minHeight, maxHeight },})}