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.

Breakpoints redesign stage 2 (#1366)

Oleg Isonen48b4980d1269
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsx
index 1eb7f1bc80..c1eaf59532 100644
--- a/apps/builder/app/builder/builder.tsx
+++ b/apps/builder/app/builder/builder.tsx
@@ -20,7 +20,6 @@ import {
import { Topbar } from "./features/topbar";
import builderStyles from "./builder.css";
import { Footer } from "./features/footer";
-import { useUpdateCanvasWidth } from "./features/breakpoints";
import {
CanvasIframe,
useReadCanvasRect,
@@ -290,7 +289,6 @@ export const Builder = ({
useSetIsPreviewMode(authPermit === "view");
const [isPreviewMode] = useIsPreviewMode();
usePublishShortcuts(publish);
- const onRefReadCanvasWidth = useUpdateCanvasWidth();
const { onRef: onRefReadCanvas, onTransitionEnd } = useReadCanvasRect();
useSubscribeCanvasReady(publish);
// We need to initialize this in both canvas and builder,
@@ -298,12 +296,11 @@ export const Builder = ({
useCopyPaste();
useSetWindowTitle();
const iframeRefCallback = useCallback(
- (ref) => {
- publishRef.current = ref;
- onRefReadCanvasWidth(ref);
- onRefReadCanvas(ref);
+ (element) => {
+ publishRef.current = element;
+ onRefReadCanvas(element);
},
- [publishRef, onRefReadCanvasWidth, onRefReadCanvas]
+ [publishRef, onRefReadCanvas]
);
const isCanvasPointerEventsEnabled = useStore(
isCanvasPointerEventsEnabledStore
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx
index 54d0b2c622..69d91ead0c 100644
--- a/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx
@@ -11,7 +11,8 @@ import {
DeprecatedText2,
} from "@webstudio-is/design-system";
import { PlusIcon, TrashIcon } from "@webstudio-is/icons";
-import { breakpointsContainer, useBreakpoints } from "~/shared/nano-states";
+import { breakpointsStore } from "~/shared/nano-states";
+import { useStore } from "@nanostores/react";
type BreakpointEditorItemProps = {
breakpoint: Breakpoint;
@@ -97,7 +98,7 @@ type BreakpointsEditorProps = {
};
export const BreakpointsEditor = ({ onDelete }: BreakpointsEditorProps) => {
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
const [addedBreakpoints, setAddedBreakpoints] = useState<Breakpoint[]>([]);
const storedBreakpoints = new Set<string>();
for (const breakpoint of breakpoints.values()) {
@@ -144,7 +145,7 @@ export const BreakpointsEditor = ({ onDelete }: BreakpointsEditorProps) => {
key={breakpoint.id}
breakpoint={breakpoint}
onChange={(updatedBreakpoint) => {
- store.createTransaction([breakpointsContainer], (breakpoints) => {
+ store.createTransaction([breakpointsStore], (breakpoints) => {
breakpoints.set(updatedBreakpoint.id, updatedBreakpoint);
});
}}
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx
new file mode 100644
index 0000000000..1d2bf8ed60
--- /dev/null
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx
@@ -0,0 +1,64 @@
+import { useStore } from "@nanostores/react";
+import {
+ Toolbar,
+ ToolbarToggleGroup,
+ ToolbarToggleItem,
+} from "@webstudio-is/design-system";
+import { useRef } from "react";
+import { CascadeIndicator } from "./cascade-indicator";
+import { BpStarOffIcon, BpStarOnIcon } from "@webstudio-is/icons";
+import { useSetInitialCanvasWidth } from ".";
+import {
+ breakpointsStore,
+ selectedBreakpointStore,
+ selectedBreakpointIdStore,
+} from "~/shared/nano-states";
+import { groupBreakpoints } from "~/shared/breakpoints";
+
+export const BreakpointsSelector = () => {
+ const breakpoints = useStore(breakpointsStore);
+ const selectedBreakpoint = useStore(selectedBreakpointStore);
+ const ref = useRef(null);
+ const setInitialCanvasWidth = useSetInitialCanvasWidth();
+ if (selectedBreakpoint === undefined) {
+ return null;
+ }
+ return (
+ <Toolbar>
+ <ToolbarToggleGroup
+ type="single"
+ value={selectedBreakpoint.id}
+ onValueChange={(breakpointId: string) => {
+ selectedBreakpointIdStore.set(breakpointId);
+ const nextSelectedBreakpoint = breakpoints.get(breakpointId);
+ if (nextSelectedBreakpoint) {
+ setInitialCanvasWidth(nextSelectedBreakpoint.id);
+ }
+ }}
+ css={{ position: "relative" }}
+ >
+ {groupBreakpoints(Array.from(breakpoints.values())).map(
+ (breakpoint) => {
+ return (
+ <ToolbarToggleItem
+ variant="subtle"
+ ref={breakpoint.id === selectedBreakpoint.id ? ref : undefined}
+ value={breakpoint.id}
+ key={breakpoint.id}
+ >
+ {breakpoint.minWidth ??
+ breakpoint.maxWidth ??
+ (breakpoint.id === selectedBreakpoint.id ? (
+ <BpStarOnIcon size={22} />
+ ) : (
+ <BpStarOffIcon size={22} />
+ ))}
+ </ToolbarToggleItem>
+ );
+ }
+ )}
+ <CascadeIndicator buttonRef={ref} />
+ </ToolbarToggleGroup>
+ </Toolbar>
+ );
+};
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx
similarity index 78%
rename from apps/builder/app/builder/features/breakpoints/breakpoints.tsx
rename to apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx
index 25b4a26df8..28d083dd84 100644
--- a/apps/builder/app/builder/features/breakpoints/breakpoints.tsx
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useState } from "react";
+import { useState } from "react";
import { useStore } from "@nanostores/react";
import store from "immerhin";
import type { Breakpoint } from "@webstudio-is/project-build";
@@ -10,43 +10,31 @@ import {
DropdownMenuItem,
DropdownMenuPortal,
DropdownMenuSeparator,
- DropdownMenuTrigger,
DropdownMenuItemRightSlot,
} from "@webstudio-is/design-system";
import { useSubscribe } from "~/shared/pubsub";
import { BreakpointsEditor } from "./breakpoints-editor";
-import { Preview } from "./preview";
-import { ZoomSetting } from "./zoom-setting";
import { TriggerButton } from "./trigger-button";
import { WidthSetting } from "./width-setting";
import { ConfirmationDialog } from "./confirmation-dialog";
import {
- breakpointsContainer,
+ breakpointsStore,
stylesStore,
- useBreakpoints,
-} from "~/shared/nano-states";
-import {
selectedBreakpointIdStore,
selectedBreakpointStore,
-} from "~/shared/nano-states/breakpoints";
-import { compareMedia } from "@webstudio-is/css-engine";
+} from "~/shared/nano-states";
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
+import { groupBreakpoints } from "~/shared/breakpoints";
-export const Breakpoints = () => {
+export const BreakpointsSettings = () => {
const [view, setView] = useState<
"selector" | "editor" | "confirmation" | undefined
>();
const [breakpointToDelete, setBreakpointToDelete] = useState<
Breakpoint | undefined
>();
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
const selectedBreakpoint = useStore(selectedBreakpointStore);
- const [breakpointPreview, setBreakpointPreview] =
- useState(selectedBreakpoint);
-
- useEffect(() => {
- setBreakpointPreview(selectedBreakpoint);
- }, [selectedBreakpoint]);
useSubscribe("openBreakpointsMenu", () => {
setView("selector");
@@ -65,7 +53,7 @@ export const Breakpoints = () => {
return;
}
store.createTransaction(
- [breakpointsContainer, stylesStore],
+ [breakpointsStore, stylesStore],
(breakpoints, styles) => {
const breakpointId = breakpointToDelete.id;
breakpoints.delete(breakpointId);
@@ -93,14 +81,13 @@ export const Breakpoints = () => {
setView(isOpen ? "selector" : undefined);
}}
>
- <DropdownMenuTrigger asChild>
- <TriggerButton />
- </DropdownMenuTrigger>
+ <TriggerButton />
<DropdownMenuPortal>
<DropdownMenuContent
css={{ zIndex: theme.zIndices[1] }}
sideOffset={4}
collisionPadding={4}
+ align="start"
>
{view === "confirmation" && breakpointToDelete && (
<ConfirmationDialog
@@ -134,23 +121,16 @@ export const Breakpoints = () => {
)}
{view === "selector" && (
<>
- {Array.from(breakpoints.values())
- .sort(compareMedia)
- .reverse()
- .map((breakpoint) => {
+ {groupBreakpoints(Array.from(breakpoints.values())).map(
+ (breakpoint) => {
return (
<DropdownMenuCheckboxItem
checked={breakpoint === selectedBreakpoint}
key={breakpoint.id}
- onMouseEnter={() => {
- setBreakpointPreview(breakpoint);
- }}
- onMouseLeave={() => {
- setBreakpointPreview(selectedBreakpoint);
- }}
onSelect={() => {
selectedBreakpointIdStore.set(breakpoint.id);
}}
+ css={{ gap: theme.spacing[10] }}
>
{breakpoint.label}
<DropdownMenuItemRightSlot>
@@ -158,14 +138,12 @@ export const Breakpoints = () => {
</DropdownMenuItemRightSlot>
</DropdownMenuCheckboxItem>
);
- })}
+ }
+ )}
<DropdownMenuSeparator />
<form>
- <ZoomSetting />
<WidthSetting />
</form>
- <DropdownMenuSeparator />
- <Preview breakpoint={breakpointPreview} />
{isFeatureEnabled("breakpointsEditor") && (
<>
<DropdownMenuSeparator />
diff --git a/apps/builder/app/builder/features/breakpoints/cascade-indicator.tsx b/apps/builder/app/builder/features/breakpoints/cascade-indicator.tsx
new file mode 100644
index 0000000000..c567393262
--- /dev/null
+++ b/apps/builder/app/builder/features/breakpoints/cascade-indicator.tsx
@@ -0,0 +1,135 @@
+import { useStore } from "@nanostores/react";
+import { css, theme } from "@webstudio-is/design-system";
+import { useEffect, useState, type RefObject } from "react";
+import { selectedBreakpointStore } from "~/shared/nano-states";
+import type { Breakpoint } from "@webstudio-is/project-build";
+import { breakpointsStore } from "~/shared/nano-states";
+import { isBaseBreakpoint } from "~/shared/breakpoints";
+
+const cascadeIndicatorStyle = css({
+ position: "absolute",
+ bottom: 0,
+ height: 2,
+ transition: "150ms width, 150ms left, 150ms right",
+ '&[data-direction="left"]': {
+ background: theme.colors.backgroundGradientHorizontal,
+ },
+ '&[data-direction="right"]': {
+ background: theme.colors.backgroundGradientHorizontalReverse,
+ },
+});
+
+const calcIndicatorStyle = ({
+ buttonLeft,
+ buttonWidth,
+ containerWidth,
+ selectedBreakpoint,
+}: {
+ buttonLeft: number;
+ buttonWidth: number;
+ containerWidth: number;
+ selectedBreakpoint: Breakpoint;
+}) => {
+ if (isBaseBreakpoint(selectedBreakpoint)) {
+ return {
+ left: {
+ left: 0,
+ width: buttonLeft + buttonWidth / 2,
+ },
+ right: {
+ width: containerWidth - buttonLeft - buttonWidth / 2,
+ left: buttonLeft + buttonWidth / 2,
+ },
+ };
+ }
+ if (selectedBreakpoint.minWidth !== undefined) {
+ return {
+ left: {
+ right: buttonLeft + buttonWidth,
+ width: buttonLeft + buttonWidth,
+ left: 0,
+ },
+ right: {
+ left: 0,
+ width: 0,
+ },
+ };
+ }
+
+ return {
+ left: {
+ left: 0,
+ width: 0,
+ },
+ right: {
+ width: containerWidth - buttonLeft,
+ left: buttonLeft,
+ },
+ };
+};
+
+const useSizes = ({
+ buttonRef,
+ selectedBreakpoint,
+}: {
+ buttonRef: RefObject<HTMLButtonElement | null>;
+ selectedBreakpoint?: Breakpoint;
+}) => {
+ const [buttonLeft, setButtonLeft] = useState<number>();
+ const [buttonWidth, setButtonWidth] = useState<number>();
+ const [containerWidth, setContainerWidth] = useState<number>();
+ const breakpoints = useStore(breakpointsStore);
+
+ useEffect(() => {
+ if (buttonRef.current) {
+ setButtonLeft(buttonRef.current.offsetLeft);
+ setButtonWidth(buttonRef.current.offsetWidth);
+ setContainerWidth(buttonRef.current.parentElement?.offsetWidth);
+ }
+ }, [
+ selectedBreakpoint,
+ buttonRef,
+ // needed to update sizes when breakpoints are changed
+ breakpoints,
+ ]);
+
+ if (
+ buttonLeft === undefined ||
+ containerWidth === undefined ||
+ buttonWidth === undefined
+ ) {
+ return;
+ }
+ return { buttonLeft, containerWidth, buttonWidth };
+};
+
+// There are 2 indicators left and right.
+// Left one is shown for min breakpoints, right one for max breakpoints.
+// When you have base breakpoint selected which has neither min nor max width, both indicators are shown.
+export const CascadeIndicator = ({
+ buttonRef,
+}: {
+ buttonRef: RefObject<HTMLButtonElement | null>;
+}) => {
+ const selectedBreakpoint = useStore(selectedBreakpointStore);
+ const sizes = useSizes({ buttonRef, selectedBreakpoint });
+ if (selectedBreakpoint === undefined || sizes === undefined) {
+ return null;
+ }
+
+ const indicatorStyle = calcIndicatorStyle({ ...sizes, selectedBreakpoint });
+ return (
+ <>
+ <div
+ className={cascadeIndicatorStyle()}
+ data-direction="left"
+ style={indicatorStyle.left}
+ />
+ <div
+ className={cascadeIndicatorStyle()}
+ data-direction="right"
+ style={indicatorStyle.right}
+ />
+ </>
+ );
+};
diff --git a/apps/builder/app/builder/features/breakpoints/find-initial-width.test.ts b/apps/builder/app/builder/features/breakpoints/find-initial-width.test.ts
new file mode 100644
index 0000000000..17f856aae1
--- /dev/null
+++ b/apps/builder/app/builder/features/breakpoints/find-initial-width.test.ts
@@ -0,0 +1,67 @@
+import { describe, test, expect } from "@jest/globals";
+import { findInitialWidth } from "./find-initial-width";
+
+const workspaceWidth = 1000;
+
+const breakpoints = [
+ { id: "0", label: "Base" },
+ { id: "1", label: "Tablet", maxWidth: 991 },
+ { id: "2", label: "Mobile landscape", maxWidth: 767 },
+ { id: "3", label: "Mobile portrait", maxWidth: 479 },
+ { id: "4", label: "Large", minWidth: 1280 },
+ { id: "5", label: "Extra Large", minWidth: 1440 },
+];
+
+describe("Find initial width", () => {
+ test("base", () => {
+ expect(
+ findInitialWidth(breakpoints, breakpoints[0], workspaceWidth)
+ ).toStrictEqual(workspaceWidth);
+ });
+ test("tablet", () => {
+ expect(
+ findInitialWidth(breakpoints, breakpoints[1], workspaceWidth)
+ ).toStrictEqual(768);
+ });
+ test("mobile landscape", () => {
+ expect(
+ findInitialWidth(breakpoints, breakpoints[2], workspaceWidth)
+ ).toStrictEqual(480);
+ });
+ test("mobile portrait", () => {
+ expect(
+ findInitialWidth(breakpoints, breakpoints[3], workspaceWidth)
+ ).toStrictEqual(320);
+ });
+ test("large", () => {
+ expect(
+ findInitialWidth(breakpoints, breakpoints[4], workspaceWidth)
+ ).toStrictEqual(1280);
+ });
+ test("extra large", () => {
+ expect(
+ findInitialWidth(breakpoints, breakpoints[5], workspaceWidth)
+ ).toStrictEqual(1440);
+ });
+
+ test("0 min-width", () => {
+ const breakpoints = [{ id: "0", label: "x", minWidth: 0 }];
+ expect(
+ findInitialWidth(breakpoints, breakpoints[0], workspaceWidth)
+ ).toStrictEqual(320);
+ });
+
+ test("low min-width", () => {
+ const breakpoints = [{ id: "0", label: "x", minWidth: 123 }];
+ expect(
+ findInitialWidth(breakpoints, breakpoints[0], workspaceWidth)
+ ).toStrictEqual(123);
+ });
+
+ test("no previous max-width", () => {
+ const breakpoints = [{ id: "0", label: "x", maxWidth: 100 }];
+ expect(
+ findInitialWidth(breakpoints, breakpoints[0], workspaceWidth)
+ ).toStrictEqual(320);
+ });
+});
diff --git a/apps/builder/app/builder/features/breakpoints/find-initial-width.ts b/apps/builder/app/builder/features/breakpoints/find-initial-width.ts
new file mode 100644
index 0000000000..e91b0ab898
--- /dev/null
+++ b/apps/builder/app/builder/features/breakpoints/find-initial-width.ts
@@ -0,0 +1,42 @@
+import { compareMedia } from "@webstudio-is/css-engine";
+import type { Breakpoint } from "@webstudio-is/project-build";
+
+const defaultWidth = 320;
+
+// Find a canvas width that is within the selected breakpoint's range, but is at it's minimum.
+// Goal is to allow user to consistently know the direction they want to resize to after they switched to a breakpoint.
+// In this case they will want to always increase the width after switching.
+export const findInitialWidth = (
+ breakpoints: Array<Breakpoint>,
+ selectedBreakpoint: Breakpoint,
+ workspaceWidth: number
+) => {
+ // When on a base breakpoint, we want to show maximum width canvas
+ if (
+ selectedBreakpoint.minWidth === undefined &&
+ selectedBreakpoint.maxWidth === undefined
+ ) {
+ return workspaceWidth;
+ }
+
+ if (selectedBreakpoint.minWidth !== undefined) {
+ if (selectedBreakpoint.minWidth === 0) {
+ return defaultWidth;
+ }
+ return selectedBreakpoint.minWidth;
+ }
+
+ const sorted = breakpoints
+ .filter((breakpoint) => breakpoint.maxWidth !== undefined)
+ .sort(compareMedia)
+ .reverse();
+
+ const index = sorted.findIndex(
+ (breakpoint) => breakpoint.id === selectedBreakpoint.id
+ );
+ const previousBreakpointMaxWidth = sorted[index - 1]?.maxWidth;
+ if (previousBreakpointMaxWidth === undefined) {
+ return defaultWidth;
+ }
+ return previousBreakpointMaxWidth + 1;
+};
diff --git a/apps/builder/app/builder/features/breakpoints/index.ts b/apps/builder/app/builder/features/breakpoints/index.ts
index 2555fdd61d..60ee353edc 100644
--- a/apps/builder/app/builder/features/breakpoints/index.ts
+++ b/apps/builder/app/builder/features/breakpoints/index.ts
@@ -1,2 +1,3 @@
-export * from "./breakpoints";
-export * from "./use-update-canvas-width";
+export * from "./breakpoints-settings";
+export * from "./breakpoints-selector";
+export * from "./use-set-initial-canvas-width";
diff --git a/apps/builder/app/builder/features/breakpoints/preview.tsx b/apps/builder/app/builder/features/breakpoints/preview.tsx
deleted file mode 100644
index 899ec6dbba..0000000000
--- a/apps/builder/app/builder/features/breakpoints/preview.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import type { Breakpoint } from "@webstudio-is/project-build";
-import {
- theme,
- DeprecatedParagraph,
- Flex,
- DeprecatedText2,
-} from "@webstudio-is/design-system";
-
-type PreviewProps = {
- breakpoint?: Breakpoint;
-};
-
-export const Preview = ({ breakpoint }: PreviewProps) => {
- return (
- <Flex
- css={{
- px: theme.spacing[11],
- py: theme.spacing[3],
-
- // need a constant width to avoid entire menu width change
- // as user hovers over different breakpoints
- width: theme.spacing[29],
- }}
- gap="1"
- direction="column"
- >
- <DeprecatedText2>CSS Preview</DeprecatedText2>
- <DeprecatedParagraph color="hint">
- {breakpoint === undefined
- ? "No breakpoint selected"
- : "minWidth" in breakpoint
- ? `@media (min-width: ${breakpoint.minWidth}px)`
- : "maxWidth" in breakpoint
- ? `@media (max-width: ${breakpoint.maxWidth}px)`
- : "@media all"}
- </DeprecatedParagraph>
- </Flex>
- );
-};
diff --git a/apps/builder/app/builder/features/breakpoints/trigger-button.tsx b/apps/builder/app/builder/features/breakpoints/trigger-button.tsx
index a080049c1d..e1ebe4ccea 100644
--- a/apps/builder/app/builder/features/breakpoints/trigger-button.tsx
+++ b/apps/builder/app/builder/features/breakpoints/trigger-button.tsx
@@ -1,34 +1,58 @@
-import { forwardRef, type ComponentProps, type ElementRef } from "react";
+import { type ComponentProps } from "react";
import { useStore } from "@nanostores/react";
-import { Button, Text } from "@webstudio-is/design-system";
-import { useCanvasWidth } from "~/builder/shared/nano-states";
import {
- selectedBreakpointStore,
- zoomStore,
-} from "~/shared/nano-states/breakpoints";
-import { matchMedia } from "@webstudio-is/css-engine";
+ DropdownMenuSubTrigger,
+ DropdownMenuTrigger,
+ Flex,
+ theme,
+ toggleItemStyle,
+} from "@webstudio-is/design-system";
+import { scaleStore, useCanvasWidth } from "~/builder/shared/nano-states";
+import { selectedBreakpointStore } from "~/shared/nano-states";
-type TriggerButtonProps = ComponentProps<typeof Button>;
+const Value = ({
+ children,
+ unit,
+ minWidth,
+}: {
+ children?: number;
+ unit: string;
+ minWidth: number;
+}) => {
+ return (
+ <Flex gap="1" as="span" justify="end" css={{ minWidth }}>
+ {children}
+ <Flex css={{ color: theme.colors.foregroundTextMoreSubtle }} as="span">
+ {unit}
+ </Flex>
+ </Flex>
+ );
+};
+
+type TriggerButtonProps = ComponentProps<typeof DropdownMenuSubTrigger>;
-export const TriggerButton = forwardRef<
- ElementRef<typeof Button>,
- TriggerButtonProps
->((props, ref) => {
- const zoom = useStore(zoomStore);
+export const TriggerButton = (props: TriggerButtonProps) => {
+ const scale = useStore(scaleStore);
const breakpoint = useStore(selectedBreakpointStore);
const [canvasWidth] = useCanvasWidth();
if (breakpoint === undefined) {
return null;
}
- const variant = matchMedia(breakpoint, canvasWidth) ? "contrast" : "subtle";
-
return (
- <Button {...props} ref={ref} color="dark" aria-label="Show breakpoints">
- <Text color={variant}>
- {`${breakpoint.label} ${canvasWidth}px / ${zoom}%`}
- </Text>
- </Button>
+ <DropdownMenuTrigger
+ aria-label="Show breakpoints"
+ className={toggleItemStyle({
+ css: { gap: theme.spacing[5] },
+ })}
+ >
+ <Value unit="PX" minWidth={55}>
+ {canvasWidth}
+ </Value>
+ {scale !== 100 && (
+ <Value unit="%" minWidth={30}>
+ {Math.round(scale)}
+ </Value>
+ )}
+ </DropdownMenuTrigger>
);
-});
-
-TriggerButton.displayName = "TriggerButton";
+};
diff --git a/apps/builder/app/builder/features/breakpoints/use-next-breakpoint.ts b/apps/builder/app/builder/features/breakpoints/use-next-breakpoint.ts
deleted file mode 100644
index 4ed8c98e74..0000000000
--- a/apps/builder/app/builder/features/breakpoints/use-next-breakpoint.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { useMemo } from "react";
-import { useBreakpoints } from "~/shared/nano-states";
-import { useStore } from "@nanostores/react";
-import { selectedBreakpointStore } from "~/shared/nano-states/breakpoints";
-import { compareMedia } from "@webstudio-is/css-engine";
-
-/**
- * Return the next breakpoint from the currently selected one, sorted by the `sort()`
- */
-export const useNextBreakpoint = () => {
- const selectedBreakpoint = useStore(selectedBreakpointStore);
- const [breakpoints] = useBreakpoints();
-
- const sortedBreakpoints = useMemo(
- () => Array.from(breakpoints.values()).sort(compareMedia),
- [breakpoints]
- );
-
- return useMemo(() => {
- if (selectedBreakpoint === undefined) {
- return;
- }
- const index = sortedBreakpoints.findIndex(
- (breakpoint) => breakpoint.id === selectedBreakpoint.id
- );
- if (index === -1) {
- return undefined;
- }
- return sortedBreakpoints[index + 1];
- }, [sortedBreakpoints, selectedBreakpoint]);
-};
diff --git a/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts b/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts
new file mode 100644
index 0000000000..edaab54649
--- /dev/null
+++ b/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts
@@ -0,0 +1,48 @@
+import { useStore } from "@nanostores/react";
+import { useCallback, useEffect, useRef } from "react";
+import {
+ useCanvasWidth,
+ workspaceRectStore,
+} from "~/builder/shared/nano-states";
+import { breakpointsStore } from "~/shared/nano-states";
+import { selectedBreakpointStore } from "~/shared/nano-states";
+import { findInitialWidth } from "./find-initial-width";
+
+export const useSetInitialCanvasWidth = () => {
+ const [, setCanvasWidth] = useCanvasWidth();
+ const workspaceRect = useStore(workspaceRectStore);
+ const breakpoints = useStore(breakpointsStore);
+ return useCallback(
+ (breakpointId) => {
+ const breakpoint = breakpoints.get(breakpointId);
+ if (workspaceRect === undefined || breakpoint === undefined) {
+ return false;
+ }
+ const width = findInitialWidth(
+ Array.from(breakpoints.values()),
+ breakpoint,
+ workspaceRect.width
+ );
+ setCanvasWidth(width);
+ return true;
+ },
+ [workspaceRect, breakpoints, setCanvasWidth]
+ );
+};
+
+export const useSetInitialCanvasWidthOnce = () => {
+ const selectedBreakpoint = useStore(selectedBreakpointStore);
+ const isDone = useRef(false);
+ const setWidth = useSetInitialCanvasWidth();
+ const workspaceRect = useStore(workspaceRectStore);
+
+ // Set it initially once.
+ useEffect(() => {
+ if (isDone.current) {
+ return;
+ }
+ if (selectedBreakpoint) {
+ isDone.current = setWidth(selectedBreakpoint.id);
+ }
+ }, [selectedBreakpoint, setWidth, workspaceRect]);
+};
diff --git a/apps/builder/app/builder/features/breakpoints/use-update-canvas-width.ts b/apps/builder/app/builder/features/breakpoints/use-update-canvas-width.ts
deleted file mode 100644
index b6a7f7751c..0000000000
--- a/apps/builder/app/builder/features/breakpoints/use-update-canvas-width.ts
+++ /dev/null
@@ -1,82 +0,0 @@
-import { useStore } from "@nanostores/react";
-import { useCallback, useEffect, useRef } from "react";
-import { useCanvasWidth } from "~/builder/shared/nano-states";
-import { useIsPreviewMode } from "~/shared/nano-states";
-import {
- selectedBreakpointStore,
- workspaceRectStore,
-} from "~/shared/nano-states/breakpoints";
-import { useNextBreakpoint } from "./use-next-breakpoint";
-import { minWidth } from "./width-setting";
-
-export const useUpdateCanvasWidth = () => {
- const selectedBreakpoint = useStore(selectedBreakpointStore);
- const [canvasWidth, setCanvasWidth] = useCanvasWidth();
- const [isPreviewMode] = useIsPreviewMode();
- const nextBreakpoint = useNextBreakpoint();
- const workspaceRect = useStore(workspaceRectStore);
-
- // We don't won't workspace rect resize observer to trigger canvas width update.
- // We only need the initial workspace width here.
- const initialWorkspaceRect = useRef(workspaceRect);
- initialWorkspaceRect.current = workspaceRect;
-
- // Ensure the size is within currently selected breakpoint when returning to design mode out of preview mode,
- // because preview mode enables resizing without constraining to the selected breakpoint.
- useEffect(() => {
- if (isPreviewMode || selectedBreakpoint === undefined) {
- return;
- }
- const maxWidthBelowNextBreakpoint = (nextBreakpoint?.minWidth ?? 1) - 1;
- const initialMaxAvailableWidth = initialWorkspaceRect.current
- ? Math.min(
- maxWidthBelowNextBreakpoint,
- initialWorkspaceRect.current.width
- )
- : maxWidthBelowNextBreakpoint;
-
- const width = Math.max(
- selectedBreakpoint.minWidth ?? 0,
- initialMaxAvailableWidth,
- minWidth
- );
- setCanvasWidth(width);
- }, [
- isPreviewMode,
- selectedBreakpoint,
- nextBreakpoint,
- setCanvasWidth,
- initialWorkspaceRect,
- ]);
-
- // This fallback is needed for cases when something unexpected loads in the iframe.
- // In that case the width remains 0, and user is unable to see what has loaded,
- // in particular any error messages.
- // The delay is used to make sure we don't set the fallback width too early,
- // because when canvas loads normally this will cause a jump in the width.
- useEffect(() => {
- if (canvasWidth !== 0) {
- return;
- }
- const timeoutId = setTimeout(() => {
- setCanvasWidth(600);
- }, 3000);
- return () => clearTimeout(timeoutId);
- }, [canvasWidth, setCanvasWidth]);
-
- // Set the initial canvas width based on the selected breakpoint upper bound, which starts where the next breakpoint begins.
- return useCallback(
- (iframe: HTMLIFrameElement | null) => {
- // Once canvasWidth is set, it means we have already set the initial width.
- if (
- iframe === null ||
- selectedBreakpoint === undefined ||
- canvasWidth !== 0
- ) {
- return;
- }
- setCanvasWidth(minWidth);
- },
- [canvasWidth, selectedBreakpoint, setCanvasWidth]
- );
-};
diff --git a/apps/builder/app/builder/features/breakpoints/width-setting.tsx b/apps/builder/app/builder/features/breakpoints/width-setting.tsx
index da29499324..a6f8182591 100644
--- a/apps/builder/app/builder/features/breakpoints/width-setting.tsx
+++ b/apps/builder/app/builder/features/breakpoints/width-setting.tsx
@@ -1,58 +1,50 @@
import { useStore } from "@nanostores/react";
-import {
- theme,
- DeprecatedText2,
- Flex,
- Slider,
-} from "@webstudio-is/design-system";
-import { useIsPreviewMode } from "~/shared/nano-states";
-import { selectedBreakpointStore } from "~/shared/nano-states/breakpoints";
+import { findApplicableMedia } from "@webstudio-is/css-engine";
+import { theme, Text, Flex, Slider } from "@webstudio-is/design-system";
import { useCanvasWidth } from "~/builder/shared/nano-states";
-import { useNextBreakpoint } from "./use-next-breakpoint";
+import { breakpointsStore } from "~/shared/nano-states";
+import {
+ selectedBreakpointIdStore,
+ selectedBreakpointStore,
+} from "~/shared/nano-states";
// Doesn't make sense to allow resizing the canvas lower/higher than this.
-export const minWidth = 360;
-export const maxWidth = 3000;
+export const minWidth = 240;
+export const maxWidth = 2500;
export const WidthSetting = () => {
const [canvasWidth, setCanvasWidth] = useCanvasWidth();
const selectedBreakpoint = useStore(selectedBreakpointStore);
- const nextBreakpoint = useNextBreakpoint();
- const [isPreviewMode] = useIsPreviewMode();
+ const breakpoints = useStore(breakpointsStore);
- if (selectedBreakpoint === undefined) {
+ if (canvasWidth === undefined || selectedBreakpoint === undefined) {
return null;
}
- // We want to enable unconstrained resizing in a preview mode
- const min = isPreviewMode
- ? minWidth
- : Math.max(minWidth, selectedBreakpoint.minWidth ?? 0);
-
- const max = isPreviewMode
- ? maxWidth
- : Math.min(
- maxWidth,
- nextBreakpoint ? (nextBreakpoint.minWidth ?? 1) - 1 : maxWidth
- );
-
return (
<Flex
css={{ px: theme.spacing[11], py: theme.spacing[3] }}
gap="1"
direction="column"
>
- <DeprecatedText2>Canvas width</DeprecatedText2>
+ <Text>Canvas width</Text>
<Flex gap="3" align="center">
<Slider
- min={min}
- max={max}
+ min={minWidth}
+ max={maxWidth}
value={[canvasWidth]}
onValueChange={([value]) => {
setCanvasWidth(value);
+ const applicableBreakpoint = findApplicableMedia(
+ Array.from(breakpoints.values()),
+ value
+ );
+ if (applicableBreakpoint) {
+ selectedBreakpointIdStore.set(applicableBreakpoint.id);
+ }
}}
/>
- <DeprecatedText2>{`${canvasWidth}px`}</DeprecatedText2>
+ <Text>{`${canvasWidth}px`}</Text>
</Flex>
</Flex>
);
diff --git a/apps/builder/app/builder/features/breakpoints/zoom-setting.tsx b/apps/builder/app/builder/features/breakpoints/zoom-setting.tsx
deleted file mode 100644
index fffacaf73a..0000000000
--- a/apps/builder/app/builder/features/breakpoints/zoom-setting.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { useStore } from "@nanostores/react";
-import {
- theme,
- Slider,
- DeprecatedText2,
- Flex,
-} from "@webstudio-is/design-system";
-import { minZoom, zoomStore } from "~/shared/nano-states/breakpoints";
-
-export const ZoomSetting = () => {
- const value = useStore(zoomStore);
- return (
- <Flex
- css={{ px: theme.spacing[11], py: theme.spacing[3] }}
- gap="1"
- direction="column"
- >
- <DeprecatedText2>Zoom</DeprecatedText2>
- <Flex gap="3" align="center">
- <Slider
- min={minZoom}
- value={value}
- onValueChange={([value]) => {
- zoomStore.set(value);
- }}
- />
- <DeprecatedText2>{value}%</DeprecatedText2>
- </Flex>
- </Flex>
- );
-};
diff --git a/apps/builder/app/builder/features/footer/breadcrumbs.tsx b/apps/builder/app/builder/features/footer/breadcrumbs.tsx
index 34f4c678bf..72125a200a 100644
--- a/apps/builder/app/builder/features/footer/breadcrumbs.tsx
+++ b/apps/builder/app/builder/features/footer/breadcrumbs.tsx
@@ -11,7 +11,7 @@ import {
selectedInstanceSelectorStore,
} from "~/shared/nano-states";
import { getAncestorInstanceSelector } from "~/shared/tree-utils";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
+import { textEditingInstanceSelectorStore } from "~/shared/nano-states";
type BreadcrumbProps = {
children: JSX.Element | string;
diff --git a/apps/builder/app/builder/features/sidebar-left/panels/components/use-draggable.tsx b/apps/builder/app/builder/features/sidebar-left/panels/components/use-draggable.tsx
index 5abb8c5d10..98723df61a 100644
--- a/apps/builder/app/builder/features/sidebar-left/panels/components/use-draggable.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/panels/components/use-draggable.tsx
@@ -22,10 +22,10 @@ import {
import { useSubscribe, type Publish } from "~/shared/pubsub";
import {
isCanvasPointerEventsEnabledStore,
+ scaleStore,
useCanvasRect,
} from "~/builder/shared/nano-states";
import { insertNewComponentInstance } from "~/shared/instance-utils";
-import { zoomStore } from "~/shared/nano-states/breakpoints";
const DragLayer = ({
component,
@@ -65,14 +65,17 @@ export const dragItemAttribute = "data-drag-component";
const toCanvasCoordinates = (
{ x, y }: Point,
- zoom: number,
+ scale: number,
canvasRect?: DOMRect
) => {
if (canvasRect === undefined) {
return { x: 0, y: 0 };
}
- const scale = zoom / 100;
- return { x: (x - canvasRect.x) / scale, y: (y - canvasRect.y) / scale };
+ const scaleFraction = scale / 100;
+ return {
+ x: (x - canvasRect.x) / scaleFraction,
+ y: (y - canvasRect.y) / scaleFraction,
+ };
};
export const elementToComponentName = (
@@ -102,7 +105,7 @@ export const useDraggable = ({
const [dragComponent, setDragComponent] = useState<Instance["component"]>();
const [point, setPoint] = useState<Point>({ x: 0, y: 0 });
const [canvasRect] = useCanvasRect();
- const zoom = useStore(zoomStore);
+ const scale = useStore(scaleStore);
const dragHandlers = useDrag<Instance["component"]>({
elementToData(element) {
@@ -125,7 +128,7 @@ export const useDraggable = ({
publish({
type: "dragMove",
payload: {
- canvasCoordinates: toCanvasCoordinates(point, zoom, canvasRect),
+ canvasCoordinates: toCanvasCoordinates(point, scale, canvasRect),
},
});
},
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 9fc7ec32bd..9043720e35 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
@@ -142,7 +142,7 @@ const useScrub = ({
};
export const isNumericString = (input: string) =>
- String(input).trim().length !== 0 && isNaN(Number(input)) === false;
+ String(input).trim().length !== 0 && Number.isNaN(Number(input)) === false;
const useHandleKeyDown =
({
diff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
index 3ba14dc795..00aa1a441e 100644
--- a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
@@ -17,7 +17,7 @@ import {
PopoverContent,
} from "@webstudio-is/design-system";
import { UndoIcon } from "@webstudio-is/icons";
-import { instancesStore, useBreakpoints } from "~/shared/nano-states";
+import { breakpointsStore, instancesStore } from "~/shared/nano-states";
import { type StyleInfo, type StyleSource, getStyleSource } from "./style-info";
const PropertyPopoverContent = ({
@@ -31,7 +31,7 @@ const PropertyPopoverContent = ({
styleSource: StyleSource;
onReset: () => void;
}) => {
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
const instances = useStore(instancesStore);
if (styleSource === "local") {
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
index 4aa6ce737b..f98602c627 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-info.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
@@ -16,10 +16,10 @@ import {
selectedInstanceSelectorStore,
selectedInstanceIntanceToTagStore,
stylesIndexStore,
- useBreakpoints,
selectedOrLastStyleSourceSelectorStore,
+ breakpointsStore,
} from "~/shared/nano-states";
-import { selectedBreakpointStore } from "~/shared/nano-states/breakpoints";
+import { selectedBreakpointStore } from "~/shared/nano-states";
import type { InstanceSelector } from "~/shared/tree-utils";
import { getComponentMeta } from "@webstudio-is/react-sdk";
import type { htmlTags as HtmlTags } from "html-tags";
@@ -257,7 +257,7 @@ export const getInheritedInfo = (
* combine all local, cascaded, inherited and browser styles
*/
export const useStyleInfo = () => {
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
const selectedBreakpoint = useStore(selectedBreakpointStore);
const selectedBreakpointId = selectedBreakpoint?.id;
const selectedInstanceSelector = useStore(selectedInstanceSelectorStore);
@@ -387,7 +387,7 @@ export const useInstanceStyleData = (
) => {
const instances = useStore(instancesStore);
const { stylesByInstanceId } = useStore(stylesIndexStore);
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
const selectedBreakpoint = useStore(selectedBreakpointStore);
// We assume that instance ancestor contains tags we need to get preset styles
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 dff08c349f..03ce8c099e 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
@@ -16,7 +16,7 @@ import {
styleSourcesStore,
stylesStore,
} from "~/shared/nano-states";
-import { selectedBreakpointStore } from "~/shared/nano-states/breakpoints";
+import { selectedBreakpointStore } from "~/shared/nano-states";
// @todo: must be removed, now it's only for compatibility with existing code
import { parseCssValue } from "./parse-css-value";
import { useStyleInfo } from "./style-info";
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 a8a443115c..e2ff3301b0 100644
--- a/apps/builder/app/builder/features/style-panel/style-panel.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-panel.tsx
@@ -7,7 +7,7 @@ import {
} from "@webstudio-is/design-system";
import type { Instance } from "@webstudio-is/project-build";
import type { Publish } from "~/shared/pubsub";
-import { selectedBreakpointStore } from "~/shared/nano-states/breakpoints";
+import { selectedBreakpointStore } from "~/shared/nano-states";
import { useStyleData } from "./shared/use-style-data";
import { StyleSettings } from "./style-settings";
import { useCanvasWidth } from "~/builder/shared/nano-states";
@@ -32,7 +32,8 @@ export const StylePanel = ({ selectedInstance, publish }: StylePanelProps) => {
if (
currentStyle === undefined ||
selectedInstance === undefined ||
- breakpoint === undefined
+ breakpoint === undefined ||
+ canvasWidth === undefined
) {
return null;
}
diff --git a/apps/builder/app/builder/features/topbar/menu/menu.tsx b/apps/builder/app/builder/features/topbar/menu/menu.tsx
index ffcfd845d1..01af732c73 100644
--- a/apps/builder/app/builder/features/topbar/menu/menu.tsx
+++ b/apps/builder/app/builder/features/topbar/menu/menu.tsx
@@ -32,7 +32,6 @@ import { useIsPreviewMode } from "~/shared/nano-states";
import { deleteSelectedInstance } from "~/shared/instance-utils";
import { MenuButton } from "./menu-button";
import { useAuthPermit } from "~/shared/nano-states";
-import { zoomIn, zoomOut } from "~/shared/nano-states/breakpoints";
const ThemeMenuItem = () => {
if (isFeatureEnabled("dark") === false) {
@@ -181,18 +180,6 @@ export const Menu = ({ publish }: MenuProps) => {
<ShortcutHint value={["cmd", "b"]} />
</DropdownMenuItemRightSlot>
</DropdownMenuItem>
- <DropdownMenuItem onSelect={zoomIn}>
- Zoom in
- <DropdownMenuItemRightSlot>
- <ShortcutHint value={["+"]} />
- </DropdownMenuItemRightSlot>
- </DropdownMenuItem>
- <DropdownMenuItem onSelect={zoomOut}>
- Zoom out
- <DropdownMenuItemRightSlot>
- <ShortcutHint value={["-"]} />
- </DropdownMenuItemRightSlot>
- </DropdownMenuItem>
<DropdownMenuSeparator />
<ThemeMenuItem />
<ViewMenuItem />
diff --git a/apps/builder/app/builder/features/topbar/preview.tsx b/apps/builder/app/builder/features/topbar/preview.tsx
index e48bd9039a..8d63fbee17 100644
--- a/apps/builder/app/builder/features/topbar/preview.tsx
+++ b/apps/builder/app/builder/features/topbar/preview.tsx
@@ -1,5 +1,5 @@
import { PlayIcon } from "@webstudio-is/icons";
-import { ToolbarToggleItem, theme } from "@webstudio-is/design-system";
+import { ToolbarToggleItem } from "@webstudio-is/design-system";
import { useIsPreviewMode } from "~/shared/nano-states";
declare module "~/shared/pubsub" {
@@ -15,11 +15,7 @@ export const PreviewButton = () => {
<ToolbarToggleItem
value="preview"
aria-label="Toggle Preview"
- css={{
- color: isPreviewMode
- ? theme.colors.foregroundSuccess
- : theme.colors.foregroundContrastMain,
- }}
+ variant="preview"
onClick={() => setIsPreviewMode(isPreviewMode === false)}
tabIndex={0}
>
diff --git a/apps/builder/app/builder/features/topbar/topbar.tsx b/apps/builder/app/builder/features/topbar/topbar.tsx
index 54df4220b1..f82a7e9e3a 100644
--- a/apps/builder/app/builder/features/topbar/topbar.tsx
+++ b/apps/builder/app/builder/features/topbar/topbar.tsx
@@ -5,7 +5,6 @@ import {
Flex,
Text,
Toolbar,
- ToolbarSeparator,
ToolbarToggleGroup,
} from "@webstudio-is/design-system";
import type { Project } from "@webstudio-is/project";
@@ -16,14 +15,16 @@ import { ShareButton } from "./share";
import { PublishButton } from "./publish";
import { SyncStatus } from "./sync-status";
import { Menu } from "./menu";
-import { Breakpoints } from "../breakpoints";
+import { BreakpointsSelector, BreakpointsSettings } from "../breakpoints";
import { ViewMode } from "./view-mode";
const topbarContainerStyle = css({
+ display: "flex",
background: theme.colors.backgroundTopbar,
height: theme.spacing[15],
boxShadow: `inset 0 -1px 0 0 ${theme.colors.panelOutline}`,
paddingRight: theme.spacing[9],
+ color: theme.colors.foregroundContrastMain,
});
type TopbarProps = {
@@ -39,43 +40,40 @@ export const Topbar = ({ gridArea, project, publish }: TopbarProps) => {
}
return (
- <Toolbar className={topbarContainerStyle({ css: { gridArea } })}>
+ <nav className={topbarContainerStyle({ css: { gridArea } })}>
<Flex grow={false} shrink={false}>
<Menu publish={publish} />
- <ToolbarSeparator
- css={{
- // Workaround to prevent separator disappearing during menu animation
- zIndex: 0,
- }}
- />
</Flex>
- <Flex css={{ width: theme.spacing[30], px: theme.spacing[9] }}>
- <Text
- variant="labelsTitleCase"
- color="contrast"
- css={{ minWidth: theme.spacing[15], maxWidth: "80%" }}
- truncate
- >
+ <Flex
+ css={{ px: theme.spacing[9], maxWidth: theme.spacing[24] }}
+ align="center"
+ >
+ <Text variant="labelsTitleCase" color="contrast" truncate>
{page.name}
</Text>
</Flex>
+ <Flex css={{ minWidth: theme.spacing[23] }}>
+ <BreakpointsSettings />
+ </Flex>
<Flex grow align="center" justify="center">
- <Breakpoints />
+ <BreakpointsSelector />
</Flex>
- <ToolbarToggleGroup
- type="single"
- css={{
- justifyContent: "flex-end",
- gap: theme.spacing[5],
- width: theme.spacing[30],
- }}
- >
- <ViewMode />
- <SyncStatus />
- <PreviewButton />
- <ShareButton projectId={project.id} />
- <PublishButton project={project} />
- </ToolbarToggleGroup>
- </Toolbar>
+ <Toolbar>
+ <ToolbarToggleGroup
+ type="single"
+ css={{
+ justifyContent: "flex-end",
+ gap: theme.spacing[5],
+ width: theme.spacing[30],
+ }}
+ >
+ <ViewMode />
+ <SyncStatus />
+ <PreviewButton />
+ <ShareButton projectId={project.id} />
+ <PublishButton project={project} />
+ </ToolbarToggleGroup>
+ </Toolbar>
+ </nav>
);
};
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx
index 29f9efbbcb..83b7e4ce7b 100644
--- a/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx
+++ b/apps/builder/app/builder/features/workspace/canvas-tools/canvas-tools.tsx
@@ -5,7 +5,6 @@ import { PlacementIndicator } from "@webstudio-is/design-system";
import {
useIsPreviewMode,
useDragAndDropState,
- useSubscribeDragAndDropState,
instancesStore,
} from "~/shared/nano-states";
import { HoveredInstanceOutline, SelectedInstanceOutline } from "./outline";
@@ -13,6 +12,7 @@ import { TextToolbar } from "./text-toolbar";
import { useSubscribeSwitchPage } from "~/shared/pages";
import { Label } from "./outline/label";
import { Outline } from "./outline/outline";
+import { useSubscribeDragAndDropState } from "./use-subscribe-drag-drop-state";
const toolsStyle = {
position: "absolute",
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/outline/hovered-instance-outline.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/outline/hovered-instance-outline.tsx
index adb87392fb..423ac29cfa 100644
--- a/apps/builder/app/builder/features/workspace/canvas-tools/outline/hovered-instance-outline.tsx
+++ b/apps/builder/app/builder/features/workspace/canvas-tools/outline/hovered-instance-outline.tsx
@@ -2,12 +2,12 @@ import { useStore } from "@nanostores/react";
import {
hoveredInstanceSelectorStore,
selectedInstanceSelectorStore,
+ textEditingInstanceSelectorStore,
+ hoveredInstanceOutlineAndInstanceStore,
} from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
import { areInstanceSelectorsEqual } from "~/shared/tree-utils";
import { Outline } from "./outline";
import { Label } from "./label";
-import { hoveredInstanceOutlineAndInstanceStore } from "~/shared/nano-states/canvas";
export const HoveredInstanceOutline = () => {
const selectedInstanceSelector = useStore(selectedInstanceSelectorStore);
@@ -16,7 +16,6 @@ export const HoveredInstanceOutline = () => {
const textEditingInstanceSelector = useStore(
textEditingInstanceSelectorStore
);
-
const isEditingText = textEditingInstanceSelector !== undefined;
const isHoveringSelectedInstance = areInstanceSelectorsEqual(
selectedInstanceSelector,
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/outline/selected-instance-outline.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/outline/selected-instance-outline.tsx
index c1e6c76298..a73c60a4f6 100644
--- a/apps/builder/app/builder/features/workspace/canvas-tools/outline/selected-instance-outline.tsx
+++ b/apps/builder/app/builder/features/workspace/canvas-tools/outline/selected-instance-outline.tsx
@@ -1,24 +1,23 @@
import { useStore } from "@nanostores/react";
import { selectedInstanceSelectorStore } from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
-import { selectedInstanceOutlineAndInstanceStore } from "~/shared/nano-states/canvas";
+import { textEditingInstanceSelectorStore } from "~/shared/nano-states";
+import { selectedInstanceOutlineAndInstanceStore } from "~/shared/nano-states";
import { areInstanceSelectorsEqual } from "~/shared/tree-utils";
import { Outline } from "./outline";
import { Label } from "./label";
export const SelectedInstanceOutline = () => {
- const outline = useStore(selectedInstanceOutlineAndInstanceStore);
const selectedInstanceSelector = useStore(selectedInstanceSelectorStore);
const textEditingInstanceSelector = useStore(
textEditingInstanceSelectorStore
);
-
const isEditingCurrentInstance =
textEditingInstanceSelector !== undefined &&
areInstanceSelectorsEqual(
textEditingInstanceSelector,
selectedInstanceSelector
);
+ const outline = useStore(selectedInstanceOutlineAndInstanceStore);
if (isEditingCurrentInstance || outline === undefined) {
return null;
diff --git a/apps/builder/app/builder/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx b/apps/builder/app/builder/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx
index 98604e3970..4766ebb427 100644
--- a/apps/builder/app/builder/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx
+++ b/apps/builder/app/builder/features/workspace/canvas-tools/text-toolbar/text-toolbar.tsx
@@ -12,10 +12,7 @@ import {
PaintBrushIcon,
} from "@webstudio-is/icons";
import { selectedInstanceSelectorStore } from "~/shared/nano-states";
-import {
- type TextToolbarState,
- textToolbarStore,
-} from "~/shared/nano-states/canvas";
+import { type TextToolbarState, textToolbarStore } from "~/shared/nano-states";
import type { Publish } from "~/shared/pubsub";
type Format =
diff --git a/apps/builder/app/shared/nano-states/use-subscribe-drag-drop-state.ts b/apps/builder/app/builder/features/workspace/canvas-tools/use-subscribe-drag-drop-state.ts
similarity index 92%
rename from apps/builder/app/shared/nano-states/use-subscribe-drag-drop-state.ts
rename to apps/builder/app/builder/features/workspace/canvas-tools/use-subscribe-drag-drop-state.ts
index 6438290217..840ee09adb 100644
--- a/apps/builder/app/shared/nano-states/use-subscribe-drag-drop-state.ts
+++ b/apps/builder/app/builder/features/workspace/canvas-tools/use-subscribe-drag-drop-state.ts
@@ -1,5 +1,5 @@
import { useSubscribe } from "~/shared/pubsub";
-import { useDragAndDropState } from "./nano-states";
+import { useDragAndDropState } from "~/shared/nano-states";
export const useSubscribeDragAndDropState = () => {
const [state, setState] = useDragAndDropState();
diff --git a/apps/builder/app/builder/features/workspace/use-read-canvas-rect.ts b/apps/builder/app/builder/features/workspace/use-read-canvas-rect.ts
index ea0a9d538c..90bec53341 100644
--- a/apps/builder/app/builder/features/workspace/use-read-canvas-rect.ts
+++ b/apps/builder/app/builder/features/workspace/use-read-canvas-rect.ts
@@ -1,8 +1,11 @@
import { useCallback, useEffect, useState } from "react";
import { useStore } from "@nanostores/react";
-import { useCanvasRect, useCanvasWidth } from "~/builder/shared/nano-states";
+import {
+ scaleStore,
+ useCanvasRect,
+ useCanvasWidth,
+} from "~/builder/shared/nano-states";
import { useWindowResize } from "~/shared/dom-hooks";
-import { zoomStore } from "~/shared/nano-states/breakpoints";
/**
* Reads the canvas iframe dom rect and puts it into nano state
@@ -14,7 +17,7 @@ export const useReadCanvasRect = () => {
);
const [, setCanvasRect] = useCanvasRect();
const [canvasWidth] = useCanvasWidth();
- const zoom = useStore(zoomStore);
+ const scale = useStore(scaleStore);
const [recalcFlag, forceRecalc] = useState(false);
useWindowResize(() => {
forceRecalc(!recalcFlag);
@@ -32,7 +35,7 @@ export const useReadCanvasRect = () => {
},
// canvasWidth will change the canvas width, so we need to React it to it and update the rect, even though we don't necessary usenthe value
// eslint-disable-next-line react-hooks/exhaustive-deps
- [iframeElement, setCanvasRect, canvasWidth, zoom, recalcFlag]
+ [iframeElement, setCanvasRect, canvasWidth, scale, recalcFlag]
);
useEffect(readRect, [readRect]);
diff --git a/apps/builder/app/builder/features/workspace/workspace.tsx b/apps/builder/app/builder/features/workspace/workspace.tsx
index 496dc4a28d..f26d7fac8d 100644
--- a/apps/builder/app/builder/features/workspace/workspace.tsx
+++ b/apps/builder/app/builder/features/workspace/workspace.tsx
@@ -1,36 +1,31 @@
import { useStore } from "@nanostores/react";
-import { theme, Box, Flex, Toaster } from "@webstudio-is/design-system";
-import { useCanvasWidth } from "~/builder/shared/nano-states";
-import type { Publish } from "~/shared/pubsub";
-import { selectedInstanceSelectorStore } from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
+import { theme, Toaster, css } from "@webstudio-is/design-system";
import {
+ scaleStore,
+ useCanvasWidth,
workspaceRectStore,
- zoomStore,
-} from "~/shared/nano-states/breakpoints";
+} from "~/builder/shared/nano-states";
+import type { Publish } from "~/shared/pubsub";
+import { selectedInstanceSelectorStore } from "~/shared/nano-states";
+import { textEditingInstanceSelectorStore } from "~/shared/nano-states";
import { CanvasTools } from "./canvas-tools";
import { useMeasure } from "react-use";
import { useEffect } from "react";
+import { useSetInitialCanvasWidthOnce } from "../breakpoints";
-const workspaceStyle = {
+const workspaceStyle = css({
flexGrow: 1,
background: theme.colors.backgroundCanvas,
- overflow: "scroll",
position: "relative",
-};
-
-const zoomStyle = {
- transformStyle: "preserve-3d",
- transition: "transform 200ms ease-out",
- height: "100%",
- width: "100%",
-};
+ overflow: "hidden",
+});
-const canvasContainerStyle = {
+const canvasContainerStyle = css({
position: "relative",
- height: "100%",
overflow: "hidden",
-};
+ transformStyle: "preserve-3d",
+ transformOrigin: "0 0",
+});
const useSetWorkspaceRect = () => {
const workspaceRect = useStore(workspaceRectStore);
@@ -45,6 +40,37 @@ const useSetWorkspaceRect = () => {
return ref;
};
+const getCanvasStyle = (
+ scale: number,
+ workspaceRect?: DOMRect,
+ canvasWidth?: number
+) => {
+ let canvasHeight;
+ let canvasLeft;
+
+ if (workspaceRect?.height) {
+ canvasHeight = workspaceRect.height / (scale / 100);
+ }
+
+ if (workspaceRect?.width && canvasWidth) {
+ canvasLeft = Math.max((workspaceRect.width - canvasWidth) / 2, 0);
+ }
+
+ return {
+ width: canvasWidth,
+ height: canvasHeight ?? "100%",
+ left: canvasLeft ?? 0,
+ transform: `scale(${scale}%)`,
+ };
+};
+
+const useCanvasStyle = () => {
+ const scale = useStore(scaleStore);
+ const workspaceRect = useStore(workspaceRectStore);
+ const [canvasWidth] = useCanvasWidth();
+ return getCanvasStyle(scale, workspaceRect, canvasWidth);
+};
+
type WorkspaceProps = {
children: JSX.Element;
onTransitionEnd: () => void;
@@ -56,30 +82,29 @@ export const Workspace = ({
onTransitionEnd,
publish,
}: WorkspaceProps) => {
- const zoom = useStore(zoomStore);
- const [canvasWidth] = useCanvasWidth();
+ const canvasStyle = useCanvasStyle();
const workspaceRef = useSetWorkspaceRect();
-
+ useSetInitialCanvasWidthOnce();
const handleWorkspaceClick = () => {
selectedInstanceSelectorStore.set(undefined);
textEditingInstanceSelectorStore.set(undefined);
};
return (
- <Box css={workspaceStyle} onClick={handleWorkspaceClick} ref={workspaceRef}>
- <Flex
- direction="column"
- align="center"
- css={zoomStyle}
- style={{ transform: `scale(${zoom / 100})` }}
+ <div
+ className={workspaceStyle()}
+ onClick={handleWorkspaceClick}
+ ref={workspaceRef}
+ >
+ <div
+ className={canvasContainerStyle()}
+ style={canvasStyle}
onTransitionEnd={onTransitionEnd}
>
- <Box css={canvasContainerStyle} style={{ width: canvasWidth }}>
- {children}
- <CanvasTools publish={publish} />
- </Box>
- </Flex>
+ {children}
+ <CanvasTools publish={publish} />
+ </div>
<Toaster />
- </Box>
+ </div>
);
};
diff --git a/apps/builder/app/builder/shared/nano-states/index.ts b/apps/builder/app/builder/shared/nano-states/index.ts
index c0c1ddded1..5bf8a0d060 100644
--- a/apps/builder/app/builder/shared/nano-states/index.ts
+++ b/apps/builder/app/builder/shared/nano-states/index.ts
@@ -1,4 +1,4 @@
-import { atom, type WritableAtom } from "nanostores";
+import { atom, computed, type WritableAtom } from "nanostores";
import { useStore } from "@nanostores/react";
import type { Project } from "@webstudio-is/project";
@@ -14,7 +14,7 @@ const isPublishDialogOpenContainer = atom<boolean>(false);
export const useIsPublishDialogOpen = () =>
useValue(isPublishDialogOpenContainer);
-const canvasWidthContainer = atom<number>(0);
+const canvasWidthContainer = atom<number | undefined>();
export const useCanvasWidth = () => useValue(canvasWidthContainer);
const canvasRectContainer = atom<DOMRect | undefined>();
@@ -24,3 +24,21 @@ export const projectContainer = atom<Project | undefined>();
export const useProject = () => useValue(projectContainer);
export const isCanvasPointerEventsEnabledStore = atom<boolean>(true);
+
+export const workspaceRectStore = atom<DOMRect | undefined>();
+
+export const scaleStore = computed(
+ [canvasWidthContainer, workspaceRectStore],
+ (canvasWidth, workspaceRect) => {
+ if (
+ canvasWidth === undefined ||
+ workspaceRect === undefined ||
+ canvasWidth <= workspaceRect.width
+ ) {
+ return 100;
+ }
+ return Number.parseFloat(
+ ((workspaceRect.width / canvasWidth) * 100).toFixed(2)
+ );
+ }
+);
diff --git a/apps/builder/app/builder/shared/navigator-tree.tsx b/apps/builder/app/builder/shared/navigator-tree.tsx
index 99e7365f79..852131e121 100644
--- a/apps/builder/app/builder/shared/navigator-tree.tsx
+++ b/apps/builder/app/builder/shared/navigator-tree.tsx
@@ -7,8 +7,8 @@ import {
rootInstanceStore,
selectedInstanceSelectorStore,
useDragAndDropState,
+ textEditingInstanceSelectorStore,
} from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
import type { InstanceSelector } from "~/shared/tree-utils";
import { reparentInstance } from "~/shared/instance-utils";
import { InstanceTree } from "./tree";
diff --git a/apps/builder/app/canvas/canvas-shortcuts.ts b/apps/builder/app/canvas/canvas-shortcuts.ts
index 6e834efe17..80e0423142 100644
--- a/apps/builder/app/canvas/canvas-shortcuts.ts
+++ b/apps/builder/app/canvas/canvas-shortcuts.ts
@@ -2,10 +2,7 @@ import { useHotkeys } from "react-hotkeys-hook";
import { shortcuts, instanceTreeShortcuts, options } from "~/shared/shortcuts";
import { publish, useSubscribe } from "~/shared/pubsub";
import { isPreviewModeStore } from "~/shared/nano-states";
-import {
- enterEditingMode,
- escapeSelection,
-} from "~/shared/nano-states/instances";
+import { enterEditingMode, escapeSelection } from "~/shared/nano-states";
declare module "~/shared/pubsub" {
export interface PubsubMap {
diff --git a/apps/builder/app/canvas/collapsed.ts b/apps/builder/app/canvas/collapsed.ts
index 91aaa5266e..8d39307c12 100644
--- a/apps/builder/app/canvas/collapsed.ts
+++ b/apps/builder/app/canvas/collapsed.ts
@@ -5,11 +5,11 @@ import {
getPresetStyle,
} from "~/builder/features/style-panel/shared/style-info";
import {
- breakpointsContainer,
+ breakpointsStore,
instancesStore,
stylesIndexStore,
} from "~/shared/nano-states";
-import { selectedBreakpointStore } from "~/shared/nano-states/breakpoints";
+import { selectedBreakpointStore } from "~/shared/nano-states";
import { subscribe } from "~/shared/pubsub";
import htmlTags, { type htmlTags as HtmlTags } from "html-tags";
@@ -45,7 +45,7 @@ const replacedHtmlElements = ["IFRAME", "VIDEO", "EMBED", "IMG"];
const skipElementsSet = new Set([...voidHtmlElements, ...replacedHtmlElements]);
const getInstanceSize = (instanceId: string, tagName: HtmlTags | undefined) => {
- const breakpoints = breakpointsContainer.get();
+ const breakpoints = breakpointsStore.get();
const selectedBreakpoint = selectedBreakpointStore.get();
const { stylesByInstanceId } = stylesIndexStore.get();
const instances = instancesStore.get();
diff --git a/apps/builder/app/canvas/features/text-editor/text-editor.stories.tsx b/apps/builder/app/canvas/features/text-editor/text-editor.stories.tsx
index af8153558e..9056918230 100644
--- a/apps/builder/app/canvas/features/text-editor/text-editor.stories.tsx
+++ b/apps/builder/app/canvas/features/text-editor/text-editor.stories.tsx
@@ -10,7 +10,7 @@ import type {
InstancesItem,
} from "@webstudio-is/project-build";
import { publish } from "~/shared/pubsub";
-import { textToolbarStore } from "~/shared/nano-states/canvas";
+import { textToolbarStore } from "~/shared/nano-states";
import { TextEditor } from "./text-editor";
export default {
diff --git a/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx b/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
index 73459ffa48..4c204ec822 100644
--- a/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
+++ b/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
@@ -14,7 +14,7 @@ import { $patchStyleText } from "@lexical/selection";
import { LinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { useSubscribe } from "~/shared/pubsub";
-import { textToolbarStore } from "~/shared/nano-states/canvas";
+import { textToolbarStore } from "~/shared/nano-states";
import { subscribeScrollState } from "~/canvas/shared/scroll-state";
const spanTriggerName = "--style-node-trigger";
diff --git a/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts b/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts
index 5faa3caa84..7ecc8cbe5b 100644
--- a/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts
+++ b/apps/builder/app/canvas/features/webstudio-component/selected-instance-connector.ts
@@ -12,7 +12,7 @@ import {
import htmlTags, { type htmlTags as HtmlTags } from "html-tags";
import { getAllElementsBoundingBox } from "~/shared/dom-utils";
import { subscribeScrollState } from "~/canvas/shared/scroll-state";
-import { selectedInstanceOutlineStore } from "~/shared/nano-states/canvas";
+import { selectedInstanceOutlineStore } from "~/shared/nano-states";
const isHtmlTag = (tag: string): tag is HtmlTags =>
htmlTags.includes(tag as HtmlTags);
diff --git a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx
index c72bd21c8b..1b95fa60c5 100644
--- a/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx
+++ b/apps/builder/app/canvas/features/webstudio-component/webstudio-component.tsx
@@ -21,7 +21,7 @@ import {
useInstanceProps,
useInstanceStyles,
} from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
+import { textEditingInstanceSelectorStore } from "~/shared/nano-states";
import { useCssRules } from "~/canvas/shared/styles";
import {
type InstanceSelector,
diff --git a/apps/builder/app/canvas/instance-hovering.ts b/apps/builder/app/canvas/instance-hovering.ts
index 9d772ea2b2..e12b57ed37 100644
--- a/apps/builder/app/canvas/instance-hovering.ts
+++ b/apps/builder/app/canvas/instance-hovering.ts
@@ -4,7 +4,7 @@ import {
hoveredInstanceSelectorStore,
instancesStore,
} from "~/shared/nano-states";
-import { hoveredInstanceOutlineStore } from "~/shared/nano-states/canvas";
+import { hoveredInstanceOutlineStore } from "~/shared/nano-states";
import {
getAllElementsBoundingBox,
getElementByInstanceSelector,
diff --git a/apps/builder/app/canvas/instance-selection.ts b/apps/builder/app/canvas/instance-selection.ts
index a29dc5586a..7f8a8fba84 100644
--- a/apps/builder/app/canvas/instance-selection.ts
+++ b/apps/builder/app/canvas/instance-selection.ts
@@ -4,7 +4,7 @@ import {
instancesStore,
selectedInstanceSelectorStore,
} from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
+import { textEditingInstanceSelectorStore } from "~/shared/nano-states";
import { publish } from "~/shared/pubsub";
import {
type InstanceSelector,
diff --git a/apps/builder/app/canvas/shared/styles.ts b/apps/builder/app/canvas/shared/styles.ts
index 8018fc093b..01e1494552 100644
--- a/apps/builder/app/canvas/shared/styles.ts
+++ b/apps/builder/app/canvas/shared/styles.ts
@@ -22,9 +22,9 @@ import {
} from "@webstudio-is/css-data";
import {
assetsStore,
+ breakpointsStore,
isPreviewModeStore,
selectedInstanceSelectorStore,
- useBreakpoints,
} from "~/shared/nano-states";
import {
createCssEngine,
@@ -39,7 +39,7 @@ const helpersCssEngine = createCssEngine({ name: "helpers" });
const fontsAndDefaultsCssEngine = createCssEngine({
name: "fonts-and-defaults",
});
-const presetStylesEngine = createCssEngine({ name: "presetStyles" });
+const presetStylesEngine = createCssEngine({ name: "preset-styles" });
// Helper styles on for canvas in design mode
// - Only instances that would collapse without helper should receive helper
@@ -113,7 +113,7 @@ export const useManageDesignModeStyles = () => {
};
export const GlobalStyles = () => {
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
const assets = useStore(assetsStore);
useIsomorphicLayoutEffect(() => {
@@ -216,7 +216,7 @@ export const useCssRules = ({
instanceId: string;
instanceStyles: StyleDecl[];
}) => {
- const [breakpoints] = useBreakpoints();
+ const breakpoints = useStore(breakpointsStore);
useIsomorphicLayoutEffect(() => {
const stylePerBreakpoint = new Map<string, Style>();
diff --git a/apps/builder/app/canvas/shared/use-drag-drop.ts b/apps/builder/app/canvas/shared/use-drag-drop.ts
index 3614638ed5..b62cc47046 100644
--- a/apps/builder/app/canvas/shared/use-drag-drop.ts
+++ b/apps/builder/app/canvas/shared/use-drag-drop.ts
@@ -11,7 +11,7 @@ import {
} from "@webstudio-is/design-system";
import { getComponentMeta } from "@webstudio-is/react-sdk";
import { instancesStore, selectedPageStore } from "~/shared/nano-states";
-import { textEditingInstanceSelectorStore } from "~/shared/nano-states/instances";
+import { textEditingInstanceSelectorStore } from "~/shared/nano-states";
import { publish, useSubscribe } from "~/shared/pubsub";
import {
insertNewComponentInstance,
diff --git a/apps/builder/app/shared/breakpoints/group-breakpoints.test.ts b/apps/builder/app/shared/breakpoints/group-breakpoints.test.ts
new file mode 100644
index 0000000000..64bbd06e8c
--- /dev/null
+++ b/apps/builder/app/shared/breakpoints/group-breakpoints.test.ts
@@ -0,0 +1,26 @@
+import { describe, test, expect } from "@jest/globals";
+import { groupBreakpoints } from "./group-breakpoints";
+
+describe("Group breakpoints", () => {
+ test("for ui", () => {
+ const initial = [
+ { minWidth: 1920 },
+ { minWidth: 1440 },
+ { minWidth: 1280 },
+ {},
+ { maxWidth: 991 },
+ { maxWidth: 767 },
+ { maxWidth: 479 },
+ ];
+ const grouped = [
+ { minWidth: 1920 },
+ { minWidth: 1440 },
+ { minWidth: 1280 },
+ {},
+ { maxWidth: 991 },
+ { maxWidth: 767 },
+ { maxWidth: 479 },
+ ];
+ expect(groupBreakpoints(initial)).toStrictEqual(grouped);
+ });
+});
diff --git a/apps/builder/app/shared/breakpoints/group-breakpoints.ts b/apps/builder/app/shared/breakpoints/group-breakpoints.ts
new file mode 100644
index 0000000000..b703b1c6ad
--- /dev/null
+++ b/apps/builder/app/shared/breakpoints/group-breakpoints.ts
@@ -0,0 +1,17 @@
+import { compareMedia } from "@webstudio-is/css-engine";
+import { isBaseBreakpoint } from "./is-base-breakpoint";
+
+// We group in 3 groups: min-width, base (no min/max), max-width conditions
+export const groupBreakpoints = <
+ Breakpoint extends { minWidth?: number; maxWidth?: number }
+>(
+ breakpoints: Array<Breakpoint>
+) => {
+ const sorted = breakpoints.sort(compareMedia);
+ const maxs = sorted.filter((breakpoint) => breakpoint.maxWidth !== undefined);
+ const mins = sorted
+ .filter((breakpoint) => breakpoint.minWidth !== undefined)
+ .reverse();
+ const base = sorted.filter(isBaseBreakpoint);
+ return [...mins, ...base, ...maxs];
+};
diff --git a/apps/builder/app/shared/breakpoints/index.ts b/apps/builder/app/shared/breakpoints/index.ts
new file mode 100644
index 0000000000..fa3dc47a41
--- /dev/null
+++ b/apps/builder/app/shared/breakpoints/index.ts
@@ -0,0 +1,3 @@
+export * from "./is-base-breakpoint";
+export * from "./select-breakpoint-by-order";
+export * from "./group-breakpoints";
diff --git a/apps/builder/app/shared/breakpoints/is-base-breakpoint.ts b/apps/builder/app/shared/breakpoints/is-base-breakpoint.ts
new file mode 100644
index 0000000000..9efe78db9c
--- /dev/null
+++ b/apps/builder/app/shared/breakpoints/is-base-breakpoint.ts
@@ -0,0 +1,4 @@
+export const isBaseBreakpoint = (breakpoint: {
+ minWidth?: number;
+ maxWidth?: number;
+}) => breakpoint.minWidth === undefined && breakpoint.maxWidth === undefined;
diff --git a/apps/builder/app/shared/breakpoints/select-breakpoint-by-order.ts b/apps/builder/app/shared/breakpoints/select-breakpoint-by-order.ts
new file mode 100644
index 0000000000..7ec92d231b
--- /dev/null
+++ b/apps/builder/app/shared/breakpoints/select-breakpoint-by-order.ts
@@ -0,0 +1,16 @@
+import { groupBreakpoints } from ".";
+import { selectedBreakpointIdStore, breakpointsStore } from "../nano-states";
+
+/**
+ * Order number starts with 1 and covers all existing breakpoints
+ */
+export const selectBreakpointByOrder = (orderNumber: number) => {
+ const breakpoints = breakpointsStore.get();
+ const index = orderNumber - 1;
+ const breakpoint = groupBreakpoints(Array.from(breakpoints.values())).at(
+ index
+ );
+ if (breakpoint) {
+ selectedBreakpointIdStore.set(breakpoint.id);
+ }
+};
diff --git a/apps/builder/app/shared/copy-paste/plugin-instance.ts b/apps/builder/app/shared/copy-paste/plugin-instance.ts
index d09170d33b..b20b98fcf7 100644
--- a/apps/builder/app/shared/copy-paste/plugin-instance.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-instance.ts
@@ -19,7 +19,7 @@ import {
styleSourcesStore,
instancesStore,
selectedPageStore,
- breakpointsContainer,
+ breakpointsStore,
} from "../nano-states";
import {
type InstanceSelector,
@@ -106,7 +106,7 @@ const getTreeData = (targetInstanceSelector: InstanceSelector) => {
treeBreapointIds.add(styleDecl.breakpointId);
}
const treeBreapoints = getMapValuesByKeysSet(
- breakpointsContainer.get(),
+ breakpointsStore.get(),
treeBreapointIds
);
@@ -153,7 +153,7 @@ export const onPaste = (clipboardData: string) => {
);
store.createTransaction(
[
- breakpointsContainer,
+ breakpointsStore,
instancesStore,
styleSourcesStore,
propsStore,
diff --git a/apps/builder/app/shared/nano-states/breakpoints.ts b/apps/builder/app/shared/nano-states/breakpoints.ts
index 7070de52ef..4fcba76336 100644
--- a/apps/builder/app/shared/nano-states/breakpoints.ts
+++ b/apps/builder/app/shared/nano-states/breakpoints.ts
@@ -1,58 +1,34 @@
import { atom, computed } from "nanostores";
-import type { Breakpoint } from "@webstudio-is/project-build";
-import { breakpointsContainer } from "./nano-states";
-import { compareMedia } from "@webstudio-is/css-engine";
+import type { Breakpoint, Breakpoints } from "@webstudio-is/project-build";
+import { isBaseBreakpoint } from "../breakpoints";
-export const minZoom = 10;
-const maxZoom = 100;
-const zoomStep = 20;
-
-export const zoomStore = atom<number>(100);
-
-export const zoomIn = () => {
- zoomStore.set(Math.min(zoomStore.get() + zoomStep, maxZoom));
-};
-
-export const zoomOut = () => {
- zoomStore.set(Math.max(zoomStore.get() - zoomStep, minZoom));
-};
+export const breakpointsStore = atom<Breakpoints>(new Map());
export const selectedBreakpointIdStore = atom<undefined | Breakpoint["id"]>(
undefined
);
export const selectedBreakpointStore = computed(
- [breakpointsContainer, selectedBreakpointIdStore],
+ [breakpointsStore, selectedBreakpointIdStore],
(breakpoints, selectedBreakpointId) => {
- const matchedBreakpoint =
+ const selectedBreakpoint =
selectedBreakpointId === undefined
? undefined
: breakpoints.get(selectedBreakpointId);
- // initially set first breakpoint as selected breakpoint
- const fallbackBreakpoint = Array.from(breakpoints.values())
- .sort(compareMedia)
- .at(0);
- return matchedBreakpoint ?? fallbackBreakpoint;
- }
-);
-/**
- * order number starts with 1 and covers all existing breakpoints
- */
-export const selectBreakpointByOrderNumber = (orderNumber: number) => {
- const breakpoints = breakpointsContainer.get();
- const index = orderNumber - 1;
- const breakpoint = Array.from(breakpoints.values())
- .sort(compareMedia)
- .at(index);
- if (breakpoint) {
- selectedBreakpointIdStore.set(breakpoint.id);
+ if (breakpoints.size === 0) {
+ return;
+ }
+ const breakpointsArray = Array.from(breakpoints.values());
+ return (
+ selectedBreakpoint ??
+ breakpointsArray.find(isBaseBreakpoint) ??
+ breakpointsArray[0] ??
+ undefined
+ );
}
-};
+);
export const synchronizedBreakpointsStores = [
- ["zoomStore", zoomStore],
["selectedBreakpointId", selectedBreakpointIdStore],
] as const;
-
-export const workspaceRectStore = atom<DOMRect | undefined>();
diff --git a/apps/builder/app/shared/nano-states/canvas.ts b/apps/builder/app/shared/nano-states/canvas.ts
index 0e90dcabc9..4fdc3160aa 100644
--- a/apps/builder/app/shared/nano-states/canvas.ts
+++ b/apps/builder/app/shared/nano-states/canvas.ts
@@ -1,6 +1,6 @@
import { atom, computed } from "nanostores";
import type { Instance, Instances } from "@webstudio-is/project-build";
-import { instancesStore } from "./nano-states";
+import { instancesStore } from "./instances";
export type TextToolbarState = {
selectionRect: undefined | DOMRect;
diff --git a/apps/builder/app/shared/nano-states/index.ts b/apps/builder/app/shared/nano-states/index.ts
index a1a7e5a60b..f355396f68 100644
--- a/apps/builder/app/shared/nano-states/index.ts
+++ b/apps/builder/app/shared/nano-states/index.ts
@@ -1,2 +1,5 @@
export * from "./nano-states";
-export * from "./use-subscribe-drag-drop-state";
+export * from "./breakpoints";
+export * from "./instances";
+export * from "./canvas";
+export * from "./pages";
diff --git a/apps/builder/app/shared/nano-states/instances.ts b/apps/builder/app/shared/nano-states/instances.ts
index 4fb8792d8b..d317b02c51 100644
--- a/apps/builder/app/shared/nano-states/instances.ts
+++ b/apps/builder/app/shared/nano-states/instances.ts
@@ -1,12 +1,18 @@
-import { atom } from "nanostores";
+import { atom, computed } from "nanostores";
import { getComponentMeta } from "@webstudio-is/react-sdk";
-
-import type { InstanceSelector } from "../tree-utils";
-import {
- selectedInstanceSelectorStore,
- selectedInstanceStore,
-} from "./nano-states";
+import type {
+ Instance,
+ Instances,
+ InstancesItem,
+} from "@webstudio-is/project-build";
+import { createInstancesIndex, type InstanceSelector } from "../tree-utils";
import { getElementByInstanceSelector } from "../dom-utils";
+import { useSyncInitializeOnce } from "../hook-utils";
+import { selectedPageStore } from "./pages";
+
+export const selectedInstanceSelectorStore = atom<undefined | InstanceSelector>(
+ undefined
+);
export const textEditingInstanceSelectorStore = atom<
undefined | InstanceSelector
@@ -56,6 +62,75 @@ export const escapeSelection = () => {
selectedInstanceSelectorStore.set(undefined);
};
+export const instancesStore = atom<Map<InstancesItem["id"], InstancesItem>>(
+ new Map()
+);
+export const useSetInstances = (
+ instances: [InstancesItem["id"], InstancesItem][]
+) => {
+ useSyncInitializeOnce(() => {
+ instancesStore.set(new Map(instances));
+ });
+};
+
+// @todo will be removed soon
+const denormalizeTree = (
+ instances: Instances,
+ rootInstanceId: Instance["id"]
+): undefined | Instance => {
+ const convertTree = (instance: InstancesItem) => {
+ const legacyInstance: Instance = {
+ type: "instance",
+ id: instance.id,
+ component: instance.component,
+ label: instance.label,
+ children: [],
+ };
+ for (const child of instance.children) {
+ if (child.type === "id") {
+ const childInstance = instances.get(child.value);
+ if (childInstance) {
+ legacyInstance.children.push(convertTree(childInstance));
+ }
+ } else {
+ legacyInstance.children.push(child);
+ }
+ }
+ return legacyInstance;
+ };
+ const rootInstance = instances.get(rootInstanceId);
+ if (rootInstance === undefined) {
+ return;
+ }
+ return convertTree(rootInstance);
+};
+
+export const rootInstanceContainer = computed(
+ [instancesStore, selectedPageStore],
+ (instances, selectedPage) => {
+ if (selectedPage === undefined) {
+ return undefined;
+ }
+ return denormalizeTree(instances, selectedPage.rootInstanceId);
+ }
+);
+
+export const instancesIndexStore = computed(
+ rootInstanceContainer,
+ createInstancesIndex
+);
+
+export const selectedInstanceStore = computed(
+ [instancesIndexStore, selectedInstanceSelectorStore],
+ (instancesIndex, selectedInstanceSelector) => {
+ if (selectedInstanceSelector === undefined) {
+ return;
+ }
+ const [selectedInstanceId] = selectedInstanceSelector;
+ return instancesIndex.instancesById.get(selectedInstanceId);
+ }
+);
+
export const synchronizedInstancesStores = [
["textEditingInstanceSelector", textEditingInstanceSelectorStore],
] as const;
diff --git a/apps/builder/app/shared/nano-states/nano-states.ts b/apps/builder/app/shared/nano-states/nano-states.ts
index 28b8704582..f92f3d4a29 100644
--- a/apps/builder/app/shared/nano-states/nano-states.ts
+++ b/apps/builder/app/shared/nano-states/nano-states.ts
@@ -7,12 +7,7 @@ import type { Asset, Assets } from "@webstudio-is/asset-uploader";
import type { ItemDropTarget, Placement } from "@webstudio-is/design-system";
import type {
Breakpoint,
- Breakpoints,
Instance,
- Instances,
- InstancesItem,
- Page,
- Pages,
Prop,
Props,
StyleDecl,
@@ -27,52 +22,21 @@ import type { Style } from "@webstudio-is/css-data";
import type { DragStartPayload } from "~/canvas/shared/use-drag-drop";
import { useSyncInitializeOnce } from "../hook-utils";
import { shallowComputed } from "../store-utils";
-import { createInstancesIndex, type InstanceSelector } from "../tree-utils";
+import { type InstanceSelector } from "../tree-utils";
import type { htmlTags as HtmlTags } from "html-tags";
+import { breakpointsStore } from "./breakpoints";
+import {
+ instancesStore,
+ rootInstanceContainer,
+ selectedInstanceSelectorStore,
+} from "./instances";
+import { selectedPageStore } from "./pages";
const useValue = <T>(atom: WritableAtom<T>) => {
const value = useStore(atom);
return [value, atom.set] as const;
};
-export const pagesStore = atom<undefined | Pages>(undefined);
-export const useSetPages = (pages: Pages) => {
- useSyncInitializeOnce(() => {
- pagesStore.set(pages);
- });
-};
-
-export const selectedPageIdStore = atom<undefined | Page["id"]>(undefined);
-export const useSetSelectedPageId = (pageId: Page["id"]) => {
- useSyncInitializeOnce(() => {
- selectedPageIdStore.set(pageId);
- });
-};
-
-export const selectedPageStore = computed(
- [pagesStore, selectedPageIdStore],
- (pages, selectedPageId) => {
- if (pages === undefined) {
- return undefined;
- }
- if (pages.homePage.id === selectedPageId) {
- return pages.homePage;
- }
- return pages.pages.find((page) => page.id === selectedPageId);
- }
-);
-
-export const instancesStore = atom<Map<InstancesItem["id"], InstancesItem>>(
- new Map()
-);
-export const useSetInstances = (
- instances: [InstancesItem["id"], InstancesItem][]
-) => {
- useSyncInitializeOnce(() => {
- instancesStore.set(new Map(instances));
- });
-};
-
export const rootInstanceStore = computed(
[instancesStore, selectedPageStore],
(instances, selectedPage) => {
@@ -83,55 +47,10 @@ export const rootInstanceStore = computed(
}
);
-// @todo will be removed soon
-const denormalizeTree = (
- instances: Instances,
- rootInstanceId: Instance["id"]
-): undefined | Instance => {
- const convertTree = (instance: InstancesItem) => {
- const legacyInstance: Instance = {
- type: "instance",
- id: instance.id,
- component: instance.component,
- label: instance.label,
- children: [],
- };
- for (const child of instance.children) {
- if (child.type === "id") {
- const childInstance = instances.get(child.value);
- if (childInstance) {
- legacyInstance.children.push(convertTree(childInstance));
- }
- } else {
- legacyInstance.children.push(child);
- }
- }
- return legacyInstance;
- };
- const rootInstance = instances.get(rootInstanceId);
- if (rootInstance === undefined) {
- return;
- }
- return convertTree(rootInstance);
-};
-
-export const rootInstanceContainer = computed(
- [instancesStore, selectedPageStore],
- (instances, selectedPage) => {
- if (selectedPage === undefined) {
- return undefined;
- }
- return denormalizeTree(instances, selectedPage.rootInstanceId);
- }
-);
export const useRootInstance = () => {
const value = useStore(rootInstanceContainer);
return [value] as const;
};
-export const instancesIndexStore = computed(
- rootInstanceContainer,
- createInstancesIndex
-);
export const propsStore = atom<Props>(new Map());
export const propsIndexStore = computed(propsStore, (props) => {
@@ -276,13 +195,11 @@ export const stylesIndexStore = computed(
}
);
-export const breakpointsContainer = atom<Breakpoints>(new Map());
-export const useBreakpoints = () => useValue(breakpointsContainer);
export const useSetBreakpoints = (
breakpoints: [Breakpoint["id"], Breakpoint][]
) => {
useSyncInitializeOnce(() => {
- breakpointsContainer.set(new Map(breakpoints));
+ breakpointsStore.set(new Map(breakpoints));
});
};
@@ -293,21 +210,6 @@ export const useSetAssets = (assets: [Asset["id"], Asset][]) => {
});
};
-export const selectedInstanceSelectorStore = atom<undefined | InstanceSelector>(
- undefined
-);
-
-export const selectedInstanceStore = computed(
- [instancesIndexStore, selectedInstanceSelectorStore],
- (instancesIndex, selectedInstanceSelector) => {
- if (selectedInstanceSelector === undefined) {
- return;
- }
- const [selectedInstanceId] = selectedInstanceSelector;
- return instancesIndex.instancesById.get(selectedInstanceId);
- }
-);
-
export const selectedInstanceBrowserStyleStore = atom<undefined | Style>();
/**
diff --git a/apps/builder/app/shared/nano-states/pages.ts b/apps/builder/app/shared/nano-states/pages.ts
new file mode 100644
index 0000000000..113a5d1cd0
--- /dev/null
+++ b/apps/builder/app/shared/nano-states/pages.ts
@@ -0,0 +1,30 @@
+import { atom, computed } from "nanostores";
+import type { Page, Pages } from "@webstudio-is/project-build";
+import { useSyncInitializeOnce } from "../hook-utils";
+
+export const pagesStore = atom<undefined | Pages>(undefined);
+export const useSetPages = (pages: Pages) => {
+ useSyncInitializeOnce(() => {
+ pagesStore.set(pages);
+ });
+};
+
+export const selectedPageIdStore = atom<undefined | Page["id"]>(undefined);
+export const useSetSelectedPageId = (pageId: Page["id"]) => {
+ useSyncInitializeOnce(() => {
+ selectedPageIdStore.set(pageId);
+ });
+};
+
+export const selectedPageStore = computed(
+ [pagesStore, selectedPageIdStore],
+ (pages, selectedPageId) => {
+ if (pages === undefined) {
+ return undefined;
+ }
+ if (pages.homePage.id === selectedPageId) {
+ return pages.homePage;
+ }
+ return pages.pages.find((page) => page.id === selectedPageId);
+ }
+);
diff --git a/apps/builder/app/shared/shortcuts/shortcuts.ts b/apps/builder/app/shared/shortcuts/shortcuts.ts
index a7ef5bff42..b0d30cb3a0 100644
--- a/apps/builder/app/shared/shortcuts/shortcuts.ts
+++ b/apps/builder/app/shared/shortcuts/shortcuts.ts
@@ -1,11 +1,7 @@
import { type Options, useHotkeys } from "react-hotkeys-hook";
import store from "immerhin";
-import {
- zoomIn,
- zoomOut,
- selectBreakpointByOrderNumber,
-} from "../nano-states/breakpoints";
import { deleteSelectedInstance } from "../instance-utils";
+import { selectBreakpointByOrder } from "../breakpoints";
export const shortcuts = {
esc: "esc",
@@ -46,49 +42,13 @@ export const useSharedShortcuts = () => {
[]
);
- useHotkeys(
- "equal",
- zoomIn,
- // prevent zoom while typing
- { enableOnFormTags: false, enableOnContentEditable: false },
- []
- );
-
- useHotkeys(
- "meta+shift+equal",
- (event) => {
- event.preventDefault();
- zoomIn();
- },
- { enableOnFormTags: true, enableOnContentEditable: true },
- []
- );
-
- useHotkeys(
- "minus",
- zoomOut,
- // prevent zoom while typing
- { enableOnFormTags: false, enableOnContentEditable: false },
- []
- );
-
- useHotkeys(
- "meta+shift+minus",
- (event) => {
- event.preventDefault();
- zoomOut();
- },
- { enableOnFormTags: true, enableOnContentEditable: true },
- []
- );
-
const breakpointShortcuts = Array.from(new Array(9))
.map((_, index) => `meta+${index + 1}, ctrl+${index + 1}`)
.join(", ");
useHotkeys(
breakpointShortcuts,
(event) => {
- selectBreakpointByOrderNumber(Number.parseInt(event.key, 10));
+ selectBreakpointByOrder(Number.parseInt(event.key, 10));
},
{ enableOnFormTags: true, enableOnContentEditable: true },
[]
diff --git a/apps/builder/app/shared/sync/sync-stores.ts b/apps/builder/app/shared/sync/sync-stores.ts
index 034a81f7c2..41a79da850 100644
--- a/apps/builder/app/shared/sync/sync-stores.ts
+++ b/apps/builder/app/shared/sync/sync-stores.ts
@@ -7,7 +7,7 @@ import {
pagesStore,
instancesStore,
propsStore,
- breakpointsContainer,
+ breakpointsStore,
stylesStore,
styleSourcesStore,
styleSourceSelectionsStore,
@@ -18,10 +18,10 @@ import {
selectedInstanceIntanceToTagStore,
hoveredInstanceSelectorStore,
isPreviewModeStore,
+ synchronizedCanvasStores,
+ synchronizedInstancesStores,
+ synchronizedBreakpointsStores,
} from "~/shared/nano-states";
-import { synchronizedBreakpointsStores } from "~/shared/nano-states/breakpoints";
-import { synchronizedInstancesStores } from "~/shared/nano-states/instances";
-import { synchronizedCanvasStores } from "~/shared/nano-states/canvas";
enableMapSet();
@@ -53,7 +53,7 @@ const clientStores = new Map<string, WritableAtom<unknown>>();
export const registerContainers = () => {
// synchronize patches
store.register("pages", pagesStore);
- store.register("breakpoints", breakpointsContainer);
+ store.register("breakpoints", breakpointsStore);
store.register("instances", instancesStore);
store.register("styles", stylesStore);
store.register("styleSources", styleSourcesStore);
diff --git a/apps/builder/docs/test-cases.md b/apps/builder/docs/test-cases.md
index 43a72e1051..7a39ee29f3 100644
--- a/apps/builder/docs/test-cases.md
+++ b/apps/builder/docs/test-cases.md
@@ -64,9 +64,6 @@
1. Breakpoints
- Clicking on different breakpoints resizes the canvas
- - Canvas width slider lets you resize canvas only within its bounds
- - Zoom slider works
- - Hovering over breakpoints with the mouse shows the right one in preview
- Click on Edit breakpoints shows you breakpoints editor
- lets you change the breakpoint min-width value and it gets applied immediately on the canvas and on the width slider constraint
- adding a new breakpoint adds it, lets you specify the value, works like every other breakpoint
@@ -77,7 +74,6 @@
- Click anywhere outside of breakpoints closes breakpoints selector
- Click on the canvas closes breakpoints selector
- Styles added on each breakpoint are only applied to each breakpoint, verify that by resizing the canvas in preview mode
- - Resizing canvas width in preview mode doesn't limit resize slider to each breakpoint
1. Auth
diff --git a/packages/asset-uploader/src/utils/to-bytes.ts b/packages/asset-uploader/src/utils/to-bytes.ts
index 7d187f6830..06d3a4ff7e 100644
--- a/packages/asset-uploader/src/utils/to-bytes.ts
+++ b/packages/asset-uploader/src/utils/to-bytes.ts
@@ -1,2 +1,2 @@
// Convert a string value in assumed MB to bytes number
-export const toBytes = (value: string) => parseFloat(value) * 1e6;
+export const toBytes = (value: string) => Number.parseFloat(value) * 1e6;
diff --git a/packages/css-engine/src/core/compare-media.test.ts b/packages/css-engine/src/core/compare-media.test.ts
index 58d01b6a4c..2ae9c4838f 100644
--- a/packages/css-engine/src/core/compare-media.test.ts
+++ b/packages/css-engine/src/core/compare-media.test.ts
@@ -20,6 +20,7 @@ describe("Compare media", () => {
test("webflow", () => {
const initial = [
+ {},
{ maxWidth: 991 },
{ maxWidth: 767 },
{ maxWidth: 479 },
@@ -28,6 +29,7 @@ describe("Compare media", () => {
{ minWidth: 1920 },
];
const sorted = [
+ {},
{ maxWidth: 991 },
{ maxWidth: 767 },
{ maxWidth: 479 },
diff --git a/packages/css-engine/src/core/compare-media.ts b/packages/css-engine/src/core/compare-media.ts
index 922459c551..a023dc0a1f 100644
--- a/packages/css-engine/src/core/compare-media.ts
+++ b/packages/css-engine/src/core/compare-media.ts
@@ -8,11 +8,22 @@ export const compareMedia = (
optionA: MediaRuleOptions,
optionB: MediaRuleOptions
) => {
+ // Ensures a media with no min/max is always first
+ if (
+ (optionA?.minWidth === undefined && optionA?.maxWidth !== undefined) ||
+ (optionB?.minWidth === undefined && optionB?.maxWidth !== undefined)
+ ) {
+ return 1;
+ }
+ // Both are defined by minWidth, put the bigger one first
if (optionA?.minWidth !== undefined && optionB?.minWidth !== undefined) {
return optionA.minWidth - optionB.minWidth;
}
+ // Both are defined by maxWidth, put the smaller one first
if (optionA?.maxWidth !== undefined && optionB?.maxWidth !== undefined) {
return optionB.maxWidth - optionA.maxWidth;
}
+
+ // Media with maxWith should render before minWith just to have the same sorting visually in the UI as in CSSOM.
return "minWidth" in optionA ? 1 : -1;
};
diff --git a/packages/css-engine/src/core/find-applicable-media.test.ts b/packages/css-engine/src/core/find-applicable-media.test.ts
new file mode 100644
index 0000000000..8c04fd96e9
--- /dev/null
+++ b/packages/css-engine/src/core/find-applicable-media.test.ts
@@ -0,0 +1,43 @@
+import { describe, test, expect } from "@jest/globals";
+import { findApplicableMedia } from "./find-applicable-media";
+
+const media = [
+ {},
+ { maxWidth: 991 },
+ { maxWidth: 767 },
+ { maxWidth: 479 },
+ { minWidth: 1280 },
+ { minWidth: 1440 },
+ { minWidth: 1920 },
+];
+
+describe("Find applicable media", () => {
+ test("200", () => {
+ expect(findApplicableMedia([...media], 200)).toStrictEqual({
+ maxWidth: 479,
+ });
+ });
+ test("479", () => {
+ expect(findApplicableMedia([...media], 479)).toStrictEqual({
+ maxWidth: 479,
+ });
+ });
+ test("480", () => {
+ expect(findApplicableMedia([...media], 480)).toStrictEqual({
+ maxWidth: 767,
+ });
+ });
+ test("1279", () => {
+ expect(findApplicableMedia([...media], 1279)).toStrictEqual({});
+ });
+ test("1280", () => {
+ expect(findApplicableMedia([...media], 1280)).toStrictEqual({
+ minWidth: 1280,
+ });
+ });
+ test("1440", () => {
+ expect(findApplicableMedia([...media], 1440)).toStrictEqual({
+ minWidth: 1440,
+ });
+ });
+});
diff --git a/packages/css-engine/src/core/find-applicable-media.ts b/packages/css-engine/src/core/find-applicable-media.ts
new file mode 100644
index 0000000000..18d8a41c3b
--- /dev/null
+++ b/packages/css-engine/src/core/find-applicable-media.ts
@@ -0,0 +1,20 @@
+import { compareMedia } from "./compare-media";
+import { matchMedia } from "./match-media";
+import type { MediaRuleOptions } from "./rules";
+
+// Find media rule that matches the given width when rendered.
+export const findApplicableMedia = <Media extends MediaRuleOptions>(
+ media: Array<Media>,
+ width: number
+) => {
+ const sortedMedia = media
+ .sort(compareMedia)
+ // Reverse order is needed because the last rule in CSSOM has higher source order specificity.
+ .reverse();
+
+ for (const options of sortedMedia) {
+ if (matchMedia(options, width)) {
+ return options;
+ }
+ }
+};
diff --git a/packages/css-engine/src/core/index.ts b/packages/css-engine/src/core/index.ts
index 77823b58f1..4e3be71faa 100644
--- a/packages/css-engine/src/core/index.ts
+++ b/packages/css-engine/src/core/index.ts
@@ -11,3 +11,4 @@ export * from "./to-value";
export * from "./match-media";
export * from "./equal-media";
export * from "./compare-media";
+export * from "./find-applicable-media";
diff --git a/packages/css-engine/src/core/match-media.ts b/packages/css-engine/src/core/match-media.ts
index ae5d575be1..ba06934849 100644
--- a/packages/css-engine/src/core/match-media.ts
+++ b/packages/css-engine/src/core/match-media.ts
@@ -1,5 +1,6 @@
import type { MediaRuleOptions } from "./rules";
+// This will match a breakpoint that has no min/max.
export const matchMedia = (options: MediaRuleOptions, width: number) => {
const minWidth = options.minWidth ?? Number.MIN_SAFE_INTEGER;
const maxWidth = options.maxWidth ?? Number.MAX_SAFE_INTEGER;
diff --git a/packages/design-system/bin/transform-figma-tokens.ts b/packages/design-system/bin/transform-figma-tokens.ts
index b0876c9dfb..91621fd7a8 100644
--- a/packages/design-system/bin/transform-figma-tokens.ts
+++ b/packages/design-system/bin/transform-figma-tokens.ts
@@ -158,7 +158,7 @@ const printLetterSpacing = (path: string[], unparsedValue: unknown) => {
return `${value}px`;
}
if (/^-?[0-9]+(.[0-9]+)?%$/.test(value)) {
- const fraction = parseFloat(value) / 100;
+ const fraction = Number.parseFloat(value) / 100;
return `${fraction}em`;
}
throw new Error(
diff --git a/packages/design-system/src/components/avatar.tsx b/packages/design-system/src/components/avatar.tsx
index 59b10bca9c..06dc44fd42 100644
--- a/packages/design-system/src/components/avatar.tsx
+++ b/packages/design-system/src/components/avatar.tsx
@@ -296,7 +296,7 @@ export const Avatar = React.forwardRef<
<Status
size={
(typeof size === "number" && size > 2) ||
- (typeof size === "string" && parseInt(size, 10) > 2)
+ (typeof size === "string" && Number.parseInt(size, 10) > 2)
? "2"
: "1"
}
diff --git a/packages/design-system/src/components/primitives/create-content-controller.stories.tsx b/packages/design-system/src/components/primitives/create-content-controller.stories.tsx
index 4bf36e85aa..9172f57286 100644
--- a/packages/design-system/src/components/primitives/create-content-controller.stories.tsx
+++ b/packages/design-system/src/components/primitives/create-content-controller.stories.tsx
@@ -24,7 +24,7 @@ const useContentController = ({
},
{
name: "number",
- match: (value: string) => isNaN(parseFloat(value)) === false,
+ match: (value: string) => Number.isNaN(parseFloat(value)) === false,
},
{ name: "unknown", match: (value: string) => Boolean(value) },
],
diff --git a/packages/design-system/src/components/primitives/create-content-controller.ts b/packages/design-system/src/components/primitives/create-content-controller.ts
index aa3e47e04f..4d1ea083ac 100644
--- a/packages/design-system/src/components/primitives/create-content-controller.ts
+++ b/packages/design-system/src/components/primitives/create-content-controller.ts
@@ -9,7 +9,7 @@
* const {update, disconnectedCallback} = createContentController(target, {
* contents: [
* { name: 'unit', match: (value) => value === 'px' },
- * { name: 'number', match: (value) => isNaN(parseFloat(value)) === false },
+ * { name: 'number', match: (value) => Number.isNaN(parseFloat(value)) === false },
* { name: 'unknown', match: (value) => true },
* ],
* onMouseMove: ({name, value, position}) => { },
@@ -38,10 +38,10 @@ const measureTextPadding = (node: HTMLElement, value: string) => {
}
canvasContext.font = `${fontWeight} ${fontSize} ${fontFamily}`;
return ["left", "start"].includes(textAlign)
- ? parseFloat(paddingLeft)
+ ? Number.parseFloat(paddingLeft)
: node.clientWidth -
canvasContext.measureText(value).width -
- parseFloat(paddingRight);
+ Number.parseFloat(paddingRight);
};
const measureTextMetrics = (value: string, index: number, offset: number) => {
let length = 0;
diff --git a/packages/design-system/src/components/primitives/numeric-gesture-control.ts b/packages/design-system/src/components/primitives/numeric-gesture-control.ts
index ca1cde95cb..4309d1055f 100644
--- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts
+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts
@@ -145,12 +145,12 @@ export const numericScrubControl = (
// When cursor moves out of the browser window
// we want it to come back from the other side
const top = wrapAround(
- parseFloat(state.cursor.style.top) + event.movementY,
+ Number.parseFloat(state.cursor.style.top) + event.movementY,
0,
globalThis.innerHeight
);
const left = wrapAround(
- parseFloat(state.cursor.style.left) + event.movementX,
+ Number.parseFloat(state.cursor.style.left) + event.movementX,
0,
globalThis.innerWidth
);
diff --git a/packages/design-system/src/components/scroll-area.tsx b/packages/design-system/src/components/scroll-area.tsx
index 110264484b..67e5aa8f41 100644
--- a/packages/design-system/src/components/scroll-area.tsx
+++ b/packages/design-system/src/components/scroll-area.tsx
@@ -40,7 +40,7 @@ const ScrollAreaScrollbar = styled(Scrollbar, {
display: "flex",
// ensures no selection
userSelect: "none",
- // disable browser handling of all panning and zooming gestures on touch devices
+ // disable browser handling of all panning and scaleUp gestures on touch devices
touchAction: "none",
paddingRight: 2,
paddingLeft: 6,
diff --git a/packages/design-system/src/components/toolbar.stories.tsx b/packages/design-system/src/components/toolbar.stories.tsx
index 8acf53389a..24d33ac118 100644
--- a/packages/design-system/src/components/toolbar.stories.tsx
+++ b/packages/design-system/src/components/toolbar.stories.tsx
@@ -23,8 +23,17 @@ const ToolbarStory = () => {
</ToolbarToggleItem>
</ToolbarToggleGroup>
<ToolbarSeparator />
+ <ToolbarToggleGroup type="single" value="4">
+ <ToolbarToggleItem value="3" variant="subtle">
+ <PlayIcon size={22} />
+ </ToolbarToggleItem>
+ <ToolbarToggleItem value="4" variant="preview">
+ <PlayIcon size={22} />
+ </ToolbarToggleItem>
+ </ToolbarToggleGroup>
+ <ToolbarSeparator />
<ToolbarToggleGroup type="single">
- <ToolbarToggleItem value="3" focused>
+ <ToolbarToggleItem value="5" focused>
<PlayIcon size={22} />
</ToolbarToggleItem>
</ToolbarToggleGroup>
diff --git a/packages/design-system/src/components/toolbar.tsx b/packages/design-system/src/components/toolbar.tsx
index ff3855d272..d65c185700 100644
--- a/packages/design-system/src/components/toolbar.tsx
+++ b/packages/design-system/src/components/toolbar.tsx
@@ -5,6 +5,7 @@
import * as ToolbarPrimitive from "@radix-ui/react-toolbar";
import { css, styled, theme } from "../stitches.config";
import { separatorStyle } from "./separator";
+import { typography } from "../__generated__/figma-design-tokens";
export const Toolbar = styled(ToolbarPrimitive.Root, {
display: "flex",
@@ -12,6 +13,7 @@ export const Toolbar = styled(ToolbarPrimitive.Root, {
background: theme.colors.backgroundTopbar,
color: theme.colors.foregroundContrastMain,
alignItems: "center",
+ gap: theme.spacing[5],
});
export const ToolbarToggleGroup = styled(ToolbarPrimitive.ToggleGroup, {
@@ -24,8 +26,7 @@ const toolbarItemFocusRing = {
"&::after": {
content: '""',
position: "absolute",
- width: theme.spacing[12],
- height: theme.spacing[12],
+ inset: 4,
outlineWidth: 2,
outlineStyle: "solid",
outlineColor: theme.colors.borderFocus,
@@ -33,10 +34,12 @@ const toolbarItemFocusRing = {
},
};
-export const toggleItemStyle = css({
+export const toggleItemStyle = css(typography.labelsTitleCase, {
// reset styles
boxSizing: "border-box",
- padding: 0,
+ position: "relative",
+ py: 0,
+ px: theme.spacing["5"],
appearance: "none",
border: "none",
outline: "none",
@@ -47,21 +50,35 @@ export const toggleItemStyle = css({
// prevent shrinking inside flex box
flexShrink: 0,
// set size and shape
- width: theme.spacing["15"],
- height: theme.spacing["15"],
+ minWidth: theme.spacing["15"],
+ minHeight: theme.spacing["15"],
color: "inherit",
background: "transparent",
+ transition: "200ms background",
"&:focus-visible": toolbarItemFocusRing,
- "&:hover, &[data-state='on'], &[data-state='open']": {
- background: theme.colors.backgroundButtonHover,
+ "&:hover, &[data-state=on], &[data-state=open]": {
+ background: theme.colors.backgroundTopbarHover,
},
variants: {
// Just for story
focused: {
true: toolbarItemFocusRing,
},
+ variant: {
+ subtle: {
+ color: theme.colors.foregroundSubtle,
+ "&:hover, &[data-state=on]": {
+ color: "inherit",
+ },
+ },
+ preview: {
+ "&[data-state=on]": {
+ color: theme.colors.foregroundSuccess,
+ },
+ },
+ },
},
});
diff --git a/packages/icons/icons/bp-star-off.svg b/packages/icons/icons/bp-star-off.svg
new file mode 100644
index 0000000000..288211f3a7
--- /dev/null
+++ b/packages/icons/icons/bp-star-off.svg
@@ -0,0 +1,5 @@
+<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path d="M10.4673 4.6117C10.6384 4.26493 10.724 4.09154 10.8402 4.03615C10.9413 3.98795 11.0587 3.98795 11.1598 4.03615C11.276 4.09154 11.3616 4.26493 11.5328 4.6117L13.1567 7.90158C13.2072 8.00395 13.2325 8.05514 13.2694 8.09488C13.3021 8.13007 13.3413 8.15858 13.3849 8.17884C13.434 8.20171 13.4905 8.20997 13.6035 8.22648L17.236 8.75742C17.6185 8.81333 17.8097 8.84128 17.8982 8.93471C17.9753 9.016 18.0115 9.12769 17.9968 9.2387C17.98 9.36629 17.8415 9.50116 17.5646 9.77088L14.9371 12.3301C14.8552 12.4098 14.8142 12.4497 14.7878 12.4972C14.7644 12.5392 14.7494 12.5854 14.7436 12.6331C14.7371 12.687 14.7467 12.7434 14.766 12.8561L15.386 16.4708C15.4514 16.8521 15.4841 17.0427 15.4227 17.1558C15.3692 17.2542 15.2742 17.3233 15.164 17.3437C15.0375 17.3671 14.8663 17.2771 14.5239 17.0971L11.2765 15.3893C11.1754 15.3361 11.1248 15.3095 11.0715 15.299C11.0243 15.2898 10.9757 15.2898 10.9285 15.299C10.8752 15.3095 10.8247 15.3361 10.7235 15.3893L7.4761 17.0971C7.13373 17.2771 6.96255 17.3671 6.83597 17.3437C6.72585 17.3233 6.63082 17.2542 6.57736 17.1558C6.51592 17.0427 6.54861 16.8521 6.614 16.4708L7.23397 12.8561C7.2533 12.7434 7.26296 12.687 7.25642 12.6331C7.25063 12.5854 7.23562 12.5392 7.21222 12.4972C7.1858 12.4497 7.14484 12.4098 7.06294 12.3301L4.43545 9.77088C4.15852 9.50116 4.02005 9.36629 4.0032 9.2387C3.98854 9.12769 4.02476 9.016 4.10177 8.93471C4.19028 8.84128 4.38154 8.81333 4.76406 8.75742L8.39652 8.22648C8.50948 8.20997 8.56597 8.20171 8.61516 8.17884C8.65871 8.15858 8.69792 8.13007 8.73061 8.09488C8.76754 8.05514 8.79281 8.00395 8.84334 7.90158L10.4673 4.6117Z" fill="#3E3E3E"/>
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M10.5174 3.35916C10.8227 3.21361 11.1773 3.21361 11.4826 3.35916C11.7468 3.48512 11.8923 3.70373 11.9653 3.82305C12.0409 3.94644 12.1184 4.10353 12.1937 4.25625C12.1976 4.26409 12.2014 4.27192 12.2053 4.27973L13.793 7.49621L17.3704 8.01909C17.5388 8.04367 17.7121 8.06896 17.8527 8.10278C17.9887 8.13549 18.2415 8.20648 18.4427 8.4189C18.6753 8.66436 18.7846 9.00167 18.7404 9.3369C18.702 9.62699 18.539 9.83277 18.4481 9.93907C18.3541 10.049 18.2286 10.1711 18.1067 10.2899L15.5191 12.8101L16.1296 16.3698C16.1585 16.5377 16.1881 16.7104 16.1996 16.8547C16.2106 16.9941 16.2214 17.2566 16.0817 17.5138C15.9203 17.811 15.6333 18.0195 15.3007 18.0811C15.0129 18.1345 14.7667 18.043 14.6375 17.9894C14.5038 17.934 14.3488 17.8524 14.198 17.7731L11 16.0913L7.80202 17.7731C7.65127 17.8524 7.49621 17.934 7.36255 17.9894C7.23332 18.043 6.9871 18.1345 6.69927 18.0811C6.36671 18.0195 6.07974 17.811 5.91831 17.5138C5.77859 17.2566 5.78942 16.9941 5.80046 16.8547C5.81188 16.7104 5.84153 16.5377 5.87036 16.3699L6.4809 12.8101L3.91215 10.3082C3.9059 10.3021 3.89965 10.296 3.89338 10.2899C3.77142 10.1711 3.64595 10.049 3.55191 9.93907C3.46097 9.83277 3.29797 9.62699 3.25966 9.3369C3.21539 9.00167 3.32476 8.66436 3.55731 8.4189C3.75856 8.20648 4.0113 8.13549 4.14731 8.10278C4.28795 8.06897 4.46122 8.04367 4.62965 8.01909C4.63831 8.01783 4.64696 8.01657 4.65558 8.0153L8.20704 7.49621L9.79473 4.27973C9.79859 4.27192 9.80245 4.26408 9.80632 4.25624C9.88166 4.10353 9.95916 3.94644 10.0347 3.82305C10.1078 3.70374 10.2532 3.48512 10.5174 3.35916ZM11 5.22685L9.51587 8.23355C9.51304 8.23928 9.5098 8.24598 9.50616 8.25353C9.47084 8.32668 9.39708 8.47943 9.28006 8.60538C9.18134 8.71164 9.06293 8.79774 8.9314 8.8589C8.77552 8.93139 8.60746 8.95447 8.52699 8.96552C8.51869 8.96666 8.51132 8.96767 8.50499 8.96859L5.18489 9.45388L7.58624 11.7928C7.59082 11.7973 7.59621 11.8024 7.60227 11.8082C7.66103 11.8645 7.78375 11.9819 7.8675 12.1323C7.93815 12.2592 7.98348 12.3987 8.00097 12.5428C8.02169 12.7137 7.99152 12.8809 7.97707 12.961C7.97558 12.9692 7.97426 12.9766 7.97317 12.9829L7.40661 16.2862L10.3744 14.7255C10.3801 14.7225 10.3866 14.719 10.394 14.715C10.4657 14.6766 10.6153 14.5962 10.7842 14.5631C10.9267 14.5351 11.0733 14.5351 11.2158 14.5631C11.3847 14.5962 11.5344 14.6766 11.606 14.715C11.6134 14.719 11.62 14.7225 11.6256 14.7255L14.5934 16.2862L14.0268 12.9829C14.0258 12.9766 14.0244 12.9692 14.0229 12.961C14.0085 12.8809 13.9783 12.7137 13.999 12.5428C14.0165 12.3987 14.0619 12.2592 14.1325 12.1323C14.2163 11.9819 14.339 11.8645 14.3977 11.8082C14.4038 11.8024 14.4092 11.7973 14.4138 11.7928L16.8151 9.45388L13.495 8.96859C13.4887 8.96767 13.4813 8.96666 13.473 8.96552C13.3926 8.95447 13.2245 8.9314 13.0686 8.8589C12.9371 8.79774 12.8187 8.71164 12.7199 8.60538C12.6029 8.47943 12.5292 8.32668 12.4939 8.25353C12.4902 8.24598 12.487 8.23928 12.4841 8.23355L11 5.22685Z" fill="#8D949A"/>
+</svg>
+
\ No newline at end of file
diff --git a/packages/icons/icons/bp-star-on.svg b/packages/icons/icons/bp-star-on.svg
new file mode 100644
index 0000000000..8620bbeaf8
--- /dev/null
+++ b/packages/icons/icons/bp-star-on.svg
@@ -0,0 +1,5 @@
+<svg width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path d="M10.4673 4.6117C10.6384 4.26493 10.724 4.09154 10.8402 4.03615C10.9413 3.98795 11.0587 3.98795 11.1598 4.03615C11.276 4.09154 11.3616 4.26493 11.5328 4.6117L13.1567 7.90158C13.2072 8.00395 13.2325 8.05514 13.2694 8.09488C13.3021 8.13007 13.3413 8.15858 13.3849 8.17884C13.434 8.20171 13.4905 8.20997 13.6035 8.22648L17.236 8.75742C17.6185 8.81333 17.8097 8.84128 17.8982 8.93471C17.9753 9.016 18.0115 9.12769 17.9968 9.2387C17.98 9.36629 17.8415 9.50116 17.5646 9.77088L14.9371 12.3301C14.8552 12.4098 14.8142 12.4497 14.7878 12.4972C14.7644 12.5392 14.7494 12.5854 14.7436 12.6331C14.7371 12.687 14.7467 12.7434 14.766 12.8561L15.386 16.4708C15.4514 16.8521 15.4841 17.0427 15.4227 17.1558C15.3692 17.2542 15.2742 17.3233 15.164 17.3437C15.0375 17.3671 14.8663 17.2771 14.5239 17.0971L11.2765 15.3893C11.1754 15.3361 11.1248 15.3095 11.0715 15.299C11.0243 15.2898 10.9757 15.2898 10.9285 15.299C10.8752 15.3095 10.8247 15.3361 10.7235 15.3893L7.4761 17.0971C7.13373 17.2771 6.96255 17.3671 6.83597 17.3437C6.72585 17.3233 6.63082 17.2542 6.57736 17.1558C6.51592 17.0427 6.54861 16.8521 6.614 16.4708L7.23397 12.8561C7.2533 12.7434 7.26296 12.687 7.25642 12.6331C7.25063 12.5854 7.23562 12.5392 7.21222 12.4972C7.1858 12.4497 7.14484 12.4098 7.06294 12.3301L4.43545 9.77088C4.15852 9.50116 4.02005 9.36629 4.0032 9.2387C3.98854 9.12769 4.02476 9.016 4.10177 8.93471C4.19028 8.84128 4.38154 8.81333 4.76406 8.75742L8.39652 8.22648C8.50948 8.20997 8.56597 8.20171 8.61516 8.17884C8.65871 8.15858 8.69792 8.13007 8.73061 8.09488C8.76754 8.05514 8.79281 8.00395 8.84334 7.90158L10.4673 4.6117Z" fill="#707375"/>
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M10.5174 3.35916C10.8227 3.21361 11.1773 3.21361 11.4826 3.35916C11.7468 3.48512 11.8923 3.70373 11.9653 3.82305C12.0409 3.94644 12.1184 4.10353 12.1937 4.25625C12.1976 4.26409 12.2014 4.27192 12.2053 4.27973L13.793 7.49621L17.3704 8.01909C17.5388 8.04367 17.7121 8.06896 17.8527 8.10278C17.9887 8.13549 18.2415 8.20648 18.4427 8.4189C18.6753 8.66436 18.7846 9.00167 18.7404 9.3369C18.702 9.62699 18.539 9.83277 18.4481 9.93907C18.3541 10.049 18.2286 10.1711 18.1067 10.2899L15.5191 12.8101L16.1296 16.3698C16.1585 16.5377 16.1881 16.7104 16.1996 16.8547C16.2106 16.9941 16.2214 17.2566 16.0817 17.5138C15.9203 17.811 15.6333 18.0195 15.3007 18.0811C15.0129 18.1345 14.7667 18.043 14.6375 17.9894C14.5038 17.934 14.3488 17.8524 14.198 17.7731L11 16.0913L7.80202 17.7731C7.65127 17.8524 7.49621 17.934 7.36255 17.9894C7.23332 18.043 6.9871 18.1345 6.69927 18.0811C6.36671 18.0195 6.07974 17.811 5.91831 17.5138C5.77859 17.2566 5.78942 16.9941 5.80046 16.8547C5.81188 16.7104 5.84153 16.5377 5.87036 16.3699L6.4809 12.8101L3.91215 10.3082C3.9059 10.3021 3.89965 10.296 3.89338 10.2899C3.77142 10.1711 3.64595 10.049 3.55191 9.93907C3.46097 9.83277 3.29797 9.62699 3.25966 9.3369C3.21539 9.00167 3.32476 8.66436 3.55731 8.4189C3.75856 8.20648 4.0113 8.13549 4.14731 8.10278C4.28795 8.06897 4.46122 8.04367 4.62965 8.01909C4.63831 8.01783 4.64696 8.01657 4.65558 8.0153L8.20704 7.49621L9.79473 4.27973C9.79859 4.27192 9.80245 4.26408 9.80632 4.25624C9.88166 4.10353 9.95916 3.94644 10.0347 3.82305C10.1078 3.70374 10.2532 3.48512 10.5174 3.35916ZM11 5.22685L9.51587 8.23355C9.51304 8.23928 9.5098 8.24598 9.50616 8.25353C9.47084 8.32668 9.39708 8.47943 9.28006 8.60538C9.18134 8.71164 9.06293 8.79774 8.9314 8.8589C8.77552 8.93139 8.60746 8.95447 8.52699 8.96552C8.51869 8.96666 8.51132 8.96767 8.50499 8.96859L5.18489 9.45388L7.58624 11.7928C7.59082 11.7973 7.59621 11.8024 7.60227 11.8082C7.66103 11.8645 7.78375 11.9819 7.8675 12.1323C7.93815 12.2592 7.98348 12.3987 8.00097 12.5428C8.02169 12.7137 7.99152 12.8809 7.97707 12.961C7.97558 12.9692 7.97426 12.9766 7.97317 12.9829L7.40661 16.2862L10.3744 14.7255C10.3801 14.7225 10.3866 14.719 10.394 14.715C10.4657 14.6766 10.6153 14.5962 10.7842 14.5631C10.9267 14.5351 11.0733 14.5351 11.2158 14.5631C11.3847 14.5962 11.5344 14.6766 11.606 14.715C11.6134 14.719 11.62 14.7225 11.6256 14.7255L14.5934 16.2862L14.0268 12.9829C14.0258 12.9766 14.0244 12.9692 14.0229 12.961C14.0085 12.8809 13.9783 12.7137 13.999 12.5428C14.0165 12.3987 14.0619 12.2592 14.1325 12.1323C14.2163 11.9819 14.339 11.8645 14.3977 11.8082C14.4038 11.8024 14.4092 11.7973 14.4138 11.7928L16.8151 9.45388L13.495 8.96859C13.4887 8.96767 13.4813 8.96666 13.473 8.96552C13.3926 8.95447 13.2245 8.9314 13.0686 8.8589C12.9371 8.79774 12.8187 8.71164 12.7199 8.60538C12.6029 8.47943 12.5292 8.32668 12.4939 8.25353C12.4902 8.24598 12.487 8.23928 12.4841 8.23355L11 5.22685Z" fill="white"/>
+</svg>
+
\ No newline at end of file
diff --git a/packages/icons/src/__generated__/bp-star-off.tsx b/packages/icons/src/__generated__/bp-star-off.tsx
new file mode 100644
index 0000000000..de2b5054d7
--- /dev/null
+++ b/packages/icons/src/__generated__/bp-star-off.tsx
@@ -0,0 +1,15 @@
+// Generated from icons/bp-star-off.svg
+
+import { forwardRef } from "react";
+import type { IconProps } from "../types";
+
+// prettier-ignore
+export const BpStarOffIcon = forwardRef<SVGSVGElement, IconProps>(
+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path fill="#3E3E3E" d="M10.467 4.612c.171-.347.257-.52.373-.576a.371.371 0 0 1 .32 0c.116.056.202.229.373.576l1.624 3.29c.05.102.075.153.112.193a.371.371 0 0 0 .116.084.81.81 0 0 0 .219.047l3.632.531c.383.056.574.084.662.178a.37.37 0 0 1 .099.304c-.017.127-.155.262-.432.532l-2.628 2.56a.809.809 0 0 0-.15.166.371.371 0 0 0-.043.136.815.815 0 0 0 .022.223l.62 3.615c.065.381.098.572.037.685a.371.371 0 0 1-.259.188c-.127.023-.298-.067-.64-.247l-3.247-1.708a.813.813 0 0 0-.205-.09.374.374 0 0 0-.143 0c-.054.01-.104.037-.206.09l-3.247 1.708c-.342.18-.513.27-.64.247a.371.371 0 0 1-.259-.188c-.061-.113-.028-.304.037-.685l.62-3.615a.812.812 0 0 0 .022-.223.371.371 0 0 0-.044-.136.81.81 0 0 0-.15-.167L4.436 9.77c-.276-.269-.415-.404-.432-.531a.371.371 0 0 1 .099-.304c.088-.094.28-.122.662-.178l3.633-.53a.812.812 0 0 0 .218-.048.371.371 0 0 0 .116-.084.812.812 0 0 0 .112-.193l1.624-3.29Z" /><path fill="#8D949A" fillRule="evenodd" d="M10.517 3.36c.306-.146.66-.146.966 0 .264.125.41.344.482.463.076.123.153.28.229.433l.011.024 1.588 3.216 3.577.523c.169.025.342.05.483.084.136.032.388.103.59.316.232.245.342.583.297.918-.038.29-.201.496-.292.602-.094.11-.22.232-.341.35l-2.588 2.521.61 3.56c.03.168.06.34.07.485.012.14.022.402-.117.659a1.121 1.121 0 0 1-.781.567 1.165 1.165 0 0 1-.664-.092c-.133-.055-.288-.137-.439-.216L11 16.091l-3.198 1.682c-.15.08-.306.161-.44.216-.129.054-.375.145-.663.092a1.121 1.121 0 0 1-.78-.567 1.166 1.166 0 0 1-.119-.66c.012-.144.042-.316.07-.484l.61-3.56-2.568-2.502-.019-.018c-.122-.119-.247-.241-.341-.35a1.166 1.166 0 0 1-.292-.603 1.121 1.121 0 0 1 .297-.918c.202-.213.454-.284.59-.316a5.764 5.764 0 0 1 .509-.088l3.551-.519L9.795 4.28l.011-.024c.076-.152.153-.31.229-.433.073-.12.218-.338.482-.464ZM11 5.226 9.516 8.234a1.422 1.422 0 0 1-.236.372 1.121 1.121 0 0 1-.349.253 1.422 1.422 0 0 1-.404.107c-.008 0-.016.002-.022.003l-3.32.485 2.401 2.339.016.015c.059.056.182.174.265.324.071.127.116.267.134.41.02.172-.01.339-.024.419a2.706 2.706 0 0 0-.004.022l-.566 3.303 2.967-1.56.02-.011c.072-.038.221-.119.39-.152a1.12 1.12 0 0 1 .432 0c.169.033.318.114.39.152l.02.01 2.967 1.561-.566-3.303-.004-.022c-.014-.08-.045-.247-.024-.418.018-.144.063-.284.133-.41.084-.151.207-.268.266-.325l.016-.015 2.401-2.34-3.32-.484-.022-.003c-.08-.012-.248-.035-.404-.107a1.123 1.123 0 0 1-.35-.254c-.116-.126-.19-.278-.225-.351l-.01-.02L11 5.227Z" clipRule="evenodd" /></svg>
+ );
+ }
+);
+
+BpStarOffIcon.displayName = "BpStarOffIcon";
diff --git a/packages/icons/src/__generated__/bp-star-on.tsx b/packages/icons/src/__generated__/bp-star-on.tsx
new file mode 100644
index 0000000000..750afdd02e
--- /dev/null
+++ b/packages/icons/src/__generated__/bp-star-on.tsx
@@ -0,0 +1,15 @@
+// Generated from icons/bp-star-on.svg
+
+import { forwardRef } from "react";
+import type { IconProps } from "../types";
+
+// prettier-ignore
+export const BpStarOnIcon = forwardRef<SVGSVGElement, IconProps>(
+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path fill="#707375" d="M10.467 4.612c.171-.347.257-.52.373-.576a.371.371 0 0 1 .32 0c.116.056.202.229.373.576l1.624 3.29c.05.102.075.153.112.193a.371.371 0 0 0 .116.084.81.81 0 0 0 .219.047l3.632.531c.383.056.574.084.662.178a.37.37 0 0 1 .099.304c-.017.127-.155.262-.432.532l-2.628 2.56a.809.809 0 0 0-.15.166.371.371 0 0 0-.043.136.815.815 0 0 0 .022.223l.62 3.615c.065.381.098.572.037.685a.371.371 0 0 1-.259.188c-.127.023-.298-.067-.64-.247l-3.247-1.708a.813.813 0 0 0-.205-.09.374.374 0 0 0-.143 0c-.054.01-.104.037-.206.09l-3.247 1.708c-.342.18-.513.27-.64.247a.371.371 0 0 1-.259-.188c-.061-.113-.028-.304.037-.685l.62-3.615a.812.812 0 0 0 .022-.223.371.371 0 0 0-.044-.136.81.81 0 0 0-.15-.167L4.436 9.77c-.276-.269-.415-.404-.432-.531a.371.371 0 0 1 .099-.304c.088-.094.28-.122.662-.178l3.633-.53a.812.812 0 0 0 .218-.048.371.371 0 0 0 .116-.084.812.812 0 0 0 .112-.193l1.624-3.29Z" /><path fill="#fff" fillRule="evenodd" d="M10.517 3.36c.306-.146.66-.146.966 0 .264.125.41.344.482.463.076.123.153.28.229.433l.011.024 1.588 3.216 3.577.523c.169.025.342.05.483.084.136.032.388.103.59.316.232.245.342.583.297.918-.038.29-.201.496-.292.602-.094.11-.22.232-.341.35l-2.588 2.521.61 3.56c.03.168.06.34.07.485.012.14.022.402-.117.659a1.121 1.121 0 0 1-.781.567 1.165 1.165 0 0 1-.664-.092c-.133-.055-.288-.137-.439-.216L11 16.091l-3.198 1.682c-.15.08-.306.161-.44.216-.129.054-.375.145-.663.092a1.121 1.121 0 0 1-.78-.567 1.166 1.166 0 0 1-.119-.66c.012-.144.042-.316.07-.484l.61-3.56-2.568-2.502-.019-.018c-.122-.119-.247-.241-.341-.35a1.166 1.166 0 0 1-.292-.603 1.121 1.121 0 0 1 .297-.918c.202-.213.454-.284.59-.316a5.764 5.764 0 0 1 .509-.088l3.551-.519L9.795 4.28l.011-.024c.076-.152.153-.31.229-.433.073-.12.218-.338.482-.464ZM11 5.226 9.516 8.234a1.422 1.422 0 0 1-.236.372 1.121 1.121 0 0 1-.349.253 1.422 1.422 0 0 1-.404.107c-.008 0-.016.002-.022.003l-3.32.485 2.401 2.339.016.015c.059.056.182.174.265.324.071.127.116.267.134.41.02.172-.01.339-.024.419a2.706 2.706 0 0 0-.004.022l-.566 3.303 2.967-1.56.02-.011c.072-.038.221-.119.39-.152a1.12 1.12 0 0 1 .432 0c.169.033.318.114.39.152l.02.01 2.967 1.561-.566-3.303-.004-.022c-.014-.08-.045-.247-.024-.418.018-.144.063-.284.133-.41.084-.151.207-.268.266-.325l.016-.015 2.401-2.34-3.32-.484-.022-.003c-.08-.012-.248-.035-.404-.107a1.123 1.123 0 0 1-.35-.254c-.116-.126-.19-.278-.225-.351l-.01-.02L11 5.227Z" clipRule="evenodd" /></svg>
+ );
+ }
+);
+
+BpStarOnIcon.displayName = "BpStarOnIcon";
diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.ts
index a74672e032..def643acef 100644
--- a/packages/icons/src/__generated__/index.ts
+++ b/packages/icons/src/__generated__/index.ts
@@ -17,6 +17,8 @@ export * from "./border-width-right";
export * from "./border-width-top";
export * from "./box-link";
export * from "./box";
+export * from "./bp-star-off";
+export * from "./bp-star-on";
export * from "./button-element";
export * from "./checkbox-checked-filled";
export * from "./checkbox-empty";
diff --git a/packages/image/src/image-optimize.ts b/packages/image/src/image-optimize.ts
index 16f20f6993..2477f1f426 100644
--- a/packages/image/src/image-optimize.ts
+++ b/packages/image/src/image-optimize.ts
@@ -112,7 +112,7 @@ const getWidths = (
const viewportWidthRe = /(^|\s)(1?\d?\d)vw/g;
const percentSizes = [];
for (let match; (match = viewportWidthRe.exec(sizes)); match) {
- percentSizes.push(parseInt(match[2], 10));
+ percentSizes.push(Number.parseInt(match[2], 10));
}
if (percentSizes.length) {
diff --git a/packages/project-build/src/schema/breakpoints.ts b/packages/project-build/src/schema/breakpoints.ts
index 21836a113b..314c130f22 100644
--- a/packages/project-build/src/schema/breakpoints.ts
+++ b/packages/project-build/src/schema/breakpoints.ts
@@ -24,5 +24,4 @@ export const initialBreakpoints: Array<Breakpoint> = [
{ id: "placeholder", label: "Tablet", maxWidth: 991 },
{ id: "placeholder", label: "Mobile landscape", maxWidth: 767 },
{ id: "placeholder", label: "Mobile portrait", maxWidth: 479 },
- { id: "placeholder", label: "Large", minWidth: 1280 },
];