@zeedhi/common 1.108.1 → 1.109.1
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/dist/zd-common.esm.js +320 -175
- package/dist/zd-common.umd.js +320 -175
- package/package.json +2 -2
- package/types/components/zd-grid/grid-editable.d.ts +1 -0
- package/types/components/zd-iterable/column.d.ts +5 -0
- package/types/components/zd-number/number.d.ts +19 -2
- package/types/components/zd-select-multiple/select-multiple.d.ts +1 -4
- package/types/components/zd-select-tree/interfaces.d.ts +1 -0
- package/types/components/zd-select-tree/select-tree.d.ts +10 -1
- package/types/components/zd-select-tree-multiple/select-tree-multiple.d.ts +35 -4
- package/types/formatters/column-zdselect.d.ts +1 -0
- package/types/formatters/column-zdselectmultiple.d.ts +1 -0
- package/types/formatters/index.d.ts +2 -0
- package/types/index.d.ts +1 -0
- package/types/services/zd-json-cache/json-cache-service.d.ts +12 -0
package/dist/zd-common.umd.js
CHANGED
|
@@ -2883,11 +2883,20 @@
|
|
|
2883
2883
|
this.formatterFn = core.FormatterParserProvider.getFormatter('ZdNumber');
|
|
2884
2884
|
this.parserFn = core.FormatterParserProvider.getParser('ZdNumber');
|
|
2885
2885
|
this.maskValid = false;
|
|
2886
|
-
const newMask =
|
|
2886
|
+
const newMask = this.mergeMasks(this.defaultMask, props.mask);
|
|
2887
2887
|
this.align = this.getInitValue('align', props.align, this.align);
|
|
2888
2888
|
this.mask = this.getInitValue('mask', newMask, this.defaultMask);
|
|
2889
2889
|
this.createAccessors();
|
|
2890
2890
|
this.validateMask();
|
|
2891
|
+
this.initializeMaskProxy();
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Merges two masks
|
|
2895
|
+
*/
|
|
2896
|
+
mergeMasks(maskA, maskB) {
|
|
2897
|
+
if (typeof maskB !== 'object')
|
|
2898
|
+
return Object.assign({}, maskA);
|
|
2899
|
+
return Object.assign(Object.assign({}, maskA), maskB);
|
|
2891
2900
|
}
|
|
2892
2901
|
validateMask() {
|
|
2893
2902
|
AutoNumeric.validate(this.mask, true);
|
|
@@ -2941,6 +2950,35 @@
|
|
|
2941
2950
|
this.localValue = parsed;
|
|
2942
2951
|
}
|
|
2943
2952
|
}
|
|
2953
|
+
/**
|
|
2954
|
+
* initializes a mask proxy to call update when the mask is changed
|
|
2955
|
+
*/
|
|
2956
|
+
initializeMaskProxy() {
|
|
2957
|
+
this.internalMask = new Proxy(Object.assign({}, this.mask), {
|
|
2958
|
+
set: (target, prop, newValue) => {
|
|
2959
|
+
target[prop] = newValue;
|
|
2960
|
+
setTimeout(() => {
|
|
2961
|
+
var _a;
|
|
2962
|
+
(_a = this.autoNumericObj) === null || _a === void 0 ? void 0 : _a.update(this.mask);
|
|
2963
|
+
});
|
|
2964
|
+
return true;
|
|
2965
|
+
},
|
|
2966
|
+
});
|
|
2967
|
+
}
|
|
2968
|
+
get mask() {
|
|
2969
|
+
return this.internalMask;
|
|
2970
|
+
}
|
|
2971
|
+
set mask(value) {
|
|
2972
|
+
this.internalMask = value;
|
|
2973
|
+
if (typeof value !== 'object')
|
|
2974
|
+
return;
|
|
2975
|
+
// when the mask is replaced, should reinitialize the mask Proxy
|
|
2976
|
+
setTimeout(() => {
|
|
2977
|
+
var _a;
|
|
2978
|
+
this.initializeMaskProxy();
|
|
2979
|
+
(_a = this.autoNumericObj) === null || _a === void 0 ? void 0 : _a.update(this.mask);
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2944
2982
|
/**
|
|
2945
2983
|
* Retrieves a formatted value with mask
|
|
2946
2984
|
* @param value Any value
|
|
@@ -5594,6 +5632,18 @@
|
|
|
5594
5632
|
super.onBeforeDestroy();
|
|
5595
5633
|
(_a = this.lookupDatasource) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
5596
5634
|
}
|
|
5635
|
+
/**
|
|
5636
|
+
* Retrieves a row from lookup using its key
|
|
5637
|
+
* @returns the row object when found, null when it is not found or empty
|
|
5638
|
+
*/
|
|
5639
|
+
getLookupRow(value) {
|
|
5640
|
+
const row = this.lookupData[value];
|
|
5641
|
+
if (!row)
|
|
5642
|
+
return null;
|
|
5643
|
+
if (Object.keys(row).length === 0)
|
|
5644
|
+
return null;
|
|
5645
|
+
return row;
|
|
5646
|
+
}
|
|
5597
5647
|
}
|
|
5598
5648
|
|
|
5599
5649
|
/**
|
|
@@ -5893,98 +5943,6 @@
|
|
|
5893
5943
|
}
|
|
5894
5944
|
}
|
|
5895
5945
|
}
|
|
5896
|
-
core.FormatterParserProvider.registerFormatter('column_ZdSelect', ({ column, value, row, componentProps, }) => {
|
|
5897
|
-
if (value === null || value === undefined)
|
|
5898
|
-
return '';
|
|
5899
|
-
const { dataText, formatterDataText, dataTextSeparator, dataValue, dataTextDiscrete, foreignColumns, } = componentProps;
|
|
5900
|
-
let currentRow = row;
|
|
5901
|
-
const dataTextColumns = Array.isArray(dataText) ? dataText : [dataText];
|
|
5902
|
-
if (dataValue) {
|
|
5903
|
-
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
|
|
5904
|
-
if (foreignColumns) {
|
|
5905
|
-
const loopkupRow = {};
|
|
5906
|
-
dataTextColumns.forEach((item) => {
|
|
5907
|
-
const dataTextName = typeof item === 'string' ? item : item.name;
|
|
5908
|
-
loopkupRow[dataTextName] = currentRow[foreignColumns[dataTextName] || dataTextName];
|
|
5909
|
-
});
|
|
5910
|
-
loopkupRow[dataValue] = currentRow[column.name];
|
|
5911
|
-
column.lookupData[currentRow[column.name]] = loopkupRow;
|
|
5912
|
-
}
|
|
5913
|
-
else if (!formatterDataText) {
|
|
5914
|
-
currentRow = column.getLookupData(dataValue, value[dataValue] || value);
|
|
5915
|
-
}
|
|
5916
|
-
else if (columns.length === dataTextColumns.length) {
|
|
5917
|
-
const loopkupRow = {};
|
|
5918
|
-
columns.forEach((item, index) => {
|
|
5919
|
-
const dataTextValue = dataTextColumns[index];
|
|
5920
|
-
const dataTextName = typeof dataTextValue === 'string' ? dataTextValue : dataTextValue.name;
|
|
5921
|
-
loopkupRow[dataTextName] = currentRow[typeof item === 'string' ? item : item.name];
|
|
5922
|
-
});
|
|
5923
|
-
loopkupRow[dataValue] = currentRow[column.name];
|
|
5924
|
-
column.lookupData[currentRow[column.name]] = loopkupRow;
|
|
5925
|
-
}
|
|
5926
|
-
}
|
|
5927
|
-
if (!Object.keys(currentRow).length)
|
|
5928
|
-
return typeof value === 'object' ? '' : value;
|
|
5929
|
-
let dataTextForeign = dataText;
|
|
5930
|
-
if (dataText && foreignColumns) {
|
|
5931
|
-
if (typeof dataText === 'string') {
|
|
5932
|
-
dataTextForeign = foreignColumns[dataText] || dataText;
|
|
5933
|
-
}
|
|
5934
|
-
else {
|
|
5935
|
-
dataTextForeign = dataTextColumns.map((item) => {
|
|
5936
|
-
const itemName = typeof item === 'string' ? item : item.name;
|
|
5937
|
-
return foreignColumns[itemName] || itemName;
|
|
5938
|
-
});
|
|
5939
|
-
}
|
|
5940
|
-
}
|
|
5941
|
-
const textColumn = dataTextDiscrete || formatterDataText || dataTextForeign;
|
|
5942
|
-
if (!textColumn)
|
|
5943
|
-
return value;
|
|
5944
|
-
if (typeof textColumn === 'string') {
|
|
5945
|
-
return currentRow[textColumn] || value;
|
|
5946
|
-
}
|
|
5947
|
-
const formatterFn = core.FormatterParserProvider.getFormatter('ZdSelect');
|
|
5948
|
-
return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator });
|
|
5949
|
-
});
|
|
5950
|
-
core.FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', ({ column, value, row, componentProps, }) => {
|
|
5951
|
-
if (!value || !Array.isArray(value) || value.length === 0)
|
|
5952
|
-
return '';
|
|
5953
|
-
const { formatterDataText, foreignColumns, dataText } = componentProps;
|
|
5954
|
-
const formatterFn = core.FormatterParserProvider.getFormatter('column_ZdSelect');
|
|
5955
|
-
const result = value.map((item, index) => {
|
|
5956
|
-
let formatterRow = Object.assign({}, row);
|
|
5957
|
-
const rowOverride = {};
|
|
5958
|
-
if (formatterDataText && formatterDataText.length > 0) {
|
|
5959
|
-
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
|
|
5960
|
-
columns.forEach((col) => {
|
|
5961
|
-
const textName = typeof col === 'string' ? col : col.name;
|
|
5962
|
-
rowOverride[textName] = row[textName][index];
|
|
5963
|
-
});
|
|
5964
|
-
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
5965
|
-
}
|
|
5966
|
-
else if (foreignColumns && dataText) {
|
|
5967
|
-
let dataTextForeign = dataText;
|
|
5968
|
-
if (typeof dataText === 'string') {
|
|
5969
|
-
dataTextForeign = [foreignColumns[dataText] || dataText];
|
|
5970
|
-
}
|
|
5971
|
-
else {
|
|
5972
|
-
dataTextForeign = dataText.map((col) => {
|
|
5973
|
-
const colName = typeof col === 'string' ? col : col.name;
|
|
5974
|
-
return foreignColumns[colName] || colName;
|
|
5975
|
-
});
|
|
5976
|
-
}
|
|
5977
|
-
dataTextForeign.forEach((col) => {
|
|
5978
|
-
rowOverride[col] = row[col][index];
|
|
5979
|
-
});
|
|
5980
|
-
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
5981
|
-
}
|
|
5982
|
-
return formatterFn({
|
|
5983
|
-
column, value: item, row: formatterRow, componentProps,
|
|
5984
|
-
});
|
|
5985
|
-
});
|
|
5986
|
-
return result.join(', ');
|
|
5987
|
-
});
|
|
5988
5946
|
const toggleableFormatter = ({ value, componentProps }) => {
|
|
5989
5947
|
const { trueValue, falseValue, trueIcon, falseIcon, trueDisplayValue, falseDisplayValue, } = componentProps;
|
|
5990
5948
|
const trueDefined = isUndefined__default["default"](trueValue) ? true : trueValue;
|
|
@@ -7124,23 +7082,23 @@
|
|
|
7124
7082
|
if (Array.isArray(colValue)) {
|
|
7125
7083
|
colValue.forEach((item) => {
|
|
7126
7084
|
const value = typeof item === 'object' ? item[componentProps.dataValue] : item;
|
|
7127
|
-
|
|
7128
|
-
componentProps.datasource.data.push(column.lookupData[value]);
|
|
7129
|
-
}
|
|
7085
|
+
this.pushLookupRow(column, componentProps, value);
|
|
7130
7086
|
});
|
|
7131
7087
|
return;
|
|
7132
7088
|
}
|
|
7133
7089
|
if (colValue && typeof colValue === 'object'
|
|
7134
7090
|
&& Object.prototype.hasOwnProperty.call(colValue, componentProps.dataValue)) {
|
|
7135
7091
|
const value = colValue[componentProps.dataValue];
|
|
7136
|
-
|
|
7137
|
-
componentProps.datasource.data.push(column.lookupData[value]);
|
|
7138
|
-
}
|
|
7092
|
+
this.pushLookupRow(column, componentProps, value);
|
|
7139
7093
|
return;
|
|
7140
7094
|
}
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7095
|
+
this.pushLookupRow(column, componentProps, colValue);
|
|
7096
|
+
}
|
|
7097
|
+
pushLookupRow(column, componentProps, value) {
|
|
7098
|
+
const lookupRow = column.getLookupRow(value);
|
|
7099
|
+
if (!lookupRow)
|
|
7100
|
+
return;
|
|
7101
|
+
componentProps.datasource.data.push(lookupRow);
|
|
7144
7102
|
}
|
|
7145
7103
|
checkCompValidity(component) {
|
|
7146
7104
|
if (!component.isValid()) {
|
|
@@ -12444,6 +12402,7 @@
|
|
|
12444
12402
|
this.limit = null;
|
|
12445
12403
|
this.showSelectAll = false;
|
|
12446
12404
|
this.showCheckboxAll = false;
|
|
12405
|
+
this.formatterFn = core.FormatterParserProvider.getFormatter('ZdSelectMultiple');
|
|
12447
12406
|
this.checkboxAllValue = false;
|
|
12448
12407
|
if (!this.selectedValue) {
|
|
12449
12408
|
this.selectedValue = [];
|
|
@@ -12660,22 +12619,6 @@
|
|
|
12660
12619
|
});
|
|
12661
12620
|
this.insertsRemoved = [];
|
|
12662
12621
|
}
|
|
12663
|
-
/**
|
|
12664
|
-
* Return formatted dataText and values
|
|
12665
|
-
*/
|
|
12666
|
-
formatter(value) {
|
|
12667
|
-
if (!value || value.length === 0) {
|
|
12668
|
-
return [];
|
|
12669
|
-
}
|
|
12670
|
-
const selectFormatter = core.FormatterParserProvider.getFormatter('ZdSelect');
|
|
12671
|
-
const formattedValue = value.map((row) => {
|
|
12672
|
-
const isDisabled = this.dataDisabled && row[this.dataDisabled];
|
|
12673
|
-
const formattedRow = { value: row[this.dataValue], disabled: isDisabled, originalRow: row };
|
|
12674
|
-
formattedRow.text = selectFormatter(row, this);
|
|
12675
|
-
return formattedRow;
|
|
12676
|
-
});
|
|
12677
|
-
return formattedValue;
|
|
12678
|
-
}
|
|
12679
12622
|
/**
|
|
12680
12623
|
* Returns the text shown when there's one or more selected items that doesn't fit in the input
|
|
12681
12624
|
*/
|
|
@@ -12921,7 +12864,21 @@
|
|
|
12921
12864
|
};
|
|
12922
12865
|
return modalSelectionDef;
|
|
12923
12866
|
}
|
|
12924
|
-
}
|
|
12867
|
+
}
|
|
12868
|
+
core.FormatterParserProvider.registerFormatter('ZdSelectMultiple', (value, props) => {
|
|
12869
|
+
const { dataDisabled, dataValue } = props;
|
|
12870
|
+
if (!value || value.length === 0) {
|
|
12871
|
+
return [];
|
|
12872
|
+
}
|
|
12873
|
+
const selectFormatter = core.FormatterParserProvider.getFormatter('ZdSelect');
|
|
12874
|
+
const formattedValue = value.map((row) => {
|
|
12875
|
+
const isDisabled = dataDisabled && row[dataDisabled];
|
|
12876
|
+
const formattedRow = { value: row[dataValue], disabled: isDisabled, originalRow: row };
|
|
12877
|
+
formattedRow.text = selectFormatter(row, props);
|
|
12878
|
+
return formattedRow;
|
|
12879
|
+
});
|
|
12880
|
+
return formattedValue;
|
|
12881
|
+
});
|
|
12925
12882
|
|
|
12926
12883
|
/**
|
|
12927
12884
|
* Base class for Select Tree component.
|
|
@@ -13012,7 +12969,6 @@
|
|
|
13012
12969
|
* Defines if should wait and not execute GET method when Datasource is created
|
|
13013
12970
|
*/
|
|
13014
12971
|
this.lazyLoad = true;
|
|
13015
|
-
this.selectValue = null;
|
|
13016
12972
|
/**
|
|
13017
12973
|
* Uses delayed loading to load tree branches
|
|
13018
12974
|
*/
|
|
@@ -13033,7 +12989,9 @@
|
|
|
13033
12989
|
* Defines the name of the form target to set using dataValueOut
|
|
13034
12990
|
*/
|
|
13035
12991
|
this.dataValueOutFormName = '';
|
|
12992
|
+
this.formatterFn = core.FormatterParserProvider.getFormatter('ZdSelectTree');
|
|
13036
12993
|
this.savedNodes = undefined;
|
|
12994
|
+
this.search = '';
|
|
13037
12995
|
this.debounceSearch = debounce__default["default"](this.searchChange, 500);
|
|
13038
12996
|
this.nodes = this.getInitValue('nodes', props.nodes, this.nodes);
|
|
13039
12997
|
this.alwaysOpen = this.getInitValue('alwaysOpen', props.alwaysOpen, this.alwaysOpen);
|
|
@@ -13053,7 +13011,6 @@
|
|
|
13053
13011
|
this.dataValue = this.getInitValue('dataValue', props.dataValue, this.dataValue);
|
|
13054
13012
|
this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
|
|
13055
13013
|
this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
|
|
13056
|
-
this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
|
|
13057
13014
|
this.fetchOnDemand = this.getInitValue('fetchOnDemand', props.fetchOnDemand, this.fetchOnDemand);
|
|
13058
13015
|
this.fieldHasChild = this.getInitValue('fieldHasChild', props.fieldHasChild, this.fieldHasChild);
|
|
13059
13016
|
this.menuMaxWidth = this.getInitValue('menuMaxWidth', props.menuMaxWidth, this.menuMaxWidth);
|
|
@@ -13071,8 +13028,21 @@
|
|
|
13071
13028
|
this.datasource = core.DatasourceFactory.factory(Object.assign(Object.assign({}, props.datasource), { searchIn: props.datasource.searchIn || searchFieldNames, lazyLoad: true, loadAll: true }));
|
|
13072
13029
|
this.createDataStructure();
|
|
13073
13030
|
}
|
|
13031
|
+
if (this.dataTextDiscrete && !Array.isArray(this.dataTextDiscrete))
|
|
13032
|
+
this.dataTextDiscrete = [this.dataTextDiscrete];
|
|
13033
|
+
this.discreteProps = {
|
|
13034
|
+
dataText: this.dataTextDiscrete,
|
|
13035
|
+
dataTextSeparator: this.dataTextSeparator,
|
|
13036
|
+
};
|
|
13037
|
+
this.preventLoadOnFocus = !this.datasource || !this.lazyLoad;
|
|
13038
|
+
this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
|
|
13039
|
+
this.value = this.getInitValue('value', props.value, this.value);
|
|
13074
13040
|
this.createAccessors();
|
|
13075
13041
|
}
|
|
13042
|
+
/**
|
|
13043
|
+
* Returns the currentRow in the dataText key
|
|
13044
|
+
*/
|
|
13045
|
+
formatter(value, props) { return this.formatterFn(value, props !== null && props !== void 0 ? props : this); }
|
|
13076
13046
|
focus(event, element) {
|
|
13077
13047
|
const _super = Object.create(null, {
|
|
13078
13048
|
focus: { get: () => super.focus }
|
|
@@ -13127,8 +13097,8 @@
|
|
|
13127
13097
|
children = undefined;
|
|
13128
13098
|
}
|
|
13129
13099
|
}
|
|
13130
|
-
const dataText = this.
|
|
13131
|
-
const dataTextDiscrete = this.
|
|
13100
|
+
const dataText = this.formatter(row);
|
|
13101
|
+
const dataTextDiscrete = this.formatter(row, this.discreteProps);
|
|
13132
13102
|
return {
|
|
13133
13103
|
id: row[this.dataValue],
|
|
13134
13104
|
label: dataText,
|
|
@@ -13148,40 +13118,6 @@
|
|
|
13148
13118
|
});
|
|
13149
13119
|
return newNodes;
|
|
13150
13120
|
}
|
|
13151
|
-
formatRow(dataText, row) {
|
|
13152
|
-
const dataTextArr = Array.isArray(dataText) ? dataText : [dataText];
|
|
13153
|
-
const dataTextNames = [];
|
|
13154
|
-
const masks = [];
|
|
13155
|
-
dataTextArr.forEach((text) => {
|
|
13156
|
-
if (typeof text === 'string') {
|
|
13157
|
-
dataTextNames.push(text);
|
|
13158
|
-
masks.push('');
|
|
13159
|
-
}
|
|
13160
|
-
else {
|
|
13161
|
-
dataTextNames.push(text.name);
|
|
13162
|
-
if (core.Accessor.isAccessorDefinition(text.mask)) {
|
|
13163
|
-
const [controller, accessor] = core.Accessor.getAccessor(text.mask);
|
|
13164
|
-
masks.push(core.Loader.getInstance(controller)[accessor]);
|
|
13165
|
-
}
|
|
13166
|
-
else {
|
|
13167
|
-
masks.push(text.mask);
|
|
13168
|
-
}
|
|
13169
|
-
}
|
|
13170
|
-
});
|
|
13171
|
-
const rowText = dataTextNames.reduce((result, column, index) => {
|
|
13172
|
-
if (row[column]) {
|
|
13173
|
-
const separator = index > 0 ? this.dataTextSeparator : '';
|
|
13174
|
-
let masked = row[column];
|
|
13175
|
-
if (masks[index]) {
|
|
13176
|
-
const maskValue = typeof masks[index] === 'function' ? masks[index](row[column]) : masks[index];
|
|
13177
|
-
masked = core.Mask.getValueWithMask(row[column], maskValue);
|
|
13178
|
-
}
|
|
13179
|
-
return result + separator + masked;
|
|
13180
|
-
}
|
|
13181
|
-
return result;
|
|
13182
|
-
}, '');
|
|
13183
|
-
return rowText;
|
|
13184
|
-
}
|
|
13185
13121
|
/**
|
|
13186
13122
|
* Triggered when the menu opens
|
|
13187
13123
|
*/
|
|
@@ -13205,6 +13141,7 @@
|
|
|
13205
13141
|
* Triggered after the search query changes
|
|
13206
13142
|
*/
|
|
13207
13143
|
searchChange(searchQuery, element) {
|
|
13144
|
+
this.search = searchQuery;
|
|
13208
13145
|
if (this.fetchOnDemand) {
|
|
13209
13146
|
if (!searchQuery && this.savedNodes) {
|
|
13210
13147
|
this.nodes = this.savedNodes;
|
|
@@ -13292,7 +13229,7 @@
|
|
|
13292
13229
|
if (!this.selectValue)
|
|
13293
13230
|
return this.selectValue;
|
|
13294
13231
|
if (this.returnObject) {
|
|
13295
|
-
return this.clearRow(this.selectValue.row);
|
|
13232
|
+
return this.clearRow(this.selectValue.row || this.selectValue);
|
|
13296
13233
|
}
|
|
13297
13234
|
return this.selectValue;
|
|
13298
13235
|
}
|
|
@@ -13339,6 +13276,8 @@
|
|
|
13339
13276
|
}
|
|
13340
13277
|
}
|
|
13341
13278
|
}
|
|
13279
|
+
const selectFormatterFn$1 = core.FormatterParserProvider.getFormatter('ZdSelect');
|
|
13280
|
+
core.FormatterParserProvider.registerFormatter('ZdSelectTree', selectFormatterFn$1);
|
|
13342
13281
|
InputFactory.register('ZdSelectTree', SelectTree);
|
|
13343
13282
|
|
|
13344
13283
|
/**
|
|
@@ -13363,7 +13302,6 @@
|
|
|
13363
13302
|
* Selected Nodes
|
|
13364
13303
|
*/
|
|
13365
13304
|
this.selectedNodes = [];
|
|
13366
|
-
this.selectValue = [];
|
|
13367
13305
|
/**
|
|
13368
13306
|
* Changes the behavior of checked nodes that will be displayed in the array of values
|
|
13369
13307
|
*/
|
|
@@ -13391,19 +13329,25 @@
|
|
|
13391
13329
|
this.callEvent('onDeselect', { element, component: this, node });
|
|
13392
13330
|
}
|
|
13393
13331
|
get value() {
|
|
13332
|
+
if (!this.selectValue)
|
|
13333
|
+
return [];
|
|
13394
13334
|
if (this.returnObject) {
|
|
13395
|
-
return this.selectValue.map((value) => this.clearRow(value.row));
|
|
13335
|
+
return this.selectValue.map((value) => this.clearRow(value.row || value));
|
|
13396
13336
|
}
|
|
13397
13337
|
return this.selectValue;
|
|
13398
13338
|
}
|
|
13399
13339
|
set value(value) {
|
|
13400
|
-
this.
|
|
13340
|
+
this.setValue(value);
|
|
13401
13341
|
}
|
|
13402
13342
|
setValue(value) {
|
|
13343
|
+
if (!value) {
|
|
13344
|
+
this.selectValue = [];
|
|
13345
|
+
return;
|
|
13346
|
+
}
|
|
13403
13347
|
const arrValue = Array.isArray(value) ? value : [value];
|
|
13404
13348
|
const key = this.datasource ? this.dataValue : 'id';
|
|
13405
13349
|
if (!this.returnObject) {
|
|
13406
|
-
this.
|
|
13350
|
+
this.selectValue = arrValue.map((item) => {
|
|
13407
13351
|
if (typeof item === 'object') {
|
|
13408
13352
|
return item[key];
|
|
13409
13353
|
}
|
|
@@ -13411,19 +13355,27 @@
|
|
|
13411
13355
|
});
|
|
13412
13356
|
return;
|
|
13413
13357
|
}
|
|
13414
|
-
this.
|
|
13358
|
+
this.selectValue = arrValue.map((item) => {
|
|
13415
13359
|
if (typeof item !== 'object') {
|
|
13416
13360
|
return { id: item };
|
|
13417
13361
|
}
|
|
13418
13362
|
return { id: item[key] };
|
|
13419
13363
|
});
|
|
13420
13364
|
}
|
|
13421
|
-
|
|
13422
|
-
|
|
13365
|
+
/**
|
|
13366
|
+
* Retrieves all nodes in the tree as a flat array. Nodes that are not matched are excluded
|
|
13367
|
+
* Nodes that are not matched but whose parent is matched are included
|
|
13368
|
+
* @param nodes
|
|
13369
|
+
* @param matched defines whether the parent of the current node branch is matched
|
|
13370
|
+
* @returns all nodes in the tree as a flat array, filtering unmatched nodes
|
|
13371
|
+
*/
|
|
13372
|
+
getAllNodes(nodes = this.nodes, matched = true) {
|
|
13373
|
+
let result = [...nodes];
|
|
13374
|
+
result = result.filter((node) => node.isMatched || matched);
|
|
13423
13375
|
nodes.forEach((node) => {
|
|
13424
13376
|
if (!node.children)
|
|
13425
13377
|
return;
|
|
13426
|
-
const childNodes = this.getAllNodes(node.children);
|
|
13378
|
+
const childNodes = this.getAllNodes(node.children, node.isMatched || matched);
|
|
13427
13379
|
result = [...result, ...childNodes];
|
|
13428
13380
|
});
|
|
13429
13381
|
return result;
|
|
@@ -13431,28 +13383,96 @@
|
|
|
13431
13383
|
/**
|
|
13432
13384
|
* Dispatches select/unselect event
|
|
13433
13385
|
*/
|
|
13434
|
-
onSelectAll(isSelected, event, element) {
|
|
13386
|
+
onSelectAll(isSelected, event, element, nodes = this.nodes) {
|
|
13435
13387
|
if (isSelected) {
|
|
13436
13388
|
this.callEvent('selectedAll', { event, element, component: this });
|
|
13437
13389
|
if (!event.defaultPrevented) {
|
|
13438
|
-
this.selectAllItems();
|
|
13390
|
+
this.selectAllItems(nodes);
|
|
13439
13391
|
}
|
|
13440
13392
|
}
|
|
13441
13393
|
else {
|
|
13442
13394
|
this.callEvent('unselectedAll', { event, element, component: this });
|
|
13443
13395
|
if (!event.defaultPrevented) {
|
|
13444
|
-
this.unSelectAllItems();
|
|
13396
|
+
this.unSelectAllItems(nodes);
|
|
13445
13397
|
}
|
|
13446
13398
|
}
|
|
13447
13399
|
}
|
|
13448
|
-
|
|
13449
|
-
|
|
13450
|
-
|
|
13400
|
+
/**
|
|
13401
|
+
* Selects all items in the tree \
|
|
13402
|
+
* If the component is fetchOnDemand, it will select all values from datasource.data \
|
|
13403
|
+
* If not, it will select all nodes from the tree, unless the nodes to be selected are specified
|
|
13404
|
+
* @param nodes nodes to be selected. These are the nodes that are currently visible in the tree
|
|
13405
|
+
* (if the user is searching, selects only the searched nodes)
|
|
13406
|
+
* @returns
|
|
13407
|
+
*/
|
|
13408
|
+
selectAllItems(nodes = this.nodes) {
|
|
13409
|
+
var _a;
|
|
13410
|
+
if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
|
|
13411
|
+
this.setValue(this.datasource.data);
|
|
13412
|
+
return;
|
|
13413
|
+
}
|
|
13414
|
+
const allNodes = this.getAllNodes(nodes, !this.search);
|
|
13415
|
+
// merge all nodes with the current value before setting it
|
|
13416
|
+
const currentValue = this.getValueAsObject();
|
|
13417
|
+
const nodeMap = this.createMergeMap(currentValue, allNodes);
|
|
13418
|
+
const uniqueArray = Array.from(nodeMap.values());
|
|
13419
|
+
this.setValue(uniqueArray);
|
|
13451
13420
|
}
|
|
13452
|
-
|
|
13453
|
-
|
|
13421
|
+
/**
|
|
13422
|
+
* Unelects all items in the tree \
|
|
13423
|
+
* If the component is fetchOnDemand, it will select all values from datasource.data \
|
|
13424
|
+
* If not, it will select all nodes from the tree, unless the nodes to be selected are specified
|
|
13425
|
+
* @param nodes nodes to be selected. These are the nodes that are currently visible in the tree
|
|
13426
|
+
* (if the user is searching, selects only the searched nodes)
|
|
13427
|
+
* @returns
|
|
13428
|
+
*/
|
|
13429
|
+
unSelectAllItems(nodes = this.nodes) {
|
|
13430
|
+
var _a;
|
|
13431
|
+
if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
|
|
13432
|
+
this.setValue([]);
|
|
13433
|
+
return;
|
|
13434
|
+
}
|
|
13435
|
+
const allNodes = this.getAllNodes(nodes, !this.search);
|
|
13436
|
+
// merge all nodes with the current value before setting it
|
|
13437
|
+
const currentValue = this.getValueAsObject();
|
|
13438
|
+
const nodeMap = this.createMergeMap(currentValue);
|
|
13439
|
+
// remove the current visible nodes from the array
|
|
13440
|
+
const valuesToRemove = allNodes.map((node) => node.id);
|
|
13441
|
+
valuesToRemove.forEach((value) => {
|
|
13442
|
+
nodeMap.delete(value);
|
|
13443
|
+
});
|
|
13444
|
+
const uniqueArray = Array.from(nodeMap.values());
|
|
13445
|
+
this.setValue(uniqueArray);
|
|
13454
13446
|
}
|
|
13455
|
-
|
|
13447
|
+
/**
|
|
13448
|
+
* Takes two arrays and creates a map of the unique values
|
|
13449
|
+
* @returns map of a merge between the two arrays, removing duplicates
|
|
13450
|
+
*/
|
|
13451
|
+
createMergeMap(arr1, arr2 = []) {
|
|
13452
|
+
const mergedNodes = arr1.concat(arr2);
|
|
13453
|
+
// filter out duplicate nodes
|
|
13454
|
+
const uniqueMap = new Map();
|
|
13455
|
+
mergedNodes.forEach((node) => {
|
|
13456
|
+
uniqueMap.set(node.id, node);
|
|
13457
|
+
});
|
|
13458
|
+
return uniqueMap;
|
|
13459
|
+
}
|
|
13460
|
+
getValueIds() {
|
|
13461
|
+
if (this.returnObject) {
|
|
13462
|
+
return this.value.map((item) => item.id);
|
|
13463
|
+
}
|
|
13464
|
+
return this.value;
|
|
13465
|
+
}
|
|
13466
|
+
getValueAsObject() {
|
|
13467
|
+
return this.value.map((row) => {
|
|
13468
|
+
if (this.returnObject)
|
|
13469
|
+
return row;
|
|
13470
|
+
return { id: row };
|
|
13471
|
+
});
|
|
13472
|
+
}
|
|
13473
|
+
}
|
|
13474
|
+
const selectFormatterFn = core.FormatterParserProvider.getFormatter('ZdSelectMultiple');
|
|
13475
|
+
core.FormatterParserProvider.registerFormatter('ZdSelectTreeMultiple', selectFormatterFn);
|
|
13456
13476
|
|
|
13457
13477
|
/**
|
|
13458
13478
|
* Base class for SelectableList component.
|
|
@@ -15829,6 +15849,131 @@
|
|
|
15829
15849
|
}
|
|
15830
15850
|
}
|
|
15831
15851
|
|
|
15852
|
+
const asArray = (value) => (Array.isArray(value) ? value : [value]);
|
|
15853
|
+
const getForeignLookupRow = (column, row, dataValue, dataTextColumns, foreignColumns) => {
|
|
15854
|
+
const lookupRow = {};
|
|
15855
|
+
dataTextColumns.forEach((item) => {
|
|
15856
|
+
const dataTextName = typeof item === 'string' ? item : item.name;
|
|
15857
|
+
lookupRow[dataTextName] = row[foreignColumns[dataTextName] || dataTextName];
|
|
15858
|
+
});
|
|
15859
|
+
lookupRow[dataValue] = row[column.name];
|
|
15860
|
+
return lookupRow;
|
|
15861
|
+
};
|
|
15862
|
+
const getFormatterLookupRow = (column, row, dataValue, formatterDataTextColumns, dataTextColumns) => {
|
|
15863
|
+
const lookupRow = {};
|
|
15864
|
+
formatterDataTextColumns.forEach((item, index) => {
|
|
15865
|
+
const dataTextValue = dataTextColumns[index];
|
|
15866
|
+
const dataTextName = typeof dataTextValue === 'string' ? dataTextValue : dataTextValue.name;
|
|
15867
|
+
const formatterDataTextColumn = typeof item === 'string' ? item : item.name;
|
|
15868
|
+
lookupRow[dataTextName] = row[formatterDataTextColumn];
|
|
15869
|
+
});
|
|
15870
|
+
lookupRow[dataValue] = row[column.name];
|
|
15871
|
+
return lookupRow;
|
|
15872
|
+
};
|
|
15873
|
+
/**
|
|
15874
|
+
* Stores data in column.lookupData when using foreignColumns or formatterDataText.
|
|
15875
|
+
* Makes a lookup when not using foreignColumns or formatterDataText
|
|
15876
|
+
* @returns the row from grid's datasource when using foreignColumns or formatterDataText. Otherwise,
|
|
15877
|
+
* returns the row from the column's component datasource
|
|
15878
|
+
*/
|
|
15879
|
+
const storeOrRetrieveLookup = (column, row, value, dataValue, componentProps) => {
|
|
15880
|
+
const { dataText, foreignColumns, formatterDataText, } = componentProps;
|
|
15881
|
+
const dataTextColumns = asArray(dataText);
|
|
15882
|
+
// when using foreignColumns, should store foreign keys information in lookupData
|
|
15883
|
+
if (foreignColumns) {
|
|
15884
|
+
column.lookupData[row[column.name]] = getForeignLookupRow(column, row, dataValue, dataTextColumns, foreignColumns);
|
|
15885
|
+
return row;
|
|
15886
|
+
}
|
|
15887
|
+
// when not using formatterDataText, should fetch data from datasource to be able to format this cell
|
|
15888
|
+
if (!formatterDataText) {
|
|
15889
|
+
return column.getLookupData(dataValue, value[dataValue] || value);
|
|
15890
|
+
}
|
|
15891
|
+
const formatterDataTextColumns = asArray(formatterDataText);
|
|
15892
|
+
// when using formatterDataText, should store dataText information in lookupData
|
|
15893
|
+
if (formatterDataTextColumns.length === dataTextColumns.length) {
|
|
15894
|
+
const rowColumn = row[column.name];
|
|
15895
|
+
column.lookupData[rowColumn] = getFormatterLookupRow(column, row, dataValue, formatterDataTextColumns, dataTextColumns);
|
|
15896
|
+
return row;
|
|
15897
|
+
}
|
|
15898
|
+
return row;
|
|
15899
|
+
};
|
|
15900
|
+
const formatter$1 = ({ column, value, row, componentProps, }) => {
|
|
15901
|
+
if (value === null || value === undefined)
|
|
15902
|
+
return '';
|
|
15903
|
+
const { dataText, formatterDataText, dataTextSeparator, dataValue, dataTextDiscrete, foreignColumns, } = componentProps;
|
|
15904
|
+
let currentRow = row;
|
|
15905
|
+
const dataTextColumns = asArray(dataText);
|
|
15906
|
+
// when dataValue is defined, should try to store or retrieve row data from lookupData
|
|
15907
|
+
if (dataValue) {
|
|
15908
|
+
currentRow = storeOrRetrieveLookup(column, row, value, dataValue, componentProps);
|
|
15909
|
+
}
|
|
15910
|
+
if (!Object.keys(currentRow).length)
|
|
15911
|
+
return typeof value === 'object' ? '' : value;
|
|
15912
|
+
let dataTextForeign = dataText;
|
|
15913
|
+
if (dataText && foreignColumns) {
|
|
15914
|
+
if (typeof dataText === 'string') {
|
|
15915
|
+
dataTextForeign = foreignColumns[dataText] || dataText;
|
|
15916
|
+
}
|
|
15917
|
+
else {
|
|
15918
|
+
dataTextForeign = dataTextColumns.map((item) => {
|
|
15919
|
+
const itemName = typeof item === 'string' ? item : item.name;
|
|
15920
|
+
return foreignColumns[itemName] || itemName;
|
|
15921
|
+
});
|
|
15922
|
+
}
|
|
15923
|
+
}
|
|
15924
|
+
const textColumn = dataTextDiscrete || formatterDataText || dataTextForeign;
|
|
15925
|
+
if (!textColumn)
|
|
15926
|
+
return value;
|
|
15927
|
+
if (typeof textColumn === 'string') {
|
|
15928
|
+
return currentRow[textColumn] || value;
|
|
15929
|
+
}
|
|
15930
|
+
const formatterFn = core.FormatterParserProvider.getFormatter('ZdSelect');
|
|
15931
|
+
return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator });
|
|
15932
|
+
};
|
|
15933
|
+
core.FormatterParserProvider.registerFormatter('column_ZdSelect', formatter$1);
|
|
15934
|
+
core.FormatterParserProvider.registerFormatter('column_ZdSelectTree', formatter$1);
|
|
15935
|
+
|
|
15936
|
+
const formatter = ({ column, value, row, componentProps, }) => {
|
|
15937
|
+
if (!value || !Array.isArray(value) || value.length === 0)
|
|
15938
|
+
return '';
|
|
15939
|
+
const { formatterDataText, foreignColumns, dataText } = componentProps;
|
|
15940
|
+
const formatterFn = core.FormatterParserProvider.getFormatter('column_ZdSelect');
|
|
15941
|
+
const result = value.map((item, index) => {
|
|
15942
|
+
let formatterRow = Object.assign({}, row);
|
|
15943
|
+
const rowOverride = {};
|
|
15944
|
+
if (formatterDataText && formatterDataText.length > 0) {
|
|
15945
|
+
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
|
|
15946
|
+
columns.forEach((col) => {
|
|
15947
|
+
const textName = typeof col === 'string' ? col : col.name;
|
|
15948
|
+
rowOverride[textName] = row[textName][index];
|
|
15949
|
+
});
|
|
15950
|
+
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
15951
|
+
}
|
|
15952
|
+
else if (foreignColumns && dataText) {
|
|
15953
|
+
let dataTextForeign = dataText;
|
|
15954
|
+
if (typeof dataText === 'string') {
|
|
15955
|
+
dataTextForeign = [foreignColumns[dataText] || dataText];
|
|
15956
|
+
}
|
|
15957
|
+
else {
|
|
15958
|
+
dataTextForeign = dataText.map((col) => {
|
|
15959
|
+
const colName = typeof col === 'string' ? col : col.name;
|
|
15960
|
+
return foreignColumns[colName] || colName;
|
|
15961
|
+
});
|
|
15962
|
+
}
|
|
15963
|
+
dataTextForeign.forEach((col) => {
|
|
15964
|
+
rowOverride[col] = row[col][index];
|
|
15965
|
+
});
|
|
15966
|
+
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
15967
|
+
}
|
|
15968
|
+
return formatterFn({
|
|
15969
|
+
column, value: item, row: formatterRow, componentProps,
|
|
15970
|
+
});
|
|
15971
|
+
});
|
|
15972
|
+
return result.join(', ');
|
|
15973
|
+
};
|
|
15974
|
+
core.FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', formatter);
|
|
15975
|
+
core.FormatterParserProvider.registerFormatter('column_ZdSelectTreeMultiple', formatter);
|
|
15976
|
+
|
|
15832
15977
|
const AutoNumeric = require('@zeedhi/autonumeric/dist/autoNumeric');
|
|
15833
15978
|
const packageContent = require('../package.json');
|
|
15834
15979
|
core.VersionService.addPackageVersion(packageContent.name, packageContent.version);
|