@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
@@ -20,7 +20,7 @@ var _getPathMaps = /*#__PURE__*/require("./hooks/getPathMaps");
20
20
  var _Combobox2 = /*#__PURE__*/require("./Combobox.styles");
21
21
  var _base = /*#__PURE__*/require("./variations/_view/base");
22
22
  var _base2 = /*#__PURE__*/require("./variations/_size/base");
23
- 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"];
23
+ 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"];
24
24
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
25
25
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
26
26
  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); }
@@ -44,6 +44,7 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
44
44
  outerValue = props.value,
45
45
  outerOnChange = props.onChange,
46
46
  isTargetAmount = props.isTargetAmount,
47
+ targetAmount = props.targetAmount,
47
48
  items = props.items,
48
49
  _props$placement = props.placement,
49
50
  placement = _props$placement === void 0 ? 'bottom-start' : _props$placement,
@@ -71,10 +72,15 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
71
72
  alwaysOpened = _props$alwaysOpened === void 0 ? false : _props$alwaysOpened,
72
73
  filter = props.filter,
73
74
  outerCloseAfterSelect = props.closeAfterSelect,
75
+ renderValue = props.renderValue,
74
76
  rest = _objectWithoutProperties(props, _excluded);
77
+ var transformedItems = (0, _react.useMemo)(function () {
78
+ return (0, _utils3.initialItemsTransform)(items || []);
79
+ }, [items]);
80
+
75
81
  // Создаем структуры для быстрой работы с деревом
76
82
  var _useMemo = (0, _react.useMemo)(function () {
77
- return (0, _getPathMaps.getTreeMaps)(items);
83
+ return (0, _getPathMaps.getTreeMaps)(transformedItems);
78
84
  }, [items]),
79
85
  _useMemo2 = _slicedToArray(_useMemo, 3),
80
86
  valueToCheckedMap = _useMemo2[0],
@@ -88,14 +94,11 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
88
94
  _useState4 = _slicedToArray(_useState3, 2),
89
95
  internalValue = _useState4[0],
90
96
  setInternalValue = _useState4[1];
91
- var value = outerValue || internalValue;
97
+ var value = outerValue !== null && outerValue !== undefined ? (0, _utils3.getInitialValue)(outerValue, valueToItemMap) : internalValue;
92
98
  var inputRef = (0, _react.useRef)(null);
93
99
  var floatingPopoverRef = (0, _react.useRef)(null);
94
100
  var inputForkRef = (0, _plasmaCore.useForkRef)(inputRef, ref);
95
101
  var treeId = (0, _plasmaCore.safeUseId)();
96
- var transformedItems = (0, _react.useMemo)(function () {
97
- return (0, _utils3.initialItemsTransform)(items || []);
98
- }, [items]);
99
102
  var filteredItems = (0, _utils3.filterItems)(transformedItems, textValue, (_valueToItemMap$get2 = valueToItemMap.get(value)) === null || _valueToItemMap$get2 === void 0 ? void 0 : _valueToItemMap$get2.label, filter);
100
103
  var _useMemo3 = (0, _react.useMemo)(function () {
101
104
  return (0, _getPathMaps.getPathMap)(filteredItems);
@@ -262,16 +265,7 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
262
265
  if (e) {
263
266
  e.stopPropagation();
264
267
  }
265
- var checkedCopy = new Map(checked);
266
- var isCurrentChecked = checkedCopy.get(item.value);
267
- checkedCopy.forEach(function (_, key) {
268
- checkedCopy.set(key, false);
269
- });
270
- if (!isCurrentChecked) {
271
- checkedCopy.set(item.value, 'done');
272
- (0, _utils3.updateSingleAncestors)(item, checkedCopy, 'dot');
273
- }
274
- setTextValue(isCurrentChecked ? '' : item.label);
268
+ var isCurrentChecked = checked.get(item.value);
275
269
  if (!alwaysOpened && closeAfterSelect) {
276
270
  dispatchPath({
277
271
  type: 'reset'
@@ -285,14 +279,18 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
285
279
  }
286
280
  };
287
281
  var getChips = function getChips() {
288
- if (multiple) {
282
+ if (multiple && Array.isArray(value)) {
289
283
  if (value.length === 0) return [];
290
284
  if (isTargetAmount) {
291
- return ["\u0412\u044B\u0431\u0440\u0430\u043D\u043E ".concat(value.length)];
285
+ return ["\u0412\u044B\u0431\u0440\u0430\u043D\u043E ".concat(targetAmount || value.length)];
292
286
  }
293
- return value.map(function (value) {
294
- return valueToItemMap.get(value).label;
295
- });
287
+ var renderValueMapper = renderValue && function (stringValue) {
288
+ return renderValue(valueToItemMap.get(stringValue));
289
+ };
290
+ var valueToItemMapper = function valueToItemMapper(stringValue) {
291
+ return valueToItemMap.get(stringValue).label;
292
+ };
293
+ return value.map(renderValueMapper || valueToItemMapper);
296
294
  }
297
295
  return [];
298
296
  };
@@ -320,6 +318,7 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
320
318
  // В данном эффекте мы следим за изменениями value снаружи и вносим коррективы в дерево чекбоксов.
321
319
  // Пример: когда юзер очистил value извне, тогда нужно пройтись по элементам и выключить все чекбоксы.
322
320
  (0, _react.useLayoutEffect)(function () {
321
+ var _valueToItemMap$get4;
323
322
  var checkedCopy = new Map(checked);
324
323
  checkedCopy.forEach(function (_, key) {
325
324
  checkedCopy.set(key, false);
@@ -337,7 +336,12 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
337
336
  }
338
337
  }
339
338
  setChecked(checkedCopy);
340
- }, [value]);
339
+ setTextValue(((_valueToItemMap$get4 = valueToItemMap.get(outerValue)) === null || _valueToItemMap$get4 === void 0 ? void 0 : _valueToItemMap$get4.label) || '');
340
+
341
+ // В deps мы кладем именно outerValue и internalValue, а не просто value.
342
+ // Т.к. вначале нужно отфильтровать и провалидировать outerValue и результат положить в переменную.
343
+ // А переменную, содержащую сложные типы данных, нельзя помещать в deps.
344
+ }, [outerValue, internalValue, items]);
341
345
  return /*#__PURE__*/_react["default"].createElement(Root, {
342
346
  size: size,
343
347
  view: view,
@@ -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
+ };
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "filterItems", {
9
9
  return _filterItems.filterItems;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "getInitialValue", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _getInitialValue.getInitialValue;
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "getItemId", {
13
19
  enumerable: true,
14
20
  get: function get() {
@@ -51,4 +57,5 @@ var _updateAncestors = /*#__PURE__*/require("./updateAncestors");
51
57
  var _updateSingleAncestors = /*#__PURE__*/require("./updateSingleAncestors");
52
58
  var _sizeToIconSize = /*#__PURE__*/require("./sizeToIconSize");
53
59
  var _filterItems = /*#__PURE__*/require("./filterItems");
54
- var _getItemId = /*#__PURE__*/require("./getItemId");
60
+ var _getItemId = /*#__PURE__*/require("./getItemId");
61
+ var _getInitialValue = /*#__PURE__*/require("./getInitialValue");
@@ -1,17 +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
  // Дает возможность прохода к корневому элементу (снизу вверх).
21
+ // На выходе получаем глубокую копию исходного массива items.
9
22
  var initialItemsTransform = exports.initialItemsTransform = function initialItemsTransform(items, parent) {
10
- items.forEach(function (item) {
11
- item.parent = parent;
12
- if (item.items) {
13
- 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);
14
28
  }
29
+ return itemCopy;
15
30
  });
16
- return items;
17
31
  };
@@ -24,8 +24,8 @@ var PaginationSelectPerPage = exports.PaginationSelectPerPage = function Paginat
24
24
  listWidth = _ref.listWidth,
25
25
  rest = _objectWithoutProperties(_ref, _excluded);
26
26
  var handleSelectChange = function handleSelectChange(newValue) {
27
- if (newValue) {
28
- onChangeValue === null || onChangeValue === void 0 || onChangeValue(Number(newValue));
27
+ if (newValue && !Array.isArray(newValue) && onChangeValue) {
28
+ onChangeValue(Number(newValue));
29
29
  }
30
30
  };
31
31
  var transformedList = perPageList.map(function (num) {
@@ -67,17 +67,6 @@ var selectRoot = exports.selectRoot = function selectRoot(Root) {
67
67
  separator = props.separator,
68
68
  outerCloseAfterSelect = props.closeAfterSelect,
69
69
  rest = _objectWithoutProperties(props, _excluded);
70
- var _useState = (0, _react.useState)(outerValue || props.multiselect ? [] : ''),
71
- _useState2 = _slicedToArray(_useState, 2),
72
- internalValue = _useState2[0],
73
- setInternalValue = _useState2[1];
74
- var value = outerValue || internalValue;
75
- var onChange = function onChange(e) {
76
- if (outerOnChange) {
77
- outerOnChange(e);
78
- }
79
- setInternalValue(e);
80
- };
81
70
  var transformedItems = (0, _react.useMemo)(function () {
82
71
  return (0, _utils2.initialItemsTransform)(items || []);
83
72
  }, [items]);
@@ -87,6 +76,12 @@ var selectRoot = exports.selectRoot = function selectRoot(Root) {
87
76
  focusedToValueMap = _usePathMaps2[1],
88
77
  valueToCheckedMap = _usePathMaps2[2],
89
78
  valueToItemMap = _usePathMaps2[3];
79
+ var value = (0, _utils2.getInitialValue)(outerValue, valueToItemMap);
80
+ var onChange = function onChange(e) {
81
+ if (outerOnChange) {
82
+ outerOnChange(e);
83
+ }
84
+ };
90
85
  var _useReducer = (0, _react.useReducer)(_reducers.pathReducer, []),
91
86
  _useReducer2 = _slicedToArray(_useReducer, 2),
92
87
  path = _useReducer2[0],
@@ -99,10 +94,10 @@ var selectRoot = exports.selectRoot = function selectRoot(Root) {
99
94
  _useReducer6 = _slicedToArray(_useReducer5, 2),
100
95
  focusedChipIndex = _useReducer6[0],
101
96
  dispatchFocusedChipIndex = _useReducer6[1];
102
- var _useState3 = (0, _react.useState)(valueToCheckedMap),
103
- _useState4 = _slicedToArray(_useState3, 2),
104
- checked = _useState4[0],
105
- setChecked = _useState4[1];
97
+ var _useState = (0, _react.useState)(valueToCheckedMap),
98
+ _useState2 = _slicedToArray(_useState, 2),
99
+ checked = _useState2[0],
100
+ setChecked = _useState2[1];
106
101
  var closeAfterSelect = outerCloseAfterSelect !== null && outerCloseAfterSelect !== void 0 ? outerCloseAfterSelect : !props.multiselect;
107
102
  var targetRef = (0, _hooks.useOutsideClick)(function () {
108
103
  if (focusedChipIndex != null) {
@@ -168,15 +163,7 @@ var selectRoot = exports.selectRoot = function selectRoot(Root) {
168
163
  if (e) {
169
164
  e.stopPropagation();
170
165
  }
171
- var checkedCopy = new Map(checked);
172
- var isCurrentChecked = checkedCopy.get(item.value);
173
- checkedCopy.forEach(function (_, key) {
174
- checkedCopy.set(key, false);
175
- });
176
- if (!isCurrentChecked) {
177
- checkedCopy.set(item.value, 'done');
178
- (0, _utils2.updateSingleAncestors)(item, checkedCopy, 'dot');
179
- }
166
+ var isCurrentChecked = checked.get(item.value);
180
167
  if (closeAfterSelect) {
181
168
  dispatchPath({
182
169
  type: 'reset'
@@ -248,7 +235,7 @@ var selectRoot = exports.selectRoot = function selectRoot(Root) {
248
235
  }
249
236
  }
250
237
  setChecked(checkedCopy);
251
- }, [value]);
238
+ }, [outerValue, items]);
252
239
  return /*#__PURE__*/_react["default"].createElement(Root, _extends({
253
240
  ref: ref,
254
241
  size: size,
@@ -159,7 +159,7 @@ var useKeyNavigation = exports.useKeyNavigation = function useKeyNavigation(_ref
159
159
  }
160
160
  case keys.Backspace:
161
161
  {
162
- if (!multiselect) break;
162
+ if (!multiselect || !Array.isArray(value)) break;
163
163
  if (focusedChipIndex !== null) {
164
164
  var _currentItem = valueToItemMap.get(value[focusedChipIndex]);
165
165
  handlePressDown(_currentItem);
@@ -41,7 +41,7 @@ var getLabel = function getLabel(_ref) {
41
41
  text: renderValue ? renderValue(valueToItemMap.get(currentValue)) : itemLabel,
42
42
  onClick: function onClick(e) {
43
43
  e.stopPropagation();
44
- onChipClick(currentValue);
44
+ onChipClick(currentValue.toString());
45
45
  },
46
46
  focused: focusedChipIndex === index
47
47
  });