Files
webstudio/apps/builder/app/shared/breakpoints/group-breakpoints.ts
T
Bogdan Chadkin 524f83203e refactor: support nanostores as sync objects (#4454)
Here added support for syncing nanostores atoms
as sync objects. Had to add some tracking of update source though it
seems like a more solid solution than previous variant.

Need to test performance caz stores updates are now synchronous and not
debounced anymore.
2024-11-21 18:17:28 +07:00

18 lines
650 B
TypeScript

import { compareMedia } from "@webstudio-is/css-engine";
import { isBaseBreakpoint } from "../nano-states";
// 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];
};