@rescui/select 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE.txt +202 -0
  2. package/README.md +3 -0
  3. package/lib/common-prop-types.d.ts +25 -0
  4. package/lib/common-prop-types.js +18 -0
  5. package/lib/index.css +742 -0
  6. package/lib/index.d.ts +3 -0
  7. package/lib/index.js +4 -0
  8. package/lib/key-codes.d.ts +7 -0
  9. package/lib/key-codes.js +8 -0
  10. package/lib/parts/common-select.module.pcss.js +4 -0
  11. package/lib/parts/foldable.d.ts +34 -0
  12. package/lib/parts/foldable.js +297 -0
  13. package/lib/parts/form-trigger-wrapper.d.ts +13 -0
  14. package/lib/parts/form-trigger-wrapper.js +87 -0
  15. package/lib/parts/form-trigger.module.pcss.js +9 -0
  16. package/lib/parts/multiselect.d.ts +80 -0
  17. package/lib/parts/multiselect.js +399 -0
  18. package/lib/parts/native-select.d.ts +29 -0
  19. package/lib/parts/native-select.js +282 -0
  20. package/lib/parts/native-select.module.pcss.js +9 -0
  21. package/lib/parts/trigger.d.ts +37 -0
  22. package/lib/parts/trigger.js +307 -0
  23. package/lib/parts/trigger.module.pcss.js +30 -0
  24. package/lib/select.d.ts +86 -0
  25. package/lib/select.js +391 -0
  26. package/lib/state/multiselect/actions.d.ts +36 -0
  27. package/lib/state/multiselect/actions.js +45 -0
  28. package/lib/state/multiselect/reducer.d.ts +21 -0
  29. package/lib/state/multiselect/reducer.js +203 -0
  30. package/lib/state/multiselect/selectors.d.ts +6 -0
  31. package/lib/state/multiselect/selectors.js +39 -0
  32. package/lib/state/select/actions.d.ts +81 -0
  33. package/lib/state/select/actions.js +87 -0
  34. package/lib/state/select/reducer.d.ts +22 -0
  35. package/lib/state/select/reducer.js +199 -0
  36. package/lib/state/select/selectors.d.ts +20 -0
  37. package/lib/state/select/selectors.js +114 -0
  38. package/lib/types.d.ts +51 -0
  39. package/lib/utils.d.ts +8 -0
  40. package/lib/utils.js +102 -0
  41. package/package.json +46 -0
@@ -0,0 +1,114 @@
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 };
package/lib/types.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ export declare type SelectSize = 'l' | 'm' | 's';
2
+ export declare type SelectMode = 'classic' | 'rock';
3
+ export declare type SelectOption = {
4
+ label: string;
5
+ value?: string;
6
+ disabled?: boolean;
7
+ };
8
+ export declare type SelectOptionsGroup = {
9
+ label?: string;
10
+ disabled?: boolean;
11
+ options: SelectOption[];
12
+ };
13
+ export declare type SelectOptionOrGroup = SelectOption | SelectOptionsGroup;
14
+ export declare type SelectOptions = SelectOptionOrGroup[];
15
+ export declare type Groups = SelectOptionsGroup[];
16
+ export declare type Index = [number, number];
17
+ export declare type State = {
18
+ groups: Groups;
19
+ menuIsOpen: boolean;
20
+ selected: SelectOption | SelectOption[];
21
+ searchString: string;
22
+ filteredGroups: Groups;
23
+ cursorIndex: Index;
24
+ hideSelected?: boolean;
25
+ groupsWithoutSelected?: Groups;
26
+ };
27
+ export declare type PartialState = Partial<State>;
28
+ export interface GetGroups {
29
+ (state: State): Groups;
30
+ }
31
+ export interface IsEmpty {
32
+ (state: State): boolean;
33
+ }
34
+ export declare type Overrides = {
35
+ getGroups?: GetGroups;
36
+ isEmpty?: IsEmpty;
37
+ };
38
+ export declare type Action = {
39
+ type: string;
40
+ [key: string]: any;
41
+ };
42
+ export interface SelectReducer {
43
+ (state: State, action: Action): State;
44
+ }
45
+ export declare type FilterFn = (option: SelectOption) => boolean;
46
+ export declare type NoOptionsMessageConfig = {
47
+ noOptions: string;
48
+ nothingFound?: string;
49
+ loading?: string;
50
+ };
51
+ export declare type NoOptionsMessage = string | NoOptionsMessageConfig;
package/lib/utils.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Theme } from '@rescui/ui-contexts';
2
+ import type { SelectOptionOrGroup, SelectOptionsGroup, NoOptionsMessage, SelectSize } from './types';
3
+ export declare function shouldOpenSelect(key: string, isTriggerTarget?: boolean): boolean;
4
+ export declare function getEmptyMessage(isLoading: boolean, isNothingFound: boolean, noOptionsMessage: NoOptionsMessage): string;
5
+ export declare function escapeRegex(str: string): string;
6
+ export declare function convertToOptionGroupsIfNeeded(optionsOrGroups?: SelectOptionOrGroup[]): SelectOptionsGroup[];
7
+ export declare const calculateMaxHeight: (size: SelectSize) => number;
8
+ export declare const reverseTheme: (theme: Theme) => "light" | "dark";
package/lib/utils.js ADDED
@@ -0,0 +1,102 @@
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 _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
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
+
8
+ 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
+
10
+ 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; }
11
+
12
+ import "core-js/modules/es.object.to-string.js";
13
+ import "core-js/modules/es.regexp.exec.js";
14
+ import "core-js/modules/es.string.replace.js";
15
+ import "core-js/modules/web.dom-collections.for-each.js";
16
+ import { ARROW_DOWN, ARROW_UP, SPACE, ENTER } from './key-codes.js';
17
+ var DEFAULT_NO_OPTIONS_MESSAGES = {
18
+ noOptions: 'No options',
19
+ nothingFound: 'Nothing found',
20
+ loading: 'Loading...'
21
+ };
22
+ var MAX_VISIBLE_ITEMS = 5;
23
+ var ITEM_HEIGHT_BY_SIZE = {
24
+ s: 32,
25
+ m: 40,
26
+ l: 52
27
+ };
28
+
29
+ var isOptionsGroup = function isOptionsGroup(optionOrGroup) {
30
+ return typeof optionOrGroup.options !== 'undefined';
31
+ };
32
+
33
+ function shouldOpenSelect(key) {
34
+ var isTriggerTarget = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
35
+ return key === ARROW_DOWN || key === ARROW_UP || (key === SPACE || key === ENTER) && isTriggerTarget;
36
+ }
37
+
38
+ function isString(s) {
39
+ return Object.prototype.toString.call(s) === '[object String]';
40
+ }
41
+
42
+ function getEmptyMessage(isLoading, isNothingFound, noOptionsMessage) {
43
+ var _ref = isString(noOptionsMessage) ? _objectSpread(_objectSpread({}, DEFAULT_NO_OPTIONS_MESSAGES), {}, {
44
+ noOptions: noOptionsMessage
45
+ }) : _objectSpread(_objectSpread({}, DEFAULT_NO_OPTIONS_MESSAGES), noOptionsMessage),
46
+ noOptions = _ref.noOptions,
47
+ nothingFound = _ref.nothingFound,
48
+ loading = _ref.loading;
49
+
50
+ if (isLoading) {
51
+ return loading;
52
+ } else if (isNothingFound) {
53
+ return nothingFound;
54
+ } else {
55
+ return noOptions;
56
+ }
57
+ }
58
+
59
+ function escapeRegex(str) {
60
+ return str.replace(/[\-\[\]\/{}()\*+?.\\^$|]/g, '\\$&');
61
+ }
62
+
63
+ function convertToOptionGroupsIfNeeded() {
64
+ var optionsOrGroups = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
65
+ var newOptions = [];
66
+ var topLevelOptions = [];
67
+ optionsOrGroups.forEach(function (optionOrGroup) {
68
+ if (isOptionsGroup(optionOrGroup)) {
69
+ if (topLevelOptions.length) {
70
+ newOptions.push({
71
+ options: topLevelOptions
72
+ });
73
+ topLevelOptions = [];
74
+ }
75
+
76
+ newOptions.push(optionOrGroup);
77
+ } else {
78
+ topLevelOptions.push(optionOrGroup);
79
+ }
80
+ });
81
+
82
+ if (topLevelOptions.length) {
83
+ newOptions.push({
84
+ options: topLevelOptions
85
+ });
86
+ topLevelOptions = [];
87
+ }
88
+
89
+ return newOptions;
90
+ }
91
+
92
+ var calculateMaxHeight = function calculateMaxHeight(size) {
93
+ var itemHeight = ITEM_HEIGHT_BY_SIZE[size]; // half of item added to show that there is more items even if scroll bar hidden
94
+
95
+ return (Math.ceil(MAX_VISIBLE_ITEMS) + 0.5) * itemHeight;
96
+ };
97
+
98
+ var reverseTheme = function reverseTheme(theme) {
99
+ return theme === 'dark' ? 'light' : 'dark';
100
+ };
101
+
102
+ export { calculateMaxHeight, convertToOptionGroupsIfNeeded, escapeRegex, getEmptyMessage, reverseTheme, shouldOpenSelect };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@rescui/select",
3
+ "version": "0.1.1",
4
+ "description": "",
5
+ "license": "Apache-2.0",
6
+ "author": "JetBrains",
7
+ "main": "lib/index.js",
8
+ "src:main": "src/index.ts",
9
+ "files": [
10
+ "lib",
11
+ "LICENSE.txt"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "@babel/runtime-corejs3": "^7.14.0",
18
+ "@juggle/resize-observer": "3.3.0",
19
+ "@rescui/dropdown": "^0.2.4",
20
+ "@rescui/icons": "^0.6.1",
21
+ "@rescui/menu": "^0.4.0",
22
+ "@rescui/tag": "^0.3.0",
23
+ "@rescui/typography": "^0.7.0",
24
+ "classnames": "^2.2.6",
25
+ "core-js": "^3.9.1",
26
+ "just-throttle": "^4.0.1",
27
+ "scroll-into-view-if-needed": "2.2.20"
28
+ },
29
+ "peerDependencies": {
30
+ "@rescui/ui-contexts": "<1.0.0",
31
+ "prop-types": "^15.7.2",
32
+ "react": ">=16.8.0 <18"
33
+ },
34
+ "devDependencies": {
35
+ "@rescui/colors": "^0.1.0",
36
+ "@rescui/postcss-preset-library": "^0.0.4",
37
+ "@rescui/scripts": "^0.1.4",
38
+ "@rescui/visual-regression": "^0.0.1",
39
+ "postcss": "^8.3.0",
40
+ "sniffr": "^1.2.0"
41
+ },
42
+ "scripts": {
43
+ "build": "rescui-scripts build --css-modules"
44
+ },
45
+ "gitHead": "ed479e17beebb317d22ad5df6c3877886bb0ea01"
46
+ }