@pinegrow/vite-plugin 3.0.0-beta.140 → 3.0.0-beta.141

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 (2) hide show
  1. package/dist/vue/index.js +109 -7
  2. package/package.json +1 -1
package/dist/vue/index.js CHANGED
@@ -17,8 +17,7 @@ export function usePinegrow() {
17
17
 
18
18
  if (!(winObj?.process?.client && winObj.process.client !== true)) {
19
19
  if (!winObj.pinegrow) {
20
- // conditional
21
- // console.log('Cache initialized by Pinegrow Vue Plugin!')
20
+ // console.log('Cache initialized by Vue Plugin!')
22
21
  const elCache = reactive(new Map())
23
22
 
24
23
  const enrichWithComponentName = (elCacheObj, localFile) => {
@@ -29,17 +28,117 @@ export function usePinegrow() {
29
28
  }
30
29
  }
31
30
 
31
+ const pgIdToElComputed = computed(() => {
32
+ const pgIds = {}
33
+ for (let [el, elCacheNodes] of elCache.entries()) {
34
+ if (el.isConnected) {
35
+ elCacheNodes.forEach(elCacheObj => {
36
+ if (
37
+ // elCacheObj.vnode.el.isConnected &&
38
+ elCacheObj.instance.isMounted &&
39
+ !elCacheObj.instance.isUnmounted &&
40
+ elCacheObj.pgId &&
41
+ (!elCacheObj.rootEl ||
42
+ elCacheObj.isRootFragment ||
43
+ (elCacheObj.rootEl && elCacheObj.rootEl === elCacheObj.el.parentNode))
44
+ ) {
45
+ if (!pgIds[elCacheObj.pgId]) {
46
+ pgIds[elCacheObj.pgId] = []
47
+ }
48
+ if (elCacheObj.key === undefined || elCacheObj.key === null) {
49
+ pgIds[elCacheObj.pgId].push(elCacheObj)
50
+ } else {
51
+ pgIds[elCacheObj.pgId].push([elCacheObj.key, elCacheObj])
52
+ }
53
+ }
54
+ })
55
+ }
56
+ }
57
+ return pgIds
58
+ })
59
+
60
+ const localComponentToElComputed = computed(() => {
61
+ const localComponents = {}
62
+ for (let [el, elCacheNodes] of elCache.entries()) {
63
+ if (el.isConnected) {
64
+ elCacheNodes.forEach(elCacheObj => {
65
+ if (
66
+ // elCacheObj.vnode.el.isConnected &&
67
+ elCacheObj.instance.isMounted &&
68
+ !elCacheObj.instance.isUnmounted &&
69
+ elCacheObj.localFile
70
+ // && !elCacheObj.isIsland
71
+ // && (!elCacheObj.rootEl ||
72
+ // elCacheObj.isRootFragment ||
73
+ // (elCacheObj.rootEl && elCacheObj.rootEl === elCacheObj.el.parentNode))
74
+ ) {
75
+ if (!localComponents[elCacheObj.localFile]) {
76
+ localComponents[elCacheObj.localFile] = []
77
+ }
78
+ // There might be a elCache that was hydrated, and has the ile-root as a parent. If it was already there, then update the iles-root instead of adding a new node
79
+ const possibleIslandRootIndex = localComponents[elCacheObj.localFile].findIndex(
80
+ prevElCacheObj =>
81
+ prevElCacheObj.isIsland &&
82
+ prevElCacheObj.firstEl?.firstElementChild === elCacheObj.el
83
+ )
84
+
85
+ if (possibleIslandRootIndex > -1) {
86
+ const pgId = localComponents[elCacheObj.localFile][possibleIslandRootIndex].pgId
87
+ localComponents[elCacheObj.localFile][possibleIslandRootIndex] =
88
+ enrichWithComponentName({ ...elCacheObj, pgId }, elCacheObj.localFile)
89
+ } else {
90
+ localComponents[elCacheObj.localFile].push(
91
+ enrichWithComponentName(elCacheObj, elCacheObj.localFile)
92
+ )
93
+ }
94
+ }
95
+ })
96
+ }
97
+ }
98
+ return localComponents
99
+ })
100
+
101
+ const appTree = computed(() => {
102
+ const appTreeNodes = Object.values(localComponentToElComputed.value).reduce((acc, elCacheNodes) => {
103
+ const filteredElCacheNodes = []
104
+ elCacheNodes.forEach(elCacheObj => {
105
+ // If Island and already hydrated, then remove it off
106
+ if (elCacheObj.isIsland) {
107
+ const childEl = elCacheObj.firstEl.firstElementChild
108
+ if (childEl) {
109
+ if (elCache.has(childEl)) {
110
+ // Hydrated, don't include
111
+ return
112
+ }
113
+ // const childElCacheObj = elCache.get(childEl)
114
+ // if (childElCacheObj) {
115
+ // childElCacheObj.pgId = elCacheObj.pgId
116
+ // // Hydrated, don't include
117
+ // return
118
+ // }
119
+ }
120
+ }
121
+ filteredElCacheNodes.push(elCacheObj)
122
+ })
123
+ return [...acc, ...filteredElCacheNodes]
124
+ }, [])
125
+ const appTreeNodesSorted = appTreeNodes.sort((a, b) =>
126
+ a.el.compareDocumentPosition(b.el) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
127
+ )
128
+ return appTreeNodesSorted
129
+ })
130
+
32
131
  winObj.pinegrow = {
33
132
  elCache,
34
- watchFromContext: watch,
133
+ pgIdToElComputed,
134
+ localComponentToElComputed,
135
+ appTree,
136
+ refFromContext: ref,
35
137
  computedFromContext: computed,
138
+ watchFromContext: watch,
36
139
  // // Uncomment these two to test locally
37
140
  // elCacheErrHandlerFn,
38
141
  // elUpdateHanderFn,
39
- // rootFragmentToPgIdComputed,
40
- // pgIdToElComputed,
41
- // localComponentToElComputed,
42
- // appTree,
43
142
  }
44
143
  }
45
144
  }
@@ -272,6 +371,9 @@ export function usePinegrow() {
272
371
  } else {
273
372
  pinegrow.elCache.delete(el)
274
373
  }
374
+ if (pinegrow.elUpdateHanderFn) {
375
+ pinegrow.elUpdateHanderFn(el)
376
+ }
275
377
  }
276
378
  }
277
379
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinegrow/vite-plugin",
3
- "version": "3.0.0-beta.140",
3
+ "version": "3.0.0-beta.141",
4
4
  "description": "Pinegrow Vite Plugin",
5
5
  "type": "module",
6
6
  "files": [