{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sortable-list",
  "title": "Sortable list",
  "description": "A list put in a new order by dragging an item from anywhere on it, except a control inside it, by touch with a long press, and by keyboard from its handle, and a group of lists whose items move between them. Its neighbours glide aside as it passes, each move is announced, and it works as a column or as a wrapping grid.",
  "dependencies": [
    "@ui-sdk/core",
    "@ui-sdk/react"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/button.json",
    "https://kinoui.com/r/flow.json",
    "https://kinoui.com/r/sort.json",
    "https://kinoui.com/r/refs.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/sortable-list.tsx",
      "content": "'use client'\n\nimport { buttonVariants } from '@/registry/components/kino/button'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { useFlow } from '@/registry/lib/flow'\nimport { mergeRefs } from '@/registry/lib/refs'\nimport {\n  ListsMove,\n  type SortAccepts,\n  SortContext,\n  SortItemContext,\n  type SortLayout,\n  type SortListDetails,\n  type SortGroupDetails,\n  type SortMove,\n  useGroupList,\n  useSettle,\n  useSortContext,\n  useSortGroup,\n  useSortList,\n} from '@/registry/lib/sort'\nimport { type PartProps, usePart } from '@ui-sdk/react/primitive'\nimport { type ReactNode, use, useMemo, useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A list put in a new order by dragging an item from anywhere on it (a long\n * press, by touch), or by keyboard from its handle, a grip at its start\n * that darkens under the pointer. A copy of the item follows the pointer, a\n * little raised, while the item shows where it would land as a dashed slot,\n * the others glide aside on `layout`, and let go, it glides from the copy\n * into its slot. In a `SortableGroup`, items move between its lists too.\n */\n\n/**\n * What every list shares: a frame that follows the list's height as items\n * come, go and wrap, and clips nothing a raised item's shadow needs, but\n * while it grows, when the list past its edge would make a scroller around\n * it scroll (Greg, 2026-11-27: a Kanban column showed its scrollbar). While\n * an item glides in from past it, from where its copy was let go or from\n * another list, it clips nothing and sits above the lists beside it.\n */\nconst frameClassName =\n  'relative [overflow-clip-margin:1rem] overflow-clip data-sizing:[overflow-clip-margin:0px] transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) has-[[data-settling]]:z-10 has-[[data-settling]]:overflow-visible motion-reduce:transition-none'\n\nconst listClassName = 'relative isolate flex gap-2 data-sorting:select-none'\n\n/**\n * A list of `SortableItem`s, shown in the order of `value`. A column, or\n * items that wrap in rows with `layout='grid'`, laid out by `className`.\n * Inside a `SortableGroup`, it is one of the group's lists: `id` names it in\n * the group's value and `label` to a screen reader, and the group holds its\n * order.\n */\nfunction SortableList(props: SortableListProps) {\n  return props.id === undefined ? <LoneList {...props} /> : <GroupList {...props} />\n}\n\ntype LoneListProps = Omit<\n  PartProps<'div'>,\n  'id' | 'defaultValue' | 'className' | 'children'\n> & {\n  className?: string\n  children?: ReactNode\n  /** Only a list in a `SortableGroup` has one: without it, a list is a list of its own, even inside a group's item. */\n  id?: never\n  /** The items' values, in order. */\n  value?: string[]\n  defaultValue?: string[]\n  /** Called with the new order once an item is dropped in a new place, and ui-sdk's change details. */\n  onValueChange?: (value: string[], details: SortListDetails) => void\n  layout?: SortLayout\n  disabled?: boolean\n}\n\ntype GroupListProps = Omit<PartProps<'div'>, 'id' | 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  /** Its key in the group's value. */\n  id: string\n  /** What a screen reader calls it as an item moves in or out. */\n  label: string\n  /** Neither gives nor takes an item. */\n  disabled?: boolean\n}\n\ntype SortableListProps = LoneListProps | GroupListProps\n\nfunction LoneList({\n  className,\n  value,\n  defaultValue,\n  onValueChange,\n  layout = 'list',\n  disabled = false,\n  children,\n  ref,\n  ...props\n}: LoneListProps) {\n  const { context, handle, ordered, extras } = useSortList(children, {\n    value,\n    defaultValue,\n    onValueChange,\n    layout,\n    disabled,\n  })\n  const { frame, row } = useFlow<HTMLDivElement, HTMLDivElement>(\n    '[data-slot=sortable-list-item]',\n  )\n  const refs = useMemo(() => mergeRefs(row, ref), [row, ref])\n  return (\n    <SortContext value={context}>\n      <div ref={frame} className={frameClassName}>\n        <ListRoot\n          handle={handle}\n          ref={refs}\n          className={cn(\n            listClassName,\n            layout === 'list' ? 'flex-col' : 'flex-wrap',\n            className,\n          )}\n          {...props}\n        >\n          {({ order }) => ordered(order)}\n        </ListRoot>\n      </div>\n      {extras}\n    </SortContext>\n  )\n}\n\nfunction GroupList({\n  className,\n  id,\n  label,\n  disabled = false,\n  children,\n  ref,\n  ...props\n}: GroupListProps) {\n  const { handle, ordered } = useGroupList(id, children)\n  const { frame, row } = useFlow<HTMLDivElement, HTMLDivElement>(\n    '[data-slot=sortable-group-item]',\n  )\n  const refs = useMemo(() => mergeRefs(row, ref), [row, ref])\n  return (\n    <div ref={frame} className={cn(frameClassName, 'min-w-0')}>\n      <GroupListPart\n        handle={handle}\n        value={id}\n        label={label}\n        disabled={disabled}\n        ref={refs}\n        className={cn(\n          listClassName,\n          // An empty list still has room to drop on.\n          'min-h-(--control-height) flex-col',\n          // A list that won't take the item being moved steps back, where it is its own box.\n          'transition-opacity duration-(--motion-exit-duration) ease-(--motion-exit-easing) data-refused:opacity-50 data-refused:duration-(--motion-enter-duration) data-refused:ease-(--motion-enter-easing)',\n          className,\n        )}\n        {...props}\n      >\n        {({ order }) => ordered(order)}\n      </GroupListPart>\n    </div>\n  )\n}\n\n/**\n * Lists whose items move between them, by pointer or with Left and Right\n * while the keys move one. `value` holds each list's items by its `id`;\n * `onValueChange` gets the new lists, the move named at both ends, and\n * ui-sdk's change details. `accepts` says whether a list takes an item from\n * another: one that doesn't opens no gap, and an item dropped there goes\n * back. Its lists are laid out by `className`, such as columns side by side.\n */\nfunction SortableGroup({\n  className,\n  value,\n  defaultValue,\n  onValueChange,\n  accepts,\n  children,\n  ref,\n  ...props\n}: Omit<PartProps<'div'>, 'defaultValue' | 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  /** Each list's items, in order, by the list's `id`. */\n  value?: Record<string, string[]>\n  defaultValue?: Record<string, string[]>\n  onValueChange?: (\n    value: Record<string, string[]>,\n    move: SortMove,\n    details: SortGroupDetails,\n  ) => void\n  accepts?: SortAccepts\n}) {\n  const { context, handle, root, extras } = useSortGroup({\n    value,\n    defaultValue,\n    onValueChange,\n    accepts,\n  })\n  const refs = useMemo(() => mergeRefs(root, ref), [root, ref])\n  return (\n    <SortContext value={context}>\n      <GroupRoot\n        handle={handle}\n        ref={refs}\n        // Outside every list that takes it, a drop puts it back.\n        className={cn(\n          'flex gap-4 data-outside:cursor-not-allowed data-outside:**:cursor-not-allowed data-sorting:select-none',\n          className,\n        )}\n        {...props}\n      >\n        {({ lists, dragging }) => (\n          <ListsMove lists={lists} dragging={dragging} root={root}>\n            {children}\n          </ListsMove>\n        )}\n      </GroupRoot>\n      {extras}\n    </SortContext>\n  )\n}\n\n/**\n * One item: a row, or a card in a grid. `label` names it to a screen reader\n * as it moves, and names its handle.\n */\nfunction SortableItem({\n  className,\n  value,\n  label,\n  disabled = false,\n  children,\n  ref,\n  ...props\n}: Omit<PartProps<'div'>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n  value: string\n  label: string\n  disabled?: boolean\n}) {\n  const context = useSortContext()\n  const own = useRef<HTMLDivElement>(null)\n  useSettle(context.handle, own, value)\n  const refs = useMemo(() => mergeRefs(own, ref), [ref])\n  const item = useMemo(() => ({ value, label, disabled }), [value, label, disabled])\n  const part = {\n    value,\n    label,\n    disabled,\n    className: cn(\n      'group/sortable-item bg-card text-card-foreground relative z-0 flex min-w-0 cursor-grab items-center gap-(--control-padding) rounded-(--list-radius) border p-(--control-padding) text-sm select-none [-webkit-touch-callout:none] data-disabled:cursor-default',\n      // Where a pointer would drop it: a dashed slot, its content hidden, tinted to read on a muted column too.\n      'data-dragging:bg-foreground/5 data-dragging:border-foreground/20 data-dragging:border-dashed data-dragging:*:invisible',\n      // It glides to a new place on `layout` (`followFlow`), and stays above\n      // its neighbours while it settles there from where it was let go or\n      // from another list, its z-index held for the glide.\n      '[transition:translate_var(--motion-layout-duration)_var(--motion-layout-easing),z-index_0s_var(--motion-layout-duration)] data-[flow=start]:[transition:z-index_0s_var(--motion-layout-duration)] data-moving:z-10 data-moving:[transition:translate_var(--motion-layout-duration)_var(--motion-layout-easing)] data-settling:z-10 data-settling:[transition:translate_var(--motion-layout-duration)_var(--motion-layout-easing)] data-settling:data-[flow=start]:transition-none motion-reduce:transition-none!',\n      // The copy a pointer drags is a clone of the item: it follows the pointer with no transition.\n      'data-drag-preview:transition-none',\n      // Forced colours drop the shadow: the raised item is outlined instead.\n      'forced-colors:data-moving:outline-2 forced-colors:data-moving:outline-[Highlight] forced-colors:data-drag-preview:outline-2 forced-colors:data-drag-preview:outline-[Highlight]',\n      className,\n    ),\n    ...props,\n    children: (\n      <>\n        {children}\n        {/*\n         * Its shadow fades in as it rises, on a layer of its own, so only\n         * opacity moves. The copy a pointer drags is raised from the start,\n         * and the item keeps its shadow as it glides from the copy into its\n         * place, then lets it fade. One that moves to another list without\n         * a hand on it, by a menu or new data, rises the same way while it\n         * glides across, so the eye follows it to where it lands.\n         */}\n        <span\n          aria-hidden\n          className='pointer-events-none absolute -inset-px rounded-[inherit] opacity-0 shadow-md [transition:opacity_var(--motion-exit-duration)_var(--motion-exit-easing)] group-data-moving/sortable-item:opacity-100 group-data-moving/sortable-item:[transition:opacity_var(--motion-enter-duration)_var(--motion-enter-easing)] group-data-[settling=drop]/sortable-item:opacity-100 group-data-[settling=drop]/sortable-item:transition-none group-data-[settling=across]/sortable-item:opacity-100 group-data-[settling=across]/sortable-item:[transition:opacity_var(--motion-enter-duration)_var(--motion-enter-easing)] dark:shadow-black/60 [[data-drag-preview]>&]:opacity-100 [[data-drag-preview]>&]:[transition:opacity_var(--motion-enter-duration)_var(--motion-enter-easing)] [[data-drag-preview]>&]:starting:opacity-0 [[data-holding]>&]:opacity-50 [[data-holding]>&]:[transition:opacity_var(--motion-press-duration)_var(--motion-press-easing)]'\n        />\n      </>\n    ),\n  }\n  return (\n    <SortItemContext value={item}>\n      {context.kind === 'list' ? (\n        <ListItemPart handle={context.handle} ref={refs} {...part} />\n      ) : (\n        <GroupItemPart handle={context.handle} ref={refs} {...part} />\n      )}\n    </SortItemContext>\n  )\n}\n\ntype ListHandle = Extract<ReturnType<typeof useSortContext>, { kind: 'list' }>['handle']\ntype GroupHandle = Extract<ReturnType<typeof useSortContext>, { kind: 'group' }>['handle']\n\n/*\n * The parts, each rendered by ui-sdk's primitive: a ref reaches it as a prop,\n * as a part's element takes it.\n */\nfunction ListRoot({\n  handle,\n  ...props\n}: PartProps<'div', { order: string[]; sorting: boolean }> & { handle: ListHandle }) {\n  return usePart(handle, 'root', {}, props, 'div')\n}\n\nfunction GroupRoot({\n  handle,\n  ...props\n}: PartProps<'div', { lists: Record<string, string[]>; dragging: string | null }> & {\n  handle: GroupHandle\n}) {\n  return usePart(handle, 'root', {}, props, 'div')\n}\n\nfunction GroupListPart({\n  handle,\n  value,\n  label,\n  disabled,\n  ...props\n}: PartProps<'div', { order: string[] }> & {\n  handle: GroupHandle\n  value: string\n  label: string\n  disabled: boolean\n}) {\n  return usePart(handle, 'list', { value, label, disabled }, props, 'div')\n}\n\ntype ItemPartProps = PartProps<'div'> & {\n  value: string\n  label: string\n  disabled: boolean\n}\n\nfunction ListItemPart({\n  handle,\n  value,\n  label,\n  disabled,\n  ...props\n}: ItemPartProps & { handle: ListHandle }) {\n  return usePart(handle, 'item', { value, label, disabled }, props, 'div')\n}\n\nfunction GroupItemPart({\n  handle,\n  value,\n  label,\n  disabled,\n  ...props\n}: ItemPartProps & { handle: GroupHandle }) {\n  return usePart(handle, 'item', { value, label, disabled }, props, 'div')\n}\n\ntype HandlePartProps = PartProps<'button'> & { value: string; disabled: boolean }\n\nfunction ListHandlePart({\n  handle,\n  value,\n  disabled,\n  ...props\n}: HandlePartProps & { handle: ListHandle }) {\n  return usePart(handle, 'handle', { value, disabled }, props, 'button')\n}\n\nfunction GroupHandlePart({\n  handle,\n  value,\n  disabled,\n  ...props\n}: HandlePartProps & { handle: GroupHandle }) {\n  return usePart(handle, 'handle', { value, disabled }, props, 'button')\n}\n\n/** The button that picks its item up: drag it, or press Space and use the arrow keys. */\nfunction SortableHandle({\n  className,\n  children,\n  ...props\n}: Omit<PartProps<'button'>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const context = useSortContext()\n  const item = use(SortItemContext)\n  if (!item) throw new Error('A SortableHandle must be inside a SortableItem.')\n  const part = {\n    'aria-label': `Move ${item.label}`,\n    'aria-describedby': context.instructionsId,\n    className: cn(\n      // Kino's ghost icon button, which picks up as it is dragged.\n      buttonVariants({ variant: 'ghost', size: 'icon-xs' }),\n      \"text-muted-foreground cursor-grab touch-none [&_svg:not([class*='size-'])]:size-4\",\n      // Muted at rest, it darkens while the pointer is on its item, which drags\n      // too, but not on the items a copy passes over; the copy's own is dark.\n      'group-hover/sortable-item:text-foreground in-data-sorting:group-hover/sortable-item:text-muted-foreground [[data-drag-preview]_&]:text-foreground',\n      'aria-pressed:text-foreground aria-pressed:cursor-grabbing forced-colors:aria-pressed:text-[Highlight]',\n      // One item that can't move dims its grip; a list that's turned off has none,\n      // and its handles take no room at all.\n      'disabled:pointer-events-none disabled:opacity-50 [[data-slot=sortable-list][data-disabled]_&]:hidden [[data-slot=sortable-group-list][data-disabled]_&]:hidden',\n      className,\n    ),\n    ...props,\n    children: children ?? (\n      <IconPlaceholder\n        lucide='GripVerticalIcon'\n        tabler='IconGripVertical'\n        hugeicons='DragDropVerticalIcon'\n        phosphor='DotsSixVerticalIcon'\n        remixicon='RiDraggable'\n        aria-hidden\n      />\n    ),\n    value: item.value,\n    disabled: item.disabled,\n  }\n  return context.kind === 'list' ? (\n    <ListHandlePart handle={context.handle} {...part} />\n  ) : (\n    <GroupHandlePart handle={context.handle} {...part} />\n  )\n}\n\nexport { SortableGroup, SortableHandle, SortableItem, SortableList }\nexport type { SortAccepts, SortGroupDetails, SortLayout, SortListDetails, SortMove }\n",
      "type": "registry:component",
      "target": "@components/kino/sortable-list.tsx"
    }
  ],
  "css": {
    "@layer base": {
      ":where([data-slot=sortable-list-item], [data-slot=sortable-group-item]) :where(a[href], button, input, select, textarea, label, summary, [contenteditable], [role=button], [role=link], [role=checkbox], [role=radio], [role=switch], [role=slider], [role=spinbutton], [role=textbox], [role=searchbox], [role=combobox], [role=option], [role=tab], [role=treeitem], [role=menuitem], [role=menuitemcheckbox], [role=menuitemradio], [data-slot=slider-control]):where(:not([data-sortable-handle]))": {
        "cursor": "auto"
      }
    }
  },
  "type": "registry:component"
}