@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
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
function cursorMovedUp() {
|
|
2
|
-
return {
|
|
3
|
-
type: cursorMovedUp.type
|
|
4
|
-
};
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
cursorMovedUp.type = 'STEP_UP';
|
|
8
|
-
|
|
9
|
-
function cursorMovedDown() {
|
|
10
|
-
return {
|
|
11
|
-
type: cursorMovedDown.type
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
cursorMovedDown.type = 'STEP_DOWN';
|
|
16
|
-
|
|
17
|
-
function setCursorIndex(cursorIndex) {
|
|
18
|
-
return {
|
|
19
|
-
type: setCursorIndex.type,
|
|
20
|
-
cursorIndex: cursorIndex
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
setCursorIndex.type = 'SET_CURSOR_INDEX';
|
|
25
|
-
|
|
26
|
-
function setGroups(groups) {
|
|
27
|
-
return {
|
|
28
|
-
type: setGroups.type,
|
|
29
|
-
groups: groups
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
setGroups.type = 'SET_GROUPS';
|
|
34
|
-
|
|
35
|
-
function setSelectedValue(selected) {
|
|
36
|
-
return {
|
|
37
|
-
type: setSelectedValue.type,
|
|
38
|
-
selected: selected
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
setSelectedValue.type = 'SET_SELECTED_VALUE';
|
|
43
|
-
|
|
44
|
-
function setSelectedIndex(index) {
|
|
45
|
-
return {
|
|
46
|
-
type: setSelectedIndex.type,
|
|
47
|
-
index: index
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
setSelectedIndex.type = 'SET_SELECTED_BY_INDEX';
|
|
52
|
-
|
|
53
|
-
function clearSelectedAndCloseMenu() {
|
|
54
|
-
return {
|
|
55
|
-
type: clearSelectedAndCloseMenu.type
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
clearSelectedAndCloseMenu.type = 'CLEAR_SELECTED_AND_CLOSE_MENU';
|
|
60
|
-
|
|
61
|
-
function setSearchString(searchString) {
|
|
62
|
-
var filterFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
63
|
-
return {
|
|
64
|
-
type: setSearchString.type,
|
|
65
|
-
searchString: searchString,
|
|
66
|
-
filterFn: filterFn
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
setSearchString.type = 'SET_SEARCH_STRING';
|
|
71
|
-
|
|
72
|
-
function openMenu() {
|
|
73
|
-
return {
|
|
74
|
-
type: openMenu.type
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
openMenu.type = 'OPEN_MENU';
|
|
79
|
-
|
|
80
|
-
function closeMenu() {
|
|
81
|
-
return {
|
|
82
|
-
type: closeMenu.type
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
closeMenu.type = 'CLOSE_MENU';
|
|
87
|
-
export { clearSelectedAndCloseMenu, closeMenu, cursorMovedDown, cursorMovedUp, openMenu, setCursorIndex, setGroups, setSearchString, setSelectedIndex, setSelectedValue };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { SelectOptionsGroup, SelectOption, Groups, State, Index, Action, SelectReducer } from '../../types';
|
|
2
|
-
export declare function getInitialState(groups: SelectOptionsGroup[], defaultSelected?: SelectOption): State;
|
|
3
|
-
export declare function baseReducer(state: State, action: Action, overrides?: {}): {
|
|
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
|
-
};
|
|
22
|
-
export declare const selectReducer: SelectReducer;
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
2
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
3
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
7
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
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
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
|
-
import { setSelectedIndex, setSearchString, clearSelectedAndCloseMenu, setSelectedValue, setGroups, setCursorIndex, cursorMovedDown, cursorMovedUp, closeMenu, openMenu } from './actions.js';
|
|
16
|
-
import { getDefaultCursorIndex, getGroups, isEmpty, getCursorIndex } from './selectors.js';
|
|
17
|
-
|
|
18
|
-
function getInitialState(groups) {
|
|
19
|
-
var defaultSelected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
20
|
-
return {
|
|
21
|
-
groups: groups,
|
|
22
|
-
menuIsOpen: false,
|
|
23
|
-
selected: defaultSelected,
|
|
24
|
-
searchString: '',
|
|
25
|
-
filteredGroups: null,
|
|
26
|
-
cursorIndex: getDefaultCursorIndex(groups)
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function setSelectedByIndex(state, index) {
|
|
31
|
-
var groups = getGroups(state);
|
|
32
|
-
|
|
33
|
-
var _index = _slicedToArray(index, 2),
|
|
34
|
-
grpIndex = _index[0],
|
|
35
|
-
optIndex = _index[1];
|
|
36
|
-
|
|
37
|
-
var selectedOption = groups[grpIndex].options[optIndex];
|
|
38
|
-
return {
|
|
39
|
-
selected: selectedOption,
|
|
40
|
-
cursorIndex: getDefaultCursorIndex(groups),
|
|
41
|
-
menuIsOpen: false,
|
|
42
|
-
searchString: ''
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function clearSelection(state) {
|
|
47
|
-
var groups = getGroups(state);
|
|
48
|
-
return {
|
|
49
|
-
selected: null,
|
|
50
|
-
cursorIndex: getDefaultCursorIndex(groups),
|
|
51
|
-
menuIsOpen: false
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function nextIndex(index, isDownDirection) {
|
|
56
|
-
return isDownDirection ? index + 1 : index - 1;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function isIndexOutOfRange(index, len) {
|
|
60
|
-
return index < 0 || index >= len;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function applySearchFilter(state, searchString, filterFn) {
|
|
64
|
-
if (searchString === '') {
|
|
65
|
-
var selected = Array.isArray(state.selected) ? state.selected[0] : state.selected;
|
|
66
|
-
return _objectSpread(_objectSpread({}, getInitialState(state.groups, selected)), {}, {
|
|
67
|
-
menuIsOpen: state.menuIsOpen
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
var _context;
|
|
71
|
-
|
|
72
|
-
var filteredGroups = _mapInstanceProperty(_context = state.groups).call(_context, function (g) {
|
|
73
|
-
var _context2;
|
|
74
|
-
|
|
75
|
-
return _objectSpread(_objectSpread({}, g), {}, {
|
|
76
|
-
options: _filterInstanceProperty(_context2 = g.options).call(_context2, filterFn)
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
searchString: searchString,
|
|
82
|
-
filteredGroups: filteredGroups,
|
|
83
|
-
cursorIndex: getDefaultCursorIndex(filteredGroups),
|
|
84
|
-
menuIsOpen: true
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function handleOpenMenu(state) {
|
|
90
|
-
return _objectSpread(_objectSpread({}, applySearchFilter(state, '')), {}, {
|
|
91
|
-
menuIsOpen: true
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function handleCloseMenu(state) {
|
|
96
|
-
return _objectSpread(_objectSpread({}, applySearchFilter(state, '')), {}, {
|
|
97
|
-
menuIsOpen: false
|
|
98
|
-
});
|
|
99
|
-
} // eslint-disable-next-line complexity
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function moveCursor(state, isDownDirection, overrides) {
|
|
103
|
-
var isGroupsEmpty = overrides.isEmpty ? overrides.isEmpty(state) : isEmpty(state);
|
|
104
|
-
if (isGroupsEmpty) return getCursorIndex(state);
|
|
105
|
-
var groups = overrides.getGroups ? overrides.getGroups(state) : getGroups(state);
|
|
106
|
-
|
|
107
|
-
var _getCursorIndex = getCursorIndex(state),
|
|
108
|
-
_getCursorIndex2 = _slicedToArray(_getCursorIndex, 2),
|
|
109
|
-
grpIndex = _getCursorIndex2[0],
|
|
110
|
-
optIndex = _getCursorIndex2[1];
|
|
111
|
-
|
|
112
|
-
var optLenByGroup = _mapInstanceProperty(groups).call(groups, function (g) {
|
|
113
|
-
return g.options ? g.options.length : 0;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
var newGrpIndex = grpIndex;
|
|
117
|
-
var newOptIndex = nextIndex(optIndex, isDownDirection);
|
|
118
|
-
|
|
119
|
-
while (isIndexOutOfRange(newOptIndex, optLenByGroup[newGrpIndex]) || isIndexOutOfRange(newGrpIndex, groups.length)) {
|
|
120
|
-
newGrpIndex = nextIndex(newGrpIndex, isDownDirection);
|
|
121
|
-
|
|
122
|
-
if (isIndexOutOfRange(newGrpIndex, groups.length)) {
|
|
123
|
-
newGrpIndex = isDownDirection ? 0 : groups.length - 1;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
newOptIndex = isDownDirection ? 0 : optLenByGroup[newGrpIndex] - 1;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return [newGrpIndex, newOptIndex];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function down(state, overrides) {
|
|
133
|
-
return moveCursor(state, true, overrides);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function up(state, overrides) {
|
|
137
|
-
return moveCursor(state, false, overrides);
|
|
138
|
-
} // eslint-disable-next-line complexity
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
function baseReducer(state, action) {
|
|
142
|
-
var overrides = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
143
|
-
|
|
144
|
-
switch (action.type) {
|
|
145
|
-
case openMenu.type:
|
|
146
|
-
return _objectSpread(_objectSpread({}, state), handleOpenMenu(state));
|
|
147
|
-
|
|
148
|
-
case closeMenu.type:
|
|
149
|
-
return _objectSpread(_objectSpread({}, state), handleCloseMenu(state));
|
|
150
|
-
|
|
151
|
-
case cursorMovedUp.type:
|
|
152
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
153
|
-
cursorIndex: up(state, overrides)
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
case cursorMovedDown.type:
|
|
157
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
158
|
-
cursorIndex: down(state, overrides)
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
case setCursorIndex.type:
|
|
162
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
163
|
-
cursorIndex: action.cursorIndex
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
case setGroups.type:
|
|
167
|
-
var selected = Array.isArray(state.selected) ? state.selected[0] : state.selected;
|
|
168
|
-
return _objectSpread({}, getInitialState(action.groups, selected));
|
|
169
|
-
|
|
170
|
-
case setSelectedValue.type:
|
|
171
|
-
return action.selected !== undefined ? _objectSpread(_objectSpread({}, state), {}, {
|
|
172
|
-
selected: action.selected
|
|
173
|
-
}) : _objectSpread({}, state);
|
|
174
|
-
|
|
175
|
-
case setSelectedIndex.type:
|
|
176
|
-
return _objectSpread(_objectSpread({}, state), setSelectedByIndex(state, action.index));
|
|
177
|
-
|
|
178
|
-
case clearSelectedAndCloseMenu.type:
|
|
179
|
-
return _objectSpread(_objectSpread({}, state), clearSelection(state));
|
|
180
|
-
|
|
181
|
-
case setSearchString.type:
|
|
182
|
-
return _objectSpread(_objectSpread({}, state), applySearchFilter(state, action.searchString, action.filterFn));
|
|
183
|
-
|
|
184
|
-
default:
|
|
185
|
-
throw new Error('Unexpected action in Select/Multiselect component');
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
var selectReducer = function selectReducer(state, action) {
|
|
190
|
-
switch (action.type) {
|
|
191
|
-
case setSelectedIndex.type:
|
|
192
|
-
return _objectSpread(_objectSpread({}, state), setSelectedByIndex(state, action.index));
|
|
193
|
-
|
|
194
|
-
default:
|
|
195
|
-
return baseReducer(state, action);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export { baseReducer, getInitialState, selectReducer };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { SelectOption, State, Index, Groups } from '../../types';
|
|
2
|
-
export declare const getGroups: (state: State) => Groups;
|
|
3
|
-
export declare const getCursorIndex: (state: State) => Index;
|
|
4
|
-
export declare const isIndexMatchCursor: (state: State, index: Index) => boolean;
|
|
5
|
-
export declare const isEmpty: (state: State) => boolean;
|
|
6
|
-
export declare const withoutGroupsLabel: ({ groups }: {
|
|
7
|
-
groups: Groups;
|
|
8
|
-
}) => boolean;
|
|
9
|
-
export declare const OptionGroupTypes: {
|
|
10
|
-
HEADER: string;
|
|
11
|
-
OPTION: string;
|
|
12
|
-
DIVIDER: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const getPlainOptionsFromGroups: (groups: Groups) => any[];
|
|
15
|
-
export declare const getPlainOptions: (state: State) => any[];
|
|
16
|
-
export declare function getOptionValue(option: SelectOption): string;
|
|
17
|
-
export declare const getSelectedValue: (state: State) => string;
|
|
18
|
-
export declare const getSelectedLabel: (state: State) => string;
|
|
19
|
-
export declare const getSelected: (state: State) => SelectOption | SelectOption[];
|
|
20
|
-
export declare const getDefaultCursorIndex: (groups: Groups) => Index;
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
2
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
3
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
7
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
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; }
|
|
12
|
-
|
|
13
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
14
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
15
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
16
|
-
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
|
|
17
|
-
|
|
18
|
-
var getGroups = function getGroups(state) {
|
|
19
|
-
return state.searchString && state.searchString !== '' ? state.filteredGroups : state.groups;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
var getCursorIndex = function getCursorIndex(state) {
|
|
23
|
-
return state.cursorIndex;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
var isIndexMatchCursor = function isIndexMatchCursor(state, index) {
|
|
27
|
-
var cursorIndex = getCursorIndex(state);
|
|
28
|
-
if (cursorIndex === null) return false;
|
|
29
|
-
return index[0] === cursorIndex[0] && index[1] === cursorIndex[1];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
var isEmpty = function isEmpty(state) {
|
|
33
|
-
var groups = getGroups(state);
|
|
34
|
-
return groups.length === 0 || groups.every(function (g) {
|
|
35
|
-
return !g.options || g.options.length === 0;
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var withoutGroupsLabel = function withoutGroupsLabel(_ref) {
|
|
40
|
-
var groups = _ref.groups;
|
|
41
|
-
return groups.every(function (g) {
|
|
42
|
-
return !g.label;
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
var OptionGroupTypes = {
|
|
47
|
-
HEADER: 'header',
|
|
48
|
-
OPTION: 'option',
|
|
49
|
-
DIVIDER: 'divider'
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
function optionsNotEmpty(options) {
|
|
53
|
-
return options && options.length > 0;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var getPlainOptionsFromGroups = function getPlainOptionsFromGroups(groups) {
|
|
57
|
-
return groups.reduce( // eslint-disable-next-line no-shadow
|
|
58
|
-
function (acc, group, i) {
|
|
59
|
-
var _context, _context2, _context3;
|
|
60
|
-
|
|
61
|
-
return _concatInstanceProperty(acc).call(acc, _filterInstanceProperty(_context = _concatInstanceProperty(_context2 = [optionsNotEmpty(group.options) && i !== 0 && !group.label && {
|
|
62
|
-
type: OptionGroupTypes.DIVIDER
|
|
63
|
-
}, optionsNotEmpty(group.options) && group.label && {
|
|
64
|
-
type: OptionGroupTypes.HEADER,
|
|
65
|
-
label: group.label
|
|
66
|
-
}]).call(_context2, _toConsumableArray(_mapInstanceProperty(_context3 = group.options).call(_context3, function (option, j) {
|
|
67
|
-
return _objectSpread(_objectSpread({}, option), {}, {
|
|
68
|
-
index: [i, j],
|
|
69
|
-
type: OptionGroupTypes.OPTION
|
|
70
|
-
});
|
|
71
|
-
})))).call(_context, function (e) {
|
|
72
|
-
return e;
|
|
73
|
-
}));
|
|
74
|
-
}, []);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
var getPlainOptions = function getPlainOptions(state) {
|
|
78
|
-
return getPlainOptionsFromGroups(getGroups(state));
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
function getOptionValue(option) {
|
|
82
|
-
return typeof option.value === 'string' ? option.value : option.label;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
var getSelectedValue = function getSelectedValue(state) {
|
|
86
|
-
if (state.selected === null) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var selected = Array.isArray(state.selected) ? state.selected[0] : state.selected;
|
|
91
|
-
return getOptionValue(selected);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
var getSelected = function getSelected(state) {
|
|
95
|
-
return state.selected;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
var getDefaultCursorIndex = function getDefaultCursorIndex(groups) {
|
|
99
|
-
if (groups.length === 0) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var firstNonEmptyGroupIndex = _findIndexInstanceProperty(groups).call(groups, function (group) {
|
|
104
|
-
return group.options && group.options.length > 0;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
if (firstNonEmptyGroupIndex === -1) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return [firstNonEmptyGroupIndex, 0];
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export { OptionGroupTypes, getCursorIndex, getDefaultCursorIndex, getGroups, getOptionValue, getPlainOptions, getPlainOptionsFromGroups, getSelected, getSelectedValue, isEmpty, isIndexMatchCursor, withoutGroupsLabel };
|