@bioturing/components 0.29.1 → 0.30.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.
@@ -1,117 +1,144 @@
1
1
  "use client";
2
- import { jsxs as u, jsx as c } from "react/jsx-runtime";
3
- import { Command as s } from "../cmdk/index.js";
4
- import { useMemo as y, useCallback as f } from "react";
2
+ import { jsxs as p, jsx as t } from "react/jsx-runtime";
3
+ import { Command as d } from "../cmdk/index.js";
4
+ import { useMemo as P, useContext as v, useCallback as b } from "react";
5
5
  import './style.css';/* empty css */
6
- import { FormItemInputContext as V } from "antd/es/form/context";
7
- import { Radio as j } from "../radio/component.js";
8
- import { useControlledState as B } from "../hooks/useControlledState.js";
9
- import { useCls as E } from "../utils/antdUtils.js";
10
- import { cn as F } from "../utils/cn.js";
11
- import { Input as L } from "../input/component.js";
12
- import { Checkbox as p } from "../checkbox/component.js";
13
- import { ScrollArea as w } from "../scroll-area/component.js";
14
- import { reactNodeToString as D } from "../utils/reactToString.js";
15
- const W = ({
16
- items: a,
17
- multiple: r,
18
- value: v,
19
- defaultValue: g,
20
- onChange: S,
21
- searchProps: C = { placeholder: "Search..." },
6
+ import { FormItemInputContext as x } from "antd/es/form/context";
7
+ import R from "antd/es/config-provider/DisabledContext";
8
+ import { Radio as T } from "../radio/component.js";
9
+ import { useControlledState as q } from "../hooks/useControlledState.js";
10
+ import { useCls as w } from "../utils/antdUtils.js";
11
+ import { cn as z } from "../utils/cn.js";
12
+ import { Input as G } from "../input/component.js";
13
+ import { Checkbox as S } from "../checkbox/component.js";
14
+ import { ScrollArea as H } from "../scroll-area/component.js";
15
+ import { reactNodeToString as J } from "../utils/reactToString.js";
16
+ const ae = ({
17
+ items: i,
18
+ multiple: a,
19
+ value: g,
20
+ defaultValue: C,
21
+ onChange: A,
22
+ searchProps: k = { placeholder: "Search..." },
22
23
  showSelectAll: I = !1,
23
- className: b,
24
- placeholder: k = "Search",
25
- ...x
24
+ className: N,
25
+ placeholder: y = "Search",
26
+ disabled: D = !1,
27
+ status: V,
28
+ getItemKeywords: m,
29
+ ...j
26
30
  }) => {
27
- const [i, t] = B(
28
- v,
29
- S,
30
- g
31
- ), o = y(() => r ? i || [] : i ? [i] : [], [i, r]), n = E(), N = f(() => {
32
- if (r) {
33
- const e = a.map((l) => l.value).filter(Boolean);
34
- t(e);
31
+ const [l, c] = q(
32
+ g,
33
+ A,
34
+ C
35
+ ), s = P(() => a ? Array.isArray(l) ? l : l ? [l] : [] : Array.isArray(l) ? l.length > 0 ? [l[0]] : [] : l ? [l] : [], [l, a]), {
36
+ status: B
37
+ } = v(x), E = v(R), F = V || B, o = D || E, n = w(), L = b(() => {
38
+ if (a) {
39
+ const e = i.map((r) => r.value).filter(Boolean);
40
+ c(e);
35
41
  }
36
- }, [r, a, t]), A = f(() => {
37
- r && t([]);
38
- }, [r, t]);
39
- return /* @__PURE__ */ u(s, { className: F(n("choice-list"), b), ...x, children: [
40
- /* @__PURE__ */ c(V.Provider, { value: {}, children: /* @__PURE__ */ c(
41
- s.Input,
42
- {
43
- render: (
44
- // isolate the input from the form context
45
- /* @__PURE__ */ c(
46
- L.Search,
42
+ }, [a, i, c]), M = b(() => {
43
+ a && c([]);
44
+ }, [a, c]);
45
+ return /* @__PURE__ */ p(
46
+ d,
47
+ {
48
+ className: z(n("choice-list"), N),
49
+ "data-disabled": o,
50
+ "data-status": F,
51
+ ...j,
52
+ children: [
53
+ /* @__PURE__ */ t(x.Provider, { value: {}, children: /* @__PURE__ */ t(
54
+ d.Input,
55
+ {
56
+ render: (
57
+ // isolate the input from the form context
58
+ /* @__PURE__ */ t(
59
+ G.Search,
60
+ {
61
+ allowClear: !0,
62
+ disabled: o,
63
+ className: n("choice-list-search"),
64
+ placeholder: y
65
+ }
66
+ )
67
+ ),
68
+ ...k
69
+ }
70
+ ) }),
71
+ I && a && i.length > 0 && (() => {
72
+ const e = i.map((f) => f.value).filter(Boolean), r = s.filter(
73
+ (f) => e.includes(f)
74
+ ), u = r.length === e.length && e.length > 0, h = r.length > 0 && r.length < e.length;
75
+ return /* @__PURE__ */ t(
76
+ "div",
47
77
  {
48
- allowClear: !0,
49
- className: n("choice-list-search"),
50
- placeholder: k
78
+ className: n("choice-list-item"),
79
+ onClick: () => {
80
+ o || (h || u ? M() : L());
81
+ },
82
+ children: /* @__PURE__ */ t(
83
+ S,
84
+ {
85
+ tabIndex: -1,
86
+ checked: u,
87
+ indeterminate: h,
88
+ disabled: o,
89
+ children: "Select All"
90
+ }
91
+ )
51
92
  }
52
- )
53
- ),
54
- ...C
55
- }
56
- ) }),
57
- I && r && a.length > 0 && (() => {
58
- const e = a.map((m) => m.value).filter(Boolean), l = o.filter(
59
- (m) => e.includes(m)
60
- ), d = l.length === e.length && e.length > 0, h = l.length > 0 && l.length < e.length;
61
- return /* @__PURE__ */ c(
62
- "div",
63
- {
64
- className: n("choice-list-item"),
65
- onClick: () => {
66
- h || d ? A() : N();
67
- },
68
- children: /* @__PURE__ */ c(
69
- p,
93
+ );
94
+ })(),
95
+ /* @__PURE__ */ t(H, { className: n("choice-list-items"), fadeEdges: !0, children: /* @__PURE__ */ p(d.List, { children: [
96
+ /* @__PURE__ */ t(d.Empty, { className: n("choice-list-empty"), children: "No results found." }),
97
+ i.map((e) => /* @__PURE__ */ t(
98
+ d.Item,
70
99
  {
71
- tabIndex: -1,
72
- checked: d,
73
- indeterminate: h,
74
- children: "Select All"
75
- }
76
- )
77
- }
78
- );
79
- })(),
80
- /* @__PURE__ */ c(w, { className: n("choice-list-items"), fadeEdges: !0, children: /* @__PURE__ */ u(s.List, { children: [
81
- /* @__PURE__ */ c(s.Empty, { className: n("choice-list-empty"), children: "No results found." }),
82
- a.map((e) => /* @__PURE__ */ c(
83
- s.Item,
84
- {
85
- className: n("choice-list-item"),
86
- keywords: [e.value, D(e.label)],
87
- value: e.value,
88
- "data-in-choice": o.includes(e.value),
89
- onSelect: (l) => {
90
- if (r) {
91
- const d = o.includes(l) ? o.filter((h) => h !== l) : [.../* @__PURE__ */ new Set([...o, l])];
92
- t(
93
- d
94
- );
95
- } else
96
- t(
97
- l
98
- );
99
- },
100
- children: r ? /* @__PURE__ */ c(
101
- p,
102
- {
103
- tabIndex: -1,
104
- checked: o.includes(e.value),
105
- children: e.label
106
- }
107
- ) : /* @__PURE__ */ c(j, { tabIndex: -1, checked: o.includes(e.value), children: e.label })
108
- },
109
- e.value
110
- ))
111
- ] }) })
112
- ] });
100
+ className: n("choice-list-item"),
101
+ keywords: m ? m(e) : [e.value || "", J(e.label)],
102
+ value: e.value,
103
+ "data-in-choice": e.value ? s.includes(e.value) : !1,
104
+ onSelect: (r) => {
105
+ if (!o)
106
+ if (a) {
107
+ const u = s.includes(r) ? s.filter((h) => h !== r) : [.../* @__PURE__ */ new Set([...s, r])];
108
+ c(
109
+ u
110
+ );
111
+ } else
112
+ c(
113
+ r
114
+ );
115
+ },
116
+ children: a ? /* @__PURE__ */ t(
117
+ S,
118
+ {
119
+ tabIndex: -1,
120
+ checked: e.value ? s.includes(e.value) : !1,
121
+ disabled: o,
122
+ children: e.label
123
+ }
124
+ ) : /* @__PURE__ */ t(
125
+ T,
126
+ {
127
+ tabIndex: -1,
128
+ checked: e.value ? s.includes(e.value) : !1,
129
+ disabled: o,
130
+ children: e.label
131
+ }
132
+ )
133
+ },
134
+ e.value
135
+ ))
136
+ ] }) })
137
+ ]
138
+ }
139
+ );
113
140
  };
114
141
  export {
115
- W as ChoiceList
142
+ ae as ChoiceList
116
143
  };
117
144
  //# sourceMappingURL=component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sources":["../../../src/components/choice-list/component.tsx"],"sourcesContent":["\"use client\";\nimport { Command, CommandProps } from \"../cmdk\";\nimport { Input } from \"../input\";\nimport { useCallback, useMemo } from \"react\";\nimport { useCls, cn, reactNodeToString } from \"../utils\";\nimport { useControlledState } from \"../hooks\";\nimport { Radio } from \"../radio\";\nimport { Checkbox } from \"../checkbox\";\nimport { ScrollArea } from \"../scroll-area\";\n\nimport \"./style.css\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\n\nexport type ChoiceListItem = {\n label: React.ReactNode;\n value?: string;\n};\n\nexport interface ChoiceListProps<M extends boolean = false>\n extends Omit<CommandProps, \"value\" | \"onChange\" | \"defaultValue\"> {\n items: ChoiceListItem[];\n multiple?: M;\n value?: M extends true ? string[] : string;\n defaultValue?: M extends true ? string[] : string;\n onChange?: (value: M extends true ? string[] : string) => void;\n searchProps?: React.ComponentProps<typeof Command.Input>;\n /**\n * Show select all option when in multiple mode\n * @default false\n */\n showSelectAll?: boolean;\n placeholder?: string;\n}\n\nexport const ChoiceList = <M extends boolean = false>({\n items,\n multiple,\n value,\n defaultValue,\n onChange,\n searchProps = { placeholder: \"Search...\" },\n showSelectAll = false,\n className,\n placeholder = \"Search\",\n ...rest\n}: ChoiceListProps<M>) => {\n const [internalValue, setInternalValue] = useControlledState(\n value,\n onChange,\n defaultValue,\n );\n\n const usedValue = useMemo(() => {\n if (multiple) {\n return (internalValue as string[]) || [];\n } else {\n return internalValue ? [internalValue as string] : [];\n }\n }, [internalValue, multiple]);\n const cls = useCls();\n\n const handleSelectAll = useCallback(() => {\n if (multiple) {\n const allValues = items\n .map((item) => item.value)\n .filter(Boolean) as string[];\n setInternalValue(allValues as M extends true ? string[] : string);\n }\n }, [multiple, items, setInternalValue]);\n\n const handleDeselectAll = useCallback(() => {\n if (multiple) {\n setInternalValue([] as M extends true ? string[] : string);\n }\n }, [multiple, setInternalValue]);\n\n return (\n <Command className={cn(cls(\"choice-list\"), className)} {...rest}>\n <FormItemInputContext.Provider value={{}}>\n <Command.Input\n render={\n // isolate the input from the form context\n <Input.Search\n allowClear\n className={cls(\"choice-list-search\")}\n placeholder={placeholder}\n />\n }\n {...searchProps}\n />\n </FormItemInputContext.Provider>\n {showSelectAll &&\n multiple &&\n items.length > 0 &&\n (() => {\n const allValues = items\n .map((item) => item.value)\n .filter(Boolean) as string[];\n const selectedFromAll = usedValue.filter((val) =>\n allValues.includes(val),\n );\n const checked =\n selectedFromAll.length === allValues.length && allValues.length > 0;\n const indeterminate =\n selectedFromAll.length > 0 &&\n selectedFromAll.length < allValues.length;\n\n return (\n <div\n className={cls(\"choice-list-item\")}\n onClick={() => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n }}\n >\n <Checkbox\n tabIndex={-1}\n checked={checked}\n indeterminate={indeterminate}\n >\n Select All\n </Checkbox>\n </div>\n );\n })()}\n <ScrollArea className={cls(\"choice-list-items\")} fadeEdges>\n <Command.List>\n <Command.Empty className={cls(\"choice-list-empty\")}>\n No results found.\n </Command.Empty>\n {items.map((item) => (\n <Command.Item\n key={item.value}\n className={cls(\"choice-list-item\")}\n keywords={[item.value, reactNodeToString(item.label)]}\n value={item.value}\n data-in-choice={usedValue.includes(item.value)}\n onSelect={(newValue) => {\n if (multiple) {\n const newValues = usedValue.includes(newValue)\n ? usedValue.filter((value) => value !== newValue)\n : [...new Set([...usedValue, newValue])];\n setInternalValue(\n newValues as M extends true ? string[] : string,\n );\n } else {\n setInternalValue(\n newValue as M extends true ? string[] : string,\n );\n }\n }}\n >\n {multiple ? (\n <Checkbox\n tabIndex={-1}\n checked={usedValue.includes(item.value)}\n >\n {item.label}\n </Checkbox>\n ) : (\n <Radio tabIndex={-1} checked={usedValue.includes(item.value)}>\n {item.label}\n </Radio>\n )}\n </Command.Item>\n ))}\n </Command.List>\n </ScrollArea>\n </Command>\n );\n};\n"],"names":["ChoiceList","items","multiple","value","defaultValue","onChange","searchProps","showSelectAll","className","placeholder","rest","internalValue","setInternalValue","useControlledState","usedValue","useMemo","cls","useCls","handleSelectAll","useCallback","allValues","item","handleDeselectAll","jsxs","Command","cn","jsx","FormItemInputContext","Input","selectedFromAll","val","checked","indeterminate","Checkbox","ScrollArea","reactNodeToString","newValue","newValues","Radio"],"mappings":";;;;;;;;;;;;;;AAkCO,MAAMA,IAAa,CAA4B;AAAA,EACpD,OAAAC;AAAA,EACA,UAAAC;A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AAO,oBAAA,IAAI,CAAC,GAAGtB,GAAWsB,CAAQ,CAAC,CAAC;AACzC,cAAAxB;AAAA,gBACEyB;AAAA,cACF;AAAA,YAAA;AAEA,cAAAzB;AAAA,gBACEwB;AAAA,cACF;AAAA,UAEJ;AAAA,UAEC,UACClC,IAAA,gBAAAwB;AAAA,YAACO;AAAA,YAAA;AAAA,cACC,UAAU;AAAA,cACV,SAASnB,EAAU,SAASO,EAAK,KAAK;AAAA,cAErC,UAAKA,EAAA;AAAA,YAAA;AAAA,UAGR,IAAA,gBAAAK,EAACY,GAAM,EAAA,UAAU,IAAI,SAASxB,EAAU,SAASO,EAAK,KAAK,GACxD,UAAAA,EAAK,MACR,CAAA;AAAA,QAAA;AAAA,QA9BGA,EAAK;AAAA,MAiCb,CAAA;AAAA,IAAA,EAAA,CACH,EACF,CAAA;AAAA,EAAA,GACF;AAEJ;"}
1
+ {"version":3,"file":"component.js","sources":["../../../src/components/choice-list/component.tsx"],"sourcesContent":["\"use client\";\nimport { Command, CommandProps } from \"../cmdk\";\nimport { Input } from \"../input\";\nimport { useCallback, useMemo, useContext } from \"react\";\nimport { useCls, cn, reactNodeToString } from \"../utils\";\nimport { useControlledState } from \"../hooks\";\nimport { Radio } from \"../radio\";\nimport { Checkbox } from \"../checkbox\";\nimport { ScrollArea } from \"../scroll-area\";\n\nimport \"./style.css\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\nimport DisabledContext from \"antd/es/config-provider/DisabledContext\";\n\nexport type ChoiceListItem = {\n label: React.ReactNode;\n value?: string;\n};\n\nexport interface ChoiceListProps<M extends boolean = false>\n extends Omit<CommandProps, \"value\" | \"onChange\" | \"defaultValue\"> {\n items: ChoiceListItem[];\n multiple?: M;\n value?: M extends true ? string[] : string;\n defaultValue?: M extends true ? string[] : string;\n onChange?: (value: M extends true ? string[] : string) => void;\n searchProps?: React.ComponentProps<typeof Command.Input>;\n /**\n * Show select all option when in multiple mode\n * @default false\n */\n showSelectAll?: boolean;\n placeholder?: string;\n /**\n * Whether the choice list is disabled\n * @default false\n */\n disabled?: boolean;\n /**\n * Validation status\n */\n status?: \"error\" | \"warning\" | \"success\" | \"validating\";\n /**\n * Function to extract keywords from the item for search filtering\n * @default (item) => [item.value, reactNodeToString(item.label)]\n */\n getItemKeywords?: (item: ChoiceListItem) => string[];\n}\n\nexport const ChoiceList = <M extends boolean = false>({\n items,\n multiple,\n value,\n defaultValue,\n onChange,\n searchProps = { placeholder: \"Search...\" },\n showSelectAll = false,\n className,\n placeholder = \"Search\",\n disabled: disabledProp = false,\n status: statusProp,\n getItemKeywords,\n ...rest\n}: ChoiceListProps<M>) => {\n const [internalValue, setInternalValue] = useControlledState(\n value,\n onChange,\n defaultValue,\n );\n\n const usedValue = useMemo(() => {\n if (multiple) {\n // Ensure we always return an array for multiple mode\n if (Array.isArray(internalValue)) {\n return internalValue;\n }\n return internalValue ? [internalValue as string] : [];\n } else {\n // For single mode, convert to array for consistent usage\n if (Array.isArray(internalValue)) {\n return internalValue.length > 0 ? [internalValue[0]] : [];\n }\n return internalValue ? [internalValue as string] : [];\n }\n }, [internalValue, multiple]);\n\n // Get form context values\n const {\n status: contextStatus,\n } = useContext(FormItemInputContext);\n const contextDisabled = useContext(DisabledContext);\n\n // Merge context values with props\n const mergedStatus = statusProp || contextStatus;\n const disabled = disabledProp || contextDisabled;\n\n const cls = useCls();\n\n const handleSelectAll = useCallback(() => {\n if (multiple) {\n const allValues = items\n .map((item) => item.value)\n .filter(Boolean) as string[];\n setInternalValue(allValues as M extends true ? string[] : string);\n }\n }, [multiple, items, setInternalValue]);\n\n const handleDeselectAll = useCallback(() => {\n if (multiple) {\n setInternalValue([] as M extends true ? string[] : string);\n }\n }, [multiple, setInternalValue]);\n\n return (\n <Command \n className={cn(cls(\"choice-list\"), className)} \n data-disabled={disabled}\n data-status={mergedStatus}\n {...rest}\n >\n <FormItemInputContext.Provider value={{}}>\n <Command.Input\n render={\n // isolate the input from the form context\n <Input.Search\n allowClear\n disabled={disabled}\n className={cls(\"choice-list-search\")}\n placeholder={placeholder}\n />\n }\n {...searchProps}\n />\n </FormItemInputContext.Provider>\n {showSelectAll &&\n multiple &&\n items.length > 0 &&\n (() => {\n const allValues = items\n .map((item) => item.value)\n .filter(Boolean) as string[];\n const selectedFromAll = usedValue.filter((val) =>\n allValues.includes(val),\n );\n const checked =\n selectedFromAll.length === allValues.length && allValues.length > 0;\n const indeterminate =\n selectedFromAll.length > 0 &&\n selectedFromAll.length < allValues.length;\n\n return (\n <div\n className={cls(\"choice-list-item\")}\n onClick={() => {\n if (disabled) return;\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n }}\n >\n <Checkbox\n tabIndex={-1}\n checked={checked}\n indeterminate={indeterminate}\n disabled={disabled}\n >\n Select All\n </Checkbox>\n </div>\n );\n })()}\n <ScrollArea className={cls(\"choice-list-items\")} fadeEdges>\n <Command.List>\n <Command.Empty className={cls(\"choice-list-empty\")}>\n No results found.\n </Command.Empty>\n {items.map((item) => (\n <Command.Item\n key={item.value}\n className={cls(\"choice-list-item\")}\n keywords={getItemKeywords ? getItemKeywords(item) : [item.value || '', reactNodeToString(item.label)]}\n value={item.value}\n data-in-choice={item.value ? usedValue.includes(item.value) : false}\n onSelect={(newValue) => {\n if (disabled) return;\n if (multiple) {\n const newValues = usedValue.includes(newValue)\n ? usedValue.filter((value) => value !== newValue)\n : [...new Set([...usedValue, newValue])];\n setInternalValue(\n newValues as M extends true ? string[] : string,\n );\n } else {\n setInternalValue(\n newValue as M extends true ? string[] : string,\n );\n }\n }}\n >\n {multiple ? (\n <Checkbox\n tabIndex={-1}\n checked={item.value ? usedValue.includes(item.value) : false}\n disabled={disabled}\n >\n {item.label}\n </Checkbox>\n ) : (\n <Radio \n tabIndex={-1} \n checked={item.value ? usedValue.includes(item.value) : false}\n disabled={disabled}\n >\n {item.label}\n </Radio>\n )}\n </Command.Item>\n ))}\n </Command.List>\n </ScrollArea>\n </Command>\n );\n};\n"],"names":["ChoiceList","items","multiple","value","defaultValue","onChange","searchProps","showSelectAll","className","placeholder","disabledProp","statusProp","getItemKeywords","rest","internalValue","setInternalValue","useControlledState","usedValue","useMemo","contextStatus","useContext","FormItemInputContext","contextDisabled","DisabledContext","mergedStatus","disabled","cls","useCls","handleSelectAll","useCallback","allValues","item","handleDeselectAll","jsxs","Command","cn","jsx","Input","selectedFromAll","val","checked","indeterminate","Checkbox","ScrollArea","reactNodeToString","newValue","newValues","Radio"],"mappings":";;;;;;;;;;;;;;;AAiDO,MAAMA,KAAa,CAA4B;AAAA,EACpD,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc,EAAE,aAAa,YAAY;AAAA,EACzC,eAAAC,IAAgB;AAAA,EAChB,WAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAe;AAAA,EACzB,QAAQC;AAAA,EACR,iBAAAC;AAAA,EACA,GAAGC;AACL,MAA0B;AAClB,QAAA,CAACC,GAAeC,CAAgB,IAAIC;AAAA,IACxCb;AAAA,IACAE;AAAA,IACAD;AAAA,EACF,GAEMa,IAAYC,EAAQ,MACpBhB,IAEE,MAAM,QAAQY,CAAa,IACtBA,IAEFA,IAAgB,CAACA,CAAuB,IAAI,CAAC,IAGhD,MAAM,QAAQA,CAAa,IACtBA,EAAc,SAAS,IAAI,CAACA,EAAc,CAAC,CAAC,IAAI,CAAC,IAEnDA,IAAgB,CAACA,CAAuB,IAAI,CAAC,GAErD,CAACA,GAAeZ,CAAQ,CAAC,GAGtB;AAAA,IACJ,QAAQiB;AAAA,EAAA,IACNC,EAAWC,CAAoB,GAC7BC,IAAkBF,EAAWG,CAAe,GAG5CC,IAAeb,KAAcQ,GAC7BM,IAAWf,KAAgBY,GAE3BI,IAAMC,EAAO,GAEbC,IAAkBC,EAAY,MAAM;AACxC,QAAI3B,GAAU;AACN,YAAA4B,IAAY7B,EACf,IAAI,CA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U,SAASc,EAAK,KAAK,IAAI;AAAA,kBACvD,UAAAN;AAAA,kBAEC,UAAKM,EAAA;AAAA,gBAAA;AAAA,cAAA,IAGR,gBAAAK;AAAA,gBAACW;AAAA,gBAAA;AAAA,kBACC,UAAU;AAAA,kBACV,SAAShB,EAAK,QAAQd,EAAU,SAASc,EAAK,KAAK,IAAI;AAAA,kBACvD,UAAAN;AAAA,kBAEC,UAAKM,EAAA;AAAA,gBAAA;AAAA,cAAA;AAAA,YACR;AAAA,YApCGA,EAAK;AAAA,UAuCb,CAAA;AAAA,QAAA,EAAA,CACH,EACF,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
@@ -5,10 +5,10 @@ import { Highlight as J, themes as K } from "prism-react-renderer";
5
5
  import { useState as p, useEffect as Q, useCallback as I } from "react";
6
6
  import { ThemeProvider as R } from "../theme-provider/component.js";
7
7
  import './style.css';/* empty css */
8
- import { reactNodeToString as U } from "../utils/reactToString.js";
9
- import { WithAntdTokens as V } from "../utils/WithAntdTokens.js";
10
- import { Segmented as X } from "../segmented/component.js";
11
- import { useControlledState as Y } from "../hooks/useControlledState.js";
8
+ import { WithAntdTokens as U } from "../utils/WithAntdTokens.js";
9
+ import { Segmented as V } from "../segmented/component.js";
10
+ import { useControlledState as X } from "../hooks/useControlledState.js";
11
+ import { reactNodeToString as Y } from "../utils/reactToString.js";
12
12
  import { useCls as Z } from "../utils/antdUtils.js";
13
13
  import { clsx as H } from "../utils/cn.js";
14
14
  import { IconButton as N } from "../icon-button/component.js";
@@ -30,7 +30,7 @@ const vo = ({
30
30
  onCopy: C,
31
31
  ...A
32
32
  }) => {
33
- const [l, y] = Y(
33
+ const [l, y] = X(
34
34
  j,
35
35
  x,
36
36
  b
@@ -51,7 +51,7 @@ const vo = ({
51
51
  y
52
52
  ]);
53
53
  const [T, u] = p(a), [D, S] = p(!1), E = I(() => {
54
- const t = c || U(m);
54
+ const t = c || Y(m);
55
55
  try {
56
56
  navigator.clipboard.writeText(t).then(() => {
57
57
  u(g), S(!0), C && C(t);
@@ -63,13 +63,13 @@ const vo = ({
63
63
  u(a), S(!1);
64
64
  }, [a]), d = Z();
65
65
  return /* @__PURE__ */ o(R, { theme: "dark", children: /* @__PURE__ */ q(
66
- V,
66
+ U,
67
67
  {
68
68
  className: H(d("code-block"), O, e == null ? void 0 : e.root),
69
69
  ...A,
70
70
  children: [
71
71
  f && /* @__PURE__ */ o("div", { className: d("code-block-header", e == null ? void 0 : e.header), children: /* @__PURE__ */ o(
72
- X,
72
+ V,
73
73
  {
74
74
  value: l,
75
75
  onChange: y,
@@ -1,22 +1,22 @@
1
1
  "use client";
2
2
  import { jsx as e, jsxs as b } from "react/jsx-runtime";
3
- import { useCallback as w, useRef as Q, createElement as X } from "react";
3
+ import { useCallback as w, useRef as X, createElement as Y } from "react";
4
4
  import { Menu as P } from "@base-ui-components/react/menu";
5
- import { useControlled as Y } from "@base-ui-components/utils/useControlled";
6
- import { Popover as Z } from "@base-ui-components/react/popover";
5
+ import { useControlled as Z } from "@base-ui-components/utils/useControlled";
6
+ import { Popover as $ } from "@base-ui-components/react/popover";
7
7
  import { Command as g } from "../cmdk/index.js";
8
- import { FormItemInputContext as $ } from "antd/es/form/context";
8
+ import { FormItemInputContext as O } from "antd/es/form/context";
9
9
  import { PopupPanelSize as S } from "../popup-panel/constants.js";
10
- import { DropdownMenuItem as O } from "./item.js";
10
+ import { DropdownMenuItem as K } from "./item.js";
11
11
  import './style.css';/* empty css */
12
- import { DropdownMenuDivider as K } from "./divider.js";
13
- import { parseAntdPlacement as a } from "../utils/placement.js";
14
- import { Input as N } from "../input/component.js";
12
+ import { DropdownMenuDivider as a } from "./divider.js";
13
+ import { parseAntdPlacement as N } from "../utils/placement.js";
14
+ import { Input as s } from "../input/component.js";
15
15
  import { ScrollArea as _ } from "../scroll-area/component.js";
16
- import { DROPDOWN_COLLISION_AVOIDANCE as s } from "../utils/constants.js";
17
- import { useCls as oo, useAntdCssVarClassname as ro } from "../utils/antdUtils.js";
16
+ import { DROPDOWN_COLLISION_AVOIDANCE as oo } from "../utils/constants.js";
17
+ import { useCls as ro, useAntdCssVarClassname as no } from "../utils/antdUtils.js";
18
18
  import { clsx as u } from "../utils/cn.js";
19
- const Go = ({
19
+ const Mo = ({
20
20
  children: j,
21
21
  items: z,
22
22
  placement: B,
@@ -37,9 +37,10 @@ const Go = ({
37
37
  keepOpenOnSelect: I,
38
38
  highlightedItemKey: G,
39
39
  selectedItemKeys: h,
40
- showCheckbox: M
40
+ showCheckbox: M,
41
+ getItemKeywords: q
41
42
  }) => {
42
- const [q, x] = Y({
43
+ const [H, x] = Z({
43
44
  controlled: T,
44
45
  default: !1,
45
46
  name: "open"
@@ -48,7 +49,7 @@ const Go = ({
48
49
  x(r), v == null || v(r);
49
50
  },
50
51
  [x, v]
51
- ), d = oo(), L = ro(), R = a(B), H = Q(null), A = z.reduce((r, n) => (r.length === 0 && n.type !== "header" && r.push({
52
+ ), d = ro(), L = no(), R = N(B), J = X(null), A = z.reduce((r, n) => (r.length === 0 && n.type !== "header" && r.push({
52
53
  label: null,
53
54
  items: []
54
55
  }), n.type === "header" ? r.push({
@@ -56,7 +57,7 @@ const Go = ({
56
57
  items: []
57
58
  }) : (n.type === "item" || n.type === "divider") && r.length > 0 && r[r.length - 1].items.push(n), r), []), m = w(
58
59
  (r, n, p) => r.type === "item" ? /* @__PURE__ */ e(
59
- O,
60
+ K,
60
61
  {
61
62
  item: r,
62
63
  inCombobox: t,
@@ -69,11 +70,12 @@ const Go = ({
69
70
  r.onClick(i), I || l == null || l(!1);
70
71
  } : void 0,
71
72
  itemRender: E,
72
- showCheckbox: M
73
+ showCheckbox: M,
74
+ getItemKeywords: q
73
75
  },
74
76
  n + "-" + p
75
77
  ) : r.type === "divider" ? /* @__PURE__ */ e(
76
- K,
78
+ a,
77
79
  {
78
80
  inCombobox: t,
79
81
  className: o == null ? void 0 : o.separator
@@ -131,7 +133,7 @@ const Go = ({
131
133
  "group" + n
132
134
  ) : r.items.map((p, i) => m(p, n, i)),
133
135
  [d, o, m]
134
- ), J = w(
136
+ ), Q = w(
135
137
  () => t ? /* @__PURE__ */ b(
136
138
  g,
137
139
  {
@@ -139,13 +141,13 @@ const Go = ({
139
141
  disablePointerSelection: t,
140
142
  defaultValue: G ? String(G) : void 0,
141
143
  children: [
142
- /* @__PURE__ */ e($.Provider, { value: {}, children: /* @__PURE__ */ X(
144
+ /* @__PURE__ */ e(O.Provider, { value: {}, children: /* @__PURE__ */ Y(
143
145
  g.Input,
144
146
  {
145
147
  ...y,
146
148
  key: "search",
147
149
  render: /* @__PURE__ */ e(
148
- N,
150
+ s,
149
151
  {
150
152
  allowClear: !0,
151
153
  className: d("dropdown-menu-search"),
@@ -178,19 +180,19 @@ const Go = ({
178
180
  D,
179
181
  V
180
182
  ]
181
- ), f = t ? Z : P;
183
+ ), f = t ? $ : P;
182
184
  return /* @__PURE__ */ b(
183
185
  f.Root,
184
186
  {
185
187
  openOnHover: F,
186
- open: q,
188
+ open: H,
187
189
  onOpenChange: l,
188
190
  children: [
189
191
  /* @__PURE__ */ e(
190
192
  f.Trigger,
191
193
  {
192
194
  render: j,
193
- ref: H,
195
+ ref: J,
194
196
  className: u(
195
197
  d("dropdown-menu-trigger"),
196
198
  o == null ? void 0 : o.trigger,
@@ -205,7 +207,7 @@ const Go = ({
205
207
  align: R.align,
206
208
  sideOffset: 4,
207
209
  className: u(d("dropdown-menu-root"), o == null ? void 0 : o.root),
208
- collisionAvoidance: s,
210
+ collisionAvoidance: oo,
209
211
  children: /* @__PURE__ */ e(
210
212
  f.Popup,
211
213
  {
@@ -222,7 +224,7 @@ const Go = ({
222
224
  style: {
223
225
  "--size-width": k in S ? S[k] : void 0
224
226
  },
225
- children: J()
227
+ children: Q()
226
228
  }
227
229
  )
228
230
  }
@@ -232,6 +234,6 @@ const Go = ({
232
234
  );
233
235
  };
234
236
  export {
235
- Go as DropdownMenu
237
+ Mo as DropdownMenu
236
238
  };
237
239
  //# sourceMappingURL=component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sources":["../../../src/components/dropdown-menu/component.tsx"],"sourcesContent":["\"use client\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { useControlled } from \"@base-ui-components/utils/useControlled\";\nimport { Popover } from \"@base-ui-components/react/popover\";\nimport { type PopoverProps } from \"antd/es/popover\";\nimport { useCallback, useRef } from \"react\";\nimport {\n clsx,\n DROPDOWN_COLLISION_AVOIDANCE,\n parseAntdPlacement,\n useAntdCssVarClassname,\n useCls,\n} from \"../utils\";\nimport { Command } from \"../cmdk\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\nimport { DropdownMenuItem } from \"./item\";\n\nimport \"./style.css\";\nimport { DropdownMenuDivider } from \"./divider\";\n\nexport type DropdownMenuItemType =\n | {\n /**\n * The type of the menu item\n */\n type: \"item\";\n /**\n * The label of the menu item\n */\n label?: React.ReactNode;\n /**\n * Whether the menu item is disabled\n */\n disabled?: boolean;\n /**\n * The icon of the menu item\n */\n icon?: React.ReactNode;\n /**\n * The key of the menu item\n */\n key: React.Key;\n /**\n * The onClick event handler of the menu item\n */\n onClick?: React.HTMLAttributes<HTMLElement>[\"onClick\"];\n /**\n * The onMouseEnter event handler of the menu item\n */\n onMouseEnter?: React.HTMLAttributes<HTMLElement>[\"onMouseEnter\"];\n /**\n * The onMouseLeave event handler of the menu item\n */\n onMouseLeave?: React.HTMLAttributes<HTMLElement>[\"onMouseLeave\"];\n /**\n * The onMouseOver event handler of the menu item\n */\n onMouseOver?: React.HTMLAttributes<HTMLElement>[\"onMouseOver\"];\n /**\n * The onMouseOut event handler of the menu item\n */\n onMouseOut?: React.HTMLAttributes<HTMLElement>[\"onMouseOut\"];\n /**\n * The className of the menu item\n */\n className?: string;\n /**\n * Whether the menu item is a danger item\n */\n danger?: boolean;\n /**\n * The ref of the menu item\n */\n ref?: React.Ref<HTMLElement>;\n }\n | {\n /**\n * The type of the menu item\n */\n type: \"divider\";\n }\n | {\n /**\n * The type of the menu item\n */\n type: \"header\";\n /**\n * The title of the menu item\n */\n title?: React.ReactNode;\n /**\n * The className of the menu item\n */\n className?: string;\n };\n\nexport interface DropdownMenuProps {\n /** Array of menu items to be displayed in the dropdown */\n items: DropdownMenuItemType[];\n /** Custom render function for the trigger element */\n children?: React.ComponentProps<typeof Menu.Trigger>[\"render\"];\n /**\n * Placement of the dropdown relative to the trigger element\n * @default \"bottomLeft\"\n */\n placement?: PopoverProps[\"placement\"];\n /**\n * Whether to open the dropdown on hover instead of click\n * @default false\n */\n openOnHover?: boolean;\n /**\n * Controlled open state of the dropdown\n */\n open?: boolean;\n /**\n * Callback fired when the dropdown open state changes\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Additional CSS class for the dropdown component\n */\n className?: string;\n /**\n * Custom class names for different parts of the dropdown\n * @default {}\n */\n classNames?: {\n root?: string;\n trigger?: string;\n popup?: string;\n group?: string;\n groupLabel?: string;\n item?: string;\n itemIcon?: string;\n itemText?: string;\n separator?: string;\n positioner?: string;\n };\n /**\n * Custom render function for menu items\n */\n itemRender?: (\n item: DropdownMenuItemType,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /**\n * Whether to show search input\n * @default false\n */\n showSearch?: boolean;\n /**\n * Size of the dropdown menu\n * @default \"auto\"\n */\n size?: \"auto\" | keyof typeof PopupPanelSize;\n /**\n * Search placeholder\n */\n searchProps?: Omit<\n React.ComponentProps<typeof Command.Input>,\n \"size\" | \"ref\"\n >;\n /**\n * Whether to match the width of the popup with the trigger\n * @default false\n */\n popupMatchTriggerWidth?: boolean;\n\n /**\n * Content to display before the list\n */\n beforeList?: React.ReactNode;\n /**\n * Content to display after the list\n */\n afterList?: React.ReactNode;\n /**\n * Whether to keep the dropdown open when an item is selected\n * @default false\n */\n keepOpenOnSelect?: boolean;\n /**\n * Control the highlighted state of the menu item\n */\n highlightedItemKey?: React.Key;\n /**\n * Control the selected state of the menu item\n */\n selectedItemKeys?: React.Key[];\n /**\n * Whether to show checkbox\n * @default false\n */\n showCheckbox?: boolean;\n}\n\ninterface DropdownMenuGroup {\n label: React.ReactNode | null;\n items: DropdownMenuItemType[];\n}\n\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n searchProps = {\n placeholder: \"Search...\",\n },\n popupMatchTriggerWidth,\n beforeList,\n afterList,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n showCheckbox,\n}: DropdownMenuProps) => {\n const [open, setOpen] = useControlled({\n controlled: outsideOpen,\n default: false,\n name: \"open\",\n });\n const onOpenChange = useCallback(\n (newValue: boolean) => {\n setOpen(newValue);\n outsideOnOpenChange?.(newValue);\n },\n [setOpen, outsideOnOpenChange]\n );\n const cls = useCls();\n const antdCssVarClassname = useAntdCssVarClassname();\n const baseUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const itemGroups = items.reduce<DropdownMenuGroup[]>((acc, current) => {\n // If no groups exist yet and current item is not a header, create default group\n if (acc.length === 0 && current.type !== \"header\") {\n acc.push({\n label: null,\n items: [],\n });\n }\n\n // If it's a header, create a new group\n if (current.type === \"header\") {\n acc.push({\n label: current.title,\n items: [],\n });\n }\n // If it's an item and we have at least one group, add it to the last group's items\n else if (\n (current.type === \"item\" || current.type === \"divider\") &&\n acc.length > 0\n ) {\n acc[acc.length - 1].items.push(current);\n }\n // Skip dividers\n return acc;\n }, []);\n\n const renderMenuItem = useCallback(\n (item: DropdownMenuItemType, i: number, j: number) => {\n if (item.type === \"item\") {\n return (\n <DropdownMenuItem\n key={i + \"-\" + j}\n item={item}\n inCombobox={showSearch}\n selected={selectedItemKeys?.includes(item.key)}\n onSelect={\n showSearch\n ? () => {\n const e = new MouseEvent(\"click\", {\n bubbles: true,\n cancelable: true,\n }) as unknown as React.MouseEvent<HTMLElement, MouseEvent>;\n item.onClick(e);\n if (!keepOpenOnSelect) onOpenChange?.(false);\n }\n : undefined\n }\n itemRender={itemRender}\n showCheckbox={showCheckbox}\n />\n );\n } else if (item.type === \"divider\") {\n return (\n <DropdownMenuDivider\n key={i + \"-\" + j}\n inCombobox={showSearch}\n className={classNames?.separator}\n />\n );\n }\n return null;\n },\n [\n classNames,\n itemRender,\n onOpenChange,\n showSearch,\n keepOpenOnSelect,\n selectedItemKeys,\n showCheckbox,\n ]\n );\n\n const renderGroup = useCallback(\n (group: DropdownMenuGroup, index: number) => (\n <Menu.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n >\n {group.label && (\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n )}\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Menu.Group>\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderGroupShowSearch = useCallback(\n (group: DropdownMenuGroup, index: number) =>\n group.label ? (\n <Command.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n heading={\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n }\n >\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Command.Group>\n ) : (\n group.items.map((item, j) => renderMenuItem(item, index, j))\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderMenuInner = useCallback(\n () =>\n showSearch ? (\n <Command\n className={cls(\"dropdown-menu-container\")}\n disablePointerSelection={showSearch}\n defaultValue={\n highlightedItemKey ? String(highlightedItemKey) : undefined\n }\n >\n <FormItemInputContext.Provider value={{}}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input\n allowClear\n className={cls(\"dropdown-menu-search\")}\n placeholder=\"Search\"\n />\n }\n />\n </FormItemInputContext.Provider>\n {beforeList}\n <ScrollArea fadeEdges>\n <Command.List className={cls(\"dropdown-menu-list\")}>\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n No results found.\n </Command.Empty>\n {itemGroups.map(renderGroupShowSearch)}\n </Command.List>\n </ScrollArea>\n {afterList}\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n {beforeList}\n <ScrollArea fadeEdges>{itemGroups.map(renderGroup)}</ScrollArea>\n {afterList}\n </div>\n ),\n [\n showSearch,\n cls,\n highlightedItemKey,\n searchProps,\n beforeList,\n itemGroups,\n renderGroupShowSearch,\n afterList,\n renderGroup,\n ]\n );\n\n const BaseComponent = showSearch ? Popover : Menu;\n\n return (\n <BaseComponent.Root\n openOnHover={openOnHover}\n open={open}\n onOpenChange={onOpenChange}\n >\n <BaseComponent.Trigger\n render={children}\n ref={buttonRef}\n className={clsx(\n cls(\"dropdown-menu-trigger\"),\n classNames?.trigger,\n antdCssVarClassname\n )}\n />\n <BaseComponent.Portal>\n <BaseComponent.Positioner\n side={baseUIPlacement.side}\n align={baseUIPlacement.align}\n sideOffset={4}\n className={clsx(cls(\"dropdown-menu-root\"), classNames?.root)}\n collisionAvoidance={DROPDOWN_COLLISION_AVOIDANCE}\n >\n <BaseComponent.Popup\n className={clsx(\n cls(\n \"dropdown-menu\",\n showCheckbox && \"dropdown-menu-show-checkbox\",\n popupMatchTriggerWidth && \"dropdown-menu-match-trigger-width\"\n ),\n className,\n classNames?.popup,\n antdCssVarClassname\n )}\n style={\n {\n \"--size-width\":\n size in PopupPanelSize ? PopupPanelSize[size] : undefined,\n } as React.CSSProperties\n }\n >\n {renderMenuInner()}\n </BaseComponent.Popup>\n </BaseComponent.Positioner>\n </BaseComponent.Portal>\n </BaseComponent.Root>\n );\n};\n"],"names":["DropdownMenu","children","items","placement","openOnHover","outsideOpen","outsideOnOpenChange","className","itemRender","classNames","size","showSearch","searchProps","popupMatchTriggerWidth","beforeList","afterList","keepOpenOnSelect","highlightedItemKey","selectedItemKeys","showCheckbox","open","setOpen","useControlled","onOpenChange","useCallback","newValue","cls","useCls","antdCssVarClassname","useAntdCssVarClassname","baseUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","acc","current","renderMenuItem","item","i","j","jsx","DropdownMenuItem","e","DropdownMenuDivider","renderGroup","group","index","jsxs","Menu","clsx","renderGroupShowSearch","Command","renderMenuInner","FormItemInputContext","createElement","Input","ScrollArea","BaseComponent","Popover","DROPDOWN_COLLISION_AVOIDANCE","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;;AA+MO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,IACZ,aAAa;AAAA,EACf;AAAA,EACA,wBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,cAAAC;AACF,MAAyB;AACvB,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAc;AAAA,IACpC,YAAYjB;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,EAAA,CACP,GACKkB,IAAeC;AAAA,IACnB,CAACC,MAAsB;AACrB,MAAAJ,EAAQI,CAAQ,GAChBnB,KAAA,QAAAA,EAAsBmB;AAAA,IACxB;AAAA,IACA,CAACJ,GAASf,CAAmB;AAAA,EAC/B,GACMoB,IAAMC,GAAO,GACbC,IAAsBC,GAAuB,GAC7CC,IAAkBC,EAAmB5B,CAAS,GAC9C6B,IAAYC,EAA0B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MACAiB;AAAA,MACApC;AAAA,MACA8B;AAAA,IAAA;AAAA,EAEJ,GAEMa,IAAgB/C,IAAagD,IAAUV;AAG3C,SAAA,gBAAAD;AAAA,IAACU,EAAc;AAAA,IAAd;AAAA,MACC,aAAAtD;AAAA,MACA,MAAAgB;AAAA,MACA,cAAAG;AAAA,MAEA,UAAA;AAAA,QAAA,gBAAAkB;AAAA,UAACiB,EAAc;AAAA,UAAd;AAAA,YACC,QAAQzD;AAAA,YACR,KAAK+B;AAAA,YACL,WAAWkB;AAAA,cACTxB,EAAI,uBAAuB;AAAA,cAC3BjB,KAAA,gBAAAA,EAAY;AAAA,cACZmB;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,QACA,gBAAAa,EAACiB,EAAc,QAAd,EACC,UAAA,gBAAAjB;AAAA,UAACiB,EAAc;AAAA,UAAd;AAAA,YACC,MAAM5B,EAAgB;AAAA,YACtB,OAAOA,EAAgB;AAAA,YACvB,YAAY;AAAA,YACZ,WAAWoB,EAAKxB,EAAI,oBAAoB,GAAGjB,KAAA,gBAAAA,EAAY,IAAI;AAAA,YAC3D,oBAAoBmD;AAAA,YAEpB,UAAA,gBAAAnB;AAAA,cAACiB,EAAc;AAAA,cAAd;AAAA,gBACC,WAAWR;AAAA,kBACTxB;AAAA,oBACE;AAAA,oBACAP,KAAgB;AAAA,oBAChBN,KAA0B;AAAA,kBAC5B;AAAA,kBACAN;AAAA,kBACAE,KAAA,gBAAAA,EAAY;AAAA,kBACZmB;AAAA,gBACF;AAAA,gBACA,OACE;AAAA,kBACE,gBACElB,KAAQmD,IAAiBA,EAAenD,CAAI,IAAI;AAAA,gBACpD;AAAA,gBAGD,UAAgB2C,EAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACnB;AAAA,QAAA,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
1
+ {"version":3,"file":"component.js","sources":["../../../src/components/dropdown-menu/component.tsx"],"sourcesContent":["\"use client\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { useControlled } from \"@base-ui-components/utils/useControlled\";\nimport { Popover } from \"@base-ui-components/react/popover\";\nimport { type PopoverProps } from \"antd/es/popover\";\nimport { useCallback, useRef } from \"react\";\nimport {\n clsx,\n DROPDOWN_COLLISION_AVOIDANCE,\n parseAntdPlacement,\n useAntdCssVarClassname,\n useCls,\n} from \"../utils\";\nimport { Command } from \"../cmdk\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\nimport { DropdownMenuItem } from \"./item\";\n\nimport \"./style.css\";\nimport { DropdownMenuDivider } from \"./divider\";\n\nexport type DropdownMenuItemType =\n | {\n /**\n * The type of the menu item\n */\n type: \"item\";\n /**\n * The label of the menu item\n */\n label?: React.ReactNode;\n /**\n * Whether the menu item is disabled\n */\n disabled?: boolean;\n /**\n * The icon of the menu item\n */\n icon?: React.ReactNode;\n /**\n * The key of the menu item\n */\n key: React.Key;\n /**\n * The onClick event handler of the menu item\n */\n onClick?: React.HTMLAttributes<HTMLElement>[\"onClick\"];\n /**\n * The onMouseEnter event handler of the menu item\n */\n onMouseEnter?: React.HTMLAttributes<HTMLElement>[\"onMouseEnter\"];\n /**\n * The onMouseLeave event handler of the menu item\n */\n onMouseLeave?: React.HTMLAttributes<HTMLElement>[\"onMouseLeave\"];\n /**\n * The onMouseOver event handler of the menu item\n */\n onMouseOver?: React.HTMLAttributes<HTMLElement>[\"onMouseOver\"];\n /**\n * The onMouseOut event handler of the menu item\n */\n onMouseOut?: React.HTMLAttributes<HTMLElement>[\"onMouseOut\"];\n /**\n * The className of the menu item\n */\n className?: string;\n /**\n * Whether the menu item is a danger item\n */\n danger?: boolean;\n /**\n * The ref of the menu item\n */\n ref?: React.Ref<HTMLElement>;\n }\n | {\n /**\n * The type of the menu item\n */\n type: \"divider\";\n }\n | {\n /**\n * The type of the menu item\n */\n type: \"header\";\n /**\n * The title of the menu item\n */\n title?: React.ReactNode;\n /**\n * The className of the menu item\n */\n className?: string;\n };\n\nexport interface DropdownMenuProps {\n /** Array of menu items to be displayed in the dropdown */\n items: DropdownMenuItemType[];\n /** Custom render function for the trigger element */\n children?: React.ComponentProps<typeof Menu.Trigger>[\"render\"];\n /**\n * Placement of the dropdown relative to the trigger element\n * @default \"bottomLeft\"\n */\n placement?: PopoverProps[\"placement\"];\n /**\n * Whether to open the dropdown on hover instead of click\n * @default false\n */\n openOnHover?: boolean;\n /**\n * Controlled open state of the dropdown\n */\n open?: boolean;\n /**\n * Callback fired when the dropdown open state changes\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Additional CSS class for the dropdown component\n */\n className?: string;\n /**\n * Custom class names for different parts of the dropdown\n * @default {}\n */\n classNames?: {\n root?: string;\n trigger?: string;\n popup?: string;\n group?: string;\n groupLabel?: string;\n item?: string;\n itemIcon?: string;\n itemText?: string;\n separator?: string;\n positioner?: string;\n };\n /**\n * Custom render function for menu items\n */\n itemRender?: (\n item: DropdownMenuItemType,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /**\n * Whether to show search input\n * @default false\n */\n showSearch?: boolean;\n /**\n * Size of the dropdown menu\n * @default \"auto\"\n */\n size?: \"auto\" | keyof typeof PopupPanelSize;\n /**\n * Search placeholder\n */\n searchProps?: Omit<\n React.ComponentProps<typeof Command.Input>,\n \"size\" | \"ref\"\n >;\n /**\n * Whether to match the width of the popup with the trigger\n * @default false\n */\n popupMatchTriggerWidth?: boolean;\n\n /**\n * Content to display before the list\n */\n beforeList?: React.ReactNode;\n /**\n * Content to display after the list\n */\n afterList?: React.ReactNode;\n /**\n * Whether to keep the dropdown open when an item is selected\n * @default false\n */\n keepOpenOnSelect?: boolean;\n /**\n * Control the highlighted state of the menu item\n */\n highlightedItemKey?: React.Key;\n /**\n * Control the selected state of the menu item\n */\n selectedItemKeys?: React.Key[];\n /**\n * Whether to show checkbox\n * @default false\n */\n showCheckbox?: boolean;\n /**\n * Function to extract keywords from the item for search filtering\n * @default (item) => [String(item.key), reactNodeToString(item.label)]\n */\n getItemKeywords?: (item: DropdownMenuItemType & { type: \"item\" }) => string[];\n}\n\ninterface DropdownMenuGroup {\n label: React.ReactNode | null;\n items: DropdownMenuItemType[];\n}\n\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n searchProps = {\n placeholder: \"Search...\",\n },\n popupMatchTriggerWidth,\n beforeList,\n afterList,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n showCheckbox,\n getItemKeywords,\n}: DropdownMenuProps) => {\n const [open, setOpen] = useControlled({\n controlled: outsideOpen,\n default: false,\n name: \"open\",\n });\n const onOpenChange = useCallback(\n (newValue: boolean) => {\n setOpen(newValue);\n outsideOnOpenChange?.(newValue);\n },\n [setOpen, outsideOnOpenChange]\n );\n const cls = useCls();\n const antdCssVarClassname = useAntdCssVarClassname();\n const baseUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const itemGroups = items.reduce<DropdownMenuGroup[]>((acc, current) => {\n // If no groups exist yet and current item is not a header, create default group\n if (acc.length === 0 && current.type !== \"header\") {\n acc.push({\n label: null,\n items: [],\n });\n }\n\n // If it's a header, create a new group\n if (current.type === \"header\") {\n acc.push({\n label: current.title,\n items: [],\n });\n }\n // If it's an item and we have at least one group, add it to the last group's items\n else if (\n (current.type === \"item\" || current.type === \"divider\") &&\n acc.length > 0\n ) {\n acc[acc.length - 1].items.push(current);\n }\n // Skip dividers\n return acc;\n }, []);\n\n const renderMenuItem = useCallback(\n (item: DropdownMenuItemType, i: number, j: number) => {\n if (item.type === \"item\") {\n return (\n <DropdownMenuItem\n key={i + \"-\" + j}\n item={item}\n inCombobox={showSearch}\n selected={selectedItemKeys?.includes(item.key)}\n onSelect={\n showSearch\n ? () => {\n const e = new MouseEvent(\"click\", {\n bubbles: true,\n cancelable: true,\n }) as unknown as React.MouseEvent<HTMLElement, MouseEvent>;\n item.onClick(e);\n if (!keepOpenOnSelect) onOpenChange?.(false);\n }\n : undefined\n }\n itemRender={itemRender}\n showCheckbox={showCheckbox}\n getItemKeywords={getItemKeywords}\n />\n );\n } else if (item.type === \"divider\") {\n return (\n <DropdownMenuDivider\n key={i + \"-\" + j}\n inCombobox={showSearch}\n className={classNames?.separator}\n />\n );\n }\n return null;\n },\n [\n classNames,\n itemRender,\n onOpenChange,\n showSearch,\n keepOpenOnSelect,\n selectedItemKeys,\n showCheckbox,\n ]\n );\n\n const renderGroup = useCallback(\n (group: DropdownMenuGroup, index: number) => (\n <Menu.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n >\n {group.label && (\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n )}\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Menu.Group>\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderGroupShowSearch = useCallback(\n (group: DropdownMenuGroup, index: number) =>\n group.label ? (\n <Command.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n heading={\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n }\n >\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Command.Group>\n ) : (\n group.items.map((item, j) => renderMenuItem(item, index, j))\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderMenuInner = useCallback(\n () =>\n showSearch ? (\n <Command\n className={cls(\"dropdown-menu-container\")}\n disablePointerSelection={showSearch}\n defaultValue={\n highlightedItemKey ? String(highlightedItemKey) : undefined\n }\n >\n <FormItemInputContext.Provider value={{}}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input\n allowClear\n className={cls(\"dropdown-menu-search\")}\n placeholder=\"Search\"\n />\n }\n />\n </FormItemInputContext.Provider>\n {beforeList}\n <ScrollArea fadeEdges>\n <Command.List className={cls(\"dropdown-menu-list\")}>\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n No results found.\n </Command.Empty>\n {itemGroups.map(renderGroupShowSearch)}\n </Command.List>\n </ScrollArea>\n {afterList}\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n {beforeList}\n <ScrollArea fadeEdges>{itemGroups.map(renderGroup)}</ScrollArea>\n {afterList}\n </div>\n ),\n [\n showSearch,\n cls,\n highlightedItemKey,\n searchProps,\n beforeList,\n itemGroups,\n renderGroupShowSearch,\n afterList,\n renderGroup,\n ]\n );\n\n const BaseComponent = showSearch ? Popover : Menu;\n\n return (\n <BaseComponent.Root\n openOnHover={openOnHover}\n open={open}\n onOpenChange={onOpenChange}\n >\n <BaseComponent.Trigger\n render={children}\n ref={buttonRef}\n className={clsx(\n cls(\"dropdown-menu-trigger\"),\n classNames?.trigger,\n antdCssVarClassname\n )}\n />\n <BaseComponent.Portal>\n <BaseComponent.Positioner\n side={baseUIPlacement.side}\n align={baseUIPlacement.align}\n sideOffset={4}\n className={clsx(cls(\"dropdown-menu-root\"), classNames?.root)}\n collisionAvoidance={DROPDOWN_COLLISION_AVOIDANCE}\n >\n <BaseComponent.Popup\n className={clsx(\n cls(\n \"dropdown-menu\",\n showCheckbox && \"dropdown-menu-show-checkbox\",\n popupMatchTriggerWidth && \"dropdown-menu-match-trigger-width\"\n ),\n className,\n classNames?.popup,\n antdCssVarClassname\n )}\n style={\n {\n \"--size-width\":\n size in PopupPanelSize ? PopupPanelSize[size] : undefined,\n } as React.CSSProperties\n }\n >\n {renderMenuInner()}\n </BaseComponent.Popup>\n </BaseComponent.Positioner>\n </BaseComponent.Portal>\n </BaseComponent.Root>\n );\n};\n"],"names":["DropdownMenu","children","items","placement","openOnHover","outsideOpen","outsideOnOpenChange","className","itemRender","classNames","size","showSearch","searchProps","popupMatchTriggerWidth","beforeList","afterList","keepOpenOnSelect","highlightedItemKey","selectedItemKeys","showCheckbox","getItemKeywords","open","setOpen","useControlled","onOpenChange","useCallback","newValue","cls","useCls","antdCssVarClassname","useAntdCssVarClassname","baseUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","acc","current","renderMenuItem","item","i","j","jsx","DropdownMenuItem","e","DropdownMenuDivider","renderGroup","group","index","jsxs","Menu","clsx","renderGroupShowSearch","Command","renderMenuInner","FormItemInputContext","createElement","Input","ScrollArea","BaseComponent","Popover","DROPDOWN_COLLISION_AVOIDANCE","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;;AAoNO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,IACZ,aAAa;AAAA,EACf;AAAA,EACA,wBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,cAAAC;AAAA,EACA,iBAAAC;AACF,MAAyB;AACvB,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAc;AAAA,IACpC,YAAYlB;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,EAAA,CACP,GACKmB,IAAeC;AAAA,IACnB,CAACC,MAAsB;AACrB,MAAAJ,EAAQI,CAAQ,GAChBpB,KAAA,QAAAA,EAAsBoB;AAAA,IACxB;AAAA,IACA,CAACJ,GAAShB,CAAmB;AAAA,EAC/B,GACMqB,IAAMC,GAAO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