@pinegrow/vite-plugin
Advanced tools
+111
-4
@@ -13,2 +13,108 @@ import { | ||
| const getAppTreeBoundaryFile = elCacheObj => elCacheObj?.localFile || elCacheObj?.component?.file || null | ||
| const getBoundaryElement = (elCacheObj, fallbackEl = null) => | ||
| elCacheObj?.firstEl || elCacheObj?.el || fallbackEl || null | ||
| const getBoundaryLastElement = (elCacheObj, fallbackEl = null) => | ||
| elCacheObj?.lastEl || elCacheObj?.firstEl || elCacheObj?.el || fallbackEl || null | ||
| const isBoundaryConnected = (elCacheObj, fallbackEl = null) => { | ||
| const firstEl = getBoundaryElement(elCacheObj, fallbackEl) | ||
| const lastEl = getBoundaryLastElement(elCacheObj, fallbackEl) | ||
| return Boolean(firstEl?.isConnected || lastEl?.isConnected || fallbackEl?.isConnected) | ||
| } | ||
| const isBoundaryMounted = elCacheObj => { | ||
| if (!elCacheObj?.instance) { | ||
| return true | ||
| } | ||
| return elCacheObj.instance.isMounted !== false && elCacheObj.instance.isUnmounted !== true | ||
| } | ||
| const isAppTreeBoundary = elCacheObj => { | ||
| if (!elCacheObj) { | ||
| return false | ||
| } | ||
| if (elCacheObj.treeScopes) { | ||
| return elCacheObj.treeScopes.appTree === true && Boolean(getAppTreeBoundaryFile(elCacheObj)) | ||
| } | ||
| return Boolean(getAppTreeBoundaryFile(elCacheObj)) | ||
| } | ||
| const getBoundaryId = elCacheObj => { | ||
| const file = getAppTreeBoundaryFile(elCacheObj) || '' | ||
| const uid = elCacheObj?.instance?.uid ?? '' | ||
| const key = elCacheObj?.key ?? '' | ||
| const pgId = elCacheObj?.pgId ?? elCacheObj?.sourceId ?? elCacheObj?.source?.id ?? '' | ||
| return [file, uid, key, pgId].join('::') | ||
| } | ||
| const createAppTreeBoundariesComputed = elCache => | ||
| computed(() => { | ||
| const boundaries = [] | ||
| const seen = new Set() | ||
| for (let [el, elCacheNodes] of elCache.entries()) { | ||
| if (!Array.isArray(elCacheNodes)) { | ||
| continue | ||
| } | ||
| elCacheNodes.forEach(elCacheObj => { | ||
| if ( | ||
| !isBoundaryMounted(elCacheObj) || | ||
| !isBoundaryConnected(elCacheObj, el) || | ||
| !isAppTreeBoundary(elCacheObj) | ||
| ) { | ||
| return | ||
| } | ||
| const localFile = getAppTreeBoundaryFile(elCacheObj) | ||
| const firstEl = getBoundaryElement(elCacheObj, el) | ||
| const lastEl = getBoundaryLastElement(elCacheObj, el) | ||
| const boundaryId = getBoundaryId(elCacheObj) | ||
| if (!localFile || !firstEl || seen.has(boundaryId)) { | ||
| return | ||
| } | ||
| if (elCacheObj.isIsland) { | ||
| const childEl = firstEl.firstElementChild | ||
| if (childEl && elCache.has(childEl)) { | ||
| return | ||
| } | ||
| } | ||
| seen.add(boundaryId) | ||
| boundaries.push({ | ||
| ...elCacheObj, | ||
| appTreeBoundary: true, | ||
| appTreeBoundaryId: boundaryId, | ||
| localFile, | ||
| firstEl, | ||
| lastEl, | ||
| }) | ||
| }) | ||
| } | ||
| return boundaries.sort((a, b) => { | ||
| const aEl = getBoundaryElement(a) | ||
| const bEl = getBoundaryElement(b) | ||
| if (!aEl?.compareDocumentPosition || !bEl) { | ||
| return 0 | ||
| } | ||
| const position = aEl.compareDocumentPosition(bEl) | ||
| if (position & Node.DOCUMENT_POSITION_PRECEDING) { | ||
| return 1 | ||
| } | ||
| if (position & Node.DOCUMENT_POSITION_FOLLOWING) { | ||
| return -1 | ||
| } | ||
| return 0 | ||
| }) | ||
| }) | ||
| export function usePinegrow() { | ||
@@ -20,5 +126,6 @@ const initCache = () => { | ||
| if (!(winObj?.process?.client && winObj.process.client !== true)) { | ||
| if (!winObj.pinegrow) { | ||
| if (!winObj.pinegrow || !winObj.pinegrow.appTreeBoundariesComputed) { | ||
| // console.log('Cache initialized by Vue Plugin!') | ||
| const elCache = reactive(new Map()) | ||
| const existingPinegrow = winObj.pinegrow || {} | ||
| const elCache = reactive(existingPinegrow.elCache || new Map()) | ||
@@ -34,6 +141,7 @@ const enrichWithComponentName = (elCacheObj, localFile) => { | ||
| winObj.pinegrow = { | ||
| ...existingPinegrow, | ||
| elCache, | ||
| // pgIdToElComputed, | ||
| // localComponentToElComputed, | ||
| // appTree, | ||
| appTreeBoundariesComputed: createAppTreeBoundariesComputed(elCache), | ||
| reactiveFromContext: reactive, | ||
@@ -322,2 +430,1 @@ refFromContext: ref, | ||
| } | ||
+1
-1
| { | ||
| "name": "@pinegrow/vite-plugin", | ||
| "version": "3.0.76-alpha.2", | ||
| "version": "3.0.76-alpha.3", | ||
| "description": "Pinegrow Vite Plugin", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
953829
0.3%495
22.22%28
-3.45%9
-10%