compelem 0.11.0-b1 → 0.20.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/CompElem.d.ts +147 -0
- package/IComponent.d.ts +65 -0
- package/README.md +48 -16
- package/constants.d.ts +27 -0
- package/decorator/Decorator.d.ts +35 -0
- package/decorator/index.d.ts +32 -0
- package/decorators/computed.d.ts +9 -0
- package/decorators/debounced.d.ts +1 -0
- package/decorators/event.d.ts +7 -0
- package/decorators/onced.d.ts +1 -0
- package/decorators/prop.d.ts +8 -0
- package/decorators/query.d.ts +8 -0
- package/decorators/state.d.ts +14 -0
- package/decorators/tag.d.ts +6 -0
- package/decorators/throttled.d.ts +1 -0
- package/decorators/watch.d.ts +9 -0
- package/directive/index.d.ts +11 -0
- package/directives/Bind.d.ts +5 -0
- package/directives/Classes.d.ts +5 -0
- package/directives/ForEach.d.ts +7 -0
- package/directives/HtmlC.d.ts +5 -0
- package/directives/HtmlD.d.ts +6 -0
- package/directives/IfElse.d.ts +7 -0
- package/directives/IfTrue.d.ts +7 -0
- package/directives/Model.d.ts +16 -0
- package/directives/Show.d.ts +9 -0
- package/directives/Slot.d.ts +7 -0
- package/directives/Styles.d.ts +5 -0
- package/directives/Sync.d.ts +6 -0
- package/directives/When.d.ts +22 -0
- package/events/event.d.ts +3 -0
- package/events/extends.d.ts +4 -0
- package/helpers.d.ts +18 -0
- package/index.d.ts +34 -0
- package/index.js +2 -2
- package/package.json +1 -1
- package/reactive.d.ts +26 -0
- package/render/CssTemplate.d.ts +12 -0
- package/render/Template.d.ts +31 -0
- package/render/render.d.ts +51 -0
- package/types.d.ts +180 -0
- package/utils.d.ts +16 -0
package/CompElem.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { IComponent } from "./IComponent";
|
|
2
|
+
import { CssTemplate } from "./render/CssTemplate";
|
|
3
|
+
import { Template } from "./render/Template";
|
|
4
|
+
import { DefaultProps, TmplFn, UpdatePoint } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* CompElem基类,意为组件元素。提供了基本内置属性及生命周期等必备接口
|
|
7
|
+
* 每个组件都需要继承自该类
|
|
8
|
+
*
|
|
9
|
+
* @author holyhigh2
|
|
10
|
+
*/
|
|
11
|
+
export declare class CompElem<T = HTMLElement> extends HTMLElement implements IComponent<T> {
|
|
12
|
+
#private;
|
|
13
|
+
static __l_globalRule: HTMLStyleElement;
|
|
14
|
+
static defaults(options: DefaultProps): void;
|
|
15
|
+
__updateTree: Array<UpdatePoint>;
|
|
16
|
+
__cssSheets: Array<CSSStyleSheet>;
|
|
17
|
+
_eventList: Array<[string, Function, Node, Function?]>;
|
|
18
|
+
__docoEventMap: Map<string, Function>;
|
|
19
|
+
__updateCssDeps: Array<string>;
|
|
20
|
+
__updateSubViewDeps: Map<string, Set<UpdatePoint>>;
|
|
21
|
+
__updateViewDeps: string[];
|
|
22
|
+
_watchUpdateMap: Record<string, Set<Function>>;
|
|
23
|
+
_watchDeepUpdateMap: Record<string, Set<Function>>;
|
|
24
|
+
_watchKeys: string[];
|
|
25
|
+
_watchKeysDeep: string[];
|
|
26
|
+
_watchUpdateSetInNextTick: Set<Function>;
|
|
27
|
+
_watchUpdateArgsInNextTick: Map<Function, Record<string, any>>;
|
|
28
|
+
_computedUpdateDeps: Map<string, Set<Function>>;
|
|
29
|
+
_computedUpdateSetInNextTick: Set<Function>;
|
|
30
|
+
_hasChangedPropOrStateMap: Map<string, Function>;
|
|
31
|
+
_hasSyncPropSet: Set<string>;
|
|
32
|
+
_hasShallowStateSet: Set<string>;
|
|
33
|
+
get [Symbol.toStringTag](): string;
|
|
34
|
+
get cid(): number;
|
|
35
|
+
get attrs(): Record<string, string>;
|
|
36
|
+
get props(): Record<string, any>;
|
|
37
|
+
get renderRoot(): T | undefined;
|
|
38
|
+
get renderRoots(): HTMLElement[];
|
|
39
|
+
get parentComponent(): CompElem | undefined;
|
|
40
|
+
get wrapperComponent(): CompElem | undefined;
|
|
41
|
+
get slotHooks(): Record<string, (...args: any[]) => Template>;
|
|
42
|
+
get styleSheets(): CSSStyleSheet[];
|
|
43
|
+
get globalStyleSheet(): CSSStyleSheet;
|
|
44
|
+
get isMounted(): boolean;
|
|
45
|
+
get slots(): Record<string, Array<Node>>;
|
|
46
|
+
/**
|
|
47
|
+
* 组件样式,CSSStyleSheet可动态变更
|
|
48
|
+
*/
|
|
49
|
+
static get styles(): Array<string | CSSStyleSheet>;
|
|
50
|
+
static get globalStyle(): string | undefined;
|
|
51
|
+
static get hostStyle(): string | CSSStyleSheet | undefined;
|
|
52
|
+
get styles(): Array<CssTemplate>;
|
|
53
|
+
constructor(...args: any[]);
|
|
54
|
+
insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet | null;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the root component in the parent chain, or itself if it's the top-level component.
|
|
57
|
+
*/
|
|
58
|
+
get rootComponent(): CompElem;
|
|
59
|
+
connectedCallback(): void;
|
|
60
|
+
disconnectedCallback(): void;
|
|
61
|
+
__bindEvents(): void;
|
|
62
|
+
__unbindEvents(): void;
|
|
63
|
+
beforeDestroyed(): void;
|
|
64
|
+
destroyed(): void;
|
|
65
|
+
get isDestroyed(): boolean;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
__init(): void;
|
|
68
|
+
propsReady(props: Record<string, any>): void;
|
|
69
|
+
render(): Template | null;
|
|
70
|
+
beforeMount(): void;
|
|
71
|
+
mounted(): void;
|
|
72
|
+
__onSlotChangeHook(e: Event): void;
|
|
73
|
+
slotChange(slot: HTMLSlotElement, name: string): void;
|
|
74
|
+
attributeChangedCallback(attributeName: string, oldValue: string | null, newValue: string | null): void;
|
|
75
|
+
/**
|
|
76
|
+
* 是否需要更新,可获取变更属性
|
|
77
|
+
* 返回true时更新
|
|
78
|
+
*/
|
|
79
|
+
shouldUpdate(changed: Record<string, any>): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* 1. 调用render
|
|
82
|
+
* 2. 更新@query/all
|
|
83
|
+
* 3. 更新ref
|
|
84
|
+
* 4. 更新prop到attr的映射
|
|
85
|
+
* @param changed
|
|
86
|
+
*/
|
|
87
|
+
updated(changed: Record<string, any>): void;
|
|
88
|
+
/**
|
|
89
|
+
* 由监控变量调用
|
|
90
|
+
* @param stateKey
|
|
91
|
+
* @param ov
|
|
92
|
+
* @param rootStateKey 如果是对象内部属性变更,会返回根属性名
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
_notify(ov: any, chain: string[], subNewValue?: any, subOldValue?: any): void;
|
|
96
|
+
_requestWatchUpdate(newValue: any, oldValue: any, fullPath: string): void;
|
|
97
|
+
_requestComputedUpdate(fullPath: string): void;
|
|
98
|
+
_updateProps(props: Record<string, any>): void;
|
|
99
|
+
_wrapperProp: Record<string, string>;
|
|
100
|
+
_initProps(props: Record<string, any>, attrs?: Record<string, any>): void;
|
|
101
|
+
/**
|
|
102
|
+
* 绑定slot标签,render时调用
|
|
103
|
+
*/
|
|
104
|
+
_bindSlot(slot: HTMLSlotElement, name: string, props: Record<string, any>): void;
|
|
105
|
+
_bindSlotHook(name: string, hook: (...args: any[]) => Template): void;
|
|
106
|
+
_updateSlot(name: string, propName?: string, value?: any): void;
|
|
107
|
+
_asyncDirectives: WeakMap<TmplFn, any>;
|
|
108
|
+
renderAsync(cbk: TmplFn, ...args: any[]): void;
|
|
109
|
+
__attrChanged(name: string, oldValue: string | null, newValue: string | null): void;
|
|
110
|
+
_regWrapper(wrapperComponent: CompElem): void;
|
|
111
|
+
_regSubViewDeps(props: string[], up: UpdatePoint): void;
|
|
112
|
+
_getPrivateData(): Record<string, any>;
|
|
113
|
+
/**
|
|
114
|
+
* 抛出自定义事件
|
|
115
|
+
* @param evName 事件名称
|
|
116
|
+
* @param args 自定义参数
|
|
117
|
+
*/
|
|
118
|
+
emit(evName: string, arg?: Record<string, any>, options?: {
|
|
119
|
+
event?: Event;
|
|
120
|
+
bubbles?: boolean;
|
|
121
|
+
composed?: boolean;
|
|
122
|
+
}): void;
|
|
123
|
+
/**
|
|
124
|
+
* 在root上绑定事件
|
|
125
|
+
* @param evName
|
|
126
|
+
* @param hook
|
|
127
|
+
* @returns 函数钩子,用于卸载
|
|
128
|
+
*/
|
|
129
|
+
on(evName: string, hook: (e: Event) => void): any;
|
|
130
|
+
/**
|
|
131
|
+
* 从root上移除事件
|
|
132
|
+
* @param evName
|
|
133
|
+
* @param hook on函数返回的钩子,可选。为空时移除所有evName事件
|
|
134
|
+
*/
|
|
135
|
+
off(evName: string, hook?: (e: Event) => void): void;
|
|
136
|
+
addEvent(node: Node, evName: string, hook: (e: Event) => void): any;
|
|
137
|
+
removeEvent(node: Node, evName: string, hook?: (e: Event) => void): void;
|
|
138
|
+
/**
|
|
139
|
+
* 下一帧执行
|
|
140
|
+
* @param cbk
|
|
141
|
+
*/
|
|
142
|
+
nextTick(cbk: () => void): void;
|
|
143
|
+
/**
|
|
144
|
+
* 强制更新一次视图
|
|
145
|
+
*/
|
|
146
|
+
forceUpdate(): void;
|
|
147
|
+
}
|
package/IComponent.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CssTemplate } from "./render/CssTemplate";
|
|
2
|
+
import { Template } from "./render/Template";
|
|
3
|
+
/**
|
|
4
|
+
* 组件接口
|
|
5
|
+
* 定义组件属性、生命周期及方法
|
|
6
|
+
* @author holyhigh2
|
|
7
|
+
*/
|
|
8
|
+
export interface IComponent<T = HTMLElement> {
|
|
9
|
+
get cid(): number;
|
|
10
|
+
get attrs(): Record<string, string>;
|
|
11
|
+
get props(): Record<string, any>;
|
|
12
|
+
get renderRoot(): T | undefined;
|
|
13
|
+
get renderRoots(): HTMLElement[];
|
|
14
|
+
get rootComponent(): HTMLElement | undefined;
|
|
15
|
+
get parentComponent(): HTMLElement | undefined;
|
|
16
|
+
get wrapperComponent(): HTMLElement | undefined;
|
|
17
|
+
get slots(): Record<string, Array<Node>>;
|
|
18
|
+
get slotHooks(): Record<string, (...args: any[]) => Template>;
|
|
19
|
+
get styleSheets(): CSSStyleSheet[];
|
|
20
|
+
get globalStyleSheet(): CSSStyleSheet;
|
|
21
|
+
get isMounted(): boolean;
|
|
22
|
+
get styles(): Array<CssTemplate>;
|
|
23
|
+
propsReady(props: Record<string, any>): void;
|
|
24
|
+
render(): Template | null;
|
|
25
|
+
beforeMount(): void;
|
|
26
|
+
mounted(): void;
|
|
27
|
+
connectedCallback(): void;
|
|
28
|
+
disconnectedCallback(): void;
|
|
29
|
+
beforeDestroyed(): void;
|
|
30
|
+
destroyed(): void;
|
|
31
|
+
shouldUpdate(changed: Record<string, any>): boolean;
|
|
32
|
+
updated(changed: Record<string, any>): void;
|
|
33
|
+
slotChange(slot: HTMLSlotElement, slotName: string): void;
|
|
34
|
+
attributeChangedCallback(attributeName: string, oldValue: string | null, newValue: string | null): void;
|
|
35
|
+
/**
|
|
36
|
+
* 抛出自定义事件
|
|
37
|
+
* @param evName 事件名称
|
|
38
|
+
* @param args 自定义参数
|
|
39
|
+
*/
|
|
40
|
+
emit(evName: string, arg: Record<string, any>, options?: {
|
|
41
|
+
event?: Event;
|
|
42
|
+
bubbles?: boolean;
|
|
43
|
+
composed?: boolean;
|
|
44
|
+
}): void;
|
|
45
|
+
/**
|
|
46
|
+
* 在root上绑定事件
|
|
47
|
+
* @param evName
|
|
48
|
+
* @param hook
|
|
49
|
+
*/
|
|
50
|
+
on(evName: string, hook: (e: Event) => void): void;
|
|
51
|
+
/**
|
|
52
|
+
* 下一帧执行
|
|
53
|
+
* @param cbk
|
|
54
|
+
*/
|
|
55
|
+
nextTick(cbk: () => void): void;
|
|
56
|
+
/**
|
|
57
|
+
* 强制更新一次视图
|
|
58
|
+
*/
|
|
59
|
+
forceUpdate(): void;
|
|
60
|
+
/**
|
|
61
|
+
* 向组件插入样式表,没有shadowDOM的组件调用无效
|
|
62
|
+
* @param sheet
|
|
63
|
+
*/
|
|
64
|
+
insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet | null;
|
|
65
|
+
}
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
一个现代化、响应式、快速、轻量的WebComponent开发库。为开发者提供丰富、灵活、可扩展的声明式接口
|
|
3
3
|
|
|
4
4
|
## 概览
|
|
5
|
-
CompElem 基于 Class
|
|
5
|
+
CompElem 基于 Class 进行构建,该模型允许开发者使用装饰器进行声明式编码并可使用继承、扩展等高级特性,其核心特性包括:
|
|
6
6
|
- 类JSX的原生模板系统
|
|
7
7
|
- 丰富的装饰器及指令
|
|
8
8
|
- 可选的生命周期
|
|
@@ -45,10 +45,10 @@ export class PageTest extends CompElem {
|
|
|
45
45
|
//动态样式
|
|
46
46
|
get styles() {
|
|
47
47
|
return [
|
|
48
|
-
|
|
48
|
+
css`h2,p,i,h3{
|
|
49
49
|
background-image:${this.color};
|
|
50
50
|
}`,
|
|
51
|
-
|
|
51
|
+
css`h2,p,i,h3{
|
|
52
52
|
filter:hue-rotate(${this.rotation}deg);
|
|
53
53
|
}`,
|
|
54
54
|
]
|
|
@@ -106,6 +106,10 @@ export class PageTest extends CompElem {
|
|
|
106
106
|
render(): Template{
|
|
107
107
|
return html`<div>Hello CompElem</div>`
|
|
108
108
|
}
|
|
109
|
+
//对于无需内部样式的组件(如容器类)可返回null,此时不会创建Shadow DOM
|
|
110
|
+
render(){
|
|
111
|
+
return null
|
|
112
|
+
}
|
|
109
113
|
```
|
|
110
114
|
- ### 视图模板-属性表达式
|
|
111
115
|
|
|
@@ -132,20 +136,38 @@ export class PageTest extends CompElem {
|
|
|
132
136
|
- kebab 短横线
|
|
133
137
|
- snake 下划线
|
|
134
138
|
|
|
139
|
+
- ### 无视图
|
|
140
|
+
对于无体组件无需定义渲染函数,常用于layout、grid等结构控制相关组件。无视图组件仅支持global及host样式,如
|
|
141
|
+
```ts
|
|
142
|
+
static get hostStyle(): string {
|
|
143
|
+
return `
|
|
144
|
+
l-main{
|
|
145
|
+
display: block;
|
|
146
|
+
flex: 1;
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
同样,无视图组件的renderRoot/renderRoots/...等属性都为空
|
|
153
|
+
|
|
135
154
|
- ### 样式
|
|
136
|
-
|
|
155
|
+
使用静态函数定义组件样式或全局样式(如弹框),对于包裹在上级组件内的动态样式(如:hover)时,可通过hostStyles进行指定
|
|
137
156
|
```ts
|
|
138
157
|
static get styles(): Array<string | CSSStyleSheet> {
|
|
139
158
|
return [];
|
|
140
159
|
}
|
|
141
|
-
static get
|
|
142
|
-
return
|
|
160
|
+
static get globalStyle(): string {
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
static get hostStyle(): string {
|
|
164
|
+
return '';
|
|
143
165
|
}
|
|
144
166
|
```
|
|
145
167
|
对于需要动态控制 host 元素样式可以使用组件实例 getter
|
|
146
168
|
```ts
|
|
147
169
|
get styles(){
|
|
148
|
-
return [
|
|
170
|
+
return [css`:host{
|
|
149
171
|
${this.border?'border: 1px solid rgb(var(--l-color-border-secondary)); ':''}
|
|
150
172
|
}`]
|
|
151
173
|
}
|
|
@@ -171,7 +193,7 @@ export class PageTest extends CompElem {
|
|
|
171
193
|
}
|
|
172
194
|
```
|
|
173
195
|
|
|
174
|
-
属性可以在组件内修改但默认不会同步父组件,除非显式指定`sync`或自行 emit update 事件
|
|
196
|
+
属性可以在组件内修改但默认不会同步父组件,除非显式指定`sync`或自行 emit `update:xxx` 事件
|
|
175
197
|
全部注解参数见 `PropOption`
|
|
176
198
|
|
|
177
199
|
- ### 状态
|
|
@@ -237,19 +259,26 @@ export class PageTest extends CompElem {
|
|
|
237
259
|
- `readonly` rootComponent 根组件引用
|
|
238
260
|
- `readonly` parentComponent 父组件引用,可能为空
|
|
239
261
|
- `readonly` wrapperComponent 包装(组件所在视图归属)组件引用,可能为空
|
|
240
|
-
- `readonly` renderRoot/renderRoots
|
|
241
|
-
- `readonly` shadowRoot 阴影DOM
|
|
262
|
+
- `readonly` renderRoot/renderRoots 渲染根元素/渲染根元素列表,可能为空
|
|
263
|
+
- `readonly` shadowRoot 阴影DOM,可能为空
|
|
242
264
|
- `readonly` slots 插槽元素映射
|
|
243
265
|
- `readonly` slotHooks 动态插槽钩子映射
|
|
244
|
-
- `readonly`
|
|
266
|
+
- `readonly` styleSheets 组件样式对象列表
|
|
267
|
+
- `readonly` globalStyleSheet 通过静态getter创建的全局样式表对象,所有实例共享
|
|
245
268
|
- `readonly` attrs 组件特性
|
|
246
269
|
- `readonly` props 组件属性
|
|
270
|
+
- `readonly` isMounted 组件是否已挂载
|
|
271
|
+
- `readonly` isDestroyed 组件是否已销毁
|
|
247
272
|
- slotComponent 所在插槽组件
|
|
248
273
|
- on(evName: string, hook: (e: Event) => void) 在root元素上绑定事件
|
|
274
|
+
- off(evName: string, hook?: (e: Event) => void) 在root元素上卸载事件
|
|
275
|
+
- addEvent(node: Node, evName: string, hook: (e: Event) => void) 在指定元素上绑定事件
|
|
276
|
+
- removeEvent(node: Node, evName: string, hook?: (e: Event) => void) 在指定元素上卸载事件
|
|
249
277
|
- emit(evName: string, arg: Record<string, any>, options?: {event?: Event;bubbles?: boolean;composed?: boolean;}) 抛出自定义事件
|
|
250
278
|
- nextTick(cbk: () => void) 下一帧执行函数
|
|
251
279
|
- forceUpdate() 强制更新一次视图
|
|
252
|
-
- insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet
|
|
280
|
+
- insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet 向组件ShadowDOM插入样式表
|
|
281
|
+
- destroy() 销毁组件
|
|
253
282
|
|
|
254
283
|
## 组件渲染流程
|
|
255
284
|
|
|
@@ -331,7 +360,7 @@ return html` <l-tooltip>
|
|
|
331
360
|
"content"
|
|
332
361
|
)}
|
|
333
362
|
</l-tooltip>`;
|
|
334
|
-
```
|
|
363
|
+
```
|
|
335
364
|
2. 通过元素注入
|
|
336
365
|
可在非CompElem环境中使用,比如将组件嵌入到React/Vue环境中使用
|
|
337
366
|
```html
|
|
@@ -379,7 +408,8 @@ return html` <l-tooltip>
|
|
|
379
408
|
| ------- | --------- | ----------------------------------------------------------- | ------------------------------------------------------ |
|
|
380
409
|
| bind | TAG | 绑定属性/特性到标签上,根据标签类型及组件 prop 定义自动判断 | `<div a="b" ${bind(obj)}>` |
|
|
381
410
|
| show | TAG | 隐藏/显示标签(基于 display) | `<div a="b" ${show(visible)}>` |
|
|
382
|
-
| model | TAG | 双向绑定 | `<div a="b" ${model(xx,modelPath?)}>`
|
|
411
|
+
| model | TAG | 双向绑定 | `<div a="b" ${model(xx,modelPath?)}>`
|
|
412
|
+
| sync | PROP | 类似Model,实现属性的同步跟踪 | `<l-dialog .visible="${sync(this.visible)}">` |
|
|
383
413
|
| classes | CLASS | 绑定样式类属性,支持对象/数组/字符串。可以和静态字符混用 | `<div class="otherClass ${classes(obj)}>"` |
|
|
384
414
|
| styles | STYLE | 绑定样式规则属性,支持对象/字符串。可以和静态字符混用 | `<div style="a:b;${styles(obj)}>"` |
|
|
385
415
|
| forEach | TEXT/SLOT | 输出循环结构 | `...>${forEach(ary,(item)=>html`...`)}<...` |
|
|
@@ -388,6 +418,7 @@ return html` <l-tooltip>
|
|
|
388
418
|
| when | TEXT/SLOT | 多条件分支,支持 switch/ifelse 两种模式 | ` ...>${when(condition,{c1:()=>html``,c2:...})}<... ` |
|
|
389
419
|
| slot | SLOT | 动态插槽 | ` ...>${slot((args) => html``)}<... ` |
|
|
390
420
|
| htmlD | TAG | 向指定元素插入HTML内容 | `<div a="b" ${htmlD('<b>1</b>')}>` |
|
|
421
|
+
| htmlC | TEXT/SLOT | 向指定文本位置插入指定HTML内容 | `...>${htmlC('<b>1</b>')}><...` |
|
|
391
422
|
|
|
392
423
|
## 装饰器 Decorator
|
|
393
424
|
|
|
@@ -396,11 +427,12 @@ return html` <l-tooltip>
|
|
|
396
427
|
> 设置 getter/setter 后,该属性的`@watch` 将会失效
|
|
397
428
|
- @query/queryAll 定义 CssSelector 查询结果
|
|
398
429
|
- @tag 自定义组件的标签名
|
|
399
|
-
- @event 定义全局事件
|
|
400
430
|
- @watch 监控 state/prop 变更
|
|
401
431
|
- @computed 计算属性,仅在响应变量变更时更新缓存值
|
|
402
432
|
- @debounced 定义函数防抖
|
|
403
|
-
- @
|
|
433
|
+
- @event 定义事件,支持修饰符
|
|
434
|
+
- @onced 定义一次性事件
|
|
435
|
+
- @throttled 定义节流函数
|
|
404
436
|
|
|
405
437
|
#### 继承
|
|
406
438
|
部分指令可由子类继承不会覆盖,包括@state/@prop/@watch/@computed
|
package/constants.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CompElem } from "./CompElem";
|
|
2
|
+
import { DecoratorWrapper } from "./decorator";
|
|
3
|
+
import { Getter, PropOption, StateOption } from "./types";
|
|
4
|
+
export declare const SLOT_NAME_DEFAULT = "default";
|
|
5
|
+
/**
|
|
6
|
+
* 共享内容
|
|
7
|
+
*/
|
|
8
|
+
export declare const EXP_KEY: RegExp;
|
|
9
|
+
export declare enum CollectorType {
|
|
10
|
+
RENDER = 1,
|
|
11
|
+
COMPUTED = 2,
|
|
12
|
+
DIRECTIVE = 3
|
|
13
|
+
}
|
|
14
|
+
export declare enum Mode {
|
|
15
|
+
Prod = "prod",
|
|
16
|
+
Dev = "dev"
|
|
17
|
+
}
|
|
18
|
+
export declare const DefinitionCompEventMap: Map<string, Record<string, any>[]>;
|
|
19
|
+
export declare const DefinitionTagMap: Record<string, string>;
|
|
20
|
+
export declare const DefinitionWatchMap: Map<string, Record<string, Record<string, any>[]>>;
|
|
21
|
+
export declare const DefinitionComputedMap: Map<string, Record<string, Getter>>;
|
|
22
|
+
export declare const DefinitionStateMap: Map<string, Record<string, StateOption>>;
|
|
23
|
+
export declare const DefinitionPropMap: Map<string, Record<string, PropOption>>;
|
|
24
|
+
export declare const DefinitionDecoratorMap: Map<string, DecoratorWrapper[]>;
|
|
25
|
+
export declare const ObservedAttrsMap: Map<string, Set<string>>;
|
|
26
|
+
export declare const ComponentDynamicCssUpdaterMap: WeakMap<CompElem<any>, Map<Function, CSSStyleSheet>>;
|
|
27
|
+
export declare const PATH_SEPARATOR = "-";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { CompElem } from "../CompElem";
|
|
2
|
+
export declare enum DecoratorType {
|
|
3
|
+
CLASS = "class",
|
|
4
|
+
FIELD = "field",
|
|
5
|
+
METHOD = "method"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 用于构造装饰器
|
|
9
|
+
* @author holyhigh2
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class Decorator {
|
|
12
|
+
/**
|
|
13
|
+
* 优先级,越大越先执行
|
|
14
|
+
*/
|
|
15
|
+
static get priority(): number;
|
|
16
|
+
/**
|
|
17
|
+
* 装饰器使用范围,超出范围会报错
|
|
18
|
+
*/
|
|
19
|
+
abstract get targets(): Array<DecoratorType>;
|
|
20
|
+
/**
|
|
21
|
+
* 构造会传递自定义参数
|
|
22
|
+
* @param args 自定义参数
|
|
23
|
+
*/
|
|
24
|
+
created(component: CompElem, ...args: any[]): void;
|
|
25
|
+
/**
|
|
26
|
+
* 执行时机与组件一致
|
|
27
|
+
* @param component 组件实例
|
|
28
|
+
* @param setReactive 为实例设置响应属性,注意,仅是设置到了instance.reactiveData中并非this.key。如需实现this访问,可自行定义组件的properties
|
|
29
|
+
* @param args 装饰器函数参数
|
|
30
|
+
*/
|
|
31
|
+
beforeMount(component: CompElem, setReactive: (key: string, value: any) => any, ...args: any[]): void;
|
|
32
|
+
mounted(component: CompElem, setReactive: (key: string, value: any) => any, ...args: any[]): void;
|
|
33
|
+
updated(component: CompElem, changed: Record<string, any>): void;
|
|
34
|
+
beforeDestroy(component: CompElem, ...args: any[]): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Constructor } from './../types';
|
|
2
|
+
/*************************************************************
|
|
3
|
+
* 装饰器
|
|
4
|
+
* @author holyhigh2
|
|
5
|
+
*************************************************************/
|
|
6
|
+
import { CompElem } from "../CompElem";
|
|
7
|
+
import { Decorator } from "./Decorator";
|
|
8
|
+
/**
|
|
9
|
+
* 装饰器包装类
|
|
10
|
+
* 用于框架内部,表示class上的一个装饰器属性定义
|
|
11
|
+
* 该定义在实例初始化时会产生装饰器实例属性
|
|
12
|
+
*/
|
|
13
|
+
export declare class DecoratorWrapper {
|
|
14
|
+
metadata: any[];
|
|
15
|
+
decorator: Decorator;
|
|
16
|
+
key?: string;
|
|
17
|
+
priority: number;
|
|
18
|
+
constructor(args: any[], metadata: any[], decoratorClass: Constructor<Decorator>);
|
|
19
|
+
dispose(): void;
|
|
20
|
+
create(comp: CompElem<any>): void;
|
|
21
|
+
beforeMount(comp: CompElem<any>, setReactive: (key: string, value: any) => any): void;
|
|
22
|
+
mounted(comp: CompElem<any>, setReactive: (key: string, value: any) => any): void;
|
|
23
|
+
updated(comp: CompElem<any>, changed: Record<string, any>): void;
|
|
24
|
+
destroy(comp: CompElem<any>): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 该函数用于创建一个装饰器
|
|
28
|
+
* @param decoClass 装饰器构造
|
|
29
|
+
* @returns 装饰器函数
|
|
30
|
+
*/
|
|
31
|
+
export declare function decorator<T extends Array<any>>(decoClass: Constructor<Decorator>): (...args: T) => (...metadata: any[]) => any;
|
|
32
|
+
export declare function decoratorWithNoArgs(decoClass: Constructor<Decorator>): (...metadata: any[]) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debounced: (wait: number, immediate?: boolean | undefined) => (...metadata: any[]) => any;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CompElem } from "../CompElem";
|
|
2
|
+
/**
|
|
3
|
+
* 绑定非视图事件,如window/document等
|
|
4
|
+
* @param eventName 事件名,含修饰参数。同视图模板中的事件名
|
|
5
|
+
* @param eventTarget 事件绑定目标,默认this
|
|
6
|
+
*/
|
|
7
|
+
export declare function event(eventName: string, eventTarget?: (comp?: CompElem) => (HTMLElement | Promise<HTMLElement> | Window)): (target: any, name: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const onced: () => (...metadata: any[]) => any;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PropOption } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* 声明一个由外部传入的单向更新属性
|
|
4
|
+
* @param options 可选参数 PropOption,如果type未定义则根据默认值自动推断类型
|
|
5
|
+
*/
|
|
6
|
+
export declare function prop(options: PropOption): (target: any, propertyKey: any) => void;
|
|
7
|
+
export declare function prop(target: any, propertyKey: any, options?: PropOption): void;
|
|
8
|
+
export declare function _getObservedAttrs(ctor: Function): Set<string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 缓存策略
|
|
3
|
+
*/
|
|
4
|
+
export declare enum QueryCache {
|
|
5
|
+
ONCE = "once"
|
|
6
|
+
}
|
|
7
|
+
export declare const query: (selector: string, cache?: QueryCache | undefined) => (...metadata: any[]) => any;
|
|
8
|
+
export declare const queryAll: (selector: string, cache?: QueryCache | undefined) => (...metadata: any[]) => any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StateOption } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* 声明一个可双向变动的属性
|
|
4
|
+
* @param options 可选参数 {prop从prop获取初始值},如果type未定义则根据默认值自动推断类型
|
|
5
|
+
*/
|
|
6
|
+
export declare function state(target: any, stateKey: any): void;
|
|
7
|
+
export declare function state(options: StateOption): (target: any, stateKey: any) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 同@state装饰器,但可用于构造器中调用
|
|
10
|
+
* @param ctor 类构造函数
|
|
11
|
+
* @param stateKey state 名称
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
14
|
+
export declare function makeState(ctor: Function, stateKey: string, options?: StateOption): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const throttled: (wait: number) => (...metadata: any[]) => any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WatchOptions } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* 监控prop/state变量值变化
|
|
4
|
+
* @param source 变量路径支持多级路径
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function watch(source: string | string[], options?: WatchOptions): (target: any, name: any) => void;
|
|
9
|
+
export type WatchHandler = (newValue: any, oldValue: any, source: string, subNewValue?: any, subOldValue?: any) => any;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CompElem } from "../CompElem";
|
|
2
|
+
import { DirectiveExecutor, DirectiveInstance, EnterPointType, UpdatePoint } from "../types";
|
|
3
|
+
export declare const DI_COMMENT_START_NODE_MAP: WeakMap<Node, Node>;
|
|
4
|
+
export declare const TextOrSlotDirectiveExecutorMap: Map<string, DirectiveExecutor>;
|
|
5
|
+
export declare function updateDirective(pointNode: Node, newArgs: any[], oldArgs: any[], executor: DirectiveExecutor, renderComponent: CompElem, slotComponent: CompElem, varChain: any[], up: UpdatePoint): void;
|
|
6
|
+
/**
|
|
7
|
+
* 返回指令调用函数
|
|
8
|
+
* @param di
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function directive<T extends Array<any>>(fn: (...args: T) => DirectiveExecutor, scopes: EnterPointType[]): (...args: T) => DirectiveInstance;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const enum ModelTriggerType {
|
|
2
|
+
CHANGE = "change",
|
|
3
|
+
INPUT = "input"
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 实现双向绑定(仅支持静态路径,动态增加的属性路径无法识别)
|
|
7
|
+
* 当用于组件时,监控 @update:value 事件
|
|
8
|
+
* 当用于元素时,
|
|
9
|
+
* - 对于 input/textarea 监控 @input,并设置 value 属性
|
|
10
|
+
* - 对于 checkbox/radio 监控 @change,并设置 checked 属性
|
|
11
|
+
* - 对于 select 监控 @change,并设置 value 属性
|
|
12
|
+
* @param modelValue 双向绑定的组件变量
|
|
13
|
+
* @param updateProp 绑定模型变更时的监控属性,默认 value
|
|
14
|
+
* @param modelProp 当初始模型路径不存在时可指定路径
|
|
15
|
+
*/
|
|
16
|
+
export declare const model: (modelValue: any, updateProp?: string | undefined, modelProp?: string | undefined) => import("../types").DirectiveInstance;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Cbk = (node: Element, isVisible: boolean) => void;
|
|
2
|
+
/**
|
|
3
|
+
* display的快捷指令
|
|
4
|
+
* 如果
|
|
5
|
+
* @param isvisible 是否显示
|
|
6
|
+
* @param cbk 显示状态变更后调用的回调函数
|
|
7
|
+
*/
|
|
8
|
+
export declare const show: (isVisible: boolean, cbk?: Cbk | undefined) => import("../types").DirectiveInstance;
|
|
9
|
+
export {};
|