@estjs/template 0.0.14-beta.2 → 0.0.14-beta.21

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.
@@ -4,6 +4,17 @@ import * as csstype from 'csstype';
4
4
  type EssorComponent = (props: Record<string, unknown>) => JSX.Element | TemplateNode;
5
5
  type Hook = 'mounted' | 'destroy';
6
6
 
7
+ interface NodeTrack {
8
+ cleanup: () => void;
9
+ isRoot?: boolean;
10
+ lastNodes?: Map<string, Node | JSX.Element>;
11
+ }
12
+ interface NodeTrack {
13
+ cleanup: () => void;
14
+ isRoot?: boolean;
15
+ lastNodes?: Map<string, Node | JSX.Element>;
16
+ }
17
+
7
18
  type Props = Record<string, any>;
8
19
 
9
20
  interface EssorNode<T = Record<string, any>> {
@@ -2212,30 +2223,72 @@ declare class LifecycleContext {
2212
2223
  clearHooks(): void;
2213
2224
  }
2214
2225
 
2226
+ declare class TemplateNode$1 implements JSX.Element {
2227
+ template: HTMLTemplateElement;
2228
+ props: Props;
2229
+ key?: string | undefined;
2230
+ protected treeMap: Map<number, Node>;
2231
+ protected mounted: boolean;
2232
+ protected nodes: Node[];
2233
+ protected trackMap: Map<string, NodeTrack>;
2234
+ protected bindValueKeys: string[];
2235
+ protected componentIndex: number;
2236
+ protected parent: Node | null;
2237
+ constructor(template: HTMLTemplateElement, props: Props, key?: string | undefined);
2238
+ get firstChild(): Node | null;
2239
+ get isConnected(): boolean;
2240
+ addEventListener(): void;
2241
+ removeEventListener(): void;
2242
+ mount(parent: Node, before?: Node | null): Node[];
2243
+ unmount(): void;
2244
+ inheritNode(node: TemplateNode$1): void;
2245
+ protected mapSSGNodeTree(parent: Node): void;
2246
+ protected mapNodeTree(parent: Node, tree: Node): void;
2247
+ protected walkNodeTree(node: Node, handler: (node: Node) => void): void;
2248
+ protected handleSSGNode(node: Node): void;
2249
+ protected patchProps(props: Record<string, Record<string, unknown>> | undefined): void;
2250
+ protected patchProp(key: string, node: Node, props: Record<string, unknown>, isRoot: boolean): void;
2251
+ protected getBindUpdateValue(props: Record<string, any>, key: string, attr: string): any;
2252
+ protected patchChildren(key: string, node: Node, children: unknown, isRoot: boolean): void;
2253
+ protected patchEventListener(key: string, node: Node, attr: string, listener: EventListener): void;
2254
+ protected patchAttribute(key: string, element: HTMLElement, attr: string, value: unknown, updateFn?: Function): void;
2255
+ protected getNodeTrack(trackKey: string, trackLastNodes?: boolean, isRoot?: boolean): NodeTrack;
2256
+ protected patchChild(track: NodeTrack, parent: Node, child: unknown, before: Node | null): void;
2257
+ protected reconcileChildren(parent: Node, nextNodes: Node[], before: Node | null): Map<string, Node>;
2258
+ }
2259
+
2215
2260
  declare class ComponentNode$1 extends LifecycleContext implements JSX.Element {
2216
2261
  template: EssorComponent;
2217
- props?: Props | undefined;
2262
+ props: Props;
2218
2263
  key?: string | undefined;
2219
- private proxyProps;
2220
- private emitter;
2221
- private rootNode;
2222
- private trackMap;
2223
- constructor(template: EssorComponent, props?: Props | undefined, key?: string | undefined);
2224
- private createProxyProps;
2264
+ protected proxyProps: Record<string, Signal$1<unknown>>;
2265
+ protected emitter: Set<() => void>;
2266
+ protected rootNode: TemplateNode$1 | null;
2267
+ protected trackMap: Map<string, NodeTrack>;
2268
+ protected nodes: Node[];
2269
+ protected parent: Node | null;
2270
+ protected before: Node | null;
2271
+ constructor(template: EssorComponent, props: Props, key?: string | undefined);
2272
+ protected createProxyProps(props?: Props): Record<string, Signal$1<unknown>>;
2225
2273
  get firstChild(): Node | null;
2226
2274
  get isConnected(): boolean;
2227
- mount(parent: Node, before?: Node | null): Node[];
2275
+ mount(parent: Node, before: Node | null): Node[];
2228
2276
  unmount(): void;
2229
- private callMountHooks;
2230
- private callDestroyHooks;
2231
- private clearEmitter;
2277
+ private resetState;
2278
+ protected callLifecycleHooks(type: 'mounted' | 'destroy'): void;
2279
+ protected callMountHooks(): void;
2280
+ protected callDestroyHooks(): void;
2281
+ protected clearEmitter(): void;
2232
2282
  inheritNode(node: ComponentNode$1): void;
2233
- private getNodeTrack;
2283
+ protected getNodeTrack(trackKey: string): NodeTrack;
2234
2284
  patchProps(props: Record<string, any> | undefined): void;
2235
- private patchEventListener;
2236
- private patchRef;
2237
- private patchUpdateHandler;
2238
- private patchNormalProp;
2285
+ protected patchEventListener(key: string, prop: any): void;
2286
+ protected patchRef(prop: {
2287
+ value: Node | null;
2288
+ }): void;
2289
+ protected patchUpdateHandler(key: string, prop: any): void;
2290
+ protected patchNormalProp(key: string, prop: any): void;
2291
+ protected cleanup(): void;
2239
2292
  }
2240
2293
 
2241
2294
  /**
@@ -2270,14 +2323,12 @@ declare function isJsxElement(node: unknown): node is EssorNode;
2270
2323
  * @returns A new HTML template element.
2271
2324
  */
2272
2325
  declare function createTemplate(html: string): HTMLTemplateElement;
2273
- /**
2274
- * @param props - An object containing the `children` prop.
2275
- * @param props.children - The children to be rendered. Can be a single JSX element, string, number, boolean,
2276
- * or an array of these. Falsy values in arrays will be filtered out.
2277
- * @returns A JSX element representing the fragment, wrapping the filtered children.
2278
- */
2279
- declare function Fragment<T extends JSX.JSXElement | string | number | boolean | (JSX.JSXElement | string | number | boolean)[]>(props: {
2326
+ declare function Fragment<T extends JSX.JSXElement | string | number | boolean | Array<JSX.JSXElement | string | number | boolean>>(template: HTMLTemplateElement | '', props: {
2280
2327
  children: T;
2328
+ } | {
2329
+ [key: string]: {
2330
+ children: T;
2331
+ };
2281
2332
  }): JSX.Element;
2282
2333
 
2283
2334
  /**
@@ -2309,7 +2360,7 @@ interface InjectionKey<T> extends Symbol {
2309
2360
  * @param key - The key to store the value in the LifecycleContext with.
2310
2361
  * @param value - The value to store in the LifecycleContext with the given key.
2311
2362
  */
2312
- declare function useProvide<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): void;
2363
+ declare function provide<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): void;
2313
2364
  /**
2314
2365
  * Injects a value from the current component LifecycleContext.
2315
2366
  *
@@ -2322,21 +2373,7 @@ declare function useProvide<T, K = InjectionKey<T> | string | number>(key: K, va
2322
2373
  * @returns The value stored in the LifecycleContext with the given key, or the default
2323
2374
  * value if the key is not present in the LifecycleContext.
2324
2375
  */
2325
- declare function useInject<T, K = InjectionKey<T> | string | number>(key: K, defaultValue?: K extends InjectionKey<infer V> ? V : T): (K extends InjectionKey<infer V> ? V : T) | undefined;
2326
- /**
2327
- * Creates a reactive ref that can be used to reference a DOM node
2328
- * or a component instance within the component function body.
2329
- *
2330
- * @returns a reactive ref signal
2331
- *
2332
- * @example
2333
- * const inputRef = useRef<HTMLInputElement>()
2334
- *
2335
- * <input ref={inputRef} />
2336
- *
2337
- * inputRef.value // input element
2338
- */
2339
- declare function useRef<T>(): Signal$1<T | null>;
2376
+ declare function inject<T, K = InjectionKey<T> | string | number>(key: K, defaultValue?: K extends InjectionKey<infer V> ? V : T): (K extends InjectionKey<infer V> ? V : T) | undefined;
2340
2377
 
2341
2378
  declare class SSGNode extends LifecycleContext {
2342
2379
  private template;
@@ -2386,4 +2423,4 @@ declare function hydrate(component: EssorComponent, container: string | Element)
2386
2423
  */
2387
2424
  declare function ssg(component: EssorComponent, props?: Props): SSGNode | JSX.Element;
2388
2425
 
2389
- export { Fragment, type InjectionKey, h, hydrate, isComponent, isJsxElement, onDestroy, onMount, renderToString, ssg, createTemplate as template, useInject, useProvide, useRef };
2426
+ export { Fragment, type InjectionKey, h, hydrate, inject, isComponent, isJsxElement, onDestroy, onMount, provide, renderToString, ssg, createTemplate as template };
@@ -4,6 +4,17 @@ import * as csstype from 'csstype';
4
4
  type EssorComponent = (props: Record<string, unknown>) => JSX.Element | TemplateNode;
5
5
  type Hook = 'mounted' | 'destroy';
6
6
 
7
+ interface NodeTrack {
8
+ cleanup: () => void;
9
+ isRoot?: boolean;
10
+ lastNodes?: Map<string, Node | JSX.Element>;
11
+ }
12
+ interface NodeTrack {
13
+ cleanup: () => void;
14
+ isRoot?: boolean;
15
+ lastNodes?: Map<string, Node | JSX.Element>;
16
+ }
17
+
7
18
  type Props = Record<string, any>;
8
19
 
9
20
  interface EssorNode<T = Record<string, any>> {
@@ -2212,30 +2223,72 @@ declare class LifecycleContext {
2212
2223
  clearHooks(): void;
2213
2224
  }
2214
2225
 
2226
+ declare class TemplateNode$1 implements JSX.Element {
2227
+ template: HTMLTemplateElement;
2228
+ props: Props;
2229
+ key?: string | undefined;
2230
+ protected treeMap: Map<number, Node>;
2231
+ protected mounted: boolean;
2232
+ protected nodes: Node[];
2233
+ protected trackMap: Map<string, NodeTrack>;
2234
+ protected bindValueKeys: string[];
2235
+ protected componentIndex: number;
2236
+ protected parent: Node | null;
2237
+ constructor(template: HTMLTemplateElement, props: Props, key?: string | undefined);
2238
+ get firstChild(): Node | null;
2239
+ get isConnected(): boolean;
2240
+ addEventListener(): void;
2241
+ removeEventListener(): void;
2242
+ mount(parent: Node, before?: Node | null): Node[];
2243
+ unmount(): void;
2244
+ inheritNode(node: TemplateNode$1): void;
2245
+ protected mapSSGNodeTree(parent: Node): void;
2246
+ protected mapNodeTree(parent: Node, tree: Node): void;
2247
+ protected walkNodeTree(node: Node, handler: (node: Node) => void): void;
2248
+ protected handleSSGNode(node: Node): void;
2249
+ protected patchProps(props: Record<string, Record<string, unknown>> | undefined): void;
2250
+ protected patchProp(key: string, node: Node, props: Record<string, unknown>, isRoot: boolean): void;
2251
+ protected getBindUpdateValue(props: Record<string, any>, key: string, attr: string): any;
2252
+ protected patchChildren(key: string, node: Node, children: unknown, isRoot: boolean): void;
2253
+ protected patchEventListener(key: string, node: Node, attr: string, listener: EventListener): void;
2254
+ protected patchAttribute(key: string, element: HTMLElement, attr: string, value: unknown, updateFn?: Function): void;
2255
+ protected getNodeTrack(trackKey: string, trackLastNodes?: boolean, isRoot?: boolean): NodeTrack;
2256
+ protected patchChild(track: NodeTrack, parent: Node, child: unknown, before: Node | null): void;
2257
+ protected reconcileChildren(parent: Node, nextNodes: Node[], before: Node | null): Map<string, Node>;
2258
+ }
2259
+
2215
2260
  declare class ComponentNode$1 extends LifecycleContext implements JSX.Element {
2216
2261
  template: EssorComponent;
2217
- props?: Props | undefined;
2262
+ props: Props;
2218
2263
  key?: string | undefined;
2219
- private proxyProps;
2220
- private emitter;
2221
- private rootNode;
2222
- private trackMap;
2223
- constructor(template: EssorComponent, props?: Props | undefined, key?: string | undefined);
2224
- private createProxyProps;
2264
+ protected proxyProps: Record<string, Signal$1<unknown>>;
2265
+ protected emitter: Set<() => void>;
2266
+ protected rootNode: TemplateNode$1 | null;
2267
+ protected trackMap: Map<string, NodeTrack>;
2268
+ protected nodes: Node[];
2269
+ protected parent: Node | null;
2270
+ protected before: Node | null;
2271
+ constructor(template: EssorComponent, props: Props, key?: string | undefined);
2272
+ protected createProxyProps(props?: Props): Record<string, Signal$1<unknown>>;
2225
2273
  get firstChild(): Node | null;
2226
2274
  get isConnected(): boolean;
2227
- mount(parent: Node, before?: Node | null): Node[];
2275
+ mount(parent: Node, before: Node | null): Node[];
2228
2276
  unmount(): void;
2229
- private callMountHooks;
2230
- private callDestroyHooks;
2231
- private clearEmitter;
2277
+ private resetState;
2278
+ protected callLifecycleHooks(type: 'mounted' | 'destroy'): void;
2279
+ protected callMountHooks(): void;
2280
+ protected callDestroyHooks(): void;
2281
+ protected clearEmitter(): void;
2232
2282
  inheritNode(node: ComponentNode$1): void;
2233
- private getNodeTrack;
2283
+ protected getNodeTrack(trackKey: string): NodeTrack;
2234
2284
  patchProps(props: Record<string, any> | undefined): void;
2235
- private patchEventListener;
2236
- private patchRef;
2237
- private patchUpdateHandler;
2238
- private patchNormalProp;
2285
+ protected patchEventListener(key: string, prop: any): void;
2286
+ protected patchRef(prop: {
2287
+ value: Node | null;
2288
+ }): void;
2289
+ protected patchUpdateHandler(key: string, prop: any): void;
2290
+ protected patchNormalProp(key: string, prop: any): void;
2291
+ protected cleanup(): void;
2239
2292
  }
2240
2293
 
2241
2294
  /**
@@ -2270,14 +2323,12 @@ declare function isJsxElement(node: unknown): node is EssorNode;
2270
2323
  * @returns A new HTML template element.
2271
2324
  */
2272
2325
  declare function createTemplate(html: string): HTMLTemplateElement;
2273
- /**
2274
- * @param props - An object containing the `children` prop.
2275
- * @param props.children - The children to be rendered. Can be a single JSX element, string, number, boolean,
2276
- * or an array of these. Falsy values in arrays will be filtered out.
2277
- * @returns A JSX element representing the fragment, wrapping the filtered children.
2278
- */
2279
- declare function Fragment<T extends JSX.JSXElement | string | number | boolean | (JSX.JSXElement | string | number | boolean)[]>(props: {
2326
+ declare function Fragment<T extends JSX.JSXElement | string | number | boolean | Array<JSX.JSXElement | string | number | boolean>>(template: HTMLTemplateElement | '', props: {
2280
2327
  children: T;
2328
+ } | {
2329
+ [key: string]: {
2330
+ children: T;
2331
+ };
2281
2332
  }): JSX.Element;
2282
2333
 
2283
2334
  /**
@@ -2309,7 +2360,7 @@ interface InjectionKey<T> extends Symbol {
2309
2360
  * @param key - The key to store the value in the LifecycleContext with.
2310
2361
  * @param value - The value to store in the LifecycleContext with the given key.
2311
2362
  */
2312
- declare function useProvide<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): void;
2363
+ declare function provide<T, K = InjectionKey<T> | string | number>(key: K, value: K extends InjectionKey<infer V> ? V : T): void;
2313
2364
  /**
2314
2365
  * Injects a value from the current component LifecycleContext.
2315
2366
  *
@@ -2322,21 +2373,7 @@ declare function useProvide<T, K = InjectionKey<T> | string | number>(key: K, va
2322
2373
  * @returns The value stored in the LifecycleContext with the given key, or the default
2323
2374
  * value if the key is not present in the LifecycleContext.
2324
2375
  */
2325
- declare function useInject<T, K = InjectionKey<T> | string | number>(key: K, defaultValue?: K extends InjectionKey<infer V> ? V : T): (K extends InjectionKey<infer V> ? V : T) | undefined;
2326
- /**
2327
- * Creates a reactive ref that can be used to reference a DOM node
2328
- * or a component instance within the component function body.
2329
- *
2330
- * @returns a reactive ref signal
2331
- *
2332
- * @example
2333
- * const inputRef = useRef<HTMLInputElement>()
2334
- *
2335
- * <input ref={inputRef} />
2336
- *
2337
- * inputRef.value // input element
2338
- */
2339
- declare function useRef<T>(): Signal$1<T | null>;
2376
+ declare function inject<T, K = InjectionKey<T> | string | number>(key: K, defaultValue?: K extends InjectionKey<infer V> ? V : T): (K extends InjectionKey<infer V> ? V : T) | undefined;
2340
2377
 
2341
2378
  declare class SSGNode extends LifecycleContext {
2342
2379
  private template;
@@ -2386,4 +2423,4 @@ declare function hydrate(component: EssorComponent, container: string | Element)
2386
2423
  */
2387
2424
  declare function ssg(component: EssorComponent, props?: Props): SSGNode | JSX.Element;
2388
2425
 
2389
- export { Fragment, type InjectionKey, h, hydrate, isComponent, isJsxElement, onDestroy, onMount, renderToString, ssg, createTemplate as template, useInject, useProvide, useRef };
2426
+ export { Fragment, type InjectionKey, h, hydrate, inject, isComponent, isJsxElement, onDestroy, onMount, provide, renderToString, ssg, createTemplate as template };