compelem 0.2.3-beta → 0.3.0-b1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compelem",
3
- "version": "0.2.3-beta",
3
+ "version": "0.3.0-b1",
4
4
  "description": "A modern, reactive, fast, lightweight and flexible lib for building web components",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -24,18 +24,18 @@
24
24
  "test": "rollup --config rollup.config.test.js --watch"
25
25
  },
26
26
  "devDependencies": {
27
- "@babel/preset-typescript": "^7.18.6",
27
+ "@babel/preset-typescript": "^7.26.0",
28
28
  "@rollup/plugin-commonjs": "^26.0.1",
29
29
  "@rollup/plugin-json": "4.1.0",
30
30
  "@rollup/plugin-node-resolve": "14.1.0",
31
31
  "@rollup/plugin-terser": "0.4.1",
32
- "@typescript-eslint/eslint-plugin": "5.37.0",
33
- "@typescript-eslint/parser": "^5.37.0",
32
+ "@typescript-eslint/eslint-plugin": "8.23.0",
33
+ "@typescript-eslint/parser": "^8.23.0",
34
34
  "autoprefixer": "^10.4.19",
35
35
  "bootstrap-icons": "^1.11.3",
36
- "eslint": "8.23.1",
37
- "eslint-config-prettier": "^8.5.0",
38
- "myfx": "^1.4.14",
36
+ "eslint": "9.19.0",
37
+ "eslint-config-prettier": "^10.0.1",
38
+ "myfx": "^1.7.0",
39
39
  "postcss": "^8.4.38",
40
40
  "prettier": "^2.8.3",
41
41
  "rollup-plugin-banner2": "1.2.2",
@@ -46,7 +46,7 @@
46
46
  "rollup-plugin-serve": "^2.0.1",
47
47
  "rollup-plugin-typescript2": "0.33.0",
48
48
  "sass": "^1.72.0",
49
- "tslib": "^2.6.2",
50
- "typescript": "^5.6.3"
49
+ "tslib": "^2.8.1",
50
+ "typescript": "^5.7.3"
51
51
  }
52
52
  }
package/reactive.d.ts CHANGED
@@ -3,26 +3,24 @@
3
3
  * @author holyhigh2
4
4
  */
5
5
  import { CompElem } from "./CompElem";
6
- import { IRenderContext } from "./render/RenderContext";
7
- import { Getter } from "./types";
6
+ import { CollectorType } from "./constants";
7
+ import { IView } from "./render/RenderContext";
8
+ import { Getter, Updater } from "./types";
8
9
  export declare const Collector: {
9
- startCss(comp: CompElem): void;
10
- endCss(): void;
11
- setCssUpdater(updater: Getter): void;
12
- startCompute(comp: CompElem): void;
13
- endCompute(): void;
14
- setComputedProp(updater: Getter): void;
15
- __computeCollecting: null;
16
- __computeUpdater: null;
17
- __cssCollecting: null;
18
- __cssUpdater: null;
10
+ collectWatch(comp: CompElem, updater: Getter, subPath: string): void;
11
+ startCollect(comp: CompElem, type: CollectorType): void;
12
+ setUpdater(updater: Getter): void;
13
+ endCollect(): void;
19
14
  __directiveQ: any[][];
20
15
  setDirectiveQ(val: any[]): void;
21
16
  popDirectiveQ(): any[];
22
- startRender(context: IRenderContext): void;
17
+ startRender(context: IView): void;
23
18
  endRender(component: CompElem): void;
24
19
  collect(prop: string): void;
25
20
  clear(): void;
21
+ __updater: null;
22
+ __collecting: null;
23
+ __collectType: number;
26
24
  __renderCollection: Set<string>;
27
25
  __renderContext: null;
28
26
  __renderCollecting: boolean;
@@ -37,3 +35,16 @@ export declare const Collector: {
37
35
  * @returns
38
36
  */
39
37
  export declare function reactive(obj: Record<string, any>, context: any): any;
38
+ export declare class Queue {
39
+ static watchSet: Set<Updater>;
40
+ static computedSet: Set<Updater>;
41
+ static cssSet: Set<Updater>;
42
+ static nextSet: Set<Updater>;
43
+ static nextPending: boolean;
44
+ static next: () => void;
45
+ static flush(): void;
46
+ static pushWatch(updater: Getter): void;
47
+ static pushComputed(updater: Getter): void;
48
+ static pushCss(updater: Getter): void;
49
+ static pushNext(updater: () => void): void;
50
+ }
@@ -1,37 +1,52 @@
1
- import { Directive } from "../directive/Directive";
2
1
  import { CompElem } from "../CompElem";
3
- import { ExpPos } from "../types";
4
- import { Template } from "./render";
5
- export interface IRenderContext {
6
- render(...args: any): Template | Template[] | void | ((...args: any[]) => (Template | Template[]));
7
- slotComponent: CompElem;
8
- renderComponent: CompElem;
9
- renderContext(...args: any): [NodeListOf<ChildNode>, Record<string, ExpPos>, Record<string, typeof this.__expPos | null>];
10
- updateContext(...args: any): void;
2
+ import { UpdatePoint } from "../types";
3
+ import { Template } from "./Template";
4
+ export interface IView {
5
+ /**
6
+ * 对比新的模板数据,更新变化点
7
+ * @param tmpl
8
+ */
9
+ updateView(tmpl: Template): void;
10
+ /**
11
+ * 构建模板返回nodes并更新 __updatePoints 属性
12
+ * @param tmpl
13
+ */
14
+ buildView(tmpl: Template): NodeListOf<ChildNode>;
11
15
  }
12
16
  /**
13
- * 为组件/指令提供渲染接口
14
- * @author holyhigh2
17
+ * 视图基类 为组件视图及指令子视图提供统一服务
18
+ * @param spuerClass
19
+ * @returns
15
20
  */
16
- export declare function RenderContext<T extends new (...args: any[]) => any>(spuerClass: T): {
21
+ export declare function View<T extends new (...args: any[]) => any>(spuerClass: T): {
17
22
  new (...args: any[]): {
18
23
  [x: string]: any;
24
+ __updatePoints: Array<UpdatePoint>;
19
25
  /**
20
- * 渲染实现
21
- */
22
- render(...args: any): Template | Template[] | void | ((...args: any[]) => (Template | Template[]));
23
- __expPos: Record<string, ExpPos>;
24
- __expPosMap: Record<string, Record<string, ExpPos> | null>;
25
- __directives: Record<string, Directive>; /**
26
- * 指令/组件所在的插槽所属组件
27
- */
28
- slotComponent: CompElem;
29
- /**
30
- * 渲染上下文所属组件
26
+ * 渲染上下文所属组件,仅用于指令
31
27
  */
32
28
  renderComponent: CompElem;
33
- renderContext(...args: any): [NodeListOf<ChildNode>, Record<string, ExpPos>, Record<string, Record<string, ExpPos> | null>];
34
- updateContext(...args: any): void;
35
- __updateExpPos(tmpl: Template, _expPos: Record<string, ExpPos>): void;
29
+ buildView(tmpl: Template): NodeListOf<ChildNode>;
30
+ updateView(tmpl: Template): void;
36
31
  };
37
32
  } & T;
33
+ declare const SubView_base: {
34
+ new (...args: any[]): {
35
+ [x: string]: any;
36
+ __updatePoints: Array<UpdatePoint>;
37
+ /**
38
+ * 渲染上下文所属组件,仅用于指令
39
+ */
40
+ renderComponent: CompElem;
41
+ buildView(tmpl: Template): NodeListOf<ChildNode>;
42
+ updateView(tmpl: Template): void;
43
+ };
44
+ } & ObjectConstructor;
45
+ /**
46
+ * 子视图,用于组件视图模板中的非指令子模版
47
+ */
48
+ export declare class SubView extends SubView_base {
49
+ tmpl: Template;
50
+ constructor(tmpl: Template);
51
+ }
52
+ export {};
@@ -0,0 +1,26 @@
1
+ import { CompElem } from "../CompElem";
2
+ /**
3
+ * 视图模板
4
+ * @author holyhigh2
5
+ */
6
+ export declare class Template {
7
+ strings: Array<string>;
8
+ vars: Array<any>;
9
+ constructor(strings: Array<string>, vars: Array<any>);
10
+ getKey(): string;
11
+ getKeys(): string[];
12
+ /**
13
+ * 追加tmpl
14
+ * 交接处模板进行合并
15
+ * @param tmpl
16
+ */
17
+ append(tmpl: Template): this;
18
+ /**
19
+ * 指定位置插入模板
20
+ * @param position 字符模板位置
21
+ * @param tmpl
22
+ * @returns
23
+ */
24
+ insert(position: number, tmpl: Template): this;
25
+ getHTML(comp: CompElem): string;
26
+ }
@@ -1,6 +1,7 @@
1
1
  import { CompElem } from "../CompElem";
2
- import { DirectiveWrapper } from "../directive/index";
3
- import { ExpPos } from "../types";
2
+ import { UpdatePoint } from "../types";
3
+ import { IView } from "./RenderContext";
4
+ import { Template } from "./Template";
4
5
  export declare const ATTR_PREFIX_EVENT = "@";
5
6
  export declare const ATTR_PREFIX_PROP = ".";
6
7
  export declare const ATTR_PREFIX_BOOLEAN = "?";
@@ -20,38 +21,21 @@ export declare const ATTR_REF = "ref";
20
21
  * 1. 在后面追加同内容注释节点,标记两个节点,以便变量可以进行绑定
21
22
  * 2. 在中间插入变量内容
22
23
  * 3. 只有表达式是一个指令时才能绑定依赖
24
+ * @param component
23
25
  * @param tmpl
24
- * @param slotArgs
25
- * @returns
26
+ * @returns [html,vars]
26
27
  */
27
- export declare function buildHTML(tmpl: Template | Template[]): string;
28
+ export declare function buildHTML(component: CompElem, tmpl: Template): [string, any[]];
28
29
  export declare const PLACEHOLDER_EXP: RegExp;
29
30
  /**
30
31
  * 构建模板为DOM结构
31
32
  * @param html
32
33
  */
33
- export declare function buildTmplate(expPos: Record<string, ExpPos>, directives: Array<DirectiveWrapper>, html: string, vars: any[], component: CompElem, slotArgs?: Record<string, any>, level?: number, expressionChain?: string): NodeListOf<ChildNode>;
34
+ export declare function buildTmplate(updatePoints: Array<UpdatePoint>, html: string, vars: any[], component: CompElem, viewContext: IView): NodeListOf<ChildNode>;
34
35
  export declare const DomUtil: {
35
36
  insertBefore: (node: Node, newNodes: any[]) => void;
36
37
  remove: (startNode: Node, endNode: Node) => void;
37
38
  };
38
- export declare class Template {
39
- strings: Array<string>;
40
- vars: Array<any>;
41
- key: string;
42
- constructor(strings: Array<string>, vars: Array<any>);
43
- getKey(): string;
44
- /**
45
- * 追加tmpl
46
- * 交接处模板进行合并
47
- * @param tmpl
48
- */
49
- append(tmpl: Template): this;
50
- /**
51
- * 获取html字符串
52
- */
53
- getHTML(): string;
54
- }
55
39
  /**
56
40
  * 标签函数,用于构建模板
57
41
  * @param strings
package/types.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * @author holyhigh2
3
3
  */
4
- import { Template } from "./render/render";
4
+ import { Template } from "./render/Template";
5
5
  export type Constructor<T> = new (...args: any[]) => T;
6
6
  export type Getter = () => any;
7
+ export type Updater = (...args: any[]) => any;
7
8
  /**
8
9
  * 插槽配置对象
9
10
  */
@@ -20,11 +21,17 @@ export declare enum DirectiveUpdateTag {
20
21
  UPDATE = "UPDATE",//对比更新
21
22
  APPEND = "APPEND"
22
23
  }
24
+ export type DefaultProps = Partial<{
25
+ css: Array<string | CSSStyleSheet>;
26
+ global: Record<string, any>;
27
+ [key: string]: Record<string, any>;
28
+ }>;
23
29
  /**
24
- * 模板中的表达式位置
30
+ * 视图更新点
25
31
  */
26
- export declare class ExpPos {
27
- index: string;
32
+ export declare class UpdatePoint {
33
+ key: string;
34
+ varIndex: number;
28
35
  value: any;
29
36
  isText: boolean;
30
37
  isTmpl: boolean;
@@ -36,6 +43,6 @@ export declare class ExpPos {
36
43
  attrTmpl: string;
37
44
  isProp: boolean;
38
45
  isToggleProp: boolean;
39
- eventName: string;
40
- constructor(varIndex: string | number, node: Node, attrName?: string, attrTmpl?: string);
46
+ isEvent: boolean;
47
+ constructor(varIndex: number, node: Node, attrName?: string, attrTmpl?: string);
41
48
  }