athena-portal-app-kit 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/preview-embed.js +26 -4
- package/package.json +1 -1
package/assets/preview-embed.js
CHANGED
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
function buildEmbedShell(config, role, sections) {
|
|
142
|
+
function buildEmbedShell(config, role, sections, onRoleChange) {
|
|
143
143
|
var activeHref = config.appKey ? "/apps/" + config.appKey : "";
|
|
144
144
|
var waPage = document.createElement("wa-page");
|
|
145
145
|
waPage.className = "shell athena-preview-shell";
|
|
@@ -255,7 +255,7 @@
|
|
|
255
255
|
main.appendChild(appWrap);
|
|
256
256
|
|
|
257
257
|
roleSelect.addEventListener("change", function () {
|
|
258
|
-
|
|
258
|
+
if (typeof onRoleChange === "function") onRoleChange(roleSelect.value);
|
|
259
259
|
});
|
|
260
260
|
|
|
261
261
|
waPage.appendChild(headerSlot);
|
|
@@ -281,10 +281,13 @@
|
|
|
281
281
|
|
|
282
282
|
var appMain = document.querySelector("main.portal-app");
|
|
283
283
|
if (!appMain) {
|
|
284
|
-
showError(
|
|
284
|
+
showError('Missing <main class="portal-app"> for preview.');
|
|
285
285
|
return;
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
// Clean snapshot of the app markup, taken before the app's first run mutates it.
|
|
289
|
+
var pristineApp = appMain.cloneNode(true);
|
|
290
|
+
|
|
288
291
|
var kit = (config.kitOrigin || DEFAULT_KIT).replace(/\/$/, "");
|
|
289
292
|
activeKit = kit;
|
|
290
293
|
globalThis.__ATHENA_KIT_ORIGIN__ = kit;
|
|
@@ -299,8 +302,27 @@
|
|
|
299
302
|
var role = defaultRole(config);
|
|
300
303
|
setPreviewViewer(role);
|
|
301
304
|
|
|
305
|
+
var appSlotRef = null;
|
|
306
|
+
|
|
307
|
+
function runApp() {
|
|
308
|
+
if (typeof globalThis.__ATHENA_APP_RUN__ === "function") {
|
|
309
|
+
globalThis.__ATHENA_APP_RUN__();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Mirror production's "reload iframe at new devRole": swap in a fresh copy of
|
|
314
|
+
// the app and re-run it so role-gated UI re-evaluates. The fresh clone drops
|
|
315
|
+
// the prior run's listeners, so re-running is safe.
|
|
316
|
+
function onRoleChange(nextRole) {
|
|
317
|
+
setPreviewViewer(nextRole);
|
|
318
|
+
if (!appSlotRef) return;
|
|
319
|
+
appSlotRef.replaceChildren(pristineApp.cloneNode(true));
|
|
320
|
+
runApp();
|
|
321
|
+
}
|
|
322
|
+
|
|
302
323
|
var sections = syntheticNav(config);
|
|
303
|
-
var built = buildEmbedShell(config, role, sections);
|
|
324
|
+
var built = buildEmbedShell(config, role, sections, onRoleChange);
|
|
325
|
+
appSlotRef = built.appSlot;
|
|
304
326
|
built.appSlot.appendChild(appMain);
|
|
305
327
|
document.body.replaceChildren(built.shell);
|
|
306
328
|
}
|
package/package.json
CHANGED