Skip to content

Commit 00b815a

Browse files
authored
experimental: Live animation setting update (#5005)
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory
1 parent 32120c3 commit 00b815a

File tree

11 files changed

+423
-211
lines changed

11 files changed

+423
-211
lines changed

apps/builder/app/builder/features/inspector/inspector.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import { MetaIcon } from "~/builder/shared/meta-icon";
3131
import { getInstanceLabel } from "~/shared/instance-utils";
3232
import { BindingPopoverProvider } from "~/builder/shared/binding-popover";
3333
import { $activeInspectorPanel } from "~/builder/shared/nano-states";
34-
import { $selectedInstance, $selectedPage } from "~/shared/awareness";
34+
import {
35+
$selectedInstance,
36+
$selectedInstanceKey,
37+
$selectedPage,
38+
} from "~/shared/awareness";
3539

3640
const InstanceInfo = ({ instance }: { instance: Instance }) => {
3741
const metas = useStore($registeredComponentMetas);
@@ -64,6 +68,7 @@ const $isDragging = computed([$dragAndDropState], (state) => state.isDragging);
6468

6569
export const Inspector = ({ navigatorLayout }: InspectorProps) => {
6670
const selectedInstance = useStore($selectedInstance);
71+
const selectedInstanceKey = useStore($selectedInstanceKey);
6772
const tabsRef = useRef<HTMLDivElement>(null);
6873
const isDragging = useStore($isDragging);
6974
const metas = useStore($registeredComponentMetas);
@@ -75,7 +80,7 @@ export const Inspector = ({ navigatorLayout }: InspectorProps) => {
7580
return <NavigatorTree />;
7681
}
7782

78-
if (selectedInstance === undefined) {
83+
if (selectedInstance === undefined || selectedInstanceKey === undefined) {
7984
return (
8085
<Flex css={{ p: theme.spacing[9] }}>
8186
{/* @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) => {
196201
// Re-render when instance changes
197202
key={selectedInstance.id}
198203
selectedInstance={selectedInstance}
204+
selectedInstanceKey={selectedInstanceKey}
199205
/>
200206
</ScrollArea>
201207
</PanelTabsContent>

apps/builder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ const Keyframe = ({
128128
}: {
129129
value: AnimationKeyframe;
130130
offsetPlaceholder: number;
131-
onChange: (value: AnimationKeyframe | undefined) => void;
131+
onChange: (
132+
value: AnimationKeyframe | undefined,
133+
isEphemeral: boolean
134+
) => void;
132135
}) => {
133136
const ids = useIds(["offset"]);
134137
const apiRef = useRef<CssEditorApi>();
@@ -164,11 +167,11 @@ const Keyframe = ({
164167
value={value.offset}
165168
placeholder={offsetPlaceholder}
166169
onChange={(offset) => {
167-
onChange({ ...value, offset });
170+
onChange({ ...value, offset }, false);
168171
}}
169172
/>
170173
<Tooltip content="Remove keyframe">
171-
<IconButton onClick={() => onChange(undefined)}>
174+
<IconButton onClick={() => onChange(undefined, false)}>
172175
<MinusIcon />
173176
</IconButton>
174177
</Tooltip>
@@ -185,24 +188,24 @@ const Keyframe = ({
185188
for (const [property, value] of addedStyleMap) {
186189
styles[property] = value;
187190
}
188-
onChange({ ...value, styles });
191+
onChange({ ...value, styles }, false);
189192
}}
190193
onDeleteProperty={(property, options = {}) => {
191194
if (options.isEphemeral === true) {
192195
return;
193196
}
194197
const styles = { ...value.styles };
195198
delete styles[property];
196-
onChange({ ...value, styles });
199+
onChange({ ...value, styles }, false);
197200
}}
198201
onSetProperty={(property) => {
199-
return (newValue) => {
202+
return (newValue, options) => {
200203
const styles = { ...value.styles, [property]: newValue };
201-
onChange({ ...value, styles });
204+
onChange({ ...value, styles }, options?.isEphemeral ?? false);
202205
};
203206
}}
204207
onDeleteAllDeclarations={() => {
205-
onChange({ ...value, styles: {} });
208+
onChange({ ...value, styles: {} }, false);
206209
}}
207210
/>
208211
</Grid>
@@ -226,7 +229,8 @@ export const Keyframes = ({
226229
onChange,
227230
}: {
228231
value: AnimationKeyframe[];
229-
onChange: (value: AnimationKeyframe[]) => void;
232+
onChange: ((value: undefined, isEphemeral: true) => void) &
233+
((value: AnimationKeyframe[], isEphemeral: boolean) => void);
230234
}) => {
231235
// To preserve focus on children swap
232236
const keyRefs = useRef(
@@ -251,7 +255,10 @@ export const Keyframes = ({
251255
tabIndex={0}
252256
prefix={<PlusIcon />}
253257
onClick={() => {
254-
onChange([...keyframes, { offset: undefined, styles: {} }]);
258+
onChange(
259+
[...keyframes, { offset: undefined, styles: {} }],
260+
false
261+
);
255262
keyRefs.current = [...keyRefs.current, keyframes.length];
256263
}}
257264
/>
@@ -268,11 +275,16 @@ export const Keyframes = ({
268275
key={keyRefs.current[index]}
269276
value={value}
270277
offsetPlaceholder={offsets[index]}
271-
onChange={(newValue) => {
278+
onChange={(newValue, isEphemeral) => {
279+
if (newValue === undefined && isEphemeral) {
280+
onChange(undefined, true);
281+
return;
282+
}
283+
272284
if (newValue === undefined) {
273285
const newValues = [...keyframes];
274286
newValues.splice(index, 1);
275-
onChange(newValues);
287+
onChange(newValues, isEphemeral);
276288
return;
277289
}
278290

@@ -281,7 +293,7 @@ export const Keyframes = ({
281293

282294
const { offset } = newValue;
283295
if (offset === undefined) {
284-
onChange(newValues);
296+
onChange(newValues, isEphemeral);
285297
return;
286298
}
287299

@@ -293,7 +305,7 @@ export const Keyframes = ({
293305
insertionIndex
294306
);
295307

296-
onChange(newValues);
308+
onChange(newValues, isEphemeral);
297309
}}
298310
/>
299311
</Fragment>

0 commit comments

Comments
 (0)