@uniweb/runtime 1.5.5 → 1.5.6
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 +41 -13
- package/dist/ssr.js.map +1 -1
- package/package.json +3 -3
- package/src/page-renderer.js +12 -6
- package/src/section-records.js +56 -16
package/dist/ssr.js
CHANGED
|
@@ -16,7 +16,7 @@ import { dataScript, jsonForScript as jsonForScript2 } from "@uniweb/core/data-s
|
|
|
16
16
|
import DataStore, { deriveCacheKey as deriveCacheKey$1 } from "@uniweb/core/datastore";
|
|
17
17
|
import { RESOLUTION_STATUS, carryQuery, localeOfPath, localeUrl, resolveRoute, routeIndex } from "@uniweb/core/resolve-route";
|
|
18
18
|
import { declaredKeys } from "@uniweb/core/data-keys";
|
|
19
|
-
import { blockRouteQuery, blockFillsOf, fillIsPageRecord } from "@uniweb/core/page-data";
|
|
19
|
+
import { heldPageRecord, blockRouteQuery, blockFillsOf, fillIsPageRecord } from "@uniweb/core/page-data";
|
|
20
20
|
import { resolveFetchConfigs } from "@uniweb/core/fetch-config";
|
|
21
21
|
import { resolveRecordsService } from "@uniweb/core/records-service";
|
|
22
22
|
function guaranteeItemStructure(item) {
|
|
@@ -1430,18 +1430,37 @@ async function loadPageData({ website, route, fetch: fetch2, dev = false, locale
|
|
|
1430
1430
|
return [...entries.values()];
|
|
1431
1431
|
}
|
|
1432
1432
|
function sectionRecords(page) {
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1435
|
-
|
|
1433
|
+
const sections = [];
|
|
1434
|
+
const shown = [];
|
|
1435
|
+
for (const block of page?.getBodyBlocks?.() ?? []) visit(block, sectionDomId(block), sections, shown);
|
|
1436
|
+
return { sections, record: pageRecordOf(page, shown) };
|
|
1436
1437
|
}
|
|
1437
|
-
function visit(block, id,
|
|
1438
|
+
function visit(block, id, sections, shown) {
|
|
1438
1439
|
if (!block) return;
|
|
1439
|
-
const data = recordsOf(block);
|
|
1440
|
-
if (data)
|
|
1441
|
-
for (const inset of block.insets || []) visit(inset, id,
|
|
1442
|
-
for (const child of block.childBlocks || []) visit(child, sectionDomId(child),
|
|
1440
|
+
const data = recordsOf(block, shown);
|
|
1441
|
+
if (data) sections.push({ id, data });
|
|
1442
|
+
for (const inset of block.insets || []) visit(inset, id, sections, shown);
|
|
1443
|
+
for (const child of block.childBlocks || []) visit(child, sectionDomId(child), sections, shown);
|
|
1444
|
+
}
|
|
1445
|
+
function pageRecordOf(page, shown) {
|
|
1446
|
+
if (!page?.dynamicContext) return void 0;
|
|
1447
|
+
const one = (value) => Array.isArray(value) ? value[0] ?? null : value;
|
|
1448
|
+
const whole = shown.find((s) => s.whole && one(s.value));
|
|
1449
|
+
if (whole) return one(whole.value);
|
|
1450
|
+
const website = page.website;
|
|
1451
|
+
const fetcher = website?.fetcher;
|
|
1452
|
+
const own = heldPageRecord(page, {
|
|
1453
|
+
website,
|
|
1454
|
+
peek: (request) => fetcher?.peek?.(request, { website, page, block: null }),
|
|
1455
|
+
peekRecord: (id2) => fetcher?.peekRecord?.(id2)
|
|
1456
|
+
});
|
|
1457
|
+
const seen = shown.map((s) => one(s.value)).find(Boolean) ?? null;
|
|
1458
|
+
const id = (own ?? seen)?.$uuid;
|
|
1459
|
+
const held = typeof id === "string" && id ? fetcher?.peekRecord?.(id) : null;
|
|
1460
|
+
if (held?.whole === true && held.record) return held.record;
|
|
1461
|
+
return seen ?? own;
|
|
1443
1462
|
}
|
|
1444
|
-
function recordsOf(block) {
|
|
1463
|
+
function recordsOf(block, shown) {
|
|
1445
1464
|
if (!globalThis.uniweb?.getComponent?.(block.type)) return null;
|
|
1446
1465
|
const meta = getComponentMeta(block.type);
|
|
1447
1466
|
const own = declaredKeys(meta?.data);
|
|
@@ -1466,8 +1485,13 @@ function recordsOf(block) {
|
|
|
1466
1485
|
route = blockRouteQuery(block);
|
|
1467
1486
|
fills = blockFillsOf(block, meta, route);
|
|
1468
1487
|
}
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1488
|
+
const fill = fills.get(key);
|
|
1489
|
+
const cfg = fill?.cfg;
|
|
1490
|
+
if (!cfg?.as) continue;
|
|
1491
|
+
if (fillIsPageRecord(block, cfg, route)) {
|
|
1492
|
+
shown.push({ value, whole: fill.whole === true });
|
|
1493
|
+
continue;
|
|
1494
|
+
}
|
|
1471
1495
|
name = cfg.as;
|
|
1472
1496
|
}
|
|
1473
1497
|
if (Object.hasOwn(out, name) && !sameValue(out[name], value)) name = key;
|
|
@@ -1519,7 +1543,11 @@ function createPageRenderer({ website, shell }) {
|
|
|
1519
1543
|
icons
|
|
1520
1544
|
});
|
|
1521
1545
|
const rendered = { outcome: missing ? "notFound" : "rendered", html, page, error: null };
|
|
1522
|
-
if (sectionData)
|
|
1546
|
+
if (sectionData) {
|
|
1547
|
+
const shown = sectionRecords(page);
|
|
1548
|
+
rendered.sections = shown.sections;
|
|
1549
|
+
if (shown.record !== void 0) rendered.record = shown.record;
|
|
1550
|
+
}
|
|
1523
1551
|
return rendered;
|
|
1524
1552
|
}
|
|
1525
1553
|
return { website, render, failingSection: (page, message) => failingSectionOf(page, message) };
|