@sankhyalabs/ezui 1.1.79 → 1.1.82

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 (91) hide show
  1. package/dist/cjs/ApplicationUtils-d1c1db56.js +35 -0
  2. package/dist/cjs/{AssetsUtils-02db4f46.js → AssetsUtils-caf95dab.js} +1 -1
  3. package/dist/cjs/ez-action-chip.cjs.entry.js +1 -1
  4. package/dist/cjs/ez-application.cjs.entry.js +1 -1
  5. package/dist/cjs/{ez-grid.cjs.entry.js → ez-button_11.cjs.entry.js} +1448 -22
  6. package/dist/cjs/ez-calendar.cjs.entry.js +217 -0
  7. package/dist/cjs/ez-collapsible-box_7.cjs.entry.js +853 -0
  8. package/dist/cjs/ez-combo-box.cjs.entry.js +254 -0
  9. package/dist/cjs/ez-dialog.cjs.entry.js +1 -1
  10. package/dist/cjs/ez-form.cjs.entry.js +728 -0
  11. package/dist/cjs/ez-label-chip.cjs.entry.js +1 -1
  12. package/dist/cjs/ez-popover.cjs.entry.js +2 -2
  13. package/dist/cjs/ez-popup.cjs.entry.js +1 -1
  14. package/dist/cjs/ez-time-input.cjs.entry.js +3 -3
  15. package/dist/cjs/ez-toast.cjs.entry.js +1 -1
  16. package/dist/cjs/ezui.cjs.js +2 -2
  17. package/dist/cjs/{index-2003dec4.js → index-0bce1636.js} +3 -0
  18. package/dist/cjs/{index-a2266984.js → index-d5d5a77c.js} +84 -56
  19. package/dist/cjs/loader.cjs.js +2 -2
  20. package/dist/collection/components/ez-form/DataBinder.js +7 -1
  21. package/dist/collection/components/ez-form/ez-form.js +6 -2
  22. package/dist/collection/components/ez-form/fieldbuilder/FieldBuilder.js +2 -1
  23. package/dist/collection/components/ez-form/fieldbuilder/tpl/DateInput.tpl.js +4 -0
  24. package/dist/collection/components/ez-grid/controller/DataUnitBridge.js +10 -7
  25. package/dist/collection/components/ez-grid/ez-grid.css +4 -1
  26. package/dist/collection/components/ez-grid/ez-grid.js +4 -0
  27. package/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.js +1 -1
  28. package/dist/collection/components/test-du/test-du.js +3 -27
  29. package/dist/custom-elements/index.js +106 -77
  30. package/dist/esm/ApplicationUtils-01280a9d.js +33 -0
  31. package/dist/esm/{AssetsUtils-76ca41e1.js → AssetsUtils-9b1d9c38.js} +1 -1
  32. package/dist/esm/ez-action-chip.entry.js +1 -1
  33. package/dist/esm/ez-application.entry.js +1 -1
  34. package/dist/esm/{ez-grid.entry.js → ez-button_11.entry.js} +1428 -12
  35. package/dist/esm/ez-calendar.entry.js +213 -0
  36. package/dist/esm/ez-collapsible-box_7.entry.js +843 -0
  37. package/dist/esm/ez-combo-box.entry.js +250 -0
  38. package/dist/esm/ez-dialog.entry.js +1 -1
  39. package/dist/esm/ez-form.entry.js +724 -0
  40. package/dist/esm/ez-label-chip.entry.js +1 -1
  41. package/dist/esm/ez-popover.entry.js +2 -2
  42. package/dist/esm/ez-popup.entry.js +1 -1
  43. package/dist/esm/ez-time-input.entry.js +3 -3
  44. package/dist/esm/ez-toast.entry.js +1 -1
  45. package/dist/esm/ezui.js +2 -2
  46. package/dist/esm/{index-afe19542.js → index-2bb35caf.js} +85 -57
  47. package/dist/esm/{index-077c7fcf.js → index-d80a8d1f.js} +3 -0
  48. package/dist/esm/loader.js +2 -2
  49. package/dist/ezui/ezui.esm.js +1 -1
  50. package/dist/ezui/{p-57ea4b84.entry.js → p-091b27f2.entry.js} +1 -1
  51. package/dist/ezui/{p-6d157776.entry.js → p-19d8a928.entry.js} +1 -1
  52. package/dist/ezui/{p-7a1f2e0e.entry.js → p-2bb74de5.entry.js} +1 -1
  53. package/dist/ezui/p-3749c696.js +1 -0
  54. package/dist/ezui/{p-a4a39579.entry.js → p-39218c31.entry.js} +1 -1
  55. package/dist/ezui/{p-5509ee41.entry.js → p-48eddf77.entry.js} +46 -46
  56. package/dist/ezui/p-513f2d2e.entry.js +1 -0
  57. package/dist/ezui/{p-da31cd21.entry.js → p-6206515e.entry.js} +1 -1
  58. package/dist/ezui/p-7107d7ef.js +1 -0
  59. package/dist/ezui/{p-7de3c95d.js → p-7c101b34.js} +1 -1
  60. package/dist/ezui/{p-920bb8c9.entry.js → p-a52b3368.entry.js} +1 -1
  61. package/dist/ezui/{p-0a2056d9.entry.js → p-b678dc80.entry.js} +1 -1
  62. package/dist/ezui/p-c151c043.entry.js +1 -0
  63. package/dist/ezui/p-da6ac011.entry.js +1 -0
  64. package/dist/ezui/p-e346a7ff.entry.js +1 -0
  65. package/dist/ezui/{p-857ead8e.entry.js → p-ec261c08.entry.js} +1 -1
  66. package/dist/ezui/p-f87c7082.js +1 -0
  67. package/dist/types/components/ez-form/ez-form.d.ts +1 -0
  68. package/dist/types/components/ez-form/fieldbuilder/tpl/DateInput.tpl.d.ts +4 -0
  69. package/dist/types/components/ez-grid/controller/DataUnitBridge.d.ts +2 -1
  70. package/dist/types/components/test-du/test-du.d.ts +0 -6
  71. package/package.json +2 -2
  72. package/dist/cjs/DateUtils-716769e0.js +0 -46
  73. package/dist/cjs/ez-button_3.cjs.entry.js +0 -520
  74. package/dist/cjs/ez-calendar_13.cjs.entry.js +0 -2417
  75. package/dist/cjs/ez-date-time-input.cjs.entry.js +0 -133
  76. package/dist/cjs/ez-icon.cjs.entry.js +0 -30
  77. package/dist/cjs/ez-modal_2.cjs.entry.js +0 -370
  78. package/dist/esm/DateUtils-0a1bbd7a.js +0 -44
  79. package/dist/esm/ez-button_3.entry.js +0 -514
  80. package/dist/esm/ez-calendar_13.entry.js +0 -2401
  81. package/dist/esm/ez-date-time-input.entry.js +0 -129
  82. package/dist/esm/ez-icon.entry.js +0 -26
  83. package/dist/esm/ez-modal_2.entry.js +0 -365
  84. package/dist/ezui/p-00b837e2.js +0 -1
  85. package/dist/ezui/p-0d8368fc.entry.js +0 -1
  86. package/dist/ezui/p-1e36e3ff.entry.js +0 -1
  87. package/dist/ezui/p-446ec85b.js +0 -1
  88. package/dist/ezui/p-9be02ecf.entry.js +0 -1
  89. package/dist/ezui/p-c89629eb.js +0 -1
  90. package/dist/ezui/p-d5699f29.entry.js +0 -1
  91. package/dist/ezui/p-d64a3939.entry.js +0 -1
@@ -0,0 +1,724 @@
1
+ import { h, r as registerInstance, f as forceUpdate, H as Host, g as getElement } from './index-d80a8d1f.js';
2
+ import { U as UserInterface, D as DataUnit, A as Action } from './index-2bb35caf.js';
3
+ import { A as ApplicationUtils } from './ApplicationUtils-01280a9d.js';
4
+
5
+ const buildTextArea = ({ name, label }) => {
6
+ return (h("div", { class: "col col--sd-12 padding--small", key: name },
7
+ h("ez-text-area", { 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--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, true);
17
+ };
18
+ const buildCheckBox = (fieldConfig) => {
19
+ return buildField$1(fieldConfig.name, fieldConfig.label, false);
20
+ };
21
+ function buildField$1(fieldName, fieldLabel, switchMode = false) {
22
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding--small align--middle padding-bottom--large" },
23
+ h("ez-check", { label: fieldLabel, mode: switchMode ? "switch" : "regular", "data-field-name": fieldName, key: fieldName })));
24
+ }
25
+
26
+ const buildComboBox = ({ name, label }, 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--small" },
37
+ h("ez-combo-box", { label: label, "data-field-name": name, key: name, options: options })));
38
+ };
39
+
40
+ const buildSearch = ({ name, label }) => {
41
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding--small" },
42
+ h("ez-search", { label: label, optionLoader: (_argument) => { }, "data-field-name": name, key: name })));
43
+ };
44
+
45
+ const buildFile = ({ name, label }) => {
46
+ return (h("div", { class: "col col--sd-12 padding--small" },
47
+ h("ez-upload", { label: label, urlUpload: "", requestHeaders: "", maxFiles: 10, "data-field-name": name, key: name })));
48
+ };
49
+
50
+ const buildDate = ({ name, label }) => {
51
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding--small" },
52
+ h("ez-date-input", { label: label, "data-field-name": name, key: name })));
53
+ };
54
+ const buildTimeDate = ({ name, label }) => {
55
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding--small" },
56
+ h("ez-date-time-input", { label: label, "data-field-name": name, key: name })));
57
+ };
58
+
59
+ const buildDecimal = ({ name, label }, properties) => {
60
+ const precision = Number((properties === null || properties === void 0 ? void 0 : properties.precision) || 2);
61
+ const prettyPrecision = Number((properties === null || properties === void 0 ? void 0 : properties.prettyPrecision) || precision);
62
+ return buildNumeric(name, label, precision, prettyPrecision);
63
+ };
64
+ const buildInteger = ({ name, label }) => {
65
+ return buildNumeric(name, label, 0, 0);
66
+ };
67
+ function buildNumeric(fieldName, fieldLabel, precision, prettyPrecision) {
68
+ return (h("div", { class: "col col--sd-12 col--tb-3 padding--small" },
69
+ h("ez-number-input", { label: fieldLabel, precision: precision, prettyPrecision: prettyPrecision, "data-field-name": fieldName, key: fieldName })));
70
+ }
71
+
72
+ const uiBuilders = new Map();
73
+ uiBuilders.set(UserInterface.LONGTEXT, buildTextArea);
74
+ uiBuilders.set(UserInterface.CHECKBOX, buildCheckBox);
75
+ uiBuilders.set(UserInterface.SWITCH, buildSwitch);
76
+ uiBuilders.set(UserInterface.OPTIONSELECTOR, buildComboBox);
77
+ uiBuilders.set(UserInterface.SEARCH, buildSearch);
78
+ uiBuilders.set(UserInterface.FILE, buildFile);
79
+ uiBuilders.set(UserInterface.DATE, buildDate);
80
+ uiBuilders.set(UserInterface.DATETIME, buildTimeDate);
81
+ uiBuilders.set(UserInterface.DECIMALNUMBER, buildDecimal);
82
+ uiBuilders.set(UserInterface.INTEGERNUMBER, buildInteger);
83
+ const buildField = (field) => {
84
+ const descriptor = field.descriptor;
85
+ const config = Object.assign({}, field.config);
86
+ let builder;
87
+ let props;
88
+ if (descriptor) {
89
+ builder = uiBuilders.get(descriptor.userInterface);
90
+ if (!config.label) {
91
+ config.label = descriptor.label;
92
+ }
93
+ if (!config.name) {
94
+ config.name = descriptor.name;
95
+ }
96
+ if (config.required === undefined) {
97
+ config.required = descriptor.required;
98
+ }
99
+ props = descriptor.properties;
100
+ }
101
+ if (config.required) {
102
+ config.label = `* ${config.label} (obrigatório)`;
103
+ }
104
+ if (!builder) {
105
+ builder = buildTextInput;
106
+ }
107
+ return builder(config, props);
108
+ };
109
+
110
+ const FormItem = ({ source }) => {
111
+ if ("items" in source) {
112
+ const fieldSet = source;
113
+ return h("ez-collapsible-box", { label: source.label }, fieldSet.items.map(fi => buildField(fi)));
114
+ }
115
+ else {
116
+ return buildField(source);
117
+ }
118
+ };
119
+
120
+ const FormSheet = ({ store, source }) => {
121
+ return (h("div", { class: "box__container" }, source.items.map(item => h(FormItem, { store: store, source: item }))));
122
+ };
123
+
124
+ class FormMetadata {
125
+ constructor() {
126
+ this._sheets = new Map();
127
+ this._requiredFields = [];
128
+ }
129
+ getSheet(name) {
130
+ return this._sheets.get(name);
131
+ }
132
+ getAllSheets() {
133
+ return this._sheets;
134
+ }
135
+ addSheet(sheet) {
136
+ this._sheets.set(sheet.name, sheet);
137
+ this._requiredFields = this._requiredFields.concat(sheet.requiredFields);
138
+ }
139
+ getRequiredFields() {
140
+ return this._requiredFields;
141
+ }
142
+ }
143
+ const buildFromDataUnit = (dataUnit) => {
144
+ var _a;
145
+ const unitMD = dataUnit.metadata;
146
+ const metadata = new FormMetadata();
147
+ if (unitMD) {
148
+ const visibleFields = (_a = unitMD.fields) === null || _a === void 0 ? void 0 : _a.filter(descriptor => descriptor.visible !== false);
149
+ metadata.addSheet({
150
+ label: unitMD.label,
151
+ name: unitMD.name,
152
+ items: visibleFields.map(descriptor => { return { descriptor }; }),
153
+ requiredFields: visibleFields
154
+ .filter(descriptor => descriptor.required)
155
+ .map(descriptor => descriptor.name)
156
+ });
157
+ }
158
+ return metadata;
159
+ };
160
+ const buildFromConfig = (fields, dataUnit) => {
161
+ const sheets = new Map();
162
+ const requiredFields = [];
163
+ fields.forEach(config => {
164
+ if (config.visible !== false) {
165
+ const tab = config.tab || "Geral";
166
+ const descriptor = dataUnit.getField(config.name);
167
+ if (!sheets.has(tab)) {
168
+ sheets.set(tab, new Map());
169
+ }
170
+ let isRequired = false;
171
+ if (config.required === undefined) {
172
+ if (descriptor) {
173
+ isRequired = descriptor.required;
174
+ }
175
+ }
176
+ else {
177
+ isRequired = config.required;
178
+ }
179
+ if (isRequired) {
180
+ requiredFields.push(config.name);
181
+ }
182
+ const tabItens = sheets.get(tab);
183
+ const fieldMD = { config, descriptor };
184
+ const group = config.group;
185
+ if (group) {
186
+ const key = `group::${group}`;
187
+ if (!tabItens.has(key)) {
188
+ tabItens.set(key, { label: group, items: [fieldMD] });
189
+ }
190
+ else {
191
+ tabItens.get(key).items.push(fieldMD);
192
+ }
193
+ }
194
+ else {
195
+ tabItens.set(config.name, fieldMD);
196
+ }
197
+ }
198
+ });
199
+ const metadata = new FormMetadata();
200
+ sheets.forEach((value, key) => {
201
+ metadata.addSheet({
202
+ label: key,
203
+ name: key,
204
+ items: Array.from(value.values()),
205
+ requiredFields
206
+ });
207
+ });
208
+ return metadata;
209
+ };
210
+
211
+ /**
212
+ * Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
213
+ *
214
+ * Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
215
+ * during build.
216
+ * @param {number} code
217
+ */
218
+ function formatProdErrorMessage(code) {
219
+ 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. ';
220
+ }
221
+
222
+ // Inlined version of the `symbol-observable` polyfill
223
+ var $$observable = (function () {
224
+ return typeof Symbol === 'function' && Symbol.observable || '@@observable';
225
+ })();
226
+
227
+ /**
228
+ * These are private action types reserved by Redux.
229
+ * For any unknown actions, you must return the current state.
230
+ * If the current state is undefined, you must return the initial state.
231
+ * Do not reference these action types directly in your code.
232
+ */
233
+ var randomString = function randomString() {
234
+ return Math.random().toString(36).substring(7).split('').join('.');
235
+ };
236
+
237
+ var ActionTypes = {
238
+ INIT: "@@redux/INIT" + randomString(),
239
+ REPLACE: "@@redux/REPLACE" + randomString(),
240
+ PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
241
+ return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
242
+ }
243
+ };
244
+
245
+ /**
246
+ * @param {any} obj The object to inspect.
247
+ * @returns {boolean} True if the argument appears to be a plain object.
248
+ */
249
+ function isPlainObject(obj) {
250
+ if (typeof obj !== 'object' || obj === null) return false;
251
+ var proto = obj;
252
+
253
+ while (Object.getPrototypeOf(proto) !== null) {
254
+ proto = Object.getPrototypeOf(proto);
255
+ }
256
+
257
+ return Object.getPrototypeOf(obj) === proto;
258
+ }
259
+
260
+ /**
261
+ * Creates a Redux store that holds the state tree.
262
+ * The only way to change the data in the store is to call `dispatch()` on it.
263
+ *
264
+ * There should only be a single store in your app. To specify how different
265
+ * parts of the state tree respond to actions, you may combine several reducers
266
+ * into a single reducer function by using `combineReducers`.
267
+ *
268
+ * @param {Function} reducer A function that returns the next state tree, given
269
+ * the current state tree and the action to handle.
270
+ *
271
+ * @param {any} [preloadedState] The initial state. You may optionally specify it
272
+ * to hydrate the state from the server in universal apps, or to restore a
273
+ * previously serialized user session.
274
+ * If you use `combineReducers` to produce the root reducer function, this must be
275
+ * an object with the same shape as `combineReducers` keys.
276
+ *
277
+ * @param {Function} [enhancer] The store enhancer. You may optionally specify it
278
+ * to enhance the store with third-party capabilities such as middleware,
279
+ * time travel, persistence, etc. The only store enhancer that ships with Redux
280
+ * is `applyMiddleware()`.
281
+ *
282
+ * @returns {Store} A Redux store that lets you read the state, dispatch actions
283
+ * and subscribe to changes.
284
+ */
285
+
286
+ function createStore(reducer, preloadedState, enhancer) {
287
+ var _ref2;
288
+
289
+ if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
290
+ throw new Error(formatProdErrorMessage(0) );
291
+ }
292
+
293
+ if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
294
+ enhancer = preloadedState;
295
+ preloadedState = undefined;
296
+ }
297
+
298
+ if (typeof enhancer !== 'undefined') {
299
+ if (typeof enhancer !== 'function') {
300
+ throw new Error(formatProdErrorMessage(1) );
301
+ }
302
+
303
+ return enhancer(createStore)(reducer, preloadedState);
304
+ }
305
+
306
+ if (typeof reducer !== 'function') {
307
+ throw new Error(formatProdErrorMessage(2) );
308
+ }
309
+
310
+ var currentReducer = reducer;
311
+ var currentState = preloadedState;
312
+ var currentListeners = [];
313
+ var nextListeners = currentListeners;
314
+ var isDispatching = false;
315
+ /**
316
+ * This makes a shallow copy of currentListeners so we can use
317
+ * nextListeners as a temporary list while dispatching.
318
+ *
319
+ * This prevents any bugs around consumers calling
320
+ * subscribe/unsubscribe in the middle of a dispatch.
321
+ */
322
+
323
+ function ensureCanMutateNextListeners() {
324
+ if (nextListeners === currentListeners) {
325
+ nextListeners = currentListeners.slice();
326
+ }
327
+ }
328
+ /**
329
+ * Reads the state tree managed by the store.
330
+ *
331
+ * @returns {any} The current state tree of your application.
332
+ */
333
+
334
+
335
+ function getState() {
336
+ if (isDispatching) {
337
+ throw new Error(formatProdErrorMessage(3) );
338
+ }
339
+
340
+ return currentState;
341
+ }
342
+ /**
343
+ * Adds a change listener. It will be called any time an action is dispatched,
344
+ * and some part of the state tree may potentially have changed. You may then
345
+ * call `getState()` to read the current state tree inside the callback.
346
+ *
347
+ * You may call `dispatch()` from a change listener, with the following
348
+ * caveats:
349
+ *
350
+ * 1. The subscriptions are snapshotted just before every `dispatch()` call.
351
+ * If you subscribe or unsubscribe while the listeners are being invoked, this
352
+ * will not have any effect on the `dispatch()` that is currently in progress.
353
+ * However, the next `dispatch()` call, whether nested or not, will use a more
354
+ * recent snapshot of the subscription list.
355
+ *
356
+ * 2. The listener should not expect to see all state changes, as the state
357
+ * might have been updated multiple times during a nested `dispatch()` before
358
+ * the listener is called. It is, however, guaranteed that all subscribers
359
+ * registered before the `dispatch()` started will be called with the latest
360
+ * state by the time it exits.
361
+ *
362
+ * @param {Function} listener A callback to be invoked on every dispatch.
363
+ * @returns {Function} A function to remove this change listener.
364
+ */
365
+
366
+
367
+ function subscribe(listener) {
368
+ if (typeof listener !== 'function') {
369
+ throw new Error(formatProdErrorMessage(4) );
370
+ }
371
+
372
+ if (isDispatching) {
373
+ throw new Error(formatProdErrorMessage(5) );
374
+ }
375
+
376
+ var isSubscribed = true;
377
+ ensureCanMutateNextListeners();
378
+ nextListeners.push(listener);
379
+ return function unsubscribe() {
380
+ if (!isSubscribed) {
381
+ return;
382
+ }
383
+
384
+ if (isDispatching) {
385
+ throw new Error(formatProdErrorMessage(6) );
386
+ }
387
+
388
+ isSubscribed = false;
389
+ ensureCanMutateNextListeners();
390
+ var index = nextListeners.indexOf(listener);
391
+ nextListeners.splice(index, 1);
392
+ currentListeners = null;
393
+ };
394
+ }
395
+ /**
396
+ * Dispatches an action. It is the only way to trigger a state change.
397
+ *
398
+ * The `reducer` function, used to create the store, will be called with the
399
+ * current state tree and the given `action`. Its return value will
400
+ * be considered the **next** state of the tree, and the change listeners
401
+ * will be notified.
402
+ *
403
+ * The base implementation only supports plain object actions. If you want to
404
+ * dispatch a Promise, an Observable, a thunk, or something else, you need to
405
+ * wrap your store creating function into the corresponding middleware. For
406
+ * example, see the documentation for the `redux-thunk` package. Even the
407
+ * middleware will eventually dispatch plain object actions using this method.
408
+ *
409
+ * @param {Object} action A plain object representing “what changed”. It is
410
+ * a good idea to keep actions serializable so you can record and replay user
411
+ * sessions, or use the time travelling `redux-devtools`. An action must have
412
+ * a `type` property which may not be `undefined`. It is a good idea to use
413
+ * string constants for action types.
414
+ *
415
+ * @returns {Object} For convenience, the same action object you dispatched.
416
+ *
417
+ * Note that, if you use a custom middleware, it may wrap `dispatch()` to
418
+ * return something else (for example, a Promise you can await).
419
+ */
420
+
421
+
422
+ function dispatch(action) {
423
+ if (!isPlainObject(action)) {
424
+ throw new Error(formatProdErrorMessage(7) );
425
+ }
426
+
427
+ if (typeof action.type === 'undefined') {
428
+ throw new Error(formatProdErrorMessage(8) );
429
+ }
430
+
431
+ if (isDispatching) {
432
+ throw new Error(formatProdErrorMessage(9) );
433
+ }
434
+
435
+ try {
436
+ isDispatching = true;
437
+ currentState = currentReducer(currentState, action);
438
+ } finally {
439
+ isDispatching = false;
440
+ }
441
+
442
+ var listeners = currentListeners = nextListeners;
443
+
444
+ for (var i = 0; i < listeners.length; i++) {
445
+ var listener = listeners[i];
446
+ listener();
447
+ }
448
+
449
+ return action;
450
+ }
451
+ /**
452
+ * Replaces the reducer currently used by the store to calculate the state.
453
+ *
454
+ * You might need this if your app implements code splitting and you want to
455
+ * load some of the reducers dynamically. You might also need this if you
456
+ * implement a hot reloading mechanism for Redux.
457
+ *
458
+ * @param {Function} nextReducer The reducer for the store to use instead.
459
+ * @returns {void}
460
+ */
461
+
462
+
463
+ function replaceReducer(nextReducer) {
464
+ if (typeof nextReducer !== 'function') {
465
+ throw new Error(formatProdErrorMessage(10) );
466
+ }
467
+
468
+ currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
469
+ // Any reducers that existed in both the new and old rootReducer
470
+ // will receive the previous state. This effectively populates
471
+ // the new state tree with any relevant data from the old one.
472
+
473
+ dispatch({
474
+ type: ActionTypes.REPLACE
475
+ });
476
+ }
477
+ /**
478
+ * Interoperability point for observable/reactive libraries.
479
+ * @returns {observable} A minimal observable of state changes.
480
+ * For more information, see the observable proposal:
481
+ * https://github.com/tc39/proposal-observable
482
+ */
483
+
484
+
485
+ function observable() {
486
+ var _ref;
487
+
488
+ var outerSubscribe = subscribe;
489
+ return _ref = {
490
+ /**
491
+ * The minimal observable subscription method.
492
+ * @param {Object} observer Any object that can be used as an observer.
493
+ * The observer object should have a `next` method.
494
+ * @returns {subscription} An object with an `unsubscribe` method that can
495
+ * be used to unsubscribe the observable from the store, and prevent further
496
+ * emission of values from the observable.
497
+ */
498
+ subscribe: function subscribe(observer) {
499
+ if (typeof observer !== 'object' || observer === null) {
500
+ throw new Error(formatProdErrorMessage(11) );
501
+ }
502
+
503
+ function observeState() {
504
+ if (observer.next) {
505
+ observer.next(getState());
506
+ }
507
+ }
508
+
509
+ observeState();
510
+ var unsubscribe = outerSubscribe(observeState);
511
+ return {
512
+ unsubscribe: unsubscribe
513
+ };
514
+ }
515
+ }, _ref[$$observable] = function () {
516
+ return this;
517
+ }, _ref;
518
+ } // When a store is created, an "INIT" action is dispatched so that every
519
+ // reducer returns their initial state. This effectively populates
520
+ // the initial state tree.
521
+
522
+
523
+ dispatch({
524
+ type: ActionTypes.INIT
525
+ });
526
+ return _ref2 = {
527
+ dispatch: dispatch,
528
+ subscribe: subscribe,
529
+ getState: getState,
530
+ replaceReducer: replaceReducer
531
+ }, _ref2[$$observable] = observable, _ref2;
532
+ }
533
+
534
+ const inicialState = {};
535
+ /////////////////////////////// REDUCERS ///////////////////////////////
536
+ function formReducer(state = inicialState, action) {
537
+ switch (action.type) {
538
+ case FormActions.METADATA_LOADED:
539
+ return Object.assign(Object.assign({}, state), { formMetadata: action.payload });
540
+ case FormActions.CHANGE_TAB:
541
+ return Object.assign(Object.assign({}, state), { currentSheet: action.payload });
542
+ default:
543
+ return state;
544
+ }
545
+ }
546
+ /////////////////////////////// ACTION CREATORS ///////////////////////////////
547
+ function loadMetadata(formMetadata) {
548
+ return {
549
+ type: FormActions.METADATA_LOADED,
550
+ payload: formMetadata
551
+ };
552
+ }
553
+ function changeTab(currentSheet) {
554
+ return {
555
+ type: FormActions.CHANGE_TAB,
556
+ payload: currentSheet
557
+ };
558
+ }
559
+ /////////////////////////////// SELECTORS ///////////////////////////////
560
+ function selectFormMetadata(state) {
561
+ return state.formMetadata;
562
+ }
563
+ function selectCurrentSheet(state) {
564
+ return state.currentSheet ? state.formMetadata.getSheet(state.currentSheet) : Array.from(state.formMetadata.getAllSheets().values())[0];
565
+ }
566
+ /////////////////////////////// TYPES ///////////////////////////////
567
+ var FormActions;
568
+ (function (FormActions) {
569
+ FormActions["METADATA_LOADED"] = "FORM/METADATA_LOADED";
570
+ FormActions["CHANGE_TAB"] = "FORM/CHANGE_TAB";
571
+ })(FormActions || (FormActions = {}));
572
+
573
+ class DataBinder {
574
+ constructor(dataUnit) {
575
+ this._fields = new Map();
576
+ this._dataUnit = dataUnit;
577
+ this._dataUnit.subscribe(_action => {
578
+ var _a;
579
+ (_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
580
+ this.updateValue(field.fieldName, field.field);
581
+ });
582
+ });
583
+ }
584
+ bind(fields) {
585
+ fields.forEach(fieldElement => {
586
+ const fieldName = fieldElement.dataset.fieldName;
587
+ this.updateBind(fieldName, fieldElement);
588
+ this.updateValue(fieldName, fieldElement);
589
+ });
590
+ }
591
+ updateValue(fieldName, field) {
592
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
593
+ }
594
+ updateBind(fieldName, field) {
595
+ const oldBind = this._fields.get(fieldName);
596
+ if (oldBind) {
597
+ oldBind.destroy();
598
+ }
599
+ this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
600
+ }
601
+ setFieldValue(fieldName, newValue) {
602
+ if (this._dataUnit.records.length === 0) {
603
+ this._dataUnit.addRecord();
604
+ }
605
+ this._dataUnit.setFieldValue(fieldName, newValue);
606
+ }
607
+ }
608
+ class Bind {
609
+ destroy() {
610
+ this.field.removeEventListener(this.eventName, this.eventListener);
611
+ }
612
+ static create(fieldName, field, callback) {
613
+ const b = new Bind();
614
+ b.fieldName = fieldName;
615
+ b.field = field;
616
+ //FIXME: Verificar se o field é um EzField
617
+ b.eventListener = (evt) => { callback(fieldName, evt.detail); };
618
+ b.eventName = "ezChange";
619
+ b.field.addEventListener(b.eventName, b.eventListener);
620
+ return b;
621
+ }
622
+ }
623
+
624
+ const ezFormCss = "ez-form{display:flex;flex-direction:column;width:100%}";
625
+
626
+ let EzForm = class {
627
+ constructor(hostRef) {
628
+ registerInstance(this, hostRef);
629
+ }
630
+ submit() {
631
+ return Promise.resolve();
632
+ }
633
+ cancel() {
634
+ return Promise.resolve();
635
+ }
636
+ validate() {
637
+ return new Promise((accept, reject) => {
638
+ const metadata = selectFormMetadata(this._store.getState());
639
+ const requiredFields = this._staticFields
640
+ .filter(f => f.dataset.required)
641
+ .map(f => f.dataset.fieldName)
642
+ .concat(metadata.getRequiredFields());
643
+ const records = this.dataUnit.records;
644
+ for (let i = 0; i < records.length; i++) {
645
+ if (!this.validateRequired(requiredFields, records[i])) {
646
+ reject();
647
+ break;
648
+ }
649
+ }
650
+ accept();
651
+ });
652
+ }
653
+ validateRequired(requiredFields, record) {
654
+ const invalidFields = [];
655
+ requiredFields.forEach(field => {
656
+ const value = record[field];
657
+ const fieldElem = this._element.querySelector(`[data-field-name=${field}]`);
658
+ if (value === null || value === undefined || value === "") {
659
+ invalidFields.push(field);
660
+ fieldElem["errorMessage"] = "Essa informação é obrigatória";
661
+ }
662
+ else {
663
+ fieldElem["errorMessage"] = "";
664
+ }
665
+ });
666
+ const isValid = invalidFields.length === 0;
667
+ if (!isValid) {
668
+ ApplicationUtils.info("Há pelo menos um campo obrigatório não preenchido.");
669
+ }
670
+ return isValid;
671
+ }
672
+ getDynamicContent() {
673
+ var _a;
674
+ const formMD = selectFormMetadata(this._store.getState());
675
+ if (!formMD)
676
+ return null;
677
+ const currentSheet = selectCurrentSheet((_a = this._store) === null || _a === void 0 ? void 0 : _a.getState());
678
+ if (!currentSheet) {
679
+ return null;
680
+ }
681
+ const allSheets = Array.from(formMD.getAllSheets().values());
682
+ const result = [];
683
+ if (allSheets.length > 1) {
684
+ 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 }))));
685
+ }
686
+ result.push(h(FormSheet, { store: this._store, source: currentSheet }));
687
+ return result;
688
+ }
689
+ processMetadata() {
690
+ if (!this.isStatic()) {
691
+ const metadata = this.config && this.config.length > 0 ? buildFromConfig(this.config, this.dataUnit) : buildFromDataUnit(this.dataUnit);
692
+ this._store.dispatch(loadMetadata(metadata));
693
+ }
694
+ }
695
+ isStatic() {
696
+ var _a;
697
+ return ((_a = this._staticFields) === null || _a === void 0 ? void 0 : _a.length) > 0;
698
+ }
699
+ componentWillLoad() {
700
+ if (this.dataUnit === undefined) {
701
+ this.dataUnit = new DataUnit("ez-form");
702
+ }
703
+ this.dataUnit.subscribe(action => {
704
+ if (action.type === Action.METADATA_LOADED) {
705
+ this.processMetadata();
706
+ }
707
+ });
708
+ this._dataBinder = new DataBinder(this.dataUnit);
709
+ this._store = createStore(formReducer);
710
+ this._store.subscribe(() => forceUpdate(this));
711
+ this._staticFields = Array.from(this._element.querySelectorAll("[data-field-name]"));
712
+ this.processMetadata();
713
+ }
714
+ componentDidRender() {
715
+ this._dataBinder.bind(Array.from(this._element.querySelectorAll("[data-field-name]")));
716
+ }
717
+ render() {
718
+ return (h(Host, null, this.isStatic() ? null : this.getDynamicContent()));
719
+ }
720
+ get _element() { return getElement(this); }
721
+ };
722
+ EzForm.style = ezFormCss;
723
+
724
+ export { EzForm as ez_form };