@rindo/core 2.18.0 → 2.22.2
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/cli/config-flags.d.ts +33 -21
- package/cli/index.cjs +670 -388
- package/cli/index.d.ts +3 -0
- package/cli/index.js +670 -388
- package/cli/package.json +1 -1
- package/compiler/lib.dom.d.ts +434 -251
- package/compiler/lib.dom.iterable.d.ts +7 -13
- package/compiler/lib.es2015.collection.d.ts +62 -1
- package/compiler/lib.es2015.promise.d.ts +9 -4
- package/compiler/lib.es2015.proxy.d.ts +91 -2
- package/compiler/lib.es2015.reflect.d.ts +25 -2
- package/compiler/lib.es2015.symbol.wellknown.d.ts +3 -3
- package/compiler/lib.es2017.intl.d.ts +16 -1
- package/compiler/lib.es2019.d.ts +1 -0
- package/compiler/lib.es2019.intl.d.ts +25 -0
- package/compiler/lib.es2020.intl.d.ts +31 -6
- package/compiler/lib.es2021.intl.d.ts +11 -3
- package/compiler/lib.es2022.d.ts +1 -0
- package/compiler/lib.es2022.error.d.ts +2 -2
- package/compiler/lib.es2022.sharedmemory.d.ts +27 -0
- package/compiler/lib.es5.d.ts +39 -14
- package/compiler/lib.esnext.intl.d.ts +5 -1
- package/compiler/lib.webworker.d.ts +318 -55
- package/compiler/lib.webworker.iterable.d.ts +11 -3
- package/compiler/package.json +1 -1
- package/compiler/rindo.d.ts +3 -25
- package/compiler/rindo.js +53912 -51834
- package/compiler/rindo.min.js +2 -2
- package/compiler/sys/in-memory-fs.d.ts +3 -3
- package/compiler/transpile.d.ts +32 -0
- package/dependencies.json +3 -1
- package/dev-server/client/app-error.d.ts +1 -1
- package/dev-server/client/index.d.ts +2 -2
- package/dev-server/client/index.js +241 -241
- package/dev-server/client/package.json +1 -1
- package/dev-server/connector.html +3 -3
- package/dev-server/index.d.ts +1 -1
- package/dev-server/index.js +2 -2
- package/dev-server/open-in-editor-api.js +1 -1
- package/dev-server/package.json +1 -1
- package/dev-server/server-process.js +1182 -1148
- package/dev-server/ws.js +1 -1
- package/internal/app-data/package.json +1 -1
- package/internal/client/css-shim.js +2 -2
- package/internal/client/dom.js +1 -1
- package/internal/client/index.js +800 -673
- package/internal/client/package.json +1 -1
- package/internal/client/patch-browser.js +19 -1
- package/internal/client/patch-esm.js +1 -1
- package/internal/client/polyfills/css-shim.js +1 -1
- package/internal/client/shadow-css.js +1 -1
- package/internal/hydrate/index.js +154 -143
- package/internal/hydrate/package.json +1 -1
- package/internal/hydrate/runner.d.ts +1 -1
- package/internal/hydrate/runner.js +106 -106
- package/internal/package.json +1 -1
- package/internal/rindo-core/index.d.ts +9 -10
- package/internal/rindo-private.d.ts +149 -80
- package/internal/rindo-public-compiler.d.ts +42 -31
- package/internal/rindo-public-docs.d.ts +24 -0
- package/internal/rindo-public-runtime.d.ts +79 -7
- package/internal/testing/index.js +187 -175
- package/internal/testing/package.json +1 -1
- package/mock-doc/index.cjs +905 -896
- package/mock-doc/index.d.ts +2 -2
- package/mock-doc/index.js +905 -896
- package/mock-doc/package.json +1 -1
- package/package.json +48 -57
- package/readme.md +44 -31
- package/screenshot/compare/build/p-f4745c2f.entry.js +1 -1
- package/screenshot/index.d.ts +1 -1
- package/screenshot/index.js +3 -3
- package/screenshot/package.json +1 -1
- package/screenshot/pixel-match.js +983 -849
- package/sys/node/autoprefixer.js +2 -2
- package/sys/node/glob.js +1 -1
- package/sys/node/index.d.ts +4 -0
- package/sys/node/index.js +399 -413
- package/sys/node/package.json +1 -1
- package/sys/node/prompts.js +1 -1
- package/sys/node/worker.js +1 -1
- package/testing/index.d.ts +6 -6
- package/testing/index.js +1136 -1277
- package/testing/jest/jest-config.d.ts +1 -1
- package/testing/jest/jest-preprocessor.d.ts +3 -3
- package/testing/jest/jest-serializer.d.ts +1 -2
- package/testing/matchers/index.d.ts +3 -3
- package/testing/mock-fetch.d.ts +1 -1
- package/testing/mocks.d.ts +2 -2
- package/testing/package.json +1 -1
- package/testing/puppeteer/puppeteer-declarations.d.ts +5 -5
- package/testing/puppeteer/puppeteer-element.d.ts +2 -2
- package/testing/puppeteer/puppeteer-events.d.ts +1 -1
- package/testing/testing-logger.d.ts +1 -1
- package/testing/testing-utils.d.ts +1 -1
- package/testing/testing.d.ts +1 -1
package/internal/client/index.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
3
|
+
* Simon Friis Vindum (@paldepind)
|
|
4
|
+
* Licensed under the MIT License
|
|
5
|
+
* https://github.com/snabbdom/snabbdom/blob/master/LICENSE
|
|
6
|
+
*
|
|
7
|
+
* Modified for Rindo's renderer and slot projection
|
|
8
|
+
*/
|
|
1
9
|
let scopeId;
|
|
2
10
|
let contentRef;
|
|
3
11
|
let hostTagName;
|
|
@@ -11,129 +19,21 @@ let renderingRef = null;
|
|
|
11
19
|
let queueCongestion = 0;
|
|
12
20
|
let queuePending = false;
|
|
13
21
|
/*
|
|
14
|
-
Rindo Client Platform v2.
|
|
22
|
+
Rindo Client Platform v2.22.2 | MIT Licensed | https://rindojs.web.app
|
|
15
23
|
*/
|
|
16
24
|
import { BUILD, NAMESPACE } from '@rindo/core/internal/app-data';
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const plt = {
|
|
23
|
-
$flags$: 0,
|
|
24
|
-
$resourcesUrl$: '',
|
|
25
|
-
jmp: (h) => h(),
|
|
26
|
-
raf: (h) => requestAnimationFrame(h),
|
|
27
|
-
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
28
|
-
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
29
|
-
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
30
|
-
};
|
|
31
|
-
const setPlatformHelpers = (helpers) => {
|
|
32
|
-
Object.assign(plt, helpers);
|
|
25
|
+
const Build = {
|
|
26
|
+
isDev: BUILD.isDev ? true : false,
|
|
27
|
+
isBrowser: true,
|
|
28
|
+
isServer: false,
|
|
29
|
+
isTesting: BUILD.isTesting ? true : false,
|
|
33
30
|
};
|
|
34
|
-
const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom
|
|
35
|
-
? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)()
|
|
36
|
-
: true;
|
|
37
|
-
const supportsListenerOptions = /*@__PURE__*/ (() => {
|
|
38
|
-
let supportsListenerOptions = false;
|
|
39
|
-
try {
|
|
40
|
-
doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
|
|
41
|
-
get() {
|
|
42
|
-
supportsListenerOptions = true;
|
|
43
|
-
},
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
catch (e) { }
|
|
47
|
-
return supportsListenerOptions;
|
|
48
|
-
})();
|
|
49
|
-
const promiseResolve = (v) => Promise.resolve(v);
|
|
50
|
-
const supportsConstructableStylesheets = BUILD.constructableCSS
|
|
51
|
-
? /*@__PURE__*/ (() => {
|
|
52
|
-
try {
|
|
53
|
-
new CSSStyleSheet();
|
|
54
|
-
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
55
|
-
}
|
|
56
|
-
catch (e) { }
|
|
57
|
-
return false;
|
|
58
|
-
})()
|
|
59
|
-
: false;
|
|
60
31
|
const Context = {};
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// initialize our event listeners on the host element
|
|
65
|
-
// we do this now so that we can listen to events that may
|
|
66
|
-
// have fired even before the instance is ready
|
|
67
|
-
if (BUILD.hostListenerTargetParent) {
|
|
68
|
-
// this component may have event listeners that should be attached to the parent
|
|
69
|
-
if (attachParentListeners) {
|
|
70
|
-
// this is being ran from within the connectedCallback
|
|
71
|
-
// which is important so that we know the host element actually has a parent element
|
|
72
|
-
// filter out the listeners to only have the ones that ARE being attached to the parent
|
|
73
|
-
listeners = listeners.filter(([flags]) => flags & 32 /* LISTENER_FLAGS.TargetParent */);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// this is being ran from within the component constructor
|
|
77
|
-
// everything BUT the parent element listeners should be attached at this time
|
|
78
|
-
// filter out the listeners that are NOT being attached to the parent
|
|
79
|
-
listeners = listeners.filter(([flags]) => !(flags & 32 /* LISTENER_FLAGS.TargetParent */));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
listeners.map(([flags, name, method]) => {
|
|
83
|
-
const target = BUILD.hostListenerTarget ? getHostListenerTarget(elm, flags) : elm;
|
|
84
|
-
const handler = hostListenerProxy(hostRef, method);
|
|
85
|
-
const opts = hostListenerOpts(flags);
|
|
86
|
-
plt.ael(target, name, handler, opts);
|
|
87
|
-
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
92
|
-
try {
|
|
93
|
-
if (BUILD.lazyLoad) {
|
|
94
|
-
if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
|
|
95
|
-
// instance is ready, let's call it's member method for this event
|
|
96
|
-
hostRef.$lazyInstance$[methodName](ev);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
hostRef.$hostElement$[methodName](ev);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (e) {
|
|
107
|
-
consoleError(e);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const getHostListenerTarget = (elm, flags) => {
|
|
111
|
-
if (BUILD.hostListenerTargetDocument && flags & 4 /* LISTENER_FLAGS.TargetDocument */)
|
|
112
|
-
return doc;
|
|
113
|
-
if (BUILD.hostListenerTargetWindow && flags & 8 /* LISTENER_FLAGS.TargetWindow */)
|
|
114
|
-
return win;
|
|
115
|
-
if (BUILD.hostListenerTargetBody && flags & 16 /* LISTENER_FLAGS.TargetBody */)
|
|
116
|
-
return doc.body;
|
|
117
|
-
if (BUILD.hostListenerTargetParent && flags & 32 /* LISTENER_FLAGS.TargetParent */)
|
|
118
|
-
return elm.parentElement;
|
|
119
|
-
return elm;
|
|
32
|
+
const getAssetPath = (path) => {
|
|
33
|
+
const assetUrl = new URL(path, plt.$resourcesUrl$);
|
|
34
|
+
return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
|
|
120
35
|
};
|
|
121
|
-
|
|
122
|
-
const hostListenerOpts = (flags) => supportsListenerOptions
|
|
123
|
-
? ({
|
|
124
|
-
passive: (flags & 1 /* LISTENER_FLAGS.Passive */) !== 0,
|
|
125
|
-
capture: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0,
|
|
126
|
-
})
|
|
127
|
-
: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
|
|
128
|
-
const CONTENT_REF_ID = 'r';
|
|
129
|
-
const ORG_LOCATION_ID = 'o';
|
|
130
|
-
const SLOT_NODE_ID = 's';
|
|
131
|
-
const TEXT_NODE_ID = 't';
|
|
132
|
-
const HYDRATE_ID = 's-id';
|
|
133
|
-
const HYDRATED_STYLE_ID = 'sty-id';
|
|
134
|
-
const HYDRATE_CHILD_ID = 'c-id';
|
|
135
|
-
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
136
|
-
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
36
|
+
const setAssetPath = (path) => (plt.$resourcesUrl$ = path);
|
|
137
37
|
const createTime = (fnName, tagName = '') => {
|
|
138
38
|
if (BUILD.profile && performance.mark) {
|
|
139
39
|
const key = `st:${fnName}:${tagName}:${i++}`;
|
|
@@ -150,11 +50,11 @@ const createTime = (fnName, tagName = '') => {
|
|
|
150
50
|
};
|
|
151
51
|
const uniqueTime = (key, measureText) => {
|
|
152
52
|
if (BUILD.profile && performance.mark) {
|
|
153
|
-
if (performance.getEntriesByName(key).length === 0) {
|
|
53
|
+
if (performance.getEntriesByName(key, 'mark').length === 0) {
|
|
154
54
|
performance.mark(key);
|
|
155
55
|
}
|
|
156
56
|
return () => {
|
|
157
|
-
if (performance.getEntriesByName(measureText).length === 0) {
|
|
57
|
+
if (performance.getEntriesByName(measureText, 'measure').length === 0) {
|
|
158
58
|
performance.measure(measureText, key);
|
|
159
59
|
}
|
|
160
60
|
};
|
|
@@ -220,6 +120,529 @@ const installDevTools = () => {
|
|
|
220
120
|
};
|
|
221
121
|
}
|
|
222
122
|
};
|
|
123
|
+
const CONTENT_REF_ID = 'r';
|
|
124
|
+
const ORG_LOCATION_ID = 'o';
|
|
125
|
+
const SLOT_NODE_ID = 's';
|
|
126
|
+
const TEXT_NODE_ID = 't';
|
|
127
|
+
const HYDRATE_ID = 's-id';
|
|
128
|
+
const HYDRATED_STYLE_ID = 'sty-id';
|
|
129
|
+
const HYDRATE_CHILD_ID = 'c-id';
|
|
130
|
+
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
131
|
+
const XLINK_NS = 'http://www.w3.org/1999/xlink';
|
|
132
|
+
/**
|
|
133
|
+
* Default style mode id
|
|
134
|
+
*/
|
|
135
|
+
/**
|
|
136
|
+
* Reusable empty obj/array
|
|
137
|
+
* Don't add values to these!!
|
|
138
|
+
*/
|
|
139
|
+
const EMPTY_OBJ = {};
|
|
140
|
+
/**
|
|
141
|
+
* Namespaces
|
|
142
|
+
*/
|
|
143
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
144
|
+
const HTML_NS = 'http://www.w3.org/1999/xhtml';
|
|
145
|
+
const isDef = (v) => v != null;
|
|
146
|
+
const isComplexType = (o) => {
|
|
147
|
+
// https://jsperf.com/typeof-fn-object/5
|
|
148
|
+
o = typeof o;
|
|
149
|
+
return o === 'object' || o === 'function';
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Helper method for querying a `meta` tag that contains a nonce value
|
|
153
|
+
* out of a DOM's head.
|
|
154
|
+
*
|
|
155
|
+
* @param doc The DOM containing the `head` to query against
|
|
156
|
+
* @returns The content of the meta tag representing the nonce value, or `undefined` if no tag
|
|
157
|
+
* exists or the tag has no content.
|
|
158
|
+
*/
|
|
159
|
+
function queryNonceMetaTagContent(doc) {
|
|
160
|
+
var _a, _b, _c;
|
|
161
|
+
return (_c = (_b = (_a = doc.head) === null || _a === void 0 ? void 0 : _a.querySelector('meta[name="csp-nonce"]')) === null || _b === void 0 ? void 0 : _b.getAttribute('content')) !== null && _c !== void 0 ? _c : undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Production h() function based on Preact by
|
|
165
|
+
* Jason Miller (@developit)
|
|
166
|
+
* Licensed under the MIT License
|
|
167
|
+
* https://github.com/developit/preact/blob/master/LICENSE
|
|
168
|
+
*
|
|
169
|
+
* Modified for Rindo's compiler and vdom
|
|
170
|
+
*/
|
|
171
|
+
// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
|
|
172
|
+
// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
|
|
173
|
+
const h = (nodeName, vnodeData, ...children) => {
|
|
174
|
+
let child = null;
|
|
175
|
+
let key = null;
|
|
176
|
+
let slotName = null;
|
|
177
|
+
let simple = false;
|
|
178
|
+
let lastSimple = false;
|
|
179
|
+
const vNodeChildren = [];
|
|
180
|
+
const walk = (c) => {
|
|
181
|
+
for (let i = 0; i < c.length; i++) {
|
|
182
|
+
child = c[i];
|
|
183
|
+
if (Array.isArray(child)) {
|
|
184
|
+
walk(child);
|
|
185
|
+
}
|
|
186
|
+
else if (child != null && typeof child !== 'boolean') {
|
|
187
|
+
if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
|
|
188
|
+
child = String(child);
|
|
189
|
+
}
|
|
190
|
+
else if (BUILD.isDev && typeof nodeName !== 'function' && child.$flags$ === undefined) {
|
|
191
|
+
consoleDevError(`vNode passed as children has unexpected type.
|
|
192
|
+
Make sure it's using the correct h() function.
|
|
193
|
+
Empty objects can also be the cause, look for JSX comments that became objects.`);
|
|
194
|
+
}
|
|
195
|
+
if (simple && lastSimple) {
|
|
196
|
+
// If the previous child was simple (string), we merge both
|
|
197
|
+
vNodeChildren[vNodeChildren.length - 1].$text$ += child;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
// Append a new vNode, if it's text, we create a text vNode
|
|
201
|
+
vNodeChildren.push(simple ? newVNode(null, child) : child);
|
|
202
|
+
}
|
|
203
|
+
lastSimple = simple;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
walk(children);
|
|
208
|
+
if (vnodeData) {
|
|
209
|
+
if (BUILD.isDev && nodeName === 'input') {
|
|
210
|
+
validateInputProperties(vnodeData);
|
|
211
|
+
}
|
|
212
|
+
// normalize class / classname attributes
|
|
213
|
+
if (BUILD.vdomKey && vnodeData.key) {
|
|
214
|
+
key = vnodeData.key;
|
|
215
|
+
}
|
|
216
|
+
if (BUILD.slotRelocation && vnodeData.name) {
|
|
217
|
+
slotName = vnodeData.name;
|
|
218
|
+
}
|
|
219
|
+
if (BUILD.vdomClass) {
|
|
220
|
+
const classData = vnodeData.className || vnodeData.class;
|
|
221
|
+
if (classData) {
|
|
222
|
+
vnodeData.class =
|
|
223
|
+
typeof classData !== 'object'
|
|
224
|
+
? classData
|
|
225
|
+
: Object.keys(classData)
|
|
226
|
+
.filter((k) => classData[k])
|
|
227
|
+
.join(' ');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (BUILD.isDev && vNodeChildren.some(isHost)) {
|
|
232
|
+
consoleDevError(`The <Host> must be the single root component. Make sure:
|
|
233
|
+
- You are NOT using hostData() and <Host> in the same component.
|
|
234
|
+
- <Host> is used once, and it's the single root component of the render() function.`);
|
|
235
|
+
}
|
|
236
|
+
if (BUILD.vdomFunctional && typeof nodeName === 'function') {
|
|
237
|
+
// nodeName is a functional component
|
|
238
|
+
return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
|
|
239
|
+
}
|
|
240
|
+
const vnode = newVNode(nodeName, null);
|
|
241
|
+
vnode.$attrs$ = vnodeData;
|
|
242
|
+
if (vNodeChildren.length > 0) {
|
|
243
|
+
vnode.$children$ = vNodeChildren;
|
|
244
|
+
}
|
|
245
|
+
if (BUILD.vdomKey) {
|
|
246
|
+
vnode.$key$ = key;
|
|
247
|
+
}
|
|
248
|
+
if (BUILD.slotRelocation) {
|
|
249
|
+
vnode.$name$ = slotName;
|
|
250
|
+
}
|
|
251
|
+
return vnode;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* A utility function for creating a virtual DOM node from a tag and some
|
|
255
|
+
* possible text content.
|
|
256
|
+
*
|
|
257
|
+
* @param tag the tag for this element
|
|
258
|
+
* @param text possible text content for the node
|
|
259
|
+
* @returns a newly-minted virtual DOM node
|
|
260
|
+
*/
|
|
261
|
+
const newVNode = (tag, text) => {
|
|
262
|
+
const vnode = {
|
|
263
|
+
$flags$: 0,
|
|
264
|
+
$tag$: tag,
|
|
265
|
+
$text$: text,
|
|
266
|
+
$elm$: null,
|
|
267
|
+
$children$: null,
|
|
268
|
+
};
|
|
269
|
+
if (BUILD.vdomAttribute) {
|
|
270
|
+
vnode.$attrs$ = null;
|
|
271
|
+
}
|
|
272
|
+
if (BUILD.vdomKey) {
|
|
273
|
+
vnode.$key$ = null;
|
|
274
|
+
}
|
|
275
|
+
if (BUILD.slotRelocation) {
|
|
276
|
+
vnode.$name$ = null;
|
|
277
|
+
}
|
|
278
|
+
return vnode;
|
|
279
|
+
};
|
|
280
|
+
const Host = {};
|
|
281
|
+
/**
|
|
282
|
+
* Check whether a given node is a Host node or not
|
|
283
|
+
*
|
|
284
|
+
* @param node the virtual DOM node to check
|
|
285
|
+
* @returns whether it's a Host node or not
|
|
286
|
+
*/
|
|
287
|
+
const isHost = (node) => node && node.$tag$ === Host;
|
|
288
|
+
/**
|
|
289
|
+
* Implementation of {@link d.FunctionalUtilities} for Rindo's VDom.
|
|
290
|
+
*
|
|
291
|
+
* Note that these functions convert from {@link d.VNode} to
|
|
292
|
+
* {@link d.ChildNode} to give functional component developers a friendly
|
|
293
|
+
* interface.
|
|
294
|
+
*/
|
|
295
|
+
const vdomFnUtils = {
|
|
296
|
+
forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
|
|
297
|
+
map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* Convert a {@link d.VNode} to a {@link d.ChildNode} in order to present a
|
|
301
|
+
* friendlier public interface (hence, 'convertToPublic').
|
|
302
|
+
*
|
|
303
|
+
* @param node the virtual DOM node to convert
|
|
304
|
+
* @returns a converted child node
|
|
305
|
+
*/
|
|
306
|
+
const convertToPublic = (node) => ({
|
|
307
|
+
vattrs: node.$attrs$,
|
|
308
|
+
vchildren: node.$children$,
|
|
309
|
+
vkey: node.$key$,
|
|
310
|
+
vname: node.$name$,
|
|
311
|
+
vtag: node.$tag$,
|
|
312
|
+
vtext: node.$text$,
|
|
313
|
+
});
|
|
314
|
+
/**
|
|
315
|
+
* Convert a {@link d.ChildNode} back to an equivalent {@link d.VNode} in
|
|
316
|
+
* order to use the resulting object in the virtual DOM. The initial object was
|
|
317
|
+
* likely created as part of presenting a public API, so converting it back
|
|
318
|
+
* involved making it 'private' again (hence, `convertToPrivate`).
|
|
319
|
+
*
|
|
320
|
+
* @param node the child node to convert
|
|
321
|
+
* @returns a converted virtual DOM node
|
|
322
|
+
*/
|
|
323
|
+
const convertToPrivate = (node) => {
|
|
324
|
+
if (typeof node.vtag === 'function') {
|
|
325
|
+
const vnodeData = Object.assign({}, node.vattrs);
|
|
326
|
+
if (node.vkey) {
|
|
327
|
+
vnodeData.key = node.vkey;
|
|
328
|
+
}
|
|
329
|
+
if (node.vname) {
|
|
330
|
+
vnodeData.name = node.vname;
|
|
331
|
+
}
|
|
332
|
+
return h(node.vtag, vnodeData, ...(node.vchildren || []));
|
|
333
|
+
}
|
|
334
|
+
const vnode = newVNode(node.vtag, node.vtext);
|
|
335
|
+
vnode.$attrs$ = node.vattrs;
|
|
336
|
+
vnode.$children$ = node.vchildren;
|
|
337
|
+
vnode.$key$ = node.vkey;
|
|
338
|
+
vnode.$name$ = node.vname;
|
|
339
|
+
return vnode;
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Validates the ordering of attributes on an input element
|
|
343
|
+
*
|
|
344
|
+
* @param inputElm the element to validate
|
|
345
|
+
*/
|
|
346
|
+
const validateInputProperties = (inputElm) => {
|
|
347
|
+
const props = Object.keys(inputElm);
|
|
348
|
+
const value = props.indexOf('value');
|
|
349
|
+
if (value === -1) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const typeIndex = props.indexOf('type');
|
|
353
|
+
const minIndex = props.indexOf('min');
|
|
354
|
+
const maxIndex = props.indexOf('max');
|
|
355
|
+
const stepIndex = props.indexOf('step');
|
|
356
|
+
if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
|
|
357
|
+
consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
|
|
361
|
+
const endHydrate = createTime('hydrateClient', tagName);
|
|
362
|
+
const shadowRoot = hostElm.shadowRoot;
|
|
363
|
+
const childRenderNodes = [];
|
|
364
|
+
const slotNodes = [];
|
|
365
|
+
const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
|
|
366
|
+
const vnode = (hostRef.$vnode$ = newVNode(tagName, null));
|
|
367
|
+
if (!plt.$orgLocNodes$) {
|
|
368
|
+
initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
|
|
369
|
+
}
|
|
370
|
+
hostElm[HYDRATE_ID] = hostId;
|
|
371
|
+
hostElm.removeAttribute(HYDRATE_ID);
|
|
372
|
+
clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
|
|
373
|
+
childRenderNodes.map((c) => {
|
|
374
|
+
const orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
|
|
375
|
+
const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
|
|
376
|
+
const node = c.$elm$;
|
|
377
|
+
if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
|
|
378
|
+
orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
|
|
379
|
+
}
|
|
380
|
+
if (!shadowRoot) {
|
|
381
|
+
node['s-hn'] = tagName;
|
|
382
|
+
if (orgLocationNode) {
|
|
383
|
+
node['s-ol'] = orgLocationNode;
|
|
384
|
+
node['s-ol']['s-nr'] = node;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
plt.$orgLocNodes$.delete(orgLocationId);
|
|
388
|
+
});
|
|
389
|
+
if (BUILD.shadowDom && shadowRoot) {
|
|
390
|
+
shadowRootNodes.map((shadowRootNode) => {
|
|
391
|
+
if (shadowRootNode) {
|
|
392
|
+
shadowRoot.appendChild(shadowRootNode);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
endHydrate();
|
|
397
|
+
};
|
|
398
|
+
const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) => {
|
|
399
|
+
let childNodeType;
|
|
400
|
+
let childIdSplt;
|
|
401
|
+
let childVNode;
|
|
402
|
+
let i;
|
|
403
|
+
if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
404
|
+
childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
|
|
405
|
+
if (childNodeType) {
|
|
406
|
+
// got the node data from the element's attribute
|
|
407
|
+
// `${hostId}.${nodeId}.${depth}.${index}`
|
|
408
|
+
childIdSplt = childNodeType.split('.');
|
|
409
|
+
if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
|
|
410
|
+
childVNode = {
|
|
411
|
+
$flags$: 0,
|
|
412
|
+
$hostId$: childIdSplt[0],
|
|
413
|
+
$nodeId$: childIdSplt[1],
|
|
414
|
+
$depth$: childIdSplt[2],
|
|
415
|
+
$index$: childIdSplt[3],
|
|
416
|
+
$tag$: node.tagName.toLowerCase(),
|
|
417
|
+
$elm$: node,
|
|
418
|
+
$attrs$: null,
|
|
419
|
+
$children$: null,
|
|
420
|
+
$key$: null,
|
|
421
|
+
$name$: null,
|
|
422
|
+
$text$: null,
|
|
423
|
+
};
|
|
424
|
+
childRenderNodes.push(childVNode);
|
|
425
|
+
node.removeAttribute(HYDRATE_CHILD_ID);
|
|
426
|
+
// this is a new child vnode
|
|
427
|
+
// so ensure its parent vnode has the vchildren array
|
|
428
|
+
if (!parentVNode.$children$) {
|
|
429
|
+
parentVNode.$children$ = [];
|
|
430
|
+
}
|
|
431
|
+
// add our child vnode to a specific index of the vnode's children
|
|
432
|
+
parentVNode.$children$[childVNode.$index$] = childVNode;
|
|
433
|
+
// this is now the new parent vnode for all the next child checks
|
|
434
|
+
parentVNode = childVNode;
|
|
435
|
+
if (shadowRootNodes && childVNode.$depth$ === '0') {
|
|
436
|
+
shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
// recursively drill down, end to start so we can remove nodes
|
|
441
|
+
for (i = node.childNodes.length - 1; i >= 0; i--) {
|
|
442
|
+
clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
|
|
443
|
+
}
|
|
444
|
+
if (node.shadowRoot) {
|
|
445
|
+
// keep drilling down through the shadow root nodes
|
|
446
|
+
for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
|
|
447
|
+
clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
|
|
452
|
+
// `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
|
|
453
|
+
childIdSplt = node.nodeValue.split('.');
|
|
454
|
+
if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
|
|
455
|
+
// comment node for either the host id or a 0 host id
|
|
456
|
+
childNodeType = childIdSplt[0];
|
|
457
|
+
childVNode = {
|
|
458
|
+
$flags$: 0,
|
|
459
|
+
$hostId$: childIdSplt[1],
|
|
460
|
+
$nodeId$: childIdSplt[2],
|
|
461
|
+
$depth$: childIdSplt[3],
|
|
462
|
+
$index$: childIdSplt[4],
|
|
463
|
+
$elm$: node,
|
|
464
|
+
$attrs$: null,
|
|
465
|
+
$children$: null,
|
|
466
|
+
$key$: null,
|
|
467
|
+
$name$: null,
|
|
468
|
+
$tag$: null,
|
|
469
|
+
$text$: null,
|
|
470
|
+
};
|
|
471
|
+
if (childNodeType === TEXT_NODE_ID) {
|
|
472
|
+
childVNode.$elm$ = node.nextSibling;
|
|
473
|
+
if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* NODE_TYPE.TextNode */) {
|
|
474
|
+
childVNode.$text$ = childVNode.$elm$.textContent;
|
|
475
|
+
childRenderNodes.push(childVNode);
|
|
476
|
+
// remove the text comment since it's no longer needed
|
|
477
|
+
node.remove();
|
|
478
|
+
if (!parentVNode.$children$) {
|
|
479
|
+
parentVNode.$children$ = [];
|
|
480
|
+
}
|
|
481
|
+
parentVNode.$children$[childVNode.$index$] = childVNode;
|
|
482
|
+
if (shadowRootNodes && childVNode.$depth$ === '0') {
|
|
483
|
+
shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else if (childVNode.$hostId$ === hostId) {
|
|
488
|
+
// this comment node is specifcally for this host id
|
|
489
|
+
if (childNodeType === SLOT_NODE_ID) {
|
|
490
|
+
// `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
|
|
491
|
+
childVNode.$tag$ = 'slot';
|
|
492
|
+
if (childIdSplt[5]) {
|
|
493
|
+
node['s-sn'] = childVNode.$name$ = childIdSplt[5];
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
node['s-sn'] = '';
|
|
497
|
+
}
|
|
498
|
+
node['s-sr'] = true;
|
|
499
|
+
if (BUILD.shadowDom && shadowRootNodes) {
|
|
500
|
+
// browser support shadowRoot and this is a shadow dom component
|
|
501
|
+
// create an actual slot element
|
|
502
|
+
childVNode.$elm$ = doc.createElement(childVNode.$tag$);
|
|
503
|
+
if (childVNode.$name$) {
|
|
504
|
+
// add the slot name attribute
|
|
505
|
+
childVNode.$elm$.setAttribute('name', childVNode.$name$);
|
|
506
|
+
}
|
|
507
|
+
// insert the new slot element before the slot comment
|
|
508
|
+
node.parentNode.insertBefore(childVNode.$elm$, node);
|
|
509
|
+
// remove the slot comment since it's not needed for shadow
|
|
510
|
+
node.remove();
|
|
511
|
+
if (childVNode.$depth$ === '0') {
|
|
512
|
+
shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
slotNodes.push(childVNode);
|
|
516
|
+
if (!parentVNode.$children$) {
|
|
517
|
+
parentVNode.$children$ = [];
|
|
518
|
+
}
|
|
519
|
+
parentVNode.$children$[childVNode.$index$] = childVNode;
|
|
520
|
+
}
|
|
521
|
+
else if (childNodeType === CONTENT_REF_ID) {
|
|
522
|
+
// `${CONTENT_REF_ID}.${hostId}`;
|
|
523
|
+
if (BUILD.shadowDom && shadowRootNodes) {
|
|
524
|
+
// remove the content ref comment since it's not needed for shadow
|
|
525
|
+
node.remove();
|
|
526
|
+
}
|
|
527
|
+
else if (BUILD.slotRelocation) {
|
|
528
|
+
hostElm['s-cr'] = node;
|
|
529
|
+
node['s-cn'] = true;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
else if (parentVNode && parentVNode.$tag$ === 'style') {
|
|
536
|
+
const vnode = newVNode(null, node.textContent);
|
|
537
|
+
vnode.$elm$ = node;
|
|
538
|
+
vnode.$index$ = '0';
|
|
539
|
+
parentVNode.$children$ = [vnode];
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
const initializeDocumentHydrate = (node, orgLocNodes) => {
|
|
543
|
+
if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
544
|
+
let i = 0;
|
|
545
|
+
for (; i < node.childNodes.length; i++) {
|
|
546
|
+
initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
|
|
547
|
+
}
|
|
548
|
+
if (node.shadowRoot) {
|
|
549
|
+
for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
|
|
550
|
+
initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
|
|
555
|
+
const childIdSplt = node.nodeValue.split('.');
|
|
556
|
+
if (childIdSplt[0] === ORG_LOCATION_ID) {
|
|
557
|
+
orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
|
|
558
|
+
node.nodeValue = '';
|
|
559
|
+
// useful to know if the original location is
|
|
560
|
+
// the root light-dom of a shadow dom component
|
|
561
|
+
node['s-en'] = childIdSplt[3];
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
// Private
|
|
566
|
+
const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
|
|
567
|
+
// Public
|
|
568
|
+
const setMode = (handler) => modeResolutionChain.push(handler);
|
|
569
|
+
const getMode = (ref) => getHostRef(ref).$modeName$;
|
|
570
|
+
/**
|
|
571
|
+
* Parse a new property value for a given property type.
|
|
572
|
+
*
|
|
573
|
+
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
574
|
+
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
575
|
+
* 1. `any`, the type given to `propValue` in the function signature
|
|
576
|
+
* 2. the type stored from `propType`.
|
|
577
|
+
*
|
|
578
|
+
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
579
|
+
*
|
|
580
|
+
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
581
|
+
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
582
|
+
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
583
|
+
* ```tsx
|
|
584
|
+
* <my-cmp prop-val={0}></my-cmp>
|
|
585
|
+
* ```
|
|
586
|
+
*
|
|
587
|
+
* HTML prop values on the other hand, will always a string
|
|
588
|
+
*
|
|
589
|
+
* @param propValue the new value to coerce to some type
|
|
590
|
+
* @param propType the type of the prop, expressed as a binary number
|
|
591
|
+
* @returns the parsed/coerced value
|
|
592
|
+
*/
|
|
593
|
+
const parsePropertyValue = (propValue, propType) => {
|
|
594
|
+
// ensure this value is of the correct prop type
|
|
595
|
+
if (propValue != null && !isComplexType(propValue)) {
|
|
596
|
+
if (BUILD.propBoolean && propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
597
|
+
// per the HTML spec, any string value means it is a boolean true value
|
|
598
|
+
// but we'll cheat here and say that the string "false" is the boolean false
|
|
599
|
+
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
600
|
+
}
|
|
601
|
+
if (BUILD.propNumber && propType & 2 /* MEMBER_FLAGS.Number */) {
|
|
602
|
+
// force it to be a number
|
|
603
|
+
return parseFloat(propValue);
|
|
604
|
+
}
|
|
605
|
+
if (BUILD.propString && propType & 1 /* MEMBER_FLAGS.String */) {
|
|
606
|
+
// could have been passed as a number or boolean
|
|
607
|
+
// but we still want it as a string
|
|
608
|
+
return String(propValue);
|
|
609
|
+
}
|
|
610
|
+
// redundant return here for better minification
|
|
611
|
+
return propValue;
|
|
612
|
+
}
|
|
613
|
+
// not sure exactly what type we want
|
|
614
|
+
// so no need to change to a different type
|
|
615
|
+
return propValue;
|
|
616
|
+
};
|
|
617
|
+
const getElement = (ref) => (BUILD.lazyLoad ? getHostRef(ref).$hostElement$ : ref);
|
|
618
|
+
const createEvent = (ref, name, flags) => {
|
|
619
|
+
const elm = getElement(ref);
|
|
620
|
+
return {
|
|
621
|
+
emit: (detail) => {
|
|
622
|
+
if (BUILD.isDev && !elm.isConnected) {
|
|
623
|
+
consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
|
|
624
|
+
}
|
|
625
|
+
return emitEvent(elm, name, {
|
|
626
|
+
bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
|
|
627
|
+
composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
|
|
628
|
+
cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
|
|
629
|
+
detail,
|
|
630
|
+
});
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
};
|
|
634
|
+
/**
|
|
635
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
636
|
+
* @param elm the target of the Event
|
|
637
|
+
* @param name the name to give the custom Event
|
|
638
|
+
* @param opts options for configuring a custom Event
|
|
639
|
+
* @returns the custom Event
|
|
640
|
+
*/
|
|
641
|
+
const emitEvent = (elm, name, opts) => {
|
|
642
|
+
const ev = plt.ce(name, opts);
|
|
643
|
+
elm.dispatchEvent(ev);
|
|
644
|
+
return ev;
|
|
645
|
+
};
|
|
223
646
|
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
224
647
|
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
225
648
|
let style = styles.get(scopeId);
|
|
@@ -238,6 +661,7 @@ const registerStyle = (scopeId, cssText, allowCS) => {
|
|
|
238
661
|
styles.set(scopeId, style);
|
|
239
662
|
};
|
|
240
663
|
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
664
|
+
var _a;
|
|
241
665
|
let scopeId = getScopeId(cmpMeta, mode);
|
|
242
666
|
const style = styles.get(scopeId);
|
|
243
667
|
if (!BUILD.attachStyles) {
|
|
@@ -277,6 +701,11 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
|
277
701
|
styleElm = doc.createElement('style');
|
|
278
702
|
styleElm.innerHTML = style;
|
|
279
703
|
}
|
|
704
|
+
// Apply CSP nonce to the style tag if it exists
|
|
705
|
+
const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
|
|
706
|
+
if (nonce != null) {
|
|
707
|
+
styleElm.setAttribute('nonce', nonce);
|
|
708
|
+
}
|
|
280
709
|
if (BUILD.hydrateServerSide || BUILD.hotModuleReplacement) {
|
|
281
710
|
styleElm.setAttribute(HYDRATED_STYLE_ID, scopeId);
|
|
282
711
|
}
|
|
@@ -317,190 +746,6 @@ const attachStyles = (hostRef) => {
|
|
|
317
746
|
};
|
|
318
747
|
const getScopeId = (cmp, mode) => 'sc-' + (BUILD.mode && mode && cmp.$flags$ & 32 /* CMP_FLAGS.hasMode */ ? cmp.$tagName$ + '-' + mode : cmp.$tagName$);
|
|
319
748
|
const convertScopedToShadow = (css) => css.replace(/\/\*!@([^\/]+)\*\/[^\{]+\{/g, '$1{');
|
|
320
|
-
// Private
|
|
321
|
-
const computeMode = (elm) => modeResolutionChain.map((h) => h(elm)).find((m) => !!m);
|
|
322
|
-
// Public
|
|
323
|
-
const setMode = (handler) => modeResolutionChain.push(handler);
|
|
324
|
-
const getMode = (ref) => getHostRef(ref).$modeName$;
|
|
325
|
-
/**
|
|
326
|
-
* Default style mode id
|
|
327
|
-
*/
|
|
328
|
-
/**
|
|
329
|
-
* Reusable empty obj/array
|
|
330
|
-
* Don't add values to these!!
|
|
331
|
-
*/
|
|
332
|
-
const EMPTY_OBJ = {};
|
|
333
|
-
/**
|
|
334
|
-
* Namespaces
|
|
335
|
-
*/
|
|
336
|
-
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
337
|
-
const HTML_NS = 'http://www.w3.org/1999/xhtml';
|
|
338
|
-
const isDef = (v) => v != null;
|
|
339
|
-
const isComplexType = (o) => {
|
|
340
|
-
// https://jsperf.com/typeof-fn-object/5
|
|
341
|
-
o = typeof o;
|
|
342
|
-
return o === 'object' || o === 'function';
|
|
343
|
-
};
|
|
344
|
-
/**
|
|
345
|
-
* Production h() function based on Preact by
|
|
346
|
-
* Jason Miller (@developit)
|
|
347
|
-
* Licensed under the MIT License
|
|
348
|
-
* https://github.com/developit/preact/blob/master/LICENSE
|
|
349
|
-
*
|
|
350
|
-
* Modified for Rindo's compiler and vdom
|
|
351
|
-
*/
|
|
352
|
-
// const stack: any[] = [];
|
|
353
|
-
// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
|
|
354
|
-
// export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
|
|
355
|
-
const h = (nodeName, vnodeData, ...children) => {
|
|
356
|
-
let child = null;
|
|
357
|
-
let key = null;
|
|
358
|
-
let slotName = null;
|
|
359
|
-
let simple = false;
|
|
360
|
-
let lastSimple = false;
|
|
361
|
-
const vNodeChildren = [];
|
|
362
|
-
const walk = (c) => {
|
|
363
|
-
for (let i = 0; i < c.length; i++) {
|
|
364
|
-
child = c[i];
|
|
365
|
-
if (Array.isArray(child)) {
|
|
366
|
-
walk(child);
|
|
367
|
-
}
|
|
368
|
-
else if (child != null && typeof child !== 'boolean') {
|
|
369
|
-
if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
|
|
370
|
-
child = String(child);
|
|
371
|
-
}
|
|
372
|
-
else if (BUILD.isDev && typeof nodeName !== 'function' && child.$flags$ === undefined) {
|
|
373
|
-
consoleDevError(`vNode passed as children has unexpected type.
|
|
374
|
-
Make sure it's using the correct h() function.
|
|
375
|
-
Empty objects can also be the cause, look for JSX comments that became objects.`);
|
|
376
|
-
}
|
|
377
|
-
if (simple && lastSimple) {
|
|
378
|
-
// If the previous child was simple (string), we merge both
|
|
379
|
-
vNodeChildren[vNodeChildren.length - 1].$text$ += child;
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
// Append a new vNode, if it's text, we create a text vNode
|
|
383
|
-
vNodeChildren.push(simple ? newVNode(null, child) : child);
|
|
384
|
-
}
|
|
385
|
-
lastSimple = simple;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
walk(children);
|
|
390
|
-
if (vnodeData) {
|
|
391
|
-
if (BUILD.isDev && nodeName === 'input') {
|
|
392
|
-
validateInputProperties(vnodeData);
|
|
393
|
-
}
|
|
394
|
-
// normalize class / classname attributes
|
|
395
|
-
if (BUILD.vdomKey && vnodeData.key) {
|
|
396
|
-
key = vnodeData.key;
|
|
397
|
-
}
|
|
398
|
-
if (BUILD.slotRelocation && vnodeData.name) {
|
|
399
|
-
slotName = vnodeData.name;
|
|
400
|
-
}
|
|
401
|
-
if (BUILD.vdomClass) {
|
|
402
|
-
const classData = vnodeData.className || vnodeData.class;
|
|
403
|
-
if (classData) {
|
|
404
|
-
vnodeData.class =
|
|
405
|
-
typeof classData !== 'object'
|
|
406
|
-
? classData
|
|
407
|
-
: Object.keys(classData)
|
|
408
|
-
.filter((k) => classData[k])
|
|
409
|
-
.join(' ');
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (BUILD.isDev && vNodeChildren.some(isHost)) {
|
|
414
|
-
consoleDevError(`The <Host> must be the single root component. Make sure:
|
|
415
|
-
- You are NOT using hostData() and <Host> in the same component.
|
|
416
|
-
- <Host> is used once, and it's the single root component of the render() function.`);
|
|
417
|
-
}
|
|
418
|
-
if (BUILD.vdomFunctional && typeof nodeName === 'function') {
|
|
419
|
-
// nodeName is a functional component
|
|
420
|
-
return nodeName(vnodeData === null ? {} : vnodeData, vNodeChildren, vdomFnUtils);
|
|
421
|
-
}
|
|
422
|
-
const vnode = newVNode(nodeName, null);
|
|
423
|
-
vnode.$attrs$ = vnodeData;
|
|
424
|
-
if (vNodeChildren.length > 0) {
|
|
425
|
-
vnode.$children$ = vNodeChildren;
|
|
426
|
-
}
|
|
427
|
-
if (BUILD.vdomKey) {
|
|
428
|
-
vnode.$key$ = key;
|
|
429
|
-
}
|
|
430
|
-
if (BUILD.slotRelocation) {
|
|
431
|
-
vnode.$name$ = slotName;
|
|
432
|
-
}
|
|
433
|
-
return vnode;
|
|
434
|
-
};
|
|
435
|
-
const newVNode = (tag, text) => {
|
|
436
|
-
const vnode = {
|
|
437
|
-
$flags$: 0,
|
|
438
|
-
$tag$: tag,
|
|
439
|
-
$text$: text,
|
|
440
|
-
$elm$: null,
|
|
441
|
-
$children$: null,
|
|
442
|
-
};
|
|
443
|
-
if (BUILD.vdomAttribute) {
|
|
444
|
-
vnode.$attrs$ = null;
|
|
445
|
-
}
|
|
446
|
-
if (BUILD.vdomKey) {
|
|
447
|
-
vnode.$key$ = null;
|
|
448
|
-
}
|
|
449
|
-
if (BUILD.slotRelocation) {
|
|
450
|
-
vnode.$name$ = null;
|
|
451
|
-
}
|
|
452
|
-
return vnode;
|
|
453
|
-
};
|
|
454
|
-
const Host = {};
|
|
455
|
-
const isHost = (node) => node && node.$tag$ === Host;
|
|
456
|
-
const vdomFnUtils = {
|
|
457
|
-
forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
|
|
458
|
-
map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate),
|
|
459
|
-
};
|
|
460
|
-
const convertToPublic = (node) => ({
|
|
461
|
-
vattrs: node.$attrs$,
|
|
462
|
-
vchildren: node.$children$,
|
|
463
|
-
vkey: node.$key$,
|
|
464
|
-
vname: node.$name$,
|
|
465
|
-
vtag: node.$tag$,
|
|
466
|
-
vtext: node.$text$,
|
|
467
|
-
});
|
|
468
|
-
const convertToPrivate = (node) => {
|
|
469
|
-
if (typeof node.vtag === 'function') {
|
|
470
|
-
const vnodeData = Object.assign({}, node.vattrs);
|
|
471
|
-
if (node.vkey) {
|
|
472
|
-
vnodeData.key = node.vkey;
|
|
473
|
-
}
|
|
474
|
-
if (node.vname) {
|
|
475
|
-
vnodeData.name = node.vname;
|
|
476
|
-
}
|
|
477
|
-
return h(node.vtag, vnodeData, ...(node.vchildren || []));
|
|
478
|
-
}
|
|
479
|
-
const vnode = newVNode(node.vtag, node.vtext);
|
|
480
|
-
vnode.$attrs$ = node.vattrs;
|
|
481
|
-
vnode.$children$ = node.vchildren;
|
|
482
|
-
vnode.$key$ = node.vkey;
|
|
483
|
-
vnode.$name$ = node.vname;
|
|
484
|
-
return vnode;
|
|
485
|
-
};
|
|
486
|
-
/**
|
|
487
|
-
* Validates the ordering of attributes on an input element
|
|
488
|
-
* @param inputElm the element to validate
|
|
489
|
-
*/
|
|
490
|
-
const validateInputProperties = (inputElm) => {
|
|
491
|
-
const props = Object.keys(inputElm);
|
|
492
|
-
const value = props.indexOf('value');
|
|
493
|
-
if (value === -1) {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
const typeIndex = props.indexOf('type');
|
|
497
|
-
const minIndex = props.indexOf('min');
|
|
498
|
-
const maxIndex = props.indexOf('max');
|
|
499
|
-
const stepIndex = props.indexOf('step');
|
|
500
|
-
if (value < typeIndex || value < minIndex || value < maxIndex || value < stepIndex) {
|
|
501
|
-
consoleDevWarn(`The "value" prop of <input> should be set after "min", "max", "type" and "step"`);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
749
|
/**
|
|
505
750
|
* Production setAccessor() function based on Preact by
|
|
506
751
|
* Jason Miller (@developit)
|
|
@@ -808,6 +1053,21 @@ const putBackInOriginalLocation = (parentElm, recursive) => {
|
|
|
808
1053
|
}
|
|
809
1054
|
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
810
1055
|
};
|
|
1056
|
+
/**
|
|
1057
|
+
* Create DOM nodes corresponding to a list of {@link d.Vnode} objects and
|
|
1058
|
+
* add them to the DOM in the appropriate place.
|
|
1059
|
+
*
|
|
1060
|
+
* @param parentElm the DOM node which should be used as a parent for the new
|
|
1061
|
+
* DOM nodes
|
|
1062
|
+
* @param before a child of the `parentElm` which the new children should be
|
|
1063
|
+
* inserted before (optional)
|
|
1064
|
+
* @param parentVNode the parent virtual DOM node
|
|
1065
|
+
* @param vnodes the new child virtual DOM nodes to produce DOM nodes for
|
|
1066
|
+
* @param startIdx the index in the child virtual DOM nodes at which to start
|
|
1067
|
+
* creating DOM nodes (inclusive)
|
|
1068
|
+
* @param endIdx the index in the child virtual DOM nodes at which to stop
|
|
1069
|
+
* creating DOM nodes (inclusive)
|
|
1070
|
+
*/
|
|
811
1071
|
const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
812
1072
|
let containerElm = ((BUILD.slotRelocation && parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
|
|
813
1073
|
let childNode;
|
|
@@ -824,6 +1084,19 @@ const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) =>
|
|
|
824
1084
|
}
|
|
825
1085
|
}
|
|
826
1086
|
};
|
|
1087
|
+
/**
|
|
1088
|
+
* Remove the DOM elements corresponding to a list of {@link d.VNode} objects.
|
|
1089
|
+
* This can be used to, for instance, clean up after a list of children which
|
|
1090
|
+
* should no longer be shown.
|
|
1091
|
+
*
|
|
1092
|
+
* This function also handles some of Rindo's slot relocation logic.
|
|
1093
|
+
*
|
|
1094
|
+
* @param vnodes a list of virtual DOM nodes to remove
|
|
1095
|
+
* @param startIdx the index at which to start removing nodes (inclusive)
|
|
1096
|
+
* @param endIdx the index at which to stop removing nodes (inclusive)
|
|
1097
|
+
* @param vnode a VNode
|
|
1098
|
+
* @param elm an element
|
|
1099
|
+
*/
|
|
827
1100
|
const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
828
1101
|
for (; startIdx <= endIdx; ++startIdx) {
|
|
829
1102
|
if ((vnode = vnodes[startIdx])) {
|
|
@@ -1105,7 +1378,8 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
1105
1378
|
*
|
|
1106
1379
|
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
1107
1380
|
* changing order within a `children` array or something along those lines then
|
|
1108
|
-
* we could obtain a false
|
|
1381
|
+
* we could obtain a false negative and then have to do needless re-rendering
|
|
1382
|
+
* (i.e. we'd say two VNodes aren't equal when in fact they should be).
|
|
1109
1383
|
*
|
|
1110
1384
|
* @param leftVNode the first VNode to check
|
|
1111
1385
|
* @param rightVNode the second VNode to check
|
|
@@ -1334,6 +1608,18 @@ const callNodeRefs = (vNode) => {
|
|
|
1334
1608
|
vNode.$children$ && vNode.$children$.map(callNodeRefs);
|
|
1335
1609
|
}
|
|
1336
1610
|
};
|
|
1611
|
+
/**
|
|
1612
|
+
* The main entry point for Rindo's virtual DOM-based rendering engine
|
|
1613
|
+
*
|
|
1614
|
+
* Given a {@link d.HostRef} container and some virtual DOM nodes, this
|
|
1615
|
+
* function will handle creating a virtual DOM tree with a single root, patching
|
|
1616
|
+
* the current virtual DOM tree onto an old one (if any), dealing with slot
|
|
1617
|
+
* relocation, and reflecting attributes.
|
|
1618
|
+
*
|
|
1619
|
+
* @param hostRef data needed to root and render the virtual DOM tree, such as
|
|
1620
|
+
* the DOM node into which it should be rendered.
|
|
1621
|
+
* @param renderFnResults the virtual DOM nodes to be rendered
|
|
1622
|
+
*/
|
|
1337
1623
|
const renderVdom = (hostRef, renderFnResults) => {
|
|
1338
1624
|
const hostElm = hostRef.$hostElement$;
|
|
1339
1625
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
@@ -1444,51 +1730,22 @@ render() {
|
|
|
1444
1730
|
}
|
|
1445
1731
|
}
|
|
1446
1732
|
if (checkSlotFallbackVisibility) {
|
|
1447
|
-
updateFallbackSlotVisibility(rootVnode.$elm$);
|
|
1448
|
-
}
|
|
1449
|
-
// done moving nodes around
|
|
1450
|
-
// allow the disconnect callback to work again
|
|
1451
|
-
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
1452
|
-
// always reset
|
|
1453
|
-
relocateNodes.length = 0;
|
|
1454
|
-
}
|
|
1455
|
-
};
|
|
1456
|
-
// slot comment debug nodes only created with the `--debug` flag
|
|
1457
|
-
// otherwise these nodes are text nodes w/out content
|
|
1458
|
-
const slotReferenceDebugNode = (slotVNode) => doc.createComment(`<slot${slotVNode.$name$ ? ' name="' + slotVNode.$name$ + '"' : ''}> (host=${hostTagName.toLowerCase()})`);
|
|
1459
|
-
const originalLocationDebugNode = (nodeToRelocate) => doc.createComment(`org-location for ` +
|
|
1460
|
-
(nodeToRelocate.localName
|
|
1461
|
-
? `<${nodeToRelocate.localName}> (host=${nodeToRelocate['s-hn']})`
|
|
1462
|
-
: `[${nodeToRelocate.textContent}]`));
|
|
1463
|
-
const getElement = (ref) => (BUILD.lazyLoad ? getHostRef(ref).$hostElement$ : ref);
|
|
1464
|
-
const createEvent = (ref, name, flags) => {
|
|
1465
|
-
const elm = getElement(ref);
|
|
1466
|
-
return {
|
|
1467
|
-
emit: (detail) => {
|
|
1468
|
-
if (BUILD.isDev && !elm.isConnected) {
|
|
1469
|
-
consoleDevWarn(`The "${name}" event was emitted, but the dispatcher node is no longer connected to the dom.`);
|
|
1470
|
-
}
|
|
1471
|
-
return emitEvent(elm, name, {
|
|
1472
|
-
bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
|
|
1473
|
-
composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
|
|
1474
|
-
cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
|
|
1475
|
-
detail,
|
|
1476
|
-
});
|
|
1477
|
-
},
|
|
1478
|
-
};
|
|
1479
|
-
};
|
|
1480
|
-
/**
|
|
1481
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
1482
|
-
* @param elm the target of the Event
|
|
1483
|
-
* @param name the name to give the custom Event
|
|
1484
|
-
* @param opts options for configuring a custom Event
|
|
1485
|
-
* @returns the custom Event
|
|
1486
|
-
*/
|
|
1487
|
-
const emitEvent = (elm, name, opts) => {
|
|
1488
|
-
const ev = plt.ce(name, opts);
|
|
1489
|
-
elm.dispatchEvent(ev);
|
|
1490
|
-
return ev;
|
|
1733
|
+
updateFallbackSlotVisibility(rootVnode.$elm$);
|
|
1734
|
+
}
|
|
1735
|
+
// done moving nodes around
|
|
1736
|
+
// allow the disconnect callback to work again
|
|
1737
|
+
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
1738
|
+
// always reset
|
|
1739
|
+
relocateNodes.length = 0;
|
|
1740
|
+
}
|
|
1491
1741
|
};
|
|
1742
|
+
// slot comment debug nodes only created with the `--debug` flag
|
|
1743
|
+
// otherwise these nodes are text nodes w/out content
|
|
1744
|
+
const slotReferenceDebugNode = (slotVNode) => doc.createComment(`<slot${slotVNode.$name$ ? ' name="' + slotVNode.$name$ + '"' : ''}> (host=${hostTagName.toLowerCase()})`);
|
|
1745
|
+
const originalLocationDebugNode = (nodeToRelocate) => doc.createComment(`org-location for ` +
|
|
1746
|
+
(nodeToRelocate.localName
|
|
1747
|
+
? `<${nodeToRelocate.localName}> (host=${nodeToRelocate['s-hn']})`
|
|
1748
|
+
: `[${nodeToRelocate.textContent}]`));
|
|
1492
1749
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
1493
1750
|
if (BUILD.asyncLoading && ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
1494
1751
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -1751,304 +2008,52 @@ const appDidLoad = (who) => {
|
|
|
1751
2008
|
if (BUILD.asyncQueue) {
|
|
1752
2009
|
plt.$flags$ |= 2 /* PLATFORM_FLAGS.appLoaded */;
|
|
1753
2010
|
}
|
|
1754
|
-
nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
|
1755
|
-
if (BUILD.profile && performance.measure) {
|
|
1756
|
-
performance.measure(`[Rindo] ${NAMESPACE} initial load (by ${who})`, 'st:app:start');
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
const safeCall = (instance, method, arg) => {
|
|
1760
|
-
if (instance && instance[method]) {
|
|
1761
|
-
try {
|
|
1762
|
-
return instance[method](arg);
|
|
1763
|
-
}
|
|
1764
|
-
catch (e) {
|
|
1765
|
-
consoleError(e);
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
return undefined;
|
|
1769
|
-
};
|
|
1770
|
-
const then = (promise, thenFn) => {
|
|
1771
|
-
return promise && promise.then ? promise.then(thenFn) : thenFn();
|
|
1772
|
-
};
|
|
1773
|
-
const emitLifecycleEvent = (elm, lifecycleName) => {
|
|
1774
|
-
if (BUILD.lifecycleDOMEvents) {
|
|
1775
|
-
emitEvent(elm, 'rindo_' + lifecycleName, {
|
|
1776
|
-
bubbles: true,
|
|
1777
|
-
composed: true,
|
|
1778
|
-
detail: {
|
|
1779
|
-
namespace: NAMESPACE,
|
|
1780
|
-
},
|
|
1781
|
-
});
|
|
1782
|
-
}
|
|
1783
|
-
};
|
|
1784
|
-
const addHydratedFlag = (elm) => BUILD.hydratedClass
|
|
1785
|
-
? elm.classList.add('hydrated')
|
|
1786
|
-
: BUILD.hydratedAttribute
|
|
1787
|
-
? elm.setAttribute('hydrated', '')
|
|
1788
|
-
: undefined;
|
|
1789
|
-
const serverSideConnected = (elm) => {
|
|
1790
|
-
const children = elm.children;
|
|
1791
|
-
if (children != null) {
|
|
1792
|
-
for (let i = 0, ii = children.length; i < ii; i++) {
|
|
1793
|
-
const childElm = children[i];
|
|
1794
|
-
if (typeof childElm.connectedCallback === 'function') {
|
|
1795
|
-
childElm.connectedCallback();
|
|
1796
|
-
}
|
|
1797
|
-
serverSideConnected(childElm);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
};
|
|
1801
|
-
const initializeClientHydrate = (hostElm, tagName, hostId, hostRef) => {
|
|
1802
|
-
const endHydrate = createTime('hydrateClient', tagName);
|
|
1803
|
-
const shadowRoot = hostElm.shadowRoot;
|
|
1804
|
-
const childRenderNodes = [];
|
|
1805
|
-
const slotNodes = [];
|
|
1806
|
-
const shadowRootNodes = BUILD.shadowDom && shadowRoot ? [] : null;
|
|
1807
|
-
const vnode = (hostRef.$vnode$ = newVNode(tagName, null));
|
|
1808
|
-
if (!plt.$orgLocNodes$) {
|
|
1809
|
-
initializeDocumentHydrate(doc.body, (plt.$orgLocNodes$ = new Map()));
|
|
1810
|
-
}
|
|
1811
|
-
hostElm[HYDRATE_ID] = hostId;
|
|
1812
|
-
hostElm.removeAttribute(HYDRATE_ID);
|
|
1813
|
-
clientHydrate(vnode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, hostElm, hostId);
|
|
1814
|
-
childRenderNodes.map((c) => {
|
|
1815
|
-
const orgLocationId = c.$hostId$ + '.' + c.$nodeId$;
|
|
1816
|
-
const orgLocationNode = plt.$orgLocNodes$.get(orgLocationId);
|
|
1817
|
-
const node = c.$elm$;
|
|
1818
|
-
if (orgLocationNode && supportsShadow && orgLocationNode['s-en'] === '') {
|
|
1819
|
-
orgLocationNode.parentNode.insertBefore(node, orgLocationNode.nextSibling);
|
|
1820
|
-
}
|
|
1821
|
-
if (!shadowRoot) {
|
|
1822
|
-
node['s-hn'] = tagName;
|
|
1823
|
-
if (orgLocationNode) {
|
|
1824
|
-
node['s-ol'] = orgLocationNode;
|
|
1825
|
-
node['s-ol']['s-nr'] = node;
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
plt.$orgLocNodes$.delete(orgLocationId);
|
|
1829
|
-
});
|
|
1830
|
-
if (BUILD.shadowDom && shadowRoot) {
|
|
1831
|
-
shadowRootNodes.map((shadowRootNode) => {
|
|
1832
|
-
if (shadowRootNode) {
|
|
1833
|
-
shadowRoot.appendChild(shadowRootNode);
|
|
1834
|
-
}
|
|
1835
|
-
});
|
|
1836
|
-
}
|
|
1837
|
-
endHydrate();
|
|
1838
|
-
};
|
|
1839
|
-
const clientHydrate = (parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node, hostId) => {
|
|
1840
|
-
let childNodeType;
|
|
1841
|
-
let childIdSplt;
|
|
1842
|
-
let childVNode;
|
|
1843
|
-
let i;
|
|
1844
|
-
if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
1845
|
-
childNodeType = node.getAttribute(HYDRATE_CHILD_ID);
|
|
1846
|
-
if (childNodeType) {
|
|
1847
|
-
// got the node data from the element's attribute
|
|
1848
|
-
// `${hostId}.${nodeId}.${depth}.${index}`
|
|
1849
|
-
childIdSplt = childNodeType.split('.');
|
|
1850
|
-
if (childIdSplt[0] === hostId || childIdSplt[0] === '0') {
|
|
1851
|
-
childVNode = {
|
|
1852
|
-
$flags$: 0,
|
|
1853
|
-
$hostId$: childIdSplt[0],
|
|
1854
|
-
$nodeId$: childIdSplt[1],
|
|
1855
|
-
$depth$: childIdSplt[2],
|
|
1856
|
-
$index$: childIdSplt[3],
|
|
1857
|
-
$tag$: node.tagName.toLowerCase(),
|
|
1858
|
-
$elm$: node,
|
|
1859
|
-
$attrs$: null,
|
|
1860
|
-
$children$: null,
|
|
1861
|
-
$key$: null,
|
|
1862
|
-
$name$: null,
|
|
1863
|
-
$text$: null,
|
|
1864
|
-
};
|
|
1865
|
-
childRenderNodes.push(childVNode);
|
|
1866
|
-
node.removeAttribute(HYDRATE_CHILD_ID);
|
|
1867
|
-
// this is a new child vnode
|
|
1868
|
-
// so ensure its parent vnode has the vchildren array
|
|
1869
|
-
if (!parentVNode.$children$) {
|
|
1870
|
-
parentVNode.$children$ = [];
|
|
1871
|
-
}
|
|
1872
|
-
// add our child vnode to a specific index of the vnode's children
|
|
1873
|
-
parentVNode.$children$[childVNode.$index$] = childVNode;
|
|
1874
|
-
// this is now the new parent vnode for all the next child checks
|
|
1875
|
-
parentVNode = childVNode;
|
|
1876
|
-
if (shadowRootNodes && childVNode.$depth$ === '0') {
|
|
1877
|
-
shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
// recursively drill down, end to start so we can remove nodes
|
|
1882
|
-
for (i = node.childNodes.length - 1; i >= 0; i--) {
|
|
1883
|
-
clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.childNodes[i], hostId);
|
|
1884
|
-
}
|
|
1885
|
-
if (node.shadowRoot) {
|
|
1886
|
-
// keep drilling down through the shadow root nodes
|
|
1887
|
-
for (i = node.shadowRoot.childNodes.length - 1; i >= 0; i--) {
|
|
1888
|
-
clientHydrate(parentVNode, childRenderNodes, slotNodes, shadowRootNodes, hostElm, node.shadowRoot.childNodes[i], hostId);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
|
|
1893
|
-
// `${COMMENT_TYPE}.${hostId}.${nodeId}.${depth}.${index}`
|
|
1894
|
-
childIdSplt = node.nodeValue.split('.');
|
|
1895
|
-
if (childIdSplt[1] === hostId || childIdSplt[1] === '0') {
|
|
1896
|
-
// comment node for either the host id or a 0 host id
|
|
1897
|
-
childNodeType = childIdSplt[0];
|
|
1898
|
-
childVNode = {
|
|
1899
|
-
$flags$: 0,
|
|
1900
|
-
$hostId$: childIdSplt[1],
|
|
1901
|
-
$nodeId$: childIdSplt[2],
|
|
1902
|
-
$depth$: childIdSplt[3],
|
|
1903
|
-
$index$: childIdSplt[4],
|
|
1904
|
-
$elm$: node,
|
|
1905
|
-
$attrs$: null,
|
|
1906
|
-
$children$: null,
|
|
1907
|
-
$key$: null,
|
|
1908
|
-
$name$: null,
|
|
1909
|
-
$tag$: null,
|
|
1910
|
-
$text$: null,
|
|
1911
|
-
};
|
|
1912
|
-
if (childNodeType === TEXT_NODE_ID) {
|
|
1913
|
-
childVNode.$elm$ = node.nextSibling;
|
|
1914
|
-
if (childVNode.$elm$ && childVNode.$elm$.nodeType === 3 /* NODE_TYPE.TextNode */) {
|
|
1915
|
-
childVNode.$text$ = childVNode.$elm$.textContent;
|
|
1916
|
-
childRenderNodes.push(childVNode);
|
|
1917
|
-
// remove the text comment since it's no longer needed
|
|
1918
|
-
node.remove();
|
|
1919
|
-
if (!parentVNode.$children$) {
|
|
1920
|
-
parentVNode.$children$ = [];
|
|
1921
|
-
}
|
|
1922
|
-
parentVNode.$children$[childVNode.$index$] = childVNode;
|
|
1923
|
-
if (shadowRootNodes && childVNode.$depth$ === '0') {
|
|
1924
|
-
shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
|
|
1925
|
-
}
|
|
1926
|
-
}
|
|
1927
|
-
}
|
|
1928
|
-
else if (childVNode.$hostId$ === hostId) {
|
|
1929
|
-
// this comment node is specifcally for this host id
|
|
1930
|
-
if (childNodeType === SLOT_NODE_ID) {
|
|
1931
|
-
// `${SLOT_NODE_ID}.${hostId}.${nodeId}.${depth}.${index}.${slotName}`;
|
|
1932
|
-
childVNode.$tag$ = 'slot';
|
|
1933
|
-
if (childIdSplt[5]) {
|
|
1934
|
-
node['s-sn'] = childVNode.$name$ = childIdSplt[5];
|
|
1935
|
-
}
|
|
1936
|
-
else {
|
|
1937
|
-
node['s-sn'] = '';
|
|
1938
|
-
}
|
|
1939
|
-
node['s-sr'] = true;
|
|
1940
|
-
if (BUILD.shadowDom && shadowRootNodes) {
|
|
1941
|
-
// browser support shadowRoot and this is a shadow dom component
|
|
1942
|
-
// create an actual slot element
|
|
1943
|
-
childVNode.$elm$ = doc.createElement(childVNode.$tag$);
|
|
1944
|
-
if (childVNode.$name$) {
|
|
1945
|
-
// add the slot name attribute
|
|
1946
|
-
childVNode.$elm$.setAttribute('name', childVNode.$name$);
|
|
1947
|
-
}
|
|
1948
|
-
// insert the new slot element before the slot comment
|
|
1949
|
-
node.parentNode.insertBefore(childVNode.$elm$, node);
|
|
1950
|
-
// remove the slot comment since it's not needed for shadow
|
|
1951
|
-
node.remove();
|
|
1952
|
-
if (childVNode.$depth$ === '0') {
|
|
1953
|
-
shadowRootNodes[childVNode.$index$] = childVNode.$elm$;
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
slotNodes.push(childVNode);
|
|
1957
|
-
if (!parentVNode.$children$) {
|
|
1958
|
-
parentVNode.$children$ = [];
|
|
1959
|
-
}
|
|
1960
|
-
parentVNode.$children$[childVNode.$index$] = childVNode;
|
|
1961
|
-
}
|
|
1962
|
-
else if (childNodeType === CONTENT_REF_ID) {
|
|
1963
|
-
// `${CONTENT_REF_ID}.${hostId}`;
|
|
1964
|
-
if (BUILD.shadowDom && shadowRootNodes) {
|
|
1965
|
-
// remove the content ref comment since it's not needed for shadow
|
|
1966
|
-
node.remove();
|
|
1967
|
-
}
|
|
1968
|
-
else if (BUILD.slotRelocation) {
|
|
1969
|
-
hostElm['s-cr'] = node;
|
|
1970
|
-
node['s-cn'] = true;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
else if (parentVNode && parentVNode.$tag$ === 'style') {
|
|
1977
|
-
const vnode = newVNode(null, node.textContent);
|
|
1978
|
-
vnode.$elm$ = node;
|
|
1979
|
-
vnode.$index$ = '0';
|
|
1980
|
-
parentVNode.$children$ = [vnode];
|
|
1981
|
-
}
|
|
1982
|
-
};
|
|
1983
|
-
const initializeDocumentHydrate = (node, orgLocNodes) => {
|
|
1984
|
-
if (node.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
1985
|
-
let i = 0;
|
|
1986
|
-
for (; i < node.childNodes.length; i++) {
|
|
1987
|
-
initializeDocumentHydrate(node.childNodes[i], orgLocNodes);
|
|
1988
|
-
}
|
|
1989
|
-
if (node.shadowRoot) {
|
|
1990
|
-
for (i = 0; i < node.shadowRoot.childNodes.length; i++) {
|
|
1991
|
-
initializeDocumentHydrate(node.shadowRoot.childNodes[i], orgLocNodes);
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
|
-
}
|
|
1995
|
-
else if (node.nodeType === 8 /* NODE_TYPE.CommentNode */) {
|
|
1996
|
-
const childIdSplt = node.nodeValue.split('.');
|
|
1997
|
-
if (childIdSplt[0] === ORG_LOCATION_ID) {
|
|
1998
|
-
orgLocNodes.set(childIdSplt[1] + '.' + childIdSplt[2], node);
|
|
1999
|
-
node.nodeValue = '';
|
|
2000
|
-
// useful to know if the original location is
|
|
2001
|
-
// the root light-dom of a shadow dom component
|
|
2002
|
-
node['s-en'] = childIdSplt[3];
|
|
2003
|
-
}
|
|
2011
|
+
nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
|
2012
|
+
if (BUILD.profile && performance.measure) {
|
|
2013
|
+
performance.measure(`[Rindo] ${NAMESPACE} initial load (by ${who})`, 'st:app:start');
|
|
2004
2014
|
}
|
|
2005
2015
|
};
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
2011
|
-
* 1. `any`, the type given to `propValue` in the function signature
|
|
2012
|
-
* 2. the type stored from `propType`.
|
|
2013
|
-
*
|
|
2014
|
-
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
2015
|
-
*
|
|
2016
|
-
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
2017
|
-
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
2018
|
-
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
2019
|
-
* ```tsx
|
|
2020
|
-
* <my-cmp prop-val={0}></my-cmp>
|
|
2021
|
-
* ```
|
|
2022
|
-
*
|
|
2023
|
-
* HTML prop values on the other hand, will always a string
|
|
2024
|
-
*
|
|
2025
|
-
* @param propValue the new value to coerce to some type
|
|
2026
|
-
* @param propType the type of the prop, expressed as a binary number
|
|
2027
|
-
* @returns the parsed/coerced value
|
|
2028
|
-
*/
|
|
2029
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
2030
|
-
// ensure this value is of the correct prop type
|
|
2031
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
2032
|
-
if (BUILD.propBoolean && propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
2033
|
-
// per the HTML spec, any string value means it is a boolean true value
|
|
2034
|
-
// but we'll cheat here and say that the string "false" is the boolean false
|
|
2035
|
-
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
2016
|
+
const safeCall = (instance, method, arg) => {
|
|
2017
|
+
if (instance && instance[method]) {
|
|
2018
|
+
try {
|
|
2019
|
+
return instance[method](arg);
|
|
2036
2020
|
}
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
return parseFloat(propValue);
|
|
2021
|
+
catch (e) {
|
|
2022
|
+
consoleError(e);
|
|
2040
2023
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2024
|
+
}
|
|
2025
|
+
return undefined;
|
|
2026
|
+
};
|
|
2027
|
+
const then = (promise, thenFn) => {
|
|
2028
|
+
return promise && promise.then ? promise.then(thenFn) : thenFn();
|
|
2029
|
+
};
|
|
2030
|
+
const emitLifecycleEvent = (elm, lifecycleName) => {
|
|
2031
|
+
if (BUILD.lifecycleDOMEvents) {
|
|
2032
|
+
emitEvent(elm, 'rindo_' + lifecycleName, {
|
|
2033
|
+
bubbles: true,
|
|
2034
|
+
composed: true,
|
|
2035
|
+
detail: {
|
|
2036
|
+
namespace: NAMESPACE,
|
|
2037
|
+
},
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
const addHydratedFlag = (elm) => BUILD.hydratedClass
|
|
2042
|
+
? elm.classList.add('hydrated')
|
|
2043
|
+
: BUILD.hydratedAttribute
|
|
2044
|
+
? elm.setAttribute('hydrated', '')
|
|
2045
|
+
: undefined;
|
|
2046
|
+
const serverSideConnected = (elm) => {
|
|
2047
|
+
const children = elm.children;
|
|
2048
|
+
if (children != null) {
|
|
2049
|
+
for (let i = 0, ii = children.length; i < ii; i++) {
|
|
2050
|
+
const childElm = children[i];
|
|
2051
|
+
if (typeof childElm.connectedCallback === 'function') {
|
|
2052
|
+
childElm.connectedCallback();
|
|
2053
|
+
}
|
|
2054
|
+
serverSideConnected(childElm);
|
|
2045
2055
|
}
|
|
2046
|
-
// redundant return here for better minification
|
|
2047
|
-
return propValue;
|
|
2048
2056
|
}
|
|
2049
|
-
// not sure exactly what type we want
|
|
2050
|
-
// so no need to change to a different type
|
|
2051
|
-
return propValue;
|
|
2052
2057
|
};
|
|
2053
2058
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
2054
2059
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
@@ -2107,6 +2112,16 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
2107
2112
|
}
|
|
2108
2113
|
}
|
|
2109
2114
|
};
|
|
2115
|
+
/**
|
|
2116
|
+
* Attach a series of runtime constructs to a compiled Rindo component
|
|
2117
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
2118
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
2119
|
+
*
|
|
2120
|
+
* @param Cstr the constructor for a component that we need to process
|
|
2121
|
+
* @param cmpMeta metadata collected previously about the component
|
|
2122
|
+
* @param flags a number used to store a series of bit flags
|
|
2123
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
2124
|
+
*/
|
|
2110
2125
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
2111
2126
|
if (BUILD.member && cmpMeta.$members$) {
|
|
2112
2127
|
if (BUILD.watchCallback && Cstr.watchers) {
|
|
@@ -2196,7 +2211,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
2196
2211
|
//
|
|
2197
2212
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
2198
2213
|
//
|
|
2199
|
-
// TODO
|
|
2214
|
+
// TODO we should think about whether or not we actually want to be reflecting the attributes to
|
|
2200
2215
|
// properties here given that this goes against best practices outlined here
|
|
2201
2216
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
|
|
2202
2217
|
if (this.hasOwnProperty(propName)) {
|
|
@@ -2543,23 +2558,6 @@ const forceModeUpdate = (elm) => {
|
|
|
2543
2558
|
}
|
|
2544
2559
|
}
|
|
2545
2560
|
};
|
|
2546
|
-
const hmrStart = (elm, cmpMeta, hmrVersionId) => {
|
|
2547
|
-
// ¯\_(ツ)_/¯
|
|
2548
|
-
const hostRef = getHostRef(elm);
|
|
2549
|
-
// reset state flags to only have been connected
|
|
2550
|
-
hostRef.$flags$ = 1 /* HOST_FLAGS.hasConnected */;
|
|
2551
|
-
// TODO
|
|
2552
|
-
// detatch any event listeners that may have been added
|
|
2553
|
-
// because we're not passing an exact event name it'll
|
|
2554
|
-
// remove all of this element's event, which is good
|
|
2555
|
-
// create a callback for when this component finishes hmr
|
|
2556
|
-
elm['s-hmr-load'] = () => {
|
|
2557
|
-
// finished hmr for this element
|
|
2558
|
-
delete elm['s-hmr-load'];
|
|
2559
|
-
};
|
|
2560
|
-
// re-initialize the component
|
|
2561
|
-
initializeComponent(elm, hostRef, cmpMeta, hmrVersionId);
|
|
2562
|
-
};
|
|
2563
2561
|
const patchCloneNode = (HostElementPrototype) => {
|
|
2564
2562
|
const orgCloneNode = HostElementPrototype.cloneNode;
|
|
2565
2563
|
HostElementPrototype.cloneNode = function (deep) {
|
|
@@ -2738,7 +2736,25 @@ const getHostSlotChildNodes = (n, slotName) => {
|
|
|
2738
2736
|
}
|
|
2739
2737
|
return childNodes;
|
|
2740
2738
|
};
|
|
2739
|
+
const hmrStart = (elm, cmpMeta, hmrVersionId) => {
|
|
2740
|
+
// ¯\_(ツ)_/¯
|
|
2741
|
+
const hostRef = getHostRef(elm);
|
|
2742
|
+
// reset state flags to only have been connected
|
|
2743
|
+
hostRef.$flags$ = 1 /* HOST_FLAGS.hasConnected */;
|
|
2744
|
+
// TODO
|
|
2745
|
+
// detatch any event listeners that may have been added
|
|
2746
|
+
// because we're not passing an exact event name it'll
|
|
2747
|
+
// remove all of this element's event, which is good
|
|
2748
|
+
// create a callback for when this component finishes hmr
|
|
2749
|
+
elm['s-hmr-load'] = () => {
|
|
2750
|
+
// finished hmr for this element
|
|
2751
|
+
delete elm['s-hmr-load'];
|
|
2752
|
+
};
|
|
2753
|
+
// re-initialize the component
|
|
2754
|
+
initializeComponent(elm, hostRef, cmpMeta, hmrVersionId);
|
|
2755
|
+
};
|
|
2741
2756
|
const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
2757
|
+
var _a;
|
|
2742
2758
|
if (BUILD.profile && performance.mark) {
|
|
2743
2759
|
performance.mark('st:app:start');
|
|
2744
2760
|
}
|
|
@@ -2873,6 +2889,11 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
2873
2889
|
if (BUILD.invisiblePrehydration && (BUILD.hydratedClass || BUILD.hydratedAttribute)) {
|
|
2874
2890
|
visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
|
|
2875
2891
|
visibilityStyle.setAttribute('data-styles', '');
|
|
2892
|
+
// Apply CSP nonce to the style tag if it exists
|
|
2893
|
+
const nonce = (_a = plt.$nonce$) !== null && _a !== void 0 ? _a : queryNonceMetaTagContent(doc);
|
|
2894
|
+
if (nonce != null) {
|
|
2895
|
+
visibilityStyle.setAttribute('nonce', nonce);
|
|
2896
|
+
}
|
|
2876
2897
|
head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
|
|
2877
2898
|
}
|
|
2878
2899
|
// Process deferred connectedCallbacks now all components have been registered
|
|
@@ -2891,11 +2912,6 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
2891
2912
|
// Fallback appLoad event
|
|
2892
2913
|
endBootstrap();
|
|
2893
2914
|
};
|
|
2894
|
-
const getAssetPath = (path) => {
|
|
2895
|
-
const assetUrl = new URL(path, plt.$resourcesUrl$);
|
|
2896
|
-
return assetUrl.origin !== win.location.origin ? assetUrl.href : assetUrl.pathname;
|
|
2897
|
-
};
|
|
2898
|
-
const setAssetPath = (path) => (plt.$resourcesUrl$ = path);
|
|
2899
2915
|
const getConnect = (_ref, tagName) => {
|
|
2900
2916
|
const componentOnReady = () => {
|
|
2901
2917
|
let elm = doc.querySelector(tagName);
|
|
@@ -2945,6 +2961,82 @@ const getContext = (_elm, context) => {
|
|
|
2945
2961
|
}
|
|
2946
2962
|
return undefined;
|
|
2947
2963
|
};
|
|
2964
|
+
const Fragment = (_, children) => children;
|
|
2965
|
+
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
2966
|
+
if (BUILD.hostListener && listeners) {
|
|
2967
|
+
// this is called immediately within the element's constructor
|
|
2968
|
+
// initialize our event listeners on the host element
|
|
2969
|
+
// we do this now so that we can listen to events that may
|
|
2970
|
+
// have fired even before the instance is ready
|
|
2971
|
+
if (BUILD.hostListenerTargetParent) {
|
|
2972
|
+
// this component may have event listeners that should be attached to the parent
|
|
2973
|
+
if (attachParentListeners) {
|
|
2974
|
+
// this is being ran from within the connectedCallback
|
|
2975
|
+
// which is important so that we know the host element actually has a parent element
|
|
2976
|
+
// filter out the listeners to only have the ones that ARE being attached to the parent
|
|
2977
|
+
listeners = listeners.filter(([flags]) => flags & 32 /* LISTENER_FLAGS.TargetParent */);
|
|
2978
|
+
}
|
|
2979
|
+
else {
|
|
2980
|
+
// this is being ran from within the component constructor
|
|
2981
|
+
// everything BUT the parent element listeners should be attached at this time
|
|
2982
|
+
// filter out the listeners that are NOT being attached to the parent
|
|
2983
|
+
listeners = listeners.filter(([flags]) => !(flags & 32 /* LISTENER_FLAGS.TargetParent */));
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
listeners.map(([flags, name, method]) => {
|
|
2987
|
+
const target = BUILD.hostListenerTarget ? getHostListenerTarget(elm, flags) : elm;
|
|
2988
|
+
const handler = hostListenerProxy(hostRef, method);
|
|
2989
|
+
const opts = hostListenerOpts(flags);
|
|
2990
|
+
plt.ael(target, name, handler, opts);
|
|
2991
|
+
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
2992
|
+
});
|
|
2993
|
+
}
|
|
2994
|
+
};
|
|
2995
|
+
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
2996
|
+
try {
|
|
2997
|
+
if (BUILD.lazyLoad) {
|
|
2998
|
+
if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
|
|
2999
|
+
// instance is ready, let's call it's member method for this event
|
|
3000
|
+
hostRef.$lazyInstance$[methodName](ev);
|
|
3001
|
+
}
|
|
3002
|
+
else {
|
|
3003
|
+
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
else {
|
|
3007
|
+
hostRef.$hostElement$[methodName](ev);
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
catch (e) {
|
|
3011
|
+
consoleError(e);
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
const getHostListenerTarget = (elm, flags) => {
|
|
3015
|
+
if (BUILD.hostListenerTargetDocument && flags & 4 /* LISTENER_FLAGS.TargetDocument */)
|
|
3016
|
+
return doc;
|
|
3017
|
+
if (BUILD.hostListenerTargetWindow && flags & 8 /* LISTENER_FLAGS.TargetWindow */)
|
|
3018
|
+
return win;
|
|
3019
|
+
if (BUILD.hostListenerTargetBody && flags & 16 /* LISTENER_FLAGS.TargetBody */)
|
|
3020
|
+
return doc.body;
|
|
3021
|
+
if (BUILD.hostListenerTargetParent && flags & 32 /* LISTENER_FLAGS.TargetParent */)
|
|
3022
|
+
return elm.parentElement;
|
|
3023
|
+
return elm;
|
|
3024
|
+
};
|
|
3025
|
+
// prettier-ignore
|
|
3026
|
+
const hostListenerOpts = (flags) => supportsListenerOptions
|
|
3027
|
+
? ({
|
|
3028
|
+
passive: (flags & 1 /* LISTENER_FLAGS.Passive */) !== 0,
|
|
3029
|
+
capture: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0,
|
|
3030
|
+
})
|
|
3031
|
+
: (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
|
|
3032
|
+
/**
|
|
3033
|
+
* Assigns the given value to the nonce property on the runtime platform object.
|
|
3034
|
+
* During runtime, this value is used to set the nonce attribute on all dynamically created script and style tags.
|
|
3035
|
+
* @param nonce The value to be assigned to the platform nonce property.
|
|
3036
|
+
* @returns void
|
|
3037
|
+
*/
|
|
3038
|
+
const setNonce = (nonce) => (plt.$nonce$ = nonce);
|
|
3039
|
+
const setPlatformOptions = (opts) => Object.assign(plt, opts);
|
|
2948
3040
|
const insertVdomAnnotations = (doc, staticComponents) => {
|
|
2949
3041
|
if (doc != null) {
|
|
2950
3042
|
const docData = {
|
|
@@ -3084,8 +3176,6 @@ const insertChildVNodeAnnotations = (doc, vnodeChild, cmpData, hostId, depth, in
|
|
|
3084
3176
|
});
|
|
3085
3177
|
}
|
|
3086
3178
|
};
|
|
3087
|
-
const setPlatformOptions = (opts) => Object.assign(plt, opts);
|
|
3088
|
-
const Fragment = (_, children) => children;
|
|
3089
3179
|
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
3090
3180
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
3091
3181
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
@@ -3150,6 +3240,49 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
3150
3240
|
};
|
|
3151
3241
|
const styles = /*@__PURE__*/ new Map();
|
|
3152
3242
|
const modeResolutionChain = [];
|
|
3243
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
3244
|
+
const CSS = BUILD.cssVarShim ? win.CSS : null;
|
|
3245
|
+
const doc = win.document || { head: {} };
|
|
3246
|
+
const H = (win.HTMLElement || class {
|
|
3247
|
+
});
|
|
3248
|
+
const plt = {
|
|
3249
|
+
$flags$: 0,
|
|
3250
|
+
$resourcesUrl$: '',
|
|
3251
|
+
jmp: (h) => h(),
|
|
3252
|
+
raf: (h) => requestAnimationFrame(h),
|
|
3253
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
3254
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
3255
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
3256
|
+
};
|
|
3257
|
+
const setPlatformHelpers = (helpers) => {
|
|
3258
|
+
Object.assign(plt, helpers);
|
|
3259
|
+
};
|
|
3260
|
+
const supportsShadow = BUILD.shadowDomShim && BUILD.shadowDom
|
|
3261
|
+
? /*@__PURE__*/ (() => (doc.head.attachShadow + '').indexOf('[native') > -1)()
|
|
3262
|
+
: true;
|
|
3263
|
+
const supportsListenerOptions = /*@__PURE__*/ (() => {
|
|
3264
|
+
let supportsListenerOptions = false;
|
|
3265
|
+
try {
|
|
3266
|
+
doc.addEventListener('e', null, Object.defineProperty({}, 'passive', {
|
|
3267
|
+
get() {
|
|
3268
|
+
supportsListenerOptions = true;
|
|
3269
|
+
},
|
|
3270
|
+
}));
|
|
3271
|
+
}
|
|
3272
|
+
catch (e) { }
|
|
3273
|
+
return supportsListenerOptions;
|
|
3274
|
+
})();
|
|
3275
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
3276
|
+
const supportsConstructableStylesheets = BUILD.constructableCSS
|
|
3277
|
+
? /*@__PURE__*/ (() => {
|
|
3278
|
+
try {
|
|
3279
|
+
new CSSStyleSheet();
|
|
3280
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
3281
|
+
}
|
|
3282
|
+
catch (e) { }
|
|
3283
|
+
return false;
|
|
3284
|
+
})()
|
|
3285
|
+
: false;
|
|
3153
3286
|
const queueDomReads = [];
|
|
3154
3287
|
const queueDomWrites = [];
|
|
3155
3288
|
const queueDomWritesLow = [];
|
|
@@ -3234,11 +3367,5 @@ const flush = () => {
|
|
|
3234
3367
|
const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
|
|
3235
3368
|
const readTask = /*@__PURE__*/ queueTask(queueDomReads, false);
|
|
3236
3369
|
const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
3237
|
-
const Build = {
|
|
3238
|
-
isDev: BUILD.isDev ? true : false,
|
|
3239
|
-
isBrowser: true,
|
|
3240
|
-
isServer: false,
|
|
3241
|
-
isTesting: BUILD.isTesting ? true : false,
|
|
3242
|
-
};
|
|
3243
3370
|
export { BUILD, Env, NAMESPACE } from '@rindo/core/internal/app-data';
|
|
3244
|
-
export { Build, CSS, Context, Fragment, H, H as HTMLElement, Host, RINDO_DEV_MODE, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, doc, forceModeUpdate, forceUpdate, getAssetPath, getConnect, getContext, getElement, getHostRef, getMode, getRenderingRef, getValue, h, insertVdomAnnotations, isMemberInElement, loadModule, modeResolutionChain, nextTick, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, renderVdom, setAssetPath, setErrorHandler, setMode, setPlatformHelpers, setPlatformOptions, setValue, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsShadow, win, writeTask };
|
|
3371
|
+
export { Build, CSS, Context, Fragment, H, H as HTMLElement, Host, RINDO_DEV_MODE, addHostEventListeners, bootstrapLazy, cmpModules, connectedCallback, consoleDevError, consoleDevInfo, consoleDevWarn, consoleError, createEvent, defineCustomElement, disconnectedCallback, doc, forceModeUpdate, forceUpdate, getAssetPath, getConnect, getContext, getElement, getHostRef, getMode, getRenderingRef, getValue, h, insertVdomAnnotations, isMemberInElement, loadModule, modeResolutionChain, nextTick, parsePropertyValue, plt, postUpdateComponent, promiseResolve, proxyComponent, proxyCustomElement, readTask, registerHost, registerInstance, renderVdom, setAssetPath, setErrorHandler, setMode, setNonce, setPlatformHelpers, setPlatformOptions, setValue, styles, supportsConstructableStylesheets, supportsListenerOptions, supportsShadow, win, writeTask };
|