@sankhyalabs/ezui 0.0.0-bugfix-dev-KB-75609.0 → 0.0.0-bugfix-dev-KB-75609.1

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 (105) hide show
  1. package/dist/cjs/DataBinder-aff1dcc7.js +445 -0
  2. package/dist/cjs/FocusResolver-885f2173.js +35 -0
  3. package/dist/cjs/ez-card-item_3.cjs.entry.js +8 -2
  4. package/dist/cjs/ez-combo-box.cjs.entry.js +46 -10
  5. package/dist/cjs/ez-date-input.cjs.entry.js +8 -2
  6. package/dist/cjs/ez-date-time-input.cjs.entry.js +8 -2
  7. package/dist/cjs/ez-dialog.cjs.entry.js +9 -1
  8. package/dist/cjs/ez-form.cjs.entry.js +3 -324
  9. package/dist/cjs/ez-grid.cjs.entry.js +254 -62
  10. package/dist/cjs/ez-number-input.cjs.entry.js +7 -0
  11. package/dist/cjs/ez-search.cjs.entry.js +27 -11
  12. package/dist/cjs/ez-text-area.cjs.entry.js +6 -0
  13. package/dist/cjs/ez-text-input.cjs.entry.js +7 -1
  14. package/dist/cjs/ez-time-input.cjs.entry.js +6 -0
  15. package/dist/cjs/ezui.cjs.js +1 -1
  16. package/dist/cjs/loader.cjs.js +1 -1
  17. package/dist/collection/collection-manifest.json +1 -1
  18. package/dist/collection/components/ez-combo-box/ez-combo-box.js +75 -14
  19. package/dist/collection/components/ez-date-input/ez-date-input.js +35 -4
  20. package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +35 -4
  21. package/dist/collection/components/ez-dialog/ez-dialog.js +9 -1
  22. package/dist/collection/components/ez-filter-input/ez-filter-input.js +35 -4
  23. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +52 -14
  24. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +3 -0
  25. package/dist/collection/components/ez-grid/controller/ag-grid/GridEditionManager.js +166 -45
  26. package/dist/collection/components/ez-grid/controller/ag-grid/components/EzGridCustomCellEditor.js +7 -0
  27. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/ComboBox.tpl.js +1 -0
  28. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/DateInput.tpl.js +1 -0
  29. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/NumberInput.tpl.js +1 -0
  30. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/Search.tpl.js +1 -0
  31. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/TextInput.tpl.js +4 -1
  32. package/dist/collection/components/ez-grid/ez-grid.js +83 -1
  33. package/dist/collection/components/ez-number-input/ez-number-input.js +25 -0
  34. package/dist/collection/components/ez-search/ez-search.js +54 -13
  35. package/dist/collection/components/ez-text-area/ez-text-area.js +24 -0
  36. package/dist/collection/components/ez-text-input/ez-text-input.css +14 -38
  37. package/dist/collection/components/ez-text-input/ez-text-input.js +24 -0
  38. package/dist/collection/components/ez-time-input/ez-time-input.js +24 -0
  39. package/dist/collection/utils/FocusResolver.js +31 -0
  40. package/dist/collection/utils/form/DataBinder.js +18 -3
  41. package/dist/custom-elements/index.js +442 -102
  42. package/dist/esm/DataBinder-bd240826.js +441 -0
  43. package/dist/esm/FocusResolver-1ccbf850.js +33 -0
  44. package/dist/esm/ez-card-item_3.entry.js +8 -2
  45. package/dist/esm/ez-combo-box.entry.js +47 -11
  46. package/dist/esm/ez-date-input.entry.js +8 -2
  47. package/dist/esm/ez-date-time-input.entry.js +8 -2
  48. package/dist/esm/ez-dialog.entry.js +9 -1
  49. package/dist/esm/ez-form.entry.js +2 -323
  50. package/dist/esm/ez-grid.entry.js +253 -61
  51. package/dist/esm/ez-number-input.entry.js +7 -0
  52. package/dist/esm/ez-search.entry.js +27 -11
  53. package/dist/esm/ez-text-area.entry.js +6 -0
  54. package/dist/esm/ez-text-input.entry.js +7 -1
  55. package/dist/esm/ez-time-input.entry.js +6 -0
  56. package/dist/esm/ezui.js +1 -1
  57. package/dist/esm/loader.js +1 -1
  58. package/dist/ezui/ezui.esm.js +1 -1
  59. package/dist/ezui/p-03a2c7d1.entry.js +1 -0
  60. package/dist/ezui/p-0a75bb05.entry.js +1 -0
  61. package/dist/ezui/{p-37219d42.entry.js → p-0db68715.entry.js} +1 -1
  62. package/dist/ezui/p-19098a3f.entry.js +1 -0
  63. package/dist/ezui/p-1f830a2f.entry.js +1 -0
  64. package/dist/ezui/p-3dd919b7.entry.js +1 -0
  65. package/dist/ezui/p-7bfae0fc.entry.js +1 -0
  66. package/dist/ezui/p-81f06699.js +1 -0
  67. package/dist/ezui/p-97af4b13.entry.js +1 -0
  68. package/dist/ezui/p-9ceefe4d.entry.js +1 -0
  69. package/dist/ezui/{p-c3c3d640.entry.js → p-b0a5c2cd.entry.js} +2 -2
  70. package/dist/ezui/p-d0ca26fe.entry.js +1 -0
  71. package/dist/ezui/p-dc628ed3.js +1 -0
  72. package/dist/ezui/p-ffd246f5.entry.js +1 -0
  73. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +7 -1
  74. package/dist/types/components/ez-date-input/ez-date-input.d.ts +6 -1
  75. package/dist/types/components/ez-date-time-input/ez-date-time-input.d.ts +6 -1
  76. package/dist/types/components/ez-dialog/ez-dialog.d.ts +2 -0
  77. package/dist/types/components/ez-filter-input/ez-filter-input.d.ts +6 -1
  78. package/dist/types/components/ez-grid/controller/EzGridController.d.ts +10 -0
  79. package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +4 -0
  80. package/dist/types/components/ez-grid/controller/ag-grid/GridEditionManager.d.ts +18 -6
  81. package/dist/types/components/ez-grid/controller/ag-grid/components/EzGridCustomCellEditor.d.ts +2 -0
  82. package/dist/types/components/ez-grid/controller/ag-grid/editor/IUICellEditor.d.ts +1 -0
  83. package/dist/types/components/ez-grid/ez-grid.d.ts +10 -0
  84. package/dist/types/components/ez-number-input/ez-number-input.d.ts +4 -0
  85. package/dist/types/components/ez-search/ez-search.d.ts +6 -1
  86. package/dist/types/components/ez-text-area/ez-text-area.d.ts +4 -0
  87. package/dist/types/components/ez-text-input/ez-text-input.d.ts +4 -0
  88. package/dist/types/components/ez-time-input/ez-time-input.d.ts +4 -0
  89. package/dist/types/components.d.ts +91 -6
  90. package/dist/types/utils/FocusResolver.d.ts +5 -0
  91. package/dist/types/utils/form/DataBinder.d.ts +3 -0
  92. package/package.json +1 -1
  93. package/dist/cjs/RecordValidationProcessor-10846595.js +0 -108
  94. package/dist/esm/RecordValidationProcessor-9c6cc267.js +0 -105
  95. package/dist/ezui/p-0f3b2e67.entry.js +0 -1
  96. package/dist/ezui/p-49456b34.entry.js +0 -1
  97. package/dist/ezui/p-5a90d7d1.entry.js +0 -1
  98. package/dist/ezui/p-62732269.entry.js +0 -1
  99. package/dist/ezui/p-b95632e8.entry.js +0 -1
  100. package/dist/ezui/p-c25f0e92.entry.js +0 -1
  101. package/dist/ezui/p-d2c06f38.entry.js +0 -1
  102. package/dist/ezui/p-e85c48d7.entry.js +0 -1
  103. package/dist/ezui/p-f0e2ce9d.entry.js +0 -1
  104. package/dist/ezui/p-f299c608.entry.js +0 -1
  105. package/dist/ezui/p-f42855b9.js +0 -1
@@ -0,0 +1,441 @@
1
+ import { UserInterface, Action, StringUtils, ApplicationContext, WaitingChangeException, DataUnitAction } from '@sankhyalabs/core';
2
+ import { A as ApplicationUtils } from './ApplicationUtils-eaf91331.js';
3
+
4
+ const buildFieldMetadata = (descriptor, config) => {
5
+ let { name, label, group } = Object.assign({}, config);
6
+ let { readOnly, required } = Object.assign({}, config);
7
+ let props;
8
+ let userInterface;
9
+ if (descriptor) {
10
+ label = label || descriptor.label;
11
+ name = name || descriptor.name;
12
+ required = descriptor.required || (config === null || config === void 0 ? void 0 : config.required);
13
+ readOnly = descriptor.readOnly || (config === null || config === void 0 ? void 0 : config.readOnly);
14
+ props = descriptor.properties;
15
+ userInterface = descriptor.userInterface;
16
+ }
17
+ return {
18
+ name, label, group,
19
+ readOnly, required,
20
+ props,
21
+ userInterface: userInterface || UserInterface.SHORTTEXT
22
+ };
23
+ };
24
+
25
+ class RecordValidationProcessor {
26
+ constructor(dataUnit, validationSource, validator) {
27
+ this._dataUnit = dataUnit;
28
+ this._validationSource = validationSource;
29
+ this._validator = validator;
30
+ }
31
+ validate(isSaving = true) {
32
+ return new Promise((accept, reject) => {
33
+ const records = this._dataUnit.getModifiedRecords();
34
+ for (let i = 0; i < records.length; i++) {
35
+ const record = records[i];
36
+ const invalidResults = [];
37
+ let validationResult = this.validateRequired(record);
38
+ if (validationResult && !validationResult.isValid) {
39
+ invalidResults.push(validationResult);
40
+ }
41
+ if (this._validator) {
42
+ validationResult = this._validator.validateRecord(record);
43
+ if (validationResult && !validationResult.isValid) {
44
+ invalidResults.push(validationResult);
45
+ }
46
+ }
47
+ if (invalidResults.length > 0) {
48
+ if (!isSaving && invalidResults[0].invalidFields.length > 0) {
49
+ this._validationSource.markAsInvalid(invalidResults[0].invalidFields[0], record.__record__id__);
50
+ reject();
51
+ break;
52
+ }
53
+ this.processValidationResult(invalidResults, record.__record__id__);
54
+ reject();
55
+ break;
56
+ }
57
+ }
58
+ return accept();
59
+ });
60
+ }
61
+ validateRequired(record) {
62
+ const requiredFields = this._validationSource.getRequiredFields();
63
+ const invalidFields = [];
64
+ new Set(requiredFields).forEach(field => {
65
+ const value = record[field];
66
+ if (value == undefined || value === "") {
67
+ const errorMessage = this._validationSource.getMessageForField(field, record.__record__id__);
68
+ if (errorMessage) {
69
+ invalidFields.push({ name: field, message: errorMessage });
70
+ }
71
+ else {
72
+ invalidFields.push({ name: field, message: "Essa informação é obrigatória" });
73
+ }
74
+ }
75
+ });
76
+ if (invalidFields.length > 0) {
77
+ return { isValid: false, invalidFields, infoMessage: "Há pelo menos um campo obrigatório não preenchido." };
78
+ }
79
+ return undefined;
80
+ }
81
+ processValidationResult(validationResult, recordId) {
82
+ validationResult.forEach(invalidResult => {
83
+ const invalidFields = invalidResult.invalidFields;
84
+ this._dataUnit.savingCanceled(invalidFields, recordId);
85
+ if (invalidFields) {
86
+ invalidFields.forEach(field => {
87
+ this.markAsInvalid(field, recordId);
88
+ });
89
+ }
90
+ if (invalidResult.infoMessage) {
91
+ ApplicationUtils.info(invalidResult.infoMessage);
92
+ }
93
+ if (invalidResult.errorMessage) {
94
+ const { errorTitle, errorMessage } = invalidResult;
95
+ ApplicationUtils.error(errorTitle, errorMessage);
96
+ }
97
+ });
98
+ }
99
+ markAsInvalid(field, recordId) {
100
+ this._dataUnit.setInvalidField(field.name, field.message, recordId);
101
+ this._validationSource.markAsInvalid(field, recordId);
102
+ }
103
+ }
104
+
105
+ class DataBinder {
106
+ constructor(dataUnit) {
107
+ this.onDataUnitEvent = (action) => {
108
+ var _a, _b;
109
+ switch (action.type) {
110
+ case Action.DATA_LOADED:
111
+ case Action.DATA_SAVED:
112
+ case Action.RECORDS_REMOVED:
113
+ case Action.RECORDS_ADDED:
114
+ case Action.RECORDS_COPIED:
115
+ case Action.EDITION_CANCELED:
116
+ case Action.SELECTION_CHANGED:
117
+ case Action.NEXT_SELECTED:
118
+ case Action.PREVIOUS_SELECTED:
119
+ this.clearInvalid();
120
+ case Action.DATA_CHANGED:
121
+ case Action.CHANGE_UNDONE:
122
+ case Action.CHANGE_REDONE:
123
+ case Action.RECORD_LOADED:
124
+ (_a = this._fields) === null || _a === void 0 ? void 0 : _a.forEach(field => {
125
+ this.updateValue(field.fieldName, field.field);
126
+ });
127
+ this.clearFieldError(Object.keys(action.payload)[0]);
128
+ break;
129
+ case Action.FIELD_INVALIDATED:
130
+ (_b = this._fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
131
+ this.updateErrorMessage(field.fieldName, field.field);
132
+ });
133
+ break;
134
+ }
135
+ };
136
+ this._uuid = StringUtils.generateUUID();
137
+ this._fields = new Map();
138
+ this._dataUnit = dataUnit;
139
+ this.applyDefaultValues();
140
+ this._dataUnit.subscribe(this.onDataUnitEvent);
141
+ this._dataUnit.addInterceptor(this);
142
+ this.setContextDataBinder(dataUnit);
143
+ }
144
+ get dataBinderId() {
145
+ return this._uuid;
146
+ }
147
+ setContextDataBinder(dataUnit) {
148
+ const dataBindersByDataUnit = ApplicationContext.getContextValue("__DATABINDER_BY_DATAUNIT__") || new Map();
149
+ const dataBinders = [...(dataBindersByDataUnit.get(dataUnit.dataUnitId) || []), this];
150
+ dataBindersByDataUnit.set(dataUnit.dataUnitId, dataBinders);
151
+ ApplicationContext.setContextValue("__DATABINDER_BY_DATAUNIT__", dataBindersByDataUnit);
152
+ }
153
+ applyDefaultValues() {
154
+ const recordIds = (this._dataUnit.getAddedRecords() || []).map(r => r.__record__id__);
155
+ if (recordIds.length > 0) {
156
+ const defaultValues = this.getDefaultValues();
157
+ if (defaultValues) {
158
+ Object.keys(defaultValues).forEach(field => {
159
+ this._dataUnit.setFieldValue(field, defaultValues[field], recordIds);
160
+ });
161
+ }
162
+ }
163
+ }
164
+ bind(fields, currentContextName, formMetadata, recordsValidator) {
165
+ fields.forEach(fieldElement => {
166
+ const { fieldName, contextName } = fieldElement.dataset;
167
+ if (contextName == undefined || contextName === currentContextName) {
168
+ this.updateBind(fieldName, fieldElement);
169
+ }
170
+ });
171
+ this._formMetadata = formMetadata;
172
+ this._recordValidatorProcessor = new RecordValidationProcessor(this._dataUnit, {
173
+ getRequiredFields: () => this.getFormRequiredFields(),
174
+ markAsInvalid: field => this.markInvalid(field),
175
+ getMessageForField: field => this.getErrorMessage(field),
176
+ }, recordsValidator);
177
+ }
178
+ getFormRequiredFields() {
179
+ return this._formMetadata.getRequiredFields();
180
+ }
181
+ disconnectDataUnit() {
182
+ const dataBindersByDataUnit = ApplicationContext.getContextValue("__DATABINDER_BY_DATAUNIT__") || new Map();
183
+ const dataBinders = dataBindersByDataUnit.get(this._dataUnit.dataUnitId);
184
+ const dataBindersFiltered = dataBinders.filter((dataBinder) => dataBinder.dataBinderId !== this.dataBinderId);
185
+ dataBindersByDataUnit.set(this._dataUnit.dataUnitId, dataBindersFiltered);
186
+ ApplicationContext.setContextValue("__DATABINDER_BY_DATAUNIT__", dataBindersByDataUnit);
187
+ }
188
+ onDisconnectedCallback() {
189
+ this._dataUnit.unsubscribe(this.onDataUnitEvent);
190
+ this._dataUnit.removeInterceptor(this);
191
+ this.disconnectDataUnit();
192
+ }
193
+ getCurrentRecordId() {
194
+ const record = this._dataUnit.getSelectedRecord();
195
+ return record === null || record === void 0 ? void 0 : record.__record__id__;
196
+ }
197
+ markInvalid(field) {
198
+ if (this._fields.has(field.name)) {
199
+ const fieldElement = this._fields.get(field.name).field;
200
+ this.updateErrorMessage(field.name, fieldElement, field.message);
201
+ }
202
+ }
203
+ setFocus(fieldName) {
204
+ if (!this._fields.has(fieldName)) {
205
+ return;
206
+ }
207
+ const fieldElement = this._fields.get(fieldName).field;
208
+ if (typeof fieldElement["setFocus"] != "function") {
209
+ return;
210
+ }
211
+ fieldElement["setFocus"]();
212
+ }
213
+ clearInvalid(recordId) {
214
+ this._dataUnit.clearInvalid(recordId);
215
+ this._fields.forEach(fieldBinder => {
216
+ const fieldElement = fieldBinder.field;
217
+ fieldElement["errorMessage"] = "";
218
+ });
219
+ }
220
+ clearFieldError(fieldName) {
221
+ var _a;
222
+ const field = (_a = this._fields.get(fieldName)) === null || _a === void 0 ? void 0 : _a.field;
223
+ if (field["errorMessage"]) {
224
+ field["errorMessage"] = "";
225
+ this._dataUnit.clearInvalid(this.getCurrentRecordId(), fieldName);
226
+ }
227
+ }
228
+ updateValue(fieldName, field) {
229
+ const bind = this._fields.get(fieldName);
230
+ try {
231
+ if (bind) {
232
+ bind.listen = false;
233
+ }
234
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
235
+ this.updateErrorMessage(fieldName, field);
236
+ }
237
+ finally {
238
+ if (bind) {
239
+ bind.listen = true;
240
+ }
241
+ }
242
+ }
243
+ validate() {
244
+ return this._recordValidatorProcessor.validate();
245
+ }
246
+ static async validateByDataunit(dataUnit) {
247
+ try {
248
+ const dataBinders = this.getDataBindersByDataUnit(dataUnit);
249
+ await Promise.all(dataBinders.map((dataBinder) => dataBinder.validate()));
250
+ return true;
251
+ }
252
+ catch (_a) {
253
+ return false;
254
+ }
255
+ }
256
+ static getDataBindersByDataUnit(dataUnit) {
257
+ const dataBindersByDataUnit = ApplicationContext.getContextValue("__DATABINDER_BY_DATAUNIT__");
258
+ return dataBindersByDataUnit.get(dataUnit.dataUnitId) || [];
259
+ }
260
+ updateErrorMessage(fieldName, field, message) {
261
+ if (message == undefined) {
262
+ message = this._dataUnit.getInvalidMessage(this.getCurrentRecordId(), fieldName);
263
+ }
264
+ if (!field["errorMessage"]) {
265
+ field["errorMessage"] = message;
266
+ }
267
+ }
268
+ getErrorMessage(fieldName) {
269
+ if (this._fields.has(fieldName)) {
270
+ const fieldElement = this._fields.get(fieldName).field;
271
+ return fieldElement["errorMessage"];
272
+ }
273
+ return undefined;
274
+ }
275
+ updateBind(fieldName, field) {
276
+ const oldBind = this._fields.get(fieldName);
277
+ if (oldBind) {
278
+ oldBind.destroy();
279
+ }
280
+ this.bindSearchOptionsLoader(fieldName, field);
281
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
282
+ this.updateErrorMessage(fieldName, field);
283
+ this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName) => this.cancelWaitingChange(fieldName), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
284
+ this.applyEzUploadContext(fieldName, field);
285
+ }
286
+ changeStarted(fieldName, waitingChange) {
287
+ /**
288
+ * se o waitingChange não é blocante, add um event listener pra
289
+ * fazer o accept da promise
290
+ *
291
+ * se não tiver promise no waitingChange, eu crio uma e resolvo no bind
292
+ *
293
+ *
294
+ */
295
+ if (this._dataUnit.records.length === 0) {
296
+ this._dataUnit.addRecord();
297
+ }
298
+ if (!waitingChange.blocking && waitingChange.promise == undefined) {
299
+ const bind = this._fields.get(fieldName);
300
+ if (bind) {
301
+ waitingChange.promise = new Promise((resolve, reject) => {
302
+ bind.waitingChangePromiseResolve = resolve;
303
+ bind.waitingChangePromiseReject = reject;
304
+ });
305
+ }
306
+ }
307
+ this._dataUnit.startChange(fieldName, waitingChange);
308
+ }
309
+ cancelWaitingChange(fieldName) {
310
+ if (this._dataUnit.waitingForChange(fieldName)) {
311
+ this._dataUnit.cancelWaitingChange(fieldName);
312
+ const bind = this._fields.get(fieldName);
313
+ if (bind) {
314
+ bind.rejectWaitingChange(new WaitingChangeException("Change canceled", fieldName));
315
+ }
316
+ }
317
+ }
318
+ setFieldValue(fieldName, newValue) {
319
+ if (this._dataUnit.records.length === 0) {
320
+ this._dataUnit.addRecord();
321
+ }
322
+ this._dataUnit.clearInvalid(this.getCurrentRecordId(), fieldName);
323
+ const record = this._dataUnit.getSelectedRecord();
324
+ this._dataUnit.setFieldValue(fieldName, newValue, record ? [record.__record__id__] : undefined);
325
+ if (this._dataUnit.waitingForChange(fieldName)) {
326
+ const bind = this._fields.get(fieldName);
327
+ if (bind) {
328
+ bind.acceptWaitingChange();
329
+ }
330
+ }
331
+ }
332
+ bindSearchOptionsLoader(fieldName, field) {
333
+ if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] == undefined) {
334
+ const loader = ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
335
+ if (loader) {
336
+ field["optionLoader"] = (arg) => {
337
+ return loader(arg, fieldName, this._dataUnit);
338
+ };
339
+ }
340
+ }
341
+ }
342
+ applyEzUploadContext(fieldName, field) {
343
+ var _a, _b;
344
+ if (field.nodeName === "EZ-UPLOAD") {
345
+ field["urlUpload"] = ApplicationContext.getContextValue("__EZUI__UPLOAD__ADD__URL__");
346
+ field["urlDelete"] = ApplicationContext.getContextValue("__EZUI__UPLOAD__DEL__URL__");
347
+ const descriptor = this._dataUnit.getField(fieldName);
348
+ const destination = (_a = descriptor.properties) === null || _a === void 0 ? void 0 : _a.DESTINATION;
349
+ if (destination) {
350
+ field["requestHeaders"] = { XTRAINF: `{"destination": "${destination}"}` };
351
+ }
352
+ field["maxFiles"] = ((_b = descriptor.properties) === null || _b === void 0 ? void 0 : _b.MAX_FILES) || 0;
353
+ }
354
+ }
355
+ interceptAction(action) {
356
+ if (action.type === Action.RECORDS_COPIED) {
357
+ const cleanFields = this._formMetadata.getCleanOnCopyFields();
358
+ if (cleanFields) {
359
+ const records = action.payload;
360
+ return new DataUnitAction(Action.RECORDS_COPIED, records.map(record => {
361
+ const newRecord = Object.assign({}, record);
362
+ cleanFields.forEach(fieldName => delete newRecord[fieldName]);
363
+ return newRecord;
364
+ }));
365
+ }
366
+ }
367
+ if (action.type === Action.SAVING_DATA) {
368
+ return new Promise((resolve) => {
369
+ this.validate()
370
+ .then(() => resolve(action))
371
+ .catch(() => { });
372
+ });
373
+ }
374
+ if (action.type === Action.RECORDS_ADDED) {
375
+ const defaultValues = this.getDefaultValues();
376
+ if (defaultValues) {
377
+ const records = action.payload;
378
+ return new DataUnitAction(Action.RECORDS_ADDED, records.map(record => {
379
+ return Object.assign(Object.assign({}, record), defaultValues);
380
+ }));
381
+ }
382
+ }
383
+ return action;
384
+ }
385
+ getDefaultValues() {
386
+ var _a;
387
+ const rawDefaultValues = (_a = this._formMetadata) === null || _a === void 0 ? void 0 : _a.getDefaultValues();
388
+ if (rawDefaultValues) {
389
+ const defaultValues = {};
390
+ for (const field in rawDefaultValues) {
391
+ defaultValues[field] = this._dataUnit.valueFromString(field, rawDefaultValues[field]);
392
+ }
393
+ return defaultValues;
394
+ }
395
+ return undefined;
396
+ }
397
+ }
398
+ class Bind {
399
+ constructor() {
400
+ this.listen = true;
401
+ this.startChangeEventName = "ezStartChange";
402
+ this.cancelWaitingChangeEventName = "ezCancelWaitingChange";
403
+ this.changeEventName = "ezChange";
404
+ }
405
+ destroy() {
406
+ this.field.removeEventListener(this.startChangeEventName, this.startChangeListener);
407
+ this.field.removeEventListener(this.cancelWaitingChangeEventName, this.cancelWaitingChangeListener);
408
+ this.field.removeEventListener(this.changeEventName, this.changeListener);
409
+ }
410
+ acceptWaitingChange() {
411
+ if (this.waitingChangePromiseResolve) {
412
+ this.waitingChangePromiseResolve();
413
+ this.waitingChangePromiseReject = undefined;
414
+ this.waitingChangePromiseResolve = undefined;
415
+ }
416
+ }
417
+ rejectWaitingChange(reason) {
418
+ if (this.waitingChangePromiseReject) {
419
+ this.waitingChangePromiseReject(reason);
420
+ this.waitingChangePromiseReject = undefined;
421
+ this.waitingChangePromiseResolve = undefined;
422
+ }
423
+ }
424
+ static create(fieldName, field, startChangeCallback, cancelWaitingChangeCallback, changeCallback) {
425
+ const b = new Bind();
426
+ b.field = field;
427
+ b.fieldName = fieldName;
428
+ b.startChangeListener = (evt) => { if (b.listen)
429
+ startChangeCallback(fieldName, evt.detail); };
430
+ b.field.addEventListener(b.startChangeEventName, b.startChangeListener);
431
+ b.cancelWaitingChangeListener = () => { if (b.listen)
432
+ cancelWaitingChangeCallback(fieldName); };
433
+ b.field.addEventListener(b.cancelWaitingChangeEventName, b.cancelWaitingChangeListener);
434
+ b.changeListener = (evt) => { if (b.listen)
435
+ changeCallback(fieldName, evt.detail); };
436
+ b.field.addEventListener(b.changeEventName, b.changeListener);
437
+ return b;
438
+ }
439
+ }
440
+
441
+ export { DataBinder as D, RecordValidationProcessor as R, buildFieldMetadata as b };
@@ -0,0 +1,33 @@
1
+ class FocusResolver {
2
+ static resolveFocus(element, selectText = true) {
3
+ var _a;
4
+ if (!element)
5
+ return;
6
+ (_a = element.focus) === null || _a === void 0 ? void 0 : _a.call(element);
7
+ if (element.setFocus) {
8
+ element.setFocus({ selectText });
9
+ return;
10
+ }
11
+ this.resolveFocusOnChild(element, selectText);
12
+ }
13
+ static resolveFocusOnChild(element, selectText = true) {
14
+ var _a, _b;
15
+ if (this.isGridCell(element) && element.firstElementChild) {
16
+ this.resolveFocusOnChild(element.firstElementChild);
17
+ return;
18
+ }
19
+ if (!element || !element.classList.contains('hydrated'))
20
+ return;
21
+ const firstChild = element.firstElementChild;
22
+ if (!(firstChild === null || firstChild === void 0 ? void 0 : firstChild.focus) && !(firstChild === null || firstChild === void 0 ? void 0 : firstChild.setFocus))
23
+ return;
24
+ (_a = firstChild === null || firstChild === void 0 ? void 0 : firstChild.focus) === null || _a === void 0 ? void 0 : _a.call(firstChild);
25
+ (_b = firstChild === null || firstChild === void 0 ? void 0 : firstChild.setFocus) === null || _b === void 0 ? void 0 : _b.call(firstChild, { selectText });
26
+ }
27
+ static isGridCell(element) {
28
+ var _a;
29
+ return ((_a = element === null || element === void 0 ? void 0 : element.getAttribute) === null || _a === void 0 ? void 0 : _a.call(element, "role")) === 'gridcell';
30
+ }
31
+ }
32
+
33
+ export { FocusResolver as F };
@@ -82,6 +82,7 @@ const EzFilterInput = class {
82
82
  this.mode = "regular";
83
83
  this.asyncSearch = false;
84
84
  this.canShowError = true;
85
+ this.autoFocus = false;
85
86
  }
86
87
  observeLabel() {
87
88
  if (this._textInput) {
@@ -102,8 +103,8 @@ const EzFilterInput = class {
102
103
  /**
103
104
  * Aplica o foco no campo.
104
105
  */
105
- async setFocus() {
106
- this._textInput.setFocus();
106
+ async setFocus(options) {
107
+ this._textInput.setFocus(options);
107
108
  }
108
109
  /**
109
110
  * Remove o foco do campo.
@@ -156,6 +157,11 @@ const EzFilterInput = class {
156
157
  }
157
158
  componentDidLoad() {
158
159
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
160
+ if (this.autoFocus) {
161
+ requestAnimationFrame(() => {
162
+ this.setFocus({ selectText: true });
163
+ });
164
+ }
159
165
  }
160
166
  render() {
161
167
  ElementIDUtils.addIDInfoIfNotExists(this._elem, 'input');
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-baa5e267.js';
2
- import { ObjectUtils, FloatingManager, ElementIDUtils } from '@sankhyalabs/core';
2
+ import { ObjectUtils, FloatingManager, StringUtils, ElementIDUtils } from '@sankhyalabs/core';
3
3
  import './ApplicationUtils-eaf91331.js';
4
4
  import { C as CSSVarsUtils } from './CSSVarsUtils-71ce76be.js';
5
5
  import './DialogType-54a62731.js';
@@ -34,12 +34,13 @@ const EzComboBox = class {
34
34
  this.suppressSearch = false;
35
35
  this.optionLoader = undefined;
36
36
  this.suppressEmptyOption = false;
37
- this.stopPropagateEnterKeyEvent = false;
37
+ this.stopPropagateEnterKeyEvent = true;
38
38
  this.canShowError = true;
39
39
  this.mode = "regular";
40
40
  this.hideErrorOnFocusOut = true;
41
41
  this.listOptionsPosition = undefined;
42
42
  this.isTextSearch = false;
43
+ this.autoFocus = false;
43
44
  }
44
45
  observeErrorMessage() {
45
46
  var _a;
@@ -102,9 +103,9 @@ const EzComboBox = class {
102
103
  /**
103
104
  * Aplica o foco no campo.
104
105
  */
105
- async setFocus() {
106
+ async setFocus(options) {
106
107
  if (this._textInput) {
107
- this._textInput.setFocus();
108
+ this._textInput.setFocus(options);
108
109
  }
109
110
  }
110
111
  /**
@@ -264,11 +265,15 @@ const EzComboBox = class {
264
265
  : undefined, h("span", { class: "item__label " + (this.showOptionValue ? "item__label--bold" : ""), title: opt.label }, opt.label));
265
266
  }
266
267
  showOptions() {
268
+ var _a, _b;
267
269
  if (!this.enabled)
268
270
  return;
269
271
  if (this.isOptionsVisible()) {
270
272
  return;
271
273
  }
274
+ const valueString = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : this.value;
275
+ const indexValue = this._visibleOptions.findIndex(option => option.value === valueString);
276
+ this._preSelection = indexValue === -1 ? 0 : indexValue;
272
277
  if (!!this._resizeObserver)
273
278
  this._resizeObserver.observe(this._textInput);
274
279
  this._floatingID = FloatingManager.float(this._listWrapper, this._listContainer, { autoClose: true, isFixed: true, backClickListener: () => this.hideOptions() });
@@ -310,11 +315,26 @@ const EzComboBox = class {
310
315
  liElem.scrollIntoView({ behavior: "smooth", block: "nearest" });
311
316
  });
312
317
  }
313
- selectCurrentOption() {
318
+ selectCurrentOption(focusOnInput = true) {
314
319
  if (this._preSelection !== undefined) {
315
- this.selectOption(this._visibleOptions[this._preSelection]);
320
+ this.selectOption(this._visibleOptions[this._preSelection], focusOnInput);
316
321
  this._preSelection = undefined;
317
322
  }
323
+ else {
324
+ this.controlListWithOnlyOne(focusOnInput);
325
+ }
326
+ }
327
+ controlListWithOnlyOne(focusOnInput = true) {
328
+ var _a;
329
+ const source = (_a = this._visibleOptions) === null || _a === void 0 ? void 0 : _a.filter((opt) => opt.label !== "" && opt.value != undefined);
330
+ if ((source === null || source === void 0 ? void 0 : source.length) > 0) {
331
+ let title = StringUtils.decodeHtmlEntities(source[0].label);
332
+ const option = {
333
+ value: source[0].value,
334
+ label: title,
335
+ };
336
+ this.selectOption(option, focusOnInput);
337
+ }
318
338
  }
319
339
  updateSource(source) {
320
340
  this._startLoading = false;
@@ -340,7 +360,7 @@ const EzComboBox = class {
340
360
  }
341
361
  }
342
362
  }
343
- selectOption(newOption) {
363
+ selectOption(newOption, focusOnInput = true) {
344
364
  var _a, _b;
345
365
  const currentValue = this.getSelectedOption(this.value);
346
366
  if ((((_a = currentValue === null || currentValue === void 0 ? void 0 : currentValue.value) === null || _a === void 0 ? void 0 : _a.toString()) !== ((_b = newOption === null || newOption === void 0 ? void 0 : newOption.value) === null || _b === void 0 ? void 0 : _b.toString()))
@@ -351,6 +371,11 @@ const EzComboBox = class {
351
371
  else {
352
372
  this.resetOptions();
353
373
  }
374
+ if (focusOnInput) {
375
+ setTimeout(() => {
376
+ this.setFocus();
377
+ }, 0);
378
+ }
354
379
  }
355
380
  loadOptions(mode, argument = "") {
356
381
  this._criteria = argument;
@@ -434,6 +459,11 @@ const EzComboBox = class {
434
459
  }
435
460
  });
436
461
  });
462
+ if (this.autoFocus) {
463
+ requestAnimationFrame(() => {
464
+ this.setFocus({ selectText: true });
465
+ });
466
+ }
437
467
  }
438
468
  //---------------------------------------------
439
469
  // Event handlers
@@ -488,18 +518,24 @@ const EzComboBox = class {
488
518
  }
489
519
  switch (event.key) {
490
520
  case "ArrowDown":
521
+ event.stopPropagation();
522
+ if (this.canShowListOptions())
523
+ event.preventDefault();
491
524
  this.showOptions();
492
525
  this.nextOption();
493
- event.stopPropagation();
494
526
  break;
495
527
  case "ArrowUp":
528
+ event.stopPropagation();
529
+ if (this.canShowListOptions())
530
+ event.preventDefault();
496
531
  this.showOptions();
497
532
  this.previousOption();
498
- event.stopPropagation();
499
533
  break;
500
534
  case "Enter":
501
535
  this.handleEventPropagation(event);
502
- this.selectCurrentOption();
536
+ if (this.isOptionsVisible()) {
537
+ this.selectCurrentOption();
538
+ }
503
539
  break;
504
540
  case "Escape":
505
541
  if (this.isOptionsVisible()) {
@@ -511,7 +547,7 @@ const EzComboBox = class {
511
547
  case "Tab":
512
548
  this._tabPressed = true;
513
549
  if (this.isOptionsVisible()) {
514
- this.selectCurrentOption();
550
+ this.selectCurrentOption(false);
515
551
  }
516
552
  this.resetOptions();
517
553
  break;
@@ -19,6 +19,7 @@ const EzDateInput = class {
19
19
  this.errorMessage = undefined;
20
20
  this.mode = "regular";
21
21
  this.canShowError = true;
22
+ this.autoFocus = false;
22
23
  }
23
24
  observeLabel() {
24
25
  if (this._textInput) {
@@ -55,8 +56,8 @@ const EzDateInput = class {
55
56
  /**
56
57
  * Aplica o foco no campo.
57
58
  */
58
- async setFocus() {
59
- this._textInput.setFocus();
59
+ async setFocus(options) {
60
+ this._textInput.setFocus(options);
60
61
  }
61
62
  /**
62
63
  * Remove o foco do campo.
@@ -174,6 +175,11 @@ const EzDateInput = class {
174
175
  componentDidLoad() {
175
176
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
176
177
  this.setInputValue();
178
+ if (this.autoFocus) {
179
+ requestAnimationFrame(() => {
180
+ this.setFocus({ selectText: true });
181
+ });
182
+ }
177
183
  }
178
184
  render() {
179
185
  ElementIDUtils.addIDInfoIfNotExists(this._elem, 'input');