iguazio.dashboard-react-controls 1.9.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/components/Backdrop/Backdrop.js +7 -7
  2. package/dist/components/Button/Button.js +20 -26
  3. package/dist/components/ConfirmDialog/ConfirmDialog.js +18 -17
  4. package/dist/components/FormCheckBox/FormCheckBox.js +28 -32
  5. package/dist/components/FormChipCell/FormChip/FormChip.js +46 -50
  6. package/dist/components/FormChipCell/FormChipCell.js +122 -142
  7. package/dist/components/FormChipCell/FormChipCellView.js +44 -47
  8. package/dist/components/FormChipCell/HiddenChipsBlock/HiddenChipsBlock.js +23 -20
  9. package/dist/components/FormChipCell/NewChipForm/NewChipForm.js +129 -152
  10. package/dist/components/FormChipCell/NewChipInput/NewChipInput.js +24 -27
  11. package/dist/components/FormChipCell/formChipCell.util.js +6 -16
  12. package/dist/components/FormCombobox/FormCombobox.js +134 -195
  13. package/dist/components/FormInput/FormInput.js +134 -212
  14. package/dist/components/FormInput/InputNumberButtons/InputNumberButtons.js +15 -14
  15. package/dist/components/FormKeyValueTable/FormKeyValueTable.js +72 -72
  16. package/dist/components/FormRadio/FormRadio.js +21 -25
  17. package/dist/components/FormSelect/FormSelect.js +98 -126
  18. package/dist/components/FormSelect/FormSelect.test.js +56 -60
  19. package/dist/components/FormTextarea/FormTextarea.js +55 -71
  20. package/dist/components/FormToggle/FormToggle.js +25 -29
  21. package/dist/components/Modal/Modal.js +17 -18
  22. package/dist/components/PopUpDialog/PopUpDialog.js +53 -63
  23. package/dist/components/RoundedIcon/RoundedIcon.js +14 -13
  24. package/dist/components/Tip/Tip.js +58 -64
  25. package/dist/components/Tip/Tip.test.js +41 -64
  26. package/dist/components/Tooltip/Tooltip.js +75 -89
  27. package/dist/components/TooltipTemplate/ProducerTooltipTemplate.js +6 -5
  28. package/dist/components/TooltipTemplate/TextTooltipTemplate.js +10 -10
  29. package/dist/components/Wizard/Wizard.js +73 -107
  30. package/dist/components/Wizard/WizardSteps/WizardSteps.js +19 -20
  31. package/dist/components/index.js +18 -18
  32. package/dist/constants.js +26 -44
  33. package/dist/elements/FormActionButton/FormActionButton.js +12 -13
  34. package/dist/elements/FormRowActions/FormRowActions.js +19 -22
  35. package/dist/elements/OptionsMenu/OptionsMenu.js +10 -8
  36. package/dist/elements/SelectOption/SelectOption.js +14 -13
  37. package/dist/elements/SelectOption/SelectOption.test.js +39 -47
  38. package/dist/elements/ValidationTemplate/ValidationTemplate.js +7 -6
  39. package/dist/elements/index.js +5 -5
  40. package/dist/hooks/index.js +5 -5
  41. package/dist/hooks/useChipCell.hook.js +66 -85
  42. package/dist/hooks/useDebounce.hook.js +22 -24
  43. package/dist/hooks/useDetectOutsideClick.hook.js +4 -4
  44. package/dist/hooks/useFormTable.hook.js +99 -112
  45. package/dist/hooks/useHiddenChipsBlock.hook.js +40 -55
  46. package/dist/index.js +2 -3
  47. package/dist/scss/borders.scss +6 -0
  48. package/dist/scss/mixins.scss +32 -0
  49. package/dist/types.js +43 -67
  50. package/dist/utils/common.util.js +19 -23
  51. package/dist/utils/form.util.js +33 -39
  52. package/dist/utils/generateChipsList.util.js +7 -7
  53. package/dist/utils/getFirstScrollableParent.util.js +4 -10
  54. package/dist/utils/math.util.js +3 -3
  55. package/dist/utils/validation.util.js +74 -131
  56. package/package.json +34 -34
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
@@ -19,114 +18,96 @@ var _close = require("../../../images/close.svg");
19
18
  require("./newChipForm.scss");
20
19
  var _jsxRuntime = require("react/jsx-runtime");
21
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
25
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
26
- 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; }
27
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
28
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
29
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
30
- 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."); }
31
- 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); }
32
- 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; }
33
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
34
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /*
35
- Copyright 2022 Iguazio Systems Ltd.
36
- Licensed under the Apache License, Version 2.0 (the "License") with
37
- an addition restriction as set forth herein. You may not use this
38
- file except in compliance with the License. You may obtain a copy of
39
- the License at http://www.apache.org/licenses/LICENSE-2.0.
40
- Unless required by applicable law or agreed to in writing, software
41
- distributed under the License is distributed on an "AS IS" BASIS,
42
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
43
- implied. See the License for the specific language governing
44
- permissions and limitations under the License.
45
- In addition, you may not use the software for any purposes that are
46
- illegal under applicable law, and the grant of the foregoing license
47
- under the Apache 2.0 license is conditioned upon your compliance with
48
- such restriction.
49
- */
50
- var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
51
- var chip = _ref.chip,
52
- chipIndex = _ref.chipIndex,
53
- chipOptions = _ref.chipOptions,
54
- className = _ref.className,
55
- editConfig = _ref.editConfig,
56
- handleRemoveChip = _ref.handleRemoveChip,
57
- isEditable = _ref.isEditable,
58
- keyName = _ref.keyName,
59
- meta = _ref.meta,
60
- onChange = _ref.onChange,
61
- setEditConfig = _ref.setEditConfig,
62
- rules = _ref.validationRules,
63
- valueName = _ref.valueName;
64
- var _useState = (0, _react.useState)({
65
- isKeyOnly: chip.isKeyOnly,
66
- key: chip.key,
67
- value: chip.value,
68
- keyFieldWidth: 0,
69
- valueFieldWidth: 0
70
- }),
71
- _useState2 = _slicedToArray(_useState, 2),
72
- chipData = _useState2[0],
73
- setChipData = _useState2[1];
74
- var _useState3 = (0, _react.useState)('key'),
75
- _useState4 = _slicedToArray(_useState3, 2),
76
- selectedInput = _useState4[0],
77
- setSelectedInput = _useState4[1];
78
- var _useState5 = (0, _react.useState)(rules),
79
- _useState6 = _slicedToArray(_useState5, 2),
80
- validationRules = _useState6[0],
81
- setValidationRules = _useState6[1];
82
- var _useState7 = (0, _react.useState)(false),
83
- _useState8 = _slicedToArray(_useState7, 2),
84
- showValidationRules = _useState8[0],
85
- setShowValidationRules = _useState8[1];
86
- var maxWidthInput = (0, _react.useMemo)(function () {
21
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
22
+ 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; }
23
+ /*
24
+ Copyright 2022 Iguazio Systems Ltd.
25
+ Licensed under the Apache License, Version 2.0 (the "License") with
26
+ an addition restriction as set forth herein. You may not use this
27
+ file except in compliance with the License. You may obtain a copy of
28
+ the License at http://www.apache.org/licenses/LICENSE-2.0.
29
+ Unless required by applicable law or agreed to in writing, software
30
+ distributed under the License is distributed on an "AS IS" BASIS,
31
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
32
+ implied. See the License for the specific language governing
33
+ permissions and limitations under the License.
34
+ In addition, you may not use the software for any purposes that are
35
+ illegal under applicable law, and the grant of the foregoing license
36
+ under the Apache 2.0 license is conditioned upon your compliance with
37
+ such restriction.
38
+ */
39
+
40
+ const NewChipForm = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
41
+ let {
42
+ chip,
43
+ chipIndex,
44
+ chipOptions,
45
+ className,
46
+ editConfig,
47
+ handleRemoveChip,
48
+ isEditable,
49
+ keyName,
50
+ meta,
51
+ onChange,
52
+ setEditConfig,
53
+ validationRules: rules,
54
+ valueName
55
+ } = _ref;
56
+ const [chipData, setChipData] = (0, _react.useState)({
57
+ isKeyOnly: chip.isKeyOnly,
58
+ key: chip.key,
59
+ value: chip.value,
60
+ keyFieldWidth: 0,
61
+ valueFieldWidth: 0
62
+ });
63
+ const [selectedInput, setSelectedInput] = (0, _react.useState)('key');
64
+ const [validationRules, setValidationRules] = (0, _react.useState)(rules);
65
+ const [showValidationRules, setShowValidationRules] = (0, _react.useState)(false);
66
+ const maxWidthInput = (0, _react.useMemo)(() => {
87
67
  var _ref$current;
88
68
  return ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientWidth) - 50;
89
69
  }, [ref]);
90
- var background = chipOptions.background,
91
- borderColor = chipOptions.borderColor,
92
- borderRadius = chipOptions.borderRadius,
93
- density = chipOptions.density,
94
- font = chipOptions.font;
95
- var minWidthInput = 25;
96
- var minWidthValueInput = 35;
97
- var refInputKey = _react.default.useRef({});
98
- var refInputValue = _react.default.useRef({});
99
- var refInputContainer = _react.default.useRef();
100
- var labelKeyClassName = (0, _classnames.default)(className, !editConfig.isKeyFocused && 'item_edited', !(0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', chipIndex, 'key'], [])) && !(0, _lodash.isEmpty)(chipData.key) && 'item_edited_invalid');
101
- var labelContainerClassName = (0, _classnames.default)('edit-chip-container', background && "edit-chip-container-background_".concat(background), borderColor && "edit-chip-container-border_".concat(borderColor), font && "edit-chip-container-font_".concat(font), density && "edit-chip-container-density_".concat(density), borderRadius && "edit-chip-container-border_".concat(borderRadius), (editConfig.isEdit || editConfig.isNewChip) && 'edit-chip-container_edited');
102
- var labelValueClassName = (0, _classnames.default)('input-label-value', !editConfig.isValueFocused && 'item_edited', !(0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', chipIndex, 'value'], [])) && !(0, _lodash.isEmpty)(chipData.value) && 'item_edited_invalid');
103
- var closeButtonClass = (0, _classnames.default)('item-icon-close', (editConfig.chipIndex === chipIndex || !isEditable) && 'item-icon-close_hidden');
104
- (0, _react.useLayoutEffect)(function () {
70
+ const {
71
+ background,
72
+ borderColor,
73
+ borderRadius,
74
+ density,
75
+ font
76
+ } = chipOptions;
77
+ const minWidthInput = 25;
78
+ const minWidthValueInput = 35;
79
+ const refInputKey = _react.default.useRef({});
80
+ const refInputValue = _react.default.useRef({});
81
+ const refInputContainer = _react.default.useRef();
82
+ const labelKeyClassName = (0, _classnames.default)(className, !editConfig.isKeyFocused && 'item_edited', !(0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', chipIndex, 'key'], [])) && !(0, _lodash.isEmpty)(chipData.key) && 'item_edited_invalid');
83
+ const labelContainerClassName = (0, _classnames.default)('edit-chip-container', background && "edit-chip-container-background_".concat(background), borderColor && "edit-chip-container-border_".concat(borderColor), font && "edit-chip-container-font_".concat(font), density && "edit-chip-container-density_".concat(density), borderRadius && "edit-chip-container-border_".concat(borderRadius), (editConfig.isEdit || editConfig.isNewChip) && 'edit-chip-container_edited');
84
+ const labelValueClassName = (0, _classnames.default)('input-label-value', !editConfig.isValueFocused && 'item_edited', !(0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', chipIndex, 'value'], [])) && !(0, _lodash.isEmpty)(chipData.value) && 'item_edited_invalid');
85
+ const closeButtonClass = (0, _classnames.default)('item-icon-close', (editConfig.chipIndex === chipIndex || !isEditable) && 'item-icon-close_hidden');
86
+ (0, _react.useLayoutEffect)(() => {
105
87
  if (!chipData.keyFieldWidth && !chipData.valueFieldWidth) {
106
- var currentWidthKeyInput = refInputKey.current.scrollWidth + 1;
107
- var currentWidthValueInput = refInputValue.current.scrollWidth + 1;
108
- var keyFieldWidth = !chipData.key || currentWidthKeyInput <= minWidthInput ? minWidthInput : currentWidthKeyInput >= maxWidthInput ? maxWidthInput : currentWidthKeyInput;
109
- var valueFieldWidth = !chipData.value || currentWidthValueInput <= minWidthValueInput ? minWidthValueInput : currentWidthValueInput >= maxWidthInput ? maxWidthInput : currentWidthValueInput;
110
- setChipData(function (prevState) {
111
- return _objectSpread(_objectSpread({}, prevState), {}, {
112
- keyFieldWidth: keyFieldWidth,
113
- valueFieldWidth: valueFieldWidth
114
- });
115
- });
88
+ const currentWidthKeyInput = refInputKey.current.scrollWidth + 1;
89
+ const currentWidthValueInput = refInputValue.current.scrollWidth + 1;
90
+ const keyFieldWidth = !chipData.key || currentWidthKeyInput <= minWidthInput ? minWidthInput : currentWidthKeyInput >= maxWidthInput ? maxWidthInput : currentWidthKeyInput;
91
+ const valueFieldWidth = !chipData.value || currentWidthValueInput <= minWidthValueInput ? minWidthValueInput : currentWidthValueInput >= maxWidthInput ? maxWidthInput : currentWidthValueInput;
92
+ setChipData(prevState => ({
93
+ ...prevState,
94
+ keyFieldWidth,
95
+ valueFieldWidth
96
+ }));
116
97
  }
117
98
  }, [chipData.key, chipData.value, chipData.keyFieldWidth, chipData.valueFieldWidth, maxWidthInput, refInputKey, refInputValue]);
118
- var handleScroll = function handleScroll() {
99
+ const handleScroll = () => {
119
100
  setShowValidationRules(false);
120
101
  };
121
- (0, _react.useEffect)(function () {
102
+ (0, _react.useEffect)(() => {
122
103
  if (showValidationRules) {
123
104
  window.addEventListener('scroll', handleScroll, true);
124
105
  }
125
- return function () {
106
+ return () => {
126
107
  window.removeEventListener('scroll', handleScroll, true);
127
108
  };
128
109
  }, [showValidationRules]);
129
- (0, _react.useEffect)(function () {
110
+ (0, _react.useEffect)(() => {
130
111
  if (editConfig.chipIndex === chipIndex) {
131
112
  if (editConfig.isKeyFocused) {
132
113
  refInputKey.current.focus();
@@ -135,10 +116,10 @@ var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
135
116
  }
136
117
  }
137
118
  }, [editConfig.isKeyFocused, editConfig.isValueFocused, refInputKey, refInputValue, chipIndex, editConfig.chipIndex]);
138
- var outsideClick = (0, _react.useCallback)(function (event) {
119
+ const outsideClick = (0, _react.useCallback)(event => {
139
120
  if (editConfig.chipIndex === chipIndex) {
140
121
  var _event$path, _event$composedPath;
141
- var elementPath = (_event$path = event.path) !== null && _event$path !== void 0 ? _event$path : (_event$composedPath = event.composedPath) === null || _event$composedPath === void 0 ? void 0 : _event$composedPath.call(event);
122
+ const elementPath = (_event$path = event.path) !== null && _event$path !== void 0 ? _event$path : (_event$composedPath = event.composedPath) === null || _event$composedPath === void 0 ? void 0 : _event$composedPath.call(event);
142
123
  if (!elementPath.includes(refInputContainer.current)) {
143
124
  onChange(event, _constants.CLICK);
144
125
  window.getSelection().removeAllRanges();
@@ -147,15 +128,15 @@ var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
147
128
  }
148
129
  }
149
130
  }, [onChange, refInputContainer, chipIndex, editConfig.chipIndex]);
150
- (0, _react.useEffect)(function () {
131
+ (0, _react.useEffect)(() => {
151
132
  if (editConfig.isEdit) {
152
133
  document.addEventListener('click', outsideClick, true);
153
- return function () {
134
+ return () => {
154
135
  document.removeEventListener('click', outsideClick, true);
155
136
  };
156
137
  }
157
138
  }, [outsideClick, editConfig.isEdit]);
158
- var focusChip = (0, _react.useCallback)(function (event) {
139
+ const focusChip = (0, _react.useCallback)(event => {
159
140
  if (editConfig.chipIndex === chipIndex && isEditable) {
160
141
  if (!event.shiftKey && event.key === _constants.TAB && editConfig.isValueFocused) {
161
142
  return onChange(event, _constants.TAB);
@@ -165,25 +146,23 @@ var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
165
146
  }
166
147
  event.stopPropagation();
167
148
  }, [editConfig, onChange, chipIndex, isEditable]);
168
- var handleOnFocus = (0, _react.useCallback)(function (event) {
169
- var isKeyFocused = event.target.name === keyName;
149
+ const handleOnFocus = (0, _react.useCallback)(event => {
150
+ const isKeyFocused = event.target.name === keyName;
170
151
  if (editConfig.chipIndex === chipIndex) {
171
152
  if (isKeyFocused) {
172
153
  refInputKey.current.selectionStart = refInputKey.current.selectionEnd;
173
- setEditConfig(function (prevConfig) {
174
- return _objectSpread(_objectSpread({}, prevConfig), {}, {
175
- isKeyFocused: true,
176
- isValueFocused: false
177
- });
178
- });
154
+ setEditConfig(prevConfig => ({
155
+ ...prevConfig,
156
+ isKeyFocused: true,
157
+ isValueFocused: false
158
+ }));
179
159
  } else {
180
160
  refInputValue.current.selectionStart = refInputValue.current.selectionEnd;
181
- setEditConfig(function (prevConfig) {
182
- return _objectSpread(_objectSpread({}, prevConfig), {}, {
183
- isKeyFocused: false,
184
- isValueFocused: true
185
- });
186
- });
161
+ setEditConfig(prevConfig => ({
162
+ ...prevConfig,
163
+ isKeyFocused: false,
164
+ isValueFocused: true
165
+ }));
187
166
  }
188
167
  event && event.stopPropagation();
189
168
  } else if ((0, _lodash.isNil)(editConfig.chipIndex)) {
@@ -193,66 +172,69 @@ var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
193
172
  refInputValue.current.selectionStart = refInputValue.current.selectionEnd;
194
173
  }
195
174
  setEditConfig({
196
- chipIndex: chipIndex,
175
+ chipIndex,
197
176
  isEdit: true,
198
177
  isKeyFocused: isKeyFocused,
199
178
  isValueFocused: !isKeyFocused
200
179
  });
201
180
  }
202
181
  }, [keyName, refInputKey, refInputValue, setEditConfig, editConfig.chipIndex, chipIndex]);
203
- var handleOnChange = (0, _react.useCallback)(function (event) {
182
+ const handleOnChange = (0, _react.useCallback)(event => {
204
183
  event.preventDefault();
205
184
  if (event.target.name === keyName) {
206
- var currentWidthKeyInput = (0, _formChipCell.getTextWidth)(refInputKey.current);
207
- setChipData(function (prevState) {
208
- return _objectSpread(_objectSpread({}, prevState), {}, {
209
- key: refInputKey.current.value,
210
- keyFieldWidth: refInputKey.current.value.length <= 1 ? minWidthInput : currentWidthKeyInput >= maxWidthInput ? maxWidthInput : currentWidthKeyInput > minWidthInput ? currentWidthKeyInput + 2 : minWidthInput
211
- });
212
- });
185
+ const currentWidthKeyInput = (0, _formChipCell.getTextWidth)(refInputKey.current);
186
+ setChipData(prevState => ({
187
+ ...prevState,
188
+ key: refInputKey.current.value,
189
+ keyFieldWidth: refInputKey.current.value.length <= 1 ? minWidthInput : currentWidthKeyInput >= maxWidthInput ? maxWidthInput : currentWidthKeyInput > minWidthInput ? currentWidthKeyInput + 2 : minWidthInput
190
+ }));
213
191
  } else {
214
- var currentWidthValueInput = (0, _formChipCell.getTextWidth)(refInputValue.current);
215
- setChipData(function (prevState) {
192
+ const currentWidthValueInput = (0, _formChipCell.getTextWidth)(refInputValue.current);
193
+ setChipData(prevState => {
216
194
  var _refInputValue$curren;
217
- return _objectSpread(_objectSpread({}, prevState), {}, {
195
+ return {
196
+ ...prevState,
218
197
  value: refInputValue.current.value,
219
198
  valueFieldWidth: ((_refInputValue$curren = refInputValue.current.value) === null || _refInputValue$curren === void 0 ? void 0 : _refInputValue$curren.length) <= 1 ? minWidthValueInput : currentWidthValueInput >= maxWidthInput ? maxWidthInput : currentWidthValueInput > minWidthValueInput ? currentWidthValueInput + 2 : minWidthValueInput
220
- });
199
+ };
221
200
  });
222
201
  }
223
202
  }, [maxWidthInput, refInputKey, refInputValue, keyName]);
224
- (0, _react.useLayoutEffect)(function () {
203
+ (0, _react.useLayoutEffect)(() => {
225
204
  if (editConfig.chipIndex === chipIndex) {
226
205
  setSelectedInput(editConfig.isKeyFocused ? 'key' : editConfig.isValueFocused ? 'value' : null);
227
206
  }
228
207
  }, [editConfig.isKeyFocused, editConfig.isValueFocused, editConfig.chipIndex, chipIndex]);
229
- (0, _react.useEffect)(function () {
208
+ (0, _react.useEffect)(() => {
230
209
  if (meta.valid && showValidationRules) {
231
210
  setShowValidationRules(false);
232
211
  }
233
212
  }, [meta.valid, showValidationRules]);
234
- (0, _react.useEffect)(function () {
213
+ (0, _react.useEffect)(() => {
235
214
  if (meta.error) {
236
- setValidationRules(function (prevState) {
215
+ setValidationRules(prevState => {
237
216
  var _prevState$selectedIn;
238
- return _objectSpread(_objectSpread({}, prevState), {}, _defineProperty({}, selectedInput, (_prevState$selectedIn = prevState[selectedInput]) === null || _prevState$selectedIn === void 0 ? void 0 : _prevState$selectedIn.map(function (rule) {
239
- return _objectSpread(_objectSpread({}, rule), {}, {
240
- isValid: (0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', editConfig.chipIndex, selectedInput], [])) ? true : !meta.error[editConfig.chipIndex][selectedInput].some(function (err) {
241
- return err && err.name === rule.name;
242
- })
243
- });
244
- })));
217
+ return {
218
+ ...prevState,
219
+ [selectedInput]: (_prevState$selectedIn = prevState[selectedInput]) === null || _prevState$selectedIn === void 0 ? void 0 : _prevState$selectedIn.map(rule => {
220
+ return {
221
+ ...rule,
222
+ isValid: (0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', editConfig.chipIndex, selectedInput], [])) ? true : !meta.error[editConfig.chipIndex][selectedInput].some(err => err && err.name === rule.name)
223
+ };
224
+ })
225
+ };
245
226
  });
246
227
  !showValidationRules && setShowValidationRules(true);
247
228
  }
248
229
  }, [meta, showValidationRules, selectedInput, editConfig.chipIndex]);
249
- var getValidationRules = (0, _react.useCallback)(function () {
230
+ const getValidationRules = (0, _react.useCallback)(() => {
250
231
  var _validationRules$sele;
251
- return (_validationRules$sele = validationRules[selectedInput]) === null || _validationRules$sele === void 0 ? void 0 : _validationRules$sele.map(function (_ref2) {
252
- var _ref2$isValid = _ref2.isValid,
253
- isValid = _ref2$isValid === void 0 ? false : _ref2$isValid,
254
- label = _ref2.label,
255
- name = _ref2.name;
232
+ return (_validationRules$sele = validationRules[selectedInput]) === null || _validationRules$sele === void 0 ? void 0 : _validationRules$sele.map(_ref2 => {
233
+ let {
234
+ isValid = false,
235
+ label,
236
+ name
237
+ } = _ref2;
256
238
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ValidationTemplate.default, {
257
239
  valid: isValid,
258
240
  validationMessage: label
@@ -261,9 +243,7 @@ var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
261
243
  }, [selectedInput, validationRules]);
262
244
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
263
245
  className: labelContainerClassName,
264
- onKeyDown: function onKeyDown(event) {
265
- return editConfig.isEdit && focusChip(event);
266
- },
246
+ onKeyDown: event => editConfig.isEdit && focusChip(event),
267
247
  ref: refInputContainer,
268
248
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_NewChipInput.default, {
269
249
  className: labelKeyClassName,
@@ -292,9 +272,7 @@ var NewChipForm = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
292
272
  }
293
273
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
294
274
  className: closeButtonClass,
295
- onClick: function onClick(event) {
296
- return handleRemoveChip(event, chipIndex);
297
- },
275
+ onClick: event => handleRemoveChip(event, chipIndex),
298
276
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_close.ReactComponent, {})
299
277
  }), (editConfig.isKeyFocused ? !(0, _lodash.isEmpty)(chipData.key) : !(0, _lodash.isEmpty)(chipData.value)) && editConfig.chipIndex === chipIndex && !(0, _lodash.isEmpty)((0, _lodash.get)(meta, ['error', editConfig.chipIndex, selectedInput], [])) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_OptionsMenu.default, {
300
278
  show: showValidationRules,
@@ -322,5 +300,4 @@ NewChipForm.propTypes = {
322
300
  validationRules: _propTypes.default.object,
323
301
  valueName: _propTypes.default.string.isRequired
324
302
  };
325
- var _default = NewChipForm;
326
- exports.default = _default;
303
+ var _default = exports.default = NewChipForm;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
@@ -9,7 +8,7 @@ var _react = _interopRequireDefault(require("react"));
9
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
9
  var _reactFinalForm = require("react-final-form");
11
10
  var _jsxRuntime = require("react/jsx-runtime");
12
- var _excluded = ["name", "onChange", "onFocus"];
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
12
  /*
14
13
  Copyright 2022 Iguazio Systems Ltd.
15
14
  Licensed under the Apache License, Version 2.0 (the "License") with
@@ -26,43 +25,42 @@ illegal under applicable law, and the grant of the foregoing license
26
25
  under the Apache 2.0 license is conditioned upon your compliance with
27
26
  such restriction.
28
27
  */
29
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
32
- 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; }
33
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
34
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
35
- 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; }
36
- 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; }
37
- var NewChipInput = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
38
- var name = _ref.name,
39
- onChange = _ref.onChange,
40
- onFocus = _ref.onFocus,
41
- inputProps = _objectWithoutProperties(_ref, _excluded);
42
- var _useField = (0, _reactFinalForm.useField)(name),
43
- input = _useField.input;
44
- var handleInputChange = function handleInputChange(event) {
28
+
29
+ const NewChipInput = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
30
+ let {
31
+ name,
32
+ onChange,
33
+ onFocus,
34
+ ...inputProps
35
+ } = _ref;
36
+ const {
37
+ input
38
+ } = (0, _reactFinalForm.useField)(name);
39
+ const handleInputChange = event => {
45
40
  input.onChange(event);
46
41
  onChange(event);
47
42
  };
48
- var handleInputFocus = function handleInputFocus(event) {
43
+ const handleInputFocus = event => {
49
44
  input.onFocus(event);
50
45
  onFocus(event);
51
46
  };
52
47
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactFinalForm.Field, {
53
48
  name: name,
54
- children: function children(_ref2) {
55
- var input = _ref2.input;
56
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("input", _objectSpread(_objectSpread({
49
+ children: _ref2 => {
50
+ let {
51
+ input
52
+ } = _ref2;
53
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
57
54
  autoComplete: "off",
58
55
  "data-testid": "input",
59
56
  ref: ref,
60
57
  type: "text",
61
- id: input.name
62
- }, _objectSpread(_objectSpread({}, inputProps), input)), {}, {
58
+ id: input.name,
59
+ ...inputProps,
60
+ ...input,
63
61
  onChange: handleInputChange,
64
62
  onFocus: handleInputFocus
65
- }));
63
+ });
66
64
  }
67
65
  });
68
66
  });
@@ -71,5 +69,4 @@ NewChipInput.propTypes = {
71
69
  onChange: _propTypes.default.func.isRequired,
72
70
  onFocus: _propTypes.default.func.isRequired
73
71
  };
74
- var _default = NewChipInput;
75
- exports.default = _default;
72
+ var _default = exports.default = NewChipInput;
@@ -4,12 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.uniquenessError = exports.getTextWidth = void 0;
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
- 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
- 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 _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; }
11
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
7
  /*
14
8
  Copyright 2022 Iguazio Systems Ltd.
15
9
  Licensed under the Apache License, Version 2.0 (the "License") with
@@ -26,30 +20,26 @@ illegal under applicable law, and the grant of the foregoing license
26
20
  under the Apache 2.0 license is conditioned upon your compliance with
27
21
  such restriction.
28
22
  */
29
- var uniquenessError = {
23
+ const uniquenessError = exports.uniquenessError = {
30
24
  name: 'uniqueness',
31
25
  label: 'Key must be unique'
32
26
  };
33
- exports.uniquenessError = uniquenessError;
34
- var getTextWidth = function getTextWidth(elementWithText) {
27
+ const getTextWidth = elementWithText => {
35
28
  var _hiddenElement$offset;
36
29
  if (!elementWithText) {
37
30
  return 0;
38
31
  }
39
- var hiddenElementId = 'chips-hidden-element';
40
- var hiddenElement = document.getElementById(hiddenElementId);
32
+ const hiddenElementId = 'chips-hidden-element';
33
+ let hiddenElement = document.getElementById(hiddenElementId);
41
34
  if (!hiddenElement) {
42
35
  hiddenElement = document.createElement('span');
43
- var styles = {
36
+ const styles = {
44
37
  position: 'absolute',
45
38
  left: '-10000px',
46
39
  top: "auto",
47
40
  visibility: 'hidden'
48
41
  };
49
- for (var _i = 0, _Object$entries = Object.entries(styles); _i < _Object$entries.length; _i++) {
50
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
51
- styleName = _Object$entries$_i[0],
52
- styleValue = _Object$entries$_i[1];
42
+ for (const [styleName, styleValue] of Object.entries(styles)) {
53
43
  hiddenElement.style[styleName] = styleValue;
54
44
  }
55
45
  hiddenElement.style.font = window.getComputedStyle(elementWithText).font;