@pinegrow/vite-plugin 3.0.35-beta.1 → 3.0.35-beta.10
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/LICENSE +20 -20
- package/README.md +204 -204
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/vue/index.js +319 -319
- package/package.json +50 -50
- package/types.d.ts +140 -140
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import pkg from './index.cjs'
|
|
2
|
-
var liveDesigner = pkg.liveDesigner
|
|
3
|
-
export { liveDesigner }
|
|
4
|
-
export default pkg
|
|
1
|
+
import pkg from './index.cjs'
|
|
2
|
+
var liveDesigner = pkg.liveDesigner
|
|
3
|
+
export { liveDesigner }
|
|
4
|
+
export default pkg
|
package/dist/vue/index.js
CHANGED
|
@@ -1,319 +1,319 @@
|
|
|
1
|
-
import {
|
|
2
|
-
onBeforeMount,
|
|
3
|
-
onMounted,
|
|
4
|
-
onBeforeUnmount,
|
|
5
|
-
getCurrentInstance,
|
|
6
|
-
ref,
|
|
7
|
-
reactive,
|
|
8
|
-
onUpdated,
|
|
9
|
-
computed,
|
|
10
|
-
watch,
|
|
11
|
-
} from 'vue'
|
|
12
|
-
|
|
13
|
-
export function usePinegrow() {
|
|
14
|
-
const initCache = () => {
|
|
15
|
-
// conditional
|
|
16
|
-
const winObj = window
|
|
17
|
-
|
|
18
|
-
if (!(winObj?.process?.client && winObj.process.client !== true)) {
|
|
19
|
-
if (!winObj.pinegrow) {
|
|
20
|
-
// console.log('Cache initialized by Vue Plugin!')
|
|
21
|
-
const elCache = reactive(new Map())
|
|
22
|
-
|
|
23
|
-
const enrichWithComponentName = (elCacheObj, localFile) => {
|
|
24
|
-
return {
|
|
25
|
-
name: elCacheObj.instance.type.__name || '',
|
|
26
|
-
localFile,
|
|
27
|
-
...elCacheObj,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
winObj.pinegrow = {
|
|
32
|
-
elCache,
|
|
33
|
-
// pgIdToElComputed,
|
|
34
|
-
// localComponentToElComputed,
|
|
35
|
-
// appTree,
|
|
36
|
-
reactiveFromContext: reactive,
|
|
37
|
-
refFromContext: ref,
|
|
38
|
-
computedFromContext: computed,
|
|
39
|
-
watchFromContext: watch,
|
|
40
|
-
// // Uncomment these two to test locally
|
|
41
|
-
// elCacheErrHandlerFn,
|
|
42
|
-
// elUpdateHanderFn,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// pgId & key can be optional
|
|
49
|
-
const pgUpdateElCache = (hook, pgId, rootEl, key, localFile) => async vnode => {
|
|
50
|
-
if (!vnode) return
|
|
51
|
-
if (window?.process?.client && process?.client !== true) return
|
|
52
|
-
if (!window.pinegrow) initCache()
|
|
53
|
-
|
|
54
|
-
let el = vnode.el
|
|
55
|
-
|
|
56
|
-
const instance = vnode.component || vnode.ctx || el.__vueParentComponent
|
|
57
|
-
|
|
58
|
-
if (!el || !instance) return
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
if ((key !== null && key !== undefined) || (vnode.key !== null && vnode.key !== undefined)) {
|
|
62
|
-
key = vnode.key || key
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
localFile = localFile || vnode.type.__file
|
|
66
|
-
|
|
67
|
-
let isRootFragment = false
|
|
68
|
-
let isFragment = el.nodeType !== 1
|
|
69
|
-
let firstEl,
|
|
70
|
-
lastEl,
|
|
71
|
-
isIsland = false,
|
|
72
|
-
childVNodes = []
|
|
73
|
-
|
|
74
|
-
// May be an iles Island that wraps components with client directives
|
|
75
|
-
if (localFile) {
|
|
76
|
-
if (localFile.includes('node_modules/iles') && localFile.includes('Island.vue')) {
|
|
77
|
-
// Retain localFiles of iles island to apply to child elements
|
|
78
|
-
isIsland = true
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (localFile.includes('node_modules')) {
|
|
82
|
-
// Ignore SFCs from node_modules
|
|
83
|
-
localFile = null
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const localFileFromInstance = instance.type.__file
|
|
88
|
-
if (
|
|
89
|
-
localFileFromInstance &&
|
|
90
|
-
localFileFromInstance.includes('node_modules/iles') &&
|
|
91
|
-
localFileFromInstance.includes('Island.vue')
|
|
92
|
-
) {
|
|
93
|
-
// Retain localFiles of iles island to apply to child elements
|
|
94
|
-
isIsland = true
|
|
95
|
-
|
|
96
|
-
localFile = instance.props.component?.__file || instance.props.importFrom
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// // 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.
|
|
100
|
-
// if (hook === 'unmounted') {
|
|
101
|
-
// if (pinegrow.elCache.has(el)) {
|
|
102
|
-
// pinegrow.elCache.delete(el)
|
|
103
|
-
// }
|
|
104
|
-
// for (let [key, value] of pinegrow.elCache.entries()) {
|
|
105
|
-
// if (value.rootEl === rootEl) {
|
|
106
|
-
// pinegrow.elCache.delete(key)
|
|
107
|
-
// }
|
|
108
|
-
// }
|
|
109
|
-
// return
|
|
110
|
-
// }
|
|
111
|
-
|
|
112
|
-
// Text/comment node
|
|
113
|
-
if (isFragment) {
|
|
114
|
-
if (!rootEl) {
|
|
115
|
-
// root Fragment
|
|
116
|
-
isRootFragment = true
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function isFragmentEl(instance) {
|
|
120
|
-
// return appRecord.options.types.Fragment === instance.subTree?.type
|
|
121
|
-
return instance.subTree.el.nodeType !== 1
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getRootVNodesFromComponentInstance(instance) {
|
|
125
|
-
if (isFragmentEl(instance)) {
|
|
126
|
-
return getFragmentRootVNodes(instance.subTree)
|
|
127
|
-
}
|
|
128
|
-
if (!instance.subTree) return []
|
|
129
|
-
return [instance.subTree]
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function getFragmentRootVNodes(vnode) {
|
|
133
|
-
if (!vnode.children) return []
|
|
134
|
-
// children is v-if when the vnode has a condition
|
|
135
|
-
if (!Array.isArray(vnode.children)) return []
|
|
136
|
-
|
|
137
|
-
const list = []
|
|
138
|
-
|
|
139
|
-
for (let i = 0, l = vnode.children.length; i < l; i++) {
|
|
140
|
-
const childVnode = vnode.children[i]
|
|
141
|
-
if (childVnode.component) {
|
|
142
|
-
list.push(...getRootVNodesFromComponentInstance(childVnode.component))
|
|
143
|
-
} else if (childVnode) {
|
|
144
|
-
list.push(childVnode)
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return list
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
childVNodes = getRootVNodesFromComponentInstance(instance)
|
|
152
|
-
|
|
153
|
-
if (!childVNodes.length) {
|
|
154
|
-
// For NuxtLayout, no childVNodes are returned, the subTree.children is in fact an object {ctx: {}, default: f}
|
|
155
|
-
if (el.nextElementSibling) {
|
|
156
|
-
const childEl = el.nextElementSibling
|
|
157
|
-
firstEl = lastEl = childEl
|
|
158
|
-
const childInstance = childEl.$ || childEl.__vueParentComponent
|
|
159
|
-
const childVNode = childInstance?.vnode // or subTree?
|
|
160
|
-
if (childVNode) {
|
|
161
|
-
childVNodes.push(childVNode)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (childVNodes.length) {
|
|
167
|
-
// Filter out recursive vnodes text1 -> div, text1 (happens when text1 is the closest to a fragment with div & slot)
|
|
168
|
-
childVNodes = childVNodes.filter(childVNode => childVNode.el !== el)
|
|
169
|
-
|
|
170
|
-
if (childVNodes.length) {
|
|
171
|
-
if (childVNodes.length === 1) {
|
|
172
|
-
firstEl = lastEl = childVNodes[0].el
|
|
173
|
-
} else {
|
|
174
|
-
firstEl = childVNodes[0].el
|
|
175
|
-
lastEl = childVNodes[childVNodes.length - 1].el
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (firstEl && firstEl.nodeType !== 1) {
|
|
179
|
-
firstEl = firstEl.nextElementSibling
|
|
180
|
-
}
|
|
181
|
-
if (lastEl && lastEl.nodeType !== 1) {
|
|
182
|
-
lastEl = lastEl.nextElementSibling
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (isIsland && !isRootFragment) {
|
|
189
|
-
return
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
let elCacheObj = {
|
|
193
|
-
el,
|
|
194
|
-
isRootFragment,
|
|
195
|
-
rootEl,
|
|
196
|
-
vnode,
|
|
197
|
-
instance,
|
|
198
|
-
isFragment,
|
|
199
|
-
firstEl,
|
|
200
|
-
lastEl,
|
|
201
|
-
pgId,
|
|
202
|
-
key,
|
|
203
|
-
localFile,
|
|
204
|
-
isIsland,
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
let prevElCacheNodes = pinegrow.elCache.get(el)
|
|
208
|
-
|
|
209
|
-
if (prevElCacheNodes) {
|
|
210
|
-
let index = prevElCacheNodes.findIndex(elCacheObj => elCacheObj.instance.uid === instance.uid)
|
|
211
|
-
|
|
212
|
-
if (index > -1) {
|
|
213
|
-
const prevElCacheObj = prevElCacheNodes[index]
|
|
214
|
-
elCacheObj.localFile = elCacheObj.localFile || prevElCacheObj.localFile
|
|
215
|
-
if (elCacheObj.pgId && prevElCacheObj.pgId && elCacheObj.pgId !== prevElCacheObj.pgId) {
|
|
216
|
-
if (!prevElCacheNodes.map(prevElCacheNode => prevElCacheNode.pgId).includes(elCacheObj.pgId)) {
|
|
217
|
-
prevElCacheNodes.push(elCacheObj)
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
elCacheObj.pgId = elCacheObj.pgId || prevElCacheObj.pgId
|
|
221
|
-
prevElCacheNodes[index] = elCacheObj
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
prevElCacheNodes.push(elCacheObj)
|
|
225
|
-
}
|
|
226
|
-
pinegrow.elCache.set(el, prevElCacheNodes)
|
|
227
|
-
} else {
|
|
228
|
-
pinegrow.elCache.set(el, [elCacheObj])
|
|
229
|
-
childVNodes.forEach(childVNode => {
|
|
230
|
-
pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (pinegrow.elUpdateHanderFn) {
|
|
235
|
-
pinegrow.elUpdateHanderFn(el)
|
|
236
|
-
}
|
|
237
|
-
} catch (err) {
|
|
238
|
-
console.log(err)
|
|
239
|
-
if (pinegrow.elCacheErrHandlerFn) {
|
|
240
|
-
pinegrow.elCacheErrHandlerFn(vnode, hook, rootEl, pgId, key, el, instance, err.message)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const elUpdateHanderFn = el => {
|
|
246
|
-
// if (pinegrow.elCache.has(el)) {
|
|
247
|
-
// const { pgId } = pinegrow.elCache.get(el)
|
|
248
|
-
// if (pgId) {
|
|
249
|
-
// // console.log(`Reselect ${pgId}`)
|
|
250
|
-
// }
|
|
251
|
-
// }
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const elCacheErrHandlerFn = () => {
|
|
255
|
-
if (message) {
|
|
256
|
-
// console.log(message)
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const cleanupCache = () => {
|
|
261
|
-
// for (let [key, value] of pinegrow.elCache.entries()) {
|
|
262
|
-
// if (value.isFragment && !value.firstEl) {
|
|
263
|
-
// console.log(value)
|
|
264
|
-
// }
|
|
265
|
-
// }
|
|
266
|
-
for (let [el, elCacheNodes] of pinegrow.elCache.entries()) {
|
|
267
|
-
// if (!el.isConnected) {
|
|
268
|
-
// pinegrow.elCache.delete(el)
|
|
269
|
-
// continue
|
|
270
|
-
// }
|
|
271
|
-
const cleanedUpElCacheNodes = elCacheNodes.filter(
|
|
272
|
-
elCacheObj => !elCacheObj.instance.isUnmounted // || elCacheObj.localFile
|
|
273
|
-
)
|
|
274
|
-
if (cleanedUpElCacheNodes.length) {
|
|
275
|
-
if (cleanedUpElCacheNodes.length !== elCacheNodes.length) {
|
|
276
|
-
pinegrow.elCache.set(el, cleanedUpElCacheNodes)
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
pinegrow.elCache.delete(el)
|
|
280
|
-
}
|
|
281
|
-
if (pinegrow.elUpdateHanderFn) {
|
|
282
|
-
pinegrow.elUpdateHanderFn(el)
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Local Component
|
|
288
|
-
const rootVNode = ref(null)
|
|
289
|
-
|
|
290
|
-
const mountLocalComponent = () => {
|
|
291
|
-
const instance = getCurrentInstance()
|
|
292
|
-
const vnode = instance?.vnode
|
|
293
|
-
const el = vnode?.el
|
|
294
|
-
const localFile = instance.type.__file && !instance.type.__file.includes('node_modules') && instance.type.__file
|
|
295
|
-
if (instance && vnode && el) {
|
|
296
|
-
rootVNode.value = vnode
|
|
297
|
-
pgUpdateElCache('mounted', null, null, null, localFile)(vnode)
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const unmountLocalComponent = () => {
|
|
302
|
-
if (rootVNode.value) {
|
|
303
|
-
pgUpdateElCache('unmounted')(rootVNode.value)
|
|
304
|
-
}
|
|
305
|
-
cleanupCache()
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
onBeforeMount(() => initCache())
|
|
309
|
-
onMounted(() => {
|
|
310
|
-
mountLocalComponent()
|
|
311
|
-
})
|
|
312
|
-
onBeforeUnmount(() => unmountLocalComponent())
|
|
313
|
-
onUpdated(() => {
|
|
314
|
-
mountLocalComponent()
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
return { pgUpdateElCache }
|
|
318
|
-
}
|
|
319
|
-
|
|
1
|
+
import {
|
|
2
|
+
onBeforeMount,
|
|
3
|
+
onMounted,
|
|
4
|
+
onBeforeUnmount,
|
|
5
|
+
getCurrentInstance,
|
|
6
|
+
ref,
|
|
7
|
+
reactive,
|
|
8
|
+
onUpdated,
|
|
9
|
+
computed,
|
|
10
|
+
watch,
|
|
11
|
+
} from 'vue'
|
|
12
|
+
|
|
13
|
+
export function usePinegrow() {
|
|
14
|
+
const initCache = () => {
|
|
15
|
+
// conditional
|
|
16
|
+
const winObj = window
|
|
17
|
+
|
|
18
|
+
if (!(winObj?.process?.client && winObj.process.client !== true)) {
|
|
19
|
+
if (!winObj.pinegrow) {
|
|
20
|
+
// console.log('Cache initialized by Vue Plugin!')
|
|
21
|
+
const elCache = reactive(new Map())
|
|
22
|
+
|
|
23
|
+
const enrichWithComponentName = (elCacheObj, localFile) => {
|
|
24
|
+
return {
|
|
25
|
+
name: elCacheObj.instance.type.__name || '',
|
|
26
|
+
localFile,
|
|
27
|
+
...elCacheObj,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
winObj.pinegrow = {
|
|
32
|
+
elCache,
|
|
33
|
+
// pgIdToElComputed,
|
|
34
|
+
// localComponentToElComputed,
|
|
35
|
+
// appTree,
|
|
36
|
+
reactiveFromContext: reactive,
|
|
37
|
+
refFromContext: ref,
|
|
38
|
+
computedFromContext: computed,
|
|
39
|
+
watchFromContext: watch,
|
|
40
|
+
// // Uncomment these two to test locally
|
|
41
|
+
// elCacheErrHandlerFn,
|
|
42
|
+
// elUpdateHanderFn,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// pgId & key can be optional
|
|
49
|
+
const pgUpdateElCache = (hook, pgId, rootEl, key, localFile) => async vnode => {
|
|
50
|
+
if (!vnode) return
|
|
51
|
+
if (window?.process?.client && process?.client !== true) return
|
|
52
|
+
if (!window.pinegrow) initCache()
|
|
53
|
+
|
|
54
|
+
let el = vnode.el
|
|
55
|
+
|
|
56
|
+
const instance = vnode.component || vnode.ctx || el.__vueParentComponent
|
|
57
|
+
|
|
58
|
+
if (!el || !instance) return
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
if ((key !== null && key !== undefined) || (vnode.key !== null && vnode.key !== undefined)) {
|
|
62
|
+
key = vnode.key || key
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
localFile = localFile || vnode.type.__file
|
|
66
|
+
|
|
67
|
+
let isRootFragment = false
|
|
68
|
+
let isFragment = el.nodeType !== 1
|
|
69
|
+
let firstEl,
|
|
70
|
+
lastEl,
|
|
71
|
+
isIsland = false,
|
|
72
|
+
childVNodes = []
|
|
73
|
+
|
|
74
|
+
// May be an iles Island that wraps components with client directives
|
|
75
|
+
if (localFile) {
|
|
76
|
+
if (localFile.includes('node_modules/iles') && localFile.includes('Island.vue')) {
|
|
77
|
+
// Retain localFiles of iles island to apply to child elements
|
|
78
|
+
isIsland = true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (localFile.includes('node_modules')) {
|
|
82
|
+
// Ignore SFCs from node_modules
|
|
83
|
+
localFile = null
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const localFileFromInstance = instance.type.__file
|
|
88
|
+
if (
|
|
89
|
+
localFileFromInstance &&
|
|
90
|
+
localFileFromInstance.includes('node_modules/iles') &&
|
|
91
|
+
localFileFromInstance.includes('Island.vue')
|
|
92
|
+
) {
|
|
93
|
+
// Retain localFiles of iles island to apply to child elements
|
|
94
|
+
isIsland = true
|
|
95
|
+
|
|
96
|
+
localFile = instance.props.component?.__file || instance.props.importFrom
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// // 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.
|
|
100
|
+
// if (hook === 'unmounted') {
|
|
101
|
+
// if (pinegrow.elCache.has(el)) {
|
|
102
|
+
// pinegrow.elCache.delete(el)
|
|
103
|
+
// }
|
|
104
|
+
// for (let [key, value] of pinegrow.elCache.entries()) {
|
|
105
|
+
// if (value.rootEl === rootEl) {
|
|
106
|
+
// pinegrow.elCache.delete(key)
|
|
107
|
+
// }
|
|
108
|
+
// }
|
|
109
|
+
// return
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
// Text/comment node
|
|
113
|
+
if (isFragment) {
|
|
114
|
+
if (!rootEl) {
|
|
115
|
+
// root Fragment
|
|
116
|
+
isRootFragment = true
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isFragmentEl(instance) {
|
|
120
|
+
// return appRecord.options.types.Fragment === instance.subTree?.type
|
|
121
|
+
return instance.subTree.el.nodeType !== 1
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getRootVNodesFromComponentInstance(instance) {
|
|
125
|
+
if (isFragmentEl(instance)) {
|
|
126
|
+
return getFragmentRootVNodes(instance.subTree)
|
|
127
|
+
}
|
|
128
|
+
if (!instance.subTree) return []
|
|
129
|
+
return [instance.subTree]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getFragmentRootVNodes(vnode) {
|
|
133
|
+
if (!vnode.children) return []
|
|
134
|
+
// children is v-if when the vnode has a condition
|
|
135
|
+
if (!Array.isArray(vnode.children)) return []
|
|
136
|
+
|
|
137
|
+
const list = []
|
|
138
|
+
|
|
139
|
+
for (let i = 0, l = vnode.children.length; i < l; i++) {
|
|
140
|
+
const childVnode = vnode.children[i]
|
|
141
|
+
if (childVnode.component) {
|
|
142
|
+
list.push(...getRootVNodesFromComponentInstance(childVnode.component))
|
|
143
|
+
} else if (childVnode) {
|
|
144
|
+
list.push(childVnode)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return list
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
childVNodes = getRootVNodesFromComponentInstance(instance)
|
|
152
|
+
|
|
153
|
+
if (!childVNodes.length) {
|
|
154
|
+
// For NuxtLayout, no childVNodes are returned, the subTree.children is in fact an object {ctx: {}, default: f}
|
|
155
|
+
if (el.nextElementSibling) {
|
|
156
|
+
const childEl = el.nextElementSibling
|
|
157
|
+
firstEl = lastEl = childEl
|
|
158
|
+
const childInstance = childEl.$ || childEl.__vueParentComponent
|
|
159
|
+
const childVNode = childInstance?.vnode // or subTree?
|
|
160
|
+
if (childVNode) {
|
|
161
|
+
childVNodes.push(childVNode)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (childVNodes.length) {
|
|
167
|
+
// Filter out recursive vnodes text1 -> div, text1 (happens when text1 is the closest to a fragment with div & slot)
|
|
168
|
+
childVNodes = childVNodes.filter(childVNode => childVNode.el !== el)
|
|
169
|
+
|
|
170
|
+
if (childVNodes.length) {
|
|
171
|
+
if (childVNodes.length === 1) {
|
|
172
|
+
firstEl = lastEl = childVNodes[0].el
|
|
173
|
+
} else {
|
|
174
|
+
firstEl = childVNodes[0].el
|
|
175
|
+
lastEl = childVNodes[childVNodes.length - 1].el
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (firstEl && firstEl.nodeType !== 1) {
|
|
179
|
+
firstEl = firstEl.nextElementSibling
|
|
180
|
+
}
|
|
181
|
+
if (lastEl && lastEl.nodeType !== 1) {
|
|
182
|
+
lastEl = lastEl.nextElementSibling
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (isIsland && !isRootFragment) {
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let elCacheObj = {
|
|
193
|
+
el,
|
|
194
|
+
isRootFragment,
|
|
195
|
+
rootEl,
|
|
196
|
+
vnode,
|
|
197
|
+
instance,
|
|
198
|
+
isFragment,
|
|
199
|
+
firstEl,
|
|
200
|
+
lastEl,
|
|
201
|
+
pgId,
|
|
202
|
+
key,
|
|
203
|
+
localFile,
|
|
204
|
+
isIsland,
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
let prevElCacheNodes = pinegrow.elCache.get(el)
|
|
208
|
+
|
|
209
|
+
if (prevElCacheNodes) {
|
|
210
|
+
let index = prevElCacheNodes.findIndex(elCacheObj => elCacheObj.instance.uid === instance.uid)
|
|
211
|
+
|
|
212
|
+
if (index > -1) {
|
|
213
|
+
const prevElCacheObj = prevElCacheNodes[index]
|
|
214
|
+
elCacheObj.localFile = elCacheObj.localFile || prevElCacheObj.localFile
|
|
215
|
+
if (elCacheObj.pgId && prevElCacheObj.pgId && elCacheObj.pgId !== prevElCacheObj.pgId) {
|
|
216
|
+
if (!prevElCacheNodes.map(prevElCacheNode => prevElCacheNode.pgId).includes(elCacheObj.pgId)) {
|
|
217
|
+
prevElCacheNodes.push(elCacheObj)
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
elCacheObj.pgId = elCacheObj.pgId || prevElCacheObj.pgId
|
|
221
|
+
prevElCacheNodes[index] = elCacheObj
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
prevElCacheNodes.push(elCacheObj)
|
|
225
|
+
}
|
|
226
|
+
pinegrow.elCache.set(el, prevElCacheNodes)
|
|
227
|
+
} else {
|
|
228
|
+
pinegrow.elCache.set(el, [elCacheObj])
|
|
229
|
+
childVNodes.forEach(childVNode => {
|
|
230
|
+
pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (pinegrow.elUpdateHanderFn) {
|
|
235
|
+
pinegrow.elUpdateHanderFn(el)
|
|
236
|
+
}
|
|
237
|
+
} catch (err) {
|
|
238
|
+
console.log(err)
|
|
239
|
+
if (pinegrow.elCacheErrHandlerFn) {
|
|
240
|
+
pinegrow.elCacheErrHandlerFn(vnode, hook, rootEl, pgId, key, el, instance, err.message)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const elUpdateHanderFn = el => {
|
|
246
|
+
// if (pinegrow.elCache.has(el)) {
|
|
247
|
+
// const { pgId } = pinegrow.elCache.get(el)
|
|
248
|
+
// if (pgId) {
|
|
249
|
+
// // console.log(`Reselect ${pgId}`)
|
|
250
|
+
// }
|
|
251
|
+
// }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const elCacheErrHandlerFn = () => {
|
|
255
|
+
if (message) {
|
|
256
|
+
// console.log(message)
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const cleanupCache = () => {
|
|
261
|
+
// for (let [key, value] of pinegrow.elCache.entries()) {
|
|
262
|
+
// if (value.isFragment && !value.firstEl) {
|
|
263
|
+
// console.log(value)
|
|
264
|
+
// }
|
|
265
|
+
// }
|
|
266
|
+
for (let [el, elCacheNodes] of pinegrow.elCache.entries()) {
|
|
267
|
+
// if (!el.isConnected) {
|
|
268
|
+
// pinegrow.elCache.delete(el)
|
|
269
|
+
// continue
|
|
270
|
+
// }
|
|
271
|
+
const cleanedUpElCacheNodes = elCacheNodes.filter(
|
|
272
|
+
elCacheObj => !elCacheObj.instance.isUnmounted // || elCacheObj.localFile
|
|
273
|
+
)
|
|
274
|
+
if (cleanedUpElCacheNodes.length) {
|
|
275
|
+
if (cleanedUpElCacheNodes.length !== elCacheNodes.length) {
|
|
276
|
+
pinegrow.elCache.set(el, cleanedUpElCacheNodes)
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
pinegrow.elCache.delete(el)
|
|
280
|
+
}
|
|
281
|
+
if (pinegrow.elUpdateHanderFn) {
|
|
282
|
+
pinegrow.elUpdateHanderFn(el)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Local Component
|
|
288
|
+
const rootVNode = ref(null)
|
|
289
|
+
|
|
290
|
+
const mountLocalComponent = () => {
|
|
291
|
+
const instance = getCurrentInstance()
|
|
292
|
+
const vnode = instance?.vnode
|
|
293
|
+
const el = vnode?.el
|
|
294
|
+
const localFile = instance.type.__file && !instance.type.__file.includes('node_modules') && instance.type.__file
|
|
295
|
+
if (instance && vnode && el) {
|
|
296
|
+
rootVNode.value = vnode
|
|
297
|
+
pgUpdateElCache('mounted', null, null, null, localFile)(vnode)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const unmountLocalComponent = () => {
|
|
302
|
+
if (rootVNode.value) {
|
|
303
|
+
pgUpdateElCache('unmounted')(rootVNode.value)
|
|
304
|
+
}
|
|
305
|
+
cleanupCache()
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
onBeforeMount(() => initCache())
|
|
309
|
+
onMounted(() => {
|
|
310
|
+
mountLocalComponent()
|
|
311
|
+
})
|
|
312
|
+
onBeforeUnmount(() => unmountLocalComponent())
|
|
313
|
+
onUpdated(() => {
|
|
314
|
+
mountLocalComponent()
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
return { pgUpdateElCache }
|
|
318
|
+
}
|
|
319
|
+
|