@sankhyalabs/sankhyablocks 1.3.30 → 1.3.31-beta.10

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 (79) hide show
  1. package/dist/cjs/{index-1133bc2a.js → index-c6671817.js} +416 -9
  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 +280 -107
  5. package/dist/cjs/snk-crud.cjs.entry.js +64 -0
  6. package/dist/cjs/snk-data-unit.cjs.entry.js +218 -0
  7. package/dist/cjs/snk-form_2.cjs.entry.js +170 -0
  8. package/dist/cjs/snk-pesquisa.cjs.entry.js +6 -3
  9. package/dist/cjs/snk-taskbar.cjs.entry.js +140 -0
  10. package/dist/cjs/taskbar-elements-7f99f0c9.js +70 -0
  11. package/dist/cjs/teste-pesquisa.cjs.entry.js +1 -1
  12. package/dist/collection/collection-manifest.json +5 -0
  13. package/dist/collection/components/snk-application/errorhandler/snk-error-handler.js +2 -2
  14. package/dist/collection/components/snk-application/snk-application.js +237 -62
  15. package/dist/collection/components/snk-crud/snk-crud.css +5 -0
  16. package/dist/collection/components/snk-crud/snk-crud.js +149 -0
  17. package/dist/collection/components/snk-data-unit/snk-data-unit.css +6 -0
  18. package/dist/collection/components/snk-data-unit/snk-data-unit.js +492 -0
  19. package/dist/collection/components/snk-form/snk-form.css +34 -0
  20. package/dist/collection/components/snk-form/snk-form.js +230 -0
  21. package/dist/collection/components/snk-grid/snk-grid.css +5 -0
  22. package/dist/collection/components/snk-grid/snk-grid.js +148 -0
  23. package/dist/collection/components/snk-pesquisa/snk-pesquisa.css +56 -13
  24. package/dist/collection/components/snk-pesquisa/snk-pesquisa.js +5 -1
  25. package/dist/collection/components/snk-taskbar/elements/taskbar-elements.js +65 -0
  26. package/dist/collection/components/snk-taskbar/snk-taskbar.css +3 -0
  27. package/dist/collection/components/snk-taskbar/snk-taskbar.js +252 -0
  28. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +52 -21
  29. package/dist/collection/lib/http/data-fetcher/fetchers/grid-config-fetcher.js +4 -3
  30. package/dist/collection/lib/http/data-fetcher/fetchers/pesquisa-fetcher.js +2 -0
  31. package/dist/components/snk-application2.js +280 -106
  32. package/dist/components/snk-crud.d.ts +11 -0
  33. package/dist/components/snk-crud.js +102 -0
  34. package/dist/components/snk-data-unit.d.ts +11 -0
  35. package/dist/components/snk-data-unit.js +242 -0
  36. package/dist/components/snk-form.d.ts +11 -0
  37. package/dist/components/snk-form.js +6 -0
  38. package/dist/components/snk-form2.js +134 -0
  39. package/dist/components/snk-grid.d.ts +11 -0
  40. package/dist/components/snk-grid.js +6 -0
  41. package/dist/components/snk-grid2.js +91 -0
  42. package/dist/components/snk-pesquisa2.js +5 -2
  43. package/dist/components/snk-taskbar.d.ts +11 -0
  44. package/dist/components/snk-taskbar.js +6 -0
  45. package/dist/components/snk-taskbar2.js +221 -0
  46. package/dist/esm/{index-ffda6382.js → index-6a83ac96.js} +416 -10
  47. package/dist/esm/loader.js +2 -2
  48. package/dist/esm/sankhyablocks.js +2 -2
  49. package/dist/esm/snk-application.entry.js +280 -107
  50. package/dist/esm/snk-crud.entry.js +60 -0
  51. package/dist/esm/snk-data-unit.entry.js +214 -0
  52. package/dist/esm/snk-form_2.entry.js +165 -0
  53. package/dist/esm/snk-pesquisa.entry.js +6 -3
  54. package/dist/esm/snk-taskbar.entry.js +136 -0
  55. package/dist/esm/taskbar-elements-e0b8a285.js +68 -0
  56. package/dist/esm/teste-pesquisa.entry.js +1 -1
  57. package/dist/sankhyablocks/p-18fe0469.entry.js +69 -0
  58. package/dist/sankhyablocks/p-4c7b32d6.entry.js +1 -0
  59. package/dist/sankhyablocks/p-5b5afdbe.entry.js +1 -0
  60. package/dist/sankhyablocks/p-7fe9e5c2.entry.js +1 -0
  61. package/dist/sankhyablocks/p-8650ae26.entry.js +1 -0
  62. package/dist/sankhyablocks/p-a5439706.js +1 -0
  63. package/dist/sankhyablocks/p-c3d20542.entry.js +1 -0
  64. package/dist/sankhyablocks/p-cd1dc099.js +2 -0
  65. package/dist/sankhyablocks/{p-2a7b4cb3.entry.js → p-d25637c9.entry.js} +1 -1
  66. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  67. package/dist/types/components/snk-application/snk-application.d.ts +103 -15
  68. package/dist/types/components/snk-taskbar/elements/taskbar-elements.d.ts +25 -0
  69. package/dist/types/components/snk-taskbar/snk-taskbar.d.ts +45 -0
  70. package/dist/types/components.d.ts +381 -6
  71. package/dist/types/lib/http/data-fetcher/fetchers/dataunit-fetcher.d.ts +2 -0
  72. package/dist/types/lib/http/data-fetcher/fetchers/grid-config-fetcher.d.ts +3 -3
  73. package/package.json +5 -5
  74. package/react/components.d.ts +5 -0
  75. package/react/components.js +5 -0
  76. package/react/components.js.map +1 -1
  77. package/dist/sankhyablocks/p-d62412bb.entry.js +0 -1
  78. package/dist/sankhyablocks/p-e6e91d5f.entry.js +0 -69
  79. package/dist/sankhyablocks/p-edcb9d8e.js +0 -2
@@ -1,7 +1,6 @@
1
- import { r as registerInstance, c as createEvent, h } from './index-ffda6382.js';
2
- import { ErrorException, StringUtils, DataUnit, DataType, ChangeOperation, DateUtils, ObjectUtils, WaitingChangeException, WarningException, ApplicationContext, ErrorTracking } from '@sankhyalabs/core';
1
+ import { r as registerInstance, c as createEvent, h } from './index-6a83ac96.js';
2
+ import { ErrorException, StringUtils, DataUnit, DataType, ChangeOperation, DateUtils, ObjectUtils, WaitingChangeException, WarningException, DependencyType, ApplicationContext, ErrorTracking } from '@sankhyalabs/core';
3
3
  import { ApplicationUtils } from '@sankhyalabs/ezui/dist/collection/utils';
4
- import { DependencyType } from '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
5
4
 
6
5
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7
6
 
@@ -1232,7 +1231,7 @@ function isNode(maybeNode) {
1232
1231
  }
1233
1232
  /** Name */
1234
1233
 
1235
- let OperationTypeNode;
1234
+ var OperationTypeNode;
1236
1235
  exports.OperationTypeNode = OperationTypeNode;
1237
1236
 
1238
1237
  (function (OperationTypeNode) {
@@ -1252,13 +1251,7 @@ exports.DirectiveLocation = void 0;
1252
1251
  /**
1253
1252
  * The set of allowed directive location values.
1254
1253
  */
1255
- let DirectiveLocation;
1256
- /**
1257
- * The enum type representing the directive location values.
1258
- *
1259
- * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
1260
- */
1261
-
1254
+ var DirectiveLocation;
1262
1255
  exports.DirectiveLocation = DirectiveLocation;
1263
1256
 
1264
1257
  (function (DirectiveLocation) {
@@ -1282,6 +1275,11 @@ exports.DirectiveLocation = DirectiveLocation;
1282
1275
  DirectiveLocation['INPUT_OBJECT'] = 'INPUT_OBJECT';
1283
1276
  DirectiveLocation['INPUT_FIELD_DEFINITION'] = 'INPUT_FIELD_DEFINITION';
1284
1277
  })(DirectiveLocation || (exports.DirectiveLocation = DirectiveLocation = {}));
1278
+ /**
1279
+ * The enum type representing the directive location values.
1280
+ *
1281
+ * @deprecated Please use `DirectiveLocation`. Will be remove in v17.
1282
+ */
1285
1283
  });
1286
1284
 
1287
1285
  var kinds = createCommonjsModule(function (module, exports) {
@@ -1294,13 +1292,7 @@ exports.Kind = void 0;
1294
1292
  /**
1295
1293
  * The set of allowed kind values for AST nodes.
1296
1294
  */
1297
- let Kind;
1298
- /**
1299
- * The enum type representing the possible kind values of AST nodes.
1300
- *
1301
- * @deprecated Please use `Kind`. Will be remove in v17.
1302
- */
1303
-
1295
+ var Kind;
1304
1296
  exports.Kind = Kind;
1305
1297
 
1306
1298
  (function (Kind) {
@@ -1348,6 +1340,11 @@ exports.Kind = Kind;
1348
1340
  Kind['ENUM_TYPE_EXTENSION'] = 'EnumTypeExtension';
1349
1341
  Kind['INPUT_OBJECT_TYPE_EXTENSION'] = 'InputObjectTypeExtension';
1350
1342
  })(Kind || (exports.Kind = Kind = {}));
1343
+ /**
1344
+ * The enum type representing the possible kind values of AST nodes.
1345
+ *
1346
+ * @deprecated Please use `Kind`. Will be remove in v17.
1347
+ */
1351
1348
  });
1352
1349
 
1353
1350
  var characterClasses = createCommonjsModule(function (module, exports) {
@@ -1635,13 +1632,7 @@ exports.TokenKind = void 0;
1635
1632
  * An exported enum describing the different kinds of tokens that the
1636
1633
  * lexer emits.
1637
1634
  */
1638
- let TokenKind;
1639
- /**
1640
- * The enum type representing the token kinds values.
1641
- *
1642
- * @deprecated Please use `TokenKind`. Will be remove in v17.
1643
- */
1644
-
1635
+ var TokenKind;
1645
1636
  exports.TokenKind = TokenKind;
1646
1637
 
1647
1638
  (function (TokenKind) {
@@ -1668,6 +1659,11 @@ exports.TokenKind = TokenKind;
1668
1659
  TokenKind['BLOCK_STRING'] = 'BlockString';
1669
1660
  TokenKind['COMMENT'] = 'Comment';
1670
1661
  })(TokenKind || (exports.TokenKind = TokenKind = {}));
1662
+ /**
1663
+ * The enum type representing the token kinds values.
1664
+ *
1665
+ * @deprecated Please use `TokenKind`. Will be remove in v17.
1666
+ */
1671
1667
  });
1672
1668
 
1673
1669
  var lexer = createCommonjsModule(function (module, exports) {
@@ -3004,12 +3000,13 @@ function parseType(source, options) {
3004
3000
  */
3005
3001
 
3006
3002
  class Parser {
3007
- constructor(source$1, options) {
3003
+ constructor(source$1, options = {}) {
3008
3004
  const sourceObj = (0, source.isSource)(source$1)
3009
3005
  ? source$1
3010
3006
  : new source.Source(source$1);
3011
3007
  this._lexer = new lexer.Lexer(sourceObj);
3012
3008
  this._options = options;
3009
+ this._tokenCounter = 0;
3013
3010
  }
3014
3011
  /**
3015
3012
  * Converts a name lex token into a name parse node.
@@ -3344,18 +3341,12 @@ class Parser {
3344
3341
  */
3345
3342
 
3346
3343
  parseFragmentDefinition() {
3347
- var _this$_options;
3348
-
3349
3344
  const start = this._lexer.token;
3350
3345
  this.expectKeyword('fragment'); // Legacy support for defining variables within fragments changes
3351
3346
  // the grammar of FragmentDefinition:
3352
3347
  // - fragment FragmentName VariableDefinitions? on TypeCondition Directives? SelectionSet
3353
3348
 
3354
- if (
3355
- ((_this$_options = this._options) === null || _this$_options === void 0
3356
- ? void 0
3357
- : _this$_options.allowLegacyFragmentVariables) === true
3358
- ) {
3349
+ if (this._options.allowLegacyFragmentVariables === true) {
3359
3350
  return this.node(start, {
3360
3351
  kind: kinds.Kind.FRAGMENT_DEFINITION,
3361
3352
  name: this.parseFragmentName(),
@@ -3416,16 +3407,14 @@ class Parser {
3416
3407
  return this.parseObject(isConst);
3417
3408
 
3418
3409
  case tokenKind.TokenKind.INT:
3419
- this._lexer.advance();
3420
-
3410
+ this.advanceLexer();
3421
3411
  return this.node(token, {
3422
3412
  kind: kinds.Kind.INT,
3423
3413
  value: token.value,
3424
3414
  });
3425
3415
 
3426
3416
  case tokenKind.TokenKind.FLOAT:
3427
- this._lexer.advance();
3428
-
3417
+ this.advanceLexer();
3429
3418
  return this.node(token, {
3430
3419
  kind: kinds.Kind.FLOAT,
3431
3420
  value: token.value,
@@ -3436,7 +3425,7 @@ class Parser {
3436
3425
  return this.parseStringLiteral();
3437
3426
 
3438
3427
  case tokenKind.TokenKind.NAME:
3439
- this._lexer.advance();
3428
+ this.advanceLexer();
3440
3429
 
3441
3430
  switch (token.value) {
3442
3431
  case 'true':
@@ -3492,9 +3481,7 @@ class Parser {
3492
3481
 
3493
3482
  parseStringLiteral() {
3494
3483
  const token = this._lexer.token;
3495
-
3496
- this._lexer.advance();
3497
-
3484
+ this.advanceLexer();
3498
3485
  return this.node(token, {
3499
3486
  kind: kinds.Kind.STRING,
3500
3487
  value: token.value,
@@ -4285,13 +4272,7 @@ class Parser {
4285
4272
  */
4286
4273
 
4287
4274
  node(startToken, node) {
4288
- var _this$_options2;
4289
-
4290
- if (
4291
- ((_this$_options2 = this._options) === null || _this$_options2 === void 0
4292
- ? void 0
4293
- : _this$_options2.noLocation) !== true
4294
- ) {
4275
+ if (this._options.noLocation !== true) {
4295
4276
  node.loc = new ast.Location(
4296
4277
  startToken,
4297
4278
  this._lexer.lastToken,
@@ -4317,8 +4298,7 @@ class Parser {
4317
4298
  const token = this._lexer.token;
4318
4299
 
4319
4300
  if (token.kind === kind) {
4320
- this._lexer.advance();
4321
-
4301
+ this.advanceLexer();
4322
4302
  return token;
4323
4303
  }
4324
4304
 
@@ -4337,8 +4317,7 @@ class Parser {
4337
4317
  const token = this._lexer.token;
4338
4318
 
4339
4319
  if (token.kind === kind) {
4340
- this._lexer.advance();
4341
-
4320
+ this.advanceLexer();
4342
4321
  return true;
4343
4322
  }
4344
4323
 
@@ -4353,7 +4332,7 @@ class Parser {
4353
4332
  const token = this._lexer.token;
4354
4333
 
4355
4334
  if (token.kind === tokenKind.TokenKind.NAME && token.value === value) {
4356
- this._lexer.advance();
4335
+ this.advanceLexer();
4357
4336
  } else {
4358
4337
  throw (0, syntaxError_1.syntaxError)(
4359
4338
  this._lexer.source,
@@ -4371,8 +4350,7 @@ class Parser {
4371
4350
  const token = this._lexer.token;
4372
4351
 
4373
4352
  if (token.kind === tokenKind.TokenKind.NAME && token.value === value) {
4374
- this._lexer.advance();
4375
-
4353
+ this.advanceLexer();
4376
4354
  return true;
4377
4355
  }
4378
4356
 
@@ -4459,6 +4437,24 @@ class Parser {
4459
4437
 
4460
4438
  return nodes;
4461
4439
  }
4440
+
4441
+ advanceLexer() {
4442
+ const { maxTokens } = this._options;
4443
+
4444
+ const token = this._lexer.advance();
4445
+
4446
+ if (maxTokens !== undefined && token.kind !== tokenKind.TokenKind.EOF) {
4447
+ ++this._tokenCounter;
4448
+
4449
+ if (this._tokenCounter > maxTokens) {
4450
+ throw (0, syntaxError_1.syntaxError)(
4451
+ this._lexer.source,
4452
+ token.start,
4453
+ `Document contains more that ${maxTokens} tokens. Parsing aborted.`,
4454
+ );
4455
+ }
4456
+ }
4457
+ }
4462
4458
  }
4463
4459
  /**
4464
4460
  * A helper function to describe a token as a string for debugging.
@@ -6691,6 +6687,7 @@ class WaitingRequest {
6691
6687
  class DataUnitFetcher {
6692
6688
  constructor() {
6693
6689
  this.templateByQuery = new Map();
6690
+ this._loadDataTimeout = {};
6694
6691
  this.buldTemplates();
6695
6692
  }
6696
6693
  buldTemplates() {
@@ -6719,9 +6716,9 @@ class DataUnitFetcher {
6719
6716
  }
6720
6717
  }
6721
6718
  }`);
6722
- this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $limit: Int $offset:Int $filter: [InputFilter!] $sort: [InputSort!]) {
6719
+ this.templateByQuery.set("fetchData", dist.gql `query($dataunit: String! $limit: Int $offset:Int $filters: [InputFilter!] $sort: [InputSort!]) {
6723
6720
  $queryAlias$: fetchDataUnit(name: $dataunit){
6724
- data(limit: $limit offset: $offset filters: $filter sort: $sort){
6721
+ data(limit: $limit offset: $offset filters: $filters sort: $sort){
6725
6722
  limit
6726
6723
  offset
6727
6724
  total
@@ -6750,7 +6747,7 @@ class DataUnitFetcher {
6750
6747
  getDataUnit(entityName, resourceID) {
6751
6748
  const dataUnit = new DataUnit(`dd://${entityName}/${resourceID}`);
6752
6749
  dataUnit.metadataLoader = (dataUnit) => this.loadMetadata(dataUnit);
6753
- dataUnit.dataLoader = (dataUnit, page, sort, filters) => this.loadData(dataUnit, page, sort, filters);
6750
+ dataUnit.dataLoader = (dataUnit, request) => this.loadData(dataUnit, request);
6754
6751
  dataUnit.saveLoader = (dataUnit, changes) => this.saveData(dataUnit, changes);
6755
6752
  dataUnit.removeLoader = (dataUnit, recordIds) => this.removeRecords(dataUnit, recordIds);
6756
6753
  return dataUnit;
@@ -6787,25 +6784,39 @@ class DataUnitFetcher {
6787
6784
  });
6788
6785
  });
6789
6786
  }
6790
- loadData(dataUnit, page, sort, filter) {
6787
+ loadData(dataUnit, request) {
6788
+ const duName = dataUnit.name;
6789
+ if (this._loadDataTimeout[duName]) {
6790
+ clearTimeout(this._loadDataTimeout[duName]);
6791
+ delete this._loadDataTimeout[duName];
6792
+ }
6791
6793
  return new Promise((resolve, reject) => {
6792
- var _a, _b, _c;
6793
- const variables = { dataunit: dataUnit.name, sort, filter };
6794
- if (page) {
6795
- variables.limit = page.limit;
6796
- variables.offset = page.offset;
6797
- }
6798
- if (!StringUtils.isEmpty((_a = page === null || page === void 0 ? void 0 : page.quickFilter) === null || _a === void 0 ? void 0 : _a.term)) {
6794
+ this._loadDataTimeout[duName] = setTimeout(() => {
6795
+ delete this._loadDataTimeout[duName];
6796
+ this.doLoadData(dataUnit, request)
6797
+ .then(result => resolve(result))
6798
+ .catch(reason => reject(reason));
6799
+ }, 200);
6800
+ });
6801
+ }
6802
+ doLoadData(dataUnit, request) {
6803
+ return new Promise((resolve, reject) => {
6804
+ var _a;
6805
+ const { sort, filters, limit, offset, quickFilter } = request;
6806
+ const variables = { dataunit: dataUnit.name, sort, filters };
6807
+ variables.limit = limit;
6808
+ variables.offset = offset;
6809
+ if (!StringUtils.isEmpty(quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.term)) {
6799
6810
  if (variables.filter === undefined) {
6800
6811
  variables.filter = [];
6801
6812
  }
6802
6813
  const quickFilterCriteria = {
6803
6814
  name: "__QUICK_FILTER__",
6804
6815
  expression: "__QUICK_FILTER__",
6805
- params: [{ name: "term", dataType: DataType.TEXT, value: page.quickFilter.term }]
6816
+ params: [{ name: "term", dataType: DataType.TEXT, value: quickFilter.term }]
6806
6817
  };
6807
- if (((_c = (_b = page.quickFilter) === null || _b === void 0 ? void 0 : _b.fields) === null || _c === void 0 ? void 0 : _c.length) > 0) {
6808
- quickFilterCriteria.params.push({ name: "fields", dataType: DataType.OBJECT, value: page.quickFilter.fields });
6818
+ if (((_a = quickFilter === null || quickFilter === void 0 ? void 0 : quickFilter.fields) === null || _a === void 0 ? void 0 : _a.length) > 0) {
6819
+ quickFilterCriteria.params.push({ name: "fields", dataType: DataType.OBJECT, value: quickFilter.fields });
6809
6820
  }
6810
6821
  variables.filter.push(quickFilterCriteria);
6811
6822
  }
@@ -6815,16 +6826,32 @@ class DataUnitFetcher {
6815
6826
  query: this.templateByQuery.get("fetchData"),
6816
6827
  })
6817
6828
  .then((resp) => {
6818
- const pageResult = resp.data;
6819
- const records = [];
6820
- pageResult.records.forEach((responseRecord) => {
6829
+ const { limit, offset, total, hasMore, records } = resp.data;
6830
+ let paginationInfo;
6831
+ if (limit) {
6832
+ const firstRecord = offset + 1;
6833
+ const lastRecord = offset + Math.min(records.length, limit);
6834
+ const currentPage = offset / limit;
6835
+ paginationInfo = {
6836
+ firstRecord,
6837
+ lastRecord,
6838
+ total,
6839
+ currentPage,
6840
+ hasMore
6841
+ };
6842
+ }
6843
+ const processedRecords = [];
6844
+ records.forEach((responseRecord) => {
6821
6845
  const duRecord = { __record__id__: responseRecord.id };
6822
6846
  responseRecord.fields.forEach(({ name, value }) => {
6823
6847
  duRecord[name] = dataUnit.valueFromString(name, value);
6824
6848
  });
6825
- records.push(duRecord);
6849
+ processedRecords.push(duRecord);
6850
+ });
6851
+ resolve({
6852
+ paginationInfo,
6853
+ records: processedRecords
6826
6854
  });
6827
- resolve(Object.assign(Object.assign({}, pageResult), { records }));
6828
6855
  })
6829
6856
  .catch((error) => {
6830
6857
  reject(error);
@@ -7050,15 +7077,16 @@ class GridConfigFetcher extends ResourceFetcher {
7050
7077
  super(...arguments);
7051
7078
  this.GRID_CONFIG_VERSION = "V3:";
7052
7079
  }
7053
- getConfig(resourceID) {
7080
+ getConfig(_gridName, resourceID) {
7054
7081
  const completePath = `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}`;
7055
7082
  return new Promise((resolve, reject) => {
7056
7083
  this.loadResource(completePath)
7057
7084
  .then(loadedResource => {
7085
+ let config = undefined;
7058
7086
  if (loadedResource) {
7059
- let config = JSON.parse(loadedResource);
7060
- resolve(config);
7087
+ config = JSON.parse(loadedResource);
7061
7088
  }
7089
+ resolve(config);
7062
7090
  }).catch((error) => {
7063
7091
  reject(error);
7064
7092
  });
@@ -7093,6 +7121,8 @@ class PesquisaFetcher {
7093
7121
  }`);
7094
7122
  }
7095
7123
  loadSearchOptions(entityName, argument, criteria, options) {
7124
+ const cleanText = (argument === null || argument === void 0 ? void 0 : argument.trim()) || undefined;
7125
+ argument = isNaN(Number(cleanText)) && cleanText ? `%${cleanText}` : cleanText;
7096
7126
  return new Promise((resolve, reject) => {
7097
7127
  DataFetcher.get()
7098
7128
  .callGraphQL({
@@ -7233,7 +7263,7 @@ class SnkErrorHandler {
7233
7263
  }
7234
7264
  else {
7235
7265
  const title = (exception === null || exception === void 0 ? void 0 : exception.title) || "Erro detectado";
7236
- const message = (typeof exception === "string") ? exception : exception.message || `Erro interno "${exception}"`;
7266
+ const message = (typeof exception === "string") ? exception : exception.message || `Erro interno "${ObjectUtils.objectToString(exception)}"`;
7237
7267
  this._app.error(title, message);
7238
7268
  }
7239
7269
  }
@@ -7251,6 +7281,9 @@ const SnkApplication = class {
7251
7281
  registerInstance(this, hostRef);
7252
7282
  this.applicationLoaded = createEvent(this, "applicationLoaded", 7);
7253
7283
  this.applicationLoading = createEvent(this, "applicationLoading", 7);
7284
+ this._authPromises = [];
7285
+ this._duCache = new Map();
7286
+ this._duPromises = new Map();
7254
7287
  this._requestListener = new RequestListenerLoadingBar();
7255
7288
  }
7256
7289
  get parameters() {
@@ -7269,18 +7302,31 @@ const SnkApplication = class {
7269
7302
  return this._resourceID;
7270
7303
  }
7271
7304
  get auth() {
7272
- return new Promise((resolve, reject) => {
7273
- if (this._auth) {
7274
- resolve(this._auth);
7275
- }
7276
- else {
7277
- this.authFetcher.getData(this._resourceID).then((authList) => {
7278
- this._auth = authList;
7279
- resolve(authList);
7280
- }).catch(error => reject(error));
7281
- }
7282
- });
7305
+ if (this._auth) {
7306
+ return Promise.resolve(this._auth);
7307
+ }
7308
+ else {
7309
+ return new Promise((resolve, reject) => {
7310
+ const waitingAuth = this._authPromises.length > 0;
7311
+ this._authPromises.push(new PendingPromise(resolve, reject));
7312
+ if (!waitingAuth) {
7313
+ this.authFetcher.getData(this._resourceID).then((authList) => {
7314
+ this._auth = authList;
7315
+ while (this._authPromises.length > 0) {
7316
+ this._authPromises.pop().resolve(this._auth);
7317
+ }
7318
+ }).catch(error => {
7319
+ while (this._authPromises.length > 0) {
7320
+ this._authPromises.pop().reject(error);
7321
+ }
7322
+ });
7323
+ }
7324
+ });
7325
+ }
7283
7326
  }
7327
+ /**
7328
+ * Caso o usuário logado seja o SUP.
7329
+ */
7284
7330
  async isUserSup() {
7285
7331
  return new Promise((resolve, reject) => {
7286
7332
  this.auth.then((authorization) => {
@@ -7290,6 +7336,9 @@ const SnkApplication = class {
7290
7336
  });
7291
7337
  });
7292
7338
  }
7339
+ /**
7340
+ * Se o usuário logado tem permissão pra determinada ação.
7341
+ */
7293
7342
  async hasAccess(access) {
7294
7343
  return new Promise((resolve, reject) => {
7295
7344
  this.auth.then((authorization) => {
@@ -7299,6 +7348,9 @@ const SnkApplication = class {
7299
7348
  });
7300
7349
  });
7301
7350
  }
7351
+ /**
7352
+ * Retorna todos os acessos do usuário logado.
7353
+ */
7302
7354
  async getAllAccess() {
7303
7355
  return new Promise((resolve, reject) => {
7304
7356
  this.auth.then((authorization) => {
@@ -7313,34 +7365,54 @@ const SnkApplication = class {
7313
7365
  });
7314
7366
  });
7315
7367
  }
7316
- async getAuthList(_auth) {
7317
- return await (new MGEAuthorization()).parseFromJSON(_auth);
7318
- }
7368
+ /**
7369
+ * Retorna o valor de um parâmetro do tipo string.
7370
+ */
7319
7371
  async getStringParam(name) {
7320
7372
  return this.parameters.asString(name, this.resourceID);
7321
7373
  }
7374
+ /**
7375
+ * Retorna o valor de um parâmetro do tipo Inteiro.
7376
+ */
7322
7377
  async getIntParam(name) {
7323
7378
  return this.parameters.asInteger(name, this.resourceID);
7324
7379
  }
7380
+ /**
7381
+ * Retorna o valor de um parâmetro do tipo Decimal.
7382
+ */
7325
7383
  async getFloatParam(name) {
7326
7384
  return this.parameters.asFloat(name, this.resourceID);
7327
7385
  }
7386
+ /**
7387
+ * Retorna o valor de um parâmetro do tipo booleano.
7388
+ */
7328
7389
  async getBooleanParam(name) {
7329
7390
  return this.parameters.asBoolean(name, this.resourceID);
7330
7391
  }
7392
+ /**
7393
+ * Retorna o valor de um parâmetro do tipo data.
7394
+ */
7331
7395
  async getDateParam(name) {
7332
7396
  return this.parameters.asDate(name, this.resourceID);
7333
7397
  }
7398
+ /**
7399
+ * Mostra o conteúdo passado em um Popup
7400
+ */
7334
7401
  async showPopUp(content) {
7402
+ this.clearPopUpContent();
7335
7403
  this._popUp.appendChild(content);
7336
- this._popUp["opened"] = true;
7404
+ this._popUp.opened = true;
7337
7405
  }
7406
+ /**
7407
+ * Fecha o popup, liberando o conteúdo.
7408
+ */
7338
7409
  async closePopUp() {
7339
- Array.from(this._popUp.children).forEach(c => {
7340
- this._popUp.removeChild(c);
7341
- });
7342
- this._popUp["opened"] = false;
7410
+ this.clearPopUpContent();
7411
+ this._popUp.opened = false;
7343
7412
  }
7413
+ /**
7414
+ * Verifica se a licença do cliente tem determinado opcional (produto)
7415
+ */
7344
7416
  async temOpcional(opcional) {
7345
7417
  const opts = opcional.split(",");
7346
7418
  return new Promise((resolve, reject) => {
@@ -7364,6 +7436,10 @@ const SnkApplication = class {
7364
7436
  });
7365
7437
  });
7366
7438
  }
7439
+ /**
7440
+ * Retorna a configuração de um recurso por service broker
7441
+ * Veja também o método "loadConfig"
7442
+ */
7367
7443
  async getConfig(key) {
7368
7444
  let payload = {
7369
7445
  "serviceName": "SystemUtilsSP.getConf",
@@ -7381,6 +7457,9 @@ const SnkApplication = class {
7381
7457
  .catch(error => reject(error));
7382
7458
  });
7383
7459
  }
7460
+ /**
7461
+ * Salva a configuração de determinado recurso.
7462
+ */
7384
7463
  async saveConfig(key, data) {
7385
7464
  let payload = {
7386
7465
  "serviceName": "SystemUtilsSP.saveConf",
@@ -7399,42 +7478,122 @@ const SnkApplication = class {
7399
7478
  .catch(error => reject(error));
7400
7479
  });
7401
7480
  }
7481
+ /**
7482
+ * Acessa informações de contexto "empurrados" na abertura da tela
7483
+ */
7402
7484
  async getAttributeFromHTMLWrapper(attribName) {
7403
7485
  return Promise.resolve(window[attribName]);
7404
7486
  }
7487
+ /**
7488
+ * Abre determinada tela, repassando pkObject
7489
+ */
7405
7490
  async openApp(resourceId, pkObject) {
7406
7491
  Workspace.openAppActivity(resourceId, pkObject);
7407
7492
  }
7408
- async createDataunit(entityName) {
7409
- return new Promise(resolve => {
7410
- const dataUnit = this.dataUnitFetcher.getDataUnit(entityName, this.resourceID);
7411
- dataUnit.loadMetadata().then(() => resolve(dataUnit));
7493
+ getDuPromissesStack(dataUnitName) {
7494
+ let stack;
7495
+ if (dataUnitName) {
7496
+ stack = this._duPromises.get(dataUnitName);
7497
+ if (!stack) {
7498
+ stack = [];
7499
+ this._duPromises.set(dataUnitName, stack);
7500
+ }
7501
+ }
7502
+ return stack || [];
7503
+ }
7504
+ /**
7505
+ * Cria o DataUnit a partir do nome da entidade. É possível armazená-lo no cache
7506
+ * passando o dataUnitName, assim, se mais de uma chamada for feita, o mesmo DataUnit será usado
7507
+ */
7508
+ async createDataunit(entityName, dataUnitName) {
7509
+ return new Promise((resolve, reject) => {
7510
+ const duPromisses = this.getDuPromissesStack(dataUnitName);
7511
+ const waitingDu = duPromisses.length > 0;
7512
+ duPromisses.push(new PendingPromise(resolve, reject));
7513
+ if (!waitingDu) {
7514
+ const dataUnit = this.dataUnitFetcher.getDataUnit(entityName, this.resourceID);
7515
+ dataUnit.loadMetadata().then(() => {
7516
+ if (dataUnitName) {
7517
+ this._duCache.set(dataUnitName, dataUnit);
7518
+ }
7519
+ while (duPromisses.length > 0) {
7520
+ duPromisses.pop().resolve(dataUnit);
7521
+ }
7522
+ }).catch(reason => {
7523
+ while (duPromisses.length > 0) {
7524
+ duPromisses.pop().reject(reason);
7525
+ }
7526
+ });
7527
+ }
7528
+ });
7529
+ }
7530
+ /**
7531
+ * Obtem um DataUnit do cache ou cria um caso ainda não tenha sido criado.
7532
+ */
7533
+ async getDataUnit(entityName, dataUnitName) {
7534
+ return new Promise((resolve, reject) => {
7535
+ const dataUnit = this._duCache.get(dataUnitName);
7536
+ if (dataUnit) {
7537
+ resolve(dataUnit);
7538
+ }
7539
+ else {
7540
+ this.createDataunit(entityName, dataUnitName).then(dataUnit => {
7541
+ resolve(dataUnit);
7542
+ }).catch(reason => reject(reason));
7543
+ }
7412
7544
  });
7413
7545
  }
7546
+ /**
7547
+ * Retorna o resourceID da tela em questão.
7548
+ */
7414
7549
  async getResourceID() {
7415
7550
  return Promise.resolve(this.resourceID);
7416
7551
  }
7552
+ /**
7553
+ * Mostra o diálogo de alerta de acordo com os parâmetros passados.
7554
+ */
7417
7555
  async alert(title, message, icon, options) {
7418
7556
  return ApplicationUtils.alert(title, message, icon, options);
7419
7557
  }
7558
+ /**
7559
+ * Mostra o diálogo de erro de acordo com os parâmetros passados.
7560
+ */
7420
7561
  async error(title, message, icon, options) {
7421
7562
  return ApplicationUtils.error(title, message, icon, options);
7422
7563
  }
7564
+ /**
7565
+ * Exibe um diálogo de confirmação
7566
+ */
7423
7567
  async confirm(title, message, icon, critical, options) {
7424
7568
  return ApplicationUtils.confirm(title, message, icon, critical, options);
7425
7569
  }
7570
+ /**
7571
+ * Mostra uma informação efêmera (de segundo plano).
7572
+ */
7426
7573
  async info(message, options) {
7427
7574
  return ApplicationUtils.info(message, options);
7428
7575
  }
7576
+ /**
7577
+ * Busca a configuração de formulário.
7578
+ */
7429
7579
  async loadFormConfig(name) {
7430
7580
  return this.formConfigFetcher.loadFormConfig(name, this.resourceID);
7431
7581
  }
7432
- async loadGridConfig() {
7433
- return this.gridConfigFetcher.getConfig(this.resourceID);
7582
+ /**
7583
+ * Busca a configuração de grade.
7584
+ */
7585
+ async loadGridConfig(name) {
7586
+ return this.gridConfigFetcher.getConfig(name, this.resourceID);
7434
7587
  }
7588
+ /**
7589
+ * Salva a configuração de grade.
7590
+ */
7435
7591
  async saveGridConfig(config) {
7436
7592
  return this.gridConfigFetcher.saveConfig(config, this.resourceID);
7437
7593
  }
7594
+ async getAuthList(_auth) {
7595
+ return await (new MGEAuthorization()).parseFromJSON(_auth);
7596
+ }
7438
7597
  get urlParams() {
7439
7598
  if (!this._urlParams) {
7440
7599
  this._urlParams = UrlUtils.getQueryParams(location.search);
@@ -7512,7 +7671,7 @@ const SnkApplication = class {
7512
7671
  pesquisaContent.searchLoader = (text) => this.pesquisaFetcher.loadAdvancedSearch(ENTITYNAME, text, criteria, searchOptions);
7513
7672
  pesquisaContent.selectItem = (option) => {
7514
7673
  accept(option);
7515
- this.cleanPopUpTitle();
7674
+ this.clearPopUpTitle();
7516
7675
  this.closePopUp();
7517
7676
  };
7518
7677
  this.setPopUpTitle(DESCRIPTIONENTITY);
@@ -7529,11 +7688,18 @@ const SnkApplication = class {
7529
7688
  accept(window['isDebugMode']);
7530
7689
  });
7531
7690
  }
7532
- cleanPopUpTitle() {
7533
- this._popUp['ezTitle'] = "";
7691
+ clearPopUpContent() {
7692
+ if (this._popUp) {
7693
+ Array.from(this._popUp.children).forEach(c => {
7694
+ this._popUp.removeChild(c);
7695
+ });
7696
+ }
7697
+ }
7698
+ clearPopUpTitle() {
7699
+ this._popUp.ezTitle = "";
7534
7700
  }
7535
7701
  setPopUpTitle(title) {
7536
- this._popUp['ezTitle'] = title;
7702
+ this._popUp.ezTitle = title;
7537
7703
  }
7538
7704
  componentWillLoad() {
7539
7705
  this._errorHandler = new SnkErrorHandler(this);
@@ -7545,6 +7711,7 @@ const SnkApplication = class {
7545
7711
  ErrorTracking.init();
7546
7712
  }
7547
7713
  connectedCallback() {
7714
+ ApplicationContext.setContextValue("__SNK__APPLICATION__", this);
7548
7715
  DataFetcher.addRequestListener(this._requestListener);
7549
7716
  }
7550
7717
  disconnectedCallback() {
@@ -7583,6 +7750,12 @@ class RequestListenerLoadingBar {
7583
7750
  }
7584
7751
  ;
7585
7752
  }
7753
+ class PendingPromise {
7754
+ constructor(resolve, reject) {
7755
+ this.resolve = resolve;
7756
+ this.reject = reject;
7757
+ }
7758
+ }
7586
7759
  SnkApplication.style = snkApplicationCss;
7587
7760
 
7588
7761
  export { SnkApplication as snk_application };