UNPKG

next

Version:

The React Framework

54 lines (53 loc) 1.75 kB
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'; import { isParallelRouteSegment } from '../shared/lib/segment'; /** * Extract slot info from a page path if it contains a parallel route */ export function extractSlotFromPath(pagePath) { const segments = pagePath.split('/'); for(let i = segments.length - 1; i >= 0; i--){ const segment = segments[i]; if (isParallelRouteSegment(segment)) { return { name: segment.slice(1), parent: normalizeAppPath(segments.slice(0, i).join('/')) }; } } return undefined; } /** * Add a slot to the slots array if it doesn't already exist */ export function addSlotIfNew(slots, pagePath) { const slot = extractSlotFromPath(pagePath); if (!slot) return false; if (slots.some((s)=>s.name === slot.name && s.parent === slot.parent)) return false; slots.push(slot); return true; } /** * Extract slots from a route mapping object */ export function extractSlotsFromRoutes(routes, skipRoutes) { const slots = []; for (const [route] of Object.entries(routes)){ if (skipRoutes == null ? void 0 : skipRoutes.has(route)) continue; addSlotIfNew(slots, route); } return slots; } /** * Combine and deduplicate slot arrays */ export function combineSlots(...slotArrays) { const slotSet = new Set(); const result = []; for (const slots of slotArrays){ for (const slot of slots){ const key = `${slot.name}:${slot.parent}`; if (!slotSet.has(key)) { slotSet.add(key); result.push(slot); } } } return result; } //# sourceMappingURL=file-classifier.js.map