skeleton-webcomponent-loader 1.0.2 → 2.1.1
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/CHANGELOG.md +26 -0
- package/dist/cjs/{css-shim-b5b9a7c7.js → css-shim-b3e497ca.js} +1 -1
- package/dist/cjs/{index-b7b0a13e.js → index-b5d2dca0.js} +209 -138
- package/dist/cjs/loader.cjs.js +5 -5
- package/dist/cjs/nb-skeleton.cjs.entry.js +23 -77
- package/dist/cjs/skeleton-webcomponent.cjs.js +5 -5
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/skeleton/skeleton.js +71 -39
- package/dist/custom-elements/index.d.ts +10 -2
- package/dist/custom-elements/index.js +26 -79
- package/dist/esm/{css-shim-2bc9d17d.js → css-shim-2f04a37a.js} +1 -1
- package/dist/esm/{index-f5ca0f12.js → index-63fd3905.js} +193 -121
- package/dist/esm/loader.js +5 -5
- package/dist/esm/nb-skeleton.entry.js +23 -77
- package/dist/esm/polyfills/index.js +2 -2
- package/dist/esm/skeleton-webcomponent.js +5 -5
- package/dist/esm-es5/{css-shim-2bc9d17d.js → css-shim-2f04a37a.js} +0 -0
- package/dist/esm-es5/index-63fd3905.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/nb-skeleton.entry.js +1 -7
- package/dist/esm-es5/skeleton-webcomponent.js +1 -1
- package/dist/skeleton-webcomponent/p-12077897.js +1 -0
- package/dist/skeleton-webcomponent/{p-527e1426.system.js → p-16aec442.system.js} +0 -0
- package/dist/skeleton-webcomponent/p-63ed3b45.entry.js +1 -0
- package/dist/skeleton-webcomponent/p-7e96e5d4.js +1 -0
- package/dist/skeleton-webcomponent/p-8bef7229.system.js +1 -0
- package/dist/skeleton-webcomponent/p-dc1bf577.system.entry.js +1 -0
- package/dist/skeleton-webcomponent/p-f59432d4.system.js +1 -0
- package/dist/skeleton-webcomponent/skeleton-webcomponent.esm.js +1 -1
- package/dist/skeleton-webcomponent/skeleton-webcomponent.js +1 -1
- package/dist/types/components/skeleton/skeleton.d.ts +9 -1
- package/dist/types/components.d.ts +14 -2
- package/dist/types/stencil-public-runtime.d.ts +225 -195
- package/loader/index.d.ts +0 -1
- package/package.json +19 -7
- package/readme.md +7 -5
- package/dist/esm-es5/index-f5ca0f12.js +0 -1
- package/dist/skeleton-webcomponent/p-4be3ea66.system.entry.js +0 -7
- package/dist/skeleton-webcomponent/p-8715773a.entry.js +0 -7
- package/dist/skeleton-webcomponent/p-8f82881f.js +0 -1
- package/dist/skeleton-webcomponent/p-b131d02e.system.js +0 -1
- package/dist/skeleton-webcomponent/p-d9243289.js +0 -1
- package/dist/skeleton-webcomponent/p-fde56e0b.system.js +0 -1
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
const NAMESPACE = 'skeleton-webcomponent';
|
|
2
2
|
|
|
3
3
|
let scopeId;
|
|
4
|
+
let hostTagName;
|
|
4
5
|
let isSvgMode = false;
|
|
5
6
|
let queuePending = false;
|
|
6
7
|
const win = typeof window !== 'undefined' ? window : {};
|
|
7
|
-
const CSS =
|
|
8
|
+
const CSS = win.CSS ;
|
|
8
9
|
const doc = win.document || { head: {} };
|
|
9
10
|
const plt = {
|
|
10
11
|
$flags$: 0,
|
|
11
12
|
$resourcesUrl$: '',
|
|
12
|
-
jmp: h => h(),
|
|
13
|
-
raf: h => requestAnimationFrame(h),
|
|
13
|
+
jmp: (h) => h(),
|
|
14
|
+
raf: (h) => requestAnimationFrame(h),
|
|
14
15
|
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
15
16
|
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
16
17
|
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
17
18
|
};
|
|
18
19
|
const promiseResolve = (v) => Promise.resolve(v);
|
|
19
|
-
const supportsConstructibleStylesheets =
|
|
20
|
+
const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
|
|
20
21
|
try {
|
|
21
22
|
new CSSStyleSheet();
|
|
22
|
-
return
|
|
23
|
+
return typeof new CSSStyleSheet().replace === 'function';
|
|
23
24
|
}
|
|
24
25
|
catch (e) { }
|
|
25
26
|
return false;
|
|
@@ -68,7 +69,7 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
|
68
69
|
}
|
|
69
70
|
if (!appliedStyles.has(scopeId)) {
|
|
70
71
|
{
|
|
71
|
-
if (
|
|
72
|
+
if (plt.$cssShim$) {
|
|
72
73
|
styleElm = plt.$cssShim$.createHostStyle(hostElm, scopeId, style, !!(cmpMeta.$flags$ & 10 /* needsScopedEncapsulation */));
|
|
73
74
|
const newScopeId = styleElm['s-sc'];
|
|
74
75
|
if (newScopeId) {
|
|
@@ -90,7 +91,7 @@ const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
|
-
else if (
|
|
94
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
94
95
|
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -101,8 +102,8 @@ const attachStyles = (hostRef) => {
|
|
|
101
102
|
const elm = hostRef.$hostElement$;
|
|
102
103
|
const flags = cmpMeta.$flags$;
|
|
103
104
|
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
104
|
-
const scopeId = addStyle( elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
|
|
105
|
-
if (
|
|
105
|
+
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta, hostRef.$modeName$, elm);
|
|
106
|
+
if (flags & 10 /* needsScopedEncapsulation */) {
|
|
106
107
|
// only required when we're NOT using native shadow dom (slot)
|
|
107
108
|
// or this browser doesn't support native shadow dom
|
|
108
109
|
// and this host element was NOT created with SSR
|
|
@@ -112,13 +113,10 @@ const attachStyles = (hostRef) => {
|
|
|
112
113
|
// DOM WRITE!!
|
|
113
114
|
elm['s-sc'] = scopeId;
|
|
114
115
|
elm.classList.add(scopeId + '-h');
|
|
115
|
-
if ( flags & 2 /* scopedCssEncapsulation */) {
|
|
116
|
-
elm.classList.add(scopeId + '-s');
|
|
117
|
-
}
|
|
118
116
|
}
|
|
119
117
|
endAttachStyles();
|
|
120
118
|
};
|
|
121
|
-
const getScopeId = (cmp, mode) => 'sc-' + (
|
|
119
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
122
120
|
/**
|
|
123
121
|
* Default style mode id
|
|
124
122
|
*/
|
|
@@ -175,7 +173,7 @@ const h = (nodeName, vnodeData, ...children) => {
|
|
|
175
173
|
walk(children);
|
|
176
174
|
if (vnodeData) {
|
|
177
175
|
// normalize class / classname attributes
|
|
178
|
-
if (
|
|
176
|
+
if (vnodeData.key) {
|
|
179
177
|
key = vnodeData.key;
|
|
180
178
|
}
|
|
181
179
|
{
|
|
@@ -185,7 +183,7 @@ const h = (nodeName, vnodeData, ...children) => {
|
|
|
185
183
|
typeof classData !== 'object'
|
|
186
184
|
? classData
|
|
187
185
|
: Object.keys(classData)
|
|
188
|
-
.filter(k => classData[k])
|
|
186
|
+
.filter((k) => classData[k])
|
|
189
187
|
.join(' ');
|
|
190
188
|
}
|
|
191
189
|
}
|
|
@@ -229,20 +227,20 @@ const isHost = (node) => node && node.$tag$ === Host;
|
|
|
229
227
|
const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
230
228
|
if (oldValue !== newValue) {
|
|
231
229
|
let isProp = isMemberInElement(elm, memberName);
|
|
232
|
-
|
|
233
|
-
if (
|
|
230
|
+
memberName.toLowerCase();
|
|
231
|
+
if (memberName === 'class') {
|
|
234
232
|
const classList = elm.classList;
|
|
235
233
|
const oldClasses = parseClassList(oldValue);
|
|
236
234
|
const newClasses = parseClassList(newValue);
|
|
237
|
-
classList.remove(...oldClasses.filter(c => c && !newClasses.includes(c)));
|
|
238
|
-
classList.add(...newClasses.filter(c => c && !oldClasses.includes(c)));
|
|
235
|
+
classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
|
|
236
|
+
classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
|
|
239
237
|
}
|
|
240
|
-
else if (
|
|
238
|
+
else if (memberName === 'style') {
|
|
241
239
|
// update style attribute, css properties and values
|
|
242
240
|
{
|
|
243
241
|
for (const prop in oldValue) {
|
|
244
242
|
if (!newValue || newValue[prop] == null) {
|
|
245
|
-
if (
|
|
243
|
+
if (prop.includes('-')) {
|
|
246
244
|
elm.style.removeProperty(prop);
|
|
247
245
|
}
|
|
248
246
|
else {
|
|
@@ -253,7 +251,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
253
251
|
}
|
|
254
252
|
for (const prop in newValue) {
|
|
255
253
|
if (!oldValue || newValue[prop] !== oldValue[prop]) {
|
|
256
|
-
if (
|
|
254
|
+
if (prop.includes('-')) {
|
|
257
255
|
elm.style.setProperty(prop, newValue[prop]);
|
|
258
256
|
}
|
|
259
257
|
else {
|
|
@@ -262,7 +260,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
262
260
|
}
|
|
263
261
|
}
|
|
264
262
|
}
|
|
265
|
-
else if (
|
|
263
|
+
else if (memberName === 'key')
|
|
266
264
|
;
|
|
267
265
|
else {
|
|
268
266
|
// Set property if it exists and it's not a SVG
|
|
@@ -274,7 +272,6 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
274
272
|
// Workaround for Safari, moving the <input> caret when re-assigning the same valued
|
|
275
273
|
if (memberName === 'list') {
|
|
276
274
|
isProp = false;
|
|
277
|
-
// tslint:disable-next-line: triple-equals
|
|
278
275
|
}
|
|
279
276
|
else if (oldValue == null || elm[memberName] != n) {
|
|
280
277
|
elm[memberName] = n;
|
|
@@ -308,7 +305,9 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
308
305
|
// if the element passed in is a shadow root, which is a document fragment
|
|
309
306
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
310
307
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
311
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
308
|
+
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
309
|
+
? newVnode.$elm$.host
|
|
310
|
+
: newVnode.$elm$;
|
|
312
311
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
313
312
|
const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
|
|
314
313
|
{
|
|
@@ -332,12 +331,12 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
332
331
|
let childNode;
|
|
333
332
|
{
|
|
334
333
|
// create element
|
|
335
|
-
elm = newVNode.$elm$ = (
|
|
334
|
+
elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
|
|
336
335
|
// add css classes, attrs, props, listeners, etc.
|
|
337
336
|
{
|
|
338
337
|
updateElement(null, newVNode, isSvgMode);
|
|
339
338
|
}
|
|
340
|
-
if (
|
|
339
|
+
if (isDef(scopeId) && elm['s-si'] !== scopeId) {
|
|
341
340
|
// if there is a scopeId and this is the initial render
|
|
342
341
|
// then let's add the scopeId as a css class
|
|
343
342
|
elm.classList.add((elm['s-si'] = scopeId));
|
|
@@ -357,14 +356,17 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
357
356
|
return elm;
|
|
358
357
|
};
|
|
359
358
|
const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
360
|
-
let containerElm = (
|
|
359
|
+
let containerElm = (parentElm);
|
|
361
360
|
let childNode;
|
|
361
|
+
if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
|
|
362
|
+
containerElm = containerElm.shadowRoot;
|
|
363
|
+
}
|
|
362
364
|
for (; startIdx <= endIdx; ++startIdx) {
|
|
363
365
|
if (vnodes[startIdx]) {
|
|
364
366
|
childNode = createElm(null, parentVNode, startIdx);
|
|
365
367
|
if (childNode) {
|
|
366
368
|
vnodes[startIdx].$elm$ = childNode;
|
|
367
|
-
containerElm.insertBefore(childNode,
|
|
369
|
+
containerElm.insertBefore(childNode, before);
|
|
368
370
|
}
|
|
369
371
|
}
|
|
370
372
|
}
|
|
@@ -438,7 +440,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
438
440
|
}
|
|
439
441
|
}
|
|
440
442
|
}
|
|
441
|
-
if (
|
|
443
|
+
if (idxInOld >= 0) {
|
|
442
444
|
elmToMove = oldCh[idxInOld];
|
|
443
445
|
if (elmToMove.$tag$ !== newStartVnode.$tag$) {
|
|
444
446
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
|
|
@@ -465,7 +467,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
465
467
|
if (oldStartIdx > oldEndIdx) {
|
|
466
468
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
467
469
|
}
|
|
468
|
-
else if (
|
|
470
|
+
else if (newStartIdx > newEndIdx) {
|
|
469
471
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
470
472
|
}
|
|
471
473
|
};
|
|
@@ -493,7 +495,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
493
495
|
updateElement(oldVNode, newVNode, isSvgMode);
|
|
494
496
|
}
|
|
495
497
|
}
|
|
496
|
-
if (
|
|
498
|
+
if (oldChildren !== null && newChildren !== null) {
|
|
497
499
|
// looks like there's child vnodes for both the old and new vnodes
|
|
498
500
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
499
501
|
}
|
|
@@ -501,7 +503,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
501
503
|
// add the new vnode children
|
|
502
504
|
addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
|
|
503
505
|
}
|
|
504
|
-
else if (
|
|
506
|
+
else if (oldChildren !== null) {
|
|
505
507
|
// no new child vnodes, but there are old child vnodes to remove
|
|
506
508
|
removeVnodes(oldChildren, 0, oldChildren.length - 1);
|
|
507
509
|
}
|
|
@@ -511,31 +513,39 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
511
513
|
const hostElm = hostRef.$hostElement$;
|
|
512
514
|
const oldVNode = hostRef.$vnode$ || newVNode(null, null);
|
|
513
515
|
const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
|
|
516
|
+
hostTagName = hostElm.tagName;
|
|
514
517
|
rootVnode.$tag$ = null;
|
|
515
518
|
rootVnode.$flags$ |= 4 /* isHost */;
|
|
516
519
|
hostRef.$vnode$ = rootVnode;
|
|
517
|
-
rootVnode.$elm$ = oldVNode.$elm$ = ( hostElm);
|
|
520
|
+
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
|
518
521
|
{
|
|
519
522
|
scopeId = hostElm['s-sc'];
|
|
520
523
|
}
|
|
521
524
|
// synchronous patch
|
|
522
525
|
patch(oldVNode, rootVnode);
|
|
523
526
|
};
|
|
527
|
+
/**
|
|
528
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
529
|
+
* @param elm the target of the Event
|
|
530
|
+
* @param name the name to give the custom Event
|
|
531
|
+
* @param opts options for configuring a custom Event
|
|
532
|
+
* @returns the custom Event
|
|
533
|
+
*/
|
|
524
534
|
const emitEvent = (elm, name, opts) => {
|
|
525
535
|
const ev = plt.ce(name, opts);
|
|
526
536
|
elm.dispatchEvent(ev);
|
|
527
537
|
return ev;
|
|
528
538
|
};
|
|
529
539
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
530
|
-
if (
|
|
531
|
-
ancestorComponent['s-p'].push(new Promise(r => (hostRef.$onRenderResolve$ = r)));
|
|
540
|
+
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
541
|
+
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
532
542
|
}
|
|
533
543
|
};
|
|
534
544
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
535
545
|
{
|
|
536
546
|
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
537
547
|
}
|
|
538
|
-
if (
|
|
548
|
+
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
539
549
|
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
540
550
|
return;
|
|
541
551
|
}
|
|
@@ -544,11 +554,11 @@ const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
|
544
554
|
// has already fired off its lifecycle update then
|
|
545
555
|
// fire off the initial update
|
|
546
556
|
const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
|
|
547
|
-
return
|
|
557
|
+
return writeTask(dispatch) ;
|
|
548
558
|
};
|
|
549
559
|
const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
550
560
|
const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
|
|
551
|
-
const instance =
|
|
561
|
+
const instance = hostRef.$lazyInstance$ ;
|
|
552
562
|
let promise;
|
|
553
563
|
if (isInitialLoad) {
|
|
554
564
|
{
|
|
@@ -568,29 +578,22 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
568
578
|
const elm = hostRef.$hostElement$;
|
|
569
579
|
const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
|
|
570
580
|
const rc = elm['s-rc'];
|
|
571
|
-
if (
|
|
581
|
+
if (isInitialLoad) {
|
|
572
582
|
// DOM WRITE!
|
|
573
583
|
attachStyles(hostRef);
|
|
574
584
|
}
|
|
575
585
|
const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
|
|
576
586
|
{
|
|
577
|
-
|
|
578
|
-
// looks like we've got child nodes to render into this host element
|
|
579
|
-
// or we need to update the css class/attrs on the host element
|
|
580
|
-
// DOM WRITE!
|
|
581
|
-
{
|
|
582
|
-
renderVdom(hostRef, callRender(hostRef, instance));
|
|
583
|
-
}
|
|
584
|
-
}
|
|
587
|
+
callRender(hostRef, instance);
|
|
585
588
|
}
|
|
586
|
-
if (
|
|
589
|
+
if (plt.$cssShim$) {
|
|
587
590
|
plt.$cssShim$.updateHost(elm);
|
|
588
591
|
}
|
|
589
|
-
if (
|
|
592
|
+
if (rc) {
|
|
590
593
|
// ok, so turns out there are some child host elements
|
|
591
594
|
// waiting on this parent element to load
|
|
592
595
|
// let's fire off all update callbacks waiting
|
|
593
|
-
rc.map(cb => cb());
|
|
596
|
+
rc.map((cb) => cb());
|
|
594
597
|
elm['s-rc'] = undefined;
|
|
595
598
|
}
|
|
596
599
|
endRender();
|
|
@@ -608,20 +611,30 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
608
611
|
}
|
|
609
612
|
}
|
|
610
613
|
};
|
|
611
|
-
const callRender = (hostRef, instance) => {
|
|
614
|
+
const callRender = (hostRef, instance, elm) => {
|
|
612
615
|
try {
|
|
613
|
-
instance =
|
|
616
|
+
instance = instance.render() ;
|
|
614
617
|
{
|
|
615
618
|
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
616
619
|
}
|
|
617
620
|
{
|
|
618
621
|
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
619
622
|
}
|
|
623
|
+
{
|
|
624
|
+
{
|
|
625
|
+
// looks like we've got child nodes to render into this host element
|
|
626
|
+
// or we need to update the css class/attrs on the host element
|
|
627
|
+
// DOM WRITE!
|
|
628
|
+
{
|
|
629
|
+
renderVdom(hostRef, instance);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
620
633
|
}
|
|
621
634
|
catch (e) {
|
|
622
|
-
consoleError(e);
|
|
635
|
+
consoleError(e, hostRef.$hostElement$);
|
|
623
636
|
}
|
|
624
|
-
return
|
|
637
|
+
return null;
|
|
625
638
|
};
|
|
626
639
|
const postUpdateComponent = (hostRef) => {
|
|
627
640
|
const tagName = hostRef.$cmpMeta$.$tagName$;
|
|
@@ -683,20 +696,21 @@ const safeCall = (instance, method, arg) => {
|
|
|
683
696
|
const then = (promise, thenFn) => {
|
|
684
697
|
return promise && promise.then ? promise.then(thenFn) : thenFn();
|
|
685
698
|
};
|
|
686
|
-
const addHydratedFlag = (elm) =>
|
|
699
|
+
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
700
|
+
;
|
|
687
701
|
const parsePropertyValue = (propValue, propType) => {
|
|
688
702
|
// ensure this value is of the correct prop type
|
|
689
703
|
if (propValue != null && !isComplexType(propValue)) {
|
|
690
|
-
if (
|
|
704
|
+
if (propType & 4 /* Boolean */) {
|
|
691
705
|
// per the HTML spec, any string value means it is a boolean true value
|
|
692
706
|
// but we'll cheat here and say that the string "false" is the boolean false
|
|
693
707
|
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
694
708
|
}
|
|
695
|
-
if (
|
|
709
|
+
if (propType & 2 /* Number */) {
|
|
696
710
|
// force it to be a number
|
|
697
711
|
return parseFloat(propValue);
|
|
698
712
|
}
|
|
699
|
-
if (
|
|
713
|
+
if (propType & 1 /* String */) {
|
|
700
714
|
// could have been passed as a number or boolean
|
|
701
715
|
// but we still want it as a string
|
|
702
716
|
return String(propValue);
|
|
@@ -714,14 +728,14 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
714
728
|
const hostRef = getHostRef(ref);
|
|
715
729
|
const oldVal = hostRef.$instanceValues$.get(propName);
|
|
716
730
|
const flags = hostRef.$flags$;
|
|
717
|
-
const instance =
|
|
731
|
+
const instance = hostRef.$lazyInstance$ ;
|
|
718
732
|
newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
|
|
719
|
-
if ((
|
|
733
|
+
if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && newVal !== oldVal) {
|
|
720
734
|
// gadzooks! the property's value has changed!!
|
|
721
735
|
// set our new value!
|
|
722
736
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
723
|
-
if (
|
|
724
|
-
if (
|
|
737
|
+
if (instance) {
|
|
738
|
+
if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
|
|
725
739
|
// looks like this value actually changed, so we've got work to do!
|
|
726
740
|
// but only if we've already rendered, otherwise just chill out
|
|
727
741
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -732,12 +746,13 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
732
746
|
}
|
|
733
747
|
};
|
|
734
748
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
735
|
-
if (
|
|
749
|
+
if (cmpMeta.$members$) {
|
|
736
750
|
// It's better to have a const than two Object.entries()
|
|
737
751
|
const members = Object.entries(cmpMeta.$members$);
|
|
738
752
|
const prototype = Cstr.prototype;
|
|
739
753
|
members.map(([memberName, [memberFlags]]) => {
|
|
740
|
-
if (
|
|
754
|
+
if ((memberFlags & 31 /* Prop */ ||
|
|
755
|
+
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
741
756
|
// proxyComponent - prop
|
|
742
757
|
Object.defineProperty(prototype, memberName, {
|
|
743
758
|
get() {
|
|
@@ -753,11 +768,56 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
753
768
|
});
|
|
754
769
|
}
|
|
755
770
|
});
|
|
756
|
-
if (
|
|
771
|
+
if ((flags & 1 /* isElementConstructor */)) {
|
|
757
772
|
const attrNameToPropName = new Map();
|
|
758
773
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
759
774
|
plt.jmp(() => {
|
|
760
775
|
const propName = attrNameToPropName.get(attrName);
|
|
776
|
+
// In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
|
|
777
|
+
// in the case where an attribute was set inline.
|
|
778
|
+
// ```html
|
|
779
|
+
// <my-component some-attribute="some-value"></my-component>
|
|
780
|
+
// ```
|
|
781
|
+
//
|
|
782
|
+
// There is an edge case where a developer sets the attribute inline on a custom element and then
|
|
783
|
+
// programmatically changes it before it has been upgraded as shown below:
|
|
784
|
+
//
|
|
785
|
+
// ```html
|
|
786
|
+
// <!-- this component has _not_ been upgraded yet -->
|
|
787
|
+
// <my-component id="test" some-attribute="some-value"></my-component>
|
|
788
|
+
// <script>
|
|
789
|
+
// // grab non-upgraded component
|
|
790
|
+
// el = document.querySelector("#test");
|
|
791
|
+
// el.someAttribute = "another-value";
|
|
792
|
+
// // upgrade component
|
|
793
|
+
// customElements.define('my-component', MyComponent);
|
|
794
|
+
// </script>
|
|
795
|
+
// ```
|
|
796
|
+
// In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
|
|
797
|
+
// will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
|
|
798
|
+
// to the value that was set inline i.e. "some-value" from above example. When
|
|
799
|
+
// the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
|
|
800
|
+
//
|
|
801
|
+
// The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
|
|
802
|
+
// by connectedCallback as this attributeChangedCallback will not fire.
|
|
803
|
+
//
|
|
804
|
+
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
805
|
+
//
|
|
806
|
+
// TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
|
|
807
|
+
// properties here given that this goes against best practices outlined here
|
|
808
|
+
// https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
|
|
809
|
+
if (this.hasOwnProperty(propName)) {
|
|
810
|
+
newValue = this[propName];
|
|
811
|
+
delete this[propName];
|
|
812
|
+
}
|
|
813
|
+
else if (prototype.hasOwnProperty(propName) &&
|
|
814
|
+
typeof this[propName] === 'number' &&
|
|
815
|
+
this[propName] == newValue) {
|
|
816
|
+
// if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
|
|
817
|
+
// APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
|
|
818
|
+
// `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
761
821
|
this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
|
|
762
822
|
});
|
|
763
823
|
};
|
|
@@ -776,7 +836,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
776
836
|
};
|
|
777
837
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
778
838
|
// initializeComponent
|
|
779
|
-
if (
|
|
839
|
+
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
780
840
|
{
|
|
781
841
|
// we haven't initialized this element yet
|
|
782
842
|
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
@@ -790,7 +850,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
790
850
|
Cstr = await Cstr;
|
|
791
851
|
endLoad();
|
|
792
852
|
}
|
|
793
|
-
if (
|
|
853
|
+
if (!Cstr.isProxied) {
|
|
794
854
|
proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
|
|
795
855
|
Cstr.isProxied = true;
|
|
796
856
|
}
|
|
@@ -816,7 +876,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
816
876
|
}
|
|
817
877
|
endNewInstance();
|
|
818
878
|
}
|
|
819
|
-
if (
|
|
879
|
+
if (Cstr.style) {
|
|
820
880
|
// this component has styles but we haven't registered them yet
|
|
821
881
|
let style = Cstr.style;
|
|
822
882
|
const scopeId = getScopeId(cmpMeta);
|
|
@@ -830,8 +890,8 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
830
890
|
// we've successfully created a lazy instance
|
|
831
891
|
const ancestorComponent = hostRef.$ancestorComponent$;
|
|
832
892
|
const schedule = () => scheduleUpdate(hostRef, true);
|
|
833
|
-
if (
|
|
834
|
-
// this is the
|
|
893
|
+
if (ancestorComponent && ancestorComponent['s-rc']) {
|
|
894
|
+
// this is the initial load and this component it has an ancestor component
|
|
835
895
|
// but the ancestor component has NOT fired its will update lifecycle yet
|
|
836
896
|
// so let's just cool our jets and wait for the ancestor to continue first
|
|
837
897
|
// this will get fired off when the ancestor component
|
|
@@ -858,8 +918,7 @@ const connectedCallback = (elm) => {
|
|
|
858
918
|
while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
|
|
859
919
|
// climb up the ancestors looking for the first
|
|
860
920
|
// component that hasn't finished its lifecycle update yet
|
|
861
|
-
if (
|
|
862
|
-
ancestorComponent['s-p']) {
|
|
921
|
+
if (ancestorComponent['s-p']) {
|
|
863
922
|
// we found this components first ancestor component
|
|
864
923
|
// keep a reference to this component's ancestor component
|
|
865
924
|
attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
|
|
@@ -869,7 +928,7 @@ const connectedCallback = (elm) => {
|
|
|
869
928
|
}
|
|
870
929
|
// Lazy properties
|
|
871
930
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
872
|
-
if (
|
|
931
|
+
if (cmpMeta.$members$) {
|
|
873
932
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
874
933
|
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
875
934
|
const value = elm[memberName];
|
|
@@ -887,9 +946,9 @@ const connectedCallback = (elm) => {
|
|
|
887
946
|
};
|
|
888
947
|
const disconnectedCallback = (elm) => {
|
|
889
948
|
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
890
|
-
|
|
949
|
+
getHostRef(elm);
|
|
891
950
|
// clear CSS var-shim tracking
|
|
892
|
-
if (
|
|
951
|
+
if (plt.$cssShim$) {
|
|
893
952
|
plt.$cssShim$.removeHost(elm);
|
|
894
953
|
}
|
|
895
954
|
}
|
|
@@ -907,51 +966,64 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
907
966
|
let isBootstrapping = true;
|
|
908
967
|
Object.assign(plt, options);
|
|
909
968
|
plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
|
|
910
|
-
lazyBundles.map(lazyBundle =>
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
const tagName = cmpMeta.$tagName$;
|
|
921
|
-
const HostElement = class extends HTMLElement {
|
|
922
|
-
// StencilLazyHost
|
|
923
|
-
constructor(self) {
|
|
924
|
-
// @ts-ignore
|
|
925
|
-
super(self);
|
|
926
|
-
self = this;
|
|
927
|
-
registerHost(self, cmpMeta);
|
|
969
|
+
lazyBundles.map((lazyBundle) => {
|
|
970
|
+
lazyBundle[1].map((compactMeta) => {
|
|
971
|
+
const cmpMeta = {
|
|
972
|
+
$flags$: compactMeta[0],
|
|
973
|
+
$tagName$: compactMeta[1],
|
|
974
|
+
$members$: compactMeta[2],
|
|
975
|
+
$listeners$: compactMeta[3],
|
|
976
|
+
};
|
|
977
|
+
{
|
|
978
|
+
cmpMeta.$members$ = compactMeta[2];
|
|
928
979
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
980
|
+
const tagName = cmpMeta.$tagName$;
|
|
981
|
+
const HostElement = class extends HTMLElement {
|
|
982
|
+
// StencilLazyHost
|
|
983
|
+
constructor(self) {
|
|
984
|
+
// @ts-ignore
|
|
985
|
+
super(self);
|
|
986
|
+
self = this;
|
|
987
|
+
registerHost(self, cmpMeta);
|
|
988
|
+
if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
|
|
989
|
+
// this component is using shadow dom
|
|
990
|
+
// and this browser supports shadow dom
|
|
991
|
+
// add the read-only property "shadowRoot" to the host element
|
|
992
|
+
// adding the shadow root build conditionals to minimize runtime
|
|
993
|
+
{
|
|
994
|
+
{
|
|
995
|
+
self.attachShadow({ mode: 'open' });
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
933
999
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1000
|
+
connectedCallback() {
|
|
1001
|
+
if (appLoadFallback) {
|
|
1002
|
+
clearTimeout(appLoadFallback);
|
|
1003
|
+
appLoadFallback = null;
|
|
1004
|
+
}
|
|
1005
|
+
if (isBootstrapping) {
|
|
1006
|
+
// connectedCallback will be processed once all components have been registered
|
|
1007
|
+
deferredConnectedCallbacks.push(this);
|
|
1008
|
+
}
|
|
1009
|
+
else {
|
|
1010
|
+
plt.jmp(() => connectedCallback(this));
|
|
1011
|
+
}
|
|
937
1012
|
}
|
|
938
|
-
|
|
939
|
-
plt.jmp(() =>
|
|
1013
|
+
disconnectedCallback() {
|
|
1014
|
+
plt.jmp(() => disconnectedCallback(this));
|
|
940
1015
|
}
|
|
1016
|
+
componentOnReady() {
|
|
1017
|
+
return getHostRef(this).$onReadyPromise$;
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
1021
|
+
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
1022
|
+
cmpTags.push(tagName);
|
|
1023
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
941
1024
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
componentOnReady() {
|
|
946
|
-
return getHostRef(this).$onReadyPromise$;
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
950
|
-
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
951
|
-
cmpTags.push(tagName);
|
|
952
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
953
|
-
}
|
|
954
|
-
}));
|
|
1025
|
+
});
|
|
1026
|
+
});
|
|
955
1027
|
{
|
|
956
1028
|
visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
|
|
957
1029
|
visibilityStyle.setAttribute('data-styles', '');
|
|
@@ -960,7 +1032,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
960
1032
|
// Process deferred connectedCallbacks now all components have been registered
|
|
961
1033
|
isBootstrapping = false;
|
|
962
1034
|
if (deferredConnectedCallbacks.length) {
|
|
963
|
-
deferredConnectedCallbacks.map(host => host.connectedCallback());
|
|
1035
|
+
deferredConnectedCallbacks.map((host) => host.connectedCallback());
|
|
964
1036
|
}
|
|
965
1037
|
else {
|
|
966
1038
|
{
|
|
@@ -981,20 +1053,20 @@ const registerHost = (elm, cmpMeta) => {
|
|
|
981
1053
|
$instanceValues$: new Map(),
|
|
982
1054
|
};
|
|
983
1055
|
{
|
|
984
|
-
hostRef.$onReadyPromise$ = new Promise(r => (hostRef.$onReadyResolve$ = r));
|
|
1056
|
+
hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
|
|
985
1057
|
elm['s-p'] = [];
|
|
986
1058
|
elm['s-rc'] = [];
|
|
987
1059
|
}
|
|
988
1060
|
return hostRefs.set(elm, hostRef);
|
|
989
1061
|
};
|
|
990
1062
|
const isMemberInElement = (elm, memberName) => memberName in elm;
|
|
991
|
-
const consoleError = (e) => console.error(e);
|
|
1063
|
+
const consoleError = (e, el) => (0, console.error)(e, el);
|
|
992
1064
|
const cmpModules = /*@__PURE__*/ new Map();
|
|
993
1065
|
const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
994
1066
|
// loadModuleImport
|
|
995
1067
|
const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
|
|
996
1068
|
const bundleId = cmpMeta.$lazyBundleId$;
|
|
997
|
-
const module =
|
|
1069
|
+
const module = cmpModules.get(bundleId) ;
|
|
998
1070
|
if (module) {
|
|
999
1071
|
return module[exportName];
|
|
1000
1072
|
}
|
|
@@ -1002,7 +1074,7 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1002
1074
|
/* webpackInclude: /\.entry\.js$/ */
|
|
1003
1075
|
/* webpackExclude: /\.system\.entry\.js$/ */
|
|
1004
1076
|
/* webpackMode: "lazy" */
|
|
1005
|
-
`./${bundleId}.entry.js${
|
|
1077
|
+
`./${bundleId}.entry.js${''}`).then((importedModule) => {
|
|
1006
1078
|
{
|
|
1007
1079
|
cmpModules.set(bundleId, importedModule);
|
|
1008
1080
|
}
|