doxa-maps/plugin-designs/research-dashboard/index.js

66 lines
2.8 KiB
JavaScript

/**
* research-dashboard / index.js — Bundle entry (DOXA-LIB-2)
*
* Vite multi-entry build target. Emits app/research-dashboard.js.
*
* Mirrors app-profiles/doxa-research-map/index.js (same ProfileLoader plumbing).
* Registers a SINGLE tag (UNCHANGED from the original profile — only the bundle folder
* is now plural so it can host N dashboard profiles tomorrow):
* - <research-dashboard-map> config-driven people-group research dashboard
*
* The dashboard mounts a Mapbox map in its center cell (Mapbox GL is loaded globally by
* index.html and the token arrives via profile-config.tk), so the RTL-text plugin is
* loaded once here, exactly like the map bundles.
*
* Profile registry — same Q3 contract as the map bundles: ProfileLoader lives in @map and
* cannot import.meta.glob across the package boundary, so the bundle evaluates
* import.meta.glob('./*.vue') HERE and hands the result to the loader via
* app.provide('profileModules'). The library panels live in @map/components/dashboards and
* are imported by the profile .vue — the glob only registers the profile screen(s).
*/
import { defineCustomElement } from 'vue'
import { createPinia } from 'pinia'
import ProfileLoader from '@map/ProfileLoader.vue'
import { createAppI18n } from '@map/i18n/index.js'
// ─── Bundle-private profile registry ─────────────────────────────────────────
const profileModules = import.meta.glob('./*.vue')
// ─── Mapbox RTL text plugin — load ONCE before any map instance ──────────────
if (typeof window !== 'undefined' && window.mapboxgl?.setRTLTextPlugin) {
try {
window.mapboxgl.setRTLTextPlugin(
'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.3.0/mapbox-gl-rtl-text.js',
null,
true // lazy
)
} catch (_) {
// Already set in this session — ignore.
}
}
/**
* Build a fresh defineCustomElement-wrapped class. Each instance gets its own Pinia + i18n
* so multiple embeds on the same page don't bleed state.
*/
function buildDoxaResearchDashboardElement() {
return defineCustomElement(ProfileLoader, {
configureApp(app) {
app.use(createPinia())
app.use(createAppI18n())
app.provide('profileModules', profileModules)
}
})
}
const DoxaResearchDashboardElement = buildDoxaResearchDashboardElement()
// ─── Register ONE tag — <research-dashboard-map> ────────────────────────────
if (typeof customElements !== 'undefined') {
if (!customElements.get('research-dashboard-map')) {
customElements.define('research-dashboard-map', DoxaResearchDashboardElement)
}
}
export default DoxaResearchDashboardElement