Skip to content

Commit 35d0d7c

Browse files
authored
experimental: Breakpoint support for the Animation component (#5012)
## Description https://animations.wstd.work/ Breakpoints Example See on narrow screen animation is disabled. <img width="699" alt="image" src="https://github.com/user-attachments/assets/f464fdf3-f57a-4cf7-91a1-beb355f8a5bd" /> ## 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: 0000) - [ ] 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` file
1 parent 8d05217 commit 35d0d7c

File tree

62 files changed

+253
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+253
-9
lines changed

apps/builder/app/canvas/canvas.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
$isContentMode,
5252
subscribeModifierKeys,
5353
assetBaseUrl,
54+
$breakpoints,
5455
} from "~/shared/nano-states";
5556
import { useDragAndDrop } from "./shared/use-drag-drop";
5657
import {
@@ -75,6 +76,7 @@ import { $selectedPage } from "~/shared/awareness";
7576
import { createInstanceElement } from "./elements";
7677
import { Body } from "./shared/body";
7778
import { subscribeScrollbarSize } from "./scrollbar-width";
79+
import { compareMedia } from "@webstudio-is/css-engine";
7880

7981
registerContainers();
8082

@@ -99,6 +101,7 @@ const FallbackComponent = ({ error, resetErrorBoundary }: FallbackProps) => {
99101
const useElementsTree = (components: Components, instances: Instances) => {
100102
const page = useStore($selectedPage);
101103
const isPreviewMode = useStore($isPreviewMode);
104+
const breakpointsMap = useStore($breakpoints);
102105
const rootInstanceId = page?.rootInstanceId ?? "";
103106

104107
if (typeof window === "undefined") {
@@ -111,6 +114,11 @@ const useElementsTree = (components: Components, instances: Instances) => {
111114
});
112115
}
113116

117+
const breakpoints = useMemo(
118+
() => [...breakpointsMap.values()].sort(compareMedia),
119+
[breakpointsMap]
120+
);
121+
114122
return useMemo(() => {
115123
return (
116124
<ReactSdkContext.Provider
@@ -119,6 +127,7 @@ const useElementsTree = (components: Components, instances: Instances) => {
119127
assetBaseUrl,
120128
imageLoader: wsImageLoader,
121129
resources: {},
130+
breakpoints,
122131
}}
123132
>
124133
{createInstanceElement({
@@ -132,7 +141,7 @@ const useElementsTree = (components: Components, instances: Instances) => {
132141
})}
133142
</ReactSdkContext.Provider>
134143
);
135-
}, [instances, rootInstanceId, components, isPreviewMode]);
144+
}, [instances, rootInstanceId, components, isPreviewMode, breakpoints]);
136145
};
137146

138147
const DesignMode = () => {

fixtures/react-router-docker/app/__generated__/[another-page]._index.tsx

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/react-router-docker/app/__generated__/_index.tsx

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/react-router-docker/app/routes/[another-page]._index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
favIconAsset,
2828
pageFontAssets,
2929
pageBackgroundImageAssets,
30+
breakpoints,
3031
} from "../__generated__/[another-page]._index";
3132
import {
3233
getResources,
@@ -272,6 +273,7 @@ const Outlet = () => {
272273
imageLoader,
273274
assetBaseUrl,
274275
resources,
276+
breakpoints,
275277
}}
276278
>
277279
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-docker/app/routes/_index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
favIconAsset,
2828
pageFontAssets,
2929
pageBackgroundImageAssets,
30+
breakpoints,
3031
} from "../__generated__/_index";
3132
import {
3233
getResources,
@@ -272,6 +273,7 @@ const Outlet = () => {
272273
imageLoader,
273274
assetBaseUrl,
274275
resources,
276+
breakpoints,
275277
}}
276278
>
277279
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-netlify/app/__generated__/[another-page]._index.tsx

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/react-router-netlify/app/__generated__/_index.tsx

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/react-router-netlify/app/routes/[another-page]._index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
favIconAsset,
2828
pageFontAssets,
2929
pageBackgroundImageAssets,
30+
breakpoints,
3031
} from "../__generated__/[another-page]._index";
3132
import {
3233
getResources,
@@ -272,6 +273,7 @@ const Outlet = () => {
272273
imageLoader,
273274
assetBaseUrl,
274275
resources,
276+
breakpoints,
275277
}}
276278
>
277279
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-netlify/app/routes/_index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
favIconAsset,
2828
pageFontAssets,
2929
pageBackgroundImageAssets,
30+
breakpoints,
3031
} from "../__generated__/_index";
3132
import {
3233
getResources,
@@ -272,6 +273,7 @@ const Outlet = () => {
272273
imageLoader,
273274
assetBaseUrl,
274275
resources,
276+
breakpoints,
275277
}}
276278
>
277279
{/* Use the URL as the key to force scripts in HTML Embed to reload on dynamic pages */}

fixtures/react-router-vercel/app/__generated__/[another-page]._index.tsx

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)