yummies 7.11.0 → 7.12.0
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/async.cjs +162 -48
- package/async.cjs.map +1 -1
- package/async.d.ts +108 -7
- package/async.js +163 -54
- package/async.js.map +1 -1
- package/chunk-CVq3Gv4J.cjs +50 -0
- package/chunk-YKewjYmz.js +37 -0
- package/common.cjs +48 -8
- package/common.cjs.map +1 -1
- package/common.d.ts +35 -2
- package/common.js +49 -11
- package/common.js.map +1 -1
- package/complex.cjs +275 -128
- package/complex.cjs.map +1 -1
- package/complex.js +275 -133
- package/complex.js.map +1 -1
- package/cookie.cjs +17 -7
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +8 -0
- package/cookie.js +18 -9
- package/cookie.js.map +1 -1
- package/css.cjs +147 -39
- package/css.cjs.map +1 -1
- package/css.d.ts +98 -6
- package/css.js +143 -41
- package/css.js.map +1 -1
- package/data.cjs +90 -55
- package/data.cjs.map +1 -1
- package/data.d.ts +32 -0
- package/data.js +91 -61
- package/data.js.map +1 -1
- package/date-time.cjs +578 -412
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +88 -0
- package/date-time.js +575 -421
- package/date-time.js.map +1 -1
- package/device.cjs +48 -23
- package/device.cjs.map +1 -1
- package/device.d.ts +32 -0
- package/device.js +49 -31
- package/device.js.map +1 -1
- package/encodings.cjs +275 -266
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +8 -0
- package/encodings.js +276 -268
- package/encodings.js.map +1 -1
- package/errors.cjs +20 -18
- package/errors.cjs.map +1 -1
- package/errors.js +19 -19
- package/errors.js.map +1 -1
- package/file.cjs +42 -24
- package/file.cjs.map +1 -1
- package/file.d.ts +16 -0
- package/file.js +43 -27
- package/file.js.map +1 -1
- package/format.cjs +125 -83
- package/format.cjs.map +1 -1
- package/format.js +118 -82
- package/format.js.map +1 -1
- package/html.cjs +226 -137
- package/html.cjs.map +1 -1
- package/html.d.ts +64 -0
- package/html.js +223 -150
- package/html.js.map +1 -1
- package/id.cjs +74 -17
- package/id.cjs.map +1 -1
- package/id.js +73 -24
- package/id.js.map +1 -1
- package/imports.cjs +41 -29
- package/imports.cjs.map +1 -1
- package/imports.d.ts +8 -0
- package/imports.js +40 -31
- package/imports.js.map +1 -1
- package/math.cjs +32 -6
- package/math.cjs.map +1 -1
- package/math.d.ts +16 -0
- package/math.js +33 -10
- package/math.js.map +1 -1
- package/media.cjs +275 -84
- package/media.cjs.map +1 -1
- package/media.d.ts +188 -2
- package/media.js +274 -93
- package/media.js.map +1 -1
- package/mobx.cjs +353 -193
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +7 -0
- package/mobx.js +351 -200
- package/mobx.js.map +1 -1
- package/ms.cjs +21 -10
- package/ms.cjs.map +1 -1
- package/ms.js +22 -13
- package/ms.js.map +1 -1
- package/number.cjs +13 -7
- package/number.cjs.map +1 -1
- package/number.js +14 -9
- package/number.js.map +1 -1
- package/package.json +10 -2
- package/parser.cjs +117 -64
- package/parser.cjs.map +1 -1
- package/parser.js +111 -64
- package/parser.js.map +1 -1
- package/price.cjs +24 -18
- package/price.cjs.map +1 -1
- package/price.d.ts +8 -0
- package/price.js +25 -20
- package/price.js.map +1 -1
- package/random.cjs +79 -13
- package/random.cjs.map +1 -1
- package/random.d.ts +64 -0
- package/random.js +80 -22
- package/random.js.map +1 -1
- package/react.cjs +673 -214
- package/react.cjs.map +1 -1
- package/react.d.ts +21 -0
- package/react.js +674 -239
- package/react.js.map +1 -1
- package/sound.cjs +14 -9
- package/sound.cjs.map +1 -1
- package/sound.js +15 -11
- package/sound.js.map +1 -1
- package/storage.cjs +49 -50
- package/storage.cjs.map +1 -1
- package/storage.d.ts +8 -0
- package/storage.js +50 -53
- package/storage.js.map +1 -1
- package/text.cjs +51 -34
- package/text.cjs.map +1 -1
- package/text.js +52 -37
- package/text.js.map +1 -1
- package/type-guard.cjs +292 -72
- package/type-guard.cjs.map +1 -1
- package/type-guard.js +288 -73
- package/type-guard.js.map +1 -1
- package/types.cjs +0 -2
- package/types.global.cjs +0 -2
- package/types.global.js +0 -2
- package/types.js +0 -2
- package/vibrate.cjs +31 -6
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +23 -1
- package/vibrate.js +32 -8
- package/vibrate.js.map +1 -1
- package/types.cjs.map +0 -1
- package/types.global.cjs.map +0 -1
- package/types.global.js.map +0 -1
- package/types.js.map +0 -1
package/mobx.cjs
CHANGED
|
@@ -1,202 +1,361 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
require("./chunk-CVq3Gv4J.cjs");
|
|
3
|
+
let yummies_type_guard = require("yummies/type-guard");
|
|
4
|
+
let mobx = require("mobx");
|
|
5
|
+
//#region src/mobx/apply-observable.ts
|
|
6
|
+
/**
|
|
7
|
+
* Applies a compact list of MobX annotations to an object using either
|
|
8
|
+
* decorator-style invocation or the annotation map form accepted by `makeObservable`.
|
|
9
|
+
*
|
|
10
|
+
* @template T Target object type.
|
|
11
|
+
* @param context Object that should become observable.
|
|
12
|
+
* @param annotationsArray Tuples of annotation followed by annotated field names.
|
|
13
|
+
* @param useDecorators Enables decorator-style application before calling `makeObservable`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* applyObservable(store, [[observable, 'items'], [action, 'setItems']]);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* applyObservable(viewModel, [[computed, 'fullName']], true);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var applyObservable = (context, annotationsArray, useDecorators) => {
|
|
26
|
+
if (useDecorators) {
|
|
27
|
+
annotationsArray.forEach(([annotation, ...fields]) => {
|
|
28
|
+
fields.forEach((field) => {
|
|
29
|
+
annotation(context, field);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
(0, mobx.makeObservable)(context);
|
|
33
|
+
} else {
|
|
34
|
+
const annotationsObject = {};
|
|
35
|
+
annotationsArray.forEach(([annotation, ...fields]) => {
|
|
36
|
+
fields.forEach((field) => {
|
|
37
|
+
annotationsObject[field] = annotation;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
(0, mobx.makeObservable)(context, annotationsObject);
|
|
41
|
+
}
|
|
22
42
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/mobx/create-enhanced-atom.ts
|
|
45
|
+
/**
|
|
46
|
+
* Creates a MobX atom extended with metadata and bound reporting methods.
|
|
47
|
+
*
|
|
48
|
+
* @template TMeta Metadata object stored on the atom.
|
|
49
|
+
* @param name Atom name used by MobX for debugging.
|
|
50
|
+
* @param onBecomeObservedHandler Callback fired when the atom becomes observed.
|
|
51
|
+
* @param onBecomeUnobservedHandler Callback fired when the atom is no longer observed.
|
|
52
|
+
* @param meta Optional metadata attached to the atom.
|
|
53
|
+
* @returns Atom instance with `meta`, `reportChanged` and `reportObserved`.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const atom = createEnhancedAtom('user-status');
|
|
58
|
+
* atom.reportChanged();
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const atom = createEnhancedAtom('cache', undefined, undefined, { scope: 'users' });
|
|
64
|
+
* atom.meta.scope;
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
var createEnhancedAtom = (name, onBecomeObservedHandler, onBecomeUnobservedHandler, meta) => {
|
|
68
|
+
const atom = (0, mobx.createAtom)(name, onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)), onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)));
|
|
69
|
+
atom.meta = meta ?? {};
|
|
70
|
+
atom.reportChanged = atom.reportChanged.bind(atom);
|
|
71
|
+
atom.reportObserved = atom.reportObserved.bind(atom);
|
|
72
|
+
return atom;
|
|
33
73
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/mobx/create-ref.ts
|
|
76
|
+
/**
|
|
77
|
+
* Creates a MobX-aware ref that behaves like a callback ref and exposes
|
|
78
|
+
* observable `current` and `meta` fields.
|
|
79
|
+
*
|
|
80
|
+
* @template T Referenced value type.
|
|
81
|
+
* @template TMeta Additional observable metadata stored on the ref.
|
|
82
|
+
* @param cfg Optional callbacks, initial value and comparer configuration.
|
|
83
|
+
* @returns Observable ref function object.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const inputRef = createRef<HTMLInputElement>();
|
|
88
|
+
* inputRef.set(document.createElement('input'));
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const ref = createRef<number>();
|
|
94
|
+
* ref(3);
|
|
95
|
+
* ref.current; // 3
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const nodeRef = createRef({
|
|
101
|
+
* onUnset: () => console.log('detached'),
|
|
102
|
+
* meta: { mounted: false },
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
var createRef = (cfg) => {
|
|
107
|
+
let lastValue;
|
|
108
|
+
const comparer = cfg?.comparer ?? mobx.comparer.default;
|
|
109
|
+
const setValue = (value) => {
|
|
110
|
+
const nextValue = value ?? null;
|
|
111
|
+
if (comparer(ref.current, nextValue)) return;
|
|
112
|
+
(0, mobx.runInAction)(() => {
|
|
113
|
+
const prevLastValue = lastValue;
|
|
114
|
+
lastValue = ref.current ?? void 0;
|
|
115
|
+
ref.current = nextValue;
|
|
116
|
+
let isNextValueIgnored = false;
|
|
117
|
+
ref.listeners.forEach((listener) => {
|
|
118
|
+
if (listener(ref.current, lastValue) === false) isNextValueIgnored = true;
|
|
119
|
+
});
|
|
120
|
+
if (isNextValueIgnored) {
|
|
121
|
+
lastValue = prevLastValue;
|
|
122
|
+
ref.current = lastValue ?? null;
|
|
123
|
+
} else if (ref.current === null && lastValue !== void 0) lastValue = void 0;
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
const ref = setValue;
|
|
127
|
+
ref.set = setValue;
|
|
128
|
+
ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);
|
|
129
|
+
if (cfg?.onSet || cfg?.onUnset) ref.listeners.add((value, prevValue) => {
|
|
130
|
+
if (value) cfg.onSet?.(value, prevValue);
|
|
131
|
+
else cfg.onUnset?.(prevValue);
|
|
132
|
+
});
|
|
133
|
+
ref.current = cfg?.initial ?? null;
|
|
134
|
+
ref.meta = cfg?.meta ?? {};
|
|
135
|
+
(0, mobx.makeObservable)(ref, {
|
|
136
|
+
current: mobx.observable.ref,
|
|
137
|
+
meta: mobx.observable
|
|
138
|
+
});
|
|
139
|
+
return ref;
|
|
80
140
|
};
|
|
81
|
-
|
|
82
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Checks whether the provided value is a ref created by `createRef`.
|
|
143
|
+
*
|
|
144
|
+
* @template T Referenced value type.
|
|
145
|
+
* @template TMeta Ref metadata type.
|
|
146
|
+
* @param value Value to inspect.
|
|
147
|
+
* @returns `true` when the value is a ref-like function with `current`.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const ref = createRef<number>();
|
|
152
|
+
* isRef(ref); // true
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* isRef({ current: 1 }); // false
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
var isRef = (value) => {
|
|
161
|
+
return typeof value === "function" && "current" in value;
|
|
83
162
|
};
|
|
84
|
-
|
|
85
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Normalizes a plain value or an existing ref into a `Ref` instance.
|
|
165
|
+
*
|
|
166
|
+
* @template T Referenced value type.
|
|
167
|
+
* @template TMeta Ref metadata type.
|
|
168
|
+
* @param value Existing ref or initial plain value.
|
|
169
|
+
* @param cfg Optional ref configuration applied when a new ref is created.
|
|
170
|
+
* @returns Existing ref or a newly created ref initialized with `value`.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const ref = toRef(document.body);
|
|
175
|
+
* ref.current === document.body;
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const existingRef = createRef<number>();
|
|
181
|
+
* const sameRef = toRef(existingRef);
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
var toRef = (value, cfg) => {
|
|
185
|
+
return isRef(value) ? value : createRef({
|
|
186
|
+
initial: value,
|
|
187
|
+
...cfg
|
|
188
|
+
});
|
|
86
189
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const observingProps = /* @__PURE__ */ new Set();
|
|
150
|
-
const properties = Array.isArray(property) ? property : [property];
|
|
151
|
-
const cleanup = () => {
|
|
152
|
-
observingProps.clear();
|
|
153
|
-
if (endDelay === false) {
|
|
154
|
-
onEnd?.(metaData, cleanup);
|
|
155
|
-
metaData = void 0;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (timeoutId) {
|
|
159
|
-
clearTimeout(timeoutId);
|
|
160
|
-
timeoutId = void 0;
|
|
161
|
-
}
|
|
162
|
-
timeoutId = setTimeout(() => {
|
|
163
|
-
onEnd?.(metaData, cleanup);
|
|
164
|
-
timeoutId = void 0;
|
|
165
|
-
metaData = void 0;
|
|
166
|
-
}, endDelay);
|
|
167
|
-
};
|
|
168
|
-
const start = (property2) => {
|
|
169
|
-
const isAlreadyObserving = observingProps.size > 0;
|
|
170
|
-
observingProps.add(property2);
|
|
171
|
-
if (isAlreadyObserving) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (timeoutId) {
|
|
175
|
-
clearTimeout(timeoutId);
|
|
176
|
-
timeoutId = void 0;
|
|
177
|
-
}
|
|
178
|
-
metaData = onStart?.();
|
|
179
|
-
};
|
|
180
|
-
const stop = (property2) => {
|
|
181
|
-
const isAlreadyNotObserving = !observingProps.size;
|
|
182
|
-
observingProps.delete(property2);
|
|
183
|
-
const isObserving = observingProps.size > 0;
|
|
184
|
-
if (isAlreadyNotObserving || isObserving) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
cleanup();
|
|
188
|
-
};
|
|
189
|
-
properties.forEach((property2) => {
|
|
190
|
-
if (context) {
|
|
191
|
-
mobx.onBecomeObserved(context, property2, () => start(property2));
|
|
192
|
-
mobx.onBecomeUnobserved(context, property2, () => stop(property2));
|
|
193
|
-
} else {
|
|
194
|
-
mobx.onBecomeObserved(property2, () => start(property2));
|
|
195
|
-
mobx.onBecomeUnobserved(property2, () => stop(property2));
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
return cleanup;
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/mobx/deep-observable-struct.ts
|
|
192
|
+
/**
|
|
193
|
+
* Wraps a plain object into a deeply observable structure and allows
|
|
194
|
+
* patch-like updates while preserving nested observable references where possible.
|
|
195
|
+
*
|
|
196
|
+
* @template TData Observable object shape.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```ts
|
|
200
|
+
* const state = new DeepObservableStruct({ user: { name: 'Ann' } });
|
|
201
|
+
* state.set({ user: { name: 'Bob' } });
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* const state = new DeepObservableStruct({ filters: { active: true } });
|
|
207
|
+
* state.set({ filters: { active: false, archived: true } });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
var DeepObservableStruct = class {
|
|
211
|
+
data;
|
|
212
|
+
constructor(data) {
|
|
213
|
+
this.data = data;
|
|
214
|
+
(0, mobx.makeObservable)(this, {
|
|
215
|
+
data: mobx.observable.deep,
|
|
216
|
+
set: mobx.action
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
set(newData) {
|
|
220
|
+
const stack = Object.keys(this.data).map((key) => [
|
|
221
|
+
key,
|
|
222
|
+
this.data,
|
|
223
|
+
newData
|
|
224
|
+
]);
|
|
225
|
+
let currentIndex = 0;
|
|
226
|
+
let stackLength = stack.length;
|
|
227
|
+
while (currentIndex < stackLength) {
|
|
228
|
+
const [key, currObservableData, newData] = stack[currentIndex];
|
|
229
|
+
const newValue = newData[key];
|
|
230
|
+
const currValue = currObservableData[key];
|
|
231
|
+
currentIndex++;
|
|
232
|
+
if (key in newData) {
|
|
233
|
+
if (yummies_type_guard.typeGuard.isObject(newValue) && yummies_type_guard.typeGuard.isObject(currValue)) {
|
|
234
|
+
const newValueKeys = Object.keys(newValue);
|
|
235
|
+
Object.keys(currValue).forEach((childKey) => {
|
|
236
|
+
if (!(childKey in newValue)) delete currObservableData[key][childKey];
|
|
237
|
+
});
|
|
238
|
+
newValueKeys.forEach((childKey) => {
|
|
239
|
+
stackLength = stack.push([
|
|
240
|
+
childKey,
|
|
241
|
+
currObservableData[key],
|
|
242
|
+
newValue
|
|
243
|
+
]);
|
|
244
|
+
});
|
|
245
|
+
} else if (newValue !== currValue) currObservableData[key] = newValue;
|
|
246
|
+
} else delete currObservableData[key];
|
|
247
|
+
}
|
|
248
|
+
Object.keys(newData).forEach((newDataKey) => {
|
|
249
|
+
if (!this.data[newDataKey]) this.data[newDataKey] = newData[newDataKey];
|
|
250
|
+
});
|
|
251
|
+
}
|
|
199
252
|
};
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/mobx/get-mobx-administration.ts
|
|
255
|
+
/**
|
|
256
|
+
* Returns the internal MobX administration object associated with an observable target.
|
|
257
|
+
*
|
|
258
|
+
* @param context Observable object instance.
|
|
259
|
+
* @returns MobX administration internals stored under `$mobx`.
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* const admin = getMobxAdministration(store);
|
|
264
|
+
* admin.name_;
|
|
265
|
+
* ```
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* const values = getMobxAdministration(formState).values_;
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
var getMobxAdministration = (context) => context[mobx.$mobx];
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region src/mobx/lazy-observe.ts
|
|
275
|
+
/**
|
|
276
|
+
* Starts side effects only while one or more MobX observables are being observed.
|
|
277
|
+
*
|
|
278
|
+
* When the first property becomes observed, `onStart` is called. When all tracked
|
|
279
|
+
* properties become unobserved, `onEnd` is called with the value returned by
|
|
280
|
+
* `onStart`. Cleanup can be delayed via `endDelay`.
|
|
281
|
+
*
|
|
282
|
+
* It uses MobX `onBecomeObserved` and `onBecomeUnobserved` hooks to perform
|
|
283
|
+
* lazy subscription management.
|
|
284
|
+
*
|
|
285
|
+
* @template TMetaData Data returned from `onStart` and forwarded to `onEnd`.
|
|
286
|
+
* @param config Configuration for tracked properties and lifecycle callbacks.
|
|
287
|
+
* @returns Cleanup function that clears the tracked state and runs `onEnd`.
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const stop = lazyObserve({
|
|
292
|
+
* context: store,
|
|
293
|
+
* property: 'items',
|
|
294
|
+
* onStart: () => api.subscribe(),
|
|
295
|
+
* onEnd: (subscription) => subscription.unsubscribe(),
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* lazyObserve({
|
|
302
|
+
* property: [boxA, boxB],
|
|
303
|
+
* onStart: () => console.log('observed'),
|
|
304
|
+
* endDelay: 300,
|
|
305
|
+
* });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
var lazyObserve = ({ context, property, onStart, onEnd, endDelay = false }) => {
|
|
309
|
+
let timeoutId;
|
|
310
|
+
let metaData;
|
|
311
|
+
const observingProps = /* @__PURE__ */ new Set();
|
|
312
|
+
const properties = Array.isArray(property) ? property : [property];
|
|
313
|
+
const cleanup = () => {
|
|
314
|
+
observingProps.clear();
|
|
315
|
+
if (endDelay === false) {
|
|
316
|
+
onEnd?.(metaData, cleanup);
|
|
317
|
+
metaData = void 0;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (timeoutId) {
|
|
321
|
+
clearTimeout(timeoutId);
|
|
322
|
+
timeoutId = void 0;
|
|
323
|
+
}
|
|
324
|
+
timeoutId = setTimeout(() => {
|
|
325
|
+
onEnd?.(metaData, cleanup);
|
|
326
|
+
timeoutId = void 0;
|
|
327
|
+
metaData = void 0;
|
|
328
|
+
}, endDelay);
|
|
329
|
+
};
|
|
330
|
+
const start = (property) => {
|
|
331
|
+
const isAlreadyObserving = observingProps.size > 0;
|
|
332
|
+
observingProps.add(property);
|
|
333
|
+
if (isAlreadyObserving) return;
|
|
334
|
+
if (timeoutId) {
|
|
335
|
+
clearTimeout(timeoutId);
|
|
336
|
+
timeoutId = void 0;
|
|
337
|
+
}
|
|
338
|
+
metaData = onStart?.();
|
|
339
|
+
};
|
|
340
|
+
const stop = (property) => {
|
|
341
|
+
const isAlreadyNotObserving = !observingProps.size;
|
|
342
|
+
observingProps.delete(property);
|
|
343
|
+
const isObserving = observingProps.size > 0;
|
|
344
|
+
if (isAlreadyNotObserving || isObserving) return;
|
|
345
|
+
cleanup();
|
|
346
|
+
};
|
|
347
|
+
properties.forEach((property) => {
|
|
348
|
+
if (context) {
|
|
349
|
+
(0, mobx.onBecomeObserved)(context, property, () => start(property));
|
|
350
|
+
(0, mobx.onBecomeUnobserved)(context, property, () => stop(property));
|
|
351
|
+
} else {
|
|
352
|
+
(0, mobx.onBecomeObserved)(property, () => start(property));
|
|
353
|
+
(0, mobx.onBecomeUnobserved)(property, () => stop(property));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
return cleanup;
|
|
357
|
+
};
|
|
358
|
+
//#endregion
|
|
200
359
|
exports.DeepObservableStruct = DeepObservableStruct;
|
|
201
360
|
exports.applyObservable = applyObservable;
|
|
202
361
|
exports.createEnhancedAtom = createEnhancedAtom;
|
|
@@ -205,4 +364,5 @@ exports.getMobxAdministration = getMobxAdministration;
|
|
|
205
364
|
exports.isRef = isRef;
|
|
206
365
|
exports.lazyObserve = lazyObserve;
|
|
207
366
|
exports.toRef = toRef;
|
|
208
|
-
|
|
367
|
+
|
|
368
|
+
//# sourceMappingURL=mobx.cjs.map
|
package/mobx.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobx.cjs","sources":["../src/mobx/apply-observable.ts","../src/mobx/create-enhanced-atom.ts","../src/mobx/create-ref.ts","../src/mobx/deep-observable-struct.ts","../src/mobx/get-mobx-administration.ts","../src/mobx/lazy-observe.ts"],"sourcesContent":["import { type AnnotationMapEntry, makeObservable } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport type ObservableAnnotationsArray<T extends AnyObject = AnyObject> = [\n AnnotationMapEntry,\n ...(keyof T | (string & {}))[],\n][];\n\n/**\n * Applies a compact list of MobX annotations to an object using either\n * decorator-style invocation or the annotation map form accepted by `makeObservable`.\n *\n * @template T Target object type.\n * @param context Object that should become observable.\n * @param annotationsArray Tuples of annotation followed by annotated field names.\n * @param useDecorators Enables decorator-style application before calling `makeObservable`.\n *\n * @example\n * ```ts\n * applyObservable(store, [[observable, 'items'], [action, 'setItems']]);\n * ```\n *\n * @example\n * ```ts\n * applyObservable(viewModel, [[computed, 'fullName']], true);\n * ```\n */\nexport const applyObservable = <T extends AnyObject>(\n context: T,\n annotationsArray: ObservableAnnotationsArray<T>,\n useDecorators?: boolean,\n) => {\n if (useDecorators) {\n annotationsArray.forEach(([annotation, ...fields]) => {\n fields.forEach((field) => {\n // @ts-expect-error\n annotation(context, field);\n });\n });\n\n makeObservable(context);\n } else {\n const annotationsObject: AnyObject = {};\n\n annotationsArray.forEach(([annotation, ...fields]) => {\n fields.forEach((field) => {\n annotationsObject[field] = annotation;\n });\n });\n\n makeObservable(context, annotationsObject);\n }\n};\n","import { createAtom, type IAtom } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>\n extends IAtom {\n meta: TMeta;\n}\n\n/**\n * Creates a MobX atom extended with metadata and bound reporting methods.\n *\n * @template TMeta Metadata object stored on the atom.\n * @param name Atom name used by MobX for debugging.\n * @param onBecomeObservedHandler Callback fired when the atom becomes observed.\n * @param onBecomeUnobservedHandler Callback fired when the atom is no longer observed.\n * @param meta Optional metadata attached to the atom.\n * @returns Atom instance with `meta`, `reportChanged` and `reportObserved`.\n *\n * @example\n * ```ts\n * const atom = createEnhancedAtom('user-status');\n * atom.reportChanged();\n * ```\n *\n * @example\n * ```ts\n * const atom = createEnhancedAtom('cache', undefined, undefined, { scope: 'users' });\n * atom.meta.scope;\n * ```\n */\nexport const createEnhancedAtom = <TMeta extends AnyObject>(\n name: string,\n onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n meta?: TMeta,\n): IEnhancedAtom<TMeta> => {\n const atom = createAtom(\n name,\n onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),\n onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)),\n ) as IEnhancedAtom<TMeta>;\n atom.meta = meta ?? ({} as TMeta);\n atom.reportChanged = atom.reportChanged.bind(atom);\n atom.reportObserved = atom.reportObserved.bind(atom);\n return atom;\n};\n","import {\n type IEqualsComparer,\n makeObservable,\n comparer as mobxComparer,\n observable,\n runInAction,\n} from 'mobx';\nimport type { AnyObject, Maybe } from 'yummies/types';\n\n/**\n * You can return `false` if you don't want to change the value in this ref\n */\nexport type RefChangeListener<T> = (\n value: T | null,\n prevValue: T | undefined,\n) => void | false;\n\n/**\n * Alternative to React.createRef but works in MobX world.\n * Typically it the should be the same React.LegacyRef (fn style)\n */\nexport interface Ref<T = any, TMeta = AnyObject> {\n /**\n * Setter function\n */\n (value: Maybe<T>): void;\n\n set(value: Maybe<T>): void;\n listeners: Set<RefChangeListener<NoInfer<T>>>;\n current: NoInfer<T> | null;\n meta: TMeta;\n}\n\nexport interface CreateRefConfig<T = any, TMeta = AnyObject> {\n onSet?: (node: T, prevValue: T | undefined) => void;\n onUnset?: (lastValue: T | undefined) => void;\n onChange?: RefChangeListener<T>;\n meta?: TMeta;\n initial?: Maybe<T>;\n comparer?: IEqualsComparer<T | null>;\n}\n\n/**\n * Creates a MobX-aware ref that behaves like a callback ref and exposes\n * observable `current` and `meta` fields.\n *\n * @template T Referenced value type.\n * @template TMeta Additional observable metadata stored on the ref.\n * @param cfg Optional callbacks, initial value and comparer configuration.\n * @returns Observable ref function object.\n *\n * @example\n * ```ts\n * const inputRef = createRef<HTMLInputElement>();\n * inputRef.set(document.createElement('input'));\n * ```\n *\n * @example\n * ```ts\n * const nodeRef = createRef({\n * onUnset: () => console.log('detached'),\n * meta: { mounted: false },\n * });\n * ```\n */\nexport const createRef = <T = any, TMeta = AnyObject>(\n cfg?: CreateRefConfig<T, TMeta>,\n): Ref<T, TMeta> => {\n let lastValue: T | undefined;\n const comparer = cfg?.comparer ?? mobxComparer.default;\n\n const setValue: Ref<T, TMeta>['set'] = (value) => {\n const nextValue = value ?? null;\n\n if (comparer(ref.current, nextValue)) {\n return;\n }\n\n runInAction(() => {\n const prevLastValue = lastValue;\n lastValue = ref.current ?? undefined;\n ref.current = nextValue;\n\n let isNextValueIgnored = false;\n\n ref.listeners.forEach((listener) => {\n const listenerResult = listener(ref.current, lastValue);\n\n if (listenerResult === false) {\n isNextValueIgnored = true;\n }\n });\n\n if (isNextValueIgnored) {\n lastValue = prevLastValue;\n ref.current = lastValue ?? null;\n } else if (ref.current === null && lastValue !== undefined) {\n lastValue = undefined;\n }\n });\n };\n\n const ref = setValue as Ref<T, TMeta>;\n\n ref.set = setValue;\n\n ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);\n\n if (cfg?.onSet || cfg?.onUnset) {\n ref.listeners.add((value, prevValue) => {\n if (value) {\n cfg.onSet?.(value, prevValue);\n } else {\n cfg.onUnset?.(prevValue);\n }\n });\n }\n\n ref.current = cfg?.initial ?? null;\n ref.meta = cfg?.meta ?? ({} as TMeta);\n\n makeObservable(ref, {\n current: observable.ref,\n meta: observable,\n });\n\n return ref;\n};\n\n/**\n * Checks whether the provided value is a ref created by `createRef`.\n *\n * @template T Referenced value type.\n * @template TMeta Ref metadata type.\n * @param value Value to inspect.\n * @returns `true` when the value is a ref-like function with `current`.\n *\n * @example\n * ```ts\n * const ref = createRef<number>();\n * isRef(ref); // true\n * ```\n *\n * @example\n * ```ts\n * isRef({ current: 1 }); // false\n * ```\n */\nexport const isRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n): value is Ref<T, TMeta> => {\n return typeof value === 'function' && 'current' in value;\n};\n\n/**\n * Normalizes a plain value or an existing ref into a `Ref` instance.\n *\n * @template T Referenced value type.\n * @template TMeta Ref metadata type.\n * @param value Existing ref or initial plain value.\n * @param cfg Optional ref configuration applied when a new ref is created.\n * @returns Existing ref or a newly created ref initialized with `value`.\n *\n * @example\n * ```ts\n * const ref = toRef(document.body);\n * ref.current === document.body;\n * ```\n *\n * @example\n * ```ts\n * const existingRef = createRef<number>();\n * const sameRef = toRef(existingRef);\n * ```\n */\nexport const toRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n cfg?: Omit<CreateRefConfig<T, TMeta>, 'initial'>,\n): Ref<T, TMeta> => {\n return isRef(value) ? value : createRef({ initial: value, ...cfg });\n};\n","import { action, makeObservable, observable } from 'mobx';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { AnyObject } from 'yummies/types';\n\n/**\n * Wraps a plain object into a deeply observable structure and allows\n * patch-like updates while preserving nested observable references where possible.\n *\n * @template TData Observable object shape.\n *\n * @example\n * ```ts\n * const state = new DeepObservableStruct({ user: { name: 'Ann' } });\n * state.set({ user: { name: 'Bob' } });\n * ```\n *\n * @example\n * ```ts\n * const state = new DeepObservableStruct({ filters: { active: true } });\n * state.set({ filters: { active: false, archived: true } });\n * ```\n */\nexport class DeepObservableStruct<TData extends AnyObject> {\n data: TData;\n\n constructor(data: TData) {\n this.data = data;\n\n makeObservable(this, {\n data: observable.deep,\n set: action,\n });\n }\n\n set(newData: Partial<TData>) {\n type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];\n\n const stack: StackItem[] = Object.keys(this.data).map((key) => [\n key,\n this.data,\n newData,\n ]);\n\n let currentIndex = 0;\n let stackLength = stack.length;\n\n while (currentIndex < stackLength) {\n const [key, currObservableData, newData] = stack[currentIndex];\n const newValue = newData[key];\n const currValue = currObservableData[key];\n\n currentIndex++;\n\n if (key in newData) {\n if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {\n const newValueKeys = Object.keys(newValue);\n\n Object.keys(currValue).forEach((childKey) => {\n if (!(childKey in newValue)) {\n delete currObservableData[key][childKey];\n }\n });\n\n newValueKeys.forEach((childKey) => {\n const length = stack.push([\n childKey,\n currObservableData[key],\n newValue,\n ]);\n stackLength = length;\n });\n } else if (newValue !== currValue) {\n currObservableData[key] = newValue;\n }\n } else {\n delete currObservableData[key];\n }\n }\n\n Object.keys(newData).forEach((newDataKey) => {\n if (!this.data[newDataKey]) {\n // @ts-expect-error\n this.data[newDataKey] = newData[newDataKey];\n }\n });\n }\n}\n","import { $mobx, type AnnotationMapEntry } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\ntype ObservableObjectAdministration = Parameters<\n Exclude<AnnotationMapEntry, boolean>['make_']\n>[0];\n\n/**\n * Returns the internal MobX administration object associated with an observable target.\n *\n * @param context Observable object instance.\n * @returns MobX administration internals stored under `$mobx`.\n *\n * @example\n * ```ts\n * const admin = getMobxAdministration(store);\n * admin.name_;\n * ```\n *\n * @example\n * ```ts\n * const values = getMobxAdministration(formState).values_;\n * ```\n */\nexport const getMobxAdministration = (\n context: AnyObject,\n): ObservableObjectAdministration => context[$mobx];\n","import { onBecomeObserved, onBecomeUnobserved } from 'mobx';\n\n/**\n * Starts side effects only while one or more MobX observables are being observed.\n *\n * When the first property becomes observed, `onStart` is called. When all tracked\n * properties become unobserved, `onEnd` is called with the value returned by\n * `onStart`. Cleanup can be delayed via `endDelay`.\n *\n * It uses MobX `onBecomeObserved` and `onBecomeUnobserved` hooks to perform\n * lazy subscription management.\n *\n * @template TMetaData Data returned from `onStart` and forwarded to `onEnd`.\n * @param config Configuration for tracked properties and lifecycle callbacks.\n * @returns Cleanup function that clears the tracked state and runs `onEnd`.\n *\n * @example\n * ```ts\n * const stop = lazyObserve({\n * context: store,\n * property: 'items',\n * onStart: () => api.subscribe(),\n * onEnd: (subscription) => subscription.unsubscribe(),\n * });\n * ```\n *\n * @example\n * ```ts\n * lazyObserve({\n * property: [boxA, boxB],\n * onStart: () => console.log('observed'),\n * endDelay: 300,\n * });\n * ```\n */\nexport const lazyObserve = <TMetaData = void>({\n context,\n property,\n onStart,\n onEnd,\n endDelay = false,\n}: {\n context?: any;\n property: any | any[];\n onStart?: () => TMetaData;\n onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;\n endDelay?: number | false;\n}) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let metaData: TMetaData | undefined;\n const observingProps = new Set<string>();\n const properties = Array.isArray(property) ? property : [property];\n\n const cleanup = () => {\n observingProps.clear();\n\n if (endDelay === false) {\n onEnd?.(metaData!, cleanup);\n metaData = undefined;\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n timeoutId = setTimeout(() => {\n onEnd?.(metaData!, cleanup);\n timeoutId = undefined;\n metaData = undefined;\n }, endDelay);\n };\n\n const start = (property: string) => {\n const isAlreadyObserving = observingProps.size > 0;\n observingProps.add(property);\n\n if (isAlreadyObserving) {\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n metaData = onStart?.();\n };\n\n const stop = (property: string) => {\n const isAlreadyNotObserving = !observingProps.size;\n\n observingProps.delete(property);\n\n const isObserving = observingProps.size > 0;\n\n if (isAlreadyNotObserving || isObserving) {\n return;\n }\n\n cleanup();\n };\n\n properties.forEach((property) => {\n if (context) {\n onBecomeObserved(context, property, () => start(property));\n onBecomeUnobserved(context, property, () => stop(property));\n } else {\n onBecomeObserved(property, () => start(property));\n onBecomeUnobserved(property, () => stop(property));\n }\n });\n\n return cleanup;\n};\n"],"names":["makeObservable","createAtom","mobxComparer","runInAction","observable","action","newData","typeGuard","$mobx","property","onBecomeObserved","onBecomeUnobserved"],"mappings":";;;;AA2BO,MAAM,kBAAkB,CAC7B,SACA,kBACA,kBACG;AACH,MAAI,eAAe;AACjB,qBAAiB,QAAQ,CAAC,CAAC,qBAAqB,MAAM;AACpD,aAAO,QAAQ,CAAC,UAAU;AAExB,mBAAW,SAAS,KAAK;AAAA,MAC3B,CAAC;AAAA,IACH,CAAC;AAEDA,SAAAA,eAAe,OAAO;AAAA,EACxB,OAAO;AACL,UAAM,oBAA+B,CAAA;AAErC,qBAAiB,QAAQ,CAAC,CAAC,qBAAqB,MAAM;AACpD,aAAO,QAAQ,CAAC,UAAU;AACxB,0BAAkB,KAA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;AACjD,mBAAe,IAAIA,SAAQ;AAE3B,QAAI,oBAAoB;AACtB;AAAA,IACF;AAEA,QAAI,WAAW;AACb,mBAAa,SAAS;AACtB,kBAAY;AAAA,IACd;AAEA,eAAW,UAAA;AAAA,EACb;AAEA,QAAM,OAAO,CAACA,cAAqB;AACjC,UAAM,wBAAwB,CAAC,eAAe;AAE9C,mBAAe,OAAOA,SAAQ;AAE9B,UAAM,cAAc,eAAe,OAAO;AAE1C,QAAI,yBAAyB,aAAa;AACxC;AAAA,IACF;AAEA,YAAA;AAAA,EACF;AAEA,aAAW,QAAQ,CAACA,cAAa;AAC/B,QAAI,SAAS;AACXC,WAAAA,iBAAiB,SAASD,WAAU,MAAM,MAAMA,SAAQ,CAAC;AACzDE,WAAAA,mBAAmB,SAASF,WAAU,MAAM,KAAKA,SAAQ,CAAC;AAAA,IAC5D,OAAO;AACLC,WAAAA,iBAAiBD,WAAU,MAAM,MAAMA,SAAQ,CAAC;AAChDE,WAAAA,mBAAmBF,WAAU,MAAM,KAAKA,SAAQ,CAAC;AAAA,IACnD;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"mobx.cjs","names":[],"sources":["../src/mobx/apply-observable.ts","../src/mobx/create-enhanced-atom.ts","../src/mobx/create-ref.ts","../src/mobx/deep-observable-struct.ts","../src/mobx/get-mobx-administration.ts","../src/mobx/lazy-observe.ts"],"sourcesContent":["import { type AnnotationMapEntry, makeObservable } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport type ObservableAnnotationsArray<T extends AnyObject = AnyObject> = [\n AnnotationMapEntry,\n ...(keyof T | (string & {}))[],\n][];\n\n/**\n * Applies a compact list of MobX annotations to an object using either\n * decorator-style invocation or the annotation map form accepted by `makeObservable`.\n *\n * @template T Target object type.\n * @param context Object that should become observable.\n * @param annotationsArray Tuples of annotation followed by annotated field names.\n * @param useDecorators Enables decorator-style application before calling `makeObservable`.\n *\n * @example\n * ```ts\n * applyObservable(store, [[observable, 'items'], [action, 'setItems']]);\n * ```\n *\n * @example\n * ```ts\n * applyObservable(viewModel, [[computed, 'fullName']], true);\n * ```\n */\nexport const applyObservable = <T extends AnyObject>(\n context: T,\n annotationsArray: ObservableAnnotationsArray<T>,\n useDecorators?: boolean,\n) => {\n if (useDecorators) {\n annotationsArray.forEach(([annotation, ...fields]) => {\n fields.forEach((field) => {\n // @ts-expect-error\n annotation(context, field);\n });\n });\n\n makeObservable(context);\n } else {\n const annotationsObject: AnyObject = {};\n\n annotationsArray.forEach(([annotation, ...fields]) => {\n fields.forEach((field) => {\n annotationsObject[field] = annotation;\n });\n });\n\n makeObservable(context, annotationsObject);\n }\n};\n","import { createAtom, type IAtom } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\nexport interface IEnhancedAtom<TMeta extends AnyObject = AnyObject>\n extends IAtom {\n meta: TMeta;\n}\n\n/**\n * Creates a MobX atom extended with metadata and bound reporting methods.\n *\n * @template TMeta Metadata object stored on the atom.\n * @param name Atom name used by MobX for debugging.\n * @param onBecomeObservedHandler Callback fired when the atom becomes observed.\n * @param onBecomeUnobservedHandler Callback fired when the atom is no longer observed.\n * @param meta Optional metadata attached to the atom.\n * @returns Atom instance with `meta`, `reportChanged` and `reportObserved`.\n *\n * @example\n * ```ts\n * const atom = createEnhancedAtom('user-status');\n * atom.reportChanged();\n * ```\n *\n * @example\n * ```ts\n * const atom = createEnhancedAtom('cache', undefined, undefined, { scope: 'users' });\n * atom.meta.scope;\n * ```\n */\nexport const createEnhancedAtom = <TMeta extends AnyObject>(\n name: string,\n onBecomeObservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n onBecomeUnobservedHandler?: (atom: IEnhancedAtom<TMeta>) => void,\n meta?: TMeta,\n): IEnhancedAtom<TMeta> => {\n const atom = createAtom(\n name,\n onBecomeObservedHandler && (() => onBecomeObservedHandler(atom)),\n onBecomeUnobservedHandler && (() => onBecomeUnobservedHandler(atom)),\n ) as IEnhancedAtom<TMeta>;\n atom.meta = meta ?? ({} as TMeta);\n atom.reportChanged = atom.reportChanged.bind(atom);\n atom.reportObserved = atom.reportObserved.bind(atom);\n return atom;\n};\n","import {\n type IEqualsComparer,\n makeObservable,\n comparer as mobxComparer,\n observable,\n runInAction,\n} from 'mobx';\nimport type { AnyObject, Maybe } from 'yummies/types';\n\n/**\n * You can return `false` if you don't want to change the value in this ref\n */\nexport type RefChangeListener<T> = (\n value: T | null,\n prevValue: T | undefined,\n) => void | false;\n\n/**\n * Alternative to React.createRef but works in MobX world.\n * Typically it the should be the same React.LegacyRef (fn style)\n */\nexport interface Ref<T = any, TMeta = AnyObject> {\n /**\n * Setter function\n */\n (value: Maybe<T>): void;\n\n set(value: Maybe<T>): void;\n listeners: Set<RefChangeListener<NoInfer<T>>>;\n current: NoInfer<T> | null;\n meta: TMeta;\n}\n\nexport interface CreateRefConfig<T = any, TMeta = AnyObject> {\n onSet?: (node: T, prevValue: T | undefined) => void;\n onUnset?: (lastValue: T | undefined) => void;\n onChange?: RefChangeListener<T>;\n meta?: TMeta;\n initial?: Maybe<T>;\n comparer?: IEqualsComparer<T | null>;\n}\n\n/**\n * Creates a MobX-aware ref that behaves like a callback ref and exposes\n * observable `current` and `meta` fields.\n *\n * @template T Referenced value type.\n * @template TMeta Additional observable metadata stored on the ref.\n * @param cfg Optional callbacks, initial value and comparer configuration.\n * @returns Observable ref function object.\n *\n * @example\n * ```ts\n * const inputRef = createRef<HTMLInputElement>();\n * inputRef.set(document.createElement('input'));\n * ```\n *\n * @example\n * ```ts\n * const ref = createRef<number>();\n * ref(3);\n * ref.current; // 3\n * ```\n *\n * @example\n * ```ts\n * const nodeRef = createRef({\n * onUnset: () => console.log('detached'),\n * meta: { mounted: false },\n * });\n * ```\n */\nexport const createRef = <T = any, TMeta = AnyObject>(\n cfg?: CreateRefConfig<T, TMeta>,\n): Ref<T, TMeta> => {\n let lastValue: T | undefined;\n const comparer = cfg?.comparer ?? mobxComparer.default;\n\n const setValue: Ref<T, TMeta>['set'] = (value) => {\n const nextValue = value ?? null;\n\n if (comparer(ref.current, nextValue)) {\n return;\n }\n\n runInAction(() => {\n const prevLastValue = lastValue;\n lastValue = ref.current ?? undefined;\n ref.current = nextValue;\n\n let isNextValueIgnored = false;\n\n ref.listeners.forEach((listener) => {\n const listenerResult = listener(ref.current, lastValue);\n\n if (listenerResult === false) {\n isNextValueIgnored = true;\n }\n });\n\n if (isNextValueIgnored) {\n lastValue = prevLastValue;\n ref.current = lastValue ?? null;\n } else if (ref.current === null && lastValue !== undefined) {\n lastValue = undefined;\n }\n });\n };\n\n const ref = setValue as Ref<T, TMeta>;\n\n ref.set = setValue;\n\n ref.listeners = new Set(cfg?.onChange ? [cfg.onChange] : []);\n\n if (cfg?.onSet || cfg?.onUnset) {\n ref.listeners.add((value, prevValue) => {\n if (value) {\n cfg.onSet?.(value, prevValue);\n } else {\n cfg.onUnset?.(prevValue);\n }\n });\n }\n\n ref.current = cfg?.initial ?? null;\n ref.meta = cfg?.meta ?? ({} as TMeta);\n\n makeObservable(ref, {\n current: observable.ref,\n meta: observable,\n });\n\n return ref;\n};\n\n/**\n * Checks whether the provided value is a ref created by `createRef`.\n *\n * @template T Referenced value type.\n * @template TMeta Ref metadata type.\n * @param value Value to inspect.\n * @returns `true` when the value is a ref-like function with `current`.\n *\n * @example\n * ```ts\n * const ref = createRef<number>();\n * isRef(ref); // true\n * ```\n *\n * @example\n * ```ts\n * isRef({ current: 1 }); // false\n * ```\n */\nexport const isRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n): value is Ref<T, TMeta> => {\n return typeof value === 'function' && 'current' in value;\n};\n\n/**\n * Normalizes a plain value or an existing ref into a `Ref` instance.\n *\n * @template T Referenced value type.\n * @template TMeta Ref metadata type.\n * @param value Existing ref or initial plain value.\n * @param cfg Optional ref configuration applied when a new ref is created.\n * @returns Existing ref or a newly created ref initialized with `value`.\n *\n * @example\n * ```ts\n * const ref = toRef(document.body);\n * ref.current === document.body;\n * ```\n *\n * @example\n * ```ts\n * const existingRef = createRef<number>();\n * const sameRef = toRef(existingRef);\n * ```\n */\nexport const toRef = <T, TMeta = any>(\n value: T | Ref<T, TMeta>,\n cfg?: Omit<CreateRefConfig<T, TMeta>, 'initial'>,\n): Ref<T, TMeta> => {\n return isRef(value) ? value : createRef({ initial: value, ...cfg });\n};\n","import { action, makeObservable, observable } from 'mobx';\nimport { typeGuard } from 'yummies/type-guard';\nimport type { AnyObject } from 'yummies/types';\n\n/**\n * Wraps a plain object into a deeply observable structure and allows\n * patch-like updates while preserving nested observable references where possible.\n *\n * @template TData Observable object shape.\n *\n * @example\n * ```ts\n * const state = new DeepObservableStruct({ user: { name: 'Ann' } });\n * state.set({ user: { name: 'Bob' } });\n * ```\n *\n * @example\n * ```ts\n * const state = new DeepObservableStruct({ filters: { active: true } });\n * state.set({ filters: { active: false, archived: true } });\n * ```\n */\nexport class DeepObservableStruct<TData extends AnyObject> {\n data: TData;\n\n constructor(data: TData) {\n this.data = data;\n\n makeObservable(this, {\n data: observable.deep,\n set: action,\n });\n }\n\n set(newData: Partial<TData>) {\n type StackItem = [key: string, currObservable: AnyObject, new: AnyObject];\n\n const stack: StackItem[] = Object.keys(this.data).map((key) => [\n key,\n this.data,\n newData,\n ]);\n\n let currentIndex = 0;\n let stackLength = stack.length;\n\n while (currentIndex < stackLength) {\n const [key, currObservableData, newData] = stack[currentIndex];\n const newValue = newData[key];\n const currValue = currObservableData[key];\n\n currentIndex++;\n\n if (key in newData) {\n if (typeGuard.isObject(newValue) && typeGuard.isObject(currValue)) {\n const newValueKeys = Object.keys(newValue);\n\n Object.keys(currValue).forEach((childKey) => {\n if (!(childKey in newValue)) {\n delete currObservableData[key][childKey];\n }\n });\n\n newValueKeys.forEach((childKey) => {\n const length = stack.push([\n childKey,\n currObservableData[key],\n newValue,\n ]);\n stackLength = length;\n });\n } else if (newValue !== currValue) {\n currObservableData[key] = newValue;\n }\n } else {\n delete currObservableData[key];\n }\n }\n\n Object.keys(newData).forEach((newDataKey) => {\n if (!this.data[newDataKey]) {\n // @ts-expect-error\n this.data[newDataKey] = newData[newDataKey];\n }\n });\n }\n}\n","import { $mobx, type AnnotationMapEntry } from 'mobx';\nimport type { AnyObject } from 'yummies/types';\n\ntype ObservableObjectAdministration = Parameters<\n Exclude<AnnotationMapEntry, boolean>['make_']\n>[0];\n\n/**\n * Returns the internal MobX administration object associated with an observable target.\n *\n * @param context Observable object instance.\n * @returns MobX administration internals stored under `$mobx`.\n *\n * @example\n * ```ts\n * const admin = getMobxAdministration(store);\n * admin.name_;\n * ```\n *\n * @example\n * ```ts\n * const values = getMobxAdministration(formState).values_;\n * ```\n */\nexport const getMobxAdministration = (\n context: AnyObject,\n): ObservableObjectAdministration => context[$mobx];\n","import { onBecomeObserved, onBecomeUnobserved } from 'mobx';\n\n/**\n * Starts side effects only while one or more MobX observables are being observed.\n *\n * When the first property becomes observed, `onStart` is called. When all tracked\n * properties become unobserved, `onEnd` is called with the value returned by\n * `onStart`. Cleanup can be delayed via `endDelay`.\n *\n * It uses MobX `onBecomeObserved` and `onBecomeUnobserved` hooks to perform\n * lazy subscription management.\n *\n * @template TMetaData Data returned from `onStart` and forwarded to `onEnd`.\n * @param config Configuration for tracked properties and lifecycle callbacks.\n * @returns Cleanup function that clears the tracked state and runs `onEnd`.\n *\n * @example\n * ```ts\n * const stop = lazyObserve({\n * context: store,\n * property: 'items',\n * onStart: () => api.subscribe(),\n * onEnd: (subscription) => subscription.unsubscribe(),\n * });\n * ```\n *\n * @example\n * ```ts\n * lazyObserve({\n * property: [boxA, boxB],\n * onStart: () => console.log('observed'),\n * endDelay: 300,\n * });\n * ```\n */\nexport const lazyObserve = <TMetaData = void>({\n context,\n property,\n onStart,\n onEnd,\n endDelay = false,\n}: {\n context?: any;\n property: any | any[];\n onStart?: () => TMetaData;\n onEnd?: (metaData: TMetaData, cleanupFn: VoidFunction) => void;\n endDelay?: number | false;\n}) => {\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n let metaData: TMetaData | undefined;\n const observingProps = new Set<string>();\n const properties = Array.isArray(property) ? property : [property];\n\n const cleanup = () => {\n observingProps.clear();\n\n if (endDelay === false) {\n onEnd?.(metaData!, cleanup);\n metaData = undefined;\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n timeoutId = setTimeout(() => {\n onEnd?.(metaData!, cleanup);\n timeoutId = undefined;\n metaData = undefined;\n }, endDelay);\n };\n\n const start = (property: string) => {\n const isAlreadyObserving = observingProps.size > 0;\n observingProps.add(property);\n\n if (isAlreadyObserving) {\n return;\n }\n\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = undefined;\n }\n\n metaData = onStart?.();\n };\n\n const stop = (property: string) => {\n const isAlreadyNotObserving = !observingProps.size;\n\n observingProps.delete(property);\n\n const isObserving = observingProps.size > 0;\n\n if (isAlreadyNotObserving || isObserving) {\n return;\n }\n\n cleanup();\n };\n\n properties.forEach((property) => {\n if (context) {\n onBecomeObserved(context, property, () => start(property));\n onBecomeUnobserved(context, property, () => stop(property));\n } else {\n onBecomeObserved(property, () => start(property));\n onBecomeUnobserved(property, () => stop(property));\n }\n });\n\n return cleanup;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,mBACX,SACA,kBACA,kBACG;AACH,KAAI,eAAe;AACjB,mBAAiB,SAAS,CAAC,YAAY,GAAG,YAAY;AACpD,UAAO,SAAS,UAAU;AAExB,eAAW,SAAS,MAAM;KAC1B;IACF;AAEF,GAAA,GAAA,KAAA,gBAAe,QAAQ;QAClB;EACL,MAAM,oBAA+B,EAAE;AAEvC,mBAAiB,SAAS,CAAC,YAAY,GAAG,YAAY;AACpD,UAAO,SAAS,UAAU;AACxB,sBAAkB,SAAS;KAC3B;IACF;AAEF,GAAA,GAAA,KAAA,gBAAe,SAAS,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpB9C,IAAa,sBACX,MACA,yBACA,2BACA,SACyB;CAC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
|
|
97
97
|
* @example
|
|
98
98
|
* ```ts
|
|
99
|
+
* const ref = createRef<number>();
|
|
100
|
+
* ref(3);
|
|
101
|
+
* ref.current; // 3
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
99
106
|
* const nodeRef = createRef({
|
|
100
107
|
* onUnset: () => console.log('detached'),
|
|
101
108
|
* meta: { mounted: false },
|