@bikdotai/bik-component-library 0.0.875-beta.1 → 0.0.875-beta.3

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 (59) hide show
  1. package/dist/cjs/components/agent-builder/components/ConfigToolPanel.js +11 -11
  2. package/dist/cjs/components/agent-builder/components/ConfigToolPanel.js.map +1 -1
  3. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js +2 -2
  4. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  5. package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js +4 -4
  6. package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
  7. package/dist/cjs/components/agent-builder/utils/sourceIcons.js +1 -1
  8. package/dist/cjs/components/dropdown/OpenedDropdown/components/OpennedDropdown.js +1 -1
  9. package/dist/cjs/components/dropdown/OpenedDropdown/components/OpennedDropdown.js.map +1 -1
  10. package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuItem.js +27 -10
  11. package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuItem.js.map +1 -1
  12. package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuList.js +1 -1
  13. package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuList.js.map +1 -1
  14. package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js +1 -1
  15. package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js.map +1 -1
  16. package/dist/cjs/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js +1 -1
  17. package/dist/cjs/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js.map +1 -1
  18. package/dist/cjs/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js +1 -1
  19. package/dist/cjs/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js.map +1 -1
  20. package/dist/cjs/components/dropdown/hooks/useDropdown.js +1 -1
  21. package/dist/cjs/components/dropdown/hooks/useDropdown.js.map +1 -1
  22. package/dist/cjs/index.js +1 -1
  23. package/dist/esm/components/agent-builder/components/ConfigToolPanel.d.ts +0 -6
  24. package/dist/esm/components/agent-builder/components/ConfigToolPanel.js +141 -143
  25. package/dist/esm/components/agent-builder/components/ConfigToolPanel.js.map +1 -1
  26. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.d.ts +0 -6
  27. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js +81 -83
  28. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  29. package/dist/esm/components/agent-builder/components/MentionPicker.js +5 -5
  30. package/dist/esm/components/agent-builder/components/RestApiToolPanel.d.ts +0 -6
  31. package/dist/esm/components/agent-builder/components/RestApiToolPanel.js +48 -50
  32. package/dist/esm/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
  33. package/dist/esm/components/agent-builder/index.d.ts +2 -18
  34. package/dist/esm/components/agent-builder/utils/sourceIcons.js +43 -43
  35. package/dist/esm/components/agent-builder/utils/toolActions.js +3 -3
  36. package/dist/esm/components/dropdown/OpenedDropdown/components/OpennedDropdown.js +300 -278
  37. package/dist/esm/components/dropdown/OpenedDropdown/components/OpennedDropdown.js.map +1 -1
  38. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuItem.d.ts +8 -0
  39. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuItem.js +170 -126
  40. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuItem.js.map +1 -1
  41. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuList.d.ts +4 -0
  42. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuList.js +144 -112
  43. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuList.js.map +1 -1
  44. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.d.ts +1 -0
  45. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js +32 -31
  46. package/dist/esm/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js.map +1 -1
  47. package/dist/esm/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.d.ts +2 -0
  48. package/dist/esm/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js +54 -39
  49. package/dist/esm/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js.map +1 -1
  50. package/dist/esm/components/dropdown/OpenedDropdown/utils/iterationOnOptions.d.ts +18 -16
  51. package/dist/esm/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js +73 -27
  52. package/dist/esm/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js.map +1 -1
  53. package/dist/esm/components/dropdown/hooks/useDropdown.d.ts +4 -17
  54. package/dist/esm/components/dropdown/hooks/useDropdown.js +176 -163
  55. package/dist/esm/components/dropdown/hooks/useDropdown.js.map +1 -1
  56. package/dist/esm/components/dropdown/type.d.ts +22 -0
  57. package/dist/esm/index.js +772 -816
  58. package/dist/esm/index.js.map +1 -1
  59. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MenuList.js","sources":["../../../../../../../src/components/dropdown/OpenedDropdown/components/menu/MenuList.tsx"],"sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport { DropdownOption, GroupedOption, SingleOption } from '../../../type';\nimport { MenuItem } from './MenuItem';\nimport { Divider, StyledGroupedLabel } from './MenuList.styled';\n\ninterface MenuListProps {\n\toptions: DropdownOption[];\n\tisMultiSelect?: boolean;\n\tshowDescription: (title?: string, description?: string) => void;\n\tonSelect: (optionSelect: SingleOption) => void;\n\tversion?: '1.0' | '2.0' | '3.0';\n\tonInfiniteScroll?: () => void;\n\tonDropdownItemClick?: (option: DropdownOption) => void;\n\tuseDefaultCursor?: boolean;\n\tfocusedIndex?: number;\n\tisDraggable?: boolean;\n\tonOptionsReorder?: (reorderedOptions: DropdownOption[]) => void;\n\tshowCheckboxForCustomElement?: boolean;\n\tcheckboxActiveColor?: string;\n\tbrandSelectedRow?: boolean;\n}\n// eslint-disable-next-line react/display-name\nexport const MenuList = forwardRef<HTMLDivElement[], MenuListProps>(\n\t(\n\t\t{\n\t\t\toptions,\n\t\t\tisMultiSelect,\n\t\t\tshowDescription,\n\t\t\tonSelect,\n\t\t\tversion,\n\t\t\tonInfiniteScroll,\n\t\t\tonDropdownItemClick,\n\t\t\tuseDefaultCursor,\n\t\t\tfocusedIndex = -1,\n\t\t\tisDraggable = false,\n\t\t\tonOptionsReorder,\n\t\t\tshowCheckboxForCustomElement = false,\n\t\t\tcheckboxActiveColor,\n\t\t\tbrandSelectedRow,\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst observer = useRef<IntersectionObserver | null>(null);\n\t\tconst spanRef = useRef<HTMLSpanElement | null>(null);\n\t\tconst [draggedIndex, setDraggedIndex] = useState<number | null>(null);\n\t\tconst [draggedOverIndex, setDraggedOverIndex] = useState<number | null>(\n\t\t\tnull,\n\t\t);\n\n\t\tconst setupObserver = useCallback(() => {\n\t\t\tif (observer.current) {\n\t\t\t\tobserver.current.disconnect();\n\t\t\t}\n\t\t\tobserver.current = new IntersectionObserver((entries) => {\n\t\t\t\tif (entries[0].isIntersecting) {\n\t\t\t\t\tonInfiniteScroll?.();\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (spanRef.current) {\n\t\t\t\tobserver.current.observe(spanRef.current);\n\t\t\t}\n\t\t}, [onInfiniteScroll]);\n\n\t\tuseEffect(() => {\n\t\t\tsetupObserver();\n\t\t\treturn () => {\n\t\t\t\tif (observer.current) {\n\t\t\t\t\tobserver.current.disconnect();\n\t\t\t\t}\n\t\t\t};\n\t\t}, [setupObserver, options]);\n\n\t\tconst handleDragStart = useCallback(\n\t\t\t(index: number) => (e: React.DragEvent<HTMLDivElement>) => {\n\t\t\t\tif (!isDraggable) return;\n\t\t\t\tsetDraggedIndex(index);\n\t\t\t\te.dataTransfer.effectAllowed = 'move';\n\t\t\t},\n\t\t\t[isDraggable],\n\t\t);\n\n\t\tconst handleDragOver = useCallback(\n\t\t\t(index: number) => (e: React.DragEvent<HTMLDivElement>) => {\n\t\t\t\tif (!isDraggable) return;\n\t\t\t\te.preventDefault();\n\t\t\t\te.dataTransfer.dropEffect = 'move';\n\t\t\t\tsetDraggedOverIndex(index);\n\t\t\t},\n\t\t\t[isDraggable],\n\t\t);\n\n\t\tconst handleDrop = useCallback(\n\t\t\t(dropIndex: number) => (e: React.DragEvent<HTMLDivElement>) => {\n\t\t\t\tif (!isDraggable || draggedIndex === null) return;\n\t\t\t\te.preventDefault();\n\n\t\t\t\tif (draggedIndex !== dropIndex) {\n\t\t\t\t\tconst newOptions = [...options];\n\t\t\t\t\tconst [item] = newOptions.splice(draggedIndex, 1);\n\t\t\t\t\tnewOptions.splice(dropIndex, 0, item);\n\t\t\t\t\tonOptionsReorder?.(newOptions);\n\t\t\t\t}\n\n\t\t\t\tsetDraggedIndex(null);\n\t\t\t\tsetDraggedOverIndex(null);\n\t\t\t},\n\t\t\t[isDraggable, draggedIndex, options, onOptionsReorder],\n\t\t);\n\n\t\tconst handleDragEnd = useCallback(() => {\n\t\t\tsetDraggedIndex(null);\n\t\t\tsetDraggedOverIndex(null);\n\t\t}, []);\n\n\t\t// Calculate flat indices for all options\n\t\tconst flatIndices = new Map<SingleOption, number>();\n\t\tlet currentIndex = -1;\n\t\toptions.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t(option as GroupedOption).options.forEach((menuOption) => {\n\t\t\t\t\tif (!menuOption.disabled) {\n\t\t\t\t\t\tcurrentIndex++;\n\t\t\t\t\t\tflatIndices.set(menuOption, currentIndex);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\tif (!singleOption.disabled) {\n\t\t\t\t\tcurrentIndex++;\n\t\t\t\t\tflatIndices.set(singleOption, currentIndex);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{options.map((option, i) => {\n\t\t\t\t\tconst last = i === options.length - 1;\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={i} style={{ marginTop: version === '2.0' ? 2 : 0 }}>\n\t\t\t\t\t\t\t\t<StyledGroupedLabel version={version}>\n\t\t\t\t\t\t\t\t\t{groupedOption.leadingIcon ? (\n\t\t\t\t\t\t\t\t\t\t<span style={{ marginRight: 8 }}>\n\t\t\t\t\t\t\t\t\t\t\t{groupedOption.leadingIcon}\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t{groupedOption.label}\n\t\t\t\t\t\t\t\t</StyledGroupedLabel>\n\t\t\t\t\t\t\t\t{groupedOption.options.map((menuOption, idx) => {\n\t\t\t\t\t\t\t\t\tconst currentFlatIndex = flatIndices.get(menuOption);\n\t\t\t\t\t\t\t\t\tconst isFocused =\n\t\t\t\t\t\t\t\t\t\tcurrentFlatIndex === focusedIndex && !menuOption.disabled;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tversion={version}\n\t\t\t\t\t\t\t\t\t\t\tlast={idx === groupedOption.options.length - 1}\n\t\t\t\t\t\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t\t\t\t\t\t\tshowDescription={showDescription}\n\t\t\t\t\t\t\t\t\t\t\tonDropdownItemClick={onDropdownItemClick}\n\t\t\t\t\t\t\t\t\t\t\tisMultiSelect={isMultiSelect}\n\t\t\t\t\t\t\t\t\t\t\toption={menuOption}\n\t\t\t\t\t\t\t\t\t\t\tuseDefaultCursor={useDefaultCursor}\n\t\t\t\t\t\t\t\t\t\t\tkey={`${i}-${idx}`}\n\t\t\t\t\t\t\t\t\t\t\tisFocused={isFocused}\n\t\t\t\t\t\t\t\t\t\t\tdataIndex={currentFlatIndex}\n\t\t\t\t\t\t\t\t\t\t\tisDraggable={false}\n\t\t\t\t\t\t\t\t\t\t\tshowCheckboxForCustomElement={\n\t\t\t\t\t\t\t\t\t\t\t\tshowCheckboxForCustomElement\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tcheckboxActiveColor={checkboxActiveColor}\n\t\t\t\t\t\t\t\t\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\t\t\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (ref && typeof ref === 'object' && ref.current) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) ref.current[i] = el;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t{last ? <span ref={spanRef} /> : null}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tconst currentFlatIndex = flatIndices.get(singleOption);\n\t\t\t\t\tconst isFocused =\n\t\t\t\t\t\tcurrentFlatIndex === focusedIndex && !singleOption.disabled;\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div key={i}>\n\t\t\t\t\t\t\t{singleOption.hasDivider && <Divider />}\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tversion={version}\n\t\t\t\t\t\t\t\tlast={last}\n\t\t\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t\t\t\tshowDescription={showDescription}\n\t\t\t\t\t\t\t\tonDropdownItemClick={onDropdownItemClick}\n\t\t\t\t\t\t\t\tisMultiSelect={isMultiSelect}\n\t\t\t\t\t\t\t\toption={singleOption}\n\t\t\t\t\t\t\t\tuseDefaultCursor={useDefaultCursor}\n\t\t\t\t\t\t\t\tkey={singleOption.value}\n\t\t\t\t\t\t\t\tisFocused={isFocused}\n\t\t\t\t\t\t\t\tdataIndex={currentFlatIndex}\n\t\t\t\t\t\t\t\tisDraggable={isDraggable}\n\t\t\t\t\t\t\t\tonDragStart={handleDragStart(i)}\n\t\t\t\t\t\t\t\tonDragOver={handleDragOver(i)}\n\t\t\t\t\t\t\t\tonDrop={handleDrop(i)}\n\t\t\t\t\t\t\t\tonDragEnd={handleDragEnd}\n\t\t\t\t\t\t\t\tisDraggedOver={draggedOverIndex === i}\n\t\t\t\t\t\t\t\tshowCheckboxForCustomElement={showCheckboxForCustomElement}\n\t\t\t\t\t\t\t\tcheckboxActiveColor={checkboxActiveColor}\n\t\t\t\t\t\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\t\tif (ref && typeof ref === 'object' && ref.current && el) {\n\t\t\t\t\t\t\t\t\t\tref.current[i] = el;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{last ? <span ref={spanRef} /> : null}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t</>\n\t\t);\n\t},\n);\n"],"names":["MenuList","forwardRef","options","isMultiSelect","showDescription","onSelect","version","onInfiniteScroll","onDropdownItemClick","useDefaultCursor","focusedIndex","isDraggable","onOptionsReorder","showCheckboxForCustomElement","checkboxActiveColor","brandSelectedRow","ref","observer","useRef","spanRef","draggedIndex","setDraggedIndex","useState","draggedOverIndex","setDraggedOverIndex","setupObserver","useCallback","entries","useEffect","handleDragStart","index","handleDragOver","handleDrop","dropIndex","newOptions","item","handleDragEnd","flatIndices","currentIndex","option","menuOption","singleOption","jsx","Fragment","i","last","groupedOption","jsxs","StyledGroupedLabel","idx","currentFlatIndex","isFocused","MenuItem","el","Divider"],"mappings":"qMAsBaA,EAAWC,EAAAA,WACvB,CACC,CACC,QAAAC,EACA,cAAAC,EACA,gBAAAC,EACA,SAAAC,EACA,QAAAC,EACA,iBAAAC,EACA,oBAAAC,EACA,iBAAAC,EACA,aAAAC,EAAe,GACf,YAAAC,EAAc,GACd,iBAAAC,EACA,6BAAAC,EAA+B,GAC/B,oBAAAC,EACA,iBAAAC,CAAA,EAEDC,IACI,CACJ,MAAMC,EAAWC,EAAAA,OAAoC,IAAI,EACnDC,EAAUD,EAAAA,OAA+B,IAAI,EAC7C,CAACE,EAAcC,CAAe,EAAIC,EAAAA,SAAwB,IAAI,EAC9D,CAACC,EAAkBC,CAAmB,EAAIF,EAAAA,SAC/C,IAAA,EAGKG,EAAgBC,EAAAA,YAAY,IAAM,CACnCT,EAAS,SACZA,EAAS,QAAQ,WAAA,EAElBA,EAAS,QAAU,IAAI,qBAAsBU,GAAY,CACpDA,EAAQ,CAAC,EAAE,gBACdpB,IAAA,CAEF,CAAC,EACGY,EAAQ,SACXF,EAAS,QAAQ,QAAQE,EAAQ,OAAO,CAE1C,EAAG,CAACZ,CAAgB,CAAC,EAErBqB,EAAAA,UAAU,KACTH,EAAA,EACO,IAAM,CACRR,EAAS,SACZA,EAAS,QAAQ,WAAA,CAEnB,GACE,CAACQ,EAAevB,CAAO,CAAC,EAE3B,MAAM2B,EAAkBH,EAAAA,YACtBI,GAAmB,GAAuC,CACrDnB,IACLU,EAAgBS,CAAK,EACrB,EAAE,aAAa,cAAgB,OAChC,EACA,CAACnB,CAAW,CAAA,EAGPoB,EAAiB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AWR,EACX,cAAeb,IAAqBqB,EACpC,6BAAA/B,EACA,oBAAAC,EACA,iBAAAC,EACA,IAAMsC,GAAO,CACRrC,GAAO,OAAOA,GAAQ,UAAYA,EAAI,SAAWqC,IACpDrC,EAAI,QAAQ4B,CAAC,EAAIS,EAEnB,CAAA,EAhBKZ,EAAa,KAAA,EAkBlBI,EAAOH,EAAAA,IAAC,OAAA,CAAK,IAAKvB,EAAS,EAAK,IAAA,CAAA,EA7BxByB,CA8BV,CAEF,CAAC,CAAA,CACF,CAEF,CACD"}
1
+ {"version":3,"file":"MenuList.js","sources":["../../../../../../../src/components/dropdown/OpenedDropdown/components/menu/MenuList.tsx"],"sourcesContent":["import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';\nimport { DropdownOption, GroupedOption, SingleOption } from '../../../type';\nimport { flattenSelectableOptions } from '../../utils/iterationOnOptions';\nimport { MenuItem } from './MenuItem';\nimport { Divider, StyledGroupedLabel } from './MenuList.styled';\n\ninterface MenuListProps {\n\toptions: DropdownOption[];\n\tisMultiSelect?: boolean;\n\tshowDescription: (title?: string, description?: string) => void;\n\tonSelect: (optionSelect: SingleOption) => void;\n\tversion?: '1.0' | '2.0' | '3.0';\n\tonInfiniteScroll?: () => void;\n\tonDropdownItemClick?: (option: DropdownOption) => void;\n\tuseDefaultCursor?: boolean;\n\tfocusedIndex?: number;\n\tisDraggable?: boolean;\n\tonOptionsReorder?: (reorderedOptions: DropdownOption[]) => void;\n\tshowCheckboxForCustomElement?: boolean;\n\tcheckboxActiveColor?: string;\n\tbrandSelectedRow?: boolean;\n\tchildrenLayout?: 'flyout' | 'nested';\n\tcollapsibleChildren?: boolean;\n\t// Collapse state lives in OpenedDropdown, which also drives keyboard focus:\n\t// the flat row order both sides use depends on which children are visible.\n\tcollapsedParents: string[];\n\tonToggleCollapsed: (value: string) => void;\n}\n// eslint-disable-next-line react/display-name\nexport const MenuList = forwardRef<HTMLDivElement[], MenuListProps>(\n\t(\n\t\t{\n\t\t\toptions,\n\t\t\tisMultiSelect,\n\t\t\tshowDescription,\n\t\t\tonSelect,\n\t\t\tversion,\n\t\t\tonInfiniteScroll,\n\t\t\tonDropdownItemClick,\n\t\t\tuseDefaultCursor,\n\t\t\tfocusedIndex = -1,\n\t\t\tisDraggable = false,\n\t\t\tonOptionsReorder,\n\t\t\tshowCheckboxForCustomElement = false,\n\t\t\tcheckboxActiveColor,\n\t\t\tbrandSelectedRow,\n\t\t\tchildrenLayout = 'flyout',\n\t\t\tcollapsibleChildren = false,\n\t\t\tcollapsedParents,\n\t\t\tonToggleCollapsed,\n\t\t},\n\t\tref,\n\t) => {\n\t\tconst observer = useRef<IntersectionObserver | null>(null);\n\t\tconst spanRef = useRef<HTMLSpanElement | null>(null);\n\t\tconst [draggedIndex, setDraggedIndex] = useState<number | null>(null);\n\t\tconst [draggedOverIndex, setDraggedOverIndex] = useState<number | null>(\n\t\t\tnull,\n\t\t);\n\n\t\tconst setupObserver = useCallback(() => {\n\t\t\tif (observer.current) {\n\t\t\t\tobserver.current.disconnect();\n\t\t\t}\n\t\t\tobserver.current = new IntersectionObserver((entries) => {\n\t\t\t\tif (entries[0].isIntersecting) {\n\t\t\t\t\tonInfiniteScroll?.();\n\t\t\t\t}\n\t\t\t});\n\t\t\tif (spanRef.current) {\n\t\t\t\tobserver.current.observe(spanRef.current);\n\t\t\t}\n\t\t}, [onInfiniteScroll]);\n\n\t\tuseEffect(() => {\n\t\t\tsetupObserver();\n\t\t\treturn () => {\n\t\t\t\tif (observer.current) {\n\t\t\t\t\tobserver.current.disconnect();\n\t\t\t\t}\n\t\t\t};\n\t\t}, [setupObserver, options]);\n\n\t\tconst handleDragStart = useCallback(\n\t\t\t(index: number) => (e: React.DragEvent<HTMLDivElement>) => {\n\t\t\t\tif (!isDraggable) return;\n\t\t\t\tsetDraggedIndex(index);\n\t\t\t\te.dataTransfer.effectAllowed = 'move';\n\t\t\t},\n\t\t\t[isDraggable],\n\t\t);\n\n\t\tconst handleDragOver = useCallback(\n\t\t\t(index: number) => (e: React.DragEvent<HTMLDivElement>) => {\n\t\t\t\tif (!isDraggable) return;\n\t\t\t\te.preventDefault();\n\t\t\t\te.dataTransfer.dropEffect = 'move';\n\t\t\t\tsetDraggedOverIndex(index);\n\t\t\t},\n\t\t\t[isDraggable],\n\t\t);\n\n\t\tconst handleDrop = useCallback(\n\t\t\t(dropIndex: number) => (e: React.DragEvent<HTMLDivElement>) => {\n\t\t\t\tif (!isDraggable || draggedIndex === null) return;\n\t\t\t\te.preventDefault();\n\n\t\t\t\tif (draggedIndex !== dropIndex) {\n\t\t\t\t\tconst newOptions = [...options];\n\t\t\t\t\tconst [item] = newOptions.splice(draggedIndex, 1);\n\t\t\t\t\tnewOptions.splice(dropIndex, 0, item);\n\t\t\t\t\tonOptionsReorder?.(newOptions);\n\t\t\t\t}\n\n\t\t\t\tsetDraggedIndex(null);\n\t\t\t\tsetDraggedOverIndex(null);\n\t\t\t},\n\t\t\t[isDraggable, draggedIndex, options, onOptionsReorder],\n\t\t);\n\n\t\tconst handleDragEnd = useCallback(() => {\n\t\t\tsetDraggedIndex(null);\n\t\t\tsetDraggedOverIndex(null);\n\t\t}, []);\n\n\t\tconst isNestedLayout = childrenLayout === 'nested';\n\n\t\tconst flatIndices = new Map<SingleOption, number>(\n\t\t\tflattenSelectableOptions(\n\t\t\t\toptions,\n\t\t\t\tisNestedLayout ? { collapsedParents } : undefined,\n\t\t\t).map((option, index) => [option, index]),\n\t\t);\n\t\treturn (\n\t\t\t<>\n\t\t\t\t{options.map((option, i) => {\n\t\t\t\t\tconst last = i === options.length - 1;\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={i} style={{ marginTop: version === '2.0' ? 2 : 0 }}>\n\t\t\t\t\t\t\t\t<StyledGroupedLabel version={version}>\n\t\t\t\t\t\t\t\t\t{groupedOption.leadingIcon ? (\n\t\t\t\t\t\t\t\t\t\t<span style={{ marginRight: 8 }}>\n\t\t\t\t\t\t\t\t\t\t\t{groupedOption.leadingIcon}\n\t\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t\t\t\t{groupedOption.label}\n\t\t\t\t\t\t\t\t</StyledGroupedLabel>\n\t\t\t\t\t\t\t\t{groupedOption.options.map((menuOption, idx) => {\n\t\t\t\t\t\t\t\t\tconst currentFlatIndex = flatIndices.get(menuOption);\n\t\t\t\t\t\t\t\t\tconst isFocused =\n\t\t\t\t\t\t\t\t\t\tcurrentFlatIndex === focusedIndex && !menuOption.disabled;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tversion={version}\n\t\t\t\t\t\t\t\t\t\t\tlast={idx === groupedOption.options.length - 1}\n\t\t\t\t\t\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t\t\t\t\t\t\tshowDescription={showDescription}\n\t\t\t\t\t\t\t\t\t\t\tonDropdownItemClick={onDropdownItemClick}\n\t\t\t\t\t\t\t\t\t\t\tisMultiSelect={isMultiSelect}\n\t\t\t\t\t\t\t\t\t\t\toption={menuOption}\n\t\t\t\t\t\t\t\t\t\t\tuseDefaultCursor={useDefaultCursor}\n\t\t\t\t\t\t\t\t\t\t\tkey={`${i}-${idx}`}\n\t\t\t\t\t\t\t\t\t\t\tisFocused={isFocused}\n\t\t\t\t\t\t\t\t\t\t\tdataIndex={currentFlatIndex}\n\t\t\t\t\t\t\t\t\t\t\tisDraggable={false}\n\t\t\t\t\t\t\t\t\t\t\tshowCheckboxForCustomElement={\n\t\t\t\t\t\t\t\t\t\t\t\tshowCheckboxForCustomElement\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tcheckboxActiveColor={checkboxActiveColor}\n\t\t\t\t\t\t\t\t\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\t\t\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (ref && typeof ref === 'object' && ref.current) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (el) ref.current[i] = el;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t{last ? <span ref={spanRef} /> : null}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tconst currentFlatIndex = flatIndices.get(singleOption);\n\t\t\t\t\tconst isFocused =\n\t\t\t\t\t\tcurrentFlatIndex === focusedIndex && !singleOption.disabled;\n\t\t\t\t\tconst nestedChildren = isNestedLayout\n\t\t\t\t\t\t? singleOption.children ?? []\n\t\t\t\t\t\t: [];\n\t\t\t\t\tconst collapsed = collapsedParents.includes(singleOption.value);\n\t\t\t\t\t// iterateOnOptions derives the parent from its selectable children,\n\t\t\t\t\t// so the dash has to ignore disabled ones as well.\n\t\t\t\t\tconst selectableChildren = nestedChildren.filter(\n\t\t\t\t\t\t(child) => !child.disabled,\n\t\t\t\t\t);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<div key={i}>\n\t\t\t\t\t\t\t{singleOption.hasDivider && <Divider />}\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\tversion={version}\n\t\t\t\t\t\t\t\tlast={last}\n\t\t\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t\t\t\tshowDescription={showDescription}\n\t\t\t\t\t\t\t\tonDropdownItemClick={onDropdownItemClick}\n\t\t\t\t\t\t\t\tisMultiSelect={isMultiSelect}\n\t\t\t\t\t\t\t\toption={singleOption}\n\t\t\t\t\t\t\t\tuseDefaultCursor={useDefaultCursor}\n\t\t\t\t\t\t\t\tkey={singleOption.value}\n\t\t\t\t\t\t\t\tisFocused={isFocused}\n\t\t\t\t\t\t\t\tdataIndex={currentFlatIndex}\n\t\t\t\t\t\t\t\tisDraggable={isDraggable}\n\t\t\t\t\t\t\t\tonDragStart={handleDragStart(i)}\n\t\t\t\t\t\t\t\tonDragOver={handleDragOver(i)}\n\t\t\t\t\t\t\t\tonDrop={handleDrop(i)}\n\t\t\t\t\t\t\t\tonDragEnd={handleDragEnd}\n\t\t\t\t\t\t\t\tisDraggedOver={draggedOverIndex === i}\n\t\t\t\t\t\t\t\tshowCheckboxForCustomElement={showCheckboxForCustomElement}\n\t\t\t\t\t\t\t\tcheckboxActiveColor={checkboxActiveColor}\n\t\t\t\t\t\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\t\t\t\t\t\tchildrenLayout={childrenLayout}\n\t\t\t\t\t\t\t\tisPartiallyChecked={\n\t\t\t\t\t\t\t\t\tselectableChildren.some((child) => child.selected) &&\n\t\t\t\t\t\t\t\t\t!selectableChildren.every((child) => child.selected)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tisCollapsible={collapsibleChildren && !!nestedChildren.length}\n\t\t\t\t\t\t\t\tisCollapsed={collapsed}\n\t\t\t\t\t\t\t\tonToggleCollapse={() => onToggleCollapsed(singleOption.value)}\n\t\t\t\t\t\t\t\tref={(el) => {\n\t\t\t\t\t\t\t\t\tif (ref && typeof ref === 'object' && ref.current && el) {\n\t\t\t\t\t\t\t\t\t\tref.current[i] = el;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t{!collapsed &&\n\t\t\t\t\t\t\t\tnestedChildren.map((child, childIdx) => {\n\t\t\t\t\t\t\t\t\tconst childFlatIndex = flatIndices.get(child);\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\tversion={version}\n\t\t\t\t\t\t\t\t\t\t\tlast={last && childIdx === nestedChildren.length - 1}\n\t\t\t\t\t\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t\t\t\t\t\t\tshowDescription={showDescription}\n\t\t\t\t\t\t\t\t\t\t\tonDropdownItemClick={onDropdownItemClick}\n\t\t\t\t\t\t\t\t\t\t\tisMultiSelect={isMultiSelect}\n\t\t\t\t\t\t\t\t\t\t\toption={child}\n\t\t\t\t\t\t\t\t\t\t\tuseDefaultCursor={useDefaultCursor}\n\t\t\t\t\t\t\t\t\t\t\tkey={child.value}\n\t\t\t\t\t\t\t\t\t\t\tisFocused={\n\t\t\t\t\t\t\t\t\t\t\t\tchildFlatIndex === focusedIndex && !child.disabled\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tdataIndex={childFlatIndex}\n\t\t\t\t\t\t\t\t\t\t\tisDraggable={false}\n\t\t\t\t\t\t\t\t\t\t\tshowCheckboxForCustomElement={\n\t\t\t\t\t\t\t\t\t\t\t\tshowCheckboxForCustomElement\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tcheckboxActiveColor={checkboxActiveColor}\n\t\t\t\t\t\t\t\t\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\t\t\t\t\t\t\t\t\tchildrenLayout={childrenLayout}\n\t\t\t\t\t\t\t\t\t\t\tisChildRow\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t{last ? <span ref={spanRef} /> : null}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t);\n\t\t\t\t})}\n\t\t\t</>\n\t\t);\n\t},\n);\n"],"names":["MenuList","forwardRef","options","isMultiSelect","showDescription","onSelect","version","onInfiniteScroll","onDropdownItemClick","useDefaultCursor","focusedIndex","isDraggable","onOptionsReorder","showCheckboxForCustomElement","checkboxActiveColor","brandSelectedRow","childrenLayout","collapsibleChildren","collapsedParents","onToggleCollapsed","ref","observer","useRef","spanRef","draggedIndex","setDraggedIndex","useState","draggedOverIndex","setDraggedOverIndex","setupObserver","useCallback","entries","useEffect","handleDragStart","index","handleDragOver","handleDrop","dropIndex","newOptions","item","handleDragEnd","isNestedLayout","flatIndices","flattenSelectableOptions","option","jsx","Fragment","i","last","groupedOption","jsxs","StyledGroupedLabel","menuOption","idx","currentFlatIndex","isFocused","MenuItem","el","singleOption","nestedChildren","collapsed","selectableChildren","child","Divider","childIdx","childFlatIndex"],"mappings":"oPA6BaA,EAAWC,EAAAA,WACvB,CACC,CACC,QAAAC,EACA,cAAAC,EACA,gBAAAC,EACA,SAAAC,EACA,QAAAC,EACA,iBAAAC,EACA,oBAAAC,EACA,iBAAAC,EACA,aAAAC,EAAe,GACf,YAAAC,EAAc,GACd,iBAAAC,EACA,6BAAAC,EAA+B,GAC/B,oBAAAC,EACA,iBAAAC,EACA,eAAAC,EAAiB,SACjB,oBAAAC,EAAsB,GACtB,iBAAAC,EACA,kBAAAC,CAAA,EAEDC,IACI,CACJ,MAAMC,EAAWC,EAAAA,OAAoC,IAAI,EACnDC,EAAUD,EAAAA,OAA+B,IAAI,EAC7C,CAACE,EAAcC,CAAe,EAAIC,EAAAA,SAAwB,IAAI,EAC9D,CAACC,EAAkBC,CAAmB,EAAIF,EAAAA,SAC/C,IAAA,EAGKG,EAAgBC,EAAAA,YAAY,IAAM,CACnCT,EAAS,SACZA,EAAS,QAAQ,WAAA,EAElBA,EAAS,QAAU,IAAI,qBAAsBU,GAAY,CACpDA,EAAQ,CAAC,EAAE,gBACdx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AC,EACA,eAAAC,EACA,WAAU,EAAA,EAZL8C,EAAM,KAAA,CAed,CAAC,EACDd,EAAOH,EAAAA,IAAC,OAAA,CAAK,IAAKtB,EAAS,EAAK,IAAA,CAAA,EAlExBwB,CAmEV,CAEF,CAAC,CAAA,CACF,CAEF,CACD"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("react"),h=require("../../../../list-item/ListItem.js"),S=require("../../../../checkBox/CheckBox.js"),A=({options:n,onSelect:c,version:r,checkboxActiveColor:u,brandSelectedRow:f})=>{const[e,s]=d.useState("notSelected");function o(){e==="partiallySelected"&&c("notSelected"),e==="selectAll"&&c("notSelected"),e==="notSelected"&&c("selectAll")}return d.useEffect(()=>{const l=[];n.filter(t=>!t.disabled).forEach(t=>{t.options?t.options.filter(i=>!i.disabled).forEach(i=>{l.push(i.selected||!1)}):l.push(t.selected||!1)}),l.every(Boolean)?s("selectAll"):l.filter(Boolean).length>0?s("partiallySelected"):s("notSelected")},[n]),a.jsx(h.ListItem,{version:r,brandSelectedRow:f,onClick:l=>{l.preventDefault(),o()},listItem:{label:"Select All",value:"All"},leadingIcon:a.jsx("div",{style:{width:18,height:18},children:a.jsx(S.CheckBox,{size:r==="2.0"?"SMALL":"DEFAULT",isChecked:e==="selectAll"||e==="partiallySelected",isPartiallyChecked:e==="partiallySelected",onValueChange:o,activeColor:u})}),variant:"default"})};exports.SelectAllMenu=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),d=require("react"),f=require("../../utils/iterationOnOptions.js"),h=require("../../../../list-item/ListItem.js"),A=require("../../../../checkBox/CheckBox.js"),C=({options:a,onSelect:i,version:n,checkboxActiveColor:u,brandSelectedRow:S,childrenLayout:r})=>{const[e,c]=d.useState("notSelected");function o(){e==="partiallySelected"&&i("notSelected"),e==="selectAll"&&i("notSelected"),e==="notSelected"&&i("selectAll")}return d.useEffect(()=>{const l=f.getSelectionLeaves(a.filter(t=>!t.disabled),r==="nested").filter(t=>!t.disabled).map(t=>t.selected||!1);l.every(Boolean)?c("selectAll"):l.filter(Boolean).length>0?c("partiallySelected"):c("notSelected")},[a,r]),s.jsx(h.ListItem,{version:n,brandSelectedRow:S,onClick:l=>{l.preventDefault(),o()},listItem:{label:"Select All",value:"All"},leadingIcon:s.jsx("div",{style:{width:18,height:18},children:s.jsx(A.CheckBox,{size:n==="2.0"?"SMALL":"DEFAULT",isChecked:e==="selectAll"||e==="partiallySelected",isPartiallyChecked:e==="partiallySelected",onValueChange:o,activeColor:u})}),variant:"default"})};exports.SelectAllMenu=C;
2
2
  //# sourceMappingURL=SelectAllMenu.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SelectAllMenu.js","sources":["../../../../../../../src/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { CheckBox } from '@src/components/checkBox';\nimport { ListItem } from '@src/components/list-item';\nimport { DropdownOption, GroupedOption, SingleOption } from '../../../type';\n\nexport type SelectAllCheckboxState =\n\t| 'notSelected'\n\t| 'selectAll'\n\t| 'partiallySelected';\n\nexport const SelectAllMenu: React.FC<{\n\toptions: DropdownOption[];\n\tonSelect: (newState: SelectAllCheckboxState) => void;\n\tversion?: '1.0' | '2.0' | '3.0';\n\tcheckboxActiveColor?: string;\n\tbrandSelectedRow?: boolean;\n}> = ({\n\toptions,\n\tonSelect,\n\tversion,\n\tcheckboxActiveColor,\n\tbrandSelectedRow,\n}) => {\n\tconst [checkStatus, setCheckStatus] =\n\t\tuseState<SelectAllCheckboxState>('notSelected');\n\n\tfunction onCheckHandler() {\n\t\tif (checkStatus === 'partiallySelected') {\n\t\t\tonSelect('notSelected');\n\t\t}\n\n\t\tif (checkStatus === 'selectAll') {\n\t\t\tonSelect('notSelected');\n\t\t}\n\n\t\tif (checkStatus === 'notSelected') {\n\t\t\tonSelect('selectAll');\n\t\t}\n\t}\n\n\tuseEffect(() => {\n\t\tconst allOptions: boolean[] = [];\n\n\t\toptions\n\t\t\t.filter((option) => !(option as SingleOption).disabled)\n\t\t\t.forEach((option) => {\n\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t(option as GroupedOption).options\n\t\t\t\t\t\t.filter((op) => !op.disabled)\n\t\t\t\t\t\t.forEach((nestedOption) => {\n\t\t\t\t\t\t\tallOptions.push(nestedOption.selected || false);\n\t\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tallOptions.push((option as SingleOption).selected || false);\n\t\t\t\t}\n\t\t\t});\n\n\t\tif (allOptions.every(Boolean)) {\n\t\t\tsetCheckStatus('selectAll');\n\t\t} else if (allOptions.filter(Boolean).length > 0) {\n\t\t\tsetCheckStatus('partiallySelected');\n\t\t} else {\n\t\t\tsetCheckStatus('notSelected');\n\t\t}\n\t}, [options]);\n\n\treturn (\n\t\t<ListItem\n\t\t\tversion={version}\n\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\tonClick={(e) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tonCheckHandler();\n\t\t\t}}\n\t\t\tlistItem={{\n\t\t\t\tlabel: 'Select All',\n\t\t\t\tvalue: 'All',\n\t\t\t}}\n\t\t\tleadingIcon={\n\t\t\t\t<div style={{ width: 18, height: 18 }}>\n\t\t\t\t\t<CheckBox\n\t\t\t\t\t\tsize={version === '2.0' ? 'SMALL' : 'DEFAULT'}\n\t\t\t\t\t\tisChecked={\n\t\t\t\t\t\t\tcheckStatus === 'selectAll' || checkStatus === 'partiallySelected'\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisPartiallyChecked={checkStatus === 'partiallySelected'}\n\t\t\t\t\t\tonValueChange={onCheckHandler}\n\t\t\t\t\t\tactiveColor={checkboxActiveColor}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t}\n\t\t\tvariant={'default'}\n\t\t/>\n\t);\n};\n"],"names":["SelectAllMenu","options","onSelect","version","checkboxActiveColor","brandSelectedRow","checkStatus","setCheckStatus","useState","onCheckHandler","useEffect","allOptions","option","op","nestedOption","jsx","ListItem","e","CheckBox"],"mappings":"qOAUaA,EAMR,CAAC,CACL,QAAAC,EACA,SAAAC,EACA,QAAAC,EACA,oBAAAC,EACA,iBAAAC,CACD,IAAM,CACL,KAAM,CAACC,EAAaC,CAAc,EACjCC,EAAAA,SAAiC,aAAa,EAE/C,SAASC,GAAiB,CACrBH,IAAgB,qBACnBJ,EAAS,aAAa,EAGnBI,IAAgB,aACnBJ,EAAS,aAAa,EAGnBI,IAAgB,eACnBJ,EAAS,WAAW,CAEtB,CAEAQ,OAAAA,EAAAA,UAAU,IAAM,CACf,MAAMC,EAAwB,CAAA,EAE9BV,EACE,OAAQW,GAAW,CAAEA,EAAwB,QAAQ,EACrD,QAASA,GAAW,CACfA,EAAyB,QAC5BA,EAAyB,QACxB,OAAQC,GAAO,CAACA,EAAG,QAAQ,EAC3B,QAASC,GAAiB,CAC1BH,EAAW,KAAKG,EAAa,UAAY,EAAK,CAC/C,CAAC,EAEFH,EAAW,KAAMC,EAAwB,UAAY,EAAK,CAE5D,CAAC,EAEED,EAAW,MAAM,OAAO,EAC3BJ,EAAe,WAAW,EAChBI,EAAW,OAAO,OAAO,EAAE,OAAS,EAC9CJ,EAAe,mBAAmB,EAElCA,EAAe,aAAa,CAE9B,EAAG,CAACN,CAAO,CAAC,EAGXc,EAAAA,IAACC,EAAAA,SAAA,CACA,QAAAb,EACA,iBAAAE,EACA,QAAUY,GAAM,CACfA,EAAE,eAAA,EACFR,EAAA,CACD,EACA,SAAU,CACT,MAAO,aACP,MAAO,KAAA,EAER,kBACE,MAAA,CAAI,MAAO,CAAE,MAAO,GAAI,OAAQ,EAAA,EAChC,SAAAM,EAAAA,IAACG,EAAAA,SAAA,CACA,KAAMf,IAAY,MAAQ,QAAU,UACpC,UACCG,IAAgB,aAAeA,IAAgB,oBAEhD,mBAAoBA,IAAgB,oBACpC,cAAeG,EACf,YAAaL,CAAA,CAAA,EAEf,EAED,QAAS,SAAA,CAAA,CAGZ"}
1
+ {"version":3,"file":"SelectAllMenu.js","sources":["../../../../../../../src/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport { CheckBox } from '@src/components/checkBox';\nimport { ListItem } from '@src/components/list-item';\nimport { DropdownOption, SingleOption } from '../../../type';\nimport { getSelectionLeaves } from '../../utils/iterationOnOptions';\n\nexport type SelectAllCheckboxState =\n\t| 'notSelected'\n\t| 'selectAll'\n\t| 'partiallySelected';\n\nexport const SelectAllMenu: React.FC<{\n\toptions: DropdownOption[];\n\tonSelect: (newState: SelectAllCheckboxState) => void;\n\tversion?: '1.0' | '2.0' | '3.0';\n\tcheckboxActiveColor?: string;\n\tbrandSelectedRow?: boolean;\n\tchildrenLayout?: 'flyout' | 'nested';\n}> = ({\n\toptions,\n\tonSelect,\n\tversion,\n\tcheckboxActiveColor,\n\tbrandSelectedRow,\n\tchildrenLayout,\n}) => {\n\tconst [checkStatus, setCheckStatus] =\n\t\tuseState<SelectAllCheckboxState>('notSelected');\n\n\tfunction onCheckHandler() {\n\t\tif (checkStatus === 'partiallySelected') {\n\t\t\tonSelect('notSelected');\n\t\t}\n\n\t\tif (checkStatus === 'selectAll') {\n\t\t\tonSelect('notSelected');\n\t\t}\n\n\t\tif (checkStatus === 'notSelected') {\n\t\t\tonSelect('selectAll');\n\t\t}\n\t}\n\n\tuseEffect(() => {\n\t\tconst allOptions = getSelectionLeaves(\n\t\t\toptions.filter((option) => !(option as SingleOption).disabled),\n\t\t\tchildrenLayout === 'nested',\n\t\t)\n\t\t\t.filter((leaf) => !leaf.disabled)\n\t\t\t.map((leaf) => leaf.selected || false);\n\n\t\tif (allOptions.every(Boolean)) {\n\t\t\tsetCheckStatus('selectAll');\n\t\t} else if (allOptions.filter(Boolean).length > 0) {\n\t\t\tsetCheckStatus('partiallySelected');\n\t\t} else {\n\t\t\tsetCheckStatus('notSelected');\n\t\t}\n\t}, [options, childrenLayout]);\n\n\treturn (\n\t\t<ListItem\n\t\t\tversion={version}\n\t\t\tbrandSelectedRow={brandSelectedRow}\n\t\t\tonClick={(e) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tonCheckHandler();\n\t\t\t}}\n\t\t\tlistItem={{\n\t\t\t\tlabel: 'Select All',\n\t\t\t\tvalue: 'All',\n\t\t\t}}\n\t\t\tleadingIcon={\n\t\t\t\t<div style={{ width: 18, height: 18 }}>\n\t\t\t\t\t<CheckBox\n\t\t\t\t\t\tsize={version === '2.0' ? 'SMALL' : 'DEFAULT'}\n\t\t\t\t\t\tisChecked={\n\t\t\t\t\t\t\tcheckStatus === 'selectAll' || checkStatus === 'partiallySelected'\n\t\t\t\t\t\t}\n\t\t\t\t\t\tisPartiallyChecked={checkStatus === 'partiallySelected'}\n\t\t\t\t\t\tonValueChange={onCheckHandler}\n\t\t\t\t\t\tactiveColor={checkboxActiveColor}\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t}\n\t\t\tvariant={'default'}\n\t\t/>\n\t);\n};\n"],"names":["SelectAllMenu","options","onSelect","version","checkboxActiveColor","brandSelectedRow","childrenLayout","checkStatus","setCheckStatus","useState","onCheckHandler","useEffect","allOptions","getSelectionLeaves","option","leaf","jsx","ListItem","e","CheckBox"],"mappings":"oRAWaA,EAOR,CAAC,CACL,QAAAC,EACA,SAAAC,EACA,QAAAC,EACA,oBAAAC,EACA,iBAAAC,EACA,eAAAC,CACD,IAAM,CACL,KAAM,CAACC,EAAaC,CAAc,EACjCC,EAAAA,SAAiC,aAAa,EAE/C,SAASC,GAAiB,CACrBH,IAAgB,qBACnBL,EAAS,aAAa,EAGnBK,IAAgB,aACnBL,EAAS,aAAa,EAGnBK,IAAgB,eACnBL,EAAS,WAAW,CAEtB,CAEAS,OAAAA,EAAAA,UAAU,IAAM,CACf,MAAMC,EAAaC,EAAAA,mBAClBZ,EAAQ,OAAQa,GAAW,CAAEA,EAAwB,QAAQ,EAC7DR,IAAmB,QAAA,EAElB,OAAQS,GAAS,CAACA,EAAK,QAAQ,EAC/B,IAAKA,GAASA,EAAK,UAAY,EAAK,EAElCH,EAAW,MAAM,OAAO,EAC3BJ,EAAe,WAAW,EAChBI,EAAW,OAAO,OAAO,EAAE,OAAS,EAC9CJ,EAAe,mBAAmB,EAElCA,EAAe,aAAa,CAE9B,EAAG,CAACP,EAASK,CAAc,CAAC,EAG3BU,EAAAA,IAACC,EAAAA,SAAA,CACA,QAAAd,EACA,iBAAAE,EACA,QAAUa,GAAM,CACfA,EAAE,eAAA,EACFR,EAAA,CACD,EACA,SAAU,CACT,MAAO,aACP,MAAO,KAAA,EAER,kBACE,MAAA,CAAI,MAAO,CAAE,MAAO,GAAI,OAAQ,EAAA,EAChC,SAAAM,EAAAA,IAACG,EAAAA,SAAA,CACA,KAAMhB,IAAY,MAAQ,QAAU,UACpC,UACCI,IAAgB,aAAeA,IAAgB,oBAEhD,mBAAoBA,IAAgB,oBACpC,cAAeG,EACf,YAAaN,CAAA,CAAA,EAEf,EAED,QAAS,SAAA,CAAA,CAGZ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),b=require("../../../../TypographyStyle.js"),f=require("../../../../../constants/Theme.js"),j=require("./MultiSelectDropdownBottomBar.styled.js"),n=require("../../../../button/Button.js"),C=s=>{const{onClear:l,onApply:u,list:i,buttonText:c,buttonOptions:y,hideClearButton:a}=s,{primaryButtonText:p,primaryButtonType:d,secondaryButtonText:B,secondaryButtonType:x}=y??{},r=i.reduce((t,o)=>{if(o.options){const m=o.options.filter(T=>T.selected===!0).length;return t+m}return o.selected?t+1:t},0);return e.jsxs(j.BottomBarContainer,{style:{justifyContent:"space-between"},children:[e.jsx(b.BodySecondary,{style:{flex:1,color:f.COLORS.content.primary},children:r?`${r} selected`:""}),e.jsxs("div",{style:{flexDirection:"row",display:"flex",gap:12},children:[!a&&e.jsx(n.Button,{size:"small",buttonType:x||"primary",buttonText:B||"Clear",onClick:l}),e.jsx(n.Button,{size:"small",buttonText:p||c||"Apply",buttonType:d||"primary",onClick:()=>{u()}})]})]})};exports.default=C;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),T=require("../../../../TypographyStyle.js"),b=require("../../../../../constants/Theme.js"),h=require("../../utils/iterationOnOptions.js"),C=require("./MultiSelectDropdownBottomBar.styled.js"),o=require("../../../../button/Button.js"),S=n=>{const{onClear:r,onApply:l,list:s,buttonText:i,buttonOptions:u,hideClearButton:c,hideSelectedCount:a,childrenLayout:y}=n,{primaryButtonText:d,primaryButtonType:p,secondaryButtonText:B,secondaryButtonType:m}=u??{},t=h.getSelectionLeaves(s,y==="nested").filter(x=>x.selected).length;return e.jsxs(C.BottomBarContainer,{style:{justifyContent:"space-between"},children:[e.jsx(T.BodySecondary,{style:{flex:1,color:b.COLORS.content.primary},children:t&&!a?`${t} selected`:""}),e.jsxs("div",{style:{flexDirection:"row",display:"flex",alignItems:"center",gap:12},children:[!c&&e.jsx(o.Button,{size:"small",buttonType:m||"primary",buttonText:B||"Clear",onClick:r}),e.jsx(o.Button,{size:"small",buttonText:d||i||"Apply",buttonType:p||"primary",onClick:()=>{l()}})]})]})};exports.default=S;
2
2
  //# sourceMappingURL=MultiSelectDropdownBottomBar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MultiSelectDropdownBottomBar.js","sources":["../../../../../../../src/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.tsx"],"sourcesContent":["import React from 'react';\nimport { Button } from '@src/components/button';\nimport { BodySecondary } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tButtonOptions,\n\tDropdownOption,\n\tGroupedOption,\n\tSingleOption,\n} from '../../../type';\nimport { BottomBarContainer } from './MultiSelectDropdownBottomBar.styled';\n\ninterface MultiSelectDropdownBottomBarProps {\n\tonClear?: () => void;\n\tonApply: () => void;\n\tlist: DropdownOption[];\n\tbuttonText?: string;\n\tbuttonOptions?: ButtonOptions;\n\thideClearButton?: boolean;\n}\nconst MultiSelectDropdownBottomBar: React.FC<\n\tMultiSelectDropdownBottomBarProps\n> = (props) => {\n\tconst { onClear, onApply, list, buttonText, buttonOptions, hideClearButton } =\n\t\tprops;\n\tconst {\n\t\tprimaryButtonText,\n\t\tprimaryButtonType,\n\t\tsecondaryButtonText,\n\t\tsecondaryButtonType,\n\t} = buttonOptions ?? {};\n\tconst count = list.reduce((total, option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\tconst groupedTotal = (option as GroupedOption).options.filter(\n\t\t\t\t(op) => op.selected === true,\n\t\t\t).length;\n\t\t\treturn total + groupedTotal;\n\t\t}\n\n\t\treturn (option as SingleOption).selected ? total + 1 : total;\n\t}, 0);\n\n\treturn (\n\t\t<BottomBarContainer style={{ justifyContent: 'space-between' }}>\n\t\t\t<BodySecondary style={{ flex: 1, color: COLORS.content.primary }}>\n\t\t\t\t{count ? `${count} selected` : ''}\n\t\t\t</BodySecondary>\n\n\t\t\t<div style={{ flexDirection: 'row', display: 'flex', gap: 12 }}>\n\t\t\t\t{!hideClearButton && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tbuttonType={secondaryButtonType || 'primary'}\n\t\t\t\t\t\tbuttonText={secondaryButtonText || 'Clear'}\n\t\t\t\t\t\tonClick={onClear}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tbuttonText={primaryButtonText || buttonText || 'Apply'}\n\t\t\t\t\tbuttonType={primaryButtonType || 'primary'}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tonApply();\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</BottomBarContainer>\n\t);\n};\n\nexport default MultiSelectDropdownBottomBar;\n"],"names":["MultiSelectDropdownBottomBar","props","onClear","onApply","list","buttonText","buttonOptions","hideClearButton","primaryButtonText","primaryButtonType","secondaryButtonText","secondaryButtonType","count","total","option","groupedTotal","op","BottomBarContainer","jsx","BodySecondary","COLORS","jsxs","Button"],"mappings":"4UAoBMA,EAEDC,GAAU,CACd,KAAM,CAAE,QAAAC,EAAS,QAAAC,EAAS,KAAAC,EAAM,WAAAC,EAAY,cAAAC,EAAe,gBAAAC,GAC1DN,EACK,CACL,kBAAAO,EACA,kBAAAC,EACA,oBAAAC,EACA,oBAAAC,CAAA,EACGL,GAAiB,CAAA,EACfM,EAAQR,EAAK,OAAO,CAACS,EAAOC,IAAW,CAC5C,GAAKA,EAAyB,QAAS,CACtC,MAAMC,EAAgBD,EAAyB,QAAQ,OACrDE,GAAOA,EAAG,WAAa,EAAA,EACvB,OACF,OAAOH,EAAQE,CAChB,CAEA,OAAQD,EAAwB,SAAWD,EAAQ,EAAIA,CACxD,EAAG,CAAC,EAEJ,cACEI,EAAAA,mBAAA,CAAmB,MAAO,CAAE,eAAgB,iBAC5C,SAAA,CAAAC,EAAAA,IAACC,EAAAA,cAAA,CAAc,MAAO,CAAE,KAAM,EAAG,MAAOC,SAAO,QAAQ,OAAA,EACrD,SAAAR,EAAQ,GAAGA,CAAK,YAAc,GAChC,EAEAS,EAAAA,KAAC,MAAA,CAAI,MAAO,CAAE,cAAe,MAAO,QAAS,OAAQ,IAAK,EAAA,EACxD,SAAA,CAAA,CAACd,GACDW,EAAAA,IAACI,EAAAA,OAAA,CACA,KAAK,QACL,WAAYX,GAAuB,UACnC,WAAYD,GAAuB,QACnC,QAASR,CAAA,CAAA,EAGXgB,EAAAA,IAACI,EAAAA,OAAA,CACA,KAAK,QACL,WAAYd,GAAqBH,GAAc,QAC/C,WAAYI,GAAqB,UACjC,QAAS,IAAM,CACdN,EAAA,CACD,CAAA,CAAA,CACD,CAAA,CACD,CAAA,EACD,CAEF"}
1
+ {"version":3,"file":"MultiSelectDropdownBottomBar.js","sources":["../../../../../../../src/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.tsx"],"sourcesContent":["import React from 'react';\nimport { Button } from '@src/components/button';\nimport { BodySecondary } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport { ButtonOptions, DropdownOption } from '../../../type';\nimport { getSelectionLeaves } from '../../utils/iterationOnOptions';\nimport { BottomBarContainer } from './MultiSelectDropdownBottomBar.styled';\n\ninterface MultiSelectDropdownBottomBarProps {\n\tonClear?: () => void;\n\tonApply: () => void;\n\tlist: DropdownOption[];\n\tbuttonText?: string;\n\tbuttonOptions?: ButtonOptions;\n\thideClearButton?: boolean;\n\thideSelectedCount?: boolean;\n\tchildrenLayout?: 'flyout' | 'nested';\n}\nconst MultiSelectDropdownBottomBar: React.FC<\n\tMultiSelectDropdownBottomBarProps\n> = (props) => {\n\tconst {\n\t\tonClear,\n\t\tonApply,\n\t\tlist,\n\t\tbuttonText,\n\t\tbuttonOptions,\n\t\thideClearButton,\n\t\thideSelectedCount,\n\t\tchildrenLayout,\n\t} = props;\n\tconst {\n\t\tprimaryButtonText,\n\t\tprimaryButtonType,\n\t\tsecondaryButtonText,\n\t\tsecondaryButtonType,\n\t} = buttonOptions ?? {};\n\tconst count = getSelectionLeaves(list, childrenLayout === 'nested').filter(\n\t\t(leaf) => leaf.selected,\n\t).length;\n\n\treturn (\n\t\t<BottomBarContainer style={{ justifyContent: 'space-between' }}>\n\t\t\t<BodySecondary style={{ flex: 1, color: COLORS.content.primary }}>\n\t\t\t\t{count && !hideSelectedCount ? `${count} selected` : ''}\n\t\t\t</BodySecondary>\n\n\t\t\t<div\n\t\t\t\tstyle={{\n\t\t\t\t\tflexDirection: 'row',\n\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\talignItems: 'center',\n\t\t\t\t\tgap: 12,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{!hideClearButton && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tbuttonType={secondaryButtonType || 'primary'}\n\t\t\t\t\t\tbuttonText={secondaryButtonText || 'Clear'}\n\t\t\t\t\t\tonClick={onClear}\n\t\t\t\t\t/>\n\t\t\t\t)}\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tbuttonText={primaryButtonText || buttonText || 'Apply'}\n\t\t\t\t\tbuttonType={primaryButtonType || 'primary'}\n\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\tonApply();\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</BottomBarContainer>\n\t);\n};\n\nexport default MultiSelectDropdownBottomBar;\n"],"names":["MultiSelectDropdownBottomBar","props","onClear","onApply","list","buttonText","buttonOptions","hideClearButton","hideSelectedCount","childrenLayout","primaryButtonText","primaryButtonType","secondaryButtonText","secondaryButtonType","count","getSelectionLeaves","leaf","BottomBarContainer","jsx","BodySecondary","COLORS","jsxs","Button"],"mappings":"2XAkBMA,EAEDC,GAAU,CACd,KAAM,CACL,QAAAC,EACA,QAAAC,EACA,KAAAC,EACA,WAAAC,EACA,cAAAC,EACA,gBAAAC,EACA,kBAAAC,EACA,eAAAC,CAAA,EACGR,EACE,CACL,kBAAAS,EACA,kBAAAC,EACA,oBAAAC,EACA,oBAAAC,CAAA,EACGP,GAAiB,CAAA,EACfQ,EAAQC,EAAAA,mBAAmBX,EAAMK,IAAmB,QAAQ,EAAE,OAClEO,GAASA,EAAK,QAAA,EACd,OAEF,cACEC,EAAAA,mBAAA,CAAmB,MAAO,CAAE,eAAgB,iBAC5C,SAAA,CAAAC,MAACC,EAAAA,eAAc,MAAO,CAAE,KAAM,EAAG,MAAOC,EAAAA,OAAO,QAAQ,OAAA,EACrD,YAAS,CAACZ,EAAoB,GAAGM,CAAK,YAAc,GACtD,EAEAO,EAAAA,KAAC,MAAA,CACA,MAAO,CACN,cAAe,MACf,QAAS,OACT,WAAY,SACZ,IAAK,EAAA,EAGL,SAAA,CAAA,CAACd,GACDW,EAAAA,IAACI,EAAAA,OAAA,CACA,KAAK,QACL,WAAYT,GAAuB,UACnC,WAAYD,GAAuB,QACnC,QAASV,CAAA,CAAA,EAGXgB,EAAAA,IAACI,EAAAA,OAAA,CACA,KAAK,QACL,WAAYZ,GAAqBL,GAAc,QAC/C,WAAYM,GAAqB,UACjC,QAAS,IAAM,CACdR,EAAA,CACD,CAAA,CAAA,CACD,CAAA,CAAA,CACD,EACD,CAEF"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e,n,t){return e.map(r=>{if(r.options){const s=r.options.map(i=>!t||t(i)?{...i,...n}:{...i});return{...r,options:[...s]}}return!t||t(r)?{...r,...n}:{...r}})}function u(e,n){e.forEach(t=>{t.options?t.options.forEach(n):n(t)})}function a(e){if(!(!e||!e.length))return e.map(n=>{const t=n;return t.selectedLabel??t.label}).join(", ")}exports.getSelectedOptionsAsText=a;exports.iterateOnOptions=o;exports.iterateOnOptionsRaw=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(r,s,e){return!e||!r.children?.length?{...r,...s}:{...r,...s,children:r.children.map(n=>n.disabled?{...n}:a(n,s,e))}}function i(r,s,e){const n=(r.children??[]).map(t=>!e||e(t)?a(t,s,!0):t.children?.length?i(t,s,e):{...t}),l=n.filter(t=>!t.disabled);return{...r,children:n,selected:l.length?l.every(t=>t.selected):r.selected}}function u(r,s,e,n=!1){const l=t=>!e||e(t)?a(t,s,n):n&&t.children?.length?i(t,s,e):{...t};return r.map(t=>t.options?{...t,options:t.options.map(l)}:l(t))}function f(r,s){const e=n=>{s(n),n.children?.forEach(e)};r.forEach(n=>{n.options?n.options.forEach(e):e(n)})}function c(r){if(!(!r||!r.length))return r.map(s=>{const e=s;return e.selectedLabel??e.label}).join(", ")}function o(r){return r.filter(s=>s.children?.length).map(s=>s.value)}function d(r,s){const e=[];return r.forEach(n=>{if(n.options){n.options.forEach(t=>{t.disabled||e.push(t)});return}const l=n;l.disabled||e.push(l),!(!s||s.collapsedParents.includes(l.value))&&l.children?.forEach(t=>{t.disabled||e.push(t)})}),e}function h(r,s=!1){const e=[];return r.forEach(n=>{if(n.options){e.push(...n.options);return}const l=n;e.push(...s&&l.children?.length?l.children:[l])}),e}exports.flattenSelectableOptions=d;exports.getNestedParentValues=o;exports.getSelectedOptionsAsText=c;exports.getSelectionLeaves=h;exports.iterateOnOptions=u;exports.iterateOnOptionsRaw=f;
2
2
  //# sourceMappingURL=iterationOnOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"iterationOnOptions.js","sources":["../../../../../../src/components/dropdown/OpenedDropdown/utils/iterationOnOptions.ts"],"sourcesContent":["import { DropdownOption, GroupedOption, SingleOption } from '../../type';\n\nexport function iterateOnOptions(\n\toptions: DropdownOption[],\n\tnewVal: Partial<SingleOption>,\n\tcheckCB?: (optionForValidation: SingleOption) => boolean,\n) {\n\tconst newOptions = options.map((option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\tconst groupedOptions = (option as GroupedOption).options.map((op) => {\n\t\t\t\tif (!checkCB || checkCB(op)) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...op,\n\t\t\t\t\t\t...newVal,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn { ...op };\n\t\t\t});\n\n\t\t\treturn {\n\t\t\t\t...option,\n\t\t\t\toptions: [...groupedOptions],\n\t\t\t};\n\t\t}\n\n\t\tif (!checkCB || checkCB(option as SingleOption)) {\n\t\t\treturn {\n\t\t\t\t...option,\n\t\t\t\t...newVal,\n\t\t\t};\n\t\t}\n\n\t\treturn { ...option };\n\t});\n\n\treturn newOptions;\n}\n\nexport function iterateOnOptionsRaw(\n\toptions: DropdownOption[],\n\tcb: (option: SingleOption) => void,\n) {\n\toptions.forEach((option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\t(option as GroupedOption).options.forEach(cb);\n\t\t} else {\n\t\t\tcb(option as SingleOption);\n\t\t}\n\t});\n}\n\nexport function getSelectedOptionsAsText(selectedOption: DropdownOption[]) {\n\tif (!selectedOption || !selectedOption.length) return undefined;\n\treturn selectedOption\n\t\t.map((option) => {\n\t\t\tconst op = option as SingleOption;\n\t\t\treturn op.selectedLabel ?? op.label;\n\t\t})\n\t\t.join(', ');\n}\n\n// get selected options as array of string\nexport function getSelectedOptionsAsArray(selectedOption: DropdownOption[]) {\n\tif (!selectedOption || !selectedOption.length) return [];\n\treturn selectedOption.map((option) => {\n\t\tconst op = option as SingleOption;\n\t\treturn op.selectedLabel ?? op.label;\n\t});\n}\n"],"names":["iterateOnOptions","options","newVal","checkCB","option","groupedOptions","op","iterateOnOptionsRaw","cb","getSelectedOptionsAsText","selectedOption"],"mappings":"gFAEO,SAASA,EACfC,EACAC,EACAC,EACC,CA8BD,OA7BmBF,EAAQ,IAAKG,GAAW,CAC1C,GAAKA,EAAyB,QAAS,CACtC,MAAMC,EAAkBD,EAAyB,QAAQ,IAAKE,GACzD,CAACH,GAAWA,EAAQG,CAAE,EAClB,CACN,GAAGA,EACH,GAAGJ,CAAA,EAIE,CAAE,GAAGI,CAAA,CACZ,EAED,MAAO,CACN,GAAGF,EACH,QAAS,CAAC,GAAGC,CAAc,CAAA,CAE7B,CAEA,MAAI,CAACF,GAAWA,EAAQC,CAAsB,EACtC,CACN,GAAGA,EACH,GAAGF,CAAA,EAIE,CAAE,GAAGE,CAAA,CACb,CAAC,CAGF,CAEO,SAASG,EACfN,EACAO,EACC,CACDP,EAAQ,QAASG,GAAW,CACtBA,EAAyB,QAC5BA,EAAyB,QAAQ,QAAQI,CAAE,EAE5CA,EAAGJ,CAAsB,CAE3B,CAAC,CACF,CAEO,SAASK,EAAyBC,EAAkC,CAC1E,GAAI,GAACA,GAAkB,CAACA,EAAe,QACvC,OAAOA,EACL,IAAKN,GAAW,CAChB,MAAME,EAAKF,EACX,OAAOE,EAAG,eAAiBA,EAAG,KAC/B,CAAC,EACA,KAAK,IAAI,CACZ"}
1
+ {"version":3,"file":"iterationOnOptions.js","sources":["../../../../../../src/components/dropdown/OpenedDropdown/utils/iterationOnOptions.ts"],"sourcesContent":["import { DropdownOption, GroupedOption, SingleOption } from '../../type';\n\nfunction applyToSubtree(\n\toption: SingleOption,\n\tnewVal: Partial<SingleOption>,\n\tnestedChildren: boolean,\n): SingleOption {\n\tif (!nestedChildren || !option.children?.length) {\n\t\treturn { ...option, ...newVal };\n\t}\n\n\treturn {\n\t\t...option,\n\t\t...newVal,\n\t\tchildren: option.children.map((child) =>\n\t\t\tchild.disabled\n\t\t\t\t? { ...child }\n\t\t\t\t: applyToSubtree(child, newVal, nestedChildren),\n\t\t),\n\t};\n}\n\n/**\n * A parent is selected only when every selectable child is. Disabled children are\n * excluded because applyToSubtree never selects them - counting them would leave\n * the parent stuck on the indeterminate dash.\n */\nfunction walkChildren(\n\toption: SingleOption,\n\tnewVal: Partial<SingleOption>,\n\tcheckCB?: (optionForValidation: SingleOption) => boolean,\n): SingleOption {\n\tconst children = (option.children ?? []).map((child) =>\n\t\t!checkCB || checkCB(child)\n\t\t\t? applyToSubtree(child, newVal, true)\n\t\t\t: child.children?.length\n\t\t\t? walkChildren(child, newVal, checkCB)\n\t\t\t: { ...child },\n\t);\n\n\tconst selectableChildren = children.filter((child) => !child.disabled);\n\n\treturn {\n\t\t...option,\n\t\tchildren,\n\t\t// `every` on an empty list reports selected, so keep what the parent had.\n\t\tselected: selectableChildren.length\n\t\t\t? selectableChildren.every((child) => child.selected)\n\t\t\t: option.selected,\n\t};\n}\n\nexport function iterateOnOptions(\n\toptions: DropdownOption[],\n\tnewVal: Partial<SingleOption>,\n\tcheckCB?: (optionForValidation: SingleOption) => boolean,\n\tnestedChildren = false,\n) {\n\tconst applyToOption = (option: SingleOption): SingleOption => {\n\t\tif (!checkCB || checkCB(option)) {\n\t\t\treturn applyToSubtree(option, newVal, nestedChildren);\n\t\t}\n\n\t\tif (nestedChildren && option.children?.length) {\n\t\t\treturn walkChildren(option, newVal, checkCB);\n\t\t}\n\n\t\treturn { ...option };\n\t};\n\n\treturn options.map((option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\treturn {\n\t\t\t\t...option,\n\t\t\t\toptions: (option as GroupedOption).options.map(applyToOption),\n\t\t\t};\n\t\t}\n\n\t\treturn applyToOption(option as SingleOption);\n\t});\n}\n\nexport function iterateOnOptionsRaw(\n\toptions: DropdownOption[],\n\tcb: (option: SingleOption) => void,\n) {\n\tconst visit = (option: SingleOption) => {\n\t\tcb(option);\n\t\toption.children?.forEach(visit);\n\t};\n\n\toptions.forEach((option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\t(option as GroupedOption).options.forEach(visit);\n\t\t} else {\n\t\t\tvisit(option as SingleOption);\n\t\t}\n\t});\n}\n\nexport function getSelectedOptionsAsText(selectedOption: DropdownOption[]) {\n\tif (!selectedOption || !selectedOption.length) return undefined;\n\treturn selectedOption\n\t\t.map((option) => {\n\t\t\tconst op = option as SingleOption;\n\t\t\treturn op.selectedLabel ?? op.label;\n\t\t})\n\t\t.join(', ');\n}\n\n// get selected options as array of string\nexport function getSelectedOptionsAsArray(selectedOption: DropdownOption[]) {\n\tif (!selectedOption || !selectedOption.length) return [];\n\treturn selectedOption.map((option) => {\n\t\tconst op = option as SingleOption;\n\t\treturn op.selectedLabel ?? op.label;\n\t});\n}\n\nexport function getNestedParentValues(options: DropdownOption[]): string[] {\n\treturn options\n\t\t.filter((option) => (option as SingleOption).children?.length)\n\t\t.map((option) => (option as SingleOption).value);\n}\n\n/**\n * Selectable rows in the order they are rendered, so keyboard focus indices line\n * up with the rows MenuList numbers - otherwise arrow keys highlight one option\n * while Enter toggles another.\n */\nexport function flattenSelectableOptions(\n\toptions: DropdownOption[],\n\tnestedChildren?: { collapsedParents: string[] },\n): SingleOption[] {\n\tconst flattened: SingleOption[] = [];\n\n\toptions.forEach((option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\t(option as GroupedOption).options.forEach((groupedOption) => {\n\t\t\t\tif (!groupedOption.disabled) {\n\t\t\t\t\tflattened.push(groupedOption);\n\t\t\t\t}\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst singleOption = option as SingleOption;\n\t\tif (!singleOption.disabled) {\n\t\t\tflattened.push(singleOption);\n\t\t}\n\n\t\tif (\n\t\t\t!nestedChildren ||\n\t\t\tnestedChildren.collapsedParents.includes(singleOption.value)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tsingleOption.children?.forEach((child) => {\n\t\t\tif (!child.disabled) {\n\t\t\t\tflattened.push(child);\n\t\t\t}\n\t\t});\n\t});\n\n\treturn flattened;\n}\n\n/**\n * The rows a selection count is about. Only the nested layout makes children\n * selectable - in the flyout layout a submenu click marks the parent, so the\n * parent stays the row that counts. Disabled rows are kept for the caller to filter.\n */\nexport function getSelectionLeaves(\n\toptions: DropdownOption[],\n\tnestedChildren = false,\n): SingleOption[] {\n\tconst leaves: SingleOption[] = [];\n\n\toptions.forEach((option) => {\n\t\tif ((option as GroupedOption).options) {\n\t\t\tleaves.push(...(option as GroupedOption).options);\n\t\t\treturn;\n\t\t}\n\n\t\tconst singleOption = option as SingleOption;\n\t\tleaves.push(\n\t\t\t...(nestedChildren && singleOption.children?.length\n\t\t\t\t? singleOption.children\n\t\t\t\t: [singleOption]),\n\t\t);\n\t});\n\n\treturn leaves;\n}\n"],"names":["applyToSubtree","option","newVal","nestedChildren","child","walkChildren","checkCB","children","selectableChildren","iterateOnOptions","options","applyToOption","iterateOnOptionsRaw","cb","visit","getSelectedOptionsAsText","selectedOption","op","getNestedParentValues","flattenSelectableOptions","flattened","groupedOption","singleOption","getSelectionLeaves","leaves"],"mappings":"gFAEA,SAASA,EACRC,EACAC,EACAC,EACe,CACf,MAAI,CAACA,GAAkB,CAACF,EAAO,UAAU,OACjC,CAAE,GAAGA,EAAQ,GAAGC,CAAA,EAGjB,CACN,GAAGD,EACH,GAAGC,EACH,SAAUD,EA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W,CAChB,MAAMgB,EAAKhB,EACX,OAAOgB,EAAG,eAAiBA,EAAG,KAC/B,CAAC,EACA,KAAK,IAAI,CACZ,CAWO,SAASC,EAAsBR,EAAqC,CAC1E,OAAOA,EACL,OAAQT,GAAYA,EAAwB,UAAU,MAAM,EAC5D,IAAKA,GAAYA,EAAwB,KAAK,CACjD,CAOO,SAASkB,EACfT,EACAP,EACiB,CACjB,MAAMiB,EAA4B,CAAA,EAElC,OAAAV,EAAQ,QAAST,GAAW,CAC3B,GAAKA,EAAyB,QAAS,CACrCA,EAAyB,QAAQ,QAASoB,GAAkB,CACvDA,EAAc,UAClBD,EAAU,KAAKC,CAAa,CAE9B,CAAC,EACD,MACD,CAEA,MAAMC,EAAerB,EAChBqB,EAAa,UACjBF,EAAU,KAAKE,CAAY,EAI3B,GAACnB,GACDA,EAAe,iBAAiB,SAASmB,EAAa,KAAK,IAK5DA,EAAa,UAAU,QAASlB,GAAU,CACpCA,EAAM,UACVgB,EAAU,KAAKhB,CAAK,CAEtB,CAAC,CACF,CAAC,EAEMgB,CACR,CAOO,SAASG,EACfb,EACAP,EAAiB,GACA,CACjB,MAAMqB,EAAyB,CAAA,EAE/B,OAAAd,EAAQ,QAAST,GAAW,CAC3B,GAAKA,EAAyB,QAAS,CACtCuB,EAAO,KAAK,GAAIvB,EAAyB,OAAO,EAChD,MACD,CAEA,MAAMqB,EAAerB,EACrBuB,EAAO,KACN,GAAIrB,GAAkBmB,EAAa,UAAU,OAC1CA,EAAa,SACb,CAACA,CAAY,CAAA,CAElB,CAAC,EAEME,CACR"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=require("lodash/debounce"),O=require("react"),v=require("../OpenedDropdown/utils/iterationOnOptions.js"),U=a=>a&&typeof a=="object"&&"default"in a?a:{default:a},V=U(Q),X=(a="1.0",C,R,A,g,w,j,H=[],i)=>{const[c,d]=O.useState(C??[]),[h,b]=O.useState([]),[l,T]=O.useState(""),[M,m]=O.useState(void 0),E=O.useRef(c),I=O.useRef(w);O.useEffect(()=>{I.current=w},[w]),O.useEffect(()=>{if(E.current=c,h.length&&l&&w){let t=[...h];const r=c.map(e=>{if(e.options)return e.options.map(n=>({value:n.value,selected:n.selected}));const s=e;return{value:s.value,selected:s.selected}}).flat();t=t.map(e=>{const s=r.find(n=>e.value===n.value);return s?{...e,selected:s.selected}:e}),j&&(t=t.map(e=>({...e,disabled:!H.includes(e.value)}))),b(g&&!A?[...t.sort(e=>e.selected?-1:1)]:[...t])}},[c]),O.useEffect(()=>{if(C){const t=[...C];d(g&&!A?[...t.sort(r=>r.selected?-1:1)]:[...t])}},[C]);const P=t=>{const r=[];return t.forEach(e=>{if(e.options){const s=e.options.filter(n=>n.selected===!0);r.push({...e,options:[...s]})}else e.selected&&r.push({...e})}),r},L=t=>{let r=0;return t.forEach(e=>{e.options?r+=e.options.filter(s=>s.selected===!0).length:e.selected&&r++}),r},D=t=>!g||!i&&i!==0?!1:L(t)>=i,y=O.useCallback(async t=>{const r=I.current;if(!t||!r)return;const e=[];v.iterateOnOptionsRaw(E.current,s=>{s.selected&&!e.includes(s.value)&&e.push(s.value)});try{const s=await r(t);if(m(void 0),s){const n=s.map(f=>{if(f.options){const o=f;return{...o,options:o.options.map(u=>({...u,selected:e.includes(u.value)}))}}return{...f,selected:e.includes(f.value)}});b([...n])}else b([])}catch(s){b([]),m(s instanceof Error?s.message:"Something went wrong while fetching the list. Please try again")}},[]),F=O.useMemo(()=>V.default(y,300),[y]);O.useEffect(()=>()=>F?.cancel(),[F]);function W(t){if(T(t),b([]),m(void 0),!t){F?.cancel();return}F(t)}function k(){l&&(m(void 0),y(l))}function q(t,r){if(!g)R?.(t);else{if(t.selected&&i&&D(c))return;if(h.length&&l&&w)if(t.selected){if(i&&D(c))return;let e=!1;const s=v.iterateOnOptions(c,{selected:t.selected},n=>n.value===t.value?(e=!0,!0):!1);if(e||s.push(t),r)return[...s];d([...s]),a==="2.0"&&p(s)}else{let e=!1,s=v.iterateOnOptions(c,{selected:t.selected},n=>n.value===t.value?(e=!0,!0):!1);if(e&&(s=s.filter(n=>n.value!==t.value)),r)return[...s];d([...s]),a==="2.0"&&p(s)}else{const e=v.iterateOnOptions(c,{selected:t.selected},s=>s.value===t.value);if(r)return[...e];d([...e]),a==="2.0"&&p(e)}}}function z(t){let r=[...c];h.forEach(e=>{r=r.map(s=>{const n=e;return typeof n.value<"u"&&n.value===s.value?{...s,selected:!1}:s})}),d([...r]),a==="2.0"&&p(r)}function B(t){let r=[...c];if(i&&i>0){const e=L(r),s=i-e;if(s<=0)return;let n=0;h.forEach(f=>{if(n>=s)return;let o=!1;r=r.map(u=>{const _=f;return u.selected||u.disabled?u:typeof _.value<"u"&&_.value===u.value?(o=!0,n++,{...u,selected:!0}):u}),!o&&n<s&&(f.disabled||(r.push({...f,selected:!0}),n++))}),d([...r]),a==="2.0"&&p(r)}}function G(t){if(h.length&&l&&w)t==="selectAll"?B():z();else if(t==="selectAll")if(i&&i>0){const r=L(c),e=i-r;if(e<=0)return;let s=0;const n=c.map(f=>{if(f.options){const o=f;return{...o,options:o.options.map(u=>u.disabled||u.selected||l&&!u.label?.toLowerCase().includes(l.toLowerCase())?u:s<e?(s++,{...u,selected:!0}):u)}}else{const o=f;return o.disabled||o.selected||l&&!o.label?.toLowerCase().includes(l.toLowerCase())?f:s<e?(s++,{...f,selected:!0}):f}});d([...n]),a==="2.0"&&p(n)}else{const r=v.iterateOnOptions(c,{selected:!0},e=>l?e.label?.toLowerCase().includes(l.toLowerCase())&&!e.disabled:!e.disabled);d([...r]),a==="2.0"&&p(r)}else if(t==="notSelected"){const r=v.iterateOnOptions(c,{selected:!1},e=>!e.disabled);d([...r]),a==="2.0"&&p(r)}}function J(){const t=v.iterateOnOptions(c,{selected:!1});d([...t]),a==="2.0"&&p(t)}function N(t){if(!g){q({label:l,value:l,isFreeForm:!0,selected:!0});return}const r=c.map(e=>e.options?e:{...e,selected:e.label===l&&e.value===l?t:e.selected});t&&(r.some(e=>e.label===l&&e.value===l)||r.unshift({label:l,value:l,isFreeForm:!0,selected:!0})),d([...r]),a==="2.0"&&p(r)}function p(t){const r=P(t??E.current);R?.([...r])}return{latestDropdownOptionsRef:E,dropdownOptions:c,search:W,searchedString:l,searchedOptions:h,searchError:M,retrySearch:k,onApplyHandler:q,selectAllHandler:G,onMultiSelectClear:J,onFreeFormSelect:N,onMultiSelectApply:p,getSelectedOptions:P,getCurrentSelectionCount:L,isMaxSelectionsReached:D,maxSelections:i}};exports.useDropdown=X;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("lodash/debounce"),h=require("react"),v=require("../OpenedDropdown/utils/iterationOnOptions.js"),X=f=>f&&typeof f=="object"&&"default"in f?f:{default:f},Y=X(V),Z=(f="1.0",m,A,I,C,w,H,T=[],a,M)=>{const p=M==="nested",[i,d]=h.useState(m??[]),[g,b]=h.useState([]),[l,W]=h.useState(""),[k,L]=h.useState(void 0),E=h.useRef(i),P=h.useRef(w);h.useEffect(()=>{P.current=w},[w]),h.useEffect(()=>{if(E.current=i,g.length&&l&&w){let t=[...g];const s=i.map(e=>{if(e.options)return e.options.map(n=>({value:n.value,selected:n.selected}));const r=e;return{value:r.value,selected:r.selected}}).flat();t=t.map(e=>{const r=s.find(n=>e.value===n.value);return r?{...e,selected:r.selected}:e}),H&&(t=t.map(e=>({...e,disabled:!T.includes(e.value)}))),b(C&&!I?[...t.sort(e=>e.selected?-1:1)]:[...t])}},[i]),h.useEffect(()=>{if(m){const t=[...m];d(C&&!I?[...t.sort(s=>s.selected?-1:1)]:[...t])}},[m]);const q=t=>{const s=[];return t.forEach(e=>{if(e.options){const r=e.options.filter(n=>n.selected===!0);s.push({...e,options:[...r]})}else{const r=e;if(p&&r.children?.length){const n=r.children.filter(c=>c.selected);n.length&&s.push({...r,children:n})}else r.selected&&s.push({...e})}}),s},F=t=>v.getSelectionLeaves(t,p).filter(s=>s.selected).length,y=t=>!C||!a&&a!==0?!1:F(t)>=a,R=h.useCallback(async t=>{const s=P.current;if(!t||!s)return;const e=[];v.iterateOnOptionsRaw(E.current,r=>{r.selected&&!e.includes(r.value)&&e.push(r.value)});try{const r=await s(t);if(L(void 0),r){const n=r.map(c=>{if(c.options){const o=c;return{...o,options:o.options.map(u=>({...u,selected:e.includes(u.value)}))}}return{...c,selected:e.includes(c.value)}});b([...n])}else b([])}catch(r){b([]),L(r instanceof Error?r.message:"Something went wrong while fetching the list. Please try again")}},[]),D=h.useMemo(()=>Y.default(R,300),[R]);h.useEffect(()=>()=>D?.cancel(),[D]);function z(t){if(W(t),b([]),L(void 0),!t){D?.cancel();return}D(t)}function B(){l&&(L(void 0),R(l))}function _(t,s){if(!C)A?.(t);else{if(t.selected&&a&&y(i))return;if(g.length&&l&&w)if(t.selected){if(a&&y(i))return;let e=!1;const r=v.iterateOnOptions(i,{selected:t.selected},n=>n.value===t.value?(e=!0,!0):!1,p);if(e||r.push(t),s)return[...r];d([...r]),f==="2.0"&&O(r)}else{let e=!1,r=v.iterateOnOptions(i,{selected:t.selected},n=>n.value===t.value?(e=!0,!0):!1,p);if(e&&(r=r.filter(n=>n.value!==t.value)),s)return[...r];d([...r]),f==="2.0"&&O(r)}else{const e=v.iterateOnOptions(i,{selected:t.selected},r=>r.value===t.value,p);if(s)return[...e];d([...e]),f==="2.0"&&O(e)}}}function G(t){let s=[...i];g.forEach(e=>{s=s.map(r=>{const n=e;return typeof n.value<"u"&&n.value===r.value?{...r,selected:!1}:r})}),d([...s]),f==="2.0"&&O(s)}function J(t){let s=[...i];if(a&&a>0){const e=F(s),r=a-e;if(r<=0)return;let n=0;g.forEach(c=>{if(n>=r)return;let o=!1;s=s.map(u=>{const j=c;return u.selected||u.disabled?u:typeof j.value<"u"&&j.value===u.value?(o=!0,n++,{...u,selected:!0}):u}),!o&&n<r&&(c.disabled||(s.push({...c,selected:!0}),n++))}),d([...s]),f==="2.0"&&O(s)}}function N(t){if(g.length&&l&&w)t==="selectAll"?J():G();else if(t==="selectAll")if(a&&a>0){const s=F(i),e=a-s;if(e<=0)return;let r=0;const n=i.map(c=>{if(c.options){const o=c;return{...o,options:o.options.map(u=>u.disabled||u.selected||l&&!u.label?.toLowerCase().includes(l.toLowerCase())?u:r<e?(r++,{...u,selected:!0}):u)}}else{const o=c;return o.disabled||o.selected||l&&!o.label?.toLowerCase().includes(l.toLowerCase())?c:r<e?(r++,{...c,selected:!0}):c}});d([...n]),f==="2.0"&&O(n)}else{const s=v.iterateOnOptions(i,{selected:!0},e=>l?e.label?.toLowerCase().includes(l.toLowerCase())&&!e.disabled:!e.disabled,p);d([...s]),f==="2.0"&&O(s)}else if(t==="notSelected"){const s=v.iterateOnOptions(i,{selected:!1},e=>!e.disabled,p);d([...s]),f==="2.0"&&O(s)}}function Q(){const t=v.iterateOnOptions(i,{selected:!1},void 0,p);d([...t]),f==="2.0"&&O(t)}function U(t){if(!C){_({label:l,value:l,isFreeForm:!0,selected:!0});return}const s=i.map(e=>e.options?e:{...e,selected:e.label===l&&e.value===l?t:e.selected});t&&(s.some(e=>e.label===l&&e.value===l)||s.unshift({label:l,value:l,isFreeForm:!0,selected:!0})),d([...s]),f==="2.0"&&O(s)}function O(t){const s=q(t??E.current);A?.([...s])}return{latestDropdownOptionsRef:E,dropdownOptions:i,search:z,searchedString:l,searchedOptions:g,searchError:k,retrySearch:B,onApplyHandler:_,selectAllHandler:N,onMultiSelectClear:Q,onFreeFormSelect:U,onMultiSelectApply:O,getSelectedOptions:q,getCurrentSelectionCount:F,isMaxSelectionsReached:y,maxSelections:a}};exports.useDropdown=Z;
2
2
  //# sourceMappingURL=useDropdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDropdown.js","sources":["../../../../../src/components/dropdown/hooks/useDropdown.tsx"],"sourcesContent":["import debounce from 'lodash/debounce';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { SelectAllCheckboxState } from '../OpenedDropdown/components/menu/SelectAllMenu';\nimport {\n\titerateOnOptions,\n\titerateOnOptionsRaw,\n} from '../OpenedDropdown/utils/iterationOnOptions';\nimport { DropdownOption, GroupedOption, SingleOption } from '../type';\n\nexport const useDropdown = (\n\tversion = '1.0',\n\toptions: DropdownOption[],\n\tonSelect: ((option: DropdownOption | DropdownOption[]) => void) | undefined,\n\tskipSorting?: boolean,\n\tisMultiSelect?: boolean,\n\tonSearch?: (searchKey: string) => Promise<DropdownOption[]>,\n\tdisableOtherSearchedOption?: boolean,\n\tdisableSearchedOptionExcept: string[] = [],\n\tmaxSelections?: number,\n) => {\n\tconst [dropdownOptions, setDropdownOptions] = useState(options ?? []);\n\tconst [searchedOptions, setSearchedOptions] = useState<DropdownOption[]>([]);\n\tconst [searchedString, setSearchedString] = useState('');\n\tconst [searchError, setSearchError] = useState<string | undefined>(undefined);\n\tconst latestDropdownOptionsRef = useRef(dropdownOptions);\n\t/** Store latest onSearch so performSearch/debouncedSearch stay stable when parent re-renders with new callback reference. */\n\tconst onSearchRef = useRef(onSearch);\n\n\tuseEffect(() => {\n\t\tonSearchRef.current = onSearch;\n\t}, [onSearch]);\n\n\tuseEffect(() => {\n\t\tlatestDropdownOptionsRef.current = dropdownOptions;\n\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tlet searchedOptionsClone = [...searchedOptions] as SingleOption[];\n\t\t\tconst dropdownOptionFlat = dropdownOptions\n\t\t\t\t.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\treturn (option as GroupedOption).options.map((op) => ({\n\t\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tconst op = option as SingleOption;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t\t.flat();\n\n\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\tconst selectedDropdownOption = dropdownOptionFlat.find(\n\t\t\t\t\t(dropdownOption) => {\n\t\t\t\t\t\tif (option.value === dropdownOption.value) {\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (selectedDropdownOption) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedDropdownOption.selected,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn option;\n\t\t\t});\n\n\t\t\t// disable other options except selected in searched options\n\t\t\tif (disableOtherSearchedOption) {\n\t\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tdisabled: !disableSearchedOptionExcept.includes(option.value),\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetSearchedOptions([\n\t\t\t\t\t...searchedOptionsClone.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([...searchedOptionsClone]);\n\t\t\t}\n\t\t}\n\t}, [dropdownOptions]);\n\n\tuseEffect(() => {\n\t\tif (options) {\n\t\t\tconst writeOptions = [...options];\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetDropdownOptions([\n\t\t\t\t\t...writeOptions.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetDropdownOptions([...writeOptions]);\n\t\t\t}\n\t\t}\n\t}, [options]);\n\n\tconst getSelectedOptions = (data: DropdownOption[]) => {\n\t\tconst selectedOptions: DropdownOption[] = [];\n\t\tdata.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\tconst groupedOptions = (option as GroupedOption).options.filter(\n\t\t\t\t\t(op) => op.selected === true,\n\t\t\t\t);\n\t\t\t\tselectedOptions.push({\n\t\t\t\t\t...option,\n\t\t\t\t\toptions: [...groupedOptions],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif ((option as SingleOption).selected) {\n\t\t\t\t\tselectedOptions.push({ ...option });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn selectedOptions;\n\t};\n\n\t// Count current selections for max selection limit\n\tconst getCurrentSelectionCount = (data: DropdownOption[]) => {\n\t\tlet count = 0;\n\t\tdata.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\tcount += (option as GroupedOption).options.filter(\n\t\t\t\t\t(op) => op.selected === true,\n\t\t\t\t).length;\n\t\t\t} else {\n\t\t\t\tif ((option as SingleOption).selected) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn count;\n\t};\n\n\t// Check if max selections limit is reached\n\tconst isMaxSelectionsReached = (data: DropdownOption[]) => {\n\t\tif (!isMultiSelect || (!maxSelections && maxSelections !== 0)) return false;\n\t\treturn getCurrentSelectionCount(data) >= maxSelections;\n\t};\n\n\t/** Reads onSearch from ref so it stays stable ([] deps). No-ops when onSearchRef.current is undefined. */\n\tconst performSearch = useCallback(async (searchKey: string) => {\n\t\tconst onSearchFn = onSearchRef.current;\n\t\tif (!searchKey || !onSearchFn) return;\n\n\t\tconst selectedIds: (string | number)[] = [];\n\t\titerateOnOptionsRaw(latestDropdownOptionsRef.current, (option) => {\n\t\t\tif (option.selected && !selectedIds.includes(option.value)) {\n\t\t\t\tselectedIds.push(option.value);\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tconst response = await onSearchFn(searchKey);\n\t\t\tsetSearchError(undefined);\n\t\t\tif (response) {\n\t\t\t\tconst updatedResponseData = response.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => ({\n\t\t\t\t\t\t\t\t...op,\n\t\t\t\t\t\t\t\tselected: selectedIds.includes(op.value),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedIds.includes((option as SingleOption).value),\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tsetSearchedOptions([...updatedResponseData]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tsetSearchedOptions([]);\n\t\t\tsetSearchError(\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: 'Something went wrong while fetching the list. Please try again',\n\t\t\t);\n\t\t}\n\t}, []);\n\n\t/** Independent of onSearch so debounce is stable when callers pass inline functions. Pending searches are preserved across parent re-renders. performSearch no-ops when onSearchRef.current is undefined. */\n\tconst debouncedSearch = useMemo(\n\t\t() => debounce(performSearch, 300),\n\t\t[performSearch],\n\t);\n\n\tuseEffect(() => () => debouncedSearch?.cancel(), [debouncedSearch]);\n\n\tfunction search(searchKey: string) {\n\t\tsetSearchedString(searchKey);\n\t\tsetSearchedOptions([]);\n\t\tsetSearchError(undefined);\n\n\t\tif (!searchKey) {\n\t\t\tdebouncedSearch?.cancel();\n\t\t\treturn;\n\t\t}\n\n\t\tdebouncedSearch(searchKey);\n\t}\n\n\tfunction retrySearch() {\n\t\tif (searchedString) {\n\t\t\tsetSearchError(undefined);\n\t\t\tperformSearch(searchedString);\n\t\t}\n\t}\n\n\t/**\n\t * wrapper to prepare option for onSelect\n\t * for single select, this will call the onClose handler ,\n\t * for multiselect, it will do state update for options list\n\t * \t\tto make any option select,\n\t * \t\t\t\tonApplyHandler({ label, value: selected: true })\n\t * to deselect any option\n\t * \t\t\t\tonApplyHandler({ label, value: selected: false })\n\t * @param optionSelect\n\t */\n\tfunction onApplyHandler(optionSelect: SingleOption, returnOnly?: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonSelect?.(optionSelect);\n\t\t} else {\n\t\t\t// Check if trying to select and max selections is reached\n\t\t\tif (\n\t\t\t\toptionSelect.selected &&\n\t\t\t\tmaxSelections &&\n\t\t\t\tisMaxSelectionsReached(dropdownOptions)\n\t\t\t) {\n\t\t\t\t// Max selections reached, don't allow new selections\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\t\t/** Search mode */\n\t\t\t\t/**\n\t\t\t\t * on selected, push it to dropdown options,\n\t\t\t\t * on un-select, remove from dropdown option\n\t\t\t\t */\n\n\t\t\t\tif (optionSelect.selected) {\n\t\t\t\t\t// Check max selections for search mode too\n\t\t\t\t\tif (maxSelections && isMaxSelectionsReached(dropdownOptions)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t/** check if already there or not,\n\t\t\t\t\t * if yes, just update\n\t\t\t\t\t * else ,\n\t\t\t\t\t * \tappend\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList.push(optionSelect);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t/** un-select,\n\t\t\t\t\t * if already present in initial data,\n\t\t\t\t\t * yes, just update\n\t\t\t\t\t * else,\n\t\t\t\t\t * \tremove\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tlet currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\tif (alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList = currList.filter((option) => {\n\t\t\t\t\t\t\tif (option.value === optionSelect.value) {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t(optionForValidation: SingleOption) =>\n\t\t\t\t\t\toptionForValidation.value === optionSelect.value,\n\t\t\t\t);\n\n\t\t\t\tif (returnOnly) {\n\t\t\t\t\treturn [...currList];\n\t\t\t\t}\n\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllForSearch(select: boolean) {\n\t\t// const allSearchedValues = searchedOptions.map(option => option.value);\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select) {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found) {\n\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t}\n\t}\n\n\tfunction selectAllForSearchWithLimit(select: boolean) {\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select && maxSelections && maxSelections > 0) {\n\t\t\tconst currentCount = getCurrentSelectionCount(clonedDropdownOptions);\n\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t// Already at max, don't select any more\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet selectedCount = 0;\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tif (selectedCount >= remainingSlots) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t// Skip if already selected\n\t\t\t\t\tif ((dOption as SingleOption).selected) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\t\t\t\t\t// Skip if disabled\n\t\t\t\t\tif ((dOption as SingleOption).disabled) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found && selectedCount < remainingSlots) {\n\t\t\t\t\tconst newOption = option as SingleOption;\n\t\t\t\t\tif (!newOption.disabled) {\n\t\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\t\tif (version === '2.0') {\n\t\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllHandler(newState: SelectAllCheckboxState) {\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tselectAllForSearchWithLimit(true);\n\t\t\t} else {\n\t\t\t\tselectAllForSearch(false);\n\t\t\t}\n\t\t} else {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tif (maxSelections && maxSelections > 0) {\n\t\t\t\t\t// Only select up to maxSelections limit\n\t\t\t\t\tconst currentCount = getCurrentSelectionCount(dropdownOptions);\n\t\t\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t\t\t// Already at max, don't select any more\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet selectedCount = 0;\n\t\t\t\t\tconst newOptions = dropdownOptions.map((option) => {\n\t\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\t\t// Handle grouped options\n\t\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => {\n\t\t\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\t\t\tif (op.disabled) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\t\t\tif (op.selected) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t\t\t!op.label\n\t\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\t\t\treturn { ...op, selected: true };\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\tif (singleOption.disabled) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\tif (singleOption.selected) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t!singleOption.label\n\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\treturn { ...option, selected: true };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// No max selection limit, select all\n\t\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: true },\n\t\t\t\t\t\t(option) =>\n\t\t\t\t\t\t\tsearchedString\n\t\t\t\t\t\t\t\t? option.label\n\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase()) && !option.disabled\n\t\t\t\t\t\t\t\t: !option.disabled,\n\t\t\t\t\t);\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (newState === 'notSelected') {\n\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: false },\n\t\t\t\t\t(option) => !option.disabled,\n\t\t\t\t);\n\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onMultiSelectClear() {\n\t\tconst newOptions = iterateOnOptions(dropdownOptions, { selected: false });\n\t\tsetDropdownOptions([...newOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(newOptions);\n\t\t}\n\t}\n\n\tfunction onFreeFormSelect(selected: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonApplyHandler({\n\t\t\t\tlabel: searchedString,\n\t\t\t\tvalue: searchedString,\n\t\t\t\tisFreeForm: true,\n\t\t\t\tselected: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst updatedList = dropdownOptions.map((option) =>\n\t\t\t(option as GroupedOption).options\n\t\t\t\t? option\n\t\t\t\t: {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected:\n\t\t\t\t\t\t\t/** free form check */\n\t\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t\t(option as SingleOption).value === searchedString\n\t\t\t\t\t\t\t\t? /** to mark as selected or not */\n\t\t\t\t\t\t\t\t selected\n\t\t\t\t\t\t\t\t: (option as SingleOption).selected,\n\t\t\t\t },\n\t\t);\n\n\t\tif (selected) {\n\t\t\tif (\n\t\t\t\t!updatedList.some(\n\t\t\t\t\t(option) =>\n\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t(option as SingleOption).value === searchedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tupdatedList.unshift({\n\t\t\t\t\tlabel: searchedString,\n\t\t\t\t\tvalue: searchedString,\n\t\t\t\t\tisFreeForm: true,\n\t\t\t\t\tselected: true,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tsetDropdownOptions([...updatedList]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(updatedList);\n\t\t}\n\t}\n\n\t/**\n\t * This is called when appy button is called,\n\t * here iterate and pick all options where selected if true.\n\t */\n\tfunction onMultiSelectApply(options?: DropdownOption[]) {\n\t\tconst optionsToSend: DropdownOption[] = getSelectedOptions(\n\t\t\toptions ?? latestDropdownOptionsRef.current,\n\t\t);\n\n\t\tonSelect?.([...optionsToSend]);\n\t}\n\n\treturn {\n\t\tlatestDropdownOptionsRef,\n\t\tdropdownOptions,\n\t\tsearch,\n\t\tsearchedString,\n\t\tsearchedOptions,\n\t\tsearchError,\n\t\tretrySearch,\n\t\tonApplyHandler,\n\t\tselectAllHandler,\n\t\tonMultiSelectClear,\n\t\tonFreeFormSelect,\n\t\tonMultiSelectApply,\n\t\tgetSelectedOptions,\n\t\tgetCurrentSelectionCount,\n\t\tisMaxSelectionsReached,\n\t\tmaxSelections,\n\t};\n};\n"],"names":["useDropdown","version","options","onSelect","skipSorting","isMultiSelect","onSearch","disableOtherSearchedOption","disableSearchedOptionExcept","maxSelections","dropdownOptions","setDropdownOptions","useState","searchedOptions","setSearchedOptions","searchedString","setSearchedString","searchError","setSearchError","latestDropdownOptionsRef","useRef","onSearchRef","useEffect","searchedOptionsClone","dropdownOptionFlat","option","op","selectedDropdownOption","dropdownOption","writeOptions","getSelectedOptions","data","selectedOptions","groupedOptions","getCurrentSelectionCount","count","isMaxSelectionsReached","performSearch","useCallback","searchKey","onSearchFn","selectedIds","iterateOnOptionsRaw","response","updatedResponseData","groupedOption","error","debouncedSearch","useMemo","debounce","search","retrySearch","onApplyHandler","optionSelect","returnOnly","alreadyPresentInInitialOptions","currList","iterateOnOptions","optionForValidation","onMultiSelectApply","selectAllForSearch","select","clonedDropdownOptions","dOption","singleOption","selectAllForSearchWithLimit","currentCount","remainingSlots","selectedCount","found","selectAllHandler","newState","newOptions","onMultiSelectClear","onFreeFormSelect","selected","updatedList","optionsToSend"],"mappings":"gQASaA,EAAc,CAC1BC,EAAU,MACVC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAwC,CAAA,EACxCC,IACI,CACJ,KAAM,CAACC,EAAiBC,CAAkB,EAAIC,EAAAA,SAASV,GAAW,CAAA,CAAE,EAC9D,CAACW,EAAiBC,CAAkB,EAAIF,EAAAA,SAA2B,CAAA,CAAE,EACrE,CAACG,EAAgBC,CAAiB,EAAIJ,EAAAA,SAAS,EAAE,EACjD,CAACK,EAAaC,CAAc,EAAIN,EAAAA,SAA6B,MAAS,EACtEO,EAA2BC,EAAAA,OAAOV,CAAe,EAEjDW,EAAcD,EAAAA,OAAOd,CAAQ,EAEnCgB,EAAAA,UAAU,IAAM,CACfD,EAAY,QAAUf,CACvB,EAAG,CAACA,CAAQ,CAAC,EAEbgB,EAAAA,UAAU,IAAM,CAGf,GAFAH,EAAyB,QAAUT,EAE/BG,EAAgB,QAAUE,GAAkBT,EAAU,CACzD,IAA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WiB,EAAyB,OAAA,EAGrChB,IAAW,CAAC,GAAG0E,CAAa,CAAC,CAC9B,CAEA,MAAO,CACN,yBAAA1D,EACA,gBAAAT,EACA,OAAAwC,EACA,eAAAnC,EACA,gBAAAF,EACA,YAAAI,EACA,YAAAkC,EACA,eAAAC,EACA,iBAAAkB,EACA,mBAAAG,EACA,iBAAAC,EACA,mBAAAf,EACA,mBAAA7B,EACA,yBAAAI,EACA,uBAAAE,EACA,cAAA3B,CAAA,CAEF"}
1
+ {"version":3,"file":"useDropdown.js","sources":["../../../../../src/components/dropdown/hooks/useDropdown.tsx"],"sourcesContent":["import debounce from 'lodash/debounce';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { SelectAllCheckboxState } from '../OpenedDropdown/components/menu/SelectAllMenu';\nimport {\n\tgetSelectionLeaves,\n\titerateOnOptions,\n\titerateOnOptionsRaw,\n} from '../OpenedDropdown/utils/iterationOnOptions';\nimport { DropdownOption, GroupedOption, SingleOption } from '../type';\n\nexport const useDropdown = (\n\tversion = '1.0',\n\toptions: DropdownOption[],\n\tonSelect: ((option: DropdownOption | DropdownOption[]) => void) | undefined,\n\tskipSorting?: boolean,\n\tisMultiSelect?: boolean,\n\tonSearch?: (searchKey: string) => Promise<DropdownOption[]>,\n\tdisableOtherSearchedOption?: boolean,\n\tdisableSearchedOptionExcept: string[] = [],\n\tmaxSelections?: number,\n\tchildrenLayout?: 'flyout' | 'nested',\n) => {\n\t// Only the nested layout makes children selectable; a flyout submenu click\n\t// marks the parent instead.\n\tconst nestedChildren = childrenLayout === 'nested';\n\tconst [dropdownOptions, setDropdownOptions] = useState(options ?? []);\n\tconst [searchedOptions, setSearchedOptions] = useState<DropdownOption[]>([]);\n\tconst [searchedString, setSearchedString] = useState('');\n\tconst [searchError, setSearchError] = useState<string | undefined>(undefined);\n\tconst latestDropdownOptionsRef = useRef(dropdownOptions);\n\t/** Store latest onSearch so performSearch/debouncedSearch stay stable when parent re-renders with new callback reference. */\n\tconst onSearchRef = useRef(onSearch);\n\n\tuseEffect(() => {\n\t\tonSearchRef.current = onSearch;\n\t}, [onSearch]);\n\n\tuseEffect(() => {\n\t\tlatestDropdownOptionsRef.current = dropdownOptions;\n\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tlet searchedOptionsClone = [...searchedOptions] as SingleOption[];\n\t\t\tconst dropdownOptionFlat = dropdownOptions\n\t\t\t\t.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\treturn (option as GroupedOption).options.map((op) => ({\n\t\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tconst op = option as SingleOption;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t\t.flat();\n\n\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\tconst selectedDropdownOption = dropdownOptionFlat.find(\n\t\t\t\t\t(dropdownOption) => {\n\t\t\t\t\t\tif (option.value === dropdownOption.value) {\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (selectedDropdownOption) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedDropdownOption.selected,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn option;\n\t\t\t});\n\n\t\t\t// disable other options except selected in searched options\n\t\t\tif (disableOtherSearchedOption) {\n\t\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tdisabled: !disableSearchedOptionExcept.includes(option.value),\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetSearchedOptions([\n\t\t\t\t\t...searchedOptionsClone.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([...searchedOptionsClone]);\n\t\t\t}\n\t\t}\n\t}, [dropdownOptions]);\n\n\tuseEffect(() => {\n\t\tif (options) {\n\t\t\tconst writeOptions = [...options];\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetDropdownOptions([\n\t\t\t\t\t...writeOptions.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetDropdownOptions([...writeOptions]);\n\t\t\t}\n\t\t}\n\t}, [options]);\n\n\tconst getSelectedOptions = (data: DropdownOption[]) => {\n\t\tconst selectedOptions: DropdownOption[] = [];\n\t\tdata.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\tconst groupedOptions = (option as GroupedOption).options.filter(\n\t\t\t\t\t(op) => op.selected === true,\n\t\t\t\t);\n\t\t\t\tselectedOptions.push({\n\t\t\t\t\t...option,\n\t\t\t\t\toptions: [...groupedOptions],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\tif (nestedChildren && singleOption.children?.length) {\n\t\t\t\t\t// A partly selected parent is itself unselected, so report it\n\t\t\t\t\t// whenever any child is selected, carrying only those children.\n\t\t\t\t\tconst selectedChildren = singleOption.children.filter(\n\t\t\t\t\t\t(child) => child.selected,\n\t\t\t\t\t);\n\t\t\t\t\tif (selectedChildren.length) {\n\t\t\t\t\t\tselectedOptions.push({\n\t\t\t\t\t\t\t...singleOption,\n\t\t\t\t\t\t\tchildren: selectedChildren,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (singleOption.selected) {\n\t\t\t\t\tselectedOptions.push({ ...option });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn selectedOptions;\n\t};\n\n\t// Count current selections for max selection limit\n\tconst getCurrentSelectionCount = (data: DropdownOption[]) =>\n\t\tgetSelectionLeaves(data, nestedChildren).filter((leaf) => leaf.selected)\n\t\t\t.length;\n\n\t// Check if max selections limit is reached\n\tconst isMaxSelectionsReached = (data: DropdownOption[]) => {\n\t\tif (!isMultiSelect || (!maxSelections && maxSelections !== 0)) return false;\n\t\treturn getCurrentSelectionCount(data) >= maxSelections;\n\t};\n\n\t/** Reads onSearch from ref so it stays stable ([] deps). No-ops when onSearchRef.current is undefined. */\n\tconst performSearch = useCallback(async (searchKey: string) => {\n\t\tconst onSearchFn = onSearchRef.current;\n\t\tif (!searchKey || !onSearchFn) return;\n\n\t\tconst selectedIds: (string | number)[] = [];\n\t\titerateOnOptionsRaw(latestDropdownOptionsRef.current, (option) => {\n\t\t\tif (option.selected && !selectedIds.includes(option.value)) {\n\t\t\t\tselectedIds.push(option.value);\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tconst response = await onSearchFn(searchKey);\n\t\t\tsetSearchError(undefined);\n\t\t\tif (response) {\n\t\t\t\tconst updatedResponseData = response.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => ({\n\t\t\t\t\t\t\t\t...op,\n\t\t\t\t\t\t\t\tselected: selectedIds.includes(op.value),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedIds.includes((option as SingleOption).value),\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tsetSearchedOptions([...updatedResponseData]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tsetSearchedOptions([]);\n\t\t\tsetSearchError(\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: 'Something went wrong while fetching the list. Please try again',\n\t\t\t);\n\t\t}\n\t}, []);\n\n\t/** Independent of onSearch so debounce is stable when callers pass inline functions. Pending searches are preserved across parent re-renders. performSearch no-ops when onSearchRef.current is undefined. */\n\tconst debouncedSearch = useMemo(\n\t\t() => debounce(performSearch, 300),\n\t\t[performSearch],\n\t);\n\n\tuseEffect(() => () => debouncedSearch?.cancel(), [debouncedSearch]);\n\n\tfunction search(searchKey: string) {\n\t\tsetSearchedString(searchKey);\n\t\tsetSearchedOptions([]);\n\t\tsetSearchError(undefined);\n\n\t\tif (!searchKey) {\n\t\t\tdebouncedSearch?.cancel();\n\t\t\treturn;\n\t\t}\n\n\t\tdebouncedSearch(searchKey);\n\t}\n\n\tfunction retrySearch() {\n\t\tif (searchedString) {\n\t\t\tsetSearchError(undefined);\n\t\t\tperformSearch(searchedString);\n\t\t}\n\t}\n\n\t/**\n\t * wrapper to prepare option for onSelect\n\t * for single select, this will call the onClose handler ,\n\t * for multiselect, it will do state update for options list\n\t * \t\tto make any option select,\n\t * \t\t\t\tonApplyHandler({ label, value: selected: true })\n\t * to deselect any option\n\t * \t\t\t\tonApplyHandler({ label, value: selected: false })\n\t * @param optionSelect\n\t */\n\tfunction onApplyHandler(optionSelect: SingleOption, returnOnly?: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonSelect?.(optionSelect);\n\t\t} else {\n\t\t\t// Check if trying to select and max selections is reached\n\t\t\tif (\n\t\t\t\toptionSelect.selected &&\n\t\t\t\tmaxSelections &&\n\t\t\t\tisMaxSelectionsReached(dropdownOptions)\n\t\t\t) {\n\t\t\t\t// Max selections reached, don't allow new selections\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\t\t/** Search mode */\n\t\t\t\t/**\n\t\t\t\t * on selected, push it to dropdown options,\n\t\t\t\t * on un-select, remove from dropdown option\n\t\t\t\t */\n\n\t\t\t\tif (optionSelect.selected) {\n\t\t\t\t\t// Check max selections for search mode too\n\t\t\t\t\tif (maxSelections && isMaxSelectionsReached(dropdownOptions)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t/** check if already there or not,\n\t\t\t\t\t * if yes, just update\n\t\t\t\t\t * else ,\n\t\t\t\t\t * \tappend\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tnestedChildren,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList.push(optionSelect);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t/** un-select,\n\t\t\t\t\t * if already present in initial data,\n\t\t\t\t\t * yes, just update\n\t\t\t\t\t * else,\n\t\t\t\t\t * \tremove\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tlet currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tnestedChildren,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList = currList.filter((option) => {\n\t\t\t\t\t\t\tif ((option as SingleOption).value === optionSelect.value) {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t(optionForValidation: SingleOption) =>\n\t\t\t\t\t\toptionForValidation.value === optionSelect.value,\n\t\t\t\t\tnestedChildren,\n\t\t\t\t);\n\n\t\t\t\tif (returnOnly) {\n\t\t\t\t\treturn [...currList];\n\t\t\t\t}\n\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllForSearch(select: boolean) {\n\t\t// const allSearchedValues = searchedOptions.map(option => option.value);\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select) {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found) {\n\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t}\n\t}\n\n\tfunction selectAllForSearchWithLimit(select: boolean) {\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select && maxSelections && maxSelections > 0) {\n\t\t\tconst currentCount = getCurrentSelectionCount(clonedDropdownOptions);\n\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t// Already at max, don't select any more\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet selectedCount = 0;\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tif (selectedCount >= remainingSlots) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t// Skip if already selected\n\t\t\t\t\tif ((dOption as SingleOption).selected) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\t\t\t\t\t// Skip if disabled\n\t\t\t\t\tif ((dOption as SingleOption).disabled) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found && selectedCount < remainingSlots) {\n\t\t\t\t\tconst newOption = option as SingleOption;\n\t\t\t\t\tif (!newOption.disabled) {\n\t\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\t\tif (version === '2.0') {\n\t\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllHandler(newState: SelectAllCheckboxState) {\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tselectAllForSearchWithLimit(true);\n\t\t\t} else {\n\t\t\t\tselectAllForSearch(false);\n\t\t\t}\n\t\t} else {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tif (maxSelections && maxSelections > 0) {\n\t\t\t\t\t// Only select up to maxSelections limit\n\t\t\t\t\tconst currentCount = getCurrentSelectionCount(dropdownOptions);\n\t\t\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t\t\t// Already at max, don't select any more\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet selectedCount = 0;\n\t\t\t\t\tconst newOptions = dropdownOptions.map((option) => {\n\t\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\t\t// Handle grouped options\n\t\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => {\n\t\t\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\t\t\tif (op.disabled) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\t\t\tif (op.selected) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t\t\t!op.label\n\t\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\t\t\treturn { ...op, selected: true };\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\tif (singleOption.disabled) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\tif (singleOption.selected) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t!singleOption.label\n\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\treturn { ...option, selected: true };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// No max selection limit, select all\n\t\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: true },\n\t\t\t\t\t\t(option) =>\n\t\t\t\t\t\t\tsearchedString\n\t\t\t\t\t\t\t\t? option.label\n\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase()) && !option.disabled\n\t\t\t\t\t\t\t\t: !option.disabled,\n\t\t\t\t\t\tnestedChildren,\n\t\t\t\t\t);\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (newState === 'notSelected') {\n\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: false },\n\t\t\t\t\t(option) => !option.disabled,\n\t\t\t\t\tnestedChildren,\n\t\t\t\t);\n\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onMultiSelectClear() {\n\t\tconst newOptions = iterateOnOptions(\n\t\t\tdropdownOptions,\n\t\t\t{ selected: false },\n\t\t\tundefined,\n\t\t\tnestedChildren,\n\t\t);\n\t\tsetDropdownOptions([...newOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(newOptions);\n\t\t}\n\t}\n\n\tfunction onFreeFormSelect(selected: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonApplyHandler({\n\t\t\t\tlabel: searchedString,\n\t\t\t\tvalue: searchedString,\n\t\t\t\tisFreeForm: true,\n\t\t\t\tselected: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst updatedList = dropdownOptions.map((option) =>\n\t\t\t(option as GroupedOption).options\n\t\t\t\t? option\n\t\t\t\t: {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected:\n\t\t\t\t\t\t\t/** free form check */\n\t\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t\t(option as SingleOption).value === searchedString\n\t\t\t\t\t\t\t\t? /** to mark as selected or not */\n\t\t\t\t\t\t\t\t selected\n\t\t\t\t\t\t\t\t: (option as SingleOption).selected,\n\t\t\t\t },\n\t\t);\n\n\t\tif (selected) {\n\t\t\tif (\n\t\t\t\t!updatedList.some(\n\t\t\t\t\t(option) =>\n\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t(option as SingleOption).value === searchedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tupdatedList.unshift({\n\t\t\t\t\tlabel: searchedString,\n\t\t\t\t\tvalue: searchedString,\n\t\t\t\t\tisFreeForm: true,\n\t\t\t\t\tselected: true,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tsetDropdownOptions([...updatedList]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(updatedList);\n\t\t}\n\t}\n\n\t/**\n\t * This is called when appy button is called,\n\t * here iterate and pick all options where selected if true.\n\t */\n\tfunction onMultiSelectApply(options?: DropdownOption[]) {\n\t\tconst optionsToSend: DropdownOption[] = getSelectedOptions(\n\t\t\toptions ?? latestDropdownOptionsRef.current,\n\t\t);\n\n\t\tonSelect?.([...optionsToSend]);\n\t}\n\n\treturn {\n\t\tlatestDropdownOptionsRef,\n\t\tdropdownOptions,\n\t\tsearch,\n\t\tsearchedString,\n\t\tsearchedOptions,\n\t\tsearchError,\n\t\tretrySearch,\n\t\tonApplyHandler,\n\t\tselectAllHandler,\n\t\tonMultiSelectClear,\n\t\tonFreeFormSelect,\n\t\tonMultiSelectApply,\n\t\tgetSelectedOptions,\n\t\tgetCurrentSelectionCount,\n\t\tisMaxSelectionsReached,\n\t\tmaxSelections,\n\t};\n};\n"],"names":["useDropdown","version","options","onSelect","skipSorting","isMultiSelect","onSearch","disableOtherSearchedOption","disableSearchedOptionExcept","maxSelections","childrenLayout","nestedChildren","dropdownOptions","setDropdownOptions","useState","searchedOptions","setSearchedOptions","searchedString","setSearchedString","searchError","setSearchError","latestDropdownOptionsRef","useRef","onSearchRef","useEffect","searchedOptionsClone","dropdownOptionFlat","option","op","selectedDropdownOption","dropdownOption","writeOptions","getSelectedOptions","data","selectedOptions","groupedOptions","singleOption","selectedChildren","child","getCurrentSelectionCount","getSelectionLeaves","leaf","isMaxSelectionsReached","performSearch","useCallback","searchKey","onSearchFn","selectedIds","iterateOnOptionsRaw","response","updatedResponseData","groupedOption","error","debouncedSearch","useMemo","debounce","search","retrySearch","onApplyHandler","optionSelect","returnOnly","alreadyPresentInInitialOptions","currList","iterateOnOptions","optionForValidation","onMultiSelectApply","selectAllForSearch","select","clonedDropdownOptions","dOption","selectAllForSearchWithLimit","currentCount","remainingSlots","selectedCount","found","selectAllHandler","newState","newOptions","onMultiSelectClear","onFreeFormSelect","selected","updatedList","optionsToSend"],"mappings":"gQAUaA,EAAc,CAC1BC,EAAU,MACVC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAwC,CAAA,EACxCC,EACAC,IACI,CAGJ,MAAMC,EAAiBD,IAAmB,SACpC,CAACE,EAAiBC,CAAkB,EAAIC,EAAAA,SAASZ,GAAW,CAAA,CAAE,EAC9D,CAACa,EAAiBC,CAAkB,EAAIF,EAAAA,SAA2B,CAAA,CAAE,EACrE,CAACG,EAAgBC,CAAiB,EAAIJ,EAAAA,SAAS,EAAE,EACjD,CAACK,EAAaC,CAAc,EAAIN,EAAAA,SAA6B,MAAS,EACtEO,EAA2BC,EAAAA,OAAOV,CAAe,EAEjDW,EAAcD,EAAAA,OAAOhB,CAAQ,EAEnCkB,EAAAA,UAAU,IAAM,CACfD,EAAY,QAAUjB,CACvB,EAAG,CAACA,CAAQ,CAAC,EAEbkB,EAAAA,UAAU,IAAM,CAGf,GAFAH,EAAyB,QAAUT,EAE/BG,EAAgB,QAAUE,GAAkBX,EAAU,CACzD,IAAImB,EAAuB,CAAC,GAAGV,CAAe,EAC9C,MAAMW,EAAqBd,EACzB,IAAKe,GAAW,CAChB,GAAKA,EAAyB,QAC7B,OAAQA,EAAyB,QAAQ,IAAKC,IAAQ,CACrD,MAAOA,EAAG,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