@bigbinary/neeto-molecules 1.15.38 → 1.15.39
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 +1011 -0
- package/dist/OptionFields.js.map +1 -0
- package/dist/cjs/OptionFields.js +1017 -0
- package/dist/cjs/OptionFields.js.map +1 -0
- package/package.json +1 -1
- package/src/translations/en.json +11 -0
- package/types/OptionFields.d.ts +62 -0
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
import { _ as _extends } from './extends-093996c9.js';
|
|
2
|
+
import { _ as _slicedToArray } from './slicedToArray-b4278ecd.js';
|
|
3
|
+
import React__default, { useState } from 'react';
|
|
4
|
+
import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
|
|
5
|
+
import { isNotEmpty, capitalize, noop, slugify } from '@bigbinary/neeto-cist';
|
|
6
|
+
import { Reorder, Edit, Delete, ImageUpload, Plus } from '@bigbinary/neeto-icons';
|
|
7
|
+
import { Typography, Button, Modal, Textarea, Input } from '@bigbinary/neetoui';
|
|
8
|
+
import { reject, prop, isEmpty, assocPath, remove, move, append, path, last, pluck } from 'ramda';
|
|
9
|
+
import { useTranslation, Trans } from 'react-i18next';
|
|
10
|
+
import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
11
|
+
import { _ as _toConsumableArray } from './toConsumableArray-1cc38429.js';
|
|
12
|
+
import { _ as _defineProperty } from './defineProperty-549061a7.js';
|
|
13
|
+
import { useFormikContext } from 'formik';
|
|
14
|
+
|
|
15
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
16
|
+
|
|
17
|
+
var DragHandle = function DragHandle(props) {
|
|
18
|
+
return /*#__PURE__*/React__default.createElement("div", _extends({
|
|
19
|
+
className: "neeto-ui-text-gray-400 absolute bottom-0 left-0 top-0 my-auto -ml-6 h-6 cursor-grab opacity-0 transition-opacity duration-300 ease-in-out group-hover:opacity-100",
|
|
20
|
+
"data-cy": "drag-handle",
|
|
21
|
+
"data-testid": "drag-handle"
|
|
22
|
+
}, props), /*#__PURE__*/React__default.createElement(Reorder, {
|
|
23
|
+
size: 24,
|
|
24
|
+
strokeWidth: 2
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var BlockOption = withT(function (_ref) {
|
|
29
|
+
var t = _ref.t,
|
|
30
|
+
innerRef = _ref.innerRef,
|
|
31
|
+
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
32
|
+
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
33
|
+
draggableProps = _ref.draggableProps,
|
|
34
|
+
dragHandleProps = _ref.dragHandleProps,
|
|
35
|
+
label = _ref.label,
|
|
36
|
+
index = _ref.index,
|
|
37
|
+
onEdit = _ref.onEdit,
|
|
38
|
+
handleDeleteClick = _ref.handleDeleteClick;
|
|
39
|
+
return /*#__PURE__*/React__default.createElement("div", _extends({
|
|
40
|
+
ref: innerRef
|
|
41
|
+
}, draggableProps, dragHandleProps), /*#__PURE__*/React__default.createElement("div", {
|
|
42
|
+
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",
|
|
43
|
+
"data-cy": "address-field-block"
|
|
44
|
+
}, /*#__PURE__*/React__default.createElement(DragHandle, dragHandleProps), /*#__PURE__*/React__default.createElement(Typography, {
|
|
45
|
+
className: "flex-grow leading-4",
|
|
46
|
+
"data-cy": "address-text-field",
|
|
47
|
+
"data-testid": "address-text-field",
|
|
48
|
+
style: "body2"
|
|
49
|
+
}, label), /*#__PURE__*/React__default.createElement("div", {
|
|
50
|
+
className: "flex items-center justify-end gap-2 opacity-0 group-hover:opacity-100"
|
|
51
|
+
}, /*#__PURE__*/React__default.createElement(Button, {
|
|
52
|
+
className: "neeto-ui-rounded hover:neeto-ui-bg-gray-400 p-1",
|
|
53
|
+
"data-cy": "address-field-edit-button",
|
|
54
|
+
"data-testid": "address-field-edit-button",
|
|
55
|
+
icon: Edit,
|
|
56
|
+
size: "small",
|
|
57
|
+
style: "text",
|
|
58
|
+
tooltipProps: {
|
|
59
|
+
content: t("neetoMolecules.common.actions.edit"),
|
|
60
|
+
position: "top"
|
|
61
|
+
},
|
|
62
|
+
onClick: function onClick() {
|
|
63
|
+
return onEdit(index);
|
|
64
|
+
}
|
|
65
|
+
}), !hideDeleteOption && /*#__PURE__*/React__default.createElement(Button, {
|
|
66
|
+
className: "neeto-ui-rounded hover:neeto-ui-bg-gray-400 p-1",
|
|
67
|
+
"data-cy": "address-field-delete-button",
|
|
68
|
+
"data-testid": "address-field-delete-button",
|
|
69
|
+
icon: Delete,
|
|
70
|
+
size: "small",
|
|
71
|
+
style: "text",
|
|
72
|
+
tooltipProps: {
|
|
73
|
+
content: t("neetoMolecules.common.actions.delete"),
|
|
74
|
+
position: "top"
|
|
75
|
+
},
|
|
76
|
+
onClick: function onClick() {
|
|
77
|
+
return handleDeleteClick({
|
|
78
|
+
index: index
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}))));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
var BulkOptionModal = function BulkOptionModal(_ref) {
|
|
85
|
+
var isOpen = _ref.isOpen,
|
|
86
|
+
onClose = _ref.onClose,
|
|
87
|
+
handleBulkAdd = _ref.handleBulkAdd,
|
|
88
|
+
bulkAddHelpDocUrl = _ref.bulkAddHelpDocUrl;
|
|
89
|
+
var _useTranslation = useTranslation(),
|
|
90
|
+
t = _useTranslation.t;
|
|
91
|
+
var _useState = useState(""),
|
|
92
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
93
|
+
optionsString = _useState2[0],
|
|
94
|
+
setOptionsString = _useState2[1];
|
|
95
|
+
var handleSave = function handleSave() {
|
|
96
|
+
handleBulkAdd(optionsString);
|
|
97
|
+
handleClose();
|
|
98
|
+
};
|
|
99
|
+
var handleClose = function handleClose() {
|
|
100
|
+
setOptionsString("");
|
|
101
|
+
onClose();
|
|
102
|
+
};
|
|
103
|
+
return /*#__PURE__*/React__default.createElement(Modal, {
|
|
104
|
+
isOpen: isOpen,
|
|
105
|
+
onClose: handleClose
|
|
106
|
+
}, /*#__PURE__*/React__default.createElement(Modal.Header, null, /*#__PURE__*/React__default.createElement(Typography, {
|
|
107
|
+
style: "h3"
|
|
108
|
+
}, t("neetoMolecules.optionFields.bulkOption.title"))), /*#__PURE__*/React__default.createElement(Modal.Body, null, /*#__PURE__*/React__default.createElement(Textarea, {
|
|
109
|
+
className: "my-2",
|
|
110
|
+
"data-cy": "bulk-add-options-textarea",
|
|
111
|
+
"data-testid": "bulk-add-options-textarea",
|
|
112
|
+
label: t("neetoMolecules.optionFields.bulkOption.label"),
|
|
113
|
+
placeholder: t("neetoMolecules.optionFields.bulkOption.label"),
|
|
114
|
+
rows: 8,
|
|
115
|
+
value: optionsString,
|
|
116
|
+
helpText: /*#__PURE__*/React__default.createElement(Trans, {
|
|
117
|
+
i18nKey: "neetoMolecules.optionFields.bulkOption.helpText",
|
|
118
|
+
components: {
|
|
119
|
+
Link: /*#__PURE__*/React__default.createElement(Button, {
|
|
120
|
+
className: "text-xs",
|
|
121
|
+
href: bulkAddHelpDocUrl,
|
|
122
|
+
style: "link",
|
|
123
|
+
target: "_blank"
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
}),
|
|
127
|
+
onChange: function onChange(e) {
|
|
128
|
+
return setOptionsString(e.target.value);
|
|
129
|
+
}
|
|
130
|
+
})), /*#__PURE__*/React__default.createElement(Modal.Footer, {
|
|
131
|
+
className: "gap-x-2"
|
|
132
|
+
}, /*#__PURE__*/React__default.createElement(Button, {
|
|
133
|
+
"data-cy": "bulk-add-options-done-button",
|
|
134
|
+
"data-testid": "bulk-add-options-done-button",
|
|
135
|
+
label: t("neetoMolecules.common.actions.submit"),
|
|
136
|
+
onClick: handleSave
|
|
137
|
+
}), /*#__PURE__*/React__default.createElement(Button, {
|
|
138
|
+
"data-cy": "bulk-add-options-cancel-button",
|
|
139
|
+
"data-testid": "bulk-add-options-cancel-button",
|
|
140
|
+
label: t("neetoMolecules.common.actions.cancel"),
|
|
141
|
+
style: "text",
|
|
142
|
+
onClick: handleClose
|
|
143
|
+
})));
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
function commonjsRequire(path) {
|
|
147
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
var pluralize$1 = {exports: {}};
|
|
151
|
+
|
|
152
|
+
/* global define */
|
|
153
|
+
|
|
154
|
+
(function (module, exports) {
|
|
155
|
+
(function (root, pluralize) {
|
|
156
|
+
/* istanbul ignore else */
|
|
157
|
+
if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
|
|
158
|
+
// Node.
|
|
159
|
+
module.exports = pluralize();
|
|
160
|
+
} else {
|
|
161
|
+
// Browser global.
|
|
162
|
+
root.pluralize = pluralize();
|
|
163
|
+
}
|
|
164
|
+
})(commonjsGlobal, function () {
|
|
165
|
+
// Rule storage - pluralize and singularize need to be run sequentially,
|
|
166
|
+
// while other rules can be optimized using an object for instant lookups.
|
|
167
|
+
var pluralRules = [];
|
|
168
|
+
var singularRules = [];
|
|
169
|
+
var uncountables = {};
|
|
170
|
+
var irregularPlurals = {};
|
|
171
|
+
var irregularSingles = {};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Sanitize a pluralization rule to a usable regular expression.
|
|
175
|
+
*
|
|
176
|
+
* @param {(RegExp|string)} rule
|
|
177
|
+
* @return {RegExp}
|
|
178
|
+
*/
|
|
179
|
+
function sanitizeRule (rule) {
|
|
180
|
+
if (typeof rule === 'string') {
|
|
181
|
+
return new RegExp('^' + rule + '$', 'i');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return rule;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Pass in a word token to produce a function that can replicate the case on
|
|
189
|
+
* another word.
|
|
190
|
+
*
|
|
191
|
+
* @param {string} word
|
|
192
|
+
* @param {string} token
|
|
193
|
+
* @return {Function}
|
|
194
|
+
*/
|
|
195
|
+
function restoreCase (word, token) {
|
|
196
|
+
// Tokens are an exact match.
|
|
197
|
+
if (word === token) return token;
|
|
198
|
+
|
|
199
|
+
// Lower cased words. E.g. "hello".
|
|
200
|
+
if (word === word.toLowerCase()) return token.toLowerCase();
|
|
201
|
+
|
|
202
|
+
// Upper cased words. E.g. "WHISKY".
|
|
203
|
+
if (word === word.toUpperCase()) return token.toUpperCase();
|
|
204
|
+
|
|
205
|
+
// Title cased words. E.g. "Title".
|
|
206
|
+
if (word[0] === word[0].toUpperCase()) {
|
|
207
|
+
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Lower cased words. E.g. "test".
|
|
211
|
+
return token.toLowerCase();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Interpolate a regexp string.
|
|
216
|
+
*
|
|
217
|
+
* @param {string} str
|
|
218
|
+
* @param {Array} args
|
|
219
|
+
* @return {string}
|
|
220
|
+
*/
|
|
221
|
+
function interpolate (str, args) {
|
|
222
|
+
return str.replace(/\$(\d{1,2})/g, function (match, index) {
|
|
223
|
+
return args[index] || '';
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Replace a word using a rule.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} word
|
|
231
|
+
* @param {Array} rule
|
|
232
|
+
* @return {string}
|
|
233
|
+
*/
|
|
234
|
+
function replace (word, rule) {
|
|
235
|
+
return word.replace(rule[0], function (match, index) {
|
|
236
|
+
var result = interpolate(rule[1], arguments);
|
|
237
|
+
|
|
238
|
+
if (match === '') {
|
|
239
|
+
return restoreCase(word[index - 1], result);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return restoreCase(match, result);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Sanitize a word by passing in the word and sanitization rules.
|
|
248
|
+
*
|
|
249
|
+
* @param {string} token
|
|
250
|
+
* @param {string} word
|
|
251
|
+
* @param {Array} rules
|
|
252
|
+
* @return {string}
|
|
253
|
+
*/
|
|
254
|
+
function sanitizeWord (token, word, rules) {
|
|
255
|
+
// Empty string or doesn't need fixing.
|
|
256
|
+
if (!token.length || uncountables.hasOwnProperty(token)) {
|
|
257
|
+
return word;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
var len = rules.length;
|
|
261
|
+
|
|
262
|
+
// Iterate over the sanitization rules and use the first one to match.
|
|
263
|
+
while (len--) {
|
|
264
|
+
var rule = rules[len];
|
|
265
|
+
|
|
266
|
+
if (rule[0].test(word)) return replace(word, rule);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return word;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Replace a word with the updated word.
|
|
274
|
+
*
|
|
275
|
+
* @param {Object} replaceMap
|
|
276
|
+
* @param {Object} keepMap
|
|
277
|
+
* @param {Array} rules
|
|
278
|
+
* @return {Function}
|
|
279
|
+
*/
|
|
280
|
+
function replaceWord (replaceMap, keepMap, rules) {
|
|
281
|
+
return function (word) {
|
|
282
|
+
// Get the correct token and case restoration functions.
|
|
283
|
+
var token = word.toLowerCase();
|
|
284
|
+
|
|
285
|
+
// Check against the keep object map.
|
|
286
|
+
if (keepMap.hasOwnProperty(token)) {
|
|
287
|
+
return restoreCase(word, token);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Check against the replacement map for a direct word replacement.
|
|
291
|
+
if (replaceMap.hasOwnProperty(token)) {
|
|
292
|
+
return restoreCase(word, replaceMap[token]);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Run all the rules against the word.
|
|
296
|
+
return sanitizeWord(token, word, rules);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Check if a word is part of the map.
|
|
302
|
+
*/
|
|
303
|
+
function checkWord (replaceMap, keepMap, rules, bool) {
|
|
304
|
+
return function (word) {
|
|
305
|
+
var token = word.toLowerCase();
|
|
306
|
+
|
|
307
|
+
if (keepMap.hasOwnProperty(token)) return true;
|
|
308
|
+
if (replaceMap.hasOwnProperty(token)) return false;
|
|
309
|
+
|
|
310
|
+
return sanitizeWord(token, token, rules) === token;
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Pluralize or singularize a word based on the passed in count.
|
|
316
|
+
*
|
|
317
|
+
* @param {string} word The word to pluralize
|
|
318
|
+
* @param {number} count How many of the word exist
|
|
319
|
+
* @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
|
|
320
|
+
* @return {string}
|
|
321
|
+
*/
|
|
322
|
+
function pluralize (word, count, inclusive) {
|
|
323
|
+
var pluralized = count === 1
|
|
324
|
+
? pluralize.singular(word) : pluralize.plural(word);
|
|
325
|
+
|
|
326
|
+
return (inclusive ? count + ' ' : '') + pluralized;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Pluralize a word.
|
|
331
|
+
*
|
|
332
|
+
* @type {Function}
|
|
333
|
+
*/
|
|
334
|
+
pluralize.plural = replaceWord(
|
|
335
|
+
irregularSingles, irregularPlurals, pluralRules
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Check if a word is plural.
|
|
340
|
+
*
|
|
341
|
+
* @type {Function}
|
|
342
|
+
*/
|
|
343
|
+
pluralize.isPlural = checkWord(
|
|
344
|
+
irregularSingles, irregularPlurals, pluralRules
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Singularize a word.
|
|
349
|
+
*
|
|
350
|
+
* @type {Function}
|
|
351
|
+
*/
|
|
352
|
+
pluralize.singular = replaceWord(
|
|
353
|
+
irregularPlurals, irregularSingles, singularRules
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Check if a word is singular.
|
|
358
|
+
*
|
|
359
|
+
* @type {Function}
|
|
360
|
+
*/
|
|
361
|
+
pluralize.isSingular = checkWord(
|
|
362
|
+
irregularPlurals, irregularSingles, singularRules
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Add a pluralization rule to the collection.
|
|
367
|
+
*
|
|
368
|
+
* @param {(string|RegExp)} rule
|
|
369
|
+
* @param {string} replacement
|
|
370
|
+
*/
|
|
371
|
+
pluralize.addPluralRule = function (rule, replacement) {
|
|
372
|
+
pluralRules.push([sanitizeRule(rule), replacement]);
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Add a singularization rule to the collection.
|
|
377
|
+
*
|
|
378
|
+
* @param {(string|RegExp)} rule
|
|
379
|
+
* @param {string} replacement
|
|
380
|
+
*/
|
|
381
|
+
pluralize.addSingularRule = function (rule, replacement) {
|
|
382
|
+
singularRules.push([sanitizeRule(rule), replacement]);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Add an uncountable word rule.
|
|
387
|
+
*
|
|
388
|
+
* @param {(string|RegExp)} word
|
|
389
|
+
*/
|
|
390
|
+
pluralize.addUncountableRule = function (word) {
|
|
391
|
+
if (typeof word === 'string') {
|
|
392
|
+
uncountables[word.toLowerCase()] = true;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Set singular and plural references for the word.
|
|
397
|
+
pluralize.addPluralRule(word, '$0');
|
|
398
|
+
pluralize.addSingularRule(word, '$0');
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Add an irregular word definition.
|
|
403
|
+
*
|
|
404
|
+
* @param {string} single
|
|
405
|
+
* @param {string} plural
|
|
406
|
+
*/
|
|
407
|
+
pluralize.addIrregularRule = function (single, plural) {
|
|
408
|
+
plural = plural.toLowerCase();
|
|
409
|
+
single = single.toLowerCase();
|
|
410
|
+
|
|
411
|
+
irregularSingles[single] = plural;
|
|
412
|
+
irregularPlurals[plural] = single;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Irregular rules.
|
|
417
|
+
*/
|
|
418
|
+
[
|
|
419
|
+
// Pronouns.
|
|
420
|
+
['I', 'we'],
|
|
421
|
+
['me', 'us'],
|
|
422
|
+
['he', 'they'],
|
|
423
|
+
['she', 'they'],
|
|
424
|
+
['them', 'them'],
|
|
425
|
+
['myself', 'ourselves'],
|
|
426
|
+
['yourself', 'yourselves'],
|
|
427
|
+
['itself', 'themselves'],
|
|
428
|
+
['herself', 'themselves'],
|
|
429
|
+
['himself', 'themselves'],
|
|
430
|
+
['themself', 'themselves'],
|
|
431
|
+
['is', 'are'],
|
|
432
|
+
['was', 'were'],
|
|
433
|
+
['has', 'have'],
|
|
434
|
+
['this', 'these'],
|
|
435
|
+
['that', 'those'],
|
|
436
|
+
// Words ending in with a consonant and `o`.
|
|
437
|
+
['echo', 'echoes'],
|
|
438
|
+
['dingo', 'dingoes'],
|
|
439
|
+
['volcano', 'volcanoes'],
|
|
440
|
+
['tornado', 'tornadoes'],
|
|
441
|
+
['torpedo', 'torpedoes'],
|
|
442
|
+
// Ends with `us`.
|
|
443
|
+
['genus', 'genera'],
|
|
444
|
+
['viscus', 'viscera'],
|
|
445
|
+
// Ends with `ma`.
|
|
446
|
+
['stigma', 'stigmata'],
|
|
447
|
+
['stoma', 'stomata'],
|
|
448
|
+
['dogma', 'dogmata'],
|
|
449
|
+
['lemma', 'lemmata'],
|
|
450
|
+
['schema', 'schemata'],
|
|
451
|
+
['anathema', 'anathemata'],
|
|
452
|
+
// Other irregular rules.
|
|
453
|
+
['ox', 'oxen'],
|
|
454
|
+
['axe', 'axes'],
|
|
455
|
+
['die', 'dice'],
|
|
456
|
+
['yes', 'yeses'],
|
|
457
|
+
['foot', 'feet'],
|
|
458
|
+
['eave', 'eaves'],
|
|
459
|
+
['goose', 'geese'],
|
|
460
|
+
['tooth', 'teeth'],
|
|
461
|
+
['quiz', 'quizzes'],
|
|
462
|
+
['human', 'humans'],
|
|
463
|
+
['proof', 'proofs'],
|
|
464
|
+
['carve', 'carves'],
|
|
465
|
+
['valve', 'valves'],
|
|
466
|
+
['looey', 'looies'],
|
|
467
|
+
['thief', 'thieves'],
|
|
468
|
+
['groove', 'grooves'],
|
|
469
|
+
['pickaxe', 'pickaxes'],
|
|
470
|
+
['passerby', 'passersby']
|
|
471
|
+
].forEach(function (rule) {
|
|
472
|
+
return pluralize.addIrregularRule(rule[0], rule[1]);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Pluralization rules.
|
|
477
|
+
*/
|
|
478
|
+
[
|
|
479
|
+
[/s?$/i, 's'],
|
|
480
|
+
[/[^\u0000-\u007F]$/i, '$0'],
|
|
481
|
+
[/([^aeiou]ese)$/i, '$1'],
|
|
482
|
+
[/(ax|test)is$/i, '$1es'],
|
|
483
|
+
[/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
|
|
484
|
+
[/(e[mn]u)s?$/i, '$1s'],
|
|
485
|
+
[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
|
|
486
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
|
|
487
|
+
[/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
|
|
488
|
+
[/(seraph|cherub)(?:im)?$/i, '$1im'],
|
|
489
|
+
[/(her|at|gr)o$/i, '$1oes'],
|
|
490
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
|
|
491
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
|
|
492
|
+
[/sis$/i, 'ses'],
|
|
493
|
+
[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
|
|
494
|
+
[/([^aeiouy]|qu)y$/i, '$1ies'],
|
|
495
|
+
[/([^ch][ieo][ln])ey$/i, '$1ies'],
|
|
496
|
+
[/(x|ch|ss|sh|zz)$/i, '$1es'],
|
|
497
|
+
[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
|
|
498
|
+
[/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'],
|
|
499
|
+
[/(pe)(?:rson|ople)$/i, '$1ople'],
|
|
500
|
+
[/(child)(?:ren)?$/i, '$1ren'],
|
|
501
|
+
[/eaux$/i, '$0'],
|
|
502
|
+
[/m[ae]n$/i, 'men'],
|
|
503
|
+
['thou', 'you']
|
|
504
|
+
].forEach(function (rule) {
|
|
505
|
+
return pluralize.addPluralRule(rule[0], rule[1]);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Singularization rules.
|
|
510
|
+
*/
|
|
511
|
+
[
|
|
512
|
+
[/s$/i, ''],
|
|
513
|
+
[/(ss)$/i, '$1'],
|
|
514
|
+
[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
|
|
515
|
+
[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
|
|
516
|
+
[/ies$/i, 'y'],
|
|
517
|
+
[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
|
|
518
|
+
[/\b(mon|smil)ies$/i, '$1ey'],
|
|
519
|
+
[/\b((?:tit)?m|l)ice$/i, '$1ouse'],
|
|
520
|
+
[/(seraph|cherub)im$/i, '$1'],
|
|
521
|
+
[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
|
|
522
|
+
[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
|
|
523
|
+
[/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
|
|
524
|
+
[/(test)(?:is|es)$/i, '$1is'],
|
|
525
|
+
[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
|
|
526
|
+
[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
|
|
527
|
+
[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
|
|
528
|
+
[/(alumn|alg|vertebr)ae$/i, '$1a'],
|
|
529
|
+
[/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
|
|
530
|
+
[/(matr|append)ices$/i, '$1ix'],
|
|
531
|
+
[/(pe)(rson|ople)$/i, '$1rson'],
|
|
532
|
+
[/(child)ren$/i, '$1'],
|
|
533
|
+
[/(eau)x?$/i, '$1'],
|
|
534
|
+
[/men$/i, 'man']
|
|
535
|
+
].forEach(function (rule) {
|
|
536
|
+
return pluralize.addSingularRule(rule[0], rule[1]);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Uncountable rules.
|
|
541
|
+
*/
|
|
542
|
+
[
|
|
543
|
+
// Singular words with no plurals.
|
|
544
|
+
'adulthood',
|
|
545
|
+
'advice',
|
|
546
|
+
'agenda',
|
|
547
|
+
'aid',
|
|
548
|
+
'aircraft',
|
|
549
|
+
'alcohol',
|
|
550
|
+
'ammo',
|
|
551
|
+
'analytics',
|
|
552
|
+
'anime',
|
|
553
|
+
'athletics',
|
|
554
|
+
'audio',
|
|
555
|
+
'bison',
|
|
556
|
+
'blood',
|
|
557
|
+
'bream',
|
|
558
|
+
'buffalo',
|
|
559
|
+
'butter',
|
|
560
|
+
'carp',
|
|
561
|
+
'cash',
|
|
562
|
+
'chassis',
|
|
563
|
+
'chess',
|
|
564
|
+
'clothing',
|
|
565
|
+
'cod',
|
|
566
|
+
'commerce',
|
|
567
|
+
'cooperation',
|
|
568
|
+
'corps',
|
|
569
|
+
'debris',
|
|
570
|
+
'diabetes',
|
|
571
|
+
'digestion',
|
|
572
|
+
'elk',
|
|
573
|
+
'energy',
|
|
574
|
+
'equipment',
|
|
575
|
+
'excretion',
|
|
576
|
+
'expertise',
|
|
577
|
+
'firmware',
|
|
578
|
+
'flounder',
|
|
579
|
+
'fun',
|
|
580
|
+
'gallows',
|
|
581
|
+
'garbage',
|
|
582
|
+
'graffiti',
|
|
583
|
+
'hardware',
|
|
584
|
+
'headquarters',
|
|
585
|
+
'health',
|
|
586
|
+
'herpes',
|
|
587
|
+
'highjinks',
|
|
588
|
+
'homework',
|
|
589
|
+
'housework',
|
|
590
|
+
'information',
|
|
591
|
+
'jeans',
|
|
592
|
+
'justice',
|
|
593
|
+
'kudos',
|
|
594
|
+
'labour',
|
|
595
|
+
'literature',
|
|
596
|
+
'machinery',
|
|
597
|
+
'mackerel',
|
|
598
|
+
'mail',
|
|
599
|
+
'media',
|
|
600
|
+
'mews',
|
|
601
|
+
'moose',
|
|
602
|
+
'music',
|
|
603
|
+
'mud',
|
|
604
|
+
'manga',
|
|
605
|
+
'news',
|
|
606
|
+
'only',
|
|
607
|
+
'personnel',
|
|
608
|
+
'pike',
|
|
609
|
+
'plankton',
|
|
610
|
+
'pliers',
|
|
611
|
+
'police',
|
|
612
|
+
'pollution',
|
|
613
|
+
'premises',
|
|
614
|
+
'rain',
|
|
615
|
+
'research',
|
|
616
|
+
'rice',
|
|
617
|
+
'salmon',
|
|
618
|
+
'scissors',
|
|
619
|
+
'series',
|
|
620
|
+
'sewage',
|
|
621
|
+
'shambles',
|
|
622
|
+
'shrimp',
|
|
623
|
+
'software',
|
|
624
|
+
'species',
|
|
625
|
+
'staff',
|
|
626
|
+
'swine',
|
|
627
|
+
'tennis',
|
|
628
|
+
'traffic',
|
|
629
|
+
'transportation',
|
|
630
|
+
'trout',
|
|
631
|
+
'tuna',
|
|
632
|
+
'wealth',
|
|
633
|
+
'welfare',
|
|
634
|
+
'whiting',
|
|
635
|
+
'wildebeest',
|
|
636
|
+
'wildlife',
|
|
637
|
+
'you',
|
|
638
|
+
/pok[eé]mon$/i,
|
|
639
|
+
// Regexes.
|
|
640
|
+
/[^aeiou]ese$/i, // "chinese", "japanese"
|
|
641
|
+
/deer$/i, // "deer", "reindeer"
|
|
642
|
+
/fish$/i, // "fish", "blowfish", "angelfish"
|
|
643
|
+
/measles$/i,
|
|
644
|
+
/o[iu]s$/i, // "carnivorous"
|
|
645
|
+
/pox$/i, // "chickpox", "smallpox"
|
|
646
|
+
/sheep$/i
|
|
647
|
+
].forEach(pluralize.addUncountableRule);
|
|
648
|
+
|
|
649
|
+
return pluralize;
|
|
650
|
+
});
|
|
651
|
+
} (pluralize$1));
|
|
652
|
+
|
|
653
|
+
var pluralize = pluralize$1.exports;
|
|
654
|
+
|
|
655
|
+
var getVisibleOptions = function getVisibleOptions() {
|
|
656
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
657
|
+
return options.filter(function (option) {
|
|
658
|
+
return !option.deleted;
|
|
659
|
+
}).sort(function (a, b) {
|
|
660
|
+
return a.position - b.position;
|
|
661
|
+
});
|
|
662
|
+
};
|
|
663
|
+
var filterDeletedRecords = reject(prop("deleted"));
|
|
664
|
+
var randomId = function randomId() {
|
|
665
|
+
return Math.random().toString(36).substring(2, 13);
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
669
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
670
|
+
var attachPosition = function attachPosition(options) {
|
|
671
|
+
return options.map(function (option, index) {
|
|
672
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
673
|
+
position: index + 1
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
};
|
|
677
|
+
var useOptionFields = function useOptionFields(_ref) {
|
|
678
|
+
var options = _ref.options,
|
|
679
|
+
onChange = _ref.onChange,
|
|
680
|
+
shouldDestroy = _ref.shouldDestroy,
|
|
681
|
+
_ref$name = _ref.name,
|
|
682
|
+
name = _ref$name === void 0 ? "" : _ref$name,
|
|
683
|
+
currentRecord = _ref.currentRecord;
|
|
684
|
+
var _useState = useState(false),
|
|
685
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
686
|
+
shouldFocus = _useState2[0],
|
|
687
|
+
setShouldFocus = _useState2[1];
|
|
688
|
+
var deletedOptions = options.filter(function (option) {
|
|
689
|
+
return !!(option !== null && option !== void 0 && option.deleted);
|
|
690
|
+
});
|
|
691
|
+
var _useFormikContext = useFormikContext(),
|
|
692
|
+
initialValues = _useFormikContext.initialValues;
|
|
693
|
+
var handleChange = function handleChange(index, value) {
|
|
694
|
+
var isOnBlur = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
695
|
+
var draftAttributes = currentRecord === null || currentRecord === void 0 ? void 0 : currentRecord.draftAttributes;
|
|
696
|
+
var getNextOptions = function getNextOptions() {
|
|
697
|
+
var _path$index, _path$index2;
|
|
698
|
+
return assocPath([index, "label"], isOnBlur ? ((_path$index = path(name.split("."), initialValues)[index]) === null || _path$index === void 0 ? void 0 : _path$index.label) || ((_path$index2 = path(name.split("."), draftAttributes)[index]) === null || _path$index2 === void 0 ? void 0 : _path$index2.label) : value, filterDeletedRecords(options));
|
|
699
|
+
};
|
|
700
|
+
if (isOnBlur && !isEmpty(value)) return;
|
|
701
|
+
onChange([].concat(_toConsumableArray(deletedOptions), _toConsumableArray(getNextOptions())));
|
|
702
|
+
};
|
|
703
|
+
var generateLabel = function generateLabel(opts, count) {
|
|
704
|
+
var labelCount = count || opts.length + 1;
|
|
705
|
+
var tempLabel = "".concat(capitalize(pluralize.singular(last(name.split(".")))), " ").concat(labelCount);
|
|
706
|
+
var isDuplicateLabel = pluck("label", opts).includes(tempLabel);
|
|
707
|
+
return isDuplicateLabel ? generateLabel(opts, labelCount + 1) : tempLabel;
|
|
708
|
+
};
|
|
709
|
+
var handleDelete = function handleDelete(index) {
|
|
710
|
+
var nextOptions;
|
|
711
|
+
var finalOptions;
|
|
712
|
+
if (shouldDestroy) {
|
|
713
|
+
nextOptions = assocPath([index, "deleted"], true, filterDeletedRecords(options));
|
|
714
|
+
finalOptions = attachPosition(filterDeletedRecords(nextOptions));
|
|
715
|
+
} else {
|
|
716
|
+
nextOptions = remove(index, 1, options);
|
|
717
|
+
finalOptions = attachPosition(nextOptions);
|
|
718
|
+
}
|
|
719
|
+
onChange([].concat(_toConsumableArray(deletedOptions), _toConsumableArray(finalOptions)));
|
|
720
|
+
};
|
|
721
|
+
var handleDragEnd = function handleDragEnd(_ref2) {
|
|
722
|
+
var source = _ref2.source,
|
|
723
|
+
destination = _ref2.destination;
|
|
724
|
+
// When dragged outside of draggable
|
|
725
|
+
if (destination === null) return;
|
|
726
|
+
var filteredOptions = filterDeletedRecords(options);
|
|
727
|
+
var nextOptions = move(source.index, destination.index, filteredOptions);
|
|
728
|
+
var finalOptions = attachPosition(nextOptions);
|
|
729
|
+
onChange([].concat(_toConsumableArray(deletedOptions), _toConsumableArray(finalOptions)));
|
|
730
|
+
};
|
|
731
|
+
var handleAddOption = function handleAddOption() {
|
|
732
|
+
setShouldFocus(true);
|
|
733
|
+
var position = filterDeletedRecords(options).length;
|
|
734
|
+
var id = randomId();
|
|
735
|
+
var newOption = {
|
|
736
|
+
id: "draft-".concat(id),
|
|
737
|
+
altId: "alt-".concat(id),
|
|
738
|
+
label: generateLabel(options, null),
|
|
739
|
+
position: position
|
|
740
|
+
};
|
|
741
|
+
var nextOptions = append(newOption, options);
|
|
742
|
+
onChange(nextOptions);
|
|
743
|
+
};
|
|
744
|
+
var handleBulkAddOption = function handleBulkAddOption(optionsString) {
|
|
745
|
+
setShouldFocus(true);
|
|
746
|
+
var position = filterDeletedRecords(options).length;
|
|
747
|
+
var newOptions = optionsString.trim().split(/\r?\n|,/).filter(isNotEmpty).map(function (option, index) {
|
|
748
|
+
return {
|
|
749
|
+
id: "draft-".concat(randomId()),
|
|
750
|
+
altId: "alt-".concat(randomId()),
|
|
751
|
+
label: option.trim(),
|
|
752
|
+
position: position + index
|
|
753
|
+
};
|
|
754
|
+
});
|
|
755
|
+
onChange([].concat(_toConsumableArray(options), _toConsumableArray(newOptions)));
|
|
756
|
+
};
|
|
757
|
+
var handleKeyDown = function handleKeyDown() {
|
|
758
|
+
return function (event) {
|
|
759
|
+
if (event.key !== "Enter") return;
|
|
760
|
+
var form = event.target.form;
|
|
761
|
+
var inputs = form.querySelectorAll("input");
|
|
762
|
+
var currentInput = inputs.indexOf(event.target);
|
|
763
|
+
if (currentInput >= inputs.length - 1) {
|
|
764
|
+
handleAddOption();
|
|
765
|
+
} else {
|
|
766
|
+
var _inputs;
|
|
767
|
+
(_inputs = inputs[currentInput + 1]) === null || _inputs === void 0 ? void 0 : _inputs.focus();
|
|
768
|
+
event.preventDefault();
|
|
769
|
+
}
|
|
770
|
+
event.stopPropagation();
|
|
771
|
+
};
|
|
772
|
+
};
|
|
773
|
+
return {
|
|
774
|
+
shouldFocus: shouldFocus,
|
|
775
|
+
handleAddOption: handleAddOption,
|
|
776
|
+
handleBulkAddOption: handleBulkAddOption,
|
|
777
|
+
handleChange: handleChange,
|
|
778
|
+
handleKeyDown: handleKeyDown,
|
|
779
|
+
handleDelete: handleDelete,
|
|
780
|
+
handleDragEnd: handleDragEnd
|
|
781
|
+
};
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
var InputOption = function InputOption(_ref) {
|
|
785
|
+
var shouldFocus = _ref.shouldFocus,
|
|
786
|
+
_ref$hideDeleteOption = _ref.hideDeleteOption,
|
|
787
|
+
hideDeleteOption = _ref$hideDeleteOption === void 0 ? false : _ref$hideDeleteOption,
|
|
788
|
+
innerRef = _ref.innerRef,
|
|
789
|
+
draggableProps = _ref.draggableProps,
|
|
790
|
+
dragHandleProps = _ref.dragHandleProps,
|
|
791
|
+
isPictureChoice = _ref.isPictureChoice,
|
|
792
|
+
onKeyDown = _ref.onKeyDown,
|
|
793
|
+
onDelete = _ref.onDelete,
|
|
794
|
+
_onChange = _ref.onChange,
|
|
795
|
+
label = _ref.label,
|
|
796
|
+
index = _ref.index,
|
|
797
|
+
disabled = _ref.disabled,
|
|
798
|
+
isTextArea = _ref.isTextArea;
|
|
799
|
+
var _useTranslation = useTranslation(),
|
|
800
|
+
t = _useTranslation.t;
|
|
801
|
+
var Component = isTextArea ? Textarea : Input;
|
|
802
|
+
return /*#__PURE__*/React__default.createElement("div", _extends({
|
|
803
|
+
ref: innerRef
|
|
804
|
+
}, draggableProps, dragHandleProps, {
|
|
805
|
+
"data-cy": "form-block-options"
|
|
806
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
807
|
+
className: "nf-input-options group relative mb-2 flex items-center gap-2"
|
|
808
|
+
}, /*#__PURE__*/React__default.createElement(DragHandle, dragHandleProps), isPictureChoice && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, index === 0 ? /*#__PURE__*/React__default.createElement("img", {
|
|
809
|
+
className: "neeto-ui-rounded-sm h-8 w-8 cursor-pointer overflow-hidden object-cover",
|
|
810
|
+
"data-testid": "picture-choice-option",
|
|
811
|
+
src: "https://i.pravatar.cc/300"
|
|
812
|
+
}) : /*#__PURE__*/React__default.createElement("div", {
|
|
813
|
+
className: "hover:neeto-ui-bg-gray-100 neeto-ui-border-primary-600 neeto-ui-text-primary-800 neeto-ui-rounded-sm flex h-8 w-8 cursor-pointer items-center justify-center border border-dashed transition-all duration-300 ease-in-out"
|
|
814
|
+
}, /*#__PURE__*/React__default.createElement(ImageUpload, {
|
|
815
|
+
size: 16
|
|
816
|
+
}))), /*#__PURE__*/React__default.createElement(Component, {
|
|
817
|
+
disabled: disabled,
|
|
818
|
+
autoFocus: shouldFocus,
|
|
819
|
+
"data-cy": "option-input",
|
|
820
|
+
"data-testid": isTextArea ? "textarea-option" : "input-option",
|
|
821
|
+
placeholder: t("neetoMolecules.optionFields.optionName"),
|
|
822
|
+
value: label,
|
|
823
|
+
suffix: !hideDeleteOption && /*#__PURE__*/React__default.createElement(Button, {
|
|
824
|
+
disabled: disabled,
|
|
825
|
+
className: "p-0.5",
|
|
826
|
+
"data-testid": "delete-option-button",
|
|
827
|
+
icon: Delete,
|
|
828
|
+
size: "small",
|
|
829
|
+
style: "text",
|
|
830
|
+
tooltipProps: {
|
|
831
|
+
content: t("neetoMolecules.common.actions.delete"),
|
|
832
|
+
position: "top"
|
|
833
|
+
},
|
|
834
|
+
onClick: function onClick() {
|
|
835
|
+
return onDelete({
|
|
836
|
+
index: index
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
}),
|
|
840
|
+
onBlur: function onBlur(_ref2) {
|
|
841
|
+
var target = _ref2.target;
|
|
842
|
+
return _onChange(index, target.value, true);
|
|
843
|
+
},
|
|
844
|
+
onChange: function onChange(_ref3) {
|
|
845
|
+
var target = _ref3.target;
|
|
846
|
+
return _onChange(index, target.value);
|
|
847
|
+
},
|
|
848
|
+
onFocus: function onFocus(_ref4) {
|
|
849
|
+
var target = _ref4.target;
|
|
850
|
+
return target.select();
|
|
851
|
+
},
|
|
852
|
+
onKeyDown: onKeyDown(index)
|
|
853
|
+
})));
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
var OptionFields = function OptionFields(_ref) {
|
|
857
|
+
var options = _ref.options,
|
|
858
|
+
error = _ref.error,
|
|
859
|
+
onChange = _ref.onChange,
|
|
860
|
+
name = _ref.name,
|
|
861
|
+
onDelete = _ref.onDelete,
|
|
862
|
+
_ref$onEdit = _ref.onEdit,
|
|
863
|
+
onEdit = _ref$onEdit === void 0 ? noop : _ref$onEdit,
|
|
864
|
+
_ref$buttonProps = _ref.buttonProps,
|
|
865
|
+
buttonProps = _ref$buttonProps === void 0 ? {} : _ref$buttonProps,
|
|
866
|
+
_ref$minOptions = _ref.minOptions,
|
|
867
|
+
minOptions = _ref$minOptions === void 0 ? 0 : _ref$minOptions,
|
|
868
|
+
_ref$draggable = _ref.draggable,
|
|
869
|
+
draggable = _ref$draggable === void 0 ? false : _ref$draggable,
|
|
870
|
+
_ref$editable = _ref.editable,
|
|
871
|
+
editable = _ref$editable === void 0 ? true : _ref$editable,
|
|
872
|
+
_ref$isPictureChoice = _ref.isPictureChoice,
|
|
873
|
+
isPictureChoice = _ref$isPictureChoice === void 0 ? false : _ref$isPictureChoice,
|
|
874
|
+
_ref$isTextArea = _ref.isTextArea,
|
|
875
|
+
isTextArea = _ref$isTextArea === void 0 ? false : _ref$isTextArea,
|
|
876
|
+
_ref$shouldDestroy = _ref.shouldDestroy,
|
|
877
|
+
shouldDestroy = _ref$shouldDestroy === void 0 ? false : _ref$shouldDestroy,
|
|
878
|
+
_ref$currentRecord = _ref.currentRecord,
|
|
879
|
+
currentRecord = _ref$currentRecord === void 0 ? {} : _ref$currentRecord,
|
|
880
|
+
_ref$bulkActionProps = _ref.bulkActionProps,
|
|
881
|
+
bulkActionProps = _ref$bulkActionProps === void 0 ? {
|
|
882
|
+
enabled: false,
|
|
883
|
+
bulkAddHelpDocUrl: ""
|
|
884
|
+
} : _ref$bulkActionProps;
|
|
885
|
+
var _useTranslation = useTranslation(),
|
|
886
|
+
t = _useTranslation.t;
|
|
887
|
+
var _useState = useState(false),
|
|
888
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
889
|
+
isBulkOptionModalOpen = _useState2[0],
|
|
890
|
+
setIsBulkOptionModalOpen = _useState2[1];
|
|
891
|
+
var _useOptionFields = useOptionFields({
|
|
892
|
+
options: options,
|
|
893
|
+
onChange: onChange,
|
|
894
|
+
shouldDestroy: shouldDestroy,
|
|
895
|
+
name: name,
|
|
896
|
+
currentRecord: currentRecord
|
|
897
|
+
}),
|
|
898
|
+
shouldFocus = _useOptionFields.shouldFocus,
|
|
899
|
+
handleAddOption = _useOptionFields.handleAddOption,
|
|
900
|
+
handleBulkAddOption = _useOptionFields.handleBulkAddOption,
|
|
901
|
+
handleChange = _useOptionFields.handleChange,
|
|
902
|
+
handleKeyDown = _useOptionFields.handleKeyDown,
|
|
903
|
+
handleDelete = _useOptionFields.handleDelete,
|
|
904
|
+
handleDragEnd = _useOptionFields.handleDragEnd;
|
|
905
|
+
|
|
906
|
+
// Temporarily disables the modifications to options when changed are getting saved to server
|
|
907
|
+
// This condition only needed for server id generated types
|
|
908
|
+
var isEditable = true;
|
|
909
|
+
if (shouldDestroy) {
|
|
910
|
+
isEditable = options.every(prop("id") || error) && !options.some(prop("_destroy"));
|
|
911
|
+
}
|
|
912
|
+
var handleDeleteClick = function handleDeleteClick(_ref2) {
|
|
913
|
+
var index = _ref2.index;
|
|
914
|
+
var deleteFunction = onDelete !== null && onDelete !== void 0 ? onDelete : handleDelete;
|
|
915
|
+
deleteFunction(index);
|
|
916
|
+
};
|
|
917
|
+
var visibleOptions = getVisibleOptions(options);
|
|
918
|
+
var hideDeleteOption = visibleOptions.length <= minOptions;
|
|
919
|
+
var getUniqueOptionId = function getUniqueOptionId(option) {
|
|
920
|
+
return option.altId || option.id.toString() || option.position.toString() || slugify(option.label);
|
|
921
|
+
};
|
|
922
|
+
return /*#__PURE__*/React__default.createElement("form", {
|
|
923
|
+
onSubmit: function onSubmit(e) {
|
|
924
|
+
return e.preventDefault();
|
|
925
|
+
}
|
|
926
|
+
}, /*#__PURE__*/React__default.createElement(DragDropContext, {
|
|
927
|
+
onDragEnd: handleDragEnd
|
|
928
|
+
}, /*#__PURE__*/React__default.createElement(Droppable, {
|
|
929
|
+
droppableId: "neeto-molecules-option-fields-".concat(name),
|
|
930
|
+
isDropDisabled: !draggable
|
|
931
|
+
}, function (_ref3) {
|
|
932
|
+
var innerRef = _ref3.innerRef,
|
|
933
|
+
droppableProps = _ref3.droppableProps,
|
|
934
|
+
placeholder = _ref3.placeholder;
|
|
935
|
+
return /*#__PURE__*/React__default.createElement("div", _extends({
|
|
936
|
+
ref: innerRef
|
|
937
|
+
}, droppableProps), visibleOptions.map(function (option, index) {
|
|
938
|
+
return /*#__PURE__*/React__default.createElement(Draggable, {
|
|
939
|
+
index: index,
|
|
940
|
+
draggableId: getUniqueOptionId(option),
|
|
941
|
+
isDragDisabled: !draggable,
|
|
942
|
+
key: getUniqueOptionId(option)
|
|
943
|
+
}, function (_ref4) {
|
|
944
|
+
var innerRef = _ref4.innerRef,
|
|
945
|
+
draggableProps = _ref4.draggableProps,
|
|
946
|
+
dragHandleProps = _ref4.dragHandleProps;
|
|
947
|
+
return editable ? /*#__PURE__*/React__default.createElement(InputOption, {
|
|
948
|
+
dragHandleProps: dragHandleProps,
|
|
949
|
+
draggableProps: draggableProps,
|
|
950
|
+
hideDeleteOption: hideDeleteOption,
|
|
951
|
+
index: index,
|
|
952
|
+
innerRef: innerRef,
|
|
953
|
+
isPictureChoice: isPictureChoice,
|
|
954
|
+
isTextArea: isTextArea,
|
|
955
|
+
name: name,
|
|
956
|
+
shouldFocus: shouldFocus,
|
|
957
|
+
disabled: !isEditable,
|
|
958
|
+
label: option.label,
|
|
959
|
+
onChange: handleChange,
|
|
960
|
+
onDelete: handleDeleteClick,
|
|
961
|
+
onKeyDown: handleKeyDown
|
|
962
|
+
}) : /*#__PURE__*/React__default.createElement(BlockOption, {
|
|
963
|
+
dragHandleProps: dragHandleProps,
|
|
964
|
+
draggableProps: draggableProps,
|
|
965
|
+
handleDeleteClick: handleDeleteClick,
|
|
966
|
+
hideDeleteOption: hideDeleteOption,
|
|
967
|
+
index: index,
|
|
968
|
+
innerRef: innerRef,
|
|
969
|
+
onEdit: onEdit,
|
|
970
|
+
label: option.label
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
}), error && /*#__PURE__*/React__default.createElement(Typography, {
|
|
974
|
+
className: "neeto-ui-input__error",
|
|
975
|
+
"data-testid": "validation-error-container",
|
|
976
|
+
style: "body3"
|
|
977
|
+
}, error), placeholder);
|
|
978
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
979
|
+
className: "mt-4 flex items-center justify-between"
|
|
980
|
+
}, /*#__PURE__*/React__default.createElement(Button, _extends({
|
|
981
|
+
"data-cy": "add-option-link",
|
|
982
|
+
"data-testid": "add-option-link",
|
|
983
|
+
disabled: !isEditable,
|
|
984
|
+
icon: Plus,
|
|
985
|
+
iconPosition: "left",
|
|
986
|
+
label: t("neetoMolecules.optionFields.addOption"),
|
|
987
|
+
size: "small",
|
|
988
|
+
style: "link",
|
|
989
|
+
onClick: handleAddOption
|
|
990
|
+
}, buttonProps)), bulkActionProps.enabled && /*#__PURE__*/React__default.createElement(Button, {
|
|
991
|
+
"data-cy": "add-bulk-option-link",
|
|
992
|
+
"data-testid": "add-bulk-option-link",
|
|
993
|
+
disabled: !isEditable,
|
|
994
|
+
label: t("neetoMolecules.optionFields.addBulk"),
|
|
995
|
+
size: "small",
|
|
996
|
+
style: "text",
|
|
997
|
+
onClick: function onClick() {
|
|
998
|
+
return setIsBulkOptionModalOpen(true);
|
|
999
|
+
}
|
|
1000
|
+
}))), /*#__PURE__*/React__default.createElement(BulkOptionModal, {
|
|
1001
|
+
bulkAddHelpDocUrl: bulkActionProps.bulkAddHelpDocUrl,
|
|
1002
|
+
handleBulkAdd: handleBulkAddOption,
|
|
1003
|
+
isOpen: isBulkOptionModalOpen,
|
|
1004
|
+
onClose: function onClose() {
|
|
1005
|
+
return setIsBulkOptionModalOpen(false);
|
|
1006
|
+
}
|
|
1007
|
+
}));
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
export { OptionFields as default };
|
|
1011
|
+
//# sourceMappingURL=OptionFields.js.map
|