/** * How large the canvas draws the page it is previewing. * * The canvas has always had a scale, and it has never been the author's. It is * derived to make the requested width fit the region left over after the * panels, so opening a panel silently shrinks the page — measured at 89% with * the rail alone and 59.5% with a panel open. Nothing said which of those an * author was looking at, and nothing let them choose. * * ## Fit is a CHOICE, not the absence of one * * Modelled as a discriminated union rather than a nullable number, because * "fit" and "a scale I picked" are different intentions and a caller has to * tell them apart. `null` meaning fit would be the same overloaded absence * that a `number | null` scale invites: is it unset, is it fitting, or did * something fail to measure? * * Fit RE-DERIVES on every layout change, which is what makes it fit; a fixed * scale deliberately does not, so opening a panel narrows what is visible * rather than shrinking the page under the author. * * ## Why a percentage is absolute, and not a multiplier of the fit * * A multiplier is the obvious composition and it makes the number a lie: an * author choosing 100% is asking for actual size, and "fit × 1" is whatever * the panels happen to leave. Every editor that shows a zoom percentage means * the absolute one, so the number here means what it says and Fit is the mode * that computes one. * * @module canvas-zoom */ /** What the canvas was asked to draw at. */ type CanvasZoom = { readonly kind: "fit"; } | { readonly kind: "fixed"; readonly scale: number; }; /** The default, and what every canvas did before there was a choice. */ declare const FIT_ZOOM: CanvasZoom; /** * The steps the control offers, as fractions. * * Discrete rather than continuous. A slider or a free number invites values * whose arithmetic is exact and whose result is unreadable — 37% of a page is * not a view of anything — and every comparable editor offers steps for the * same reason. `1` is in the middle of the list because actual size is the * value an author returns to. */ declare const ZOOM_STEPS: readonly number[]; /** * The bounds a stored or typed scale is held to. * * Wider than the steps, because a value can arrive from storage written by a * later version, and clamping is what keeps that from painting the canvas * somewhere unreachable. Below the floor the page is illegible; above the * ceiling one block fills the region and the author has lost the page. */ declare const MIN_ZOOM = .25; declare const MAX_ZOOM = 4; /** * A stored value read back as a zoom, or `null` when it is not one. * * `null` rather than a silent fall back to fit: a caller restoring preferences * needs to know it found nothing, and a fixed scale that quietly became fit * would look to an author like the editor forgetting what they chose. */ declare function readZoom(value: unknown): CanvasZoom | null; /** A zoom as it is stored: the string `"fit"`, or the scale itself. */ declare function writeZoom(zoom: CanvasZoom): "fit" | number; /** * The next step in a direction, or the same zoom when there is none. * * From FIT it steps off the scale the fit produced, so the first press moves * from what the author is looking at rather than jumping to an end of the * list. That needs the fit scale passed in, because only the canvas knows it. * * A scale the canvas cannot paint steps from the fit scale as well, for the * same reason and by the rule {@link usableScale} states: a host can construct * `{ kind: "fixed", scale }` with any number the type admits, and the canvas * already falls back to fit when it cannot use one. Stepping from the raw value * instead makes every comparison against `NaN` false, so both directions return * the zoom unchanged — leaving a stepper that cannot move off an unusable * scale, while the canvas is meanwhile painting the fit the steps would come * from. */ declare function steppedZoom(zoom: CanvasZoom, fitScale: number, direction: "in" | "out"): CanvasZoom; /** * Which sections of the block panel are open: each tab's sections fold on * their own, and stay as the author left them across selections and visits. * * Kept per tab and section NAME (`style:Spacing`), not per block, because an * author working on spacing selects one block after another and means to keep * Spacing open on each. "Expand all" and "Collapse all" store one entry for * the tab (`style:*`) and drop the tab's own, so they reach sections the panel * has not drawn yet. * * Held with the shell's other preferences (`panel-folds-context` lends them * to the panel). * * @module panel-folds */ /** The open or closed state of each section the author has folded. */ type SectionFolds = Readonly>; /** * The panels the left rail switches between, in the order an author meets * them. * * One at a time, by decision (PB-D17 D10-1): fixed sides, no docking, no * floating. The rail selects; it never opens a second panel beside the first. * Settings and Help sit at the rail's foot as dialogs, never panels, so * neither is one of these. */ declare const LEFT_PANELS: readonly ["add", "layers", "pages", "components", "design"]; type LeftPanel = (typeof LEFT_PANELS)[number]; /** * Whether a stored value still names a panel. * * Persisted preferences outlive the code that wrote them. A panel removed in a * later release leaves a string nothing answers to, and restoring it blindly * opens a panel that renders nothing — an empty region with no way back to a * real one. */ declare function isLeftPanel(value: unknown): value is LeftPanel; /** * Width bounds for the two resizable regions, in CSS pixels. * * DECLARED here and enforced by `react-resizable-panels`, which takes pixel * bounds directly (`minSize={240}`) and solves them — including which region * yields when a window resize leaves no room. This module deliberately does NOT * solve them a second time: a hand-rolled clamp beside a library that already * constrains the same drag is two answers to one question, and the two disagree * the first time the library changes how it distributes a shortfall. * * Lower bounds are the point below which a region stops being usable rather than * round numbers: a layers tree needs an indent plus a label, and the inspector * carries two-column controls. * * `MIN_CANVAS_WIDTH` is the reason bounds cannot be read per-panel. At the * minimum supported viewport, both panels at their individual maximums leave the * canvas at 232px — narrower than either panel, in an editor whose subject IS * the canvas — and no per-panel bound is violated, because the constraint was * never per-panel. Expressed as the canvas panel's OWN minimum, the library * enforces it jointly during a drag. */ declare const PANEL_BOUNDS: { readonly left: { readonly min: 240; readonly max: 480; readonly initial: 300; }; readonly inspector: { readonly min: 308; readonly max: 520; readonly initial: 320; }; }; /** * The rail's fixed width in CSS pixels: a 36px icon square with 6px either * side. The rail shows icons alone, each named by its tooltip, so it gives the * canvas back the width a labelled rail took. */ declare const RAIL_WIDTH = 48; /** * The narrowest the canvas may become before a drag stops taking from it. * * The canvas is the thing being edited, so it is the region with a floor rather * than the one that absorbs whatever is left. * * This is the EDITING SURFACE, and {@link MIN_CANVAS_PANEL_WIDTH} is what a * bound is read from. */ declare const MIN_CANVAS_WIDTH = 480; /** * The narrowest the canvas PANEL may become. * * The page meets the panel's edges with no gap around it, so the panel and the * editing surface it holds are one width, and the panel's floor is the * surface's own. Named apart from {@link MIN_CANVAS_WIDTH} because it is what * a resize bound is read from, and the surface is what the floor protects. */ declare const MIN_CANVAS_PANEL_WIDTH: number; /** * The narrowest viewport the full shell is supported at (PB-D17 D10-5). * * Below this the rail, both panels and a usable canvas do not fit at their * minimum widths, so the shell does not try: it shows the canvas and says where * to edit instead. A builder that merely gets cramped is worse than one that * says it needs more width, because the author discovers the limit by failing * at a task. */ declare const MIN_SHELL_WIDTH = 1280; /** * Whether a box of this width can carry the full shell. * * The parameter is the width of the space the shell was GIVEN, not the * window's. The shell sizes to its container, so the two differ whenever it is * embedded — a narrow column on a wide display being the case that matters. */ declare function fitsFullShell(width: number): boolean; /** * What the shell remembers between sessions. * * The layout is stored as the PROPORTIONAL map `react-resizable-panels` reports * from `onLayoutChanged` — panel id to a percentage — never as pixel widths. A * pixel layout is wrong on the next monitor; a proportional one survives a * window resize, and the pixel BOUNDS still hold because the library re-applies * them to whatever the proportions resolve to. * * Deliberately NOT stored: selection, scroll position, or anything describing * the document. Those belong to the document's own state, and a copy here is a * second source that goes stale the first time the document changes underneath * it. */ interface ShellPreferences { leftPanel: LeftPanel | null; /** * Which part of a panel is showing, for a panel with parts — the Design * panel's tab. The host decides what the names mean; the shell only keeps * the one the author last chose. */ leftPanelView: string | null; leftPinned: boolean; /** * Whether the author has hidden a side of the editor to give the canvas the * room. Kept apart from which left panel is open, so hiding the left side * and showing it again comes back to the same panel. The top bar's panel * buttons and mod+backslash set them. */ leftPanelHidden: boolean; inspectorHidden: boolean; /** * How large the canvas draws the page, as the author last left it. * * Chrome rather than document state, like everything else here: it describes * how one person is looking at the editor, not what the page IS, so it must * not travel with the document to another author. */ zoom: CanvasZoom; /** * The breakpoint the author is styling, as they last chose it: an id from the * site's breakpoints, or null for the base one, which is named Desktop. * * A choice, never a reading. Taking it from the width the canvas measured * made opening a panel, or a narrower window, move every edit to a narrower * breakpoint the author never picked. Opening and closing panels changes * only how far the canvas is zoomed to fit. * * Stored as the author left it even when the site no longer defines that * breakpoint: the host resolves an unknown id to the base one, so removing a * breakpoint and adding it back does not lose the choice. */ editingBreakpoint: string | null; /** * Layouts, one per PANEL TOPOLOGY. * * Keyed rather than singular because a layout only means anything alongside * the panel set it was measured for. The left panel is conditionally * rendered, so the group has two shapes — with it and without — and their * layouts have different keys and different arithmetic. Stored as one record * they overwrote each other: resizing with a panel open and then closing it * left a three-key layout that no two-panel group could accept, so the widths * were dropped on the next load. * * This is the shape the panel library's own persistence helper uses, for the * same reason — its `panelIds` prop exists so a group with conditionally * rendered panels can "save and restore multiple layouts". * * Outer key: {@link topologyKey} over the mounted panel ids. * Inner: panel id to percentage. */ layouts: Record>; /** * Whether the rail's single-letter keys (A, L, P, C, D) open its panels. * * ON by default, and a preference because a key with no modifier can be * set off by speech input or a stray press: WCAG 2.1.4 asks that such a * shortcut can be turned off. Help holds the switch, beside the keys. * * Optional in this published type, so a host that builds preferences * written before the switch still compiles; absent reads as on. */ panelKeys?: boolean; /** * Which sections of the block panel the author left open or closed, by tab * and section name (`panel-folds`). * * Optional in this published type, as `panelKeys` is; absent reads as none * remembered. */ sectionFolds?: SectionFolds; /** * Whether the block panel prints each control's CSS names under its label * ("Show CSS names" in the panel's options menu). Off by default, and * optional in this published type, as `panelKeys` is: absent reads as off. */ showCssNames?: boolean; } /** * The class marking the editor shell's own root element. * * The scope every piece of editor chrome is drawn inside. Kept here and away * from the component because `builder-chrome.css` has to spell it out * literally, and a marker spelled out literally is one a rename can break * silently: so it has one exported spelling that the shell writing it, the * code asking about it and the test pinning the stylesheet all take from. */ declare const BUILDER_CHROME_CLASS = "nx-builder-chrome"; /** * A scope that resolves `--nx-builder-*` without claiming to be the chrome root. * * For a surface the shell mounts OUTSIDE {@link BUILDER_CHROME_CLASS} — custom * properties inherit down and never across, so such a surface needs the tokens * declared on an ancestor of its own. Giving it the chrome class instead would * put a second chrome root in the document, and every selector and query * meaning "the editor" would match whichever came first. */ declare const BUILDER_TOKENS_CLASS = "nx-builder-tokens"; /** * The class marking the canvas root, and the boundary the hit-test stops at. * * Here rather than in `canvas.tsx` for the reason above: it is the middle term * of the empty-container affordance's selector, which `empty-slot.ts` composes * — and reaching into the canvas COMPONENT for it would pull a React module * into every consumer of that constant, for one string. `canvas.tsx` re-exports * it, so callers reading it as the canvas's own marker are unaffected. * * The hit-test walk needs an upper bound (see `nodeIdFromEvent`), and that * bound has to be identifiable from a DOM node rather than from React state, * because the walk starts at an event target and climbs. */ declare const CANVAS_ROOT_CLASS = "nx-canvas"; /** * The identity of a panel arrangement, from the panels themselves. * * Sorted and joined rather than taken from `leftPanel`, so it is derived from * what is actually MOUNTED rather than from a second description of it that can * disagree. Sorting makes it independent of the order the ids arrive in, which * varies with how a host's JSON was serialised. */ declare function topologyKey(panelIds: readonly string[]): string; declare const DEFAULT_PREFERENCES: ShellPreferences; /** * Where preferences are read and written. * * A PORT rather than a direct `localStorage` call, for two reasons that both * bite later. The ratified plan wants these durable per user on the server * eventually, and a component reaching for `localStorage` makes that a rewrite * instead of a different argument. And `localStorage` does not exist while the * shell renders on a server, so a direct call is a crash rather than a default. * * Both methods may fail and the shell must not care: storage is unavailable in * private browsing on some engines, and a quota error is possible on write. */ interface PreferenceStore { read: () => string | null; write: (value: string) => void; } /** A store that remembers nothing, for a server render and for a browser that refuses storage. */ declare const NO_STORAGE: PreferenceStore; /** * A `localStorage`-backed store under one key. * * Takes the key rather than owning one, so the shell's chrome preferences and * anything else the editor remembers share this port instead of each writing * their own `typeof window` check and their own swallow. Outside a browser it * degrades to {@link NO_STORAGE} rather than throwing, which is the whole * reason the port exists. * * @param key - where to store the value * @returns a store, or one that remembers nothing outside a browser * * @experimental */ declare function browserStore(key: string): PreferenceStore; /** * Where the shell keeps its preferences in a browser: under this key alone * for a host that names no user, and under this key and the user's id for * one that does. */ declare const SHELL_PREFERENCES_KEY = "nextly.builder.shell"; /** * The shell's preferences for one signed-in user, so two authors of one * browser each get their own panel, device and zoom. * * Preferences stored before they were kept per user sit under the shell's key * alone. The first user to load with no record of their own takes that one: * it is copied to theirs and removed, so it moves once and no second author * inherits it. With no user known (signed out, or not read yet), nothing is * remembered: a record kept for a guess would be read by the wrong author. * * A host whose browser storage follows rules of its own (a site that keeps * nothing on the device, a sign-out that forgets the person) passes `open`, * which opens the store under a key; both records, the user's and the one * from before, are then read, written and removed through it alone. * * @param userId - the signed-in user's id, or null when there is none * @param open - opens the store under a key; this browser's storage by default * @returns a store under that user's own key, or one that keeps nothing */ declare function userPreferenceStore(userId: string | null, open?: OpenPreferenceStore): PreferenceStore; /** * Opens the store under a key, one that can also remove what it holds: the * record from before is removed once moved, so no second author inherits it. * * @experimental */ type OpenPreferenceStore = (key: string) => PreferenceStore & { remove: () => void; }; /** * Preferences parsed from whatever was stored. * * Every field is validated separately and falls back on its own, rather than * one malformed field discarding the rest. A layout written under a different * panel set should reset the layout, not the author's panel choice with it. * * Only the fields named below are read, and anything else in the record is * ignored rather than refused. Records written by an earlier release still * carry `showEmptyElements`, a preference that no longer exists because empty * containers are always shown: such a record loads whole, without it. */ declare function readPreferences(store: PreferenceStore): ShellPreferences; /** Preferences written back, ignoring a store that refuses. */ declare function writePreferences(store: PreferenceStore, preferences: ShellPreferences): void; /** * The panel a rail click selects. * * Clicking the open panel's own rail item CLOSES it. That is what makes the * rail a toggle rather than a one-way switch, and it is the only way to reach a * full-width canvas without a separate control. */ declare function panelAfterRailClick(current: LeftPanel | null, clicked: LeftPanel): LeftPanel | null; export { readZoom as A, userPreferenceStore as C, MAX_ZOOM as D, FIT_ZOOM as E, writeZoom as M, MIN_ZOOM as O, topologyKey as S, CanvasZoom as T, browserStore as _, LEFT_PANELS as a, panelAfterRailClick as b, MIN_CANVAS_WIDTH as c, OpenPreferenceStore as d, PANEL_BOUNDS as f, ShellPreferences as g, SHELL_PREFERENCES_KEY as h, DEFAULT_PREFERENCES as i, steppedZoom as j, ZOOM_STEPS as k, MIN_SHELL_WIDTH as l, RAIL_WIDTH as m, BUILDER_TOKENS_CLASS as n, LeftPanel as o, PreferenceStore as p, CANVAS_ROOT_CLASS as r, MIN_CANVAS_PANEL_WIDTH as s, BUILDER_CHROME_CLASS as t, NO_STORAGE as u, fitsFullShell as v, writePreferences as w, readPreferences as x, isLeftPanel as y }; //# sourceMappingURL=shell-state-cTWI_x2H.d.ts.map