{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "selection-slot",
  "type": "registry:ui",
  "title": "Selection Slot",
  "description": "Swaps a toolbar for a selection toolbar in place.",
  "categories": [
    "layout"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/selection-slot.tsx",
      "type": "registry:ui",
      "target": "components/ui/selection-slot.tsx",
      "content": "'use client';\n\nimport { useLayoutEffect, useRef, type ComponentProps, type ReactNode } from 'react';\nimport { cn } from '@/lib/sprout/classes';\n\nexport interface SelectionSlotProps extends Omit<ComponentProps<'div'>, 'children'> {\n  active: boolean;\n  selection: ReactNode;\n  children: ReactNode;\n}\n\nconst tabbable =\n  'a[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]), [contenteditable=\"true\"]';\n\nfunction focusable(root: HTMLElement | null) {\n  return Array.from(root?.querySelectorAll<HTMLElement>(tabbable) ?? []).find(\n    node => !node.closest('[inert]') && node.getClientRects().length > 0,\n  );\n}\n\nfunction lost() {\n  const current = document.activeElement;\n  return !current || current === document.body;\n}\n\nexport function SelectionSlot({ active, selection, children, className, ...props }: SelectionSlotProps) {\n  const tools = useRef<HTMLDivElement>(null);\n  const selected = useRef<HTMLDivElement>(null);\n  const origin = useRef<HTMLElement | null>(null);\n  const previous = useRef(false);\n  const inside = useRef(false);\n  useLayoutEffect(() => {\n    if (active && !previous.current) {\n      const current = document.activeElement;\n      origin.current = current instanceof HTMLElement && current !== document.body ? current : null;\n      if (origin.current && tools.current?.contains(origin.current))\n        focusable(selected.current)?.focus({ preventScroll: true });\n    }\n    if (!active && previous.current && lost()) {\n      if (origin.current?.isConnected) origin.current.focus({ preventScroll: true });\n      else if (inside.current) focusable(tools.current)?.focus({ preventScroll: true });\n    }\n    if (!active) inside.current = false;\n    previous.current = active;\n  }, [active]);\n  return (\n    <div\n      data-slot=\"selection-slot\"\n      data-active={active || undefined}\n      className={cn('sprout-selection-slot', className)}\n      {...props}\n    >\n      <div\n        ref={tools}\n        data-slot=\"selection-slot-default\"\n        className=\"sprout-selection-slot-layer\"\n        inert={active}\n        aria-hidden={active || undefined}\n      >\n        {children}\n      </div>\n      {active && (\n        <div\n          ref={selected}\n          onFocus={() => (inside.current = true)}\n          onBlur={event => {\n            const next = event.relatedTarget;\n            if (next && !event.currentTarget.contains(next)) inside.current = false;\n          }}\n          data-slot=\"selection-slot-selection\"\n          className=\"sprout-selection-slot-layer sprout-selection-slot-selection\"\n        >\n          {selection}\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "css": {
    "@layer components": {
      ".sprout-selection-slot": {
        "grid-template-columns": "minmax(0, 1fr)",
        "align-items": "center",
        "min-width": "0",
        "display": "grid",
        "container": "sprout-selection / inline-size"
      },
      ".sprout-selection-slot-layer": {
        "grid-area": "1 / 1",
        "min-width": "0"
      },
      ".sprout-selection-slot-layer[inert]": {
        "visibility": "hidden"
      },
      "@media (prefers-reduced-motion: no-preference)": {
        ".sprout-selection-slot-selection": {
          "animation": "sprout-selection-slot-in var(--sprout-motion-normal) var(--sprout-motion-ease)"
        }
      },
      "@keyframes sprout-selection-slot-in": {
        "from": {
          "opacity": "0",
          "transform": "translateY(2px)"
        }
      }
    }
  },
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/selection-slot/",
  "meta": {
    "source": "packages/sprout/src/components/selection-slot.tsx"
  }
}
