@bioturing/components 0.30.0 → 0.31.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 (31) hide show
  1. package/dist/components/choice-list/component.js +26 -28
  2. package/dist/components/choice-list/component.js.map +1 -1
  3. package/dist/components/code-block/component.js +10 -10
  4. package/dist/components/combobox/component.js +113 -112
  5. package/dist/components/combobox/component.js.map +1 -1
  6. package/dist/components/command-palette/component.js +79 -0
  7. package/dist/components/command-palette/component.js.map +1 -0
  8. package/dist/components/command-palette/style.css +1 -0
  9. package/dist/components/dropdown-menu/component.js +117 -189
  10. package/dist/components/dropdown-menu/component.js.map +1 -1
  11. package/dist/components/dropdown-menu/item.css +1 -1
  12. package/dist/components/dropdown-menu/item.js +50 -37
  13. package/dist/components/dropdown-menu/item.js.map +1 -1
  14. package/dist/components/dropdown-menu/style.css +1 -1
  15. package/dist/components/dropdown-menu/useDropdownMenu.js +124 -0
  16. package/dist/components/dropdown-menu/useDropdownMenu.js.map +1 -0
  17. package/dist/components/keyboard-shortcut/component.js +72 -0
  18. package/dist/components/keyboard-shortcut/component.js.map +1 -0
  19. package/dist/components/keyboard-shortcut/style.css +1 -0
  20. package/dist/components/loader/component.js +15 -0
  21. package/dist/components/loader/component.js.map +1 -0
  22. package/dist/components/loader/style.css +1 -0
  23. package/dist/components/popup-panel/style.css +1 -1
  24. package/dist/components/theme-provider/style.css +1 -1
  25. package/dist/components/toast/style.css +1 -1
  26. package/dist/index.d.ts +180 -51
  27. package/dist/index.js +203 -197
  28. package/dist/index.js.map +1 -1
  29. package/dist/metadata.js +47 -2
  30. package/dist/metadata.js.map +1 -1
  31. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"component.js","sources":["../../../src/components/combobox/component.tsx"],"sourcesContent":["\"use client\";\nimport React, {\n forwardRef,\n useCallback,\n useMemo,\n useState,\n useContext,\n} from \"react\";\nimport { useControlled } from \"@base-ui-components/utils/useControlled\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\nimport { ValidateStatus } from \"antd/es/form/FormItem\";\nimport DisabledContext from \"antd/es/config-provider/DisabledContext\";\nimport { clsx, useCls } from \"../utils\";\nimport { SelectTrigger } from \"../select-trigger\";\nimport {\n DropdownMenu,\n DropdownMenuProps,\n DropdownMenuItem,\n type DropdownMenuItemType,\n} from \"../dropdown-menu\";\nimport type { PopoverProps } from \"antd/es/popover\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { useControlledState } from \"../hooks\";\nimport { DropdownMenuDivider } from \"../dropdown-menu/divider\";\n\nexport interface ComboboxOption {\n value: string | number;\n label: React.ReactNode;\n disabled?: boolean;\n icon?: React.ReactNode;\n}\n\nexport interface ComboboxProps {\n /** Array of options to be displayed in the combobox */\n options?: ComboboxOption[];\n /** Current value of the combobox */\n value?: string | number | Array<string | number>;\n /** Default value when uncontrolled */\n defaultValue?: string | number | Array<string | number>;\n /** Callback when value changes */\n onChange?: (value: string | number | Array<string | number>) => void;\n /** Placeholder text for the input */\n placeholder?: string;\n /** Whether the combobox is disabled */\n disabled?: boolean;\n /** Validation status */\n status?: ValidateStatus;\n /** Whether to allow clearing the selection */\n allowClear?: boolean;\n /** Whether to allow multiple selections */\n multiple?: boolean;\n /** Maximum number of tags to show */\n maxTagCount?: number;\n /** Whether to show search functionality */\n showSearch?: boolean;\n /** Controlled open state */\n open?: boolean;\n /** Callback when open state changes */\n onOpenChange?: (open: boolean) => void;\n /** Placement of the dropdown */\n placement?: PopoverProps[\"placement\"];\n /** Custom className for the component */\n className?: string;\n /** Custom class names for different parts */\n classNames?: {\n trigger?: string;\n input?: string;\n option?: string;\n optionIcon?: string;\n optionText?: string;\n };\n /** Size of the combobox */\n size?: \"small\" | \"middle\" | \"large\";\n /** Loading state */\n loading?: boolean;\n /** Custom render for options */\n optionRender?: (\n option: ComboboxOption,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /** Filter function for search */\n filterOption?: boolean | ((input: string, option: ComboboxOption) => boolean);\n /** Callback when search input changes */\n onSearch?: (value: string) => void;\n /** Custom dropdown render */\n dropdownRender?: (menu: React.ReactElement) => React.ReactElement;\n /** Custom clear icon */\n clearIcon?: React.ReactNode;\n /** Custom suffix icon */\n suffixIcon?: React.ReactNode;\n /**\n * Props to pass to the dropdown menu\n */\n dropdownMenuProps?: DropdownMenuProps;\n /**\n * Props to pass to the combobox trigger\n */\n triggerProps?: React.ComponentPropsWithoutRef<typeof SelectTrigger>;\n searchProps?: {\n placeholder?: string;\n onValueChange?: (value: string) => void;\n value?: string;\n };\n /**\n * Show selection summary instead of individual tags when multiple\n * @default false\n */\n showSelectionSummary?: boolean;\n /**\n * Render function for the selection summary in multiple case\n * @default (selectedValues) => `${selectedValues.length} items selected`\n */\n selectionSummaryRender?: (\n selectedValues: Array<string | number>\n ) => React.ReactNode;\n /**\n * Show select all option when in multiple mode\n * @default false\n */\n showSelectAll?: boolean;\n /**\n * Render function for the select all option\n */\n selectAllRender?: (props: {\n onSelectAll: () => void;\n onDeselectAll: () => void;\n checked: boolean;\n indeterminate: boolean;\n }) => React.ReactNode;\n}\n\nconst ComboboxInner = (\n {\n options = [],\n value: controlledValue,\n defaultValue,\n onChange,\n placeholder = \"Select...\",\n disabled: disabledProp = false,\n status: statusProp,\n allowClear = false,\n multiple = false,\n maxTagCount,\n showSearch = true,\n open: controlledOpen,\n onOpenChange,\n placement = \"bottomLeft\",\n className,\n classNames,\n size = \"middle\",\n loading: _loading = false,\n optionRender,\n filterOption = true,\n onSearch,\n dropdownRender,\n clearIcon,\n suffixIcon,\n dropdownMenuProps,\n triggerProps,\n searchProps,\n showSelectionSummary = false,\n selectionSummaryRender,\n showSelectAll = false,\n selectAllRender,\n ...rest\n }: ComboboxProps,\n ref: React.ForwardedRef<HTMLDivElement>\n) => {\n const [initialDefaultValue] = useState(\n defaultValue !== undefined ? defaultValue : multiple ? [] : undefined\n );\n const [value, setValue] = useControlled({\n controlled: controlledValue,\n default: initialDefaultValue,\n name: \"value\",\n });\n\n const [open, setOpen] = useControlledState(\n controlledOpen,\n onOpenChange,\n false\n );\n const [searchValue, setSearchValue] = useState(\"\");\n const cls = useCls();\n\n // Get form context values\n const {\n status: contextStatus,\n // hasFeedback,\n // feedbackIcon,\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 handleValueChange = useCallback(\n (newValue: string | number | Array<string | number>) => {\n setValue(newValue);\n onChange?.(newValue);\n },\n [setValue, onChange]\n );\n\n const handleOptionSelect = useCallback(\n (optionValue: string | number) => {\n if (multiple) {\n const currentValues = Array.isArray(value) ? value : [];\n const newValues = currentValues.includes(optionValue)\n ? currentValues.filter((v) => v !== optionValue)\n : [...currentValues, optionValue];\n handleValueChange(newValues);\n } else {\n handleValueChange(optionValue);\n // onOpenChange?.(false);\n }\n },\n [multiple, value, handleValueChange]\n );\n\n const handleSearchChange = useCallback(\n (newValue: string) => {\n setSearchValue(newValue);\n onSearch?.(newValue);\n },\n [onSearch]\n );\n\n // Check if option is selected\n const isSelected = useCallback(\n (optionValue: string | number) => {\n if (multiple) {\n return Array.isArray(value) && value.includes(optionValue);\n }\n return value === optionValue;\n },\n [multiple, value]\n );\n\n // Filter options based on search\n const filteredOptions = useMemo(() => {\n if (!showSearch || !searchValue) return options;\n\n return options.filter((option) => {\n if (typeof filterOption === \"function\") {\n return filterOption(searchValue, option);\n }\n if (filterOption === false) return true;\n\n const label =\n typeof option.label === \"string\" ? option.label : String(option.value);\n return label.toLowerCase().includes(searchValue.toLowerCase());\n });\n }, [options, showSearch, searchValue, filterOption]);\n\n const handleSelectAll = useCallback(() => {\n if (multiple) {\n const allValues = filteredOptions.map((option) => option.value);\n handleValueChange(allValues);\n }\n }, [multiple, filteredOptions, handleValueChange]);\n\n const handleDeselectAll = useCallback(() => {\n if (multiple) {\n handleValueChange([]);\n }\n }, [multiple, handleValueChange]);\n\n // Convert options to DropdownMenu items\n const dropdownItems: DropdownMenuItemType[] = useMemo(() => {\n return filteredOptions.map((option) => {\n return {\n type: \"item\",\n key: option.value,\n icon: option.icon,\n label: option.label,\n disabled: option.disabled,\n onClick: () => !option.disabled && handleOptionSelect(option.value),\n };\n });\n }, [filteredOptions, handleOptionSelect]);\n\n // Select all component for beforeList\n const selectAllComponent = useMemo(() => {\n if (!showSelectAll || !multiple || filteredOptions.length === 0) {\n return null;\n }\n\n const selectedValues = Array.isArray(value) ? value : [];\n const filteredOptionValues = filteredOptions.map((opt) => opt.value);\n const selectedFromFiltered = selectedValues.filter((val) =>\n filteredOptionValues.includes(val)\n );\n const checked =\n selectedFromFiltered.length === filteredOptions.length &&\n filteredOptions.length > 0;\n const indeterminate =\n selectedFromFiltered.length > 0 &&\n selectedFromFiltered.length < filteredOptions.length;\n\n const selectAllItem: DropdownMenuItemType & { type: \"item\" } = {\n type: \"item\",\n key: \"select_all\",\n label: \"Select All\",\n onClick: () => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n },\n };\n\n return (\n <>\n <DropdownMenuItem\n key=\"select_all\"\n item={selectAllItem}\n inCombobox={showSearch}\n selected={checked}\n showCheckbox\n indeterminate={indeterminate}\n renderAsNativeElement\n onSelect={() => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n }}\n />\n <DropdownMenuDivider />\n </>\n );\n }, [\n showSelectAll,\n multiple,\n filteredOptions,\n value,\n showSearch,\n handleDeselectAll,\n handleSelectAll,\n ]);\n\n // Prepare trigger data\n const selectedValues = useMemo(() => {\n return Array.isArray(value) ? value : value ? [value] : [];\n }, [value]);\n const selectedOptions = selectedValues\n .map((val) => options.find((opt) => opt.value === val))\n .filter(Boolean);\n\n // Generate display value and prefix for SelectTrigger\n const { displayValue, displayPrefix } = useMemo(() => {\n if (selectedOptions.length === 0) {\n return { displayValue: undefined, displayPrefix: undefined };\n }\n\n if (multiple) {\n const summaryText = `${selectedOptions.length} ${\n selectedOptions.length === 1 ? \"item\" : \"items\"\n } selected`;\n if (showSelectionSummary) {\n if (selectionSummaryRender) {\n return {\n displayValue: selectionSummaryRender(selectedValues),\n displayPrefix: undefined,\n };\n }\n // Default summary with icons\n return {\n displayValue: summaryText,\n // TODO: Create icon component for multiple selection summary\n displayPrefix: undefined,\n };\n }\n // For non-summary multiple selection\n return selectedOptions.length === 1\n ? {\n displayValue: selectedOptions[0].label,\n displayPrefix: selectedOptions[0].icon,\n }\n : {\n displayValue: summaryText,\n displayPrefix: undefined,\n };\n }\n\n // Single selection\n const selectedOption = selectedOptions[0];\n return {\n displayValue: selectedOption?.label,\n displayPrefix: selectedOption?.icon,\n };\n }, [\n selectedOptions,\n multiple,\n showSelectionSummary,\n selectionSummaryRender,\n selectedValues,\n ]);\n\n return (\n <div ref={ref} className={clsx(cls(\"combobox\"), className)} {...rest}>\n <DropdownMenu\n items={dropdownItems}\n open={open}\n onOpenChange={setOpen}\n placement={placement}\n showSearch={showSearch}\n searchProps={{\n placeholder: \"Search options...\",\n onValueChange: handleSearchChange,\n value: searchValue,\n ...searchProps,\n }}\n className={clsx(cls(\"combobox-dropdown\"))}\n classNames={{\n trigger: clsx(cls(\"combobox-trigger-wrapper\")),\n popup: clsx(cls(\"combobox-popup\")),\n item: clsx(cls(\"combobox-option\"), classNames?.option),\n ...classNames,\n }}\n popupMatchTriggerWidth\n keepOpenOnSelect={multiple}\n highlightedItemKey={multiple ? undefined : selectedValues[0]}\n showCheckbox={multiple}\n beforeList={selectAllComponent}\n selectedItemKeys={selectedValues}\n {...dropdownMenuProps}\n >\n <SelectTrigger\n value={displayValue}\n prefix={displayPrefix}\n placeholder={placeholder}\n disabled={disabled}\n status={mergedStatus}\n open={open}\n size={size}\n allowClear={allowClear}\n suffixIcon={suffixIcon}\n clearIcon={clearIcon}\n classNames={{\n trigger: classNames?.trigger,\n ...triggerProps?.classNames,\n }}\n onClear={() => handleValueChange(multiple ? [] : undefined)}\n onOpenChange={setOpen}\n role=\"combobox\"\n {...triggerProps}\n />\n </DropdownMenu>\n </div>\n );\n};\n\nconst MainCombobox = forwardRef(ComboboxInner);\n\nexport const Combobox = Object.assign(MainCombobox, {\n // Add any sub components here if needed\n});\n\nexport default Combobox;\n"],"names":["ComboboxInner","options","controlledValue","defaultValue","onChange","placeholder","disabledProp","statusProp","allowClear","multiple","maxTagCount","showSearch","controlledOpen","onOpenChange","placement","className","classNames","size","_loading","optionRender","filterOption","onSearch","dropdownRender","clearIcon","suffixIcon","dropdownMenuProps","triggerProps","searchProps","showSelectionSummary","selectionSummaryRender","showSelectAll","selectAllRender","rest","ref","initialDefaultValue","useState","value","setValue","useControlled","open","setOpen","useControlledState","searchValue","setSearchValue","cls","useCls","contextStatus","useContext","FormItemInputContext","contextDisabled","DisabledContext","mergedStatus","disabled","handleValueChange","useCallback","newValue","handleOptionSelect","optionValue","currentValues","newValues","v","handleSearchChange","filteredOptions","useMemo","option","handleSelectAll","allValues","handleDeselectAll","dropdownItems","selectAllComponent","selectedValues","filteredOptionValues","opt","selectedFromFiltered","val","checked","indeterminate","jsxs","Fragment","jsx","DropdownMenuItem","DropdownMenuDivider","selectedOptions","displayValue","displayPrefix","summaryText","selectedOption","clsx","DropdownMenu","SelectTrigger","MainCombobox","forwardRef","Combobox"],"mappings":";;;;;;;;;;;;;;AAqIA,MAAMA,KAAgB,CACpB;AAAA,EACE,SAAAC,IAAU,CAAC;AAAA,EACX,OAAOC;AAAA,EACP,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAe;AAAA,EACzB,QAAQC;AAAA,EACR,YAAAC,IAAa;AAAA,EACb,UAAAC,IAAW;AAAA,EACX,aAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,MAAMC;AAAA,EACN,cAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,SA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AAA,MACA,YAAAH;AAAA,MACA,aAAa;AAAA,QACX,aAAa;AAAA,QACb,eAAekD;AAAA,QACf,OAAOnB;AAAA,QACP,GAAGf;AAAA,MACL;AAAA,MACA,WAAW4D,EAAK3C,EAAI,mBAAmB,CAAC;AAAA,MACxC,YAAY;AAAA,QACV,SAAS2C,EAAK3C,EAAI,0BAA0B,CAAC;AAAA,QAC7C,OAAO2C,EAAK3C,EAAI,gBAAgB,CAAC;AAAA,QACjC,MAAM2C,EAAK3C,EAAI,iBAAiB,GAAG5B,KAAA,gBAAAA,EAAY,MAAM;AAAA,QACrD,GAAGA;AAAA,MACL;AAAA,MACA,wBAAsB;AAAA,MACtB,kBAAkBP;AAAA,MAClB,oBAAoBA,IAAW,SAAY6D,EAAe,CAAC;AAAA,MAC3D,cAAc7D;AAAA,MACd,YAAY4D;AAAA,MACZ,kBAAkBC;AAAA,MACjB,GAAG7C;AAAA,MAEJ,UAAA,gBAAAsD;AAAA,QAACU;AAAA,QAAA;AAAA,UACC,OAAON;AAAA,UACP,QAAQC;AAAA,UACR,aAAA/E;AAAA,UACA,UAAA+C;AAAA,UACA,QAAQD;AAAA,UACR,MAAAZ;AAAA,UACA,MAAAtB;AAAA,UACA,YAAAT;AAAA,UACA,YAAAgB;AAAA,UACA,WAAAD;AAAA,UACA,YAAY;AAAA,YACV,SAASP,KAAA,gBAAAA,EAAY;AAAA,YACrB,GAAGU,KAAA,gBAAAA,EAAc;AAAA,UACnB;AAAA,UACA,SAAS,MAAM2B,EAAkB5C,IAAW,CAAA,IAAK,MAAS;AAAA,UAC1D,cAAc+B;AAAA,UACd,MAAK;AAAA,UACJ,GAAGd;AAAA,QAAA;AAAA,MAAA;AAAA,IACN;AAAA,EAAA,GAEJ;AAEJ,GAEMgE,KAAeC,GAAW3F,EAAa,GAEhC4F,KAAW,OAAO,OAAOF,IAAc;AAAA;AAEpD,CAAC;"}
1
+ {"version":3,"file":"component.js","sources":["../../../src/components/combobox/component.tsx"],"sourcesContent":["\"use client\";\nimport React, {\n forwardRef,\n useCallback,\n useMemo,\n useState,\n useContext,\n} from \"react\";\nimport { useControlled } from \"@base-ui-components/utils/useControlled\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\nimport { ValidateStatus } from \"antd/es/form/FormItem\";\nimport DisabledContext from \"antd/es/config-provider/DisabledContext\";\nimport { clsx, reactNodeToString, useCls } from \"../utils\";\nimport { SelectTrigger } from \"../select-trigger\";\nimport {\n DropdownMenu,\n DropdownMenuProps,\n DropdownMenuItem,\n type DropdownMenuItemType,\n} from \"../dropdown-menu\";\nimport type { PopoverProps } from \"antd/es/popover\";\n\n// Import component-specific styles\nimport \"./style.css\";\nimport { useControlledState } from \"../hooks\";\nimport { DropdownMenuDivider } from \"../dropdown-menu/divider\";\n\nexport interface ComboboxOption {\n value: string | number;\n label: React.ReactNode;\n disabled?: boolean;\n icon?: React.ReactNode;\n}\n\nexport interface ComboboxProps {\n /** Array of options to be displayed in the combobox */\n options?: ComboboxOption[];\n /** Current value of the combobox */\n value?: string | number | Array<string | number>;\n /** Default value when uncontrolled */\n defaultValue?: string | number | Array<string | number>;\n /** Callback when value changes */\n onChange?: (value: string | number | Array<string | number>) => void;\n /** Placeholder text for the input */\n placeholder?: string;\n /** Whether the combobox is disabled */\n disabled?: boolean;\n /** Validation status */\n status?: ValidateStatus;\n /** Whether to allow clearing the selection */\n allowClear?: boolean;\n /** Whether to allow multiple selections */\n multiple?: boolean;\n /** Maximum number of tags to show */\n maxTagCount?: number;\n /** Whether to show search functionality */\n showSearch?: boolean;\n /** Controlled open state */\n open?: boolean;\n /** Callback when open state changes */\n onOpenChange?: (open: boolean) => void;\n /** Placement of the dropdown */\n placement?: PopoverProps[\"placement\"];\n /** Custom className for the component */\n className?: string;\n /** Custom class names for different parts */\n classNames?: {\n trigger?: string;\n input?: string;\n option?: string;\n optionIcon?: string;\n optionText?: string;\n };\n /** Size of the combobox */\n size?: \"small\" | \"middle\" | \"large\";\n /** Loading state */\n loading?: boolean;\n /** Custom render for options */\n optionRender?: (\n option: ComboboxOption,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /** Filter function for search */\n filterOption?: boolean | ((input: string, option: ComboboxOption) => boolean);\n /** Callback when search input changes */\n onSearch?: (value: string) => void;\n /** Custom dropdown render */\n dropdownRender?: (menu: React.ReactElement) => React.ReactElement;\n /** Custom clear icon */\n clearIcon?: React.ReactNode;\n /** Custom suffix icon */\n suffixIcon?: React.ReactNode;\n /**\n * Props to pass to the dropdown menu\n */\n dropdownMenuProps?: DropdownMenuProps;\n /**\n * Props to pass to the combobox trigger\n */\n triggerProps?: React.ComponentPropsWithoutRef<typeof SelectTrigger>;\n searchProps?: {\n placeholder?: string;\n onValueChange?: (value: string) => void;\n value?: string;\n };\n /**\n * Show selection summary instead of individual tags when multiple\n * @default false\n */\n showSelectionSummary?: boolean;\n /**\n * Render function for the selection summary in multiple case\n * @default (selectedValues) => `${selectedValues.length} items selected`\n */\n selectionSummaryRender?: (\n selectedValues: Array<string | number>\n ) => React.ReactNode;\n /**\n * Show select all option when in multiple mode\n * @default false\n */\n showSelectAll?: boolean;\n /**\n * Render function for the select all option\n */\n selectAllRender?: (props: {\n onSelectAll: () => void;\n onDeselectAll: () => void;\n checked: boolean;\n indeterminate: boolean;\n }) => React.ReactNode;\n /**\n * Function to extract keywords from the item for search filtering\n * @default (option) => [String(option.key), reactNodeToString(option.label)]\n */\n getOptionKeywords?: (\n option: DropdownMenuItemType & { type: \"item\" }\n ) => string[];\n}\n\nconst ComboboxInner = (\n {\n options = [],\n value: controlledValue,\n defaultValue,\n onChange,\n placeholder = \"Select...\",\n disabled: disabledProp = false,\n status: statusProp,\n allowClear = false,\n multiple = false,\n maxTagCount,\n showSearch = true,\n open: controlledOpen,\n onOpenChange,\n placement = \"bottomLeft\",\n className,\n classNames,\n size = \"middle\",\n loading: _loading = false,\n optionRender,\n filterOption = true,\n onSearch,\n dropdownRender,\n clearIcon,\n suffixIcon,\n dropdownMenuProps,\n triggerProps,\n searchProps,\n showSelectionSummary = false,\n selectionSummaryRender,\n showSelectAll = false,\n selectAllRender,\n getOptionKeywords = (option: DropdownMenuItemType & { type: \"item\" }) => [\n String(option.key),\n reactNodeToString(option.label),\n ],\n ...rest\n }: ComboboxProps,\n ref: React.ForwardedRef<HTMLDivElement>\n) => {\n const [initialDefaultValue] = useState(\n defaultValue !== undefined ? defaultValue : multiple ? [] : undefined\n );\n const [value, setValue] = useControlled({\n controlled: controlledValue,\n default: initialDefaultValue,\n name: \"value\",\n });\n\n const [open, setOpen] = useControlledState(\n controlledOpen,\n onOpenChange,\n false\n );\n const [searchValue, setSearchValue] = useState(\"\");\n const cls = useCls();\n\n // Get form context values\n const {\n status: contextStatus,\n // hasFeedback,\n // feedbackIcon,\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 handleValueChange = useCallback(\n (newValue: string | number | Array<string | number>) => {\n setValue(newValue);\n onChange?.(newValue);\n },\n [setValue, onChange]\n );\n\n const handleOptionSelect = useCallback(\n (optionValue: string | number) => {\n if (multiple) {\n const currentValues = Array.isArray(value) ? value : [];\n const newValues = currentValues.includes(optionValue)\n ? currentValues.filter((v) => v !== optionValue)\n : [...currentValues, optionValue];\n handleValueChange(newValues);\n } else {\n handleValueChange(optionValue);\n // onOpenChange?.(false);\n }\n },\n [multiple, value, handleValueChange]\n );\n\n const handleSearchChange = useCallback(\n (newValue: string) => {\n setSearchValue(newValue);\n onSearch?.(newValue);\n },\n [onSearch]\n );\n\n // Filter options based on search\n const filteredOptions = useMemo(() => {\n if (!showSearch || !searchValue) return options;\n\n return options.filter((option) => {\n if (typeof filterOption === \"function\") {\n return filterOption(searchValue, option);\n }\n if (filterOption === false) return true;\n\n const label =\n typeof option.label === \"string\" ? option.label : String(option.value);\n return label.toLowerCase().includes(searchValue.toLowerCase());\n });\n }, [options, showSearch, searchValue, filterOption]);\n\n const handleSelectAll = useCallback(() => {\n if (multiple) {\n const allValues = filteredOptions.map((option) => option.value);\n handleValueChange(allValues);\n }\n }, [multiple, filteredOptions, handleValueChange]);\n\n const handleDeselectAll = useCallback(() => {\n if (multiple) {\n handleValueChange([]);\n }\n }, [multiple, handleValueChange]);\n\n // Convert options to DropdownMenu items\n const dropdownItems: DropdownMenuItemType[] = useMemo(() => {\n return filteredOptions.map((option) => {\n return {\n type: \"item\",\n key: option.value,\n icon: option.icon,\n label: option.label,\n disabled: option.disabled,\n onClick: () => !option.disabled && handleOptionSelect(option.value),\n };\n });\n }, [filteredOptions, handleOptionSelect]);\n\n // Select all component for beforeList\n const selectAllComponent = useMemo(() => {\n if (!showSelectAll || !multiple || filteredOptions.length === 0) {\n return null;\n }\n\n const selectedValues = Array.isArray(value) ? value : [];\n const filteredOptionValues = filteredOptions.map((opt) => opt.value);\n const selectedFromFiltered = selectedValues.filter((val) =>\n filteredOptionValues.includes(val)\n );\n const checked =\n selectedFromFiltered.length === filteredOptions.length &&\n filteredOptions.length > 0;\n const indeterminate =\n selectedFromFiltered.length > 0 &&\n selectedFromFiltered.length < filteredOptions.length;\n\n const selectAllItem: DropdownMenuItemType & { type: \"item\" } = {\n type: \"item\",\n key: \"select_all\",\n label: \"Select All\",\n onClick: () => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n },\n };\n\n return (\n <>\n <DropdownMenuItem\n key=\"select_all\"\n item={selectAllItem}\n inCombobox={showSearch}\n selected={checked}\n showCheckbox\n indeterminate={indeterminate}\n renderAsNativeElement\n onSelect={() => {\n if (indeterminate || checked) {\n handleDeselectAll();\n } else {\n handleSelectAll();\n }\n }}\n />\n <DropdownMenuDivider />\n </>\n );\n }, [\n showSelectAll,\n multiple,\n filteredOptions,\n value,\n showSearch,\n handleDeselectAll,\n handleSelectAll,\n ]);\n\n // Prepare trigger data\n const selectedValues = useMemo(() => {\n return Array.isArray(value) ? value : value ? [value] : [];\n }, [value]);\n const selectedOptions = selectedValues\n .map((val) => options.find((opt) => opt.value === val))\n .filter(Boolean);\n\n // Generate display value and prefix for SelectTrigger\n const { displayValue, displayPrefix } = useMemo(() => {\n if (selectedOptions.length === 0) {\n return { displayValue: undefined, displayPrefix: undefined };\n }\n\n if (multiple) {\n const summaryText = `${selectedOptions.length} ${\n selectedOptions.length === 1 ? \"item\" : \"items\"\n } selected`;\n if (showSelectionSummary) {\n if (selectionSummaryRender) {\n return {\n displayValue: selectionSummaryRender(selectedValues),\n displayPrefix: undefined,\n };\n }\n // Default summary with icons\n return {\n displayValue: summaryText,\n // TODO: Create icon component for multiple selection summary\n displayPrefix: undefined,\n };\n }\n // For non-summary multiple selection\n return selectedOptions.length === 1\n ? {\n displayValue: selectedOptions[0].label,\n displayPrefix: selectedOptions[0].icon,\n }\n : {\n displayValue: summaryText,\n displayPrefix: undefined,\n };\n }\n\n // Single selection\n const selectedOption = selectedOptions[0];\n return {\n displayValue: selectedOption?.label,\n displayPrefix: selectedOption?.icon,\n };\n }, [\n selectedOptions,\n multiple,\n showSelectionSummary,\n selectionSummaryRender,\n selectedValues,\n ]);\n\n return (\n <div ref={ref} className={clsx(cls(\"combobox\"), className)} {...rest}>\n <DropdownMenu\n items={dropdownItems}\n open={open}\n onOpenChange={setOpen}\n placement={placement}\n showSearch={showSearch}\n searchProps={{\n placeholder: \"Search options...\",\n onValueChange: handleSearchChange,\n value: searchValue,\n ...searchProps,\n }}\n className={clsx(cls(\"combobox-dropdown\"))}\n classNames={{\n trigger: clsx(cls(\"combobox-trigger-wrapper\")),\n popup: clsx(cls(\"combobox-popup\")),\n item: clsx(cls(\"combobox-option\"), classNames?.option),\n ...classNames,\n }}\n popupMatchTriggerWidth\n keepOpenOnSelect={multiple}\n highlightedItemKey={multiple ? undefined : selectedValues[0]}\n showCheckbox={multiple}\n beforeList={selectAllComponent}\n selectedItemKeys={selectedValues}\n getItemKeywords={getOptionKeywords}\n {...dropdownMenuProps}\n >\n <SelectTrigger\n value={displayValue}\n prefix={displayPrefix}\n placeholder={placeholder}\n disabled={disabled}\n status={mergedStatus}\n open={open}\n size={size}\n allowClear={allowClear}\n suffixIcon={suffixIcon}\n clearIcon={clearIcon}\n classNames={{\n trigger: classNames?.trigger,\n ...triggerProps?.classNames,\n }}\n onClear={() => handleValueChange(multiple ? [] : undefined)}\n onOpenChange={setOpen}\n role=\"combobox\"\n {...triggerProps}\n />\n </DropdownMenu>\n </div>\n );\n};\n\nconst MainCombobox = forwardRef(ComboboxInner);\n\nexport const Combobox = Object.assign(MainCombobox, {\n // Add any sub components here if needed\n});\n\nexport default Combobox;\n"],"names":["ComboboxInner","options","controlledValue","defaultValue","onChange","placeholder","disabledProp","statusProp","allowClear","multiple","maxTagCount","showSearch","controlledOpen","onOpenChange","placement","className","classNames","size","_loading","optionRender","filterOption","onSearch","dropdownRender","clearIcon","suffixIcon","dropdownMenuProps","triggerProps","searchProps","showSelectionSummary","selectionSummaryRender","showSelectAll","selectAllRender","getOptionKeywords","option","reactNodeToString","rest","ref","initialDefaultValue","useState","value","setValue","useControlled","open","setOpen","useControlledState","searchValue","setSearchValue","cls","useCls","contextStatus","useContext","FormItemInputContext","contextDisabled","DisabledContext","mergedStatus","disabled","handleValueChange","useCallback","newValue","handleOptionSelect","optionValue","currentValues","newValues","v","handleSearchChange","filteredOptions","useMemo","handleSelectAll","allValues","handleDeselectAll","dropdownItems","selectAllComponent","selectedValues","filteredOptionValues","opt","selectedFromFiltered","val","checked","indeterminate","jsxs","Fragment","jsx","DropdownMenuItem","DropdownMenuDivider","selectedOptions","displayValue","displayPrefix","summaryText","selectedOption","clsx","DropdownMenu","SelectTrigger","MainCombobox","forwardRef","Combobox"],"mappings":";;;;;;;;;;;;;;;AA4IA,MAAMA,KAAgB,CACpB;AAAA,EACE,SAAAC,IAAU,CAAC;AAAA,EACX,OAAOC;AAAA,EACP,cAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,UAAUC,IAAe;AAA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,GAAGjB;AAAA,QAAA;AAAA,MAAA;AAAA,IACN;AAAA,EAAA,GAEJ;AAEJ,GAEMkE,KAAeC,GAAW7F,EAAa,GAEhC8F,KAAW,OAAO,OAAOF,IAAc;AAAA;AAEpD,CAAC;"}
@@ -0,0 +1,79 @@
1
+ "use client";
2
+ import { jsxs as s, Fragment as S, jsx as r } from "react/jsx-runtime";
3
+ import { useEffect as E, useCallback as L } from "react";
4
+ import { Command as m } from "../cmdk/index.js";
5
+ import { useDropdownMenu as D } from "../dropdown-menu/useDropdownMenu.js";
6
+ import './style.css';/* empty css */
7
+ import { WithAntdTokens as b } from "../utils/WithAntdTokens.js";
8
+ import { useCls as x } from "../utils/antdUtils.js";
9
+ import { useControlledState as A } from "../hooks/useControlledState.js";
10
+ import { ScrollArea as j } from "../scroll-area/component.js";
11
+ const G = [
12
+ { key: "k", metaKey: !0 },
13
+ { key: "k", ctrlKey: !0 }
14
+ ];
15
+ function I(t, e) {
16
+ return t.key.toLowerCase() === e.key.toLowerCase() && !!t.metaKey == !!e.metaKey && !!t.ctrlKey == !!e.ctrlKey && !!t.altKey == !!e.altKey && !!t.shiftKey == !!e.shiftKey;
17
+ }
18
+ const H = ({
19
+ open: t,
20
+ onOpenChange: e,
21
+ defaultOpen: h,
22
+ items: k = [],
23
+ shortcuts: i = G,
24
+ placeholder: c = "Type a command or search...",
25
+ emptyText: l = "No results found.",
26
+ label: C = "Command Palette",
27
+ className: K,
28
+ classNames: o
29
+ }) => {
30
+ const n = x(), [a, d] = A(
31
+ t,
32
+ e,
33
+ h
34
+ );
35
+ E(() => {
36
+ const y = (f) => {
37
+ i.find(
38
+ (g) => I(f, g)
39
+ ) && (f.preventDefault(), d(!a));
40
+ };
41
+ return document.addEventListener("keydown", y), () => document.removeEventListener("keydown", y);
42
+ }, [i, a, d]);
43
+ const { renderGroup: u, itemGroups: p } = D({
44
+ items: k,
45
+ inCombobox: !0,
46
+ onOpenChange: e
47
+ }), w = L(
48
+ () => /* @__PURE__ */ s(S, { children: [
49
+ /* @__PURE__ */ r(m.Input, { placeholder: c }),
50
+ /* @__PURE__ */ r(j, { fadeEdges: !0, children: /* @__PURE__ */ s(
51
+ m.List,
52
+ {
53
+ className: n("dropdown-menu-list", "command-palette-list"),
54
+ children: [
55
+ /* @__PURE__ */ r(m.Empty, { className: n("dropdown-menu-empty"), children: l }),
56
+ p.map(u)
57
+ ]
58
+ }
59
+ ) })
60
+ ] }),
61
+ [n, l, p, c, u]
62
+ );
63
+ return /* @__PURE__ */ r(b, { children: /* @__PURE__ */ r(
64
+ m.Dialog,
65
+ {
66
+ open: a,
67
+ onOpenChange: d,
68
+ label: C,
69
+ overlayClassName: n("command-palette-overlay", o == null ? void 0 : o.mask),
70
+ contentClassName: n("command-palette-content", o == null ? void 0 : o.content),
71
+ className: n("command-palette", K),
72
+ children: w()
73
+ }
74
+ ) });
75
+ };
76
+ export {
77
+ H as CommandPalette
78
+ };
79
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sources":["../../../src/components/command-palette/component.tsx"],"sourcesContent":["\"use client\";\nimport React, { useCallback, useEffect } from \"react\";\nimport { Command } from \"../cmdk\";\nimport { DropdownMenuItemType } from \"../dropdown-menu/types\";\nimport { useDropdownMenu } from \"../dropdown-menu/useDropdownMenu\";\nimport { useControlledState } from \"../hooks\";\nimport { ScrollArea } from \"../scroll-area\";\nimport { useCls, WithAntdTokens } from \"../utils\";\nimport \"./style.css\";\n\nexport type CommandPaletteShortcut = {\n key: string;\n metaKey?: boolean;\n ctrlKey?: boolean;\n altKey?: boolean;\n shiftKey?: boolean;\n};\n\nexport interface CommandPaletteProps {\n /** Whether the command palette is open */\n open?: boolean;\n /** Callback fired when the open state changes */\n onOpenChange?: (open: boolean) => void;\n /**\n * Default open state\n */\n defaultOpen?: boolean;\n /** Items to display in the command palette */\n items?: DropdownMenuItemType[];\n /** Keyboard shortcuts to open the palette */\n shortcuts?: CommandPaletteShortcut[];\n /** Placeholder text for the search input */\n placeholder?: string;\n /** Text to show when no results are found */\n emptyText?: string;\n /** Accessible label for the command palette */\n label?: string;\n /** Additional CSS class names */\n className?: string;\n classNames?: {\n root?: string;\n mask?: string;\n content?: string;\n group?: string;\n item?: string;\n groupLabel?: string;\n };\n}\n\nconst defaultShortcuts: CommandPaletteShortcut[] = [\n { key: \"k\", metaKey: true },\n { key: \"k\", ctrlKey: true },\n];\n\nfunction matchesShortcut(\n event: KeyboardEvent,\n shortcut: CommandPaletteShortcut,\n): boolean {\n return (\n event.key.toLowerCase() === shortcut.key.toLowerCase() &&\n !!event.metaKey === !!shortcut.metaKey &&\n !!event.ctrlKey === !!shortcut.ctrlKey &&\n !!event.altKey === !!shortcut.altKey &&\n !!event.shiftKey === !!shortcut.shiftKey\n );\n}\n\n// Default items for testing/demo purposes\n// const defaultItems: DropdownMenuItemType[] = [\n// {\n// type: \"item\",\n// key: \"search\",\n// label: \"Search files\",\n// onClick: () => console.log(\"Search files\"),\n// },\n// {\n// type: \"item\",\n// key: \"new-file\",\n// label: \"New file\",\n// onClick: () => console.log(\"New file\"),\n// },\n// {\n// type: \"item\",\n// key: \"settings\",\n// label: \"Open settings\",\n// onClick: () => console.log(\"Open settings\"),\n// },\n// ];\n\nexport const CommandPalette: React.FC<CommandPaletteProps> = ({\n open,\n onOpenChange,\n defaultOpen,\n items = [],\n shortcuts = defaultShortcuts,\n placeholder = \"Type a command or search...\",\n emptyText = \"No results found.\",\n label = \"Command Palette\",\n className,\n classNames,\n}) => {\n const cls = useCls();\n const [actualOpen, setActualOpen] = useControlledState(\n open,\n onOpenChange,\n defaultOpen,\n );\n\n // Set up keyboard shortcuts\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n const matchingShortcut = shortcuts.find((shortcut) =>\n matchesShortcut(event, shortcut),\n );\n\n if (matchingShortcut) {\n event.preventDefault();\n setActualOpen(!actualOpen);\n }\n };\n\n document.addEventListener(\"keydown\", handleKeyDown);\n return () => document.removeEventListener(\"keydown\", handleKeyDown);\n }, [shortcuts, actualOpen, setActualOpen]);\n\n const { renderGroup, itemGroups } = useDropdownMenu({\n items,\n inCombobox: true,\n onOpenChange,\n });\n\n const renderMenuInner = useCallback(\n () => (\n <>\n <Command.Input placeholder={placeholder} />\n {/*{beforeList}*/}\n <ScrollArea fadeEdges>\n <Command.List\n className={cls(\"dropdown-menu-list\", \"command-palette-list\")}\n >\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n {emptyText}\n </Command.Empty>\n {itemGroups.map(renderGroup)}\n </Command.List>\n </ScrollArea>\n {/*{afterList}*/}\n </>\n ),\n [cls, emptyText, itemGroups, placeholder, renderGroup],\n );\n return (\n <WithAntdTokens>\n <Command.Dialog\n open={actualOpen}\n onOpenChange={setActualOpen}\n label={label}\n overlayClassName={cls(\"command-palette-overlay\", classNames?.mask)}\n contentClassName={cls(\"command-palette-content\", classNames?.content)}\n className={cls(\"command-palette\", className)}\n >\n {renderMenuInner()}\n </Command.Dialog>\n </WithAntdTokens>\n );\n};\n"],"names":["defaultShortcuts","matchesShortcut","event","shortcut","CommandPalette","open","onOpenChange","defaultOpen","items","shortcuts","placeholder","emptyText","label","className","classNames","cls","useCls","actualOpen","setActualOpen","useControlledState","useEffect","handleKeyDown","renderGroup","itemGroups","useDropdownMenu","renderMenuInner","useCallback","jsxs","Fragment","jsx","Command","ScrollArea","WithAntdTokens"],"mappings":";;;;;;;;;;AAiDA,MAAMA,IAA6C;AAAA,EACjD,EAAE,KAAK,KAAK,SAAS,GAAK;AAAA,EAC1B,EAAE,KAAK,KAAK,SAAS,GAAK;AAC5B;AAEA,SAASC,EACPC,GACAC,GACS;AACT,SACED,EAAM,IAAI,YAAkB,MAAAC,EAAS,IAAI,YAAY,KACrD,CAAC,CAACD,EAAM,WAAY,CAAC,CAACC,EAAS,WAC/B,CAAC,CAACD,EAAM,WAAY,CAAC,CAACC,EAAS,WAC/B,CAAC,CAACD,EAAM,UAAW,CAAC,CAACC,EAAS,UAC9B,CAA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AAqB,GAChD,UACHJ,GAAA;AAAA,YACCY,EAAW,IAAID,CAAW;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA,EAE/B,CAAA;AAAA,IAAA,GAEF;AAAA,IAEF,CAACP,GAAKJ,GAAWY,GAAYb,GAAaY,CAAW;AAAA,EACvD;AACA,2BACGU,GACC,EAAA,UAAA,gBAAAH;AAAA,IAACC,EAAQ;AAAA,IAAR;AAAA,MACC,MAAMb;AAAA,MACN,cAAcC;AAAA,MACd,OAAAN;AAAA,MACA,kBAAkBG,EAAI,2BAA2BD,KAAA,gBAAAA,EAAY,IAAI;AAAA,MACjE,kBAAkBC,EAAI,2BAA2BD,KAAA,gBAAAA,EAAY,OAAO;AAAA,MACpE,WAAWC,EAAI,mBAAmBF,CAAS;AAAA,MAE1C,UAAgBY,EAAA;AAAA,IAAA;AAAA,EAAA,GAErB;AAEJ;"}
@@ -0,0 +1 @@
1
+ @layer components{.ds-command-palette-overlay{background-color:var(--ds-color-bg-mask);-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);position:fixed;top:0;right:0;bottom:0;left:0;z-index:var(--ds-z-index-modal-mask)}.ds-command-palette-content{position:fixed;top:20%;left:50%;transform:translate(-50%);width:90%;max-width:640px;max-height:60vh;background:var(--ds-color-bg-elevated);border:1px solid var(--ds-color-border);border-radius:var(--ds-border-radius-lg);box-shadow:0 10px 38px -10px #16171859,0 10px 20px -15px #16171833;overflow:hidden;z-index:var(--ds-z-index-modal);animation:commandPaletteIn var(--ds-motion-duration-fast) var(--ds-motion-ease-out)}.ds-command-palette-content:focus:not(:focus-visible){outline:none}.ds-command-palette{display:flex;flex-direction:column;height:100%}.ds-command-palette-list{padding:.5rem}.ds-command-palette [cmdk-input]{font-family:var(--ds-font-family);font-size:1rem;border:none;outline:none;background:transparent;padding:var(--ds-padding) var(--ds-padding-md);color:var(--ds-color-text);border-bottom:1px solid var(--ds-color-border);width:100%}.ds-command-palette [cmdk-input]::placeholder{color:var(--color-ds-color-text-placeholder)}.ds-command-palette [cmdk-empty]{display:flex;align-items:center;justify-content:center;height:5rem}@keyframes commandPaletteIn{0%{opacity:0;transform:translate(-50%) scale(.95) translateY(-10px)}to{opacity:1;transform:translate(-50%) scale(1) translateY(0)}}@media (prefers-color-scheme: dark){.ds-command-palette-overlay{background-color:var(--ds-color-bg-mask)}}@media (max-width: 640px){.ds-command-palette-content{top:10%;width:95%;max-height:70vh}}}
@@ -1,230 +1,158 @@
1
1
  "use client";
2
- import { jsx as e, jsxs as b } from "react/jsx-runtime";
3
- import { useCallback as w, useRef as X, createElement as Y } from "react";
4
- import { Menu as P } from "@base-ui-components/react/menu";
5
- import { useControlled as Z } from "@base-ui-components/utils/useControlled";
6
- import { Popover as $ } from "@base-ui-components/react/popover";
7
- import { Command as g } from "../cmdk/index.js";
8
- import { FormItemInputContext as O } from "antd/es/form/context";
9
- import { PopupPanelSize as S } from "../popup-panel/constants.js";
10
- import { DropdownMenuItem as K } from "./item.js";
2
+ import { jsxs as i, jsx as n } from "react/jsx-runtime";
3
+ import { useRef as T, useCallback as U, createElement as W } from "react";
4
+ import { Menu as q } from "@base-ui-components/react/menu";
5
+ import { Popover as H } from "@base-ui-components/react/popover";
6
+ import { Command as d } from "../cmdk/index.js";
7
+ import { FormItemInputContext as J } from "antd/es/form/context";
8
+ import { PopupPanelSize as b } from "../popup-panel/constants.js";
9
+ import { useDropdownMenu as Q } from "./useDropdownMenu.js";
11
10
  import './style.css';/* empty css */
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
- import { ScrollArea as _ } from "../scroll-area/component.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
- import { clsx as u } from "../utils/cn.js";
19
- const Mo = ({
20
- children: j,
21
- items: z,
22
- placement: B,
23
- openOnHover: F,
24
- open: T,
25
- onOpenChange: v,
26
- className: U,
27
- itemRender: E,
11
+ import { parseAntdPlacement as X } from "../utils/placement.js";
12
+ import { Input as Y } from "../input/component.js";
13
+ import { ScrollArea as h } from "../scroll-area/component.js";
14
+ import { DROPDOWN_COLLISION_AVOIDANCE as Z } from "../utils/constants.js";
15
+ import { useControlledState as $ } from "../hooks/useControlledState.js";
16
+ import { useCls as K, useAntdCssVarClassname as a } from "../utils/antdUtils.js";
17
+ import { clsx as l } from "../utils/cn.js";
18
+ const vo = ({
19
+ children: A,
20
+ items: S,
21
+ placement: D,
22
+ openOnHover: E,
23
+ open: c,
24
+ onOpenChange: M,
25
+ defaultOpen: R,
26
+ className: V,
27
+ itemRender: k,
28
28
  classNames: o,
29
- size: k = "auto",
30
- showSearch: t,
31
- searchProps: y = {
29
+ size: C = "auto",
30
+ showSearch: e,
31
+ inCombobox: w,
32
+ searchProps: v = {
32
33
  placeholder: "Search..."
33
34
  },
34
- popupMatchTriggerWidth: W,
35
- beforeList: C,
36
- afterList: D,
37
- keepOpenOnSelect: I,
38
- highlightedItemKey: G,
39
- selectedItemKeys: h,
40
- showCheckbox: M,
41
- getItemKeywords: q
35
+ popupMatchTriggerWidth: y,
36
+ beforeList: p,
37
+ afterList: u,
38
+ keepOpenOnSelect: j,
39
+ highlightedItemKey: m,
40
+ selectedItemKeys: G,
41
+ getItemKeywords: _,
42
+ showCheckbox: I
42
43
  }) => {
43
- const [H, x] = Z({
44
- controlled: T,
45
- default: !1,
46
- name: "open"
47
- }), l = w(
48
- (r) => {
49
- x(r), v == null || v(r);
50
- },
51
- [x, v]
52
- ), d = ro(), L = no(), R = N(B), J = X(null), A = z.reduce((r, n) => (r.length === 0 && n.type !== "header" && r.push({
53
- label: null,
54
- items: []
55
- }), n.type === "header" ? r.push({
56
- label: n.title,
57
- items: []
58
- }) : (n.type === "item" || n.type === "divider") && r.length > 0 && r[r.length - 1].items.push(n), r), []), m = w(
59
- (r, n, p) => r.type === "item" ? /* @__PURE__ */ e(
60
- K,
61
- {
62
- item: r,
63
- inCombobox: t,
64
- selected: h == null ? void 0 : h.includes(r.key),
65
- onSelect: t ? () => {
66
- const i = new MouseEvent("click", {
67
- bubbles: !0,
68
- cancelable: !0
69
- });
70
- r.onClick(i), I || l == null || l(!1);
71
- } : void 0,
72
- itemRender: E,
73
- showCheckbox: M,
74
- getItemKeywords: q
75
- },
76
- n + "-" + p
77
- ) : r.type === "divider" ? /* @__PURE__ */ e(
78
- a,
79
- {
80
- inCombobox: t,
81
- className: o == null ? void 0 : o.separator
82
- },
83
- n + "-" + p
84
- ) : null,
85
- [
86
- o,
87
- E,
88
- l,
89
- t,
90
- I,
91
- h,
92
- M
93
- ]
94
- ), V = w(
95
- (r, n) => /* @__PURE__ */ b(
96
- P.Group,
97
- {
98
- className: u(d("dropdown-menu-group"), o == null ? void 0 : o.group),
99
- children: [
100
- r.label && /* @__PURE__ */ e(
101
- P.GroupLabel,
102
- {
103
- className: u(
104
- d("dropdown-menu-header"),
105
- o == null ? void 0 : o.groupLabel
106
- ),
107
- children: /* @__PURE__ */ e("span", { children: r.label })
108
- }
109
- ),
110
- r.items.map((p, i) => m(p, n, i))
111
- ]
112
- },
113
- "group" + n
114
- ),
115
- [d, o, m]
116
- ), c = w(
117
- (r, n) => r.label ? /* @__PURE__ */ e(
118
- g.Group,
119
- {
120
- className: u(d("dropdown-menu-group"), o == null ? void 0 : o.group),
121
- heading: /* @__PURE__ */ e(
122
- P.GroupLabel,
123
- {
124
- className: u(
125
- d("dropdown-menu-header"),
126
- o == null ? void 0 : o.groupLabel
127
- ),
128
- children: /* @__PURE__ */ e("span", { children: r.label })
129
- }
130
- ),
131
- children: r.items.map((p, i) => m(p, n, i))
132
- },
133
- "group" + n
134
- ) : r.items.map((p, i) => m(p, n, i)),
135
- [d, o, m]
136
- ), Q = w(
137
- () => t ? /* @__PURE__ */ b(
138
- g,
44
+ const z = typeof w == "boolean" ? w : e, [B, P] = $(
45
+ c,
46
+ M,
47
+ R
48
+ ), r = K(), x = a(), O = X(D), F = T(null), { itemGroups: f, renderGroup: g } = Q({
49
+ items: S,
50
+ keepOpenOnSelect: j,
51
+ selectedItemKeys: G,
52
+ showCheckbox: I,
53
+ getItemKeywords: _,
54
+ itemRender: k,
55
+ inCombobox: z,
56
+ onOpenChange: P,
57
+ classNames: {
58
+ item: o == null ? void 0 : o.item,
59
+ itemIcon: o == null ? void 0 : o.itemIcon,
60
+ itemSuffix: o == null ? void 0 : o.itemSuffix,
61
+ group: o == null ? void 0 : o.group,
62
+ groupLabel: o == null ? void 0 : o.groupLabel,
63
+ divider: o == null ? void 0 : o.divider
64
+ }
65
+ }), L = U(
66
+ () => e ? /* @__PURE__ */ i(
67
+ d,
139
68
  {
140
- className: d("dropdown-menu-container"),
141
- disablePointerSelection: t,
142
- defaultValue: G ? String(G) : void 0,
69
+ className: r("dropdown-menu-container"),
70
+ disablePointerSelection: e,
71
+ defaultValue: m ? String(m) : void 0,
143
72
  children: [
144
- /* @__PURE__ */ e(O.Provider, { value: {}, children: /* @__PURE__ */ Y(
145
- g.Input,
73
+ /* @__PURE__ */ n(J.Provider, { value: {}, children: /* @__PURE__ */ W(
74
+ d.Input,
146
75
  {
147
- ...y,
76
+ ...v,
148
77
  key: "search",
149
- render: /* @__PURE__ */ e(
150
- s,
78
+ render: /* @__PURE__ */ n(
79
+ Y,
151
80
  {
152
81
  allowClear: !0,
153
- className: d("dropdown-menu-search"),
82
+ className: r("dropdown-menu-search"),
154
83
  placeholder: "Search"
155
84
  }
156
85
  )
157
86
  }
158
87
  ) }),
159
- C,
160
- /* @__PURE__ */ e(_, { fadeEdges: !0, children: /* @__PURE__ */ b(g.List, { className: d("dropdown-menu-list"), children: [
161
- /* @__PURE__ */ e(g.Empty, { className: d("dropdown-menu-empty"), children: "No results found." }),
162
- A.map(c)
88
+ p,
89
+ /* @__PURE__ */ n(h, { fadeEdges: !0, children: /* @__PURE__ */ i(d.List, { className: r("dropdown-menu-list"), children: [
90
+ /* @__PURE__ */ n(d.Empty, { className: r("dropdown-menu-empty"), children: "No results found." }),
91
+ f.map(g)
163
92
  ] }) }),
164
- D
93
+ u
165
94
  ]
166
95
  }
167
- ) : /* @__PURE__ */ b("div", { className: d("dropdown-menu-container"), children: [
168
- C,
169
- /* @__PURE__ */ e(_, { fadeEdges: !0, children: A.map(V) }),
170
- D
96
+ ) : /* @__PURE__ */ i("div", { className: r("dropdown-menu-container"), children: [
97
+ p,
98
+ /* @__PURE__ */ n(h, { fadeEdges: !0, children: f.map(g) }),
99
+ u
171
100
  ] }),
172
101
  [
173
- t,
174
- d,
175
- G,
176
- y,
177
- C,
178
- A,
179
- c,
180
- D,
181
- V
102
+ e,
103
+ r,
104
+ m,
105
+ v,
106
+ p,
107
+ f,
108
+ u,
109
+ g
182
110
  ]
183
- ), f = t ? $ : P;
184
- return /* @__PURE__ */ b(
185
- f.Root,
111
+ ), t = e ? H : q;
112
+ return /* @__PURE__ */ i(
113
+ t.Root,
186
114
  {
187
- openOnHover: F,
188
- open: H,
189
- onOpenChange: l,
115
+ openOnHover: E,
116
+ open: B,
117
+ onOpenChange: P,
190
118
  children: [
191
- /* @__PURE__ */ e(
192
- f.Trigger,
119
+ /* @__PURE__ */ n(
120
+ t.Trigger,
193
121
  {
194
- render: j,
195
- ref: J,
196
- className: u(
197
- d("dropdown-menu-trigger"),
122
+ render: A,
123
+ ref: F,
124
+ className: l(
125
+ r("dropdown-menu-trigger"),
198
126
  o == null ? void 0 : o.trigger,
199
- L
127
+ x
200
128
  )
201
129
  }
202
130
  ),
203
- /* @__PURE__ */ e(f.Portal, { children: /* @__PURE__ */ e(
204
- f.Positioner,
131
+ /* @__PURE__ */ n(t.Portal, { children: /* @__PURE__ */ n(
132
+ t.Positioner,
205
133
  {
206
- side: R.side,
207
- align: R.align,
134
+ side: O.side,
135
+ align: O.align,
208
136
  sideOffset: 4,
209
- className: u(d("dropdown-menu-root"), o == null ? void 0 : o.root),
210
- collisionAvoidance: oo,
211
- children: /* @__PURE__ */ e(
212
- f.Popup,
137
+ className: l(r("dropdown-menu-root"), o == null ? void 0 : o.root),
138
+ collisionAvoidance: Z,
139
+ children: /* @__PURE__ */ n(
140
+ t.Popup,
213
141
  {
214
- className: u(
215
- d(
142
+ className: l(
143
+ r(
216
144
  "dropdown-menu",
217
- M && "dropdown-menu-show-checkbox",
218
- W && "dropdown-menu-match-trigger-width"
145
+ I && "dropdown-menu-show-checkbox",
146
+ y && "dropdown-menu-match-trigger-width"
219
147
  ),
220
- U,
148
+ V,
221
149
  o == null ? void 0 : o.popup,
222
- L
150
+ x
223
151
  ),
224
152
  style: {
225
- "--size-width": k in S ? S[k] : void 0
153
+ "--size-width": C in b ? b[C] : void 0
226
154
  },
227
- children: Q()
155
+ children: L()
228
156
  }
229
157
  )
230
158
  }
@@ -234,6 +162,6 @@ const Mo = ({
234
162
  );
235
163
  };
236
164
  export {
237
- Mo as DropdownMenu
165
+ vo as DropdownMenu
238
166
  };
239
167
  //# sourceMappingURL=component.js.map