@salutejs/plasma-new-hope 0.175.1-dev.0 → 0.175.2-canary.1505.11553165432.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. package/cjs/components/Combobox/ComboboxNew/Combobox.js +27 -22
  2. package/cjs/components/Combobox/ComboboxNew/Combobox.js.map +1 -1
  3. package/cjs/components/Combobox/ComboboxNew/utils/getInitialValue.js +21 -0
  4. package/cjs/components/Combobox/ComboboxNew/utils/getInitialValue.js.map +1 -0
  5. package/cjs/components/Combobox/ComboboxNew/utils/initialItemsTransform.js +9 -5
  6. package/cjs/components/Combobox/ComboboxNew/utils/initialItemsTransform.js.map +1 -1
  7. package/cjs/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js +2 -2
  8. package/cjs/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js.map +1 -1
  9. package/cjs/components/Select/Select.js +13 -25
  10. package/cjs/components/Select/Select.js.map +1 -1
  11. package/cjs/components/Select/hooks/useKeyboardNavigation.js +1 -1
  12. package/cjs/components/Select/hooks/useKeyboardNavigation.js.map +1 -1
  13. package/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js +1 -1
  14. package/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js.map +1 -1
  15. package/cjs/components/Select/ui/Target/ui/Textfield/Textfield.styles.js +1 -1
  16. package/cjs/components/Select/ui/Target/ui/Textfield/Textfield.styles.js.map +1 -1
  17. package/cjs/components/Select/utils/getButtonLabel.js +1 -1
  18. package/cjs/components/Select/utils/getButtonLabel.js.map +1 -1
  19. package/cjs/components/Select/utils/getInitialValue.js +21 -0
  20. package/cjs/components/Select/utils/getInitialValue.js.map +1 -0
  21. package/cjs/components/Select/utils/initialItemsTransform.js +9 -6
  22. package/cjs/components/Select/utils/initialItemsTransform.js.map +1 -1
  23. package/emotion/cjs/components/Combobox/ComboboxNew/Combobox.js +26 -22
  24. package/emotion/cjs/components/Combobox/ComboboxNew/utils/getInitialValue.js +20 -0
  25. package/emotion/cjs/components/Combobox/ComboboxNew/utils/index.js +8 -1
  26. package/emotion/cjs/components/Combobox/ComboboxNew/utils/initialItemsTransform.js +19 -5
  27. package/emotion/cjs/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js +2 -2
  28. package/emotion/cjs/components/Select/Select.js +12 -25
  29. package/emotion/cjs/components/Select/hooks/useKeyboardNavigation.js +1 -1
  30. package/emotion/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js +1 -1
  31. package/emotion/cjs/components/Select/ui/Target/ui/Textfield/Textfield.styles.js +13 -13
  32. package/emotion/cjs/components/Select/utils/getButtonLabel.js +1 -1
  33. package/emotion/cjs/components/Select/utils/getInitialValue.js +20 -0
  34. package/emotion/cjs/components/Select/utils/index.js +8 -1
  35. package/emotion/cjs/components/Select/utils/initialItemsTransform.js +19 -6
  36. package/emotion/cjs/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +6 -0
  37. package/emotion/cjs/examples/plasma_web/components/Combobox/Combobox.stories.tsx +6 -0
  38. package/emotion/es/components/Combobox/ComboboxNew/Combobox.js +27 -23
  39. package/emotion/es/components/Combobox/ComboboxNew/utils/getInitialValue.js +14 -0
  40. package/emotion/es/components/Combobox/ComboboxNew/utils/index.js +2 -1
  41. package/emotion/es/components/Combobox/ComboboxNew/utils/initialItemsTransform.js +19 -5
  42. package/emotion/es/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js +2 -2
  43. package/emotion/es/components/Select/Select.js +13 -26
  44. package/emotion/es/components/Select/hooks/useKeyboardNavigation.js +1 -1
  45. package/emotion/es/components/Select/ui/Target/ui/Textfield/Textfield.js +1 -1
  46. package/emotion/es/components/Select/ui/Target/ui/Textfield/Textfield.styles.js +13 -13
  47. package/emotion/es/components/Select/utils/getButtonLabel.js +1 -1
  48. package/emotion/es/components/Select/utils/getInitialValue.js +14 -0
  49. package/emotion/es/components/Select/utils/index.js +2 -1
  50. package/emotion/es/components/Select/utils/initialItemsTransform.js +19 -6
  51. package/emotion/es/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +6 -0
  52. package/emotion/es/examples/plasma_web/components/Combobox/Combobox.stories.tsx +6 -0
  53. package/es/components/Combobox/ComboboxNew/Combobox.js +27 -22
  54. package/es/components/Combobox/ComboboxNew/Combobox.js.map +1 -1
  55. package/es/components/Combobox/ComboboxNew/utils/getInitialValue.js +17 -0
  56. package/es/components/Combobox/ComboboxNew/utils/getInitialValue.js.map +1 -0
  57. package/es/components/Combobox/ComboboxNew/utils/initialItemsTransform.js +9 -5
  58. package/es/components/Combobox/ComboboxNew/utils/initialItemsTransform.js.map +1 -1
  59. package/es/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js +2 -2
  60. package/es/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js.map +1 -1
  61. package/es/components/Select/Select.js +14 -26
  62. package/es/components/Select/Select.js.map +1 -1
  63. package/es/components/Select/hooks/useKeyboardNavigation.js +1 -1
  64. package/es/components/Select/hooks/useKeyboardNavigation.js.map +1 -1
  65. package/es/components/Select/ui/Target/ui/Textfield/Textfield.js +1 -1
  66. package/es/components/Select/ui/Target/ui/Textfield/Textfield.js.map +1 -1
  67. package/es/components/Select/ui/Target/ui/Textfield/Textfield.styles.js +1 -1
  68. package/es/components/Select/ui/Target/ui/Textfield/Textfield.styles.js.map +1 -1
  69. package/es/components/Select/utils/getButtonLabel.js +1 -1
  70. package/es/components/Select/utils/getButtonLabel.js.map +1 -1
  71. package/es/components/Select/utils/getInitialValue.js +17 -0
  72. package/es/components/Select/utils/getInitialValue.js.map +1 -0
  73. package/es/components/Select/utils/initialItemsTransform.js +9 -6
  74. package/es/components/Select/utils/initialItemsTransform.js.map +1 -1
  75. package/package.json +2 -2
  76. package/styled-components/cjs/components/Combobox/ComboboxNew/Combobox.js +26 -22
  77. package/styled-components/cjs/components/Combobox/ComboboxNew/utils/getInitialValue.js +20 -0
  78. package/styled-components/cjs/components/Combobox/ComboboxNew/utils/index.js +8 -1
  79. package/styled-components/cjs/components/Combobox/ComboboxNew/utils/initialItemsTransform.js +19 -5
  80. package/styled-components/cjs/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js +2 -2
  81. package/styled-components/cjs/components/Select/Select.js +12 -25
  82. package/styled-components/cjs/components/Select/hooks/useKeyboardNavigation.js +1 -1
  83. package/styled-components/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js +1 -1
  84. package/styled-components/cjs/components/Select/ui/Target/ui/Textfield/Textfield.styles.js +1 -1
  85. package/styled-components/cjs/components/Select/utils/getButtonLabel.js +1 -1
  86. package/styled-components/cjs/components/Select/utils/getInitialValue.js +20 -0
  87. package/styled-components/cjs/components/Select/utils/index.js +8 -1
  88. package/styled-components/cjs/components/Select/utils/initialItemsTransform.js +19 -6
  89. package/styled-components/cjs/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +6 -0
  90. package/styled-components/cjs/examples/plasma_web/components/Combobox/Combobox.stories.tsx +6 -0
  91. package/styled-components/es/components/Combobox/ComboboxNew/Combobox.js +27 -23
  92. package/styled-components/es/components/Combobox/ComboboxNew/utils/getInitialValue.js +14 -0
  93. package/styled-components/es/components/Combobox/ComboboxNew/utils/index.js +2 -1
  94. package/styled-components/es/components/Combobox/ComboboxNew/utils/initialItemsTransform.js +19 -5
  95. package/styled-components/es/components/Pagination/ui/PaginationSelectPerPage/PaginationSelectPerPage.js +2 -2
  96. package/styled-components/es/components/Select/Select.js +13 -26
  97. package/styled-components/es/components/Select/hooks/useKeyboardNavigation.js +1 -1
  98. package/styled-components/es/components/Select/ui/Target/ui/Textfield/Textfield.js +1 -1
  99. package/styled-components/es/components/Select/ui/Target/ui/Textfield/Textfield.styles.js +1 -1
  100. package/styled-components/es/components/Select/utils/getButtonLabel.js +1 -1
  101. package/styled-components/es/components/Select/utils/getInitialValue.js +14 -0
  102. package/styled-components/es/components/Select/utils/index.js +2 -1
  103. package/styled-components/es/components/Select/utils/initialItemsTransform.js +19 -6
  104. package/styled-components/es/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +6 -0
  105. package/styled-components/es/examples/plasma_web/components/Combobox/Combobox.stories.tsx +6 -0
  106. package/types/components/Combobox/ComboboxNew/Combobox.d.ts.map +1 -1
  107. package/types/components/Combobox/ComboboxNew/Combobox.types.d.ts +14 -3
  108. package/types/components/Combobox/ComboboxNew/Combobox.types.d.ts.map +1 -1
  109. package/types/components/Combobox/ComboboxNew/utils/getInitialValue.d.ts +4 -0
  110. package/types/components/Combobox/ComboboxNew/utils/getInitialValue.d.ts.map +1 -0
  111. package/types/components/Combobox/ComboboxNew/utils/index.d.ts +1 -0
  112. package/types/components/Combobox/ComboboxNew/utils/index.d.ts.map +1 -1
  113. package/types/components/Combobox/ComboboxNew/utils/initialItemsTransform.d.ts.map +1 -1
  114. package/types/components/Select/Select.d.ts.map +1 -1
  115. package/types/components/Select/Select.types.d.ts +1 -0
  116. package/types/components/Select/Select.types.d.ts.map +1 -1
  117. package/types/components/Select/hooks/useKeyboardNavigation.d.ts +2 -2
  118. package/types/components/Select/hooks/useKeyboardNavigation.d.ts.map +1 -1
  119. package/types/components/Select/ui/Target/Target.types.d.ts +2 -2
  120. package/types/components/Select/ui/Target/Target.types.d.ts.map +1 -1
  121. package/types/components/Select/ui/Target/ui/Textfield/Textfield.styles.d.ts +4 -4
  122. package/types/components/Select/ui/Target/ui/Textfield/Textfield.styles.d.ts.map +1 -1
  123. package/types/components/Select/utils/getInitialValue.d.ts +4 -0
  124. package/types/components/Select/utils/getInitialValue.d.ts.map +1 -0
  125. package/types/components/Select/utils/index.d.ts +1 -0
  126. package/types/components/Select/utils/index.d.ts.map +1 -1
  127. package/types/components/Select/utils/initialItemsTransform.d.ts.map +1 -1
  128. package/types/examples/plasma_b2c/components/Combobox/Combobox.d.ts +30 -6
  129. package/types/examples/plasma_b2c/components/Combobox/Combobox.d.ts.map +1 -1
  130. package/types/examples/plasma_web/components/Combobox/Combobox.d.ts +30 -6
  131. package/types/examples/plasma_web/components/Combobox/Combobox.d.ts.map +1 -1
@@ -22,7 +22,7 @@ var getButtonLabel = exports.getButtonLabel = function getButtonLabel(_ref3) {
22
22
  if ((0, _utils.isEmpty)(value) && typeof value !== 'number') {
23
23
  return label || '';
24
24
  }
25
- if (selectProps.multiselect && selectProps.isTargetAmount) {
25
+ if (selectProps.multiselect && Array.isArray(value) && selectProps.isTargetAmount) {
26
26
  return "\u0412\u044B\u0431\u0440\u0430\u043D\u043E: ".concat(value.length);
27
27
  }
28
28
  if (selectProps.multiselect && Array.isArray(value)) {
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getInitialValue = void 0;
7
+ // Утилита предназначена для фильтрации элементов в value, которые отсутствуют в items.
8
+ // Эти элементы игнорируются и не участвуют в дальнейшей работе компонента.
9
+ var getInitialValue = exports.getInitialValue = function getInitialValue(outerValue, valueToItemMap) {
10
+ if (Array.isArray(outerValue)) {
11
+ if (outerValue.length === 0) {
12
+ return [];
13
+ }
14
+ return outerValue.filter(valueToItemMap.has.bind(valueToItemMap));
15
+ }
16
+ if (valueToItemMap.has(outerValue)) {
17
+ return outerValue;
18
+ }
19
+ return '';
20
+ };
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "getCorrectHeight", {
15
15
  return _getCorrectHeight.getCorrectHeight;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "getInitialValue", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _getInitialValue.getInitialValue;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "getView", {
19
25
  enumerable: true,
20
26
  get: function get() {
@@ -58,4 +64,5 @@ var _updateSingleAncestors = /*#__PURE__*/require("./updateSingleAncestors");
58
64
  var _sizeToIconSize = /*#__PURE__*/require("./sizeToIconSize");
59
65
  var _getCorrectHeight = /*#__PURE__*/require("./getCorrectHeight");
60
66
  var _getButtonLabel = /*#__PURE__*/require("./getButtonLabel");
61
- var _getView = /*#__PURE__*/require("./getView");
67
+ var _getView = /*#__PURE__*/require("./getView");
68
+ var _getInitialValue = /*#__PURE__*/require("./getInitialValue");
@@ -1,18 +1,31 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.initialItemsTransform = void 0;
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
14
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
18
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
19
  // Проходимся по массиву items и добавляем в каждый item ключ parent, который ссылается на item родителя.
8
20
  // Дает возможность прохода к корневому элементу (снизу вверх).
9
-
21
+ // На выходе получаем глубокую копию исходного массива items.
10
22
  var initialItemsTransform = exports.initialItemsTransform = function initialItemsTransform(items, parent) {
11
- items.forEach(function (item) {
12
- item.parent = parent;
13
- if (item.items) {
14
- item.items = initialItemsTransform(item.items, item);
23
+ return _toConsumableArray(items).map(function (item) {
24
+ var itemCopy = _objectSpread({}, item);
25
+ itemCopy.parent = parent;
26
+ if (itemCopy.items) {
27
+ itemCopy.items = initialItemsTransform(itemCopy.items, itemCopy);
15
28
  }
29
+ return itemCopy;
16
30
  });
17
- return items;
18
31
  };
@@ -68,6 +68,10 @@ const meta: Meta<StorySelectProps> = {
68
68
  control: { type: 'boolean' },
69
69
  if: { arg: 'alwaysOpened', truthy: false },
70
70
  },
71
+ targetAmount: {
72
+ control: { type: 'number' },
73
+ if: { arg: 'isTargetAmount', truthy: true },
74
+ },
71
75
  },
72
76
  args: {
73
77
  label: 'Label',
@@ -78,6 +82,7 @@ const meta: Meta<StorySelectProps> = {
78
82
  view: 'default',
79
83
  enableContentLeft: false,
80
84
  isTargetAmount: false,
85
+ targetAmount: undefined,
81
86
  variant: 'normal',
82
87
  alwaysOpened: false,
83
88
  disabled: false,
@@ -94,6 +99,7 @@ const meta: Meta<StorySelectProps> = {
94
99
  'placeholder',
95
100
  'helperText',
96
101
  'isTargetAmount',
102
+ 'targetAmount',
97
103
  'closeAfterSelect',
98
104
  'alwaysOpened',
99
105
  'variant',
@@ -68,6 +68,10 @@ const meta: Meta<StorySelectProps> = {
68
68
  control: { type: 'boolean' },
69
69
  if: { arg: 'alwaysOpened', truthy: false },
70
70
  },
71
+ targetAmount: {
72
+ control: { type: 'number' },
73
+ if: { arg: 'isTargetAmount', truthy: true },
74
+ },
71
75
  },
72
76
  args: {
73
77
  label: 'Label',
@@ -78,6 +82,7 @@ const meta: Meta<StorySelectProps> = {
78
82
  view: 'default',
79
83
  enableContentLeft: false,
80
84
  isTargetAmount: false,
85
+ targetAmount: undefined,
81
86
  variant: 'normal',
82
87
  alwaysOpened: false,
83
88
  disabled: false,
@@ -94,6 +99,7 @@ const meta: Meta<StorySelectProps> = {
94
99
  'placeholder',
95
100
  'helperText',
96
101
  'isTargetAmount',
102
+ 'targetAmount',
97
103
  'closeAfterSelect',
98
104
  'alwaysOpened',
99
105
  'variant',
@@ -1,4 +1,4 @@
1
- var _excluded = ["multiple", "value", "onChange", "isTargetAmount", "items", "placement", "label", "placeholder", "helperText", "contentLeft", "textBefore", "textAfter", "variant", "listOverflow", "listHeight", "listWidth", "portal", "renderItem", "view", "size", "labelPlacement", "readOnly", "disabled", "alwaysOpened", "filter", "closeAfterSelect"];
1
+ var _excluded = ["multiple", "value", "onChange", "isTargetAmount", "targetAmount", "items", "placement", "label", "placeholder", "helperText", "contentLeft", "textBefore", "textAfter", "variant", "listOverflow", "listHeight", "listWidth", "portal", "renderItem", "view", "size", "labelPlacement", "readOnly", "disabled", "alwaysOpened", "filter", "closeAfterSelect", "renderValue"];
2
2
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
3
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
4
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -16,7 +16,7 @@ import { sizeToIconSize } from '../../Select/utils';
16
16
  import { classes } from './Combobox.tokens';
17
17
  import { FloatingPopover } from './FloatingPopover';
18
18
  import { useKeyNavigation, getItemByFocused } from './hooks/useKeyboardNavigation';
19
- import { initialItemsTransform, updateAncestors, updateDescendants, updateSingleAncestors, filterItems, getItemId } from './utils';
19
+ import { initialItemsTransform, updateAncestors, updateDescendants, updateSingleAncestors, filterItems, getItemId, getInitialValue } from './utils';
20
20
  import { Inner, StyledTextField } from './ui';
21
21
  import { pathReducer, focusedPathReducer } from './reducers';
22
22
  import { getPathMap, getTreeMaps } from './hooks/getPathMaps';
@@ -35,6 +35,7 @@ export var comboboxRoot = function comboboxRoot(Root) {
35
35
  outerValue = props.value,
36
36
  outerOnChange = props.onChange,
37
37
  isTargetAmount = props.isTargetAmount,
38
+ targetAmount = props.targetAmount,
38
39
  items = props.items,
39
40
  _props$placement = props.placement,
40
41
  placement = _props$placement === void 0 ? 'bottom-start' : _props$placement,
@@ -62,10 +63,15 @@ export var comboboxRoot = function comboboxRoot(Root) {
62
63
  alwaysOpened = _props$alwaysOpened === void 0 ? false : _props$alwaysOpened,
63
64
  filter = props.filter,
64
65
  outerCloseAfterSelect = props.closeAfterSelect,
66
+ renderValue = props.renderValue,
65
67
  rest = _objectWithoutProperties(props, _excluded);
68
+ var transformedItems = useMemo(function () {
69
+ return initialItemsTransform(items || []);
70
+ }, [items]);
71
+
66
72
  // Создаем структуры для быстрой работы с деревом
67
73
  var _useMemo = useMemo(function () {
68
- return getTreeMaps(items);
74
+ return getTreeMaps(transformedItems);
69
75
  }, [items]),
70
76
  _useMemo2 = _slicedToArray(_useMemo, 3),
71
77
  valueToCheckedMap = _useMemo2[0],
@@ -79,14 +85,11 @@ export var comboboxRoot = function comboboxRoot(Root) {
79
85
  _useState4 = _slicedToArray(_useState3, 2),
80
86
  internalValue = _useState4[0],
81
87
  setInternalValue = _useState4[1];
82
- var value = outerValue || internalValue;
88
+ var value = outerValue !== null && outerValue !== undefined ? getInitialValue(outerValue, valueToItemMap) : internalValue;
83
89
  var inputRef = useRef(null);
84
90
  var floatingPopoverRef = useRef(null);
85
91
  var inputForkRef = useForkRef(inputRef, ref);
86
92
  var treeId = safeUseId();
87
- var transformedItems = useMemo(function () {
88
- return initialItemsTransform(items || []);
89
- }, [items]);
90
93
  var filteredItems = filterItems(transformedItems, textValue, (_valueToItemMap$get2 = valueToItemMap.get(value)) === null || _valueToItemMap$get2 === void 0 ? void 0 : _valueToItemMap$get2.label, filter);
91
94
  var _useMemo3 = useMemo(function () {
92
95
  return getPathMap(filteredItems);
@@ -253,16 +256,7 @@ export var comboboxRoot = function comboboxRoot(Root) {
253
256
  if (e) {
254
257
  e.stopPropagation();
255
258
  }
256
- var checkedCopy = new Map(checked);
257
- var isCurrentChecked = checkedCopy.get(item.value);
258
- checkedCopy.forEach(function (_, key) {
259
- checkedCopy.set(key, false);
260
- });
261
- if (!isCurrentChecked) {
262
- checkedCopy.set(item.value, 'done');
263
- updateSingleAncestors(item, checkedCopy, 'dot');
264
- }
265
- setTextValue(isCurrentChecked ? '' : item.label);
259
+ var isCurrentChecked = checked.get(item.value);
266
260
  if (!alwaysOpened && closeAfterSelect) {
267
261
  dispatchPath({
268
262
  type: 'reset'
@@ -276,14 +270,18 @@ export var comboboxRoot = function comboboxRoot(Root) {
276
270
  }
277
271
  };
278
272
  var getChips = function getChips() {
279
- if (multiple) {
273
+ if (multiple && Array.isArray(value)) {
280
274
  if (value.length === 0) return [];
281
275
  if (isTargetAmount) {
282
- return ["\u0412\u044B\u0431\u0440\u0430\u043D\u043E ".concat(value.length)];
276
+ return ["\u0412\u044B\u0431\u0440\u0430\u043D\u043E ".concat(targetAmount || value.length)];
283
277
  }
284
- return value.map(function (value) {
285
- return valueToItemMap.get(value).label;
286
- });
278
+ var renderValueMapper = renderValue && function (stringValue) {
279
+ return renderValue(valueToItemMap.get(stringValue));
280
+ };
281
+ var valueToItemMapper = function valueToItemMapper(stringValue) {
282
+ return valueToItemMap.get(stringValue).label;
283
+ };
284
+ return value.map(renderValueMapper || valueToItemMapper);
287
285
  }
288
286
  return [];
289
287
  };
@@ -311,6 +309,7 @@ export var comboboxRoot = function comboboxRoot(Root) {
311
309
  // В данном эффекте мы следим за изменениями value снаружи и вносим коррективы в дерево чекбоксов.
312
310
  // Пример: когда юзер очистил value извне, тогда нужно пройтись по элементам и выключить все чекбоксы.
313
311
  useLayoutEffect(function () {
312
+ var _valueToItemMap$get4;
314
313
  var checkedCopy = new Map(checked);
315
314
  checkedCopy.forEach(function (_, key) {
316
315
  checkedCopy.set(key, false);
@@ -328,7 +327,12 @@ export var comboboxRoot = function comboboxRoot(Root) {
328
327
  }
329
328
  }
330
329
  setChecked(checkedCopy);
331
- }, [value]);
330
+ setTextValue(((_valueToItemMap$get4 = valueToItemMap.get(outerValue)) === null || _valueToItemMap$get4 === void 0 ? void 0 : _valueToItemMap$get4.label) || '');
331
+
332
+ // В deps мы кладем именно outerValue и internalValue, а не просто value.
333
+ // Т.к. вначале нужно отфильтровать и провалидировать outerValue и результат положить в переменную.
334
+ // А переменную, содержащую сложные типы данных, нельзя помещать в deps.
335
+ }, [outerValue, internalValue, items]);
332
336
  return /*#__PURE__*/React.createElement(Root, {
333
337
  size: size,
334
338
  view: view,
@@ -0,0 +1,14 @@
1
+ // Утилита предназначена для фильтрации элементов в value, которые отсутствуют в items.
2
+ // Эти элементы игнорируются и не участвуют в дальнейшей работе компонента.
3
+ export var getInitialValue = function getInitialValue(outerValue, valueToItemMap) {
4
+ if (Array.isArray(outerValue)) {
5
+ if (outerValue.length === 0) {
6
+ return [];
7
+ }
8
+ return outerValue.filter(valueToItemMap.has.bind(valueToItemMap));
9
+ }
10
+ if (valueToItemMap.has(outerValue)) {
11
+ return outerValue;
12
+ }
13
+ return '';
14
+ };
@@ -4,4 +4,5 @@ export { updateAncestors } from './updateAncestors';
4
4
  export { updateSingleAncestors } from './updateSingleAncestors';
5
5
  export { sizeToIconSize } from './sizeToIconSize';
6
6
  export { filterItems } from './filterItems';
7
- export { getItemId } from './getItemId';
7
+ export { getItemId } from './getItemId';
8
+ export { getInitialValue } from './getInitialValue';
@@ -1,11 +1,25 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
13
  // Проходимся по массиву items и добавляем в каждый item ключ parent, который ссылается на item родителя.
2
14
  // Дает возможность прохода к корневому элементу (снизу вверх).
15
+ // На выходе получаем глубокую копию исходного массива items.
3
16
  export var initialItemsTransform = function initialItemsTransform(items, parent) {
4
- items.forEach(function (item) {
5
- item.parent = parent;
6
- if (item.items) {
7
- item.items = initialItemsTransform(item.items, item);
17
+ return _toConsumableArray(items).map(function (item) {
18
+ var itemCopy = _objectSpread({}, item);
19
+ itemCopy.parent = parent;
20
+ if (itemCopy.items) {
21
+ itemCopy.items = initialItemsTransform(itemCopy.items, itemCopy);
8
22
  }
23
+ return itemCopy;
9
24
  });
10
- return items;
11
25
  };
@@ -17,8 +17,8 @@ export var PaginationSelectPerPage = function PaginationSelectPerPage(_ref) {
17
17
  listWidth = _ref.listWidth,
18
18
  rest = _objectWithoutProperties(_ref, _excluded);
19
19
  var handleSelectChange = function handleSelectChange(newValue) {
20
- if (newValue) {
21
- onChangeValue === null || onChangeValue === void 0 || onChangeValue(Number(newValue));
20
+ if (newValue && !Array.isArray(newValue) && onChangeValue) {
21
+ onChangeValue(Number(newValue));
22
22
  }
23
23
  };
24
24
  var transformedList = perPageList.map(function (num) {
@@ -12,7 +12,7 @@ import React, { forwardRef, useState, useReducer, useMemo, createContext, useLay
12
12
  import { isEmpty, getPlacements } from '../../utils';
13
13
  import { useOutsideClick } from '../../hooks';
14
14
  import { useKeyNavigation } from './hooks/useKeyboardNavigation';
15
- import { initialItemsTransform, updateAncestors, updateDescendants, updateSingleAncestors, getView } from './utils';
15
+ import { initialItemsTransform, updateAncestors, updateDescendants, updateSingleAncestors, getView, getInitialValue } from './utils';
16
16
  import { Inner, Target } from './ui';
17
17
  import { pathReducer, focusedPathReducer, focusedChipIndexReducer } from './reducers';
18
18
  import { usePathMaps } from './hooks/usePathMaps';
@@ -58,17 +58,6 @@ export var selectRoot = function selectRoot(Root) {
58
58
  separator = props.separator,
59
59
  outerCloseAfterSelect = props.closeAfterSelect,
60
60
  rest = _objectWithoutProperties(props, _excluded);
61
- var _useState = useState(outerValue || props.multiselect ? [] : ''),
62
- _useState2 = _slicedToArray(_useState, 2),
63
- internalValue = _useState2[0],
64
- setInternalValue = _useState2[1];
65
- var value = outerValue || internalValue;
66
- var onChange = function onChange(e) {
67
- if (outerOnChange) {
68
- outerOnChange(e);
69
- }
70
- setInternalValue(e);
71
- };
72
61
  var transformedItems = useMemo(function () {
73
62
  return initialItemsTransform(items || []);
74
63
  }, [items]);
@@ -78,6 +67,12 @@ export var selectRoot = function selectRoot(Root) {
78
67
  focusedToValueMap = _usePathMaps2[1],
79
68
  valueToCheckedMap = _usePathMaps2[2],
80
69
  valueToItemMap = _usePathMaps2[3];
70
+ var value = getInitialValue(outerValue, valueToItemMap);
71
+ var onChange = function onChange(e) {
72
+ if (outerOnChange) {
73
+ outerOnChange(e);
74
+ }
75
+ };
81
76
  var _useReducer = useReducer(pathReducer, []),
82
77
  _useReducer2 = _slicedToArray(_useReducer, 2),
83
78
  path = _useReducer2[0],
@@ -90,10 +85,10 @@ export var selectRoot = function selectRoot(Root) {
90
85
  _useReducer6 = _slicedToArray(_useReducer5, 2),
91
86
  focusedChipIndex = _useReducer6[0],
92
87
  dispatchFocusedChipIndex = _useReducer6[1];
93
- var _useState3 = useState(valueToCheckedMap),
94
- _useState4 = _slicedToArray(_useState3, 2),
95
- checked = _useState4[0],
96
- setChecked = _useState4[1];
88
+ var _useState = useState(valueToCheckedMap),
89
+ _useState2 = _slicedToArray(_useState, 2),
90
+ checked = _useState2[0],
91
+ setChecked = _useState2[1];
97
92
  var closeAfterSelect = outerCloseAfterSelect !== null && outerCloseAfterSelect !== void 0 ? outerCloseAfterSelect : !props.multiselect;
98
93
  var targetRef = useOutsideClick(function () {
99
94
  if (focusedChipIndex != null) {
@@ -159,15 +154,7 @@ export var selectRoot = function selectRoot(Root) {
159
154
  if (e) {
160
155
  e.stopPropagation();
161
156
  }
162
- var checkedCopy = new Map(checked);
163
- var isCurrentChecked = checkedCopy.get(item.value);
164
- checkedCopy.forEach(function (_, key) {
165
- checkedCopy.set(key, false);
166
- });
167
- if (!isCurrentChecked) {
168
- checkedCopy.set(item.value, 'done');
169
- updateSingleAncestors(item, checkedCopy, 'dot');
170
- }
157
+ var isCurrentChecked = checked.get(item.value);
171
158
  if (closeAfterSelect) {
172
159
  dispatchPath({
173
160
  type: 'reset'
@@ -239,7 +226,7 @@ export var selectRoot = function selectRoot(Root) {
239
226
  }
240
227
  }
241
228
  setChecked(checkedCopy);
242
- }, [value]);
229
+ }, [outerValue, items]);
243
230
  return /*#__PURE__*/React.createElement(Root, _extends({
244
231
  ref: ref,
245
232
  size: size,
@@ -153,7 +153,7 @@ export var useKeyNavigation = function useKeyNavigation(_ref) {
153
153
  }
154
154
  case keys.Backspace:
155
155
  {
156
- if (!multiselect) break;
156
+ if (!multiselect || !Array.isArray(value)) break;
157
157
  if (focusedChipIndex !== null) {
158
158
  var _currentItem = valueToItemMap.get(value[focusedChipIndex]);
159
159
  handlePressDown(_currentItem);
@@ -34,7 +34,7 @@ var getLabel = function getLabel(_ref) {
34
34
  text: renderValue ? renderValue(valueToItemMap.get(currentValue)) : itemLabel,
35
35
  onClick: function onClick(e) {
36
36
  e.stopPropagation();
37
- onChipClick(currentValue);
37
+ onChipClick(currentValue.toString());
38
38
  },
39
39
  focused: focusedChipIndex === index
40
40
  });