@sankhyalabs/sankhyablocks 5.1.3 → 5.2.0

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 (136) hide show
  1. package/dist/cjs/{SnkMessageBuilder-47185d5d.js → SnkMessageBuilder-c6bd8bc7.js} +9 -2
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  4. package/dist/cjs/snk-application.cjs.entry.js +1 -1
  5. package/dist/cjs/snk-config-options.cjs.entry.js +2 -1
  6. package/dist/cjs/snk-configurator.cjs.entry.js +3 -2
  7. package/dist/cjs/snk-crud.cjs.entry.js +10 -3
  8. package/dist/cjs/snk-data-exporter.cjs.entry.js +10 -1
  9. package/dist/cjs/snk-data-unit-3b6ab2ad.js +436 -0
  10. package/dist/cjs/snk-data-unit.cjs.entry.js +6 -411
  11. package/dist/cjs/snk-detail-view.cjs.entry.js +7 -2
  12. package/dist/cjs/snk-field-config.cjs.entry.js +2 -4
  13. package/dist/cjs/snk-filter-bar.cjs.entry.js +3 -1
  14. package/dist/cjs/snk-filter-param-config.cjs.entry.js +2 -1
  15. package/dist/cjs/snk-form-config.cjs.entry.js +6 -5
  16. package/dist/cjs/snk-form.cjs.entry.js +2 -1
  17. package/dist/cjs/snk-grid.cjs.entry.js +6 -4
  18. package/dist/cjs/{snk-guides-viewer-6225bb73.js → snk-guides-viewer-8a6743d6.js} +8 -5
  19. package/dist/cjs/snk-guides-viewer.cjs.entry.js +1 -1
  20. package/dist/cjs/snk-simple-crud.cjs.entry.js +2 -1
  21. package/dist/cjs/snk-tab-config.cjs.entry.js +2 -1
  22. package/dist/cjs/snk-taskbar.cjs.entry.js +3 -1
  23. package/dist/collection/components/snk-application/snk-application.js +2 -2
  24. package/dist/collection/components/snk-configurator/snk-configurator.js +23 -2
  25. package/dist/collection/components/snk-crud/snk-crud.js +30 -3
  26. package/dist/collection/components/snk-crud/subcomponents/snk-detail-view.js +27 -2
  27. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +29 -6
  28. package/dist/collection/components/snk-data-exporter/snk-data-exporter.js +29 -1
  29. package/dist/collection/components/snk-data-unit/snk-data-unit.js +64 -3
  30. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +23 -1
  31. package/dist/collection/components/snk-form/snk-form.js +22 -1
  32. package/dist/collection/components/snk-form/subcomponents/snk-config-options/snk-config-options.js +22 -1
  33. package/dist/collection/components/snk-form/subcomponents/snk-field-config/snk-field-config.js +23 -5
  34. package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.js +26 -5
  35. package/dist/collection/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.js +22 -1
  36. package/dist/collection/components/snk-grid/snk-grid.js +26 -4
  37. package/dist/collection/components/snk-personalized-filter/subcomponents/snk-filter-param-config/snk-filter-param-config.js +26 -1
  38. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +22 -1
  39. package/dist/collection/components/snk-taskbar/snk-taskbar.js +23 -1
  40. package/dist/collection/lib/message/SnkMessageBuilder.js +9 -2
  41. package/dist/components/SnkMessageBuilder.js +9 -2
  42. package/dist/components/snk-application2.js +1 -1
  43. package/dist/components/snk-config-options2.js +3 -1
  44. package/dist/components/snk-configurator2.js +4 -2
  45. package/dist/components/snk-crud.js +11 -3
  46. package/dist/components/snk-data-exporter2.js +10 -1
  47. package/dist/components/snk-data-unit2.js +25 -4
  48. package/dist/components/snk-detail-view2.js +17 -7
  49. package/dist/components/snk-field-config2.js +5 -6
  50. package/dist/components/snk-filter-bar2.js +4 -1
  51. package/dist/components/snk-filter-param-config.js +3 -1
  52. package/dist/components/snk-form-config2.js +7 -5
  53. package/dist/components/snk-form.js +3 -1
  54. package/dist/components/snk-grid2.js +7 -4
  55. package/dist/components/snk-simple-crud.js +3 -1
  56. package/dist/components/snk-tab-config2.js +3 -1
  57. package/dist/components/snk-taskbar2.js +4 -1
  58. package/dist/esm/{SnkMessageBuilder-ec0850af.js → SnkMessageBuilder-68bbf0ae.js} +9 -2
  59. package/dist/esm/loader.js +1 -1
  60. package/dist/esm/sankhyablocks.js +1 -1
  61. package/dist/esm/snk-application.entry.js +1 -1
  62. package/dist/esm/snk-config-options.entry.js +2 -1
  63. package/dist/esm/snk-configurator.entry.js +3 -2
  64. package/dist/esm/snk-crud.entry.js +10 -3
  65. package/dist/esm/snk-data-exporter.entry.js +10 -1
  66. package/dist/esm/snk-data-unit-a8093f95.js +434 -0
  67. package/dist/esm/snk-data-unit.entry.js +5 -414
  68. package/dist/esm/snk-detail-view.entry.js +7 -2
  69. package/dist/esm/snk-field-config.entry.js +3 -5
  70. package/dist/esm/snk-filter-bar.entry.js +3 -1
  71. package/dist/esm/snk-filter-param-config.entry.js +2 -1
  72. package/dist/esm/snk-form-config.entry.js +6 -5
  73. package/dist/esm/snk-form.entry.js +2 -1
  74. package/dist/esm/snk-grid.entry.js +6 -4
  75. package/dist/esm/{snk-guides-viewer-73b9eb29.js → snk-guides-viewer-d8654e2a.js} +9 -6
  76. package/dist/esm/snk-guides-viewer.entry.js +1 -1
  77. package/dist/esm/snk-simple-crud.entry.js +2 -1
  78. package/dist/esm/snk-tab-config.entry.js +2 -1
  79. package/dist/esm/snk-taskbar.entry.js +3 -1
  80. package/dist/sankhyablocks/p-046b2563.entry.js +1 -0
  81. package/dist/sankhyablocks/p-0a1e7f75.entry.js +1 -0
  82. package/dist/sankhyablocks/{p-28c800b9.js → p-0d70c017.js} +1 -1
  83. package/dist/sankhyablocks/p-1a16426f.js +1 -0
  84. package/dist/sankhyablocks/{p-9ce550b7.entry.js → p-21a6c546.entry.js} +1 -1
  85. package/dist/sankhyablocks/p-280b1321.entry.js +1 -0
  86. package/dist/sankhyablocks/p-32599159.entry.js +1 -0
  87. package/dist/sankhyablocks/p-5b84b0c5.entry.js +1 -0
  88. package/dist/sankhyablocks/p-601e6920.entry.js +1 -0
  89. package/dist/sankhyablocks/p-69af76d4.entry.js +1 -0
  90. package/dist/sankhyablocks/p-76f04efe.entry.js +1 -0
  91. package/dist/sankhyablocks/p-93d8fe00.entry.js +1 -0
  92. package/dist/sankhyablocks/p-a12d74dc.entry.js +1 -0
  93. package/dist/sankhyablocks/p-a7468f4b.js +1 -0
  94. package/dist/sankhyablocks/p-a80c766c.entry.js +1 -0
  95. package/dist/sankhyablocks/p-b686e91a.entry.js +1 -0
  96. package/dist/sankhyablocks/p-b80cf644.entry.js +1 -0
  97. package/dist/sankhyablocks/p-d65809d5.entry.js +1 -0
  98. package/dist/sankhyablocks/{p-b9fe5ed3.entry.js → p-e999631f.entry.js} +2 -2
  99. package/dist/sankhyablocks/p-f29caa0a.entry.js +1 -0
  100. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  101. package/dist/types/components/snk-application/snk-application.d.ts +1 -4
  102. package/dist/types/components/snk-configurator/snk-configurator.d.ts +5 -0
  103. package/dist/types/components/snk-crud/snk-crud.d.ts +6 -0
  104. package/dist/types/components/snk-crud/subcomponents/snk-detail-view.d.ts +2 -3
  105. package/dist/types/components/snk-crud/subcomponents/snk-guides-viewer.d.ts +5 -1
  106. package/dist/types/components/snk-data-exporter/snk-data-exporter.d.ts +5 -0
  107. package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +13 -2
  108. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +5 -0
  109. package/dist/types/components/snk-form/snk-form.d.ts +5 -0
  110. package/dist/types/components/snk-form/subcomponents/snk-config-options/snk-config-options.d.ts +5 -0
  111. package/dist/types/components/snk-form/subcomponents/snk-field-config/snk-field-config.d.ts +5 -2
  112. package/dist/types/components/snk-form/subcomponents/snk-form-config/snk-form-config.d.ts +5 -0
  113. package/dist/types/components/snk-form/subcomponents/snk-tab-config/snk-tab-config.d.ts +5 -0
  114. package/dist/types/components/snk-grid/snk-grid.d.ts +5 -0
  115. package/dist/types/components/snk-personalized-filter/subcomponents/snk-filter-param-config/snk-filter-param-config.d.ts +5 -0
  116. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +5 -0
  117. package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +5 -0
  118. package/dist/types/components.d.ts +126 -12
  119. package/dist/types/lib/message/SnkMessageBuilder.d.ts +4 -2
  120. package/package.json +1 -1
  121. package/dist/sankhyablocks/p-0154ae58.entry.js +0 -1
  122. package/dist/sankhyablocks/p-10be1b2a.entry.js +0 -1
  123. package/dist/sankhyablocks/p-12d2dccf.entry.js +0 -1
  124. package/dist/sankhyablocks/p-193b0fa5.entry.js +0 -1
  125. package/dist/sankhyablocks/p-31d4e5d4.entry.js +0 -1
  126. package/dist/sankhyablocks/p-68507ace.entry.js +0 -1
  127. package/dist/sankhyablocks/p-72277163.entry.js +0 -1
  128. package/dist/sankhyablocks/p-7d4bb27a.entry.js +0 -1
  129. package/dist/sankhyablocks/p-94fef424.entry.js +0 -1
  130. package/dist/sankhyablocks/p-983fef8f.js +0 -1
  131. package/dist/sankhyablocks/p-af8cf505.entry.js +0 -1
  132. package/dist/sankhyablocks/p-c88c4f80.entry.js +0 -1
  133. package/dist/sankhyablocks/p-dd90bd52.entry.js +0 -1
  134. package/dist/sankhyablocks/p-eb7b2496.entry.js +0 -1
  135. package/dist/sankhyablocks/p-ecd3cad5.entry.js +0 -1
  136. package/dist/sankhyablocks/p-f9ca6d74.entry.js +0 -1
@@ -0,0 +1,434 @@
1
+ import { r as registerInstance, c as createEvent, h, g as getElement, H as Host } from './index-cfd4bb13.js';
2
+ import { Action, ObjectUtils, JSUtils, ApplicationContext, DataType } from '@sankhyalabs/core';
3
+ import { ApplicationUtils, DialogType } from '@sankhyalabs/ezui/dist/collection/utils';
4
+ import { O as OperationMap, S as SnkMessageBuilder } from './SnkMessageBuilder-68bbf0ae.js';
5
+
6
+ const snkDataUnitCss = ".sc-snk-data-unit-h{display:flex;flex-direction:column;height:100%;width:100%}";
7
+
8
+ const SnkDataUnit = class {
9
+ constructor(hostRef) {
10
+ registerInstance(this, hostRef);
11
+ this.dataStateChange = createEvent(this, "dataStateChange", 3);
12
+ this.dataUnitReady = createEvent(this, "dataUnitReady", 3);
13
+ this.messagesBuilderUpdated = createEvent(this, "messagesBuilderUpdated", 3);
14
+ this.insertionMode = createEvent(this, "insertionMode", 3);
15
+ this.cancelEdition = createEvent(this, "cancelEdition", 3);
16
+ this._onDataUnitResolve = [];
17
+ this._dataUnitObserver = (action) => {
18
+ var _a, _b;
19
+ const duState = this.buildDataState();
20
+ this.dataState = duState;
21
+ if (action.type === Action.DATA_SAVED) {
22
+ const msg = this.getMessage("snkDataUnit.saveInfo", action.payload.records[0]);
23
+ if (msg != undefined) {
24
+ this.showSuccessMessage(msg);
25
+ }
26
+ }
27
+ if (action.type === Action.RECORDS_ADDED || action.type === Action.RECORDS_COPIED) {
28
+ this.insertionMode.emit();
29
+ }
30
+ if (action.type === Action.EDITION_CANCELED) {
31
+ this.cancelEdition.emit();
32
+ }
33
+ if (action.type === Action.RECORDS_REMOVED) {
34
+ const cachedRecords = action.payload.cachedRecords;
35
+ let removeFinishMsg;
36
+ if ((cachedRecords === null || cachedRecords === void 0 ? void 0 : cachedRecords.length) > 1) {
37
+ removeFinishMsg = this.getMessage("snkDataUnit.removeAllInfo", { size: cachedRecords.length });
38
+ }
39
+ else {
40
+ removeFinishMsg = this.getMessage("snkDataUnit.removeInfo", action.payload.cachedRecords[0]);
41
+ }
42
+ if (removeFinishMsg != undefined) {
43
+ this.showSuccessMessage(removeFinishMsg);
44
+ }
45
+ const recordsCount = (_b = (_a = this.dataUnit.records) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
46
+ const paginationInfo = this.dataUnit.getPaginationInfo();
47
+ if (paginationInfo) {
48
+ if (recordsCount > 0 || paginationInfo.hasMore) {
49
+ this.dataUnit.gotoPage(paginationInfo.currentPage);
50
+ }
51
+ else {
52
+ this.dataUnit.gotoPage(0);
53
+ }
54
+ }
55
+ }
56
+ this.messagesBuilder.currentOperation = this.getMessageOperation();
57
+ };
58
+ this.dataState = undefined;
59
+ this.messagesBuilder = undefined;
60
+ this.dataUnitName = undefined;
61
+ this.entityName = undefined;
62
+ this.pageSize = 150;
63
+ this.dataUnit = undefined;
64
+ this.beforeSave = undefined;
65
+ this.afterSave = undefined;
66
+ }
67
+ observePageSize() {
68
+ if (this.dataUnit) {
69
+ this.dataUnit.pageSize = this.pageSize;
70
+ }
71
+ }
72
+ observeDataUnitName(newValue, oldValue) {
73
+ if (oldValue != newValue) {
74
+ if (this.dataUnit) {
75
+ this._application.updateDataunitCache(oldValue, this.dataUnitName, this.dataUnit);
76
+ }
77
+ else {
78
+ this.loadDataUnit();
79
+ }
80
+ }
81
+ }
82
+ observeEntityName(newValue, oldValue) {
83
+ if (oldValue != newValue) {
84
+ this.dataUnit = undefined;
85
+ this.entityName = newValue;
86
+ this.loadDataUnit();
87
+ }
88
+ }
89
+ observeDataState(newValue, oldValue) {
90
+ if (ObjectUtils.objectToString(oldValue) != ObjectUtils.objectToString(newValue)) {
91
+ this.dataStateChange.emit(newValue);
92
+ }
93
+ }
94
+ observeDataUnit() {
95
+ this.handlerLinkFields();
96
+ this.dataUnitReady.emit(this.dataUnit);
97
+ }
98
+ observeMessagesBuilder(newValue) {
99
+ if (newValue) {
100
+ this.messagesBuilderUpdated.emit(newValue);
101
+ }
102
+ }
103
+ /**
104
+ * Obtém o dataUnit.
105
+ */
106
+ async getDataUnit() {
107
+ return new Promise((resolve) => {
108
+ if (this.dataUnit) {
109
+ resolve(this.dataUnit);
110
+ }
111
+ else {
112
+ this._onDataUnitResolve.push(resolve);
113
+ }
114
+ });
115
+ }
116
+ /**
117
+ * Método que retorna a lista de IDs dos registros selecionados.
118
+ * @returns Retorna a lista de IDs dos registros selecionados.
119
+ */
120
+ async getSelectedRecordsIDsInfo() {
121
+ var _a;
122
+ const selectionInfo = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getSelectionInfo();
123
+ if (selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isAllRecords()) {
124
+ return [];
125
+ }
126
+ const selectedRecordsIDsInfo = [];
127
+ const selectedRecords = selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.records;
128
+ if ((selectedRecords === null || selectedRecords === void 0 ? void 0 : selectedRecords.length) > 0) {
129
+ selectedRecords.forEach(({ __record__id__ }) => {
130
+ if (!this.dataUnit.isNewRecord(__record__id__)) {
131
+ /*
132
+ Esse if foi necessário para tratar corretamente o ID
133
+ do record quando está sendo utilizado no modo standAlone
134
+ isso não faz a exportação da grid funcionar no modo standAlone
135
+ mas deixa de causar erro nas oprações de CRUD.
136
+ */
137
+ if (!JSUtils.isBase64(__record__id__)) {
138
+ selectedRecordsIDsInfo.push({
139
+ name: "__record__id__",
140
+ type: DataType.TEXT,
141
+ value: __record__id__
142
+ });
143
+ return;
144
+ }
145
+ const revertBase64ToObject = JSON.parse(window.atob(__record__id__));
146
+ Object.entries(revertBase64ToObject).forEach(([name, value]) => {
147
+ var _a;
148
+ const metadataField = (_a = this.dataUnit) === null || _a === void 0 ? void 0 : _a.getField(name);
149
+ if (metadataField == undefined) {
150
+ return;
151
+ }
152
+ selectedRecordsIDsInfo.push(Object.assign({ name, type: metadataField.dataType }, value));
153
+ });
154
+ }
155
+ });
156
+ }
157
+ return selectedRecordsIDsInfo;
158
+ }
159
+ async interceptAction(action) {
160
+ return new Promise(resolve => {
161
+ var _a, _b;
162
+ switch (action.type) {
163
+ case Action.RECORDS_ADDED:
164
+ if (this.isAllowed("INSERT")) {
165
+ resolve(action);
166
+ }
167
+ else {
168
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenInsert"));
169
+ }
170
+ break;
171
+ case Action.RECORDS_COPIED:
172
+ if (this.isAllowed("CLONE")) {
173
+ resolve(action);
174
+ }
175
+ else {
176
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenClone"));
177
+ }
178
+ break;
179
+ case Action.DATA_CHANGED:
180
+ case Action.CHANGING_DATA:
181
+ if (this.isAllowed("UPDATE")) {
182
+ resolve(action);
183
+ }
184
+ else {
185
+ this.dataUnit.cancelEdition();
186
+ ApplicationUtils.alert(this.getMessage("snkDataUnit.forbidden"), this.getMessage("snkDataUnit.forbiddenUpdate"));
187
+ }
188
+ break;
189
+ case Action.SAVING_DATA:
190
+ if (this.beforeSave) {
191
+ const continueAction = this.beforeSave(this.dataUnit);
192
+ if (continueAction instanceof Promise) {
193
+ continueAction.then(result => resolve(result ? action : undefined));
194
+ }
195
+ else {
196
+ resolve(continueAction ? action : undefined);
197
+ }
198
+ }
199
+ else {
200
+ resolve(action);
201
+ }
202
+ break;
203
+ case Action.DATA_SAVED:
204
+ if (this.afterSave) {
205
+ this.afterSave(this.dataUnit);
206
+ }
207
+ else {
208
+ resolve(action);
209
+ }
210
+ break;
211
+ case Action.EDITION_CANCELED:
212
+ if (this.dataState.hasDirtyRecords) {
213
+ const cancelConfirmation = this.getMessage("snkDataUnit.cancelConfirmation");
214
+ if ((_a = action.payload) === null || _a === void 0 ? void 0 : _a.fromParent) {
215
+ resolve(action);
216
+ return;
217
+ }
218
+ if (cancelConfirmation == undefined) {
219
+ this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
220
+ resolve(action);
221
+ }
222
+ else {
223
+ const cancelConfirmationTitle = this.getMessage("snkDataUnit.cancelConfirmationTitle");
224
+ ApplicationUtils.confirm(cancelConfirmationTitle, cancelConfirmation)
225
+ .then((result) => {
226
+ result && this.showSuccessMessage(this.getMessage("snkDataUnit.cancelInfo"));
227
+ resolve(result ? action : undefined);
228
+ });
229
+ }
230
+ }
231
+ else {
232
+ resolve(action);
233
+ }
234
+ break;
235
+ case Action.REMOVING_RECORDS:
236
+ if (this.isAllowed("REMOVE")) {
237
+ let multipleSelection = false;
238
+ let removeConfirmation = this.getMessage("snkDataUnit.removeConfirmation");
239
+ const selection = (_b = this.dataUnit) === null || _b === void 0 ? void 0 : _b.getSelectionInfo();
240
+ if ((selection === null || selection === void 0 ? void 0 : selection.length) > 1) {
241
+ removeConfirmation = this.getMessage("snkDataUnit.removeAllConfirmation", { size: selection.length });
242
+ multipleSelection = true;
243
+ }
244
+ if (removeConfirmation == undefined) {
245
+ resolve(action);
246
+ }
247
+ else {
248
+ const options = {
249
+ canClose: false,
250
+ labelCancel: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "no" : "cancel"}`),
251
+ labelConfirm: this.getMessage(`snkDataUnit.confirm.${multipleSelection ? "yes" : "delete"}`),
252
+ btnConfirmDanger: false
253
+ };
254
+ const removeConfirmationTitle = this.getMessage("snkDataUnit.removeConfirmationTitle");
255
+ ApplicationUtils.confirm(removeConfirmationTitle, removeConfirmation, null, DialogType.WARN, options)
256
+ .then((result) => resolve(result ? action : undefined));
257
+ }
258
+ }
259
+ else {
260
+ ApplicationUtils.info(this.getMessage("snkDataUnit.forbiddenRemove"));
261
+ }
262
+ break;
263
+ default:
264
+ resolve(action);
265
+ }
266
+ });
267
+ }
268
+ showSuccessMessage(message) {
269
+ ApplicationUtils.info(message, { iconName: "check" });
270
+ }
271
+ isAllowed(flag) {
272
+ return this._permissions ? this._permissions.isSup || this._permissions[flag] : false;
273
+ }
274
+ buildDataState() {
275
+ const selectionInfo = this.dataUnit.getSelectionInfo();
276
+ return new DataStateImpl({
277
+ insertionMode: this.dataUnit.hasNewRecord(),
278
+ hasNext: this.dataUnit.hasNext(),
279
+ hasPrevious: this.dataUnit.hasPrevious(),
280
+ copyMode: this.dataUnit.hasCopiedRecord(),
281
+ isDirty: this.dataUnit.isDirty(),
282
+ hasDirtyRecords: this.dataUnit.hasDirtyRecords(),
283
+ selectedRecords: undefined,
284
+ selectionInfo,
285
+ selectedRecord: this.dataUnit.getSelectedRecord()
286
+ });
287
+ }
288
+ /**
289
+ * Conforme mecanismo de mensagens, é possível customizar as mensagens dos blocos de construção
290
+ * através de um pequeno modulo na estrutura da aplicação:
291
+ * - Criar um arquivo no seguinte caminho: /messages/appmessages.msg.js.
292
+ * Para conhecer os detalhes do módulo, vide o arquivo neste projeto "/src/lib/message/resources/snk-data-unit.msg.ts"
293
+ */
294
+ getMessage(key, params = undefined) {
295
+ if (!params) {
296
+ params = this.getMessageParams();
297
+ }
298
+ return this.messagesBuilder.getMessage(key, params);
299
+ }
300
+ getMessageParams() {
301
+ //FIXME: Devido ao recurso de multiseleção do dataunit, precisaremos criar um mecanismo para
302
+ //oferecer todos os registros selecionados para a mensagem, pois mensagens podem ficar incorretas.
303
+ return this.dataState.selectedRecord;
304
+ }
305
+ getMessageOperation() {
306
+ if (this.dataState.copyMode) {
307
+ return OperationMap.CLONE;
308
+ }
309
+ if (this.dataState.insertionMode) {
310
+ return OperationMap.INSERT;
311
+ }
312
+ if (this.dataState.isDirty) {
313
+ return OperationMap.UPDATE;
314
+ }
315
+ return OperationMap.CLEAN;
316
+ }
317
+ async getDataUnitParentOrChild() {
318
+ var _a;
319
+ const cacheName = this.dataUnitName ? this.dataUnitName : this.entityName;
320
+ if (this._parentSnkDataUnit) {
321
+ this._parentDataUnit = await ((_a = this._parentSnkDataUnit) === null || _a === void 0 ? void 0 : _a.getDataUnit());
322
+ return await this._application.getDataUnit(this.entityName, cacheName, this._parentDataUnit);
323
+ }
324
+ else {
325
+ return await this._application.getDataUnit(this.entityName, cacheName);
326
+ }
327
+ }
328
+ async loadDataUnit() {
329
+ if (this.dataUnit == null && this._application && this.entityName) {
330
+ this.dataUnit = await this.getDataUnitParentOrChild();
331
+ }
332
+ if (this.dataUnit) {
333
+ this.dataUnit.pageSize = this.pageSize;
334
+ this.dataUnit.unsubscribe(this._dataUnitObserver);
335
+ this.dataUnit.addInterceptor(this);
336
+ this.dataUnit.subscribe(this._dataUnitObserver);
337
+ this.dataState = this.buildDataState();
338
+ let resolver;
339
+ while (resolver = this._onDataUnitResolve.pop()) {
340
+ resolver(this.dataUnit);
341
+ }
342
+ }
343
+ }
344
+ getParentSnkDataUnit() {
345
+ let currentElement = this.element;
346
+ while (currentElement.parentNode) {
347
+ if (currentElement.parentNode.nodeName === 'SNK-DATA-UNIT') {
348
+ return currentElement.parentNode;
349
+ }
350
+ currentElement = currentElement.parentNode;
351
+ }
352
+ return;
353
+ }
354
+ handlerLinkFields() {
355
+ var _a, _b;
356
+ const metadata = Object.assign({}, this.dataUnit.metadata);
357
+ if (!this._parentDataUnit)
358
+ return;
359
+ const child = this._parentDataUnit.getChildInfo(this.entityName);
360
+ if (!child)
361
+ return;
362
+ const fieldsLink = (_a = child === null || child === void 0 ? void 0 : child.links) === null || _a === void 0 ? void 0 : _a.map(link => link.target);
363
+ (_b = metadata === null || metadata === void 0 ? void 0 : metadata.fields) === null || _b === void 0 ? void 0 : _b.forEach(field => {
364
+ if (fieldsLink === null || fieldsLink === void 0 ? void 0 : fieldsLink.includes(field.name)) {
365
+ field.visible = false;
366
+ }
367
+ });
368
+ this.dataUnit.metadata = metadata;
369
+ }
370
+ static getNearestInstance(element) {
371
+ let parent = element.parentElement;
372
+ while (parent) {
373
+ if (parent.tagName.toUpperCase() === "SNK-DATA-UNIT") {
374
+ return parent;
375
+ }
376
+ parent = parent.parentElement;
377
+ }
378
+ }
379
+ //---------------------------------------------
380
+ // Lifecycle web component
381
+ //---------------------------------------------
382
+ componentWillLoad() {
383
+ this._application = ApplicationContext.getContextValue("__SNK__APPLICATION__");
384
+ this._application.getAllAccess().then(access => this._permissions = access);
385
+ this._parentSnkDataUnit = this.getParentSnkDataUnit();
386
+ if (this.messagesBuilder == undefined) {
387
+ this.messagesBuilder = new SnkMessageBuilder(this.entityName);
388
+ }
389
+ }
390
+ disconnectedCallback() {
391
+ if (this.dataUnit) {
392
+ this.dataUnit.unsubscribe(this._dataUnitObserver);
393
+ this.dataUnit.removeInterceptor(this);
394
+ }
395
+ }
396
+ componentDidLoad() {
397
+ this.loadDataUnit();
398
+ }
399
+ render() {
400
+ return (h(Host, null));
401
+ }
402
+ get element() { return getElement(this); }
403
+ static get watchers() { return {
404
+ "pageSize": ["observePageSize"],
405
+ "dataUnitName": ["observeDataUnitName"],
406
+ "entityName": ["observeEntityName"],
407
+ "dataState": ["observeDataState"],
408
+ "dataUnit": ["observeDataUnit"],
409
+ "messagesBuilder": ["observeMessagesBuilder"]
410
+ }; }
411
+ };
412
+ class DataStateImpl {
413
+ constructor(datastate) {
414
+ this.copyMode = datastate.copyMode;
415
+ this.insertionMode = datastate.insertionMode;
416
+ this.isDirty = datastate.isDirty;
417
+ this.hasDirtyRecords = datastate.hasDirtyRecords;
418
+ this.hasNext = datastate.hasNext;
419
+ this.hasPrevious = datastate.hasPrevious;
420
+ this.selectionInfo = datastate.selectionInfo;
421
+ this.selectedRecord = datastate.selectedRecord;
422
+ }
423
+ get selectedRecords() {
424
+ var _a;
425
+ console.warn("SnkDataUnit: O método `selectedRecords` foi descontinuado. Use o método `selectionInfo`.");
426
+ if ((_a = this.selectionInfo) === null || _a === void 0 ? void 0 : _a.isAllRecords()) {
427
+ throw new Error("Erro interno: Impossível obter os registros selecionados. A seleção atual é virtual. Use o atributo `selectionInfo`.");
428
+ }
429
+ return this.selectionInfo.records;
430
+ }
431
+ }
432
+ SnkDataUnit.style = snkDataUnitCss;
433
+
434
+ export { SnkDataUnit as S };