@uniweb/runtime 1.4.6 → 1.5.1
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/dist/ssr.js +37 -13
- package/dist/ssr.js.map +1 -1
- package/package.json +4 -4
- package/src/components/BlockRenderer.jsx +14 -0
- package/src/components/Layout.jsx +8 -2
- package/src/components/PageRenderer.jsx +9 -3
- package/src/page-renderer.js +5 -10
- package/src/ssr-renderer.js +25 -16
- package/src/sticky-check.js +36 -0
- package/src/sticky-top.js +48 -5
- package/src/under-header.js +85 -0
- package/src/start-page.js +0 -26
package/dist/ssr.js
CHANGED
|
@@ -436,6 +436,31 @@ function areaWrapperProps(region, transitions, layers, sticky = null) {
|
|
|
436
436
|
if (!style) return null;
|
|
437
437
|
return sticky ? { style, "data-uw-sticky": "area" } : { style };
|
|
438
438
|
}
|
|
439
|
+
const HEADER_HEIGHT = "--uw-header-height";
|
|
440
|
+
const MEASURED_HEADER_HEIGHT = "--uw-header-measured";
|
|
441
|
+
function headerOverlay(page) {
|
|
442
|
+
const first = page?.getBodyBlocks?.()?.[0];
|
|
443
|
+
if (!first?.underHeader) return null;
|
|
444
|
+
const header = page.getLayoutAreas?.()?.header;
|
|
445
|
+
if (!Array.isArray(header) || header.length === 0) return null;
|
|
446
|
+
const heights = header.map((block) => block?.height).filter(Boolean);
|
|
447
|
+
const height = heights.length === 0 ? "0px" : heights.length === 1 ? heights[0] : `calc(${heights.join(" + ")})`;
|
|
448
|
+
return { height };
|
|
449
|
+
}
|
|
450
|
+
function overlayBoxProps(props) {
|
|
451
|
+
return { ...props || {}, style: { ...props?.style || {}, height: 0, minHeight: 0 }, "data-uw-header": "over" };
|
|
452
|
+
}
|
|
453
|
+
function underHeaderProps(overlay) {
|
|
454
|
+
return {
|
|
455
|
+
style: { [HEADER_HEIGHT]: `var(${MEASURED_HEADER_HEIGHT}, ${overlay.height})` },
|
|
456
|
+
"data-uw-under-header": ""
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
function openingUnderHeader(block) {
|
|
460
|
+
const page = block?.page;
|
|
461
|
+
if (!page || page.getBodyBlocks?.()?.[0] !== block) return null;
|
|
462
|
+
return headerOverlay(page);
|
|
463
|
+
}
|
|
439
464
|
const COLUMN = { display: "flex", flexDirection: "column", minHeight: "100vh" };
|
|
440
465
|
const GROW = { flex: 1 };
|
|
441
466
|
function DefaultLayout({ header, body, footer, zones }) {
|
|
@@ -492,13 +517,6 @@ function documentTitle(pageTitle, siteName) {
|
|
|
492
517
|
const title = String(pageTitle);
|
|
493
518
|
return siteName ? `${title} | ${siteName}` : title;
|
|
494
519
|
}
|
|
495
|
-
const startPages = /* @__PURE__ */ new WeakMap();
|
|
496
|
-
function recordStartPage(website) {
|
|
497
|
-
if (website && !startPages.has(website)) startPages.set(website, website.activePage);
|
|
498
|
-
}
|
|
499
|
-
function restoreStartPage(website) {
|
|
500
|
-
if (startPages.has(website)) website.activePage = startPages.get(website);
|
|
501
|
-
}
|
|
502
520
|
function resolvePage(website, route) {
|
|
503
521
|
return website.getPage(route);
|
|
504
522
|
}
|
|
@@ -567,12 +585,19 @@ function renderBlock(block, { as = "section", stickySelf = false } = {}) {
|
|
|
567
585
|
}
|
|
568
586
|
const margin = sectionScrollMargin(block, stickySelf);
|
|
569
587
|
if (margin) wrapperProps.style = { ...wrapperProps.style, ...margin };
|
|
588
|
+
const overlay = stickySelf === "section" || stickySelf === true ? openingUnderHeader(block) : null;
|
|
589
|
+
if (overlay) {
|
|
590
|
+
const under = underHeaderProps(overlay);
|
|
591
|
+
wrapperProps.style = { ...wrapperProps.style, ...under.style };
|
|
592
|
+
wrapperProps["data-uw-under-header"] = under["data-uw-under-header"];
|
|
593
|
+
}
|
|
570
594
|
const componentClassName = Component.className;
|
|
571
595
|
if (componentClassName) {
|
|
572
596
|
wrapperProps.className = wrapperProps.className ? `${wrapperProps.className} ${componentClassName}` : componentClassName;
|
|
573
597
|
}
|
|
574
598
|
const hasBackground = background?.mode && meta?.background !== "self";
|
|
575
599
|
block.hasBackground = hasBackground;
|
|
600
|
+
if (meta?.background === "self") wrapperProps["data-uw-background"] = "self";
|
|
576
601
|
const wrapperTag = as !== "section" ? as : Component.as || "section";
|
|
577
602
|
if (hasBackground) {
|
|
578
603
|
return React.createElement(
|
|
@@ -615,8 +640,10 @@ function renderLayout(page, website) {
|
|
|
615
640
|
const transitions = website.viewTransitions ? resolveLayoutTransitions(layoutMeta?.transitions) : null;
|
|
616
641
|
const sticky = layoutStickiness(areas);
|
|
617
642
|
const layers = resolveLayoutLayers(areaNames, layoutMeta?.layers, sticky);
|
|
643
|
+
const overlay = headerOverlay(page);
|
|
618
644
|
const wrapArea = (name, element) => {
|
|
619
|
-
|
|
645
|
+
let props = areaWrapperProps(name, transitions, layers, RemoteLayout ? sticky[name] : null);
|
|
646
|
+
if (overlay && RemoteLayout && name === "header") props = overlayBoxProps(props);
|
|
620
647
|
return props ? React.createElement("div", props, element) : element;
|
|
621
648
|
};
|
|
622
649
|
const bodyElement = bodyBlocks ? wrapArea("body", renderBlocks(bodyBlocks, { stickySelf: "section" })) : null;
|
|
@@ -638,7 +665,7 @@ function renderLayout(page, website) {
|
|
|
638
665
|
return React.createElement(DefaultLayout, {
|
|
639
666
|
body: bodyElement,
|
|
640
667
|
...areaElements,
|
|
641
|
-
zones: { header: zone("header"), footer: zone("footer") }
|
|
668
|
+
zones: { header: overlay ? overlayBoxProps(zone("header")) : zone("header"), footer: zone("footer") }
|
|
642
669
|
});
|
|
643
670
|
}
|
|
644
671
|
function initPrerenderForLocale(content, foundation, locale, extensionsOrOptions, maybeOptions) {
|
|
@@ -663,7 +690,6 @@ function initPrerender(content, foundation, extensionsOrOptions, maybeOptions) {
|
|
|
663
690
|
} } = options;
|
|
664
691
|
onProgress("Initializing runtime...");
|
|
665
692
|
const uniweb = createUniweb(content, foundation, extensions);
|
|
666
|
-
recordStartPage(uniweb.activeWebsite);
|
|
667
693
|
if (content.config?.base && uniweb.activeWebsite?.setBasePath) {
|
|
668
694
|
uniweb.activeWebsite.setBasePath(content.config.base);
|
|
669
695
|
}
|
|
@@ -744,7 +770,7 @@ function classifyRenderError(err) {
|
|
|
744
770
|
};
|
|
745
771
|
}
|
|
746
772
|
function renderPage(page, website) {
|
|
747
|
-
|
|
773
|
+
website.setActivePage(page);
|
|
748
774
|
if (page.hasContent?.() && page.getBodyBlocks().length === 0) {
|
|
749
775
|
return {
|
|
750
776
|
error: {
|
|
@@ -1395,8 +1421,6 @@ function createPageRenderer({ website, shell }) {
|
|
|
1395
1421
|
if (!resolved) return { outcome: "notFound", html: null, page: null, error: null };
|
|
1396
1422
|
const page = typeof resolved.getRenderableSelf === "function" ? resolved.getRenderableSelf() : resolved;
|
|
1397
1423
|
const missing = !named || page?.notFound === true;
|
|
1398
|
-
restoreStartPage(website);
|
|
1399
|
-
if (typeof target === "string") website.setActivePage(target);
|
|
1400
1424
|
const icons = /* @__PURE__ */ new Map();
|
|
1401
1425
|
let result;
|
|
1402
1426
|
try {
|