@zeedhi/common 1.88.0 → 1.89.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.
@@ -3147,6 +3147,7 @@ class Dialog extends Component {
3147
3147
  }
3148
3148
  },
3149
3149
  stop: true,
3150
+ index: 89,
3150
3151
  },
3151
3152
  esc: {
3152
3153
  event: () => {
@@ -3162,6 +3163,7 @@ class Dialog extends Component {
3162
3163
  this.hide();
3163
3164
  }
3164
3165
  },
3166
+ index: 89,
3165
3167
  stop: true,
3166
3168
  },
3167
3169
  };
@@ -5955,21 +5957,25 @@ class Grid extends Iterable {
5955
5957
  up: {
5956
5958
  event: this.navigateUp.bind(this),
5957
5959
  stop: true,
5960
+ index: 99,
5958
5961
  active: true,
5959
5962
  },
5960
5963
  down: {
5961
5964
  event: this.navigateDown.bind(this),
5962
5965
  stop: true,
5966
+ index: 99,
5963
5967
  active: true,
5964
5968
  },
5965
5969
  pageup: {
5966
5970
  event: this.navigatePageUp.bind(this),
5967
5971
  stop: true,
5972
+ index: 99,
5968
5973
  active: true,
5969
5974
  },
5970
5975
  pagedown: {
5971
5976
  event: this.navigatePageDown.bind(this),
5972
5977
  stop: true,
5978
+ index: 99,
5973
5979
  active: true,
5974
5980
  },
5975
5981
  };
@@ -6357,6 +6363,7 @@ class GridEditable extends Grid {
6357
6363
  * Enter edit mode on double click
6358
6364
  */
6359
6365
  this.doubleClickEdit = false;
6366
+ this.singleEdit = false;
6360
6367
  /**
6361
6368
  * Edited rows
6362
6369
  * @private
@@ -6376,6 +6383,7 @@ class GridEditable extends Grid {
6376
6383
  this.cancelEditedRowsKeyMapping = {
6377
6384
  esc: {
6378
6385
  event: this.cancelEditedRows.bind(this),
6386
+ index: 99,
6379
6387
  stop: true,
6380
6388
  input: true,
6381
6389
  active: true,
@@ -6385,6 +6393,7 @@ class GridEditable extends Grid {
6385
6393
  this.doubleClickEdit = this.getInitValue('doubleClickEdit', props.doubleClickEdit, this.doubleClickEdit);
6386
6394
  this.canEditRow = this.getInitValue('canEditRow', props.canEditRow, this.canEditRow);
6387
6395
  this.editingNewRows = this.getInitValue('editingNewRows', props.editingNewRows, this.editingNewRows);
6396
+ this.singleEdit = this.getInitValue('singleEdit', props.singleEdit, this.singleEdit);
6388
6397
  this.createAccessors();
6389
6398
  }
6390
6399
  onMounted(element) {
@@ -6493,6 +6502,13 @@ class GridEditable extends Grid {
6493
6502
  });
6494
6503
  }
6495
6504
  }
6505
+ getVisibleValue(row, column) {
6506
+ const key = row[this.datasource.uniqueKey];
6507
+ if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
6508
+ return this.editedRows[key][column.name];
6509
+ }
6510
+ return row[column.name];
6511
+ }
6496
6512
  /**
6497
6513
  * Returns editable component properties based on the column definition
6498
6514
  * @param column Column definition
@@ -6503,13 +6519,7 @@ class GridEditable extends Grid {
6503
6519
  getEditableComponent(column, row, cellProps, events) {
6504
6520
  const key = row[this.datasource.uniqueKey];
6505
6521
  const compName = this.getCompName(key, column.name);
6506
- let colValue;
6507
- if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
6508
- colValue = this.editedRows[key][column.name];
6509
- }
6510
- else {
6511
- colValue = row[column.name];
6512
- }
6522
+ const colValue = this.getVisibleValue(row, column);
6513
6523
  const componentProps = merge({}, column.componentProps, cellProps === null || cellProps === void 0 ? void 0 : cellProps.componentProps);
6514
6524
  let compEvents = {};
6515
6525
  if (componentProps && componentProps.events) {
@@ -6650,7 +6660,9 @@ class GridEditable extends Grid {
6650
6660
  */
6651
6661
  cancelEditedRows() {
6652
6662
  return __awaiter(this, void 0, void 0, function* () {
6663
+ const { page } = this.datasource;
6653
6664
  yield this.cancelAddedRows();
6665
+ yield this.datasource.setPage(page);
6654
6666
  this.editing = false;
6655
6667
  this.editedRows = {};
6656
6668
  this.invalidComponents = {};
@@ -6658,7 +6670,7 @@ class GridEditable extends Grid {
6658
6670
  }
6659
6671
  cancelAddedRows() {
6660
6672
  return __awaiter(this, void 0, void 0, function* () {
6661
- const { data, page } = this.datasource;
6673
+ const { data } = this.datasource;
6662
6674
  const allData = this.datasource.allData || data;
6663
6675
  Promise.resolve(allData);
6664
6676
  for (let index = allData.length - 1; index >= 0; index -= 1) {
@@ -6668,8 +6680,6 @@ class GridEditable extends Grid {
6668
6680
  }
6669
6681
  }
6670
6682
  yield this.datasource.updateData(allData);
6671
- yield this.datasource.get();
6672
- yield this.datasource.setPage(page);
6673
6683
  });
6674
6684
  }
6675
6685
  addDataRow(row) {
@@ -6685,6 +6695,7 @@ class GridEditable extends Grid {
6685
6695
  */
6686
6696
  saveEditedRows(revalidate = false) {
6687
6697
  return __awaiter(this, void 0, void 0, function* () {
6698
+ const { page } = this.datasource;
6688
6699
  yield this.cancelAddedRows();
6689
6700
  const response = yield Promise.all(this.getEditedRows(revalidate).map((row) => this.addDataRow(row)));
6690
6701
  this.editing = false;
@@ -6692,7 +6703,7 @@ class GridEditable extends Grid {
6692
6703
  this.addedRows = {};
6693
6704
  this.invalidComponents = {};
6694
6705
  this.addedRows = {};
6695
- yield this.datasource.get();
6706
+ yield this.datasource.setPage(page);
6696
6707
  return response;
6697
6708
  });
6698
6709
  }
@@ -6701,7 +6712,7 @@ class GridEditable extends Grid {
6701
6712
  * @param revalidate Defines if the fields should be revalidated
6702
6713
  * @throws Will throw when it finds an invalid row
6703
6714
  */
6704
- getEditedRows(revalidate = false) {
6715
+ getEditedRows(revalidate = false, silent = false) {
6705
6716
  const editedRows = [];
6706
6717
  Object.keys(this.editedRows).forEach((key) => {
6707
6718
  const row = Object.assign(Object.assign({}, this.editedRows[key].originalRow), this.editedRows[key]);
@@ -6712,7 +6723,7 @@ class GridEditable extends Grid {
6712
6723
  delete row[`${attr}_original`];
6713
6724
  }
6714
6725
  });
6715
- if (!this.isGridValid(revalidate)) {
6726
+ if (!silent && !this.isGridValid(revalidate)) {
6716
6727
  throw new Error('Invalid rows');
6717
6728
  }
6718
6729
  editedRows.push(row);
@@ -7476,13 +7487,27 @@ class Select extends TextInput {
7476
7487
  const oldGet = this.datasource.get;
7477
7488
  this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
7478
7489
  const response = yield oldGet.call(this.datasource);
7490
+ if (!this.datasource.search && !this.manualMode) {
7491
+ this.cachedData = [...this.datasource.data];
7492
+ this.cachedTotal = this.datasource.total;
7493
+ }
7479
7494
  if (this.indexOf(this.value) === -1 && !this.datasource.search && !this.isFocused) {
7480
7495
  yield this.setValue(this.value, false);
7481
7496
  this.removePushedValue();
7482
7497
  }
7498
+ this.insertSelected();
7483
7499
  return response;
7484
7500
  });
7485
7501
  }
7502
+ insertSelected() {
7503
+ if (this.datasource.search || !this.pushedValue || this.indexOf(this.pushedValue) !== -1)
7504
+ return;
7505
+ const filterValue = this.pushedValue[this.dataValue];
7506
+ const foundInData = this.datasource.data.find(this.getCondition(filterValue));
7507
+ if (!foundInData) {
7508
+ this.datasource.data.unshift(this.pushedValue);
7509
+ }
7510
+ }
7486
7511
  get search() {
7487
7512
  return this.searchValue;
7488
7513
  }
@@ -7762,14 +7787,14 @@ class Select extends TextInput {
7762
7787
  loadMore() {
7763
7788
  return __awaiter(this, void 0, void 0, function* () {
7764
7789
  yield this.datasource.setLimit(this.datasource.limit + this.loadMoreQtty);
7765
- if (!this.datasource.search) {
7766
- this.afterLoad();
7767
- const { dataValue } = this;
7768
- const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
7769
- if (isSelected)
7770
- return;
7771
- this.removePushedValue();
7772
- }
7790
+ if (this.datasource.search)
7791
+ return;
7792
+ this.afterLoad();
7793
+ const { dataValue } = this;
7794
+ const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
7795
+ if (isSelected)
7796
+ return;
7797
+ this.removePushedValue();
7773
7798
  });
7774
7799
  }
7775
7800
  /**
@@ -9878,7 +9903,6 @@ class SelectMultiple extends Select {
9878
9903
  const parsedValue = this.parserFn(value, this);
9879
9904
  if (parsedValue !== this.datasource.search) {
9880
9905
  yield this.datasource.setSearch(parsedValue);
9881
- this.insertSelected();
9882
9906
  }
9883
9907
  });
9884
9908
  }
@@ -9907,6 +9931,7 @@ class SelectMultiple extends Select {
9907
9931
  yield this.updateSearch(value);
9908
9932
  }
9909
9933
  else {
9934
+ this.datasource.search = value;
9910
9935
  if (!this.manualMode) {
9911
9936
  this.datasource.data = [...this.cachedData];
9912
9937
  this.datasource.total = this.cachedTotal;
@@ -9986,7 +10011,6 @@ class SelectMultiple extends Select {
9986
10011
  const foundInData = this.datasource.data.find(this.getCondition(value));
9987
10012
  return !foundInData;
9988
10013
  });
9989
- this.insertSelected();
9990
10014
  if (!this.datasource.search) {
9991
10015
  this.setCache();
9992
10016
  }
@@ -10058,9 +10082,6 @@ class SelectMultiple extends Select {
10058
10082
  return __awaiter(this, void 0, void 0, function* () {
10059
10083
  if (!this.preventLoadOnFocus) {
10060
10084
  yield this.datasource.get();
10061
- const values = this.datasource.data.map((row) => row[this.dataValue]);
10062
- // remove inserted items that are already in datasource
10063
- this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
10064
10085
  this.preventLoadOnFocus = true;
10065
10086
  }
10066
10087
  this.setCache();
@@ -12632,11 +12653,13 @@ class TreeGrid extends Grid {
12632
12653
  right: {
12633
12654
  event: this.navigateToggle.bind(this, false),
12634
12655
  stop: true,
12656
+ index: 99,
12635
12657
  active: true,
12636
12658
  },
12637
12659
  left: {
12638
12660
  event: this.navigateToggle.bind(this, true),
12639
12661
  stop: true,
12662
+ index: 99,
12640
12663
  active: true,
12641
12664
  },
12642
12665
  };
@@ -12873,6 +12896,7 @@ class TreeGridEditable extends TreeGrid {
12873
12896
  * Editing rows
12874
12897
  */
12875
12898
  this.editing = false;
12899
+ this.singleEdit = false;
12876
12900
  /**
12877
12901
  * Edited rows
12878
12902
  * @private
@@ -12890,6 +12914,7 @@ class TreeGridEditable extends TreeGrid {
12890
12914
  this.cancelEditedRowsKeyMapping = {
12891
12915
  esc: {
12892
12916
  event: this.cancelEditedRows.bind(this),
12917
+ index: 99,
12893
12918
  stop: true,
12894
12919
  input: true,
12895
12920
  active: true,
@@ -12897,6 +12922,7 @@ class TreeGridEditable extends TreeGrid {
12897
12922
  };
12898
12923
  this.doubleClickEdit = this.getInitValue('doubleClickEdit', props.doubleClickEdit, this.doubleClickEdit);
12899
12924
  this.canEditRow = this.getInitValue('canEditRow', props.canEditRow, this.canEditRow);
12925
+ this.singleEdit = this.getInitValue('singleEdit', props.singleEdit, this.singleEdit);
12900
12926
  this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
12901
12927
  this.createAccessors();
12902
12928
  }
@@ -13006,6 +13032,13 @@ class TreeGridEditable extends TreeGrid {
13006
13032
  });
13007
13033
  }
13008
13034
  }
13035
+ getVisibleValue(row, column) {
13036
+ const key = row[this.datasource.uniqueKey];
13037
+ if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
13038
+ return this.editedRows[key][column.name];
13039
+ }
13040
+ return row[column.name];
13041
+ }
13009
13042
  /**
13010
13043
  * Returns editable component properties based on the column definition
13011
13044
  * @param column Column definition
@@ -13016,13 +13049,7 @@ class TreeGridEditable extends TreeGrid {
13016
13049
  getEditableComponent(column, row, cellProps, events) {
13017
13050
  const key = row[this.datasource.uniqueKey];
13018
13051
  const compName = this.getCompName(key, column.name);
13019
- let colValue;
13020
- if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
13021
- colValue = this.editedRows[key][column.name];
13022
- }
13023
- else {
13024
- colValue = row[column.name];
13025
- }
13052
+ const colValue = this.getVisibleValue(row, column);
13026
13053
  const componentProps = merge({}, column.componentProps, cellProps.componentProps);
13027
13054
  let compEvents = {};
13028
13055
  if (componentProps && componentProps.events) {
@@ -13118,10 +13145,24 @@ class TreeGridEditable extends TreeGrid {
13118
13145
  * @param column Column
13119
13146
  * @param row Row
13120
13147
  */
13121
- isValid(column, row) {
13148
+ isValid(column, row, revalidate = false) {
13122
13149
  const key = row[this.datasource.uniqueKey];
13123
13150
  const compName = this.getCompName(key, column.name);
13124
- return !Object.prototype.hasOwnProperty.call(this.invalidComponents, compName);
13151
+ if (!revalidate) {
13152
+ return !Object.prototype.hasOwnProperty.call(this.invalidComponents, compName);
13153
+ }
13154
+ try {
13155
+ const input = this.getComponent(key, column.name);
13156
+ const isValid = input.validate();
13157
+ this.checkCompValidity(input);
13158
+ return isValid;
13159
+ }
13160
+ catch (e) {
13161
+ if (e instanceof InstanceNotFoundError) {
13162
+ return true;
13163
+ }
13164
+ throw e;
13165
+ }
13125
13166
  }
13126
13167
  /**
13127
13168
  * Cancels all edited rows and enable grid components
@@ -13164,7 +13205,7 @@ class TreeGridEditable extends TreeGrid {
13164
13205
  * Retrieves all edited rows if they are valid
13165
13206
  * @throws Will throw when it finds an invalid row
13166
13207
  */
13167
- getEditedRows() {
13208
+ getEditedRows(revalidate = false, silent = false) {
13168
13209
  const editedRows = [];
13169
13210
  Object.keys(this.editedRows).forEach((key) => {
13170
13211
  const row = Object.assign(Object.assign({}, this.editedRows[key].originalRow), this.editedRows[key]);
@@ -13177,15 +13218,29 @@ class TreeGridEditable extends TreeGrid {
13177
13218
  delete row[attr];
13178
13219
  }
13179
13220
  });
13180
- if (!this.isGridValid()) {
13221
+ if (!silent && !this.isGridValid(revalidate)) {
13181
13222
  throw new Error('Invalid rows');
13182
13223
  }
13183
13224
  editedRows.push(row);
13184
13225
  });
13185
13226
  return editedRows;
13186
13227
  }
13187
- isGridValid() {
13188
- return Object.keys(this.invalidComponents).length === 0;
13228
+ /**
13229
+ * Checks whether the grid is valid or not
13230
+ * @param revalidate Defines if the fields should be revalidated
13231
+ */
13232
+ isGridValid(revalidate = false) {
13233
+ if (!revalidate) {
13234
+ return Object.keys(this.invalidComponents).length === 0;
13235
+ }
13236
+ let allValid = true;
13237
+ this.datasource.data.forEach((row) => this.columns.forEach((column) => {
13238
+ if (!column.isVisible || !column.editable)
13239
+ return;
13240
+ if (!this.isValid(column, row, true))
13241
+ allValid = false;
13242
+ }));
13243
+ return allValid;
13189
13244
  }
13190
13245
  /**
13191
13246
  * Gets the editable component name
@@ -13861,7 +13916,7 @@ class PDFReport extends BaseReport {
13861
13916
  else if (column.componentProps && Object.keys(column.componentProps).length) {
13862
13917
  const { component } = column.componentProps;
13863
13918
  if (this.isNumberComponent(component)) {
13864
- format = { type: 'float' };
13919
+ format = { type: 'float', params: {} };
13865
13920
  mask = this.checkAccessor(column.componentProps.mask);
13866
13921
  if (mask) {
13867
13922
  format.params = {};
@@ -3154,6 +3154,7 @@
3154
3154
  }
3155
3155
  },
3156
3156
  stop: true,
3157
+ index: 89,
3157
3158
  },
3158
3159
  esc: {
3159
3160
  event: () => {
@@ -3169,6 +3170,7 @@
3169
3170
  this.hide();
3170
3171
  }
3171
3172
  },
3173
+ index: 89,
3172
3174
  stop: true,
3173
3175
  },
3174
3176
  };
@@ -5962,21 +5964,25 @@
5962
5964
  up: {
5963
5965
  event: this.navigateUp.bind(this),
5964
5966
  stop: true,
5967
+ index: 99,
5965
5968
  active: true,
5966
5969
  },
5967
5970
  down: {
5968
5971
  event: this.navigateDown.bind(this),
5969
5972
  stop: true,
5973
+ index: 99,
5970
5974
  active: true,
5971
5975
  },
5972
5976
  pageup: {
5973
5977
  event: this.navigatePageUp.bind(this),
5974
5978
  stop: true,
5979
+ index: 99,
5975
5980
  active: true,
5976
5981
  },
5977
5982
  pagedown: {
5978
5983
  event: this.navigatePageDown.bind(this),
5979
5984
  stop: true,
5985
+ index: 99,
5980
5986
  active: true,
5981
5987
  },
5982
5988
  };
@@ -6364,6 +6370,7 @@
6364
6370
  * Enter edit mode on double click
6365
6371
  */
6366
6372
  this.doubleClickEdit = false;
6373
+ this.singleEdit = false;
6367
6374
  /**
6368
6375
  * Edited rows
6369
6376
  * @private
@@ -6383,6 +6390,7 @@
6383
6390
  this.cancelEditedRowsKeyMapping = {
6384
6391
  esc: {
6385
6392
  event: this.cancelEditedRows.bind(this),
6393
+ index: 99,
6386
6394
  stop: true,
6387
6395
  input: true,
6388
6396
  active: true,
@@ -6392,6 +6400,7 @@
6392
6400
  this.doubleClickEdit = this.getInitValue('doubleClickEdit', props.doubleClickEdit, this.doubleClickEdit);
6393
6401
  this.canEditRow = this.getInitValue('canEditRow', props.canEditRow, this.canEditRow);
6394
6402
  this.editingNewRows = this.getInitValue('editingNewRows', props.editingNewRows, this.editingNewRows);
6403
+ this.singleEdit = this.getInitValue('singleEdit', props.singleEdit, this.singleEdit);
6395
6404
  this.createAccessors();
6396
6405
  }
6397
6406
  onMounted(element) {
@@ -6500,6 +6509,13 @@
6500
6509
  });
6501
6510
  }
6502
6511
  }
6512
+ getVisibleValue(row, column) {
6513
+ const key = row[this.datasource.uniqueKey];
6514
+ if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
6515
+ return this.editedRows[key][column.name];
6516
+ }
6517
+ return row[column.name];
6518
+ }
6503
6519
  /**
6504
6520
  * Returns editable component properties based on the column definition
6505
6521
  * @param column Column definition
@@ -6510,13 +6526,7 @@
6510
6526
  getEditableComponent(column, row, cellProps, events) {
6511
6527
  const key = row[this.datasource.uniqueKey];
6512
6528
  const compName = this.getCompName(key, column.name);
6513
- let colValue;
6514
- if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
6515
- colValue = this.editedRows[key][column.name];
6516
- }
6517
- else {
6518
- colValue = row[column.name];
6519
- }
6529
+ const colValue = this.getVisibleValue(row, column);
6520
6530
  const componentProps = merge__default["default"]({}, column.componentProps, cellProps === null || cellProps === void 0 ? void 0 : cellProps.componentProps);
6521
6531
  let compEvents = {};
6522
6532
  if (componentProps && componentProps.events) {
@@ -6657,7 +6667,9 @@
6657
6667
  */
6658
6668
  cancelEditedRows() {
6659
6669
  return __awaiter(this, void 0, void 0, function* () {
6670
+ const { page } = this.datasource;
6660
6671
  yield this.cancelAddedRows();
6672
+ yield this.datasource.setPage(page);
6661
6673
  this.editing = false;
6662
6674
  this.editedRows = {};
6663
6675
  this.invalidComponents = {};
@@ -6665,7 +6677,7 @@
6665
6677
  }
6666
6678
  cancelAddedRows() {
6667
6679
  return __awaiter(this, void 0, void 0, function* () {
6668
- const { data, page } = this.datasource;
6680
+ const { data } = this.datasource;
6669
6681
  const allData = this.datasource.allData || data;
6670
6682
  Promise.resolve(allData);
6671
6683
  for (let index = allData.length - 1; index >= 0; index -= 1) {
@@ -6675,8 +6687,6 @@
6675
6687
  }
6676
6688
  }
6677
6689
  yield this.datasource.updateData(allData);
6678
- yield this.datasource.get();
6679
- yield this.datasource.setPage(page);
6680
6690
  });
6681
6691
  }
6682
6692
  addDataRow(row) {
@@ -6692,6 +6702,7 @@
6692
6702
  */
6693
6703
  saveEditedRows(revalidate = false) {
6694
6704
  return __awaiter(this, void 0, void 0, function* () {
6705
+ const { page } = this.datasource;
6695
6706
  yield this.cancelAddedRows();
6696
6707
  const response = yield Promise.all(this.getEditedRows(revalidate).map((row) => this.addDataRow(row)));
6697
6708
  this.editing = false;
@@ -6699,7 +6710,7 @@
6699
6710
  this.addedRows = {};
6700
6711
  this.invalidComponents = {};
6701
6712
  this.addedRows = {};
6702
- yield this.datasource.get();
6713
+ yield this.datasource.setPage(page);
6703
6714
  return response;
6704
6715
  });
6705
6716
  }
@@ -6708,7 +6719,7 @@
6708
6719
  * @param revalidate Defines if the fields should be revalidated
6709
6720
  * @throws Will throw when it finds an invalid row
6710
6721
  */
6711
- getEditedRows(revalidate = false) {
6722
+ getEditedRows(revalidate = false, silent = false) {
6712
6723
  const editedRows = [];
6713
6724
  Object.keys(this.editedRows).forEach((key) => {
6714
6725
  const row = Object.assign(Object.assign({}, this.editedRows[key].originalRow), this.editedRows[key]);
@@ -6719,7 +6730,7 @@
6719
6730
  delete row[`${attr}_original`];
6720
6731
  }
6721
6732
  });
6722
- if (!this.isGridValid(revalidate)) {
6733
+ if (!silent && !this.isGridValid(revalidate)) {
6723
6734
  throw new Error('Invalid rows');
6724
6735
  }
6725
6736
  editedRows.push(row);
@@ -7483,13 +7494,27 @@
7483
7494
  const oldGet = this.datasource.get;
7484
7495
  this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
7485
7496
  const response = yield oldGet.call(this.datasource);
7497
+ if (!this.datasource.search && !this.manualMode) {
7498
+ this.cachedData = [...this.datasource.data];
7499
+ this.cachedTotal = this.datasource.total;
7500
+ }
7486
7501
  if (this.indexOf(this.value) === -1 && !this.datasource.search && !this.isFocused) {
7487
7502
  yield this.setValue(this.value, false);
7488
7503
  this.removePushedValue();
7489
7504
  }
7505
+ this.insertSelected();
7490
7506
  return response;
7491
7507
  });
7492
7508
  }
7509
+ insertSelected() {
7510
+ if (this.datasource.search || !this.pushedValue || this.indexOf(this.pushedValue) !== -1)
7511
+ return;
7512
+ const filterValue = this.pushedValue[this.dataValue];
7513
+ const foundInData = this.datasource.data.find(this.getCondition(filterValue));
7514
+ if (!foundInData) {
7515
+ this.datasource.data.unshift(this.pushedValue);
7516
+ }
7517
+ }
7493
7518
  get search() {
7494
7519
  return this.searchValue;
7495
7520
  }
@@ -7769,14 +7794,14 @@
7769
7794
  loadMore() {
7770
7795
  return __awaiter(this, void 0, void 0, function* () {
7771
7796
  yield this.datasource.setLimit(this.datasource.limit + this.loadMoreQtty);
7772
- if (!this.datasource.search) {
7773
- this.afterLoad();
7774
- const { dataValue } = this;
7775
- const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
7776
- if (isSelected)
7777
- return;
7778
- this.removePushedValue();
7779
- }
7797
+ if (this.datasource.search)
7798
+ return;
7799
+ this.afterLoad();
7800
+ const { dataValue } = this;
7801
+ const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
7802
+ if (isSelected)
7803
+ return;
7804
+ this.removePushedValue();
7780
7805
  });
7781
7806
  }
7782
7807
  /**
@@ -9885,7 +9910,6 @@
9885
9910
  const parsedValue = this.parserFn(value, this);
9886
9911
  if (parsedValue !== this.datasource.search) {
9887
9912
  yield this.datasource.setSearch(parsedValue);
9888
- this.insertSelected();
9889
9913
  }
9890
9914
  });
9891
9915
  }
@@ -9914,6 +9938,7 @@
9914
9938
  yield this.updateSearch(value);
9915
9939
  }
9916
9940
  else {
9941
+ this.datasource.search = value;
9917
9942
  if (!this.manualMode) {
9918
9943
  this.datasource.data = [...this.cachedData];
9919
9944
  this.datasource.total = this.cachedTotal;
@@ -9993,7 +10018,6 @@
9993
10018
  const foundInData = this.datasource.data.find(this.getCondition(value));
9994
10019
  return !foundInData;
9995
10020
  });
9996
- this.insertSelected();
9997
10021
  if (!this.datasource.search) {
9998
10022
  this.setCache();
9999
10023
  }
@@ -10065,9 +10089,6 @@
10065
10089
  return __awaiter(this, void 0, void 0, function* () {
10066
10090
  if (!this.preventLoadOnFocus) {
10067
10091
  yield this.datasource.get();
10068
- const values = this.datasource.data.map((row) => row[this.dataValue]);
10069
- // remove inserted items that are already in datasource
10070
- this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
10071
10092
  this.preventLoadOnFocus = true;
10072
10093
  }
10073
10094
  this.setCache();
@@ -12639,11 +12660,13 @@
12639
12660
  right: {
12640
12661
  event: this.navigateToggle.bind(this, false),
12641
12662
  stop: true,
12663
+ index: 99,
12642
12664
  active: true,
12643
12665
  },
12644
12666
  left: {
12645
12667
  event: this.navigateToggle.bind(this, true),
12646
12668
  stop: true,
12669
+ index: 99,
12647
12670
  active: true,
12648
12671
  },
12649
12672
  };
@@ -12880,6 +12903,7 @@
12880
12903
  * Editing rows
12881
12904
  */
12882
12905
  this.editing = false;
12906
+ this.singleEdit = false;
12883
12907
  /**
12884
12908
  * Edited rows
12885
12909
  * @private
@@ -12897,6 +12921,7 @@
12897
12921
  this.cancelEditedRowsKeyMapping = {
12898
12922
  esc: {
12899
12923
  event: this.cancelEditedRows.bind(this),
12924
+ index: 99,
12900
12925
  stop: true,
12901
12926
  input: true,
12902
12927
  active: true,
@@ -12904,6 +12929,7 @@
12904
12929
  };
12905
12930
  this.doubleClickEdit = this.getInitValue('doubleClickEdit', props.doubleClickEdit, this.doubleClickEdit);
12906
12931
  this.canEditRow = this.getInitValue('canEditRow', props.canEditRow, this.canEditRow);
12932
+ this.singleEdit = this.getInitValue('singleEdit', props.singleEdit, this.singleEdit);
12907
12933
  this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
12908
12934
  this.createAccessors();
12909
12935
  }
@@ -13013,6 +13039,13 @@
13013
13039
  });
13014
13040
  }
13015
13041
  }
13042
+ getVisibleValue(row, column) {
13043
+ const key = row[this.datasource.uniqueKey];
13044
+ if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
13045
+ return this.editedRows[key][column.name];
13046
+ }
13047
+ return row[column.name];
13048
+ }
13016
13049
  /**
13017
13050
  * Returns editable component properties based on the column definition
13018
13051
  * @param column Column definition
@@ -13023,13 +13056,7 @@
13023
13056
  getEditableComponent(column, row, cellProps, events) {
13024
13057
  const key = row[this.datasource.uniqueKey];
13025
13058
  const compName = this.getCompName(key, column.name);
13026
- let colValue;
13027
- if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
13028
- colValue = this.editedRows[key][column.name];
13029
- }
13030
- else {
13031
- colValue = row[column.name];
13032
- }
13059
+ const colValue = this.getVisibleValue(row, column);
13033
13060
  const componentProps = merge__default["default"]({}, column.componentProps, cellProps.componentProps);
13034
13061
  let compEvents = {};
13035
13062
  if (componentProps && componentProps.events) {
@@ -13125,10 +13152,24 @@
13125
13152
  * @param column Column
13126
13153
  * @param row Row
13127
13154
  */
13128
- isValid(column, row) {
13155
+ isValid(column, row, revalidate = false) {
13129
13156
  const key = row[this.datasource.uniqueKey];
13130
13157
  const compName = this.getCompName(key, column.name);
13131
- return !Object.prototype.hasOwnProperty.call(this.invalidComponents, compName);
13158
+ if (!revalidate) {
13159
+ return !Object.prototype.hasOwnProperty.call(this.invalidComponents, compName);
13160
+ }
13161
+ try {
13162
+ const input = this.getComponent(key, column.name);
13163
+ const isValid = input.validate();
13164
+ this.checkCompValidity(input);
13165
+ return isValid;
13166
+ }
13167
+ catch (e) {
13168
+ if (e instanceof core.InstanceNotFoundError) {
13169
+ return true;
13170
+ }
13171
+ throw e;
13172
+ }
13132
13173
  }
13133
13174
  /**
13134
13175
  * Cancels all edited rows and enable grid components
@@ -13171,7 +13212,7 @@
13171
13212
  * Retrieves all edited rows if they are valid
13172
13213
  * @throws Will throw when it finds an invalid row
13173
13214
  */
13174
- getEditedRows() {
13215
+ getEditedRows(revalidate = false, silent = false) {
13175
13216
  const editedRows = [];
13176
13217
  Object.keys(this.editedRows).forEach((key) => {
13177
13218
  const row = Object.assign(Object.assign({}, this.editedRows[key].originalRow), this.editedRows[key]);
@@ -13184,15 +13225,29 @@
13184
13225
  delete row[attr];
13185
13226
  }
13186
13227
  });
13187
- if (!this.isGridValid()) {
13228
+ if (!silent && !this.isGridValid(revalidate)) {
13188
13229
  throw new Error('Invalid rows');
13189
13230
  }
13190
13231
  editedRows.push(row);
13191
13232
  });
13192
13233
  return editedRows;
13193
13234
  }
13194
- isGridValid() {
13195
- return Object.keys(this.invalidComponents).length === 0;
13235
+ /**
13236
+ * Checks whether the grid is valid or not
13237
+ * @param revalidate Defines if the fields should be revalidated
13238
+ */
13239
+ isGridValid(revalidate = false) {
13240
+ if (!revalidate) {
13241
+ return Object.keys(this.invalidComponents).length === 0;
13242
+ }
13243
+ let allValid = true;
13244
+ this.datasource.data.forEach((row) => this.columns.forEach((column) => {
13245
+ if (!column.isVisible || !column.editable)
13246
+ return;
13247
+ if (!this.isValid(column, row, true))
13248
+ allValid = false;
13249
+ }));
13250
+ return allValid;
13196
13251
  }
13197
13252
  /**
13198
13253
  * Gets the editable component name
@@ -13868,7 +13923,7 @@
13868
13923
  else if (column.componentProps && Object.keys(column.componentProps).length) {
13869
13924
  const { component } = column.componentProps;
13870
13925
  if (this.isNumberComponent(component)) {
13871
- format = { type: 'float' };
13926
+ format = { type: 'float', params: {} };
13872
13927
  mask = this.checkAccessor(column.componentProps.mask);
13873
13928
  if (mask) {
13874
13929
  format.params = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.88.0",
3
+ "version": "1.89.0",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -43,5 +43,5 @@
43
43
  "lodash.times": "4.3.*",
44
44
  "mockdate": "3.0.*"
45
45
  },
46
- "gitHead": "b9e30e705a88fa882c1fbdf140c15cc7c47c7c87"
46
+ "gitHead": "338bd948c7d990ff8ca1c26470b5da2220f10730"
47
47
  }
@@ -1,5 +1,6 @@
1
- import { IDictionary } from '@zeedhi/core';
1
+ import { IDictionary, IKeyMap } from '@zeedhi/core';
2
2
  import { IGridColumnEditable, IGridEditable } from './interfaces';
3
+ import { Input } from '../zd-input/input';
3
4
  import { Grid } from '..';
4
5
  import { GridColumnEditable } from './grid-column-editable';
5
6
  /**
@@ -25,6 +26,7 @@ export declare class GridEditable extends Grid implements IGridEditable {
25
26
  row: IDictionary<any>;
26
27
  component: GridEditable;
27
28
  }) => boolean;
29
+ singleEdit: boolean;
28
30
  /**
29
31
  * Edited rows
30
32
  * @private
@@ -41,7 +43,7 @@ export declare class GridEditable extends Grid implements IGridEditable {
41
43
  */
42
44
  private invalidComponents;
43
45
  editingNewRows: boolean;
44
- protected cancelEditedRowsKeyMapping: any;
46
+ protected cancelEditedRowsKeyMapping: IKeyMap;
45
47
  constructor(props: IGridEditable);
46
48
  onMounted(element: any): void;
47
49
  onBeforeDestroy(): void;
@@ -87,6 +89,7 @@ export declare class GridEditable extends Grid implements IGridEditable {
87
89
  * @param element DOM Element
88
90
  */
89
91
  selectAllClick(isSelected: boolean, event: Event, element: any): void;
92
+ getVisibleValue(row: IDictionary, column: IGridColumnEditable): any;
90
93
  /**
91
94
  * Returns editable component properties based on the column definition
92
95
  * @param column Column definition
@@ -111,7 +114,7 @@ export declare class GridEditable extends Grid implements IGridEditable {
111
114
  /**
112
115
  * change event of editable components
113
116
  */
114
- private changeEditableComponent;
117
+ protected changeEditableComponent(column: IGridColumnEditable, row: IDictionary<any>, value: any, component?: Input): void;
115
118
  private updateOriginalRow;
116
119
  /**
117
120
  * Checks if column is edited
@@ -143,7 +146,7 @@ export declare class GridEditable extends Grid implements IGridEditable {
143
146
  * @param revalidate Defines if the fields should be revalidated
144
147
  * @throws Will throw when it finds an invalid row
145
148
  */
146
- getEditedRows(revalidate?: boolean): IDictionary<any>[];
149
+ getEditedRows(revalidate?: boolean, silent?: boolean): IDictionary<any>[];
147
150
  /**
148
151
  * Checks whether the grid is valid or not
149
152
  * @param revalidate Defines if the fields should be revalidated
@@ -1,4 +1,4 @@
1
- import { IDictionary } from '@zeedhi/core';
1
+ import { IDictionary, IKeyMap } from '@zeedhi/core';
2
2
  import { Component } from '../zd-component/component';
3
3
  import { IComponent, IComponentRender } from '../zd-component/interfaces';
4
4
  import { Iterable } from '../zd-iterable/iterable';
@@ -145,7 +145,7 @@ export declare class Grid extends Iterable implements IGrid {
145
145
  * @param props Grid properties
146
146
  */
147
147
  constructor(props: IGrid);
148
- protected navigationKeyMapping: any;
148
+ protected navigationKeyMapping: IKeyMap;
149
149
  onMounted(element: any): void;
150
150
  onBeforeDestroy(): void;
151
151
  /**
@@ -64,6 +64,7 @@ export interface IGridEditable extends IGrid {
64
64
  columns?: IGridColumnEditable[];
65
65
  doubleClickEdit?: boolean;
66
66
  events?: IGridEditableEvents;
67
+ singleEdit?: boolean;
67
68
  canEditRow?: (args: {
68
69
  row: IDictionary<any>;
69
70
  component: GridEditable;
@@ -123,6 +123,7 @@ export declare class Select extends TextInput implements ISelect {
123
123
  */
124
124
  private getDefaultDatasource;
125
125
  overrideGet(): void;
126
+ protected insertSelected(): void;
126
127
  get search(): string;
127
128
  set search(value: string);
128
129
  /**
@@ -66,7 +66,7 @@ export declare class SelectMultiple extends Select implements ISelectMultiple {
66
66
  /**
67
67
  * Inserts selected items in datasource
68
68
  */
69
- private insertSelected;
69
+ protected insertSelected(): void;
70
70
  protected removePushedValue(): void;
71
71
  protected doSearch(value: string): Promise<void>;
72
72
  /**
@@ -13,6 +13,7 @@ export interface ITreeGridEditable extends ITreeGrid {
13
13
  columns?: IGridColumnEditable[];
14
14
  doubleClickEdit?: boolean;
15
15
  events?: IGridEditableEvents;
16
+ singleEdit?: boolean;
16
17
  canEditRow?: (args: {
17
18
  row: IDictionary<any>;
18
19
  component: TreeGridEditable;
@@ -19,6 +19,7 @@ export declare class TreeGridEditable extends TreeGrid implements ITreeGridEdita
19
19
  row: IDictionary<any>;
20
20
  component: TreeGridEditable;
21
21
  }) => boolean;
22
+ singleEdit: boolean;
22
23
  /**
23
24
  * Edited rows
24
25
  * @private
@@ -79,6 +80,7 @@ export declare class TreeGridEditable extends TreeGrid implements ITreeGridEdita
79
80
  * @param element DOM Element
80
81
  */
81
82
  selectAllClick(isSelected: boolean, event?: Event, element?: any): void;
83
+ getVisibleValue(row: IDictionary, column: IGridColumnEditable): any;
82
84
  /**
83
85
  * Returns editable component properties based on the column definition
84
86
  * @param column Column definition
@@ -116,7 +118,7 @@ export declare class TreeGridEditable extends TreeGrid implements ITreeGridEdita
116
118
  * @param column Column
117
119
  * @param row Row
118
120
  */
119
- isValid(column: IGridColumnEditable, row: IDictionary): boolean;
121
+ isValid(column: IGridColumnEditable, row: IDictionary, revalidate?: boolean): boolean;
120
122
  /**
121
123
  * Cancels all edited rows and enable grid components
122
124
  */
@@ -135,8 +137,12 @@ export declare class TreeGridEditable extends TreeGrid implements ITreeGridEdita
135
137
  * Retrieves all edited rows if they are valid
136
138
  * @throws Will throw when it finds an invalid row
137
139
  */
138
- getEditedRows(): IDictionary<any>[];
139
- isGridValid(): boolean;
140
+ getEditedRows(revalidate?: boolean, silent?: boolean): IDictionary<any>[];
141
+ /**
142
+ * Checks whether the grid is valid or not
143
+ * @param revalidate Defines if the fields should be revalidated
144
+ */
145
+ isGridValid(revalidate?: boolean): boolean;
140
146
  /**
141
147
  * Gets the editable component name
142
148
  * @param key Row unique key