@pinegrow/vite-plugin 3.0.0-beta.56 → 3.0.0-beta.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-plugin.js +142 -138
- package/package.json +1 -1
package/dist/vue-plugin.js
CHANGED
|
@@ -11,52 +11,38 @@ export function usePinegrow() {
|
|
|
11
11
|
// console.log('Cache initialized by Pinegrow Vue Plugin!')
|
|
12
12
|
const elCache = reactive(new Map())
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
// return {
|
|
16
|
-
// name:
|
|
17
|
-
// getComponentName(elCacheObj.instance.type, elCacheObj.localFile) +
|
|
18
|
-
// `${elCacheObj.key !== undefined && elCacheObj.key !== null ? ` (${elCacheObj.key})` : ''}`,
|
|
19
|
-
// ...elCacheObj,
|
|
20
|
-
// }
|
|
21
|
-
// }
|
|
22
|
-
|
|
23
|
-
const enRichWithComponentName = elCacheObj => {
|
|
14
|
+
const enRichWithComponentName = (elCacheObj, localFile) => {
|
|
24
15
|
return {
|
|
25
16
|
name: elCacheObj.instance.type.__name || '',
|
|
17
|
+
localFile,
|
|
26
18
|
...elCacheObj,
|
|
27
19
|
}
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
const rootFragmentToPgIdComputed = computed(() => {
|
|
31
|
-
const rootEls = new Map()
|
|
32
|
-
for (let [key, value] of elCache.entries()) {
|
|
33
|
-
if (value.instance.isMounted && !value.instance.isUnmounted && value.isRootFragment) {
|
|
34
|
-
rootEls.set(key, value)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return rootEls
|
|
38
|
-
})
|
|
39
|
-
|
|
40
22
|
const pgIdToElComputed = computed(() => {
|
|
41
23
|
const pgIds = {}
|
|
42
|
-
for (let [
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
pgIds
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
24
|
+
for (let [el, elCacheNodeMap] of elCache.entries()) {
|
|
25
|
+
if (el.isConnected) {
|
|
26
|
+
for (let [instanceUid, elCacheObj] of elCacheNodeMap.entries()) {
|
|
27
|
+
if (
|
|
28
|
+
elCacheObj.instance.isMounted &&
|
|
29
|
+
!elCacheObj.instance.isUnmounted &&
|
|
30
|
+
elCacheObj.pgIds &&
|
|
31
|
+
elCacheObj.pgIds.length
|
|
32
|
+
// && (!elCacheObj.rootEl || elCacheObj.isRootFragment)
|
|
33
|
+
) {
|
|
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
|
+
})
|
|
58
44
|
}
|
|
59
|
-
}
|
|
45
|
+
}
|
|
60
46
|
}
|
|
61
47
|
}
|
|
62
48
|
return pgIds
|
|
@@ -64,17 +50,23 @@ export function usePinegrow() {
|
|
|
64
50
|
|
|
65
51
|
const localComponentToElComputed = computed(() => {
|
|
66
52
|
const localComponents = {}
|
|
67
|
-
for (let [
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
53
|
+
for (let [el, elCacheNodeMap] of elCache.entries()) {
|
|
54
|
+
if (el.isConnected) {
|
|
55
|
+
for (let [instanceUid, elCacheObj] of elCacheNodeMap.entries()) {
|
|
56
|
+
if (
|
|
57
|
+
elCacheObj.instance.isMounted &&
|
|
58
|
+
!elCacheObj.instance.isUnmounted &&
|
|
59
|
+
elCacheObj.localFile
|
|
60
|
+
// && (!elCacheObj.rootEl || elCacheObj.isRootFragment)
|
|
61
|
+
) {
|
|
62
|
+
if (!localComponents[elCacheObj.localFile]) {
|
|
63
|
+
localComponents[elCacheObj.localFile] = []
|
|
64
|
+
}
|
|
65
|
+
localComponents[elCacheObj.localFile].push(
|
|
66
|
+
enRichWithComponentName(elCacheObj, elCacheObj.localFile)
|
|
67
|
+
)
|
|
68
|
+
}
|
|
76
69
|
}
|
|
77
|
-
localComponents[value.localFile].push(enRichWithComponentName(value))
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
72
|
return localComponents
|
|
@@ -96,7 +88,7 @@ export function usePinegrow() {
|
|
|
96
88
|
// // Uncomment these two to test locally
|
|
97
89
|
// elCacheErrHandlerFn,
|
|
98
90
|
// elUpdateHanderFn,
|
|
99
|
-
rootFragmentToPgIdComputed,
|
|
91
|
+
// rootFragmentToPgIdComputed,
|
|
100
92
|
pgIdToElComputed,
|
|
101
93
|
localComponentToElComputed,
|
|
102
94
|
appTree,
|
|
@@ -116,7 +108,7 @@ export function usePinegrow() {
|
|
|
116
108
|
|
|
117
109
|
try {
|
|
118
110
|
if ((key !== null && key !== undefined) || (vnode.key !== null && vnode.key !== undefined)) {
|
|
119
|
-
key = key ||
|
|
111
|
+
key = vnode.key || key
|
|
120
112
|
}
|
|
121
113
|
localFile = localFile || vnode.type.__file
|
|
122
114
|
|
|
@@ -152,108 +144,112 @@ export function usePinegrow() {
|
|
|
152
144
|
// return
|
|
153
145
|
// }
|
|
154
146
|
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (key !== null && key !== undefined) {
|
|
161
|
-
pinegrow.elCache.get(el).key = key
|
|
147
|
+
// Text/comment node
|
|
148
|
+
if (isFragment) {
|
|
149
|
+
if (!rootEl) {
|
|
150
|
+
// root Fragment
|
|
151
|
+
isRootFragment = true
|
|
162
152
|
}
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
|
|
154
|
+
function isFragmentEl(instance) {
|
|
155
|
+
// return appRecord.options.types.Fragment === instance.subTree?.type
|
|
156
|
+
return instance.subTree.el.nodeType !== 1
|
|
165
157
|
}
|
|
166
|
-
} else {
|
|
167
|
-
// Text/comment node
|
|
168
|
-
if (isFragment) {
|
|
169
|
-
if (!rootEl) {
|
|
170
|
-
// root Fragment
|
|
171
|
-
isRootFragment = true
|
|
172
|
-
}
|
|
173
158
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return instance.subTree
|
|
159
|
+
function getRootVNodesFromComponentInstance(instance) {
|
|
160
|
+
if (isFragmentEl(instance)) {
|
|
161
|
+
return getFragmentRootVNodes(instance.subTree)
|
|
177
162
|
}
|
|
163
|
+
if (!instance.subTree) return []
|
|
164
|
+
return [instance.subTree]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function getFragmentRootVNodes(vnode) {
|
|
168
|
+
if (!vnode.children) return []
|
|
169
|
+
// children is v-if when the vnode has a condition
|
|
170
|
+
if (!Array.isArray(vnode.children)) return []
|
|
178
171
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
172
|
+
const list = []
|
|
173
|
+
|
|
174
|
+
for (let i = 0, l = vnode.children.length; i < l; i++) {
|
|
175
|
+
const childVnode = vnode.children[i]
|
|
176
|
+
if (childVnode.component) {
|
|
177
|
+
list.push(...getRootVNodesFromComponentInstance(childVnode.component))
|
|
178
|
+
} else if (childVnode) {
|
|
179
|
+
list.push(childVnode)
|
|
182
180
|
}
|
|
183
|
-
if (!instance.subTree) return []
|
|
184
|
-
return [instance.subTree]
|
|
185
181
|
}
|
|
186
182
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const list = []
|
|
183
|
+
return list
|
|
184
|
+
}
|
|
191
185
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
let childVNodes = getRootVNodesFromComponentInstance(instance)
|
|
187
|
+
|
|
188
|
+
if (!childVNodes.length) {
|
|
189
|
+
// For NuxtLayout, no childVNodes are returned, the subTree.children is in fact an object {ctx: {}, default: f}
|
|
190
|
+
if (el.nextElementSibling) {
|
|
191
|
+
const childEl = el.nextElementSibling
|
|
192
|
+
firstEl = lastEl = childEl
|
|
193
|
+
const childInstance = childEl.$ || childEl.__vueParentComponent
|
|
194
|
+
const childVNode = childInstance?.vnode // or subTree?
|
|
195
|
+
if (childVNode) {
|
|
196
|
+
childVNodes.push(childVNode)
|
|
199
197
|
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
200
|
|
|
201
|
-
|
|
201
|
+
if (childVNodes.length) {
|
|
202
|
+
// Filter out recursive vnodes text1 -> div, text1 (happens when text1 is the closest to a fragment with div & slot)
|
|
203
|
+
childVNodes = childVNodes.filter(childVNode => childVNode.el !== el)
|
|
204
|
+
|
|
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
|
|
202
210
|
}
|
|
203
211
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const childEl = el.nextElementSibling
|
|
210
|
-
firstEl = lastEl = childEl
|
|
211
|
-
const childInstance = childEl.$ || childEl.__vueParentComponent
|
|
212
|
-
const childVNode = childInstance?.vnode // or subTree?
|
|
213
|
-
if (childVNode) {
|
|
214
|
-
childVNodes.push(childVNode)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
212
|
+
if (firstEl && firstEl.nodeType !== 1) {
|
|
213
|
+
firstEl = firstEl.nextElementSibling
|
|
214
|
+
}
|
|
215
|
+
if (lastEl && lastEl.nodeType !== 1) {
|
|
216
|
+
lastEl = lastEl.nextElementSibling
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
childVNodes.forEach(childVNode => {
|
|
220
|
+
pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
}
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
let elCacheObj = {
|
|
226
|
+
el,
|
|
227
|
+
isRootFragment,
|
|
228
|
+
rootEl,
|
|
229
|
+
vnode,
|
|
230
|
+
instance,
|
|
231
|
+
isFragment,
|
|
232
|
+
firstEl,
|
|
233
|
+
lastEl,
|
|
234
|
+
pgIds: pgId ? [pgId] : [],
|
|
235
|
+
key,
|
|
236
|
+
localFile,
|
|
237
|
+
isIsland,
|
|
238
|
+
}
|
|
229
239
|
|
|
230
|
-
|
|
231
|
-
firstEl = firstEl.nextElementSibling
|
|
232
|
-
}
|
|
233
|
-
if (lastEl && lastEl.nodeType !== 1) {
|
|
234
|
-
lastEl = lastEl.nextElementSibling
|
|
235
|
-
}
|
|
240
|
+
let prevElCacheNodeMap = pinegrow.elCache.get(el)
|
|
236
241
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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 })
|
|
250
|
+
} else {
|
|
251
|
+
prevElCacheNodeMap.set(instance.uid, elCacheObj)
|
|
241
252
|
}
|
|
242
|
-
|
|
243
|
-
pinegrow.elCache.set(el, {
|
|
244
|
-
el,
|
|
245
|
-
isRootFragment,
|
|
246
|
-
rootEl,
|
|
247
|
-
vnode,
|
|
248
|
-
instance,
|
|
249
|
-
isFragment,
|
|
250
|
-
firstEl,
|
|
251
|
-
lastEl,
|
|
252
|
-
pgIds: pgId ? [pgId] : [],
|
|
253
|
-
key,
|
|
254
|
-
localFile,
|
|
255
|
-
isIsland,
|
|
256
|
-
})
|
|
257
253
|
}
|
|
258
254
|
|
|
259
255
|
if (pinegrow.elUpdateHanderFn) {
|
|
@@ -277,7 +273,7 @@ export function usePinegrow() {
|
|
|
277
273
|
|
|
278
274
|
const elCacheErrHandlerFn = () => {
|
|
279
275
|
if (message) {
|
|
280
|
-
console.log(message)
|
|
276
|
+
// console.log(message)
|
|
281
277
|
}
|
|
282
278
|
}
|
|
283
279
|
|
|
@@ -287,10 +283,19 @@ export function usePinegrow() {
|
|
|
287
283
|
// console.log(value)
|
|
288
284
|
// }
|
|
289
285
|
// }
|
|
290
|
-
for (let [
|
|
291
|
-
if (
|
|
292
|
-
pinegrow.elCache.delete(
|
|
293
|
-
|
|
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)
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!elCacheNodeMap.size) {
|
|
298
|
+
pinegrow.elCache.delete(el)
|
|
294
299
|
}
|
|
295
300
|
}
|
|
296
301
|
}
|
|
@@ -303,7 +308,6 @@ export function usePinegrow() {
|
|
|
303
308
|
const vnode = instance?.vnode
|
|
304
309
|
const el = vnode?.el
|
|
305
310
|
const localFile = instance.type.__file && !instance.type.__file.includes('node_modules') && instance.type.__file
|
|
306
|
-
|
|
307
311
|
if (instance && vnode && el) {
|
|
308
312
|
rootVNode.value = vnode
|
|
309
313
|
pgUpdateElCache('mounted', null, null, null, localFile)(vnode)
|