@pinegrow/vite-plugin 3.0.73-alpha.0 → 3.0.73-alpha.5

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.
@@ -8,14 +8,44 @@ export interface AstroRuntimeBridgeOptions {
8
8
  export interface AstroElCacheEntry {
9
9
  el: Element
10
10
  framework: 'astro'
11
+ entryKind: 'source-node' | 'component-boundary' | 'page-root'
12
+ treeScopes: {
13
+ pageTree: boolean
14
+ appTree: boolean
15
+ }
11
16
  isAstro: true
17
+ isAstroSourceDomEntry: boolean
18
+ isAstroComponent: boolean
19
+ isAppTreeComponent: boolean
20
+ isAstroPageRoot?: boolean
12
21
  sourceId: string
13
- pgId: string
14
- key: string
22
+ pgId: string | null
23
+ key: string | null
15
24
  localFile: string | null
16
25
  sourceFile: string | null
17
26
  nodeType: string | null
18
27
  name: string
28
+ source: {
29
+ id: string
30
+ file: string | null
31
+ range: {
32
+ start: number | null
33
+ end: number | null
34
+ status: string
35
+ }
36
+ nodeType: string | null
37
+ name: string
38
+ }
39
+ component: {
40
+ file: string
41
+ name: string
42
+ kind: string
43
+ } | null
44
+ owners: Array<{
45
+ kind: string
46
+ file: string
47
+ name?: string
48
+ }>
19
49
  sourceRange: {
20
50
  start: number | null
21
51
  end: number | null
@@ -32,11 +62,53 @@ export interface AstroElCacheEntry {
32
62
  isIsland: false
33
63
  rootEl: null
34
64
  firstEl: Element
35
- lastEl: Element
36
- instance: null
65
+ lastEl: Element | null
66
+ instance: {
67
+ uid: string
68
+ isMounted: boolean
69
+ isUnmounted: boolean
70
+ type: {
71
+ __name?: string
72
+ __file?: string | null
73
+ }
74
+ props: Record<string, unknown>
75
+ attrs: Record<string, unknown>
76
+ slots: Record<string, unknown>
77
+ subTree: {
78
+ el: Element
79
+ }
80
+ appContext: unknown
81
+ }
37
82
  vnode: null
38
83
  }
39
84
 
85
+ export type AstroComponentEntry = AstroElCacheEntry & {
86
+ entryKind: 'component-boundary' | 'page-root'
87
+ treeScopes: {
88
+ pageTree: false
89
+ appTree: true
90
+ }
91
+ isAstroSourceDomEntry: false
92
+ isAstroComponent: true
93
+ isAppTreeComponent: true
94
+ pgId: null
95
+ key: null
96
+ localFile: string
97
+ sourceFile: string
98
+ nodeType: 'component-file'
99
+ component: {
100
+ file: string
101
+ name: string
102
+ kind: string
103
+ }
104
+ }
105
+
106
+ export function createAstroComponentEntries(input: {
107
+ entries: AstroElCacheEntry[]
108
+ manifest: unknown
109
+ root?: Document | Element
110
+ }): AstroComponentEntry[]
111
+
40
112
  export function createAstroElCacheEntry(input: {
41
113
  element: Element
42
114
  manifest: unknown
@@ -1,6 +1,48 @@
1
1
  const defaultMarkerAttribute = 'data-pg-source-id'
2
2
  const astroFrameworkKey = 'astro'
3
3
 
4
+ const createFallbackComputed = getter => ({
5
+ get value() {
6
+ return getter()
7
+ },
8
+ })
9
+
10
+ const createFallbackRef = value => ({ value })
11
+
12
+ const readWatchSource = source => {
13
+ if (typeof source === 'function') {
14
+ return source()
15
+ }
16
+
17
+ return source?.value
18
+ }
19
+
20
+ const createFallbackWatch = (source, callback, options = {}) => {
21
+ if (options.immediate && typeof callback === 'function') {
22
+ callback(readWatchSource(source), undefined)
23
+ }
24
+
25
+ return () => {}
26
+ }
27
+
28
+ const createAstroSyntheticInstance = (node, element) => ({
29
+ uid: `astro:${node.id}`,
30
+ isMounted: true,
31
+ isUnmounted: false,
32
+ parent: null,
33
+ type: {
34
+ __name: node.name || 'AstroElement',
35
+ __file: null,
36
+ },
37
+ props: {},
38
+ attrs: {},
39
+ slots: {},
40
+ subTree: {
41
+ el: element,
42
+ },
43
+ appContext: null,
44
+ })
45
+
4
46
  const getDefaultWindow = () => {
5
47
  if (typeof window !== 'undefined') {
6
48
  return window
@@ -16,6 +58,13 @@ const isMapLike = value =>
16
58
  typeof value.delete === 'function' &&
17
59
  typeof value.entries === 'function'
18
60
 
61
+ const createReactiveMap = (pinegrow, value) => {
62
+ const map = isMapLike(value) ? value : new Map()
63
+ const reactiveFromContext = pinegrow?.reactiveFromContext
64
+
65
+ return typeof reactiveFromContext === 'function' ? reactiveFromContext(map) : map
66
+ }
67
+
19
68
  const getMarkerAttribute = (manifest, options = {}) =>
20
69
  options.markerAttribute || manifest?.marker?.attribute || defaultMarkerAttribute
21
70
 
@@ -23,6 +72,57 @@ const getManifestSourceKey = manifest => manifest?.sourceFile || manifest?.id ||
23
72
 
24
73
  const normalizeElCacheEntries = entries => Array.isArray(entries) ? entries : []
25
74
 
75
+ const normalizePathLike = value => `${value || ''}`.replace(/\\/g, '/')
76
+
77
+ const getBasename = value => {
78
+ if (!value) {
79
+ return ''
80
+ }
81
+
82
+ return normalizePathLike(value).split('/').pop() || ''
83
+ }
84
+
85
+ const isAstroPageSourceFile = sourceFile =>
86
+ /(^|\/)src\/pages\/.+\.astro$/i.test(normalizePathLike(sourceFile))
87
+
88
+ const getRootElement = root => {
89
+ if (!root) {
90
+ return null
91
+ }
92
+
93
+ if (root.documentElement) {
94
+ return root.documentElement
95
+ }
96
+
97
+ if (root.body) {
98
+ return root.body
99
+ }
100
+
101
+ if (root.firstElementChild) {
102
+ return root.firstElementChild
103
+ }
104
+
105
+ return root.nodeType === 1 ? root : null
106
+ }
107
+
108
+ const createAstroComponentSyntheticInstance = (manifest, componentId, element) => ({
109
+ uid: componentId,
110
+ isMounted: true,
111
+ isUnmounted: false,
112
+ parent: null,
113
+ type: {
114
+ __name: getBasename(manifest?.sourceFile) || 'AstroComponent',
115
+ __file: manifest?.sourceFile || null,
116
+ },
117
+ props: {},
118
+ attrs: {},
119
+ slots: {},
120
+ subTree: {
121
+ el: element,
122
+ },
123
+ appContext: null,
124
+ })
125
+
26
126
  const createNodeIndex = manifest => {
27
127
  const index = new Map()
28
128
 
@@ -61,14 +161,31 @@ const createAstroElCacheEntry = ({ element, manifest, node }) => {
61
161
  return {
62
162
  el: element,
63
163
  framework: astroFrameworkKey,
164
+ entryKind: 'source-node',
165
+ treeScopes: {
166
+ pageTree: true,
167
+ appTree: false,
168
+ },
64
169
  isAstro: true,
170
+ isAstroSourceDomEntry: true,
171
+ isAstroComponent: false,
172
+ isAppTreeComponent: false,
65
173
  sourceId: node.id,
66
174
  pgId: node.id,
67
175
  key: node.id,
68
- localFile: manifest.sourceFile || null,
176
+ localFile: null,
69
177
  sourceFile: manifest.sourceFile || null,
70
178
  nodeType: node.type || null,
71
179
  name: node.name || '',
180
+ source: {
181
+ id: node.id,
182
+ file: manifest.sourceFile || null,
183
+ range: sourceRange,
184
+ nodeType: node.type || null,
185
+ name: node.name || '',
186
+ },
187
+ component: null,
188
+ owners: [],
72
189
  sourceRange,
73
190
  sourceStart: sourceRange.start,
74
191
  sourceEnd: sourceRange.end,
@@ -82,11 +199,98 @@ const createAstroElCacheEntry = ({ element, manifest, node }) => {
82
199
  rootEl: null,
83
200
  firstEl: element,
84
201
  lastEl: element,
85
- instance: null,
202
+ instance: createAstroSyntheticInstance(node, element),
86
203
  vnode: null,
87
204
  }
88
205
  }
89
206
 
207
+ const createAstroComponentEntry = ({ entries, manifest, root }) => {
208
+ const sourceFile = manifest?.sourceFile
209
+ const rootElement = getRootElement(root)
210
+ const isPageFile = isAstroPageSourceFile(sourceFile)
211
+ const isPageRoot = isPageFile && rootElement
212
+
213
+ if (!sourceFile || (!entries.length && !isPageRoot)) {
214
+ return null
215
+ }
216
+
217
+ const firstEntry = entries[0]
218
+ const lastEntry = entries[entries.length - 1]
219
+ const componentId = `astro-component:${sourceFile}`
220
+ const firstEl = isPageRoot ? rootElement : firstEntry.firstEl || firstEntry.el
221
+ const lastEl = isPageRoot ? null : lastEntry.lastEl || lastEntry.el
222
+ const componentName = getBasename(sourceFile)
223
+ const entryKind = isPageRoot ? 'page-root' : 'component-boundary'
224
+
225
+ return {
226
+ el: firstEl,
227
+ framework: astroFrameworkKey,
228
+ entryKind,
229
+ treeScopes: {
230
+ pageTree: false,
231
+ appTree: true,
232
+ },
233
+ isAstro: true,
234
+ isAstroSourceDomEntry: false,
235
+ isAstroComponent: true,
236
+ isAppTreeComponent: true,
237
+ isAstroPageRoot: Boolean(isPageRoot),
238
+ sourceId: componentId,
239
+ pgId: null,
240
+ key: null,
241
+ localFile: sourceFile,
242
+ sourceFile,
243
+ nodeType: 'component-file',
244
+ name: componentName,
245
+ source: {
246
+ id: componentId,
247
+ file: sourceFile,
248
+ range: {
249
+ start: null,
250
+ end: null,
251
+ status: 'component-file',
252
+ },
253
+ nodeType: 'component-file',
254
+ name: componentName,
255
+ },
256
+ component: {
257
+ file: sourceFile,
258
+ name: componentName,
259
+ kind: isPageFile ? 'page' : 'component',
260
+ },
261
+ owners: [],
262
+ sourceRange: {
263
+ start: null,
264
+ end: null,
265
+ status: 'component-file',
266
+ },
267
+ sourceStart: null,
268
+ sourceEnd: null,
269
+ sourceRangeStatus: 'component-file',
270
+ marker: null,
271
+ editability: {
272
+ mode: 'inspect',
273
+ operations: ['select', 'open-source-file'],
274
+ reasons: ['astro-component-file'],
275
+ },
276
+ attributes: [],
277
+ isFragment: false,
278
+ isRootFragment: false,
279
+ isIsland: false,
280
+ rootEl: null,
281
+ firstEl,
282
+ lastEl,
283
+ instance: createAstroComponentSyntheticInstance(manifest, componentId, firstEl),
284
+ vnode: null,
285
+ }
286
+ }
287
+
288
+ const createAstroComponentEntries = ({ entries, manifest, root }) => {
289
+ const componentEntry = createAstroComponentEntry({ entries, manifest, root })
290
+
291
+ return componentEntry ? [componentEntry] : []
292
+ }
293
+
90
294
  const scanAstroSourceDomMarkers = (root, manifest, options = {}) => {
91
295
  const markerAttribute = getMarkerAttribute(manifest, options)
92
296
  const entries = []
@@ -97,6 +301,7 @@ const scanAstroSourceDomMarkers = (root, manifest, options = {}) => {
97
301
  status: 'unavailable',
98
302
  markerAttribute,
99
303
  entries,
304
+ componentEntries: [],
100
305
  missing,
101
306
  reason: manifest?.reason || 'Astro source manifest is unavailable.',
102
307
  }
@@ -107,6 +312,7 @@ const scanAstroSourceDomMarkers = (root, manifest, options = {}) => {
107
312
  status: 'unavailable',
108
313
  markerAttribute,
109
314
  entries,
315
+ componentEntries: [],
110
316
  missing,
111
317
  reason: 'A DOM root with querySelectorAll() is required.',
112
318
  }
@@ -130,6 +336,7 @@ const scanAstroSourceDomMarkers = (root, manifest, options = {}) => {
130
336
  status: 'ready',
131
337
  markerAttribute,
132
338
  entries,
339
+ componentEntries: createAstroComponentEntries({ entries, manifest, root }),
133
340
  missing,
134
341
  }
135
342
  }
@@ -143,17 +350,32 @@ const ensurePinegrowAstroBridge = (win = getDefaultWindow()) => {
143
350
  win.pinegrow = {}
144
351
  }
145
352
 
146
- if (!isMapLike(win.pinegrow.elCache)) {
147
- win.pinegrow.elCache = new Map()
353
+ if (typeof win.pinegrow.reactiveFromContext !== 'function') {
354
+ win.pinegrow.reactiveFromContext = value => value
355
+ }
356
+
357
+ if (typeof win.pinegrow.refFromContext !== 'function') {
358
+ win.pinegrow.refFromContext = createFallbackRef
148
359
  }
149
360
 
361
+ if (typeof win.pinegrow.computedFromContext !== 'function') {
362
+ win.pinegrow.computedFromContext = createFallbackComputed
363
+ }
364
+
365
+ if (typeof win.pinegrow.watchFromContext !== 'function') {
366
+ win.pinegrow.watchFromContext = createFallbackWatch
367
+ }
368
+
369
+ win.pinegrow.elCache = createReactiveMap(win.pinegrow, win.pinegrow.elCache)
370
+
150
371
  if (!win.pinegrow.astro) {
151
372
  win.pinegrow.astro = {}
152
373
  }
153
374
 
154
- if (!isMapLike(win.pinegrow.astro.sourceManifests)) {
155
- win.pinegrow.astro.sourceManifests = new Map()
156
- }
375
+ win.pinegrow.astro.sourceManifests = createReactiveMap(
376
+ win.pinegrow,
377
+ win.pinegrow.astro.sourceManifests
378
+ )
157
379
 
158
380
  return win.pinegrow
159
381
  }
@@ -232,7 +454,9 @@ const refreshAstroElCache = (manifest, options = {}) => {
232
454
  : removeAstroEntriesForManifest(pinegrow.elCache, manifest)
233
455
  const updatedElements = new Set(removal.elements)
234
456
 
235
- scan.entries.forEach(entry => {
457
+ const cacheEntries = [...scan.entries, ...(scan.componentEntries || [])]
458
+
459
+ cacheEntries.forEach(entry => {
236
460
  upsertAstroEntry(pinegrow.elCache, entry)
237
461
  updatedElements.add(entry.el)
238
462
  })
@@ -251,7 +475,7 @@ const refreshAstroElCache = (manifest, options = {}) => {
251
475
 
252
476
  return {
253
477
  ...scan,
254
- cached: scan.entries.length,
478
+ cached: cacheEntries.length,
255
479
  removed: removal.removed,
256
480
  }
257
481
  }
@@ -267,6 +491,7 @@ const createAstroRuntimeBridge = (manifest, options = {}) => ({
267
491
  })
268
492
 
269
493
  export {
494
+ createAstroComponentEntries,
270
495
  createAstroElCacheEntry,
271
496
  createAstroRuntimeBridge,
272
497
  ensurePinegrowAstroBridge,
@@ -1 +1 @@
1
- (()=>{var e={748:e=>{e.exports=function(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n},e.exports.__esModule=!0,e.exports.default=e.exports},314:e=>{e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},290:(e,r,t)=>{var n=t(739);e.exports=function(e,r,t){return(r=n(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e},e.exports.__esModule=!0,e.exports.default=e.exports},193:e=>{e.exports=function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,u,i,l=[],s=!0,a=!1;try{if(u=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(n=u.call(t)).done)&&(l.push(n.value),l.length!==r);s=!0);}catch(e){a=!0,o=e}finally{try{if(!s&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(a)throw o}}return l}},e.exports.__esModule=!0,e.exports.default=e.exports},147:e=>{e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},681:(e,r,t)=>{var n=t(314),o=t(193),u=t(121),i=t(147);e.exports=function(e,r){return n(e)||o(e,r)||u(e,r)||i()},e.exports.__esModule=!0,e.exports.default=e.exports},64:(e,r,t)=>{var n=t(425).default;e.exports=function(e,r){if("object"!==n(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r||"default");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},739:(e,r,t)=>{var n=t(425).default,o=t(64);e.exports=function(e){var r=o(e,"string");return"symbol"===n(r)?r:String(r)},e.exports.__esModule=!0,e.exports.default=e.exports},425:e=>{function r(t){return e.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,r(t)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports},121:(e,r,t)=>{var n=t(748);e.exports=function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var u=r[n]={exports:{}};return e[n](u,u.exports,t),u.exports}t.d=(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";t.r(n),t.d(n,{createAstroElCacheEntry:()=>f,createAstroRuntimeBridge:()=>y,ensurePinegrowAstroBridge:()=>p,refreshAstroElCache:()=>v,scanAstroSourceDomMarkers:()=>d});var e=t(290),r=t(681);function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function u(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}var i="astro",l=function(){return"undefined"!=typeof window?window:null},s=function(e){return e&&"function"==typeof e.get&&"function"==typeof e.set&&"function"==typeof e.delete&&"function"==typeof e.entries},a=function(e){return(null==e?void 0:e.sourceFile)||(null==e?void 0:e.id)||null},c=function(e){return Array.isArray(e)?e:[]},f=function(e){var r,t,n=e.element,o=e.manifest,u=e.node,l={start:null!==(r=u.sourceStart)&&void 0!==r?r:null,end:null!==(t=u.sourceEnd)&&void 0!==t?t:null,status:u.sourceRangeStatus||"unknown"};return{el:n,framework:i,isAstro:!0,sourceId:u.id,pgId:u.id,key:u.id,localFile:o.sourceFile||null,sourceFile:o.sourceFile||null,nodeType:u.type||null,name:u.name||"",sourceRange:l,sourceStart:l.start,sourceEnd:l.end,sourceRangeStatus:l.status,marker:u.marker||null,editability:u.editability||null,attributes:u.attributes||[],isFragment:!1,isRootFragment:!1,isIsland:!1,rootEl:null,firstEl:n,lastEl:n,instance:null,vnode:null}},d=function(e,r){var t=function(e){var r;return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).markerAttribute||(null==e||null===(r=e.marker)||void 0===r?void 0:r.attribute)||"data-pg-source-id"}(r,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}),n=[],o=[];if("ready"!==(null==r?void 0:r.status))return{status:"unavailable",markerAttribute:t,entries:n,missing:o,reason:(null==r?void 0:r.reason)||"Astro source manifest is unavailable."};if(!e||"function"!=typeof e.querySelectorAll)return{status:"unavailable",markerAttribute:t,entries:n,missing:o,reason:"A DOM root with querySelectorAll() is required."};var u=function(e){var r=new Map;return((null==e?void 0:e.nodes)||[]).forEach((function(e){null!=e&&e.id&&r.set(e.id,e)})),r}(r);return function(e,r){return e&&"function"==typeof e.querySelectorAll?Array.from(e.querySelectorAll("[".concat(r,"]"))):[]}(e,t).forEach((function(e){var i=function(e,r){return e&&"function"==typeof e.getAttribute?e.getAttribute(r):null}(e,t),l=u.get(i);l?n.push(f({element:e,manifest:r,node:l})):o.push({element:e,sourceId:i})})),{status:"ready",markerAttribute:t,entries:n,missing:o}},p=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:l();return e?(e.pinegrow||(e.pinegrow={}),s(e.pinegrow.elCache)||(e.pinegrow.elCache=new Map),e.pinegrow.astro||(e.pinegrow.astro={}),s(e.pinegrow.astro.sourceManifests)||(e.pinegrow.astro.sourceManifests=new Map),e.pinegrow):null},v=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=t.win||l(),o=t.root||(null==n?void 0:n.document)||null,s=p(n),f=d(o,e,t);if(!s)return u(u({},f),{},{cached:0,removed:0,reason:f.reason||"A browser window is required."});if("ready"!==f.status)return u(u({},f),{},{cached:0,removed:0});var v=!1===t.clearPrevious?{elements:[],removed:0}:function(e,t){var n=a(t),o=0,u=[];return n?(Array.from(e.entries()).forEach((function(t){var l=r(t,2),s=l[0],a=l[1],f=c(a),d=f.filter((function(e){return!function(e,r){return(null==e?void 0:e.framework)===i&&(e.localFile===r||e.sourceFile===r)}(e,n)})),p=f.length-d.length;o+=p,p&&u.push(s),d.length?e.set(s,d):e.delete(s)})),{elements:u,removed:o}):{elements:u,removed:o}}(s.elCache,e),y=new Set(v.elements);f.entries.forEach((function(e){!function(e,r){var t=c(e.get(r.el)).filter((function(e){return e.framework!==i||e.sourceId!==r.sourceId||e.localFile!==r.localFile}));t.push(r),e.set(r.el,t)}(s.elCache,e),y.add(e.el)})),y.forEach((function(e){s.elUpdateHanderFn&&s.elUpdateHanderFn(e)}));var m=a(e);return m&&s.astro.sourceManifests.set(m,e),u(u({},f),{},{cached:f.entries.length,removed:v.removed})},y=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{manifest:e,scan:function(t){var n,o;return d(t||r.root||(null===(n=r.win)||void 0===n?void 0:n.document)||(null===(o=l())||void 0===o?void 0:o.document),e,r)},refresh:function(t){return v(e,u(u({},r),t))}}}})(),module.exports=n})();
1
+ (()=>{var e={748:e=>{e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},314:e=>{e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},850:(e,t,r)=>{var n=r(748);e.exports=function(e){if(Array.isArray(e))return n(e)},e.exports.__esModule=!0,e.exports.default=e.exports},290:(e,t,r)=>{var n=r(739);e.exports=function(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},912:e=>{e.exports=function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)},e.exports.__esModule=!0,e.exports.default=e.exports},193:e=>{e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,u,i,l=[],s=!0,a=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=u.call(r)).done)&&(l.push(n.value),l.length!==t);s=!0);}catch(e){a=!0,o=e}finally{try{if(!s&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(a)throw o}}return l}},e.exports.__esModule=!0,e.exports.default=e.exports},147:e=>{e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},96:e=>{e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},681:(e,t,r)=>{var n=r(314),o=r(193),u=r(121),i=r(147);e.exports=function(e,t){return n(e)||o(e,t)||u(e,t)||i()},e.exports.__esModule=!0,e.exports.default=e.exports},408:(e,t,r)=>{var n=r(850),o=r(912),u=r(121),i=r(96);e.exports=function(e){return n(e)||o(e)||u(e)||i()},e.exports.__esModule=!0,e.exports.default=e.exports},64:(e,t,r)=>{var n=r(425).default;e.exports=function(e,t){if("object"!==n(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},739:(e,t,r)=>{var n=r(425).default,o=r(64);e.exports=function(e){var t=o(e,"string");return"symbol"===n(t)?t:String(t)},e.exports.__esModule=!0,e.exports.default=e.exports},425:e=>{function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},121:(e,t,r)=>{var n=r(748);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var u=t[n]={exports:{}};return e[n](u,u.exports,r),u.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};(()=>{"use strict";r.r(n),r.d(n,{createAstroComponentEntries:()=>w,createAstroElCacheEntry:()=>x,createAstroRuntimeBridge:()=>S,ensurePinegrowAstroBridge:()=>A,refreshAstroElCache:()=>_,scanAstroSourceDomMarkers:()=>h});var e=r(408),t=r(290),o=r(681);function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?u(Object(n),!0).forEach((function(r){t(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var l="astro",s=function(e){return{get value(){return e()}}},a=function(e){return{value:e}},c=function(e,t){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}).immediate&&"function"==typeof t&&t(function(e){return"function"==typeof e?e():null==e?void 0:e.value}(e),void 0),function(){}},p=function(e,t){return{uid:"astro:".concat(e.id),isMounted:!0,isUnmounted:!1,parent:null,type:{__name:e.name||"AstroElement",__file:null},props:{},attrs:{},slots:{},subTree:{el:t},appContext:null}},f=function(){return"undefined"!=typeof window?window:null},d=function(e,t){var r=function(e){return e&&"function"==typeof e.get&&"function"==typeof e.set&&"function"==typeof e.delete&&"function"==typeof e.entries}(t)?t:new Map,n=null==e?void 0:e.reactiveFromContext;return"function"==typeof n?n(r):r},m=function(e){return(null==e?void 0:e.sourceFile)||(null==e?void 0:e.id)||null},y=function(e){return Array.isArray(e)?e:[]},v=function(e){return"".concat(e||"").replace(/\\/g,"/")},g=function(e){return e&&v(e).split("/").pop()||""},b=function(e,t,r){return{uid:t,isMounted:!0,isUnmounted:!1,parent:null,type:{__name:g(null==e?void 0:e.sourceFile)||"AstroComponent",__file:(null==e?void 0:e.sourceFile)||null},props:{},attrs:{},slots:{},subTree:{el:r},appContext:null}},x=function(e){var t,r,n=e.element,o=e.manifest,u=e.node,i={start:null!==(t=u.sourceStart)&&void 0!==t?t:null,end:null!==(r=u.sourceEnd)&&void 0!==r?r:null,status:u.sourceRangeStatus||"unknown"};return{el:n,framework:l,entryKind:"source-node",treeScopes:{pageTree:!0,appTree:!1},isAstro:!0,isAstroSourceDomEntry:!0,isAstroComponent:!1,isAppTreeComponent:!1,sourceId:u.id,pgId:u.id,key:u.id,localFile:null,sourceFile:o.sourceFile||null,nodeType:u.type||null,name:u.name||"",source:{id:u.id,file:o.sourceFile||null,range:i,nodeType:u.type||null,name:u.name||""},component:null,owners:[],sourceRange:i,sourceStart:i.start,sourceEnd:i.end,sourceRangeStatus:i.status,marker:u.marker||null,editability:u.editability||null,attributes:u.attributes||[],isFragment:!1,isRootFragment:!1,isIsland:!1,rootEl:null,firstEl:n,lastEl:n,instance:p(u,n),vnode:null}},w=function(e){var t=function(e){var t=e.entries,r=e.manifest,n=e.root,o=null==r?void 0:r.sourceFile,u=function(e){return e?e.documentElement?e.documentElement:e.body?e.body:e.firstElementChild?e.firstElementChild:1===e.nodeType?e:null:null}(n),i=function(e){return/(^|\/)src\/pages\/.+\.astro$/i.test(v(e))}(o),s=i&&u;if(!o||!t.length&&!s)return null;var a=t[0],c=t[t.length-1],p="astro-component:".concat(o),f=s?u:a.firstEl||a.el,d=s?null:c.lastEl||c.el,m=g(o);return{el:f,framework:l,entryKind:s?"page-root":"component-boundary",treeScopes:{pageTree:!1,appTree:!0},isAstro:!0,isAstroSourceDomEntry:!1,isAstroComponent:!0,isAppTreeComponent:!0,isAstroPageRoot:Boolean(s),sourceId:p,pgId:null,key:null,localFile:o,sourceFile:o,nodeType:"component-file",name:m,source:{id:p,file:o,range:{start:null,end:null,status:"component-file"},nodeType:"component-file",name:m},component:{file:o,name:m,kind:i?"page":"component"},owners:[],sourceRange:{start:null,end:null,status:"component-file"},sourceStart:null,sourceEnd:null,sourceRangeStatus:"component-file",marker:null,editability:{mode:"inspect",operations:["select","open-source-file"],reasons:["astro-component-file"]},attributes:[],isFragment:!1,isRootFragment:!1,isIsland:!1,rootEl:null,firstEl:f,lastEl:d,instance:b(r,p,f),vnode:null}}({entries:e.entries,manifest:e.manifest,root:e.root});return t?[t]:[]},h=function(e,t){var r=function(e){var t;return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).markerAttribute||(null==e||null===(t=e.marker)||void 0===t?void 0:t.attribute)||"data-pg-source-id"}(t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}),n=[],o=[];if("ready"!==(null==t?void 0:t.status))return{status:"unavailable",markerAttribute:r,entries:n,componentEntries:[],missing:o,reason:(null==t?void 0:t.reason)||"Astro source manifest is unavailable."};if(!e||"function"!=typeof e.querySelectorAll)return{status:"unavailable",markerAttribute:r,entries:n,componentEntries:[],missing:o,reason:"A DOM root with querySelectorAll() is required."};var u=function(e){var t=new Map;return((null==e?void 0:e.nodes)||[]).forEach((function(e){null!=e&&e.id&&t.set(e.id,e)})),t}(t);return function(e,t){return e&&"function"==typeof e.querySelectorAll?Array.from(e.querySelectorAll("[".concat(t,"]"))):[]}(e,r).forEach((function(e){var i=function(e,t){return e&&"function"==typeof e.getAttribute?e.getAttribute(t):null}(e,r),l=u.get(i);l?n.push(x({element:e,manifest:t,node:l})):o.push({element:e,sourceId:i})})),{status:"ready",markerAttribute:r,entries:n,componentEntries:w({entries:n,manifest:t,root:e}),missing:o}},A=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:f();return e?(e.pinegrow||(e.pinegrow={}),"function"!=typeof e.pinegrow.reactiveFromContext&&(e.pinegrow.reactiveFromContext=function(e){return e}),"function"!=typeof e.pinegrow.refFromContext&&(e.pinegrow.refFromContext=a),"function"!=typeof e.pinegrow.computedFromContext&&(e.pinegrow.computedFromContext=s),"function"!=typeof e.pinegrow.watchFromContext&&(e.pinegrow.watchFromContext=c),e.pinegrow.elCache=d(e.pinegrow,e.pinegrow.elCache),e.pinegrow.astro||(e.pinegrow.astro={}),e.pinegrow.astro.sourceManifests=d(e.pinegrow,e.pinegrow.astro.sourceManifests),e.pinegrow):null},_=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.win||f(),u=r.root||(null==n?void 0:n.document)||null,s=A(n),a=h(u,t,r);if(!s)return i(i({},a),{},{cached:0,removed:0,reason:a.reason||"A browser window is required."});if("ready"!==a.status)return i(i({},a),{},{cached:0,removed:0});var c=!1===r.clearPrevious?{elements:[],removed:0}:function(e,t){var r=m(t),n=0,u=[];return r?(Array.from(e.entries()).forEach((function(t){var i=o(t,2),s=i[0],a=i[1],c=y(a),p=c.filter((function(e){return!function(e,t){return(null==e?void 0:e.framework)===l&&(e.localFile===t||e.sourceFile===t)}(e,r)})),f=c.length-p.length;n+=f,f&&u.push(s),p.length?e.set(s,p):e.delete(s)})),{elements:u,removed:n}):{elements:u,removed:n}}(s.elCache,t),p=new Set(c.elements),d=[].concat(e(a.entries),e(a.componentEntries||[]));d.forEach((function(e){!function(e,t){var r=y(e.get(t.el)).filter((function(e){return e.framework!==l||e.sourceId!==t.sourceId||e.localFile!==t.localFile}));r.push(t),e.set(t.el,r)}(s.elCache,e),p.add(e.el)})),p.forEach((function(e){s.elUpdateHanderFn&&s.elUpdateHanderFn(e)}));var v=m(t);return v&&s.astro.sourceManifests.set(v,t),i(i({},a),{},{cached:d.length,removed:c.removed})},S=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{manifest:e,scan:function(r){var n,o;return h(r||t.root||(null===(n=t.win)||void 0===n?void 0:n.document)||(null===(o=f())||void 0===o?void 0:o.document),e,t)},refresh:function(r){return _(e,i(i({},t),r))}}}})(),module.exports=n})();
@@ -1,4 +1,5 @@
1
1
  export {
2
+ createAstroComponentEntries,
2
3
  createAstroElCacheEntry,
3
4
  createAstroRuntimeBridge,
4
5
  ensurePinegrowAstroBridge,
package/dist/vue/index.js CHANGED
@@ -16,10 +16,26 @@ export function usePinegrow() {
16
16
  const winObj = window
17
17
 
18
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())
19
+ const isMapLike = value =>
20
+ value &&
21
+ typeof value.get === 'function' &&
22
+ typeof value.set === 'function' &&
23
+ typeof value.delete === 'function' &&
24
+ typeof value.entries === 'function'
25
+
26
+ const existingPinegrow = winObj.pinegrow || {}
27
+ const existingElCache = isMapLike(existingPinegrow.elCache) ? existingPinegrow.elCache : new Map()
28
+ const elCache = reactive(existingElCache)
22
29
 
30
+ if (
31
+ !winObj.pinegrow ||
32
+ winObj.pinegrow.elCache !== elCache ||
33
+ winObj.pinegrow.reactiveFromContext !== reactive ||
34
+ winObj.pinegrow.refFromContext !== ref ||
35
+ winObj.pinegrow.computedFromContext !== computed ||
36
+ winObj.pinegrow.watchFromContext !== watch
37
+ ) {
38
+ // console.log('Cache initialized by Vue Plugin!')
23
39
  const enrichWithComponentName = (elCacheObj, localFile) => {
24
40
  return {
25
41
  name: elCacheObj.instance.type.__name || '',
@@ -28,7 +44,7 @@ export function usePinegrow() {
28
44
  }
29
45
  }
30
46
 
31
- winObj.pinegrow = {
47
+ winObj.pinegrow = Object.assign(existingPinegrow, {
32
48
  elCache,
33
49
  // pgIdToElComputed,
34
50
  // localComponentToElComputed,
@@ -40,7 +56,7 @@ export function usePinegrow() {
40
56
  // // Uncomment these two to test locally
41
57
  // elCacheErrHandlerFn,
42
58
  // elUpdateHanderFn,
43
- }
59
+ })
44
60
  }
45
61
  }
46
62
  }
@@ -316,4 +332,3 @@ export function usePinegrow() {
316
332
 
317
333
  return { pgUpdateElCache }
318
334
  }
319
-
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@pinegrow/vite-plugin",
3
- "version": "3.0.73-alpha.0",
3
+ "version": "3.0.73-alpha.5",
4
4
  "description": "Pinegrow Vite Plugin",
5
5
  "type": "module",
6
- "files": [
7
- "dist",
8
- "./types.d.ts",
9
- "./astro.d.ts",
10
- "./astro-runtime.d.ts"
11
- ],
6
+ "files": [
7
+ "dist",
8
+ "./types.d.ts",
9
+ "./astro.d.ts",
10
+ "./astro-runtime.d.ts"
11
+ ],
12
12
  "main": "./dist/index.cjs",
13
13
  "module": "./dist/index.mjs",
14
14
  "types": "./types.d.ts",
@@ -17,25 +17,25 @@
17
17
  "types": "./types.d.ts",
18
18
  "import": "./dist/index.mjs",
19
19
  "require": "./dist/index.cjs"
20
- },
21
- "./dev": {
22
- "import": "./src/index.dev.js",
23
- "require": "./src/index.dev.js"
24
- },
25
- "./vue": {
26
- "import": "./dist/vue/index.js"
27
- },
28
- "./astro": {
29
- "types": "./astro.d.ts",
30
- "import": "./dist/astro/index.mjs",
31
- "require": "./dist/astro/index.cjs"
32
- },
33
- "./astro/runtime": {
34
- "types": "./astro-runtime.d.ts",
35
- "import": "./dist/astro/runtime.mjs",
36
- "require": "./dist/astro/runtime.cjs"
37
- }
38
- },
20
+ },
21
+ "./dev": {
22
+ "import": "./src/index.dev.js",
23
+ "require": "./src/index.dev.js"
24
+ },
25
+ "./vue": {
26
+ "import": "./dist/vue/index.js"
27
+ },
28
+ "./astro": {
29
+ "types": "./astro.d.ts",
30
+ "import": "./dist/astro/index.mjs",
31
+ "require": "./dist/astro/index.cjs"
32
+ },
33
+ "./astro/runtime": {
34
+ "types": "./astro-runtime.d.ts",
35
+ "import": "./dist/astro/runtime.mjs",
36
+ "require": "./dist/astro/runtime.cjs"
37
+ }
38
+ },
39
39
  "keywords": [
40
40
  "pinegrow",
41
41
  "vue designer",
@@ -46,23 +46,23 @@
46
46
  ],
47
47
  "author": "Pinegrow (http://pinegrow.com/)",
48
48
  "license": "MIT",
49
- "scripts": {
50
- "build": "webpack -- --env mode=production vite",
51
- "build:vite-plugin": "webpack -- --env mode=production vite",
52
- "build:vite-plugin:dev": "webpack -- --env mode=development vite",
53
- "test": "node --test test/*.test.mjs",
54
- "publish-alpha": "npm run increment-alpha-version && npm publish --tag alpha",
55
- "increment-alpha-version": "npm version prerelease --preid=alpha",
56
- "publish-beta": "npm run increment-beta-version && npm publish --tag beta",
49
+ "scripts": {
50
+ "build": "webpack -- --env mode=production vite",
51
+ "build:vite-plugin": "webpack -- --env mode=production vite",
52
+ "build:vite-plugin:dev": "webpack -- --env mode=development vite",
53
+ "test": "node --test test/*.test.mjs",
54
+ "publish-alpha": "npm run increment-alpha-version && npm publish --tag alpha",
55
+ "increment-alpha-version": "npm version prerelease --preid=alpha",
56
+ "publish-beta": "npm run increment-beta-version && npm publish --tag beta",
57
57
  "increment-beta-version": "npm version prerelease --preid=beta",
58
58
  "publish-patch": "npm run increment-version && npm publish",
59
59
  "increment-version": "npm version patch"
60
60
  },
61
- "dependencies": {
62
- "@vue/compiler-sfc": "^3.2.45",
63
- "magic-string": "^0.27.0"
64
- },
65
- "devDependencies": {
66
- "@astrojs/compiler": "^2.2.1"
67
- }
68
- }
61
+ "dependencies": {
62
+ "@vue/compiler-sfc": "^3.2.45",
63
+ "magic-string": "^0.27.0"
64
+ },
65
+ "devDependencies": {
66
+ "@astrojs/compiler": "^2.2.1"
67
+ }
68
+ }