@pinegrow/vite-plugin 3.0.0-beta.11 → 3.0.0-beta.110

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,297 @@
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
+ winObj.pinegrow = {
23
+ elCache,
24
+ // // Uncomment these two to test locally
25
+ // elCacheErrHandlerFn,
26
+ // elUpdateHanderFn,
27
+ // rootFragmentToPgIdComputed,
28
+ // pgIdToElComputed,
29
+ // localComponentToElComputed,
30
+ // appTree,
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ // pgId & key can be optional
37
+ const pgUpdateElCache = (hook, pgId, rootEl, key, localFile) => async vnode => {
38
+ if (!vnode) return
39
+ if (window?.process?.client && process?.client !== true) return
40
+ if (!window.pinegrow) initCache()
41
+
42
+ let el = vnode.el
43
+ if (!el) return
44
+
45
+ const instance = vnode.component || vnode.ctx || el.__vueParentComponent
46
+
47
+ try {
48
+ if ((key !== null && key !== undefined) || (vnode.key !== null && vnode.key !== undefined)) {
49
+ key = vnode.key || key
50
+ }
51
+
52
+ localFile = localFile || vnode.type.__file
53
+
54
+ let isRootFragment = false
55
+ let isFragment = el.nodeType !== 1
56
+ let firstEl,
57
+ lastEl,
58
+ isIsland = false,
59
+ childVNodes = []
60
+
61
+ // May be an iles Island that wraps components with client directives
62
+ if (localFile) {
63
+ if (localFile.includes('node_modules/iles') && localFile.includes('Island.vue')) {
64
+ // Retain localFiles of iles island to apply to child elements
65
+ isIsland = true
66
+ }
67
+
68
+ if (localFile.includes('node_modules')) {
69
+ // Ignore SFCs from node_modules
70
+ localFile = null
71
+ }
72
+ }
73
+
74
+ const localFileFromInstance = instance.type.__file
75
+ if (
76
+ localFileFromInstance &&
77
+ localFileFromInstance.includes('node_modules/iles') &&
78
+ localFileFromInstance.includes('Island.vue')
79
+ ) {
80
+ // Retain localFiles of iles island to apply to child elements
81
+ isIsland = true
82
+
83
+ localFile = instance.props.component?.__file || instance.props.importFrom
84
+ }
85
+
86
+ // // 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.
87
+ // if (hook === 'unmounted') {
88
+ // if (pinegrow.elCache.has(el)) {
89
+ // pinegrow.elCache.delete(el)
90
+ // }
91
+ // for (let [key, value] of pinegrow.elCache.entries()) {
92
+ // if (value.rootEl === rootEl) {
93
+ // pinegrow.elCache.delete(key)
94
+ // }
95
+ // }
96
+ // return
97
+ // }
98
+
99
+ // Text/comment node
100
+ if (isFragment) {
101
+ if (!rootEl) {
102
+ // root Fragment
103
+ isRootFragment = true
104
+ }
105
+
106
+ function isFragmentEl(instance) {
107
+ // return appRecord.options.types.Fragment === instance.subTree?.type
108
+ return instance.subTree.el.nodeType !== 1
109
+ }
110
+
111
+ function getRootVNodesFromComponentInstance(instance) {
112
+ if (isFragmentEl(instance)) {
113
+ return getFragmentRootVNodes(instance.subTree)
114
+ }
115
+ if (!instance.subTree) return []
116
+ return [instance.subTree]
117
+ }
118
+
119
+ function getFragmentRootVNodes(vnode) {
120
+ if (!vnode.children) return []
121
+ // children is v-if when the vnode has a condition
122
+ if (!Array.isArray(vnode.children)) return []
123
+
124
+ const list = []
125
+
126
+ for (let i = 0, l = vnode.children.length; i < l; i++) {
127
+ const childVnode = vnode.children[i]
128
+ if (childVnode.component) {
129
+ list.push(...getRootVNodesFromComponentInstance(childVnode.component))
130
+ } else if (childVnode) {
131
+ list.push(childVnode)
132
+ }
133
+ }
134
+
135
+ return list
136
+ }
137
+
138
+ childVNodes = getRootVNodesFromComponentInstance(instance)
139
+
140
+ if (!childVNodes.length) {
141
+ // For NuxtLayout, no childVNodes are returned, the subTree.children is in fact an object {ctx: {}, default: f}
142
+ if (el.nextElementSibling) {
143
+ const childEl = el.nextElementSibling
144
+ firstEl = lastEl = childEl
145
+ const childInstance = childEl.$ || childEl.__vueParentComponent
146
+ const childVNode = childInstance?.vnode // or subTree?
147
+ if (childVNode) {
148
+ childVNodes.push(childVNode)
149
+ }
150
+ }
151
+ }
152
+
153
+ if (childVNodes.length) {
154
+ // Filter out recursive vnodes text1 -> div, text1 (happens when text1 is the closest to a fragment with div & slot)
155
+ childVNodes = childVNodes.filter(childVNode => childVNode.el !== el)
156
+
157
+ if (childVNodes.length) {
158
+ if (childVNodes.length === 1) {
159
+ firstEl = lastEl = childVNodes[0].el
160
+ } else {
161
+ firstEl = childVNodes[0].el
162
+ lastEl = childVNodes[childVNodes.length - 1].el
163
+ }
164
+
165
+ if (firstEl && firstEl.nodeType !== 1) {
166
+ firstEl = firstEl.nextElementSibling
167
+ }
168
+ if (lastEl && lastEl.nodeType !== 1) {
169
+ lastEl = lastEl.nextElementSibling
170
+ }
171
+ }
172
+ }
173
+ }
174
+
175
+ if (isIsland && !isRootFragment) {
176
+ return
177
+ }
178
+
179
+ let elCacheObj = {
180
+ el,
181
+ isRootFragment,
182
+ rootEl,
183
+ vnode,
184
+ instance,
185
+ isFragment,
186
+ firstEl,
187
+ lastEl,
188
+ pgId,
189
+ key,
190
+ localFile,
191
+ isIsland,
192
+ }
193
+
194
+ let prevElCacheNodes = pinegrow.elCache.get(el)
195
+
196
+ if (prevElCacheNodes) {
197
+ let index = prevElCacheNodes.findIndex(elCacheObj => elCacheObj.instance.uid === instance.uid)
198
+
199
+ if (index > -1) {
200
+ const prevElCacheObj = prevElCacheNodes[index]
201
+ elCacheObj.localFile = elCacheObj.localFile || prevElCacheObj.localFile
202
+ elCacheObj.pgId = elCacheObj.pgId || prevElCacheObj.pgId
203
+ prevElCacheNodes[index] = elCacheObj
204
+ } else {
205
+ prevElCacheNodes.push(elCacheObj)
206
+ }
207
+ pinegrow.elCache.set(el, prevElCacheNodes)
208
+ } else {
209
+ pinegrow.elCache.set(el, [elCacheObj])
210
+ childVNodes.forEach(childVNode => {
211
+ pgUpdateElCache(hook, pgId, isRootFragment ? el : rootEl, key)(childVNode)
212
+ })
213
+ }
214
+
215
+ if (pinegrow.elUpdateHanderFn) {
216
+ pinegrow.elUpdateHanderFn(el)
217
+ }
218
+ } catch (err) {
219
+ console.log(err)
220
+ if (pinegrow.elCacheErrHandlerFn) {
221
+ pinegrow.elCacheErrHandlerFn(vnode, hook, rootEl, pgId, key, el, instance, err.message)
222
+ }
223
+ }
224
+ }
225
+
226
+ const elUpdateHanderFn = el => {
227
+ // if (pinegrow.elCache.has(el)) {
228
+ // const { pgId } = pinegrow.elCache.get(el)
229
+ // if (pgId) {
230
+ // // console.log(`Reselect ${pgId}`)
231
+ // }
232
+ // }
233
+ }
234
+
235
+ const elCacheErrHandlerFn = () => {
236
+ if (message) {
237
+ // console.log(message)
238
+ }
239
+ }
240
+
241
+ const cleanupCache = () => {
242
+ // for (let [key, value] of pinegrow.elCache.entries()) {
243
+ // if (value.isFragment && !value.firstEl) {
244
+ // console.log(value)
245
+ // }
246
+ // }
247
+ for (let [el, elCacheNodes] of pinegrow.elCache.entries()) {
248
+ // if (!el.isConnected) {
249
+ // pinegrow.elCache.delete(el)
250
+ // continue
251
+ // }
252
+ const cleanedUpElCacheNodes = elCacheNodes.filter(
253
+ elCacheObj => !elCacheObj.instance.isUnmounted // || elCacheObj.localFile
254
+ )
255
+ if (cleanedUpElCacheNodes.length) {
256
+ if (cleanedUpElCacheNodes.length !== elCacheNodes.length) {
257
+ pinegrow.elCache.set(el, cleanedUpElCacheNodes)
258
+ }
259
+ } else {
260
+ pinegrow.elCache.delete(el)
261
+ }
262
+ }
263
+ }
264
+
265
+ // Local Component
266
+ const rootVNode = ref(null)
267
+
268
+ const mountLocalComponent = () => {
269
+ const instance = getCurrentInstance()
270
+ const vnode = instance?.vnode
271
+ const el = vnode?.el
272
+ const localFile = instance.type.__file && !instance.type.__file.includes('node_modules') && instance.type.__file
273
+ if (instance && vnode && el) {
274
+ rootVNode.value = vnode
275
+ pgUpdateElCache('mounted', null, null, null, localFile)(vnode)
276
+ }
277
+ }
278
+
279
+ const unmountLocalComponent = () => {
280
+ if (rootVNode.value) {
281
+ pgUpdateElCache('unmounted')(rootVNode.value)
282
+ }
283
+ cleanupCache()
284
+ }
285
+
286
+ onBeforeMount(() => initCache())
287
+ onMounted(() => {
288
+ mountLocalComponent()
289
+ })
290
+ onBeforeUnmount(() => unmountLocalComponent())
291
+ onUpdated(() => {
292
+ mountLocalComponent()
293
+ })
294
+
295
+ return { pgUpdateElCache }
296
+ }
297
+
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "@pinegrow/vite-plugin",
3
- "version": "3.0.0-beta.11",
3
+ "version": "3.0.0-beta.110",
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,87 @@
1
+ import type { Options as PinegrowTailwindCSSPluginOptions } from '@pinegrow/tailwindcss-plugin'
2
+ import type { Options as AutoImportComponentsOptions } from 'unplugin-vue-components/types'
3
+ import type { Options as AutoImportAPIsOptions } from 'unplugin-auto-import/types'
4
+
5
+ interface Options {
6
+ repoRoot?: string // relative path from the project root to the root of the monorepo
7
+
8
+ configPath?: string // relative path from project root to the custom config file when it's not auto-detected, for eg, './my-config.dev.js' or './docs/my-config.dev.js', defaults to viteServer.config.configFile
9
+
10
+ // pinegrow plugins
11
+ plugins?: string[]
12
+
13
+ // User can override the themePath in the plugin's options
14
+ // {
15
+ // key: 'vuetify',
16
+ // pluginPath: '...',
17
+ // options: {
18
+ // themePath: './src/themes' // directory or file, for eg, './src/themes/my-pg-theme.cjs'
19
+ // }
20
+ // }
21
+
22
+ devtoolsKey?: string
23
+ // vscodeTunnelUrl?: string
24
+
25
+ // routerHistoryMode?: string // 'hash', 'html5' (default)
26
+
27
+ // Adds to package.json, used when a package was installed (available in lock file) probably as a peer dependency, so not available in package.json
28
+ // mergeWithPackageJson?: {
29
+ // dependencies?: {}
30
+ // devDependencies?: {
31
+ // // vite: string;
32
+ // }
33
+ // }
34
+
35
+ customTypes?: {
36
+ // To apply type overrides to a specific component (overrides above default fn),
37
+ // ComponentName: { prop: { customType: 'icon' } },
38
+ // VRating: {
39
+ // ripple: {
40
+ // customType: "boolean";
41
+ // };
42
+ // };
43
+ // VSelect: {
44
+ // variant: {
45
+ // customType: 'select',
46
+ // options: ['plain', 'outlined', 'underlined', 'solo'],
47
+ // default: ''
48
+ // },
49
+ // density: {
50
+ // customType: 'select',
51
+ // options: ['default', 'compact', 'comfortable']
52
+ // },
53
+ // disabled: {
54
+ // customType: 'boolean'
55
+ // },
56
+ // appendIcon: {
57
+ // customType: 'icon'
58
+ // },
59
+ // }
60
+ // To apply type overrides to all components,
61
+ // all: { prop: { customType: 'icon' } },
62
+ defaultTypes?: {
63
+ // density: {
64
+ // customType: "select";
65
+ // // add options when customType is 'select'
66
+ // options: ["default", "compact", "comfortable"];
67
+ // };
68
+ }
69
+ }
70
+
71
+ tailwindcss?: PinegrowTailwindCSSPluginOptions
72
+
73
+ autoImportComponents?: AutoImportComponentsOptions
74
+
75
+ autoImportAPIs?: AutoImportAPIsOptions
76
+ }
77
+
78
+ interface PinegrowVitePlugin {
79
+ liveDesigner?: {
80
+ [key in string]?: any
81
+ } & Options
82
+ }
83
+
84
+ declare function export_default(liveDesigner: Options): PinegrowVitePlugin
85
+
86
+ export { PinegrowVitePlugin, Options, export_default as default, export_default as liveDesigner }
87
+