@flipdish/ui-library 0.66.2 → 0.67.1

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 (97) hide show
  1. package/README.md +31 -31
  2. package/dist/components/__internal__/listOption/listOption.styles.cjs +1 -1
  3. package/dist/components/__internal__/listOption/listOption.styles.cjs.map +1 -1
  4. package/dist/components/__internal__/listOption/listOption.styles.js +1 -1
  5. package/dist/components/__internal__/listOption/listOption.styles.js.map +1 -1
  6. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs +13 -30
  7. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs.map +1 -1
  8. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts.map +1 -1
  9. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js +10 -27
  10. package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js.map +1 -1
  11. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs +55 -0
  12. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs.map +1 -0
  13. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts +56 -0
  14. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts.map +1 -0
  15. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js +52 -0
  16. package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js.map +1 -0
  17. package/dist/components/forms/fields/FormMultiSelect/index.cjs +8 -23
  18. package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -1
  19. package/dist/components/forms/fields/FormMultiSelect/index.d.ts +4 -4
  20. package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -1
  21. package/dist/components/forms/fields/FormMultiSelect/index.js +8 -23
  22. package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -1
  23. package/dist/components/molecules/Dropdown/index.cjs +3 -1
  24. package/dist/components/molecules/Dropdown/index.cjs.map +1 -1
  25. package/dist/components/molecules/Dropdown/index.d.ts.map +1 -1
  26. package/dist/components/molecules/Dropdown/index.js +3 -1
  27. package/dist/components/molecules/Dropdown/index.js.map +1 -1
  28. package/dist/components/molecules/Select/index.d.ts +1 -6
  29. package/dist/components/molecules/Select/index.d.ts.map +1 -1
  30. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.cjs +76 -41
  31. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.cjs.map +1 -1
  32. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.d.ts +15 -38
  33. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.d.ts.map +1 -1
  34. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.js +79 -44
  35. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.js.map +1 -1
  36. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.cjs +18 -0
  37. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.cjs.map +1 -0
  38. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.d.ts +15 -0
  39. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.d.ts.map +1 -0
  40. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.js +15 -0
  41. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.js.map +1 -0
  42. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.cjs +74 -0
  43. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.cjs.map +1 -0
  44. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.d.ts +23 -0
  45. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.d.ts.map +1 -0
  46. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.js +72 -0
  47. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.js.map +1 -0
  48. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.cjs +85 -0
  49. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.cjs.map +1 -0
  50. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.d.ts +35 -0
  51. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.d.ts.map +1 -0
  52. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.js +83 -0
  53. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.js.map +1 -0
  54. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.cjs +43 -0
  55. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.cjs.map +1 -0
  56. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.d.ts +14 -0
  57. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.d.ts.map +1 -0
  58. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.js +41 -0
  59. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.js.map +1 -0
  60. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.cjs +114 -22
  61. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.cjs.map +1 -1
  62. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.d.ts +79 -12
  63. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.d.ts.map +1 -1
  64. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.js +108 -21
  65. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.js.map +1 -1
  66. package/dist/components/molecules/Selects/Select/Select.cjs +1 -3
  67. package/dist/components/molecules/Selects/Select/Select.cjs.map +1 -1
  68. package/dist/components/molecules/Selects/Select/Select.d.ts +0 -2
  69. package/dist/components/molecules/Selects/Select/Select.d.ts.map +1 -1
  70. package/dist/components/molecules/Selects/Select/Select.js +1 -3
  71. package/dist/components/molecules/Selects/Select/Select.js.map +1 -1
  72. package/dist/components/molecules/Selects/Selects.styles.cjs +3 -4
  73. package/dist/components/molecules/Selects/Selects.styles.cjs.map +1 -1
  74. package/dist/components/molecules/Selects/Selects.styles.d.ts +1 -4
  75. package/dist/components/molecules/Selects/Selects.styles.d.ts.map +1 -1
  76. package/dist/components/molecules/Selects/Selects.styles.js +3 -4
  77. package/dist/components/molecules/Selects/Selects.styles.js.map +1 -1
  78. package/dist/components/molecules/Selects/index.d.ts +1 -2
  79. package/dist/components/molecules/Selects/index.d.ts.map +1 -1
  80. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.cjs +1 -1
  81. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.cjs.map +1 -1
  82. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.js +1 -1
  83. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.js.map +1 -1
  84. package/dist/styles.css +26 -0
  85. package/package.json +1 -1
  86. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.cjs +0 -43
  87. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.cjs.map +0 -1
  88. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.d.ts +0 -35
  89. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.d.ts.map +0 -1
  90. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.js +0 -41
  91. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.js.map +0 -1
  92. package/dist/components/molecules/Selects/Select/components/Combobox.cjs +0 -60
  93. package/dist/components/molecules/Selects/Select/components/Combobox.cjs.map +0 -1
  94. package/dist/components/molecules/Selects/Select/components/Combobox.d.ts +0 -16
  95. package/dist/components/molecules/Selects/Select/components/Combobox.d.ts.map +0 -1
  96. package/dist/components/molecules/Selects/Select/components/Combobox.js +0 -58
  97. package/dist/components/molecules/Selects/Select/components/Combobox.js.map +0 -1
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var multiSelect_utils = require('../utilities/multiSelect.utils.cjs');
5
+
6
+ /**
7
+ * Keeps a MultiSelect's two selections apart: the applied one the trigger shows, and the draft the open menu edits.
8
+ * Ticks, Clear all and Select all change only the draft; Apply commits it, and closing any other way drops it.
9
+ *
10
+ * @param options The selection props, the footer callbacks and the list of options.
11
+ * @returns The applied and draft keys, whether the menu is open, and the handlers for the menu, footer and pills.
12
+ */
13
+ const useMultiSelectSelection = ({ selectedKeys, defaultSelectedKeys, onSelectionChange, onClearAll, onSelectAll, options, }) => {
14
+ const isControlled = selectedKeys !== undefined;
15
+ // Read once per value, never on each render: an iterable such as a generator is empty the second time.
16
+ const controlledKeys = React.useMemo(() => multiSelect_utils.snapshotSelection(selectedKeys), [selectedKeys]);
17
+ const [internalKeys, setInternalKeys] = React.useState(() => multiSelect_utils.snapshotSelection(defaultSelectedKeys) ?? new Set());
18
+ const appliedKeys = multiSelect_utils.resolveSelectedKeys(isControlled ? controlledKeys : internalKeys, options);
19
+ const [isOpen, setIsOpen] = React.useState(false);
20
+ // What the user changed in the open menu, kept as a difference from the applied selection and not as a copy of it.
21
+ // `null` until a tick changes: an untouched menu mirrors the applied selection, so Apply has nothing stale to send, and
22
+ // an edited one is rebased onto whatever the parent sets while it is open instead of undoing that update.
23
+ const [edits, setEdits] = React.useState(null);
24
+ const draftKeys = isOpen && edits ? new Set([...appliedKeys].filter((key) => !edits.removed.has(key)).concat([...edits.added])) : appliedKeys;
25
+ const commit = (keys) => {
26
+ if (multiSelect_utils.areKeySetsEqual(keys, appliedKeys))
27
+ return;
28
+ if (!isControlled)
29
+ setInternalKeys(keys);
30
+ onSelectionChange?.(keys);
31
+ };
32
+ const setOpen = (nextOpen) => {
33
+ setIsOpen(nextOpen);
34
+ setEdits(null);
35
+ };
36
+ // Records only what this change ticked or unticked, on top of the earlier edits. Working the edits out afresh from the
37
+ // applied selection would forget an untick whose option the parent has since dropped, and bring it back ticked later.
38
+ const setDraft = (keys) => {
39
+ if (!isOpen)
40
+ return;
41
+ const added = new Set(edits?.added);
42
+ const removed = new Set(edits?.removed);
43
+ for (const key of keys) {
44
+ if (draftKeys.has(key))
45
+ continue;
46
+ added.add(key);
47
+ removed.delete(key);
48
+ }
49
+ for (const key of draftKeys) {
50
+ if (keys.has(key))
51
+ continue;
52
+ removed.add(key);
53
+ added.delete(key);
54
+ }
55
+ setEdits({ added, removed });
56
+ };
57
+ // The list's own select-all reports `'all'`; like the footer's, it must not untick a disabled option that is ticked.
58
+ const changeDraft = (selection) => setDraft(selection === 'all' ? multiSelect_utils.selectAllKeys(draftKeys, options) : new Set(multiSelect_utils.resolveSelectedKeys(selection, options)));
59
+ const clearAll = () => {
60
+ setDraft(multiSelect_utils.clearAllKeys(draftKeys, options));
61
+ onClearAll?.();
62
+ };
63
+ const selectAll = () => {
64
+ setDraft(multiSelect_utils.selectAllKeys(draftKeys, options));
65
+ onSelectAll?.();
66
+ };
67
+ const apply = () => {
68
+ if (edits)
69
+ commit(draftKeys);
70
+ setOpen(false);
71
+ };
72
+ // A pill sits on the trigger, outside the menu, so removing one commits at once; an open menu must not tick it back.
73
+ const removeKeys = (keys) => {
74
+ const removed = new Set(keys);
75
+ commit(new Set([...appliedKeys].filter((key) => !removed.has(key))));
76
+ if (isOpen && edits)
77
+ setEdits({ added: new Set([...edits.added].filter((key) => !removed.has(key))), removed: edits.removed });
78
+ };
79
+ // Clear all has nothing to do when the only ticked options are ones the user cannot untick.
80
+ const canClearAll = multiSelect_utils.clearAllKeys(draftKeys, options).size < draftKeys.size;
81
+ return { appliedKeys, draftKeys, isOpen, canClearAll, setOpen, changeDraft, clearAll, selectAll, apply, removeKeys };
82
+ };
83
+
84
+ exports.useMultiSelectSelection = useMultiSelectSelection;
85
+ //# sourceMappingURL=useMultiSelectSelection.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMultiSelectSelection.cjs","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.ts"],"sourcesContent":[null],"names":["useMemo","snapshotSelection","useState","resolveSel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a,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC3C,WAAW,IAAI;AACjB,IAAA,CAAC;IAED,MAAM,KAAK,GAAG,MAAK;AACjB,QAAA,IAAI,KAAK;YAAE,MAAM,CAAC,SAAS,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC;AAChB,IAAA,CAAC;;AAGD,IAAA,MAAM,UAAU,GAAG,CAAC,IAA8B,KAAI;AACpD,QAAA,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC;QAC7B,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,MAAM,IAAI,KAAK;AAAE,YAAA,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;AAChI,IAAA,CAAC;;AAGD,IAAA,MAAM,WAAW,GAAGC,8BAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI;IAE1E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE;AACtH;;"}
@@ -0,0 +1,35 @@
1
+ import { type MultiSelectKey, type MultiSelectOption, type MultiSelectSelection } from '../utilities/multiSelect.utils';
2
+ export interface UseMultiSelectSelectionOptions {
3
+ /** Controlled selection. When omitted, the hook tracks the applied selection itself. */
4
+ selectedKeys?: MultiSelectSelection;
5
+ /** Initial selection used only while uncontrolled. */
6
+ defaultSelectedKeys?: MultiSelectSelection;
7
+ /** Called with the applied keys when Apply or a pill's remove button changes them. */
8
+ onSelectionChange?: (keys: Set<MultiSelectKey>) => void;
9
+ /** Called when Clear all is pressed, after the draft is cleared. */
10
+ onClearAll?: () => void;
11
+ /** Called when Select all is pressed, after the draft is filled. */
12
+ onSelectAll?: () => void;
13
+ /** Every option, in menu order; expands `'all'` and tells the bulk actions which options are disabled. */
14
+ options: readonly MultiSelectOption[];
15
+ }
16
+ /**
17
+ * Keeps a MultiSelect's two selections apart: the applied one the trigger shows, and the draft the open menu edits.
18
+ * Ticks, Clear all and Select all change only the draft; Apply commits it, and closing any other way drops it.
19
+ *
20
+ * @param options The selection props, the footer callbacks and the list of options.
21
+ * @returns The applied and draft keys, whether the menu is open, and the handlers for the menu, footer and pills.
22
+ */
23
+ export declare const useMultiSelectSelection: ({ selectedKeys, defaultSelectedKeys, onSelectionChange, onClearAll, onSelectAll, options, }: UseMultiSelectSelectionOptions) => {
24
+ appliedKeys: Set<MultiSelectKey>;
25
+ draftKeys: Set<MultiSelectKey>;
26
+ isOpen: boolean;
27
+ canClearAll: boolean;
28
+ setOpen: (nextOpen: boolean) => void;
29
+ changeDraft: (selection: MultiSelectSelection) => void;
30
+ clearAll: () => void;
31
+ selectAll: () => void;
32
+ apply: () => void;
33
+ removeKeys: (keys: Iterable<MultiSelectKey>) => void;
34
+ };
35
+ //# sourceMappingURL=useMultiSelectSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMultiSelectSelection.d.ts","sourceRoot":"","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAI1B,MAAM,gCAAgC,CAAC;AAExC,MAAM,WAAW,8BAA8B;IAC7C,wFAAwF;IACxF,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,sDAAsD;IACtD,mBAAmB,CAAC,EAAE,oBAAoB,CAAC;IAC3C,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IACxD,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,0GAA0G;IAC1G,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACvC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,6FAOrC,8BAA8B;;;;;wBAoBJ,OAAO;6BAyBF,oBAAoB;;;;uBAmB1B,QAAQ,CAAC,cAAc,CAAC;CAUnD,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { snapshotSelection, resolveSelectedKeys, clearAllKeys, selectAllKeys, areKeySetsEqual } from '../utilities/multiSelect.utils.js';
3
+
4
+ /**
5
+ * Keeps a MultiSelect's two selections apart: the applied one the trigger shows, and the draft the open menu edits.
6
+ * Ticks, Clear all and Select all change only the draft; Apply commits it, and closing any other way drops it.
7
+ *
8
+ * @param options The selection props, the footer callbacks and the list of options.
9
+ * @returns The applied and draft keys, whether the menu is open, and the handlers for the menu, footer and pills.
10
+ */
11
+ const useMultiSelectSelection = ({ selectedKeys, defaultSelectedKeys, onSelectionChange, onClearAll, onSelectAll, options, }) => {
12
+ const isControlled = selectedKeys !== undefined;
13
+ // Read once per value, never on each render: an iterable such as a generator is empty the second time.
14
+ const controlledKeys = useMemo(() => snapshotSelection(selectedKeys), [selectedKeys]);
15
+ const [internalKeys, setInternalKeys] = useState(() => snapshotSelection(defaultSelectedKeys) ?? new Set());
16
+ const appliedKeys = resolveSelectedKeys(isControlled ? controlledKeys : internalKeys, options);
17
+ const [isOpen, setIsOpen] = useState(false);
18
+ // What the user changed in the open menu, kept as a difference from the applied selection and not as a copy of it.
19
+ // `null` until a tick changes: an untouched menu mirrors the applied selection, so Apply has nothing stale to send, and
20
+ // an edited one is rebased onto whatever the parent sets while it is open instead of undoing that update.
21
+ const [edits, setEdits] = useState(null);
22
+ const draftKeys = isOpen && edits ? new Set([...appliedKeys].filter((key) => !edits.removed.has(key)).concat([...edits.added])) : appliedKeys;
23
+ const commit = (keys) => {
24
+ if (areKeySetsEqual(keys, appliedKeys))
25
+ return;
26
+ if (!isControlled)
27
+ setInternalKeys(keys);
28
+ onSelectionChange?.(keys);
29
+ };
30
+ const setOpen = (nextOpen) => {
31
+ setIsOpen(nextOpen);
32
+ setEdits(null);
33
+ };
34
+ // Records only what this change ticked or unticked, on top of the earlier edits. Working the edits out afresh from the
35
+ // applied selection would forget an untick whose option the parent has since dropped, and bring it back ticked later.
36
+ const setDraft = (keys) => {
37
+ if (!isOpen)
38
+ return;
39
+ const added = new Set(edits?.added);
40
+ const removed = new Set(edits?.removed);
41
+ for (const key of keys) {
42
+ if (draftKeys.has(key))
43
+ continue;
44
+ added.add(key);
45
+ removed.delete(key);
46
+ }
47
+ for (const key of draftKeys) {
48
+ if (keys.has(key))
49
+ continue;
50
+ removed.add(key);
51
+ added.delete(key);
52
+ }
53
+ setEdits({ added, removed });
54
+ };
55
+ // The list's own select-all reports `'all'`; like the footer's, it must not untick a disabled option that is ticked.
56
+ const changeDraft = (selection) => setDraft(selection === 'all' ? selectAllKeys(draftKeys, options) : new Set(resolveSelectedKeys(selection, options)));
57
+ const clearAll = () => {
58
+ setDraft(clearAllKeys(draftKeys, options));
59
+ onClearAll?.();
60
+ };
61
+ const selectAll = () => {
62
+ setDraft(selectAllKeys(draftKeys, options));
63
+ onSelectAll?.();
64
+ };
65
+ const apply = () => {
66
+ if (edits)
67
+ commit(draftKeys);
68
+ setOpen(false);
69
+ };
70
+ // A pill sits on the trigger, outside the menu, so removing one commits at once; an open menu must not tick it back.
71
+ const removeKeys = (keys) => {
72
+ const removed = new Set(keys);
73
+ commit(new Set([...appliedKeys].filter((key) => !removed.has(key))));
74
+ if (isOpen && edits)
75
+ setEdits({ added: new Set([...edits.added].filter((key) => !removed.has(key))), removed: edits.removed });
76
+ };
77
+ // Clear all has nothing to do when the only ticked options are ones the user cannot untick.
78
+ const canClearAll = clearAllKeys(draftKeys, options).size < draftKeys.size;
79
+ return { appliedKeys, draftKeys, isOpen, canClearAll, setOpen, changeDraft, clearAll, selectAll, apply, removeKeys };
80
+ };
81
+
82
+ export { useMultiSelectSelection };
83
+ //# sourceMappingURL=useMultiSelectSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMultiSelectSelection.js","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AA6BA;;;;;;AAMG;AACI,MAAM,uBAAuB,GAAG,CAAC,EACtC,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,OAAO,GACwB,KAAI;AACnC,IAAA,MAAM,YAAY,GAAG,YAAY,KAAK,SAAS;;AAE/C,IAAA,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;IACrF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,MAAM,iBAAiB,CAAC,mBAAmB,CAAC,IAAI,IAAI,GAAG,EAAkB,CAAC;AAC3H,IAAA,MAAM,WAAW,GAAG,mBAAmB,CAAC,YAAY,GAAG,cAAc,GAAG,YAAY,EAAE,OAAO,CAAC;IAE9F,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;;;;IAI3C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAsE,IAAI,CAAC;IAC7G,MAAM,SAAS,GAAG,MAAM,IAAI,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,G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AAC,IAAI;IAE1E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE;AACtH;;"}
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var useResizeObserver = require('@flipdish/ui-library/hooks/useResizeObserver');
4
+ var React = require('react');
5
+ var multiSelect_utils = require('../utilities/multiSelect.utils.cjs');
6
+
7
+ /** Pixels of label a squeezed pill keeps: room for a character or two and the ellipsis. */
8
+ const MIN_LABEL_WIDTH = 24;
9
+ /**
10
+ * Measures how many of the trigger's pills fit on its one row, so the rest collapse into a `+N` count. It re-measures
11
+ * when the selection changes and when the row is resized.
12
+ *
13
+ * @param pillKey A string that changes whenever the pills do, such as their ids joined, with the size.
14
+ * @param gap Space between two neighbours in the row, in pixels; must match the row's `gap` class.
15
+ * @returns `rowRef` for the row the pills share, `measureRef` for a hidden copy of every pill (its label as its first child) followed by the overflow count, and how many pills fit.
16
+ */
17
+ const usePillOverflow = (pillKey, gap) => {
18
+ const rowRef = React.useRef(null);
19
+ const measureRef = React.useRef(null);
20
+ const [visibleCount, setVisibleCount] = React.useState(Number.POSITIVE_INFINITY);
21
+ const measure = React.useCallback(() => {
22
+ const row = rowRef.current;
23
+ const copies = measureRef.current;
24
+ if (!row || !copies)
25
+ return;
26
+ const widths = Array.from(copies.children, (child) => child.getBoundingClientRect().width);
27
+ const overflowWidth = widths.pop() ?? 0;
28
+ // Everything in the first pill but its label is fixed: padding and the remove button.
29
+ const firstLabelWidth = copies.firstElementChild?.firstElementChild?.getBoundingClientRect().width ?? 0;
30
+ const minPillWidth = (widths[0] ?? 0) - firstLabelWidth + Math.min(firstLabelWidth, MIN_LABEL_WIDTH);
31
+ setVisibleCount(multiSelect_utils.countFittingPills({ pillWidths: widths, availableWidth: row.getBoundingClientRect().width, gap, overflowWidth, minPillWidth }));
32
+ }, [gap]);
33
+ // Before paint, so a changed selection never flashes pills that do not fit.
34
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `pillKey` is the signal that the measured pills changed.
35
+ React.useLayoutEffect(measure, [measure, pillKey]);
36
+ useResizeObserver.useResizeObserver({ ref: rowRef, onResize: measure });
37
+ // The copies change size without the row doing so when a web font loads or a pill gains its remove button.
38
+ useResizeObserver.useResizeObserver({ ref: measureRef, onResize: measure });
39
+ return { rowRef, measureRef, visibleCount };
40
+ };
41
+
42
+ exports.usePillOverflow = usePillOverflow;
43
+ //# sourceMappingURL=usePillOverflow.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePillOverflow.cjs","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.ts"],"sourcesContent":[null],"names":["useRef","useState","useCallback","countFittingPills","useLayoutEffect","useResizeObserver"],"mappings":";;;;;;AAMA;AACA,MAAM,eAAe,GAAG,EAAE;AAE1B;;;;;;;AAOG;MACU,eAAe,GAAG,CAAC,OAAe,EAAE,GAAW,KAAI;AAC9D,IAAA,MAAM,MAAM,GAAGA,YAAM,CAAiB,IAAI,CAAC;AAC3C,IAAA,MAAM,UAAU,GAAGA,YAAM,CAAiB,IAAI,CAAC;AAC/C,IAAA,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAGC,cAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC;AAE1E,IAAA,MAAM,OAAO,GAAGC,iBAAW,CAAC,MAAK;AAC/B,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO;AAC1B,QAAA,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO;AACjC,QAAA,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE;QAErB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC;QAC1F,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC;;AAEvC,QAAA,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,CAAC,KAAK,IAAI,CAAC;QACvG,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC;QAEpG,eAAe,CAACC,mCAAiB,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;AACjJ,IAAA,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;;;IAITC,qBAAe,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5CC,mCAAiB,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;;IAErDA,mCAAiB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAEzD,IAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE;AAC7C;;"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Measures how many of the trigger's pills fit on its one row, so the rest collapse into a `+N` count. It re-measures
3
+ * when the selection changes and when the row is resized.
4
+ *
5
+ * @param pillKey A string that changes whenever the pills do, such as their ids joined, with the size.
6
+ * @param gap Space between two neighbours in the row, in pixels; must match the row's `gap` class.
7
+ * @returns `rowRef` for the row the pills share, `measureRef` for a hidden copy of every pill (its label as its first child) followed by the overflow count, and how many pills fit.
8
+ */
9
+ export declare const usePillOverflow: (pillKey: string, gap: number) => {
10
+ rowRef: import("react").RefObject<HTMLDivElement | null>;
11
+ measureRef: import("react").RefObject<HTMLDivElement | null>;
12
+ visibleCount: number;
13
+ };
14
+ //# sourceMappingURL=usePillOverflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePillOverflow.d.ts","sourceRoot":"","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,KAAK,MAAM;;;;CA2B3D,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { useResizeObserver } from '@flipdish/ui-library/hooks/useResizeObserver';
2
+ import { useRef, useState, useCallback, useLayoutEffect } from 'react';
3
+ import { countFittingPills } from '../utilities/multiSelect.utils.js';
4
+
5
+ /** Pixels of label a squeezed pill keeps: room for a character or two and the ellipsis. */
6
+ const MIN_LABEL_WIDTH = 24;
7
+ /**
8
+ * Measures how many of the trigger's pills fit on its one row, so the rest collapse into a `+N` count. It re-measures
9
+ * when the selection changes and when the row is resized.
10
+ *
11
+ * @param pillKey A string that changes whenever the pills do, such as their ids joined, with the size.
12
+ * @param gap Space between two neighbours in the row, in pixels; must match the row's `gap` class.
13
+ * @returns `rowRef` for the row the pills share, `measureRef` for a hidden copy of every pill (its label as its first child) followed by the overflow count, and how many pills fit.
14
+ */
15
+ const usePillOverflow = (pillKey, gap) => {
16
+ const rowRef = useRef(null);
17
+ const measureRef = useRef(null);
18
+ const [visibleCount, setVisibleCount] = useState(Number.POSITIVE_INFINITY);
19
+ const measure = useCallback(() => {
20
+ const row = rowRef.current;
21
+ const copies = measureRef.current;
22
+ if (!row || !copies)
23
+ return;
24
+ const widths = Array.from(copies.children, (child) => child.getBoundingClientRect().width);
25
+ const overflowWidth = widths.pop() ?? 0;
26
+ // Everything in the first pill but its label is fixed: padding and the remove button.
27
+ const firstLabelWidth = copies.firstElementChild?.firstElementChild?.getBoundingClientRect().width ?? 0;
28
+ const minPillWidth = (widths[0] ?? 0) - firstLabelWidth + Math.min(firstLabelWidth, MIN_LABEL_WIDTH);
29
+ setVisibleCount(countFittingPills({ pillWidths: widths, availableWidth: row.getBoundingClientRect().width, gap, overflowWidth, minPillWidth }));
30
+ }, [gap]);
31
+ // Before paint, so a changed selection never flashes pills that do not fit.
32
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `pillKey` is the signal that the measured pills changed.
33
+ useLayoutEffect(measure, [measure, pillKey]);
34
+ useResizeObserver({ ref: rowRef, onResize: measure });
35
+ // The copies change size without the row doing so when a web font loads or a pill gains its remove button.
36
+ useResizeObserver({ ref: measureRef, onResize: measure });
37
+ return { rowRef, measureRef, visibleCount };
38
+ };
39
+
40
+ export { usePillOverflow };
41
+ //# sourceMappingURL=usePillOverflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePillOverflow.js","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAMA;AACA,MAAM,eAAe,GAAG,EAAE;AAE1B;;;;;;;AAOG;MACU,eAAe,GAAG,CAAC,OAAe,EAAE,GAAW,KAAI;AAC9D,IAAA,MAAM,MAAM,GAAG,MAAM,CAAiB,IAAI,CAAC;AAC3C,IAAA,MAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC;AAC/C,IAAA,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,iBAAiB,CAAC;AAE1E,IAAA,MAAM,OAAO,GAAG,WAAW,CAAC,MAAK;AAC/B,QAAA,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO;AAC1B,QAAA,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO;AACjC,QAAA,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM;YAAE;QAErB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC;QAC1F,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC;;AAEvC,QAAA,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,CAAC,KAAK,IAAI,CAAC;QACvG,MAAM,YAAY,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC;QAEpG,eAAe,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC;AACjJ,IAAA,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;;;IAIT,eAAe,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5C,iBAAiB,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;;IAErD,iBAAiB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAEzD,IAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE;AAC7C;;"}
@@ -3,36 +3,128 @@
3
3
  var React = require('react');
4
4
  var children_utils = require('../../../../../utilities/__internal__/childrenUtils/children.utils.cjs');
5
5
 
6
+ const toOption = (source, fallback = {}) => {
7
+ const id = source.id ?? fallback.id;
8
+ if (id == null)
9
+ return null;
10
+ const text = source.label || (typeof source.children === 'string' ? source.children : '') || source.textValue || fallback.label;
11
+ return { id, label: text || String(id), isDisabled: Boolean(source.isDisabled ?? fallback.isDisabled) };
12
+ };
13
+ const isOption = (option) => option !== null;
14
+ /**
15
+ * Lists the options the menu draws, in its order, which is the order the trigger shows their pills. It reads them from
16
+ * the same place react-aria does, so the trigger and the footer never act on an option the menu does not show.
17
+ *
18
+ * @param items The data-driven `items` list; used with a render function, or alone when there are no children.
19
+ * @param children Static `MultiSelect.Item` elements, which react-aria draws in place of `items`, or a render function.
20
+ * A render function is called per item and the id, text and disabled state of the element it returns win over the item's.
21
+ * @returns One entry per option that has an id. Empty when children is a render function and no items were passed.
22
+ */
23
+ const collectOptions = (items, children) => {
24
+ if (typeof children === 'function') {
25
+ return (items ?? [])
26
+ .map((item) => {
27
+ const rendered = children(item);
28
+ return toOption(React.isValidElement(rendered) ? rendered.props : {}, item);
29
+ })
30
+ .filter(isOption);
31
+ }
32
+ if (children != null) {
33
+ return children_utils.flattenChildren(children)
34
+ .filter(React.isValidElement)
35
+ .map((child) => toOption(child.props))
36
+ .filter(isOption);
37
+ }
38
+ return (items ?? []).map((item) => toOption(item)).filter(isOption);
39
+ };
40
+ /**
41
+ * Reads a selection once into a form that can be read again. An iterable such as a generator is spent by its first
42
+ * read, so the same one must never be read on a later render.
43
+ *
44
+ * @param selection The selection as the consumer passed it.
45
+ * @returns `'all'`, `undefined` and a set as they are; any other iterable as a new set of its keys.
46
+ */
47
+ const snapshotSelection = (selection) => {
48
+ if (selection === undefined)
49
+ return undefined;
50
+ // Returned as a literal: a string is itself iterable, so the comparison alone does not narrow the type.
51
+ if (selection === 'all')
52
+ return 'all';
53
+ return selection instanceof Set ? selection : new Set(selection);
54
+ };
6
55
  /**
7
- * Counts how many options the trigger should report as selected.
56
+ * Turns a selection into explicit keys, so nothing downstream has to handle `'all'`.
8
57
  *
9
- * @param selection The current selection. A set counts its members; `'all'` counts the data-driven list.
10
- * @param itemCount Length of the `items` array. Used only when `selection` is `'all'`, and zero when that list is absent.
11
- * @returns The number shown in the trigger. Zero when the selection is neither a set nor `'all'`.
58
+ * @param selection The selection as the consumer or the list reports it.
59
+ * @param options Every option, used to expand `'all'`.
60
+ * @returns The same set when one was given, a set of any other iterable's keys, and an empty set for none. `'all'`
61
+ * gives every enabled option's id, as it does in react-aria: a disabled option the user could never untick is left out.
12
62
  */
13
- const countSelectedKeys = (selection, itemCount) => {
63
+ const resolveSelectedKeys = (selection, options) => {
14
64
  if (selection instanceof Set)
15
- return selection.size;
16
- return selection === 'all' ? itemCount : 0;
65
+ return selection;
66
+ if (selection === 'all')
67
+ return new Set(options.filter((option) => !option.isDisabled).map((option) => option.id));
68
+ return new Set(selection ?? []);
17
69
  };
18
70
  /**
19
- * Collects the keys Select all applies.
71
+ * Applies Select all: ticks every option the user is allowed to change.
72
+ *
73
+ * @param current The keys ticked before the press.
74
+ * @param options Every option. A disabled one keeps the state it had.
75
+ * @returns The keys ticked after the press.
76
+ */
77
+ const selectAllKeys = (current, options) => new Set([...current, ...options.filter((option) => !option.isDisabled).map((option) => option.id)]);
78
+ /**
79
+ * Applies Clear all: unticks every option the user is allowed to change.
80
+ *
81
+ * @param current The keys ticked before the press.
82
+ * @param options Every option. A disabled one that is ticked stays ticked.
83
+ * @returns The keys ticked after the press.
84
+ */
85
+ const clearAllKeys = (current, options) => new Set(options.filter((option) => option.isDisabled && current.has(option.id)).map((option) => option.id));
86
+ /**
87
+ * Compares two selections by their members.
88
+ *
89
+ * @param a One selection.
90
+ * @param b The other selection.
91
+ * @returns `true` when both hold exactly the same keys.
92
+ */
93
+ const areKeySetsEqual = (a, b) => a.size === b.size && [...a].every((key) => b.has(key));
94
+ /**
95
+ * Works out how many pills the trigger shows before it collapses the rest into `+N`.
20
96
  *
21
- * @param itemIds Ids from a data-driven `items` list. When present, even empty, static children are ignored.
22
- * @param children Static `MultiSelect.Item` elements, or a render function that carries no ids.
23
- * @returns Those ids. Empty when children is a render function and no items were passed.
97
+ * @param options The pill, row, gap and overflow-count widths.
98
+ * @returns Every pill when they all fit, otherwise as many whole pills as fit beside the count. When not even one whole
99
+ * pill fits, one if it can be squeezed into the room left, and none (the count alone) if it cannot.
24
100
  */
25
- const collectSelectableKeys = (itemIds, children) => {
26
- if (itemIds)
27
- return new Set(itemIds);
28
- if (typeof children === 'function')
29
- return new Set();
30
- return new Set(children_utils.flattenChildren(children)
31
- .filter(React.isValidElement)
32
- .map((child) => child.props.id)
33
- .filter((id) => id != null));
101
+ const countFittingPills = ({ pillWidths, availableWidth, gap, overflowWidth, minPillWidth }) => {
102
+ if (pillWidths.length === 0)
103
+ return 0;
104
+ const totalWidth = pillWidths.reduce((sum, width) => sum + width, 0) + gap * (pillWidths.length - 1);
105
+ if (totalWidth <= availableWidth)
106
+ return pillWidths.length;
107
+ let usedWidth = 0;
108
+ let count = 0;
109
+ for (const width of pillWidths) {
110
+ const nextWidth = usedWidth + width + gap;
111
+ if (nextWidth + overflowWidth > availableWidth)
112
+ break;
113
+ usedWidth = nextWidth;
114
+ count += 1;
115
+ }
116
+ if (count > 0)
117
+ return count;
118
+ // A lone pill needs no count beside it; any other is squeezed into what the count leaves.
119
+ const roomForOnePill = pillWidths.length > 1 ? availableWidth - gap - overflowWidth : availableWidth;
120
+ return roomForOnePill >= minPillWidth ? 1 : 0;
34
121
  };
35
122
 
36
- exports.collectSelectableKeys = collectSelectableKeys;
37
- exports.countSelectedKeys = countSelectedKeys;
123
+ exports.areKeySetsEqual = areKeySetsEqual;
124
+ exports.clearAllKeys = clearAllKeys;
125
+ exports.collectOptions = collectOptions;
126
+ exports.countFittingPills = countFittingPills;
127
+ exports.resolveSelectedKeys = resolveSelectedKeys;
128
+ exports.selectAllKeys = selectAllKeys;
129
+ exports.snapshotSelection = snapshotSelection;
38
130
  //# sourceMappingURL=multiSelect.utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"multiSelect.utils.cjs","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.ts"],"sourcesContent":[null],"names":["flattenChildren","isValidElement"],"mappings":";;;;;AAUA;;;;;;AAMG;MACU,iBAAiB,GAAG,CAAC,SAA+B,EAAE,SAAiB,KAAY;IAC9F,IAAI,SAAS,YAAY,GAAG;QAAE,OAAO,SAAS,CAAC,IAAI;IACnD,OAAO,SAAS,KAAK,KAAK,GAAG,SAAS,GAAG,CAAC;AAC5C;AAEA;;;;;;AAMG;MACU,qBAAqB,GAAG,CAAC,OAAiD,EAAE,QAA6B,KAA0B;AAC9I,IAAA,IAAI,OAAO;AAAE,QAAA,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC;IACpC,IAAI,OAAO,QAAQ,KAAK,UAAU;QAAE,OAAO,IAAI,GAAG,EAAE;AAEpD,IAAA,OAAO,IAAI,GAAG,CACZA,8BAAe,CAAC,QAAQ;SACrB,MAAM,CAACC,oBAAc;SACrB,GAAG,CAAC,CAAC,KAAK,KAAM,KAAK,CAAC,KAAkC,CAAC,EAAE;SAC3D,MAAM,CAAC,CAAC,EAAE,KAA4B,EAAE,IAAI,IAAI,CAAC,CACrD;AACH;;;"}
1
+ {"version":3,"file":"multiSelect.utils.cjs","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.ts"],"sourcesContent":[null],"names":["isValidElement","flattenChildren"],"mappings":";;;;;AA+BA,MAAM,QAAQ,GAAG,CAAC,MAAoB,EAAE,QAAA,GAAyB,EAAE,KAA8B;IAC/F,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,IAAI,QAAQ,CAAC,EAAE;IACnC,IAAI,EAAE,IAAI,IAAI;AAAE,QAAA,OAAO,IAAI;AAC3B,IAAA,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,KAAK,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,GAAG,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,SAAS,IAAI,QAAQ,CAAC,KAAK;IAC/H,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,EAAE;AACzG,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,MAAgC,KAAkC,MAAM,KAAK,IAAI;AAEnG;;;;;;;;AAQG;MACU,cAAc,GAAG,CAAC,KAA4C,EAAE,QAA6B,KAAyB;AACjI,I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,CAAC,MAAM,GAAG,CAAC,CAAC;IACpG,IAAI,UAAU,IAAI,cAAc;QAAE,OAAO,UAAU,CAAC,MAAM;IAE1D,IAAI,SAAS,GAAG,CAAC;IACjB,IAAI,KAAK,GAAG,CAAC;AACb,IAAA,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;AAC9B,QAAA,MAAM,SAAS,GAAG,SAAS,GAAG,KAAK,GAAG,GAAG;AACzC,QAAA,IAAI,SAAS,GAAG,aAAa,GAAG,cAAc;YAAE;QAChD,SAAS,GAAG,SAAS;QACrB,KAAK,IAAI,CAAC;IACZ;IACA,IAAI,KAAK,GAAG,CAAC;AAAE,QAAA,OAAO,KAAK;;AAG3B,IAAA,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,GAAG,cAAc,GAAG,GAAG,GAAG,aAAa,GAAG,cAAc;IACpG,OAAO,cAAc,IAAI,YAAY,GAAG,CAAC,GAAG,CAAC;AAC/C;;;;;;;;"}
@@ -1,23 +1,90 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { SelectItemType } from '../../selects.types';
3
- /** Explicit keys, or `'all'` when every option is selected. */
4
- export type MultiSelectSelection = 'all' | Set<string | number>;
3
+ /** The id of one option. */
4
+ export type MultiSelectKey = string | number;
5
+ /** Explicit keys in any iterable, or `'all'` for every option the user is allowed to change. */
6
+ export type MultiSelectSelection = 'all' | Iterable<MultiSelectKey>;
5
7
  /** Static item elements, or a render function when the list is data-driven. */
6
8
  export type MultiSelectChildren = ReactNode | ((item: SelectItemType) => ReactNode);
9
+ /** What the trigger and the footer need to know about one option. */
10
+ export interface MultiSelectOption {
11
+ /** The option's key in the selection. */
12
+ id: MultiSelectKey;
13
+ /** The text its pill shows in the trigger. */
14
+ label: string;
15
+ /** Whether the user is blocked from ticking or unticking it. */
16
+ isDisabled: boolean;
17
+ }
7
18
  /**
8
- * Counts how many options the trigger should report as selected.
19
+ * Lists the options the menu draws, in its order, which is the order the trigger shows their pills. It reads them from
20
+ * the same place react-aria does, so the trigger and the footer never act on an option the menu does not show.
9
21
  *
10
- * @param selection The current selection. A set counts its members; `'all'` counts the data-driven list.
11
- * @param itemCount Length of the `items` array. Used only when `selection` is `'all'`, and zero when that list is absent.
12
- * @returns The number shown in the trigger. Zero when the selection is neither a set nor `'all'`.
22
+ * @param items The data-driven `items` list; used with a render function, or alone when there are no children.
23
+ * @param children Static `MultiSelect.Item` elements, which react-aria draws in place of `items`, or a render function.
24
+ * A render function is called per item and the id, text and disabled state of the element it returns win over the item's.
25
+ * @returns One entry per option that has an id. Empty when children is a render function and no items were passed.
13
26
  */
14
- export declare const countSelectedKeys: (selection: MultiSelectSelection, itemCount: number) => number;
27
+ export declare const collectOptions: (items: readonly SelectItemType[] | undefined, children: MultiSelectChildren) => MultiSelectOption[];
15
28
  /**
16
- * Collects the keys Select all applies.
29
+ * Reads a selection once into a form that can be read again. An iterable such as a generator is spent by its first
30
+ * read, so the same one must never be read on a later render.
17
31
  *
18
- * @param itemIds Ids from a data-driven `items` list. When present, even empty, static children are ignored.
19
- * @param children Static `MultiSelect.Item` elements, or a render function that carries no ids.
20
- * @returns Those ids. Empty when children is a render function and no items were passed.
32
+ * @param selection The selection as the consumer passed it.
33
+ * @returns `'all'`, `undefined` and a set as they are; any other iterable as a new set of its keys.
21
34
  */
22
- export declare const collectSelectableKeys: (itemIds: readonly (string | number)[] | undefined, children: MultiSelectChildren) => Set<string | number>;
35
+ export declare const snapshotSelection: (selection: MultiSelectSelection | undefined) => "all" | Set<MultiSelectKey> | undefined;
36
+ /**
37
+ * Turns a selection into explicit keys, so nothing downstream has to handle `'all'`.
38
+ *
39
+ * @param selection The selection as the consumer or the list reports it.
40
+ * @param options Every option, used to expand `'all'`.
41
+ * @returns The same set when one was given, a set of any other iterable's keys, and an empty set for none. `'all'`
42
+ * gives every enabled option's id, as it does in react-aria: a disabled option the user could never untick is left out.
43
+ */
44
+ export declare const resolveSelectedKeys: (selection: MultiSelectSelection | undefined, options: readonly MultiSelectOption[]) => Set<MultiSelectKey>;
45
+ /**
46
+ * Applies Select all: ticks every option the user is allowed to change.
47
+ *
48
+ * @param current The keys ticked before the press.
49
+ * @param options Every option. A disabled one keeps the state it had.
50
+ * @returns The keys ticked after the press.
51
+ */
52
+ export declare const selectAllKeys: (current: ReadonlySet<MultiSelectKey>, options: readonly MultiSelectOption[]) => Set<MultiSelectKey>;
53
+ /**
54
+ * Applies Clear all: unticks every option the user is allowed to change.
55
+ *
56
+ * @param current The keys ticked before the press.
57
+ * @param options Every option. A disabled one that is ticked stays ticked.
58
+ * @returns The keys ticked after the press.
59
+ */
60
+ export declare const clearAllKeys: (current: ReadonlySet<MultiSelectKey>, options: readonly MultiSelectOption[]) => Set<MultiSelectKey>;
61
+ /**
62
+ * Compares two selections by their members.
63
+ *
64
+ * @param a One selection.
65
+ * @param b The other selection.
66
+ * @returns `true` when both hold exactly the same keys.
67
+ */
68
+ export declare const areKeySetsEqual: (a: ReadonlySet<MultiSelectKey>, b: ReadonlySet<MultiSelectKey>) => boolean;
69
+ /** The measurements `countFittingPills` works from, all in pixels. */
70
+ export interface PillFitOptions {
71
+ /** Width of each pill, in the order they are shown. */
72
+ pillWidths: readonly number[];
73
+ /** Width of the row the pills share with the overflow count. */
74
+ availableWidth: number;
75
+ /** Space between two neighbours in the row. */
76
+ gap: number;
77
+ /** Width reserved for the `+N` count when some pills are left out. */
78
+ overflowWidth: number;
79
+ /** The narrowest the first pill can be squeezed to and still show its remove button and a few characters. */
80
+ minPillWidth: number;
81
+ }
82
+ /**
83
+ * Works out how many pills the trigger shows before it collapses the rest into `+N`.
84
+ *
85
+ * @param options The pill, row, gap and overflow-count widths.
86
+ * @returns Every pill when they all fit, otherwise as many whole pills as fit beside the count. When not even one whole
87
+ * pill fits, one if it can be squeezed into the room left, and none (the count alone) if it cannot.
88
+ */
89
+ export declare const countFittingPills: ({ pillWidths, availableWidth, gap, overflowWidth, minPillWidth }: PillFitOptions) => number;
23
90
  //# sourceMappingURL=multiSelect.utils.d.ts.map