strata-react 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -209,7 +209,7 @@ thousands of lines. Such an app imports the same stylesheet **without the reset*
209
209
 
210
210
  | Group | Exports | Notes |
211
211
  |---|---|---|
212
- | Actions | `Button`, `IconButton`, `RowAction`, `AsyncButton`, `useAsyncAction` | Default is `outline`; one filled button per view; `IconButton` requires `label`; `RowAction` is named for its row ("Withdraw Tom Ellery"); `AsyncButton` keeps one width through idle, pending, done and error, and announces `error` with its retry label; buttons carry `data-variant` and `AsyncButton` `data-phase` for tests; a `title` is refused (type `never`, and a development warning): a tip is a `Tooltip`, or `IconButton`'s `label` and `hint`; `useAsyncAction` returns `{ phase, run, error, thrown, fieldErrors, clearFieldError }` with a stable `run`, describes an `HttpError` in a sentence with the server's own reason for a 4xx (`describeActionError`, or the product's own `describeError`), and `validate` plus a server's 422 put messages on `fieldErrors` for each `Field` |
212
+ | Actions | `Button`, `IconButton`, `RowAction`, `AsyncButton`, `useAsyncAction` | Default is `outline`; one filled button per view; `size="lg"` is the one big action for small fingers (a round's Check), not moved by density; `IconButton` requires `label`; `RowAction` is named for its row ("Withdraw Tom Ellery"); `AsyncButton` keeps one width through idle, pending, done and error, and announces `error` with its retry label; buttons carry `data-variant` and `AsyncButton` `data-phase` for tests; a `title` is refused (type `never`, and a development warning): a tip is a `Tooltip`, or `IconButton`'s `label` and `hint`; `useAsyncAction` returns `{ phase, run, error, thrown, fieldErrors, clearFieldError }` with a stable `run`, describes an `HttpError` in a sentence with the server's own reason for a 4xx (`describeActionError`, or the product's own `describeError`), and `validate` plus a server's 422 put messages on `fieldErrors` for each `Field` |
213
213
  | Form | `Field`, `Input`, `Textarea`, `NativeSelect`, `ChoiceGroup`, `Checkbox` | `Field` wires label, hint, error, `aria-describedby`, `aria-invalid`, and `action` puts a one-field form's button on the control's row with the hint and error under both; `Checkbox` requires `label` and is one target with it, and has a mixed state |
214
214
  | Status and figures | `Status`, `Metric`, `MetricStrip`, `Meter`, `crossedThreshold`, `CompositionBar`, `WorkflowSteps`, `WorkflowSummary`, `JobsTable`, `ScheduleTable`, `SystemPanel`, `useSystemInfo`, `PauseButton` | A status is always a word; figures have no icons or sparklines; `Meter` is a `meter` named for what it measures, with its reading in words ("72% used"), threshold notches, and a `Status` word once a threshold is crossed (each threshold must name its state); `CompositionBar` is a stacked bar over a table naming every part, its amount and share, and names the remainder (`total` needs `restLabel`); `other={{ label }}` folds data-driven parts past five into one "Other" part (the four largest stay in order), and a production build folds instead of throwing; a part that is there reads "<1%" and keeps a sliver, never "0%"; `JobStatus` is a long-running server job (its `progress` `{ done, total, current }` reads "12 of 40 done, 28 remaining · IMG_0412"; `useJobAction` starts one: busy until the server answers, a "queued" toast with a link to the jobs page, a "finished" toast when it ends): a required word per state beside the app's sentence, a progress bar when the total is known, each failure named with its reason, announced only when the item changes or the job ends; `WorkflowSteps` draws strata-python's shared `WorkflowRun` (`/api/workflows/<pipeline>/subjects/<id>`): each stage's state as a word, when it ran and how long it took, a failed stage's error with Try again, and Approve on a waiting gate (the first is the view's filled button), saying who approved or that its policy did; `JobsTable` is the shared jobs page (`GET /api/jobs`): each job's state as a word with its progress or error, and Cancel or Run again only where they apply. Both take the app's generated `Schema<"WorkflowRun">` and `Schema<"Task">` as they come; `ScheduleTable` is a machine's scheduled jobs (systemd timers, cron), not the queue: each job's last result as a word (OK, Failed, Running, Never run), when it last ran and when it runs next, the last two dropping on a phone; `SystemPanel` is strata-python's `GET /api/system` (`useSystemInfo()` reads it): version and commit, uptime, each folder as a `Meter` on shared disk limits ("Filling up", "Nearly full") or the word Missing, each service Up or Down with the server's reason, and the app's own `facts`; `PauseButton` takes the `Poll` from `usePoll` (passed to `useLoad({ poll })`): a fixed-name "Pause updates" toggle and "Updated 12:00" |
215
215
  | Data | `DataView`, `Load<T>`, `Stale`, `StaleNotice`, `LoadError`, `EmptyState`, `Skeleton`, `Thumbnail`, `ThumbnailSkeleton`, `DataTable`, `TableSkeleton`, `VirtualList`, `InfiniteList`, `LoadMore`, `useInView`, `LineChart` | `DataView` requires skeleton and empty, keeps data on screen under a `StaleNotice` (why, how old, Try again) when a refresh fails, and takes an `error` renderer for an app's own look of a failed read (default `LoadError`, always inside an alert); `Thumbnail` is a remote image in a box of fixed `aspect`, with a skeleton while it loads, the required `missing` words (or a `fallback` drawing, such as an avatar's initial) when it fails or `src` is null, required `alt`, `children` overlaid in its corners, and a request only once it nears the screen (`eager` for the first few); tables, lists and tile grids virtualise from 100 rows, on React Aria's Virtualizer; a `DataTable` is a React Aria table (a `grid`) over TanStack Table's data model; a `DataTable` column with `value` sorts by type with missing values last both ways and draws a placeholder (`missing`, default an en dash); `InfiniteList` loads the next page on approach, with a skeleton for it, a Try again row when it fails and a Show more button for the keyboard, and `scroll="page"` draws a grid that scrolls with the page; `LoadMore` is that next-page row for any list or grid; charts label values directly; `LineChart` can also follow an app's position (`current`), read a value at the pointer or by arrow keys (`readout`, one slider whose value text is the reading), report a picked x (`onPick`) and fill one flat area (`area`); `xLabel` names the x column of its table `Thumbnail`'s `src` may be a list tried in order, `onLoad` can reject a picture that loaded (a host's grey placeholder) and `onMissing` is told once when none worked; with `alt=""` and a `fallback` its missing state is presentational. `LoadMore` and `InfiniteList` can draw the Show more and loading rows the app's way (`more`, `loading`, and `ruled={false}` for no hairlines).; a `DataTable` column's `hideBelow="sm"` hides its header and cells together on a narrow screen (CSS only; a virtualised table drops the column by a media query), never a hand-written `matchMedia` filter |
@@ -247,7 +247,7 @@ thousands of lines. Such an app imports the same stylesheet **without the reset*
247
247
  | Maps | `strata-react/map`: `RouteMap`; `geo`, `LatLng` (main entry) | Routes and a position that moves along them, on Leaflet (no react-leaflet), behind its own entry. Tiles are the app's (`tiles.light`, `tiles.dark`, each with its attribution); the dark scheme uses the dark set or a filter over the light one. Route colours are roles resolved at draw time; `values` with `colourScale` colour a route by value in runs of one step, with a key that names the steps; a single route gets direction chevrons and start/finish marks (a loop is one mark). The position is one marker moved with `setLatLng`: no route is redrawn for it (keep `routes` stable). As picture content (a route inset over footage): `zoom` sets any zoom (animate it per frame), `follow="centre"` holds the view exactly on a position with no animation (a frame is deterministic), and `positions` draws several, each tied to a route, in its colour and named in the text alternative; routes are not redrawn for any of it. Leaflet's keyboard pan and zoom stay; the map is named by `label` and described by a generated text alternative (routes, lengths, position along). Overlay slots `topEnd` and `bottomStart` avoid Leaflet's own controls and attribution. Leaflet's stylesheet is injected once, so an app imports nothing. `geo` (distance, bearing, bounds, `pointAlong`, `arrows`, `ends`) and `format.distance` need no map library |
248
248
  | Timeline | `Timeline`, `useTimelineZoom`, `TimelineZoomControls`, `noOverlap` | Items with a start and a length in lanes on a zoomable time axis, for media edits, bookings, rotas and plans. The timeline draws and the app decides: every move, trim, lane change, selection and current-time change is reported (`onItemChange`, `onSelect`, `onPositionChange`) and the app applies it; `validate` refuses a change with a reason shown in words while it is made. One tab stop for the items; arrows move between them, Ctrl+arrows nudge and change lane, Alt+arrows trim, the current time is its own slider, `+` `-` `0` zoom, and each change is announced ("run-02.mp4 moved to 0:13"). The ruler picks steps people write on a scale so labels never collide. Lanes take drops from outside (`dropTypes`, `onDrop` with the lane and snapped time, `validateDrop`, and React Aria's keyboard drag landing at the current time), `laneRows` makes them taller, `kindColours` fixes each kind's stripe, and the header column fits its content. Only items near the view are rendered |
249
249
  | Answering by tap | `ChoiceGrid`, `ChoiceGridSkeleton`, `ChoiceState`; the `type-picture` step | One question, large picture tiles, one right answer, for someone who may not read yet (a child's learning game). Each tile is `open`, `wrong` (greyed, never red), `right` or `answer` (shown after the tries ran out), always with its word; a choice with no answer key ("Which one next?", a rating) uses `picked` (primary border, neutral word, `marks={{ picked }}`), which closes the grid so a slow request cannot be tapped twice; the app owns the answer key. Answered tiles cannot be pressed again and the grid closes once the answer shows. React Aria's `GridList`: arrows across and down, Enter answers. Tiles at least 120px (`md`) or 160px (`lg`); `stretch` shares the row out so a few tiles fill a wide screen; `beckon` pulses the open tiles one at a time in a random order until the grid closes |
250
- | Answering by placing | `PlaceBoard`, `PlaceState` | An answer that is an arrangement (give a number, put in order, match pairs, sort), for someone who may not read yet. Two taps: pick a piece up (`aria-pressed`, "Picked up"), put it in a place ("Put apple in the basket"); tap it again to put it down, "Put … back" returns a placed one. Same presses by touch, mouse, keyboard and screen reader; places are disabled until a piece is held, so Tab walks the pieces, then the places; focus follows a moved piece. The app owns `placement`, applies `onMove` and checks; `placeState` marks a place `right` or `wrong` (neutral, never red) with its word, `locked` ends the round. Pieces 96px or more in the pile, 72px once placed; `beckon` pulses the pile's pieces one at a time while none is held; `stretch` shares the pile's and places' rows out; a picture never outgrows its tile |
250
+ | Answering by placing | `PlaceBoard`, `PlaceState` | An answer that is an arrangement (give a number, put in order, match pairs, sort), for someone who may not read yet. Two taps: pick a piece up (`aria-pressed`, "Picked up", a blue info ring), put it in a place ("Put apple in the basket"; every place that takes it gets the same ring); tap it again to put it down, or tap its gap in the pile ("Put … back"). Or drag it there by pointer (from the press, no long press). With one place a tap moves at once, in or out (a big X on hover). `limit` caps a place: a piece put in a full one sends the one there back ("in place of 4"). The pile keeps a slot per piece and each place room for all it can hold (a lone place takes the row), so nothing moves during a round. Same presses by touch, mouse, keyboard and screen reader; places are disabled until a piece is held, so Tab walks the pieces, then the places; focus follows a moved piece. The app owns `placement`, applies `onMove` and checks (`check` draws its big Check, `Button size="lg"` with a tick either side); `placeState` marks a place `right` or `wrong` (neutral, never red) with its word, `locked` ends the round. Pieces 96px or more in the pile, 72px once placed; `beckon` pulses the pile's pieces one at a time while none is held; `stretch` shares the pile's and places' rows out; a picture never outgrows its tile |
251
251
  | Sortable list | `SortableList` | Reorder a list and move items between lists, by pointer and by keyboard. React Aria's `GridList` with `useDragAndDrop` (no `@dnd-kit`): a grip per row is the drag handle, so clicking a row selects it and its own actions still work; Enter on the grip picks up, arrows and Tab choose a position or list, Enter drops, Escape cancels, with React Aria's screen-reader announcements. Items carry a kind (`getKind`); a list takes the kinds in `accepts` and says why it refuses another (`refuses`, shown with an icon while that kind is dragged over it). The list never changes the data: `onReorder` and `onInsert` report the move and the app applies it, undoably |
252
252
  | Drag source | `DragSource` | A row that is dragged onto a drop target elsewhere (a `Timeline` lane), by pointer or from the keyboard. React Aria's `useDrag` with a drag button: a grip named "Drag <label>" picks it up with Enter, Tab moves between targets that take its types, Enter drops, Escape cancels, with React Aria's announcements; the pointer can pick up the whole row and the row's own buttons still work. `items` returns the drag's data (`DragData`, a type to a value), read by the target |
253
253
  | File intake | `FileButton`, `FileDropZone`, `FileDropOverlay`, `FileOutcomes`, `MissingFile`, `useFileIntake` | Pick or drop local files, then one outcome per file. `FileButton` is React Aria's `FileTrigger` behind a real named button (the keyboard and phone route); `FileDropZone` is its `DropZone` and says what it takes while a drag is over it; `FileDropOverlay` (also `Workspace onFiles`) is the whole window as the target, with an overlay that names what it takes; it ignores the app's own drags (every `DragSource`'s, and any type named in `refuseTypes`), so a keyboard drag to a timeline lane does not stop on it. `useFileIntake({ accept, acceptLabel, process })` judges each file after the drop, so a wrong one is named with its reason (type, `maxBytes`, your `check`), runs your own `process` per file (a throw becomes `Failed` with its message and a retry), and never blocks the rest. `FileOutcomes` draws the rows and announces one summary per batch. `MissingFile` is a status word and a "Relink" that opens the picker for that item; the name wraps in a narrow pane and a `thumbnail` can lead it. Nothing assumes a server |
package/UPGRADING.md CHANGED
@@ -11,6 +11,12 @@ time. While the version is 0.x, any release may break.
11
11
 
12
12
  Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Changelog").
13
13
 
14
+ ## 2026-11-28 (PlaceBoard: gaps, one tap, drag)
15
+
16
+ - `PlaceBoard`'s pile keeps every piece's slot: a placed piece leaves an `aria-hidden` gap there (`[data-gap]`), and the "Put … back" button is now that gap, in the pile, while the placed piece is held. A test that found it outside the pile group or counted the pile's children sees the change.
17
+ - With exactly one place, pieces are no longer toggle buttons: a tap puts a piece in or takes it out at once, and they are named "Put apple in the basket" / "Take apple out of the basket" (no `aria-pressed`, no "Picked up"). Tests that picked a piece up and then pressed the basket press the piece once.
18
+ - Each place reserves `aria-hidden` slots (`[data-room]`) for as many pieces as it can hold (its `limit`, else every piece), and a lone place takes the whole row, so places are taller from the start. A held piece and the places that take it are drawn with the info role (a ring), not primary; a right place has a success ring. Pieces take `touch-action: none` while the board is not locked. Every `PlaceBoard` baseline moves.
19
+
14
20
  ## 2026-11-28 (Compare: above and below, ink match)
15
21
 
16
22
  - `CompareMode` has two more members, `"stack"` and `"match"`: a `Record<CompareMode, …>` in an app needs entries for them (or use `Partial`). The default `modes` is unchanged; pass them in `modes` to offer them.
@@ -69,7 +69,8 @@ const buttonVariants = cva("inline-flex max-w-full shrink-0 cursor-pointer items
69
69
  default: "h-(--control-h) px-(--control-px)",
70
70
  sm: "h-(--control-h-sm) px-(--control-px-sm)",
71
71
  icon: "size-(--control-h)",
72
- "icon-sm": "size-(--control-h-sm)"
72
+ "icon-sm": "size-(--control-h-sm)",
73
+ lg: "h-(--control-h-lg) px-(--control-px-lg) type-title [&_svg]:size-(--control-icon-lg)"
73
74
  }
74
75
  },
75
76
  defaultVariants: {
@@ -148,4 +149,4 @@ function RowAction({ label, subject, icon: Icon, variant = "ghost", size = "sm",
148
149
  }
149
150
 
150
151
  export { isDev as a, buttonVariants as i, IconButton as n, useInView as o, RowAction as r, Button$1 as t };
151
- //# sourceMappingURL=button-CYXjU-fs.js.map
152
+ //# sourceMappingURL=button-CjnotDTb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"button-CYXjU-fs.js","names":["Button","AriaButton","Tooltip"],"sources":["../src/lib/in-view.ts","../src/lib/dev.ts","../src/components/button.tsx"],"sourcesContent":["import * as React from \"react\";\n\n// One IntersectionObserver hook for everything that waits until it is near the screen: the\n// sentinel at the end of an InfiniteList and an image in a Thumbnail. Both watch from the nearest\n// `[data-strata-scroll]` region (a VirtualList's) or else the viewport, with a root\n// margin so the work starts before the element is reached. They differ in two ways, which are\n// options rather than two hooks:\n//\n// - `once`: an image, once asked for, stays asked for; scrolling it away again must not unload it.\n// A sentinel reports in and out of view every time.\n// - `unsupported`: where there is no IntersectionObserver (an old browser, a test without the\n// fake), an image loads at once, because a photo that never loads is worse than one loaded\n// early. A sentinel reports out of view, because InfiniteList's Show more button is the path\n// that always works.\n\n/** Options for {@link useInView}. */\nexport type InViewOptions = {\n /** Watch only while this is true. Default true. */\n active?: boolean;\n /** How far outside the scroll region still counts as in view (IntersectionObserver `rootMargin`). */\n rootMargin?: string;\n /** Stay in view after the first time, and stop watching. */\n once?: boolean;\n /** What to report where `IntersectionObserver` does not exist. Default false. */\n unsupported?: boolean;\n};\n\n/**\n * Whether an element is within `rootMargin` of its scroll region (the nearest\n * `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the\n * element as it mounts and unmounts.\n */\nexport function useInView({\n active = true,\n rootMargin = \"0px\",\n once = false,\n unsupported = false,\n}: InViewOptions = {}) {\n const [inView, setInView] = React.useState(false);\n const [el, setEl] = React.useState<Element | null>(null);\n const seen = once && inView;\n React.useEffect(() => {\n if (seen) return;\n if (!active || !el) {\n setInView(false);\n return;\n }\n if (typeof IntersectionObserver === \"undefined\") {\n setInView(unsupported);\n return;\n }\n const root = el.parentElement?.closest<HTMLElement>(\"[data-strata-scroll]\") ?? null;\n const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {\n root,\n rootMargin,\n });\n observer.observe(el);\n return () => observer.disconnect();\n }, [active, el, rootMargin, seen, unsupported]);\n return { ref: setEl, inView };\n}\n","// Development-only checks (a warning for a mistake a type cannot catch). `import.meta.env.DEV` is\n// replaced by the library build itself, so in the published package it is always false and the check\n// never runs in an app's development. `process.env.NODE_ENV` is left for the app's bundler to replace\n// (Vite, webpack and the rest do, in dependencies too), so the app decides. Where nothing replaces it\n// `process` does not exist, and the check is off.\n\n/** Whether the app is running in development, decided by the app's bundler. */\nexport function isDev(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n","import * as React from \"react\";\nimport { Button as AriaButton, type PressEvent } from \"react-aria-components\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport type { IconComponent } from \"../lib/icon\";\nimport { cn } from \"../lib/utils\";\nimport type { ControlSize } from \"../lib/control\";\nimport { Tooltip } from \"./tooltip\";\nimport { isDev } from \"../lib/dev\";\n\n// Variant names are shadcn's, so copied code and agents' prior knowledge still work. Two things\n// differ on purpose:\n// 1. The default variant is `outline`, not the filled accent. A bare <Button> is the restrained\n// one; the accent (`variant=\"default\"`) has to be asked for, once per view. Generated app screens\n// put the accent on every button; 12 of 23 real product screens had no filled primary at all.\n// 2. Heights come from --control-h, shared with Input and NativeSelect, so density changes move\n// every control together.\n// 3. React Aria is the primitives layer (CLAUDE.md, \"The stack\"): behaviour and accessibility come\n// from it, the look from our tokens. `asChild`/`Slot` is gone; a button that navigates is a link.\n// 4. `press`: the button gives 2% under a click or a finger, over 100ms. Buttons are used tens of\n// times a day, so that is all the motion they get (character.md, the frequency budget).\n// 5. `title` is refused, not passed through (issue #231). React Aria's `Button` does not forward it,\n// so a tip moved over from a native button vanished with nothing said. Passing it through would\n// give a tip that has no keyboard focus, no touch and a long, unstyled delay; the answer is a\n// `Tooltip` (and `IconButton`'s `label` and `hint`). The type says so (`title?: never`) and, for\n// an untyped caller, so does a development warning. A button whose only child is one symbol\n// (`✕`, `−`, `+`) has no accessible name from its text and gets a development warning too.\nexport const buttonVariants = cva(\n \"inline-flex max-w-full shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control type-label transition-state press disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-(--control-icon) [&_svg]:shrink-0\",\n {\n variants: {\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary-10\",\n outline: \"border border-input bg-background text-foreground hover:bg-muted\",\n secondary: \"bg-muted text-foreground hover:bg-neutral-4\",\n ghost: \"text-foreground hover:bg-muted\",\n destructive: \"bg-destructive text-destructive-foreground hover:bg-danger\",\n link: \"h-auto px-0 text-primary-11 underline underline-offset-4 hover:text-primary-12\",\n },\n size: {\n default: \"h-(--control-h) px-(--control-px)\",\n sm: \"h-(--control-h-sm) px-(--control-px-sm)\",\n icon: \"size-(--control-h)\",\n \"icon-sm\": \"size-(--control-h-sm)\",\n },\n },\n defaultVariants: { variant: \"outline\", size: \"default\" },\n },\n);\n\nexport type ButtonProps = Omit<React.ComponentProps<\"button\">, \"className\" | \"style\" | \"title\"> &\n VariantProps<typeof buttonVariants> & {\n className?: string;\n /** Not accepted: a `title` is a poor tooltip (no keyboard focus, no touch) and React Aria's button drops it. Wrap the button in a `Tooltip`, or use `IconButton`'s `label` and `hint`. */\n title?: never;\n /** React Aria's press event (mouse, touch, pen and keyboard alike). `onClick` also works. */\n onPress?: (event: PressEvent) => void;\n /** When a press begins and ends: for a control that acts while held (a nudge that repeats). */\n onPressStart?: (event: PressEvent) => void;\n onPressEnd?: (event: PressEvent) => void;\n };\n\n/**\n * A button with shadcn's variant names, built on React Aria's `Button` (press handling that behaves\n * the same for mouse, touch, pen and keyboard, focus-visible and hover state). The default variant is\n * `outline`; ask for the filled accent (`variant=\"default\"`) once per view. `type` defaults to `button`.\n * `onClick` and `disabled` are the DOM names and keep working; `onPress` is also accepted.\n */\nexport function Button({\n className,\n variant,\n size,\n type = \"button\",\n disabled,\n children,\n \"aria-busy\": ariaBusy,\n ...props\n}: ButtonProps) {\n // React Aria's button drops `aria-busy` (it forwards only the aria props it knows), so it is set\n // on the element here; a pending row action says it is busy to a screen reader (issue #248).\n const ref = React.useRef<HTMLButtonElement>(null);\n React.useEffect(() => {\n const el = ref.current;\n if (!el) return;\n if (ariaBusy) el.setAttribute(\"aria-busy\", String(ariaBusy));\n else el.removeAttribute(\"aria-busy\");\n }, [ariaBusy]);\n if (isDev()) warnOnLoss(props as Record<string, unknown>, children);\n // data-variant says which variant was drawn, so a test can check \"one filled button per view\"\n // without reading class names (strata-react issue #48, `filledButtons` in strata-react/testing).\n return (\n <AriaButton\n ref={ref}\n type={type}\n isDisabled={disabled}\n data-variant={variant ?? \"outline\"}\n className={cn(buttonVariants({ variant, size }), className)}\n {...(props as object)}\n >\n {/* A text label that cannot fit its column is cut with an ellipsis, not drawn past the button (issue #116). */}\n {typeof children === \"string\" ? <span className=\"min-w-0 truncate\">{children}</span> : children}\n </AriaButton>\n );\n}\n\n/** Development only: what a native button had that this one loses or cannot name (issue #231). */\nfunction warnOnLoss(props: Record<string, unknown>, children: React.ReactNode) {\n if (props.title !== undefined && !warned.has(\"title\")) {\n warned.add(\"title\");\n console.warn(\n \"strata-react: Button does not pass `title` through (React Aria's button drops it, and a title has no keyboard or touch). Wrap the button in a `Tooltip`, or use IconButton's `label` and `hint`.\",\n );\n }\n const glyph = typeof children === \"string\" ? children.trim() : \"\";\n if (\n glyph &&\n Array.from(glyph).length === 1 &&\n !/[\\p{L}\\p{N}]/u.test(glyph) &&\n !props[\"aria-label\"] &&\n !props[\"aria-labelledby\"] &&\n !warned.has(\"glyph\")\n ) {\n warned.add(\"glyph\");\n console.warn(\n `strata-react: a Button whose only content is \"${glyph}\" has no accessible name. Give it an aria-label, or use an IconButton with a label.`,\n );\n }\n}\nconst warned = new Set<string>();\n\n// An icon-only button cannot be written without a name: `label` is required by the type, becomes\n// the accessible name and is shown as a `Tooltip` on hover and keyboard focus, so the name and the\n// visible hint come from one string and cannot drift. This makes the most common generated\n// accessibility defect (an unlabelled icon button) a compile error instead of an audit finding.\nexport type IconButtonProps = Omit<ButtonProps, \"size\" | \"children\" | \"aria-label\"> & {\n /** `sm` is --control-h-sm, the height of a small `Toggle` or `Button`, for a toolbar or property row. Default --control-h. */\n size?: ControlSize;\n icon: IconComponent;\n label: string;\n /** Shown after the label in its tooltip, muted: \"Ctrl+Z\". */\n hint?: React.ReactNode;\n};\n\n/** An icon-only button. `label` is required and becomes the accessible name and the tooltip (hover and keyboard focus); `hint` adds a muted aside to it, such as a shortcut. */\nexport function IconButton({\n icon: Icon,\n label,\n hint,\n variant = \"ghost\",\n size = \"default\",\n ...props\n}: IconButtonProps) {\n return (\n <Tooltip label={label} hint={hint}>\n <Button size={size === \"sm\" ? \"icon-sm\" : \"icon\"} variant={variant} aria-label={label} {...props}>\n <Icon aria-hidden />\n </Button>\n </Tooltip>\n );\n}\n\n// A row action says what it does in the row (\"Withdraw\") and whom it does it to in its name\n// (\"Withdraw Tom Ellery\"): a table of eight \"Withdraw\" buttons is eight identical names in a\n// screen reader's list of controls. The name is an aria-label that starts with the visible verb,\n// so it meets WCAG 2.5.3 (label in name) and voice control still finds it by \"Withdraw\". Visually\n// hidden suffix text is not used: a hidden span joined to the verb did not form a name with its\n// space in dom-testing-library (strata-react issue #11). Ghost and small, one per row, shown only\n// on the rows where it applies; an icon-only row action is an `IconButton` whose `label` names the\n// row the same way. It keeps the row's pitch: rows with and without the action are the same height.\nexport type RowActionProps = Omit<ButtonProps, \"children\" | \"aria-label\"> & {\n /** The visible verb, sentence case: \"Withdraw\", \"Remove\". */\n label: string;\n /** What the row is, as a person would say it: \"Tom Ellery\", \"Moonbeam\". Completes the accessible name. */\n subject: string;\n icon?: IconComponent;\n};\n\n/** A small ghost action for one table row: shows `label`, and is named \"`label` `subject`\" so every row's action has its own name. */\nexport function RowAction({\n label,\n subject,\n icon: Icon,\n variant = \"ghost\",\n size = \"sm\",\n className,\n ...props\n}: RowActionProps) {\n // -my-1.5 lets the 32px button sit in the 20px line of a table row, inside the row's padding, so\n // rows with an action keep the same pitch as rows without one.\n return (\n <Button\n variant={variant}\n size={size}\n aria-label={`${label} ${subject}`}\n className={cn(\"-my-1.5\", className)}\n {...props}\n >\n {Icon && <Icon aria-hidden />}\n {label}\n </Button>\n );\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"button-CjnotDTb.js","names":["Button","AriaButton","Tooltip"],"sources":["../src/lib/in-view.ts","../src/lib/dev.ts","../src/components/button.tsx"],"sourcesContent":["import * as React from \"react\";\n\n// One IntersectionObserver hook for everything that waits until it is near the screen: the\n// sentinel at the end of an InfiniteList and an image in a Thumbnail. Both watch from the nearest\n// `[data-strata-scroll]` region (a VirtualList's) or else the viewport, with a root\n// margin so the work starts before the element is reached. They differ in two ways, which are\n// options rather than two hooks:\n//\n// - `once`: an image, once asked for, stays asked for; scrolling it away again must not unload it.\n// A sentinel reports in and out of view every time.\n// - `unsupported`: where there is no IntersectionObserver (an old browser, a test without the\n// fake), an image loads at once, because a photo that never loads is worse than one loaded\n// early. A sentinel reports out of view, because InfiniteList's Show more button is the path\n// that always works.\n\n/** Options for {@link useInView}. */\nexport type InViewOptions = {\n /** Watch only while this is true. Default true. */\n active?: boolean;\n /** How far outside the scroll region still counts as in view (IntersectionObserver `rootMargin`). */\n rootMargin?: string;\n /** Stay in view after the first time, and stop watching. */\n once?: boolean;\n /** What to report where `IntersectionObserver` does not exist. Default false. */\n unsupported?: boolean;\n};\n\n/**\n * Whether an element is within `rootMargin` of its scroll region (the nearest\n * `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the\n * element as it mounts and unmounts.\n */\nexport function useInView({\n active = true,\n rootMargin = \"0px\",\n once = false,\n unsupported = false,\n}: InViewOptions = {}) {\n const [inView, setInView] = React.useState(false);\n const [el, setEl] = React.useState<Element | null>(null);\n const seen = once && inView;\n React.useEffect(() => {\n if (seen) return;\n if (!active || !el) {\n setInView(false);\n return;\n }\n if (typeof IntersectionObserver === \"undefined\") {\n setInView(unsupported);\n return;\n }\n const root = el.parentElement?.closest<HTMLElement>(\"[data-strata-scroll]\") ?? null;\n const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {\n root,\n rootMargin,\n });\n observer.observe(el);\n return () => observer.disconnect();\n }, [active, el, rootMargin, seen, unsupported]);\n return { ref: setEl, inView };\n}\n","// Development-only checks (a warning for a mistake a type cannot catch). `import.meta.env.DEV` is\n// replaced by the library build itself, so in the published package it is always false and the check\n// never runs in an app's development. `process.env.NODE_ENV` is left for the app's bundler to replace\n// (Vite, webpack and the rest do, in dependencies too), so the app decides. Where nothing replaces it\n// `process` does not exist, and the check is off.\n\n/** Whether the app is running in development, decided by the app's bundler. */\nexport function isDev(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n","import * as React from \"react\";\nimport { Button as AriaButton, type PressEvent } from \"react-aria-components\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport type { IconComponent } from \"../lib/icon\";\nimport { cn } from \"../lib/utils\";\nimport type { ControlSize } from \"../lib/control\";\nimport { Tooltip } from \"./tooltip\";\nimport { isDev } from \"../lib/dev\";\n\n// Variant names are shadcn's, so copied code and agents' prior knowledge still work. Two things\n// differ on purpose:\n// 1. The default variant is `outline`, not the filled accent. A bare <Button> is the restrained\n// one; the accent (`variant=\"default\"`) has to be asked for, once per view. Generated app screens\n// put the accent on every button; 12 of 23 real product screens had no filled primary at all.\n// 2. Heights come from --control-h, shared with Input and NativeSelect, so density changes move\n// every control together.\n// `lg` is the exception, sized for a child's finger and not moved by density.\n// 3. React Aria is the primitives layer (CLAUDE.md, \"The stack\"): behaviour and accessibility come\n// from it, the look from our tokens. `asChild`/`Slot` is gone; a button that navigates is a link.\n// 4. `press`: the button gives 2% under a click or a finger, over 100ms. Buttons are used tens of\n// times a day, so that is all the motion they get (character.md, the frequency budget).\n// 5. `title` is refused, not passed through (issue #231). React Aria's `Button` does not forward it,\n// so a tip moved over from a native button vanished with nothing said. Passing it through would\n// give a tip that has no keyboard focus, no touch and a long, unstyled delay; the answer is a\n// `Tooltip` (and `IconButton`'s `label` and `hint`). The type says so (`title?: never`) and, for\n// an untyped caller, so does a development warning. A button whose only child is one symbol\n// (`✕`, `−`, `+`) has no accessible name from its text and gets a development warning too.\nexport const buttonVariants = cva(\n \"inline-flex max-w-full shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-control type-label transition-state press disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-(--control-icon) [&_svg]:shrink-0\",\n {\n variants: {\n variant: {\n default: \"bg-primary text-primary-foreground hover:bg-primary-10\",\n outline: \"border border-input bg-background text-foreground hover:bg-muted\",\n secondary: \"bg-muted text-foreground hover:bg-neutral-4\",\n ghost: \"text-foreground hover:bg-muted\",\n destructive: \"bg-destructive text-destructive-foreground hover:bg-danger\",\n link: \"h-auto px-0 text-primary-11 underline underline-offset-4 hover:text-primary-12\",\n },\n size: {\n default: \"h-(--control-h) px-(--control-px)\",\n sm: \"h-(--control-h-sm) px-(--control-px-sm)\",\n icon: \"size-(--control-h)\",\n \"icon-sm\": \"size-(--control-h-sm)\",\n // The one action a young learner presses to finish a step (\"Check\"): a target several times the 44px\n // minimum, in title type with icons to match (Flashtap's owner, 2026-11-28: \"a much bigger check button\").\n // Not a ControlSize: it never sits in a toolbar row, and density does not shrink it.\n lg: \"h-(--control-h-lg) px-(--control-px-lg) type-title [&_svg]:size-(--control-icon-lg)\",\n },\n },\n defaultVariants: { variant: \"outline\", size: \"default\" },\n },\n);\n\nexport type ButtonProps = Omit<React.ComponentProps<\"button\">, \"className\" | \"style\" | \"title\"> &\n VariantProps<typeof buttonVariants> & {\n className?: string;\n /** Not accepted: a `title` is a poor tooltip (no keyboard focus, no touch) and React Aria's button drops it. Wrap the button in a `Tooltip`, or use `IconButton`'s `label` and `hint`. */\n title?: never;\n /** React Aria's press event (mouse, touch, pen and keyboard alike). `onClick` also works. */\n onPress?: (event: PressEvent) => void;\n /** When a press begins and ends: for a control that acts while held (a nudge that repeats). */\n onPressStart?: (event: PressEvent) => void;\n onPressEnd?: (event: PressEvent) => void;\n };\n\n/**\n * A button with shadcn's variant names, built on React Aria's `Button` (press handling that behaves\n * the same for mouse, touch, pen and keyboard, focus-visible and hover state). The default variant is\n * `outline`; ask for the filled accent (`variant=\"default\"`) once per view. `type` defaults to `button`.\n * `onClick` and `disabled` are the DOM names and keep working; `onPress` is also accepted.\n */\nexport function Button({\n className,\n variant,\n size,\n type = \"button\",\n disabled,\n children,\n \"aria-busy\": ariaBusy,\n ...props\n}: ButtonProps) {\n // React Aria's button drops `aria-busy` (it forwards only the aria props it knows), so it is set\n // on the element here; a pending row action says it is busy to a screen reader (issue #248).\n const ref = React.useRef<HTMLButtonElement>(null);\n React.useEffect(() => {\n const el = ref.current;\n if (!el) return;\n if (ariaBusy) el.setAttribute(\"aria-busy\", String(ariaBusy));\n else el.removeAttribute(\"aria-busy\");\n }, [ariaBusy]);\n if (isDev()) warnOnLoss(props as Record<string, unknown>, children);\n // data-variant says which variant was drawn, so a test can check \"one filled button per view\"\n // without reading class names (strata-react issue #48, `filledButtons` in strata-react/testing).\n return (\n <AriaButton\n ref={ref}\n type={type}\n isDisabled={disabled}\n data-variant={variant ?? \"outline\"}\n className={cn(buttonVariants({ variant, size }), className)}\n {...(props as object)}\n >\n {/* A text label that cannot fit its column is cut with an ellipsis, not drawn past the button (issue #116). */}\n {typeof children === \"string\" ? <span className=\"min-w-0 truncate\">{children}</span> : children}\n </AriaButton>\n );\n}\n\n/** Development only: what a native button had that this one loses or cannot name (issue #231). */\nfunction warnOnLoss(props: Record<string, unknown>, children: React.ReactNode) {\n if (props.title !== undefined && !warned.has(\"title\")) {\n warned.add(\"title\");\n console.warn(\n \"strata-react: Button does not pass `title` through (React Aria's button drops it, and a title has no keyboard or touch). Wrap the button in a `Tooltip`, or use IconButton's `label` and `hint`.\",\n );\n }\n const glyph = typeof children === \"string\" ? children.trim() : \"\";\n if (\n glyph &&\n Array.from(glyph).length === 1 &&\n !/[\\p{L}\\p{N}]/u.test(glyph) &&\n !props[\"aria-label\"] &&\n !props[\"aria-labelledby\"] &&\n !warned.has(\"glyph\")\n ) {\n warned.add(\"glyph\");\n console.warn(\n `strata-react: a Button whose only content is \"${glyph}\" has no accessible name. Give it an aria-label, or use an IconButton with a label.`,\n );\n }\n}\nconst warned = new Set<string>();\n\n// An icon-only button cannot be written without a name: `label` is required by the type, becomes\n// the accessible name and is shown as a `Tooltip` on hover and keyboard focus, so the name and the\n// visible hint come from one string and cannot drift. This makes the most common generated\n// accessibility defect (an unlabelled icon button) a compile error instead of an audit finding.\nexport type IconButtonProps = Omit<ButtonProps, \"size\" | \"children\" | \"aria-label\"> & {\n /** `sm` is --control-h-sm, the height of a small `Toggle` or `Button`, for a toolbar or property row. Default --control-h. */\n size?: ControlSize;\n icon: IconComponent;\n label: string;\n /** Shown after the label in its tooltip, muted: \"Ctrl+Z\". */\n hint?: React.ReactNode;\n};\n\n/** An icon-only button. `label` is required and becomes the accessible name and the tooltip (hover and keyboard focus); `hint` adds a muted aside to it, such as a shortcut. */\nexport function IconButton({\n icon: Icon,\n label,\n hint,\n variant = \"ghost\",\n size = \"default\",\n ...props\n}: IconButtonProps) {\n return (\n <Tooltip label={label} hint={hint}>\n <Button size={size === \"sm\" ? \"icon-sm\" : \"icon\"} variant={variant} aria-label={label} {...props}>\n <Icon aria-hidden />\n </Button>\n </Tooltip>\n );\n}\n\n// A row action says what it does in the row (\"Withdraw\") and whom it does it to in its name\n// (\"Withdraw Tom Ellery\"): a table of eight \"Withdraw\" buttons is eight identical names in a\n// screen reader's list of controls. The name is an aria-label that starts with the visible verb,\n// so it meets WCAG 2.5.3 (label in name) and voice control still finds it by \"Withdraw\". Visually\n// hidden suffix text is not used: a hidden span joined to the verb did not form a name with its\n// space in dom-testing-library (strata-react issue #11). Ghost and small, one per row, shown only\n// on the rows where it applies; an icon-only row action is an `IconButton` whose `label` names the\n// row the same way. It keeps the row's pitch: rows with and without the action are the same height.\nexport type RowActionProps = Omit<ButtonProps, \"children\" | \"aria-label\"> & {\n /** The visible verb, sentence case: \"Withdraw\", \"Remove\". */\n label: string;\n /** What the row is, as a person would say it: \"Tom Ellery\", \"Moonbeam\". Completes the accessible name. */\n subject: string;\n icon?: IconComponent;\n};\n\n/** A small ghost action for one table row: shows `label`, and is named \"`label` `subject`\" so every row's action has its own name. */\nexport function RowAction({\n label,\n subject,\n icon: Icon,\n variant = \"ghost\",\n size = \"sm\",\n className,\n ...props\n}: RowActionProps) {\n // -my-1.5 lets the 32px button sit in the 20px line of a table row, inside the row's padding, so\n // rows with an action keep the same pitch as rows without one.\n return (\n <Button\n variant={variant}\n size={size}\n aria-label={`${label} ${subject}`}\n className={cn(\"-my-1.5\", className)}\n {...props}\n >\n {Icon && <Icon aria-hidden />}\n {label}\n </Button>\n );\n}\n"],"mappings":"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"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as AsyncActionOptions, B as RowAction, C as useColorScheme, D as DensityName, E as Density, F as useAsyncAction, H as buttonVariants, I as Button, L as ButtonProps, M as AsyncLabels, N as FieldErrors, O as DensityProps, P as Phase, R as IconButton, S as palettes, T as useSystemColorScheme, U as ControlSize, V as RowActionProps, W as IconComponent, _ as PaletteOption, a as browserMicrophone, b as colorSchemeScript, c as COLOR_SCHEME_STORAGE_KEY, d as ColorSchemeLabels, f as ColorSchemePreference, g as PaletteChoice, h as PALETTE_STORAGE_KEY, i as MicrophoneStream, j as AsyncButton, k as AsyncAction, l as ColorScheme, m as DEFAULT_PALETTE, n as MicrophoneContext, o as explainMicrophoneError, p as ColorSchemeState, r as MicrophoneError, s as useMicrophone, t as Microphone, u as ColorSchemeChoice, v as PaletteState, w as usePalette, x as paletteScript, y as ThemeProvider, z as IconButtonProps } from "./microphone-DDOnQHxf.js";
1
+ import { A as AsyncActionOptions, B as RowAction, C as useColorScheme, D as DensityName, E as Density, F as useAsyncAction, H as buttonVariants, I as Button, L as ButtonProps, M as AsyncLabels, N as FieldErrors, O as DensityProps, P as Phase, R as IconButton, S as palettes, T as useSystemColorScheme, U as ControlSize, V as RowActionProps, W as IconComponent, _ as PaletteOption, a as browserMicrophone, b as colorSchemeScript, c as COLOR_SCHEME_STORAGE_KEY, d as ColorSchemeLabels, f as ColorSchemePreference, g as PaletteChoice, h as PALETTE_STORAGE_KEY, i as MicrophoneStream, j as AsyncButton, k as AsyncAction, l as ColorScheme, m as DEFAULT_PALETTE, n as MicrophoneContext, o as explainMicrophoneError, p as ColorSchemeState, r as MicrophoneError, s as useMicrophone, t as Microphone, u as ColorSchemeChoice, v as PaletteState, w as usePalette, x as paletteScript, y as ThemeProvider, z as IconButtonProps } from "./microphone-xGKxcK6p.js";
2
2
  import { n as geo, t as LatLng } from "./geo-DfKa9JtK.js";
3
3
  import { $ as LineChartGroupProps, A as RateChoice, B as VolumeControlProps, C as SpanBehaviour, D as useMediaSpans, E as SpanWords, F as StageGuides, G as isTypingTarget, H as HotkeysOptions, I as TimeReadout, J as ChartMark, K as keyName, L as Transport, M as SeekBarProps, N as SeekBarSpan, O as MediaStage, P as SpanStrip, Q as LineChartGroup, R as TransportProps, S as SpanActionsNotice, T as SpanOutcome, U as KeysLegend, V as transportShortcuts, W as Shortcut, X as GroupedChart, Y as ChartSpan, Z as LineChart, _ as MediaProgress, _t as skipAction, a as MediaPlayerProps, at as valueAt, b as PlayerNotice, bt as usePlayerWarnings, c as MediaSource, ct as CursorScope, d as SPEECH_RATES, dt as useSharedCursor, et as LineChartProps, f as SourceAttacher, ft as MediaMark, g as useMediaElement, gt as marksFor, h as useAttachedSource, ht as SkipSteps, i as MediaPlayer, it as logScale, j as SeekBar, k as Precision, l as MediaWindow, lt as CursorScopeProps, m as StreamContext, mt as SkipLevel, n as MediaElementState, nt as SpanTone, o as MediaProblem, ot as CursorMapping, p as StreamAttachment, pt as SkipAction, q as useHotkeys, r as MediaHeading, rt as YScale, s as MediaSession, st as CursorOwner, t as MediaElementOptions, tt as Point, u as ResumeWords, ut as SharedCursor, v as MediaSpanData, vt as PlayerWarning, w as SpanKind, x as SpanActions, y as MediaSpansState, yt as PlayerWarningEvent, z as VolumeControl } from "./media-player-Buvu2l7R.js";
4
4
  import { ClassValue } from "clsx";
@@ -3151,10 +3151,18 @@ type PlaceBoardProps<P, S> = {
3151
3151
  beckon?: boolean;
3152
3152
  /** Time between pulses while `beckon`; default 1600. */
3153
3153
  beckonMs?: number;
3154
+ /** How many pieces a place holds at most (an order's slot: 1). A piece put in a full place sends the one there back to the pile, so a learner can put a piece on top of another instead of moving that one out first. Default: no limit. */
3155
+ limit?: (place: S) => number;
3156
+ /** The app's check, drawn as the board's big button under the places while it is not locked ("Check", with a tick either side). */
3157
+ check?: {
3158
+ label: string;
3159
+ onCheck: () => void;
3160
+ disabled?: boolean;
3161
+ };
3154
3162
  className?: string;
3155
3163
  };
3156
- /** Pictures put into places with two taps (pick up, put down) for an answer that is an arrangement: give a number, order, match, sort. The app owns where each piece is and checks it; the board only moves what the learner asks. */
3157
- export declare function PlaceBoard<P, S>({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState, marks, locked, stretch, beckon, beckonMs, className }: PlaceBoardProps<P, S>): React.JSX.Element;
3164
+ /** Pictures put into places for an answer that is an arrangement (give a number, order, match, sort): two taps (pick up, put down), one tap when there is one place, or a drag. The app owns where each piece is and checks it; the board only moves what the learner asks, and keeps every piece's slot so nothing shifts. */
3165
+ export declare function PlaceBoard<P, S>({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState, marks, locked, stretch, beckon, beckonMs, check, limit, className }: PlaceBoardProps<P, S>): React.JSX.Element;
3158
3166
  /** A list that renders only its visible rows (React Aria's GridList and Virtualizer) from `virtualizeFrom` items, with arrow-key navigation between rows. */
3159
3167
  export declare function VirtualList<T>({ label, items, itemKey, children, estimateSize, rowHeight, height, virtualizeFrom, bounded, footer, className }: {
3160
3168
  label: string;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { i as typeSteps, n as KeyText, r as cn, t as Tooltip } from "./tooltip-BosfsWYh.js";
2
2
  import { a as Textarea, c as useSearchParam, d as createFormat, f as format, i as NativeSelect, l as MISSING, n as Field, o as useFieldControl, p as toDate, r as Input, s as controlHeight, t as ChoiceGroup, u as NBSP } from "./field-DBCsFIng.js";
3
- import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-CYXjU-fs.js";
3
+ import { a as isDev, i as buttonVariants, n as IconButton, o as useInView, r as RowAction, t as Button } from "./button-CjnotDTb.js";
4
4
  import { t as followAim } from "./follow-CXQsL86O.js";
5
5
  import { n as useViewPointers, r as useWheelZoom, t as useSettledStatus } from "./viewer-input-3Qa-o35k.js";
6
- import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-76skMt6i.js";
7
- import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-5u7sD_wG.js";
6
+ import { A as StrataQueryProvider, C as toast, D as LoadError, E as EmptyState, F as useLoad, I as usePoll, L as overlaySurface, M as fetchJson, N as staleOf, O as Skeleton, P as toLoad, S as StrataToastRegion, T as DataView$1, _ as clampViewport, a as useMicrophone, b as viewportTransform, d as zoomToBox, f as FIT, g as boxViewport, h as actualPixelsScale, i as explainMicrophoneError, j as createQueryClient, k as StaleNotice, l as readingOrder, m as MIN_SCALE, n as MicrophoneError, o as Thumbnail, p as MAX_SCALE, r as browserMicrophone, s as ThumbnailSkeleton, t as MicrophoneContext, u as regionStyle, v as frameBoxToShares, w as toastTimeout, x as zoomAt, y as regionShares } from "./microphone-D3sbBVka.js";
7
+ import { a as useAsyncAction, c as KeysLegend, d as useHotkeys, i as AsyncButton, l as isTypingTarget, n as NumberField, o as Toolbar, r as Slider, s as ToolbarSeparator, t as ColorField, u as keyName } from "./value-controls-ColD28Pp.js";
8
8
  import { n as useSharedCursor, r as geo, t as CursorScope } from "./cursor-Cwyvgwsw.js";
9
9
  import { a as fieldErrorsOf, i as errorPayload, n as describeActionError, o as readErrorBody, r as describeHttpError, t as HttpError } from "./errors-CmuwcWlb.js";
10
10
  import { a as PaletteChoice, c as paletteScript, d as usePalette, f as useSystemColorScheme, i as PALETTE_STORAGE_KEY, l as palettes, n as ColorSchemeChoice, o as ThemeProvider, p as Density, r as DEFAULT_PALETTE, s as colorSchemeScript, t as COLOR_SCHEME_STORAGE_KEY, u as useColorScheme } from "./theme-1oOSMj_D.js";
@@ -17,6 +17,7 @@ import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/r
17
17
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
18
18
  import { UNSAFE_PortalProvider, VisuallyHidden, mergeProps, useDrag, useDrop, useFocusRing, useMove, useSlider, useSliderThumb, useUNSAFE_PortalContext } from "react-aria";
19
19
  import { LayoutInfo, Rect, Size, useSliderState } from "react-stately";
20
+ import { createPortal } from "react-dom";
20
21
  import pixelmatch from "pixelmatch";
21
22
 
22
23
  // src/lib/chords.ts
@@ -12698,17 +12699,22 @@ const pieceSide = 96;
12698
12699
  const placedSide = 72;
12699
12700
  const placedPicture = { "--type-picture-size": "2.5rem" };
12700
12701
  const placeSide = 160;
12701
- /** Pictures put into places with two taps (pick up, put down) for an answer that is an arrangement: give a number, order, match, sort. The app owns where each piece is and checks it; the board only moves what the learner asks. */
12702
- function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, className }) {
12702
+ /** Pictures put into places for an answer that is an arrangement (give a number, order, match, sort): two taps (pick up, put down), one tap when there is one place, or a drag. The app owns where each piece is and checks it; the board only moves what the learner asks, and keeps every piece's slot so nothing shifts. */
12703
+ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places, placeKey, placeLabel, renderPlace, placement, onMove, pileLabel, placeState = () => "open", marks, locked = false, stretch = false, beckon = false, beckonMs = 1600, check, limit, className }) {
12703
12704
  const fill = stretch ? "auto-fit" : "auto-fill";
12704
12705
  const [heldKey, setHeld] = React.useState(null);
12705
12706
  const [follow, setFollow] = React.useState(null);
12707
+ const [drag, setDrag] = React.useState(null);
12706
12708
  const buttons = React.useRef(/* @__PURE__ */ new Map());
12709
+ const zones = React.useRef(/* @__PURE__ */ new Map());
12710
+ const dragged = React.useRef(false);
12711
+ const stopDrag = React.useRef(null);
12707
12712
  const placeKeys = new Set(places.map(placeKey));
12708
12713
  const where = (p) => {
12709
12714
  const at = placement[pieceKey(p)];
12710
12715
  return at !== void 0 && placeKeys.has(at) ? at : null;
12711
12716
  };
12717
+ const only = places.length === 1 ? places[0] : void 0;
12712
12718
  const held = locked ? void 0 : pieces.find((p) => pieceKey(p) === heldKey);
12713
12719
  const heldAt = held === void 0 ? null : where(held);
12714
12720
  const lit = useBeckon(beckon && !locked && held === void 0, pieces.filter((p) => where(p) === null).map(pieceKey), beckonMs);
@@ -12717,93 +12723,277 @@ function PlaceBoard({ label, pieces, pieceKey, pieceLabel, renderPiece, places,
12717
12723
  buttons.current.get(follow)?.focus();
12718
12724
  setFollow(null);
12719
12725
  }, [follow]);
12720
- const move = (to) => {
12721
- if (held === void 0) return;
12722
- const key = pieceKey(held);
12726
+ React.useEffect(() => () => stopDrag.current?.(), []);
12727
+ React.useEffect(() => {
12728
+ if (locked) stopDrag.current?.();
12729
+ }, [locked]);
12730
+ const bumped = (key, to) => {
12731
+ const s = places.find((q) => placeKey(q) === to);
12732
+ const max = s === void 0 || limit === void 0 ? Infinity : limit(s);
12733
+ const there = pieces.filter((p) => pieceKey(p) !== key && where(p) === to);
12734
+ return there.length >= max ? there[0] : void 0;
12735
+ };
12736
+ const room = (s) => Math.min(pieces.length, limit === void 0 ? Infinity : limit(s));
12737
+ const send = (key, to) => {
12723
12738
  setHeld(null);
12739
+ const out = to === null ? void 0 : bumped(key, to);
12740
+ if (out !== void 0) onMove(pieceKey(out), null);
12724
12741
  onMove(key, to);
12725
12742
  setFollow(key);
12726
12743
  };
12744
+ const move = (to) => {
12745
+ if (held !== void 0) send(pieceKey(held), to);
12746
+ };
12747
+ const latest = React.useRef({
12748
+ send,
12749
+ placement,
12750
+ placeKeys
12751
+ });
12752
+ latest.current = {
12753
+ send,
12754
+ placement,
12755
+ placeKeys
12756
+ };
12757
+ const hit = (x, y) => {
12758
+ for (const [key, el] of zones.current) {
12759
+ const r = el.getBoundingClientRect();
12760
+ if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) return key;
12761
+ }
12762
+ };
12763
+ const press = (key) => (e) => {
12764
+ if (locked || e.button !== 0 || !e.isPrimary) return;
12765
+ stopDrag.current?.();
12766
+ const el = e.currentTarget;
12767
+ const { clientX: x0, clientY: y0, pointerId } = e;
12768
+ let size = null;
12769
+ const moved = (ev) => {
12770
+ if (ev.pointerId !== pointerId) return;
12771
+ if (size === null) {
12772
+ if (Math.hypot(ev.clientX - x0, ev.clientY - y0) < DRAG_START) return;
12773
+ const r = el.getBoundingClientRect();
12774
+ size = {
12775
+ w: r.width,
12776
+ h: r.height
12777
+ };
12778
+ dragged.current = true;
12779
+ setHeld(key);
12780
+ }
12781
+ ev.preventDefault();
12782
+ setDrag({
12783
+ key,
12784
+ x: ev.clientX,
12785
+ y: ev.clientY,
12786
+ ...size,
12787
+ over: hit(ev.clientX, ev.clientY)
12788
+ });
12789
+ };
12790
+ const ended = (ev) => {
12791
+ if (ev.pointerId !== pointerId) return;
12792
+ stop();
12793
+ if (size === null) return;
12794
+ const over = ev.type === "pointerup" ? hit(ev.clientX, ev.clientY) : void 0;
12795
+ const { send, placement, placeKeys } = latest.current;
12796
+ const raw = placement[key];
12797
+ const at = raw !== void 0 && placeKeys.has(raw) ? raw : null;
12798
+ const to = over === PILE ? null : over;
12799
+ if (to !== void 0 && to !== at) send(key, to);
12800
+ else setHeld(null);
12801
+ setTimeout(() => {
12802
+ dragged.current = false;
12803
+ }, 0);
12804
+ };
12805
+ const stop = () => {
12806
+ window.removeEventListener("pointermove", moved);
12807
+ window.removeEventListener("pointerup", ended);
12808
+ window.removeEventListener("pointercancel", ended);
12809
+ stopDrag.current = null;
12810
+ setDrag(null);
12811
+ };
12812
+ window.addEventListener("pointermove", moved);
12813
+ window.addEventListener("pointerup", ended);
12814
+ window.addEventListener("pointercancel", ended);
12815
+ stopDrag.current = () => {
12816
+ stop();
12817
+ dragged.current = false;
12818
+ if (size !== null) setHeld(null);
12819
+ };
12820
+ };
12821
+ const zone = (key) => (el) => {
12822
+ if (el) zones.current.set(key, el);
12823
+ else zones.current.delete(key);
12824
+ };
12825
+ const ref = (key) => (el) => {
12826
+ if (el) buttons.current.set(key, el);
12827
+ else buttons.current.delete(key);
12828
+ };
12829
+ const pieceClass = (key) => cn("@container relative flex aspect-square w-full min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-info selected:bg-info-subtle selected:ring-4 selected:ring-info", key === lit?.key && cn(lit.className, "border-primary"));
12830
+ const picture = (p, placed) => /* @__PURE__ */ jsx("span", {
12831
+ "aria-hidden": true,
12832
+ className: "type-picture",
12833
+ style: placed ? {
12834
+ ...placedPicture,
12835
+ ...pictureInTile
12836
+ } : pictureInTile,
12837
+ children: renderPiece(p)
12838
+ });
12727
12839
  const piece = (p, placed) => {
12728
12840
  const key = pieceKey(p);
12729
12841
  const isHeld = held !== void 0 && pieceKey(held) === key;
12730
- return /* @__PURE__ */ jsxs(ToggleButton, {
12731
- ref: (el) => {
12732
- if (el) buttons.current.set(key, el);
12733
- else buttons.current.delete(key);
12842
+ const name = pieceLabel(p);
12843
+ const control = only !== void 0 ? /* @__PURE__ */ jsxs(Button$1, {
12844
+ ref: ref(key),
12845
+ isDisabled: locked,
12846
+ onPress: () => {
12847
+ if (!dragged.current) send(key, placed ? null : placeKey(only));
12734
12848
  },
12849
+ "aria-label": placed ? `Take ${name} out of ${placeLabel(only)}` : `Put ${name} in ${placeLabel(only)}`,
12850
+ "data-beckon": key === lit?.key || void 0,
12851
+ className: cn(pieceClass(key), "group", isHeld && "border-info bg-info-subtle ring-4 ring-info"),
12852
+ children: [picture(p, placed), placed && !locked && /* @__PURE__ */ jsx("span", {
12853
+ "aria-hidden": true,
12854
+ "data-remove": true,
12855
+ className: "absolute inset-0 flex items-center justify-center rounded-overlay bg-background/70 text-foreground opacity-0 transition-state group-hover:opacity-100 group-focus-visible:opacity-100",
12856
+ children: /* @__PURE__ */ jsx(X, {
12857
+ className: "size-3/4",
12858
+ strokeWidth: 3
12859
+ })
12860
+ })]
12861
+ }) : /* @__PURE__ */ jsxs(ToggleButton, {
12862
+ ref: ref(key),
12735
12863
  isSelected: isHeld,
12736
- onChange: (on) => setHeld(on ? key : null),
12864
+ onChange: (on) => {
12865
+ if (!dragged.current) setHeld(on ? key : null);
12866
+ },
12737
12867
  isDisabled: locked,
12738
- "aria-label": isHeld ? `${pieceLabel(p)}, ${marks.held.toLowerCase()}` : pieceLabel(p),
12868
+ "aria-label": isHeld ? `${name}, ${marks.held.toLowerCase()}` : name,
12739
12869
  "data-held": isHeld || void 0,
12740
12870
  "data-beckon": key === lit?.key || void 0,
12741
- className: cn("@container flex aspect-square min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-overlay border-2 border-border bg-card p-1 text-card-foreground select-none outline-offset-2 transition-state press", "hover:border-primary disabled:cursor-default disabled:hover:border-border", "selected:border-4 selected:border-primary selected:bg-muted", key === lit?.key && cn(lit.className, "border-primary")),
12742
- children: [/* @__PURE__ */ jsx("span", {
12743
- "aria-hidden": true,
12744
- className: "type-picture",
12745
- style: placed ? {
12746
- ...placedPicture,
12747
- ...pictureInTile
12748
- } : pictureInTile,
12749
- children: renderPiece(p)
12750
- }), isHeld && /* @__PURE__ */ jsx(Status, {
12871
+ className: pieceClass(key),
12872
+ children: [picture(p, placed), isHeld && /* @__PURE__ */ jsx(Status, {
12751
12873
  tone: "info",
12752
12874
  className: "max-w-full truncate",
12753
12875
  children: marks.held
12754
12876
  })]
12877
+ });
12878
+ return /* @__PURE__ */ jsx("div", {
12879
+ "data-piece": key,
12880
+ onPointerDownCapture: press(key),
12881
+ onDragStart: (e) => e.preventDefault(),
12882
+ className: cn("grid min-w-0", !locked && "touch-none", drag?.key === key && "opacity-30"),
12883
+ children: control
12755
12884
  }, key);
12756
12885
  };
12757
- const grid = (inside, name, side) => inside.length > 0 && /* @__PURE__ */ jsx("div", {
12758
- role: "group",
12759
- "aria-label": name,
12760
- className: "grid min-w-0 gap-2",
12761
- style: { gridTemplateColumns: `repeat(${side === placedSide ? "auto-fill" : fill}, minmax(min(${side}px, 100%), 1fr))` },
12762
- children: inside.map((p) => piece(p, side === placedSide))
12763
- });
12764
- const pile = pieces.filter((p) => where(p) === null);
12886
+ const columns = (side, fit) => ({ gridTemplateColumns: `repeat(${fit}, minmax(min(${side}px, 100%), 1fr))` });
12887
+ const slot = (p) => {
12888
+ if (where(p) === null) return piece(p, false);
12889
+ const key = pieceKey(p);
12890
+ const isHeld = held !== void 0 && pieceKey(held) === key && only === void 0;
12891
+ const gap = "aspect-square min-w-0 rounded-overlay border-2 border-dashed border-border";
12892
+ return isHeld ? /* @__PURE__ */ jsx(Button$1, {
12893
+ onPress: () => move(null),
12894
+ "aria-label": `Put ${pieceLabel(p)} back`,
12895
+ className: cn(gap, "cursor-pointer border-solid border-info ring-4 ring-info outline-offset-2 transition-state press hover:bg-info-subtle")
12896
+ }, key) : /* @__PURE__ */ jsx("div", {
12897
+ "aria-hidden": true,
12898
+ "data-gap": true,
12899
+ className: gap
12900
+ }, key);
12901
+ };
12902
+ const target = (over) => over && "bg-info-subtle";
12903
+ const swap = (out) => out === void 0 ? "" : ` in place of ${pieceLabel(out)}`;
12765
12904
  return /* @__PURE__ */ jsxs("section", {
12766
12905
  "aria-label": label,
12767
12906
  className: cn("grid min-w-0 gap-6", className),
12768
- children: [/* @__PURE__ */ jsxs("div", {
12769
- className: "grid min-w-0 gap-2",
12770
- children: [grid(pile, pileLabel, pieceSide), heldAt !== null && held !== void 0 && /* @__PURE__ */ jsx(Button$1, {
12771
- onPress: () => move(null),
12772
- className: "min-h-(--control-h) justify-self-start rounded-control border border-input bg-background px-3 type-label transition-state press hover:bg-muted",
12773
- children: `Put ${pieceLabel(held)} back`
12774
- })]
12775
- }), /* @__PURE__ */ jsx("div", {
12776
- className: "grid min-w-0 gap-4",
12777
- style: { gridTemplateColumns: `repeat(${fill}, minmax(min(${placeSide}px, 100%), 1fr))` },
12778
- children: places.map((s) => {
12779
- const key = placeKey(s);
12780
- const state = placeState(s);
12781
- const name = placeLabel(s);
12782
- const inside = pieces.filter((p) => where(p) === key);
12783
- const takes = held !== void 0 && heldAt !== key;
12784
- return /* @__PURE__ */ jsxs("div", {
12785
- "data-place": state,
12786
- className: cn("grid min-w-0 content-start gap-2 rounded-overlay border-2 border-dashed border-input p-2 transition-state", takes && "border-solid border-primary", state === "right" && "border-4 border-solid border-success bg-success-subtle", state === "wrong" && "border-solid border-muted-foreground"),
12787
- children: [/* @__PURE__ */ jsxs(Button$1, {
12788
- isDisabled: !takes,
12789
- onPress: () => move(key),
12790
- "aria-label": (takes && held !== void 0 ? `Put ${pieceLabel(held)} in ${name}` : name) + (state === "open" ? "" : `, ${marks[state].toLowerCase()}`),
12791
- className: "flex min-h-30 min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-surface outline-offset-2 transition-state press hover:bg-muted disabled:cursor-default disabled:hover:bg-transparent",
12792
- children: [/* @__PURE__ */ jsx("span", {
12793
- "aria-hidden": true,
12794
- className: renderPlace ? "type-picture" : "type-heading",
12795
- children: renderPlace ? renderPlace(s) : name
12796
- }), state !== "open" && /* @__PURE__ */ jsx(Status, {
12797
- tone: state === "right" ? "success" : "neutral",
12798
- className: "max-w-full truncate",
12799
- children: marks[state]
12907
+ children: [
12908
+ /* @__PURE__ */ jsx("div", {
12909
+ ref: zone(PILE),
12910
+ role: "group",
12911
+ "aria-label": pileLabel,
12912
+ className: cn("grid min-w-0 gap-2 rounded-overlay transition-state", target(drag?.over === PILE && heldAt !== null)),
12913
+ style: columns(pieceSide, fill),
12914
+ children: pieces.map(slot)
12915
+ }),
12916
+ /* @__PURE__ */ jsx("div", {
12917
+ className: "grid min-w-0 gap-4",
12918
+ style: only !== void 0 ? void 0 : columns(placeSide, fill),
12919
+ children: places.map((s) => {
12920
+ const key = placeKey(s);
12921
+ const state = placeState(s);
12922
+ const name = placeLabel(s);
12923
+ const inside = pieces.filter((p) => where(p) === key);
12924
+ const takes = held !== void 0 && heldAt !== key;
12925
+ return /* @__PURE__ */ jsxs("div", {
12926
+ ref: zone(key),
12927
+ "data-place": state,
12928
+ className: cn("grid min-w-0 content-start gap-2 rounded-overlay border-2 border-dashed border-input p-2 transition-state", takes && "border-solid border-info ring-4 ring-info", takes && target(drag?.over === key), state === "right" && "border-solid border-success bg-success-subtle ring-2 ring-success", state === "wrong" && "border-solid border-muted-foreground"),
12929
+ children: [/* @__PURE__ */ jsxs(Button$1, {
12930
+ isDisabled: !takes || only !== void 0,
12931
+ onPress: () => move(key),
12932
+ "aria-label": (takes && held !== void 0 && only === void 0 ? `Put ${pieceLabel(held)} in ${name}` + swap(bumped(pieceKey(held), key)) : name) + (state === "open" ? "" : `, ${marks[state].toLowerCase()}`),
12933
+ className: "flex min-h-30 min-w-0 cursor-pointer flex-col items-center justify-center gap-1 rounded-surface outline-offset-2 transition-state press hover:bg-muted disabled:cursor-default disabled:hover:bg-transparent",
12934
+ children: [/* @__PURE__ */ jsx("span", {
12935
+ "aria-hidden": true,
12936
+ className: renderPlace ? "type-picture" : "type-heading",
12937
+ children: renderPlace ? renderPlace(s) : name
12938
+ }), state !== "open" && /* @__PURE__ */ jsx(Status, {
12939
+ tone: state === "right" ? "success" : "neutral",
12940
+ className: "max-w-full truncate",
12941
+ children: marks[state]
12942
+ })]
12943
+ }), /* @__PURE__ */ jsxs("div", {
12944
+ role: inside.length > 0 ? "group" : void 0,
12945
+ "aria-label": inside.length > 0 ? `In ${name}` : void 0,
12946
+ className: "grid min-w-0 gap-2",
12947
+ style: columns(placedSide, "auto-fill"),
12948
+ children: [inside.map((p) => piece(p, true)), Array.from({ length: Math.max(0, room(s) - inside.length) }, (_, i) => /* @__PURE__ */ jsx("div", {
12949
+ "aria-hidden": true,
12950
+ "data-room": true,
12951
+ className: "aspect-square min-w-0"
12952
+ }, `room${i}`))]
12800
12953
  })]
12801
- }), grid(inside, `In ${name}`, placedSide)]
12802
- }, key);
12803
- })
12804
- })]
12954
+ }, key);
12955
+ })
12956
+ }),
12957
+ check && !locked && /* @__PURE__ */ jsxs(Button, {
12958
+ variant: "default",
12959
+ size: "lg",
12960
+ onClick: check.onCheck,
12961
+ disabled: check.disabled,
12962
+ className: "justify-self-center",
12963
+ children: [
12964
+ /* @__PURE__ */ jsx(Check, {
12965
+ "aria-hidden": true,
12966
+ strokeWidth: 3
12967
+ }),
12968
+ check.label,
12969
+ /* @__PURE__ */ jsx(Check, {
12970
+ "aria-hidden": true,
12971
+ strokeWidth: 3
12972
+ })
12973
+ ]
12974
+ }),
12975
+ drag !== null && createPortal((() => {
12976
+ const p = pieces.find((q) => pieceKey(q) === drag.key);
12977
+ return p === void 0 ? null : /* @__PURE__ */ jsx("div", {
12978
+ "aria-hidden": true,
12979
+ "data-dragging": true,
12980
+ className: "@container pointer-events-none fixed z-50 flex items-center justify-center rounded-overlay border-2 border-info bg-info-subtle p-1 text-card-foreground shadow-overlay ring-4 ring-info",
12981
+ style: {
12982
+ left: drag.x - drag.w / 2,
12983
+ top: drag.y - drag.h / 2,
12984
+ width: drag.w,
12985
+ height: drag.h
12986
+ },
12987
+ children: picture(p, where(p) !== null)
12988
+ });
12989
+ })(), document.body)
12990
+ ]
12805
12991
  });
12806
12992
  }
12993
+ /** The pile's key among the drop zones: not a string a place key can be. */
12994
+ const PILE = "\0pile";
12995
+ /** How far a press moves, in px, before it is a drag rather than a tap (a finger wobbles a few). */
12996
+ const DRAG_START = 8;
12807
12997
 
12808
12998
  // src/components/infinite-list.tsx
12809
12999
  const PendingFocus = React.createContext(null);