@everymatrix/general-input 1.44.0 → 1.45.2

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.
Files changed (139) hide show
  1. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  2. package/dist/cjs/checkbox-group-input_10.cjs.entry.js +3873 -1756
  3. package/dist/cjs/general-input.cjs.entry.js +65 -63
  4. package/dist/cjs/general-input.cjs.js +17 -11
  5. package/dist/cjs/index-8cb018cb.js +1316 -0
  6. package/dist/cjs/index.cjs.js +13 -13
  7. package/dist/cjs/loader.cjs.js +7 -13
  8. package/dist/cjs/locale.utils-76c75c40.js +147 -0
  9. package/dist/cjs/toggle-checkbox-input.cjs.entry.js +77 -78
  10. package/dist/collection/collection-manifest.json +14 -14
  11. package/dist/collection/components/checkbox-group-input/checkbox-group-input.js +368 -353
  12. package/dist/collection/components/checkbox-input/checkbox-input.js +325 -315
  13. package/dist/collection/components/date-input/date-input.css +2 -2
  14. package/dist/collection/components/date-input/date-input.js +397 -376
  15. package/dist/collection/components/email-input/email-input.css +7 -11
  16. package/dist/collection/components/email-input/email-input.js +404 -385
  17. package/dist/collection/components/general-input/general-input.js +373 -368
  18. package/dist/collection/components/general-input/index.js +1 -0
  19. package/dist/collection/components/number-input/number-input.js +370 -352
  20. package/dist/collection/components/password-input/password-input.css +2 -4
  21. package/dist/collection/components/password-input/password-input.js +513 -540
  22. package/dist/collection/components/radio-input/radio-input.js +301 -286
  23. package/dist/collection/components/select-input/select-input.css +8 -9
  24. package/dist/collection/components/select-input/select-input.js +427 -414
  25. package/dist/collection/components/tel-input/tel-input.css +1 -1
  26. package/dist/collection/components/tel-input/tel-input.js +440 -422
  27. package/dist/collection/components/text-input/text-input.css +0 -1
  28. package/dist/collection/components/text-input/text-input.js +444 -429
  29. package/dist/collection/components/toggle-checkbox-input/toggle-checkbox-input.js +327 -340
  30. package/dist/collection/index.js +13 -13
  31. package/dist/collection/utils/locale.utils.js +133 -133
  32. package/dist/collection/utils/utils.js +3 -3
  33. package/dist/esm/app-globals-0f993ce5.js +3 -0
  34. package/dist/esm/checkbox-group-input_10.entry.js +3873 -1756
  35. package/dist/esm/general-input.entry.js +65 -63
  36. package/dist/esm/general-input.js +14 -11
  37. package/dist/esm/index-514fda47.js +1287 -0
  38. package/dist/esm/index.js +13 -13
  39. package/dist/esm/loader.js +7 -13
  40. package/dist/esm/locale.utils-ca41bf95.js +144 -0
  41. package/dist/esm/toggle-checkbox-input.entry.js +77 -78
  42. package/dist/general-input/general-input.esm.js +1 -1
  43. package/dist/general-input/p-03e81c11.js +2 -0
  44. package/dist/general-input/p-aec71434.js +1 -0
  45. package/dist/general-input/p-e1255160.js +1 -0
  46. package/dist/general-input/p-eb454344.entry.js +1 -0
  47. package/dist/general-input/p-ecdc294b.entry.js +5430 -0
  48. package/dist/general-input/p-f92ab852.entry.js +1 -0
  49. package/dist/stencil.config.dev.js +17 -0
  50. package/dist/stencil.config.js +14 -19
  51. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/general-input/.stencil/packages/stencil/general-input/stencil.config.d.ts +2 -0
  52. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-monorepo/packages/stencil/general-input/.stencil/packages/stencil/general-input/stencil.config.dev.d.ts +2 -0
  53. package/dist/types/components/checkbox-group-input/checkbox-group-input.d.ts +68 -68
  54. package/dist/types/components/checkbox-input/checkbox-input.d.ts +61 -62
  55. package/dist/types/components/date-input/date-input.d.ts +78 -78
  56. package/dist/types/components/email-input/email-input.d.ts +77 -77
  57. package/dist/types/components/general-input/general-input.d.ts +72 -72
  58. package/dist/types/components/general-input/index.d.ts +1 -0
  59. package/dist/types/components/number-input/number-input.d.ts +71 -71
  60. package/dist/types/components/password-input/password-input.d.ts +87 -92
  61. package/dist/types/components/radio-input/radio-input.d.ts +55 -55
  62. package/dist/types/components/select-input/select-input.d.ts +79 -79
  63. package/dist/types/components/tel-input/tel-input.d.ts +85 -85
  64. package/dist/types/components/text-input/text-input.d.ts +81 -81
  65. package/dist/types/components/toggle-checkbox-input/toggle-checkbox-input.d.ts +63 -68
  66. package/dist/types/components.d.ts +201 -39
  67. package/dist/types/stencil-public-runtime.d.ts +142 -33
  68. package/dist/types/utils/locale.utils.d.ts +8 -8
  69. package/dist/types/utils/types.d.ts +54 -54
  70. package/loader/cdn.js +1 -3
  71. package/loader/index.cjs.js +1 -3
  72. package/loader/index.d.ts +13 -1
  73. package/loader/index.es2017.js +1 -3
  74. package/loader/index.js +1 -3
  75. package/loader/package.json +1 -0
  76. package/package.json +8 -1
  77. package/dist/cjs/index-132a0774.js +0 -1327
  78. package/dist/cjs/locale.utils-2fa6f747.js +0 -147
  79. package/dist/components/active-mixin.js +0 -975
  80. package/dist/components/checkbox-group-input.d.ts +0 -11
  81. package/dist/components/checkbox-group-input.js +0 -6
  82. package/dist/components/checkbox-group-input2.js +0 -1078
  83. package/dist/components/checkbox-input.d.ts +0 -11
  84. package/dist/components/checkbox-input.js +0 -6
  85. package/dist/components/checkbox-input2.js +0 -132
  86. package/dist/components/date-input.d.ts +0 -11
  87. package/dist/components/date-input.js +0 -6
  88. package/dist/components/date-input2.js +0 -11556
  89. package/dist/components/email-input.d.ts +0 -11
  90. package/dist/components/email-input.js +0 -6
  91. package/dist/components/email-input2.js +0 -171
  92. package/dist/components/field-mixin.js +0 -12426
  93. package/dist/components/general-input.d.ts +0 -11
  94. package/dist/components/general-input.js +0 -6
  95. package/dist/components/general-input2.js +0 -350
  96. package/dist/components/index.d.ts +0 -26
  97. package/dist/components/index.js +0 -18
  98. package/dist/components/input-field-shared-styles.js +0 -1211
  99. package/dist/components/number-input.d.ts +0 -11
  100. package/dist/components/number-input.js +0 -6
  101. package/dist/components/number-input2.js +0 -158
  102. package/dist/components/password-input.d.ts +0 -11
  103. package/dist/components/password-input.js +0 -6
  104. package/dist/components/password-input2.js +0 -1059
  105. package/dist/components/radio-input.d.ts +0 -11
  106. package/dist/components/radio-input.js +0 -6
  107. package/dist/components/radio-input2.js +0 -114
  108. package/dist/components/select-input.d.ts +0 -11
  109. package/dist/components/select-input.js +0 -6
  110. package/dist/components/select-input2.js +0 -183
  111. package/dist/components/tel-input.d.ts +0 -11
  112. package/dist/components/tel-input.js +0 -6
  113. package/dist/components/tel-input2.js +0 -197
  114. package/dist/components/text-input.d.ts +0 -11
  115. package/dist/components/text-input.js +0 -6
  116. package/dist/components/text-input2.js +0 -199
  117. package/dist/components/toggle-checkbox-input.d.ts +0 -11
  118. package/dist/components/toggle-checkbox-input.js +0 -6
  119. package/dist/components/tooltipIcon.js +0 -146
  120. package/dist/components/vaadin-button.js +0 -490
  121. package/dist/components/vaadin-combo-box.js +0 -4512
  122. package/dist/components/virtual-keyboard-controller.js +0 -2001
  123. package/dist/esm/index-db76d5b5.js +0 -1299
  124. package/dist/esm/locale.utils-30fb5289.js +0 -144
  125. package/dist/esm/polyfills/core-js.js +0 -11
  126. package/dist/esm/polyfills/css-shim.js +0 -1
  127. package/dist/esm/polyfills/dom.js +0 -79
  128. package/dist/esm/polyfills/es5-html-element.js +0 -1
  129. package/dist/esm/polyfills/index.js +0 -34
  130. package/dist/esm/polyfills/system.js +0 -6
  131. package/dist/general-input/p-04d4b145.js +0 -1
  132. package/dist/general-input/p-a8221ce9.entry.js +0 -1
  133. package/dist/general-input/p-b408093e.js +0 -1
  134. package/dist/general-input/p-b64caafa.entry.js +0 -3646
  135. package/dist/general-input/p-c85c0e4d.entry.js +0 -1
  136. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-stencil/packages/general-input/.stencil/packages/general-input/stencil.config.d.ts +0 -2
  137. /package/dist/cjs/{tooltipIcon-092a795f.js → tooltipIcon-7e9ee226.js} +0 -0
  138. /package/dist/esm/{tooltipIcon-99c1c7b7.js → tooltipIcon-0a5a06a2.js} +0 -0
  139. /package/dist/general-input/{p-f4f4ccda.js → p-2dccd0bf.js} +0 -0
@@ -1,1299 +0,0 @@
1
- const NAMESPACE = 'general-input';
2
-
3
- let scopeId;
4
- let hostTagName;
5
- let isSvgMode = false;
6
- let queuePending = false;
7
- const win = typeof window !== 'undefined' ? window : {};
8
- const doc = win.document || { head: {} };
9
- const plt = {
10
- $flags$: 0,
11
- $resourcesUrl$: '',
12
- jmp: (h) => h(),
13
- raf: (h) => requestAnimationFrame(h),
14
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
15
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
16
- ce: (eventName, opts) => new CustomEvent(eventName, opts),
17
- };
18
- const promiseResolve = (v) => Promise.resolve(v);
19
- const supportsConstructibleStylesheets = /*@__PURE__*/ (() => {
20
- try {
21
- new CSSStyleSheet();
22
- return typeof new CSSStyleSheet().replace === 'function';
23
- }
24
- catch (e) { }
25
- return false;
26
- })()
27
- ;
28
- const addHostEventListeners = (elm, hostRef, listeners, attachParentListeners) => {
29
- if (listeners) {
30
- listeners.map(([flags, name, method]) => {
31
- const target = getHostListenerTarget(elm, flags) ;
32
- const handler = hostListenerProxy(hostRef, method);
33
- const opts = hostListenerOpts(flags);
34
- plt.ael(target, name, handler, opts);
35
- (hostRef.$rmListeners$ = hostRef.$rmListeners$ || []).push(() => plt.rel(target, name, handler, opts));
36
- });
37
- }
38
- };
39
- const hostListenerProxy = (hostRef, methodName) => (ev) => {
40
- try {
41
- {
42
- if (hostRef.$flags$ & 256 /* isListenReady */) {
43
- // instance is ready, let's call it's member method for this event
44
- hostRef.$lazyInstance$[methodName](ev);
45
- }
46
- else {
47
- (hostRef.$queuedListeners$ = hostRef.$queuedListeners$ || []).push([methodName, ev]);
48
- }
49
- }
50
- }
51
- catch (e) {
52
- consoleError(e);
53
- }
54
- };
55
- const getHostListenerTarget = (elm, flags) => {
56
- if (flags & 4 /* TargetDocument */)
57
- return doc;
58
- if (flags & 16 /* TargetBody */)
59
- return doc.body;
60
- return elm;
61
- };
62
- // prettier-ignore
63
- const hostListenerOpts = (flags) => (flags & 2 /* Capture */) !== 0;
64
- const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
65
- const createTime = (fnName, tagName = '') => {
66
- {
67
- return () => {
68
- return;
69
- };
70
- }
71
- };
72
- const uniqueTime = (key, measureText) => {
73
- {
74
- return () => {
75
- return;
76
- };
77
- }
78
- };
79
- const rootAppliedStyles = new WeakMap();
80
- const registerStyle = (scopeId, cssText, allowCS) => {
81
- let style = styles.get(scopeId);
82
- if (supportsConstructibleStylesheets && allowCS) {
83
- style = (style || new CSSStyleSheet());
84
- style.replace(cssText);
85
- }
86
- else {
87
- style = cssText;
88
- }
89
- styles.set(scopeId, style);
90
- };
91
- const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
92
- let scopeId = getScopeId(cmpMeta);
93
- let style = styles.get(scopeId);
94
- // if an element is NOT connected then getRootNode() will return the wrong root node
95
- // so the fallback is to always use the document for the root node in those cases
96
- styleContainerNode = styleContainerNode.nodeType === 11 /* DocumentFragment */ ? styleContainerNode : doc;
97
- if (style) {
98
- if (typeof style === 'string') {
99
- styleContainerNode = styleContainerNode.head || styleContainerNode;
100
- let appliedStyles = rootAppliedStyles.get(styleContainerNode);
101
- let styleElm;
102
- if (!appliedStyles) {
103
- rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
104
- }
105
- if (!appliedStyles.has(scopeId)) {
106
- {
107
- {
108
- styleElm = doc.createElement('style');
109
- styleElm.innerHTML = style;
110
- }
111
- styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
112
- }
113
- if (appliedStyles) {
114
- appliedStyles.add(scopeId);
115
- }
116
- }
117
- }
118
- else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
119
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
120
- }
121
- }
122
- return scopeId;
123
- };
124
- const attachStyles = (hostRef) => {
125
- const cmpMeta = hostRef.$cmpMeta$;
126
- const elm = hostRef.$hostElement$;
127
- const flags = cmpMeta.$flags$;
128
- const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
129
- const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
130
- if (flags & 10 /* needsScopedEncapsulation */) {
131
- // only required when we're NOT using native shadow dom (slot)
132
- // or this browser doesn't support native shadow dom
133
- // and this host element was NOT created with SSR
134
- // let's pick out the inner content for slot projection
135
- // create a node to represent where the original
136
- // content was first placed, which is useful later on
137
- // DOM WRITE!!
138
- elm['s-sc'] = scopeId;
139
- elm.classList.add(scopeId + '-h');
140
- }
141
- endAttachStyles();
142
- };
143
- const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
144
- /**
145
- * Default style mode id
146
- */
147
- /**
148
- * Reusable empty obj/array
149
- * Don't add values to these!!
150
- */
151
- const EMPTY_OBJ = {};
152
- const isDef = (v) => v != null;
153
- const isComplexType = (o) => {
154
- // https://jsperf.com/typeof-fn-object/5
155
- o = typeof o;
156
- return o === 'object' || o === 'function';
157
- };
158
- /**
159
- * Production h() function based on Preact by
160
- * Jason Miller (@developit)
161
- * Licensed under the MIT License
162
- * https://github.com/developit/preact/blob/master/LICENSE
163
- *
164
- * Modified for Stencil's compiler and vdom
165
- */
166
- // const stack: any[] = [];
167
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
168
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
169
- const h = (nodeName, vnodeData, ...children) => {
170
- let child = null;
171
- let key = null;
172
- let simple = false;
173
- let lastSimple = false;
174
- let vNodeChildren = [];
175
- const walk = (c) => {
176
- for (let i = 0; i < c.length; i++) {
177
- child = c[i];
178
- if (Array.isArray(child)) {
179
- walk(child);
180
- }
181
- else if (child != null && typeof child !== 'boolean') {
182
- if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
183
- child = String(child);
184
- }
185
- if (simple && lastSimple) {
186
- // If the previous child was simple (string), we merge both
187
- vNodeChildren[vNodeChildren.length - 1].$text$ += child;
188
- }
189
- else {
190
- // Append a new vNode, if it's text, we create a text vNode
191
- vNodeChildren.push(simple ? newVNode(null, child) : child);
192
- }
193
- lastSimple = simple;
194
- }
195
- }
196
- };
197
- walk(children);
198
- if (vnodeData) {
199
- // normalize class / classname attributes
200
- if (vnodeData.key) {
201
- key = vnodeData.key;
202
- }
203
- {
204
- const classData = vnodeData.className || vnodeData.class;
205
- if (classData) {
206
- vnodeData.class =
207
- typeof classData !== 'object'
208
- ? classData
209
- : Object.keys(classData)
210
- .filter((k) => classData[k])
211
- .join(' ');
212
- }
213
- }
214
- }
215
- const vnode = newVNode(nodeName, null);
216
- vnode.$attrs$ = vnodeData;
217
- if (vNodeChildren.length > 0) {
218
- vnode.$children$ = vNodeChildren;
219
- }
220
- {
221
- vnode.$key$ = key;
222
- }
223
- return vnode;
224
- };
225
- const newVNode = (tag, text) => {
226
- const vnode = {
227
- $flags$: 0,
228
- $tag$: tag,
229
- $text$: text,
230
- $elm$: null,
231
- $children$: null,
232
- };
233
- {
234
- vnode.$attrs$ = null;
235
- }
236
- {
237
- vnode.$key$ = null;
238
- }
239
- return vnode;
240
- };
241
- const Host = {};
242
- const isHost = (node) => node && node.$tag$ === Host;
243
- /**
244
- * Production setAccessor() function based on Preact by
245
- * Jason Miller (@developit)
246
- * Licensed under the MIT License
247
- * https://github.com/developit/preact/blob/master/LICENSE
248
- *
249
- * Modified for Stencil's compiler and vdom
250
- */
251
- const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
252
- if (oldValue !== newValue) {
253
- let isProp = isMemberInElement(elm, memberName);
254
- let ln = memberName.toLowerCase();
255
- if (memberName === 'class') {
256
- const classList = elm.classList;
257
- const oldClasses = parseClassList(oldValue);
258
- const newClasses = parseClassList(newValue);
259
- classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
260
- classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
261
- }
262
- else if (memberName === 'key')
263
- ;
264
- else if (memberName === 'ref') {
265
- // minifier will clean this up
266
- if (newValue) {
267
- newValue(elm);
268
- }
269
- }
270
- else if ((!isProp ) &&
271
- memberName[0] === 'o' &&
272
- memberName[1] === 'n') {
273
- // Event Handlers
274
- // so if the member name starts with "on" and the 3rd characters is
275
- // a capital letter, and it's not already a member on the element,
276
- // then we're assuming it's an event listener
277
- if (memberName[2] === '-') {
278
- // on- prefixed events
279
- // allows to be explicit about the dom event to listen without any magic
280
- // under the hood:
281
- // <my-cmp on-click> // listens for "click"
282
- // <my-cmp on-Click> // listens for "Click"
283
- // <my-cmp on-ionChange> // listens for "ionChange"
284
- // <my-cmp on-EVENTS> // listens for "EVENTS"
285
- memberName = memberName.slice(3);
286
- }
287
- else if (isMemberInElement(win, ln)) {
288
- // standard event
289
- // the JSX attribute could have been "onMouseOver" and the
290
- // member name "onmouseover" is on the window's prototype
291
- // so let's add the listener "mouseover", which is all lowercased
292
- memberName = ln.slice(2);
293
- }
294
- else {
295
- // custom event
296
- // the JSX attribute could have been "onMyCustomEvent"
297
- // so let's trim off the "on" prefix and lowercase the first character
298
- // and add the listener "myCustomEvent"
299
- // except for the first character, we keep the event name case
300
- memberName = ln[2] + memberName.slice(3);
301
- }
302
- if (oldValue) {
303
- plt.rel(elm, memberName, oldValue, false);
304
- }
305
- if (newValue) {
306
- plt.ael(elm, memberName, newValue, false);
307
- }
308
- }
309
- else {
310
- // Set property if it exists and it's not a SVG
311
- const isComplex = isComplexType(newValue);
312
- if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
313
- try {
314
- if (!elm.tagName.includes('-')) {
315
- let n = newValue == null ? '' : newValue;
316
- // Workaround for Safari, moving the <input> caret when re-assigning the same valued
317
- if (memberName === 'list') {
318
- isProp = false;
319
- }
320
- else if (oldValue == null || elm[memberName] != n) {
321
- elm[memberName] = n;
322
- }
323
- }
324
- else {
325
- elm[memberName] = newValue;
326
- }
327
- }
328
- catch (e) { }
329
- }
330
- if (newValue == null || newValue === false) {
331
- if (newValue !== false || elm.getAttribute(memberName) === '') {
332
- {
333
- elm.removeAttribute(memberName);
334
- }
335
- }
336
- }
337
- else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
338
- newValue = newValue === true ? '' : newValue;
339
- {
340
- elm.setAttribute(memberName, newValue);
341
- }
342
- }
343
- }
344
- }
345
- };
346
- const parseClassListRegex = /\s/;
347
- const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
348
- const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
349
- // if the element passed in is a shadow root, which is a document fragment
350
- // then we want to be adding attrs/props to the shadow root's "host" element
351
- // if it's not a shadow root, then we add attrs/props to the same element
352
- const elm = newVnode.$elm$.nodeType === 11 /* DocumentFragment */ && newVnode.$elm$.host
353
- ? newVnode.$elm$.host
354
- : newVnode.$elm$;
355
- const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
356
- const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
357
- {
358
- // remove attributes no longer present on the vnode by setting them to undefined
359
- for (memberName in oldVnodeAttrs) {
360
- if (!(memberName in newVnodeAttrs)) {
361
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
362
- }
363
- }
364
- }
365
- // add new & update changed attributes
366
- for (memberName in newVnodeAttrs) {
367
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
368
- }
369
- };
370
- const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
371
- // tslint:disable-next-line: prefer-const
372
- let newVNode = newParentVNode.$children$[childIndex];
373
- let i = 0;
374
- let elm;
375
- let childNode;
376
- if (newVNode.$text$ !== null) {
377
- // create text node
378
- elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
379
- }
380
- else {
381
- // create element
382
- elm = newVNode.$elm$ = (doc.createElement(newVNode.$tag$));
383
- // add css classes, attrs, props, listeners, etc.
384
- {
385
- updateElement(null, newVNode, isSvgMode);
386
- }
387
- if (isDef(scopeId) && elm['s-si'] !== scopeId) {
388
- // if there is a scopeId and this is the initial render
389
- // then let's add the scopeId as a css class
390
- elm.classList.add((elm['s-si'] = scopeId));
391
- }
392
- if (newVNode.$children$) {
393
- for (i = 0; i < newVNode.$children$.length; ++i) {
394
- // create the node
395
- childNode = createElm(oldParentVNode, newVNode, i);
396
- // return node could have been null
397
- if (childNode) {
398
- // append our new node
399
- elm.appendChild(childNode);
400
- }
401
- }
402
- }
403
- }
404
- return elm;
405
- };
406
- const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
407
- let containerElm = (parentElm);
408
- let childNode;
409
- if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
410
- containerElm = containerElm.shadowRoot;
411
- }
412
- for (; startIdx <= endIdx; ++startIdx) {
413
- if (vnodes[startIdx]) {
414
- childNode = createElm(null, parentVNode, startIdx);
415
- if (childNode) {
416
- vnodes[startIdx].$elm$ = childNode;
417
- containerElm.insertBefore(childNode, before);
418
- }
419
- }
420
- }
421
- };
422
- const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
423
- for (; startIdx <= endIdx; ++startIdx) {
424
- if ((vnode = vnodes[startIdx])) {
425
- elm = vnode.$elm$;
426
- callNodeRefs(vnode);
427
- // remove the vnode's element from the dom
428
- elm.remove();
429
- }
430
- }
431
- };
432
- const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
433
- let oldStartIdx = 0;
434
- let newStartIdx = 0;
435
- let idxInOld = 0;
436
- let i = 0;
437
- let oldEndIdx = oldCh.length - 1;
438
- let oldStartVnode = oldCh[0];
439
- let oldEndVnode = oldCh[oldEndIdx];
440
- let newEndIdx = newCh.length - 1;
441
- let newStartVnode = newCh[0];
442
- let newEndVnode = newCh[newEndIdx];
443
- let node;
444
- let elmToMove;
445
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
446
- if (oldStartVnode == null) {
447
- // Vnode might have been moved left
448
- oldStartVnode = oldCh[++oldStartIdx];
449
- }
450
- else if (oldEndVnode == null) {
451
- oldEndVnode = oldCh[--oldEndIdx];
452
- }
453
- else if (newStartVnode == null) {
454
- newStartVnode = newCh[++newStartIdx];
455
- }
456
- else if (newEndVnode == null) {
457
- newEndVnode = newCh[--newEndIdx];
458
- }
459
- else if (isSameVnode(oldStartVnode, newStartVnode)) {
460
- patch(oldStartVnode, newStartVnode);
461
- oldStartVnode = oldCh[++oldStartIdx];
462
- newStartVnode = newCh[++newStartIdx];
463
- }
464
- else if (isSameVnode(oldEndVnode, newEndVnode)) {
465
- patch(oldEndVnode, newEndVnode);
466
- oldEndVnode = oldCh[--oldEndIdx];
467
- newEndVnode = newCh[--newEndIdx];
468
- }
469
- else if (isSameVnode(oldStartVnode, newEndVnode)) {
470
- patch(oldStartVnode, newEndVnode);
471
- parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
472
- oldStartVnode = oldCh[++oldStartIdx];
473
- newEndVnode = newCh[--newEndIdx];
474
- }
475
- else if (isSameVnode(oldEndVnode, newStartVnode)) {
476
- patch(oldEndVnode, newStartVnode);
477
- parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
478
- oldEndVnode = oldCh[--oldEndIdx];
479
- newStartVnode = newCh[++newStartIdx];
480
- }
481
- else {
482
- // createKeyToOldIdx
483
- idxInOld = -1;
484
- {
485
- for (i = oldStartIdx; i <= oldEndIdx; ++i) {
486
- if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
487
- idxInOld = i;
488
- break;
489
- }
490
- }
491
- }
492
- if (idxInOld >= 0) {
493
- elmToMove = oldCh[idxInOld];
494
- if (elmToMove.$tag$ !== newStartVnode.$tag$) {
495
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld);
496
- }
497
- else {
498
- patch(elmToMove, newStartVnode);
499
- oldCh[idxInOld] = undefined;
500
- node = elmToMove.$elm$;
501
- }
502
- newStartVnode = newCh[++newStartIdx];
503
- }
504
- else {
505
- // new element
506
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx);
507
- newStartVnode = newCh[++newStartIdx];
508
- }
509
- if (node) {
510
- {
511
- oldStartVnode.$elm$.parentNode.insertBefore(node, oldStartVnode.$elm$);
512
- }
513
- }
514
- }
515
- }
516
- if (oldStartIdx > oldEndIdx) {
517
- addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
518
- }
519
- else if (newStartIdx > newEndIdx) {
520
- removeVnodes(oldCh, oldStartIdx, oldEndIdx);
521
- }
522
- };
523
- const isSameVnode = (vnode1, vnode2) => {
524
- // compare if two vnode to see if they're "technically" the same
525
- // need to have the same element tag, and same key to be the same
526
- if (vnode1.$tag$ === vnode2.$tag$) {
527
- {
528
- return vnode1.$key$ === vnode2.$key$;
529
- }
530
- }
531
- return false;
532
- };
533
- const patch = (oldVNode, newVNode) => {
534
- const elm = (newVNode.$elm$ = oldVNode.$elm$);
535
- const oldChildren = oldVNode.$children$;
536
- const newChildren = newVNode.$children$;
537
- const text = newVNode.$text$;
538
- if (text === null) {
539
- // element node
540
- {
541
- {
542
- // either this is the first render of an element OR it's an update
543
- // AND we already know it's possible it could have changed
544
- // this updates the element's css classes, attrs, props, listeners, etc.
545
- updateElement(oldVNode, newVNode, isSvgMode);
546
- }
547
- }
548
- if (oldChildren !== null && newChildren !== null) {
549
- // looks like there's child vnodes for both the old and new vnodes
550
- updateChildren(elm, oldChildren, newVNode, newChildren);
551
- }
552
- else if (newChildren !== null) {
553
- // no old child vnodes, but there are new child vnodes to add
554
- if (oldVNode.$text$ !== null) {
555
- // the old vnode was text, so be sure to clear it out
556
- elm.textContent = '';
557
- }
558
- // add the new vnode children
559
- addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
560
- }
561
- else if (oldChildren !== null) {
562
- // no new child vnodes, but there are old child vnodes to remove
563
- removeVnodes(oldChildren, 0, oldChildren.length - 1);
564
- }
565
- }
566
- else if (oldVNode.$text$ !== text) {
567
- // update the text content for the text only vnode
568
- // and also only if the text is different than before
569
- elm.data = text;
570
- }
571
- };
572
- const callNodeRefs = (vNode) => {
573
- {
574
- vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
575
- vNode.$children$ && vNode.$children$.map(callNodeRefs);
576
- }
577
- };
578
- const renderVdom = (hostRef, renderFnResults) => {
579
- const hostElm = hostRef.$hostElement$;
580
- const cmpMeta = hostRef.$cmpMeta$;
581
- const oldVNode = hostRef.$vnode$ || newVNode(null, null);
582
- const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
583
- hostTagName = hostElm.tagName;
584
- if (cmpMeta.$attrsToReflect$) {
585
- rootVnode.$attrs$ = rootVnode.$attrs$ || {};
586
- cmpMeta.$attrsToReflect$.map(([propName, attribute]) => (rootVnode.$attrs$[attribute] = hostElm[propName]));
587
- }
588
- rootVnode.$tag$ = null;
589
- rootVnode.$flags$ |= 4 /* isHost */;
590
- hostRef.$vnode$ = rootVnode;
591
- rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
592
- {
593
- scopeId = hostElm['s-sc'];
594
- }
595
- // synchronous patch
596
- patch(oldVNode, rootVnode);
597
- };
598
- const getElement = (ref) => (getHostRef(ref).$hostElement$ );
599
- const createEvent = (ref, name, flags) => {
600
- const elm = getElement(ref);
601
- return {
602
- emit: (detail) => {
603
- return emitEvent(elm, name, {
604
- bubbles: !!(flags & 4 /* Bubbles */),
605
- composed: !!(flags & 2 /* Composed */),
606
- cancelable: !!(flags & 1 /* Cancellable */),
607
- detail,
608
- });
609
- },
610
- };
611
- };
612
- /**
613
- * Helper function to create & dispatch a custom Event on a provided target
614
- * @param elm the target of the Event
615
- * @param name the name to give the custom Event
616
- * @param opts options for configuring a custom Event
617
- * @returns the custom Event
618
- */
619
- const emitEvent = (elm, name, opts) => {
620
- const ev = plt.ce(name, opts);
621
- elm.dispatchEvent(ev);
622
- return ev;
623
- };
624
- const attachToAncestor = (hostRef, ancestorComponent) => {
625
- if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
626
- ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
627
- }
628
- };
629
- const scheduleUpdate = (hostRef, isInitialLoad) => {
630
- {
631
- hostRef.$flags$ |= 16 /* isQueuedForUpdate */;
632
- }
633
- if (hostRef.$flags$ & 4 /* isWaitingForChildren */) {
634
- hostRef.$flags$ |= 512 /* needsRerender */;
635
- return;
636
- }
637
- attachToAncestor(hostRef, hostRef.$ancestorComponent$);
638
- // there is no ancestor component or the ancestor component
639
- // has already fired off its lifecycle update then
640
- // fire off the initial update
641
- const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
642
- return writeTask(dispatch) ;
643
- };
644
- const dispatchHooks = (hostRef, isInitialLoad) => {
645
- const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
646
- const instance = hostRef.$lazyInstance$ ;
647
- let promise;
648
- if (isInitialLoad) {
649
- {
650
- hostRef.$flags$ |= 256 /* isListenReady */;
651
- if (hostRef.$queuedListeners$) {
652
- hostRef.$queuedListeners$.map(([methodName, event]) => safeCall(instance, methodName, event));
653
- hostRef.$queuedListeners$ = null;
654
- }
655
- }
656
- {
657
- promise = safeCall(instance, 'componentWillLoad');
658
- }
659
- }
660
- endSchedule();
661
- return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
662
- };
663
- const updateComponent = async (hostRef, instance, isInitialLoad) => {
664
- // updateComponent
665
- const elm = hostRef.$hostElement$;
666
- const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
667
- const rc = elm['s-rc'];
668
- if (isInitialLoad) {
669
- // DOM WRITE!
670
- attachStyles(hostRef);
671
- }
672
- const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
673
- {
674
- callRender(hostRef, instance);
675
- }
676
- if (rc) {
677
- // ok, so turns out there are some child host elements
678
- // waiting on this parent element to load
679
- // let's fire off all update callbacks waiting
680
- rc.map((cb) => cb());
681
- elm['s-rc'] = undefined;
682
- }
683
- endRender();
684
- endUpdate();
685
- {
686
- const childrenPromises = elm['s-p'];
687
- const postUpdate = () => postUpdateComponent(hostRef);
688
- if (childrenPromises.length === 0) {
689
- postUpdate();
690
- }
691
- else {
692
- Promise.all(childrenPromises).then(postUpdate);
693
- hostRef.$flags$ |= 4 /* isWaitingForChildren */;
694
- childrenPromises.length = 0;
695
- }
696
- }
697
- };
698
- const callRender = (hostRef, instance, elm) => {
699
- try {
700
- instance = instance.render() ;
701
- {
702
- hostRef.$flags$ &= ~16 /* isQueuedForUpdate */;
703
- }
704
- {
705
- hostRef.$flags$ |= 2 /* hasRendered */;
706
- }
707
- {
708
- {
709
- // looks like we've got child nodes to render into this host element
710
- // or we need to update the css class/attrs on the host element
711
- // DOM WRITE!
712
- {
713
- renderVdom(hostRef, instance);
714
- }
715
- }
716
- }
717
- }
718
- catch (e) {
719
- consoleError(e, hostRef.$hostElement$);
720
- }
721
- return null;
722
- };
723
- const postUpdateComponent = (hostRef) => {
724
- const tagName = hostRef.$cmpMeta$.$tagName$;
725
- const elm = hostRef.$hostElement$;
726
- const endPostUpdate = createTime('postUpdate', tagName);
727
- const instance = hostRef.$lazyInstance$ ;
728
- const ancestorComponent = hostRef.$ancestorComponent$;
729
- {
730
- safeCall(instance, 'componentDidRender');
731
- }
732
- if (!(hostRef.$flags$ & 64 /* hasLoadedComponent */)) {
733
- hostRef.$flags$ |= 64 /* hasLoadedComponent */;
734
- {
735
- // DOM WRITE!
736
- addHydratedFlag(elm);
737
- }
738
- {
739
- safeCall(instance, 'componentDidLoad');
740
- }
741
- endPostUpdate();
742
- {
743
- hostRef.$onReadyResolve$(elm);
744
- if (!ancestorComponent) {
745
- appDidLoad();
746
- }
747
- }
748
- }
749
- else {
750
- endPostUpdate();
751
- }
752
- // load events fire from bottom to top
753
- // the deepest elements load first then bubbles up
754
- {
755
- if (hostRef.$onRenderResolve$) {
756
- hostRef.$onRenderResolve$();
757
- hostRef.$onRenderResolve$ = undefined;
758
- }
759
- if (hostRef.$flags$ & 512 /* needsRerender */) {
760
- nextTick(() => scheduleUpdate(hostRef, false));
761
- }
762
- hostRef.$flags$ &= ~(4 /* isWaitingForChildren */ | 512 /* needsRerender */);
763
- }
764
- // ( •_•)
765
- // ( •_•)>⌐■-■
766
- // (⌐■_■)
767
- };
768
- const appDidLoad = (who) => {
769
- // on appload
770
- // we have finish the first big initial render
771
- {
772
- addHydratedFlag(doc.documentElement);
773
- }
774
- nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
775
- };
776
- const safeCall = (instance, method, arg) => {
777
- if (instance && instance[method]) {
778
- try {
779
- return instance[method](arg);
780
- }
781
- catch (e) {
782
- consoleError(e);
783
- }
784
- }
785
- return undefined;
786
- };
787
- const then = (promise, thenFn) => {
788
- return promise && promise.then ? promise.then(thenFn) : thenFn();
789
- };
790
- const addHydratedFlag = (elm) => elm.classList.add('hydrated')
791
- ;
792
- /**
793
- * Parse a new property value for a given property type.
794
- *
795
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
796
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
797
- * 1. `any`, the type given to `propValue` in the function signature
798
- * 2. the type stored from `propType`.
799
- *
800
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
801
- *
802
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
803
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
804
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
805
- * ```tsx
806
- * <my-cmp prop-val={0}></my-cmp>
807
- * ```
808
- *
809
- * HTML prop values on the other hand, will always a string
810
- *
811
- * @param propValue the new value to coerce to some type
812
- * @param propType the type of the prop, expressed as a binary number
813
- * @returns the parsed/coerced value
814
- */
815
- const parsePropertyValue = (propValue, propType) => {
816
- // ensure this value is of the correct prop type
817
- if (propValue != null && !isComplexType(propValue)) {
818
- if (propType & 4 /* Boolean */) {
819
- // per the HTML spec, any string value means it is a boolean true value
820
- // but we'll cheat here and say that the string "false" is the boolean false
821
- return propValue === 'false' ? false : propValue === '' || !!propValue;
822
- }
823
- if (propType & 1 /* String */) {
824
- // could have been passed as a number or boolean
825
- // but we still want it as a string
826
- return String(propValue);
827
- }
828
- // redundant return here for better minification
829
- return propValue;
830
- }
831
- // not sure exactly what type we want
832
- // so no need to change to a different type
833
- return propValue;
834
- };
835
- const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
836
- const setValue = (ref, propName, newVal, cmpMeta) => {
837
- // check our new property value against our internal value
838
- const hostRef = getHostRef(ref);
839
- const elm = hostRef.$hostElement$ ;
840
- const oldVal = hostRef.$instanceValues$.get(propName);
841
- const flags = hostRef.$flags$;
842
- const instance = hostRef.$lazyInstance$ ;
843
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
844
- // explicitly check for NaN on both sides, as `NaN === NaN` is always false
845
- const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
846
- const didValueChange = newVal !== oldVal && !areBothNaN;
847
- if ((!(flags & 8 /* isConstructingInstance */) || oldVal === undefined) && didValueChange) {
848
- // gadzooks! the property's value has changed!!
849
- // set our new value!
850
- hostRef.$instanceValues$.set(propName, newVal);
851
- if (instance) {
852
- // get an array of method names of watch functions to call
853
- if (cmpMeta.$watchers$ && flags & 128 /* isWatchReady */) {
854
- const watchMethods = cmpMeta.$watchers$[propName];
855
- if (watchMethods) {
856
- // this instance is watching for when this property changed
857
- watchMethods.map((watchMethodName) => {
858
- try {
859
- // fire off each of the watch methods that are watching this property
860
- instance[watchMethodName](newVal, oldVal, propName);
861
- }
862
- catch (e) {
863
- consoleError(e, elm);
864
- }
865
- });
866
- }
867
- }
868
- if ((flags & (2 /* hasRendered */ | 16 /* isQueuedForUpdate */)) === 2 /* hasRendered */) {
869
- // looks like this value actually changed, so we've got work to do!
870
- // but only if we've already rendered, otherwise just chill out
871
- // queue that we need to do an update, but don't worry about queuing
872
- // up millions cuz this function ensures it only runs once
873
- scheduleUpdate(hostRef, false);
874
- }
875
- }
876
- }
877
- };
878
- const proxyComponent = (Cstr, cmpMeta, flags) => {
879
- if (cmpMeta.$members$) {
880
- if (Cstr.watchers) {
881
- cmpMeta.$watchers$ = Cstr.watchers;
882
- }
883
- // It's better to have a const than two Object.entries()
884
- const members = Object.entries(cmpMeta.$members$);
885
- const prototype = Cstr.prototype;
886
- members.map(([memberName, [memberFlags]]) => {
887
- if ((memberFlags & 31 /* Prop */ ||
888
- ((flags & 2 /* proxyState */) && memberFlags & 32 /* State */))) {
889
- // proxyComponent - prop
890
- Object.defineProperty(prototype, memberName, {
891
- get() {
892
- // proxyComponent, get value
893
- return getValue(this, memberName);
894
- },
895
- set(newValue) {
896
- // proxyComponent, set value
897
- setValue(this, memberName, newValue, cmpMeta);
898
- },
899
- configurable: true,
900
- enumerable: true,
901
- });
902
- }
903
- });
904
- if ((flags & 1 /* isElementConstructor */)) {
905
- const attrNameToPropName = new Map();
906
- prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
907
- plt.jmp(() => {
908
- const propName = attrNameToPropName.get(attrName);
909
- // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
910
- // in the case where an attribute was set inline.
911
- // ```html
912
- // <my-component some-attribute="some-value"></my-component>
913
- // ```
914
- //
915
- // There is an edge case where a developer sets the attribute inline on a custom element and then
916
- // programmatically changes it before it has been upgraded as shown below:
917
- //
918
- // ```html
919
- // <!-- this component has _not_ been upgraded yet -->
920
- // <my-component id="test" some-attribute="some-value"></my-component>
921
- // <script>
922
- // // grab non-upgraded component
923
- // el = document.querySelector("#test");
924
- // el.someAttribute = "another-value";
925
- // // upgrade component
926
- // customElements.define('my-component', MyComponent);
927
- // </script>
928
- // ```
929
- // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
930
- // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
931
- // to the value that was set inline i.e. "some-value" from above example. When
932
- // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
933
- //
934
- // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
935
- // by connectedCallback as this attributeChangedCallback will not fire.
936
- //
937
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
938
- //
939
- // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
940
- // properties here given that this goes against best practices outlined here
941
- // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
942
- if (this.hasOwnProperty(propName)) {
943
- newValue = this[propName];
944
- delete this[propName];
945
- }
946
- else if (prototype.hasOwnProperty(propName) &&
947
- typeof this[propName] === 'number' &&
948
- this[propName] == newValue) {
949
- // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
950
- // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
951
- // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
952
- return;
953
- }
954
- this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
955
- });
956
- };
957
- // create an array of attributes to observe
958
- // and also create a map of html attribute name to js property name
959
- Cstr.observedAttributes = members
960
- .filter(([_, m]) => m[0] & 15 /* HasAttribute */) // filter to only keep props that should match attributes
961
- .map(([propName, m]) => {
962
- const attrName = m[1] || propName;
963
- attrNameToPropName.set(attrName, propName);
964
- if (m[0] & 512 /* ReflectAttr */) {
965
- cmpMeta.$attrsToReflect$.push([propName, attrName]);
966
- }
967
- return attrName;
968
- });
969
- }
970
- }
971
- return Cstr;
972
- };
973
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
974
- // initializeComponent
975
- if ((hostRef.$flags$ & 32 /* hasInitializedComponent */) === 0) {
976
- {
977
- // we haven't initialized this element yet
978
- hostRef.$flags$ |= 32 /* hasInitializedComponent */;
979
- // lazy loaded components
980
- // request the component's implementation to be
981
- // wired up with the host element
982
- Cstr = loadModule(cmpMeta);
983
- if (Cstr.then) {
984
- // Await creates a micro-task avoid if possible
985
- const endLoad = uniqueTime();
986
- Cstr = await Cstr;
987
- endLoad();
988
- }
989
- if (!Cstr.isProxied) {
990
- // we've never proxied this Constructor before
991
- // let's add the getters/setters to its prototype before
992
- // the first time we create an instance of the implementation
993
- {
994
- cmpMeta.$watchers$ = Cstr.watchers;
995
- }
996
- proxyComponent(Cstr, cmpMeta, 2 /* proxyState */);
997
- Cstr.isProxied = true;
998
- }
999
- const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1000
- // ok, time to construct the instance
1001
- // but let's keep track of when we start and stop
1002
- // so that the getters/setters don't incorrectly step on data
1003
- {
1004
- hostRef.$flags$ |= 8 /* isConstructingInstance */;
1005
- }
1006
- // construct the lazy-loaded component implementation
1007
- // passing the hostRef is very important during
1008
- // construction in order to directly wire together the
1009
- // host element and the lazy-loaded instance
1010
- try {
1011
- new Cstr(hostRef);
1012
- }
1013
- catch (e) {
1014
- consoleError(e);
1015
- }
1016
- {
1017
- hostRef.$flags$ &= ~8 /* isConstructingInstance */;
1018
- }
1019
- {
1020
- hostRef.$flags$ |= 128 /* isWatchReady */;
1021
- }
1022
- endNewInstance();
1023
- fireConnectedCallback(hostRef.$lazyInstance$);
1024
- }
1025
- if (Cstr.style) {
1026
- // this component has styles but we haven't registered them yet
1027
- let style = Cstr.style;
1028
- const scopeId = getScopeId(cmpMeta);
1029
- if (!styles.has(scopeId)) {
1030
- const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1031
- registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */));
1032
- endRegisterStyles();
1033
- }
1034
- }
1035
- }
1036
- // we've successfully created a lazy instance
1037
- const ancestorComponent = hostRef.$ancestorComponent$;
1038
- const schedule = () => scheduleUpdate(hostRef, true);
1039
- if (ancestorComponent && ancestorComponent['s-rc']) {
1040
- // this is the initial load and this component it has an ancestor component
1041
- // but the ancestor component has NOT fired its will update lifecycle yet
1042
- // so let's just cool our jets and wait for the ancestor to continue first
1043
- // this will get fired off when the ancestor component
1044
- // finally gets around to rendering its lazy self
1045
- // fire off the initial update
1046
- ancestorComponent['s-rc'].push(schedule);
1047
- }
1048
- else {
1049
- schedule();
1050
- }
1051
- };
1052
- const fireConnectedCallback = (instance) => {
1053
- {
1054
- safeCall(instance, 'connectedCallback');
1055
- }
1056
- };
1057
- const connectedCallback = (elm) => {
1058
- if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1059
- const hostRef = getHostRef(elm);
1060
- const cmpMeta = hostRef.$cmpMeta$;
1061
- const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1062
- if (!(hostRef.$flags$ & 1 /* hasConnected */)) {
1063
- // first time this component has connected
1064
- hostRef.$flags$ |= 1 /* hasConnected */;
1065
- {
1066
- // find the first ancestor component (if there is one) and register
1067
- // this component as one of the actively loading child components for its ancestor
1068
- let ancestorComponent = elm;
1069
- while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1070
- // climb up the ancestors looking for the first
1071
- // component that hasn't finished its lifecycle update yet
1072
- if (ancestorComponent['s-p']) {
1073
- // we found this components first ancestor component
1074
- // keep a reference to this component's ancestor component
1075
- attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1076
- break;
1077
- }
1078
- }
1079
- }
1080
- // Lazy properties
1081
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1082
- if (cmpMeta.$members$) {
1083
- Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1084
- if (memberFlags & 31 /* Prop */ && elm.hasOwnProperty(memberName)) {
1085
- const value = elm[memberName];
1086
- delete elm[memberName];
1087
- elm[memberName] = value;
1088
- }
1089
- });
1090
- }
1091
- {
1092
- initializeComponent(elm, hostRef, cmpMeta);
1093
- }
1094
- }
1095
- else {
1096
- // not the first time this has connected
1097
- // reattach any event listeners to the host
1098
- // since they would have been removed when disconnected
1099
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
1100
- // fire off connectedCallback() on component instance
1101
- fireConnectedCallback(hostRef.$lazyInstance$);
1102
- }
1103
- endConnected();
1104
- }
1105
- };
1106
- const disconnectedCallback = (elm) => {
1107
- if ((plt.$flags$ & 1 /* isTmpDisconnected */) === 0) {
1108
- const hostRef = getHostRef(elm);
1109
- {
1110
- if (hostRef.$rmListeners$) {
1111
- hostRef.$rmListeners$.map((rmListener) => rmListener());
1112
- hostRef.$rmListeners$ = undefined;
1113
- }
1114
- }
1115
- }
1116
- };
1117
- const bootstrapLazy = (lazyBundles, options = {}) => {
1118
- const endBootstrap = createTime();
1119
- const cmpTags = [];
1120
- const exclude = options.exclude || [];
1121
- const customElements = win.customElements;
1122
- const head = doc.head;
1123
- const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1124
- const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
1125
- const deferredConnectedCallbacks = [];
1126
- let appLoadFallback;
1127
- let isBootstrapping = true;
1128
- Object.assign(plt, options);
1129
- plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1130
- lazyBundles.map((lazyBundle) => {
1131
- lazyBundle[1].map((compactMeta) => {
1132
- const cmpMeta = {
1133
- $flags$: compactMeta[0],
1134
- $tagName$: compactMeta[1],
1135
- $members$: compactMeta[2],
1136
- $listeners$: compactMeta[3],
1137
- };
1138
- {
1139
- cmpMeta.$members$ = compactMeta[2];
1140
- }
1141
- {
1142
- cmpMeta.$listeners$ = compactMeta[3];
1143
- }
1144
- {
1145
- cmpMeta.$attrsToReflect$ = [];
1146
- }
1147
- {
1148
- cmpMeta.$watchers$ = {};
1149
- }
1150
- const tagName = cmpMeta.$tagName$;
1151
- const HostElement = class extends HTMLElement {
1152
- // StencilLazyHost
1153
- constructor(self) {
1154
- // @ts-ignore
1155
- super(self);
1156
- self = this;
1157
- registerHost(self, cmpMeta);
1158
- if (cmpMeta.$flags$ & 1 /* shadowDomEncapsulation */) {
1159
- // this component is using shadow dom
1160
- // and this browser supports shadow dom
1161
- // add the read-only property "shadowRoot" to the host element
1162
- // adding the shadow root build conditionals to minimize runtime
1163
- {
1164
- {
1165
- self.attachShadow({ mode: 'open' });
1166
- }
1167
- }
1168
- }
1169
- }
1170
- connectedCallback() {
1171
- if (appLoadFallback) {
1172
- clearTimeout(appLoadFallback);
1173
- appLoadFallback = null;
1174
- }
1175
- if (isBootstrapping) {
1176
- // connectedCallback will be processed once all components have been registered
1177
- deferredConnectedCallbacks.push(this);
1178
- }
1179
- else {
1180
- plt.jmp(() => connectedCallback(this));
1181
- }
1182
- }
1183
- disconnectedCallback() {
1184
- plt.jmp(() => disconnectedCallback(this));
1185
- }
1186
- componentOnReady() {
1187
- return getHostRef(this).$onReadyPromise$;
1188
- }
1189
- };
1190
- cmpMeta.$lazyBundleId$ = lazyBundle[0];
1191
- if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1192
- cmpTags.push(tagName);
1193
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* isElementConstructor */));
1194
- }
1195
- });
1196
- });
1197
- {
1198
- visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1199
- visibilityStyle.setAttribute('data-styles', '');
1200
- head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1201
- }
1202
- // Process deferred connectedCallbacks now all components have been registered
1203
- isBootstrapping = false;
1204
- if (deferredConnectedCallbacks.length) {
1205
- deferredConnectedCallbacks.map((host) => host.connectedCallback());
1206
- }
1207
- else {
1208
- {
1209
- plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1210
- }
1211
- }
1212
- // Fallback appLoad event
1213
- endBootstrap();
1214
- };
1215
- const hostRefs = new WeakMap();
1216
- const getHostRef = (ref) => hostRefs.get(ref);
1217
- const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1218
- const registerHost = (elm, cmpMeta) => {
1219
- const hostRef = {
1220
- $flags$: 0,
1221
- $hostElement$: elm,
1222
- $cmpMeta$: cmpMeta,
1223
- $instanceValues$: new Map(),
1224
- };
1225
- {
1226
- hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1227
- elm['s-p'] = [];
1228
- elm['s-rc'] = [];
1229
- }
1230
- addHostEventListeners(elm, hostRef, cmpMeta.$listeners$);
1231
- return hostRefs.set(elm, hostRef);
1232
- };
1233
- const isMemberInElement = (elm, memberName) => memberName in elm;
1234
- const consoleError = (e, el) => (0, console.error)(e, el);
1235
- const cmpModules = /*@__PURE__*/ new Map();
1236
- const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1237
- // loadModuleImport
1238
- const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1239
- const bundleId = cmpMeta.$lazyBundleId$;
1240
- const module = cmpModules.get(bundleId) ;
1241
- if (module) {
1242
- return module[exportName];
1243
- }
1244
- return import(
1245
- /* webpackInclude: /\.entry\.js$/ */
1246
- /* webpackExclude: /\.system\.entry\.js$/ */
1247
- /* webpackMode: "lazy" */
1248
- `./${bundleId}.entry.js${''}`).then((importedModule) => {
1249
- {
1250
- cmpModules.set(bundleId, importedModule);
1251
- }
1252
- return importedModule[exportName];
1253
- }, consoleError);
1254
- };
1255
- const styles = new Map();
1256
- const queueDomReads = [];
1257
- const queueDomWrites = [];
1258
- const queueTask = (queue, write) => (cb) => {
1259
- queue.push(cb);
1260
- if (!queuePending) {
1261
- queuePending = true;
1262
- if (write && plt.$flags$ & 4 /* queueSync */) {
1263
- nextTick(flush);
1264
- }
1265
- else {
1266
- plt.raf(flush);
1267
- }
1268
- }
1269
- };
1270
- const consume = (queue) => {
1271
- for (let i = 0; i < queue.length; i++) {
1272
- try {
1273
- queue[i](performance.now());
1274
- }
1275
- catch (e) {
1276
- consoleError(e);
1277
- }
1278
- }
1279
- queue.length = 0;
1280
- };
1281
- const flush = () => {
1282
- // always force a bunch of medium callbacks to run, but still have
1283
- // a throttle on how many can run in a certain time
1284
- // DOM READS!!!
1285
- consume(queueDomReads);
1286
- // DOM WRITES!!!
1287
- {
1288
- consume(queueDomWrites);
1289
- if ((queuePending = queueDomReads.length > 0)) {
1290
- // still more to do yet, but we've run out of time
1291
- // let's let this thing cool off and try again in the next tick
1292
- plt.raf(flush);
1293
- }
1294
- }
1295
- };
1296
- const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
1297
- const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1298
-
1299
- export { Host as H, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r };