essor 0.0.6-beta.9 → 0.0.6

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/essor.d.cts CHANGED
@@ -1,19 +1,41 @@
1
+ import { ExcludeType } from 'essor-shared';
1
2
  import * as csstype from 'csstype';
2
3
 
4
+ declare const __essor_version = "0.0.6-beta.16";
5
+
3
6
  type EffectFn = () => void;
7
+ /**
8
+ * Signal class representing a reactive value.
9
+ */
4
10
  declare class Signal$1<T> {
5
11
  private _value;
12
+ private _reactive;
13
+ private __activeEffect;
6
14
  constructor(value: T);
7
15
  valueOf(): T;
8
16
  toString(): string;
9
17
  toJSON(): T;
10
18
  get value(): T;
19
+ __triggerObject(): void;
11
20
  set value(newValue: T);
12
21
  peek(): T;
13
22
  update(): void;
14
23
  }
24
+ /**
25
+ * Creates a Signal object.
26
+ * @param value - The initial value for the Signal.
27
+ * @returns A Signal object.
28
+ */
15
29
  declare function useSignal<T>(value?: T): Signal$1<T>;
30
+ /**
31
+ * Checks if a value is a Signal.
32
+ * @param value - The value to check.
33
+ * @returns True if the value is a Signal, otherwise false.
34
+ */
16
35
  declare function isSignal<T>(value: any): value is Signal$1<T>;
36
+ /**
37
+ * Computed class representing a computed reactive value.
38
+ */
17
39
  declare class Computed<T> {
18
40
  private readonly fn;
19
41
  private _value;
@@ -23,31 +45,60 @@ declare class Computed<T> {
23
45
  run(): void;
24
46
  get value(): T;
25
47
  }
48
+ /**
49
+ * Creates a Computed object.
50
+ * @param fn - The function to compute the value.
51
+ * @returns A Computed object.
52
+ */
26
53
  declare function useComputed<T>(fn: () => T): Computed<T>;
54
+ /**
55
+ * Checks if a value is a Computed object.
56
+ * @param value - The value to check.
57
+ * @returns True if the value is a Computed object, otherwise false.
58
+ */
27
59
  declare function isComputed<T>(value: any): value is Computed<T>;
60
+ /**
61
+ * Registers an effect function that runs whenever its dependencies change.
62
+ * @param fn - The effect function to register.
63
+ * @returns A function to unregister the effect.
64
+ */
28
65
  declare function useEffect(fn: EffectFn): () => void;
29
66
  type SignalObject<T> = {
30
67
  [K in keyof T]: Signal$1<T[K]> | T[K];
31
68
  };
32
69
  /**
33
70
  * Creates a SignalObject from the given initialValues, excluding specified keys.
34
- *
35
- * @param {T extends Object} initialValues - The initial values for the SignalObject.
36
- * @param {(key: string) => boolean | string[]} exclude - A function that determines which keys to exclude from the SignalObject.
37
- * @return {SignalObject<T>} The created SignalObject.
71
+ * @param initialValues - The initial values for the SignalObject.
72
+ * @param exclude - A function or array that determines which keys to exclude from the SignalObject.
73
+ * @returns The created SignalObject.
38
74
  */
39
- declare function signalObject<T extends object>(initialValues: T, exclude?: ((key: string) => boolean) | string[]): SignalObject<T>;
75
+ declare function signalObject<T extends object>(initialValues: T, exclude?: ExcludeType): SignalObject<T>;
40
76
  /**
41
77
  * Returns the current value of a signal, signal object, or plain object, excluding specified keys.
42
- *
43
- * @param {SignalObject<T> | T | Signal<T>} signal - The signal, signal object, or plain object to unwrap.
44
- * @param {(key: string) => boolean | string[]} [exclude] - A function that determines which keys to exclude from the unwrapped object.
45
- * @return {T} The unwrapped value of the signal, signal object, or plain object.
78
+ * @param signal - The signal, signal object, or plain object to unwrap.
79
+ * @param exclude - A function or array that determines which keys to exclude from the unwrapped object.
80
+ * @returns The unwrapped value of the signal, signal object, or plain object.
81
+ */
82
+ declare function unSignal<T>(signal: SignalObject<T> | T | Signal$1<T>, exclude?: ExcludeType): T;
83
+ /**
84
+ * Checks if an object is reactive.
85
+ * @param obj - The object to check.
86
+ * @returns True if the object is reactive, otherwise false.
87
+ */
88
+ declare function isReactive(obj: any): boolean;
89
+ /**
90
+ * Creates a shallow copy of a reactive object.
91
+ * @param obj - The reactive object to copy.
92
+ * @returns A shallow copy of the reactive object.
46
93
  */
47
- declare function unSignal<T>(signal: SignalObject<T> | T | Signal$1<T>, exclude?: ((key: string) => boolean) | string[]): T;
48
- declare function isReactive(obj: any): any;
49
94
  declare function unReactive(obj: any): any;
50
- declare function useReactive<T extends object>(initialValue: T): T;
95
+ /**
96
+ * Creates a reactive object.
97
+ * @param initialValue - The initial value for the reactive object.
98
+ * @param exclude - A function or array that determines which keys to exclude from the reactive object.
99
+ * @returns A reactive object.
100
+ */
101
+ declare function useReactive<T extends object>(initialValue: T, exclude?: ExcludeType): T;
51
102
 
52
103
  type WatchSource<T = any> = Signal$1<T> | Computed<T> | (() => T);
53
104
  type WatchCallback<V = any, OV = any> = (value: V, oldValue: OV) => any;
@@ -94,8 +145,9 @@ interface Output<T> {
94
145
  type: 'output';
95
146
  }
96
147
 
97
- type EssorComponent = (props: Record<string, unknown>) => TemplateNode;
98
- type Hook$1 = 'destroy' | 'create' | 'mounted' | 'update';
148
+ type EssorComponent = (props: Record<string, unknown>) => JSX.Element | TemplateNode;
149
+ type Hook$1 = 'mounted' | 'destroy';
150
+
99
151
  interface NodeTrack {
100
152
  cleanup: () => void;
101
153
  isRoot?: boolean;
@@ -266,9 +318,6 @@ declare global {
266
318
  }
267
319
  interface CustomAttributes<T> {
268
320
  ref?: Signal<T> | ((el: T) => void);
269
- classList?: {
270
- [k: string]: boolean | undefined;
271
- };
272
321
  key?: string | number | symbol;
273
322
  }
274
323
  type Accessor<T> = () => T;
@@ -276,7 +325,11 @@ declare global {
276
325
  interface DirectiveFunctions {
277
326
  [x: string]: (el: DOMElement, accessor: Accessor<any>) => void;
278
327
  }
279
- interface ExplicitProperties {}
328
+ interface ExplicitProperties<T> {
329
+ value: Signal<T>;
330
+ updateValue: (value: T) => void;
331
+ }
332
+
280
333
  interface ExplicitAttributes {}
281
334
  interface CustomEvents {}
282
335
  interface CustomCaptureEvents {}
@@ -286,12 +339,12 @@ declare global {
286
339
  CustomCaptureEvents[Key]
287
340
  >;
288
341
  };
289
- type BindAttributes = {
290
- [Key in string | number | symbol as `bind:${Key}`]?: ExplicitAttributes[Key];
342
+ type PropAttributes<T> = {
343
+ [Key in keyof ExplicitProperties]?: ExplicitProperties<T>[Key];
291
344
  };
292
345
  interface DOMAttributes<T>
293
346
  extends CustomAttributes<T>,
294
- BindAttributes,
347
+ PropAttributes<T>,
295
348
  OnCaptureAttributes<T>,
296
349
  CustomEventHandlersCamelCase<T>,
297
350
  CustomEventHandlersLowerCase<T> {
@@ -2299,7 +2352,7 @@ declare global {
2299
2352
  }
2300
2353
  }
2301
2354
 
2302
- declare class TemplateNode implements JSX.Element {
2355
+ declare class TemplateNode$1 implements JSX.Element {
2303
2356
  template: HTMLTemplateElement;
2304
2357
  props: Record<string, unknown>;
2305
2358
  key?: string | undefined;
@@ -2319,7 +2372,7 @@ declare class TemplateNode implements JSX.Element {
2319
2372
  mapNodeTree(parent: Node, tree: Node): void;
2320
2373
  patchNodes(props: any): void;
2321
2374
  getNodeTrack(trackKey: string, trackLastNodes?: boolean, isRoot?: boolean): NodeTrack;
2322
- inheritNode(node: TemplateNode): void;
2375
+ inheritNode(node: TemplateNode$1): void;
2323
2376
  patchNode(key: any, node: any, props: any, isRoot: any): void;
2324
2377
  }
2325
2378
 
@@ -2338,7 +2391,7 @@ declare class ComponentNode$1 implements JSX.Element {
2338
2391
  context: Record<symbol | string | number, any>;
2339
2392
  emitter: Set<Function>;
2340
2393
  mounted: boolean;
2341
- rootNode: TemplateNode | null;
2394
+ rootNode: TemplateNode$1 | null;
2342
2395
  hooks: Record<Hook, Set<() => void>>;
2343
2396
  private trackMap;
2344
2397
  get firstChild(): Node | null;
@@ -2353,7 +2406,7 @@ declare class ComponentNode$1 implements JSX.Element {
2353
2406
  patchProps(props: Record<string, any>): void;
2354
2407
  }
2355
2408
 
2356
- declare function h(template: EssorComponent | HTMLTemplateElement, props: Record<string, any>, key?: string): JSX.Element;
2409
+ declare function h<K extends keyof HTMLElementTagNameMap>(_template: EssorComponent | HTMLTemplateElement | K, props: Record<string, any>, key?: string): JSX.Element;
2357
2410
  declare function isJsxElement(node: unknown): node is EssorNode;
2358
2411
  declare function template(html: string): HTMLTemplateElement;
2359
2412
  declare function Fragment(props: {
@@ -2379,20 +2432,15 @@ declare function useRef<T>(): {
2379
2432
  current: T | null;
2380
2433
  };
2381
2434
 
2382
- declare const __essor_version = "0.0.6-beta.8";
2383
-
2384
- interface TemplateMap {
2385
- [key: number]: {
2386
- template: string;
2387
- prop?: Record<string, any>;
2388
- };
2389
- }
2390
2435
  type Props = Record<string, any>;
2391
- declare function ssrtmpl(templates?: string[]): TemplateMap;
2392
- declare function ssr(template: TemplateMap | EssorNode | ((props: Props) => string), props: Props): string;
2436
+ declare function renderTemplate(template: string[] | EssorNode | Function, props: Props): string;
2437
+ /**
2438
+ * Renders the component to a string.
2439
+ * @param component - The component function.
2440
+ * @param props - The properties to pass to the component.
2441
+ * @returns The rendered component as a string.
2442
+ */
2393
2443
  declare function renderToString(component: (...args: any[]) => string, props: Props): string;
2394
- declare function ssgRender(component: {
2395
- mount: (root: HTMLElement) => void;
2396
- }, root: HTMLElement): void;
2444
+ declare function ssgRender(component: any, root: HTMLElement, props?: Props): void;
2397
2445
 
2398
- export { ComponentNode$1 as ComponentNode, Computed, type EssorComponent, type EssorNode, Fragment, type Hook$1 as Hook, type InjectionKey, type NodeTrack, type Output, Signal$1 as Signal, type StoreActions, TemplateNode, __essor_version, createStore, h, isComputed, isJsxElement, isReactive, isSignal, nextTick, onDestroy, onMount, renderToString, signalObject, ssgRender, ssr, ssrtmpl, template, unReactive, unSignal, useComputed, useEffect, useInject, useProvide, useReactive, useRef, useSignal, useWatch };
2446
+ export { ComponentNode$1 as ComponentNode, Computed, type EssorComponent, type EssorNode, Fragment, type Hook$1 as Hook, type InjectionKey, type NodeTrack, type Output, Signal$1 as Signal, type StoreActions, TemplateNode$1 as TemplateNode, __essor_version, createStore, h, isComputed, isJsxElement, isReactive, isSignal, nextTick, onDestroy, onMount, renderTemplate, renderToString, signalObject, ssgRender, template, unReactive, unSignal, useComputed, useEffect, useInject, useProvide, useReactive, useRef, useSignal, useWatch };
package/dist/essor.d.ts CHANGED
@@ -1,19 +1,41 @@
1
+ import { ExcludeType } from 'essor-shared';
1
2
  import * as csstype from 'csstype';
2
3
 
4
+ declare const __essor_version = "0.0.6-beta.16";
5
+
3
6
  type EffectFn = () => void;
7
+ /**
8
+ * Signal class representing a reactive value.
9
+ */
4
10
  declare class Signal$1<T> {
5
11
  private _value;
12
+ private _reactive;
13
+ private __activeEffect;
6
14
  constructor(value: T);
7
15
  valueOf(): T;
8
16
  toString(): string;
9
17
  toJSON(): T;
10
18
  get value(): T;
19
+ __triggerObject(): void;
11
20
  set value(newValue: T);
12
21
  peek(): T;
13
22
  update(): void;
14
23
  }
24
+ /**
25
+ * Creates a Signal object.
26
+ * @param value - The initial value for the Signal.
27
+ * @returns A Signal object.
28
+ */
15
29
  declare function useSignal<T>(value?: T): Signal$1<T>;
30
+ /**
31
+ * Checks if a value is a Signal.
32
+ * @param value - The value to check.
33
+ * @returns True if the value is a Signal, otherwise false.
34
+ */
16
35
  declare function isSignal<T>(value: any): value is Signal$1<T>;
36
+ /**
37
+ * Computed class representing a computed reactive value.
38
+ */
17
39
  declare class Computed<T> {
18
40
  private readonly fn;
19
41
  private _value;
@@ -23,31 +45,60 @@ declare class Computed<T> {
23
45
  run(): void;
24
46
  get value(): T;
25
47
  }
48
+ /**
49
+ * Creates a Computed object.
50
+ * @param fn - The function to compute the value.
51
+ * @returns A Computed object.
52
+ */
26
53
  declare function useComputed<T>(fn: () => T): Computed<T>;
54
+ /**
55
+ * Checks if a value is a Computed object.
56
+ * @param value - The value to check.
57
+ * @returns True if the value is a Computed object, otherwise false.
58
+ */
27
59
  declare function isComputed<T>(value: any): value is Computed<T>;
60
+ /**
61
+ * Registers an effect function that runs whenever its dependencies change.
62
+ * @param fn - The effect function to register.
63
+ * @returns A function to unregister the effect.
64
+ */
28
65
  declare function useEffect(fn: EffectFn): () => void;
29
66
  type SignalObject<T> = {
30
67
  [K in keyof T]: Signal$1<T[K]> | T[K];
31
68
  };
32
69
  /**
33
70
  * Creates a SignalObject from the given initialValues, excluding specified keys.
34
- *
35
- * @param {T extends Object} initialValues - The initial values for the SignalObject.
36
- * @param {(key: string) => boolean | string[]} exclude - A function that determines which keys to exclude from the SignalObject.
37
- * @return {SignalObject<T>} The created SignalObject.
71
+ * @param initialValues - The initial values for the SignalObject.
72
+ * @param exclude - A function or array that determines which keys to exclude from the SignalObject.
73
+ * @returns The created SignalObject.
38
74
  */
39
- declare function signalObject<T extends object>(initialValues: T, exclude?: ((key: string) => boolean) | string[]): SignalObject<T>;
75
+ declare function signalObject<T extends object>(initialValues: T, exclude?: ExcludeType): SignalObject<T>;
40
76
  /**
41
77
  * Returns the current value of a signal, signal object, or plain object, excluding specified keys.
42
- *
43
- * @param {SignalObject<T> | T | Signal<T>} signal - The signal, signal object, or plain object to unwrap.
44
- * @param {(key: string) => boolean | string[]} [exclude] - A function that determines which keys to exclude from the unwrapped object.
45
- * @return {T} The unwrapped value of the signal, signal object, or plain object.
78
+ * @param signal - The signal, signal object, or plain object to unwrap.
79
+ * @param exclude - A function or array that determines which keys to exclude from the unwrapped object.
80
+ * @returns The unwrapped value of the signal, signal object, or plain object.
81
+ */
82
+ declare function unSignal<T>(signal: SignalObject<T> | T | Signal$1<T>, exclude?: ExcludeType): T;
83
+ /**
84
+ * Checks if an object is reactive.
85
+ * @param obj - The object to check.
86
+ * @returns True if the object is reactive, otherwise false.
87
+ */
88
+ declare function isReactive(obj: any): boolean;
89
+ /**
90
+ * Creates a shallow copy of a reactive object.
91
+ * @param obj - The reactive object to copy.
92
+ * @returns A shallow copy of the reactive object.
46
93
  */
47
- declare function unSignal<T>(signal: SignalObject<T> | T | Signal$1<T>, exclude?: ((key: string) => boolean) | string[]): T;
48
- declare function isReactive(obj: any): any;
49
94
  declare function unReactive(obj: any): any;
50
- declare function useReactive<T extends object>(initialValue: T): T;
95
+ /**
96
+ * Creates a reactive object.
97
+ * @param initialValue - The initial value for the reactive object.
98
+ * @param exclude - A function or array that determines which keys to exclude from the reactive object.
99
+ * @returns A reactive object.
100
+ */
101
+ declare function useReactive<T extends object>(initialValue: T, exclude?: ExcludeType): T;
51
102
 
52
103
  type WatchSource<T = any> = Signal$1<T> | Computed<T> | (() => T);
53
104
  type WatchCallback<V = any, OV = any> = (value: V, oldValue: OV) => any;
@@ -94,8 +145,9 @@ interface Output<T> {
94
145
  type: 'output';
95
146
  }
96
147
 
97
- type EssorComponent = (props: Record<string, unknown>) => TemplateNode;
98
- type Hook$1 = 'destroy' | 'create' | 'mounted' | 'update';
148
+ type EssorComponent = (props: Record<string, unknown>) => JSX.Element | TemplateNode;
149
+ type Hook$1 = 'mounted' | 'destroy';
150
+
99
151
  interface NodeTrack {
100
152
  cleanup: () => void;
101
153
  isRoot?: boolean;
@@ -266,9 +318,6 @@ declare global {
266
318
  }
267
319
  interface CustomAttributes<T> {
268
320
  ref?: Signal<T> | ((el: T) => void);
269
- classList?: {
270
- [k: string]: boolean | undefined;
271
- };
272
321
  key?: string | number | symbol;
273
322
  }
274
323
  type Accessor<T> = () => T;
@@ -276,7 +325,11 @@ declare global {
276
325
  interface DirectiveFunctions {
277
326
  [x: string]: (el: DOMElement, accessor: Accessor<any>) => void;
278
327
  }
279
- interface ExplicitProperties {}
328
+ interface ExplicitProperties<T> {
329
+ value: Signal<T>;
330
+ updateValue: (value: T) => void;
331
+ }
332
+
280
333
  interface ExplicitAttributes {}
281
334
  interface CustomEvents {}
282
335
  interface CustomCaptureEvents {}
@@ -286,12 +339,12 @@ declare global {
286
339
  CustomCaptureEvents[Key]
287
340
  >;
288
341
  };
289
- type BindAttributes = {
290
- [Key in string | number | symbol as `bind:${Key}`]?: ExplicitAttributes[Key];
342
+ type PropAttributes<T> = {
343
+ [Key in keyof ExplicitProperties]?: ExplicitProperties<T>[Key];
291
344
  };
292
345
  interface DOMAttributes<T>
293
346
  extends CustomAttributes<T>,
294
- BindAttributes,
347
+ PropAttributes<T>,
295
348
  OnCaptureAttributes<T>,
296
349
  CustomEventHandlersCamelCase<T>,
297
350
  CustomEventHandlersLowerCase<T> {
@@ -2299,7 +2352,7 @@ declare global {
2299
2352
  }
2300
2353
  }
2301
2354
 
2302
- declare class TemplateNode implements JSX.Element {
2355
+ declare class TemplateNode$1 implements JSX.Element {
2303
2356
  template: HTMLTemplateElement;
2304
2357
  props: Record<string, unknown>;
2305
2358
  key?: string | undefined;
@@ -2319,7 +2372,7 @@ declare class TemplateNode implements JSX.Element {
2319
2372
  mapNodeTree(parent: Node, tree: Node): void;
2320
2373
  patchNodes(props: any): void;
2321
2374
  getNodeTrack(trackKey: string, trackLastNodes?: boolean, isRoot?: boolean): NodeTrack;
2322
- inheritNode(node: TemplateNode): void;
2375
+ inheritNode(node: TemplateNode$1): void;
2323
2376
  patchNode(key: any, node: any, props: any, isRoot: any): void;
2324
2377
  }
2325
2378
 
@@ -2338,7 +2391,7 @@ declare class ComponentNode$1 implements JSX.Element {
2338
2391
  context: Record<symbol | string | number, any>;
2339
2392
  emitter: Set<Function>;
2340
2393
  mounted: boolean;
2341
- rootNode: TemplateNode | null;
2394
+ rootNode: TemplateNode$1 | null;
2342
2395
  hooks: Record<Hook, Set<() => void>>;
2343
2396
  private trackMap;
2344
2397
  get firstChild(): Node | null;
@@ -2353,7 +2406,7 @@ declare class ComponentNode$1 implements JSX.Element {
2353
2406
  patchProps(props: Record<string, any>): void;
2354
2407
  }
2355
2408
 
2356
- declare function h(template: EssorComponent | HTMLTemplateElement, props: Record<string, any>, key?: string): JSX.Element;
2409
+ declare function h<K extends keyof HTMLElementTagNameMap>(_template: EssorComponent | HTMLTemplateElement | K, props: Record<string, any>, key?: string): JSX.Element;
2357
2410
  declare function isJsxElement(node: unknown): node is EssorNode;
2358
2411
  declare function template(html: string): HTMLTemplateElement;
2359
2412
  declare function Fragment(props: {
@@ -2379,20 +2432,15 @@ declare function useRef<T>(): {
2379
2432
  current: T | null;
2380
2433
  };
2381
2434
 
2382
- declare const __essor_version = "0.0.6-beta.8";
2383
-
2384
- interface TemplateMap {
2385
- [key: number]: {
2386
- template: string;
2387
- prop?: Record<string, any>;
2388
- };
2389
- }
2390
2435
  type Props = Record<string, any>;
2391
- declare function ssrtmpl(templates?: string[]): TemplateMap;
2392
- declare function ssr(template: TemplateMap | EssorNode | ((props: Props) => string), props: Props): string;
2436
+ declare function renderTemplate(template: string[] | EssorNode | Function, props: Props): string;
2437
+ /**
2438
+ * Renders the component to a string.
2439
+ * @param component - The component function.
2440
+ * @param props - The properties to pass to the component.
2441
+ * @returns The rendered component as a string.
2442
+ */
2393
2443
  declare function renderToString(component: (...args: any[]) => string, props: Props): string;
2394
- declare function ssgRender(component: {
2395
- mount: (root: HTMLElement) => void;
2396
- }, root: HTMLElement): void;
2444
+ declare function ssgRender(component: any, root: HTMLElement, props?: Props): void;
2397
2445
 
2398
- export { ComponentNode$1 as ComponentNode, Computed, type EssorComponent, type EssorNode, Fragment, type Hook$1 as Hook, type InjectionKey, type NodeTrack, type Output, Signal$1 as Signal, type StoreActions, TemplateNode, __essor_version, createStore, h, isComputed, isJsxElement, isReactive, isSignal, nextTick, onDestroy, onMount, renderToString, signalObject, ssgRender, ssr, ssrtmpl, template, unReactive, unSignal, useComputed, useEffect, useInject, useProvide, useReactive, useRef, useSignal, useWatch };
2446
+ export { ComponentNode$1 as ComponentNode, Computed, type EssorComponent, type EssorNode, Fragment, type Hook$1 as Hook, type InjectionKey, type NodeTrack, type Output, Signal$1 as Signal, type StoreActions, TemplateNode$1 as TemplateNode, __essor_version, createStore, h, isComputed, isJsxElement, isReactive, isSignal, nextTick, onDestroy, onMount, renderTemplate, renderToString, signalObject, ssgRender, template, unReactive, unSignal, useComputed, useEffect, useInject, useProvide, useReactive, useRef, useSignal, useWatch };