@momentum-design/components 0.116.0 → 0.116.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/custom-elements.json +1041 -1041
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/utils/controllers/ElementStore.d.ts +21 -10
- package/dist/utils/controllers/ElementStore.js +9 -0
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
@@ -12,9 +12,9 @@ export { default as Brandvisual } from './brandvisual';
|
|
12
12
|
export { default as Bullet } from './bullet';
|
13
13
|
export { default as Button } from './button';
|
14
14
|
export { default as ButtonGroup } from './buttongroup';
|
15
|
-
export { default as ButtonLink } from './buttonlink';
|
16
15
|
export { default as Buttonsimple } from './buttonsimple';
|
17
16
|
export { default as Card } from './card';
|
17
|
+
export { default as ButtonLink } from './buttonlink';
|
18
18
|
export { default as CardButton } from './cardbutton';
|
19
19
|
export { default as CardCheckbox } from './cardcheckbox';
|
20
20
|
export { default as CardRadio } from './cardradio';
|
package/dist/react/index.js
CHANGED
@@ -12,9 +12,9 @@ export { default as Brandvisual } from './brandvisual';
|
|
12
12
|
export { default as Bullet } from './bullet';
|
13
13
|
export { default as Button } from './button';
|
14
14
|
export { default as ButtonGroup } from './buttongroup';
|
15
|
-
export { default as ButtonLink } from './buttonlink';
|
16
15
|
export { default as Buttonsimple } from './buttonsimple';
|
17
16
|
export { default as Card } from './card';
|
17
|
+
export { default as ButtonLink } from './buttonlink';
|
18
18
|
export { default as CardButton } from './cardbutton';
|
19
19
|
export { default as CardCheckbox } from './cardcheckbox';
|
20
20
|
export { default as CardRadio } from './cardradio';
|
@@ -1,11 +1,27 @@
|
|
1
1
|
import { ReactiveController } from 'lit';
|
2
2
|
import type { Component } from '../../models';
|
3
3
|
export type ElementStoreChangeTypes = 'added' | 'removed';
|
4
|
-
interface ElementStoreOptions {
|
4
|
+
interface ElementStoreOptions<TItem extends HTMLElement = HTMLElement> {
|
5
5
|
/**
|
6
|
-
*
|
6
|
+
* Checks if the item is valid.
|
7
|
+
* Invalid items will not be collected or processed.
|
8
|
+
* This method can be overridden by subclasses to define custom validation logic.
|
9
|
+
*
|
10
|
+
* @param item - The item to validate.
|
11
|
+
* @returns - True if the item is valid, false otherwise.
|
7
12
|
*/
|
8
13
|
isValidItem: (item: any) => boolean;
|
14
|
+
/**
|
15
|
+
* Callback function that is called before the store is updated.
|
16
|
+
*
|
17
|
+
* Not called when the store is reset.
|
18
|
+
*
|
19
|
+
* @param item - The item that is being added or removed.
|
20
|
+
* @param changeType - The type of change ('added' or 'removed').
|
21
|
+
* @param index - Index at which the item is added or removed.
|
22
|
+
* @param store - The current state of the store.
|
23
|
+
*/
|
24
|
+
onStoreUpdate?: (item: TItem, changeType: ElementStoreChangeTypes, index: number, store: TItem[]) => void;
|
9
25
|
}
|
10
26
|
/**
|
11
27
|
* ElementStore is a controller that manages a collection of elements.
|
@@ -35,15 +51,10 @@ interface ElementStoreOptions {
|
|
35
51
|
*/
|
36
52
|
export declare class ElementStore<TItem extends HTMLElement> implements ReactiveController {
|
37
53
|
private host;
|
38
|
-
/**
|
39
|
-
* Checks if the item is valid.
|
40
|
-
* Invalid items will not be collected or processed.
|
41
|
-
* This method can be overridden by subclasses to define custom validation logic.
|
42
|
-
*
|
43
|
-
* @param item - The item to validate.
|
44
|
-
* @returns - True if the item is valid, false otherwise.
|
45
|
-
*/
|
54
|
+
/** Checks if the item is valid. */
|
46
55
|
private readonly isValidItem;
|
56
|
+
/** Callback function that is called before the store is updated. */
|
57
|
+
private readonly onStoreUpdate;
|
47
58
|
/** Stored items */
|
48
59
|
private cache;
|
49
60
|
/** Access to stored items */
|
@@ -97,6 +97,7 @@ export class ElementStore {
|
|
97
97
|
this.host = host;
|
98
98
|
host.addController(this);
|
99
99
|
this.isValidItem = (options === null || options === void 0 ? void 0 : options.isValidItem) || defaultIsValidFn;
|
100
|
+
this.onStoreUpdate = options === null || options === void 0 ? void 0 : options.onStoreUpdate;
|
100
101
|
this.host.addEventListener(LIFE_CYCLE_EVENTS.CREATED, this.itemCreationHandler);
|
101
102
|
this.host.addEventListener(LIFE_CYCLE_EVENTS.DESTROYED, this.itemDestroyHandler);
|
102
103
|
}
|
@@ -136,9 +137,13 @@ export class ElementStore {
|
|
136
137
|
* @param index - The index at which to add the item. If `undefined`, the item is added automatically.
|
137
138
|
*/
|
138
139
|
addItem(item, index = undefined) {
|
140
|
+
var _a;
|
139
141
|
const newItem = item;
|
140
142
|
if (this.isValidItem(newItem) && !this.cache.includes(newItem)) {
|
141
143
|
const idx = index === undefined ? this.cache.findIndex(e => isBefore(newItem, e)) : index;
|
144
|
+
if (this.onStoreUpdate) {
|
145
|
+
(_a = this.onStoreUpdate) === null || _a === void 0 ? void 0 : _a.call(this, newItem, 'added', idx === -1 ? this.cache.length : idx, this.cache.slice());
|
146
|
+
}
|
142
147
|
if (idx === -1) {
|
143
148
|
this.cache.push(newItem);
|
144
149
|
}
|
@@ -153,8 +158,12 @@ export class ElementStore {
|
|
153
158
|
* @param item - The item to remove from the cache.
|
154
159
|
*/
|
155
160
|
delete(item) {
|
161
|
+
var _a;
|
156
162
|
const idx = this.cache.indexOf(item);
|
157
163
|
if (idx !== -1) {
|
164
|
+
if (this.onStoreUpdate) {
|
165
|
+
(_a = this.onStoreUpdate) === null || _a === void 0 ? void 0 : _a.call(this, item, 'removed', idx, this.cache.slice());
|
166
|
+
}
|
158
167
|
this.cache.splice(idx, 1);
|
159
168
|
}
|
160
169
|
}
|