torch-glare 2.4.4 → 2.5.0

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.
Files changed (147) hide show
  1. package/apps/lib/components/DataViews/{badgeAdapter.ts → badge.ts} +2 -2
  2. package/apps/lib/components/DataViews/cell.tsx +324 -0
  3. package/apps/lib/components/DataViews/context.ts +144 -0
  4. package/apps/lib/components/DataViews/data-views.tsx +383 -0
  5. package/apps/lib/components/DataViews/filters/children.tsx +98 -0
  6. package/apps/lib/components/DataViews/filters/custom.tsx +34 -0
  7. package/apps/lib/components/DataViews/filters/filters.tsx +163 -0
  8. package/apps/lib/components/DataViews/filters/index.ts +4 -0
  9. package/apps/lib/components/DataViews/filters/labelled.tsx +20 -0
  10. package/apps/lib/components/DataViews/filters/presets.tsx +65 -0
  11. package/apps/lib/components/DataViews/filters/summary.tsx +65 -0
  12. package/apps/lib/components/DataViews/filters/sync.tsx +35 -0
  13. package/apps/lib/components/DataViews/filters/values.ts +173 -0
  14. package/apps/lib/components/DataViews/header.tsx +217 -0
  15. package/apps/lib/components/DataViews/hooks/index.ts +5 -0
  16. package/apps/lib/components/DataViews/hooks/useActiveRow.ts +22 -0
  17. package/apps/lib/components/DataViews/hooks/useControllable.ts +52 -0
  18. package/apps/lib/components/DataViews/index.ts +74 -26
  19. package/apps/lib/components/DataViews/panel/columns.tsx +153 -0
  20. package/apps/lib/components/DataViews/panel/controls.tsx +106 -0
  21. package/apps/lib/components/DataViews/panel/index.ts +3 -0
  22. package/apps/lib/components/DataViews/panel/panel.tsx +164 -0
  23. package/apps/lib/components/DataViews/panel/saved-views.tsx +67 -0
  24. package/apps/lib/components/DataViews/panel/section.tsx +79 -0
  25. package/apps/lib/components/DataViews/panel/sort.tsx +42 -0
  26. package/apps/lib/components/DataViews/panel/tab.tsx +31 -0
  27. package/apps/lib/components/DataViews/slots.ts +63 -0
  28. package/apps/lib/components/DataViews/states.tsx +38 -0
  29. package/apps/lib/components/DataViews/types.ts +485 -178
  30. package/apps/lib/components/DataViews/views/board-view.tsx +379 -0
  31. package/apps/lib/components/DataViews/views/card-rows.tsx +36 -0
  32. package/apps/lib/components/DataViews/views/inbox-view.tsx +257 -0
  33. package/apps/lib/components/DataViews/views/pane-views.tsx +192 -0
  34. package/apps/lib/components/DataViews/views/table-view.tsx +426 -0
  35. package/apps/lib/components/DataViews/views/tree-view.tsx +365 -0
  36. package/apps/lib/components/FormBuilder/context.ts +20 -6
  37. package/apps/lib/components/FormBuilder/field-kind.ts +28 -0
  38. package/apps/lib/components/FormBuilder/fields/DateField.tsx +3 -3
  39. package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +7 -6
  40. package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +30 -4
  41. package/apps/lib/components/FormBuilder/fields/SelectField.tsx +7 -7
  42. package/apps/lib/components/FormBuilder/fields/TableField.tsx +80 -52
  43. package/apps/lib/components/FormBuilder/fields/TextField.tsx +9 -9
  44. package/apps/lib/components/FormBuilder/form-builder.tsx +66 -6
  45. package/apps/lib/components/FormBuilder/index.ts +3 -1
  46. package/apps/lib/components/FormBuilder/types.ts +40 -0
  47. package/apps/lib/components/Input.tsx +3 -0
  48. package/apps/lib/components/SearchableTable.tsx +5 -4
  49. package/apps/lib/components/SectionBlock.tsx +58 -11
  50. package/apps/lib/components/Select.tsx +3 -1
  51. package/apps/lib/components/TabSwitch.tsx +16 -4
  52. package/apps/lib/components/Table.tsx +265 -67
  53. package/apps/lib/components/TreeFolder/TreeFolder.tsx +6 -3
  54. package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +16 -14
  55. package/apps/lib/components/TreeFolder/index.ts +1 -1
  56. package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +70 -207
  57. package/apps/lib/hooks/useDragDrop.tsx +365 -0
  58. package/apps/lib/hooks/useInfiniteScroll.ts +108 -0
  59. package/apps/lib/registry.json +159 -4
  60. package/apps/lib/tsconfig.tsbuildinfo +1 -1
  61. package/apps/lib/utils/dataViews/path.ts +67 -0
  62. package/apps/lib/utils/dataViews/query.ts +73 -0
  63. package/apps/lib/utils/dataViews/types.ts +187 -0
  64. package/docs/components/breadcrumb.md +1 -1
  65. package/docs/components/button-group.md +1 -1
  66. package/docs/components/button.md +1 -1
  67. package/docs/components/card.md +1 -1
  68. package/docs/components/checkbox.md +1 -1
  69. package/docs/components/data-views/backend-response.md +324 -0
  70. package/docs/components/data-views/examples/a11y-rtl.md +250 -0
  71. package/docs/components/data-views/examples/api-orders-route.md +130 -0
  72. package/docs/components/data-views/examples/fields.md +362 -0
  73. package/docs/components/data-views/examples/filters.md +308 -0
  74. package/docs/components/data-views/examples/inbox-routing.md +218 -0
  75. package/docs/components/data-views/examples/index.md +29 -0
  76. package/docs/components/data-views/examples/overview.md +244 -0
  77. package/docs/components/data-views/examples/panel.md +212 -0
  78. package/docs/components/data-views/examples/scale.md +231 -0
  79. package/docs/components/data-views/examples/server-side.md +210 -0
  80. package/docs/components/data-views/examples/state.md +250 -0
  81. package/docs/components/data-views/examples/tree-custom.md +388 -0
  82. package/docs/components/data-views/examples/view-registry.md +313 -0
  83. package/docs/components/data-views/examples/views.md +534 -0
  84. package/docs/components/data-views/guide.md +405 -0
  85. package/docs/components/data-views/index.md +1504 -0
  86. package/docs/components/data-views/migration.md +79 -0
  87. package/docs/components/date-picker.md +0 -1
  88. package/docs/components/form-builder.md +19 -8
  89. package/docs/components/form-renderer.md +2 -1
  90. package/docs/components/form.md +1 -1
  91. package/docs/components/input-field.md +1 -1
  92. package/docs/components/input-otp.md +1 -1
  93. package/docs/components/input.md +1 -1
  94. package/docs/components/labeled-check-box.md +1 -1
  95. package/docs/components/labeled-radio.md +1 -1
  96. package/docs/components/radio-card.md +1 -1
  97. package/docs/components/radio.md +1 -1
  98. package/docs/components/search-field.md +1 -1
  99. package/docs/components/section-block.md +79 -3
  100. package/docs/components/select.md +1 -1
  101. package/docs/components/simple-select.md +1 -1
  102. package/docs/components/switch.md +1 -1
  103. package/docs/components/tab-switch.md +1 -1
  104. package/docs/components/table.md +45 -8
  105. package/docs/components/text-editor.md +1 -1
  106. package/docs/components/textarea.md +1 -1
  107. package/docs/components/toggle-button.md +1 -1
  108. package/docs/components/toggle.md +1 -1
  109. package/docs/components/tree-folder.md +110 -0
  110. package/docs/how-to/forms-with-form-builder.md +6 -4
  111. package/docs/reference/components.md +16 -6
  112. package/docs/tutorials/component-composition.md +11 -13
  113. package/package.json +3 -2
  114. package/apps/lib/components/DataViews/DataViewRadio.tsx +0 -49
  115. package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +0 -393
  116. package/apps/lib/components/DataViews/DataViewsHeader.tsx +0 -207
  117. package/apps/lib/components/DataViews/DataViewsLayout.tsx +0 -332
  118. package/apps/lib/components/DataViews/FilterPanel.tsx +0 -493
  119. package/apps/lib/components/DataViews/HeaderSearch.tsx +0 -93
  120. package/apps/lib/components/DataViews/InboxView.tsx +0 -463
  121. package/apps/lib/components/DataViews/InboxViewCard.tsx +0 -127
  122. package/apps/lib/components/DataViews/KanbanView.tsx +0 -336
  123. package/apps/lib/components/DataViews/PanelControls.tsx +0 -39
  124. package/apps/lib/components/DataViews/SettingsPanel.tsx +0 -279
  125. package/apps/lib/components/DataViews/TableView.tsx +0 -212
  126. package/apps/lib/components/DataViews/TreeView.tsx +0 -364
  127. package/apps/lib/components/DataViews/fieldRenderers.tsx +0 -299
  128. package/apps/lib/components/DataViews/filters/DatePickerRangeFilter.tsx +0 -87
  129. package/apps/lib/components/DataViews/filters/DateRangePopover.tsx +0 -120
  130. package/apps/lib/components/DataViews/filters/PresetChips.tsx +0 -45
  131. package/apps/lib/components/DataViews/filters/RangeSliderWithInputs.tsx +0 -165
  132. package/apps/lib/components/DataViews/tree/TreeDrawer.tsx +0 -50
  133. package/apps/lib/components/DataViews/tree/TreeSidebar.tsx +0 -74
  134. package/apps/lib/hooks/useDataViewsState.ts +0 -175
  135. package/apps/lib/utils/dataViews/columnUtils.ts +0 -132
  136. package/apps/lib/utils/dataViews/fieldUtils.ts +0 -197
  137. package/apps/lib/utils/dataViews/nestedDataUtils.tsx +0 -371
  138. package/apps/lib/utils/dataViews/pathUtils.ts +0 -139
  139. package/apps/lib/utils/dataViews/rangeUtils.ts +0 -234
  140. package/apps/lib/utils/dataViews/treeUtils.ts +0 -396
  141. package/docs/components/data-views-config-panel.md +0 -208
  142. package/docs/components/data-views-layout.md +0 -291
  143. package/docs/components/inbox-view.md +0 -170
  144. package/docs/components/kanban-view.md +0 -135
  145. package/docs/components/table-view.md +0 -141
  146. package/docs/components/tree-view.md +0 -147
  147. package/docs/how-to/data-views-from-backend-response.md +0 -194
@@ -0,0 +1,250 @@
1
+ ---
2
+ title: DataViews example — Keyboard & RTL
3
+ description: Keyboard paths and the RTL mirror.
4
+ group: examples
5
+ component: DataViews
6
+ keywords: [data-views, example, examples, a11y, rtl]
7
+ ---
8
+
9
+ # DataViews example — Keyboard & RTL
10
+
11
+ Keyboard paths and the RTL mirror.
12
+
13
+ Complete and runnable — this is the page itself, not an excerpt. In the monorepo it lives at `apps/app/data-views/a11y-rtl/page.tsx`.
14
+
15
+ See the [component reference](../index.md) for what each prop does, or the [guide](../guide.md) for the same ground as scenarios.
16
+
17
+ ```tsx
18
+ "use client";
19
+
20
+ import { useMemo, useState } from "react";
21
+ import { useInfiniteQuery } from "@tanstack/react-query";
22
+ import { Filter, Settings } from "lucide-react";
23
+ import { Button } from "@/components/Button";
24
+ import { DataViews, emptyQuery, queryToParams, type SavedView } from "@/components/DataViews";
25
+ import { FormBuilder } from "@/components/FormBuilder";
26
+ import type {
27
+ DataViewsQuery,
28
+ FieldConfig,
29
+ Row,
30
+ RowGroup,
31
+ TreeNode,
32
+ } from "@/utils/dataViews/types";
33
+ import type { Themes } from "@/utils/types";
34
+
35
+ // ─── Data ─────────────────────────────────────────────────────────────────────
36
+
37
+ interface Order extends Row {
38
+ id: number;
39
+ customer: { name: string };
40
+ status: "Pending" | "Shipped" | "Delivered";
41
+ total: number;
42
+ createdAt: string;
43
+ }
44
+
45
+ const FIELDS: FieldConfig[] = [
46
+ { path: "id", label: "Order #", type: "number" },
47
+ { path: "customer.name", label: "Customer", type: "text" },
48
+ { path: "brand.name", label: "Brand", type: "text" },
49
+ { path: "status", label: "Status", type: "enum-badge", variants: { Pending: "yellow", Shipped: "blue", Delivered: "green" } },
50
+ { path: "total", label: "Total", type: "currency", currency: "USD" },
51
+ { path: "createdAt", label: "Created", type: "date-format", dateFormat: "YYYY-MM-DD" },
52
+ ];
53
+
54
+ /** Arabic labels, so a right-to-left layout is legible rather than mirrored English. */
55
+ const ARABIC_FIELDS: FieldConfig[] = [
56
+ { path: "id", label: "رقم الطلب", type: "number" },
57
+ { path: "customer.name", label: "العميل", type: "text" },
58
+ { path: "status", label: "الحالة", type: "enum-badge", variants: { Pending: "yellow", Shipped: "blue", Delivered: "green" } },
59
+ { path: "total", label: "المجموع", type: "currency", currency: "USD" },
60
+ { path: "createdAt", label: "التاريخ", type: "date-format", dateFormat: "YYYY-MM-DD" },
61
+ ];
62
+
63
+ /** Dynamic sets — in a real app these come from the endpoint that also does the filtering. */
64
+ const CUSTOMER_OPTIONS = [
65
+ "Acme Inc.", "Globex Corp.", "Initech", "Umbrella",
66
+ "Hooli", "Stark Industries", "Wayne Enterprises", "Cyberdyne",
67
+ ].map((v) => ({ label: v, value: v }));
68
+
69
+ const BRAND_OPTIONS = ["Bosch", "Makita", "DeWalt", "Hilti"].map((v) => ({ label: v, value: v }));
70
+
71
+ const PRIORITY_OPTIONS = ["High", "Medium", "Low"].map((v) => ({ label: v, value: v }));
72
+
73
+ const STATUS_OPTIONS = [
74
+ { label: "Pending", value: "Pending" },
75
+ { label: "Shipped", value: "Shipped" },
76
+ { label: "Delivered", value: "Delivered" },
77
+ ];
78
+
79
+ /**
80
+ * The request this page makes. The querying itself happens in `app/api/orders/route.ts` —
81
+ * nothing on this page filters, sorts or pages anything, which is the split DataViews is built
82
+ * around.
83
+ */
84
+ async function fetchOrders(q: DataViewsQuery): Promise<{ rows: Order[]; total: number }> {
85
+ const params = queryToParams(q);
86
+ const res = await fetch(`/api/orders?${params}`);
87
+ if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
88
+ return res.json();
89
+ }
90
+
91
+ const groupByStatus = (rows: readonly Order[]): RowGroup[] =>
92
+ (["Pending", "Shipped", "Delivered"] as const).map((status) => ({
93
+ id: status,
94
+ label: status,
95
+ color: ({ Pending: "gray", Shipped: "blue", Delivered: "green" } as const)[status],
96
+ rows: rows.filter((row) => row.status === status),
97
+ }));
98
+
99
+ const nodesFromRows = (rows: readonly Order[]): TreeNode[] =>
100
+ rows.map((row) => ({ id: String(row.id), row, depth: 0, children: [] }));
101
+
102
+ // ─── Page ─────────────────────────────────────────────────────────────────────
103
+
104
+ /**
105
+ * Keyboard: tab through it with the mouse down. A row with `onRowClick` takes a `tabIndex`, a
106
+ * button role and Enter/Space handling — press Enter on one and it selects. Without the handler a
107
+ * row stays a plain row and is skipped, which is right: a row that does nothing is not a tab stop.
108
+ *
109
+ * The tree handles `←`/`→` and Enter but not yet `↑`/`↓`, `Home`/`End` or roving tabindex, so
110
+ * every node is its own tab stop. Drag-and-drop has no keyboard equivalent at all — if moving
111
+ * records matters, give people a menu action that emits the same intent.
112
+ *
113
+ * Direction comes from the DOM, not a prop: the component is built from logical properties, so
114
+ * `dir="rtl"` moves the rail left and aligns the table to the start edge. `theme` sets
115
+ * `data-theme` — but the filter dropdowns and the date calendar portal to `document.body`, so
116
+ * they follow the *page's* theme rather than this one.
117
+ */
118
+ export default function AccessibilityExample() {
119
+ const [rtl, setRtl] = useState(false);
120
+ const [theme, setTheme] = useState<Themes>("default");
121
+
122
+ const [query, setQuery] = useState(emptyQuery());
123
+ const [activated, setActivated] = useState<string | null>(null);
124
+ const [saved, setSaved] = useState<SavedView[]>([]);
125
+
126
+
127
+ const { data, isPending, fetchNextPage, isFetchingNextPage } = useInfiniteQuery({
128
+ // The key *is* the query: touch any part of it and TanStack refetches, and a response that
129
+ // has been superseded is discarded rather than landing on top of a newer one.
130
+ queryKey: ["a11y-orders", { ...query, page: undefined }],
131
+ queryFn: ({ pageParam }) => fetchOrders({ ...query, page: pageParam }),
132
+ initialPageParam: 1,
133
+ // Undefined means "no more" — which is what the component's `hasMore` resolves to.
134
+ getNextPageParam: (last, pages) => {
135
+ const loaded = pages.reduce((n, page) => n + page.rows.length, 0);
136
+ return loaded < last.total ? pages.length + 1 : undefined;
137
+ },
138
+ });
139
+
140
+ // Memoised because `data?.rows ?? []` is a new array on every render, which would make the
141
+ // `groups`/`nodes` memos below miss every time and hand the board a new array to diff.
142
+ const rows = useMemo(() => data?.pages.flatMap((page) => page.rows) ?? [], [data]);
143
+ const total = data?.pages[0]?.total ?? 0;
144
+ const groups = useMemo(() => groupByStatus(rows), [rows]);
145
+ const nodes = useMemo(() => nodesFromRows(rows), [rows]);
146
+
147
+ return (
148
+ <div dir={rtl ? "rtl" : "ltr"} className="flex h-full min-h-0 flex-col p-4">
149
+ <DataViews
150
+ key={rtl ? "rtl" : "ltr"}
151
+ rows={rows}
152
+ fields={rtl ? ARABIC_FIELDS : FIELDS}
153
+ theme={theme}
154
+ total={total}
155
+ loading={isPending}
156
+ onLoadMore={fetchNextPage}
157
+ loadingMore={isFetchingNextPage}
158
+ onQueryChange={setQuery}
159
+ className="h-full"
160
+ >
161
+ <DataViews.Header title={rtl ? "الطلبات" : "Orders"}>
162
+ <DataViews.ViewSwitch />
163
+ <DataViews.Search />
164
+ <DataViews.Actions>
165
+ {/* Proof the keyboard path works: Enter on a focused row fires `onRowClick`. */}
166
+ <span
167
+ data-testid="activated"
168
+ className="typography-body-small-regular text-content-presentation-global-secondary"
169
+ >
170
+ {activated ? `row ${activated}` : "no row activated"}
171
+ </span>
172
+ {/* Two buttons rather than one toggle: a single button labelled with the current
173
+ direction is ambiguous — it reads as either the state or the action. */}
174
+ <Button variant="BluColStyle" size="M" onClick={() => setRtl(false)}>
175
+ LTR
176
+ </Button>
177
+ <Button variant="BluColStyle" size="M" onClick={() => setRtl(true)}>
178
+ RTL
179
+ </Button>
180
+ {(["default", "dark", "light"] as const).map((t) => (
181
+ <Button variant="BluColStyle"
182
+ size="M"
183
+ key={t}
184
+ onClick={() => setTheme(t)}
185
+ >
186
+ {t}
187
+ </Button>
188
+ ))}
189
+ </DataViews.Actions>
190
+ <DataViews.PanelToggle />
191
+ </DataViews.Header>
192
+
193
+ {/* Enter on a focused row fires `onRowClick` — the visible proof the row is reachable
194
+ without a mouse. What to do about it is the app's call; here it is a readout. */}
195
+ <DataViews.Table selectable onRowClick={(_row, id) => setActivated(id)} />
196
+ <DataViews.Board
197
+ groups={groups}
198
+ titlePath="customer.name"
199
+ />
200
+ {/* The pane's tabs are children, like every other part: pass none and there is no pane. */}
201
+ <DataViews.Tree nodes={nodes} labelPath="customer.name">
202
+ <DataViews.Tree.Table />
203
+ <DataViews.Tree.Cards />
204
+ </DataViews.Tree>
205
+
206
+ <DataViews.Panel>
207
+ <DataViews.Panel.Tab value="config" label="Config." icon={<Settings />}>
208
+ {/* Saving is the app's job — a view outlives the component. Restoring is not:
209
+ hand the snapshot back and selecting it puts everything back internally. */}
210
+ <DataViews.Panel.SavedViews
211
+ views={saved}
212
+ onSave={(snapshot) =>
213
+ setSaved((prev) => [
214
+ ...prev,
215
+ { id: `view-${prev.length + 1}`, label: `View ${prev.length + 1}`, snapshot },
216
+ ])
217
+ }
218
+ />
219
+ <DataViews.Panel.Columns />
220
+ <DataViews.Panel.Sort />
221
+ </DataViews.Panel.Tab>
222
+
223
+ <DataViews.Panel.Tab value="filters" label="Filters" icon={<Filter />}>
224
+ {/* The controls are FormBuilder fields — the same Select and Slider any form in
225
+ this library uses. Filters reads each child's name, label and bounds to learn
226
+ what it is; there is no second description of the form. */}
227
+ <DataViews.Filters
228
+ title={null}
229
+ className="border-b-0 p-0"
230
+ >
231
+ {/* One control per section type. Which one a field gets is decided by the data:
232
+ can the option set grow, and can the user pick more than one. */}
233
+ <FormBuilder.CheckboxGroup name="status" label="Status" options={STATUS_OPTIONS} />
234
+ <FormBuilder.RadioList name="priority" label="Priority" options={PRIORITY_OPTIONS} />
235
+ <FormBuilder.SearchableSelect
236
+ name="customer.name"
237
+ label="Customer"
238
+ options={CUSTOMER_OPTIONS}
239
+ />
240
+ <FormBuilder.MultiSelect name="brand.name" label="Brand" options={BRAND_OPTIONS} />
241
+ <FormBuilder.Slider name="total" label="Total" range min={0} max={15000} step={100} />
242
+ <FormBuilder.DateRange name="createdAt" label="Created" />
243
+ </DataViews.Filters>
244
+ </DataViews.Panel.Tab>
245
+ </DataViews.Panel>
246
+ </DataViews>
247
+ </div>
248
+ );
249
+ }
250
+ ```
@@ -0,0 +1,130 @@
1
+ ---
2
+ title: DataViews example — The endpoint these examples call
3
+ description: The route handler every DataViews example fetches from — and the only worked example of `parseQuery` on the server.
4
+ group: examples
5
+ component: DataViews
6
+ keywords: [data-views, example, examples, api, orders, route]
7
+ ---
8
+
9
+ # DataViews example — The endpoint these examples call
10
+
11
+ The route handler every DataViews example fetches from — and the only worked example of `parseQuery` on the server.
12
+
13
+ Complete and runnable — this is the page itself, not an excerpt. In the monorepo it lives at `apps/app/api/orders/route.ts`.
14
+
15
+ See the [component reference](../index.md) for what each prop does, or the [guide](../guide.md) for the same ground as scenarios.
16
+
17
+ ```ts
18
+ import { NextResponse } from "next/server";
19
+ import type { Row } from "@/utils/dataViews/types";
20
+ import { parseQuery } from "@/utils/dataViews/query";
21
+ import { latency, runQuery } from "../_lib/query";
22
+
23
+ /**
24
+ * `GET /api/orders` — the orders table most of the examples read.
25
+ *
26
+ * ```
27
+ * /api/orders?search=acme&filters={"status":["Pending"]}&sort=total:desc&page=1&pageSize=10
28
+ * → { rows, total, page, pageSize }
29
+ * ```
30
+ *
31
+ * `?fail=1` returns a 502, which is what the server-side example's failure toggle asks for.
32
+ */
33
+
34
+ export interface Order extends Row {
35
+ id: number;
36
+ customer: { name: string };
37
+ /** Org-configurable master data — the annex's Type ④ example (dynamic, multi-pick). */
38
+ brand: { name: string };
39
+ status: "Pending" | "Shipped" | "Delivered";
40
+ priority: "High" | "Medium" | "Low";
41
+ total: number;
42
+ items: number;
43
+ createdAt: string;
44
+ }
45
+
46
+ /**
47
+ * Eight rows, three of them `Pending`. Small on purpose: every behaviour these examples
48
+ * demonstrate is visible at eight rows, and a filter that leaves three is easy to check at a
49
+ * glance. The scale endpoint is where volume is the point.
50
+ */
51
+ const ORDERS: Order[] = [
52
+ { id: 1, brand: { name: "Bosch" }, customer: { name: "Acme Inc." }, status: "Pending", priority: "High", total: 1240, items: 4, createdAt: "2025-09-10" },
53
+ { id: 2, brand: { name: "Makita" }, customer: { name: "Globex Corp." }, status: "Shipped", priority: "Medium", total: 480, items: 2, createdAt: "2025-09-12" },
54
+ { id: 3, brand: { name: "DeWalt" }, customer: { name: "Initech" }, status: "Delivered", priority: "Low", total: 99, items: 1, createdAt: "2025-09-15" },
55
+ { id: 4, brand: { name: "Bosch" }, customer: { name: "Umbrella" }, status: "Pending", priority: "High", total: 2890, items: 9, createdAt: "2025-09-18" },
56
+ { id: 5, brand: { name: "Hilti" }, customer: { name: "Hooli" }, status: "Shipped", priority: "Medium", total: 740, items: 3, createdAt: "2025-09-20" },
57
+ { id: 6, brand: { name: "Makita" }, customer: { name: "Stark Industries" }, status: "Pending", priority: "High", total: 12400, items: 21, createdAt: "2025-09-22" },
58
+ { id: 7, brand: { name: "DeWalt" }, customer: { name: "Wayne Enterprises" }, status: "Delivered", priority: "Medium", total: 5300, items: 12, createdAt: "2025-09-25" },
59
+ { id: 8, brand: { name: "Hilti" }, customer: { name: "Cyberdyne" }, status: "Shipped", priority: "Low", total: 220, items: 1, createdAt: "2025-09-28" },
60
+ ];
61
+
62
+ /**
63
+ * What each order's status was before anyone dragged it. Captured once at module load so the
64
+ * board examples have something to reset to — this array *is* the mutable store.
65
+ */
66
+ const ORIGINAL_STATUS = ORDERS.map((row) => row.status);
67
+
68
+ /**
69
+ * `items` is filtered by a bucket picker the filters example builds with `Filters.Custom`, so its
70
+ * value is a label rather than a stored value. A filter no field produces still has to be a filter
71
+ * the endpoint understands — that is the whole point of the escape hatch.
72
+ */
73
+ const IN_BUCKET: Record<string, (n: number) => boolean> = {
74
+ "1–3": (n) => n <= 3,
75
+ "4–10": (n) => n > 3 && n <= 10,
76
+ "10+": (n) => n > 10,
77
+ };
78
+
79
+ /**
80
+ * `PATCH /api/orders` — move an order to another status, or put them all back.
81
+ *
82
+ * This is the other half of `onRowMove`: the board emits an intent and nothing moves until the
83
+ * data says so. Persisting it here is what makes the card stay put after the refetch — and what
84
+ * makes "Ignoring moves" visibly different from "Applying moves".
85
+ *
86
+ * ```
87
+ * PATCH { id: 4, status: "Shipped" }
88
+ * PATCH { reset: true }
89
+ * ```
90
+ */
91
+ export async function PATCH(request: Request) {
92
+ const body = (await request.json()) as { id?: number; status?: Order["status"]; reset?: boolean };
93
+ await latency(150);
94
+
95
+ if (body.reset) {
96
+ ORDERS.forEach((row, i) => (row.status = ORIGINAL_STATUS[i]));
97
+ return NextResponse.json({ ok: true });
98
+ }
99
+
100
+ const order = ORDERS.find((row) => row.id === Number(body.id));
101
+ if (!order) return NextResponse.json({ error: "Not found" }, { status: 404 });
102
+ if (body.status) order.status = body.status;
103
+
104
+ return NextResponse.json(order);
105
+ }
106
+
107
+ export async function GET(request: Request) {
108
+ const url = new URL(request.url);
109
+ await latency();
110
+
111
+ if (url.searchParams.get("fail") === "1") {
112
+ return NextResponse.json({ error: "Bad Gateway" }, { status: 502 });
113
+ }
114
+
115
+ const query = parseQuery(url);
116
+
117
+ // Pull the bucket filter out and apply it here; the rest is the generic path.
118
+ const { items, ...rest } = query.filters;
119
+ const buckets = Array.isArray(items) ? items : [];
120
+ const source = buckets.length
121
+ ? ORDERS.filter((row) => buckets.some((bucket) => IN_BUCKET[bucket]?.(row.items)))
122
+ : ORDERS;
123
+
124
+ return NextResponse.json(
125
+ runQuery(source, { ...query, filters: rest }, {
126
+ searchPaths: ["customer.name", "status", "priority"],
127
+ }),
128
+ );
129
+ }
130
+ ```