@agnos-ui/core 0.2.0 → 0.3.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/README.md +3 -3
- package/accordion-BaWN0_n-.js +330 -0
- package/accordion-BuIgxZ0S.cjs +329 -0
- package/alert-C4jCg9Pl.cjs +8 -0
- package/alert-Dlf-BV98.js +9 -0
- package/common-DRdsw5m8.js +76 -0
- package/common-nJRMXbwj.cjs +75 -0
- package/components/accordion/accordion.d.ts +38 -49
- package/components/accordion/index.cjs +7 -0
- package/components/accordion/index.js +7 -1
- package/components/alert/alert.d.ts +3 -12
- package/components/alert/common.d.ts +4 -13
- package/components/alert/index.cjs +10 -0
- package/components/alert/index.js +10 -2
- package/components/modal/index.cjs +7 -0
- package/components/modal/index.js +7 -1
- package/components/modal/modal.d.ts +7 -49
- package/components/pagination/index.cjs +5 -0
- package/components/pagination/index.d.ts +0 -1
- package/components/pagination/index.js +5 -2
- package/components/pagination/pagination.d.ts +68 -139
- package/components/progressbar/index.cjs +5 -0
- package/components/progressbar/index.js +5 -1
- package/components/progressbar/progressbar.d.ts +6 -22
- package/components/rating/index.cjs +5 -0
- package/components/rating/index.js +5 -1
- package/components/rating/rating.d.ts +16 -11
- package/components/select/index.cjs +6 -0
- package/components/select/index.js +6 -1
- package/components/select/select.d.ts +15 -33
- package/components/slider/index.cjs +5 -0
- package/components/slider/index.js +5 -1
- package/components/slider/slider.d.ts +29 -35
- package/components/toast/index.cjs +5 -0
- package/components/toast/index.js +5 -1
- package/components/toast/toast.d.ts +11 -8
- package/config.cjs +38 -0
- package/config.d.ts +1 -1
- package/config.js +35 -50
- package/directive-BTSEYLF3.cjs +404 -0
- package/directive-DCYlDznf.js +405 -0
- package/func-DR0n-ShK.js +7 -0
- package/func-Qd3cD9a3.cjs +6 -0
- package/index.cjs +119 -0
- package/index.d.ts +1 -1
- package/index.js +119 -33
- package/modal-BI2qUu1M.js +251 -0
- package/modal-rzMpATf5.cjs +250 -0
- package/package.json +29 -19
- package/pagination--GkwduJn.js +263 -0
- package/pagination-EWSWQT1I.cjs +262 -0
- package/progressbar-DH7DHYMp.cjs +83 -0
- package/progressbar-DuRX7_my.js +84 -0
- package/promise-BMJ8qhA8.cjs +118 -0
- package/promise-CY2U8bTP.js +119 -0
- package/rating-BR5wD7y2.js +173 -0
- package/rating-CmuYUSxy.cjs +172 -0
- package/select-BCs6HQWn.js +358 -0
- package/select-CCIKn8WR.cjs +357 -0
- package/services/extendWidget.cjs +32 -0
- package/services/extendWidget.d.ts +2 -1
- package/services/extendWidget.js +31 -34
- package/services/floatingUI.cjs +131 -0
- package/services/floatingUI.d.ts +30 -14
- package/services/floatingUI.js +128 -102
- package/services/focustrack.cjs +47 -0
- package/services/focustrack.js +45 -44
- package/services/hash.cjs +15 -0
- package/services/hash.js +14 -12
- package/services/intersection.cjs +53 -0
- package/services/intersection.js +48 -50
- package/services/matchMedia.cjs +13 -0
- package/services/matchMedia.d.ts +7 -0
- package/services/matchMedia.js +13 -0
- package/services/navManager.cjs +196 -0
- package/services/navManager.d.ts +9 -9
- package/services/navManager.js +186 -168
- package/services/portal.cjs +43 -0
- package/services/portal.js +41 -42
- package/services/resizeObserver.cjs +32 -0
- package/services/resizeObserver.d.ts +1 -1
- package/services/resizeObserver.js +31 -28
- package/services/siblingsInert.cjs +40 -0
- package/services/siblingsInert.js +31 -31
- package/services/transitions/baseTransitions.cjs +171 -0
- package/services/transitions/baseTransitions.d.ts +16 -16
- package/services/transitions/baseTransitions.js +159 -170
- package/services/transitions/collapse.cjs +44 -0
- package/services/transitions/collapse.js +41 -49
- package/services/transitions/cssTransitions.cjs +32 -0
- package/services/transitions/cssTransitions.d.ts +2 -1
- package/services/transitions/cssTransitions.js +29 -39
- package/services/transitions/simpleClassTransition.cjs +31 -0
- package/services/transitions/simpleClassTransition.js +30 -41
- package/slider-CA_fszn7.js +536 -0
- package/slider-DsLvT87U.cjs +535 -0
- package/toast-8tWp6x89.js +63 -0
- package/toast-Aw8o0Iwe.cjs +62 -0
- package/types.cjs +12 -0
- package/types.d.ts +21 -1
- package/types.js +11 -13
- package/utils/directive.cjs +26 -0
- package/utils/directive.d.ts +148 -5
- package/utils/directive.js +25 -205
- package/utils/internal/dom.d.ts +43 -4
- package/utils/internal/promise.d.ts +2 -2
- package/utils/internal/ssrHTMLElement.d.ts +7 -0
- package/utils/stores.cjs +163 -0
- package/utils/stores.d.ts +9 -17
- package/utils/stores.js +149 -284
- package/utils/writables.cjs +13 -0
- package/utils/writables.js +12 -71
- package/writables-D46sFgGK.cjs +85 -0
- package/writables-DoU_XYTX.js +86 -0
- package/components/accordion/accordion.js +0 -264
- package/components/alert/alert.js +0 -22
- package/components/alert/common.js +0 -69
- package/components/commonProps.js +0 -1
- package/components/modal/modal.js +0 -186
- package/components/pagination/bootstrap.d.ts +0 -8
- package/components/pagination/bootstrap.js +0 -110
- package/components/pagination/pagination.js +0 -195
- package/components/progressbar/progressbar.js +0 -78
- package/components/rating/rating.js +0 -137
- package/components/select/select.js +0 -297
- package/components/slider/slider.js +0 -420
- package/components/toast/toast.js +0 -43
- package/services/transitions/bootstrap/collapse.d.ts +0 -2
- package/services/transitions/bootstrap/collapse.js +0 -15
- package/services/transitions/bootstrap/fade.d.ts +0 -1
- package/services/transitions/bootstrap/fade.js +0 -7
- package/services/transitions/bootstrap.d.ts +0 -2
- package/services/transitions/bootstrap.js +0 -2
- package/utils/internal/checks.js +0 -60
- package/utils/internal/dom.js +0 -82
- package/utils/internal/func.js +0 -11
- package/utils/internal/isFocusable.js +0 -37
- package/utils/internal/math.js +0 -13
- package/utils/internal/promise.js +0 -169
- package/utils/internal/scrollbars.js +0 -33
- package/utils/internal/sort.js +0 -28
- package/utils/internal/textDirection.js +0 -7
- package/utils/internal/traversal.js +0 -105
package/utils/stores.js
CHANGED
|
@@ -1,298 +1,163 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { INVALID_VALUE } from
|
|
3
|
-
import { identity } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* const storeB$ = writable(1);
|
|
14
|
-
* const patch = createPatch({a: storeA$, b: storeB$});
|
|
15
|
-
*
|
|
16
|
-
* patch({a: 2}) // will perform storeA$.set(2)
|
|
17
|
-
* patch({a: 2, b: 2}) // will perform storeA$.set(2) and storeB$.set(2) in the same batch.
|
|
18
|
-
* patch({a: 2, c: 2}) // will perform storeA$.set(2), c is ignored.
|
|
19
|
-
*
|
|
20
|
-
* ```
|
|
21
|
-
* @param stores - object of stores
|
|
22
|
-
* @returns the patch function
|
|
23
|
-
*/
|
|
24
|
-
export function createPatch(stores) {
|
|
25
|
-
return function (storesValues) {
|
|
26
|
-
batch(() => {
|
|
27
|
-
for (const [name, value] of Object.entries(storesValues ?? {})) {
|
|
28
|
-
stores[`${name}$`]?.set(value);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
};
|
|
1
|
+
import { batch, computed, asWritable, readable, writable, asReadable, get, derived, equal } from "@amadeus-it-group/tansu";
|
|
2
|
+
import { INVALID_VALUE } from "../types.js";
|
|
3
|
+
import { i as identity } from "../func-DR0n-ShK.js";
|
|
4
|
+
function createPatch(stores) {
|
|
5
|
+
return function(storesValues) {
|
|
6
|
+
batch(() => {
|
|
7
|
+
var _a;
|
|
8
|
+
for (const [name, value] of Object.entries(storesValues ?? {})) {
|
|
9
|
+
(_a = stores[`${name}$`]) == null ? void 0 : _a.set(value);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
};
|
|
32
13
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (obj1 === obj2) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
let hasUpdate = false;
|
|
49
|
-
const changedValues = {};
|
|
50
|
-
const keys = new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
|
|
51
|
-
for (const key of keys) {
|
|
52
|
-
const value = obj2[key];
|
|
53
|
-
if (obj1[key] !== value) {
|
|
54
|
-
changedValues[key] = value;
|
|
55
|
-
hasUpdate = true;
|
|
56
|
-
}
|
|
14
|
+
function findChangedProperties(obj1, obj2) {
|
|
15
|
+
if (obj1 === obj2) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
let hasUpdate = false;
|
|
19
|
+
const changedValues = {};
|
|
20
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const value = obj2[key];
|
|
23
|
+
if (obj1[key] !== value) {
|
|
24
|
+
changedValues[key] = value;
|
|
25
|
+
hasUpdate = true;
|
|
57
26
|
}
|
|
58
|
-
|
|
27
|
+
}
|
|
28
|
+
return hasUpdate ? changedValues : null;
|
|
59
29
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* @param defValue - Default value used when both the own value and the config$ value are undefined.
|
|
69
|
-
* @param config$ - Store containing the default value used when the own value is undefined
|
|
70
|
-
* @param options - Object which can contain the following optional functions: normalizeValue and equal
|
|
71
|
-
* @param own$ - Store containing the own value
|
|
72
|
-
* @returns a writable store with the extra default value and normalization logic described above
|
|
73
|
-
*/
|
|
74
|
-
export function writableWithDefault(defValue, config$ = readable(undefined), options = {}, own$ = writable(undefined)) {
|
|
75
|
-
const { normalizeValue = identity, equal = Object.is } = options;
|
|
76
|
-
const getDefValue = () => defValue;
|
|
77
|
-
const callNormalizeValue = (value, defValue = getDefValue) => {
|
|
78
|
-
const normalizedValue = value === undefined ? undefined : normalizeValue(value);
|
|
79
|
-
if (normalizedValue === INVALID_VALUE) {
|
|
80
|
-
console.error('Not using invalid value', value);
|
|
81
|
-
return defValue();
|
|
82
|
-
}
|
|
83
|
-
if (normalizedValue === undefined) {
|
|
84
|
-
return defValue();
|
|
85
|
-
}
|
|
86
|
-
return normalizedValue;
|
|
87
|
-
};
|
|
88
|
-
const validatedDefConfig$ = computed(() => callNormalizeValue(config$()), { equal });
|
|
89
|
-
const validatedOwnValue$ = computed(() => callNormalizeValue(own$(), validatedDefConfig$), { equal });
|
|
90
|
-
return asWritable(validatedOwnValue$, (value) => {
|
|
91
|
-
if (value !== undefined) {
|
|
92
|
-
const normalizedValue = normalizeValue(value);
|
|
93
|
-
if (normalizedValue === INVALID_VALUE) {
|
|
94
|
-
console.error('Not setting invalid value', value);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
value = normalizedValue;
|
|
98
|
-
}
|
|
99
|
-
own$.set(value);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Returns true if the provided argument is a store (ReadableSignal).
|
|
104
|
-
* @param x - argument that is tested
|
|
105
|
-
* @returns true if the argument is a store (ReadableSignal)
|
|
106
|
-
*/
|
|
107
|
-
export const isStore = (x) => !!(x && typeof x === 'function' && 'subscribe' in x);
|
|
108
|
-
/**
|
|
109
|
-
* If the provided argument is already a store, it is returned as is, otherwise, a readable store is created with the provided argument as its initial value.
|
|
110
|
-
* @param x - either a store or a simple value
|
|
111
|
-
* @returns either x if x is already a store, or readable(x) otherwise
|
|
112
|
-
*/
|
|
113
|
-
export const toReadableStore = (x) => (isStore(x) ? x : readable(x));
|
|
114
|
-
/**
|
|
115
|
-
* If the provided argument is already a store, it is returned as is, otherwise, a writable store is created with the provided argument as its initial value.
|
|
116
|
-
* @param x - either a writable store or a simple value
|
|
117
|
-
* @returns either x if x is already a store, or writable(x) otherwise
|
|
118
|
-
*/
|
|
119
|
-
export const toWritableStore = (x) => (isStore(x) ? x : writable(x));
|
|
120
|
-
/**
|
|
121
|
-
* Extract and normalize config stores.
|
|
122
|
-
*
|
|
123
|
-
* @param keys - the keys of the stores to extract / normalize
|
|
124
|
-
* @param config - the config stores
|
|
125
|
-
* @returns the normalized config stores
|
|
126
|
-
*/
|
|
127
|
-
export const normalizeConfigStores = (keys, config) => {
|
|
128
|
-
const res = {};
|
|
129
|
-
if (config) {
|
|
130
|
-
const configIsStore = isStore(config);
|
|
131
|
-
for (const key of keys) {
|
|
132
|
-
res[key] = configIsStore
|
|
133
|
-
? computed(() => config()[key])
|
|
134
|
-
: toReadableStore(config[key]);
|
|
135
|
-
}
|
|
30
|
+
function writableWithDefault(defValue, config$ = readable(void 0), options = {}, own$ = writable(void 0)) {
|
|
31
|
+
const { normalizeValue = identity, equal: equal2 = Object.is } = options;
|
|
32
|
+
const getDefValue = () => defValue;
|
|
33
|
+
const callNormalizeValue = (value, defValue2 = getDefValue) => {
|
|
34
|
+
const normalizedValue = value === void 0 ? void 0 : normalizeValue(value);
|
|
35
|
+
if (normalizedValue === INVALID_VALUE) {
|
|
36
|
+
console.error("Not using invalid value", value);
|
|
37
|
+
return defValue2();
|
|
136
38
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Merge two stores configs into one
|
|
141
|
-
*
|
|
142
|
-
* @param keys - the keys of the stores to extract and merge from the two provided configs
|
|
143
|
-
* @param config1 - the first config
|
|
144
|
-
* @param config2 - the second config
|
|
145
|
-
* @returns the merged config
|
|
146
|
-
*/
|
|
147
|
-
export const mergeConfigStores = (keys, config1, config2) => {
|
|
148
|
-
const res = {};
|
|
149
|
-
for (const key of keys) {
|
|
150
|
-
const config1Store = config1?.[key];
|
|
151
|
-
const config2Store = config2?.[key];
|
|
152
|
-
res[key] = config1Store && config2Store ? computed(() => config1Store() ?? config2Store()) : config1Store || config2Store;
|
|
39
|
+
if (normalizedValue === void 0) {
|
|
40
|
+
return defValue2();
|
|
153
41
|
}
|
|
154
|
-
return
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* const defConfig = {propA: 1, propB: 2};
|
|
178
|
-
* const validation = {propA: {normalizeValue: value => +value}};
|
|
179
|
-
* const config = {propA: 5, propB: writable(3)};
|
|
180
|
-
* const {propA$, propB$} = writablesWithDefault(defConfig, {config}, validation);
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
export const writablesWithDefault = (defConfig, propsConfig, options) => {
|
|
184
|
-
const res = {};
|
|
185
|
-
const keys = Object.keys(defConfig);
|
|
186
|
-
const configStores = normalizeConfigStores(keys, propsConfig?.config);
|
|
187
|
-
const props = propsConfig?.props;
|
|
42
|
+
return normalizedValue;
|
|
43
|
+
};
|
|
44
|
+
const validatedDefConfig$ = computed(() => callNormalizeValue(config$()), { equal: equal2 });
|
|
45
|
+
const validatedOwnValue$ = computed(() => callNormalizeValue(own$(), validatedDefConfig$), { equal: equal2 });
|
|
46
|
+
return asWritable(validatedOwnValue$, (value) => {
|
|
47
|
+
if (value !== void 0) {
|
|
48
|
+
const normalizedValue = normalizeValue(value);
|
|
49
|
+
if (normalizedValue === INVALID_VALUE) {
|
|
50
|
+
console.error("Not setting invalid value", value);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
value = normalizedValue;
|
|
54
|
+
}
|
|
55
|
+
own$.set(value);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const isStore = (x) => !!(x && typeof x === "function" && "subscribe" in x);
|
|
59
|
+
const toReadableStore = (x) => isStore(x) ? x : readable(x);
|
|
60
|
+
const toWritableStore = (x) => isStore(x) ? x : writable(x);
|
|
61
|
+
const normalizeConfigStores = (keys, config) => {
|
|
62
|
+
const res = {};
|
|
63
|
+
if (config) {
|
|
64
|
+
const configIsStore = isStore(config);
|
|
188
65
|
for (const key of keys) {
|
|
189
|
-
|
|
190
|
-
res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options?.[key], toWritableStore(propValue));
|
|
66
|
+
res[key] = configIsStore ? computed(() => config()[key]) : toReadableStore(config[key]);
|
|
191
67
|
}
|
|
192
|
-
|
|
68
|
+
}
|
|
69
|
+
return res;
|
|
193
70
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* and the second one containing the patch function (returned by {@link createPatch})
|
|
203
|
-
*
|
|
204
|
-
* @example With a store
|
|
205
|
-
* ```ts
|
|
206
|
-
* const defConfig = {propA: 1};
|
|
207
|
-
* const validation = {propA: {normalizeValue: value => +value}};
|
|
208
|
-
* const config$ = writable({propA: 5});
|
|
209
|
-
* const [{propA$}, patch] = writablesForProps(defConfig, config$, validation);
|
|
210
|
-
* ```
|
|
211
|
-
*
|
|
212
|
-
* @example With an object containing a value and a store
|
|
213
|
-
* ```ts
|
|
214
|
-
* const defConfig = {propA: 1, propB: 2};
|
|
215
|
-
* const validation = {propA: {normalizeValue: value => +value}};
|
|
216
|
-
* const config = {propA: 5, propB: writable(3)};
|
|
217
|
-
* const [{propA$, propB$}, patch] = writablesForProps(defConfig, config, validation);
|
|
218
|
-
* ```
|
|
219
|
-
*/
|
|
220
|
-
export const writablesForProps = (defConfig, propsConfig, options) => {
|
|
221
|
-
const stores = writablesWithDefault(defConfig, propsConfig, options);
|
|
222
|
-
return [stores, createPatch(stores)];
|
|
71
|
+
const mergeConfigStores = (keys, config1, config2) => {
|
|
72
|
+
const res = {};
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
const config1Store = config1 == null ? void 0 : config1[key];
|
|
75
|
+
const config2Store = config2 == null ? void 0 : config2[key];
|
|
76
|
+
res[key] = config1Store && config2Store ? computed(() => config1Store() ?? config2Store()) : config1Store || config2Store;
|
|
77
|
+
}
|
|
78
|
+
return res;
|
|
223
79
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
80
|
+
const writablesWithDefault = (defConfig, propsConfig, options) => {
|
|
81
|
+
const res = {};
|
|
82
|
+
const keys = Object.keys(defConfig);
|
|
83
|
+
const configStores = normalizeConfigStores(keys, propsConfig == null ? void 0 : propsConfig.config);
|
|
84
|
+
const props = propsConfig == null ? void 0 : propsConfig.props;
|
|
85
|
+
for (const key of keys) {
|
|
86
|
+
const propValue = props == null ? void 0 : props[key];
|
|
87
|
+
res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options == null ? void 0 : options[key], toWritableStore(propValue));
|
|
88
|
+
}
|
|
89
|
+
return res;
|
|
90
|
+
};
|
|
91
|
+
const writablesForProps = (defConfig, propsConfig, options) => {
|
|
92
|
+
const stores = writablesWithDefault(defConfig, propsConfig, options);
|
|
93
|
+
return [stores, createPatch(stores)];
|
|
94
|
+
};
|
|
95
|
+
const stateStores = (inputStores) => {
|
|
96
|
+
const storesNames = [];
|
|
97
|
+
const storesArray = [];
|
|
98
|
+
const stores = {};
|
|
99
|
+
for (const [key, store] of Object.entries(inputStores)) {
|
|
100
|
+
if (key.endsWith("$")) {
|
|
101
|
+
storesNames.push(key.substring(0, key.length - 1));
|
|
102
|
+
storesArray.push(store);
|
|
103
|
+
stores[key] = asReadable(store);
|
|
241
104
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
stores,
|
|
108
|
+
state$: computed(() => {
|
|
109
|
+
const values = storesArray.map(get);
|
|
110
|
+
const res = {};
|
|
111
|
+
storesNames.forEach((name, index) => {
|
|
112
|
+
res[name] = values[index];
|
|
113
|
+
});
|
|
114
|
+
return res;
|
|
115
|
+
})
|
|
116
|
+
};
|
|
253
117
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
// with angular and react only when rectifiedValue is true?
|
|
275
|
-
onChange$()(newValue);
|
|
276
|
-
}
|
|
277
|
-
return newValue;
|
|
278
|
-
},
|
|
279
|
-
equal,
|
|
280
|
-
}), stores[0].set.bind(stores[0]));
|
|
118
|
+
const bindableDerived = (onChange$, stores, adjustValue = (arg) => arg[0], equal2 = (currentValue, newValue) => newValue === currentValue) => {
|
|
119
|
+
let currentValue = stores[0]();
|
|
120
|
+
return asWritable(
|
|
121
|
+
derived(stores, {
|
|
122
|
+
derive(values) {
|
|
123
|
+
const newValue = adjustValue(values);
|
|
124
|
+
const rectifiedValue = !equal2(values[0], newValue);
|
|
125
|
+
if (rectifiedValue) {
|
|
126
|
+
stores[0].set(newValue);
|
|
127
|
+
}
|
|
128
|
+
if (rectifiedValue || !equal2(currentValue, newValue)) {
|
|
129
|
+
currentValue = newValue;
|
|
130
|
+
onChange$()(newValue);
|
|
131
|
+
}
|
|
132
|
+
return newValue;
|
|
133
|
+
},
|
|
134
|
+
equal: equal2
|
|
135
|
+
}),
|
|
136
|
+
stores[0].set.bind(stores[0])
|
|
137
|
+
);
|
|
281
138
|
};
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
* @param store$ - store to be bound
|
|
286
|
-
* @param onChange$ - A readable signal containing a callback function to execute when the value changes from the set or update method of the returned writable store.
|
|
287
|
-
* @param adjustValue - A function to adjust the value of the store, called in a reactive context each time the value changes or any called dependency changes.
|
|
288
|
-
* By default, the value of store$ is returned.
|
|
289
|
-
* @param equal - A function to determine if two values are equal.
|
|
290
|
-
* @returns A writable store that contains the adjusted value of the given store, with the set or update functions that trigger the onChange$ callback.
|
|
291
|
-
*/
|
|
292
|
-
export const bindableProp = (store$, onChange$, adjustValue = identity, equal = tansuDefaultEqual) => asWritable(computed(() => adjustValue(store$()), { equal }), (newValue) => {
|
|
139
|
+
const bindableProp = (store$, onChange$, adjustValue = identity, equal$1 = equal) => asWritable(
|
|
140
|
+
computed(() => adjustValue(store$()), { equal: equal$1 }),
|
|
141
|
+
(newValue) => {
|
|
293
142
|
const adjustedValue = adjustValue(newValue);
|
|
294
|
-
if (!equal(store$(), adjustedValue)) {
|
|
295
|
-
|
|
296
|
-
|
|
143
|
+
if (!equal$1(store$(), adjustedValue)) {
|
|
144
|
+
store$.set(adjustedValue);
|
|
145
|
+
onChange$()(adjustedValue);
|
|
297
146
|
}
|
|
298
|
-
}
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
export {
|
|
150
|
+
bindableDerived,
|
|
151
|
+
bindableProp,
|
|
152
|
+
createPatch,
|
|
153
|
+
findChangedProperties,
|
|
154
|
+
isStore,
|
|
155
|
+
mergeConfigStores,
|
|
156
|
+
normalizeConfigStores,
|
|
157
|
+
stateStores,
|
|
158
|
+
toReadableStore,
|
|
159
|
+
toWritableStore,
|
|
160
|
+
writableWithDefault,
|
|
161
|
+
writablesForProps,
|
|
162
|
+
writablesWithDefault
|
|
163
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const utils_writables = require("../writables-D46sFgGK.cjs");
|
|
4
|
+
require("../types.cjs");
|
|
5
|
+
exports.testToNormalizeValue = utils_writables.testToNormalizeValue;
|
|
6
|
+
exports.typeArray = utils_writables.typeArray;
|
|
7
|
+
exports.typeBoolean = utils_writables.typeBoolean;
|
|
8
|
+
exports.typeBooleanOrNull = utils_writables.typeBooleanOrNull;
|
|
9
|
+
exports.typeFunction = utils_writables.typeFunction;
|
|
10
|
+
exports.typeHTMLElementOrNull = utils_writables.typeHTMLElementOrNull;
|
|
11
|
+
exports.typeNumber = utils_writables.typeNumber;
|
|
12
|
+
exports.typeNumberInRangeFactory = utils_writables.typeNumberInRangeFactory;
|
|
13
|
+
exports.typeString = utils_writables.typeString;
|
package/utils/writables.js
CHANGED
|
@@ -1,72 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Factory function for creating a type constraint for numbers within a specified range.
|
|
16
|
-
*
|
|
17
|
-
* @param min - The minimum value.
|
|
18
|
-
* @param max - The maximum value.
|
|
19
|
-
* @param options - Additional options to customize the behavior.
|
|
20
|
-
*
|
|
21
|
-
* @returns A type guard function that returns the clamp value or INVALID_VALUE depending on the provided options.
|
|
22
|
-
*/
|
|
23
|
-
export function typeNumberInRangeFactory(min, max, options = {}) {
|
|
24
|
-
const { strict = false, useClamp = true } = options;
|
|
25
|
-
return {
|
|
26
|
-
normalizeValue: (value) => {
|
|
27
|
-
let normalizedNumber = numberNormalizeFn(value);
|
|
28
|
-
if (normalizedNumber !== INVALID_VALUE) {
|
|
29
|
-
if (!strict && useClamp) {
|
|
30
|
-
normalizedNumber = clamp(normalizedNumber, max, min);
|
|
31
|
-
}
|
|
32
|
-
if (normalizedNumber >= min && normalizedNumber <= max) {
|
|
33
|
-
if (!strict || (normalizedNumber !== min && normalizedNumber !== max)) {
|
|
34
|
-
return normalizedNumber;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return INVALID_VALUE;
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export const typeBoolean = {
|
|
43
|
-
normalizeValue: testToNormalizeValue(isBoolean),
|
|
44
|
-
};
|
|
45
|
-
export const typeBooleanOrNull = {
|
|
46
|
-
normalizeValue: testToNormalizeValue(allowNull(isBoolean)),
|
|
47
|
-
};
|
|
48
|
-
export const typeString = {
|
|
49
|
-
normalizeValue: testToNormalizeValue(isString),
|
|
50
|
-
};
|
|
51
|
-
export const typeFunction = {
|
|
52
|
-
normalizeValue: testToNormalizeValue(isFunction),
|
|
53
|
-
equal: Object.is,
|
|
54
|
-
};
|
|
55
|
-
export const typeHTMLElementOrNull = {
|
|
56
|
-
normalizeValue: testToNormalizeValue(allowNull(isHTMLElement)),
|
|
57
|
-
equal: Object.is,
|
|
58
|
-
};
|
|
59
|
-
export const typeArray = {
|
|
60
|
-
normalizeValue: testToNormalizeValue(isArray),
|
|
61
|
-
equal: (a, b) => {
|
|
62
|
-
if (a === b) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
if (a?.length !== b?.length) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return a.every((val, index) => val === b[index]);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
1
|
+
import { t, h, c, d, f, g, a, b, e } from "../writables-DoU_XYTX.js";
|
|
2
|
+
import "../types.js";
|
|
3
|
+
export {
|
|
4
|
+
t as testToNormalizeValue,
|
|
5
|
+
h as typeArray,
|
|
6
|
+
c as typeBoolean,
|
|
7
|
+
d as typeBooleanOrNull,
|
|
8
|
+
f as typeFunction,
|
|
9
|
+
g as typeHTMLElementOrNull,
|
|
10
|
+
a as typeNumber,
|
|
11
|
+
b as typeNumberInRangeFactory,
|
|
12
|
+
e as typeString
|
|
72
13
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const types = require("./types.cjs");
|
|
3
|
+
function isNumber(value) {
|
|
4
|
+
return typeof value === "number" && !isNaN(value) && Number.isFinite(value);
|
|
5
|
+
}
|
|
6
|
+
function isBoolean(value) {
|
|
7
|
+
return value === true || value === false;
|
|
8
|
+
}
|
|
9
|
+
function isFunction(value) {
|
|
10
|
+
return typeof value === "function";
|
|
11
|
+
}
|
|
12
|
+
function isString(value) {
|
|
13
|
+
return typeof value === "string";
|
|
14
|
+
}
|
|
15
|
+
const isArray = Array.isArray;
|
|
16
|
+
function clamp(value, max, min = 0) {
|
|
17
|
+
return Math.max(Math.min(value, max), min);
|
|
18
|
+
}
|
|
19
|
+
const isHTMLElement = (value) => value instanceof HTMLElement;
|
|
20
|
+
const allowNull = (isType) => (value) => value === null || isType(value);
|
|
21
|
+
const testToNormalizeValue = (filter) => (value) => filter(value) ? value : types.INVALID_VALUE;
|
|
22
|
+
const numberNormalizeFn = testToNormalizeValue(isNumber);
|
|
23
|
+
const typeNumber = {
|
|
24
|
+
normalizeValue: numberNormalizeFn
|
|
25
|
+
};
|
|
26
|
+
function typeNumberInRangeFactory(min, max, options = {}) {
|
|
27
|
+
const { strict = false, useClamp = true } = options;
|
|
28
|
+
return {
|
|
29
|
+
normalizeValue: (value) => {
|
|
30
|
+
let normalizedNumber = numberNormalizeFn(value);
|
|
31
|
+
if (normalizedNumber !== types.INVALID_VALUE) {
|
|
32
|
+
if (!strict && useClamp) {
|
|
33
|
+
normalizedNumber = clamp(normalizedNumber, max, min);
|
|
34
|
+
}
|
|
35
|
+
if (normalizedNumber >= min && normalizedNumber <= max) {
|
|
36
|
+
if (!strict || normalizedNumber !== min && normalizedNumber !== max) {
|
|
37
|
+
return normalizedNumber;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return types.INVALID_VALUE;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const typeBoolean = {
|
|
46
|
+
normalizeValue: testToNormalizeValue(isBoolean)
|
|
47
|
+
};
|
|
48
|
+
const typeBooleanOrNull = {
|
|
49
|
+
normalizeValue: testToNormalizeValue(allowNull(isBoolean))
|
|
50
|
+
};
|
|
51
|
+
const typeString = {
|
|
52
|
+
normalizeValue: testToNormalizeValue(isString)
|
|
53
|
+
};
|
|
54
|
+
const typeFunction = {
|
|
55
|
+
normalizeValue: testToNormalizeValue(isFunction),
|
|
56
|
+
equal: Object.is
|
|
57
|
+
};
|
|
58
|
+
const typeHTMLElementOrNull = {
|
|
59
|
+
normalizeValue: testToNormalizeValue(allowNull(isHTMLElement)),
|
|
60
|
+
equal: Object.is
|
|
61
|
+
};
|
|
62
|
+
const typeArray = {
|
|
63
|
+
normalizeValue: testToNormalizeValue(isArray),
|
|
64
|
+
equal: (a, b) => {
|
|
65
|
+
if (a === b) {
|
|
66
|
+
return true;
|
|
67
|
+
} else {
|
|
68
|
+
if ((a == null ? void 0 : a.length) !== (b == null ? void 0 : b.length)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return a.every((val, index) => val === b[index]);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.clamp = clamp;
|
|
76
|
+
exports.isNumber = isNumber;
|
|
77
|
+
exports.testToNormalizeValue = testToNormalizeValue;
|
|
78
|
+
exports.typeArray = typeArray;
|
|
79
|
+
exports.typeBoolean = typeBoolean;
|
|
80
|
+
exports.typeBooleanOrNull = typeBooleanOrNull;
|
|
81
|
+
exports.typeFunction = typeFunction;
|
|
82
|
+
exports.typeHTMLElementOrNull = typeHTMLElementOrNull;
|
|
83
|
+
exports.typeNumber = typeNumber;
|
|
84
|
+
exports.typeNumberInRangeFactory = typeNumberInRangeFactory;
|
|
85
|
+
exports.typeString = typeString;
|