@fanvue/ui 3.31.0 → 3.32.0

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.
Files changed (46) hide show
  1. package/dist/cjs/components/ChatInput/ChatInput.cjs +6 -5
  2. package/dist/cjs/components/ChatInput/ChatInput.cjs.map +1 -1
  3. package/dist/cjs/components/DropdownMenu/DropdownMenuHeader.cjs +190 -0
  4. package/dist/cjs/components/DropdownMenu/DropdownMenuHeader.cjs.map +1 -0
  5. package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs +213 -0
  6. package/dist/cjs/components/DropdownMenu/DropdownMenuItem.cjs.map +1 -0
  7. package/dist/cjs/components/DropdownMenu/DropdownMenuReorderGroup.cjs +438 -0
  8. package/dist/cjs/components/DropdownMenu/DropdownMenuReorderGroup.cjs.map +1 -0
  9. package/dist/cjs/components/DropdownMenu/DropdownMenuReorderItem.cjs +197 -0
  10. package/dist/cjs/components/DropdownMenu/DropdownMenuReorderItem.cjs.map +1 -0
  11. package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs +221 -0
  12. package/dist/cjs/components/DropdownMenu/DropdownMenuRoot.cjs.map +1 -0
  13. package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs +128 -0
  14. package/dist/cjs/components/DropdownMenu/DropdownMenuSelectionItems.cjs.map +1 -0
  15. package/dist/cjs/components/DropdownMenu/context.cjs +26 -0
  16. package/dist/cjs/components/DropdownMenu/context.cjs.map +1 -0
  17. package/dist/cjs/components/DropdownMenu/reorderShared.cjs +38 -0
  18. package/dist/cjs/components/DropdownMenu/reorderShared.cjs.map +1 -0
  19. package/dist/cjs/index.cjs +19 -12
  20. package/dist/cjs/index.cjs.map +1 -1
  21. package/dist/components/ChatInput/ChatInput.mjs +2 -1
  22. package/dist/components/ChatInput/ChatInput.mjs.map +1 -1
  23. package/dist/components/DropdownMenu/DropdownMenuHeader.mjs +173 -0
  24. package/dist/components/DropdownMenu/DropdownMenuHeader.mjs.map +1 -0
  25. package/dist/components/DropdownMenu/DropdownMenuItem.mjs +195 -0
  26. package/dist/components/DropdownMenu/DropdownMenuItem.mjs.map +1 -0
  27. package/dist/components/DropdownMenu/DropdownMenuReorderGroup.mjs +421 -0
  28. package/dist/components/DropdownMenu/DropdownMenuReorderGroup.mjs.map +1 -0
  29. package/dist/components/DropdownMenu/DropdownMenuReorderItem.mjs +180 -0
  30. package/dist/components/DropdownMenu/DropdownMenuReorderItem.mjs.map +1 -0
  31. package/dist/components/DropdownMenu/DropdownMenuRoot.mjs +203 -0
  32. package/dist/components/DropdownMenu/DropdownMenuRoot.mjs.map +1 -0
  33. package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs +110 -0
  34. package/dist/components/DropdownMenu/DropdownMenuSelectionItems.mjs.map +1 -0
  35. package/dist/components/DropdownMenu/context.mjs +9 -0
  36. package/dist/components/DropdownMenu/context.mjs.map +1 -0
  37. package/dist/components/DropdownMenu/reorderShared.mjs +21 -0
  38. package/dist/components/DropdownMenu/reorderShared.mjs.map +1 -0
  39. package/dist/index.d.ts +121 -1
  40. package/dist/index.mjs +8 -1
  41. package/dist/index.mjs.map +1 -1
  42. package/package.json +3 -2
  43. package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs +0 -598
  44. package/dist/cjs/components/DropdownMenu/DropdownMenu.cjs.map +0 -1
  45. package/dist/components/DropdownMenu/DropdownMenu.mjs +0 -580
  46. package/dist/components/DropdownMenu/DropdownMenu.mjs.map +0 -1
@@ -0,0 +1,195 @@
1
+ "use client";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
4
+ import { Slot } from "@radix-ui/react-slot";
5
+ import * as React from "react";
6
+ import { cn } from "../../utils/cn.mjs";
7
+ import { CheckIcon } from "../Icons/CheckIcon.mjs";
8
+ import { DropdownMenuVariantContext, ToggleOpenContext } from "./context.mjs";
9
+ const DropdownMenuLabel = React.forwardRef(({ className, position = "default", ...props }, ref) => {
10
+ const variant = React.useContext(DropdownMenuVariantContext);
11
+ const labelClassName = cn(
12
+ "typography-description-12px-regular flex items-center px-3 text-content-secondary",
13
+ position === "top" ? "py-2" : "pt-4 pb-2",
14
+ className
15
+ );
16
+ if (variant === "sheet") {
17
+ return /* @__PURE__ */ jsx("div", { ref, className: labelClassName, ...props });
18
+ }
19
+ return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Label, { ref, className: labelClassName, ...props });
20
+ });
21
+ DropdownMenuLabel.displayName = "DropdownMenuLabel";
22
+ const SIZE_NORMALIZED = {
23
+ "40": "40",
24
+ md: "40",
25
+ "32": "32",
26
+ sm: "32"
27
+ };
28
+ const ITEM_SIZE_CLASSES = {
29
+ "40": "min-h-10 py-2 typography-body-default-16px-regular",
30
+ "32": "min-h-8 py-[7px] typography-body-small-14px-regular"
31
+ };
32
+ const ITEM_COUNT_TYPOGRAPHY = {
33
+ "40": "typography-body-small-14px-regular",
34
+ "32": "typography-body-small-14px-regular"
35
+ };
36
+ function SelectedCheckIndicator({ hasDescription }) {
37
+ return /* @__PURE__ */ jsx(
38
+ CheckIcon,
39
+ {
40
+ className: cn(
41
+ "size-4 shrink-0 text-content-primary",
42
+ // The two-line layout switches the row to `items-start`, which would hang
43
+ // the tick off the title's line. A leading icon or avatar belongs there —
44
+ // it labels the title — but the tick is a property of the whole row, so it
45
+ // centres against both lines. {@link SelectItem} already does this.
46
+ hasDescription && "self-center"
47
+ )
48
+ }
49
+ );
50
+ }
51
+ const DropdownMenuItem = React.forwardRef(
52
+ ({
53
+ size = "40",
54
+ destructive,
55
+ leadingIcon,
56
+ avatar,
57
+ trailingIcon,
58
+ count,
59
+ description,
60
+ selected,
61
+ className,
62
+ children,
63
+ asChild,
64
+ onSelect,
65
+ disabled,
66
+ ...props
67
+ }, ref) => {
68
+ const variant = React.useContext(DropdownMenuVariantContext);
69
+ const toggleOpen = React.useContext(ToggleOpenContext);
70
+ const normalizedSize = SIZE_NORMALIZED[size];
71
+ const hasDescription = description != null;
72
+ const hasAvatar = avatar != null;
73
+ const itemClassName = cn(
74
+ // `text-start` because the sheet variant renders the row as a <button>,
75
+ // whose UA-centred text misaligned it from the popper variant's rows.
76
+ "group flex w-full cursor-pointer gap-2 rounded-sm px-3 text-start outline-none",
77
+ hasDescription ? "items-start" : "items-center",
78
+ // The sheet's header runs the full width of the panel, so its rows have to
79
+ // come in off the edge themselves — 12px here on the panel's own 4px is the
80
+ // design's 16px. `w-auto` lets the column stretch them to the space left
81
+ // over; `w-full` plus a margin would overflow.
82
+ variant === "sheet" && "mx-3 w-auto",
83
+ ITEM_SIZE_CLASSES[normalizedSize],
84
+ // A 24px avatar would push the compact 32px row past its height with the
85
+ // default padding; tighten it so the avatar variant keeps the 32px contract.
86
+ hasAvatar && !hasDescription && normalizedSize === "32" && "py-1",
87
+ "data-[highlighted]:bg-neutral-alphas-50",
88
+ "data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled",
89
+ "disabled:cursor-not-allowed disabled:text-content-disabled",
90
+ // Sheet-variant asChild items are marked disabled via aria-disabled
91
+ // (see below), not the native disabled attribute or Radix's
92
+ // data-disabled — neither selector above matches them.
93
+ "aria-disabled:cursor-not-allowed aria-disabled:text-content-disabled",
94
+ destructive && "text-error-content",
95
+ // bg-interaction-hover aliases to the same token as the plain hover
96
+ // background above, so a selected row would be indistinguishable from a
97
+ // hovered-but-unselected one. Use the next step up the neutral-alphas
98
+ // ramp instead (still a subtle overlay, not the heavy filled style).
99
+ selected && ["bg-neutral-alphas-100", "data-[highlighted]:bg-neutral-alphas-200"],
100
+ className
101
+ );
102
+ const iconAlignClassName = hasDescription ? "flex h-[18px] shrink-0 items-center" : null;
103
+ const countNode = count != null && /* @__PURE__ */ jsx(
104
+ "span",
105
+ {
106
+ className: cn(
107
+ "shrink-0 tabular-nums",
108
+ iconAlignClassName,
109
+ ITEM_COUNT_TYPOGRAPHY[normalizedSize],
110
+ destructive ? "text-error-content" : "text-content-tertiary",
111
+ "group-data-[disabled]:text-content-disabled"
112
+ ),
113
+ children: count
114
+ }
115
+ );
116
+ const trailingNode = trailingIcon != null ? hasDescription ? /* @__PURE__ */ jsx("span", { className: iconAlignClassName, children: trailingIcon }) : trailingIcon : selected && /* @__PURE__ */ jsx(SelectedCheckIndicator, { hasDescription });
117
+ const itemChildren = /* @__PURE__ */ jsxs(Fragment, { children: [
118
+ avatar != null ? /* @__PURE__ */ jsx("span", { className: cn("shrink-0", iconAlignClassName), children: avatar }) : leadingIcon != null && (hasDescription ? /* @__PURE__ */ jsx("span", { className: iconAlignClassName, children: leadingIcon }) : leadingIcon),
119
+ hasDescription ? /* @__PURE__ */ jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [
120
+ /* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-semibold truncate", children }),
121
+ /* @__PURE__ */ jsx("span", { className: "typography-body-small-14px-regular truncate text-content-secondary", children: description })
122
+ ] }) : /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children }),
123
+ countNode,
124
+ trailingNode
125
+ ] });
126
+ if (variant === "sheet") {
127
+ const Comp = asChild ? Slot : "button";
128
+ const { onClick: consumerOnClick, ...restProps } = props;
129
+ const sheetSpecificProps = !asChild ? { type: "button", disabled } : disabled ? { "aria-disabled": true } : {};
130
+ return /* @__PURE__ */ jsx(
131
+ Comp,
132
+ {
133
+ ref,
134
+ ...restProps,
135
+ ...sheetSpecificProps,
136
+ role: "option",
137
+ "aria-selected": selected,
138
+ className: itemClassName,
139
+ onClick: (event) => {
140
+ if (disabled) {
141
+ event.preventDefault();
142
+ return;
143
+ }
144
+ consumerOnClick?.(event);
145
+ if (event.defaultPrevented) return;
146
+ onSelect?.(event.nativeEvent);
147
+ if (!event.nativeEvent.defaultPrevented) toggleOpen?.(() => false);
148
+ },
149
+ children: asChild ? children : itemChildren
150
+ }
151
+ );
152
+ }
153
+ if (asChild) {
154
+ return /* @__PURE__ */ jsx(
155
+ DropdownMenuPrimitive.Item,
156
+ {
157
+ ref,
158
+ asChild: true,
159
+ className: itemClassName,
160
+ disabled,
161
+ onSelect,
162
+ ...props,
163
+ children
164
+ }
165
+ );
166
+ }
167
+ return /* @__PURE__ */ jsx(
168
+ DropdownMenuPrimitive.Item,
169
+ {
170
+ ref,
171
+ className: itemClassName,
172
+ disabled,
173
+ onSelect,
174
+ ...props,
175
+ children: itemChildren
176
+ }
177
+ );
178
+ }
179
+ );
180
+ DropdownMenuItem.displayName = "DropdownMenuItem";
181
+ const DropdownMenuSeparator = React.forwardRef(({ className, ...props }, ref) => {
182
+ const variant = React.useContext(DropdownMenuVariantContext);
183
+ const separatorClassName = cn("my-1 h-px bg-neutral-alphas-200", className);
184
+ if (variant === "sheet") {
185
+ return /* @__PURE__ */ jsx("hr", { ref, className: separatorClassName, ...props });
186
+ }
187
+ return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Separator, { ref, className: separatorClassName, ...props });
188
+ });
189
+ DropdownMenuSeparator.displayName = "DropdownMenuSeparator";
190
+ export {
191
+ DropdownMenuItem,
192
+ DropdownMenuLabel,
193
+ DropdownMenuSeparator
194
+ };
195
+ //# sourceMappingURL=DropdownMenuItem.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DropdownMenuItem.mjs","sources":["../../../src/components/DropdownMenu/DropdownMenuItem.tsx"],"sourcesContent":["import * as DropdownMenuPrimitive from \"@radix-ui/react-dropdown-menu\";\nimport { Slot } from \"@radix-ui/react-slot\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { CheckIcon } from \"../Icons/CheckIcon\";\nimport { DropdownMenuVariantContext, ToggleOpenContext } from \"./context\";\n\n/** Vertical placement of a {@link DropdownMenuLabel} within its group. */\nexport type DropdownMenuLabelPosition = \"default\" | \"top\";\n\n/** Props for the {@link DropdownMenuLabel} component. */\nexport interface DropdownMenuLabelProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> {\n /**\n * Vertical placement within the surrounding group. `\"top\"` is used for the\n * first label directly under a header; `\"default\"` adds extra top padding to\n * separate it from preceding items. @default \"default\"\n */\n position?: DropdownMenuLabelPosition;\n}\n\n/** A non-interactive label that groups related items within a menu. */\nexport const DropdownMenuLabel = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Label>,\n DropdownMenuLabelProps\n>(({ className, position = \"default\", ...props }, ref) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n const labelClassName = cn(\n \"typography-description-12px-regular flex items-center px-3 text-content-secondary\",\n position === \"top\" ? \"py-2\" : \"pt-4 pb-2\",\n className,\n );\n\n // DropdownMenuPrimitive.Label requires Radix menu context, unavailable when\n // the sheet variant renders inside a Drawer (Dialog) instead.\n if (variant === \"sheet\") {\n return <div ref={ref} className={labelClassName} {...props} />;\n }\n\n return <DropdownMenuPrimitive.Label ref={ref} className={labelClassName} {...props} />;\n});\nDropdownMenuLabel.displayName = \"DropdownMenuLabel\";\n\n/**\n * Height preset for a dropdown menu item.\n *\n * `\"40\"` (default) and `\"32\"` are the v2 numeric tokens that mirror the Figma\n * design system. `\"sm\"` and `\"md\"` are deprecated aliases retained for\n * backwards compatibility — `\"sm\"` maps to `\"32\"`, `\"md\"` maps to `\"40\"`.\n */\nexport type DropdownMenuItemSize =\n | \"40\"\n | \"32\"\n /** @deprecated Use `\"32\"` instead. */\n | \"sm\"\n /** @deprecated Use `\"40\"` instead. */\n | \"md\";\n\nconst SIZE_NORMALIZED: Record<DropdownMenuItemSize, \"40\" | \"32\"> = {\n \"40\": \"40\",\n md: \"40\",\n \"32\": \"32\",\n sm: \"32\",\n};\n\nconst ITEM_SIZE_CLASSES: Record<\"40\" | \"32\", string> = {\n \"40\": \"min-h-10 py-2 typography-body-default-16px-regular\",\n \"32\": \"min-h-8 py-[7px] typography-body-small-14px-regular\",\n};\n\n/*\n * 14px at both heights. `V2 Menu Item` draws the count as `Body Small 14px/Regular`\n * in `content-tertiary` (node `21542:8629`), and the 40 row previously stepped up to\n * 16px — which also put the count's line box at 24px against the two-line layout's\n * 18px title leading.\n *\n * Only the 40 row is drawn in Figma: the component set's variants are Type and State\n * with no size axis. The 32 row is ours, and 14px matches the body type it already\n * uses, so both entries agree by construction rather than by design reference.\n */\nconst ITEM_COUNT_TYPOGRAPHY: Record<\"40\" | \"32\", string> = {\n \"40\": \"typography-body-small-14px-regular\",\n \"32\": \"typography-body-small-14px-regular\",\n};\n\n// Background alone can't reliably tell \"selected\" apart from a\n// hovered-but-unselected row across every theme/contrast combination (see the\n// neutral-alphas fix on itemClassName below) — pair it with an explicit\n// indicator, matching SelectItem's check indicator for the same V2 Menu Item\n// spec.\nfunction SelectedCheckIndicator({ hasDescription }: { hasDescription: boolean }) {\n return (\n <CheckIcon\n className={cn(\n \"size-4 shrink-0 text-content-primary\",\n // The two-line layout switches the row to `items-start`, which would hang\n // the tick off the title's line. A leading icon or avatar belongs there —\n // it labels the title — but the tick is a property of the whole row, so it\n // centres against both lines. {@link SelectItem} already does this.\n hasDescription && \"self-center\",\n )}\n />\n );\n}\n\nexport interface DropdownMenuItemProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> {\n /** Height of the menu item row. @default \"40\" */\n size?: DropdownMenuItemSize;\n /** Applies the destructive (error) treatment. Use for irreversible actions. @default false */\n destructive?: boolean;\n /** Icon (or other node) rendered before the label. Ignored when {@link DropdownMenuItemProps.avatar} is set. */\n leadingIcon?: React.ReactNode;\n /**\n * Leading avatar rendered in place of {@link DropdownMenuItemProps.leadingIcon},\n * for rows that represent a person or account. Pass an `Avatar` sized to `24`.\n * Takes precedence over `leadingIcon`.\n */\n avatar?: React.ReactNode;\n /**\n * Icon (or other node) rendered after the label. When\n * {@link DropdownMenuItemProps.selected} is true and no `trailingIcon` is\n * given, the built-in selected check indicator renders in this slot\n * instead — pass a `trailingIcon` to use a custom selected indicator (e.g.\n * a themed tick) rather than the default one.\n */\n trailingIcon?: React.ReactNode;\n /** Trailing count or number (e.g. an unread total) rendered before {@link DropdownMenuItemProps.trailingIcon}. */\n count?: React.ReactNode;\n /**\n * Optional secondary text rendered on a second line below the label. When\n * provided, the row switches to a two-line layout and the leading/trailing\n * icons align to the title line (top) rather than the row's vertical centre.\n */\n description?: React.ReactNode;\n /** Marks the item as the current selection in a single-select menu. @default false */\n selected?: boolean;\n}\n\n/**\n * An individual item within a {@link DropdownMenuContent}.\n *\n * @example\n * ```tsx\n * <DropdownMenuItem>Edit profile</DropdownMenuItem>\n * <DropdownMenuItem destructive>Delete</DropdownMenuItem>\n * <DropdownMenuItem leadingIcon={<EditIcon />}>Edit</DropdownMenuItem>\n *\n * // Feature-rich row with an avatar and a trailing count\n * <DropdownMenuItem avatar={<Avatar size={24} src={src} />} count=\"12\">\n * Jane Doe\n * </DropdownMenuItem>\n *\n * // As a link\n * <DropdownMenuItem asChild>\n * <a href=\"/settings\">Settings</a>\n * </DropdownMenuItem>\n * ```\n */\nexport const DropdownMenuItem = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Item>,\n DropdownMenuItemProps\n>(\n (\n {\n size = \"40\",\n destructive,\n leadingIcon,\n avatar,\n trailingIcon,\n count,\n description,\n selected,\n className,\n children,\n asChild,\n onSelect,\n disabled,\n ...props\n },\n ref,\n ) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n const toggleOpen = React.useContext(ToggleOpenContext);\n const normalizedSize = SIZE_NORMALIZED[size];\n const hasDescription = description != null;\n const hasAvatar = avatar != null;\n const itemClassName = cn(\n // `text-start` because the sheet variant renders the row as a <button>,\n // whose UA-centred text misaligned it from the popper variant's rows.\n \"group flex w-full cursor-pointer gap-2 rounded-sm px-3 text-start outline-none\",\n hasDescription ? \"items-start\" : \"items-center\",\n // The sheet's header runs the full width of the panel, so its rows have to\n // come in off the edge themselves — 12px here on the panel's own 4px is the\n // design's 16px. `w-auto` lets the column stretch them to the space left\n // over; `w-full` plus a margin would overflow.\n variant === \"sheet\" && \"mx-3 w-auto\",\n ITEM_SIZE_CLASSES[normalizedSize],\n // A 24px avatar would push the compact 32px row past its height with the\n // default padding; tighten it so the avatar variant keeps the 32px contract.\n hasAvatar && !hasDescription && normalizedSize === \"32\" && \"py-1\",\n \"data-[highlighted]:bg-neutral-alphas-50\",\n \"data-[disabled]:cursor-not-allowed data-[disabled]:text-content-disabled\",\n \"disabled:cursor-not-allowed disabled:text-content-disabled\",\n // Sheet-variant asChild items are marked disabled via aria-disabled\n // (see below), not the native disabled attribute or Radix's\n // data-disabled — neither selector above matches them.\n \"aria-disabled:cursor-not-allowed aria-disabled:text-content-disabled\",\n destructive && \"text-error-content\",\n // bg-interaction-hover aliases to the same token as the plain hover\n // background above, so a selected row would be indistinguishable from a\n // hovered-but-unselected one. Use the next step up the neutral-alphas\n // ramp instead (still a subtle overlay, not the heavy filled style).\n selected && [\"bg-neutral-alphas-100\", \"data-[highlighted]:bg-neutral-alphas-200\"],\n className,\n );\n\n // In the two-line (description) layout everything beside the title sits on\n // the title's line, not the centre of the two-line block. A box the height of\n // that line centres each sibling on it whatever its own size — a 16px icon, a\n // 24px avatar, or the count's larger text box. The height is the title's, from\n // `typography-body-small-14px-semibold`; a `pt-*` nudge cannot do this because\n // the correct offset differs per sibling, and the previous `pt-1` was computed\n // against the single-line title's 24px leading, leaving all four 3px low.\n const iconAlignClassName = hasDescription ? \"flex h-[18px] shrink-0 items-center\" : null;\n\n const countNode = count != null && (\n <span\n className={cn(\n \"shrink-0 tabular-nums\",\n iconAlignClassName,\n ITEM_COUNT_TYPOGRAPHY[normalizedSize],\n destructive ? \"text-error-content\" : \"text-content-tertiary\",\n \"group-data-[disabled]:text-content-disabled\",\n )}\n >\n {count}\n </span>\n );\n\n // A caller-supplied trailingIcon always wins the trailing slot — some\n // consumers pass their own selected indicator (e.g. a themed tick) and\n // rely on it being shown as-is rather than replaced. Only fall back to\n // the built-in check indicator when selected and no trailingIcon is given.\n const trailingNode =\n trailingIcon != null ? (\n hasDescription ? (\n <span className={iconAlignClassName!}>{trailingIcon}</span>\n ) : (\n trailingIcon\n )\n ) : (\n selected && <SelectedCheckIndicator hasDescription={hasDescription} />\n );\n\n const itemChildren = (\n <>\n {avatar != null ? (\n <span className={cn(\"shrink-0\", iconAlignClassName)}>{avatar}</span>\n ) : (\n leadingIcon != null &&\n (hasDescription ? (\n <span className={iconAlignClassName!}>{leadingIcon}</span>\n ) : (\n leadingIcon\n ))\n )}\n {hasDescription ? (\n <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n {/*\n * The two-line row sets its own title type rather than inheriting the\n * row's: `V2 Menu Item` pairs a 14px semibold title with the 14px\n * regular description below it, where a single-line row's title is the\n * size's own 16px regular. It also settles the row's height — 18 + 2 +\n * 18 of text inside `py-2` is the design's 54px.\n */}\n <span className=\"typography-body-small-14px-semibold truncate\">{children}</span>\n <span className=\"typography-body-small-14px-regular truncate text-content-secondary\">\n {description}\n </span>\n </span>\n ) : (\n <span className=\"min-w-0 flex-1 truncate\">{children}</span>\n )}\n {countNode}\n {trailingNode}\n </>\n );\n\n // The sheet variant renders inside a Drawer (Dialog), not a Radix menu, so\n // DropdownMenuPrimitive.Item (which requires menu context) can't be used —\n // render a plain option element with equivalent selection semantics instead.\n // asChild goes through the same Slot primitive Radix's own Item uses\n // internally, so a custom element (e.g. a link) gets the option\n // role/handlers merged onto it without needing menu context.\n if (variant === \"sheet\") {\n const Comp = asChild ? Slot : \"button\";\n // Pull the consumer's onClick out of the passthrough spread so the\n // handler below can compose with it instead of the spread order\n // silently overwriting it (an explicit onClick after {...props} always\n // wins over the spread's).\n const { onClick: consumerOnClick, ...restProps } =\n props as React.ComponentPropsWithoutRef<\"button\">;\n const sheetSpecificProps = !asChild\n ? { type: \"button\" as const, disabled }\n : disabled\n ? { \"aria-disabled\": true }\n : {};\n return (\n <Comp\n ref={ref as React.Ref<HTMLButtonElement>}\n {...restProps}\n {...sheetSpecificProps}\n role=\"option\"\n aria-selected={selected}\n className={itemClassName}\n onClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n // A native <button disabled> already blocks its click event, but\n // asChild's element (e.g. a link) has no such enforcement — guard\n // explicitly, and prevent the click's default action (e.g. anchor\n // navigation) since aria-disabled alone doesn't stop it.\n if (disabled) {\n event.preventDefault();\n return;\n }\n consumerOnClick?.(event);\n if (event.defaultPrevented) return;\n // Pass the real native event through, not a fake partial shape —\n // handlers that call any Event API beyond preventDefault (e.g.\n // stopPropagation, composedPath) need it to actually exist. It's\n // still live (currentTarget/target are valid) since we're inside\n // the same synchronous click handler that produced it.\n onSelect?.(event.nativeEvent);\n if (!event.nativeEvent.defaultPrevented) toggleOpen?.(() => false);\n }}\n >\n {asChild ? children : itemChildren}\n </Comp>\n );\n }\n\n if (asChild) {\n return (\n <DropdownMenuPrimitive.Item\n ref={ref}\n asChild\n className={itemClassName}\n disabled={disabled}\n onSelect={onSelect}\n {...props}\n >\n {children}\n </DropdownMenuPrimitive.Item>\n );\n }\n\n return (\n <DropdownMenuPrimitive.Item\n ref={ref}\n className={itemClassName}\n disabled={disabled}\n onSelect={onSelect}\n {...props}\n >\n {itemChildren}\n </DropdownMenuPrimitive.Item>\n );\n },\n);\nDropdownMenuItem.displayName = \"DropdownMenuItem\";\n\n/** Props for the {@link DropdownMenuSeparator} component. */\nexport interface DropdownMenuSeparatorProps\n extends React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator> {}\n\n/** Visual separator between groups of items. */\nexport const DropdownMenuSeparator = React.forwardRef<\n React.ComponentRef<typeof DropdownMenuPrimitive.Separator>,\n DropdownMenuSeparatorProps\n>(({ className, ...props }, ref) => {\n const variant = React.useContext(DropdownMenuVariantContext);\n const separatorClassName = cn(\"my-1 h-px bg-neutral-alphas-200\", className);\n\n // DropdownMenuPrimitive.Separator requires Radix menu context, unavailable\n // when the sheet variant renders inside a Drawer (Dialog) instead. <hr> is a\n // native separator, so it needs no ARIA role.\n if (variant === \"sheet\") {\n return <hr ref={ref as React.Ref<HTMLHRElement>} className={separatorClassName} {...props} />;\n }\n\n return <DropdownMenuPrimitive.Separator ref={ref} className={separatorClassName} {...props} />;\n});\nDropdownMenuSeparator.displayName = \"DropdownMenuSeparator\";\n"],"names":[],"mappings":"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"}
@@ -0,0 +1,421 @@
1
+ "use client";
2
+ import { jsxs, jsx } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { cn } from "../../utils/cn.mjs";
5
+ import { DropdownMenuVariantContext } from "./context.mjs";
6
+ import { ReorderActionsContext, ReorderLiftedContext } from "./reorderShared.mjs";
7
+ const REORDER_LIFT_THRESHOLD_PX = 4;
8
+ const REORDER_AUTOSCROLL_ZONE_PX = 32;
9
+ const REORDER_AUTOSCROLL_MAX_STEP_PX = 8;
10
+ const DEFAULT_REORDER_INSTRUCTIONS = "Press the up and down arrow keys to move this item.";
11
+ function findScrollableAncestor(element) {
12
+ let current = element.parentElement;
13
+ while (current !== null) {
14
+ const { overflowY } = getComputedStyle(current);
15
+ if ((overflowY === "auto" || overflowY === "scroll") && current.scrollHeight > current.clientHeight) {
16
+ return current;
17
+ }
18
+ current = current.parentElement;
19
+ }
20
+ return null;
21
+ }
22
+ function edgeOvershoot(rect, y) {
23
+ if (y < rect.top + REORDER_AUTOSCROLL_ZONE_PX) return y - (rect.top + REORDER_AUTOSCROLL_ZONE_PX);
24
+ if (y > rect.bottom - REORDER_AUTOSCROLL_ZONE_PX) {
25
+ return y - (rect.bottom - REORDER_AUTOSCROLL_ZONE_PX);
26
+ }
27
+ return 0;
28
+ }
29
+ function useLatestRef(value) {
30
+ const ref = React.useRef(value);
31
+ React.useLayoutEffect(() => {
32
+ ref.current = value;
33
+ });
34
+ return ref;
35
+ }
36
+ function shallowEqualArrays(a, b) {
37
+ return a.length === b.length && a.every((value, index) => value === b[index]);
38
+ }
39
+ function defaultReorderAnnouncement({ label, to, total }) {
40
+ return `${label} moved to position ${to + 1} of ${total}`;
41
+ }
42
+ const DropdownMenuReorderGroup = React.forwardRef(
43
+ ({
44
+ values,
45
+ onReorder,
46
+ getAnnouncement = defaultReorderAnnouncement,
47
+ instructions = DEFAULT_REORDER_INSTRUCTIONS,
48
+ className,
49
+ children,
50
+ ...props
51
+ }, ref) => {
52
+ const variant = React.useContext(DropdownMenuVariantContext);
53
+ const instructionsId = React.useId();
54
+ const groupRef = React.useRef(null);
55
+ const itemsRef = React.useRef(/* @__PURE__ */ new Map());
56
+ const dragRef = React.useRef(null);
57
+ const ghostRef = React.useRef(null);
58
+ const scrollContainerRef = React.useRef(null);
59
+ const lastPointerRef = React.useRef(null);
60
+ const autoScrollFrameRef = React.useRef(null);
61
+ const dragDisposersRef = React.useRef([]);
62
+ const valuesRef = useLatestRef(values);
63
+ const onReorderRef = useLatestRef(onReorder);
64
+ const getAnnouncementRef = useLatestRef(getAnnouncement);
65
+ const [lifted, setLifted] = React.useState(null);
66
+ const [dropIndex, setDropIndex] = React.useState(-1);
67
+ const [announcement, setAnnouncement] = React.useState("");
68
+ const registerItem = React.useCallback((value, item) => {
69
+ if (item === null) {
70
+ itemsRef.current.delete(value);
71
+ } else {
72
+ itemsRef.current.set(value, item);
73
+ }
74
+ }, []);
75
+ const positionGhost = React.useCallback(() => {
76
+ const drag2 = dragRef.current;
77
+ const ghost = ghostRef.current;
78
+ const pointer = lastPointerRef.current;
79
+ if (drag2 === null || ghost === null || pointer === null) return;
80
+ ghost.style.transform = `translate3d(${pointer.x - drag2.offsetX}px, ${pointer.y - drag2.offsetY}px, 0)`;
81
+ }, []);
82
+ const registerGhost = React.useCallback(
83
+ (element) => {
84
+ ghostRef.current = element;
85
+ if (element !== null) positionGhost();
86
+ },
87
+ [positionGhost]
88
+ );
89
+ const measure = React.useCallback(
90
+ (drag2) => {
91
+ const group = groupRef.current;
92
+ if (group === null) return;
93
+ const groupTop = group.getBoundingClientRect().top;
94
+ const midpoints = [];
95
+ const edges = [];
96
+ let bottom = groupTop;
97
+ for (const value of valuesRef.current) {
98
+ const rect = itemsRef.current.get(value)?.element.getBoundingClientRect();
99
+ if (rect === void 0) {
100
+ midpoints.push(bottom);
101
+ edges.push(bottom - groupTop);
102
+ continue;
103
+ }
104
+ midpoints.push(rect.top + rect.height / 2);
105
+ edges.push(rect.top - groupTop);
106
+ bottom = rect.bottom;
107
+ }
108
+ edges.push(bottom - groupTop);
109
+ drag2.midpoints = midpoints;
110
+ drag2.edges = edges;
111
+ const container = scrollContainerRef.current;
112
+ drag2.scrollTopAtMeasure = container?.scrollTop ?? 0;
113
+ drag2.containerRect = container?.getBoundingClientRect() ?? null;
114
+ },
115
+ [valuesRef]
116
+ );
117
+ const computeDropIndex = React.useCallback((drag2, clientY) => {
118
+ const container = scrollContainerRef.current;
119
+ const y = clientY + (container === null ? 0 : container.scrollTop - drag2.scrollTopAtMeasure);
120
+ let index = 0;
121
+ for (const midpoint of drag2.midpoints) {
122
+ if (midpoint >= y) break;
123
+ index += 1;
124
+ }
125
+ return index;
126
+ }, []);
127
+ const refreshDropIndex = React.useCallback(
128
+ (drag2, clientY) => {
129
+ const next = computeDropIndex(drag2, clientY);
130
+ if (next === drag2.dropIndex) return;
131
+ drag2.dropIndex = next;
132
+ setDropIndex(next);
133
+ },
134
+ [computeDropIndex]
135
+ );
136
+ const stopAutoScroll = React.useCallback(() => {
137
+ if (autoScrollFrameRef.current === null) return;
138
+ cancelAnimationFrame(autoScrollFrameRef.current);
139
+ autoScrollFrameRef.current = null;
140
+ }, []);
141
+ const updateAutoScroll = React.useCallback(() => {
142
+ const drag2 = dragRef.current;
143
+ const container = scrollContainerRef.current;
144
+ const pointer = lastPointerRef.current;
145
+ if (drag2 === null || !drag2.lifted || container === null || drag2.containerRect === null || pointer === null || edgeOvershoot(drag2.containerRect, pointer.y) === 0) {
146
+ stopAutoScroll();
147
+ return;
148
+ }
149
+ if (autoScrollFrameRef.current !== null) return;
150
+ const step = () => {
151
+ autoScrollFrameRef.current = null;
152
+ const current = dragRef.current;
153
+ const latest = lastPointerRef.current;
154
+ if (current === null || !current.lifted || current.containerRect === null || latest === null) {
155
+ return;
156
+ }
157
+ const overshoot = edgeOvershoot(current.containerRect, latest.y);
158
+ if (overshoot === 0) return;
159
+ const amount = Math.min(Math.ceil(Math.abs(overshoot) / 4), REORDER_AUTOSCROLL_MAX_STEP_PX);
160
+ const before = container.scrollTop;
161
+ container.scrollTop = before + (overshoot < 0 ? -amount : amount);
162
+ if (container.scrollTop === before) return;
163
+ autoScrollFrameRef.current = requestAnimationFrame(step);
164
+ };
165
+ autoScrollFrameRef.current = requestAnimationFrame(step);
166
+ }, [stopAutoScroll]);
167
+ const clearDrag = React.useCallback(() => {
168
+ stopAutoScroll();
169
+ for (const dispose of dragDisposersRef.current) dispose();
170
+ dragDisposersRef.current = [];
171
+ const drag2 = dragRef.current;
172
+ dragRef.current = null;
173
+ lastPointerRef.current = null;
174
+ scrollContainerRef.current = null;
175
+ if (drag2?.lifted) {
176
+ setLifted(null);
177
+ setDropIndex(-1);
178
+ }
179
+ }, [stopAutoScroll]);
180
+ const applyReorder = React.useCallback(
181
+ (value, from, to) => {
182
+ const next = [...valuesRef.current];
183
+ next.splice(from, 1);
184
+ next.splice(to, 0, value);
185
+ const detail = {
186
+ value,
187
+ label: itemsRef.current.get(value)?.label ?? value,
188
+ from,
189
+ to,
190
+ total: next.length
191
+ };
192
+ onReorderRef.current(next, detail);
193
+ setAnnouncement(getAnnouncementRef.current(detail));
194
+ },
195
+ [valuesRef, onReorderRef, getAnnouncementRef]
196
+ );
197
+ const endDrag = React.useCallback(
198
+ (pointerId, commit) => {
199
+ const drag2 = dragRef.current;
200
+ if (drag2 === null || pointerId !== drag2.pointerId) return;
201
+ clearDrag();
202
+ if (!commit || !drag2.lifted) return;
203
+ const current = valuesRef.current;
204
+ const from = current.indexOf(drag2.value);
205
+ if (from === -1) return;
206
+ const to = Math.max(
207
+ 0,
208
+ Math.min(drag2.dropIndex > from ? drag2.dropIndex - 1 : drag2.dropIndex, current.length - 1)
209
+ );
210
+ if (to === from) return;
211
+ applyReorder(drag2.value, from, to);
212
+ },
213
+ [clearDrag, applyReorder, valuesRef]
214
+ );
215
+ const startDrag = React.useCallback(
216
+ (value, event, element) => {
217
+ if (dragRef.current !== null || groupRef.current === null) return false;
218
+ dragRef.current = {
219
+ value,
220
+ pointerId: event.pointerId,
221
+ element,
222
+ startX: event.clientX,
223
+ startY: event.clientY,
224
+ offsetX: 0,
225
+ offsetY: 0,
226
+ lifted: false,
227
+ dropIndex: -1,
228
+ midpoints: [],
229
+ edges: [],
230
+ scrollTopAtMeasure: 0,
231
+ containerRect: null
232
+ };
233
+ lastPointerRef.current = { x: event.clientX, y: event.clientY };
234
+ const view = element.ownerDocument.defaultView ?? window;
235
+ const onPointerUp = (pointerEvent) => endDrag(pointerEvent.pointerId, true);
236
+ const onPointerCancel = (pointerEvent) => endDrag(pointerEvent.pointerId, false);
237
+ const onKeyDown = (keyEvent) => {
238
+ if (keyEvent.key !== "Escape" || dragRef.current?.lifted !== true) return;
239
+ keyEvent.preventDefault();
240
+ keyEvent.stopPropagation();
241
+ clearDrag();
242
+ };
243
+ view.addEventListener("pointerup", onPointerUp);
244
+ view.addEventListener("pointercancel", onPointerCancel);
245
+ view.addEventListener("keydown", onKeyDown, true);
246
+ dragDisposersRef.current.push(() => {
247
+ view.removeEventListener("pointerup", onPointerUp);
248
+ view.removeEventListener("pointercancel", onPointerCancel);
249
+ view.removeEventListener("keydown", onKeyDown, true);
250
+ });
251
+ return true;
252
+ },
253
+ [endDrag, clearDrag]
254
+ );
255
+ const lift = React.useCallback(
256
+ (drag2, pointer) => {
257
+ const { element } = drag2;
258
+ const rect = element.getBoundingClientRect();
259
+ drag2.offsetX = drag2.startX - rect.left;
260
+ drag2.offsetY = drag2.startY - rect.top;
261
+ const container = findScrollableAncestor(element);
262
+ scrollContainerRef.current = container;
263
+ if (container !== null) {
264
+ const onScroll = () => {
265
+ const current = dragRef.current;
266
+ const latest = lastPointerRef.current;
267
+ if (current === null || !current.lifted || latest === null) return;
268
+ refreshDropIndex(current, latest.y);
269
+ };
270
+ container.addEventListener("scroll", onScroll, { passive: true });
271
+ dragDisposersRef.current.push(() => container.removeEventListener("scroll", onScroll));
272
+ }
273
+ measure(drag2);
274
+ drag2.lifted = true;
275
+ drag2.dropIndex = computeDropIndex(drag2, pointer.y);
276
+ const surface = element.closest('[role="menu"],[role="dialog"]');
277
+ const surfaceZIndex = surface === null ? "" : getComputedStyle(surface).zIndex;
278
+ setLifted({
279
+ value: drag2.value,
280
+ width: rect.width,
281
+ zIndex: surfaceZIndex === "" || surfaceZIndex === "auto" ? "var(--fanvue-ui-portal-z-index, 50)" : surfaceZIndex
282
+ });
283
+ setDropIndex(drag2.dropIndex);
284
+ },
285
+ [measure, computeDropIndex, refreshDropIndex]
286
+ );
287
+ const updateDrag = React.useCallback(
288
+ (event) => {
289
+ const drag2 = dragRef.current;
290
+ if (drag2 === null || event.pointerId !== drag2.pointerId) return;
291
+ const pointer = { x: event.clientX, y: event.clientY };
292
+ lastPointerRef.current = pointer;
293
+ if (!drag2.lifted) {
294
+ if (Math.hypot(pointer.x - drag2.startX, pointer.y - drag2.startY) <= REORDER_LIFT_THRESHOLD_PX) {
295
+ return;
296
+ }
297
+ lift(drag2, pointer);
298
+ }
299
+ positionGhost();
300
+ refreshDropIndex(drag2, pointer.y);
301
+ updateAutoScroll();
302
+ },
303
+ [lift, positionGhost, refreshDropIndex, updateAutoScroll]
304
+ );
305
+ const moveItem = React.useCallback(
306
+ (value, delta) => {
307
+ const current = valuesRef.current;
308
+ const from = current.indexOf(value);
309
+ const to = from + delta;
310
+ if (from === -1 || to < 0 || to >= current.length) return;
311
+ applyReorder(value, from, to);
312
+ },
313
+ [applyReorder, valuesRef]
314
+ );
315
+ React.useEffect(() => clearDrag, [clearDrag]);
316
+ const previousValuesRef = React.useRef(values);
317
+ React.useLayoutEffect(() => {
318
+ if (shallowEqualArrays(previousValuesRef.current, values)) return;
319
+ previousValuesRef.current = values;
320
+ const drag2 = dragRef.current;
321
+ if (drag2 === null) return;
322
+ if (!values.includes(drag2.value)) {
323
+ clearDrag();
324
+ return;
325
+ }
326
+ if (!drag2.lifted) return;
327
+ measure(drag2);
328
+ const pointer = lastPointerRef.current;
329
+ if (pointer !== null) refreshDropIndex(drag2, pointer.y);
330
+ }, [values, clearDrag, measure, refreshDropIndex]);
331
+ React.useEffect(() => {
332
+ if (variant !== "menu") return;
333
+ const group = groupRef.current;
334
+ const menu = group?.closest('[role="menu"]') ?? null;
335
+ if (group === null || menu === null) return;
336
+ const doc = group.ownerDocument;
337
+ const focusFirstHandle = () => {
338
+ const handle = group.querySelector("button:not(:disabled)");
339
+ if (handle === null) return false;
340
+ handle.focus({ preventScroll: true });
341
+ return true;
342
+ };
343
+ const frame = requestAnimationFrame(() => {
344
+ const active = doc.activeElement;
345
+ const parkedOnMenu = active === null || active === doc.body || active === menu;
346
+ const hasMenuItems = menu.querySelector('[role^="menuitem"]') !== null;
347
+ if (parkedOnMenu && !hasMenuItems) focusFirstHandle();
348
+ });
349
+ const rescueTab = (event) => {
350
+ if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey) return;
351
+ const active = doc.activeElement;
352
+ if (active !== null && active !== doc.body) return;
353
+ if (menu.getAttribute("data-state") !== "open") return;
354
+ if (focusFirstHandle()) event.preventDefault();
355
+ };
356
+ doc.addEventListener("keydown", rescueTab, true);
357
+ return () => {
358
+ cancelAnimationFrame(frame);
359
+ doc.removeEventListener("keydown", rescueTab, true);
360
+ };
361
+ }, [variant]);
362
+ const actions = React.useMemo(
363
+ () => ({
364
+ registerItem,
365
+ registerGhost,
366
+ startDrag,
367
+ updateDrag,
368
+ endDrag,
369
+ moveItem,
370
+ instructionsId
371
+ }),
372
+ [registerItem, registerGhost, startDrag, updateDrag, endDrag, moveItem, instructionsId]
373
+ );
374
+ const drag = dragRef.current;
375
+ const liftedFrom = lifted === null ? -1 : values.indexOf(lifted.value);
376
+ const showDropIndicator = lifted !== null && drag !== null && dropIndex !== -1 && dropIndex !== liftedFrom && dropIndex !== liftedFrom + 1;
377
+ return (
378
+ // biome-ignore lint/a11y/useSemanticElements: <fieldset> carries form semantics and default styling we don't want inside a menu; role="group" is the correct ARIA pattern here
379
+ /* @__PURE__ */ jsxs(
380
+ "div",
381
+ {
382
+ ref: (node) => {
383
+ groupRef.current = node;
384
+ if (typeof ref === "function") {
385
+ ref(node);
386
+ } else if (ref) {
387
+ ref.current = node;
388
+ }
389
+ },
390
+ role: "group",
391
+ "data-dropdown-menu-tab-stops": "",
392
+ className: cn("relative flex w-full flex-col", className),
393
+ ...props,
394
+ children: [
395
+ /* @__PURE__ */ jsx(ReorderActionsContext.Provider, { value: actions, children: /* @__PURE__ */ jsx(ReorderLiftedContext.Provider, { value: lifted, children }) }),
396
+ showDropIndicator && /* @__PURE__ */ jsxs(
397
+ "div",
398
+ {
399
+ "aria-hidden": "true",
400
+ "data-reorder-indicator": "",
401
+ className: "pointer-events-none absolute inset-x-3 z-10 flex -translate-y-1/2 items-center",
402
+ style: { top: drag.edges[dropIndex] },
403
+ children: [
404
+ /* @__PURE__ */ jsx("span", { className: "size-2 shrink-0 rounded-full bg-content-primary" }),
405
+ /* @__PURE__ */ jsx("span", { className: "h-0.5 min-w-0 flex-1 rounded-full bg-content-primary" })
406
+ ]
407
+ }
408
+ ),
409
+ /* @__PURE__ */ jsx("span", { id: instructionsId, className: "sr-only", children: instructions }),
410
+ /* @__PURE__ */ jsx("span", { role: "status", "aria-live": "polite", className: "sr-only", children: announcement })
411
+ ]
412
+ }
413
+ )
414
+ );
415
+ }
416
+ );
417
+ DropdownMenuReorderGroup.displayName = "DropdownMenuReorderGroup";
418
+ export {
419
+ DropdownMenuReorderGroup
420
+ };
421
+ //# sourceMappingURL=DropdownMenuReorderGroup.mjs.map