@rescui/select 0.1.1 → 0.2.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.
- package/lib/index.css +230 -230
- package/lib/parts/common-select.module.pcss.js +1 -1
- package/lib/parts/form-trigger-wrapper.d.ts +1 -0
- package/lib/parts/form-trigger-wrapper.js +5 -2
- package/lib/parts/form-trigger.module.pcss.js +6 -6
- package/lib/parts/multiselect.d.ts +2 -5
- package/lib/parts/multiselect.js +201 -125
- package/lib/parts/native-select.d.ts +2 -2
- package/lib/parts/native-select.js +17 -27
- package/lib/parts/native-select.module.pcss.js +6 -6
- package/lib/parts/trigger.js +3 -2
- package/lib/parts/trigger.module.pcss.js +27 -27
- package/lib/select.d.ts +2 -5
- package/lib/select.js +125 -83
- package/lib/types.d.ts +0 -28
- package/lib/utils.d.ts +14 -0
- package/lib/utils.js +126 -2
- package/package.json +6 -6
- package/lib/state/multiselect/actions.d.ts +0 -36
- package/lib/state/multiselect/actions.js +0 -45
- package/lib/state/multiselect/reducer.d.ts +0 -21
- package/lib/state/multiselect/reducer.js +0 -203
- package/lib/state/multiselect/selectors.d.ts +0 -6
- package/lib/state/multiselect/selectors.js +0 -39
- package/lib/state/select/actions.d.ts +0 -81
- package/lib/state/select/actions.js +0 -87
- package/lib/state/select/reducer.d.ts +0 -22
- package/lib/state/select/reducer.js +0 -199
- package/lib/state/select/selectors.d.ts +0 -20
- package/lib/state/select/selectors.js +0 -114
package/lib/utils.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
2
|
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
3
|
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
4
|
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
5
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
6
|
+
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
6
7
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
8
|
+
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
|
|
9
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
10
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
11
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
7
12
|
|
|
8
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
9
14
|
|
|
@@ -13,6 +18,7 @@ import "core-js/modules/es.object.to-string.js";
|
|
|
13
18
|
import "core-js/modules/es.regexp.exec.js";
|
|
14
19
|
import "core-js/modules/es.string.replace.js";
|
|
15
20
|
import "core-js/modules/web.dom-collections.for-each.js";
|
|
21
|
+
import { useRef } from 'react';
|
|
16
22
|
import { ARROW_DOWN, ARROW_UP, SPACE, ENTER } from './key-codes.js';
|
|
17
23
|
var DEFAULT_NO_OPTIONS_MESSAGES = {
|
|
18
24
|
noOptions: 'No options',
|
|
@@ -99,4 +105,122 @@ var reverseTheme = function reverseTheme(theme) {
|
|
|
99
105
|
return theme === 'dark' ? 'light' : 'dark';
|
|
100
106
|
};
|
|
101
107
|
|
|
102
|
-
|
|
108
|
+
function getOptionValue(option) {
|
|
109
|
+
return typeof option.value === 'string' ? option.value : option.label;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var OptionGroupTypes = {
|
|
113
|
+
HEADER: 'header',
|
|
114
|
+
OPTION: 'option',
|
|
115
|
+
DIVIDER: 'divider'
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
var getDefaultCursorIndex = function getDefaultCursorIndex(groups) {
|
|
119
|
+
if (groups.length === 0) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var firstNonEmptyGroupIndex = _findIndexInstanceProperty(groups).call(groups, function (group) {
|
|
124
|
+
return group.options && group.options.length > 0;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (firstNonEmptyGroupIndex === -1) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return [firstNonEmptyGroupIndex, 0];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
function optionsNotEmpty(options) {
|
|
135
|
+
return options && options.length > 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var getPlainOptionsFromGroups = function getPlainOptionsFromGroups(groups) {
|
|
139
|
+
return groups.reduce( // eslint-disable-next-line no-shadow
|
|
140
|
+
function (acc, group, i) {
|
|
141
|
+
var _context, _context2, _context3;
|
|
142
|
+
|
|
143
|
+
return _concatInstanceProperty(acc).call(acc, _filterInstanceProperty(_context = _concatInstanceProperty(_context2 = [optionsNotEmpty(group.options) && i !== 0 && !group.label && {
|
|
144
|
+
type: OptionGroupTypes.DIVIDER
|
|
145
|
+
}, optionsNotEmpty(group.options) && group.label && {
|
|
146
|
+
type: OptionGroupTypes.HEADER,
|
|
147
|
+
label: group.label
|
|
148
|
+
}]).call(_context2, _toConsumableArray(_mapInstanceProperty(_context3 = group.options).call(_context3, function (option, j) {
|
|
149
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
150
|
+
index: [i, j],
|
|
151
|
+
type: OptionGroupTypes.OPTION
|
|
152
|
+
});
|
|
153
|
+
})))).call(_context, function (e) {
|
|
154
|
+
return e;
|
|
155
|
+
}));
|
|
156
|
+
}, []);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
function isGroupsEmpty(groups) {
|
|
160
|
+
return groups.length === 0 || groups.every(function (g) {
|
|
161
|
+
return !g.options || g.options.length === 0;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function useStrongMemo(callback, deps) {
|
|
166
|
+
var prevDeps = useRef([]);
|
|
167
|
+
var memoResult = useRef(null);
|
|
168
|
+
|
|
169
|
+
if (deps.length !== prevDeps.current.length || !prevDeps.current.every(function (dep, i) {
|
|
170
|
+
return dep === deps[i];
|
|
171
|
+
})) {
|
|
172
|
+
prevDeps.current = _toConsumableArray(deps);
|
|
173
|
+
memoResult.current = callback();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return memoResult.current;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function nextIndex(index, isDownDirection) {
|
|
180
|
+
return isDownDirection ? index + 1 : index - 1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function isIndexOutOfRange(index, len) {
|
|
184
|
+
return index < 0 || index >= len;
|
|
185
|
+
} // eslint-disable-next-line complexity
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
function getMovedCursorIndex(groups, currentCursorIndex, isDownDirection) {
|
|
189
|
+
if (isGroupsEmpty(groups)) return currentCursorIndex;
|
|
190
|
+
|
|
191
|
+
var _currentCursorIndex = _slicedToArray(currentCursorIndex, 2),
|
|
192
|
+
grpIndex = _currentCursorIndex[0],
|
|
193
|
+
optIndex = _currentCursorIndex[1];
|
|
194
|
+
|
|
195
|
+
var optLenByGroup = _mapInstanceProperty(groups).call(groups, function (g) {
|
|
196
|
+
return g.options ? g.options.length : 0;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
var newGrpIndex = grpIndex;
|
|
200
|
+
var newOptIndex = nextIndex(optIndex, isDownDirection);
|
|
201
|
+
|
|
202
|
+
while (isIndexOutOfRange(newOptIndex, optLenByGroup[newGrpIndex]) || isIndexOutOfRange(newGrpIndex, groups.length)) {
|
|
203
|
+
newGrpIndex = nextIndex(newGrpIndex, isDownDirection);
|
|
204
|
+
|
|
205
|
+
if (isIndexOutOfRange(newGrpIndex, groups.length)) {
|
|
206
|
+
newGrpIndex = isDownDirection ? 0 : groups.length - 1;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
newOptIndex = isDownDirection ? 0 : optLenByGroup[newGrpIndex] - 1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return [newGrpIndex, newOptIndex];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var isIndexMatchCursor = function isIndexMatchCursor(cursorIndex, index) {
|
|
216
|
+
if (cursorIndex === null) return false;
|
|
217
|
+
return index[0] === cursorIndex[0] && index[1] === cursorIndex[1];
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
var withoutGroupsLabel = function withoutGroupsLabel(groups) {
|
|
221
|
+
return groups.every(function (g) {
|
|
222
|
+
return !g.label;
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export { OptionGroupTypes, calculateMaxHeight, convertToOptionGroupsIfNeeded, escapeRegex, getDefaultCursorIndex, getEmptyMessage, getMovedCursorIndex, getOptionValue, getPlainOptionsFromGroups, isGroupsEmpty, isIndexMatchCursor, reverseTheme, shouldOpenSelect, useStrongMemo, withoutGroupsLabel };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/select",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime-corejs3": "^7.14.0",
|
|
18
18
|
"@juggle/resize-observer": "3.3.0",
|
|
19
|
-
"@rescui/dropdown": "^0.2.
|
|
20
|
-
"@rescui/icons": "^0.
|
|
21
|
-
"@rescui/menu": "^0.
|
|
22
|
-
"@rescui/tag": "^0.3.
|
|
19
|
+
"@rescui/dropdown": "^0.2.5",
|
|
20
|
+
"@rescui/icons": "^0.7.0",
|
|
21
|
+
"@rescui/menu": "^0.5.0",
|
|
22
|
+
"@rescui/tag": "^0.3.2",
|
|
23
23
|
"@rescui/typography": "^0.7.0",
|
|
24
24
|
"classnames": "^2.2.6",
|
|
25
25
|
"core-js": "^3.9.1",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"scripts": {
|
|
43
43
|
"build": "rescui-scripts build --css-modules"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "dd88e661d9570902b4eed4ffb2b9d164f246c89b"
|
|
46
46
|
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Index, SelectOption } from '../../types';
|
|
2
|
-
export declare function addSelectedIndex(index: Index): {
|
|
3
|
-
type: string;
|
|
4
|
-
index: Index;
|
|
5
|
-
};
|
|
6
|
-
export declare namespace addSelectedIndex {
|
|
7
|
-
var type: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function removeSelectedIndex(index: Index): {
|
|
10
|
-
type: string;
|
|
11
|
-
index: Index;
|
|
12
|
-
};
|
|
13
|
-
export declare namespace removeSelectedIndex {
|
|
14
|
-
var type: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function setHideSelected(hideSelected: boolean): {
|
|
17
|
-
type: string;
|
|
18
|
-
hideSelected: boolean;
|
|
19
|
-
};
|
|
20
|
-
export declare namespace setHideSelected {
|
|
21
|
-
var type: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function removeSelectedOption(unselectedOption: SelectOption): {
|
|
24
|
-
type: string;
|
|
25
|
-
unselectedOption: SelectOption;
|
|
26
|
-
};
|
|
27
|
-
export declare namespace removeSelectedOption {
|
|
28
|
-
var type: string;
|
|
29
|
-
}
|
|
30
|
-
export declare function setSelectedValue(selected: SelectOption[]): {
|
|
31
|
-
type: string;
|
|
32
|
-
selected: SelectOption[];
|
|
33
|
-
};
|
|
34
|
-
export declare namespace setSelectedValue {
|
|
35
|
-
var type: string;
|
|
36
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
function addSelectedIndex(index) {
|
|
2
|
-
return {
|
|
3
|
-
type: addSelectedIndex.type,
|
|
4
|
-
index: index
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
addSelectedIndex.type = 'ADD_SELECTED_BY_INDEX';
|
|
9
|
-
|
|
10
|
-
function removeSelectedIndex(index) {
|
|
11
|
-
return {
|
|
12
|
-
type: removeSelectedIndex.type,
|
|
13
|
-
index: index
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
removeSelectedIndex.type = 'REMOVE_SELECTED_BY_INDEX';
|
|
18
|
-
|
|
19
|
-
function setHideSelected(hideSelected) {
|
|
20
|
-
return {
|
|
21
|
-
type: setHideSelected.type,
|
|
22
|
-
hideSelected: hideSelected
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
setHideSelected.type = 'SET_HIDE_SELECTED';
|
|
27
|
-
|
|
28
|
-
function removeSelectedOption(unselectedOption) {
|
|
29
|
-
return {
|
|
30
|
-
type: removeSelectedOption.type,
|
|
31
|
-
unselectedOption: unselectedOption
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
removeSelectedOption.type = 'REMOVE_SELECTED_OPTION';
|
|
36
|
-
|
|
37
|
-
function setSelectedValue(selected) {
|
|
38
|
-
return {
|
|
39
|
-
type: setSelectedValue.type,
|
|
40
|
-
selected: selected
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
setSelectedValue.type = 'SET_SELECTED_VALUE';
|
|
45
|
-
export { addSelectedIndex, removeSelectedIndex, removeSelectedOption, setHideSelected, setSelectedValue };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { SelectOption, State, Index, Groups, Action } from '../../types';
|
|
2
|
-
export declare function getInitialState(groups: Groups, defaultSelected?: SelectOption[], hideSelected?: boolean): State;
|
|
3
|
-
export declare function multiselectReducer(state: State, action: Action): {
|
|
4
|
-
cursorIndex: any;
|
|
5
|
-
groups: Groups;
|
|
6
|
-
menuIsOpen: boolean;
|
|
7
|
-
selected: SelectOption | SelectOption[];
|
|
8
|
-
searchString: string;
|
|
9
|
-
filteredGroups: Groups;
|
|
10
|
-
hideSelected?: boolean;
|
|
11
|
-
groupsWithoutSelected?: Groups;
|
|
12
|
-
} | {
|
|
13
|
-
selected: any;
|
|
14
|
-
groups: Groups;
|
|
15
|
-
menuIsOpen: boolean;
|
|
16
|
-
searchString: string;
|
|
17
|
-
filteredGroups: Groups;
|
|
18
|
-
cursorIndex: Index;
|
|
19
|
-
hideSelected?: boolean;
|
|
20
|
-
groupsWithoutSelected?: Groups;
|
|
21
|
-
};
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
4
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
5
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
6
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
7
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
8
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
9
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
10
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
11
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
12
|
-
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
-
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
16
|
-
|
|
17
|
-
import { baseReducer } from '../select/reducer.js';
|
|
18
|
-
import { setGroups, clearSelectedAndCloseMenu, closeMenu, openMenu } from '../select/actions.js';
|
|
19
|
-
import { getDefaultCursorIndex, getOptionValue } from '../select/selectors.js';
|
|
20
|
-
import { getGroups, isEmpty } from './selectors.js';
|
|
21
|
-
import { setSelectedValue, setHideSelected, removeSelectedOption, removeSelectedIndex, addSelectedIndex } from './actions.js';
|
|
22
|
-
|
|
23
|
-
function getInitialState(groups) {
|
|
24
|
-
var defaultSelected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
25
|
-
var hideSelected = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
26
|
-
return {
|
|
27
|
-
groups: groups,
|
|
28
|
-
menuIsOpen: false,
|
|
29
|
-
selected: defaultSelected,
|
|
30
|
-
searchString: '',
|
|
31
|
-
filteredGroups: null,
|
|
32
|
-
cursorIndex: getDefaultCursorIndex(groups),
|
|
33
|
-
hideSelected: hideSelected,
|
|
34
|
-
groupsWithoutSelected: groups
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function handleOpenMenu(state) {
|
|
39
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
40
|
-
menuIsOpen: true
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function handleCloseMenu(state) {
|
|
45
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
46
|
-
menuIsOpen: false
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function clearSelection(state) {
|
|
51
|
-
var groups = getGroups(state);
|
|
52
|
-
return {
|
|
53
|
-
selected: null,
|
|
54
|
-
cursorIndex: getDefaultCursorIndex(groups),
|
|
55
|
-
menuIsOpen: false
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function filterSelected(groups, selected) {
|
|
60
|
-
var selectedValues = {};
|
|
61
|
-
|
|
62
|
-
if (selected) {
|
|
63
|
-
selected.forEach(function (s) {
|
|
64
|
-
selectedValues[getOptionValue(s)] = true;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return _mapInstanceProperty(groups).call(groups, function (g) {
|
|
69
|
-
var newOptions = [];
|
|
70
|
-
|
|
71
|
-
if (g.options) {
|
|
72
|
-
var _context;
|
|
73
|
-
|
|
74
|
-
newOptions = _filterInstanceProperty(_context = g.options).call(_context, function (opt) {
|
|
75
|
-
return !selectedValues[getOptionValue(opt)];
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return _objectSpread(_objectSpread({}, g), {}, {
|
|
80
|
-
options: newOptions
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function addSelectedByIndex(state, index) {
|
|
86
|
-
var _context2;
|
|
87
|
-
|
|
88
|
-
var groups = getGroups(state);
|
|
89
|
-
|
|
90
|
-
var _index = _slicedToArray(index, 2),
|
|
91
|
-
grpIndex = _index[0],
|
|
92
|
-
optIndex = _index[1];
|
|
93
|
-
|
|
94
|
-
var selected = Array.isArray(state.selected) ? state.selected : [state.selected];
|
|
95
|
-
var selectedOption = groups[grpIndex].options[optIndex];
|
|
96
|
-
var newSelected = !state.selected ? [selectedOption] : _concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(selected), [selectedOption]);
|
|
97
|
-
return {
|
|
98
|
-
selected: newSelected,
|
|
99
|
-
menuIsOpen: false,
|
|
100
|
-
searchString: '',
|
|
101
|
-
groupsWithoutSelected: filterSelected(state.groups, newSelected)
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function removeSelected(state, option) {
|
|
106
|
-
var selected = Array.isArray(state.selected) ? state.selected : [state.selected];
|
|
107
|
-
|
|
108
|
-
var selectedWithoutOne = _filterInstanceProperty(selected).call(selected, function (o) {
|
|
109
|
-
return getOptionValue(o) !== getOptionValue(option);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
selected: selectedWithoutOne,
|
|
114
|
-
menuIsOpen: false,
|
|
115
|
-
searchString: '',
|
|
116
|
-
groupsWithoutSelected: filterSelected(state.groups, selectedWithoutOne)
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function removeSelectedByIndex(state, index) {
|
|
121
|
-
var groups = getGroups(state);
|
|
122
|
-
|
|
123
|
-
var _index2 = _slicedToArray(index, 2),
|
|
124
|
-
grpIndex = _index2[0],
|
|
125
|
-
optIndex = _index2[1];
|
|
126
|
-
|
|
127
|
-
var unselectedOption = groups[grpIndex].options[optIndex];
|
|
128
|
-
return removeSelected(state, unselectedOption);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function handleToggleHideSelected(state, hideSelected) {
|
|
132
|
-
var result = {
|
|
133
|
-
hideSelected: hideSelected
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
if (hideSelected) {
|
|
137
|
-
var selected = Array.isArray(state.selected) ? state.selected : [state.selected];
|
|
138
|
-
result.groupsWithoutSelected = filterSelected(state.groups, selected);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return result;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function setSelectedControllable(state, selected) {
|
|
145
|
-
var result = {
|
|
146
|
-
selected: selected
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
if (state.hideSelected) {
|
|
150
|
-
result.groupsWithoutSelected = filterSelected(state.groups, selected);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function addDefaultCursorPosFromNewState(state) {
|
|
157
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
158
|
-
cursorIndex: getDefaultCursorIndex(getGroups(state))
|
|
159
|
-
});
|
|
160
|
-
} // eslint-disable-next-line complexity
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
function multiselectReducer(state, action) {
|
|
164
|
-
switch (action.type) {
|
|
165
|
-
case openMenu.type:
|
|
166
|
-
return _objectSpread(_objectSpread({}, state), handleOpenMenu(state));
|
|
167
|
-
|
|
168
|
-
case closeMenu.type:
|
|
169
|
-
return _objectSpread(_objectSpread({}, state), handleCloseMenu(state));
|
|
170
|
-
|
|
171
|
-
case addSelectedIndex.type:
|
|
172
|
-
return addDefaultCursorPosFromNewState(_objectSpread(_objectSpread({}, state), addSelectedByIndex(state, action.index)));
|
|
173
|
-
|
|
174
|
-
case removeSelectedIndex.type:
|
|
175
|
-
return addDefaultCursorPosFromNewState(_objectSpread(_objectSpread({}, state), removeSelectedByIndex(state, action.index)));
|
|
176
|
-
|
|
177
|
-
case removeSelectedOption.type:
|
|
178
|
-
return addDefaultCursorPosFromNewState(_objectSpread(_objectSpread({}, state), removeSelected(state, action.unselectedOption)));
|
|
179
|
-
|
|
180
|
-
case setHideSelected.type:
|
|
181
|
-
return addDefaultCursorPosFromNewState(_objectSpread(_objectSpread({}, state), handleToggleHideSelected(state, action.hideSelected)));
|
|
182
|
-
|
|
183
|
-
case clearSelectedAndCloseMenu.type:
|
|
184
|
-
return _objectSpread(_objectSpread(_objectSpread({}, state), clearSelection(state)), {}, {
|
|
185
|
-
groupsWithoutSelected: state.groups
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
case setGroups.type:
|
|
189
|
-
var selected = Array.isArray(state.selected) ? state.selected : [state.selected];
|
|
190
|
-
return _objectSpread({}, getInitialState(action.groups, selected, state.hideSelected));
|
|
191
|
-
|
|
192
|
-
case setSelectedValue.type:
|
|
193
|
-
return addDefaultCursorPosFromNewState(_objectSpread(_objectSpread({}, state), setSelectedControllable(state, action.selected)));
|
|
194
|
-
|
|
195
|
-
default:
|
|
196
|
-
return baseReducer(state, action, {
|
|
197
|
-
getGroups: getGroups,
|
|
198
|
-
isEmpty: isEmpty
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export { getInitialState, multiselectReducer };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SelectOption, State } from '../../types';
|
|
2
|
-
export declare const getGroups: (state: State) => import("../../types").Groups;
|
|
3
|
-
export declare const isEmpty: (state: State) => boolean;
|
|
4
|
-
export declare const getPlainOptions: (state: State) => any[];
|
|
5
|
-
export declare const isSelected: (state: State, value: string) => boolean;
|
|
6
|
-
export declare const getSelectedArray: (state: State) => SelectOption[];
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
2
|
-
import { getPlainOptionsFromGroups, getOptionValue } from '../select/selectors.js';
|
|
3
|
-
|
|
4
|
-
var getGroups = function getGroups(state) {
|
|
5
|
-
var groups = state.searchString && state.searchString !== '' ? state.filteredGroups : state.groups;
|
|
6
|
-
return state.hideSelected ? state.groupsWithoutSelected : groups;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
var isEmpty = function isEmpty(state) {
|
|
10
|
-
var groups = getGroups(state);
|
|
11
|
-
return groups.length === 0 || groups.every(function (g) {
|
|
12
|
-
return g.options.length === 0;
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
var getPlainOptions = function getPlainOptions(state) {
|
|
17
|
-
return getPlainOptionsFromGroups(getGroups(state));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var isSelected = function isSelected(state, value) {
|
|
21
|
-
if (!state.selected) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var selected = Array.isArray(state.selected) ? state.selected : [state.selected];
|
|
26
|
-
return Boolean(_findInstanceProperty(selected).call(selected, function (o) {
|
|
27
|
-
return getOptionValue(o) === value;
|
|
28
|
-
}));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var getSelectedArray = function getSelectedArray(state) {
|
|
32
|
-
if (!state.selected) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return Array.isArray(state.selected) ? state.selected : [state.selected];
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { getGroups, getPlainOptions, getSelectedArray, isEmpty, isSelected };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Index, Groups, SelectOption, FilterFn } from '../../types';
|
|
2
|
-
export declare function cursorMovedUp(): {
|
|
3
|
-
type: string;
|
|
4
|
-
};
|
|
5
|
-
export declare namespace cursorMovedUp {
|
|
6
|
-
var type: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function cursorMovedDown(): {
|
|
9
|
-
type: string;
|
|
10
|
-
};
|
|
11
|
-
export declare namespace cursorMovedDown {
|
|
12
|
-
var type: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function setCursorIndex(cursorIndex: Index): {
|
|
15
|
-
type: string;
|
|
16
|
-
cursorIndex: Index;
|
|
17
|
-
};
|
|
18
|
-
export declare namespace setCursorIndex {
|
|
19
|
-
var type: string;
|
|
20
|
-
}
|
|
21
|
-
export declare function setGroups(groups: Groups): {
|
|
22
|
-
type: string;
|
|
23
|
-
groups: Groups;
|
|
24
|
-
};
|
|
25
|
-
export declare namespace setGroups {
|
|
26
|
-
var type: string;
|
|
27
|
-
}
|
|
28
|
-
export declare function setSelectedValue(selected: SelectOption): {
|
|
29
|
-
type: string;
|
|
30
|
-
selected: SelectOption;
|
|
31
|
-
};
|
|
32
|
-
export declare namespace setSelectedValue {
|
|
33
|
-
var type: string;
|
|
34
|
-
}
|
|
35
|
-
export declare function setSelectedIndex(index: Index): {
|
|
36
|
-
type: string;
|
|
37
|
-
index: Index;
|
|
38
|
-
};
|
|
39
|
-
export declare namespace setSelectedIndex {
|
|
40
|
-
var type: string;
|
|
41
|
-
}
|
|
42
|
-
export declare function addSelectedIndex(index: Index): {
|
|
43
|
-
type: string;
|
|
44
|
-
index: Index;
|
|
45
|
-
};
|
|
46
|
-
export declare namespace addSelectedIndex {
|
|
47
|
-
var type: string;
|
|
48
|
-
}
|
|
49
|
-
export declare function removeSelectedIndex(index: Index): {
|
|
50
|
-
type: string;
|
|
51
|
-
index: Index;
|
|
52
|
-
};
|
|
53
|
-
export declare namespace removeSelectedIndex {
|
|
54
|
-
var type: string;
|
|
55
|
-
}
|
|
56
|
-
export declare function clearSelectedAndCloseMenu(): {
|
|
57
|
-
type: string;
|
|
58
|
-
};
|
|
59
|
-
export declare namespace clearSelectedAndCloseMenu {
|
|
60
|
-
var type: string;
|
|
61
|
-
}
|
|
62
|
-
export declare function setSearchString(searchString: string, filterFn?: FilterFn): {
|
|
63
|
-
type: string;
|
|
64
|
-
searchString: string;
|
|
65
|
-
filterFn: FilterFn;
|
|
66
|
-
};
|
|
67
|
-
export declare namespace setSearchString {
|
|
68
|
-
var type: string;
|
|
69
|
-
}
|
|
70
|
-
export declare function openMenu(): {
|
|
71
|
-
type: string;
|
|
72
|
-
};
|
|
73
|
-
export declare namespace openMenu {
|
|
74
|
-
var type: string;
|
|
75
|
-
}
|
|
76
|
-
export declare function closeMenu(): {
|
|
77
|
-
type: string;
|
|
78
|
-
};
|
|
79
|
-
export declare namespace closeMenu {
|
|
80
|
-
var type: string;
|
|
81
|
-
}
|