@flipdish/ui-library 0.66.2 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/components/__internal__/listOption/listOption.styles.cjs +1 -1
  2. package/dist/components/__internal__/listOption/listOption.styles.cjs.map +1 -1
  3. package/dist/components/__internal__/listOption/listOption.styles.js +1 -1
  4. package/dist/components/__internal__/listOption/listOption.styles.js.map +1 -1
  5. package/dist/components/forms/fields/FormMultiSelect/index.cjs +8 -23
  6. package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -1
  7. package/dist/components/forms/fields/FormMultiSelect/index.d.ts +4 -4
  8. package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -1
  9. package/dist/components/forms/fields/FormMultiSelect/index.js +8 -23
  10. package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -1
  11. package/dist/components/molecules/Dropdown/index.cjs +3 -1
  12. package/dist/components/molecules/Dropdown/index.cjs.map +1 -1
  13. package/dist/components/molecules/Dropdown/index.d.ts.map +1 -1
  14. package/dist/components/molecules/Dropdown/index.js +3 -1
  15. package/dist/components/molecules/Dropdown/index.js.map +1 -1
  16. package/dist/components/molecules/Select/index.d.ts +1 -6
  17. package/dist/components/molecules/Select/index.d.ts.map +1 -1
  18. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.cjs +76 -41
  19. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.cjs.map +1 -1
  20. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.d.ts +15 -38
  21. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.d.ts.map +1 -1
  22. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.js +79 -44
  23. package/dist/components/molecules/Selects/MultiSelect/MultiSelect.js.map +1 -1
  24. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.cjs +18 -0
  25. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.cjs.map +1 -0
  26. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.d.ts +15 -0
  27. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.d.ts.map +1 -0
  28. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.js +15 -0
  29. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectItem.js.map +1 -0
  30. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.cjs +74 -0
  31. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.cjs.map +1 -0
  32. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.d.ts +23 -0
  33. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.d.ts.map +1 -0
  34. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.js +72 -0
  35. package/dist/components/molecules/Selects/MultiSelect/components/MultiSelectPills.js.map +1 -0
  36. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.cjs +85 -0
  37. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.cjs.map +1 -0
  38. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.d.ts +35 -0
  39. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.d.ts.map +1 -0
  40. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.js +83 -0
  41. package/dist/components/molecules/Selects/MultiSelect/hooks/useMultiSelectSelection.js.map +1 -0
  42. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.cjs +43 -0
  43. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.cjs.map +1 -0
  44. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.d.ts +14 -0
  45. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.d.ts.map +1 -0
  46. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.js +41 -0
  47. package/dist/components/molecules/Selects/MultiSelect/hooks/usePillOverflow.js.map +1 -0
  48. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.cjs +114 -22
  49. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.cjs.map +1 -1
  50. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.d.ts +79 -12
  51. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.d.ts.map +1 -1
  52. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.js +108 -21
  53. package/dist/components/molecules/Selects/MultiSelect/utilities/multiSelect.utils.js.map +1 -1
  54. package/dist/components/molecules/Selects/Select/Select.cjs +1 -3
  55. package/dist/components/molecules/Selects/Select/Select.cjs.map +1 -1
  56. package/dist/components/molecules/Selects/Select/Select.d.ts +0 -2
  57. package/dist/components/molecules/Selects/Select/Select.d.ts.map +1 -1
  58. package/dist/components/molecules/Selects/Select/Select.js +1 -3
  59. package/dist/components/molecules/Selects/Select/Select.js.map +1 -1
  60. package/dist/components/molecules/Selects/Selects.styles.cjs +3 -4
  61. package/dist/components/molecules/Selects/Selects.styles.cjs.map +1 -1
  62. package/dist/components/molecules/Selects/Selects.styles.d.ts +1 -4
  63. package/dist/components/molecules/Selects/Selects.styles.d.ts.map +1 -1
  64. package/dist/components/molecules/Selects/Selects.styles.js +3 -4
  65. package/dist/components/molecules/Selects/Selects.styles.js.map +1 -1
  66. package/dist/components/molecules/Selects/index.d.ts +1 -2
  67. package/dist/components/molecules/Selects/index.d.ts.map +1 -1
  68. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.cjs +1 -1
  69. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.cjs.map +1 -1
  70. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.js +1 -1
  71. package/dist/components/organisms/DatePickers/DateRangePicker/DateRangePicker.js.map +1 -1
  72. package/dist/styles.css +26 -0
  73. package/package.json +1 -1
  74. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.cjs +0 -43
  75. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.cjs.map +0 -1
  76. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.d.ts +0 -35
  77. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.d.ts.map +0 -1
  78. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.js +0 -41
  79. package/dist/components/molecules/Selects/MultiSelect/useMultiSelectSelection.js.map +0 -1
  80. package/dist/components/molecules/Selects/Select/components/Combobox.cjs +0 -60
  81. package/dist/components/molecules/Selects/Select/components/Combobox.cjs.map +0 -1
  82. package/dist/components/molecules/Selects/Select/components/Combobox.d.ts +0 -16
  83. package/dist/components/molecules/Selects/Select/components/Combobox.d.ts.map +0 -1
  84. package/dist/components/molecules/Selects/Select/components/Combobox.js +0 -58
  85. package/dist/components/molecules/Selects/Select/components/Combobox.js.map +0 -1
@@ -0,0 +1,72 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import { Tooltip } from '@flipdish/ui-library/components/atoms/Tooltip';
3
+ import { cx } from '@flipdish/ui-library/utilities/cx';
4
+ import { joinTestId, slugifyTestId } from '@flipdish/ui-library/utilities/testIdUtils';
5
+ import { useRef, useState, useLayoutEffect } from 'react';
6
+ import { TagGroup, TagList, Tag } from 'react-aria-components';
7
+ import { TagCloseX } from '../../../Tags/Tag/components/TagCloseX.js';
8
+ import { styles as styles$1 } from '../../../Tags/Tags.styles.js';
9
+ import { styles } from '../../Selects.styles.js';
10
+ import { usePillOverflow } from '../hooks/usePillOverflow.js';
11
+
12
+ /** Pixels between two pills; must match the `gap-1` on the row, the tag list and the hidden copies. */
13
+ const PILL_GAP = 4;
14
+ const pillSizes = {
15
+ sm: { tag: 'sm', label: 'max-w-18' },
16
+ md: { tag: 'md', label: 'max-w-20' },
17
+ lg: { tag: 'md', label: 'max-w-20' },
18
+ };
19
+ const pillClassName = (tagSize, hasRemove) => cx(styles$1.root, styles$1.sizes[tagSize].root.base, hasRemove && styles$1.sizes[tagSize].root.withClose, 'shrink-0');
20
+ const PillLabel = ({ label, className, isFocusVisible }) => {
21
+ const labelRef = useRef(null);
22
+ // Tracked here: react-aria reports no hover for a tag that can be neither selected nor pressed.
23
+ const [isHovered, setIsHovered] = useState(false);
24
+ const [isTruncated, setIsTruncated] = useState(false);
25
+ const isActive = isHovered || isFocusVisible;
26
+ // Measured only when the pill becomes active: a label that fits never needs a tooltip.
27
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `label` changes what is measured.
28
+ useLayoutEffect(() => {
29
+ const element = labelRef.current;
30
+ if (isActive && element)
31
+ setIsTruncated(element.scrollWidth > element.clientWidth);
32
+ }, [isActive, label]);
33
+ return (jsx(Tooltip, { title: label, arrow: true, delay: 0, isOpen: isActive && isTruncated, triggerRef: labelRef, children: jsx("span", { ref: labelRef, className: className,
34
+ // A touch has no hover to end, so only a mouse opens the tooltip this way.
35
+ onPointerEnter: (event) => setIsHovered(event.pointerType === 'mouse'), onPointerLeave: () => setIsHovered(false), children: label }) }));
36
+ };
37
+ /**
38
+ * The row of removable pills on a `MultiSelect` trigger: as many as fit, then a `+N` count, or the placeholder when
39
+ * nothing is selected.
40
+ */
41
+ const MultiSelectPills = ({ selectedOptions, size, placeholder, fieldLabel, isDisabled, onRemove, onRemovedLast, testIdPrefix, }) => {
42
+ const { tag: tagSize, label: labelMaxWidth } = pillSizes[size];
43
+ const labelClassName = cx('truncate', labelMaxWidth);
44
+ const canRemove = (option) => !isDisabled && !option.isDisabled;
45
+ const pillTestId = (option) => joinTestId(testIdPrefix, `tag-${slugifyTestId(String(option.id))}`);
46
+ // Whether a pill has its remove button is part of the key: the button changes the pill's width.
47
+ const pillKey = `${size}:${selectedOptions.map((option) => `${option.id}=${option.label}=${canRemove(option)}`).join('|')}`;
48
+ const { rowRef, measureRef, visibleCount } = usePillOverflow(pillKey, PILL_GAP);
49
+ const visibleOptions = selectedOptions.slice(0, visibleCount);
50
+ const hiddenCount = selectedOptions.length - visibleOptions.length;
51
+ // A tag group is a tab stop even when none of its tags can take focus, so it is drawn only when one can.
52
+ const hasRemovablePill = visibleOptions.some(canRemove);
53
+ // A pill on its own may be wider than the row, so it alone may shrink; its label then truncates sooner.
54
+ const squeezable = visibleOptions.length === 1 && 'min-w-0 shrink';
55
+ const handleRemove = (keys) => {
56
+ onRemove(keys);
57
+ // The tag group unmounts once it shows no removable pill, and focus would otherwise fall to the page. Only the pills
58
+ // it will still show count: a removable option hidden behind the count cannot take the focus.
59
+ const stillShown = selectedOptions.filter((option) => !keys.has(option.id)).slice(0, visibleCount);
60
+ if (!stillShown.some(canRemove))
61
+ onRemovedLast();
62
+ };
63
+ return (
64
+ // The row lies over the trigger button, so only the pills take the pointer: a press between them still opens the menu.
65
+ jsxs("div", { ref: rowRef, className: "pointer-events-none relative flex min-w-0 flex-1 items-center gap-1", children: [selectedOptions.length === 0 && (jsx("span", { "aria-hidden": "true", className: cx('truncate text-placeholder', styles.sizes[size].text), children: placeholder })), hasRemovablePill && (jsx(TagGroup, { "aria-label": fieldLabel ? `${fieldLabel}: selected options` : 'Selected options', onRemove: handleRemove, className: "min-w-0", children: jsx(TagList, { className: "flex min-w-0 items-center gap-1", children: visibleOptions.map((option) => (jsx(Tag, { id: option.id, textValue: option.label, isDisabled: !canRemove(option), "data-testid": pillTestId(option), className: cx(pillClassName(tagSize, canRemove(option)), 'pointer-events-auto', !canRemove(option) && 'cursor-not-allowed', squeezable), children: ({ isFocusVisible, allowsRemoving }) => (jsxs(Fragment, { children: [jsx(PillLabel, { label: option.label, className: labelClassName, isFocusVisible: isFocusVisible }), allowsRemoving && canRemove(option) && (jsx(TagCloseX, { size: tagSize, excludeFromTabOrder: true, "data-testid": `${pillTestId(option)}-close` }))] })) }, option.id))) }) })), !hasRemovablePill &&
66
+ visibleOptions.map((option) => (
67
+ // `aria-disabled` when the whole select is: it is dimmed as a disabled control, which a contrast check then leaves alone.
68
+ jsx("span", { "aria-hidden": "true", "aria-disabled": isDisabled || undefined, "data-testid": pillTestId(option), className: cx(pillClassName(tagSize, false), squeezable), children: jsx("span", { className: labelClassName, children: option.label }) }, option.id))), hiddenCount > 0 && (jsxs("span", { "aria-hidden": "true", "data-testid": joinTestId(testIdPrefix, 'overflow'), className: cx('shrink-0 text-primary', styles.sizes[size].text), children: ["+", hiddenCount] })), jsxs("div", { ref: measureRef, "aria-hidden": "true", className: "pointer-events-none invisible absolute top-0 left-0 flex gap-1", children: [selectedOptions.map((option) => (jsxs("span", { className: pillClassName(tagSize, canRemove(option)), children: [jsx("span", { className: labelClassName, children: option.label }), canRemove(option) && (jsx("span", { className: cx('flex', styles$1.close[tagSize].root), children: jsx("span", { className: cx('block', styles$1.close[tagSize].icon) }) }))] }, option.id))), jsxs("span", { className: cx('shrink-0', styles.sizes[size].text), children: ["+", selectedOptions.length] })] })] }));
69
+ };
70
+
71
+ export { MultiSelectPills };
72
+ //# sourceMappingURL=MultiSelectPills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultiSelectPills.js","sources":["../../../../../../src/components/molecules/Selects/MultiSelect/components/MultiSelectPills.tsx"],"sourcesContent":[null],"names":["tagStyles","_jsx","_jsxs","AriaTagGroup","AriaTagList","AriaTag","_Fragment"],"mappings":";;;;;;;;;;;AAcA;AACA,MAAM,QAAQ,GAAG,CAAC;AAElB,MAAM,SAAS,GAAgE;IAC7E,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE;IACpC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE;IACpC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE;CACrC;AAED,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,SAAkB,KACzD,EAAE,CAACA,QAAS,CAAC,IAAI,EAAEA,QAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,IAAIA,QA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IAAA,CAAA,MAAA,EAAA,EAAsB,SAAS,EAAE,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAA,QAAA,EAAA,CACxED,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,cAAc,YAAG,MAAM,CAAC,KAAK,EAAA,CAAQ,EACrD,SAAS,CAAC,MAAM,CAAC,KAChBA,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,EAAE,CAAC,MAAM,EAAED,QAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAA,QAAA,EACxDC,GAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,EAAE,CAAC,OAAO,EAAED,QAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAA,CAAI,EAAA,CAC1D,CACR,CAAA,EAAA,EANQ,MAAM,CAAC,EAAE,CAOb,CACR,CAAC,EACFE,IAAA,CAAA,MAAA,EAAA,EAAM,SAAS,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kBAAI,eAAe,CAAC,MAAM,CAAA,EAAA,CAAQ,CAAA,EAAA,CACtF,CAAA,EAAA,CACF;AAEV;;"}
@@ -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","resolveSelectedKeys","areKeySetsEqual","selectAllKeys","clearAllKeys"],"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,GAAGA,aAAO,CAAC,MAAMC,mCAAiB,CAAC,YAAY,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;I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G,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,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,WAAW;AAE7I,IAAA,MAAM,MAAM,GAAG,CAAC,IAAyB,KAAI;AAC3C,QAAA,IAAI,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC;YAAE;AACxC,QAAA,IAAI,CAAC,YAAY;YAAE,eAAe,CAAC,IAAI,CAAC;AACxC,QAAA,iBAAiB,GAAG,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G,MAAK;QACrB,QAAQ,CAAC,aAAa,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,GAAG,YAAY,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,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,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,CAAC,KAAK,IAAI,EAAE;AAChB,aAAA,GAAG,CAAC,CAAC,IAAI,KAAI;AACZ,YAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;AAC/B,YAAA,OAAO,QAAQ,CAACA,oBAAc,CAAC,QAAQ,CAAC,GAAI,QAAQ,CAAC,KAAsB,GAAG,EAAE,EAAE,IAAI,CAAC;AACzF,QAAA,CAAC;aACA,MAAM,CAAC,QAAQ,CAAC;I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