forked from redom/redom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
145 lines (107 loc) · 5.28 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Type definitions for redom 3.12
// Project: https://github.com/redom/redom/, https://redom.js.org
// Definitions by: Rauli Laine <https://github.com/RauliL>
// Felix Nehrke <https://github.com/nemoinho>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
export type RedomElement = Node | RedomComponent;
export type RedomQuery = string | RedomElement;
export type RedomMiddleware = (el: HTMLElement) => void;
export type RedomQueryArgumentValue = RedomElement | string | number | { [key: string]: any } | RedomMiddleware;
export type RedomQueryArgument = RedomQueryArgumentValue | RedomQueryArgumentValue[];
export type RedomElQuery = string | Node | RedomComponentCreator;
export interface RedomComponent {
el: HTMLElement;
update?(item: any, index: number, data: any, context?: any): void;
onmount?(): void;
onremount?(): void;
onunmount?(): void;
}
export interface RedomComponentClass {
new (): RedomComponent;
}
export type RedomComponentConstructor = RedomComponentClass;
export type RedomComponentFactoryFunction = () => RedomComponent
export type RedomComponentCreator = RedomComponentConstructor | RedomComponentFactoryFunction
export class ListPool {
constructor(View: RedomComponentConstructor, key?: string, initData?: any);
update(data: any[], context?: any): void;
}
export class List implements RedomComponent {
el: HTMLElement;
constructor(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any);
update(data: any[], context?: any): void;
onmount?(): void;
onremount?(): void;
onunmount?(): void;
static extend(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any): RedomComponentConstructor;
}
export class Place implements RedomComponent {
el: HTMLElement;
constructor(View: RedomComponentConstructor, initData?: any);
update(visible: boolean, data?: any): void;
}
export class Router implements RedomComponent {
el: HTMLElement;
constructor(parent: RedomQuery, Views: RouterDictionary, initData?: any);
update(route: string, data?: any): void;
}
export interface RouterDictionary {
[key: string]: RedomComponentConstructor;
}
type HTMLElementOfStringLiteral<Q extends string> =
Q extends 'div' ? HTMLDivElement:
Q extends 'a' ? HTMLAnchorElement:
Q extends 'span' ? HTMLSpanElement:
Q extends 'pre' ? HTMLPreElement:
Q extends 'p' ? HTMLParagraphElement:
Q extends 'hr' ? HTMLHRElement:
Q extends 'br' ? HTMLBRElement:
Q extends 'img' ? HTMLImageElement:
Q extends 'iframe' ? HTMLIFrameElement:
Q extends 'ul' ? HTMLUListElement:
Q extends 'li' ? HTMLLIElement:
Q extends 'ol' ? HTMLOListElement:
Q extends 'form' ? HTMLFormElement:
Q extends 'input' ? HTMLInputElement:
Q extends 'label' ? HTMLLabelElement:
Q extends 'textarea' ? HTMLTextAreaElement:
Q extends 'select' ? HTMLSelectElement:
Q extends 'option' ? HTMLOptionElement:
Q extends 'button' ? HTMLButtonElement:
Q extends 'h1'|'h2'|'h3'|'h4'|'h5'|'h6' ? HTMLHeadingElement:
Q extends 'table' ? HTMLTableElement:
Q extends 'tr' ? HTMLTableRowElement:
Q extends 'td' ? HTMLTableCellElement:
Q extends 'thead'|'tbody'|'tfoot' ? HTMLTableSectionElement:
Q extends 'th' ? HTMLTableHeaderCellElement:
Q extends 'style' ? HTMLStyleElement:
Q extends 'svg' ? SVGElement:
HTMLElement
type RedomElementOfElQuery<Q extends RedomElQuery> =
Q extends Node ? Q:
Q extends RedomComponentClass ? InstanceType<Q>:
Q extends RedomComponentFactoryFunction ? ReturnType<Q>:
Q extends string ? HTMLElementOfStringLiteral<Q>:
never
export function html<Q extends RedomElQuery>(query: Q, ...args: RedomQueryArgument[]): RedomElementOfElQuery<Q>;
export function h<Q extends RedomElQuery>(query: Q, ...args: RedomQueryArgument[]): RedomElementOfElQuery<Q>;
export function el<Q extends RedomElQuery>(query: Q, ...args: RedomQueryArgument[]): RedomElementOfElQuery<Q>;
export function listPool(View: RedomComponentConstructor, key?: string, initData?: any): ListPool;
export function list(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any): List;
export function mount(parent: RedomElement, child: RedomElement, before?: RedomElement, replace?: boolean): RedomElement;
export function unmount(parent: RedomElement, child: RedomElement): RedomElement;
export function place(View: RedomComponentConstructor, initData?: any): Place;
export function router(parent: RedomQuery, Views: RouterDictionary, initData?: any): Router;
export function setAttr(view: RedomElement, arg1: string | object, arg2?: string): void;
export function setStyle(view: RedomElement, arg1: string | object, arg2?: string): void;
export function setChildren(parent: RedomElement, children: RedomElement[]): void;
export function svg(query: RedomQuery, ...args: RedomQueryArgument[]): SVGElement;
export function s(query: RedomQuery, ...args: RedomQueryArgument[]): SVGElement;
export function text(str: string): Text;
export namespace list {
function extend(parent: RedomQuery, View: RedomComponentConstructor, key?: string, initData?: any): RedomComponentConstructor;
}
export namespace svg {
function extend(query: RedomQuery): RedomComponentConstructor;
}