@maggioli-design-system/mds-progress 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-70bc96f7.js → index-db3031a9.js} +395 -182
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/mds-progress.cjs.entry.js +29 -3
- package/dist/cjs/mds-progress.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-progress/mds-progress.css +5 -11
- package/dist/collection/components/mds-progress/mds-progress.js +131 -72
- 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-progress.js +32 -4
- package/dist/esm/{index-38630cc3.js → index-c2cf8238.js} +395 -183
- package/dist/esm/loader.js +3 -3
- package/dist/esm/mds-progress.entry.js +29 -3
- package/dist/esm/mds-progress.js +3 -3
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm-es5/index-c2cf8238.js +2 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/mds-progress.entry.js +1 -1
- package/dist/esm-es5/mds-progress.js +1 -1
- package/dist/mds-progress/mds-progress.esm.js +1 -1
- package/dist/mds-progress/mds-progress.js +2 -1
- package/dist/mds-progress/p-763baf47.js +2 -0
- package/dist/mds-progress/p-c94616ee.system.js +2 -0
- package/dist/mds-progress/p-ccaf7022.system.entry.js +1 -0
- package/dist/mds-progress/p-e91b0c4d.entry.js +1 -0
- package/dist/mds-progress/p-f219ebba.system.js +1 -0
- package/dist/stats.json +109 -46
- package/dist/types/common/aria.d.ts +4 -0
- package/dist/types/components/mds-progress/mds-progress.d.ts +11 -0
- package/dist/types/components.d.ts +8 -0
- 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 +3 -3
- package/readme.md +6 -5
- package/src/common/aria.ts +27 -0
- package/src/components/mds-progress/.gitlab-ci.yml +2 -2
- package/src/components/mds-progress/mds-progress.css +7 -10
- package/src/components/mds-progress/mds-progress.tsx +33 -3
- package/src/components/mds-progress/readme.md +6 -5
- package/src/components.d.ts +8 -0
- package/src/dictionary/typography.ts +19 -4
- package/src/types/typography.ts +13 -2
- package/www/build/mds-progress.esm.js +1 -1
- package/www/build/mds-progress.js +2 -1
- package/www/build/p-763baf47.js +2 -0
- package/www/build/p-c94616ee.system.js +2 -0
- package/www/build/p-ccaf7022.system.entry.js +1 -0
- package/www/build/p-e91b0c4d.entry.js +1 -0
- package/www/build/p-f219ebba.system.js +1 -0
- package/dist/esm-es5/index-38630cc3.js +0 -2
- package/dist/mds-progress/p-284f97ac.entry.js +0 -1
- package/dist/mds-progress/p-d402cd92.system.js +0 -2
- package/dist/mds-progress/p-d64b07f9.system.js +0 -1
- package/dist/mds-progress/p-dadd4466.js +0 -2
- package/dist/mds-progress/p-f93dfdf4.system.entry.js +0 -1
- package/www/build/p-284f97ac.entry.js +0 -1
- package/www/build/p-d402cd92.system.js +0 -2
- package/www/build/p-d64b07f9.system.js +0 -1
- package/www/build/p-dadd4466.js +0 -2
- package/www/build/p-f93dfdf4.system.entry.js +0 -1
|
@@ -22,32 +22,18 @@ function _interopNamespace(e) {
|
|
|
22
22
|
|
|
23
23
|
const NAMESPACE = 'mds-progress';
|
|
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,131 @@ 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 & 2 /* MEMBER_FLAGS.Number */) {
|
|
167
|
+
// force it to be a number
|
|
168
|
+
return parseFloat(propValue);
|
|
169
|
+
}
|
|
170
|
+
if (propType & 1 /* MEMBER_FLAGS.String */) {
|
|
171
|
+
// could have been passed as a number or boolean
|
|
172
|
+
// but we still want it as a string
|
|
173
|
+
return String(propValue);
|
|
174
|
+
}
|
|
175
|
+
// redundant return here for better minification
|
|
176
|
+
return propValue;
|
|
177
|
+
}
|
|
178
|
+
// not sure exactly what type we want
|
|
179
|
+
// so no need to change to a different type
|
|
180
|
+
return propValue;
|
|
181
|
+
};
|
|
182
|
+
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
183
|
+
/**
|
|
184
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
185
|
+
* @param elm the target of the Event
|
|
186
|
+
* @param name the name to give the custom Event
|
|
187
|
+
* @param opts options for configuring a custom Event
|
|
188
|
+
* @returns the custom Event
|
|
189
|
+
*/
|
|
190
|
+
const emitEvent = (elm, name, opts) => {
|
|
191
|
+
const ev = plt.ce(name, opts);
|
|
192
|
+
elm.dispatchEvent(ev);
|
|
193
|
+
return ev;
|
|
194
|
+
};
|
|
195
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
196
|
+
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
197
|
+
let style = styles.get(scopeId);
|
|
198
|
+
if (supportsConstructableStylesheets && allowCS) {
|
|
199
|
+
style = (style || new CSSStyleSheet());
|
|
200
|
+
if (typeof style === 'string') {
|
|
201
|
+
style = cssText;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
style.replaceSync(cssText);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
style = cssText;
|
|
209
|
+
}
|
|
210
|
+
styles.set(scopeId, style);
|
|
211
|
+
};
|
|
212
|
+
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
213
|
+
let scopeId = getScopeId(cmpMeta);
|
|
214
|
+
const style = styles.get(scopeId);
|
|
215
|
+
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
216
|
+
// so the fallback is to always use the document for the root node in those cases
|
|
217
|
+
styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
|
|
218
|
+
if (style) {
|
|
219
|
+
if (typeof style === 'string') {
|
|
220
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
221
|
+
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
222
|
+
let styleElm;
|
|
223
|
+
if (!appliedStyles) {
|
|
224
|
+
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
225
|
+
}
|
|
226
|
+
if (!appliedStyles.has(scopeId)) {
|
|
227
|
+
{
|
|
228
|
+
{
|
|
229
|
+
styleElm = doc.createElement('style');
|
|
230
|
+
styleElm.innerHTML = style;
|
|
231
|
+
}
|
|
232
|
+
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
233
|
+
}
|
|
234
|
+
if (appliedStyles) {
|
|
235
|
+
appliedStyles.add(scopeId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
240
|
+
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return scopeId;
|
|
244
|
+
};
|
|
245
|
+
const attachStyles = (hostRef) => {
|
|
246
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
247
|
+
const elm = hostRef.$hostElement$;
|
|
248
|
+
const flags = cmpMeta.$flags$;
|
|
249
|
+
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
250
|
+
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
251
|
+
if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
|
|
252
|
+
// only required when we're NOT using native shadow dom (slot)
|
|
253
|
+
// or this browser doesn't support native shadow dom
|
|
254
|
+
// and this host element was NOT created with SSR
|
|
255
|
+
// let's pick out the inner content for slot projection
|
|
256
|
+
// create a node to represent where the original
|
|
257
|
+
// content was first placed, which is useful later on
|
|
258
|
+
// DOM WRITE!!
|
|
259
|
+
elm['s-sc'] = scopeId;
|
|
260
|
+
elm.classList.add(scopeId + '-h');
|
|
261
|
+
}
|
|
262
|
+
endAttachStyles();
|
|
263
|
+
};
|
|
264
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
218
265
|
/**
|
|
219
266
|
* Production setAccessor() function based on Preact by
|
|
220
267
|
* Jason Miller (@developit)
|
|
@@ -287,7 +334,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
287
334
|
}
|
|
288
335
|
}
|
|
289
336
|
}
|
|
290
|
-
else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
|
|
337
|
+
else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
|
|
291
338
|
newValue = newValue === true ? '' : newValue;
|
|
292
339
|
{
|
|
293
340
|
elm.setAttribute(memberName, newValue);
|
|
@@ -302,7 +349,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
302
349
|
// if the element passed in is a shadow root, which is a document fragment
|
|
303
350
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
304
351
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
305
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
352
|
+
const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
|
|
306
353
|
? newVnode.$elm$.host
|
|
307
354
|
: newVnode.$elm$;
|
|
308
355
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
@@ -320,6 +367,16 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
320
367
|
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
|
321
368
|
}
|
|
322
369
|
};
|
|
370
|
+
/**
|
|
371
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
372
|
+
*
|
|
373
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
374
|
+
* @param newParentVNode the parent VNode from the current render
|
|
375
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
376
|
+
* children, for which we will create a new DOM node
|
|
377
|
+
* @param parentElm the parent DOM node which our new node will be a child of
|
|
378
|
+
* @returns the newly created node
|
|
379
|
+
*/
|
|
323
380
|
const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
324
381
|
// tslint:disable-next-line: prefer-const
|
|
325
382
|
const newVNode = newParentVNode.$children$[childIndex];
|
|
@@ -377,6 +434,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
|
377
434
|
}
|
|
378
435
|
}
|
|
379
436
|
};
|
|
437
|
+
/**
|
|
438
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
439
|
+
* traversing the two collections of children, identifying nodes that are
|
|
440
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
441
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
442
|
+
*
|
|
443
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
444
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
445
|
+
* 'windows' by storing start and end indices and references to the
|
|
446
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
447
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
448
|
+
* no children left to update by doing the following:
|
|
449
|
+
*
|
|
450
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
451
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
452
|
+
* only with a window bounded by the highlighted elements:
|
|
453
|
+
*
|
|
454
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
455
|
+
* ^^^^^^ ^^^^^^
|
|
456
|
+
*
|
|
457
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
458
|
+
* across the windows. This will basically detect elements which haven't
|
|
459
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
460
|
+
* VNode elements (represented as HTML):
|
|
461
|
+
*
|
|
462
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
463
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
464
|
+
*
|
|
465
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
466
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
467
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
468
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
469
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
470
|
+
*
|
|
471
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
472
|
+
* window corresponds to the element at the end of the other window. This is
|
|
473
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
474
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
475
|
+
* children nodes themselves have not changed but merely moved in the
|
|
476
|
+
* following example:
|
|
477
|
+
*
|
|
478
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
479
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
480
|
+
*
|
|
481
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
482
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
483
|
+
* DOM.
|
|
484
|
+
*
|
|
485
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
486
|
+
* nodes in the old children which have the same key as the first element in
|
|
487
|
+
* our window on the new children. If we find such a node we handle calling
|
|
488
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
489
|
+
* what we find.
|
|
490
|
+
*
|
|
491
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
492
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
493
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
494
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
495
|
+
* children has collapsed we still have more nodes on the new children that
|
|
496
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
497
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
498
|
+
* sure the corresponding DOM nodes are removed.
|
|
499
|
+
*
|
|
500
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
501
|
+
* @param oldCh the old children of the parent node
|
|
502
|
+
* @param newVNode the new VNode which will replace the parent
|
|
503
|
+
* @param newCh the new children of the parent node
|
|
504
|
+
*/
|
|
380
505
|
const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
381
506
|
let oldStartIdx = 0;
|
|
382
507
|
let newStartIdx = 0;
|
|
@@ -389,7 +514,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
389
514
|
let node;
|
|
390
515
|
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
391
516
|
if (oldStartVnode == null) {
|
|
392
|
-
//
|
|
517
|
+
// VNode might have been moved left
|
|
393
518
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
394
519
|
}
|
|
395
520
|
else if (oldEndVnode == null) {
|
|
@@ -402,34 +527,67 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
402
527
|
newEndVnode = newCh[--newEndIdx];
|
|
403
528
|
}
|
|
404
529
|
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
530
|
+
// if the start nodes are the same then we should patch the new VNode
|
|
531
|
+
// onto the old one, and increment our `newStartIdx` and `oldStartIdx`
|
|
532
|
+
// indices to reflect that. We don't need to move any DOM Nodes around
|
|
533
|
+
// since things are matched up in order.
|
|
405
534
|
patch(oldStartVnode, newStartVnode);
|
|
406
535
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
407
536
|
newStartVnode = newCh[++newStartIdx];
|
|
408
537
|
}
|
|
409
538
|
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
539
|
+
// likewise, if the end nodes are the same we patch new onto old and
|
|
540
|
+
// decrement our end indices, and also likewise in this case we don't
|
|
541
|
+
// need to move any DOM Nodes.
|
|
410
542
|
patch(oldEndVnode, newEndVnode);
|
|
411
543
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
412
544
|
newEndVnode = newCh[--newEndIdx];
|
|
413
545
|
}
|
|
414
546
|
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
415
547
|
patch(oldStartVnode, newEndVnode);
|
|
548
|
+
// We need to move the element for `oldStartVnode` into a position which
|
|
549
|
+
// will be appropriate for `newEndVnode`. For this we can use
|
|
550
|
+
// `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
|
|
551
|
+
// sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
|
|
552
|
+
// `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
|
|
553
|
+
//
|
|
554
|
+
// <old-start-node />
|
|
555
|
+
// <some-intervening-node />
|
|
556
|
+
// <old-end-node />
|
|
557
|
+
// <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
|
|
558
|
+
// <next-sibling />
|
|
559
|
+
//
|
|
560
|
+
// If instead `oldEndVnode.$elm$` has no sibling then we just want to put
|
|
561
|
+
// the node for `oldStartVnode` at the end of the children of
|
|
562
|
+
// `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
|
|
563
|
+
// aren't any siblings, and passing `null` to `Node.insertBefore` will
|
|
564
|
+
// append it to the children of the parent element.
|
|
416
565
|
parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
417
566
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
418
567
|
newEndVnode = newCh[--newEndIdx];
|
|
419
568
|
}
|
|
420
569
|
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
421
570
|
patch(oldEndVnode, newStartVnode);
|
|
571
|
+
// We've already checked above if `oldStartVnode` and `newStartVnode` are
|
|
572
|
+
// the same node, so since we're here we know that they are not. Thus we
|
|
573
|
+
// can move the element for `oldEndVnode` _before_ the element for
|
|
574
|
+
// `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
|
|
575
|
+
// future.
|
|
422
576
|
parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
423
577
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
424
578
|
newStartVnode = newCh[++newStartIdx];
|
|
425
579
|
}
|
|
426
580
|
else {
|
|
427
581
|
{
|
|
428
|
-
//
|
|
582
|
+
// We either didn't find an element in the old children that matches
|
|
583
|
+
// the key of the first new child OR the build is not using `key`
|
|
584
|
+
// attributes at all. In either case we need to create a new element
|
|
585
|
+
// for the new node.
|
|
429
586
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
|
|
430
587
|
newStartVnode = newCh[++newStartIdx];
|
|
431
588
|
}
|
|
432
589
|
if (node) {
|
|
590
|
+
// if we created a new node then handle inserting it to the DOM
|
|
433
591
|
{
|
|
434
592
|
oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
|
|
435
593
|
}
|
|
@@ -437,26 +595,54 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
437
595
|
}
|
|
438
596
|
}
|
|
439
597
|
if (oldStartIdx > oldEndIdx) {
|
|
598
|
+
// we have some more new nodes to add which don't match up with old nodes
|
|
440
599
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
441
600
|
}
|
|
442
601
|
else if (newStartIdx > newEndIdx) {
|
|
602
|
+
// there are nodes in the `oldCh` array which no longer correspond to nodes
|
|
603
|
+
// in the new array, so lets remove them (which entails cleaning up the
|
|
604
|
+
// relevant DOM nodes)
|
|
443
605
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
444
606
|
}
|
|
445
607
|
};
|
|
446
|
-
|
|
608
|
+
/**
|
|
609
|
+
* Compare two VNodes to determine if they are the same
|
|
610
|
+
*
|
|
611
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
612
|
+
* information set on the two VNodes and can be misleading under certain
|
|
613
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
614
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
615
|
+
* checking that they have the same tag.
|
|
616
|
+
*
|
|
617
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
618
|
+
* changing order within a `children` array or something along those lines then
|
|
619
|
+
* we could obtain a false positive and then have to do needless re-rendering.
|
|
620
|
+
*
|
|
621
|
+
* @param leftVNode the first VNode to check
|
|
622
|
+
* @param rightVNode the second VNode to check
|
|
623
|
+
* @returns whether they're equal or not
|
|
624
|
+
*/
|
|
625
|
+
const isSameVnode = (leftVNode, rightVNode) => {
|
|
447
626
|
// compare if two vnode to see if they're "technically" the same
|
|
448
627
|
// need to have the same element tag, and same key to be the same
|
|
449
|
-
if (
|
|
628
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
450
629
|
return true;
|
|
451
630
|
}
|
|
452
631
|
return false;
|
|
453
632
|
};
|
|
633
|
+
/**
|
|
634
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
635
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
636
|
+
* children of the two nodes (if any).
|
|
637
|
+
*
|
|
638
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
639
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
640
|
+
*/
|
|
454
641
|
const patch = (oldVNode, newVNode) => {
|
|
455
642
|
const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
|
456
643
|
const oldChildren = oldVNode.$children$;
|
|
457
644
|
const newChildren = newVNode.$children$;
|
|
458
645
|
{
|
|
459
|
-
// element node
|
|
460
646
|
{
|
|
461
647
|
{
|
|
462
648
|
// either this is the first render of an element OR it's an update
|
|
@@ -467,6 +653,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
467
653
|
}
|
|
468
654
|
if (oldChildren !== null && newChildren !== null) {
|
|
469
655
|
// looks like there's child vnodes for both the old and new vnodes
|
|
656
|
+
// so we need to call `updateChildren` to reconcile them
|
|
470
657
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
471
658
|
}
|
|
472
659
|
else if (newChildren !== null) {
|
|
@@ -490,7 +677,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
490
677
|
cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
|
|
491
678
|
}
|
|
492
679
|
rootVnode.$tag$ = null;
|
|
493
|
-
rootVnode.$flags$ |= 4 /* isHost */;
|
|
680
|
+
rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
|
|
494
681
|
hostRef.$vnode$ = rootVnode;
|
|
495
682
|
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
|
496
683
|
{
|
|
@@ -499,18 +686,6 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
499
686
|
// synchronous patch
|
|
500
687
|
patch(oldVNode, rootVnode);
|
|
501
688
|
};
|
|
502
|
-
/**
|
|
503
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
504
|
-
* @param elm the target of the Event
|
|
505
|
-
* @param name the name to give the custom Event
|
|
506
|
-
* @param opts options for configuring a custom Event
|
|
507
|
-
* @returns the custom Event
|
|
508
|
-
*/
|
|
509
|
-
const emitEvent = (elm, name, opts) => {
|
|
510
|
-
const ev = plt.ce(name, opts);
|
|
511
|
-
elm.dispatchEvent(ev);
|
|
512
|
-
return ev;
|
|
513
|
-
};
|
|
514
689
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
515
690
|
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
516
691
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -518,10 +693,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
|
518
693
|
};
|
|
519
694
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
520
695
|
{
|
|
521
|
-
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
696
|
+
hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
522
697
|
}
|
|
523
|
-
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
524
|
-
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
698
|
+
if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
|
|
699
|
+
hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
|
|
525
700
|
return;
|
|
526
701
|
}
|
|
527
702
|
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
@@ -535,6 +710,11 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
|
535
710
|
const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
|
|
536
711
|
const instance = hostRef.$lazyInstance$ ;
|
|
537
712
|
let promise;
|
|
713
|
+
if (isInitialLoad) {
|
|
714
|
+
{
|
|
715
|
+
promise = safeCall(instance, 'componentWillLoad');
|
|
716
|
+
}
|
|
717
|
+
}
|
|
538
718
|
endSchedule();
|
|
539
719
|
return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
|
|
540
720
|
};
|
|
@@ -568,7 +748,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
568
748
|
}
|
|
569
749
|
else {
|
|
570
750
|
Promise.all(childrenPromises).then(postUpdate);
|
|
571
|
-
hostRef.$flags$ |= 4 /* isWaitingForChildren */;
|
|
751
|
+
hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
|
|
572
752
|
childrenPromises.length = 0;
|
|
573
753
|
}
|
|
574
754
|
}
|
|
@@ -577,10 +757,10 @@ const callRender = (hostRef, instance, elm) => {
|
|
|
577
757
|
try {
|
|
578
758
|
instance = instance.render() ;
|
|
579
759
|
{
|
|
580
|
-
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
760
|
+
hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
581
761
|
}
|
|
582
762
|
{
|
|
583
|
-
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
763
|
+
hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
|
|
584
764
|
}
|
|
585
765
|
{
|
|
586
766
|
{
|
|
@@ -603,8 +783,8 @@ const postUpdateComponent = (hostRef) => {
|
|
|
603
783
|
const elm = hostRef.$hostElement$;
|
|
604
784
|
const endPostUpdate = createTime('postUpdate', tagName);
|
|
605
785
|
const ancestorComponent = hostRef.$ancestorComponent$;
|
|
606
|
-
if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
|
|
607
|
-
hostRef.$flags$ |= 64 /* hasLoadedComponent */;
|
|
786
|
+
if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
|
|
787
|
+
hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
|
|
608
788
|
{
|
|
609
789
|
// DOM WRITE!
|
|
610
790
|
addHydratedFlag(elm);
|
|
@@ -627,10 +807,10 @@ const postUpdateComponent = (hostRef) => {
|
|
|
627
807
|
hostRef.$onRenderResolve$();
|
|
628
808
|
hostRef.$onRenderResolve$ = undefined;
|
|
629
809
|
}
|
|
630
|
-
if (hostRef.$flags$ & 512 /* needsRerender */) {
|
|
810
|
+
if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
|
|
631
811
|
nextTick(() => scheduleUpdate(hostRef, false));
|
|
632
812
|
}
|
|
633
|
-
hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
|
|
813
|
+
hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
|
|
634
814
|
}
|
|
635
815
|
// ( •_•)
|
|
636
816
|
// ( •_•)>⌐■-■
|
|
@@ -644,57 +824,27 @@ const appDidLoad = (who) => {
|
|
|
644
824
|
}
|
|
645
825
|
nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
|
|
646
826
|
};
|
|
827
|
+
const safeCall = (instance, method, arg) => {
|
|
828
|
+
if (instance && instance[method]) {
|
|
829
|
+
try {
|
|
830
|
+
return instance[method](arg);
|
|
831
|
+
}
|
|
832
|
+
catch (e) {
|
|
833
|
+
consoleError(e);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return undefined;
|
|
837
|
+
};
|
|
647
838
|
const then = (promise, thenFn) => {
|
|
648
839
|
return promise && promise.then ? promise.then(thenFn) : thenFn();
|
|
649
840
|
};
|
|
650
841
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
651
842
|
;
|
|
652
|
-
/**
|
|
653
|
-
* Parse a new property value for a given property type.
|
|
654
|
-
*
|
|
655
|
-
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
656
|
-
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
657
|
-
* 1. `any`, the type given to `propValue` in the function signature
|
|
658
|
-
* 2. the type stored from `propType`.
|
|
659
|
-
*
|
|
660
|
-
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
661
|
-
*
|
|
662
|
-
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
663
|
-
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
664
|
-
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
665
|
-
* ```tsx
|
|
666
|
-
* <my-cmp prop-val={0}></my-cmp>
|
|
667
|
-
* ```
|
|
668
|
-
*
|
|
669
|
-
* HTML prop values on the other hand, will always a string
|
|
670
|
-
*
|
|
671
|
-
* @param propValue the new value to coerce to some type
|
|
672
|
-
* @param propType the type of the prop, expressed as a binary number
|
|
673
|
-
* @returns the parsed/coerced value
|
|
674
|
-
*/
|
|
675
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
676
|
-
// ensure this value is of the correct prop type
|
|
677
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
678
|
-
if (propType & 2 /* Number */) {
|
|
679
|
-
// force it to be a number
|
|
680
|
-
return parseFloat(propValue);
|
|
681
|
-
}
|
|
682
|
-
if (propType & 1 /* String */) {
|
|
683
|
-
// could have been passed as a number or boolean
|
|
684
|
-
// but we still want it as a string
|
|
685
|
-
return String(propValue);
|
|
686
|
-
}
|
|
687
|
-
// redundant return here for better minification
|
|
688
|
-
return propValue;
|
|
689
|
-
}
|
|
690
|
-
// not sure exactly what type we want
|
|
691
|
-
// so no need to change to a different type
|
|
692
|
-
return propValue;
|
|
693
|
-
};
|
|
694
843
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
695
844
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
696
845
|
// check our new property value against our internal value
|
|
697
846
|
const hostRef = getHostRef(ref);
|
|
847
|
+
const elm = hostRef.$hostElement$ ;
|
|
698
848
|
const oldVal = hostRef.$instanceValues$.get(propName);
|
|
699
849
|
const flags = hostRef.$flags$;
|
|
700
850
|
const instance = hostRef.$lazyInstance$ ;
|
|
@@ -702,12 +852,28 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
702
852
|
// explicitly check for NaN on both sides, as `NaN === NaN` is always false
|
|
703
853
|
const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
|
|
704
854
|
const didValueChange = newVal !== oldVal && !areBothNaN;
|
|
705
|
-
if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
855
|
+
if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
706
856
|
// gadzooks! the property's value has changed!!
|
|
707
857
|
// set our new value!
|
|
708
858
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
709
859
|
if (instance) {
|
|
710
|
-
|
|
860
|
+
// get an array of method names of watch functions to call
|
|
861
|
+
if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
|
|
862
|
+
const watchMethods = cmpMeta.$watchers$[propName];
|
|
863
|
+
if (watchMethods) {
|
|
864
|
+
// this instance is watching for when this property changed
|
|
865
|
+
watchMethods.map((watchMethodName) => {
|
|
866
|
+
try {
|
|
867
|
+
// fire off each of the watch methods that are watching this property
|
|
868
|
+
instance[watchMethodName](newVal, oldVal, propName);
|
|
869
|
+
}
|
|
870
|
+
catch (e) {
|
|
871
|
+
consoleError(e, elm);
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
|
|
711
877
|
// looks like this value actually changed, so we've got work to do!
|
|
712
878
|
// but only if we've already rendered, otherwise just chill out
|
|
713
879
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -717,14 +883,27 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
717
883
|
}
|
|
718
884
|
}
|
|
719
885
|
};
|
|
886
|
+
/**
|
|
887
|
+
* Attach a series of runtime constructs to a compiled Stencil component
|
|
888
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
889
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
890
|
+
*
|
|
891
|
+
* @param Cstr the constructor for a component that we need to process
|
|
892
|
+
* @param cmpMeta metadata collected previously about the component
|
|
893
|
+
* @param flags a number used to store a series of bit flags
|
|
894
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
895
|
+
*/
|
|
720
896
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
721
897
|
if (cmpMeta.$members$) {
|
|
898
|
+
if (Cstr.watchers) {
|
|
899
|
+
cmpMeta.$watchers$ = Cstr.watchers;
|
|
900
|
+
}
|
|
722
901
|
// It's better to have a const than two Object.entries()
|
|
723
902
|
const members = Object.entries(cmpMeta.$members$);
|
|
724
903
|
const prototype = Cstr.prototype;
|
|
725
904
|
members.map(([memberName, [memberFlags]]) => {
|
|
726
|
-
if ((memberFlags & 31 /* Prop */ ||
|
|
727
|
-
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
905
|
+
if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
|
|
906
|
+
((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
|
|
728
907
|
// proxyComponent - prop
|
|
729
908
|
Object.defineProperty(prototype, memberName, {
|
|
730
909
|
get() {
|
|
@@ -740,7 +919,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
740
919
|
});
|
|
741
920
|
}
|
|
742
921
|
});
|
|
743
|
-
if ((flags & 1 /* isElementConstructor */)) {
|
|
922
|
+
if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
|
|
744
923
|
const attrNameToPropName = new Map();
|
|
745
924
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
746
925
|
plt.jmp(() => {
|
|
@@ -796,11 +975,11 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
796
975
|
// create an array of attributes to observe
|
|
797
976
|
// and also create a map of html attribute name to js property name
|
|
798
977
|
Cstr.observedAttributes = members
|
|
799
|
-
.filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
|
|
978
|
+
.filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
|
|
800
979
|
.map(([propName, m]) => {
|
|
801
980
|
const attrName = m[1] || propName;
|
|
802
981
|
attrNameToPropName.set(attrName, propName);
|
|
803
|
-
if (m[0] & 512 /* ReflectAttr */) {
|
|
982
|
+
if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
|
|
804
983
|
cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
|
805
984
|
}
|
|
806
985
|
return attrName;
|
|
@@ -811,10 +990,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
811
990
|
};
|
|
812
991
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
813
992
|
// initializeComponent
|
|
814
|
-
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
993
|
+
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
815
994
|
{
|
|
816
995
|
// we haven't initialized this element yet
|
|
817
|
-
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
996
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
818
997
|
// lazy loaded components
|
|
819
998
|
// request the component's implementation to be
|
|
820
999
|
// wired up with the host element
|
|
@@ -826,7 +1005,13 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
826
1005
|
endLoad();
|
|
827
1006
|
}
|
|
828
1007
|
if (!Cstr.isProxied) {
|
|
829
|
-
|
|
1008
|
+
// we've never proxied this Constructor before
|
|
1009
|
+
// let's add the getters/setters to its prototype before
|
|
1010
|
+
// the first time we create an instance of the implementation
|
|
1011
|
+
{
|
|
1012
|
+
cmpMeta.$watchers$ = Cstr.watchers;
|
|
1013
|
+
}
|
|
1014
|
+
proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
|
|
830
1015
|
Cstr.isProxied = true;
|
|
831
1016
|
}
|
|
832
1017
|
const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
|
@@ -834,7 +1019,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
834
1019
|
// but let's keep track of when we start and stop
|
|
835
1020
|
// so that the getters/setters don't incorrectly step on data
|
|
836
1021
|
{
|
|
837
|
-
hostRef.$flags$ |= 8 /* isConstructingInstance */;
|
|
1022
|
+
hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
|
|
838
1023
|
}
|
|
839
1024
|
// construct the lazy-loaded component implementation
|
|
840
1025
|
// passing the hostRef is very important during
|
|
@@ -847,7 +1032,10 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
847
1032
|
consoleError(e);
|
|
848
1033
|
}
|
|
849
1034
|
{
|
|
850
|
-
hostRef.$flags$ &= ~8 /* isConstructingInstance */;
|
|
1035
|
+
hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
|
|
1036
|
+
}
|
|
1037
|
+
{
|
|
1038
|
+
hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
|
|
851
1039
|
}
|
|
852
1040
|
endNewInstance();
|
|
853
1041
|
}
|
|
@@ -857,7 +1045,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
857
1045
|
const scopeId = getScopeId(cmpMeta);
|
|
858
1046
|
if (!styles.has(scopeId)) {
|
|
859
1047
|
const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
|
860
|
-
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
|
|
1048
|
+
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
|
|
861
1049
|
endRegisterStyles();
|
|
862
1050
|
}
|
|
863
1051
|
}
|
|
@@ -879,13 +1067,13 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
879
1067
|
}
|
|
880
1068
|
};
|
|
881
1069
|
const connectedCallback = (elm) => {
|
|
882
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1070
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
883
1071
|
const hostRef = getHostRef(elm);
|
|
884
1072
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
885
1073
|
const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
|
886
|
-
if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
|
|
1074
|
+
if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
|
|
887
1075
|
// first time this component has connected
|
|
888
|
-
hostRef.$flags$ |= 1 /* hasConnected */;
|
|
1076
|
+
hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
|
|
889
1077
|
{
|
|
890
1078
|
// find the first ancestor component (if there is one) and register
|
|
891
1079
|
// this component as one of the actively loading child components for its ancestor
|
|
@@ -905,7 +1093,7 @@ const connectedCallback = (elm) => {
|
|
|
905
1093
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
906
1094
|
if (cmpMeta.$members$) {
|
|
907
1095
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
908
|
-
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1096
|
+
if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
|
|
909
1097
|
const value = elm[memberName];
|
|
910
1098
|
delete elm[memberName];
|
|
911
1099
|
elm[memberName] = value;
|
|
@@ -920,7 +1108,7 @@ const connectedCallback = (elm) => {
|
|
|
920
1108
|
}
|
|
921
1109
|
};
|
|
922
1110
|
const disconnectedCallback = (elm) => {
|
|
923
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1111
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
924
1112
|
getHostRef(elm);
|
|
925
1113
|
}
|
|
926
1114
|
};
|
|
@@ -951,6 +1139,9 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
951
1139
|
{
|
|
952
1140
|
cmpMeta.$attrsToReflect$ = [];
|
|
953
1141
|
}
|
|
1142
|
+
{
|
|
1143
|
+
cmpMeta.$watchers$ = {};
|
|
1144
|
+
}
|
|
954
1145
|
const tagName = cmpMeta.$tagName$;
|
|
955
1146
|
const HostElement = class extends HTMLElement {
|
|
956
1147
|
// StencilLazyHost
|
|
@@ -959,7 +1150,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
959
1150
|
super(self);
|
|
960
1151
|
self = this;
|
|
961
1152
|
registerHost(self, cmpMeta);
|
|
962
|
-
if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
|
|
1153
|
+
if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
|
|
963
1154
|
// this component is using shadow dom
|
|
964
1155
|
// and this browser supports shadow dom
|
|
965
1156
|
// add the read-only property "shadowRoot" to the host element
|
|
@@ -994,7 +1185,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
994
1185
|
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
995
1186
|
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
996
1187
|
cmpTags.push(tagName);
|
|
997
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
1188
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
|
|
998
1189
|
}
|
|
999
1190
|
});
|
|
1000
1191
|
});
|
|
@@ -1016,7 +1207,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1016
1207
|
// Fallback appLoad event
|
|
1017
1208
|
endBootstrap();
|
|
1018
1209
|
};
|
|
1019
|
-
const hostRefs = new WeakMap();
|
|
1210
|
+
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
1020
1211
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
1021
1212
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
1022
1213
|
const registerHost = (elm, cmpMeta) => {
|
|
@@ -1057,14 +1248,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1057
1248
|
return importedModule[exportName];
|
|
1058
1249
|
}, consoleError);
|
|
1059
1250
|
};
|
|
1060
|
-
const styles = new Map();
|
|
1251
|
+
const styles = /*@__PURE__*/ new Map();
|
|
1252
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
1253
|
+
const doc = win.document || { head: {} };
|
|
1254
|
+
const plt = {
|
|
1255
|
+
$flags$: 0,
|
|
1256
|
+
$resourcesUrl$: '',
|
|
1257
|
+
jmp: (h) => h(),
|
|
1258
|
+
raf: (h) => requestAnimationFrame(h),
|
|
1259
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
1260
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
1261
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
1262
|
+
};
|
|
1263
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
1264
|
+
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
1265
|
+
try {
|
|
1266
|
+
new CSSStyleSheet();
|
|
1267
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
1268
|
+
}
|
|
1269
|
+
catch (e) { }
|
|
1270
|
+
return false;
|
|
1271
|
+
})()
|
|
1272
|
+
;
|
|
1061
1273
|
const queueDomReads = [];
|
|
1062
1274
|
const queueDomWrites = [];
|
|
1063
1275
|
const queueTask = (queue, write) => (cb) => {
|
|
1064
1276
|
queue.push(cb);
|
|
1065
1277
|
if (!queuePending) {
|
|
1066
1278
|
queuePending = true;
|
|
1067
|
-
if (write && plt.$flags$ & 4 /* queueSync */) {
|
|
1279
|
+
if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
|
|
1068
1280
|
nextTick(flush);
|
|
1069
1281
|
}
|
|
1070
1282
|
else {
|
|
@@ -1103,6 +1315,7 @@ const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
|
1103
1315
|
|
|
1104
1316
|
exports.Host = Host;
|
|
1105
1317
|
exports.bootstrapLazy = bootstrapLazy;
|
|
1318
|
+
exports.getElement = getElement;
|
|
1106
1319
|
exports.h = h;
|
|
1107
1320
|
exports.promiseResolve = promiseResolve;
|
|
1108
1321
|
exports.registerInstance = registerInstance;
|