@sankhyalabs/ezui 5.10.8 → 5.11.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/{CSSVarsUtils-af809e73.js → CSSVarsUtils-b136a156.js} +5 -0
  3. package/dist/cjs/RecordValidationProcessor-edd23705.js +102 -0
  4. package/dist/cjs/ez-actions-button.cjs.entry.js +1 -1
  5. package/dist/cjs/ez-calendar.cjs.entry.js +34 -5
  6. package/dist/cjs/ez-combo-box.cjs.entry.js +89 -14
  7. package/dist/cjs/ez-date-input.cjs.entry.js +53 -22
  8. package/dist/cjs/ez-date-time-input.cjs.entry.js +53 -19
  9. package/dist/cjs/ez-filter-input_2.cjs.entry.js +1 -1
  10. package/dist/cjs/ez-form.cjs.entry.js +9 -83
  11. package/dist/cjs/ez-grid.cjs.entry.js +488 -6
  12. package/dist/cjs/ez-number-input.cjs.entry.js +39 -15
  13. package/dist/cjs/ez-search.cjs.entry.js +11 -2
  14. package/dist/cjs/ez-text-area.cjs.entry.js +6 -2
  15. package/dist/cjs/ez-text-input.cjs.entry.js +7 -4
  16. package/dist/cjs/ez-time-input.cjs.entry.js +11 -7
  17. package/dist/cjs/ezui.cjs.js +1 -1
  18. package/dist/cjs/loader.cjs.js +1 -1
  19. package/dist/collection/collection-manifest.json +2 -2
  20. package/dist/collection/components/ez-calendar/ez-calendar.js +63 -6
  21. package/dist/collection/components/ez-combo-box/ez-combo-box.css +6 -0
  22. package/dist/collection/components/ez-combo-box/ez-combo-box.js +122 -12
  23. package/dist/collection/components/ez-date-input/ez-date-input.js +71 -21
  24. package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +71 -18
  25. package/dist/collection/components/ez-grid/controller/ag-grid/AgGridController.js +40 -7
  26. package/dist/collection/components/ez-grid/controller/ag-grid/DataSource.js +1 -0
  27. package/dist/collection/components/ez-grid/controller/ag-grid/GridEditionManager.js +230 -0
  28. package/dist/collection/components/ez-grid/controller/ag-grid/editor/EzCellEditor.js +49 -0
  29. package/dist/collection/components/ez-grid/controller/ag-grid/editor/GridEditorUtils.js +10 -0
  30. package/dist/collection/components/ez-grid/controller/ag-grid/editor/IEditorMetadata.js +4 -0
  31. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/ComboBox.tpl.js +38 -0
  32. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/DateInput.tpl.js +40 -0
  33. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/NumberInput.tpl.js +20 -0
  34. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/Search.tpl.js +15 -0
  35. package/dist/collection/components/ez-grid/controller/ag-grid/editor/templates/TextInput.tpl.js +41 -0
  36. package/dist/collection/components/ez-grid/ez-grid.js +67 -0
  37. package/dist/collection/components/ez-number-input/ez-number-input.css +4 -0
  38. package/dist/collection/components/ez-number-input/ez-number-input.js +62 -15
  39. package/dist/collection/components/ez-search/ez-search.css +1 -1
  40. package/dist/collection/components/ez-search/ez-search.js +46 -1
  41. package/dist/collection/components/ez-text-area/ez-text-area.css +4 -0
  42. package/dist/collection/components/ez-text-area/ez-text-area.js +23 -1
  43. package/dist/collection/components/ez-text-input/ez-text-input.css +8 -1
  44. package/dist/collection/components/ez-text-input/ez-text-input.js +14 -5
  45. package/dist/collection/components/ez-time-input/ez-time-input.css +4 -0
  46. package/dist/collection/components/ez-time-input/ez-time-input.js +18 -7
  47. package/dist/collection/utils/CSSVarsUtils.js +5 -0
  48. package/dist/collection/utils/form/DataBinder.js +7 -62
  49. package/dist/collection/utils/form/FormMetadata.js +3 -22
  50. package/dist/collection/utils/interfaces/AbstractFieldMetadata.js +21 -0
  51. package/dist/collection/utils/validators/recordvalidator/IValidationResult.js +1 -0
  52. package/dist/collection/utils/validators/recordvalidator/IValidationSource.js +1 -0
  53. package/dist/collection/utils/validators/recordvalidator/RecordValidationProcessor.js +74 -0
  54. package/dist/custom-elements/index.js +922 -203
  55. package/dist/esm/{CSSVarsUtils-00f67f32.js → CSSVarsUtils-a97cfa29.js} +5 -0
  56. package/dist/esm/RecordValidationProcessor-abc814af.js +99 -0
  57. package/dist/esm/ez-actions-button.entry.js +1 -1
  58. package/dist/esm/ez-calendar.entry.js +35 -6
  59. package/dist/esm/ez-combo-box.entry.js +89 -14
  60. package/dist/esm/ez-date-input.entry.js +53 -22
  61. package/dist/esm/ez-date-time-input.entry.js +53 -19
  62. package/dist/esm/ez-filter-input_2.entry.js +1 -1
  63. package/dist/esm/ez-form.entry.js +10 -84
  64. package/dist/esm/ez-grid.entry.js +489 -7
  65. package/dist/esm/ez-number-input.entry.js +39 -15
  66. package/dist/esm/ez-search.entry.js +11 -2
  67. package/dist/esm/ez-text-area.entry.js +6 -2
  68. package/dist/esm/ez-text-input.entry.js +7 -4
  69. package/dist/esm/ez-time-input.entry.js +11 -7
  70. package/dist/esm/ezui.js +1 -1
  71. package/dist/esm/loader.js +1 -1
  72. package/dist/ezui/ezui.esm.js +1 -1
  73. package/dist/ezui/p-028f264f.entry.js +1 -0
  74. package/dist/ezui/p-391de0e4.entry.js +1 -0
  75. package/dist/ezui/p-4535da17.entry.js +1 -0
  76. package/dist/ezui/p-5cef0264.entry.js +1 -0
  77. package/dist/ezui/p-7eb3e1a5.js +1 -0
  78. package/dist/ezui/p-86a2036d.js +1 -0
  79. package/dist/ezui/{p-12303d2e.entry.js → p-87e85160.entry.js} +1 -1
  80. package/dist/ezui/p-90fa4cb3.entry.js +1 -0
  81. package/dist/ezui/p-9f41b414.entry.js +1 -0
  82. package/dist/ezui/p-ce035beb.entry.js +1 -0
  83. package/dist/ezui/p-d43b22f3.entry.js +1 -0
  84. package/dist/ezui/p-e2dfd935.entry.js +1 -0
  85. package/dist/ezui/p-e67d0bd5.entry.js +1 -0
  86. package/dist/ezui/{p-c7a23be9.entry.js → p-fd54b5b4.entry.js} +2 -2
  87. package/dist/ezui/{p-f1a537e3.entry.js → p-ff82b176.entry.js} +1 -1
  88. package/dist/types/components/ez-calendar/ez-calendar.d.ts +9 -1
  89. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +14 -0
  90. package/dist/types/components/ez-date-input/ez-date-input.d.ts +4 -0
  91. package/dist/types/components/ez-date-time-input/ez-date-time-input.d.ts +4 -0
  92. package/dist/types/components/ez-form-view/interfaces/IFormViewField.d.ts +2 -14
  93. package/dist/types/components/ez-grid/controller/EzGridController.d.ts +18 -0
  94. package/dist/types/components/ez-grid/controller/ag-grid/AgGridController.d.ts +4 -0
  95. package/dist/types/components/ez-grid/controller/ag-grid/GridEditionManager.d.ts +38 -0
  96. package/dist/types/components/ez-grid/controller/ag-grid/editor/EzCellEditor.d.ts +10 -0
  97. package/dist/types/components/ez-grid/controller/ag-grid/editor/GridEditorUtils.d.ts +1 -0
  98. package/dist/types/components/ez-grid/controller/ag-grid/editor/IEditorMetadata.d.ts +9 -0
  99. package/dist/types/components/ez-grid/controller/ag-grid/editor/IUICellEditor.d.ts +10 -0
  100. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/ComboBox.tpl.d.ts +4 -0
  101. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/DateInput.tpl.d.ts +5 -0
  102. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/NumberInput.tpl.d.ts +4 -0
  103. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/Search.tpl.d.ts +3 -0
  104. package/dist/types/components/ez-grid/controller/ag-grid/editor/templates/TextInput.tpl.d.ts +4 -0
  105. package/dist/types/components/ez-grid/ez-grid.d.ts +13 -0
  106. package/dist/types/components/ez-number-input/ez-number-input.d.ts +5 -1
  107. package/dist/types/components/ez-search/ez-search.d.ts +6 -1
  108. package/dist/types/components/ez-text-area/ez-text-area.d.ts +4 -0
  109. package/dist/types/components/ez-text-input/ez-text-input.d.ts +4 -1
  110. package/dist/types/components/ez-time-input/ez-time-input.d.ts +2 -1
  111. package/dist/types/components.d.ts +65 -6
  112. package/dist/types/utils/form/DataBinder.d.ts +1 -3
  113. package/dist/types/utils/form/interfaces/IFormConfig.d.ts +1 -1
  114. package/dist/types/utils/form/interfaces/index.d.ts +4 -4
  115. package/dist/types/utils/interfaces/AbstractFieldMetadata.d.ts +17 -0
  116. package/dist/types/utils/{form/interfaces → interfaces}/IFieldConfig.d.ts +2 -2
  117. package/dist/types/utils/validators/recordvalidator/IValidationSource.d.ts +6 -0
  118. package/dist/types/utils/validators/recordvalidator/RecordValidationProcessor.d.ts +13 -0
  119. package/package.json +2 -2
  120. package/dist/ezui/p-00c7c25d.entry.js +0 -1
  121. package/dist/ezui/p-0b160fec.entry.js +0 -1
  122. package/dist/ezui/p-0bd54a6f.entry.js +0 -1
  123. package/dist/ezui/p-39153935.entry.js +0 -1
  124. package/dist/ezui/p-4a5e37a7.js +0 -1
  125. package/dist/ezui/p-5782443e.entry.js +0 -1
  126. package/dist/ezui/p-5d45e384.entry.js +0 -1
  127. package/dist/ezui/p-70ea4beb.entry.js +0 -1
  128. package/dist/ezui/p-78a6e049.entry.js +0 -1
  129. package/dist/ezui/p-8bcb197f.entry.js +0 -1
  130. package/dist/ezui/p-a4c9f3c4.entry.js +0 -1
  131. /package/dist/collection/{utils/form/interfaces/IFieldConfig.js → components/ez-grid/controller/ag-grid/editor/IUICellEditor.js} +0 -0
  132. /package/dist/collection/utils/{form/interfaces/IInvalidField.js → interfaces/IFieldConfig.js} +0 -0
  133. /package/dist/collection/utils/{form/interfaces/IRecordValidator.js → validators/recordvalidator/IInvalidField.js} +0 -0
  134. /package/dist/collection/utils/{form/interfaces/IValidationResult.js → validators/recordvalidator/IRecordValidator.js} +0 -0
  135. /package/dist/types/utils/{form/interfaces → validators/recordvalidator}/IInvalidField.d.ts +0 -0
  136. /package/dist/types/utils/{form/interfaces → validators/recordvalidator}/IRecordValidator.d.ts +0 -0
  137. /package/dist/types/utils/{form/interfaces → validators/recordvalidator}/IValidationResult.d.ts +0 -0
@@ -6,6 +6,7 @@ const index = require('./index-1064511f.js');
6
6
  const core = require('@sankhyalabs/core');
7
7
  const DataUnit = require('@sankhyalabs/core/dist/dataunit/DataUnit');
8
8
  const constants = require('./constants-3a1d64fb.js');
9
+ const RecordValidationProcessor = require('./RecordValidationProcessor-edd23705.js');
9
10
  const ApplicationUtils = require('./ApplicationUtils-2e444734.js');
10
11
  require('./DialogType-2114c337.js');
11
12
  require('./CheckMode-ecb90b87.js');
@@ -118854,6 +118855,7 @@ class DataSource {
118854
118855
  case core.Action.DATA_SAVED:
118855
118856
  case core.Action.EDITION_CANCELED:
118856
118857
  case core.Action.DATA_CHANGED:
118858
+ case core.Action.DATA_RESOLVED:
118857
118859
  this._controller.refresh();
118858
118860
  break;
118859
118861
  case core.Action.SELECTION_CHANGED:
@@ -119187,6 +119189,443 @@ const gridTerms = {
119187
119189
  ctrlV: "Ctrl+V"
119188
119190
  };
119189
119191
 
119192
+ const buildEditorMetadata = (descriptor, eGridCell, dataUnit, editionManager) => {
119193
+ return Object.assign(Object.assign({}, RecordValidationProcessor.buildFieldMetadata(descriptor)), { eGridCell, dataUnit, editionManager });
119194
+ };
119195
+
119196
+ const MINIMIUM_WIDTH_TEXTAREA = 210;
119197
+ const PADDING_VALUE_TEXTAREA = 12;
119198
+ const buildTextInput = ({ name, contextName }) => {
119199
+ return core.HTMLBuilder.parseElement(`<ez-text-input
119200
+ class="ez-grid grid_editor"
119201
+ data-field-name=${name}
119202
+ data-context-name=${contextName}
119203
+ mode="slim"
119204
+ />`);
119205
+ };
119206
+ const buildTextAreaInput = ({ eGridCell, editionManager }) => {
119207
+ const element = core.HTMLBuilder.parseElement(`<ez-text-area
119208
+ can-show-error="false"
119209
+ enable-resize="true"
119210
+ />`);
119211
+ element.addEventListener('keydown', event => handlePressEnterEvent(event, element, editionManager));
119212
+ setElementInitialWidth(eGridCell, element);
119213
+ element.isPopUp = true;
119214
+ return element;
119215
+ };
119216
+ function setElementInitialWidth(eGridCell, element) {
119217
+ const { width } = eGridCell.getBoundingClientRect();
119218
+ const newValue = width > MINIMIUM_WIDTH_TEXTAREA ? width : MINIMIUM_WIDTH_TEXTAREA;
119219
+ element.style.minWidth = `${newValue - PADDING_VALUE_TEXTAREA}px`;
119220
+ element.style.resize = "both";
119221
+ }
119222
+ function handlePressEnterEvent(event, element, editionManager) {
119223
+ if (isEnter(event)) {
119224
+ const shouldBreakLine = event.ctrlKey;
119225
+ if (shouldBreakLine) {
119226
+ element.appendTextToSelection('\n');
119227
+ event.preventDefault();
119228
+ return;
119229
+ }
119230
+ editionManager.navigateByEnterKey(event);
119231
+ }
119232
+ }
119233
+ function isEnter(event) {
119234
+ return [event.key, event.code].includes('Enter');
119235
+ }
119236
+
119237
+ const LIMIT_TIME_VALUE = 2359;
119238
+ const buildDate = () => {
119239
+ const dateInput = core.HTMLBuilder.parseElement(`<ez-date-input
119240
+ class="ez-grid grid_editor"
119241
+ mode="slim"
119242
+ data-is-fixed="true"
119243
+ />`);
119244
+ dateInput.valueGetter = () => dateInput.getValueAsync();
119245
+ return dateInput;
119246
+ };
119247
+ const buildTime = ({ readOnly }) => {
119248
+ const timeInputElement = core.HTMLBuilder.parseElement(`<ez-time-input
119249
+ class="ez-grid grid_editor"
119250
+ enabled=${!readOnly}
119251
+ mode="slim"
119252
+ />`);
119253
+ timeInputElement.valueGetter = () => {
119254
+ const value = timeInputElement.value;
119255
+ const isAllowedTime = parseInt(value) <= LIMIT_TIME_VALUE;
119256
+ return isAllowedTime ? value : null;
119257
+ };
119258
+ timeInputElement.valueSetter = (value) => {
119259
+ const isAllowedTime = parseInt(value) <= LIMIT_TIME_VALUE;
119260
+ if (!isAllowedTime)
119261
+ return timeInputElement.value = null;
119262
+ return timeInputElement.value = value;
119263
+ };
119264
+ return timeInputElement;
119265
+ };
119266
+ const buildDateTime = ({ readOnly }) => {
119267
+ const dateTimeInput = core.HTMLBuilder.parseElement(`<ez-date-time-input
119268
+ class="ez-grid grid_editor"
119269
+ mode="slim"
119270
+ enabled=${!readOnly}
119271
+ data-is-fixed="true"
119272
+ />`);
119273
+ dateTimeInput.valueGetter = () => dateTimeInput.getValueAsync();
119274
+ return dateTimeInput;
119275
+ };
119276
+
119277
+ const buildDecimal = ({ readOnly, props }) => {
119278
+ const precision = Number((props === null || props === void 0 ? void 0 : props.precision) || 2);
119279
+ const prettyPrecision = Number((props === null || props === void 0 ? void 0 : props.prettyPrecision) || precision);
119280
+ return buildNumeric(readOnly, precision, prettyPrecision);
119281
+ };
119282
+ const buildInteger = ({ readOnly }) => {
119283
+ return buildNumeric(readOnly, 0, 0);
119284
+ };
119285
+ function buildNumeric(readOnly, precision, prettyPrecision) {
119286
+ const input = core.HTMLBuilder.parseElement(`<ez-number-input
119287
+ class="ez-grid grid_editor"
119288
+ enabled=${!readOnly}
119289
+ precision=${precision}
119290
+ pretty-precision=${prettyPrecision}
119291
+ mode="slim"
119292
+ />`);
119293
+ input.valueGetter = () => input.getValueAsync();
119294
+ return input;
119295
+ }
119296
+
119297
+ function getViewPortHeight(cell) {
119298
+ let currentElem = cell;
119299
+ while (currentElem) {
119300
+ const viewPort = currentElem.querySelector("[ref=eBodyViewport]");
119301
+ if (viewPort) {
119302
+ return viewPort.getBoundingClientRect().bottom;
119303
+ }
119304
+ currentElem = currentElem.parentElement;
119305
+ }
119306
+ }
119307
+
119308
+ const BOOLEAN_OPTIONS = new Map([[true, { value: "S", label: "Sim" }], [false, { value: "N", label: "Não" }]]);
119309
+ const buildComboBox = ({ required, props, eGridCell }) => {
119310
+ const prop = props === null || props === void 0 ? void 0 : props.options;
119311
+ let options;
119312
+ if (typeof prop === "string") {
119313
+ const parsed = JSON.parse(prop);
119314
+ options = Object.keys(parsed).map(key => { return { value: key, label: parsed[key] }; });
119315
+ }
119316
+ else {
119317
+ options = prop;
119318
+ }
119319
+ const combo = core.HTMLBuilder.parseElement(`<ez-combo-box
119320
+ class="grid_editor"
119321
+ suppress-empty-option=${required}
119322
+ mode="slim"
119323
+ />`);
119324
+ combo.options = options;
119325
+ combo.listOptionsPosition = { verticalPosition: 29, bottomLimit: getViewPortHeight(eGridCell), hardPosition: true };
119326
+ return combo;
119327
+ };
119328
+ const buildSwitch = (fieldMetadata) => {
119329
+ const combo = buildComboBox(Object.assign(Object.assign({}, fieldMetadata), { props: Object.assign(Object.assign({}, fieldMetadata.props), { options: Array.from(BOOLEAN_OPTIONS.values()) }) }));
119330
+ combo.valueGetter = () => {
119331
+ const value = combo.value;
119332
+ if (value == undefined) {
119333
+ return;
119334
+ }
119335
+ return value.value == "S";
119336
+ };
119337
+ combo.valueSetter = (value) => {
119338
+ if (value != undefined) {
119339
+ combo.value = BOOLEAN_OPTIONS.get(value);
119340
+ }
119341
+ };
119342
+ return combo;
119343
+ };
119344
+
119345
+ const buildSearch = ({ name, required, readOnly, eGridCell, dataUnit }) => {
119346
+ const ezSearch = core.HTMLBuilder.parseElement(`<ez-search
119347
+ class="ez-grid grid_editor"
119348
+ mode="slim"
119349
+ suppress-empty-option=${required}
119350
+ enabled=${!readOnly}
119351
+ />`);
119352
+ const loader = core.ApplicationContext.getContextValue("__EZUI__SEARCH__OPTION__LOADER__");
119353
+ ezSearch.optionLoader = (argument) => loader(argument, name, dataUnit);
119354
+ ezSearch.listOptionsPosition = { verticalPosition: 29, bottomLimit: getViewPortHeight(eGridCell), hardPosition: true };
119355
+ ezSearch.valueGetter = () => ezSearch.getValueAsync();
119356
+ return ezSearch;
119357
+ };
119358
+
119359
+ const uiBuilders = new Map();
119360
+ uiBuilders.set(core.UserInterface.DATE, buildDate);
119361
+ uiBuilders.set(core.UserInterface.TIME, buildTime);
119362
+ uiBuilders.set(core.UserInterface.DATETIME, buildDateTime);
119363
+ uiBuilders.set(core.UserInterface.DECIMALNUMBER, buildDecimal);
119364
+ uiBuilders.set(core.UserInterface.INTEGERNUMBER, buildInteger);
119365
+ uiBuilders.set(core.UserInterface.SWITCH, buildSwitch);
119366
+ uiBuilders.set(core.UserInterface.CHECKBOX, buildSwitch);
119367
+ uiBuilders.set(core.UserInterface.OPTIONSELECTOR, buildComboBox);
119368
+ uiBuilders.set(core.UserInterface.LONGTEXT, buildTextAreaInput);
119369
+ uiBuilders.set(core.UserInterface.SEARCH, buildSearch);
119370
+ class EzCellEditor {
119371
+ init(params) {
119372
+ const fieldName = params.column.getColId();
119373
+ const dataUnit = params.context.dataUnit;
119374
+ const fieldMetadata = buildEditorMetadata(dataUnit.getField(fieldName), params.eGridCell, dataUnit, params.context.editionManager);
119375
+ const builder = uiBuilders.get(fieldMetadata.userInterface) || buildTextInput;
119376
+ this._gui = builder(fieldMetadata);
119377
+ if (this._gui.valueSetter != undefined) {
119378
+ this._gui.valueSetter(params.value);
119379
+ }
119380
+ else {
119381
+ this._gui.value = params.value;
119382
+ }
119383
+ }
119384
+ getGui() {
119385
+ return this._gui;
119386
+ }
119387
+ afterGuiAttached() {
119388
+ this.focusIn();
119389
+ }
119390
+ focusIn() {
119391
+ this._gui.focus();
119392
+ this._gui.setFocus({ selectText: true });
119393
+ }
119394
+ getValue() {
119395
+ return this._gui.valueGetter != undefined ? this._gui.valueGetter() : this._gui.value;
119396
+ }
119397
+ isPopup() {
119398
+ return this._gui.isPopUp;
119399
+ }
119400
+ }
119401
+
119402
+ class GridEditionManager {
119403
+ constructor(dataUnit, useEnterLikeTab, recordsValidator, editionIsDisabled) {
119404
+ this._dataUnit = dataUnit;
119405
+ this._recordValidationProcessor = new RecordValidationProcessor.RecordValidationProcessor(this._dataUnit, {
119406
+ getRequiredFields: () => this.getRequiredFields(),
119407
+ markAsInvalid: () => { },
119408
+ getMessageForField: () => null
119409
+ }, recordsValidator);
119410
+ this._useEnterLikeTab = useEnterLikeTab;
119411
+ this._editionIsDisabled = editionIsDisabled;
119412
+ }
119413
+ configureGrid(options) {
119414
+ this._gridOptions = options;
119415
+ options.readOnlyEdit = true;
119416
+ options.onCellEditRequest = evt => this.onCellEditRequest(evt);
119417
+ options.onCellKeyDown = evt => {
119418
+ if (evt.event && evt["column"]) {
119419
+ this.onCellKeyDown(evt);
119420
+ }
119421
+ };
119422
+ return options;
119423
+ }
119424
+ proceedAutoSave() {
119425
+ if (!this._dataUnit.isDirty()) {
119426
+ this.saveSuccess();
119427
+ return;
119428
+ }
119429
+ if (!this._isGridEdition) {
119430
+ return;
119431
+ }
119432
+ const currentRercord = this._dataUnit.getSelectedRecord();
119433
+ if (currentRercord == undefined) {
119434
+ return;
119435
+ }
119436
+ this._recordValidationProcessor
119437
+ .validate()
119438
+ .then(() => {
119439
+ this._dataUnit.saveData()
119440
+ .then(() => this.saveSuccess())
119441
+ .catch(reason => this.saveFail(reason));
119442
+ })
119443
+ .catch(reason => this.saveFail(reason));
119444
+ }
119445
+ navigateByEnterKey(keyboardEvent) {
119446
+ const backwards = keyboardEvent.shiftKey;
119447
+ if (this._useEnterLikeTab) {
119448
+ if (backwards) {
119449
+ this._gridOptions.api.tabToPreviousCell(keyboardEvent);
119450
+ }
119451
+ else {
119452
+ this._gridOptions.api.tabToNextCell(keyboardEvent);
119453
+ }
119454
+ }
119455
+ else {
119456
+ const editionCell = this._gridOptions.api.getEditingCells()[0];
119457
+ if (editionCell) {
119458
+ let { rowIndex } = editionCell;
119459
+ this.nextEditionRow(rowIndex, editionCell.column, backwards);
119460
+ }
119461
+ }
119462
+ }
119463
+ getComponents() {
119464
+ return { ezCellEditor: EzCellEditor };
119465
+ }
119466
+ verifyClickToEdition(api, cellClicked) {
119467
+ if (this.isSecondClick(cellClicked)) {
119468
+ api.startEditingCell({ rowIndex: cellClicked.rowIndex, colKey: cellClicked.column.getColId() });
119469
+ }
119470
+ this._lastCellClicked = cellClicked;
119471
+ }
119472
+ configureColumn(col) {
119473
+ col.cellEditor = 'ezCellEditor';
119474
+ col.editable = params => this.canEdit(params);
119475
+ col.suppressKeyboardEvent = (params) => {
119476
+ return params.event.key === KeyCode.ENTER;
119477
+ };
119478
+ return col;
119479
+ }
119480
+ getRequiredFields() {
119481
+ return this._gridOptions.columnApi.getAllDisplayedColumns().filter(c => {
119482
+ const fieldDefinition = this._dataUnit.getField(c.getColId());
119483
+ return fieldDefinition && fieldDefinition.required;
119484
+ }).map(c => c.getColId());
119485
+ }
119486
+ saveSuccess() {
119487
+ this.focusOnCell(this._targetEditionCell);
119488
+ this._lastCellEdited = undefined;
119489
+ this._targetEditionCell = undefined;
119490
+ this._isGridEdition = false;
119491
+ }
119492
+ saveFail(reason) {
119493
+ this.focusOnCell(this._lastCellEdited);
119494
+ this._isGridEdition = false;
119495
+ if (reason) {
119496
+ Promise.reject(reason);
119497
+ }
119498
+ }
119499
+ focusOnCell(cell) {
119500
+ if (cell == undefined) {
119501
+ return;
119502
+ }
119503
+ const { rowIndex, column } = cell;
119504
+ this._gridOptions.api.getDisplayedRowAtIndex(rowIndex).setSelected(true, true);
119505
+ this._gridOptions.api.clearRangeSelection();
119506
+ this._gridOptions.api.addCellRange({ rowStartIndex: rowIndex, rowEndIndex: rowIndex, columns: [column] });
119507
+ this._gridOptions.api.startEditingCell({ colKey: column.getColId(), rowIndex });
119508
+ this._gridOptions.api.setFocusedCell(rowIndex, column.getColId());
119509
+ const cellEditor = this._gridOptions.api.getCellEditorInstances()[0];
119510
+ if (cellEditor) {
119511
+ cellEditor.focusIn();
119512
+ }
119513
+ }
119514
+ onCellKeyDown(event) {
119515
+ const keyboardEvent = event.event;
119516
+ switch (keyboardEvent.key) {
119517
+ case KeyCode.ENTER:
119518
+ this.processEnterKey(keyboardEvent, event);
119519
+ break;
119520
+ case KeyCode.UP:
119521
+ this.editPreviousRow(event.api);
119522
+ break;
119523
+ case KeyCode.DOWN:
119524
+ this.editNextRow(event.api);
119525
+ break;
119526
+ }
119527
+ }
119528
+ processEnterKey(keyboardEvent, event) {
119529
+ const editionCell = event.api.getEditingCells()[0];
119530
+ if (!editionCell) {
119531
+ event.api.startEditingCell({ colKey: event.column.getColId(), rowIndex: event.rowIndex });
119532
+ return;
119533
+ }
119534
+ this.navigateByEnterKey(keyboardEvent);
119535
+ }
119536
+ nextEditionRow(rowIndex, column, backwards) {
119537
+ if (backwards) {
119538
+ rowIndex = rowIndex - 1;
119539
+ if (rowIndex < 0) {
119540
+ rowIndex = this._dataUnit.records.length - 1;
119541
+ }
119542
+ }
119543
+ else {
119544
+ rowIndex = rowIndex + 1;
119545
+ if (rowIndex >= this._dataUnit.records.length) {
119546
+ rowIndex = 0;
119547
+ }
119548
+ }
119549
+ this._targetEditionCell = new TargetEdition(rowIndex, column, true);
119550
+ this.finishEdition();
119551
+ }
119552
+ editPreviousRow(api) {
119553
+ this.moveEditionVertically(api, -1);
119554
+ }
119555
+ editNextRow(api) {
119556
+ this.moveEditionVertically(api, 1);
119557
+ }
119558
+ moveEditionVertically(api, offset) {
119559
+ const editionCell = api.getEditingCells()[0];
119560
+ if (!editionCell) {
119561
+ return;
119562
+ }
119563
+ const rowIndex = editionCell.rowIndex + offset;
119564
+ if (api.getDisplayedRowAtIndex(rowIndex)) {
119565
+ this._targetEditionCell = new TargetEdition(rowIndex, editionCell.column, offset < 0);
119566
+ this.finishEdition();
119567
+ }
119568
+ }
119569
+ finishEdition() {
119570
+ this._gridOptions.api.stopEditing();
119571
+ setTimeout(() => {
119572
+ //O Timeout foi inserido para permitir que o ciclo de finalização prossiga
119573
+ //pois precisamos aguardar o fim da edição para executar o autosave.
119574
+ this.proceedAutoSave();
119575
+ }, 0);
119576
+ }
119577
+ canEdit(params) {
119578
+ if (this._editionIsDisabled()) {
119579
+ return false;
119580
+ }
119581
+ return this.isColEditable(params.colDef.field);
119582
+ }
119583
+ isColEditable(fieldName) {
119584
+ const fieldDefinition = this._dataUnit.getField(fieldName);
119585
+ if (fieldDefinition) {
119586
+ return !fieldDefinition.readOnly;
119587
+ }
119588
+ return false;
119589
+ }
119590
+ isSecondClick(cellClicked) {
119591
+ if (!this._lastCellClicked) {
119592
+ return false;
119593
+ }
119594
+ if (this._lastCellClicked.column != cellClicked.column) {
119595
+ return false;
119596
+ }
119597
+ if (this._lastCellClicked.rowIndex != cellClicked.rowIndex) {
119598
+ return false;
119599
+ }
119600
+ return true;
119601
+ }
119602
+ onCellEditRequest(event) {
119603
+ const fieldName = event.colDef.field;
119604
+ const value = event.newValue;
119605
+ if (event.oldValue != value) {
119606
+ if (value instanceof Promise) {
119607
+ const fieldDescriptor = this._dataUnit.getField(event.colDef.colId);
119608
+ event.node.setData(Object.assign(Object.assign({}, event.data), { [fieldName]: (fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.userInterface) === core.UserInterface.SEARCH ? value : event.oldValue }));
119609
+ value.then(resolved => event.node.setData(Object.assign(Object.assign({}, event.data), { [fieldName]: resolved })));
119610
+ }
119611
+ else {
119612
+ event.node.setData(Object.assign(Object.assign({}, event.data), { [fieldName]: value }));
119613
+ }
119614
+ this._isGridEdition = true;
119615
+ this._dataUnit.setFieldValue(fieldName, value, [event.data.__record__id__]);
119616
+ this._lastCellEdited = { rowIndex: event.rowIndex, column: event.column, rowPinned: undefined };
119617
+ }
119618
+ }
119619
+ }
119620
+ class TargetEdition {
119621
+ constructor(rowIndex, column, backwards) {
119622
+ this.rowPinned = null;
119623
+ this.rowIndex = rowIndex;
119624
+ this.column = column;
119625
+ this.backwards = backwards;
119626
+ }
119627
+ }
119628
+
119190
119629
  class AgGridController {
119191
119630
  configFilterColumn(filterColumn) {
119192
119631
  this._filterColumn = filterColumn;
@@ -119222,6 +119661,9 @@ class AgGridController {
119222
119661
  getGridConfig() {
119223
119662
  return this._gridConfig;
119224
119663
  }
119664
+ getGridApi() {
119665
+ return this._gridOptions.api;
119666
+ }
119225
119667
  getSort() {
119226
119668
  const sortedColumns = [];
119227
119669
  this._gridOptions.columnApi
@@ -119282,6 +119724,7 @@ class AgGridController {
119282
119724
  this._doubleClickCallBack = options.onDoubleClick;
119283
119725
  this._multipleSelection = options.allowMultipleSelection;
119284
119726
  this._dataUnit = options.dataUnit;
119727
+ this._editionManager = new GridEditionManager(this._dataUnit, options.useEnterLikeTab, options.recordsValidator, options.editionIsDisabled);
119285
119728
  this._statusResolver = options.statusResolver;
119286
119729
  if (this._dataUnit) {
119287
119730
  this._dataUnit.sortingProvider = this;
@@ -119301,12 +119744,14 @@ class AgGridController {
119301
119744
  defaultColDef: {
119302
119745
  headerClass: 'ez-grid__cell-header',
119303
119746
  cellClass: 'ez-grid__cell-body',
119747
+ cellStyle: {
119748
+ height: '100%'
119749
+ }
119304
119750
  },
119305
- components: {
119306
- ezGridHeaderComponent: SelectionHeader,
119307
- ezGridCustomHeader: EzGridCustomHeader,
119308
- },
119751
+ components: Object.assign({ ezGridHeaderComponent: SelectionHeader, ezGridCustomHeader: EzGridCustomHeader }, this._editionManager.getComponents()),
119309
119752
  context: {
119753
+ editionManager: this._editionManager,
119754
+ dataUnit: this._dataUnit,
119310
119755
  headerCheckStatusGetter: () => this.getSelectionHeaderStatus(),
119311
119756
  headerCheckStatusSetter: (selectAll) => this.updateSelectionForAll(selectAll),
119312
119757
  },
@@ -119314,6 +119759,7 @@ class AgGridController {
119314
119759
  this.defineRowModelType(this._gridOptions, options);
119315
119760
  this.setOptionsEvents(this._gridOptions);
119316
119761
  this.setOptionsSupress(this._gridOptions);
119762
+ this._gridOptions = this._editionManager.configureGrid(this._gridOptions);
119317
119763
  if (this._enterprise) {
119318
119764
  this._grid = new Grid(container, this._gridOptions);
119319
119765
  }
@@ -119460,6 +119906,7 @@ class AgGridController {
119460
119906
  opt.onSelectionChanged = e => this.onSelectionChange(e);
119461
119907
  opt.onRowDoubleClicked = evt => this.onRowDoubleClick(evt);
119462
119908
  opt.onDragStopped = evt => this.onCallStateChange('columnMovedEnd', evt);
119909
+ opt.onCellClicked = evt => this.onCellClicked(evt);
119463
119910
  }
119464
119911
  setOptionsSupress(opt) {
119465
119912
  opt.suppressDragLeaveHidesColumns = true;
@@ -119763,7 +120210,7 @@ class AgGridController {
119763
120210
  else if (propSortable === false) {
119764
120211
  tooltip = 'Coluna não pode ser ordenada';
119765
120212
  }
119766
- return {
120213
+ return this._editionManager.configureColumn({
119767
120214
  headerName: source.label,
119768
120215
  field: source.name,
119769
120216
  sortable: propSortable,
@@ -119776,10 +120223,19 @@ class AgGridController {
119776
120223
  showColumnFilter: (leftPosition) => this.showFilterColumn({ columnName: source.name, columnLabel: source.label, leftPosition, filteredOptions: this._filteredColumns.get(source.name) }),
119777
120224
  },
119778
120225
  valueFormatter: params => {
120226
+ if (params.value == undefined) {
120227
+ return "";
120228
+ }
120229
+ if (params.value instanceof Promise) {
120230
+ return "Carregando...";
120231
+ }
120232
+ if (this._dataUnit) {
120233
+ return this._dataUnit.getFormattedValue(source.name, params.value);
120234
+ }
119779
120235
  return this.getFormatterByColumn(params, source);
119780
120236
  },
119781
120237
  cellStyle: this.getStyleByColumn(source),
119782
- };
120238
+ });
119783
120239
  }
119784
120240
  getInitCellStyle() {
119785
120241
  return {
@@ -119852,6 +120308,13 @@ class AgGridController {
119852
120308
  return params.value.toLocaleDateString();
119853
120309
  }
119854
120310
  }
120311
+ if ((source === null || source === void 0 ? void 0 : source.userInterface) === core.UserInterface.ELAPSEDTIME || (source === null || source === void 0 ? void 0 : source.userInterface) === core.UserInterface.TIME) {
120312
+ if (!!params.value) {
120313
+ const maskFormatter = new core.MaskFormatter("##:##");
120314
+ const formattedValue = String(params.value).padStart(4, '0');
120315
+ return maskFormatter.format(formattedValue);
120316
+ }
120317
+ }
119855
120318
  }
119856
120319
  onCallStateChange(type, e) {
119857
120320
  const finished = !('finished' in e) || e['finished'];
@@ -119866,6 +120329,13 @@ class AgGridController {
119866
120329
  this._columnStateChangeCallback(type, this.getColumnsState(), info);
119867
120330
  }
119868
120331
  }
120332
+ onCellClicked(event) {
120333
+ this._editionManager.verifyClickToEdition(event.api, {
120334
+ rowIndex: event.rowIndex,
120335
+ column: event.column,
120336
+ rowPinned: undefined
120337
+ });
120338
+ }
119869
120339
  isElementResize(e) {
119870
120340
  return e['target'] && e['target'].getAttribute('ref') === 'eResize';
119871
120341
  }
@@ -119883,6 +120353,7 @@ class AgGridController {
119883
120353
  if (this._selectionChangeCallback) {
119884
120354
  clearTimeout(this._selectionChangeDeboucing);
119885
120355
  this._selectionChangeDeboucing = window.setTimeout(() => {
120356
+ this._editionManager.proceedAutoSave();
119886
120357
  if (this._dataUnit) {
119887
120358
  if (event.context.selectionChangeQuietly) {
119888
120359
  const selectionInfo = this._dataUnit;
@@ -120004,6 +120475,9 @@ const EzGrid = class {
120004
120475
  this.dataUnit = undefined;
120005
120476
  this.statusResolver = undefined;
120006
120477
  this.columnfilterDataSource = undefined;
120478
+ this.useEnterLikeTab = false;
120479
+ this.recordsValidator = undefined;
120480
+ this.canEdit = true;
120007
120481
  }
120008
120482
  /**
120009
120483
  * Aplica a definição de colunas.
@@ -120237,6 +120711,9 @@ const EzGrid = class {
120237
120711
  serverURL: this.serverUrl,
120238
120712
  dataUnit: this.dataUnit,
120239
120713
  statusResolver: this.statusResolver,
120714
+ useEnterLikeTab: this.useEnterLikeTab,
120715
+ recordsValidator: this.recordsValidator,
120716
+ editionIsDisabled: () => !this.canEdit
120240
120717
  });
120241
120718
  if (this.config) {
120242
120719
  this.observeConfig(this.config);
@@ -120245,6 +120722,11 @@ const EzGrid = class {
120245
120722
  this.setEvents();
120246
120723
  this.componentReady.emit();
120247
120724
  this._gridController.configFilterColumn(this._filterColumn);
120725
+ this._container.addEventListener('focusout', (event) => {
120726
+ const api = this._gridController.getGridApi();
120727
+ if (api && !this._container.contains(event.relatedTarget))
120728
+ api.clearFocusedCell();
120729
+ });
120248
120730
  }
120249
120731
  componentWillRender() {
120250
120732
  this.configSelectionCounter();