@sankhyalabs/sankhyablocks 8.16.0-dev.63 → 8.16.0-dev.65

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 (124) hide show
  1. package/dist/cjs/{ContinuousInsertUtils-414b772c.js → ContinuousInsertUtils-a6139f3d.js} +2 -2
  2. package/dist/cjs/{dataunit-fetcher-228016f4.js → dataunit-fetcher-0121621c.js} +1 -1
  3. package/dist/cjs/index-f9e81701.js +4 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/{pesquisa-fetcher-2ec4811b.js → pesquisa-fetcher-a85d6935.js} +175 -0
  6. package/dist/cjs/pesquisa-grid_2.cjs.entry.js +127 -0
  7. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  8. package/dist/cjs/snk-actions-button_5.cjs.entry.js +2 -2
  9. package/dist/cjs/snk-application.cjs.entry.js +140 -17
  10. package/dist/cjs/snk-attach.cjs.entry.js +2 -2
  11. package/dist/cjs/snk-crud.cjs.entry.js +5 -4
  12. package/dist/cjs/snk-data-exporter.cjs.entry.js +3 -3
  13. package/dist/cjs/{snk-data-unit-3d9b6ed4.js → snk-data-unit-c699179d.js} +1 -1
  14. package/dist/cjs/snk-data-unit.cjs.entry.js +2 -2
  15. package/dist/cjs/snk-detail-view.cjs.entry.js +3 -3
  16. package/dist/cjs/snk-filter-bar_4.cjs.entry.js +21 -7
  17. package/dist/cjs/snk-grid.cjs.entry.js +6 -5
  18. package/dist/cjs/{snk-guides-viewer-421555af.js → snk-guides-viewer-575596a2.js} +2 -2
  19. package/dist/cjs/snk-guides-viewer.cjs.entry.js +3 -3
  20. package/dist/cjs/snk-pesquisa.cjs.entry.js +105 -31
  21. package/dist/cjs/snk-simple-crud.cjs.entry.js +6 -5
  22. package/dist/collection/collection-manifest.json +2 -0
  23. package/dist/collection/components/snk-application/request-listener/DebouncedRequestListener.js +4 -3
  24. package/dist/collection/components/snk-application/snk-application.css +34 -0
  25. package/dist/collection/components/snk-application/snk-application.js +197 -14
  26. package/dist/collection/components/snk-crud/snk-crud.js +39 -20
  27. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +40 -8
  28. package/dist/collection/components/snk-grid/snk-grid.js +39 -20
  29. package/dist/collection/components/snk-pesquisa/pesquisa-grid/pesquisa-grid.css +10 -0
  30. package/dist/collection/components/snk-pesquisa/pesquisa-grid/pesquisa-grid.js +190 -0
  31. package/dist/collection/components/snk-pesquisa/pesquisa-tree/pesquisa-tree.css +25 -0
  32. package/dist/collection/components/snk-pesquisa/pesquisa-tree/pesquisa-tree.js +173 -0
  33. package/dist/collection/components/snk-pesquisa/pesquisaHelper.js +89 -0
  34. package/dist/collection/components/snk-pesquisa/snk-pesquisa.css +24 -5
  35. package/dist/collection/components/snk-pesquisa/snk-pesquisa.js +168 -32
  36. package/dist/collection/components/snk-simple-crud/snk-simple-crud.js +39 -20
  37. package/dist/collection/lib/dataUnit/dataUnitInMemoryUtils.js +1 -1
  38. package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +89 -3
  39. package/dist/components/ContinuousInsertUtils.js +1 -2
  40. package/dist/components/ISave.js +346 -1
  41. package/dist/components/dataunit-fetcher.js +1 -1
  42. package/dist/components/index.d.ts +2 -0
  43. package/dist/components/index.js +2 -0
  44. package/dist/components/pesquisa-grid.d.ts +11 -0
  45. package/dist/components/pesquisa-grid.js +6 -0
  46. package/dist/components/pesquisa-grid2.js +86 -0
  47. package/dist/components/pesquisa-tree.d.ts +11 -0
  48. package/dist/components/pesquisa-tree.js +6 -0
  49. package/dist/components/pesquisa-tree2.js +76 -0
  50. package/dist/components/snk-actions-button2.js +0 -1
  51. package/dist/components/snk-application2.js +159 -20
  52. package/dist/components/snk-attach2.js +0 -1
  53. package/dist/components/snk-crud.js +5 -4
  54. package/dist/components/snk-data-exporter2.js +1 -2
  55. package/dist/components/snk-detail-view2.js +0 -1
  56. package/dist/components/snk-filter-bar2.js +23 -8
  57. package/dist/components/snk-grid2.js +5 -4
  58. package/dist/components/snk-pesquisa2.js +118 -33
  59. package/dist/components/snk-simple-crud2.js +6 -5
  60. package/dist/components/snk-simple-form-config2.js +1 -2
  61. package/dist/components/teste-pesquisa.js +13 -1
  62. package/dist/esm/{ContinuousInsertUtils-bab45060.js → ContinuousInsertUtils-15b5f1da.js} +2 -2
  63. package/dist/esm/{dataunit-fetcher-56cb648b.js → dataunit-fetcher-481e159d.js} +1 -1
  64. package/dist/esm/index-a7d3d3f1.js +4 -0
  65. package/dist/esm/loader.js +1 -1
  66. package/dist/esm/{pesquisa-fetcher-24e5bba0.js → pesquisa-fetcher-c437c9b1.js} +176 -2
  67. package/dist/esm/pesquisa-grid_2.entry.js +122 -0
  68. package/dist/esm/sankhyablocks.js +1 -1
  69. package/dist/esm/snk-actions-button_5.entry.js +2 -2
  70. package/dist/esm/snk-application.entry.js +142 -19
  71. package/dist/esm/snk-attach.entry.js +2 -2
  72. package/dist/esm/snk-crud.entry.js +5 -4
  73. package/dist/esm/snk-data-exporter.entry.js +3 -3
  74. package/dist/esm/{snk-data-unit-9fa7d2b9.js → snk-data-unit-d4ba54d7.js} +1 -1
  75. package/dist/esm/snk-data-unit.entry.js +2 -2
  76. package/dist/esm/snk-detail-view.entry.js +3 -3
  77. package/dist/esm/snk-filter-bar_4.entry.js +22 -8
  78. package/dist/esm/snk-grid.entry.js +6 -5
  79. package/dist/esm/{snk-guides-viewer-b740a1fe.js → snk-guides-viewer-3043422d.js} +2 -2
  80. package/dist/esm/snk-guides-viewer.entry.js +3 -3
  81. package/dist/esm/snk-pesquisa.entry.js +105 -31
  82. package/dist/esm/snk-simple-crud.entry.js +6 -5
  83. package/dist/sankhyablocks/{p-c629c07a.entry.js → p-08242e3f.entry.js} +1 -1
  84. package/dist/sankhyablocks/{p-342eeb3b.js → p-0f3b2a32.js} +1 -1
  85. package/dist/sankhyablocks/{p-72a451c8.js → p-229c3615.js} +1 -1
  86. package/dist/sankhyablocks/p-22d04eac.entry.js +1 -0
  87. package/dist/sankhyablocks/{p-b619ee23.js → p-36598f95.js} +1 -1
  88. package/dist/sankhyablocks/p-4895f6e4.entry.js +1 -0
  89. package/dist/sankhyablocks/p-4be4cdac.js +6 -0
  90. package/dist/sankhyablocks/{p-47d24ac8.js → p-58fd3017.js} +1 -1
  91. package/dist/sankhyablocks/p-70cb4e36.entry.js +11 -0
  92. package/dist/sankhyablocks/{p-64ff0fb6.entry.js → p-73fc8ec5.entry.js} +1 -1
  93. package/dist/sankhyablocks/{p-50306605.entry.js → p-7d09f66c.entry.js} +1 -1
  94. package/dist/sankhyablocks/{p-53ae0296.entry.js → p-a33e803a.entry.js} +1 -1
  95. package/dist/sankhyablocks/{p-89da2953.entry.js → p-b299dc14.entry.js} +1 -1
  96. package/dist/sankhyablocks/p-badbd2ca.entry.js +1 -0
  97. package/dist/sankhyablocks/p-c9bd54e6.entry.js +1 -0
  98. package/dist/sankhyablocks/{p-0d2a2e9e.entry.js → p-e2bd42c0.entry.js} +1 -1
  99. package/dist/sankhyablocks/p-e8512d4b.entry.js +1 -0
  100. package/dist/sankhyablocks/p-f71d043b.entry.js +1 -0
  101. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  102. package/dist/types/components/snk-application/snk-application.d.ts +22 -4
  103. package/dist/types/components/snk-crud/snk-crud.d.ts +8 -4
  104. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +6 -1
  105. package/dist/types/components/snk-grid/snk-grid.d.ts +8 -4
  106. package/dist/types/components/snk-pesquisa/pesquisa-grid/pesquisa-grid.d.ts +38 -0
  107. package/dist/types/components/snk-pesquisa/pesquisa-tree/pesquisa-tree.d.ts +28 -0
  108. package/dist/types/components/snk-pesquisa/pesquisaHelper.d.ts +19 -0
  109. package/dist/types/components/snk-pesquisa/snk-pesquisa.d.ts +35 -1
  110. package/dist/types/components/snk-simple-crud/snk-simple-crud.d.ts +8 -1
  111. package/dist/types/components.d.ts +206 -23
  112. package/dist/types/lib/http/data-fetcher/fetchers/pesquisa-fetcher.d.ts +10 -1
  113. package/package.json +1 -1
  114. package/react/components.d.ts +2 -0
  115. package/react/components.js +2 -0
  116. package/react/components.js.map +1 -1
  117. package/dist/components/pesquisa-fetcher.js +0 -172
  118. package/dist/sankhyablocks/p-0c55538b.entry.js +0 -1
  119. package/dist/sankhyablocks/p-65650e05.entry.js +0 -1
  120. package/dist/sankhyablocks/p-690b4311.entry.js +0 -1
  121. package/dist/sankhyablocks/p-8cf0a9fe.entry.js +0 -1
  122. package/dist/sankhyablocks/p-d1791da2.entry.js +0 -1
  123. package/dist/sankhyablocks/p-e6683406.js +0 -6
  124. package/dist/sankhyablocks/p-eda55eef.entry.js +0 -11
@@ -1,3 +1,348 @@
1
+ import { UserInterface, DataType, ApplicationContext, ErrorException } from '@sankhyalabs/core';
2
+ import { d as dist, D as DataFetcher } from './DataFetcher.js';
3
+
4
+ function buildGridMetadata(rawValue) {
5
+ const fieldsMetadata = buildFieldsMetadata(rawValue.fieldsMetadata);
6
+ const duName = rawValue.descriptionField;
7
+ const duLabel = rawValue.entityDescription;
8
+ return {
9
+ label: duLabel,
10
+ name: duName,
11
+ fields: fieldsMetadata,
12
+ };
13
+ }
14
+ function buildFieldsMetadata(rawMetadata) {
15
+ if (!rawMetadata || !rawMetadata.length)
16
+ return [];
17
+ return rawMetadata.map(field => {
18
+ return {
19
+ name: field['fieldName'],
20
+ label: field['description'],
21
+ dataType: buildDataType(field['type']),
22
+ userInterface: buildUserInterface(field),
23
+ properties: bildProperties(field)
24
+ };
25
+ });
26
+ }
27
+ function bildProperties(field) {
28
+ const properties = {};
29
+ properties['options'] = buildOptions(field);
30
+ properties['mask'] = buildMask(field);
31
+ return properties;
32
+ }
33
+ function buildMask(field) {
34
+ const fieldUI = field['uiType'];
35
+ return fieldUI ? String(fieldUI).toLowerCase() : undefined;
36
+ }
37
+ function buildOptions(field) {
38
+ const optionsJson = field.options;
39
+ if (!optionsJson)
40
+ return undefined;
41
+ const options = [];
42
+ Object.keys(optionsJson).forEach(key => {
43
+ options.push({
44
+ label: key,
45
+ value: optionsJson[key]
46
+ });
47
+ });
48
+ return options;
49
+ }
50
+ function buildUserInterface(field) {
51
+ const options = field.options;
52
+ if (options && Object.keys(options).length > 0)
53
+ return UserInterface.OPTIONSELECTOR;
54
+ if (field['type'] === 'D')
55
+ return UserInterface.DATE;
56
+ if (field['type'] === 'H')
57
+ return UserInterface.DATETIME;
58
+ if (field['type'] === 'T')
59
+ return UserInterface.TIME;
60
+ return undefined;
61
+ }
62
+ function buildDataType(rawType) {
63
+ switch (rawType) {
64
+ case 'F':
65
+ return DataType.NUMBER;
66
+ case 'D':
67
+ case 'H':
68
+ return DataType.DATE;
69
+ case 'B':
70
+ return DataType.OBJECT;
71
+ default:
72
+ return DataType.TEXT;
73
+ }
74
+ }
75
+ function parseLegacyTree(legacy) {
76
+ var _a, _b;
77
+ const structure = (_b = (_a = legacy.arvore) === null || _a === void 0 ? void 0 : _a.no) !== null && _b !== void 0 ? _b : [];
78
+ return structure.map(parseLegacyItem);
79
+ }
80
+ function parseLegacyItem(node) {
81
+ return Object.assign({ id: node.codigo, label: `${node.caminho} - ${node.descricao}`, bold: node.analitico === "N", props: { analitico: node.analitico === 'S' } }, (node.no && { children: node.no.map(parseLegacyItem) }));
82
+ }
83
+ function parseGridConfig(rawConfig) {
84
+ var _a, _b;
85
+ const columns = [];
86
+ const fields = (_b = (_a = rawConfig === null || rawConfig === void 0 ? void 0 : rawConfig.gridConfig) === null || _a === void 0 ? void 0 : _a.field) !== null && _b !== void 0 ? _b : {};
87
+ Object.keys(fields).forEach(key => columns.push(fields[key]));
88
+ if (!columns.length)
89
+ return undefined;
90
+ return { columns };
91
+ }
92
+
93
+ class PesquisaFetcher {
94
+ constructor() {
95
+ this._defaultPageSize = 100;
96
+ this._templateByQuery = new Map();
97
+ this._searchListenersByDataUnit = new Map();
98
+ this.buldTemplates();
99
+ }
100
+ buldTemplates() {
101
+ this._templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
102
+ $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria options: $options){
103
+ value
104
+ label
105
+ }
106
+ }`);
107
+ }
108
+ loadSearchOptions(entityName, argument, criteria, options) {
109
+ var _a;
110
+ const cleanText = (argument === null || argument === void 0 ? void 0 : argument.toString().trim()) || undefined;
111
+ argument = isNaN(Number(cleanText)) && cleanText ? `%${cleanText}` : cleanText;
112
+ criteria === null || criteria === void 0 ? void 0 : criteria.params.forEach(param => {
113
+ if (param.dataType === DataType.OBJECT) {
114
+ param.value = JSON.stringify(param.value);
115
+ }
116
+ });
117
+ const listenerResult = this.applySearchListener(SearchListenerType.beforeSearch, entityName, argument, criteria, options);
118
+ const values = {
119
+ argument: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.argument) || argument,
120
+ entityName,
121
+ criteria: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.criteria) || criteria,
122
+ options: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.searchOptions) || options,
123
+ };
124
+ if (values.options) {
125
+ (_a = values.options) === null || _a === void 0 ? true : delete _a.dataUnitId;
126
+ }
127
+ return new Promise((resolve, reject) => {
128
+ DataFetcher.get()
129
+ .callGraphQL({
130
+ values,
131
+ query: this._templateByQuery.get("search"),
132
+ })
133
+ .then((result) => {
134
+ resolve(result);
135
+ })
136
+ .catch((error) => {
137
+ reject(error);
138
+ });
139
+ });
140
+ }
141
+ loadAdvancedSearch(entityName, argument, criteria, searchOptions) {
142
+ var _a, _b, _c, _d, _e;
143
+ const listenerResult = this.applySearchListener(SearchListenerType.beforeSearch, entityName, argument, criteria, searchOptions);
144
+ const values = {
145
+ argument: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.argument) || argument,
146
+ criteria: (listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.criteria) || criteria,
147
+ searchOptions: Object.assign(Object.assign({}, searchOptions), listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.searchOptions),
148
+ };
149
+ const serviceName = "PesquisaSP.getSuggestion";
150
+ const externalCriteria = {
151
+ query: {
152
+ $: (_a = values.criteria) === null || _a === void 0 ? void 0 : _a.expression
153
+ }
154
+ };
155
+ if (((_c = (_b = values.criteria) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.length) > 0) {
156
+ externalCriteria.params = {
157
+ param: values.criteria.params.map(param => {
158
+ let value = param.value;
159
+ if (typeof value === "string") {
160
+ const match = /CTX\{([^}]+)\}/.exec(value);
161
+ if (match) {
162
+ value = ApplicationContext.getContextValue(`__SNK__APPLICATION__FILTER__CONTEXT(${match[1]})__`);
163
+ }
164
+ }
165
+ if (param.dataType === DataType.NUMBER && value === undefined) {
166
+ throw new ErrorException("Falha detectada", `O campo ${param.name} deve ser informado.`);
167
+ }
168
+ let type = param.dataType;
169
+ if (type === DataType.OBJECT) {
170
+ value = value.value;
171
+ type = "S";
172
+ }
173
+ else {
174
+ type = convertParamType(param.dataType);
175
+ }
176
+ return { $: value, type };
177
+ })
178
+ };
179
+ }
180
+ const options = searchOptions != undefined
181
+ ? Object.assign(Object.assign({}, values === null || values === void 0 ? void 0 : values.searchOptions), { "pkFieldName": searchOptions.codeFieldName, "label": searchOptions.descriptionFieldName, "fieldName": searchOptions.codeFieldName, "useDescriptionOptions": false, "enableRowsCounter": true }) : undefined;
182
+ const reqBody = {
183
+ "serviceName": serviceName,
184
+ "requestBody": {
185
+ "criteria": Object.assign({ "entityName": entityName, "compacted": false, "ignoreEntityCriteria": (_d = options === null || options === void 0 ? void 0 : options.ignoreEntityCriteria) !== null && _d !== void 0 ? _d : false, "limit": this._defaultPageSize, "query": { "$": values.argument }, "orderByDesc": false, "externalCriteria": externalCriteria, "localEntityName": (_e = values.searchOptions) === null || _e === void 0 ? void 0 : _e.rootEntity }, { options }),
186
+ "clientEventList": {
187
+ "clientEvent": []
188
+ }
189
+ }
190
+ };
191
+ const urlOptions = {
192
+ urlParams: {
193
+ "quietMode": true
194
+ }
195
+ };
196
+ return new Promise((resolve, reject) => {
197
+ DataFetcher.get()
198
+ .callServiceBroker("PesquisaSP.getSuggestion", JSON.stringify(reqBody), urlOptions)
199
+ .then(result => resolve(result))
200
+ .catch(error => reject(error));
201
+ });
202
+ }
203
+ addSearchListener(entityName, dataUnitID, listener) {
204
+ var _a;
205
+ const dataUnitSearchListeners = this._searchListenersByDataUnit.get(dataUnitID) || [];
206
+ const entityListener = dataUnitSearchListeners.find(currentListener => currentListener.entity === entityName);
207
+ if (!entityListener) {
208
+ this._searchListenersByDataUnit.set(dataUnitID, [...dataUnitSearchListeners, { entity: entityName, listener }]);
209
+ }
210
+ else {
211
+ for (const type of Object.keys(listener)) {
212
+ if (type in entityListener.listener) {
213
+ const listenerFunctionIsEquals = ((_a = entityListener.listener[type]) === null || _a === void 0 ? void 0 : _a.toString()) === listener[type].toString();
214
+ if (listenerFunctionIsEquals)
215
+ continue;
216
+ entityListener.listener[type] = listener[type];
217
+ }
218
+ }
219
+ }
220
+ return () => {
221
+ const newListeners = dataUnitSearchListeners.filter(currentListener => currentListener.entity !== entityName);
222
+ if (!newListeners.length) {
223
+ this._searchListenersByDataUnit.delete(dataUnitID);
224
+ return;
225
+ }
226
+ this._searchListenersByDataUnit.set(dataUnitID, newListeners);
227
+ };
228
+ }
229
+ applySearchListener(listenerType, entityName, argument, criteria, searchOptions) {
230
+ var _a;
231
+ const dataUnitId = searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.dataUnitId;
232
+ if (!dataUnitId)
233
+ return;
234
+ const entityListener = (_a = this._searchListenersByDataUnit.get(dataUnitId)) === null || _a === void 0 ? void 0 : _a.find(({ entity }) => entity === entityName);
235
+ if (!entityListener)
236
+ return;
237
+ const { listener } = entityListener;
238
+ if (!(listenerType in listener))
239
+ return;
240
+ return listener[listenerType]({ argument, criteria, searchOptions });
241
+ }
242
+ async loadPresentationConfig(entityName) {
243
+ var _a, _b;
244
+ let payload = buildLoadConfig(entityName);
245
+ const response = await DataFetcher.get().callServiceBroker("SystemUtilsSP.getConf", JSON.stringify(payload));
246
+ return (_b = (_a = response === null || response === void 0 ? void 0 : response.config) === null || _a === void 0 ? void 0 : _a.lastUsedMode) !== null && _b !== void 0 ? _b : 'list';
247
+ }
248
+ async savePresentationConfig(entityName, lastUsedMode) {
249
+ let payload = buildSaveConfig(entityName, lastUsedMode);
250
+ await DataFetcher.get().callServiceBroker("SystemUtilsSP.saveConf", JSON.stringify(payload));
251
+ }
252
+ async loadPesquisaGridConfig(entityName) {
253
+ const payload = buildLoadGridConfigPayload(entityName);
254
+ const response = await DataFetcher.get().callServiceBroker("GridConfig.getGridConfigFromJson", JSON.stringify(payload));
255
+ return parseGridConfig(response);
256
+ }
257
+ async savePesquisaGridConfig(entityName, columns) {
258
+ const payload = buildSaveGridConfigPayload(entityName, columns);
259
+ await DataFetcher.get().callServiceBroker("GridConfig.saveGridConfigFromJSON", JSON.stringify(payload));
260
+ }
261
+ async loadTree(entityName, argument, criteria, searchOptions) {
262
+ const requestBody = this.buildLoadTreeRequestBody(entityName, argument, criteria, searchOptions);
263
+ const response = await DataFetcher.get().callServiceBroker("Pesquisa.getStructuredData", JSON.stringify(requestBody));
264
+ return parseLegacyTree(response);
265
+ }
266
+ buildLoadTreeRequestBody(entityName, argument, criteria, searchOptions) {
267
+ var _a, _b, _c;
268
+ const listenerResult = this.applySearchListener(SearchListenerType.beforeSearch, entityName, argument, criteria, searchOptions);
269
+ console.log("criteria: ", criteria);
270
+ const incomeSearchOptions = (_a = listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.searchOptions) !== null && _a !== void 0 ? _a : searchOptions;
271
+ const rootEntity = incomeSearchOptions === null || incomeSearchOptions === void 0 ? void 0 : incomeSearchOptions.rootEntity;
272
+ const codeFieldName = incomeSearchOptions === null || incomeSearchOptions === void 0 ? void 0 : incomeSearchOptions.codeFieldName;
273
+ const expression = (_b = listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.criteria) === null || _b === void 0 ? void 0 : _b.expression;
274
+ const params = (_c = listenerResult === null || listenerResult === void 0 ? void 0 : listenerResult.criteria) === null || _c === void 0 ? void 0 : _c.params;
275
+ const instancia = {
276
+ 'nome': entityName,
277
+ 'nomeInstanciaLocal': rootEntity,
278
+ 'codeFieldName': codeFieldName,
279
+ };
280
+ if (expression) {
281
+ instancia['criterioLiteral'] = {
282
+ 'expressao': {
283
+ '$': expression,
284
+ },
285
+ 'parametro': params,
286
+ };
287
+ }
288
+ return {
289
+ 'instancia': instancia,
290
+ };
291
+ }
292
+ }
293
+ function buildLoadGridConfigPayload(entityName) {
294
+ return {
295
+ 'gridConfig': {
296
+ 'configName': `GrdCfgHtml5:grdcfg.dynaform.pesquisa.${entityName}`,
297
+ },
298
+ };
299
+ }
300
+ function buildSaveGridConfigPayload(entityName, columns) {
301
+ const field = {};
302
+ columns === null || columns === void 0 ? void 0 : columns.forEach((col, index) => field[`field${index}`] = col);
303
+ return {
304
+ 'gridConfig': {
305
+ 'compactMode': true,
306
+ 'configName': `GrdCfgHtml5:grdcfg.dynaform.pesquisa.${entityName}`,
307
+ field,
308
+ },
309
+ };
310
+ }
311
+ function buildLoadConfig(entityName) {
312
+ return {
313
+ 'config': {
314
+ 'chave': `PesquisaContent:${entityName}`,
315
+ 'tipo': 'T',
316
+ },
317
+ };
318
+ }
319
+ function buildSaveConfig(entityName, lastUsedMode) {
320
+ return {
321
+ 'config': {
322
+ lastUsedMode,
323
+ 'chave': `PesquisaContent:${entityName}`,
324
+ 'tipo': 'T',
325
+ }
326
+ };
327
+ }
328
+ function convertParamType(dataType) {
329
+ //Alerta: Cuidado pra não contaminar o DataType com a implementação
330
+ //atual da pesquisa... em geral, somente inteiros,
331
+ //data (com ou sem hora) e string são realmente relevantes
332
+ switch (dataType) {
333
+ case DataType.NUMBER:
334
+ return "I";
335
+ case DataType.DATE:
336
+ return "D";
337
+ default:
338
+ return "S";
339
+ }
340
+ }
341
+ var SearchListenerType;
342
+ (function (SearchListenerType) {
343
+ SearchListenerType["beforeSearch"] = "beforeSearch";
344
+ })(SearchListenerType || (SearchListenerType = {}));
345
+
1
346
  var PresentationMode;
2
347
  (function (PresentationMode) {
3
348
  PresentationMode["PRIMARY"] = "primary";
@@ -44,4 +389,4 @@ var SaveErrorsEnum;
44
389
  SaveErrorsEnum["DESCRIPTION_CANNOT_BE_CHANGED"] = "DESCRIPTION_CANNOT_BE_CHANGED";
45
390
  })(SaveErrorsEnum || (SaveErrorsEnum = {}));
46
391
 
47
- export { DataExporterOption as D, PresentationMode as P, SaveErrorsEnum as S, DataExporterType as a, DataExporterFormat as b };
392
+ export { DataExporterOption as D, PresentationMode as P, SaveErrorsEnum as S, PesquisaFetcher as a, DataExporterType as b, DataExporterFormat as c, buildGridMetadata as d };
@@ -247,7 +247,7 @@ function buildLoadDataResponse(recordsIn, dataUnit, request) {
247
247
  };
248
248
  return Promise.resolve({
249
249
  records: getPagesByRecords(records, offset, limit),
250
- paginationInfo: buildPaginationInfo(paginationInfoBuilderParams),
250
+ paginationInfo: dataUnit.pageSize ? buildPaginationInfo(paginationInfoBuilderParams) : undefined,
251
251
  });
252
252
  }
253
253
  function applySorting(records, dataUnit, sorting) {
@@ -1,4 +1,6 @@
1
1
  /* sankhyablocks custom elements */
2
+ export { PesquisaGrid as PesquisaGrid } from '../types/components/snk-pesquisa/pesquisa-grid/pesquisa-grid';
3
+ export { PesquisaTree as PesquisaTree } from '../types/components/snk-pesquisa/pesquisa-tree/pesquisa-tree';
2
4
  export { SnkActionsButton as SnkActionsButton } from '../types/components/snk-actions-button/snk-actions-button';
3
5
  export { SnkActionsForm as SnkActionsForm } from '../types/components/snk-actions-button/subcomponents/snk-actions-form';
4
6
  export { SnkApplication as SnkApplication } from '../types/components/snk-application/snk-application';
@@ -1,4 +1,6 @@
1
1
  export { setAssetPath, setNonce, setPlatformOptions } from '@stencil/core/internal/client';
2
+ export { PesquisaGrid, defineCustomElement as defineCustomElementPesquisaGrid } from './pesquisa-grid.js';
3
+ export { PesquisaTree, defineCustomElement as defineCustomElementPesquisaTree } from './pesquisa-tree.js';
2
4
  export { SnkActionsButton, defineCustomElement as defineCustomElementSnkActionsButton } from './snk-actions-button.js';
3
5
  export { SnkActionsForm, defineCustomElement as defineCustomElementSnkActionsForm } from './snk-actions-form.js';
4
6
  export { SnkApplication, defineCustomElement as defineCustomElementSnkApplication } from './snk-application.js';
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface PesquisaGrid extends Components.PesquisaGrid, HTMLElement {}
4
+ export const PesquisaGrid: {
5
+ prototype: PesquisaGrid;
6
+ new (): PesquisaGrid;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,6 @@
1
+ import { P as PesquisaGrid$1, d as defineCustomElement$1 } from './pesquisa-grid2.js';
2
+
3
+ const PesquisaGrid = PesquisaGrid$1;
4
+ const defineCustomElement = defineCustomElement$1;
5
+
6
+ export { PesquisaGrid, defineCustomElement };
@@ -0,0 +1,86 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
+ import { I as InMemoryLoader } from './dataunit-fetcher.js';
3
+ import './DataFetcher.js';
4
+ import { a as PesquisaFetcher } from './ISave.js';
5
+ import '@sankhyalabs/core';
6
+ import '@sankhyalabs/ezui/dist/collection/utils/constants';
7
+ import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
8
+ import './filter-item-type.enum.js';
9
+ import './form-config-fetcher.js';
10
+
11
+ const pesquisaGridCss = ".sc-pesquisa-grid-h{height:100vh;background:var(--background--xlight, #FFF);overflow-x:auto}ez-grid.sc-pesquisa-grid{--ez-grid__container--shadow:none;--ez-grid__header--shadow:none}";
12
+
13
+ const PesquisaGrid = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
14
+ constructor() {
15
+ super();
16
+ this.__registerHost();
17
+ this.pesquisaGridSelectItem = createEvent(this, "pesquisaGridSelectItem", 7);
18
+ this._pesquisaFetcher = new PesquisaFetcher();
19
+ this.metadata = undefined;
20
+ this.dataSource = [];
21
+ this.pkField = undefined;
22
+ this.descriptionField = undefined;
23
+ this.entityName = undefined;
24
+ this._inMemoryLoader = undefined;
25
+ this._dataunit = undefined;
26
+ this._gridConfig = undefined;
27
+ }
28
+ observeDataSource(newValue) {
29
+ if (!this._inMemoryLoader || !this._dataunit || !newValue)
30
+ return;
31
+ this._inMemoryLoader.records = [...newValue];
32
+ }
33
+ async componentWillLoad() {
34
+ this.initializeDataUnit();
35
+ this._gridConfig = await this._pesquisaFetcher.loadPesquisaGridConfig(this.entityName);
36
+ }
37
+ initializeDataUnit() {
38
+ var _a;
39
+ this._inMemoryLoader = new InMemoryLoader(this.metadata, (_a = this.dataSource) !== null && _a !== void 0 ? _a : []);
40
+ this._dataunit = this._inMemoryLoader.dataUnit;
41
+ this._dataunit.pageSize = 0;
42
+ }
43
+ handleDbClick(record) {
44
+ const option = {
45
+ value: record[this.pkField],
46
+ label: record[this.descriptionField],
47
+ };
48
+ this.pesquisaGridSelectItem.emit(option);
49
+ }
50
+ async handleConfigChanged({ detail }) {
51
+ var _a;
52
+ const columns = (_a = detail === null || detail === void 0 ? void 0 : detail.columns) !== null && _a !== void 0 ? _a : [];
53
+ await this._pesquisaFetcher.savePesquisaGridConfig(this.entityName, columns);
54
+ }
55
+ render() {
56
+ return (h(Host, null, h("ez-grid", { dataUnit: this._dataunit, config: this._gridConfig, canEdit: false, suppressCheckboxColumn: true, compact: true, autoFocus: false, onEzDoubleClick: ({ detail }) => this.handleDbClick(detail), onConfigChange: async (event) => this.handleConfigChanged(event) })));
57
+ }
58
+ static get watchers() { return {
59
+ "dataSource": ["observeDataSource"]
60
+ }; }
61
+ static get style() { return pesquisaGridCss; }
62
+ }, [2, "pesquisa-grid", {
63
+ "metadata": [16],
64
+ "dataSource": [16],
65
+ "pkField": [1, "pk-field"],
66
+ "descriptionField": [1, "description-field"],
67
+ "entityName": [1, "entity-name"],
68
+ "_inMemoryLoader": [32],
69
+ "_dataunit": [32],
70
+ "_gridConfig": [32]
71
+ }]);
72
+ function defineCustomElement() {
73
+ if (typeof customElements === "undefined") {
74
+ return;
75
+ }
76
+ const components = ["pesquisa-grid"];
77
+ components.forEach(tagName => { switch (tagName) {
78
+ case "pesquisa-grid":
79
+ if (!customElements.get(tagName)) {
80
+ customElements.define(tagName, PesquisaGrid);
81
+ }
82
+ break;
83
+ } });
84
+ }
85
+
86
+ export { PesquisaGrid as P, defineCustomElement as d };
@@ -0,0 +1,11 @@
1
+ import type { Components, JSX } from "../types/components";
2
+
3
+ interface PesquisaTree extends Components.PesquisaTree, HTMLElement {}
4
+ export const PesquisaTree: {
5
+ prototype: PesquisaTree;
6
+ new (): PesquisaTree;
7
+ };
8
+ /**
9
+ * Used to define this component and all nested components recursively.
10
+ */
11
+ export const defineCustomElement: () => void;
@@ -0,0 +1,6 @@
1
+ import { P as PesquisaTree$1, d as defineCustomElement$1 } from './pesquisa-tree2.js';
2
+
3
+ const PesquisaTree = PesquisaTree$1;
4
+ const defineCustomElement = defineCustomElement$1;
5
+
6
+ export { PesquisaTree, defineCustomElement };
@@ -0,0 +1,76 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
2
+ import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
3
+
4
+ const pesquisaTreeCss = ".sc-pesquisa-tree-h{--snk-pesquisa--tree__action-container--top:var(--space--sm);--snk-pesquisa--tree__action-container--right:var(--space--small);--snk-pesquisa--tree__min-height:var(--space--extra-large);background:var(--background--xlight, #FFF);position:relative;display:inline-block;min-height:var(--snk-pesquisa--tree__min-height)}.sc-pesquisa-tree-h:hover .actions-container.sc-pesquisa-tree{display:flex}.actions-container.sc-pesquisa-tree{flex-direction:row;position:absolute;top:var(--snk-pesquisa--tree__action-container--top);right:var(--snk-pesquisa--tree__action-container--right);display:none}";
5
+
6
+ const PesquisaTree = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ this.__registerHost();
10
+ this.pesquisaTreeSelectItem = createEvent(this, "pesquisaTreeSelectItem", 7);
11
+ this.treeLoader = undefined;
12
+ this.argument = undefined;
13
+ this.allowsNonAnalytic = false;
14
+ this.items = [];
15
+ }
16
+ async applyFilter() {
17
+ await this._tree.applyFilter(this.argument);
18
+ }
19
+ async loadTree() {
20
+ if (!this.treeLoader || typeof this.treeLoader !== 'function')
21
+ return;
22
+ const response = await this.treeLoader((this.argument || '').trim());
23
+ this.items = [...response];
24
+ }
25
+ expandOrCloseAllItems(items, expanded) {
26
+ return items.map(item => (Object.assign(Object.assign({}, item), { expanded, children: item.children ? this.expandOrCloseAllItems(item.children, expanded) : undefined })));
27
+ }
28
+ handleExpandAll() {
29
+ this.items = [...this.expandOrCloseAllItems(this.items, true)];
30
+ }
31
+ handleCloseAll() {
32
+ this.items = [...this.expandOrCloseAllItems(this.items, false)];
33
+ }
34
+ handleDbClick(item) {
35
+ var _a;
36
+ if (!this.allowsNonAnalytic && !((_a = item['props']) === null || _a === void 0 ? void 0 : _a['analitico'])) {
37
+ const title = 'Erro';
38
+ const message = `Há pelo menos um registro inválido selecionado. Você deve selecionar itens do tipo 'analítico'.`;
39
+ ApplicationUtils.error(title, message);
40
+ return;
41
+ }
42
+ const option = {
43
+ value: item.id,
44
+ label: item.label,
45
+ };
46
+ this.pesquisaTreeSelectItem.emit(option);
47
+ }
48
+ async componentWillLoad() {
49
+ await this.loadTree();
50
+ }
51
+ render() {
52
+ return (h(Host, null, h("div", { class: 'actions-container' }, h("ez-button", { size: 'small', mode: 'icon', class: 'ez-margin-right--small', iconName: 'show-list', title: "Expandir", onClick: () => this.handleExpandAll() }), h("ez-button", { size: 'small', mode: 'icon', iconName: 'hide-list', title: "Recolher", onClick: () => this.handleCloseAll() })), h("ez-tree", { ref: (element) => this._tree = element, onEzDbClickItem: ({ detail }) => this.handleDbClick(detail), items: this.items })));
53
+ }
54
+ static get style() { return pesquisaTreeCss; }
55
+ }, [2, "pesquisa-tree", {
56
+ "treeLoader": [16],
57
+ "argument": [1025],
58
+ "allowsNonAnalytic": [4, "allows-non-analytic"],
59
+ "items": [32],
60
+ "applyFilter": [64]
61
+ }]);
62
+ function defineCustomElement() {
63
+ if (typeof customElements === "undefined") {
64
+ return;
65
+ }
66
+ const components = ["pesquisa-tree"];
67
+ components.forEach(tagName => { switch (tagName) {
68
+ case "pesquisa-tree":
69
+ if (!customElements.get(tagName)) {
70
+ customElements.define(tagName, PesquisaTree);
71
+ }
72
+ break;
73
+ } });
74
+ }
75
+
76
+ export { PesquisaTree as P, defineCustomElement as d };
@@ -2,7 +2,6 @@ import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal
2
2
  import { ApplicationContext, StringUtils, ErrorException, WarningException, ObjectUtils, DateUtils, ServiceUtils, StorageType, ArrayUtils, ElementIDUtils } from '@sankhyalabs/core';
3
3
  import { D as DataFetcher } from './DataFetcher.js';
4
4
  import { P as ParamType } from './ParamType.js';
5
- import './pesquisa-fetcher.js';
6
5
  import './ISave.js';
7
6
  import '@sankhyalabs/ezui/dist/collection/utils/constants';
8
7
  import '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';