@bpmn-io/form-js-viewer 0.6.0 → 0.7.2

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 (40) hide show
  1. package/dist/index.cjs +126 -117
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.es.js +126 -117
  4. package/dist/index.es.js.map +1 -1
  5. package/dist/types/Form.d.ts +136 -130
  6. package/dist/types/core/EventBus.d.ts +1 -1
  7. package/dist/types/core/FormFieldRegistry.d.ts +17 -17
  8. package/dist/types/core/Validator.d.ts +7 -3
  9. package/dist/types/core/index.d.ts +16 -16
  10. package/dist/types/import/Importer.d.ts +43 -43
  11. package/dist/types/import/index.d.ts +5 -5
  12. package/dist/types/index.d.ts +18 -18
  13. package/dist/types/render/FormFields.d.ts +5 -5
  14. package/dist/types/render/Renderer.d.ts +23 -23
  15. package/dist/types/render/components/Description.d.ts +1 -1
  16. package/dist/types/render/components/Errors.d.ts +1 -1
  17. package/dist/types/render/components/FormComponent.d.ts +1 -1
  18. package/dist/types/render/components/FormField.d.ts +1 -1
  19. package/dist/types/render/components/Label.d.ts +1 -1
  20. package/dist/types/render/components/PoweredBy.d.ts +1 -1
  21. package/dist/types/render/components/Sanitizer.d.ts +7 -7
  22. package/dist/types/render/components/Util.d.ts +4 -4
  23. package/dist/types/render/components/form-fields/Button.d.ts +11 -11
  24. package/dist/types/render/components/form-fields/Checkbox.d.ts +10 -10
  25. package/dist/types/render/components/form-fields/Default.d.ts +9 -9
  26. package/dist/types/render/components/form-fields/Number.d.ts +10 -10
  27. package/dist/types/render/components/form-fields/Radio.d.ts +15 -15
  28. package/dist/types/render/components/form-fields/Select.d.ts +15 -15
  29. package/dist/types/render/components/form-fields/Text.d.ts +10 -10
  30. package/dist/types/render/components/form-fields/Textfield.d.ts +10 -10
  31. package/dist/types/render/components/index.d.ts +11 -11
  32. package/dist/types/render/context/FormContext.d.ts +12 -12
  33. package/dist/types/render/context/FormRenderContext.d.ts +6 -6
  34. package/dist/types/render/context/index.d.ts +2 -2
  35. package/dist/types/render/hooks/useService.d.ts +1 -1
  36. package/dist/types/render/index.d.ts +11 -11
  37. package/dist/types/util/form.d.ts +6 -6
  38. package/dist/types/util/index.d.ts +16 -16
  39. package/dist/types/util/injector.d.ts +1 -1
  40. package/package.json +2 -2
package/dist/index.cjs CHANGED
@@ -18,109 +18,6 @@ var Ids__default = /*#__PURE__*/_interopDefaultLegacy(Ids);
18
18
  var snarkdown__default = /*#__PURE__*/_interopDefaultLegacy(snarkdown);
19
19
  var Markup__default = /*#__PURE__*/_interopDefaultLegacy(Markup);
20
20
 
21
- function createInjector(bootstrapModules) {
22
- const modules = [],
23
- components = [];
24
-
25
- function hasModule(module) {
26
- return modules.includes(module);
27
- }
28
-
29
- function addModule(module) {
30
- modules.push(module);
31
- }
32
-
33
- function visit(module) {
34
- if (hasModule(module)) {
35
- return;
36
- }
37
-
38
- (module.__depends__ || []).forEach(visit);
39
-
40
- if (hasModule(module)) {
41
- return;
42
- }
43
-
44
- addModule(module);
45
- (module.__init__ || []).forEach(function (component) {
46
- components.push(component);
47
- });
48
- }
49
-
50
- bootstrapModules.forEach(visit);
51
- const injector = new didi.Injector(modules);
52
- components.forEach(function (component) {
53
- try {
54
- injector[typeof component === 'string' ? 'get' : 'invoke'](component);
55
- } catch (err) {
56
- console.error('Failed to instantiate component');
57
- console.error(err.stack);
58
- throw err;
59
- }
60
- });
61
- return injector;
62
- }
63
-
64
- /**
65
- * @param {string?} prefix
66
- *
67
- * @returns Element
68
- */
69
- function createFormContainer(prefix = 'fjs') {
70
- const container = document.createElement('div');
71
- container.classList.add(`${prefix}-container`);
72
- return container;
73
- }
74
-
75
- function findErrors(errors, path) {
76
- return errors[pathStringify(path)];
77
- }
78
- function isRequired(field) {
79
- return field.required;
80
- }
81
- function pathParse(path) {
82
- if (!path) {
83
- return [];
84
- }
85
-
86
- return path.split('.').map(key => {
87
- return isNaN(parseInt(key)) ? key : parseInt(key);
88
- });
89
- }
90
- function pathsEqual(a, b) {
91
- return a && b && a.length === b.length && a.every((value, index) => value === b[index]);
92
- }
93
- function pathStringify(path) {
94
- if (!path) {
95
- return '';
96
- }
97
-
98
- return path.join('.');
99
- }
100
- const indices = {};
101
- function generateIndexForType(type) {
102
- if (type in indices) {
103
- indices[type]++;
104
- } else {
105
- indices[type] = 1;
106
- }
107
-
108
- return indices[type];
109
- }
110
- function generateIdForType(type) {
111
- return `${type}${generateIndexForType(type)}`;
112
- }
113
- /**
114
- * @template T
115
- * @param {T} data
116
- * @param {(this: any, key: string, value: any) => any} [replacer]
117
- * @return {T}
118
- */
119
-
120
- function clone(data, replacer) {
121
- return JSON.parse(JSON.stringify(data, replacer));
122
- }
123
-
124
21
  var FN_REF = '__fn';
125
22
  var DEFAULT_PRIORITY = 1000;
126
23
  var slice = Array.prototype.slice;
@@ -634,6 +531,7 @@ class Validator {
634
531
  }
635
532
 
636
533
  }
534
+ Validator.$inject = [];
637
535
 
638
536
  class FormFieldRegistry {
639
537
  constructor(eventBus) {
@@ -699,6 +597,109 @@ class FormFieldRegistry {
699
597
  }
700
598
  FormFieldRegistry.$inject = ['eventBus'];
701
599
 
600
+ function createInjector(bootstrapModules) {
601
+ const modules = [],
602
+ components = [];
603
+
604
+ function hasModule(module) {
605
+ return modules.includes(module);
606
+ }
607
+
608
+ function addModule(module) {
609
+ modules.push(module);
610
+ }
611
+
612
+ function visit(module) {
613
+ if (hasModule(module)) {
614
+ return;
615
+ }
616
+
617
+ (module.__depends__ || []).forEach(visit);
618
+
619
+ if (hasModule(module)) {
620
+ return;
621
+ }
622
+
623
+ addModule(module);
624
+ (module.__init__ || []).forEach(function (component) {
625
+ components.push(component);
626
+ });
627
+ }
628
+
629
+ bootstrapModules.forEach(visit);
630
+ const injector = new didi.Injector(modules);
631
+ components.forEach(function (component) {
632
+ try {
633
+ injector[typeof component === 'string' ? 'get' : 'invoke'](component);
634
+ } catch (err) {
635
+ console.error('Failed to instantiate component');
636
+ console.error(err.stack);
637
+ throw err;
638
+ }
639
+ });
640
+ return injector;
641
+ }
642
+
643
+ /**
644
+ * @param {string?} prefix
645
+ *
646
+ * @returns Element
647
+ */
648
+ function createFormContainer(prefix = 'fjs') {
649
+ const container = document.createElement('div');
650
+ container.classList.add(`${prefix}-container`);
651
+ return container;
652
+ }
653
+
654
+ function findErrors(errors, path) {
655
+ return errors[pathStringify(path)];
656
+ }
657
+ function isRequired(field) {
658
+ return field.required;
659
+ }
660
+ function pathParse(path) {
661
+ if (!path) {
662
+ return [];
663
+ }
664
+
665
+ return path.split('.').map(key => {
666
+ return isNaN(parseInt(key)) ? key : parseInt(key);
667
+ });
668
+ }
669
+ function pathsEqual(a, b) {
670
+ return a && b && a.length === b.length && a.every((value, index) => value === b[index]);
671
+ }
672
+ function pathStringify(path) {
673
+ if (!path) {
674
+ return '';
675
+ }
676
+
677
+ return path.join('.');
678
+ }
679
+ const indices = {};
680
+ function generateIndexForType(type) {
681
+ if (type in indices) {
682
+ indices[type]++;
683
+ } else {
684
+ indices[type] = 1;
685
+ }
686
+
687
+ return indices[type];
688
+ }
689
+ function generateIdForType(type) {
690
+ return `${type}${generateIndexForType(type)}`;
691
+ }
692
+ /**
693
+ * @template T
694
+ * @param {T} data
695
+ * @param {(this: any, key: string, value: any) => any} [replacer]
696
+ * @return {T}
697
+ */
698
+
699
+ function clone(data, replacer) {
700
+ return JSON.parse(JSON.stringify(data, replacer));
701
+ }
702
+
702
703
  class Importer {
703
704
  /**
704
705
  * @constructor
@@ -1480,7 +1481,7 @@ function Radio(props) {
1480
1481
  type: "radio",
1481
1482
  onClick: () => onChange(v.value)
1482
1483
  })
1483
- }, v.value);
1484
+ }, `${id}-${index}`);
1484
1485
  }), jsxRuntime.jsx(Description, {
1485
1486
  description: description
1486
1487
  }), jsxRuntime.jsx(Errors, {
@@ -1549,11 +1550,11 @@ function Select(props) {
1549
1550
  value: value || '',
1550
1551
  children: [jsxRuntime.jsx("option", {
1551
1552
  value: ""
1552
- }), values.map(v => {
1553
+ }), values.map((v, index) => {
1553
1554
  return jsxRuntime.jsx("option", {
1554
1555
  value: v.value,
1555
1556
  children: v.label
1556
- }, v.value);
1557
+ }, `${id}-${index}`);
1557
1558
  })]
1558
1559
  }), jsxRuntime.jsx(Description, {
1559
1560
  description: description
@@ -1775,6 +1776,10 @@ var core = {
1775
1776
  * properties: FormProperties,
1776
1777
  * schema: Schema
1777
1778
  * } } State
1779
+ *
1780
+ * @typedef { (type:FormEvent, priority:number, handler:Function) => void } OnEventWithPriority
1781
+ * @typedef { (type:FormEvent, handler:Function) => void } OnEventWithOutPriority
1782
+ * @typedef { OnEventWithPriority & OnEventWithOutPriority } OnEventType
1778
1783
  */
1779
1784
 
1780
1785
  const ids = new Ids__default['default']([32, 36, 1]);
@@ -1788,10 +1793,16 @@ class Form {
1788
1793
  * @param {FormOptions} options
1789
1794
  */
1790
1795
  constructor(options = {}) {
1796
+ /**
1797
+ * @public
1798
+ * @type {OnEventType}
1799
+ */
1800
+ this.on = this._onEvent;
1791
1801
  /**
1792
1802
  * @public
1793
1803
  * @type {String}
1794
1804
  */
1805
+
1795
1806
  this._id = ids.next();
1796
1807
  /**
1797
1808
  * @private
@@ -2038,16 +2049,6 @@ class Form {
2038
2049
  properties
2039
2050
  });
2040
2051
  }
2041
- /**
2042
- * @param {FormEvent} type
2043
- * @param {number} priority
2044
- * @param {Function} handler
2045
- */
2046
-
2047
-
2048
- on(type, priority, handler) {
2049
- this.get('eventBus').on(type, priority, handler);
2050
- }
2051
2052
  /**
2052
2053
  * @param {FormEvent} type
2053
2054
  * @param {Function} handler
@@ -2142,10 +2143,18 @@ class Form {
2142
2143
 
2143
2144
  this._emit('changed', this._getState());
2144
2145
  }
2146
+ /**
2147
+ * @internal
2148
+ */
2149
+
2150
+
2151
+ _onEvent(type, priority, handler) {
2152
+ this.get('eventBus').on(type, priority, handler);
2153
+ }
2145
2154
 
2146
2155
  }
2147
2156
 
2148
- const schemaVersion = 3;
2157
+ const schemaVersion = 4;
2149
2158
  /**
2150
2159
  * @typedef { import('./types').CreateFormOptions } CreateFormOptions
2151
2160
  */