@zeedhi/common 1.109.0 → 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 +281 -174
- package/dist/zd-common.umd.js +281 -174
- 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-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/dist/zd-common.esm.js
CHANGED
|
@@ -5625,6 +5625,18 @@ class Column extends Component {
|
|
|
5625
5625
|
super.onBeforeDestroy();
|
|
5626
5626
|
(_a = this.lookupDatasource) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
5627
5627
|
}
|
|
5628
|
+
/**
|
|
5629
|
+
* Retrieves a row from lookup using its key
|
|
5630
|
+
* @returns the row object when found, null when it is not found or empty
|
|
5631
|
+
*/
|
|
5632
|
+
getLookupRow(value) {
|
|
5633
|
+
const row = this.lookupData[value];
|
|
5634
|
+
if (!row)
|
|
5635
|
+
return null;
|
|
5636
|
+
if (Object.keys(row).length === 0)
|
|
5637
|
+
return null;
|
|
5638
|
+
return row;
|
|
5639
|
+
}
|
|
5628
5640
|
}
|
|
5629
5641
|
|
|
5630
5642
|
/**
|
|
@@ -5924,98 +5936,6 @@ class GridColumn extends Column {
|
|
|
5924
5936
|
}
|
|
5925
5937
|
}
|
|
5926
5938
|
}
|
|
5927
|
-
FormatterParserProvider.registerFormatter('column_ZdSelect', ({ column, value, row, componentProps, }) => {
|
|
5928
|
-
if (value === null || value === undefined)
|
|
5929
|
-
return '';
|
|
5930
|
-
const { dataText, formatterDataText, dataTextSeparator, dataValue, dataTextDiscrete, foreignColumns, } = componentProps;
|
|
5931
|
-
let currentRow = row;
|
|
5932
|
-
const dataTextColumns = Array.isArray(dataText) ? dataText : [dataText];
|
|
5933
|
-
if (dataValue) {
|
|
5934
|
-
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
|
|
5935
|
-
if (foreignColumns) {
|
|
5936
|
-
const loopkupRow = {};
|
|
5937
|
-
dataTextColumns.forEach((item) => {
|
|
5938
|
-
const dataTextName = typeof item === 'string' ? item : item.name;
|
|
5939
|
-
loopkupRow[dataTextName] = currentRow[foreignColumns[dataTextName] || dataTextName];
|
|
5940
|
-
});
|
|
5941
|
-
loopkupRow[dataValue] = currentRow[column.name];
|
|
5942
|
-
column.lookupData[currentRow[column.name]] = loopkupRow;
|
|
5943
|
-
}
|
|
5944
|
-
else if (!formatterDataText) {
|
|
5945
|
-
currentRow = column.getLookupData(dataValue, value[dataValue] || value);
|
|
5946
|
-
}
|
|
5947
|
-
else if (columns.length === dataTextColumns.length) {
|
|
5948
|
-
const loopkupRow = {};
|
|
5949
|
-
columns.forEach((item, index) => {
|
|
5950
|
-
const dataTextValue = dataTextColumns[index];
|
|
5951
|
-
const dataTextName = typeof dataTextValue === 'string' ? dataTextValue : dataTextValue.name;
|
|
5952
|
-
loopkupRow[dataTextName] = currentRow[typeof item === 'string' ? item : item.name];
|
|
5953
|
-
});
|
|
5954
|
-
loopkupRow[dataValue] = currentRow[column.name];
|
|
5955
|
-
column.lookupData[currentRow[column.name]] = loopkupRow;
|
|
5956
|
-
}
|
|
5957
|
-
}
|
|
5958
|
-
if (!Object.keys(currentRow).length)
|
|
5959
|
-
return typeof value === 'object' ? '' : value;
|
|
5960
|
-
let dataTextForeign = dataText;
|
|
5961
|
-
if (dataText && foreignColumns) {
|
|
5962
|
-
if (typeof dataText === 'string') {
|
|
5963
|
-
dataTextForeign = foreignColumns[dataText] || dataText;
|
|
5964
|
-
}
|
|
5965
|
-
else {
|
|
5966
|
-
dataTextForeign = dataTextColumns.map((item) => {
|
|
5967
|
-
const itemName = typeof item === 'string' ? item : item.name;
|
|
5968
|
-
return foreignColumns[itemName] || itemName;
|
|
5969
|
-
});
|
|
5970
|
-
}
|
|
5971
|
-
}
|
|
5972
|
-
const textColumn = dataTextDiscrete || formatterDataText || dataTextForeign;
|
|
5973
|
-
if (!textColumn)
|
|
5974
|
-
return value;
|
|
5975
|
-
if (typeof textColumn === 'string') {
|
|
5976
|
-
return currentRow[textColumn] || value;
|
|
5977
|
-
}
|
|
5978
|
-
const formatterFn = FormatterParserProvider.getFormatter('ZdSelect');
|
|
5979
|
-
return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator });
|
|
5980
|
-
});
|
|
5981
|
-
FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', ({ column, value, row, componentProps, }) => {
|
|
5982
|
-
if (!value || !Array.isArray(value) || value.length === 0)
|
|
5983
|
-
return '';
|
|
5984
|
-
const { formatterDataText, foreignColumns, dataText } = componentProps;
|
|
5985
|
-
const formatterFn = FormatterParserProvider.getFormatter('column_ZdSelect');
|
|
5986
|
-
const result = value.map((item, index) => {
|
|
5987
|
-
let formatterRow = Object.assign({}, row);
|
|
5988
|
-
const rowOverride = {};
|
|
5989
|
-
if (formatterDataText && formatterDataText.length > 0) {
|
|
5990
|
-
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
|
|
5991
|
-
columns.forEach((col) => {
|
|
5992
|
-
const textName = typeof col === 'string' ? col : col.name;
|
|
5993
|
-
rowOverride[textName] = row[textName][index];
|
|
5994
|
-
});
|
|
5995
|
-
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
5996
|
-
}
|
|
5997
|
-
else if (foreignColumns && dataText) {
|
|
5998
|
-
let dataTextForeign = dataText;
|
|
5999
|
-
if (typeof dataText === 'string') {
|
|
6000
|
-
dataTextForeign = [foreignColumns[dataText] || dataText];
|
|
6001
|
-
}
|
|
6002
|
-
else {
|
|
6003
|
-
dataTextForeign = dataText.map((col) => {
|
|
6004
|
-
const colName = typeof col === 'string' ? col : col.name;
|
|
6005
|
-
return foreignColumns[colName] || colName;
|
|
6006
|
-
});
|
|
6007
|
-
}
|
|
6008
|
-
dataTextForeign.forEach((col) => {
|
|
6009
|
-
rowOverride[col] = row[col][index];
|
|
6010
|
-
});
|
|
6011
|
-
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
6012
|
-
}
|
|
6013
|
-
return formatterFn({
|
|
6014
|
-
column, value: item, row: formatterRow, componentProps,
|
|
6015
|
-
});
|
|
6016
|
-
});
|
|
6017
|
-
return result.join(', ');
|
|
6018
|
-
});
|
|
6019
5939
|
const toggleableFormatter = ({ value, componentProps }) => {
|
|
6020
5940
|
const { trueValue, falseValue, trueIcon, falseIcon, trueDisplayValue, falseDisplayValue, } = componentProps;
|
|
6021
5941
|
const trueDefined = isUndefined(trueValue) ? true : trueValue;
|
|
@@ -7155,23 +7075,23 @@ class GridEditable extends Grid {
|
|
|
7155
7075
|
if (Array.isArray(colValue)) {
|
|
7156
7076
|
colValue.forEach((item) => {
|
|
7157
7077
|
const value = typeof item === 'object' ? item[componentProps.dataValue] : item;
|
|
7158
|
-
|
|
7159
|
-
componentProps.datasource.data.push(column.lookupData[value]);
|
|
7160
|
-
}
|
|
7078
|
+
this.pushLookupRow(column, componentProps, value);
|
|
7161
7079
|
});
|
|
7162
7080
|
return;
|
|
7163
7081
|
}
|
|
7164
7082
|
if (colValue && typeof colValue === 'object'
|
|
7165
7083
|
&& Object.prototype.hasOwnProperty.call(colValue, componentProps.dataValue)) {
|
|
7166
7084
|
const value = colValue[componentProps.dataValue];
|
|
7167
|
-
|
|
7168
|
-
componentProps.datasource.data.push(column.lookupData[value]);
|
|
7169
|
-
}
|
|
7085
|
+
this.pushLookupRow(column, componentProps, value);
|
|
7170
7086
|
return;
|
|
7171
7087
|
}
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7088
|
+
this.pushLookupRow(column, componentProps, colValue);
|
|
7089
|
+
}
|
|
7090
|
+
pushLookupRow(column, componentProps, value) {
|
|
7091
|
+
const lookupRow = column.getLookupRow(value);
|
|
7092
|
+
if (!lookupRow)
|
|
7093
|
+
return;
|
|
7094
|
+
componentProps.datasource.data.push(lookupRow);
|
|
7175
7095
|
}
|
|
7176
7096
|
checkCompValidity(component) {
|
|
7177
7097
|
if (!component.isValid()) {
|
|
@@ -12475,6 +12395,7 @@ class SelectMultiple extends Select {
|
|
|
12475
12395
|
this.limit = null;
|
|
12476
12396
|
this.showSelectAll = false;
|
|
12477
12397
|
this.showCheckboxAll = false;
|
|
12398
|
+
this.formatterFn = FormatterParserProvider.getFormatter('ZdSelectMultiple');
|
|
12478
12399
|
this.checkboxAllValue = false;
|
|
12479
12400
|
if (!this.selectedValue) {
|
|
12480
12401
|
this.selectedValue = [];
|
|
@@ -12691,22 +12612,6 @@ class SelectMultiple extends Select {
|
|
|
12691
12612
|
});
|
|
12692
12613
|
this.insertsRemoved = [];
|
|
12693
12614
|
}
|
|
12694
|
-
/**
|
|
12695
|
-
* Return formatted dataText and values
|
|
12696
|
-
*/
|
|
12697
|
-
formatter(value) {
|
|
12698
|
-
if (!value || value.length === 0) {
|
|
12699
|
-
return [];
|
|
12700
|
-
}
|
|
12701
|
-
const selectFormatter = FormatterParserProvider.getFormatter('ZdSelect');
|
|
12702
|
-
const formattedValue = value.map((row) => {
|
|
12703
|
-
const isDisabled = this.dataDisabled && row[this.dataDisabled];
|
|
12704
|
-
const formattedRow = { value: row[this.dataValue], disabled: isDisabled, originalRow: row };
|
|
12705
|
-
formattedRow.text = selectFormatter(row, this);
|
|
12706
|
-
return formattedRow;
|
|
12707
|
-
});
|
|
12708
|
-
return formattedValue;
|
|
12709
|
-
}
|
|
12710
12615
|
/**
|
|
12711
12616
|
* Returns the text shown when there's one or more selected items that doesn't fit in the input
|
|
12712
12617
|
*/
|
|
@@ -12952,7 +12857,21 @@ class SelectMultiple extends Select {
|
|
|
12952
12857
|
};
|
|
12953
12858
|
return modalSelectionDef;
|
|
12954
12859
|
}
|
|
12955
|
-
}
|
|
12860
|
+
}
|
|
12861
|
+
FormatterParserProvider.registerFormatter('ZdSelectMultiple', (value, props) => {
|
|
12862
|
+
const { dataDisabled, dataValue } = props;
|
|
12863
|
+
if (!value || value.length === 0) {
|
|
12864
|
+
return [];
|
|
12865
|
+
}
|
|
12866
|
+
const selectFormatter = FormatterParserProvider.getFormatter('ZdSelect');
|
|
12867
|
+
const formattedValue = value.map((row) => {
|
|
12868
|
+
const isDisabled = dataDisabled && row[dataDisabled];
|
|
12869
|
+
const formattedRow = { value: row[dataValue], disabled: isDisabled, originalRow: row };
|
|
12870
|
+
formattedRow.text = selectFormatter(row, props);
|
|
12871
|
+
return formattedRow;
|
|
12872
|
+
});
|
|
12873
|
+
return formattedValue;
|
|
12874
|
+
});
|
|
12956
12875
|
|
|
12957
12876
|
/**
|
|
12958
12877
|
* Base class for Select Tree component.
|
|
@@ -13043,7 +12962,6 @@ class SelectTree extends TextInput {
|
|
|
13043
12962
|
* Defines if should wait and not execute GET method when Datasource is created
|
|
13044
12963
|
*/
|
|
13045
12964
|
this.lazyLoad = true;
|
|
13046
|
-
this.selectValue = null;
|
|
13047
12965
|
/**
|
|
13048
12966
|
* Uses delayed loading to load tree branches
|
|
13049
12967
|
*/
|
|
@@ -13064,7 +12982,9 @@ class SelectTree extends TextInput {
|
|
|
13064
12982
|
* Defines the name of the form target to set using dataValueOut
|
|
13065
12983
|
*/
|
|
13066
12984
|
this.dataValueOutFormName = '';
|
|
12985
|
+
this.formatterFn = FormatterParserProvider.getFormatter('ZdSelectTree');
|
|
13067
12986
|
this.savedNodes = undefined;
|
|
12987
|
+
this.search = '';
|
|
13068
12988
|
this.debounceSearch = debounce(this.searchChange, 500);
|
|
13069
12989
|
this.nodes = this.getInitValue('nodes', props.nodes, this.nodes);
|
|
13070
12990
|
this.alwaysOpen = this.getInitValue('alwaysOpen', props.alwaysOpen, this.alwaysOpen);
|
|
@@ -13084,7 +13004,6 @@ class SelectTree extends TextInput {
|
|
|
13084
13004
|
this.dataValue = this.getInitValue('dataValue', props.dataValue, this.dataValue);
|
|
13085
13005
|
this.dataDisabled = this.getInitValue('dataDisabled', props.dataDisabled, this.dataDisabled);
|
|
13086
13006
|
this.disabledItems = this.getInitValue('disabledItems', props.disabledItems, this.disabledItems);
|
|
13087
|
-
this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
|
|
13088
13007
|
this.fetchOnDemand = this.getInitValue('fetchOnDemand', props.fetchOnDemand, this.fetchOnDemand);
|
|
13089
13008
|
this.fieldHasChild = this.getInitValue('fieldHasChild', props.fieldHasChild, this.fieldHasChild);
|
|
13090
13009
|
this.menuMaxWidth = this.getInitValue('menuMaxWidth', props.menuMaxWidth, this.menuMaxWidth);
|
|
@@ -13102,8 +13021,21 @@ class SelectTree extends TextInput {
|
|
|
13102
13021
|
this.datasource = DatasourceFactory.factory(Object.assign(Object.assign({}, props.datasource), { searchIn: props.datasource.searchIn || searchFieldNames, lazyLoad: true, loadAll: true }));
|
|
13103
13022
|
this.createDataStructure();
|
|
13104
13023
|
}
|
|
13024
|
+
if (this.dataTextDiscrete && !Array.isArray(this.dataTextDiscrete))
|
|
13025
|
+
this.dataTextDiscrete = [this.dataTextDiscrete];
|
|
13026
|
+
this.discreteProps = {
|
|
13027
|
+
dataText: this.dataTextDiscrete,
|
|
13028
|
+
dataTextSeparator: this.dataTextSeparator,
|
|
13029
|
+
};
|
|
13030
|
+
this.preventLoadOnFocus = !this.datasource || !this.lazyLoad;
|
|
13031
|
+
this.preventLoadOnFocus = this.getInitValue('preventLoadOnFocus', props.preventLoadOnFocus, this.preventLoadOnFocus);
|
|
13032
|
+
this.value = this.getInitValue('value', props.value, this.value);
|
|
13105
13033
|
this.createAccessors();
|
|
13106
13034
|
}
|
|
13035
|
+
/**
|
|
13036
|
+
* Returns the currentRow in the dataText key
|
|
13037
|
+
*/
|
|
13038
|
+
formatter(value, props) { return this.formatterFn(value, props !== null && props !== void 0 ? props : this); }
|
|
13107
13039
|
focus(event, element) {
|
|
13108
13040
|
const _super = Object.create(null, {
|
|
13109
13041
|
focus: { get: () => super.focus }
|
|
@@ -13158,8 +13090,8 @@ class SelectTree extends TextInput {
|
|
|
13158
13090
|
children = undefined;
|
|
13159
13091
|
}
|
|
13160
13092
|
}
|
|
13161
|
-
const dataText = this.
|
|
13162
|
-
const dataTextDiscrete = this.
|
|
13093
|
+
const dataText = this.formatter(row);
|
|
13094
|
+
const dataTextDiscrete = this.formatter(row, this.discreteProps);
|
|
13163
13095
|
return {
|
|
13164
13096
|
id: row[this.dataValue],
|
|
13165
13097
|
label: dataText,
|
|
@@ -13179,40 +13111,6 @@ class SelectTree extends TextInput {
|
|
|
13179
13111
|
});
|
|
13180
13112
|
return newNodes;
|
|
13181
13113
|
}
|
|
13182
|
-
formatRow(dataText, row) {
|
|
13183
|
-
const dataTextArr = Array.isArray(dataText) ? dataText : [dataText];
|
|
13184
|
-
const dataTextNames = [];
|
|
13185
|
-
const masks = [];
|
|
13186
|
-
dataTextArr.forEach((text) => {
|
|
13187
|
-
if (typeof text === 'string') {
|
|
13188
|
-
dataTextNames.push(text);
|
|
13189
|
-
masks.push('');
|
|
13190
|
-
}
|
|
13191
|
-
else {
|
|
13192
|
-
dataTextNames.push(text.name);
|
|
13193
|
-
if (Accessor.isAccessorDefinition(text.mask)) {
|
|
13194
|
-
const [controller, accessor] = Accessor.getAccessor(text.mask);
|
|
13195
|
-
masks.push(Loader.getInstance(controller)[accessor]);
|
|
13196
|
-
}
|
|
13197
|
-
else {
|
|
13198
|
-
masks.push(text.mask);
|
|
13199
|
-
}
|
|
13200
|
-
}
|
|
13201
|
-
});
|
|
13202
|
-
const rowText = dataTextNames.reduce((result, column, index) => {
|
|
13203
|
-
if (row[column]) {
|
|
13204
|
-
const separator = index > 0 ? this.dataTextSeparator : '';
|
|
13205
|
-
let masked = row[column];
|
|
13206
|
-
if (masks[index]) {
|
|
13207
|
-
const maskValue = typeof masks[index] === 'function' ? masks[index](row[column]) : masks[index];
|
|
13208
|
-
masked = Mask.getValueWithMask(row[column], maskValue);
|
|
13209
|
-
}
|
|
13210
|
-
return result + separator + masked;
|
|
13211
|
-
}
|
|
13212
|
-
return result;
|
|
13213
|
-
}, '');
|
|
13214
|
-
return rowText;
|
|
13215
|
-
}
|
|
13216
13114
|
/**
|
|
13217
13115
|
* Triggered when the menu opens
|
|
13218
13116
|
*/
|
|
@@ -13236,6 +13134,7 @@ class SelectTree extends TextInput {
|
|
|
13236
13134
|
* Triggered after the search query changes
|
|
13237
13135
|
*/
|
|
13238
13136
|
searchChange(searchQuery, element) {
|
|
13137
|
+
this.search = searchQuery;
|
|
13239
13138
|
if (this.fetchOnDemand) {
|
|
13240
13139
|
if (!searchQuery && this.savedNodes) {
|
|
13241
13140
|
this.nodes = this.savedNodes;
|
|
@@ -13323,7 +13222,7 @@ class SelectTree extends TextInput {
|
|
|
13323
13222
|
if (!this.selectValue)
|
|
13324
13223
|
return this.selectValue;
|
|
13325
13224
|
if (this.returnObject) {
|
|
13326
|
-
return this.clearRow(this.selectValue.row);
|
|
13225
|
+
return this.clearRow(this.selectValue.row || this.selectValue);
|
|
13327
13226
|
}
|
|
13328
13227
|
return this.selectValue;
|
|
13329
13228
|
}
|
|
@@ -13370,6 +13269,8 @@ class SelectTree extends TextInput {
|
|
|
13370
13269
|
}
|
|
13371
13270
|
}
|
|
13372
13271
|
}
|
|
13272
|
+
const selectFormatterFn$1 = FormatterParserProvider.getFormatter('ZdSelect');
|
|
13273
|
+
FormatterParserProvider.registerFormatter('ZdSelectTree', selectFormatterFn$1);
|
|
13373
13274
|
InputFactory.register('ZdSelectTree', SelectTree);
|
|
13374
13275
|
|
|
13375
13276
|
/**
|
|
@@ -13394,7 +13295,6 @@ class SelectTreeMultiple extends SelectTree {
|
|
|
13394
13295
|
* Selected Nodes
|
|
13395
13296
|
*/
|
|
13396
13297
|
this.selectedNodes = [];
|
|
13397
|
-
this.selectValue = [];
|
|
13398
13298
|
/**
|
|
13399
13299
|
* Changes the behavior of checked nodes that will be displayed in the array of values
|
|
13400
13300
|
*/
|
|
@@ -13422,19 +13322,25 @@ class SelectTreeMultiple extends SelectTree {
|
|
|
13422
13322
|
this.callEvent('onDeselect', { element, component: this, node });
|
|
13423
13323
|
}
|
|
13424
13324
|
get value() {
|
|
13325
|
+
if (!this.selectValue)
|
|
13326
|
+
return [];
|
|
13425
13327
|
if (this.returnObject) {
|
|
13426
|
-
return this.selectValue.map((value) => this.clearRow(value.row));
|
|
13328
|
+
return this.selectValue.map((value) => this.clearRow(value.row || value));
|
|
13427
13329
|
}
|
|
13428
13330
|
return this.selectValue;
|
|
13429
13331
|
}
|
|
13430
13332
|
set value(value) {
|
|
13431
|
-
this.
|
|
13333
|
+
this.setValue(value);
|
|
13432
13334
|
}
|
|
13433
13335
|
setValue(value) {
|
|
13336
|
+
if (!value) {
|
|
13337
|
+
this.selectValue = [];
|
|
13338
|
+
return;
|
|
13339
|
+
}
|
|
13434
13340
|
const arrValue = Array.isArray(value) ? value : [value];
|
|
13435
13341
|
const key = this.datasource ? this.dataValue : 'id';
|
|
13436
13342
|
if (!this.returnObject) {
|
|
13437
|
-
this.
|
|
13343
|
+
this.selectValue = arrValue.map((item) => {
|
|
13438
13344
|
if (typeof item === 'object') {
|
|
13439
13345
|
return item[key];
|
|
13440
13346
|
}
|
|
@@ -13442,19 +13348,27 @@ class SelectTreeMultiple extends SelectTree {
|
|
|
13442
13348
|
});
|
|
13443
13349
|
return;
|
|
13444
13350
|
}
|
|
13445
|
-
this.
|
|
13351
|
+
this.selectValue = arrValue.map((item) => {
|
|
13446
13352
|
if (typeof item !== 'object') {
|
|
13447
13353
|
return { id: item };
|
|
13448
13354
|
}
|
|
13449
13355
|
return { id: item[key] };
|
|
13450
13356
|
});
|
|
13451
13357
|
}
|
|
13452
|
-
|
|
13453
|
-
|
|
13358
|
+
/**
|
|
13359
|
+
* Retrieves all nodes in the tree as a flat array. Nodes that are not matched are excluded
|
|
13360
|
+
* Nodes that are not matched but whose parent is matched are included
|
|
13361
|
+
* @param nodes
|
|
13362
|
+
* @param matched defines whether the parent of the current node branch is matched
|
|
13363
|
+
* @returns all nodes in the tree as a flat array, filtering unmatched nodes
|
|
13364
|
+
*/
|
|
13365
|
+
getAllNodes(nodes = this.nodes, matched = true) {
|
|
13366
|
+
let result = [...nodes];
|
|
13367
|
+
result = result.filter((node) => node.isMatched || matched);
|
|
13454
13368
|
nodes.forEach((node) => {
|
|
13455
13369
|
if (!node.children)
|
|
13456
13370
|
return;
|
|
13457
|
-
const childNodes = this.getAllNodes(node.children);
|
|
13371
|
+
const childNodes = this.getAllNodes(node.children, node.isMatched || matched);
|
|
13458
13372
|
result = [...result, ...childNodes];
|
|
13459
13373
|
});
|
|
13460
13374
|
return result;
|
|
@@ -13462,28 +13376,96 @@ class SelectTreeMultiple extends SelectTree {
|
|
|
13462
13376
|
/**
|
|
13463
13377
|
* Dispatches select/unselect event
|
|
13464
13378
|
*/
|
|
13465
|
-
onSelectAll(isSelected, event, element) {
|
|
13379
|
+
onSelectAll(isSelected, event, element, nodes = this.nodes) {
|
|
13466
13380
|
if (isSelected) {
|
|
13467
13381
|
this.callEvent('selectedAll', { event, element, component: this });
|
|
13468
13382
|
if (!event.defaultPrevented) {
|
|
13469
|
-
this.selectAllItems();
|
|
13383
|
+
this.selectAllItems(nodes);
|
|
13470
13384
|
}
|
|
13471
13385
|
}
|
|
13472
13386
|
else {
|
|
13473
13387
|
this.callEvent('unselectedAll', { event, element, component: this });
|
|
13474
13388
|
if (!event.defaultPrevented) {
|
|
13475
|
-
this.unSelectAllItems();
|
|
13389
|
+
this.unSelectAllItems(nodes);
|
|
13476
13390
|
}
|
|
13477
13391
|
}
|
|
13478
13392
|
}
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13393
|
+
/**
|
|
13394
|
+
* Selects all items in the tree \
|
|
13395
|
+
* If the component is fetchOnDemand, it will select all values from datasource.data \
|
|
13396
|
+
* If not, it will select all nodes from the tree, unless the nodes to be selected are specified
|
|
13397
|
+
* @param nodes nodes to be selected. These are the nodes that are currently visible in the tree
|
|
13398
|
+
* (if the user is searching, selects only the searched nodes)
|
|
13399
|
+
* @returns
|
|
13400
|
+
*/
|
|
13401
|
+
selectAllItems(nodes = this.nodes) {
|
|
13402
|
+
var _a;
|
|
13403
|
+
if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
|
|
13404
|
+
this.setValue(this.datasource.data);
|
|
13405
|
+
return;
|
|
13406
|
+
}
|
|
13407
|
+
const allNodes = this.getAllNodes(nodes, !this.search);
|
|
13408
|
+
// merge all nodes with the current value before setting it
|
|
13409
|
+
const currentValue = this.getValueAsObject();
|
|
13410
|
+
const nodeMap = this.createMergeMap(currentValue, allNodes);
|
|
13411
|
+
const uniqueArray = Array.from(nodeMap.values());
|
|
13412
|
+
this.setValue(uniqueArray);
|
|
13482
13413
|
}
|
|
13483
|
-
|
|
13484
|
-
|
|
13414
|
+
/**
|
|
13415
|
+
* Unelects all items in the tree \
|
|
13416
|
+
* If the component is fetchOnDemand, it will select all values from datasource.data \
|
|
13417
|
+
* If not, it will select all nodes from the tree, unless the nodes to be selected are specified
|
|
13418
|
+
* @param nodes nodes to be selected. These are the nodes that are currently visible in the tree
|
|
13419
|
+
* (if the user is searching, selects only the searched nodes)
|
|
13420
|
+
* @returns
|
|
13421
|
+
*/
|
|
13422
|
+
unSelectAllItems(nodes = this.nodes) {
|
|
13423
|
+
var _a;
|
|
13424
|
+
if (((_a = this.datasource) === null || _a === void 0 ? void 0 : _a.data) && this.fetchOnDemand) {
|
|
13425
|
+
this.setValue([]);
|
|
13426
|
+
return;
|
|
13427
|
+
}
|
|
13428
|
+
const allNodes = this.getAllNodes(nodes, !this.search);
|
|
13429
|
+
// merge all nodes with the current value before setting it
|
|
13430
|
+
const currentValue = this.getValueAsObject();
|
|
13431
|
+
const nodeMap = this.createMergeMap(currentValue);
|
|
13432
|
+
// remove the current visible nodes from the array
|
|
13433
|
+
const valuesToRemove = allNodes.map((node) => node.id);
|
|
13434
|
+
valuesToRemove.forEach((value) => {
|
|
13435
|
+
nodeMap.delete(value);
|
|
13436
|
+
});
|
|
13437
|
+
const uniqueArray = Array.from(nodeMap.values());
|
|
13438
|
+
this.setValue(uniqueArray);
|
|
13485
13439
|
}
|
|
13486
|
-
|
|
13440
|
+
/**
|
|
13441
|
+
* Takes two arrays and creates a map of the unique values
|
|
13442
|
+
* @returns map of a merge between the two arrays, removing duplicates
|
|
13443
|
+
*/
|
|
13444
|
+
createMergeMap(arr1, arr2 = []) {
|
|
13445
|
+
const mergedNodes = arr1.concat(arr2);
|
|
13446
|
+
// filter out duplicate nodes
|
|
13447
|
+
const uniqueMap = new Map();
|
|
13448
|
+
mergedNodes.forEach((node) => {
|
|
13449
|
+
uniqueMap.set(node.id, node);
|
|
13450
|
+
});
|
|
13451
|
+
return uniqueMap;
|
|
13452
|
+
}
|
|
13453
|
+
getValueIds() {
|
|
13454
|
+
if (this.returnObject) {
|
|
13455
|
+
return this.value.map((item) => item.id);
|
|
13456
|
+
}
|
|
13457
|
+
return this.value;
|
|
13458
|
+
}
|
|
13459
|
+
getValueAsObject() {
|
|
13460
|
+
return this.value.map((row) => {
|
|
13461
|
+
if (this.returnObject)
|
|
13462
|
+
return row;
|
|
13463
|
+
return { id: row };
|
|
13464
|
+
});
|
|
13465
|
+
}
|
|
13466
|
+
}
|
|
13467
|
+
const selectFormatterFn = FormatterParserProvider.getFormatter('ZdSelectMultiple');
|
|
13468
|
+
FormatterParserProvider.registerFormatter('ZdSelectTreeMultiple', selectFormatterFn);
|
|
13487
13469
|
|
|
13488
13470
|
/**
|
|
13489
13471
|
* Base class for SelectableList component.
|
|
@@ -15860,6 +15842,131 @@ class TreeGridEditable extends TreeGrid {
|
|
|
15860
15842
|
}
|
|
15861
15843
|
}
|
|
15862
15844
|
|
|
15845
|
+
const asArray = (value) => (Array.isArray(value) ? value : [value]);
|
|
15846
|
+
const getForeignLookupRow = (column, row, dataValue, dataTextColumns, foreignColumns) => {
|
|
15847
|
+
const lookupRow = {};
|
|
15848
|
+
dataTextColumns.forEach((item) => {
|
|
15849
|
+
const dataTextName = typeof item === 'string' ? item : item.name;
|
|
15850
|
+
lookupRow[dataTextName] = row[foreignColumns[dataTextName] || dataTextName];
|
|
15851
|
+
});
|
|
15852
|
+
lookupRow[dataValue] = row[column.name];
|
|
15853
|
+
return lookupRow;
|
|
15854
|
+
};
|
|
15855
|
+
const getFormatterLookupRow = (column, row, dataValue, formatterDataTextColumns, dataTextColumns) => {
|
|
15856
|
+
const lookupRow = {};
|
|
15857
|
+
formatterDataTextColumns.forEach((item, index) => {
|
|
15858
|
+
const dataTextValue = dataTextColumns[index];
|
|
15859
|
+
const dataTextName = typeof dataTextValue === 'string' ? dataTextValue : dataTextValue.name;
|
|
15860
|
+
const formatterDataTextColumn = typeof item === 'string' ? item : item.name;
|
|
15861
|
+
lookupRow[dataTextName] = row[formatterDataTextColumn];
|
|
15862
|
+
});
|
|
15863
|
+
lookupRow[dataValue] = row[column.name];
|
|
15864
|
+
return lookupRow;
|
|
15865
|
+
};
|
|
15866
|
+
/**
|
|
15867
|
+
* Stores data in column.lookupData when using foreignColumns or formatterDataText.
|
|
15868
|
+
* Makes a lookup when not using foreignColumns or formatterDataText
|
|
15869
|
+
* @returns the row from grid's datasource when using foreignColumns or formatterDataText. Otherwise,
|
|
15870
|
+
* returns the row from the column's component datasource
|
|
15871
|
+
*/
|
|
15872
|
+
const storeOrRetrieveLookup = (column, row, value, dataValue, componentProps) => {
|
|
15873
|
+
const { dataText, foreignColumns, formatterDataText, } = componentProps;
|
|
15874
|
+
const dataTextColumns = asArray(dataText);
|
|
15875
|
+
// when using foreignColumns, should store foreign keys information in lookupData
|
|
15876
|
+
if (foreignColumns) {
|
|
15877
|
+
column.lookupData[row[column.name]] = getForeignLookupRow(column, row, dataValue, dataTextColumns, foreignColumns);
|
|
15878
|
+
return row;
|
|
15879
|
+
}
|
|
15880
|
+
// when not using formatterDataText, should fetch data from datasource to be able to format this cell
|
|
15881
|
+
if (!formatterDataText) {
|
|
15882
|
+
return column.getLookupData(dataValue, value[dataValue] || value);
|
|
15883
|
+
}
|
|
15884
|
+
const formatterDataTextColumns = asArray(formatterDataText);
|
|
15885
|
+
// when using formatterDataText, should store dataText information in lookupData
|
|
15886
|
+
if (formatterDataTextColumns.length === dataTextColumns.length) {
|
|
15887
|
+
const rowColumn = row[column.name];
|
|
15888
|
+
column.lookupData[rowColumn] = getFormatterLookupRow(column, row, dataValue, formatterDataTextColumns, dataTextColumns);
|
|
15889
|
+
return row;
|
|
15890
|
+
}
|
|
15891
|
+
return row;
|
|
15892
|
+
};
|
|
15893
|
+
const formatter$1 = ({ column, value, row, componentProps, }) => {
|
|
15894
|
+
if (value === null || value === undefined)
|
|
15895
|
+
return '';
|
|
15896
|
+
const { dataText, formatterDataText, dataTextSeparator, dataValue, dataTextDiscrete, foreignColumns, } = componentProps;
|
|
15897
|
+
let currentRow = row;
|
|
15898
|
+
const dataTextColumns = asArray(dataText);
|
|
15899
|
+
// when dataValue is defined, should try to store or retrieve row data from lookupData
|
|
15900
|
+
if (dataValue) {
|
|
15901
|
+
currentRow = storeOrRetrieveLookup(column, row, value, dataValue, componentProps);
|
|
15902
|
+
}
|
|
15903
|
+
if (!Object.keys(currentRow).length)
|
|
15904
|
+
return typeof value === 'object' ? '' : value;
|
|
15905
|
+
let dataTextForeign = dataText;
|
|
15906
|
+
if (dataText && foreignColumns) {
|
|
15907
|
+
if (typeof dataText === 'string') {
|
|
15908
|
+
dataTextForeign = foreignColumns[dataText] || dataText;
|
|
15909
|
+
}
|
|
15910
|
+
else {
|
|
15911
|
+
dataTextForeign = dataTextColumns.map((item) => {
|
|
15912
|
+
const itemName = typeof item === 'string' ? item : item.name;
|
|
15913
|
+
return foreignColumns[itemName] || itemName;
|
|
15914
|
+
});
|
|
15915
|
+
}
|
|
15916
|
+
}
|
|
15917
|
+
const textColumn = dataTextDiscrete || formatterDataText || dataTextForeign;
|
|
15918
|
+
if (!textColumn)
|
|
15919
|
+
return value;
|
|
15920
|
+
if (typeof textColumn === 'string') {
|
|
15921
|
+
return currentRow[textColumn] || value;
|
|
15922
|
+
}
|
|
15923
|
+
const formatterFn = FormatterParserProvider.getFormatter('ZdSelect');
|
|
15924
|
+
return formatterFn(currentRow, { dataText: textColumn, dataTextSeparator });
|
|
15925
|
+
};
|
|
15926
|
+
FormatterParserProvider.registerFormatter('column_ZdSelect', formatter$1);
|
|
15927
|
+
FormatterParserProvider.registerFormatter('column_ZdSelectTree', formatter$1);
|
|
15928
|
+
|
|
15929
|
+
const formatter = ({ column, value, row, componentProps, }) => {
|
|
15930
|
+
if (!value || !Array.isArray(value) || value.length === 0)
|
|
15931
|
+
return '';
|
|
15932
|
+
const { formatterDataText, foreignColumns, dataText } = componentProps;
|
|
15933
|
+
const formatterFn = FormatterParserProvider.getFormatter('column_ZdSelect');
|
|
15934
|
+
const result = value.map((item, index) => {
|
|
15935
|
+
let formatterRow = Object.assign({}, row);
|
|
15936
|
+
const rowOverride = {};
|
|
15937
|
+
if (formatterDataText && formatterDataText.length > 0) {
|
|
15938
|
+
const columns = Array.isArray(formatterDataText) ? formatterDataText : [formatterDataText];
|
|
15939
|
+
columns.forEach((col) => {
|
|
15940
|
+
const textName = typeof col === 'string' ? col : col.name;
|
|
15941
|
+
rowOverride[textName] = row[textName][index];
|
|
15942
|
+
});
|
|
15943
|
+
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
15944
|
+
}
|
|
15945
|
+
else if (foreignColumns && dataText) {
|
|
15946
|
+
let dataTextForeign = dataText;
|
|
15947
|
+
if (typeof dataText === 'string') {
|
|
15948
|
+
dataTextForeign = [foreignColumns[dataText] || dataText];
|
|
15949
|
+
}
|
|
15950
|
+
else {
|
|
15951
|
+
dataTextForeign = dataText.map((col) => {
|
|
15952
|
+
const colName = typeof col === 'string' ? col : col.name;
|
|
15953
|
+
return foreignColumns[colName] || colName;
|
|
15954
|
+
});
|
|
15955
|
+
}
|
|
15956
|
+
dataTextForeign.forEach((col) => {
|
|
15957
|
+
rowOverride[col] = row[col][index];
|
|
15958
|
+
});
|
|
15959
|
+
formatterRow = Object.assign(Object.assign({}, row), rowOverride);
|
|
15960
|
+
}
|
|
15961
|
+
return formatterFn({
|
|
15962
|
+
column, value: item, row: formatterRow, componentProps,
|
|
15963
|
+
});
|
|
15964
|
+
});
|
|
15965
|
+
return result.join(', ');
|
|
15966
|
+
};
|
|
15967
|
+
FormatterParserProvider.registerFormatter('column_ZdSelectMultiple', formatter);
|
|
15968
|
+
FormatterParserProvider.registerFormatter('column_ZdSelectTreeMultiple', formatter);
|
|
15969
|
+
|
|
15863
15970
|
const AutoNumeric = require('@zeedhi/autonumeric/dist/autoNumeric');
|
|
15864
15971
|
const packageContent = require('../package.json');
|
|
15865
15972
|
VersionService.addPackageVersion(packageContent.name, packageContent.version);
|