@sankhyalabs/core 5.20.0-dev.7 → 5.20.0-dev.70

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 (182) hide show
  1. package/.docs/classes/Change.md +11 -11
  2. package/.docs/classes/ColumnFilterManager.md +145 -0
  3. package/.docs/classes/DataUnit.md +405 -137
  4. package/.docs/classes/DataUnitInMemoryLoader.md +303 -0
  5. package/.docs/classes/DataUnitLoaderUtils.md +151 -0
  6. package/.docs/classes/DateUtils.md +8 -8
  7. package/.docs/classes/FieldComparator.md +2 -2
  8. package/.docs/classes/IDBRepository.md +22 -0
  9. package/.docs/classes/LockManager.md +249 -0
  10. package/.docs/classes/MaskFormatter.md +66 -14
  11. package/.docs/classes/ObjectUtils.md +141 -0
  12. package/.docs/classes/OverflowWatcher.md +533 -0
  13. package/.docs/classes/SelectionInfo.md +25 -11
  14. package/.docs/classes/ServiceCanceledException.md +193 -0
  15. package/.docs/classes/ServiceUtils.md +67 -0
  16. package/.docs/classes/SilentException.md +193 -0
  17. package/.docs/classes/UserAgentUtils.md +15 -1
  18. package/.docs/enumerations/Action.md +41 -21
  19. package/.docs/enumerations/ChangeOperation.md +4 -4
  20. package/.docs/enumerations/LockManagerOperation.md +33 -0
  21. package/.docs/enumerations/OverflowDirection.md +29 -0
  22. package/.docs/enumerations/RECORD_DATE_FORMAT.md +27 -0
  23. package/.docs/enumerations/SelectionMode.md +2 -2
  24. package/.docs/enumerations/StorageType.md +37 -0
  25. package/.docs/globals.md +24 -0
  26. package/.docs/interfaces/DUActionInterceptor.md +1 -1
  27. package/.docs/interfaces/DataUnitInMemoryLoaderConfig.md +37 -0
  28. package/.docs/interfaces/IRepository.md +18 -0
  29. package/.docs/interfaces/LoadDataRequest.md +1 -1
  30. package/.docs/interfaces/OverFlowWatcherParams.md +67 -0
  31. package/.docs/interfaces/PageRequest.md +3 -3
  32. package/.docs/interfaces/PaginationInfo.md +25 -0
  33. package/.docs/interfaces/PaginationInfoBuilderParams.md +37 -0
  34. package/.docs/interfaces/QuickFilter.md +3 -3
  35. package/.docs/interfaces/Record.md +4 -4
  36. package/.docs/interfaces/SavedRecord.md +5 -5
  37. package/.docs/interfaces/WaitingChange.md +3 -3
  38. package/.docs/namespaces/MaskFormatter/type-aliases/MaskCharacter.md +1 -1
  39. package/.docs/namespaces/MaskFormatter/variables/MaskCharacter.md +1 -1
  40. package/.docs/type-aliases/DataUnitEventOptions.md +17 -0
  41. package/.docs/type-aliases/OnOverflowCallBack.md +25 -0
  42. package/.docs/variables/OVERFLOWED_CLASS_NAME.md +13 -0
  43. package/bun.lockb +0 -0
  44. package/dist/dataunit/DataUnit.d.ts +82 -12
  45. package/dist/dataunit/DataUnit.js +209 -67
  46. package/dist/dataunit/DataUnit.js.map +1 -1
  47. package/dist/dataunit/DataUnitHelper.js +6 -5
  48. package/dist/dataunit/DataUnitHelper.js.map +1 -1
  49. package/dist/dataunit/formatting/PrettyFormatter.js +14 -6
  50. package/dist/dataunit/formatting/PrettyFormatter.js.map +1 -1
  51. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.d.ts +9 -0
  52. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js +6 -0
  53. package/dist/dataunit/loader/DataUnitInMemoryLoaderConfig.js.map +1 -0
  54. package/dist/dataunit/loader/dataUnitInMemoryLoader.d.ts +25 -0
  55. package/dist/dataunit/loader/dataUnitInMemoryLoader.js +131 -0
  56. package/dist/dataunit/loader/dataUnitInMemoryLoader.js.map +1 -0
  57. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.d.ts +20 -0
  58. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js +62 -0
  59. package/dist/dataunit/loader/utils/dataUnitLoaderUtils.js.map +1 -0
  60. package/dist/dataunit/loading/LoadDataRequest.d.ts +1 -1
  61. package/dist/dataunit/loading/PaginationInfo.d.ts +8 -0
  62. package/dist/dataunit/metadata/DataType.js +3 -0
  63. package/dist/dataunit/metadata/DataType.js.map +1 -1
  64. package/dist/dataunit/sorting/FieldComparator.d.ts +2 -2
  65. package/dist/dataunit/sorting/FieldComparator.js +4 -9
  66. package/dist/dataunit/sorting/FieldComparator.js.map +1 -1
  67. package/dist/dataunit/state/action/DataUnitAction.d.ts +2 -0
  68. package/dist/dataunit/state/action/DataUnitAction.js +2 -0
  69. package/dist/dataunit/state/action/DataUnitAction.js.map +1 -1
  70. package/dist/dataunit/state/slice/InvalidFieldsSlice.js +2 -0
  71. package/dist/dataunit/state/slice/InvalidFieldsSlice.js.map +1 -1
  72. package/dist/dataunit/state/slice/LoadingControlSlice.js +16 -0
  73. package/dist/dataunit/state/slice/LoadingControlSlice.js.map +1 -1
  74. package/dist/dataunit/state/slice/RecordsSlice.js +1 -1
  75. package/dist/dataunit/state/slice/RecordsSlice.js.map +1 -1
  76. package/dist/dataunit/state/slice/SelectionSlice.js +4 -4
  77. package/dist/dataunit/state/slice/SelectionSlice.js.map +1 -1
  78. package/dist/exceptions/ServiceCanceledException.d.ts +14 -0
  79. package/dist/exceptions/ServiceCanceledException.js +13 -0
  80. package/dist/exceptions/ServiceCanceledException.js.map +1 -0
  81. package/dist/exceptions/SilentException.d.ts +14 -0
  82. package/dist/exceptions/SilentException.js +13 -0
  83. package/dist/exceptions/SilentException.js.map +1 -0
  84. package/dist/index.d.ts +12 -2
  85. package/dist/index.js +11 -1
  86. package/dist/index.js.map +1 -1
  87. package/dist/repository/IRepository.d.ts +6 -0
  88. package/dist/repository/indexeddb/IDBRepository.d.ts +1 -0
  89. package/dist/repository/indexeddb/IDBRepository.js +3 -0
  90. package/dist/repository/indexeddb/IDBRepository.js.map +1 -1
  91. package/dist/utils/CacheManager/index.d.ts +52 -0
  92. package/dist/utils/CacheManager/index.js +101 -0
  93. package/dist/utils/CacheManager/index.js.map +1 -0
  94. package/dist/utils/CacheManager/interfaces/index.d.ts +5 -0
  95. package/dist/utils/CacheManager/interfaces/index.js +7 -0
  96. package/dist/utils/CacheManager/interfaces/index.js.map +1 -0
  97. package/dist/utils/ColumnFilterManager.d.ts +19 -0
  98. package/dist/utils/ColumnFilterManager.js +73 -0
  99. package/dist/utils/ColumnFilterManager.js.map +1 -0
  100. package/dist/utils/DateUtils.js +3 -0
  101. package/dist/utils/DateUtils.js.map +1 -1
  102. package/dist/utils/ElementUtils.d.ts +2 -0
  103. package/dist/utils/ElementUtils.js +9 -0
  104. package/dist/utils/ElementUtils.js.map +1 -0
  105. package/dist/utils/LockManager.d.ts +58 -0
  106. package/dist/utils/LockManager.js +191 -0
  107. package/dist/utils/LockManager.js.map +1 -0
  108. package/dist/utils/MaskFormatter.d.ts +16 -1
  109. package/dist/utils/MaskFormatter.js +82 -2
  110. package/dist/utils/MaskFormatter.js.map +1 -1
  111. package/dist/utils/ObjectUtils.d.ts +38 -0
  112. package/dist/utils/ObjectUtils.js +51 -0
  113. package/dist/utils/ObjectUtils.js.map +1 -1
  114. package/dist/utils/OnboardingUtils.js +1 -1
  115. package/dist/utils/OnboardingUtils.js.map +1 -1
  116. package/dist/utils/OverflowWatcher/index.d.ts +59 -0
  117. package/dist/utils/OverflowWatcher/index.js +188 -0
  118. package/dist/utils/OverflowWatcher/index.js.map +1 -0
  119. package/dist/utils/OverflowWatcher/types/overflow-callback.d.ts +6 -0
  120. package/dist/utils/OverflowWatcher/types/overflow-callback.js +2 -0
  121. package/dist/utils/OverflowWatcher/types/overflow-callback.js.map +1 -0
  122. package/dist/utils/OverflowWatcher/types/overflow-direction.d.ts +7 -0
  123. package/dist/utils/OverflowWatcher/types/overflow-direction.js +9 -0
  124. package/dist/utils/OverflowWatcher/types/overflow-direction.js.map +1 -0
  125. package/dist/utils/ServiceUtils.d.ts +24 -0
  126. package/dist/utils/ServiceUtils.js +40 -0
  127. package/dist/utils/ServiceUtils.js.map +1 -0
  128. package/dist/utils/SortingUtils.d.ts +9 -0
  129. package/dist/utils/SortingUtils.js +24 -0
  130. package/dist/utils/SortingUtils.js.map +1 -0
  131. package/dist/utils/UserAgentUtils/index.d.ts +1 -0
  132. package/dist/utils/UserAgentUtils/index.js +5 -0
  133. package/dist/utils/UserAgentUtils/index.js.map +1 -1
  134. package/jest.config.ts +2 -0
  135. package/package.json +2 -1
  136. package/reports/test-report.xml +215 -0
  137. package/setupTests.js +7 -0
  138. package/sonar-project.properties +6 -3
  139. package/src/dataunit/DataUnit.ts +250 -82
  140. package/src/dataunit/DataUnitHelper.ts +6 -5
  141. package/src/dataunit/formatting/PrettyFormatter.ts +15 -6
  142. package/src/dataunit/loader/DataUnitInMemoryLoaderConfig.ts +10 -0
  143. package/src/dataunit/loader/dataUnitInMemoryLoader.ts +176 -0
  144. package/src/dataunit/loader/utils/dataUnitLoaderUtils.ts +86 -0
  145. package/src/dataunit/loading/LoadDataRequest.ts +1 -1
  146. package/src/dataunit/loading/PaginationInfo.ts +10 -0
  147. package/src/dataunit/metadata/DataType.ts +3 -0
  148. package/src/dataunit/sorting/FieldComparator.ts +18 -32
  149. package/src/dataunit/state/action/DataUnitAction.ts +2 -0
  150. package/src/dataunit/state/slice/InvalidFieldsSlice.ts +2 -0
  151. package/src/dataunit/state/slice/LoadingControlSlice.ts +42 -0
  152. package/src/dataunit/state/slice/RecordsSlice.ts +1 -1
  153. package/src/dataunit/state/slice/SelectionSlice.ts +4 -4
  154. package/src/dataunit/state/slice/test/RecordsSlice.spec.ts +45 -0
  155. package/src/dataunit/test/DataUnit.spec.ts +44 -0
  156. package/src/exceptions/ServiceCanceledException.ts +25 -0
  157. package/src/exceptions/SilentException.ts +25 -0
  158. package/src/index.ts +29 -1
  159. package/src/repository/IRepository.ts +7 -0
  160. package/src/repository/indexeddb/IDBRepository.ts +4 -0
  161. package/src/utils/CacheManager/index.ts +103 -0
  162. package/src/utils/CacheManager/interfaces/index.ts +5 -0
  163. package/src/utils/ColumnFilterManager.ts +104 -0
  164. package/src/utils/DateUtils.ts +3 -0
  165. package/src/utils/ElementUtils.ts +10 -0
  166. package/src/utils/LockManager.ts +213 -0
  167. package/src/utils/MaskFormatter.ts +93 -2
  168. package/src/utils/ObjectUtils.ts +56 -0
  169. package/src/utils/OnboardingUtils.ts +1 -1
  170. package/src/utils/OverflowWatcher/index.ts +243 -0
  171. package/src/utils/OverflowWatcher/types/overflow-callback.ts +6 -0
  172. package/src/utils/OverflowWatcher/types/overflow-direction.ts +7 -0
  173. package/src/utils/ServiceUtils.ts +36 -0
  174. package/src/utils/SortingUtils.ts +30 -0
  175. package/src/utils/UserAgentUtils/index.ts +6 -1
  176. package/src/utils/test/objectUtils.spec.ts +109 -0
  177. package/test/dataunit/formatting/PrettyFormatter.spec.ts +177 -0
  178. package/test/dataunit/loader/dataUnitInMemoryLoader.spec.ts +221 -0
  179. package/test/dataunit/loader/utils/dataUnitLoaderUtils.spec.ts +158 -0
  180. package/test/util/ColumnFilterManager.spec.ts +133 -0
  181. package/test/util/ElementUtils.spec.ts +34 -0
  182. package/test/util/OverflowWatcher.spec.ts +152 -0
@@ -29,6 +29,9 @@ import { v4 as uuid } from "uuid";
29
29
  import { DataUnitStorage } from "./DataUnitStorage.js";
30
30
  import { getInvalidFieldMessage, InvalidFieldsReducer } from "./state/slice/InvalidFieldsSlice.js";
31
31
  import { getLoadingProperties, LoadingPropertiesReducer } from "./state/slice/LoadingProperties.js";
32
+ import SortingUtils from "../utils/SortingUtils.js";
33
+ import ServiceCanceledException from "../exceptions/ServiceCanceledException.js";
34
+ import SilentException from "../exceptions/SilentException.js";
32
35
  /***
33
36
  * `DataUnit`: Atua como uma camada de abstração entre o back-end e a interface do usuário.
34
37
  */
@@ -37,6 +40,8 @@ export default class DataUnit {
37
40
  var _a;
38
41
  this._childByName = new Map();
39
42
  this._savingLockers = [];
43
+ this._waitingToReload = false;
44
+ this._cancelPagination = false;
40
45
  /**
41
46
  *
42
47
  * Trata as Actions do DataUnit Parent
@@ -50,6 +55,8 @@ export default class DataUnit {
50
55
  case Action.NEXT_SELECTED:
51
56
  case Action.PREVIOUS_SELECTED:
52
57
  case Action.DATA_LOADED:
58
+ case Action.RECORDS_ADDED:
59
+ case Action.EDITION_CANCELED:
53
60
  this.clearDataUnit();
54
61
  const selectedRecord = (_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.getSelectedRecord();
55
62
  if (selectedRecord != undefined && !this.isNewRecord(selectedRecord.__record__id__)) {
@@ -75,11 +82,12 @@ export default class DataUnit {
75
82
  InvalidFieldsReducer,
76
83
  SnapshotReducer
77
84
  ]);
78
- this._observers = [];
85
+ this._observers = new Map();
79
86
  this._filterProviders = new Map();
80
87
  this._sortingProvider = undefined;
81
88
  this._defaultSorting = [];
82
- this._interceptors = [];
89
+ this._allowReleaseCallbacks = true;
90
+ this._interceptors = new Map();
83
91
  this._parentDataUnit = parentDataUnit;
84
92
  (_a = this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.subscribe(this.onDataUnitParentEvent);
85
93
  this._loadingLockers = [];
@@ -107,10 +115,12 @@ export default class DataUnit {
107
115
  * - Sorting Providers
108
116
  */
109
117
  releaseCallbacks() {
110
- this._observers = [];
118
+ if (!this._allowReleaseCallbacks)
119
+ return;
120
+ this._observers = new Map();
111
121
  this._filterProviders = new Map();
112
122
  this._sortingProvider = undefined;
113
- this._interceptors = [];
123
+ this._interceptors = new Map();
114
124
  }
115
125
  /**
116
126
  * Adiciona uma propriedade transacional que será envida aos
@@ -135,6 +145,31 @@ export default class DataUnit {
135
145
  get dataUnitId() {
136
146
  return this._uuid;
137
147
  }
148
+ /**
149
+ * Retorna se o dataUnit está com recarregamento pendente.
150
+ */
151
+ isWaitingToReload() {
152
+ return this._waitingToReload;
153
+ }
154
+ /**
155
+ * Define se o dataUnit tem um recarregamento pendente.
156
+ * @param isWaiting
157
+ */
158
+ setWaitingToReload(isWaiting) {
159
+ this._waitingToReload = isWaiting;
160
+ }
161
+ /**
162
+ * Informa se a paginação deve ser cancelada.
163
+ */
164
+ get cancelPagination() {
165
+ return this._cancelPagination;
166
+ }
167
+ /**
168
+ * Informa se a paginação deve ser cancelada.
169
+ */
170
+ set cancelPagination(cancelPagination) {
171
+ this._cancelPagination = cancelPagination;
172
+ }
138
173
  /**
139
174
  *
140
175
  * Obtém o nome de identificação do DataUnit (geralmente em formato de URI - Uniform Resource Identifier).
@@ -203,7 +238,7 @@ export default class DataUnit {
203
238
  if (yield this.dispatchAction(Action.LOADING_DATA, request, executionCtx)) {
204
239
  if (this.dataLoader) {
205
240
  this.dataLoader(this, request).then((response) => __awaiter(this, void 0, void 0, function* () {
206
- yield this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection, filters: request.filters }), executionCtx);
241
+ yield this.dispatchAction(Action.DATA_LOADED, Object.assign(Object.assign({}, response), { keepSelection: request.keepSelection, filters: request.filters, selectFirstRecord }), executionCtx);
207
242
  yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
208
243
  if (selectFirstRecord) {
209
244
  this.requestSelectFirst(executionCtx);
@@ -269,13 +304,16 @@ export default class DataUnit {
269
304
  loadData(quickFilter, executionCtx, checkLastFilter, source, selectFirstRecord) {
270
305
  return __awaiter(this, void 0, void 0, function* () {
271
306
  yield this.processLoadingLockers();
272
- if (this._parentDataUnit && !this._parentDataUnit.getSelectedRecord()) {
273
- if (this.records) {
274
- this.clearDataUnit();
307
+ if (this._parentDataUnit) {
308
+ const parentRecord = this._parentDataUnit.getSelectedRecord();
309
+ if (parentRecord == undefined || this._parentDataUnit.isNewRecord(parentRecord.__record__id__)) {
310
+ if (this.records) {
311
+ this.clearDataUnit();
312
+ }
313
+ return Promise.resolve({
314
+ records: []
315
+ });
275
316
  }
276
- return Promise.resolve({
277
- records: []
278
- });
279
317
  }
280
318
  const loadDataRequest = this.getLoadDataRequest(quickFilter, source);
281
319
  return this.executeLoadData(loadDataRequest, executionCtx, checkLastFilter, selectFirstRecord);
@@ -293,6 +331,9 @@ export default class DataUnit {
293
331
  */
294
332
  gotoPage(page, executionCtx) {
295
333
  return __awaiter(this, void 0, void 0, function* () {
334
+ if (this._pageSize === 0) {
335
+ return;
336
+ }
296
337
  let request = getCurrentRequest(this._stateManager);
297
338
  if (!request) {
298
339
  request = {
@@ -405,7 +446,16 @@ export default class DataUnit {
405
446
  Promise.all(dispatchPromisses).then(() => resolve());
406
447
  }).catch(cause => {
407
448
  const { errorCode } = cause;
449
+ this.dispatchAction(Action.SAVING_ERROR);
408
450
  this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
451
+ if (cause instanceof ServiceCanceledException) {
452
+ console.debug("Service canceled: " + cause.message);
453
+ resolve();
454
+ }
455
+ if (cause instanceof SilentException) {
456
+ fail(cause);
457
+ return;
458
+ }
409
459
  fail(new ErrorException("Erro ao salvar alterações", cause, errorCode));
410
460
  });
411
461
  }
@@ -509,9 +559,10 @@ export default class DataUnit {
509
559
  const currentRecordsKeys = Array.from(getCurrentRecords(this._stateManager).keys());
510
560
  const removedIndex = recordIds
511
561
  .map(id => currentRecordsKeys.indexOf(id))
512
- .filter(index => index > -1);
562
+ .filter(index => index > -1)
563
+ .sort((a, b) => a - b);
513
564
  const nextIndex = Math.min(removedIndex.slice(-1)[0] + 1, currentRecordsKeys.length);
514
- const selectionAfterRemove = [currentRecordsKeys[nextIndex]];
565
+ const selectionAfterRemove = currentRecordsKeys[nextIndex] ? [currentRecordsKeys[nextIndex]] : [];
515
566
  this.dispatchAction(Action.RECORDS_REMOVED, { records: removedIds, cachedRecords, removedIndex, buffered: false, selectionAfterRemove }, executionCtx);
516
567
  this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
517
568
  resolve(removedIds);
@@ -591,7 +642,7 @@ export default class DataUnit {
591
642
  *
592
643
  */
593
644
  addInterceptor(interceptor) {
594
- this._interceptors.push(interceptor);
645
+ this._interceptors.set(interceptor.interceptAction.toString(), interceptor);
595
646
  }
596
647
  /**
597
648
  *
@@ -601,7 +652,7 @@ export default class DataUnit {
601
652
  *
602
653
  */
603
654
  removeInterceptor(interceptor) {
604
- this._interceptors = this._interceptors.filter(i => i !== interceptor);
655
+ this._interceptors.delete(interceptor.interceptAction.toString());
605
656
  }
606
657
  /**
607
658
  *
@@ -700,7 +751,8 @@ export default class DataUnit {
700
751
  *
701
752
  */
702
753
  set records(records) {
703
- this.dispatchAction(Action.DATA_LOADED, { records }, undefined);
754
+ const paginationInfo = this.getPaginationInfo();
755
+ this.dispatchAction(Action.DATA_LOADED, { records, paginationInfo }, undefined);
704
756
  }
705
757
  /**
706
758
  *
@@ -787,6 +839,9 @@ export default class DataUnit {
787
839
  copySelected(executionCtx) {
788
840
  const selectionInfo = this.getSelectionInfo();
789
841
  if (selectionInfo) {
842
+ if (selectionInfo.isAllRecords()) {
843
+ throw new Error("Erro interno: Impossível copiar os registros selecionados pois a seleção atual é virtual.");
844
+ }
790
845
  const selectedRecords = selectionInfo.records;
791
846
  if (selectedRecords) {
792
847
  this.dispatchAction(Action.RECORDS_COPIED, prepareCopiedRecord(this._stateManager, selectedRecords, this.getParentRecordId()), executionCtx);
@@ -845,27 +900,35 @@ export default class DataUnit {
845
900
  * @param fieldName -Identificador do campo a ser modificado.
846
901
  * @param newValue - Valor a ser inserido no campo.
847
902
  * @param records - Indica quais registros foram afetados pela alteração no valor do campo.
903
+ * @param options - Configurações do evento
848
904
  * @returns - Promise que será resolvida quando o novo valor for persistido no state.
849
905
  *
850
- */
851
- setFieldValue(fieldName, newValue, records) {
906
+ */
907
+ setFieldValue(fieldName, newValue, records, options) {
852
908
  return __awaiter(this, void 0, void 0, function* () {
853
- if (!this.hasNewRecord() && !this.getSelectedRecord())
909
+ const noRecordSelected = !this.hasNewRecord() && !this.getSelectedRecord();
910
+ const suppressCreateNewRecord = options === null || options === void 0 ? void 0 : options.suppressCreateNewRecord;
911
+ if (noRecordSelected && suppressCreateNewRecord)
912
+ return Promise.resolve(false);
913
+ if (noRecordSelected)
854
914
  yield this.addRecord();
855
915
  const typedValue = this.validateAndTypeValue(fieldName, newValue);
856
916
  const currentValue = this.getFieldValue(fieldName);
917
+ if (!(newValue instanceof Promise) && ObjectUtils.hasEquivalentProps(currentValue, typedValue)) {
918
+ return Promise.resolve(false);
919
+ }
857
920
  if (newValue instanceof Promise) {
858
921
  const promise = new Promise(accept => {
859
922
  newValue.then(resolvedValue => {
860
923
  this.dispatchAction(Action.DATA_RESOLVED, { [fieldName]: resolvedValue, records }, undefined);
861
- accept(this.setFieldValue(fieldName, resolvedValue, records));
924
+ accept(this.setFieldValue(fieldName, resolvedValue, records, options));
862
925
  });
863
926
  });
864
927
  this._savingLockers.push(promise);
865
928
  return promise;
866
929
  }
867
930
  if (currentValue !== typedValue) {
868
- const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined);
931
+ const promise = this.dispatchAction(Action.DATA_CHANGED, { [fieldName]: typedValue, records }, undefined, options);
869
932
  this._savingLockers.push(promise);
870
933
  return promise;
871
934
  }
@@ -884,6 +947,17 @@ export default class DataUnit {
884
947
  setInvalidField(fieldName, message, recordId) {
885
948
  this.dispatchAction(Action.FIELD_INVALIDATED, { fieldName, message, recordId }, undefined);
886
949
  }
950
+ /**
951
+ *
952
+ * Cancela o saving exibindo os campos invalidos.
953
+ *
954
+ * @param filds - Lista dos campos
955
+ * @param recordId - Indica qual registro está com os campos inválido.
956
+ *
957
+ */
958
+ savingCanceled(fields, recordId) {
959
+ this.dispatchAction(Action.SAVING_CANCELED, { fields, recordId }, undefined);
960
+ }
887
961
  /**
888
962
  *
889
963
  * Limpa campos inválidos.
@@ -982,7 +1056,7 @@ export default class DataUnit {
982
1056
  setSelection(selection, executionCtx) {
983
1057
  return new Promise(resolve => {
984
1058
  this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection }, executionCtx)
985
- .then(() => resolve(getSelectionInfo(this._stateManager)));
1059
+ .then(() => resolve(this.getSelectionInfo()));
986
1060
  });
987
1061
  }
988
1062
  /**
@@ -1001,30 +1075,44 @@ export default class DataUnit {
1001
1075
  *
1002
1076
  * @param selection - IDs dos registros selecionados no snapshot atual
1003
1077
  * @param executionCtx - Contexto de execução da seleção dos registros do DataUnit.
1004
- *
1005
1078
  * @returns - Informações sobre a seleção.
1006
1079
  */
1007
1080
  updatePageSelection(selection, executionCtx) {
1008
- if (!selection) {
1081
+ if (!selection)
1009
1082
  return Promise.resolve(this.getSelectionInfo());
1010
- }
1011
1083
  return new Promise(resolve => {
1012
- const newSelection = new Set(getSelection(this._stateManager));
1013
- const currentRecords = getCurrentRecords(this._stateManager) || new Map();
1014
- Array.from(currentRecords.keys()).forEach(recordId => {
1015
- if (selection.includes(recordId)) {
1016
- newSelection.add(recordId);
1017
- }
1018
- else {
1019
- newSelection.delete(recordId);
1020
- }
1021
- });
1084
+ const newSelection = new Set(selection);
1022
1085
  this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) }, executionCtx)
1023
- .then(() => {
1024
- resolve(this.getSelectionInfo());
1025
- });
1086
+ .then(() => resolve(this.getSelectionInfo()));
1026
1087
  });
1027
1088
  }
1089
+ updatePageSelectionAll(addRecords) {
1090
+ return new Promise(resolve => {
1091
+ const newSelection = new Set();
1092
+ const cachedSelection = getSelection(this._stateManager);
1093
+ cachedSelection.forEach(item => newSelection.add(item));
1094
+ const recordsIds = this.records.map(r => r.__record__id__);
1095
+ recordsIds.forEach(id => addRecords ? newSelection.add(id) : newSelection.delete(id));
1096
+ this.dispatchAction(Action.SELECTION_CHANGED, { type: "id", selection: Array.from(newSelection) })
1097
+ .then(() => resolve(this.getSelectionInfo()));
1098
+ });
1099
+ }
1100
+ /**
1101
+ * Seleciona todos os registros da página.
1102
+ *
1103
+ * @returns - Informações sobre a seleção.
1104
+ */
1105
+ selectAllRecords() {
1106
+ return this.updatePageSelectionAll(true);
1107
+ }
1108
+ /**
1109
+ * Desseleciona todos os registros da página.
1110
+ *
1111
+ * @returns - Informações sobre a seleção.
1112
+ */
1113
+ unSelectAllRecords() {
1114
+ return this.updatePageSelectionAll(false);
1115
+ }
1028
1116
  /**
1029
1117
  *
1030
1118
  * Obtém informações sobre a seleção atual.
@@ -1033,7 +1121,14 @@ export default class DataUnit {
1033
1121
  *
1034
1122
  **/
1035
1123
  getSelectionInfo() {
1036
- return getSelectionInfo(this._stateManager);
1124
+ var _a;
1125
+ const selectionInfo = getSelectionInfo(this._stateManager);
1126
+ selectionInfo.getAllRecords = () => { var _a; return (_a = this.allRecordsLoader) === null || _a === void 0 ? void 0 : _a.call(this, this); };
1127
+ if (selectionInfo.sort != undefined && selectionInfo.sort.length > 0) {
1128
+ const sortingFunction = SortingUtils.getSortingFunction(this, selectionInfo.sort);
1129
+ (_a = selectionInfo.records) === null || _a === void 0 ? void 0 : _a.sort(sortingFunction);
1130
+ }
1131
+ return selectionInfo;
1037
1132
  }
1038
1133
  /**
1039
1134
  *
@@ -1045,6 +1140,14 @@ export default class DataUnit {
1045
1140
  getSelectedRecord() {
1046
1141
  return getSelectedRecord(this._stateManager);
1047
1142
  }
1143
+ /**
1144
+ * Retorna o DataUnit pai
1145
+ *
1146
+ * @returns DataUnit pai ou undefined
1147
+ */
1148
+ getParentDataUnit() {
1149
+ return this._parentDataUnit;
1150
+ }
1048
1151
  /**
1049
1152
  *
1050
1153
  * Limpa todos os registros do DataUnit
@@ -1132,12 +1235,25 @@ export default class DataUnit {
1132
1235
  *
1133
1236
  * Retorna se existe algum tipo de alteração pendente.
1134
1237
  *
1238
+ * @param ignoreChildren: Define se deverá ignorar alterações pendentes no DataUnit filho.
1135
1239
  * @returns Verdadeiro se existir alterações pendentes.
1136
1240
  *
1137
1241
  */
1138
- isDirty() {
1242
+ isDirty(ignoreChildren) {
1243
+ if (ignoreChildren)
1244
+ return isDirty(this._stateManager);
1139
1245
  return isDirty(this._stateManager) || this.childrenIsDirty();
1140
1246
  }
1247
+ /**
1248
+ *
1249
+ * Retorna se existe alterações pendentes no DataUnit pai.
1250
+ *
1251
+ * @returns Verdadeiro se existir alterações pendentes e Falso caso não exista alterações ou não exista DataUnit pai.
1252
+ *
1253
+ */
1254
+ isParentDirty() {
1255
+ return this._parentDataUnit ? this._parentDataUnit.isDirty(true) : false;
1256
+ }
1141
1257
  /**
1142
1258
  *
1143
1259
  * Retorna se existe algum DataUnit detail com alterações pendentes.
@@ -1299,18 +1415,18 @@ export default class DataUnit {
1299
1415
  * @returns - Verdadeiro se ação iniciada.
1300
1416
  *
1301
1417
  */
1302
- dispatchAction(actionType, payload, executionCtx) {
1418
+ dispatchAction(actionType, payload, executionCtx, options) {
1303
1419
  return __awaiter(this, void 0, void 0, function* () {
1304
1420
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
1305
1421
  let action = new DataUnitAction(actionType, payload);
1306
1422
  if (executionCtx && executionCtx.before) {
1307
1423
  action = executionCtx.before(action);
1308
1424
  }
1309
- if (action && this._interceptors && this._interceptors.length > 0) {
1425
+ if (action && this._interceptors && this._interceptors.size > 0) {
1310
1426
  action = yield this.intercept(action, this._interceptors.values());
1311
1427
  }
1312
1428
  if (action) {
1313
- this.doDispatchAction(action);
1429
+ this.doDispatchAction(action, options);
1314
1430
  if (executionCtx && executionCtx.after) {
1315
1431
  executionCtx.after(action);
1316
1432
  }
@@ -1350,17 +1466,14 @@ export default class DataUnit {
1350
1466
  * @param action - Ações em execução no DataUnit.
1351
1467
  *
1352
1468
  */
1353
- doDispatchAction(action) {
1469
+ doDispatchAction(action, options = {}) {
1354
1470
  var _a;
1355
1471
  this._stateManager.process(action);
1356
1472
  (_a = this === null || this === void 0 ? void 0 : this._parentDataUnit) === null || _a === void 0 ? void 0 : _a.dispatchAction(Action.CHILD_CHANGED, { srcAction: action, srcDataUnit: this });
1357
1473
  this._observers.forEach(f => {
1358
- /*
1359
- if some observer throws exceptions,
1360
- should be continued
1361
- */
1474
+ //if some observer throws exceptions, should be continued
1362
1475
  try {
1363
- f(action);
1476
+ f(action, options);
1364
1477
  }
1365
1478
  catch (e) {
1366
1479
  console.warn("[DataUnit] error while call observer", e);
@@ -1395,20 +1508,36 @@ export default class DataUnit {
1395
1508
  * Ela vai ser chamada sempre que uma ação for despachada (dispatchAction()).
1396
1509
  *
1397
1510
  * @param observer - Função que recebe como parâmetro as ações que serão monitoradas.
1398
- *
1511
+ * @param uuid - Identificador do observer. Quando não informado, será gerado um identificador aleatório.
1399
1512
  */
1400
- subscribe(observer) {
1401
- this._observers.push(observer);
1513
+ subscribe(observer, uuid) {
1514
+ if (uuid) {
1515
+ this._observers.set(uuid, observer);
1516
+ }
1517
+ else {
1518
+ uuid = StringUtils.generateUUID();
1519
+ this._observers.set(uuid, observer);
1520
+ }
1521
+ return uuid;
1402
1522
  }
1403
1523
  /**
1404
1524
  *
1405
1525
  * Remove um observer existente.
1406
1526
  *
1407
1527
  * @param observer - Observer que se deseja remover.
1408
- *
1528
+ * @param uuid - Identificador do observer. Quando não informado o delete removera com base no equals do observer.
1409
1529
  */
1410
- unsubscribe(observer) {
1411
- this._observers = this._observers.filter(f => f !== observer);
1530
+ unsubscribe(observer, uuid) {
1531
+ if (uuid) {
1532
+ this._observers.delete(uuid);
1533
+ }
1534
+ else {
1535
+ this._observers.forEach((valor, chave) => {
1536
+ if (valor == observer) {
1537
+ this._observers.delete(chave);
1538
+ }
1539
+ });
1540
+ }
1412
1541
  }
1413
1542
  /**
1414
1543
  *
@@ -1420,19 +1549,21 @@ export default class DataUnit {
1420
1549
  reloadCurrentRecord() {
1421
1550
  return new Promise((resolve, fail) => __awaiter(this, void 0, void 0, function* () {
1422
1551
  const selection = getSelection(this._stateManager);
1423
- this.dispatchAction(Action.LOADING_RECORD, selection);
1552
+ yield this.dispatchAction(Action.LOADING_RECORD, selection);
1424
1553
  if (!this.recordLoader || !this.dataLoader) {
1425
- this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1554
+ yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1555
+ resolve([]);
1426
1556
  return;
1427
1557
  }
1428
- this.recordLoader(this, selection).then(response => {
1429
- this.dispatchAction(Action.RECORD_LOADED, response);
1430
- this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1431
- }).catch(cause => {
1432
- this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1558
+ this.recordLoader(this, selection).then((response) => __awaiter(this, void 0, void 0, function* () {
1559
+ yield this.dispatchAction(Action.RECORD_LOADED, response);
1560
+ yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1561
+ resolve(response);
1562
+ })).catch((cause) => __awaiter(this, void 0, void 0, function* () {
1563
+ yield this.dispatchAction(Action.LOADING_PROPERTIES_CLEANED);
1433
1564
  const { errorCode } = cause;
1434
1565
  fail(new ErrorException("Erro ao recarregar registro", cause, errorCode));
1435
- });
1566
+ }));
1436
1567
  }));
1437
1568
  }
1438
1569
  /**
@@ -1515,10 +1646,11 @@ export default class DataUnit {
1515
1646
  * @param fieldName - nome do campo para ficar invisível.
1516
1647
  *
1517
1648
  */
1518
- hideField(fieldName) {
1649
+ hideField(fieldName, options) {
1519
1650
  const fieldDescriptor = this.getField(fieldName);
1520
1651
  if ((fieldDescriptor === null || fieldDescriptor === void 0 ? void 0 : fieldDescriptor.visible) === true) {
1521
1652
  fieldDescriptor.visible = false;
1653
+ fieldDescriptor.properties = Object.assign(Object.assign({}, fieldDescriptor.properties), { visibleOnConfig: options.visibleOnConfig });
1522
1654
  this.metadata = Object.assign({}, this.metadata);
1523
1655
  }
1524
1656
  }
@@ -1570,10 +1702,13 @@ export default class DataUnit {
1570
1702
  getSelection() {
1571
1703
  console.warn("DataUnit: O método `getSelection` foi descontinuado. Use o método `getSelectionInfo`.");
1572
1704
  const selection = this.getSelectionInfo();
1573
- if (selection != undefined && selection.isAllRecords()) {
1705
+ if (selection == undefined) {
1706
+ return [];
1707
+ }
1708
+ if (selection.isAllRecords()) {
1574
1709
  throw new Error("Erro interno: Impossível retornar os registros selecionados. A seleção atual é virtual. Use o método `getSelectionInfo`.");
1575
1710
  }
1576
- return (selection === null || selection === void 0 ? void 0 : selection.recordIds) || [];
1711
+ return selection === null || selection === void 0 ? void 0 : selection.recordIds;
1577
1712
  }
1578
1713
  /**
1579
1714
  * Adiciona um campo stand-alone ao dataUnit.
@@ -1603,6 +1738,9 @@ export default class DataUnit {
1603
1738
  }));
1604
1739
  return loadingLockerResolver || Promise.resolve;
1605
1740
  }
1741
+ set allowReleaseCallbacks(allow) {
1742
+ this._allowReleaseCallbacks = allow;
1743
+ }
1606
1744
  processLoadingLockers() {
1607
1745
  return __awaiter(this, void 0, void 0, function* () {
1608
1746
  if (this._loadingLockers.length) {
@@ -1613,6 +1751,7 @@ export default class DataUnit {
1613
1751
  }
1614
1752
  }
1615
1753
  DataUnit.CHANGING_PAGE_LOADING_SOURCE = "CHANGING_PAGE_LOADING_SOURCE";
1754
+ DataUnit.ALL_RECORDS_SELECTION_SOURCE = "ALL_RECORDS_SELECTION_SOURCE";
1616
1755
  DataUnit.DEFAULT_DATAUNIT_NAME = "dataunit";
1617
1756
  export var ChangeOperation;
1618
1757
  (function (ChangeOperation) {
@@ -1698,7 +1837,10 @@ export class SelectionInfo {
1698
1837
  }
1699
1838
  get records() {
1700
1839
  if (this.isAllRecords()) {
1701
- throw new Error("Erro interno: [ALL_RECORDS] - Impossível retornar os registros selecionados numa seleção virtual.");
1840
+ if (this.getAllRecords != undefined) {
1841
+ return this.getAllRecords();
1842
+ }
1843
+ throw new Error("Erro interno: Impossível retornar os registros selecionados numa seleção virtual.");
1702
1844
  }
1703
1845
  return this._records;
1704
1846
  }