@pixum/combobox 5.10.5 → 5.10.7
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.
- package/lib/ComboBox.d.ts +32 -6
- package/lib/ComboBox.js +212 -77
- package/lib/ComboBox.js.map +1 -1
- package/lib/ComboBox.module.css +1 -0
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useComboBox.d.ts +60 -0
- package/lib/hooks/useComboBox.js +226 -0
- package/lib/hooks/useComboBox.js.map +1 -0
- package/lib/hooks/useComboBoxFocus.d.ts +35 -0
- package/lib/hooks/useComboBoxFocus.js +49 -0
- package/lib/hooks/useComboBoxFocus.js.map +1 -0
- package/lib/hooks/useIsDesktopScreenWidth.d.ts +5 -0
- package/lib/hooks/useIsDesktopScreenWidth.js +34 -24
- package/lib/hooks/useIsDesktopScreenWidth.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/partials/ComboBoxNoResults.d.ts +14 -0
- package/lib/partials/ComboBoxNoResults.js +18 -0
- package/lib/partials/ComboBoxNoResults.js.map +1 -0
- package/lib/partials/ComboBoxOptions.d.ts +16 -5
- package/lib/partials/ComboBoxOptions.js +25 -21
- package/lib/partials/ComboBoxOptions.js.map +1 -1
- package/lib/partials/ComboBoxOptionsGroup.d.ts +15 -0
- package/lib/partials/ComboBoxOptionsGroup.js +31 -0
- package/lib/partials/ComboBoxOptionsGroup.js.map +1 -0
- package/lib/partials/ComboBoxOptionsItems.d.ts +32 -17
- package/lib/partials/ComboBoxOptionsItems.js +46 -14
- package/lib/partials/ComboBoxOptionsItems.js.map +1 -1
- package/lib/partials/ComboBoxOptionsSlot.d.ts +17 -16
- package/lib/partials/ComboBoxOptionsSlot.js +26 -11
- package/lib/partials/ComboBoxOptionsSlot.js.map +1 -1
- package/lib/partials/index.d.ts +2 -1
- package/lib/partials/index.js +2 -1
- package/lib/partials/index.js.map +1 -1
- package/lib/types.d.ts +183 -45
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +1 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/options.d.ts +77 -0
- package/lib/utils/options.js +145 -0
- package/lib/utils/options.js.map +1 -0
- package/package.json +8 -8
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { MenuItemProps } from '@pixum/menu-item';
|
|
2
|
+
import type { ComboBoxOption, ComboBoxOptionGroup, ComboBoxOptionItemProps, ComboBoxOptionsInput } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the stable value of an option.
|
|
5
|
+
*
|
|
6
|
+
* `MenuItemProps` does not guarantee a plain string `text`, so the value is
|
|
7
|
+
* resolved in three steps: the visible label first - that is the value existing
|
|
8
|
+
* consumers pass in as `value` and get back from `onOptionItemClick` -, then
|
|
9
|
+
* the explicit `key`, and finally the render index as a last resort so that
|
|
10
|
+
* options without a label still get a unique value.
|
|
11
|
+
*
|
|
12
|
+
* @param item - The option as handed in by the consumer
|
|
13
|
+
* @param index - Position of the option in render order
|
|
14
|
+
* @returns The stable value of the option
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveOptionValue(item: ComboBoxOptionItemProps, index: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the label of an option for the trigger field.
|
|
19
|
+
*
|
|
20
|
+
* Falls back to the resolved value when the option renders a custom node
|
|
21
|
+
* instead of a plain string.
|
|
22
|
+
*
|
|
23
|
+
* @param option - A normalised option
|
|
24
|
+
* @returns The label to display in the trigger field
|
|
25
|
+
*/
|
|
26
|
+
export declare function getOptionLabel(option: ComboBoxOption): string;
|
|
27
|
+
/**
|
|
28
|
+
* Strips the ComboBox specific props from an option so the rest can be spread
|
|
29
|
+
* onto the `MenuItem`.
|
|
30
|
+
*
|
|
31
|
+
* `key` is a reserved React prop and `disabled` is handled by the option
|
|
32
|
+
* wrapper (`aria-disabled` plus the click guard); everything else belongs to
|
|
33
|
+
* `MenuItem` and is forwarded untouched.
|
|
34
|
+
*
|
|
35
|
+
* @param item - The option as handed in by the consumer
|
|
36
|
+
* @returns The props meant for the `MenuItem`
|
|
37
|
+
*/
|
|
38
|
+
export declare function toMenuItemProps({ key, disabled, ...menuItemProps }: ComboBoxOptionItemProps): MenuItemProps;
|
|
39
|
+
/**
|
|
40
|
+
* Normalises flat and grouped options into one list in render order.
|
|
41
|
+
*
|
|
42
|
+
* The index of an entry is identical for both input shapes and is therefore
|
|
43
|
+
* used as the option DOM id that `aria-activedescendant` points at. Doing this
|
|
44
|
+
* once removes the offset arithmetic that grouped rendering used to need.
|
|
45
|
+
*
|
|
46
|
+
* @param options - Flat or grouped options as passed in by the consumer
|
|
47
|
+
* @param listboxId - Id of the listbox, used as prefix for the option ids
|
|
48
|
+
* @returns The normalised options in render order
|
|
49
|
+
*/
|
|
50
|
+
export declare function normaliseOptions(options: ComboBoxOptionsInput, listboxId: string): ComboBoxOption[];
|
|
51
|
+
/**
|
|
52
|
+
* Splits normalised options back into their render groups while keeping the
|
|
53
|
+
* global indices intact, so that the list can be rendered with a single code
|
|
54
|
+
* path for flat and grouped options.
|
|
55
|
+
*
|
|
56
|
+
* @param options - Normalised options in render order
|
|
57
|
+
* @returns One entry per consecutive group
|
|
58
|
+
*/
|
|
59
|
+
export declare function groupOptions(options: ComboBoxOption[]): ComboBoxOptionGroup[];
|
|
60
|
+
/**
|
|
61
|
+
* Normalises the `value` prop to an array, so that single and multi select
|
|
62
|
+
* share the same selection logic.
|
|
63
|
+
*
|
|
64
|
+
* @param value - Selected value(s) or `undefined`
|
|
65
|
+
* @returns The selected values as an array
|
|
66
|
+
*/
|
|
67
|
+
export declare function toValueArray(value: string | string[] | undefined): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Finds the first option that can be activated, starting at `start` and moving
|
|
70
|
+
* by `delta` with wrap-around. Disabled options are skipped.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Normalised options
|
|
73
|
+
* @param start - Index to start from; use `-1` to start before the first option
|
|
74
|
+
* @param delta - Step width, negative values move backwards
|
|
75
|
+
* @returns The index of the next enabled option, or `null` when there is none
|
|
76
|
+
*/
|
|
77
|
+
export declare function findEnabledIndex(options: ComboBoxOption[], start: number, delta: number): number | null;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the stable value of an option.
|
|
14
|
+
*
|
|
15
|
+
* `MenuItemProps` does not guarantee a plain string `text`, so the value is
|
|
16
|
+
* resolved in three steps: the visible label first - that is the value existing
|
|
17
|
+
* consumers pass in as `value` and get back from `onOptionItemClick` -, then
|
|
18
|
+
* the explicit `key`, and finally the render index as a last resort so that
|
|
19
|
+
* options without a label still get a unique value.
|
|
20
|
+
*
|
|
21
|
+
* @param item - The option as handed in by the consumer
|
|
22
|
+
* @param index - Position of the option in render order
|
|
23
|
+
* @returns The stable value of the option
|
|
24
|
+
*/
|
|
25
|
+
export function resolveOptionValue(item, index) {
|
|
26
|
+
if (typeof item.text === 'string' && item.text)
|
|
27
|
+
return item.text;
|
|
28
|
+
if (item.key)
|
|
29
|
+
return item.key;
|
|
30
|
+
return `option-${index}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the label of an option for the trigger field.
|
|
34
|
+
*
|
|
35
|
+
* Falls back to the resolved value when the option renders a custom node
|
|
36
|
+
* instead of a plain string.
|
|
37
|
+
*
|
|
38
|
+
* @param option - A normalised option
|
|
39
|
+
* @returns The label to display in the trigger field
|
|
40
|
+
*/
|
|
41
|
+
export function getOptionLabel(option) {
|
|
42
|
+
if (typeof option.item.text === 'string' && option.item.text) {
|
|
43
|
+
return option.item.text;
|
|
44
|
+
}
|
|
45
|
+
return option.value;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Strips the ComboBox specific props from an option so the rest can be spread
|
|
49
|
+
* onto the `MenuItem`.
|
|
50
|
+
*
|
|
51
|
+
* `key` is a reserved React prop and `disabled` is handled by the option
|
|
52
|
+
* wrapper (`aria-disabled` plus the click guard); everything else belongs to
|
|
53
|
+
* `MenuItem` and is forwarded untouched.
|
|
54
|
+
*
|
|
55
|
+
* @param item - The option as handed in by the consumer
|
|
56
|
+
* @returns The props meant for the `MenuItem`
|
|
57
|
+
*/
|
|
58
|
+
export function toMenuItemProps(_a) {
|
|
59
|
+
var { key, disabled } = _a, menuItemProps = __rest(_a, ["key", "disabled"]);
|
|
60
|
+
return menuItemProps;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Normalises flat and grouped options into one list in render order.
|
|
64
|
+
*
|
|
65
|
+
* The index of an entry is identical for both input shapes and is therefore
|
|
66
|
+
* used as the option DOM id that `aria-activedescendant` points at. Doing this
|
|
67
|
+
* once removes the offset arithmetic that grouped rendering used to need.
|
|
68
|
+
*
|
|
69
|
+
* @param options - Flat or grouped options as passed in by the consumer
|
|
70
|
+
* @param listboxId - Id of the listbox, used as prefix for the option ids
|
|
71
|
+
* @returns The normalised options in render order
|
|
72
|
+
*/
|
|
73
|
+
export function normaliseOptions(options, listboxId) {
|
|
74
|
+
const groups = Array.isArray(options)
|
|
75
|
+
? [['', options]]
|
|
76
|
+
: Object.entries(options);
|
|
77
|
+
const normalised = [];
|
|
78
|
+
groups.forEach(([group, items]) => {
|
|
79
|
+
items.forEach(item => {
|
|
80
|
+
const index = normalised.length;
|
|
81
|
+
normalised.push({
|
|
82
|
+
item,
|
|
83
|
+
group: group || undefined,
|
|
84
|
+
value: resolveOptionValue(item, index),
|
|
85
|
+
index,
|
|
86
|
+
id: `${listboxId}-option-${index}`,
|
|
87
|
+
disabled: item.disabled === true,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return normalised;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Splits normalised options back into their render groups while keeping the
|
|
95
|
+
* global indices intact, so that the list can be rendered with a single code
|
|
96
|
+
* path for flat and grouped options.
|
|
97
|
+
*
|
|
98
|
+
* @param options - Normalised options in render order
|
|
99
|
+
* @returns One entry per consecutive group
|
|
100
|
+
*/
|
|
101
|
+
export function groupOptions(options) {
|
|
102
|
+
return options.reduce((groups, option) => {
|
|
103
|
+
const current = groups[groups.length - 1];
|
|
104
|
+
if (current && current.group === option.group) {
|
|
105
|
+
current.options.push(option);
|
|
106
|
+
return groups;
|
|
107
|
+
}
|
|
108
|
+
groups.push({ group: option.group, options: [option] });
|
|
109
|
+
return groups;
|
|
110
|
+
}, []);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Normalises the `value` prop to an array, so that single and multi select
|
|
114
|
+
* share the same selection logic.
|
|
115
|
+
*
|
|
116
|
+
* @param value - Selected value(s) or `undefined`
|
|
117
|
+
* @returns The selected values as an array
|
|
118
|
+
*/
|
|
119
|
+
export function toValueArray(value) {
|
|
120
|
+
if (Array.isArray(value))
|
|
121
|
+
return value;
|
|
122
|
+
return value ? [value] : [];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Finds the first option that can be activated, starting at `start` and moving
|
|
126
|
+
* by `delta` with wrap-around. Disabled options are skipped.
|
|
127
|
+
*
|
|
128
|
+
* @param options - Normalised options
|
|
129
|
+
* @param start - Index to start from; use `-1` to start before the first option
|
|
130
|
+
* @param delta - Step width, negative values move backwards
|
|
131
|
+
* @returns The index of the next enabled option, or `null` when there is none
|
|
132
|
+
*/
|
|
133
|
+
export function findEnabledIndex(options, start, delta) {
|
|
134
|
+
const { length } = options;
|
|
135
|
+
if (length === 0)
|
|
136
|
+
return null;
|
|
137
|
+
let index = start;
|
|
138
|
+
for (let step = 0; step < length; step += 1) {
|
|
139
|
+
index = (index + delta + length) % length;
|
|
140
|
+
if (!options[index].disabled)
|
|
141
|
+
return index;
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":";;;;;;;;;;;AAQA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAA6B,EAC7B,KAAa;IAEb,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC,IAAI,CAAA;IAChE,IAAI,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC,GAAG,CAAA;IAE7B,OAAO,UAAU,KAAK,EAAE,CAAA;AAC1B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB;IACnD,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC7D,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAA;IACzB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAA;AACrB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,EAIN;QAJM,EAC9B,GAAG,EACH,QAAQ,OAEgB,EADrB,aAAa,cAHc,mBAI/B,CADiB;IAEhB,OAAO,aAAa,CAAA;AACtB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gBAAg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EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAEvD,OAAO,MAAM,CAAA;IACf,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAoC;IAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAEtC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC7B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAyB,EACzB,KAAa,EACb,KAAa;IAEb,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC1B,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAE7B,IAAI,KAAK,GAAG,KAAK,CAAA;IAEjB,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;QAC5C,KAAK,GAAG,CAAC,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC,GAAG,MAAM,CAAA;QAEzC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAA;IAC5C,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixum/combobox",
|
|
3
|
-
"version": "5.10.
|
|
3
|
+
"version": "5.10.7",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"peerDependencies": {
|
|
8
|
-
"@pixum/bottom-sheet": "
|
|
9
|
-
"@pixum/menu": "
|
|
10
|
-
"@pixum/menu-item": "
|
|
11
|
-
"@pixum/text": "
|
|
12
|
-
"@pixum/theme-provider": "
|
|
13
|
-
"@pixum/web-input": "2.
|
|
8
|
+
"@pixum/bottom-sheet": "4.9.0",
|
|
9
|
+
"@pixum/menu": "4.4.2",
|
|
10
|
+
"@pixum/menu-item": "3.4.3",
|
|
11
|
+
"@pixum/text": "3.7.0",
|
|
12
|
+
"@pixum/theme-provider": "5.6.0",
|
|
13
|
+
"@pixum/web-input": "2.5.6"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"lib"
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"sideEffects": [
|
|
19
19
|
"*.css"
|
|
20
20
|
],
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "193f8ae1494e01582893258403bec5a13b847198"
|
|
22
22
|
}
|