@zeedhi/common 1.113.0 → 1.115.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.
@@ -1916,6 +1916,7 @@ class Input extends ComponentRender {
1916
1916
  this.internalDisplayValue = '';
1917
1917
  this.internalValue = null;
1918
1918
  this.formParent = this.getFormParent();
1919
+ this.grid = {};
1919
1920
  this.lastInputValue = '';
1920
1921
  this.callInputEvent = debounce(({ event, element, component }) => {
1921
1922
  this.callEvent('input', { event, element, component });
@@ -1943,6 +1944,7 @@ class Input extends ComponentRender {
1943
1944
  this.value = this.getInitValue('value', props.value, this.value);
1944
1945
  this.validations = this.getInitValue('validations', props.validations, this.validations);
1945
1946
  this.autoRegister = this.getInitValue('autoRegister', props.autoRegister, this.autoRegister);
1947
+ this.grid = this.getInitValue('grid', props.grid, this.grid);
1946
1948
  this.parseValidations(props.validations || {});
1947
1949
  if (this.autoRegister && this.formParent) {
1948
1950
  this.formParent.registerInput(this);
@@ -4432,6 +4434,9 @@ class DateRange extends TextInput {
4432
4434
  userAppendIconClick({ event, element, component });
4433
4435
  }
4434
4436
  };
4437
+ if (this.value && Array.isArray(this.value)) {
4438
+ this.internalDisplayValue = this.formatter(this.value);
4439
+ }
4435
4440
  }
4436
4441
  /**
4437
4442
  * Character that will separate the two dates
@@ -5858,7 +5863,24 @@ class Iterable extends ComponentRender {
5858
5863
  && (!this.searchVisibleOnly || column.isVisible)
5859
5864
  && (this.searchIn === undefined || this.searchIn === column.name);
5860
5865
  }
5861
- }
5866
+ }
5867
+ Messages.add({
5868
+ 'pt-BR': {
5869
+ translation: {
5870
+ gridPageText: '{{firstRow}} - {{lastRow}} de {{total}}',
5871
+ },
5872
+ },
5873
+ 'en-US': {
5874
+ translation: {
5875
+ gridPageText: '{{firstRow}} - {{lastRow}} of {{total}}',
5876
+ },
5877
+ },
5878
+ 'es-CL': {
5879
+ translation: {
5880
+ gridPageText: '{{firstRow}} - {{lastRow}} de {{total}}',
5881
+ },
5882
+ },
5883
+ });
5862
5884
 
5863
5885
  /**
5864
5886
  * Delete rows error
@@ -7057,6 +7079,9 @@ class GridEditable extends Grid {
7057
7079
  });
7058
7080
  }
7059
7081
  }
7082
+ /**
7083
+ * Retrieves the visible value of a cell, which is the corresponding cell in edited row or in the default row
7084
+ */
7060
7085
  getVisibleValue(row, column) {
7061
7086
  const key = row[this.datasource.uniqueKey];
7062
7087
  if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.valueIn)) {
@@ -7064,6 +7089,18 @@ class GridEditable extends Grid {
7064
7089
  }
7065
7090
  return row[column.valueIn];
7066
7091
  }
7092
+ /**
7093
+ * Retrieves the visible values of a row
7094
+ * @param row
7095
+ * @returns
7096
+ */
7097
+ getVisibleRow(row) {
7098
+ const visibleRow = Object.assign({}, row);
7099
+ this.columns.forEach((column) => {
7100
+ visibleRow[column.valueIn] = this.getVisibleValue(row, column);
7101
+ });
7102
+ return visibleRow;
7103
+ }
7067
7104
  /**
7068
7105
  * Returns editable component properties based on the column definition
7069
7106
  * @param column Column definition
@@ -7159,6 +7196,15 @@ class GridEditable extends Grid {
7159
7196
  delete this.invalidComponents[component.name];
7160
7197
  }
7161
7198
  }
7199
+ clearInvalidComponentsForRow(rowKey) {
7200
+ const cloneInvalidComponents = Object.assign({}, this.invalidComponents);
7201
+ Object.keys(cloneInvalidComponents).forEach((compName) => {
7202
+ if (compName.includes(`_editable_${rowKey}`)) {
7203
+ delete cloneInvalidComponents[compName];
7204
+ }
7205
+ });
7206
+ this.invalidComponents = cloneInvalidComponents;
7207
+ }
7162
7208
  /**
7163
7209
  * change event of editable components
7164
7210
  */
@@ -7270,6 +7316,7 @@ class GridEditable extends Grid {
7270
7316
  delete cloneAddedRows[key];
7271
7317
  this.editedRows = cloneEditedRows;
7272
7318
  this.addedRows = cloneAddedRows;
7319
+ this.clearInvalidComponentsForRow(key);
7273
7320
  const { data, uniqueKey } = this.datasource;
7274
7321
  const index = data.findIndex((row) => row[uniqueKey] === key);
7275
7322
  data.splice(index, 1);
@@ -7283,6 +7330,8 @@ class GridEditable extends Grid {
7283
7330
  for (let index = allData.length - 1; index >= 0; index -= 1) {
7284
7331
  const row = allData[index];
7285
7332
  if (this.addedRows[row[this.datasource.uniqueKey]]) {
7333
+ const key = row[this.datasource.uniqueKey];
7334
+ this.clearInvalidComponentsForRow(key);
7286
7335
  allData.splice(index, 1);
7287
7336
  }
7288
7337
  }
@@ -7303,13 +7352,17 @@ class GridEditable extends Grid {
7303
7352
  saveEditedRows(revalidate = false) {
7304
7353
  return __awaiter(this, void 0, void 0, function* () {
7305
7354
  const { page } = this.datasource;
7355
+ // Verificar se o grid é válido antes de tentar salvar
7356
+ if (!this.isGridValid(revalidate)) {
7357
+ throw new Error('Invalid rows');
7358
+ }
7359
+ // Só cancelar as linhas adicionadas se todas forem válidas
7306
7360
  yield this.cancelAddedRows();
7307
- const response = yield Promise.all(this.getEditedRows(revalidate).map((row) => this.addDataRow(row)));
7361
+ const response = yield Promise.all(this.getEditedRows(revalidate, true).map((row) => this.addDataRow(row)));
7308
7362
  this.editing = false;
7309
7363
  this.editedRows = {};
7310
7364
  this.addedRows = {};
7311
7365
  this.invalidComponents = {};
7312
- this.addedRows = {};
7313
7366
  yield this.datasource.setPage(page);
7314
7367
  return response;
7315
7368
  });
@@ -7560,6 +7613,8 @@ class GridEditable extends Grid {
7560
7613
  const rows = Object.assign({}, this.editedRows);
7561
7614
  delete rows[foundRow[uniqueKey]];
7562
7615
  this.editedRows = rows;
7616
+ const key = foundRow[uniqueKey];
7617
+ this.clearInvalidComponentsForRow(key);
7563
7618
  }
7564
7619
  /**
7565
7620
  * Makes the cell enter edit mode
@@ -9661,6 +9716,22 @@ class TreeDataStructure {
9661
9716
  }
9662
9717
  return result;
9663
9718
  }
9719
+ loadChildren(row, rowIndex = -1) {
9720
+ return __awaiter(this, void 0, void 0, function* () {
9721
+ const { uniqueKey } = this.originalDatasource;
9722
+ let index = rowIndex;
9723
+ if (index === -1) {
9724
+ index = this.findDataIndex(this.treeData, row[uniqueKey]);
9725
+ }
9726
+ const originalData = [...this.originalDatasource.data];
9727
+ const data = yield this.originalDatasource.addFilter(this.parentField, row[uniqueKey]);
9728
+ originalData.splice(index + 1, 0, ...data);
9729
+ this.originalDatasource.data = originalData;
9730
+ this.originalDatasource.currentRow = this.clearRow(row);
9731
+ delete this.originalDatasource.filter[this.parentField];
9732
+ return data;
9733
+ });
9734
+ }
9664
9735
  /**
9665
9736
  * Expands or collapses a row
9666
9737
  * @param row Row object
@@ -9675,17 +9746,7 @@ class TreeDataStructure {
9675
9746
  && this.fetchOnDemand
9676
9747
  && rowData.tree__children.length === 1
9677
9748
  && !rowData.tree__children[0][uniqueKey]) {
9678
- let index = rowIndex;
9679
- if (index === -1) {
9680
- index = this.findDataIndex(this.treeData, row[uniqueKey]);
9681
- }
9682
- const originalData = [...this.originalDatasource.data];
9683
- const data = yield this.originalDatasource.addFilter(this.parentField, row[uniqueKey]);
9684
- originalData.splice(index + 1, 0, ...data);
9685
- this.originalDatasource.data = originalData;
9686
- this.originalDatasource.currentRow = this.clearRow(row);
9687
- delete this.originalDatasource.filter[this.parentField];
9688
- return data;
9749
+ return this.loadChildren(row, rowIndex);
9689
9750
  }
9690
9751
  return undefined;
9691
9752
  });
@@ -9847,6 +9908,77 @@ class DataValueOutHelper {
9847
9908
  }
9848
9909
  }
9849
9910
 
9911
+ class DatasourceSearcher {
9912
+ constructor() {
9913
+ this.dsSearch = {
9914
+ SEARCH: (value, searchIn) => ({
9915
+ searchIn: [searchIn],
9916
+ search: String(value || ''),
9917
+ }),
9918
+ FILTER: (value, searchIn) => ({
9919
+ filter: {
9920
+ [searchIn]: value,
9921
+ },
9922
+ }),
9923
+ FIND: (value, searchIn) => ({
9924
+ find: {
9925
+ [searchIn]: value,
9926
+ },
9927
+ }),
9928
+ DYNAMIC_FILTER: (value, search_in) => {
9929
+ const arrayValue = Array.isArray(value) ? value : Array.of(value);
9930
+ const filter = arrayValue.map((item) => ({ operation: 'EQUALS', relation: 'OR', value: item }));
9931
+ const dynamicFilter = { [search_in]: filter };
9932
+ return { dynamicFilter };
9933
+ },
9934
+ };
9935
+ }
9936
+ search(datasource, searchValue, searchIn, searchParam) {
9937
+ return __awaiter(this, void 0, void 0, function* () {
9938
+ // using filter/find/dynamicFilter should make only 1 request
9939
+ // using normal search should make one request per search value
9940
+ if (!Array.isArray(searchValue)) {
9941
+ return this.searchRequest(datasource, searchValue, searchIn, searchParam);
9942
+ }
9943
+ if (searchParam !== 'SEARCH') {
9944
+ const items = yield this.searchRequest(datasource, searchValue, searchIn, searchParam);
9945
+ return items;
9946
+ }
9947
+ const searchedItems = [];
9948
+ const promises = searchValue.map((value) => __awaiter(this, void 0, void 0, function* () {
9949
+ const [item] = yield this.searchRequest(datasource, value, searchIn, searchParam);
9950
+ searchedItems.push(item);
9951
+ }));
9952
+ yield Promise.all(promises);
9953
+ return searchedItems;
9954
+ });
9955
+ }
9956
+ searchRequest(datasource, searchValue, searchIn, searchParam) {
9957
+ return __awaiter(this, void 0, void 0, function* () {
9958
+ const config = Object.assign(Object.assign(Object.assign({}, datasource.clone()), this.dsSearch[searchParam](searchValue, searchIn)), { lazyLoad: true, loadAll: Array.isArray(searchValue) });
9959
+ const cloneDatasource = DatasourceFactory.factory(config);
9960
+ const items = yield cloneDatasource.get();
9961
+ cloneDatasource.destroy();
9962
+ if (Array.isArray(searchValue)) {
9963
+ return items.filter((item) => searchValue.includes(item[searchIn]));
9964
+ }
9965
+ return items.filter((row) => row[searchIn] === searchValue);
9966
+ });
9967
+ }
9968
+ }
9969
+
9970
+ const uniqueBy = (a, key) => {
9971
+ const seen = {};
9972
+ return a.filter((item) => {
9973
+ const k = item[key] || JSON.stringify(item);
9974
+ if (!seen[k]) {
9975
+ seen[k] = true;
9976
+ return true;
9977
+ }
9978
+ return false;
9979
+ });
9980
+ };
9981
+
9850
9982
  /**
9851
9983
  * Base class for Select component.
9852
9984
  */
@@ -10137,18 +10269,13 @@ class Select extends TextInput {
10137
10269
  * Finds and retrieves items searching by value
10138
10270
  * @param value Default value
10139
10271
  */
10140
- getItemsBySearchValue(value, searchIn) {
10272
+ getItemsBySearchValue(value) {
10141
10273
  return __awaiter(this, void 0, void 0, function* () {
10142
- const config = Object.assign(Object.assign(Object.assign({}, this.datasource.clone()), this.dsSearch[this.searchParam](value, searchIn)), { lazyLoad: true, loadAll: Array.isArray(value) });
10143
10274
  this.datasource.loading = true;
10144
- const datasource = DatasourceFactory.factory(config);
10145
- const items = yield datasource.get();
10275
+ const datasourceSearcher = new DatasourceSearcher();
10276
+ const result = yield datasourceSearcher.search(this.datasource, value, this.dataValue, this.searchParam);
10146
10277
  this.datasource.loading = false;
10147
- datasource.destroy();
10148
- if (Array.isArray(value)) {
10149
- return items.filter((item) => value.includes(item[this.dataValue]));
10150
- }
10151
- return items.filter(this.getCondition(value));
10278
+ return result;
10152
10279
  });
10153
10280
  }
10154
10281
  getCondition(filterValue) {
@@ -10173,17 +10300,6 @@ class Select extends TextInput {
10173
10300
  this.updateSearch(this.dirtySearchValue);
10174
10301
  });
10175
10302
  }
10176
- uniqueBy(a, key) {
10177
- const seen = {};
10178
- return a.filter((item) => {
10179
- const k = item[key] || JSON.stringify(item);
10180
- if (!seen[k]) {
10181
- seen[k] = true;
10182
- return true;
10183
- }
10184
- return false;
10185
- });
10186
- }
10187
10303
  afterLoad() {
10188
10304
  if (this.manualMode)
10189
10305
  return;
@@ -10249,11 +10365,10 @@ class Select extends TextInput {
10249
10365
  else {
10250
10366
  filterValue = value;
10251
10367
  }
10252
- const searchIn = this.dataValue;
10253
10368
  const foundInData = this.datasource.data.find(this.getCondition(filterValue));
10254
10369
  let searchValue = foundInData;
10255
10370
  if (!foundInData && !this.manualMode) {
10256
- [searchValue] = yield this.getItemsBySearchValue(filterValue, searchIn);
10371
+ [searchValue] = yield this.getItemsBySearchValue(filterValue);
10257
10372
  }
10258
10373
  if (!searchValue) {
10259
10374
  this.setFieldRowValue(null);
@@ -10886,15 +11001,12 @@ class IterableComponentRender extends Iterable {
10886
11001
  this.createAccessors();
10887
11002
  }
10888
11003
  addSlashes(value) {
10889
- if (typeof value === 'string') {
10890
- return value.replace(/\\/g, '\\\\')
10891
- .replace(/\t/g, '\\t')
10892
- .replace(/\n/g, '\\n')
10893
- .replace(/\f/g, '\\f')
10894
- .replace(/\r/g, '\\r')
10895
- .replace(/"/g, '\\"');
10896
- }
10897
- return value;
11004
+ return value.replace(/\\/g, '\\\\')
11005
+ .replace(/\t/g, '\\t')
11006
+ .replace(/\n/g, '\\n')
11007
+ .replace(/\f/g, '\\f')
11008
+ .replace(/\r/g, '\\r')
11009
+ .replace(/"/g, '\\"');
10898
11010
  }
10899
11011
  /**
10900
11012
  * Returns the iterable component metadata based on row data
@@ -10907,14 +11019,13 @@ class IterableComponentRender extends Iterable {
10907
11019
  .replace(rowExp, JSON.stringify(row))
10908
11020
  .replace(exp, (match) => {
10909
11021
  const propPath = match.replace(/<<|>>|"/g, '').split('.').splice(1).join('.');
10910
- const value = this.addSlashes(get(row, propPath));
11022
+ let value = get(row, propPath);
11023
+ if (value === undefined || value === null)
11024
+ value = '';
10911
11025
  if (typeof value === 'string') {
10912
- if (match.startsWith('"') && match.endsWith('"'))
10913
- return `"${value}"`;
10914
- return value;
11026
+ const escaped = this.addSlashes(value);
11027
+ return match.startsWith('"') && match.endsWith('"') ? `"${escaped}"` : escaped;
10915
11028
  }
10916
- if (value === undefined)
10917
- return '""';
10918
11029
  return value;
10919
11030
  });
10920
11031
  return JSON.parse(metadata);
@@ -12592,19 +12703,10 @@ class SelectMultiple extends Select {
12592
12703
  this.insertedValues.push(item);
12593
12704
  pushed = true;
12594
12705
  });
12595
- // using filter/find/dynamicFilter should make only 1 request
12596
- // using normal search should make one request per search value
12597
- if (this.searchParam !== 'SEARCH') {
12598
- const items = yield this.getItemsBySearchValue(searchedValues, this.dataValue);
12706
+ if (searchedValues.length) {
12707
+ const items = yield this.getItemsBySearchValue(searchedValues);
12599
12708
  items.forEach(insertItem);
12600
12709
  }
12601
- else {
12602
- const promises = searchedValues.map((searchedValue) => __awaiter(this, void 0, void 0, function* () {
12603
- const [item] = yield this.getItemsBySearchValue(searchedValue, this.dataValue);
12604
- insertItem(item);
12605
- }));
12606
- yield Promise.all(promises);
12607
- }
12608
12710
  if (foundValues.length > 0) {
12609
12711
  this.setFieldRowValue(foundValues);
12610
12712
  }
@@ -12842,7 +12944,7 @@ class SelectMultiple extends Select {
12842
12944
  if (this.manualMode)
12843
12945
  return;
12844
12946
  if (this.insertedValues.length) {
12845
- this.datasource.data = this.uniqueBy(this.insertedValues.concat(this.datasource.data), this.datasource.uniqueKey);
12947
+ this.datasource.data = uniqueBy(this.insertedValues.concat(this.datasource.data), this.datasource.uniqueKey);
12846
12948
  const values = this.insertedValues.map((inserted) => inserted[this.dataValue]);
12847
12949
  // prevent caching insertedValues
12848
12950
  this.cachedData = this.datasource.data.filter((row) => !values.includes(row[this.dataValue]));
@@ -13077,6 +13179,7 @@ class SelectTree extends TextInput {
13077
13179
  * Defines if should wait and not execute GET method when Datasource is created
13078
13180
  */
13079
13181
  this.lazyLoad = true;
13182
+ this.selectValue = null;
13080
13183
  /**
13081
13184
  * Uses delayed loading to load tree branches
13082
13185
  */
@@ -13098,6 +13201,10 @@ class SelectTree extends TextInput {
13098
13201
  */
13099
13202
  this.dataValueOutFormName = '';
13100
13203
  this.formatterFn = FormatterParserProvider.getFormatter('ZdSelectTree');
13204
+ /**
13205
+ * Defines if data handling should be manual or automatic
13206
+ */
13207
+ this.searchParam = 'SEARCH';
13101
13208
  this.savedNodes = undefined;
13102
13209
  this.search = '';
13103
13210
  this.debounceSearch = debounce(this.searchChange, 500);
@@ -13125,6 +13232,7 @@ class SelectTree extends TextInput {
13125
13232
  this.autoSelection = this.getInitValue('autoSelection', props.autoSelection, this.autoSelection);
13126
13233
  this.dataValueOut = this.getInitValue('dataValueOut', props.dataValueOut, this.dataValueOut);
13127
13234
  this.dataValueOutFormName = this.getInitValue('dataValueOutFormName', props.dataValueOutFormName, this.dataValueOutFormName);
13235
+ this.searchParam = this.getInitValue('searchParam', props.searchParam, this.searchParam);
13128
13236
  if (props.datasource && Object.keys(props.datasource).length) {
13129
13237
  this.lazyLoad = props.datasource.lazyLoad !== false;
13130
13238
  const searchFields = Array.isArray(this.dataText) ? this.dataText : [this.dataText];
@@ -13194,6 +13302,9 @@ class SelectTree extends TextInput {
13194
13302
  this.nodes = this.createChildrenNodes(firstLevelNodes);
13195
13303
  }
13196
13304
  }
13305
+ /**
13306
+ * Creates a Tree Node from a datasource row
13307
+ */
13197
13308
  createNodeFromRow(row) {
13198
13309
  let children;
13199
13310
  if (this.fetchOnDemand && !this.datasource.search) {
@@ -13333,31 +13444,71 @@ class SelectTree extends TextInput {
13333
13444
  });
13334
13445
  return result;
13335
13446
  }
13447
+ clearNodeRow(row) {
13448
+ return this.clearRow(row.row || row);
13449
+ }
13450
+ /**
13451
+ * Finds and retrieves items searching by value
13452
+ * @param value Default value
13453
+ */
13454
+ getItemsBySearchValue(value) {
13455
+ return __awaiter(this, void 0, void 0, function* () {
13456
+ this.datasource.loading = true;
13457
+ const datasourceSearcher = new DatasourceSearcher();
13458
+ const result = yield datasourceSearcher.search(this.datasource, value, this.dataValue, this.searchParam);
13459
+ this.datasource.loading = false;
13460
+ return result;
13461
+ });
13462
+ }
13336
13463
  get value() {
13337
13464
  if (!this.selectValue)
13338
13465
  return this.selectValue;
13339
13466
  if (this.returnObject) {
13340
- return this.clearRow(this.selectValue.row || this.selectValue);
13467
+ return this.clearNodeRow(this.selectValue);
13341
13468
  }
13342
- return this.selectValue;
13469
+ const key = this.datasource ? this.dataValue : 'id';
13470
+ return this.selectValue[key];
13343
13471
  }
13344
13472
  set value(value) {
13345
13473
  this.setValue(value);
13346
13474
  }
13347
13475
  setValue(value) {
13348
- let val = value;
13349
- const key = this.datasource ? this.dataValue : 'id';
13350
- if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
13351
- val = value[key];
13352
- }
13353
- else if (!value && value !== 0) {
13354
- val = null;
13355
- }
13356
- if (this.returnObject) {
13357
- this.selectValue = val ? { id: val } : null;
13358
- return;
13359
- }
13360
- this.selectValue = val;
13476
+ return __awaiter(this, void 0, void 0, function* () {
13477
+ let val = null;
13478
+ const key = this.datasource ? this.dataValue : 'id';
13479
+ if (!value && value !== 0) {
13480
+ val = null;
13481
+ }
13482
+ else if (typeof value === 'object') {
13483
+ val = value[key];
13484
+ }
13485
+ else {
13486
+ val = value;
13487
+ }
13488
+ if (!val) {
13489
+ this.selectValue = null;
13490
+ return;
13491
+ }
13492
+ if (!this.datasource) {
13493
+ this.selectValue = { id: val };
13494
+ return;
13495
+ }
13496
+ const searchIn = this.dataValue;
13497
+ const foundInData = this.datasource.data.find((row) => row[searchIn] === val);
13498
+ let foundValue = foundInData;
13499
+ if (!foundInData) {
13500
+ [foundValue] = yield this.getItemsBySearchValue(val);
13501
+ }
13502
+ if (!foundValue) {
13503
+ if (typeof value === 'object') {
13504
+ this.selectValue = Object.assign({ id: val }, value);
13505
+ return;
13506
+ }
13507
+ this.selectValue = { id: val };
13508
+ return;
13509
+ }
13510
+ this.selectValue = foundValue;
13511
+ });
13361
13512
  }
13362
13513
  loadChildren(parentNode) {
13363
13514
  return __awaiter(this, void 0, void 0, function* () {
@@ -13410,6 +13561,7 @@ class SelectTreeMultiple extends SelectTree {
13410
13561
  * Selected Nodes
13411
13562
  */
13412
13563
  this.selectedNodes = [];
13564
+ this.selectValue = [];
13413
13565
  /**
13414
13566
  * Changes the behavior of checked nodes that will be displayed in the array of values
13415
13567
  */
@@ -13428,7 +13580,9 @@ class SelectTreeMultiple extends SelectTree {
13428
13580
  * Triggered after selected nodes change
13429
13581
  */
13430
13582
  changeSelectedNodes(selectedNodes, element) {
13431
- this.callEvent('onChangeSelectedNodes', { element, component: this, selectedNodes });
13583
+ const selection = this.returnObject
13584
+ ? selectedNodes.map((value) => this.clearNodeRow(value)) : selectedNodes.map((node) => node.id);
13585
+ this.callEvent('onChangeSelectedNodes', { element, component: this, selectedNodes: selection });
13432
13586
  }
13433
13587
  /**
13434
13588
  * Triggered deselecting an node
@@ -13440,34 +13594,58 @@ class SelectTreeMultiple extends SelectTree {
13440
13594
  if (!this.selectValue)
13441
13595
  return [];
13442
13596
  if (this.returnObject) {
13443
- return this.selectValue.map((value) => this.clearRow(value.row || value));
13597
+ return this.selectValue.map((value) => this.clearNodeRow(value));
13444
13598
  }
13445
- return this.selectValue;
13599
+ const key = this.datasource ? this.dataValue : 'id';
13600
+ return this.selectValue.map((item) => item[key]);
13446
13601
  }
13447
13602
  set value(value) {
13448
13603
  this.setValue(value);
13449
13604
  }
13450
13605
  setValue(value) {
13451
- if (!value) {
13452
- this.selectValue = [];
13453
- return;
13454
- }
13455
- const arrValue = Array.isArray(value) ? value : [value];
13456
- const key = this.datasource ? this.dataValue : 'id';
13457
- if (!this.returnObject) {
13458
- this.selectValue = arrValue.map((item) => {
13606
+ return __awaiter(this, void 0, void 0, function* () {
13607
+ if (!value) {
13608
+ this.selectValue = [];
13609
+ return;
13610
+ }
13611
+ const arrValue = Array.isArray(value) ? value : [value];
13612
+ const key = this.datasource ? this.dataValue : 'id';
13613
+ if (!this.datasource) {
13614
+ this.selectValue = arrValue.map((item) => {
13615
+ if (item && typeof item === 'object') {
13616
+ return item;
13617
+ }
13618
+ return { [key]: item };
13619
+ });
13620
+ return;
13621
+ }
13622
+ const valuesToSearch = [];
13623
+ const foundValues = [];
13624
+ const insertItem = (item) => __awaiter(this, void 0, void 0, function* () {
13625
+ if (!item)
13626
+ return;
13627
+ foundValues.push(item);
13628
+ });
13629
+ arrValue.forEach((item) => __awaiter(this, void 0, void 0, function* () {
13630
+ const searchIn = this.dataValue;
13631
+ if (!item)
13632
+ return;
13459
13633
  if (typeof item === 'object') {
13460
- return item[key];
13634
+ insertItem(item);
13635
+ return;
13461
13636
  }
13462
- return item;
13463
- });
13464
- return;
13465
- }
13466
- this.selectValue = arrValue.map((item) => {
13467
- if (typeof item !== 'object') {
13468
- return { id: item };
13637
+ const foundInData = this.datasource.data.find((row) => row[searchIn] === item);
13638
+ if (!foundInData) {
13639
+ valuesToSearch.push(item);
13640
+ return;
13641
+ }
13642
+ insertItem(foundInData);
13643
+ }));
13644
+ if (valuesToSearch.length) {
13645
+ const items = yield this.getItemsBySearchValue(valuesToSearch);
13646
+ items.forEach(insertItem);
13469
13647
  }
13470
- return { id: item[key] };
13648
+ this.selectValue = foundValues;
13471
13649
  });
13472
13650
  }
13473
13651
  /**
@@ -13515,16 +13693,18 @@ class SelectTreeMultiple extends SelectTree {
13515
13693
  */
13516
13694
  selectAllItems(nodes = this.nodes) {
13517
13695
  var _a;
13518
- if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13519
- this.setValue(this.datasource.data);
13520
- return;
13521
- }
13522
- const allNodes = this.getAllNodes(nodes, !this.search);
13523
- // merge all nodes with the current value before setting it
13524
- const currentValue = this.getValueAsObject();
13525
- const nodeMap = this.createMergeMap(currentValue, allNodes);
13526
- const uniqueArray = Array.from(nodeMap.values());
13527
- this.setValue(uniqueArray);
13696
+ return __awaiter(this, void 0, void 0, function* () {
13697
+ if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13698
+ yield this.setValue(this.datasource.data);
13699
+ return;
13700
+ }
13701
+ const allNodes = this.getAllNodes(nodes, !this.search);
13702
+ // merge all nodes with the current value before setting it
13703
+ const currentValue = this.getValueAsObject();
13704
+ const nodeMap = this.createMergeMap(currentValue, allNodes);
13705
+ const uniqueArray = Array.from(nodeMap.values());
13706
+ yield this.setValue(uniqueArray);
13707
+ });
13528
13708
  }
13529
13709
  /**
13530
13710
  * Unelects all items in the tree \
@@ -13536,21 +13716,23 @@ class SelectTreeMultiple extends SelectTree {
13536
13716
  */
13537
13717
  unSelectAllItems(nodes = this.nodes) {
13538
13718
  var _a;
13539
- if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13540
- this.setValue([]);
13541
- return;
13542
- }
13543
- const allNodes = this.getAllNodes(nodes, !this.search);
13544
- // merge all nodes with the current value before setting it
13545
- const currentValue = this.getValueAsObject();
13546
- const nodeMap = this.createMergeMap(currentValue);
13547
- // remove the current visible nodes from the array
13548
- const valuesToRemove = allNodes.map((node) => node.id);
13549
- valuesToRemove.forEach((value) => {
13550
- nodeMap.delete(value);
13719
+ return __awaiter(this, void 0, void 0, function* () {
13720
+ if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
13721
+ yield this.setValue([]);
13722
+ return;
13723
+ }
13724
+ const allNodes = this.getAllNodes(nodes, !this.search);
13725
+ // merge all nodes with the current value before setting it
13726
+ const currentValue = this.getValueAsObject();
13727
+ const nodeMap = this.createMergeMap(currentValue);
13728
+ // remove the current visible nodes from the array
13729
+ const valuesToRemove = allNodes.map((node) => node.id);
13730
+ valuesToRemove.forEach((value) => {
13731
+ nodeMap.delete(value);
13732
+ });
13733
+ const uniqueArray = Array.from(nodeMap.values());
13734
+ yield this.setValue(uniqueArray);
13551
13735
  });
13552
- const uniqueArray = Array.from(nodeMap.values());
13553
- this.setValue(uniqueArray);
13554
13736
  }
13555
13737
  /**
13556
13738
  * Takes two arrays and creates a map of the unique values
@@ -13572,10 +13754,9 @@ class SelectTreeMultiple extends SelectTree {
13572
13754
  return this.value;
13573
13755
  }
13574
13756
  getValueAsObject() {
13575
- return this.value.map((row) => {
13576
- if (this.returnObject)
13577
- return row;
13578
- return { id: row };
13757
+ return this.selectValue.map((row) => {
13758
+ const key = this.datasource ? this.dataValue : 'id';
13759
+ return Object.assign({ id: row[key] }, row);
13579
13760
  });
13580
13761
  }
13581
13762
  }
@@ -15289,6 +15470,11 @@ class TreeGrid extends Grid {
15289
15470
  return response;
15290
15471
  });
15291
15472
  }
15473
+ loadChildren(row, rowIndex = -1) {
15474
+ return __awaiter(this, void 0, void 0, function* () {
15475
+ yield this.treeDataStructure.loadChildren(row, rowIndex);
15476
+ });
15477
+ }
15292
15478
  /**
15293
15479
  * Expands or collapses a row
15294
15480
  * @param row Row object
@@ -16091,4 +16277,4 @@ const AutoNumeric = require('@zeedhi/autonumeric/dist/autoNumeric');
16091
16277
  const packageContent = require('../package.json');
16092
16278
  VersionService.addPackageVersion(packageContent.name, packageContent.version);
16093
16279
 
16094
- export { Alert, AlertService, ApexChart, AutoNumeric, Badge, Breadcrumbs, Button, ButtonGroup, CSVReport, Card, Carousel, Checkbox, CheckboxMultiple, ChildNotFoundError, Chip, CodeEditor, Col, CollapseCard, Column, ColumnNotFoundError, Component, ComponentRender, Container, Currency, Dashboard, DataValueOutHelper, Date$1 as Date, DateRange, Dialog, DialogService, Divider, Dropdown, EmptyDataError, FileInput, Footer, Form, Frame, FramePage, Grid, GridColumn, GridColumnEditable, GridEditable, GroupedPDFFormatter, Header, Icon, Icons, Image, Increment, Input, InputFactory, Iterable, IterableColumnsButton, IterableColumnsButtonController, IterableComponentRender, IterablePageComponent, IterablePageInfo, IterablePageSize, IterablePagination, List, ListGroup, ListItem, Loading, LoadingService, Login, LoginButton, MasterDetail, Menu, MenuButton, MenuGroup, MenuLink, MenuSeparator, Modal, ModalCloseButton, ModalService, Month, Number$1 as Number, PDFReport, Password, Progress, Radio, RangeSlider, Report, Row, Search, Select, SelectMultiple, SelectTree, SelectTreeMultiple, SelectableList, SpeedDial, Steppers, SvgMap, Switch, Tab, Table, Tabs, Tag, Text, TextInput, Textarea, Time, Toggleable, Tooltip, Tree, TreeDataStructure, TreeGrid, TreeGridEditable, WatchURL, XLS2Report, XLS3Report, XLSReport, initTheme };
16280
+ export { Alert, AlertService, ApexChart, AutoNumeric, Badge, Breadcrumbs, Button, ButtonGroup, CSVReport, Card, Carousel, Checkbox, CheckboxMultiple, ChildNotFoundError, Chip, CodeEditor, Col, CollapseCard, Column, ColumnNotFoundError, Component, ComponentRender, Container, Currency, Dashboard, DataValueOutHelper, DatasourceSearcher, Date$1 as Date, DateRange, Dialog, DialogService, Divider, Dropdown, EmptyDataError, FileInput, Footer, Form, Frame, FramePage, Grid, GridColumn, GridColumnEditable, GridEditable, GroupedPDFFormatter, Header, Icon, Icons, Image, Increment, Input, InputFactory, Iterable, IterableColumnsButton, IterableColumnsButtonController, IterableComponentRender, IterablePageComponent, IterablePageInfo, IterablePageSize, IterablePagination, List, ListGroup, ListItem, Loading, LoadingService, Login, LoginButton, MasterDetail, Menu, MenuButton, MenuGroup, MenuLink, MenuSeparator, Modal, ModalCloseButton, ModalService, Month, Number$1 as Number, PDFReport, Password, Progress, Radio, RangeSlider, Report, Row, Search, Select, SelectMultiple, SelectTree, SelectTreeMultiple, SelectableList, SpeedDial, Steppers, SvgMap, Switch, Tab, Table, Tabs, Tag, Text, TextInput, Textarea, Time, Toggleable, Tooltip, Tree, TreeDataStructure, TreeGrid, TreeGridEditable, WatchURL, XLS2Report, XLS3Report, XLSReport, initTheme, uniqueBy };