@sankhyalabs/ezui 1.1.92 → 1.1.95

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