@sankhyalabs/sankhyablocks 1.3.31-beta.16 → 1.3.31-beta.17

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 (170) hide show
  1. package/dist/cjs/{SnkMessageBuilder-79cf15c5.js → SnkMessageBuilder-cb132e6d.js} +133 -1
  2. package/dist/cjs/app-globals-3a1e7e63.js +5 -0
  3. package/dist/cjs/css-shim-b8158822.js +6 -0
  4. package/dist/cjs/dom-36862b77.js +75 -0
  5. package/dist/cjs/filter-item-type.enum-e2e1bc5b.js +14 -0
  6. package/dist/cjs/index-02201bc9.js +2397 -0
  7. package/dist/cjs/{index-5575fe3d.js → index-b0b676c5.js} +1598 -145
  8. package/dist/cjs/loader.cjs.js +18 -2
  9. package/dist/cjs/sankhyablocks.cjs.js +116 -4
  10. package/dist/cjs/shadow-css-346c0795.js +389 -0
  11. package/dist/cjs/snk-application.cjs.entry.js +542 -66
  12. package/dist/cjs/snk-crud.cjs.entry.js +1 -1
  13. package/dist/cjs/snk-data-unit.cjs.entry.js +23 -24
  14. package/dist/cjs/snk-filter-bar.cjs.entry.js +199 -0
  15. package/dist/cjs/snk-filter-binary-select.cjs.entry.js +47 -0
  16. package/dist/cjs/snk-filter-detail.cjs.entry.js +44 -0
  17. package/dist/cjs/snk-filter-item.cjs.entry.js +131 -0
  18. package/dist/cjs/snk-filter-list.cjs.entry.js +91 -0
  19. package/dist/cjs/snk-filter-number.cjs.entry.js +23 -0
  20. package/dist/cjs/snk-filter-period.cjs.entry.js +26 -0
  21. package/dist/cjs/snk-filter-search.cjs.entry.js +44 -0
  22. package/dist/cjs/snk-filter-text.cjs.entry.js +22 -0
  23. package/dist/cjs/{snk-form_2.cjs.entry.js → snk-form.cjs.entry.js} +3 -65
  24. package/dist/cjs/snk-grid.cjs.entry.js +69 -0
  25. package/dist/cjs/snk-pesquisa.cjs.entry.js +5 -5
  26. package/dist/cjs/snk-taskbar.cjs.entry.js +5 -4
  27. package/dist/cjs/{taskbar-elements-2ae0d005.js → taskbar-elements-efa44ff1.js} +1 -1
  28. package/dist/cjs/teste-pesquisa.cjs.entry.js +5 -5
  29. package/dist/collection/collection-manifest.json +9 -0
  30. package/dist/collection/components/snk-application/errorhandler/snk-error-handler.js +7 -0
  31. package/dist/collection/components/snk-application/snk-application.js +89 -17
  32. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-binary-select.js +88 -0
  33. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-number.js +64 -0
  34. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-period.js +69 -0
  35. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-search.js +118 -0
  36. package/dist/collection/components/snk-filter-bar/filter-item/editors/snk-filter-text.js +63 -0
  37. package/dist/collection/components/snk-filter-bar/filter-item/filter-item-type.enum.js +10 -0
  38. package/dist/collection/components/snk-filter-bar/filter-item/snk-filter-detail.js +113 -0
  39. package/dist/collection/components/snk-filter-bar/filter-item/snk-filter-item.js +209 -0
  40. package/dist/collection/components/snk-filter-bar/filter-list/snk-filter-list.js +182 -0
  41. package/dist/collection/components/snk-filter-bar/snk-filter-bar.css +99 -0
  42. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +257 -0
  43. package/dist/collection/components/snk-grid/snk-grid.css +14 -1
  44. package/dist/collection/components/snk-grid/snk-grid.js +1 -1
  45. package/dist/collection/lib/http/data-fetcher/DataFetcher.js +24 -2
  46. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +1 -1
  47. package/dist/collection/lib/http/data-fetcher/fetchers/filter-bar-config-fetcher.js +268 -0
  48. package/dist/collection/lib/message/SnkMessageBuilder.js +3 -1
  49. package/dist/collection/lib/message/resources/snk-filter-bar.msg.js +14 -0
  50. package/dist/components/SnkMessageBuilder.js +133 -2
  51. package/dist/components/filter-item-type.enum.js +12 -0
  52. package/dist/components/index.d.ts +9 -0
  53. package/dist/components/index.js +13 -0
  54. package/dist/components/index2.js +2384 -0
  55. package/dist/components/snk-application2.js +508 -30
  56. package/dist/components/snk-crud.js +25 -1
  57. package/dist/components/snk-data-unit.js +2 -3
  58. package/dist/components/snk-filter-bar.d.ts +11 -0
  59. package/dist/components/snk-filter-bar.js +6 -0
  60. package/dist/components/snk-filter-bar2.js +230 -0
  61. package/dist/components/snk-filter-binary-select.d.ts +11 -0
  62. package/dist/components/snk-filter-binary-select.js +63 -0
  63. package/dist/components/snk-filter-detail.d.ts +11 -0
  64. package/dist/components/snk-filter-detail.js +6 -0
  65. package/dist/components/snk-filter-detail2.js +58 -0
  66. package/dist/components/snk-filter-item.d.ts +11 -0
  67. package/dist/components/snk-filter-item.js +6 -0
  68. package/dist/components/snk-filter-item2.js +151 -0
  69. package/dist/components/snk-filter-list.d.ts +11 -0
  70. package/dist/components/snk-filter-list.js +6 -0
  71. package/dist/components/snk-filter-list2.js +108 -0
  72. package/dist/components/snk-filter-number.d.ts +11 -0
  73. package/dist/components/snk-filter-number.js +39 -0
  74. package/dist/components/snk-filter-period.d.ts +11 -0
  75. package/dist/components/snk-filter-period.js +42 -0
  76. package/dist/components/snk-filter-search.d.ts +11 -0
  77. package/dist/components/snk-filter-search.js +62 -0
  78. package/dist/components/snk-filter-text.d.ts +11 -0
  79. package/dist/components/snk-filter-text.js +38 -0
  80. package/dist/components/snk-form2.js +1 -1
  81. package/dist/components/snk-grid2.js +28 -4
  82. package/dist/components/snk-pesquisa2.js +1 -1
  83. package/dist/components/snk-taskbar2.js +2 -1
  84. package/dist/components/teste-pesquisa.js +1 -1
  85. package/dist/esm/{SnkMessageBuilder-3cdde541.js → SnkMessageBuilder-cff80920.js} +133 -2
  86. package/dist/esm/app-globals-0f993ce5.js +3 -0
  87. package/dist/esm/css-shim-b3f2ee8d.js +4 -0
  88. package/dist/esm/dom-665d6011.js +73 -0
  89. package/dist/esm/filter-item-type.enum-61fbf80a.js +12 -0
  90. package/dist/esm/index-2b4d2d14.js +3262 -0
  91. package/dist/esm/index-e5b61043.js +2384 -0
  92. package/dist/esm/loader.js +18 -2
  93. package/dist/esm/sankhyablocks.js +116 -4
  94. package/dist/esm/shadow-css-b18e99d7.js +387 -0
  95. package/dist/esm/snk-application.entry.js +507 -31
  96. package/dist/esm/snk-crud.entry.js +1 -1
  97. package/dist/esm/snk-data-unit.entry.js +3 -4
  98. package/dist/esm/snk-filter-bar.entry.js +195 -0
  99. package/dist/esm/snk-filter-binary-select.entry.js +43 -0
  100. package/dist/esm/snk-filter-detail.entry.js +40 -0
  101. package/dist/esm/snk-filter-item.entry.js +127 -0
  102. package/dist/esm/snk-filter-list.entry.js +87 -0
  103. package/dist/esm/snk-filter-number.entry.js +19 -0
  104. package/dist/esm/snk-filter-period.entry.js +22 -0
  105. package/dist/esm/snk-filter-search.entry.js +40 -0
  106. package/dist/esm/snk-filter-text.entry.js +18 -0
  107. package/dist/esm/{snk-form_2.entry.js → snk-form.entry.js} +3 -64
  108. package/dist/esm/snk-grid.entry.js +65 -0
  109. package/dist/esm/snk-pesquisa.entry.js +2 -2
  110. package/dist/esm/snk-taskbar.entry.js +4 -3
  111. package/dist/esm/{taskbar-elements-bcccc0ff.js → taskbar-elements-c119510a.js} +1 -1
  112. package/dist/esm/teste-pesquisa.entry.js +2 -2
  113. package/dist/sankhyablocks/SnkMessageBuilder-cff80920.js +299 -0
  114. package/dist/sankhyablocks/app-globals-0f993ce5.js +3 -0
  115. package/dist/sankhyablocks/css-shim-b3f2ee8d.js +4 -0
  116. package/dist/sankhyablocks/dom-665d6011.js +73 -0
  117. package/dist/sankhyablocks/filter-item-type.enum-61fbf80a.js +12 -0
  118. package/dist/sankhyablocks/index-2b4d2d14.js +3262 -0
  119. package/dist/sankhyablocks/index-e5b61043.js +2384 -0
  120. package/dist/sankhyablocks/index.esm.js +1 -0
  121. package/dist/sankhyablocks/sankhyablocks.esm.js +129 -1
  122. package/dist/sankhyablocks/shadow-css-b18e99d7.js +387 -0
  123. package/dist/sankhyablocks/snk-application.entry.js +8306 -0
  124. package/dist/sankhyablocks/snk-crud.entry.js +60 -0
  125. package/dist/sankhyablocks/snk-data-unit.entry.js +272 -0
  126. package/dist/sankhyablocks/snk-filter-bar.entry.js +195 -0
  127. package/dist/sankhyablocks/snk-filter-binary-select.entry.js +43 -0
  128. package/dist/sankhyablocks/snk-filter-detail.entry.js +40 -0
  129. package/dist/sankhyablocks/snk-filter-item.entry.js +127 -0
  130. package/dist/sankhyablocks/snk-filter-list.entry.js +87 -0
  131. package/dist/sankhyablocks/snk-filter-number.entry.js +19 -0
  132. package/dist/sankhyablocks/snk-filter-period.entry.js +22 -0
  133. package/dist/sankhyablocks/snk-filter-search.entry.js +40 -0
  134. package/dist/sankhyablocks/snk-filter-text.entry.js +18 -0
  135. package/dist/sankhyablocks/snk-form.entry.js +111 -0
  136. package/dist/sankhyablocks/snk-grid.entry.js +65 -0
  137. package/dist/sankhyablocks/snk-pesquisa.entry.js +311 -0
  138. package/dist/sankhyablocks/snk-taskbar.entry.js +153 -0
  139. package/dist/sankhyablocks/taskbar-elements-c119510a.js +72 -0
  140. package/dist/sankhyablocks/teste-pesquisa.entry.js +33 -0
  141. package/dist/types/components/snk-application/errorhandler/snk-error-handler.d.ts +1 -0
  142. package/dist/types/components/snk-application/snk-application.d.ts +9 -0
  143. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-binary-select.d.ts +12 -0
  144. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-number.d.ts +7 -0
  145. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-period.d.ts +13 -0
  146. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-search.d.ts +12 -0
  147. package/dist/types/components/snk-filter-bar/filter-item/editors/snk-filter-text.d.ts +7 -0
  148. package/dist/types/components/snk-filter-bar/filter-item/filter-item-type.enum.d.ts +9 -0
  149. package/dist/types/components/snk-filter-bar/filter-item/snk-filter-detail.d.ts +13 -0
  150. package/dist/types/components/snk-filter-bar/filter-list/snk-filter-list.d.ts +37 -0
  151. package/dist/types/components/snk-filter-bar/snk-filter-bar.d.ts +43 -0
  152. package/dist/types/components.d.ts +199 -0
  153. package/dist/types/lib/http/data-fetcher/DataFetcher.d.ts +1 -0
  154. package/dist/types/lib/http/data-fetcher/fetchers/filter-bar-config-fetcher.d.ts +5 -0
  155. package/dist/types/lib/message/resources/snk-filter-bar.msg.d.ts +2 -0
  156. package/package.json +2 -2
  157. package/react/components.d.ts +0 -7
  158. package/react/components.js +0 -7
  159. package/react/components.js.map +1 -1
  160. package/dist/esm/index-cf91f542.js +0 -1817
  161. package/dist/sankhyablocks/p-1ba29824.entry.js +0 -74
  162. package/dist/sankhyablocks/p-2266555e.entry.js +0 -1
  163. package/dist/sankhyablocks/p-23c4c94f.js +0 -2
  164. package/dist/sankhyablocks/p-2454be94.js +0 -1
  165. package/dist/sankhyablocks/p-49743bc5.js +0 -1
  166. package/dist/sankhyablocks/p-4fa389bd.entry.js +0 -1
  167. package/dist/sankhyablocks/p-5327ba05.entry.js +0 -1
  168. package/dist/sankhyablocks/p-7a922fb4.entry.js +0 -1
  169. package/dist/sankhyablocks/p-92d6f826.entry.js +0 -1
  170. package/dist/sankhyablocks/p-bdeef7f2.entry.js +0 -1
@@ -1,1817 +0,0 @@
1
- const NAMESPACE = 'sankhyablocks';
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
- */
11
- let scopeId;
12
- let contentRef;
13
- let hostTagName;
14
- let useNativeShadowDom = false;
15
- let checkSlotFallbackVisibility = false;
16
- let checkSlotRelocate = false;
17
- let isSvgMode = false;
18
- let queuePending = false;
19
- const createTime = (fnName, tagName = '') => {
20
- {
21
- return () => {
22
- return;
23
- };
24
- }
25
- };
26
- const uniqueTime = (key, measureText) => {
27
- {
28
- return () => {
29
- return;
30
- };
31
- }
32
- };
33
- const HYDRATED_CSS = '{visibility:hidden}.hydrated{visibility:inherit}';
34
- /**
35
- * Default style mode id
36
- */
37
- /**
38
- * Reusable empty obj/array
39
- * Don't add values to these!!
40
- */
41
- const EMPTY_OBJ = {};
42
- const isDef = (v) => v != null;
43
- const isComplexType = (o) => {
44
- // https://jsperf.com/typeof-fn-object/5
45
- o = typeof o;
46
- return o === 'object' || o === 'function';
47
- };
48
- /**
49
- * Production h() function based on Preact by
50
- * Jason Miller (@developit)
51
- * Licensed under the MIT License
52
- * https://github.com/developit/preact/blob/master/LICENSE
53
- *
54
- * Modified for Stencil's compiler and vdom
55
- */
56
- // const stack: any[] = [];
57
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, child?: d.ChildType): d.VNode;
58
- // export function h(nodeName: string | d.FunctionalComponent, vnodeData: d.PropsType, ...children: d.ChildType[]): d.VNode;
59
- const h = (nodeName, vnodeData, ...children) => {
60
- let child = null;
61
- let key = null;
62
- let slotName = null;
63
- let simple = false;
64
- let lastSimple = false;
65
- const vNodeChildren = [];
66
- const walk = (c) => {
67
- for (let i = 0; i < c.length; i++) {
68
- child = c[i];
69
- if (Array.isArray(child)) {
70
- walk(child);
71
- }
72
- else if (child != null && typeof child !== 'boolean') {
73
- if ((simple = typeof nodeName !== 'function' && !isComplexType(child))) {
74
- child = String(child);
75
- }
76
- if (simple && lastSimple) {
77
- // If the previous child was simple (string), we merge both
78
- vNodeChildren[vNodeChildren.length - 1].$text$ += child;
79
- }
80
- else {
81
- // Append a new vNode, if it's text, we create a text vNode
82
- vNodeChildren.push(simple ? newVNode(null, child) : child);
83
- }
84
- lastSimple = simple;
85
- }
86
- }
87
- };
88
- walk(children);
89
- if (vnodeData) {
90
- // normalize class / classname attributes
91
- if (vnodeData.key) {
92
- key = vnodeData.key;
93
- }
94
- if (vnodeData.name) {
95
- slotName = vnodeData.name;
96
- }
97
- {
98
- const classData = vnodeData.className || vnodeData.class;
99
- if (classData) {
100
- vnodeData.class =
101
- typeof classData !== 'object'
102
- ? classData
103
- : Object.keys(classData)
104
- .filter((k) => classData[k])
105
- .join(' ');
106
- }
107
- }
108
- }
109
- const vnode = newVNode(nodeName, null);
110
- vnode.$attrs$ = vnodeData;
111
- if (vNodeChildren.length > 0) {
112
- vnode.$children$ = vNodeChildren;
113
- }
114
- {
115
- vnode.$key$ = key;
116
- }
117
- {
118
- vnode.$name$ = slotName;
119
- }
120
- return vnode;
121
- };
122
- const newVNode = (tag, text) => {
123
- const vnode = {
124
- $flags$: 0,
125
- $tag$: tag,
126
- $text$: text,
127
- $elm$: null,
128
- $children$: null,
129
- };
130
- {
131
- vnode.$attrs$ = null;
132
- }
133
- {
134
- vnode.$key$ = null;
135
- }
136
- {
137
- vnode.$name$ = null;
138
- }
139
- return vnode;
140
- };
141
- const Host = {};
142
- const isHost = (node) => node && node.$tag$ === Host;
143
- /**
144
- * Parse a new property value for a given property type.
145
- *
146
- * While the prop value can reasonably be expected to be of `any` type as far as TypeScript's type checker is concerned,
147
- * it is not safe to assume that the string returned by evaluating `typeof propValue` matches:
148
- * 1. `any`, the type given to `propValue` in the function signature
149
- * 2. the type stored from `propType`.
150
- *
151
- * This function provides the capability to parse/coerce a property's value to potentially any other JavaScript type.
152
- *
153
- * Property values represented in TSX preserve their type information. In the example below, the number 0 is passed to
154
- * a component. This `propValue` will preserve its type information (`typeof propValue === 'number'`). Note that is
155
- * based on the type of the value being passed in, not the type declared of the class member decorated with `@Prop`.
156
- * ```tsx
157
- * <my-cmp prop-val={0}></my-cmp>
158
- * ```
159
- *
160
- * HTML prop values on the other hand, will always a string
161
- *
162
- * @param propValue the new value to coerce to some type
163
- * @param propType the type of the prop, expressed as a binary number
164
- * @returns the parsed/coerced value
165
- */
166
- const parsePropertyValue = (propValue, propType) => {
167
- // ensure this value is of the correct prop type
168
- if (propValue != null && !isComplexType(propValue)) {
169
- if (propType & 4 /* MEMBER_FLAGS.Boolean */) {
170
- // per the HTML spec, any string value means it is a boolean true value
171
- // but we'll cheat here and say that the string "false" is the boolean false
172
- return propValue === 'false' ? false : propValue === '' || !!propValue;
173
- }
174
- if (propType & 2 /* MEMBER_FLAGS.Number */) {
175
- // force it to be a number
176
- return parseFloat(propValue);
177
- }
178
- if (propType & 1 /* MEMBER_FLAGS.String */) {
179
- // could have been passed as a number or boolean
180
- // but we still want it as a string
181
- return String(propValue);
182
- }
183
- // redundant return here for better minification
184
- return propValue;
185
- }
186
- // not sure exactly what type we want
187
- // so no need to change to a different type
188
- return propValue;
189
- };
190
- const getElement = (ref) => (getHostRef(ref).$hostElement$ );
191
- const createEvent = (ref, name, flags) => {
192
- const elm = getElement(ref);
193
- return {
194
- emit: (detail) => {
195
- return emitEvent(elm, name, {
196
- bubbles: !!(flags & 4 /* EVENT_FLAGS.Bubbles */),
197
- composed: !!(flags & 2 /* EVENT_FLAGS.Composed */),
198
- cancelable: !!(flags & 1 /* EVENT_FLAGS.Cancellable */),
199
- detail,
200
- });
201
- },
202
- };
203
- };
204
- /**
205
- * Helper function to create & dispatch a custom Event on a provided target
206
- * @param elm the target of the Event
207
- * @param name the name to give the custom Event
208
- * @param opts options for configuring a custom Event
209
- * @returns the custom Event
210
- */
211
- const emitEvent = (elm, name, opts) => {
212
- const ev = plt.ce(name, opts);
213
- elm.dispatchEvent(ev);
214
- return ev;
215
- };
216
- const rootAppliedStyles = /*@__PURE__*/ new WeakMap();
217
- const registerStyle = (scopeId, cssText, allowCS) => {
218
- let style = styles.get(scopeId);
219
- if (supportsConstructableStylesheets && allowCS) {
220
- style = (style || new CSSStyleSheet());
221
- if (typeof style === 'string') {
222
- style = cssText;
223
- }
224
- else {
225
- style.replaceSync(cssText);
226
- }
227
- }
228
- else {
229
- style = cssText;
230
- }
231
- styles.set(scopeId, style);
232
- };
233
- const addStyle = (styleContainerNode, cmpMeta, mode, hostElm) => {
234
- let scopeId = getScopeId(cmpMeta);
235
- const style = styles.get(scopeId);
236
- // if an element is NOT connected then getRootNode() will return the wrong root node
237
- // so the fallback is to always use the document for the root node in those cases
238
- styleContainerNode = styleContainerNode.nodeType === 11 /* NODE_TYPE.DocumentFragment */ ? styleContainerNode : doc;
239
- if (style) {
240
- if (typeof style === 'string') {
241
- styleContainerNode = styleContainerNode.head || styleContainerNode;
242
- let appliedStyles = rootAppliedStyles.get(styleContainerNode);
243
- let styleElm;
244
- if (!appliedStyles) {
245
- rootAppliedStyles.set(styleContainerNode, (appliedStyles = new Set()));
246
- }
247
- if (!appliedStyles.has(scopeId)) {
248
- {
249
- {
250
- styleElm = doc.createElement('style');
251
- styleElm.innerHTML = style;
252
- }
253
- styleContainerNode.insertBefore(styleElm, styleContainerNode.querySelector('link'));
254
- }
255
- if (appliedStyles) {
256
- appliedStyles.add(scopeId);
257
- }
258
- }
259
- }
260
- else if (!styleContainerNode.adoptedStyleSheets.includes(style)) {
261
- styleContainerNode.adoptedStyleSheets = [...styleContainerNode.adoptedStyleSheets, style];
262
- }
263
- }
264
- return scopeId;
265
- };
266
- const attachStyles = (hostRef) => {
267
- const cmpMeta = hostRef.$cmpMeta$;
268
- const elm = hostRef.$hostElement$;
269
- const flags = cmpMeta.$flags$;
270
- const endAttachStyles = createTime('attachStyles', cmpMeta.$tagName$);
271
- const scopeId = addStyle(elm.shadowRoot ? elm.shadowRoot : elm.getRootNode(), cmpMeta);
272
- if (flags & 10 /* CMP_FLAGS.needsScopedEncapsulation */) {
273
- // only required when we're NOT using native shadow dom (slot)
274
- // or this browser doesn't support native shadow dom
275
- // and this host element was NOT created with SSR
276
- // let's pick out the inner content for slot projection
277
- // create a node to represent where the original
278
- // content was first placed, which is useful later on
279
- // DOM WRITE!!
280
- elm['s-sc'] = scopeId;
281
- elm.classList.add(scopeId + '-h');
282
- if (flags & 2 /* CMP_FLAGS.scopedCssEncapsulation */) {
283
- elm.classList.add(scopeId + '-s');
284
- }
285
- }
286
- endAttachStyles();
287
- };
288
- const getScopeId = (cmp, mode) => 'sc-' + (cmp.$tagName$);
289
- /**
290
- * Production setAccessor() function based on Preact by
291
- * Jason Miller (@developit)
292
- * Licensed under the MIT License
293
- * https://github.com/developit/preact/blob/master/LICENSE
294
- *
295
- * Modified for Stencil's compiler and vdom
296
- */
297
- const setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags) => {
298
- if (oldValue !== newValue) {
299
- let isProp = isMemberInElement(elm, memberName);
300
- let ln = memberName.toLowerCase();
301
- if (memberName === 'class') {
302
- const classList = elm.classList;
303
- const oldClasses = parseClassList(oldValue);
304
- const newClasses = parseClassList(newValue);
305
- classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
306
- classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
307
- }
308
- else if (memberName === 'key')
309
- ;
310
- else if (memberName === 'ref') {
311
- // minifier will clean this up
312
- if (newValue) {
313
- newValue(elm);
314
- }
315
- }
316
- else if ((!isProp ) &&
317
- memberName[0] === 'o' &&
318
- memberName[1] === 'n') {
319
- // Event Handlers
320
- // so if the member name starts with "on" and the 3rd characters is
321
- // a capital letter, and it's not already a member on the element,
322
- // then we're assuming it's an event listener
323
- if (memberName[2] === '-') {
324
- // on- prefixed events
325
- // allows to be explicit about the dom event to listen without any magic
326
- // under the hood:
327
- // <my-cmp on-click> // listens for "click"
328
- // <my-cmp on-Click> // listens for "Click"
329
- // <my-cmp on-ionChange> // listens for "ionChange"
330
- // <my-cmp on-EVENTS> // listens for "EVENTS"
331
- memberName = memberName.slice(3);
332
- }
333
- else if (isMemberInElement(win, ln)) {
334
- // standard event
335
- // the JSX attribute could have been "onMouseOver" and the
336
- // member name "onmouseover" is on the window's prototype
337
- // so let's add the listener "mouseover", which is all lowercased
338
- memberName = ln.slice(2);
339
- }
340
- else {
341
- // custom event
342
- // the JSX attribute could have been "onMyCustomEvent"
343
- // so let's trim off the "on" prefix and lowercase the first character
344
- // and add the listener "myCustomEvent"
345
- // except for the first character, we keep the event name case
346
- memberName = ln[2] + memberName.slice(3);
347
- }
348
- if (oldValue) {
349
- plt.rel(elm, memberName, oldValue, false);
350
- }
351
- if (newValue) {
352
- plt.ael(elm, memberName, newValue, false);
353
- }
354
- }
355
- else {
356
- // Set property if it exists and it's not a SVG
357
- const isComplex = isComplexType(newValue);
358
- if ((isProp || (isComplex && newValue !== null)) && !isSvg) {
359
- try {
360
- if (!elm.tagName.includes('-')) {
361
- const n = newValue == null ? '' : newValue;
362
- // Workaround for Safari, moving the <input> caret when re-assigning the same valued
363
- if (memberName === 'list') {
364
- isProp = false;
365
- }
366
- else if (oldValue == null || elm[memberName] != n) {
367
- elm[memberName] = n;
368
- }
369
- }
370
- else {
371
- elm[memberName] = newValue;
372
- }
373
- }
374
- catch (e) { }
375
- }
376
- if (newValue == null || newValue === false) {
377
- if (newValue !== false || elm.getAttribute(memberName) === '') {
378
- {
379
- elm.removeAttribute(memberName);
380
- }
381
- }
382
- }
383
- else if ((!isProp || flags & 4 /* VNODE_FLAGS.isHost */ || isSvg) && !isComplex) {
384
- newValue = newValue === true ? '' : newValue;
385
- {
386
- elm.setAttribute(memberName, newValue);
387
- }
388
- }
389
- }
390
- }
391
- };
392
- const parseClassListRegex = /\s/;
393
- const parseClassList = (value) => (!value ? [] : value.split(parseClassListRegex));
394
- const updateElement = (oldVnode, newVnode, isSvgMode, memberName) => {
395
- // if the element passed in is a shadow root, which is a document fragment
396
- // then we want to be adding attrs/props to the shadow root's "host" element
397
- // if it's not a shadow root, then we add attrs/props to the same element
398
- const elm = newVnode.$elm$.nodeType === 11 /* NODE_TYPE.DocumentFragment */ && newVnode.$elm$.host
399
- ? newVnode.$elm$.host
400
- : newVnode.$elm$;
401
- const oldVnodeAttrs = (oldVnode && oldVnode.$attrs$) || EMPTY_OBJ;
402
- const newVnodeAttrs = newVnode.$attrs$ || EMPTY_OBJ;
403
- {
404
- // remove attributes no longer present on the vnode by setting them to undefined
405
- for (memberName in oldVnodeAttrs) {
406
- if (!(memberName in newVnodeAttrs)) {
407
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], undefined, isSvgMode, newVnode.$flags$);
408
- }
409
- }
410
- }
411
- // add new & update changed attributes
412
- for (memberName in newVnodeAttrs) {
413
- setAccessor(elm, memberName, oldVnodeAttrs[memberName], newVnodeAttrs[memberName], isSvgMode, newVnode.$flags$);
414
- }
415
- };
416
- /**
417
- * Create a DOM Node corresponding to one of the children of a given VNode.
418
- *
419
- * @param oldParentVNode the parent VNode from the previous render
420
- * @param newParentVNode the parent VNode from the current render
421
- * @param childIndex the index of the VNode, in the _new_ parent node's
422
- * children, for which we will create a new DOM node
423
- * @param parentElm the parent DOM node which our new node will be a child of
424
- * @returns the newly created node
425
- */
426
- const createElm = (oldParentVNode, newParentVNode, childIndex, parentElm) => {
427
- // tslint:disable-next-line: prefer-const
428
- const newVNode = newParentVNode.$children$[childIndex];
429
- let i = 0;
430
- let elm;
431
- let childNode;
432
- let oldVNode;
433
- if (!useNativeShadowDom) {
434
- // remember for later we need to check to relocate nodes
435
- checkSlotRelocate = true;
436
- if (newVNode.$tag$ === 'slot') {
437
- if (scopeId) {
438
- // scoped css needs to add its scoped id to the parent element
439
- parentElm.classList.add(scopeId + '-s');
440
- }
441
- newVNode.$flags$ |= newVNode.$children$
442
- ? // slot element has fallback content
443
- 2 /* VNODE_FLAGS.isSlotFallback */
444
- : // slot element does not have fallback content
445
- 1 /* VNODE_FLAGS.isSlotReference */;
446
- }
447
- }
448
- if (newVNode.$text$ !== null) {
449
- // create text node
450
- elm = newVNode.$elm$ = doc.createTextNode(newVNode.$text$);
451
- }
452
- else if (newVNode.$flags$ & 1 /* VNODE_FLAGS.isSlotReference */) {
453
- // create a slot reference node
454
- elm = newVNode.$elm$ =
455
- doc.createTextNode('');
456
- }
457
- else {
458
- // create element
459
- elm = newVNode.$elm$ = (doc.createElement(newVNode.$flags$ & 2 /* VNODE_FLAGS.isSlotFallback */
460
- ? 'slot-fb'
461
- : newVNode.$tag$));
462
- // add css classes, attrs, props, listeners, etc.
463
- {
464
- updateElement(null, newVNode, isSvgMode);
465
- }
466
- if (isDef(scopeId) && elm['s-si'] !== scopeId) {
467
- // if there is a scopeId and this is the initial render
468
- // then let's add the scopeId as a css class
469
- elm.classList.add((elm['s-si'] = scopeId));
470
- }
471
- if (newVNode.$children$) {
472
- for (i = 0; i < newVNode.$children$.length; ++i) {
473
- // create the node
474
- childNode = createElm(oldParentVNode, newVNode, i, elm);
475
- // return node could have been null
476
- if (childNode) {
477
- // append our new node
478
- elm.appendChild(childNode);
479
- }
480
- }
481
- }
482
- }
483
- {
484
- elm['s-hn'] = hostTagName;
485
- if (newVNode.$flags$ & (2 /* VNODE_FLAGS.isSlotFallback */ | 1 /* VNODE_FLAGS.isSlotReference */)) {
486
- // remember the content reference comment
487
- elm['s-sr'] = true;
488
- // remember the content reference comment
489
- elm['s-cr'] = contentRef;
490
- // remember the slot name, or empty string for default slot
491
- elm['s-sn'] = newVNode.$name$ || '';
492
- // check if we've got an old vnode for this slot
493
- oldVNode = oldParentVNode && oldParentVNode.$children$ && oldParentVNode.$children$[childIndex];
494
- if (oldVNode && oldVNode.$tag$ === newVNode.$tag$ && oldParentVNode.$elm$) {
495
- // we've got an old slot vnode and the wrapper is being replaced
496
- // so let's move the old slot content back to it's original location
497
- putBackInOriginalLocation(oldParentVNode.$elm$, false);
498
- }
499
- }
500
- }
501
- return elm;
502
- };
503
- const putBackInOriginalLocation = (parentElm, recursive) => {
504
- plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
505
- const oldSlotChildNodes = parentElm.childNodes;
506
- for (let i = oldSlotChildNodes.length - 1; i >= 0; i--) {
507
- const childNode = oldSlotChildNodes[i];
508
- if (childNode['s-hn'] !== hostTagName && childNode['s-ol']) {
509
- // // this child node in the old element is from another component
510
- // // remove this node from the old slot's parent
511
- // childNode.remove();
512
- // and relocate it back to it's original location
513
- parentReferenceNode(childNode).insertBefore(childNode, referenceNode(childNode));
514
- // remove the old original location comment entirely
515
- // later on the patch function will know what to do
516
- // and move this to the correct spot in need be
517
- childNode['s-ol'].remove();
518
- childNode['s-ol'] = undefined;
519
- checkSlotRelocate = true;
520
- }
521
- if (recursive) {
522
- putBackInOriginalLocation(childNode, recursive);
523
- }
524
- }
525
- plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
526
- };
527
- const addVnodes = (parentElm, before, parentVNode, vnodes, startIdx, endIdx) => {
528
- let containerElm = ((parentElm['s-cr'] && parentElm['s-cr'].parentNode) || parentElm);
529
- let childNode;
530
- if (containerElm.shadowRoot && containerElm.tagName === hostTagName) {
531
- containerElm = containerElm.shadowRoot;
532
- }
533
- for (; startIdx <= endIdx; ++startIdx) {
534
- if (vnodes[startIdx]) {
535
- childNode = createElm(null, parentVNode, startIdx, parentElm);
536
- if (childNode) {
537
- vnodes[startIdx].$elm$ = childNode;
538
- containerElm.insertBefore(childNode, referenceNode(before) );
539
- }
540
- }
541
- }
542
- };
543
- const removeVnodes = (vnodes, startIdx, endIdx, vnode, elm) => {
544
- for (; startIdx <= endIdx; ++startIdx) {
545
- if ((vnode = vnodes[startIdx])) {
546
- elm = vnode.$elm$;
547
- callNodeRefs(vnode);
548
- {
549
- // we're removing this element
550
- // so it's possible we need to show slot fallback content now
551
- checkSlotFallbackVisibility = true;
552
- if (elm['s-ol']) {
553
- // remove the original location comment
554
- elm['s-ol'].remove();
555
- }
556
- else {
557
- // it's possible that child nodes of the node
558
- // that's being removed are slot nodes
559
- putBackInOriginalLocation(elm, true);
560
- }
561
- }
562
- // remove the vnode's element from the dom
563
- elm.remove();
564
- }
565
- }
566
- };
567
- /**
568
- * Reconcile the children of a new VNode with the children of an old VNode by
569
- * traversing the two collections of children, identifying nodes that are
570
- * conserved or changed, calling out to `patch` to make any necessary
571
- * updates to the DOM, and rearranging DOM nodes as needed.
572
- *
573
- * The algorithm for reconciling children works by analyzing two 'windows' onto
574
- * the two arrays of children (`oldCh` and `newCh`). We keep track of the
575
- * 'windows' by storing start and end indices and references to the
576
- * corresponding array entries. Initially the two 'windows' are basically equal
577
- * to the entire array, but we progressively narrow the windows until there are
578
- * no children left to update by doing the following:
579
- *
580
- * 1. Skip any `null` entries at the beginning or end of the two arrays, so
581
- * that if we have an initial array like the following we'll end up dealing
582
- * only with a window bounded by the highlighted elements:
583
- *
584
- * [null, null, VNode1 , ... , VNode2, null, null]
585
- * ^^^^^^ ^^^^^^
586
- *
587
- * 2. Check to see if the elements at the head and tail positions are equal
588
- * across the windows. This will basically detect elements which haven't
589
- * been added, removed, or changed position, i.e. if you had the following
590
- * VNode elements (represented as HTML):
591
- *
592
- * oldVNode: `<div><p><span>HEY</span></p></div>`
593
- * newVNode: `<div><p><span>THERE</span></p></div>`
594
- *
595
- * Then when comparing the children of the `<div>` tag we check the equality
596
- * of the VNodes corresponding to the `<p>` tags and, since they are the
597
- * same tag in the same position, we'd be able to avoid completely
598
- * re-rendering the subtree under them with a new DOM element and would just
599
- * call out to `patch` to handle reconciling their children and so on.
600
- *
601
- * 3. Check, for both windows, to see if the element at the beginning of the
602
- * window corresponds to the element at the end of the other window. This is
603
- * a heuristic which will let us identify _some_ situations in which
604
- * elements have changed position, for instance it _should_ detect that the
605
- * children nodes themselves have not changed but merely moved in the
606
- * following example:
607
- *
608
- * oldVNode: `<div><element-one /><element-two /></div>`
609
- * newVNode: `<div><element-two /><element-one /></div>`
610
- *
611
- * If we find cases like this then we also need to move the concrete DOM
612
- * elements corresponding to the moved children to write the re-order to the
613
- * DOM.
614
- *
615
- * 4. Finally, if VNodes have the `key` attribute set on them we check for any
616
- * nodes in the old children which have the same key as the first element in
617
- * our window on the new children. If we find such a node we handle calling
618
- * out to `patch`, moving relevant DOM nodes, and so on, in accordance with
619
- * what we find.
620
- *
621
- * Finally, once we've narrowed our 'windows' to the point that either of them
622
- * collapse (i.e. they have length 0) we then handle any remaining VNode
623
- * insertion or deletion that needs to happen to get a DOM state that correctly
624
- * reflects the new child VNodes. If, for instance, after our window on the old
625
- * children has collapsed we still have more nodes on the new children that
626
- * we haven't dealt with yet then we need to add them, or if the new children
627
- * collapse but we still have unhandled _old_ children then we need to make
628
- * sure the corresponding DOM nodes are removed.
629
- *
630
- * @param parentElm the node into which the parent VNode is rendered
631
- * @param oldCh the old children of the parent node
632
- * @param newVNode the new VNode which will replace the parent
633
- * @param newCh the new children of the parent node
634
- */
635
- const updateChildren = (parentElm, oldCh, newVNode, newCh) => {
636
- let oldStartIdx = 0;
637
- let newStartIdx = 0;
638
- let idxInOld = 0;
639
- let i = 0;
640
- let oldEndIdx = oldCh.length - 1;
641
- let oldStartVnode = oldCh[0];
642
- let oldEndVnode = oldCh[oldEndIdx];
643
- let newEndIdx = newCh.length - 1;
644
- let newStartVnode = newCh[0];
645
- let newEndVnode = newCh[newEndIdx];
646
- let node;
647
- let elmToMove;
648
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
649
- if (oldStartVnode == null) {
650
- // VNode might have been moved left
651
- oldStartVnode = oldCh[++oldStartIdx];
652
- }
653
- else if (oldEndVnode == null) {
654
- oldEndVnode = oldCh[--oldEndIdx];
655
- }
656
- else if (newStartVnode == null) {
657
- newStartVnode = newCh[++newStartIdx];
658
- }
659
- else if (newEndVnode == null) {
660
- newEndVnode = newCh[--newEndIdx];
661
- }
662
- else if (isSameVnode(oldStartVnode, newStartVnode)) {
663
- // if the start nodes are the same then we should patch the new VNode
664
- // onto the old one, and increment our `newStartIdx` and `oldStartIdx`
665
- // indices to reflect that. We don't need to move any DOM Nodes around
666
- // since things are matched up in order.
667
- patch(oldStartVnode, newStartVnode);
668
- oldStartVnode = oldCh[++oldStartIdx];
669
- newStartVnode = newCh[++newStartIdx];
670
- }
671
- else if (isSameVnode(oldEndVnode, newEndVnode)) {
672
- // likewise, if the end nodes are the same we patch new onto old and
673
- // decrement our end indices, and also likewise in this case we don't
674
- // need to move any DOM Nodes.
675
- patch(oldEndVnode, newEndVnode);
676
- oldEndVnode = oldCh[--oldEndIdx];
677
- newEndVnode = newCh[--newEndIdx];
678
- }
679
- else if (isSameVnode(oldStartVnode, newEndVnode)) {
680
- // case: "Vnode moved right"
681
- //
682
- // We've found that the last node in our window on the new children is
683
- // the same VNode as the _first_ node in our window on the old children
684
- // we're dealing with now. Visually, this is the layout of these two
685
- // nodes:
686
- //
687
- // newCh: [..., newStartVnode , ... , newEndVnode , ...]
688
- // ^^^^^^^^^^^
689
- // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
690
- // ^^^^^^^^^^^^^
691
- //
692
- // In this situation we need to patch `newEndVnode` onto `oldStartVnode`
693
- // and move the DOM element for `oldStartVnode`.
694
- if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
695
- putBackInOriginalLocation(oldStartVnode.$elm$.parentNode, false);
696
- }
697
- patch(oldStartVnode, newEndVnode);
698
- // We need to move the element for `oldStartVnode` into a position which
699
- // will be appropriate for `newEndVnode`. For this we can use
700
- // `.insertBefore` and `oldEndVnode.$elm$.nextSibling`. If there is a
701
- // sibling for `oldEndVnode.$elm$` then we want to move the DOM node for
702
- // `oldStartVnode` between `oldEndVnode` and it's sibling, like so:
703
- //
704
- // <old-start-node />
705
- // <some-intervening-node />
706
- // <old-end-node />
707
- // <!-- -> <-- `oldStartVnode.$elm$` should be inserted here
708
- // <next-sibling />
709
- //
710
- // If instead `oldEndVnode.$elm$` has no sibling then we just want to put
711
- // the node for `oldStartVnode` at the end of the children of
712
- // `parentElm`. Luckily, `Node.nextSibling` will return `null` if there
713
- // aren't any siblings, and passing `null` to `Node.insertBefore` will
714
- // append it to the children of the parent element.
715
- parentElm.insertBefore(oldStartVnode.$elm$, oldEndVnode.$elm$.nextSibling);
716
- oldStartVnode = oldCh[++oldStartIdx];
717
- newEndVnode = newCh[--newEndIdx];
718
- }
719
- else if (isSameVnode(oldEndVnode, newStartVnode)) {
720
- // case: "Vnode moved left"
721
- //
722
- // We've found that the first node in our window on the new children is
723
- // the same VNode as the _last_ node in our window on the old children.
724
- // Visually, this is the layout of these two nodes:
725
- //
726
- // newCh: [..., newStartVnode , ... , newEndVnode , ...]
727
- // ^^^^^^^^^^^^^
728
- // oldCh: [..., oldStartVnode , ... , oldEndVnode , ...]
729
- // ^^^^^^^^^^^
730
- //
731
- // In this situation we need to patch `newStartVnode` onto `oldEndVnode`
732
- // (which will handle updating any changed attributes, reconciling their
733
- // children etc) but we also need to move the DOM node to which
734
- // `oldEndVnode` corresponds.
735
- if ((oldStartVnode.$tag$ === 'slot' || newEndVnode.$tag$ === 'slot')) {
736
- putBackInOriginalLocation(oldEndVnode.$elm$.parentNode, false);
737
- }
738
- patch(oldEndVnode, newStartVnode);
739
- // We've already checked above if `oldStartVnode` and `newStartVnode` are
740
- // the same node, so since we're here we know that they are not. Thus we
741
- // can move the element for `oldEndVnode` _before_ the element for
742
- // `oldStartVnode`, leaving `oldStartVnode` to be reconciled in the
743
- // future.
744
- parentElm.insertBefore(oldEndVnode.$elm$, oldStartVnode.$elm$);
745
- oldEndVnode = oldCh[--oldEndIdx];
746
- newStartVnode = newCh[++newStartIdx];
747
- }
748
- else {
749
- // Here we do some checks to match up old and new nodes based on the
750
- // `$key$` attribute, which is set by putting a `key="my-key"` attribute
751
- // in the JSX for a DOM element in the implementation of a Stencil
752
- // component.
753
- //
754
- // First we check to see if there are any nodes in the array of old
755
- // children which have the same key as the first node in the new
756
- // children.
757
- idxInOld = -1;
758
- {
759
- for (i = oldStartIdx; i <= oldEndIdx; ++i) {
760
- if (oldCh[i] && oldCh[i].$key$ !== null && oldCh[i].$key$ === newStartVnode.$key$) {
761
- idxInOld = i;
762
- break;
763
- }
764
- }
765
- }
766
- if (idxInOld >= 0) {
767
- // We found a node in the old children which matches up with the first
768
- // node in the new children! So let's deal with that
769
- elmToMove = oldCh[idxInOld];
770
- if (elmToMove.$tag$ !== newStartVnode.$tag$) {
771
- // the tag doesn't match so we'll need a new DOM element
772
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, idxInOld, parentElm);
773
- }
774
- else {
775
- patch(elmToMove, newStartVnode);
776
- // invalidate the matching old node so that we won't try to update it
777
- // again later on
778
- oldCh[idxInOld] = undefined;
779
- node = elmToMove.$elm$;
780
- }
781
- newStartVnode = newCh[++newStartIdx];
782
- }
783
- else {
784
- // We either didn't find an element in the old children that matches
785
- // the key of the first new child OR the build is not using `key`
786
- // attributes at all. In either case we need to create a new element
787
- // for the new node.
788
- node = createElm(oldCh && oldCh[newStartIdx], newVNode, newStartIdx, parentElm);
789
- newStartVnode = newCh[++newStartIdx];
790
- }
791
- if (node) {
792
- // if we created a new node then handle inserting it to the DOM
793
- {
794
- parentReferenceNode(oldStartVnode.$elm$).insertBefore(node, referenceNode(oldStartVnode.$elm$));
795
- }
796
- }
797
- }
798
- }
799
- if (oldStartIdx > oldEndIdx) {
800
- // we have some more new nodes to add which don't match up with old nodes
801
- addVnodes(parentElm, newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].$elm$, newVNode, newCh, newStartIdx, newEndIdx);
802
- }
803
- else if (newStartIdx > newEndIdx) {
804
- // there are nodes in the `oldCh` array which no longer correspond to nodes
805
- // in the new array, so lets remove them (which entails cleaning up the
806
- // relevant DOM nodes)
807
- removeVnodes(oldCh, oldStartIdx, oldEndIdx);
808
- }
809
- };
810
- /**
811
- * Compare two VNodes to determine if they are the same
812
- *
813
- * **NB**: This function is an equality _heuristic_ based on the available
814
- * information set on the two VNodes and can be misleading under certain
815
- * circumstances. In particular, if the two nodes do not have `key` attrs
816
- * (available under `$key$` on VNodes) then the function falls back on merely
817
- * checking that they have the same tag.
818
- *
819
- * So, in other words, if `key` attrs are not set on VNodes which may be
820
- * changing order within a `children` array or something along those lines then
821
- * we could obtain a false positive and then have to do needless re-rendering.
822
- *
823
- * @param leftVNode the first VNode to check
824
- * @param rightVNode the second VNode to check
825
- * @returns whether they're equal or not
826
- */
827
- const isSameVnode = (leftVNode, rightVNode) => {
828
- // compare if two vnode to see if they're "technically" the same
829
- // need to have the same element tag, and same key to be the same
830
- if (leftVNode.$tag$ === rightVNode.$tag$) {
831
- if (leftVNode.$tag$ === 'slot') {
832
- return leftVNode.$name$ === rightVNode.$name$;
833
- }
834
- // this will be set if components in the build have `key` attrs set on them
835
- {
836
- return leftVNode.$key$ === rightVNode.$key$;
837
- }
838
- }
839
- return false;
840
- };
841
- const referenceNode = (node) => {
842
- // this node was relocated to a new location in the dom
843
- // because of some other component's slot
844
- // but we still have an html comment in place of where
845
- // it's original location was according to it's original vdom
846
- return (node && node['s-ol']) || node;
847
- };
848
- const parentReferenceNode = (node) => (node['s-ol'] ? node['s-ol'] : node).parentNode;
849
- /**
850
- * Handle reconciling an outdated VNode with a new one which corresponds to
851
- * it. This function handles flushing updates to the DOM and reconciling the
852
- * children of the two nodes (if any).
853
- *
854
- * @param oldVNode an old VNode whose DOM element and children we want to update
855
- * @param newVNode a new VNode representing an updated version of the old one
856
- */
857
- const patch = (oldVNode, newVNode) => {
858
- const elm = (newVNode.$elm$ = oldVNode.$elm$);
859
- const oldChildren = oldVNode.$children$;
860
- const newChildren = newVNode.$children$;
861
- const tag = newVNode.$tag$;
862
- const text = newVNode.$text$;
863
- let defaultHolder;
864
- if (text === null) {
865
- {
866
- if (tag === 'slot')
867
- ;
868
- else {
869
- // either this is the first render of an element OR it's an update
870
- // AND we already know it's possible it could have changed
871
- // this updates the element's css classes, attrs, props, listeners, etc.
872
- updateElement(oldVNode, newVNode, isSvgMode);
873
- }
874
- }
875
- if (oldChildren !== null && newChildren !== null) {
876
- // looks like there's child vnodes for both the old and new vnodes
877
- // so we need to call `updateChildren` to reconcile them
878
- updateChildren(elm, oldChildren, newVNode, newChildren);
879
- }
880
- else if (newChildren !== null) {
881
- // no old child vnodes, but there are new child vnodes to add
882
- if (oldVNode.$text$ !== null) {
883
- // the old vnode was text, so be sure to clear it out
884
- elm.textContent = '';
885
- }
886
- // add the new vnode children
887
- addVnodes(elm, null, newVNode, newChildren, 0, newChildren.length - 1);
888
- }
889
- else if (oldChildren !== null) {
890
- // no new child vnodes, but there are old child vnodes to remove
891
- removeVnodes(oldChildren, 0, oldChildren.length - 1);
892
- }
893
- }
894
- else if ((defaultHolder = elm['s-cr'])) {
895
- // this element has slotted content
896
- defaultHolder.parentNode.textContent = text;
897
- }
898
- else if (oldVNode.$text$ !== text) {
899
- // update the text content for the text only vnode
900
- // and also only if the text is different than before
901
- elm.data = text;
902
- }
903
- };
904
- const updateFallbackSlotVisibility = (elm) => {
905
- // tslint:disable-next-line: prefer-const
906
- const childNodes = elm.childNodes;
907
- let childNode;
908
- let i;
909
- let ilen;
910
- let j;
911
- let slotNameAttr;
912
- let nodeType;
913
- for (i = 0, ilen = childNodes.length; i < ilen; i++) {
914
- childNode = childNodes[i];
915
- if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
916
- if (childNode['s-sr']) {
917
- // this is a slot fallback node
918
- // get the slot name for this slot reference node
919
- slotNameAttr = childNode['s-sn'];
920
- // by default always show a fallback slot node
921
- // then hide it if there are other slots in the light dom
922
- childNode.hidden = false;
923
- for (j = 0; j < ilen; j++) {
924
- nodeType = childNodes[j].nodeType;
925
- if (childNodes[j]['s-hn'] !== childNode['s-hn'] || slotNameAttr !== '') {
926
- // this sibling node is from a different component OR is a named fallback slot node
927
- if (nodeType === 1 /* NODE_TYPE.ElementNode */ && slotNameAttr === childNodes[j].getAttribute('slot')) {
928
- childNode.hidden = true;
929
- break;
930
- }
931
- }
932
- else {
933
- // this is a default fallback slot node
934
- // any element or text node (with content)
935
- // should hide the default fallback slot node
936
- if (nodeType === 1 /* NODE_TYPE.ElementNode */ ||
937
- (nodeType === 3 /* NODE_TYPE.TextNode */ && childNodes[j].textContent.trim() !== '')) {
938
- childNode.hidden = true;
939
- break;
940
- }
941
- }
942
- }
943
- }
944
- // keep drilling down
945
- updateFallbackSlotVisibility(childNode);
946
- }
947
- }
948
- };
949
- const relocateNodes = [];
950
- const relocateSlotContent = (elm) => {
951
- // tslint:disable-next-line: prefer-const
952
- let childNode;
953
- let node;
954
- let hostContentNodes;
955
- let slotNameAttr;
956
- let relocateNodeData;
957
- let j;
958
- let i = 0;
959
- const childNodes = elm.childNodes;
960
- const ilen = childNodes.length;
961
- for (; i < ilen; i++) {
962
- childNode = childNodes[i];
963
- if (childNode['s-sr'] && (node = childNode['s-cr']) && node.parentNode) {
964
- // first got the content reference comment node
965
- // then we got it's parent, which is where all the host content is in now
966
- hostContentNodes = node.parentNode.childNodes;
967
- slotNameAttr = childNode['s-sn'];
968
- for (j = hostContentNodes.length - 1; j >= 0; j--) {
969
- node = hostContentNodes[j];
970
- if (!node['s-cn'] && !node['s-nr'] && node['s-hn'] !== childNode['s-hn']) {
971
- // let's do some relocating to its new home
972
- // but never relocate a content reference node
973
- // that is suppose to always represent the original content location
974
- if (isNodeLocatedInSlot(node, slotNameAttr)) {
975
- // it's possible we've already decided to relocate this node
976
- relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
977
- // made some changes to slots
978
- // let's make sure we also double check
979
- // fallbacks are correctly hidden or shown
980
- checkSlotFallbackVisibility = true;
981
- node['s-sn'] = node['s-sn'] || slotNameAttr;
982
- if (relocateNodeData) {
983
- // previously we never found a slot home for this node
984
- // but turns out we did, so let's remember it now
985
- relocateNodeData.$slotRefNode$ = childNode;
986
- }
987
- else {
988
- // add to our list of nodes to relocate
989
- relocateNodes.push({
990
- $slotRefNode$: childNode,
991
- $nodeToRelocate$: node,
992
- });
993
- }
994
- if (node['s-sr']) {
995
- relocateNodes.map((relocateNode) => {
996
- if (isNodeLocatedInSlot(relocateNode.$nodeToRelocate$, node['s-sn'])) {
997
- relocateNodeData = relocateNodes.find((r) => r.$nodeToRelocate$ === node);
998
- if (relocateNodeData && !relocateNode.$slotRefNode$) {
999
- relocateNode.$slotRefNode$ = relocateNodeData.$slotRefNode$;
1000
- }
1001
- }
1002
- });
1003
- }
1004
- }
1005
- else if (!relocateNodes.some((r) => r.$nodeToRelocate$ === node)) {
1006
- // so far this element does not have a slot home, not setting slotRefNode on purpose
1007
- // if we never find a home for this element then we'll need to hide it
1008
- relocateNodes.push({
1009
- $nodeToRelocate$: node,
1010
- });
1011
- }
1012
- }
1013
- }
1014
- }
1015
- if (childNode.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1016
- relocateSlotContent(childNode);
1017
- }
1018
- }
1019
- };
1020
- const isNodeLocatedInSlot = (nodeToRelocate, slotNameAttr) => {
1021
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1022
- if (nodeToRelocate.getAttribute('slot') === null && slotNameAttr === '') {
1023
- return true;
1024
- }
1025
- if (nodeToRelocate.getAttribute('slot') === slotNameAttr) {
1026
- return true;
1027
- }
1028
- return false;
1029
- }
1030
- if (nodeToRelocate['s-sn'] === slotNameAttr) {
1031
- return true;
1032
- }
1033
- return slotNameAttr === '';
1034
- };
1035
- const callNodeRefs = (vNode) => {
1036
- {
1037
- vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
1038
- vNode.$children$ && vNode.$children$.map(callNodeRefs);
1039
- }
1040
- };
1041
- const renderVdom = (hostRef, renderFnResults) => {
1042
- const hostElm = hostRef.$hostElement$;
1043
- const cmpMeta = hostRef.$cmpMeta$;
1044
- const oldVNode = hostRef.$vnode$ || newVNode(null, null);
1045
- const rootVnode = isHost(renderFnResults) ? renderFnResults : h(null, null, renderFnResults);
1046
- hostTagName = hostElm.tagName;
1047
- rootVnode.$tag$ = null;
1048
- rootVnode.$flags$ |= 4 /* VNODE_FLAGS.isHost */;
1049
- hostRef.$vnode$ = rootVnode;
1050
- rootVnode.$elm$ = oldVNode.$elm$ = (hostElm.shadowRoot || hostElm );
1051
- {
1052
- scopeId = hostElm['s-sc'];
1053
- }
1054
- {
1055
- contentRef = hostElm['s-cr'];
1056
- useNativeShadowDom = (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) !== 0;
1057
- // always reset
1058
- checkSlotFallbackVisibility = false;
1059
- }
1060
- // synchronous patch
1061
- patch(oldVNode, rootVnode);
1062
- {
1063
- // while we're moving nodes around existing nodes, temporarily disable
1064
- // the disconnectCallback from working
1065
- plt.$flags$ |= 1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1066
- if (checkSlotRelocate) {
1067
- relocateSlotContent(rootVnode.$elm$);
1068
- let relocateData;
1069
- let nodeToRelocate;
1070
- let orgLocationNode;
1071
- let parentNodeRef;
1072
- let insertBeforeNode;
1073
- let refNode;
1074
- let i = 0;
1075
- for (; i < relocateNodes.length; i++) {
1076
- relocateData = relocateNodes[i];
1077
- nodeToRelocate = relocateData.$nodeToRelocate$;
1078
- if (!nodeToRelocate['s-ol']) {
1079
- // add a reference node marking this node's original location
1080
- // keep a reference to this node for later lookups
1081
- orgLocationNode =
1082
- doc.createTextNode('');
1083
- orgLocationNode['s-nr'] = nodeToRelocate;
1084
- nodeToRelocate.parentNode.insertBefore((nodeToRelocate['s-ol'] = orgLocationNode), nodeToRelocate);
1085
- }
1086
- }
1087
- for (i = 0; i < relocateNodes.length; i++) {
1088
- relocateData = relocateNodes[i];
1089
- nodeToRelocate = relocateData.$nodeToRelocate$;
1090
- if (relocateData.$slotRefNode$) {
1091
- // by default we're just going to insert it directly
1092
- // after the slot reference node
1093
- parentNodeRef = relocateData.$slotRefNode$.parentNode;
1094
- insertBeforeNode = relocateData.$slotRefNode$.nextSibling;
1095
- orgLocationNode = nodeToRelocate['s-ol'];
1096
- while ((orgLocationNode = orgLocationNode.previousSibling)) {
1097
- refNode = orgLocationNode['s-nr'];
1098
- if (refNode && refNode['s-sn'] === nodeToRelocate['s-sn'] && parentNodeRef === refNode.parentNode) {
1099
- refNode = refNode.nextSibling;
1100
- if (!refNode || !refNode['s-nr']) {
1101
- insertBeforeNode = refNode;
1102
- break;
1103
- }
1104
- }
1105
- }
1106
- if ((!insertBeforeNode && parentNodeRef !== nodeToRelocate.parentNode) ||
1107
- nodeToRelocate.nextSibling !== insertBeforeNode) {
1108
- // we've checked that it's worth while to relocate
1109
- // since that the node to relocate
1110
- // has a different next sibling or parent relocated
1111
- if (nodeToRelocate !== insertBeforeNode) {
1112
- if (!nodeToRelocate['s-hn'] && nodeToRelocate['s-ol']) {
1113
- // probably a component in the index.html that doesn't have it's hostname set
1114
- nodeToRelocate['s-hn'] = nodeToRelocate['s-ol'].parentNode.nodeName;
1115
- }
1116
- // add it back to the dom but in its new home
1117
- parentNodeRef.insertBefore(nodeToRelocate, insertBeforeNode);
1118
- }
1119
- }
1120
- }
1121
- else {
1122
- // this node doesn't have a slot home to go to, so let's hide it
1123
- if (nodeToRelocate.nodeType === 1 /* NODE_TYPE.ElementNode */) {
1124
- nodeToRelocate.hidden = true;
1125
- }
1126
- }
1127
- }
1128
- }
1129
- if (checkSlotFallbackVisibility) {
1130
- updateFallbackSlotVisibility(rootVnode.$elm$);
1131
- }
1132
- // done moving nodes around
1133
- // allow the disconnect callback to work again
1134
- plt.$flags$ &= ~1 /* PLATFORM_FLAGS.isTmpDisconnected */;
1135
- // always reset
1136
- relocateNodes.length = 0;
1137
- }
1138
- };
1139
- const attachToAncestor = (hostRef, ancestorComponent) => {
1140
- if (ancestorComponent && !hostRef.$onRenderResolve$ && ancestorComponent['s-p']) {
1141
- ancestorComponent['s-p'].push(new Promise((r) => (hostRef.$onRenderResolve$ = r)));
1142
- }
1143
- };
1144
- const scheduleUpdate = (hostRef, isInitialLoad) => {
1145
- {
1146
- hostRef.$flags$ |= 16 /* HOST_FLAGS.isQueuedForUpdate */;
1147
- }
1148
- if (hostRef.$flags$ & 4 /* HOST_FLAGS.isWaitingForChildren */) {
1149
- hostRef.$flags$ |= 512 /* HOST_FLAGS.needsRerender */;
1150
- return;
1151
- }
1152
- attachToAncestor(hostRef, hostRef.$ancestorComponent$);
1153
- // there is no ancestor component or the ancestor component
1154
- // has already fired off its lifecycle update then
1155
- // fire off the initial update
1156
- const dispatch = () => dispatchHooks(hostRef, isInitialLoad);
1157
- return writeTask(dispatch) ;
1158
- };
1159
- const dispatchHooks = (hostRef, isInitialLoad) => {
1160
- const endSchedule = createTime('scheduleUpdate', hostRef.$cmpMeta$.$tagName$);
1161
- const instance = hostRef.$lazyInstance$ ;
1162
- let promise;
1163
- if (isInitialLoad) {
1164
- {
1165
- promise = safeCall(instance, 'componentWillLoad');
1166
- }
1167
- }
1168
- {
1169
- promise = then(promise, () => safeCall(instance, 'componentWillRender'));
1170
- }
1171
- endSchedule();
1172
- return then(promise, () => updateComponent(hostRef, instance, isInitialLoad));
1173
- };
1174
- const updateComponent = async (hostRef, instance, isInitialLoad) => {
1175
- // updateComponent
1176
- const elm = hostRef.$hostElement$;
1177
- const endUpdate = createTime('update', hostRef.$cmpMeta$.$tagName$);
1178
- const rc = elm['s-rc'];
1179
- if (isInitialLoad) {
1180
- // DOM WRITE!
1181
- attachStyles(hostRef);
1182
- }
1183
- const endRender = createTime('render', hostRef.$cmpMeta$.$tagName$);
1184
- {
1185
- callRender(hostRef, instance);
1186
- }
1187
- if (rc) {
1188
- // ok, so turns out there are some child host elements
1189
- // waiting on this parent element to load
1190
- // let's fire off all update callbacks waiting
1191
- rc.map((cb) => cb());
1192
- elm['s-rc'] = undefined;
1193
- }
1194
- endRender();
1195
- endUpdate();
1196
- {
1197
- const childrenPromises = elm['s-p'];
1198
- const postUpdate = () => postUpdateComponent(hostRef);
1199
- if (childrenPromises.length === 0) {
1200
- postUpdate();
1201
- }
1202
- else {
1203
- Promise.all(childrenPromises).then(postUpdate);
1204
- hostRef.$flags$ |= 4 /* HOST_FLAGS.isWaitingForChildren */;
1205
- childrenPromises.length = 0;
1206
- }
1207
- }
1208
- };
1209
- const callRender = (hostRef, instance, elm) => {
1210
- try {
1211
- instance = instance.render() ;
1212
- {
1213
- hostRef.$flags$ &= ~16 /* HOST_FLAGS.isQueuedForUpdate */;
1214
- }
1215
- {
1216
- hostRef.$flags$ |= 2 /* HOST_FLAGS.hasRendered */;
1217
- }
1218
- {
1219
- {
1220
- // looks like we've got child nodes to render into this host element
1221
- // or we need to update the css class/attrs on the host element
1222
- // DOM WRITE!
1223
- {
1224
- renderVdom(hostRef, instance);
1225
- }
1226
- }
1227
- }
1228
- }
1229
- catch (e) {
1230
- consoleError(e, hostRef.$hostElement$);
1231
- }
1232
- return null;
1233
- };
1234
- const postUpdateComponent = (hostRef) => {
1235
- const tagName = hostRef.$cmpMeta$.$tagName$;
1236
- const elm = hostRef.$hostElement$;
1237
- const endPostUpdate = createTime('postUpdate', tagName);
1238
- const instance = hostRef.$lazyInstance$ ;
1239
- const ancestorComponent = hostRef.$ancestorComponent$;
1240
- if (!(hostRef.$flags$ & 64 /* HOST_FLAGS.hasLoadedComponent */)) {
1241
- hostRef.$flags$ |= 64 /* HOST_FLAGS.hasLoadedComponent */;
1242
- {
1243
- // DOM WRITE!
1244
- addHydratedFlag(elm);
1245
- }
1246
- {
1247
- safeCall(instance, 'componentDidLoad');
1248
- }
1249
- endPostUpdate();
1250
- {
1251
- hostRef.$onReadyResolve$(elm);
1252
- if (!ancestorComponent) {
1253
- appDidLoad();
1254
- }
1255
- }
1256
- }
1257
- else {
1258
- endPostUpdate();
1259
- }
1260
- {
1261
- hostRef.$onInstanceResolve$(elm);
1262
- }
1263
- // load events fire from bottom to top
1264
- // the deepest elements load first then bubbles up
1265
- {
1266
- if (hostRef.$onRenderResolve$) {
1267
- hostRef.$onRenderResolve$();
1268
- hostRef.$onRenderResolve$ = undefined;
1269
- }
1270
- if (hostRef.$flags$ & 512 /* HOST_FLAGS.needsRerender */) {
1271
- nextTick(() => scheduleUpdate(hostRef, false));
1272
- }
1273
- hostRef.$flags$ &= ~(4 /* HOST_FLAGS.isWaitingForChildren */ | 512 /* HOST_FLAGS.needsRerender */);
1274
- }
1275
- // ( •_•)
1276
- // ( •_•)>⌐■-■
1277
- // (⌐■_■)
1278
- };
1279
- const appDidLoad = (who) => {
1280
- // on appload
1281
- // we have finish the first big initial render
1282
- {
1283
- addHydratedFlag(doc.documentElement);
1284
- }
1285
- nextTick(() => emitEvent(win, 'appload', { detail: { namespace: NAMESPACE } }));
1286
- };
1287
- const safeCall = (instance, method, arg) => {
1288
- if (instance && instance[method]) {
1289
- try {
1290
- return instance[method](arg);
1291
- }
1292
- catch (e) {
1293
- consoleError(e);
1294
- }
1295
- }
1296
- return undefined;
1297
- };
1298
- const then = (promise, thenFn) => {
1299
- return promise && promise.then ? promise.then(thenFn) : thenFn();
1300
- };
1301
- const addHydratedFlag = (elm) => elm.classList.add('hydrated')
1302
- ;
1303
- const getValue = (ref, propName) => getHostRef(ref).$instanceValues$.get(propName);
1304
- const setValue = (ref, propName, newVal, cmpMeta) => {
1305
- // check our new property value against our internal value
1306
- const hostRef = getHostRef(ref);
1307
- const elm = hostRef.$hostElement$ ;
1308
- const oldVal = hostRef.$instanceValues$.get(propName);
1309
- const flags = hostRef.$flags$;
1310
- const instance = hostRef.$lazyInstance$ ;
1311
- newVal = parsePropertyValue(newVal, cmpMeta.$members$[propName][0]);
1312
- // explicitly check for NaN on both sides, as `NaN === NaN` is always false
1313
- const areBothNaN = Number.isNaN(oldVal) && Number.isNaN(newVal);
1314
- const didValueChange = newVal !== oldVal && !areBothNaN;
1315
- if ((!(flags & 8 /* HOST_FLAGS.isConstructingInstance */) || oldVal === undefined) && didValueChange) {
1316
- // gadzooks! the property's value has changed!!
1317
- // set our new value!
1318
- hostRef.$instanceValues$.set(propName, newVal);
1319
- if (instance) {
1320
- // get an array of method names of watch functions to call
1321
- if (cmpMeta.$watchers$ && flags & 128 /* HOST_FLAGS.isWatchReady */) {
1322
- const watchMethods = cmpMeta.$watchers$[propName];
1323
- if (watchMethods) {
1324
- // this instance is watching for when this property changed
1325
- watchMethods.map((watchMethodName) => {
1326
- try {
1327
- // fire off each of the watch methods that are watching this property
1328
- instance[watchMethodName](newVal, oldVal, propName);
1329
- }
1330
- catch (e) {
1331
- consoleError(e, elm);
1332
- }
1333
- });
1334
- }
1335
- }
1336
- if ((flags & (2 /* HOST_FLAGS.hasRendered */ | 16 /* HOST_FLAGS.isQueuedForUpdate */)) === 2 /* HOST_FLAGS.hasRendered */) {
1337
- // looks like this value actually changed, so we've got work to do!
1338
- // but only if we've already rendered, otherwise just chill out
1339
- // queue that we need to do an update, but don't worry about queuing
1340
- // up millions cuz this function ensures it only runs once
1341
- scheduleUpdate(hostRef, false);
1342
- }
1343
- }
1344
- }
1345
- };
1346
- /**
1347
- * Attach a series of runtime constructs to a compiled Stencil component
1348
- * constructor, including getters and setters for the `@Prop` and `@State`
1349
- * decorators, callbacks for when attributes change, and so on.
1350
- *
1351
- * @param Cstr the constructor for a component that we need to process
1352
- * @param cmpMeta metadata collected previously about the component
1353
- * @param flags a number used to store a series of bit flags
1354
- * @returns a reference to the same constructor passed in (but now mutated)
1355
- */
1356
- const proxyComponent = (Cstr, cmpMeta, flags) => {
1357
- if (cmpMeta.$members$) {
1358
- if (Cstr.watchers) {
1359
- cmpMeta.$watchers$ = Cstr.watchers;
1360
- }
1361
- // It's better to have a const than two Object.entries()
1362
- const members = Object.entries(cmpMeta.$members$);
1363
- const prototype = Cstr.prototype;
1364
- members.map(([memberName, [memberFlags]]) => {
1365
- if ((memberFlags & 31 /* MEMBER_FLAGS.Prop */ ||
1366
- ((flags & 2 /* PROXY_FLAGS.proxyState */) && memberFlags & 32 /* MEMBER_FLAGS.State */))) {
1367
- // proxyComponent - prop
1368
- Object.defineProperty(prototype, memberName, {
1369
- get() {
1370
- // proxyComponent, get value
1371
- return getValue(this, memberName);
1372
- },
1373
- set(newValue) {
1374
- // proxyComponent, set value
1375
- setValue(this, memberName, newValue, cmpMeta);
1376
- },
1377
- configurable: true,
1378
- enumerable: true,
1379
- });
1380
- }
1381
- else if (flags & 1 /* PROXY_FLAGS.isElementConstructor */ &&
1382
- memberFlags & 64 /* MEMBER_FLAGS.Method */) {
1383
- // proxyComponent - method
1384
- Object.defineProperty(prototype, memberName, {
1385
- value(...args) {
1386
- const ref = getHostRef(this);
1387
- return ref.$onInstancePromise$.then(() => ref.$lazyInstance$[memberName](...args));
1388
- },
1389
- });
1390
- }
1391
- });
1392
- if ((flags & 1 /* PROXY_FLAGS.isElementConstructor */)) {
1393
- const attrNameToPropName = new Map();
1394
- prototype.attributeChangedCallback = function (attrName, _oldValue, newValue) {
1395
- plt.jmp(() => {
1396
- const propName = attrNameToPropName.get(attrName);
1397
- // In a web component lifecycle the attributeChangedCallback runs prior to connectedCallback
1398
- // in the case where an attribute was set inline.
1399
- // ```html
1400
- // <my-component some-attribute="some-value"></my-component>
1401
- // ```
1402
- //
1403
- // There is an edge case where a developer sets the attribute inline on a custom element and then
1404
- // programmatically changes it before it has been upgraded as shown below:
1405
- //
1406
- // ```html
1407
- // <!-- this component has _not_ been upgraded yet -->
1408
- // <my-component id="test" some-attribute="some-value"></my-component>
1409
- // <script>
1410
- // // grab non-upgraded component
1411
- // el = document.querySelector("#test");
1412
- // el.someAttribute = "another-value";
1413
- // // upgrade component
1414
- // customElements.define('my-component', MyComponent);
1415
- // </script>
1416
- // ```
1417
- // In this case if we do not unshadow here and use the value of the shadowing property, attributeChangedCallback
1418
- // will be called with `newValue = "some-value"` and will set the shadowed property (this.someAttribute = "another-value")
1419
- // to the value that was set inline i.e. "some-value" from above example. When
1420
- // the connectedCallback attempts to unshadow it will use "some-value" as the initial value rather than "another-value"
1421
- //
1422
- // The case where the attribute was NOT set inline but was not set programmatically shall be handled/unshadowed
1423
- // by connectedCallback as this attributeChangedCallback will not fire.
1424
- //
1425
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1426
- //
1427
- // TODO(STENCIL-16) we should think about whether or not we actually want to be reflecting the attributes to
1428
- // properties here given that this goes against best practices outlined here
1429
- // https://developers.google.com/web/fundamentals/web-components/best-practices#avoid-reentrancy
1430
- if (this.hasOwnProperty(propName)) {
1431
- newValue = this[propName];
1432
- delete this[propName];
1433
- }
1434
- else if (prototype.hasOwnProperty(propName) &&
1435
- typeof this[propName] === 'number' &&
1436
- this[propName] == newValue) {
1437
- // if the propName exists on the prototype of `Cstr`, this update may be a result of Stencil using native
1438
- // APIs to reflect props as attributes. Calls to `setAttribute(someElement, propName)` will result in
1439
- // `propName` to be converted to a `DOMString`, which may not be what we want for other primitive props.
1440
- return;
1441
- }
1442
- this[propName] = newValue === null && typeof this[propName] === 'boolean' ? false : newValue;
1443
- });
1444
- };
1445
- // create an array of attributes to observe
1446
- // and also create a map of html attribute name to js property name
1447
- Cstr.observedAttributes = members
1448
- .filter(([_, m]) => m[0] & 15 /* MEMBER_FLAGS.HasAttribute */) // filter to only keep props that should match attributes
1449
- .map(([propName, m]) => {
1450
- const attrName = m[1] || propName;
1451
- attrNameToPropName.set(attrName, propName);
1452
- return attrName;
1453
- });
1454
- }
1455
- }
1456
- return Cstr;
1457
- };
1458
- const initializeComponent = async (elm, hostRef, cmpMeta, hmrVersionId, Cstr) => {
1459
- // initializeComponent
1460
- if ((hostRef.$flags$ & 32 /* HOST_FLAGS.hasInitializedComponent */) === 0) {
1461
- {
1462
- // we haven't initialized this element yet
1463
- hostRef.$flags$ |= 32 /* HOST_FLAGS.hasInitializedComponent */;
1464
- // lazy loaded components
1465
- // request the component's implementation to be
1466
- // wired up with the host element
1467
- Cstr = loadModule(cmpMeta);
1468
- if (Cstr.then) {
1469
- // Await creates a micro-task avoid if possible
1470
- const endLoad = uniqueTime();
1471
- Cstr = await Cstr;
1472
- endLoad();
1473
- }
1474
- if (!Cstr.isProxied) {
1475
- // we've never proxied this Constructor before
1476
- // let's add the getters/setters to its prototype before
1477
- // the first time we create an instance of the implementation
1478
- {
1479
- cmpMeta.$watchers$ = Cstr.watchers;
1480
- }
1481
- proxyComponent(Cstr, cmpMeta, 2 /* PROXY_FLAGS.proxyState */);
1482
- Cstr.isProxied = true;
1483
- }
1484
- const endNewInstance = createTime('createInstance', cmpMeta.$tagName$);
1485
- // ok, time to construct the instance
1486
- // but let's keep track of when we start and stop
1487
- // so that the getters/setters don't incorrectly step on data
1488
- {
1489
- hostRef.$flags$ |= 8 /* HOST_FLAGS.isConstructingInstance */;
1490
- }
1491
- // construct the lazy-loaded component implementation
1492
- // passing the hostRef is very important during
1493
- // construction in order to directly wire together the
1494
- // host element and the lazy-loaded instance
1495
- try {
1496
- new Cstr(hostRef);
1497
- }
1498
- catch (e) {
1499
- consoleError(e);
1500
- }
1501
- {
1502
- hostRef.$flags$ &= ~8 /* HOST_FLAGS.isConstructingInstance */;
1503
- }
1504
- {
1505
- hostRef.$flags$ |= 128 /* HOST_FLAGS.isWatchReady */;
1506
- }
1507
- endNewInstance();
1508
- fireConnectedCallback(hostRef.$lazyInstance$);
1509
- }
1510
- if (Cstr.style) {
1511
- // this component has styles but we haven't registered them yet
1512
- let style = Cstr.style;
1513
- const scopeId = getScopeId(cmpMeta);
1514
- if (!styles.has(scopeId)) {
1515
- const endRegisterStyles = createTime('registerStyles', cmpMeta.$tagName$);
1516
- registerStyle(scopeId, style, !!(cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */));
1517
- endRegisterStyles();
1518
- }
1519
- }
1520
- }
1521
- // we've successfully created a lazy instance
1522
- const ancestorComponent = hostRef.$ancestorComponent$;
1523
- const schedule = () => scheduleUpdate(hostRef, true);
1524
- if (ancestorComponent && ancestorComponent['s-rc']) {
1525
- // this is the initial load and this component it has an ancestor component
1526
- // but the ancestor component has NOT fired its will update lifecycle yet
1527
- // so let's just cool our jets and wait for the ancestor to continue first
1528
- // this will get fired off when the ancestor component
1529
- // finally gets around to rendering its lazy self
1530
- // fire off the initial update
1531
- ancestorComponent['s-rc'].push(schedule);
1532
- }
1533
- else {
1534
- schedule();
1535
- }
1536
- };
1537
- const fireConnectedCallback = (instance) => {
1538
- {
1539
- safeCall(instance, 'connectedCallback');
1540
- }
1541
- };
1542
- const connectedCallback = (elm) => {
1543
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1544
- const hostRef = getHostRef(elm);
1545
- const cmpMeta = hostRef.$cmpMeta$;
1546
- const endConnected = createTime('connectedCallback', cmpMeta.$tagName$);
1547
- if (!(hostRef.$flags$ & 1 /* HOST_FLAGS.hasConnected */)) {
1548
- // first time this component has connected
1549
- hostRef.$flags$ |= 1 /* HOST_FLAGS.hasConnected */;
1550
- {
1551
- // initUpdate
1552
- // if the slot polyfill is required we'll need to put some nodes
1553
- // in here to act as original content anchors as we move nodes around
1554
- // host element has been connected to the DOM
1555
- if ((cmpMeta.$flags$ & (4 /* CMP_FLAGS.hasSlotRelocation */ | 8 /* CMP_FLAGS.needsShadowDomShim */))) {
1556
- setContentReference(elm);
1557
- }
1558
- }
1559
- {
1560
- // find the first ancestor component (if there is one) and register
1561
- // this component as one of the actively loading child components for its ancestor
1562
- let ancestorComponent = elm;
1563
- while ((ancestorComponent = ancestorComponent.parentNode || ancestorComponent.host)) {
1564
- // climb up the ancestors looking for the first
1565
- // component that hasn't finished its lifecycle update yet
1566
- if (ancestorComponent['s-p']) {
1567
- // we found this components first ancestor component
1568
- // keep a reference to this component's ancestor component
1569
- attachToAncestor(hostRef, (hostRef.$ancestorComponent$ = ancestorComponent));
1570
- break;
1571
- }
1572
- }
1573
- }
1574
- // Lazy properties
1575
- // https://developers.google.com/web/fundamentals/web-components/best-practices#lazy-properties
1576
- if (cmpMeta.$members$) {
1577
- Object.entries(cmpMeta.$members$).map(([memberName, [memberFlags]]) => {
1578
- if (memberFlags & 31 /* MEMBER_FLAGS.Prop */ && elm.hasOwnProperty(memberName)) {
1579
- const value = elm[memberName];
1580
- delete elm[memberName];
1581
- elm[memberName] = value;
1582
- }
1583
- });
1584
- }
1585
- {
1586
- initializeComponent(elm, hostRef, cmpMeta);
1587
- }
1588
- }
1589
- else {
1590
- // fire off connectedCallback() on component instance
1591
- fireConnectedCallback(hostRef.$lazyInstance$);
1592
- }
1593
- endConnected();
1594
- }
1595
- };
1596
- const setContentReference = (elm) => {
1597
- // only required when we're NOT using native shadow dom (slot)
1598
- // or this browser doesn't support native shadow dom
1599
- // and this host element was NOT created with SSR
1600
- // let's pick out the inner content for slot projection
1601
- // create a node to represent where the original
1602
- // content was first placed, which is useful later on
1603
- const contentRefElm = (elm['s-cr'] = doc.createComment(''));
1604
- contentRefElm['s-cn'] = true;
1605
- elm.insertBefore(contentRefElm, elm.firstChild);
1606
- };
1607
- const disconnectedCallback = (elm) => {
1608
- if ((plt.$flags$ & 1 /* PLATFORM_FLAGS.isTmpDisconnected */) === 0) {
1609
- const hostRef = getHostRef(elm);
1610
- const instance = hostRef.$lazyInstance$ ;
1611
- {
1612
- safeCall(instance, 'disconnectedCallback');
1613
- }
1614
- }
1615
- };
1616
- const bootstrapLazy = (lazyBundles, options = {}) => {
1617
- const endBootstrap = createTime();
1618
- const cmpTags = [];
1619
- const exclude = options.exclude || [];
1620
- const customElements = win.customElements;
1621
- const head = doc.head;
1622
- const metaCharset = /*@__PURE__*/ head.querySelector('meta[charset]');
1623
- const visibilityStyle = /*@__PURE__*/ doc.createElement('style');
1624
- const deferredConnectedCallbacks = [];
1625
- let appLoadFallback;
1626
- let isBootstrapping = true;
1627
- Object.assign(plt, options);
1628
- plt.$resourcesUrl$ = new URL(options.resourcesUrl || './', doc.baseURI).href;
1629
- lazyBundles.map((lazyBundle) => {
1630
- lazyBundle[1].map((compactMeta) => {
1631
- const cmpMeta = {
1632
- $flags$: compactMeta[0],
1633
- $tagName$: compactMeta[1],
1634
- $members$: compactMeta[2],
1635
- $listeners$: compactMeta[3],
1636
- };
1637
- {
1638
- cmpMeta.$members$ = compactMeta[2];
1639
- }
1640
- {
1641
- cmpMeta.$watchers$ = {};
1642
- }
1643
- const tagName = cmpMeta.$tagName$;
1644
- const HostElement = class extends HTMLElement {
1645
- // StencilLazyHost
1646
- constructor(self) {
1647
- // @ts-ignore
1648
- super(self);
1649
- self = this;
1650
- registerHost(self, cmpMeta);
1651
- if (cmpMeta.$flags$ & 1 /* CMP_FLAGS.shadowDomEncapsulation */) {
1652
- // this component is using shadow dom
1653
- // and this browser supports shadow dom
1654
- // add the read-only property "shadowRoot" to the host element
1655
- // adding the shadow root build conditionals to minimize runtime
1656
- {
1657
- {
1658
- self.attachShadow({ mode: 'open' });
1659
- }
1660
- }
1661
- }
1662
- }
1663
- connectedCallback() {
1664
- if (appLoadFallback) {
1665
- clearTimeout(appLoadFallback);
1666
- appLoadFallback = null;
1667
- }
1668
- if (isBootstrapping) {
1669
- // connectedCallback will be processed once all components have been registered
1670
- deferredConnectedCallbacks.push(this);
1671
- }
1672
- else {
1673
- plt.jmp(() => connectedCallback(this));
1674
- }
1675
- }
1676
- disconnectedCallback() {
1677
- plt.jmp(() => disconnectedCallback(this));
1678
- }
1679
- componentOnReady() {
1680
- return getHostRef(this).$onReadyPromise$;
1681
- }
1682
- };
1683
- cmpMeta.$lazyBundleId$ = lazyBundle[0];
1684
- if (!exclude.includes(tagName) && !customElements.get(tagName)) {
1685
- cmpTags.push(tagName);
1686
- customElements.define(tagName, proxyComponent(HostElement, cmpMeta, 1 /* PROXY_FLAGS.isElementConstructor */));
1687
- }
1688
- });
1689
- });
1690
- {
1691
- visibilityStyle.innerHTML = cmpTags + HYDRATED_CSS;
1692
- visibilityStyle.setAttribute('data-styles', '');
1693
- head.insertBefore(visibilityStyle, metaCharset ? metaCharset.nextSibling : head.firstChild);
1694
- }
1695
- // Process deferred connectedCallbacks now all components have been registered
1696
- isBootstrapping = false;
1697
- if (deferredConnectedCallbacks.length) {
1698
- deferredConnectedCallbacks.map((host) => host.connectedCallback());
1699
- }
1700
- else {
1701
- {
1702
- plt.jmp(() => (appLoadFallback = setTimeout(appDidLoad, 30)));
1703
- }
1704
- }
1705
- // Fallback appLoad event
1706
- endBootstrap();
1707
- };
1708
- const hostRefs = /*@__PURE__*/ new WeakMap();
1709
- const getHostRef = (ref) => hostRefs.get(ref);
1710
- const registerInstance = (lazyInstance, hostRef) => hostRefs.set((hostRef.$lazyInstance$ = lazyInstance), hostRef);
1711
- const registerHost = (elm, cmpMeta) => {
1712
- const hostRef = {
1713
- $flags$: 0,
1714
- $hostElement$: elm,
1715
- $cmpMeta$: cmpMeta,
1716
- $instanceValues$: new Map(),
1717
- };
1718
- {
1719
- hostRef.$onInstancePromise$ = new Promise((r) => (hostRef.$onInstanceResolve$ = r));
1720
- }
1721
- {
1722
- hostRef.$onReadyPromise$ = new Promise((r) => (hostRef.$onReadyResolve$ = r));
1723
- elm['s-p'] = [];
1724
- elm['s-rc'] = [];
1725
- }
1726
- return hostRefs.set(elm, hostRef);
1727
- };
1728
- const isMemberInElement = (elm, memberName) => memberName in elm;
1729
- const consoleError = (e, el) => (0, console.error)(e, el);
1730
- const cmpModules = /*@__PURE__*/ new Map();
1731
- const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
1732
- // loadModuleImport
1733
- const exportName = cmpMeta.$tagName$.replace(/-/g, '_');
1734
- const bundleId = cmpMeta.$lazyBundleId$;
1735
- const module = cmpModules.get(bundleId) ;
1736
- if (module) {
1737
- return module[exportName];
1738
- }
1739
- /*!__STENCIL_STATIC_IMPORT_SWITCH__*/
1740
- return import(
1741
- /* @vite-ignore */
1742
- /* webpackInclude: /\.entry\.js$/ */
1743
- /* webpackExclude: /\.system\.entry\.js$/ */
1744
- /* webpackMode: "lazy" */
1745
- `./${bundleId}.entry.js${''}`).then((importedModule) => {
1746
- {
1747
- cmpModules.set(bundleId, importedModule);
1748
- }
1749
- return importedModule[exportName];
1750
- }, consoleError);
1751
- };
1752
- const styles = /*@__PURE__*/ new Map();
1753
- const win = typeof window !== 'undefined' ? window : {};
1754
- const doc = win.document || { head: {} };
1755
- const plt = {
1756
- $flags$: 0,
1757
- $resourcesUrl$: '',
1758
- jmp: (h) => h(),
1759
- raf: (h) => requestAnimationFrame(h),
1760
- ael: (el, eventName, listener, opts) => el.addEventListener(eventName, listener, opts),
1761
- rel: (el, eventName, listener, opts) => el.removeEventListener(eventName, listener, opts),
1762
- ce: (eventName, opts) => new CustomEvent(eventName, opts),
1763
- };
1764
- const promiseResolve = (v) => Promise.resolve(v);
1765
- const supportsConstructableStylesheets = /*@__PURE__*/ (() => {
1766
- try {
1767
- new CSSStyleSheet();
1768
- return typeof new CSSStyleSheet().replaceSync === 'function';
1769
- }
1770
- catch (e) { }
1771
- return false;
1772
- })()
1773
- ;
1774
- const queueDomReads = [];
1775
- const queueDomWrites = [];
1776
- const queueTask = (queue, write) => (cb) => {
1777
- queue.push(cb);
1778
- if (!queuePending) {
1779
- queuePending = true;
1780
- if (write && plt.$flags$ & 4 /* PLATFORM_FLAGS.queueSync */) {
1781
- nextTick(flush);
1782
- }
1783
- else {
1784
- plt.raf(flush);
1785
- }
1786
- }
1787
- };
1788
- const consume = (queue) => {
1789
- for (let i = 0; i < queue.length; i++) {
1790
- try {
1791
- queue[i](performance.now());
1792
- }
1793
- catch (e) {
1794
- consoleError(e);
1795
- }
1796
- }
1797
- queue.length = 0;
1798
- };
1799
- const flush = () => {
1800
- // always force a bunch of medium callbacks to run, but still have
1801
- // a throttle on how many can run in a certain time
1802
- // DOM READS!!!
1803
- consume(queueDomReads);
1804
- // DOM WRITES!!!
1805
- {
1806
- consume(queueDomWrites);
1807
- if ((queuePending = queueDomReads.length > 0)) {
1808
- // still more to do yet, but we've run out of time
1809
- // let's let this thing cool off and try again in the next tick
1810
- plt.raf(flush);
1811
- }
1812
- }
1813
- };
1814
- const nextTick = /*@__PURE__*/ (cb) => promiseResolve().then(cb);
1815
- const writeTask = /*@__PURE__*/ queueTask(queueDomWrites, true);
1816
-
1817
- export { Host as H, bootstrapLazy as b, createEvent as c, getElement as g, h, promiseResolve as p, registerInstance as r };