@kumix/ui 0.3.8 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -15
- package/dist/components/agents/ai-sidebar.js +3 -5
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +15 -7
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +1 -1
- package/dist/components/motion/button/index.d.ts +2 -1
- package/dist/components/motion/button/index.js +2 -1
- package/dist/components/motion/button/metallic.d.ts +10 -0
- package/dist/components/motion/button/metallic.d.ts.map +1 -0
- package/dist/components/motion/button/metallic.js +71 -0
- package/dist/components/motion/button/metallic.js.map +1 -0
- package/dist/components/motion/combobox/content.js +1 -1
- package/dist/components/motion/combobox/context.d.ts +6 -0
- package/dist/components/motion/combobox/context.d.ts.map +1 -1
- package/dist/components/motion/combobox/context.js +1 -233
- package/dist/components/motion/combobox/list.js +1 -1
- package/dist/components/motion/combobox/trigger.js +7 -8
- package/dist/components/motion/combobox/trigger.js.map +1 -1
- package/dist/components/motion/combobox.js +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +21 -26
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/expandable-control.d.ts +28 -0
- package/dist/components/motion/expandable-control.d.ts.map +1 -0
- package/dist/components/motion/expandable-control.js +149 -0
- package/dist/components/motion/expandable-control.js.map +1 -0
- package/dist/components/motion/expanding-arrow-button.d.ts +12 -0
- package/dist/components/motion/expanding-arrow-button.d.ts.map +1 -0
- package/dist/components/motion/expanding-arrow-button.js +142 -0
- package/dist/components/motion/expanding-arrow-button.js.map +1 -0
- package/dist/components/motion/file-tree.d.ts +42 -0
- package/dist/components/motion/file-tree.d.ts.map +1 -0
- package/dist/components/motion/file-tree.js +272 -0
- package/dist/components/motion/file-tree.js.map +1 -0
- package/dist/components/motion/morphing-search.d.ts.map +1 -1
- package/dist/components/motion/morphing-search.js +27 -23
- package/dist/components/motion/morphing-search.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/code-block/code-block-highlight.d.ts +216 -0
- package/dist/components/reui/code-block/code-block-highlight.d.ts.map +1 -0
- package/dist/components/reui/code-block/code-block-highlight.js +792 -0
- package/dist/components/reui/code-block/code-block-highlight.js.map +1 -0
- package/dist/components/reui/code-block/code-block.d.ts +197 -0
- package/dist/components/reui/code-block/code-block.d.ts.map +1 -0
- package/dist/components/reui/code-block/code-block.js +1150 -0
- package/dist/components/reui/code-block/code-block.js.map +1 -0
- package/dist/components/reui/filters/filters-builder.js +1 -1
- package/dist/components/reui/filters/filters-chip.js.map +1 -1
- package/dist/components/reui/filters/filters-editors.js +2 -2
- package/dist/components/reui/filters/filters-editors.js.map +1 -1
- package/dist/components/reui/gantt/gantt-bar.js +42 -12
- package/dist/components/reui/gantt/gantt-bar.js.map +1 -1
- package/dist/components/reui/gantt/gantt-dnd.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-dnd.js +22 -7
- package/dist/components/reui/gantt/gantt-dnd.js.map +1 -1
- package/dist/components/reui/gantt/gantt-i18n.d.ts +8 -0
- package/dist/components/reui/gantt/gantt-i18n.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-i18n.js +6 -1
- package/dist/components/reui/gantt/gantt-i18n.js.map +1 -1
- package/dist/components/reui/gantt/gantt-lib.d.ts +59 -2
- package/dist/components/reui/gantt/gantt-lib.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-lib.js +67 -2
- package/dist/components/reui/gantt/gantt-lib.js.map +1 -1
- package/dist/components/reui/gantt/gantt-recurrence.js +3 -3
- package/dist/components/reui/gantt/gantt-recurrence.js.map +1 -1
- package/dist/components/reui/gantt/gantt-types.d.ts +32 -1
- package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt-view.js +324 -35
- package/dist/components/reui/gantt/gantt-view.js.map +1 -1
- package/dist/components/reui/gantt/gantt.d.ts +71 -2
- package/dist/components/reui/gantt/gantt.d.ts.map +1 -1
- package/dist/components/reui/gantt/gantt.js +8 -0
- package/dist/components/reui/gantt/gantt.js.map +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/context-BizvUNZv.js +298 -0
- package/dist/context-BizvUNZv.js.map +1 -0
- package/dist/{copy-menu-1FKoMc9o.js → copy-menu-C5GaT4Z-.js} +67 -2
- package/dist/copy-menu-C5GaT4Z-.js.map +1 -0
- package/dist/hooks/use-on-open.d.ts +18 -0
- package/dist/hooks/use-on-open.d.ts.map +1 -0
- package/dist/hooks/use-on-open.js +27 -0
- package/dist/hooks/use-on-open.js.map +1 -0
- package/dist/hooks/use-row-cursor.d.ts +39 -0
- package/dist/hooks/use-row-cursor.d.ts.map +1 -0
- package/dist/hooks/use-row-cursor.js +77 -0
- package/dist/hooks/use-row-cursor.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +7 -13
- package/dist/components/motion/combobox/context.js.map +0 -1
- package/dist/copy-menu-1FKoMc9o.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block.js","names":[],"sources":["../../../../src/components/reui/code-block/code-block.tsx"],"sourcesContent":["/** biome-ignore-all assist/source/organizeImports: <> */\n\n\"use client\";\n\nimport {\n Children,\n createContext,\n isValidElement,\n memo,\n useCallback,\n useContext,\n useDeferredValue,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport type {\n ComponentProps,\n CSSProperties,\n KeyboardEvent as ReactKeyboardEvent,\n ReactNode,\n} from \"react\";\nimport {\n highlightCode,\n markdownCodeProps,\n markdownFences,\n resolveCodeBlockLanguage,\n stripNotationComments,\n toPlainLines,\n} from \"./code-block-highlight\";\nimport type {\n CodeBlockDiffSpec,\n CodeBlockLevelSpec,\n CodeBlockLine,\n CodeBlockLineActionsRender,\n CodeBlockLineSpec,\n CodeBlockThemes,\n CodeBlockToken,\n CodeBlockTransformer,\n CodeBlockWordSpec,\n} from \"./code-block-highlight\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\n\n/* -------------------------------------------------------------------------- */\n/* Context */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Two contexts: the document changes on every streamed chunk, the config does\n * not. Splitting them keeps a stream from re-rendering the chrome per chunk.\n */\ntype CodeBlockConfigValue = {\n language?: string;\n resolvedLanguage?: string;\n showLineNumbers: boolean;\n wrap: boolean;\n setWrap: (wrap: boolean) => void;\n wrapControlled: boolean;\n expanded: boolean;\n setExpanded: (expanded: boolean) => void;\n collapsible: boolean;\n streaming: boolean;\n contentId: string;\n};\n\ntype CodeBlockDocumentValue = {\n code: string;\n lines: CodeBlockLine[];\n selected: Set<number>;\n selectable: boolean;\n toggleLine: (line: number, extend: boolean) => void;\n clearSelection: () => void;\n foldable: boolean;\n foldRegions: CodeBlockFoldRegion[];\n folded: Set<number>;\n toggleFold: (start: number) => void;\n setFolded: (folded: number[]) => void;\n};\n\nconst CodeBlockConfigContext = createContext<CodeBlockConfigValue | null>(null);\nconst CodeBlockDocumentContext = createContext<CodeBlockDocumentValue | null>(null);\n\n/** Lets the copy button tell a header placement from a floating one. */\nconst CodeBlockHeaderContext = createContext(false);\n\n/**\n * The root prepares every prop the code surface needs and publishes the\n * bundle here. `CodeBlockContent` reads it to render the surface wherever the\n * consumer composed it - typically inside their own ScrollArea - and the root\n * renders its built-in scrolling surface only when no `CodeBlockContent` is\n * found among its children.\n */\nconst CodeBlockSurfacePropsContext = createContext<CodeBlockSurfaceProps | null>(null);\n\n/**\n * `CodeBlockLineActions` renders nothing itself: it registers its render prop\n * here and the ACTIVE ROW renders it, so actions stay aligned when soft wrap\n * gives lines different heights.\n */\nexport type CodeBlockLineActionsSide = \"end\" | \"gutter\";\n\nconst CodeBlockActionsContext = createContext<{\n register: (\n owner: object,\n render: CodeBlockLineActionsRender | null,\n side?: CodeBlockLineActionsSide,\n ) => void;\n} | null>(null);\n\n/* Next still server-renders \"use client\" files, and a bare useLayoutEffect\n logs on every SSR pass. Same alias the event calendar ships. */\nconst useIsoLayoutEffect = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\nfunction useInternalConfig(part: string): CodeBlockConfigValue {\n const context = useContext(CodeBlockConfigContext);\n if (!context) {\n throw new Error(`${part} must be used within a CodeBlock`);\n }\n return context;\n}\n\nfunction useCodeBlockConfig(part: string): CodeBlockConfigValue & { code: string } {\n const context = useContext(CodeBlockConfigContext);\n const document = useContext(CodeBlockDocumentContext);\n if (!context || !document) {\n throw new Error(`${part} must be used within a CodeBlock`);\n }\n /* `code` lives on the DOCUMENT context (it changes per streamed chunk);\n keeping it out of the config is what lets chrome that ignores the source\n skip those re-renders. The public hook still returns it. */\n return useMemo(() => ({ ...context, code: document.code }), [context, document.code]);\n}\n\n/* -------------------------------------------------------------------------- */\n/* Styling */\n/* -------------------------------------------------------------------------- */\n\n/* Radius per style. Every style is named, including the zero rungs: a missing\n rung is a style someone forgot. The parity suite enforces all-eight-or-one. */\nconst ROOT_GHOST_CLASS = \"[--code-block-bg:transparent]\";\n\nconst ROOT_RADIUS_CLASS = \"[--code-block-radius:var(--radius-lg)]\";\n\n/*\n * Colour vars use the BASE theme tokens (--card, --primary, ...), never the\n * --color-* twins: those are static @theme literals that ignore a nested\n * `.dark` scope, which once painted a white gutter cell on a forced-dark\n * block. Tints are one system, 8% light / 12% dark (yellow a touch more),\n * matching the *-light badge weights. This item ships the same cssVars.\n */\nconst ROOT_TOKEN_CLASS = [\n \"[--code-block-padding:--spacing(3)]\",\n \"[--code-block-gutter-width:--spacing(9)]\",\n \"[--code-block-gutter-gap:--spacing(2.5)]\",\n /* The fold channel sits between the numbers and the code, so both the number\n cell's padding and the gutter width are expressed against it and a block\n without folding pays nothing for it. */\n \"[--code-block-fold-width:--spacing(4.5)]\",\n \"[--code-block-number-pad:var(--code-block-gutter-gap)]\",\n \"data-[gutter-channel]:[--code-block-number-pad:calc(var(--code-block-gutter-gap)+var(--code-block-fold-width))]\",\n /* A diff column breathes: the +/- glyph gets a wider channel. */\n \"data-[has-diff]:[--code-block-gutter-gap:--spacing(4)]\",\n \"[--code-block-line-height:1.5rem]\",\n \"[--code-block-font-size:0.8125rem]\",\n \"[--code-block-copy-inset:--spacing(2)]\",\n /* Where a PINNED control starts. With a header composed in, the root's top\n edge is the header, so an unadjusted inset drops the copy button onto the\n title row instead of the code. The header's own `min-h-9` is the height\n assumed here, plus its 1px bottom border; override the variable for a\n header built taller than one row. */\n \"[--code-block-header-height:--spacing(9)]\",\n \"[--code-block-copy-top:var(--code-block-copy-inset)]\",\n \"data-[has-header]:[--code-block-copy-top:calc(var(--code-block-header-height)+1px+var(--code-block-copy-inset))]\",\n /* Room the expanded block keeps under the last line for the floating\n \"Show less\" control. */\n \"[--code-block-expand-clearance:--spacing(9)]\",\n /* What sits behind a sticky line number while the code scrolls under it.\n `ghost` blanks it, because there the surface belongs to the wrapper. */\n \"[--code-block-bg:var(--card)]\",\n \"[--code-block-highlight-bg:color-mix(in_oklch,var(--primary)_6%,transparent)]\",\n \"dark:[--code-block-highlight-bg:color-mix(in_oklch,var(--primary)_12%,transparent)]\",\n \"[--code-block-highlight-bar:color-mix(in_oklch,var(--primary)_60%,transparent)]\",\n \"[--code-block-diff-add-bg:color-mix(in_oklch,var(--success)_8%,transparent)]\",\n \"dark:[--code-block-diff-add-bg:color-mix(in_oklch,var(--success)_12%,transparent)]\",\n \"[--code-block-diff-remove-bg:color-mix(in_oklch,var(--destructive)_8%,transparent)]\",\n \"dark:[--code-block-diff-remove-bg:color-mix(in_oklch,var(--destructive)_12%,transparent)]\",\n \"[--code-block-error-bg:color-mix(in_oklch,var(--destructive)_8%,transparent)]\",\n \"dark:[--code-block-error-bg:color-mix(in_oklch,var(--destructive)_12%,transparent)]\",\n \"[--code-block-warning-bg:color-mix(in_oklch,var(--warning)_10%,transparent)]\",\n \"dark:[--code-block-warning-bg:color-mix(in_oklch,var(--warning)_14%,transparent)]\",\n \"[--code-block-info-bg:color-mix(in_oklch,var(--info)_8%,transparent)]\",\n \"dark:[--code-block-info-bg:color-mix(in_oklch,var(--info)_12%,transparent)]\",\n \"[--code-block-caret-color:var(--primary)]\",\n].join(\" \");\n\nconst ROOT_BASE_CLASS =\n \"group/code-block relative flex min-w-0 flex-col rounded-(--code-block-radius) text-left\";\n\nconst ROOT_SURFACE_CLASS = \"border border-border bg-card text-card-foreground bg-clip-padding\";\n\n/**\n * The token colour switch: tokens carry only `--cb-c` / `--cb-cd`, and these\n * two rules recolour the whole block per theme instead of a `dark:` utility on\n * every span. The `color:` hint is load-bearing: `text-[var(--x)]` is\n * type-ambiguous to Tailwind and emits NO rule at all, which renders as a\n * highlighter that silently failed. Same reason the font size uses `length:`.\n */\nconst TOKEN_COLOR_CLASS =\n \"[&_[data-slot=code-block-token]]:text-[color:var(--cb-c,currentColor)] dark:[&_[data-slot=code-block-token]]:text-[color:var(--cb-cd,currentColor)]\";\n\n/**\n * Line numbers are a CSS counter, never DOM: a pseudo-element cannot join a\n * text selection, so copying yields exact source, and the gutter costs zero\n * elements. `startLine` is a counter reset on the pre.\n */\nconst LINE_NUMBER_CLASS = [\n \"[[data-code-line-numbers]_&]:before:pointer-events-none\",\n \"[[data-code-line-numbers]_&]:before:sticky\",\n \"[[data-code-line-numbers]_&]:before:left-0\",\n \"[[data-code-line-numbers]_&]:before:z-10\",\n \"[[data-code-line-numbers]_&]:before:-ml-(--code-block-gutter-width)\",\n \"[[data-code-line-numbers]_&]:before:inline-block\",\n \"[[data-code-line-numbers]_&]:before:w-(--code-block-gutter-width)\",\n \"[[data-code-line-numbers]_&]:before:pl-(--code-block-padding)\",\n \"[[data-code-line-numbers]_&]:before:pr-(--code-block-number-pad)\",\n \"[[data-code-line-numbers]_&]:before:bg-(--code-block-bg)\",\n \"[[data-code-line-numbers]_&]:before:text-right\",\n \"[[data-code-line-numbers]_&]:before:tabular-nums\",\n \"[[data-code-line-numbers]_&]:before:text-muted-foreground/50\",\n \"[[data-code-line-numbers]_&]:before:select-none\",\n \"[[data-code-line-numbers]_&]:before:[counter-increment:cb-line]\",\n \"[[data-code-line-numbers]_&]:before:content-[counter(cb-line)]\",\n /* A line carrying its own gutter label (a patch's dual numbers, a hunk\n marker) renders that instead of the counter. */\n \"[[data-code-line-numbers]_&[data-gutter]]:before:content-[attr(data-gutter)]\",\n \"[[data-code-line-numbers]_&[data-gutter]]:before:whitespace-pre\",\n].join(\" \");\n\n/** Diff glyphs ride in the same pseudo-element family, so they never copy. */\n/**\n * The diff glyph gets its own channel, centred in the left padding (no\n * numbers) or in the number-to-code gap. A fixed `left-1` had ~1px of\n * clearance and would land on the first character.\n */\nconst LINE_DIFF_CLASS = [\n \"data-[diff]:after:absolute\",\n /* Above the number cell. That cell is sticky with an opaque backdrop at z-10,\n so a glyph sharing its column is painted out at the default z. */\n \"data-[diff]:after:z-20\",\n \"data-[diff]:after:left-0\",\n \"data-[diff]:after:w-(--code-block-padding)\",\n \"data-[diff]:after:text-center\",\n \"[[data-code-line-numbers]_&]:data-[diff]:after:-left-(--code-block-gutter-gap)\",\n \"[[data-code-line-numbers]_&]:data-[diff]:after:w-(--code-block-gutter-gap)\",\n \"data-[diff]:after:select-none\",\n \"data-[diff=add]:after:text-success\",\n \"data-[diff=remove]:after:text-destructive\",\n \"data-[diff=add]:after:content-['+']\",\n \"data-[diff=remove]:after:content-['-']\",\n].join(\" \");\n\nconst LINE_STATE_CLASS = [\n \"data-[highlighted]:bg-(--code-block-highlight-bg)\",\n \"data-[highlighted]:shadow-[inset_2px_0_0_0_var(--code-block-highlight-bar)]\",\n \"data-[diff=add]:bg-(--code-block-diff-add-bg)\",\n \"data-[diff=remove]:bg-(--code-block-diff-remove-bg)\",\n \"data-[level=error]:bg-(--code-block-error-bg)\",\n \"data-[level=warning]:bg-(--code-block-warning-bg)\",\n \"data-[level=info]:bg-(--code-block-info-bg)\",\n \"data-[selected]:bg-accent\",\n /* Arrow navigation needs a visible position (WCAG 2.4.7); gated on the\n selectable listbox so plain blocks stay inert on hover. */\n \"[[data-selectable]_&]:data-[active]:bg-muted/40\",\n].join(\" \");\n\n/**\n * Focus mode dims the rest and clears on hover.\n *\n * Blur alone makes a snippet unreadable if the reader wanted the surrounding\n * context after all, so hovering the block restores everything.\n */\n/**\n * Motion is streaming-only and compositor-only: rows keep identity across\n * chunks, so the entry animation fires once per NEW line and a static block\n * never animates. Tokens deliberately do not animate (the plain tail gaining\n * colour remounts them mid-read). Reduced motion disables the row entry.\n */\nconst LINE_MOTION_CLASS =\n \"[[data-streaming]_&]:animate-in [[data-streaming]_&]:fade-in-0 [[data-streaming]_&]:slide-in-from-bottom-1 [[data-streaming]_&]:duration-150 [[data-streaming]_&]:ease-out motion-reduce:animate-none\";\n\n/**\n * Deliberately no per-token animation. The highlighter runs a chunk behind\n * the stream and REPLACES the plain-text fallback lines with tokenised ones,\n * which remounts every token span; a mount-keyed fade therefore re-flashed\n * whole lines that were already readable, 300ms behind the caret. Colour\n * arriving instantly reads as highlighting; re-fading reads as a glitch.\n */\nconst TOKEN_MOTION_CLASS = \"\";\n\nconst LINE_FOCUS_CLASS =\n \"data-[blurred]:opacity-40 data-[blurred]:blur-[1.5px] data-[blurred]:transition-[opacity,filter] group-hover/code-block:data-[blurred]:opacity-100 group-hover/code-block:data-[blurred]:blur-none\";\n\n/**\n * `data-code-line`, not `data-line`: rehype-pretty-code apps ship a global\n * `[data-line] span { color !important }` rule, and reusing its attribute\n * rendered every token monochrome. Cost a real investigation.\n */\nconst LINE_BASE_CLASS = cn(\n \"relative block min-h-(--code-block-line-height) w-full px-(--code-block-padding) leading-(--code-block-line-height)\",\n /* With numbers on, the left inset lives inside the sticky cell instead, so\n paying it here too would restore the double count the gutter just lost. */\n \"[[data-code-line-numbers]_&]:pl-0\",\n);\n\n/* -------------------------------------------------------------------------- */\n/* Folding */\n/* -------------------------------------------------------------------------- */\n\nexport type CodeBlockFoldRegion = {\n /** Source line that owns the toggle and stays visible when folded. */\n start: number;\n /** Last source line the region swallows. */\n end: number;\n};\n\nconst INDENT_RE = /^[ \\t]*/;\n\n/**\n * Regions come from indentation, not the grammar: shiki returns tokens, no\n * AST, and indentation is language-agnostic where a brace matcher is not.\n * A tab counts as two columns; only self-consistency matters.\n */\nfunction computeFoldRegions(lines: CodeBlockLine[]): CodeBlockFoldRegion[] {\n const indent = (text: string) => (INDENT_RE.exec(text)?.[0] ?? \"\").replace(/\\t/g, \" \").length;\n const blank = (text: string) => text.trim().length === 0;\n\n /* One pass with an open-region stack instead of a nested scan per line:\n the old shape was quadratic on monotonically indenting files and re-ran\n per streamed chunk. A region closes when a non-blank line returns to its\n opener's indent; trailing blanks belong to whatever follows. */\n const regions: CodeBlockFoldRegion[] = [];\n const stack: { start: number; indent: number; last: number }[] = [];\n let previous: { number: number; indent: number } | null = null;\n\n for (const line of lines) {\n if (blank(line.text)) continue;\n const own = indent(line.text);\n\n while (stack.length && own <= stack[stack.length - 1].indent) {\n const open = stack.pop()!;\n if (open.last > open.start) {\n regions.push({ start: open.start, end: open.last });\n }\n }\n for (const open of stack) open.last = line.number;\n\n if (previous && own > previous.indent) {\n stack.push({\n start: previous.number,\n indent: previous.indent,\n last: line.number,\n });\n }\n previous = { number: line.number, indent: own };\n }\n\n while (stack.length) {\n const open = stack.pop()!;\n if (open.last > open.start) regions.push({ start: open.start, end: open.last });\n }\n\n return regions.sort((a, b) => a.start - b.start);\n}\n\n/** Frozen so the disabled path keeps a stable identity across renders. */\nconst EMPTY_FOLD_REGIONS: CodeBlockFoldRegion[] = [];\n\n/* -------------------------------------------------------------------------- */\n/* Tokens */\n/* -------------------------------------------------------------------------- */\n\ntype TokenStyle = CSSProperties & Record<\"--cb-c\" | \"--cb-cd\", string>;\n\nfunction tokenStyle(token: CodeBlockToken): CSSProperties | undefined {\n if (!token.color && !token.colorDark && !token.fontStyle) return undefined;\n\n const style: Partial<TokenStyle> = {};\n if (token.color) style[\"--cb-c\"] = token.color;\n if (token.colorDark) style[\"--cb-cd\"] = token.colorDark;\n if (token.fontStyle === \"italic\") style.fontStyle = \"italic\";\n if (token.fontStyle === \"bold\") style.fontWeight = 700;\n if (token.fontStyle === \"underline\") style.textDecoration = \"underline\";\n return style as CSSProperties;\n}\n\nfunction CodeBlockTokens({ tokens }: { tokens: CodeBlockToken[] }) {\n return (\n <>\n {tokens.map((token, index) => {\n const style = tokenStyle(token);\n\n /* An unstyled token needs no element at all. Whitespace and\n punctuation are most of a file, so this removes most of the spans. */\n if (!style && !token.word) {\n return <span key={index}>{token.content}</span>;\n }\n\n return (\n <span\n key={index}\n data-slot=\"code-block-token\"\n data-word={token.word || undefined}\n className={cn(\n token.word &&\n \"rounded-sm bg-primary/10 px-0.5 py-px ring-1 ring-primary/20 ring-inset\",\n )}\n style={style}\n >\n {token.content}\n </span>\n );\n })}\n </>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Line */\n/* -------------------------------------------------------------------------- */\n\ntype CodeBlockLineRowProps = {\n line: CodeBlockLine;\n selectable: boolean;\n selected: boolean;\n focusMode: boolean;\n active: boolean;\n caret: boolean;\n actions?: CodeBlockLineActionsRender | null;\n actionsSide?: CodeBlockLineActionsSide;\n domIdBase?: string;\n startLine?: number;\n onSelect?: (line: number, extend: boolean) => void;\n foldable?: boolean;\n foldRegion?: CodeBlockFoldRegion;\n folded?: boolean;\n onToggleFold?: (start: number) => void;\n};\n\n/**\n * Plain reference-equality `memo`, on purpose: the highlighter returns the\n * SAME object for an unchanged line, so a streamed chunk re-renders one row.\n * A custom comparator would spend that win walking every token.\n */\nconst CodeBlockLineRow = memo(function CodeBlockLineRow({\n line,\n selectable,\n selected,\n focusMode,\n active,\n caret,\n actions,\n actionsSide = \"end\",\n domIdBase,\n startLine = 1,\n onSelect,\n foldRegion,\n folded,\n onToggleFold,\n}: CodeBlockLineRowProps) {\n const state = line.state;\n const blurred = focusMode && !state?.focused;\n const lineDomId = domIdBase ? `${domIdBase}-L${line.number}` : undefined;\n const hiddenCount = foldRegion ? foldRegion.end - foldRegion.start : 0;\n /* The fold toggle owns the channel, so a fold-start row keeps its chevron\n and sends the action back to the row end. */\n const inGutter = actionsSide === \"gutter\" && !foldRegion;\n\n return (\n // biome-ignore lint/a11y/useKeyWithClickEvents: <>\n <span\n data-slot=\"code-block-line\"\n data-code-line={line.number}\n data-gutter={line.gutter}\n id={lineDomId}\n data-active={active || undefined}\n data-highlighted={state?.highlighted || undefined}\n data-diff={state?.diff}\n data-focused={state?.focused || undefined}\n data-blurred={blurred || undefined}\n data-level={state?.level}\n data-selected={selected || undefined}\n role={selectable ? \"option\" : undefined}\n aria-selected={selectable ? selected : undefined}\n tabIndex={selectable ? -1 : undefined}\n onMouseDown={\n /* Shift-click is line-range selection here, but the browser also reads\n it as \"extend the text selection\", which paints a stray highlight\n across the block. Suppressing it only for the shift case leaves plain\n drag-to-select, and therefore copying, untouched. */\n selectable\n ? (event) => {\n if (event.shiftKey) event.preventDefault();\n }\n : undefined\n }\n onClick={\n selectable && onSelect ? (event) => onSelect(line.number, event.shiftKey) : undefined\n }\n className={cn(\n LINE_BASE_CLASS,\n LINE_NUMBER_CLASS,\n LINE_STATE_CLASS,\n LINE_DIFF_CLASS,\n LINE_FOCUS_CLASS,\n LINE_MOTION_CLASS,\n selectable && \"cursor-pointer\",\n )}\n /**\n * Every row re-seeds the counter, making its number absolute rather\n * than ordinal. That serves two features at once: folding can remove\n * rows without renumbering the tail, and `content-visibility` can skip\n * offscreen rows - a style-contained row cannot read a shared counter,\n * which once rendered every gutter number as 1.\n */\n style={{ counterReset: `cb-line ${line.number - 1}` }}\n >\n {foldRegion && onToggleFold ? (\n <button\n type=\"button\"\n /* Inside a role=\"option\" row a focusable descendant is invalid ARIA,\n so the toggle leaves the tab order when the block is selectable;\n pointer use is unaffected. */\n tabIndex={selectable ? -1 : undefined}\n data-slot=\"code-block-fold-toggle\"\n data-state={folded ? \"folded\" : \"unfolded\"}\n aria-expanded={!folded}\n aria-label={\n folded\n ? `Unfold lines ${foldRegion.start + startLine - 1} to ${foldRegion.end + startLine - 1}`\n : `Fold lines ${foldRegion.start + startLine - 1} to ${foldRegion.end + startLine - 1}`\n }\n onClick={(event) => {\n /* The row itself may be a selection target, and a fold is not a\n selection. */\n event.stopPropagation();\n onToggleFold(foldRegion.start);\n }}\n className={cn(\n /* Styled as a ghost xs button rather than composed from Button:\n the ghost variant paints aria-expanded:bg-muted, which would\n keep every UNFOLDED toggle lit, and its icon rungs do not fit\n an 18px channel. Hover feedback only; folded state reads\n through color. */\n /* Square, centred in the line box: height matches the width and\n the translate makes up the difference to the 24px line. Open\n regions read darker than folded ones. */\n \"sticky z-20 inline-flex size-(--code-block-fold-width) shrink-0 translate-y-[calc((var(--code-block-line-height)-var(--code-block-fold-width))/2)] cursor-pointer items-center justify-center rounded-[4px] align-top text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50\",\n /* Margins cancel: -(4px + width) then +4px, so the toggle paints\n in the channel, sits 4px from the code, and the code still\n starts where a row without a toggle does. An uncancelled\n margin slid every foldable row and clipped characters. The\n spacing() shorthand is written as a rem literal because\n `mr-(--spacing(1))` is not valid Tailwind and generates no\n rule at all - measured live as a 4px drift. */\n \"-ml-[calc(var(--code-block-fold-width)+0.25rem)]\",\n \"mr-[0.25rem]\",\n \"left-[calc(var(--code-block-gutter-width)-var(--code-block-fold-width)-0.25rem)]\",\n folded && \"text-muted-foreground/60\",\n )}\n >\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"size-3\"\n >\n <path d={folded ? \"m9 18 6-6-6-6\" : \"m6 9 6 6 6-6\"} />\n </svg>\n </button>\n ) : null}\n {actions && active ? (\n // biome-ignore lint/a11y/useKeyWithClickEvents: <>\n <span\n data-slot=\"code-block-line-actions\"\n data-side={inGutter ? \"gutter\" : \"end\"}\n contentEditable={false}\n /* An action is a control, not line content. Without this the click\n bubbles to a selectable row and toggles the very selection the\n action just consumed, so \"add these 6 lines\" left line 6 selected\n behind it. The consumer's own handler has already run by here. */\n onClick={(event) => event.stopPropagation()}\n className={cn(\n /* Inside the <pre>, so the code surface's mono face, pre\n whitespace and token color would cascade into real buttons\n placed here. Reset to app typography at the boundary. */\n \"z-20 select-none items-center gap-1 whitespace-normal font-sans text-foreground\",\n !inGutter && \"absolute end-2 top-0 flex h-(--code-block-line-height)\",\n /* ABSOLUTE and centred on the row's START EDGE: `left-0` is where\n the code column begins (the row box already excludes the\n gutter), and the -50% translate hangs the control half over the\n number column, half over the code - the editor treatment. Being\n out of flow on BOTH axes is the point: an in-flow version\n pushed the code right by its own width, and an earlier block\n level one broke the row onto a new line. The control travels\n with the code on a horizontal scroll; it cannot also be sticky. */\n inGutter &&\n \"absolute top-1/2 left-0 flex -translate-x-1/2 -translate-y-1/2 items-center justify-center\",\n )}\n >\n {actions({ line: line.number, text: line.text, state })}\n </span>\n ) : null}\n <span data-slot=\"code-block-line-content\">\n {/* An empty line needs an explicit break. Copying a selection relies on\n the browser emitting a newline between block-level rows, and a row\n with no text at all contributes neither text nor separator, so a\n blank line silently vanishes from the pasted source. */}\n {line.tokens.length === 0 ? <br /> : null}\n <CodeBlockTokens tokens={line.tokens} />\n {folded && hiddenCount > 0 ? (\n /* `select-none` is doing real work: a manual drag-select over a\n folded block would otherwise paste this chip into the middle of\n the source. The copy button reads the raw code and never sees it. */\n <button\n type=\"button\"\n tabIndex={selectable ? -1 : undefined}\n data-slot=\"code-block-fold-marker\"\n aria-label={`Unfold ${hiddenCount} hidden lines`}\n onClick={(event) => {\n event.stopPropagation();\n onToggleFold?.(line.number);\n }}\n /* Same centring as the fold toggle: chip height matches the fold\n channel and the translate makes up the difference to the line\n box, so the label sits on the code baseline's visual centre\n instead of riding high. */\n className=\"ml-2 inline-flex h-(--code-block-fold-width) translate-y-[calc((var(--code-block-line-height)-var(--code-block-fold-width))/2)] cursor-pointer select-none items-center rounded-sm bg-muted/80 px-1.5 align-top text-[0.8em] text-muted-foreground leading-none hover:bg-muted\"\n >\n {`... ${hiddenCount} lines`}\n </button>\n ) : null}\n {caret ? (\n <span\n data-slot=\"code-block-caret\"\n aria-hidden=\"true\"\n /* An underline caret: a thin strip on the baseline, the shape a\n terminal uses, instead of a bold block that outweighs the text\n it follows. */\n className=\"ml-0.5 inline-block h-[0.12em] w-[0.55em] translate-y-[0.02em] animate-pulse rounded-[1px] bg-(--code-block-caret-color) motion-reduce:animate-none\"\n />\n ) : null}\n </span>\n </span>\n );\n});\n\n/* -------------------------------------------------------------------------- */\n/* Root */\n/* -------------------------------------------------------------------------- */\n\nexport type CodeBlockProps = {\n code?: string;\n language?: string;\n lines?: CodeBlockLine[];\n themes?: CodeBlockThemes;\n highlight?: boolean;\n showLineNumbers?: boolean;\n startLine?: number;\n wrap?: boolean;\n defaultWrap?: boolean;\n onWrapChange?: (wrap: boolean) => void;\n maxLines?: number;\n variant?: \"default\" | \"ghost\";\n label?: string;\n highlightedLines?: CodeBlockLineSpec;\n highlightedWords?: CodeBlockWordSpec[];\n focusedLines?: CodeBlockLineSpec;\n diff?: CodeBlockDiffSpec;\n lineLevels?: CodeBlockLevelSpec;\n transformers?: CodeBlockTransformer[];\n streaming?: boolean;\n selectable?: boolean;\n selectedLines?: number[];\n defaultSelectedLines?: number[];\n onSelectedLinesChange?: (lines: number[]) => void;\n /** Screen-reader text announced when a stream finishes, for localisation. */\n completeAnnouncement?: string;\n /** Collapsed state under `maxLines`, controlled. */\n expanded?: boolean;\n defaultExpanded?: boolean;\n onExpandedChange?: (expanded: boolean) => void;\n /** Detects fold regions from indentation and renders a toggle per region. */\n foldable?: boolean;\n /**\n * Replaces the indentation heuristic with your own regions (source-numbered,\n * like every line spec) - grammar folding, JSON blocks, patch hunks.\n * Implies nothing about `foldable`; pass both.\n */\n foldRegions?: CodeBlockFoldRegion[];\n /** Folded regions by start line, 1-based within `code`. Controlled. */\n folded?: number[];\n /** Folded regions by their start line, uncontrolled. */\n defaultFolded?: number[];\n onFoldedChange?: (folded: number[]) => void;\n children?: ReactNode;\n} & Omit<ComponentProps<\"div\">, \"children\" | \"onSelect\">;\n\n/**\n * The root. `<CodeBlock code={code} language=\"tsx\" />` is a complete block;\n * passing `lines` from a server component skips the client highlighter and\n * shiki entirely. Children are CHROME ONLY: the root renders the code surface\n * itself, so child order never matters and a wrapper cannot break scrolling.\n */\nfunction CodeBlock({\n code,\n language,\n lines: linesProp,\n themes,\n highlight = true,\n showLineNumbers = false,\n startLine = 1,\n wrap: wrapProp,\n defaultWrap = false,\n onWrapChange,\n maxLines,\n variant = \"default\",\n label,\n highlightedLines,\n highlightedWords,\n focusedLines,\n diff,\n lineLevels,\n transformers,\n streaming = false,\n selectable = false,\n selectedLines,\n defaultSelectedLines,\n onSelectedLinesChange,\n completeAnnouncement,\n expanded: expandedProp,\n defaultExpanded = false,\n onExpandedChange,\n foldable = false,\n foldRegions: foldRegionsProp,\n folded,\n defaultFolded,\n onFoldedChange,\n className,\n children,\n ...props\n}: CodeBlockProps) {\n const contentId = useId();\n const source = code ?? \"\";\n const resolvedLanguage = resolveCodeBlockLanguage(language);\n\n /* The deferred copy is what a fast stream tokenises against. React keeps the\n previous render on screen while the new one is prepared, so the block never\n blanks and the main thread is never blocked by a chunk. */\n const deferredSource = useDeferredValue(source);\n\n const plainLines = useMemo(\n () => toPlainLines(deferredSource, startLine),\n [deferredSource, startLine],\n );\n\n /* The result is tagged with the exact inputs that produced it. Without the\n tag, swapping `code` kept rendering the PREVIOUS document for the whole\n async highlight pass - or spliced two files together when the old result\n was shorter than the new source. */\n const [highlighted, setHighlighted] = useState<{\n source: string;\n spec: string;\n lines: CodeBlockLine[];\n } | null>(null);\n\n const shouldHighlight = !linesProp && highlight && Boolean(resolvedLanguage) && source.length > 0;\n\n /* Presentation props enter the effect as ONE serialized key: they are\n inline literals at most call sites, and reference deps would re-tokenize\n per parent render. The effect parses its inputs back out of the key, so\n used and depended-on values cannot drift. `transformers` holds functions\n and stays a reference dep - hoist it to module scope. */\n const specKey = JSON.stringify([\n themes ?? null,\n startLine,\n highlightedLines ?? null,\n highlightedWords ?? null,\n focusedLines ?? null,\n diff ?? null,\n lineLevels ?? null,\n ]);\n\n const transformersWarnedRef = useRef(false);\n const previousTransformersRef = useRef(transformers);\n useEffect(() => {\n if (\n process.env.NODE_ENV !== \"production\" &&\n streaming &&\n previousTransformersRef.current !== transformers &&\n !transformersWarnedRef.current\n ) {\n transformersWarnedRef.current = true;\n console.warn(\n \"[code-block] `transformers` changed identity during a stream, which \" +\n \"re-tokenizes the whole document per chunk. Hoist the array to \" +\n \"module scope or memoize it.\",\n );\n }\n previousTransformersRef.current = transformers;\n }, [transformers, streaming]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: <>\n useEffect(() => {\n if (!shouldHighlight) {\n setHighlighted(null);\n return;\n }\n\n const [\n specThemes,\n specStartLine,\n specHighlightedLines,\n specHighlightedWords,\n specFocusedLines,\n specDiff,\n specLineLevels,\n ] = JSON.parse(specKey) as [\n CodeBlockThemes | null,\n number,\n CodeBlockLineSpec | null,\n CodeBlockWordSpec[] | null,\n CodeBlockLineSpec | null,\n CodeBlockDiffSpec | null,\n CodeBlockLevelSpec | null,\n ];\n\n let active = true;\n void highlightCode(deferredSource, {\n language,\n instanceKey: contentId,\n themes: specThemes ?? undefined,\n transformers,\n startLine: specStartLine,\n highlightedLines: specHighlightedLines ?? undefined,\n highlightedWords: specHighlightedWords ?? undefined,\n focusedLines: specFocusedLines ?? undefined,\n diff: specDiff ?? undefined,\n lineLevels: specLineLevels ?? undefined,\n }).then((next) => {\n if (active) {\n setHighlighted({ source: deferredSource, spec: specKey, lines: next });\n }\n });\n\n return () => {\n active = false;\n };\n }, [shouldHighlight, deferredSource, language, transformers, specKey]);\n\n /* Plain text is the floor, never a blank frame: the highlighter runs a\n chunk behind a stream, so its lines show as-is and the remainder appends\n as plain text that gains colour a frame later. */\n const lines = useMemo(() => {\n if (linesProp) return linesProp;\n if (!shouldHighlight || !highlighted) return plainLines;\n /* The merge below is only valid under the STREAMING invariant: the\n highlighted source must be a prefix of what is on screen, with the same\n presentation spec. A swapped `code` or spec falls back to plain text\n for one highlight pass instead of showing the previous document. */\n if (highlighted.spec !== specKey || !deferredSource.startsWith(highlighted.source)) {\n return plainLines;\n }\n if (highlighted.lines.length >= plainLines.length) return highlighted.lines;\n return [...highlighted.lines, ...plainLines.slice(highlighted.lines.length)];\n }, [linesProp, shouldHighlight, highlighted, plainLines, deferredSource, specKey]);\n\n const focusMode = useMemo(() => lines.some((line) => line.state?.focused), [lines]);\n\n const hasDiff = useMemo(() => lines.some((line) => line.state?.diff), [lines]);\n\n const [internalWrap, setInternalWrap] = useState(defaultWrap);\n const wrap = wrapProp ?? internalWrap;\n const setWrap = useCallback(\n (next: boolean) => {\n if (wrapProp === undefined) setInternalWrap(next);\n onWrapChange?.(next);\n },\n [wrapProp, onWrapChange],\n );\n\n const collapsible = typeof maxLines === \"number\" && lines.length > maxLines;\n const [internalExpanded, setInternalExpanded] = useState(defaultExpanded);\n const expanded = expandedProp ?? internalExpanded;\n const setExpanded = useCallback(\n (next: boolean) => {\n if (expandedProp === undefined) setInternalExpanded(next);\n onExpandedChange?.(next);\n },\n [expandedProp, onExpandedChange],\n );\n const isExpanded = collapsible ? expanded : true;\n\n const [internalSelected, setInternalSelected] = useState<number[]>(defaultSelectedLines ?? []);\n const selection = selectedLines ?? internalSelected;\n const selectedSet = useMemo(() => new Set(selection), [selection]);\n const lastSelectedRef = useRef<number | null>(null);\n\n /* Latest-value refs, so the toggle callbacks below can be created ONCE.\n With state in their dep lists every selection or fold change minted new\n identities, which reached every row through `onSelect`/`onToggleFold` and\n busted the row memo the streaming design rests on. */\n const selectionStateRef = useRef({\n selection,\n selectedSet,\n controlled: selectedLines !== undefined,\n onSelectedLinesChange,\n });\n selectionStateRef.current = {\n selection,\n selectedSet,\n controlled: selectedLines !== undefined,\n onSelectedLinesChange,\n };\n\n const commitSelection = useCallback((next: number[]) => {\n if (!selectionStateRef.current.controlled) setInternalSelected(next);\n selectionStateRef.current.onSelectedLinesChange?.(next);\n }, []);\n\n const toggleLine = useCallback(\n (line: number, extend: boolean) => {\n const anchor = lastSelectedRef.current;\n const { selection, selectedSet } = selectionStateRef.current;\n\n if (extend && anchor !== null) {\n const from = Math.min(anchor, line);\n const to = Math.max(anchor, line);\n const range: number[] = [];\n for (let value = from; value <= to; value += 1) range.push(value);\n commitSelection(range);\n return;\n }\n\n lastSelectedRef.current = line;\n commitSelection(\n selectedSet.has(line)\n ? selection.filter((value) => value !== line)\n : [...selection, line].sort((a, b) => a - b),\n );\n },\n [commitSelection],\n );\n\n /* Regions are SOURCE-numbered (1-based within `code`), like every other\n line spec, so `folded` values and `highlightedLines` values interchange. */\n const foldRegions = useMemo(() => {\n if (!foldable) return EMPTY_FOLD_REGIONS;\n if (foldRegionsProp) return foldRegionsProp;\n return computeFoldRegions(lines).map((region) => ({\n start: region.start - startLine + 1,\n end: region.end - startLine + 1,\n }));\n }, [foldable, foldRegionsProp, lines, startLine]);\n\n const foldStarts = useMemo(\n () => new Map(foldRegions.map((region) => [region.start, region])),\n [foldRegions],\n );\n\n const [internalFolded, setInternalFolded] = useState<number[]>(defaultFolded ?? []);\n const foldedValue = folded ?? internalFolded;\n const foldedSet = useMemo(() => new Set(foldedValue), [foldedValue]);\n\n /* Same latest-value shape as selection, for the same row-memo reason. */\n const foldStateRef = useRef({\n foldedValue,\n foldedSet,\n controlled: folded !== undefined,\n onFoldedChange,\n });\n foldStateRef.current = {\n foldedValue,\n foldedSet,\n controlled: folded !== undefined,\n onFoldedChange,\n };\n\n const commitFolded = useCallback((next: number[]) => {\n if (!foldStateRef.current.controlled) setInternalFolded(next);\n foldStateRef.current.onFoldedChange?.(next);\n }, []);\n\n const toggleFold = useCallback(\n (start: number) => {\n const { foldedValue, foldedSet } = foldStateRef.current;\n commitFolded(\n foldedSet.has(start)\n ? foldedValue.filter((value) => value !== start)\n : [...foldedValue, start].sort((a, b) => a - b),\n );\n },\n [commitFolded],\n );\n\n /**\n * A line is hidden when ANY folded region covers it, and that one rule is\n * what makes nesting work without a tree: folding an outer region swallows\n * the inner toggles as well, their own folded state survives untouched\n * underneath, and unfolding the outer one restores exactly what the reader\n * left behind rather than a flattened block.\n */\n const renderedLines = useMemo(() => {\n if (!foldable || foldedSet.size === 0) return lines;\n const hidden = new Set<number>();\n for (const start of foldedSet) {\n const region = foldStarts.get(start);\n if (!region) continue;\n for (let n = region.start + 1; n <= region.end; n += 1) {\n hidden.add(n + startLine - 1);\n }\n }\n return lines.filter((line) => !hidden.has(line.number));\n }, [foldable, foldedSet, foldStarts, lines, startLine]);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: <>\n const configValue = useMemo<CodeBlockConfigValue>(\n () => ({\n language,\n resolvedLanguage,\n showLineNumbers,\n wrap,\n setWrap,\n wrapControlled: wrapProp !== undefined,\n expanded: isExpanded,\n setExpanded,\n collapsible,\n streaming,\n contentId,\n }),\n [\n language,\n resolvedLanguage,\n showLineNumbers,\n wrap,\n setWrap,\n wrapProp,\n isExpanded,\n collapsible,\n streaming,\n contentId,\n ],\n );\n\n const clearSelection = useCallback(() => commitSelection([]), [commitSelection]);\n\n const documentValue = useMemo<CodeBlockDocumentValue>(\n () => ({\n code: source,\n lines,\n selected: selectedSet,\n selectable,\n toggleLine,\n clearSelection,\n foldable,\n foldRegions,\n folded: foldedSet,\n toggleFold,\n setFolded: commitFolded,\n }),\n [\n source,\n lines,\n selectedSet,\n selectable,\n toggleLine,\n clearSelection,\n foldable,\n foldRegions,\n foldedSet,\n toggleFold,\n commitFolded,\n ],\n );\n\n const visibleLines = collapsible && !isExpanded ? maxLines : undefined;\n\n /* Detected from the element type rather than a `:has()` selector. This repo\n has measured `:has()` at 85-120ms of style invalidation per DOM mutation,\n and a streaming block mutates on every chunk, so the primitive uses none. */\n const hasHeader = containsElementType(children, CodeBlockHeader);\n\n const [lineActions, setLineActions] = useState<CodeBlockLineActionsRender | null>(null);\n const [actionsSide, setActionsSide] = useState<CodeBlockLineActionsSide>(\"end\");\n const actionsOwnerRef = useRef<object | null>(null);\n const actionsRegistry = useMemo(\n () => ({\n /* Wrapped in a setter callback: a render prop IS a function, so passing\n it to setState bare would run it as a state updater. Ownership makes\n a stale unmount a no-op and makes a SECOND live group loud in dev -\n the registry holds one render prop, so the second silently won. */\n register: (\n owner: object,\n render: CodeBlockLineActionsRender | null,\n side: CodeBlockLineActionsSide = \"end\",\n ) => {\n if (render) {\n if (\n process.env.NODE_ENV !== \"production\" &&\n actionsOwnerRef.current &&\n actionsOwnerRef.current !== owner\n ) {\n console.warn(\n \"[code-block] Two CodeBlockLineActions are mounted; the block \" +\n \"renders ONE action group and the later mount replaces the \" +\n \"earlier one.\",\n );\n }\n actionsOwnerRef.current = owner;\n } else if (actionsOwnerRef.current !== owner) {\n return;\n } else {\n actionsOwnerRef.current = null;\n }\n setLineActions(() => render);\n setActionsSide(side);\n },\n }),\n [],\n );\n\n /* One channel between the numbers and the code, shared by the fold toggle\n and a gutter-side action. Reserved only when something asks for it, so a\n plain block keeps the gutter it always had. */\n /* Only FOLDING reserves gutter space. A gutter-side action floats over the\n row's start edge instead of widening anything, so a block with actions is\n geometrically identical to one without. */\n const gutterChannel = foldable;\n\n /* Walked rather than registered, so server HTML never carries a doubled\n surface. Sees through plain wrappers; a consumer component boundary is\n opaque, which the dev-mode guard in CodeBlockContent reports. */\n const hasContent = containsElementType(children, CodeBlockContent);\n\n const surfaceProps: CodeBlockSurfaceProps = {\n lines: renderedLines,\n gutterMax: lines[lines.length - 1]?.number ?? startLine,\n foldable,\n gutterChannel,\n actionsSide,\n foldStarts,\n foldedSet,\n onToggleFold: toggleFold,\n expandClearance: collapsible && isExpanded,\n wrap,\n startLine,\n showLineNumbers,\n focusMode,\n selectable,\n selectedSet,\n toggleLine,\n visibleLines,\n streaming,\n label: label ?? (language ? `${language} code` : \"Code\"),\n contentId,\n actions: lineActions,\n completeAnnouncement,\n builtInSurfaceRendered: !hasContent,\n };\n\n return (\n <CodeBlockConfigContext.Provider value={configValue}>\n <CodeBlockDocumentContext.Provider value={documentValue}>\n <CodeBlockActionsContext.Provider value={actionsRegistry}>\n <div\n data-slot=\"code-block\"\n data-variant={variant}\n data-streaming={streaming || undefined}\n data-has-diff={hasDiff || undefined}\n data-foldable={foldable || undefined}\n data-gutter-channel={gutterChannel || undefined}\n data-has-header={hasHeader || undefined}\n className={cn(\n ROOT_BASE_CLASS,\n ROOT_RADIUS_CLASS,\n ROOT_TOKEN_CLASS,\n variant === \"default\" && ROOT_SURFACE_CLASS,\n variant === \"ghost\" && ROOT_GHOST_CLASS,\n className,\n )}\n {...props}\n >\n <CodeBlockSurfacePropsContext.Provider value={surfaceProps}>\n {children}\n {!hasContent && <CodeBlockSurface {...surfaceProps} />}\n </CodeBlockSurfacePropsContext.Provider>\n </div>\n </CodeBlockActionsContext.Provider>\n </CodeBlockDocumentContext.Provider>\n </CodeBlockConfigContext.Provider>\n );\n}\n\n/**\n * The code surface as a composable part: inside your own ScrollArea the block\n * stops scrolling internally and the ancestor owns both axes (`maxLines`'\n * height cap no longer applies). Omitted, the root renders the same surface\n * itself, exactly as before.\n */\nfunction CodeBlockContent({ className }: { className?: string }) {\n const surface = useContext(CodeBlockSurfacePropsContext);\n if (!surface) {\n throw new Error(\"CodeBlockContent must be used within a CodeBlock\");\n }\n\n /* The render-time walk cannot see through a consumer's own component\n boundary; when that happens the root also renders its built-in surface\n and the code appears twice. Silent double content is the worst failure\n mode, so development says exactly what to do. */\n useEffect(() => {\n if (process.env.NODE_ENV === \"production\") return;\n if (surface.builtInSurfaceRendered) {\n console.error(\n \"CodeBlockContent is hidden behind a component boundary, so CodeBlock \" +\n \"also rendered its built-in surface and the code appears twice. \" +\n \"Compose <CodeBlockContent /> directly in the CodeBlock's children \" +\n \"(plain wrappers like a ScrollArea are fine).\",\n );\n }\n }, [surface.builtInSurfaceRendered]);\n\n return <CodeBlockSurface {...surface} scroll={false} className={className} />;\n}\n\n/**\n * Sees through plain element wrappers (a ScrollArea, a div) but not through a\n * consumer's own component boundary - unrendered children are opaque. Compose\n * `CodeBlockContent` directly in the block's subtree.\n */\nfunction containsElementType(node: ReactNode, type: unknown): boolean {\n for (const child of Children.toArray(node)) {\n if (!isValidElement(child)) continue;\n if (child.type === type) return true;\n const inner = (child.props as { children?: ReactNode }).children;\n if (inner && containsElementType(inner, type)) return true;\n }\n return false;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Surface */\n/* -------------------------------------------------------------------------- */\n\ntype CodeBlockSurfaceProps = {\n lines: CodeBlockLine[];\n wrap: boolean;\n startLine: number;\n showLineNumbers: boolean;\n focusMode: boolean;\n selectable: boolean;\n selectedSet: Set<number>;\n toggleLine: (line: number, extend: boolean) => void;\n visibleLines?: number;\n gutterMax: number;\n foldable: boolean;\n gutterChannel: boolean;\n actionsSide: CodeBlockLineActionsSide;\n foldStarts: Map<number, CodeBlockFoldRegion>;\n foldedSet: Set<number>;\n onToggleFold: (start: number) => void;\n expandClearance: boolean;\n streaming: boolean;\n label: string;\n contentId: string;\n actions?: CodeBlockLineActionsRender | null;\n completeAnnouncement?: string;\n /** true when the root rendered its own surface (no CodeBlockContent found). */\n builtInSurfaceRendered?: boolean;\n /** false = no scroll container of its own; an ancestor scrolls instead. */\n scroll?: boolean;\n className?: string;\n};\n\nfunction CodeBlockSurface({\n lines,\n wrap,\n startLine,\n showLineNumbers,\n focusMode,\n selectable,\n selectedSet,\n toggleLine,\n visibleLines,\n gutterMax,\n foldable,\n gutterChannel,\n actionsSide,\n foldStarts,\n foldedSet,\n onToggleFold,\n expandClearance,\n streaming,\n label,\n contentId,\n actions,\n completeAnnouncement,\n scroll = true,\n className,\n}: CodeBlockSurfaceProps) {\n const viewportRef = useRef<HTMLDivElement | null>(null);\n const preRef = useRef<HTMLPreElement | null>(null);\n const [activeLine, setActiveLine] = useState<number | null>(null);\n const stickRef = useRef(true);\n\n /* Stick-to-bottom disengages the moment the reader scrolls up, and re-engages\n when they come back. Reading the scroll position on the event is enough\n here because nothing is written back during the same frame. */\n /* Announced once when a stream ends, so a screen reader learns the code is\n complete without hearing it assembled character by character. */\n const [announcement, setAnnouncement] = useState(\"\");\n const wasStreaming = useRef(streaming);\n useEffect(() => {\n if (wasStreaming.current && !streaming) {\n setAnnouncement(completeAnnouncement ?? `Code generation complete, ${lines.length} lines.`);\n }\n wasStreaming.current = streaming;\n }, [streaming, lines.length, completeAnnouncement]);\n\n /* Stick-to-bottom follows whichever element ACTUALLY scrolls - writing\n scrollTop to the composed mode's inert viewport was a silent no-op.\n Resolved per commit: a short block becomes its own scroller the moment\n it outgrows its cap. */\n const resolveScroller = useCallback((): HTMLElement | null => {\n const viewport = viewportRef.current;\n if (!viewport) return null;\n if (viewport.scrollHeight > viewport.clientHeight + 1) return viewport;\n\n let node: HTMLElement | null = viewport.parentElement;\n while (node && node !== document.body) {\n const overflowY = getComputedStyle(node).overflowY;\n if (\n (overflowY === \"auto\" || overflowY === \"scroll\" || overflowY === \"overlay\") &&\n node.scrollHeight > node.clientHeight + 1\n ) {\n return node;\n }\n node = node.parentElement;\n }\n\n /* An AI transcript's default shape scrolls the PAGE. The walk above never\n reaches the root elements, so without this branch the stream wrote\n scrollTop to an inert viewport and drifted off screen. */\n const page = document.scrollingElement as HTMLElement | null;\n if (page && page.scrollHeight > page.clientHeight + 1) return page;\n\n return viewport;\n }, []);\n\n const handleScroll = useCallback(() => {\n const viewport = viewportRef.current;\n if (!viewport) return;\n const distance = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;\n stickRef.current = distance < 24;\n }, []);\n\n /* The ancestor case needs its own listener: the reader's intent has to be\n recorded BEFORE the next chunk grows the content, or the distance already\n includes what just arrived. Re-attached per chunk rather than diffed,\n which is a handful of listener swaps a second and keeps this correct when\n the scrolling element changes underneath. */\n // biome-ignore lint/correctness/useExhaustiveDependencies: <>\n useEffect(() => {\n if (!streaming) return;\n const scroller = resolveScroller();\n if (!scroller || scroller === viewportRef.current) return;\n\n const onScroll = () => {\n const distance = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight;\n stickRef.current = distance < 24;\n };\n\n /* Page scrolls fire on window, not on the scrolling element. */\n const target: EventTarget = scroller === document.scrollingElement ? window : scroller;\n target.addEventListener(\"scroll\", onScroll, { passive: true });\n return () => target.removeEventListener(\"scroll\", onScroll);\n }, [streaming, lines.length, resolveScroller]);\n\n useIsoLayoutEffect(() => {\n if (!streaming || !stickRef.current) return;\n const scroller = resolveScroller();\n if (scroller) scroller.scrollTop = scroller.scrollHeight;\n }, [lines, streaming, resolveScroller]);\n\n /* One listener for the whole surface rather than a handler per line: the\n active row is resolved from the event target, so the floating action group\n costs one element no matter how long the file is. Focus is tracked as well\n as hover, or the actions would be unreachable without a pointer. */\n const trackActive = useCallback(\n (event: { target: EventTarget | null }) => {\n if (!actions && !selectable) return;\n const target = event.target as HTMLElement | null;\n const row = target?.closest?.(\"[data-code-line]\") as HTMLElement | null;\n const value = row?.getAttribute(\"data-code-line\");\n\n /* No row under the pointer means the gutter, which lives in the <pre>'s\n PADDING and so is covered by no row element. Keep the active line\n rather than clearing it: clearing here unmounted a gutter action the\n moment the pointer left the code toward it, so the control vanished\n before it could be pressed. `onPointerLeave` still clears on exit. */\n if (!value) return;\n setActiveLine(Number(value));\n },\n [actions, selectable],\n );\n\n const clearActive = useCallback(() => setActiveLine(null), []);\n\n /* Rows and keyboard speak DISPLAYED numbers (the gutter, data-code-line);\n selection state speaks SOURCE numbers like every other line spec. This is\n the one conversion point between them. */\n const toggleDisplayed = useCallback(\n (displayed: number, extend: boolean) => toggleLine(displayed - startLine + 1, extend),\n [toggleLine, startLine],\n );\n\n const handleKeyDown = useCallback(\n (event: ReactKeyboardEvent<HTMLElement>) => {\n if (!selectable) return;\n\n if (event.key === \"Escape\") {\n setActiveLine(null);\n return;\n }\n\n /* Toggle IN PLACE. Shift+Arrow selects while moving, but without this a\n keyboard user could never deselect a single line. */\n if ((event.key === \"Enter\" || event.key === \" \") && activeLine !== null) {\n event.preventDefault();\n toggleDisplayed(activeLine, event.shiftKey);\n return;\n }\n\n const isArrow = event.key === \"ArrowDown\" || event.key === \"ArrowUp\";\n if (!isArrow && event.key !== \"Home\" && event.key !== \"End\") return;\n event.preventDefault();\n\n /* Step by RENDERED index, not by number arithmetic: folding removes\n rows, and numeric stepping walked the active line into hidden lines\n where it silently vanished. */\n let next: number;\n if (event.key === \"Home\") {\n next = lines[0]?.number ?? startLine;\n } else if (event.key === \"End\") {\n next = lines[lines.length - 1]?.number ?? startLine;\n } else {\n const step = event.key === \"ArrowDown\" ? 1 : -1;\n const index = lines.findIndex((line) => line.number === activeLine);\n const nextIndex =\n index === -1\n ? step === 1\n ? 0\n : lines.length - 1\n : Math.min(lines.length - 1, Math.max(0, index + step));\n next = lines[nextIndex]?.number ?? startLine;\n }\n\n setActiveLine(next);\n const row = preRef.current?.querySelector<HTMLElement>(`[data-code-line=\"${next}\"]`);\n row?.scrollIntoView({ block: \"nearest\" });\n if (isArrow && event.shiftKey) toggleDisplayed(next, true);\n },\n [selectable, lines, startLine, activeLine, toggleDisplayed],\n );\n\n const lastLineNumber = lines[lines.length - 1]?.number;\n\n /* `startLine` is just a counter reset. Gutter width follows the widest\n number in the DOCUMENT (not the folded view, or folding the tail would\n shift every row); `ch` is one digit in the mono `pre`, and the floor of 2\n stops the column twitching as a stream crosses line 9. Lines carrying\n their own gutter label (a patch's dual numbers) widen it to the longest\n label instead. */\n const gutterDigits = Math.max(\n 2,\n String(gutterMax ?? startLine).length,\n ...lines.map((line) => line.gutter?.length ?? 0),\n );\n\n const surfaceStyle = {\n \"--code-block-gutter-width\": gutterChannel\n ? `calc(${gutterDigits}ch + var(--code-block-fold-width) + var(--code-block-gutter-gap) + var(--code-block-padding))`\n : `calc(${gutterDigits}ch + var(--code-block-gutter-gap) + var(--code-block-padding))`,\n counterReset: `cb-line ${startLine - 1}`,\n } as CSSProperties;\n\n return (\n <div\n data-slot=\"code-block-content\"\n className={cn(\n \"relative min-w-0 rounded-[inherit]\",\n /* Clipping is the scroll-mode contract only: composed, a clipped pre\n would hide its own width from the ancestor's viewport and the\n horizontal scrollbar would never render. */\n scroll && \"flex-1 overflow-hidden\",\n )}\n >\n {/* A polite status, deliberately NOT an aria-live region on the code\n itself: a live region over streaming code narrates every token. */}\n <span role=\"status\" aria-live=\"polite\" className=\"sr-only\">\n {announcement}\n </span>\n {/* A plain overflow container, deliberately not a ScrollArea primitive.\n The scroll must stay INSIDE the block (the sticky gutter, the\n stick-to-bottom stream and `maxLines` all anchor to it), but nothing\n here needs custom scrollbar machinery, and dropping it leaves the\n block with no UI-library dependency at all - which is why both twins\n are the same file. Compose Card, Frame, or your own ScrollArea\n around the block for outer framing. */}\n <div\n ref={viewportRef}\n data-slot=\"code-block-viewport\"\n id={contentId}\n role=\"region\"\n aria-label={label}\n aria-busy={streaming || undefined}\n aria-activedescendant={\n selectable && activeLine !== null ? `${contentId}-L${activeLine}` : undefined\n }\n // biome-ignore lint/a11y/noNoninteractiveTabindex: <>\n tabIndex={0}\n onScroll={handleScroll}\n onKeyDown={handleKeyDown}\n className={cn(\n \"relative min-w-0 rounded-[inherit] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\",\n /* Composed under an ancestor scroller the surface scrolls NOTHING\n itself: both axes belong to the ancestor, whose viewport picks up\n the pre's overflowing width, and the sticky number cell anchors\n to that viewport instead. Mixed ownership shipped once and read\n as two scrollbar styles on one block. */\n scroll && \"overflow-auto [scrollbar-width:thin]\",\n scroll && visibleLines && \"max-h-(--cb-max-height)\",\n className,\n )}\n style={\n scroll && visibleLines\n ? ({\n \"--cb-max-height\": `calc(${visibleLines} * var(--code-block-line-height) + 2 * var(--code-block-padding))`,\n } as CSSProperties)\n : undefined\n }\n >\n <pre\n ref={preRef}\n dir=\"ltr\"\n data-code-line-numbers={showLineNumbers || undefined}\n data-wrap={wrap || undefined}\n role={selectable ? \"listbox\" : undefined}\n data-selectable={selectable || undefined}\n aria-multiselectable={selectable || undefined}\n aria-label={selectable ? `${label} lines` : undefined}\n onPointerOver={trackActive}\n onPointerLeave={clearActive}\n onFocus={trackActive}\n className={cn(\n \"text-(length:--code-block-font-size) w-max min-w-full py-(--code-block-padding) font-mono\",\n TOKEN_COLOR_CLASS,\n TOKEN_MOTION_CLASS,\n /* `min-w-0` must beat the `min-w-full` above, or the pre keeps\n a floor of 100% of a scroll container that is itself wider\n than the viewport, and wrapping still leaves a stray\n horizontal scrollbar. */\n wrap && \"wrap-break-word w-full min-w-0 max-w-full whitespace-pre-wrap\",\n showLineNumbers && \"pl-(--code-block-gutter-width)\",\n /* The expand control floats over the surface in BOTH states, so\n an expanded block reserves a row of clearance rather than\n growing a bordered footer under the code. */\n expandClearance && \"pb-(--code-block-expand-clearance)\",\n )}\n style={surfaceStyle}\n >\n {/* `content-visibility: auto` is a measured dead end on BOTH axes:\n its style containment breaks the shared gutter counter\n (every number renders as 1), and per-row it still fails -\n the paint containment clips the number cell, which is\n deliberately pulled left OUT of the row's box (verified in\n Chrome: forcing one row visible restored only that row's\n number). Windowing here means rendering fewer rows, not\n containing them. */}\n {/* presentation, so the listbox owns its options directly. */}\n <code data-slot=\"code-block-code\" role={selectable ? \"presentation\" : undefined}>\n {lines.map((line) => (\n <CodeBlockLineRow\n key={line.number}\n line={line}\n selectable={selectable}\n selected={selectedSet.has(line.number - startLine + 1)}\n focusMode={focusMode}\n active={activeLine === line.number}\n caret={streaming && line.number === lastLineNumber}\n actions={activeLine === line.number ? actions : null}\n actionsSide={actionsSide}\n domIdBase={contentId}\n startLine={startLine}\n onSelect={toggleDisplayed}\n foldable={foldable}\n foldRegion={foldStarts.get(line.number - startLine + 1)}\n folded={foldedSet.has(line.number - startLine + 1)}\n onToggleFold={onToggleFold}\n />\n ))}\n </code>\n </pre>\n </div>\n </div>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Chrome */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Opt-in header. Absent, the block renders no chrome, so it nests in a Card or\n * Frame without a doubled bar. Presence flips `data-has-header` on the root,\n * detected from the element type rather than a `:has()` selector.\n */\nfunction CodeBlockHeader({ className, ...props }: ComponentProps<\"div\">) {\n return (\n <CodeBlockHeaderContext.Provider value={true}>\n <div\n data-slot=\"code-block-header\"\n className={cn(\n \"flex min-h-9 shrink-0 items-center gap-2 border-border border-b px-3 py-0 text-sm\",\n className,\n )}\n {...props}\n />\n </CodeBlockHeaderContext.Provider>\n );\n}\n\nfunction CodeBlockTitle({ className, ...props }: ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"code-block-title\"\n className={cn(\"min-w-0 truncate font-mono text-muted-foreground text-xs\", className)}\n {...props}\n />\n );\n}\n\n/**\n * The resolved language as a label, no props needed. It shows what the\n * highlighter actually resolved, so an unsupported grammar becomes visible\n * instead of silently rendering plain.\n */\nfunction CodeBlockLanguage({ className, children, ...props }: ComponentProps<\"span\">) {\n const { language, resolvedLanguage } = useInternalConfig(\"CodeBlockLanguage\");\n const label = children ?? resolvedLanguage ?? language;\n\n if (!label) return null;\n\n return (\n <span\n data-slot=\"code-block-language\"\n data-unsupported={!resolvedLanguage || undefined}\n className={cn(\n \"inline-flex shrink-0 items-center rounded-md border border-border bg-muted/60 px-1.5 py-0.5 font-mono text-[0.6875rem] text-muted-foreground uppercase leading-none\",\n className,\n )}\n {...props}\n >\n {label}\n </span>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Copy button */\n/* -------------------------------------------------------------------------- */\n\nfunction CopyIcon({ copied }: { copied: boolean }) {\n return copied ? (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <path d=\"M20 6 9 17l-5-5\" />\n </svg>\n ) : (\n <svg\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n aria-hidden=\"true\"\n >\n <rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\" />\n <path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\" />\n </svg>\n );\n}\n\nexport type CodeBlockCopyButtonProps = {\n value?: string;\n timeout?: number;\n onCopy?: (value: string) => void;\n onCopyError?: (error: unknown) => void;\n /** Accessible names, for localisation. */\n labels?: { copy?: string; copied?: string };\n /** `pinned` floats over the surface; `inline` sits in a header. */\n position?: \"auto\" | \"pinned\" | \"inline\";\n alwaysVisible?: boolean;\n} & Omit<ComponentProps<typeof Button>, \"value\" | \"onCopy\">;\n\n/**\n * Copy button. Inline inside a header, pinned over the surface anywhere else.\n * Pinning is absolute against the root, not `position: sticky`: sticky still\n * slides away under HORIZONTAL scroll, and code scrolls sideways constantly.\n * Notation comments are stripped from the payload, matching what is rendered.\n */\nfunction CodeBlockCopyButton({\n value,\n timeout = 2000,\n onCopy,\n onCopyError,\n labels,\n position = \"auto\",\n alwaysVisible = false,\n className,\n variant = \"ghost\",\n size,\n children,\n ...props\n}: CodeBlockCopyButtonProps) {\n const context = useContext(CodeBlockConfigContext);\n const inHeader = useContext(CodeBlockHeaderContext);\n const [copied, setCopied] = useState(false);\n const [copyFailed, setCopyFailed] = useState(false);\n\n const resolvedPosition = position === \"auto\" ? (inHeader ? \"inline\" : \"pinned\") : position;\n\n /* A header is chrome, so the button takes the smaller icon rung there and the\n full one when it floats over the code. Both are per-style ladders in the\n shadcn button, so this stays style-aware instead of pinning a pixel size. */\n const resolvedSize = size ?? (resolvedPosition === \"inline\" ? \"icon-sm\" : \"icon\");\n\n useEffect(() => {\n if (!copied || timeout === 0) return;\n const id = window.setTimeout(() => setCopied(false), timeout);\n return () => window.clearTimeout(id);\n }, [copied, timeout]);\n\n useEffect(() => {\n if (!copyFailed) return;\n const id = window.setTimeout(() => setCopyFailed(false), 2000);\n return () => window.clearTimeout(id);\n }, [copyFailed]);\n\n const document_ = useContext(CodeBlockDocumentContext);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: <>\n const handleClick = useCallback(() => {\n /* Server-highlighted blocks pass `lines` and no `code`, so the document\n text is the fallback; without it this rendered a labelled control that\n did nothing on the exact path the docs advertise. */\n const fallback = document_?.code || document_?.lines.map((line) => line.text).join(\"\\n\");\n const payload = stripNotationComments(value ?? fallback ?? \"\");\n if (!payload) return;\n if (typeof navigator === \"undefined\" || !navigator.clipboard?.writeText) {\n return;\n }\n\n navigator.clipboard.writeText(payload).then(\n () => {\n setCopied(true);\n onCopy?.(payload);\n },\n /* Rejection is routine: a denied permission, or a document that lost\n focus. Without the handler it surfaced as an unhandled rejection in\n the consumer's error monitoring. */\n (error: unknown) => {\n setCopyFailed(true);\n onCopyError?.(error);\n },\n );\n }, [value, context, document_, onCopy, onCopyError]);\n\n return (\n <Button\n type=\"button\"\n data-slot=\"code-block-copy\"\n data-copied={copied || undefined}\n data-copy-failed={copyFailed || undefined}\n data-position={resolvedPosition}\n aria-label={copied ? (labels?.copied ?? \"Copied\") : (labels?.copy ?? \"Copy code\")}\n variant={variant}\n size={resolvedSize}\n onClick={handleClick}\n className={cn(\n \"shrink-0 [&_svg]:size-3.5\",\n resolvedPosition === \"pinned\" &&\n /* Physical `right`, not logical `end`: the code surface is forced\n dir=\"ltr\", so in an RTL app the logical inset landed the button\n over the first characters instead of the trailing edge. */\n \"absolute top-(--code-block-copy-top) right-(--code-block-copy-inset) z-20\",\n resolvedPosition === \"pinned\" &&\n !alwaysVisible &&\n \"opacity-0 transition-opacity focus-visible:opacity-100 group-hover/code-block:opacity-100\",\n className,\n )}\n {...props}\n >\n {children ?? <CopyIcon copied={copied} />}\n </Button>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Wrap and expand */\n/* -------------------------------------------------------------------------- */\n\nfunction CodeBlockWrapToggle({\n className,\n children,\n variant = \"ghost\",\n size = \"sm\",\n onClick,\n ...props\n}: ComponentProps<typeof Button>) {\n const { wrap, setWrap } = useInternalConfig(\"CodeBlockWrapToggle\");\n\n return (\n <Button\n type=\"button\"\n data-slot=\"code-block-wrap-toggle\"\n data-state={wrap ? \"on\" : \"off\"}\n aria-pressed={wrap}\n variant={variant}\n size={size}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) setWrap(!wrap);\n }}\n className={cn(\"shrink-0\", className)}\n {...props}\n >\n {children ?? (wrap ? \"No wrap\" : \"Wrap\")}\n </Button>\n );\n}\n\n/**\n * Expands a block collapsed by `maxLines`.\n *\n * Renders nothing when the content is shorter than the cut, so a consumer can\n * always compose it without guarding on line count themselves.\n */\nfunction CodeBlockExpandButton({\n className,\n children,\n variant = \"ghost\",\n size = \"sm\",\n onClick,\n ...props\n}: ComponentProps<typeof Button>) {\n const { expanded, setExpanded, collapsible, contentId } =\n useInternalConfig(\"CodeBlockExpandButton\");\n\n if (!collapsible) return null;\n\n return (\n <div\n data-slot=\"code-block-expand\"\n data-state={expanded ? \"expanded\" : \"collapsed\"}\n className={cn(\n /* Both states float over the surface. Expanded used to rejoin the flex\n column as a bordered strip, which read as a card footer and moved the\n block's bottom edge on the first click; the surface reserves a row of\n clearance instead, so only the label changes. */\n \"absolute inset-x-0 bottom-0 z-10 order-last flex items-end justify-center pt-10 pb-2\",\n /* The fade means \"there is more below\", so it belongs to the collapsed\n state only. Expanded, the surface already reserves a clear row for\n this control, and keeping the gradient just dimmed the last real\n line of code. */\n !expanded && \"bg-linear-to-t from-card via-card/85 to-transparent\",\n className,\n )}\n >\n <Button\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={contentId}\n variant={variant}\n size={size}\n onClick={(event) => {\n onClick?.(event);\n if (!event.defaultPrevented) setExpanded(!expanded);\n }}\n {...props}\n >\n {children ?? (expanded ? \"Show less\" : \"Show more\")}\n </Button>\n </div>\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Line actions */\n/* -------------------------------------------------------------------------- */\n\nexport type CodeBlockLineActionsProps = {\n children: CodeBlockLineActionsRender;\n /**\n * `end` floats the group over the end of the active row. `gutter` puts it in\n * the channel beside the line number, which is where a \"add this line\"\n * affordance belongs. A fold toggle owns that channel when both are on, so a\n * gutter action on a fold-start row falls back to `end`.\n */\n side?: CodeBlockLineActionsSide;\n};\n\n/**\n * Actions on the hovered or focused line. ONE group exists for the whole\n * block, rendered inside the active row: a 2,000 line file mounts one button\n * group, not 2,000.\n */\nconst LANGUAGE_EXTENSIONS: Record<string, string> = {\n bash: \"sh\",\n c: \"c\",\n cpp: \"cpp\",\n csharp: \"cs\",\n css: \"css\",\n diff: \"patch\",\n docker: \"dockerfile\",\n go: \"go\",\n graphql: \"graphql\",\n html: \"html\",\n java: \"java\",\n javascript: \"js\",\n json: \"json\",\n jsx: \"jsx\",\n kotlin: \"kt\",\n markdown: \"md\",\n php: \"php\",\n python: \"py\",\n ruby: \"rb\",\n rust: \"rs\",\n sql: \"sql\",\n swift: \"swift\",\n toml: \"toml\",\n tsx: \"tsx\",\n typescript: \"ts\",\n xml: \"xml\",\n yaml: \"yaml\",\n};\n\nexport type CodeBlockDownloadButtonProps = {\n /** Text to save. Defaults to the block's code with notation stripped. */\n value?: string;\n /** Defaults to `code.<ext>` from the block's language. */\n filename?: string;\n onDownload?: (filename: string) => void;\n /** `pinned` floats over the surface; `inline` sits in a header. */\n position?: \"auto\" | \"pinned\" | \"inline\";\n alwaysVisible?: boolean;\n /** Accessible name, for localisation. */\n label?: string;\n} & Omit<ComponentProps<typeof Button>, \"value\">;\n\n/**\n * Saves the block's code as a file - the sibling the copy button was missing\n * for builder-style output, where the result IS a file and disk is the next\n * step. Same placement contract as the copy button.\n */\nfunction CodeBlockDownloadButton({\n value,\n filename,\n onDownload,\n position = \"auto\",\n alwaysVisible = false,\n label,\n className,\n variant = \"ghost\",\n size,\n children,\n ...props\n}: CodeBlockDownloadButtonProps) {\n const context = useContext(CodeBlockConfigContext);\n const document_ = useContext(CodeBlockDocumentContext);\n const inHeader = useContext(CodeBlockHeaderContext);\n\n const resolvedPosition = position === \"auto\" ? (inHeader ? \"inline\" : \"pinned\") : position;\n const resolvedSize = size ?? (resolvedPosition === \"inline\" ? \"icon-sm\" : \"icon\");\n\n const handleClick = useCallback(() => {\n const fallback = document_?.code || document_?.lines.map((line) => line.text).join(\"\\n\");\n const payload = stripNotationComments(value ?? fallback ?? \"\");\n if (!payload || typeof window === \"undefined\") return;\n\n const extension = LANGUAGE_EXTENSIONS[context?.resolvedLanguage ?? \"\"] ?? \"txt\";\n const name = filename ?? `code.${extension}`;\n const url = URL.createObjectURL(new Blob([payload], { type: \"text/plain;charset=utf-8\" }));\n const anchor = window.document.createElement(\"a\");\n anchor.href = url;\n anchor.download = name;\n anchor.click();\n /* Deferred: revoking synchronously races the browser starting the save. */\n window.setTimeout(() => URL.revokeObjectURL(url), 1000);\n onDownload?.(name);\n }, [value, filename, context, document_, onDownload]);\n\n return (\n <Button\n type=\"button\"\n data-slot=\"code-block-download\"\n data-position={resolvedPosition}\n aria-label={label ?? \"Download code\"}\n variant={variant}\n size={resolvedSize}\n onClick={handleClick}\n className={cn(\n \"shrink-0 [&_svg]:size-3.5\",\n resolvedPosition === \"pinned\" &&\n \"absolute top-(--code-block-copy-top) right-(--code-block-copy-inset) z-20\",\n resolvedPosition === \"pinned\" &&\n !alwaysVisible &&\n \"opacity-0 transition-opacity focus-visible:opacity-100 group-hover/code-block:opacity-100\",\n className,\n )}\n {...props}\n >\n {children ?? (\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 3v12m0 0 4-4m-4 4-4-4M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2\" />\n </svg>\n )}\n </Button>\n );\n}\n\nfunction CodeBlockLineActions({ children, side = \"end\" }: CodeBlockLineActionsProps) {\n const registry = useContext(CodeBlockActionsContext);\n const owner = useRef({}).current;\n\n useEffect(() => {\n registry?.register(owner, children, side);\n return () => registry?.register(owner, null);\n }, [registry, owner, children, side]);\n\n return null;\n}\n\n/**\n * Live folding for anything composed inside the block - a \"fold all\" control,\n * a region count. Mirrors `useCodeBlockSelection`; region and start numbers\n * are source-based like every line spec.\n */\nfunction useCodeBlockFolding() {\n const document = useContext(CodeBlockDocumentContext);\n if (!document) {\n throw new Error(\"useCodeBlockFolding must be used within a CodeBlock\");\n }\n\n const { foldable, foldRegions, folded, toggleFold, setFolded } = document;\n const foldedStarts = useMemo(() => [...folded].sort((a, b) => a - b), [folded]);\n const foldAll = useCallback(\n () => setFolded(foldRegions.map((region) => region.start)),\n [setFolded, foldRegions],\n );\n const unfoldAll = useCallback(() => setFolded([]), [setFolded]);\n\n return {\n foldable,\n regions: foldRegions,\n foldedStarts,\n toggleFold,\n foldAll,\n unfoldAll,\n };\n}\n\n/**\n * Live selection for anything composed inside the block - a line action, a\n * header control. Returns the selected lines as a sorted array plus the same\n * toggle the rows use, so an \"add selection to chat\" affordance can act on the\n * whole range instead of only the hovered line.\n */\nfunction useCodeBlockSelection() {\n const document = useContext(CodeBlockDocumentContext);\n if (!document) {\n throw new Error(\"useCodeBlockSelection must be used within a CodeBlock\");\n }\n\n const { selected, selectable, toggleLine, clearSelection } = document;\n const selectedLines = useMemo(() => [...selected].sort((a, b) => a - b), [selected]);\n\n return { selectable, selectedLines, toggleLine, clearSelection };\n}\n\n/* Re-exported so a consumer wires an AI transcript from one import path. */\nexport { markdownCodeProps, markdownFences };\nexport {\n ansiToLines,\n parseUnifiedDiff,\n} from \"./code-block-highlight\";\nexport type {\n CodeBlockDiffSpec,\n CodeBlockHighlightOptions,\n CodeBlockLevelSpec,\n CodeBlockLine,\n CodeBlockLineActionsRender,\n CodeBlockLineSpec,\n CodeBlockLineState,\n CodeBlockPatchFile,\n CodeBlockThemes,\n CodeBlockToken,\n CodeBlockTransformer,\n CodeBlockWordSpec,\n} from \"./code-block-highlight\";\n\nexport {\n CodeBlock,\n CodeBlockCopyButton,\n CodeBlockDownloadButton,\n CodeBlockExpandButton,\n CodeBlockHeader,\n CodeBlockLanguage,\n CodeBlockLineActions,\n CodeBlockTitle,\n CodeBlockContent,\n CodeBlockWrapToggle,\n useCodeBlockConfig,\n useCodeBlockFolding,\n useCodeBlockSelection,\n};\n"],"mappings":";;;;;;;;AAoFA,MAAM,yBAAyB,cAA2C,IAAI;AAC9E,MAAM,2BAA2B,cAA6C,IAAI;;AAGlF,MAAM,yBAAyB,cAAc,KAAK;;;;;;;;AASlD,MAAM,+BAA+B,cAA4C,IAAI;AASrF,MAAM,0BAA0B,cAMtB,IAAI;AAId,MAAM,qBAAqB,OAAO,WAAW,cAAc,kBAAkB;AAE7E,SAAS,kBAAkB,MAAoC;CAC7D,MAAM,UAAU,WAAW,sBAAsB;CACjD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,GAAG,KAAK,iCAAiC;CAE3D,OAAO;AACT;AAEA,SAAS,mBAAmB,MAAuD;CACjF,MAAM,UAAU,WAAW,sBAAsB;CACjD,MAAM,WAAW,WAAW,wBAAwB;CACpD,IAAI,CAAC,WAAW,CAAC,UACf,MAAM,IAAI,MAAM,GAAG,KAAK,iCAAiC;CAK3D,OAAO,eAAe;EAAE,GAAG;EAAS,M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C/B,MAAM,WAAW,WAAW,wBAAwB;CACpD,IAAI,CAAC,UACH,MAAM,IAAI,MAAM,uDAAuD;CAGzE,MAAM,EAAE,UAAU,YAAY,YAAY,mBAAmB;CAG7D,OAAO;EAAE;EAAY,eAFC,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAEjD;EAAG;EAAY;CAAe;AACjE"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Button } from "../../ui/button.js";
|
|
3
3
|
import { Popover, PopoverContent, PopoverTrigger } from "../../ui/popover.js";
|
|
4
|
-
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
5
4
|
import { CascaderFooter } from "../cascader/cascader-footer.js";
|
|
6
5
|
import { CascaderBreadcrumb, CascaderInput, CascaderNav } from "../cascader/cascader-nav.js";
|
|
7
6
|
import { CascaderVirtualItems } from "../cascader/cascader-virtual.js";
|
|
7
|
+
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
8
8
|
import { filterControlSizes, filterReadOnlyProps, useFilterActions, useFilterState } from "./filters-context.js";
|
|
9
9
|
import { FILTER_FIELD_PICKER_CLASS, getFilterField, getFilterFieldCount, joinFilterPath, splitFilterPath } from "./filters-lib.js";
|
|
10
10
|
import { getDefaultFilterOperator } from "./filters-operators.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filters-chip.js","names":["React"],"sources":["../../../../src/components/reui/filters/filters-chip.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n ArrowLeftRightIcon,\n ChevronRightIcon,\n CopyIcon,\n CornerDownRightIcon,\n EllipsisVerticalIcon,\n LayersIcon,\n SlidersHorizontalIcon,\n Trash2Icon,\n XIcon,\n} from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\nimport { ButtonGroup, ButtonGroupText } from \"../../ui/button-group\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from \"../../ui/dropdown-menu\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../../ui/popover\";\nimport { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from \"../../ui/tooltip\";\nimport {\n filterControlSizes,\n filterReadOnlyProps,\n isFilterLocked,\n useFilterActions,\n useFilterChipAutoOpen,\n useFilterChipFocused,\n useFilterFocusEmpty,\n useFilterFocusStore,\n useFilterRender,\n useFilterReorderable,\n} from \"./filters-context\";\nimport { FilterMenu, useFilterOptions, useFilterValueResolution } from \"./filters-editors\";\nimport {\n collapseFilterPath,\n FILTER_MENU_CLASS,\n FILTER_MENU_LABEL_CLASS,\n formatFilterPath,\n getFilterField,\n getFilterFieldChain,\n} from \"./filters-lib\";\nimport {\n coerceFilterValue,\n getFilterArity,\n getFilterOperator,\n operatorTakesValue,\n visibleFilterOperators,\n} from \"./filters-operators\";\nimport { findFilterNode, isFilterGroup } from \"./filters-query\";\nimport type {\n FilterEditorProps,\n FilterField,\n FilterGroupNode,\n FilterOperator,\n FilterRule,\n} from \"./filters-types\";\n\n/** Which part of the chip a pointer or key is aimed at. No `field`: the chip's\n * attribute segment is display only, and only the builder re-picks one. */\ntype ChipSegment = \"operator\" | \"value\" | \"menu\";\n\n/** The ref half of `autoFocusProps`: a CALLBACK ref, the one shape an editor\n * can spread onto any element without a cast, and a no-op here. */\nconst noopAutoFocusRef: React.RefCallback<HTMLElement> = () => {};\n\nfunction defaultValueDisplay<V>(\n value: V | undefined,\n operator: FilterOperator | undefined,\n resolveOption: (value: string) => { label: string } | undefined,\n labels: ReturnType<typeof useFilterActions>[\"labels\"],\n // The field's own word for \"no value yet\", which a generic label cannot beat.\n fieldPlaceholder?: string,\n /** Whether the value is PICKED rather than typed: a select's search prompt\n * and \"enter text...\" both give way to `labels.selectPlaceholder`. */\n optionBacked?: boolean,\n): string {\n const emptyLabel = optionBacked\n ? labels.selectPlaceholder\n : (fieldPlaceholder ?? labels.valuePlaceholder);\n if (value === undefined || value === null || value === \"\") {\n return emptyLabel;\n }\n\n if (getFilterArity(operator) === \"range\" && Array.isArray(value)) {\n const [from, to] = value as unknown[];\n return labels.valueRange(String(from ?? \"\"), String(to ?? \"\"));\n }\n\n if (Array.isArray(value)) {\n const values = value as string[];\n if (values.length === 0) return emptyLabel;\n if (values.length === 1) {\n return resolveOption(values[0])?.label ?? String(values[0]);\n }\n return labels.valueCount(values.length);\n }\n\n if (typeof value === \"boolean\") return value ? \"True\" : \"False\";\n\n return resolveOption(String(value))?.label ?? String(value);\n}\n\n/** The same display with the option's own icon in front. A status filter reads\n * as its colour before its word, so dropping the swatch the picker showed\n * makes the chip harder to scan than the list it came from. */\nfunction valueWithIcon<V>(\n value: V | undefined,\n text: string,\n resolveOption: (value: string) => { icon?: React.ReactNode } | undefined,\n): React.ReactNode {\n const single =\n value === undefined || value === null || Array.isArray(value)\n ? Array.isArray(value) && value.length === 1\n ? String(value[0])\n : null\n : String(value);\n const icon = single ? resolveOption(single)?.icon : null;\n if (!icon) return text;\n return (\n <span className=\"flex items-center gap-1.5\">\n {icon}\n {text}\n </span>\n );\n}\n\n/** The glyph between two ancestors in a nested attribute path, a chevron\n * because the `pathSeparator` string read as loud as the names it parts.\n * DECORATIVE: `aria-hidden`, and the plain string is still what\n * `formatFilterPath` joins for the chip's accessible name and `title`. */\nfunction FilterPathSeparator() {\n return (\n <ChevronRightIcon\n aria-hidden=\"true\"\n data-slot=\"filter-path-separator\"\n className=\"mx-[3px] inline-block size-3 shrink-0 self-center align-[calc(0.3635em-0.375rem)] text-muted-foreground\"\n />\n );\n}\n\n/** The elided run of a collapsed path, with the FULL path behind it. THE\n * TOOLTIP IS NOT THE ACCESSIBLE ROUTE: it is hover and focus, so the segment\n * is `aria-hidden` and the whole path stays in the control's NAME. The host's\n * own `title` is dropped while collapsed (`pathCollapsed`) or both fire. */\nfunction FilterPathEllipsis({ full }: { full: string }) {\n return (\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger\n render={\n <span\n aria-hidden=\"true\"\n data-slot=\"filter-path-ellipsis\"\n /* A path SEGMENT with no air of its own: the chevron's margin\n is all that parts a name from the next, and this used to STACK\n an `mx` on it. Plain inline, no `vertical-align`: `middle` sat\n the dots 1.7px low and inline-block grew the run to 21.17px. */\n className=\"shrink-0 self-center text-muted-foreground\"\n >\n ...\n </span>\n }\n />\n <TooltipContent>{full}</TooltipContent>\n </Tooltip>\n </TooltipProvider>\n );\n}\n\n/** Everything a rule needs in order to be READ, in either chrome. */\nexport interface FilterRuleDisplay {\n pathText: string;\n pathLabel: React.ReactNode;\n /** Whether `pathLabel` shows fewer names than the path has, so the cell's\n * own `title` can step aside for the ellipsis segment's tooltip. */\n pathCollapsed: boolean;\n operatorLabel: string;\n valueLabel: React.ReactNode;\n /** The same value as PLAIN TEXT, for an accessible name. Never scraped from\n * the `renderValue` node: whatever text survives inside avatars and a count\n * badge announces \"plus one\" for two people. Kept separate from\n * `valueLabel`, not derived from it: a React node has no honest text to\n * read back. A field whose values do not stringify supplies `valueText`\n * itself, or the built-in fallback says \"[object Object]\" to exactly the\n * audience the visible display is hiding it from. */\n valueText: string;\n /** The same value with any collapsed COUNT spelled out. \"3 selected\" cannot\n * be recovered from, which is fine while the editor opens and not once\n * locked, so the control carries this as `title` and, locked, as its name. */\n valueFullText: string;\n valueEmpty: boolean;\n}\n\n/** How one rule reads, resolved once and shared by both chromes, so a consumer\n * `renderValue`, the field's own and the built-in cannot disagree. */\nexport function useFilterRuleDisplay<V, O>(\n rule: FilterRule<V>,\n field: FilterField<V, O> | undefined,\n operator: FilterOperator | undefined,\n): FilterRuleDisplay {\n const actions = useFilterActions<V, O>();\n const render = useFilterRender<V, O>();\n // Lazily: a label needs no options until an editor actually opens.\n const optionsState = useFilterOptions<V, O>(field, false);\n\n const values =\n rule.value === undefined || rule.value === null\n ? []\n : Array.isArray(rule.value)\n ? (rule.value as unknown[])\n : [rule.value];\n\n // Saved views: values the loader has never returned are resolved through the\n // field's own `resolveValues`, so a restored chip reads \"John Doe\", not an id.\n useFilterValueResolution(field, values);\n\n const pathText = formatFilterPath(actions.index, rule.path, actions.labels.pathSeparator);\n\n const chain = getFilterFieldChain(actions.index, rule.path);\n // The CASCADER's collapser, from the actions context rather than per host, so\n // a deep path reads the same on a chip and in a builder row.\n const segments = collapseFilterPath(chain, {\n maxSegments: actions.maxPathSegments,\n collapse: actions.pathCollapse,\n });\n const pathCollapsed = segments.some((segment) => segment.type === \"ellipsis\");\n const pathLabel = chain.length\n ? segments.map((segment, index) => (\n <React.Fragment\n /* Positional, because a field id is unique among its SIBLINGS only:\n \"Company > Team > Company\" is a legal path and its two ids collide. */\n key={segment.type === \"field\" ? `${index}:${segment.field.id}` : `${index}:ellipsis`}\n >\n {index > 0 ? <FilterPathSeparator /> : null}\n {segment.type === \"field\" ? (\n <span>{segment.field.label}</span>\n ) : (\n <FilterPathEllipsis full={pathText} />\n )}\n </React.Fragment>\n ))\n : pathText;\n\n const operatorLabel = operator\n ? rule.negated\n ? actions.labels.negated(operator.label)\n : operator.label\n : rule.operator || actions.labels.selectCondition;\n\n const valueEmpty =\n rule.value === undefined ||\n rule.value === null ||\n rule.value === (\"\" as unknown as V) ||\n values.length === 0;\n\n if (!field) {\n return {\n pathText,\n pathLabel,\n pathCollapsed,\n operatorLabel,\n valueLabel: \"\",\n valueText: \"\",\n valueFullText: \"\",\n valueEmpty,\n };\n }\n\n const valueContext = {\n value: rule.value,\n values,\n field,\n operator: operator ?? { value: rule.operator, label: rule.operator },\n // Resolved, not empty: a custom display needs the option behind each value.\n options: values\n .map((entry) => optionsState.resolve(String(entry)))\n .filter(Boolean) as NonNullable<ReturnType<typeof optionsState.resolve>>[],\n labels: actions.labels,\n };\n\n // Computed even when a custom display replaces it: this is the string the\n // accessible name is built from. `field.valueText` overrides it.\n const valueText = field.valueText\n ? field.valueText(valueContext)\n : defaultValueDisplay(\n rule.value,\n operator,\n optionsState.resolve,\n actions.labels,\n field.placeholder,\n // Option-backed by the FIELD, not the operator: `is any of` is\n // multi-value on a plain text field too, and that one is typed into.\n field.type === \"select\" ||\n field.type === \"multiselect\" ||\n Boolean(field.options?.length) ||\n Boolean(field.loadOptions),\n );\n\n const valueLabel = render.renderValue\n ? render.renderValue(valueContext)\n : field.renderValue\n ? field.renderValue(valueContext)\n : valueWithIcon(rule.value, valueText, optionsState.resolve);\n\n // The list behind the count, or the same text again. Multi-value only: a\n // RANGE also stores an array but already spells both ends out (\"10 to 99\").\n const valueFullText =\n field.valueText ||\n !Array.isArray(rule.value) ||\n getFilterArity(operator) === \"range\" ||\n values.length < 2\n ? valueText\n : actions.labels.valueDetail(\n valueText,\n values.map((entry) => optionsState.resolve(String(entry))?.label ?? String(entry)),\n );\n\n return {\n pathText,\n pathLabel,\n pathCollapsed,\n operatorLabel,\n valueLabel,\n valueText,\n valueFullText,\n valueEmpty,\n };\n}\n\ninterface FilterValueEditorProps<V = unknown, O = unknown> {\n rule: FilterRule<V>;\n field: FilterField<V, O>;\n operator: FilterOperator;\n /** Whether the surface holding it is showing. Gates the option service. */\n open: boolean;\n onClose: () => void;\n}\n\n/** The value editor - draft, option service, commit - with NO surface of its\n * own, so surface and wiring can be replaced independently. The draft lives\n * here, so a text filter dispatches once on commit, not once per keystroke. */\nfunction FilterValueEditor<V, O>({\n rule,\n field,\n operator,\n open,\n onClose,\n}: FilterValueEditorProps<V, O>) {\n const actions = useFilterActions<V, O>();\n const [draft, setDraft] = React.useState<V | undefined>(rule.value);\n\n React.useEffect(() => {\n if (open) setDraft(rule.value);\n }, [open, rule.value]);\n\n const options = useFilterOptions<V, O>(field, open);\n // A LOOKUP, not a definition: every result is a module-level built-in or the\n // consumer's own component, so the editor is never remounted mid-edit.\n const editor = React.useMemo(\n () => actions.resolveEditor(field, operator),\n [actions, field, operator],\n );\n\n if (!editor) return null;\n\n const editorProps: FilterEditorProps<V, O> = {\n field,\n operator,\n value: draft,\n onValueChange: (next) => setDraft(next as V),\n host: \"amend\",\n autoFocusProps: {\n ref: noopAutoFocusRef,\n autoFocus: true,\n },\n commit: (next, commitOptions) => {\n actions.updateRule(rule.id, {\n value: (next === undefined ? draft : next) as V,\n });\n // A multi-select commits per toggle and asks to stay put; others dismiss.\n if (commitOptions?.close === false) return;\n onClose();\n },\n cancel: onClose,\n // The same as cancel, honestly: `back` means something only to a `create`\n // host.\n back: onClose,\n options,\n labels: actions.labels,\n };\n\n // `createElement` rather than JSX: the component comes out of a lookup, so\n // `<Editor />` trips `react-hooks/static-components`. The fragment keeps the\n // props object, which carries a ref, from looking like a ref read in render.\n return <>{React.createElement(editor, editorProps)}</>;\n}\n\n/** One step of the flow, released when the panel that owes it has LEFT THE\n * DOM: both popovers keep portal content mounted through the exit transition,\n * so this unmount IS that moment and nothing is timed. `onRelease` is used AS\n * the cleanup, so an unmemoized callback fires its step early. */\nfunction FilterStepHandoff({ onRelease }: { onRelease: () => void }) {\n React.useEffect(() => onRelease, [onRelease]);\n return null;\n}\n\n/** The value host: the editor in a popover anchored to the value segment, and\n * BOTH routes end here. The operator popover used to draw the editor itself,\n * so a handed-off panel sat a segment's width left of a second press. */\nexport interface FilterValuePopoverProps<V = unknown, O = unknown> {\n rule: FilterRule<V>;\n field: FilterField<V, O>;\n operator: FilterOperator | undefined;\n /** The element that opens it, WITH its own children: a chip segment must be\n * a direct child of its `ButtonGroup` for the pill to fuse. */\n trigger: React.ReactElement;\n className?: string;\n}\n\nexport function FilterValuePopover<V, O>({\n rule,\n field,\n operator,\n trigger,\n className,\n}: FilterValuePopoverProps<V, O>) {\n const actions = useFilterActions<V, O>();\n const focusStore = useFilterFocusStore();\n const autoOpen = useFilterChipAutoOpen(rule.id) === \"value\";\n const [open, setOpen] = React.useState(false);\n const locked = isFilterLocked(actions);\n\n // The last step of the flow as well as the amend route; by now the condition\n // menu has UNMOUNTED (see `FilterStepHandoff`). CONSUMED as it is honoured,\n // or Escape closes the editor and this effect reopens it in the same frame.\n // The `set` stays OUTSIDE the `locked` guard on purpose: a handoff nobody\n // spends sits armed until some later chip spends it, and a chip that opened\n // because a DIFFERENT chip was arrowed onto is worse than one that opened\n // nothing.\n React.useEffect(() => {\n if (!autoOpen || open) return;\n if (!locked) setOpen(true);\n focusStore.set({ id: rule.id, segment: \"value\", autoOpen: false });\n }, [autoOpen, open, focusStore, rule.id, locked]);\n\n // Nothing to open, but the trigger still renders so the value keeps its\n // place, and it wears the bar's state: that hangs on the TRIGGER below,\n // which this path never reaches, so the segment used to look live.\n if (!operator || !actions.resolveEditor(field, operator)) {\n return React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n disabled: actions.disabled,\n ...filterReadOnlyProps(actions),\n });\n }\n\n return (\n // REFUSES to open while locked rather than leaving it to the trigger: an\n // `aria-disabled` control that still opens an editor is one that lied.\n <Popover\n open={open}\n onOpenChange={(next) => {\n if (next && locked) return;\n setOpen(next);\n }}\n >\n {/* The trigger IS the segment, never a wrapper. `ButtonGroup` fuses\n DIRECT children only (`*:data-slot:rounded-r-none`,\n `[&>[data-slot]~[data-slot]]:border-l-0`), so a nested one keeps its\n own border and the chip reads as separate badges. */}\n <PopoverTrigger\n render={trigger}\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n />\n <PopoverContent align=\"start\" className={cn(\"w-auto p-0\", className)}>\n <FilterValueEditor<V, O>\n rule={rule}\n field={field}\n operator={operator}\n open={open}\n onClose={() => {\n setOpen(false);\n focusStore.set({ id: rule.id, segment: \"value\", autoOpen: false });\n }}\n />\n </PopoverContent>\n </Popover>\n );\n}\n\n/* A chip's ATTRIBUTE is fixed once the chip exists: no field popover here. A\n new field invalidates the operator and the value, so \"amending\" threw both\n away. The builder keeps its picker, where a row reads as a form. */\n\n/** The condition menu, and the step after it. The list is the cascader run\n * flat: the old hand-rolled one marked the keyboard HIGHLIGHT with\n * `aria-selected` and had no Home, End or typeahead. It HANDS OFF to the\n * value popover once its own panel has left the DOM; advancing in place\n * anchored the editor to the CONDITION segment and doubled up in the row. */\nexport interface FilterOperatorPopoverProps<V = unknown, O = unknown> {\n rule: FilterRule<V>;\n field: FilterField<V, O>;\n trigger: React.ReactElement;\n className?: string;\n}\n\nexport function FilterOperatorPopover<V, O>({\n rule,\n field,\n trigger,\n className,\n}: FilterOperatorPopoverProps<V, O>) {\n const actions = useFilterActions<V, O>();\n const focusStore = useFilterFocusStore();\n const autoOpen = useFilterChipAutoOpen(rule.id) === \"operator\";\n const [open, setOpen] = React.useState(false);\n const locked = isFilterLocked(actions);\n /** Whether the close this panel is going through IS the step being handed\n * on. A ref, so it survives the render that closes the popover. Every OPEN\n * clears it, so an Escape or an outside press finds it already lowered and\n * spends nothing; `release` leaves it standing because one twin asks again\n * later: Radix reads it from `onCloseAutoFocus`, a macrotask after the\n * unmount. Clearing it in `release` would break that twin only. */\n const handoff = React.useRef(false);\n const operators = actions.resolveOperators(field);\n\n // Memoized because the array IS the menu's identity: the cascader rebuilds\n // its index per `items` identity, so a fresh array rebuilds it per keystroke.\n const items = React.useMemo(\n () =>\n visibleFilterOperators(operators).map((entry) => ({\n value: entry.value,\n label: entry.label,\n })),\n [operators],\n );\n\n // Opened by the root the moment the chip is created. CONSUMED here, or the\n // handoff re-opens the menu on the frame Escape closes it. Consumed even\n // while locked, for the reason on the value popover's copy.\n React.useEffect(() => {\n if (!autoOpen || open) return;\n handoff.current = false;\n if (!locked) setOpen(true);\n focusStore.set({ id: rule.id, segment: \"operator\", autoOpen: false });\n }, [autoOpen, open, focusStore, rule.id, locked]);\n\n const close = () => {\n handoff.current = false;\n setOpen(false);\n focusStore.set({ id: rule.id, segment: \"operator\", autoOpen: false });\n };\n\n /** The parked step, spent on the frame this panel stops existing. Memoized\n * on nothing that changes, and load bearing: `FilterStepHandoff` uses this\n * AS its cleanup, so a new identity mid-flow fires the step too early. */\n const release = React.useCallback(() => {\n if (!handoff.current) return;\n focusStore.set({ id: rule.id, segment: \"value\", autoOpen: true });\n }, [focusStore, rule.id]);\n\n // The chip going away takes its step with it: React destroys a deleted\n // subtree top down, so this runs before the panel's own cleanup.\n React.useEffect(\n () => () => {\n handoff.current = false;\n },\n [],\n );\n\n return (\n <Popover\n open={open}\n onOpenChange={(next) => {\n if (next && locked) return;\n /* Escape, an outside press, a second press: none is the step being\n taken, so none may spend it. RETIRED ON OPEN, not on close, and that\n is a twin difference: in Radix an item choice dismisses through here\n too, so retiring on close wiped the request before the unmount. */\n if (next) handoff.current = false;\n setOpen(next);\n }}\n >\n <PopoverTrigger\n render={trigger}\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n />\n <PopoverContent\n align=\"start\"\n /* Base UI restores focus to the trigger as this panel closes, which\n lands on the condition segment AFTER the value editor has opened and\n focused its input, so a keyboard user is dropped back a step and\n cannot reach the value at all. Suppressed only while the handoff is\n up; a function because Base UI resolves it at close time, which is\n when the ref is accurate. Radix runs the same guard through\n `onCloseAutoFocus`. */\n finalFocus={() => !handoff.current}\n /* `w-auto` with a FLOOR: a catalog sizes to its longest label, and a\n boolean field's \"is\" and \"is not\" would read as a scrap of paper. */\n className={cn(\"w-auto min-w-40 p-0\", className)}\n >\n {/* INSIDE the panel deliberately: only a child of the content is\n unmounted by the exit transition rather than by the close. */}\n <FilterStepHandoff onRelease={release} />\n <FilterMenu\n items={items}\n selected={rule.operator ? [rule.operator] : []}\n onSelectionChange={(values) => {\n const value = values[0];\n /* Deselecting the committed operator is a step back rather than a\n choice, so pressing the current row simply closes. */\n if (value === undefined) {\n close();\n return;\n }\n const chosen = getFilterOperator(operators, value);\n /* BUILDING versus AMENDING, the same fork the advanced row draws\n at its field step. A rule reaches this menu with no operator\n exactly once, while it is being added, and only then is the\n value the step after this one. Re-picking the condition on a\n rule that already has one is an edit of that one cell: it\n commits and closes, and the user opens the value themselves. */\n const building = !rule.operator;\n actions.updateRule(rule.id, {\n operator: value,\n /* The value moves with the operator: \"is\" to \"is any of\" would\n leave a bare string where every reader expects an array. */\n value: coerceFilterValue(\n rule.value,\n getFilterOperator(operators, rule.operator),\n chosen,\n ) as V,\n });\n if (building && operatorTakesValue(chosen)) {\n /* PARKED, not opened: `release` hands the row to its value\n surface once this panel has unmounted. */\n handoff.current = true;\n setOpen(false);\n return;\n }\n close();\n }}\n labels={actions.labels}\n ariaLabel={field.label}\n searchPlaceholder={actions.labels.searchOperators}\n /* No visible search field: a CLOSED enum of six to ten labels, all\n on screen. Still RENDERED, visually hidden, because it owns focus\n and `aria-activedescendant`: arrows, Home, End and typeahead. */\n searchable={false}\n /* Taller than a value list on purpose: the operator set is CLOSED, so\n all of it fits and the height buys the whole catalog. A value list\n is open ended and would only push its own footer off the screen. */\n maxHeight={320}\n /* Deliberately unpinned: one selected operator in a short list, so\n lifting it would lose the catalog's declared reading order. */\n />\n </PopoverContent>\n </Popover>\n );\n}\n\n/** The keyboard path to a CROSS-GROUP move: Alt+Arrow reorders within the\n * owning group only and Wrap creates a NEW group, so the drag layer's\n * cross-group move had no keyboard parity. Numbered in document order. */\nexport function FilterMoveToMenuItems({ nodeId }: { nodeId: string }) {\n const actions = useFilterActions();\n // A menu ITEM takes the native word: both twins already make `disabled`\n // roving-focusable and `aria-disabled`.\n const reorderable = useFilterReorderable();\n const locked = isFilterLocked(actions);\n // Read at render time: the menu's content mounts when the menu opens, so\n // this is the tree the user is looking at.\n const query = actions.getQuery();\n const found = findFilterNode(query, nodeId);\n if (!found?.parent) return null;\n\n const destinations: { id: string; label: string; size: number }[] = [];\n if (found.parent.id !== query.id) {\n destinations.push({\n id: query.id,\n label: actions.labels.moveToTopLevel,\n size: query.rules.length,\n });\n }\n\n let position = 0;\n // `inside` suppresses the PUSH and not the walk, so the numbering stays\n // document order rather than renumbering every group after this one. Counted\n // before the exclusions for the same reason: the current parent is not\n // offered but still holds its number, so the numbering is stable whichever\n // row's menu is open.\n const visit = (group: FilterGroupNode<unknown>, inside: boolean) => {\n for (const child of group.rules) {\n if (!isFilterGroup(child)) continue;\n position += 1;\n // Itself and everything under it: `moveFilterNodeTo` already refuses that\n // move - it would detach the subtree and leave a cycle - so offering it\n // would be a menu row that quietly does nothing.\n const within = inside || child.id === nodeId;\n if (!within && child.id !== found.parent!.id) {\n destinations.push({\n id: child.id,\n label: actions.labels.moveToGroup(position),\n size: child.rules.length,\n });\n }\n visit(child, within);\n }\n };\n visit(query, false);\n\n if (destinations.length === 0) return null;\n\n // The THIRD route into a move, gated on the same switch as the grip and\n // Alt+Arrow: ungated, a builder that draws no handle still reordered here.\n if (!reorderable) return null;\n\n return (\n <>\n {destinations.map((destination) => (\n <DropdownMenuItem\n key={destination.id}\n disabled={locked}\n onClick={() => actions.moveNodeTo(nodeId, destination.id, destination.size)}\n >\n {/* A bend into the destination: movement, not duplication or nesting. */}\n <CornerDownRightIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{destination.label}</span>\n </DropdownMenuItem>\n ))}\n </>\n );\n}\n\n/** The per-rule actions, without the trigger: the chip's kebab and a builder\n * row's kebab act on the same rule. `allowGrouping` is the CHROME's answer;\n * \"Convert to advanced filter\" is the CONSUMER's, and hides itself there. */\nexport function FilterRuleMenuItems({\n ruleId,\n /** Offer \"Wrap in condition group\". Off for the chip row, which cannot draw\n * a group; on in the builder, the only way to nest without dragging. */\n allowGrouping = false,\n}: {\n ruleId: string;\n allowGrouping?: boolean;\n}) {\n const actions = useFilterActions();\n // Gated here as well as at the trigger, because this is EXPORTED: a consumer\n // composing their own menu gets rows that say they are unavailable.\n const locked = isFilterLocked(actions);\n return (\n /* Every row leads with an icon. `IconPlaceholder` because the source ships\n under five icon sets; no size class, because each style already sizes an\n unsized svg in a menu row; `aria-hidden`, the label IS the name. */\n <>\n <DropdownMenuItem disabled={locked} onClick={() => actions.duplicateNode(ruleId)}>\n <CopyIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.duplicate}</span>\n </DropdownMenuItem>\n <DropdownMenuItem disabled={locked} onClick={() => actions.negateRule(ruleId)}>\n {/* Two arrows swapping: negation flips to the declared inverse. */}\n <ArrowLeftRightIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.negate}</span>\n </DropdownMenuItem>\n {allowGrouping ? (\n <DropdownMenuItem disabled={locked} onClick={() => actions.wrapNodeInGroup(ruleId)}>\n {/* Layers: braces read as grouping in only three of the five sets. */}\n <LayersIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.wrapInGroup}</span>\n </DropdownMenuItem>\n ) : null}\n {allowGrouping ? <FilterMoveToMenuItems nodeId={ruleId} /> : null}\n {/* OPTIONAL, and gated on both halves of \"would this do anything\": the\n handler is the consumer's opt-in, and an already-advanced bar has\n nothing to convert. NOT gated on `locked`: it changes no query, is\n handed no mutator, and the shipped kebab will not open while locked. */}\n {actions.convertToAdvanced && actions.variant !== \"advanced\" ? (\n <DropdownMenuItem onClick={() => actions.convertToAdvanced?.()}>\n {/* Sliders: the one \"advanced settings\" glyph in all five sets. */}\n <SlidersHorizontalIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.convertToAdvanced}</span>\n </DropdownMenuItem>\n ) : null}\n <DropdownMenuItem\n variant=\"destructive\"\n disabled={locked}\n onClick={() => actions.removeNode(ruleId)}\n >\n {/* No colour: the destructive variant already paints the row's svgs. */}\n <Trash2Icon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.remove}</span>\n </DropdownMenuItem>\n </>\n );\n}\n\nexport interface FilterChipProps<V = unknown> {\n rule: FilterRule<V>;\n index: number;\n}\n\n/** One filter, as a chip. Memoization means something here: the actions\n * context is stable, the focus store is subscribed to a boolean and the query\n * shares structure, so editing one filter of forty re-renders one chip. */\nfunction FilterChipImpl<V, O>({ rule, index }: FilterChipProps<V>) {\n const actions = useFilterActions<V, O>();\n const render = useFilterRender<V, O>();\n const focusStore = useFilterFocusStore();\n const focused = useFilterChipFocused(rule.id);\n const noFocus = useFilterFocusEmpty();\n const locked = isFilterLocked(actions);\n // THE CHIP'S HEIGHT, by way of the one button in it that has one:\n // `ButtonGroup` is `items-stretch` and no style gives a text segment a\n // height, so the kebab's rung is the pill's. The RADIUS survives because\n // every style whose `icon-sm` rounds differently re-pins it in a group.\n const sizes = filterControlSizes(actions);\n // The kebab is CONTROLLED so it can refuse to open: every mutating row\n // behind it is gated. That puts \"Convert to advanced filter\" out of reach\n // while locked; a consumer-composed menu still draws it.\n const [menuOpen, setMenuOpen] = React.useState(false);\n // Exactly one chip is in the tab order at a time. Before anything has been\n // focused that is the first chip, so Tab reaches the row in one press.\n const isTabStop = focused || (noFocus && index === 0);\n\n const field = getFilterField(actions.index, rule.path);\n const operators = field ? actions.resolveOperators(field) : [];\n const operator = getFilterOperator(operators, rule.operator);\n\n const {\n pathText,\n pathLabel,\n pathCollapsed,\n operatorLabel,\n valueLabel,\n valueText,\n valueFullText,\n valueEmpty,\n } = useFilterRuleDisplay<V, O>(rule, field, operator);\n\n if (!field) {\n // A rule pointing at a field the schema no longer has. Dropping it loses a\n // saved view's data; rendering nothing leaves an invisible condition still\n // filtering. It carries the SAME roving wiring as a real chip: `data-slot`\n // alone joined the arrow-key query with no `tabIndex` to land on.\n return (\n <ButtonGroup\n data-slot=\"filter-chip\"\n data-unknown=\"\"\n role=\"group\"\n aria-label={actions.labels.filterLabel(rule.path.join(actions.labels.pathSeparator))}\n data-focused={focused || undefined}\n data-rule-id={rule.id}\n data-index={index}\n tabIndex={isTabStop ? 0 : -1}\n onFocusCapture={() => {\n if (!focused) focusStore.set({ id: rule.id, segment: null, autoOpen: false });\n }}\n >\n <ButtonGroupText className=\"bg-background text-muted-foreground dark:bg-input/30\">\n {rule.path.join(actions.labels.pathSeparator)}\n </ButtonGroupText>\n <Button\n variant=\"outline\"\n size={sizes.icon}\n className=\"bg-background dark:bg-input/30\"\n aria-label={actions.labels.remove}\n /* It had no gate at all, so the one chip whose whole purpose is to be\n removed could be removed from a bar that refuses every other edit. */\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n onClick={() => actions.removeNode(rule.id)}\n >\n <XIcon />\n </Button>\n </ButtonGroup>\n );\n }\n\n if (render.renderChip) return <>{render.renderChip(rule)}</>;\n\n const focusSegment = (segment: ChipSegment) =>\n focusStore.set({ id: rule.id, segment, autoOpen: false });\n\n // A rule with no condition yet, KEPT rather than removed (see\n // `isFilterRuleComplete`), so it has to read as unfinished. Through WORDS:\n // the dashed outline it replaces degraded to an underline under sera.\n const incomplete = !rule.operator;\n\n // The same test the value segment renders under, so the name matches the\n // chip: `valueText` alone appended a placeholder to valueless conditions.\n const hasValue = Boolean(rule.operator) && operatorTakesValue(operator);\n\n // The value's spoken form in the chip's NAME: a name is not a prompt, so\n // \"Description contains enter text...\" becomes \"no value\".\n const valueName = valueEmpty && !field.valueText ? actions.labels.noValue : valueText;\n\n return (\n <ButtonGroup\n data-slot=\"filter-chip\"\n role=\"group\"\n aria-label={actions.labels.filterLabel(\n `${pathText} ${operatorLabel}${hasValue ? ` ${valueName}` : \"\"}`.trim() +\n (incomplete ? `, ${actions.labels.incomplete}` : \"\"),\n )}\n data-focused={focused || undefined}\n data-incomplete={incomplete || undefined}\n data-rule-id={rule.id}\n tabIndex={isTabStop ? 0 : -1}\n className={cn(\n /* Sera is an underline style, so the boxed segments are normalised to\n its bottom-border-only look or the chip reads as a mix of both. */\n \"\",\n )}\n onFocusCapture={() => {\n if (!focused) focusStore.set({ id: rule.id, segment: null, autoOpen: false });\n }}\n data-index={index}\n >\n {/* DISPLAY ONLY: a div, not a button, not a tab stop, no popover. The\n attribute is fixed for the life of the chip. */}\n <ButtonGroupText\n /* Dropped while the path is collapsed: the ellipsis inside carries the\n same sentence as a tooltip, and the two would stack. */\n title={pathCollapsed ? undefined : pathText}\n className=\"cursor-default gap-1.5 bg-background dark:bg-input/30\"\n >\n {field.icon}\n {/* Zero gap INSIDE the path, so the separator's own margin is the only\n air around a chevron; `gap-1.5` used to stack 6px a side on it. */}\n <span className=\"flex items-center\">{pathLabel}</span>\n </ButtonGroupText>\n\n <FilterOperatorPopover\n rule={rule}\n field={field}\n trigger={\n <ButtonGroupText\n render={<button type=\"button\" />}\n className={cn(\n \"cursor-default bg-background hover:bg-accent dark:bg-input/30\",\n /* The operator is connective tissue between the field and the\n value, so it reads quieter than either - unless it is still\n the prompt \"Select condition\", the one thing to act on. */\n incomplete ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n onPointerDown={() => focusSegment(\"operator\")}\n >\n {operatorLabel}\n </ButtonGroupText>\n }\n />\n\n {/* No condition, no value: `getFilterArity(undefined)` defaults to \"one\",\n so testing the operator alone renders a stray value segment. */}\n {hasValue ? (\n <FilterValuePopover\n rule={rule}\n field={field}\n operator={operator}\n trigger={\n <ButtonGroupText\n render={<button type=\"button\" />}\n /* Named explicitly rather than by its contents: avatars or a\n \"+2\" badge, and \"plus two\" says nothing about two people. It\n grows to the whole list when the editor cannot be opened,\n since locked it must carry what a press no longer reveals. */\n aria-label={locked ? valueFullText : valueText}\n /* The pointer's route to the same thing, and only when there is\n more to say than the segment already says. */\n title={valueFullText === valueText ? undefined : valueFullText}\n className={cn(\n \"cursor-default bg-background hover:bg-accent dark:bg-input/30\",\n valueEmpty && \"text-muted-foreground\",\n )}\n onPointerDown={() => focusSegment(\"value\")}\n >\n {valueLabel}\n </ButtonGroupText>\n }\n />\n ) : null}\n\n <DropdownMenu\n open={menuOpen}\n onOpenChange={(next) => {\n if (next && locked) return;\n setMenuOpen(next);\n }}\n >\n <DropdownMenuTrigger\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n render={\n <Button\n variant=\"outline\"\n size={sizes.icon}\n /* The same surface the three text segments force. Styles whose\n outline button is transparent in dark (sera, luma, rhea) left\n the kebab as a notch in an otherwise filled pill. */\n className=\"bg-background dark:bg-input/30\"\n aria-label={actions.labels.chipMenu(field.label)}\n onPointerDown={() => focusSegment(\"menu\")}\n />\n }\n >\n <EllipsisVerticalIcon />\n </DropdownMenuTrigger>\n {/* The SAME sizing the builder's menus use, from one constant: a menu\n that cuts \"Convert to group\" in one chrome is one defect twice. */}\n <DropdownMenuContent align=\"end\" className={cn(FILTER_MENU_CLASS, actions.menuClassName)}>\n <FilterRuleMenuItems ruleId={rule.id} />\n </DropdownMenuContent>\n </DropdownMenu>\n </ButtonGroup>\n );\n}\n\nexport const FilterChip = React.memo(FilterChipImpl) as typeof FilterChipImpl;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqEA,MAAM,yBAAyD,CAAC;AAEhE,SAAS,oBACP,OACA,UACA,eACA,QAEA,kBAGA,cACQ;CACR,MAAM,aAAa,eACf,OAAO,oBACN,oBAAoB,OAAO;CAChC,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IACrD,OAAO;CAGT,IAAI,eAAe,QAAQ,MAAM,WAAW,MAAM,QAAQ,KAAK,GAAG;EAChE,MAAM,CAAC,MAAM,MAAM;EACnB,OAAO,OAAO,WAAW,OAAO,QAAQ,EAAE,GAAG,OAAO,MAAM,EAAE,CAAC;CAC/D;CAEA,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,MAAM,SAAS;EACf,IAAI,OAAO,WAAW,GAAG,OAAO;EAChC,IAAI,OAAO,WAAW,GACpB,OAAO,cAAc,OAAO,EAAE,CAAC,EAAE,SAAS,OAAO,OAAO,EAAE;EAE5D,OAAO,OAAO,WAAW,OAAO,MAAM;CACxC;CAEA,IAAI,OAAO,UAAU,WAAW,OAAO,QAAQ,SAAS;CAExD,OAAO,cAAc,OAAO,KAAK,CAAC,CAAC,EAAE,SAAS,OAAO,KAAK;AAC5D;;;;AAKA,SAAS,cACP,OACA,MACA,eACiB;CACjB,MAAM,SACJ,UAAU,KAAA,KAAa,UAAU,QAAQ,MAAM,QAAQ,KAAK,IACxD,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,IACvC,OAAO,MAAM,EAAE,IACf,OACF,OAAO,KAAK;C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,CACT;;EACH;;AAEjB;AAEA,MAAa,aAAaA,QAAM,KAAK,cAAc"}
|
|
1
|
+
{"version":3,"file":"filters-chip.js","names":["React"],"sources":["../../../../src/components/reui/filters/filters-chip.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n ArrowLeftRightIcon,\n ChevronRightIcon,\n CopyIcon,\n CornerDownRightIcon,\n EllipsisVerticalIcon,\n LayersIcon,\n SlidersHorizontalIcon,\n Trash2Icon,\n XIcon,\n} from \"lucide-react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { Button } from \"../../ui/button\";\nimport { ButtonGroup, ButtonGroupText } from \"../../ui/button-group\";\nimport {\n DropdownMenu,\n DropdownMenuContent,\n DropdownMenuItem,\n DropdownMenuTrigger,\n} from \"../../ui/dropdown-menu\";\nimport { Popover, PopoverContent, PopoverTrigger } from \"../../ui/popover\";\nimport { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from \"../../ui/tooltip\";\nimport {\n filterControlSizes,\n filterReadOnlyProps,\n isFilterLocked,\n useFilterActions,\n useFilterChipAutoOpen,\n useFilterChipFocused,\n useFilterFocusEmpty,\n useFilterFocusStore,\n useFilterRender,\n useFilterReorderable,\n} from \"./filters-context\";\nimport { FilterMenu, useFilterOptions, useFilterValueResolution } from \"./filters-editors\";\nimport {\n collapseFilterPath,\n FILTER_MENU_CLASS,\n FILTER_MENU_LABEL_CLASS,\n formatFilterPath,\n getFilterField,\n getFilterFieldChain,\n} from \"./filters-lib\";\nimport {\n coerceFilterValue,\n getFilterArity,\n getFilterOperator,\n operatorTakesValue,\n visibleFilterOperators,\n} from \"./filters-operators\";\nimport { findFilterNode, isFilterGroup } from \"./filters-query\";\nimport type {\n FilterEditorProps,\n FilterField,\n FilterGroupNode,\n FilterOperator,\n FilterRule,\n} from \"./filters-types\";\n\n/** Which part of the chip a pointer or key is aimed at. No `field`: the chip's\n * attribute segment is display only, and only the builder re-picks one. */\ntype ChipSegment = \"operator\" | \"value\" | \"menu\";\n\n/** The ref half of `autoFocusProps`: a CALLBACK ref, the one shape an editor\n * can spread onto any element without a cast, and a no-op here. */\nconst noopAutoFocusRef: React.RefCallback<HTMLElement> = () => {};\n\nfunction defaultValueDisplay<V>(\n value: V | undefined,\n operator: FilterOperator | undefined,\n resolveOption: (value: string) => { label: string } | undefined,\n labels: ReturnType<typeof useFilterActions>[\"labels\"],\n // The field's own word for \"no value yet\", which a generic label cannot beat.\n fieldPlaceholder?: string,\n /** Whether the value is PICKED rather than typed: a select's search prompt\n * and \"enter text...\" both give way to `labels.selectPlaceholder`. */\n optionBacked?: boolean,\n): string {\n const emptyLabel = optionBacked\n ? labels.selectPlaceholder\n : (fieldPlaceholder ?? labels.valuePlaceholder);\n if (value === undefined || value === null || value === \"\") {\n return emptyLabel;\n }\n\n if (getFilterArity(operator) === \"range\" && Array.isArray(value)) {\n const [from, to] = value as unknown[];\n return labels.valueRange(String(from ?? \"\"), String(to ?? \"\"));\n }\n\n if (Array.isArray(value)) {\n const values = value as string[];\n if (values.length === 0) return emptyLabel;\n if (values.length === 1) {\n return resolveOption(values[0])?.label ?? String(values[0]);\n }\n return labels.valueCount(values.length);\n }\n\n if (typeof value === \"boolean\") return value ? \"True\" : \"False\";\n\n return resolveOption(String(value))?.label ?? String(value);\n}\n\n/** The same display with the option's own icon in front. A status filter reads\n * as its colour before its word, so dropping the swatch the picker showed\n * makes the chip harder to scan than the list it came from. */\nfunction valueWithIcon<V>(\n value: V | undefined,\n text: string,\n resolveOption: (value: string) => { icon?: React.ReactNode } | undefined,\n): React.ReactNode {\n const single =\n value === undefined || value === null || Array.isArray(value)\n ? Array.isArray(value) && value.length === 1\n ? String(value[0])\n : null\n : String(value);\n const icon = single ? resolveOption(single)?.icon : null;\n if (!icon) return text;\n return (\n <span className=\"flex items-center gap-1.5\">\n {icon}\n {text}\n </span>\n );\n}\n\n/** The glyph between two ancestors in a nested attribute path, a chevron\n * because the `pathSeparator` string read as loud as the names it parts.\n * DECORATIVE: `aria-hidden`, and the plain string is still what\n * `formatFilterPath` joins for the chip's accessible name and `title`. */\nfunction FilterPathSeparator() {\n return (\n <ChevronRightIcon\n aria-hidden=\"true\"\n data-slot=\"filter-path-separator\"\n className=\"mx-[3px] inline-block size-3 shrink-0 self-center align-[calc(0.3635em-0.375rem)] text-muted-foreground\"\n />\n );\n}\n\n/** The elided run of a collapsed path, with the FULL path behind it. THE\n * TOOLTIP IS NOT THE ACCESSIBLE ROUTE: it is hover and focus, so the segment\n * is `aria-hidden` and the whole path stays in the control's NAME. The host's\n * own `title` is dropped while collapsed (`pathCollapsed`) or both fire. */\nfunction FilterPathEllipsis({ full }: { full: string }) {\n return (\n <TooltipProvider>\n <Tooltip>\n <TooltipTrigger\n render={\n <span\n aria-hidden=\"true\"\n data-slot=\"filter-path-ellipsis\"\n /* A path SEGMENT with no air of its own: the chevron's margin\n is all that parts a name from the next, and this used to STACK\n an `mx` on it. Plain inline, no `vertical-align`: `middle` sat\n the dots 1.7px low and inline-block grew the run to 21.17px. */\n className=\"shrink-0 self-center text-muted-foreground\"\n >\n ...\n </span>\n }\n />\n <TooltipContent>{full}</TooltipContent>\n </Tooltip>\n </TooltipProvider>\n );\n}\n\n/** Everything a rule needs in order to be READ, in either chrome. */\nexport interface FilterRuleDisplay {\n pathText: string;\n pathLabel: React.ReactNode;\n /** Whether `pathLabel` shows fewer names than the path has, so the cell's\n * own `title` can step aside for the ellipsis segment's tooltip. */\n pathCollapsed: boolean;\n operatorLabel: string;\n valueLabel: React.ReactNode;\n /** The same value as PLAIN TEXT, for an accessible name. Never scraped from\n * the `renderValue` node: whatever text survives inside avatars and a count\n * badge announces \"plus one\" for two people. Kept separate from\n * `valueLabel`, not derived from it: a React node has no honest text to\n * read back. A field whose values do not stringify supplies `valueText`\n * itself, or the built-in fallback says \"[object Object]\" to exactly the\n * audience the visible display is hiding it from. */\n valueText: string;\n /** The same value with any collapsed COUNT spelled out. \"3 selected\" cannot\n * be recovered from, which is fine while the editor opens and not once\n * locked, so the control carries this as `title` and, locked, as its name. */\n valueFullText: string;\n valueEmpty: boolean;\n}\n\n/** How one rule reads, resolved once and shared by both chromes, so a consumer\n * `renderValue`, the field's own and the built-in cannot disagree. */\nexport function useFilterRuleDisplay<V, O>(\n rule: FilterRule<V>,\n field: FilterField<V, O> | undefined,\n operator: FilterOperator | undefined,\n): FilterRuleDisplay {\n const actions = useFilterActions<V, O>();\n const render = useFilterRender<V, O>();\n // Lazily: a label needs no options until an editor actually opens.\n const optionsState = useFilterOptions<V, O>(field, false);\n\n const values =\n rule.value === undefined || rule.value === null\n ? []\n : Array.isArray(rule.value)\n ? (rule.value as unknown[])\n : [rule.value];\n\n // Saved views: values the loader has never returned are resolved through the\n // field's own `resolveValues`, so a restored chip reads \"John Doe\", not an id.\n useFilterValueResolution(field, values);\n\n const pathText = formatFilterPath(actions.index, rule.path, actions.labels.pathSeparator);\n\n const chain = getFilterFieldChain(actions.index, rule.path);\n // The CASCADER's collapser, from the actions context rather than per host, so\n // a deep path reads the same on a chip and in a builder row.\n const segments = collapseFilterPath(chain, {\n maxSegments: actions.maxPathSegments,\n collapse: actions.pathCollapse,\n });\n const pathCollapsed = segments.some((segment) => segment.type === \"ellipsis\");\n const pathLabel = chain.length\n ? segments.map((segment, index) => (\n <React.Fragment\n /* Positional, because a field id is unique among its SIBLINGS only:\n \"Company > Team > Company\" is a legal path and its two ids collide. */\n key={segment.type === \"field\" ? `${index}:${segment.field.id}` : `${index}:ellipsis`}\n >\n {index > 0 ? <FilterPathSeparator /> : null}\n {segment.type === \"field\" ? (\n <span>{segment.field.label}</span>\n ) : (\n <FilterPathEllipsis full={pathText} />\n )}\n </React.Fragment>\n ))\n : pathText;\n\n const operatorLabel = operator\n ? rule.negated\n ? actions.labels.negated(operator.label)\n : operator.label\n : rule.operator || actions.labels.selectCondition;\n\n const valueEmpty =\n rule.value === undefined ||\n rule.value === null ||\n rule.value === (\"\" as unknown as V) ||\n values.length === 0;\n\n if (!field) {\n return {\n pathText,\n pathLabel,\n pathCollapsed,\n operatorLabel,\n valueLabel: \"\",\n valueText: \"\",\n valueFullText: \"\",\n valueEmpty,\n };\n }\n\n const valueContext = {\n value: rule.value,\n values,\n field,\n operator: operator ?? { value: rule.operator, label: rule.operator },\n // Resolved, not empty: a custom display needs the option behind each value.\n options: values\n .map((entry) => optionsState.resolve(String(entry)))\n .filter(Boolean) as NonNullable<ReturnType<typeof optionsState.resolve>>[],\n labels: actions.labels,\n };\n\n // Computed even when a custom display replaces it: this is the string the\n // accessible name is built from. `field.valueText` overrides it.\n const valueText = field.valueText\n ? field.valueText(valueContext)\n : defaultValueDisplay(\n rule.value,\n operator,\n optionsState.resolve,\n actions.labels,\n field.placeholder,\n // Option-backed by the FIELD, not the operator: `is any of` is\n // multi-value on a plain text field too, and that one is typed into.\n field.type === \"select\" ||\n field.type === \"multiselect\" ||\n Boolean(field.options?.length) ||\n Boolean(field.loadOptions),\n );\n\n const valueLabel = render.renderValue\n ? render.renderValue(valueContext)\n : field.renderValue\n ? field.renderValue(valueContext)\n : valueWithIcon(rule.value, valueText, optionsState.resolve);\n\n // The list behind the count, or the same text again. Multi-value only: a\n // RANGE also stores an array but already spells both ends out (\"10 to 99\").\n const valueFullText =\n field.valueText ||\n !Array.isArray(rule.value) ||\n getFilterArity(operator) === \"range\" ||\n values.length < 2\n ? valueText\n : actions.labels.valueDetail(\n valueText,\n values.map((entry) => optionsState.resolve(String(entry))?.label ?? String(entry)),\n );\n\n return {\n pathText,\n pathLabel,\n pathCollapsed,\n operatorLabel,\n valueLabel,\n valueText,\n valueFullText,\n valueEmpty,\n };\n}\n\ninterface FilterValueEditorProps<V = unknown, O = unknown> {\n rule: FilterRule<V>;\n field: FilterField<V, O>;\n operator: FilterOperator;\n /** Whether the surface holding it is showing. Gates the option service. */\n open: boolean;\n onClose: () => void;\n}\n\n/** The value editor - draft, option service, commit - with NO surface of its\n * own, so surface and wiring can be replaced independently. The draft lives\n * here, so a text filter dispatches once on commit, not once per keystroke. */\nfunction FilterValueEditor<V, O>({\n rule,\n field,\n operator,\n open,\n onClose,\n}: FilterValueEditorProps<V, O>) {\n const actions = useFilterActions<V, O>();\n const [draft, setDraft] = React.useState<V | undefined>(rule.value);\n\n React.useEffect(() => {\n if (open) setDraft(rule.value);\n }, [open, rule.value]);\n\n const options = useFilterOptions<V, O>(field, open);\n // A LOOKUP, not a definition: every result is a module-level built-in or the\n // consumer's own component, so the editor is never remounted mid-edit.\n const editor = React.useMemo(\n () => actions.resolveEditor(field, operator),\n [actions, field, operator],\n );\n\n if (!editor) return null;\n\n const editorProps: FilterEditorProps<V, O> = {\n field,\n operator,\n value: draft,\n onValueChange: (next) => setDraft(next as V),\n host: \"amend\",\n autoFocusProps: {\n ref: noopAutoFocusRef,\n autoFocus: true,\n },\n commit: (next, commitOptions) => {\n actions.updateRule(rule.id, {\n value: (next === undefined ? draft : next) as V,\n });\n // A multi-select commits per toggle and asks to stay put; others dismiss.\n if (commitOptions?.close === false) return;\n onClose();\n },\n cancel: onClose,\n // The same as cancel, honestly: `back` means something only to a `create`\n // host.\n back: onClose,\n options,\n labels: actions.labels,\n };\n\n // `createElement` rather than JSX: the component comes out of a lookup, so\n // `<Editor />` trips `react-hooks/static-components`. The fragment keeps the\n // props object, which carries a ref, from looking like a ref read in render.\n return <>{React.createElement(editor, editorProps)}</>;\n}\n\n/** One step of the flow, released when the panel that owes it has LEFT THE\n * DOM: both popovers keep portal content mounted through the exit transition,\n * so this unmount IS that moment and nothing is timed. `onRelease` is used AS\n * the cleanup, so an unmemoized callback fires its step early. */\nfunction FilterStepHandoff({ onRelease }: { onRelease: () => void }) {\n React.useEffect(() => onRelease, [onRelease]);\n return null;\n}\n\n/** The value host: the editor in a popover anchored to the value segment, and\n * BOTH routes end here. The operator popover used to draw the editor itself,\n * so a handed-off panel sat a segment's width left of a second press. */\nexport interface FilterValuePopoverProps<V = unknown, O = unknown> {\n rule: FilterRule<V>;\n field: FilterField<V, O>;\n operator: FilterOperator | undefined;\n /** The element that opens it, WITH its own children: a chip segment must be\n * a direct child of its `ButtonGroup` for the pill to fuse. */\n trigger: React.ReactElement;\n className?: string;\n}\n\nexport function FilterValuePopover<V, O>({\n rule,\n field,\n operator,\n trigger,\n className,\n}: FilterValuePopoverProps<V, O>) {\n const actions = useFilterActions<V, O>();\n const focusStore = useFilterFocusStore();\n const autoOpen = useFilterChipAutoOpen(rule.id) === \"value\";\n const [open, setOpen] = React.useState(false);\n const locked = isFilterLocked(actions);\n\n // The last step of the flow as well as the amend route; by now the condition\n // menu has UNMOUNTED (see `FilterStepHandoff`). CONSUMED as it is honoured,\n // or Escape closes the editor and this effect reopens it in the same frame.\n // The `set` stays OUTSIDE the `locked` guard on purpose: a handoff nobody\n // spends sits armed until some later chip spends it, and a chip that opened\n // because a DIFFERENT chip was arrowed onto is worse than one that opened\n // nothing.\n React.useEffect(() => {\n if (!autoOpen || open) return;\n if (!locked) setOpen(true);\n focusStore.set({ id: rule.id, segment: \"value\", autoOpen: false });\n }, [autoOpen, open, focusStore, rule.id, locked]);\n\n // Nothing to open, but the trigger still renders so the value keeps its\n // place, and it wears the bar's state: that hangs on the TRIGGER below,\n // which this path never reaches, so the segment used to look live.\n if (!operator || !actions.resolveEditor(field, operator)) {\n return React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n disabled: actions.disabled,\n ...filterReadOnlyProps(actions),\n });\n }\n\n return (\n // REFUSES to open while locked rather than leaving it to the trigger: an\n // `aria-disabled` control that still opens an editor is one that lied.\n <Popover\n open={open}\n onOpenChange={(next) => {\n if (next && locked) return;\n setOpen(next);\n }}\n >\n {/* The trigger IS the segment, never a wrapper. `ButtonGroup` fuses\n DIRECT children only (`*:data-slot:rounded-r-none`,\n `[&>[data-slot]~[data-slot]]:border-l-0`), so a nested one keeps its\n own border and the chip reads as separate badges. */}\n <PopoverTrigger\n render={trigger}\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n />\n <PopoverContent align=\"start\" className={cn(\"w-auto p-0\", className)}>\n <FilterValueEditor<V, O>\n rule={rule}\n field={field}\n operator={operator}\n open={open}\n onClose={() => {\n setOpen(false);\n focusStore.set({ id: rule.id, segment: \"value\", autoOpen: false });\n }}\n />\n </PopoverContent>\n </Popover>\n );\n}\n\n/* A chip's ATTRIBUTE is fixed once the chip exists: no field popover here. A\n new field invalidates the operator and the value, so \"amending\" threw both\n away. The builder keeps its picker, where a row reads as a form. */\n\n/** The condition menu, and the step after it. The list is the cascader run\n * flat: the old hand-rolled one marked the keyboard HIGHLIGHT with\n * `aria-selected` and had no Home, End or typeahead. It HANDS OFF to the\n * value popover once its own panel has left the DOM; advancing in place\n * anchored the editor to the CONDITION segment and doubled up in the row. */\nexport interface FilterOperatorPopoverProps<V = unknown, O = unknown> {\n rule: FilterRule<V>;\n field: FilterField<V, O>;\n trigger: React.ReactElement;\n className?: string;\n}\n\nexport function FilterOperatorPopover<V, O>({\n rule,\n field,\n trigger,\n className,\n}: FilterOperatorPopoverProps<V, O>) {\n const actions = useFilterActions<V, O>();\n const focusStore = useFilterFocusStore();\n const autoOpen = useFilterChipAutoOpen(rule.id) === \"operator\";\n const [open, setOpen] = React.useState(false);\n const locked = isFilterLocked(actions);\n /** Whether the close this panel is going through IS the step being handed\n * on. A ref, so it survives the render that closes the popover. Every OPEN\n * clears it, so an Escape or an outside press finds it already lowered and\n * spends nothing; `release` leaves it standing because one twin asks again\n * later: Radix reads it from `onCloseAutoFocus`, a macrotask after the\n * unmount. Clearing it in `release` would break that twin only. */\n const handoff = React.useRef(false);\n const operators = actions.resolveOperators(field);\n\n // Memoized because the array IS the menu's identity: the cascader rebuilds\n // its index per `items` identity, so a fresh array rebuilds it per keystroke.\n const items = React.useMemo(\n () =>\n visibleFilterOperators(operators).map((entry) => ({\n value: entry.value,\n label: entry.label,\n })),\n [operators],\n );\n\n // Opened by the root the moment the chip is created. CONSUMED here, or the\n // handoff re-opens the menu on the frame Escape closes it. Consumed even\n // while locked, for the reason on the value popover's copy.\n React.useEffect(() => {\n if (!autoOpen || open) return;\n handoff.current = false;\n if (!locked) setOpen(true);\n focusStore.set({ id: rule.id, segment: \"operator\", autoOpen: false });\n }, [autoOpen, open, focusStore, rule.id, locked]);\n\n const close = () => {\n handoff.current = false;\n setOpen(false);\n focusStore.set({ id: rule.id, segment: \"operator\", autoOpen: false });\n };\n\n /** The parked step, spent on the frame this panel stops existing. Memoized\n * on nothing that changes, and load bearing: `FilterStepHandoff` uses this\n * AS its cleanup, so a new identity mid-flow fires the step too early. */\n const release = React.useCallback(() => {\n if (!handoff.current) return;\n focusStore.set({ id: rule.id, segment: \"value\", autoOpen: true });\n }, [focusStore, rule.id]);\n\n // The chip going away takes its step with it: React destroys a deleted\n // subtree top down, so this runs before the panel's own cleanup.\n React.useEffect(\n () => () => {\n handoff.current = false;\n },\n [],\n );\n\n return (\n <Popover\n open={open}\n onOpenChange={(next) => {\n if (next && locked) return;\n /* Escape, an outside press, a second press: none is the step being\n taken, so none may spend it. RETIRED ON OPEN, not on close, and that\n is a twin difference: in Radix an item choice dismisses through here\n too, so retiring on close wiped the request before the unmount. */\n if (next) handoff.current = false;\n setOpen(next);\n }}\n >\n <PopoverTrigger\n render={trigger}\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n />\n <PopoverContent\n align=\"start\"\n /* Base UI restores focus to the trigger as this panel closes, which\n lands on the condition segment AFTER the value editor has opened and\n focused its input, so a keyboard user is dropped back a step and\n cannot reach the value at all. Suppressed only while the handoff is\n up; a function because Base UI resolves it at close time, which is\n when the ref is accurate. Radix runs the same guard through\n `onCloseAutoFocus`. */\n finalFocus={() => !handoff.current}\n /* `w-auto` with a FLOOR: a catalog sizes to its longest label, and a\n boolean field's \"is\" and \"is not\" would read as a scrap of paper. */\n className={cn(\"w-auto min-w-40 p-0\", className)}\n >\n {/* INSIDE the panel deliberately: only a child of the content is\n unmounted by the exit transition rather than by the close. */}\n <FilterStepHandoff onRelease={release} />\n <FilterMenu\n items={items}\n selected={rule.operator ? [rule.operator] : []}\n onSelectionChange={(values) => {\n const value = values[0];\n /* Deselecting the committed operator is a step back rather than a\n choice, so pressing the current row simply closes. */\n if (value === undefined) {\n close();\n return;\n }\n const chosen = getFilterOperator(operators, value);\n /* BUILDING versus AMENDING, the same fork the advanced row draws\n at its field step. A rule reaches this menu with no operator\n exactly once, while it is being added, and only then is the\n value the step after this one. Re-picking the condition on a\n rule that already has one is an edit of that one cell: it\n commits and closes, and the user opens the value themselves. */\n const building = !rule.operator;\n actions.updateRule(rule.id, {\n operator: value,\n /* The value moves with the operator: \"is\" to \"is any of\" would\n leave a bare string where every reader expects an array. */\n value: coerceFilterValue(\n rule.value,\n getFilterOperator(operators, rule.operator),\n chosen,\n ) as V,\n });\n if (building && operatorTakesValue(chosen)) {\n /* PARKED, not opened: `release` hands the row to its value\n surface once this panel has unmounted. */\n handoff.current = true;\n setOpen(false);\n return;\n }\n close();\n }}\n labels={actions.labels}\n ariaLabel={field.label}\n searchPlaceholder={actions.labels.searchOperators}\n /* No visible search field: a CLOSED enum of six to ten labels, all\n on screen. Still RENDERED, visually hidden, because it owns focus\n and `aria-activedescendant`: arrows, Home, End and typeahead. */\n searchable={false}\n /* Taller than a value list on purpose: the operator set is CLOSED, so\n all of it fits and the height buys the whole catalog. A value list\n is open ended and would only push its own footer off the screen. */\n maxHeight={320}\n /* Deliberately unpinned: one selected operator in a short list, so\n lifting it would lose the catalog's declared reading order. */\n />\n </PopoverContent>\n </Popover>\n );\n}\n\n/** The keyboard path to a CROSS-GROUP move: Alt+Arrow reorders within the\n * owning group only and Wrap creates a NEW group, so the drag layer's\n * cross-group move had no keyboard parity. Numbered in document order. */\nexport function FilterMoveToMenuItems({ nodeId }: { nodeId: string }) {\n const actions = useFilterActions();\n // A menu ITEM takes the native word: both twins already make `disabled`\n // roving-focusable and `aria-disabled`.\n const reorderable = useFilterReorderable();\n const locked = isFilterLocked(actions);\n // Read at render time: the menu's content mounts when the menu opens, so\n // this is the tree the user is looking at.\n const query = actions.getQuery();\n const found = findFilterNode(query, nodeId);\n if (!found?.parent) return null;\n\n const destinations: { id: string; label: string; size: number }[] = [];\n if (found.parent.id !== query.id) {\n destinations.push({\n id: query.id,\n label: actions.labels.moveToTopLevel,\n size: query.rules.length,\n });\n }\n\n let position = 0;\n // `inside` suppresses the PUSH and not the walk, so the numbering stays\n // document order rather than renumbering every group after this one. Counted\n // before the exclusions for the same reason: the current parent is not\n // offered but still holds its number, so the numbering is stable whichever\n // row's menu is open.\n const visit = (group: FilterGroupNode<unknown>, inside: boolean) => {\n for (const child of group.rules) {\n if (!isFilterGroup(child)) continue;\n position += 1;\n // Itself and everything under it: `moveFilterNodeTo` already refuses that\n // move - it would detach the subtree and leave a cycle - so offering it\n // would be a menu row that quietly does nothing.\n const within = inside || child.id === nodeId;\n if (!within && child.id !== found.parent!.id) {\n destinations.push({\n id: child.id,\n label: actions.labels.moveToGroup(position),\n size: child.rules.length,\n });\n }\n visit(child, within);\n }\n };\n visit(query, false);\n\n if (destinations.length === 0) return null;\n\n // The THIRD route into a move, gated on the same switch as the grip and\n // Alt+Arrow: ungated, a builder that draws no handle still reordered here.\n if (!reorderable) return null;\n\n return (\n <>\n {destinations.map((destination) => (\n <DropdownMenuItem\n key={destination.id}\n disabled={locked}\n onClick={() => actions.moveNodeTo(nodeId, destination.id, destination.size)}\n >\n {/* A bend into the destination: movement, not duplication or nesting. */}\n <CornerDownRightIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{destination.label}</span>\n </DropdownMenuItem>\n ))}\n </>\n );\n}\n\n/** The per-rule actions, without the trigger: the chip's kebab and a builder\n * row's kebab act on the same rule. `allowGrouping` is the CHROME's answer;\n * \"Convert to advanced filter\" is the CONSUMER's, and hides itself there. */\nexport function FilterRuleMenuItems({\n ruleId,\n /** Offer \"Wrap in condition group\". Off for the chip row, which cannot draw\n * a group; on in the builder, the only way to nest without dragging. */\n allowGrouping = false,\n}: {\n ruleId: string;\n allowGrouping?: boolean;\n}) {\n const actions = useFilterActions();\n // Gated here as well as at the trigger, because this is EXPORTED: a consumer\n // composing their own menu gets rows that say they are unavailable.\n const locked = isFilterLocked(actions);\n return (\n /* Every row leads with an icon. `IconPlaceholder` because the source ships\n under five icon sets; no size class, because each style already sizes an\n unsized svg in a menu row; `aria-hidden`, the label IS the name. */\n <>\n <DropdownMenuItem disabled={locked} onClick={() => actions.duplicateNode(ruleId)}>\n <CopyIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.duplicate}</span>\n </DropdownMenuItem>\n <DropdownMenuItem disabled={locked} onClick={() => actions.negateRule(ruleId)}>\n {/* Two arrows swapping: negation flips to the declared inverse. */}\n <ArrowLeftRightIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.negate}</span>\n </DropdownMenuItem>\n {allowGrouping ? (\n <DropdownMenuItem disabled={locked} onClick={() => actions.wrapNodeInGroup(ruleId)}>\n {/* Layers: braces read as grouping in only three of the five sets. */}\n <LayersIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.wrapInGroup}</span>\n </DropdownMenuItem>\n ) : null}\n {allowGrouping ? <FilterMoveToMenuItems nodeId={ruleId} /> : null}\n {/* OPTIONAL, and gated on both halves of \"would this do anything\": the\n handler is the consumer's opt-in, and an already-advanced bar has\n nothing to convert. NOT gated on `locked`: it changes no query, is\n handed no mutator, and the shipped kebab will not open while locked. */}\n {actions.convertToAdvanced && actions.variant !== \"advanced\" ? (\n <DropdownMenuItem onClick={() => actions.convertToAdvanced?.()}>\n {/* Sliders: the one \"advanced settings\" glyph in all five sets. */}\n <SlidersHorizontalIcon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.convertToAdvanced}</span>\n </DropdownMenuItem>\n ) : null}\n <DropdownMenuItem\n variant=\"destructive\"\n disabled={locked}\n onClick={() => actions.removeNode(ruleId)}\n >\n {/* No colour: the destructive variant already paints the row's svgs. */}\n <Trash2Icon aria-hidden=\"true\" />\n <span className={FILTER_MENU_LABEL_CLASS}>{actions.labels.remove}</span>\n </DropdownMenuItem>\n </>\n );\n}\n\nexport interface FilterChipProps<V = unknown> {\n rule: FilterRule<V>;\n index: number;\n}\n\n/** One filter, as a chip. Memoization means something here: the actions\n * context is stable, the focus store is subscribed to a boolean and the query\n * shares structure, so editing one filter of forty re-renders one chip. */\nfunction FilterChipImpl<V, O>({ rule, index }: FilterChipProps<V>) {\n const actions = useFilterActions<V, O>();\n const render = useFilterRender<V, O>();\n const focusStore = useFilterFocusStore();\n const focused = useFilterChipFocused(rule.id);\n const noFocus = useFilterFocusEmpty();\n const locked = isFilterLocked(actions);\n // THE CHIP'S HEIGHT, by way of the one button in it that has one:\n // `ButtonGroup` is `items-stretch` and no style gives a text segment a\n // height, so the kebab's rung is the pill's. The RADIUS survives because\n // every style whose `icon-sm` rounds differently re-pins it in a group.\n const sizes = filterControlSizes(actions);\n // The kebab is CONTROLLED so it can refuse to open: every mutating row\n // behind it is gated. That puts \"Convert to advanced filter\" out of reach\n // while locked; a consumer-composed menu still draws it.\n const [menuOpen, setMenuOpen] = React.useState(false);\n // Exactly one chip is in the tab order at a time. Before anything has been\n // focused that is the first chip, so Tab reaches the row in one press.\n const isTabStop = focused || (noFocus && index === 0);\n\n const field = getFilterField(actions.index, rule.path);\n const operators = field ? actions.resolveOperators(field) : [];\n const operator = getFilterOperator(operators, rule.operator);\n\n const {\n pathText,\n pathLabel,\n pathCollapsed,\n operatorLabel,\n valueLabel,\n valueText,\n valueFullText,\n valueEmpty,\n } = useFilterRuleDisplay<V, O>(rule, field, operator);\n\n if (!field) {\n // A rule pointing at a field the schema no longer has. Dropping it loses a\n // saved view's data; rendering nothing leaves an invisible condition still\n // filtering. It carries the SAME roving wiring as a real chip: `data-slot`\n // alone joined the arrow-key query with no `tabIndex` to land on.\n return (\n <ButtonGroup\n data-slot=\"filter-chip\"\n data-unknown=\"\"\n role=\"group\"\n aria-label={actions.labels.filterLabel(rule.path.join(actions.labels.pathSeparator))}\n data-focused={focused || undefined}\n data-rule-id={rule.id}\n data-index={index}\n tabIndex={isTabStop ? 0 : -1}\n onFocusCapture={() => {\n if (!focused) focusStore.set({ id: rule.id, segment: null, autoOpen: false });\n }}\n >\n <ButtonGroupText className=\"bg-background text-muted-foreground dark:bg-input/30\">\n {rule.path.join(actions.labels.pathSeparator)}\n </ButtonGroupText>\n <Button\n variant=\"outline\"\n size={sizes.icon}\n className=\"bg-background dark:bg-input/30\"\n aria-label={actions.labels.remove}\n /* It had no gate at all, so the one chip whose whole purpose is to be\n removed could be removed from a bar that refuses every other edit. */\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n onClick={() => actions.removeNode(rule.id)}\n >\n <XIcon />\n </Button>\n </ButtonGroup>\n );\n }\n\n if (render.renderChip) return <>{render.renderChip(rule)}</>;\n\n const focusSegment = (segment: ChipSegment) =>\n focusStore.set({ id: rule.id, segment, autoOpen: false });\n\n // A rule with no condition yet, KEPT rather than removed (see\n // `isFilterRuleComplete`), so it has to read as unfinished. Through WORDS:\n // the dashed outline it replaces degraded to an underline under sera.\n const incomplete = !rule.operator;\n\n // The same test the value segment renders under, so the name matches the\n // chip: `valueText` alone appended a placeholder to valueless conditions.\n const hasValue = Boolean(rule.operator) && operatorTakesValue(operator);\n\n // The value's spoken form in the chip's NAME: a name is not a prompt, so\n // \"Description contains enter text...\" becomes \"no value\".\n const valueName = valueEmpty && !field.valueText ? actions.labels.noValue : valueText;\n\n return (\n <ButtonGroup\n data-slot=\"filter-chip\"\n role=\"group\"\n aria-label={actions.labels.filterLabel(\n `${pathText} ${operatorLabel}${hasValue ? ` ${valueName}` : \"\"}`.trim() +\n (incomplete ? `, ${actions.labels.incomplete}` : \"\"),\n )}\n data-focused={focused || undefined}\n data-incomplete={incomplete || undefined}\n data-rule-id={rule.id}\n tabIndex={isTabStop ? 0 : -1}\n className={cn(\n /* Sera is an underline style, so the boxed segments are normalised to\n its bottom-border-only look or the chip reads as a mix of both. */\n \"\",\n )}\n onFocusCapture={() => {\n if (!focused) focusStore.set({ id: rule.id, segment: null, autoOpen: false });\n }}\n data-index={index}\n >\n {/* DISPLAY ONLY: a div, not a button, not a tab stop, no popover. The\n attribute is fixed for the life of the chip. */}\n <ButtonGroupText\n /* Dropped while the path is collapsed: the ellipsis inside carries the\n same sentence as a tooltip, and the two would stack. */\n title={pathCollapsed ? undefined : pathText}\n className=\"cursor-default gap-1.5 bg-background dark:bg-input/30\"\n >\n {field.icon}\n {/* Zero gap INSIDE the path, so the separator's own margin is the only\n air around a chevron; `gap-1.5` used to stack 6px a side on it. */}\n <span className=\"flex items-center\">{pathLabel}</span>\n </ButtonGroupText>\n\n <FilterOperatorPopover\n rule={rule}\n field={field}\n trigger={\n <ButtonGroupText\n render={<button type=\"button\" />}\n className={cn(\n \"cursor-default bg-background hover:bg-accent dark:bg-input/30\",\n /* The operator is connective tissue between the field and the\n value, so it reads quieter than either - unless it is still\n the prompt \"Select condition\", the one thing to act on. */\n incomplete ? \"text-foreground\" : \"text-muted-foreground\",\n )}\n onPointerDown={() => focusSegment(\"operator\")}\n >\n {operatorLabel}\n </ButtonGroupText>\n }\n />\n\n {/* No condition, no value: `getFilterArity(undefined)` defaults to \"one\",\n so testing the operator alone renders a stray value segment. */}\n {hasValue ? (\n <FilterValuePopover\n rule={rule}\n field={field}\n operator={operator}\n trigger={\n <ButtonGroupText\n render={<button type=\"button\" />}\n /* Named explicitly rather than by its contents: avatars or a\n \"+2\" badge, and \"plus two\" says nothing about two people. It\n grows to the whole list when the editor cannot be opened,\n since locked it must carry what a press no longer reveals. */\n aria-label={locked ? valueFullText : valueText}\n /* The pointer's route to the same thing, and only when there is\n more to say than the segment already says. */\n title={valueFullText === valueText ? undefined : valueFullText}\n className={cn(\n \"cursor-default bg-background hover:bg-accent dark:bg-input/30\",\n valueEmpty && \"text-muted-foreground\",\n )}\n onPointerDown={() => focusSegment(\"value\")}\n >\n {valueLabel}\n </ButtonGroupText>\n }\n />\n ) : null}\n\n <DropdownMenu\n open={menuOpen}\n onOpenChange={(next) => {\n if (next && locked) return;\n setMenuOpen(next);\n }}\n >\n <DropdownMenuTrigger\n disabled={actions.disabled}\n {...filterReadOnlyProps(actions)}\n render={\n <Button\n variant=\"outline\"\n size={sizes.icon}\n /* The same surface the three text segments force. Styles whose\n outline button is transparent in dark (sera, luma, rhea) left\n the kebab as a notch in an otherwise filled pill. */\n className=\"bg-background dark:bg-input/30\"\n aria-label={actions.labels.chipMenu(field.label)}\n onPointerDown={() => focusSegment(\"menu\")}\n />\n }\n >\n <EllipsisVerticalIcon />\n </DropdownMenuTrigger>\n {/* The SAME sizing the builder's menus use, from one constant: a menu\n that cuts \"Convert to group\" in one chrome is one defect twice. */}\n <DropdownMenuContent align=\"end\" className={cn(FILTER_MENU_CLASS, actions.menuClassName)}>\n <FilterRuleMenuItems ruleId={rule.id} />\n </DropdownMenuContent>\n </DropdownMenu>\n </ButtonGroup>\n );\n}\n\nexport const FilterChip = React.memo(FilterChipImpl) as typeof FilterChipImpl;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAqEA,MAAM,yBAAyD,CAAC;AAEhE,SAAS,oBACP,OACA,UACA,eACA,QAEA,kBAGA,cACQ;CACR,MAAM,aAAa,eACf,OAAO,oBACN,oBAAoB,OAAO;CAChC,IAAI,UAAU,KAAA,KAAa,UAAU,QAAQ,UAAU,IACrD,OAAO;CAGT,IAAI,eAAe,QAAQ,MAAM,WAAW,MAAM,QAAQ,KAAK,GAAG;EAChE,MAAM,CAAC,MAAM,MAAM;EACnB,OAAO,OAAO,WAAW,OAAO,QAAQ,EAAE,GAAG,OAAO,MAAM,EAAE,CAAC;CAC/D;CAEA,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,MAAM,SAAS;EACf,IAAI,OAAO,WAAW,GAAG,OAAO;EAChC,IAAI,OAAO,WAAW,GACpB,OAAO,cAAc,OAAO,EAAE,CAAC,EAAE,SAAS,OAAO,OAAO,EAAE;EAE5D,OA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OAAO;KAC/B,QACE,oBAAC,QAAD;MACE,SAAQ;MACR,MAAM,MAAM;MAIZ,WAAU;MACV,cAAY,QAAQ,OAAO,SAAS,MAAM,KAAK;MAC/C,qBAAqB,aAAa,MAAM;KACzC,CAAA;KAGH,UAAA,oBAAC,sBAAD,CAAuB,CAAA;IACJ,CAAA,GAGrB,oBAAC,qBAAD;KAAqB,OAAM;KAAM,WAAW,GAAG,mBAAmB,QAAQ,aAAa;KACrF,UAAA,oBAAC,qBAAD,EAAqB,QAAQ,KAAK,GAAK,CAAA;IACpB,CAAA,CACT;;EACH;;AAEjB;AAEA,MAAa,aAAaA,QAAM,KAAK,cAAc"}
|
|
@@ -3,10 +3,10 @@ import { Button } from "../../ui/button.js";
|
|
|
3
3
|
import { Input } from "../../ui/input.js";
|
|
4
4
|
import { ButtonGroup } from "../../ui/button-group.js";
|
|
5
5
|
import { useCascaderActions, useCascaderHighlight } from "../cascader/cascader-context.js";
|
|
6
|
-
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
7
6
|
import { CascaderItems } from "../cascader/cascader-item.js";
|
|
8
7
|
import { CascaderFooter } from "../cascader/cascader-footer.js";
|
|
9
8
|
import { CascaderInput, CascaderNav } from "../cascader/cascader-nav.js";
|
|
9
|
+
import { Cascader, CascaderEmpty, CascaderList, CascaderPanel, CascaderStatus } from "../cascader/cascader.js";
|
|
10
10
|
import { FilterActionsContext, filterControlSizes } from "./filters-context.js";
|
|
11
11
|
import { applyFilterExclusiveSelection, filterFilterOptions, joinFilterPath, normalizeFilterQuery, warnFilterOnce } from "./filters-lib.js";
|
|
12
12
|
import * as React$1 from "react";
|
|
@@ -566,7 +566,7 @@ function FilterMenu({ items, selected, multiple = false, onSelectionChange, labe
|
|
|
566
566
|
}) : null,
|
|
567
567
|
itemState.selected ? /* @__PURE__ */ jsx("span", {
|
|
568
568
|
"data-slot": "filter-menu-check",
|
|
569
|
-
className: "pointer-events-none absolute end-
|
|
569
|
+
className: "pointer-events-none absolute end-(--cascader-row-inset,8px)! flex size-4 items-center justify-center rtl:right-auto!",
|
|
570
570
|
children: /* @__PURE__ */ jsx(CheckIcon, { className: "text-foreground! **:text-foreground!" })
|
|
571
571
|
}) : null
|
|
572
572
|
] }), [labels.exclusiveHint]),
|