@pinegrow/vite-plugin 3.0.0-beta.10 → 3.0.0-beta.101

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.
@@ -40,6 +40,8 @@
40
40
  * Released under the MIT License.
41
41
  */
42
42
 
43
+ /*! ../../../src/framework-mgmt/pinegrow-config-manager.js */
44
+
43
45
  /*! ../../../src/framework-mgmt/transform-plugins.js */
44
46
 
45
47
  /*! ../contrib/parseqs.js */
@@ -240,7 +242,7 @@
240
242
 
241
243
  /*! https */
242
244
 
243
- /*! https://mths.be/he v1.2.0 by @mathias | MIT license */
245
+ /*! https://mths.be/cssesc v3.0.0 by @mathias */
244
246
 
245
247
  /*! is-binary-path */
246
248
 
@@ -578,9 +580,9 @@
578
580
  !*** ../../node_modules/chokidar/lib/fsevents-handler.js ***!
579
581
  \***********************************************************/
580
582
 
581
- /*!*************************************************************!*\
582
- !*** ./node_modules/socket.io-client/build/esm-debug/on.js ***!
583
- \*************************************************************/
583
+ /*!***********************************************************!*\
584
+ !*** ../../src/framework-mgmt/pinegrow-config-manager.js ***!
585
+ \***********************************************************/
584
586
 
585
587
  /*!**************************************************************!*\
586
588
  !*** ../../node_modules/@babel/runtime/regenerator/index.js ***!
@@ -590,10 +592,6 @@
590
592
  !*** ../../node_modules/engine.io-parser/build/esm/index.js ***!
591
593
  \**************************************************************/
592
594
 
593
- /*!**************************************************************!*\
594
- !*** ./node_modules/socket.io-client/build/esm-debug/url.js ***!
595
- \**************************************************************/
596
-
597
595
  /*!****************************************************************!*\
598
596
  !*** ../../node_modules/@babel/runtime/helpers/createClass.js ***!
599
597
  \****************************************************************/
@@ -606,16 +604,12 @@
606
604
  !*** ../../node_modules/engine.io-parser/build/esm/commons.js ***!
607
605
  \****************************************************************/
608
606
 
609
- /*!****************************************************************!*\
610
- !*** ./node_modules/socket.io-client/build/esm-debug/index.js ***!
611
- \****************************************************************/
612
-
613
607
  /*!*****************************************************************!*\
614
608
  !*** ../../node_modules/@socket.io/component-emitter/index.mjs ***!
615
609
  \*****************************************************************/
616
610
 
617
611
  /*!*****************************************************************!*\
618
- !*** ./node_modules/socket.io-client/build/esm-debug/socket.js ***!
612
+ !*** ../../node_modules/socket.io-client/build/esm-debug/on.js ***!
619
613
  \*****************************************************************/
620
614
 
621
615
  /*!******************************************************************!*\
@@ -627,7 +621,7 @@
627
621
  \******************************************************************/
628
622
 
629
623
  /*!******************************************************************!*\
630
- !*** ./node_modules/socket.io-client/build/esm-debug/manager.js ***!
624
+ !*** ../../node_modules/socket.io-client/build/esm-debug/url.js ***!
631
625
  \******************************************************************/
632
626
 
633
627
  /*!*******************************************************************!*\
@@ -666,6 +660,10 @@
666
660
  !*** ../../node_modules/engine.io-client/build/esm-debug/index.js ***!
667
661
  \********************************************************************/
668
662
 
663
+ /*!********************************************************************!*\
664
+ !*** ../../node_modules/socket.io-client/build/esm-debug/index.js ***!
665
+ \********************************************************************/
666
+
669
667
  /*!********************************************************************!*\
670
668
  !*** ../../node_modules/socket.io-parser/build/esm-debug/index.js ***!
671
669
  \********************************************************************/
@@ -690,6 +688,10 @@
690
688
  !*** ../../node_modules/engine.io-parser/build/esm/encodePacket.js ***!
691
689
  \*********************************************************************/
692
690
 
691
+ /*!*********************************************************************!*\
692
+ !*** ../../node_modules/socket.io-client/build/esm-debug/socket.js ***!
693
+ \*********************************************************************/
694
+
693
695
  /*!*********************************************************************!*\
694
696
  !*** ../../node_modules/socket.io-parser/build/esm-debug/binary.js ***!
695
697
  \*********************************************************************/
@@ -706,6 +708,10 @@
706
708
  !*** ../../node_modules/@babel/runtime/helpers/toConsumableArray.js ***!
707
709
  \**********************************************************************/
708
710
 
711
+ /*!**********************************************************************!*\
712
+ !*** ../../node_modules/socket.io-client/build/esm-debug/manager.js ***!
713
+ \**********************************************************************/
714
+
709
715
  /*!***********************************************************************!*\
710
716
  !*** ../../node_modules/@babel/runtime/helpers/regeneratorRuntime.js ***!
711
717
  \***********************************************************************/
@@ -726,10 +732,6 @@
726
732
  !*** ../../node_modules/engine.io-client/build/esm-debug/globalThis.js ***!
727
733
  \*************************************************************************/
728
734
 
729
- /*!*************************************************************************!*\
730
- !*** ./node_modules/socket.io-client/build/esm-debug/contrib/backo2.js ***!
731
- \*************************************************************************/
732
-
733
735
  /*!****************************************************************************!*\
734
736
  !*** ../../node_modules/@babel/runtime/helpers/objectWithoutProperties.js ***!
735
737
  \****************************************************************************/
@@ -738,6 +740,10 @@
738
740
  !*** ../../node_modules/engine.io-client/build/esm-debug/contrib/yeast.js ***!
739
741
  \****************************************************************************/
740
742
 
743
+ /*!*****************************************************************************!*\
744
+ !*** ../../node_modules/socket.io-client/build/esm-debug/contrib/backo2.js ***!
745
+ \*****************************************************************************/
746
+
741
747
  /*!******************************************************************************!*\
742
748
  !*** ../../node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js ***!
743
749
  \******************************************************************************/
@@ -0,0 +1,374 @@
1
+ import { onBeforeMount, onMounted, onBeforeUnmount, getCurrentInstance, ref, reactive, computed, onUpdated } from 'vue'
2
+
3
+ export function usePinegrow() {
4
+ const initCache = () => {
5
+ // conditional
6
+ const winObj = window
7
+
8
+ if (!(winObj?.process?.client && winObj.process.client !== true)) {
9
+ if (!winObj.pinegrow) {
10
+ // conditional
11
+ // console.log('Cache initialized by Pinegrow Vue Plugin!')
12
+ const elCache = reactive(new Map())
13
+
14
+ const enrichWithComponentName = (elCacheObj, localFile) => {
15
+ return {
16
+ name: elCacheObj.instance.type.__name || '',
17
+ localFile,
18
+ ...elCacheObj,
19
+ }
20
+ }
21
+
22
+ const pgIdToElComputed = computed(() => {
23
+ const pgIds = {}
24
+ for (let [el, elCacheNodes] of elCache.entries()) {
25
+ if (el.isConnected) {
26
+ elCacheNodes.forEach(elCacheObj => {
27
+ if (
28
+ // elCacheObj.vnode.el.isConnected &&
29
+ elCacheObj.instance.isMounted &&
30
+ !elCacheObj.instance.isUnmounted &&
31
+ elCacheObj.pgId &&
32
+ (!elCacheObj.rootEl || elCacheObj.isRootFragment)
33
+ ) {
34
+ if (!pgIds[elCacheObj.pgId]) {
35
+ pgIds[elCacheObj.pgId] = []
36
+ }
37
+ if (elCacheObj.key === undefined || elCacheObj.key === null) {
38
+ pgIds[elCacheObj.pgId].push(elCacheObj)
39
+ } else {
40
+ pgIds[elCacheObj.pgId].push([elCacheObj.key, elCacheObj])
41
+ }
42
+ }
43
+ })
44
+ }
45
+ }
46
+ return pgIds
47
+ })
48
+
49
+ const localComponentToElComputed = computed(() => {
50
+ const localComponents = {}
51
+ for (let [el, elCacheNodes] of elCache.entries()) {
52
+ if (el.isConnected) {
53
+ elCacheNodes.forEach(elCacheObj => {
54
+ if (
55
+ // elCacheObj.vnode.el.isConnected &&
56
+ elCacheObj.instance.isMounted &&
57
+ !elCacheObj.instance.isUnmounted &&
58
+ elCacheObj.localFile
59
+ // && !elCacheObj.isIsland
60
+ // && (!elCacheObj.rootEl || elCacheObj.isRootFragment)
61
+ ) {
62
+ if (!localComponents[elCacheObj.localFile]) {
63
+ localComponents[elCacheObj.localFile] = []
64
+ }
65
+ // 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
66
+ const possibleIslandRootIndex = localComponents[elCacheObj.localFile].findIndex(
67
+ prevElCacheObj =>
68
+ prevElCacheObj.isIsland &&
69
+ prevElCacheObj.firstEl?.firstElementChild === elCacheObj.el
70
+ )
71
+
72
+ if (possibleIslandRootIndex > -1) {
73
+ const pgId = localComponents[elCacheObj.localFile][possibleIslandRootIndex].pgId
74
+ localComponents[elCacheObj.localFile][possibleIslandRootIndex] =
75
+ enrichWithComponentName({ ...elCacheObj, pgId }, elCacheObj.localFile)
76
+ } else {
77
+ localComponents[elCacheObj.localFile].push(
78
+ enrichWithComponentName(elCacheObj, elCacheObj.localFile)
79
+ )
80
+ }
81
+ }
82
+ })
83
+ }
84
+ }
85
+ return localComponents
86
+ })
87
+
88
+ const appTree = computed(() => {
89
+ const appTreeNodes = Object.values(localComponentToElComputed.value).reduce(
90
+ (acc, localComponent) => [...acc, ...localComponent],
91
+ []
92
+ )
93
+ const appTreeNodesSorted = appTreeNodes.sort((a, b) =>
94
+ a.el.compareDocumentPosition(b.el) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
95
+ )
96
+ return appTreeNodesSorted
97
+ })
98
+
99
+ winObj.pinegrow = {
100
+ elCache,
101
+ // // Uncomment these two to test locally
102
+ // elCacheErrHandlerFn,
103
+ // elUpdateHanderFn,
104
+ // rootFragmentToPgIdComputed,
105
+ pgIdToElComputed,
106
+ localComponentToElComputed,
107
+ appTree,
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ // pgId & key can be optional
114
+ const pgUpdateElCache = (hook, pgId, rootEl, key, localFile) => async vnode => {
115
+ if (!vnode) return
116
+ if (window?.process?.client && process?.client !== true) return
117
+ if (!window.pinegrow) initCache()
118
+
119
+ let el = vnode.el
120
+ if (!el) return
121
+
122
+ const instance = vnode.component || vnode.ctx || el.__vueParentComponent
123
+
124
+ try {
125
+ if ((key !== null && key !== undefined) || (vnode.key !== null && vnode.key !== undefined)) {
126
+ key = vnode.key || key
127
+ }
128
+
129
+ localFile = localFile || vnode.type.__file
130
+
131
+ let isRootFragment = false
132
+ let isFragment = el.nodeType !== 1
133
+ let firstEl,
134
+ lastEl,
135
+ isIsland = false,
136
+ childVNodes = []
137
+
138
+ // May be an iles Island that wraps components with client directives
139
+ if (localFile) {
140
+ if (localFile.includes('node_modules/iles') && localFile.includes('Island.vue')) {
141
+ // Retain localFiles of iles island to apply to child elements
142
+ isIsland = true
143
+ }
144
+
145
+ if (localFile.includes('node_modules')) {
146
+ // Ignore SFCs from node_modules
147
+ localFile = null
148
+ }
149
+ }
150
+
151
+ const localFileFromInstance = instance.type.__file
152
+ if (
153
+ localFileFromInstance &&
154
+ localFileFromInstance.includes('node_modules/iles') &&
155
+ localFileFromInstance.includes('Island.vue')
156
+ ) {
157
+ // Retain localFiles of iles island to apply to child elements
158
+ isIsland = true
159
+
160
+ localFile = instance.props.component?.__file || instance.props.importFrom
161
+ }
162
+
163
+ // // 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.
164
+ // if (hook === 'unmounted') {
165
+ // if (pinegrow.elCache.has(el)) {
166
+ // pinegrow.elCache.delete(el)
167
+ // }
168
+ // for (let [key, value] of pinegrow.elCache.entries()) {
169
+ // if (value.rootEl === rootEl) {
170
+ // pinegrow.elCache.delete(key)
171
+ // }
172
+ // }
173
+ // return
174
+ // }
175
+
176
+ // Text/comment node
177
+ if (isFragment) {
178
+ if (!rootEl) {
179
+ // root Fragment
180
+ isRootFragment = true
181
+ }
182
+
183
+ function isFragmentEl(instance) {
184
+ // return appRecord.options.types.Fragment === instance.subTree?.type
185
+ return instance.subTree.el.nodeType !== 1
186
+ }
187
+
188
+ function getRootVNodesFromComponentInstance(instance) {
189
+ if (isFragmentEl(instance)) {
190
+ return getFragmentRootVNodes(instance.subTree)
191
+ }
192
+ if (!instance.subTree) return []
193
+ return [instance.subTree]
194
+ }
195
+
196
+ function getFragmentRootVNodes(vnode) {
197
+ if (!vnode.children) return []
198
+ // children is v-if when the vnode has a condition
199
+ if (!Array.isArray(vnode.children)) return []
200
+
201
+ const list = []
202
+
203
+ for (let i = 0, l = vnode.children.length; i < l; i++) {
204
+ const childVnode = vnode.children[i]
205
+ if (childVnode.component) {
206
+ list.push(...getRootVNodesFromComponentInstance(childVnode.component))
207
+ } else if (childVnode) {
208
+ list.push(childVnode)
209
+ }
210
+ }
211
+
212
+ return list
213
+ }
214
+
215
+ childVNodes = getRootVNodesFromComponentInstance(instance)
216
+
217
+ if (!childVNodes.length) {
218
+ // For NuxtLayout, no childVNodes are returned, the subTree.children is in fact an object {ctx: {}, default: f}
219
+ if (el.nextElementSibling) {
220
+ const childEl = el.nextElementSibling
221
+ firstEl = lastEl = childEl
222
+ const childInstance = childEl.$ || childEl.__vueParentComponent
223
+ const childVNode = childInstance?.vnode // or subTree?
224
+ if (childVNode) {
225
+ childVNodes.push(childVNode)
226
+ }
227
+ }
228
+ }
229
+
230
+ if (childVNodes.length) {
231
+ // Filter out recursive vnodes text1 -> div, text1 (happens when text1 is the closest to a fragment with div & slot)
232
+ childVNodes = childVNodes.filter(childVNode => childVNode.el !== el)
233
+
234
+ if (childVNodes.length) {
235
+ if (childVNodes.length === 1) {
236
+ firstEl = lastEl = childVNodes[0].el
237
+ } else {
238
+ firstEl = childVNodes[0].el
239
+ lastEl = childVNodes[childVNodes.length - 1].el
240
+ }
241
+
242
+ if (firstEl && firstEl.nodeType !== 1) {
243
+ firstEl = firstEl.nextElementSibling
244
+ }
245
+ if (lastEl && lastEl.nodeType !== 1) {
246
+ lastEl = lastEl.nextElementSibling
247
+ }
248
+ }
249
+ }
250
+ }
251
+
252
+ if (isIsland && !isRootFragment) {
253
+ return
254
+ }
255
+
256
+ let elCacheObj = {
257
+ el,
258
+ isRootFragment,
259
+ rootEl,
260
+ vnode,
261
+ instance,
262
+ isFragment,
263
+ firstEl,
264
+ lastEl,
265
+ pgId,
266
+ key,
267
+ localFile,
268
+ isIsland,
269
+ }
270
+
271
+ let prevElCacheNodes = pinegrow.elCache.get(el)
272
+
273
+ if (prevElCacheNodes) {
274
+ let index = prevElCacheNodes.findIndex(elCacheObj => elCacheObj.instance.uid === instance.uid)
275
+
276
+ if (index > -1) {
277
+ const prevElCacheObj = prevElCacheNodes[index]
278
+ elCacheObj.localFile = elCacheObj.localFile || prevElCacheObj.localFile
279
+ elCacheObj.pgId = elCacheObj.pgId || prevElCacheObj.pgId
280
+ prevElCacheNodes[index] = elCacheObj
281
+ } else {
282
+ prevElCacheNodes.push(elCacheObj)
283
+ }
284
+ pinegrow.elCache.set(el, prevElCacheNodes)
285
+ } else {
286
+ pinegrow.elCache.set(el, [elCacheObj])
287
+ childVNodes.forEach(childVNode => {
288
+ pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
289
+ })
290
+ }
291
+
292
+ if (pinegrow.elUpdateHanderFn) {
293
+ pinegrow.elUpdateHanderFn(el)
294
+ }
295
+ } catch (err) {
296
+ console.log(err)
297
+ if (pinegrow.elCacheErrHandlerFn) {
298
+ pinegrow.elCacheErrHandlerFn(vnode, hook, rootEl, pgId, key, el, instance, err.message)
299
+ }
300
+ }
301
+ }
302
+
303
+ const elUpdateHanderFn = el => {
304
+ // if (pinegrow.elCache.has(el)) {
305
+ // const { pgId } = pinegrow.elCache.get(el)
306
+ // if (pgId) {
307
+ // // console.log(`Reselect ${pgId}`)
308
+ // }
309
+ // }
310
+ }
311
+
312
+ const elCacheErrHandlerFn = () => {
313
+ if (message) {
314
+ // console.log(message)
315
+ }
316
+ }
317
+
318
+ const cleanupCache = () => {
319
+ // for (let [key, value] of pinegrow.elCache.entries()) {
320
+ // if (value.isFragment && !value.firstEl) {
321
+ // console.log(value)
322
+ // }
323
+ // }
324
+ for (let [el, elCacheNodes] of pinegrow.elCache.entries()) {
325
+ // if (!el.isConnected) {
326
+ // pinegrow.elCache.delete(el)
327
+ // continue
328
+ // }
329
+ const cleanedUpElCacheNodes = elCacheNodes.filter(
330
+ elCacheObj => !elCacheObj.instance.isUnmounted // || elCacheObj.localFile
331
+ )
332
+ if (cleanedUpElCacheNodes.length) {
333
+ if (cleanedUpElCacheNodes.length !== elCacheNodes.length) {
334
+ pinegrow.elCache.set(el, cleanedUpElCacheNodes)
335
+ }
336
+ } else {
337
+ pinegrow.elCache.delete(el)
338
+ }
339
+ }
340
+ }
341
+
342
+ // Local Component
343
+ const rootVNode = ref(null)
344
+
345
+ const mountLocalComponent = () => {
346
+ const instance = getCurrentInstance()
347
+ const vnode = instance?.vnode
348
+ const el = vnode?.el
349
+ const localFile = instance.type.__file && !instance.type.__file.includes('node_modules') && instance.type.__file
350
+ if (instance && vnode && el) {
351
+ rootVNode.value = vnode
352
+ pgUpdateElCache('mounted', null, null, null, localFile)(vnode)
353
+ }
354
+ }
355
+
356
+ const unmountLocalComponent = () => {
357
+ if (rootVNode.value) {
358
+ pgUpdateElCache('unmounted')(rootVNode.value)
359
+ }
360
+ cleanupCache()
361
+ }
362
+
363
+ onBeforeMount(() => initCache())
364
+ onMounted(() => {
365
+ mountLocalComponent()
366
+ })
367
+ onBeforeUnmount(() => unmountLocalComponent())
368
+ onUpdated(() => {
369
+ mountLocalComponent()
370
+ })
371
+
372
+ return { pgUpdateElCache }
373
+ }
374
+
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@pinegrow/vite-plugin",
3
- "version": "3.0.0-beta.10",
3
+ "version": "3.0.0-beta.101",
4
4
  "description": "Pinegrow Vite Plugin",
5
5
  "type": "module",
6
6
  "files": [
7
- "dist"
7
+ "dist",
8
+ "./types.d.ts"
8
9
  ],
9
10
  "main": "./dist/index.cjs",
10
11
  "module": "./dist/index.cjs",
12
+ "types": "./types.d.ts",
11
13
  "exports": {
12
14
  ".": {
13
15
  "import": "./dist/index.cjs",
@@ -16,6 +18,12 @@
16
18
  "./dev": {
17
19
  "import": "./src/index.js",
18
20
  "require": "./src/index.js"
21
+ },
22
+ "./vue": {
23
+ "import": "./dist/vue/index.js"
24
+ },
25
+ "./pgia": {
26
+ "import": "./dist/pgia/index.js"
19
27
  }
20
28
  },
21
29
  "keywords": [
@@ -33,6 +41,8 @@
33
41
  "increment-beta-version": "npm version prerelease --preid=beta"
34
42
  },
35
43
  "dependencies": {
44
+ "@vue/compiler-sfc": "^3.2.45",
45
+ "magic-string": "^0.27.0",
36
46
  "node-html-parser": "^5.2.0"
37
47
  }
38
48
  }
package/types.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ declare module '@pinegrow/vite-plugin'
2
+
3
+ // export interface liveDesigner {
4
+ // repoRoot?: string;
5
+ // configPath?: string;
6
+ // plugins?: string[];
7
+ // devtoolsKey?: string;
8
+ // vscodeTunnelUrl?: string
9
+ // customTypes?: {
10
+ // default?: {};
11
+ // };
12
+ // };
13
+