@joker.front/core 1.2.136
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/README.md +91 -0
- package/dist/bundle.es.js +3589 -0
- package/dist/bundle.js +3643 -0
- package/package.json +50 -0
- package/types/component.d.ts +216 -0
- package/types/components/component.d.ts +13 -0
- package/types/components/container.d.ts +15 -0
- package/types/components/template.d.ts +7 -0
- package/types/docs/build/docs.d.ts +1 -0
- package/types/docs/build/markdown-it-demo.d.ts +3 -0
- package/types/docs/build/utils.d.ts +3 -0
- package/types/docs/common/loading.d.ts +2 -0
- package/types/docs/main.d.ts +1 -0
- package/types/event-bus.d.ts +15 -0
- package/types/eventBus.d.ts +15 -0
- package/types/filter.d.ts +13 -0
- package/types/global.d.ts +13 -0
- package/types/hmr.d.ts +15 -0
- package/types/index.d.ts +10 -0
- package/types/observer/dep.d.ts +46 -0
- package/types/observer/index.d.ts +46 -0
- package/types/observer/watcher.d.ts +46 -0
- package/types/parser/command/code.d.ts +6 -0
- package/types/parser/command/condition.d.ts +22 -0
- package/types/parser/command/for.d.ts +23 -0
- package/types/parser/command/section.d.ts +8 -0
- package/types/parser/comment.d.ts +6 -0
- package/types/parser/component.d.ts +23 -0
- package/types/parser/element.d.ts +9 -0
- package/types/parser/index.d.ts +77 -0
- package/types/parser/parser.d.ts +82 -0
- package/types/parser/render.d.ts +86 -0
- package/types/parser/text.d.ts +6 -0
- package/types/parser/vnode.d.ts +180 -0
- package/types/props.d.ts +9 -0
- package/types/src/component.d.ts +216 -0
- package/types/src/event-bus.d.ts +15 -0
- package/types/src/filter.d.ts +13 -0
- package/types/src/hmr.d.ts +15 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/observer/dep.d.ts +46 -0
- package/types/src/observer/index.d.ts +46 -0
- package/types/src/observer/watcher.d.ts +46 -0
- package/types/src/parser/command/code.d.ts +6 -0
- package/types/src/parser/command/condition.d.ts +22 -0
- package/types/src/parser/command/for.d.ts +23 -0
- package/types/src/parser/command/section.d.ts +8 -0
- package/types/src/parser/comment.d.ts +6 -0
- package/types/src/parser/component.d.ts +23 -0
- package/types/src/parser/element.d.ts +9 -0
- package/types/src/parser/index.d.ts +77 -0
- package/types/src/parser/parser.d.ts +82 -0
- package/types/src/parser/render.d.ts +86 -0
- package/types/src/parser/text.d.ts +6 -0
- package/types/src/parser/vnode.d.ts +182 -0
- package/types/src/props.d.ts +9 -0
- package/types/src/utils/DI.d.ts +15 -0
- package/types/utils/DI.d.ts +15 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AST } from "@joker.front/ast";
|
|
2
|
+
import { Component } from "../component";
|
|
3
|
+
import { Render } from "./render";
|
|
4
|
+
import { VNode } from "./vnode";
|
|
5
|
+
export type NodeChangeType = "append" | "remove" | "update" | "after-enter" | "after-leave";
|
|
6
|
+
export type ObType = Component & Record<string, any>;
|
|
7
|
+
export declare class ParserTemplate {
|
|
8
|
+
asts: AST.Node[];
|
|
9
|
+
ob: ObType;
|
|
10
|
+
/** VNode 根 */
|
|
11
|
+
root: VNode.Root;
|
|
12
|
+
/** VNode ref索引集 */
|
|
13
|
+
refs: Record<string, Array<VNode.Node>>;
|
|
14
|
+
sleeped: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* node变更观察者
|
|
17
|
+
*/
|
|
18
|
+
nodeWatcherEvents: Record<string, Array<(node: VNode.Node, type: NodeChangeType, propertyKey?: string) => void>>;
|
|
19
|
+
/** VNode 渲染处理程序 (依赖注入) */
|
|
20
|
+
render: Render.IRender;
|
|
21
|
+
constructor(asts: AST.Node[], ob: ObType, parent?: VNode.Node);
|
|
22
|
+
parser(): void;
|
|
23
|
+
/**
|
|
24
|
+
* VNode挂载
|
|
25
|
+
* @param root
|
|
26
|
+
*/
|
|
27
|
+
mount(root: any): void;
|
|
28
|
+
/**
|
|
29
|
+
* 编译AST子集
|
|
30
|
+
* @param asts
|
|
31
|
+
* @param parent
|
|
32
|
+
*/
|
|
33
|
+
parserNodes(asts: AST.Node[], parent: VNode.Node, ob?: Component & Record<string, any>): void;
|
|
34
|
+
/**
|
|
35
|
+
* 添加ref
|
|
36
|
+
* @param refName ref值
|
|
37
|
+
* @param node VNode节点
|
|
38
|
+
*/
|
|
39
|
+
addRef(refKey: string, node: VNode.Node): void;
|
|
40
|
+
/**
|
|
41
|
+
* 移除Node所在ref
|
|
42
|
+
* @param node VNode节点
|
|
43
|
+
*/
|
|
44
|
+
removeRef(node: VNode.Node): void;
|
|
45
|
+
/**
|
|
46
|
+
* 添加节点变更观察者
|
|
47
|
+
* @param ref
|
|
48
|
+
* @param callBack
|
|
49
|
+
*/
|
|
50
|
+
addNodeWatcher(ref: string, callBack: (node: VNode.Node, type: NodeChangeType) => void): void;
|
|
51
|
+
/**
|
|
52
|
+
* 移除节点变更观察者
|
|
53
|
+
* @param ref
|
|
54
|
+
* @param callBack
|
|
55
|
+
*/
|
|
56
|
+
removeNodeWatcher(ref: string, callBack: Function): void;
|
|
57
|
+
/**
|
|
58
|
+
* 响应节点变更,通知观察者
|
|
59
|
+
* @param ref
|
|
60
|
+
* @param node
|
|
61
|
+
* @param nodeChangeType
|
|
62
|
+
*/
|
|
63
|
+
notifyNodeWatcher(ref: string, node: VNode.Node, nodeChangeType: NodeChangeType, propertyKey?: string): void;
|
|
64
|
+
sleep(node?: VNode.Node): void;
|
|
65
|
+
private weakup;
|
|
66
|
+
/**
|
|
67
|
+
* 销毁
|
|
68
|
+
*/
|
|
69
|
+
destroy(keepalive?: boolean): void;
|
|
70
|
+
reParser(asts: AST.Node[], keepalive?: boolean): void;
|
|
71
|
+
nodeTransition(node: VNode.Node | undefined, mode: "enter" | "leave", name?: string, callBack?: Function, type?: "transition" | "animation"): boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare function getFirstElement(node: VNode.Node): VNode.Element | undefined;
|
|
74
|
+
export declare function getNodeSupportTransition(node: VNode.Node): {
|
|
75
|
+
name: any;
|
|
76
|
+
type: any;
|
|
77
|
+
} | undefined;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AST } from "@joker.front/ast";
|
|
2
|
+
import { ObType, ParserTemplate, NodeChangeType } from ".";
|
|
3
|
+
import { Watcher } from "../observer/watcher";
|
|
4
|
+
import { VNode } from "./vnode";
|
|
5
|
+
export declare const GLOBAL_TAG = "Global";
|
|
6
|
+
export declare abstract class IParser<T extends AST.Node, N extends VNode.Node> {
|
|
7
|
+
/** ast集合 */
|
|
8
|
+
protected ast: T;
|
|
9
|
+
/** 数据源 会在component上进行属性新增 */
|
|
10
|
+
ob: ObType;
|
|
11
|
+
/** 父节点 */
|
|
12
|
+
protected parent: VNode.Node;
|
|
13
|
+
/** 外部处理(ParserTemplate) */
|
|
14
|
+
protected ext: ParserTemplate;
|
|
15
|
+
/** 当前转换节点ref标记 */
|
|
16
|
+
ref: string;
|
|
17
|
+
/** 当前AST解析 所产生的观察者 */
|
|
18
|
+
private watchers;
|
|
19
|
+
node?: N;
|
|
20
|
+
constructor(
|
|
21
|
+
/** ast集合 */
|
|
22
|
+
ast: T,
|
|
23
|
+
/** 数据源 会在component上进行属性新增 */
|
|
24
|
+
ob: ObType,
|
|
25
|
+
/** 父节点 */
|
|
26
|
+
parent: VNode.Node,
|
|
27
|
+
/** 外部处理(ParserTemplate) */
|
|
28
|
+
ext: ParserTemplate);
|
|
29
|
+
/**
|
|
30
|
+
* 上游主入口方法(初始化执行)
|
|
31
|
+
*/
|
|
32
|
+
abstract parser(): void;
|
|
33
|
+
protected beforeDestroy(keepalive?: boolean): void | boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 销毁流程
|
|
36
|
+
*/
|
|
37
|
+
destroy(keepalive?: boolean): void;
|
|
38
|
+
private destroyOtherData;
|
|
39
|
+
/**
|
|
40
|
+
* 销毁所有子集VNode
|
|
41
|
+
*/
|
|
42
|
+
protected destroyChildrens(keepalive?: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* 销毁所有子集VNode的watcher,为了防止延迟卸载时,无效通知广播
|
|
45
|
+
*/
|
|
46
|
+
protected destroyChildrensWatcher(nodeItem?: VNode.Node): void;
|
|
47
|
+
/**
|
|
48
|
+
* 插入自身节点
|
|
49
|
+
*/
|
|
50
|
+
protected appendNode(): void;
|
|
51
|
+
protected afterParser(): void;
|
|
52
|
+
/**
|
|
53
|
+
* 通知节点观察者
|
|
54
|
+
* @param type 通知类型
|
|
55
|
+
*/
|
|
56
|
+
protected notifyNodeWatcher(type: NodeChangeType, propertyKey?: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* 运行表达式方法,并返回运行后的值(不带观察者)
|
|
59
|
+
* @param express 表达式 string|function
|
|
60
|
+
* @param ob 数据源
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
protected runExpress(express: string, ob: any): any;
|
|
64
|
+
/**
|
|
65
|
+
* 运行表达式方法,并返回运行后的值(带观察者)
|
|
66
|
+
* @param express 表达式 string|function
|
|
67
|
+
* @param ob 数据源
|
|
68
|
+
* @param updateCallBack 更新回调
|
|
69
|
+
* @param forceCallBack 是否强制回调
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
protected runExpressWithWatcher(express: string | Function, ob: any, updateCallBack: (newVal: any, oldVal: any) => void, forceCallBack?: boolean): any;
|
|
73
|
+
/**
|
|
74
|
+
* 添加观察者
|
|
75
|
+
* @param watcher
|
|
76
|
+
*/
|
|
77
|
+
protected addWatch(watcher: Watcher<any>): void;
|
|
78
|
+
/**
|
|
79
|
+
* 清空所有观察者
|
|
80
|
+
*/
|
|
81
|
+
protected clearWatchers(): void;
|
|
82
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { VNode } from "./vnode";
|
|
2
|
+
import { IComponent } from "@joker.front/ast";
|
|
3
|
+
type TransitionType = "transition" | "animation";
|
|
4
|
+
export declare namespace Render {
|
|
5
|
+
/**
|
|
6
|
+
* 注入TagId
|
|
7
|
+
*/
|
|
8
|
+
const IRENDERIOCTAGID: unique symbol;
|
|
9
|
+
/**
|
|
10
|
+
* 备注:在渲染时执行appendNode,最终执行一次mount挂载
|
|
11
|
+
* 不会出现根目录append的场景,因为指令group会优先占位
|
|
12
|
+
*
|
|
13
|
+
* append 和 remove方法不会存在 parent的参数,因为一次挂载后
|
|
14
|
+
* 会存在关系,根据关系直接执行
|
|
15
|
+
* 上游调用也无需关心parent,特别是在watch周期内
|
|
16
|
+
*/
|
|
17
|
+
interface IRender {
|
|
18
|
+
/**
|
|
19
|
+
* 挂载
|
|
20
|
+
* @param root 挂载根
|
|
21
|
+
* 不限制root类型,为后面做多端兼容
|
|
22
|
+
*/
|
|
23
|
+
mount(root: any): void;
|
|
24
|
+
/**
|
|
25
|
+
* 添加节点
|
|
26
|
+
* @param node NodeInfo
|
|
27
|
+
*/
|
|
28
|
+
appendNode(node: VNode.Node): void;
|
|
29
|
+
/**
|
|
30
|
+
* 更新节点
|
|
31
|
+
* @param node NodeInfo
|
|
32
|
+
* @param propertyKey 更新属性名称
|
|
33
|
+
*/
|
|
34
|
+
updateNode(node: VNode.Node, propertyKey?: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* 删除节点
|
|
37
|
+
* @param {VNode.Node} node
|
|
38
|
+
* @param {VNode.Node} parent 如果为空则带表root跟节点下集
|
|
39
|
+
* @param {boolean} reserveOutPut 是否需要保留out产物
|
|
40
|
+
*/
|
|
41
|
+
removeNode(node: VNode.Node, reserveOutPut?: boolean): void;
|
|
42
|
+
/**
|
|
43
|
+
* 销毁,卸载DOM并释放变量
|
|
44
|
+
*/
|
|
45
|
+
destroy(): void;
|
|
46
|
+
/**
|
|
47
|
+
* element节点transition enter
|
|
48
|
+
*/
|
|
49
|
+
elementToEnter(node: VNode.Element, name: string, type?: TransitionType, callBack?: Function): void;
|
|
50
|
+
/**
|
|
51
|
+
* element节点transition leave
|
|
52
|
+
*/
|
|
53
|
+
elementToLeave(node: VNode.Element, name: string, type?: TransitionType, callBack?: Function): void;
|
|
54
|
+
/**
|
|
55
|
+
* 触发组件事件
|
|
56
|
+
* @param node
|
|
57
|
+
* @param eventName
|
|
58
|
+
* @returns false 则代表停止广播
|
|
59
|
+
*/
|
|
60
|
+
triggerEvent(node: VNode.Component, eventName: string, e: VNode.Event): void | false;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 默认Render,采用H5-DOM模式进行输出
|
|
64
|
+
*/
|
|
65
|
+
class DomRender implements IRender {
|
|
66
|
+
elements: DocumentFragment;
|
|
67
|
+
constructor();
|
|
68
|
+
mount(root: Element | VNode.Component): void;
|
|
69
|
+
appendNode(node: VNode.Node): void;
|
|
70
|
+
updateNode(node: VNode.Node, propertyKey?: string | undefined): void;
|
|
71
|
+
removeNode(node: VNode.Node, reserveOutPut?: boolean): void;
|
|
72
|
+
destroy(): void;
|
|
73
|
+
elementToEnter(node: VNode.Element, name: string, type?: TransitionType, callBack?: Function): void;
|
|
74
|
+
elementToLeave(node: VNode.Element, name: string, type?: TransitionType, callBack?: Function): void;
|
|
75
|
+
triggerEvent(node: VNode.Component<IComponent & Record<string, any>>, _eventName: string, _e: VNode.Event): void | false;
|
|
76
|
+
private transitionFrame;
|
|
77
|
+
private renderNode;
|
|
78
|
+
private initElementEvents;
|
|
79
|
+
private parserHtml;
|
|
80
|
+
private isCommandGroup;
|
|
81
|
+
private appendNodeChildren;
|
|
82
|
+
private setAttribute;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export declare function getTransitionClassName(transition: string, mode: "enter" | "leave", type: "from" | "active" | "to"): string;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { AST, IComponent } from "@joker.front/ast";
|
|
2
|
+
import { Component as ComponentClass } from "../component";
|
|
3
|
+
import { ObType } from ".";
|
|
4
|
+
import { SectionType } from "../component";
|
|
5
|
+
import { IParser } from "./parser";
|
|
6
|
+
/**
|
|
7
|
+
* 虚拟DOM
|
|
8
|
+
*
|
|
9
|
+
* 该控件分类区别于AST,分类是按照实际输出类型作为划分
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace VNode {
|
|
12
|
+
const PARSERKEY: unique symbol;
|
|
13
|
+
/**
|
|
14
|
+
* VNode 基类
|
|
15
|
+
*/
|
|
16
|
+
class Node {
|
|
17
|
+
parent?: Node | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 是否是静态节点,非动态节点。例如:element、text、comment等
|
|
20
|
+
*/
|
|
21
|
+
static?: boolean;
|
|
22
|
+
output?: any;
|
|
23
|
+
[PARSERKEY]?: IParser<AST.Node, VNode.Node>;
|
|
24
|
+
childrens?: Node[];
|
|
25
|
+
/**
|
|
26
|
+
* 当前节点是否睡眠
|
|
27
|
+
*/
|
|
28
|
+
sleep: boolean;
|
|
29
|
+
constructor(parent?: Node | undefined);
|
|
30
|
+
/**
|
|
31
|
+
* 上一个节点
|
|
32
|
+
*/
|
|
33
|
+
get prev(): Node | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* 下一个节点
|
|
36
|
+
*/
|
|
37
|
+
get next(): Node | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 匹配第一个符合要求的祖先元素
|
|
40
|
+
* @param match
|
|
41
|
+
* @param breakWhenVRoot 是否过滤到当前视图根时中断
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
closest<T extends VNode.Node = VNode.Node>(filter: (node: VNode.Node) => boolean | void, breakWhenVRoot?: boolean): T | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* 返回所有匹配的子元素
|
|
47
|
+
* @param filter 返回true则记录,返回false则跳过该元素的子集
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
find(filter: (node: VNode.Node) => boolean | void, childrens?: Array<VNode.Node>, _out?: Array<VNode.Node>): Array<VNode.Node>;
|
|
51
|
+
/**
|
|
52
|
+
* 是否包含
|
|
53
|
+
* @param filter 返回true则记录,返回false则跳过该元素的子集
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
contains(filter: (node: VNode.Node) => boolean | void, childrens?: Array<VNode.Node>): boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 根节点
|
|
60
|
+
*/
|
|
61
|
+
class Root<T extends IComponent = IComponent & Record<string, any>> extends Node {
|
|
62
|
+
childrens: Node[];
|
|
63
|
+
component: T;
|
|
64
|
+
constructor();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 文本类型节点
|
|
68
|
+
*/
|
|
69
|
+
class Text extends Node {
|
|
70
|
+
text: string;
|
|
71
|
+
static: boolean;
|
|
72
|
+
constructor(text: string, parent: Node);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Html节点
|
|
76
|
+
*/
|
|
77
|
+
class Html extends Node {
|
|
78
|
+
html: string;
|
|
79
|
+
static: boolean;
|
|
80
|
+
constructor(html: string, parent: Node);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 注释节点
|
|
84
|
+
*/
|
|
85
|
+
class Comment extends Node {
|
|
86
|
+
text: string;
|
|
87
|
+
static: boolean;
|
|
88
|
+
constructor(text: string, parent: Node);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Element节点
|
|
92
|
+
*/
|
|
93
|
+
class Element extends Node {
|
|
94
|
+
tagName: string;
|
|
95
|
+
static: boolean;
|
|
96
|
+
attributes: Record<string, any>;
|
|
97
|
+
childrens: Node[];
|
|
98
|
+
events: Array<[string, {
|
|
99
|
+
modifiers?: string[];
|
|
100
|
+
callBack: EventCallBack;
|
|
101
|
+
}]>;
|
|
102
|
+
/**
|
|
103
|
+
* 协助事件存储,用于存储辅助事件,例如outside等事件
|
|
104
|
+
*/
|
|
105
|
+
_assistEventCache?: Array<[string, (e: any) => void]>;
|
|
106
|
+
constructor(tagName: string, parent: Node);
|
|
107
|
+
}
|
|
108
|
+
type Event<T = undefined> = {
|
|
109
|
+
/**
|
|
110
|
+
* 事件名称
|
|
111
|
+
*/
|
|
112
|
+
eventName: string;
|
|
113
|
+
/**
|
|
114
|
+
* 原生event,对应运行平台
|
|
115
|
+
*/
|
|
116
|
+
event?: any;
|
|
117
|
+
/** 触发事件目标元素 */
|
|
118
|
+
target?: Node;
|
|
119
|
+
/** 阻止默认事件 */
|
|
120
|
+
preventDefault(): void;
|
|
121
|
+
/** 阻止事件传播 */
|
|
122
|
+
stopPropagation(): void;
|
|
123
|
+
/** 参数 */
|
|
124
|
+
data: T;
|
|
125
|
+
};
|
|
126
|
+
type EventCallBack<T = any> = (e: Event<T>) => void;
|
|
127
|
+
/**
|
|
128
|
+
* 组件节点
|
|
129
|
+
*/
|
|
130
|
+
class Component<T extends IComponent = IComponent & Record<string, any>> extends Node {
|
|
131
|
+
name?: string;
|
|
132
|
+
component: T;
|
|
133
|
+
events: Array<[string, {
|
|
134
|
+
modifiers?: string[];
|
|
135
|
+
callBack: EventCallBack;
|
|
136
|
+
}]>;
|
|
137
|
+
propValues: Record<string, any>;
|
|
138
|
+
keepalive?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* 当前组件第一个element vnode
|
|
141
|
+
*/
|
|
142
|
+
get firstElement(): Element | undefined;
|
|
143
|
+
private findElement;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 条件节点
|
|
147
|
+
*/
|
|
148
|
+
class Condition extends Node {
|
|
149
|
+
cmdName: AST.IfCommand["kind"];
|
|
150
|
+
result: boolean;
|
|
151
|
+
childrens: Node[];
|
|
152
|
+
isShow: boolean;
|
|
153
|
+
constructor(cmdName: AST.IfCommand["kind"], parent: Node);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* 列表节点,内部包含多组列表项
|
|
157
|
+
*/
|
|
158
|
+
class List extends Node {
|
|
159
|
+
childrens: ListItem[];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 循环列表项
|
|
163
|
+
*/
|
|
164
|
+
class ListItem extends Node {
|
|
165
|
+
ob: ObType;
|
|
166
|
+
childrens: Node[];
|
|
167
|
+
constructor(ob: ObType, parent: VNode.Node);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 插槽节点
|
|
171
|
+
*/
|
|
172
|
+
class RenderSection extends Node {
|
|
173
|
+
id: string;
|
|
174
|
+
params: any[];
|
|
175
|
+
section?: SectionType;
|
|
176
|
+
childrens: Node[];
|
|
177
|
+
ob?: ComponentClass & Record<string, any>;
|
|
178
|
+
constructor(idOrSection: string | SectionType, parent: Node);
|
|
179
|
+
}
|
|
180
|
+
}
|
package/types/props.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type PropValueType = String | ArrayConstructor | Number | Object | Function | Boolean;
|
|
2
|
+
export type PropTypeFullModel = {
|
|
3
|
+
type?: PropValueType | Array<PropValueType>;
|
|
4
|
+
required?: Boolean;
|
|
5
|
+
default?: any;
|
|
6
|
+
validate?: (val: any) => Boolean;
|
|
7
|
+
};
|
|
8
|
+
export type PropType = PropValueType | Array<PropValueType> | PropTypeFullModel;
|
|
9
|
+
export declare function getPropValue(propsData: Readonly<Record<string | symbol, any>>, key: string | symbol, propsType?: Record<string | symbol, any>): any;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { AST, IComponent, RENDER_HANDLER } from "@joker.front/ast";
|
|
2
|
+
import { NodeChangeType, ParserTemplate } from "./parser";
|
|
3
|
+
import { VNode } from "./parser/vnode";
|
|
4
|
+
import { PropType } from "./props";
|
|
5
|
+
declare const PROPS_DATA_KEY: unique symbol;
|
|
6
|
+
declare const PROPS_DATA_PROXY: unique symbol;
|
|
7
|
+
declare const PRIVATE_WATCHERS: unique symbol;
|
|
8
|
+
declare const EVENT_DATA_KEY: unique symbol;
|
|
9
|
+
declare const PARSER_TEMPLATE_TARGET: unique symbol;
|
|
10
|
+
export type TemplateType = Array<AST.Node> | ((h: typeof RENDER_HANDLER) => Array<AST.Node>);
|
|
11
|
+
export declare const SCOPE_ID: unique symbol;
|
|
12
|
+
export declare const JOKER_COMPONENT_TAG: unique symbol;
|
|
13
|
+
export type ComponentConstructor = typeof Component<any>;
|
|
14
|
+
export type ImportComponentConstructor = () => Promise<{
|
|
15
|
+
default: ComponentConstructor;
|
|
16
|
+
}>;
|
|
17
|
+
export type SectionType = {
|
|
18
|
+
asts: AST.Node[];
|
|
19
|
+
ob?: Component & Record<string, any>;
|
|
20
|
+
parser?: ParserTemplate;
|
|
21
|
+
params?: string[];
|
|
22
|
+
};
|
|
23
|
+
type DefaultKeyVal = Record<string | symbol, any>;
|
|
24
|
+
/**
|
|
25
|
+
* Joker组件
|
|
26
|
+
*/
|
|
27
|
+
export declare class Component<T extends DefaultKeyVal = {}> implements IComponent {
|
|
28
|
+
$sections: Record<string, SectionType>;
|
|
29
|
+
readonly isKeepAlive?: boolean | undefined;
|
|
30
|
+
static [JOKER_COMPONENT_TAG]: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* scopeId 配合css:Scoped
|
|
33
|
+
*/
|
|
34
|
+
[SCOPE_ID]?: string;
|
|
35
|
+
/**
|
|
36
|
+
* 可观察数据(具备劫持观察能力)
|
|
37
|
+
*/
|
|
38
|
+
model: DefaultKeyVal;
|
|
39
|
+
/**
|
|
40
|
+
* 渲染模板
|
|
41
|
+
*/
|
|
42
|
+
template?: TemplateType;
|
|
43
|
+
/**
|
|
44
|
+
* 挂载根
|
|
45
|
+
*/
|
|
46
|
+
$root: any;
|
|
47
|
+
/**
|
|
48
|
+
* 是否已睡眠
|
|
49
|
+
*/
|
|
50
|
+
isSleeped: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 可用的声明组件
|
|
53
|
+
*/
|
|
54
|
+
components: Record<string, ComponentConstructor | ImportComponentConstructor>;
|
|
55
|
+
/**
|
|
56
|
+
* props辅助约束
|
|
57
|
+
* @example { name:"默认值",age:Number }
|
|
58
|
+
* 可以配置默认值,也可以配置为约束,类型参考PropType
|
|
59
|
+
*/
|
|
60
|
+
propsOption?: Partial<Record<keyof T, PropType | any>>;
|
|
61
|
+
private [PROPS_DATA_KEY];
|
|
62
|
+
private [PARSER_TEMPLATE_TARGET]?;
|
|
63
|
+
private [PROPS_DATA_PROXY]?;
|
|
64
|
+
private [PRIVATE_WATCHERS];
|
|
65
|
+
private [EVENT_DATA_KEY];
|
|
66
|
+
/**
|
|
67
|
+
* @param propData prop参数
|
|
68
|
+
* @param sections 渲染部分区域
|
|
69
|
+
* @param isKeepAlive 是否要保持存活,启用时再destroy时只会销毁UI部分,不会销毁数据,直到使用destroy(true)才会销毁
|
|
70
|
+
*/
|
|
71
|
+
constructor(propData?: T, $sections?: Record<string, SectionType>, isKeepAlive?: boolean | undefined);
|
|
72
|
+
/**
|
|
73
|
+
* 主动声明接受的参数
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
get props(): Readonly<Partial<T>>;
|
|
77
|
+
/**
|
|
78
|
+
* 挂载
|
|
79
|
+
* @param root
|
|
80
|
+
*/
|
|
81
|
+
$mount(root: any | VNode.Component<IComponent>): this;
|
|
82
|
+
/**
|
|
83
|
+
* 节点动画,仅支持 element及组件节点
|
|
84
|
+
*/
|
|
85
|
+
$nodeTransition(nodeOrRef: string | VNode.Node, mode: "enter" | "leave", name?: string, callBack?: Function, type?: "transition" | "animation"): void;
|
|
86
|
+
/**
|
|
87
|
+
* 销毁
|
|
88
|
+
*/
|
|
89
|
+
$destroy(force?: boolean): void;
|
|
90
|
+
/**
|
|
91
|
+
* VNode ref索引集
|
|
92
|
+
*/
|
|
93
|
+
get $refs(): Readonly<Record<string, Array<VNode.Node>>>;
|
|
94
|
+
/**
|
|
95
|
+
* 根据ref获取单个VNode
|
|
96
|
+
*/
|
|
97
|
+
$getRef<T extends VNode.Node>(ref: string): T | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* 获取相同ref的VNode集合
|
|
100
|
+
*/
|
|
101
|
+
$getRefs<T extends VNode.Node>(ref: string): Array<T> | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* 单向同步prop值,并监听变更后重新同步
|
|
104
|
+
* @param propKey 需要观察同步的props key
|
|
105
|
+
* @param modelKey 要赋值的model key,不传案prop key 进行赋值
|
|
106
|
+
* @param convertVal 值转换方法
|
|
107
|
+
*/
|
|
108
|
+
$syncProp(propKey: keyof T): void;
|
|
109
|
+
$syncProp(propKey: keyof T, modelKey: string): void;
|
|
110
|
+
$syncProp(propKey: keyof T, convertVal: (val: any) => any): void;
|
|
111
|
+
$syncProp(propKey: keyof T, modelKey: string, convertVal: (val: any) => any): void;
|
|
112
|
+
/**
|
|
113
|
+
* 根节点(虚拟DOM)
|
|
114
|
+
*/
|
|
115
|
+
get $rootVNode(): Readonly<VNode.Root> | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* 添加节点变更监听
|
|
118
|
+
* @param ref ref标记
|
|
119
|
+
* @param callBack
|
|
120
|
+
* @returns 销毁方法
|
|
121
|
+
*/
|
|
122
|
+
$watchNode(ref: string, callBack: (node: VNode.Node, type: NodeChangeType, property?: string) => void): (() => void) | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* 观察值变更
|
|
125
|
+
* @param express
|
|
126
|
+
* @param callBack
|
|
127
|
+
* @returns 销毁watcher
|
|
128
|
+
*/
|
|
129
|
+
$watch(express: () => any, callBack: (nv?: any, ov?: any) => void): () => void;
|
|
130
|
+
/**
|
|
131
|
+
* 事件注册
|
|
132
|
+
* @param eventName
|
|
133
|
+
* @param callBack
|
|
134
|
+
*/
|
|
135
|
+
$on(eventName: string, callBack: VNode.EventCallBack): void;
|
|
136
|
+
/**
|
|
137
|
+
* 事件卸载
|
|
138
|
+
* @param eventName
|
|
139
|
+
* @param callBack
|
|
140
|
+
*/
|
|
141
|
+
$off(eventName: string, callBack?: VNode.EventCallBack): void;
|
|
142
|
+
/**
|
|
143
|
+
* 触发事件
|
|
144
|
+
* @param eventName 事件名称
|
|
145
|
+
* @param param 参数
|
|
146
|
+
* @param targetEvent event
|
|
147
|
+
*/
|
|
148
|
+
$trigger(eventName: string, param?: any, targetEvent?: VNode.Event): void;
|
|
149
|
+
/**
|
|
150
|
+
* 主动渲染(仅渲染,一般适用于模板区域的热更新使用/或动态装载等复杂场景)
|
|
151
|
+
* @param newTemplate 可指定新的模板,否则按照原模板
|
|
152
|
+
* @param keepalive 渲染新模板时,是否要保留之前的存活组件(高级用法)
|
|
153
|
+
* @returns
|
|
154
|
+
*/
|
|
155
|
+
$render(newTemplate?: TemplateType, keepalive?: boolean): void;
|
|
156
|
+
/**
|
|
157
|
+
* 生命周期函数(完成初始化)
|
|
158
|
+
*/
|
|
159
|
+
protected created(): void;
|
|
160
|
+
/**
|
|
161
|
+
* 生命周期函数(完成挂载)
|
|
162
|
+
*/
|
|
163
|
+
protected mounted(): void;
|
|
164
|
+
/**
|
|
165
|
+
* 生命周期函数(销毁前)
|
|
166
|
+
*/
|
|
167
|
+
protected beforeDestroy(): void;
|
|
168
|
+
/**
|
|
169
|
+
* 睡眠时,在启用keepalive属性时才会触发该周期
|
|
170
|
+
*/
|
|
171
|
+
protected sleeped(): void;
|
|
172
|
+
/**
|
|
173
|
+
* 唤醒时,在启用keepalive属性时才会触发该周期
|
|
174
|
+
*/
|
|
175
|
+
protected wakeup(): void;
|
|
176
|
+
/**
|
|
177
|
+
* 生命周期函数(销毁后)
|
|
178
|
+
*/
|
|
179
|
+
protected destroyed(): void;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* 注册全局组件
|
|
183
|
+
* @param componentsOrName 组件名/列表
|
|
184
|
+
* @param component 组件
|
|
185
|
+
*/
|
|
186
|
+
export declare function registerGlobalComponent(componentsOrName: Record<string, ComponentConstructor> | string, component?: ComponentConstructor): void;
|
|
187
|
+
/**
|
|
188
|
+
* 根据注册key获取组件
|
|
189
|
+
* @param name 组件名称
|
|
190
|
+
* @returns 组件
|
|
191
|
+
*/
|
|
192
|
+
export declare function getGlobalComponent(key: string): ComponentConstructor | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* 动态组件容器
|
|
195
|
+
*/
|
|
196
|
+
export declare class ComponentContainer extends Component<{
|
|
197
|
+
[key: string]: any;
|
|
198
|
+
name: string;
|
|
199
|
+
"transition-name": string;
|
|
200
|
+
}> {
|
|
201
|
+
template: never[];
|
|
202
|
+
private cache;
|
|
203
|
+
mounted(): void;
|
|
204
|
+
private propsVaule;
|
|
205
|
+
created(): void;
|
|
206
|
+
loadComponent(componentName?: string): Promise<void>;
|
|
207
|
+
beforeDestroy(): void;
|
|
208
|
+
removeCache(componentName?: string): void;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 虚拟模板容器,用于进行归组,作为组件配置属性
|
|
212
|
+
*/
|
|
213
|
+
export declare class Template extends Component {
|
|
214
|
+
template: () => AST.Command[];
|
|
215
|
+
}
|
|
216
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type EventCallBackItem = {
|
|
2
|
+
callBack: EventCallBackType;
|
|
3
|
+
once?: Boolean;
|
|
4
|
+
};
|
|
5
|
+
export type EventCallBackType = (e: {
|
|
6
|
+
stopPropagation: Function;
|
|
7
|
+
callTimes: Number;
|
|
8
|
+
}, params?: any) => boolean | void;
|
|
9
|
+
export declare class EventBus<T extends string> {
|
|
10
|
+
private eventDatas;
|
|
11
|
+
on(eventName: T, callBack: EventCallBackType): void;
|
|
12
|
+
once(eventName: T, callBack: EventCallBackType): void;
|
|
13
|
+
off(eventName: T, callBack?: EventCallBackType): void;
|
|
14
|
+
trigger(eventName: T, param?: any): false | undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type GlobalFilter = (...args: any[]) => string | void | undefined;
|
|
2
|
+
export declare const globalFilters: Record<string, GlobalFilter>;
|
|
3
|
+
/**
|
|
4
|
+
* 注册全局组件
|
|
5
|
+
* @param components 组件
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerGlobalFilter(filters: Record<string, GlobalFilter>): void;
|
|
8
|
+
/**
|
|
9
|
+
* 根据注册key获取组件
|
|
10
|
+
* @param name 组件名称
|
|
11
|
+
* @returns 组件
|
|
12
|
+
*/
|
|
13
|
+
export declare function getGlobalFilter(key: string): GlobalFilter | undefined;
|