@uniweb/runtime 1.1.13 → 1.1.14
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 +26 -11
- package/dist/ssr.js.map +1 -1
- package/package.json +4 -4
- package/src/area-wrappers.js +17 -0
- package/src/components/BlockRenderer.jsx +12 -5
- package/src/components/Blocks.jsx +2 -2
- package/src/components/Layout.jsx +13 -8
- package/src/components/PageRenderer.jsx +1 -1
- package/src/default-layout.js +6 -7
- package/src/ssr-renderer.js +15 -11
- package/src/sticky-check.js +44 -2
- package/src/sticky-top.js +100 -0
- package/src/sticky.js +53 -5
package/dist/ssr.js
CHANGED
|
@@ -291,6 +291,7 @@ function ensureThemeCss(uniweb, foundation) {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
const STICKY_TOP = "0px";
|
|
294
|
+
const STICKY_SECTION_TOP = "var(--uw-sticky-top, 0px)";
|
|
294
295
|
function stickyStyle(top, zIndex) {
|
|
295
296
|
const style = { position: "sticky", top: top || STICKY_TOP };
|
|
296
297
|
if (zIndex != null) style.zIndex = zIndex;
|
|
@@ -305,8 +306,15 @@ function layoutStickiness(areas) {
|
|
|
305
306
|
for (const [name, blocks] of Object.entries(areas || {})) sticky[name] = areaStickiness(blocks);
|
|
306
307
|
return sticky;
|
|
307
308
|
}
|
|
309
|
+
function zoneProps(stickiness, layer) {
|
|
310
|
+
return stickiness ? { style: stickyStyle(stickiness.top, layer), "data-uw-sticky": "area" } : null;
|
|
311
|
+
}
|
|
308
312
|
function sectionStickyStyle(block) {
|
|
309
|
-
return block?.sticky ? stickyStyle(block.stickyTop, 1) : null;
|
|
313
|
+
return block?.sticky ? { ...stickyStyle(block.stickyTop || STICKY_SECTION_TOP, 1), alignSelf: "start" } : null;
|
|
314
|
+
}
|
|
315
|
+
function sectionStickyProps(block, kind) {
|
|
316
|
+
const style = kind ? sectionStickyStyle(block) : null;
|
|
317
|
+
return style ? { style, "data-uw-sticky": kind === "child" ? "child" : "section" } : null;
|
|
310
318
|
}
|
|
311
319
|
const NS = "uw-";
|
|
312
320
|
const toIdent = (name) => NS + String(name).replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
@@ -342,16 +350,20 @@ function areaWrapperStyle(region, transitions, layers, sticky = null) {
|
|
|
342
350
|
}
|
|
343
351
|
return Object.keys(style).length > 0 ? style : null;
|
|
344
352
|
}
|
|
353
|
+
function areaWrapperProps(region, transitions, layers, sticky = null) {
|
|
354
|
+
const style = areaWrapperStyle(region, transitions, layers, sticky);
|
|
355
|
+
if (!style) return null;
|
|
356
|
+
return sticky ? { style, "data-uw-sticky": "area" } : { style };
|
|
357
|
+
}
|
|
345
358
|
const COLUMN = { display: "flex", flexDirection: "column", minHeight: "100vh" };
|
|
346
359
|
const GROW = { flex: 1 };
|
|
347
360
|
function DefaultLayout({ header, body, footer, zones }) {
|
|
348
|
-
const zone = (name) => zones?.[name] ? { style: zones[name] } : null;
|
|
349
361
|
return React.createElement(
|
|
350
362
|
"div",
|
|
351
363
|
{ style: COLUMN },
|
|
352
|
-
header && React.createElement("header",
|
|
364
|
+
header && React.createElement("header", zones?.header || null, header),
|
|
353
365
|
body && React.createElement("main", { style: GROW }, body),
|
|
354
|
-
footer && React.createElement("footer",
|
|
366
|
+
footer && React.createElement("footer", zones?.footer || null, footer)
|
|
355
367
|
);
|
|
356
368
|
}
|
|
357
369
|
function applyBootScheme(respectSystem, fallback) {
|
|
@@ -552,8 +564,11 @@ function renderBlock(block, { as = "section", stickySelf = false } = {}) {
|
|
|
552
564
|
return React.createElement(Component, componentProps);
|
|
553
565
|
}
|
|
554
566
|
const { background, ...wrapperProps } = getWrapperProps(block);
|
|
555
|
-
const sticky =
|
|
556
|
-
if (sticky)
|
|
567
|
+
const sticky = sectionStickyProps(block, stickySelf);
|
|
568
|
+
if (sticky) {
|
|
569
|
+
wrapperProps.style = { ...wrapperProps.style, ...sticky.style };
|
|
570
|
+
wrapperProps["data-uw-sticky"] = sticky["data-uw-sticky"];
|
|
571
|
+
}
|
|
557
572
|
const componentClassName = Component.className;
|
|
558
573
|
if (componentClassName) {
|
|
559
574
|
wrapperProps.className = wrapperProps.className ? `${wrapperProps.className} ${componentClassName}` : componentClassName;
|
|
@@ -603,10 +618,10 @@ function renderLayout(page, website) {
|
|
|
603
618
|
const sticky = layoutStickiness(areas);
|
|
604
619
|
const layers = resolveLayoutLayers(areaNames, layoutMeta?.layers, sticky);
|
|
605
620
|
const wrapArea = (name, element) => {
|
|
606
|
-
const
|
|
607
|
-
return
|
|
621
|
+
const props = areaWrapperProps(name, transitions, layers, RemoteLayout ? sticky[name] : null);
|
|
622
|
+
return props ? React.createElement("div", props, element) : element;
|
|
608
623
|
};
|
|
609
|
-
const bodyElement = bodyBlocks ? wrapArea("body", renderBlocks(bodyBlocks, { stickySelf:
|
|
624
|
+
const bodyElement = bodyBlocks ? wrapArea("body", renderBlocks(bodyBlocks, { stickySelf: "section" })) : null;
|
|
610
625
|
const areaElements = {};
|
|
611
626
|
for (const [name, blocks] of Object.entries(areas)) {
|
|
612
627
|
areaElements[name] = wrapArea(name, renderBlocks(blocks));
|
|
@@ -621,7 +636,7 @@ function renderLayout(page, website) {
|
|
|
621
636
|
...areaElements
|
|
622
637
|
});
|
|
623
638
|
}
|
|
624
|
-
const zone = (name) =>
|
|
639
|
+
const zone = (name) => zoneProps(sticky[name], layers?.[name]);
|
|
625
640
|
return React.createElement(DefaultLayout, {
|
|
626
641
|
body: bodyElement,
|
|
627
642
|
...areaElements,
|
|
@@ -659,7 +674,7 @@ function initPrerender(content, foundation, extensionsOrOptions, maybeOptions) {
|
|
|
659
674
|
(childBlock, index) => React.createElement(
|
|
660
675
|
React.Fragment,
|
|
661
676
|
{ key: childBlock.id || index },
|
|
662
|
-
renderBlock(childBlock, { as: wrapAs || null })
|
|
677
|
+
renderBlock(childBlock, { as: wrapAs || null, stickySelf: wrapAs ? "child" : false })
|
|
663
678
|
)
|
|
664
679
|
);
|
|
665
680
|
};
|