@sankhyalabs/sankhyablocks 1.1.28 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +75 -75
  3. package/dist/cjs/index-4720dab8.js +735 -0
  4. package/dist/cjs/loader.cjs.js +2 -2
  5. package/dist/cjs/sankhyablocks.cjs.js +2 -2
  6. package/dist/cjs/snk-application.cjs.entry.js +668 -653
  7. package/dist/collection/collection-manifest.json +5 -34
  8. package/dist/collection/components/snk-application/snk-application.css +5 -5
  9. package/dist/collection/components/snk-application/snk-application.js +492 -492
  10. package/dist/collection/index.js +1 -1
  11. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +158 -158
  12. package/dist/collection/lib/http/data-fetcher/fetchers/application-config-fetcher.js +23 -23
  13. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +188 -188
  14. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +25 -25
  15. package/dist/collection/lib/http/data-fetcher/fetchers/grid-config-fetcher.js +2 -2
  16. package/dist/collection/lib/http/data-fetcher/fetchers/parameters-fecher.js +59 -59
  17. package/dist/collection/lib/http/data-fetcher/fetchers/resource-fetcher.js +30 -30
  18. package/dist/collection/lib/http/data-fetcher/state/LoadStateManager.js +66 -66
  19. package/dist/collection/lib/utils/pesquisa.js +16 -16
  20. package/dist/collection/lib/utils/urlutils.js +23 -23
  21. package/dist/collection/lib/workspace/workspace.js +7 -7
  22. package/dist/components/snk-application.js +655 -640
  23. package/dist/esm/index-72d4e2e0.js +709 -0
  24. package/dist/esm/loader.js +2 -2
  25. package/dist/esm/polyfills/core-js.js +0 -0
  26. package/dist/esm/polyfills/dom.js +0 -0
  27. package/dist/esm/polyfills/es5-html-element.js +0 -0
  28. package/dist/esm/polyfills/index.js +0 -0
  29. package/dist/esm/polyfills/system.js +0 -0
  30. package/dist/esm/sankhyablocks.js +2 -2
  31. package/dist/esm/snk-application.entry.js +626 -611
  32. package/dist/sankhyablocks/p-5d8ddbda.entry.js +57 -0
  33. package/dist/sankhyablocks/p-a33afc3b.js +2 -0
  34. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  35. package/dist/types/components/snk-application/snk-application.d.ts +44 -44
  36. package/dist/types/index.d.ts +1 -1
  37. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +15 -15
  38. package/dist/types/lib/http/data-fetcher/fetchers/application-config-fetcher.d.ts +6 -6
  39. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +12 -12
  40. package/dist/types/lib/http/data-fetcher/fetchers/form-config-fetcher.d.ts +5 -5
  41. package/dist/types/lib/http/data-fetcher/fetchers/grid-config-fetcher.d.ts +2 -2
  42. package/dist/types/lib/http/data-fetcher/fetchers/parameters-fecher.d.ts +13 -13
  43. package/dist/types/lib/http/data-fetcher/fetchers/resource-fetcher.d.ts +6 -6
  44. package/dist/types/lib/http/data-fetcher/state/LoadStateManager.d.ts +23 -23
  45. package/dist/types/lib/utils/pesquisa.d.ts +2 -2
  46. package/dist/types/lib/utils/urlutils.d.ts +4 -4
  47. package/dist/types/lib/workspace/workspace.d.ts +4 -4
  48. package/package.json +63 -52
  49. package/react/.keepfolder +1 -0
  50. package/react/components.d.ts +3 -32
  51. package/react/components.js +5 -34
  52. package/react/components.js.map +1 -1
  53. package/react/react-component-lib/createComponent.d.ts +10 -10
  54. package/react/react-component-lib/createComponent.js +58 -74
  55. package/react/react-component-lib/createComponent.js.map +1 -1
  56. package/react/react-component-lib/createOverlayComponent.d.ts +20 -21
  57. package/react/react-component-lib/createOverlayComponent.js +88 -108
  58. package/react/react-component-lib/createOverlayComponent.js.map +1 -1
  59. package/react/react-component-lib/index.d.ts +2 -2
  60. package/react/react-component-lib/index.js +2 -2
  61. package/react/react-component-lib/interfaces.d.ts +29 -29
  62. package/react/react-component-lib/utils/attachProps.d.ts +12 -12
  63. package/react/react-component-lib/utils/attachProps.js +95 -97
  64. package/react/react-component-lib/utils/attachProps.js.map +1 -1
  65. package/react/react-component-lib/utils/case.d.ts +2 -2
  66. package/react/react-component-lib/utils/case.js +6 -6
  67. package/react/react-component-lib/utils/dev.d.ts +2 -2
  68. package/react/react-component-lib/utils/dev.js +12 -12
  69. package/react/react-component-lib/utils/index.d.ts +7 -10
  70. package/react/react-component-lib/utils/index.js +20 -33
  71. package/react/react-component-lib/utils/index.js.map +1 -1
  72. package/dist/cjs/ApplicationUtils-05b74ee9.js +0 -39
  73. package/dist/cjs/AssetsUtils-7e3c38f9.js +0 -24
  74. package/dist/cjs/CSSVarsUtils-75ca9c64.js +0 -19
  75. package/dist/cjs/_commonjsHelpers-537d719a.js +0 -20
  76. package/dist/cjs/ez-action-chip.cjs.entry.js +0 -27
  77. package/dist/cjs/ez-application.cjs.entry.js +0 -26
  78. package/dist/cjs/ez-button_4.cjs.entry.js +0 -660
  79. package/dist/cjs/ez-calendar.cjs.entry.js +0 -223
  80. package/dist/cjs/ez-collapsible-box.cjs.entry.js +0 -47
  81. package/dist/cjs/ez-combo-box.cjs.entry.js +0 -278
  82. package/dist/cjs/ez-date-input.cjs.entry.js +0 -102
  83. package/dist/cjs/ez-date-time-input.cjs.entry.js +0 -145
  84. package/dist/cjs/ez-dialog.cjs.entry.js +0 -89
  85. package/dist/cjs/ez-form.cjs.entry.js +0 -785
  86. package/dist/cjs/ez-grid.cjs.entry.js +0 -110485
  87. package/dist/cjs/ez-icon.cjs.entry.js +0 -41
  88. package/dist/cjs/ez-label-chip.cjs.entry.js +0 -104
  89. package/dist/cjs/ez-modal_2.cjs.entry.js +0 -316
  90. package/dist/cjs/ez-number-input.cjs.entry.js +0 -86
  91. package/dist/cjs/ez-popover.cjs.entry.js +0 -120
  92. package/dist/cjs/ez-popup.cjs.entry.js +0 -48
  93. package/dist/cjs/ez-search.cjs.entry.js +0 -64
  94. package/dist/cjs/ez-tabselector.cjs.entry.js +0 -198
  95. package/dist/cjs/ez-text-area.cjs.entry.js +0 -114
  96. package/dist/cjs/ez-text-input.cjs.entry.js +0 -201
  97. package/dist/cjs/ez-time-input.cjs.entry.js +0 -118
  98. package/dist/cjs/ez-toast.cjs.entry.js +0 -44
  99. package/dist/cjs/ez-upload.cjs.entry.js +0 -356
  100. package/dist/cjs/index-682c98b2.js +0 -1771
  101. package/dist/cjs/test-du.cjs.entry.js +0 -76
  102. package/dist/components/ApplicationUtils.js +0 -37
  103. package/dist/components/AssetsUtils.js +0 -22
  104. package/dist/components/CSSVarsUtils.js +0 -17
  105. package/dist/components/_commonjsHelpers.js +0 -17
  106. package/dist/components/ez-action-chip.js +0 -44
  107. package/dist/components/ez-application.js +0 -39
  108. package/dist/components/ez-button.js +0 -6
  109. package/dist/components/ez-button2.js +0 -105
  110. package/dist/components/ez-calendar.js +0 -6
  111. package/dist/components/ez-calendar2.js +0 -242
  112. package/dist/components/ez-check.js +0 -6
  113. package/dist/components/ez-check2.js +0 -94
  114. package/dist/components/ez-collapsible-box.js +0 -67
  115. package/dist/components/ez-combo-box.js +0 -6
  116. package/dist/components/ez-combo-box2.js +0 -311
  117. package/dist/components/ez-date-input.js +0 -135
  118. package/dist/components/ez-date-time-input.js +0 -179
  119. package/dist/components/ez-dialog.js +0 -124
  120. package/dist/components/ez-form.js +0 -6
  121. package/dist/components/ez-form2.js +0 -807
  122. package/dist/components/ez-grid.js +0 -110576
  123. package/dist/components/ez-icon.js +0 -6
  124. package/dist/components/ez-icon2.js +0 -56
  125. package/dist/components/ez-label-chip.js +0 -125
  126. package/dist/components/ez-list.js +0 -6
  127. package/dist/components/ez-list2.js +0 -523
  128. package/dist/components/ez-modal.js +0 -6
  129. package/dist/components/ez-modal2.js +0 -82
  130. package/dist/components/ez-number-input.js +0 -115
  131. package/dist/components/ez-popover.js +0 -145
  132. package/dist/components/ez-popup.js +0 -67
  133. package/dist/components/ez-search.js +0 -100
  134. package/dist/components/ez-tabselector.js +0 -6
  135. package/dist/components/ez-tabselector2.js +0 -213
  136. package/dist/components/ez-text-area.js +0 -137
  137. package/dist/components/ez-text-input.js +0 -6
  138. package/dist/components/ez-text-input2.js +0 -223
  139. package/dist/components/ez-time-input.js +0 -153
  140. package/dist/components/ez-toast.js +0 -64
  141. package/dist/components/ez-upload.js +0 -382
  142. package/dist/components/grid-config.js +0 -6
  143. package/dist/components/grid-config2.js +0 -318
  144. package/dist/components/select-box.js +0 -6
  145. package/dist/components/select-box2.js +0 -47
  146. package/dist/components/test-du.js +0 -101
  147. package/dist/esm/ApplicationUtils-e0b6d857.js +0 -37
  148. package/dist/esm/AssetsUtils-6e6624dc.js +0 -22
  149. package/dist/esm/CSSVarsUtils-0787c3f3.js +0 -17
  150. package/dist/esm/_commonjsHelpers-9943807e.js +0 -17
  151. package/dist/esm/ez-action-chip.entry.js +0 -23
  152. package/dist/esm/ez-application.entry.js +0 -22
  153. package/dist/esm/ez-button_4.entry.js +0 -653
  154. package/dist/esm/ez-calendar.entry.js +0 -219
  155. package/dist/esm/ez-collapsible-box.entry.js +0 -43
  156. package/dist/esm/ez-combo-box.entry.js +0 -274
  157. package/dist/esm/ez-date-input.entry.js +0 -98
  158. package/dist/esm/ez-date-time-input.entry.js +0 -141
  159. package/dist/esm/ez-dialog.entry.js +0 -85
  160. package/dist/esm/ez-form.entry.js +0 -781
  161. package/dist/esm/ez-grid.entry.js +0 -110481
  162. package/dist/esm/ez-icon.entry.js +0 -37
  163. package/dist/esm/ez-label-chip.entry.js +0 -100
  164. package/dist/esm/ez-modal_2.entry.js +0 -311
  165. package/dist/esm/ez-number-input.entry.js +0 -82
  166. package/dist/esm/ez-popover.entry.js +0 -116
  167. package/dist/esm/ez-popup.entry.js +0 -44
  168. package/dist/esm/ez-search.entry.js +0 -60
  169. package/dist/esm/ez-tabselector.entry.js +0 -194
  170. package/dist/esm/ez-text-area.entry.js +0 -110
  171. package/dist/esm/ez-text-input.entry.js +0 -197
  172. package/dist/esm/ez-time-input.entry.js +0 -114
  173. package/dist/esm/ez-toast.entry.js +0 -40
  174. package/dist/esm/ez-upload.entry.js +0 -352
  175. package/dist/esm/index-35088a3f.js +0 -1740
  176. package/dist/esm/test-du.entry.js +0 -72
  177. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-action-chip/ez-action-chip.css +0 -67
  178. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-application/ez-application.css +0 -3
  179. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-button/ez-button.css +0 -180
  180. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-calendar/ez-calendar.css +0 -319
  181. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-check/ez-check.css +0 -327
  182. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-collapsible-box/ez-collapsible-box.css +0 -162
  183. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-combo-box/ez-combo-box.css +0 -217
  184. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-input/ez-date-input.css +0 -49
  185. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-date-time-input/ez-date-time-input.css +0 -44
  186. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-dialog/ez-dialog.css +0 -527
  187. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-form/ez-form.css +0 -5
  188. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/ez-grid.css +0 -31
  189. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/gridconfig/grid-config.css +0 -129
  190. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-grid/subcomponents/select-box/select-box.css +0 -10
  191. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-icon/ez-icon.css +0 -176
  192. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-label-chip/ez-label-chip.css +0 -139
  193. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-list/ez-list.css +0 -335
  194. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-modal/ez-modal.css +0 -358
  195. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-number-input/ez-number-input.css +0 -4
  196. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popover/ez-popover.css +0 -44
  197. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-popup/ez-popup.css +0 -405
  198. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-search/ez-search.css +0 -3
  199. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-tabselector/ez-tabselector.css +0 -138
  200. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-area/ez-text-area.css +0 -165
  201. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-text-input/ez-text-input.css +0 -196
  202. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-time-input/ez-time-input.css +0 -10
  203. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-toast/ez-toast.css +0 -127
  204. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/ez-upload/ez-upload.css +0 -568
  205. package/dist/node_modules/@sankhyalabs/ezui/dist/collection/components/test-du/test-du.css +0 -3
  206. package/dist/sankhyablocks/p-0183d259.entry.js +0 -1
  207. package/dist/sankhyablocks/p-01f23a70.entry.js +0 -1
  208. package/dist/sankhyablocks/p-07c32f68.entry.js +0 -1
  209. package/dist/sankhyablocks/p-0f90499d.entry.js +0 -1
  210. package/dist/sankhyablocks/p-105724a3.entry.js +0 -1
  211. package/dist/sankhyablocks/p-112455b1.js +0 -1
  212. package/dist/sankhyablocks/p-2ac02d48.entry.js +0 -1
  213. package/dist/sankhyablocks/p-35364a97.entry.js +0 -1
  214. package/dist/sankhyablocks/p-3f6aa9a7.entry.js +0 -1
  215. package/dist/sankhyablocks/p-4811bc0a.entry.js +0 -369
  216. package/dist/sankhyablocks/p-5f9af495.entry.js +0 -1
  217. package/dist/sankhyablocks/p-60967cf0.js +0 -1
  218. package/dist/sankhyablocks/p-70ad6c16.entry.js +0 -1
  219. package/dist/sankhyablocks/p-710bfffe.entry.js +0 -1
  220. package/dist/sankhyablocks/p-73397a0f.entry.js +0 -57
  221. package/dist/sankhyablocks/p-811b4b9d.js +0 -1
  222. package/dist/sankhyablocks/p-813fe4f7.js +0 -1
  223. package/dist/sankhyablocks/p-85a9446b.js +0 -2
  224. package/dist/sankhyablocks/p-89a1100f.entry.js +0 -1
  225. package/dist/sankhyablocks/p-8b543003.entry.js +0 -1
  226. package/dist/sankhyablocks/p-9750632b.entry.js +0 -1
  227. package/dist/sankhyablocks/p-a96272f7.entry.js +0 -1
  228. package/dist/sankhyablocks/p-ac8842e5.entry.js +0 -1
  229. package/dist/sankhyablocks/p-ba64cc41.entry.js +0 -1
  230. package/dist/sankhyablocks/p-c1ede043.entry.js +0 -1
  231. package/dist/sankhyablocks/p-d90ebb85.entry.js +0 -1
  232. package/dist/sankhyablocks/p-e5355a29.entry.js +0 -1
  233. package/dist/sankhyablocks/p-ef04b633.entry.js +0 -1
  234. package/dist/sankhyablocks/p-f6db07fb.entry.js +0 -1
  235. package/dist/sankhyablocks/p-f80cabc7.entry.js +0 -1
  236. package/dist/sankhyablocks/p-fcd9bd92.entry.js +0 -1
@@ -1,8 +1,23 @@
1
1
  import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
2
  import { DataUnit, ChangeOperation, DateUtils, StringUtils, ApplicationContext } from '@sankhyalabs/core';
3
- import { c as createCommonjsModule, a as commonjsGlobal } from './_commonjsHelpers.js';
4
3
  import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
5
4
 
5
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
+
7
+ function createCommonjsModule(fn, basedir, module) {
8
+ return module = {
9
+ path: basedir,
10
+ exports: {},
11
+ require: function (path, base) {
12
+ return commonjsRequire();
13
+ }
14
+ }, fn(module, module.exports), module.exports;
15
+ }
16
+
17
+ function commonjsRequire () {
18
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
19
+ }
20
+
6
21
  var browserPonyfill = createCommonjsModule(function (module, exports) {
7
22
  var global = typeof self !== 'undefined' ? self : commonjsGlobal;
8
23
  var __self__ = (function () {
@@ -6414,663 +6429,663 @@ Object.defineProperty(exports, "GraphQLWebSocketClient", { enumerable: true, get
6414
6429
  //# sourceMappingURL=index.js.map
6415
6430
  });
6416
6431
 
6417
- class HttpFetcher {
6418
- constructor() {
6419
- this.watingRequestsById = new Map();
6420
- }
6421
- static get() {
6422
- if (!HttpFetcher.instance) {
6423
- HttpFetcher.instance = new HttpFetcher();
6424
- const application = document.querySelector(this.appTagName);
6425
- if (application === null) {
6426
- HttpFetcher.instance.resume();
6427
- }
6428
- else {
6429
- application.addEventListener('applicationLoading', () => HttpFetcher.instance.pause());
6430
- application.addEventListener('applicationLoaded', () => HttpFetcher.instance.resume());
6431
- }
6432
- }
6433
- return this.instance;
6434
- }
6435
- async callGraphQL(req) {
6436
- var _a;
6437
- const reqKey = this.getReqKey(req);
6438
- req.queryID = reqKey;
6439
- req.values.queryID = reqKey;
6440
- if (this.ready) {
6441
- return new Promise(async (resolve, reject) => {
6442
- let query = this.getQueryTemplate(req);
6443
- const res = await this.fecthGrapql([{ document: query, variables: req.values }]);
6444
- if (res.errors.length > 0) {
6445
- reject(res);
6446
- }
6447
- else {
6448
- //resolve(res);
6449
- //FIXME: Precisamos trabalhar melhor a resposta, quem chamou
6450
- //a API não pode ficar responsavel por desempacotar... fiz uma
6451
- //gambiarra aqui...
6452
- resolve(res.data[0][reqKey]);
6453
- }
6454
- });
6455
- }
6456
- else {
6457
- if (!this.watingRequestsById.has(reqKey)) {
6458
- this.watingRequestsById.set(reqKey, new WaitingRequest(req));
6459
- }
6460
- return (_a = this.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
6461
- }
6462
- }
6463
- getReqKey(req) {
6464
- return window.btoa(this.hashCode(`${req.query}${JSON.stringify(req.values || "")}`)).replace(/=/g, "");
6465
- }
6466
- getQueryTemplate(re) {
6467
- return (re.query || "").replaceAll("$queryAlias$", re.queryID);
6468
- }
6469
- getWatingRequest(reqID) {
6470
- return this.watingRequestsById.get(reqID);
6471
- }
6472
- pause() {
6473
- this.ready = false;
6474
- }
6475
- async resume() {
6476
- this.ready = true;
6477
- if (this.watingRequestsById.size > 0) {
6478
- const requestsBatch = [];
6479
- this.watingRequestsById.forEach(async (waitingReq) => {
6480
- let query = this.getQueryTemplate(waitingReq.request);
6481
- requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
6482
- });
6483
- let res = undefined;
6484
- let dataResponse = [];
6485
- let errorsResponse = [];
6486
- res = await this.fecthGrapql(requestsBatch);
6487
- dataResponse = res.data;
6488
- errorsResponse = res.errors;
6489
- //Reject promises with errors from query
6490
- errorsResponse.forEach((errorResponse) => {
6491
- Object.entries(errorResponse).forEach(([_key, val]) => {
6492
- var _a;
6493
- (((_a = this.getWatingRequest(val.request.variables[val.index].queryID)) === null || _a === void 0 ? void 0 : _a.reject) || Promise.reject)(val);
6494
- });
6495
- });
6496
- //Resolve promises with data from query
6497
- dataResponse.forEach((data) => {
6498
- Object.entries(data).forEach(([key, val]) => {
6499
- var _a;
6500
- (((_a = this.getWatingRequest(key)) === null || _a === void 0 ? void 0 : _a.resolve) || Promise.resolve)(val);
6501
- });
6502
- });
6503
- this.watingRequestsById.clear();
6504
- }
6505
- }
6506
- async fecthGrapql(request) {
6507
- let res = undefined;
6508
- let dataResponse = [];
6509
- let errorsResponse = [];
6510
- try {
6511
- res = await dist.batchRequests('http://localhost:8082/', request);
6512
- res.forEach((resItem) => {
6513
- dataResponse.push(resItem.data);
6514
- });
6515
- }
6516
- catch (err) {
6517
- //TODO: Tratar erro quando não existir err.response
6518
- res = err.response;
6519
- const req = err.request;
6520
- Object.entries(res).forEach(([key, val]) => {
6521
- if (val.errors) {
6522
- errorsResponse.push(val.errors.map((item) => {
6523
- item.request = req;
6524
- item.index = Number(key);
6525
- return item;
6526
- }));
6527
- }
6528
- else if (val.data) {
6529
- dataResponse.push(val.data);
6530
- }
6531
- });
6532
- }
6533
- return { data: dataResponse, errors: errorsResponse };
6534
- }
6535
- //TODO: Mover este metodo para o @sankhyalabs/core classe string utils.
6536
- hashCode(txt) {
6537
- var hash = 0, i, chr;
6538
- if (txt.length === 0)
6539
- return hash.toString();
6540
- for (i = 0; i < txt.length; i++) {
6541
- chr = txt.charCodeAt(i);
6542
- hash = ((hash << 5) - hash) + chr;
6543
- hash |= 0; // Convert to 32bit integer
6544
- }
6545
- return hash.toString();
6546
- }
6547
- ;
6548
- }
6549
- HttpFetcher.appTagName = "snk-application";
6550
- class WaitingRequest {
6551
- constructor(req) {
6552
- this._resolve = () => { };
6553
- this._reject = () => { };
6554
- this._request = undefined;
6555
- this._request = req;
6556
- this._promisse = new Promise((resolve, reject) => {
6557
- this._resolve = resolve;
6558
- this._reject = reject;
6559
- });
6560
- }
6561
- get resolve() {
6562
- return this._resolve;
6563
- }
6564
- get reject() {
6565
- return this._reject;
6566
- }
6567
- get promise() {
6568
- return this._promisse;
6569
- }
6570
- get request() {
6571
- return this._request;
6572
- }
6432
+ class HttpFetcher {
6433
+ constructor() {
6434
+ this.watingRequestsById = new Map();
6435
+ }
6436
+ static get() {
6437
+ if (!HttpFetcher.instance) {
6438
+ HttpFetcher.instance = new HttpFetcher();
6439
+ const application = document.querySelector(this.appTagName);
6440
+ if (application === null) {
6441
+ HttpFetcher.instance.resume();
6442
+ }
6443
+ else {
6444
+ application.addEventListener('applicationLoading', () => HttpFetcher.instance.pause());
6445
+ application.addEventListener('applicationLoaded', () => HttpFetcher.instance.resume());
6446
+ }
6447
+ }
6448
+ return this.instance;
6449
+ }
6450
+ async callGraphQL(req) {
6451
+ var _a;
6452
+ const reqKey = this.getReqKey(req);
6453
+ req.queryID = reqKey;
6454
+ req.values.queryID = reqKey;
6455
+ if (this.ready) {
6456
+ return new Promise(async (resolve, reject) => {
6457
+ let query = this.getQueryTemplate(req);
6458
+ const res = await this.fecthGrapql([{ document: query, variables: req.values }]);
6459
+ if (res.errors.length > 0) {
6460
+ reject(res);
6461
+ }
6462
+ else {
6463
+ //resolve(res);
6464
+ //FIXME: Precisamos trabalhar melhor a resposta, quem chamou
6465
+ //a API não pode ficar responsavel por desempacotar... fiz uma
6466
+ //gambiarra aqui...
6467
+ resolve(res.data[0][reqKey]);
6468
+ }
6469
+ });
6470
+ }
6471
+ else {
6472
+ if (!this.watingRequestsById.has(reqKey)) {
6473
+ this.watingRequestsById.set(reqKey, new WaitingRequest(req));
6474
+ }
6475
+ return (_a = this.getWatingRequest(reqKey)) === null || _a === void 0 ? void 0 : _a.promise;
6476
+ }
6477
+ }
6478
+ getReqKey(req) {
6479
+ return window.btoa(this.hashCode(`${req.query}${JSON.stringify(req.values || "")}`)).replace(/=/g, "");
6480
+ }
6481
+ getQueryTemplate(re) {
6482
+ return (re.query || "").replaceAll("$queryAlias$", re.queryID);
6483
+ }
6484
+ getWatingRequest(reqID) {
6485
+ return this.watingRequestsById.get(reqID);
6486
+ }
6487
+ pause() {
6488
+ this.ready = false;
6489
+ }
6490
+ async resume() {
6491
+ this.ready = true;
6492
+ if (this.watingRequestsById.size > 0) {
6493
+ const requestsBatch = [];
6494
+ this.watingRequestsById.forEach(async (waitingReq) => {
6495
+ let query = this.getQueryTemplate(waitingReq.request);
6496
+ requestsBatch.push({ document: query, variables: Object.assign({}, waitingReq.request.values) });
6497
+ });
6498
+ let res = undefined;
6499
+ let dataResponse = [];
6500
+ let errorsResponse = [];
6501
+ res = await this.fecthGrapql(requestsBatch);
6502
+ dataResponse = res.data;
6503
+ errorsResponse = res.errors;
6504
+ //Reject promises with errors from query
6505
+ errorsResponse.forEach((errorResponse) => {
6506
+ Object.entries(errorResponse).forEach(([_key, val]) => {
6507
+ var _a;
6508
+ (((_a = this.getWatingRequest(val.request.variables[val.index].queryID)) === null || _a === void 0 ? void 0 : _a.reject) || Promise.reject)(val);
6509
+ });
6510
+ });
6511
+ //Resolve promises with data from query
6512
+ dataResponse.forEach((data) => {
6513
+ Object.entries(data).forEach(([key, val]) => {
6514
+ var _a;
6515
+ (((_a = this.getWatingRequest(key)) === null || _a === void 0 ? void 0 : _a.resolve) || Promise.resolve)(val);
6516
+ });
6517
+ });
6518
+ this.watingRequestsById.clear();
6519
+ }
6520
+ }
6521
+ async fecthGrapql(request) {
6522
+ let res = undefined;
6523
+ let dataResponse = [];
6524
+ let errorsResponse = [];
6525
+ try {
6526
+ res = await dist.batchRequests('http://localhost:8082/', request);
6527
+ res.forEach((resItem) => {
6528
+ dataResponse.push(resItem.data);
6529
+ });
6530
+ }
6531
+ catch (err) {
6532
+ //TODO: Tratar erro quando não existir err.response
6533
+ res = err.response;
6534
+ const req = err.request;
6535
+ Object.entries(res).forEach(([key, val]) => {
6536
+ if (val.errors) {
6537
+ errorsResponse.push(val.errors.map((item) => {
6538
+ item.request = req;
6539
+ item.index = Number(key);
6540
+ return item;
6541
+ }));
6542
+ }
6543
+ else if (val.data) {
6544
+ dataResponse.push(val.data);
6545
+ }
6546
+ });
6547
+ }
6548
+ return { data: dataResponse, errors: errorsResponse };
6549
+ }
6550
+ //TODO: Mover este metodo para o @sankhyalabs/core classe string utils.
6551
+ hashCode(txt) {
6552
+ var hash = 0, i, chr;
6553
+ if (txt.length === 0)
6554
+ return hash.toString();
6555
+ for (i = 0; i < txt.length; i++) {
6556
+ chr = txt.charCodeAt(i);
6557
+ hash = ((hash << 5) - hash) + chr;
6558
+ hash |= 0; // Convert to 32bit integer
6559
+ }
6560
+ return hash.toString();
6561
+ }
6562
+ ;
6563
+ }
6564
+ HttpFetcher.appTagName = "snk-application";
6565
+ class WaitingRequest {
6566
+ constructor(req) {
6567
+ this._resolve = () => { };
6568
+ this._reject = () => { };
6569
+ this._request = undefined;
6570
+ this._request = req;
6571
+ this._promisse = new Promise((resolve, reject) => {
6572
+ this._resolve = resolve;
6573
+ this._reject = reject;
6574
+ });
6575
+ }
6576
+ get resolve() {
6577
+ return this._resolve;
6578
+ }
6579
+ get reject() {
6580
+ return this._reject;
6581
+ }
6582
+ get promise() {
6583
+ return this._promisse;
6584
+ }
6585
+ get request() {
6586
+ return this._request;
6587
+ }
6573
6588
  }
6574
6589
 
6575
- class DataUnitFetcher {
6576
- constructor() {
6577
- this.templateByQuery = new Map();
6578
- this.buldTemplates();
6579
- }
6580
- buldTemplates() {
6581
- this.templateByQuery.set("fetchDataUnit", dist.gql `query($name: String!) {
6582
- $queryAlias$: fetchDataUnit(name: $name){
6583
- name
6584
- fields{
6585
- name
6586
- defaultValue
6587
- label
6588
- readOnly
6589
- required
6590
- dataType
6591
- userInterface
6592
- properties{
6593
- name
6594
- value
6595
- }
6596
- dependencies{
6597
- masterFields
6598
- type
6599
- expression
6600
- }
6601
- }
6602
- }
6603
- }`);
6604
- this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $first: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
6605
- $queryAlias$: fetchDataUnit(name: $dataunit){
6606
- data(first: $first offset: $offset filters: $filter sort: $sort){
6607
- first
6608
- offset
6609
- total
6610
- hasMore
6611
- records{
6612
- id
6613
- fields {
6614
- name
6615
- value
6616
- }
6617
- }
6618
- }
6619
- }
6620
- }`);
6621
- this.templateByQuery.set("saveData", dist.gql `mutation($changes: [Change!]!) {
6622
- $queryAlias$: saveDataUnitChanges(changes: $changes){
6623
- oldId
6624
- id
6625
- fields {
6626
- name
6627
- value
6628
- }
6629
- }
6630
- }`);
6631
- }
6632
- getDataUnit(entityName, resourceID) {
6633
- const dataUnit = new DataUnit(`dd://${entityName}/${resourceID}`);
6634
- dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
6635
- dataUnit.dataLoader = (dataUnit, sort, filters) => this.loadData(dataUnit, sort, filters);
6636
- dataUnit.saveLoader = (dataUnit, changes) => this.saveData(dataUnit, changes);
6637
- dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
6638
- return dataUnit;
6639
- }
6640
- loadMetadata(dataUnit) {
6641
- return new Promise((resolve, reject) => {
6642
- HttpFetcher.get()
6643
- .callGraphQL({
6644
- values: { name: dataUnit.name },
6645
- query: this.templateByQuery.get("fetchDataUnit"),
6646
- })
6647
- .then((resp) => {
6648
- var _a;
6649
- const metadata = {
6650
- name: resp.name,
6651
- label: resp.name,
6652
- fields: [],
6653
- };
6654
- (_a = resp.fields) === null || _a === void 0 ? void 0 : _a.forEach((source) => {
6655
- let properties = undefined;
6656
- if (Array.isArray(source.properties)) {
6657
- properties = {};
6658
- source.properties.forEach((prop) => (properties[prop.name] = prop.value));
6659
- }
6660
- metadata.fields.push(Object.assign(Object.assign({}, source), { properties }));
6661
- });
6662
- resolve(metadata);
6663
- })
6664
- .catch((error) => {
6665
- reject(error);
6666
- });
6667
- });
6668
- }
6669
- loadData(dataUnit, sort, filters) {
6670
- return new Promise((resolve, reject) => {
6671
- HttpFetcher.get()
6672
- .callGraphQL({
6673
- values: { dataunit: dataUnit.name, sort, filters },
6674
- query: this.templateByQuery.get("fetchData"),
6675
- })
6676
- .then((resp) => {
6677
- const result = resp.data;
6678
- const dataUnitRecords = [];
6679
- result.records.forEach((responseRecord) => {
6680
- const duRecord = { __record__id__: responseRecord.id };
6681
- responseRecord.fields.forEach(({ name, value }) => {
6682
- duRecord[name] = dataUnit.valueFromString(name, value);
6683
- });
6684
- dataUnitRecords.push(duRecord);
6685
- });
6686
- resolve(dataUnitRecords);
6687
- })
6688
- .catch((error) => {
6689
- reject(error);
6690
- });
6691
- });
6692
- }
6693
- saveData(dataUnit, duChanges) {
6694
- const changes = duChanges.map((change) => {
6695
- const { dataUnit: changeDU, record, updatingFields, operation } = change;
6696
- const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6697
- return { fieldName, value: this.formatValueToServer(value) };
6698
- });
6699
- return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6700
- });
6701
- return new Promise((resolve, reject) => {
6702
- HttpFetcher.get()
6703
- .callGraphQL({
6704
- values: { changes: changes },
6705
- query: this.templateByQuery.get("saveData"),
6706
- })
6707
- .then((resp) => {
6708
- const dataUnitRecords = [];
6709
- resp === null || resp === void 0 ? void 0 : resp.forEach((responseRecord) => {
6710
- const duRecord = { __record__id__: responseRecord.id };
6711
- if (responseRecord.oldId) {
6712
- duRecord.__old__id__ = responseRecord.oldId;
6713
- }
6714
- responseRecord.fields.forEach(({ name, value }) => {
6715
- duRecord[name] = dataUnit.valueFromString(name, value);
6716
- });
6717
- dataUnitRecords.push(duRecord);
6718
- });
6719
- resolve(dataUnitRecords);
6720
- })
6721
- .catch((error) => {
6722
- reject(error);
6723
- });
6724
- });
6725
- }
6726
- formatValueToServer(value) {
6727
- if (value === undefined)
6728
- return value;
6729
- try {
6730
- if (value instanceof Date) {
6731
- return value.toString();
6732
- }
6733
- //Any others objects
6734
- value = JSON.stringify(value);
6735
- }
6736
- catch (_a) {
6737
- value = value.toString();
6738
- }
6739
- return value;
6740
- }
6741
- removeRecords(dataUnit, recordIds) {
6742
- const changes = recordIds.map((recordId) => {
6743
- return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
6744
- });
6745
- return new Promise((resolve, reject) => {
6746
- HttpFetcher.get()
6747
- .callGraphQL({
6748
- values: { changes: changes },
6749
- query: this.templateByQuery.get("saveData"),
6750
- })
6751
- .then((_resp) => {
6752
- resolve(recordIds);
6753
- })
6754
- .catch((error) => {
6755
- reject(error);
6756
- });
6757
- });
6758
- }
6590
+ class DataUnitFetcher {
6591
+ constructor() {
6592
+ this.templateByQuery = new Map();
6593
+ this.buldTemplates();
6594
+ }
6595
+ buldTemplates() {
6596
+ this.templateByQuery.set("fetchDataUnit", dist.gql `query($name: String!) {
6597
+ $queryAlias$: fetchDataUnit(name: $name){
6598
+ name
6599
+ fields{
6600
+ name
6601
+ defaultValue
6602
+ label
6603
+ readOnly
6604
+ required
6605
+ dataType
6606
+ userInterface
6607
+ properties{
6608
+ name
6609
+ value
6610
+ }
6611
+ dependencies{
6612
+ masterFields
6613
+ type
6614
+ expression
6615
+ }
6616
+ }
6617
+ }
6618
+ }`);
6619
+ this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $first: Int $offset:Int $filter: [Filter!] $sort: [Sort!]) {
6620
+ $queryAlias$: fetchDataUnit(name: $dataunit){
6621
+ data(first: $first offset: $offset filters: $filter sort: $sort){
6622
+ first
6623
+ offset
6624
+ total
6625
+ hasMore
6626
+ records{
6627
+ id
6628
+ fields {
6629
+ name
6630
+ value
6631
+ }
6632
+ }
6633
+ }
6634
+ }
6635
+ }`);
6636
+ this.templateByQuery.set("saveData", dist.gql `mutation($changes: [Change!]!) {
6637
+ $queryAlias$: saveDataUnitChanges(changes: $changes){
6638
+ oldId
6639
+ id
6640
+ fields {
6641
+ name
6642
+ value
6643
+ }
6644
+ }
6645
+ }`);
6646
+ }
6647
+ getDataUnit(entityName, resourceID) {
6648
+ const dataUnit = new DataUnit(`dd://${entityName}/${resourceID}`);
6649
+ dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
6650
+ dataUnit.dataLoader = (dataUnit, sort, filters) => this.loadData(dataUnit, sort, filters);
6651
+ dataUnit.saveLoader = (dataUnit, changes) => this.saveData(dataUnit, changes);
6652
+ dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
6653
+ return dataUnit;
6654
+ }
6655
+ loadMetadata(dataUnit) {
6656
+ return new Promise((resolve, reject) => {
6657
+ HttpFetcher.get()
6658
+ .callGraphQL({
6659
+ values: { name: dataUnit.name },
6660
+ query: this.templateByQuery.get("fetchDataUnit"),
6661
+ })
6662
+ .then((resp) => {
6663
+ var _a;
6664
+ const metadata = {
6665
+ name: resp.name,
6666
+ label: resp.name,
6667
+ fields: [],
6668
+ };
6669
+ (_a = resp.fields) === null || _a === void 0 ? void 0 : _a.forEach((source) => {
6670
+ let properties = undefined;
6671
+ if (Array.isArray(source.properties)) {
6672
+ properties = {};
6673
+ source.properties.forEach((prop) => (properties[prop.name] = prop.value));
6674
+ }
6675
+ metadata.fields.push(Object.assign(Object.assign({}, source), { properties }));
6676
+ });
6677
+ resolve(metadata);
6678
+ })
6679
+ .catch((error) => {
6680
+ reject(error);
6681
+ });
6682
+ });
6683
+ }
6684
+ loadData(dataUnit, sort, filters) {
6685
+ return new Promise((resolve, reject) => {
6686
+ HttpFetcher.get()
6687
+ .callGraphQL({
6688
+ values: { dataunit: dataUnit.name, sort, filters },
6689
+ query: this.templateByQuery.get("fetchData"),
6690
+ })
6691
+ .then((resp) => {
6692
+ const result = resp.data;
6693
+ const dataUnitRecords = [];
6694
+ result.records.forEach((responseRecord) => {
6695
+ const duRecord = { __record__id__: responseRecord.id };
6696
+ responseRecord.fields.forEach(({ name, value }) => {
6697
+ duRecord[name] = dataUnit.valueFromString(name, value);
6698
+ });
6699
+ dataUnitRecords.push(duRecord);
6700
+ });
6701
+ resolve(dataUnitRecords);
6702
+ })
6703
+ .catch((error) => {
6704
+ reject(error);
6705
+ });
6706
+ });
6707
+ }
6708
+ saveData(dataUnit, duChanges) {
6709
+ const changes = duChanges.map((change) => {
6710
+ const { dataUnit: changeDU, record, updatingFields, operation } = change;
6711
+ const parsedUpdatingFields = Object.entries(updatingFields).map(([fieldName, value]) => {
6712
+ return { fieldName, value: this.formatValueToServer(value) };
6713
+ });
6714
+ return { dataUnit: changeDU, updatingFields: parsedUpdatingFields, operation, recordId: record.__record__id__ };
6715
+ });
6716
+ return new Promise((resolve, reject) => {
6717
+ HttpFetcher.get()
6718
+ .callGraphQL({
6719
+ values: { changes: changes },
6720
+ query: this.templateByQuery.get("saveData"),
6721
+ })
6722
+ .then((resp) => {
6723
+ const dataUnitRecords = [];
6724
+ resp === null || resp === void 0 ? void 0 : resp.forEach((responseRecord) => {
6725
+ const duRecord = { __record__id__: responseRecord.id };
6726
+ if (responseRecord.oldId) {
6727
+ duRecord.__old__id__ = responseRecord.oldId;
6728
+ }
6729
+ responseRecord.fields.forEach(({ name, value }) => {
6730
+ duRecord[name] = dataUnit.valueFromString(name, value);
6731
+ });
6732
+ dataUnitRecords.push(duRecord);
6733
+ });
6734
+ resolve(dataUnitRecords);
6735
+ })
6736
+ .catch((error) => {
6737
+ reject(error);
6738
+ });
6739
+ });
6740
+ }
6741
+ formatValueToServer(value) {
6742
+ if (value === undefined)
6743
+ return value;
6744
+ try {
6745
+ if (value instanceof Date) {
6746
+ return value.toString();
6747
+ }
6748
+ //Any others objects
6749
+ value = JSON.stringify(value);
6750
+ }
6751
+ catch (_a) {
6752
+ value = value.toString();
6753
+ }
6754
+ return value;
6755
+ }
6756
+ removeRecords(dataUnit, recordIds) {
6757
+ const changes = recordIds.map((recordId) => {
6758
+ return { dataUnit: dataUnit.name, operation: ChangeOperation.DELETE, recordId };
6759
+ });
6760
+ return new Promise((resolve, reject) => {
6761
+ HttpFetcher.get()
6762
+ .callGraphQL({
6763
+ values: { changes: changes },
6764
+ query: this.templateByQuery.get("saveData"),
6765
+ })
6766
+ .then((_resp) => {
6767
+ resolve(recordIds);
6768
+ })
6769
+ .catch((error) => {
6770
+ reject(error);
6771
+ });
6772
+ });
6773
+ }
6759
6774
  }
6760
6775
 
6761
- class UrlUtils {
6762
- static getQueryParams(queryString) {
6763
- const params = new Map();
6764
- const re = /[?&]?([^=]+)=([^&]*)/g;
6765
- let tokens;
6766
- //Necessário por causa da tela Histórico Padrão que possui resourceID com acento
6767
- queryString = window.unescape(queryString);
6768
- queryString = queryString.split("+").join(" ");
6769
- while ((tokens = re.exec(queryString))) {
6770
- params.set(window.decodeURIComponent(tokens[1]), tokens[2]);
6771
- }
6772
- //Inserimos a urlBase no params.
6773
- params.set("urlBase", this.getUrlBase());
6774
- if (window["moduleID"] && window["URIServiceBroker"]) {
6775
- params.set("moduleID", window["moduleID"]);
6776
- params.set("URIServiceBroker", window["URIServiceBroker"]);
6777
- }
6778
- return params;
6779
- }
6780
- static getUrlBase() {
6781
- return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6782
- }
6776
+ class UrlUtils {
6777
+ static getQueryParams(queryString) {
6778
+ const params = new Map();
6779
+ const re = /[?&]?([^=]+)=([^&]*)/g;
6780
+ let tokens;
6781
+ //Necessário por causa da tela Histórico Padrão que possui resourceID com acento
6782
+ queryString = window.unescape(queryString);
6783
+ queryString = queryString.split("+").join(" ");
6784
+ while ((tokens = re.exec(queryString))) {
6785
+ params.set(window.decodeURIComponent(tokens[1]), tokens[2]);
6786
+ }
6787
+ //Inserimos a urlBase no params.
6788
+ params.set("urlBase", this.getUrlBase());
6789
+ if (window["moduleID"] && window["URIServiceBroker"]) {
6790
+ params.set("moduleID", window["moduleID"]);
6791
+ params.set("URIServiceBroker", window["URIServiceBroker"]);
6792
+ }
6793
+ return params;
6794
+ }
6795
+ static getUrlBase() {
6796
+ return `${location.protocol}"//"${location.hostname}${location.port ? ":" + location.port : ""}`;
6797
+ }
6783
6798
  }
6784
6799
 
6785
- class Workspace {
6786
- static openAppActivity(resourceId, pkObject) {
6787
- var _a;
6788
- (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
6789
- }
6790
- }
6800
+ class Workspace {
6801
+ static openAppActivity(resourceId, pkObject) {
6802
+ var _a;
6803
+ (_a = window["workspace"]) === null || _a === void 0 ? void 0 : _a.openAppActivity(resourceId, pkObject);
6804
+ }
6805
+ }
6791
6806
  Workspace.resourceID = window["workspace"].resourceID;
6792
6807
 
6793
- class ParametersFetcher {
6794
- constructor() {
6795
- this.templateByQuery = new Map();
6796
- this.buldTemplates();
6797
- }
6798
- buldTemplates() {
6799
- this.templateByQuery.set("fetchParam", dist.gql `query($name: String!) {
6800
- $queryAlias$: fetchResource(name: $name){
6801
- name
6802
- resource
6803
- }
6804
- }`);
6805
- }
6806
- async getParam(name, resourceID) {
6807
- const completPath = `param://${resourceID}?params=${window.btoa(name)}`;
6808
- return HttpFetcher.get().callGraphQL({
6809
- values: { name: completPath },
6810
- query: this.templateByQuery.get("fetchParam"),
6811
- });
6812
- }
6813
- async asString(name, resourceID) {
6814
- const paramArr = await this.getParam(name, resourceID);
6815
- return this.getValue(paramArr);
6816
- }
6817
- async asInteger(name, resourceID) {
6818
- const paramArr = await this.getParam(name, resourceID);
6819
- return parseInt(this.getValue(paramArr));
6820
- }
6821
- async asFloat(name, resourceID) {
6822
- const paramArr = await this.getParam(name, resourceID);
6823
- return parseFloat(this.getValue(paramArr));
6824
- }
6825
- async asBoolean(name, resourceID) {
6826
- const paramArr = await this.getParam(name, resourceID);
6827
- return this.getValue(paramArr) == "S";
6828
- }
6829
- async asDate(name, resourceID) {
6830
- const paramArr = await this.getParam(name, resourceID);
6831
- return DateUtils.strToDate(this.getValue(paramArr));
6832
- }
6833
- async getBatchParams(names, resourceID) {
6834
- const paramArr = await this.getParam(names.join(","), resourceID);
6835
- //TODO: try to typed params val?
6836
- const response = {};
6837
- paramArr.forEach((param) => (response[param.name] = param.resource));
6838
- return response;
6839
- }
6840
- getValue(obj = {}) {
6841
- if (Array.isArray(obj) && obj.length > 0) {
6842
- obj = obj[0];
6843
- }
6844
- if (StringUtils.isEmpty(obj.resource))
6845
- return "";
6846
- return obj.resource;
6847
- }
6808
+ class ParametersFetcher {
6809
+ constructor() {
6810
+ this.templateByQuery = new Map();
6811
+ this.buldTemplates();
6812
+ }
6813
+ buldTemplates() {
6814
+ this.templateByQuery.set("fetchParam", dist.gql `query($name: String!) {
6815
+ $queryAlias$: fetchResource(name: $name){
6816
+ name
6817
+ resource
6818
+ }
6819
+ }`);
6820
+ }
6821
+ async getParam(name, resourceID) {
6822
+ const completPath = `param://${resourceID}?params=${window.btoa(name)}`;
6823
+ return HttpFetcher.get().callGraphQL({
6824
+ values: { name: completPath },
6825
+ query: this.templateByQuery.get("fetchParam"),
6826
+ });
6827
+ }
6828
+ async asString(name, resourceID) {
6829
+ const paramArr = await this.getParam(name, resourceID);
6830
+ return this.getValue(paramArr);
6831
+ }
6832
+ async asInteger(name, resourceID) {
6833
+ const paramArr = await this.getParam(name, resourceID);
6834
+ return parseInt(this.getValue(paramArr));
6835
+ }
6836
+ async asFloat(name, resourceID) {
6837
+ const paramArr = await this.getParam(name, resourceID);
6838
+ return parseFloat(this.getValue(paramArr));
6839
+ }
6840
+ async asBoolean(name, resourceID) {
6841
+ const paramArr = await this.getParam(name, resourceID);
6842
+ return this.getValue(paramArr) == "S";
6843
+ }
6844
+ async asDate(name, resourceID) {
6845
+ const paramArr = await this.getParam(name, resourceID);
6846
+ return DateUtils.strToDate(this.getValue(paramArr));
6847
+ }
6848
+ async getBatchParams(names, resourceID) {
6849
+ const paramArr = await this.getParam(names.join(","), resourceID);
6850
+ //TODO: try to typed params val?
6851
+ const response = {};
6852
+ paramArr.forEach((param) => (response[param.name] = param.resource));
6853
+ return response;
6854
+ }
6855
+ getValue(obj = {}) {
6856
+ if (Array.isArray(obj) && obj.length > 0) {
6857
+ obj = obj[0];
6858
+ }
6859
+ if (StringUtils.isEmpty(obj.resource))
6860
+ return "";
6861
+ return obj.resource;
6862
+ }
6848
6863
  }
6849
6864
 
6850
- class ResourceFetcher {
6851
- constructor() {
6852
- this.templateByQuery = new Map();
6853
- this.buldTemplates();
6854
- }
6855
- buldTemplates() {
6856
- this.templateByQuery.set("fetchResource", dist.gql `query($name: String!) {
6857
- $queryAlias$: fetchResource(name: $name){
6858
- resource
6859
- }
6860
- }`);
6861
- }
6862
- loadResource(name) {
6863
- return new Promise((resolve, reject) => {
6864
- HttpFetcher.get()
6865
- .callGraphQL({
6866
- values: { name },
6867
- query: this.templateByQuery.get("fetchResource"),
6868
- })
6869
- .then((result) => {
6870
- resolve(result === null || result === void 0 ? void 0 : result.resource);
6871
- })
6872
- .catch((error) => {
6873
- reject(error);
6874
- });
6875
- });
6876
- }
6865
+ class ResourceFetcher {
6866
+ constructor() {
6867
+ this.templateByQuery = new Map();
6868
+ this.buldTemplates();
6869
+ }
6870
+ buldTemplates() {
6871
+ this.templateByQuery.set("fetchResource", dist.gql `query($name: String!) {
6872
+ $queryAlias$: fetchResource(name: $name){
6873
+ resource
6874
+ }
6875
+ }`);
6876
+ }
6877
+ loadResource(name) {
6878
+ return new Promise((resolve, reject) => {
6879
+ HttpFetcher.get()
6880
+ .callGraphQL({
6881
+ values: { name },
6882
+ query: this.templateByQuery.get("fetchResource"),
6883
+ })
6884
+ .then((result) => {
6885
+ resolve(result === null || result === void 0 ? void 0 : result.resource);
6886
+ })
6887
+ .catch((error) => {
6888
+ reject(error);
6889
+ });
6890
+ });
6891
+ }
6877
6892
  }
6878
6893
 
6879
- class FormConfigFetcher extends ResourceFetcher {
6880
- loadFormConfig(formName, resourceID) {
6881
- return new Promise((accept, reject) => {
6882
- this.loadResource(`cfg://form/${resourceID}/${formName}`)
6883
- .then((configAsString) => {
6884
- if (configAsString) {
6885
- const config = JSON.parse(configAsString);
6886
- const { tabs, fields } = config;
6887
- if (tabs) {
6888
- const allTabs = new Map(tabs.map(t => [t.label, t]));
6889
- fields.forEach(f => f.tab = allTabs.get(f.tab));
6890
- }
6891
- accept(fields);
6892
- }
6893
- else {
6894
- reject(`Sem configuração pro formulário "${formName}".`);
6895
- }
6896
- })
6897
- .catch((error) => {
6898
- reject(error);
6899
- });
6900
- });
6901
- }
6894
+ class FormConfigFetcher extends ResourceFetcher {
6895
+ loadFormConfig(formName, resourceID) {
6896
+ return new Promise((accept, reject) => {
6897
+ this.loadResource(`cfg://form/${resourceID}/${formName}`)
6898
+ .then((configAsString) => {
6899
+ if (configAsString) {
6900
+ const config = JSON.parse(configAsString);
6901
+ const { tabs, fields } = config;
6902
+ if (tabs) {
6903
+ const allTabs = new Map(tabs.map(t => [t.label, t]));
6904
+ fields.forEach(f => f.tab = allTabs.get(f.tab));
6905
+ }
6906
+ accept(fields);
6907
+ }
6908
+ else {
6909
+ reject(`Sem configuração pro formulário "${formName}".`);
6910
+ }
6911
+ })
6912
+ .catch((error) => {
6913
+ reject(error);
6914
+ });
6915
+ });
6916
+ }
6902
6917
  }
6903
6918
 
6904
- const mockByEntity = {
6905
- "ImplantacaoSaldoConta": [{ "value": 6, "label": "Conta Financeiro" }, { "value": 7, "label": "Conta Banco do Brasil" }],
6906
- "HistoricoBancario": [{ "value": 9, "label": "Lanç. Origem" }, { "value": 8, "label": "Lanç. Origem 2" }],
6907
- "ContaDestino": [{ "value": 10, "label": "Conta BB" }, { "value": 7, "label": "Conta Santander" }],
6908
- "HistoricoBancarioDestino": [{ "value": 11, "label": "Contra Bradesco" }, { "value": 13, "label": "Contra Destino" }],
6909
- "Usuario": [{ "value": 0, "label": "SUP" }],
6910
- "ContaBancaria": [{ "value": 10, "label": "Conta 10" }, { "value": 17, "label": "Conta 17" }],
6911
- "TipoOperacao": [{ "value": 4, "label": "Entrada NFse" }, { "value": 5, "label": "Outra top" }, { "value": 6, "label": "Top 6" }]
6912
- };
6913
- const pesquisaLoadOptions = (searchArgument, fieldName, dataUnit) => {
6914
- var _a;
6915
- console.log(searchArgument);
6916
- const field = dataUnit.getField(fieldName);
6917
- const entityName = (_a = field.properties) === null || _a === void 0 ? void 0 : _a.ENTITYNAME;
6918
- return (mockByEntity[entityName] || []);
6919
+ const mockByEntity = {
6920
+ "ImplantacaoSaldoConta": [{ "value": 6, "label": "Conta Financeiro" }, { "value": 7, "label": "Conta Banco do Brasil" }],
6921
+ "HistoricoBancario": [{ "value": 9, "label": "Lanç. Origem" }, { "value": 8, "label": "Lanç. Origem 2" }],
6922
+ "ContaDestino": [{ "value": 10, "label": "Conta BB" }, { "value": 7, "label": "Conta Santander" }],
6923
+ "HistoricoBancarioDestino": [{ "value": 11, "label": "Contra Bradesco" }, { "value": 13, "label": "Contra Destino" }],
6924
+ "Usuario": [{ "value": 0, "label": "SUP" }],
6925
+ "ContaBancaria": [{ "value": 10, "label": "Conta 10" }, { "value": 17, "label": "Conta 17" }],
6926
+ "TipoOperacao": [{ "value": 4, "label": "Entrada NFse" }, { "value": 5, "label": "Outra top" }, { "value": 6, "label": "Top 6" }]
6927
+ };
6928
+ const pesquisaLoadOptions = (searchArgument, fieldName, dataUnit) => {
6929
+ var _a;
6930
+ console.log(searchArgument);
6931
+ const field = dataUnit.getField(fieldName);
6932
+ const entityName = (_a = field.properties) === null || _a === void 0 ? void 0 : _a.ENTITYNAME;
6933
+ return (mockByEntity[entityName] || []);
6919
6934
  };
6920
6935
 
6921
6936
  const snkApplicationCss = ".sc-snk-application-h{display:flex;flex-direction:column;height:100%}";
6922
6937
 
6923
- const SnkApplication$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
6924
- constructor() {
6925
- super();
6926
- this.__registerHost();
6927
- this.applicationLoaded = createEvent(this, "applicationLoaded", 7);
6928
- this.applicationLoading = createEvent(this, "applicationLoading", 7);
6929
- }
6930
- get parameters() {
6931
- if (!this._parameters) {
6932
- this._parameters = new ParametersFetcher();
6933
- }
6934
- return this._parameters;
6935
- }
6936
- get resourceID() {
6937
- if (!this._resourceID) {
6938
- this._resourceID = this.urlParams.get("workspaceResourceID") ||
6939
- this.urlParams.get("resourceID") ||
6940
- Workspace.resourceID ||
6941
- "unknown.resource.id";
6942
- }
6943
- return this._resourceID;
6944
- }
6945
- async getStringParam(name) {
6946
- return this.parameters.asString(name, this.resourceID);
6947
- }
6948
- async getIntParam(name) {
6949
- return this.parameters.asInteger(name, this.resourceID);
6950
- }
6951
- async getFloatParam(name) {
6952
- return this.parameters.asFloat(name, this.resourceID);
6953
- }
6954
- async getBooleanParam(name) {
6955
- return this.parameters.asBoolean(name, this.resourceID);
6956
- }
6957
- async getDateParam(name) {
6958
- return this.parameters.asDate(name, this.resourceID);
6959
- }
6960
- async temOpcional(opcional) {
6961
- const opts = opcional.split(",");
6962
- return new Promise((resolve, reject) => {
6963
- this.getAttributeFromHTMLWrapper("opc0009")
6964
- .then(value => {
6965
- if (value === "1") {
6966
- resolve(true);
6967
- }
6968
- else {
6969
- Promise.all(opts.map(opt => this.getAttributeFromHTMLWrapper("opc" + opt)))
6970
- .then(result => {
6971
- resolve(result.includes("1"));
6972
- })
6973
- .catch(error => {
6974
- reject(error);
6975
- });
6976
- }
6977
- })
6978
- .catch(error => {
6979
- reject(error);
6980
- });
6981
- });
6982
- }
6983
- async getAttributeFromHTMLWrapper(attribName) {
6984
- return Promise.resolve(window[attribName]);
6985
- }
6986
- async openApp(resourceId, pkObject) {
6987
- Workspace.openAppActivity(resourceId, pkObject);
6988
- }
6989
- async createDataunit(entityName) {
6990
- return new Promise(resolve => {
6991
- const dataUnit = this.dataUnitFetcher.getDataUnit(entityName, this.resourceID);
6992
- dataUnit.loadMetadata();
6993
- resolve(dataUnit);
6994
- });
6995
- }
6996
- async getResourceID() {
6997
- return Promise.resolve(this.resourceID);
6998
- }
6999
- async alert(title, message, icon) {
7000
- return ApplicationUtils.alert(title, message, icon);
7001
- }
7002
- async error(title, message, icon) {
7003
- return ApplicationUtils.error(title, message, icon);
7004
- }
7005
- async confirm(title, message, icon, critical) {
7006
- return ApplicationUtils.confirm(title, message, icon, critical);
7007
- }
7008
- async info(message, options = undefined) {
7009
- return ApplicationUtils.info(message, options);
7010
- }
7011
- async loadFormConfig(name) {
7012
- return this.formConfigFetcher.loadFormConfig(name, this.resourceID);
7013
- }
7014
- get urlParams() {
7015
- if (!this._urlParams) {
7016
- this._urlParams = UrlUtils.getQueryParams(location.search);
7017
- }
7018
- return this._urlParams;
7019
- }
7020
- get dataUnitFetcher() {
7021
- if (!this._dataUnitFetcher) {
7022
- this._dataUnitFetcher = new DataUnitFetcher();
7023
- }
7024
- return this._dataUnitFetcher;
7025
- }
7026
- get formConfigFetcher() {
7027
- if (!this._formConfigFetcher) {
7028
- this._formConfigFetcher = new FormConfigFetcher();
7029
- }
7030
- return this._formConfigFetcher;
7031
- }
7032
- componentWillLoad() {
7033
- ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
7034
- }
7035
- componentDidLoad() {
7036
- this.applicationLoading.emit(true);
7037
- window.requestAnimationFrame(() => {
7038
- this.applicationLoaded.emit(true);
7039
- });
7040
- }
7041
- render() {
7042
- return (h("div", null));
7043
- }
7044
- static get style() { return snkApplicationCss; }
7045
- }, [2, "snk-application", {
7046
- "getStringParam": [64],
7047
- "getIntParam": [64],
7048
- "getFloatParam": [64],
7049
- "getBooleanParam": [64],
7050
- "getDateParam": [64],
7051
- "temOpcional": [64],
7052
- "getAttributeFromHTMLWrapper": [64],
7053
- "openApp": [64],
7054
- "createDataunit": [64],
7055
- "getResourceID": [64],
7056
- "alert": [64],
7057
- "error": [64],
7058
- "confirm": [64],
7059
- "info": [64],
7060
- "loadFormConfig": [64]
7061
- }]);
7062
- function defineCustomElement$1() {
7063
- if (typeof customElements === "undefined") {
7064
- return;
7065
- }
7066
- const components = ["snk-application"];
7067
- components.forEach(tagName => { switch (tagName) {
7068
- case "snk-application":
7069
- if (!customElements.get(tagName)) {
7070
- customElements.define(tagName, SnkApplication$1);
7071
- }
7072
- break;
7073
- } });
6938
+ const SnkApplication$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
6939
+ constructor() {
6940
+ super();
6941
+ this.__registerHost();
6942
+ this.applicationLoaded = createEvent(this, "applicationLoaded", 7);
6943
+ this.applicationLoading = createEvent(this, "applicationLoading", 7);
6944
+ }
6945
+ get parameters() {
6946
+ if (!this._parameters) {
6947
+ this._parameters = new ParametersFetcher();
6948
+ }
6949
+ return this._parameters;
6950
+ }
6951
+ get resourceID() {
6952
+ if (!this._resourceID) {
6953
+ this._resourceID = this.urlParams.get("workspaceResourceID") ||
6954
+ this.urlParams.get("resourceID") ||
6955
+ Workspace.resourceID ||
6956
+ "unknown.resource.id";
6957
+ }
6958
+ return this._resourceID;
6959
+ }
6960
+ async getStringParam(name) {
6961
+ return this.parameters.asString(name, this.resourceID);
6962
+ }
6963
+ async getIntParam(name) {
6964
+ return this.parameters.asInteger(name, this.resourceID);
6965
+ }
6966
+ async getFloatParam(name) {
6967
+ return this.parameters.asFloat(name, this.resourceID);
6968
+ }
6969
+ async getBooleanParam(name) {
6970
+ return this.parameters.asBoolean(name, this.resourceID);
6971
+ }
6972
+ async getDateParam(name) {
6973
+ return this.parameters.asDate(name, this.resourceID);
6974
+ }
6975
+ async temOpcional(opcional) {
6976
+ const opts = opcional.split(",");
6977
+ return new Promise((resolve, reject) => {
6978
+ this.getAttributeFromHTMLWrapper("opc0009")
6979
+ .then(value => {
6980
+ if (value === "1") {
6981
+ resolve(true);
6982
+ }
6983
+ else {
6984
+ Promise.all(opts.map(opt => this.getAttributeFromHTMLWrapper("opc" + opt)))
6985
+ .then(result => {
6986
+ resolve(result.includes("1"));
6987
+ })
6988
+ .catch(error => {
6989
+ reject(error);
6990
+ });
6991
+ }
6992
+ })
6993
+ .catch(error => {
6994
+ reject(error);
6995
+ });
6996
+ });
6997
+ }
6998
+ async getAttributeFromHTMLWrapper(attribName) {
6999
+ return Promise.resolve(window[attribName]);
7000
+ }
7001
+ async openApp(resourceId, pkObject) {
7002
+ Workspace.openAppActivity(resourceId, pkObject);
7003
+ }
7004
+ async createDataunit(entityName) {
7005
+ return new Promise(resolve => {
7006
+ const dataUnit = this.dataUnitFetcher.getDataUnit(entityName, this.resourceID);
7007
+ dataUnit.loadMetadata();
7008
+ resolve(dataUnit);
7009
+ });
7010
+ }
7011
+ async getResourceID() {
7012
+ return Promise.resolve(this.resourceID);
7013
+ }
7014
+ async alert(title, message, icon) {
7015
+ return ApplicationUtils.alert(title, message, icon);
7016
+ }
7017
+ async error(title, message, icon) {
7018
+ return ApplicationUtils.error(title, message, icon);
7019
+ }
7020
+ async confirm(title, message, icon, critical) {
7021
+ return ApplicationUtils.confirm(title, message, icon, critical);
7022
+ }
7023
+ async info(message, options = undefined) {
7024
+ return ApplicationUtils.info(message, options);
7025
+ }
7026
+ async loadFormConfig(name) {
7027
+ return this.formConfigFetcher.loadFormConfig(name, this.resourceID);
7028
+ }
7029
+ get urlParams() {
7030
+ if (!this._urlParams) {
7031
+ this._urlParams = UrlUtils.getQueryParams(location.search);
7032
+ }
7033
+ return this._urlParams;
7034
+ }
7035
+ get dataUnitFetcher() {
7036
+ if (!this._dataUnitFetcher) {
7037
+ this._dataUnitFetcher = new DataUnitFetcher();
7038
+ }
7039
+ return this._dataUnitFetcher;
7040
+ }
7041
+ get formConfigFetcher() {
7042
+ if (!this._formConfigFetcher) {
7043
+ this._formConfigFetcher = new FormConfigFetcher();
7044
+ }
7045
+ return this._formConfigFetcher;
7046
+ }
7047
+ componentWillLoad() {
7048
+ ApplicationContext.setContextValue("__EZUI__SEARCH__OPTION__LOADER__", pesquisaLoadOptions);
7049
+ }
7050
+ componentDidLoad() {
7051
+ this.applicationLoading.emit(true);
7052
+ window.requestAnimationFrame(() => {
7053
+ this.applicationLoaded.emit(true);
7054
+ });
7055
+ }
7056
+ render() {
7057
+ return (h("div", null));
7058
+ }
7059
+ static get style() { return snkApplicationCss; }
7060
+ }, [2, "snk-application", {
7061
+ "getStringParam": [64],
7062
+ "getIntParam": [64],
7063
+ "getFloatParam": [64],
7064
+ "getBooleanParam": [64],
7065
+ "getDateParam": [64],
7066
+ "temOpcional": [64],
7067
+ "getAttributeFromHTMLWrapper": [64],
7068
+ "openApp": [64],
7069
+ "createDataunit": [64],
7070
+ "getResourceID": [64],
7071
+ "alert": [64],
7072
+ "error": [64],
7073
+ "confirm": [64],
7074
+ "info": [64],
7075
+ "loadFormConfig": [64]
7076
+ }]);
7077
+ function defineCustomElement$1() {
7078
+ if (typeof customElements === "undefined") {
7079
+ return;
7080
+ }
7081
+ const components = ["snk-application"];
7082
+ components.forEach(tagName => { switch (tagName) {
7083
+ case "snk-application":
7084
+ if (!customElements.get(tagName)) {
7085
+ customElements.define(tagName, SnkApplication$1);
7086
+ }
7087
+ break;
7088
+ } });
7074
7089
  }
7075
7090
 
7076
7091
  const SnkApplication = SnkApplication$1;