compelem 0.10.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 +53 -22
- package/IComponent.d.ts +13 -10
- package/README.md +48 -16
- package/constants.d.ts +17 -10
- package/decorator/Decorator.d.ts +5 -8
- package/decorator/index.d.ts +7 -10
- package/decorators/event.d.ts +3 -22
- package/decorators/prop.d.ts +1 -52
- package/decorators/query.d.ts +1 -19
- package/decorators/state.d.ts +1 -17
- package/decorators/tag.d.ts +1 -1
- package/decorators/watch.d.ts +5 -15
- package/directive/index.d.ts +4 -17
- package/directives/Styles.d.ts +2 -2
- package/events/event.d.ts +1 -12
- package/events/extends.d.ts +2 -1
- package/helpers.d.ts +1 -1
- package/index.d.ts +4 -3
- package/index.js +2 -2
- package/package.json +1 -1
- package/reactive.d.ts +11 -33
- package/render/CssTemplate.d.ts +12 -0
- package/render/Template.d.ts +1 -0
- package/render/render.d.ts +17 -26
- package/types.d.ts +118 -11
- package/utils.d.ts +7 -0
- package/compelem.umd.js +0 -7
- package/decorators/bindThis.d.ts +0 -1
package/CompElem.d.ts
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
1
|
import { IComponent } from "./IComponent";
|
|
2
|
+
import { CssTemplate } from "./render/CssTemplate";
|
|
2
3
|
import { Template } from "./render/Template";
|
|
3
|
-
import { DefaultProps, TmplFn } from "./types";
|
|
4
|
-
export declare const PROP_OBJECT_KEY_MAP_SYMBOL: unique symbol;
|
|
4
|
+
import { DefaultProps, TmplFn, UpdatePoint } from "./types";
|
|
5
5
|
/**
|
|
6
6
|
* CompElem基类,意为组件元素。提供了基本内置属性及生命周期等必备接口
|
|
7
7
|
* 每个组件都需要继承自该类
|
|
8
8
|
*
|
|
9
9
|
* @author holyhigh2
|
|
10
10
|
*/
|
|
11
|
-
export declare class CompElem extends HTMLElement implements IComponent {
|
|
11
|
+
export declare class CompElem<T = HTMLElement> extends HTMLElement implements IComponent<T> {
|
|
12
12
|
#private;
|
|
13
13
|
static __l_globalRule: HTMLStyleElement;
|
|
14
14
|
static defaults(options: DefaultProps): void;
|
|
15
|
-
|
|
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>;
|
|
16
33
|
get [Symbol.toStringTag](): string;
|
|
17
34
|
get cid(): number;
|
|
18
|
-
get reactiveData(): Record<string, any>;
|
|
19
35
|
get attrs(): Record<string, string>;
|
|
20
36
|
get props(): Record<string, any>;
|
|
21
|
-
get renderRoot():
|
|
37
|
+
get renderRoot(): T | undefined;
|
|
22
38
|
get renderRoots(): HTMLElement[];
|
|
23
|
-
get parentComponent(): CompElem |
|
|
24
|
-
get wrapperComponent(): CompElem |
|
|
39
|
+
get parentComponent(): CompElem | undefined;
|
|
40
|
+
get wrapperComponent(): CompElem | undefined;
|
|
25
41
|
get slotHooks(): Record<string, (...args: any[]) => Template>;
|
|
26
|
-
get
|
|
42
|
+
get styleSheets(): CSSStyleSheet[];
|
|
27
43
|
get globalStyleSheet(): CSSStyleSheet;
|
|
28
44
|
get isMounted(): boolean;
|
|
29
45
|
get slots(): Record<string, Array<Node>>;
|
|
@@ -31,22 +47,29 @@ export declare class CompElem extends HTMLElement implements IComponent {
|
|
|
31
47
|
* 组件样式,CSSStyleSheet可动态变更
|
|
32
48
|
*/
|
|
33
49
|
static get styles(): Array<string | CSSStyleSheet>;
|
|
34
|
-
static get
|
|
35
|
-
static get
|
|
36
|
-
get styles(): Array<
|
|
50
|
+
static get globalStyle(): string | undefined;
|
|
51
|
+
static get hostStyle(): string | CSSStyleSheet | undefined;
|
|
52
|
+
get styles(): Array<CssTemplate>;
|
|
37
53
|
constructor(...args: any[]);
|
|
38
|
-
insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet;
|
|
54
|
+
insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet | null;
|
|
39
55
|
/**
|
|
40
56
|
* Returns the root component in the parent chain, or itself if it's the top-level component.
|
|
41
57
|
*/
|
|
42
58
|
get rootComponent(): CompElem;
|
|
43
59
|
connectedCallback(): void;
|
|
44
60
|
disconnectedCallback(): void;
|
|
61
|
+
__bindEvents(): void;
|
|
62
|
+
__unbindEvents(): void;
|
|
63
|
+
beforeDestroyed(): void;
|
|
64
|
+
destroyed(): void;
|
|
65
|
+
get isDestroyed(): boolean;
|
|
66
|
+
destroy(): void;
|
|
45
67
|
__init(): void;
|
|
46
68
|
propsReady(props: Record<string, any>): void;
|
|
47
|
-
render(): Template;
|
|
69
|
+
render(): Template | null;
|
|
48
70
|
beforeMount(): void;
|
|
49
71
|
mounted(): void;
|
|
72
|
+
__onSlotChangeHook(e: Event): void;
|
|
50
73
|
slotChange(slot: HTMLSlotElement, name: string): void;
|
|
51
74
|
attributeChangedCallback(attributeName: string, oldValue: string | null, newValue: string | null): void;
|
|
52
75
|
/**
|
|
@@ -69,7 +92,9 @@ export declare class CompElem extends HTMLElement implements IComponent {
|
|
|
69
92
|
* @param rootStateKey 如果是对象内部属性变更,会返回根属性名
|
|
70
93
|
* @returns
|
|
71
94
|
*/
|
|
72
|
-
_notify(ov: any, chain: string[]):
|
|
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;
|
|
73
98
|
_updateProps(props: Record<string, any>): void;
|
|
74
99
|
_wrapperProp: Record<string, string>;
|
|
75
100
|
_initProps(props: Record<string, any>, attrs?: Record<string, any>): void;
|
|
@@ -81,12 +106,9 @@ export declare class CompElem extends HTMLElement implements IComponent {
|
|
|
81
106
|
_updateSlot(name: string, propName?: string, value?: any): void;
|
|
82
107
|
_asyncDirectives: WeakMap<TmplFn, any>;
|
|
83
108
|
renderAsync(cbk: TmplFn, ...args: any[]): void;
|
|
84
|
-
|
|
85
|
-
* todo
|
|
86
|
-
* 1. 取消上溯递归路径
|
|
87
|
-
*/
|
|
88
|
-
_regDeps(varPath: string, renderContext: CompElem | Node): void;
|
|
109
|
+
__attrChanged(name: string, oldValue: string | null, newValue: string | null): void;
|
|
89
110
|
_regWrapper(wrapperComponent: CompElem): void;
|
|
111
|
+
_regSubViewDeps(props: string[], up: UpdatePoint): void;
|
|
90
112
|
_getPrivateData(): Record<string, any>;
|
|
91
113
|
/**
|
|
92
114
|
* 抛出自定义事件
|
|
@@ -102,13 +124,22 @@ export declare class CompElem extends HTMLElement implements IComponent {
|
|
|
102
124
|
* 在root上绑定事件
|
|
103
125
|
* @param evName
|
|
104
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事件
|
|
105
134
|
*/
|
|
106
|
-
|
|
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;
|
|
107
138
|
/**
|
|
108
139
|
* 下一帧执行
|
|
109
140
|
* @param cbk
|
|
110
141
|
*/
|
|
111
|
-
nextTick(cbk: () => void
|
|
142
|
+
nextTick(cbk: () => void): void;
|
|
112
143
|
/**
|
|
113
144
|
* 强制更新一次视图
|
|
114
145
|
*/
|
package/IComponent.d.ts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
+
import { CssTemplate } from "./render/CssTemplate";
|
|
1
2
|
import { Template } from "./render/Template";
|
|
2
3
|
/**
|
|
3
4
|
* 组件接口
|
|
4
5
|
* 定义组件属性、生命周期及方法
|
|
5
6
|
* @author holyhigh2
|
|
6
7
|
*/
|
|
7
|
-
export interface IComponent {
|
|
8
|
+
export interface IComponent<T = HTMLElement> {
|
|
8
9
|
get cid(): number;
|
|
9
10
|
get attrs(): Record<string, string>;
|
|
10
11
|
get props(): Record<string, any>;
|
|
11
|
-
get renderRoot():
|
|
12
|
+
get renderRoot(): T | undefined;
|
|
12
13
|
get renderRoots(): HTMLElement[];
|
|
13
|
-
get rootComponent(): HTMLElement;
|
|
14
|
-
get parentComponent(): HTMLElement |
|
|
15
|
-
get wrapperComponent(): HTMLElement |
|
|
14
|
+
get rootComponent(): HTMLElement | undefined;
|
|
15
|
+
get parentComponent(): HTMLElement | undefined;
|
|
16
|
+
get wrapperComponent(): HTMLElement | undefined;
|
|
16
17
|
get slots(): Record<string, Array<Node>>;
|
|
17
18
|
get slotHooks(): Record<string, (...args: any[]) => Template>;
|
|
18
|
-
get
|
|
19
|
+
get styleSheets(): CSSStyleSheet[];
|
|
19
20
|
get globalStyleSheet(): CSSStyleSheet;
|
|
20
21
|
get isMounted(): boolean;
|
|
21
|
-
get styles(): Array<
|
|
22
|
+
get styles(): Array<CssTemplate>;
|
|
22
23
|
propsReady(props: Record<string, any>): void;
|
|
23
|
-
render(): Template;
|
|
24
|
+
render(): Template | null;
|
|
24
25
|
beforeMount(): void;
|
|
25
26
|
mounted(): void;
|
|
26
27
|
connectedCallback(): void;
|
|
27
28
|
disconnectedCallback(): void;
|
|
29
|
+
beforeDestroyed(): void;
|
|
30
|
+
destroyed(): void;
|
|
28
31
|
shouldUpdate(changed: Record<string, any>): boolean;
|
|
29
32
|
updated(changed: Record<string, any>): void;
|
|
30
33
|
slotChange(slot: HTMLSlotElement, slotName: string): void;
|
|
@@ -55,8 +58,8 @@ export interface IComponent {
|
|
|
55
58
|
*/
|
|
56
59
|
forceUpdate(): void;
|
|
57
60
|
/**
|
|
58
|
-
*
|
|
61
|
+
* 向组件插入样式表,没有shadowDOM的组件调用无效
|
|
59
62
|
* @param sheet
|
|
60
63
|
*/
|
|
61
|
-
insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet;
|
|
64
|
+
insertStyleSheet(sheet: string | CSSStyleSheet): CSSStyleSheet | null;
|
|
62
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
CHANGED
|
@@ -1,20 +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";
|
|
1
5
|
/**
|
|
2
6
|
* 共享内容
|
|
3
7
|
*/
|
|
4
8
|
export declare const EXP_KEY: RegExp;
|
|
5
9
|
export declare enum CollectorType {
|
|
6
|
-
|
|
7
|
-
COMPUTED = 2
|
|
8
|
-
|
|
9
|
-
export declare enum DecoratorKey {
|
|
10
|
-
PROPS = "__deco_props",
|
|
11
|
-
STATES = "__deco_states",
|
|
12
|
-
COMPUTED = "__deco_computed",
|
|
13
|
-
WATCH = "__deco_watch",
|
|
14
|
-
EVENTS = "__deco_events"
|
|
10
|
+
RENDER = 1,
|
|
11
|
+
COMPUTED = 2,
|
|
12
|
+
DIRECTIVE = 3
|
|
15
13
|
}
|
|
16
14
|
export declare enum Mode {
|
|
17
15
|
Prod = "prod",
|
|
18
16
|
Dev = "dev"
|
|
19
17
|
}
|
|
20
|
-
export declare const
|
|
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 = "-";
|
package/decorator/Decorator.d.ts
CHANGED
|
@@ -21,18 +21,15 @@ export declare abstract class Decorator {
|
|
|
21
21
|
* 构造会传递自定义参数
|
|
22
22
|
* @param args 自定义参数
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
* 返回用于识别唯一实例的key,比如@watch(a.b.c)中的变量路径就会作为唯一key。key相同的装饰器仅会保存一份,如果无需唯一校验可不实现该函数
|
|
26
|
-
* @param args
|
|
27
|
-
*/
|
|
28
|
-
abstract created(component: CompElem, ...args: any[]): any;
|
|
24
|
+
created(component: CompElem, ...args: any[]): void;
|
|
29
25
|
/**
|
|
30
26
|
* 执行时机与组件一致
|
|
31
27
|
* @param component 组件实例
|
|
32
28
|
* @param setReactive 为实例设置响应属性,注意,仅是设置到了instance.reactiveData中并非this.key。如需实现this访问,可自行定义组件的properties
|
|
33
29
|
* @param args 装饰器函数参数
|
|
34
30
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|
|
38
35
|
}
|
package/decorator/index.d.ts
CHANGED
|
@@ -5,26 +5,23 @@ import { Constructor } from './../types';
|
|
|
5
5
|
*************************************************************/
|
|
6
6
|
import { CompElem } from "../CompElem";
|
|
7
7
|
import { Decorator } from "./Decorator";
|
|
8
|
-
export declare const GetKeyFnName = "getKey";
|
|
9
|
-
export declare const _DecoratorsKey = "__decorators";
|
|
10
|
-
export declare const _DecoratorMap: WeakMap<WeakKey, any>;
|
|
11
8
|
/**
|
|
12
9
|
* 装饰器包装类
|
|
13
10
|
* 用于框架内部,表示class上的一个装饰器属性定义
|
|
14
11
|
* 该定义在实例初始化时会产生装饰器实例属性
|
|
15
12
|
*/
|
|
16
13
|
export declare class DecoratorWrapper {
|
|
17
|
-
args: any[];
|
|
18
14
|
metadata: any[];
|
|
19
|
-
|
|
20
|
-
instanceMap: WeakMap<CompElem, Decorator>;
|
|
15
|
+
decorator: Decorator;
|
|
21
16
|
key?: string;
|
|
22
17
|
priority: number;
|
|
23
18
|
constructor(args: any[], metadata: any[], decoratorClass: Constructor<Decorator>);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
30
27
|
* 该函数用于创建一个装饰器
|
package/decorators/event.d.ts
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import { CompElem } from "../CompElem";
|
|
2
|
-
/**
|
|
3
|
-
* 事件选项
|
|
4
|
-
*/
|
|
5
|
-
export type EventOption = {
|
|
6
|
-
/**
|
|
7
|
-
* 事件绑定目标,默认document
|
|
8
|
-
*/
|
|
9
|
-
target?: Object | ((comp?: CompElem) => (HTMLElement | Promise<HTMLElement>));
|
|
10
|
-
/**
|
|
11
|
-
* 是否在捕获阶段执行
|
|
12
|
-
*/
|
|
13
|
-
capture?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* 是否仅执行一次
|
|
16
|
-
*/
|
|
17
|
-
once?: boolean;
|
|
18
|
-
passive?: boolean;
|
|
19
|
-
};
|
|
20
2
|
/**
|
|
21
3
|
* 绑定非视图事件,如window/document等
|
|
22
|
-
* @param eventName
|
|
23
|
-
* @param
|
|
24
|
-
* @param deep 深度监控
|
|
4
|
+
* @param eventName 事件名,含修饰参数。同视图模板中的事件名
|
|
5
|
+
* @param eventTarget 事件绑定目标,默认this
|
|
25
6
|
*/
|
|
26
|
-
export declare function event(eventName: string,
|
|
7
|
+
export declare function event(eventName: string, eventTarget?: (comp?: CompElem) => (HTMLElement | Promise<HTMLElement> | Window)): (target: any, name: string, descriptor: PropertyDescriptor) => void;
|
package/decorators/prop.d.ts
CHANGED
|
@@ -1,55 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
* 属性定义
|
|
4
|
-
*/
|
|
5
|
-
export type PropOption = {
|
|
6
|
-
/**
|
|
7
|
-
* 参数类型
|
|
8
|
-
*/
|
|
9
|
-
type: Constructor<any> | Array<Constructor<any>>;
|
|
10
|
-
/**
|
|
11
|
-
* 是否必填,默认false
|
|
12
|
-
*/
|
|
13
|
-
required?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* 是否可以修改属性,默认false
|
|
16
|
-
*/
|
|
17
|
-
sync?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* 是否关联属性,prop会生成dom属性且当属性变动时自动更新值。默认true
|
|
20
|
-
*/
|
|
21
|
-
attribute?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* 是否发生变更,如果未指定使用严格相等
|
|
24
|
-
* @param newValue
|
|
25
|
-
* @param oldValue
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
hasChanged?: (newValue: any, oldValue: any, changeChain: string[], subNewValue: any, subOldValue: any) => boolean;
|
|
29
|
-
/**
|
|
30
|
-
* 设置属性getter,可以通过 get 函数方式设置
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
getter?: () => any;
|
|
34
|
-
/**
|
|
35
|
-
* 设置属性setter,可以通过 set 函数方式设置
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
setter?: (v: any) => void;
|
|
39
|
-
/**
|
|
40
|
-
* 当传递参数值为string类型且参数类型不是string时会调用转换器进行转换
|
|
41
|
-
* @param stringValue
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
converter?: (stringValue: string) => any;
|
|
45
|
-
_defaultValue?: any;
|
|
46
|
-
/**
|
|
47
|
-
* 属性校验器,可动态校验值是否合法
|
|
48
|
-
* @param value
|
|
49
|
-
* @returns
|
|
50
|
-
*/
|
|
51
|
-
isValid?: (value: any, props?: Record<string, any>) => boolean;
|
|
52
|
-
};
|
|
1
|
+
import { PropOption } from "../types";
|
|
53
2
|
/**
|
|
54
3
|
* 声明一个由外部传入的单向更新属性
|
|
55
4
|
* @param options 可选参数 PropOption,如果type未定义则根据默认值自动推断类型
|
package/decorators/query.d.ts
CHANGED
|
@@ -2,25 +2,7 @@
|
|
|
2
2
|
* 缓存策略
|
|
3
3
|
*/
|
|
4
4
|
export declare enum QueryCache {
|
|
5
|
-
ONCE = "once"
|
|
6
|
-
UPDATABLE = "updatable"
|
|
5
|
+
ONCE = "once"
|
|
7
6
|
}
|
|
8
|
-
/**
|
|
9
|
-
* 事件选项
|
|
10
|
-
*/
|
|
11
|
-
export type QueryOption = {
|
|
12
|
-
/**
|
|
13
|
-
* 指示是否返回任何可用子<slot>元素的指定节点(true)或不返回(false)
|
|
14
|
-
*/
|
|
15
|
-
flatten?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* 对节点列表进行过滤
|
|
18
|
-
*/
|
|
19
|
-
selector?: string;
|
|
20
|
-
/**
|
|
21
|
-
* 缓存标识
|
|
22
|
-
*/
|
|
23
|
-
cache?: string;
|
|
24
|
-
};
|
|
25
7
|
export declare const query: (selector: string, cache?: QueryCache | undefined) => (...metadata: any[]) => any;
|
|
26
8
|
export declare const queryAll: (selector: string, cache?: QueryCache | undefined) => (...metadata: any[]) => any;
|
package/decorators/state.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* 是否浅层监控,默认false
|
|
4
|
-
*/
|
|
5
|
-
shallow?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* 指定prop进行初始化,如果时对象类型时
|
|
8
|
-
*/
|
|
9
|
-
prop?: string;
|
|
10
|
-
/**
|
|
11
|
-
* 是否发生变更,如果未指定使用严格相等
|
|
12
|
-
* @param newValue
|
|
13
|
-
* @param oldValue
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
hasChanged?: (newValue: any, oldValue: any, changeChain: string[], subNewValue: any, subOldValue: any) => boolean;
|
|
17
|
-
};
|
|
1
|
+
import { StateOption } from "../types";
|
|
18
2
|
/**
|
|
19
3
|
* 声明一个可双向变动的属性
|
|
20
4
|
* @param options 可选参数 {prop从prop获取初始值},如果type未定义则根据默认值自动推断类型
|
package/decorators/tag.d.ts
CHANGED
package/decorators/watch.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
+
import { WatchOptions } from "../types";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* 监控prop/state变量值变化
|
|
4
|
+
* @param source 变量路径支持多级路径
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns
|
|
3
7
|
*/
|
|
4
|
-
export type WatchOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* 是否立即执行
|
|
7
|
-
*/
|
|
8
|
-
immediate?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* 是否深度监控
|
|
11
|
-
*/
|
|
12
|
-
deep?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* 是否仅执行一次
|
|
15
|
-
*/
|
|
16
|
-
once?: boolean;
|
|
17
|
-
};
|
|
18
8
|
export declare function watch(source: string | string[], options?: WatchOptions): (target: any, name: any) => void;
|
|
19
9
|
export type WatchHandler = (newValue: any, oldValue: any, source: string, subNewValue?: any, subOldValue?: any) => any;
|
package/directive/index.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { CompElem } from "../CompElem";
|
|
2
|
-
import { DirectiveExecutor, DirectiveInstance, EnterPointType } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare class EnterPoint {
|
|
7
|
-
startNode: Node;
|
|
8
|
-
endNode: Node;
|
|
9
|
-
type: EnterPointType;
|
|
10
|
-
attrName: string;
|
|
11
|
-
varIndex: number;
|
|
12
|
-
expressionChain: string;
|
|
13
|
-
nodes: Node[];
|
|
14
|
-
constructor(node: Node, attrName: string, type: EnterPointType);
|
|
15
|
-
setVarIndex(varIndex: number): void;
|
|
16
|
-
getNodes(): Node[];
|
|
17
|
-
}
|
|
18
|
-
export declare function updateDirective(point: EnterPoint, newArgs: any[], oldArgs: any[], updater: DirectiveExecutor, renderComponent: CompElem, slotComponent: CompElem, varChain: any[][], isTextOrSlot?: boolean): void;
|
|
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;
|
|
19
6
|
/**
|
|
20
7
|
* 返回指令调用函数
|
|
21
8
|
* @param di
|
package/directives/Styles.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 根据变量内容设置元素样式,仅能用于style属性
|
|
3
3
|
* @param styles 对象/字符串
|
|
4
4
|
*/
|
|
5
|
-
export declare const styles: (
|
|
5
|
+
export declare const styles: (...args: (string | Record<string, string>)[]) => import("../types").DirectiveInstance;
|