DEDUP-AUDIT.md (measured today: 253 files, 31 cross-plugin duplicate clusters, 622 duplicated lines) ranks this tenth by raw cost and first by suitability. It is the only cluster where the copies are identical in code, close over nothing, and sit in two plugins with one owner between them. loadScriptOnce (13 lines) and whenTagDefined (11) were byte-identical between doxa-maps-spa and plugin-studio. deriveTreeBase (9) differed by ONE COMMENT LINE and not one character of code -- drift in the documentation of a shared function, which is its own argument for having one copy. They are one concern, not three: load a bundle's script once, wait for its custom element to register, and work out the tree base to load it from. That is what a capability-5 app shell does to nest another plugin, and both plugins here ARE the capability-5 shells. Any future shell needs the same three. Verbatim move: no parameterisation, no behaviour change, callers import instead of declaring. The comments travel with the code because each records a measurement -- particularly the one explaining why onload is not a usable success signal for a dev-server ES module. ONE BEHAVIOUR CHANGE, AND IT IS AN IMPROVEMENT: the _loaded cache is now shared. Two shells on one page previously kept separate caches and each loaded the same bundle; the second now reuses the first's promise. deriveTreeBase reads document.currentScript, so it is only valid AT MODULE EVALUATION TIME. The call sites did not move -- both entries still call it at module top level -- and the library file documents the constraint, because a later call silently returns '' and every nested bundle URL would break. Verified: both bundles build; each built file contains all three functions exactly once and still derives currentScript; check:sri, check:series-isolation, check:studio-rail and check:capability-derived all PASS. library/utils/embedScript.js is the build owner's under rule 5B. The plugin-designs and public/ changes are in the same commit because they import it -- landing them apart breaks the build in between.
51 lines
2.6 KiB
JavaScript
51 lines
2.6 KiB
JavaScript
/**
|
|
* doxa-maps-spa / index.js — Bundle entry (Capability-5 nested-mfe-spa / app-shell).
|
|
*
|
|
* ONE folder -> ONE bundle -> ONE custom element: <doxa-maps-spa>.
|
|
*
|
|
* <doxa-maps-spa> is the OUTER app-shell of the whole DX-maps app: a vertical-tab layout whose
|
|
* tab-1 is the Cat-4 Big Picture (mounted directly via its real <bp-big-picture> tag + the built
|
|
* big-picture.js) and whose other tabs are every production research map, each nested as its OWN
|
|
* full SPA via that map's standalone leaf page (iframe). See doxa-maps-spa.vue for the full why.
|
|
*
|
|
* ★ ONE-SHOT-DEFINE SAFETY: the ONLY tag this bundle registers is <doxa-maps-spa>. It NEVER
|
|
* imports another plugin's components and NEVER re-registers a tag another bundle owns. The
|
|
* nested maps register their own tags when THEIR IIFE loads (tab-1 loads big-picture.js at
|
|
* runtime; the iframe tabs run each map's own document). So loading this bundle beside any other
|
|
* bundle can never collide.
|
|
*
|
|
* ★ TREE BASE: to find each nested map's .js / leaf page, the shell needs the built tree's root
|
|
* URL. We derive it HERE, at IIFE load, from this script's own URL
|
|
* (.../doxa-maps/doxa-maps-spa/doxa-maps-spa.js) → two levels up = the tree root. That value is
|
|
* provided to the Vue app so the element self-locates from wherever the tree is served (any
|
|
* static host, a subpath, file://). A host can still override it with the tree-base="" attribute
|
|
* or profile-config.treeBase.
|
|
*
|
|
* Usage from a host page (direct-JS, deploy-method-3):
|
|
* <script src="/dx-maps/doxa-maps-spa/doxa-maps-spa.js"></script>
|
|
* <doxa-maps-spa></doxa-maps-spa>
|
|
* <!-- or pin the tree explicitly: -->
|
|
* <doxa-maps-spa tree-base="https://your-host/doxa-maps"></doxa-maps-spa>
|
|
*/
|
|
|
|
import { defineCustomElement } from 'vue'
|
|
import DoxaMapsSpa from './doxa-maps-spa.vue'
|
|
import { deriveTreeBase } from '@map/utils/embedScript.js'
|
|
|
|
// Capture the running <script>'s own URL synchronously at IIFE load, BEFORE any async runs, so
|
|
// document.currentScript is still this bundle's tag. Derive the tree root = two levels up
|
|
// (.../doxa-maps/doxa-maps-spa/doxa-maps-spa.js → .../doxa-maps/). Guarded for non-browser.
|
|
const TREE_BASE = deriveTreeBase()
|
|
|
|
const DoxaMapsSpaElement = defineCustomElement(DoxaMapsSpa, {
|
|
configureApp(app) {
|
|
// Hand the derived tree root to the component (props/attrs still override it).
|
|
app.provide('dmsTreeBase', TREE_BASE)
|
|
}
|
|
})
|
|
|
|
if (typeof customElements !== 'undefined' && !customElements.get('doxa-maps-spa')) {
|
|
customElements.define('doxa-maps-spa', DoxaMapsSpaElement)
|
|
}
|
|
|
|
export default DoxaMapsSpaElement
|