maplestory/frontend/src/features/registry.js
caadiq bc0c2b22f0 태블릿 전용 라우트 / 폴더 추가
- routes/tablet.jsx: 태블릿 placeholder
- App.jsx: isMobileOnly / isTablet / (그 외=PC) 3단 분기
- components/tablet/, pages/tablet/: 향후 태블릿 전용 컴포넌트·페이지 자리
- features/registry.js: tablet device 지원 (getTabletComponent 추가)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 16:07:31 +09:00

71 lines
2 KiB
JavaScript

/**
* 기능 자동 등록 시스템
*
* - features/{kebab-case}/pc/{PascalCase}.jsx : PC 사용자 페이지
* - features/{kebab-case}/pc/{PascalCase}Admin.jsx: PC 관리자 페이지
* - features/{kebab-case}/tablet/{PascalCase}.jsx : 태블릿 사용자 페이지
* - features/{kebab-case}/mobile/{PascalCase}.jsx : 모바일 사용자 페이지
*/
import { lazy } from 'react'
const pages = import.meta.glob('./*/{pc,tablet,mobile}/*.jsx')
function slugToPascal(slug) {
return slug
.split('-')
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join('')
}
const userPcCache = new Map()
const adminPcCache = new Map()
const userTabletCache = new Map()
const userMobileCache = new Map()
function loadCached(cache, slug, device, suffix) {
if (cache.has(slug)) return cache.get(slug)
const pascal = slugToPascal(slug)
const path = `./${slug}/${device}/${pascal}${suffix}.jsx`
const loader = pages[path]
const component = loader ? lazy(loader) : null
cache.set(slug, component)
return component
}
/**
* slug에 해당하는 PC 사용자 페이지 컴포넌트 반환
*/
export function getUserComponent(slug) {
return loadCached(userPcCache, slug, 'pc', '')
}
/**
* slug에 해당하는 관리자 페이지 컴포넌트 반환 (PC 전용)
*/
export function getAdminComponent(slug) {
return loadCached(adminPcCache, slug, 'pc', 'Admin')
}
/**
* slug에 해당하는 태블릿 사용자 페이지 컴포넌트 반환
*/
export function getTabletComponent(slug) {
return loadCached(userTabletCache, slug, 'tablet', '')
}
/**
* slug에 해당하는 모바일 사용자 페이지 컴포넌트 반환
*/
export function getMobileComponent(slug) {
return loadCached(userMobileCache, slug, 'mobile', '')
}
/**
* slug에 해당하는 관리자 페이지가 존재하는지
*/
export function hasAdminPage(slug) {
if (!slug) return false
const cleaned = slug.replace(/^\/+/, '').split('/')[0]
return getAdminComponent(cleaned) !== null
}