@maggioli-design-system/mds-table-row 2.0.0 → 2.0.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/dist/cjs/{index-2159a30d.js → index-516d954b.js} +376 -213
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/mds-table-row.cjs.entry.js +2 -1
- package/dist/cjs/mds-table-row.cjs.js +2 -2
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/common/aria.js +19 -0
- package/dist/collection/components/mds-table-row/mds-table-row.js +45 -35
- package/dist/collection/dictionary/typography.js +16 -5
- package/dist/components/index.d.ts +1 -5
- package/dist/components/index.js +1 -0
- package/dist/components/mds-table-row.js +1 -0
- package/dist/esm/{index-1e8e95d7.js → index-e2bb9874.js} +376 -213
- package/dist/esm/loader.js +2 -2
- package/dist/esm/mds-table-row.entry.js +2 -1
- package/dist/esm/mds-table-row.js +2 -2
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm-es5/index-e2bb9874.js +2 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/mds-table-row.entry.js +1 -1
- package/dist/esm-es5/mds-table-row.js +1 -1
- package/dist/mds-table-row/mds-table-row.esm.js +1 -1
- package/dist/mds-table-row/mds-table-row.js +2 -1
- package/dist/mds-table-row/p-2689570a.system.js +2 -0
- package/dist/mds-table-row/{p-c8145b7b.system.entry.js → p-2a317845.system.entry.js} +1 -1
- package/dist/mds-table-row/{p-caab8e1e.system.js → p-2ca79ad0.system.js} +1 -1
- package/dist/mds-table-row/p-a14f9222.js +2 -0
- package/dist/mds-table-row/p-c9a97ed3.entry.js +1 -0
- package/dist/stats.json +36 -34
- package/dist/types/common/aria.d.ts +4 -0
- package/dist/types/dictionary/typography.d.ts +5 -3
- package/dist/types/stencil-public-runtime.d.ts +20 -4
- package/dist/types/types/typography.d.ts +6 -4
- package/loader/package.json +1 -0
- package/package.json +4 -4
- package/src/common/aria.ts +27 -0
- package/src/components/mds-table-row/.gitlab-ci.yml +2 -2
- package/src/dictionary/typography.ts +21 -6
- package/src/fixtures/icons.json +2 -2
- package/src/types/typography.ts +15 -4
- package/www/build/mds-table-row.esm.js +1 -1
- package/www/build/mds-table-row.js +2 -1
- package/www/build/p-2689570a.system.js +2 -0
- package/www/build/{p-c8145b7b.system.entry.js → p-2a317845.system.entry.js} +1 -1
- package/www/build/{p-caab8e1e.system.js → p-2ca79ad0.system.js} +1 -1
- package/www/build/p-a14f9222.js +2 -0
- package/www/build/p-c9a97ed3.entry.js +1 -0
- package/dist/esm-es5/index-1e8e95d7.js +0 -2
- package/dist/mds-table-row/p-c6fbd532.system.js +0 -2
- package/dist/mds-table-row/p-ca70a50c.entry.js +0 -1
- package/dist/mds-table-row/p-f5a4be35.js +0 -2
- package/www/build/p-c6fbd532.system.js +0 -2
- package/www/build/p-ca70a50c.entry.js +0 -1
- package/www/build/p-f5a4be35.js +0 -2
|
@@ -1,65 +1,17 @@
|
|
|
1
1
|
const NAMESPACE = 'mds-table-row';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
5
|
+
* Simon Friis Vindum (@paldepind)
|
|
6
|
+
* Licensed under the MIT License
|
|
7
|
+
* https://github.com/snabbdom/snabbdom/blob/master/LICENSE
|
|
8
|
+
*
|
|
9
|
+
* Modified for Stencil's renderer and slot projection
|
|
10
|
+
*/
|
|
3
11
|
let scopeId;
|
|
4
12
|
let hostTagName;
|
|
5
13
|
let isSvgMode = false;
|
|
6
14
|
let queuePending = false;
|
|
7
|
-
const win = typeof window !== 'undefined' ? window : {};
|
|
8
|
-
const doc = win.document || { head: {} };
|
|
9
|
-
const plt = {
|
|
10
|
-
$flags$: 0,
|
|
11
|
-
$resourcesUrl$: '',
|
|
12
|
-
jmp: (h) => h(),
|
|
13
|
-
raf: (h) => requestAnimationFrame(h),
|
|
14
|
-
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
15
|
-
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
16
|
-
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
17
|
-
};
|
|
18
|
-
const promiseResolve = (v) => Promise.resolve(v);
|
|
19
|
-
const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
|
|
20
|
-
try {
|
|
21
|
-
new CSSStyleSheet();
|
|
22
|
-
return typeof new CSSStyleSheet().replace === 'function';
|
|
23
|
-
}
|
|
24
|
-
catch (e) { }
|
|
25
|
-
return false;
|
|
26
|
-
})()
|
|
27
|
-
;
|
|
28
|
-
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
29
|
-
if (listeners) {
|
|
30
|
-
listeners.map(([flags, name, method]) => {
|
|
31
|
-
const target = getHostListenerTarget(elm, flags) ;
|
|
32
|
-
const handler = hostListenerProxy(hostRef, method);
|
|
33
|
-
const opts = hostListenerOpts(flags);
|
|
34
|
-
plt.ael(target, name, handler, opts);
|
|
35
|
-
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
40
|
-
try {
|
|
41
|
-
{
|
|
42
|
-
if (hostRef.$flags$ & 256 /* isListenReady */) {
|
|
43
|
-
// instance is ready, let's call it's member method for this event
|
|
44
|
-
hostRef.$lazyInstance$[methodName](ev);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch (e) {
|
|
52
|
-
consoleError(e);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const getHostListenerTarget = (elm, flags) => {
|
|
56
|
-
if (flags & 16 /* TargetBody */)
|
|
57
|
-
return doc.body;
|
|
58
|
-
return elm;
|
|
59
|
-
};
|
|
60
|
-
// prettier-ignore
|
|
61
|
-
const hostListenerOpts = (flags) => (flags & 2 /* Capture */) !== 0;
|
|
62
|
-
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
63
15
|
const createTime = (fnName, tagName = '') => {
|
|
64
16
|
{
|
|
65
17
|
return () => {
|
|
@@ -74,71 +26,7 @@ const uniqueTime = (key, measureText) => {
|
|
|
74
26
|
};
|
|
75
27
|
}
|
|
76
28
|
};
|
|
77
|
-
const
|
|
78
|
-
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
79
|
-
let style = styles.get(scopeId);
|
|
80
|
-
if (supportsConstructibleStylesheets && allowCS) {
|
|
81
|
-
style = (style || new CSSStyleSheet());
|
|
82
|
-
style.replace(cssText);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
style = cssText;
|
|
86
|
-
}
|
|
87
|
-
styles.set(scopeId, style);
|
|
88
|
-
};
|
|
89
|
-
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
90
|
-
let scopeId = getScopeId(cmpMeta);
|
|
91
|
-
const style = styles.get(scopeId);
|
|
92
|
-
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
93
|
-
// so the fallback is to always use the document for the root node in those cases
|
|
94
|
-
styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
|
|
95
|
-
if (style) {
|
|
96
|
-
if (typeof style === 'string') {
|
|
97
|
-
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
98
|
-
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
99
|
-
let styleElm;
|
|
100
|
-
if (!appliedStyles) {
|
|
101
|
-
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
102
|
-
}
|
|
103
|
-
if (!appliedStyles.has(scopeId)) {
|
|
104
|
-
{
|
|
105
|
-
{
|
|
106
|
-
styleElm = doc.createElement('style');
|
|
107
|
-
styleElm.innerHTML = style;
|
|
108
|
-
}
|
|
109
|
-
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
110
|
-
}
|
|
111
|
-
if (appliedStyles) {
|
|
112
|
-
appliedStyles.add(scopeId);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
117
|
-
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return scopeId;
|
|
121
|
-
};
|
|
122
|
-
const attachStyles = (hostRef) => {
|
|
123
|
-
const cmpMeta = hostRef.$cmpMeta$;
|
|
124
|
-
const elm = hostRef.$hostElement$;
|
|
125
|
-
const flags = cmpMeta.$flags$;
|
|
126
|
-
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
127
|
-
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
128
|
-
if (flags & 10 /* needsScopedEncapsulation */) {
|
|
129
|
-
// only required when we're NOT using native shadow dom (slot)
|
|
130
|
-
// or this browser doesn't support native shadow dom
|
|
131
|
-
// and this host element was NOT created with SSR
|
|
132
|
-
// let's pick out the inner content for slot projection
|
|
133
|
-
// create a node to represent where the original
|
|
134
|
-
// content was first placed, which is useful later on
|
|
135
|
-
// DOM WRITE!!
|
|
136
|
-
elm['s-sc'] = scopeId;
|
|
137
|
-
elm.classList.add(scopeId + '-h');
|
|
138
|
-
}
|
|
139
|
-
endAttachStyles();
|
|
140
|
-
};
|
|
141
|
-
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
29
|
+
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
142
30
|
/**
|
|
143
31
|
* Default style mode id
|
|
144
32
|
*/
|
|
@@ -214,6 +102,126 @@ const newVNode = (tag, text) => {
|
|
|
214
102
|
};
|
|
215
103
|
const Host = {};
|
|
216
104
|
const isHost = (node) => node && node.$tag$ === Host;
|
|
105
|
+
/**
|
|
106
|
+
* Parse a new property value for a given property type.
|
|
107
|
+
*
|
|
108
|
+
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
109
|
+
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
110
|
+
* 1. `any`, the type given to `propValue` in the function signature
|
|
111
|
+
* 2. the type stored from `propType`.
|
|
112
|
+
*
|
|
113
|
+
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
114
|
+
*
|
|
115
|
+
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
116
|
+
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
117
|
+
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <my-cmp prop-val={0}></my-cmp>
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* HTML prop values on the other hand, will always a string
|
|
123
|
+
*
|
|
124
|
+
* @param propValue the new value to coerce to some type
|
|
125
|
+
* @param propType the type of the prop, expressed as a binary number
|
|
126
|
+
* @returns the parsed/coerced value
|
|
127
|
+
*/
|
|
128
|
+
const parsePropertyValue = (propValue, propType) => {
|
|
129
|
+
// ensure this value is of the correct prop type
|
|
130
|
+
if (propValue != null && !isComplexType(propValue)) {
|
|
131
|
+
if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
132
|
+
// per the HTML spec, any string value means it is a boolean true value
|
|
133
|
+
// but we'll cheat here and say that the string "false" is the boolean false
|
|
134
|
+
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
135
|
+
}
|
|
136
|
+
// redundant return here for better minification
|
|
137
|
+
return propValue;
|
|
138
|
+
}
|
|
139
|
+
// not sure exactly what type we want
|
|
140
|
+
// so no need to change to a different type
|
|
141
|
+
return propValue;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
145
|
+
* @param elm the target of the Event
|
|
146
|
+
* @param name the name to give the custom Event
|
|
147
|
+
* @param opts options for configuring a custom Event
|
|
148
|
+
* @returns the custom Event
|
|
149
|
+
*/
|
|
150
|
+
const emitEvent = (elm, name, opts) => {
|
|
151
|
+
const ev = plt.ce(name, opts);
|
|
152
|
+
elm.dispatchEvent(ev);
|
|
153
|
+
return ev;
|
|
154
|
+
};
|
|
155
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
156
|
+
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
157
|
+
let style = styles.get(scopeId);
|
|
158
|
+
if (supportsConstructableStylesheets && allowCS) {
|
|
159
|
+
style = (style || new CSSStyleSheet());
|
|
160
|
+
if (typeof style === 'string') {
|
|
161
|
+
style = cssText;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
style.replaceSync(cssText);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
style = cssText;
|
|
169
|
+
}
|
|
170
|
+
styles.set(scopeId, style);
|
|
171
|
+
};
|
|
172
|
+
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
173
|
+
let scopeId = getScopeId(cmpMeta);
|
|
174
|
+
const style = styles.get(scopeId);
|
|
175
|
+
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
176
|
+
// so the fallback is to always use the document for the root node in those cases
|
|
177
|
+
styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
|
|
178
|
+
if (style) {
|
|
179
|
+
if (typeof style === 'string') {
|
|
180
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
181
|
+
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
182
|
+
let styleElm;
|
|
183
|
+
if (!appliedStyles) {
|
|
184
|
+
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
185
|
+
}
|
|
186
|
+
if (!appliedStyles.has(scopeId)) {
|
|
187
|
+
{
|
|
188
|
+
{
|
|
189
|
+
styleElm = doc.createElement('style');
|
|
190
|
+
styleElm.innerHTML = style;
|
|
191
|
+
}
|
|
192
|
+
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
193
|
+
}
|
|
194
|
+
if (appliedStyles) {
|
|
195
|
+
appliedStyles.add(scopeId);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
200
|
+
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return scopeId;
|
|
204
|
+
};
|
|
205
|
+
const attachStyles = (hostRef) => {
|
|
206
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
207
|
+
const elm = hostRef.$hostElement$;
|
|
208
|
+
const flags = cmpMeta.$flags$;
|
|
209
|
+
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
210
|
+
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
211
|
+
if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
|
|
212
|
+
// only required when we're NOT using native shadow dom (slot)
|
|
213
|
+
// or this browser doesn't support native shadow dom
|
|
214
|
+
// and this host element was NOT created with SSR
|
|
215
|
+
// let's pick out the inner content for slot projection
|
|
216
|
+
// create a node to represent where the original
|
|
217
|
+
// content was first placed, which is useful later on
|
|
218
|
+
// DOM WRITE!!
|
|
219
|
+
elm['s-sc'] = scopeId;
|
|
220
|
+
elm.classList.add(scopeId + '-h');
|
|
221
|
+
}
|
|
222
|
+
endAttachStyles();
|
|
223
|
+
};
|
|
224
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
217
225
|
/**
|
|
218
226
|
* Production setAccessor() function based on Preact by
|
|
219
227
|
* Jason Miller (@developit)
|
|
@@ -254,7 +262,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
254
262
|
}
|
|
255
263
|
}
|
|
256
264
|
}
|
|
257
|
-
else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
|
|
265
|
+
else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
|
|
258
266
|
newValue = newValue === true ? '' : newValue;
|
|
259
267
|
{
|
|
260
268
|
elm.setAttribute(memberName, newValue);
|
|
@@ -267,7 +275,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
267
275
|
// if the element passed in is a shadow root, which is a document fragment
|
|
268
276
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
269
277
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
270
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
278
|
+
const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
|
|
271
279
|
? newVnode.$elm$.host
|
|
272
280
|
: newVnode.$elm$;
|
|
273
281
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
@@ -285,6 +293,16 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
285
293
|
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
|
286
294
|
}
|
|
287
295
|
};
|
|
296
|
+
/**
|
|
297
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
298
|
+
*
|
|
299
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
300
|
+
* @param newParentVNode the parent VNode from the current render
|
|
301
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
302
|
+
* children, for which we will create a new DOM node
|
|
303
|
+
* @param parentElm the parent DOM node which our new node will be a child of
|
|
304
|
+
* @returns the newly created node
|
|
305
|
+
*/
|
|
288
306
|
const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
289
307
|
// tslint:disable-next-line: prefer-const
|
|
290
308
|
const newVNode = newParentVNode.$children$[childIndex];
|
|
@@ -342,6 +360,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
|
342
360
|
}
|
|
343
361
|
}
|
|
344
362
|
};
|
|
363
|
+
/**
|
|
364
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
365
|
+
* traversing the two collections of children, identifying nodes that are
|
|
366
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
367
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
368
|
+
*
|
|
369
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
370
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
371
|
+
* 'windows' by storing start and end indices and references to the
|
|
372
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
373
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
374
|
+
* no children left to update by doing the following:
|
|
375
|
+
*
|
|
376
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
377
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
378
|
+
* only with a window bounded by the highlighted elements:
|
|
379
|
+
*
|
|
380
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
381
|
+
* ^^^^^^ ^^^^^^
|
|
382
|
+
*
|
|
383
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
384
|
+
* across the windows. This will basically detect elements which haven't
|
|
385
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
386
|
+
* VNode elements (represented as HTML):
|
|
387
|
+
*
|
|
388
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
389
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
390
|
+
*
|
|
391
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
392
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
393
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
394
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
395
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
396
|
+
*
|
|
397
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
398
|
+
* window corresponds to the element at the end of the other window. This is
|
|
399
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
400
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
401
|
+
* children nodes themselves have not changed but merely moved in the
|
|
402
|
+
* following example:
|
|
403
|
+
*
|
|
404
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
405
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
406
|
+
*
|
|
407
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
408
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
409
|
+
* DOM.
|
|
410
|
+
*
|
|
411
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
412
|
+
* nodes in the old children which have the same key as the first element in
|
|
413
|
+
* our window on the new children. If we find such a node we handle calling
|
|
414
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
415
|
+
* what we find.
|
|
416
|
+
*
|
|
417
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
418
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
419
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
420
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
421
|
+
* children has collapsed we still have more nodes on the new children that
|
|
422
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
423
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
424
|
+
* sure the corresponding DOM nodes are removed.
|
|
425
|
+
*
|
|
426
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
427
|
+
* @param oldCh the old children of the parent node
|
|
428
|
+
* @param newVNode the new VNode which will replace the parent
|
|
429
|
+
* @param newCh the new children of the parent node
|
|
430
|
+
*/
|
|
345
431
|
const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
346
432
|
let oldStartIdx = 0;
|
|
347
433
|
let newStartIdx = 0;
|
|
@@ -354,7 +440,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
354
440
|
let node;
|
|
355
441
|
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
356
442
|
if (oldStartVnode == null) {
|
|
357
|
-
//
|
|
443
|
+
// VNode might have been moved left
|
|
358
444
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
359
445
|
}
|
|
360
446
|
else if (oldEndVnode == null) {
|
|
@@ -367,34 +453,67 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
367
453
|
newEndVnode = newCh[--newEndIdx];
|
|
368
454
|
}
|
|
369
455
|
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
456
|
+
// if the start nodes are the same then we should patch the new VNode
|
|
457
|
+
// onto the old one, and increment our `newStartIdx` and `oldStartIdx`
|
|
458
|
+
// indices to reflect that. We don't need to move any DOM Nodes around
|
|
459
|
+
// since things are matched up in order.
|
|
370
460
|
patch(oldStartVnode, newStartVnode);
|
|
371
461
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
372
462
|
newStartVnode = newCh[++newStartIdx];
|
|
373
463
|
}
|
|
374
464
|
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
465
|
+
// likewise, if the end nodes are the same we patch new onto old and
|
|
466
|
+
// decrement our end indices, and also likewise in this case we don't
|
|
467
|
+
// need to move any DOM Nodes.
|
|
375
468
|
patch(oldEndVnode, newEndVnode);
|
|
376
469
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
377
470
|
newEndVnode = newCh[--newEndIdx];
|
|
378
471
|
}
|
|
379
472
|
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
380
473
|
patch(oldStartVnode, newEndVnode);
|
|
474
|
+
// We need to move the element for `oldStartVnode` into a position which
|
|
475
|
+
// will be appropriate for `newEndVnode`. For this we can use
|
|
476
|
+
// `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
|
|
477
|
+
// sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
|
|
478
|
+
// `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
|
|
479
|
+
//
|
|
480
|
+
// <old-start-node />
|
|
481
|
+
// <some-intervening-node />
|
|
482
|
+
// <old-end-node />
|
|
483
|
+
// <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
|
|
484
|
+
// <next-sibling />
|
|
485
|
+
//
|
|
486
|
+
// If instead `oldEndVnode.$elm$` has no sibling then we just want to put
|
|
487
|
+
// the node for `oldStartVnode` at the end of the children of
|
|
488
|
+
// `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
|
|
489
|
+
// aren't any siblings, and passing `null` to `Node.insertBefore` will
|
|
490
|
+
// append it to the children of the parent element.
|
|
381
491
|
parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
382
492
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
383
493
|
newEndVnode = newCh[--newEndIdx];
|
|
384
494
|
}
|
|
385
495
|
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
386
496
|
patch(oldEndVnode, newStartVnode);
|
|
497
|
+
// We've already checked above if `oldStartVnode` and `newStartVnode` are
|
|
498
|
+
// the same node, so since we're here we know that they are not. Thus we
|
|
499
|
+
// can move the element for `oldEndVnode` _before_ the element for
|
|
500
|
+
// `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
|
|
501
|
+
// future.
|
|
387
502
|
parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
388
503
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
389
504
|
newStartVnode = newCh[++newStartIdx];
|
|
390
505
|
}
|
|
391
506
|
else {
|
|
392
507
|
{
|
|
393
|
-
//
|
|
508
|
+
// We either didn't find an element in the old children that matches
|
|
509
|
+
// the key of the first new child OR the build is not using `key`
|
|
510
|
+
// attributes at all. In either case we need to create a new element
|
|
511
|
+
// for the new node.
|
|
394
512
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
|
395
513
|
newStartVnode = newCh[++newStartIdx];
|
|
396
514
|
}
|
|
397
515
|
if (node) {
|
|
516
|
+
// if we created a new node then handle inserting it to the DOM
|
|
398
517
|
{
|
|
399
518
|
oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
|
|
400
519
|
}
|
|
@@ -402,27 +521,55 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
402
521
|
}
|
|
403
522
|
}
|
|
404
523
|
if (oldStartIdx > oldEndIdx) {
|
|
524
|
+
// we have some more new nodes to add which don't match up with old nodes
|
|
405
525
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
406
526
|
}
|
|
407
527
|
else if (newStartIdx > newEndIdx) {
|
|
528
|
+
// there are nodes in the `oldCh` array which no longer correspond to nodes
|
|
529
|
+
// in the new array, so lets remove them (which entails cleaning up the
|
|
530
|
+
// relevant DOM nodes)
|
|
408
531
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
409
532
|
}
|
|
410
533
|
};
|
|
411
|
-
|
|
534
|
+
/**
|
|
535
|
+
* Compare two VNodes to determine if they are the same
|
|
536
|
+
*
|
|
537
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
538
|
+
* information set on the two VNodes and can be misleading under certain
|
|
539
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
540
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
541
|
+
* checking that they have the same tag.
|
|
542
|
+
*
|
|
543
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
544
|
+
* changing order within a `children` array or something along those lines then
|
|
545
|
+
* we could obtain a false positive and then have to do needless re-rendering.
|
|
546
|
+
*
|
|
547
|
+
* @param leftVNode the first VNode to check
|
|
548
|
+
* @param rightVNode the second VNode to check
|
|
549
|
+
* @returns whether they're equal or not
|
|
550
|
+
*/
|
|
551
|
+
const isSameVnode = (leftVNode, rightVNode) => {
|
|
412
552
|
// compare if two vnode to see if they're "technically" the same
|
|
413
553
|
// need to have the same element tag, and same key to be the same
|
|
414
|
-
if (
|
|
554
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
415
555
|
return true;
|
|
416
556
|
}
|
|
417
557
|
return false;
|
|
418
558
|
};
|
|
559
|
+
/**
|
|
560
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
561
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
562
|
+
* children of the two nodes (if any).
|
|
563
|
+
*
|
|
564
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
565
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
566
|
+
*/
|
|
419
567
|
const patch = (oldVNode, newVNode) => {
|
|
420
568
|
const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
|
421
569
|
const oldChildren = oldVNode.$children$;
|
|
422
570
|
const newChildren = newVNode.$children$;
|
|
423
571
|
const tag = newVNode.$tag$;
|
|
424
572
|
{
|
|
425
|
-
// element node
|
|
426
573
|
{
|
|
427
574
|
if (tag === 'slot')
|
|
428
575
|
;
|
|
@@ -435,6 +582,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
435
582
|
}
|
|
436
583
|
if (oldChildren !== null && newChildren !== null) {
|
|
437
584
|
// looks like there's child vnodes for both the old and new vnodes
|
|
585
|
+
// so we need to call `updateChildren` to reconcile them
|
|
438
586
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
439
587
|
}
|
|
440
588
|
else if (newChildren !== null) {
|
|
@@ -458,7 +606,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
458
606
|
cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
|
|
459
607
|
}
|
|
460
608
|
rootVnode.$tag$ = null;
|
|
461
|
-
rootVnode.$flags$ |= 4 /* isHost */;
|
|
609
|
+
rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
|
|
462
610
|
hostRef.$vnode$ = rootVnode;
|
|
463
611
|
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
|
464
612
|
{
|
|
@@ -467,18 +615,6 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
467
615
|
// synchronous patch
|
|
468
616
|
patch(oldVNode, rootVnode);
|
|
469
617
|
};
|
|
470
|
-
/**
|
|
471
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
472
|
-
* @param elm the target of the Event
|
|
473
|
-
* @param name the name to give the custom Event
|
|
474
|
-
* @param opts options for configuring a custom Event
|
|
475
|
-
* @returns the custom Event
|
|
476
|
-
*/
|
|
477
|
-
const emitEvent = (elm, name, opts) => {
|
|
478
|
-
const ev = plt.ce(name, opts);
|
|
479
|
-
elm.dispatchEvent(ev);
|
|
480
|
-
return ev;
|
|
481
|
-
};
|
|
482
618
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
483
619
|
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
484
620
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -486,10 +622,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
|
486
622
|
};
|
|
487
623
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
488
624
|
{
|
|
489
|
-
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
625
|
+
hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
490
626
|
}
|
|
491
|
-
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
492
|
-
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
627
|
+
if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
|
|
628
|
+
hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
|
|
493
629
|
return;
|
|
494
630
|
}
|
|
495
631
|
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
@@ -505,7 +641,7 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
|
505
641
|
let promise;
|
|
506
642
|
if (isInitialLoad) {
|
|
507
643
|
{
|
|
508
|
-
hostRef.$flags$ |= 256 /* isListenReady */;
|
|
644
|
+
hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
|
|
509
645
|
if (hostRef.$queuedListeners$) {
|
|
510
646
|
hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
|
|
511
647
|
hostRef.$queuedListeners$ = null;
|
|
@@ -545,7 +681,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
545
681
|
}
|
|
546
682
|
else {
|
|
547
683
|
Promise.all(childrenPromises).then(postUpdate);
|
|
548
|
-
hostRef.$flags$ |= 4 /* isWaitingForChildren */;
|
|
684
|
+
hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
|
|
549
685
|
childrenPromises.length = 0;
|
|
550
686
|
}
|
|
551
687
|
}
|
|
@@ -554,10 +690,10 @@ const callRender = (hostRef, instance, elm) => {
|
|
|
554
690
|
try {
|
|
555
691
|
instance = instance.render() ;
|
|
556
692
|
{
|
|
557
|
-
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
693
|
+
hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
558
694
|
}
|
|
559
695
|
{
|
|
560
|
-
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
696
|
+
hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
|
|
561
697
|
}
|
|
562
698
|
{
|
|
563
699
|
{
|
|
@@ -580,8 +716,8 @@ const postUpdateComponent = (hostRef) => {
|
|
|
580
716
|
const elm = hostRef.$hostElement$;
|
|
581
717
|
const endPostUpdate = createTime('postUpdate', tagName);
|
|
582
718
|
const ancestorComponent = hostRef.$ancestorComponent$;
|
|
583
|
-
if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
|
|
584
|
-
hostRef.$flags$ |= 64 /* hasLoadedComponent */;
|
|
719
|
+
if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
|
|
720
|
+
hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
|
|
585
721
|
{
|
|
586
722
|
// DOM WRITE!
|
|
587
723
|
addHydratedFlag(elm);
|
|
@@ -604,10 +740,10 @@ const postUpdateComponent = (hostRef) => {
|
|
|
604
740
|
hostRef.$onRenderResolve$();
|
|
605
741
|
hostRef.$onRenderResolve$ = undefined;
|
|
606
742
|
}
|
|
607
|
-
if (hostRef.$flags$ & 512 /* needsRerender */) {
|
|
743
|
+
if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
|
|
608
744
|
nextTick(() => scheduleUpdate(hostRef, false));
|
|
609
745
|
}
|
|
610
|
-
hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
|
|
746
|
+
hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
|
|
611
747
|
}
|
|
612
748
|
// ( •_•)
|
|
613
749
|
// ( •_•)>⌐■-■
|
|
@@ -637,44 +773,6 @@ const then = (promise, thenFn) => {
|
|
|
637
773
|
};
|
|
638
774
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
639
775
|
;
|
|
640
|
-
/**
|
|
641
|
-
* Parse a new property value for a given property type.
|
|
642
|
-
*
|
|
643
|
-
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
644
|
-
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
645
|
-
* 1. `any`, the type given to `propValue` in the function signature
|
|
646
|
-
* 2. the type stored from `propType`.
|
|
647
|
-
*
|
|
648
|
-
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
649
|
-
*
|
|
650
|
-
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
651
|
-
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
652
|
-
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
653
|
-
* ```tsx
|
|
654
|
-
* <my-cmp prop-val={0}></my-cmp>
|
|
655
|
-
* ```
|
|
656
|
-
*
|
|
657
|
-
* HTML prop values on the other hand, will always a string
|
|
658
|
-
*
|
|
659
|
-
* @param propValue the new value to coerce to some type
|
|
660
|
-
* @param propType the type of the prop, expressed as a binary number
|
|
661
|
-
* @returns the parsed/coerced value
|
|
662
|
-
*/
|
|
663
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
664
|
-
// ensure this value is of the correct prop type
|
|
665
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
666
|
-
if (propType & 4 /* Boolean */) {
|
|
667
|
-
// per the HTML spec, any string value means it is a boolean true value
|
|
668
|
-
// but we'll cheat here and say that the string "false" is the boolean false
|
|
669
|
-
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
670
|
-
}
|
|
671
|
-
// redundant return here for better minification
|
|
672
|
-
return propValue;
|
|
673
|
-
}
|
|
674
|
-
// not sure exactly what type we want
|
|
675
|
-
// so no need to change to a different type
|
|
676
|
-
return propValue;
|
|
677
|
-
};
|
|
678
776
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
679
777
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
680
778
|
// check our new property value against our internal value
|
|
@@ -686,12 +784,12 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
686
784
|
// explicitly check for NaN on both sides, as `NaN === NaN` is always false
|
|
687
785
|
const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
|
|
688
786
|
const didValueChange = newVal !== oldVal && !areBothNaN;
|
|
689
|
-
if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
787
|
+
if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
690
788
|
// gadzooks! the property's value has changed!!
|
|
691
789
|
// set our new value!
|
|
692
790
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
693
791
|
if (instance) {
|
|
694
|
-
if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
|
|
792
|
+
if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
|
|
695
793
|
// looks like this value actually changed, so we've got work to do!
|
|
696
794
|
// but only if we've already rendered, otherwise just chill out
|
|
697
795
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -701,14 +799,24 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
701
799
|
}
|
|
702
800
|
}
|
|
703
801
|
};
|
|
802
|
+
/**
|
|
803
|
+
* Attach a series of runtime constructs to a compiled Stencil component
|
|
804
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
805
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
806
|
+
*
|
|
807
|
+
* @param Cstr the constructor for a component that we need to process
|
|
808
|
+
* @param cmpMeta metadata collected previously about the component
|
|
809
|
+
* @param flags a number used to store a series of bit flags
|
|
810
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
811
|
+
*/
|
|
704
812
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
705
813
|
if (cmpMeta.$members$) {
|
|
706
814
|
// It's better to have a const than two Object.entries()
|
|
707
815
|
const members = Object.entries(cmpMeta.$members$);
|
|
708
816
|
const prototype = Cstr.prototype;
|
|
709
817
|
members.map(([memberName, [memberFlags]]) => {
|
|
710
|
-
if ((memberFlags & 31 /* Prop */ ||
|
|
711
|
-
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
818
|
+
if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
|
|
819
|
+
((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
|
|
712
820
|
// proxyComponent - prop
|
|
713
821
|
Object.defineProperty(prototype, memberName, {
|
|
714
822
|
get() {
|
|
@@ -724,7 +832,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
724
832
|
});
|
|
725
833
|
}
|
|
726
834
|
});
|
|
727
|
-
if ((flags & 1 /* isElementConstructor */)) {
|
|
835
|
+
if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
|
|
728
836
|
const attrNameToPropName = new Map();
|
|
729
837
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
730
838
|
plt.jmp(() => {
|
|
@@ -780,11 +888,11 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
780
888
|
// create an array of attributes to observe
|
|
781
889
|
// and also create a map of html attribute name to js property name
|
|
782
890
|
Cstr.observedAttributes = members
|
|
783
|
-
.filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
|
|
891
|
+
.filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
|
|
784
892
|
.map(([propName, m]) => {
|
|
785
893
|
const attrName = m[1] || propName;
|
|
786
894
|
attrNameToPropName.set(attrName, propName);
|
|
787
|
-
if (m[0] & 512 /* ReflectAttr */) {
|
|
895
|
+
if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
|
|
788
896
|
cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
|
789
897
|
}
|
|
790
898
|
return attrName;
|
|
@@ -795,10 +903,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
795
903
|
};
|
|
796
904
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
797
905
|
// initializeComponent
|
|
798
|
-
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
906
|
+
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
799
907
|
{
|
|
800
908
|
// we haven't initialized this element yet
|
|
801
|
-
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
909
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
802
910
|
// lazy loaded components
|
|
803
911
|
// request the component's implementation to be
|
|
804
912
|
// wired up with the host element
|
|
@@ -810,7 +918,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
810
918
|
endLoad();
|
|
811
919
|
}
|
|
812
920
|
if (!Cstr.isProxied) {
|
|
813
|
-
proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
|
|
921
|
+
proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
|
|
814
922
|
Cstr.isProxied = true;
|
|
815
923
|
}
|
|
816
924
|
const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
|
@@ -818,7 +926,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
818
926
|
// but let's keep track of when we start and stop
|
|
819
927
|
// so that the getters/setters don't incorrectly step on data
|
|
820
928
|
{
|
|
821
|
-
hostRef.$flags$ |= 8 /* isConstructingInstance */;
|
|
929
|
+
hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
|
|
822
930
|
}
|
|
823
931
|
// construct the lazy-loaded component implementation
|
|
824
932
|
// passing the hostRef is very important during
|
|
@@ -831,7 +939,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
831
939
|
consoleError(e);
|
|
832
940
|
}
|
|
833
941
|
{
|
|
834
|
-
hostRef.$flags$ &= ~8 /* isConstructingInstance */;
|
|
942
|
+
hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
|
|
835
943
|
}
|
|
836
944
|
endNewInstance();
|
|
837
945
|
}
|
|
@@ -841,7 +949,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
841
949
|
const scopeId = getScopeId(cmpMeta);
|
|
842
950
|
if (!styles.has(scopeId)) {
|
|
843
951
|
const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
|
844
|
-
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
|
|
952
|
+
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
|
|
845
953
|
endRegisterStyles();
|
|
846
954
|
}
|
|
847
955
|
}
|
|
@@ -863,13 +971,13 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
863
971
|
}
|
|
864
972
|
};
|
|
865
973
|
const connectedCallback = (elm) => {
|
|
866
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
974
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
867
975
|
const hostRef = getHostRef(elm);
|
|
868
976
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
869
977
|
const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
|
870
|
-
if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
|
|
978
|
+
if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
|
|
871
979
|
// first time this component has connected
|
|
872
|
-
hostRef.$flags$ |= 1 /* hasConnected */;
|
|
980
|
+
hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
|
|
873
981
|
{
|
|
874
982
|
// find the first ancestor component (if there is one) and register
|
|
875
983
|
// this component as one of the actively loading child components for its ancestor
|
|
@@ -889,7 +997,7 @@ const connectedCallback = (elm) => {
|
|
|
889
997
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
890
998
|
if (cmpMeta.$members$) {
|
|
891
999
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
892
|
-
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1000
|
+
if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
|
|
893
1001
|
const value = elm[memberName];
|
|
894
1002
|
delete elm[memberName];
|
|
895
1003
|
elm[memberName] = value;
|
|
@@ -910,7 +1018,7 @@ const connectedCallback = (elm) => {
|
|
|
910
1018
|
}
|
|
911
1019
|
};
|
|
912
1020
|
const disconnectedCallback = (elm) => {
|
|
913
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1021
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
914
1022
|
const hostRef = getHostRef(elm);
|
|
915
1023
|
{
|
|
916
1024
|
if (hostRef.$rmListeners$) {
|
|
@@ -958,7 +1066,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
958
1066
|
super(self);
|
|
959
1067
|
self = this;
|
|
960
1068
|
registerHost(self, cmpMeta);
|
|
961
|
-
if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
|
|
1069
|
+
if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
|
|
962
1070
|
// this component is using shadow dom
|
|
963
1071
|
// and this browser supports shadow dom
|
|
964
1072
|
// add the read-only property "shadowRoot" to the host element
|
|
@@ -993,7 +1101,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
993
1101
|
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
994
1102
|
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
995
1103
|
cmpTags.push(tagName);
|
|
996
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
1104
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
|
|
997
1105
|
}
|
|
998
1106
|
});
|
|
999
1107
|
});
|
|
@@ -1015,7 +1123,41 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1015
1123
|
// Fallback appLoad event
|
|
1016
1124
|
endBootstrap();
|
|
1017
1125
|
};
|
|
1018
|
-
const
|
|
1126
|
+
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
1127
|
+
if (listeners) {
|
|
1128
|
+
listeners.map(([flags, name, method]) => {
|
|
1129
|
+
const target = getHostListenerTarget(elm, flags) ;
|
|
1130
|
+
const handler = hostListenerProxy(hostRef, method);
|
|
1131
|
+
const opts = hostListenerOpts(flags);
|
|
1132
|
+
plt.ael(target, name, handler, opts);
|
|
1133
|
+
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
1138
|
+
try {
|
|
1139
|
+
{
|
|
1140
|
+
if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
|
|
1141
|
+
// instance is ready, let's call it's member method for this event
|
|
1142
|
+
hostRef.$lazyInstance$[methodName](ev);
|
|
1143
|
+
}
|
|
1144
|
+
else {
|
|
1145
|
+
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
catch (e) {
|
|
1150
|
+
consoleError(e);
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
const getHostListenerTarget = (elm, flags) => {
|
|
1154
|
+
if (flags & 16 /* LISTENER_FLAGS.TargetBody */)
|
|
1155
|
+
return doc.body;
|
|
1156
|
+
return elm;
|
|
1157
|
+
};
|
|
1158
|
+
// prettier-ignore
|
|
1159
|
+
const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
|
|
1160
|
+
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
1019
1161
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
1020
1162
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
1021
1163
|
const registerHost = (elm, cmpMeta) => {
|
|
@@ -1057,14 +1199,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1057
1199
|
return importedModule[exportName];
|
|
1058
1200
|
}, consoleError);
|
|
1059
1201
|
};
|
|
1060
|
-
const styles = new Map();
|
|
1202
|
+
const styles = /*@__PURE__*/ new Map();
|
|
1203
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
1204
|
+
const doc = win.document || { head: {} };
|
|
1205
|
+
const plt = {
|
|
1206
|
+
$flags$: 0,
|
|
1207
|
+
$resourcesUrl$: '',
|
|
1208
|
+
jmp: (h) => h(),
|
|
1209
|
+
raf: (h) => requestAnimationFrame(h),
|
|
1210
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
1211
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
1212
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
1213
|
+
};
|
|
1214
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
1215
|
+
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
1216
|
+
try {
|
|
1217
|
+
new CSSStyleSheet();
|
|
1218
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
1219
|
+
}
|
|
1220
|
+
catch (e) { }
|
|
1221
|
+
return false;
|
|
1222
|
+
})()
|
|
1223
|
+
;
|
|
1061
1224
|
const queueDomReads = [];
|
|
1062
1225
|
const queueDomWrites = [];
|
|
1063
1226
|
const queueTask = (queue, write) => (cb) => {
|
|
1064
1227
|
queue.push(cb);
|
|
1065
1228
|
if (!queuePending) {
|
|
1066
1229
|
queuePending = true;
|
|
1067
|
-
if (write && plt.$flags$ & 4 /* queueSync */) {
|
|
1230
|
+
if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
|
|
1068
1231
|
nextTick(flush);
|
|
1069
1232
|
}
|
|
1070
1233
|
else {
|