@marktiderman/genesis-ui 2.5.0 → 2.7.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.
package/SKILL.md CHANGED
@@ -75,6 +75,7 @@ report against Genesis (`packages/ui/EXTENDING.md`), not a reason to fork.
75
75
  | Settings list rows | `SettingsRow`, `ToggleRow` | `/settings-row`, `/toggle-row` |
76
76
  | Cmd-K palette | `CommandPalette`, `useCommandPaletteHotkey` | `/command-palette` |
77
77
  | Arrow-key list navigation | `useKeyboardNavigation` | `/hooks/use-keyboard-navigation` |
78
+ | Reorderable list: drag, keyboard, row-menu moves | `SortableList` | `/sortable-list` |
78
79
  | Persisted page size / density | `useViewSettings` | `/hooks/use-view-settings` |
79
80
 
80
81
  ## Import rule
@@ -0,0 +1,320 @@
1
+ "use client";
2
+ import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from './chunk-QJ6P2DW6.js';
3
+ import { cn } from './chunk-NZ5WBA4R.js';
4
+ import * as React from 'react';
5
+ import { GripVertical, MoreVertical } from 'lucide-react';
6
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
7
+
8
+ var DRAG_TYPE = "application/x-genesis-sortable-item";
9
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? React.useEffect : React.useLayoutEffect;
10
+ function moved(keys, from, to) {
11
+ const next = keys.slice();
12
+ const [key] = next.splice(from, 1);
13
+ next.splice(to, 0, key);
14
+ return next;
15
+ }
16
+ function SortableList({
17
+ items,
18
+ getKey,
19
+ getItemLabel,
20
+ renderItem,
21
+ onReorder,
22
+ label,
23
+ disabled,
24
+ moveMenu = true,
25
+ className,
26
+ itemClassName
27
+ }) {
28
+ const [armed, setArmed] = React.useState(null);
29
+ const [dragging, setDragging] = React.useState(null);
30
+ const [dropAt, setDropAt] = React.useState(null);
31
+ const [grabbed, setGrabbed] = React.useState(null);
32
+ const [preview, setPreview] = React.useState(null);
33
+ const [pending, setPending] = React.useState(false);
34
+ const [announcement, setAnnouncement] = React.useState("");
35
+ const handles = React.useRef(/* @__PURE__ */ new Map());
36
+ const refocus = React.useRef(null);
37
+ const instructionsId = React.useId();
38
+ const byKey = new Map(items.map((item) => [getKey(item), item]));
39
+ const itemKeys = items.map(getKey);
40
+ const keys = preview && preview.length === itemKeys.length && preview.every((k) => byKey.has(k)) ? preview : itemKeys;
41
+ const total = keys.length;
42
+ const nameOf = (key) => {
43
+ const item = byKey.get(key);
44
+ return item === void 0 ? "Item" : getItemLabel(item);
45
+ };
46
+ const announce = (message) => setAnnouncement((previous) => previous === message ? `${message}\xA0` : message);
47
+ const keepFocus = (key) => {
48
+ const active = typeof document === "undefined" ? null : document.activeElement;
49
+ refocus.current = active === handles.current.get(key) || active === document.body || active === null ? key : null;
50
+ };
51
+ const keysSignature = keys.join("\0");
52
+ useIsomorphicLayoutEffect(() => {
53
+ const key = refocus.current;
54
+ refocus.current = null;
55
+ if (!key) return;
56
+ const handle = handles.current.get(key);
57
+ const active = document.activeElement;
58
+ if (handle && (active === document.body || active === null || active === handle)) handle.focus();
59
+ }, [keysSignature]);
60
+ React.useEffect(() => {
61
+ if (disabled && (grabbed || armed || dragging)) {
62
+ setGrabbed(null);
63
+ setArmed(null);
64
+ setDragging(null);
65
+ setDropAt(null);
66
+ if (!pending) setPreview(null);
67
+ return;
68
+ }
69
+ if (dragging && !byKey.has(dragging)) {
70
+ setDragging(null);
71
+ setDropAt(null);
72
+ setArmed(null);
73
+ }
74
+ if (grabbed && !byKey.has(grabbed.key)) {
75
+ setGrabbed(null);
76
+ setPreview(null);
77
+ }
78
+ });
79
+ const commit = (key, from, to, message) => {
80
+ if (from === to) return;
81
+ setPending(true);
82
+ setPreview(moved(itemKeys, from, to));
83
+ let result;
84
+ try {
85
+ result = onReorder(from, to, { key });
86
+ } catch (error) {
87
+ result = Promise.reject(error);
88
+ }
89
+ Promise.resolve(result).then(
90
+ () => announce(message),
91
+ () => announce(`Couldn\u2019t move ${nameOf(key)}.`)
92
+ ).finally(() => {
93
+ setPending(false);
94
+ setPreview(null);
95
+ });
96
+ };
97
+ const move = (key, to) => {
98
+ if (disabled || pending || grabbed) return;
99
+ if (!Number.isFinite(to)) return;
100
+ const from = itemKeys.indexOf(key);
101
+ const target = Math.max(0, Math.min(total - 1, Math.round(to)));
102
+ if (from < 0 || target === from) return;
103
+ keepFocus(key);
104
+ commit(key, from, target, `${nameOf(key)} moved to position ${target + 1} of ${total}.`);
105
+ };
106
+ const pickUp = (key) => {
107
+ if (disabled || pending) return;
108
+ const from = itemKeys.indexOf(key);
109
+ if (from < 0) return;
110
+ setGrabbed({ key, from });
111
+ setPreview(itemKeys);
112
+ announce(
113
+ `${nameOf(key)} picked up, position ${from + 1} of ${total}. Use the up and down arrow keys to move, Space to drop, Escape to cancel.`
114
+ );
115
+ };
116
+ const drop = (key) => {
117
+ if (!grabbed) return;
118
+ const to = keys.indexOf(key);
119
+ const from = grabbed.from;
120
+ setGrabbed(null);
121
+ if (to === from) {
122
+ setPreview(null);
123
+ announce(`${nameOf(key)} dropped at position ${to + 1} of ${total}.`);
124
+ return;
125
+ }
126
+ keepFocus(key);
127
+ commit(key, from, to, `${nameOf(key)} dropped at position ${to + 1} of ${total}.`);
128
+ };
129
+ const cancel = (key) => {
130
+ if (!grabbed) return;
131
+ const from = grabbed.from;
132
+ keepFocus(key);
133
+ setGrabbed(null);
134
+ setPreview(null);
135
+ announce(`Move cancelled. ${nameOf(key)} is back at position ${from + 1} of ${total}.`);
136
+ };
137
+ const step = (key, to) => {
138
+ const index = keys.indexOf(key);
139
+ const target = Math.max(0, Math.min(total - 1, to));
140
+ if (index < 0 || target === index) return;
141
+ keepFocus(key);
142
+ setPreview(moved(keys, index, target));
143
+ announce(`${nameOf(key)} moved to position ${target + 1} of ${total}.`);
144
+ };
145
+ React.useEffect(() => {
146
+ if (!grabbed) return;
147
+ const onKey = (event) => {
148
+ if (event.key !== "Escape") return;
149
+ event.preventDefault();
150
+ event.stopPropagation();
151
+ cancel(grabbed.key);
152
+ };
153
+ window.addEventListener("keydown", onKey, true);
154
+ return () => window.removeEventListener("keydown", onKey, true);
155
+ });
156
+ React.useEffect(() => {
157
+ if (!armed || dragging) return;
158
+ const disarm = () => setArmed(null);
159
+ window.addEventListener("pointerup", disarm, { once: true });
160
+ window.addEventListener("pointercancel", disarm, { once: true });
161
+ return () => {
162
+ window.removeEventListener("pointerup", disarm);
163
+ window.removeEventListener("pointercancel", disarm);
164
+ };
165
+ }, [armed, dragging]);
166
+ const onHandleKeyDown = (event, key) => {
167
+ if (disabled) return;
168
+ const isGrabbed = grabbed?.key === key;
169
+ const index = keys.indexOf(key);
170
+ const delta = event.key === "ArrowUp" ? -1 : event.key === "ArrowDown" ? 1 : 0;
171
+ if (isGrabbed) {
172
+ if (delta) {
173
+ event.preventDefault();
174
+ step(key, index + delta);
175
+ } else if (event.key === "Home" || event.key === "End") {
176
+ event.preventDefault();
177
+ step(key, event.key === "Home" ? 0 : total - 1);
178
+ }
179
+ return;
180
+ }
181
+ if (delta && event.altKey) {
182
+ event.preventDefault();
183
+ move(key, index + delta);
184
+ }
185
+ };
186
+ const onHandleClick = (event, key) => {
187
+ if (disabled || event.detail !== 0) return;
188
+ if (grabbed?.key === key) drop(key);
189
+ else if (!grabbed) pickUp(key);
190
+ };
191
+ const onDragOver = (event, key) => {
192
+ if (!dragging) return;
193
+ event.preventDefault();
194
+ event.dataTransfer.dropEffect = "move";
195
+ const rect = event.currentTarget.getBoundingClientRect();
196
+ const edge = event.clientY < rect.top + rect.height / 2 ? "before" : "after";
197
+ if (dropAt?.key !== key || dropAt.edge !== edge) setDropAt({ key, edge });
198
+ };
199
+ const endDrag = () => {
200
+ setDragging(null);
201
+ setDropAt(null);
202
+ setArmed(null);
203
+ };
204
+ const onDrop = (event) => {
205
+ event.preventDefault();
206
+ const key = event.dataTransfer.getData(DRAG_TYPE) || dragging;
207
+ const target = dropAt;
208
+ endDrag();
209
+ if (!key || !target || pending || grabbed) return;
210
+ const from = itemKeys.indexOf(key);
211
+ const over = itemKeys.indexOf(target.key);
212
+ if (from < 0 || over < 0) return;
213
+ let to = target.edge === "before" ? over : over + 1;
214
+ if (from < to) to -= 1;
215
+ commit(key, from, to, `${nameOf(key)} dropped at position ${to + 1} of ${total}.`);
216
+ };
217
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
218
+ /* @__PURE__ */ jsx("ul", { "aria-label": label, "aria-busy": pending || void 0, className: cn("flex flex-col gap-1", className), children: keys.map((key, index) => {
219
+ const item = byKey.get(key);
220
+ const itemLabel = getItemLabel(item);
221
+ const isGrabbed = grabbed?.key === key;
222
+ const isDragging = dragging === key;
223
+ const handle = disabled ? null : /* @__PURE__ */ jsx(
224
+ "button",
225
+ {
226
+ type: "button",
227
+ ref: (node) => {
228
+ if (node) handles.current.set(key, node);
229
+ else handles.current.delete(key);
230
+ },
231
+ "aria-label": `Reorder ${itemLabel}`,
232
+ "aria-describedby": instructionsId,
233
+ "data-grabbed": isGrabbed || void 0,
234
+ className: cn(
235
+ "inline-flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded text-muted-foreground",
236
+ "hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
237
+ isGrabbed && "bg-accent text-foreground"
238
+ ),
239
+ onPointerDown: () => {
240
+ if (!pending && !grabbed) setArmed(key);
241
+ },
242
+ onPointerCancel: () => setArmed(null),
243
+ onClick: (event) => onHandleClick(event, key),
244
+ onKeyDown: (event) => onHandleKeyDown(event, key),
245
+ onBlur: () => {
246
+ if (isGrabbed && refocus.current !== key) cancel(key);
247
+ },
248
+ children: /* @__PURE__ */ jsx(GripVertical, { className: "h-4 w-4", "aria-hidden": true })
249
+ }
250
+ );
251
+ return /* @__PURE__ */ jsxs(
252
+ "li",
253
+ {
254
+ "data-sortable-key": key,
255
+ draggable: !disabled && armed === key || void 0,
256
+ className: cn(
257
+ "relative rounded-md",
258
+ moveMenu && !disabled && "pr-8",
259
+ isDragging && "opacity-50",
260
+ isGrabbed && "ring-2 ring-primary/50",
261
+ itemClassName
262
+ ),
263
+ onDragStart: (event) => {
264
+ if (disabled || armed !== key) return;
265
+ event.dataTransfer.setData(DRAG_TYPE, key);
266
+ event.dataTransfer.effectAllowed = "move";
267
+ setDragging(key);
268
+ },
269
+ onDragEnd: endDrag,
270
+ onDragOver: (event) => onDragOver(event, key),
271
+ onDrop,
272
+ children: [
273
+ dropAt?.key === key && dragging !== key && /* @__PURE__ */ jsx(
274
+ "span",
275
+ {
276
+ "aria-hidden": true,
277
+ className: cn(
278
+ "pointer-events-none absolute inset-x-0 h-0.5 rounded bg-primary",
279
+ dropAt.edge === "before" ? "-top-0.5" : "-bottom-0.5"
280
+ )
281
+ }
282
+ ),
283
+ renderItem(item, {
284
+ index,
285
+ handle,
286
+ isDragging,
287
+ isGrabbed,
288
+ moveUp: () => move(key, index - 1),
289
+ moveDown: () => move(key, index + 1),
290
+ moveTo: (to) => move(key, to)
291
+ }),
292
+ moveMenu && !disabled && total > 1 && /* @__PURE__ */ jsxs(DropdownMenu, { children: [
293
+ /* @__PURE__ */ jsx(
294
+ DropdownMenuTrigger,
295
+ {
296
+ "aria-label": `Move ${itemLabel}`,
297
+ className: "absolute right-1 top-1 rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
298
+ children: /* @__PURE__ */ jsx(MoreVertical, { className: "h-4 w-4", "aria-hidden": true })
299
+ }
300
+ ),
301
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", children: [
302
+ /* @__PURE__ */ jsx(DropdownMenuItem, { disabled: index === 0, onSelect: () => move(key, index - 1), children: "Move up" }),
303
+ /* @__PURE__ */ jsx(DropdownMenuItem, { disabled: index === total - 1, onSelect: () => move(key, index + 1), children: "Move down" }),
304
+ /* @__PURE__ */ jsx(DropdownMenuItem, { disabled: index === 0, onSelect: () => move(key, 0), children: "Move to top" }),
305
+ /* @__PURE__ */ jsx(DropdownMenuItem, { disabled: index === total - 1, onSelect: () => move(key, total - 1), children: "Move to bottom" })
306
+ ] })
307
+ ] })
308
+ ]
309
+ },
310
+ key
311
+ );
312
+ }) }),
313
+ /* @__PURE__ */ jsx("p", { id: instructionsId, hidden: true, children: "Space or Enter picks the item up. Up and down arrows, Home and End move it. Space or Enter drops it, Escape puts it back. Alt with an arrow moves it one step." }),
314
+ /* @__PURE__ */ jsx("div", { "aria-live": "polite", "aria-atomic": "true", className: "sr-only", children: announcement })
315
+ ] });
316
+ }
317
+
318
+ export { SortableList };
319
+ //# sourceMappingURL=chunk-TXOZMKNW.js.map
320
+ //# sourceMappingURL=chunk-TXOZMKNW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/patterns/sortable-list.tsx"],"names":[],"mappings":";;;;;;AAkEA,IAAM,SAAA,GAAY,qCAAA;AAGlB,IAAM,yBAAA,GAA4B,OAAO,MAAA,KAAW,WAAA,GAAoB,KAAA,CAAA,SAAA,GAAkB,KAAA,CAAA,eAAA;AAE1F,SAAS,KAAA,CAAM,IAAA,EAAyB,IAAA,EAAc,EAAA,EAAY;AAChE,EAAA,MAAM,IAAA,GAAO,KAAK,KAAA,EAAM;AACxB,EAAA,MAAM,CAAC,GAAG,CAAA,GAAI,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,CAAA;AACjC,EAAA,IAAA,CAAK,MAAA,CAAO,EAAA,EAAI,CAAA,EAAG,GAAI,CAAA;AACvB,EAAA,OAAO,IAAA;AACT;AAqBO,SAAS,YAAA,CAAgB;AAAA,EAC9B,KAAA;AAAA,EACA,MAAA;AAAA,EACA,YAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA,GAAW,IAAA;AAAA,EACX,SAAA;AAAA,EACA;AACF,CAAA,EAAyB;AACvB,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAU,eAAwB,IAAI,CAAA;AAC5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","file":"chunk-TXOZMKNW.js","sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { GripVertical, MoreVertical } from \"lucide-react\";\nimport { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from \"../ui/dropdown-menu\";\nimport { cn } from \"../../utils\";\n\nexport interface SortableListItemContext {\n /** The item's position as shown, from 0. */\n index: number;\n /**\n * The drag handle: drag it with a pointer, or focus it and press Space or\n * Enter to pick the item up, the arrow keys to move it and Space or Enter\n * again to drop it. Render it somewhere in the row.\n */\n handle: React.ReactNode;\n /** True while this item is being dragged with a pointer. */\n isDragging: boolean;\n /** True while this item is picked up from the keyboard. */\n isGrabbed: boolean;\n /** Move this item without dragging, for a row menu of your own. */\n moveUp: () => void;\n moveDown: () => void;\n moveTo: (index: number) => void;\n}\n\nexport interface SortableListReorder {\n /** Key of the item that moved. */\n key: string;\n}\n\nexport interface SortableListProps<T> {\n items: readonly T[];\n /** A stable key per item. Required: dragging finds the item again by key. */\n getKey: (item: T) => string;\n /** A name for an item, for the handle's label and announcements (\"Week 1\"). */\n getItemLabel: (item: T) => string;\n renderItem: (item: T, context: SortableListItemContext) => React.ReactNode;\n /**\n * Move the item at `from` to `to` (both from 0, `to` counted after the item\n * is taken out). Each finished move calls this once: a keyboard pick-up\n * that wanders and comes back calls nothing.\n *\n * The list shows the new order straight away and keeps showing it until the\n * returned promise settles; by then `items` must be in the new order. A\n * synchronous handler must update `items` in the same tick. A rejected\n * promise puts the old order back and announces that the move failed. Other\n * moves wait until this one settles.\n */\n onReorder: (from: number, to: number, move: SortableListReorder) => void | Promise<void>;\n /** Accessible name of the list (\"Course steps\"). */\n label: string;\n /** Turns off dragging and every kind of move. */\n disabled?: boolean | undefined;\n /**\n * A \"Move\" menu on each row (up, down, to top, to bottom), on by default so\n * touch and screen-reader users always have a way to move an item. Turn it\n * off only when the row offers `moveUp` / `moveDown` / `moveTo` itself.\n */\n moveMenu?: boolean | undefined;\n className?: string | undefined;\n itemClassName?: string | undefined;\n}\n\ntype DropAt = { key: string; edge: \"before\" | \"after\" };\n\nconst DRAG_TYPE = \"application/x-genesis-sortable-item\";\n\n// useLayoutEffect warns during server rendering; nothing needs refocusing there.\nconst useIsomorphicLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nfunction moved(keys: readonly string[], from: number, to: number) {\n const next = keys.slice();\n const [key] = next.splice(from, 1);\n next.splice(to, 0, key!);\n return next;\n}\n\n/**\n * A vertical list the user can rearrange: course steps, lesson blocks, form\n * fields.\n *\n * Every way to move an item is equivalent, so dragging is never the only one\n * (the same stance as KanbanBoard's \"Move to…\" menu):\n * - drag the handle with a pointer;\n * - focus the handle, Space or Enter to pick up, ↑/↓ and Home/End to move,\n * Space or Enter to drop, Escape to put it back (tabbing away also puts it\n * back); Alt+↑/↓ moves one step without picking up;\n * - the row's \"Move\" menu, or `moveUp` / `moveDown` / `moveTo` from the render\n * context.\n *\n * Moves are announced in a polite live region once they succeed. Native drag\n * and drop needs no dependency and Radix has none to offer (docs/FRAMEWORK.md\n * rule 3).\n *\n * @stability Beta\n */\nexport function SortableList<T>({\n items,\n getKey,\n getItemLabel,\n renderItem,\n onReorder,\n label,\n disabled,\n moveMenu = true,\n className,\n itemClassName,\n}: SortableListProps<T>) {\n const [armed, setArmed] = React.useState<string | null>(null);\n const [dragging, setDragging] = React.useState<string | null>(null);\n const [dropAt, setDropAt] = React.useState<DropAt | null>(null);\n // While a key is grabbed, `preview` is the order on screen; nothing is\n // written until the drop.\n const [grabbed, setGrabbed] = React.useState<{ key: string; from: number } | null>(null);\n // The order to show instead of `items`: during a keyboard pick-up, and from\n // a committed move until its promise settles.\n const [preview, setPreview] = React.useState<string[] | null>(null);\n const [pending, setPending] = React.useState(false);\n const [announcement, setAnnouncement] = React.useState(\"\");\n const handles = React.useRef(new Map<string, HTMLButtonElement>());\n const refocus = React.useRef<string | null>(null);\n const instructionsId = React.useId();\n\n const byKey = new Map(items.map((item) => [getKey(item), item] as const));\n const itemKeys = items.map(getKey);\n const keys = preview && preview.length === itemKeys.length && preview.every((k) => byKey.has(k)) ? preview : itemKeys;\n const total = keys.length;\n const nameOf = (key: string) => {\n const item = byKey.get(key);\n return item === undefined ? \"Item\" : getItemLabel(item);\n };\n\n // A live region only speaks when its text changes, so the same message\n // twice in a row is told apart by a trailing no-break space.\n const announce = (message: string) =>\n setAnnouncement((previous) => (previous === message ? `${message} ` : message));\n\n // Only follow the moved item with focus when its handle had focus (or the\n // DOM move dropped focus to the body); a row menu keeps its own focus.\n const keepFocus = (key: string) => {\n const active = typeof document === \"undefined\" ? null : document.activeElement;\n refocus.current = active === handles.current.get(key) || active === document.body || active === null ? key : null;\n };\n const keysSignature = keys.join(\"\\u0000\");\n useIsomorphicLayoutEffect(() => {\n const key = refocus.current;\n refocus.current = null;\n if (!key) return;\n const handle = handles.current.get(key);\n const active = document.activeElement;\n if (handle && (active === document.body || active === null || active === handle)) handle.focus();\n }, [keysSignature]);\n\n // An item that disappears mid-gesture, or the list turning disabled, ends\n // the gesture.\n React.useEffect(() => {\n if (disabled && (grabbed || armed || dragging)) {\n setGrabbed(null);\n setArmed(null);\n setDragging(null);\n setDropAt(null);\n if (!pending) setPreview(null);\n return;\n }\n if (dragging && !byKey.has(dragging)) {\n setDragging(null);\n setDropAt(null);\n setArmed(null);\n }\n if (grabbed && !byKey.has(grabbed.key)) {\n setGrabbed(null);\n setPreview(null);\n }\n });\n\n const commit = (key: string, from: number, to: number, message: string) => {\n if (from === to) return;\n setPending(true);\n setPreview(moved(itemKeys, from, to));\n // Called synchronously, so a synchronous handler updates `items` in the\n // same tick as the preview.\n let result: void | Promise<void>;\n try {\n result = onReorder(from, to, { key });\n } catch (error) {\n result = Promise.reject(error);\n }\n Promise.resolve(result)\n .then(\n () => announce(message),\n () => announce(`Couldn’t move ${nameOf(key)}.`),\n )\n .finally(() => {\n setPending(false);\n setPreview(null);\n });\n };\n\n const move = (key: string, to: number) => {\n if (disabled || pending || grabbed) return;\n if (!Number.isFinite(to)) return;\n const from = itemKeys.indexOf(key);\n const target = Math.max(0, Math.min(total - 1, Math.round(to)));\n if (from < 0 || target === from) return;\n keepFocus(key);\n commit(key, from, target, `${nameOf(key)} moved to position ${target + 1} of ${total}.`);\n };\n\n const pickUp = (key: string) => {\n if (disabled || pending) return;\n const from = itemKeys.indexOf(key);\n if (from < 0) return;\n setGrabbed({ key, from });\n setPreview(itemKeys);\n announce(\n `${nameOf(key)} picked up, position ${from + 1} of ${total}. Use the up and down arrow keys to move, Space to drop, Escape to cancel.`,\n );\n };\n\n const drop = (key: string) => {\n if (!grabbed) return;\n const to = keys.indexOf(key);\n const from = grabbed.from;\n setGrabbed(null);\n if (to === from) {\n setPreview(null);\n announce(`${nameOf(key)} dropped at position ${to + 1} of ${total}.`);\n return;\n }\n keepFocus(key);\n commit(key, from, to, `${nameOf(key)} dropped at position ${to + 1} of ${total}.`);\n };\n\n const cancel = (key: string) => {\n if (!grabbed) return;\n const from = grabbed.from;\n keepFocus(key);\n setGrabbed(null);\n setPreview(null);\n announce(`Move cancelled. ${nameOf(key)} is back at position ${from + 1} of ${total}.`);\n };\n\n const step = (key: string, to: number) => {\n const index = keys.indexOf(key);\n const target = Math.max(0, Math.min(total - 1, to));\n if (index < 0 || target === index) return;\n keepFocus(key);\n setPreview(moved(keys, index, target));\n announce(`${nameOf(key)} moved to position ${target + 1} of ${total}.`);\n };\n\n // Escape while an item is picked up must not also close a surrounding\n // Dialog or Sheet, which listen before the handle does.\n React.useEffect(() => {\n if (!grabbed) return;\n const onKey = (event: KeyboardEvent) => {\n if (event.key !== \"Escape\") return;\n event.preventDefault();\n event.stopPropagation();\n cancel(grabbed.key);\n };\n window.addEventListener(\"keydown\", onKey, true);\n return () => window.removeEventListener(\"keydown\", onKey, true);\n });\n\n // A press on the handle arms its row for native dragging; any release or\n // cancel, wherever it lands, disarms it.\n React.useEffect(() => {\n if (!armed || dragging) return;\n const disarm = () => setArmed(null);\n window.addEventListener(\"pointerup\", disarm, { once: true });\n window.addEventListener(\"pointercancel\", disarm, { once: true });\n return () => {\n window.removeEventListener(\"pointerup\", disarm);\n window.removeEventListener(\"pointercancel\", disarm);\n };\n }, [armed, dragging]);\n\n const onHandleKeyDown = (event: React.KeyboardEvent, key: string) => {\n if (disabled) return;\n const isGrabbed = grabbed?.key === key;\n const index = keys.indexOf(key);\n const delta = event.key === \"ArrowUp\" ? -1 : event.key === \"ArrowDown\" ? 1 : 0;\n if (isGrabbed) {\n if (delta) {\n event.preventDefault();\n step(key, index + delta);\n } else if (event.key === \"Home\" || event.key === \"End\") {\n event.preventDefault();\n step(key, event.key === \"Home\" ? 0 : total - 1);\n }\n return;\n }\n if (delta && event.altKey) {\n event.preventDefault();\n move(key, index + delta);\n }\n };\n\n // Space and Enter reach the handle as a click with `detail === 0`, as do\n // screen readers' activations; a pointer click is a press for dragging.\n const onHandleClick = (event: React.MouseEvent, key: string) => {\n if (disabled || event.detail !== 0) return;\n if (grabbed?.key === key) drop(key);\n else if (!grabbed) pickUp(key);\n };\n\n const onDragOver = (event: React.DragEvent<HTMLLIElement>, key: string) => {\n if (!dragging) return;\n event.preventDefault();\n event.dataTransfer.dropEffect = \"move\";\n const rect = event.currentTarget.getBoundingClientRect();\n const edge = event.clientY < rect.top + rect.height / 2 ? \"before\" : \"after\";\n if (dropAt?.key !== key || dropAt.edge !== edge) setDropAt({ key, edge });\n };\n\n const endDrag = () => {\n setDragging(null);\n setDropAt(null);\n setArmed(null);\n };\n\n const onDrop = (event: React.DragEvent) => {\n event.preventDefault();\n const key = event.dataTransfer.getData(DRAG_TYPE) || dragging;\n const target = dropAt;\n endDrag();\n if (!key || !target || pending || grabbed) return;\n const from = itemKeys.indexOf(key);\n const over = itemKeys.indexOf(target.key);\n if (from < 0 || over < 0) return;\n // `to` counts positions after the dragged item is taken out.\n let to = target.edge === \"before\" ? over : over + 1;\n if (from < to) to -= 1;\n commit(key, from, to, `${nameOf(key)} dropped at position ${to + 1} of ${total}.`);\n };\n\n return (\n <>\n <ul aria-label={label} aria-busy={pending || undefined} className={cn(\"flex flex-col gap-1\", className)}>\n {keys.map((key, index) => {\n const item = byKey.get(key)!;\n const itemLabel = getItemLabel(item);\n const isGrabbed = grabbed?.key === key;\n const isDragging = dragging === key;\n const handle = disabled ? null : (\n <button\n type=\"button\"\n ref={(node) => {\n if (node) handles.current.set(key, node);\n else handles.current.delete(key);\n }}\n aria-label={`Reorder ${itemLabel}`}\n aria-describedby={instructionsId}\n data-grabbed={isGrabbed || undefined}\n className={cn(\n \"inline-flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded text-muted-foreground\",\n \"hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n isGrabbed && \"bg-accent text-foreground\",\n )}\n onPointerDown={() => {\n if (!pending && !grabbed) setArmed(key);\n }}\n onPointerCancel={() => setArmed(null)}\n onClick={(event) => onHandleClick(event, key)}\n onKeyDown={(event) => onHandleKeyDown(event, key)}\n onBlur={() => {\n // A DOM move during the pick-up blurs the handle for a moment;\n // that is not the user leaving.\n if (isGrabbed && refocus.current !== key) cancel(key);\n }}\n >\n <GripVertical className=\"h-4 w-4\" aria-hidden />\n </button>\n );\n return (\n <li\n key={key}\n data-sortable-key={key}\n draggable={(!disabled && armed === key) || undefined}\n className={cn(\n \"relative rounded-md\",\n moveMenu && !disabled && \"pr-8\",\n isDragging && \"opacity-50\",\n isGrabbed && \"ring-2 ring-primary/50\",\n itemClassName,\n )}\n onDragStart={(event) => {\n if (disabled || armed !== key) return;\n event.dataTransfer.setData(DRAG_TYPE, key);\n event.dataTransfer.effectAllowed = \"move\";\n setDragging(key);\n }}\n onDragEnd={endDrag}\n onDragOver={(event) => onDragOver(event, key)}\n onDrop={onDrop}\n >\n {dropAt?.key === key && dragging !== key && (\n <span\n aria-hidden\n className={cn(\n \"pointer-events-none absolute inset-x-0 h-0.5 rounded bg-primary\",\n dropAt.edge === \"before\" ? \"-top-0.5\" : \"-bottom-0.5\",\n )}\n />\n )}\n {renderItem(item, {\n index,\n handle,\n isDragging,\n isGrabbed,\n moveUp: () => move(key, index - 1),\n moveDown: () => move(key, index + 1),\n moveTo: (to) => move(key, to),\n })}\n {moveMenu && !disabled && total > 1 && (\n <DropdownMenu>\n <DropdownMenuTrigger\n aria-label={`Move ${itemLabel}`}\n className=\"absolute right-1 top-1 rounded p-1 text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <MoreVertical className=\"h-4 w-4\" aria-hidden />\n </DropdownMenuTrigger>\n <DropdownMenuContent align=\"end\">\n <DropdownMenuItem disabled={index === 0} onSelect={() => move(key, index - 1)}>\n Move up\n </DropdownMenuItem>\n <DropdownMenuItem disabled={index === total - 1} onSelect={() => move(key, index + 1)}>\n Move down\n </DropdownMenuItem>\n <DropdownMenuItem disabled={index === 0} onSelect={() => move(key, 0)}>\n Move to top\n </DropdownMenuItem>\n <DropdownMenuItem disabled={index === total - 1} onSelect={() => move(key, total - 1)}>\n Move to bottom\n </DropdownMenuItem>\n </DropdownMenuContent>\n </DropdownMenu>\n )}\n </li>\n );\n })}\n </ul>\n <p id={instructionsId} hidden>\n Space or Enter picks the item up. Up and down arrows, Home and End move it. Space or Enter drops it, Escape puts\n it back. Alt with an arrow moves it one step.\n </p>\n <div aria-live=\"polite\" aria-atomic=\"true\" className=\"sr-only\">\n {announcement}\n </div>\n </>\n );\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  "use client";
2
2
  import { ViewToggle, ViewSettings } from './chunk-46TZGMFW.js';
3
- import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from './chunk-QJ6P2DW6.js';
4
3
  import { Collapsible, CollapsibleContent } from './chunk-B2GIBUQD.js';
5
4
  import { Badge } from './chunk-NPNADZHM.js';
6
5
  import { Popover, PopoverTrigger, PopoverContent } from './chunk-22XB3Q6H.js';
6
+ import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from './chunk-QJ6P2DW6.js';
7
7
  import { Switch } from './chunk-27ELYTGE.js';
8
8
  import { Button } from './chunk-NWSCYLPT.js';
9
9
  import { Label } from './chunk-F47U5KNW.js';
@@ -1149,5 +1149,5 @@ function AppShell({
1149
1149
  }
1150
1150
 
1151
1151
  export { AppShell, PageHeader };
1152
- //# sourceMappingURL=chunk-DWM7ELFI.js.map
1153
- //# sourceMappingURL=chunk-DWM7ELFI.js.map
1152
+ //# sourceMappingURL=chunk-ZPPLUGLA.js.map
1153
+ //# sourceMappingURL=chunk-ZPPLUGLA.js.map