@uniweb/runtime 1.1.13 → 1.1.15
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 +35 -11
- package/dist/ssr.js.map +1 -1
- package/package.json +3 -3
- package/src/area-wrappers.js +17 -0
- package/src/components/BlockRenderer.jsx +15 -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 +18 -11
- package/src/sticky-check.js +44 -2
- package/src/sticky-top.js +100 -0
- package/src/sticky.js +81 -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,22 @@ 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 hasStickyArea(page) {
|
|
316
|
+
const areas = page?.getLayoutAreas?.() || {};
|
|
317
|
+
return Object.values(areas).some((blocks) => areaStickiness(blocks) !== null);
|
|
318
|
+
}
|
|
319
|
+
function sectionScrollMargin(block, kind) {
|
|
320
|
+
return kind && hasStickyArea(block?.page) ? { scrollMarginTop: STICKY_SECTION_TOP } : null;
|
|
321
|
+
}
|
|
322
|
+
function sectionStickyProps(block, kind) {
|
|
323
|
+
const style = kind ? sectionStickyStyle(block) : null;
|
|
324
|
+
return style ? { style, "data-uw-sticky": kind === "child" ? "child" : "section" } : null;
|
|
310
325
|
}
|
|
311
326
|
const NS = "uw-";
|
|
312
327
|
const toIdent = (name) => NS + String(name).replace(/[^a-zA-Z0-9_-]/g, "-");
|
|
@@ -342,16 +357,20 @@ function areaWrapperStyle(region, transitions, layers, sticky = null) {
|
|
|
342
357
|
}
|
|
343
358
|
return Object.keys(style).length > 0 ? style : null;
|
|
344
359
|
}
|
|
360
|
+
function areaWrapperProps(region, transitions, layers, sticky = null) {
|
|
361
|
+
const style = areaWrapperStyle(region, transitions, layers, sticky);
|
|
362
|
+
if (!style) return null;
|
|
363
|
+
return sticky ? { style, "data-uw-sticky": "area" } : { style };
|
|
364
|
+
}
|
|
345
365
|
const COLUMN = { display: "flex", flexDirection: "column", minHeight: "100vh" };
|
|
346
366
|
const GROW = { flex: 1 };
|
|
347
367
|
function DefaultLayout({ header, body, footer, zones }) {
|
|
348
|
-
const zone = (name) => zones?.[name] ? { style: zones[name] } : null;
|
|
349
368
|
return React.createElement(
|
|
350
369
|
"div",
|
|
351
370
|
{ style: COLUMN },
|
|
352
|
-
header && React.createElement("header",
|
|
371
|
+
header && React.createElement("header", zones?.header || null, header),
|
|
353
372
|
body && React.createElement("main", { style: GROW }, body),
|
|
354
|
-
footer && React.createElement("footer",
|
|
373
|
+
footer && React.createElement("footer", zones?.footer || null, footer)
|
|
355
374
|
);
|
|
356
375
|
}
|
|
357
376
|
function applyBootScheme(respectSystem, fallback) {
|
|
@@ -552,8 +571,13 @@ function renderBlock(block, { as = "section", stickySelf = false } = {}) {
|
|
|
552
571
|
return React.createElement(Component, componentProps);
|
|
553
572
|
}
|
|
554
573
|
const { background, ...wrapperProps } = getWrapperProps(block);
|
|
555
|
-
const sticky =
|
|
556
|
-
if (sticky)
|
|
574
|
+
const sticky = sectionStickyProps(block, stickySelf);
|
|
575
|
+
if (sticky) {
|
|
576
|
+
wrapperProps.style = { ...wrapperProps.style, ...sticky.style };
|
|
577
|
+
wrapperProps["data-uw-sticky"] = sticky["data-uw-sticky"];
|
|
578
|
+
}
|
|
579
|
+
const margin = sectionScrollMargin(block, stickySelf);
|
|
580
|
+
if (margin) wrapperProps.style = { ...wrapperProps.style, ...margin };
|
|
557
581
|
const componentClassName = Component.className;
|
|
558
582
|
if (componentClassName) {
|
|
559
583
|
wrapperProps.className = wrapperProps.className ? `${wrapperProps.className} ${componentClassName}` : componentClassName;
|
|
@@ -603,10 +627,10 @@ function renderLayout(page, website) {
|
|
|
603
627
|
const sticky = layoutStickiness(areas);
|
|
604
628
|
const layers = resolveLayoutLayers(areaNames, layoutMeta?.layers, sticky);
|
|
605
629
|
const wrapArea = (name, element) => {
|
|
606
|
-
const
|
|
607
|
-
return
|
|
630
|
+
const props = areaWrapperProps(name, transitions, layers, RemoteLayout ? sticky[name] : null);
|
|
631
|
+
return props ? React.createElement("div", props, element) : element;
|
|
608
632
|
};
|
|
609
|
-
const bodyElement = bodyBlocks ? wrapArea("body", renderBlocks(bodyBlocks, { stickySelf:
|
|
633
|
+
const bodyElement = bodyBlocks ? wrapArea("body", renderBlocks(bodyBlocks, { stickySelf: "section" })) : null;
|
|
610
634
|
const areaElements = {};
|
|
611
635
|
for (const [name, blocks] of Object.entries(areas)) {
|
|
612
636
|
areaElements[name] = wrapArea(name, renderBlocks(blocks));
|
|
@@ -621,7 +645,7 @@ function renderLayout(page, website) {
|
|
|
621
645
|
...areaElements
|
|
622
646
|
});
|
|
623
647
|
}
|
|
624
|
-
const zone = (name) =>
|
|
648
|
+
const zone = (name) => zoneProps(sticky[name], layers?.[name]);
|
|
625
649
|
return React.createElement(DefaultLayout, {
|
|
626
650
|
body: bodyElement,
|
|
627
651
|
...areaElements,
|
|
@@ -659,7 +683,7 @@ function initPrerender(content, foundation, extensionsOrOptions, maybeOptions) {
|
|
|
659
683
|
(childBlock, index) => React.createElement(
|
|
660
684
|
React.Fragment,
|
|
661
685
|
{ key: childBlock.id || index },
|
|
662
|
-
renderBlock(childBlock, { as: wrapAs || null })
|
|
686
|
+
renderBlock(childBlock, { as: wrapAs || null, stickySelf: wrapAs ? "child" : false })
|
|
663
687
|
)
|
|
664
688
|
);
|
|
665
689
|
};
|