@kosdev-code/kos-ui-sdk 2.1.7 → 2.1.9
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.
|
@@ -4,24 +4,116 @@ import { IKosModelContainer } from '../core/kos-container-model';
|
|
|
4
4
|
interface Identifiable {
|
|
5
5
|
id: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Function that transforms an entity, typically to update its id property before container insertion.
|
|
9
|
+
* Useful for normalizing ids or adding prefixes/suffixes.
|
|
10
|
+
*/
|
|
7
11
|
export type IdMapper = <D extends Identifiable = Identifiable>(entity: D) => D;
|
|
8
12
|
type Container = IKosContainerModel<any, any> | IKosModelContainer<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Parameters for resolving container deltas.
|
|
15
|
+
* @template T - The container type
|
|
16
|
+
* @template D - The entity type with an id property
|
|
17
|
+
*/
|
|
9
18
|
interface ResolveParams<T extends Container, D> {
|
|
19
|
+
/** The container to synchronize */
|
|
10
20
|
container: T;
|
|
21
|
+
/** Callback to create a new item when an entity is added */
|
|
11
22
|
onAddItem: (entity: D) => any;
|
|
23
|
+
/** Optional callback when an item is removed, receives the id to remove */
|
|
12
24
|
onRemoveItem?: (id: string) => any;
|
|
25
|
+
/** Optional callback when an existing item needs updating */
|
|
13
26
|
onUpdateItem?: (entity: D, existingModel: any) => any;
|
|
27
|
+
/** Optional mapper to transform entity ids before processing */
|
|
14
28
|
idMapper?: IdMapper;
|
|
15
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a function that synchronizes a container with a new list of entities.
|
|
32
|
+
* Handles additions, removals, and optional updates to keep the container in sync.
|
|
33
|
+
*
|
|
34
|
+
* @template T - Container type implementing IKosModelContainer
|
|
35
|
+
* @template D - Entity type with an id property
|
|
36
|
+
* @param params - Configuration for resolving deltas
|
|
37
|
+
* @returns A function that accepts entities and synchronizes the container
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* const syncUsers = resolveContainerDeltas({
|
|
41
|
+
* container: userContainer,
|
|
42
|
+
* onAddItem: (user) => User.instance(user.id).options(user).build(),
|
|
43
|
+
* onUpdateItem: (user, existing) => existing.update(user),
|
|
44
|
+
* onRemoveItem: (id) => id
|
|
45
|
+
* });
|
|
46
|
+
* syncUsers(newUserList);
|
|
47
|
+
*/
|
|
16
48
|
export declare const resolveContainerDeltas: <T extends IKosModelContainer<any>, D extends Identifiable>({ container, onAddItem, onUpdateItem, onRemoveItem, idMapper, }: ResolveParams<T, D>) => (entities: D[]) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a function that synchronizes a container model's list with new entities.
|
|
51
|
+
* Simpler alternative to resolveContainerDeltas that directly invokes callbacks for each addition and removal.
|
|
52
|
+
*
|
|
53
|
+
* @template T - Container model type implementing IKosContainerModel
|
|
54
|
+
* @template D - Entity type with an id property
|
|
55
|
+
* @param params - Configuration for resolving deltas
|
|
56
|
+
* @returns A function that accepts entities and synchronizes by invoking callbacks
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const syncLayers = resolveListDeltas({
|
|
60
|
+
* container: layerContainer,
|
|
61
|
+
* onAddItem: (layer) => addLayer(layer),
|
|
62
|
+
* onRemoveItem: (id) => removeLayer(id)
|
|
63
|
+
* });
|
|
64
|
+
* syncLayers(newLayerList);
|
|
65
|
+
*/
|
|
17
66
|
export declare const resolveListDeltas: <T extends IKosContainerModel<any, any>, D extends Identifiable>({ container, onAddItem, onRemoveItem, idMapper, }: ResolveParams<T, D>) => (entities: D[]) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Parameters for resolving deltas on plain item arrays (not container models).
|
|
69
|
+
* @template T - Current item type with an id property
|
|
70
|
+
* @template D - New entity type with an id property
|
|
71
|
+
*/
|
|
18
72
|
interface ResolveItemsParams<T extends Identifiable, D> {
|
|
73
|
+
/** The current array of items to synchronize */
|
|
19
74
|
items: T[];
|
|
75
|
+
/** Callback invoked for each entity to add */
|
|
20
76
|
onAddItem: (entity: D) => void;
|
|
77
|
+
/** Callback invoked for each id to remove */
|
|
21
78
|
onRemoveItem: (id: string) => void;
|
|
79
|
+
/** Optional mapper to transform entity ids before processing */
|
|
22
80
|
idMapper?: IdMapper;
|
|
23
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a function that synchronizes a plain array of items with new entities.
|
|
84
|
+
* Does not require a container model - works with any array of identifiable items.
|
|
85
|
+
*
|
|
86
|
+
* @template T - Current item type with an id property
|
|
87
|
+
* @template D - New entity type with an id property
|
|
88
|
+
* @param params - Configuration including the items array and callbacks
|
|
89
|
+
* @returns A function that accepts entities and synchronizes the array
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const currentItems = [{ id: '1', name: 'Item 1' }];
|
|
93
|
+
* const syncItems = resolveItemListDeltas({
|
|
94
|
+
* items: currentItems,
|
|
95
|
+
* onAddItem: (item) => currentItems.push(item),
|
|
96
|
+
* onRemoveItem: (id) => {
|
|
97
|
+
* const index = currentItems.findIndex(i => i.id === id);
|
|
98
|
+
* if (index >= 0) currentItems.splice(index, 1);
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* syncItems(newItems);
|
|
102
|
+
*/
|
|
24
103
|
export declare const resolveItemListDeltas: <T extends Identifiable, D extends Identifiable>({ items, onAddItem, onRemoveItem, idMapper, }: ResolveItemsParams<T, D>) => (entities: D[]) => void;
|
|
104
|
+
/**
|
|
105
|
+
* Removes a prefix from an id string if present.
|
|
106
|
+
* Useful for normalizing ids that may have parent or namespace prefixes.
|
|
107
|
+
*
|
|
108
|
+
* @param id - The id string to process
|
|
109
|
+
* @param prefix - The prefix to remove (defaults to "parent-")
|
|
110
|
+
* @returns The id with the prefix removed, or the original id if prefix not found
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* processId("parent-123") // returns "123"
|
|
114
|
+
* processId("parent-abc", "parent-") // returns "abc"
|
|
115
|
+
* processId("child-456", "parent-") // returns "child-456"
|
|
116
|
+
*/
|
|
25
117
|
export declare const processId: (id: string, prefix?: string) => string;
|
|
26
118
|
export {};
|
|
27
119
|
//# sourceMappingURL=container-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container-utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/container-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;CACZ;AAqBD,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/E,KAAK,SAAS,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"container-utils.d.ts","sourceRoot":"","sources":["../../../../../../packages/sdk/kos-ui-sdk/src/core/util/container-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;CACZ;AAqBD;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/E,KAAK,SAAS,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAExE;;;;GAIG;AACH,UAAU,aAAa,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC;IAC5C,mCAAmC;IACnC,SAAS,EAAE,CAAC,CAAC;IACb,4DAA4D;IAC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