diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands-opac.ts b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands-opac.ts index 780b6e65d3..2a515abdb5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands-opac.ts +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands-opac.ts @@ -1,5 +1,11 @@ export * from "./islands"; -import { hydrate, registerIsland, WebComponentDynamicImport } from "./islands"; +import { + hydrate as hydrateIslands, + registerIsland, + IslandStoreDefinitions, + WebComponentDynamicImport, +} from "./islands"; +import { useMainStore } from "../stores/main"; /** * The islands available in the OPAC. @@ -16,14 +22,35 @@ const islands: Map = new Map([ ); return module.default; }, - config: {}, + config: { + stores: ["mainStore"], + }, }, ], ]); +/** + * The Pinia stores islands in the OPAC may request via config.stores. + * @type {IslandStoreDefinitions} + */ +const storeDefinitions: IslandStoreDefinitions = { + mainStore: useMainStore, +}; + // Core islands take the same registration path as plugin islands. islands.forEach((entry, name) => registerIsland(name, entry)); +/** + * Hydrates islands with the OPAC store set. + * + * This local export takes precedence over the star re-export from ./islands, + * so imports of hydrate from the built islands.esm.js get the stores baked in. + * @returns {void} + */ +export function hydrate(): void { + hydrateIslands(storeDefinitions); +} + if (parseInt(document?.currentScript?.getAttribute("init") ?? "0", 10)) { hydrate(); }