@viewfly/core 0.0.14 → 0.0.16

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.
@@ -5,5 +5,5 @@ export interface ObjectChanges {
5
5
  }
6
6
  export declare const refKey = "ref";
7
7
  export declare function getObjectChanges(newProps: Record<string, any>, oldProps: Record<string, any>): ObjectChanges;
8
- export declare function classToString(config: unknown): any;
8
+ export declare function classToString(config: unknown): string;
9
9
  export declare function styleToObject(style: string | Record<string, any>): Record<string, any>;
@@ -81,9 +81,14 @@ function classToString(config) {
81
81
  return config;
82
82
  }
83
83
  else if (Array.isArray(config)) {
84
- return config.map(i => {
85
- return classToString(i);
86
- }).join(' ');
84
+ const classes = [];
85
+ for (const i of config) {
86
+ const v = classToString(i);
87
+ if (v) {
88
+ classes.push(v);
89
+ }
90
+ }
91
+ return classes.join(' ');
87
92
  }
88
93
  else if (typeof config === 'object') {
89
94
  if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
@@ -97,6 +102,7 @@ function classToString(config) {
97
102
  }
98
103
  return classes.join(' ');
99
104
  }
105
+ return '';
100
106
  }
101
107
  function styleToObject(style) {
102
108
  if (typeof style !== 'string') {
@@ -608,20 +614,12 @@ function inject(token, notFoundValue, flags) {
608
614
  return component.parentInjector.get(token, notFoundValue, flags);
609
615
  }
610
616
 
611
- const Fragment = function Fragment(props) {
617
+ function Fragment(props) {
612
618
  return () => {
613
619
  return props.children;
614
620
  };
615
- };
616
- function jsx(setup, props, key) {
617
- if (typeof setup === 'string') {
618
- return new JSXElement(setup, props, key);
619
- }
620
- return new JSXComponent(props, function (context, props) {
621
- return new Component(context, setup, props, key);
622
- });
623
621
  }
624
- function jsxs(setup, props, key) {
622
+ function jsx(setup, props, key) {
625
623
  if (typeof setup === 'string') {
626
624
  return new JSXElement(setup, props, key);
627
625
  }
@@ -629,6 +627,7 @@ function jsxs(setup, props, key) {
629
627
  return new Component(context, setup, props, key);
630
628
  });
631
629
  }
630
+ const jsxs = jsx;
632
631
  class JSXText {
633
632
  constructor(text) {
634
633
  this.text = text;
package/bundles/index.js CHANGED
@@ -82,9 +82,14 @@ function classToString(config) {
82
82
  return config;
83
83
  }
84
84
  else if (Array.isArray(config)) {
85
- return config.map(i => {
86
- return classToString(i);
87
- }).join(' ');
85
+ const classes = [];
86
+ for (const i of config) {
87
+ const v = classToString(i);
88
+ if (v) {
89
+ classes.push(v);
90
+ }
91
+ }
92
+ return classes.join(' ');
88
93
  }
89
94
  else if (typeof config === 'object') {
90
95
  if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
@@ -98,6 +103,7 @@ function classToString(config) {
98
103
  }
99
104
  return classes.join(' ');
100
105
  }
106
+ return '';
101
107
  }
102
108
  function styleToObject(style) {
103
109
  if (typeof style !== 'string') {
@@ -609,20 +615,12 @@ function inject(token, notFoundValue, flags) {
609
615
  return component.parentInjector.get(token, notFoundValue, flags);
610
616
  }
611
617
 
612
- const Fragment = function Fragment(props) {
618
+ function Fragment(props) {
613
619
  return () => {
614
620
  return props.children;
615
621
  };
616
- };
617
- function jsx(setup, props, key) {
618
- if (typeof setup === 'string') {
619
- return new JSXElement(setup, props, key);
620
- }
621
- return new JSXComponent(props, function (context, props) {
622
- return new Component(context, setup, props, key);
623
- });
624
622
  }
625
- function jsxs(setup, props, key) {
623
+ function jsx(setup, props, key) {
626
624
  if (typeof setup === 'string') {
627
625
  return new JSXElement(setup, props, key);
628
626
  }
@@ -630,6 +628,7 @@ function jsxs(setup, props, key) {
630
628
  return new Component(context, setup, props, key);
631
629
  });
632
630
  }
631
+ const jsxs = jsx;
633
632
  class JSXText {
634
633
  constructor(text) {
635
634
  this.text = text;
@@ -2,3 +2,4 @@ export * from './component';
2
2
  export * from './jsx-element';
3
3
  export * from './memo';
4
4
  export * from './root.component';
5
+ export * from './types';
@@ -1,29 +1,20 @@
1
1
  import { Provider, ReflectiveInjector, AbstractType, Type, InjectionToken, InjectFlags, Injector } from '@tanbo/di';
2
- import { Props, Key, JSXTypeof, JSXChildNode } from './jsx-element';
2
+ import { Props, Key, JSXTypeof } from './jsx-element';
3
+ import { JSXInternal } from './types';
3
4
  export declare class JSXComponent {
4
5
  props: Props;
5
6
  private factory;
6
7
  constructor(props: Props, factory: (injector: Component, props: Props) => Component);
7
8
  createInstance(injector: Component): Component;
8
9
  }
9
- export interface ComponentInstance<T> {
10
- $render(): JSXChildNode;
11
- $shouldUpdate?(currentProps: T, prevProps: T): unknown;
12
- }
13
- export interface Renderable {
14
- $render(): any;
15
- }
16
- export interface ComponentSetup<T extends Props<any> = Props<any>> {
17
- (props?: T): (() => JSXChildNode) | ComponentInstance<T>;
18
- }
19
10
  /**
20
11
  * Viewfly 组件管理类,用于管理组件的生命周期,上下文等
21
12
  */
22
13
  export declare class Component extends ReflectiveInjector implements JSXTypeof {
23
- type: ComponentSetup;
24
- props: Props<any>;
14
+ type: JSXInternal.ElementClass;
15
+ props: Props;
25
16
  key?: Key | undefined;
26
- $$typeOf: ComponentSetup<Props<any>>;
17
+ $$typeOf: JSXInternal.ElementClass<any>;
27
18
  destroyCallbacks: LifeCycleCallback[];
28
19
  mountCallbacks: LifeCycleCallback[];
29
20
  propsChangedCallbacks: PropsChangedCallback<any>[];
@@ -37,12 +28,12 @@ export declare class Component extends ReflectiveInjector implements JSXTypeof {
37
28
  private propsChangedDestroyCallbacks;
38
29
  private unWatch?;
39
30
  private isFirstRending;
40
- constructor(context: Injector, type: ComponentSetup, props: Props<any>, key?: Key | undefined);
31
+ constructor(context: Injector, type: JSXInternal.ElementClass, props: Props, key?: Key | undefined);
41
32
  is(target: JSXTypeof): boolean;
42
33
  addProvide<T>(providers: Provider<T> | Provider<T>[]): void;
43
34
  init(): {
44
- template: JSXChildNode;
45
- render: (newProps: Props, oldProps: Props) => JSXChildNode;
35
+ template: JSXInternal.JSXChildNode;
36
+ render: (newProps: Props, oldProps: Props) => JSXInternal.JSXChildNode;
46
37
  };
47
38
  markAsDirtied(): void;
48
39
  markAsChanged(): void;
@@ -55,7 +46,7 @@ export declare class Component extends ReflectiveInjector implements JSXTypeof {
55
46
  export interface LifeCycleCallback {
56
47
  (): void | (() => void);
57
48
  }
58
- export interface PropsChangedCallback<T extends Props<any>> {
49
+ export interface PropsChangedCallback<T extends Props> {
59
50
  (currentProps: T | null, oldProps: T | null): void | (() => void);
60
51
  }
61
52
  /**
@@ -106,7 +97,7 @@ export declare function onUpdated(callback: LifeCycleCallback): () => void;
106
97
  * }
107
98
  * ```
108
99
  */
109
- export declare function onPropsChanged<T extends Props<any>>(callback: PropsChangedCallback<T>): () => void;
100
+ export declare function onPropsChanged<T extends Props>(callback: PropsChangedCallback<T>): () => void;
110
101
  /**
111
102
  * 当组件销毁时调用回调函数
112
103
  * @param callback
@@ -115,9 +106,9 @@ export declare function onDestroy(callback: () => void): void;
115
106
  export interface RefListener<T> {
116
107
  (current: T): void | (() => void);
117
108
  }
118
- export type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends Renderable ? Omit<U, keyof ComponentInstance<any>> : U extends Function ? never : T;
109
+ export type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends JSXInternal.ComponentInstance<any> ? Omit<U, keyof JSXInternal.ComponentInstance<any>> : U extends Function ? never : T;
119
110
  export interface AbstractInstanceType<T extends Record<string, any>> {
120
- (): T & Renderable;
111
+ (): T & JSXInternal.ComponentInstance<any>;
121
112
  }
122
113
  export declare class Ref<T, U> {
123
114
  private callback;
@@ -1,18 +1,17 @@
1
- import { JSXComponent, ComponentSetup } from './component';
2
- export type JSXChildNode = JSXElement | JSXComponent | string | number | boolean | null | undefined | JSXChildNode[];
3
- export interface Props<T = JSXChildNode | JSXChildNode[]> {
4
- children?: T;
1
+ import { JSXComponent } from './component';
2
+ import { JSXInternal } from './types';
3
+ export interface Props {
4
+ children?: JSXInternal.JSXChildNode | JSXInternal.JSXChildNode[];
5
5
  [key: string]: any;
6
6
  [key: symbol]: any;
7
7
  }
8
- export declare const Fragment: (props: Props) => () => JSXChildNode | JSXChildNode[];
8
+ export declare function Fragment(props: Props): () => JSXInternal.JSXChildNode | JSXInternal.JSXChildNode[];
9
9
  export type Key = number | string;
10
- export declare function jsx<T extends JSXChildNode>(name: string, props: Props<T>, key?: Key): JSXElement;
11
- export declare function jsx<T extends JSXChildNode>(setup: ComponentSetup, props: Props<T>, key?: Key): JSXComponent;
12
- export declare function jsxs<T extends JSXChildNode[]>(name: string, props: Props<T>, key?: Key): JSXElement;
13
- export declare function jsxs<T extends JSXChildNode[]>(setup: ComponentSetup, props: Props<T>, key?: Key): JSXComponent;
10
+ export declare function jsx(name: string, props: Props, key?: Key): JSXElement;
11
+ export declare function jsx(setup: JSXInternal.ElementClass, props: Props, key?: Key): JSXComponent;
12
+ export declare const jsxs: typeof jsx;
14
13
  export interface JSXTypeof {
15
- $$typeOf: string | ComponentSetup;
14
+ $$typeOf: string | JSXInternal.ElementClass;
16
15
  is(target: JSXTypeof): boolean;
17
16
  }
18
17
  export declare class JSXText implements JSXTypeof {
@@ -27,10 +26,10 @@ export interface ListenDelegate {
27
26
  }
28
27
  export declare class JSXElement implements JSXTypeof {
29
28
  type: string;
30
- props: Props<any>;
29
+ props: Props;
31
30
  key?: Key | undefined;
32
31
  $$typeOf: string;
33
32
  on?: Record<string, ListenDelegate>;
34
- constructor(type: string, props: Props<any>, key?: Key | undefined);
33
+ constructor(type: string, props: Props, key?: Key | undefined);
35
34
  is(target: JSXTypeof): boolean;
36
35
  }
@@ -1,6 +1,3 @@
1
- import { JSXChildNode, Props } from './jsx-element';
2
- import { ComponentInstance } from './component';
3
- export interface ShouldUpdate<T extends Props> {
4
- (currentProps: T, prevProps: T): unknown;
5
- }
6
- export declare function withMemo<T extends Props = Props>(shouldUpdate: ShouldUpdate<T>, render: () => JSXChildNode): ComponentInstance<T>;
1
+ import { Props } from './jsx-element';
2
+ import { JSXInternal } from './types';
3
+ export declare function withMemo<T extends Props = Props>(shouldUpdate: JSXInternal.ComponentInstance<T>['$shouldUpdate'], render: () => JSXInternal.Element): JSXInternal.ComponentInstance<T>;
@@ -1,11 +1,12 @@
1
1
  import { Subject } from '@tanbo/stream';
2
2
  import { NullInjector } from '@tanbo/di';
3
- import { Component, ComponentSetup } from './component';
3
+ import { Component } from './component';
4
+ import { JSXInternal } from './types';
4
5
  /**
5
6
  * Viewfly 根组件,用于实现组件状态更新事件通知
6
7
  */
7
8
  export declare class RootComponent extends Component {
8
9
  changeEmitter: Subject<void>;
9
- constructor(factory: ComponentSetup, parentInjector?: NullInjector);
10
+ constructor(factory: JSXInternal.ElementClass, parentInjector?: NullInjector);
10
11
  markAsChanged(): void;
11
12
  }
@@ -0,0 +1,27 @@
1
+ import { Key, ExtractInstanceType, Ref } from './_api';
2
+ export declare namespace JSXInternal {
3
+ type ClassNames = string | Record<string, unknown> | ClassNames[];
4
+ interface ComponentInstance<P> {
5
+ $render(): JSXChildNode;
6
+ $shouldUpdate?(currentProps: P, prevProps: P): boolean;
7
+ }
8
+ type JSXChildNode = Element | ElementClass | string | number | boolean | null | undefined | JSXChildNode[];
9
+ interface Element<P = any, C extends string | ElementClass<P> = string | ElementClass<P>> {
10
+ }
11
+ interface IntrinsicAttributes {
12
+ key?: Key;
13
+ ref?: any;
14
+ }
15
+ interface RefAttributes<T> extends IntrinsicAttributes {
16
+ ref?: Ref<T, ExtractInstanceType<T>> | Ref<T, ExtractInstanceType<T>>[];
17
+ }
18
+ interface ElementClass<P = any> {
19
+ (props?: P): () => (JSXChildNode | ComponentInstance<P>);
20
+ }
21
+ interface ElementChildrenAttribute {
22
+ }
23
+ interface IntrinsicElements {
24
+ }
25
+ interface IntrinsicClassAttributes<T> extends RefAttributes<T> {
26
+ }
27
+ }
@@ -3,5 +3,4 @@ export * from '@tanbo/di';
3
3
  export * from './_utils/make-error';
4
4
  export * from './foundation/_api';
5
5
  export * from './model/_api';
6
- export * from './types';
7
6
  export * from './viewfly';
@@ -1,7 +1,6 @@
1
1
  import { Injector, Provider, ReflectiveInjector } from '@tanbo/di';
2
2
  import { NativeNode } from './foundation/_api';
3
- import { JSXComponent, JSXElement } from './model/_api';
4
- export type RootNode = JSXElement | JSXComponent;
3
+ import { JSXInternal } from './model/_api';
5
4
  /**
6
5
  * Viewfly 配置项
7
6
  */
@@ -11,7 +10,7 @@ export interface Config {
11
10
  /** 是否自动更新视图 */
12
11
  autoUpdate?: boolean;
13
12
  /** 根节点 */
14
- root: RootNode;
13
+ root: JSXInternal.JSXChildNode;
15
14
  /** 根组件的上下文 */
16
15
  context?: Injector;
17
16
  }
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs, Fragment, ViewTypes } from '@viewfly/core';
1
+ import { jsx, jsxs, Fragment, JSXInternal } from '@viewfly/core';
2
2
  import { NativeElements } from '@viewfly/platform-browser';
3
3
  /**
4
4
  * JSX namespace for usage with @jsxImportsSource directive
@@ -8,14 +8,16 @@ import { NativeElements } from '@viewfly/platform-browser';
8
8
  declare const jsxDEV: typeof jsx;
9
9
  export { jsx, jsxs, Fragment, jsxDEV };
10
10
  export declare namespace JSX {
11
- interface ElementClass extends ViewTypes.ElementClass {
11
+ interface Element extends JSXInternal.Element {
12
12
  }
13
- interface IntrinsicElements extends NativeElements, ViewTypes.IntrinsicElements {
13
+ interface ElementClass extends JSXInternal.ElementClass {
14
14
  }
15
- interface IntrinsicAttributes extends ViewTypes.IntrinsicAttributes {
15
+ interface IntrinsicElements extends NativeElements, JSXInternal.IntrinsicElements {
16
16
  }
17
- interface ElementChildrenAttribute extends ViewTypes.ElementChildrenAttribute {
17
+ interface IntrinsicAttributes extends JSXInternal.IntrinsicAttributes {
18
18
  }
19
- interface IntrinsicClassAttributes<T> extends ViewTypes.IntrinsicClassAttributes<T> {
19
+ interface ElementChildrenAttribute extends JSXInternal.ElementChildrenAttribute {
20
+ }
21
+ interface IntrinsicClassAttributes<T> extends JSXInternal.IntrinsicClassAttributes<T> {
20
22
  }
21
23
  }
@@ -6,8 +6,8 @@
6
6
  "build:lib": "rimraf index.esm.js index.js index.d.ts && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript && tsc index.ts -d"
7
7
  },
8
8
  "dependencies": {
9
- "@viewfly/core": "^0.0.12",
10
- "@viewfly/platform-browser": "^0.0.12"
9
+ "@viewfly/core": "*",
10
+ "@viewfly/platform-browser": "*"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@rollup/plugin-commonjs": "^25.0.3",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -23,8 +23,7 @@
23
23
  }
24
24
  },
25
25
  "scripts": {
26
- "build:lib": "rimraf bundles && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript && npm run build:jsx",
27
- "build:jsx": "cd jsx-runtime && npm run build:lib",
26
+ "build:lib": "rimraf bundles && rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript",
28
27
  "publish:lib": "npm run build:lib && npm publish --access=public"
29
28
  },
30
29
  "license": "MIT",
@@ -52,5 +51,5 @@
52
51
  "bugs": {
53
52
  "url": "https://github.com/viewfly/viewfly.git/issues"
54
53
  },
55
- "gitHead": "bc795457277616f7f448bae91360eb11baf1ad6b"
54
+ "gitHead": "424aee30ec55010f16a8e055222d42b07fae4b38"
56
55
  }
@@ -1,19 +0,0 @@
1
- import { Key, ExtractInstanceType, Ref, JSXComponent } from './model/_api';
2
- export declare namespace ViewTypes {
3
- type ClassNames = string | Record<string, unknown> | Array<string | Record<string, unknown>>;
4
- interface IntrinsicAttributes {
5
- key?: Key;
6
- ref?: any;
7
- }
8
- interface RefAttributes<T> extends IntrinsicAttributes {
9
- ref?: Ref<T, ExtractInstanceType<T>> | Ref<T, ExtractInstanceType<T>>[];
10
- }
11
- interface ElementClass extends JSXComponent {
12
- }
13
- interface ElementChildrenAttribute {
14
- }
15
- interface IntrinsicElements {
16
- }
17
- interface IntrinsicClassAttributes<T> extends IntrinsicAttributes {
18
- }
19
- }