{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-kanban",
  "type": "registry:component",
  "title": "Kanban",
  "description": "Columns of cards a person reorders with a pointer or the arrow keys",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/controllable.ts",
      "target": "@ui/gpuixui/components/internal/controllable.ts",
      "type": "registry:lib",
      "content": "import { useCallback, useState } from \"react\";\n\nexport type ControllableState<Value> = readonly [Value, (next: Value) => void];\n\nexport interface ControllableStateOptions<Value> {\n  readonly value: Value | undefined;\n\n  readonly defaultValue: Value;\n\n  readonly onChange?: (next: Value) => void;\n}\n\nexport const useControllableState = <Value>({\n  value,\n  defaultValue,\n  onChange,\n}: ControllableStateOptions<Value>): ControllableState<Value> => {\n  const [internal, setInternal] = useState(defaultValue);\n  const controlled = value !== undefined;\n\n  const setValue = useCallback(\n    (next: Value) => {\n      if (!controlled) setInternal(next);\n      if (value !== next) onChange?.(next);\n    },\n    [controlled, value, onChange],\n  );\n\n  return [controlled ? value : internal, setValue];\n};\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/kanban.tsx",
      "target": "@ui/gpuixui/components/kanban.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\n// No `@dnd-kit/core`: it reads `document`/`getBoundingClientRect`, which 0.11.0 lacks.\n// Drag is pointer capture plus `renderer.getElementBounds` (`docs/gpuix-capabilities.md`).\nimport type {\n  EventPayload,\n  KeyEvent,\n  NativeRenderer,\n  PublicInstance,\n  StyleDesc,\n} from \"@gpuix/react\";\nimport { useGpuix } from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport { primaryButton } from \"../primitives/core/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport {\n  Fragment,\n  useLayoutEffect,\n  useRef,\n  useState,\n  type ReactNode,\n} from \"react\";\nimport { useControllableState } from \"./internal/controllable.js\";\nimport { keyboardRing, textStyle, useTheme } from \"./internal/theme.js\";\nimport {\n  columnAt,\n  columnCards,\n  directionOf,\n  dropIndexFromCentres,\n  keyboardMove,\n  moveCardInOrder,\n  resolveOrder,\n  type KanbanCard,\n  type KanbanColumn,\n  type KanbanColumnBox,\n  type KanbanDirection,\n  type KanbanMove,\n  type KanbanOrder,\n} from \"./kanban/logic.js\";\n\nexport type {\n  KanbanCard,\n  KanbanColumn,\n  KanbanDirection,\n  KanbanMove,\n  KanbanOrder,\n  KanbanPlacement,\n} from \"./kanban/logic.js\";\n\nexport interface KanbanCardState {\n  readonly dragging: boolean;\n}\n\nexport interface KanbanProps {\n  readonly columns: ReadonlyArray<KanbanColumn>;\n\n  readonly cards: ReadonlyArray<KanbanCard>;\n\n  readonly order?: KanbanOrder;\n\n  readonly defaultOrder?: KanbanOrder;\n\n  readonly onOrderChange?: (order: KanbanOrder) => void;\n\n  readonly onMove?: (move: KanbanMove) => void;\n\n  readonly onCardClick?: (card: KanbanCard) => void;\n\n  readonly label?: string;\n\n  readonly cardLabel?: (card: KanbanCard) => string;\n\n  readonly renderCard?: (card: KanbanCard, state: KanbanCardState) => ReactNode;\n\n  readonly style?: StyleDesc;\n\n  readonly testId?: string;\n}\n\ninterface DropTarget {\n  readonly column: string;\n  readonly index: number;\n}\n\ninterface Drag {\n  readonly id: string;\n  readonly x: number;\n  readonly y: number;\n  moved: boolean;\n}\n\nconst sameDrop = (\n  current: Option.Option<DropTarget>,\n  next: Option.Option<DropTarget>,\n): boolean =>\n  Option.match(current, {\n    onNone: () => Option.isNone(next),\n    onSome: (held) =>\n      Option.exists(\n        next,\n        (target) =>\n          target.column === held.column && target.index === held.index,\n      ),\n  });\n\nconst locatorOf = (\n  base: string | undefined,\n  kind: string,\n  id: string,\n): string | undefined =>\n  base === undefined ? undefined : `${base}-${kind}-${id}`;\n\nconst isPlain = (event: EventPayload): boolean =>\n  event.modifiers?.cmd !== true &&\n  event.modifiers?.ctrl !== true &&\n  event.modifiers?.alt !== true &&\n  event.modifiers?.shift !== true;\n\nconst boundsOf = (\n  renderer: NativeRenderer | null,\n  id: number | undefined,\n): Option.Option<{\n  readonly x: number;\n  readonly y: number;\n  readonly width: number;\n  readonly height: number;\n}> =>\n  id === undefined\n    ? Option.none()\n    : Option.fromNullishOr(renderer?.getElementBounds?.(id));\n\nexport const Kanban = ({\n  columns,\n  cards,\n  order,\n  defaultOrder,\n  onOrderChange,\n  onMove,\n  onCardClick,\n  label,\n  cardLabel,\n  renderCard,\n  style,\n  testId,\n}: KanbanProps) => {\n  const theme = useTheme();\n  const { renderer } = useGpuix();\n  const [stored, setStored] = useControllableState<KanbanOrder>({\n    value: order,\n    defaultValue: resolveOrder(cards, columns, defaultOrder),\n    onChange: onOrderChange,\n  });\n  const placed = resolveOrder(cards, columns, stored);\n  const [dragging, setDragging] = useState<Option.Option<string>>(\n    Option.none(),\n  );\n  const [drop, setDrop] = useState<Option.Option<DropTarget>>(Option.none());\n  const drag = useRef<Option.Option<Drag>>(Option.none());\n  const suppressClick = useRef(false);\n  const pendingFocus = useRef<Option.Option<string>>(Option.none());\n  const columnIds = useRef(new Map<string, number>());\n  const cardIds = useRef(new Map<string, number>());\n\n  useLayoutEffect(() => {\n    Option.match(pendingFocus.current, {\n      onNone: () => undefined,\n      onSome: (id) => {\n        pendingFocus.current = Option.none();\n        Option.match(Option.fromNullishOr(cardIds.current.get(id)), {\n          onNone: () => undefined,\n          onSome: (nativeId) => renderer?.focusElement?.(nativeId),\n        });\n      },\n    });\n  });\n\n  const apply = (move: KanbanMove): void => {\n    const current = Option.getOrElse(\n      Arr.findFirstIndex(\n        columnCards(placed, move.from),\n        (id) => id === move.id,\n      ),\n      () => -1,\n    );\n    if (move.to === move.from && move.index === current) return;\n    pendingFocus.current = Option.some(move.id);\n    setStored(moveCardInOrder(placed, move.id, move.to, move.index));\n    onMove?.(move);\n  };\n\n  const dropAt = (\n    x: number,\n    y: number,\n    id: string,\n  ): Option.Option<DropTarget> => {\n    const boxes: ReadonlyArray<KanbanColumnBox> = Arr.flatMap(\n      columns,\n      (column) =>\n        Option.match(boundsOf(renderer, columnIds.current.get(column.id)), {\n          onNone: () => [],\n          onSome: (box) => [\n            {\n              id: column.id,\n              left: box.x,\n              right: box.x + box.width,\n            },\n          ],\n        }),\n    );\n\n    return Option.map(columnAt(x, boxes), (column) => {\n      const centres = Arr.flatMap(columnCards(placed, column), (card) =>\n        card === id\n          ? []\n          : Option.match(boundsOf(renderer, cardIds.current.get(card)), {\n              onNone: () => [],\n              onSome: (box) => [box.y + box.height / 2],\n            }),\n      );\n      return { column, index: dropIndexFromCentres(centres, y) };\n    });\n  };\n\n  const finishDrag = (event: EventPayload): void => {\n    Option.match(drag.current, {\n      onNone: () => undefined,\n      onSome: (gesture) => {\n        const x = event.x ?? gesture.x;\n        const y = event.y ?? gesture.y;\n        drag.current = Option.none();\n        suppressClick.current = gesture.moved;\n        setDragging(Option.none());\n        setDrop(Option.none());\n        if (!gesture.moved) return;\n        Option.match(dropAt(x, y, gesture.id), {\n          onNone: () => undefined,\n          onSome: (target) =>\n            apply({\n              id: gesture.id,\n              from: Option.getOrElse(\n                Option.map(\n                  Arr.findFirst(placed, (entry) => entry.id === gesture.id),\n                  (entry) => entry.column,\n                ),\n                () => target.column,\n              ),\n              to: target.column,\n              index: target.index,\n            }),\n        });\n      },\n    });\n  };\n\n  const cardSurface = (draggingHere: boolean): StyleDesc => ({\n    display: \"flex\",\n    flexDirection: \"column\",\n    gap: theme.spacing.xs,\n    padding: theme.spacing.lg,\n    borderRadius: theme.radius.lg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: theme.colors.border,\n    backgroundColor: theme.colors.card,\n    color: theme.colors.cardForeground,\n    cursor: draggingHere ? \"grabbing\" : \"grab\",\n    opacity: draggingHere ? 0.45 : 1,\n    ...keyboardRing(theme),\n  });\n\n  const dropLine = (key: string) => (\n    <div\n      key={key}\n      testId={testId === undefined ? undefined : `${testId}-drop-line`}\n      role=\"presentation\"\n      style={{\n        height: 2,\n        borderRadius: theme.radius.sm,\n        backgroundColor: theme.colors.primary,\n      }}\n    />\n  );\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={label ?? \"Kanban board\"}\n      testId={testId}\n      style={mergeStyles(\n        {\n          display: \"flex\",\n          flexDirection: \"row\",\n          alignItems: \"flex-start\",\n          gap: theme.spacing.lg,\n          width: \"100%\",\n          minWidth: 0,\n        },\n        style,\n      )}\n    >\n      {Arr.map(columns, (column) => {\n        const ids = columnCards(placed, column.id);\n        const target = Option.exists(drop, (held) => held.column === column.id);\n        const visible = Arr.filter(\n          ids,\n          (id) => !Option.exists(dragging, (held) => held === id),\n        );\n        const before = Option.flatMap(drop, (held) =>\n          held.column === column.id\n            ? Arr.get(visible, held.index)\n            : Option.none(),\n        );\n\n        return (\n          <div\n            key={column.id}\n            ref={(instance: PublicInstance | null) => {\n              if (instance === null) columnIds.current.delete(column.id);\n              else columnIds.current.set(column.id, instance.id);\n            }}\n            role=\"group\"\n            aria-label={column.title}\n            testId={locatorOf(testId, \"column\", column.id)}\n            style={{\n              display: \"flex\",\n              flexGrow: 1,\n              flexBasis: 0,\n              flexDirection: \"column\",\n              gap: theme.spacing.sm,\n              minWidth: 0,\n            }}\n          >\n            <div\n              style={{\n                display: \"flex\",\n                flexDirection: \"row\",\n                alignItems: \"center\",\n                gap: theme.spacing.xs,\n                paddingLeft: theme.spacing[\"2xs\"],\n                paddingRight: theme.spacing[\"2xs\"],\n              }}\n            >\n              <text\n                style={{\n                  ...textStyle(theme, \"caption\"),\n                  color: theme.colors.mutedForeground,\n                }}\n              >\n                {column.title}\n              </text>\n              <text\n                style={{\n                  ...textStyle(theme, \"caption\"),\n                  color: theme.colors.mutedForeground,\n                }}\n              >\n                {String(Arr.length(ids))}\n              </text>\n            </div>\n            <div\n              style={{\n                display: \"flex\",\n                flexDirection: \"column\",\n                gap: theme.spacing.sm,\n                minHeight: theme.spacing[\"2xs\"],\n              }}\n            >\n              {Arr.map(ids, (id) => {\n                const card = Arr.findFirst(cards, (entry) => entry.id === id);\n                return Option.match(card, {\n                  onNone: () => null,\n                  onSome: (card) => {\n                    const draggingHere = Option.exists(\n                      dragging,\n                      (held) => held === card.id,\n                    );\n                    const lineHere = Option.exists(\n                      before,\n                      (anchor) => anchor === card.id,\n                    );\n                    return (\n                      <Fragment key={card.id}>\n                        {target && lineHere\n                          ? dropLine(`${card.id}-before`)\n                          : null}\n                        <div\n                          ref={(instance: PublicInstance | null) => {\n                            if (instance === null)\n                              cardIds.current.delete(card.id);\n                            else cardIds.current.set(card.id, instance.id);\n                          }}\n                          role=\"button\"\n                          aria-label={cardLabel?.(card) ?? card.title}\n                          aria-description=\"Use the arrow keys to move this card.\"\n                          tabIndex={0}\n                          testId={locatorOf(testId, \"card\", card.id)}\n                          style={cardSurface(draggingHere)}\n                          onMouseDown={(event) => {\n                            if (!primaryButton(event)) return;\n                            suppressClick.current = false;\n                            drag.current = Option.some({\n                              id: card.id,\n                              x: event.x ?? 0,\n                              y: event.y ?? 0,\n                              moved: false,\n                            });\n                            Option.match(\n                              Option.fromNullishOr(\n                                cardIds.current.get(card.id),\n                              ),\n                              {\n                                onNone: () => undefined,\n                                onSome: (id) => renderer?.focusElement?.(id),\n                              },\n                            );\n                            setDragging(Option.some(card.id));\n                          }}\n                          onMouseMove={(event) => {\n                            Option.match(drag.current, {\n                              onNone: () => undefined,\n                              onSome: (gesture) => {\n                                if (event.pressedButton !== 0) {\n                                  drag.current = Option.none();\n                                  setDragging(Option.none());\n                                  setDrop(Option.none());\n                                  return;\n                                }\n                                const x = event.x ?? gesture.x;\n                                const y = event.y ?? gesture.y;\n                                if (\n                                  !gesture.moved &&\n                                  Math.abs(x - gesture.x) < 4 &&\n                                  Math.abs(y - gesture.y) < 4\n                                ) {\n                                  return;\n                                }\n                                gesture.moved = true;\n                                const next = dropAt(x, y, gesture.id);\n                                setDrop((current) =>\n                                  sameDrop(current, next) ? current : next,\n                                );\n                              },\n                            });\n                          }}\n                          onMouseUp={finishDrag}\n                          onClick={() => {\n                            if (suppressClick.current) return;\n                            onCardClick?.(card);\n                          }}\n                          onKeyDown={(event: KeyEvent) => {\n                            Option.match(directionOf(event.key), {\n                              onNone: () => undefined,\n                              onSome: (direction) => {\n                                if (!isPlain(event)) return;\n                                event.preventDefault();\n                                Option.match(\n                                  keyboardMove(\n                                    placed,\n                                    columns,\n                                    card.id,\n                                    direction,\n                                  ),\n                                  {\n                                    onNone: () => undefined,\n                                    onSome: apply,\n                                  },\n                                );\n                              },\n                            });\n                            if (event.key === \"enter\") onCardClick?.(card);\n                            if (event.key === \"space\") event.preventDefault();\n                          }}\n                          onKeyUp={(event: KeyEvent) => {\n                            if (event.key === \"space\") onCardClick?.(card);\n                          }}\n                        >\n                          {renderCard === undefined ? (\n                            <>\n                              <text\n                                style={{\n                                  ...textStyle(theme, \"bodyStrong\"),\n                                  color: theme.colors.cardForeground,\n                                }}\n                              >\n                                {card.title}\n                              </text>\n                              {card.description === undefined ? null : (\n                                <text\n                                  style={{\n                                    ...textStyle(theme, \"caption\"),\n                                    color: theme.colors.mutedForeground,\n                                  }}\n                                >\n                                  {card.description}\n                                </text>\n                              )}\n                            </>\n                          ) : (\n                            renderCard(card, { dragging: draggingHere })\n                          )}\n                        </div>\n                      </Fragment>\n                    );\n                  },\n                });\n              })}\n              {target && Option.isNone(before)\n                ? dropLine(`${column.id}-end`)\n                : null}\n            </div>\n          </div>\n        );\n      })}\n    </div>\n  );\n};\n\nexport const cardsInColumn = columnCards;\n\nexport const kanbanDirectionOf = (\n  key: string | undefined,\n): Option.Option<KanbanDirection> => directionOf(key);\n\nexport const kanbanMeta = {\n  name: \"Kanban\",\n  tier: 2,\n  status: \"done\",\n  gpuixSupport: \"partial\",\n  limitations: [\n    \"No `aria-grabbed` or `aria-dropeffect`: 0.11.0's aria set is closed, so a move is spoken through the card's name and the arrow-key contract\",\n    \"No `document`, `window` or `getBoundingClientRect`: drag is pointer capture plus `renderer.getElementBounds`, which is why `@dnd-kit/core` cannot be used\",\n    \"No live region: a move is not announced; the column counts are painted text\",\n  ],\n  docs: \"docs/kanban.mdx\",\n  example: \"examples/kanban.example.tsx\",\n  testFile: \"src/behaviour/kanban.test.tsx\",\n} as const;\n"
    },
    {
      "path": "packages/components/src/kanban/logic.ts",
      "target": "@ui/gpuixui/components/kanban/logic.ts",
      "type": "registry:lib",
      "content": "// One flat placement list makes a cross-column move and a reorder one splice.\n// A stored order is a start; omitted cards keep their column.\nimport { Match } from \"effect\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\n\nexport interface KanbanColumn {\n  readonly id: string;\n\n  readonly title: string;\n}\n\nexport interface KanbanCard {\n  readonly id: string;\n  readonly column: string;\n  readonly title: string;\n\n  readonly description?: string;\n}\n\nexport interface KanbanPlacement {\n  readonly id: string;\n  readonly column: string;\n}\n\nexport type KanbanOrder = ReadonlyArray<KanbanPlacement>;\n\nexport interface KanbanMove {\n  readonly id: string;\n  readonly from: string;\n  readonly to: string;\n\n  readonly index: number;\n}\n\nexport type KanbanDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\nexport const directionOf = (\n  key: string | undefined,\n): Option.Option<KanbanDirection> =>\n  Match.value(key).pipe(\n    Match.when(\"up\", () => Option.some<KanbanDirection>(\"up\")),\n    Match.when(\"down\", () => Option.some<KanbanDirection>(\"down\")),\n    Match.when(\"left\", () => Option.some<KanbanDirection>(\"left\")),\n    Match.when(\"right\", () => Option.some<KanbanDirection>(\"right\")),\n    Match.orElse(() => Option.none<KanbanDirection>()),\n  );\n\nexport interface KanbanColumnBox {\n  readonly id: string;\n  readonly left: number;\n  readonly right: number;\n}\n\nconst hasColumn = (columns: ReadonlyArray<KanbanColumn>, id: string): boolean =>\n  Arr.some(columns, (column) => column.id === id);\n\nconst firstColumn = (\n  columns: ReadonlyArray<KanbanColumn>,\n): Option.Option<string> =>\n  Option.map(Arr.head(columns), (column) => column.id);\n\nexport const resolveOrder = (\n  cards: ReadonlyArray<KanbanCard>,\n  columns: ReadonlyArray<KanbanColumn>,\n  stored?: KanbanOrder,\n): KanbanOrder => {\n  const fallback = firstColumn(columns);\n  const stated = Arr.reduce(\n    Option.getOrElse(Option.fromNullishOr(stored), () =>\n      Arr.empty<KanbanPlacement>(),\n    ),\n    Arr.empty<KanbanPlacement>(),\n    (accepted, placement) =>\n      Arr.some(accepted, (entry) => entry.id === placement.id) ||\n      !hasColumn(columns, placement.column) ||\n      !Arr.some(cards, (card) => card.id === placement.id)\n        ? accepted\n        : [...accepted, placement],\n  );\n\n  const unplaced = Arr.filter(\n    cards,\n    (card) => !Arr.some(stated, (placement) => placement.id === card.id),\n  );\n\n  return Arr.match(unplaced, {\n    onEmpty: () => stated,\n    onNonEmpty: (cards) =>\n      Arr.reduce(cards, stated, (order, card) => {\n        const column = hasColumn(columns, card.column)\n          ? Option.some(card.column)\n          : fallback;\n        return Option.match(column, {\n          onNone: () => order,\n          onSome: (id) => [...order, { id: card.id, column: id }],\n        });\n      }),\n  });\n};\n\nexport const columnCards = (\n  order: KanbanOrder,\n  column: string,\n): ReadonlyArray<string> =>\n  Arr.flatMap(order, (placement) =>\n    placement.column === column ? [placement.id] : [],\n  );\n\nexport const placementIndex = (\n  order: KanbanOrder,\n  id: string,\n): Option.Option<number> =>\n  Arr.findFirstIndex(order, (entry) => entry.id === id);\n\nexport const moveCardInOrder = (\n  order: KanbanOrder,\n  id: string,\n  to: string,\n  index: number,\n): KanbanOrder =>\n  Option.match(\n    Arr.findFirst(order, (placement) => placement.id === id),\n    {\n      onNone: () => order,\n      onSome: () => {\n        const rest = Arr.filter(order, (placement) => placement.id !== id);\n        const target = Arr.filter(rest, (placement) => placement.column === to);\n        const at = Math.max(0, Math.min(index, Arr.length(target)));\n        const next: KanbanPlacement = { id, column: to };\n        const insertBefore = (first: string): KanbanOrder =>\n          Option.getOrElse(\n            Arr.insertAt(\n              rest,\n              Option.getOrElse(\n                Arr.findFirstIndex(rest, (placement) => placement.id === first),\n                () => Arr.length(rest),\n              ),\n              next,\n            ),\n            () => rest,\n          );\n\n        return Option.match(Arr.get(target, at), {\n          onNone: () =>\n            Option.match(Arr.last(target), {\n              onNone: () => [...rest, next],\n              onSome: (last) => {\n                const after = Option.getOrElse(\n                  Arr.findFirstIndex(\n                    rest,\n                    (placement) => placement.id === last.id,\n                  ),\n                  () => Arr.length(rest) - 1,\n                );\n                return Option.getOrElse(\n                  Arr.insertAt(rest, after + 1, next),\n                  () => [...rest, next],\n                );\n              },\n            }),\n          onSome: (first) => insertBefore(first.id),\n        });\n      },\n    },\n  );\n\nexport const keyboardMove = (\n  order: KanbanOrder,\n  columns: ReadonlyArray<KanbanColumn>,\n  id: string,\n  direction: KanbanDirection,\n): Option.Option<KanbanMove> =>\n  Option.flatMap(\n    Arr.findFirst(order, (placement) => placement.id === id),\n    (placed) =>\n      Option.flatMap(\n        Arr.findFirstIndex(columns, (column) => column.id === placed.column),\n        (columnIndex) => {\n          const cards = columnCards(order, placed.column);\n          const current = Option.getOrElse(\n            Arr.findFirstIndex(cards, (card) => card === id),\n            () => 0,\n          );\n\n          if (direction === \"up\" || direction === \"down\") {\n            const target = current + (direction === \"up\" ? -1 : 1);\n            return target < 0 || target >= Arr.length(cards)\n              ? Option.none()\n              : Option.some({\n                  id,\n                  from: placed.column,\n                  to: placed.column,\n                  index: target,\n                });\n          }\n\n          return Option.map(\n            Arr.get(columns, columnIndex + (direction === \"right\" ? 1 : -1)),\n            (column) => ({\n              id,\n              from: placed.column,\n              to: column.id,\n              index: Math.min(\n                current,\n                Arr.length(columnCards(order, column.id)),\n              ),\n            }),\n          );\n        },\n      ),\n  );\n\nexport const dropIndexFromCentres = (\n  centres: ReadonlyArray<number>,\n  y: number,\n): number => Arr.length(Arr.filter(centres, (centre) => y > centre));\n\nexport const columnAt = (\n  x: number,\n  boxes: ReadonlyArray<KanbanColumnBox>,\n): Option.Option<string> =>\n  Option.orElse(\n    Option.map(\n      Arr.findFirst(boxes, (box) => x >= box.left && x <= box.right),\n      (box) => box.id,\n    ),\n    () =>\n      Option.map(\n        Arr.reduce(\n          boxes,\n          Option.none<{\n            readonly box: KanbanColumnBox;\n            readonly away: number;\n          }>(),\n          (nearest, box) => {\n            const away = x < box.left ? box.left - x : x - box.right;\n            return Option.match(nearest, {\n              onNone: () => Option.some({ box, away }),\n              onSome: (held) =>\n                away < held.away ? Option.some({ box, away }) : nearest,\n            });\n          },\n        ),\n        (nearest) => nearest.box.id,\n      ),\n  );\n"
    }
  ],
  "docs": "[Kanban](https://gpuixui.sudokw.com/components/kanban) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/kanban",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}