@salutejs/plasma-new-hope 0.193.1-canary.1562.11858039838.0 → 0.194.0-canary.1552.11858023676.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. package/cjs/components/Combobox/ComboboxNew/Combobox.css +2 -0
  2. package/cjs/components/Combobox/ComboboxNew/Combobox.js +42 -24
  3. package/cjs/components/Combobox/ComboboxNew/Combobox.js.map +1 -1
  4. package/cjs/components/Combobox/ComboboxNew/ui/Inner/Inner.css +2 -0
  5. package/cjs/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.css +2 -0
  6. package/cjs/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js +2 -1
  7. package/cjs/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js.map +1 -1
  8. package/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.css +1 -0
  9. package/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js +39 -0
  10. package/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js.map +1 -0
  11. package/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js +15 -0
  12. package/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js.map +1 -0
  13. package/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles_18yw2bf.css +1 -0
  14. package/cjs/components/Combobox/ComboboxOld/Combobox.css +4 -5
  15. package/cjs/components/Combobox/ComboboxOld/ui/ComboboxDivider/ComboboxDivider.css +4 -5
  16. package/cjs/components/Combobox/ComboboxOld/ui/ComboboxFooter/ComboboxFooter.css +4 -5
  17. package/cjs/components/Combobox/ComboboxOld/ui/ComboboxGroup/ComboboxGroup.css +4 -5
  18. package/cjs/components/Combobox/ComboboxOld/ui/ComboboxHeader/ComboboxHeader.css +4 -5
  19. package/cjs/components/Dropdown/Dropdown.css +4 -5
  20. package/cjs/components/Dropdown/Dropdown.js +2 -4
  21. package/cjs/components/Dropdown/Dropdown.js.map +1 -1
  22. package/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.css +4 -5
  23. package/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.js +2 -3
  24. package/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.js.map +1 -1
  25. package/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js +1 -7
  26. package/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js.map +1 -1
  27. package/cjs/components/Dropdown/ui/DropdownItem/{DropdownItem.styles_14yih1y.css → DropdownItem.styles_1b439rx.css} +0 -1
  28. package/cjs/components/Select/Select.js +1 -0
  29. package/cjs/components/Select/Select.js.map +1 -1
  30. package/cjs/components/Select/ui/Inner/ui/Item/Item.js +2 -1
  31. package/cjs/components/Select/ui/Inner/ui/Item/Item.js.map +1 -1
  32. package/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js +3 -18
  33. package/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js.map +1 -1
  34. package/cjs/index.css +6 -5
  35. package/cjs/index.js +2 -0
  36. package/cjs/index.js.map +1 -1
  37. package/cjs/utils/createEvent.js +54 -0
  38. package/cjs/utils/createEvent.js.map +1 -0
  39. package/cjs/utils/index.js.map +1 -1
  40. package/emotion/cjs/components/Combobox/ComboboxNew/Combobox.js +43 -29
  41. package/emotion/cjs/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js +2 -1
  42. package/emotion/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js +40 -0
  43. package/emotion/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js +13 -0
  44. package/emotion/cjs/components/Dropdown/Dropdown.js +2 -4
  45. package/emotion/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.js +2 -3
  46. package/emotion/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js +11 -15
  47. package/emotion/cjs/components/Select/Select.js +1 -0
  48. package/emotion/cjs/components/Select/ui/Inner/ui/Item/Item.js +2 -1
  49. package/emotion/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js +3 -24
  50. package/emotion/cjs/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +1 -1
  51. package/emotion/cjs/utils/createEvent.js +53 -0
  52. package/emotion/cjs/utils/index.js +10 -1
  53. package/emotion/es/components/Combobox/ComboboxNew/Combobox.js +44 -29
  54. package/emotion/es/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js +2 -1
  55. package/emotion/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js +31 -0
  56. package/emotion/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js +6 -0
  57. package/emotion/es/components/Dropdown/Dropdown.js +2 -4
  58. package/emotion/es/components/Dropdown/ui/DropdownItem/DropdownItem.js +3 -4
  59. package/emotion/es/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js +11 -15
  60. package/emotion/es/components/Select/Select.js +1 -0
  61. package/emotion/es/components/Select/ui/Inner/ui/Item/Item.js +2 -1
  62. package/emotion/es/components/Select/ui/Target/ui/Textfield/Textfield.js +3 -24
  63. package/emotion/es/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +1 -1
  64. package/emotion/es/utils/createEvent.js +47 -0
  65. package/emotion/es/utils/index.js +1 -0
  66. package/es/components/Combobox/ComboboxNew/Combobox.css +2 -0
  67. package/es/components/Combobox/ComboboxNew/Combobox.js +44 -26
  68. package/es/components/Combobox/ComboboxNew/Combobox.js.map +1 -1
  69. package/es/components/Combobox/ComboboxNew/ui/Inner/Inner.css +2 -0
  70. package/es/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.css +2 -0
  71. package/es/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js +2 -1
  72. package/es/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js.map +1 -1
  73. package/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.css +1 -0
  74. package/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js +35 -0
  75. package/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js.map +1 -0
  76. package/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js +11 -0
  77. package/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js.map +1 -0
  78. package/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles_18yw2bf.css +1 -0
  79. package/es/components/Combobox/ComboboxOld/Combobox.css +4 -5
  80. package/es/components/Combobox/ComboboxOld/ui/ComboboxDivider/ComboboxDivider.css +4 -5
  81. package/es/components/Combobox/ComboboxOld/ui/ComboboxFooter/ComboboxFooter.css +4 -5
  82. package/es/components/Combobox/ComboboxOld/ui/ComboboxGroup/ComboboxGroup.css +4 -5
  83. package/es/components/Combobox/ComboboxOld/ui/ComboboxHeader/ComboboxHeader.css +4 -5
  84. package/es/components/Dropdown/Dropdown.css +4 -5
  85. package/es/components/Dropdown/Dropdown.js +2 -4
  86. package/es/components/Dropdown/Dropdown.js.map +1 -1
  87. package/es/components/Dropdown/ui/DropdownItem/DropdownItem.css +4 -5
  88. package/es/components/Dropdown/ui/DropdownItem/DropdownItem.js +3 -4
  89. package/es/components/Dropdown/ui/DropdownItem/DropdownItem.js.map +1 -1
  90. package/es/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js +2 -7
  91. package/es/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js.map +1 -1
  92. package/es/components/Dropdown/ui/DropdownItem/{DropdownItem.styles_14yih1y.css → DropdownItem.styles_1b439rx.css} +0 -1
  93. package/es/components/Select/Select.js +1 -0
  94. package/es/components/Select/Select.js.map +1 -1
  95. package/es/components/Select/ui/Inner/ui/Item/Item.js +2 -1
  96. package/es/components/Select/ui/Inner/ui/Item/Item.js.map +1 -1
  97. package/es/components/Select/ui/Target/ui/Textfield/Textfield.js +4 -19
  98. package/es/components/Select/ui/Target/ui/Textfield/Textfield.js.map +1 -1
  99. package/es/index.css +6 -5
  100. package/es/index.js +1 -0
  101. package/es/index.js.map +1 -1
  102. package/es/utils/createEvent.js +50 -0
  103. package/es/utils/createEvent.js.map +1 -0
  104. package/es/utils/index.js.map +1 -1
  105. package/package.json +2 -3
  106. package/styled-components/cjs/components/Combobox/ComboboxNew/Combobox.js +43 -29
  107. package/styled-components/cjs/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js +2 -1
  108. package/styled-components/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js +40 -0
  109. package/styled-components/cjs/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js +12 -0
  110. package/styled-components/cjs/components/Dropdown/Dropdown.js +2 -4
  111. package/styled-components/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.js +2 -3
  112. package/styled-components/cjs/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js +2 -5
  113. package/styled-components/cjs/components/Select/Select.js +1 -0
  114. package/styled-components/cjs/components/Select/ui/Inner/ui/Item/Item.js +2 -1
  115. package/styled-components/cjs/components/Select/ui/Target/ui/Textfield/Textfield.js +3 -24
  116. package/styled-components/cjs/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +1 -1
  117. package/styled-components/cjs/utils/createEvent.js +53 -0
  118. package/styled-components/cjs/utils/index.js +10 -1
  119. package/styled-components/es/components/Combobox/ComboboxNew/Combobox.js +44 -29
  120. package/styled-components/es/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.js +2 -1
  121. package/styled-components/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.js +31 -0
  122. package/styled-components/es/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.js +5 -0
  123. package/styled-components/es/components/Dropdown/Dropdown.js +2 -4
  124. package/styled-components/es/components/Dropdown/ui/DropdownItem/DropdownItem.js +3 -4
  125. package/styled-components/es/components/Dropdown/ui/DropdownItem/DropdownItem.styles.js +2 -5
  126. package/styled-components/es/components/Select/Select.js +1 -0
  127. package/styled-components/es/components/Select/ui/Inner/ui/Item/Item.js +2 -1
  128. package/styled-components/es/components/Select/ui/Target/ui/Textfield/Textfield.js +3 -24
  129. package/styled-components/es/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx +1 -1
  130. package/styled-components/es/utils/createEvent.js +47 -0
  131. package/styled-components/es/utils/index.js +1 -0
  132. package/types/components/Combobox/ComboboxNew/Combobox.d.ts.map +1 -1
  133. package/types/components/Combobox/ComboboxNew/Combobox.types.d.ts +26 -3
  134. package/types/components/Combobox/ComboboxNew/Combobox.types.d.ts.map +1 -1
  135. package/types/components/Combobox/ComboboxNew/ui/Inner/ui/Item/Item.d.ts.map +1 -1
  136. package/types/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.d.ts +6 -0
  137. package/types/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.d.ts.map +1 -0
  138. package/types/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.d.ts +3 -0
  139. package/types/components/Combobox/ComboboxNew/ui/SelectNative/SelectNative.styles.d.ts.map +1 -0
  140. package/types/components/Dropdown/Dropdown.d.ts +2 -50
  141. package/types/components/Dropdown/Dropdown.d.ts.map +1 -1
  142. package/types/components/Dropdown/Dropdown.types.d.ts +6 -11
  143. package/types/components/Dropdown/Dropdown.types.d.ts.map +1 -1
  144. package/types/components/Dropdown/index.d.ts +0 -1
  145. package/types/components/Dropdown/index.d.ts.map +1 -1
  146. package/types/components/Dropdown/ui/DropdownItem/DropdownItem.d.ts.map +1 -1
  147. package/types/components/Dropdown/ui/DropdownItem/DropdownItem.styles.d.ts +0 -1
  148. package/types/components/Dropdown/ui/DropdownItem/DropdownItem.styles.d.ts.map +1 -1
  149. package/types/components/Select/Select.d.ts.map +1 -1
  150. package/types/components/Select/Select.types.d.ts +2 -1
  151. package/types/components/Select/Select.types.d.ts.map +1 -1
  152. package/types/components/Select/ui/Inner/ui/Item/Item.d.ts.map +1 -1
  153. package/types/components/Select/ui/Target/ui/Textfield/Textfield.d.ts.map +1 -1
  154. package/types/examples/plasma_b2c/components/Combobox/Combobox.d.ts +1076 -116
  155. package/types/examples/plasma_b2c/components/Combobox/Combobox.d.ts.map +1 -1
  156. package/types/examples/plasma_b2c/components/Dropdown/Dropdown.d.ts +1 -25
  157. package/types/examples/plasma_b2c/components/Dropdown/Dropdown.d.ts.map +1 -1
  158. package/types/examples/plasma_web/components/Combobox/Combobox.d.ts +1076 -116
  159. package/types/examples/plasma_web/components/Combobox/Combobox.d.ts.map +1 -1
  160. package/types/examples/plasma_web/components/Dropdown/Dropdown.d.ts +1 -25
  161. package/types/examples/plasma_web/components/Dropdown/Dropdown.d.ts.map +1 -1
  162. package/types/utils/createEvent.d.ts +3 -0
  163. package/types/utils/createEvent.d.ts.map +1 -0
  164. package/types/utils/index.d.ts +1 -0
  165. package/types/utils/index.d.ts.map +1 -1
@@ -1,6 +1,5 @@
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); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
@@ -20,14 +19,12 @@ var _getPathMaps = /*#__PURE__*/require("./hooks/getPathMaps");
20
19
  var _Combobox2 = /*#__PURE__*/require("./Combobox.styles");
21
20
  var _base = /*#__PURE__*/require("./variations/_view/base");
22
21
  var _base2 = /*#__PURE__*/require("./variations/_size/base");
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"];
22
+ var _SelectNative = /*#__PURE__*/require("./ui/SelectNative/SelectNative");
23
+ var _excluded = ["name", "multiple", "value", "onChange", "defaultValue", "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); }
27
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
28
- 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."); }
29
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
30
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
+ 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); }
31
28
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
32
29
  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."); }
33
30
  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); }
@@ -41,12 +38,15 @@ var Context = exports.Context = /*#__PURE__*/(0, _react.createContext)({});
41
38
  /**
42
39
  * Поле ввода с выпадающим списком и возможностью фильтрации и выбора элементов.
43
40
  */
41
+
44
42
  var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
45
43
  return /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
46
44
  var _valueToItemMap$get, _valueToItemMap$get2, _getItemByFocused;
47
- var multiple = props.multiple,
45
+ var name = props.name,
46
+ multiple = props.multiple,
48
47
  outerValue = props.value,
49
48
  outerOnChange = props.onChange,
49
+ defaultValue = props.defaultValue,
50
50
  isTargetAmount = props.isTargetAmount,
51
51
  targetAmount = props.targetAmount,
52
52
  items = props.items,
@@ -78,6 +78,7 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
78
78
  outerCloseAfterSelect = props.closeAfterSelect,
79
79
  renderValue = props.renderValue,
80
80
  rest = _objectWithoutProperties(props, _excluded);
81
+ console.log('render');
81
82
  var transformedItems = (0, _react.useMemo)(function () {
82
83
  return (0, _utils3.initialItemsTransform)(items || []);
83
84
  }, [items]);
@@ -153,11 +154,27 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
153
154
  }
154
155
  }
155
156
  }, floatingPopoverRef);
157
+
158
+ // Эта функция срабатывает при изменении Combobox и
159
+ // при изменении нативного Select для формы (срабатывает только после изменения internalValue и рендера).
156
160
  var onChange = function onChange(newValue) {
161
+ // Условие для отправки изменений наружу
157
162
  if (outerOnChange) {
158
- outerOnChange(newValue);
163
+ // Условие для отправки если комбобокс используется без формы.
164
+ if (!name && (typeof newValue === 'string' || Array.isArray(newValue))) {
165
+ outerOnChange(newValue);
166
+ }
167
+
168
+ // Условие для отправки если комбобокс используется с формой.
169
+ if (name && _typeof(newValue) === 'object' && !Array.isArray(newValue)) {
170
+ outerOnChange(newValue);
171
+ }
172
+ }
173
+
174
+ // Условие для изменения внутреннего значения (только если newValue строка или массив строк).
175
+ if (typeof newValue === 'string' || Array.isArray(newValue)) {
176
+ setInternalValue(newValue);
159
177
  }
160
- setInternalValue(newValue);
161
178
  };
162
179
  var handleClickArrow = function handleClickArrow() {
163
180
  if (disabled || readOnly) {
@@ -190,24 +207,9 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
190
207
 
191
208
  // Обработчик чипов
192
209
  var handleChipsChange = function handleChipsChange(chipLabels) {
193
- if (!Array.isArray(value)) return;
194
-
195
- // TODO: #1564
196
- // Из лейблов чипов получаем value у item и далее прокидываем его в onChange.
197
- if (renderValue && !isTargetAmount) {
198
- var resultValues = _toConsumableArray(value);
199
- value.forEach(function (_, index) {
200
- var labelAfterRenderValue = renderValue(labelToItemMap.get(valueToItemMap.get(value[index]).label));
201
- if (!chipLabels.includes(labelAfterRenderValue)) {
202
- resultValues.splice(index, 1);
203
- }
204
- });
205
- onChange(resultValues);
206
- } else {
207
- onChange(chipLabels.map(function (chipLabel) {
208
- return labelToItemMap.get(chipLabel).value;
209
- }));
210
- }
210
+ onChange(chipLabels.map(function (chipLabel) {
211
+ return labelToItemMap.get(chipLabel).value;
212
+ }));
211
213
  };
212
214
 
213
215
  // Обработчик открытия/закрытия выпадающего списка
@@ -360,13 +362,24 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
360
362
  // Т.к. вначале нужно отфильтровать и провалидировать outerValue и результат положить в переменную.
361
363
  // А переменную, содержащую сложные типы данных, нельзя помещать в deps.
362
364
  }, [outerValue, internalValue, items]);
365
+ (0, _react.useEffect)(function () {
366
+ if (defaultValue) {
367
+ setInternalValue(defaultValue);
368
+ }
369
+ }, [defaultValue]);
363
370
  return /*#__PURE__*/_react["default"].createElement(Root, {
364
371
  size: size,
365
372
  view: view,
366
373
  labelPlacement: labelPlacement,
367
374
  disabled: disabled,
368
375
  readOnly: readOnly
369
- }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(Context.Provider, {
376
+ }, name && /*#__PURE__*/_react["default"].createElement(_SelectNative.SelectNative, {
377
+ name: name,
378
+ value: internalValue,
379
+ multiple: multiple,
380
+ onChange: onChange,
381
+ ref: ref
382
+ }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(Context.Provider, {
370
383
  value: {
371
384
  focusedPath: focusedPath,
372
385
  checked: checked,
@@ -376,6 +389,7 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
376
389
  handleItemClick: handleItemClick,
377
390
  variant: variant,
378
391
  renderItem: renderItem,
392
+ valueToItemMap: valueToItemMap,
379
393
  treeId: treeId
380
394
  }
381
395
  }, /*#__PURE__*/_react["default"].createElement(_FloatingPopover.FloatingPopover, {
@@ -389,7 +403,7 @@ var comboboxRoot = exports.comboboxRoot = function comboboxRoot(Root) {
389
403
  listWidth: listWidth,
390
404
  target: function target(referenceRef) {
391
405
  return /*#__PURE__*/_react["default"].createElement(_ui.StyledTextField, _extends({
392
- ref: inputForkRef,
406
+ ref: name ? inputRef : inputForkRef,
393
407
  inputWrapperRef: referenceRef,
394
408
  value: textValue,
395
409
  onChange: handleTextValueChange,
@@ -40,6 +40,7 @@ var Item = exports.Item = function Item(_ref) {
40
40
  handleItemClick = _useContext.handleItemClick,
41
41
  variant = _useContext.variant,
42
42
  renderItem = _useContext.renderItem,
43
+ valueToItemMap = _useContext.valueToItemMap,
43
44
  treeId = _useContext.treeId;
44
45
  var disabledClassName = disabled ? _Combobox.classes.dropdownItemIsDisabled : undefined;
45
46
  var focusedClass = currentLevel === focusedPath.length - 1 && index === (focusedPath === null || focusedPath === void 0 ? void 0 : focusedPath[currentLevel]) ? _Combobox.classes.dropdownItemIsFocused : undefined;
@@ -93,7 +94,7 @@ var Item = exports.Item = function Item(_ref) {
93
94
  }))), !multiple && checked.get(item.value) === 'done' && /*#__PURE__*/_react["default"].createElement(_Icon.IconDone, {
94
95
  size: (0, _utils.sizeToIconSize)(size, variant),
95
96
  color: "inherit"
96
- })), renderItem ? /*#__PURE__*/_react["default"].createElement(_Item.StyledText, null, renderItem(item)) : /*#__PURE__*/_react["default"].createElement(_Item.StyledWrapper, null, /*#__PURE__*/_react["default"].createElement(_Item.StyledCell, {
97
+ })), renderItem ? /*#__PURE__*/_react["default"].createElement(_Item.StyledText, null, renderItem(valueToItemMap.get(value))) : /*#__PURE__*/_react["default"].createElement(_Item.StyledWrapper, null, /*#__PURE__*/_react["default"].createElement(_Item.StyledCell, {
97
98
  view: "default",
98
99
  size: "l",
99
100
  contentLeft: contentLeft,
@@ -0,0 +1,40 @@
1
+ "use strict";
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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SelectNative = void 0;
8
+ var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
9
+ var _plasmaCore = /*#__PURE__*/require("@salutejs/plasma-core");
10
+ var _utils = /*#__PURE__*/require("../../../../../utils");
11
+ var _SelectNative = /*#__PURE__*/require("./SelectNative.styles");
12
+ 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); }
13
+ 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; }
14
+ var SelectNative = exports.SelectNative = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
15
+ var name = _ref.name,
16
+ multiple = _ref.multiple,
17
+ value = _ref.value,
18
+ onChange = _ref.onChange;
19
+ var values = multiple ? value : [value];
20
+ var selectRef = (0, _react.useRef)(null);
21
+ var forkRef = (0, _plasmaCore.useForkRef)(selectRef, ref);
22
+ (0, _react.useEffect)(function () {
23
+ var event = (0, _utils.createEvent)(selectRef);
24
+ if (onChange) {
25
+ onChange(event);
26
+ }
27
+ }, [values]);
28
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_SelectNative.SelectHidden, {
29
+ ref: forkRef,
30
+ multiple: multiple,
31
+ name: name,
32
+ hidden: true,
33
+ value: multiple ? values : values[0]
34
+ }, values.map(function (v) {
35
+ return /*#__PURE__*/_react["default"].createElement("option", {
36
+ key: v,
37
+ value: v
38
+ }, v);
39
+ })));
40
+ });
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SelectHidden = void 0;
7
+ var _styledComponents = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("styled-components"));
8
+ var _mixins = /*#__PURE__*/require("../../../../../mixins");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ var SelectHidden = exports.SelectHidden = /*#__PURE__*/_styledComponents["default"].select.withConfig({
11
+ componentId: "plasma-new-hope__sc-w046ru-0"
12
+ })(["", ";"], /*#__PURE__*/(0, _mixins.applyHidden)());
@@ -20,7 +20,7 @@ var _Dropdown2 = /*#__PURE__*/require("./Dropdown.tokens");
20
20
  var _useKeyboardNavigation = /*#__PURE__*/require("./hooks/useKeyboardNavigation");
21
21
  var _useHashMaps3 = /*#__PURE__*/require("./hooks/useHashMaps");
22
22
  var _FloatingPopover = /*#__PURE__*/require("./FloatingPopover");
23
- var _excluded = ["items", "children", "placement", "offset", "closeOnOverlayClick", "onToggle", "size", "view", "itemRole", "className", "listWidth", "listHeight", "listOverflow", "closeOnSelect", "onHover", "onItemSelect", "onItemClick", "trigger", "variant", "hasArrow", "alwaysOpened", "portal", "renderItem"];
23
+ var _excluded = ["items", "children", "placement", "offset", "closeOnOverlayClick", "onToggle", "size", "view", "itemRole", "className", "listWidth", "listHeight", "listOverflow", "closeOnSelect", "onHover", "onItemSelect", "onItemClick", "trigger", "variant", "hasArrow", "alwaysOpened", "portal"];
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); }
@@ -69,7 +69,6 @@ var dropdownRoot = exports.dropdownRoot = function dropdownRoot(Root) {
69
69
  _ref$alwaysOpened = _ref.alwaysOpened,
70
70
  alwaysOpened = _ref$alwaysOpened === void 0 ? false : _ref$alwaysOpened,
71
71
  portal = _ref.portal,
72
- renderItem = _ref.renderItem,
73
72
  rest = _objectWithoutProperties(_ref, _excluded);
74
73
  var _useReducer = (0, _react.useReducer)(_pathReducer.pathReducer, []),
75
74
  _useReducer2 = _slicedToArray(_useReducer, 2),
@@ -145,8 +144,7 @@ var dropdownRoot = exports.dropdownRoot = function dropdownRoot(Root) {
145
144
  onItemClick: onItemClick,
146
145
  onItemSelect: onItemSelect,
147
146
  hasArrow: hasArrow,
148
- treeId: treeId,
149
- renderItem: renderItem
147
+ treeId: treeId
150
148
  }
151
149
  }, /*#__PURE__*/_react["default"].createElement(_FloatingPopover.FloatingPopover, {
152
150
  ref: floatingPopoverRef,
@@ -43,8 +43,7 @@ var DropdownItem = exports.DropdownItem = function DropdownItem(_ref) {
43
43
  onItemSelect = _useContext.onItemSelect,
44
44
  onItemClick = _useContext.onItemClick,
45
45
  hasArrow = _useContext.hasArrow,
46
- treeId = _useContext.treeId,
47
- renderItem = _useContext.renderItem;
46
+ treeId = _useContext.treeId;
48
47
  var hasDescendants = Boolean(item.items);
49
48
  var disclosureIconSize = size === 'xs' ? 'xs' : 's';
50
49
  var isDisabledClassName = disabled || isDisabled ? _Dropdown.classes.dropdownItemIsDisabled : undefined;
@@ -95,7 +94,7 @@ var DropdownItem = exports.DropdownItem = function DropdownItem(_ref) {
95
94
  "aria-expanded": ariaExpanded,
96
95
  "aria-level": ariaLevel,
97
96
  "aria-label": ariaLabel
98
- }, renderItem ? /*#__PURE__*/_react["default"].createElement(_DropdownItem.RenderItemWrapper, null, renderItem(item)) : /*#__PURE__*/_react["default"].createElement(_DropdownItem.CellWrapper, null, /*#__PURE__*/_react["default"].createElement(_DropdownItem.StyledCell, {
97
+ }, /*#__PURE__*/_react["default"].createElement(_DropdownItem.CellWrapper, null, /*#__PURE__*/_react["default"].createElement(_DropdownItem.StyledCell, {
99
98
  contentLeft: contentLeft,
100
99
  contentRight: contentRight,
101
100
  alignContentLeft: "center",
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Wrapper = exports.StyledCell = exports.RenderItemWrapper = exports.Divider = exports.DisclosureIconWrapper = exports.CellWrapper = void 0;
6
+ exports.Wrapper = exports.StyledCell = exports.Divider = exports.DisclosureIconWrapper = exports.CellWrapper = void 0;
7
7
  var _styledComponents = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("styled-components"));
8
8
  var _Dropdown = /*#__PURE__*/require("../../Dropdown.tokens");
9
9
  var _mixins = /*#__PURE__*/require("../../../../mixins");
@@ -42,7 +42,4 @@ var Wrapper = exports.Wrapper = /*#__PURE__*/_styledComponents["default"].li.wit
42
42
  outlineRadius: /*#__PURE__*/"var(".concat(_Dropdown.tokens.itemBorderRadius, ")"),
43
43
  hasTransition: false,
44
44
  customFocusRules: /*#__PURE__*/"\n &.".concat(_Dropdown.classes.dropdownItemIsFocused, ":before {\n outline: none;\n box-shadow: 0 0 0 0.0625rem var(").concat(_Dropdown.constants.focusColor, ");\n }\n ")
45
- }));
46
- var RenderItemWrapper = exports.RenderItemWrapper = /*#__PURE__*/_styledComponents["default"].div.withConfig({
47
- componentId: "plasma-new-hope__sc-hs0ek1-5"
48
- })(["", ";flex:1;"], /*#__PURE__*/(0, _mixins.applyEllipsis)());
45
+ }));
@@ -281,6 +281,7 @@ var selectRoot = exports.selectRoot = function selectRoot(Root) {
281
281
  handleItemClick: handleItemClick,
282
282
  variant: variant,
283
283
  renderItem: renderItem,
284
+ valueToItemMap: valueToItemMap,
284
285
  treeId: treeId
285
286
  }
286
287
  }, /*#__PURE__*/_react["default"].createElement(_FloatingPopover.FloatingPopover, {
@@ -41,6 +41,7 @@ var Item = exports.Item = function Item(_ref) {
41
41
  handleItemClick = _useContext.handleItemClick,
42
42
  variant = _useContext.variant,
43
43
  renderItem = _useContext.renderItem,
44
+ valueToItemMap = _useContext.valueToItemMap,
44
45
  treeId = _useContext.treeId;
45
46
  var itemDisabled = Boolean(disabled || isDisabled);
46
47
  var disabledClassName = itemDisabled ? _Select.classes.dropdownItemIsDisabled : undefined;
@@ -95,7 +96,7 @@ var Item = exports.Item = function Item(_ref) {
95
96
  }))), !multiselect && checked.get(item.value) === 'done' && /*#__PURE__*/_react["default"].createElement(_Icon.IconDone, {
96
97
  size: (0, _utils.sizeToIconSize)(size, variant),
97
98
  color: "inherit"
98
- })), renderItem ? /*#__PURE__*/_react["default"].createElement(_Item.StyledText, null, renderItem(item)) : /*#__PURE__*/_react["default"].createElement(_Item.StyledWrapper, null, /*#__PURE__*/_react["default"].createElement(_Item.StyledCell, {
99
+ })), renderItem ? /*#__PURE__*/_react["default"].createElement(_Item.StyledText, null, renderItem(valueToItemMap.get(value))) : /*#__PURE__*/_react["default"].createElement(_Item.StyledWrapper, null, /*#__PURE__*/_react["default"].createElement(_Item.StyledCell, {
99
100
  contentLeft: contentLeft,
100
101
  contentRight: contentRight
101
102
  // TODO: #1548
@@ -12,12 +12,6 @@ var _Textfield = /*#__PURE__*/require("./Textfield.styles");
12
12
  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); }
13
13
  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; }
14
14
  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); }
15
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
16
- 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."); }
17
- 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); }
18
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
- 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; }
21
15
  var Textfield = exports.Textfield = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
22
16
  var _valueToItemMap$get;
23
17
  var inputWrapperRef = _ref.inputWrapperRef,
@@ -62,24 +56,9 @@ var Textfield = exports.Textfield = /*#__PURE__*/(0, _react.forwardRef)(function
62
56
 
63
57
  // Обработчик чипов
64
58
  var handleChipsChange = function handleChipsChange(chipLabels) {
65
- if (!Array.isArray(value)) return;
66
-
67
- // TODO: #1564
68
- // Из лейблов чипов получаем value у item и далее прокидываем его в onChange.
69
- if (renderValue && !isTargetAmount) {
70
- var resultValues = _toConsumableArray(value);
71
- value.forEach(function (_, index) {
72
- var labelAfterRenderValue = renderValue(labelToItemMap.get(valueToItemMap.get(value[index]).label));
73
- if (!chipLabels.includes(labelAfterRenderValue)) {
74
- resultValues.splice(index, 1);
75
- }
76
- });
77
- onChange(resultValues);
78
- } else {
79
- onChange(chipLabels.map(function (chipLabel) {
80
- return labelToItemMap.get(chipLabel).value;
81
- }));
82
- }
59
+ onChange(chipLabels.map(function (chipLabel) {
60
+ return labelToItemMap.get(chipLabel).value;
61
+ }));
83
62
  };
84
63
  return /*#__PURE__*/_react["default"].createElement(_Textfield.StyledTextField, _extends({
85
64
  ref: ref,
@@ -353,11 +353,11 @@ const items = [
353
353
 
354
354
  const SingleStory = (args: StorySelectProps) => {
355
355
  const [value, setValue] = useState('');
356
-
357
356
  return (
358
357
  <div style={{ width: '400px' }}>
359
358
  <Combobox
360
359
  {...args}
360
+ name="mau"
361
361
  items={items}
362
362
  value={value}
363
363
  onChange={setValue}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createEvent = void 0;
7
+ var createEvent = exports.createEvent = function createEvent(ref) {
8
+ if (ref.current) {
9
+ var event = new Event('change', {
10
+ bubbles: true
11
+ });
12
+ Object.defineProperty(event, 'target', {
13
+ writable: false,
14
+ value: ref.current
15
+ });
16
+ var syntheticEvent = createSyntheticEvent(event);
17
+ return syntheticEvent;
18
+ }
19
+ return null;
20
+ };
21
+ var createSyntheticEvent = function createSyntheticEvent(event) {
22
+ var _isDefaultPrevented = false;
23
+ var _isPropagationStopped = false;
24
+ var preventDefault = function preventDefault() {
25
+ _isDefaultPrevented = true;
26
+ event.preventDefault();
27
+ };
28
+ var stopPropagation = function stopPropagation() {
29
+ _isPropagationStopped = true;
30
+ event.stopPropagation();
31
+ };
32
+ return {
33
+ nativeEvent: event,
34
+ currentTarget: event.currentTarget,
35
+ target: event.target,
36
+ bubbles: event.bubbles,
37
+ cancelable: event.cancelable,
38
+ defaultPrevented: event.defaultPrevented,
39
+ eventPhase: event.eventPhase,
40
+ isTrusted: event.isTrusted,
41
+ preventDefault: preventDefault,
42
+ isDefaultPrevented: function isDefaultPrevented() {
43
+ return _isDefaultPrevented;
44
+ },
45
+ stopPropagation: stopPropagation,
46
+ isPropagationStopped: function isPropagationStopped() {
47
+ return _isPropagationStopped;
48
+ },
49
+ persist: function persist() {},
50
+ timeStamp: event.timeStamp,
51
+ type: event.type
52
+ };
53
+ };
@@ -16,6 +16,7 @@ var _exportNames = {
16
16
  mergeRefs: true,
17
17
  setRefList: true,
18
18
  isEmpty: true,
19
+ createEvent: true,
19
20
  constants: true,
20
21
  noop: true,
21
22
  fixedForwardRef: true
@@ -32,7 +33,14 @@ Object.defineProperty(exports, "canUseDOM", {
32
33
  return _canUseDOM.canUseDOM;
33
34
  }
34
35
  });
35
- exports.cx = exports.constants = exports.composableStyle = void 0;
36
+ exports.constants = exports.composableStyle = void 0;
37
+ Object.defineProperty(exports, "createEvent", {
38
+ enumerable: true,
39
+ get: function get() {
40
+ return _createEvent.createEvent;
41
+ }
42
+ });
43
+ exports.cx = void 0;
36
44
  Object.defineProperty(exports, "extractTextFrom", {
37
45
  enumerable: true,
38
46
  get: function get() {
@@ -94,6 +102,7 @@ var _react = /*#__PURE__*/require("./react");
94
102
  var _isNumber = /*#__PURE__*/require("./isNumber");
95
103
  var _setRefList = /*#__PURE__*/require("./setRefList");
96
104
  var _isEmpty = /*#__PURE__*/require("./isEmpty");
105
+ var _createEvent = /*#__PURE__*/require("./createEvent");
97
106
  var _constants = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./constants"));
98
107
  exports.constants = _constants;
99
108
  var _getPopoverPlacement = /*#__PURE__*/require("./getPopoverPlacement");
@@ -1,9 +1,6 @@
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"];
1
+ var _excluded = ["name", "multiple", "value", "onChange", "defaultValue", "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
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
- 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."); }
5
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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); }
7
4
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
5
  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."); }
9
6
  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); }
@@ -12,7 +9,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
12
9
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
10
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
14
11
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
- import React, { forwardRef, useState, useReducer, useMemo, createContext, useLayoutEffect, useRef } from 'react';
12
+ import React, { forwardRef, useState, useReducer, useMemo, createContext, useLayoutEffect, useRef, useEffect } from 'react';
16
13
  import { safeUseId, useForkRef } from '@salutejs/plasma-core';
17
14
  import { isEmpty } from '../../../utils';
18
15
  import { useOutsideClick } from '../../../hooks';
@@ -27,17 +24,21 @@ import { getPathMap, getTreeMaps } from './hooks/getPathMaps';
27
24
  import { Ul, base, StyledArrow, IconArrowWrapper, StyledEmptyState } from './Combobox.styles';
28
25
  import { base as viewCSS } from './variations/_view/base';
29
26
  import { base as sizeCSS } from './variations/_size/base';
27
+ import { SelectNative } from './ui/SelectNative/SelectNative';
30
28
  export var Context = /*#__PURE__*/createContext({});
31
29
 
32
30
  /**
33
31
  * Поле ввода с выпадающим списком и возможностью фильтрации и выбора элементов.
34
32
  */
33
+
35
34
  export var comboboxRoot = function comboboxRoot(Root) {
36
35
  return /*#__PURE__*/forwardRef(function (props, ref) {
37
36
  var _valueToItemMap$get, _valueToItemMap$get2, _getItemByFocused;
38
- var multiple = props.multiple,
37
+ var name = props.name,
38
+ multiple = props.multiple,
39
39
  outerValue = props.value,
40
40
  outerOnChange = props.onChange,
41
+ defaultValue = props.defaultValue,
41
42
  isTargetAmount = props.isTargetAmount,
42
43
  targetAmount = props.targetAmount,
43
44
  items = props.items,
@@ -69,6 +70,7 @@ export var comboboxRoot = function comboboxRoot(Root) {
69
70
  outerCloseAfterSelect = props.closeAfterSelect,
70
71
  renderValue = props.renderValue,
71
72
  rest = _objectWithoutProperties(props, _excluded);
73
+ console.log('render');
72
74
  var transformedItems = useMemo(function () {
73
75
  return initialItemsTransform(items || []);
74
76
  }, [items]);
@@ -144,11 +146,27 @@ export var comboboxRoot = function comboboxRoot(Root) {
144
146
  }
145
147
  }
146
148
  }, floatingPopoverRef);
149
+
150
+ // Эта функция срабатывает при изменении Combobox и
151
+ // при изменении нативного Select для формы (срабатывает только после изменения internalValue и рендера).
147
152
  var onChange = function onChange(newValue) {
153
+ // Условие для отправки изменений наружу
148
154
  if (outerOnChange) {
149
- outerOnChange(newValue);
155
+ // Условие для отправки если комбобокс используется без формы.
156
+ if (!name && (typeof newValue === 'string' || Array.isArray(newValue))) {
157
+ outerOnChange(newValue);
158
+ }
159
+
160
+ // Условие для отправки если комбобокс используется с формой.
161
+ if (name && _typeof(newValue) === 'object' && !Array.isArray(newValue)) {
162
+ outerOnChange(newValue);
163
+ }
164
+ }
165
+
166
+ // Условие для изменения внутреннего значения (только если newValue строка или массив строк).
167
+ if (typeof newValue === 'string' || Array.isArray(newValue)) {
168
+ setInternalValue(newValue);
150
169
  }
151
- setInternalValue(newValue);
152
170
  };
153
171
  var handleClickArrow = function handleClickArrow() {
154
172
  if (disabled || readOnly) {
@@ -181,24 +199,9 @@ export var comboboxRoot = function comboboxRoot(Root) {
181
199
 
182
200
  // Обработчик чипов
183
201
  var handleChipsChange = function handleChipsChange(chipLabels) {
184
- if (!Array.isArray(value)) return;
185
-
186
- // TODO: #1564
187
- // Из лейблов чипов получаем value у item и далее прокидываем его в onChange.
188
- if (renderValue && !isTargetAmount) {
189
- var resultValues = _toConsumableArray(value);
190
- value.forEach(function (_, index) {
191
- var labelAfterRenderValue = renderValue(labelToItemMap.get(valueToItemMap.get(value[index]).label));
192
- if (!chipLabels.includes(labelAfterRenderValue)) {
193
- resultValues.splice(index, 1);
194
- }
195
- });
196
- onChange(resultValues);
197
- } else {
198
- onChange(chipLabels.map(function (chipLabel) {
199
- return labelToItemMap.get(chipLabel).value;
200
- }));
201
- }
202
+ onChange(chipLabels.map(function (chipLabel) {
203
+ return labelToItemMap.get(chipLabel).value;
204
+ }));
202
205
  };
203
206
 
204
207
  // Обработчик открытия/закрытия выпадающего списка
@@ -351,13 +354,24 @@ export var comboboxRoot = function comboboxRoot(Root) {
351
354
  // Т.к. вначале нужно отфильтровать и провалидировать outerValue и результат положить в переменную.
352
355
  // А переменную, содержащую сложные типы данных, нельзя помещать в deps.
353
356
  }, [outerValue, internalValue, items]);
357
+ useEffect(function () {
358
+ if (defaultValue) {
359
+ setInternalValue(defaultValue);
360
+ }
361
+ }, [defaultValue]);
354
362
  return /*#__PURE__*/React.createElement(Root, {
355
363
  size: size,
356
364
  view: view,
357
365
  labelPlacement: labelPlacement,
358
366
  disabled: disabled,
359
367
  readOnly: readOnly
360
- }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Context.Provider, {
368
+ }, name && /*#__PURE__*/React.createElement(SelectNative, {
369
+ name: name,
370
+ value: internalValue,
371
+ multiple: multiple,
372
+ onChange: onChange,
373
+ ref: ref
374
+ }), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Context.Provider, {
361
375
  value: {
362
376
  focusedPath: focusedPath,
363
377
  checked: checked,
@@ -367,6 +381,7 @@ export var comboboxRoot = function comboboxRoot(Root) {
367
381
  handleItemClick: handleItemClick,
368
382
  variant: variant,
369
383
  renderItem: renderItem,
384
+ valueToItemMap: valueToItemMap,
370
385
  treeId: treeId
371
386
  }
372
387
  }, /*#__PURE__*/React.createElement(FloatingPopover, {
@@ -380,7 +395,7 @@ export var comboboxRoot = function comboboxRoot(Root) {
380
395
  listWidth: listWidth,
381
396
  target: function target(referenceRef) {
382
397
  return /*#__PURE__*/React.createElement(StyledTextField, _extends({
383
- ref: inputForkRef,
398
+ ref: name ? inputRef : inputForkRef,
384
399
  inputWrapperRef: referenceRef,
385
400
  value: textValue,
386
401
  onChange: handleTextValueChange,