@formio/js 5.0.0-dev.5708.6c19568 → 5.0.0-dev.5710.e2e8388

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 (44) hide show
  1. package/Changelog.md +1 -0
  2. package/dist/formio.embed.js +1 -1
  3. package/dist/formio.embed.min.js +1 -1
  4. package/dist/formio.form.js +6 -102
  5. package/dist/formio.form.min.js +1 -1
  6. package/dist/formio.full.js +7 -7
  7. package/dist/formio.full.min.js +1 -1
  8. package/dist/formio.js +1 -1
  9. package/dist/formio.min.js +1 -1
  10. package/lib/cjs/CDN.d.ts +1 -0
  11. package/lib/cjs/CDN.js +1 -0
  12. package/lib/cjs/Webform.js +0 -2
  13. package/lib/cjs/WebformBuilder.d.ts +5 -0
  14. package/lib/cjs/WebformBuilder.js +22 -15
  15. package/lib/cjs/components/_classes/component/Component.d.ts +1 -0
  16. package/lib/cjs/components/_classes/component/Component.js +18 -0
  17. package/lib/cjs/components/currency/Currency.d.ts +1 -0
  18. package/lib/cjs/components/datagrid/DataGrid.d.ts +2 -0
  19. package/lib/cjs/components/datagrid/DataGrid.js +38 -26
  20. package/lib/cjs/components/datamap/DataMap.js +2 -2
  21. package/lib/cjs/components/number/Number.d.ts +10 -1
  22. package/lib/cjs/components/number/Number.js +15 -6
  23. package/lib/cjs/components/number/fixtures/comp9.d.ts +18 -0
  24. package/lib/cjs/components/number/fixtures/comp9.js +21 -0
  25. package/lib/cjs/components/number/fixtures/index.d.ts +2 -1
  26. package/lib/cjs/components/number/fixtures/index.js +3 -1
  27. package/lib/mjs/CDN.d.ts +1 -0
  28. package/lib/mjs/CDN.js +1 -0
  29. package/lib/mjs/Webform.js +0 -2
  30. package/lib/mjs/WebformBuilder.d.ts +5 -0
  31. package/lib/mjs/WebformBuilder.js +22 -15
  32. package/lib/mjs/components/_classes/component/Component.d.ts +1 -0
  33. package/lib/mjs/components/_classes/component/Component.js +7 -0
  34. package/lib/mjs/components/currency/Currency.d.ts +1 -0
  35. package/lib/mjs/components/datagrid/DataGrid.d.ts +2 -0
  36. package/lib/mjs/components/datagrid/DataGrid.js +37 -25
  37. package/lib/mjs/components/datamap/DataMap.js +1 -1
  38. package/lib/mjs/components/number/Number.d.ts +10 -1
  39. package/lib/mjs/components/number/Number.js +14 -5
  40. package/lib/mjs/components/number/fixtures/comp9.d.ts +18 -0
  41. package/lib/mjs/components/number/fixtures/comp9.js +19 -0
  42. package/lib/mjs/components/number/fixtures/index.d.ts +2 -1
  43. package/lib/mjs/components/number/fixtures/index.js +2 -1
  44. package/package.json +1 -1
@@ -1,8 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import NestedArrayComponent from '../_classes/nestedarray/NestedArrayComponent';
3
3
  import { fastCloneDeep, getFocusableElements } from '../../utils/utils';
4
- import { Components } from '../Components';
5
- import dragula from 'dragula';
4
+ import Components from '../Components';
6
5
  export default class DataGridComponent extends NestedArrayComponent {
7
6
  static schema(...extend) {
8
7
  return NestedArrayComponent.schema({
@@ -39,6 +38,9 @@ export default class DataGridComponent extends NestedArrayComponent {
39
38
  if (this.initRows || !_.isEqual(this.dataValue, this.emptyValue)) {
40
39
  this.createRows(true);
41
40
  }
41
+ if (this.allowReorder) {
42
+ this.dragulaReady = this.getDragula();
43
+ }
42
44
  this.visibleColumns = {};
43
45
  this.prevHasAddButton = this.hasAddButton();
44
46
  this.checkColumns();
@@ -279,31 +281,25 @@ export default class DataGridComponent extends NestedArrayComponent {
279
281
  this.refs[`${this.datagridKey}-row`].forEach((row, index) => {
280
282
  row.dragInfo = { index };
281
283
  });
282
- this.dragula = dragula([this.refs[`${this.datagridKey}-tbody`]], {
283
- moves: (_draggedElement, _oldParent, clickedElement) => {
284
- const clickedElementKey = clickedElement.getAttribute('data-key');
285
- const oldParentKey = _oldParent.getAttribute('data-key');
286
- //Check if the clicked button belongs to that container, if false, it belongs to the nested container
287
- if (oldParentKey === clickedElementKey) {
288
- return clickedElement.classList.contains('formio-drag-button');
289
- }
284
+ this.dragulaReady.then((dragula) => {
285
+ // The drop event may call redraw twice which calls attach twice and because this block of code is asynchronous
286
+ // BOTH redraws may be called before this block of code runs (which causes this block of code to run twice sequentially).
287
+ // This causes two dragula() calls on the same container which breaks dragula. To fix this the return value must
288
+ // be saved in this.dragula and have its container contents reset if it exists
289
+ if (this.dragula && this.dragula.containers) {
290
+ this.dragula.containers = [];
290
291
  }
291
- }).on('drop', this.onReorder.bind(this));
292
- this.dragula.on('cloned', (el, original) => {
293
- if (el && el.children && original && original.children) {
294
- _.each(original.children, (child, index) => {
295
- const styles = getComputedStyle(child, null);
296
- if (styles.cssText !== '') {
297
- el.children[index].style.cssText = styles.cssText;
292
+ this.dragula = dragula([this.refs[`${this.datagridKey}-tbody`]], {
293
+ moves: (_draggedElement, _oldParent, clickedElement) => {
294
+ const clickedElementKey = clickedElement.getAttribute('data-key');
295
+ const oldParentKey = _oldParent.getAttribute('data-key');
296
+ //Check if the clicked button belongs to that container, if false, it belongs to the nested container
297
+ if (oldParentKey === clickedElementKey) {
298
+ return clickedElement.classList.contains('formio-drag-button');
298
299
  }
299
- else {
300
- const cssText = Object.values(styles).reduce((css, propertyName) => {
301
- return `${css}${propertyName}:${styles.getPropertyValue(propertyName)};`;
302
- }, '');
303
- el.children[index].style.cssText = cssText;
304
- }
305
- });
306
- }
300
+ }
301
+ }).on('drop', this.onReorder.bind(this))
302
+ .on('cloned', this.onCloned.bind(this));
307
303
  });
308
304
  }
309
305
  this.refs[`${this.datagridKey}-addRow`].forEach((addButton) => {
@@ -370,6 +366,22 @@ export default class DataGridComponent extends NestedArrayComponent {
370
366
  this.setValue(dataValue, { isReordered: true });
371
367
  this.rebuild();
372
368
  }
369
+ onCloned(el, original) {
370
+ if (el && el.children && original && original.children) {
371
+ _.each(original.children, (child, index) => {
372
+ const styles = getComputedStyle(child, null);
373
+ if (styles.cssText !== '') {
374
+ el.children[index].style.cssText = styles.cssText;
375
+ }
376
+ else {
377
+ const cssText = Object.values(styles).reduce((css, propertyName) => {
378
+ return `${css}${propertyName}:${styles.getPropertyValue(propertyName)};`;
379
+ }, '');
380
+ el.children[index].style.cssText = cssText;
381
+ }
382
+ });
383
+ }
384
+ }
373
385
  focusOnNewRowElement(row) {
374
386
  Object.keys(row).find((key) => {
375
387
  const element = row[key].element;
@@ -3,7 +3,7 @@ import DataGridComponent from '../datagrid/DataGrid';
3
3
  import _ from 'lodash';
4
4
  import EventEmitter from 'eventemitter3';
5
5
  import { componentValueTypes, getComponentSavedTypes, uniqueKey } from '../../utils/utils';
6
- import { Components } from '../Components';
6
+ import Components from '../Components';
7
7
  export default class DataMapComponent extends DataGridComponent {
8
8
  static schema(...extend) {
9
9
  return Component.schema({
@@ -31,7 +31,16 @@ export default class NumberComponent extends Input {
31
31
  setInputMask(input: any): void;
32
32
  getValueAt(index: any): number | null;
33
33
  setValueAt(index: any, value: any, flags?: {}): void;
34
- parseValue(input: any): number;
34
+ /**
35
+ * Converts a string to a floating point number, formats the number based on the parsed float function
36
+ * (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat) and then returns the
37
+ * formatted number back as a string
38
+ * Example Input: "123.456,22"
39
+ * Example Output: "123456,22"
40
+ * @param {string | number} input the numeric string to parse
41
+ * @returns {string | null} a parsed string
42
+ */
43
+ parseValue(input: string | number): string | null;
35
44
  focus(): void;
36
45
  getMaskedValue(value: any): any;
37
46
  getValueAsString(value: any, options: any): any;
@@ -50,12 +50,12 @@ export default class NumberComponent extends Input {
50
50
  || this.options.properties?.decimalSeparator
51
51
  || separators.decimalSeparator;
52
52
  if (this.component.delimiter) {
53
- if (this.options.hasOwnProperty('thousandsSeparator')) {
54
- console.warn("Property 'thousandsSeparator' is deprecated. Please use i18n to specify delimiter.");
55
- }
56
- this.delimiter = this.options.properties?.thousandsSeparator || this.options.thousandsSeparator || separators.delimiter;
53
+ this.delimiter = this.component.thousandsSeparator || this.options.properties?.thousandsSeparator || this.options.thousandsSeparator || separators.delimiter;
57
54
  }
58
55
  else {
56
+ if (this.component.thousandsSeparator || this.options.properties?.thousandsSeparator || this.options.thousandsSeparator) {
57
+ console.warn('In order for thousands separator to work properly, you must set the delimiter to true in the component json');
58
+ }
59
59
  this.delimiter = '';
60
60
  }
61
61
  const requireDecimal = _.get(this.component, 'requireDecimal', false);
@@ -77,7 +77,7 @@ export default class NumberComponent extends Input {
77
77
  prefix: '',
78
78
  suffix: '',
79
79
  requireDecimal: _.get(this.component, 'requireDecimal', false),
80
- thousandsSeparatorSymbol: _.get(this.component, 'thousandsSeparator', this.delimiter),
80
+ thousandsSeparatorSymbol: this.delimiter || '',
81
81
  decimalSymbol: _.get(this.component, 'decimalSymbol', this.decimalSeparator),
82
82
  decimalLimit: _.get(this.component, 'decimalLimit', this.decimalLimit),
83
83
  allowNegative: _.get(this.component, 'allowNegative', true),
@@ -144,6 +144,15 @@ export default class NumberComponent extends Input {
144
144
  setValueAt(index, value, flags = {}) {
145
145
  return super.setValueAt(index, this.formatValue(this.parseValue(value)), flags);
146
146
  }
147
+ /**
148
+ * Converts a string to a floating point number, formats the number based on the parsed float function
149
+ * (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat) and then returns the
150
+ * formatted number back as a string
151
+ * Example Input: "123.456,22"
152
+ * Example Output: "123456,22"
153
+ * @param {string | number} input the numeric string to parse
154
+ * @returns {string | null} a parsed string
155
+ */
147
156
  parseValue(input) {
148
157
  if (typeof input === 'string') {
149
158
  input = input.split(this.delimiter).join('').replace(this.decimalSeparator, '.');
@@ -0,0 +1,18 @@
1
+ declare namespace _default {
2
+ let components: {
3
+ label: string;
4
+ applyMaskOn: string;
5
+ mask: boolean;
6
+ tableView: boolean;
7
+ delimiter: boolean;
8
+ requireDecimal: boolean;
9
+ inputFormat: string;
10
+ truncateMultipleSpaces: boolean;
11
+ key: string;
12
+ type: string;
13
+ input: boolean;
14
+ decimalSymbol: string;
15
+ thousandsSeparator: string;
16
+ }[];
17
+ }
18
+ export default _default;
@@ -0,0 +1,19 @@
1
+ export default {
2
+ components: [
3
+ {
4
+ "label": "Number",
5
+ "applyMaskOn": "change",
6
+ "mask": false,
7
+ "tableView": false,
8
+ "delimiter": true,
9
+ "requireDecimal": false,
10
+ "inputFormat": "plain",
11
+ "truncateMultipleSpaces": false,
12
+ "key": "number",
13
+ "type": "number",
14
+ "input": true,
15
+ "decimalSymbol": ",",
16
+ "thousandsSeparator": "."
17
+ }
18
+ ]
19
+ };
@@ -6,4 +6,5 @@ import comp5 from './comp5';
6
6
  import comp6 from './comp6';
7
7
  import comp7 from './comp7';
8
8
  import comp8 from './comp8';
9
- export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8 };
9
+ import comp9 from './comp9';
10
+ export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, comp9 };
@@ -6,4 +6,5 @@ import comp5 from './comp5';
6
6
  import comp6 from './comp6';
7
7
  import comp7 from './comp7';
8
8
  import comp8 from './comp8';
9
- export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8 };
9
+ import comp9 from './comp9';
10
+ export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, comp9 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5708.6c19568",
3
+ "version": "5.0.0-dev.5710.e2e8388",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {