{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "source-field-link",
  "title": "Source field link",
  "description": "A field-path adapter over segmented-document anchors.",
  "registryDependencies": [
    "@retab/segmented-document"
  ],
  "files": [
    {
      "path": "registry/new-york-v4/ui/source-field-link.ts",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport type {\n  DocumentSegment,\n  SegmentAnchor,\n} from \"./segmented-document-model\";\nimport { useSegmentedItemLink } from \"./segmented-item-link\";\n\nexport type SourceFieldLink = {\n  activeSourcePath: string | null;\n  onSourceHover: (path: string | null) => void;\n  selectSourcePath?: (path: string) => void;\n};\n\nexport type SegmentedSourceFieldLink = SourceFieldLink & {\n  activeAnchor: SegmentAnchor | null;\n  activeAnchors: readonly SegmentAnchor[];\n  activeSegment: DocumentSegment | null;\n  selectedSourcePath: string | null;\n};\n\nexport type SegmentedSourceFieldLinkOptions = {\n  initialSourcePath?: string | null;\n};\n\nexport function useSegmentedSourceFieldLink(\n  options: SegmentedSourceFieldLinkOptions = {},\n): SegmentedSourceFieldLink {\n  const link = useSegmentedItemLink({\n    initialItemId: options.initialSourcePath,\n  });\n\n  const onSourceHover = React.useCallback(\n    (path: string | null) => {\n      if (!path) {\n        link.previewItem(null);\n        return;\n      }\n\n      link.previewItem(path);\n    },\n    [link],\n  );\n\n  const selectSourcePath = React.useCallback(\n    (path: string) => {\n      link.selectItem(path);\n      link.navigateItem(path, { behavior: \"smooth\", clearPreview: false });\n    },\n    [link],\n  );\n\n  return React.useMemo(\n    () => ({\n      activeAnchor: link.activeAnchor,\n      activeAnchors: link.activeAnchors,\n      activeSourcePath: link.activeItemId,\n      activeSegment: link.activeSegment,\n      onSourceHover,\n      selectSourcePath,\n      selectedSourcePath: link.selectedItemId,\n    }),\n    [\n      link.activeAnchor,\n      link.activeAnchors,\n      link.activeItemId,\n      link.activeSegment,\n      link.selectedItemId,\n      onSourceHover,\n      selectSourcePath,\n    ],\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/source-field-link.ts"
    }
  ],
  "type": "registry:ui"
}