@zeedhi/common 1.112.0 → 1.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/zd-common.esm.js +351 -156
  2. package/dist/zd-common.umd.js +352 -155
  3. package/package.json +2 -2
  4. package/types/components/zd-grid/grid-editable.d.ts +12 -0
  5. package/types/components/zd-input/input.d.ts +3 -1
  6. package/types/components/zd-input/interfaces.d.ts +2 -0
  7. package/types/components/zd-select/interfaces.d.ts +0 -1
  8. package/types/components/zd-select/select.d.ts +3 -3
  9. package/types/components/zd-select-tree/interfaces.d.ts +2 -1
  10. package/types/components/zd-select-tree/select-tree.d.ts +26 -3
  11. package/types/components/zd-select-tree-multiple/interfaces.d.ts +2 -0
  12. package/types/components/zd-select-tree-multiple/select-tree-multiple.d.ts +8 -6
  13. package/types/formatters/column-zdtextinput.d.ts +1 -0
  14. package/types/formatters/index.d.ts +1 -0
  15. package/types/utils/datasource-searcher/datasource-searcher.d.ts +7 -0
  16. package/types/utils/datasource-searcher/index.d.ts +2 -0
  17. package/types/utils/datasource-searcher/interfaces.d.ts +5 -0
  18. package/types/utils/index.d.ts +2 -0
  19. package/types/utils/report/report-type/base-report.d.ts +6 -2
  20. package/types/utils/report/report-type/csv-report.d.ts +2 -1
  21. package/types/utils/report/report-type/interfaces.d.ts +6 -2
  22. package/types/utils/report/report-type/pdf-report.d.ts +3 -1
  23. package/types/utils/report/report-type/xls-report.d.ts +2 -1
  24. package/types/utils/report/report-type/xls2-report.d.ts +2 -2
  25. package/types/utils/report/report-type/xls3-report.d.ts +2 -2
  26. package/types/utils/report/report.d.ts +0 -1
  27. package/types/utils/unique-by/index.d.ts +1 -0
  28. package/types/utils/unique-by/unique-by.d.ts +3 -0
  29. package/types/utils/unique-by.d.ts +3 -0
@@ -1923,6 +1923,7 @@
1923
1923
  this.internalDisplayValue = '';
1924
1924
  this.internalValue = null;
1925
1925
  this.formParent = this.getFormParent();
1926
+ this.grid = {};
1926
1927
  this.lastInputValue = '';
1927
1928
  this.callInputEvent = debounce__default["default"](({ event, element, component }) => {
1928
1929
  this.callEvent('input', { event, element, component });
@@ -1950,6 +1951,7 @@
1950
1951
  this.value = this.getInitValue('value', props.value, this.value);
1951
1952
  this.validations = this.getInitValue('validations', props.validations, this.validations);
1952
1953
  this.autoRegister = this.getInitValue('autoRegister', props.autoRegister, this.autoRegister);
1954
+ this.grid = this.getInitValue('grid', props.grid, this.grid);
1953
1955
  this.parseValidations(props.validations || {});
1954
1956
  if (this.autoRegister && this.formParent) {
1955
1957
  this.formParent.registerInput(this);
@@ -2838,7 +2840,7 @@
2838
2840
  return mask;
2839
2841
  }
2840
2842
  }
2841
- core.FormatterParserProvider.registerFormatter('ZdTextInput', (value, { valueWithPrefix = textInputDefaults.valueWithPrefix, prefix = textInputDefaults.prefix, valueWithSuffix = textInputDefaults.valueWithSuffix, suffix = textInputDefaults.suffix, mask = textInputDefaults.mask, } = {}) => {
2843
+ core.FormatterParserProvider.registerFormatter('ZdTextInput', (value, { valueWithPrefix = textInputDefaults.valueWithPrefix, prefix = textInputDefaults.prefix, valueWithSuffix = textInputDefaults.valueWithSuffix, suffix = textInputDefaults.suffix, mask = textInputDefaults.mask, eagerMask, } = {}) => {
2842
2844
  let formatted = value;
2843
2845
  if (formatted) {
2844
2846
  formatted = valueWithPrefix ? formatted.substring(prefix.length) : formatted;
@@ -2849,7 +2851,10 @@
2849
2851
  maskDef = core.Loader.getInstance(controller)[accessor];
2850
2852
  }
2851
2853
  const maskValue = typeof (maskDef) === 'function' ? maskDef(core.Mask.getValueWithoutMask(formatted)) : maskDef;
2852
- formatted = maskValue ? core.Mask.getValueWithMask(core.Mask.getValueWithoutMask(formatted), maskValue) : formatted;
2854
+ if (maskValue) {
2855
+ const valueWithoutMask = core.Mask.getValueWithoutMask(formatted);
2856
+ formatted = core.Mask.getValueWithMask(valueWithoutMask, maskValue, false, eagerMask);
2857
+ }
2853
2858
  }
2854
2859
  return formatted;
2855
2860
  });
@@ -3145,8 +3150,10 @@
3145
3150
  * Hides alert by index. Default index is 0
3146
3151
  */
3147
3152
  static hide(index = 0) {
3148
- this.alertsManager.visibleInstances[index].hide();
3149
- this.remove(index);
3153
+ if (this.alertsManager.visibleInstances[index]) {
3154
+ this.alertsManager.visibleInstances[index].hide();
3155
+ this.remove(index);
3156
+ }
3150
3157
  }
3151
3158
  /**
3152
3159
  * Hides alert by alert id (returned by the `show` method)
@@ -5860,7 +5867,24 @@
5860
5867
  && (!this.searchVisibleOnly || column.isVisible)
5861
5868
  && (this.searchIn === undefined || this.searchIn === column.name);
5862
5869
  }
5863
- }
5870
+ }
5871
+ core.Messages.add({
5872
+ 'pt-BR': {
5873
+ translation: {
5874
+ gridPageText: '{{firstRow}} - {{lastRow}} de {{total}}',
5875
+ },
5876
+ },
5877
+ 'en-US': {
5878
+ translation: {
5879
+ gridPageText: '{{firstRow}} - {{lastRow}} of {{total}}',
5880
+ },
5881
+ },
5882
+ 'es-CL': {
5883
+ translation: {
5884
+ gridPageText: '{{firstRow}} - {{lastRow}} de {{total}}',
5885
+ },
5886
+ },
5887
+ });
5864
5888
 
5865
5889
  /**
5866
5890
  * Delete rows error
@@ -7059,6 +7083,9 @@
7059
7083
  });
7060
7084
  }
7061
7085
  }
7086
+ /**
7087
+ * Retrieves the visible value of a cell, which is the corresponding cell in edited row or in the default row
7088
+ */
7062
7089
  getVisibleValue(row, column) {
7063
7090
  const key = row[this.datasource.uniqueKey];
7064
7091
  if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.valueIn)) {
@@ -7066,6 +7093,18 @@
7066
7093
  }
7067
7094
  return row[column.valueIn];
7068
7095
  }
7096
+ /**
7097
+ * Retrieves the visible values of a row
7098
+ * @param row
7099
+ * @returns
7100
+ */
7101
+ getVisibleRow(row) {
7102
+ const visibleRow = Object.assign({}, row);
7103
+ this.columns.forEach((column) => {
7104
+ visibleRow[column.valueIn] = this.getVisibleValue(row, column);
7105
+ });
7106
+ return visibleRow;
7107
+ }
7069
7108
  /**
7070
7109
  * Returns editable component properties based on the column definition
7071
7110
  * @param column Column definition
@@ -7161,6 +7200,15 @@
7161
7200
  delete this.invalidComponents[component.name];
7162
7201
  }
7163
7202
  }
7203
+ clearInvalidComponentsForRow(rowKey) {
7204
+ const cloneInvalidComponents = Object.assign({}, this.invalidComponents);
7205
+ Object.keys(cloneInvalidComponents).forEach((compName) => {
7206
+ if (compName.includes(`_editable_${rowKey}`)) {
7207
+ delete cloneInvalidComponents[compName];
7208
+ }
7209
+ });
7210
+ this.invalidComponents = cloneInvalidComponents;
7211
+ }
7164
7212
  /**
7165
7213
  * change event of editable components
7166
7214
  */
@@ -7272,6 +7320,7 @@
7272
7320
  delete cloneAddedRows[key];
7273
7321
  this.editedRows = cloneEditedRows;
7274
7322
  this.addedRows = cloneAddedRows;
7323
+ this.clearInvalidComponentsForRow(key);
7275
7324
  const { data, uniqueKey } = this.datasource;
7276
7325
  const index = data.findIndex((row) => row[uniqueKey] === key);
7277
7326
  data.splice(index, 1);
@@ -7285,6 +7334,8 @@
7285
7334
  for (let index = allData.length - 1; index >= 0; index -= 1) {
7286
7335
  const row = allData[index];
7287
7336
  if (this.addedRows[row[this.datasource.uniqueKey]]) {
7337
+ const key = row[this.datasource.uniqueKey];
7338
+ this.clearInvalidComponentsForRow(key);
7288
7339
  allData.splice(index, 1);
7289
7340
  }
7290
7341
  }
@@ -7305,13 +7356,17 @@
7305
7356
  saveEditedRows(revalidate = false) {
7306
7357
  return __awaiter(this, void 0, void 0, function* () {
7307
7358
  const { page } = this.datasource;
7359
+ // Verificar se o grid é válido antes de tentar salvar
7360
+ if (!this.isGridValid(revalidate)) {
7361
+ throw new Error('Invalid rows');
7362
+ }
7363
+ // Só cancelar as linhas adicionadas se todas forem válidas
7308
7364
  yield this.cancelAddedRows();
7309
- const response = yield Promise.all(this.getEditedRows(revalidate).map((row) => this.addDataRow(row)));
7365
+ const response = yield Promise.all(this.getEditedRows(revalidate, true).map((row) => this.addDataRow(row)));
7310
7366
  this.editing = false;
7311
7367
  this.editedRows = {};
7312
7368
  this.addedRows = {};
7313
7369
  this.invalidComponents = {};
7314
- this.addedRows = {};
7315
7370
  yield this.datasource.setPage(page);
7316
7371
  return response;
7317
7372
  });
@@ -7562,6 +7617,8 @@
7562
7617
  const rows = Object.assign({}, this.editedRows);
7563
7618
  delete rows[foundRow[uniqueKey]];
7564
7619
  this.editedRows = rows;
7620
+ const key = foundRow[uniqueKey];
7621
+ this.clearInvalidComponentsForRow(key);
7565
7622
  }
7566
7623
  /**
7567
7624
  * Makes the cell enter edit mode
@@ -8534,18 +8591,26 @@
8534
8591
  SUM: 'SUM',
8535
8592
  };
8536
8593
  this.colunmXLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
8594
+ this.labelFormatter = labelFormatter;
8537
8595
  this.reportColumnTransformer = this.getReportColumnTransformer(labelFormatter);
8538
8596
  }
8539
8597
  getReportColumnTransformer(labelFormatter) {
8540
8598
  return new ReportColumnTransformer({ labelFormatter, fileType: this.getFileType() });
8541
8599
  }
8600
+ getColumnLabel(key, column) {
8601
+ if (!column)
8602
+ return key;
8603
+ if (!this.labelFormatter)
8604
+ return column.label || key;
8605
+ return this.labelFormatter({ column, fileType: this.getFileType() });
8606
+ }
8542
8607
  buildFilter(filter, columns) {
8543
8608
  return Object.keys(filter).map((key) => {
8544
- var _a;
8545
- return ({
8546
- label: ((_a = columns.find((col) => col.name === key)) === null || _a === void 0 ? void 0 : _a.label) || key,
8609
+ const column = columns.find((col) => col.name === key);
8610
+ return {
8611
+ label: this.getColumnLabel(key, column),
8547
8612
  value: core.I18n.translate('IS_EQUAL', { value: filter[key] }),
8548
- });
8613
+ };
8549
8614
  });
8550
8615
  }
8551
8616
  formatLangCode(lang) {
@@ -8554,6 +8619,12 @@
8554
8619
  }
8555
8620
  return lang.toLowerCase().replace('-', '_');
8556
8621
  }
8622
+ filterColumns(columns) {
8623
+ return columns.filter((item) => (item.type !== 'action' && item.isVisible !== false));
8624
+ }
8625
+ buildCols(columns) {
8626
+ return this.reportColumnTransformer.transform(this.filterColumns(columns));
8627
+ }
8557
8628
  }
8558
8629
 
8559
8630
  class CSVReport extends BaseReport {
@@ -8564,8 +8635,9 @@
8564
8635
  getFileType() {
8565
8636
  return 'csv';
8566
8637
  }
8567
- buildDataset(data, columns) {
8568
- const columnNames = columns.map((col) => col.name);
8638
+ buildDataset({ data, columns }) {
8639
+ const filteredColumns = this.filterColumns(columns);
8640
+ const columnNames = filteredColumns.map((col) => col.name);
8569
8641
  const result = data.reduce((reduced, row) => {
8570
8642
  const values = columnNames.map((col) => row[col] || '');
8571
8643
  return [...reduced, values];
@@ -8573,7 +8645,7 @@
8573
8645
  return JSON.stringify(result);
8574
8646
  }
8575
8647
  buildMetadata(name, title, columns, filter) {
8576
- const builtCols = this.reportColumnTransformer.transform(columns);
8648
+ const builtCols = this.buildCols(columns);
8577
8649
  const builtFilters = this.buildFilter(filter || {}, columns);
8578
8650
  const lang = this.formatLangCode(core.I18n.instance.language);
8579
8651
  const clientLogo = '';
@@ -8617,7 +8689,7 @@
8617
8689
  const fileType = this.getFileType();
8618
8690
  return new ReportColumnTransformer({ getFormatFn, labelFormatter, fileType });
8619
8691
  }
8620
- buildDataset(data) {
8692
+ buildDataset({ data }) {
8621
8693
  return JSON.stringify(data);
8622
8694
  }
8623
8695
  getFormatOfColumn(column) {
@@ -8667,7 +8739,7 @@
8667
8739
  }
8668
8740
  buildMetadata(name, title, columns, filter, portrait = true) {
8669
8741
  return __awaiter(this, void 0, void 0, function* () {
8670
- const builtCols = this.reportColumnTransformer.transform(columns);
8742
+ const builtCols = this.buildCols(columns);
8671
8743
  const builtFilters = this.buildFilter(filter || {}, columns);
8672
8744
  const lang = this.formatLangCode(core.I18n.instance.language);
8673
8745
  let clientLogo = '';
@@ -8755,8 +8827,8 @@
8755
8827
  getFileType() {
8756
8828
  return 'xls';
8757
8829
  }
8758
- buildDataset(data, columns) {
8759
- const result = this.formatRawDataSet(data, columns);
8830
+ buildDataset({ data, columns }) {
8831
+ const result = this.formatRawDataSet(data, this.filterColumns(columns));
8760
8832
  return JSON.stringify(result);
8761
8833
  }
8762
8834
  // formata o dataset para o formato "cru" xls
@@ -8769,7 +8841,7 @@
8769
8841
  return result;
8770
8842
  }
8771
8843
  buildMetadata(name, title, columns, filter) {
8772
- const builtCols = this.reportColumnTransformer.transform(columns);
8844
+ const builtCols = this.buildCols(columns);
8773
8845
  const builtFilters = this.buildFilter(filter || {}, columns);
8774
8846
  const lang = this.formatLangCode(core.I18n.instance.language);
8775
8847
  const clientLogo = '';
@@ -8812,12 +8884,12 @@
8812
8884
  getFileType() {
8813
8885
  return 'xls';
8814
8886
  }
8815
- buildDataset(data, metadata) {
8887
+ buildDataset({ data, metadata }) {
8816
8888
  const result = this.formatDataSet(metadata, data);
8817
8889
  return JSON.stringify(result);
8818
8890
  }
8819
8891
  buildMetadata(name, title, columns, filter) {
8820
- const builtCols = this.reportColumnTransformer.transform(columns);
8892
+ const builtCols = this.buildCols(columns);
8821
8893
  const builtFilters = this.buildFilter(filter || {}, columns);
8822
8894
  const lang = this.formatLangCode(core.I18n.instance.language);
8823
8895
  const clientLogo = '';
@@ -9012,12 +9084,12 @@
9012
9084
  getFileType() {
9013
9085
  return 'xls';
9014
9086
  }
9015
- buildDataset(data, metadata) {
9087
+ buildDataset({ data, metadata }) {
9016
9088
  const result = this.formatDataSet(metadata, data);
9017
9089
  return JSON.stringify(result);
9018
9090
  }
9019
9091
  buildMetadata(name, title, columns, filter) {
9020
- const builtCols = this.reportColumnTransformer.transform(columns);
9092
+ const builtCols = this.buildCols(columns);
9021
9093
  const builtFilters = this.buildFilter(filter || {}, columns);
9022
9094
  const lang = this.formatLangCode(core.I18n.instance.language);
9023
9095
  const clientLogo = '';
@@ -9337,21 +9409,20 @@
9337
9409
  const { route } = reportType;
9338
9410
  const { name, columns, datasource } = this.iterable;
9339
9411
  const { groupedData } = Object.assign({}, this.iterable);
9340
- const formattedColumns = this.filterColumns(columns);
9341
- const metadataObj = yield reportType.buildMetadata(name, this.title, formattedColumns, datasource.filter, portrait);
9412
+ const metadataObj = yield reportType.buildMetadata(name, this.title, columns, datasource.filter, portrait);
9342
9413
  let dataset;
9343
9414
  if ((reportType instanceof XLS2Report || reportType instanceof XLS3Report) && groupedData) {
9344
9415
  const rowMetadata = rowObj.metaData;
9345
9416
  const metadataObjClone = merge__default["default"](rowMetadata, JSON.parse(metadataObj));
9346
- dataset = reportType.buildDataset(groupedData, metadataObjClone);
9417
+ dataset = reportType.buildDataset({ data: groupedData, metadata: metadataObjClone });
9347
9418
  }
9348
9419
  else if (reportType instanceof PDFReport && groupedData && groupedData.length > 0) {
9349
9420
  const formatter = new GroupedPDFFormatter();
9350
9421
  const pdfGroupedData = formatter.format(groupedData);
9351
- dataset = reportType.buildDataset(pdfGroupedData);
9422
+ dataset = reportType.buildDataset({ data: pdfGroupedData });
9352
9423
  }
9353
9424
  else {
9354
- dataset = reportType.buildDataset(data, formattedColumns);
9425
+ dataset = reportType.buildDataset({ data, metadata: metadataObj, columns });
9355
9426
  }
9356
9427
  const filter = '[]';
9357
9428
  let row = {
@@ -9380,9 +9451,6 @@
9380
9451
  return new URL(reportFile, this.fileEndPoint).href;
9381
9452
  });
9382
9453
  }
9383
- filterColumns(columns) {
9384
- return columns.filter((item) => (item.type !== 'action' && item.isVisible));
9385
- }
9386
9454
  }
9387
9455
 
9388
9456
  class TreeDataStructure {
@@ -9838,6 +9906,77 @@
9838
9906
  }
9839
9907
  }
9840
9908
 
9909
+ class DatasourceSearcher {
9910
+ constructor() {
9911
+ this.dsSearch = {
9912
+ SEARCH: (value, searchIn) => ({
9913
+ searchIn: [searchIn],
9914
+ search: String(value || ''),
9915
+ }),
9916
+ FILTER: (value, searchIn) => ({
9917
+ filter: {
9918
+ [searchIn]: value,
9919
+ },
9920
+ }),
9921
+ FIND: (value, searchIn) => ({
9922
+ find: {
9923
+ [searchIn]: value,
9924
+ },
9925
+ }),
9926
+ DYNAMIC_FILTER: (value, search_in) => {
9927
+ const arrayValue = Array.isArray(value) ? value : Array.of(value);
9928
+ const filter = arrayValue.map((item) => ({ operation: 'EQUALS', relation: 'OR', value: item }));
9929
+ const dynamicFilter = { [search_in]: filter };
9930
+ return { dynamicFilter };
9931
+ },
9932
+ };
9933
+ }
9934
+ search(datasource, searchValue, searchIn, searchParam) {
9935
+ return __awaiter(this, void 0, void 0, function* () {
9936
+ // using filter/find/dynamicFilter should make only 1 request
9937
+ // using normal search should make one request per search value
9938
+ if (!Array.isArray(searchValue)) {
9939
+ return this.searchRequest(datasource, searchValue, searchIn, searchParam);
9940
+ }
9941
+ if (searchParam !== 'SEARCH') {
9942
+ const items = yield this.searchRequest(datasource, searchValue, searchIn, searchParam);
9943
+ return items;
9944
+ }
9945
+ const searchedItems = [];
9946
+ const promises = searchValue.map((value) => __awaiter(this, void 0, void 0, function* () {
9947
+ const [item] = yield this.searchRequest(datasource, value, searchIn, searchParam);
9948
+ searchedItems.push(item);
9949
+ }));
9950
+ yield Promise.all(promises);
9951
+ return searchedItems;
9952
+ });
9953
+ }
9954
+ searchRequest(datasource, searchValue, searchIn, searchParam) {
9955
+ return __awaiter(this, void 0, void 0, function* () {
9956
+ const config = Object.assign(Object.assign(Object.assign({}, datasource.clone()), this.dsSearch[searchParam](searchValue, searchIn)), { lazyLoad: true, loadAll: Array.isArray(searchValue) });
9957
+ const cloneDatasource = core.DatasourceFactory.factory(config);
9958
+ const items = yield cloneDatasource.get();
9959
+ cloneDatasource.destroy();
9960
+ if (Array.isArray(searchValue)) {
9961
+ return items.filter((item) => searchValue.includes(item[searchIn]));
9962
+ }
9963
+ return items.filter((row) => row[searchIn] === searchValue);
9964
+ });
9965
+ }
9966
+ }
9967
+
9968
+ const uniqueBy = (a, key) => {
9969
+ const seen = {};
9970
+ return a.filter((item) => {
9971
+ const k = item[key] || JSON.stringify(item);
9972
+ if (!seen[k]) {
9973
+ seen[k] = true;
9974
+ return true;
9975
+ }
9976
+ return false;
9977
+ });
9978
+ };
9979
+
9841
9980
  /**
9842
9981
  * Base class for Select component.
9843
9982
  */
@@ -10128,18 +10267,13 @@
10128
10267
  * Finds and retrieves items searching by value
10129
10268
  * @param value Default value
10130
10269
  */
10131
- getItemsBySearchValue(value, searchIn) {
10270
+ getItemsBySearchValue(value) {
10132
10271
  return __awaiter(this, void 0, void 0, function* () {
10133
- const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true, loadAll: Array.isArray(value) });
10134
10272
  this.datasource.loading = true;
10135
- const datasource = core.DatasourceFactory.factory(config);
10136
- const items = yield datasource.get();
10273
+ const datasourceSearcher = new DatasourceSearcher();
10274
+ const result = yield datasourceSearcher.search(this.datasource, value, this.dataValue, this.searchParam);
10137
10275
  this.datasource.loading = false;
10138
- datasource.destroy();
10139
- if (Array.isArray(value)) {
10140
- return items.filter((item) => value.includes(item[this.dataValue]));
10141
- }
10142
- return items.filter(this.getCondition(value));
10276
+ return result;
10143
10277
  });
10144
10278
  }
10145
10279
  getCondition(filterValue) {
@@ -10164,17 +10298,6 @@
10164
10298
  this.updateSearch(this.dirtySearchValue);
10165
10299
  });
10166
10300
  }
10167
- uniqueBy(a, key) {
10168
- const seen = {};
10169
- return a.filter((item) => {
10170
- const k = item[key] || JSON.stringify(item);
10171
- if (!seen[k]) {
10172
- seen[k] = true;
10173
- return true;
10174
- }
10175
- return false;
10176
- });
10177
- }
10178
10301
  afterLoad() {
10179
10302
  if (this.manualMode)
10180
10303
  return;
@@ -10240,11 +10363,10 @@
10240
10363
  else {
10241
10364
  filterValue = value;
10242
10365
  }
10243
- const searchIn = this.dataValue;
10244
10366
  const foundInData = this.datasource.data.find(this.getCondition(filterValue));
10245
10367
  let searchValue = foundInData;
10246
10368
  if (!foundInData && !this.manualMode) {
10247
- [searchValue] = yield this.getItemsBySearchValue(filterValue, searchIn);
10369
+ [searchValue] = yield this.getItemsBySearchValue(filterValue);
10248
10370
  }
10249
10371
  if (!searchValue) {
10250
10372
  this.setFieldRowValue(null);
@@ -10542,7 +10664,7 @@
10542
10664
  });
10543
10665
  }
10544
10666
  }
10545
- core.FormatterParserProvider.registerFormatter('ZdSelect', (value, { dataText, dataTextSeparator = ' | ', }) => {
10667
+ core.FormatterParserProvider.registerFormatter('ZdSelect', (value, { dataText, dataTextSeparator = ' | ', eagerMask, }) => {
10546
10668
  if (value === null || value === undefined) {
10547
10669
  return null;
10548
10670
  }
@@ -10574,7 +10696,7 @@
10574
10696
  let masked = value[column];
10575
10697
  if (masks[index]) {
10576
10698
  const maskValue = typeof masks[index] === 'function' ? masks[index](value[column]) : masks[index];
10577
- masked = core.Mask.getValueWithMask(value[column], maskValue);
10699
+ masked = core.Mask.getValueWithMask(value[column], maskValue, false, eagerMask);
10578
10700
  }
10579
10701
  return result + separator + masked;
10580
10702
  }
@@ -10877,15 +10999,12 @@
10877
10999
  this.createAccessors();
10878
11000
  }
10879
11001
  addSlashes(value) {
10880
- if (typeof value === 'string') {
10881
- return value.replace(/\\/g, '\\\\')
10882
- .replace(/\t/g, '\\t')
10883
- .replace(/\n/g, '\\n')
10884
- .replace(/\f/g, '\\f')
10885
- .replace(/\r/g, '\\r')
10886
- .replace(/"/g, '\\"');
10887
- }
10888
- return value;
11002
+ return value.replace(/\\/g, '\\\\')
11003
+ .replace(/\t/g, '\\t')
11004
+ .replace(/\n/g, '\\n')
11005
+ .replace(/\f/g, '\\f')
11006
+ .replace(/\r/g, '\\r')
11007
+ .replace(/"/g, '\\"');
10889
11008
  }
10890
11009
  /**
10891
11010
  * Returns the iterable component metadata based on row data
@@ -10898,14 +11017,13 @@
10898
11017
  .replace(rowExp, JSON.stringify(row))
10899
11018
  .replace(exp, (match) => {
10900
11019
  const propPath = match.replace(/<<|>>|"/g, '').split('.').splice(1).join('.');
10901
- const value = this.addSlashes(get__default["default"](row, propPath));
11020
+ let value = get__default["default"](row, propPath);
11021
+ if (value === undefined || value === null)
11022
+ value = '';
10902
11023
  if (typeof value === 'string') {
10903
- if (match.startsWith('"') && match.endsWith('"'))
10904
- return `"${value}"`;
10905
- return value;
11024
+ const escaped = this.addSlashes(value);
11025
+ return match.startsWith('"') && match.endsWith('"') ? `"${escaped}"` : escaped;
10906
11026
  }
10907
- if (value === undefined)
10908
- return '""';
10909
11027
  return value;
10910
11028
  });
10911
11029
  return JSON.parse(metadata);
@@ -12185,7 +12303,8 @@
12185
12303
  }
12186
12304
  }
12187
12305
  return value;
12188
- });
12306
+ });
12307
+ InputFactory.register('ZdMonth', Month);
12189
12308
 
12190
12309
  /**
12191
12310
  * Base class for Password component.
@@ -12582,19 +12701,10 @@
12582
12701
  this.insertedValues.push(item);
12583
12702
  pushed = true;
12584
12703
  });
12585
- // using filter/find/dynamicFilter should make only 1 request
12586
- // using normal search should make one request per search value
12587
- if (this.searchParam !== 'SEARCH') {
12588
- const items = yield this.getItemsBySearchValue(searchedValues, this.dataValue);
12704
+ if (searchedValues.length) {
12705
+ const items = yield this.getItemsBySearchValue(searchedValues);
12589
12706
  items.forEach(insertItem);
12590
12707
  }
12591
- else {
12592
- const promises = searchedValues.map((searchedValue) => __awaiter(this, void 0, void 0, function* () {
12593
- const [item] = yield this.getItemsBySearchValue(searchedValue, this.dataValue);
12594
- insertItem(item);
12595
- }));
12596
- yield Promise.all(promises);
12597
- }
12598
12708
  if (foundValues.length > 0) {
12599
12709
  this.setFieldRowValue(foundValues);
12600
12710
  }
@@ -12832,7 +12942,7 @@
12832
12942
  if (this.manualMode)
12833
12943
  return;
12834
12944
  if (this.insertedValues.length) {
12835
- this.datasource.data = this.uniqueBy(this.insertedValues.concat(this.datasource.data), this.datasource.uniqueKey);
12945
+ this.datasource.data = uniqueBy(this.insertedValues.concat(this.datasource.data), this.datasource.uniqueKey);
12836
12946
  const values = this.insertedValues.map((inserted) => inserted[this.dataValue]);
12837
12947
  // prevent caching insertedValues
12838
12948
  this.cachedData = this.datasource.data.filter((row) => !values.includes(row[this.dataValue]));
@@ -12975,7 +13085,8 @@
12975
13085
  return formattedRow;
12976
13086
  });
12977
13087
  return formattedValue;
12978
- });
13088
+ });
13089
+ InputFactory.register('ZdSelectMultiple', SelectMultiple);
12979
13090
 
12980
13091
  /**
12981
13092
  * Base class for Select Tree component.
@@ -13066,6 +13177,7 @@
13066
13177
  * Defines if should wait and not execute GET method when Datasource is created
13067
13178
  */
13068
13179
  this.lazyLoad = true;
13180
+ this.selectValue = null;
13069
13181
  /**
13070
13182
  * Uses delayed loading to load tree branches
13071
13183
  */
@@ -13087,6 +13199,10 @@
13087
13199
  */
13088
13200
  this.dataValueOutFormName = '';
13089
13201
  this.formatterFn = core.FormatterParserProvider.getFormatter('ZdSelectTree');
13202
+ /**
13203
+ * Defines if data handling should be manual or automatic
13204
+ */
13205
+ this.searchParam = 'SEARCH';
13090
13206
  this.savedNodes = undefined;
13091
13207
  this.search = '';
13092
13208
  this.debounceSearch = debounce__default["default"](this.searchChange, 500);
@@ -13114,6 +13230,7 @@
13114
13230
  this.autoSelection = this.getInitValue('autoSelection', props.autoSelection, this.autoSelection);
13115
13231
  this.dataValueOut = this.getInitValue('dataValueOut', props.dataValueOut, this.dataValueOut);
13116
13232
  this.dataValueOutFormName = this.getInitValue('dataValueOutFormName', props.dataValueOutFormName, this.dataValueOutFormName);
13233
+ this.searchParam = this.getInitValue('searchParam', props.searchParam, this.searchParam);
13117
13234
  if (props.datasource && Object.keys(props.datasource).length) {
13118
13235
  this.lazyLoad = props.datasource.lazyLoad !== false;
13119
13236
  const searchFields = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
@@ -13183,6 +13300,9 @@
13183
13300
  this.nodes = this.createChildrenNodes(firstLevelNodes);
13184
13301
  }
13185
13302
  }
13303
+ /**
13304
+ * Creates a Tree Node from a datasource row
13305
+ */
13186
13306
  createNodeFromRow(row) {
13187
13307
  let children;
13188
13308
  if (this.fetchOnDemand && !this.datasource.search) {
@@ -13322,31 +13442,71 @@
13322
13442
  });
13323
13443
  return result;
13324
13444
  }
13445
+ clearNodeRow(row) {
13446
+ return this.clearRow(row.row || row);
13447
+ }
13448
+ /**
13449
+ * Finds and retrieves items searching by value
13450
+ * @param value Default value
13451
+ */
13452
+ getItemsBySearchValue(value) {
13453
+ return __awaiter(this, void 0, void 0, function* () {
13454
+ this.datasource.loading = true;
13455
+ const datasourceSearcher = new DatasourceSearcher();
13456
+ const result = yield datasourceSearcher.search(this.datasource, value, this.dataValue, this.searchParam);
13457
+ this.datasource.loading = false;
13458
+ return result;
13459
+ });
13460
+ }
13325
13461
  get value() {
13326
13462
  if (!this.selectValue)
13327
13463
  return this.selectValue;
13328
13464
  if (this.returnObject) {
13329
- return this.clearRow(this.selectValue.row || this.selectValue);
13465
+ return this.clearNodeRow(this.selectValue);
13330
13466
  }
13331
- return this.selectValue;
13467
+ const key = this.datasource ? this.dataValue : 'id';
13468
+ return this.selectValue[key];
13332
13469
  }
13333
13470
  set value(value) {
13334
13471
  this.setValue(value);
13335
13472
  }
13336
13473
  setValue(value) {
13337
- let val = value;
13338
- const key = this.datasource ? this.dataValue : 'id';
13339
- if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
13340
- val = value[key];
13341
- }
13342
- else if (!value && value !== 0) {
13343
- val = null;
13344
- }
13345
- if (this.returnObject) {
13346
- this.selectValue = val ? { id: val } : null;
13347
- return;
13348
- }
13349
- this.selectValue = val;
13474
+ return __awaiter(this, void 0, void 0, function* () {
13475
+ let val = null;
13476
+ const key = this.datasource ? this.dataValue : 'id';
13477
+ if (!value && value !== 0) {
13478
+ val = null;
13479
+ }
13480
+ else if (typeof value === 'object') {
13481
+ val = value[key];
13482
+ }
13483
+ else {
13484
+ val = value;
13485
+ }
13486
+ if (!val) {
13487
+ this.selectValue = null;
13488
+ return;
13489
+ }
13490
+ if (!this.datasource) {
13491
+ this.selectValue = { id: val };
13492
+ return;
13493
+ }
13494
+ const searchIn = this.dataValue;
13495
+ const foundInData = this.datasource.data.find((row) => row[searchIn] === val);
13496
+ let foundValue = foundInData;
13497
+ if (!foundInData) {
13498
+ [foundValue] = yield this.getItemsBySearchValue(val);
13499
+ }
13500
+ if (!foundValue) {
13501
+ if (typeof value === 'object') {
13502
+ this.selectValue = Object.assign({ id: val }, value);
13503
+ return;
13504
+ }
13505
+ this.selectValue = { id: val };
13506
+ return;
13507
+ }
13508
+ this.selectValue = foundValue;
13509
+ });
13350
13510
  }
13351
13511
  loadChildren(parentNode) {
13352
13512
  return __awaiter(this, void 0, void 0, function* () {
@@ -13399,6 +13559,7 @@
13399
13559
  * Selected Nodes
13400
13560
  */
13401
13561
  this.selectedNodes = [];
13562
+ this.selectValue = [];
13402
13563
  /**
13403
13564
  * Changes the behavior of checked nodes that will be displayed in the array of values
13404
13565
  */
@@ -13417,7 +13578,9 @@
13417
13578
  * Triggered after selected nodes change
13418
13579
  */
13419
13580
  changeSelectedNodes(selectedNodes, element) {
13420
- this.callEvent('onChangeSelectedNodes', { element, component: this, selectedNodes });
13581
+ const selection = this.returnObject
13582
+ ? selectedNodes.map((value) => this.clearNodeRow(value)) : selectedNodes.map((node) => node.id);
13583
+ this.callEvent('onChangeSelectedNodes', { element, component: this, selectedNodes: selection });
13421
13584
  }
13422
13585
  /**
13423
13586
  * Triggered deselecting an node
@@ -13429,34 +13592,58 @@
13429
13592
  if (!this.selectValue)
13430
13593
  return [];
13431
13594
  if (this.returnObject) {
13432
- return this.selectValue.map((value) => this.clearRow(value.row || value));
13595
+ return this.selectValue.map((value) => this.clearNodeRow(value));
13433
13596
  }
13434
- return this.selectValue;
13597
+ const key = this.datasource ? this.dataValue : 'id';
13598
+ return this.selectValue.map((item) => item[key]);
13435
13599
  }
13436
13600
  set value(value) {
13437
13601
  this.setValue(value);
13438
13602
  }
13439
13603
  setValue(value) {
13440
- if (!value) {
13441
- this.selectValue = [];
13442
- return;
13443
- }
13444
- const arrValue = Array.isArray(value) ? value : [value];
13445
- const key = this.datasource ? this.dataValue : 'id';
13446
- if (!this.returnObject) {
13447
- this.selectValue = arrValue.map((item) => {
13604
+ return __awaiter(this, void 0, void 0, function* () {
13605
+ if (!value) {
13606
+ this.selectValue = [];
13607
+ return;
13608
+ }
13609
+ const arrValue = Array.isArray(value) ? value : [value];
13610
+ const key = this.datasource ? this.dataValue : 'id';
13611
+ if (!this.datasource) {
13612
+ this.selectValue = arrValue.map((item) => {
13613
+ if (item && typeof item === 'object') {
13614
+ return item;
13615
+ }
13616
+ return { [key]: item };
13617
+ });
13618
+ return;
13619
+ }
13620
+ const valuesToSearch = [];
13621
+ const foundValues = [];
13622
+ const insertItem = (item) => __awaiter(this, void 0, void 0, function* () {
13623
+ if (!item)
13624
+ return;
13625
+ foundValues.push(item);
13626
+ });
13627
+ arrValue.forEach((item) => __awaiter(this, void 0, void 0, function* () {
13628
+ const searchIn = this.dataValue;
13629
+ if (!item)
13630
+ return;
13448
13631
  if (typeof item === 'object') {
13449
- return item[key];
13632
+ insertItem(item);
13633
+ return;
13450
13634
  }
13451
- return item;
13452
- });
13453
- return;
13454
- }
13455
- this.selectValue = arrValue.map((item) => {
13456
- if (typeof item !== 'object') {
13457
- return { id: item };
13635
+ const foundInData = this.datasource.data.find((row) => row[searchIn] === item);
13636
+ if (!foundInData) {
13637
+ valuesToSearch.push(item);
13638
+ return;
13639
+ }
13640
+ insertItem(foundInData);
13641
+ }));
13642
+ if (valuesToSearch.length) {
13643
+ const items = yield this.getItemsBySearchValue(valuesToSearch);
13644
+ items.forEach(insertItem);
13458
13645
  }
13459
- return { id: item[key] };
13646
+ this.selectValue = foundValues;
13460
13647
  });
13461
13648
  }
13462
13649
  /**
@@ -13504,16 +13691,18 @@
13504
13691
  */
13505
13692
  selectAllItems(nodes = this.nodes) {
13506
13693
  var _a;
13507
- if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13508
- this.setValue(this.datasource.data);
13509
- return;
13510
- }
13511
- const allNodes = this.getAllNodes(nodes, !this.search);
13512
- // merge all nodes with the current value before setting it
13513
- const currentValue = this.getValueAsObject();
13514
- const nodeMap = this.createMergeMap(currentValue, allNodes);
13515
- const uniqueArray = Array.from(nodeMap.values());
13516
- this.setValue(uniqueArray);
13694
+ return __awaiter(this, void 0, void 0, function* () {
13695
+ if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13696
+ yield this.setValue(this.datasource.data);
13697
+ return;
13698
+ }
13699
+ const allNodes = this.getAllNodes(nodes, !this.search);
13700
+ // merge all nodes with the current value before setting it
13701
+ const currentValue = this.getValueAsObject();
13702
+ const nodeMap = this.createMergeMap(currentValue, allNodes);
13703
+ const uniqueArray = Array.from(nodeMap.values());
13704
+ yield this.setValue(uniqueArray);
13705
+ });
13517
13706
  }
13518
13707
  /**
13519
13708
  * Unelects all items in the tree \
@@ -13525,21 +13714,23 @@
13525
13714
  */
13526
13715
  unSelectAllItems(nodes = this.nodes) {
13527
13716
  var _a;
13528
- if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13529
- this.setValue([]);
13530
- return;
13531
- }
13532
- const allNodes = this.getAllNodes(nodes, !this.search);
13533
- // merge all nodes with the current value before setting it
13534
- const currentValue = this.getValueAsObject();
13535
- const nodeMap = this.createMergeMap(currentValue);
13536
- // remove the current visible nodes from the array
13537
- const valuesToRemove = allNodes.map((node) => node.id);
13538
- valuesToRemove.forEach((value) => {
13539
- nodeMap.delete(value);
13717
+ return __awaiter(this, void 0, void 0, function* () {
13718
+ if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13719
+ yield this.setValue([]);
13720
+ return;
13721
+ }
13722
+ const allNodes = this.getAllNodes(nodes, !this.search);
13723
+ // merge all nodes with the current value before setting it
13724
+ const currentValue = this.getValueAsObject();
13725
+ const nodeMap = this.createMergeMap(currentValue);
13726
+ // remove the current visible nodes from the array
13727
+ const valuesToRemove = allNodes.map((node) => node.id);
13728
+ valuesToRemove.forEach((value) => {
13729
+ nodeMap.delete(value);
13730
+ });
13731
+ const uniqueArray = Array.from(nodeMap.values());
13732
+ yield this.setValue(uniqueArray);
13540
13733
  });
13541
- const uniqueArray = Array.from(nodeMap.values());
13542
- this.setValue(uniqueArray);
13543
13734
  }
13544
13735
  /**
13545
13736
  * Takes two arrays and creates a map of the unique values
@@ -13561,15 +13752,15 @@
13561
13752
  return this.value;
13562
13753
  }
13563
13754
  getValueAsObject() {
13564
- return this.value.map((row) => {
13565
- if (this.returnObject)
13566
- return row;
13567
- return { id: row };
13755
+ return this.selectValue.map((row) => {
13756
+ const key = this.datasource ? this.dataValue : 'id';
13757
+ return Object.assign({ id: row[key] }, row);
13568
13758
  });
13569
13759
  }
13570
13760
  }
13571
13761
  const selectFormatterFn = core.FormatterParserProvider.getFormatter('ZdSelectMultiple');
13572
- core.FormatterParserProvider.registerFormatter('ZdSelectTreeMultiple', selectFormatterFn);
13762
+ core.FormatterParserProvider.registerFormatter('ZdSelectTreeMultiple', selectFormatterFn);
13763
+ InputFactory.register('ZdSelectTreeMultiple', SelectTreeMultiple);
13573
13764
 
13574
13765
  /**
13575
13766
  * Base class for SelectableList component.
@@ -15994,7 +16185,7 @@
15994
16185
  }
15995
16186
  return row;
15996
16187
  };
15997
- const formatter$1 = ({ column, value, row, componentProps, }) => {
16188
+ const formatter$2 = ({ column, value, row, componentProps, }) => {
15998
16189
  if (value === null || value === undefined)
15999
16190
  return '';
16000
16191
  const { dataText, formatterDataText, dataTextSeparator, dataValue, dataTextDiscrete, foreignColumns, } = componentProps;
@@ -16025,12 +16216,12 @@
16025
16216
  return currentRow[textColumn] || value;
16026
16217
  }
16027
16218
  const formatterFn = core.FormatterParserProvider.getFormatter('ZdSelect');
16028
- return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator });
16219
+ return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator, eagerMask: false });
16029
16220
  };
16030
- core.FormatterParserProvider.registerFormatter('column_ZdSelect', formatter$1);
16031
- core.FormatterParserProvider.registerFormatter('column_ZdSelectTree', formatter$1);
16221
+ core.FormatterParserProvider.registerFormatter('column_ZdSelect', formatter$2);
16222
+ core.FormatterParserProvider.registerFormatter('column_ZdSelectTree', formatter$2);
16032
16223
 
16033
- const formatter = ({ column, value, row, componentProps, }) => {
16224
+ const formatter$1 = ({ column, value, row, componentProps, }) => {
16034
16225
  if (!value || !Array.isArray(value) || value.length === 0)
16035
16226
  return '';
16036
16227
  const { formatterDataText, foreignColumns, dataText } = componentProps;
@@ -16068,8 +16259,12 @@
16068
16259
  });
16069
16260
  return result.join(', ');
16070
16261
  };
16071
- core.FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', formatter);
16072
- core.FormatterParserProvider.registerFormatter('column_ZdSelectTreeMultiple', formatter);
16262
+ core.FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', formatter$1);
16263
+ core.FormatterParserProvider.registerFormatter('column_ZdSelectTreeMultiple', formatter$1);
16264
+
16265
+ const defaultFormatter = core.FormatterParserProvider.getFormatter('ZdTextInput');
16266
+ const formatter = ({ value, componentProps, }) => defaultFormatter(value, Object.assign(Object.assign({}, componentProps), { eagerMask: false }));
16267
+ core.FormatterParserProvider.registerFormatter('column_ZdTextInput', formatter);
16073
16268
 
16074
16269
  const AutoNumeric = require('@zeedhi/autonumeric/dist/autoNumeric');
16075
16270
  const packageContent = require('../package.json');
@@ -16101,6 +16296,7 @@
16101
16296
  exports.Currency = Currency;
16102
16297
  exports.Dashboard = Dashboard;
16103
16298
  exports.DataValueOutHelper = DataValueOutHelper;
16299
+ exports.DatasourceSearcher = DatasourceSearcher;
16104
16300
  exports.Date = Date$1;
16105
16301
  exports.DateRange = DateRange;
16106
16302
  exports.Dialog = Dialog;
@@ -16187,6 +16383,7 @@
16187
16383
  exports.XLS3Report = XLS3Report;
16188
16384
  exports.XLSReport = XLSReport;
16189
16385
  exports.initTheme = initTheme;
16386
+ exports.uniqueBy = uniqueBy;
16190
16387
 
16191
16388
  Object.defineProperty(exports, '__esModule', { value: true });
16192
16389