@viewfly/core 0.5.3 → 0.6.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.
@@ -1,6 +1,7 @@
1
- import { JSXComponent, JSXElement, JSXText } from './jsx-element';
1
+ import { JSXNode } from './jsx-element';
2
2
  import { NativeNode } from './injection-tokens';
3
3
  import { Component } from './component';
4
+ import { JSXInternal } from './types';
4
5
  export interface ListenDelegate {
5
6
  delegate: () => any;
6
7
  listenFn: ((...args: any[]) => any) | void;
@@ -19,14 +20,31 @@ export interface ArrayChanges<T> {
19
20
  export declare function getArrayChanges<T>(left: T[], right: T[]): ArrayChanges<T>;
20
21
  export declare function classToString(config: unknown): string;
21
22
  export declare function styleToObject(style: string | Record<string, any>): Record<string, any>;
22
- export interface Atom {
23
- jsxNode: JSXElement | JSXText | JSXComponent | Component;
24
- parent: Atom | null;
23
+ export interface TextAtom {
24
+ type: 'text';
25
+ jsxNode: string;
25
26
  nativeNode: NativeNode | null;
26
27
  child: Atom | null;
27
28
  sibling: Atom | null;
28
29
  isSvg: boolean;
29
30
  }
31
+ export interface ElementAtom {
32
+ type: 'element';
33
+ jsxNode: JSXNode<string>;
34
+ nativeNode: NativeNode | null;
35
+ child: Atom | null;
36
+ sibling: Atom | null;
37
+ isSvg: boolean;
38
+ }
39
+ export interface ComponentAtom {
40
+ type: 'component';
41
+ jsxNode: JSXNode<JSXInternal.ComponentSetup> | Component;
42
+ nativeNode: NativeNode | null;
43
+ child: Atom | null;
44
+ sibling: Atom | null;
45
+ isSvg: boolean;
46
+ }
47
+ export type Atom = TextAtom | ElementAtom | ComponentAtom;
30
48
  export interface ComponentView {
31
49
  atom: Atom;
32
50
  host: NativeNode;
@@ -1,28 +1,27 @@
1
1
  import { AbstractType, InjectFlags, InjectionToken, Injector, Provider, ReflectiveInjector, Type } from '../di/_api';
2
- import { JSXTypeof, Key, Props } from './jsx-element';
2
+ import { Key, Props } from './jsx-element';
3
3
  import { ComponentView } from './_utils';
4
4
  import { JSXInternal } from './types';
5
5
  /**
6
6
  * Viewfly 组件管理类,用于管理组件的生命周期,上下文等
7
7
  */
8
- export declare class Component extends ReflectiveInjector implements JSXTypeof<JSXInternal.ComponentSetup> {
9
- private parentComponent;
10
- type: JSXInternal.ComponentSetup;
8
+ export declare class Component extends ReflectiveInjector {
9
+ private readonly parentComponent;
10
+ readonly type: JSXInternal.ComponentSetup;
11
11
  props: Props;
12
- key?: Key | undefined;
13
- $$typeOf: JSXInternal.ComponentSetup<any>;
12
+ readonly key?: Key | undefined;
14
13
  instance: JSXInternal.ComponentInstance<Props>;
15
- template: JSXInternal.JSXNode;
14
+ template: JSXInternal.ViewNode;
16
15
  changedSubComponents: Set<Component>;
17
16
  get dirty(): boolean;
18
17
  get changed(): boolean;
19
18
  $$view: ComponentView;
20
- unmountedCallbacks: LifeCycleCallback[];
21
- mountCallbacks: LifeCycleCallback[];
22
- propsChangedCallbacks: PropsChangedCallback<any>[];
23
- updatedCallbacks: LifeCycleCallback[];
24
- private updatedDestroyCallbacks;
25
- private propsChangedDestroyCallbacks;
19
+ unmountedCallbacks?: LifeCycleCallback[] | null;
20
+ mountCallbacks?: LifeCycleCallback[] | null;
21
+ propsChangedCallbacks?: PropsChangedCallback<any>[] | null;
22
+ updatedCallbacks?: LifeCycleCallback[] | null;
23
+ private updatedDestroyCallbacks?;
24
+ private propsChangedDestroyCallbacks?;
26
25
  protected _dirty: boolean;
27
26
  protected _changed: boolean;
28
27
  private unWatch?;
@@ -12,6 +12,7 @@ export declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode
12
12
  abstract listen<T = any>(node: ElementNode, type: string, callback: (ev: T) => any, isSvg: boolean): void;
13
13
  abstract unListen(node: ElementNode, type: string, callback: (ev: any) => any, isSvg: boolean): void;
14
14
  abstract remove(node: ElementNode | TextNode, isSvg: boolean): void;
15
+ abstract cleanChildren(node: ElementNode, isSvg: boolean): void;
15
16
  abstract syncTextContent(target: TextNode, content: string, isSvg: boolean): void;
16
17
  abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, isSvg: boolean): void;
17
18
  }
@@ -1,40 +1,20 @@
1
- import { Component } from './component';
2
1
  import { JSXInternal } from './types';
3
2
  import { ListenDelegate } from './_utils';
4
3
  export interface Props {
5
- children?: JSXInternal.JSXNode | JSXInternal.JSXNode[];
4
+ children?: JSXInternal.ViewNode | JSXInternal.ViewNode[];
6
5
  [key: string]: any;
7
6
  [key: symbol]: any;
8
7
  }
9
8
  export declare function Fragment(props: Props): () => any;
10
9
  export type Key = number | string;
11
- export declare function jsx(name: string, props: Props, key?: Key): JSXElement;
12
- export declare function jsx(setup: JSXInternal.ComponentSetup, props: Props, key?: Key): JSXComponent;
10
+ export declare function jsx(type: string | JSXInternal.ComponentSetup, props: Props, key?: Key): JSXNode;
13
11
  export declare const jsxs: typeof jsx;
14
- export interface JSXTypeof<T extends string | Symbol | JSXInternal.ComponentSetup = string | Symbol | JSXInternal.ComponentSetup> {
15
- $$typeOf: T;
16
- }
17
- export declare class JSXText implements JSXTypeof<Symbol> {
18
- text: string;
19
- $$typeOf: symbol;
20
- constructor(text: string);
21
- }
22
- export declare class JSXElement implements JSXTypeof<string> {
23
- type: string;
12
+ export interface JSXNode<T = string | JSXInternal.ComponentSetup> {
13
+ type: T;
24
14
  props: Props;
25
- key?: Key | undefined;
26
- $$typeOf: string;
27
- static createInstance(type: string, props: Props, key?: Key): JSXElement;
15
+ key?: Key;
28
16
  on?: Record<string, ListenDelegate>;
29
- constructor(type: string, props: Props, key?: Key | undefined);
30
- }
31
- export declare class JSXComponent implements JSXTypeof<JSXInternal.ComponentSetup> {
32
- type: JSXInternal.ComponentSetup;
33
- props: Props;
34
- factory: (parentComponent: Component) => Component;
35
- key?: Key | undefined;
36
- static createInstance(type: JSXInternal.ComponentSetup, props: Props, factory: (parentComponent: Component) => Component, key?: Key): JSXComponent;
37
- $$typeOf: JSXInternal.ComponentSetup<any>;
38
- constructor(type: JSXInternal.ComponentSetup, props: Props, factory: (parentComponent: Component) => Component, key?: Key | undefined);
39
- createInstance(parentComponent: Component): Component;
40
17
  }
18
+ export declare const JSXNodeFactory: {
19
+ createNode<T = string | JSXInternal.ComponentSetup<any>>(type: T, props: Props, key?: Key): JSXNode<T>;
20
+ };
@@ -1,3 +1,3 @@
1
1
  import { Props } from './jsx-element';
2
2
  import { JSXInternal } from './types';
3
- export declare function withMemo<T extends Props = Props>(canUseMemo: JSXInternal.ComponentInstance<T>['$useMemo'], render: () => JSXInternal.JSXNode): JSXInternal.ComponentInstance<T>;
3
+ export declare function withMemo<T extends Props = Props>(canUseMemo: JSXInternal.ComponentInstance<T>['$useMemo'], render: () => JSXInternal.ViewNode): JSXInternal.ComponentInstance<T>;
@@ -2,17 +2,17 @@ import { Key } from './jsx-element';
2
2
  import { ExtractInstanceType, DynamicRef } from './component';
3
3
  import { Scope } from '../di/injectable';
4
4
  import { NativeNode } from './injection-tokens';
5
- export type JSXNode = JSXInternal.JSXNode;
5
+ export type ViewNode = JSXInternal.ViewNode;
6
6
  export declare namespace JSXInternal {
7
7
  type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
8
8
  interface ComponentInstance<P> {
9
9
  $portalHost?: NativeNode;
10
- $render(): JSXNode;
10
+ $render(): ViewNode;
11
11
  $useMemo?(currentProps: P, prevProps: P): boolean;
12
12
  }
13
- type JSXNode = Element | JSXInternal.ElementClass | string | number | boolean | null | undefined | JSXNode[];
13
+ type ViewNode = Element | JSXInternal.ElementClass | string | number | boolean | null | undefined | Iterable<ViewNode>;
14
14
  interface ComponentSetup<P = any> {
15
- (props: P): (() => Element) | ComponentInstance<P>;
15
+ (props: P): (() => ViewNode) | ComponentInstance<P>;
16
16
  scope?: Scope;
17
17
  }
18
18
  type Element<P = any, C extends string | ComponentSetup<P> = string | ComponentSetup<P>> = C extends string ? IntrinsicElements[C] : (() => Element) | ComponentInstance<P>;