@zeedhi/common 1.88.1 → 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.
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Zeedhi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ This repository includes one file originally copied from https://github.com/vuetifyjs/vuetify/
24
+ under /blob/v1.5.16/packages/vuetify/src/util/, mask.ts.
@@ -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);
@@ -7484,16 +7495,19 @@ class Select extends TextInput {
7484
7495
  yield this.setValue(this.value, false);
7485
7496
  this.removePushedValue();
7486
7497
  }
7487
- if (this.pushedValue && this.indexOf(this.pushedValue) === -1) {
7488
- const filterValue = this.pushedValue[this.dataValue];
7489
- const foundInData = this.datasource.data.find(this.getCondition(filterValue));
7490
- if (!foundInData) {
7491
- this.datasource.data.unshift(this.pushedValue);
7492
- }
7493
- }
7498
+ this.insertSelected();
7494
7499
  return response;
7495
7500
  });
7496
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
+ }
7497
7511
  get search() {
7498
7512
  return this.searchValue;
7499
7513
  }
@@ -7773,14 +7787,14 @@ class Select extends TextInput {
7773
7787
  loadMore() {
7774
7788
  return __awaiter(this, void 0, void 0, function* () {
7775
7789
  yield this.datasource.setLimit(this.datasource.limit + this.loadMoreQtty);
7776
- if (!this.datasource.search) {
7777
- this.afterLoad();
7778
- const { dataValue } = this;
7779
- const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
7780
- if (isSelected)
7781
- return;
7782
- this.removePushedValue();
7783
- }
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();
7784
7798
  });
7785
7799
  }
7786
7800
  /**
@@ -9889,7 +9903,6 @@ class SelectMultiple extends Select {
9889
9903
  const parsedValue = this.parserFn(value, this);
9890
9904
  if (parsedValue !== this.datasource.search) {
9891
9905
  yield this.datasource.setSearch(parsedValue);
9892
- this.insertSelected();
9893
9906
  }
9894
9907
  });
9895
9908
  }
@@ -9918,6 +9931,7 @@ class SelectMultiple extends Select {
9918
9931
  yield this.updateSearch(value);
9919
9932
  }
9920
9933
  else {
9934
+ this.datasource.search = value;
9921
9935
  if (!this.manualMode) {
9922
9936
  this.datasource.data = [...this.cachedData];
9923
9937
  this.datasource.total = this.cachedTotal;
@@ -9997,7 +10011,6 @@ class SelectMultiple extends Select {
9997
10011
  const foundInData = this.datasource.data.find(this.getCondition(value));
9998
10012
  return !foundInData;
9999
10013
  });
10000
- this.insertSelected();
10001
10014
  if (!this.datasource.search) {
10002
10015
  this.setCache();
10003
10016
  }
@@ -10069,9 +10082,6 @@ class SelectMultiple extends Select {
10069
10082
  return __awaiter(this, void 0, void 0, function* () {
10070
10083
  if (!this.preventLoadOnFocus) {
10071
10084
  yield this.datasource.get();
10072
- const values = this.datasource.data.map((row) => row[this.dataValue]);
10073
- // remove inserted items that are already in datasource
10074
- this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
10075
10085
  this.preventLoadOnFocus = true;
10076
10086
  }
10077
10087
  this.setCache();
@@ -12643,11 +12653,13 @@ class TreeGrid extends Grid {
12643
12653
  right: {
12644
12654
  event: this.navigateToggle.bind(this, false),
12645
12655
  stop: true,
12656
+ index: 99,
12646
12657
  active: true,
12647
12658
  },
12648
12659
  left: {
12649
12660
  event: this.navigateToggle.bind(this, true),
12650
12661
  stop: true,
12662
+ index: 99,
12651
12663
  active: true,
12652
12664
  },
12653
12665
  };
@@ -12884,6 +12896,7 @@ class TreeGridEditable extends TreeGrid {
12884
12896
  * Editing rows
12885
12897
  */
12886
12898
  this.editing = false;
12899
+ this.singleEdit = false;
12887
12900
  /**
12888
12901
  * Edited rows
12889
12902
  * @private
@@ -12901,6 +12914,7 @@ class TreeGridEditable extends TreeGrid {
12901
12914
  this.cancelEditedRowsKeyMapping = {
12902
12915
  esc: {
12903
12916
  event: this.cancelEditedRows.bind(this),
12917
+ index: 99,
12904
12918
  stop: true,
12905
12919
  input: true,
12906
12920
  active: true,
@@ -12908,6 +12922,7 @@ class TreeGridEditable extends TreeGrid {
12908
12922
  };
12909
12923
  this.doubleClickEdit = this.getInitValue('doubleClickEdit', props.doubleClickEdit, this.doubleClickEdit);
12910
12924
  this.canEditRow = this.getInitValue('canEditRow', props.canEditRow, this.canEditRow);
12925
+ this.singleEdit = this.getInitValue('singleEdit', props.singleEdit, this.singleEdit);
12911
12926
  this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
12912
12927
  this.createAccessors();
12913
12928
  }
@@ -13017,6 +13032,13 @@ class TreeGridEditable extends TreeGrid {
13017
13032
  });
13018
13033
  }
13019
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
+ }
13020
13042
  /**
13021
13043
  * Returns editable component properties based on the column definition
13022
13044
  * @param column Column definition
@@ -13027,13 +13049,7 @@ class TreeGridEditable extends TreeGrid {
13027
13049
  getEditableComponent(column, row, cellProps, events) {
13028
13050
  const key = row[this.datasource.uniqueKey];
13029
13051
  const compName = this.getCompName(key, column.name);
13030
- let colValue;
13031
- if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
13032
- colValue = this.editedRows[key][column.name];
13033
- }
13034
- else {
13035
- colValue = row[column.name];
13036
- }
13052
+ const colValue = this.getVisibleValue(row, column);
13037
13053
  const componentProps = merge({}, column.componentProps, cellProps.componentProps);
13038
13054
  let compEvents = {};
13039
13055
  if (componentProps && componentProps.events) {
@@ -13129,10 +13145,24 @@ class TreeGridEditable extends TreeGrid {
13129
13145
  * @param column Column
13130
13146
  * @param row Row
13131
13147
  */
13132
- isValid(column, row) {
13148
+ isValid(column, row, revalidate = false) {
13133
13149
  const key = row[this.datasource.uniqueKey];
13134
13150
  const compName = this.getCompName(key, column.name);
13135
- 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
+ }
13136
13166
  }
13137
13167
  /**
13138
13168
  * Cancels all edited rows and enable grid components
@@ -13175,7 +13205,7 @@ class TreeGridEditable extends TreeGrid {
13175
13205
  * Retrieves all edited rows if they are valid
13176
13206
  * @throws Will throw when it finds an invalid row
13177
13207
  */
13178
- getEditedRows() {
13208
+ getEditedRows(revalidate = false, silent = false) {
13179
13209
  const editedRows = [];
13180
13210
  Object.keys(this.editedRows).forEach((key) => {
13181
13211
  const row = Object.assign(Object.assign({}, this.editedRows[key].originalRow), this.editedRows[key]);
@@ -13188,15 +13218,29 @@ class TreeGridEditable extends TreeGrid {
13188
13218
  delete row[attr];
13189
13219
  }
13190
13220
  });
13191
- if (!this.isGridValid()) {
13221
+ if (!silent && !this.isGridValid(revalidate)) {
13192
13222
  throw new Error('Invalid rows');
13193
13223
  }
13194
13224
  editedRows.push(row);
13195
13225
  });
13196
13226
  return editedRows;
13197
13227
  }
13198
- isGridValid() {
13199
- 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;
13200
13244
  }
13201
13245
  /**
13202
13246
  * Gets the editable component name
@@ -13872,7 +13916,7 @@ class PDFReport extends BaseReport {
13872
13916
  else if (column.componentProps && Object.keys(column.componentProps).length) {
13873
13917
  const { component } = column.componentProps;
13874
13918
  if (this.isNumberComponent(component)) {
13875
- format = { type: 'float' };
13919
+ format = { type: 'float', params: {} };
13876
13920
  mask = this.checkAccessor(column.componentProps.mask);
13877
13921
  if (mask) {
13878
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);
@@ -7491,16 +7502,19 @@
7491
7502
  yield this.setValue(this.value, false);
7492
7503
  this.removePushedValue();
7493
7504
  }
7494
- if (this.pushedValue && this.indexOf(this.pushedValue) === -1) {
7495
- const filterValue = this.pushedValue[this.dataValue];
7496
- const foundInData = this.datasource.data.find(this.getCondition(filterValue));
7497
- if (!foundInData) {
7498
- this.datasource.data.unshift(this.pushedValue);
7499
- }
7500
- }
7505
+ this.insertSelected();
7501
7506
  return response;
7502
7507
  });
7503
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
+ }
7504
7518
  get search() {
7505
7519
  return this.searchValue;
7506
7520
  }
@@ -7780,14 +7794,14 @@
7780
7794
  loadMore() {
7781
7795
  return __awaiter(this, void 0, void 0, function* () {
7782
7796
  yield this.datasource.setLimit(this.datasource.limit + this.loadMoreQtty);
7783
- if (!this.datasource.search) {
7784
- this.afterLoad();
7785
- const { dataValue } = this;
7786
- const isSelected = this.selectValue && this.pushedValue && this.selectValue[dataValue] === this.pushedValue[dataValue];
7787
- if (isSelected)
7788
- return;
7789
- this.removePushedValue();
7790
- }
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();
7791
7805
  });
7792
7806
  }
7793
7807
  /**
@@ -9896,7 +9910,6 @@
9896
9910
  const parsedValue = this.parserFn(value, this);
9897
9911
  if (parsedValue !== this.datasource.search) {
9898
9912
  yield this.datasource.setSearch(parsedValue);
9899
- this.insertSelected();
9900
9913
  }
9901
9914
  });
9902
9915
  }
@@ -9925,6 +9938,7 @@
9925
9938
  yield this.updateSearch(value);
9926
9939
  }
9927
9940
  else {
9941
+ this.datasource.search = value;
9928
9942
  if (!this.manualMode) {
9929
9943
  this.datasource.data = [...this.cachedData];
9930
9944
  this.datasource.total = this.cachedTotal;
@@ -10004,7 +10018,6 @@
10004
10018
  const foundInData = this.datasource.data.find(this.getCondition(value));
10005
10019
  return !foundInData;
10006
10020
  });
10007
- this.insertSelected();
10008
10021
  if (!this.datasource.search) {
10009
10022
  this.setCache();
10010
10023
  }
@@ -10076,9 +10089,6 @@
10076
10089
  return __awaiter(this, void 0, void 0, function* () {
10077
10090
  if (!this.preventLoadOnFocus) {
10078
10091
  yield this.datasource.get();
10079
- const values = this.datasource.data.map((row) => row[this.dataValue]);
10080
- // remove inserted items that are already in datasource
10081
- this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
10082
10092
  this.preventLoadOnFocus = true;
10083
10093
  }
10084
10094
  this.setCache();
@@ -12650,11 +12660,13 @@
12650
12660
  right: {
12651
12661
  event: this.navigateToggle.bind(this, false),
12652
12662
  stop: true,
12663
+ index: 99,
12653
12664
  active: true,
12654
12665
  },
12655
12666
  left: {
12656
12667
  event: this.navigateToggle.bind(this, true),
12657
12668
  stop: true,
12669
+ index: 99,
12658
12670
  active: true,
12659
12671
  },
12660
12672
  };
@@ -12891,6 +12903,7 @@
12891
12903
  * Editing rows
12892
12904
  */
12893
12905
  this.editing = false;
12906
+ this.singleEdit = false;
12894
12907
  /**
12895
12908
  * Edited rows
12896
12909
  * @private
@@ -12908,6 +12921,7 @@
12908
12921
  this.cancelEditedRowsKeyMapping = {
12909
12922
  esc: {
12910
12923
  event: this.cancelEditedRows.bind(this),
12924
+ index: 99,
12911
12925
  stop: true,
12912
12926
  input: true,
12913
12927
  active: true,
@@ -12915,6 +12929,7 @@
12915
12929
  };
12916
12930
  this.doubleClickEdit = this.getInitValue('doubleClickEdit', props.doubleClickEdit, this.doubleClickEdit);
12917
12931
  this.canEditRow = this.getInitValue('canEditRow', props.canEditRow, this.canEditRow);
12932
+ this.singleEdit = this.getInitValue('singleEdit', props.singleEdit, this.singleEdit);
12918
12933
  this.noDataSlot = this.changeDefaultSlotNames(this.noDataSlot);
12919
12934
  this.createAccessors();
12920
12935
  }
@@ -13024,6 +13039,13 @@
13024
13039
  });
13025
13040
  }
13026
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
+ }
13027
13049
  /**
13028
13050
  * Returns editable component properties based on the column definition
13029
13051
  * @param column Column definition
@@ -13034,13 +13056,7 @@
13034
13056
  getEditableComponent(column, row, cellProps, events) {
13035
13057
  const key = row[this.datasource.uniqueKey];
13036
13058
  const compName = this.getCompName(key, column.name);
13037
- let colValue;
13038
- if (this.editedRows[key] && Object.prototype.hasOwnProperty.call(this.editedRows[key], column.name)) {
13039
- colValue = this.editedRows[key][column.name];
13040
- }
13041
- else {
13042
- colValue = row[column.name];
13043
- }
13059
+ const colValue = this.getVisibleValue(row, column);
13044
13060
  const componentProps = merge__default["default"]({}, column.componentProps, cellProps.componentProps);
13045
13061
  let compEvents = {};
13046
13062
  if (componentProps && componentProps.events) {
@@ -13136,10 +13152,24 @@
13136
13152
  * @param column Column
13137
13153
  * @param row Row
13138
13154
  */
13139
- isValid(column, row) {
13155
+ isValid(column, row, revalidate = false) {
13140
13156
  const key = row[this.datasource.uniqueKey];
13141
13157
  const compName = this.getCompName(key, column.name);
13142
- 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
+ }
13143
13173
  }
13144
13174
  /**
13145
13175
  * Cancels all edited rows and enable grid components
@@ -13182,7 +13212,7 @@
13182
13212
  * Retrieves all edited rows if they are valid
13183
13213
  * @throws Will throw when it finds an invalid row
13184
13214
  */
13185
- getEditedRows() {
13215
+ getEditedRows(revalidate = false, silent = false) {
13186
13216
  const editedRows = [];
13187
13217
  Object.keys(this.editedRows).forEach((key) => {
13188
13218
  const row = Object.assign(Object.assign({}, this.editedRows[key].originalRow), this.editedRows[key]);
@@ -13195,15 +13225,29 @@
13195
13225
  delete row[attr];
13196
13226
  }
13197
13227
  });
13198
- if (!this.isGridValid()) {
13228
+ if (!silent && !this.isGridValid(revalidate)) {
13199
13229
  throw new Error('Invalid rows');
13200
13230
  }
13201
13231
  editedRows.push(row);
13202
13232
  });
13203
13233
  return editedRows;
13204
13234
  }
13205
- isGridValid() {
13206
- 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;
13207
13251
  }
13208
13252
  /**
13209
13253
  * Gets the editable component name
@@ -13879,7 +13923,7 @@
13879
13923
  else if (column.componentProps && Object.keys(column.componentProps).length) {
13880
13924
  const { component } = column.componentProps;
13881
13925
  if (this.isNumberComponent(component)) {
13882
- format = { type: 'float' };
13926
+ format = { type: 'float', params: {} };
13883
13927
  mask = this.checkAccessor(column.componentProps.mask);
13884
13928
  if (mask) {
13885
13929
  format.params = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.88.1",
3
+ "version": "1.89.0",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -42,5 +42,6 @@
42
42
  "@types/lodash.times": "4.3.*",
43
43
  "lodash.times": "4.3.*",
44
44
  "mockdate": "3.0.*"
45
- }
45
+ },
46
+ "gitHead": "338bd948c7d990ff8ca1c26470b5da2220f10730"
46
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
@@ -0,0 +1,12 @@
1
+ export interface IJSONObject {
2
+ path: string;
3
+ }
4
+ export declare class JsonCacheService {
5
+ /**
6
+ * jsons collection
7
+ */
8
+ static jsonCollection: IJSONObject[];
9
+ static saveJSONCache(jsonCollection: IJSONObject[]): Promise<void>;
10
+ static getJSONCache(path: string): any;
11
+ static clearJSONCache(jsonCollection: IJSONObject[]): void;
12
+ }