compelem 0.0.0 → 0.1.0-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.
@@ -0,0 +1,26 @@
1
+ import { CompElem } from "../CompElem";
2
+ /**
3
+ * 事件选项
4
+ */
5
+ export type EventOption = {
6
+ /**
7
+ * 事件绑定目标,默认document
8
+ */
9
+ target?: Object | ((comp?: CompElem) => HTMLElement);
10
+ /**
11
+ * 是否深度监控
12
+ */
13
+ capture?: boolean;
14
+ /**
15
+ * 是否仅执行一次
16
+ */
17
+ once?: boolean;
18
+ passive?: boolean;
19
+ };
20
+ /**
21
+ * 绑定非视图事件,如window/document等
22
+ * @param eventName 事件名
23
+ * @param immediate 立即执行
24
+ * @param deep 深度监控
25
+ */
26
+ export declare function event(eventName: string, options?: EventOption): (target: any, name: string, descriptor: PropertyDescriptor) => void;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * 属性定义
3
+ */
4
+ export type PropOption = {
5
+ /**
6
+ * 参数类型
7
+ */
8
+ type: any;
9
+ /**
10
+ * 是否必填,默认false
11
+ */
12
+ required?: boolean;
13
+ /**
14
+ * 是否可以修改属性,默认false
15
+ */
16
+ sync?: boolean;
17
+ /**
18
+ * 是否关联属性,prop会生成dom属性且当属性变动时自动更新值。默认true
19
+ */
20
+ attribute?: boolean;
21
+ /**
22
+ * 是否发生变更,如果未指定使用严格相等
23
+ * @param newValue
24
+ * @param oldValue
25
+ * @returns
26
+ */
27
+ hasChanged?: (newValue: any, oldValue: any) => boolean;
28
+ /**
29
+ * 设置属性getter,可以通过 get 函数方式设置
30
+ * @returns
31
+ */
32
+ getter?: () => any;
33
+ /**
34
+ * 设置属性setter,可以通过 set 函数方式设置
35
+ * @returns
36
+ */
37
+ setter?: (v: any) => void;
38
+ /**
39
+ * 当传递参数值为string类型且参数类型不是string时会调用转换器进行转换
40
+ * @param stringValue
41
+ * @returns
42
+ */
43
+ converter?: (stringValue: string) => any;
44
+ _defaultValue?: any;
45
+ /**
46
+ * 属性校验器,可动态校验值是否合法
47
+ * @param value
48
+ * @returns
49
+ */
50
+ isValid?: (value: any, props?: Record<string, any>) => boolean;
51
+ };
52
+ /**
53
+ * 声明一个由外部传入的单向更新属性
54
+ * @param options 可选参数 PropOption,如果type未定义则根据默认值自动推断类型
55
+ */
56
+ export declare function prop(options: PropOption): (target: any, propertyKey: any) => void;
57
+ export declare function prop(target: any, propertyKey: any): void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 缓存策略
3
+ */
4
+ export declare enum QueryCache {
5
+ ONCE = "once",//仅缓存一次(首次查询到结果时)
6
+ UPDATABLE = "updatable"
7
+ }
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
+ export declare const query: (selector: string, cache?: QueryCache | undefined) => (...metadata: any[]) => void;
26
+ export declare const queryAll: (selector: string, cache?: QueryCache | undefined) => (...metadata: any[]) => void;
@@ -0,0 +1,19 @@
1
+ export type StateOption = {
2
+ /**
3
+ * 指定prop进行初始化,如果时对象类型时
4
+ */
5
+ prop?: string;
6
+ /**
7
+ * 是否发生变更,如果未指定使用严格相等
8
+ * @param newValue
9
+ * @param oldValue
10
+ * @returns
11
+ */
12
+ hasChanged?: (newValue: any, oldValue: any) => boolean;
13
+ };
14
+ /**
15
+ * 声明一个可双向变动的属性
16
+ * @param options 可选参数 {prop从prop获取初始值},如果type未定义则根据默认值自动推断类型
17
+ */
18
+ export declare function state(target: any, stateKey: any): void;
19
+ export declare function state(options: StateOption): (target: any, stateKey: any) => void;
@@ -0,0 +1,6 @@
1
+ import { CompElem } from "../CompElem";
2
+ /**
3
+ * class用注解,用于自动注册自定义组件
4
+ * @param name 自定义组件名称
5
+ */
6
+ export declare function tag(name: string): (target: typeof CompElem) => void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 监控定义
3
+ */
4
+ export type WatchOptions = {
5
+ /**
6
+ * 是否立即执行
7
+ */
8
+ immediate?: boolean;
9
+ /**
10
+ * 是否深度监控
11
+ */
12
+ deep?: boolean;
13
+ /**
14
+ * 是否仅执行一次
15
+ */
16
+ once?: boolean;
17
+ };
18
+ export type WatchHandler = (newValue: any, oldValue: any, source: string) => any;
19
+ /**
20
+ * 装饰器
21
+ */
22
+ export type DecoratorWatch = {
23
+ handler: WatchHandler;
24
+ options: WatchOptions;
25
+ };
26
+ export declare const watch: (source: string | string[], options?: WatchOptions | undefined) => (...metadata: any[]) => void;
@@ -0,0 +1,43 @@
1
+ import { Template } from "../render/render";
2
+ import { DirectiveUpdateTag, TmplFn } from "../types";
3
+ import { EnterPointType } from "./index";
4
+ declare const Directive_base: {
5
+ new (...args: any[]): {
6
+ [x: string]: any;
7
+ render(...args: any): void | Template | Template[] | ((...args: any[]) => (Template | Template[]));
8
+ __expPos: Record<string, import("../types").ExpPos>;
9
+ __expPosMap: Record<string, Record<string, import("../types").ExpPos> | null>;
10
+ __directives: Record<string, Directive>;
11
+ slotComponent: import("..").CompElem;
12
+ renderComponent: import("..").CompElem;
13
+ renderContext(...args: any): [NodeListOf<ChildNode>, Record<string, import("../types").ExpPos>, Record<string, Record<string, import("../types").ExpPos> | null>];
14
+ updateContext(...args: any): void;
15
+ __updateExpPos(tmpl: Template, _expPos: Record<string, import("../types").ExpPos>): void;
16
+ };
17
+ } & ObjectConstructor;
18
+ /**
19
+ * 用于解析HTML模板
20
+ * @author holyhigh2
21
+ */
22
+ export declare abstract class Directive extends Directive_base {
23
+ _renderArgs: any[];
24
+ /**
25
+ * 指令使用范围,超出范围会报错
26
+ */
27
+ static get scopes(): Array<EnterPointType>;
28
+ /**
29
+ * 更新时调用
30
+ * @param point
31
+ */
32
+ abstract update(nodes: Node[], newArgs: any[], oldArgs: any[]): DirectiveUpdateTag;
33
+ /**
34
+ * 调用实现
35
+ * 如果返回tmplFn则表示异步渲染
36
+ */
37
+ abstract render(...args: any): Template | Template[] | void | TmplFn;
38
+ /**
39
+ * 指令渲染参数变量链
40
+ */
41
+ renderParams: Array<string[]>;
42
+ }
43
+ export {};
@@ -0,0 +1,52 @@
1
+ import { CompElem } from "../CompElem";
2
+ import { Directive } from "./Directive";
3
+ /**
4
+ * 属性定义
5
+ */
6
+ export declare enum EnterPointType {
7
+ ATTR = "attr",//属性,文本内容,可以内嵌多插值
8
+ PROP = "prop",//参数,智能内嵌一个插值
9
+ TEXT = "text",
10
+ CLASS = "class",
11
+ STYLE = "style",
12
+ SLOT = "slot",
13
+ TAG = "tag"
14
+ }
15
+ /**
16
+ * 交互点信息
17
+ */
18
+ export declare class EnterPoint {
19
+ startNode: Node;
20
+ endNode: Node;
21
+ type: EnterPointType;
22
+ attrName: string;
23
+ varIndex: number;
24
+ expressionChain: string;
25
+ nodes: Node[];
26
+ constructor(level: number, node: Node, attrName: string, type: EnterPointType);
27
+ setVarIndex(varIndex: number): void;
28
+ }
29
+ /**
30
+ * Delay the actual time of execution of directive
31
+ */
32
+ export declare class DirectiveWrapper extends Function {
33
+ #private;
34
+ diClass: any;
35
+ args: any[];
36
+ di: Directive;
37
+ varPath: string;
38
+ point: EnterPoint;
39
+ slotComponent: CompElem;
40
+ varChain: any[];
41
+ constructor(diClass: typeof Directive, ...args: any[]);
42
+ checkScope(scopeType: string): void;
43
+ render(component: CompElem): NodeListOf<ChildNode>;
44
+ update(nodes: Node[], newArgs: any[], oldArgs: any[]): void;
45
+ getDirective(): Directive;
46
+ }
47
+ /**
48
+ * 返回指令调用函数
49
+ * @param di
50
+ * @returns
51
+ */
52
+ export declare function directive<T extends Array<any>>(diClass: typeof Directive): (...args: T) => DirectiveWrapper;
@@ -0,0 +1 @@
1
+ export declare const bind: (obj: Record<string, any>) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1 @@
1
+ export declare const classes: (clazz: string | Record<string, string | boolean> | string[]) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,2 @@
1
+ import { TmplFn } from "../types";
2
+ export declare const forEach: (value: any[] | Record<string, any[]>, cbk: TmplFn) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,2 @@
1
+ import { TmplFn } from "../types";
2
+ export declare const ifElse: (condition: boolean, tmplFn1: TmplFn, tmplFn2: TmplFn) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,2 @@
1
+ import { TmplFn } from "../types";
2
+ export declare const ifTrue: (condition: boolean, tmplFn: TmplFn) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,5 @@
1
+ export declare const enum ModelTriggerType {
2
+ CHANGE = "change",
3
+ INPUT = "input"
4
+ }
5
+ export declare const model: (modelValue: any) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1 @@
1
+ export declare const show: (isVisible: boolean) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,2 @@
1
+ import { TmplFn } from "../types";
2
+ export declare const slot: (cbk: TmplFn, slotName?: string | undefined) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1 @@
1
+ export declare const styles: (styles: string | Record<string, string>) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1 @@
1
+ export declare const sync: (syncValue: any) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,2 @@
1
+ import { TmplFn } from "../types";
2
+ export declare const when: (value: any, cases: TmplFn[][] | Record<string | number, TmplFn>) => import("../directive/index").DirectiveWrapper;
@@ -0,0 +1,13 @@
1
+ import { CompElem } from "../CompElem";
2
+ export declare const MODI_PARAM_DIVIDER = ":";
3
+ /*************************************************************
4
+ * 事件修饰符
5
+ * @author holyhigh2
6
+ *
7
+ * 通用 debounce/stop/prevent/once/throttle/self 可组合
8
+ * 鼠标 left/right/middle 不可组合
9
+ * 键盘 ctrl/alt/shift/meta 可组合 esc/letters... 不可组合,多个key并列式表示可选
10
+ *
11
+ * 部分修饰符支持参数,使用冒号传参如:throttle:100 / debounce:100
12
+ *************************************************************/
13
+ export declare function addEvent(fullName: string, cbk: (ev: Event) => any, node: Element, component: CompElem): (ev: Event) => any;
@@ -0,0 +1,2 @@
1
+ export declare function isExtEvent(evName: string): boolean;
2
+ export declare function addExtEvent(evName: string, node: Element, cbk: (ev: Event) => any, parts: string[]): void;
package/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { createRef, html, RefObject, Template } from "./render/render";
2
+ export * from "./decorator/Decorator";
3
+ export * from "./decorator/index";
4
+ export * from "./decorators/computed";
5
+ export * from "./decorators/event";
6
+ export * from "./decorators/prop";
7
+ export * from "./decorators/query";
8
+ export * from "./decorators/state";
9
+ export * from "./decorators/tag";
10
+ export * from "./decorators/watch";
11
+ export * from "./directive/Directive";
12
+ export * from "./directive/index";
13
+ export * from "./directives/Bind";
14
+ export * from "./directives/Classes";
15
+ export * from "./directives/ForEach";
16
+ export * from "./directives/IfElse";
17
+ export * from "./directives/IfTrue";
18
+ export * from "./directives/Model";
19
+ export * from "./directives/Show";
20
+ export * from "./directives/Slot";
21
+ export * from "./directives/Styles";
22
+ export * from "./directives/Sync";
23
+ export * from "./directives/When";
24
+ export { createRef, html, RefObject, Template };
25
+ export * from './CompElem';
26
+ export * from './types';