@sankhyalabs/sankhyablocks 1.3.21 → 1.3.22

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 (33) hide show
  1. package/dist/cjs/{index-dcacd71c.js → index-1133bc2a.js} +55 -1
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/sankhyablocks.cjs.js +2 -2
  4. package/dist/cjs/snk-application.cjs.entry.js +106 -13
  5. package/dist/cjs/snk-pesquisa.cjs.entry.js +296 -3
  6. package/dist/cjs/teste-pesquisa.cjs.entry.js +1 -1
  7. package/dist/collection/components/snk-application/snk-application.js +167 -5
  8. package/dist/collection/components/snk-pesquisa/snk-pesquisa.css +92 -1
  9. package/dist/collection/components/snk-pesquisa/snk-pesquisa.js +311 -6
  10. package/dist/collection/lib/http/data-fetcher/fetchers/auth-fetcher.js +29 -0
  11. package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +8 -7
  12. package/dist/components/snk-application2.js +111 -14
  13. package/dist/components/snk-pesquisa2.js +300 -6
  14. package/dist/esm/{index-b13a53d8.js → index-ffda6382.js} +55 -1
  15. package/dist/esm/loader.js +2 -2
  16. package/dist/esm/sankhyablocks.js +2 -2
  17. package/dist/esm/snk-application.entry.js +107 -14
  18. package/dist/esm/snk-pesquisa.entry.js +296 -3
  19. package/dist/esm/teste-pesquisa.entry.js +1 -1
  20. package/dist/sankhyablocks/{p-28a5ef28.entry.js → p-2a7b4cb3.entry.js} +1 -1
  21. package/dist/sankhyablocks/p-a200791b.entry.js +68 -0
  22. package/dist/sankhyablocks/p-d62412bb.entry.js +1 -0
  23. package/dist/sankhyablocks/p-edcb9d8e.js +2 -0
  24. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  25. package/dist/types/components/snk-application/snk-application.d.ts +87 -0
  26. package/dist/types/components/snk-pesquisa/snk-pesquisa.d.ts +44 -2
  27. package/dist/types/components.d.ts +9 -2
  28. package/dist/types/lib/http/data-fetcher/fetchers/auth-fetcher.d.ts +17 -0
  29. package/dist/types/lib/http/data-fetcher/fetchers/pesquisa-fetcher.d.ts +3 -2
  30. package/package.json +2 -2
  31. package/dist/sankhyablocks/p-0b1577eb.entry.js +0 -1
  32. package/dist/sankhyablocks/p-4e116571.js +0 -2
  33. package/dist/sankhyablocks/p-dedc8d7b.entry.js +0 -68
@@ -183,6 +183,19 @@ const h = (nodeName, vnodeData, ...children) => {
183
183
  }
184
184
  };
185
185
  walk(children);
186
+ if (vnodeData) {
187
+ {
188
+ const classData = vnodeData.className || vnodeData.class;
189
+ if (classData) {
190
+ vnodeData.class =
191
+ typeof classData !== 'object'
192
+ ? classData
193
+ : Object.keys(classData)
194
+ .filter((k) => classData[k])
195
+ .join(' ');
196
+ }
197
+ }
198
+ }
186
199
  const vnode = newVNode(nodeName, null);
187
200
  vnode.$attrs$ = vnodeData;
188
201
  if (vNodeChildren.length > 0) {
@@ -217,7 +230,14 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
217
230
  if (oldValue !== newValue) {
218
231
  let isProp = isMemberInElement(elm, memberName);
219
232
  let ln = memberName.toLowerCase();
220
- if (memberName === 'ref') {
233
+ if (memberName === 'class') {
234
+ const classList = elm.classList;
235
+ const oldClasses = parseClassList(oldValue);
236
+ const newClasses = parseClassList(newValue);
237
+ classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
238
+ classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
239
+ }
240
+ else if (memberName === 'ref') {
221
241
  // minifier will clean this up
222
242
  if (newValue) {
223
243
  newValue(elm);
@@ -299,6 +319,8 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
299
319
  }
300
320
  }
301
321
  };
322
+ const parseClassListRegex = /\s/;
323
+ const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
302
324
  const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
303
325
  // if the element passed in is a shadow root, which is a document fragment
304
326
  // then we want to be adding attrs/props to the shadow root's "host" element
@@ -746,6 +768,7 @@ const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propNam
746
768
  const setValue = (ref, propName, newVal, cmpMeta) => {
747
769
  // check our new property value against our internal value
748
770
  const hostRef = getHostRef(ref);
771
+ const elm = hostRef.$hostElement$ ;
749
772
  const oldVal = hostRef.$instanceValues$.get(propName);
750
773
  const flags = hostRef.$flags$;
751
774
  const instance = hostRef.$lazyInstance$ ;
@@ -758,6 +781,22 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
758
781
  // set our new value!
759
782
  hostRef.$instanceValues$.set(propName, newVal);
760
783
  if (instance) {
784
+ // get an array of method names of watch functions to call
785
+ if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
786
+ const watchMethods = cmpMeta.$watchers$[propName];
787
+ if (watchMethods) {
788
+ // this instance is watching for when this property changed
789
+ watchMethods.map((watchMethodName) => {
790
+ try {
791
+ // fire off each of the watch methods that are watching this property
792
+ instance[watchMethodName](newVal, oldVal, propName);
793
+ }
794
+ catch (e) {
795
+ consoleError(e, elm);
796
+ }
797
+ });
798
+ }
799
+ }
761
800
  if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
762
801
  // looks like this value actually changed, so we've got work to do!
763
802
  // but only if we've already rendered, otherwise just chill out
@@ -770,6 +809,9 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
770
809
  };
771
810
  const proxyComponent = (Cstr, cmpMeta, flags) => {
772
811
  if (cmpMeta.$members$) {
812
+ if (Cstr.watchers) {
813
+ cmpMeta.$watchers$ = Cstr.watchers;
814
+ }
773
815
  // It's better to have a const than two Object.entries()
774
816
  const members = Object.entries(cmpMeta.$members$);
775
817
  const prototype = Cstr.prototype;
@@ -884,6 +926,12 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
884
926
  endLoad();
885
927
  }
886
928
  if (!Cstr.isProxied) {
929
+ // we've never proxied this Constructor before
930
+ // let's add the getters/setters to its prototype before
931
+ // the first time we create an instance of the implementation
932
+ {
933
+ cmpMeta.$watchers$ = Cstr.watchers;
934
+ }
887
935
  proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
888
936
  Cstr.isProxied = true;
889
937
  }
@@ -907,6 +955,9 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
907
955
  {
908
956
  hostRef.$flags$ &= ~8 /* isConstructingInstance */;
909
957
  }
958
+ {
959
+ hostRef.$flags$ |= 128 /* isWatchReady */;
960
+ }
910
961
  endNewInstance();
911
962
  fireConnectedCallback(hostRef.$lazyInstance$);
912
963
  }
@@ -1020,6 +1071,9 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
1020
1071
  {
1021
1072
  cmpMeta.$members$ = compactMeta[2];
1022
1073
  }
1074
+ {
1075
+ cmpMeta.$watchers$ = {};
1076
+ }
1023
1077
  const tagName = cmpMeta.$tagName$;
1024
1078
  const HostElement = class extends HTMLElement {
1025
1079
  // StencilLazyHost
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-dcacd71c.js');
5
+ const index = require('./index-1133bc2a.js');
6
6
 
7
7
  /*
8
8
  Stencil Client Patch Esm v2.16.1 | MIT Licensed | https://stenciljs.com
@@ -14,7 +14,7 @@ const patchEsm = () => {
14
14
  const defineCustomElements = (win, options) => {
15
15
  if (typeof window === 'undefined') return Promise.resolve();
16
16
  return patchEsm().then(() => {
17
- return index.bootstrapLazy([["snk-pesquisa.cjs",[[1,"snk-pesquisa",{"searchLoader":[16],"onSelectItem":[16],"argument":[1025]}]]],["snk-application.cjs",[[2,"snk-application",{"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getConfig":[64],"saveConfig":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64],"loadGridConfig":[64],"saveGridConfig":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
17
+ return index.bootstrapLazy([["snk-pesquisa.cjs",[[2,"snk-pesquisa",{"searchLoader":[16],"selectItem":[16],"argument":[1025],"_itemList":[32],"_startLoading":[32]}]]],["snk-application.cjs",[[2,"snk-application",{"isUserSup":[64],"hasAccess":[64],"getAllAccess":[64],"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getConfig":[64],"saveConfig":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64],"loadGridConfig":[64],"saveGridConfig":[64],"executeSearch":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
18
18
  });
19
19
  };
20
20
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const index = require('./index-dcacd71c.js');
3
+ const index = require('./index-1133bc2a.js');
4
4
 
5
5
  /*
6
6
  Stencil Client Patch Browser v2.16.1 | MIT Licensed | https://stenciljs.com
@@ -15,5 +15,5 @@ const patchBrowser = () => {
15
15
  };
16
16
 
17
17
  patchBrowser().then(options => {
18
- return index.bootstrapLazy([["snk-pesquisa.cjs",[[1,"snk-pesquisa",{"searchLoader":[16],"onSelectItem":[16],"argument":[1025]}]]],["snk-application.cjs",[[2,"snk-application",{"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getConfig":[64],"saveConfig":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64],"loadGridConfig":[64],"saveGridConfig":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
18
+ return index.bootstrapLazy([["snk-pesquisa.cjs",[[2,"snk-pesquisa",{"searchLoader":[16],"selectItem":[16],"argument":[1025],"_itemList":[32],"_startLoading":[32]}]]],["snk-application.cjs",[[2,"snk-application",{"isUserSup":[64],"hasAccess":[64],"getAllAccess":[64],"getStringParam":[64],"getIntParam":[64],"getFloatParam":[64],"getBooleanParam":[64],"getDateParam":[64],"showPopUp":[64],"closePopUp":[64],"temOpcional":[64],"getConfig":[64],"saveConfig":[64],"getAttributeFromHTMLWrapper":[64],"openApp":[64],"createDataunit":[64],"getResourceID":[64],"alert":[64],"error":[64],"confirm":[64],"info":[64],"loadFormConfig":[64],"loadGridConfig":[64],"saveGridConfig":[64],"executeSearch":[64]}]]],["teste-pesquisa.cjs",[[1,"teste-pesquisa"]]]], options);
19
19
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-dcacd71c.js');
5
+ const index = require('./index-1133bc2a.js');
6
6
  const core = require('@sankhyalabs/core');
7
7
  const utils = require('@sankhyalabs/ezui/dist/collection/utils');
8
8
  const UnitMetadata = require('@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata');
@@ -7093,11 +7093,12 @@ class GridConfigFetcher extends ResourceFetcher {
7093
7093
 
7094
7094
  class PesquisaFetcher {
7095
7095
  constructor() {
7096
- this.templateByQuery = new Map();
7096
+ this._defaultPageSize = 100;
7097
+ this._templateByQuery = new Map();
7097
7098
  this.buldTemplates();
7098
7099
  }
7099
7100
  buldTemplates() {
7100
- this.templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
7101
+ this._templateByQuery.set("search", dist.gql `query($entityName: String! $argument: String $criteria: InputSearchCriteria $options: InputSearchOptions) {
7101
7102
  $queryAlias$: search(entityName: $entityName argument: $argument criteria: $criteria options: $options){
7102
7103
  value
7103
7104
  label
@@ -7109,7 +7110,7 @@ class PesquisaFetcher {
7109
7110
  DataFetcher.get()
7110
7111
  .callGraphQL({
7111
7112
  values: { argument, entityName, criteria, options },
7112
- query: this.templateByQuery.get("search"),
7113
+ query: this._templateByQuery.get("search"),
7113
7114
  })
7114
7115
  .then((result) => {
7115
7116
  resolve(result);
@@ -7119,7 +7120,7 @@ class PesquisaFetcher {
7119
7120
  });
7120
7121
  });
7121
7122
  }
7122
- loadAdvancedSearch(entityName, argument, criteria) {
7123
+ loadAdvancedSearch(entityName, argument, criteria, searchOptions) {
7123
7124
  const serviceName = "PesquisaSP.getSuggestion";
7124
7125
  const externalCriteria = {
7125
7126
  query: {
@@ -7138,11 +7139,11 @@ class PesquisaFetcher {
7138
7139
  "entityName": entityName,
7139
7140
  "compacted": false,
7140
7141
  "ignoreEntityCriteria": false,
7141
- "limit": "5",
7142
+ "limit": this._defaultPageSize,
7142
7143
  "query": { "$": argument },
7143
7144
  "orderByDesc": false,
7144
- "options": { "showInactives": false },
7145
- "externalCriteria": externalCriteria
7145
+ "externalCriteria": externalCriteria,
7146
+ "localEntityName": searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.rootEntity
7146
7147
  },
7147
7148
  "clientEventList": {
7148
7149
  "clientEvent": []
@@ -7171,6 +7172,36 @@ function convertParamType(dataType) {
7171
7172
  }
7172
7173
  }
7173
7174
 
7175
+ class AuthFetcher extends ResourceFetcher {
7176
+ getData(resourceID) {
7177
+ const completePath = `cfg://auth/${resourceID}`;
7178
+ return new Promise((resolve, reject) => {
7179
+ this.loadResource(completePath)
7180
+ .then((loadedResource) => {
7181
+ let auth = core.ObjectUtils.stringToObject(loadedResource);
7182
+ if (auth && typeof (auth) === 'object') {
7183
+ resolve(auth);
7184
+ }
7185
+ }).catch((error) => {
7186
+ reject(error);
7187
+ });
7188
+ });
7189
+ }
7190
+ }
7191
+ var AutorizationType;
7192
+ (function (AutorizationType) {
7193
+ AutorizationType["INSERT"] = "I";
7194
+ AutorizationType["UPDATE"] = "A";
7195
+ AutorizationType["REMOVE"] = "E";
7196
+ AutorizationType["SHOW"] = "C";
7197
+ AutorizationType["CONFIG"] = "F";
7198
+ AutorizationType["CONFIG_NUMBER"] = "N";
7199
+ AutorizationType["CLONE"] = "D";
7200
+ AutorizationType["CONFIG_GRID"] = "G";
7201
+ })(AutorizationType || (AutorizationType = {}));
7202
+
7203
+ var _0x19bf=['hasOwnProperty','isUserSup','parseFromJSON','authorizationSf','string','parse','item','forEach','putAccess','status','true','isSup','actions'];(function(_0x232776,_0x161588){var _0xf498c3=function(_0x1b72ca){while(--_0x1b72ca){_0x232776['push'](_0x232776['shift']());}};_0xf498c3(++_0x161588);}(_0x19bf,0x1bc));var _0x4ace=function(_0x18a194,_0x20fa62){_0x18a194=_0x18a194-0x0;var _0x4bcfc6=_0x19bf[_0x18a194];return _0x4bcfc6;};class MGEAuthorization{[_0x4ace('0x0')](_0x5da3ee){_0x5da3ee=utxt(_0x5da3ee[_0x4ace('0x1')]);if(typeof _0x5da3ee==_0x4ace('0x2')){_0x5da3ee=JSON[_0x4ace('0x3')](_0x5da3ee);}if(_0x5da3ee==undefined){throw Error('Objeto\x20não\x20pode\x20ser\x20indefinido.');}const _0xa117bd=new MGEAuthorizationData(_0x5da3ee['isSup']==='S');if(Array['isArray'](_0x5da3ee[_0x4ace('0x4')])){_0x5da3ee['item'][_0x4ace('0x5')](_0x1d7ff8=>_0xa117bd[_0x4ace('0x6')](_0x1d7ff8['name'],String(_0x1d7ff8[_0x4ace('0x7')])==_0x4ace('0x8')));}return _0xa117bd;}}class MGEAuthorizationData{constructor(_0x2419ec){this[_0x4ace('0x9')]=_0x2419ec;this[_0x4ace('0xa')]={};}[_0x4ace('0x6')](_0x225382,_0x418c04){this['actions'][_0x225382]=_0x418c04;}['hasAccess'](_0x4f03c9){if(this[_0x4ace('0x9')]){return !![];}let _0x4347e9=!![];if(this['actions'][_0x4ace('0xb')](_0x4f03c9)){_0x4347e9=this['actions'][_0x4f03c9];}return _0x4347e9;}[_0x4ace('0xc')](){return this[_0x4ace('0x9')];}}
7204
+
7174
7205
  class SnkErrorHandler {
7175
7206
  constructor(app) {
7176
7207
  this._app = app;
@@ -7240,6 +7271,54 @@ const SnkApplication = class {
7240
7271
  }
7241
7272
  return this._resourceID;
7242
7273
  }
7274
+ get auth() {
7275
+ return new Promise((resolve, reject) => {
7276
+ if (this._auth) {
7277
+ resolve(this._auth);
7278
+ }
7279
+ else {
7280
+ this.authFetcher.getData(this._resourceID).then((authList) => {
7281
+ this._auth = authList;
7282
+ resolve(authList);
7283
+ }).catch(error => reject(error));
7284
+ }
7285
+ });
7286
+ }
7287
+ async isUserSup() {
7288
+ return new Promise((resolve, reject) => {
7289
+ this.auth.then((authorization) => {
7290
+ this.getAuthList(authorization).then((auths) => {
7291
+ resolve(auths.isSup);
7292
+ }).catch(error => reject(error));
7293
+ });
7294
+ });
7295
+ }
7296
+ async hasAccess(access) {
7297
+ return new Promise((resolve, reject) => {
7298
+ this.auth.then((authorization) => {
7299
+ this.getAuthList(authorization).then((auths) => {
7300
+ resolve(auths.isSup || auths.actions[access]);
7301
+ }).catch(error => reject(error));
7302
+ });
7303
+ });
7304
+ }
7305
+ async getAllAccess() {
7306
+ return new Promise((resolve, reject) => {
7307
+ this.auth.then((authorization) => {
7308
+ this.getAuthList(authorization).then((auths) => {
7309
+ const allAccess = {};
7310
+ allAccess['isSup'] = auths.isSup;
7311
+ Object.entries(AutorizationType).forEach((data) => {
7312
+ allAccess[data[0]] = auths.actions[data[1]] || false;
7313
+ });
7314
+ resolve(allAccess);
7315
+ }).catch(error => reject(error));
7316
+ });
7317
+ });
7318
+ }
7319
+ async getAuthList(_auth) {
7320
+ return await (new MGEAuthorization()).parseFromJSON(_auth);
7321
+ }
7243
7322
  async getStringParam(name) {
7244
7323
  return this.parameters.asString(name, this.resourceID);
7245
7324
  }
@@ -7389,12 +7468,18 @@ const SnkApplication = class {
7389
7468
  }
7390
7469
  return this._pesquisaFetcher;
7391
7470
  }
7392
- executeSearch(searchArgument, fieldName, dataUnit) {
7393
- const descriptor = dataUnit.getField(fieldName);
7471
+ get authFetcher() {
7472
+ if (!this._authFetcher) {
7473
+ this._authFetcher = new AuthFetcher();
7474
+ }
7475
+ return this._authFetcher;
7476
+ }
7477
+ async executeSearch(searchArgument, fieldName, dataUnit) {
7478
+ const descriptor = dataUnit === null || dataUnit === void 0 ? void 0 : dataUnit.getField(fieldName);
7394
7479
  if (!descriptor) ;
7395
7480
  else {
7396
7481
  const { mode, argument } = searchArgument;
7397
- const { ENTITYNAME, CODEFIELD, DESCRIPTIONFIELD, ROOTENTITY } = descriptor.properties;
7482
+ const { ENTITYNAME, CODEFIELD, DESCRIPTIONFIELD, ROOTENTITY, DESCRIPTIONENTITY } = descriptor.properties;
7398
7483
  const dependencies = descriptor.dependencies;
7399
7484
  let criteria;
7400
7485
  const searchOptions = {
@@ -7427,11 +7512,13 @@ const SnkApplication = class {
7427
7512
  return new Promise(accept => {
7428
7513
  const pesquisaContent = document.createElement("snk-pesquisa");
7429
7514
  pesquisaContent.argument = argument;
7430
- pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria);
7431
- pesquisaContent.onSelectItem = (option) => {
7515
+ pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria, searchOptions);
7516
+ pesquisaContent.selectItem = (option) => {
7432
7517
  accept(option);
7518
+ this.cleanPopUpTitle();
7433
7519
  this.closePopUp();
7434
7520
  };
7521
+ this.setPopUpTitle(DESCRIPTIONENTITY);
7435
7522
  this.showPopUp(pesquisaContent);
7436
7523
  });
7437
7524
  }
@@ -7440,6 +7527,12 @@ const SnkApplication = class {
7440
7527
  }
7441
7528
  }
7442
7529
  }
7530
+ cleanPopUpTitle() {
7531
+ this._popUp['ezTitle'] = "";
7532
+ }
7533
+ setPopUpTitle(title) {
7534
+ this._popUp['ezTitle'] = title;
7535
+ }
7443
7536
  componentWillLoad() {
7444
7537
  this._errorHandler = new SnkErrorHandler(this);
7445
7538
  core.ApplicationContext.setContextValue("__EZUI__UPLOAD__ADD__URL__", `${UrlUtils.getUrlBase()}/mge/ez.uploading`);
@@ -2,17 +2,310 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const index = require('./index-dcacd71c.js');
5
+ const index = require('./index-1133bc2a.js');
6
+ const core = require('@sankhyalabs/core');
6
7
 
7
- const snkPesquisaCss = ":host{display:block}";
8
+ const snkPesquisaCss = ".sc-snk-pesquisa-h{--snk-pesquisa--font-size:var(--text--medium, 14px);--snk-pesquisa--font-family:var(--font-pattern, Arial);--snk-pesquisa--font-weight:var(--text-weight--medium, 400);--snk-pesquisa__records--color:var(--text--primary, #626e82);--snk-pesquisa__records--padding-vertical:var(--space--medium, 12px);--snk-pesquisa__content--padding-right:var(--space--small, 6px);--snk-pesquisa__content-scrollbar--background-color:var(--text--primary, #626e82);--snk-pesquisa__content-scrollbar--border-radius:var(--border--radius-medium, 12px);--snk-pesquisa__content-scrollbar--width:var(--space--medium, 12px) display: block;max-height:100%;height:100%;display:flex;flex-direction:column;overflow-y:auto}.snk-pesquisa.sc-snk-pesquisa{display:flex;flex-direction:column;height:100%}.snk-pesquisa__input.sc-snk-pesquisa{display:flex;width:100%;box-sizing:border-box;padding-top:4px;padding-right:4px}.snk-pesquisa__input-close.sc-snk-pesquisa{cursor:pointer}.snk-pesquisa__content.sc-snk-pesquisa{display:flex;flex-direction:column;height:100%;overflow-y:auto;padding-right:var(--snk-pesquisa__content--padding-right)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-track{background-color:#f0f2f5;border-radius:var(--snk-pesquisa__content-scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar-thumb{background-color:var(--snk-pesquisa__content-scrollbar--background-color);border-radius:var(--snk-pesquisa__content-scrollbar--border-radius)}.snk-pesquisa__content.sc-snk-pesquisa::-webkit-scrollbar{background-color:#f0f2f5;width:var(--snk-pesquisa__content-scrollbar--width);max-width:var(--snk-pesquisa__content-scrollbar--width);min-width:var(--snk-pesquisa__content-scrollbar--width)}.snk-pesquisa__records.sc-snk-pesquisa{font-family:var(--snk-pesquisa--font-family);font-weight:var(--snk-pesquisa--font-weight);font-size:var(--snk-pesquisa--font-size);color:var(--snk-pesquisa__records--color);padding-bottom:var(--snk-pesquisa__records--padding-vertical);padding-top:var(--snk-pesquisa__records--padding-vertical)}";
8
9
 
9
10
  const SnkPesquisa = class {
10
11
  constructor(hostRef) {
11
12
  index.registerInstance(this, hostRef);
13
+ this._mdByName = {};
14
+ this._startHighlightTag = "<span class='card-item__highlight'>";
15
+ this._endHighlightTag = "</span>";
16
+ this._specialCharsRegex = /[[.\-\$\+\*,_\&\(\)%\/\\#@!:\|\=\'\"]/gmi;
17
+ this._charsWithAccentuation = "ÁÉÍÓÚ_ÃÕ_ÂÊÎÔÛ_ÀÈÌÒÙ_Ü_Ç_áéíóú_ãõ_âêîôû_àèìòù_ü_ç";
18
+ this._charsWithoutAccentuation = "AEIOU_AO_AEIOU_AEIOU_U_C_aeiou_ao_aeiou_aeiou_u_c";
19
+ this._changeDeboucingTimeout = null;
20
+ this._limitCharsToSearch = 3;
21
+ this._deboucingTime = 450;
22
+ this._startLoading = false;
23
+ }
24
+ observeArgument() {
25
+ if (this._textInput) {
26
+ this._textInput.value = this.argument;
27
+ }
28
+ }
29
+ clearSearch() {
30
+ this.argument = "";
31
+ this._itemList = undefined;
32
+ }
33
+ buildDetails(fields, item) {
34
+ let details = {};
35
+ for (let index = 0; (index < fields.length); index++) {
36
+ const field = fields[index];
37
+ const itemValue = item[field.fieldName];
38
+ const optionValue = field.options ? field.options[itemValue] || itemValue : itemValue;
39
+ details[field.description] = this.highlightValue(item['__matchFields'], optionValue, fields, true);
40
+ }
41
+ return details;
42
+ }
43
+ buildFirstFields(matchFields, fields, qtyFields = 6) {
44
+ if (matchFields && Array.isArray(matchFields)) {
45
+ matchFields.forEach((matchField) => {
46
+ let fieldMD = this.removeReference(fields, this._mdByName[matchField]);
47
+ if (fieldMD) {
48
+ fields.unshift(fieldMD);
49
+ }
50
+ });
51
+ }
52
+ fields = fields.slice(0, qtyFields);
53
+ return fields;
54
+ }
55
+ doSearch(argument) {
56
+ if (this.searchLoader && typeof this.searchLoader === "function") {
57
+ this._startLoading = true;
58
+ this.searchLoader(argument)
59
+ .then((resp) => {
60
+ this._startLoading = false;
61
+ if (resp) {
62
+ resp = core.ObjectUtils.stringToObject(resp.json.$);
63
+ let descriptionField = resp.descriptionField;
64
+ let pkField = resp.pkField;
65
+ if (descriptionField && pkField) {
66
+ let newItemList = [];
67
+ resp.data.forEach((item) => {
68
+ var _a;
69
+ let fieldsMetadata = this.filterFieldsMetadata(resp, item);
70
+ let fields = this.buildFirstFields(item['__matchFields'], fieldsMetadata);
71
+ let exibitionItem = {
72
+ key: this.highlightValue(item['__matchFields'], (_a = item[pkField]) === null || _a === void 0 ? void 0 : _a.toString(), fields, true),
73
+ title: this.highlightValue(item['__matchFields'], item[descriptionField], fields, true),
74
+ details: this.buildDetails(fields, item)
75
+ };
76
+ newItemList.push(exibitionItem);
77
+ });
78
+ this._itemList = newItemList;
79
+ }
80
+ }
81
+ }).catch((error) => {
82
+ this._startLoading = false;
83
+ this._itemList = [];
84
+ console.warn(error);
85
+ });
86
+ }
87
+ }
88
+ filterFieldsMetadata(resp, item) {
89
+ let fieldsMetadata = resp.fieldsMetadata.filter((field) => {
90
+ let accept = !core.StringUtils.isEmpty(item[field.fieldName]) &&
91
+ field.visible !== false &&
92
+ field.type !== 'B' &&
93
+ resp.pkField !== field.fieldName &&
94
+ resp.descriptionField !== field.fieldName &&
95
+ (field.isPrimaryKey || !field.isLinkField) &&
96
+ !(field.type === 'S' && field.presentationType === 'H');
97
+ if (accept) {
98
+ this._mdByName[field.fieldName] = field;
99
+ }
100
+ //Condição que trata o problema de trazer imagem no entityCard na pesquisa de registros
101
+ if (typeof item[field.fieldName] === 'string' && (item[field.fieldName].indexOf('<img') > -1 || item[field.fieldName].indexOf('<svg') > -1)) {
102
+ return false;
103
+ }
104
+ return accept;
105
+ });
106
+ return fieldsMetadata;
107
+ }
108
+ removeAtIndex(array, index) {
109
+ if (index >= 0 && index < array.length) {
110
+ return array.splice(index, 1)[0];
111
+ }
112
+ }
113
+ removeReference(array, obj) {
114
+ let index = this.indexOf(array, obj);
115
+ return this.removeAtIndex(array, index);
116
+ }
117
+ indexOf(arr, obj) {
118
+ let index = -1;
119
+ if (Array.isArray(arr)) {
120
+ this.find(arr, (item, i) => {
121
+ index = i;
122
+ return this.equals(obj, item);
123
+ });
124
+ }
125
+ return index;
126
+ }
127
+ equals(obj1, obj2) {
128
+ return core.ObjectUtils.objectToString(obj1) === core.ObjectUtils.objectToString(obj2);
129
+ }
130
+ find(arr, checkerFn) {
131
+ if (arr) {
132
+ for (let i = 0, length = arr.length; i < length; i++) {
133
+ if (checkerFn(arr[i], i, arr)) {
134
+ return arr[i];
135
+ }
136
+ }
137
+ }
138
+ else {
139
+ return undefined;
140
+ }
141
+ }
142
+ /**
143
+ matchFields-> array __matchFields do data
144
+ value -> termo que está sendo pesquisao
145
+ fieldMD -> metadados retornados pelo serviço de pesquisa
146
+ forceMatch -> força a pesquisa mesmo que não tenha __matchFields no metadado
147
+ */
148
+ highlightValue(matchFields, value, fieldMD, forceMatch) {
149
+ let valueAux = this.replaceHtmlEntities(value);
150
+ if (this.argument && (forceMatch || this.isIn(matchFields, fieldMD.fieldName))) {
151
+ const argumentNumber = this.getArgumentNumber();
152
+ let replacements = (isNaN(argumentNumber) ? this.argument : argumentNumber.toString()).split(/%|,|\s+/);
153
+ let lastMatchIndex = 0;
154
+ let cleanText = this.replaceAccentuatedChars(valueAux);
155
+ replacements.forEach((r) => {
156
+ if (r) {
157
+ r = this.replaceAccentuatedChars(r);
158
+ let specialChars = this.getSpecialCharacters(r);
159
+ if (specialChars != undefined && specialChars.length > 0) {
160
+ r = this.removeSpecialCharacters(r);
161
+ }
162
+ if (fieldMD.mask || fieldMD.uiType === 'CGC_CPF' || fieldMD.uiType === 'Phone') {
163
+ //Fazemos isso para descondirerar os caracteres especiais de formatação da string
164
+ r = r.split('').join('\\.?\\-?\\/?\\(?\\)?');
165
+ }
166
+ let regex = new RegExp(r, "ig");
167
+ regex.lastIndex = lastMatchIndex;
168
+ let match = regex.exec(cleanText);
169
+ if (match && match.length > 0) {
170
+ lastMatchIndex = match.index;
171
+ let sizeMatch = match[0].length;
172
+ let txtToColor = valueAux.substring(lastMatchIndex, lastMatchIndex + sizeMatch);
173
+ let txtColored = (txtToColor === null || txtToColor === void 0 ? void 0 : txtToColor.trim()) ? this._startHighlightTag + txtToColor + this._endHighlightTag : '';
174
+ let start = valueAux.substring(0, lastMatchIndex);
175
+ let end = valueAux.substring(lastMatchIndex + sizeMatch);
176
+ valueAux = start + txtColored + end;
177
+ lastMatchIndex = lastMatchIndex + txtColored.length;
178
+ cleanText = this.replaceAccentuatedChars(valueAux);
179
+ }
180
+ }
181
+ });
182
+ }
183
+ return valueAux;
184
+ }
185
+ replaceHtmlEntities(source) {
186
+ if (source == undefined) {
187
+ return source;
188
+ }
189
+ return String(source)
190
+ .replace(/&/g, '&amp;')
191
+ .replace(/</g, '&lt;')
192
+ .replace(/>/g, '&gt;')
193
+ .replace(/"/g, '&quot;');
194
+ }
195
+ replaceAccentuatedChars(source) {
196
+ if (source == undefined) {
197
+ return source;
198
+ }
199
+ const replaceList = ['&amp;', '&lt;', '&gt;', '&quot;'];
200
+ const sourceAux = this.replaceToSpace(source, replaceList);
201
+ return sourceAux.replace(/[^\w ]/g, (char) => {
202
+ let index = this._charsWithAccentuation.indexOf(char);
203
+ if (index > -1) {
204
+ char = this._charsWithoutAccentuation.charAt(index);
205
+ }
206
+ return char || '';
207
+ });
208
+ }
209
+ replaceToSpace(source, replaceList = []) {
210
+ if (source == undefined) {
211
+ return source;
212
+ }
213
+ replaceList.forEach((word) => {
214
+ const wordAux = new RegExp(word, 'g');
215
+ let whiteSpace = '';
216
+ for (let i = 0; i < word.length; i++) {
217
+ whiteSpace += ' ';
218
+ }
219
+ source = String(source).replace(wordAux, whiteSpace);
220
+ });
221
+ return source;
222
+ }
223
+ isIn(arr, obj) {
224
+ return this.indexOf(arr, obj) > -1;
225
+ }
226
+ getSpecialCharacters(str) {
227
+ let match;
228
+ let charList = [];
229
+ while ((match = this._specialCharsRegex.exec(str))) {
230
+ charList.push(str[match.index]);
231
+ }
232
+ return charList;
233
+ }
234
+ removeSpecialCharacters(str) {
235
+ let specialChars = this.getSpecialCharacters(str);
236
+ specialChars.forEach((ch) => {
237
+ str = this.replaceAll(str, ch, '');
238
+ });
239
+ return str;
240
+ }
241
+ replaceAll(str, strFrom, strTo) {
242
+ let pos = (str != undefined ? str : '').indexOf(strFrom);
243
+ while (pos > -1) {
244
+ str = str.replace(strFrom, strTo);
245
+ pos = str.indexOf(strFrom);
246
+ }
247
+ return (str);
248
+ }
249
+ getArgumentNumber() {
250
+ return Number(this.argument || undefined);
251
+ }
252
+ createOption(detail) {
253
+ const { key, title } = detail;
254
+ const startHighlight = new RegExp(this._startHighlightTag, 'g');
255
+ const endHighlight = new RegExp(this._endHighlightTag, 'g');
256
+ const option = {
257
+ value: key === null || key === void 0 ? void 0 : key.replace(startHighlight, '').replace(endHighlight, ''),
258
+ label: title === null || title === void 0 ? void 0 : title.replace(startHighlight, '').replace(endHighlight, '')
259
+ };
260
+ this.selectItem(option);
261
+ }
262
+ onChangeValue(event) {
263
+ this.clearDeboucingTimeout();
264
+ if (this._startLoading) {
265
+ this._changeDeboucingTimeout = setTimeout(() => {
266
+ this.onChangeValue(event);
267
+ }, this._deboucingTime);
268
+ return;
269
+ }
270
+ this.argument = (event.detail || "").trim();
271
+ const argumentNumber = this.getArgumentNumber();
272
+ if (this.argument && (!isNaN(argumentNumber) || this.argument.length >= this._limitCharsToSearch)) {
273
+ this._changeDeboucingTimeout = setTimeout(() => {
274
+ this.doSearch(isNaN(argumentNumber) ? this.argument : argumentNumber.toString());
275
+ }, this._deboucingTime);
276
+ }
277
+ else {
278
+ this._itemList = undefined;
279
+ }
280
+ }
281
+ clearDeboucingTimeout() {
282
+ if (this._changeDeboucingTimeout) {
283
+ clearTimeout(this._changeDeboucingTimeout);
284
+ this._changeDeboucingTimeout = undefined;
285
+ }
286
+ }
287
+ onClickSearch() {
288
+ this.doSearch((this.argument || "").trim());
289
+ }
290
+ getMessageView() {
291
+ return this._startLoading
292
+ ? 'Aguarde, buscando registros...'
293
+ : this._itemList
294
+ ? this._itemList.length >= 1
295
+ ? `${this._itemList.length} ${this._itemList.length > 1
296
+ ? 'registros encontrados'
297
+ : 'registro encontrado'}`
298
+ : 'Nenhum registro encontrado'
299
+ : 'Os resultados de sua pesquisa aparecerão aqui...';
12
300
  }
13
301
  render() {
14
- return (index.h(index.Host, null, index.h("ez-text-input", { ref: ref => this._textInput = ref, value: this.argument }), index.h("button", { onClick: () => this.searchLoader(this._textInput["value"]) }, "pesquisar"), index.h("button", { onClick: () => this.onSelectItem({ value: "10", label: "Zé das couves" }) }, "selecionar")));
302
+ return (index.h(index.Host, null, index.h("div", { class: "snk-pesquisa" }, index.h("div", { class: "snk-pesquisa__input" }, index.h("ez-text-input", { label: "Buscar", class: "ez-margin-right--medium", canShowError: false, ref: (ref) => this._textInput = ref, onEzChange: (event) => this.onChangeValue(event), value: this.argument }, index.h("ez-icon", { slot: "leftIcon", iconName: "search" }), index.h("ez-icon", { class: "snk-pesquisa__input-close", slot: "rightIcon", iconName: "close", onClick: () => { this.clearSearch(); } })), index.h("ez-button", { class: "ez-button--primary", label: "Pesquisar", onClick: () => this.onClickSearch() })), index.h("label", { class: "snk-pesquisa__records" }, this.getMessageView()), index.h("div", { class: "snk-pesquisa__content" }, this._itemList && this._itemList.map((item) => {
303
+ return (index.h("ez-card-item", { onEzClick: (event) => this.createOption(event.detail), item: item }));
304
+ })))));
15
305
  }
306
+ static get watchers() { return {
307
+ "argument": ["observeArgument"]
308
+ }; }
16
309
  };
17
310
  SnkPesquisa.style = snkPesquisaCss;
18
311