@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
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
const NAMESPACE = 'mg-components';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
5
|
+
* Simon Friis Vindum (@paldepind)
|
|
6
|
+
* Licensed under the MIT License
|
|
7
|
+
* https://github.com/snabbdom/snabbdom/blob/master/LICENSE
|
|
8
|
+
*
|
|
9
|
+
* Modified for Stencil's renderer and slot projection
|
|
10
|
+
*/
|
|
3
11
|
let scopeId;
|
|
4
12
|
let contentRef;
|
|
5
13
|
let hostTagName;
|
|
@@ -8,65 +16,6 @@ let checkSlotFallbackVisibility = false;
|
|
|
8
16
|
let checkSlotRelocate = false;
|
|
9
17
|
let isSvgMode = false;
|
|
10
18
|
let queuePending = false;
|
|
11
|
-
const win = typeof window !== 'undefined' ? window : {};
|
|
12
|
-
const doc = win.document || { head: {} };
|
|
13
|
-
const H = (win.HTMLElement || class {
|
|
14
|
-
});
|
|
15
|
-
const plt = {
|
|
16
|
-
$flags$: 0,
|
|
17
|
-
$resourcesUrl$: '',
|
|
18
|
-
jmp: (h) => h(),
|
|
19
|
-
raf: (h) => requestAnimationFrame(h),
|
|
20
|
-
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
21
|
-
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
22
|
-
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
23
|
-
};
|
|
24
|
-
const supportsShadow = true;
|
|
25
|
-
const promiseResolve = (v) => Promise.resolve(v);
|
|
26
|
-
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
27
|
-
try {
|
|
28
|
-
new CSSStyleSheet();
|
|
29
|
-
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
30
|
-
}
|
|
31
|
-
catch (e) { }
|
|
32
|
-
return false;
|
|
33
|
-
})()
|
|
34
|
-
;
|
|
35
|
-
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
36
|
-
if (listeners) {
|
|
37
|
-
listeners.map(([flags, name, method]) => {
|
|
38
|
-
const target = getHostListenerTarget(elm, flags) ;
|
|
39
|
-
const handler = hostListenerProxy(hostRef, method);
|
|
40
|
-
const opts = hostListenerOpts(flags);
|
|
41
|
-
plt.ael(target, name, handler, opts);
|
|
42
|
-
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
47
|
-
try {
|
|
48
|
-
{
|
|
49
|
-
if (hostRef.$flags$ & 256 /* isListenReady */) {
|
|
50
|
-
// instance is ready, let's call it's member method for this event
|
|
51
|
-
hostRef.$lazyInstance$[methodName](ev);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch (e) {
|
|
59
|
-
consoleError(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const getHostListenerTarget = (elm, flags) => {
|
|
63
|
-
if (flags & 8 /* TargetWindow */)
|
|
64
|
-
return win;
|
|
65
|
-
return elm;
|
|
66
|
-
};
|
|
67
|
-
// prettier-ignore
|
|
68
|
-
const hostListenerOpts = (flags) => (flags & 2 /* Capture */) !== 0;
|
|
69
|
-
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
70
19
|
const createTime = (fnName, tagName = '') => {
|
|
71
20
|
{
|
|
72
21
|
return () => {
|
|
@@ -81,79 +30,7 @@ const uniqueTime = (key, measureText) => {
|
|
|
81
30
|
};
|
|
82
31
|
}
|
|
83
32
|
};
|
|
84
|
-
const
|
|
85
|
-
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
86
|
-
let style = styles.get(scopeId);
|
|
87
|
-
if (supportsConstructableStylesheets && allowCS) {
|
|
88
|
-
style = (style || new CSSStyleSheet());
|
|
89
|
-
if (typeof style === 'string') {
|
|
90
|
-
style = cssText;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
style.replaceSync(cssText);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
style = cssText;
|
|
98
|
-
}
|
|
99
|
-
styles.set(scopeId, style);
|
|
100
|
-
};
|
|
101
|
-
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
102
|
-
let scopeId = getScopeId(cmpMeta);
|
|
103
|
-
const style = styles.get(scopeId);
|
|
104
|
-
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
105
|
-
// so the fallback is to always use the document for the root node in those cases
|
|
106
|
-
styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
|
|
107
|
-
if (style) {
|
|
108
|
-
if (typeof style === 'string') {
|
|
109
|
-
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
110
|
-
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
111
|
-
let styleElm;
|
|
112
|
-
if (!appliedStyles) {
|
|
113
|
-
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
114
|
-
}
|
|
115
|
-
if (!appliedStyles.has(scopeId)) {
|
|
116
|
-
{
|
|
117
|
-
{
|
|
118
|
-
styleElm = doc.createElement('style');
|
|
119
|
-
styleElm.innerHTML = style;
|
|
120
|
-
}
|
|
121
|
-
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
122
|
-
}
|
|
123
|
-
if (appliedStyles) {
|
|
124
|
-
appliedStyles.add(scopeId);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
129
|
-
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return scopeId;
|
|
133
|
-
};
|
|
134
|
-
const attachStyles = (hostRef) => {
|
|
135
|
-
const cmpMeta = hostRef.$cmpMeta$;
|
|
136
|
-
const elm = hostRef.$hostElement$;
|
|
137
|
-
const flags = cmpMeta.$flags$;
|
|
138
|
-
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
139
|
-
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
140
|
-
if (flags & 10 /* needsScopedEncapsulation */) {
|
|
141
|
-
// only required when we're NOT using native shadow dom (slot)
|
|
142
|
-
// or this browser doesn't support native shadow dom
|
|
143
|
-
// and this host element was NOT created with SSR
|
|
144
|
-
// let's pick out the inner content for slot projection
|
|
145
|
-
// create a node to represent where the original
|
|
146
|
-
// content was first placed, which is useful later on
|
|
147
|
-
// DOM WRITE!!
|
|
148
|
-
elm['s-sc'] = scopeId;
|
|
149
|
-
elm.classList.add(scopeId + '-h');
|
|
150
|
-
if (flags & 2 /* scopedCssEncapsulation */) {
|
|
151
|
-
elm.classList.add(scopeId + '-s');
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
endAttachStyles();
|
|
155
|
-
};
|
|
156
|
-
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
33
|
+
const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
|
|
157
34
|
/**
|
|
158
35
|
* Default style mode id
|
|
159
36
|
*/
|
|
@@ -291,6 +168,152 @@ const convertToPrivate = (node) => {
|
|
|
291
168
|
vnode.$name$ = node.vname;
|
|
292
169
|
return vnode;
|
|
293
170
|
};
|
|
171
|
+
/**
|
|
172
|
+
* Parse a new property value for a given property type.
|
|
173
|
+
*
|
|
174
|
+
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
175
|
+
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
176
|
+
* 1. `any`, the type given to `propValue` in the function signature
|
|
177
|
+
* 2. the type stored from `propType`.
|
|
178
|
+
*
|
|
179
|
+
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
180
|
+
*
|
|
181
|
+
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
182
|
+
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
183
|
+
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
184
|
+
* ```tsx
|
|
185
|
+
* <my-cmp prop-val={0}></my-cmp>
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* HTML prop values on the other hand, will always a string
|
|
189
|
+
*
|
|
190
|
+
* @param propValue the new value to coerce to some type
|
|
191
|
+
* @param propType the type of the prop, expressed as a binary number
|
|
192
|
+
* @returns the parsed/coerced value
|
|
193
|
+
*/
|
|
194
|
+
const parsePropertyValue = (propValue, propType) => {
|
|
195
|
+
// ensure this value is of the correct prop type
|
|
196
|
+
if (propValue != null && !isComplexType(propValue)) {
|
|
197
|
+
if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
|
|
198
|
+
// per the HTML spec, any string value means it is a boolean true value
|
|
199
|
+
// but we'll cheat here and say that the string "false" is the boolean false
|
|
200
|
+
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
201
|
+
}
|
|
202
|
+
if (propType & 2 /* MEMBER_FLAGS.Number */) {
|
|
203
|
+
// force it to be a number
|
|
204
|
+
return parseFloat(propValue);
|
|
205
|
+
}
|
|
206
|
+
if (propType & 1 /* MEMBER_FLAGS.String */) {
|
|
207
|
+
// could have been passed as a number or boolean
|
|
208
|
+
// but we still want it as a string
|
|
209
|
+
return String(propValue);
|
|
210
|
+
}
|
|
211
|
+
// redundant return here for better minification
|
|
212
|
+
return propValue;
|
|
213
|
+
}
|
|
214
|
+
// not sure exactly what type we want
|
|
215
|
+
// so no need to change to a different type
|
|
216
|
+
return propValue;
|
|
217
|
+
};
|
|
218
|
+
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
219
|
+
const createEvent = (ref, name, flags) => {
|
|
220
|
+
const elm = getElement(ref);
|
|
221
|
+
return {
|
|
222
|
+
emit: (detail) => {
|
|
223
|
+
return emitEvent(elm, name, {
|
|
224
|
+
bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
|
|
225
|
+
composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
|
|
226
|
+
cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
|
|
227
|
+
detail,
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Helper function to create & dispatch a custom Event on a provided target
|
|
234
|
+
* @param elm the target of the Event
|
|
235
|
+
* @param name the name to give the custom Event
|
|
236
|
+
* @param opts options for configuring a custom Event
|
|
237
|
+
* @returns the custom Event
|
|
238
|
+
*/
|
|
239
|
+
const emitEvent = (elm, name, opts) => {
|
|
240
|
+
const ev = plt.ce(name, opts);
|
|
241
|
+
elm.dispatchEvent(ev);
|
|
242
|
+
return ev;
|
|
243
|
+
};
|
|
244
|
+
const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
|
|
245
|
+
const registerStyle = (scopeId, cssText, allowCS) => {
|
|
246
|
+
let style = styles.get(scopeId);
|
|
247
|
+
if (supportsConstructableStylesheets && allowCS) {
|
|
248
|
+
style = (style || new CSSStyleSheet());
|
|
249
|
+
if (typeof style === 'string') {
|
|
250
|
+
style = cssText;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
style.replaceSync(cssText);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
style = cssText;
|
|
258
|
+
}
|
|
259
|
+
styles.set(scopeId, style);
|
|
260
|
+
};
|
|
261
|
+
const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
|
|
262
|
+
let scopeId = getScopeId(cmpMeta);
|
|
263
|
+
const style = styles.get(scopeId);
|
|
264
|
+
// if an element is NOT connected then getRootNode() will return the wrong root node
|
|
265
|
+
// so the fallback is to always use the document for the root node in those cases
|
|
266
|
+
styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
|
|
267
|
+
if (style) {
|
|
268
|
+
if (typeof style === 'string') {
|
|
269
|
+
styleContainerNode = styleContainerNode.head || styleContainerNode;
|
|
270
|
+
let appliedStyles = rootAppliedStyles.get(styleContainerNode);
|
|
271
|
+
let styleElm;
|
|
272
|
+
if (!appliedStyles) {
|
|
273
|
+
rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
|
|
274
|
+
}
|
|
275
|
+
if (!appliedStyles.has(scopeId)) {
|
|
276
|
+
{
|
|
277
|
+
{
|
|
278
|
+
styleElm = doc.createElement('style');
|
|
279
|
+
styleElm.innerHTML = style;
|
|
280
|
+
}
|
|
281
|
+
styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
|
|
282
|
+
}
|
|
283
|
+
if (appliedStyles) {
|
|
284
|
+
appliedStyles.add(scopeId);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
|
|
289
|
+
styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return scopeId;
|
|
293
|
+
};
|
|
294
|
+
const attachStyles = (hostRef) => {
|
|
295
|
+
const cmpMeta = hostRef.$cmpMeta$;
|
|
296
|
+
const elm = hostRef.$hostElement$;
|
|
297
|
+
const flags = cmpMeta.$flags$;
|
|
298
|
+
const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
|
|
299
|
+
const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
|
|
300
|
+
if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
|
|
301
|
+
// only required when we're NOT using native shadow dom (slot)
|
|
302
|
+
// or this browser doesn't support native shadow dom
|
|
303
|
+
// and this host element was NOT created with SSR
|
|
304
|
+
// let's pick out the inner content for slot projection
|
|
305
|
+
// create a node to represent where the original
|
|
306
|
+
// content was first placed, which is useful later on
|
|
307
|
+
// DOM WRITE!!
|
|
308
|
+
elm['s-sc'] = scopeId;
|
|
309
|
+
elm.classList.add(scopeId + '-h');
|
|
310
|
+
if (flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
|
|
311
|
+
elm.classList.add(scopeId + '-s');
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
endAttachStyles();
|
|
315
|
+
};
|
|
316
|
+
const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
|
|
294
317
|
/**
|
|
295
318
|
* Production setAccessor() function based on Preact by
|
|
296
319
|
* Jason Miller (@developit)
|
|
@@ -408,7 +431,7 @@ const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
|
|
|
408
431
|
}
|
|
409
432
|
}
|
|
410
433
|
}
|
|
411
|
-
else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
|
|
434
|
+
else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
|
|
412
435
|
newValue = newValue === true ? '' : newValue;
|
|
413
436
|
{
|
|
414
437
|
elm.setAttribute(memberName, newValue);
|
|
@@ -423,7 +446,7 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
423
446
|
// if the element passed in is a shadow root, which is a document fragment
|
|
424
447
|
// then we want to be adding attrs/props to the shadow root's "host" element
|
|
425
448
|
// if it's not a shadow root, then we add attrs/props to the same element
|
|
426
|
-
const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
|
|
449
|
+
const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
|
|
427
450
|
? newVnode.$elm$.host
|
|
428
451
|
: newVnode.$elm$;
|
|
429
452
|
const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
|
|
@@ -441,6 +464,16 @@ const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
|
|
|
441
464
|
setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
|
|
442
465
|
}
|
|
443
466
|
};
|
|
467
|
+
/**
|
|
468
|
+
* Create a DOM Node corresponding to one of the children of a given VNode.
|
|
469
|
+
*
|
|
470
|
+
* @param oldParentVNode the parent VNode from the previous render
|
|
471
|
+
* @param newParentVNode the parent VNode from the current render
|
|
472
|
+
* @param childIndex the index of the VNode, in the _new_ parent node's
|
|
473
|
+
* children, for which we will create a new DOM node
|
|
474
|
+
* @param parentElm the parent DOM node which our new node will be a child of
|
|
475
|
+
* @returns the newly created node
|
|
476
|
+
*/
|
|
444
477
|
const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
445
478
|
// tslint:disable-next-line: prefer-const
|
|
446
479
|
const newVNode = newParentVNode.$children$[childIndex];
|
|
@@ -458,16 +491,16 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
458
491
|
}
|
|
459
492
|
newVNode.$flags$ |= newVNode.$children$
|
|
460
493
|
? // slot element has fallback content
|
|
461
|
-
2 /* isSlotFallback */
|
|
494
|
+
2 /* VNODE_FLAGS.isSlotFallback */
|
|
462
495
|
: // slot element does not have fallback content
|
|
463
|
-
1 /* isSlotReference */;
|
|
496
|
+
1 /* VNODE_FLAGS.isSlotReference */;
|
|
464
497
|
}
|
|
465
498
|
}
|
|
466
499
|
if (newVNode.$text$ !== null) {
|
|
467
500
|
// create text node
|
|
468
501
|
elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
|
|
469
502
|
}
|
|
470
|
-
else if (newVNode.$flags$ & 1 /* isSlotReference */) {
|
|
503
|
+
else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
|
|
471
504
|
// create a slot reference node
|
|
472
505
|
elm = newVNode.$elm$ =
|
|
473
506
|
doc.createTextNode('');
|
|
@@ -477,7 +510,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
477
510
|
isSvgMode = newVNode.$tag$ === 'svg';
|
|
478
511
|
}
|
|
479
512
|
// create element
|
|
480
|
-
elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$flags$ & 2 /* isSlotFallback */
|
|
513
|
+
elm = newVNode.$elm$ = (doc.createElementNS(isSvgMode ? SVG_NS : HTML_NS, newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
|
|
481
514
|
? 'slot-fb'
|
|
482
515
|
: newVNode.$tag$)
|
|
483
516
|
);
|
|
@@ -517,7 +550,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
517
550
|
}
|
|
518
551
|
{
|
|
519
552
|
elm['s-hn'] = hostTagName;
|
|
520
|
-
if (newVNode.$flags$ & (2 /* isSlotFallback */ | 1 /* isSlotReference */)) {
|
|
553
|
+
if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
|
|
521
554
|
// remember the content reference comment
|
|
522
555
|
elm['s-sr'] = true;
|
|
523
556
|
// remember the content reference comment
|
|
@@ -536,7 +569,7 @@ const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
|
|
|
536
569
|
return elm;
|
|
537
570
|
};
|
|
538
571
|
const putBackInOriginalLocation = (parentElm, recursive) => {
|
|
539
|
-
plt.$flags$ |= 1 /* isTmpDisconnected */;
|
|
572
|
+
plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
540
573
|
const oldSlotChildNodes = parentElm.childNodes;
|
|
541
574
|
for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
|
|
542
575
|
const childNode = oldSlotChildNodes[i];
|
|
@@ -557,7 +590,7 @@ const putBackInOriginalLocation = (parentElm, recursive) => {
|
|
|
557
590
|
putBackInOriginalLocation(childNode, recursive);
|
|
558
591
|
}
|
|
559
592
|
}
|
|
560
|
-
plt.$flags$ &= ~1 /* isTmpDisconnected */;
|
|
593
|
+
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
561
594
|
};
|
|
562
595
|
const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
|
|
563
596
|
let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
|
|
@@ -599,6 +632,74 @@ const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
|
|
|
599
632
|
}
|
|
600
633
|
}
|
|
601
634
|
};
|
|
635
|
+
/**
|
|
636
|
+
* Reconcile the children of a new VNode with the children of an old VNode by
|
|
637
|
+
* traversing the two collections of children, identifying nodes that are
|
|
638
|
+
* conserved or changed, calling out to `patch` to make any necessary
|
|
639
|
+
* updates to the DOM, and rearranging DOM nodes as needed.
|
|
640
|
+
*
|
|
641
|
+
* The algorithm for reconciling children works by analyzing two 'windows' onto
|
|
642
|
+
* the two arrays of children (`oldCh` and `newCh`). We keep track of the
|
|
643
|
+
* 'windows' by storing start and end indices and references to the
|
|
644
|
+
* corresponding array entries. Initially the two 'windows' are basically equal
|
|
645
|
+
* to the entire array, but we progressively narrow the windows until there are
|
|
646
|
+
* no children left to update by doing the following:
|
|
647
|
+
*
|
|
648
|
+
* 1. Skip any `null` entries at the beginning or end of the two arrays, so
|
|
649
|
+
* that if we have an initial array like the following we'll end up dealing
|
|
650
|
+
* only with a window bounded by the highlighted elements:
|
|
651
|
+
*
|
|
652
|
+
* [null, null, VNode1 , ... , VNode2, null, null]
|
|
653
|
+
* ^^^^^^ ^^^^^^
|
|
654
|
+
*
|
|
655
|
+
* 2. Check to see if the elements at the head and tail positions are equal
|
|
656
|
+
* across the windows. This will basically detect elements which haven't
|
|
657
|
+
* been added, removed, or changed position, i.e. if you had the following
|
|
658
|
+
* VNode elements (represented as HTML):
|
|
659
|
+
*
|
|
660
|
+
* oldVNode: `<div><p><span>HEY</span></p></div>`
|
|
661
|
+
* newVNode: `<div><p><span>THERE</span></p></div>`
|
|
662
|
+
*
|
|
663
|
+
* Then when comparing the children of the `<div>` tag we check the equality
|
|
664
|
+
* of the VNodes corresponding to the `<p>` tags and, since they are the
|
|
665
|
+
* same tag in the same position, we'd be able to avoid completely
|
|
666
|
+
* re-rendering the subtree under them with a new DOM element and would just
|
|
667
|
+
* call out to `patch` to handle reconciling their children and so on.
|
|
668
|
+
*
|
|
669
|
+
* 3. Check, for both windows, to see if the element at the beginning of the
|
|
670
|
+
* window corresponds to the element at the end of the other window. This is
|
|
671
|
+
* a heuristic which will let us identify _some_ situations in which
|
|
672
|
+
* elements have changed position, for instance it _should_ detect that the
|
|
673
|
+
* children nodes themselves have not changed but merely moved in the
|
|
674
|
+
* following example:
|
|
675
|
+
*
|
|
676
|
+
* oldVNode: `<div><element-one /><element-two /></div>`
|
|
677
|
+
* newVNode: `<div><element-two /><element-one /></div>`
|
|
678
|
+
*
|
|
679
|
+
* If we find cases like this then we also need to move the concrete DOM
|
|
680
|
+
* elements corresponding to the moved children to write the re-order to the
|
|
681
|
+
* DOM.
|
|
682
|
+
*
|
|
683
|
+
* 4. Finally, if VNodes have the `key` attribute set on them we check for any
|
|
684
|
+
* nodes in the old children which have the same key as the first element in
|
|
685
|
+
* our window on the new children. If we find such a node we handle calling
|
|
686
|
+
* out to `patch`, moving relevant DOM nodes, and so on, in accordance with
|
|
687
|
+
* what we find.
|
|
688
|
+
*
|
|
689
|
+
* Finally, once we've narrowed our 'windows' to the point that either of them
|
|
690
|
+
* collapse (i.e. they have length 0) we then handle any remaining VNode
|
|
691
|
+
* insertion or deletion that needs to happen to get a DOM state that correctly
|
|
692
|
+
* reflects the new child VNodes. If, for instance, after our window on the old
|
|
693
|
+
* children has collapsed we still have more nodes on the new children that
|
|
694
|
+
* we haven't dealt with yet then we need to add them, or if the new children
|
|
695
|
+
* collapse but we still have unhandled _old_ children then we need to make
|
|
696
|
+
* sure the corresponding DOM nodes are removed.
|
|
697
|
+
*
|
|
698
|
+
* @param parentElm the node into which the parent VNode is rendered
|
|
699
|
+
* @param oldCh the old children of the parent node
|
|
700
|
+
* @param newVNode the new VNode which will replace the parent
|
|
701
|
+
* @param newCh the new children of the parent node
|
|
702
|
+
*/
|
|
602
703
|
const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
603
704
|
let oldStartIdx = 0;
|
|
604
705
|
let newStartIdx = 0;
|
|
@@ -611,7 +712,7 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
611
712
|
let node;
|
|
612
713
|
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
613
714
|
if (oldStartVnode == null) {
|
|
614
|
-
//
|
|
715
|
+
// VNode might have been moved left
|
|
615
716
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
616
717
|
}
|
|
617
718
|
else if (oldEndVnode == null) {
|
|
@@ -624,42 +725,102 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
624
725
|
newEndVnode = newCh[--newEndIdx];
|
|
625
726
|
}
|
|
626
727
|
else if (isSameVnode(oldStartVnode, newStartVnode)) {
|
|
728
|
+
// if the start nodes are the same then we should patch the new VNode
|
|
729
|
+
// onto the old one, and increment our `newStartIdx` and `oldStartIdx`
|
|
730
|
+
// indices to reflect that. We don't need to move any DOM Nodes around
|
|
731
|
+
// since things are matched up in order.
|
|
627
732
|
patch(oldStartVnode, newStartVnode);
|
|
628
733
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
629
734
|
newStartVnode = newCh[++newStartIdx];
|
|
630
735
|
}
|
|
631
736
|
else if (isSameVnode(oldEndVnode, newEndVnode)) {
|
|
737
|
+
// likewise, if the end nodes are the same we patch new onto old and
|
|
738
|
+
// decrement our end indices, and also likewise in this case we don't
|
|
739
|
+
// need to move any DOM Nodes.
|
|
632
740
|
patch(oldEndVnode, newEndVnode);
|
|
633
741
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
634
742
|
newEndVnode = newCh[--newEndIdx];
|
|
635
743
|
}
|
|
636
744
|
else if (isSameVnode(oldStartVnode, newEndVnode)) {
|
|
637
|
-
// Vnode moved right
|
|
745
|
+
// case: "Vnode moved right"
|
|
746
|
+
//
|
|
747
|
+
// We've found that the last node in our window on the new children is
|
|
748
|
+
// the same VNode as the _first_ node in our window on the old children
|
|
749
|
+
// we're dealing with now. Visually, this is the layout of these two
|
|
750
|
+
// nodes:
|
|
751
|
+
//
|
|
752
|
+
// newCh: [..., newStartVnode , ... , newEndVnode , ...]
|
|
753
|
+
// ^^^^^^^^^^^
|
|
754
|
+
// oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
|
|
755
|
+
// ^^^^^^^^^^^^^
|
|
756
|
+
//
|
|
757
|
+
// In this situation we need to patch `newEndVnode` onto `oldStartVnode`
|
|
758
|
+
// and move the DOM element for `oldStartVnode`.
|
|
638
759
|
if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
|
|
639
760
|
putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
|
|
640
761
|
}
|
|
641
762
|
patch(oldStartVnode, newEndVnode);
|
|
763
|
+
// We need to move the element for `oldStartVnode` into a position which
|
|
764
|
+
// will be appropriate for `newEndVnode`. For this we can use
|
|
765
|
+
// `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
|
|
766
|
+
// sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
|
|
767
|
+
// `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
|
|
768
|
+
//
|
|
769
|
+
// <old-start-node />
|
|
770
|
+
// <some-intervening-node />
|
|
771
|
+
// <old-end-node />
|
|
772
|
+
// <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
|
|
773
|
+
// <next-sibling />
|
|
774
|
+
//
|
|
775
|
+
// If instead `oldEndVnode.$elm$` has no sibling then we just want to put
|
|
776
|
+
// the node for `oldStartVnode` at the end of the children of
|
|
777
|
+
// `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
|
|
778
|
+
// aren't any siblings, and passing `null` to `Node.insertBefore` will
|
|
779
|
+
// append it to the children of the parent element.
|
|
642
780
|
parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
|
|
643
781
|
oldStartVnode = oldCh[++oldStartIdx];
|
|
644
782
|
newEndVnode = newCh[--newEndIdx];
|
|
645
783
|
}
|
|
646
784
|
else if (isSameVnode(oldEndVnode, newStartVnode)) {
|
|
647
|
-
// Vnode moved left
|
|
785
|
+
// case: "Vnode moved left"
|
|
786
|
+
//
|
|
787
|
+
// We've found that the first node in our window on the new children is
|
|
788
|
+
// the same VNode as the _last_ node in our window on the old children.
|
|
789
|
+
// Visually, this is the layout of these two nodes:
|
|
790
|
+
//
|
|
791
|
+
// newCh: [..., newStartVnode , ... , newEndVnode , ...]
|
|
792
|
+
// ^^^^^^^^^^^^^
|
|
793
|
+
// oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
|
|
794
|
+
// ^^^^^^^^^^^
|
|
795
|
+
//
|
|
796
|
+
// In this situation we need to patch `newStartVnode` onto `oldEndVnode`
|
|
797
|
+
// (which will handle updating any changed attributes, reconciling their
|
|
798
|
+
// children etc) but we also need to move the DOM node to which
|
|
799
|
+
// `oldEndVnode` corresponds.
|
|
648
800
|
if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
|
|
649
801
|
putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
|
|
650
802
|
}
|
|
651
803
|
patch(oldEndVnode, newStartVnode);
|
|
804
|
+
// We've already checked above if `oldStartVnode` and `newStartVnode` are
|
|
805
|
+
// the same node, so since we're here we know that they are not. Thus we
|
|
806
|
+
// can move the element for `oldEndVnode` _before_ the element for
|
|
807
|
+
// `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
|
|
808
|
+
// future.
|
|
652
809
|
parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
|
|
653
810
|
oldEndVnode = oldCh[--oldEndIdx];
|
|
654
811
|
newStartVnode = newCh[++newStartIdx];
|
|
655
812
|
}
|
|
656
813
|
else {
|
|
657
814
|
{
|
|
658
|
-
//
|
|
815
|
+
// We either didn't find an element in the old children that matches
|
|
816
|
+
// the key of the first new child OR the build is not using `key`
|
|
817
|
+
// attributes at all. In either case we need to create a new element
|
|
818
|
+
// for the new node.
|
|
659
819
|
node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
|
|
660
820
|
newStartVnode = newCh[++newStartIdx];
|
|
661
821
|
}
|
|
662
822
|
if (node) {
|
|
823
|
+
// if we created a new node then handle inserting it to the DOM
|
|
663
824
|
{
|
|
664
825
|
parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
|
|
665
826
|
}
|
|
@@ -667,18 +828,39 @@ const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
|
|
|
667
828
|
}
|
|
668
829
|
}
|
|
669
830
|
if (oldStartIdx > oldEndIdx) {
|
|
831
|
+
// we have some more new nodes to add which don't match up with old nodes
|
|
670
832
|
addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
|
|
671
833
|
}
|
|
672
834
|
else if (newStartIdx > newEndIdx) {
|
|
835
|
+
// there are nodes in the `oldCh` array which no longer correspond to nodes
|
|
836
|
+
// in the new array, so lets remove them (which entails cleaning up the
|
|
837
|
+
// relevant DOM nodes)
|
|
673
838
|
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
|
|
674
839
|
}
|
|
675
840
|
};
|
|
676
|
-
|
|
841
|
+
/**
|
|
842
|
+
* Compare two VNodes to determine if they are the same
|
|
843
|
+
*
|
|
844
|
+
* **NB**: This function is an equality _heuristic_ based on the available
|
|
845
|
+
* information set on the two VNodes and can be misleading under certain
|
|
846
|
+
* circumstances. In particular, if the two nodes do not have `key` attrs
|
|
847
|
+
* (available under `$key$` on VNodes) then the function falls back on merely
|
|
848
|
+
* checking that they have the same tag.
|
|
849
|
+
*
|
|
850
|
+
* So, in other words, if `key` attrs are not set on VNodes which may be
|
|
851
|
+
* changing order within a `children` array or something along those lines then
|
|
852
|
+
* we could obtain a false positive and then have to do needless re-rendering.
|
|
853
|
+
*
|
|
854
|
+
* @param leftVNode the first VNode to check
|
|
855
|
+
* @param rightVNode the second VNode to check
|
|
856
|
+
* @returns whether they're equal or not
|
|
857
|
+
*/
|
|
858
|
+
const isSameVnode = (leftVNode, rightVNode) => {
|
|
677
859
|
// compare if two vnode to see if they're "technically" the same
|
|
678
860
|
// need to have the same element tag, and same key to be the same
|
|
679
|
-
if (
|
|
680
|
-
if (
|
|
681
|
-
return
|
|
861
|
+
if (leftVNode.$tag$ === rightVNode.$tag$) {
|
|
862
|
+
if (leftVNode.$tag$ === 'slot') {
|
|
863
|
+
return leftVNode.$name$ === rightVNode.$name$;
|
|
682
864
|
}
|
|
683
865
|
return true;
|
|
684
866
|
}
|
|
@@ -692,6 +874,14 @@ const referenceNode = (node) => {
|
|
|
692
874
|
return (node && node['s-ol']) || node;
|
|
693
875
|
};
|
|
694
876
|
const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
|
|
877
|
+
/**
|
|
878
|
+
* Handle reconciling an outdated VNode with a new one which corresponds to
|
|
879
|
+
* it. This function handles flushing updates to the DOM and reconciling the
|
|
880
|
+
* children of the two nodes (if any).
|
|
881
|
+
*
|
|
882
|
+
* @param oldVNode an old VNode whose DOM element and children we want to update
|
|
883
|
+
* @param newVNode a new VNode representing an updated version of the old one
|
|
884
|
+
*/
|
|
695
885
|
const patch = (oldVNode, newVNode) => {
|
|
696
886
|
const elm = (newVNode.$elm$ = oldVNode.$elm$);
|
|
697
887
|
const oldChildren = oldVNode.$children$;
|
|
@@ -705,7 +895,6 @@ const patch = (oldVNode, newVNode) => {
|
|
|
705
895
|
// only add this to the when the compiler sees we're using an svg somewhere
|
|
706
896
|
isSvgMode = tag === 'svg' ? true : tag === 'foreignObject' ? false : isSvgMode;
|
|
707
897
|
}
|
|
708
|
-
// element node
|
|
709
898
|
{
|
|
710
899
|
if (tag === 'slot')
|
|
711
900
|
;
|
|
@@ -718,6 +907,7 @@ const patch = (oldVNode, newVNode) => {
|
|
|
718
907
|
}
|
|
719
908
|
if (oldChildren !== null && newChildren !== null) {
|
|
720
909
|
// looks like there's child vnodes for both the old and new vnodes
|
|
910
|
+
// so we need to call `updateChildren` to reconcile them
|
|
721
911
|
updateChildren(elm, oldChildren, newVNode, newChildren);
|
|
722
912
|
}
|
|
723
913
|
else if (newChildren !== null) {
|
|
@@ -758,7 +948,7 @@ const updateFallbackSlotVisibility = (elm) => {
|
|
|
758
948
|
let nodeType;
|
|
759
949
|
for (i = 0, ilen = childNodes.length; i < ilen; i++) {
|
|
760
950
|
childNode = childNodes[i];
|
|
761
|
-
if (childNode.nodeType === 1 /* ElementNode */) {
|
|
951
|
+
if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
762
952
|
if (childNode['s-sr']) {
|
|
763
953
|
// this is a slot fallback node
|
|
764
954
|
// get the slot name for this slot reference node
|
|
@@ -770,7 +960,7 @@ const updateFallbackSlotVisibility = (elm) => {
|
|
|
770
960
|
nodeType = childNodes[j].nodeType;
|
|
771
961
|
if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
|
|
772
962
|
// this sibling node is from a different component OR is a named fallback slot node
|
|
773
|
-
if (nodeType === 1 /* ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
|
|
963
|
+
if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
|
|
774
964
|
childNode.hidden = true;
|
|
775
965
|
break;
|
|
776
966
|
}
|
|
@@ -779,8 +969,8 @@ const updateFallbackSlotVisibility = (elm) => {
|
|
|
779
969
|
// this is a default fallback slot node
|
|
780
970
|
// any element or text node (with content)
|
|
781
971
|
// should hide the default fallback slot node
|
|
782
|
-
if (nodeType === 1 /* ElementNode */ ||
|
|
783
|
-
(nodeType === 3 /* TextNode */ && childNodes[j].textContent.trim() !== '')) {
|
|
972
|
+
if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
|
|
973
|
+
(nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
|
|
784
974
|
childNode.hidden = true;
|
|
785
975
|
break;
|
|
786
976
|
}
|
|
@@ -858,13 +1048,13 @@ const relocateSlotContent = (elm) => {
|
|
|
858
1048
|
}
|
|
859
1049
|
}
|
|
860
1050
|
}
|
|
861
|
-
if (childNode.nodeType === 1 /* ElementNode */) {
|
|
1051
|
+
if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
862
1052
|
relocateSlotContent(childNode);
|
|
863
1053
|
}
|
|
864
1054
|
}
|
|
865
1055
|
};
|
|
866
1056
|
const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
|
|
867
|
-
if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
|
|
1057
|
+
if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
868
1058
|
if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
|
|
869
1059
|
return true;
|
|
870
1060
|
}
|
|
@@ -895,7 +1085,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
895
1085
|
cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
|
|
896
1086
|
}
|
|
897
1087
|
rootVnode.$tag$ = null;
|
|
898
|
-
rootVnode.$flags$ |= 4 /* isHost */;
|
|
1088
|
+
rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
|
|
899
1089
|
hostRef.$vnode$ = rootVnode;
|
|
900
1090
|
rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
|
|
901
1091
|
{
|
|
@@ -903,7 +1093,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
903
1093
|
}
|
|
904
1094
|
{
|
|
905
1095
|
contentRef = hostElm['s-cr'];
|
|
906
|
-
useNativeShadowDom = (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) !== 0;
|
|
1096
|
+
useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
|
|
907
1097
|
// always reset
|
|
908
1098
|
checkSlotFallbackVisibility = false;
|
|
909
1099
|
}
|
|
@@ -912,7 +1102,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
912
1102
|
{
|
|
913
1103
|
// while we're moving nodes around existing nodes, temporarily disable
|
|
914
1104
|
// the disconnectCallback from working
|
|
915
|
-
plt.$flags$ |= 1 /* isTmpDisconnected */;
|
|
1105
|
+
plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
916
1106
|
if (checkSlotRelocate) {
|
|
917
1107
|
relocateSlotContent(rootVnode.$elm$);
|
|
918
1108
|
let relocateData;
|
|
@@ -970,7 +1160,7 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
970
1160
|
}
|
|
971
1161
|
else {
|
|
972
1162
|
// this node doesn't have a slot home to go to, so let's hide it
|
|
973
|
-
if (nodeToRelocate.nodeType === 1 /* ElementNode */) {
|
|
1163
|
+
if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
|
|
974
1164
|
nodeToRelocate.hidden = true;
|
|
975
1165
|
}
|
|
976
1166
|
}
|
|
@@ -981,37 +1171,11 @@ const renderVdom = (hostRef, renderFnResults) => {
|
|
|
981
1171
|
}
|
|
982
1172
|
// done moving nodes around
|
|
983
1173
|
// allow the disconnect callback to work again
|
|
984
|
-
plt.$flags$ &= ~1 /* isTmpDisconnected */;
|
|
1174
|
+
plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
|
|
985
1175
|
// always reset
|
|
986
1176
|
relocateNodes.length = 0;
|
|
987
1177
|
}
|
|
988
1178
|
};
|
|
989
|
-
const getElement = (ref) => (getHostRef(ref).$hostElement$ );
|
|
990
|
-
const createEvent = (ref, name, flags) => {
|
|
991
|
-
const elm = getElement(ref);
|
|
992
|
-
return {
|
|
993
|
-
emit: (detail) => {
|
|
994
|
-
return emitEvent(elm, name, {
|
|
995
|
-
bubbles: !!(flags & 4 /* Bubbles */),
|
|
996
|
-
composed: !!(flags & 2 /* Composed */),
|
|
997
|
-
cancelable: !!(flags & 1 /* Cancellable */),
|
|
998
|
-
detail,
|
|
999
|
-
});
|
|
1000
|
-
},
|
|
1001
|
-
};
|
|
1002
|
-
};
|
|
1003
|
-
/**
|
|
1004
|
-
* Helper function to create & dispatch a custom Event on a provided target
|
|
1005
|
-
* @param elm the target of the Event
|
|
1006
|
-
* @param name the name to give the custom Event
|
|
1007
|
-
* @param opts options for configuring a custom Event
|
|
1008
|
-
* @returns the custom Event
|
|
1009
|
-
*/
|
|
1010
|
-
const emitEvent = (elm, name, opts) => {
|
|
1011
|
-
const ev = plt.ce(name, opts);
|
|
1012
|
-
elm.dispatchEvent(ev);
|
|
1013
|
-
return ev;
|
|
1014
|
-
};
|
|
1015
1179
|
const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
1016
1180
|
if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
|
|
1017
1181
|
ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
|
|
@@ -1019,10 +1183,10 @@ const attachToAncestor = (hostRef, ancestorComponent) => {
|
|
|
1019
1183
|
};
|
|
1020
1184
|
const scheduleUpdate = (hostRef, isInitialLoad) => {
|
|
1021
1185
|
{
|
|
1022
|
-
hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
|
|
1186
|
+
hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
1023
1187
|
}
|
|
1024
|
-
if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
|
|
1025
|
-
hostRef.$flags$ |= 512 /* needsRerender */;
|
|
1188
|
+
if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
|
|
1189
|
+
hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
|
|
1026
1190
|
return;
|
|
1027
1191
|
}
|
|
1028
1192
|
attachToAncestor(hostRef, hostRef.$ancestorComponent$);
|
|
@@ -1038,7 +1202,7 @@ const dispatchHooks = (hostRef, isInitialLoad) => {
|
|
|
1038
1202
|
let promise;
|
|
1039
1203
|
if (isInitialLoad) {
|
|
1040
1204
|
{
|
|
1041
|
-
hostRef.$flags$ |= 256 /* isListenReady */;
|
|
1205
|
+
hostRef.$flags$ |= 256 /* HOST_FLAGS.isListenReady */;
|
|
1042
1206
|
if (hostRef.$queuedListeners$) {
|
|
1043
1207
|
hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
|
|
1044
1208
|
hostRef.$queuedListeners$ = null;
|
|
@@ -1081,7 +1245,7 @@ const updateComponent = async (hostRef, instance, isInitialLoad) => {
|
|
|
1081
1245
|
}
|
|
1082
1246
|
else {
|
|
1083
1247
|
Promise.all(childrenPromises).then(postUpdate);
|
|
1084
|
-
hostRef.$flags$ |= 4 /* isWaitingForChildren */;
|
|
1248
|
+
hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
|
|
1085
1249
|
childrenPromises.length = 0;
|
|
1086
1250
|
}
|
|
1087
1251
|
}
|
|
@@ -1090,10 +1254,10 @@ const callRender = (hostRef, instance, elm) => {
|
|
|
1090
1254
|
try {
|
|
1091
1255
|
instance = instance.render() ;
|
|
1092
1256
|
{
|
|
1093
|
-
hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
|
|
1257
|
+
hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
|
|
1094
1258
|
}
|
|
1095
1259
|
{
|
|
1096
|
-
hostRef.$flags$ |= 2 /* hasRendered */;
|
|
1260
|
+
hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
|
|
1097
1261
|
}
|
|
1098
1262
|
{
|
|
1099
1263
|
{
|
|
@@ -1120,8 +1284,8 @@ const postUpdateComponent = (hostRef) => {
|
|
|
1120
1284
|
{
|
|
1121
1285
|
safeCall(instance, 'componentDidRender');
|
|
1122
1286
|
}
|
|
1123
|
-
if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
|
|
1124
|
-
hostRef.$flags$ |= 64 /* hasLoadedComponent */;
|
|
1287
|
+
if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
|
|
1288
|
+
hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
|
|
1125
1289
|
{
|
|
1126
1290
|
// DOM WRITE!
|
|
1127
1291
|
addHydratedFlag(elm);
|
|
@@ -1150,10 +1314,10 @@ const postUpdateComponent = (hostRef) => {
|
|
|
1150
1314
|
hostRef.$onRenderResolve$();
|
|
1151
1315
|
hostRef.$onRenderResolve$ = undefined;
|
|
1152
1316
|
}
|
|
1153
|
-
if (hostRef.$flags$ & 512 /* needsRerender */) {
|
|
1317
|
+
if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
|
|
1154
1318
|
nextTick(() => scheduleUpdate(hostRef, false));
|
|
1155
1319
|
}
|
|
1156
|
-
hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
|
|
1320
|
+
hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
|
|
1157
1321
|
}
|
|
1158
1322
|
// ( •_•)
|
|
1159
1323
|
// ( •_•)>⌐■-■
|
|
@@ -1183,53 +1347,6 @@ const then = (promise, thenFn) => {
|
|
|
1183
1347
|
};
|
|
1184
1348
|
const addHydratedFlag = (elm) => elm.classList.add('hydrated')
|
|
1185
1349
|
;
|
|
1186
|
-
/**
|
|
1187
|
-
* Parse a new property value for a given property type.
|
|
1188
|
-
*
|
|
1189
|
-
* While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
|
|
1190
|
-
* it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
|
|
1191
|
-
* 1. `any`, the type given to `propValue` in the function signature
|
|
1192
|
-
* 2. the type stored from `propType`.
|
|
1193
|
-
*
|
|
1194
|
-
* This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
|
|
1195
|
-
*
|
|
1196
|
-
* Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
|
|
1197
|
-
* a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
|
|
1198
|
-
* based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
|
|
1199
|
-
* ```tsx
|
|
1200
|
-
* <my-cmp prop-val={0}></my-cmp>
|
|
1201
|
-
* ```
|
|
1202
|
-
*
|
|
1203
|
-
* HTML prop values on the other hand, will always a string
|
|
1204
|
-
*
|
|
1205
|
-
* @param propValue the new value to coerce to some type
|
|
1206
|
-
* @param propType the type of the prop, expressed as a binary number
|
|
1207
|
-
* @returns the parsed/coerced value
|
|
1208
|
-
*/
|
|
1209
|
-
const parsePropertyValue = (propValue, propType) => {
|
|
1210
|
-
// ensure this value is of the correct prop type
|
|
1211
|
-
if (propValue != null && !isComplexType(propValue)) {
|
|
1212
|
-
if (propType & 4 /* Boolean */) {
|
|
1213
|
-
// per the HTML spec, any string value means it is a boolean true value
|
|
1214
|
-
// but we'll cheat here and say that the string "false" is the boolean false
|
|
1215
|
-
return propValue === 'false' ? false : propValue === '' || !!propValue;
|
|
1216
|
-
}
|
|
1217
|
-
if (propType & 2 /* Number */) {
|
|
1218
|
-
// force it to be a number
|
|
1219
|
-
return parseFloat(propValue);
|
|
1220
|
-
}
|
|
1221
|
-
if (propType & 1 /* String */) {
|
|
1222
|
-
// could have been passed as a number or boolean
|
|
1223
|
-
// but we still want it as a string
|
|
1224
|
-
return String(propValue);
|
|
1225
|
-
}
|
|
1226
|
-
// redundant return here for better minification
|
|
1227
|
-
return propValue;
|
|
1228
|
-
}
|
|
1229
|
-
// not sure exactly what type we want
|
|
1230
|
-
// so no need to change to a different type
|
|
1231
|
-
return propValue;
|
|
1232
|
-
};
|
|
1233
1350
|
const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
|
|
1234
1351
|
const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
1235
1352
|
// check our new property value against our internal value
|
|
@@ -1242,13 +1359,13 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
1242
1359
|
// explicitly check for NaN on both sides, as `NaN === NaN` is always false
|
|
1243
1360
|
const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
|
|
1244
1361
|
const didValueChange = newVal !== oldVal && !areBothNaN;
|
|
1245
|
-
if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
1362
|
+
if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
|
|
1246
1363
|
// gadzooks! the property's value has changed!!
|
|
1247
1364
|
// set our new value!
|
|
1248
1365
|
hostRef.$instanceValues$.set(propName, newVal);
|
|
1249
1366
|
if (instance) {
|
|
1250
1367
|
// get an array of method names of watch functions to call
|
|
1251
|
-
if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
|
|
1368
|
+
if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
|
|
1252
1369
|
const watchMethods = cmpMeta.$watchers$[propName];
|
|
1253
1370
|
if (watchMethods) {
|
|
1254
1371
|
// this instance is watching for when this property changed
|
|
@@ -1263,7 +1380,7 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
1263
1380
|
});
|
|
1264
1381
|
}
|
|
1265
1382
|
}
|
|
1266
|
-
if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
|
|
1383
|
+
if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
|
|
1267
1384
|
// looks like this value actually changed, so we've got work to do!
|
|
1268
1385
|
// but only if we've already rendered, otherwise just chill out
|
|
1269
1386
|
// queue that we need to do an update, but don't worry about queuing
|
|
@@ -1273,6 +1390,16 @@ const setValue = (ref, propName, newVal, cmpMeta) => {
|
|
|
1273
1390
|
}
|
|
1274
1391
|
}
|
|
1275
1392
|
};
|
|
1393
|
+
/**
|
|
1394
|
+
* Attach a series of runtime constructs to a compiled Stencil component
|
|
1395
|
+
* constructor, including getters and setters for the `@Prop` and `@State`
|
|
1396
|
+
* decorators, callbacks for when attributes change, and so on.
|
|
1397
|
+
*
|
|
1398
|
+
* @param Cstr the constructor for a component that we need to process
|
|
1399
|
+
* @param cmpMeta metadata collected previously about the component
|
|
1400
|
+
* @param flags a number used to store a series of bit flags
|
|
1401
|
+
* @returns a reference to the same constructor passed in (but now mutated)
|
|
1402
|
+
*/
|
|
1276
1403
|
const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
1277
1404
|
if (cmpMeta.$members$) {
|
|
1278
1405
|
if (Cstr.watchers) {
|
|
@@ -1282,8 +1409,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1282
1409
|
const members = Object.entries(cmpMeta.$members$);
|
|
1283
1410
|
const prototype = Cstr.prototype;
|
|
1284
1411
|
members.map(([memberName, [memberFlags]]) => {
|
|
1285
|
-
if ((memberFlags & 31 /* Prop */ ||
|
|
1286
|
-
((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
|
|
1412
|
+
if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
|
|
1413
|
+
((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
|
|
1287
1414
|
// proxyComponent - prop
|
|
1288
1415
|
Object.defineProperty(prototype, memberName, {
|
|
1289
1416
|
get() {
|
|
@@ -1298,8 +1425,8 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1298
1425
|
enumerable: true,
|
|
1299
1426
|
});
|
|
1300
1427
|
}
|
|
1301
|
-
else if (flags & 1 /* isElementConstructor */ &&
|
|
1302
|
-
memberFlags & 64 /* Method */) {
|
|
1428
|
+
else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
|
|
1429
|
+
memberFlags & 64 /* MEMBER_FLAGS.Method */) {
|
|
1303
1430
|
// proxyComponent - method
|
|
1304
1431
|
Object.defineProperty(prototype, memberName, {
|
|
1305
1432
|
value(...args) {
|
|
@@ -1309,7 +1436,7 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1309
1436
|
});
|
|
1310
1437
|
}
|
|
1311
1438
|
});
|
|
1312
|
-
if ((flags & 1 /* isElementConstructor */)) {
|
|
1439
|
+
if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
|
|
1313
1440
|
const attrNameToPropName = new Map();
|
|
1314
1441
|
prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
|
|
1315
1442
|
plt.jmp(() => {
|
|
@@ -1365,11 +1492,11 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1365
1492
|
// create an array of attributes to observe
|
|
1366
1493
|
// and also create a map of html attribute name to js property name
|
|
1367
1494
|
Cstr.observedAttributes = members
|
|
1368
|
-
.filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
|
|
1495
|
+
.filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
|
|
1369
1496
|
.map(([propName, m]) => {
|
|
1370
1497
|
const attrName = m[1] || propName;
|
|
1371
1498
|
attrNameToPropName.set(attrName, propName);
|
|
1372
|
-
if (m[0] & 512 /* ReflectAttr */) {
|
|
1499
|
+
if (m[0] & 512 /* MEMBER_FLAGS.ReflectAttr */) {
|
|
1373
1500
|
cmpMeta.$attrsToReflect$.push([propName, attrName]);
|
|
1374
1501
|
}
|
|
1375
1502
|
return attrName;
|
|
@@ -1380,10 +1507,10 @@ const proxyComponent = (Cstr, cmpMeta, flags) => {
|
|
|
1380
1507
|
};
|
|
1381
1508
|
const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
|
|
1382
1509
|
// initializeComponent
|
|
1383
|
-
if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
|
|
1510
|
+
if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
|
|
1384
1511
|
{
|
|
1385
1512
|
// we haven't initialized this element yet
|
|
1386
|
-
hostRef.$flags$ |= 32 /* hasInitializedComponent */;
|
|
1513
|
+
hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
|
|
1387
1514
|
// lazy loaded components
|
|
1388
1515
|
// request the component's implementation to be
|
|
1389
1516
|
// wired up with the host element
|
|
@@ -1401,7 +1528,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1401
1528
|
{
|
|
1402
1529
|
cmpMeta.$watchers$ = Cstr.watchers;
|
|
1403
1530
|
}
|
|
1404
|
-
proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
|
|
1531
|
+
proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
|
|
1405
1532
|
Cstr.isProxied = true;
|
|
1406
1533
|
}
|
|
1407
1534
|
const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
|
|
@@ -1409,7 +1536,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1409
1536
|
// but let's keep track of when we start and stop
|
|
1410
1537
|
// so that the getters/setters don't incorrectly step on data
|
|
1411
1538
|
{
|
|
1412
|
-
hostRef.$flags$ |= 8 /* isConstructingInstance */;
|
|
1539
|
+
hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
|
|
1413
1540
|
}
|
|
1414
1541
|
// construct the lazy-loaded component implementation
|
|
1415
1542
|
// passing the hostRef is very important during
|
|
@@ -1422,10 +1549,10 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1422
1549
|
consoleError(e);
|
|
1423
1550
|
}
|
|
1424
1551
|
{
|
|
1425
|
-
hostRef.$flags$ &= ~8 /* isConstructingInstance */;
|
|
1552
|
+
hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
|
|
1426
1553
|
}
|
|
1427
1554
|
{
|
|
1428
|
-
hostRef.$flags$ |= 128 /* isWatchReady */;
|
|
1555
|
+
hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
|
|
1429
1556
|
}
|
|
1430
1557
|
endNewInstance();
|
|
1431
1558
|
}
|
|
@@ -1435,7 +1562,7 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1435
1562
|
const scopeId = getScopeId(cmpMeta);
|
|
1436
1563
|
if (!styles.has(scopeId)) {
|
|
1437
1564
|
const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
|
|
1438
|
-
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
|
|
1565
|
+
registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
|
|
1439
1566
|
endRegisterStyles();
|
|
1440
1567
|
}
|
|
1441
1568
|
}
|
|
@@ -1457,19 +1584,19 @@ const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) =>
|
|
|
1457
1584
|
}
|
|
1458
1585
|
};
|
|
1459
1586
|
const connectedCallback = (elm) => {
|
|
1460
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1587
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
1461
1588
|
const hostRef = getHostRef(elm);
|
|
1462
1589
|
const cmpMeta = hostRef.$cmpMeta$;
|
|
1463
1590
|
const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
|
|
1464
|
-
if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
|
|
1591
|
+
if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
|
|
1465
1592
|
// first time this component has connected
|
|
1466
|
-
hostRef.$flags$ |= 1 /* hasConnected */;
|
|
1593
|
+
hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
|
|
1467
1594
|
{
|
|
1468
1595
|
// initUpdate
|
|
1469
1596
|
// if the slot polyfill is required we'll need to put some nodes
|
|
1470
1597
|
// in here to act as original content anchors as we move nodes around
|
|
1471
1598
|
// host element has been connected to the DOM
|
|
1472
|
-
if ((cmpMeta.$flags$ & (4 /* hasSlotRelocation */ | 8 /* needsShadowDomShim */))) {
|
|
1599
|
+
if ((cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
|
|
1473
1600
|
setContentReference(elm);
|
|
1474
1601
|
}
|
|
1475
1602
|
}
|
|
@@ -1492,7 +1619,7 @@ const connectedCallback = (elm) => {
|
|
|
1492
1619
|
// https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
|
|
1493
1620
|
if (cmpMeta.$members$) {
|
|
1494
1621
|
Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
|
|
1495
|
-
if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1622
|
+
if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
|
|
1496
1623
|
const value = elm[memberName];
|
|
1497
1624
|
delete elm[memberName];
|
|
1498
1625
|
elm[memberName] = value;
|
|
@@ -1524,7 +1651,7 @@ const setContentReference = (elm) => {
|
|
|
1524
1651
|
elm.insertBefore(contentRefElm, elm.firstChild);
|
|
1525
1652
|
};
|
|
1526
1653
|
const disconnectedCallback = (elm) => {
|
|
1527
|
-
if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
|
|
1654
|
+
if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
|
|
1528
1655
|
const hostRef = getHostRef(elm);
|
|
1529
1656
|
{
|
|
1530
1657
|
if (hostRef.$rmListeners$) {
|
|
@@ -1534,46 +1661,6 @@ const disconnectedCallback = (elm) => {
|
|
|
1534
1661
|
}
|
|
1535
1662
|
}
|
|
1536
1663
|
};
|
|
1537
|
-
const patchCloneNode = (HostElementPrototype) => {
|
|
1538
|
-
const orgCloneNode = HostElementPrototype.cloneNode;
|
|
1539
|
-
HostElementPrototype.cloneNode = function (deep) {
|
|
1540
|
-
const srcNode = this;
|
|
1541
|
-
const isShadowDom = srcNode.shadowRoot && supportsShadow ;
|
|
1542
|
-
const clonedNode = orgCloneNode.call(srcNode, isShadowDom ? deep : false);
|
|
1543
|
-
if (!isShadowDom && deep) {
|
|
1544
|
-
let i = 0;
|
|
1545
|
-
let slotted, nonStencilNode;
|
|
1546
|
-
const stencilPrivates = [
|
|
1547
|
-
's-id',
|
|
1548
|
-
's-cr',
|
|
1549
|
-
's-lr',
|
|
1550
|
-
's-rc',
|
|
1551
|
-
's-sc',
|
|
1552
|
-
's-p',
|
|
1553
|
-
's-cn',
|
|
1554
|
-
's-sr',
|
|
1555
|
-
's-sn',
|
|
1556
|
-
's-hn',
|
|
1557
|
-
's-ol',
|
|
1558
|
-
's-nr',
|
|
1559
|
-
's-si',
|
|
1560
|
-
];
|
|
1561
|
-
for (; i < srcNode.childNodes.length; i++) {
|
|
1562
|
-
slotted = srcNode.childNodes[i]['s-nr'];
|
|
1563
|
-
nonStencilNode = stencilPrivates.every((privateField) => !srcNode.childNodes[i][privateField]);
|
|
1564
|
-
if (slotted) {
|
|
1565
|
-
{
|
|
1566
|
-
clonedNode.appendChild(slotted.cloneNode(true));
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
if (nonStencilNode) {
|
|
1570
|
-
clonedNode.appendChild(srcNode.childNodes[i].cloneNode(true));
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
return clonedNode;
|
|
1575
|
-
};
|
|
1576
|
-
};
|
|
1577
1664
|
const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
1578
1665
|
const endBootstrap = createTime();
|
|
1579
1666
|
const cmpTags = [];
|
|
@@ -1615,7 +1702,7 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1615
1702
|
super(self);
|
|
1616
1703
|
self = this;
|
|
1617
1704
|
registerHost(self, cmpMeta);
|
|
1618
|
-
if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
|
|
1705
|
+
if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
|
|
1619
1706
|
// this component is using shadow dom
|
|
1620
1707
|
// and this browser supports shadow dom
|
|
1621
1708
|
// add the read-only property "shadowRoot" to the host element
|
|
@@ -1647,13 +1734,10 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1647
1734
|
return getHostRef(this).$onReadyPromise$;
|
|
1648
1735
|
}
|
|
1649
1736
|
};
|
|
1650
|
-
{
|
|
1651
|
-
patchCloneNode(HostElement.prototype);
|
|
1652
|
-
}
|
|
1653
1737
|
cmpMeta.$lazyBundleId$ = lazyBundle[0];
|
|
1654
1738
|
if (!exclude.includes(tagName) && !customElements.get(tagName)) {
|
|
1655
1739
|
cmpTags.push(tagName);
|
|
1656
|
-
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
|
|
1740
|
+
customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
|
|
1657
1741
|
}
|
|
1658
1742
|
});
|
|
1659
1743
|
});
|
|
@@ -1675,7 +1759,41 @@ const bootstrapLazy = (lazyBundles, options = {}) => {
|
|
|
1675
1759
|
// Fallback appLoad event
|
|
1676
1760
|
endBootstrap();
|
|
1677
1761
|
};
|
|
1678
|
-
const
|
|
1762
|
+
const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
|
|
1763
|
+
if (listeners) {
|
|
1764
|
+
listeners.map(([flags, name, method]) => {
|
|
1765
|
+
const target = getHostListenerTarget(elm, flags) ;
|
|
1766
|
+
const handler = hostListenerProxy(hostRef, method);
|
|
1767
|
+
const opts = hostListenerOpts(flags);
|
|
1768
|
+
plt.ael(target, name, handler, opts);
|
|
1769
|
+
(hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
|
|
1770
|
+
});
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
const hostListenerProxy = (hostRef, methodName) => (ev) => {
|
|
1774
|
+
try {
|
|
1775
|
+
{
|
|
1776
|
+
if (hostRef.$flags$ & 256 /* HOST_FLAGS.isListenReady */) {
|
|
1777
|
+
// instance is ready, let's call it's member method for this event
|
|
1778
|
+
hostRef.$lazyInstance$[methodName](ev);
|
|
1779
|
+
}
|
|
1780
|
+
else {
|
|
1781
|
+
(hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
catch (e) {
|
|
1786
|
+
consoleError(e);
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
const getHostListenerTarget = (elm, flags) => {
|
|
1790
|
+
if (flags & 8 /* LISTENER_FLAGS.TargetWindow */)
|
|
1791
|
+
return win;
|
|
1792
|
+
return elm;
|
|
1793
|
+
};
|
|
1794
|
+
// prettier-ignore
|
|
1795
|
+
const hostListenerOpts = (flags) => (flags & 2 /* LISTENER_FLAGS.Capture */) !== 0;
|
|
1796
|
+
const hostRefs = /*@__PURE__*/ new WeakMap();
|
|
1679
1797
|
const getHostRef = (ref) => hostRefs.get(ref);
|
|
1680
1798
|
const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
|
|
1681
1799
|
const registerHost = (elm, cmpMeta) => {
|
|
@@ -1720,14 +1838,35 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
1720
1838
|
return importedModule[exportName];
|
|
1721
1839
|
}, consoleError);
|
|
1722
1840
|
};
|
|
1723
|
-
const styles = new Map();
|
|
1841
|
+
const styles = /*@__PURE__*/ new Map();
|
|
1842
|
+
const win = typeof window !== 'undefined' ? window : {};
|
|
1843
|
+
const doc = win.document || { head: {} };
|
|
1844
|
+
const plt = {
|
|
1845
|
+
$flags$: 0,
|
|
1846
|
+
$resourcesUrl$: '',
|
|
1847
|
+
jmp: (h) => h(),
|
|
1848
|
+
raf: (h) => requestAnimationFrame(h),
|
|
1849
|
+
ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
|
|
1850
|
+
rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
|
|
1851
|
+
ce: (eventName, opts) => new CustomEvent(eventName, opts),
|
|
1852
|
+
};
|
|
1853
|
+
const promiseResolve = (v) => Promise.resolve(v);
|
|
1854
|
+
const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
|
|
1855
|
+
try {
|
|
1856
|
+
new CSSStyleSheet();
|
|
1857
|
+
return typeof new CSSStyleSheet().replaceSync === 'function';
|
|
1858
|
+
}
|
|
1859
|
+
catch (e) { }
|
|
1860
|
+
return false;
|
|
1861
|
+
})()
|
|
1862
|
+
;
|
|
1724
1863
|
const queueDomReads = [];
|
|
1725
1864
|
const queueDomWrites = [];
|
|
1726
1865
|
const queueTask = (queue, write) => (cb) => {
|
|
1727
1866
|
queue.push(cb);
|
|
1728
1867
|
if (!queuePending) {
|
|
1729
1868
|
queuePending = true;
|
|
1730
|
-
if (write && plt.$flags$ & 4 /* queueSync */) {
|
|
1869
|
+
if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
|
|
1731
1870
|
nextTick(flush);
|
|
1732
1871
|
}
|
|
1733
1872
|
else {
|
|
@@ -1764,4 +1903,4 @@ const flush = () => {
|
|
|
1764
1903
|
const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
|
|
1765
1904
|
const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
|
|
1766
1905
|
|
|
1767
|
-
export {
|
|
1906
|
+
export { Host as H, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r };
|