@sankhyalabs/sankhyablocks 1.1.23 → 1.1.27

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 (186) hide show
  1. package/dist/cjs/ApplicationUtils-05b74ee9.js +39 -0
  2. package/dist/cjs/AssetsUtils-bd004f63.js +24 -0
  3. package/dist/cjs/CSSVarsUtils-75ca9c64.js +19 -0
  4. package/dist/cjs/_commonjsHelpers-537d719a.js +20 -0
  5. package/dist/cjs/ez-action-chip.cjs.entry.js +27 -0
  6. package/dist/cjs/ez-application.cjs.entry.js +26 -0
  7. package/dist/cjs/ez-button_4.cjs.entry.js +660 -0
  8. package/dist/cjs/ez-calendar.cjs.entry.js +223 -0
  9. package/dist/cjs/ez-collapsible-box.cjs.entry.js +47 -0
  10. package/dist/cjs/ez-combo-box.cjs.entry.js +278 -0
  11. package/dist/cjs/ez-date-input.cjs.entry.js +102 -0
  12. package/dist/cjs/ez-date-time-input.cjs.entry.js +145 -0
  13. package/dist/cjs/ez-dialog.cjs.entry.js +89 -0
  14. package/dist/cjs/ez-form.cjs.entry.js +785 -0
  15. package/dist/cjs/ez-grid.cjs.entry.js +110485 -0
  16. package/dist/cjs/ez-icon.cjs.entry.js +41 -0
  17. package/dist/cjs/ez-label-chip.cjs.entry.js +104 -0
  18. package/dist/cjs/ez-modal_2.cjs.entry.js +316 -0
  19. package/dist/cjs/ez-number-input.cjs.entry.js +86 -0
  20. package/dist/cjs/ez-popover.cjs.entry.js +120 -0
  21. package/dist/cjs/ez-popup.cjs.entry.js +48 -0
  22. package/dist/cjs/ez-search.cjs.entry.js +64 -0
  23. package/dist/cjs/ez-tabselector.cjs.entry.js +198 -0
  24. package/dist/cjs/ez-text-area.cjs.entry.js +114 -0
  25. package/dist/cjs/ez-text-input.cjs.entry.js +201 -0
  26. package/dist/cjs/ez-time-input.cjs.entry.js +118 -0
  27. package/dist/cjs/ez-toast.cjs.entry.js +44 -0
  28. package/dist/cjs/ez-upload.cjs.entry.js +356 -0
  29. package/dist/cjs/index-6ac5268e.js +1769 -0
  30. package/dist/cjs/loader.cjs.js +2 -2
  31. package/dist/cjs/sankhyablocks.cjs.js +2 -2
  32. package/dist/cjs/snk-application.cjs.entry.js +52 -1313
  33. package/dist/cjs/test-du.cjs.entry.js +76 -0
  34. package/dist/collection/collection-manifest.json +36 -1
  35. package/dist/collection/components/snk-application/snk-application.js +8 -4
  36. package/dist/{collection/temp → components}/ApplicationUtils.js +37 -31
  37. package/dist/components/AssetsUtils.js +22 -0
  38. package/dist/components/CSSVarsUtils.js +17 -0
  39. package/dist/components/_commonjsHelpers.js +17 -0
  40. package/dist/components/ez-action-chip.js +44 -0
  41. package/dist/components/ez-application.js +39 -0
  42. package/dist/components/ez-button.js +6 -0
  43. package/dist/components/ez-button2.js +105 -0
  44. package/dist/components/ez-calendar.js +6 -0
  45. package/dist/components/ez-calendar2.js +242 -0
  46. package/dist/components/ez-check.js +6 -0
  47. package/dist/components/ez-check2.js +94 -0
  48. package/dist/components/ez-collapsible-box.js +67 -0
  49. package/dist/components/ez-combo-box.js +6 -0
  50. package/dist/components/ez-combo-box2.js +311 -0
  51. package/dist/components/ez-date-input.js +135 -0
  52. package/dist/components/ez-date-time-input.js +179 -0
  53. package/dist/components/ez-dialog.js +124 -0
  54. package/dist/components/ez-form.js +6 -0
  55. package/dist/components/ez-form2.js +807 -0
  56. package/dist/components/ez-grid.js +110576 -0
  57. package/dist/components/ez-icon.js +6 -0
  58. package/dist/components/ez-icon2.js +56 -0
  59. package/dist/components/ez-label-chip.js +125 -0
  60. package/dist/components/ez-list.js +6 -0
  61. package/dist/components/ez-list2.js +523 -0
  62. package/dist/components/ez-modal.js +6 -0
  63. package/dist/components/ez-modal2.js +82 -0
  64. package/dist/components/ez-number-input.js +115 -0
  65. package/dist/components/ez-popover.js +145 -0
  66. package/dist/components/ez-popup.js +67 -0
  67. package/dist/components/ez-search.js +100 -0
  68. package/dist/components/ez-tabselector.js +6 -0
  69. package/dist/components/ez-tabselector2.js +213 -0
  70. package/dist/components/ez-text-area.js +137 -0
  71. package/dist/components/ez-text-input.js +6 -0
  72. package/dist/components/ez-text-input2.js +223 -0
  73. package/dist/components/ez-time-input.js +153 -0
  74. package/dist/components/ez-toast.js +64 -0
  75. package/dist/components/ez-upload.js +382 -0
  76. package/dist/components/grid-config.js +6 -0
  77. package/dist/components/grid-config2.js +318 -0
  78. package/dist/components/select-box.js +6 -0
  79. package/dist/components/select-box2.js +47 -0
  80. package/dist/components/snk-application.js +5 -1266
  81. package/dist/components/test-du.js +101 -0
  82. package/dist/esm/ApplicationUtils-e0b6d857.js +37 -0
  83. package/dist/esm/AssetsUtils-98074c9c.js +22 -0
  84. package/dist/esm/CSSVarsUtils-0787c3f3.js +17 -0
  85. package/dist/esm/_commonjsHelpers-9943807e.js +17 -0
  86. package/dist/esm/ez-action-chip.entry.js +23 -0
  87. package/dist/esm/ez-application.entry.js +22 -0
  88. package/dist/esm/ez-button_4.entry.js +653 -0
  89. package/dist/esm/ez-calendar.entry.js +219 -0
  90. package/dist/esm/ez-collapsible-box.entry.js +43 -0
  91. package/dist/esm/ez-combo-box.entry.js +274 -0
  92. package/dist/esm/ez-date-input.entry.js +98 -0
  93. package/dist/esm/ez-date-time-input.entry.js +141 -0
  94. package/dist/esm/ez-dialog.entry.js +85 -0
  95. package/dist/esm/ez-form.entry.js +781 -0
  96. package/dist/esm/ez-grid.entry.js +110481 -0
  97. package/dist/esm/ez-icon.entry.js +37 -0
  98. package/dist/esm/ez-label-chip.entry.js +100 -0
  99. package/dist/esm/ez-modal_2.entry.js +311 -0
  100. package/dist/esm/ez-number-input.entry.js +82 -0
  101. package/dist/esm/ez-popover.entry.js +116 -0
  102. package/dist/esm/ez-popup.entry.js +44 -0
  103. package/dist/esm/ez-search.entry.js +60 -0
  104. package/dist/esm/ez-tabselector.entry.js +194 -0
  105. package/dist/esm/ez-text-area.entry.js +110 -0
  106. package/dist/esm/ez-text-input.entry.js +197 -0
  107. package/dist/esm/ez-time-input.entry.js +114 -0
  108. package/dist/esm/ez-toast.entry.js +40 -0
  109. package/dist/esm/ez-upload.entry.js +352 -0
  110. package/dist/esm/index-df166135.js +1738 -0
  111. package/dist/esm/loader.js +2 -2
  112. package/dist/esm/sankhyablocks.js +2 -2
  113. package/dist/esm/snk-application.entry.js +6 -1267
  114. package/dist/esm/test-du.entry.js +72 -0
  115. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-action-chip/ez-action-chip.css +67 -0
  116. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-application/ez-application.css +3 -0
  117. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-button/ez-button.css +180 -0
  118. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-calendar/ez-calendar.css +319 -0
  119. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-check/ez-check.css +327 -0
  120. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-collapsible-box/ez-collapsible-box.css +162 -0
  121. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-combo-box/ez-combo-box.css +217 -0
  122. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-input/ez-date-input.css +49 -0
  123. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-time-input/ez-date-time-input.css +44 -0
  124. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-dialog/ez-dialog.css +527 -0
  125. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-form/ez-form.css +5 -0
  126. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/ez-grid.css +31 -0
  127. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.css +129 -0
  128. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/select-box/select-box.css +10 -0
  129. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-icon/ez-icon.css +176 -0
  130. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-label-chip/ez-label-chip.css +139 -0
  131. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-list/ez-list.css +335 -0
  132. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-modal/ez-modal.css +358 -0
  133. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-number-input/ez-number-input.css +4 -0
  134. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popover/ez-popover.css +44 -0
  135. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popup/ez-popup.css +405 -0
  136. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-search/ez-search.css +3 -0
  137. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-tabselector/ez-tabselector.css +138 -0
  138. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-area/ez-text-area.css +165 -0
  139. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-input/ez-text-input.css +196 -0
  140. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-time-input/ez-time-input.css +10 -0
  141. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-toast/ez-toast.css +127 -0
  142. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-upload/ez-upload.css +568 -0
  143. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/test-du/test-du.css +3 -0
  144. package/dist/sankhyablocks/p-08e1cded.entry.js +1 -0
  145. package/dist/sankhyablocks/p-0a77ac95.entry.js +57 -0
  146. package/dist/sankhyablocks/p-112455b1.js +1 -0
  147. package/dist/sankhyablocks/p-126c4aaa.entry.js +1 -0
  148. package/dist/sankhyablocks/p-1421b89a.entry.js +1 -0
  149. package/dist/sankhyablocks/p-1beadcaf.entry.js +1 -0
  150. package/dist/sankhyablocks/p-1c423f5d.entry.js +1 -0
  151. package/dist/sankhyablocks/p-28a0dbf0.entry.js +1 -0
  152. package/dist/sankhyablocks/p-4763d5c2.js +1 -0
  153. package/dist/sankhyablocks/p-4c66200a.entry.js +1 -0
  154. package/dist/sankhyablocks/p-5dc772be.entry.js +1 -0
  155. package/dist/sankhyablocks/p-5ff3e300.entry.js +1 -0
  156. package/dist/sankhyablocks/p-7122cec4.entry.js +1 -0
  157. package/dist/sankhyablocks/p-811b4b9d.js +1 -0
  158. package/dist/sankhyablocks/p-813fe4f7.js +1 -0
  159. package/dist/sankhyablocks/p-9b33a005.entry.js +1 -0
  160. package/dist/sankhyablocks/p-9e22ec87.entry.js +1 -0
  161. package/dist/sankhyablocks/p-9f7239df.entry.js +1 -0
  162. package/dist/sankhyablocks/p-9f7e6e48.js +1 -0
  163. package/dist/sankhyablocks/p-a47e0537.entry.js +1 -0
  164. package/dist/sankhyablocks/p-a9aba60a.entry.js +1 -0
  165. package/dist/sankhyablocks/p-afda7940.entry.js +1 -0
  166. package/dist/sankhyablocks/p-b3a83eaf.entry.js +1 -0
  167. package/dist/sankhyablocks/p-b96a8d40.entry.js +1 -0
  168. package/dist/sankhyablocks/p-c61c0e40.entry.js +1 -0
  169. package/dist/sankhyablocks/p-ca29d028.entry.js +1 -0
  170. package/dist/sankhyablocks/p-cd17abb1.entry.js +1 -0
  171. package/dist/sankhyablocks/p-d3a5366d.entry.js +369 -0
  172. package/dist/sankhyablocks/p-d5703a41.entry.js +1 -0
  173. package/dist/sankhyablocks/p-e5f77a59.entry.js +1 -0
  174. package/dist/sankhyablocks/p-e9e94d51.entry.js +1 -0
  175. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  176. package/dist/types/components/snk-application/snk-application.d.ts +1 -1
  177. package/dist/types/components.d.ts +1 -1
  178. package/package.json +11 -3
  179. package/react/components.d.ts +29 -0
  180. package/react/components.js +29 -0
  181. package/react/components.js.map +1 -1
  182. package/dist/cjs/index-20a7d705.js +0 -733
  183. package/dist/esm/index-8d3572c4.js +0 -707
  184. package/dist/sankhyablocks/p-5fa264b9.js +0 -1
  185. package/dist/sankhyablocks/p-f3bdd8c3.entry.js +0 -57
  186. package/dist/types/temp/ApplicationUtils.d.ts +0 -7
@@ -0,0 +1,781 @@
1
+ import { h, r as registerInstance, f as forceUpdate, H as Host, g as getElement } from './index-df166135.js';
2
+ import { UserInterface, ApplicationContext, Action, DataUnitAction, DataUnit } from '@sankhyalabs/core';
3
+ import { A as ApplicationUtils } from './ApplicationUtils-e0b6d857.js';
4
+
5
+ const buildTextArea = ({ name, label, readOnly }) => {
6
+ return (h("div", { class: "col col--sd-12 padding-horizontal--small", key: name },
7
+ h("ez-text-area", { enabled: !readOnly, label: label, "data-field-name": name })));
8
+ };
9
+
10
+ const buildTextInput = ({ name, label }) => {
11
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
12
+ h("ez-text-input", { label: label, "data-field-name": name, key: name })));
13
+ };
14
+
15
+ const buildSwitch = (fieldConfig) => {
16
+ return buildField$1(fieldConfig.name, fieldConfig.label, fieldConfig.readOnly, true);
17
+ };
18
+ const buildCheckBox = (fieldConfig) => {
19
+ return buildField$1(fieldConfig.name, fieldConfig.label, fieldConfig.readOnly, false);
20
+ };
21
+ function buildField$1(fieldName, fieldLabel, readOnly, switchMode = false) {
22
+ return (h("div", { class: "col col--sd-12 col--tb-3 align--middle padding-horizontal--small padding-bottom--large" },
23
+ h("ez-check", { enabled: !readOnly, label: fieldLabel, mode: switchMode ? "switch" : "regular", "data-field-name": fieldName, key: fieldName })));
24
+ }
25
+
26
+ const buildComboBox = ({ name, label, readOnly }, properties) => {
27
+ const prop = properties === null || properties === void 0 ? void 0 : properties.options;
28
+ let options;
29
+ if (typeof prop === "string") {
30
+ const parsed = JSON.parse(prop);
31
+ options = Object.keys(parsed).map(key => { return { value: key, label: parsed[key] }; });
32
+ }
33
+ else {
34
+ options = prop;
35
+ }
36
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
37
+ h("ez-combo-box", { enabled: !readOnly, label: label, "data-field-name": name, key: name, options: options })));
38
+ };
39
+
40
+ const buildSearch = ({ name, label, readOnly }) => {
41
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
42
+ h("ez-search", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
43
+ };
44
+
45
+ const buildFile = ({ name, label, readOnly }) => {
46
+ return (h("div", { class: "col col--sd-12 padding-horizontal--small" },
47
+ h("ez-upload", { enabled: !readOnly, label: label, urlUpload: "", requestHeaders: "", maxFiles: 10, "data-field-name": name, key: name })));
48
+ };
49
+
50
+ const buildDate = ({ name, label, readOnly }) => {
51
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
52
+ h("ez-date-input", { enabled: !readOnly, label: label, "data-field-name": name, key: name })));
53
+ };
54
+ const buildTime = ({ name, label }) => {
55
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
56
+ h("ez-time-input", { label: label, "data-field-name": name, key: name })));
57
+ };
58
+ const buildTimeDate = ({ name, label }) => {
59
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
60
+ h("ez-date-time-input", { label: label, "data-field-name": name, key: name })));
61
+ };
62
+
63
+ const buildDecimal = ({ name, label, readOnly }, properties) => {
64
+ const precision = Number((properties === null || properties === void 0 ? void 0 : properties.precision) || 2);
65
+ const prettyPrecision = Number((properties === null || properties === void 0 ? void 0 : properties.prettyPrecision) || precision);
66
+ return buildNumeric(name, label, readOnly, precision, prettyPrecision);
67
+ };
68
+ const buildInteger = ({ name, label, readOnly }) => {
69
+ return buildNumeric(name, label, readOnly, 0, 0);
70
+ };
71
+ function buildNumeric(fieldName, fieldLabel, readOnly, precision, prettyPrecision) {
72
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding-horizontal--small" },
73
+ h("ez-number-input", { enabled: !readOnly, label: fieldLabel, precision: precision, prettyPrecision: prettyPrecision, "data-field-name": fieldName, key: fieldName })));
74
+ }
75
+
76
+ const uiBuilders = new Map();
77
+ uiBuilders.set(UserInterface.LONGTEXT, buildTextArea);
78
+ uiBuilders.set(UserInterface.CHECKBOX, buildCheckBox);
79
+ uiBuilders.set(UserInterface.SWITCH, buildSwitch);
80
+ uiBuilders.set(UserInterface.OPTIONSELECTOR, buildComboBox);
81
+ uiBuilders.set(UserInterface.SEARCH, buildSearch);
82
+ uiBuilders.set(UserInterface.FILE, buildFile);
83
+ uiBuilders.set(UserInterface.DATE, buildDate);
84
+ uiBuilders.set(UserInterface.TIME, buildTime);
85
+ uiBuilders.set(UserInterface.DATETIME, buildTimeDate);
86
+ uiBuilders.set(UserInterface.DECIMALNUMBER, buildDecimal);
87
+ uiBuilders.set(UserInterface.INTEGERNUMBER, buildInteger);
88
+ const buildField = (field) => {
89
+ const descriptor = field.descriptor;
90
+ const config = Object.assign({}, field.config);
91
+ let builder;
92
+ let props;
93
+ if (descriptor) {
94
+ if (!config.label) {
95
+ config.label = descriptor.label;
96
+ }
97
+ if (!config.name) {
98
+ config.name = descriptor.name;
99
+ }
100
+ if (config.required === undefined) {
101
+ config.required = descriptor.required;
102
+ }
103
+ if (config.readOnly === undefined) {
104
+ config.readOnly = descriptor.readOnly;
105
+ }
106
+ props = descriptor.properties;
107
+ builder = uiBuilders.get(descriptor.userInterface);
108
+ }
109
+ if (config.required) {
110
+ config.label = `* ${config.label} (obrigatório)`;
111
+ }
112
+ if (!builder) {
113
+ builder = buildTextInput;
114
+ }
115
+ return builder(config, props);
116
+ };
117
+
118
+ const FormItem = ({ source }) => {
119
+ if ("items" in source) {
120
+ const fieldSet = source;
121
+ return h("ez-collapsible-box", { label: source.label }, fieldSet.items.map(fi => buildField(fi)));
122
+ }
123
+ else {
124
+ return buildField(source);
125
+ }
126
+ };
127
+
128
+ const FormSheet = ({ store, source }) => {
129
+ return (h("div", { class: "box__container" },
130
+ h("div", { class: "row padding-vertical--small" }, source.items.map(item => h(FormItem, { store: store, source: item })))));
131
+ };
132
+
133
+ class FormMetadata {
134
+ constructor() {
135
+ this._sheets = new Map();
136
+ this._requiredFields = [];
137
+ this._cleanOnCopyFields = [];
138
+ }
139
+ getSheet(name) {
140
+ return this._sheets.get(name);
141
+ }
142
+ getAllSheets() {
143
+ return this._sheets;
144
+ }
145
+ addSheet(sheet) {
146
+ this._sheets.set(sheet.name, sheet);
147
+ this._requiredFields = this._requiredFields.concat(sheet.requiredFields);
148
+ this._cleanOnCopyFields = this._cleanOnCopyFields.concat(sheet.cleanOnCopyFields);
149
+ }
150
+ getRequiredFields() {
151
+ return this._requiredFields;
152
+ }
153
+ getCleanOnCopyFields() {
154
+ return this._cleanOnCopyFields;
155
+ }
156
+ }
157
+ const buildFromDataUnit = (dataUnit) => {
158
+ var _a;
159
+ const unitMD = dataUnit.metadata;
160
+ const metadata = new FormMetadata();
161
+ if (unitMD) {
162
+ const visibleFields = (_a = unitMD.fields) === null || _a === void 0 ? void 0 : _a.filter(descriptor => descriptor.visible !== false);
163
+ metadata.addSheet({
164
+ label: unitMD.label,
165
+ name: unitMD.name,
166
+ items: visibleFields.map(descriptor => { return { descriptor }; }),
167
+ requiredFields: visibleFields
168
+ .filter(descriptor => descriptor.required)
169
+ .map(descriptor => descriptor.name),
170
+ cleanOnCopyFields: visibleFields
171
+ .filter(descriptor => { var _a; return (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy; })
172
+ .map(descriptor => descriptor.name)
173
+ });
174
+ }
175
+ return metadata;
176
+ };
177
+ function getTabConfig(tab, sheets) {
178
+ const tabConfig = (typeof tab === "string" ? Array.from(sheets.keys()).find(t => t.label === tab) : tab);
179
+ return tabConfig || { label: tab, visible: true };
180
+ }
181
+ const buildFromConfig = (fields, dataUnit) => {
182
+ const sheets = new Map();
183
+ const requiredFields = [];
184
+ const cleanOnCopyFields = [];
185
+ fields.forEach(config => {
186
+ var _a;
187
+ if (config.visible !== false) {
188
+ const tabConfig = getTabConfig(config.tab || "Geral", sheets);
189
+ const descriptor = dataUnit.getField(config.name);
190
+ if (descriptor && tabConfig.visible) {
191
+ if (!sheets.has(tabConfig)) {
192
+ sheets.set(tabConfig, new Map());
193
+ }
194
+ const tabItens = sheets.get(tabConfig);
195
+ const isRequired = config.required === undefined ? descriptor.required : config.required;
196
+ if (isRequired) {
197
+ requiredFields.push(config.name);
198
+ }
199
+ const clearOnCopy = config.cleanOnCopy === undefined ? (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.cleanOnCopy : config.cleanOnCopy;
200
+ if (clearOnCopy) {
201
+ cleanOnCopyFields.push(config.name);
202
+ }
203
+ const fieldMD = { config, descriptor };
204
+ const group = config.group;
205
+ if (group) {
206
+ const key = `group::${group}`;
207
+ if (!tabItens.has(key)) {
208
+ tabItens.set(key, { label: group, items: [fieldMD] });
209
+ }
210
+ else {
211
+ tabItens.get(key).items.push(fieldMD);
212
+ }
213
+ }
214
+ else {
215
+ tabItens.set(config.name, fieldMD);
216
+ }
217
+ }
218
+ }
219
+ });
220
+ const metadata = new FormMetadata();
221
+ Array.from(sheets.entries())
222
+ .sort((a, b) => (a[0].order || 10000) - (b[0].order || 10000))
223
+ .forEach(([key, value]) => {
224
+ metadata.addSheet({
225
+ label: key.label,
226
+ name: key.label,
227
+ items: Array.from(value.values()),
228
+ requiredFields,
229
+ cleanOnCopyFields
230
+ });
231
+ });
232
+ return metadata;
233
+ };
234
+
235
+ /**
236
+ * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
237
+ *
238
+ * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
239
+ * during build.
240
+ * @param {number} code
241
+ */
242
+ function formatProdErrorMessage(code) {
243
+ return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. ';
244
+ }
245
+
246
+ // Inlined version of the `symbol-observable` polyfill
247
+ var $$observable = (function () {
248
+ return typeof Symbol === 'function' && Symbol.observable || '@@observable';
249
+ })();
250
+
251
+ /**
252
+ * These are private action types reserved by Redux.
253
+ * For any unknown actions, you must return the current state.
254
+ * If the current state is undefined, you must return the initial state.
255
+ * Do not reference these action types directly in your code.
256
+ */
257
+ var randomString = function randomString() {
258
+ return Math.random().toString(36).substring(7).split('').join('.');
259
+ };
260
+
261
+ var ActionTypes = {
262
+ INIT: "@@redux/INIT" + randomString(),
263
+ REPLACE: "@@redux/REPLACE" + randomString(),
264
+ PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
265
+ return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
266
+ }
267
+ };
268
+
269
+ /**
270
+ * @param {any} obj The object to inspect.
271
+ * @returns {boolean} True if the argument appears to be a plain object.
272
+ */
273
+ function isPlainObject(obj) {
274
+ if (typeof obj !== 'object' || obj === null) return false;
275
+ var proto = obj;
276
+
277
+ while (Object.getPrototypeOf(proto) !== null) {
278
+ proto = Object.getPrototypeOf(proto);
279
+ }
280
+
281
+ return Object.getPrototypeOf(obj) === proto;
282
+ }
283
+
284
+ /**
285
+ * @deprecated
286
+ *
287
+ * **We recommend using the `configureStore` method
288
+ * of the `@reduxjs/toolkit` package**, which replaces `createStore`.
289
+ *
290
+ * Redux Toolkit is our recommended approach for writing Redux logic today,
291
+ * including store setup, reducers, data fetching, and more.
292
+ *
293
+ * **For more details, please read this Redux docs page:**
294
+ * **https://redux.js.org/introduction/why-rtk-is-redux-today**
295
+ *
296
+ * `configureStore` from Redux Toolkit is an improved version of `createStore` that
297
+ * simplifies setup and helps avoid common bugs.
298
+ *
299
+ * You should not be using the `redux` core package by itself today, except for learning purposes.
300
+ * The `createStore` method from the core `redux` package will not be removed, but we encourage
301
+ * all users to migrate to using Redux Toolkit for all Redux code.
302
+ *
303
+ * If you want to use `createStore` without this visual deprecation warning, use
304
+ * the `legacy_createStore` import instead:
305
+ *
306
+ * `import { legacy_createStore as createStore} from 'redux'`
307
+ *
308
+ */
309
+
310
+ function createStore(reducer, preloadedState, enhancer) {
311
+ var _ref2;
312
+
313
+ if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
314
+ throw new Error(formatProdErrorMessage(0) );
315
+ }
316
+
317
+ if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
318
+ enhancer = preloadedState;
319
+ preloadedState = undefined;
320
+ }
321
+
322
+ if (typeof enhancer !== 'undefined') {
323
+ if (typeof enhancer !== 'function') {
324
+ throw new Error(formatProdErrorMessage(1) );
325
+ }
326
+
327
+ return enhancer(createStore)(reducer, preloadedState);
328
+ }
329
+
330
+ if (typeof reducer !== 'function') {
331
+ throw new Error(formatProdErrorMessage(2) );
332
+ }
333
+
334
+ var currentReducer = reducer;
335
+ var currentState = preloadedState;
336
+ var currentListeners = [];
337
+ var nextListeners = currentListeners;
338
+ var isDispatching = false;
339
+ /**
340
+ * This makes a shallow copy of currentListeners so we can use
341
+ * nextListeners as a temporary list while dispatching.
342
+ *
343
+ * This prevents any bugs around consumers calling
344
+ * subscribe/unsubscribe in the middle of a dispatch.
345
+ */
346
+
347
+ function ensureCanMutateNextListeners() {
348
+ if (nextListeners === currentListeners) {
349
+ nextListeners = currentListeners.slice();
350
+ }
351
+ }
352
+ /**
353
+ * Reads the state tree managed by the store.
354
+ *
355
+ * @returns {any} The current state tree of your application.
356
+ */
357
+
358
+
359
+ function getState() {
360
+ if (isDispatching) {
361
+ throw new Error(formatProdErrorMessage(3) );
362
+ }
363
+
364
+ return currentState;
365
+ }
366
+ /**
367
+ * Adds a change listener. It will be called any time an action is dispatched,
368
+ * and some part of the state tree may potentially have changed. You may then
369
+ * call `getState()` to read the current state tree inside the callback.
370
+ *
371
+ * You may call `dispatch()` from a change listener, with the following
372
+ * caveats:
373
+ *
374
+ * 1. The subscriptions are snapshotted just before every `dispatch()` call.
375
+ * If you subscribe or unsubscribe while the listeners are being invoked, this
376
+ * will not have any effect on the `dispatch()` that is currently in progress.
377
+ * However, the next `dispatch()` call, whether nested or not, will use a more
378
+ * recent snapshot of the subscription list.
379
+ *
380
+ * 2. The listener should not expect to see all state changes, as the state
381
+ * might have been updated multiple times during a nested `dispatch()` before
382
+ * the listener is called. It is, however, guaranteed that all subscribers
383
+ * registered before the `dispatch()` started will be called with the latest
384
+ * state by the time it exits.
385
+ *
386
+ * @param {Function} listener A callback to be invoked on every dispatch.
387
+ * @returns {Function} A function to remove this change listener.
388
+ */
389
+
390
+
391
+ function subscribe(listener) {
392
+ if (typeof listener !== 'function') {
393
+ throw new Error(formatProdErrorMessage(4) );
394
+ }
395
+
396
+ if (isDispatching) {
397
+ throw new Error(formatProdErrorMessage(5) );
398
+ }
399
+
400
+ var isSubscribed = true;
401
+ ensureCanMutateNextListeners();
402
+ nextListeners.push(listener);
403
+ return function unsubscribe() {
404
+ if (!isSubscribed) {
405
+ return;
406
+ }
407
+
408
+ if (isDispatching) {
409
+ throw new Error(formatProdErrorMessage(6) );
410
+ }
411
+
412
+ isSubscribed = false;
413
+ ensureCanMutateNextListeners();
414
+ var index = nextListeners.indexOf(listener);
415
+ nextListeners.splice(index, 1);
416
+ currentListeners = null;
417
+ };
418
+ }
419
+ /**
420
+ * Dispatches an action. It is the only way to trigger a state change.
421
+ *
422
+ * The `reducer` function, used to create the store, will be called with the
423
+ * current state tree and the given `action`. Its return value will
424
+ * be considered the **next** state of the tree, and the change listeners
425
+ * will be notified.
426
+ *
427
+ * The base implementation only supports plain object actions. If you want to
428
+ * dispatch a Promise, an Observable, a thunk, or something else, you need to
429
+ * wrap your store creating function into the corresponding middleware. For
430
+ * example, see the documentation for the `redux-thunk` package. Even the
431
+ * middleware will eventually dispatch plain object actions using this method.
432
+ *
433
+ * @param {Object} action A plain object representing “what changed”. It is
434
+ * a good idea to keep actions serializable so you can record and replay user
435
+ * sessions, or use the time travelling `redux-devtools`. An action must have
436
+ * a `type` property which may not be `undefined`. It is a good idea to use
437
+ * string constants for action types.
438
+ *
439
+ * @returns {Object} For convenience, the same action object you dispatched.
440
+ *
441
+ * Note that, if you use a custom middleware, it may wrap `dispatch()` to
442
+ * return something else (for example, a Promise you can await).
443
+ */
444
+
445
+
446
+ function dispatch(action) {
447
+ if (!isPlainObject(action)) {
448
+ throw new Error(formatProdErrorMessage(7) );
449
+ }
450
+
451
+ if (typeof action.type === 'undefined') {
452
+ throw new Error(formatProdErrorMessage(8) );
453
+ }
454
+
455
+ if (isDispatching) {
456
+ throw new Error(formatProdErrorMessage(9) );
457
+ }
458
+
459
+ try {
460
+ isDispatching = true;
461
+ currentState = currentReducer(currentState, action);
462
+ } finally {
463
+ isDispatching = false;
464
+ }
465
+
466
+ var listeners = currentListeners = nextListeners;
467
+
468
+ for (var i = 0; i < listeners.length; i++) {
469
+ var listener = listeners[i];
470
+ listener();
471
+ }
472
+
473
+ return action;
474
+ }
475
+ /**
476
+ * Replaces the reducer currently used by the store to calculate the state.
477
+ *
478
+ * You might need this if your app implements code splitting and you want to
479
+ * load some of the reducers dynamically. You might also need this if you
480
+ * implement a hot reloading mechanism for Redux.
481
+ *
482
+ * @param {Function} nextReducer The reducer for the store to use instead.
483
+ * @returns {void}
484
+ */
485
+
486
+
487
+ function replaceReducer(nextReducer) {
488
+ if (typeof nextReducer !== 'function') {
489
+ throw new Error(formatProdErrorMessage(10) );
490
+ }
491
+
492
+ currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
493
+ // Any reducers that existed in both the new and old rootReducer
494
+ // will receive the previous state. This effectively populates
495
+ // the new state tree with any relevant data from the old one.
496
+
497
+ dispatch({
498
+ type: ActionTypes.REPLACE
499
+ });
500
+ }
501
+ /**
502
+ * Interoperability point for observable/reactive libraries.
503
+ * @returns {observable} A minimal observable of state changes.
504
+ * For more information, see the observable proposal:
505
+ * https://github.com/tc39/proposal-observable
506
+ */
507
+
508
+
509
+ function observable() {
510
+ var _ref;
511
+
512
+ var outerSubscribe = subscribe;
513
+ return _ref = {
514
+ /**
515
+ * The minimal observable subscription method.
516
+ * @param {Object} observer Any object that can be used as an observer.
517
+ * The observer object should have a `next` method.
518
+ * @returns {subscription} An object with an `unsubscribe` method that can
519
+ * be used to unsubscribe the observable from the store, and prevent further
520
+ * emission of values from the observable.
521
+ */
522
+ subscribe: function subscribe(observer) {
523
+ if (typeof observer !== 'object' || observer === null) {
524
+ throw new Error(formatProdErrorMessage(11) );
525
+ }
526
+
527
+ function observeState() {
528
+ if (observer.next) {
529
+ observer.next(getState());
530
+ }
531
+ }
532
+
533
+ observeState();
534
+ var unsubscribe = outerSubscribe(observeState);
535
+ return {
536
+ unsubscribe: unsubscribe
537
+ };
538
+ }
539
+ }, _ref[$$observable] = function () {
540
+ return this;
541
+ }, _ref;
542
+ } // When a store is created, an "INIT" action is dispatched so that every
543
+ // reducer returns their initial state. This effectively populates
544
+ // the initial state tree.
545
+
546
+
547
+ dispatch({
548
+ type: ActionTypes.INIT
549
+ });
550
+ return _ref2 = {
551
+ dispatch: dispatch,
552
+ subscribe: subscribe,
553
+ getState: getState,
554
+ replaceReducer: replaceReducer
555
+ }, _ref2[$$observable] = observable, _ref2;
556
+ }
557
+
558
+ const inicialState = {};
559
+ /////////////////////////////// REDUCERS ///////////////////////////////
560
+ function formReducer(state = inicialState, action) {
561
+ switch (action.type) {
562
+ case FormActions.METADATA_LOADED:
563
+ return Object.assign(Object.assign({}, state), { formMetadata: action.payload });
564
+ case FormActions.CHANGE_TAB:
565
+ return Object.assign(Object.assign({}, state), { currentSheet: action.payload });
566
+ default:
567
+ return state;
568
+ }
569
+ }
570
+ /////////////////////////////// ACTION CREATORS ///////////////////////////////
571
+ function loadMetadata(formMetadata) {
572
+ return {
573
+ type: FormActions.METADATA_LOADED,
574
+ payload: formMetadata
575
+ };
576
+ }
577
+ function changeTab(currentSheet) {
578
+ return {
579
+ type: FormActions.CHANGE_TAB,
580
+ payload: currentSheet.tabKey
581
+ };
582
+ }
583
+ /////////////////////////////// SELECTORS ///////////////////////////////
584
+ function selectFormMetadata(state) {
585
+ return state.formMetadata;
586
+ }
587
+ function selectCurrentSheet(state) {
588
+ return state.currentSheet ? state.formMetadata.getSheet(state.currentSheet) : Array.from(state.formMetadata.getAllSheets().values())[0];
589
+ }
590
+ /////////////////////////////// TYPES ///////////////////////////////
591
+ var FormActions;
592
+ (function (FormActions) {
593
+ FormActions["METADATA_LOADED"] = "FORM/METADATA_LOADED";
594
+ FormActions["CHANGE_TAB"] = "FORM/CHANGE_TAB";
595
+ })(FormActions || (FormActions = {}));
596
+
597
+ class DataBinder {
598
+ constructor(dataUnit) {
599
+ this._fields = new Map();
600
+ this._dataUnit = dataUnit;
601
+ this._dataUnit.subscribe(_action => {
602
+ var _a;
603
+ (_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
604
+ this.updateValue(field.fieldName, field.field);
605
+ });
606
+ });
607
+ }
608
+ bind(fields) {
609
+ fields.forEach(fieldElement => {
610
+ const fieldName = fieldElement.dataset.fieldName;
611
+ this.updateBind(fieldName, fieldElement);
612
+ this.updateValue(fieldName, fieldElement);
613
+ });
614
+ }
615
+ updateValue(fieldName, field) {
616
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
617
+ }
618
+ updateBind(fieldName, field) {
619
+ const oldBind = this._fields.get(fieldName);
620
+ if (oldBind) {
621
+ oldBind.destroy();
622
+ }
623
+ this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
624
+ this.bindSearchOptionsLoader(fieldName, field);
625
+ }
626
+ setFieldValue(fieldName, newValue) {
627
+ if (this._dataUnit.records.length === 0) {
628
+ this._dataUnit.addRecord();
629
+ }
630
+ this._dataUnit.setFieldValue(fieldName, newValue);
631
+ }
632
+ bindSearchOptionsLoader(fieldName, field) {
633
+ if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] === undefined) {
634
+ const loader = ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
635
+ if (loader) {
636
+ field["optionLoader"] = (arg) => {
637
+ return loader(arg, fieldName, this._dataUnit);
638
+ };
639
+ }
640
+ }
641
+ }
642
+ }
643
+ class Bind {
644
+ destroy() {
645
+ this.field.removeEventListener(this.eventName, this.eventListener);
646
+ }
647
+ static create(fieldName, field, callback) {
648
+ const b = new Bind();
649
+ b.fieldName = fieldName;
650
+ b.field = field;
651
+ //FIXME: Verificar se o field é um EzField
652
+ b.eventListener = (evt) => { callback(fieldName, evt.detail); };
653
+ b.eventName = "ezChange";
654
+ b.field.addEventListener(b.eventName, b.eventListener);
655
+ return b;
656
+ }
657
+ }
658
+
659
+ const ezFormCss = "ez-form{display:flex;flex-direction:column;width:100%}";
660
+
661
+ const EzForm = class {
662
+ constructor(hostRef) {
663
+ registerInstance(this, hostRef);
664
+ }
665
+ submit() {
666
+ return Promise.resolve();
667
+ }
668
+ cancel() {
669
+ return Promise.resolve();
670
+ }
671
+ validate() {
672
+ return new Promise((accept, reject) => {
673
+ const metadata = selectFormMetadata(this._store.getState());
674
+ const requiredFields = this._staticFields
675
+ .filter(f => f.dataset.required)
676
+ .map(f => f.dataset.fieldName)
677
+ .concat(metadata.getRequiredFields());
678
+ const records = this.dataUnit.records;
679
+ for (let i = 0; i < records.length; i++) {
680
+ if (!this.validateRequired(requiredFields, records[i])) {
681
+ reject();
682
+ break;
683
+ }
684
+ }
685
+ accept();
686
+ });
687
+ }
688
+ configChanged() {
689
+ this.processMetadata();
690
+ }
691
+ validateRequired(requiredFields, record) {
692
+ const invalidFields = [];
693
+ requiredFields.forEach(field => {
694
+ const value = record[field];
695
+ const fieldElem = this._element.querySelector(`[data-field-name=${field}]`);
696
+ if (value === null || value === undefined || value === "") {
697
+ invalidFields.push(field);
698
+ fieldElem["errorMessage"] = "Essa informação é obrigatória";
699
+ }
700
+ else {
701
+ fieldElem["errorMessage"] = "";
702
+ }
703
+ });
704
+ const isValid = invalidFields.length === 0;
705
+ if (!isValid) {
706
+ ApplicationUtils.info("Há pelo menos um campo obrigatório não preenchido.");
707
+ }
708
+ return isValid;
709
+ }
710
+ getDynamicContent() {
711
+ var _a;
712
+ const formMD = selectFormMetadata(this._store.getState());
713
+ if (!formMD)
714
+ return null;
715
+ const currentSheet = selectCurrentSheet((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
716
+ if (!currentSheet) {
717
+ return null;
718
+ }
719
+ const allSheets = Array.from(formMD.getAllSheets().values());
720
+ const result = [];
721
+ if (allSheets.length > 1) {
722
+ result.push(h("ez-tabselector", { onEzChange: (evt) => this._store.dispatch(changeTab(evt.detail)), selectedTab: currentSheet.name }, allSheets.map(s => h("ez-tab", { tabKey: s.name, label: s.label }))));
723
+ }
724
+ result.push(h(FormSheet, { store: this._store, source: currentSheet }));
725
+ return result;
726
+ }
727
+ processMetadata() {
728
+ if (!this.isStatic()) {
729
+ const metadata = this.config && this.config.length > 0 ? buildFromConfig(this.config, this.dataUnit) : buildFromDataUnit(this.dataUnit);
730
+ this._store.dispatch(loadMetadata(metadata));
731
+ }
732
+ }
733
+ isStatic() {
734
+ var _a;
735
+ return ((_a = this._staticFields) === null || _a === void 0 ? void 0 : _a.length) > 0;
736
+ }
737
+ interceptAction(action) {
738
+ if (action.type === Action.RECORDS_COPIED) {
739
+ const metadata = selectFormMetadata(this._store.getState());
740
+ const cleanFields = metadata.getCleanOnCopyFields();
741
+ if (cleanFields) {
742
+ const records = action.payload;
743
+ return new DataUnitAction(Action.RECORDS_COPIED, records.map(record => {
744
+ const newRecord = Object.assign({}, record);
745
+ cleanFields.forEach(fieldName => delete newRecord[fieldName]);
746
+ return newRecord;
747
+ }));
748
+ }
749
+ }
750
+ return action;
751
+ }
752
+ componentWillLoad() {
753
+ if (this.dataUnit === undefined) {
754
+ this.dataUnit = new DataUnit("ez-form");
755
+ }
756
+ this.dataUnit.addInterceptor(this);
757
+ this.dataUnit.subscribe(action => {
758
+ if (action.type === Action.METADATA_LOADED) {
759
+ this.processMetadata();
760
+ }
761
+ });
762
+ this._dataBinder = new DataBinder(this.dataUnit);
763
+ this._store = createStore(formReducer);
764
+ this._store.subscribe(() => forceUpdate(this));
765
+ this._staticFields = Array.from(this._element.querySelectorAll("[data-field-name]"));
766
+ this.processMetadata();
767
+ }
768
+ componentDidRender() {
769
+ this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")));
770
+ }
771
+ render() {
772
+ return (h(Host, null, this.isStatic() ? null : this.getDynamicContent()));
773
+ }
774
+ get _element() { return getElement(this); }
775
+ static get watchers() { return {
776
+ "config": ["configChanged"]
777
+ }; }
778
+ };
779
+ EzForm.style = ezFormCss;
780
+
781
+ export { EzForm as ez_form };