@formio/js 5.0.0-dev.5772.7636454 → 5.0.0-dev.5777.4ccabb1

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.
@@ -403,6 +403,7 @@ class PDFBuilder extends WebformBuilder_1.default {
403
403
  return false;
404
404
  }
405
405
  onDragEnd(e) {
406
+ var _a;
406
407
  // IMPORTANT - must retrieve offsets BEFORE disabling the dropzone - offsets will
407
408
  // reflect absolute positioning if accessed after the target element is hidden
408
409
  const iframeRect = this.webform.refs.iframeContainer.getBoundingClientRect();
@@ -435,7 +436,7 @@ class PDFBuilder extends WebformBuilder_1.default {
435
436
  lodash_1.default.merge(schema, info);
436
437
  }
437
438
  // Set a unique key for this component.
438
- builder_1.default.uniquify([this.webform._form], schema);
439
+ builder_1.default.uniquify(((_a = this.webform._form) === null || _a === void 0 ? void 0 : _a.components) || [], schema);
439
440
  this.webform._form.components.push(schema);
440
441
  schema.overlay = {
441
442
  top: layerY ? (layerY - this.itemOffsetY + HEIGHT) : (e.clientY - iframeRect.top - (this.itemOffsetY - HEIGHT) * 2),
@@ -1,6 +1,5 @@
1
1
  export default class Multivalue extends Field {
2
2
  get addAnother(): string;
3
- useWrapper(): any;
4
3
  /**
5
4
  * @returns {Field} - The created field.
6
5
  */
@@ -6,12 +6,40 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Field_1 = __importDefault(require("../field/Field"));
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  class Multivalue extends Field_1.default {
9
- get dataValue() {
10
- const parent = super.dataValue;
11
- if (!parent && this.component.multiple) {
12
- return [];
9
+ /**
10
+ * Normalize values coming into updateValue.
11
+ * @param {*} value - The value to normalize before setting.
12
+ * @returns {*} - The normalized value.
13
+ */
14
+ normalizeValue(value) {
15
+ if (this.component.multiple) {
16
+ if (Array.isArray(value)) {
17
+ if (value.length === 0) {
18
+ return [this.emptyValue];
19
+ }
20
+ if (this.component.storeas === 'array') {
21
+ return super.normalizeValue([value]);
22
+ }
23
+ return super.normalizeValue(value);
24
+ }
25
+ else {
26
+ return super.normalizeValue(value == null ? [this.emptyValue] : [value]);
27
+ }
28
+ }
29
+ else {
30
+ if (Array.isArray(value) && this.component.storeas !== 'array') {
31
+ if (this.component.storeas === 'string') {
32
+ return super.normalizeValue(value.join(this.delimiter || ''));
33
+ }
34
+ return super.normalizeValue(value[0] || this.emptyValue);
35
+ }
36
+ else {
37
+ return super.normalizeValue(value);
38
+ }
13
39
  }
14
- return parent;
40
+ }
41
+ get dataValue() {
42
+ return super.dataValue;
15
43
  }
16
44
  set dataValue(value) {
17
45
  super.dataValue = value;
@@ -31,30 +59,20 @@ class Multivalue extends Field_1.default {
31
59
  get addAnother() {
32
60
  return this.t(this.component.addAnother || 'Add Another');
33
61
  }
34
- useWrapper() {
35
- return this.component.hasOwnProperty('multiple') && this.component.multiple;
36
- }
37
62
  /**
38
63
  * @returns {Field} - The created field.
39
64
  */
40
65
  render() {
41
- // If single value field.
42
- if (!this.useWrapper()) {
43
- return super.render(`<div ${this._referenceAttributeName}="element">
44
- ${this.renderElement(this.component.type !== 'hidden' ? this.dataValue : '')}
45
- </div>`);
46
- }
47
- // Make sure dataValue is in the correct array format.
48
- let dataValue = this.dataValue;
49
- if (!Array.isArray(dataValue)) {
50
- dataValue = dataValue ? [dataValue] : [];
51
- }
52
- // If multiple value field.
53
- return super.render(this.renderTemplate('multiValueTable', {
54
- rows: dataValue.map(this.renderRow.bind(this)).join(''),
55
- disabled: this.disabled,
56
- addAnother: this.addAnother,
57
- }));
66
+ let dataValue = this.normalizeValue(this.dataValue);
67
+ return this.component.hasOwnProperty('multiple') && this.component.multiple
68
+ ? super.render(this.renderTemplate('multiValueTable', {
69
+ rows: dataValue.map(this.renderRow.bind(this)).join(''),
70
+ disabled: this.disabled,
71
+ addAnother: this.addAnother,
72
+ }))
73
+ : super.render(`<div ${this._referenceAttributeName}="element">
74
+ ${this.renderElement(this.component.type !== 'hidden' ? dataValue : '')}
75
+ </div>`);
58
76
  }
59
77
  renderElement() {
60
78
  return '';
@@ -436,7 +436,7 @@ class DataGridComponent extends NestedArrayComponent_1.default {
436
436
  }
437
437
  removeRow(index) {
438
438
  const makeEmpty = index === 0 && this.rows.length === 1;
439
- const flags = { isReordered: !makeEmpty, resetValue: makeEmpty };
439
+ const flags = { isReordered: !makeEmpty, resetValue: makeEmpty, modified: true };
440
440
  this.splice(index, flags);
441
441
  this.emit('dataGridDeleteRow', { index });
442
442
  const [row] = this.rows.splice(index, 1);
@@ -118,12 +118,12 @@ class TagsComponent extends Input_1.default {
118
118
  }
119
119
  normalizeValue(value) {
120
120
  if (this.component.storeas === 'string' && Array.isArray(value)) {
121
- return value.join(this.delimiter);
121
+ return super.normalizeValue(value.join(this.delimiter));
122
122
  }
123
123
  else if (this.component.storeas === 'array' && typeof value === 'string') {
124
- return value.split(this.delimiter).filter(result => result);
124
+ return super.normalizeValue(value.split(this.delimiter).filter(result => result));
125
125
  }
126
- return value;
126
+ return super.normalizeValue(value);
127
127
  }
128
128
  setValue(value, flags = {}) {
129
129
  const changed = super.setValue(value, flags);
@@ -429,7 +429,7 @@ export default class PDFBuilder extends WebformBuilder {
429
429
  _.merge(schema, info);
430
430
  }
431
431
  // Set a unique key for this component.
432
- BuilderUtils.uniquify([this.webform._form], schema);
432
+ BuilderUtils.uniquify(this.webform._form?.components || [], schema);
433
433
  this.webform._form.components.push(schema);
434
434
  schema.overlay = {
435
435
  top: layerY ? (layerY - this.itemOffsetY + HEIGHT) : (e.clientY - iframeRect.top - (this.itemOffsetY - HEIGHT) * 2),
@@ -1,6 +1,5 @@
1
1
  export default class Multivalue extends Field {
2
2
  get addAnother(): string;
3
- useWrapper(): any;
4
3
  /**
5
4
  * @returns {Field} - The created field.
6
5
  */
@@ -1,12 +1,40 @@
1
1
  import Field from '../field/Field';
2
2
  import _ from 'lodash';
3
3
  export default class Multivalue extends Field {
4
- get dataValue() {
5
- const parent = super.dataValue;
6
- if (!parent && this.component.multiple) {
7
- return [];
4
+ /**
5
+ * Normalize values coming into updateValue.
6
+ * @param {*} value - The value to normalize before setting.
7
+ * @returns {*} - The normalized value.
8
+ */
9
+ normalizeValue(value) {
10
+ if (this.component.multiple) {
11
+ if (Array.isArray(value)) {
12
+ if (value.length === 0) {
13
+ return [this.emptyValue];
14
+ }
15
+ if (this.component.storeas === 'array') {
16
+ return super.normalizeValue([value]);
17
+ }
18
+ return super.normalizeValue(value);
19
+ }
20
+ else {
21
+ return super.normalizeValue(value == null ? [this.emptyValue] : [value]);
22
+ }
23
+ }
24
+ else {
25
+ if (Array.isArray(value) && this.component.storeas !== 'array') {
26
+ if (this.component.storeas === 'string') {
27
+ return super.normalizeValue(value.join(this.delimiter || ''));
28
+ }
29
+ return super.normalizeValue(value[0] || this.emptyValue);
30
+ }
31
+ else {
32
+ return super.normalizeValue(value);
33
+ }
8
34
  }
9
- return parent;
35
+ }
36
+ get dataValue() {
37
+ return super.dataValue;
10
38
  }
11
39
  set dataValue(value) {
12
40
  super.dataValue = value;
@@ -26,30 +54,20 @@ export default class Multivalue extends Field {
26
54
  get addAnother() {
27
55
  return this.t(this.component.addAnother || 'Add Another');
28
56
  }
29
- useWrapper() {
30
- return this.component.hasOwnProperty('multiple') && this.component.multiple;
31
- }
32
57
  /**
33
58
  * @returns {Field} - The created field.
34
59
  */
35
60
  render() {
36
- // If single value field.
37
- if (!this.useWrapper()) {
38
- return super.render(`<div ${this._referenceAttributeName}="element">
39
- ${this.renderElement(this.component.type !== 'hidden' ? this.dataValue : '')}
40
- </div>`);
41
- }
42
- // Make sure dataValue is in the correct array format.
43
- let dataValue = this.dataValue;
44
- if (!Array.isArray(dataValue)) {
45
- dataValue = dataValue ? [dataValue] : [];
46
- }
47
- // If multiple value field.
48
- return super.render(this.renderTemplate('multiValueTable', {
49
- rows: dataValue.map(this.renderRow.bind(this)).join(''),
50
- disabled: this.disabled,
51
- addAnother: this.addAnother,
52
- }));
61
+ let dataValue = this.normalizeValue(this.dataValue);
62
+ return this.component.hasOwnProperty('multiple') && this.component.multiple
63
+ ? super.render(this.renderTemplate('multiValueTable', {
64
+ rows: dataValue.map(this.renderRow.bind(this)).join(''),
65
+ disabled: this.disabled,
66
+ addAnother: this.addAnother,
67
+ }))
68
+ : super.render(`<div ${this._referenceAttributeName}="element">
69
+ ${this.renderElement(this.component.type !== 'hidden' ? dataValue : '')}
70
+ </div>`);
53
71
  }
54
72
  renderElement() {
55
73
  return '';
@@ -432,7 +432,7 @@ export default class DataGridComponent extends NestedArrayComponent {
432
432
  }
433
433
  removeRow(index) {
434
434
  const makeEmpty = index === 0 && this.rows.length === 1;
435
- const flags = { isReordered: !makeEmpty, resetValue: makeEmpty };
435
+ const flags = { isReordered: !makeEmpty, resetValue: makeEmpty, modified: true };
436
436
  this.splice(index, flags);
437
437
  this.emit('dataGridDeleteRow', { index });
438
438
  const [row] = this.rows.splice(index, 1);
@@ -116,12 +116,12 @@ export default class TagsComponent extends Input {
116
116
  }
117
117
  normalizeValue(value) {
118
118
  if (this.component.storeas === 'string' && Array.isArray(value)) {
119
- return value.join(this.delimiter);
119
+ return super.normalizeValue(value.join(this.delimiter));
120
120
  }
121
121
  else if (this.component.storeas === 'array' && typeof value === 'string') {
122
- return value.split(this.delimiter).filter(result => result);
122
+ return super.normalizeValue(value.split(this.delimiter).filter(result => result));
123
123
  }
124
- return value;
124
+ return super.normalizeValue(value);
125
125
  }
126
126
  setValue(value, flags = {}) {
127
127
  const changed = super.setValue(value, flags);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5772.7636454",
3
+ "version": "5.0.0-dev.5777.4ccabb1",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {