@bigbinary/neeto-molecules 4.0.30 → 4.0.31
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.
- package/dist/OptionFields.js +408 -95
- package/dist/OptionFields.js.map +1 -1
- package/dist/cjs/OptionFields.js +406 -93
- package/dist/cjs/OptionFields.js.map +1 -1
- package/package.json +1 -1
- package/types/OptionFields.d.ts +11 -1
package/dist/OptionFields.js
CHANGED
|
@@ -6,19 +6,20 @@ import { useField, FieldArray } from 'formik';
|
|
|
6
6
|
import { isNotPresent, slugify, findIndexById, isNotEmpty, noop } from '@bigbinary/neeto-cist';
|
|
7
7
|
import Plus from '@bigbinary/neeto-icons/Plus';
|
|
8
8
|
import Button from '@bigbinary/neetoui/Button';
|
|
9
|
-
import { reject, prop, pluck, move, assocPath, remove, append, isEmpty } from 'ramda';
|
|
9
|
+
import { identity, reject, prop, pluck, clone, insert, move, assocPath, remove, append, isEmpty } from 'ramda';
|
|
10
10
|
import { useTranslation, Trans } from 'react-i18next';
|
|
11
11
|
import Modal from '@bigbinary/neetoui/Modal';
|
|
12
12
|
import Textarea from '@bigbinary/neetoui/Textarea';
|
|
13
13
|
import Typography from '@bigbinary/neetoui/Typography';
|
|
14
14
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
15
|
-
import i18next from 'i18next';
|
|
15
|
+
import i18next, { t } from 'i18next';
|
|
16
16
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
17
17
|
import { n } from './inject-css-C2dztUxs.js';
|
|
18
18
|
import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
19
|
-
import Delete from '@bigbinary/neeto-icons/Delete';
|
|
20
19
|
import Edit from '@bigbinary/neeto-icons/Edit';
|
|
21
20
|
import Drag from '@bigbinary/neeto-icons/Drag';
|
|
21
|
+
import Copy from '@bigbinary/neeto-icons/Copy';
|
|
22
|
+
import Delete from '@bigbinary/neeto-icons/Delete';
|
|
22
23
|
import Input from '@bigbinary/neetoui/formik/Input';
|
|
23
24
|
import Textarea$1 from '@bigbinary/neetoui/formik/Textarea';
|
|
24
25
|
import ImageUploader from '@bigbinary/neeto-image-uploader-frontend/ImageUploader';
|
|
@@ -102,6 +103,20 @@ var IMAGE_UPLOAD_CONFIG = {
|
|
|
102
103
|
"image/svg": [".svg"]
|
|
103
104
|
}
|
|
104
105
|
};
|
|
106
|
+
var INPUT_TYPES = {
|
|
107
|
+
TEXT: "text",
|
|
108
|
+
NUMBER: "number"
|
|
109
|
+
};
|
|
110
|
+
var OPTION_ACTIONS = {
|
|
111
|
+
UPDATE_IMAGE: "update_image",
|
|
112
|
+
UPDATE_VALUES: "update_values",
|
|
113
|
+
UPDATE_LABEL: "update_label",
|
|
114
|
+
DELETE: "delete",
|
|
115
|
+
REORDER: "reorder",
|
|
116
|
+
ADD: "add",
|
|
117
|
+
BULK_ADD: "bulk_add",
|
|
118
|
+
CLONE: "clone"
|
|
119
|
+
};
|
|
105
120
|
|
|
106
121
|
var FormError = function FormError(_ref) {
|
|
107
122
|
var error = _ref.error;
|
|
@@ -147,12 +162,53 @@ var resolveFormikValue = function resolveFormikValue(path, values) {
|
|
|
147
162
|
return acc && acc[key] !== undefined ? acc[key] : undefined;
|
|
148
163
|
}, values);
|
|
149
164
|
};
|
|
165
|
+
var handleNumberKeyDown = function handleNumberKeyDown(event, onKeyDown) {
|
|
166
|
+
var allowedKeys = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "-"];
|
|
167
|
+
var controlKeys = ["Backspace", "Delete", "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Tab", "Enter"];
|
|
168
|
+
if ((event.ctrlKey || event.metaKey) && ["a", "c", "v", "x", "z"].includes(event.key.toLowerCase())) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (![].concat(allowedKeys, controlKeys).includes(event.key)) {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
}
|
|
174
|
+
onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
|
|
175
|
+
};
|
|
176
|
+
var handleInputBlur = function handleInputBlur(event, _ref) {
|
|
177
|
+
var id = _ref.id,
|
|
178
|
+
inputIndex = _ref.inputIndex,
|
|
179
|
+
onChange = _ref.onChange,
|
|
180
|
+
onBlur = _ref.onBlur,
|
|
181
|
+
field = _ref.field,
|
|
182
|
+
config = _ref.config;
|
|
183
|
+
var value = event.target.value;
|
|
184
|
+
var finalValue = !value && config !== null && config !== void 0 && config.defaultValue ? config.defaultValue : value;
|
|
185
|
+
onChange({
|
|
186
|
+
id: id,
|
|
187
|
+
value: finalValue,
|
|
188
|
+
inputIndex: inputIndex,
|
|
189
|
+
isOnBlur: true
|
|
190
|
+
});
|
|
191
|
+
onBlur === null || onBlur === void 0 || onBlur(id, finalValue, inputIndex);
|
|
192
|
+
field.onBlur(event);
|
|
193
|
+
};
|
|
194
|
+
var getMultiInputError = function getMultiInputError(isMultiInput, meta) {
|
|
195
|
+
if (!isMultiInput || !meta.error) return null;
|
|
196
|
+
if (Array.isArray(meta.error)) {
|
|
197
|
+
var hasValuesError = meta.error.some(function (optionError) {
|
|
198
|
+
return Array.isArray(optionError.values) && optionError.values.some(identity);
|
|
199
|
+
});
|
|
200
|
+
if (hasValuesError) {
|
|
201
|
+
return t("neetoMolecules.optionFields.allFieldsRequired");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
};
|
|
150
206
|
|
|
151
|
-
function ownKeys$
|
|
152
|
-
function _objectSpread$
|
|
207
|
+
function ownKeys$5(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; }
|
|
208
|
+
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
153
209
|
var attachPosition = function attachPosition(options) {
|
|
154
210
|
return options.map(function (option, index) {
|
|
155
|
-
return _objectSpread$
|
|
211
|
+
return _objectSpread$5(_objectSpread$5({}, option), {}, {
|
|
156
212
|
position: index
|
|
157
213
|
});
|
|
158
214
|
});
|
|
@@ -167,7 +223,11 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
167
223
|
destroyFlagName = _ref.destroyFlagName,
|
|
168
224
|
isNewItemsPrefilled = _ref.isNewItemsPrefilled,
|
|
169
225
|
isAddOptionEnabled = _ref.isAddOptionEnabled,
|
|
170
|
-
isPictureChoice = _ref.isPictureChoice
|
|
226
|
+
isPictureChoice = _ref.isPictureChoice,
|
|
227
|
+
isMultiInput = _ref.isMultiInput,
|
|
228
|
+
inputConfig = _ref.inputConfig;
|
|
229
|
+
var _useTranslation = useTranslation(),
|
|
230
|
+
t = _useTranslation.t;
|
|
171
231
|
var _useState = useState(false),
|
|
172
232
|
_useState2 = _slicedToArray(_useState, 2),
|
|
173
233
|
shouldFocus = _useState2[0],
|
|
@@ -182,9 +242,15 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
182
242
|
_useField2[1];
|
|
183
243
|
var helpers = _useField2[2];
|
|
184
244
|
var setValue = helpers.setValue;
|
|
185
|
-
var handleChange = function handleChange(
|
|
186
|
-
var
|
|
187
|
-
|
|
245
|
+
var handleChange = function handleChange(_ref2) {
|
|
246
|
+
var id = _ref2.id,
|
|
247
|
+
value = _ref2.value,
|
|
248
|
+
_ref2$inputIndex = _ref2.inputIndex,
|
|
249
|
+
inputIndex = _ref2$inputIndex === void 0 ? 0 : _ref2$inputIndex,
|
|
250
|
+
_ref2$isOnBlur = _ref2.isOnBlur,
|
|
251
|
+
isOnBlur = _ref2$isOnBlur === void 0 ? false : _ref2$isOnBlur,
|
|
252
|
+
_ref2$fieldType = _ref2.fieldType,
|
|
253
|
+
fieldType = _ref2$fieldType === void 0 ? "label" : _ref2$fieldType;
|
|
188
254
|
var index = findIndexById(id, options);
|
|
189
255
|
var currentOption = options[index];
|
|
190
256
|
|
|
@@ -192,7 +258,18 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
192
258
|
if (isPictureChoice && fieldType === "image") {
|
|
193
259
|
var _nextOptions = assocPath([index, "image"], value, options);
|
|
194
260
|
setValue(_nextOptions);
|
|
195
|
-
onChange === null || onChange === void 0 || onChange(_nextOptions);
|
|
261
|
+
onChange === null || onChange === void 0 || onChange(_nextOptions, OPTION_ACTIONS.UPDATE_IMAGE);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Handle multi-input changes
|
|
266
|
+
if (isMultiInput && typeof inputIndex === "number") {
|
|
267
|
+
var currentValues = currentOption.values || [];
|
|
268
|
+
var newValues = clone(currentValues);
|
|
269
|
+
newValues[inputIndex] = value;
|
|
270
|
+
var _nextOptions2 = assocPath([index, "values"], newValues, options);
|
|
271
|
+
setValue(_nextOptions2);
|
|
272
|
+
onChange === null || onChange === void 0 || onChange(_nextOptions2, OPTION_ACTIONS.UPDATE_VALUES);
|
|
196
273
|
return;
|
|
197
274
|
}
|
|
198
275
|
|
|
@@ -212,7 +289,7 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
212
289
|
// Update options with the determined value (always updating label field)
|
|
213
290
|
var nextOptions = assocPath([index, "label"], valueToUpdate, options);
|
|
214
291
|
setValue(nextOptions);
|
|
215
|
-
onChange === null || onChange === void 0 || onChange(nextOptions);
|
|
292
|
+
onChange === null || onChange === void 0 || onChange(nextOptions, OPTION_ACTIONS.UPDATE_LABEL);
|
|
216
293
|
};
|
|
217
294
|
var handleDelete = function handleDelete(id, arrayHelpers) {
|
|
218
295
|
var nextOptions;
|
|
@@ -224,11 +301,11 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
224
301
|
arrayHelpers.remove(indexToDelete);
|
|
225
302
|
nextOptions = attachPosition(remove(indexToDelete, 1, options));
|
|
226
303
|
}
|
|
227
|
-
onChange === null || onChange === void 0 || onChange(nextOptions);
|
|
304
|
+
onChange === null || onChange === void 0 || onChange(nextOptions, OPTION_ACTIONS.DELETE);
|
|
228
305
|
};
|
|
229
|
-
var handleDragEnd = function handleDragEnd(
|
|
230
|
-
var source =
|
|
231
|
-
destination =
|
|
306
|
+
var handleDragEnd = function handleDragEnd(_ref3) {
|
|
307
|
+
var source = _ref3.source,
|
|
308
|
+
destination = _ref3.destination;
|
|
232
309
|
// When dragged outside of draggable
|
|
233
310
|
if (destination === null) return;
|
|
234
311
|
var deletedOptions = options.filter(prop(destroyFlagName));
|
|
@@ -236,22 +313,26 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
236
313
|
var nextOptions = move(source.index, destination.index, filteredOptions);
|
|
237
314
|
var finalOptions = attachPosition(nextOptions);
|
|
238
315
|
setValue([].concat(_toConsumableArray(deletedOptions), _toConsumableArray(finalOptions)));
|
|
239
|
-
onChange === null || onChange === void 0 || onChange([].concat(_toConsumableArray(deletedOptions), _toConsumableArray(finalOptions)));
|
|
316
|
+
onChange === null || onChange === void 0 || onChange([].concat(_toConsumableArray(deletedOptions), _toConsumableArray(finalOptions)), OPTION_ACTIONS.REORDER);
|
|
240
317
|
};
|
|
241
318
|
var handleAddOption = function handleAddOption() {
|
|
242
319
|
var id = randomId();
|
|
243
|
-
var newOption = _objectSpread$
|
|
320
|
+
var newOption = _objectSpread$5(_objectSpread$5({
|
|
244
321
|
id: "draft-".concat(id),
|
|
245
322
|
altId: "alt-".concat(id),
|
|
246
323
|
label: isNewItemsPrefilled ? _generateLabel(itemLabel, options) : "",
|
|
247
324
|
position: options.length
|
|
248
325
|
}, isPictureChoice && {
|
|
249
326
|
image: null
|
|
327
|
+
}), isMultiInput && {
|
|
328
|
+
values: inputConfig.map(function (config) {
|
|
329
|
+
return config.defaultValue || "";
|
|
330
|
+
})
|
|
250
331
|
});
|
|
251
332
|
setShouldFocus(true);
|
|
252
333
|
var nextOptions = append(newOption, options);
|
|
253
334
|
setValue(nextOptions);
|
|
254
|
-
onChange === null || onChange === void 0 || onChange(nextOptions);
|
|
335
|
+
onChange === null || onChange === void 0 || onChange(nextOptions, OPTION_ACTIONS.ADD);
|
|
255
336
|
};
|
|
256
337
|
var handleBulkAddOption = function handleBulkAddOption(optionsString) {
|
|
257
338
|
setShouldFocus(true);
|
|
@@ -266,7 +347,27 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
266
347
|
});
|
|
267
348
|
var nextOptions = [].concat(_toConsumableArray(options), _toConsumableArray(newOptions));
|
|
268
349
|
setValue(nextOptions);
|
|
269
|
-
onChange === null || onChange === void 0 || onChange(nextOptions);
|
|
350
|
+
onChange === null || onChange === void 0 || onChange(nextOptions, OPTION_ACTIONS.BULK_ADD);
|
|
351
|
+
};
|
|
352
|
+
var handleClone = function handleClone(id) {
|
|
353
|
+
var index = findIndexById(id, options);
|
|
354
|
+
var optionToClone = options[index];
|
|
355
|
+
if (!optionToClone) return;
|
|
356
|
+
var newId = randomId();
|
|
357
|
+
var clonedOption = _objectSpread$5(_objectSpread$5({}, optionToClone), {}, {
|
|
358
|
+
id: "draft-".concat(newId),
|
|
359
|
+
altId: "alt-".concat(newId),
|
|
360
|
+
label: isMultiInput ? optionToClone.label : t("neetoMolecules.optionFields.clonedOption", {
|
|
361
|
+
originalLabel: optionToClone.label
|
|
362
|
+
})
|
|
363
|
+
}, isMultiInput && optionToClone.values && {
|
|
364
|
+
values: clone(optionToClone.values)
|
|
365
|
+
});
|
|
366
|
+
setShouldFocus(true);
|
|
367
|
+
var nextOptions = insert(index + 1, clonedOption, options);
|
|
368
|
+
var optionsWithUpdatedPositions = attachPosition(nextOptions);
|
|
369
|
+
setValue(optionsWithUpdatedPositions);
|
|
370
|
+
onChange === null || onChange === void 0 || onChange(optionsWithUpdatedPositions, OPTION_ACTIONS.CLONE);
|
|
270
371
|
};
|
|
271
372
|
var handleKeyDown = function handleKeyDown(event) {
|
|
272
373
|
if (event.key !== "Enter") return;
|
|
@@ -289,17 +390,18 @@ var useOptionFields = function useOptionFields(_ref) {
|
|
|
289
390
|
handleChange: handleChange,
|
|
290
391
|
handleKeyDown: handleKeyDown,
|
|
291
392
|
handleDelete: handleDelete,
|
|
292
|
-
handleDragEnd: handleDragEnd
|
|
393
|
+
handleDragEnd: handleDragEnd,
|
|
394
|
+
handleClone: handleClone
|
|
293
395
|
};
|
|
294
396
|
};
|
|
295
397
|
|
|
296
398
|
var css = ".neeto-molecules-option-fields__image-uploader img{max-height:100px}";
|
|
297
399
|
n(css,{});
|
|
298
400
|
|
|
299
|
-
function ownKeys$
|
|
300
|
-
function _objectSpread$
|
|
401
|
+
function ownKeys$4(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; }
|
|
402
|
+
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
301
403
|
var DragHandle = function DragHandle(props) {
|
|
302
|
-
return /*#__PURE__*/jsx("div", _objectSpread$
|
|
404
|
+
return /*#__PURE__*/jsx("div", _objectSpread$4(_objectSpread$4({
|
|
303
405
|
className: "neeto-ui-text-gray-500 flex h-8 flex-shrink-0 cursor-grab items-center",
|
|
304
406
|
"data-cy": "drag-handle",
|
|
305
407
|
"data-testid": "drag-handle"
|
|
@@ -311,29 +413,84 @@ var DragHandle = function DragHandle(props) {
|
|
|
311
413
|
}));
|
|
312
414
|
};
|
|
313
415
|
|
|
314
|
-
|
|
315
|
-
|
|
416
|
+
var OptionActions = withT(function (_ref) {
|
|
417
|
+
var t = _ref.t,
|
|
418
|
+
disabled = _ref.disabled,
|
|
419
|
+
_ref$hideCloneOption = _ref.hideCloneOption,
|
|
420
|
+
hideCloneOption = _ref$hideCloneOption === void 0 ? false : _ref$hideCloneOption,
|
|
421
|
+
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
422
|
+
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
423
|
+
optionIndex = _ref.optionIndex,
|
|
424
|
+
id = _ref.id,
|
|
425
|
+
arrayHelpers = _ref.arrayHelpers,
|
|
426
|
+
onClone = _ref.onClone,
|
|
427
|
+
onDelete = _ref.onDelete,
|
|
428
|
+
_ref$className = _ref.className,
|
|
429
|
+
className = _ref$className === void 0 ? "" : _ref$className;
|
|
430
|
+
return /*#__PURE__*/jsxs("div", {
|
|
431
|
+
className: "flex items-center gap-1 ".concat(className),
|
|
432
|
+
children: [!hideCloneOption && /*#__PURE__*/jsx(Button, {
|
|
433
|
+
disabled: disabled,
|
|
434
|
+
className: "p-0.5",
|
|
435
|
+
"data-cy": "clone-option-button-".concat(optionIndex),
|
|
436
|
+
"data-testid": "clone-option-button-".concat(optionIndex),
|
|
437
|
+
icon: Copy,
|
|
438
|
+
size: "small",
|
|
439
|
+
style: "text",
|
|
440
|
+
tooltipProps: {
|
|
441
|
+
content: t("neetoMolecules.common.actions.clone"),
|
|
442
|
+
position: "top",
|
|
443
|
+
touch: ["hold", 500]
|
|
444
|
+
},
|
|
445
|
+
onClick: function onClick() {
|
|
446
|
+
return onClone(id);
|
|
447
|
+
}
|
|
448
|
+
}), !hideDeleteOption && /*#__PURE__*/jsx(Button, {
|
|
449
|
+
disabled: disabled,
|
|
450
|
+
className: "p-0.5",
|
|
451
|
+
"data-cy": "delete-option-button-".concat(optionIndex),
|
|
452
|
+
"data-testid": "delete-option-button-".concat(optionIndex),
|
|
453
|
+
icon: Delete,
|
|
454
|
+
size: "small",
|
|
455
|
+
style: "text",
|
|
456
|
+
tooltipProps: {
|
|
457
|
+
content: t("neetoMolecules.common.actions.delete"),
|
|
458
|
+
position: "top",
|
|
459
|
+
touch: ["hold", 500]
|
|
460
|
+
},
|
|
461
|
+
onClick: function onClick() {
|
|
462
|
+
return onDelete(id, arrayHelpers);
|
|
463
|
+
}
|
|
464
|
+
})]
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
function ownKeys$3(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; }
|
|
469
|
+
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
316
470
|
var BlockOption = withT(function (_ref) {
|
|
317
471
|
var t = _ref.t,
|
|
318
472
|
innerRef = _ref.innerRef,
|
|
319
473
|
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
320
474
|
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
475
|
+
_ref$hideCloneOption = _ref.hideCloneOption,
|
|
476
|
+
hideCloneOption = _ref$hideCloneOption === void 0 ? false : _ref$hideCloneOption,
|
|
321
477
|
draggableProps = _ref.draggableProps,
|
|
322
478
|
dragHandleProps = _ref.dragHandleProps,
|
|
323
479
|
label = _ref.label,
|
|
324
480
|
onEdit = _ref.onEdit,
|
|
481
|
+
onClone = _ref.onClone,
|
|
325
482
|
handleDeleteClick = _ref.handleDeleteClick,
|
|
326
483
|
id = _ref.id,
|
|
327
484
|
isDraggable = _ref.isDraggable,
|
|
328
485
|
optionIndex = _ref.optionIndex,
|
|
329
486
|
arrayHelpers = _ref.arrayHelpers;
|
|
330
|
-
return /*#__PURE__*/jsx("div", _objectSpread$
|
|
487
|
+
return /*#__PURE__*/jsx("div", _objectSpread$3(_objectSpread$3(_objectSpread$3({
|
|
331
488
|
ref: innerRef
|
|
332
489
|
}, draggableProps), dragHandleProps), {}, {
|
|
333
490
|
children: /*#__PURE__*/jsxs("div", {
|
|
334
491
|
className: "neeto-ui-border-gray-400 hover:neeto-ui-bg-gray-200 neeto-ui-rounded-sm shadow-xs group relative mb-2 flex h-10 cursor-pointer items-center gap-2 border p-3 transition-colors duration-300 ease-in-out",
|
|
335
492
|
"data-cy": "address-field-block",
|
|
336
|
-
children: [isDraggable && /*#__PURE__*/jsx(DragHandle, _objectSpread$
|
|
493
|
+
children: [isDraggable && /*#__PURE__*/jsx(DragHandle, _objectSpread$3(_objectSpread$3({}, dragHandleProps), {}, {
|
|
337
494
|
"data-testid": "drag-handle-".concat(optionIndex)
|
|
338
495
|
})), /*#__PURE__*/jsx(Typography, {
|
|
339
496
|
className: "flex-grow truncate leading-4",
|
|
@@ -358,21 +515,15 @@ var BlockOption = withT(function (_ref) {
|
|
|
358
515
|
onClick: function onClick() {
|
|
359
516
|
return onEdit(id);
|
|
360
517
|
}
|
|
361
|
-
}),
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
position: "top",
|
|
371
|
-
touch: ["hold", 500]
|
|
372
|
-
},
|
|
373
|
-
onClick: function onClick() {
|
|
374
|
-
return handleDeleteClick(id, arrayHelpers);
|
|
375
|
-
}
|
|
518
|
+
}), /*#__PURE__*/jsx(OptionActions, {
|
|
519
|
+
arrayHelpers: arrayHelpers,
|
|
520
|
+
hideCloneOption: hideCloneOption,
|
|
521
|
+
hideDeleteOption: hideDeleteOption,
|
|
522
|
+
id: id,
|
|
523
|
+
onClone: onClone,
|
|
524
|
+
optionIndex: optionIndex,
|
|
525
|
+
className: "flex items-center gap-2",
|
|
526
|
+
onDelete: handleDeleteClick
|
|
376
527
|
})]
|
|
377
528
|
})]
|
|
378
529
|
})
|
|
@@ -391,11 +542,12 @@ var ImageOption = function ImageOption(_ref) {
|
|
|
391
542
|
_onChange = _ref.onChange,
|
|
392
543
|
_onBlur = _ref.onBlur,
|
|
393
544
|
onDelete = _ref.onDelete,
|
|
545
|
+
onClone = _ref.onClone,
|
|
394
546
|
arrayHelpers = _ref.arrayHelpers,
|
|
395
547
|
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
396
|
-
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption
|
|
397
|
-
|
|
398
|
-
|
|
548
|
+
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
549
|
+
_ref$hideCloneOption = _ref.hideCloneOption,
|
|
550
|
+
hideCloneOption = _ref$hideCloneOption === void 0 ? false : _ref$hideCloneOption;
|
|
399
551
|
var imageFieldName = name.replace(".label", ".image");
|
|
400
552
|
var _useField = useField(imageFieldName),
|
|
401
553
|
_useField2 = _slicedToArray(_useField, 3);
|
|
@@ -405,7 +557,12 @@ var ImageOption = function ImageOption(_ref) {
|
|
|
405
557
|
var handleImageChange = function handleImageChange(changedImage) {
|
|
406
558
|
var imageValue = isEmpty(changedImage === null || changedImage === void 0 ? void 0 : changedImage.url) ? null : changedImage;
|
|
407
559
|
setValue(imageValue, false);
|
|
408
|
-
_onChange(
|
|
560
|
+
_onChange({
|
|
561
|
+
id: id,
|
|
562
|
+
value: imageValue,
|
|
563
|
+
isOnBlur: false,
|
|
564
|
+
fieldType: "image"
|
|
565
|
+
});
|
|
409
566
|
};
|
|
410
567
|
return /*#__PURE__*/jsx("div", {
|
|
411
568
|
className: classnames("flex w-full items-center justify-center", {
|
|
@@ -436,56 +593,59 @@ var ImageOption = function ImageOption(_ref) {
|
|
|
436
593
|
"data-testid": "input-option-".concat(optionIndex),
|
|
437
594
|
onChange: function onChange(_ref2) {
|
|
438
595
|
var target = _ref2.target;
|
|
439
|
-
return _onChange(
|
|
596
|
+
return _onChange({
|
|
597
|
+
id: id,
|
|
598
|
+
value: target.value
|
|
599
|
+
});
|
|
440
600
|
},
|
|
441
601
|
onFocus: function onFocus(_ref3) {
|
|
442
602
|
var target = _ref3.target;
|
|
443
603
|
return target.select();
|
|
444
604
|
}
|
|
445
605
|
}, "onBlur", function onBlur(event) {
|
|
446
|
-
_onChange(
|
|
606
|
+
_onChange({
|
|
607
|
+
id: id,
|
|
608
|
+
value: event.target.value,
|
|
609
|
+
isOnBlur: true
|
|
610
|
+
});
|
|
447
611
|
_onBlur === null || _onBlur === void 0 || _onBlur(id, event.target.value);
|
|
448
612
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
449
613
|
args[_key - 1] = arguments[_key];
|
|
450
614
|
}
|
|
451
615
|
field.onBlur.apply(field, [event].concat(args));
|
|
452
616
|
}))
|
|
453
|
-
}),
|
|
454
|
-
className: "absolute right-
|
|
455
|
-
children: /*#__PURE__*/jsx(
|
|
617
|
+
}), /*#__PURE__*/jsx("div", {
|
|
618
|
+
className: "absolute right-3 top-1/2 flex -translate-y-1/2 items-center gap-1 opacity-0 transition-opacity duration-200 group-hover:opacity-100",
|
|
619
|
+
children: /*#__PURE__*/jsx(OptionActions, {
|
|
620
|
+
arrayHelpers: arrayHelpers,
|
|
456
621
|
disabled: disabled,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
tooltipProps: {
|
|
464
|
-
content: t("neetoMolecules.common.actions.delete"),
|
|
465
|
-
position: "top",
|
|
466
|
-
touch: ["hold", 500]
|
|
467
|
-
},
|
|
468
|
-
onClick: function onClick() {
|
|
469
|
-
return onDelete(id, arrayHelpers);
|
|
470
|
-
}
|
|
622
|
+
hideCloneOption: hideCloneOption,
|
|
623
|
+
hideDeleteOption: hideDeleteOption,
|
|
624
|
+
id: id,
|
|
625
|
+
onClone: onClone,
|
|
626
|
+
onDelete: onDelete,
|
|
627
|
+
optionIndex: optionIndex
|
|
471
628
|
})
|
|
472
629
|
})]
|
|
473
630
|
})
|
|
474
631
|
});
|
|
475
632
|
};
|
|
476
633
|
|
|
477
|
-
function ownKeys$
|
|
478
|
-
function _objectSpread$
|
|
634
|
+
function ownKeys$2(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; }
|
|
635
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
479
636
|
var InputOption = function InputOption(_ref) {
|
|
480
637
|
var shouldFocus = _ref.shouldFocus,
|
|
481
638
|
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
482
639
|
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
640
|
+
_ref$hideCloneOption = _ref.hideCloneOption,
|
|
641
|
+
hideCloneOption = _ref$hideCloneOption === void 0 ? false : _ref$hideCloneOption,
|
|
483
642
|
innerRef = _ref.innerRef,
|
|
484
643
|
draggableProps = _ref.draggableProps,
|
|
485
644
|
dragHandleProps = _ref.dragHandleProps,
|
|
486
645
|
isPictureChoice = _ref.isPictureChoice,
|
|
487
646
|
onKeyDown = _ref.onKeyDown,
|
|
488
647
|
onDelete = _ref.onDelete,
|
|
648
|
+
onClone = _ref.onClone,
|
|
489
649
|
_onChange = _ref.onChange,
|
|
490
650
|
optionIndex = _ref.optionIndex,
|
|
491
651
|
disabled = _ref.disabled,
|
|
@@ -496,29 +656,29 @@ var InputOption = function InputOption(_ref) {
|
|
|
496
656
|
placeholder = _ref.placeholder,
|
|
497
657
|
_onBlur = _ref.onBlur,
|
|
498
658
|
arrayHelpers = _ref.arrayHelpers;
|
|
499
|
-
var _useTranslation = useTranslation(),
|
|
500
|
-
t = _useTranslation.t;
|
|
501
659
|
var Component = isTextArea ? Textarea$1 : Input;
|
|
502
660
|
var _useField = useField(name),
|
|
503
661
|
_useField2 = _slicedToArray(_useField, 1),
|
|
504
662
|
field = _useField2[0];
|
|
505
|
-
return /*#__PURE__*/jsx("div", _objectSpread$
|
|
663
|
+
return /*#__PURE__*/jsx("div", _objectSpread$2(_objectSpread$2({
|
|
506
664
|
ref: innerRef
|
|
507
|
-
}, _objectSpread$
|
|
665
|
+
}, _objectSpread$2(_objectSpread$2({}, draggableProps), dragHandleProps)), {}, {
|
|
508
666
|
"data-cy": "form-block-options",
|
|
509
667
|
children: /*#__PURE__*/jsxs("div", {
|
|
510
668
|
className: "nf-input-options group relative mb-2 flex items-start gap-1",
|
|
511
|
-
children: [isDraggable && /*#__PURE__*/jsx(DragHandle, _objectSpread$
|
|
669
|
+
children: [isDraggable && /*#__PURE__*/jsx(DragHandle, _objectSpread$2(_objectSpread$2({}, dragHandleProps), {}, {
|
|
512
670
|
"data-testid": "drag-handle-".concat(optionIndex)
|
|
513
671
|
})), isPictureChoice ? /*#__PURE__*/jsx(ImageOption, {
|
|
514
672
|
arrayHelpers: arrayHelpers,
|
|
515
673
|
disabled: disabled,
|
|
516
674
|
field: field,
|
|
675
|
+
hideCloneOption: hideCloneOption,
|
|
517
676
|
hideDeleteOption: hideDeleteOption,
|
|
518
677
|
id: id,
|
|
519
678
|
name: name,
|
|
520
679
|
onBlur: _onBlur,
|
|
521
680
|
onChange: _onChange,
|
|
681
|
+
onClone: onClone,
|
|
522
682
|
onDelete: onDelete,
|
|
523
683
|
onKeyDown: onKeyDown,
|
|
524
684
|
optionIndex: optionIndex,
|
|
@@ -532,33 +692,33 @@ var InputOption = function InputOption(_ref) {
|
|
|
532
692
|
autoFocus: shouldFocus,
|
|
533
693
|
"data-cy": "option-input-".concat(optionIndex),
|
|
534
694
|
"data-testid": "".concat(isTextArea ? "textarea-option" : "input-option", "-").concat(optionIndex),
|
|
535
|
-
suffix:
|
|
695
|
+
suffix: /*#__PURE__*/jsx(OptionActions, {
|
|
696
|
+
arrayHelpers: arrayHelpers,
|
|
536
697
|
disabled: disabled,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
tooltipProps: {
|
|
544
|
-
content: t("neetoMolecules.common.actions.delete"),
|
|
545
|
-
position: "top",
|
|
546
|
-
touch: ["hold", 500]
|
|
547
|
-
},
|
|
548
|
-
onClick: function onClick() {
|
|
549
|
-
return onDelete(id, arrayHelpers);
|
|
550
|
-
}
|
|
698
|
+
hideCloneOption: hideCloneOption,
|
|
699
|
+
hideDeleteOption: hideDeleteOption,
|
|
700
|
+
id: id,
|
|
701
|
+
onClone: onClone,
|
|
702
|
+
onDelete: onDelete,
|
|
703
|
+
optionIndex: optionIndex
|
|
551
704
|
}),
|
|
552
705
|
onChange: function onChange(_ref2) {
|
|
553
706
|
var target = _ref2.target;
|
|
554
|
-
return _onChange(
|
|
707
|
+
return _onChange({
|
|
708
|
+
id: id,
|
|
709
|
+
value: target.value
|
|
710
|
+
});
|
|
555
711
|
},
|
|
556
712
|
onFocus: function onFocus(_ref3) {
|
|
557
713
|
var target = _ref3.target;
|
|
558
714
|
return target.select();
|
|
559
715
|
},
|
|
560
716
|
onBlur: function onBlur(event) {
|
|
561
|
-
_onChange(
|
|
717
|
+
_onChange({
|
|
718
|
+
id: id,
|
|
719
|
+
value: event.target.value,
|
|
720
|
+
isOnBlur: true
|
|
721
|
+
});
|
|
562
722
|
_onBlur === null || _onBlur === void 0 || _onBlur(id, event.target.value);
|
|
563
723
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
564
724
|
args[_key - 1] = arguments[_key];
|
|
@@ -570,19 +730,127 @@ var InputOption = function InputOption(_ref) {
|
|
|
570
730
|
}));
|
|
571
731
|
};
|
|
572
732
|
|
|
733
|
+
function ownKeys$1(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; }
|
|
734
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
735
|
+
var MultiInputOption = withT(function (_ref) {
|
|
736
|
+
var shouldFocus = _ref.shouldFocus,
|
|
737
|
+
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
738
|
+
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
739
|
+
_ref$hideCloneOption = _ref.hideCloneOption,
|
|
740
|
+
hideCloneOption = _ref$hideCloneOption === void 0 ? false : _ref$hideCloneOption,
|
|
741
|
+
innerRef = _ref.innerRef,
|
|
742
|
+
draggableProps = _ref.draggableProps,
|
|
743
|
+
dragHandleProps = _ref.dragHandleProps,
|
|
744
|
+
_onKeyDown = _ref.onKeyDown,
|
|
745
|
+
onDelete = _ref.onDelete,
|
|
746
|
+
onClone = _ref.onClone,
|
|
747
|
+
_onChange = _ref.onChange,
|
|
748
|
+
optionIndex = _ref.optionIndex,
|
|
749
|
+
disabled = _ref.disabled,
|
|
750
|
+
id = _ref.id,
|
|
751
|
+
isDraggable = _ref.isDraggable,
|
|
752
|
+
name = _ref.name,
|
|
753
|
+
placeholder = _ref.placeholder,
|
|
754
|
+
_onBlur = _ref.onBlur,
|
|
755
|
+
arrayHelpers = _ref.arrayHelpers,
|
|
756
|
+
_ref$inputConfig = _ref.inputConfig,
|
|
757
|
+
inputConfig = _ref$inputConfig === void 0 ? [] : _ref$inputConfig;
|
|
758
|
+
return /*#__PURE__*/jsx("div", _objectSpread$1(_objectSpread$1({
|
|
759
|
+
ref: innerRef
|
|
760
|
+
}, _objectSpread$1(_objectSpread$1({}, draggableProps), dragHandleProps)), {}, {
|
|
761
|
+
"data-cy": "form-block-multi-options",
|
|
762
|
+
"data-testid": "form-block-multi-options",
|
|
763
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
764
|
+
className: "nf-multi-input-options group relative mb-2 flex items-center gap-1",
|
|
765
|
+
children: [isDraggable && /*#__PURE__*/jsx(DragHandle, _objectSpread$1(_objectSpread$1({}, dragHandleProps), {}, {
|
|
766
|
+
"data-testid": "drag-handle-".concat(optionIndex)
|
|
767
|
+
})), /*#__PURE__*/jsx("div", {
|
|
768
|
+
className: "flex flex-1 flex-col gap-2",
|
|
769
|
+
children: /*#__PURE__*/jsx("div", {
|
|
770
|
+
className: "flex gap-2",
|
|
771
|
+
children: inputConfig.map(function (config, inputIndex) {
|
|
772
|
+
var _field$value;
|
|
773
|
+
var inputName = "".concat(name.replace(".label", ""), ".values.").concat(inputIndex);
|
|
774
|
+
var inputType = config.type || INPUT_TYPES.TEXT;
|
|
775
|
+
var isNumberType = inputType === INPUT_TYPES.NUMBER;
|
|
776
|
+
var _useField = useField(inputName),
|
|
777
|
+
_useField2 = _slicedToArray(_useField, 1),
|
|
778
|
+
field = _useField2[0];
|
|
779
|
+
return /*#__PURE__*/jsx("div", {
|
|
780
|
+
className: "flex-1",
|
|
781
|
+
children: /*#__PURE__*/jsx(Input, _objectSpread$1(_objectSpread$1({
|
|
782
|
+
disabled: disabled,
|
|
783
|
+
autoFocus: shouldFocus && inputIndex === 0,
|
|
784
|
+
"data-cy": "multi-option-input-".concat(optionIndex, "-").concat(inputIndex),
|
|
785
|
+
"data-testid": "multi-option-input-".concat(optionIndex, "-").concat(inputIndex)
|
|
786
|
+
}, isNumberType && {
|
|
787
|
+
min: config.min,
|
|
788
|
+
max: config.max
|
|
789
|
+
}), {}, {
|
|
790
|
+
name: inputName,
|
|
791
|
+
type: inputType,
|
|
792
|
+
value: (_field$value = field.value) !== null && _field$value !== void 0 ? _field$value : config.defaultValue,
|
|
793
|
+
placeholder: config.placeholder || "".concat(placeholder, " ").concat(inputIndex + 1),
|
|
794
|
+
onFocus: function onFocus(_ref2) {
|
|
795
|
+
var target = _ref2.target;
|
|
796
|
+
return target.select();
|
|
797
|
+
},
|
|
798
|
+
onBlur: function onBlur(event) {
|
|
799
|
+
return handleInputBlur(event, {
|
|
800
|
+
id: id,
|
|
801
|
+
inputIndex: inputIndex,
|
|
802
|
+
onChange: _onChange,
|
|
803
|
+
onBlur: _onBlur,
|
|
804
|
+
field: field,
|
|
805
|
+
config: config
|
|
806
|
+
});
|
|
807
|
+
},
|
|
808
|
+
onChange: function onChange(_ref3) {
|
|
809
|
+
var target = _ref3.target;
|
|
810
|
+
return _onChange({
|
|
811
|
+
id: id,
|
|
812
|
+
value: target.value,
|
|
813
|
+
inputIndex: inputIndex
|
|
814
|
+
});
|
|
815
|
+
},
|
|
816
|
+
onKeyDown: function onKeyDown(event) {
|
|
817
|
+
return isNumberType ? handleNumberKeyDown(event, _onKeyDown) : _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(event);
|
|
818
|
+
}
|
|
819
|
+
}))
|
|
820
|
+
}, inputIndex);
|
|
821
|
+
})
|
|
822
|
+
})
|
|
823
|
+
}), /*#__PURE__*/jsx(OptionActions, {
|
|
824
|
+
arrayHelpers: arrayHelpers,
|
|
825
|
+
disabled: disabled,
|
|
826
|
+
hideCloneOption: hideCloneOption,
|
|
827
|
+
hideDeleteOption: hideDeleteOption,
|
|
828
|
+
id: id,
|
|
829
|
+
onClone: onClone,
|
|
830
|
+
onDelete: onDelete,
|
|
831
|
+
optionIndex: optionIndex
|
|
832
|
+
})]
|
|
833
|
+
})
|
|
834
|
+
}));
|
|
835
|
+
});
|
|
836
|
+
|
|
573
837
|
var OptionField = function OptionField(_ref) {
|
|
574
838
|
var option = _ref.option,
|
|
575
839
|
editable = _ref.editable,
|
|
576
840
|
dragHandleProps = _ref.dragHandleProps,
|
|
577
841
|
draggableProps = _ref.draggableProps,
|
|
578
842
|
handleDeleteClick = _ref.handleDeleteClick,
|
|
843
|
+
handleCloneClick = _ref.handleCloneClick,
|
|
579
844
|
hideDeleteOption = _ref.hideDeleteOption,
|
|
845
|
+
hideCloneOption = _ref.hideCloneOption,
|
|
580
846
|
innerRef = _ref.innerRef,
|
|
581
847
|
onEdit = _ref.onEdit,
|
|
582
848
|
draggable = _ref.draggable,
|
|
583
849
|
disabled = _ref.disabled,
|
|
584
850
|
isPictureChoice = _ref.isPictureChoice,
|
|
585
851
|
isTextArea = _ref.isTextArea,
|
|
852
|
+
isMultiInput = _ref.isMultiInput,
|
|
853
|
+
inputConfig = _ref.inputConfig,
|
|
586
854
|
shouldFocus = _ref.shouldFocus,
|
|
587
855
|
isEditable = _ref.isEditable,
|
|
588
856
|
itemLabel = _ref.itemLabel,
|
|
@@ -598,19 +866,46 @@ var OptionField = function OptionField(_ref) {
|
|
|
598
866
|
dragHandleProps: dragHandleProps,
|
|
599
867
|
draggableProps: draggableProps,
|
|
600
868
|
handleDeleteClick: handleDeleteClick,
|
|
869
|
+
hideCloneOption: hideCloneOption,
|
|
601
870
|
hideDeleteOption: hideDeleteOption,
|
|
602
871
|
innerRef: innerRef,
|
|
603
872
|
onEdit: onEdit,
|
|
604
873
|
optionIndex: optionIndex,
|
|
605
874
|
id: option.id,
|
|
606
875
|
isDraggable: draggable && !disabled,
|
|
607
|
-
label: option.label
|
|
876
|
+
label: option.label,
|
|
877
|
+
onClone: handleCloneClick
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
if (isMultiInput) {
|
|
881
|
+
return /*#__PURE__*/jsx(MultiInputOption, {
|
|
882
|
+
arrayHelpers: arrayHelpers,
|
|
883
|
+
dragHandleProps: dragHandleProps,
|
|
884
|
+
draggableProps: draggableProps,
|
|
885
|
+
hideCloneOption: hideCloneOption,
|
|
886
|
+
hideDeleteOption: hideDeleteOption,
|
|
887
|
+
innerRef: innerRef,
|
|
888
|
+
inputConfig: inputConfig,
|
|
889
|
+
name: name,
|
|
890
|
+
onBlur: onBlur,
|
|
891
|
+
option: option,
|
|
892
|
+
optionIndex: optionIndex,
|
|
893
|
+
shouldFocus: shouldFocus,
|
|
894
|
+
disabled: !isEditable || disabled,
|
|
895
|
+
id: option.id,
|
|
896
|
+
isDraggable: draggable && !disabled,
|
|
897
|
+
placeholder: generatePlaceholder(itemLabel, optionIndex),
|
|
898
|
+
onChange: handleChange,
|
|
899
|
+
onClone: handleCloneClick,
|
|
900
|
+
onDelete: handleDeleteClick,
|
|
901
|
+
onKeyDown: handleKeyDown
|
|
608
902
|
});
|
|
609
903
|
}
|
|
610
904
|
return /*#__PURE__*/jsx(InputOption, {
|
|
611
905
|
arrayHelpers: arrayHelpers,
|
|
612
906
|
dragHandleProps: dragHandleProps,
|
|
613
907
|
draggableProps: draggableProps,
|
|
908
|
+
hideCloneOption: hideCloneOption,
|
|
614
909
|
hideDeleteOption: hideDeleteOption,
|
|
615
910
|
innerRef: innerRef,
|
|
616
911
|
isPictureChoice: isPictureChoice,
|
|
@@ -624,6 +919,7 @@ var OptionField = function OptionField(_ref) {
|
|
|
624
919
|
isDraggable: draggable && !disabled,
|
|
625
920
|
placeholder: generatePlaceholder(itemLabel, optionIndex),
|
|
626
921
|
onChange: handleChange,
|
|
922
|
+
onClone: handleCloneClick,
|
|
627
923
|
onDelete: handleDeleteClick,
|
|
628
924
|
onKeyDown: handleKeyDown
|
|
629
925
|
});
|
|
@@ -636,6 +932,7 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
636
932
|
var name = _ref.name,
|
|
637
933
|
error = _ref.error,
|
|
638
934
|
onDelete = _ref.onDelete,
|
|
935
|
+
onClone = _ref.onClone,
|
|
639
936
|
onChange = _ref.onChange,
|
|
640
937
|
onBlur = _ref.onBlur,
|
|
641
938
|
_ref$onEdit = _ref.onEdit,
|
|
@@ -654,10 +951,16 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
654
951
|
isAddOptionEnabled = _ref$isAddOptionEnabl === void 0 ? true : _ref$isAddOptionEnabl,
|
|
655
952
|
_ref$isDeleteOptionEn = _ref.isDeleteOptionEnabled,
|
|
656
953
|
isDeleteOptionEnabled = _ref$isDeleteOptionEn === void 0 ? true : _ref$isDeleteOptionEn,
|
|
954
|
+
_ref$isCloneOptionEna = _ref.isCloneOptionEnabled,
|
|
955
|
+
isCloneOptionEnabled = _ref$isCloneOptionEna === void 0 ? true : _ref$isCloneOptionEna,
|
|
657
956
|
_ref$isPictureChoice = _ref.isPictureChoice,
|
|
658
957
|
isPictureChoice = _ref$isPictureChoice === void 0 ? false : _ref$isPictureChoice,
|
|
659
958
|
_ref$isTextArea = _ref.isTextArea,
|
|
660
959
|
isTextArea = _ref$isTextArea === void 0 ? false : _ref$isTextArea,
|
|
960
|
+
_ref$isMultiInput = _ref.isMultiInput,
|
|
961
|
+
isMultiInput = _ref$isMultiInput === void 0 ? false : _ref$isMultiInput,
|
|
962
|
+
_ref$inputConfig = _ref.inputConfig,
|
|
963
|
+
inputConfig = _ref$inputConfig === void 0 ? [] : _ref$inputConfig,
|
|
661
964
|
_ref$shouldDestroy = _ref.shouldDestroy,
|
|
662
965
|
shouldDestroy = _ref$shouldDestroy === void 0 ? false : _ref$shouldDestroy,
|
|
663
966
|
_ref$destroyFlagName = _ref.destroyFlagName,
|
|
@@ -684,6 +987,7 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
684
987
|
field = _useField2[0],
|
|
685
988
|
meta = _useField2[1];
|
|
686
989
|
var fieldError = meta.touched ? meta.error : null;
|
|
990
|
+
var multiInputError = getMultiInputError(isMultiInput, meta);
|
|
687
991
|
var options = (_field$value = field.value) !== null && _field$value !== void 0 ? _field$value : [];
|
|
688
992
|
var _useOptionFields = useOptionFields({
|
|
689
993
|
options: options,
|
|
@@ -695,7 +999,9 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
695
999
|
name: name,
|
|
696
1000
|
isNewItemsPrefilled: isNewItemsPrefilled,
|
|
697
1001
|
isAddOptionEnabled: isAddOptionEnabled,
|
|
698
|
-
isPictureChoice: isPictureChoice
|
|
1002
|
+
isPictureChoice: isPictureChoice,
|
|
1003
|
+
isMultiInput: isMultiInput,
|
|
1004
|
+
inputConfig: inputConfig
|
|
699
1005
|
}),
|
|
700
1006
|
shouldFocus = _useOptionFields.shouldFocus,
|
|
701
1007
|
handleAddOption = _useOptionFields.handleAddOption,
|
|
@@ -703,7 +1009,8 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
703
1009
|
handleChange = _useOptionFields.handleChange,
|
|
704
1010
|
handleKeyDown = _useOptionFields.handleKeyDown,
|
|
705
1011
|
handleDelete = _useOptionFields.handleDelete,
|
|
706
|
-
handleDragEnd = _useOptionFields.handleDragEnd
|
|
1012
|
+
handleDragEnd = _useOptionFields.handleDragEnd,
|
|
1013
|
+
handleClone = _useOptionFields.handleClone;
|
|
707
1014
|
|
|
708
1015
|
// Temporarily disables the modifications to options when changed are getting saved to server
|
|
709
1016
|
// This condition only needed for server id generated types
|
|
@@ -715,15 +1022,20 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
715
1022
|
return !deleted;
|
|
716
1023
|
});
|
|
717
1024
|
var hideDeleteOption = filteredOptions.length <= minOptions || disabled || !isDeleteOptionEnabled;
|
|
1025
|
+
var hideCloneOption = disabled || !isCloneOptionEnabled;
|
|
718
1026
|
var optionFieldProps = {
|
|
719
1027
|
disabled: disabled,
|
|
720
1028
|
draggable: draggable,
|
|
721
1029
|
editable: editable,
|
|
722
1030
|
handleChange: handleChange,
|
|
723
1031
|
handleDeleteClick: onDelete !== null && onDelete !== void 0 ? onDelete : handleDelete,
|
|
1032
|
+
handleCloneClick: onClone !== null && onClone !== void 0 ? onClone : handleClone,
|
|
724
1033
|
handleKeyDown: handleKeyDown,
|
|
725
1034
|
hideDeleteOption: hideDeleteOption,
|
|
1035
|
+
hideCloneOption: hideCloneOption,
|
|
1036
|
+
inputConfig: inputConfig,
|
|
726
1037
|
isEditable: isEditable,
|
|
1038
|
+
isMultiInput: isMultiInput,
|
|
727
1039
|
isPictureChoice: isPictureChoice,
|
|
728
1040
|
isTextArea: isTextArea,
|
|
729
1041
|
itemLabel: itemLabel,
|
|
@@ -763,6 +1075,7 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
763
1075
|
isDropDisabled: !draggable || disabled,
|
|
764
1076
|
renderClone: renderDragClone,
|
|
765
1077
|
children: function children(_ref3) {
|
|
1078
|
+
var _ref5;
|
|
766
1079
|
var innerRef = _ref3.innerRef,
|
|
767
1080
|
droppableProps = _ref3.droppableProps,
|
|
768
1081
|
placeholder = _ref3.placeholder;
|
|
@@ -800,7 +1113,7 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
800
1113
|
});
|
|
801
1114
|
}
|
|
802
1115
|
}), placeholder, /*#__PURE__*/jsx(FormError, {
|
|
803
|
-
error: error !== null && error !== void 0 ? error : fieldError
|
|
1116
|
+
error: (_ref5 = error !== null && error !== void 0 ? error : multiInputError) !== null && _ref5 !== void 0 ? _ref5 : fieldError
|
|
804
1117
|
})]
|
|
805
1118
|
}));
|
|
806
1119
|
}
|
|
@@ -816,7 +1129,7 @@ var OptionFields = function OptionFields(_ref) {
|
|
|
816
1129
|
size: "small",
|
|
817
1130
|
style: "link",
|
|
818
1131
|
onClick: handleAddOption
|
|
819
|
-
}, buttonProps)), bulkActionProps.enabled && !isPictureChoice && /*#__PURE__*/jsx(Button, {
|
|
1132
|
+
}, buttonProps)), bulkActionProps.enabled && !isPictureChoice && !isMultiInput && /*#__PURE__*/jsx(Button, {
|
|
820
1133
|
"data-cy": "add-bulk-option-link",
|
|
821
1134
|
"data-testid": "add-bulk-option-link",
|
|
822
1135
|
disabled: !isEditable,
|