{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"widget-reorder-input","type":"registry:component","title":"Widget Reorder Input","description":"A \"customise your dashboard\" panel: drag or keyboard reorder, show and hide switches, a live miniature of the result, and save, cancel and reset.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/widget-reorder-input.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, KeyboardEvent as ReactKeyboardEvent, PointerEvent as ReactPointerEvent, RefObject } from \"react\";\n\n/**\n * WidgetReorderInput — the \"customise your dashboard\" panel, in the bento\n * kit's utility register.\n *\n * A list of widgets on shared hairlines: drag a row by its grip, or do it\n * all from the keyboard (Space picks a row up, the arrow keys move it, Space\n * drops it and Escape puts it back; Alt with an arrow moves it in one step).\n * A switch shows or hides each widget. Beside the list, a miniature of the\n * dashboard redraws as you go, each tile gliding to its new place, so the\n * result is visible before it is saved. Save hands the new layout to\n * `onSave`; Cancel returns to the last save and Reset to the defaults.\n * Every move is announced to screen readers.\n *\n * Needs Tailwind v4 (container queries are built in). No dependencies beyond\n * React.\n */\n\nexport type DashWidget = {\n  id: string;\n  name: string;\n  /** Footprint on the dashboard: columns x rows. */\n  size: \"1x1\" | \"2x1\" | \"1x2\" | \"2x2\";\n  visible: boolean;\n};\n\nexport type WidgetReorderInputProps = {\n  title?: string;\n  /** The saved layout, in order. */\n  widgets: DashWidget[];\n  /** What Reset returns to. Defaults to `widgets`. */\n  defaults?: DashWidget[];\n  /** Store the layout. Resolve when it is stored; throw to show the error. */\n  onSave?: (widgets: DashWidget[]) => Promise<void> | void;\n  accent?: string;\n  className?: string;\n};\n\nconst MONO = \"var(--font-mono, var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace))\";\nconst OUT = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n/** The kit's reorder spring, shared with the rest of the Bento kit. */\nconst SPRING = \"cubic-bezier(0.34, 1.25, 0.64, 1)\";\nconst SPAN: Record<DashWidget[\"size\"], string> = {\n  \"1x1\": \"\",\n  \"2x1\": \"col-span-2\",\n  \"1x2\": \"row-span-2\",\n  \"2x2\": \"col-span-2 row-span-2\",\n};\n\n/** \"#rrggbb\" if valid, otherwise the fallback. Never interpolated unchecked. */\nfunction safeHex(hex: string | undefined, fallback: string): string {\n  return /^#[0-9a-f]{6}$/i.test(hex || \"\") ? (hex as string) : fallback;\n}\n\nfunction isLight(hex: string): boolean {\n  const n = parseInt(hex.slice(1), 16);\n  const c = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((v) => {\n    const s = v / 255;\n    return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);\n  });\n  return 0.2126 * c[0] + 0.7152 * c[1] + 0.0722 * c[2] > 0.18;\n}\n\nfunction reduced(): boolean {\n  return window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\nfunction move<T>(list: T[], from: number, to: number): T[] {\n  const next = list.slice();\n  const [item] = next.splice(from, 1);\n  next.splice(to, 0, item);\n  return next;\n}\n\n/** Remember where each child sat, then glide the ones that moved. */\nfunction useFlip(ref: RefObject<HTMLElement | null>, key: string, skip?: string | null) {\n  const last = useRef(new Map<string, { x: number; y: number }>());\n  useLayoutEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    const next = new Map<string, { x: number; y: number }>();\n    const runs: Animation[] = [];\n    const still = reduced();\n    root.querySelectorAll<HTMLElement>(\"[data-flip]\").forEach((el) => {\n      const id = el.dataset.flip as string;\n      const pos = { x: el.offsetLeft, y: el.offsetTop };\n      next.set(id, pos);\n      const prev = last.current.get(id);\n      if (still || id === skip) return;\n      if (!prev) {\n        if (last.current.size) runs.push(el.animate([{ opacity: 0, transform: \"scale(0.92)\" }, { opacity: 1, transform: \"none\" }], { duration: 260, easing: OUT }));\n        return;\n      }\n      const dx = prev.x - pos.x;\n      const dy = prev.y - pos.y;\n      if (dx || dy) runs.push(el.animate([{ transform: \"translate(\" + dx + \"px,\" + dy + \"px)\" }, { transform: \"none\" }], { duration: 380, easing: SPRING }));\n    });\n    last.current = next;\n    return () => runs.forEach((a) => a.finish());\n  }, [ref, key, skip]);\n}\n\nexport function WidgetReorderInput({ title = \"Customise dashboard\", widgets, defaults, onSave, accent, className = \"\" }: WidgetReorderInputProps) {\n  const uid = useId();\n  const tint = safeHex(accent, \"#ff5a1f\");\n  const ink = isLight(tint) ? \"#0b0b0c\" : \"#ffffff\";\n\n  const [saved, setSaved] = useState(widgets);\n  const [draft, setDraft] = useState(widgets);\n  const [grabbed, setGrabbed] = useState<{ id: string; from: number } | null>(null);\n  const [dragging, setDragging] = useState<string | null>(null);\n  const [said, setSaid] = useState(\"\");\n  const [saveState, setSaveState] = useState<\"idle\" | \"busy\" | \"done\" | \"error\">(\"idle\");\n\n  const listRef = useRef<HTMLUListElement>(null);\n  const miniRef = useRef<HTMLDivElement>(null);\n  const refocus = useRef<string | null>(null);\n  const drag = useRef({ id: \"\", pointer: 0, startY: 0, grab: 0, pitch: 49, active: false, lastY: 0 });\n  const saveRun = useRef(0);\n\n  const order = draft.map((w) => w.id + (w.visible ? \"\" : \"~\")).join(\",\");\n  useFlip(listRef, order, dragging);\n  useFlip(miniRef, order);\n\n  // After a keyboard move React may have moved the row's node: focus it again.\n  useLayoutEffect(() => {\n    const id = refocus.current;\n    if (!id) return;\n    refocus.current = null;\n    listRef.current?.querySelector<HTMLElement>('[data-grip=\"' + CSS.escape(id) + '\"]')?.focus();\n  }, [order]);\n\n  // While dragging, keep the row under the pointer across re-orders.\n  useLayoutEffect(() => {\n    const d = drag.current;\n    if (!dragging || !d.active) return;\n    const row = listRef.current?.querySelector<HTMLElement>('[data-flip=\"' + CSS.escape(d.id) + '\"]');\n    if (row) row.style.transform = \"translateY(\" + (d.lastY - d.grab - row.offsetTop) + \"px)\";\n  });\n\n  useEffect(() => {\n    if (saveState !== \"done\") return;\n    const t = window.setTimeout(() => setSaveState(\"idle\"), 1400);\n    return () => window.clearTimeout(t);\n  }, [saveState]);\n\n  // Changes as a person counts them: rows moved (all rows minus the longest\n  // run still in saved order, so one drag is one change) plus rows switched.\n  const savedAt = new Map(saved.map((s, i) => [s.id, i]));\n  const seq = draft.map((w) => savedAt.get(w.id) ?? -1).filter((i) => i >= 0);\n  const run: number[] = [];\n  seq.forEach((v, i) => {\n    run[i] = 1;\n    for (let j = 0; j < i; j++) if (seq[j] < v && run[j] + 1 > run[i]) run[i] = run[j] + 1;\n  });\n  const moved = seq.length - (run.length ? Math.max(...run) : 0);\n  const switched = draft.filter((w) => {\n    const j = savedAt.get(w.id);\n    return j === undefined || saved[j].visible !== w.visible;\n  }).length;\n  const changes = moved + switched;\n  const dirty = changes > 0;\n\n  function announce(text: string) {\n    setSaid(text);\n  }\n  function posText(i: number) {\n    return \"position \" + (i + 1) + \" of \" + draft.length;\n  }\n\n  // ---- Keyboard -----------------------------------------------------------\n  function onGripKey(e: ReactKeyboardEvent, w: DashWidget, i: number) {\n    const up = e.key === \"ArrowUp\";\n    const down = e.key === \"ArrowDown\";\n    if ((up || down) && (e.altKey || grabbed?.id === w.id)) {\n      e.preventDefault();\n      const to = Math.max(0, Math.min(draft.length - 1, i + (up ? -1 : 1)));\n      if (to === i) return;\n      refocus.current = w.id;\n      setDraft(move(draft, i, to));\n      announce(w.name + \", moved to \" + posText(to) + \".\");\n      return;\n    }\n    if (e.key === \" \" || e.key === \"Enter\") {\n      e.preventDefault();\n      if (grabbed?.id === w.id) {\n        setGrabbed(null);\n        announce(w.name + \", dropped at \" + posText(i) + \".\");\n      } else {\n        setGrabbed({ id: w.id, from: i });\n        announce(w.name + \", picked up at \" + posText(i) + \". Use the arrow keys to move, Space to drop, Escape to cancel.\");\n      }\n      return;\n    }\n    if (e.key === \"Escape\" && grabbed?.id === w.id) {\n      e.preventDefault();\n      refocus.current = w.id;\n      setDraft(move(draft, i, grabbed.from));\n      setGrabbed(null);\n      announce(w.name + \", move cancelled. Back at \" + posText(grabbed.from) + \".\");\n    }\n  }\n\n  // ---- Pointer ------------------------------------------------------------\n  function local(clientY: number) {\n    const list = listRef.current as HTMLUListElement;\n    const r = list.getBoundingClientRect();\n    return (clientY - r.top) * (list.offsetHeight / (r.height || 1));\n  }\n  function rowOf(id: string) {\n    return listRef.current?.querySelector<HTMLElement>('[data-flip=\"' + CSS.escape(id) + '\"]') ?? null;\n  }\n  function place(y: number) {\n    const d = drag.current;\n    const row = rowOf(d.id);\n    if (!row) return;\n    row.style.transform = \"translateY(\" + (y - d.grab - row.offsetTop) + \"px)\";\n  }\n  function onGripDown(e: ReactPointerEvent, w: DashWidget) {\n    if (e.button !== 0 || !listRef.current) return;\n    const row = rowOf(w.id);\n    if (!row) return;\n    const rows = listRef.current.querySelectorAll<HTMLElement>(\"[data-flip]\");\n    const y = local(e.clientY);\n    drag.current = {\n      id: w.id,\n      pointer: e.pointerId,\n      startY: y,\n      grab: y - row.offsetTop,\n      pitch: rows.length > 1 ? rows[1].offsetTop - rows[0].offsetTop : row.offsetHeight,\n      active: false,\n      lastY: y,\n    };\n    try {\n      (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n    } catch {\n      // Synthetic or already-released pointers cannot be captured.\n    }\n  }\n  function onGripMove(e: ReactPointerEvent) {\n    const d = drag.current;\n    if (!d.id || e.pointerId !== d.pointer) return;\n    const y = local(e.clientY);\n    d.lastY = y;\n    if (!d.active) {\n      if (Math.abs(y - d.startY) < 6) return;\n      d.active = true;\n      setDragging(d.id);\n      setGrabbed(null);\n    }\n    const from = draft.findIndex((w) => w.id === d.id);\n    const to = Math.max(0, Math.min(draft.length - 1, Math.round((y - d.grab) / d.pitch)));\n    if (from !== -1 && to !== from) setDraft(move(draft, from, to));\n    place(y);\n  }\n  function onGripUp(e: ReactPointerEvent) {\n    const d = drag.current;\n    if (!d.id || e.pointerId !== d.pointer) return;\n    const row = rowOf(d.id);\n    const wasActive = d.active;\n    const id = d.id;\n    drag.current = { ...d, id: \"\", active: false };\n    if (!wasActive) return;\n    if (row) {\n      const from = row.style.transform;\n      row.style.transform = \"\";\n      if (from && !reduced()) row.animate([{ transform: from }, { transform: \"none\" }], { duration: 320, easing: SPRING });\n    }\n    setDragging(null);\n    const i = draft.findIndex((w) => w.id === id);\n    const w = draft[i];\n    if (w) announce(w.name + \", dropped at \" + posText(i) + \".\");\n  }\n\n  // ---- Actions ------------------------------------------------------------\n  function toggle(id: string) {\n    const w = draft.find((x) => x.id === id);\n    setDraft(draft.map((x) => (x.id === id ? { ...x, visible: !x.visible } : x)));\n    if (w) announce(w.name + (w.visible ? \" hidden.\" : \" shown.\"));\n  }\n  async function save() {\n    if (!dirty || saveState === \"busy\") return;\n    const run = ++saveRun.current;\n    const sent = draft;\n    setSaveState(\"busy\");\n    try {\n      if (onSave) await onSave(sent);\n      if (run !== saveRun.current) return;\n      setSaved(sent);\n      setSaveState(\"done\");\n      announce(\"Layout saved.\");\n    } catch {\n      if (run !== saveRun.current) return;\n      setSaveState(\"error\");\n      announce(\"The layout was not saved. Try again.\");\n    }\n  }\n\n  const hint = uid + \"-hint\";\n  const btn =\n    \"inline-flex h-9 items-center justify-center rounded-[10px] px-3.5 text-[13px] font-medium outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-white/80 disabled:opacity-40 motion-reduce:transition-none\";\n\n  return (\n    <section\n      aria-labelledby={uid + \"-title\"}\n      className={\"@container relative w-full rounded-[20px] bg-[#0f1012] text-white \" + className}\n      style={{ boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.08)\" }}\n    >\n      <div className=\"flex items-center justify-between gap-4 px-5 pt-5\">\n        <div>\n          <h2 id={uid + \"-title\"} className=\"text-[17px] font-semibold tracking-[-0.01em]\">\n            {title}\n          </h2>\n          <p className=\"mt-1 text-[13px] text-white/50\">Drag to reorder, or use the keyboard. Switch widgets on and off.</p>\n        </div>\n        <p className=\"shrink-0 text-[11px] uppercase tracking-[0.12em] text-white/50\" style={{ fontFamily: MONO }}>\n          {dirty ? changes + (changes === 1 ? \" change\" : \" changes\") : \"Saved\"}\n        </p>\n      </div>\n      <p id={hint} className=\"sr-only\">\n        Press Space to pick up, the arrow keys to move, Space to drop and Escape to cancel. Alt and an arrow key moves it in one step.\n      </p>\n      <p className=\"sr-only\" aria-live=\"polite\" role=\"status\">\n        {said}\n      </p>\n\n      <div className=\"grid gap-5 p-5 @3xl:grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)]\">\n        {/* The list, on shared hairlines. */}\n        <div className=\"relative isolate rounded-[14px]\">\n          <span aria-hidden className=\"pointer-events-none absolute inset-0 -z-10 rounded-[14px] bg-white/[0.08]\" />\n          <ul ref={listRef} role=\"list\" className=\"relative m-px flex flex-col gap-px overflow-hidden rounded-[13px]\">\n            {draft.map((w, i) => {\n              const held = grabbed?.id === w.id || dragging === w.id;\n              return (\n                <li\n                  key={w.id}\n                  data-flip={w.id}\n                  className={\"relative flex h-12 items-center gap-3 pr-3 transition-colors duration-150 \" + (held ? \"z-10 bg-[#1b1c20]\" : \"bg-[#131417]\")}\n                  style={held ? { boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.22)\" } : undefined}\n                >\n                  <button\n                    type=\"button\"\n                    data-grip={w.id}\n                    aria-label={\"Move \" + w.name}\n                    aria-describedby={hint}\n                    aria-pressed={grabbed?.id === w.id}\n                    onKeyDown={(e) => onGripKey(e, w, i)}\n                    onBlur={() => {\n                      if (grabbed?.id === w.id && refocus.current !== w.id) {\n                        setGrabbed(null);\n                        announce(w.name + \", dropped at \" + posText(i) + \".\");\n                      }\n                    }}\n                    onPointerDown={(e) => onGripDown(e, w)}\n                    onPointerMove={onGripMove}\n                    onPointerUp={onGripUp}\n                    onPointerCancel={onGripUp}\n                    className={\n                      \"grid h-full w-10 shrink-0 touch-none place-items-center text-white/40 outline-none hover:text-white focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-white/80 \" +\n                      (dragging === w.id ? \"cursor-grabbing\" : \"cursor-grab\")\n                    }\n                  >\n                    <svg aria-hidden width=\"10\" height=\"14\" viewBox=\"0 0 10 14\" fill=\"currentColor\">\n                      <circle cx=\"2.5\" cy=\"2.5\" r=\"1.3\" />\n                      <circle cx=\"7.5\" cy=\"2.5\" r=\"1.3\" />\n                      <circle cx=\"2.5\" cy=\"7\" r=\"1.3\" />\n                      <circle cx=\"7.5\" cy=\"7\" r=\"1.3\" />\n                      <circle cx=\"2.5\" cy=\"11.5\" r=\"1.3\" />\n                      <circle cx=\"7.5\" cy=\"11.5\" r=\"1.3\" />\n                    </svg>\n                  </button>\n                  <span className={\"min-w-0 flex-1 truncate text-[14px] \" + (w.visible ? \"text-white\" : \"text-white/40\")}>{w.name}</span>\n                  <span className=\"shrink-0 text-[11px] text-white/40\" style={{ fontFamily: MONO }}>\n                    {w.size}\n                  </span>\n                  <button\n                    type=\"button\"\n                    role=\"switch\"\n                    aria-checked={w.visible}\n                    aria-label={\"Show \" + w.name}\n                    onClick={() => toggle(w.id)}\n                    className={\n                      \"relative h-5 w-9 shrink-0 rounded-full outline-none transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-white/80 focus-visible:ring-offset-2 focus-visible:ring-offset-[#131417] motion-reduce:transition-none \" +\n                      (w.visible ? \"bg-white/90\" : \"bg-[#26272b]\")\n                    }\n                  >\n                    <span\n                      aria-hidden\n                      className={\"absolute top-0.5 left-0.5 size-4 rounded-full transition-transform duration-200 motion-reduce:transition-none \" + (w.visible ? \"bg-[#0f1012]\" : \"bg-white/60\")}\n                      style={{ transform: w.visible ? \"translateX(16px)\" : \"none\", transitionTimingFunction: OUT }}\n                    />\n                  </button>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n\n        {/* The miniature: the dashboard as it will be. A screen inside the\n            tile, so it drops back to the canvas colour on purpose. */}\n        <div aria-hidden className=\"rounded-[14px] bg-[#08090a] p-3\" style={{ boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.06)\" }}>\n          <p className=\"mb-2.5 text-[11px] uppercase tracking-[0.12em] text-white/40\" style={{ fontFamily: MONO }}>\n            Preview\n          </p>\n          <div ref={miniRef} className=\"grid grid-cols-4 gap-1.5\" style={{ gridAutoRows: \"56px\", gridAutoFlow: \"dense\" }}>\n            {draft\n              .filter((w) => w.visible)\n              .map((w) => (\n                <div\n                  key={w.id}\n                  data-flip={w.id}\n                  className={\"flex items-end overflow-hidden rounded-[10px] bg-[#16171a] p-1.5 \" + SPAN[w.size]}\n                  style={{\n                    boxShadow: \"inset 0 0 0 1px \" + (dragging === w.id || grabbed?.id === w.id ? \"rgba(255,255,255,0.4)\" : \"rgba(255,255,255,0.08)\"),\n                  }}\n                >\n                  <span className=\"truncate text-[10px] leading-none text-white/55\" style={{ fontFamily: MONO }}>\n                    {w.name}\n                  </span>\n                </div>\n              ))}\n          </div>\n        </div>\n      </div>\n\n      <div className=\"flex flex-wrap items-center justify-between gap-3 px-5 pb-5\" style={{ borderTop: \"1px solid rgba(255,255,255,0.08)\", paddingTop: 16 }}>\n        <button\n          type=\"button\"\n          disabled={saveState === \"busy\"}\n          onClick={() => {\n            setDraft(defaults ?? widgets);\n            announce(\"Defaults restored. Save to keep them.\");\n          }}\n          className={btn + \" -ml-2 text-white/55 hover:text-white\"}\n        >\n          Reset to defaults\n        </button>\n        <div className=\"flex items-center gap-2\">\n          {saveState === \"error\" && <span className=\"text-[12px] text-[#ff8a8a]\">Not saved. Try again.</span>}\n          <button\n            type=\"button\"\n            disabled={!dirty || saveState === \"busy\"}\n            onClick={() => {\n              setDraft(saved);\n              announce(\"Changes discarded.\");\n            }}\n            className={btn + \" text-white/70 hover:bg-[#16171a] hover:text-white\"}\n            style={{ boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.12)\" }}\n          >\n            Cancel\n          </button>\n          <button\n            type=\"button\"\n            disabled={!dirty || saveState === \"busy\"}\n            onClick={save}\n            className={btn + \" min-w-[88px] font-semibold hover:brightness-110\"}\n            style={{ background: dirty || saveState === \"done\" ? tint : \"#26272b\", color: dirty || saveState === \"done\" ? ink : \"rgba(255,255,255,0.6)\" } as CSSProperties}\n          >\n            {saveState === \"busy\" ? \"Saving…\" : saveState === \"done\" ? \"Saved\" : \"Save\"}\n          </button>\n        </div>\n      </div>\n    </section>\n  );\n}\n","type":"registry:component","target":"components/viberdy/widget-reorder-input.tsx"}],"meta":{"tier":"free","tags":["reorder","drag and drop","dashboard","settings","bento","keyboard","form"],"href":"https://viberdy.dev/library/widget-reorder-input","aiPrompt":"Create a React + Tailwind v4 client component, WidgetReorderInput: a \"customise your dashboard\" panel in a dark bento kit's utility register, with drag and full keyboard reorder, show and hide switches, a live miniature of the result, and save, cancel and reset.\n\nTypes: DashWidget = { id, name, size: \"1x1\" | \"2x1\" | \"1x2\" | \"2x2\", visible }. Props: title (default \"Customise dashboard\"), widgets (the saved layout, in order), defaults? (what Reset returns to; default widgets), onSave?(widgets) (resolve when stored, throw to show the error), accent (\"#rrggbb\", regex-validated, default #ff5a1f), className.\n\nKit tokens: the panel is a tile, #0f1012 with an inset 1px hairline at white 0.08, radius 20, and a Tailwind `@container`; rows #131417; raised #1b1c20 with a 0.22 hairline for a row being moved; mono 11px uppercase +0.12em labels in var(--font-mono, var(--font-geist-mono, ui-monospace, …)); controls radius 10; the Save button is the only accent (text dark or white by luminance) and turns grey when there is nothing to save; no shadows.\n\nState: saved, draft, grabbed ({ id, from } | null), dragging (id | null), an announcement string and a save state (idle, busy, done for 1.4s, error). The header shows the title, one line of help, and a mono count of changes or \"Saved\": rows moved (all rows minus the longest run still in saved order, so one drag counts once) plus rows whose visibility differs. A sr-only instructions paragraph and a sr-only aria-live=\"polite\" role=\"status\" line that announces every pick-up, move, drop, cancel, show, hide, save and reset.\n\nThe list, on shared hairlines: an isolated wrapper with a white 0.08 layer behind (z −1, radius 14) and a <ul role=\"list\"> with 1px margin, gap 1px, radius 13, overflow hidden; each <li> is 48px (data-flip={id}): a grip button (40px wide, a six-dot SVG, aria-label \"Move {name}\", aria-describedby the instructions, aria-pressed while picked up, touch-action none, grab and grabbing cursors), the name (white, or 40% when hidden, truncated), the size in mono, and a role=\"switch\" (aria-checked, aria-label \"Show {name}\", a 36x20 track, white 90% with a #0f1012 knob when on, #26272b with a 60% white knob when off, the knob sliding 16px over 200ms).\n\nKeyboard on the grip: Space or Enter picks up and drops; ArrowUp/ArrowDown move a picked-up row (Alt with an arrow moves any row in one step); Escape returns it to where it was picked up; blurring a picked-up row drops it. After a keyboard move, refocus the grip in a layout effect keyed on the order (React may have moved the node), and ignore the blur that move causes.\n\nPointer: pointerdown on the grip records the pointer y in list layout pixels (rect scaled by offsetHeight / rect height), the grab offset within the row and the row pitch (second row's offsetTop minus the first's); capture the pointer in try/catch. After 6px of travel, dragging starts; each move sets the target index to round((y − grab) / pitch), clamped, reorders the draft when it changes, and translates the row by y − grab − its offsetTop (a layout effect re-applies this after each reorder). On pointerup or cancel, the row settles from its transform to none (320ms on the same spring) and the drop is announced.\n\nFLIP: a hook that, in a layout effect keyed on the order string (ids plus a visibility mark), records every [data-flip] child's offsetLeft/offsetTop and animates the ones that moved from their old place (translate, 380ms on the kit's reorder spring, cubic-bezier(0.34,1.25,0.64,1)); new children scale in from 0.92 with a fade; skip the dragged row and everything under reduced motion; finish running animations in cleanup. It runs on the list and on the miniature.\n\nThe miniature (aria-hidden, #08090a with a 0.06 hairline, radius 14, a mono \"Preview\" label): a 4-column grid with 56px rows, gap 6, dense, holding the visible widgets as #16171a tiles (radius 10, spans from their size, the name in 10px mono), the moving one outlined at white 0.4. At @3xl the list and the miniature sit side by side (1.15fr and 1fr).\n\nFooter, above a 1px hairline: \"Reset to defaults\" (a text button), then Cancel (a hairline button; disabled when clean or while saving; restores the draft to saved) and Save (disabled when clean or busy; \"Saving…\", then \"Saved\"; on error a red \"Not saved. Try again.\"). Reset is disabled while saving too. Each save takes a run number and saves the draft it started with; when it resolves, it only writes saved and announces if no newer run has started.\n\nOutput one self-contained \"use client\" TSX file with no dependencies beyond React; export the DashWidget type. Build strings with + rather than template literals.","license":"https://viberdy.dev/license"}}