@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.es.js CHANGED
@@ -8,109 +8,6 @@ import Markup from 'preact-markup';
8
8
  import { createPortal } from 'preact/compat';
9
9
  import { Injector } from 'didi';
10
10
 
11
- function createInjector(bootstrapModules) {
12
- const modules = [],
13
- components = [];
14
-
15
- function hasModule(module) {
16
- return modules.includes(module);
17
- }
18
-
19
- function addModule(module) {
20
- modules.push(module);
21
- }
22
-
23
- function visit(module) {
24
- if (hasModule(module)) {
25
- return;
26
- }
27
-
28
- (module.__depends__ || []).forEach(visit);
29
-
30
- if (hasModule(module)) {
31
- return;
32
- }
33
-
34
- addModule(module);
35
- (module.__init__ || []).forEach(function (component) {
36
- components.push(component);
37
- });
38
- }
39
-
40
- bootstrapModules.forEach(visit);
41
- const injector = new Injector(modules);
42
- components.forEach(function (component) {
43
- try {
44
- injector[typeof component === 'string' ? 'get' : 'invoke'](component);
45
- } catch (err) {
46
- console.error('Failed to instantiate component');
47
- console.error(err.stack);
48
- throw err;
49
- }
50
- });
51
- return injector;
52
- }
53
-
54
- /**
55
- * @param {string?} prefix
56
- *
57
- * @returns Element
58
- */
59
- function createFormContainer(prefix = 'fjs') {
60
- const container = document.createElement('div');
61
- container.classList.add(`${prefix}-container`);
62
- return container;
63
- }
64
-
65
- function findErrors(errors, path) {
66
- return errors[pathStringify(path)];
67
- }
68
- function isRequired(field) {
69
- return field.required;
70
- }
71
- function pathParse(path) {
72
- if (!path) {
73
- return [];
74
- }
75
-
76
- return path.split('.').map(key => {
77
- return isNaN(parseInt(key)) ? key : parseInt(key);
78
- });
79
- }
80
- function pathsEqual(a, b) {
81
- return a && b && a.length === b.length && a.every((value, index) => value === b[index]);
82
- }
83
- function pathStringify(path) {
84
- if (!path) {
85
- return '';
86
- }
87
-
88
- return path.join('.');
89
- }
90
- const indices = {};
91
- function generateIndexForType(type) {
92
- if (type in indices) {
93
- indices[type]++;
94
- } else {
95
- indices[type] = 1;
96
- }
97
-
98
- return indices[type];
99
- }
100
- function generateIdForType(type) {
101
- return `${type}${generateIndexForType(type)}`;
102
- }
103
- /**
104
- * @template T
105
- * @param {T} data
106
- * @param {(this: any, key: string, value: any) => any} [replacer]
107
- * @return {T}
108
- */
109
-
110
- function clone(data, replacer) {
111
- return JSON.parse(JSON.stringify(data, replacer));
112
- }
113
-
114
11
  var FN_REF = '__fn';
115
12
  var DEFAULT_PRIORITY = 1000;
116
13
  var slice = Array.prototype.slice;
@@ -624,6 +521,7 @@ class Validator {
624
521
  }
625
522
 
626
523
  }
524
+ Validator.$inject = [];
627
525
 
628
526
  class FormFieldRegistry {
629
527
  constructor(eventBus) {
@@ -689,6 +587,109 @@ class FormFieldRegistry {
689
587
  }
690
588
  FormFieldRegistry.$inject = ['eventBus'];
691
589
 
590
+ function createInjector(bootstrapModules) {
591
+ const modules = [],
592
+ components = [];
593
+
594
+ function hasModule(module) {
595
+ return modules.includes(module);
596
+ }
597
+
598
+ function addModule(module) {
599
+ modules.push(module);
600
+ }
601
+
602
+ function visit(module) {
603
+ if (hasModule(module)) {
604
+ return;
605
+ }
606
+
607
+ (module.__depends__ || []).forEach(visit);
608
+
609
+ if (hasModule(module)) {
610
+ return;
611
+ }
612
+
613
+ addModule(module);
614
+ (module.__init__ || []).forEach(function (component) {
615
+ components.push(component);
616
+ });
617
+ }
618
+
619
+ bootstrapModules.forEach(visit);
620
+ const injector = new Injector(modules);
621
+ components.forEach(function (component) {
622
+ try {
623
+ injector[typeof component === 'string' ? 'get' : 'invoke'](component);
624
+ } catch (err) {
625
+ console.error('Failed to instantiate component');
626
+ console.error(err.stack);
627
+ throw err;
628
+ }
629
+ });
630
+ return injector;
631
+ }
632
+
633
+ /**
634
+ * @param {string?} prefix
635
+ *
636
+ * @returns Element
637
+ */
638
+ function createFormContainer(prefix = 'fjs') {
639
+ const container = document.createElement('div');
640
+ container.classList.add(`${prefix}-container`);
641
+ return container;
642
+ }
643
+
644
+ function findErrors(errors, path) {
645
+ return errors[pathStringify(path)];
646
+ }
647
+ function isRequired(field) {
648
+ return field.required;
649
+ }
650
+ function pathParse(path) {
651
+ if (!path) {
652
+ return [];
653
+ }
654
+
655
+ return path.split('.').map(key => {
656
+ return isNaN(parseInt(key)) ? key : parseInt(key);
657
+ });
658
+ }
659
+ function pathsEqual(a, b) {
660
+ return a && b && a.length === b.length && a.every((value, index) => value === b[index]);
661
+ }
662
+ function pathStringify(path) {
663
+ if (!path) {
664
+ return '';
665
+ }
666
+
667
+ return path.join('.');
668
+ }
669
+ const indices = {};
670
+ function generateIndexForType(type) {
671
+ if (type in indices) {
672
+ indices[type]++;
673
+ } else {
674
+ indices[type] = 1;
675
+ }
676
+
677
+ return indices[type];
678
+ }
679
+ function generateIdForType(type) {
680
+ return `${type}${generateIndexForType(type)}`;
681
+ }
682
+ /**
683
+ * @template T
684
+ * @param {T} data
685
+ * @param {(this: any, key: string, value: any) => any} [replacer]
686
+ * @return {T}
687
+ */
688
+
689
+ function clone(data, replacer) {
690
+ return JSON.parse(JSON.stringify(data, replacer));
691
+ }
692
+
692
693
  class Importer {
693
694
  /**
694
695
  * @constructor
@@ -1470,7 +1471,7 @@ function Radio(props) {
1470
1471
  type: "radio",
1471
1472
  onClick: () => onChange(v.value)
1472
1473
  })
1473
- }, v.value);
1474
+ }, `${id}-${index}`);
1474
1475
  }), jsx(Description, {
1475
1476
  description: description
1476
1477
  }), jsx(Errors, {
@@ -1539,11 +1540,11 @@ function Select(props) {
1539
1540
  value: value || '',
1540
1541
  children: [jsx("option", {
1541
1542
  value: ""
1542
- }), values.map(v => {
1543
+ }), values.map((v, index) => {
1543
1544
  return jsx("option", {
1544
1545
  value: v.value,
1545
1546
  children: v.label
1546
- }, v.value);
1547
+ }, `${id}-${index}`);
1547
1548
  })]
1548
1549
  }), jsx(Description, {
1549
1550
  description: description
@@ -1765,6 +1766,10 @@ var core = {
1765
1766
  * properties: FormProperties,
1766
1767
  * schema: Schema
1767
1768
  * } } State
1769
+ *
1770
+ * @typedef { (type:FormEvent, priority:number, handler:Function) => void } OnEventWithPriority
1771
+ * @typedef { (type:FormEvent, handler:Function) => void } OnEventWithOutPriority
1772
+ * @typedef { OnEventWithPriority & OnEventWithOutPriority } OnEventType
1768
1773
  */
1769
1774
 
1770
1775
  const ids = new Ids([32, 36, 1]);
@@ -1778,10 +1783,16 @@ class Form {
1778
1783
  * @param {FormOptions} options
1779
1784
  */
1780
1785
  constructor(options = {}) {
1786
+ /**
1787
+ * @public
1788
+ * @type {OnEventType}
1789
+ */
1790
+ this.on = this._onEvent;
1781
1791
  /**
1782
1792
  * @public
1783
1793
  * @type {String}
1784
1794
  */
1795
+
1785
1796
  this._id = ids.next();
1786
1797
  /**
1787
1798
  * @private
@@ -2028,16 +2039,6 @@ class Form {
2028
2039
  properties
2029
2040
  });
2030
2041
  }
2031
- /**
2032
- * @param {FormEvent} type
2033
- * @param {number} priority
2034
- * @param {Function} handler
2035
- */
2036
-
2037
-
2038
- on(type, priority, handler) {
2039
- this.get('eventBus').on(type, priority, handler);
2040
- }
2041
2042
  /**
2042
2043
  * @param {FormEvent} type
2043
2044
  * @param {Function} handler
@@ -2132,10 +2133,18 @@ class Form {
2132
2133
 
2133
2134
  this._emit('changed', this._getState());
2134
2135
  }
2136
+ /**
2137
+ * @internal
2138
+ */
2139
+
2140
+
2141
+ _onEvent(type, priority, handler) {
2142
+ this.get('eventBus').on(type, priority, handler);
2143
+ }
2135
2144
 
2136
2145
  }
2137
2146
 
2138
- const schemaVersion = 3;
2147
+ const schemaVersion = 4;
2139
2148
  /**
2140
2149
  * @typedef { import('./types').CreateFormOptions } CreateFormOptions
2141
2150
  */