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: Show animation is running is Nav Tree (#5023)

Ivan Starkov10a4c7090256
diff --git a/apps/builder/app/builder/features/navigator/navigator-tree.tsx b/apps/builder/app/builder/features/navigator/navigator-tree.tsx
index bfd0d7bf14..9f32bf7861 100644
--- a/apps/builder/app/builder/features/navigator/navigator-tree.tsx
+++ b/apps/builder/app/builder/features/navigator/navigator-tree.tsx
@@ -5,6 +5,7 @@ import { mergeRefs } from "@react-aria/utils";
import { useStore } from "@nanostores/react";
import {
Box,
+ keyframes,
rawTheme,
ScrollArea,
SmallIconButton,
@@ -19,7 +20,10 @@ import {
TreeSortableItem,
type TreeDropTarget,
} from "@webstudio-is/design-system";
-import { showAttribute } from "@webstudio-is/react-sdk";
+import {
+ animationCanPlayOnCanvasAttribute,
+ showAttribute,
+} from "@webstudio-is/react-sdk";
import {
ROOT_INSTANCE_ID,
collectionComponent,
@@ -49,6 +53,7 @@ import {
$selectedInstanceSelector,
getIndexedInstanceId,
type ItemDropTarget,
+ $propValuesByInstanceSelectorWithMemoryProps,
} from "~/shared/nano-states";
import type { InstanceSelector } from "~/shared/tree-utils";
import { serverSyncStore } from "~/shared/sync";
@@ -282,12 +287,27 @@ const handleExpand = (item: TreeItem, isExpanded: boolean, all: boolean) => {
$expandedItems.set(expandedItems);
};
+const pulse = keyframes({
+ "0%": { fillOpacity: 0 },
+ "100%": { fillOpacity: 1 },
+});
+
+const AnimatedEyeOpenIcon = styled(EyeOpenIcon, {
+ "& .ws-eye-open-pupil": {
+ transformOrigin: "center",
+ animation: `${pulse} 1.5s ease-in-out infinite alternate`,
+ fill: "currentColor",
+ },
+});
+
const ShowToggle = ({
instance,
value,
+ isAnimating,
}: {
instance: Instance;
value: boolean;
+ isAnimating: boolean;
}) => {
// descendant component is not actually rendered
// but affects styling of nested elements
@@ -315,18 +335,45 @@ const ShowToggle = ({
}
});
};
+
+ const EyeIcon = isAnimating ? AnimatedEyeOpenIcon : EyeOpenIcon;
+
return (
<Tooltip
// If you are changing it, change the other one too
- content="Removes the instance from the DOM. Breakpoints have no effect on this setting."
+ content={
+ <Text>
+ Removes the instance from the DOM. Breakpoints have no effect on this
+ setting.
+ {isAnimating && value && (
+ <>
+ <br />
+ <Text css={{ color: theme.colors.foregroundPrimary }}>
+ Animation is running on canvas.
+ </Text>
+ </>
+ )}
+ </Text>
+ }
disableHoverableContent
variant="wrapped"
>
<SmallIconButton
+ css={
+ value && isAnimating
+ ? {
+ color: theme.colors.foregroundPrimary,
+ "&:hover": {
+ color: theme.colors.foregroundPrimary,
+ filter: "brightness(80%)",
+ },
+ }
+ : undefined
+ }
tabIndex={-1}
aria-label="Show"
onClick={toggleShow}
- icon={value ? <EyeOpenIcon /> : <EyeClosedIcon />}
+ icon={value ? <EyeIcon /> : <EyeClosedIcon />}
/>
</Tooltip>
);
@@ -521,7 +568,11 @@ export const NavigatorTree = () => {
const selectedKey = selectedInstanceSelector?.join();
const hoveredInstanceSelector = useStore($hoveredInstanceSelector);
const hoveredKey = hoveredInstanceSelector?.join();
- const propValuesByInstanceSelector = useStore($propValuesByInstanceSelector);
+ const propValuesByInstanceSelectorWithMemoryProps = useStore(
+ $propValuesByInstanceSelectorWithMemoryProps
+ );
+ const { propsByInstanceId } = useStore($propsIndex);
+
const metas = useStore($registeredComponentMetas);
const editingItemSelector = useStore($editingItemSelector);
const dragAndDropState = useStore($dragAndDropState);
@@ -608,14 +659,30 @@ export const NavigatorTree = () => {
{flatTree.map((item) => {
const level = item.visibleAncestors.length - 1;
const key = item.selector.join();
- const propValues = propValuesByInstanceSelector.get(
+ const propValues = propValuesByInstanceSelectorWithMemoryProps.get(
getInstanceKey(item.selector)
);
const show = Boolean(propValues?.get(showAttribute) ?? true);
+
+ // Hook memory prop
+ const isAnimationSelected =
+ propValues?.get(animationCanPlayOnCanvasAttribute) === true;
+
+ const props = propsByInstanceId.get(item.instance.id);
+ const actionProp = props?.find(
+ (prop) => prop.type === "animationAction"
+ );
+
+ const isAnimationPinned = actionProp?.value?.isPinned === true;
+
+ const isAnimating = isAnimationSelected || isAnimationPinned;
+
const meta = metas.get(item.instance.component);
+
if (meta === undefined) {
return;
}
+
return (
<TreeSortableItem
key={key}
@@ -669,6 +736,7 @@ export const NavigatorTree = () => {
isSelected={selectedKey === key}
isHighlighted={hoveredKey === key || dropTargetKey === key}
isExpanded={item.isExpanded}
+ isActionVisible={isAnimating}
onExpand={(isExpanded, all) =>
handleExpand(item, isExpanded, all)
}
@@ -696,7 +764,13 @@ export const NavigatorTree = () => {
}
},
}}
- action={<ShowToggle instance={item.instance} value={show} />}
+ action={
+ <ShowToggle
+ instance={item.instance}
+ value={show}
+ isAnimating={isAnimating}
+ />
+ }
>
<TreeNodeContent
meta={meta}
diff --git a/packages/design-system/src/components/tree.tsx b/packages/design-system/src/components/tree.tsx
index 1c8ecde65a..de146c3281 100644
--- a/packages/design-system/src/components/tree.tsx
+++ b/packages/design-system/src/components/tree.tsx
@@ -408,6 +408,7 @@ export const TreeNode = ({
isSelected,
isHighlighted,
isExpanded,
+ isActionVisible,
onExpand,
nodeProps,
buttonProps,
@@ -419,10 +420,11 @@ export const TreeNode = ({
isSelected: boolean;
isHighlighted?: boolean;
isExpanded?: undefined | boolean;
+ isActionVisible?: boolean;
onExpand?: (expanded: boolean, all: boolean) => void;
nodeProps?: ComponentPropsWithoutRef<"div">;
buttonProps: ComponentPropsWithoutRef<"button">;
- action?: ReactNode;
+ action: ReactNode;
children: ReactNode;
}) => {
const buttonRef = useRef<HTMLButtonElement>(null);
@@ -463,7 +465,10 @@ export const TreeNode = ({
return (
<NodeContainer
{...nodeProps}
- css={{ [treeNodeLevel]: level }}
+ css={{
+ [treeNodeLevel]: level,
+ ...(isActionVisible && { [treeActionOpacity]: 1 }),
+ }}
onKeyDown={handleKeydown}
>
<DepthBars />
@@ -489,7 +494,7 @@ export const TreeNode = ({
)}
</ExpandButton>
)}
- {action && <ActionContainer data-tree-action>{action}</ActionContainer>}
+ <ActionContainer data-tree-action>{action}</ActionContainer>
</NodeContainer>
);
};
diff --git a/packages/icons/icons/eye-open.svg b/packages/icons/icons/eye-open.svg
index 51b3e27930..a98be98bb1 100644
--- a/packages/icons/icons/eye-open.svg
+++ b/packages/icons/icons/eye-open.svg
@@ -12,6 +12,7 @@
stroke-linejoin="round"
/>
<path
+ class="ws-eye-open-pupil"
d="M8 10C9.10457 10 10 9.10457 10 8C10 6.89543 9.10457 6 8 6C6.89543 6 6 6.89543 6 8C6 9.10457 6.89543 10 8 10Z"
stroke="currentColor"
stroke-linecap="round"
diff --git a/packages/icons/src/__generated__/components.tsx b/packages/icons/src/__generated__/components.tsx
index a3a4385c95..09c7a84d17 100644
--- a/packages/icons/src/__generated__/components.tsx
+++ b/packages/icons/src/__generated__/components.tsx
@@ -2254,6 +2254,7 @@ export const EyeOpenIcon: IconComponent = forwardRef(
strokeLinecap="round"
strokeLinejoin="round"
d="M8 10a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z"
+ className="ws-eye-open-pupil"
/>
</svg>
);
diff --git a/packages/icons/src/__generated__/svg.ts b/packages/icons/src/__generated__/svg.ts
index 65c92a15ac..f18a242776 100644
--- a/packages/icons/src/__generated__/svg.ts
+++ b/packages/icons/src/__generated__/svg.ts
@@ -166,7 +166,7 @@ export const ExternalLinkIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="n
export const EyeClosedIcon = `<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 12-.481-2.167M1.333 5.333a7.097 7.097 0 0 0 13.334 0M13.333 10l-1.15-1.367M2.667 10l1.15-1.367M6 12l.481-2.167"/></svg>`;
-export const EyeOpenIcon = `<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="M1.375 8.232a.667.667 0 0 1 0-.464 7.167 7.167 0 0 1 13.25 0 .666.666 0 0 1 0 .464 7.166 7.166 0 0 1-13.25 0Z"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 10a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z"/></svg>`;
+export const EyeOpenIcon = `<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="M1.375 8.232a.667.667 0 0 1 0-.464 7.167 7.167 0 0 1 13.25 0 .666.666 0 0 1 0 .464 7.166 7.166 0 0 1-13.25 0Z"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 10a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z" class="ws-eye-open-pupil"/></svg>`;
export const EyedropperIcon = `<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="m1.502 14.498.65-.65h1.947L9.94 8.008"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M2.151 13.849V11.9L7.993 6.06M9.94 4.113l2.207-2.207a1.377 1.377 0 0 1 1.947 1.947L11.887 6.06l.26.26A1.376 1.376 0 1 1 10.2 8.266L7.733 5.8a1.377 1.377 0 1 1 1.948-1.947l.26.26Z"/></svg>`;
diff --git a/packages/react-sdk/src/props.ts b/packages/react-sdk/src/props.ts
index 8fdf2d05d3..e47bf252ef 100644
--- a/packages/react-sdk/src/props.ts
+++ b/packages/react-sdk/src/props.ts
@@ -129,6 +129,8 @@ export const showAttribute = "data-ws-show" as const;
export const indexAttribute = "data-ws-index" as const;
export const collapsedAttribute = "data-ws-collapsed" as const;
export const textContentAttribute = "data-ws-text-content" as const;
+export const animationCanPlayOnCanvasAttribute =
+ "data-ws-animation-can-play-on-canvas";
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
diff --git a/packages/sdk-components-animation/private-src b/packages/sdk-components-animation/private-src
index 9c747258d2..d17da84813 160000
--- a/packages/sdk-components-animation/private-src
+++ b/packages/sdk-components-animation/private-src
@@ -1 +1 @@
-Subproject commit 9c747258d2a6a9700a5ea70f303a0ff83b20669b
+Subproject commit d17da8481348a4fa0e1545d16c63fdd35798e4f8
diff --git a/packages/sdk-components-animation/src/animate-children.tsx b/packages/sdk-components-animation/src/animate-children.tsx
index 5662e2eb8d..34e09ad325 100644
--- a/packages/sdk-components-animation/src/animate-children.tsx
+++ b/packages/sdk-components-animation/src/animate-children.tsx
@@ -1,7 +1,9 @@
-import type { Hook } from "@webstudio-is/react-sdk";
+import {
+ animationCanPlayOnCanvasAttribute,
+ type Hook,
+} from "@webstudio-is/react-sdk";
import type { AnimationAction } from "@webstudio-is/sdk";
import { forwardRef, type ElementRef } from "react";
-import { animationCanPlayOnCanvasProperty } from "./shared/consts";
type ScrollProps = {
debug?: boolean;
@@ -28,7 +30,7 @@ export const hooksAnimateChildren: Hook = {
) {
context.setMemoryProp(
event.instancePath[0],
- animationCanPlayOnCanvasProperty,
+ animationCanPlayOnCanvasAttribute,
undefined
);
}
@@ -40,7 +42,7 @@ export const hooksAnimateChildren: Hook = {
) {
context.setMemoryProp(
event.instancePath[0],
- animationCanPlayOnCanvasProperty,
+ animationCanPlayOnCanvasAttribute,
true
);
}
diff --git a/packages/sdk-components-animation/src/shared/consts.ts b/packages/sdk-components-animation/src/shared/consts.ts
deleted file mode 100644
index 0a2dee9706..0000000000
--- a/packages/sdk-components-animation/src/shared/consts.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export const animationCanPlayOnCanvasProperty =
- "data-ws-animation-can-play-on-canvas";