@but212/atom-effect-jquery 0.24.1 → 0.26.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/README.md +1 -1
- package/dist/atom-effect-jquery.min.js +2 -2
- package/dist/atom-effect-jquery.min.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +73 -9
- package/dist/index.mjs +697 -568
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,27 @@ import { ReadonlyAtom } from '@but212/atom-effect';
|
|
|
11
11
|
import { untracked } from '@but212/atom-effect';
|
|
12
12
|
import { WritableAtom } from '@but212/atom-effect';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Represents a value that can be a synchronous `ReactiveValue<T>`,
|
|
16
|
+
* a `Promise<T>`, or an Atom yielding `T | Promise<T>`.
|
|
17
|
+
*/
|
|
18
|
+
declare type AsyncReactiveValue<T> = T | ReadonlyAtom<T | Promise<T>> | Promise<T> | (() => T | Promise<T>);
|
|
19
|
+
|
|
14
20
|
export { atom }
|
|
15
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Creates a two-way "lens" for a specific property path on an object-based atom.
|
|
24
|
+
* Optimized for performance using structural sharing and equality guards.
|
|
25
|
+
*
|
|
26
|
+
* This "fake" atom allows fine-grained binding to deep properties of a
|
|
27
|
+
* monolithic state atom without extra memory or complex computed logic.
|
|
28
|
+
*
|
|
29
|
+
* @param atom The source atom containing the object.
|
|
30
|
+
* @param path Dot-separated path to the property (e.g. 'user.profile.name').
|
|
31
|
+
* @returns A WritableAtom that reads from and writes to the specified path.
|
|
32
|
+
*/
|
|
33
|
+
export declare function atomLens<T extends object, P extends Paths<T>>(atom: WritableAtom<T>, path: P): WritableAtom<PathValue<T, P>>;
|
|
34
|
+
|
|
16
35
|
export { batch }
|
|
17
36
|
|
|
18
37
|
/**
|
|
@@ -21,21 +40,21 @@ export { batch }
|
|
|
21
40
|
*/
|
|
22
41
|
export declare interface BindingOptions<T = unknown> {
|
|
23
42
|
/** Binds textContent to any reactive source. */
|
|
24
|
-
text?:
|
|
43
|
+
text?: AsyncReactiveValue<unknown>;
|
|
25
44
|
/** Binds innerHTML to a reactive string source (sanitized). */
|
|
26
|
-
html?:
|
|
45
|
+
html?: AsyncReactiveValue<string>;
|
|
27
46
|
/** Map of class names to reactive boolean conditions. */
|
|
28
|
-
class?: Record<string,
|
|
47
|
+
class?: Record<string, AsyncReactiveValue<boolean>>;
|
|
29
48
|
/** Map of CSS properties to reactive values or [value, unit] tuples. */
|
|
30
49
|
css?: CssBindings;
|
|
31
50
|
/** Binds attributes with consistent primitive constraints. */
|
|
32
|
-
attr?: Record<string,
|
|
51
|
+
attr?: Record<string, AsyncReactiveValue<PrimitiveValue>>;
|
|
33
52
|
/** Binds DOM properties. */
|
|
34
|
-
prop?: Record<string,
|
|
53
|
+
prop?: Record<string, AsyncReactiveValue<unknown>>;
|
|
35
54
|
/** Direct visibility control (display: none). */
|
|
36
|
-
show?:
|
|
55
|
+
show?: AsyncReactiveValue<boolean>;
|
|
37
56
|
/** Inverse visibility control. */
|
|
38
|
-
hide?:
|
|
57
|
+
hide?: AsyncReactiveValue<boolean>;
|
|
39
58
|
/**
|
|
40
59
|
* Two-way binding for input values.
|
|
41
60
|
* Pass an atom or a `[atom, options]` tuple.
|
|
@@ -43,6 +62,8 @@ export declare interface BindingOptions<T = unknown> {
|
|
|
43
62
|
val?: WritableAtom<T> | [atom: WritableAtom<T>, options: ValOptions<T>];
|
|
44
63
|
/** Two-way binding for checkboxes and radio buttons. */
|
|
45
64
|
checked?: WritableAtom<boolean>;
|
|
65
|
+
/** Fully automated two-way form binding using name attributes. */
|
|
66
|
+
form?: WritableAtom<T extends object ? T : unknown>;
|
|
46
67
|
/** Event listeners with automatic batched execution and lifecycle-bound cleanup. */
|
|
47
68
|
on?: Record<string, (e: JQuery.Event) => void>;
|
|
48
69
|
}
|
|
@@ -80,6 +101,15 @@ declare class BindingRegistry {
|
|
|
80
101
|
*/
|
|
81
102
|
export declare type ComponentFn<P = Record<string, unknown>> = ($el: JQuery, props: P) => EffectResult;
|
|
82
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Composes an existing lens with a sub-path to create a deeper lens.
|
|
106
|
+
*
|
|
107
|
+
* @param lens The parent lens.
|
|
108
|
+
* @param path Sub-path relative to the parent lens.
|
|
109
|
+
* @returns A new lens pointing to the deeper path.
|
|
110
|
+
*/
|
|
111
|
+
export declare function composeLens<T extends object, P extends Paths<T>>(lens: WritableAtom<T>, path: P): WritableAtom<PathValue<T, P>>;
|
|
112
|
+
|
|
83
113
|
export { computed }
|
|
84
114
|
|
|
85
115
|
export { ComputedAtom }
|
|
@@ -92,7 +122,7 @@ export declare type CssBindings = Record<string, CssValue>;
|
|
|
92
122
|
/**
|
|
93
123
|
* CSS value: either a direct reactive value or a numeric tuple of [source, unit].
|
|
94
124
|
*/
|
|
95
|
-
export declare type CssValue =
|
|
125
|
+
export declare type CssValue = AsyncReactiveValue<string | number> | [source: AsyncReactiveValue<number>, unit: string];
|
|
96
126
|
|
|
97
127
|
export default default_2;
|
|
98
128
|
|
|
@@ -191,6 +221,16 @@ declare type KeysOfType<T, V> = {
|
|
|
191
221
|
[K in keyof T]: T[K] extends V ? K : never;
|
|
192
222
|
}[keyof T];
|
|
193
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Creates a lens factory bound to a specific atom.
|
|
226
|
+
* Eliminates the need to pass the atom reference on every call.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* const lens = lensFor(userAtom);
|
|
230
|
+
* const email = lens('settings.notifications.email'); // WritableAtom<boolean>
|
|
231
|
+
*/
|
|
232
|
+
export declare function lensFor<T extends object>(atom: WritableAtom<T>): <P extends Paths<T>>(path: P) => WritableAtom<PathValue<T, P>>;
|
|
233
|
+
|
|
194
234
|
/** Key type for Map/Set inside list.ts */
|
|
195
235
|
declare type ListKey = string | number;
|
|
196
236
|
|
|
@@ -230,6 +270,12 @@ export declare interface ListOptions<T> {
|
|
|
230
270
|
/** Possible return types for render() / empty */
|
|
231
271
|
declare type ListRenderResult = string | Element | DocumentFragment | JQuery;
|
|
232
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Maximum recursion depth for path generation.
|
|
275
|
+
* Prevents TypeScript compiler from hitting recursion limits on deeply nested types.
|
|
276
|
+
*/
|
|
277
|
+
declare type MaxDepth = 8;
|
|
278
|
+
|
|
233
279
|
/**
|
|
234
280
|
* Resolves after all pending microtask-scheduled reactive effects have flushed.
|
|
235
281
|
*
|
|
@@ -249,6 +295,18 @@ declare type ListRenderResult = string | Element | DocumentFragment | JQuery;
|
|
|
249
295
|
*/
|
|
250
296
|
export declare function nextTick(): Promise<void>;
|
|
251
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Generates a union of all valid dot-separated paths for type T.
|
|
300
|
+
*/
|
|
301
|
+
export declare type Paths<T, D extends unknown[] = []> = D['length'] extends MaxDepth ? never : T extends object ? {
|
|
302
|
+
[K in keyof T & (string | number)]-?: `${K}` | (T[K] extends object ? `${K}.${Paths<T[K], [...D, 1]>}` : never);
|
|
303
|
+
}[keyof T & (string | number)] : never;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Extracts the value type at path P within type T.
|
|
307
|
+
*/
|
|
308
|
+
export declare type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? StringKeyToNumber<K> extends keyof T ? PathValue<T[StringKeyToNumber<K> & keyof T], Rest> : never : StringKeyToNumber<P> extends keyof T ? T[StringKeyToNumber<P> & keyof T] : never;
|
|
309
|
+
|
|
252
310
|
/**
|
|
253
311
|
* Values allowed for DOM properties and attributes.
|
|
254
312
|
*/
|
|
@@ -261,7 +319,7 @@ export declare type PrimitiveValue = string | number | boolean | null | undefine
|
|
|
261
319
|
* `ComputedAtom<T>` is a structural sub-type of `ReadonlyAtom<T>`, so it is
|
|
262
320
|
* already covered by `ReadonlyAtom<T>`.
|
|
263
321
|
*/
|
|
264
|
-
export declare type ReactiveValue<T> = T | ReadonlyAtom<T
|
|
322
|
+
export declare type ReactiveValue<T> = T | ReadonlyAtom<T> | (() => T);
|
|
265
323
|
|
|
266
324
|
export { ReadonlyAtom }
|
|
267
325
|
|
|
@@ -300,6 +358,12 @@ export declare interface Router {
|
|
|
300
358
|
destroy: () => void;
|
|
301
359
|
}
|
|
302
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Helper to convert a numeric string to a number type, otherwise returns the string.
|
|
363
|
+
* Used for array indexing in paths.
|
|
364
|
+
*/
|
|
365
|
+
declare type StringKeyToNumber<S extends string> = S extends `${infer N extends number}` ? N : S;
|
|
366
|
+
|
|
303
367
|
export declare interface TemplateRoute extends RouteLifecycle {
|
|
304
368
|
template: string;
|
|
305
369
|
render?: never;
|