@acorex/cdk 20.2.0-next.18 → 20.2.0-next.19
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/common/index.d.ts
CHANGED
|
@@ -210,13 +210,6 @@ declare class AXItemClickEvent<T = any> extends AXClickEvent {
|
|
|
210
210
|
name?: string;
|
|
211
211
|
item: T;
|
|
212
212
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Fires each time the user select the element.
|
|
215
|
-
* @category Events
|
|
216
|
-
*/
|
|
217
|
-
declare class AXItemSelectedEvent<T = any> extends AXEvent {
|
|
218
|
-
item: T;
|
|
219
|
-
}
|
|
220
213
|
/**
|
|
221
214
|
* Fires each time the component gets focused.
|
|
222
215
|
* @category Events
|
|
@@ -653,7 +646,6 @@ declare function convertArrayToDataSource<T = unknown>(items: T[], options?: {
|
|
|
653
646
|
key: string;
|
|
654
647
|
pageSize: number;
|
|
655
648
|
}): AXDataSource<T>;
|
|
656
|
-
declare function applyDataSourceQuery<T extends Record<string, unknown>>(items: T[], filter: AXDataSourceFilterOption): T[];
|
|
657
649
|
|
|
658
650
|
interface AXDataListQuery {
|
|
659
651
|
take?: number;
|
|
@@ -928,10 +920,6 @@ declare abstract class MXSelectionValueComponent<T = unknown> extends MXValueCom
|
|
|
928
920
|
/** Template string for formatting item display text */
|
|
929
921
|
get textTemplate(): string;
|
|
930
922
|
set textTemplate(value: string);
|
|
931
|
-
private _defaultText;
|
|
932
|
-
/** Text to display when neither textField nor valueField exist on the item */
|
|
933
|
-
get defaultText(): string;
|
|
934
|
-
set defaultText(value: string);
|
|
935
923
|
private _disabledField;
|
|
936
924
|
/** Field name used to determine if an item is disabled */
|
|
937
925
|
get disabledField(): string;
|
|
@@ -942,13 +930,6 @@ declare abstract class MXSelectionValueComponent<T = unknown> extends MXValueCom
|
|
|
942
930
|
set multiple(value: boolean);
|
|
943
931
|
/** Gets the currently selected items */
|
|
944
932
|
get selectedItems(): unknown[];
|
|
945
|
-
onItemSelected: EventEmitter<AXItemSelectedEvent>;
|
|
946
|
-
/**
|
|
947
|
-
* Emitted when an item in the list is clicked.
|
|
948
|
-
*
|
|
949
|
-
* @event
|
|
950
|
-
*/
|
|
951
|
-
onItemClick: EventEmitter<AXItemClickEvent>;
|
|
952
933
|
/**
|
|
953
934
|
* Abstract method to retrieve an item by its key
|
|
954
935
|
* @param key The unique identifier of the item
|
|
@@ -996,8 +977,8 @@ declare abstract class MXSelectionValueComponent<T = unknown> extends MXValueCom
|
|
|
996
977
|
*/
|
|
997
978
|
private createCacheKey;
|
|
998
979
|
/**
|
|
999
|
-
|
|
1000
|
-
|
|
980
|
+
* Normalizes currently selected items and updates the data service
|
|
981
|
+
*/
|
|
1001
982
|
private _normalizeSelectedItems;
|
|
1002
983
|
/**
|
|
1003
984
|
* Unselects the specified items from the selection
|
|
@@ -1026,12 +1007,6 @@ declare abstract class MXSelectionValueComponent<T = unknown> extends MXValueCom
|
|
|
1026
1007
|
* @returns True if the item is disabled
|
|
1027
1008
|
*/
|
|
1028
1009
|
isItemDisabled(item: T): boolean;
|
|
1029
|
-
/**
|
|
1030
|
-
* Checks if an item is currently loading
|
|
1031
|
-
* @param item Item to check
|
|
1032
|
-
* @returns True if the item is loading
|
|
1033
|
-
*/
|
|
1034
|
-
isItemLoading(item: T): boolean;
|
|
1035
1010
|
/**
|
|
1036
1011
|
* Gets the display text for an item using template or text field
|
|
1037
1012
|
* @param item Item to get display text for
|
|
@@ -1052,25 +1027,6 @@ declare abstract class MXSelectionValueComponent<T = unknown> extends MXValueCom
|
|
|
1052
1027
|
* Clears only the cache while preserving selected items
|
|
1053
1028
|
*/
|
|
1054
1029
|
protected softClearSelectionCache(): void;
|
|
1055
|
-
/**
|
|
1056
|
-
* Clears the debouncing cache for specific items to ensure fresh data is displayed
|
|
1057
|
-
*/
|
|
1058
|
-
protected clearItemDebouncingCache(item: T): void;
|
|
1059
|
-
/**
|
|
1060
|
-
* Forces a refresh of the display when items are loaded asynchronously
|
|
1061
|
-
* This should be called when the data source is updated
|
|
1062
|
-
*/
|
|
1063
|
-
protected refreshDisplay(): void;
|
|
1064
|
-
/**
|
|
1065
|
-
* Refreshes the display for all selected items to ensure consistency
|
|
1066
|
-
* This is useful when the data source has been updated
|
|
1067
|
-
*/
|
|
1068
|
-
protected refreshSelectedItemsDisplay(): void;
|
|
1069
|
-
/**
|
|
1070
|
-
* Forces a refresh of all selected items by clearing their debouncing cache
|
|
1071
|
-
* This ensures fresh data is displayed when the data source is updated
|
|
1072
|
-
*/
|
|
1073
|
-
protected forceRefreshSelectedItems(): void;
|
|
1074
1030
|
/**
|
|
1075
1031
|
* Asynchronously loads an item by its key and caches the result
|
|
1076
1032
|
* @param key Key to load item by
|
|
@@ -1154,5 +1110,5 @@ declare class AXHotkeysService {
|
|
|
1154
1110
|
static ɵprov: i0.ɵɵInjectableDeclaration<AXHotkeysService>;
|
|
1155
1111
|
}
|
|
1156
1112
|
|
|
1157
|
-
export { AXAutoFocusDirective, AXAutocompleteParentComponent, AXButtonClickEvent, AXClearableComponent, AXClickEvent, AXClosableComponent, AXCommonModule, AXComponent, AXComponentCloseEvent, AXComponentClosedPromise, AXComponentClosing, AXComponentResult, AXDataSource, AXDomService, AXEvent, AXFocusEvent, AXFocusableComponent, AXHotkeyDirective, AXHotkeysService, AXHtmlEvent, AXInfiniteScrollerDirective, AXInvertedColorDirective, AXItemClickEvent,
|
|
1113
|
+
export { AXAutoFocusDirective, AXAutocompleteParentComponent, AXButtonClickEvent, AXClearableComponent, AXClickEvent, AXClosableComponent, AXCommonModule, AXComponent, AXComponentCloseEvent, AXComponentClosedPromise, AXComponentClosing, AXComponentResult, AXDataSource, AXDomService, AXEvent, AXFocusEvent, AXFocusableComponent, AXHotkeyDirective, AXHotkeysService, AXHtmlEvent, AXInfiniteScrollerDirective, AXInvertedColorDirective, AXItemClickEvent, AXListDataSource, AXNgModelDelayedValueChangedDirective, AXOptionChangedEvent, AXPagedComponent, AXRangeChangedEvent, AXResponsiveDirective, AXRippleDirective, AXSearchableComponent, AXSelectionValueChangedEvent, AXValuableComponent, AXValueChangedEvent, AX_LOCATIONS, AX_PLACEMENT_BOTTOM, AX_PLACEMENT_BOTTOM_END, AX_PLACEMENT_BOTTOM_START, AX_PLACEMENT_END, AX_PLACEMENT_END_BOTTOM, AX_PLACEMENT_END_TOP, AX_PLACEMENT_MAP, AX_PLACEMENT_START, AX_PLACEMENT_START_BOTTOM, AX_PLACEMENT_START_TOP, AX_PLACEMENT_TOP, AX_PLACEMENT_TOP_END, AX_PLACEMENT_TOP_START, AX_SELECTION_DATA_TOKEN, AX_STYLE_COLOR_TYPES, AX_STYLE_LOOK_TYPES, MXBaseComponent, MXButtonBaseComponent, MXColorComponent, MXColorLookComponent, MXInputBaseValueComponent, MXInteractiveComponent, MXLookComponent, MXLookableComponent, MXSelectionBridgeService, MXSelectionValueComponent, MXValueComponent, NXButtonComponent, NXClickEvent, NXColorComponent, NXComponent, NXEvent, NXInteractiveComponent, NXLookComponent, NXNativeEvent, NXValueComponent, TAB_META_KEY, convertArrayToDataSource, convertToPlacement };
|
|
1158
1114
|
export type { AXAnimationEasing, AXComponentState, AXConnectedPosition, AXDataListFetchCallbackResult, AXDataListFetchDataCallback, AXDataListItems, AXDataListQuery, AXDataSourceByKeyCallback, AXDataSourceCallbackResult, AXDataSourceChangedEvent, AXDataSourceConfig, AXDataSourceFilterOption, AXDataSourceItemExpandedEvent, AXDataSourceLoadCallback, AXDataSourceOperator, AXDataSourceQuery, AXDataSourceSortOption, AXDirection, AXExpandToggleIcons, AXFilterLogic, AXFormValidationRule, AXHotKeyAction, AXLocation, AXOrientation, AXPagedComponentInterface, AXPlacement, AXPlacementType, AXRange, AXScrollPosition, AXSelectionMode, AXSizeType, AXSortOrder, AXStyleColorType, AXStyleLookType, AXStyleSizeType, AXSurfaceType, DisabledCallback, MXComponentOptionChanged, MXComponentOptionChanging, MXComponentSetOption, NormalizedItem };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { model, output, Component, inject, ElementRef, signal, afterNextRender, Injectable, ChangeDetectorRef, ViewContainerRef, EventEmitter, DOCUMENT, PLATFORM_ID, Renderer2, Input, Directive, NgModule, InjectionToken, Output, input, effect } from '@angular/core';
|
|
3
3
|
import { AXHtmlUtil } from '@acorex/core/utils';
|
|
4
|
-
import { flatten, clone, cloneDeep, isEqual, omit, set
|
|
4
|
+
import { flatten, clone, cloneDeep, isEqual, omit, set } from 'lodash-es';
|
|
5
5
|
import { isBrowser } from '@acorex/core/platform';
|
|
6
6
|
import { AXValidationService } from '@acorex/core/validation';
|
|
7
7
|
import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
|
|
@@ -871,12 +871,6 @@ class AXButtonClickEvent extends AXClickEvent {
|
|
|
871
871
|
*/
|
|
872
872
|
class AXItemClickEvent extends AXClickEvent {
|
|
873
873
|
}
|
|
874
|
-
/**
|
|
875
|
-
* Fires each time the user select the element.
|
|
876
|
-
* @category Events
|
|
877
|
-
*/
|
|
878
|
-
class AXItemSelectedEvent extends AXEvent {
|
|
879
|
-
}
|
|
880
874
|
/**
|
|
881
875
|
* Fires each time the component gets focused.
|
|
882
876
|
* @category Events
|
|
@@ -1173,49 +1167,33 @@ class AXDataSource {
|
|
|
1173
1167
|
}
|
|
1174
1168
|
}
|
|
1175
1169
|
function convertArrayToDataSource(items, options = { key: 'id', pageSize: 100 }) {
|
|
1176
|
-
// Normalize primitives to objects so consumers (e.g., select/list) can rely on
|
|
1177
|
-
// value and text fields without triggering extra byKey lookups.
|
|
1178
|
-
const normalizedItems = items.map((candidate) => {
|
|
1179
|
-
const isObjectItem = candidate != null && typeof candidate === 'object';
|
|
1180
|
-
if (isObjectItem) {
|
|
1181
|
-
return candidate;
|
|
1182
|
-
}
|
|
1183
|
-
// For primitive values, create an object with both key and text
|
|
1184
|
-
return { [options.key]: candidate, text: String(candidate ?? '') };
|
|
1185
|
-
});
|
|
1186
1170
|
const config = {
|
|
1187
1171
|
key: options.key,
|
|
1188
1172
|
pageSize: options.pageSize,
|
|
1189
1173
|
load: async (e) => {
|
|
1190
|
-
const
|
|
1191
|
-
const resultNormalized = e.filter
|
|
1192
|
-
? applyDataSourceQuery(itemsForFilter, e.filter)
|
|
1193
|
-
: itemsForFilter;
|
|
1194
|
-
const result = resultNormalized;
|
|
1174
|
+
const result = e.filter ? handleSearch(items, e.filter) : items;
|
|
1195
1175
|
return {
|
|
1196
1176
|
items: result.slice(e.skip, e.skip + e.take),
|
|
1197
|
-
total:
|
|
1177
|
+
total: result.length,
|
|
1198
1178
|
};
|
|
1199
1179
|
},
|
|
1200
|
-
byKey:
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
return record[options.key] == v;
|
|
1204
|
-
}),
|
|
1180
|
+
byKey: (v) => Promise.resolve(items.find((c) => {
|
|
1181
|
+
return c[options.key] == v;
|
|
1182
|
+
})),
|
|
1205
1183
|
};
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
if (!filter?.field || filter.value === undefined || filter.value === null) {
|
|
1210
|
-
return items; // No filter applied
|
|
1211
|
-
}
|
|
1212
|
-
return items.filter((item) => {
|
|
1213
|
-
const itemField = item[filter.field];
|
|
1214
|
-
if (typeof itemField === 'string' && typeof filter.value === 'string') {
|
|
1215
|
-
return itemField.toLowerCase().includes(filter.value.toLowerCase());
|
|
1184
|
+
const handleSearch = (items, filter) => {
|
|
1185
|
+
if (!filter?.field || filter.value === undefined || filter.value === null) {
|
|
1186
|
+
return items; // No filter applied
|
|
1216
1187
|
}
|
|
1217
|
-
return
|
|
1218
|
-
|
|
1188
|
+
return items.filter((item) => {
|
|
1189
|
+
const itemField = item[filter.field];
|
|
1190
|
+
if (typeof itemField === 'string' && typeof filter.value === 'string') {
|
|
1191
|
+
return itemField.toLowerCase().includes(filter.value.toLowerCase());
|
|
1192
|
+
}
|
|
1193
|
+
return false; // Return false if itemField isn't comparable
|
|
1194
|
+
});
|
|
1195
|
+
};
|
|
1196
|
+
return new AXDataSource(config);
|
|
1219
1197
|
}
|
|
1220
1198
|
|
|
1221
1199
|
const AX_STYLE_COLOR_TYPES = [
|
|
@@ -1744,18 +1722,8 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1744
1722
|
this._valueField = 'id';
|
|
1745
1723
|
this._textField = 'text';
|
|
1746
1724
|
this._textTemplate = '';
|
|
1747
|
-
this._defaultText = '-';
|
|
1748
1725
|
this._disabledField = 'disabled';
|
|
1749
1726
|
this._multiple = false;
|
|
1750
|
-
// #endregion
|
|
1751
|
-
// #region Events
|
|
1752
|
-
this.onItemSelected = new EventEmitter();
|
|
1753
|
-
/**
|
|
1754
|
-
* Emitted when an item in the list is clicked.
|
|
1755
|
-
*
|
|
1756
|
-
* @event
|
|
1757
|
-
*/
|
|
1758
|
-
this.onItemClick = new EventEmitter();
|
|
1759
1727
|
}
|
|
1760
1728
|
/** Field name used to extract the unique value from items */
|
|
1761
1729
|
get valueField() {
|
|
@@ -1778,13 +1746,6 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1778
1746
|
set textTemplate(value) {
|
|
1779
1747
|
this.setOption({ name: 'textTemplate', value });
|
|
1780
1748
|
}
|
|
1781
|
-
/** Text to display when neither textField nor valueField exist on the item */
|
|
1782
|
-
get defaultText() {
|
|
1783
|
-
return this._defaultText;
|
|
1784
|
-
}
|
|
1785
|
-
set defaultText(value) {
|
|
1786
|
-
this.setOption({ name: 'defaultText', value });
|
|
1787
|
-
}
|
|
1788
1749
|
/** Field name used to determine if an item is disabled */
|
|
1789
1750
|
get disabledField() {
|
|
1790
1751
|
return this._disabledField;
|
|
@@ -1822,22 +1783,16 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1822
1783
|
if (value == null || (isArray && value.length === 0)) {
|
|
1823
1784
|
return this.multiple ? [] : null;
|
|
1824
1785
|
}
|
|
1825
|
-
//
|
|
1786
|
+
// Normalize items and find by key if needed
|
|
1826
1787
|
const itemsToNormalize = isArray ? value : [value];
|
|
1827
|
-
const
|
|
1828
|
-
if (typeof item === 'object' && item !== null) {
|
|
1829
|
-
return get(item, this.textField) == null;
|
|
1830
|
-
}
|
|
1831
|
-
return true; // Primitive values need findByKey
|
|
1832
|
-
});
|
|
1833
|
-
const normalizedItems = this.normalizeItemsList(itemsToNormalize, needsFindByKey);
|
|
1788
|
+
const normalizedItems = this.normalizeItemsList(itemsToNormalize, true);
|
|
1834
1789
|
if (normalizedItems.length === 0) {
|
|
1835
1790
|
return this.multiple ? [] : null;
|
|
1836
1791
|
}
|
|
1837
1792
|
// Extract values based on selection mode
|
|
1838
1793
|
return this.multiple
|
|
1839
|
-
? normalizedItems.map(item =>
|
|
1840
|
-
:
|
|
1794
|
+
? normalizedItems.map(item => item[this.valueField])
|
|
1795
|
+
: normalizedItems[0]?.[this.valueField] ?? null;
|
|
1841
1796
|
}
|
|
1842
1797
|
/**
|
|
1843
1798
|
* Override to normalize selected items when value changes
|
|
@@ -1870,24 +1825,22 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1870
1825
|
normalizeItem(item, findByKey = false) {
|
|
1871
1826
|
const isComplexObject = typeof item === 'object' && item !== null;
|
|
1872
1827
|
const itemRecord = item;
|
|
1873
|
-
const
|
|
1874
|
-
const key = valueKey != null ? String(valueKey) : String(item);
|
|
1828
|
+
const key = isComplexObject ? String(itemRecord[this.valueField]) : String(item);
|
|
1875
1829
|
const cacheKey = this.createCacheKey(key);
|
|
1876
1830
|
// Return cached item if available and has text
|
|
1877
1831
|
const cachedItem = this.dataService.cacheList[cacheKey];
|
|
1878
|
-
if (cachedItem &&
|
|
1832
|
+
if (cachedItem && cachedItem[this.textField]) {
|
|
1879
1833
|
return cachedItem;
|
|
1880
1834
|
}
|
|
1881
|
-
const hasTextProperty = !isComplexObject ||
|
|
1835
|
+
const hasTextProperty = !isComplexObject || itemRecord[this.textField] != null;
|
|
1882
1836
|
const normalizedObj = {};
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
this.handleItemNormalization(normalizedObj, item, key, true, cacheKey);
|
|
1837
|
+
if (isComplexObject && hasTextProperty) {
|
|
1838
|
+
// Item already has all required properties
|
|
1839
|
+
Object.assign(normalizedObj, item);
|
|
1887
1840
|
}
|
|
1888
1841
|
else {
|
|
1889
|
-
//
|
|
1890
|
-
|
|
1842
|
+
// Need to find or create item properties
|
|
1843
|
+
this.handleItemNormalization(normalizedObj, item, key, findByKey, cacheKey);
|
|
1891
1844
|
}
|
|
1892
1845
|
this.dataService.cacheList[cacheKey] = normalizedObj;
|
|
1893
1846
|
return normalizedObj;
|
|
@@ -1914,7 +1867,7 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1914
1867
|
// Set loading state
|
|
1915
1868
|
obj[this.valueField] = key;
|
|
1916
1869
|
obj['isLoading'] = true;
|
|
1917
|
-
obj[this.textField] = 'Loading
|
|
1870
|
+
obj[this.textField] = 'Loading';
|
|
1918
1871
|
promise
|
|
1919
1872
|
.then(result => {
|
|
1920
1873
|
if (typeof result === 'object' && result) {
|
|
@@ -1924,23 +1877,11 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1924
1877
|
obj[this.valueField] = result || key;
|
|
1925
1878
|
obj[this.textField] = result;
|
|
1926
1879
|
}
|
|
1927
|
-
})
|
|
1928
|
-
.catch(error => {
|
|
1929
|
-
console.warn('Failed to load item by key:', key, error);
|
|
1930
|
-
// On error, keep the original value but mark as failed
|
|
1931
|
-
obj[this.textField] = this.defaultText;
|
|
1932
1880
|
})
|
|
1933
1881
|
.finally(() => {
|
|
1934
1882
|
delete obj['isLoading'];
|
|
1935
|
-
delete obj['_displayTextLoading'];
|
|
1936
|
-
delete obj['_loadingTriggered'];
|
|
1937
1883
|
this.dataService.cacheList[cacheKey] = obj;
|
|
1938
|
-
|
|
1939
|
-
setTimeout(() => {
|
|
1940
|
-
if (this.cdr) {
|
|
1941
|
-
this.cdr.markForCheck();
|
|
1942
|
-
}
|
|
1943
|
-
}, 0);
|
|
1884
|
+
this.cdr.markForCheck();
|
|
1944
1885
|
});
|
|
1945
1886
|
}
|
|
1946
1887
|
/**
|
|
@@ -1950,16 +1891,12 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1950
1891
|
const isSourceObject = typeof sourceItem === 'object' && sourceItem !== null;
|
|
1951
1892
|
const sourceRecord = sourceItem;
|
|
1952
1893
|
if (isComplexSource && isSourceObject) {
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
obj[this.valueField] = (valueFromSource ?? textFromSource);
|
|
1956
|
-
obj[this.textField] = (textFromSource ?? valueFromSource ?? this.defaultText);
|
|
1894
|
+
obj[this.valueField] = sourceRecord[this.valueField];
|
|
1895
|
+
obj[this.textField] = sourceRecord[this.textField];
|
|
1957
1896
|
}
|
|
1958
1897
|
else {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
obj[this.valueField] = (valueFromSource ?? textFromSource);
|
|
1962
|
-
obj[this.textField] = (textFromSource ?? valueFromSource ?? this.defaultText);
|
|
1898
|
+
obj[this.valueField] = isSourceObject ? sourceRecord[this.valueField] : sourceItem;
|
|
1899
|
+
obj[this.textField] = isSourceObject ? sourceRecord[this.textField] : sourceItem;
|
|
1963
1900
|
}
|
|
1964
1901
|
}
|
|
1965
1902
|
/**
|
|
@@ -1969,19 +1906,13 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1969
1906
|
return `k-${key}`;
|
|
1970
1907
|
}
|
|
1971
1908
|
/**
|
|
1972
|
-
|
|
1973
|
-
|
|
1909
|
+
* Normalizes currently selected items and updates the data service
|
|
1910
|
+
*/
|
|
1974
1911
|
_normalizeSelectedItems() {
|
|
1975
1912
|
const values = Array.isArray(this.value)
|
|
1976
1913
|
? this.value
|
|
1977
1914
|
: this.value != null ? [this.value] : [];
|
|
1978
|
-
|
|
1979
|
-
// This prevents unnecessary API calls for items that already have text
|
|
1980
|
-
this.dataService.selectedItems = values.map(value => {
|
|
1981
|
-
const hasText = typeof value === 'object' && value !== null &&
|
|
1982
|
-
get(value, this.textField) != null;
|
|
1983
|
-
return this.normalizeItem(value, !hasText);
|
|
1984
|
-
});
|
|
1915
|
+
this.dataService.selectedItems = values.map(value => this.normalizeItem(value));
|
|
1985
1916
|
}
|
|
1986
1917
|
// #endregion
|
|
1987
1918
|
// #region Public Selection Methods
|
|
@@ -1995,7 +1926,7 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
1995
1926
|
return;
|
|
1996
1927
|
}
|
|
1997
1928
|
const normalizedItems = this.normalizeItemsList(items);
|
|
1998
|
-
const newSelectedItems = this.selectedItems.filter(selectedItem => !normalizedItems.some(normalizedItem =>
|
|
1929
|
+
const newSelectedItems = this.selectedItems.filter(selectedItem => !normalizedItems.some(normalizedItem => normalizedItem[this.valueField] === selectedItem[this.valueField]));
|
|
1999
1930
|
this.commitValue(newSelectedItems, true);
|
|
2000
1931
|
}
|
|
2001
1932
|
/**
|
|
@@ -2003,20 +1934,13 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2003
1934
|
* @param items Items to select
|
|
2004
1935
|
*/
|
|
2005
1936
|
selectItems(...items) {
|
|
2006
|
-
if (!items?.length)
|
|
1937
|
+
if (!items?.length)
|
|
2007
1938
|
return;
|
|
2008
|
-
}
|
|
2009
1939
|
const currentValue = Array.isArray(this.value) ? this.value : [this.value];
|
|
2010
1940
|
const normalizedItems = this.normalizeItemsList(items);
|
|
2011
1941
|
const newSelectedItems = this.multiple
|
|
2012
1942
|
? [...currentValue, ...normalizedItems]
|
|
2013
1943
|
: normalizedItems;
|
|
2014
|
-
this.onItemSelected.emit({
|
|
2015
|
-
component: this,
|
|
2016
|
-
isUserInteraction: true,
|
|
2017
|
-
item: newSelectedItems[0],
|
|
2018
|
-
htmlElement: this.getHostElement()
|
|
2019
|
-
});
|
|
2020
1944
|
this.commitValue(newSelectedItems, true);
|
|
2021
1945
|
}
|
|
2022
1946
|
/**
|
|
@@ -2044,8 +1968,7 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2044
1968
|
*/
|
|
2045
1969
|
isItemSelected(item) {
|
|
2046
1970
|
const normalizedItem = this.normalizeItem(item);
|
|
2047
|
-
|
|
2048
|
-
return this.selectedItems.some(selectedItem => get(selectedItem, this.valueField) === normalizedValue);
|
|
1971
|
+
return this.selectedItems.some(selectedItem => selectedItem[this.valueField] === normalizedItem[this.valueField]);
|
|
2049
1972
|
}
|
|
2050
1973
|
/**
|
|
2051
1974
|
* Checks if an item is disabled
|
|
@@ -2055,18 +1978,9 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2055
1978
|
isItemDisabled(item) {
|
|
2056
1979
|
const itemRecord = item;
|
|
2057
1980
|
return (this.disabled ||
|
|
2058
|
-
coerceBooleanProperty(
|
|
1981
|
+
coerceBooleanProperty(itemRecord[this.disabledField]) === true ||
|
|
2059
1982
|
(this.disabledCallback?.({ item, index: -1 }) ?? false));
|
|
2060
1983
|
}
|
|
2061
|
-
/**
|
|
2062
|
-
* Checks if an item is currently loading
|
|
2063
|
-
* @param item Item to check
|
|
2064
|
-
* @returns True if the item is loading
|
|
2065
|
-
*/
|
|
2066
|
-
isItemLoading(item) {
|
|
2067
|
-
const normalizedItem = this.normalizeItem(item);
|
|
2068
|
-
return normalizedItem['isLoading'] === true;
|
|
2069
|
-
}
|
|
2070
1984
|
// #endregion
|
|
2071
1985
|
// #region Protected Utility Methods
|
|
2072
1986
|
/**
|
|
@@ -2075,108 +1989,22 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2075
1989
|
* @returns Formatted display text
|
|
2076
1990
|
*/
|
|
2077
1991
|
getDisplayText(item) {
|
|
2078
|
-
|
|
2079
|
-
if (item && typeof item === 'object' && item['_displayTextLoading']) {
|
|
2080
|
-
return 'Loading...';
|
|
2081
|
-
}
|
|
2082
|
-
// Add timestamp-based debouncing to prevent excessive calls for ALL item types
|
|
2083
|
-
const now = Date.now();
|
|
2084
|
-
const itemKey = typeof item === 'string' ? item : get(item, this.valueField);
|
|
2085
|
-
const cacheKey = this.createCacheKey(String(itemKey));
|
|
2086
|
-
// Check if we have a recent result in the cache to prevent duplicate processing
|
|
2087
|
-
const cachedResult = this.dataService.cacheList[cacheKey];
|
|
2088
|
-
if (cachedResult && cachedResult['_lastDisplayTextCall']) {
|
|
2089
|
-
const timeSinceLastCall = now - cachedResult['_lastDisplayTextCall'];
|
|
2090
|
-
if (timeSinceLastCall < 50) { // 50ms debounce
|
|
2091
|
-
return cachedResult['_lastDisplayTextResult'] || String(itemKey || '');
|
|
2092
|
-
}
|
|
2093
|
-
}
|
|
2094
|
-
// For string values, we need to normalize with findByKey=true to trigger async loading
|
|
2095
|
-
const isStringValue = typeof item === 'string';
|
|
2096
|
-
const normalizedItem = this.normalizeItem(item, isStringValue);
|
|
2097
|
-
// Check if this item is already in the cache with proper text
|
|
2098
|
-
const itemValue = get(normalizedItem, this.valueField);
|
|
2099
|
-
if (itemValue != null && itemValue !== '') {
|
|
2100
|
-
const cacheKey = this.createCacheKey(String(itemValue));
|
|
2101
|
-
const cachedItem = this.dataService.cacheList[cacheKey];
|
|
2102
|
-
if (cachedItem && get(cachedItem, this.textField) != null) {
|
|
2103
|
-
// Use cached text if available
|
|
2104
|
-
const cachedText = get(cachedItem, this.textField);
|
|
2105
|
-
if (cachedText && cachedText !== 'Loading...') {
|
|
2106
|
-
const result = String(cachedText);
|
|
2107
|
-
// Cache the timestamp and result for debouncing in the cache (works for all item types)
|
|
2108
|
-
if (cachedItem) {
|
|
2109
|
-
cachedItem['_lastDisplayTextCall'] = now;
|
|
2110
|
-
cachedItem['_lastDisplayTextResult'] = result;
|
|
2111
|
-
}
|
|
2112
|
-
return result;
|
|
2113
|
-
}
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
1992
|
+
const normalizedItem = this.normalizeItem(item);
|
|
2116
1993
|
// Try template formatting first
|
|
2117
1994
|
if (this.textTemplate) {
|
|
2118
1995
|
const formattedTemplate = this.formatService.format(this.textTemplate, 'string', normalizedItem);
|
|
2119
1996
|
if (formattedTemplate !== this.textTemplate) {
|
|
2120
|
-
|
|
2121
|
-
// Cache the timestamp and result for debouncing in the cache
|
|
2122
|
-
if (normalizedItem) {
|
|
2123
|
-
normalizedItem['_lastDisplayTextCall'] = now;
|
|
2124
|
-
normalizedItem['_lastDisplayTextResult'] = result;
|
|
2125
|
-
}
|
|
2126
|
-
return result;
|
|
1997
|
+
return formattedTemplate;
|
|
2127
1998
|
}
|
|
2128
1999
|
}
|
|
2129
2000
|
// Use text field or fallback to value field
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
const result = String(textValue);
|
|
2133
|
-
// Cache the timestamp and result for debouncing in the cache
|
|
2134
|
-
if (normalizedItem) {
|
|
2135
|
-
normalizedItem['_lastDisplayTextCall'] = now;
|
|
2136
|
-
normalizedItem['_lastDisplayTextResult'] = result;
|
|
2137
|
-
}
|
|
2138
|
-
return result;
|
|
2139
|
-
}
|
|
2140
|
-
// If text is missing and item is loading, show loading state
|
|
2141
|
-
if (normalizedItem['isLoading']) {
|
|
2142
|
-
const result = 'Loading...';
|
|
2143
|
-
// Cache the timestamp and result for debouncing in the cache
|
|
2144
|
-
if (normalizedItem) {
|
|
2145
|
-
normalizedItem['_lastDisplayTextCall'] = now;
|
|
2146
|
-
normalizedItem['_lastDisplayTextResult'] = result;
|
|
2147
|
-
}
|
|
2148
|
-
return result;
|
|
2001
|
+
if (normalizedItem[this.textField]) {
|
|
2002
|
+
return String(normalizedItem[this.textField]);
|
|
2149
2003
|
}
|
|
2150
2004
|
// Attempt to load item by key if text is missing
|
|
2151
|
-
const value =
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
// Cache the timestamp and result for debouncing in the cache
|
|
2155
|
-
if (normalizedItem) {
|
|
2156
|
-
normalizedItem['_lastDisplayTextCall'] = now;
|
|
2157
|
-
normalizedItem['_lastDisplayTextResult'] = result;
|
|
2158
|
-
}
|
|
2159
|
-
return result;
|
|
2160
|
-
}
|
|
2161
|
-
// If we have a value but no text, trigger async loading only once
|
|
2162
|
-
// Use a flag to prevent multiple calls
|
|
2163
|
-
if (!normalizedItem['_loadingTriggered'] && !normalizedItem[this.textField]) {
|
|
2164
|
-
normalizedItem['_loadingTriggered'] = true;
|
|
2165
|
-
normalizedItem['_displayTextLoading'] = true;
|
|
2166
|
-
// Use setTimeout to defer the async loading and prevent immediate change detection
|
|
2167
|
-
setTimeout(() => {
|
|
2168
|
-
this.loadAndCacheItemByKey(value);
|
|
2169
|
-
}, 0);
|
|
2170
|
-
}
|
|
2171
|
-
// Return the value itself as a fallback
|
|
2172
|
-
// This will be updated once the async loading completes
|
|
2173
|
-
const result = String(value);
|
|
2174
|
-
// Cache the timestamp and result for debouncing in the cache
|
|
2175
|
-
if (normalizedItem) {
|
|
2176
|
-
normalizedItem['_lastDisplayTextCall'] = now;
|
|
2177
|
-
normalizedItem['_lastDisplayTextResult'] = result;
|
|
2178
|
-
}
|
|
2179
|
-
return result;
|
|
2005
|
+
const value = normalizedItem[this.valueField];
|
|
2006
|
+
this.loadAndCacheItemByKey(value);
|
|
2007
|
+
return String(value);
|
|
2180
2008
|
}
|
|
2181
2009
|
/**
|
|
2182
2010
|
* Gets the value of an item
|
|
@@ -2185,7 +2013,7 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2185
2013
|
*/
|
|
2186
2014
|
getValue(item) {
|
|
2187
2015
|
const normalizedItem = this.normalizeItem(item);
|
|
2188
|
-
return
|
|
2016
|
+
return normalizedItem[this.valueField];
|
|
2189
2017
|
}
|
|
2190
2018
|
/**
|
|
2191
2019
|
* Clears the selection cache and selected items
|
|
@@ -2202,52 +2030,6 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2202
2030
|
this.dataService.cacheList = {};
|
|
2203
2031
|
this.cdr.markForCheck();
|
|
2204
2032
|
}
|
|
2205
|
-
/**
|
|
2206
|
-
* Clears the debouncing cache for specific items to ensure fresh data is displayed
|
|
2207
|
-
*/
|
|
2208
|
-
clearItemDebouncingCache(item) {
|
|
2209
|
-
// Get the cache key for this item
|
|
2210
|
-
const itemKey = typeof item === 'string' ? item : get(item, this.valueField);
|
|
2211
|
-
if (itemKey != null) {
|
|
2212
|
-
const cacheKey = this.createCacheKey(String(itemKey));
|
|
2213
|
-
const cachedItem = this.dataService.cacheList[cacheKey];
|
|
2214
|
-
if (cachedItem) {
|
|
2215
|
-
delete cachedItem['_lastDisplayTextCall'];
|
|
2216
|
-
delete cachedItem['_lastDisplayTextResult'];
|
|
2217
|
-
delete cachedItem['_displayTextLoading'];
|
|
2218
|
-
delete cachedItem['_loadingTriggered'];
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
/**
|
|
2223
|
-
* Forces a refresh of the display when items are loaded asynchronously
|
|
2224
|
-
* This should be called when the data source is updated
|
|
2225
|
-
*/
|
|
2226
|
-
refreshDisplay() {
|
|
2227
|
-
this.cdr.markForCheck();
|
|
2228
|
-
}
|
|
2229
|
-
/**
|
|
2230
|
-
* Refreshes the display for all selected items to ensure consistency
|
|
2231
|
-
* This is useful when the data source has been updated
|
|
2232
|
-
*/
|
|
2233
|
-
refreshSelectedItemsDisplay() {
|
|
2234
|
-
// Force a refresh of the display without re-normalizing to avoid infinite loops
|
|
2235
|
-
if (this.selectedItems.length > 0) {
|
|
2236
|
-
this.cdr.markForCheck();
|
|
2237
|
-
}
|
|
2238
|
-
}
|
|
2239
|
-
/**
|
|
2240
|
-
* Forces a refresh of all selected items by clearing their debouncing cache
|
|
2241
|
-
* This ensures fresh data is displayed when the data source is updated
|
|
2242
|
-
*/
|
|
2243
|
-
forceRefreshSelectedItems() {
|
|
2244
|
-
if (this.selectedItems.length > 0) {
|
|
2245
|
-
this.selectedItems.forEach(item => {
|
|
2246
|
-
this.clearItemDebouncingCache(item);
|
|
2247
|
-
});
|
|
2248
|
-
this.cdr.markForCheck();
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
2033
|
// #endregion
|
|
2252
2034
|
// #region Private Helper Methods
|
|
2253
2035
|
/**
|
|
@@ -2260,29 +2042,12 @@ class MXSelectionValueComponent extends MXValueComponent {
|
|
|
2260
2042
|
if (item) {
|
|
2261
2043
|
const normalizedItem = this.normalizeItem(item);
|
|
2262
2044
|
const cacheKey = this.createCacheKey(String(normalizedItem[this.valueField]));
|
|
2263
|
-
// Update the cache with the loaded item
|
|
2264
2045
|
this.dataService.cacheList[cacheKey] = normalizedItem;
|
|
2265
|
-
|
|
2266
|
-
if (this.dataService.cacheList[cacheKey]) {
|
|
2267
|
-
delete this.dataService.cacheList[cacheKey]['_displayTextLoading'];
|
|
2268
|
-
delete this.dataService.cacheList[cacheKey]['_loadingTriggered'];
|
|
2269
|
-
}
|
|
2270
|
-
// Use setTimeout to defer change detection and prevent immediate re-rendering
|
|
2271
|
-
setTimeout(() => {
|
|
2272
|
-
if (this.cdr) {
|
|
2273
|
-
this.cdr.markForCheck();
|
|
2274
|
-
}
|
|
2275
|
-
}, 0);
|
|
2046
|
+
this.cdr.markForCheck();
|
|
2276
2047
|
}
|
|
2277
2048
|
}
|
|
2278
2049
|
catch (error) {
|
|
2279
2050
|
console.warn('Failed to load item by key:', key, error);
|
|
2280
|
-
// Clear loading flags on error too
|
|
2281
|
-
const cacheKey = this.createCacheKey(String(key));
|
|
2282
|
-
if (this.dataService.cacheList[cacheKey]) {
|
|
2283
|
-
delete this.dataService.cacheList[cacheKey]['_displayTextLoading'];
|
|
2284
|
-
delete this.dataService.cacheList[cacheKey]['_loadingTriggered'];
|
|
2285
|
-
}
|
|
2286
2051
|
}
|
|
2287
2052
|
}
|
|
2288
2053
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.8", ngImport: i0, type: MXSelectionValueComponent, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
@@ -2450,5 +2215,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.8", ngImpor
|
|
|
2450
2215
|
* Generated bundle index. Do not edit.
|
|
2451
2216
|
*/
|
|
2452
2217
|
|
|
2453
|
-
export { AXAutoFocusDirective, AXAutocompleteParentComponent, AXButtonClickEvent, AXClearableComponent, AXClickEvent, AXClosableComponent, AXCommonModule, AXComponent, AXComponentCloseEvent, AXComponentClosedPromise, AXComponentClosing, AXComponentResult, AXDataSource, AXDomService, AXEvent, AXFocusEvent, AXFocusableComponent, AXHotkeyDirective, AXHotkeysService, AXHtmlEvent, AXInfiniteScrollerDirective, AXInvertedColorDirective, AXItemClickEvent,
|
|
2218
|
+
export { AXAutoFocusDirective, AXAutocompleteParentComponent, AXButtonClickEvent, AXClearableComponent, AXClickEvent, AXClosableComponent, AXCommonModule, AXComponent, AXComponentCloseEvent, AXComponentClosedPromise, AXComponentClosing, AXComponentResult, AXDataSource, AXDomService, AXEvent, AXFocusEvent, AXFocusableComponent, AXHotkeyDirective, AXHotkeysService, AXHtmlEvent, AXInfiniteScrollerDirective, AXInvertedColorDirective, AXItemClickEvent, AXListDataSource, AXNgModelDelayedValueChangedDirective, AXOptionChangedEvent, AXPagedComponent, AXRangeChangedEvent, AXResponsiveDirective, AXRippleDirective, AXSearchableComponent, AXSelectionValueChangedEvent, AXValuableComponent, AXValueChangedEvent, AX_LOCATIONS, AX_PLACEMENT_BOTTOM, AX_PLACEMENT_BOTTOM_END, AX_PLACEMENT_BOTTOM_START, AX_PLACEMENT_END, AX_PLACEMENT_END_BOTTOM, AX_PLACEMENT_END_TOP, AX_PLACEMENT_MAP, AX_PLACEMENT_START, AX_PLACEMENT_START_BOTTOM, AX_PLACEMENT_START_TOP, AX_PLACEMENT_TOP, AX_PLACEMENT_TOP_END, AX_PLACEMENT_TOP_START, AX_SELECTION_DATA_TOKEN, AX_STYLE_COLOR_TYPES, AX_STYLE_LOOK_TYPES, MXBaseComponent, MXButtonBaseComponent, MXColorComponent, MXColorLookComponent, MXInputBaseValueComponent, MXInteractiveComponent, MXLookComponent, MXLookableComponent, MXSelectionBridgeService, MXSelectionValueComponent, MXValueComponent, NXButtonComponent, NXClickEvent, NXColorComponent, NXComponent, NXEvent, NXInteractiveComponent, NXLookComponent, NXNativeEvent, NXValueComponent, TAB_META_KEY, convertArrayToDataSource, convertToPlacement };
|
|
2454
2219
|
//# sourceMappingURL=acorex-cdk-common.mjs.map
|