@mgdis/mg-components 4.1.1 → 4.2.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/dist/cjs/{index-dd2c7f7b.js → index-94497267.js} +455 -317
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/cjs/{mg-badge_24.cjs.entry.js → mg-badge_23.cjs.entry.js} +219 -2181
- package/dist/cjs/mg-components.cjs.js +3 -26
- package/dist/cjs/mg-modal.cjs.entry.js +15 -2
- package/dist/cjs/mg-popover.cjs.entry.js +171 -0
- package/dist/cjs/popper-11d5f714.js +1801 -0
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +118 -99
- package/dist/collection/components/atoms/mg-button/mg-button.js +221 -220
- package/dist/collection/components/atoms/mg-character-left/mg-character-left.js +72 -69
- package/dist/collection/components/atoms/mg-icon/doc/mg-icon.stories.js +1 -2
- package/dist/collection/components/atoms/mg-icon/mg-icon.js +102 -92
- package/dist/collection/components/atoms/mg-input-title/mg-input-title.js +85 -67
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +64 -55
- package/dist/collection/components/atoms/mg-tooltip/doc/mg-tooltip.stories.js +3 -6
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +122 -106
- package/dist/collection/components/molecules/inputs/MgInput.js +10 -17
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +323 -318
- package/dist/collection/components/molecules/inputs/mg-input-date/doc/mg-input-date.stories.js +3 -2
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +356 -361
- package/dist/collection/components/molecules/inputs/mg-input-numeric/doc/mg-input-numeric.stories.js +1 -2
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +463 -457
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +347 -340
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +348 -343
- package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js +4 -3
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +406 -401
- package/dist/collection/components/molecules/inputs/mg-input-text/doc/mg-input-text.stories.js +12 -15
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +2 -0
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +476 -473
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +461 -456
- package/dist/collection/components/molecules/inputs/mg-input-toggle/doc/mg-input-toggle.stories.js +2 -8
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.css +1 -0
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +299 -298
- package/dist/collection/components/molecules/mg-details/doc/mg-details.stories.js +1 -3
- package/dist/collection/components/molecules/mg-details/mg-details.js +95 -93
- package/dist/collection/components/molecules/mg-form/doc/mg-form.stories.js +13 -27
- package/dist/collection/components/molecules/mg-form/mg-form.js +175 -166
- package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +2 -6
- package/dist/collection/components/molecules/mg-illustrated-message/mg-illustrated-message.js +37 -37
- package/dist/collection/components/molecules/mg-message/doc/mg-message.stories.js +1 -3
- package/dist/collection/components/molecules/mg-message/mg-message.js +154 -153
- package/dist/collection/components/molecules/mg-modal/doc/mg-modal.stories.js +11 -15
- package/dist/collection/components/molecules/mg-modal/mg-modal.css +2 -2
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +153 -134
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.css +5 -6
- package/dist/collection/components/molecules/mg-pagination/mg-pagination.js +112 -117
- package/dist/collection/components/molecules/mg-panel/doc/mg-panel.stories.js +1 -8
- package/dist/collection/components/molecules/mg-panel/mg-panel.css +2 -2
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +194 -189
- package/dist/collection/components/molecules/mg-popover/doc/mg-popover.stories.js +1 -4
- package/dist/collection/components/molecules/mg-popover/mg-popover.css +3 -5
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +129 -127
- package/dist/collection/components/molecules/mg-tabs/doc/mg-tabs.stories.js +1 -5
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.css +1 -0
- package/dist/collection/components/molecules/mg-tabs/mg-tabs.js +152 -135
- package/dist/collection/fonts/OpenSans-Bold.ttf +0 -0
- package/dist/collection/locales/en/messages.json +50 -0
- package/dist/collection/locales/fr/messages.json +50 -0
- package/dist/collection/stories/grids.stories.js +1 -44
- package/dist/collection/stories/helpers.stories.js +1 -19
- package/dist/collection/stories/icons.stories.js +1 -4
- package/dist/collection/stories/typography.stories.js +1 -12
- package/dist/collection/variables.css +3 -2
- package/dist/collection/variables.scss +3 -2
- package/dist/components/MgInput.js +8 -3
- package/dist/components/mg-badge2.js +9 -0
- package/dist/components/mg-button2.js +2 -7
- package/dist/components/mg-input-checkbox.js +1 -6
- package/dist/components/mg-input-date.js +10 -27
- package/dist/components/mg-input-numeric.js +2 -7
- package/dist/components/mg-input-password.js +1 -6
- package/dist/components/mg-input-radio.js +1 -6
- package/dist/components/mg-input-select2.js +1 -6
- package/dist/components/mg-input-text2.js +3 -8
- package/dist/components/mg-input-textarea.js +2 -7
- package/dist/components/mg-input-title2.js +11 -0
- package/dist/components/mg-input-toggle.js +2 -7
- package/dist/components/mg-modal.js +14 -1
- package/dist/components/mg-pagination.js +3 -3
- package/dist/components/mg-panel.js +10 -4
- package/dist/components/mg-popover.js +1 -1
- package/dist/components/mg-tabs.js +10 -1
- package/dist/components/mg-tooltip2.js +9 -0
- package/dist/components/popper.js +60 -49
- package/dist/esm/{index-f58b769f.js → index-aad0184c.js} +456 -317
- package/dist/esm/loader.js +3 -3
- package/dist/esm/{mg-badge_24.entry.js → mg-badge_23.entry.js} +220 -2181
- package/dist/esm/mg-components.js +3 -26
- package/dist/esm/mg-modal.entry.js +15 -2
- package/dist/esm/mg-popover.entry.js +167 -0
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm/popper-f860750c.js +1799 -0
- package/dist/mg-components/fonts/OpenSans-Bold.ttf +0 -0
- package/dist/mg-components/locales/en/messages.json +50 -0
- package/dist/mg-components/locales/fr/messages.json +50 -0
- package/dist/mg-components/mg-components.css +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/p-25452f60.entry.js +1 -0
- package/dist/mg-components/p-3899d5d2.js +2 -0
- package/dist/mg-components/p-a20fc541.entry.js +1 -0
- package/dist/mg-components/p-e08bc19a.entry.js +1 -0
- package/dist/mg-components/p-ec26fc38.js +1 -0
- package/dist/mg-components/variables.css +3 -2
- package/dist/mg-components/variables.scss +3 -2
- package/dist/types/components/atoms/mg-badge/mg-badge.d.ts +1 -0
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +0 -1
- package/dist/types/components/atoms/mg-input-title/mg-input-title.d.ts +1 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +1 -0
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +1 -10
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +0 -1
- package/dist/types/components/molecules/inputs/mg-input-toggle/mg-input-toggle.d.ts +0 -1
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +2 -0
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +1 -1
- package/dist/types/components/molecules/mg-tabs/mg-tabs.d.ts +1 -0
- package/dist/types/components.d.ts +29 -29
- package/dist/types/stencil-public-runtime.d.ts +15 -4
- package/loader/package.json +1 -0
- package/package.json +9 -9
- package/dist/collection/fonts/Poppins-Bold.ttf +0 -0
- package/dist/mg-components/fonts/Poppins-Bold.ttf +0 -0
- package/dist/mg-components/p-2a3d8f60.entry.js +0 -1
- package/dist/mg-components/p-b6df1cac.js +0 -2
- package/dist/mg-components/p-c8779533.entry.js +0 -1
|
@@ -22,6 +22,14 @@ function _interopNamespace(e) {
|
|
|
22
22
|
|
|
23
23
|
const NAMESPACE = 'mg-components';
|
|
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 contentRef;
|
|
27
35
|
let hostTagName;
|
|
@@ -30,65 +38,6 @@ let checkSlotFallbackVisibility = false;
|
|
|
30
38
|
let checkSlotRelocate = false;
|
|
31
39
|
let isSvgMode = false;
|
|
32
40
|
let queuePending = false;
|
|
33
|
-
const win = typeof window !== 'undefined' ? window : {};
|
|
34
|
-
const doc = win.document || { head: {} };
|
|
35
|
-
const H = (win.HTMLElement || class {
|
|
36
|
-
});
|
|
37
|
-
const plt = {
|
|
38
|
-
$flags$: 0,
|
|
39
|
-
$resourcesUrl$: '',
|
|
40
|
-
jmp: (h) => h(),
|
|
41
|
-
raf: (h) => requestAnimationFrame(h),
|
|
42
|
-
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
43
|
-
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
44
|
-
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
45
|
-
};
|
|
46
|
-
const supportsShadow = true;
|
|
47
|
-
const promiseResolve = (v) => Promise.resolve(v);
|
|
48
|
-
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
49
|
-
try {
|
|
50
|
-
new CSSStyleSheet();
|
|
51
|
-
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
52
|
-
}
|
|
53
|
-
catch (e) { }
|
|
54
|
-
return false;
|
|
55
|
-
})()
|
|
56
|
-
;
|
|
57
|
-
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
58
|
-
if (listeners) {
|
|
59
|
-
listeners.map(([flags, name, method]) => {
|
|
60
|
-
const target = getHostListenerTarget(elm, flags) ;
|
|
61
|
-
const handler = hostListenerProxy(hostRef, method);
|
|
62
|
-
const opts = hostListenerOpts(flags);
|
|
63
|
-
plt.ael(target, name, handler, opts);
|
|
64
|
-
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
69
|
-
try {
|
|
70
|
-
{
|
|
71
|
-
if (hostRef.$flags$ & 256 /* isListenReady */) {
|
|
72
|
-
// instance is ready, let's call it's member method for this event
|
|
73
|
-
hostRef.$lazyInstance$[methodName](ev);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
consoleError(e);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
const getHostListenerTarget = (elm, flags) => {
|
|
85
|
-
if (flags & 8 /* TargetWindow */)
|
|
86
|
-
return win;
|
|
87
|
-
return elm;
|
|
88
|
-
};
|
|
89
|
-
// prettier-ignore
|
|
90
|
-
const hostListenerOpts = (flags) => (flags & 2 /* Capture */) !== 0;
|
|
91
|
-
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
92
41
|
const createTime = (fnName, tagName = '') => {
|
|
93
42
|
{
|
|
94
43
|
return () => {
|
|
@@ -103,79 +52,7 @@ const uniqueTime = (key, measureText) => {
|
|
|
103
52
|
};
|
|
104
53
|
}
|
|
105
54
|
};
|
|
106
|
-
const
|
|
107
|
-
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
108
|
-
let style = styles.get(scopeId);
|
|
109
|
-
if (supportsConstructableStylesheets && allowCS) {
|
|
110
|
-
style = (style || new CSSStyleSheet());
|
|
111
|
-
if (typeof style === 'string') {
|
|
112
|
-
style = cssText;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
style.replaceSync(cssText);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
style = cssText;
|
|
120
|
-
}
|
|
121
|
-
styles.set(scopeId, style);
|
|
122
|
-
};
|
|
123
|
-
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
124
|
-
let scopeId = getScopeId(cmpMeta);
|
|
125
|
-
const style = styles.get(scopeId);
|
|
126
|
-
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
127
|
-
// so the fallback is to always use the document for the root node in those cases
|
|
128
|
-
styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
|
|
129
|
-
if (style) {
|
|
130
|
-
if (typeof style === 'string') {
|
|
131
|
-
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
132
|
-
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
133
|
-
let styleElm;
|
|
134
|
-
if (!appliedStyles) {
|
|
135
|
-
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
136
|
-
}
|
|
137
|
-
if (!appliedStyles.has(scopeId)) {
|
|
138
|
-
{
|
|
139
|
-
{
|
|
140
|
-
styleElm = doc.createElement('style');
|
|
141
|
-
styleElm.innerHTML = style;
|
|
142
|
-
}
|
|
143
|
-
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
144
|
-
}
|
|
145
|
-
if (appliedStyles) {
|
|
146
|
-
appliedStyles.add(scopeId);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
151
|
-
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return scopeId;
|
|
155
|
-
};
|
|
156
|
-
const attachStyles = (hostRef) => {
|
|
157
|
-
const cmpMeta = hostRef.$cmpMeta$;
|
|
158
|
-
const elm = hostRef.$hostElement$;
|
|
159
|
-
const flags = cmpMeta.$flags$;
|
|
160
|
-
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
161
|
-
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
162
|
-
if (flags & 10 /* needsScopedEncapsulation */) {
|
|
163
|
-
// only required when we're NOT using native shadow dom (slot)
|
|
164
|
-
// or this browser doesn't support native shadow dom
|
|
165
|
-
// and this host element was NOT created with SSR
|
|
166
|
-
// let's pick out the inner content for slot projection
|
|
167
|
-
// create a node to represent where the original
|
|
168
|
-
// content was first placed, which is useful later on
|
|
169
|
-
// DOM WRITE!!
|
|
170
|
-
elm['s-sc'] = scopeId;
|
|
171
|
-
elm.classList.add(scopeId + '-h');
|
|
172
|
-
if (flags & 2 /* scopedCssEncapsulation */) {
|
|
173
|
-
elm.classList.add(scopeId + '-s');
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
endAttachStyles();
|
|
177
|
-
};
|
|
178
|
-
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
55
|
+
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
179
56
|
/**
|
|
180
57
|
* Default style mode id
|
|
181
58
|
*/
|
|
@@ -313,6 +190,152 @@ const convertToPrivate = (node) => {
|
|
|
313
190
|
vnode.$name$ = node.vname;
|
|
314
191
|
return vnode;
|
|
315
192
|
};
|
|
193
|
+
/**
|
|
194
|
+
* Parse a new property value for a given property type.
|
|
195
|
+
*
|
|
196
|
+
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
197
|
+
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
198
|
+
* 1. `any`, the type given to `propValue` in the function signature
|
|
199
|
+
* 2. the type stored from `propType`.
|
|
200
|
+
*
|
|
201
|
+
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
202
|
+
*
|
|
203
|
+
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
204
|
+
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
205
|
+
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
206
|
+
* ```tsx
|
|
207
|
+
* <my-cmp prop-val={0}></my-cmp>
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* HTML prop values on the other hand, will always a string
|
|
211
|
+
*
|
|
212
|
+
* @param propValue the new value to coerce to some type
|
|
213
|
+
* @param propType the type of the prop, expressed as a binary number
|
|
214
|
+
* @returns the parsed/coerced value
|
|
215
|
+
*/
|
|
216
|
+
const parsePropertyValue = (propValue, propType) => {
|
|
217
|
+
// ensure this value is of the correct prop type
|
|
218
|
+
if (propValue != null && !isComplexType(propValue)) {
|
|
219
|
+
if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
220
|
+
// per the HTML spec, any string value means it is a boolean true value
|
|
221
|
+
// but we'll cheat here and say that the string "false" is the boolean false
|
|
222
|
+
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
223
|
+
}
|
|
224
|
+
if (propType & 2 /* MEMBER_FLAGS.Number */) {
|
|
225
|
+
// force it to be a number
|
|
226
|
+
return parseFloat(propValue);
|
|
227
|
+
}
|
|
228
|
+
if (propType & 1 /* MEMBER_FLAGS.String */) {
|
|
229
|
+
// could have been passed as a number or boolean
|
|
230
|
+
// but we still want it as a string
|
|
231
|
+
return String(propValue);
|
|
232
|
+
}
|
|
233
|
+
// redundant return here for better minification
|
|
234
|
+
return propValue;
|
|
235
|
+
}
|
|
236
|
+
// not sure exactly what type we want
|
|
237
|
+
// so no need to change to a different type
|
|
238
|
+
return propValue;
|
|
239
|
+
};
|
|
240
|
+
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
241
|
+
const createEvent = (ref, name, flags) => {
|
|
242
|
+
const elm = getElement(ref);
|
|
243
|
+
return {
|
|
244
|
+
emit: (detail) => {
|
|
245
|
+
return emitEvent(elm, name, {
|
|
246
|
+
bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
|
|
247
|
+
composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
|
|
248
|
+
cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
|
|
249
|
+
detail,
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
256
|
+
* @param elm the target of the Event
|
|
257
|
+
* @param name the name to give the custom Event
|
|
258
|
+
* @param opts options for configuring a custom Event
|
|
259
|
+
* @returns the custom Event
|
|
260
|
+
*/
|
|
261
|
+
const emitEvent = (elm, name, opts) => {
|
|
262
|
+
const ev = plt.ce(name, opts);
|
|
263
|
+
elm.dispatchEvent(ev);
|
|
264
|
+
return ev;
|
|
265
|
+
};
|
|
266
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
267
|
+
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
268
|
+
let style = styles.get(scopeId);
|
|
269
|
+
if (supportsConstructableStylesheets && allowCS) {
|
|
270
|
+
style = (style || new CSSStyleSheet());
|
|
271
|
+
if (typeof style === 'string') {
|
|
272
|
+
style = cssText;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
style.replaceSync(cssText);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
style = cssText;
|
|
280
|
+
}
|
|
281
|
+
styles.set(scopeId, style);
|
|
282
|
+
};
|
|
283
|
+
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
284
|
+
let scopeId = getScopeId(cmpMeta);
|
|
285
|
+
const style = styles.get(scopeId);
|
|
286
|
+
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
287
|
+
// so the fallback is to always use the document for the root node in those cases
|
|
288
|
+
styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
|
|
289
|
+
if (style) {
|
|
290
|
+
if (typeof style === 'string') {
|
|
291
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
292
|
+
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
293
|
+
let styleElm;
|
|
294
|
+
if (!appliedStyles) {
|
|
295
|
+
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
296
|
+
}
|
|
297
|
+
if (!appliedStyles.has(scopeId)) {
|
|
298
|
+
{
|
|
299
|
+
{
|
|
300
|
+
styleElm = doc.createElement('style');
|
|
301
|
+
styleElm.innerHTML = style;
|
|
302
|
+
}
|
|
303
|
+
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
304
|
+
}
|
|
305
|
+
if (appliedStyles) {
|
|
306
|
+
appliedStyles.add(scopeId);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
311
|
+
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return scopeId;
|
|
315
|
+
};
|
|
316
|
+
const attachStyles = (hostRef) => {
|
|
317
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
318
|
+
const elm = hostRef.$hostElement$;
|
|
319
|
+
const flags = cmpMeta.$flags$;
|
|
320
|
+
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
321
|
+
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
322
|
+
if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
|
|
323
|
+
// only required when we're NOT using native shadow dom (slot)
|
|
324
|
+
// or this browser doesn't support native shadow dom
|
|
325
|
+
// and this host element was NOT created with SSR
|
|
326
|
+
// let's pick out the inner content for slot projection
|
|
327
|
+
// create a node to represent where the original
|
|
328
|
+
// content was first placed, which is useful later on
|
|
329
|
+
// DOM WRITE!!
|
|
330
|
+
elm['s-sc'] = scopeId;
|
|
331
|
+
elm.classList.add(scopeId + '-h');
|
|
332
|
+
if (flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
|
|
333
|
+
elm.classList.add(scopeId + '-s');
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
endAttachStyles();
|
|
337
|
+
};
|
|
338
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
316
339
|
/**
|
|
317
340
|
* Production setAccessor() function based on Preact by
|
|
318
341
|
* Jason Miller (@developit)
|
|
@@ -430,7 +453,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
430
453
|
}
|
|
431
454
|
}
|
|
432
455
|
}
|
|
433
|
-
else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
|
|
456
|
+
else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
|
|
434
457
|
newValue = newValue === true ? '' : newValue;
|
|
435
458
|
{
|
|
436
459
|
elm.setAttribute(memberName, newValue);
|
|
@@ -445,7 +468,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
445
468
|
// if the element passed in is a shadow root, which is a document fragment
|
|
446
469
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
447
470
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
448
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
471
|
+
const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
|
|
449
472
|
? newVnode.$elm$.host
|
|
450
473
|
: newVnode.$elm$;
|
|
451
474
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
@@ -463,6 +486,16 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
463
486
|
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
|
464
487
|
}
|
|
465
488
|
};
|
|
489
|
+
/**
|
|
490
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
491
|
+
*
|
|
492
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
493
|
+
* @param newParentVNode the parent VNode from the current render
|
|
494
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
495
|
+
* children, for which we will create a new DOM node
|
|
496
|
+
* @param parentElm the parent DOM node which our new node will be a child of
|
|
497
|
+
* @returns the newly created node
|
|
498
|
+
*/
|
|
466
499
|
const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
467
500
|
// tslint:disable-next-line: prefer-const
|
|
468
501
|
const newVNode = newParentVNode.$children$[childIndex];
|
|
@@ -480,16 +513,16 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
480
513
|
}
|
|
481
514
|
newVNode.$flags$ |= newVNode.$children$
|
|
482
515
|
? // slot element has fallback content
|
|
483
|
-
2 /* isSlotFallback */
|
|
516
|
+
2 /* VNODE_FLAGS.isSlotFallback */
|
|
484
517
|
: // slot element does not have fallback content
|
|
485
|
-
1 /* isSlotReference */;
|
|
518
|
+
1 /* VNODE_FLAGS.isSlotReference */;
|
|
486
519
|
}
|
|
487
520
|
}
|
|
488
521
|
if (newVNode.$text$ !== null) {
|
|
489
522
|
// create text node
|
|
490
523
|
elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
|
|
491
524
|
}
|
|
492
|
-
else if (newVNode.$flags$ & 1 /* isSlotReference */) {
|
|
525
|
+
else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
|
|
493
526
|
// create a slot reference node
|
|
494
527
|
elm = newVNode.$elm$ =
|
|
495
528
|
doc.createTextNode('');
|
|
@@ -499,7 +532,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
499
532
|
isSvgMode = newVNode.$tag$ === 'svg';
|
|
500
533
|
}
|
|
501
534
|
// create element
|
|
502
|
-
elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$flags$ & 2 /* isSlotFallback */
|
|
535
|
+
elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
|
|
503
536
|
? 'slot-fb'
|
|
504
537
|
: newVNode.$tag$)
|
|
505
538
|
);
|
|
@@ -539,7 +572,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
539
572
|
}
|
|
540
573
|
{
|
|
541
574
|
elm['s-hn'] = hostTagName;
|
|
542
|
-
if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
|
|
575
|
+
if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
|
|
543
576
|
// remember the content reference comment
|
|
544
577
|
elm['s-sr'] = true;
|
|
545
578
|
// remember the content reference comment
|
|
@@ -558,7 +591,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
558
591
|
return elm;
|
|
559
592
|
};
|
|
560
593
|
const putBackInOriginalLocation = (parentElm, recursive) => {
|
|
561
|
-
plt.$flags$ |= 1 /* isTmpDisconnected */;
|
|
594
|
+
plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
562
595
|
const oldSlotChildNodes = parentElm.childNodes;
|
|
563
596
|
for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
|
|
564
597
|
const childNode = oldSlotChildNodes[i];
|
|
@@ -579,7 +612,7 @@ const putBackInOriginalLocation = (parentElm, recursive) => {
|
|
|
579
612
|
putBackInOriginalLocation(childNode, recursive);
|
|
580
613
|
}
|
|
581
614
|
}
|
|
582
|
-
plt.$flags$ &= ~1 /* isTmpDisconnected */;
|
|
615
|
+
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
583
616
|
};
|
|
584
617
|
const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
585
618
|
let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
|
|
@@ -621,6 +654,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
|
621
654
|
}
|
|
622
655
|
}
|
|
623
656
|
};
|
|
657
|
+
/**
|
|
658
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
659
|
+
* traversing the two collections of children, identifying nodes that are
|
|
660
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
661
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
662
|
+
*
|
|
663
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
664
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
665
|
+
* 'windows' by storing start and end indices and references to the
|
|
666
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
667
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
668
|
+
* no children left to update by doing the following:
|
|
669
|
+
*
|
|
670
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
671
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
672
|
+
* only with a window bounded by the highlighted elements:
|
|
673
|
+
*
|
|
674
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
675
|
+
* ^^^^^^ ^^^^^^
|
|
676
|
+
*
|
|
677
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
678
|
+
* across the windows. This will basically detect elements which haven't
|
|
679
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
680
|
+
* VNode elements (represented as HTML):
|
|
681
|
+
*
|
|
682
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
683
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
684
|
+
*
|
|
685
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
686
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
687
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
688
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
689
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
690
|
+
*
|
|
691
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
692
|
+
* window corresponds to the element at the end of the other window. This is
|
|
693
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
694
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
695
|
+
* children nodes themselves have not changed but merely moved in the
|
|
696
|
+
* following example:
|
|
697
|
+
*
|
|
698
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
699
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
700
|
+
*
|
|
701
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
702
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
703
|
+
* DOM.
|
|
704
|
+
*
|
|
705
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
706
|
+
* nodes in the old children which have the same key as the first element in
|
|
707
|
+
* our window on the new children. If we find such a node we handle calling
|
|
708
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
709
|
+
* what we find.
|
|
710
|
+
*
|
|
711
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
712
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
713
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
714
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
715
|
+
* children has collapsed we still have more nodes on the new children that
|
|
716
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
717
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
718
|
+
* sure the corresponding DOM nodes are removed.
|
|
719
|
+
*
|
|
720
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
721
|
+
* @param oldCh the old children of the parent node
|
|
722
|
+
* @param newVNode the new VNode which will replace the parent
|
|
723
|
+
* @param newCh the new children of the parent node
|
|
724
|
+
*/
|
|
624
725
|
const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
625
726
|
let oldStartIdx = 0;
|
|
626
727
|
let newStartIdx = 0;
|
|
@@ -633,7 +734,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
633
734
|
let node;
|
|
634
735
|
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
635
736
|
if (oldStartVnode == null) {
|
|
636
|
-
//
|
|
737
|
+
// VNode might have been moved left
|
|
637
738
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
638
739
|
}
|
|
639
740
|
else if (oldEndVnode == null) {
|
|
@@ -646,42 +747,102 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
646
747
|
newEndVnode = newCh[--newEndIdx];
|
|
647
748
|
}
|
|
648
749
|
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
750
|
+
// if the start nodes are the same then we should patch the new VNode
|
|
751
|
+
// onto the old one, and increment our `newStartIdx` and `oldStartIdx`
|
|
752
|
+
// indices to reflect that. We don't need to move any DOM Nodes around
|
|
753
|
+
// since things are matched up in order.
|
|
649
754
|
patch(oldStartVnode, newStartVnode);
|
|
650
755
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
651
756
|
newStartVnode = newCh[++newStartIdx];
|
|
652
757
|
}
|
|
653
758
|
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
759
|
+
// likewise, if the end nodes are the same we patch new onto old and
|
|
760
|
+
// decrement our end indices, and also likewise in this case we don't
|
|
761
|
+
// need to move any DOM Nodes.
|
|
654
762
|
patch(oldEndVnode, newEndVnode);
|
|
655
763
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
656
764
|
newEndVnode = newCh[--newEndIdx];
|
|
657
765
|
}
|
|
658
766
|
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
659
|
-
// Vnode moved right
|
|
767
|
+
// case: "Vnode moved right"
|
|
768
|
+
//
|
|
769
|
+
// We've found that the last node in our window on the new children is
|
|
770
|
+
// the same VNode as the _first_ node in our window on the old children
|
|
771
|
+
// we're dealing with now. Visually, this is the layout of these two
|
|
772
|
+
// nodes:
|
|
773
|
+
//
|
|
774
|
+
// newCh: [..., newStartVnode , ... , newEndVnode , ...]
|
|
775
|
+
// ^^^^^^^^^^^
|
|
776
|
+
// oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
|
|
777
|
+
// ^^^^^^^^^^^^^
|
|
778
|
+
//
|
|
779
|
+
// In this situation we need to patch `newEndVnode` onto `oldStartVnode`
|
|
780
|
+
// and move the DOM element for `oldStartVnode`.
|
|
660
781
|
if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
|
|
661
782
|
putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
|
|
662
783
|
}
|
|
663
784
|
patch(oldStartVnode, newEndVnode);
|
|
785
|
+
// We need to move the element for `oldStartVnode` into a position which
|
|
786
|
+
// will be appropriate for `newEndVnode`. For this we can use
|
|
787
|
+
// `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
|
|
788
|
+
// sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
|
|
789
|
+
// `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
|
|
790
|
+
//
|
|
791
|
+
// <old-start-node />
|
|
792
|
+
// <some-intervening-node />
|
|
793
|
+
// <old-end-node />
|
|
794
|
+
// <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
|
|
795
|
+
// <next-sibling />
|
|
796
|
+
//
|
|
797
|
+
// If instead `oldEndVnode.$elm$` has no sibling then we just want to put
|
|
798
|
+
// the node for `oldStartVnode` at the end of the children of
|
|
799
|
+
// `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
|
|
800
|
+
// aren't any siblings, and passing `null` to `Node.insertBefore` will
|
|
801
|
+
// append it to the children of the parent element.
|
|
664
802
|
parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
665
803
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
666
804
|
newEndVnode = newCh[--newEndIdx];
|
|
667
805
|
}
|
|
668
806
|
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
669
|
-
// Vnode moved left
|
|
807
|
+
// case: "Vnode moved left"
|
|
808
|
+
//
|
|
809
|
+
// We've found that the first node in our window on the new children is
|
|
810
|
+
// the same VNode as the _last_ node in our window on the old children.
|
|
811
|
+
// Visually, this is the layout of these two nodes:
|
|
812
|
+
//
|
|
813
|
+
// newCh: [..., newStartVnode , ... , newEndVnode , ...]
|
|
814
|
+
// ^^^^^^^^^^^^^
|
|
815
|
+
// oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
|
|
816
|
+
// ^^^^^^^^^^^
|
|
817
|
+
//
|
|
818
|
+
// In this situation we need to patch `newStartVnode` onto `oldEndVnode`
|
|
819
|
+
// (which will handle updating any changed attributes, reconciling their
|
|
820
|
+
// children etc) but we also need to move the DOM node to which
|
|
821
|
+
// `oldEndVnode` corresponds.
|
|
670
822
|
if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
|
|
671
823
|
putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
|
|
672
824
|
}
|
|
673
825
|
patch(oldEndVnode, newStartVnode);
|
|
826
|
+
// We've already checked above if `oldStartVnode` and `newStartVnode` are
|
|
827
|
+
// the same node, so since we're here we know that they are not. Thus we
|
|
828
|
+
// can move the element for `oldEndVnode` _before_ the element for
|
|
829
|
+
// `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
|
|
830
|
+
// future.
|
|
674
831
|
parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
675
832
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
676
833
|
newStartVnode = newCh[++newStartIdx];
|
|
677
834
|
}
|
|
678
835
|
else {
|
|
679
836
|
{
|
|
680
|
-
//
|
|
837
|
+
// We either didn't find an element in the old children that matches
|
|
838
|
+
// the key of the first new child OR the build is not using `key`
|
|
839
|
+
// attributes at all. In either case we need to create a new element
|
|
840
|
+
// for the new node.
|
|
681
841
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
|
|
682
842
|
newStartVnode = newCh[++newStartIdx];
|
|
683
843
|
}
|
|
684
844
|
if (node) {
|
|
845
|
+
// if we created a new node then handle inserting it to the DOM
|
|
685
846
|
{
|
|
686
847
|
parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
|
|
687
848
|
}
|
|
@@ -689,18 +850,39 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
689
850
|
}
|
|
690
851
|
}
|
|
691
852
|
if (oldStartIdx > oldEndIdx) {
|
|
853
|
+
// we have some more new nodes to add which don't match up with old nodes
|
|
692
854
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
693
855
|
}
|
|
694
856
|
else if (newStartIdx > newEndIdx) {
|
|
857
|
+
// there are nodes in the `oldCh` array which no longer correspond to nodes
|
|
858
|
+
// in the new array, so lets remove them (which entails cleaning up the
|
|
859
|
+
// relevant DOM nodes)
|
|
695
860
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
696
861
|
}
|
|
697
862
|
};
|
|
698
|
-
|
|
863
|
+
/**
|
|
864
|
+
* Compare two VNodes to determine if they are the same
|
|
865
|
+
*
|
|
866
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
867
|
+
* information set on the two VNodes and can be misleading under certain
|
|
868
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
869
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
870
|
+
* checking that they have the same tag.
|
|
871
|
+
*
|
|
872
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
873
|
+
* changing order within a `children` array or something along those lines then
|
|
874
|
+
* we could obtain a false positive and then have to do needless re-rendering.
|
|
875
|
+
*
|
|
876
|
+
* @param leftVNode the first VNode to check
|
|
877
|
+
* @param rightVNode the second VNode to check
|
|
878
|
+
* @returns whether they're equal or not
|
|
879
|
+
*/
|
|
880
|
+
const isSameVnode = (leftVNode, rightVNode) => {
|
|
699
881
|
// compare if two vnode to see if they're "technically" the same
|
|
700
882
|
// need to have the same element tag, and same key to be the same
|
|
701
|
-
if (
|
|
702
|
-
if (
|
|
703
|
-
return
|
|
883
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
884
|
+
if (leftVNode.$tag$ === 'slot') {
|
|
885
|
+
return leftVNode.$name$ === rightVNode.$name$;
|
|
704
886
|
}
|
|
705
887
|
return true;
|
|
706
888
|
}
|
|
@@ -714,6 +896,14 @@ const referenceNode = (node) => {
|
|
|
714
896
|
return (node && node['s-ol']) || node;
|
|
715
897
|
};
|
|
716
898
|
const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
|
|
899
|
+
/**
|
|
900
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
901
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
902
|
+
* children of the two nodes (if any).
|
|
903
|
+
*
|
|
904
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
905
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
906
|
+
*/
|
|
717
907
|
const patch = (oldVNode, newVNode) => {
|
|
718
908
|
const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
|
719
909
|
const oldChildren = oldVNode.$children$;
|
|
@@ -727,7 +917,6 @@ const patch = (oldVNode, newVNode) => {
|
|
|
727
917
|
// only add this to the when the compiler sees we're using an svg somewhere
|
|
728
918
|
isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
|
|
729
919
|
}
|
|
730
|
-
// element node
|
|
731
920
|
{
|
|
732
921
|
if (tag === 'slot')
|
|
733
922
|
;
|
|
@@ -740,6 +929,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
740
929
|
}
|
|
741
930
|
if (oldChildren !== null && newChildren !== null) {
|
|
742
931
|
// looks like there's child vnodes for both the old and new vnodes
|
|
932
|
+
// so we need to call `updateChildren` to reconcile them
|
|
743
933
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
744
934
|
}
|
|
745
935
|
else if (newChildren !== null) {
|
|
@@ -780,7 +970,7 @@ const updateFallbackSlotVisibility = (elm) => {
|
|
|
780
970
|
let nodeType;
|
|
781
971
|
for (i = 0, ilen = childNodes.length; i < ilen; i++) {
|
|
782
972
|
childNode = childNodes[i];
|
|
783
|
-
if (childNode.nodeType === 1 /* ElementNode */) {
|
|
973
|
+
if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
784
974
|
if (childNode['s-sr']) {
|
|
785
975
|
// this is a slot fallback node
|
|
786
976
|
// get the slot name for this slot reference node
|
|
@@ -792,7 +982,7 @@ const updateFallbackSlotVisibility = (elm) => {
|
|
|
792
982
|
nodeType = childNodes[j].nodeType;
|
|
793
983
|
if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
|
|
794
984
|
// this sibling node is from a different component OR is a named fallback slot node
|
|
795
|
-
if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
|
|
985
|
+
if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
|
|
796
986
|
childNode.hidden = true;
|
|
797
987
|
break;
|
|
798
988
|
}
|
|
@@ -801,8 +991,8 @@ const updateFallbackSlotVisibility = (elm) => {
|
|
|
801
991
|
// this is a default fallback slot node
|
|
802
992
|
// any element or text node (with content)
|
|
803
993
|
// should hide the default fallback slot node
|
|
804
|
-
if (nodeType === 1 /* ElementNode */ ||
|
|
805
|
-
(nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
|
|
994
|
+
if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
|
|
995
|
+
(nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
|
|
806
996
|
childNode.hidden = true;
|
|
807
997
|
break;
|
|
808
998
|
}
|
|
@@ -880,13 +1070,13 @@ const relocateSlotContent = (elm) => {
|
|
|
880
1070
|
}
|
|
881
1071
|
}
|
|
882
1072
|
}
|
|
883
|
-
if (childNode.nodeType === 1 /* ElementNode */) {
|
|
1073
|
+
if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
884
1074
|
relocateSlotContent(childNode);
|
|
885
1075
|
}
|
|
886
1076
|
}
|
|
887
1077
|
};
|
|
888
1078
|
const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
|
|
889
|
-
if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
|
|
1079
|
+
if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
890
1080
|
if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
|
|
891
1081
|
return true;
|
|
892
1082
|
}
|
|
@@ -917,7 +1107,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
917
1107
|
cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
|
|
918
1108
|
}
|
|
919
1109
|
rootVnode.$tag$ = null;
|
|
920
|
-
rootVnode.$flags$ |= 4 /* isHost */;
|
|
1110
|
+
rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
|
|
921
1111
|
hostRef.$vnode$ = rootVnode;
|
|
922
1112
|
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
|
923
1113
|
{
|
|
@@ -925,7 +1115,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
925
1115
|
}
|
|
926
1116
|
{
|
|
927
1117
|
contentRef = hostElm['s-cr'];
|
|
928
|
-
useNativeShadowDom = (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
|
|
1118
|
+
useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
|
|
929
1119
|
// always reset
|
|
930
1120
|
checkSlotFallbackVisibility = false;
|
|
931
1121
|
}
|
|
@@ -934,7 +1124,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
934
1124
|
{
|
|
935
1125
|
// while we're moving nodes around existing nodes, temporarily disable
|
|
936
1126
|
// the disconnectCallback from working
|
|
937
|
-
plt.$flags$ |= 1 /* isTmpDisconnected */;
|
|
1127
|
+
plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
938
1128
|
if (checkSlotRelocate) {
|
|
939
1129
|
relocateSlotContent(rootVnode.$elm$);
|
|
940
1130
|
let relocateData;
|
|
@@ -992,7 +1182,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
992
1182
|
}
|
|
993
1183
|
else {
|
|
994
1184
|
// this node doesn't have a slot home to go to, so let's hide it
|
|
995
|
-
if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
|
|
1185
|
+
if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
996
1186
|
nodeToRelocate.hidden = true;
|
|
997
1187
|
}
|
|
998
1188
|
}
|
|
@@ -1003,37 +1193,11 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
1003
1193
|
}
|
|
1004
1194
|
// done moving nodes around
|
|
1005
1195
|
// allow the disconnect callback to work again
|
|
1006
|
-
plt.$flags$ &= ~1 /* isTmpDisconnected */;
|
|
1196
|
+
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
1007
1197
|
// always reset
|
|
1008
1198
|
relocateNodes.length = 0;
|
|
1009
1199
|
}
|
|
1010
1200
|
};
|
|
1011
|
-
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
1012
|
-
const createEvent = (ref, name, flags) => {
|
|
1013
|
-
const elm = getElement(ref);
|
|
1014
|
-
return {
|
|
1015
|
-
emit: (detail) => {
|
|
1016
|
-
return emitEvent(elm, name, {
|
|
1017
|
-
bubbles: !!(flags & 4 /* Bubbles */),
|
|
1018
|
-
composed: !!(flags & 2 /* Composed */),
|
|
1019
|
-
cancelable: !!(flags & 1 /* Cancellable */),
|
|
1020
|
-
detail,
|
|
1021
|
-
});
|
|
1022
|
-
},
|
|
1023
|
-
};
|
|
1024
|
-
};
|
|
1025
|
-
/**
|
|
1026
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
1027
|
-
* @param elm the target of the Event
|
|
1028
|
-
* @param name the name to give the custom Event
|
|
1029
|
-
* @param opts options for configuring a custom Event
|
|
1030
|
-
* @returns the custom Event
|
|
1031
|
-
*/
|
|
1032
|
-
const emitEvent = (elm, name, opts) => {
|
|
1033
|
-
const ev = plt.ce(name, opts);
|
|
1034
|
-
elm.dispatchEvent(ev);
|
|
1035
|
-
return ev;
|
|
1036
|
-
};
|
|
1037
1201
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
1038
1202
|
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
1039
1203
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -1041,10 +1205,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
|
1041
1205
|
};
|
|
1042
1206
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
1043
1207
|
{
|
|
1044
|
-
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
1208
|
+
hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
1045
1209
|
}
|
|
1046
|
-
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
1047
|
-
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
1210
|
+
if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
|
|
1211
|
+
hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
|
|
1048
1212
|
return;
|
|
1049
1213
|
}
|
|
1050
1214
|
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
@@ -1060,7 +1224,7 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
|
1060
1224
|
let promise;
|
|
1061
1225
|
if (isInitialLoad) {
|
|
1062
1226
|
{
|
|
1063
|
-
hostRef.$flags$ |= 256 /* isListenReady */;
|
|
1227
|
+
hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
|
|
1064
1228
|
if (hostRef.$queuedListeners$) {
|
|
1065
1229
|
hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
|
|
1066
1230
|
hostRef.$queuedListeners$ = null;
|
|
@@ -1103,7 +1267,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
1103
1267
|
}
|
|
1104
1268
|
else {
|
|
1105
1269
|
Promise.all(childrenPromises).then(postUpdate);
|
|
1106
|
-
hostRef.$flags$ |= 4 /* isWaitingForChildren */;
|
|
1270
|
+
hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
|
|
1107
1271
|
childrenPromises.length = 0;
|
|
1108
1272
|
}
|
|
1109
1273
|
}
|
|
@@ -1112,10 +1276,10 @@ const callRender = (hostRef, instance, elm) => {
|
|
|
1112
1276
|
try {
|
|
1113
1277
|
instance = instance.render() ;
|
|
1114
1278
|
{
|
|
1115
|
-
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
1279
|
+
hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
1116
1280
|
}
|
|
1117
1281
|
{
|
|
1118
|
-
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
1282
|
+
hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
|
|
1119
1283
|
}
|
|
1120
1284
|
{
|
|
1121
1285
|
{
|
|
@@ -1142,8 +1306,8 @@ const postUpdateComponent = (hostRef) => {
|
|
|
1142
1306
|
{
|
|
1143
1307
|
safeCall(instance, 'componentDidRender');
|
|
1144
1308
|
}
|
|
1145
|
-
if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
|
|
1146
|
-
hostRef.$flags$ |= 64 /* hasLoadedComponent */;
|
|
1309
|
+
if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
|
|
1310
|
+
hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
|
|
1147
1311
|
{
|
|
1148
1312
|
// DOM WRITE!
|
|
1149
1313
|
addHydratedFlag(elm);
|
|
@@ -1172,10 +1336,10 @@ const postUpdateComponent = (hostRef) => {
|
|
|
1172
1336
|
hostRef.$onRenderResolve$();
|
|
1173
1337
|
hostRef.$onRenderResolve$ = undefined;
|
|
1174
1338
|
}
|
|
1175
|
-
if (hostRef.$flags$ & 512 /* needsRerender */) {
|
|
1339
|
+
if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
|
|
1176
1340
|
nextTick(() => scheduleUpdate(hostRef, false));
|
|
1177
1341
|
}
|
|
1178
|
-
hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
|
|
1342
|
+
hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
|
|
1179
1343
|
}
|
|
1180
1344
|
// ( •_•)
|
|
1181
1345
|
// ( •_•)>⌐■-■
|
|
@@ -1205,53 +1369,6 @@ const then = (promise, thenFn) => {
|
|
|
1205
1369
|
};
|
|
1206
1370
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
1207
1371
|
;
|
|
1208
|
-
/**
|
|
1209
|
-
* Parse a new property value for a given property type.
|
|
1210
|
-
*
|
|
1211
|
-
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
1212
|
-
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
1213
|
-
* 1. `any`, the type given to `propValue` in the function signature
|
|
1214
|
-
* 2. the type stored from `propType`.
|
|
1215
|
-
*
|
|
1216
|
-
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
1217
|
-
*
|
|
1218
|
-
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
1219
|
-
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
1220
|
-
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
1221
|
-
* ```tsx
|
|
1222
|
-
* <my-cmp prop-val={0}></my-cmp>
|
|
1223
|
-
* ```
|
|
1224
|
-
*
|
|
1225
|
-
* HTML prop values on the other hand, will always a string
|
|
1226
|
-
*
|
|
1227
|
-
* @param propValue the new value to coerce to some type
|
|
1228
|
-
* @param propType the type of the prop, expressed as a binary number
|
|
1229
|
-
* @returns the parsed/coerced value
|
|
1230
|
-
*/
|
|
1231
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
1232
|
-
// ensure this value is of the correct prop type
|
|
1233
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
1234
|
-
if (propType & 4 /* Boolean */) {
|
|
1235
|
-
// per the HTML spec, any string value means it is a boolean true value
|
|
1236
|
-
// but we'll cheat here and say that the string "false" is the boolean false
|
|
1237
|
-
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
1238
|
-
}
|
|
1239
|
-
if (propType & 2 /* Number */) {
|
|
1240
|
-
// force it to be a number
|
|
1241
|
-
return parseFloat(propValue);
|
|
1242
|
-
}
|
|
1243
|
-
if (propType & 1 /* String */) {
|
|
1244
|
-
// could have been passed as a number or boolean
|
|
1245
|
-
// but we still want it as a string
|
|
1246
|
-
return String(propValue);
|
|
1247
|
-
}
|
|
1248
|
-
// redundant return here for better minification
|
|
1249
|
-
return propValue;
|
|
1250
|
-
}
|
|
1251
|
-
// not sure exactly what type we want
|
|
1252
|
-
// so no need to change to a different type
|
|
1253
|
-
return propValue;
|
|
1254
|
-
};
|
|
1255
1372
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
1256
1373
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
1257
1374
|
// check our new property value against our internal value
|
|
@@ -1264,13 +1381,13 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
1264
1381
|
// explicitly check for NaN on both sides, as `NaN === NaN` is always false
|
|
1265
1382
|
const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
|
|
1266
1383
|
const didValueChange = newVal !== oldVal && !areBothNaN;
|
|
1267
|
-
if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
1384
|
+
if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
1268
1385
|
// gadzooks! the property's value has changed!!
|
|
1269
1386
|
// set our new value!
|
|
1270
1387
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
1271
1388
|
if (instance) {
|
|
1272
1389
|
// get an array of method names of watch functions to call
|
|
1273
|
-
if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
|
|
1390
|
+
if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
|
|
1274
1391
|
const watchMethods = cmpMeta.$watchers$[propName];
|
|
1275
1392
|
if (watchMethods) {
|
|
1276
1393
|
// this instance is watching for when this property changed
|
|
@@ -1285,7 +1402,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
1285
1402
|
});
|
|
1286
1403
|
}
|
|
1287
1404
|
}
|
|
1288
|
-
if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
|
|
1405
|
+
if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
|
|
1289
1406
|
// looks like this value actually changed, so we've got work to do!
|
|
1290
1407
|
// but only if we've already rendered, otherwise just chill out
|
|
1291
1408
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -1295,6 +1412,16 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
1295
1412
|
}
|
|
1296
1413
|
}
|
|
1297
1414
|
};
|
|
1415
|
+
/**
|
|
1416
|
+
* Attach a series of runtime constructs to a compiled Stencil component
|
|
1417
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
1418
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
1419
|
+
*
|
|
1420
|
+
* @param Cstr the constructor for a component that we need to process
|
|
1421
|
+
* @param cmpMeta metadata collected previously about the component
|
|
1422
|
+
* @param flags a number used to store a series of bit flags
|
|
1423
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
1424
|
+
*/
|
|
1298
1425
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
1299
1426
|
if (cmpMeta.$members$) {
|
|
1300
1427
|
if (Cstr.watchers) {
|
|
@@ -1304,8 +1431,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1304
1431
|
const members = Object.entries(cmpMeta.$members$);
|
|
1305
1432
|
const prototype = Cstr.prototype;
|
|
1306
1433
|
members.map(([memberName, [memberFlags]]) => {
|
|
1307
|
-
if ((memberFlags & 31 /* Prop */ ||
|
|
1308
|
-
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
1434
|
+
if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
|
|
1435
|
+
((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
|
|
1309
1436
|
// proxyComponent - prop
|
|
1310
1437
|
Object.defineProperty(prototype, memberName, {
|
|
1311
1438
|
get() {
|
|
@@ -1320,8 +1447,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1320
1447
|
enumerable: true,
|
|
1321
1448
|
});
|
|
1322
1449
|
}
|
|
1323
|
-
else if (flags & 1 /* isElementConstructor */ &&
|
|
1324
|
-
memberFlags & 64 /* Method */) {
|
|
1450
|
+
else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
|
|
1451
|
+
memberFlags & 64 /* MEMBER_FLAGS.Method */) {
|
|
1325
1452
|
// proxyComponent - method
|
|
1326
1453
|
Object.defineProperty(prototype, memberName, {
|
|
1327
1454
|
value(...args) {
|
|
@@ -1331,7 +1458,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1331
1458
|
});
|
|
1332
1459
|
}
|
|
1333
1460
|
});
|
|
1334
|
-
if ((flags & 1 /* isElementConstructor */)) {
|
|
1461
|
+
if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
|
|
1335
1462
|
const attrNameToPropName = new Map();
|
|
1336
1463
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
1337
1464
|
plt.jmp(() => {
|
|
@@ -1387,11 +1514,11 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1387
1514
|
// create an array of attributes to observe
|
|
1388
1515
|
// and also create a map of html attribute name to js property name
|
|
1389
1516
|
Cstr.observedAttributes = members
|
|
1390
|
-
.filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
|
|
1517
|
+
.filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
|
|
1391
1518
|
.map(([propName, m]) => {
|
|
1392
1519
|
const attrName = m[1] || propName;
|
|
1393
1520
|
attrNameToPropName.set(attrName, propName);
|
|
1394
|
-
if (m[0] & 512 /* ReflectAttr */) {
|
|
1521
|
+
if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
|
|
1395
1522
|
cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
|
1396
1523
|
}
|
|
1397
1524
|
return attrName;
|
|
@@ -1402,10 +1529,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1402
1529
|
};
|
|
1403
1530
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
1404
1531
|
// initializeComponent
|
|
1405
|
-
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
1532
|
+
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
1406
1533
|
{
|
|
1407
1534
|
// we haven't initialized this element yet
|
|
1408
|
-
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
1535
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
1409
1536
|
// lazy loaded components
|
|
1410
1537
|
// request the component's implementation to be
|
|
1411
1538
|
// wired up with the host element
|
|
@@ -1423,7 +1550,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1423
1550
|
{
|
|
1424
1551
|
cmpMeta.$watchers$ = Cstr.watchers;
|
|
1425
1552
|
}
|
|
1426
|
-
proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
|
|
1553
|
+
proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
|
|
1427
1554
|
Cstr.isProxied = true;
|
|
1428
1555
|
}
|
|
1429
1556
|
const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
|
@@ -1431,7 +1558,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1431
1558
|
// but let's keep track of when we start and stop
|
|
1432
1559
|
// so that the getters/setters don't incorrectly step on data
|
|
1433
1560
|
{
|
|
1434
|
-
hostRef.$flags$ |= 8 /* isConstructingInstance */;
|
|
1561
|
+
hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
|
|
1435
1562
|
}
|
|
1436
1563
|
// construct the lazy-loaded component implementation
|
|
1437
1564
|
// passing the hostRef is very important during
|
|
@@ -1444,10 +1571,10 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1444
1571
|
consoleError(e);
|
|
1445
1572
|
}
|
|
1446
1573
|
{
|
|
1447
|
-
hostRef.$flags$ &= ~8 /* isConstructingInstance */;
|
|
1574
|
+
hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
|
|
1448
1575
|
}
|
|
1449
1576
|
{
|
|
1450
|
-
hostRef.$flags$ |= 128 /* isWatchReady */;
|
|
1577
|
+
hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
|
|
1451
1578
|
}
|
|
1452
1579
|
endNewInstance();
|
|
1453
1580
|
}
|
|
@@ -1457,7 +1584,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1457
1584
|
const scopeId = getScopeId(cmpMeta);
|
|
1458
1585
|
if (!styles.has(scopeId)) {
|
|
1459
1586
|
const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
|
1460
|
-
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
|
|
1587
|
+
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
|
|
1461
1588
|
endRegisterStyles();
|
|
1462
1589
|
}
|
|
1463
1590
|
}
|
|
@@ -1479,19 +1606,19 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1479
1606
|
}
|
|
1480
1607
|
};
|
|
1481
1608
|
const connectedCallback = (elm) => {
|
|
1482
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1609
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
1483
1610
|
const hostRef = getHostRef(elm);
|
|
1484
1611
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
1485
1612
|
const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
|
1486
|
-
if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
|
|
1613
|
+
if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
|
|
1487
1614
|
// first time this component has connected
|
|
1488
|
-
hostRef.$flags$ |= 1 /* hasConnected */;
|
|
1615
|
+
hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
|
|
1489
1616
|
{
|
|
1490
1617
|
// initUpdate
|
|
1491
1618
|
// if the slot polyfill is required we'll need to put some nodes
|
|
1492
1619
|
// in here to act as original content anchors as we move nodes around
|
|
1493
1620
|
// host element has been connected to the DOM
|
|
1494
|
-
if ((cmpMeta.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
|
|
1621
|
+
if ((cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
|
|
1495
1622
|
setContentReference(elm);
|
|
1496
1623
|
}
|
|
1497
1624
|
}
|
|
@@ -1514,7 +1641,7 @@ const connectedCallback = (elm) => {
|
|
|
1514
1641
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
1515
1642
|
if (cmpMeta.$members$) {
|
|
1516
1643
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
1517
|
-
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1644
|
+
if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1518
1645
|
const value = elm[memberName];
|
|
1519
1646
|
delete elm[memberName];
|
|
1520
1647
|
elm[memberName] = value;
|
|
@@ -1546,7 +1673,7 @@ const setContentReference = (elm) => {
|
|
|
1546
1673
|
elm.insertBefore(contentRefElm, elm.firstChild);
|
|
1547
1674
|
};
|
|
1548
1675
|
const disconnectedCallback = (elm) => {
|
|
1549
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1676
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
1550
1677
|
const hostRef = getHostRef(elm);
|
|
1551
1678
|
{
|
|
1552
1679
|
if (hostRef.$rmListeners$) {
|
|
@@ -1556,46 +1683,6 @@ const disconnectedCallback = (elm) => {
|
|
|
1556
1683
|
}
|
|
1557
1684
|
}
|
|
1558
1685
|
};
|
|
1559
|
-
const patchCloneNode = (HostElementPrototype) => {
|
|
1560
|
-
const orgCloneNode = HostElementPrototype.cloneNode;
|
|
1561
|
-
HostElementPrototype.cloneNode = function (deep) {
|
|
1562
|
-
const srcNode = this;
|
|
1563
|
-
const isShadowDom = srcNode.shadowRoot && supportsShadow ;
|
|
1564
|
-
const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
|
|
1565
|
-
if (!isShadowDom && deep) {
|
|
1566
|
-
let i = 0;
|
|
1567
|
-
let slotted, nonStencilNode;
|
|
1568
|
-
const stencilPrivates = [
|
|
1569
|
-
's-id',
|
|
1570
|
-
's-cr',
|
|
1571
|
-
's-lr',
|
|
1572
|
-
's-rc',
|
|
1573
|
-
's-sc',
|
|
1574
|
-
's-p',
|
|
1575
|
-
's-cn',
|
|
1576
|
-
's-sr',
|
|
1577
|
-
's-sn',
|
|
1578
|
-
's-hn',
|
|
1579
|
-
's-ol',
|
|
1580
|
-
's-nr',
|
|
1581
|
-
's-si',
|
|
1582
|
-
];
|
|
1583
|
-
for (; i < srcNode.childNodes.length; i++) {
|
|
1584
|
-
slotted = srcNode.childNodes[i]['s-nr'];
|
|
1585
|
-
nonStencilNode = stencilPrivates.every((privateField) => !srcNode.childNodes[i][privateField]);
|
|
1586
|
-
if (slotted) {
|
|
1587
|
-
{
|
|
1588
|
-
clonedNode.appendChild(slotted.cloneNode(true));
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
if (nonStencilNode) {
|
|
1592
|
-
clonedNode.appendChild(srcNode.childNodes[i].cloneNode(true));
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
return clonedNode;
|
|
1597
|
-
};
|
|
1598
|
-
};
|
|
1599
1686
|
const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
1600
1687
|
const endBootstrap = createTime();
|
|
1601
1688
|
const cmpTags = [];
|
|
@@ -1637,7 +1724,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1637
1724
|
super(self);
|
|
1638
1725
|
self = this;
|
|
1639
1726
|
registerHost(self, cmpMeta);
|
|
1640
|
-
if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
|
|
1727
|
+
if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
|
|
1641
1728
|
// this component is using shadow dom
|
|
1642
1729
|
// and this browser supports shadow dom
|
|
1643
1730
|
// add the read-only property "shadowRoot" to the host element
|
|
@@ -1669,13 +1756,10 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1669
1756
|
return getHostRef(this).$onReadyPromise$;
|
|
1670
1757
|
}
|
|
1671
1758
|
};
|
|
1672
|
-
{
|
|
1673
|
-
patchCloneNode(HostElement.prototype);
|
|
1674
|
-
}
|
|
1675
1759
|
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
1676
1760
|
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
1677
1761
|
cmpTags.push(tagName);
|
|
1678
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
1762
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
|
|
1679
1763
|
}
|
|
1680
1764
|
});
|
|
1681
1765
|
});
|
|
@@ -1697,7 +1781,41 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1697
1781
|
// Fallback appLoad event
|
|
1698
1782
|
endBootstrap();
|
|
1699
1783
|
};
|
|
1700
|
-
const
|
|
1784
|
+
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
1785
|
+
if (listeners) {
|
|
1786
|
+
listeners.map(([flags, name, method]) => {
|
|
1787
|
+
const target = getHostListenerTarget(elm, flags) ;
|
|
1788
|
+
const handler = hostListenerProxy(hostRef, method);
|
|
1789
|
+
const opts = hostListenerOpts(flags);
|
|
1790
|
+
plt.ael(target, name, handler, opts);
|
|
1791
|
+
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
1796
|
+
try {
|
|
1797
|
+
{
|
|
1798
|
+
if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
|
|
1799
|
+
// instance is ready, let's call it's member method for this event
|
|
1800
|
+
hostRef.$lazyInstance$[methodName](ev);
|
|
1801
|
+
}
|
|
1802
|
+
else {
|
|
1803
|
+
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
catch (e) {
|
|
1808
|
+
consoleError(e);
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
const getHostListenerTarget = (elm, flags) => {
|
|
1812
|
+
if (flags & 8 /* LISTENER_FLAGS.TargetWindow */)
|
|
1813
|
+
return win;
|
|
1814
|
+
return elm;
|
|
1815
|
+
};
|
|
1816
|
+
// prettier-ignore
|
|
1817
|
+
const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
|
|
1818
|
+
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
1701
1819
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
1702
1820
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
1703
1821
|
const registerHost = (elm, cmpMeta) => {
|
|
@@ -1742,14 +1860,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1742
1860
|
return importedModule[exportName];
|
|
1743
1861
|
}, consoleError);
|
|
1744
1862
|
};
|
|
1745
|
-
const styles = new Map();
|
|
1863
|
+
const styles = /*@__PURE__*/ new Map();
|
|
1864
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
1865
|
+
const doc = win.document || { head: {} };
|
|
1866
|
+
const plt = {
|
|
1867
|
+
$flags$: 0,
|
|
1868
|
+
$resourcesUrl$: '',
|
|
1869
|
+
jmp: (h) => h(),
|
|
1870
|
+
raf: (h) => requestAnimationFrame(h),
|
|
1871
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
1872
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
1873
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
1874
|
+
};
|
|
1875
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
1876
|
+
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
1877
|
+
try {
|
|
1878
|
+
new CSSStyleSheet();
|
|
1879
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
1880
|
+
}
|
|
1881
|
+
catch (e) { }
|
|
1882
|
+
return false;
|
|
1883
|
+
})()
|
|
1884
|
+
;
|
|
1746
1885
|
const queueDomReads = [];
|
|
1747
1886
|
const queueDomWrites = [];
|
|
1748
1887
|
const queueTask = (queue, write) => (cb) => {
|
|
1749
1888
|
queue.push(cb);
|
|
1750
1889
|
if (!queuePending) {
|
|
1751
1890
|
queuePending = true;
|
|
1752
|
-
if (write && plt.$flags$ & 4 /* queueSync */) {
|
|
1891
|
+
if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
|
|
1753
1892
|
nextTick(flush);
|
|
1754
1893
|
}
|
|
1755
1894
|
else {
|
|
@@ -1786,7 +1925,6 @@ const flush = () => {
|
|
|
1786
1925
|
const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
|
|
1787
1926
|
const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
1788
1927
|
|
|
1789
|
-
exports.H = H;
|
|
1790
1928
|
exports.Host = Host;
|
|
1791
1929
|
exports.bootstrapLazy = bootstrapLazy;
|
|
1792
1930
|
exports.createEvent = createEvent;
|