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.

experimental: Live animation setting update (#5005)

Ivan Starkov00b815aeb200
diff --git a/apps/builder/app/builder/features/inspector/inspector.tsx b/apps/builder/app/builder/features/inspector/inspector.tsx
index 004fb9ff2b..4e60951144 100644
--- a/apps/builder/app/builder/features/inspector/inspector.tsx
+++ b/apps/builder/app/builder/features/inspector/inspector.tsx
@@ -31,7 +31,11 @@ import { MetaIcon } from "~/builder/shared/meta-icon";
import { getInstanceLabel } from "~/shared/instance-utils";
import { BindingPopoverProvider } from "~/builder/shared/binding-popover";
import { $activeInspectorPanel } from "~/builder/shared/nano-states";
-import { $selectedInstance, $selectedPage } from "~/shared/awareness";
+import {
+ $selectedInstance,
+ $selectedInstanceKey,
+ $selectedPage,
+} from "~/shared/awareness";
const InstanceInfo = ({ instance }: { instance: Instance }) => {
const metas = useStore($registeredComponentMetas);
@@ -64,6 +68,7 @@ const $isDragging = computed([$dragAndDropState], (state) => state.isDragging);
export const Inspector = ({ navigatorLayout }: InspectorProps) => {
const selectedInstance = useStore($selectedInstance);
+ const selectedInstanceKey = useStore($selectedInstanceKey);
const tabsRef = useRef<HTMLDivElement>(null);
const isDragging = useStore($isDragging);
const metas = useStore($registeredComponentMetas);
@@ -75,7 +80,7 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {
return <NavigatorTree />;
}
- if (selectedInstance === undefined) {
+ if (selectedInstance === undefined || selectedInstanceKey === undefined) {
return (
<Flex css={{ p: theme.spacing[9] }}>
{/* @todo: use this space for something more usefull: a-la figma's no instance selected sate, maybe create an issue with a more specific proposal? */}
@@ -196,6 +201,7 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {
// Re-render when instance changes
key={selectedInstance.id}
selectedInstance={selectedInstance}
+ selectedInstanceKey={selectedInstanceKey}
/>
</ScrollArea>
</PanelTabsContent>
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx
index a75d5ec6c8..fa3defd4bd 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx
@@ -128,7 +128,10 @@ const Keyframe = ({
}: {
value: AnimationKeyframe;
offsetPlaceholder: number;
- onChange: (value: AnimationKeyframe | undefined) => void;
+ onChange: (
+ value: AnimationKeyframe | undefined,
+ isEphemeral: boolean
+ ) => void;
}) => {
const ids = useIds(["offset"]);
const apiRef = useRef<CssEditorApi>();
@@ -164,11 +167,11 @@ const Keyframe = ({
value={value.offset}
placeholder={offsetPlaceholder}
onChange={(offset) => {
- onChange({ ...value, offset });
+ onChange({ ...value, offset }, false);
}}
/>
<Tooltip content="Remove keyframe">
- <IconButton onClick={() => onChange(undefined)}>
+ <IconButton onClick={() => onChange(undefined, false)}>
<MinusIcon />
</IconButton>
</Tooltip>
@@ -185,7 +188,7 @@ const Keyframe = ({
for (const [property, value] of addedStyleMap) {
styles[property] = value;
}
- onChange({ ...value, styles });
+ onChange({ ...value, styles }, false);
}}
onDeleteProperty={(property, options = {}) => {
if (options.isEphemeral === true) {
@@ -193,16 +196,16 @@ const Keyframe = ({
}
const styles = { ...value.styles };
delete styles[property];
- onChange({ ...value, styles });
+ onChange({ ...value, styles }, false);
}}
onSetProperty={(property) => {
- return (newValue) => {
+ return (newValue, options) => {
const styles = { ...value.styles, [property]: newValue };
- onChange({ ...value, styles });
+ onChange({ ...value, styles }, options?.isEphemeral ?? false);
};
}}
onDeleteAllDeclarations={() => {
- onChange({ ...value, styles: {} });
+ onChange({ ...value, styles: {} }, false);
}}
/>
</Grid>
@@ -226,7 +229,8 @@ export const Keyframes = ({
onChange,
}: {
value: AnimationKeyframe[];
- onChange: (value: AnimationKeyframe[]) => void;
+ onChange: ((value: undefined, isEphemeral: true) => void) &
+ ((value: AnimationKeyframe[], isEphemeral: boolean) => void);
}) => {
// To preserve focus on children swap
const keyRefs = useRef(
@@ -251,7 +255,10 @@ export const Keyframes = ({
tabIndex={0}
prefix={<PlusIcon />}
onClick={() => {
- onChange([...keyframes, { offset: undefined, styles: {} }]);
+ onChange(
+ [...keyframes, { offset: undefined, styles: {} }],
+ false
+ );
keyRefs.current = [...keyRefs.current, keyframes.length];
}}
/>
@@ -268,11 +275,16 @@ export const Keyframes = ({
key={keyRefs.current[index]}
value={value}
offsetPlaceholder={offsets[index]}
- onChange={(newValue) => {
+ onChange={(newValue, isEphemeral) => {
+ if (newValue === undefined && isEphemeral) {
+ onChange(undefined, true);
+ return;
+ }
+
if (newValue === undefined) {
const newValues = [...keyframes];
newValues.splice(index, 1);
- onChange(newValues);
+ onChange(newValues, isEphemeral);
return;
}
@@ -281,7 +293,7 @@ export const Keyframes = ({
const { offset } = newValue;
if (offset === undefined) {
- onChange(newValues);
+ onChange(newValues, isEphemeral);
return;
}
@@ -293,7 +305,7 @@ export const Keyframes = ({
insertionIndex
);
- onChange(newValues);
+ onChange(newValues, isEphemeral);
}}
/>
</Fragment>
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx
index b1f99c719a..5661ff30a5 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx
@@ -26,7 +26,11 @@ import {
CssValueInput,
type IntermediateStyleValue,
} from "~/builder/features/style-panel/shared/css-value-input/css-value-input";
-import { toValue, type StyleValue } from "@webstudio-is/css-engine";
+import {
+ cssWideKeywords,
+ toValue,
+ type StyleValue,
+} from "@webstudio-is/css-engine";
import { useState } from "react";
import { Keyframes } from "./animation-keyframes";
import { titleCase } from "title-case";
@@ -34,7 +38,11 @@ import { titleCase } from "title-case";
type Props = {
type: "scroll" | "view";
value: ScrollAnimation | ViewAnimation;
- onChange: (value: ScrollAnimation | ViewAnimation) => void;
+ onChange: ((
+ value: ScrollAnimation | ViewAnimation,
+ isEphemeral: boolean
+ ) => void) &
+ ((value: undefined, isEphemeral: true) => void);
};
const fillModeDescriptions: Record<
@@ -97,7 +105,8 @@ const RangeValueInput = ({
}: {
id: string;
value: RangeUnitValue;
- onChange: (value: RangeUnitValue) => void;
+ onChange: ((value: undefined, isEphemeral: true) => void) &
+ ((value: RangeUnitValue, isEphemeral: boolean) => void);
}) => {
const [intermediateValue, setIntermediateValue] = useState<
StyleValue | IntermediateStyleValue
@@ -114,7 +123,14 @@ const RangeValueInput = ({
intermediateValue={intermediateValue}
onChange={(styleValue) => {
setIntermediateValue(styleValue);
- /* @todo: allow to change some ephemeral property to see the result in action */
+
+ const parsedValue = rangeUnitValueSchema.safeParse(styleValue);
+ if (parsedValue.success) {
+ onChange(parsedValue.data, true);
+ return;
+ }
+
+ onChange(undefined, true);
}}
getOptions={() => []}
onHighlight={() => {
@@ -123,7 +139,7 @@ const RangeValueInput = ({
onChangeComplete={(event) => {
const parsedValue = rangeUnitValueSchema.safeParse(event.value);
if (parsedValue.success) {
- onChange(parsedValue.data);
+ onChange(parsedValue.data, false);
setIntermediateValue(undefined);
return;
}
@@ -134,10 +150,11 @@ const RangeValueInput = ({
});
}}
onAbort={() => {
- /* @todo: allow to change some ephemeral property to see the result in action */
+ onChange(undefined, true);
}}
onReset={() => {
setIntermediateValue(undefined);
+ onChange(undefined, true);
}}
/>
);
@@ -150,7 +167,7 @@ const EasingInput = ({
}: {
id: string;
value: string | undefined;
- onChange: (value: string | undefined) => void;
+ onChange: (value: string | undefined, isEphemeral: boolean) => void;
}) => {
const [intermediateValue, setIntermediateValue] = useState<
StyleValue | IntermediateStyleValue
@@ -166,10 +183,12 @@ const EasingInput = ({
: { type: "unparsed", value }
}
getOptions={() => [
- ...keywordValues["animation-timing-function"].map((value) => ({
- type: "keyword" as const,
- value,
- })),
+ ...keywordValues["animation-timing-function"]
+ .filter((value) => !cssWideKeywords.has(value))
+ .map((value) => ({
+ type: "keyword" as const,
+ value,
+ })),
]}
property="animation-timing-function"
intermediateValue={intermediateValue}
@@ -177,18 +196,19 @@ const EasingInput = ({
setIntermediateValue(styleValue);
/* @todo: allow to change some ephemeral property to see the result in action */
}}
- onHighlight={() => {
- /* Nothing to Highlight */
+ onHighlight={(value) => {
+ onChange(toValue(value), true);
}}
onChangeComplete={(event) => {
- onChange(toValue(event.value));
+ onChange(toValue(event.value), false);
setIntermediateValue(undefined);
}}
onAbort={() => {
- /* @todo: allow to change some ephemeral property to see the result in action */
+ onChange(undefined, true);
}}
onReset={() => {
setIntermediateValue(undefined);
+ onChange(undefined, true);
}}
/>
);
@@ -212,13 +232,20 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
const animationSchema =
type === "scroll" ? scrollAnimationSchema : viewAnimationSchema;
- const handleChange = (rawValue: unknown) => {
+ const handleChange = (rawValue: unknown, isEphemeral: boolean) => {
+ if (rawValue === undefined) {
+ onChange(undefined, true);
+ return;
+ }
+
const parsedValue = animationSchema.safeParse(rawValue);
+
if (parsedValue.success) {
- onChange(parsedValue.data);
+ onChange(parsedValue.data, isEphemeral);
return;
}
+ console.error(parsedValue.error.format());
toast.error("Animation schema is incompatible, try fix");
};
@@ -245,6 +272,23 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
options={fillModeNames}
getLabel={(fillModeName: string) => titleCase(fillModeName)}
value={value.timing.fill ?? fillModeNames[0]}
+ onItemHighlight={(fillModeName) => {
+ if (fillModeName === undefined) {
+ handleChange(undefined, true);
+ return;
+ }
+
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ fill: fillModeName,
+ },
+ },
+ true
+ );
+ }}
getDescription={(fillModeName: string) => (
<Box
css={{
@@ -259,26 +303,37 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
</Box>
)}
onChange={(fillModeName) => {
- handleChange({
- ...value,
- timing: {
- ...value.timing,
- fill: fillModeName,
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ fill: fillModeName,
+ },
},
- });
+ false
+ );
}}
/>
<EasingInput
id={fieldIds.easing}
value={value.timing.easing}
- onChange={(easing) => {
- handleChange({
- ...value,
- timing: {
- ...value.timing,
- easing,
+ onChange={(easing, isEphemeral) => {
+ if (easing === undefined && isEphemeral) {
+ handleChange(undefined, true);
+ return;
+ }
+
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ easing,
+ },
},
- });
+ isEphemeral
+ );
}}
/>
</Grid>
@@ -310,21 +365,48 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
}
</Box>
)}
+ onItemHighlight={(timelineRangeName) => {
+ if (timelineRangeName === undefined) {
+ handleChange(undefined, true);
+ return;
+ }
+
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeStart: [
+ timelineRangeName,
+ value.timing.rangeStart?.[1] ?? {
+ type: "unit",
+ value: 0,
+ unit: "%",
+ },
+ ],
+ },
+ },
+ true
+ );
+ }}
onChange={(timelineRangeName) => {
- handleChange({
- ...value,
- timing: {
- ...value.timing,
- rangeStart: [
- timelineRangeName,
- value.timing.rangeStart?.[1] ?? {
- type: "unit",
- value: 0,
- unit: "%",
- },
- ],
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeStart: [
+ timelineRangeName,
+ value.timing.rangeStart?.[1] ?? {
+ type: "unit",
+ value: 0,
+ unit: "%",
+ },
+ ],
+ },
},
- });
+ false
+ );
}}
/>
<RangeValueInput
@@ -336,19 +418,27 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
unit: "%",
}
}
- onChange={(rangeStart) => {
+ onChange={(rangeStart, isEphemeral) => {
+ if (rangeStart === undefined && isEphemeral) {
+ handleChange(undefined, true);
+ return;
+ }
+
const defaultTimelineRangeName = timelineRangeNames[0]!;
- handleChange({
- ...value,
- timing: {
- ...value.timing,
- rangeStart: [
- value.timing.rangeStart?.[0] ?? defaultTimelineRangeName,
- rangeStart,
- ],
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeStart: [
+ value.timing.rangeStart?.[0] ?? defaultTimelineRangeName,
+ rangeStart,
+ ],
+ },
},
- });
+ isEphemeral
+ );
}}
/>
@@ -374,21 +464,47 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
}
</Box>
)}
+ onItemHighlight={(timelineRangeName) => {
+ if (timelineRangeName === undefined) {
+ handleChange(undefined, true);
+ return;
+ }
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeEnd: [
+ timelineRangeName,
+ value.timing.rangeEnd?.[1] ?? {
+ type: "unit",
+ value: 0,
+ unit: "%",
+ },
+ ],
+ },
+ },
+ true
+ );
+ }}
onChange={(timelineRangeName) => {
- handleChange({
- ...value,
- timing: {
- ...value.timing,
- rangeEnd: [
- timelineRangeName,
- value.timing.rangeEnd?.[1] ?? {
- type: "unit",
- value: 0,
- unit: "%",
- },
- ],
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeEnd: [
+ timelineRangeName,
+ value.timing.rangeEnd?.[1] ?? {
+ type: "unit",
+ value: 0,
+ unit: "%",
+ },
+ ],
+ },
},
- });
+ false
+ );
}}
/>
<RangeValueInput
@@ -400,26 +516,41 @@ export const AnimationPanelContent = ({ onChange, value, type }: Props) => {
unit: "%",
}
}
- onChange={(rangeEnd) => {
+ onChange={(rangeEnd, isEphemeral) => {
+ if (rangeEnd === undefined && isEphemeral) {
+ handleChange(undefined, true);
+ return;
+ }
+
const defaultTimelineRangeName = timelineRangeNames[0]!;
- handleChange({
- ...value,
- timing: {
- ...value.timing,
- rangeEnd: [
- value.timing.rangeEnd?.[0] ?? defaultTimelineRangeName,
- rangeEnd,
- ],
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeEnd: [
+ value.timing.rangeEnd?.[0] ?? defaultTimelineRangeName,
+ rangeEnd,
+ ],
+ },
},
- });
+ isEphemeral
+ );
}}
/>
</Grid>
<Keyframes
value={value.keyframes}
- onChange={(keyframes) => handleChange({ ...value, keyframes })}
+ onChange={(keyframes, isEphemeral) => {
+ if (keyframes === undefined && isEphemeral) {
+ handleChange(undefined, true);
+ return;
+ }
+
+ handleChange({ ...value, keyframes }, isEphemeral);
+ }}
/>
</Flex>
);
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx
index bdb64b52c1..3709fdc14a 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx
@@ -103,12 +103,29 @@ const InsetValueInput = ({
}: {
id: string;
value: InsetUnitValue;
- onChange: (value: InsetUnitValue) => void;
+ onChange: ((value: undefined, isEphemeral: true) => void) &
+ ((value: InsetUnitValue, isEphemeral: boolean) => void);
}) => {
const [intermediateValue, setIntermediateValue] = useState<
StyleValue | IntermediateStyleValue
>();
+ const handleEphemeralChange = (styleValue: unknown | undefined) => {
+ if (styleValue === undefined) {
+ onChange(undefined, true);
+ return;
+ }
+
+ const parsedResult = insetUnitValueSchema.safeParse(styleValue);
+
+ if (parsedResult.success) {
+ onChange(parsedResult.data, true);
+ return;
+ }
+
+ onChange(undefined, true);
+ };
+
return (
<CssValueInput
id={id}
@@ -120,7 +137,7 @@ const InsetValueInput = ({
intermediateValue={intermediateValue}
onChange={(styleValue) => {
setIntermediateValue(styleValue);
- /* @todo: allow to change some ephemeral property to see the result in action */
+ handleEphemeralChange(styleValue);
}}
getOptions={() => [
{
@@ -130,13 +147,13 @@ const InsetValueInput = ({
"Pick the child element’s viewTimelineInset property or use the scrolling element’s scroll-padding, depending on the selected axis.",
},
]}
- onHighlight={() => {
- /* Nothing to Highlight */
+ onHighlight={(value) => {
+ handleEphemeralChange(value);
}}
onChangeComplete={(event) => {
const parsedValue = insetUnitValueSchema.safeParse(event.value);
if (parsedValue.success) {
- onChange(parsedValue.data);
+ onChange(parsedValue.data, false);
setIntermediateValue(undefined);
return;
}
@@ -147,9 +164,10 @@ const InsetValueInput = ({
});
}}
onAbort={() => {
- /* @todo: allow to change some ephemeral property to see the result in action */
+ handleEphemeralChange(undefined);
}}
onReset={() => {
+ handleEphemeralChange(undefined);
setIntermediateValue(undefined);
}}
/>
@@ -165,7 +183,8 @@ export const AnimateSection = ({
onChange,
}: {
animationAction: PropAndMeta;
- onChange: (value: AnimationAction) => void;
+ onChange: ((value: undefined, isEphemeral: true) => void) &
+ ((value: AnimationAction, isEphemeral: boolean) => void);
}) => {
const fieldIds = useIds([
"type",
@@ -180,10 +199,15 @@ export const AnimateSection = ({
const value: AnimationAction =
prop?.type === "animationAction" ? prop.value : defaultActionValue;
- const handleChange = (value: unknown) => {
+ const handleChange = (value: unknown, isEphemeral: boolean) => {
+ if (value === undefined && isEphemeral) {
+ onChange(undefined, isEphemeral);
+ return;
+ }
+
const parsedValue = animationActionSchema.safeParse(value);
if (parsedValue.success) {
- onChange(parsedValue.data);
+ onChange(parsedValue.data, isEphemeral);
return;
}
@@ -235,7 +259,7 @@ export const AnimateSection = ({
}
pressed={value.debug ?? false}
onPressedChange={() => {
- handleChange({ ...value, debug: !value.debug });
+ handleChange({ ...value, debug: !value.debug }, false);
}}
variant="normal"
tabIndex={-1}
@@ -247,7 +271,7 @@ export const AnimateSection = ({
<Switch
checked={value.isPinned ?? false}
onCheckedChange={(isPinned) => {
- handleChange({ ...value, isPinned });
+ handleChange({ ...value, isPinned }, false);
}}
/>
</Tooltip>
@@ -276,7 +300,10 @@ export const AnimateSection = ({
</Box>
)}
onChange={(typeValue) => {
- handleChange({ ...value, type: typeValue, animations: [] });
+ handleChange(
+ { ...value, type: typeValue, animations: [] },
+ false
+ );
}}
/>
</Grid>
@@ -287,7 +314,7 @@ export const AnimateSection = ({
type="single"
value={value.axis ?? ("block" as const)}
onValueChange={(axis) => {
- handleChange({ ...value, axis });
+ handleChange({ ...value, axis }, false);
}}
>
{Object.entries(animationAxisDescription).map(
@@ -335,7 +362,7 @@ export const AnimateSection = ({
</Box>
)}
onChange={(source) => {
- handleChange({ ...value, source });
+ handleChange({ ...value, source }, false);
}}
/>
</Grid>
@@ -351,7 +378,7 @@ export const AnimateSection = ({
<SubjectSelect
id={fieldIds.subject}
value={value}
- onChange={onChange}
+ onChange={handleChange}
/>
</Grid>
)}
@@ -375,21 +402,21 @@ export const AnimateSection = ({
<InsetValueInput
id={fieldIds.insetStart}
value={value.insetStart ?? { type: "keyword", value: "auto" }}
- onChange={(insetStart) => {
- handleChange({ ...value, insetStart });
+ onChange={(insetStart, isEphemeral) => {
+ handleChange({ ...value, insetStart }, isEphemeral);
}}
/>
<InsetValueInput
id={fieldIds.insetEnd}
value={value.insetEnd ?? { type: "keyword", value: "auto" }}
- onChange={(insetEnd) => {
- handleChange({ ...value, insetEnd });
+ onChange={(insetEnd, isEphemeral) => {
+ handleChange({ ...value, insetEnd }, isEphemeral);
}}
/>
</Grid>
)}
- <AnimationsSelect value={value} onChange={onChange} />
+ <AnimationsSelect value={value} onChange={handleChange} />
</Grid>
</Grid>
);
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx
index 1a56cb6104..ae5727bd59 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx
@@ -17,7 +17,6 @@ import {
Grid,
useSortable,
CssValueListArrowFocus,
- toast,
FloatingPanel,
InputField,
DialogTitle,
@@ -33,8 +32,6 @@ import type {
ScrollAnimation,
ViewAnimation,
} from "@webstudio-is/sdk";
-
-import { animationActionSchema } from "@webstudio-is/sdk";
import { newScrollAnimations } from "./new-scroll-animations";
import { newViewAnimations } from "./new-view-animations";
import { useIds } from "~/shared/form-utils";
@@ -50,7 +47,8 @@ const newAnimationsPerType: {
type Props = {
value: AnimationAction;
- onChange: (value: AnimationAction) => void;
+ onChange: ((value: unknown, isEphemeral: boolean) => void) &
+ ((value: undefined, isEphemeral: true) => void);
};
const floatingPanelOffset = { alignmentAxis: -100 };
@@ -76,24 +74,12 @@ export const AnimationsSelect = ({ value, onChange }: Props) => {
const [movedItem] = newAnimations.splice(oldIndex, 1);
newAnimations.splice(newIndex, 0, movedItem);
const newValue = { ...value, animations: newAnimations };
- const parsedValue = animationActionSchema.safeParse(newValue);
-
- if (parsedValue.success) {
- onChange(parsedValue.data);
- return;
- }
- toast.error("Failed to sort animation");
+ onChange(newValue, false);
},
});
- const handleChange = (newValue: unknown) => {
- const parsedValue = animationActionSchema.safeParse(newValue);
-
- if (parsedValue.success) {
- onChange(parsedValue.data);
- return;
- }
- toast.error("Failed to add animation");
+ const handleChange = (newValue: unknown, isEphemeral: boolean) => {
+ onChange(newValue, isEphemeral);
};
return (
@@ -116,10 +102,13 @@ export const AnimationsSelect = ({ value, onChange }: Props) => {
<DropdownMenuItem
key={index}
onSelect={() => {
- handleChange({
- ...value,
- animations: value.animations.concat(animation),
- });
+ handleChange(
+ {
+ ...value,
+ animations: value.animations.concat(animation),
+ },
+ false
+ );
}}
onFocus={() => setNewAnimationHint(animation.description)}
onBlur={() => setNewAnimationHint(undefined)}
@@ -180,7 +169,7 @@ export const AnimationsSelect = ({ value, onChange }: Props) => {
animations: newAnimations,
};
- handleChange(newValue);
+ handleChange(newValue, false);
}}
/>
</DialogTitle>
@@ -189,14 +178,20 @@ export const AnimationsSelect = ({ value, onChange }: Props) => {
<AnimationPanelContent
type={value.type}
value={animation}
- onChange={(animation) => {
+ onChange={(animation, isEphemeral) => {
+ if (animation === undefined) {
+ // Reset ephemeral state
+ handleChange(undefined, true);
+ return;
+ }
+
const newAnimations = [...value.animations];
newAnimations[index] = animation;
const newValue = {
...value,
animations: newAnimations,
};
- handleChange(newValue);
+ handleChange(newValue, isEphemeral);
}}
/>
}
@@ -242,7 +237,7 @@ export const AnimationsSelect = ({ value, onChange }: Props) => {
...value,
animations: newAnimations,
};
- handleChange(newValue);
+ handleChange(newValue, false);
}}
/>
</>
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx
index c51ba0ff9f..067f7859d9 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx
@@ -8,19 +8,10 @@ import {
$selectedInstanceSelector,
} from "~/shared/nano-states";
import { getInstanceStyleDecl } from "~/builder/features/style-panel/shared/model";
-import { getInstanceLabel } from "~/shared/instance-utils";
+import { getInstanceLabel, updateWebstudioData } from "~/shared/instance-utils";
import { toValue } from "@webstudio-is/css-engine";
import type { AnimationAction } from "@webstudio-is/sdk";
-import { animationActionSchema } from "@webstudio-is/sdk";
import { setListedCssProperty } from "./set-css-property";
-import { serverSyncStore } from "~/shared/sync";
-
-import {
- $breakpoints,
- $styles,
- $styleSources,
- $styleSourceSelections,
-} from "~/shared/nano-states";
const initSubjects = () => {
const selectedInstanceSelector = $selectedInstanceSelector.get();
@@ -86,7 +77,8 @@ export const SubjectSelect = ({
id,
}: {
value: AnimationAction;
- onChange: (value: AnimationAction) => void;
+ onChange: ((value: AnimationAction, isEphemeral: boolean) => void) &
+ ((value: undefined, isEphemeral: true) => void);
id: string;
}) => {
const [subjects] = useState(() => initSubjects());
@@ -107,51 +99,69 @@ export const SubjectSelect = ({
const selector =
subjects.find((s) => s.value === subject)?.selector ?? undefined;
$hoveredInstanceSelector.set(selector);
+
+ if (subject === undefined) {
+ onChange(undefined, true);
+ return;
+ }
+
+ const subjectItem = subjects.find((s) => s.value === subject);
+ if (subjectItem === undefined) {
+ onChange(undefined, true);
+ return;
+ }
+ const newValue = {
+ ...value,
+ subject: subject === "self" ? undefined : subject,
+ };
+
+ onChange(newValue, true);
}}
onChange={(subject) => {
const newValue = {
...value,
subject: subject === "self" ? undefined : subject,
};
- const parsedValue = animationActionSchema.safeParse(newValue);
-
- if (parsedValue.success) {
- const subjectItem = subjects.find((s) => s.value === subject);
-
- if (subjectItem === undefined) {
- toast.error(`Subject "${newValue.subject}" not found`);
- return;
- }
-
- if (
- subjectItem.isTimelineExists === false &&
- newValue.subject !== undefined
- ) {
- serverSyncStore.createTransaction(
- [$breakpoints, $styles, $styleSources, $styleSourceSelections],
- (breakpoints, styles, styleSources, styleSourceSelections) => {
- if (newValue.subject === undefined) {
- return;
- }
-
- setListedCssProperty(
- breakpoints,
- styleSources,
- styleSourceSelections,
- styles
- )(subjectItem.instanceId, "view-timeline-name", {
- type: "unparsed",
- value: newValue.subject,
- });
+
+ const subjectItem = subjects.find((s) => s.value === subject);
+
+ if (subjectItem === undefined) {
+ toast.error(`Subject "${newValue.subject}" not found`);
+ return;
+ }
+
+ if (
+ subjectItem.isTimelineExists === false &&
+ newValue.subject !== undefined
+ ) {
+ updateWebstudioData(
+ ({ breakpoints, styleSources, styleSourceSelections, styles }) => {
+ if (newValue.subject === undefined) {
+ return;
}
- );
- }
- onChange(parsedValue.data);
+ setListedCssProperty(
+ breakpoints,
+ styleSources,
+ styleSourceSelections,
+ styles
+ )(subjectItem.instanceId, "view-timeline-name", {
+ type: "unparsed",
+ value: newValue.subject,
+ });
+ }
+ );
+
+ // Wait styles to be applied
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => {
+ onChange(newValue, false);
+ });
+ });
return;
}
- toast.error("Schemas are incompatible, try fix");
+ onChange(newValue, false);
}}
/>
);
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/props-section.stories.tsx b/apps/builder/app/builder/features/settings-panel/props-section/props-section.stories.tsx
index 41e89d9062..ebb6bd8cb7 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/props-section.stories.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/props-section.stories.tsx
@@ -393,6 +393,7 @@ export const Story = () => {
propsLogic={logic}
propValues={new Map()}
component="Button"
+ selectedInstanceKey={instanceId}
/>
</div>
<pre style={textVariants.mono}>
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx b/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
index 729cb7cfe6..bbf5ac031f 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx
@@ -2,7 +2,7 @@ import { computed } from "nanostores";
import { useState } from "react";
import { useStore } from "@nanostores/react";
import { matchSorter } from "match-sorter";
-import { type Instance, descendantComponent } from "@webstudio-is/sdk";
+import { type Instance, Props, descendantComponent } from "@webstudio-is/sdk";
import {
theme,
Combobox,
@@ -18,6 +18,7 @@ import {
$props,
$isDesignMode,
$isContentMode,
+ $memoryProps,
} from "~/shared/nano-states";
import { CollapsibleSectionWithAddButton } from "~/builder/shared/collapsible-section";
import { renderControl } from "../controls/combined";
@@ -25,6 +26,7 @@ import { usePropsLogic, type PropAndMeta } from "./use-props-logic";
import { serverSyncStore } from "~/shared/sync";
import { $selectedInstanceKey } from "~/shared/awareness";
import { AnimateSection } from "./animation/animation-section";
+import { nanoid } from "nanoid";
type Item = {
name: string;
@@ -138,6 +140,7 @@ type PropsSectionProps = {
propValues: Map<string, unknown>;
component: Instance["component"];
instanceId: string;
+ selectedInstanceKey: string;
};
// A UI componet with minimum logic that can be demoed in Storybook etc.
@@ -163,12 +166,43 @@ export const PropsSection = (props: PropsSectionProps) => {
<>
<AnimateSection
animationAction={animationAction}
- onChange={(value) =>
+ onChange={(value, isEphemeral) => {
+ const memoryProps = new Map($memoryProps.get());
+ const memoryInstanceProp: Props = new Map(
+ memoryProps.get(props.selectedInstanceKey)
+ );
+
+ if (isEphemeral && value !== undefined) {
+ memoryInstanceProp.set(animationAction.propName, {
+ id: nanoid(),
+ instanceId: props.instanceId,
+ type: "animationAction",
+ name: animationAction.propName,
+ value,
+ });
+ memoryProps.set(props.selectedInstanceKey, memoryInstanceProp);
+ $memoryProps.set(memoryProps);
+ return;
+ }
+
+ if (memoryInstanceProp.has(animationAction.propName)) {
+ memoryInstanceProp.delete(animationAction.propName);
+ memoryProps.set(props.selectedInstanceKey, memoryInstanceProp);
+
+ $memoryProps.set(memoryProps);
+ }
+
+ if (isEphemeral || value === undefined) {
+ return;
+ }
+
+ isEphemeral satisfies false;
+
logic.handleChangeByPropName(animationAction.propName, {
type: "animationAction",
value,
- })
- }
+ });
+ }}
/>
<Separator />
</>
@@ -223,8 +257,10 @@ const $propValues = computed(
export const PropsSectionContainer = ({
selectedInstance: instance,
+ selectedInstanceKey,
}: {
selectedInstance: Instance;
+ selectedInstanceKey: string;
}) => {
const { propsByInstanceId } = useStore($propsIndex);
const propValues = useStore($propValues);
@@ -266,6 +302,7 @@ export const PropsSectionContainer = ({
propValues={propValues ?? new Map()}
component={instance.component}
instanceId={instance.id}
+ selectedInstanceKey={selectedInstanceKey}
/>
</fieldset>
);
diff --git a/apps/builder/app/builder/features/settings-panel/settings-panel.tsx b/apps/builder/app/builder/features/settings-panel/settings-panel.tsx
index 15d1ba227b..6cc6eab386 100644
--- a/apps/builder/app/builder/features/settings-panel/settings-panel.tsx
+++ b/apps/builder/app/builder/features/settings-panel/settings-panel.tsx
@@ -18,8 +18,10 @@ import { $isDesignMode, $userPlanFeatures } from "~/shared/nano-states";
export const SettingsPanel = ({
selectedInstance,
+ selectedInstanceKey,
}: {
selectedInstance: Instance;
+ selectedInstanceKey: string;
}) => {
const { allowDynamicData } = useStore($userPlanFeatures);
const isDesignMode = useStore($isDesignMode);
@@ -28,7 +30,10 @@ export const SettingsPanel = ({
<Box css={{ pt: theme.spacing[5] }}>
<SettingsSection />
- <PropsSectionContainer selectedInstance={selectedInstance} />
+ <PropsSectionContainer
+ selectedInstance={selectedInstance}
+ selectedInstanceKey={selectedInstanceKey}
+ />
{isDesignMode && <VariablesSection />}
diff --git a/apps/builder/app/shared/form-utils/use-ids.ts b/apps/builder/app/shared/form-utils/use-ids.ts
index 1da8fa6ae7..27ed2d49a6 100644
--- a/apps/builder/app/shared/form-utils/use-ids.ts
+++ b/apps/builder/app/shared/form-utils/use-ids.ts
@@ -1,25 +1,10 @@
-import { useId, useRef } from "react";
+import { useId } from "react";
export const useIds = <FieldName extends string>(
fieldNames: readonly FieldName[]
) => {
- if (process.env.NODE_ENV !== "production") {
- // It's OK to disable because process.env.NODE_ENV is not going to change
- // eslint-disable-next-line react-hooks/rules-of-hooks
- const fieldNamesLength = useRef<number>(fieldNames.length);
- if (fieldNamesLength.current !== fieldNames.length) {
- throw new Error("changing fieldNames length is not supported");
- }
- fieldNamesLength.current = fieldNames.length;
- }
-
- const result: Record<string, string> = {};
-
- for (const fieldName of fieldNames) {
- // It's OK to disable because of the check above
- // eslint-disable-next-line react-hooks/rules-of-hooks
- result[fieldName] = useId();
- }
-
- return result as Record<FieldName, string>;
+ const id = useId();
+ return Object.fromEntries(
+ fieldNames.map((fieldName) => [fieldName, `${id}-${fieldName}`])
+ ) as Record<FieldName, string>;
};
diff --git a/packages/sdk/src/schema/styles.ts b/packages/sdk/src/schema/styles.ts
index 722af5820c..8c4574be4b 100644
--- a/packages/sdk/src/schema/styles.ts
+++ b/packages/sdk/src/schema/styles.ts
@@ -9,7 +9,10 @@ const StyleDeclRaw = z.object({
// @todo can't figure out how to make property to be enum
property: z.string(),
value: StyleValue,
- listed: z.boolean().optional(),
+ listed: z
+ .boolean()
+ .optional()
+ .describe("Whether the style is from the Advanced panel"),
});
export type StyleDecl = Simplify<