@pinegrow/vite-plugin 3.0.0-beta.58 → 3.0.0-beta.59

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.
@@ -11,7 +11,7 @@ export function usePinegrow() {
11
11
  // console.log('Cache initialized by Pinegrow Vue Plugin!')
12
12
  const elCache = reactive(new Map())
13
13
 
14
- const enRichWithComponentName = (elCacheObj, localFile) => {
14
+ const enrichWithComponentName = (elCacheObj, localFile) => {
15
15
  return {
16
16
  name: elCacheObj.instance.type.__name || '',
17
17
  localFile,
@@ -21,28 +21,25 @@ export function usePinegrow() {
21
21
 
22
22
  const pgIdToElComputed = computed(() => {
23
23
  const pgIds = {}
24
- for (let [el, elCacheNodeMap] of elCache.entries()) {
24
+ for (let [el, elCacheNodes] of elCache.entries()) {
25
25
  if (el.isConnected) {
26
- for (let [instanceUid, elCacheObj] of elCacheNodeMap.entries()) {
26
+ elCacheNodes.forEach(elCacheObj => {
27
27
  if (
28
28
  elCacheObj.instance.isMounted &&
29
29
  !elCacheObj.instance.isUnmounted &&
30
- elCacheObj.pgIds &&
31
- elCacheObj.pgIds.length
32
- // && (!elCacheObj.rootEl || elCacheObj.isRootFragment)
30
+ elCacheObj.pgId &&
31
+ (!elCacheObj.rootEl || elCacheObj.isRootFragment)
33
32
  ) {
34
- elCacheObj.pgIds.forEach(pgId => {
35
- if (!pgIds[pgId]) {
36
- pgIds[pgId] = []
37
- }
38
- if (elCacheObj.key === undefined || elCacheObj.key === null) {
39
- pgIds[pgId].push(elCacheObj)
40
- } else {
41
- pgIds[pgId].push([elCacheObj.key, elCacheObj])
42
- }
43
- })
33
+ if (!pgIds[elCacheObj.pgId]) {
34
+ pgIds[elCacheObj.pgId] = []
35
+ }
36
+ if (elCacheObj.key === undefined || elCacheObj.key === null) {
37
+ pgIds[elCacheObj.pgId].push(elCacheObj)
38
+ } else {
39
+ pgIds[elCacheObj.pgId].push([elCacheObj.key, elCacheObj])
40
+ }
44
41
  }
45
- }
42
+ })
46
43
  }
47
44
  }
48
45
  return pgIds
@@ -50,9 +47,9 @@ export function usePinegrow() {
50
47
 
51
48
  const localComponentToElComputed = computed(() => {
52
49
  const localComponents = {}
53
- for (let [el, elCacheNodeMap] of elCache.entries()) {
50
+ for (let [el, elCacheNodes] of elCache.entries()) {
54
51
  if (el.isConnected) {
55
- for (let [instanceUid, elCacheObj] of elCacheNodeMap.entries()) {
52
+ elCacheNodes.forEach(elCacheObj => {
56
53
  if (
57
54
  elCacheObj.instance.isMounted &&
58
55
  !elCacheObj.instance.isUnmounted &&
@@ -63,10 +60,10 @@ export function usePinegrow() {
63
60
  localComponents[elCacheObj.localFile] = []
64
61
  }
65
62
  localComponents[elCacheObj.localFile].push(
66
- enRichWithComponentName(elCacheObj, elCacheObj.localFile)
63
+ enrichWithComponentName(elCacheObj, elCacheObj.localFile)
67
64
  )
68
65
  }
69
- }
66
+ })
70
67
  }
71
68
  }
72
69
  return localComponents
@@ -104,19 +101,23 @@ export function usePinegrow() {
104
101
  if (!window.pinegrow) initCache()
105
102
 
106
103
  let el = vnode.el
104
+ if (!el) return
105
+
107
106
  const instance = vnode.component || vnode.ctx || el.__vueParentComponent
108
107
 
109
108
  try {
110
109
  if ((key !== null && key !== undefined) || (vnode.key !== null && vnode.key !== undefined)) {
111
110
  key = vnode.key || key
112
111
  }
112
+
113
113
  localFile = localFile || vnode.type.__file
114
114
 
115
115
  let isRootFragment = false
116
116
  let isFragment = el.nodeType !== 1
117
117
  let firstEl,
118
118
  lastEl,
119
- isIsland = false
119
+ isIsland = false,
120
+ childVNodes = []
120
121
 
121
122
  // May be an iles Island that wraps components with client directives
122
123
  if (localFile) {
@@ -131,6 +132,16 @@ export function usePinegrow() {
131
132
  }
132
133
  }
133
134
 
135
+ const localFileFromInstance = instance.type.__file
136
+ if (
137
+ localFileFromInstance &&
138
+ localFileFromInstance.includes('node_modules/iles') &&
139
+ localFileFromInstance.includes('Island.vue')
140
+ ) {
141
+ // Retain localFiles of iles island to apply to child elements
142
+ isIsland = true
143
+ }
144
+
134
145
  // // Computed props anyway filters out unmounted ones, and we use the local components unmounted hooks to cleanup unmounted nodes. Using the unmounted hook seems to be out of sync when el is reused but instance is remounted.
135
146
  // if (hook === 'unmounted') {
136
147
  // if (pinegrow.elCache.has(el)) {
@@ -183,7 +194,7 @@ export function usePinegrow() {
183
194
  return list
184
195
  }
185
196
 
186
- let childVNodes = getRootVNodesFromComponentInstance(instance)
197
+ childVNodes = getRootVNodesFromComponentInstance(instance)
187
198
 
188
199
  if (!childVNodes.length) {
189
200
  // For NuxtLayout, no childVNodes are returned, the subTree.children is in fact an object {ctx: {}, default: f}
@@ -202,23 +213,21 @@ export function usePinegrow() {
202
213
  // Filter out recursive vnodes text1 -> div, text1 (happens when text1 is the closest to a fragment with div & slot)
203
214
  childVNodes = childVNodes.filter(childVNode => childVNode.el !== el)
204
215
 
205
- if (childVNodes.length === 1) {
206
- firstEl = lastEl = childVNodes[0].el
207
- } else {
208
- firstEl = childVNodes[0].el
209
- lastEl = childVNodes[childVNodes.length - 1].el
210
- }
216
+ if (childVNodes.length) {
217
+ if (childVNodes.length === 1) {
218
+ firstEl = lastEl = childVNodes[0].el
219
+ } else {
220
+ firstEl = childVNodes[0].el
221
+ lastEl = childVNodes[childVNodes.length - 1].el
222
+ }
211
223
 
212
- if (firstEl && firstEl.nodeType !== 1) {
213
- firstEl = firstEl.nextElementSibling
214
- }
215
- if (lastEl && lastEl.nodeType !== 1) {
216
- lastEl = lastEl.nextElementSibling
224
+ if (firstEl && firstEl.nodeType !== 1) {
225
+ firstEl = firstEl.nextElementSibling
226
+ }
227
+ if (lastEl && lastEl.nodeType !== 1) {
228
+ lastEl = lastEl.nextElementSibling
229
+ }
217
230
  }
218
-
219
- childVNodes.forEach(childVNode => {
220
- pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
221
- })
222
231
  }
223
232
  }
224
233
 
@@ -231,31 +240,38 @@ export function usePinegrow() {
231
240
  isFragment,
232
241
  firstEl,
233
242
  lastEl,
234
- pgIds: pgId ? [pgId] : [],
243
+ pgId,
235
244
  key,
236
245
  localFile,
237
246
  isIsland,
238
247
  }
239
248
 
240
- let prevElCacheNodeMap = pinegrow.elCache.get(el)
249
+ let prevElCacheNodes = pinegrow.elCache.get(el)
241
250
 
242
- if (!prevElCacheNodeMap) {
243
- const newElCacheNodeMap = new Map()
244
- pinegrow.elCache.set(el, newElCacheNodeMap)
245
- newElCacheNodeMap.set(instance.uid, elCacheObj)
246
- } else {
247
- const prevElCacheObj = prevElCacheNodeMap.get(instance.uid)
248
- if (prevElCacheObj && prevElCacheObj.localFile) {
249
- prevElCacheNodeMap.set(instance.uid, { ...elCacheObj, localFile: prevElCacheObj.localFile })
251
+ if (prevElCacheNodes) {
252
+ let index = prevElCacheNodes.findIndex(elCacheObj => elCacheObj.instance.uid === instance.uid)
253
+
254
+ if (index > -1) {
255
+ const prevElCacheObj = prevElCacheNodes[index]
256
+ elCacheObj.localFile = elCacheObj.localFile || prevElCacheObj.localFile
257
+ elCacheObj.pgId = elCacheObj.pgId || prevElCacheObj.pgId
258
+ prevElCacheNodes[index] = elCacheObj
250
259
  } else {
251
- prevElCacheNodeMap.set(instance.uid, elCacheObj)
260
+ prevElCacheNodes.push(elCacheObj)
252
261
  }
262
+ pinegrow.elCache.set(el, prevElCacheNodes)
263
+ } else {
264
+ pinegrow.elCache.set(el, [elCacheObj])
265
+ childVNodes.forEach(childVNode => {
266
+ pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
267
+ })
253
268
  }
254
269
 
255
270
  if (pinegrow.elUpdateHanderFn) {
256
271
  pinegrow.elUpdateHanderFn(el)
257
272
  }
258
273
  } catch (err) {
274
+ console.log(err)
259
275
  if (pinegrow.elCacheErrHandlerFn) {
260
276
  pinegrow.elCacheErrHandlerFn(vnode, hook, rootEl, pgId, key, el, instance, err.message)
261
277
  }
@@ -283,18 +299,19 @@ export function usePinegrow() {
283
299
  // console.log(value)
284
300
  // }
285
301
  // }
286
- for (let [el, elCacheNodeMap] of pinegrow.elCache.entries()) {
287
- if (!el.isConnected) {
288
- pinegrow.elCache.delete(el)
289
- continue
290
- }
291
- for (let [instance, elCacheObj] of elCacheNodeMap.entries()) {
292
- if (elCacheObj.instance.isUnmounted) {
293
- elCacheNodeMap.delete(instance)
294
- // console.log(elCacheObj)
302
+ for (let [el, elCacheNodes] of pinegrow.elCache.entries()) {
303
+ // if (!el.isConnected) {
304
+ // pinegrow.elCache.delete(el)
305
+ // continue
306
+ // }
307
+ const cleanedUpElCacheNodes = elCacheNodes.filter(
308
+ elCacheObj => !elCacheObj.instance.isUnmounted // || elCacheObj.localFile
309
+ )
310
+ if (cleanedUpElCacheNodes.length) {
311
+ if (cleanedUpElCacheNodes.length !== elCacheNodes.length) {
312
+ pinegrow.elCache.set(el, cleanedUpElCacheNodes)
295
313
  }
296
- }
297
- if (!elCacheNodeMap.size) {
314
+ } else {
298
315
  pinegrow.elCache.delete(el)
299
316
  }
300
317
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinegrow/vite-plugin",
3
- "version": "3.0.0-beta.58",
3
+ "version": "3.0.0-beta.59",
4
4
  "description": "Pinegrow Vite Plugin",
5
5
  "type": "module",
6
6
  "files": [