/
index.ts
176 lines (148 loc) · 4.42 KB
/
index.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
164
165
166
167
168
169
170
171
172
173
174
175
176
import type * as d from '../../declarations';
import { addHostEventListeners } from '@runtime';
export const cmpModules = new Map<string, { [exportName: string]: d.ComponentConstructor }>();
const getModule = (tagName: string): d.ComponentConstructor => {
if (typeof tagName === 'string') {
tagName = tagName.toLowerCase();
const cmpModule = cmpModules.get(tagName);
if (cmpModule != null) {
return cmpModule[tagName];
}
}
return null;
};
export const loadModule = (cmpMeta: d.ComponentRuntimeMeta, _hostRef: d.HostRef, _hmrVersionId?: string): any => {
return getModule(cmpMeta.$tagName$);
};
export const isMemberInElement = (elm: any, memberName: string) => {
if (elm != null) {
if (memberName in elm) {
return true;
}
const cstr = getModule(elm.nodeName);
if (cstr != null) {
const hostRef: d.ComponentNativeConstructor = cstr as any;
if (hostRef != null && hostRef.cmpMeta != null && hostRef.cmpMeta.$members$ != null) {
return memberName in hostRef.cmpMeta.$members$;
}
}
}
return false;
};
export const registerComponents = (Cstrs: d.ComponentNativeConstructor[]) => {
for (const Cstr of Cstrs) {
// using this format so it follows exactly how client-side modules work
const exportName = Cstr.cmpMeta.$tagName$;
cmpModules.set(exportName, {
[exportName]: Cstr,
});
}
};
export const win = window;
export const doc = win.document;
export const readTask = (cb: Function) => {
process.nextTick(() => {
try {
cb();
} catch (e) {
consoleError(e);
}
});
};
export const writeTask = (cb: Function) => {
process.nextTick(() => {
try {
cb();
} catch (e) {
consoleError(e);
}
});
};
const resolved = /*@__PURE__*/ Promise.resolve();
export const nextTick = /*@__PURE__*/ (cb: () => void) => resolved.then(cb);
export const consoleError = (e: any) => {
if (e != null) {
console.error(e.stack || e.message || e);
}
};
export const consoleDevError = (..._: any[]) => {
/* noop for hydrate */
};
export const consoleDevWarn = (..._: any[]) => {
/* noop for hydrate */
};
export const consoleDevInfo = (..._: any[]) => {
/* noop for hydrate */
};
/*hydrate context start*/ export const Context = {}; /*hydrate context end*/
export const plt: d.PlatformRuntime = {
$flags$: 0,
$resourcesUrl$: '',
jmp: h => h(),
raf: h => requestAnimationFrame(h),
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
ce: (eventName, opts) => new win.CustomEvent(eventName, opts),
};
export const supportsShadow = false;
export const supportsListenerOptions = false;
export const supportsConstructibleStylesheets = false;
const hostRefs: WeakMap<d.RuntimeRef, d.HostRef> = new WeakMap();
export const getHostRef = (ref: d.RuntimeRef) => hostRefs.get(ref);
export const registerInstance = (lazyInstance: any, hostRef: d.HostRef) =>
hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
export const registerHost = (elm: d.HostElement, cmpMeta: d.ComponentRuntimeMeta) => {
const hostRef: d.HostRef = {
$flags$: 0,
$cmpMeta$: cmpMeta,
$hostElement$: elm,
$instanceValues$: new Map(),
$renderCount$: 0,
};
hostRef.$onInstancePromise$ = new Promise(r => (hostRef.$onInstanceResolve$ = r));
hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
elm['s-p'] = [];
elm['s-rc'] = [];
addHostEventListeners(elm, hostRef, cmpMeta.$listeners$, false);
return hostRefs.set(elm, hostRef);
};
export const Build: d.UserBuildConditionals = {
isDev: false,
isBrowser: false,
isServer: true,
isTesting: false,
};
export const styles: d.StyleMap = new Map();
export const modeResolutionChain: d.ResolutionHandler[] = [];
export { BUILD, NAMESPACE } from '@app-data';
export { hydrateApp } from './hydrate-app';
export {
addHostEventListeners,
attachShadow,
defineCustomElement,
forceModeUpdate,
proxyCustomElement,
bootstrapLazy,
connectedCallback,
createEvent,
disconnectedCallback,
getAssetPath,
setAssetPath,
getConnect,
getContext,
getElement,
getValue,
setValue,
Fragment,
Host,
insertVdomAnnotations,
parsePropertyValue,
forceUpdate,
postUpdateComponent,
getRenderingRef,
proxyComponent,
renderVdom,
setMode,
getMode,
} from '@runtime';
export { hAsync as h } from './h-async';