@formio/js 5.1.0-dev.5913.5ccc183 → 5.1.0-dev.5936.81a1533

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +2 -0
  2. package/dist/formio.form.js +112 -123
  3. package/dist/formio.form.min.js +1 -1
  4. package/dist/formio.full.js +119 -130
  5. package/dist/formio.full.min.js +1 -1
  6. package/dist/formio.js +62 -51
  7. package/dist/formio.min.js +1 -1
  8. package/dist/formio.utils.js +73 -73
  9. package/dist/formio.utils.min.js +1 -1
  10. package/lib/cjs/Element.js +13 -36
  11. package/lib/cjs/EventEmitter.js +2 -25
  12. package/lib/cjs/Form.js +2 -25
  13. package/lib/cjs/PDF.js +1 -1
  14. package/lib/cjs/PDFBuilder.js +4 -5
  15. package/lib/cjs/Webform.js +5 -6
  16. package/lib/cjs/WebformBuilder.js +20 -15
  17. package/lib/cjs/Wizard.js +1 -1
  18. package/lib/cjs/WizardBuilder.js +1 -1
  19. package/lib/cjs/components/_classes/component/Component.d.ts +0 -1
  20. package/lib/cjs/components/_classes/component/Component.js +36 -57
  21. package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  22. package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  23. package/lib/cjs/components/_classes/componentModal/ComponentModal.js +1 -1
  24. package/lib/cjs/components/_classes/input/Input.js +1 -1
  25. package/lib/cjs/components/_classes/list/ListComponent.js +1 -1
  26. package/lib/cjs/components/_classes/nested/NestedComponent.js +6 -6
  27. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  28. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  29. package/lib/cjs/components/address/Address.js +1 -1
  30. package/lib/cjs/components/alert/Alert.js +1 -1
  31. package/lib/cjs/components/button/Button.js +1 -1
  32. package/lib/cjs/components/checkbox/Checkbox.js +1 -1
  33. package/lib/cjs/components/container/Container.js +1 -1
  34. package/lib/cjs/components/currency/Currency.js +1 -1
  35. package/lib/cjs/components/datagrid/DataGrid.js +1 -1
  36. package/lib/cjs/components/datetime/DateTime.d.ts +1 -1
  37. package/lib/cjs/components/datetime/DateTime.js +15 -13
  38. package/lib/cjs/components/day/Day.js +2 -2
  39. package/lib/cjs/components/editgrid/EditGrid.js +1 -1
  40. package/lib/cjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
  41. package/lib/cjs/components/file/File.js +1 -1
  42. package/lib/cjs/components/form/Form.js +14 -2
  43. package/lib/cjs/components/form/editForm/Form.edit.form.js +4 -3
  44. package/lib/cjs/components/number/Number.js +1 -1
  45. package/lib/cjs/components/panel/Panel.js +1 -1
  46. package/lib/cjs/components/radio/Radio.d.ts +4 -0
  47. package/lib/cjs/components/radio/Radio.js +69 -23
  48. package/lib/cjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
  49. package/lib/cjs/components/select/Select.js +1 -1
  50. package/lib/cjs/components/select/editForm/Select.edit.data.js +1 -1
  51. package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
  52. package/lib/cjs/components/signature/Signature.js +1 -1
  53. package/lib/cjs/components/survey/Survey.js +1 -1
  54. package/lib/cjs/components/tags/Tags.js +1 -1
  55. package/lib/cjs/components/textarea/TextArea.js +3 -3
  56. package/lib/cjs/components/textfield/TextField.js +7 -30
  57. package/lib/cjs/components/time/Time.js +1 -1
  58. package/lib/cjs/formio.form.js +3 -3
  59. package/lib/cjs/i18n.js +1 -1
  60. package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
  61. package/lib/cjs/utils/Evaluator.d.ts +20 -6
  62. package/lib/cjs/utils/Evaluator.js +38 -15
  63. package/lib/cjs/utils/builder.js +5 -5
  64. package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
  65. package/lib/cjs/utils/i18n.js +3 -3
  66. package/lib/cjs/utils/index.d.ts +169 -2
  67. package/lib/cjs/utils/index.js +22 -2
  68. package/lib/cjs/utils/utils.d.ts +22 -37
  69. package/lib/cjs/utils/utils.js +54 -132
  70. package/lib/cjs/widgets/CalendarWidget.d.ts +1 -8
  71. package/lib/cjs/widgets/CalendarWidget.js +17 -43
  72. package/lib/mjs/Element.js +6 -6
  73. package/lib/mjs/EventEmitter.js +2 -2
  74. package/lib/mjs/Form.js +1 -1
  75. package/lib/mjs/PDF.js +1 -1
  76. package/lib/mjs/PDFBuilder.js +1 -2
  77. package/lib/mjs/Webform.js +3 -4
  78. package/lib/mjs/WebformBuilder.js +12 -7
  79. package/lib/mjs/Wizard.js +1 -1
  80. package/lib/mjs/WizardBuilder.js +1 -1
  81. package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
  82. package/lib/mjs/components/_classes/component/Component.js +9 -7
  83. package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
  84. package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
  85. package/lib/mjs/components/_classes/componentModal/ComponentModal.js +1 -1
  86. package/lib/mjs/components/_classes/input/Input.js +1 -1
  87. package/lib/mjs/components/_classes/list/ListComponent.js +1 -1
  88. package/lib/mjs/components/_classes/nested/NestedComponent.js +6 -6
  89. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  90. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  91. package/lib/mjs/components/address/Address.js +1 -1
  92. package/lib/mjs/components/alert/Alert.js +1 -1
  93. package/lib/mjs/components/button/Button.js +1 -1
  94. package/lib/mjs/components/checkbox/Checkbox.js +1 -1
  95. package/lib/mjs/components/container/Container.js +1 -1
  96. package/lib/mjs/components/currency/Currency.js +1 -1
  97. package/lib/mjs/components/datagrid/DataGrid.js +1 -1
  98. package/lib/mjs/components/datetime/DateTime.d.ts +1 -1
  99. package/lib/mjs/components/datetime/DateTime.js +15 -13
  100. package/lib/mjs/components/day/Day.js +2 -2
  101. package/lib/mjs/components/editgrid/EditGrid.js +1 -1
  102. package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
  103. package/lib/mjs/components/file/File.js +1 -1
  104. package/lib/mjs/components/form/Form.js +13 -2
  105. package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -2
  106. package/lib/mjs/components/number/Number.js +1 -1
  107. package/lib/mjs/components/panel/Panel.js +1 -1
  108. package/lib/mjs/components/radio/Radio.d.ts +4 -0
  109. package/lib/mjs/components/radio/Radio.js +68 -23
  110. package/lib/mjs/components/recaptcha/editForm/ReCaptcha.edit.display.js +1 -1
  111. package/lib/mjs/components/select/Select.js +1 -1
  112. package/lib/mjs/components/select/editForm/Select.edit.data.js +1 -1
  113. package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
  114. package/lib/mjs/components/signature/Signature.js +1 -1
  115. package/lib/mjs/components/survey/Survey.js +1 -1
  116. package/lib/mjs/components/tags/Tags.js +1 -1
  117. package/lib/mjs/components/textarea/TextArea.js +3 -3
  118. package/lib/mjs/components/textfield/TextField.js +1 -1
  119. package/lib/mjs/components/time/Time.js +1 -1
  120. package/lib/mjs/formio.form.js +2 -2
  121. package/lib/mjs/i18n.js +1 -1
  122. package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
  123. package/lib/mjs/utils/Evaluator.d.ts +20 -6
  124. package/lib/mjs/utils/Evaluator.js +31 -13
  125. package/lib/mjs/utils/builder.js +1 -1
  126. package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
  127. package/lib/mjs/utils/i18n.js +1 -1
  128. package/lib/mjs/utils/index.d.ts +169 -2
  129. package/lib/mjs/utils/index.js +18 -1
  130. package/lib/mjs/utils/utils.d.ts +22 -37
  131. package/lib/mjs/utils/utils.js +47 -107
  132. package/lib/mjs/widgets/CalendarWidget.d.ts +1 -8
  133. package/lib/mjs/widgets/CalendarWidget.js +17 -43
  134. package/package.json +5 -3
@@ -8,7 +8,7 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const Component_1 = __importDefault(require("../_classes/component/Component"));
9
9
  const ComponentModal_1 = __importDefault(require("../_classes/componentModal/ComponentModal"));
10
10
  const eventemitter3_1 = __importDefault(require("eventemitter3"));
11
- const utils_1 = require("../../utils/utils");
11
+ const utils_1 = require("../../utils");
12
12
  const Formio_1 = require("../../Formio");
13
13
  const Form_1 = __importDefault(require("../../Form"));
14
14
  class FormComponent extends Component_1.default {
@@ -278,6 +278,9 @@ class FormComponent extends Component_1.default {
278
278
  if (this.isSubFormLazyLoad() && !this.hasLoadedForm && !this.subFormLoading) {
279
279
  this.createSubForm(true);
280
280
  }
281
+ if (!this.subFormReady) {
282
+ return Promise.resolve();
283
+ }
281
284
  return this.subFormReady.then(() => {
282
285
  this.empty(element);
283
286
  if (this.options.builder) {
@@ -408,13 +411,15 @@ class FormComponent extends Component_1.default {
408
411
  }
409
412
  // Render the form.
410
413
  return (new Form_1.default(form, this.getSubOptions())).ready.then((instance) => {
414
+ var _a, _b;
411
415
  this.subForm = instance;
412
416
  this.subForm.currentForm = this;
413
417
  this.subForm.parentVisible = this.visible;
414
418
  const componentsMap = this.componentsMap;
415
419
  const formComponentsMap = this.subForm.componentsMap;
416
420
  lodash_1.default.assign(componentsMap, formComponentsMap);
417
- this.component.components = this.subForm.components.map((comp) => comp.component);
421
+ this.component.components = (_a = this.subForm._form) === null || _a === void 0 ? void 0 : _a.components;
422
+ this.component.display = (_b = this.subForm._form) === null || _b === void 0 ? void 0 : _b.display;
418
423
  this.subForm.on('change', () => {
419
424
  if (this.subForm && !this.shouldConditionallyClear()) {
420
425
  this.dataValue = this.subForm.getValue();
@@ -699,6 +704,13 @@ class FormComponent extends Component_1.default {
699
704
  }
700
705
  return errors;
701
706
  }
707
+ conditionallyHidden() {
708
+ const conditionallyHidden = super.conditionallyHidden();
709
+ if (this.subForm) {
710
+ this.subForm._conditionallyHidden = conditionallyHidden;
711
+ }
712
+ return conditionallyHidden;
713
+ }
702
714
  updateSubFormVisibility() {
703
715
  if (this.subForm) {
704
716
  this.subForm.parentVisible = this.visible;
@@ -32,10 +32,11 @@ exports.default = [
32
32
  tooltip: 'if it is checked, the subform is loaded after navigation to the page with this component within the wizard.',
33
33
  input: true,
34
34
  customConditional({ instance, data }) {
35
- var _a, _b, _c, _d;
36
- const formInfo = (_b = (_a = instance.root) === null || _a === void 0 ? void 0 : _a.getComponent('form')) === null || _b === void 0 ? void 0 : _b.defaultDownloadedResources.find(res => res._id === data.form);
35
+ var _a, _b, _c;
36
+ const formComp = (_a = instance.root) === null || _a === void 0 ? void 0 : _a.getComponent('form');
37
+ const formInfo = formComp === null || formComp === void 0 ? void 0 : formComp.defaultDownloadedResources.find(res => res._id === data.form);
37
38
  const displayMode = 'wizard';
38
- return ((_d = (_c = instance.options) === null || _c === void 0 ? void 0 : _c.editForm) === null || _d === void 0 ? void 0 : _d.display) === displayMode && formInfo && formInfo.display !== displayMode;
39
+ return ((_c = (_b = instance.options) === null || _b === void 0 ? void 0 : _b.editForm) === null || _c === void 0 ? void 0 : _c.display) === displayMode && ((data.form && !formInfo) || (formInfo && formInfo.display !== displayMode));
39
40
  },
40
41
  },
41
42
  {
@@ -7,7 +7,7 @@ const text_mask_addons_1 = require("@formio/text-mask-addons");
7
7
  const vanilla_text_mask_1 = require("@formio/vanilla-text-mask");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
9
  const Input_1 = __importDefault(require("../_classes/input/Input"));
10
- const utils_1 = require("../../utils/utils");
10
+ const utils_1 = require("../../utils/");
11
11
  class NumberComponent extends Input_1.default {
12
12
  static schema(...extend) {
13
13
  return Input_1.default.schema({
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const NestedComponent_1 = __importDefault(require("../_classes/nested/NestedComponent"));
7
- const utils_1 = require("../../utils/utils");
7
+ const utils_1 = require("../../utils");
8
8
  class PanelComponent extends NestedComponent_1.default {
9
9
  static schema(...extend) {
10
10
  return NestedComponent_1.default.schema({
@@ -27,6 +27,7 @@ export default class RadioComponent extends ListComponent {
27
27
  itemsLoadedResolve: ((value: any) => void) | undefined;
28
28
  optionsLoaded: boolean | undefined;
29
29
  loadedOptions: any[] | undefined;
30
+ valuesMap: Map<any, any> | undefined;
30
31
  beforeSubmit(): Promise<any>;
31
32
  render(): string;
32
33
  attach(element: any): Promise<void>;
@@ -35,10 +36,13 @@ export default class RadioComponent extends ListComponent {
35
36
  validateValueAvailability(setting: any, value: any): boolean;
36
37
  getValueAsString(value: any, options?: {}): any;
37
38
  setValueAt(index: any, value: any): void;
39
+ prepareValue(item: any, options?: {}): any;
40
+ getValueByInput(input: any): any;
38
41
  loadItems(url: any, search: any, headers: any, options: any, method: any, body: any): void;
39
42
  loadItemsFromMetadata(): void;
40
43
  setItems(items: any): void;
41
44
  setSelectedClasses(): void;
45
+ setMetadata(value: any): void;
42
46
  updateValue(value: any, flags: any): boolean;
43
47
  currentValue: any;
44
48
  }
@@ -7,6 +7,7 @@ const lodash_1 = __importDefault(require("lodash"));
7
7
  const ListComponent_1 = __importDefault(require("../_classes/list/ListComponent"));
8
8
  const Formio_1 = require("../../Formio");
9
9
  const utils_1 = require("../../utils/utils");
10
+ const uuid_1 = require("uuid");
10
11
  class RadioComponent extends ListComponent_1.default {
11
12
  static schema(...extend) {
12
13
  return ListComponent_1.default.schema({
@@ -142,6 +143,7 @@ class RadioComponent extends ListComponent_1.default {
142
143
  });
143
144
  this.optionsLoaded = !this.component.dataSrc || this.component.dataSrc === 'values';
144
145
  this.loadedOptions = [];
146
+ this.valuesMap = new Map();
145
147
  if (!this.visible) {
146
148
  this.itemsLoadedResolve();
147
149
  }
@@ -181,9 +183,12 @@ class RadioComponent extends ListComponent_1.default {
181
183
  if (!lodash_1.default.isString(this.dataValue)) {
182
184
  dataValue = lodash_1.default.toString(this.dataValue);
183
185
  }
184
- if (this.isSelectURL && lodash_1.default.isObject(this.loadedOptions[index].value)) {
185
- const optionValue = this.component.dataType === 'string' ? JSON.stringify(this.loadedOptions[index].value) : this.loadedOptions[index].value;
186
- input.checked = lodash_1.default.isEqual(optionValue, this.dataValue);
186
+ if (this.isSelectURL) {
187
+ const valueKey = this.loadedOptions[index].value;
188
+ const optionValue = this.valuesMap.has(valueKey)
189
+ ? this.valuesMap.get(valueKey)
190
+ : valueKey;
191
+ input.checked = lodash_1.default.isEqual(this.normalizeValue(optionValue), this.dataValue);
187
192
  }
188
193
  else {
189
194
  input.checked = (dataValue === input.value && (input.value || this.component.dataSrc !== 'url'));
@@ -220,9 +225,14 @@ class RadioComponent extends ListComponent_1.default {
220
225
  let value = this.component.inputType === 'checkbox' ? '' : this.dataValue;
221
226
  this.refs.input.forEach((input, index) => {
222
227
  if (input.checked) {
223
- value = (this.isSelectURL && lodash_1.default.isObject(this.loadedOptions[index].value)) ?
224
- this.loadedOptions[index].value :
225
- input.value;
228
+ if (!this.isSelectURL) {
229
+ value = input.value;
230
+ return;
231
+ }
232
+ const optionValue = this.loadedOptions[index].value;
233
+ value = this.valuesMap.has(optionValue)
234
+ ? this.valuesMap.get(optionValue)
235
+ : optionValue;
226
236
  }
227
237
  });
228
238
  return value;
@@ -266,8 +276,8 @@ class RadioComponent extends ListComponent_1.default {
266
276
  }
267
277
  setValueAt(index, value) {
268
278
  if (this.refs.input && this.refs.input[index] && value !== null && value !== undefined) {
269
- const inputValue = this.refs.input[index].value;
270
- this.refs.input[index].checked = (inputValue === value.toString());
279
+ const inputValue = this.getValueByInput(this.refs.input[index]);
280
+ this.refs.input[index].checked = lodash_1.default.isEqual(inputValue, value);
271
281
  }
272
282
  }
273
283
  get shouldLoad() {
@@ -277,6 +287,23 @@ class RadioComponent extends ListComponent_1.default {
277
287
  }
278
288
  return super.shouldLoad;
279
289
  }
290
+ prepareValue(item, options = {}) {
291
+ const value = this.component.valueProperty && !options.skipValueProperty
292
+ ? lodash_1.default.get(item, this.component.valueProperty)
293
+ : item;
294
+ if (this.component.type === 'radio' && typeof value !== 'string') {
295
+ const uuid = (0, uuid_1.v4)();
296
+ this.valuesMap.set(uuid, value);
297
+ return uuid;
298
+ }
299
+ return value;
300
+ }
301
+ getValueByInput(input) {
302
+ const inputValue = input.value;
303
+ return this.valuesMap.has(inputValue)
304
+ ? this.valuesMap.get(inputValue)
305
+ : inputValue;
306
+ }
280
307
  loadItems(url, search, headers, options, method, body) {
281
308
  if (this.optionsLoaded) {
282
309
  this.itemsLoadedResolve();
@@ -327,7 +354,7 @@ class RadioComponent extends ListComponent_1.default {
327
354
  label: this.itemTemplate(item)
328
355
  };
329
356
  if (lodash_1.default.isEqual(item, this.selectData || lodash_1.default.pick(this.dataValue, lodash_1.default.keys(item)))) {
330
- this.loadedOptions[i].value = this.dataValue;
357
+ this.loadedOptions[i].value = this.prepareValue(this.dataValue, { skipValueProperty: true });
331
358
  }
332
359
  });
333
360
  this.optionsLoaded = true;
@@ -337,12 +364,15 @@ class RadioComponent extends ListComponent_1.default {
337
364
  const listData = [];
338
365
  items === null || items === void 0 ? void 0 : items.forEach((item, i) => {
339
366
  const valueAtProperty = lodash_1.default.get(item, this.component.valueProperty);
340
- this.loadedOptions[i] = {
341
- value: this.component.valueProperty ? valueAtProperty : item,
342
- label: this.component.valueProperty ? this.itemTemplate(item, valueAtProperty) : this.itemTemplate(item, item, i)
343
- };
344
- listData.push(this.templateData[this.component.valueProperty ? valueAtProperty : i]);
345
- const value = this.loadedOptions[i].value;
367
+ const value = this.prepareValue(item);
368
+ const label = this.component.valueProperty
369
+ ? this.itemTemplate(item, valueAtProperty, i)
370
+ : this.itemTemplate(item, item, i);
371
+ this.loadedOptions[i] = { label, value };
372
+ listData.push(this.templateData[i]);
373
+ if (this.valuesMap.has(value)) {
374
+ this.templateData[value] = this.templateData[i];
375
+ }
346
376
  if (!this.isRadio && (lodash_1.default.isObject(value) || lodash_1.default.isBoolean(value) || lodash_1.default.isUndefined(value))) {
347
377
  this.loadedOptions[i].invalid = true;
348
378
  }
@@ -365,7 +395,11 @@ class RadioComponent extends ListComponent_1.default {
365
395
  const value = this.dataValue;
366
396
  this.refs.wrapper.forEach((wrapper, index) => {
367
397
  const input = this.refs.input[index];
368
- const checked = (value === undefined || value === null) ? false : (input.type === 'checkbox') ? value[input.value] || input.checked : (input.value.toString() === value.toString());
398
+ const checked = (value === undefined || value === null)
399
+ ? false
400
+ : (input.type === 'checkbox')
401
+ ? value[input.value] || input.checked
402
+ : lodash_1.default.isEqual(this.normalizeValue(this.getValueByInput(input)), value);
369
403
  if (checked) {
370
404
  //add class to container when selected
371
405
  this.addClass(wrapper, this.optionSelectedClass);
@@ -379,10 +413,26 @@ class RadioComponent extends ListComponent_1.default {
379
413
  });
380
414
  }
381
415
  }
416
+ setMetadata(value) {
417
+ var _a;
418
+ let key = value;
419
+ if (typeof value !== 'string') {
420
+ const checkedInput = Array.prototype.find.call((_a = this.refs.input) !== null && _a !== void 0 ? _a : [], (input => input.type === 'radio' && input.getAttribute('checked')));
421
+ key = (checkedInput === null || checkedInput === void 0 ? void 0 : checkedInput.value) || key;
422
+ }
423
+ if (this.isSelectURL && this.templateData && this.templateData[key]) {
424
+ const submission = this.root.submission;
425
+ if (!submission.metadata.selectData) {
426
+ submission.metadata.selectData = {};
427
+ }
428
+ lodash_1.default.set(submission.metadata.selectData, this.path, this.templateData[key]);
429
+ }
430
+ }
382
431
  updateValue(value, flags) {
383
432
  const changed = super.updateValue(value, flags);
384
433
  if (changed) {
385
434
  this.setSelectedClasses();
435
+ this.setMetadata(this.dataValue);
386
436
  }
387
437
  if (!flags || !flags.modified || !this.isRadio) {
388
438
  if (changed) {
@@ -438,14 +488,10 @@ class RadioComponent extends ListComponent_1.default {
438
488
  value = !(!value || value.toString() === 'false');
439
489
  break;
440
490
  }
441
- if (this.isSelectURL && this.templateData && this.templateData[value]) {
442
- const submission = this.root.submission;
443
- if (!submission.metadata.selectData) {
444
- submission.metadata.selectData = {};
445
- }
446
- lodash_1.default.set(submission.metadata.selectData, this.path, this.templateData[value]);
447
- }
448
491
  return super.normalizeValue(value);
449
492
  }
493
+ isSingleInputValue() {
494
+ return true;
495
+ }
450
496
  }
451
497
  exports.default = RadioComponent;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("../../../utils/utils");
3
+ const utils_1 = require("../../../utils");
4
4
  exports.default = [
5
5
  {
6
6
  key: 'recaptchaInfo',
@@ -7,7 +7,7 @@ const lodash_1 = __importDefault(require("lodash"));
7
7
  const Formio_1 = require("../../Formio");
8
8
  const ListComponent_1 = __importDefault(require("../_classes/list/ListComponent"));
9
9
  const Form_1 = __importDefault(require("../../Form"));
10
- const utils_1 = require("../../utils/utils");
10
+ const utils_1 = require("../../utils");
11
11
  const ChoicesWrapper_1 = __importDefault(require("../../utils/ChoicesWrapper"));
12
12
  class SelectComponent extends ListComponent_1.default {
13
13
  static schema(...extend) {
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
- const utils_1 = require("../../../utils/utils");
7
+ const utils_1 = require("../../../utils");
8
8
  const calculateSingleSelectData = (context, defaultValue) => {
9
9
  const { instance, data } = context;
10
10
  const rawDefaultValue = instance.downloadedResources.find(resource => lodash_1.default.get(resource, data.valueProperty) === defaultValue);
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
- const utils_1 = require("../../utils/utils");
7
+ const utils_1 = require("../../utils");
8
8
  const Radio_1 = __importDefault(require("../radio/Radio"));
9
9
  class SelectBoxesComponent extends Radio_1.default {
10
10
  static schema(...extend) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const signature_pad_1 = __importDefault(require("signature_pad"));
7
7
  const Input_1 = __importDefault(require("../_classes/input/Input"));
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
- const utils_1 = require("../../utils/utils");
9
+ const utils_1 = require("../../utils");
10
10
  class SignatureComponent extends Input_1.default {
11
11
  static schema(...extend) {
12
12
  return Input_1.default.schema({
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const lodash_1 = __importDefault(require("lodash"));
7
7
  const Field_1 = __importDefault(require("../_classes/field/Field"));
8
- const utils_1 = require("../../utils/utils");
8
+ const utils_1 = require("../../utils");
9
9
  class SurveyComponent extends Field_1.default {
10
10
  static schema(...extend) {
11
11
  return Field_1.default.schema({
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const utils_1 = require("../../utils/utils");
6
+ const utils_1 = require("../../utils");
7
7
  const Input_1 = __importDefault(require("../_classes/input/Input"));
8
8
  const choices_js_1 = __importDefault(require("choices.js"));
9
9
  class TagsComponent extends Input_1.default {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* global Quill */
7
7
  const TextField_1 = __importDefault(require("../textfield/TextField"));
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
- const utils_1 = require("../../utils/utils");
9
+ const utils_1 = require("../../utils");
10
10
  class TextAreaComponent extends TextField_1.default {
11
11
  static schema(...extend) {
12
12
  return TextField_1.default.schema({
@@ -63,8 +63,8 @@ class TextAreaComponent extends TextField_1.default {
63
63
  if ((this.options.readOnly || this.disabled) && !this.isHtmlRenderMode()) {
64
64
  const elementStyle = this.info.attr.style || '';
65
65
  const children = `
66
- <div ${this._referenceAttributeName}="input"
67
- class="formio-editor-read-only-content"
66
+ <div ${this._referenceAttributeName}="input"
67
+ class="formio-editor-read-only-content"
68
68
  ${elementStyle ? `style='${elementStyle}'` : ''}
69
69
  role="textbox"
70
70
  aria-multiline="true"
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
@@ -29,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
6
  const Input_1 = __importDefault(require("../_classes/input/Input"));
30
7
  const vanilla_text_mask_1 = require("@formio/vanilla-text-mask");
31
8
  const inputmask_1 = __importDefault(require("inputmask"));
32
- const FormioUtils = __importStar(require("../../utils/utils"));
9
+ const utils_1 = __importDefault(require("../../utils"));
33
10
  const lodash_1 = __importDefault(require("lodash"));
34
11
  class TextFieldComponent extends Input_1.default {
35
12
  static schema(...extend) {
@@ -71,7 +48,7 @@ class TextFieldComponent extends Input_1.default {
71
48
  } });
72
49
  }
73
50
  static savedValueTypes(schema) {
74
- return FormioUtils.getComponentSavedTypes(schema) || [FormioUtils.componentValueTypes.string];
51
+ return utils_1.default.getComponentSavedTypes(schema) || [utils_1.default.componentValueTypes.string];
75
52
  }
76
53
  get defaultSchema() {
77
54
  return TextFieldComponent.schema();
@@ -104,7 +81,7 @@ class TextFieldComponent extends Input_1.default {
104
81
  displayInTimezone, locale: this.component.widget.locale || this.options.language, saveAs: 'text' });
105
82
  // update originalComponent to include widget settings after component initialization
106
83
  // originalComponent is used to restore the component (and widget) after evaluating field logic
107
- this.originalComponent = FormioUtils.fastCloneDeep(this.component);
84
+ this.originalComponent = utils_1.default.fastCloneDeep(this.component);
108
85
  }
109
86
  }
110
87
  attach(element) {
@@ -175,7 +152,7 @@ class TextFieldComponent extends Input_1.default {
175
152
  }
176
153
  else {
177
154
  const placeholderChar = this.placeholderChar;
178
- textInput.value = (0, vanilla_text_mask_1.conformToMask)(textValue, FormioUtils.getInputMask(mask), { placeholderChar }).conformedValue;
155
+ textInput.value = (0, vanilla_text_mask_1.conformToMask)(textValue, utils_1.default.getInputMask(mask), { placeholderChar }).conformedValue;
179
156
  }
180
157
  }
181
158
  else {
@@ -183,8 +160,8 @@ class TextFieldComponent extends Input_1.default {
183
160
  }
184
161
  }
185
162
  unmaskValue(value, format = this.component.displayMask) {
186
- const mask = FormioUtils.getInputMask(format, this.placeholderChar);
187
- return FormioUtils.unmaskValue(value, mask, this.placeholderChar);
163
+ const mask = utils_1.default.getInputMask(format, this.placeholderChar);
164
+ return utils_1.default.unmaskValue(value, mask, this.placeholderChar);
188
165
  }
189
166
  /**
190
167
  * Returns the value at this index.
@@ -245,7 +222,7 @@ class TextFieldComponent extends Input_1.default {
245
222
  return;
246
223
  }
247
224
  inputMask = inputMask || this.component.displayMask || this.component.inputMask;
248
- const mask = FormioUtils.getInputMask(inputMask, this.placeholderChar);
225
+ const mask = utils_1.default.getInputMask(inputMask, this.placeholderChar);
249
226
  this.defaultMask = mask;
250
227
  if (input && inputMask) {
251
228
  try {
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const moment_1 = __importDefault(require("moment"));
7
7
  const TextField_1 = __importDefault(require("../textfield/TextField"));
8
- const utils_1 = require("../../utils/utils");
8
+ const utils_1 = require("../../utils");
9
9
  const defaultDataFormat = 'HH:mm:ss';
10
10
  class TimeComponent extends TextField_1.default {
11
11
  static schema(...extend) {
@@ -22,7 +22,6 @@ const Form_1 = __importDefault(require("./Form"));
22
22
  exports.Form = Form_1.default;
23
23
  const utils_1 = __importDefault(require("./utils"));
24
24
  exports.Utils = utils_1.default;
25
- const Evaluator_1 = require("./utils/Evaluator");
26
25
  const licenses_1 = __importDefault(require("./licenses"));
27
26
  exports.Licenses = licenses_1.default;
28
27
  const EventEmitter_1 = __importDefault(require("./EventEmitter"));
@@ -30,6 +29,7 @@ exports.EventEmitter = EventEmitter_1.default;
30
29
  const Webform_1 = __importDefault(require("./Webform"));
31
30
  exports.Webform = Webform_1.default;
32
31
  const i18n_1 = require("./utils/i18n");
32
+ const utils_2 = require("./utils");
33
33
  Formio_1.Formio.loadModules = (path = `${Formio_1.Formio.getApiUrl()}/externalModules.js`, name = 'externalModules') => {
34
34
  Formio_1.Formio.requireLibrary(name, name, path, true)
35
35
  .then((modules) => {
@@ -45,7 +45,7 @@ Formio_1.Formio.Form = Form_1.default;
45
45
  Formio_1.Formio.Displays = Displays_1.default;
46
46
  Formio_1.Formio.Providers = providers_1.default;
47
47
  Formio_1.Formio.Widgets = widgets_1.default;
48
- Formio_1.Formio.Evaluator = Evaluator_1.Evaluator;
48
+ Formio_1.Formio.Evaluator = utils_2.Evaluator;
49
49
  Formio_1.Formio.AllComponents = components_1.default;
50
50
  Formio_1.Formio.Licenses = licenses_1.default;
51
51
  // This is strange, but is needed for "premium" components to import correctly.
@@ -100,7 +100,7 @@ function registerModule(mod, defaultFn = null, options = {}) {
100
100
  Formio_1.Formio.Displays.addDisplays(mod.displays);
101
101
  break;
102
102
  case 'evaluator':
103
- Formio_1.Formio.Evaluator.registerEvaluator(mod.evaluator);
103
+ (0, utils_2.registerEvaluator)(mod.evaluator);
104
104
  break;
105
105
  case 'translations':
106
106
  i18n_1.I18n.setDefaultTranslations(mod.translations);
package/lib/cjs/i18n.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const en_1 = __importDefault(require("./translations/en"));
7
- const utils_1 = require("./utils/utils");
7
+ const utils_1 = require("./utils");
8
8
  exports.default = {
9
9
  lng: 'en',
10
10
  nsSeparator: '::',
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFormioUploadAdapterPlugin = void 0;
4
- const utils_1 = require("../../utils/utils");
4
+ const utils_1 = require("../../utils");
5
5
  /**
6
6
  * UploadAdapter for CKEditor https://ckeditor.com/docs/ckeditor5/latest/framework/guides/deep-dive/upload-adapter.html
7
7
  */
@@ -1,7 +1,21 @@
1
- export class Evaluator {
2
- static cache: {};
3
- static protectedEval: boolean;
4
- static noeval: boolean;
5
- static template(template: any, hash: any): any;
6
- static interpolate(rawTemplate: any, data: any, _options: any): any;
1
+ /**
2
+ * For backwards compatibility we a standalone interpolate function. This merely calls the
3
+ * global mutable Evaluator instance's interpolate function.
4
+ * @param {...any} args - interpolate arguments, typically "rawTemplate", "data", and "options"
5
+ * @returns {any} the interpolation result.
6
+ */
7
+ export function interpolate(...args: any[]): any;
8
+ /**
9
+ * Set the evaluator to use for evaluating expressions.
10
+ * @param {CoreEvaluator} override - The new evaluator instance to use.
11
+ * @returns {void}
12
+ */
13
+ export function registerEvaluator(override: CoreEvaluator): void;
14
+ export class DefaultEvaluator extends CoreEvaluator {
15
+ cache: {};
16
+ protectedEval: boolean;
17
+ template(template: any, hash: any): any;
18
+ interpolate(rawTemplate: any, data: any, _options: any): any;
7
19
  }
20
+ export let Evaluator: DefaultEvaluator;
21
+ import { DefaultEvaluator as CoreEvaluator } from '@formio/core';
@@ -3,26 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Evaluator = void 0;
6
+ exports.registerEvaluator = exports.interpolate = exports.Evaluator = exports.DefaultEvaluator = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const string_hash_1 = __importDefault(require("string-hash"));
9
- const utils_1 = require("@formio/core/utils");
10
- class Evaluator extends utils_1.JSONLogicEvaluator {
11
- static template(template, hash) {
9
+ const core_1 = require("@formio/core");
10
+ class DefaultEvaluator extends core_1.DefaultEvaluator {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.cache = {};
14
+ this.protectedEval = false;
15
+ }
16
+ template(template, hash) {
12
17
  hash = hash || (0, string_hash_1.default)(template);
13
- if (Evaluator.cache[hash]) {
14
- return Evaluator.cache[hash];
18
+ if (this.cache[hash]) {
19
+ return this.cache[hash];
15
20
  }
16
21
  try {
17
22
  // Ensure we handle copied templates from the ejs files.
18
23
  template = template.replace(/ctx\./g, '');
19
- return (Evaluator.cache[hash] = lodash_1.default.template(template, Evaluator.templateSettings));
24
+ return (this.cache[hash] = lodash_1.default.template(template, this.templateSettings));
20
25
  }
21
26
  catch (err) {
22
27
  console.warn('Error while processing template', err, template);
23
28
  }
24
29
  }
25
- static interpolate(rawTemplate, data, _options) {
30
+ interpolate(rawTemplate, data, _options) {
26
31
  // Ensure reverse compatability.
27
32
  const options = lodash_1.default.isObject(_options) ? _options : { noeval: _options };
28
33
  if (typeof rawTemplate === 'function') {
@@ -36,11 +41,11 @@ class Evaluator extends utils_1.JSONLogicEvaluator {
36
41
  }
37
42
  rawTemplate = String(rawTemplate);
38
43
  let template;
39
- if (Evaluator.noeval || options.noeval) {
40
- return utils_1.JSONLogicEvaluator.interpolateString(rawTemplate, data, _options);
44
+ if (this.noeval || options.noeval) {
45
+ return this.interpolateString(rawTemplate, data, _options);
41
46
  }
42
47
  else {
43
- template = Evaluator.template(rawTemplate);
48
+ template = this.template(rawTemplate);
44
49
  }
45
50
  if (typeof template === 'function') {
46
51
  try {
@@ -54,7 +59,25 @@ class Evaluator extends utils_1.JSONLogicEvaluator {
54
59
  return template;
55
60
  }
56
61
  }
57
- exports.Evaluator = Evaluator;
58
- Evaluator.cache = {};
59
- Evaluator.protectedEval = false;
60
- Evaluator.noeval = false;
62
+ exports.DefaultEvaluator = DefaultEvaluator;
63
+ exports.Evaluator = new DefaultEvaluator();
64
+ // preserve the standalone interpolate function for backwards compatibility
65
+ /**
66
+ * For backwards compatibility we a standalone interpolate function. This merely calls the
67
+ * global mutable Evaluator instance's interpolate function.
68
+ * @param {...any} args - interpolate arguments, typically "rawTemplate", "data", and "options"
69
+ * @returns {any} the interpolation result.
70
+ */
71
+ function interpolate(...args) {
72
+ return exports.Evaluator.interpolate(...args);
73
+ }
74
+ exports.interpolate = interpolate;
75
+ /**
76
+ * Set the evaluator to use for evaluating expressions.
77
+ * @param {CoreEvaluator} override - The new evaluator instance to use.
78
+ * @returns {void}
79
+ */
80
+ function registerEvaluator(override) {
81
+ exports.Evaluator = override;
82
+ }
83
+ exports.registerEvaluator = registerEvaluator;