@pinegrow/vite-plugin
Advanced tools
+85
-9
@@ -18,2 +18,14 @@ import { | ||
| elCacheObj?.lastEl || elCacheObj?.firstEl || elCacheObj?.el || fallbackEl || null | ||
| const getSourceInspector = (elCacheObj, fallbackEl = null) => { | ||
| const props = elCacheObj?.vnode?.props | ||
| const firstEl = getBoundaryElement(elCacheObj, fallbackEl) | ||
| return ( | ||
| elCacheObj?.sourceInspector || | ||
| props?.['data-v-inspector'] || | ||
| firstEl?.getAttribute?.('data-v-inspector') || | ||
| fallbackEl?.getAttribute?.('data-v-inspector') || | ||
| null | ||
| ) | ||
| } | ||
| const isBoundaryConnected = (elCacheObj, fallbackEl = null) => { | ||
@@ -51,6 +63,44 @@ const firstEl = getBoundaryElement(elCacheObj, fallbackEl) | ||
| } | ||
| const getRuntimeBoundaryKey = (elCacheObj, localFile, firstEl) => { | ||
| const uid = elCacheObj?.instance?.uid | ||
| if (uid !== undefined && uid !== null) { | ||
| const key = elCacheObj?.key ?? '' | ||
| return [localFile || '', uid, key].join('::') | ||
| } | ||
| return getBoundaryId({ ...elCacheObj, localFile, firstEl }) | ||
| } | ||
| const mergeAppTreeBoundary = (existing, candidate) => { | ||
| if (!existing) { | ||
| return candidate | ||
| } | ||
| const preferred = candidate.sourcePgId && !existing.sourcePgId ? candidate : existing | ||
| const fallback = preferred === existing ? candidate : existing | ||
| const sourceElCacheObj = preferred.sourcePgId | ||
| ? preferred.sourceElCacheObj || preferred | ||
| : fallback.sourcePgId | ||
| ? fallback.sourceElCacheObj || fallback | ||
| : preferred.sourceElCacheObj || fallback.sourceElCacheObj || preferred | ||
| const sourcePgId = preferred.sourcePgId || fallback.sourcePgId || null | ||
| const renderPgId = preferred.renderPgId || fallback.renderPgId || null | ||
| const sourceInspector = preferred.sourceInspector || fallback.sourceInspector || null | ||
| return { | ||
| ...fallback, | ||
| ...preferred, | ||
| sourceElCacheObj, | ||
| sourcePgId, | ||
| renderPgId, | ||
| sourceInspector, | ||
| pgId: sourcePgId || preferred.pgId || fallback.pgId || null, | ||
| firstEl: preferred.firstEl || fallback.firstEl, | ||
| lastEl: preferred.lastEl || fallback.lastEl, | ||
| el: preferred.el || fallback.el, | ||
| localFile: preferred.localFile || fallback.localFile, | ||
| } | ||
| } | ||
| const createAppTreeBoundariesComputed = elCache => | ||
| computed(() => { | ||
| const boundaries = [] | ||
| const seen = new Set() | ||
| const boundariesByRuntimeKey = new Map() | ||
@@ -74,5 +124,4 @@ for (let [el, elCacheNodes] of elCache.entries()) { | ||
| const lastEl = getBoundaryLastElement(elCacheObj, el) | ||
| const boundaryId = getBoundaryId(elCacheObj) | ||
| if (!localFile || !firstEl || seen.has(boundaryId)) { | ||
| if (!localFile || !firstEl) { | ||
| return | ||
@@ -88,15 +137,35 @@ } | ||
| seen.add(boundaryId) | ||
| boundaries.push({ | ||
| const sourcePgId = elCacheObj.sourcePgId || null | ||
| const renderPgId = !sourcePgId | ||
| ? elCacheObj.renderPgId || elCacheObj.pgId || null | ||
| : elCacheObj.renderPgId || null | ||
| const candidate = { | ||
| ...elCacheObj, | ||
| sourceElCacheObj: elCacheObj, | ||
| appTreeBoundary: true, | ||
| appTreeBoundaryId: boundaryId, | ||
| appTreeBoundaryId: null, | ||
| localFile, | ||
| firstEl, | ||
| lastEl, | ||
| }) | ||
| sourcePgId, | ||
| renderPgId, | ||
| sourceInspector: getSourceInspector(elCacheObj, el), | ||
| } | ||
| const runtimeKey = getRuntimeBoundaryKey(candidate, localFile, firstEl) | ||
| boundariesByRuntimeKey.set( | ||
| runtimeKey, | ||
| mergeAppTreeBoundary(boundariesByRuntimeKey.get(runtimeKey), candidate) | ||
| ) | ||
| }) | ||
| } | ||
| const boundaries = Array.from(boundariesByRuntimeKey.values()).map(boundary => { | ||
| const boundaryId = getBoundaryId(boundary) | ||
| return { | ||
| ...boundary, | ||
| appTreeBoundaryId: boundaryId, | ||
| } | ||
| }) | ||
| return boundaries.sort((a, b) => { | ||
@@ -305,2 +374,5 @@ const aEl = getBoundaryElement(a) | ||
| const isComponentVNode = Boolean(vnode.component) | ||
| const sourceInspector = getSourceInspector({ vnode, el, firstEl, lastEl }, el) | ||
| let elCacheObj = { | ||
@@ -316,3 +388,5 @@ el, | ||
| pgId, | ||
| sourcePgId: vnode.component && pgId ? pgId : null, | ||
| sourcePgId: isComponentVNode && pgId ? pgId : null, | ||
| renderPgId: !isComponentVNode && pgId ? pgId : null, | ||
| sourceInspector, | ||
| key, | ||
@@ -332,2 +406,4 @@ localFile, | ||
| elCacheObj.sourcePgId = elCacheObj.sourcePgId || prevElCacheObj.sourcePgId | ||
| elCacheObj.renderPgId = elCacheObj.renderPgId || prevElCacheObj.renderPgId | ||
| elCacheObj.sourceInspector = elCacheObj.sourceInspector || prevElCacheObj.sourceInspector | ||
| if (elCacheObj.pgId && prevElCacheObj.pgId && elCacheObj.pgId !== prevElCacheObj.pgId) { | ||
@@ -334,0 +410,0 @@ if (!prevElCacheNodes.map(prevElCacheNode => prevElCacheNode.pgId).includes(elCacheObj.pgId)) { |
+1
-1
| { | ||
| "name": "@pinegrow/vite-plugin", | ||
| "version": "3.0.76-alpha.4", | ||
| "version": "3.0.76-alpha.5", | ||
| "description": "Pinegrow Vite Plugin", | ||
@@ -5,0 +5,0 @@ "type": "module", |
956722
0.28%567
13.86%