@bigbinary/neeto-molecules 1.15.47 → 1.15.48

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.
@@ -2,17 +2,16 @@ import { _ as _extends } from './extends-093996c9.js';
2
2
  import { _ as _slicedToArray } from './slicedToArray-b4278ecd.js';
3
3
  import React__default, { useState } from 'react';
4
4
  import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
5
- import { isNotEmpty, capitalize, noop, slugify } from '@bigbinary/neeto-cist';
5
+ import { isNotEmpty, noop, slugify } from '@bigbinary/neeto-cist';
6
6
  import { Reorder, Edit, Delete, ImageUpload, Plus } from '@bigbinary/neeto-icons';
7
7
  import { Typography, Button, Modal, Textarea, Input } from '@bigbinary/neetoui';
8
- import { reject, prop, isEmpty, assocPath, remove, move, append, path, last, pluck } from 'ramda';
8
+ import { reject, prop, isEmpty, assocPath, remove, move, append, path, pluck } from 'ramda';
9
9
  import { useTranslation, Trans } from 'react-i18next';
10
10
  import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
11
11
  import { _ as _toConsumableArray } from './toConsumableArray-1cc38429.js';
12
12
  import { _ as _defineProperty } from './defineProperty-549061a7.js';
13
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 : {};
14
+ import i18next from 'i18next';
16
15
 
17
16
  var DragHandle = function DragHandle(props) {
18
17
  return /*#__PURE__*/React__default.createElement("div", _extends({
@@ -143,514 +142,7 @@ var BulkOptionModal = function BulkOptionModal(_ref) {
143
142
  })));
144
143
  };
145
144
 
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;
145
+ var DEFAULT_OPTION_LABEL = i18next.t("neetoMolecules.optionFields.defaultOption");
654
146
 
655
147
  var getVisibleOptions = function getVisibleOptions() {
656
148
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -680,7 +172,9 @@ var useOptionFields = function useOptionFields(_ref) {
680
172
  shouldDestroy = _ref.shouldDestroy,
681
173
  _ref$name = _ref.name,
682
174
  name = _ref$name === void 0 ? "" : _ref$name,
683
- currentRecord = _ref.currentRecord;
175
+ currentRecord = _ref.currentRecord,
176
+ _ref$itemLabel = _ref.itemLabel,
177
+ itemLabel = _ref$itemLabel === void 0 ? DEFAULT_OPTION_LABEL : _ref$itemLabel;
684
178
  var _useState = useState(false),
685
179
  _useState2 = _slicedToArray(_useState, 2),
686
180
  shouldFocus = _useState2[0],
@@ -702,7 +196,7 @@ var useOptionFields = function useOptionFields(_ref) {
702
196
  };
703
197
  var generateLabel = function generateLabel(opts, count) {
704
198
  var labelCount = count || opts.length + 1;
705
- var tempLabel = "".concat(capitalize(pluralize.singular(last(name.split(".")))), " ").concat(labelCount);
199
+ var tempLabel = "".concat(itemLabel, " ").concat(labelCount);
706
200
  var isDuplicateLabel = pluck("label", opts).includes(tempLabel);
707
201
  return isDuplicateLabel ? generateLabel(opts, labelCount + 1) : tempLabel;
708
202
  };
@@ -859,6 +353,7 @@ var OptionFields = function OptionFields(_ref) {
859
353
  onChange = _ref.onChange,
860
354
  name = _ref.name,
861
355
  onDelete = _ref.onDelete,
356
+ itemLabel = _ref.itemLabel,
862
357
  _ref$onEdit = _ref.onEdit,
863
358
  onEdit = _ref$onEdit === void 0 ? noop : _ref$onEdit,
864
359
  _ref$buttonProps = _ref.buttonProps,
@@ -893,7 +388,8 @@ var OptionFields = function OptionFields(_ref) {
893
388
  onChange: onChange,
894
389
  shouldDestroy: shouldDestroy,
895
390
  name: name,
896
- currentRecord: currentRecord
391
+ currentRecord: currentRecord,
392
+ itemLabel: itemLabel
897
393
  }),
898
394
  shouldFocus = _useOptionFields.shouldFocus,
899
395
  handleAddOption = _useOptionFields.handleAddOption,
@@ -917,7 +413,8 @@ var OptionFields = function OptionFields(_ref) {
917
413
  var visibleOptions = getVisibleOptions(options);
918
414
  var hideDeleteOption = visibleOptions.length <= minOptions;
919
415
  var getUniqueOptionId = function getUniqueOptionId(option) {
920
- return option.altId || option.id.toString() || option.position.toString() || slugify(option.label);
416
+ var _option$id, _option$position;
417
+ return option.altId || ((_option$id = option.id) === null || _option$id === void 0 ? void 0 : _option$id.toString()) || ((_option$position = option.position) === null || _option$position === void 0 ? void 0 : _option$position.toString()) || slugify(option.label);
921
418
  };
922
419
  return /*#__PURE__*/React__default.createElement("form", {
923
420
  onSubmit: function onSubmit(e) {