@maggioli-design-system/mds-accordion-timer-item 2.0.0 → 2.1.0
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-12f10871.js → index-1c1f0a71.js} +364 -249
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/mds-accordion-timer-item.cjs.entry.js +19 -57
- package/dist/cjs/mds-accordion-timer-item.cjs.js +3 -3
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/common/aria.js +19 -0
- package/dist/collection/components/mds-accordion-timer-item/mds-accordion-timer-item.css +16 -45
- package/dist/collection/components/mds-accordion-timer-item/mds-accordion-timer-item.js +168 -168
- package/dist/collection/components/mds-accordion-timer-item/test/mds-accordion-timer-item.stories.js +3 -5
- package/dist/collection/dictionary/typography.js +14 -3
- package/dist/components/index.d.ts +1 -5
- package/dist/components/index.js +1 -0
- package/dist/components/mds-accordion-timer-item.js +19 -58
- package/dist/esm/{index-e1bd79fc.js → index-2e2e1e5b.js} +364 -249
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mds-accordion-timer-item.entry.js +19 -57
- package/dist/esm/mds-accordion-timer-item.js +3 -3
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm-es5/index-2e2e1e5b.js +2 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/mds-accordion-timer-item.entry.js +1 -1
- package/dist/esm-es5/mds-accordion-timer-item.js +1 -1
- package/dist/mds-accordion-timer-item/mds-accordion-timer-item.esm.js +1 -1
- package/dist/mds-accordion-timer-item/mds-accordion-timer-item.js +2 -1
- package/dist/mds-accordion-timer-item/p-0121b7d5.system.entry.js +1 -0
- package/dist/mds-accordion-timer-item/p-3d9eb7bb.entry.js +1 -0
- package/dist/mds-accordion-timer-item/p-4bbca925.system.js +1 -0
- package/dist/mds-accordion-timer-item/p-69f67485.js +2 -0
- package/dist/mds-accordion-timer-item/p-a21f6c71.system.js +2 -0
- package/dist/stats.json +61 -61
- package/dist/types/common/aria.d.ts +4 -0
- package/dist/types/components/mds-accordion-timer-item/mds-accordion-timer-item.d.ts +2 -5
- package/dist/types/components.d.ts +3 -3
- package/dist/types/dictionary/typography.d.ts +5 -3
- package/dist/types/stencil-public-runtime.d.ts +15 -4
- package/dist/types/types/typography.d.ts +4 -2
- package/loader/package.json +1 -0
- package/package.json +7 -7
- package/readme.md +6 -5
- package/src/common/aria.ts +27 -0
- package/src/components/mds-accordion-timer-item/.gitlab-ci.yml +2 -2
- package/src/components/mds-accordion-timer-item/mds-accordion-timer-item.css +18 -12
- package/src/components/mds-accordion-timer-item/mds-accordion-timer-item.tsx +27 -21
- package/src/components/mds-accordion-timer-item/readme.md +6 -5
- package/src/components/mds-accordion-timer-item/test/mds-accordion-timer-item.stories.tsx +2 -2
- package/src/components.d.ts +3 -3
- package/src/dictionary/typography.ts +19 -4
- package/src/types/typography.ts +13 -2
- package/www/build/mds-accordion-timer-item.esm.js +1 -1
- package/www/build/mds-accordion-timer-item.js +2 -1
- package/www/build/p-0121b7d5.system.entry.js +1 -0
- package/www/build/p-3d9eb7bb.entry.js +1 -0
- package/www/build/p-4bbca925.system.js +1 -0
- package/www/build/p-69f67485.js +2 -0
- package/www/build/p-a21f6c71.system.js +2 -0
- package/dist/esm-es5/index-e1bd79fc.js +0 -2
- package/dist/mds-accordion-timer-item/p-0a14f155.system.js +0 -1
- package/dist/mds-accordion-timer-item/p-13669e01.js +0 -2
- package/dist/mds-accordion-timer-item/p-43a565f8.system.entry.js +0 -1
- package/dist/mds-accordion-timer-item/p-4aec1fdb.system.js +0 -2
- package/dist/mds-accordion-timer-item/p-799f5ad2.entry.js +0 -1
- package/www/build/p-0a14f155.system.js +0 -1
- package/www/build/p-13669e01.js +0 -2
- package/www/build/p-43a565f8.system.entry.js +0 -1
- package/www/build/p-4aec1fdb.system.js +0 -2
- package/www/build/p-799f5ad2.entry.js +0 -1
|
@@ -22,32 +22,18 @@ function _interopNamespace(e) {
|
|
|
22
22
|
|
|
23
23
|
const NAMESPACE = 'mds-accordion-timer-item';
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
27
|
+
* Simon Friis Vindum (@paldepind)
|
|
28
|
+
* Licensed under the MIT License
|
|
29
|
+
* https://github.com/snabbdom/snabbdom/blob/master/LICENSE
|
|
30
|
+
*
|
|
31
|
+
* Modified for Stencil's renderer and slot projection
|
|
32
|
+
*/
|
|
25
33
|
let scopeId;
|
|
26
34
|
let hostTagName;
|
|
27
35
|
let isSvgMode = false;
|
|
28
36
|
let queuePending = false;
|
|
29
|
-
const win = typeof window !== 'undefined' ? window : {};
|
|
30
|
-
const doc = win.document || { head: {} };
|
|
31
|
-
const plt = {
|
|
32
|
-
$flags$: 0,
|
|
33
|
-
$resourcesUrl$: '',
|
|
34
|
-
jmp: (h) => h(),
|
|
35
|
-
raf: (h) => requestAnimationFrame(h),
|
|
36
|
-
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
37
|
-
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
38
|
-
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
39
|
-
};
|
|
40
|
-
const promiseResolve = (v) => Promise.resolve(v);
|
|
41
|
-
const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
|
|
42
|
-
try {
|
|
43
|
-
new CSSStyleSheet();
|
|
44
|
-
return typeof new CSSStyleSheet().replace === 'function';
|
|
45
|
-
}
|
|
46
|
-
catch (e) { }
|
|
47
|
-
return false;
|
|
48
|
-
})()
|
|
49
|
-
;
|
|
50
|
-
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
51
37
|
const createTime = (fnName, tagName = '') => {
|
|
52
38
|
{
|
|
53
39
|
return () => {
|
|
@@ -62,71 +48,7 @@ const uniqueTime = (key, measureText) => {
|
|
|
62
48
|
};
|
|
63
49
|
}
|
|
64
50
|
};
|
|
65
|
-
const
|
|
66
|
-
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
67
|
-
let style = styles.get(scopeId);
|
|
68
|
-
if (supportsConstructibleStylesheets && allowCS) {
|
|
69
|
-
style = (style || new CSSStyleSheet());
|
|
70
|
-
style.replace(cssText);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
style = cssText;
|
|
74
|
-
}
|
|
75
|
-
styles.set(scopeId, style);
|
|
76
|
-
};
|
|
77
|
-
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
78
|
-
let scopeId = getScopeId(cmpMeta);
|
|
79
|
-
const style = styles.get(scopeId);
|
|
80
|
-
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
81
|
-
// so the fallback is to always use the document for the root node in those cases
|
|
82
|
-
styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
|
|
83
|
-
if (style) {
|
|
84
|
-
if (typeof style === 'string') {
|
|
85
|
-
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
86
|
-
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
87
|
-
let styleElm;
|
|
88
|
-
if (!appliedStyles) {
|
|
89
|
-
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
90
|
-
}
|
|
91
|
-
if (!appliedStyles.has(scopeId)) {
|
|
92
|
-
{
|
|
93
|
-
{
|
|
94
|
-
styleElm = doc.createElement('style');
|
|
95
|
-
styleElm.innerHTML = style;
|
|
96
|
-
}
|
|
97
|
-
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
98
|
-
}
|
|
99
|
-
if (appliedStyles) {
|
|
100
|
-
appliedStyles.add(scopeId);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
105
|
-
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return scopeId;
|
|
109
|
-
};
|
|
110
|
-
const attachStyles = (hostRef) => {
|
|
111
|
-
const cmpMeta = hostRef.$cmpMeta$;
|
|
112
|
-
const elm = hostRef.$hostElement$;
|
|
113
|
-
const flags = cmpMeta.$flags$;
|
|
114
|
-
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
115
|
-
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
116
|
-
if (flags & 10 /* needsScopedEncapsulation */) {
|
|
117
|
-
// only required when we're NOT using native shadow dom (slot)
|
|
118
|
-
// or this browser doesn't support native shadow dom
|
|
119
|
-
// and this host element was NOT created with SSR
|
|
120
|
-
// let's pick out the inner content for slot projection
|
|
121
|
-
// create a node to represent where the original
|
|
122
|
-
// content was first placed, which is useful later on
|
|
123
|
-
// DOM WRITE!!
|
|
124
|
-
elm['s-sc'] = scopeId;
|
|
125
|
-
elm.classList.add(scopeId + '-h');
|
|
126
|
-
}
|
|
127
|
-
endAttachStyles();
|
|
128
|
-
};
|
|
129
|
-
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
51
|
+
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
130
52
|
/**
|
|
131
53
|
* Default style mode id
|
|
132
54
|
*/
|
|
@@ -215,6 +137,149 @@ const newVNode = (tag, text) => {
|
|
|
215
137
|
};
|
|
216
138
|
const Host = {};
|
|
217
139
|
const isHost = (node) => node && node.$tag$ === Host;
|
|
140
|
+
/**
|
|
141
|
+
* Parse a new property value for a given property type.
|
|
142
|
+
*
|
|
143
|
+
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
144
|
+
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
145
|
+
* 1. `any`, the type given to `propValue` in the function signature
|
|
146
|
+
* 2. the type stored from `propType`.
|
|
147
|
+
*
|
|
148
|
+
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
149
|
+
*
|
|
150
|
+
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
151
|
+
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
152
|
+
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
153
|
+
* ```tsx
|
|
154
|
+
* <my-cmp prop-val={0}></my-cmp>
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* HTML prop values on the other hand, will always a string
|
|
158
|
+
*
|
|
159
|
+
* @param propValue the new value to coerce to some type
|
|
160
|
+
* @param propType the type of the prop, expressed as a binary number
|
|
161
|
+
* @returns the parsed/coerced value
|
|
162
|
+
*/
|
|
163
|
+
const parsePropertyValue = (propValue, propType) => {
|
|
164
|
+
// ensure this value is of the correct prop type
|
|
165
|
+
if (propValue != null && !isComplexType(propValue)) {
|
|
166
|
+
if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
167
|
+
// per the HTML spec, any string value means it is a boolean true value
|
|
168
|
+
// but we'll cheat here and say that the string "false" is the boolean false
|
|
169
|
+
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
170
|
+
}
|
|
171
|
+
if (propType & 2 /* MEMBER_FLAGS.Number */) {
|
|
172
|
+
// force it to be a number
|
|
173
|
+
return parseFloat(propValue);
|
|
174
|
+
}
|
|
175
|
+
if (propType & 1 /* MEMBER_FLAGS.String */) {
|
|
176
|
+
// could have been passed as a number or boolean
|
|
177
|
+
// but we still want it as a string
|
|
178
|
+
return String(propValue);
|
|
179
|
+
}
|
|
180
|
+
// redundant return here for better minification
|
|
181
|
+
return propValue;
|
|
182
|
+
}
|
|
183
|
+
// not sure exactly what type we want
|
|
184
|
+
// so no need to change to a different type
|
|
185
|
+
return propValue;
|
|
186
|
+
};
|
|
187
|
+
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
188
|
+
const createEvent = (ref, name, flags) => {
|
|
189
|
+
const elm = getElement(ref);
|
|
190
|
+
return {
|
|
191
|
+
emit: (detail) => {
|
|
192
|
+
return emitEvent(elm, name, {
|
|
193
|
+
bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
|
|
194
|
+
composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
|
|
195
|
+
cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
|
|
196
|
+
detail,
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
203
|
+
* @param elm the target of the Event
|
|
204
|
+
* @param name the name to give the custom Event
|
|
205
|
+
* @param opts options for configuring a custom Event
|
|
206
|
+
* @returns the custom Event
|
|
207
|
+
*/
|
|
208
|
+
const emitEvent = (elm, name, opts) => {
|
|
209
|
+
const ev = plt.ce(name, opts);
|
|
210
|
+
elm.dispatchEvent(ev);
|
|
211
|
+
return ev;
|
|
212
|
+
};
|
|
213
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
214
|
+
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
215
|
+
let style = styles.get(scopeId);
|
|
216
|
+
if (supportsConstructableStylesheets && allowCS) {
|
|
217
|
+
style = (style || new CSSStyleSheet());
|
|
218
|
+
if (typeof style === 'string') {
|
|
219
|
+
style = cssText;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
style.replaceSync(cssText);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
style = cssText;
|
|
227
|
+
}
|
|
228
|
+
styles.set(scopeId, style);
|
|
229
|
+
};
|
|
230
|
+
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
231
|
+
let scopeId = getScopeId(cmpMeta);
|
|
232
|
+
const style = styles.get(scopeId);
|
|
233
|
+
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
234
|
+
// so the fallback is to always use the document for the root node in those cases
|
|
235
|
+
styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
|
|
236
|
+
if (style) {
|
|
237
|
+
if (typeof style === 'string') {
|
|
238
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
239
|
+
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
240
|
+
let styleElm;
|
|
241
|
+
if (!appliedStyles) {
|
|
242
|
+
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
243
|
+
}
|
|
244
|
+
if (!appliedStyles.has(scopeId)) {
|
|
245
|
+
{
|
|
246
|
+
{
|
|
247
|
+
styleElm = doc.createElement('style');
|
|
248
|
+
styleElm.innerHTML = style;
|
|
249
|
+
}
|
|
250
|
+
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
251
|
+
}
|
|
252
|
+
if (appliedStyles) {
|
|
253
|
+
appliedStyles.add(scopeId);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
258
|
+
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return scopeId;
|
|
262
|
+
};
|
|
263
|
+
const attachStyles = (hostRef) => {
|
|
264
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
265
|
+
const elm = hostRef.$hostElement$;
|
|
266
|
+
const flags = cmpMeta.$flags$;
|
|
267
|
+
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
268
|
+
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
269
|
+
if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
|
|
270
|
+
// only required when we're NOT using native shadow dom (slot)
|
|
271
|
+
// or this browser doesn't support native shadow dom
|
|
272
|
+
// and this host element was NOT created with SSR
|
|
273
|
+
// let's pick out the inner content for slot projection
|
|
274
|
+
// create a node to represent where the original
|
|
275
|
+
// content was first placed, which is useful later on
|
|
276
|
+
// DOM WRITE!!
|
|
277
|
+
elm['s-sc'] = scopeId;
|
|
278
|
+
elm.classList.add(scopeId + '-h');
|
|
279
|
+
}
|
|
280
|
+
endAttachStyles();
|
|
281
|
+
};
|
|
282
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
218
283
|
/**
|
|
219
284
|
* Production setAccessor() function based on Preact by
|
|
220
285
|
* Jason Miller (@developit)
|
|
@@ -301,7 +366,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
301
366
|
}
|
|
302
367
|
}
|
|
303
368
|
}
|
|
304
|
-
else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
|
|
369
|
+
else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
|
|
305
370
|
newValue = newValue === true ? '' : newValue;
|
|
306
371
|
{
|
|
307
372
|
elm.setAttribute(memberName, newValue);
|
|
@@ -316,7 +381,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
316
381
|
// if the element passed in is a shadow root, which is a document fragment
|
|
317
382
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
318
383
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
319
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
384
|
+
const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
|
|
320
385
|
? newVnode.$elm$.host
|
|
321
386
|
: newVnode.$elm$;
|
|
322
387
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
@@ -334,6 +399,16 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
334
399
|
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
|
335
400
|
}
|
|
336
401
|
};
|
|
402
|
+
/**
|
|
403
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
404
|
+
*
|
|
405
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
406
|
+
* @param newParentVNode the parent VNode from the current render
|
|
407
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
408
|
+
* children, for which we will create a new DOM node
|
|
409
|
+
* @param parentElm the parent DOM node which our new node will be a child of
|
|
410
|
+
* @returns the newly created node
|
|
411
|
+
*/
|
|
337
412
|
const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
338
413
|
// tslint:disable-next-line: prefer-const
|
|
339
414
|
const newVNode = newParentVNode.$children$[childIndex];
|
|
@@ -395,6 +470,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
|
395
470
|
}
|
|
396
471
|
}
|
|
397
472
|
};
|
|
473
|
+
/**
|
|
474
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
475
|
+
* traversing the two collections of children, identifying nodes that are
|
|
476
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
477
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
478
|
+
*
|
|
479
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
480
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
481
|
+
* 'windows' by storing start and end indices and references to the
|
|
482
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
483
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
484
|
+
* no children left to update by doing the following:
|
|
485
|
+
*
|
|
486
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
487
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
488
|
+
* only with a window bounded by the highlighted elements:
|
|
489
|
+
*
|
|
490
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
491
|
+
* ^^^^^^ ^^^^^^
|
|
492
|
+
*
|
|
493
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
494
|
+
* across the windows. This will basically detect elements which haven't
|
|
495
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
496
|
+
* VNode elements (represented as HTML):
|
|
497
|
+
*
|
|
498
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
499
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
500
|
+
*
|
|
501
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
502
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
503
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
504
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
505
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
506
|
+
*
|
|
507
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
508
|
+
* window corresponds to the element at the end of the other window. This is
|
|
509
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
510
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
511
|
+
* children nodes themselves have not changed but merely moved in the
|
|
512
|
+
* following example:
|
|
513
|
+
*
|
|
514
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
515
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
516
|
+
*
|
|
517
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
518
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
519
|
+
* DOM.
|
|
520
|
+
*
|
|
521
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
522
|
+
* nodes in the old children which have the same key as the first element in
|
|
523
|
+
* our window on the new children. If we find such a node we handle calling
|
|
524
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
525
|
+
* what we find.
|
|
526
|
+
*
|
|
527
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
528
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
529
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
530
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
531
|
+
* children has collapsed we still have more nodes on the new children that
|
|
532
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
533
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
534
|
+
* sure the corresponding DOM nodes are removed.
|
|
535
|
+
*
|
|
536
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
537
|
+
* @param oldCh the old children of the parent node
|
|
538
|
+
* @param newVNode the new VNode which will replace the parent
|
|
539
|
+
* @param newCh the new children of the parent node
|
|
540
|
+
*/
|
|
398
541
|
const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
399
542
|
let oldStartIdx = 0;
|
|
400
543
|
let newStartIdx = 0;
|
|
@@ -407,7 +550,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
407
550
|
let node;
|
|
408
551
|
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
409
552
|
if (oldStartVnode == null) {
|
|
410
|
-
//
|
|
553
|
+
// VNode might have been moved left
|
|
411
554
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
412
555
|
}
|
|
413
556
|
else if (oldEndVnode == null) {
|
|
@@ -420,34 +563,67 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
420
563
|
newEndVnode = newCh[--newEndIdx];
|
|
421
564
|
}
|
|
422
565
|
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
566
|
+
// if the start nodes are the same then we should patch the new VNode
|
|
567
|
+
// onto the old one, and increment our `newStartIdx` and `oldStartIdx`
|
|
568
|
+
// indices to reflect that. We don't need to move any DOM Nodes around
|
|
569
|
+
// since things are matched up in order.
|
|
423
570
|
patch(oldStartVnode, newStartVnode);
|
|
424
571
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
425
572
|
newStartVnode = newCh[++newStartIdx];
|
|
426
573
|
}
|
|
427
574
|
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
575
|
+
// likewise, if the end nodes are the same we patch new onto old and
|
|
576
|
+
// decrement our end indices, and also likewise in this case we don't
|
|
577
|
+
// need to move any DOM Nodes.
|
|
428
578
|
patch(oldEndVnode, newEndVnode);
|
|
429
579
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
430
580
|
newEndVnode = newCh[--newEndIdx];
|
|
431
581
|
}
|
|
432
582
|
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
433
583
|
patch(oldStartVnode, newEndVnode);
|
|
584
|
+
// We need to move the element for `oldStartVnode` into a position which
|
|
585
|
+
// will be appropriate for `newEndVnode`. For this we can use
|
|
586
|
+
// `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
|
|
587
|
+
// sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
|
|
588
|
+
// `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
|
|
589
|
+
//
|
|
590
|
+
// <old-start-node />
|
|
591
|
+
// <some-intervening-node />
|
|
592
|
+
// <old-end-node />
|
|
593
|
+
// <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
|
|
594
|
+
// <next-sibling />
|
|
595
|
+
//
|
|
596
|
+
// If instead `oldEndVnode.$elm$` has no sibling then we just want to put
|
|
597
|
+
// the node for `oldStartVnode` at the end of the children of
|
|
598
|
+
// `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
|
|
599
|
+
// aren't any siblings, and passing `null` to `Node.insertBefore` will
|
|
600
|
+
// append it to the children of the parent element.
|
|
434
601
|
parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
435
602
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
436
603
|
newEndVnode = newCh[--newEndIdx];
|
|
437
604
|
}
|
|
438
605
|
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
439
606
|
patch(oldEndVnode, newStartVnode);
|
|
607
|
+
// We've already checked above if `oldStartVnode` and `newStartVnode` are
|
|
608
|
+
// the same node, so since we're here we know that they are not. Thus we
|
|
609
|
+
// can move the element for `oldEndVnode` _before_ the element for
|
|
610
|
+
// `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
|
|
611
|
+
// future.
|
|
440
612
|
parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
441
613
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
442
614
|
newStartVnode = newCh[++newStartIdx];
|
|
443
615
|
}
|
|
444
616
|
else {
|
|
445
617
|
{
|
|
446
|
-
//
|
|
618
|
+
// We either didn't find an element in the old children that matches
|
|
619
|
+
// the key of the first new child OR the build is not using `key`
|
|
620
|
+
// attributes at all. In either case we need to create a new element
|
|
621
|
+
// for the new node.
|
|
447
622
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
|
448
623
|
newStartVnode = newCh[++newStartIdx];
|
|
449
624
|
}
|
|
450
625
|
if (node) {
|
|
626
|
+
// if we created a new node then handle inserting it to the DOM
|
|
451
627
|
{
|
|
452
628
|
oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
|
|
453
629
|
}
|
|
@@ -455,20 +631,49 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
455
631
|
}
|
|
456
632
|
}
|
|
457
633
|
if (oldStartIdx > oldEndIdx) {
|
|
634
|
+
// we have some more new nodes to add which don't match up with old nodes
|
|
458
635
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
459
636
|
}
|
|
460
637
|
else if (newStartIdx > newEndIdx) {
|
|
638
|
+
// there are nodes in the `oldCh` array which no longer correspond to nodes
|
|
639
|
+
// in the new array, so lets remove them (which entails cleaning up the
|
|
640
|
+
// relevant DOM nodes)
|
|
461
641
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
462
642
|
}
|
|
463
643
|
};
|
|
464
|
-
|
|
644
|
+
/**
|
|
645
|
+
* Compare two VNodes to determine if they are the same
|
|
646
|
+
*
|
|
647
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
648
|
+
* information set on the two VNodes and can be misleading under certain
|
|
649
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
650
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
651
|
+
* checking that they have the same tag.
|
|
652
|
+
*
|
|
653
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
654
|
+
* changing order within a `children` array or something along those lines then
|
|
655
|
+
* we could obtain a false positive and then have to do needless re-rendering.
|
|
656
|
+
*
|
|
657
|
+
* @param leftVNode the first VNode to check
|
|
658
|
+
* @param rightVNode the second VNode to check
|
|
659
|
+
* @returns whether they're equal or not
|
|
660
|
+
*/
|
|
661
|
+
const isSameVnode = (leftVNode, rightVNode) => {
|
|
465
662
|
// compare if two vnode to see if they're "technically" the same
|
|
466
663
|
// need to have the same element tag, and same key to be the same
|
|
467
|
-
if (
|
|
664
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
468
665
|
return true;
|
|
469
666
|
}
|
|
470
667
|
return false;
|
|
471
668
|
};
|
|
669
|
+
/**
|
|
670
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
671
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
672
|
+
* children of the two nodes (if any).
|
|
673
|
+
*
|
|
674
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
675
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
676
|
+
*/
|
|
472
677
|
const patch = (oldVNode, newVNode) => {
|
|
473
678
|
const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
|
474
679
|
const oldChildren = oldVNode.$children$;
|
|
@@ -476,7 +681,6 @@ const patch = (oldVNode, newVNode) => {
|
|
|
476
681
|
const tag = newVNode.$tag$;
|
|
477
682
|
const text = newVNode.$text$;
|
|
478
683
|
if (text === null) {
|
|
479
|
-
// element node
|
|
480
684
|
{
|
|
481
685
|
if (tag === 'slot')
|
|
482
686
|
;
|
|
@@ -489,6 +693,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
489
693
|
}
|
|
490
694
|
if (oldChildren !== null && newChildren !== null) {
|
|
491
695
|
// looks like there's child vnodes for both the old and new vnodes
|
|
696
|
+
// so we need to call `updateChildren` to reconcile them
|
|
492
697
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
493
698
|
}
|
|
494
699
|
else if (newChildren !== null) {
|
|
@@ -522,7 +727,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
522
727
|
cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
|
|
523
728
|
}
|
|
524
729
|
rootVnode.$tag$ = null;
|
|
525
|
-
rootVnode.$flags$ |= 4 /* isHost */;
|
|
730
|
+
rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
|
|
526
731
|
hostRef.$vnode$ = rootVnode;
|
|
527
732
|
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
|
528
733
|
{
|
|
@@ -531,32 +736,6 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
531
736
|
// synchronous patch
|
|
532
737
|
patch(oldVNode, rootVnode);
|
|
533
738
|
};
|
|
534
|
-
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
535
|
-
const createEvent = (ref, name, flags) => {
|
|
536
|
-
const elm = getElement(ref);
|
|
537
|
-
return {
|
|
538
|
-
emit: (detail) => {
|
|
539
|
-
return emitEvent(elm, name, {
|
|
540
|
-
bubbles: !!(flags & 4 /* Bubbles */),
|
|
541
|
-
composed: !!(flags & 2 /* Composed */),
|
|
542
|
-
cancelable: !!(flags & 1 /* Cancellable */),
|
|
543
|
-
detail,
|
|
544
|
-
});
|
|
545
|
-
},
|
|
546
|
-
};
|
|
547
|
-
};
|
|
548
|
-
/**
|
|
549
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
550
|
-
* @param elm the target of the Event
|
|
551
|
-
* @param name the name to give the custom Event
|
|
552
|
-
* @param opts options for configuring a custom Event
|
|
553
|
-
* @returns the custom Event
|
|
554
|
-
*/
|
|
555
|
-
const emitEvent = (elm, name, opts) => {
|
|
556
|
-
const ev = plt.ce(name, opts);
|
|
557
|
-
elm.dispatchEvent(ev);
|
|
558
|
-
return ev;
|
|
559
|
-
};
|
|
560
739
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
561
740
|
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
562
741
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -564,10 +743,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
|
564
743
|
};
|
|
565
744
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
566
745
|
{
|
|
567
|
-
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
746
|
+
hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
568
747
|
}
|
|
569
|
-
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
570
|
-
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
748
|
+
if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
|
|
749
|
+
hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
|
|
571
750
|
return;
|
|
572
751
|
}
|
|
573
752
|
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
@@ -581,11 +760,6 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
|
581
760
|
const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
|
|
582
761
|
const instance = hostRef.$lazyInstance$ ;
|
|
583
762
|
let promise;
|
|
584
|
-
if (isInitialLoad) {
|
|
585
|
-
{
|
|
586
|
-
promise = safeCall(instance, 'componentWillLoad');
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
763
|
endSchedule();
|
|
590
764
|
return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
|
|
591
765
|
};
|
|
@@ -619,7 +793,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
619
793
|
}
|
|
620
794
|
else {
|
|
621
795
|
Promise.all(childrenPromises).then(postUpdate);
|
|
622
|
-
hostRef.$flags$ |= 4 /* isWaitingForChildren */;
|
|
796
|
+
hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
|
|
623
797
|
childrenPromises.length = 0;
|
|
624
798
|
}
|
|
625
799
|
}
|
|
@@ -628,10 +802,10 @@ const callRender = (hostRef, instance, elm) => {
|
|
|
628
802
|
try {
|
|
629
803
|
instance = instance.render() ;
|
|
630
804
|
{
|
|
631
|
-
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
805
|
+
hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
632
806
|
}
|
|
633
807
|
{
|
|
634
|
-
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
808
|
+
hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
|
|
635
809
|
}
|
|
636
810
|
{
|
|
637
811
|
{
|
|
@@ -654,8 +828,8 @@ const postUpdateComponent = (hostRef) => {
|
|
|
654
828
|
const elm = hostRef.$hostElement$;
|
|
655
829
|
const endPostUpdate = createTime('postUpdate', tagName);
|
|
656
830
|
const ancestorComponent = hostRef.$ancestorComponent$;
|
|
657
|
-
if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
|
|
658
|
-
hostRef.$flags$ |= 64 /* hasLoadedComponent */;
|
|
831
|
+
if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
|
|
832
|
+
hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
|
|
659
833
|
{
|
|
660
834
|
// DOM WRITE!
|
|
661
835
|
addHydratedFlag(elm);
|
|
@@ -678,10 +852,10 @@ const postUpdateComponent = (hostRef) => {
|
|
|
678
852
|
hostRef.$onRenderResolve$();
|
|
679
853
|
hostRef.$onRenderResolve$ = undefined;
|
|
680
854
|
}
|
|
681
|
-
if (hostRef.$flags$ & 512 /* needsRerender */) {
|
|
855
|
+
if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
|
|
682
856
|
nextTick(() => scheduleUpdate(hostRef, false));
|
|
683
857
|
}
|
|
684
|
-
hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
|
|
858
|
+
hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
|
|
685
859
|
}
|
|
686
860
|
// ( •_•)
|
|
687
861
|
// ( •_•)>⌐■-■
|
|
@@ -695,74 +869,15 @@ const appDidLoad = (who) => {
|
|
|
695
869
|
}
|
|
696
870
|
nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
|
697
871
|
};
|
|
698
|
-
const safeCall = (instance, method, arg) => {
|
|
699
|
-
if (instance && instance[method]) {
|
|
700
|
-
try {
|
|
701
|
-
return instance[method](arg);
|
|
702
|
-
}
|
|
703
|
-
catch (e) {
|
|
704
|
-
consoleError(e);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
return undefined;
|
|
708
|
-
};
|
|
709
872
|
const then = (promise, thenFn) => {
|
|
710
873
|
return promise && promise.then ? promise.then(thenFn) : thenFn();
|
|
711
874
|
};
|
|
712
875
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
713
876
|
;
|
|
714
|
-
/**
|
|
715
|
-
* Parse a new property value for a given property type.
|
|
716
|
-
*
|
|
717
|
-
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
718
|
-
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
719
|
-
* 1. `any`, the type given to `propValue` in the function signature
|
|
720
|
-
* 2. the type stored from `propType`.
|
|
721
|
-
*
|
|
722
|
-
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
723
|
-
*
|
|
724
|
-
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
725
|
-
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
726
|
-
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
727
|
-
* ```tsx
|
|
728
|
-
* <my-cmp prop-val={0}></my-cmp>
|
|
729
|
-
* ```
|
|
730
|
-
*
|
|
731
|
-
* HTML prop values on the other hand, will always a string
|
|
732
|
-
*
|
|
733
|
-
* @param propValue the new value to coerce to some type
|
|
734
|
-
* @param propType the type of the prop, expressed as a binary number
|
|
735
|
-
* @returns the parsed/coerced value
|
|
736
|
-
*/
|
|
737
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
738
|
-
// ensure this value is of the correct prop type
|
|
739
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
740
|
-
if (propType & 4 /* Boolean */) {
|
|
741
|
-
// per the HTML spec, any string value means it is a boolean true value
|
|
742
|
-
// but we'll cheat here and say that the string "false" is the boolean false
|
|
743
|
-
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
744
|
-
}
|
|
745
|
-
if (propType & 2 /* Number */) {
|
|
746
|
-
// force it to be a number
|
|
747
|
-
return parseFloat(propValue);
|
|
748
|
-
}
|
|
749
|
-
if (propType & 1 /* String */) {
|
|
750
|
-
// could have been passed as a number or boolean
|
|
751
|
-
// but we still want it as a string
|
|
752
|
-
return String(propValue);
|
|
753
|
-
}
|
|
754
|
-
// redundant return here for better minification
|
|
755
|
-
return propValue;
|
|
756
|
-
}
|
|
757
|
-
// not sure exactly what type we want
|
|
758
|
-
// so no need to change to a different type
|
|
759
|
-
return propValue;
|
|
760
|
-
};
|
|
761
877
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
762
878
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
763
879
|
// check our new property value against our internal value
|
|
764
880
|
const hostRef = getHostRef(ref);
|
|
765
|
-
const elm = hostRef.$hostElement$ ;
|
|
766
881
|
const oldVal = hostRef.$instanceValues$.get(propName);
|
|
767
882
|
const flags = hostRef.$flags$;
|
|
768
883
|
const instance = hostRef.$lazyInstance$ ;
|
|
@@ -770,28 +885,12 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
770
885
|
// explicitly check for NaN on both sides, as `NaN === NaN` is always false
|
|
771
886
|
const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
|
|
772
887
|
const didValueChange = newVal !== oldVal && !areBothNaN;
|
|
773
|
-
if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
888
|
+
if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
774
889
|
// gadzooks! the property's value has changed!!
|
|
775
890
|
// set our new value!
|
|
776
891
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
777
892
|
if (instance) {
|
|
778
|
-
|
|
779
|
-
if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
|
|
780
|
-
const watchMethods = cmpMeta.$watchers$[propName];
|
|
781
|
-
if (watchMethods) {
|
|
782
|
-
// this instance is watching for when this property changed
|
|
783
|
-
watchMethods.map((watchMethodName) => {
|
|
784
|
-
try {
|
|
785
|
-
// fire off each of the watch methods that are watching this property
|
|
786
|
-
instance[watchMethodName](newVal, oldVal, propName);
|
|
787
|
-
}
|
|
788
|
-
catch (e) {
|
|
789
|
-
consoleError(e, elm);
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
|
|
893
|
+
if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
|
|
795
894
|
// looks like this value actually changed, so we've got work to do!
|
|
796
895
|
// but only if we've already rendered, otherwise just chill out
|
|
797
896
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -801,17 +900,24 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
801
900
|
}
|
|
802
901
|
}
|
|
803
902
|
};
|
|
903
|
+
/**
|
|
904
|
+
* Attach a series of runtime constructs to a compiled Stencil component
|
|
905
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
906
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
907
|
+
*
|
|
908
|
+
* @param Cstr the constructor for a component that we need to process
|
|
909
|
+
* @param cmpMeta metadata collected previously about the component
|
|
910
|
+
* @param flags a number used to store a series of bit flags
|
|
911
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
912
|
+
*/
|
|
804
913
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
805
914
|
if (cmpMeta.$members$) {
|
|
806
|
-
if (Cstr.watchers) {
|
|
807
|
-
cmpMeta.$watchers$ = Cstr.watchers;
|
|
808
|
-
}
|
|
809
915
|
// It's better to have a const than two Object.entries()
|
|
810
916
|
const members = Object.entries(cmpMeta.$members$);
|
|
811
917
|
const prototype = Cstr.prototype;
|
|
812
918
|
members.map(([memberName, [memberFlags]]) => {
|
|
813
|
-
if ((memberFlags & 31 /* Prop */ ||
|
|
814
|
-
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
919
|
+
if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
|
|
920
|
+
((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
|
|
815
921
|
// proxyComponent - prop
|
|
816
922
|
Object.defineProperty(prototype, memberName, {
|
|
817
923
|
get() {
|
|
@@ -827,7 +933,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
827
933
|
});
|
|
828
934
|
}
|
|
829
935
|
});
|
|
830
|
-
if ((flags & 1 /* isElementConstructor */)) {
|
|
936
|
+
if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
|
|
831
937
|
const attrNameToPropName = new Map();
|
|
832
938
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
833
939
|
plt.jmp(() => {
|
|
@@ -883,11 +989,11 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
883
989
|
// create an array of attributes to observe
|
|
884
990
|
// and also create a map of html attribute name to js property name
|
|
885
991
|
Cstr.observedAttributes = members
|
|
886
|
-
.filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
|
|
992
|
+
.filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
|
|
887
993
|
.map(([propName, m]) => {
|
|
888
994
|
const attrName = m[1] || propName;
|
|
889
995
|
attrNameToPropName.set(attrName, propName);
|
|
890
|
-
if (m[0] & 512 /* ReflectAttr */) {
|
|
996
|
+
if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
|
|
891
997
|
cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
|
892
998
|
}
|
|
893
999
|
return attrName;
|
|
@@ -898,10 +1004,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
898
1004
|
};
|
|
899
1005
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
900
1006
|
// initializeComponent
|
|
901
|
-
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
1007
|
+
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
902
1008
|
{
|
|
903
1009
|
// we haven't initialized this element yet
|
|
904
|
-
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
1010
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
905
1011
|
// lazy loaded components
|
|
906
1012
|
// request the component's implementation to be
|
|
907
1013
|
// wired up with the host element
|
|
@@ -913,13 +1019,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
913
1019
|
endLoad();
|
|
914
1020
|
}
|
|
915
1021
|
if (!Cstr.isProxied) {
|
|
916
|
-
|
|
917
|
-
// let's add the getters/setters to its prototype before
|
|
918
|
-
// the first time we create an instance of the implementation
|
|
919
|
-
{
|
|
920
|
-
cmpMeta.$watchers$ = Cstr.watchers;
|
|
921
|
-
}
|
|
922
|
-
proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
|
|
1022
|
+
proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
|
|
923
1023
|
Cstr.isProxied = true;
|
|
924
1024
|
}
|
|
925
1025
|
const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
|
@@ -927,7 +1027,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
927
1027
|
// but let's keep track of when we start and stop
|
|
928
1028
|
// so that the getters/setters don't incorrectly step on data
|
|
929
1029
|
{
|
|
930
|
-
hostRef.$flags$ |= 8 /* isConstructingInstance */;
|
|
1030
|
+
hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
|
|
931
1031
|
}
|
|
932
1032
|
// construct the lazy-loaded component implementation
|
|
933
1033
|
// passing the hostRef is very important during
|
|
@@ -940,10 +1040,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
940
1040
|
consoleError(e);
|
|
941
1041
|
}
|
|
942
1042
|
{
|
|
943
|
-
hostRef.$flags$ &= ~8 /* isConstructingInstance */;
|
|
944
|
-
}
|
|
945
|
-
{
|
|
946
|
-
hostRef.$flags$ |= 128 /* isWatchReady */;
|
|
1043
|
+
hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
|
|
947
1044
|
}
|
|
948
1045
|
endNewInstance();
|
|
949
1046
|
}
|
|
@@ -953,7 +1050,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
953
1050
|
const scopeId = getScopeId(cmpMeta);
|
|
954
1051
|
if (!styles.has(scopeId)) {
|
|
955
1052
|
const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
|
956
|
-
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
|
|
1053
|
+
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
|
|
957
1054
|
endRegisterStyles();
|
|
958
1055
|
}
|
|
959
1056
|
}
|
|
@@ -975,13 +1072,13 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
975
1072
|
}
|
|
976
1073
|
};
|
|
977
1074
|
const connectedCallback = (elm) => {
|
|
978
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1075
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
979
1076
|
const hostRef = getHostRef(elm);
|
|
980
1077
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
981
1078
|
const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
|
982
|
-
if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
|
|
1079
|
+
if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
|
|
983
1080
|
// first time this component has connected
|
|
984
|
-
hostRef.$flags$ |= 1 /* hasConnected */;
|
|
1081
|
+
hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
|
|
985
1082
|
{
|
|
986
1083
|
// find the first ancestor component (if there is one) and register
|
|
987
1084
|
// this component as one of the actively loading child components for its ancestor
|
|
@@ -1001,7 +1098,7 @@ const connectedCallback = (elm) => {
|
|
|
1001
1098
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
1002
1099
|
if (cmpMeta.$members$) {
|
|
1003
1100
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
1004
|
-
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1101
|
+
if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1005
1102
|
const value = elm[memberName];
|
|
1006
1103
|
delete elm[memberName];
|
|
1007
1104
|
elm[memberName] = value;
|
|
@@ -1016,7 +1113,7 @@ const connectedCallback = (elm) => {
|
|
|
1016
1113
|
}
|
|
1017
1114
|
};
|
|
1018
1115
|
const disconnectedCallback = (elm) => {
|
|
1019
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1116
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
1020
1117
|
getHostRef(elm);
|
|
1021
1118
|
}
|
|
1022
1119
|
};
|
|
@@ -1047,9 +1144,6 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1047
1144
|
{
|
|
1048
1145
|
cmpMeta.$attrsToReflect$ = [];
|
|
1049
1146
|
}
|
|
1050
|
-
{
|
|
1051
|
-
cmpMeta.$watchers$ = {};
|
|
1052
|
-
}
|
|
1053
1147
|
const tagName = cmpMeta.$tagName$;
|
|
1054
1148
|
const HostElement = class extends HTMLElement {
|
|
1055
1149
|
// StencilLazyHost
|
|
@@ -1058,7 +1152,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1058
1152
|
super(self);
|
|
1059
1153
|
self = this;
|
|
1060
1154
|
registerHost(self, cmpMeta);
|
|
1061
|
-
if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
|
|
1155
|
+
if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
|
|
1062
1156
|
// this component is using shadow dom
|
|
1063
1157
|
// and this browser supports shadow dom
|
|
1064
1158
|
// add the read-only property "shadowRoot" to the host element
|
|
@@ -1093,7 +1187,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1093
1187
|
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
1094
1188
|
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
1095
1189
|
cmpTags.push(tagName);
|
|
1096
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
1190
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
|
|
1097
1191
|
}
|
|
1098
1192
|
});
|
|
1099
1193
|
});
|
|
@@ -1115,7 +1209,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1115
1209
|
// Fallback appLoad event
|
|
1116
1210
|
endBootstrap();
|
|
1117
1211
|
};
|
|
1118
|
-
const hostRefs = new WeakMap();
|
|
1212
|
+
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
1119
1213
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
1120
1214
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
1121
1215
|
const registerHost = (elm, cmpMeta) => {
|
|
@@ -1156,14 +1250,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1156
1250
|
return importedModule[exportName];
|
|
1157
1251
|
}, consoleError);
|
|
1158
1252
|
};
|
|
1159
|
-
const styles = new Map();
|
|
1253
|
+
const styles = /*@__PURE__*/ new Map();
|
|
1254
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
1255
|
+
const doc = win.document || { head: {} };
|
|
1256
|
+
const plt = {
|
|
1257
|
+
$flags$: 0,
|
|
1258
|
+
$resourcesUrl$: '',
|
|
1259
|
+
jmp: (h) => h(),
|
|
1260
|
+
raf: (h) => requestAnimationFrame(h),
|
|
1261
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
1262
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
1263
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
1264
|
+
};
|
|
1265
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
1266
|
+
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
1267
|
+
try {
|
|
1268
|
+
new CSSStyleSheet();
|
|
1269
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
1270
|
+
}
|
|
1271
|
+
catch (e) { }
|
|
1272
|
+
return false;
|
|
1273
|
+
})()
|
|
1274
|
+
;
|
|
1160
1275
|
const queueDomReads = [];
|
|
1161
1276
|
const queueDomWrites = [];
|
|
1162
1277
|
const queueTask = (queue, write) => (cb) => {
|
|
1163
1278
|
queue.push(cb);
|
|
1164
1279
|
if (!queuePending) {
|
|
1165
1280
|
queuePending = true;
|
|
1166
|
-
if (write && plt.$flags$ & 4 /* queueSync */) {
|
|
1281
|
+
if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
|
|
1167
1282
|
nextTick(flush);
|
|
1168
1283
|
}
|
|
1169
1284
|
else {
|