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 stage 3 (#1413)

Oleg Isonen3b0aba880e7f
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx
index 28d083dd84..d247676292 100644
--- a/apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-settings.tsx
@@ -11,11 +11,14 @@ import {
DropdownMenuPortal,
DropdownMenuSeparator,
DropdownMenuItemRightSlot,
+ Flex,
+ Label,
+ Button,
} from "@webstudio-is/design-system";
import { useSubscribe } from "~/shared/pubsub";
import { BreakpointsEditor } from "./breakpoints-editor";
import { TriggerButton } from "./trigger-button";
-import { WidthSetting } from "./width-setting";
+import { WidthInput } from "./width-input";
import { ConfirmationDialog } from "./confirmation-dialog";
import {
breakpointsStore,
@@ -25,6 +28,7 @@ import {
} from "~/shared/nano-states";
import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import { groupBreakpoints } from "~/shared/breakpoints";
+import { scaleStore } from "~/builder/shared/nano-states";
export const BreakpointsSettings = () => {
const [view, setView] = useState<
@@ -35,6 +39,7 @@ export const BreakpointsSettings = () => {
>();
const breakpoints = useStore(breakpointsStore);
const selectedBreakpoint = useStore(selectedBreakpointStore);
+ const scale = useStore(scaleStore);
useSubscribe("openBreakpointsMenu", () => {
setView("selector");
@@ -121,6 +126,21 @@ export const BreakpointsSettings = () => {
)}
{view === "selector" && (
<>
+ <Flex
+ css={{ px: theme.spacing[7], py: theme.spacing[5] }}
+ gap="3"
+ direction="row"
+ >
+ <WidthInput />
+ <Flex align="center" gap="2">
+ <Label>Scale</Label>
+ <Button color="neutral" css={{ width: theme.spacing[17] }}>
+ {Math.round(scale)}%
+ </Button>
+ </Flex>
+ </Flex>
+ <DropdownMenuSeparator />
+
{groupBreakpoints(Array.from(breakpoints.values())).map(
(breakpoint) => {
return (
@@ -140,10 +160,6 @@ export const BreakpointsSettings = () => {
);
}
)}
- <DropdownMenuSeparator />
- <form>
- <WidthSetting />
- </form>
{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
index c567393262..d24ab63a23 100644
--- a/apps/builder/app/builder/features/breakpoints/cascade-indicator.tsx
+++ b/apps/builder/app/builder/features/breakpoints/cascade-indicator.tsx
@@ -9,7 +9,7 @@ import { isBaseBreakpoint } from "~/shared/breakpoints";
const cascadeIndicatorStyle = css({
position: "absolute",
bottom: 0,
- height: 2,
+ height: 3,
transition: "150ms width, 150ms left, 150ms right",
'&[data-direction="left"]': {
background: theme.colors.backgroundGradientHorizontal,
diff --git a/apps/builder/app/builder/features/breakpoints/width-input.tsx b/apps/builder/app/builder/features/breakpoints/width-input.tsx
new file mode 100644
index 0000000000..cecf3962aa
--- /dev/null
+++ b/apps/builder/app/builder/features/breakpoints/width-input.tsx
@@ -0,0 +1,140 @@
+import { useStore } from "@nanostores/react";
+import { findApplicableMedia } from "@webstudio-is/css-engine";
+import {
+ theme,
+ Text,
+ Flex,
+ Label,
+ type NumericScrubValue,
+ InputField,
+ useId,
+ useScrub,
+} from "@webstudio-is/design-system";
+import { useCanvasWidth } from "~/builder/shared/nano-states";
+import { breakpointsStore, isResizingCanvasStore } from "~/shared/nano-states";
+import {
+ selectedBreakpointIdStore,
+ selectedBreakpointStore,
+} from "~/shared/nano-states";
+import {
+ useState,
+ type ChangeEvent,
+ type KeyboardEvent,
+ useEffect,
+} from "react";
+
+// Doesn't make sense to allow resizing the canvas lower/higher than this.
+export const minWidth = 240;
+
+const useEnhancedInput = ({
+ onChange,
+ onChangeComplete,
+ value,
+}: {
+ onChange: (value: NumericScrubValue) => void;
+ onChangeComplete: (value: NumericScrubValue) => void;
+ value: number;
+}) => {
+ const [intermediateValue, setIntermediateValue] = useState<number>();
+
+ const handleChange = (nextValue: number) => {
+ onChange(Math.max(nextValue, minWidth));
+ setIntermediateValue(undefined);
+ };
+
+ const handleChangeComplete = (nextValue: number) => {
+ onChangeComplete(Math.max(nextValue, minWidth));
+ setIntermediateValue(undefined);
+ };
+
+ const { scrubRef, inputRef } = useScrub({
+ value,
+ onChange: handleChange,
+ onChangeComplete: handleChangeComplete,
+ });
+
+ return {
+ ref: scrubRef,
+ inputRef,
+ onChange(event: ChangeEvent<HTMLInputElement>) {
+ setIntermediateValue(event.target.valueAsNumber);
+ },
+ onKeyDown(event: KeyboardEvent<HTMLInputElement>) {
+ if (event.key === "Enter") {
+ handleChangeComplete(event.currentTarget.valueAsNumber);
+ }
+ },
+ onBlur() {
+ handleChangeComplete(inputRef.current?.valueAsNumber ?? 0);
+ },
+ type: "number" as const,
+ value: intermediateValue ?? value,
+ };
+};
+
+export const WidthInput = () => {
+ const id = useId();
+ const [canvasWidth, setCanvasWidth] = useCanvasWidth();
+ const selectedBreakpoint = useStore(selectedBreakpointStore);
+ const breakpoints = useStore(breakpointsStore);
+
+ const onChange = (value: number) => {
+ setCanvasWidth(value);
+ const applicableBreakpoint = findApplicableMedia(
+ Array.from(breakpoints.values()),
+ value
+ );
+ if (applicableBreakpoint) {
+ selectedBreakpointIdStore.set(applicableBreakpoint.id);
+ }
+ if (isResizingCanvasStore.get() === false) {
+ isResizingCanvasStore.set(true);
+ }
+ };
+
+ const onChangeComplete = (value: number) => {
+ onChange(value);
+ isResizingCanvasStore.set(false);
+ };
+
+ useEffect(() => {
+ return () => {
+ // Just in case we haven't received onChangeComplete, make sure we have set isResizingCanvasStore to false,
+ // otherwise the canvas will be stuck in a resizing state.
+ if (isResizingCanvasStore.get()) {
+ isResizingCanvasStore.set(false);
+ }
+ };
+ }, []);
+
+ const inputProps = useEnhancedInput({
+ value: canvasWidth ?? 0,
+ onChange,
+ onChangeComplete,
+ });
+
+ if (canvasWidth === undefined || selectedBreakpoint === undefined) {
+ return null;
+ }
+
+ return (
+ <Flex gap="2" align="center">
+ <Label htmlFor={id}>Width</Label>
+ <InputField
+ {...inputProps}
+ css={{ width: theme.spacing[19] }}
+ id={id}
+ suffix={
+ <Text
+ variant="unit"
+ color="subtle"
+ align="center"
+ css={{ width: theme.spacing[10] }}
+ >
+ PX
+ </Text>
+ }
+ />
+ </Flex>
+ );
+};
diff --git a/apps/builder/app/builder/features/breakpoints/width-setting.tsx b/apps/builder/app/builder/features/breakpoints/width-setting.tsx
deleted file mode 100644
index a6f8182591..0000000000
--- a/apps/builder/app/builder/features/breakpoints/width-setting.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { useStore } from "@nanostores/react";
-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 { 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 = 240;
-export const maxWidth = 2500;
-
-export const WidthSetting = () => {
- const [canvasWidth, setCanvasWidth] = useCanvasWidth();
- const selectedBreakpoint = useStore(selectedBreakpointStore);
- const breakpoints = useStore(breakpointsStore);
-
- if (canvasWidth === undefined || selectedBreakpoint === undefined) {
- return null;
- }
-
- return (
- <Flex
- css={{ px: theme.spacing[11], py: theme.spacing[3] }}
- gap="1"
- direction="column"
- >
- <Text>Canvas width</Text>
- <Flex gap="3" align="center">
- <Slider
- min={minWidth}
- max={maxWidth}
- value={[canvasWidth]}
- onValueChange={([value]) => {
- setCanvasWidth(value);
- const applicableBreakpoint = findApplicableMedia(
- Array.from(breakpoints.values()),
- value
- );
- if (applicableBreakpoint) {
- selectedBreakpointIdStore.set(applicableBreakpoint.id);
- }
- }}
- />
- <Text>{`${canvasWidth}px`}</Text>
- </Flex>
- </Flex>
- );
-};
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 90bec53341..bbac6a991f 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,11 +1,11 @@
import { useCallback, useEffect, useState } from "react";
-import { useStore } from "@nanostores/react";
+
import {
scaleStore,
- useCanvasRect,
- useCanvasWidth,
+ canvasWidthContainer,
+ canvasRectContainer,
} from "~/builder/shared/nano-states";
-import { useWindowResize } from "~/shared/dom-hooks";
+import { useWindowResizeDebounced } from "~/shared/dom-hooks";
/**
* Reads the canvas iframe dom rect and puts it into nano state
@@ -15,33 +15,33 @@ export const useReadCanvasRect = () => {
const [iframeElement, setIframeElement] = useState<HTMLIFrameElement | null>(
null
);
- const [, setCanvasRect] = useCanvasRect();
- const [canvasWidth] = useCanvasWidth();
- const scale = useStore(scaleStore);
- const [recalcFlag, forceRecalc] = useState(false);
- useWindowResize(() => {
- forceRecalc(!recalcFlag);
- });
- const readRect = useCallback(
- () => {
- if (iframeElement === null) {
- return;
- }
- requestAnimationFrame(() => {
- const rect = iframeElement.getBoundingClientRect();
- setCanvasRect(rect);
- });
- },
- // 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, scale, recalcFlag]
- );
+ const updateRect = useCallback(() => {
+ if (iframeElement === null) {
+ return;
+ }
+ const rect = iframeElement.getBoundingClientRect();
+ canvasRectContainer.set(rect);
+ }, [iframeElement]);
- useEffect(readRect, [readRect]);
+ useEffect(() => {
+ updateRect();
+ const scaleStoreUnsubscribe = scaleStore.listen(updateRect);
+ const canvasWidthContainerUnsubscribe =
+ canvasWidthContainer.listen(updateRect);
+
+ return () => {
+ scaleStoreUnsubscribe();
+ canvasWidthContainerUnsubscribe();
+ };
+ }, [updateRect]);
+
+ useWindowResizeDebounced(() => {
+ updateRect();
+ });
return {
onRef: setIframeElement,
- onTransitionEnd: readRect,
+ onTransitionEnd: updateRect,
};
};
diff --git a/apps/builder/app/builder/shared/nano-states/index.ts b/apps/builder/app/builder/shared/nano-states/index.ts
index 5bf8a0d060..66da0cdb03 100644
--- a/apps/builder/app/builder/shared/nano-states/index.ts
+++ b/apps/builder/app/builder/shared/nano-states/index.ts
@@ -14,10 +14,10 @@ const isPublishDialogOpenContainer = atom<boolean>(false);
export const useIsPublishDialogOpen = () =>
useValue(isPublishDialogOpenContainer);
-const canvasWidthContainer = atom<number | undefined>();
+export const canvasWidthContainer = atom<number | undefined>();
export const useCanvasWidth = () => useValue(canvasWidthContainer);
-const canvasRectContainer = atom<DOMRect | undefined>();
+export const canvasRectContainer = atom<DOMRect | undefined>();
export const useCanvasRect = () => useValue(canvasRectContainer);
export const projectContainer = atom<Project | undefined>();
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 5d268c8337..8237cef768 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
@@ -5,6 +5,7 @@ import { getBrowserStyle, idAttribute } from "@webstudio-is/react-sdk";
import { subscribe } from "~/shared/pubsub";
import { subscribeWindowResize } from "~/shared/dom-hooks";
import {
+ isResizingCanvasStore,
rootInstanceContainer,
selectedInstanceBrowserStyleStore,
selectedInstanceIntanceToTagStore,
@@ -76,27 +77,33 @@ export const SelectedInstanceConnector = ({
instanceProps: undefined | Prop[];
}) => {
const rootInstance = useStore(rootInstanceContainer);
+
useEffect(() => {
const element = instanceElementRef.current;
if (element === undefined) {
return;
}
-
+ const showOutline = () => {
+ if (isResizingCanvasStore.get()) {
+ return;
+ }
+ setOutline(instance.id, element);
+ };
// effect close to rendered element also catches dnd remounts
// so actual state is always provided here
- setOutline(instance.id, element);
+ showOutline();
const resizeObserver = new ResizeObserver(() => {
// contentRect has wrong x/y values for absolutely positioned element.
// getBoundingClientRect is used instead.
- setOutline(instance.id, element);
+ showOutline();
});
resizeObserver.observe(element);
// detect movement of the element within same parent
// React prevent remount when key stays the same
const mutationObserver = new window.MutationObserver(() => {
- setOutline(instance.id, element);
+ showOutline();
});
const parent = element?.parentElement;
if (parent) {
@@ -110,12 +117,21 @@ export const SelectedInstanceConnector = ({
hideOutline();
});
+ const unsubscribeIsResizingCanvas = isResizingCanvasStore.subscribe(
+ (isResizing) => {
+ if (isResizing && selectedInstanceOutlineStore.get()) {
+ return hideOutline();
+ }
+ showOutline();
+ }
+ );
+
const unsubscribeScrollState = subscribeScrollState({
onScrollStart() {
hideOutline();
},
onScrollEnd() {
- setOutline(instance.id, element);
+ showOutline();
},
});
@@ -124,7 +140,7 @@ export const SelectedInstanceConnector = ({
hideOutline();
},
onResizeEnd() {
- setOutline(instance.id, element);
+ showOutline();
},
});
@@ -158,6 +174,7 @@ export const SelectedInstanceConnector = ({
unsubscribePreviewStyle();
unsubscribeScrollState();
unsubscribeWindowResize();
+ unsubscribeIsResizingCanvas();
};
}, [
instanceElementRef,
diff --git a/apps/builder/app/shared/nano-states/instances.ts b/apps/builder/app/shared/nano-states/instances.ts
index d317b02c51..3a1df85b44 100644
--- a/apps/builder/app/shared/nano-states/instances.ts
+++ b/apps/builder/app/shared/nano-states/instances.ts
@@ -10,6 +10,8 @@ import { getElementByInstanceSelector } from "../dom-utils";
import { useSyncInitializeOnce } from "../hook-utils";
import { selectedPageStore } from "./pages";
+export const isResizingCanvasStore = atom(false);
+
export const selectedInstanceSelectorStore = atom<undefined | InstanceSelector>(
undefined
);
@@ -133,4 +135,5 @@ export const selectedInstanceStore = computed(
export const synchronizedInstancesStores = [
["textEditingInstanceSelector", textEditingInstanceSelectorStore],
+ ["isResizingCanvas", isResizingCanvasStore],
] as const;
diff --git a/packages/design-system/src/components/input-field.tsx b/packages/design-system/src/components/input-field.tsx
index 19f33bfa4e..01fe1018b4 100644
--- a/packages/design-system/src/components/input-field.tsx
+++ b/packages/design-system/src/components/input-field.tsx
@@ -58,11 +58,11 @@ const containerStyle = css({
display: "flex",
height: theme.spacing[12],
boxSizing: "border-box",
+ minWidth: 0,
alignItems: "center",
borderRadius: theme.borderRadius[4],
border: `solid 1px ${theme.colors.borderMain}`,
backgroundColor: theme.colors.backgroundControls,
-
"&:has([data-input-field-input]:focus), &:focus": {
outline: `solid 2px ${theme.colors.borderFocus}`,
outlineOffset: "-1px",
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 4309d1055f..0bc2a8ff89 100644
--- a/packages/design-system/src/components/primitives/numeric-gesture-control.ts
+++ b/packages/design-system/src/components/primitives/numeric-gesture-control.ts
@@ -199,9 +199,11 @@ const requestPointerLock = (
// albeit without an infinite cursor ux.
if (shouldUsePointerLock) {
targetNode.requestPointerLock();
- const cursorNode = (targetNode.ownerDocument.querySelector("#cursor") ||
+ const cursorNode = (targetNode.ownerDocument.querySelector(
+ "#numeric-guesture-control-cursor"
+ ) ||
new Range().createContextualFragment(`
- <svg id="cursor" version="1.1" xmlns="http://www.w3.org/2000/svg" width="46" height="15">
+ <svg id="numeric-guesture-control-cursor" version="1.1" xmlns="http://www.w3.org/2000/svg" width="46" height="15">
<g transform="translate(2 3)">
<path d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z" fill="#111" fill-rule="evenodd" stroke="#FFF" stroke-width="2"></path>
<path d="M 15 4.5L 15 2L 11.5 5.5L 15 9L 15 6.5L 31 6.5L 31 9L 34.5 5.5L 31 2L 31 4.5Z" fill="#111" fill-rule="evenodd"></path>
@@ -211,6 +213,7 @@ const requestPointerLock = (
state.direction === "horizontal" ? "0 1px" : "1px 0"
} 1.1px rgba(0,0,0,.4))`;
cursorNode.style.position = "absolute";
+ cursorNode.style.zIndex = Number.MAX_SAFE_INTEGER.toString();
cursorNode.style.left = `${event.clientX}px`;
cursorNode.style.top = `${event.clientY}px`;
cursorNode.style.transform = `translate(-50%, -50%) ${
diff --git a/packages/design-system/src/components/primitives/use-scrub.ts b/packages/design-system/src/components/primitives/use-scrub.ts
new file mode 100644
index 0000000000..ca2bc52a29
--- /dev/null
+++ b/packages/design-system/src/components/primitives/use-scrub.ts
@@ -0,0 +1,74 @@
+import { useEffect, useRef } from "react";
+import {
+ numericScrubControl,
+ type NumericScrubValue,
+} from "./numeric-gesture-control";
+import { unstable_batchedUpdates as unstableBatchedUpdates } from "react-dom";
+
+export const useScrub = ({
+ value,
+ onChange,
+ onChangeComplete,
+ shouldHandleEvent,
+}: {
+ value: NumericScrubValue;
+ onChange: (value: NumericScrubValue) => void;
+ onChangeComplete?: (value: NumericScrubValue) => void;
+ shouldHandleEvent?: (node: EventTarget) => boolean;
+}) => {
+ const scrubRef = useRef<HTMLDivElement | null>(null);
+ const inputRef = useRef<HTMLInputElement | null>(null);
+
+ const onChangeRef = useRef(onChange);
+ onChangeRef.current = onChange;
+
+ const onChangeCompleteRef = useRef(onChangeComplete);
+ onChangeCompleteRef.current = onChangeComplete;
+
+ const valueRef = useRef(value);
+ valueRef.current = value;
+
+ const shouldHandleEventRef = useRef(shouldHandleEvent);
+ shouldHandleEventRef.current = shouldHandleEvent;
+
+ // Since scrub is going to call onChange and onChangeComplete callbacks, it will result in a new value and potentially new callback refs.
+ // We need this effect to ONLY run when type or unit changes, but not when callbacks or value.value changes.
+ useEffect(() => {
+ const inputRefCurrent = inputRef.current;
+ const scrubRefCurrent = scrubRef.current;
+ if (inputRefCurrent === null || scrubRefCurrent === null) {
+ return;
+ }
+
+ const scrub = numericScrubControl(scrubRefCurrent, {
+ getValue: () => {
+ return valueRef.current;
+ },
+ onValueInput(event) {
+ // Moving focus to container of the input to hide the caret
+ // (it makes text harder to read and may jump around as you scrub)
+ scrubRef.current?.setAttribute("tabindex", "-1");
+ scrubRef.current?.focus();
+
+ onChangeRef.current(event.value);
+ },
+ onValueChange(event) {
+ // Will work without but depends on order of setState updates
+ // at text-control, now fixed in both places (order of updates is right, and batched here)
+ unstableBatchedUpdates(() => {
+ onChangeCompleteRef.current?.(event.value);
+ });
+
+ // Returning focus that we've moved above
+ scrubRef.current?.removeAttribute("tabindex");
+ inputRef.current?.focus();
+ inputRef.current?.select();
+ },
+ shouldHandleEvent: shouldHandleEventRef.current,
+ });
+
+ return scrub.disconnectedCallback;
+ }, []);
+
+ return { scrubRef, inputRef };
+};
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index 94de4f7df9..f9e1965de3 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -77,6 +77,7 @@ export * from "./components/primitives/numeric-gesture-control";
export * from "./components/primitives/is-truncated";
export * from "./components/primitives/arrow-focus";
export * from "./components/scroll-area";
+export * from "./components/primitives/use-scrub";
// Deprecated
diff --git a/packages/prisma-client/migrations-cli/commands.ts b/packages/prisma-client/migrations-cli/commands.ts
index fb85896796..4538f5a6bb 100644
--- a/packages/prisma-client/migrations-cli/commands.ts
+++ b/packages/prisma-client/migrations-cli/commands.ts
@@ -197,14 +197,14 @@ export const createData = async ({ name }: { name: string }) => {
let schemaContent = fs.readFileSync(prismaMigrations.schemaFilePath, "utf8");
schemaContent = `// DO NOT EDIT THIS FILE!
-// This is a copy of your schema.prisma that corresponds to the state of the database
+// This is a copy of your schema.prisma that corresponds to the state of the database
// when all migrations up until this one are applied.
// It's used to generate a Prisma Client for the migration.
${schemaContent}`;
schemaContent = schemaContent.replace(
- "// <output-placeholder-for-migrations>",
+ /\/\/[\s]*<output-placeholder-for-migrations>[\s\S]*?\/\/[\s]*<\/output-placeholder-for-migrations>/g,
`output = "client"`
);
@@ -247,7 +247,7 @@ const up = async () => {
} catch (error) {
throw new UserError(
`Could not acquire lock!
-This means that another process is already running migrations.
+This means that another process is already running migrations.
If you're sure no other process is running, please delete the lockfile:
$ rm ${lockfilePath}`
);
diff --git a/packages/prisma-client/prisma/migrations/20230412160008_min-width-remove/migration.ts b/packages/prisma-client/prisma/migrations/20230412160008_min-width-remove/migration.ts
new file mode 100644
index 0000000000..a375bf1827
--- /dev/null
+++ b/packages/prisma-client/prisma/migrations/20230412160008_min-width-remove/migration.ts
@@ -0,0 +1,35 @@
+import { PrismaClient } from "./client";
+
+// NOTE ON IMPORTS:
+//
+// We want to be able to run old migrations at any point.
+// For example, when we setting up a fresh database or making a reset.
+//
+// You shouldn't import code that may change later
+// and become incompatible with the migration.
+// It's better to copy it to the migration directory.
+
+export default () => {
+ const client = new PrismaClient({
+ // Uncomment to see the queries in console as the migration runs
+ // log: ["query", "info", "warn", "error"],
+ });
+ return client.$transaction(
+ async (prisma) => {
+ /*
+ There are no minWidth: 0 inside other breakpoints anymore. Manually tested with
+ select distinct((breakpoints::jsonb #> '{1, minWidth}')::int) from "Build";
+
+ Below in jsonb syntax:
+ #> means select by path
+ #- remove at path
+ */
+ await prisma.$executeRaw`
+ UPDATE "Build"
+ SET breakpoints = (breakpoints::jsonb #- '{0, minWidth}')::text
+ WHERE (breakpoints::jsonb #> '{0, minWidth}')::int = 0;
+ `;
+ },
+ { timeout: 1000 * 60 }
+ );
+};
diff --git a/packages/prisma-client/prisma/migrations/20230412160008_min-width-remove/schema.prisma b/packages/prisma-client/prisma/migrations/20230412160008_min-width-remove/schema.prisma
new file mode 100644
index 0000000000..cbb4923904
--- /dev/null
+++ b/packages/prisma-client/prisma/migrations/20230412160008_min-width-remove/schema.prisma
@@ -0,0 +1,129 @@
+// DO NOT EDIT THIS FILE!
+// This is a copy of your schema.prisma that corresponds to the state of the database
+// when all migrations up until this one are applied.
+// It's used to generate a Prisma Client for the migration.
+
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+generator client {
+ provider = "prisma-client-js"
+ previewFeatures = ["views", "clientExtensions"]
+ // see commands.ts
+ output = "client"
+}
+
+datasource db {
+ provider = "postgres"
+ url = env("DATABASE_URL")
+}
+
+model Team {
+ id String @id @default(uuid())
+ users User[]
+}
+
+enum Location {
+ FS
+ REMOTE
+}
+
+enum UploadStatus {
+ UPLOADING
+ UPLOADED
+}
+
+model Asset {
+ id String @default(uuid()) // not unique!
+ projectId String
+ format String
+ size Int
+ name String
+ description String?
+ location Location
+ createdAt DateTime @default(now())
+ meta String @default("{}")
+ status UploadStatus @default(UPLOADED)
+
+ @@id([id, projectId])
+}
+
+model User {
+ id String @id @default(uuid())
+ email String? @unique
+ provider String?
+ image String?
+ username String?
+ createdAt DateTime @default(now())
+ team Team? @relation(fields: [teamId], references: [id])
+ teamId String?
+ projects Project[]
+}
+
+model Project {
+ id String @id @default(uuid())
+ createdAt DateTime @default(now())
+ title String
+ domain String @unique
+ user User? @relation(fields: [userId], references: [id])
+ userId String?
+ build Build[]
+ isDeleted Boolean @default(false)
+
+ @@unique([id, isDeleted])
+ @@unique([domain, isDeleted])
+}
+
+model Build {
+ id String @default(uuid())
+ createdAt DateTime @default(now())
+ pages String
+
+ project Project @relation(fields: [projectId], references: [id])
+ projectId String
+
+ isDev Boolean // exctly one is true per project
+ isProd Boolean // at most one is true per project (none if not published)
+
+ breakpoints String @default("[]")
+ styles String @default("[]")
+ styleSources String @default("[]")
+ styleSourceSelections String @default("[]")
+ props String @default("[]")
+ instances String @default("[]")
+
+ @@id([id, projectId])
+}
+
+model Breakpoints {
+ buildId String @id
+ values String @default("[]")
+}
+
+enum AuthorizationRelation {
+ viewers
+ editors
+ builders
+}
+
+model AuthorizationToken {
+ token String @default(uuid())
+ // No relation to Project, as the Authorization system is not tied to a project
+ projectId String
+ name String @default("")
+ relation AuthorizationRelation @default(viewers)
+ createdAt DateTime @default(now())
+
+ @@id([token, projectId])
+}
+
+// Dashboard
+view DashboardProject {
+ id String @id @default(uuid())
+ createdAt DateTime @default(now())
+ title String
+ domain String
+ userId String?
+ isDeleted Boolean @default(false)
+ isPublished Boolean
+}
diff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prisma
index 415ec9dcd5..e4af886017 100644
--- a/packages/prisma-client/prisma/schema.prisma
+++ b/packages/prisma-client/prisma/schema.prisma
@@ -4,8 +4,10 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["views", "clientExtensions"]
- output = "../src/__generated__"
+ // see commands.ts
// <output-placeholder-for-migrations>
+ output = "../src/__generated__"
+ // </output-placeholder-for-migrations>
}
datasource db {