forked from angular/preboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preboot.d.ts
163 lines (144 loc) · 5.37 KB
/
preboot.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// basically this is used to identify which events to listen for and what we do with them
interface EventSelector {
selector: string; // same as jQuery; selector for nodes
events: [string]; // array of event names to listen for
keyCodes?: [number]; // key codes to watch out for
preventDefault?: boolean; // will prevent default handlers if true
freeze?: boolean; // if true, the UI will freeze when this event occurs
action?: Function; // custom action to take with this event
noReplay?: boolean; // if true, no replay will occur
}
interface PrebootCompleteOptions {
appRoot?: string;
window?: Window;
noCleanup?: boolean;
}
interface ServerClientRoot {
serverSelector: string;
serverNode?: Element;
clientSelector?: string;
clientNode?: Element;
}
// interface for the options that can be passed into preboot
interface PrebootOptions {
window?: Window; // just used for testing purposes to mock out the window
uglify?: boolean; // if true, client code generated will be uglified
buffer?: boolean; // if true, attempt to buffer client rendering to hidden div
noInlineCache?: boolean; // if true, preboot_node will NOT cache generated inline code
eventSelectors?: EventSelector[]; // when any of these events occur, they are recorded
appRoot?: string | string[]; // define selectors for one or more server roots
// an alternative for appRoot where you can define separate server and client root selectors
serverClientRoot?: ServerClientRoot[];
}
// our wrapper around DOM events in preboot
interface PrebootEvent {
node: any;
nodeKey?: any;
event: DomEvent;
name: string;
}
// an actual DOM event object
interface DomEvent {
which?: number;
type?: string;
target?: any;
preventDefault(): void;
}
// data on global preboot object for one particular app
interface PrebootAppData {
root: ServerClientRoot;
events: PrebootEvent[];
}
// object that is used to keep track of all the preboot listeners (so we can remove the listeners later)
interface PrebootEventListener {
node: Element;
eventName: string;
handler: Function;
}
// object that contains all data about the currently active node in the DOM (i.e. that has focus)
interface NodeContext {
root: ServerClientRoot;
node: Element;
nodeKey?: string;
selection?: {
start: number,
end: number,
direction: string
};
}
// interface for global object that contains all preboot data
interface PrebootData {
opts?: PrebootOptions;
overlay?: Element;
activeNode?: NodeContext;
apps?: PrebootAppData[];
listeners?: PrebootEventListener[];
}
// global document object
interface Document {
body?: Element;
readyState?: string;
addEventListener?(name?: string, callback?: Function): void;
querySelector?(selector?: string): Element;
querySelectorAll?(selector?: string): Element[];
createElement?(elementName?: string): Element;
}
interface ComputedStyle {
getPropertyValue(prop: string): string;
}
// interface for the global window object
interface Window {
prebootData: PrebootData;
document: Document;
getComputedStyle?(node: Element): ComputedStyle;
}
// this represents a node in the DOM
interface Element {
id?: string;
value?: string;
checked?: boolean;
selected?: boolean;
tagName?: string;
nodeName?: string;
className?: string;
selectionStart?: number;
selectionEnd?: number;
selectionDirection?: string;
selection?: any;
createTextRange?(): any;
setSelectionRange?(fromPos: number, toPos: number, direction: string): void;
style?: {
display?: string;
};
parentNode?: Element;
childNodes?: Element[];
attributes?: string[];
remove?(): void;
focus?(): void;
dispatchEvent?(event: DomEvent): boolean;
getAttribute?(name: string): string;
cloneNode?(deep?: boolean): Element;
insertBefore?(nodeToInsert: Element, beforeNode: Element): Node;
addEventListener?(name: string, callback: Function): void;
removeEventListener?(name: string, callback: Function): void;
querySelector?(selector: string): Element;
querySelectorAll?(selector: string): Element[];
appendChild?(node: Element): Node;
setAttribute?(attrName: string, styles: string): void;
}
export declare function prebootClient(): {
complete: (opts?: PrebootCompleteOptions) => void;
completeApp: (opts: PrebootCompleteOptions, appData: PrebootAppData) => void;
replayEvent: (appData: PrebootAppData, prebootEvent: PrebootEvent) => void;
switchBuffer: (window: Window, appData: PrebootAppData) => void;
cleanup: (window: Window, prebootData: PrebootData) => void;
removeOverlay: (window: Window) => void;
setFocus: (activeNode: NodeContext) => void;
findClientNode: (serverNodeContext: NodeContext) => Element;
getNodeKey: (nodeContext: NodeContext) => string;
};
export declare const defaultOptions: PrebootOptions;
export declare function getBrowserCode(legacyOptions: any): any;
export declare function getInlineCode(customOptions?: PrebootOptions): string;
export declare function assign(target: Object, ...optionSets: any[]): Object;
export declare function stringifyWithFunctions(obj: Object): string;