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.

feat: Token lock (#5678)

Shrekfb260a3a92d7
diff --git a/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx b/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx
index 1f4f28d2cb..23b73e3244 100644
--- a/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx
@@ -6,8 +6,10 @@ import {
useComputedStyleDecl,
} from "../../shared/model";
import { deleteProperty, setProperty } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
export const ColorControl = ({ property }: { property: CssProperty }) => {
+ const readonly = useReadonly();
const computedStyleDecl = useComputedStyleDecl(property);
const value = computedStyleDecl.cascadedValue;
const usedColor = computedStyleDecl.usedValue;
@@ -27,6 +29,7 @@ export const ColorControl = ({ property }: { property: CssProperty }) => {
const setValue = setProperty(property);
return (
<ColorPickerControl
+ disabled={readonly}
property={property}
value={value}
currentColor={currentColor}
diff --git a/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx b/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx
index d37cf28340..9431e8d12f 100644
--- a/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/font-family/font-family-control.tsx
@@ -15,6 +15,7 @@ import { useAssets, AssetUpload } from "~/builder/shared/assets";
import { toItems } from "~/builder/shared/fonts-manager";
import { useComputedStyleDecl } from "../../shared/model";
import { setProperty } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
type Item = { value: string; label?: string };
@@ -41,6 +42,7 @@ const matchOrSuggestToCreate = (
};
export const FontFamilyControl = () => {
+ const readonly = useReadonly();
const fontFamily = useComputedStyleDecl("font-family");
const value = fontFamily.cascadedValue;
const setValue = setProperty("font-family");
@@ -65,11 +67,12 @@ export const FontFamilyControl = () => {
return (
<Flex>
<Combobox<Item>
+ disabled={readonly}
suffix={
<FloatingPanel
placement="left-start"
title="Fonts"
- titleSuffix={<AssetUpload type="font" />}
+ titleSuffix={readonly ? undefined : <AssetUpload type="font" />}
onOpenChange={setIsFontMangerOpen}
content={
<FontsManager
@@ -80,7 +83,7 @@ export const FontFamilyControl = () => {
/>
}
>
- <FontsManagerButton />
+ <FontsManagerButton disabled={readonly} />
</FloatingPanel>
}
getItems={() => items}
diff --git a/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx b/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx
index 10391bd0f3..3a1469e695 100644
--- a/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx
@@ -11,6 +11,7 @@ import { canvasApi } from "~/shared/canvas-api";
import { $detectedFontsWeights } from "~/shared/nano-states";
import { useComputedStyles } from "../../shared/model";
import { setProperty } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
const allFontWeights = Object.keys(fontWeights) as Array<FontWeight>;
@@ -22,6 +23,7 @@ const labels = new Map(
);
export const FontWeightControl = () => {
+ const readonly = useReadonly();
// We need the font family to determine which font weights are available
const [fontWeight, fontFamily] = useComputedStyles([
"font-weight",
@@ -50,6 +52,7 @@ export const FontWeightControl = () => {
return (
<Select
+ disabled={readonly}
// show empty field instead of radix placeholder
// like css value input does
placeholder=""
diff --git a/apps/builder/app/builder/features/style-panel/controls/image/image-control.tsx b/apps/builder/app/builder/features/style-panel/controls/image/image-control.tsx
index bbfb71fd90..e2a406e9ec 100644
--- a/apps/builder/app/builder/features/style-panel/controls/image/image-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/image/image-control.tsx
@@ -33,9 +33,11 @@ type IntermediateValue = {
export const ImageControl = ({
property,
index,
+ disabled = false,
}: {
property: CssProperty;
index: number;
+ disabled?: boolean;
}) => {
const assets = useStore($assets);
const styleDecl = useComputedStyleDecl(property);
@@ -64,6 +66,9 @@ export const ImageControl = ({
: undefined;
const handleImageURLInput = (event: React.ChangeEvent<HTMLInputElement>) => {
+ if (disabled) {
+ return;
+ }
const value = event.target.value;
if (isValidURL(value) === true) {
setRemoteImageURL({ type: "intermediate", value });
@@ -73,6 +78,9 @@ export const ImageControl = ({
};
const handleImageURLComplete = () => {
+ if (disabled) {
+ return;
+ }
if (
remoteImageURL?.type === "intermediate" &&
isValidURL(remoteImageURL.value) === true
@@ -89,6 +97,7 @@ export const ImageControl = ({
<Flex direction="column" gap="2">
<InputField
type="text"
+ disabled={disabled}
color={remoteImageURL?.type === "invalid" ? "error" : undefined}
placeholder="Enter image URL..."
value={remoteImageURL?.value ?? ""}
@@ -102,7 +111,7 @@ export const ImageControl = ({
/>
<FloatingPanel
title="Images"
- titleSuffix={<AssetUpload type="image" />}
+ titleSuffix={disabled ? undefined : <AssetUpload type="image" />}
content={
<AssetManager
accept="image/*"
@@ -117,6 +126,7 @@ export const ImageControl = ({
>
<Button
color="neutral"
+ disabled={disabled}
css={{ maxWidth: "100%", justifySelf: "right" }}
>
{asset ? formatAssetName(asset) : "Choose image..."}
diff --git a/apps/builder/app/builder/features/style-panel/controls/menu/menu-control.tsx b/apps/builder/app/builder/features/style-panel/controls/menu/menu-control.tsx
index 08ec0b1318..ad29978d50 100644
--- a/apps/builder/app/builder/features/style-panel/controls/menu/menu-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/menu/menu-control.tsx
@@ -23,6 +23,7 @@ import { humanizeString } from "~/shared/string-utils";
import { setProperty } from "../../shared/use-style-data";
import { useComputedStyleDecl } from "../../shared/model";
import { PropertyValueTooltip } from "../../property-label";
+import { useReadonly } from "../../shared/readonly";
export const MenuControl = ({
property,
@@ -35,6 +36,7 @@ export const MenuControl = ({
icon: IconComponent;
}>;
}) => {
+ const readonly = useReadonly();
const computedStyleDecl = useComputedStyleDecl(property);
const [descriptionValue, setDescriptionValue] = useState<string>();
@@ -63,6 +65,7 @@ export const MenuControl = ({
>
<DropdownMenuTrigger asChild>
<IconButton
+ disabled={readonly}
aria-disabled={isAdvanced}
variant={computedStyleDecl.source.name}
onPointerDown={(event) => {
diff --git a/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx b/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx
index ddc5622dc3..0718ba5c06 100644
--- a/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/position/position-control.tsx
@@ -18,6 +18,7 @@ import {
type SetValue,
} from "../../shared/use-style-data";
import { PropertyInlineLabel } from "../../property-label";
+import { useReadonly } from "../../shared/readonly";
const toPosition = (value: TupleValue) => {
// Should never actually happen, just for TS
@@ -59,6 +60,7 @@ export const PositionControl = ({
property: CssProperty;
styleDecl: ComputedStyleDecl;
}) => {
+ const readonly = useReadonly();
const value = toTuple(styleDecl.cascadedValue);
const keywords = (keywordValues[property] ?? []).map((value) => ({
type: "keyword" as const,
@@ -86,6 +88,7 @@ export const PositionControl = ({
/>
<Flex gap="6">
<PositionGrid
+ disabled={readonly}
selectedPosition={toPosition(value)}
onSelect={({ x, y }) => {
setValue({
@@ -108,6 +111,7 @@ export const PositionControl = ({
properties={[property]}
/>
<CssValueInputContainer
+ disabled={readonly}
property={property}
styleSource={styleDecl.source.name}
getOptions={() => keywords}
@@ -121,6 +125,7 @@ export const PositionControl = ({
properties={[property]}
/>
<CssValueInputContainer
+ disabled={readonly}
property={property}
styleSource={styleDecl.source.name}
getOptions={() => keywords}
diff --git a/apps/builder/app/builder/features/style-panel/controls/select/select-control.tsx b/apps/builder/app/builder/features/style-panel/controls/select/select-control.tsx
index a6200e27e0..247d4cab89 100644
--- a/apps/builder/app/builder/features/style-panel/controls/select/select-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/select/select-control.tsx
@@ -16,6 +16,7 @@ import {
setProperty,
type StyleUpdateOptions,
} from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
import {
getRepeatedStyleItem,
setRepeatedStyleItem,
@@ -25,11 +26,14 @@ export const SelectControl = ({
property,
index,
items,
+ disabled,
}: {
property: CssProperty;
index?: number;
items?: Array<{ label: string; name: string }>;
+ disabled?: boolean;
}) => {
+ const readonly = useReadonly();
const styleDecl = useComputedStyleDecl(property);
const value =
index === undefined
@@ -66,6 +70,7 @@ export const SelectControl = ({
return (
<Select
// Show empty field instead of radix placeholder like css value input does.
+ disabled={disabled || readonly}
placeholder=""
options={options}
value={valueString}
diff --git a/apps/builder/app/builder/features/style-panel/controls/text/text-control.tsx b/apps/builder/app/builder/features/style-panel/controls/text/text-control.tsx
index a709452f21..2b4a608724 100644
--- a/apps/builder/app/builder/features/style-panel/controls/text/text-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/text/text-control.tsx
@@ -10,8 +10,16 @@ import {
$availableUnitVariables,
useComputedStyleDecl,
} from "../../shared/model";
+import { useReadonly } from "../../shared/readonly";
-export const TextControl = ({ property }: { property: CssProperty }) => {
+export const TextControl = ({
+ property,
+ disabled,
+}: {
+ property: CssProperty;
+ disabled?: boolean;
+}) => {
+ const readonly = useReadonly();
const computedStyleDecl = useComputedStyleDecl(property);
const value = computedStyleDecl.cascadedValue;
const setValue = setProperty(property);
@@ -22,6 +30,7 @@ export const TextControl = ({ property }: { property: CssProperty }) => {
<CssValueInput
styleSource={computedStyleDecl.source.name}
property={property}
+ disabled={disabled || readonly}
value={value}
intermediateValue={intermediateValue}
getOptions={() => [
diff --git a/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx b/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx
index 41101f8b9e..b9bee17f64 100644
--- a/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx
@@ -19,6 +19,7 @@ import {
getPriorityStyleValueSource,
PropertyInfo,
} from "../../property-label";
+import { useReadonly } from "../../shared/readonly";
export const ToggleGroupTooltip = ({
isOpen,
@@ -105,6 +106,7 @@ export const ToggleGroupControl = ({
description?: string;
}>;
}) => {
+ const readonly = useReadonly();
const styles = useComputedStyles(properties);
const styleValueSource = getPriorityStyleValueSource(styles);
const selectedValue = toValue(styles[0].cascadedValue);
@@ -122,6 +124,7 @@ export const ToggleGroupControl = ({
const [activeTooltip, setActiveTooltip] = useState<undefined | string>();
return (
<ToggleGroup
+ disabled={readonly}
color={styleValueSource}
type="single"
// trigger value change when value is advanced
diff --git a/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx b/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx
index 689f3ec090..374b62bf9d 100644
--- a/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx
@@ -9,6 +9,7 @@ import { humanizeString } from "~/shared/string-utils";
import { setProperty } from "../../shared/use-style-data";
import { useComputedStyleDecl } from "../../shared/model";
import { PropertyValueTooltip } from "../../property-label";
+import { useReadonly } from "../../shared/readonly";
export const ToggleControl = ({
property,
@@ -21,6 +22,7 @@ export const ToggleControl = ({
icon: IconComponent;
}>;
}) => {
+ const readonly = useReadonly();
const computedStyleDecl = useComputedStyleDecl(property);
const currentValue = toValue(computedStyleDecl.cascadedValue);
const currentItem = items.find((item) => item.name === currentValue);
@@ -44,6 +46,7 @@ export const ToggleControl = ({
isAdvanced={isAdvanced}
>
<ToggleButton
+ disabled={readonly}
aria-disabled={isAdvanced}
variant={computedStyleDecl.source.name}
pressed={isPressed}
diff --git a/apps/builder/app/builder/features/style-panel/property-label.tsx b/apps/builder/app/builder/features/style-panel/property-label.tsx
index e57229b34f..48176764ce 100644
--- a/apps/builder/app/builder/features/style-panel/property-label.tsx
+++ b/apps/builder/app/builder/features/style-panel/property-label.tsx
@@ -28,6 +28,7 @@ import type {
StyleValueSourceColor,
} from "~/shared/style-object-model";
import { useComputedStyles } from "./shared/model";
+import { useReadonly } from "./shared/readonly";
import { StyleSourceBadge } from "./style-source";
import { createBatchUpdate } from "./shared/use-style-data";
import { $virtualInstances } from "~/shared/awareness";
@@ -78,6 +79,7 @@ export const PropertyInfo = ({
onReset: () => void;
resetType?: "reset" | "delete";
}) => {
+ const readonly = useReadonly();
const breakpoints = useStore($breakpoints);
const instances = useStore($instances);
const virtualInstances = useStore($virtualInstances);
@@ -188,7 +190,7 @@ export const PropertyInfo = ({
</Flex>
</Flex>
)}
- {resettable && (
+ {resettable && readonly === false && (
<Button
color="dark"
prefix={
@@ -238,9 +240,13 @@ export const PropertyLabel = ({
disabled?: boolean;
}) => {
const styles = useComputedStyles(properties);
+ const readonly = useReadonly();
const styleValueSourceColor = getPriorityStyleValueSource(styles);
const [isOpen, setIsOpen] = useState(false);
const resetProperty = () => {
+ if (readonly) {
+ return;
+ }
const batch = createBatchUpdate();
for (const property of properties) {
batch.deleteProperty(property);
@@ -255,6 +261,9 @@ export const PropertyLabel = ({
onOpenChange={setIsOpen}
triggerProps={{
onClick: (event) => {
+ if (readonly) {
+ return;
+ }
if (event.altKey) {
event.preventDefault();
// If not, when mixed with ToogleGroupControl.
@@ -300,9 +309,13 @@ export const PropertySectionLabel = ({
properties: [CssProperty, ...CssProperty[]];
}) => {
const styles = useComputedStyles(properties);
+ const readonly = useReadonly();
const styleValueSourceColor = getPriorityStyleValueSource(styles);
const [isOpen, setIsOpen] = useState(false);
const resetProperty = () => {
+ if (readonly) {
+ return;
+ }
const batch = createBatchUpdate();
for (const property of properties) {
batch.deleteProperty(property);
@@ -319,6 +332,9 @@ export const PropertySectionLabel = ({
onPointerDown={(event) => event.preventDefault()}
triggerProps={{
onClick: (event) => {
+ if (readonly) {
+ return;
+ }
if (event.altKey) {
event.preventDefault();
resetProperty();
@@ -427,8 +443,12 @@ export const PropertyValueTooltip = ({
children: ReactNode;
}) => {
const styles = useComputedStyles(properties);
+ const readonly = useReadonly();
const [isOpen, setIsOpen] = useState(false);
const resetProperty = () => {
+ if (readonly) {
+ return;
+ }
const batch = createBatchUpdate();
for (const property of properties) {
batch.deleteProperty(property);
@@ -444,6 +464,9 @@ export const PropertyValueTooltip = ({
onPointerDown={(event) => event.preventDefault()}
triggerProps={{
onClick: (event) => {
+ if (readonly) {
+ return;
+ }
if (event.altKey) {
event.preventDefault();
resetProperty();
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
index 663455ee71..b6de24ae0b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx
@@ -22,17 +22,19 @@ import { getDots } from "../../shared/style-section";
import { CssEditor } from "../../../../shared/css-editor";
import { $advancedStyleDeclarations } from "./stores";
import { $selectedInstanceKey } from "~/shared/awareness";
+import { useReadonly } from "../../shared/readonly";
// Only here to keep the same section module interface
export const properties = [];
const AdvancedStyleSection = (props: {
label: string;
+ readonly: boolean;
properties: Array<CssProperty>;
onAdd: () => void;
children: ReactNode;
}) => {
- const { label, children, properties, onAdd } = props;
+ const { label, readonly, children, properties, onAdd } = props;
const [isOpen, setIsOpen] = useOpenState(label);
const styles = useComputedStyles(properties);
return (
@@ -45,6 +47,7 @@ const AdvancedStyleSection = (props: {
dots={getDots(styles)}
suffix={
<SectionTitleButton
+ disabled={readonly}
prefix={<PlusIcon />}
onClick={() => {
setIsOpen(true);
@@ -64,6 +67,7 @@ const AdvancedStyleSection = (props: {
export const Section = () => {
const advancedStyleDeclarations = useStore($advancedStyleDeclarations);
+ const readonly = useReadonly();
const properties = advancedStyleDeclarations.map(
(styleDecl) => styleDecl.property
);
@@ -129,12 +133,14 @@ export const Section = () => {
return (
<AdvancedStyleSection
label="Advanced"
+ readonly={readonly}
properties={properties}
onAdd={() => {
setShowAddStyleInput(true);
}}
>
<CssEditor
+ readonly={readonly}
declarations={advancedStyleDeclarations}
onDeleteProperty={handleDeleteProperty}
onSetProperty={setProperty}
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx
index 799fe48120..85ee65d5a4 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-code-editor.tsx
@@ -15,6 +15,7 @@ import {
} from "../../shared/repeated-style";
import { useComputedStyleDecl } from "../../shared/model";
import { InputErrorsTooltip, toast } from "@webstudio-is/design-system";
+import { useReadonly } from "../../shared/readonly";
type IntermediateValue = {
type: "intermediate";
@@ -39,6 +40,7 @@ export const BackgroundCodeEditor = ({
index,
onValidate,
}: BackgroundCodeEditorProps) => {
+ const readonly = useReadonly();
const styleDecl = useComputedStyleDecl("background-image");
let styleValue = styleDecl.cascadedValue;
if (styleValue.type === "layers") {
@@ -158,6 +160,7 @@ export const BackgroundCodeEditor = ({
css={getCodeEditorCssVars({ minHeight: "4lh", maxHeight: "4lh" })}
content={
<CssFragmentEditorContent
+ readOnly={readonly}
invalid={intermediateValue?.type === "invalid"}
autoFocus={styleValue.type === "var"}
value={textAreaValue ?? ""}
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
index 9937be0914..cc6a26462d 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
@@ -30,6 +30,7 @@ import {
} from "@webstudio-is/design-system";
import { SelectControl } from "../../controls";
import { ToggleGroupTooltip } from "../../controls/toggle-group/toggle-group-control";
+import { useReadonly } from "../../shared/readonly";
import { BackgroundSize } from "./background-size";
import { BackgroundGradient } from "./background-gradient";
import { BackgroundImage } from "./background-image";
@@ -119,6 +120,7 @@ const backgroundTypeOptions: BackgroundTypeOption[] = [
];
type BackgroundTypeToggleProps = {
+ disabled?: boolean;
value: BackgroundType;
onChange: (value: BackgroundType) => void;
backgroundStyleItem: StyleValue | undefined;
@@ -130,6 +132,7 @@ type BackgroundTypeToggleProps = {
};
const BackgroundTypeToggle = ({
+ disabled,
value,
onChange,
backgroundStyleItem,
@@ -183,6 +186,7 @@ const BackgroundTypeToggle = ({
return (
<ToggleGroup
type="single"
+ disabled={disabled}
value={value}
aria-label="Background type"
onValueChange={handleValueChange}
@@ -204,7 +208,13 @@ const BackgroundTypeToggle = ({
);
};
-const BackgroundRepeat = ({ index }: { index: number }) => {
+const BackgroundRepeat = ({
+ index,
+ disabled,
+}: {
+ index: number;
+ disabled?: boolean;
+}) => {
const styleDecl = useComputedStyleDecl("background-repeat");
const value = getRepeatedStyleItem(styleDecl, index);
const items = [
@@ -247,6 +257,7 @@ const BackgroundRepeat = ({ index }: { index: number }) => {
>
<ToggleGroup
type="single"
+ disabled={disabled}
value={toValue(value)}
aria-label="Background repeat"
onValueChange={(value) => {
@@ -293,7 +304,13 @@ const BackgroundRepeat = ({ index }: { index: number }) => {
);
};
-const BackgroundAttachment = ({ index }: { index: number }) => {
+const BackgroundAttachment = ({
+ index,
+ disabled,
+}: {
+ index: number;
+ disabled?: boolean;
+}) => {
const styleDecl = useComputedStyleDecl("background-attachment");
const value = getRepeatedStyleItem(styleDecl, index);
return (
@@ -304,6 +321,7 @@ const BackgroundAttachment = ({ index }: { index: number }) => {
>
<ToggleGroup
type="single"
+ disabled={disabled}
value={toValue(value)}
aria-label="Background attachment"
onValueChange={(value) => {
@@ -322,6 +340,7 @@ const BackgroundAttachment = ({ index }: { index: number }) => {
};
const OtherLayerProperties = ({ index }: { index: number }) => {
+ const readonly = useReadonly();
return (
<CollapsibleSectionRoot label={"More properties"} fullWidth={true}>
<Flex
@@ -335,24 +354,28 @@ const OtherLayerProperties = ({ index }: { index: number }) => {
description={propertyDescriptions.backgroundBlendMode}
properties={["background-blend-mode"]}
/>
- <SelectControl property="background-blend-mode" index={index} />
+ <SelectControl
+ disabled={readonly}
+ property="background-blend-mode"
+ index={index}
+ />
</Grid>
- <BackgroundSize index={index} />
- <BackgroundPosition index={index} />
+ <BackgroundSize disabled={readonly} index={index} />
+ <BackgroundPosition disabled={readonly} index={index} />
<Grid columns={2} align="center" gap={2}>
<PropertyLabel
label="Repeat"
description={propertyDescriptions.backgroundRepeat}
properties={["background-repeat"]}
/>
- <BackgroundRepeat index={index} />
+ <BackgroundRepeat disabled={readonly} index={index} />
<PropertyLabel
label="Attachment"
description={propertyDescriptions.backgroundAttachment}
properties={["background-attachment"]}
/>
- <BackgroundAttachment index={index} />
+ <BackgroundAttachment disabled={readonly} index={index} />
</Grid>
<Grid columns={2} align="center" gap={2}>
<PropertyLabel
@@ -360,14 +383,22 @@ const OtherLayerProperties = ({ index }: { index: number }) => {
description={propertyDescriptions.backgroundClip}
properties={["background-clip"]}
/>
- <SelectControl property="background-clip" index={index} />
+ <SelectControl
+ disabled={readonly}
+ property="background-clip"
+ index={index}
+ />
<PropertyLabel
label="Origin"
description={propertyDescriptions.backgroundOrigin}
properties={["background-origin"]}
/>
- <SelectControl property="background-origin" index={index} />
+ <SelectControl
+ disabled={readonly}
+ property="background-origin"
+ index={index}
+ />
</Grid>
</Flex>
</CollapsibleSectionRoot>
@@ -375,6 +406,7 @@ const OtherLayerProperties = ({ index }: { index: number }) => {
};
export const BackgroundContent = ({ index }: { index: number }) => {
+ const readonly = useReadonly();
const backgroundImage = useComputedStyleDecl("background-image");
const backgroundStyleItem = getBackgroundStyleItem(backgroundImage, index);
@@ -401,6 +433,7 @@ export const BackgroundContent = ({ index }: { index: number }) => {
description={propertyDescriptions.backgroundImage}
/>
<BackgroundTypeToggle
+ disabled={readonly}
value={backgroundType}
onChange={setBackgroundType}
backgroundStyleItem={backgroundStyleItem}
@@ -431,7 +464,9 @@ export const BackgroundContent = ({ index }: { index: number }) => {
/>
)}
- {backgroundType === "image" && <BackgroundImage index={index} />}
+ {backgroundType === "image" && (
+ <BackgroundImage index={index} disabled={readonly} />
+ )}
<Separator />
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx
index 3b3eec1849..9edeb5aa4e 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-gradient.tsx
@@ -86,6 +86,7 @@ import {
} from "./gradient-utils";
import { BackgroundPositionControl } from "./background-position";
import { BackgroundCodeEditor } from "./background-code-editor";
+import { useReadonly } from "../../shared/readonly";
import type {
GradientType,
IntermediateColorValue,
@@ -140,6 +141,7 @@ export const BackgroundGradient = ({
type?: GradientType;
variant?: "default" | "solid";
}) => {
+ const readonly = useReadonly();
const styleDecl = useComputedStyleDecl("background-image");
let styleValue = styleDecl.cascadedValue;
let computedStyleValue = styleDecl.computedValue;
@@ -256,6 +258,7 @@ export const BackgroundGradient = ({
{isSolidVariant ? (
<Box css={{ padding: theme.panel.padding }}>
<SolidColorControls
+ disabled={readonly}
gradient={gradient}
applyGradient={applyGradient}
/>
@@ -263,6 +266,7 @@ export const BackgroundGradient = ({
) : (
<>
<GradientPickerSection
+ disabled={readonly}
gradient={gradient}
computedGradient={computedParsedGradient}
gradientType={gradientType}
@@ -275,6 +279,7 @@ export const BackgroundGradient = ({
<Separator />
<Box css={{ paddingInline: theme.panel.paddingInline }}>
<OtherGradientPropertiesSection
+ disabled={readonly}
gradient={gradient}
applyGradient={applyGradient}
isRepeating={isRepeating}
@@ -283,6 +288,7 @@ export const BackgroundGradient = ({
</Box>
<Box css={{ paddingInline: theme.panel.paddingInline }}>
<GradientPositionControls
+ disabled={readonly}
gradient={gradient}
applyGradient={applyGradient}
/>
@@ -302,6 +308,7 @@ export const BackgroundGradient = ({
};
type GradientPickerSectionProps = {
+ disabled?: boolean;
gradient: ParsedGradient;
computedGradient: ParsedGradient;
gradientType: GradientType;
@@ -313,6 +320,7 @@ type GradientPickerSectionProps = {
};
const GradientPickerSection = ({
+ disabled,
gradient,
computedGradient,
gradientType,
@@ -368,6 +376,7 @@ const GradientPickerSection = ({
css={{ padding: theme.panel.padding }}
>
<GradientPicker
+ disabled={disabled}
gradient={computedGradientForPicker}
backgroundImage={formatLinearGradient(previewGradientForTrack)}
type={gradientType}
@@ -377,6 +386,7 @@ const GradientPickerSection = ({
selectedStopIndex={selectedStopIndex}
/>
<GradientStopControls
+ disabled={disabled}
gradient={gradient}
computedGradient={computedGradient}
selectedStopIndex={selectedStopIndex}
@@ -390,6 +400,7 @@ const GradientPickerSection = ({
};
type OtherGradientPropertiesSectionProps = {
+ disabled?: boolean;
gradient: ParsedGradient;
applyGradient: GradientEditorApplyFn;
isRepeating: boolean;
@@ -397,6 +408,7 @@ type OtherGradientPropertiesSectionProps = {
};
const OtherGradientPropertiesSection = ({
+ disabled,
gradient,
applyGradient,
isRepeating,
@@ -549,6 +561,7 @@ const OtherGradientPropertiesSection = ({
description="Direction of the gradient line. 0deg is up, 90deg is right, 180deg is down, 270deg is left."
/>
<CssValueInputContainer
+ disabled={disabled}
property="rotate"
styleSource="default"
getOptions={getAvailableUnitVariables}
@@ -566,6 +579,7 @@ const OtherGradientPropertiesSection = ({
description="Radial gradient size determining how far the gradient extends from its center."
/>
<Select
+ disabled={disabled}
options={radialSizeOptions}
value={radialSizeValue}
fullWidth
@@ -581,6 +595,7 @@ const OtherGradientPropertiesSection = ({
description="Radial gradient ending shape."
/>
<ToggleGroup
+ disabled={disabled}
type="single"
value={radialShapeValue}
aria-label="Radial ending shape"
@@ -611,6 +626,7 @@ const OtherGradientPropertiesSection = ({
description="Whether to repeat the gradient pattern."
/>
<ToggleGroup
+ disabled={disabled}
type="single"
value={isRepeating ? "repeat" : "no-repeat"}
aria-label="Gradient repeat"
@@ -640,11 +656,13 @@ const OtherGradientPropertiesSection = ({
};
type SolidColorControlsProps = {
+ disabled?: boolean;
gradient: ParsedGradient;
applyGradient: GradientEditorApplyFn;
};
const SolidColorControls = ({
+ disabled,
gradient,
applyGradient,
}: SolidColorControlsProps) => {
@@ -689,6 +707,7 @@ const SolidColorControls = ({
/>
<Flex css={{ gridColumn: "span 2" }}>
<ColorPickerControl
+ disabled={disabled}
property="color"
value={solidColor}
currentColor={solidColor}
@@ -703,6 +722,7 @@ const SolidColorControls = ({
};
type GradientStopControlsProps = {
+ disabled?: boolean;
gradient: ParsedGradient;
computedGradient: ParsedGradient;
selectedStopIndex: number;
@@ -713,6 +733,7 @@ type GradientStopControlsProps = {
};
const GradientStopControls = ({
+ disabled,
gradient,
computedGradient,
selectedStopIndex,
@@ -806,13 +827,17 @@ const GradientStopControls = ({
<IconButton
aria-label="Reverse gradient stops"
onClick={handleReverseStops}
- disabled={reverseDisabled}
+ disabled={disabled || reverseDisabled}
>
<ArrowRightLeftIcon />
</IconButton>
</Tooltip>
<Tooltip content="Add gradient stop" variant="wrapped">
- <IconButton aria-label="Add stop" onClick={handleAddStop}>
+ <IconButton
+ aria-label="Add stop"
+ disabled={disabled}
+ onClick={handleAddStop}
+ >
<PlusIcon />
</IconButton>
</Tooltip>
@@ -978,6 +1003,7 @@ const GradientStopControls = ({
>
<Box>
<CssValueInputContainer
+ disabled={disabled}
property={"background-position-x"}
styleSource="default"
getOptions={getAvailableUnitVariables}
@@ -994,6 +1020,7 @@ const GradientStopControls = ({
>
<Box>
<CssValueInputContainer
+ disabled={disabled}
property={"background-position-x"}
styleSource="default"
getOptions={getAvailableUnitVariables}
@@ -1007,6 +1034,7 @@ const GradientStopControls = ({
<Tooltip content="Color of this gradient stop." variant="wrapped">
<Box>
<ColorPickerControl
+ disabled={disabled}
property="color"
value={stopColor}
currentColor={currentColor}
@@ -1022,7 +1050,7 @@ const GradientStopControls = ({
<IconButton
aria-label="Delete stop"
onClick={() => handleDeleteStop(stopIndex)}
- disabled={gradient.stops.length <= 2}
+ disabled={disabled || gradient.stops.length <= 2}
>
<MinusIcon />
</IconButton>
@@ -1035,11 +1063,13 @@ const GradientStopControls = ({
};
type GradientPositionControlsProps = {
+ disabled?: boolean;
gradient: ParsedGradient;
applyGradient: GradientEditorApplyFn;
};
const GradientPositionControls = ({
+ disabled,
gradient,
applyGradient,
}: GradientPositionControlsProps) => {
@@ -1125,6 +1155,7 @@ const GradientPositionControls = ({
return (
<BackgroundPositionControl
+ disabled={disabled}
label="Position"
xAxis={{
label: "Left",
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx
index 9e0db0603f..8f7c1b1de1 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-image.tsx
@@ -8,7 +8,13 @@ import { BackgroundCodeEditor } from "./background-code-editor";
import { $assets } from "~/shared/sync/data-stores";
import { isAbsoluteUrl } from "@webstudio-is/sdk";
-export const BackgroundImage = ({ index }: { index: number }) => {
+export const BackgroundImage = ({
+ index,
+ disabled,
+}: {
+ index: number;
+ disabled?: boolean;
+}) => {
const elementRef = useRef<HTMLDivElement>(null);
const handleValidate = useCallback(
@@ -64,7 +70,11 @@ export const BackgroundImage = ({ index }: { index: number }) => {
ref={elementRef}
data-floating-panel-container
>
- <ImageControl property="background-image" index={index} />
+ <ImageControl
+ property="background-image"
+ index={index}
+ disabled={disabled}
+ />
</Box>
</Grid>
<BackgroundCodeEditor index={index} onValidate={handleValidate} />
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx
index 5e32206081..0bfcee5c2f 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx
@@ -54,12 +54,14 @@ type AxisControlProps = {
export const BackgroundPositionControl = ({
label = "Position",
description = propertyDescriptions.backgroundPosition,
+ disabled,
xAxis,
yAxis,
onSelect,
}: {
label?: string;
description?: string;
+ disabled?: boolean;
xAxis: AxisControlProps;
yAxis: AxisControlProps;
onSelect: (position: { x: number; y: number }) => void;
@@ -92,6 +94,7 @@ export const BackgroundPositionControl = ({
)}
<Grid gap="2" columns={2}>
<PositionGrid
+ disabled={disabled}
selectedPosition={{
x: calculateBackgroundPosition(xAxis.value),
y: calculateBackgroundPosition(yAxis.value),
@@ -116,6 +119,7 @@ export const BackgroundPositionControl = ({
/>
)}
<CssValueInputContainer
+ disabled={disabled}
property={xAxis.property}
styleSource="default"
getOptions={xAxis.getOptions}
@@ -137,6 +141,7 @@ export const BackgroundPositionControl = ({
/>
)}
<CssValueInputContainer
+ disabled={disabled}
property={yAxis.property}
styleSource="default"
getOptions={yAxis.getOptions}
@@ -151,7 +156,13 @@ export const BackgroundPositionControl = ({
);
};
-export const BackgroundPosition = ({ index }: { index: number }) => {
+export const BackgroundPosition = ({
+ index,
+ disabled,
+}: {
+ index: number;
+ disabled?: boolean;
+}) => {
const [backgroundPositionX, backgroundPositionY] = useComputedStyles([
"background-position-x",
"background-position-y",
@@ -176,6 +187,7 @@ export const BackgroundPosition = ({ index }: { index: number }) => {
return (
<BackgroundPositionControl
+ disabled={disabled}
xAxis={{
label: "Left",
description: "Left position offset",
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx
index 5de8b7a4fe..7c527849de 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-size.tsx
@@ -49,7 +49,13 @@ const toTuple = (
};
};
-export const BackgroundSize = ({ index }: { index: number }) => {
+export const BackgroundSize = ({
+ index,
+ disabled,
+}: {
+ index: number;
+ disabled?: boolean;
+}) => {
const property = "background-size";
const styleDecl = useComputedStyleDecl(property);
const styleValue = getRepeatedStyleItem(styleDecl, index);
@@ -88,6 +94,7 @@ export const BackgroundSize = ({ index }: { index: number }) => {
<Select
// show empty field instead of radix placeholder
// like css value input does
+ disabled={disabled}
placeholder=""
options={selectOptions}
value={selectValue}
@@ -144,6 +151,7 @@ export const BackgroundSize = ({ index }: { index: number }) => {
/>
<CssValueInputContainer
+ disabled={disabled}
property={property}
styleSource="default"
getOptions={() => customSizeOptions}
@@ -153,6 +161,7 @@ export const BackgroundSize = ({ index }: { index: number }) => {
/>
<CssValueInputContainer
+ disabled={disabled}
property={property}
styleSource="default"
getOptions={() => customSizeOptions}
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
index cdea476986..1a40956dd7 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
@@ -8,6 +8,7 @@ import {
useComputedStyles,
} from "../../shared/model";
import { createBatchUpdate } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
import { keywordValues } from "@webstudio-is/css-data";
export const properties = [
@@ -18,6 +19,7 @@ export const properties = [
] satisfies [CssProperty, ...CssProperty[]];
export const BorderColor = () => {
+ const readonly = useReadonly();
const styles = useComputedStyles(properties);
const serialized = styles.map((styleDecl) =>
toValue(styleDecl.cascadedValue)
@@ -50,7 +52,7 @@ export const BorderColor = () => {
>
<div>
<ColorPickerControl
- disabled={isAdvanced}
+ disabled={isAdvanced || readonly}
currentColor={currentColor}
property={local.property}
value={value}
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/border-property.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/border-property.tsx
index c2250380ad..e1f9e2d575 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/border-property.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/border-property.tsx
@@ -16,6 +16,7 @@ import {
setProperty,
} from "../../shared/use-style-data";
import { $availableUnitVariables, useComputedStyles } from "../../shared/model";
+import { useReadonly } from "../../shared/readonly";
export const BorderProperty = ({
individualModeIcon,
@@ -30,6 +31,7 @@ export const BorderProperty = ({
label: string;
description: string;
}) => {
+ const readonly = useReadonly();
const borderProperties = Object.keys(borderPropertyOptions) as [
CssProperty,
...CssProperty[],
@@ -76,6 +78,7 @@ export const BorderProperty = ({
}}
>
<CssValueInputContainer
+ disabled={readonly}
property={firstPropertyName}
styleSource={styleValueSourceColor}
getOptions={() => [
@@ -105,6 +108,7 @@ export const BorderProperty = ({
{individualModeIcon && (
<ToggleButton
+ disabled={readonly}
pressed={showIndividualMode}
onPressedChange={setShowIndividualMode}
>
@@ -117,6 +121,7 @@ export const BorderProperty = ({
{styles.map((styleDecl) => (
<CssValueInputContainer
key={styleDecl.property}
+ disabled={readonly}
icon={borderPropertyOptions[styleDecl.property]?.icon}
property={styleDecl.property}
styleSource={styleDecl.source.name}
diff --git a/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx b/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
index 05857a3cb7..b768fb6d74 100644
--- a/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
@@ -29,6 +29,7 @@ import { useState } from "react";
import { useStore } from "@nanostores/react";
import { useComputedStyles } from "../../shared/model";
import { createBatchUpdate } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
import { AlignSelfControl } from "../shared/align-self";
import { OrderControl } from "../shared/order";
import { $selectedInstancePath, selectInstance } from "~/shared/awareness";
@@ -88,6 +89,7 @@ const getSizingValue = (flexGrow: string, flexShrink: string) => {
};
const FlexChildSectionSizing = () => {
+ const readonly = useReadonly();
const styles = useComputedStyles(["flex-grow", "flex-shrink", "flex-basis"]);
const [flexGrow, flexShrink, flexBasis] = styles;
const styleValueSource = getPriorityStyleValueSource(styles);
@@ -148,6 +150,7 @@ const FlexChildSectionSizing = () => {
{/* We don't support "flex" shorthand and
this control is manipulating 3 properties at once */}
<ToggleGroup
+ disabled={readonly}
color={styleValueSource}
type="single"
value={selectedValue}
diff --git a/apps/builder/app/builder/features/style-panel/sections/grid-child/grid-child.tsx b/apps/builder/app/builder/features/style-panel/sections/grid-child/grid-child.tsx
index 47ba3e8f51..61ed18bb9a 100644
--- a/apps/builder/app/builder/features/style-panel/sections/grid-child/grid-child.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/grid-child/grid-child.tsx
@@ -31,6 +31,7 @@ import {
deleteProperty,
resetEphemeralStyles,
} from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
import { getGridDimensions } from "../layout/shared/grid-areas";
import { GridAreaPicker } from "../layout/shared/grid-area-picker";
import {
@@ -258,6 +259,7 @@ const GridChildPositionMode = ({
value: PositionMode;
onChange: (value: PositionMode) => void;
}) => {
+ const readonly = useReadonly();
const [activeTooltip, setActiveTooltip] = useState<string | undefined>();
const items = [
@@ -294,6 +296,7 @@ const GridChildPositionMode = ({
]}
/>
<ToggleGroup
+ disabled={readonly}
type="single"
value={value}
onValueChange={(newValue) => {
@@ -369,6 +372,7 @@ const SpanInput = ({
property: "grid-column-end" | "grid-row-end";
startProperty: "grid-column-start" | "grid-row-start";
}) => {
+ const readonly = useReadonly();
const computedStyleDecl = useComputedStyleDecl(property);
const value = computedStyleDecl.cascadedValue;
const [intermediateValue, setIntermediateValue] = useState<
@@ -453,6 +457,7 @@ const SpanInput = ({
return (
<CssValueInput
+ disabled={readonly}
styleSource={computedStyleDecl.source.name}
property={property}
value={displayValue}
@@ -494,6 +499,7 @@ const SpanInput = ({
};
const GridChildPositionArea = () => {
+ const readonly = useReadonly();
const parentGridTemplateAreas = useParentComputedStyleDecl(
"grid-template-areas"
);
@@ -532,6 +538,7 @@ const GridChildPositionArea = () => {
<Grid css={{ gridTemplateColumns: "3fr 8fr" }}>
<div />
<Select
+ disabled={readonly}
options={areaNames}
value={selectedArea}
onChange={handleAreaChange}
@@ -542,6 +549,7 @@ const GridChildPositionArea = () => {
};
const GridChildPositionManual = () => {
+ const readonly = useReadonly();
const parentGridTemplateColumns = useParentComputedStyleDecl(
"grid-template-columns"
);
@@ -684,6 +692,7 @@ const GridChildPositionManual = () => {
>
<div />
<GridPositionInputs
+ disabled={readonly}
value={localValue.value}
onChange={handleChange}
onBlur={() => {
@@ -695,6 +704,7 @@ const GridChildPositionManual = () => {
/>
</Grid>
<GridAreaPicker
+ disabled={readonly}
value={{
name: "",
...localValue.value,
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/layout.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/layout.tsx
index 0f26d00e0d..69d0fc1923 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/layout.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/layout.tsx
@@ -44,6 +44,7 @@ import {
} from "@webstudio-is/icons";
import { MenuControl, SelectControl } from "../../controls";
import { createBatchUpdate, deleteProperty } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
import { StyleSection } from "../../shared/style-section";
import {
type IntermediateStyleValue,
@@ -68,12 +69,15 @@ import { DEFAULT_GRID_TRACK_COUNT, DEFAULT_GRID_GAP } from "./shared/constants";
const GapLinked = ({
isLinked,
onChange,
+ disabled,
}: {
isLinked: boolean;
onChange: (isLinked: boolean) => void;
+ disabled?: boolean;
}) => (
<EnhancedTooltip content={isLinked ? "Unlink gap values" : "Link gap values"}>
<SmallToggleButton
+ disabled={disabled}
pressed={isLinked}
onPressedChange={onChange}
variant="normal"
@@ -137,6 +141,7 @@ const GapInput = ({
onPreviewChange,
onChange,
onReset,
+ disabled,
}: {
icon: JSX.Element;
property: CssProperty;
@@ -146,10 +151,12 @@ const GapInput = ({
onPreviewChange: (value?: StyleValue) => void;
onChange: (value: StyleValue) => void;
onReset: () => void;
+ disabled?: boolean;
}) => {
return (
<Box>
<CssValueInput
+ disabled={disabled}
styleSource={styleDecl.source.name}
icon={
<GapTooltip
@@ -204,6 +211,7 @@ const GapInput = ({
};
const Gap = () => {
+ const readonly = useReadonly();
const [columnGap, rowGap] = useComputedStyles(["column-gap", "row-gap"]);
const [isLinked, setIsLinked] = useState(
() => toValue(columnGap.cascadedValue) === toValue(rowGap.cascadedValue)
@@ -229,6 +237,7 @@ const Gap = () => {
>
<Box css={{ gridArea: "column-gap" }}>
<GapInput
+ disabled={readonly}
icon={
<GapHorizontalIcon
onClick={(event) => {
@@ -287,6 +296,7 @@ const Gap = () => {
<Flex css={{ gridArea: "linked", px: theme.spacing[3] }} justify="center">
<GapLinked
+ disabled={readonly}
isLinked={isLinked}
onChange={(isLinked) => {
setIsLinked(isLinked);
@@ -314,6 +324,7 @@ const Gap = () => {
<Box css={{ gridArea: "row-gap" }}>
<GapInput
+ disabled={readonly}
icon={
<GapVerticalIcon
onClick={(event) => {
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-area-picker.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-area-picker.tsx
index f967ad195c..7072b671bd 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-area-picker.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-area-picker.tsx
@@ -180,6 +180,7 @@ type GridAreaPickerProps = {
gridColumns: number;
gridRows: number;
otherAreas: AreaInfo[];
+ disabled?: boolean;
};
export const GridAreaPicker = ({
@@ -189,6 +190,7 @@ export const GridAreaPicker = ({
gridColumns,
gridRows,
otherAreas,
+ disabled,
}: GridAreaPickerProps) => {
const anchorRef = useRef<{ col: number; row: number }>({
col: value.columnStart,
@@ -252,6 +254,7 @@ export const GridAreaPicker = ({
result.push(
<button
key={`${col},${row}`}
+ disabled={disabled}
className={isSelected ? selectedCellStyle() : freeCellStyle()}
style={{
gridColumn: `${col} / ${col + 1}`,
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-areas.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-areas.tsx
index 754e7497b5..2a97946741 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-areas.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-areas.tsx
@@ -29,6 +29,7 @@ import { createBatchUpdate } from "../../../shared/use-style-data";
import { GridPositionInputs } from "./grid-position-inputs";
import { GridAreaPicker } from "./grid-area-picker";
import { $gridEditingArea } from "~/builder/shared/nano-states";
+import { useReadonly } from "../../../shared/readonly";
export { parseGridAreas, type AreaInfo } from "@webstudio-is/css-data";
@@ -225,6 +226,7 @@ type AreaEditorProps = {
gridColumns: number;
gridRows: number;
existingAreas: AreaInfo[];
+ disabled?: boolean;
onSave: (area: AreaInfo, oldName?: string) => void;
onClose: () => void;
};
@@ -235,6 +237,7 @@ const AreaEditor = ({
gridColumns,
gridRows,
existingAreas,
+ disabled,
onSave,
onClose,
}: AreaEditorProps) => {
@@ -329,6 +332,7 @@ const AreaEditor = ({
>
<Label>Name</Label>
<InputField
+ disabled={disabled}
css={{ gridColumn: "span 2" }}
value={value.name}
onChange={(event) => setValue({ ...value, name: event.target.value })}
@@ -355,6 +359,7 @@ const AreaEditor = ({
>
<Label css={{ paddingTop: theme.spacing[3] }}>Position</Label>
<GridPositionInputs
+ disabled={disabled}
value={{
...value,
columnEnd: value.columnEnd - 1,
@@ -384,6 +389,7 @@ const AreaEditor = ({
</Grid>
<GridAreaPicker
+ disabled={disabled}
value={value}
onChange={(picked) => {
setValue(picked);
@@ -427,6 +433,7 @@ const AreaEditor = ({
};
export const GridAreas = () => {
+ const readonly = useReadonly();
const [isOpen, setIsOpen] = useOpenState("Areas");
const [editingAreaIndex, setEditingAreaIndex] = useState<number | undefined>(
undefined
@@ -608,6 +615,7 @@ export const GridAreas = () => {
Areas ({areas.length})
</Text>
<IconButton
+ disabled={readonly}
onClick={(e) => {
e.stopPropagation();
addArea();
@@ -636,6 +644,7 @@ export const GridAreas = () => {
title="Edit area"
content={
<AreaEditor
+ disabled={readonly}
area={area}
editingIndex={index}
gridColumns={columns}
@@ -668,6 +677,7 @@ export const GridAreas = () => {
buttons={
<SmallIconButton
variant="destructive"
+ disabled={readonly}
tabIndex={-1}
icon={<MinusIcon />}
onClick={(e) => {
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-generator.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-generator.tsx
index bf722971c3..d6036cb3b6 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-generator.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-generator.tsx
@@ -25,6 +25,7 @@ import {
} from "@webstudio-is/css-data";
import { useComputedStyleDecl } from "../../../shared/model";
import { createBatchUpdate } from "../../../shared/use-style-data";
+import { useReadonly } from "../../../shared/readonly";
import {
$breakpoints,
$gridCellData,
@@ -377,6 +378,7 @@ type GridGeneratorProps = {
};
export const GridGenerator = ({ open, onOpenChange }: GridGeneratorProps) => {
+ const readonly = useReadonly();
const gridTemplateColumns = useComputedStyleDecl("grid-template-columns");
const gridTemplateRows = useComputedStyleDecl("grid-template-rows");
const gridTemplateAreas = useComputedStyleDecl("grid-template-areas");
@@ -578,6 +580,7 @@ export const GridGenerator = ({ open, onOpenChange }: GridGeneratorProps) => {
>
{/* Visual grid preview - similar to Figma's style */}
<button
+ disabled={readonly}
aria-label={`Grid layout: ${columnCount} columns by ${rowCount} rows`}
className={gridGeneratorButtonStyle()}
style={{
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-position-inputs.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-position-inputs.tsx
index 00030ccec4..94d46c01e7 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-position-inputs.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-position-inputs.tsx
@@ -58,6 +58,7 @@ type GridPositionInputsProps = {
gridColumns: number;
gridRows: number;
checkBounds?: boolean;
+ disabled?: boolean;
/**
* When true, "end" values are inclusive track indices (1-based)
* instead of exclusive grid-line numbers.
@@ -80,6 +81,7 @@ const PositionInputGroup = ({
minEnd,
maxEnd,
label,
+ disabled,
}: {
startValue: number;
endValue: number;
@@ -93,11 +95,13 @@ const PositionInputGroup = ({
minEnd: number;
maxEnd: number;
label: string;
+ disabled?: boolean;
onKeyDown?: (event: React.KeyboardEvent) => void;
}) => (
<Flex direction="column" gap="1" css={{ flex: 1 }}>
<Grid css={{ gridTemplateColumns: "1fr 1fr", gap: theme.spacing[3] }}>
<InputField
+ disabled={disabled}
type="number"
value={String(startValue)}
onChange={(event) => {
@@ -113,6 +117,7 @@ const PositionInputGroup = ({
max={maxStart}
/>
<InputField
+ disabled={disabled}
type="number"
value={String(endValue)}
onChange={(event) => {
@@ -143,6 +148,7 @@ export const GridPositionInputs = ({
gridRows,
checkBounds = false,
inclusiveEnd = false,
+ disabled,
}: GridPositionInputsProps) => {
const validation = validateGridPosition(value, gridColumns, gridRows, {
checkBounds,
@@ -156,6 +162,7 @@ export const GridPositionInputs = ({
return (
<Flex gap="2">
<PositionInputGroup
+ disabled={disabled}
startValue={value.columnStart}
endValue={value.columnEnd}
onStartChange={(columnStart) => onChange({ ...value, columnStart })}
@@ -171,6 +178,7 @@ export const GridPositionInputs = ({
label="Column: start/end"
/>
<PositionInputGroup
+ disabled={disabled}
startValue={value.rowStart}
endValue={value.rowEnd}
onStartChange={(rowStart) => onChange({ ...value, rowStart })}
diff --git a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-settings.tsx b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-settings.tsx
index 4942219af7..8966674503 100644
--- a/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-settings.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/layout/shared/grid-settings.tsx
@@ -27,6 +27,7 @@ import {
import { PlusIcon, MinusIcon } from "@webstudio-is/icons";
import { useStore } from "@nanostores/react";
import { $selectedInstance } from "~/shared/awareness";
+import { useReadonly } from "../../../shared/readonly";
import { useComputedStyleDecl } from "../../../shared/model";
import { CssValueInputContainer } from "../../../shared/css-value-input";
import { createBatchUpdate } from "../../../shared/use-style-data";
@@ -82,6 +83,7 @@ type TrackItemProps = {
isEditing: boolean;
isAuto?: boolean;
canRemove: boolean;
+ disabled?: boolean;
onEditingChange: (open: boolean) => void;
onUpdate: (index: number, newValue: string) => void;
onRemove: (index: number) => void;
@@ -99,6 +101,7 @@ const TrackItem = ({
isEditing,
isAuto,
canRemove,
+ disabled,
onEditingChange,
onUpdate,
onRemove,
@@ -156,6 +159,7 @@ const TrackItem = ({
<Flex direction="column" gap="1">
<Label>Min</Label>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={property}
value={{
@@ -175,6 +179,7 @@ const TrackItem = ({
<Flex direction="column" gap="1">
<Label>Max</Label>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={property}
value={{
@@ -196,6 +201,7 @@ const TrackItem = ({
<Flex direction="column" gap="1">
<Label>Value</Label>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={property}
value={{
@@ -215,6 +221,7 @@ const TrackItem = ({
)}
<Flex align="center" gap="2">
<Checkbox
+ disabled={disabled}
id={`minmax-${id}`}
checked={isMinmax}
onCheckedChange={handleMinmaxToggle}
@@ -243,7 +250,7 @@ const TrackItem = ({
<SmallIconButton
variant="destructive"
tabIndex={-1}
- disabled={canRemove === false}
+ disabled={canRemove === false || disabled}
icon={<MinusIcon />}
onClick={(e) => {
e.stopPropagation();
@@ -274,6 +281,7 @@ const TrackEditor = ({
autoTrackCount,
disabled = false,
}: TrackEditorProps) => {
+ const readonly = useReadonly();
const { plural } = trackTypeLabels[trackType];
const isAuto =
property === "grid-auto-columns" || property === "grid-auto-rows";
@@ -386,7 +394,7 @@ const TrackEditor = ({
</Text>
{!isAuto && (
<IconButton
- disabled={disabled}
+ disabled={disabled || readonly}
onClick={(e) => {
e.stopPropagation();
addTrack();
@@ -423,6 +431,7 @@ const TrackEditor = ({
isEditing={editingIndex === index}
isAuto={isAuto}
canRemove={tracks.length > 1}
+ disabled={readonly}
onEditingChange={(open) => {
if (open) {
setEditingIndex(index);
@@ -450,6 +459,7 @@ type GridSettingsProps = {
};
export const GridSettings = ({ open, onOpenChange }: GridSettingsProps) => {
+ const readonly = useReadonly();
const selectedInstance = useStore($selectedInstance);
const gridTemplateColumns = useComputedStyleDecl("grid-template-columns");
const gridTemplateRows = useComputedStyleDecl("grid-template-rows");
@@ -480,7 +490,7 @@ export const GridSettings = ({ open, onOpenChange }: GridSettingsProps) => {
const isRowsEditable = isEditableGridMode(rowsMode);
const editGridButton = (
- <Button color="neutral" css={{ width: "100%" }}>
+ <Button disabled={readonly} color="neutral" css={{ width: "100%" }}>
Configure grid
</Button>
);
diff --git a/apps/builder/app/builder/features/style-panel/sections/position/inset-control.tsx b/apps/builder/app/builder/features/style-panel/sections/position/inset-control.tsx
index 7b84538256..b92b786f58 100644
--- a/apps/builder/app/builder/features/style-panel/sections/position/inset-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/position/inset-control.tsx
@@ -7,6 +7,7 @@ import { useScrub } from "../shared/scrub";
import { ValueText } from "../shared/value-text";
import { useComputedStyleDecl, useComputedStyles } from "../../shared/model";
import { useModifierKeys, type Modifiers } from "../../shared/modifier-keys";
+import { useReadonly } from "../../shared/readonly";
import { InputPopover } from "../shared/input-popover";
import { InsetLayout, type InsetProperty } from "./inset-layout";
import { getInsetModifiersGroup, InsetTooltip } from "./inset-tooltip";
@@ -68,6 +69,7 @@ type HoverTarget = {
};
export const InsetControl = () => {
+ const readonly = useReadonly();
const styles = useComputedStyles(["top", "right", "bottom", "left"]);
const [hoverTarget, setHoverTarget] = useState<HoverTarget>();
const styleValue = styles.find(
@@ -76,9 +78,15 @@ export const InsetControl = () => {
const scrubStatus = useScrub({
value: styleValue?.usedValue,
- target: styleValue?.cascadedValue.type === "unit" ? hoverTarget : undefined,
+ target:
+ readonly || styleValue?.cascadedValue.type !== "unit"
+ ? undefined
+ : hoverTarget,
getModifiersGroup: getInsetModifiersGroup,
onChange: (values, options) => {
+ if (readonly) {
+ return;
+ }
const batch = createBatchUpdate();
for (const property of ["top", "right", "bottom", "left"] as const) {
const value = values[property];
@@ -132,7 +140,8 @@ export const InsetControl = () => {
return (
<Grid
ref={layoutRef}
- tabIndex={0}
+ tabIndex={readonly ? -1 : 0}
+ aria-disabled={readonly || undefined}
css={{
// Create stacking context to prevent z-index issues with internal z-indexes
zIndex: 0,
@@ -145,28 +154,34 @@ export const InsetControl = () => {
outline: `1px solid ${theme.colors.backgroundPrimary}`,
outlineOffset: -1,
},
+ ...(readonly ? { opacity: 0.5, pointerEvents: "none" } : undefined),
}}
- onFocus={keyboardNavigation.handleFocus}
- onBlur={keyboardNavigation.handleBlur}
- onKeyDown={keyboardNavigation.handleKeyDown}
- onMouseMove={keyboardNavigation.handleMouseMove}
- onMouseLeave={keyboardNavigation.handleMouseLeave}
- onClick={(event) => {
- const property = hoverTarget?.property;
- const styleValueSource = styles.find(
- (styleDecl) => styleDecl.property === property
- )?.source.name;
- if (
- event.altKey &&
- property &&
- // reset when the value is set and after try to edit two sides
- (styleValueSource === "local" || styleValueSource === "overwritten")
- ) {
- deleteProperty(property);
- return;
- }
- handleOpenProperty(property);
- }}
+ onFocus={readonly ? undefined : keyboardNavigation.handleFocus}
+ onBlur={readonly ? undefined : keyboardNavigation.handleBlur}
+ onKeyDown={readonly ? undefined : keyboardNavigation.handleKeyDown}
+ onMouseMove={readonly ? undefined : keyboardNavigation.handleMouseMove}
+ onMouseLeave={readonly ? undefined : keyboardNavigation.handleMouseLeave}
+ onClick={
+ readonly
+ ? undefined
+ : (event) => {
+ const property = hoverTarget?.property;
+ const styleValueSource = styles.find(
+ (styleDecl) => styleDecl.property === property
+ )?.source.name;
+ if (
+ event.altKey &&
+ property &&
+ // reset when the value is set and after try to edit two sides
+ (styleValueSource === "local" ||
+ styleValueSource === "overwritten")
+ ) {
+ deleteProperty(property);
+ return;
+ }
+ handleOpenProperty(property);
+ }
+ }
>
<InsetLayout
getActiveProperties={getActiveProperties}
diff --git a/apps/builder/app/builder/features/style-panel/sections/shared/order.tsx b/apps/builder/app/builder/features/style-panel/sections/shared/order.tsx
index e8556a777d..fd7f5a88c6 100644
--- a/apps/builder/app/builder/features/style-panel/sections/shared/order.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/shared/order.tsx
@@ -20,6 +20,7 @@ import { PropertyLabel } from "../../property-label";
import { propertyDescriptions } from "@webstudio-is/css-data";
import { useComputedStyleDecl } from "../../shared/model";
import { setProperty } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
const OrderPopover = () => {
return (
@@ -51,6 +52,7 @@ const OrderPopover = () => {
};
export const OrderControl = () => {
+ const readonly = useReadonly();
const order = useComputedStyleDecl("order");
const selectedValue = toValue(order.cascadedValue);
const items = [
@@ -93,6 +95,7 @@ export const OrderControl = () => {
properties={["order"]}
/>
<ToggleGroup
+ disabled={readonly}
color={order.source.name}
type="single"
value={selectedValue}
diff --git a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
index 17c619c1e7..5806e6cbce 100644
--- a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
@@ -26,6 +26,7 @@ import { humanizeString } from "~/shared/string-utils";
import { PropertyLabel } from "../../property-label";
import { useComputedStyleDecl } from "../../shared/model";
import { deleteProperty } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
const SizeProperty = ({ property }: { property: CssProperty }) => {
return (
@@ -41,6 +42,7 @@ const SizeProperty = ({ property }: { property: CssProperty }) => {
};
const ObjectPosition = () => {
+ const readonly = useReadonly();
const styleDecl = useComputedStyleDecl("object-position");
return (
<Flex justify="end">
@@ -54,6 +56,7 @@ const ObjectPosition = () => {
}
>
<IconButton
+ disabled={readonly}
variant={styleDecl.source.name}
onClick={(event) => {
if (event.altKey) {
diff --git a/apps/builder/app/builder/features/style-panel/sections/space/layout.tsx b/apps/builder/app/builder/features/style-panel/sections/space/layout.tsx
index 16377b4afd..1eb3bd0fb5 100644
--- a/apps/builder/app/builder/features/style-panel/sections/space/layout.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/space/layout.tsx
@@ -244,6 +244,7 @@ const getPath = (property: SpaceStyleProperty) => {
};
type LayoutProps = {
+ disabled?: boolean;
onFocus?: ComponentProps<"div">["onFocus"];
onBlur?: ComponentProps<"div">["onBlur"];
onKeyDown?: ComponentProps<"div">["onKeyDown"];
@@ -258,6 +259,7 @@ type LayoutProps = {
export const SpaceLayout = forwardRef(
(
{
+ disabled = false,
onFocus,
onBlur,
onKeyDown,
@@ -277,11 +279,14 @@ export const SpaceLayout = forwardRef(
<ValueArea
side={getSide(property)}
d={getPath(property)}
- onMouseEnter={(event) =>
- onHover({ element: event.currentTarget, property })
+ onMouseEnter={
+ disabled
+ ? undefined
+ : (event) => onHover({ element: event.currentTarget, property })
}
- onMouseLeave={() => onHover(undefined)}
+ onMouseLeave={disabled ? undefined : () => onHover(undefined)}
isActive={activeProperties?.includes(property)}
+ css={disabled ? { cursor: "default" } : undefined}
/>
);
@@ -293,7 +298,8 @@ export const SpaceLayout = forwardRef(
onKeyDown={onKeyDown}
onMouseLeave={onMouseLeave}
onMouseMove={onMouseMove}
- tabIndex={0}
+ tabIndex={disabled ? -1 : 0}
+ aria-disabled={disabled}
ref={ref}
>
<svg
diff --git a/apps/builder/app/builder/features/style-panel/sections/space/space.tsx b/apps/builder/app/builder/features/style-panel/sections/space/space.tsx
index 366dd4bd40..41049ce2a9 100644
--- a/apps/builder/app/builder/features/style-panel/sections/space/space.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/space/space.tsx
@@ -14,6 +14,7 @@ import { useKeyboardNavigation } from "../shared/keyboard";
import { useComputedStyleDecl, useComputedStyles } from "../../shared/model";
import { createBatchUpdate, deleteProperty } from "../../shared/use-style-data";
import { useModifierKeys, type Modifiers } from "../../shared/modifier-keys";
+import { useReadonly } from "../../shared/readonly";
const movementMapSpace = {
"margin-top": ["margin-bottom", "margin-right", "padding-top", "margin-left"],
@@ -101,7 +102,7 @@ const Cell = ({
onHover: (target: HoverTarget | undefined) => void;
property: SpaceStyleProperty;
getActiveProperties: (modifiers?: Modifiers) => CssProperty[];
- scrubStatus: ReturnType<typeof useScrub>;
+ scrubStatus: ReturnType<typeof useScrub> & { readonly: boolean };
}) => {
const styleDecl = useComputedStyleDecl(property);
const finalValue =
@@ -113,7 +114,7 @@ const Cell = ({
<InputPopover
styleSource={styleDecl.source.name}
value={finalValue}
- isOpen={isPopoverOpen}
+ isOpen={scrubStatus.readonly ? false : isPopoverOpen}
property={property}
getActiveProperties={getActiveProperties}
onClose={onPopoverClose}
@@ -126,6 +127,9 @@ const Cell = ({
}
onMouseLeave={() => onHover(undefined)}
onClick={(event) => {
+ if (scrubStatus.readonly) {
+ return;
+ }
if (event.altKey) {
deleteProperty(property);
}
@@ -138,6 +142,7 @@ const Cell = ({
export { spaceProperties as properties };
export const Section = () => {
+ const readonly = useReadonly();
const styles = useComputedStyles(spaceProperties);
const [hoverTarget, setHoverTarget] = useState<HoverTarget>();
const styleValue = styles.find(
@@ -145,9 +150,15 @@ export const Section = () => {
);
const scrubStatus = useScrub({
value: styleValue?.usedValue,
- target: styleValue?.cascadedValue.type === "unit" ? hoverTarget : undefined,
+ target:
+ readonly || styleValue?.cascadedValue.type !== "unit"
+ ? undefined
+ : hoverTarget,
getModifiersGroup: getSpaceModifiersGroup,
onChange: (values, options) => {
+ if (readonly) {
+ return;
+ }
const batch = createBatchUpdate();
for (const property of spaceProperties) {
const value = values[property];
@@ -202,6 +213,7 @@ export const Section = () => {
return (
<StyleSection label="Space" properties={spaceProperties}>
<SpaceLayout
+ disabled={readonly}
ref={layoutRef}
onClick={(event) => {
const property = hoverTarget?.property;
@@ -210,6 +222,7 @@ export const Section = () => {
)?.source.name;
if (
+ readonly === false &&
property &&
// reset when the value is set and after try to edit two sides
(styleValueSource === "local" || styleValueSource === "overwritten")
@@ -230,15 +243,20 @@ export const Section = () => {
return;
}
}
+ if (readonly) {
+ return;
+ }
handleOpenProperty(property);
}}
- onHover={handleHover}
- onFocus={keyboardNavigation.handleFocus}
- onBlur={keyboardNavigation.handleBlur}
+ onHover={readonly ? () => undefined : handleHover}
+ onFocus={readonly ? undefined : keyboardNavigation.handleFocus}
+ onBlur={readonly ? undefined : keyboardNavigation.handleBlur}
activeProperties={activeProperties}
- onKeyDown={keyboardNavigation.handleKeyDown}
- onMouseMove={keyboardNavigation.handleMouseMove}
- onMouseLeave={keyboardNavigation.handleMouseLeave}
+ onKeyDown={readonly ? undefined : keyboardNavigation.handleKeyDown}
+ onMouseMove={readonly ? undefined : keyboardNavigation.handleMouseMove}
+ onMouseLeave={
+ readonly ? undefined : keyboardNavigation.handleMouseLeave
+ }
renderCell={({ property }) => (
<Cell
isPopoverOpen={openProperty === property}
@@ -251,7 +269,10 @@ export const Section = () => {
onHover={handleHover}
property={property}
getActiveProperties={getActiveProperties}
- scrubStatus={scrubStatus}
+ scrubStatus={{
+ ...scrubStatus,
+ readonly,
+ }}
/>
)}
/>
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-and-perspective-origin.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-and-perspective-origin.tsx
index 7bbdb1f0cd..9beb94554a 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-and-perspective-origin.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-and-perspective-origin.tsx
@@ -55,8 +55,10 @@ export const calculatePositionFromOrigin = (value: StyleValue | undefined) => {
export const TransformAndPerspectiveOrigin = ({
property,
+ disabled,
}: {
property: CssProperty;
+ disabled?: boolean;
}) => {
const styleDecl = useComputedStyleDecl(property);
const value = styleDecl.cascadedValue;
@@ -164,6 +166,7 @@ export const TransformAndPerspectiveOrigin = ({
<PositionGrid
selectedPosition={{ x: xInfo, y: yInfo }}
onSelect={handlePositionGridChange}
+ disabled={disabled}
/>
<Flex gap="2" direction="column">
<Grid
@@ -183,6 +186,7 @@ export const TransformAndPerspectiveOrigin = ({
}
/>
<CssValueInputContainer
+ disabled={disabled}
value={origin.x}
getOptions={() => xOriginKeywords}
styleSource="local"
@@ -210,6 +214,7 @@ export const TransformAndPerspectiveOrigin = ({
}
/>
<CssValueInputContainer
+ disabled={disabled}
value={origin.y}
getOptions={() => yOriginKeywords}
styleSource="local"
@@ -232,6 +237,7 @@ export const TransformAndPerspectiveOrigin = ({
description={propertySyntaxes.transformOriginZ}
/>
<CssValueInputContainer
+ disabled={disabled}
value={origin.z}
styleSource="local"
property={fakePropertyZ}
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-rotate.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-rotate.tsx
index 63ec167b9e..d5721635b2 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-rotate.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-rotate.tsx
@@ -14,7 +14,7 @@ import {
} from "../../shared/model";
import { updateTransformFunction } from "./transform-utils";
-export const RotatePanelContent = () => {
+export const RotatePanelContent = ({ disabled }: { disabled?: boolean }) => {
const styleDecl = useComputedStyleDecl("transform");
const tuple =
styleDecl.cascadedValue.type === "tuple"
@@ -49,6 +49,7 @@ export const RotatePanelContent = () => {
description={propertySyntaxes.rotateX}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property="rotate"
getOptions={() => $availableUnitVariables.get()}
@@ -69,6 +70,7 @@ export const RotatePanelContent = () => {
description={propertySyntaxes.rotateY}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property="rotate"
getOptions={() => $availableUnitVariables.get()}
@@ -89,6 +91,7 @@ export const RotatePanelContent = () => {
description={propertySyntaxes.rotateZ}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property="rotate"
getOptions={() => $availableUnitVariables.get()}
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-scale.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-scale.tsx
index e670a27742..390d65e8dc 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-scale.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-scale.tsx
@@ -32,7 +32,7 @@ import {
const property: CssProperty = "scale";
-export const ScalePanelContent = () => {
+export const ScalePanelContent = ({ disabled }: { disabled?: boolean }) => {
const styleDecl = useComputedStyleDecl(property);
const tuple =
styleDecl.cascadedValue.type === "tuple"
@@ -98,6 +98,7 @@ export const ScalePanelContent = () => {
description={propertySyntaxes.scaleX}
/>
<CssValueInput
+ disabled={disabled}
styleSource="local"
property={property}
getOptions={() => $availableUnitVariables.get()}
@@ -142,6 +143,7 @@ export const ScalePanelContent = () => {
description={propertySyntaxes.scaleY}
/>
<CssValueInput
+ disabled={disabled}
styleSource="local"
property={property}
getOptions={() => $availableUnitVariables.get()}
@@ -186,6 +188,7 @@ export const ScalePanelContent = () => {
description={propertySyntaxes.scaleZ}
/>
<CssValueInput
+ disabled={disabled}
styleSource="local"
property={property}
getOptions={() => $availableUnitVariables.get()}
@@ -235,6 +238,7 @@ export const ScalePanelContent = () => {
css={{ rotate: "90deg" }}
pressed={isScalingLocked}
onPressedChange={toggleScaling}
+ disabled={disabled}
variant="normal"
icon={isScalingLocked ? <Link2Icon /> : <Link2UnlinkedIcon />}
/>
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-skew.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-skew.tsx
index 6209643b74..1e128bd80a 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-skew.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-skew.tsx
@@ -15,7 +15,7 @@ const fakeProperty = "rotate";
const defaultAngle: StyleValue = { type: "unit", value: 0, unit: "deg" };
-export const SkewPanelContent = () => {
+export const SkewPanelContent = ({ disabled }: { disabled?: boolean }) => {
const styleDecl = useComputedStyleDecl("transform");
const { skewX: skewXFn, skewY: skewYFn } = extractSkewPropertiesFromTransform(
styleDecl.cascadedValue
@@ -36,6 +36,7 @@ export const SkewPanelContent = () => {
description={propertySyntaxes.skewX}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={fakeProperty}
value={skewX}
@@ -55,6 +56,7 @@ export const SkewPanelContent = () => {
description={propertySyntaxes.skewY}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={fakeProperty}
value={skewY}
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-translate.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-translate.tsx
index 7955561e16..cebf0b8128 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-translate.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-translate.tsx
@@ -15,7 +15,7 @@ import {
const property: CssProperty = "translate";
-export const TranslatePanelContent = () => {
+export const TranslatePanelContent = ({ disabled }: { disabled?: boolean }) => {
const styleDecl = useComputedStyleDecl(property);
const tuple =
styleDecl.cascadedValue.type === "tuple"
@@ -59,6 +59,7 @@ export const TranslatePanelContent = () => {
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={property}
getOptions={() => $availableUnitVariables.get()}
@@ -79,6 +80,7 @@ export const TranslatePanelContent = () => {
description={propertySyntaxes.translateY}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={property}
getOptions={() => $availableUnitVariables.get()}
@@ -99,6 +101,7 @@ export const TranslatePanelContent = () => {
description={propertySyntaxes.translateZ}
/>
<CssValueInputContainer
+ disabled={disabled}
styleSource="local"
property={property}
getOptions={() => $availableUnitVariables.get()}
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx
index 5b218d994f..376948213c 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx
@@ -31,6 +31,7 @@ import {
CollapsibleSectionRoot,
useOpenState,
} from "~/builder/shared/collapsible-section";
+import { useReadonly } from "../../shared/readonly";
import { humanizeString } from "~/shared/string-utils";
import { getDots } from "../../shared/style-section";
import {
@@ -76,6 +77,7 @@ const TransformAdvancedButton = forwardRef<
ElementRef<"button">,
ComponentProps<"button">
>((props, ref) => {
+ const readonly = useReadonly();
const styles = useComputedStyles(advancedProperties);
const styleValueSourceColor = getPriorityStyleValueSource(styles);
return (
@@ -84,6 +86,7 @@ const TransformAdvancedButton = forwardRef<
{...props}
ref={ref}
variant={styleValueSourceColor}
+ disabled={readonly}
onClick={(event) => {
if (event.altKey) {
const batch = createBatchUpdate();
@@ -103,30 +106,42 @@ const TransformAdvancedButton = forwardRef<
});
const TransformAdvancedPopover = () => {
+ const readonly = useReadonly();
return (
<FloatingPanel
title="Advanced Transform"
placement="bottom-within"
content={
- <Grid gap="2" css={{ padding: theme.panel.padding }}>
+ <Grid
+ gap="2"
+ css={{
+ padding: theme.panel.padding,
+ }}
+ >
<Grid css={{ gridTemplateColumns: `2fr 1fr` }}>
<PropertyLabel
label="Backface Visibility"
description={propertyDescriptions.backfaceVisibility}
properties={["backface-visibility"]}
/>
- <TextControl property="backface-visibility" />
+ <TextControl property="backface-visibility" disabled={readonly} />
</Grid>
- <TransformAndPerspectiveOrigin property="transform-origin" />
+ <TransformAndPerspectiveOrigin
+ property="transform-origin"
+ disabled={readonly}
+ />
<Grid css={{ gridTemplateColumns: `2fr 1fr` }}>
<PropertyLabel
label="Perspective"
description={propertyDescriptions.perspective}
properties={["perspective"]}
/>
- <TextControl property="perspective" />
+ <TextControl property="perspective" disabled={readonly} />
</Grid>
- <TransformAndPerspectiveOrigin property="perspective-origin" />
+ <TransformAndPerspectiveOrigin
+ property="perspective-origin"
+ disabled={readonly}
+ />
</Grid>
}
>
@@ -137,6 +152,7 @@ const TransformAdvancedPopover = () => {
export const Section = () => {
const [isOpen, setIsOpen] = useOpenState(label);
+ const readonly = useReadonly();
const styles = useComputedStyles(properties);
const isAnyTransformPropertyAdded = transformPanels.some((panel) =>
@@ -164,6 +180,7 @@ export const Section = () => {
<DropdownMenu>
<DropdownMenuTrigger asChild>
<SectionTitleButton
+ disabled={readonly}
prefix={<PlusIcon />}
></SectionTitleButton>
</DropdownMenuTrigger>
@@ -228,6 +245,7 @@ const TransformSection = ({
index: number;
panel: TransformPanel;
}) => {
+ const readonly = useReadonly();
const property = panel === "rotate" || panel === "skew" ? "transform" : panel;
const styleDecl = useComputedStyleDecl(property);
const values = getHumanizedTextFromTransformLayer(
@@ -243,11 +261,18 @@ const TransformSection = ({
<FloatingPanel
title={humanizeString(panel)}
content={
- <Flex direction="column" css={{ padding: theme.panel.padding }}>
- {panel === "translate" && <TranslatePanelContent />}
- {panel === "scale" && <ScalePanelContent />}
- {panel === "rotate" && <RotatePanelContent />}
- {panel === "skew" && <SkewPanelContent />}
+ <Flex
+ direction="column"
+ css={{
+ padding: theme.panel.padding,
+ }}
+ >
+ {panel === "translate" && (
+ <TranslatePanelContent disabled={readonly} />
+ )}
+ {panel === "scale" && <ScalePanelContent disabled={readonly} />}
+ {panel === "rotate" && <RotatePanelContent disabled={readonly} />}
+ {panel === "skew" && <SkewPanelContent disabled={readonly} />}
</Flex>
}
>
@@ -261,6 +286,7 @@ const TransformSection = ({
<SmallToggleButton
variant="normal"
pressed={value.hidden}
+ disabled={readonly}
tabIndex={-1}
onPressedChange={() =>
handleHideTransformProperty({
@@ -272,6 +298,7 @@ const TransformSection = ({
/>
<SmallIconButton
variant="destructive"
+ disabled={readonly}
tabIndex={-1}
icon={<MinusIcon />}
onClick={() =>
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
index 5d9ea0617c..13cd3a7201 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
@@ -33,11 +33,13 @@ import {
editRepeatedStyleItem,
setRepeatedStyleItem,
} from "../../shared/repeated-style";
+import { useReadonly } from "../../shared/readonly";
const getLayer = (value: undefined | StyleValue, index: number) =>
value?.type === "layers" ? value.value[index] : undefined;
export const TransitionContent = ({ index }: { index: number }) => {
+ const readonly = useReadonly();
const styles = useComputedStyles([
"transition-property",
"transition-duration",
@@ -132,6 +134,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
properties={["transition-property"]}
/>
<TransitionProperty
+ disabled={readonly}
value={property ?? propertiesData["transition-property"].initial}
onChange={(value) => {
updateIntermediateValue({ property: value });
@@ -145,6 +148,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
properties={["transition-duration"]}
/>
<CssValueInputContainer
+ disabled={readonly}
property="transition-duration"
styleSource="local"
getOptions={() => $availableUnitVariables.get()}
@@ -170,6 +174,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
properties={["transition-delay"]}
/>
<CssValueInputContainer
+ disabled={readonly}
property="transition-delay"
styleSource="local"
getOptions={() => $availableUnitVariables.get()}
@@ -195,6 +200,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
properties={["transition-timing-function"]}
/>
<CssValueInputContainer
+ disabled={readonly}
property="transition-timing-function"
styleSource="local"
getOptions={() => [
@@ -261,6 +267,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
</Flex>
</Label>
<TextArea
+ disabled={readonly}
rows={3}
name="description"
css={{ minHeight: theme.spacing[14], ...textVariants.mono }}
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
index 8c4d3032c5..733649c8ba 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
@@ -55,6 +55,7 @@ type AnimatableProperties = (typeof animatableProperties)[number];
type NameAndLabel = { name: string; label?: string };
type TransitionPropertyProps = {
value: StyleValue;
+ disabled?: boolean;
onChange: (value: KeywordValue | UnparsedValue) => void;
};
@@ -79,6 +80,7 @@ const $animatableDefinedProperties = computed(
export const TransitionProperty = ({
value,
+ disabled,
onChange,
}: TransitionPropertyProps) => {
const animatableDefinedProperties = useStore($animatableDefinedProperties);
@@ -195,6 +197,7 @@ export const TransitionProperty = ({
<div {...getComboboxProps()}>
<ComboboxAnchor>
<InputField
+ disabled={disabled}
autoFocus
{...getInputProps({
onKeyDown: (event) => {
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
index 6b7f05d735..1bd164829e 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
@@ -16,6 +16,7 @@ import {
useOpenState,
} from "~/builder/shared/collapsible-section";
import { $selectedOrLastStyleSourceSelector } from "~/shared/nano-states";
+import { useReadonly } from "../../shared/readonly";
import { humanizeString } from "~/shared/string-utils";
import { repeatUntil } from "~/shared/array-utils";
import type { ComputedStyleDecl } from "~/shared/style-object-model";
@@ -86,6 +87,7 @@ const getLayerLabel = ({
export const Section = () => {
const [isOpen, setIsOpen] = useOpenState(label);
+ const readonly = useReadonly();
const selectedOrLastStyleSourceSelector = useStore(
$selectedOrLastStyleSourceSelector
@@ -117,7 +119,7 @@ export const Section = () => {
}
>
<SectionTitleButton
- disabled={isStyleInLocalState === false}
+ disabled={readonly || isStyleInLocalState === false}
prefix={<PlusIcon />}
onClick={() => {
setIsOpen(true);
diff --git a/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx b/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
index ac2c1f1957..22b60b6cca 100644
--- a/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
@@ -43,6 +43,7 @@ import {
} from "../../property-label";
import { useComputedStyles } from "../../shared/model";
import { createBatchUpdate } from "../../shared/use-style-data";
+import { useReadonly } from "../../shared/readonly";
const advancedProperties: CssProperty[] = [
"white-space-collapse",
@@ -245,6 +246,7 @@ const AdvancedOptionsButton = forwardRef<
"data-state"?: "open" | "closed";
}
>(({ onClick, ...rest }, ref) => {
+ const readonly = useReadonly();
const styles = useComputedStyles(advancedProperties);
const styleValueSourceColor = getPriorityStyleValueSource(styles);
return (
@@ -252,6 +254,7 @@ const AdvancedOptionsButton = forwardRef<
<EnhancedTooltip content="More typography options">
<IconButton
{...rest}
+ disabled={readonly}
onClick={(event) => {
if (event.altKey) {
const batch = createBatchUpdate();
diff --git a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx
index e714870504..d641a09d15 100644
--- a/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/color-picker.tsx
@@ -20,6 +20,7 @@ type ColorPickerProps = {
getOptions?: () => Array<KeywordValue | VarValue>;
property: CssProperty;
disabled?: boolean;
+ "aria-disabled"?: boolean;
};
export const ColorPickerControl = ({
@@ -28,24 +29,32 @@ export const ColorPickerControl = ({
getOptions,
property,
disabled,
+ ["aria-disabled"]: ariaDisabled,
onChange,
onChangeComplete,
onAbort,
onReset,
}: ColorPickerProps) => {
+ const isDisabled = disabled || ariaDisabled;
+
const [intermediateValue, setIntermediateValue] = useState<
StyleValue | IntermediateStyleValue
>();
return (
<CssValueInput
- aria-disabled={disabled}
+ disabled={isDisabled}
+ aria-disabled={isDisabled}
styleSource="default"
prefix={
<Box css={{ paddingLeft: 2 }}>
<ColorPicker
+ disabled={isDisabled}
value={currentColor}
onChange={(styleValue) => {
+ if (isDisabled) {
+ return;
+ }
setIntermediateValue(styleValue);
if (styleValue) {
onChange(styleValue);
@@ -54,6 +63,9 @@ export const ColorPickerControl = ({
}
}}
onChangeComplete={(value) => {
+ if (isDisabled) {
+ return;
+ }
setIntermediateValue(undefined);
onChangeComplete(value);
}}
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
index 695a512b80..1d829adf41 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -86,6 +86,7 @@ const useScrub = ({
intermediateValue,
defaultUnit,
property,
+ disabled,
onChange,
onChangeComplete,
onAbort,
@@ -95,6 +96,7 @@ const useScrub = ({
value: CssValueInputValue;
intermediateValue: CssValueInputValue | undefined;
property: CssProperty;
+ disabled: boolean | undefined;
onChange: (value: CssValueInputValue | undefined) => void;
onChangeComplete: (value: StyleValue) => void;
onAbort: () => void;
@@ -136,6 +138,10 @@ const useScrub = ({
return;
}
+ if (disabled) {
+ return;
+ }
+
// Don't activate scrub for keyword values
if (valueRef.current.type === "keyword") {
return;
@@ -266,6 +272,7 @@ const useScrub = ({
shouldHandleEvent,
property,
defaultUnit,
+ disabled,
value.type,
// eslint-disable-next-line react-hooks/exhaustive-deps
"unit" in value ? value.unit : undefined,
@@ -550,6 +557,7 @@ export const CssValueInput = ({
options: unitOptions,
property,
value,
+ disabled,
onChange: (unitOrKeyword) => {
if (unitOrKeyword.type === "keyword") {
onChangeComplete({ value: unitOrKeyword, type: "unit-select" });
@@ -642,6 +650,7 @@ export const CssValueInput = ({
defaultUnit,
value,
property,
+ disabled,
intermediateValue: props.intermediateValue,
onChange: props.onChange,
onChangeComplete: (value) => onChangeComplete({ value, type: "scrub-end" }),
@@ -695,7 +704,8 @@ export const CssValueInput = ({
const keywordButtonElement =
value.type === "keyword" && items.length !== 0 ? (
<NestedInputButton
- {...getToggleButtonProps()}
+ {...(disabled ? {} : getToggleButtonProps())}
+ disabled={disabled}
data-state={isOpen ? "open" : "closed"}
tabIndex={-1}
/>
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
index ee1ba89e40..6b03f00970 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
@@ -25,6 +25,7 @@ export type UnitOption =
type UseUnitSelectType = {
property: CssProperty;
value: CssValueInputValue;
+ disabled?: boolean;
onChange: (
value: { type: "unit"; value: Unit } | { type: "keyword"; value: string }
) => void;
@@ -35,6 +36,7 @@ type UseUnitSelectType = {
export const useUnitSelect = ({
property,
value,
+ disabled = false,
onChange,
onCloseAutoFocus,
options: unitOptions,
@@ -69,6 +71,7 @@ export const useUnitSelect = ({
<UnitSelect
value={unitOrKeywordValue}
label={unit ?? nestedSelectButtonUnitless}
+ disabled={disabled}
options={options}
open={isOpen}
onCloseAutoFocus={onCloseAutoFocus}
@@ -91,6 +94,7 @@ type UnitSelectProps = {
options: Array<UnitOption>;
value?: string | undefined;
label?: string | undefined;
+ disabled?: boolean;
onChange: (value: UnitOption) => void;
onOpenChange: (open: boolean) => void;
onCloseAutoFocus: (event: Event) => void;
@@ -101,6 +105,7 @@ const UnitSelect = ({
options,
value,
label,
+ disabled = false,
onChange,
onOpenChange,
onCloseAutoFocus,
@@ -117,10 +122,10 @@ const UnitSelect = ({
onChange(optionValue);
}}
onOpenChange={onOpenChange}
- open={open}
+ open={disabled ? false : open}
>
<SelectPrimitive.SelectTrigger asChild>
- <NestedInputButton tabIndex={-1}>
+ <NestedInputButton tabIndex={-1} disabled={disabled}>
<SelectPrimitive.Value>
{value === "number" ? nestedSelectButtonUnitless : label}
</SelectPrimitive.Value>
diff --git a/apps/builder/app/builder/features/style-panel/shared/filter-content.tsx b/apps/builder/app/builder/features/style-panel/shared/filter-content.tsx
index dd7cbb06a4..712bb0e41c 100644
--- a/apps/builder/app/builder/features/style-panel/shared/filter-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/filter-content.tsx
@@ -24,6 +24,7 @@ import { parseCssValue } from "@webstudio-is/css-data";
import type { StyleUpdateOptions } from "../shared/use-style-data";
import { ShadowContent } from "./shadow-content";
import { parseCssFragment } from "./css-fragment";
+import { useReadonly } from "./readonly";
// filters can't be validated directly in the css-engine. Because, these are not properties
// but functions that proeprties accept. So, we need to validate them manually using fake proeprties
@@ -99,6 +100,7 @@ export const FilterSectionContent = ({
tooltip,
layer,
}: FilterContentProps) => {
+ const readonly = useReadonly();
const [intermediateValue, setIntermediateValue] = useState<
IntermediateStyleValue | InvalidValue | undefined
>();
@@ -182,6 +184,7 @@ export const FilterSectionContent = ({
<Label>Function</Label>
</Flex>
<Select
+ disabled={readonly}
name="filterFunction"
placeholder="Select Filter"
options={Object.keys(filterFunctions) as FilterFunction[]}
@@ -201,6 +204,7 @@ export const FilterSectionContent = ({
<Label>Value</Label>
</Flex>
<CssValueInputContainer
+ disabled={readonly}
key="functionValue"
property={
filterFunction
@@ -254,6 +258,7 @@ export const FilterSectionContent = ({
</Flex>
</Label>
<TextArea
+ disabled={readonly}
rows={3}
name="description"
value={intermediateValue?.value ?? ""}
diff --git a/apps/builder/app/builder/features/style-panel/shared/readonly.tsx b/apps/builder/app/builder/features/style-panel/shared/readonly.tsx
new file mode 100644
index 0000000000..061e29d6ed
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/shared/readonly.tsx
@@ -0,0 +1,7 @@
+import { createContext, useContext } from "react";
+
+const ReadonlyContext = createContext(false);
+
+export const ReadonlyProvider = ReadonlyContext.Provider;
+
+export const useReadonly = () => useContext(ReadonlyContext);
diff --git a/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx b/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx
index d5bcd916d6..4153cc011c 100644
--- a/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/repeated-style.tsx
@@ -23,6 +23,7 @@ import {
} from "@webstudio-is/design-system";
import { repeatUntil } from "~/shared/array-utils";
import type { ComputedStyleDecl } from "~/shared/style-object-model";
+import { useReadonly } from "./readonly";
import { createBatchUpdate, type StyleUpdateOptions } from "./use-style-data";
const isRepeatedValue = (
@@ -384,6 +385,7 @@ export const RepeatedStyle = (props: {
renderItemButtons,
renderPanelTitleSuffix,
} = props;
+ const readonly = useReadonly();
// first property should describe the amount of layers or tuple items
const primaryValue = styles[0].cascadedValue;
let primaryItems: StyleValue[] = [];
@@ -408,8 +410,12 @@ export const RepeatedStyle = (props: {
const { dragItemId, placementIndicator, sortableRefCallback } = useSortable({
items: sortableItems,
- onSort: (newIndex, oldIndex) =>
- swapRepeatedStyleItems(styles, oldIndex, newIndex),
+ onSort: (newIndex, oldIndex) => {
+ if (readonly) {
+ return;
+ }
+ swapRepeatedStyleItems(styles, oldIndex, newIndex);
+ },
});
if (primaryItems.length === 0) {
@@ -430,27 +436,31 @@ export const RepeatedStyle = (props: {
styles[0].cascadedValue.type === "var" ? index === 0 : true;
const customButtons = renderItemButtons?.(index, primaryItem, {
isHidden,
- canBeChanged,
+ canBeChanged: canBeChanged && readonly === false,
});
const panelTitleSuffix = renderPanelTitleSuffix?.(
index,
primaryItem,
{
isHidden,
- canBeChanged,
+ canBeChanged: canBeChanged && readonly === false,
}
);
return (
<FloatingPanel
key={index}
title={label}
- content={renderItemContent(index, primaryItem)}
+ content={
+ <Flex direction="column">
+ {renderItemContent(index, primaryItem)}
+ </Flex>
+ }
titleSuffix={panelTitleSuffix}
offset={floatingPanelOffset}
>
<CssValueListItem
id={id}
- draggable
+ draggable={readonly === false}
active={dragItemId === id}
index={index}
label={<Label truncate>{itemLabel}</Label>}
@@ -465,7 +475,7 @@ export const RepeatedStyle = (props: {
<SmallToggleButton
variant="normal"
pressed={isHidden}
- disabled={false === canBeChanged}
+ disabled={false === canBeChanged || readonly}
tabIndex={-1}
icon={isHidden ? <EyeClosedIcon /> : <EyeOpenIcon />}
onPressedChange={() =>
@@ -474,7 +484,7 @@ export const RepeatedStyle = (props: {
/>
<SmallIconButton
variant="destructive"
- disabled={false === canBeChanged}
+ disabled={false === canBeChanged || readonly}
tabIndex={-1}
icon={<MinusIcon />}
onClick={() => deleteRepeatedStyleItem(styles, index)}
diff --git a/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx b/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx
index 26c71b5ef8..2efaa88f8a 100644
--- a/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx
@@ -43,6 +43,7 @@ import {
} from "./css-fragment";
import { ColorPickerControl } from "./color-picker";
import { $availableColorVariables, $availableUnitVariables } from "./model";
+import { useReadonly } from "./readonly";
/*
When it comes to checking and validating individual CSS properties for the box-shadow,
@@ -156,7 +157,9 @@ export const ShadowContent = ({
const computedShadow =
computedLayer?.type === "shadow" ? computedLayer : shadowValue;
- const disabledControls = layer.type === "var" || layer.type === "unparsed";
+ const readonly = useReadonly();
+ const disabledControls =
+ readonly || layer.type === "var" || layer.type === "unparsed";
const handleChange = (value: string) => {
setIntermediateValue({
@@ -230,7 +233,7 @@ export const ShadowContent = ({
// outline-offset is a fake property for validating box-shadow's offsetX.
property="outline-offset"
styleSource="local"
- aria-disabled={disabledControls}
+ disabled={disabledControls}
getOptions={() => $availableUnitVariables.get()}
value={shadowValue.offsetX}
onUpdate={(value, options) => {
@@ -254,7 +257,7 @@ export const ShadowContent = ({
// outline-offset is a fake property for validating box-shadow's offsetY.
property="outline-offset"
styleSource="local"
- aria-disabled={disabledControls}
+ disabled={disabledControls}
getOptions={() => $availableUnitVariables.get()}
value={shadowValue.offsetY}
onUpdate={(value, options) => {
@@ -278,7 +281,7 @@ export const ShadowContent = ({
// border-top-width is a fake property for validating box-shadow's blur.
property="border-top-width"
styleSource="local"
- aria-disabled={disabledControls}
+ disabled={disabledControls}
getOptions={() => $availableUnitVariables.get()}
value={shadowValue.blur ?? { type: "unit", value: 0, unit: "px" }}
onUpdate={(value, options) => {
@@ -303,7 +306,7 @@ export const ShadowContent = ({
// outline-offset is a fake property for validating box-shadow's spread.
property="outline-offset"
styleSource="local"
- aria-disabled={disabledControls}
+ disabled={disabledControls}
getOptions={() => $availableUnitVariables.get()}
value={
shadowValue.spread ?? { type: "unit", value: 0, unit: "px" }
@@ -335,7 +338,7 @@ export const ShadowContent = ({
/>
<ColorPickerControl
property="color"
- aria-disabled={disabledControls}
+ disabled={disabledControls}
value={shadowValue.color ?? defaultColor}
currentColor={computedShadow?.color ?? defaultColor}
getOptions={() => [
@@ -376,7 +379,7 @@ export const ShadowContent = ({
/>
<ToggleGroup
type="single"
- aria-disabled={disabledControls}
+ disabled={disabledControls}
value={shadowValue.position}
defaultValue="inset"
onValueChange={(value) =>
@@ -432,6 +435,7 @@ export const ShadowContent = ({
<CssFragmentEditor
content={
<CssFragmentEditorContent
+ readOnly={readonly}
invalid={intermediateValue?.type === "invalid"}
autoFocus={disabledControls}
value={intermediateValue?.value ?? propertyValue ?? ""}
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-section.tsx b/apps/builder/app/builder/features/style-panel/shared/style-section.tsx
index c9c5809cc4..f6b7621f68 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-section.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/style-section.tsx
@@ -10,6 +10,7 @@ import {
CollapsibleSectionRoot,
useOpenState,
} from "~/builder/shared/collapsible-section";
+import { useReadonly } from "./readonly";
import { useComputedStyles } from "./model";
import type { ComputedStyleDecl } from "~/shared/style-object-model";
import { PropertySectionLabel } from "../property-label";
@@ -71,6 +72,7 @@ export const RepeatedStyleSection = (props: {
const { label, description, children, properties, onAdd, collapsible } =
props;
const [isOpen, setIsOpen] = useOpenState(label);
+ const readonly = useReadonly();
const styles = useComputedStyles(properties);
const dots = getDots(styles);
@@ -87,6 +89,7 @@ export const RepeatedStyleSection = (props: {
dots={getDots(styles)}
suffix={
<SectionTitleButton
+ disabled={readonly}
prefix={<PlusIcon />}
onClick={() => {
setIsOpen(true);
diff --git a/apps/builder/app/builder/features/style-panel/shared/use-style-data.test.ts b/apps/builder/app/builder/features/style-panel/shared/use-style-data.test.ts
new file mode 100644
index 0000000000..b9c021fd37
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/shared/use-style-data.test.ts
@@ -0,0 +1,111 @@
+import { enableMapSet } from "immer";
+import { describe, expect, test } from "vitest";
+import { registerContainers } from "~/shared/sync/sync-stores";
+import {
+ $breakpoints,
+ $instances,
+ $selectedBreakpointId,
+ $selectedStyleSources,
+ $styleSourceSelections,
+ $styleSources,
+ $styles,
+} from "~/shared/nano-states";
+import { $awareness } from "~/shared/awareness";
+import { deleteProperty, setProperty } from "./use-style-data";
+import { getStyleDeclKey, type StyleDecl } from "@webstudio-is/sdk";
+
+enableMapSet();
+registerContainers();
+
+const setupSelection = (styleSource: {
+ id: string;
+ type: "token";
+ name: string;
+ locked?: true;
+}) => {
+ $instances.set(
+ new Map([
+ [
+ "body",
+ { type: "instance", id: "body", component: "Body", children: [] },
+ ],
+ ])
+ );
+ $awareness.set({
+ pageId: "",
+ instanceSelector: ["body"],
+ });
+ $breakpoints.set(new Map([["base", { id: "base", label: "Base" }]]));
+ $selectedBreakpointId.set("base");
+ $styleSources.set(new Map([[styleSource.id, styleSource]]));
+ $styleSourceSelections.set(
+ new Map([
+ [
+ "body",
+ {
+ instanceId: "body",
+ values: [styleSource.id],
+ },
+ ],
+ ])
+ );
+ $selectedStyleSources.set(new Map([["body", styleSource.id]]));
+ $styles.set(new Map());
+};
+
+describe("use-style-data", () => {
+ test("does not write styles for locked tokens", () => {
+ setupSelection({
+ id: "token1",
+ type: "token",
+ name: "Primary",
+ locked: true,
+ });
+
+ setProperty("color")({ type: "keyword", value: "red" });
+
+ expect($styles.get().size).toBe(0);
+ });
+
+ test("does not delete styles for locked tokens", () => {
+ setupSelection({
+ id: "token1",
+ type: "token",
+ name: "Primary",
+ locked: true,
+ });
+
+ const styleDecl: StyleDecl = {
+ breakpointId: "base",
+ styleSourceId: "token1",
+ property: "color",
+ value: { type: "keyword", value: "red" },
+ };
+ $styles.set(new Map([[getStyleDeclKey(styleDecl), styleDecl]]));
+
+ deleteProperty("color");
+
+ expect(Array.from($styles.get().values())).toEqual([styleDecl]);
+ });
+
+ test("writes styles for unlocked tokens", () => {
+ setupSelection({
+ id: "token1",
+ type: "token",
+ name: "Primary",
+ });
+
+ setProperty("color")({ type: "keyword", value: "red" });
+
+ expect(Array.from($styles.get().values())).toEqual([
+ {
+ breakpointId: "base",
+ styleSourceId: "token1",
+ property: "color",
+ value: { type: "keyword", value: "red" },
+ listed: undefined,
+ state: undefined,
+ },
+ ]);
+ });
+});
diff --git a/apps/builder/app/builder/features/style-panel/shared/use-style-data.ts b/apps/builder/app/builder/features/style-panel/shared/use-style-data.ts
index b2c1a09398..de4f545410 100644
--- a/apps/builder/app/builder/features/style-panel/shared/use-style-data.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/use-style-data.ts
@@ -12,6 +12,7 @@ import {
import { serverSyncStore } from "~/shared/sync/sync-stores";
import { $ephemeralStyles } from "~/canvas/stores";
import { $selectedInstance } from "~/shared/awareness";
+import { isStyleSourceLocked } from "~/shared/style-source-utils";
type StyleUpdate =
| {
@@ -67,6 +68,13 @@ const publishUpdates = (
return;
}
+ if (isStyleSourceLocked(selectedStyleSource)) {
+ if (type === "preview") {
+ $ephemeralStyles.set([]);
+ }
+ return;
+ }
+
if (type === "preview") {
const ephemeralStyles: ReturnType<typeof $ephemeralStyles.get> = [];
for (const update of updates) {
diff --git a/apps/builder/app/builder/features/style-panel/style-panel.tsx b/apps/builder/app/builder/features/style-panel/style-panel.tsx
index 7ec7b05e41..0d7dbe316f 100644
--- a/apps/builder/app/builder/features/style-panel/style-panel.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-panel.tsx
@@ -23,7 +23,12 @@ import {
} from "@webstudio-is/design-system";
import { toValue } from "@webstudio-is/css-engine";
import { EllipsesIcon } from "@webstudio-is/icons";
-import { $selectedInstanceRenderState } from "~/shared/nano-states";
+import {
+ $selectedInstanceRenderState,
+ $selectedStyleSource,
+} from "~/shared/nano-states";
+import { isStyleSourceLocked } from "~/shared/style-source-utils";
+import { ReadonlyProvider } from "./shared/readonly";
import { $selectedInstance } from "~/shared/awareness";
import { CollapsibleProvider } from "~/builder/shared/collapsible-section";
import {
@@ -122,6 +127,7 @@ export const ModeMenu = () => {
export const StylePanel = () => {
const { stylePanelMode } = useStore($settings);
const selectedInstanceRenderState = useStore($selectedInstanceRenderState);
+ const readonly = isStyleSourceLocked(useStore($selectedStyleSource));
const tag = useStore($selectedInstanceTag);
const display = toValue(useComputedStyleDecl("display").computedValue);
const parentDisplay = toValue(
@@ -179,7 +185,7 @@ export const StylePanel = () => {
}
return (
- <>
+ <ReadonlyProvider value={readonly}>
<Box css={{ padding: theme.panel.padding }}>
<Text variant="titles" css={{ paddingBlock: theme.panel.paddingBlock }}>
Style sources
@@ -195,6 +201,6 @@ export const StylePanel = () => {
{all}
</CollapsibleProvider>
</ScrollArea>
- </>
+ </ReadonlyProvider>
);
};
diff --git a/apps/builder/app/builder/features/style-panel/style-source-section.test.ts b/apps/builder/app/builder/features/style-panel/style-source-section.test.ts
index 6081339794..f0b59452bf 100644
--- a/apps/builder/app/builder/features/style-panel/style-source-section.test.ts
+++ b/apps/builder/app/builder/features/style-panel/style-source-section.test.ts
@@ -6,11 +6,12 @@ import {
$selectedStyleSources,
$styleSourceSelections,
$styleSources,
+ $styles,
} from "~/shared/nano-states";
import { addStyleSourceToInstance, __testing__ } from "./style-source-section";
import { $awareness } from "~/shared/awareness";
-const { getComponentStates } = __testing__;
+const { duplicateStyleSource, getComponentStates } = __testing__;
enableMapSet();
registerContainers();
@@ -182,3 +183,41 @@ test("add style source to instance", () => {
values: ["token1", "token2", "local1"],
});
});
+
+test("duplicate locked style source creates an unlocked copy", () => {
+ $instances.set(
+ new Map([
+ [
+ "body",
+ { type: "instance", id: "body", component: "Body", children: [] },
+ ],
+ ])
+ );
+ $awareness.set({
+ pageId: "",
+ instanceSelector: ["body"],
+ });
+ $styleSources.set(
+ new Map([
+ [
+ "token1",
+ { id: "token1", type: "token", name: "Primary", locked: true },
+ ],
+ ])
+ );
+ $styleSourceSelections.set(
+ new Map([["body", { instanceId: "body", values: ["token1"] }]])
+ );
+ $selectedStyleSources.set(new Map([["body", "token1"]]));
+ $styles.set(new Map());
+
+ const duplicatedId = duplicateStyleSource("token1");
+
+ expect(duplicatedId).toBeDefined();
+ const duplicatedStyleSource = $styleSources.get().get(duplicatedId!);
+ expect(duplicatedStyleSource).toEqual({
+ id: duplicatedId,
+ type: "token",
+ name: "Primary (copy)",
+ });
+});
diff --git a/apps/builder/app/builder/features/style-panel/style-source-section.tsx b/apps/builder/app/builder/features/style-panel/style-source-section.tsx
index ce8c383428..9a3596d21b 100644
--- a/apps/builder/app/builder/features/style-panel/style-source-section.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source-section.tsx
@@ -19,6 +19,7 @@ import {
type RenameStyleSourceError,
deleteStyleSource,
DeleteStyleSourceDialog,
+ setStyleSourceLocked,
} from "~/builder/shared/style-source-actions";
import {
$registeredComponentMetas,
@@ -387,6 +388,7 @@ type StyleSourceInputItem = {
label: string;
disabled: boolean;
source: ItemSource;
+ locked: boolean;
states: string[];
};
@@ -399,6 +401,7 @@ const convertToInputItem = (
label: styleSource.type === "local" ? "Local" : styleSource.name,
disabled: false,
source: styleSource.type,
+ locked: styleSource.type === "token" && styleSource.locked === true,
states,
};
};
@@ -490,6 +493,9 @@ export const StyleSourcesSection = () => {
setTokenToDelete(token);
}
}}
+ onToggleLockItem={(id, locked) => {
+ setStyleSourceLocked(id, locked);
+ }}
onSort={(items) => {
reorderStyleSources(items.map((item) => item.id));
}}
@@ -532,4 +538,4 @@ export const StyleSourcesSection = () => {
);
};
-export const __testing__ = { getComponentStates };
+export const __testing__ = { duplicateStyleSource, getComponentStates };
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx
index df0868b28d..7b0e8d87e9 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-control.tsx
@@ -6,6 +6,7 @@ import {
Flex,
Tooltip,
} from "@webstudio-is/design-system";
+import { LockIcon } from "@webstudio-is/icons";
import type { StyleSource } from "@webstudio-is/sdk";
import { type ReactNode } from "react";
import { useContentEditable } from "~/shared/dom-hooks";
@@ -217,6 +218,7 @@ type StyleSourceControlProps = {
isDragging: boolean;
hasStyles: boolean;
source: ItemSource;
+ locked: boolean;
onSelect: () => void;
onChangeValue: (value: string) => void;
onChangeEditing: (isEditing: boolean) => void;
@@ -235,6 +237,7 @@ export const StyleSourceControl = ({
isDragging,
hasStyles,
source,
+ locked,
label,
onChangeValue,
onChangeEditing,
@@ -288,6 +291,7 @@ export const StyleSourceControl = ({
onChangeValue={onChangeValue}
value={label}
/>
+ {locked && isEditing === false && <LockIcon size={12} />}
{hasStyles === false && isEditing === false && (
<LocalStyleIcon showDot={hasStyles} />
)}
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx
index 972478c3ea..0f71b8c56d 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx
@@ -17,6 +17,7 @@ type Item = {
label: string;
source: ItemSource;
disabled: boolean;
+ locked: boolean;
states: string[];
};
@@ -25,6 +26,7 @@ const localItem: Item = {
label: "Local",
source: "local",
disabled: false,
+ locked: false,
states: [],
};
@@ -34,6 +36,7 @@ const getItems = (): Array<Item> => [
label: "Token",
source: "token",
disabled: false,
+ locked: false,
states: [],
},
{
@@ -41,6 +44,7 @@ const getItems = (): Array<Item> => [
label: "Tag",
source: "tag",
disabled: false,
+ locked: false,
states: [],
},
];
@@ -55,6 +59,7 @@ const createItem = (
label,
source: "token",
disabled: false,
+ locked: false,
states: [],
};
setValue([...value, item]);
@@ -77,6 +82,7 @@ export const StyleSourceInput = () => {
label: "Disabled",
source: "token",
disabled: true,
+ locked: false,
states: [],
},
]);
@@ -93,6 +99,7 @@ export const StyleSourceInput = () => {
"Local Something Something Something Something Something Something Something",
source: "token",
disabled: false,
+ locked: false,
states: [],
},
]);
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
index 9aa9802f0a..d2d3f05a38 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
@@ -62,6 +62,7 @@ type IntermediateItem = {
label: string;
disabled: boolean;
source: ItemSource;
+ locked: boolean;
isAdded?: boolean;
states: string[];
};
@@ -278,6 +279,7 @@ const TextFieldBase: ForwardRefRenderFunction<
isEditing={item.id === editingItemId}
hasStyles={hasStyles(item.id)}
source={item.source}
+ locked={item.locked}
onChangeEditing={(isEditing) => {
onEditItem?.(isEditing ? item.id : undefined);
}}
@@ -309,6 +311,7 @@ type StyleSourceInputProps<Item extends IntermediateItem> = {
onDeleteItem?: (id: Item["id"]) => void;
onClearStyles?: (id: Item["id"]) => void;
onDuplicateItem?: (id: Item["id"]) => void;
+ onToggleLockItem?: (id: Item["id"], locked: boolean) => void;
onConvertToToken?: (id: Item["id"]) => void;
onCreateItem?: (id: Item["id"], label: string) => void;
onChangeItem?: (item: Item) => void;
@@ -347,6 +350,7 @@ const matchOrSuggestToCreate = (
label: search.trim(),
disabled: false,
source: "token",
+ locked: false,
isAdded: false,
states: [],
});
@@ -388,6 +392,7 @@ export const StyleSourceInput = (
disabled: false,
id: "",
source: "local",
+ locked: false,
states: [],
},
selectedItem: undefined,
@@ -451,6 +456,7 @@ export const StyleSourceInput = (
}}
onSelect={props.onSelectItem}
onDuplicate={props.onDuplicateItem}
+ onToggleLock={props.onToggleLockItem}
onConvertToToken={props.onConvertToToken}
onEnable={props.onEnableItem}
onDisable={props.onDisableItem}
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.test.ts b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.test.ts
new file mode 100644
index 0000000000..a0afab2f54
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.test.ts
@@ -0,0 +1,43 @@
+import { describe, expect, test } from "vitest";
+import { __testing__ } from "./style-source-menu";
+
+const { canEditStyleSourceStyles } = __testing__;
+
+describe("canEditStyleSourceStyles", () => {
+ test("allows style editing for local and unlocked token sources", () => {
+ expect(
+ canEditStyleSourceStyles({
+ id: "local",
+ label: "Local",
+ disabled: false,
+ source: "local",
+ locked: false,
+ states: [],
+ })
+ ).toBe(true);
+
+ expect(
+ canEditStyleSourceStyles({
+ id: "token",
+ label: "Token",
+ disabled: false,
+ source: "token",
+ locked: false,
+ states: [],
+ })
+ ).toBe(true);
+ });
+
+ test("hides style editing options for locked tokens", () => {
+ expect(
+ canEditStyleSourceStyles({
+ id: "token",
+ label: "Token",
+ disabled: false,
+ source: "token",
+ locked: true,
+ states: [],
+ })
+ ).toBe(false);
+ });
+});
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
index f81c2b8077..a2bfca3e06 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-menu.tsx
@@ -40,6 +40,7 @@ type IntermediateItem = {
label: string;
disabled: boolean;
source: ItemSource;
+ locked: boolean;
isAdded?: boolean;
states: string[];
};
@@ -113,12 +114,17 @@ const menuActionDescriptions = {
convertToToken:
"Turn local styles into a reusable token you can apply to other elements.",
clearStyles: "Remove all styles from this local style source.",
+ lock: "Protect this token from accidental style changes until you unlock it.",
+ unlock: "Allow style changes on this token again.",
detach: "Remove this token from the element without deleting it.",
delete: "Permanently delete this token and all its styles from the project.",
} as const;
type MenuAction = keyof typeof menuActionDescriptions;
+const canEditStyleSourceStyles = (item: IntermediateItem) =>
+ item.source === "local" || item.locked === false;
+
// All available CSS selectors for autocomplete
const allSelectors = [
...Object.keys(pseudoClassDescriptions),
@@ -233,6 +239,7 @@ type StyleSourceMenuProps = {
onSelect?: (itemSelector: ItemSelector) => void;
onEdit?: (itemId: IntermediateItem["id"]) => void;
onDuplicate?: (itemId: IntermediateItem["id"]) => void;
+ onToggleLock?: (itemId: IntermediateItem["id"], locked: boolean) => void;
onConvertToToken?: (itemId: IntermediateItem["id"]) => void;
onDisable?: (itemId: IntermediateItem["id"]) => void;
onEnable?: (itemId: IntermediateItem["id"]) => void;
@@ -248,6 +255,7 @@ export const StyleSourceMenu = (props: StyleSourceMenuProps) => {
description?: string;
}>();
const [highlightedAction, setHighlightedAction] = useState<MenuAction>();
+ const canEditStyles = canEditStyleSourceStyles(props.item);
// Get description for highlighted or selected item
const selectedState = props.selectedItemSelector?.state;
@@ -330,6 +338,19 @@ export const StyleSourceMenu = (props: StyleSourceMenuProps) => {
Duplicate
</DropdownMenuItem>
)}
+ {props.item.source === "token" && (
+ <DropdownMenuItem
+ onFocus={() => {
+ setHighlightedSelector(undefined);
+ setHighlightedAction(props.item.locked ? "unlock" : "lock");
+ }}
+ onSelect={() =>
+ props.onToggleLock?.(props.item.id, props.item.locked === false)
+ }
+ >
+ {props.item.locked ? "Unlock" : "Lock"}
+ </DropdownMenuItem>
+ )}
{props.item.source === "local" && (
<DropdownMenuItem
onFocus={() => {
@@ -376,98 +397,105 @@ export const StyleSourceMenu = (props: StyleSourceMenuProps) => {
Delete
</DropdownMenuItem>
)}
- {selectorLabels.map((currentCategory) => {
- const categoryStates = props.states.filter(
- ({ type }) => type === currentCategory
- );
- if (categoryStates.length === 0) {
- return;
- }
- return (
- <Fragment key={currentCategory}>
- <DropdownMenuSeparator />
- <DropdownMenuLabel>
- {categoryLabels[currentCategory]}
- </DropdownMenuLabel>
- {categoryStates.map(
- ({ label, selector, source, type, description }, index) => {
- const previousItem = categoryStates[index - 1];
- const showSeparator =
- index > 0 &&
- ((source === "component" &&
- previousItem?.source !== "component") ||
- (source === "custom" &&
- previousItem?.source !== "custom"));
+ {canEditStyles &&
+ selectorLabels.map((currentCategory) => {
+ const categoryStates = props.states.filter(
+ ({ type }) => type === currentCategory
+ );
+ if (categoryStates.length === 0) {
+ return;
+ }
+ return (
+ <Fragment key={currentCategory}>
+ <DropdownMenuSeparator />
+ <DropdownMenuLabel>
+ {categoryLabels[currentCategory]}
+ </DropdownMenuLabel>
+ {categoryStates.map(
+ ({ label, selector, source, type, description }, index) => {
+ const previousItem = categoryStates[index - 1];
+ const showSeparator =
+ index > 0 &&
+ ((source === "component" &&
+ previousItem?.source !== "component") ||
+ (source === "custom" &&
+ previousItem?.source !== "custom"));
- return (
- <Fragment key={selector}>
- {showSeparator && <DropdownMenuSeparator />}
- <DropdownMenuItem
- withIndicator={true}
- onFocus={() => {
- setHighlightedAction(undefined);
- setHighlightedSelector({
- selector,
- type,
- description,
- });
- }}
- icon={
- props.item.id ===
- props.selectedItemSelector?.styleSourceId &&
- selector === props.selectedItemSelector.state && (
- <CheckMarkIcon
- color={
- props.item.states.includes(selector)
- ? rawTheme.colors.foregroundPrimary
- : rawTheme.colors.foregroundIconMain
- }
- size={12}
- />
- )
- }
- onSelect={() =>
- props.onSelect?.({
- styleSourceId: props.item.id,
- state:
- props.selectedItemSelector?.state === selector
- ? undefined
- : selector,
- })
- }
- >
- <Flex justify="between" align="center" grow>
- <Text variant="labels" truncate>
- {label}
- </Text>
- {props.item.states.includes(selector) && (
- <DotIcon
- size="12"
- color={rawTheme.colors.foregroundPrimary}
- />
- )}
- </Flex>
- </DropdownMenuItem>
- </Fragment>
- );
+ return (
+ <Fragment key={selector}>
+ {showSeparator && <DropdownMenuSeparator />}
+ <DropdownMenuItem
+ withIndicator={true}
+ onFocus={() => {
+ setHighlightedAction(undefined);
+ setHighlightedSelector({
+ selector,
+ type,
+ description,
+ });
+ }}
+ icon={
+ props.item.id ===
+ props.selectedItemSelector?.styleSourceId &&
+ selector === props.selectedItemSelector.state && (
+ <CheckMarkIcon
+ color={
+ props.item.states.includes(selector)
+ ? rawTheme.colors.foregroundPrimary
+ : rawTheme.colors.foregroundIconMain
+ }
+ size={12}
+ />
+ )
+ }
+ onSelect={() =>
+ props.onSelect?.({
+ styleSourceId: props.item.id,
+ state:
+ props.selectedItemSelector?.state === selector
+ ? undefined
+ : selector,
+ })
+ }
+ >
+ <Flex justify="between" align="center" grow>
+ <Text variant="labels" truncate>
+ {label}
+ </Text>
+ {props.item.states.includes(selector) && (
+ <DotIcon
+ size="12"
+ color={rawTheme.colors.foregroundPrimary}
+ />
+ )}
+ </Flex>
+ </DropdownMenuItem>
+ </Fragment>
+ );
+ }
+ )}
+ </Fragment>
+ );
+ })}
+ {canEditStyles && (
+ <>
+ <DropdownMenuSeparator />
+ <DropdownMenuLabel>Add more</DropdownMenuLabel>
+ <Box css={{ padding: theme.spacing[4] }}>
+ <SelectorCombobox
+ existingSelectors={props.states.map((state) => state.selector)}
+ onSelect={(selector) =>
+ props.onAddSelector?.(props.item.id, selector)
}
- )}
- </Fragment>
- );
- })}
- <DropdownMenuSeparator />
- <DropdownMenuLabel>Add more</DropdownMenuLabel>
- <Box css={{ padding: theme.spacing[4] }}>
- <SelectorCombobox
- existingSelectors={props.states.map((state) => state.selector)}
- onSelect={(selector) =>
- props.onAddSelector?.(props.item.id, selector)
- }
- />
- </Box>
+ />
+ </Box>
+ </>
+ )}
<DropdownMenuSeparator />
<DropdownMenuItem hint>{description}</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
};
+
+export const __testing__ = { canEditStyleSourceStyles };
diff --git a/apps/builder/app/builder/shared/css-editor/css-editor.tsx b/apps/builder/app/builder/shared/css-editor/css-editor.tsx
index 1328b3f77a..92d06fa4db 100644
--- a/apps/builder/app/builder/shared/css-editor/css-editor.tsx
+++ b/apps/builder/app/builder/shared/css-editor/css-editor.tsx
@@ -120,6 +120,7 @@ const AdvancedPropertyLabel = ({
const AdvancedPropertyValue = ({
styleDecl,
+ readonly = false,
onDeleteProperty,
onSetProperty,
onChangeComplete,
@@ -127,6 +128,7 @@ const AdvancedPropertyValue = ({
inputRef: inputRefProp,
}: {
styleDecl: ComputedStyleDecl;
+ readonly?: boolean;
onDeleteProperty: DeleteProperty;
onSetProperty: SetProperty;
onChangeComplete: ComponentProps<
@@ -150,9 +152,11 @@ const AdvancedPropertyValue = ({
variant="chromeless"
text="mono"
fieldSizing="content"
+ disabled={readonly}
prefix={
isColor && (
<ColorPicker
+ disabled={readonly}
value={styleDecl.usedValue}
onChange={(styleValue) => {
const options = { isEphemeral: true, listed: true };
@@ -262,6 +266,7 @@ const LazyRender = ({ children }: ComponentProps<"div">) => {
const AdvancedDeclarationLonghand = memo(
({
styleDecl,
+ readonly = false,
onChangeComplete,
onDeleteProperty,
onSetProperty,
@@ -270,6 +275,7 @@ const AdvancedDeclarationLonghand = memo(
indentation = initialIndentation,
}: {
styleDecl: ComputedStyleDecl;
+ readonly?: boolean;
indentation?: string;
onReset?: () => void;
onSetProperty: SetProperty;
@@ -304,6 +310,7 @@ const AdvancedDeclarationLonghand = memo(
</Text>
<AdvancedPropertyValue
styleDecl={styleDecl}
+ readonly={readonly}
onChangeComplete={onChangeComplete}
onReset={onReset}
onDeleteProperty={onDeleteProperty}
@@ -321,6 +328,7 @@ export const CssEditor = ({
onAddDeclarations,
onDeleteAllDeclarations,
declarations,
+ readonly = false,
showSearch = true,
virtualize = true,
propertiesPosition = "bottom",
@@ -333,6 +341,7 @@ export const CssEditor = ({
onSetProperty: SetProperty;
onAddDeclarations: (styleMap: CssStyleMap) => void;
onDeleteAllDeclarations: (styleMap: CssStyleMap) => void;
+ readonly?: boolean;
showSearch?: boolean;
propertiesPosition?: "top" | "bottom";
virtualize?: boolean;
@@ -348,11 +357,19 @@ export const CssEditor = ({
useState<Array<CssProperty>>();
const containerRef = useRef<HTMLDivElement>(null);
+ const effectiveShowAddStyleInput = readonly ? false : showAddStyleInput;
+ const guardedSetProperty: SetProperty = readonly
+ ? () => () => undefined
+ : onSetProperty;
+ const guardedToggleAddStyleInput = readonly
+ ? undefined
+ : onToggleAddStyleInput;
+
useEffect(() => {
- if (showAddStyleInput) {
+ if (effectiveShowAddStyleInput) {
addPropertyInputRef.current?.focus();
}
- }, [showAddStyleInput]);
+ }, [effectiveShowAddStyleInput]);
const declarationsMap = new Map(
declarations.map((decl) => [decl.property, decl])
@@ -370,6 +387,9 @@ export const CssEditor = ({
recentProperties.length > 0 && searchProperties === undefined;
const handleInsertStyles = (cssText: string) => {
+ if (readonly) {
+ return new Map();
+ }
const { styleMap, errors } = parseStyleInput(cssText, $cssVarsMap.get());
for (const error of errors) {
toast.error(error);
@@ -423,7 +443,7 @@ export const CssEditor = ({
};
const afterChangingStyles = () => {
- onToggleAddStyleInput?.(false);
+ guardedToggleAddStyleInput?.(false);
requestAnimationFrame(() => {
// We are either focusing the last value input from the recent list if available or the search input.
const element =
@@ -437,6 +457,9 @@ export const CssEditor = ({
};
const handleDeleteProperty: DeleteProperty = (property, options = {}) => {
+ if (readonly) {
+ return;
+ }
onDeleteProperty(property, options);
if (options.isEphemeral === true) {
return;
@@ -447,6 +470,9 @@ export const CssEditor = ({
};
const handleDeleteAllDeclarations = (styleMap: CssStyleMap) => {
+ if (readonly) {
+ return;
+ }
setSearchProperties(
searchProperties?.filter(
(searchProperty) => styleMap.has(searchProperty) === false
@@ -469,22 +495,23 @@ export const CssEditor = ({
return (
<AdvancedDeclarationLonghand
styleDecl={styleDecl}
+ readonly={readonly}
key={property}
valueInputRef={lastRecentValueInputRef}
onChangeComplete={(event) => {
if (event.type === "enter") {
- onToggleAddStyleInput?.(true);
+ guardedToggleAddStyleInput?.(true);
}
}}
onReset={afterChangingStyles}
onDeleteProperty={handleDeleteProperty}
- onSetProperty={onSetProperty}
+ onSetProperty={guardedSetProperty}
/>
);
})}
<Box
css={
- showAddStyleInput
+ effectiveShowAddStyleInput
? { paddingTop: theme.spacing[3] }
: // We hide it visually so you can tab into it to get shown.
{ overflow: "hidden", height: 0 }
@@ -499,10 +526,10 @@ export const CssEditor = ({
}}
onClose={afterChangingStyles}
onFocus={() => {
- onToggleAddStyleInput?.(true);
+ guardedToggleAddStyleInput?.(true);
}}
onBlur={() => {
- onToggleAddStyleInput?.(false);
+ guardedToggleAddStyleInput?.(false);
}}
ref={addPropertyInputRef}
/>
@@ -562,8 +589,9 @@ export const CssEditor = ({
const declarationElement = (
<AdvancedDeclarationLonghand
styleDecl={styleDecl}
+ readonly={readonly}
onDeleteProperty={handleDeleteProperty}
- onSetProperty={onSetProperty}
+ onSetProperty={guardedSetProperty}
valueInputRef={lastRegularValueInputRef}
key={property}
/>
diff --git a/apps/builder/app/builder/shared/style-source-actions.tsx b/apps/builder/app/builder/shared/style-source-actions.tsx
index 0864ff00b3..9a39a830d1 100644
--- a/apps/builder/app/builder/shared/style-source-actions.tsx
+++ b/apps/builder/app/builder/shared/style-source-actions.tsx
@@ -28,6 +28,7 @@ import {
deleteStyleSourcesMutable,
validateAndRenameStyleSource,
renameStyleSourceMutable,
+ toggleStyleSourceLockMutable,
type RenameStyleSourceError,
} from "~/shared/style-source-utils";
import { serverSyncStore } from "~/shared/sync/sync-stores";
@@ -131,6 +132,15 @@ export const renameStyleSource = (
});
};
+export const setStyleSourceLocked = (
+ id: StyleSource["id"],
+ locked: boolean
+) => {
+ serverSyncStore.createTransaction([$styleSources], (styleSources) => {
+ toggleStyleSourceLockMutable({ id, locked, styleSources });
+ });
+};
+
type DeleteStyleSourceDialogProps = {
styleSource?: { id: StyleSource["id"]; name: string };
onClose: () => void;
diff --git a/apps/builder/app/shared/style-source-utils.test.tsx b/apps/builder/app/shared/style-source-utils.test.tsx
index 20f9bfe3a9..18b78a77f0 100644
--- a/apps/builder/app/shared/style-source-utils.test.tsx
+++ b/apps/builder/app/shared/style-source-utils.test.tsx
@@ -20,6 +20,8 @@ import {
deleteStyleSourcesMutable,
validateAndRenameStyleSource,
renameStyleSourceMutable,
+ toggleStyleSourceLockMutable,
+ isStyleSourceLocked,
deleteLocalStyleSourcesMutable,
collectStyleSourcesFromInstances,
findDuplicateTokens,
@@ -1818,6 +1820,92 @@ describe("renameStyleSourceMutable", () => {
});
});
+describe("toggleStyleSourceLockMutable", () => {
+ test("locks a token style source", () => {
+ const styleSources: StyleSources = new Map([
+ ["token1", { type: "token", id: "token1", name: "Token" } as StyleSource],
+ ]);
+
+ toggleStyleSourceLockMutable({
+ id: "token1",
+ locked: true,
+ styleSources,
+ });
+
+ expect(styleSources.get("token1")).toEqual({
+ type: "token",
+ id: "token1",
+ name: "Token",
+ locked: true,
+ });
+ });
+
+ test("unlocks a token style source by removing the locked field", () => {
+ const styleSources: StyleSources = new Map([
+ [
+ "token1",
+ {
+ type: "token",
+ id: "token1",
+ name: "Token",
+ locked: true,
+ } as StyleSource,
+ ],
+ ]);
+
+ toggleStyleSourceLockMutable({
+ id: "token1",
+ locked: false,
+ styleSources,
+ });
+
+ expect(styleSources.get("token1")).toEqual({
+ type: "token",
+ id: "token1",
+ name: "Token",
+ });
+ });
+
+ test("does not lock local style sources", () => {
+ const styleSources: StyleSources = new Map([
+ ["local1", { type: "local", id: "local1" } as StyleSource],
+ ]);
+
+ toggleStyleSourceLockMutable({
+ id: "local1",
+ locked: true,
+ styleSources,
+ });
+
+ expect(styleSources.get("local1")).toEqual({
+ type: "local",
+ id: "local1",
+ });
+ });
+});
+
+describe("isStyleSourceLocked", () => {
+ test("returns true only for locked tokens", () => {
+ expect(
+ isStyleSourceLocked({
+ type: "token",
+ id: "token1",
+ name: "Token",
+ locked: true,
+ })
+ ).toBe(true);
+ expect(
+ isStyleSourceLocked({
+ type: "token",
+ id: "token1",
+ name: "Token",
+ })
+ ).toBe(false);
+ expect(isStyleSourceLocked({ type: "local", id: "local1" })).toBe(false);
+ expect(isStyleSourceLocked(undefined)).toBe(false);
+ });
+});
+
describe("deleteLocalStyleSourcesMutable", () => {
test("deletes local style sources from styleSources map", () => {
const localStyleSourceIds = new Set(["local1", "local2"]);
diff --git a/apps/builder/app/shared/style-source-utils.ts b/apps/builder/app/shared/style-source-utils.ts
index ea86fdcd3d..324a908fb5 100644
--- a/apps/builder/app/shared/style-source-utils.ts
+++ b/apps/builder/app/shared/style-source-utils.ts
@@ -14,6 +14,9 @@ import { toValue } from "@webstudio-is/css-engine";
import type { ConflictResolution } from "./token-conflict-dialog";
import { removeByMutable } from "./array-utils";
+export const isStyleSourceLocked = (styleSource: StyleSource | undefined) =>
+ styleSource?.type === "token" && styleSource.locked === true;
+
/**
* Generates a normalized CSS string for comparing style source styles.
* This creates a deterministic signature based on breakpoint, state, property, and value.
@@ -619,6 +622,26 @@ export const renameStyleSourceMutable = ({
}
};
+export const toggleStyleSourceLockMutable = ({
+ id,
+ locked,
+ styleSources,
+}: {
+ id: StyleSource["id"];
+ locked: boolean;
+ styleSources: StyleSources;
+}): void => {
+ const styleSource = styleSources.get(id);
+ if (styleSource?.type !== "token") {
+ return;
+ }
+ if (locked) {
+ styleSource.locked = true;
+ return;
+ }
+ delete styleSource.locked;
+};
+
/**
* Delete local style sources and their associated styles for a set of instances.
* This is typically used when deleting instances to clean up their local styles.
diff --git a/packages/design-system/src/components/color-picker.tsx b/packages/design-system/src/components/color-picker.tsx
index c9074fccbb..4c9f201282 100644
--- a/packages/design-system/src/components/color-picker.tsx
+++ b/packages/design-system/src/components/color-picker.tsx
@@ -147,6 +147,7 @@ type ColorPickerProps = {
open?: boolean;
onOpenChange?: (open: boolean) => void;
css?: CSS;
+ disabled?: boolean;
};
// Renders <color-input> with its built-in trigger chip, hiding the text input.
@@ -162,6 +163,7 @@ export const ColorPicker = ({
open,
onOpenChange,
css,
+ disabled = false,
}: ColorPickerProps) => {
const colorInputRef = useRef<ColorInput>(null);
const scopeClass = useId().replace(/:/g, "");
@@ -202,6 +204,12 @@ export const ColorPicker = ({
// Sync externally-controlled open state into the web component.
useEffect(() => {
+ if (disabled) {
+ try {
+ colorInputRef.current?.close();
+ } catch {}
+ return;
+ }
if (open === undefined) {
return;
}
@@ -216,7 +224,7 @@ export const ColorPicker = ({
}
} catch {}
});
- }, [open]);
+ }, [disabled, open]);
// Sync external value changes into the web component.
useEffect(() => {
@@ -241,6 +249,9 @@ export const ColorPicker = ({
colorInputElement.addEventListener(
"change",
(event: Event) => {
+ if (disabled) {
+ return;
+ }
const { value, colorspace } = (event as CustomEvent<ChangeDetail>)
.detail;
lastStyleValue = cssStringToStyleValue(value, colorspace);
@@ -253,6 +264,12 @@ export const ColorPicker = ({
colorInputElement.addEventListener(
"open",
() => {
+ if (disabled) {
+ try {
+ colorInputElement.close();
+ } catch {}
+ return;
+ }
// Set contrast immediately on open so the initial color is correct
// before any change event fires (the component's own JS sets --contrast
// based on raw color only, ignoring alpha).
@@ -270,7 +287,9 @@ export const ColorPicker = ({
callbacksRef.current.enableCanvasPointerEvents();
document.body.style.removeProperty("user-select");
callbacksRef.current.onOpenChange?.(false);
- callbacksRef.current.onChangeComplete(lastStyleValue);
+ if (!disabled) {
+ callbacksRef.current.onChangeComplete(lastStyleValue);
+ }
},
{ signal }
);
@@ -285,7 +304,7 @@ export const ColorPicker = ({
callbacksRef.current.enableCanvasPointerEvents();
document.body.style.removeProperty("user-select");
};
- }, [overrideContrast]);
+ }, [disabled, overrideContrast]);
const { className: textClass } = textStyle();
@@ -315,13 +334,15 @@ export const ColorPicker = ({
}
`}</style>
- <ColorThumb color={colorString} css={css}>
- <color-input
- ref={colorInputRef}
- value={colorString}
- theme="light"
- class={`${textClass} ${scopeClass}`}
- />
+ <ColorThumb color={colorString} css={css} aria-disabled={disabled}>
+ {disabled === false && (
+ <color-input
+ ref={colorInputRef}
+ value={colorString}
+ theme="light"
+ class={`${textClass} ${scopeClass}`}
+ />
+ )}
</ColorThumb>
</>
);
diff --git a/packages/design-system/src/components/combobox.tsx b/packages/design-system/src/components/combobox.tsx
index 45e0a85e49..ae5d00379c 100644
--- a/packages/design-system/src/components/combobox.tsx
+++ b/packages/design-system/src/components/combobox.tsx
@@ -464,6 +464,7 @@ type ComboboxProps<Item> = UseComboboxProps<Item> &
| "suffix"
| "onBlur"
| "onInvalid"
+ | "disabled"
>;
export const Combobox = <Item,>({
@@ -477,6 +478,7 @@ export const Combobox = <Item,>({
suffix,
onBlur,
onInvalid,
+ disabled,
...props
}: ComboboxProps<Item>) => {
const combobox = useCombobox<Item>(props);
@@ -500,6 +502,7 @@ export const Combobox = <Item,>({
placeholder={placeholder}
name={name}
color={color}
+ disabled={disabled}
suffix={
suffix ??
(props.getItems().length > 0 && (
diff --git a/packages/design-system/src/components/gradient-picker.tsx b/packages/design-system/src/components/gradient-picker.tsx
index 81fd3ae7bb..9b36250933 100644
--- a/packages/design-system/src/components/gradient-picker.tsx
+++ b/packages/design-system/src/components/gradient-picker.tsx
@@ -69,6 +69,7 @@ export type GradientPickerProps<T extends ParsedGradient = ParsedGradient> = {
onThumbSelect: (index: number, stop: GradientStop) => void;
selectedStopIndex?: number;
type?: T["type"];
+ disabled?: boolean;
};
const THUMB_INTERACTION_DISTANCE = 12;
@@ -253,6 +254,7 @@ export const GradientPicker = <T extends ParsedGradient>({
onChangeComplete,
onThumbSelect,
selectedStopIndex,
+ disabled = false,
}: GradientPickerProps<T>) => {
const [stops, setStops] = useState<Array<GradientStop>>(gradient.stops);
const [selectedStop, setSelectedStop] = useState<number | undefined>();
@@ -476,6 +478,14 @@ export const GradientPicker = <T extends ParsedGradient>({
}
}, [colorPickerOpenStop, stops.length]);
+ useEffect(() => {
+ if (disabled) {
+ setColorPickerOpenStop(undefined);
+ setDraggingStop(undefined);
+ setIsHoveredOnStop(false);
+ }
+ }, [disabled]);
+
const checkIfStopExistsAtPosition = useCallback(
(
clientX: number
@@ -525,6 +535,10 @@ export const GradientPicker = <T extends ParsedGradient>({
const handleThumbPointerDown = useCallback(
(index: number, stop: GradientStop) =>
(event: ReactPointerEvent<HTMLDivElement>) => {
+ if (disabled) {
+ event.preventDefault();
+ return;
+ }
// Don't start drag if the color picker is open for this thumb
if (colorPickerOpenStop === index) {
event.stopPropagation();
@@ -611,6 +625,7 @@ export const GradientPicker = <T extends ParsedGradient>({
});
},
[
+ disabled,
colorPickerOpenStop,
handleStopSelected,
thumbDragHandler,
@@ -622,6 +637,10 @@ export const GradientPicker = <T extends ParsedGradient>({
const handleHintPointerDown = useCallback(
(index: number) => (event: ReactPointerEvent<HTMLDivElement>) => {
+ if (disabled) {
+ event.preventDefault();
+ return;
+ }
event.stopPropagation();
hintDragHandler.handlePointerDown({
event,
@@ -633,11 +652,14 @@ export const GradientPicker = <T extends ParsedGradient>({
},
});
},
- [hintDragHandler, updateStopHint, onChangeComplete, buildGradient]
+ [buildGradient, disabled, hintDragHandler, onChangeComplete, updateStopHint]
);
const handleKeyDown = useCallback(
(event: KeyboardEvent<HTMLDivElement>) => {
+ if (disabled) {
+ return;
+ }
if (selectedStop === undefined) {
return;
}
@@ -725,6 +747,7 @@ export const GradientPicker = <T extends ParsedGradient>({
},
[
handleStopSelected,
+ disabled,
onThumbSelect,
selectedStop,
stops,
@@ -736,6 +759,9 @@ export const GradientPicker = <T extends ParsedGradient>({
const handlePointerDown = useCallback(
(event: ReactPointerEvent<HTMLDivElement>) => {
+ if (disabled) {
+ return;
+ }
if (
event.target instanceof HTMLElement &&
event.target.closest("[data-gradient-thumb='true']")
@@ -830,20 +856,27 @@ export const GradientPicker = <T extends ParsedGradient>({
setIsHoveredOnStop(true);
},
- [checkIfStopExistsAtPosition, onThumbSelect, updateStops]
+ [checkIfStopExistsAtPosition, disabled, onThumbSelect, updateStops]
);
const handleMouseIndicator = useCallback(
(event: MouseEvent<HTMLDivElement>) => {
+ if (disabled) {
+ setIsHoveredOnStop(false);
+ return;
+ }
const { isStopExistingAtPosition } = checkIfStopExistsAtPosition(
event.clientX
);
setIsHoveredOnStop(isStopExistingAtPosition);
},
- [checkIfStopExistsAtPosition]
+ [checkIfStopExistsAtPosition, disabled]
);
const handleSliderFocus = useCallback(() => {
+ if (disabled) {
+ return;
+ }
if (stops.length === 0) {
return;
}
@@ -855,7 +888,7 @@ export const GradientPicker = <T extends ParsedGradient>({
handleStopSelected(0, firstStop);
}
}
- }, [handleStopSelected, selectedStop, stops]);
+ }, [disabled, handleStopSelected, selectedStop, stops]);
if (
stops.some(
@@ -877,11 +910,16 @@ export const GradientPicker = <T extends ParsedGradient>({
<SliderRoot
ref={handleSliderRef}
data-gradient-slider
- css={{ backgroundImage }}
+ css={
+ disabled
+ ? { backgroundImage, opacity: 0.5, pointerEvents: "none" }
+ : { backgroundImage }
+ }
isHoveredOnStop={isHoveredOnStop}
- tabIndex={0}
+ tabIndex={disabled ? -1 : 0}
role="group"
aria-label="Gradient stops"
+ aria-disabled={disabled}
onPointerDown={handlePointerDown}
onFocus={handleSliderFocus}
onMouseEnter={handleMouseIndicator}
@@ -923,10 +961,14 @@ export const GradientPicker = <T extends ParsedGradient>({
}}
onPointerDown={handleThumbPointerDown(index, stop)}
onClick={() => {
+ if (disabled) {
+ return;
+ }
handleStopSelected(index, stop);
}}
>
<ColorPicker
+ disabled={disabled}
value={stopColor}
onChange={(value) =>
handleStopColorChange(index, value, "change")
@@ -935,9 +977,12 @@ export const GradientPicker = <T extends ParsedGradient>({
handleStopColorChange(index, value, "complete")
}
open={colorPickerOpenStop === index}
- onOpenChange={(open) =>
- handleColorPickerOpenChange(index, open)
- }
+ onOpenChange={(open) => {
+ if (disabled) {
+ return;
+ }
+ handleColorPickerOpenChange(index, open);
+ }}
css={{
width: theme.spacing[8],
height: theme.spacing[8],
diff --git a/packages/design-system/src/components/position-grid.tsx b/packages/design-system/src/components/position-grid.tsx
index 8478ccf3a8..ad957aef44 100644
--- a/packages/design-system/src/components/position-grid.tsx
+++ b/packages/design-system/src/components/position-grid.tsx
@@ -121,6 +121,7 @@ type PositionGridProps = {
focusedPosition?: Position;
selectedPosition?: MixedPosition;
focused?: boolean;
+ disabled?: boolean;
onSelect: (position: Position) => void;
};
@@ -133,6 +134,7 @@ export const PositionGrid = ({
selectedPosition,
focusedPosition,
focused = false,
+ disabled = false,
onSelect,
}: PositionGridProps) => {
const { handleKeyDown, focusedKey } = useKeyboard({
@@ -143,10 +145,12 @@ export const PositionGrid = ({
return (
<Grid
- tabIndex={0}
- onKeyDown={handleKeyDown}
+ tabIndex={disabled ? -1 : 0}
+ onKeyDown={disabled ? undefined : handleKeyDown}
data-focused={focused}
+ aria-disabled={disabled}
className={containerStyle()}
+ css={disabled ? { opacity: 0.5, pointerEvents: "none" } : undefined}
>
{positions.map(([x, y]) => {
const selectedKey = `${numericSelectedPosition?.x}-${numericSelectedPosition?.y}`;
diff --git a/packages/icons/icons/lock.svg b/packages/icons/icons/lock.svg
new file mode 100644
index 0000000000..c01be142d1
--- /dev/null
+++ b/packages/icons/icons/lock.svg
@@ -0,0 +1,14 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+<path
+ d="M4.66667 7.33334V4.66668C4.66667 3.78262 5.01786 2.93478 5.64298 2.30965C6.2681 1.68453 7.11594 1.33334 8 1.33334C8.88406 1.33334 9.7319 1.68453 10.357 2.30965C10.9821 2.93478 11.3333 3.78262 11.3333 4.66668V7.33334M3.33333 7.33334H12.6667C13.403 7.33334 14 7.9303 14 8.66668V13.3333C14 14.0697 13.403 14.6667 12.6667 14.6667H3.33333C2.59695 14.6667 2 14.0697 2 13.3333V8.66668C2 7.9303 2.59695 7.33334 3.33333 7.33334Z"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+/>
+</svg>
diff --git a/packages/icons/src/__generated__/components.tsx b/packages/icons/src/__generated__/components.tsx
index 05ca3b75bd..d9a6ee7dbe 100644
--- a/packages/icons/src/__generated__/components.tsx
+++ b/packages/icons/src/__generated__/components.tsx
@@ -3573,6 +3573,30 @@ export const LoadingDotsIcon: IconComponent = forwardRef(
);
LoadingDotsIcon.displayName = "LoadingDotsIcon";
+export const LockIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M4.667 7.333V4.667a3.333 3.333 0 0 1 6.666 0v2.666m-8 0h9.334c.736 0 1.333.597 1.333 1.334v4.666c0 .737-.597 1.334-1.333 1.334H3.333A1.333 1.333 0 0 1 2 13.333V8.667c0-.737.597-1.334 1.333-1.334Z"
+ />
+ </svg>
+ );
+ }
+);
+LockIcon.displayName = "LockIcon";
+
export const MarkdownEmbedIcon: IconComponent = forwardRef(
({ fill = "none", size = 16, ...props }, forwardedRef) => {
return (
diff --git a/packages/icons/src/__generated__/svg.ts b/packages/icons/src/__generated__/svg.ts
index c22f394b5e..91b62917a0 100644
--- a/packages/icons/src/__generated__/svg.ts
+++ b/packages/icons/src/__generated__/svg.ts
@@ -264,6 +264,8 @@ export const ListIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16
export const LoadingDotsIcon = `<svg xmlns="http://www.w3.org/2000/svg" id="cfdbcf7a5__eEMFTOz1Zbw1" shape-rendering="geometricPrecision" text-rendering="geometricPrecision" viewBox="0 0 300 300" fill="currentColor" width="100%" height="100%" style="display: block;"><style>@keyframes eEMFTOz1Zbw12_to__to{0%,26.666667%,56.666667%,6.333333%,77%,to{transform:translate(150px,180px)}16.666667%,67%{transform:translate(150px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw13_to__to{0%,20%,50%,70%,to{transform:translate(80px,180px)}10%,60%{transform:translate(80px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}@keyframes eEMFTOz1Zbw14_to__to{0%,13.333333%,33.333333%,63.333333%,83.333333%,to{transform:translate(220px,180px)}23.333333%,73.333333%{transform:translate(220px,120px);animation-timing-function:cubic-bezier(.42,0,.58,1)}}#cfdbcf7a5__eEMFTOz1Zbw12_to{animation:eEMFTOz1Zbw12_to__to 2000ms linear infinite normal forwards}#cfdbcf7a5__eEMFTOz1Zbw13_to{animation:eEMFTOz1Zbw13_to__to 2000ms linear infinite normal forwards}#cfdbcf7a5__eEMFTOz1Zbw14_to{animation:eEMFTOz1Zbw14_to__to 2000ms linear infinite normal forwards}</style><circle id="cfdbcf7a5__eEMFTOz1Zbw12_to" r="20" stroke-width="0" transform="translate(150,180) translate(0,0)"/><circle id="cfdbcf7a5__eEMFTOz1Zbw13_to" r="20" stroke-width="0" transform="translate(80,180) translate(0,0)"/><circle id="cfdbcf7a5__eEMFTOz1Zbw14_to" r="20" stroke-width="0" transform="translate(220,180) translate(0,0)"/></svg>`;
+export const LockIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.667 7.333V4.667a3.333 3.333 0 0 1 6.666 0v2.666m-8 0h9.334c.736 0 1.333.597 1.333 1.334v4.666c0 .737-.597 1.334-1.333 1.334H3.333A1.333 1.333 0 0 1 2 13.333V8.667c0-.737.597-1.334 1.333-1.334Z"/></svg>`;
+
export const MarkdownEmbedIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M4.667 5.333h4M4.667 8H10M14 8.75V3.5A1.5 1.5 0 0 0 12.5 2h-9A1.5 1.5 0 0 0 2 3.5v9.191c0 .725.588 1.313 1.313 1.313h4.691"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M10 14.314v-4l2 2.03 2-2.03v4"/></svg>`;
export const MaximizeIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M10 2h4v4M6 14H2v-4M14 2 9.334 6.667M2 14l4.667-4.667"/></svg>`;
diff --git a/packages/sdk/src/schema/style-sources.test.ts b/packages/sdk/src/schema/style-sources.test.ts
new file mode 100644
index 0000000000..8a29c75d03
--- /dev/null
+++ b/packages/sdk/src/schema/style-sources.test.ts
@@ -0,0 +1,34 @@
+import { describe, expect, test } from "vitest";
+import { StyleSource } from "./style-sources";
+
+describe("StyleSource", () => {
+ test("parses unlocked tokens without locked field", () => {
+ expect(
+ StyleSource.parse({
+ id: "token",
+ type: "token",
+ name: "Token",
+ })
+ ).toEqual({
+ id: "token",
+ type: "token",
+ name: "Token",
+ });
+ });
+
+ test("parses locked tokens", () => {
+ expect(
+ StyleSource.parse({
+ id: "token",
+ type: "token",
+ name: "Token",
+ locked: true,
+ })
+ ).toEqual({
+ id: "token",
+ type: "token",
+ name: "Token",
+ locked: true,
+ });
+ });
+});
diff --git a/packages/sdk/src/schema/style-sources.ts b/packages/sdk/src/schema/style-sources.ts
index 8181051890..f9c78a5dd8 100644
--- a/packages/sdk/src/schema/style-sources.ts
+++ b/packages/sdk/src/schema/style-sources.ts
@@ -6,6 +6,7 @@ const StyleSourceToken = z.object({
type: z.literal("token"),
id: StyleSourceId,
name: z.string(),
+ locked: z.boolean().optional(),
});
export type StyleSourceToken = z.infer<typeof StyleSourceToken>;