compelem 0.0.0 → 0.1.1-beta
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/CHANGELOG.md +1 -0
- package/CompElem.d.ts +137 -0
- package/IComponent.d.ts +49 -0
- package/LICENSE +21 -0
- package/README.md +402 -0
- package/decorator/Decorator.d.ts +34 -0
- package/decorator/index.d.ts +32 -0
- package/decorators/computed.d.ts +10 -0
- package/decorators/event.d.ts +26 -0
- package/decorators/prop.d.ts +57 -0
- package/decorators/query.d.ts +26 -0
- package/decorators/state.d.ts +19 -0
- package/decorators/tag.d.ts +6 -0
- package/decorators/watch.d.ts +26 -0
- package/directive/Directive.d.ts +43 -0
- package/directive/index.d.ts +52 -0
- package/directives/Bind.d.ts +1 -0
- package/directives/Classes.d.ts +1 -0
- package/directives/ForEach.d.ts +2 -0
- package/directives/IfElse.d.ts +2 -0
- package/directives/IfTrue.d.ts +2 -0
- package/directives/Model.d.ts +5 -0
- package/directives/Show.d.ts +1 -0
- package/directives/Slot.d.ts +2 -0
- package/directives/Styles.d.ts +1 -0
- package/directives/Sync.d.ts +1 -0
- package/directives/When.d.ts +2 -0
- package/events/event.d.ts +13 -0
- package/events/extends.d.ts +2 -0
- package/index.d.ts +26 -0
- package/index.js +3119 -0
- package/package.json +51 -12
- package/reactive.d.ts +39 -0
- package/render/RenderContext.d.ts +37 -0
- package/render/render.d.ts +69 -0
- package/types.d.ts +41 -0
- package/utils.d.ts +5 -0
package/package.json
CHANGED
|
@@ -1,12 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "compelem",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "compelem",
|
|
3
|
+
"version": "0.1.1-beta",
|
|
4
|
+
"description": "A modern, reactive, fast, lightweight and flexible lib for building web components",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"author": "holyhigh2",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/holyhigh2/compelem"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/holyhigh2/compelem/issues",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"typescript",
|
|
17
|
+
"webcomponent",
|
|
18
|
+
"reactive"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"lint": "eslint src/**",
|
|
22
|
+
"build": "rollup --config",
|
|
23
|
+
"test": "rollup --config rollup.config.test.js --watch"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
27
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
28
|
+
"@rollup/plugin-json": "4.1.0",
|
|
29
|
+
"@rollup/plugin-node-resolve": "14.1.0",
|
|
30
|
+
"@rollup/plugin-terser": "0.4.1",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "5.37.0",
|
|
32
|
+
"@typescript-eslint/parser": "^5.37.0",
|
|
33
|
+
"autoprefixer": "^10.4.19",
|
|
34
|
+
"bootstrap-icons": "^1.11.3",
|
|
35
|
+
"eslint": "8.23.1",
|
|
36
|
+
"eslint-config-prettier": "^8.5.0",
|
|
37
|
+
"myfx": "^1.4.14",
|
|
38
|
+
"postcss": "^8.4.38",
|
|
39
|
+
"prettier": "^2.8.3",
|
|
40
|
+
"rollup-plugin-banner2": "1.2.2",
|
|
41
|
+
"rollup-plugin-clear": "2.0.7",
|
|
42
|
+
"rollup-plugin-copy": "3.4.0",
|
|
43
|
+
"rollup-plugin-livereload": "^2.0.5",
|
|
44
|
+
"rollup-plugin-scss": "^3.0.0",
|
|
45
|
+
"rollup-plugin-serve": "^2.0.1",
|
|
46
|
+
"rollup-plugin-typescript2": "0.33.0",
|
|
47
|
+
"sass": "^1.72.0",
|
|
48
|
+
"tslib": "^2.6.2",
|
|
49
|
+
"typescript": "^5.6.3"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/reactive.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 用于提供全局state状态管理
|
|
3
|
+
* @author holyhigh2
|
|
4
|
+
*/
|
|
5
|
+
import { CompElem } from "./CompElem";
|
|
6
|
+
import { IRenderContext } from "./render/RenderContext";
|
|
7
|
+
import { Getter } from "./types";
|
|
8
|
+
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;
|
|
19
|
+
__directiveQ: any[][];
|
|
20
|
+
setDirectiveQ(val: any[]): void;
|
|
21
|
+
popDirectiveQ(): any[];
|
|
22
|
+
startRender(context: IRenderContext): void;
|
|
23
|
+
endRender(component: CompElem): void;
|
|
24
|
+
collect(prop: string): void;
|
|
25
|
+
clear(): void;
|
|
26
|
+
__renderCollection: Set<string>;
|
|
27
|
+
__renderContext: null;
|
|
28
|
+
__renderCollecting: boolean;
|
|
29
|
+
__skipCheck: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 1. 初始化时obj都是普通对象
|
|
33
|
+
* 2. OBJECT_VAR_PATH 首次是普通对象
|
|
34
|
+
* 3. OBJECT_META_DATA 直接绑定代理对象
|
|
35
|
+
* @param obj
|
|
36
|
+
* @param context
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export declare function reactive(obj: Record<string, any>, context: any): any;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Directive } from "../directive/Directive";
|
|
2
|
+
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;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 为组件/指令提供渲染接口
|
|
14
|
+
* @author holyhigh2
|
|
15
|
+
*/
|
|
16
|
+
export declare function RenderContext<T extends new (...args: any[]) => any>(spuerClass: T): {
|
|
17
|
+
new (...args: any[]): {
|
|
18
|
+
[x: string]: any;
|
|
19
|
+
/**
|
|
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
|
+
* 渲染上下文所属组件
|
|
31
|
+
*/
|
|
32
|
+
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;
|
|
36
|
+
};
|
|
37
|
+
} & T;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { CompElem } from "../CompElem";
|
|
2
|
+
import { DirectiveWrapper } from "../directive/index";
|
|
3
|
+
import { ExpPos } from "../types";
|
|
4
|
+
export declare const ATTR_PREFIX_EVENT = "@";
|
|
5
|
+
export declare const ATTR_PREFIX_PROP = ".";
|
|
6
|
+
export declare const ATTR_PREFIX_BOOLEAN = "?";
|
|
7
|
+
export declare const ATTR_PREFIX_REF = "*";
|
|
8
|
+
export declare const ATTR_PROP_DELIMITER = ":";
|
|
9
|
+
export declare const ATTR_REF = "ref";
|
|
10
|
+
/**
|
|
11
|
+
* 提供渲染函数相关操作
|
|
12
|
+
* @author holyhigh2
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* 高性能dom生成及变量绑定算法
|
|
16
|
+
* 1. 使用占位符拼接HTML字符串,占位符与变量需要按照顺序对应
|
|
17
|
+
* 2. 插入dom片段,并遍历元素+注释节点, 搜索占位符
|
|
18
|
+
* 1. 按顺序遍历所有attr,发现一个属性值含有占位符时,标记节点及属性名,以便变量可以进行绑定( 如果key是事件/ref则内容仅允许一个占位符)
|
|
19
|
+
* 2. 如果是注释节点
|
|
20
|
+
* 1. 在后面追加同内容注释节点,标记两个节点,以便变量可以进行绑定
|
|
21
|
+
* 2. 在中间插入变量内容
|
|
22
|
+
* 3. 只有表达式是一个指令时才能绑定依赖
|
|
23
|
+
* @param tmpl
|
|
24
|
+
* @param slotArgs
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildHTML(tmpl: Template | Template[]): string;
|
|
28
|
+
export declare const PLACEHOLDER_EXP: RegExp;
|
|
29
|
+
/**
|
|
30
|
+
* 构建模板为DOM结构
|
|
31
|
+
* @param html
|
|
32
|
+
*/
|
|
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 const DomUtil: {
|
|
35
|
+
insertBefore: (node: Node, newNodes: any[]) => void;
|
|
36
|
+
remove: (startNode: Node, endNode: Node) => void;
|
|
37
|
+
};
|
|
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
|
+
/**
|
|
56
|
+
* 标签函数,用于构建模板
|
|
57
|
+
* @param strings
|
|
58
|
+
* @param vars
|
|
59
|
+
*/
|
|
60
|
+
export declare function html(strings: TemplateStringsArray, ...vars: any): Template;
|
|
61
|
+
export interface RefObject<T> {
|
|
62
|
+
current: T;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 使用初始值创建一个引用对象
|
|
66
|
+
* @param initValue
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export declare function createRef<T>(initValue?: any): RefObject<T>;
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author holyhigh2
|
|
3
|
+
*/
|
|
4
|
+
import { Template } from "./render/render";
|
|
5
|
+
export type Constructor<T> = new (...args: any[]) => T;
|
|
6
|
+
export type Getter = () => any;
|
|
7
|
+
/**
|
|
8
|
+
* 插槽配置对象
|
|
9
|
+
*/
|
|
10
|
+
export type SlotOptions = {
|
|
11
|
+
filter: Record<string, any> | Function;
|
|
12
|
+
props: Record<string, any>;
|
|
13
|
+
hook: Function;
|
|
14
|
+
};
|
|
15
|
+
export type TmplFn = (...args: any[]) => Template;
|
|
16
|
+
export declare enum DirectiveUpdateTag {
|
|
17
|
+
NONE = "NONE",//框架不处理
|
|
18
|
+
REMOVE = "REMOVE",//删除指令创建的节点
|
|
19
|
+
REPLACE = "REPLACE",//删除已有节点后插入
|
|
20
|
+
UPDATE = "UPDATE",//对比更新
|
|
21
|
+
APPEND = "APPEND"
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 模板中的表达式位置
|
|
25
|
+
*/
|
|
26
|
+
export declare class ExpPos {
|
|
27
|
+
index: string;
|
|
28
|
+
value: any;
|
|
29
|
+
isText: boolean;
|
|
30
|
+
isTmpl: boolean;
|
|
31
|
+
isDirective: boolean;
|
|
32
|
+
node: Node;
|
|
33
|
+
textNode: Node;
|
|
34
|
+
isComponent: boolean;
|
|
35
|
+
attrName: string;
|
|
36
|
+
attrTmpl: string;
|
|
37
|
+
isProp: boolean;
|
|
38
|
+
isToggleProp: boolean;
|
|
39
|
+
eventName: string;
|
|
40
|
+
constructor(varIndex: string | number, node: Node, attrName?: string, attrTmpl?: string);
|
|
41
|
+
}
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function showError(msg: string): void;
|
|
2
|
+
export declare function showTagError(tagName: string, msg: string): void;
|
|
3
|
+
export declare function showWarn(...args: unknown[]): void;
|
|
4
|
+
export declare function showTagWarn(tagName: string, msg: string): void;
|
|
5
|
+
export declare function toUpdatePath(varPath: string[]): string;
|