@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.
@@ -13,12 +13,12 @@ var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
13
13
  var toConsumableArray = require('./toConsumableArray-9abb3858.js');
14
14
  var defineProperty = require('./defineProperty-886ed289.js');
15
15
  var formik = require('formik');
16
+ var i18next = require('i18next');
16
17
 
17
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
19
 
19
20
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
20
-
21
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
21
+ var i18next__default = /*#__PURE__*/_interopDefaultLegacy(i18next);
22
22
 
23
23
  var DragHandle = function DragHandle(props) {
24
24
  return /*#__PURE__*/React__default["default"].createElement("div", _extends._extends({
@@ -149,514 +149,7 @@ var BulkOptionModal = function BulkOptionModal(_ref) {
149
149
  })));
150
150
  };
151
151
 
152
- function commonjsRequire(path) {
153
- 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.');
154
- }
155
-
156
- var pluralize$1 = {exports: {}};
157
-
158
- /* global define */
159
-
160
- (function (module, exports) {
161
- (function (root, pluralize) {
162
- /* istanbul ignore else */
163
- if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
164
- // Node.
165
- module.exports = pluralize();
166
- } else {
167
- // Browser global.
168
- root.pluralize = pluralize();
169
- }
170
- })(commonjsGlobal, function () {
171
- // Rule storage - pluralize and singularize need to be run sequentially,
172
- // while other rules can be optimized using an object for instant lookups.
173
- var pluralRules = [];
174
- var singularRules = [];
175
- var uncountables = {};
176
- var irregularPlurals = {};
177
- var irregularSingles = {};
178
-
179
- /**
180
- * Sanitize a pluralization rule to a usable regular expression.
181
- *
182
- * @param {(RegExp|string)} rule
183
- * @return {RegExp}
184
- */
185
- function sanitizeRule (rule) {
186
- if (typeof rule === 'string') {
187
- return new RegExp('^' + rule + '$', 'i');
188
- }
189
-
190
- return rule;
191
- }
192
-
193
- /**
194
- * Pass in a word token to produce a function that can replicate the case on
195
- * another word.
196
- *
197
- * @param {string} word
198
- * @param {string} token
199
- * @return {Function}
200
- */
201
- function restoreCase (word, token) {
202
- // Tokens are an exact match.
203
- if (word === token) return token;
204
-
205
- // Lower cased words. E.g. "hello".
206
- if (word === word.toLowerCase()) return token.toLowerCase();
207
-
208
- // Upper cased words. E.g. "WHISKY".
209
- if (word === word.toUpperCase()) return token.toUpperCase();
210
-
211
- // Title cased words. E.g. "Title".
212
- if (word[0] === word[0].toUpperCase()) {
213
- return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
214
- }
215
-
216
- // Lower cased words. E.g. "test".
217
- return token.toLowerCase();
218
- }
219
-
220
- /**
221
- * Interpolate a regexp string.
222
- *
223
- * @param {string} str
224
- * @param {Array} args
225
- * @return {string}
226
- */
227
- function interpolate (str, args) {
228
- return str.replace(/\$(\d{1,2})/g, function (match, index) {
229
- return args[index] || '';
230
- });
231
- }
232
-
233
- /**
234
- * Replace a word using a rule.
235
- *
236
- * @param {string} word
237
- * @param {Array} rule
238
- * @return {string}
239
- */
240
- function replace (word, rule) {
241
- return word.replace(rule[0], function (match, index) {
242
- var result = interpolate(rule[1], arguments);
243
-
244
- if (match === '') {
245
- return restoreCase(word[index - 1], result);
246
- }
247
-
248
- return restoreCase(match, result);
249
- });
250
- }
251
-
252
- /**
253
- * Sanitize a word by passing in the word and sanitization rules.
254
- *
255
- * @param {string} token
256
- * @param {string} word
257
- * @param {Array} rules
258
- * @return {string}
259
- */
260
- function sanitizeWord (token, word, rules) {
261
- // Empty string or doesn't need fixing.
262
- if (!token.length || uncountables.hasOwnProperty(token)) {
263
- return word;
264
- }
265
-
266
- var len = rules.length;
267
-
268
- // Iterate over the sanitization rules and use the first one to match.
269
- while (len--) {
270
- var rule = rules[len];
271
-
272
- if (rule[0].test(word)) return replace(word, rule);
273
- }
274
-
275
- return word;
276
- }
277
-
278
- /**
279
- * Replace a word with the updated word.
280
- *
281
- * @param {Object} replaceMap
282
- * @param {Object} keepMap
283
- * @param {Array} rules
284
- * @return {Function}
285
- */
286
- function replaceWord (replaceMap, keepMap, rules) {
287
- return function (word) {
288
- // Get the correct token and case restoration functions.
289
- var token = word.toLowerCase();
290
-
291
- // Check against the keep object map.
292
- if (keepMap.hasOwnProperty(token)) {
293
- return restoreCase(word, token);
294
- }
295
-
296
- // Check against the replacement map for a direct word replacement.
297
- if (replaceMap.hasOwnProperty(token)) {
298
- return restoreCase(word, replaceMap[token]);
299
- }
300
-
301
- // Run all the rules against the word.
302
- return sanitizeWord(token, word, rules);
303
- };
304
- }
305
-
306
- /**
307
- * Check if a word is part of the map.
308
- */
309
- function checkWord (replaceMap, keepMap, rules, bool) {
310
- return function (word) {
311
- var token = word.toLowerCase();
312
-
313
- if (keepMap.hasOwnProperty(token)) return true;
314
- if (replaceMap.hasOwnProperty(token)) return false;
315
-
316
- return sanitizeWord(token, token, rules) === token;
317
- };
318
- }
319
-
320
- /**
321
- * Pluralize or singularize a word based on the passed in count.
322
- *
323
- * @param {string} word The word to pluralize
324
- * @param {number} count How many of the word exist
325
- * @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
326
- * @return {string}
327
- */
328
- function pluralize (word, count, inclusive) {
329
- var pluralized = count === 1
330
- ? pluralize.singular(word) : pluralize.plural(word);
331
-
332
- return (inclusive ? count + ' ' : '') + pluralized;
333
- }
334
-
335
- /**
336
- * Pluralize a word.
337
- *
338
- * @type {Function}
339
- */
340
- pluralize.plural = replaceWord(
341
- irregularSingles, irregularPlurals, pluralRules
342
- );
343
-
344
- /**
345
- * Check if a word is plural.
346
- *
347
- * @type {Function}
348
- */
349
- pluralize.isPlural = checkWord(
350
- irregularSingles, irregularPlurals, pluralRules
351
- );
352
-
353
- /**
354
- * Singularize a word.
355
- *
356
- * @type {Function}
357
- */
358
- pluralize.singular = replaceWord(
359
- irregularPlurals, irregularSingles, singularRules
360
- );
361
-
362
- /**
363
- * Check if a word is singular.
364
- *
365
- * @type {Function}
366
- */
367
- pluralize.isSingular = checkWord(
368
- irregularPlurals, irregularSingles, singularRules
369
- );
370
-
371
- /**
372
- * Add a pluralization rule to the collection.
373
- *
374
- * @param {(string|RegExp)} rule
375
- * @param {string} replacement
376
- */
377
- pluralize.addPluralRule = function (rule, replacement) {
378
- pluralRules.push([sanitizeRule(rule), replacement]);
379
- };
380
-
381
- /**
382
- * Add a singularization rule to the collection.
383
- *
384
- * @param {(string|RegExp)} rule
385
- * @param {string} replacement
386
- */
387
- pluralize.addSingularRule = function (rule, replacement) {
388
- singularRules.push([sanitizeRule(rule), replacement]);
389
- };
390
-
391
- /**
392
- * Add an uncountable word rule.
393
- *
394
- * @param {(string|RegExp)} word
395
- */
396
- pluralize.addUncountableRule = function (word) {
397
- if (typeof word === 'string') {
398
- uncountables[word.toLowerCase()] = true;
399
- return;
400
- }
401
-
402
- // Set singular and plural references for the word.
403
- pluralize.addPluralRule(word, '$0');
404
- pluralize.addSingularRule(word, '$0');
405
- };
406
-
407
- /**
408
- * Add an irregular word definition.
409
- *
410
- * @param {string} single
411
- * @param {string} plural
412
- */
413
- pluralize.addIrregularRule = function (single, plural) {
414
- plural = plural.toLowerCase();
415
- single = single.toLowerCase();
416
-
417
- irregularSingles[single] = plural;
418
- irregularPlurals[plural] = single;
419
- };
420
-
421
- /**
422
- * Irregular rules.
423
- */
424
- [
425
- // Pronouns.
426
- ['I', 'we'],
427
- ['me', 'us'],
428
- ['he', 'they'],
429
- ['she', 'they'],
430
- ['them', 'them'],
431
- ['myself', 'ourselves'],
432
- ['yourself', 'yourselves'],
433
- ['itself', 'themselves'],
434
- ['herself', 'themselves'],
435
- ['himself', 'themselves'],
436
- ['themself', 'themselves'],
437
- ['is', 'are'],
438
- ['was', 'were'],
439
- ['has', 'have'],
440
- ['this', 'these'],
441
- ['that', 'those'],
442
- // Words ending in with a consonant and `o`.
443
- ['echo', 'echoes'],
444
- ['dingo', 'dingoes'],
445
- ['volcano', 'volcanoes'],
446
- ['tornado', 'tornadoes'],
447
- ['torpedo', 'torpedoes'],
448
- // Ends with `us`.
449
- ['genus', 'genera'],
450
- ['viscus', 'viscera'],
451
- // Ends with `ma`.
452
- ['stigma', 'stigmata'],
453
- ['stoma', 'stomata'],
454
- ['dogma', 'dogmata'],
455
- ['lemma', 'lemmata'],
456
- ['schema', 'schemata'],
457
- ['anathema', 'anathemata'],
458
- // Other irregular rules.
459
- ['ox', 'oxen'],
460
- ['axe', 'axes'],
461
- ['die', 'dice'],
462
- ['yes', 'yeses'],
463
- ['foot', 'feet'],
464
- ['eave', 'eaves'],
465
- ['goose', 'geese'],
466
- ['tooth', 'teeth'],
467
- ['quiz', 'quizzes'],
468
- ['human', 'humans'],
469
- ['proof', 'proofs'],
470
- ['carve', 'carves'],
471
- ['valve', 'valves'],
472
- ['looey', 'looies'],
473
- ['thief', 'thieves'],
474
- ['groove', 'grooves'],
475
- ['pickaxe', 'pickaxes'],
476
- ['passerby', 'passersby']
477
- ].forEach(function (rule) {
478
- return pluralize.addIrregularRule(rule[0], rule[1]);
479
- });
480
-
481
- /**
482
- * Pluralization rules.
483
- */
484
- [
485
- [/s?$/i, 's'],
486
- [/[^\u0000-\u007F]$/i, '$0'],
487
- [/([^aeiou]ese)$/i, '$1'],
488
- [/(ax|test)is$/i, '$1es'],
489
- [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
490
- [/(e[mn]u)s?$/i, '$1s'],
491
- [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
492
- [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
493
- [/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
494
- [/(seraph|cherub)(?:im)?$/i, '$1im'],
495
- [/(her|at|gr)o$/i, '$1oes'],
496
- [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
497
- [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
498
- [/sis$/i, 'ses'],
499
- [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
500
- [/([^aeiouy]|qu)y$/i, '$1ies'],
501
- [/([^ch][ieo][ln])ey$/i, '$1ies'],
502
- [/(x|ch|ss|sh|zz)$/i, '$1es'],
503
- [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
504
- [/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'],
505
- [/(pe)(?:rson|ople)$/i, '$1ople'],
506
- [/(child)(?:ren)?$/i, '$1ren'],
507
- [/eaux$/i, '$0'],
508
- [/m[ae]n$/i, 'men'],
509
- ['thou', 'you']
510
- ].forEach(function (rule) {
511
- return pluralize.addPluralRule(rule[0], rule[1]);
512
- });
513
-
514
- /**
515
- * Singularization rules.
516
- */
517
- [
518
- [/s$/i, ''],
519
- [/(ss)$/i, '$1'],
520
- [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
521
- [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
522
- [/ies$/i, 'y'],
523
- [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
524
- [/\b(mon|smil)ies$/i, '$1ey'],
525
- [/\b((?:tit)?m|l)ice$/i, '$1ouse'],
526
- [/(seraph|cherub)im$/i, '$1'],
527
- [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
528
- [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
529
- [/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
530
- [/(test)(?:is|es)$/i, '$1is'],
531
- [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
532
- [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
533
- [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
534
- [/(alumn|alg|vertebr)ae$/i, '$1a'],
535
- [/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
536
- [/(matr|append)ices$/i, '$1ix'],
537
- [/(pe)(rson|ople)$/i, '$1rson'],
538
- [/(child)ren$/i, '$1'],
539
- [/(eau)x?$/i, '$1'],
540
- [/men$/i, 'man']
541
- ].forEach(function (rule) {
542
- return pluralize.addSingularRule(rule[0], rule[1]);
543
- });
544
-
545
- /**
546
- * Uncountable rules.
547
- */
548
- [
549
- // Singular words with no plurals.
550
- 'adulthood',
551
- 'advice',
552
- 'agenda',
553
- 'aid',
554
- 'aircraft',
555
- 'alcohol',
556
- 'ammo',
557
- 'analytics',
558
- 'anime',
559
- 'athletics',
560
- 'audio',
561
- 'bison',
562
- 'blood',
563
- 'bream',
564
- 'buffalo',
565
- 'butter',
566
- 'carp',
567
- 'cash',
568
- 'chassis',
569
- 'chess',
570
- 'clothing',
571
- 'cod',
572
- 'commerce',
573
- 'cooperation',
574
- 'corps',
575
- 'debris',
576
- 'diabetes',
577
- 'digestion',
578
- 'elk',
579
- 'energy',
580
- 'equipment',
581
- 'excretion',
582
- 'expertise',
583
- 'firmware',
584
- 'flounder',
585
- 'fun',
586
- 'gallows',
587
- 'garbage',
588
- 'graffiti',
589
- 'hardware',
590
- 'headquarters',
591
- 'health',
592
- 'herpes',
593
- 'highjinks',
594
- 'homework',
595
- 'housework',
596
- 'information',
597
- 'jeans',
598
- 'justice',
599
- 'kudos',
600
- 'labour',
601
- 'literature',
602
- 'machinery',
603
- 'mackerel',
604
- 'mail',
605
- 'media',
606
- 'mews',
607
- 'moose',
608
- 'music',
609
- 'mud',
610
- 'manga',
611
- 'news',
612
- 'only',
613
- 'personnel',
614
- 'pike',
615
- 'plankton',
616
- 'pliers',
617
- 'police',
618
- 'pollution',
619
- 'premises',
620
- 'rain',
621
- 'research',
622
- 'rice',
623
- 'salmon',
624
- 'scissors',
625
- 'series',
626
- 'sewage',
627
- 'shambles',
628
- 'shrimp',
629
- 'software',
630
- 'species',
631
- 'staff',
632
- 'swine',
633
- 'tennis',
634
- 'traffic',
635
- 'transportation',
636
- 'trout',
637
- 'tuna',
638
- 'wealth',
639
- 'welfare',
640
- 'whiting',
641
- 'wildebeest',
642
- 'wildlife',
643
- 'you',
644
- /pok[eé]mon$/i,
645
- // Regexes.
646
- /[^aeiou]ese$/i, // "chinese", "japanese"
647
- /deer$/i, // "deer", "reindeer"
648
- /fish$/i, // "fish", "blowfish", "angelfish"
649
- /measles$/i,
650
- /o[iu]s$/i, // "carnivorous"
651
- /pox$/i, // "chickpox", "smallpox"
652
- /sheep$/i
653
- ].forEach(pluralize.addUncountableRule);
654
-
655
- return pluralize;
656
- });
657
- } (pluralize$1));
658
-
659
- var pluralize = pluralize$1.exports;
152
+ var DEFAULT_OPTION_LABEL = i18next__default["default"].t("neetoMolecules.optionFields.defaultOption");
660
153
 
661
154
  var getVisibleOptions = function getVisibleOptions() {
662
155
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
@@ -686,7 +179,9 @@ var useOptionFields = function useOptionFields(_ref) {
686
179
  shouldDestroy = _ref.shouldDestroy,
687
180
  _ref$name = _ref.name,
688
181
  name = _ref$name === void 0 ? "" : _ref$name,
689
- currentRecord = _ref.currentRecord;
182
+ currentRecord = _ref.currentRecord,
183
+ _ref$itemLabel = _ref.itemLabel,
184
+ itemLabel = _ref$itemLabel === void 0 ? DEFAULT_OPTION_LABEL : _ref$itemLabel;
690
185
  var _useState = React.useState(false),
691
186
  _useState2 = slicedToArray._slicedToArray(_useState, 2),
692
187
  shouldFocus = _useState2[0],
@@ -708,7 +203,7 @@ var useOptionFields = function useOptionFields(_ref) {
708
203
  };
709
204
  var generateLabel = function generateLabel(opts, count) {
710
205
  var labelCount = count || opts.length + 1;
711
- var tempLabel = "".concat(neetoCist.capitalize(pluralize.singular(ramda.last(name.split(".")))), " ").concat(labelCount);
206
+ var tempLabel = "".concat(itemLabel, " ").concat(labelCount);
712
207
  var isDuplicateLabel = ramda.pluck("label", opts).includes(tempLabel);
713
208
  return isDuplicateLabel ? generateLabel(opts, labelCount + 1) : tempLabel;
714
209
  };
@@ -865,6 +360,7 @@ var OptionFields = function OptionFields(_ref) {
865
360
  onChange = _ref.onChange,
866
361
  name = _ref.name,
867
362
  onDelete = _ref.onDelete,
363
+ itemLabel = _ref.itemLabel,
868
364
  _ref$onEdit = _ref.onEdit,
869
365
  onEdit = _ref$onEdit === void 0 ? neetoCist.noop : _ref$onEdit,
870
366
  _ref$buttonProps = _ref.buttonProps,
@@ -899,7 +395,8 @@ var OptionFields = function OptionFields(_ref) {
899
395
  onChange: onChange,
900
396
  shouldDestroy: shouldDestroy,
901
397
  name: name,
902
- currentRecord: currentRecord
398
+ currentRecord: currentRecord,
399
+ itemLabel: itemLabel
903
400
  }),
904
401
  shouldFocus = _useOptionFields.shouldFocus,
905
402
  handleAddOption = _useOptionFields.handleAddOption,
@@ -923,7 +420,8 @@ var OptionFields = function OptionFields(_ref) {
923
420
  var visibleOptions = getVisibleOptions(options);
924
421
  var hideDeleteOption = visibleOptions.length <= minOptions;
925
422
  var getUniqueOptionId = function getUniqueOptionId(option) {
926
- return option.altId || option.id.toString() || option.position.toString() || neetoCist.slugify(option.label);
423
+ var _option$id, _option$position;
424
+ 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()) || neetoCist.slugify(option.label);
927
425
  };
928
426
  return /*#__PURE__*/React__default["default"].createElement("form", {
929
427
  onSubmit: function onSubmit(e) {