@zeedhi/common 1.83.1 → 1.83.2

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.
@@ -7418,10 +7418,21 @@ class Select extends TextInput {
7418
7418
  const oldGet = this.datasource.get;
7419
7419
  this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
7420
7420
  const response = yield oldGet.call(this.datasource);
7421
+ if (!this.datasource.search && !this.manualMode) {
7422
+ this.cachedData = [...this.datasource.data];
7423
+ this.cachedTotal = this.datasource.total;
7424
+ }
7421
7425
  if (this.indexOf(this.value) === -1 && !this.datasource.search && !this.isFocused) {
7422
7426
  yield this.setValue(this.value, false);
7423
7427
  this.removePushedValue();
7424
7428
  }
7429
+ if (this.pushedValue && this.indexOf(this.pushedValue) === -1) {
7430
+ const filterValue = this.pushedValue[this.dataValue];
7431
+ const foundInData = this.datasource.data.find(this.getCondition(filterValue));
7432
+ if (!foundInData) {
7433
+ this.datasource.data.unshift(this.pushedValue);
7434
+ }
7435
+ }
7425
7436
  return response;
7426
7437
  });
7427
7438
  }
@@ -7688,10 +7699,13 @@ class Select extends TextInput {
7688
7699
  yield this.updateSearch(value);
7689
7700
  }
7690
7701
  else {
7691
- this.removePushedValue();
7692
- this.datasource.search = this.searchValue;
7693
7702
  this.datasource.data = [...this.cachedData];
7694
7703
  this.datasource.total = this.cachedTotal;
7704
+ this.datasource.search = value;
7705
+ this.removePushedValue();
7706
+ if (this.preventLoadOnFocus) {
7707
+ yield this.datasource.get();
7708
+ }
7695
7709
  }
7696
7710
  });
7697
7711
  }
@@ -7775,7 +7789,7 @@ FormatterParserProvider.registerFormatter('ZdSelect', (value, { dataText, dataTe
7775
7789
  const dataTextArr = Array.isArray(dataText) ? dataText : [dataText];
7776
7790
  const dataTextNames = [];
7777
7791
  const masks = [];
7778
- dataTextArr.forEach((text) => {
7792
+ dataTextArr.map((text) => {
7779
7793
  if (typeof text === 'string') {
7780
7794
  dataTextNames.push(text);
7781
7795
  masks.push('');
@@ -7790,6 +7804,7 @@ FormatterParserProvider.registerFormatter('ZdSelect', (value, { dataText, dataTe
7790
7804
  masks.push(text.mask);
7791
7805
  }
7792
7806
  }
7807
+ return null;
7793
7808
  });
7794
7809
  return dataTextNames.reduce((result, column, index) => {
7795
7810
  if (value[column] !== null && value[column] !== undefined) {
@@ -9677,10 +9692,6 @@ class SelectMultiple extends Select {
9677
9692
  return __awaiter(this, void 0, void 0, function* () {
9678
9693
  if (!this.preventLoadOnFocus) {
9679
9694
  yield this.datasource.get();
9680
- const values = this.datasource.data.map((row) => row[this.dataValue]);
9681
- // remove inserted items that are already in datasource
9682
- this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
9683
- this.preventLoadOnFocus = true;
9684
9695
  }
9685
9696
  this.setCache();
9686
9697
  this.updateSearch(this.dirtySearchValue);
@@ -9700,6 +9711,13 @@ class SelectMultiple extends Select {
9700
9711
  }
9701
9712
  this.cachedTotal = this.datasource.total;
9702
9713
  }
9714
+ overrideGet() {
9715
+ const oldGet = this.datasource.get;
9716
+ this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
9717
+ yield oldGet.call(this.datasource);
9718
+ this.setItemsOnSelect();
9719
+ });
9720
+ }
9703
9721
  /**
9704
9722
  * Field selected rows
9705
9723
  */
@@ -9728,9 +9746,7 @@ class SelectMultiple extends Select {
9728
9746
  */
9729
9747
  cutFromAToB(a, b, condition) {
9730
9748
  const indices = a.reduce((result, value, index) => (condition(value) ? [...result, index] : result), []);
9731
- indices.forEach((index) => {
9732
- b.push(a.splice(index, 1)[0]);
9733
- });
9749
+ indices.map((index) => b.push(a.splice(index, 1)[0]));
9734
9750
  }
9735
9751
  setFieldValue(value) {
9736
9752
  return __awaiter(this, void 0, void 0, function* () {
@@ -9833,12 +9849,14 @@ class SelectMultiple extends Select {
9833
9849
  const parsedValue = this.parserFn(value, this);
9834
9850
  if (parsedValue !== this.datasource.search) {
9835
9851
  yield this.datasource.setSearch(parsedValue);
9836
- this.insertSelected();
9837
9852
  }
9838
9853
  });
9839
9854
  }
9840
9855
  /**
9841
- * Inserts selected items in datasource
9856
+ * Inserts selected items in datasource.
9857
+ * This method will validate, for every selected value, if it is present in datasource:
9858
+ * if it is, removes from insertedValues
9859
+ * if not, add to insertedValues
9842
9860
  */
9843
9861
  insertSelected() {
9844
9862
  if (this.manualMode)
@@ -9862,10 +9880,9 @@ class SelectMultiple extends Select {
9862
9880
  yield this.updateSearch(value);
9863
9881
  }
9864
9882
  else {
9865
- if (!this.manualMode) {
9866
- this.datasource.data = [...this.cachedData];
9867
- this.datasource.total = this.cachedTotal;
9868
- }
9883
+ this.datasource.data = [...this.cachedData];
9884
+ this.datasource.total = this.cachedTotal;
9885
+ this.datasource.search = value;
9869
9886
  this.removeInserts();
9870
9887
  this.insertSelected();
9871
9888
  }
@@ -9891,7 +9908,7 @@ class SelectMultiple extends Select {
9891
9908
  }
9892
9909
  const dataTextNames = [];
9893
9910
  const masks = [];
9894
- this.dataText.forEach((text) => {
9911
+ this.dataText.map((text) => {
9895
9912
  if (typeof text === 'string') {
9896
9913
  dataTextNames.push(text);
9897
9914
  masks.push('');
@@ -9900,6 +9917,7 @@ class SelectMultiple extends Select {
9900
9917
  dataTextNames.push(text.name);
9901
9918
  masks.push(text.mask);
9902
9919
  }
9920
+ return text;
9903
9921
  });
9904
9922
  const formattedValue = value.map((row) => {
9905
9923
  const isDisabled = this.dataDisabled && row[this.dataDisabled];
@@ -9941,10 +9959,6 @@ class SelectMultiple extends Select {
9941
9959
  const foundInData = this.datasource.data.find(this.getCondition(value));
9942
9960
  return !foundInData;
9943
9961
  });
9944
- this.insertSelected();
9945
- if (!this.datasource.search) {
9946
- this.setCache();
9947
- }
9948
9962
  this.removePushedValue();
9949
9963
  });
9950
9964
  }
@@ -10005,6 +10019,16 @@ class SelectMultiple extends Select {
10005
10019
  }
10006
10020
  });
10007
10021
  }
10022
+ setItemsOnSelect() {
10023
+ const values = this.datasource.data.map((row) => row[this.dataValue]);
10024
+ // remove inserted items that are already in datasource
10025
+ this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
10026
+ this.preventLoadOnFocus = true;
10027
+ this.insertSelected();
10028
+ if (!this.datasource.search) {
10029
+ this.setCache();
10030
+ }
10031
+ }
10008
10032
  checkValueOnBlur() { }
10009
10033
  }
10010
10034
 
@@ -7425,10 +7425,21 @@
7425
7425
  const oldGet = this.datasource.get;
7426
7426
  this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
7427
7427
  const response = yield oldGet.call(this.datasource);
7428
+ if (!this.datasource.search && !this.manualMode) {
7429
+ this.cachedData = [...this.datasource.data];
7430
+ this.cachedTotal = this.datasource.total;
7431
+ }
7428
7432
  if (this.indexOf(this.value) === -1 && !this.datasource.search && !this.isFocused) {
7429
7433
  yield this.setValue(this.value, false);
7430
7434
  this.removePushedValue();
7431
7435
  }
7436
+ if (this.pushedValue && this.indexOf(this.pushedValue) === -1) {
7437
+ const filterValue = this.pushedValue[this.dataValue];
7438
+ const foundInData = this.datasource.data.find(this.getCondition(filterValue));
7439
+ if (!foundInData) {
7440
+ this.datasource.data.unshift(this.pushedValue);
7441
+ }
7442
+ }
7432
7443
  return response;
7433
7444
  });
7434
7445
  }
@@ -7695,10 +7706,13 @@
7695
7706
  yield this.updateSearch(value);
7696
7707
  }
7697
7708
  else {
7698
- this.removePushedValue();
7699
- this.datasource.search = this.searchValue;
7700
7709
  this.datasource.data = [...this.cachedData];
7701
7710
  this.datasource.total = this.cachedTotal;
7711
+ this.datasource.search = value;
7712
+ this.removePushedValue();
7713
+ if (this.preventLoadOnFocus) {
7714
+ yield this.datasource.get();
7715
+ }
7702
7716
  }
7703
7717
  });
7704
7718
  }
@@ -7782,7 +7796,7 @@
7782
7796
  const dataTextArr = Array.isArray(dataText) ? dataText : [dataText];
7783
7797
  const dataTextNames = [];
7784
7798
  const masks = [];
7785
- dataTextArr.forEach((text) => {
7799
+ dataTextArr.map((text) => {
7786
7800
  if (typeof text === 'string') {
7787
7801
  dataTextNames.push(text);
7788
7802
  masks.push('');
@@ -7797,6 +7811,7 @@
7797
7811
  masks.push(text.mask);
7798
7812
  }
7799
7813
  }
7814
+ return null;
7800
7815
  });
7801
7816
  return dataTextNames.reduce((result, column, index) => {
7802
7817
  if (value[column] !== null && value[column] !== undefined) {
@@ -9684,10 +9699,6 @@
9684
9699
  return __awaiter(this, void 0, void 0, function* () {
9685
9700
  if (!this.preventLoadOnFocus) {
9686
9701
  yield this.datasource.get();
9687
- const values = this.datasource.data.map((row) => row[this.dataValue]);
9688
- // remove inserted items that are already in datasource
9689
- this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
9690
- this.preventLoadOnFocus = true;
9691
9702
  }
9692
9703
  this.setCache();
9693
9704
  this.updateSearch(this.dirtySearchValue);
@@ -9707,6 +9718,13 @@
9707
9718
  }
9708
9719
  this.cachedTotal = this.datasource.total;
9709
9720
  }
9721
+ overrideGet() {
9722
+ const oldGet = this.datasource.get;
9723
+ this.datasource.get = () => __awaiter(this, void 0, void 0, function* () {
9724
+ yield oldGet.call(this.datasource);
9725
+ this.setItemsOnSelect();
9726
+ });
9727
+ }
9710
9728
  /**
9711
9729
  * Field selected rows
9712
9730
  */
@@ -9735,9 +9753,7 @@
9735
9753
  */
9736
9754
  cutFromAToB(a, b, condition) {
9737
9755
  const indices = a.reduce((result, value, index) => (condition(value) ? [...result, index] : result), []);
9738
- indices.forEach((index) => {
9739
- b.push(a.splice(index, 1)[0]);
9740
- });
9756
+ indices.map((index) => b.push(a.splice(index, 1)[0]));
9741
9757
  }
9742
9758
  setFieldValue(value) {
9743
9759
  return __awaiter(this, void 0, void 0, function* () {
@@ -9840,12 +9856,14 @@
9840
9856
  const parsedValue = this.parserFn(value, this);
9841
9857
  if (parsedValue !== this.datasource.search) {
9842
9858
  yield this.datasource.setSearch(parsedValue);
9843
- this.insertSelected();
9844
9859
  }
9845
9860
  });
9846
9861
  }
9847
9862
  /**
9848
- * Inserts selected items in datasource
9863
+ * Inserts selected items in datasource.
9864
+ * This method will validate, for every selected value, if it is present in datasource:
9865
+ * if it is, removes from insertedValues
9866
+ * if not, add to insertedValues
9849
9867
  */
9850
9868
  insertSelected() {
9851
9869
  if (this.manualMode)
@@ -9869,10 +9887,9 @@
9869
9887
  yield this.updateSearch(value);
9870
9888
  }
9871
9889
  else {
9872
- if (!this.manualMode) {
9873
- this.datasource.data = [...this.cachedData];
9874
- this.datasource.total = this.cachedTotal;
9875
- }
9890
+ this.datasource.data = [...this.cachedData];
9891
+ this.datasource.total = this.cachedTotal;
9892
+ this.datasource.search = value;
9876
9893
  this.removeInserts();
9877
9894
  this.insertSelected();
9878
9895
  }
@@ -9898,7 +9915,7 @@
9898
9915
  }
9899
9916
  const dataTextNames = [];
9900
9917
  const masks = [];
9901
- this.dataText.forEach((text) => {
9918
+ this.dataText.map((text) => {
9902
9919
  if (typeof text === 'string') {
9903
9920
  dataTextNames.push(text);
9904
9921
  masks.push('');
@@ -9907,6 +9924,7 @@
9907
9924
  dataTextNames.push(text.name);
9908
9925
  masks.push(text.mask);
9909
9926
  }
9927
+ return text;
9910
9928
  });
9911
9929
  const formattedValue = value.map((row) => {
9912
9930
  const isDisabled = this.dataDisabled && row[this.dataDisabled];
@@ -9948,10 +9966,6 @@
9948
9966
  const foundInData = this.datasource.data.find(this.getCondition(value));
9949
9967
  return !foundInData;
9950
9968
  });
9951
- this.insertSelected();
9952
- if (!this.datasource.search) {
9953
- this.setCache();
9954
- }
9955
9969
  this.removePushedValue();
9956
9970
  });
9957
9971
  }
@@ -10012,6 +10026,16 @@
10012
10026
  }
10013
10027
  });
10014
10028
  }
10029
+ setItemsOnSelect() {
10030
+ const values = this.datasource.data.map((row) => row[this.dataValue]);
10031
+ // remove inserted items that are already in datasource
10032
+ this.insertedValues = this.insertedValues.filter((inserted) => !values.includes(inserted[this.dataValue]));
10033
+ this.preventLoadOnFocus = true;
10034
+ this.insertSelected();
10035
+ if (!this.datasource.search) {
10036
+ this.setCache();
10037
+ }
10038
+ }
10015
10039
  checkValueOnBlur() { }
10016
10040
  }
10017
10041
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/common",
3
- "version": "1.83.1",
3
+ "version": "1.83.2",
4
4
  "description": "Zeedhi Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -42,6 +42,5 @@
42
42
  "@types/lodash.times": "4.3.*",
43
43
  "lodash.times": "4.3.*",
44
44
  "mockdate": "3.0.*"
45
- },
46
- "gitHead": "543eabdb14abf45c8c6f645c760cbf299b446cee"
45
+ }
47
46
  }
@@ -1,7 +1,7 @@
1
1
  import { Datasource, IDictionary } from '@zeedhi/core';
2
2
  import { IComponentRender } from '../zd-component/interfaces';
3
- import { ISelect, SearchParam } from './interfaces';
4
3
  import { TextInput } from '../zd-text-input/text-input';
4
+ import { ISelect, SearchParam } from './interfaces';
5
5
  /**
6
6
  * Base class for Select component.
7
7
  */
@@ -1,6 +1,6 @@
1
1
  import { IDictionary } from '@zeedhi/core';
2
- import { ISelectMultiple } from './interfaces';
3
2
  import { Select } from '../zd-select/select';
3
+ import { ISelectMultiple } from './interfaces';
4
4
  export declare class SelectMultiple extends Select implements ISelectMultiple {
5
5
  private selectedValue;
6
6
  /**
@@ -31,6 +31,7 @@ export declare class SelectMultiple extends Select implements ISelectMultiple {
31
31
  * @param props Select properties
32
32
  */
33
33
  constructor(props: ISelectMultiple);
34
+ overrideGet(): void;
34
35
  /**
35
36
  * Field selected rows
36
37
  */
@@ -66,7 +67,10 @@ export declare class SelectMultiple extends Select implements ISelectMultiple {
66
67
  */
67
68
  updateSearch(value: string): Promise<void>;
68
69
  /**
69
- * Inserts selected items in datasource
70
+ * Inserts selected items in datasource.
71
+ * This method will validate, for every selected value, if it is present in datasource:
72
+ * if it is, removes from insertedValues
73
+ * if not, add to insertedValues
70
74
  */
71
75
  private insertSelected;
72
76
  protected removePushedValue(): void;
@@ -103,5 +107,6 @@ export declare class SelectMultiple extends Select implements ISelectMultiple {
103
107
  onSelectAll(isSelected: boolean, event: Event, element: any): void;
104
108
  selectAllItems(): Promise<void>;
105
109
  unSelectAllItems(): Promise<void>;
110
+ private setItemsOnSelect;
106
111
  protected checkValueOnBlur(): void;
107
112
  }
package/LICENSE DELETED
@@ -1,24 +0,0 @@
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.