@selfhelp/shared 1.20.0 → 1.21.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/CHANGELOG.md +23 -0
- package/dist/index.d.mts +168 -108
- package/dist/index.d.ts +168 -108
- package/dist/index.js +476 -107
- package/dist/index.mjs +444 -92
- package/package.json +1 -1
- package/src/api/endpoints.ts +8 -0
- package/src/navigation/__tests__/navigation.test.ts +217 -68
- package/src/navigation/__tests__/startup.test.ts +33 -0
- package/src/navigation/branchNav.ts +261 -0
- package/src/navigation/headerPreset.ts +52 -0
- package/src/navigation/index.ts +9 -7
- package/src/navigation/menuMembership.ts +89 -0
- package/src/navigation/menuSearch.ts +69 -0
- package/src/navigation/menuVisibility.ts +24 -25
- package/src/navigation/mobileRoute.ts +20 -0
- package/src/navigation/navLinks.ts +38 -0
- package/src/navigation/navigationPayload.ts +84 -0
- package/src/navigation/startup.ts +87 -0
- package/src/types/api/__tests__/page-routing.test.ts +0 -6
- package/src/types/pages.ts +0 -13
- package/src/utils/__tests__/transformPageData.test.ts +3 -19
- package/src/utils/transformPageData.ts +1 -37
- package/src/navigation/navRender.ts +0 -132
package/dist/index.mjs
CHANGED
|
@@ -399,6 +399,14 @@ var ENDPOINTS = {
|
|
|
399
399
|
*/
|
|
400
400
|
RESOLVE: (path) => `${API_VERSION_PREFIX}/pages/resolve?path=${encodeURIComponent(path)}`
|
|
401
401
|
},
|
|
402
|
+
NAVIGATION: {
|
|
403
|
+
GET: `${API_VERSION_PREFIX}/navigation`,
|
|
404
|
+
LAST_VISITED: `${API_VERSION_PREFIX}/navigation/last-visited`
|
|
405
|
+
},
|
|
406
|
+
SEARCH: {
|
|
407
|
+
CONTENT: `${API_VERSION_PREFIX}/search`,
|
|
408
|
+
PAGES: `${API_VERSION_PREFIX}/search/pages`
|
|
409
|
+
},
|
|
402
410
|
LANGUAGES: `${API_VERSION_PREFIX}/languages`,
|
|
403
411
|
FORMS: {
|
|
404
412
|
SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
|
|
@@ -1397,78 +1405,327 @@ function stripHtmlToText(value) {
|
|
|
1397
1405
|
return out.replace(/\s+/g, " ").trim();
|
|
1398
1406
|
}
|
|
1399
1407
|
|
|
1400
|
-
// src/navigation/
|
|
1401
|
-
var
|
|
1402
|
-
"
|
|
1408
|
+
// src/navigation/headerPreset.ts
|
|
1409
|
+
var WEB_HEADER_PRESET_VALUES = [
|
|
1410
|
+
"simple",
|
|
1411
|
+
"dropdown",
|
|
1412
|
+
"mega-menu",
|
|
1403
1413
|
"tabs",
|
|
1404
|
-
"
|
|
1405
|
-
"
|
|
1414
|
+
"double-dropdown",
|
|
1415
|
+
"double-mega-menu"
|
|
1406
1416
|
];
|
|
1407
|
-
var
|
|
1408
|
-
|
|
1409
|
-
"
|
|
1410
|
-
"
|
|
1411
|
-
"
|
|
1417
|
+
var DEFAULT_WEB_HEADER_PRESET = "dropdown";
|
|
1418
|
+
var WEB_HEADER_PRESET_OPTIONS = [
|
|
1419
|
+
{ value: "simple", label: "Simple", description: "Flat header links for small sites." },
|
|
1420
|
+
{ value: "dropdown", label: "Dropdown", description: "Default \u2014 nested dropdown menus." },
|
|
1421
|
+
{ value: "mega-menu", label: "Mega menu", description: "Rich sections with descriptions and icons." },
|
|
1422
|
+
{ value: "tabs", label: "Tabs", description: "Top-level sections as tabs." },
|
|
1423
|
+
{ value: "double-dropdown", label: "Double header (dropdown)", description: "Utility row plus main dropdown nav." },
|
|
1424
|
+
{ value: "double-mega-menu", label: "Double header (mega menu)", description: "Utility row plus mega menu." }
|
|
1412
1425
|
];
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
{
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
{
|
|
1429
|
-
value: "sidebar-drawer",
|
|
1430
|
-
label: "Sidebar drawer",
|
|
1431
|
-
description: "Side drawer / hamburger menu. Best for large or deep navigation."
|
|
1432
|
-
},
|
|
1433
|
-
{
|
|
1434
|
-
value: "hero-cards",
|
|
1435
|
-
label: "Hero cards",
|
|
1436
|
-
description: "Dashboard-style card grid. Best for landing pages and CMS app dashboards."
|
|
1426
|
+
function isWebHeaderPreset(value) {
|
|
1427
|
+
return typeof value === "string" && WEB_HEADER_PRESET_VALUES.includes(value);
|
|
1428
|
+
}
|
|
1429
|
+
function resolveWebHeaderPreset(value, fallback = DEFAULT_WEB_HEADER_PRESET) {
|
|
1430
|
+
return isWebHeaderPreset(value) ? value : fallback;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
// src/navigation/menuMembership.ts
|
|
1434
|
+
function flattenItems(items) {
|
|
1435
|
+
const out = [];
|
|
1436
|
+
for (const item of items) {
|
|
1437
|
+
out.push(item);
|
|
1438
|
+
if (item.children?.length) {
|
|
1439
|
+
out.push(...flattenItems(item.children));
|
|
1440
|
+
}
|
|
1437
1441
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
value: "bottom-tabs",
|
|
1447
|
-
label: "Bottom tabs",
|
|
1448
|
-
description: "Bottom tab bar for 3\u20135 main app-like destinations."
|
|
1449
|
-
},
|
|
1450
|
-
{
|
|
1451
|
-
value: "drawer",
|
|
1452
|
-
label: "Drawer",
|
|
1453
|
-
description: "Hamburger / side drawer for larger navigation."
|
|
1454
|
-
},
|
|
1455
|
-
{
|
|
1456
|
-
value: "hero-cards",
|
|
1457
|
-
label: "Hero cards",
|
|
1458
|
-
description: "Card grid for dashboards and CMS app pages."
|
|
1442
|
+
return out;
|
|
1443
|
+
}
|
|
1444
|
+
function collectPageIdsFromMenuItems(items) {
|
|
1445
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1446
|
+
for (const item of flattenItems(items)) {
|
|
1447
|
+
if (item.page?.id != null) {
|
|
1448
|
+
ids.add(item.page.id);
|
|
1449
|
+
}
|
|
1459
1450
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1451
|
+
return ids;
|
|
1452
|
+
}
|
|
1453
|
+
function isPageInMenuTree(items, pageId) {
|
|
1454
|
+
return collectPageIdsFromMenuItems(items).has(pageId);
|
|
1455
|
+
}
|
|
1456
|
+
function isPageInResolvedMenus(menus, menuKeys, pageId) {
|
|
1457
|
+
for (const key of menuKeys) {
|
|
1458
|
+
const menu = menus[key];
|
|
1459
|
+
if (menu && isPageInMenuTree(menu.items, pageId)) {
|
|
1460
|
+
return true;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
function isOnAnyMobileMenu(menus, pageId) {
|
|
1466
|
+
return isPageInResolvedMenus(menus, ["mobile_drawer", "mobile_bottom_tabs"], pageId);
|
|
1467
|
+
}
|
|
1468
|
+
function findMenuItemByPageId(items, pageId) {
|
|
1469
|
+
for (const item of flattenItems(items)) {
|
|
1470
|
+
if (item.page?.id === pageId) {
|
|
1471
|
+
return item;
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
return null;
|
|
1475
|
+
}
|
|
1476
|
+
function findPageRefInNavigationPayload(payload, pageId) {
|
|
1477
|
+
const menuKeys = [
|
|
1478
|
+
"web_header",
|
|
1479
|
+
"web_footer",
|
|
1480
|
+
"mobile_drawer",
|
|
1481
|
+
"mobile_bottom_tabs"
|
|
1482
|
+
];
|
|
1483
|
+
for (const key of menuKeys) {
|
|
1484
|
+
const menu = payload.menus[key];
|
|
1485
|
+
if (!menu?.items?.length) {
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
const item = findMenuItemByPageId(menu.items, pageId);
|
|
1489
|
+
if (item?.page) {
|
|
1490
|
+
return item.page;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
// src/navigation/mobileRoute.ts
|
|
1497
|
+
function pageUrlToMobileRoute(url, keyword) {
|
|
1498
|
+
const normalizedKeyword = keyword.trim().toLowerCase();
|
|
1499
|
+
if (normalizedKeyword === "profile") {
|
|
1500
|
+
return "/profile";
|
|
1501
|
+
}
|
|
1502
|
+
if (normalizedKeyword === "home" || url === "/" || url === "" || url == null) {
|
|
1503
|
+
return "/index";
|
|
1504
|
+
}
|
|
1505
|
+
return `/${normalizedKeyword}`;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// src/navigation/branchNav.ts
|
|
1509
|
+
function itemLabel(item) {
|
|
1510
|
+
return item.label || item.page?.title || item.page?.keyword || "";
|
|
1511
|
+
}
|
|
1512
|
+
function toSegment(item) {
|
|
1513
|
+
if (!item.page) {
|
|
1514
|
+
return null;
|
|
1515
|
+
}
|
|
1516
|
+
return {
|
|
1517
|
+
pageId: item.page.id,
|
|
1518
|
+
keyword: item.page.keyword,
|
|
1519
|
+
url: item.page.url,
|
|
1520
|
+
label: itemLabel(item),
|
|
1521
|
+
icon: item.icon ?? item.page.icon,
|
|
1522
|
+
mobile_icon: item.page.mobile_icon
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
function findParentItem(items, pageId, parent = null) {
|
|
1526
|
+
for (const item of items) {
|
|
1527
|
+
if (item.page?.id === pageId) {
|
|
1528
|
+
return { parent, siblings: items };
|
|
1529
|
+
}
|
|
1530
|
+
if (item.children?.length) {
|
|
1531
|
+
const found = findParentItem(item.children, pageId, item);
|
|
1532
|
+
if (found) {
|
|
1533
|
+
return found;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return null;
|
|
1538
|
+
}
|
|
1539
|
+
function menuVisibleChildItems(item) {
|
|
1540
|
+
return (item.children ?? []).filter((child) => child.page != null && child.is_active !== false);
|
|
1541
|
+
}
|
|
1542
|
+
function findMenuItemByPageId2(items, pageId) {
|
|
1543
|
+
for (const item of items) {
|
|
1544
|
+
if (item.page?.id === pageId) {
|
|
1545
|
+
return item;
|
|
1546
|
+
}
|
|
1547
|
+
if (item.children?.length) {
|
|
1548
|
+
const nested = findMenuItemByPageId2(item.children, pageId);
|
|
1549
|
+
if (nested) {
|
|
1550
|
+
return nested;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
return null;
|
|
1555
|
+
}
|
|
1556
|
+
function selfSegment(item) {
|
|
1557
|
+
return toSegment(item);
|
|
1558
|
+
}
|
|
1559
|
+
function resolveBranchNavGroup(payload, currentPageId, menuKeys) {
|
|
1560
|
+
const allItems = [];
|
|
1561
|
+
for (const key of menuKeys) {
|
|
1562
|
+
const menu = payload.menus[key];
|
|
1563
|
+
if (menu?.items) {
|
|
1564
|
+
allItems.push(...menu.items);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
for (const root of allItems) {
|
|
1568
|
+
const selfChildren = menuVisibleChildItems(root);
|
|
1569
|
+
if (root.page?.id === currentPageId && selfChildren.length > 0) {
|
|
1570
|
+
const segments = selfChildren.map(toSegment).filter((s) => s != null);
|
|
1571
|
+
return segments.length > 0 ? segments : null;
|
|
1572
|
+
}
|
|
1573
|
+
const located = findParentItem([root], currentPageId);
|
|
1574
|
+
if (located) {
|
|
1575
|
+
const directChildren = menuVisibleChildItems(
|
|
1576
|
+
located.parent ?? { id: 0, item_type: "group", label: "", position: 0, children: located.siblings }
|
|
1577
|
+
);
|
|
1578
|
+
if (located.parent && located.parent.page?.id === currentPageId && directChildren.length > 0) {
|
|
1579
|
+
const segments = directChildren.map(toSegment).filter((s) => s != null);
|
|
1580
|
+
return segments.length > 0 ? segments : null;
|
|
1581
|
+
}
|
|
1582
|
+
const siblings = located.siblings.filter((s) => s.page != null && s.is_active !== false);
|
|
1583
|
+
if (siblings.length > 1) {
|
|
1584
|
+
const segments = siblings.map(toSegment).filter((s) => s != null);
|
|
1585
|
+
return segments.length > 0 ? segments : null;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
return null;
|
|
1590
|
+
}
|
|
1591
|
+
function resolveMobileSegmentGroup(payload, currentPageId) {
|
|
1592
|
+
const allItems = [];
|
|
1593
|
+
for (const key of ["mobile_drawer", "mobile_bottom_tabs"]) {
|
|
1594
|
+
const menu = payload.menus[key];
|
|
1595
|
+
if (menu?.items) {
|
|
1596
|
+
allItems.push(...menu.items);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
const currentItem = findMenuItemByPageId2(allItems, currentPageId);
|
|
1600
|
+
if (currentItem) {
|
|
1601
|
+
const selfChildren = menuVisibleChildItems(currentItem);
|
|
1602
|
+
if (selfChildren.length > 0) {
|
|
1603
|
+
const childSegments = selfChildren.map(toSegment).filter((segment) => segment != null);
|
|
1604
|
+
if (childSegments.length > 0) {
|
|
1605
|
+
if (currentItem.page?.has_content) {
|
|
1606
|
+
const self = selfSegment(currentItem);
|
|
1607
|
+
return self ? [self, ...childSegments] : childSegments;
|
|
1608
|
+
}
|
|
1609
|
+
return childSegments;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
return resolveBranchNavGroup(payload, currentPageId, ["mobile_drawer", "mobile_bottom_tabs"]);
|
|
1614
|
+
}
|
|
1615
|
+
function resolveWebBranchNavGroup(payload, currentPageId) {
|
|
1616
|
+
return resolveBranchNavGroup(payload, currentPageId, ["web_header", "web_footer"]);
|
|
1463
1617
|
}
|
|
1464
|
-
function
|
|
1465
|
-
return
|
|
1618
|
+
function resolveMobilePagePresentation(payload, pageId) {
|
|
1619
|
+
return isOnAnyMobileMenuFromPayload(payload, pageId) ? "route" : "modal";
|
|
1466
1620
|
}
|
|
1467
|
-
function
|
|
1468
|
-
|
|
1621
|
+
function isOnAnyMobileMenuFromPayload(payload, pageId) {
|
|
1622
|
+
const drawerIds = collectPageIdsFromMenuItems(payload.menus.mobile_drawer?.items ?? []);
|
|
1623
|
+
const tabIds = collectPageIdsFromMenuItems(payload.menus.mobile_bottom_tabs?.items ?? []);
|
|
1624
|
+
return drawerIds.has(pageId) || tabIds.has(pageId);
|
|
1469
1625
|
}
|
|
1470
|
-
function
|
|
1471
|
-
|
|
1626
|
+
function resolveHolderRedirectPath(payload, currentPageId, platform, hasContent) {
|
|
1627
|
+
if (hasContent) {
|
|
1628
|
+
return null;
|
|
1629
|
+
}
|
|
1630
|
+
const segments = platform === "mobile" ? resolveMobileSegmentGroup(payload, currentPageId) : resolveWebBranchNavGroup(payload, currentPageId);
|
|
1631
|
+
if (!segments || segments.length === 0) {
|
|
1632
|
+
return null;
|
|
1633
|
+
}
|
|
1634
|
+
const target = segments.find((segment) => segment.pageId !== currentPageId) ?? segments[0];
|
|
1635
|
+
if (target.pageId === currentPageId) {
|
|
1636
|
+
return null;
|
|
1637
|
+
}
|
|
1638
|
+
if (platform === "mobile") {
|
|
1639
|
+
return pageUrlToMobileRoute(target.url, target.keyword);
|
|
1640
|
+
}
|
|
1641
|
+
if (target.url && target.url !== "") {
|
|
1642
|
+
return target.url.startsWith("/") ? target.url : `/${target.url}`;
|
|
1643
|
+
}
|
|
1644
|
+
return target.keyword === "home" ? "/" : `/${target.keyword}`;
|
|
1645
|
+
}
|
|
1646
|
+
function findNearestBottomTabMenuItemForPage(tabs, pageId) {
|
|
1647
|
+
for (const tab of tabs) {
|
|
1648
|
+
if (tab.page?.id === pageId) {
|
|
1649
|
+
return tab;
|
|
1650
|
+
}
|
|
1651
|
+
if (findMenuItemByPageId2(tab.children ?? [], pageId)) {
|
|
1652
|
+
return tab;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return null;
|
|
1656
|
+
}
|
|
1657
|
+
function navigationPathMatches(item, pathname) {
|
|
1658
|
+
const href = pageUrlToMobileRoute(item.page?.url ?? null, item.page?.keyword ?? "");
|
|
1659
|
+
if (pathname === href) {
|
|
1660
|
+
return true;
|
|
1661
|
+
}
|
|
1662
|
+
if (href !== "/" && pathname.startsWith(`${href}/`)) {
|
|
1663
|
+
return true;
|
|
1664
|
+
}
|
|
1665
|
+
return false;
|
|
1666
|
+
}
|
|
1667
|
+
function isBottomTabMenuItemActive(item, pathname) {
|
|
1668
|
+
if (navigationPathMatches(item, pathname)) {
|
|
1669
|
+
return true;
|
|
1670
|
+
}
|
|
1671
|
+
return (item.children ?? []).some(
|
|
1672
|
+
(child) => navigationPathMatches(child, pathname) || isBottomTabMenuItemActive(child, pathname)
|
|
1673
|
+
);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
// src/navigation/navLinks.ts
|
|
1677
|
+
function getNavigationItemLabel(item) {
|
|
1678
|
+
return item.label || item.page?.title || item.page?.keyword || "";
|
|
1679
|
+
}
|
|
1680
|
+
function getNavigationItemHref(item) {
|
|
1681
|
+
if (item.item_type === "external_url" && item.external_url) {
|
|
1682
|
+
return item.external_url;
|
|
1683
|
+
}
|
|
1684
|
+
const page = item.page;
|
|
1685
|
+
if (!page) {
|
|
1686
|
+
return "#";
|
|
1687
|
+
}
|
|
1688
|
+
if (page.url) {
|
|
1689
|
+
return page.url;
|
|
1690
|
+
}
|
|
1691
|
+
return page.keyword === "home" ? "/" : `/${page.keyword}`;
|
|
1692
|
+
}
|
|
1693
|
+
function flattenNavigationMenuItems(items) {
|
|
1694
|
+
const out = [];
|
|
1695
|
+
for (const item of items) {
|
|
1696
|
+
out.push(item);
|
|
1697
|
+
if (item.children?.length) {
|
|
1698
|
+
out.push(...flattenNavigationMenuItems(item.children));
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
return out;
|
|
1702
|
+
}
|
|
1703
|
+
function getNavigationItemKeyword(item) {
|
|
1704
|
+
return item.page?.keyword ?? null;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// src/navigation/menuVisibility.ts
|
|
1708
|
+
var WEB_MENU_KEYS = ["web_header", "web_footer"];
|
|
1709
|
+
var MOBILE_MENU_KEYS = ["mobile_drawer", "mobile_bottom_tabs"];
|
|
1710
|
+
var ALL_MENU_KEYS = [...WEB_MENU_KEYS, ...MOBILE_MENU_KEYS];
|
|
1711
|
+
function isPageOnAnyMenu(payload, pageId) {
|
|
1712
|
+
return isPageInResolvedMenus(payload.menus, ALL_MENU_KEYS, pageId);
|
|
1713
|
+
}
|
|
1714
|
+
function isPageOnWebMenu(payload, pageId) {
|
|
1715
|
+
return isPageInResolvedMenus(payload.menus, WEB_MENU_KEYS, pageId);
|
|
1716
|
+
}
|
|
1717
|
+
function isPageOnMobileMenu(payload, pageId) {
|
|
1718
|
+
return isPageInResolvedMenus(payload.menus, MOBILE_MENU_KEYS, pageId);
|
|
1719
|
+
}
|
|
1720
|
+
function flattenMenuItems(items) {
|
|
1721
|
+
const out = [];
|
|
1722
|
+
for (const item of items) {
|
|
1723
|
+
out.push(item);
|
|
1724
|
+
if (item.children?.length) {
|
|
1725
|
+
out.push(...flattenMenuItems(item.children));
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return out;
|
|
1472
1729
|
}
|
|
1473
1730
|
|
|
1474
1731
|
// src/navigation/mobileIcons.ts
|
|
@@ -1527,17 +1784,99 @@ function resolveMobileIcon(value) {
|
|
|
1527
1784
|
return isMobileIconName(value) ? value : DEFAULT_MOBILE_ICON;
|
|
1528
1785
|
}
|
|
1529
1786
|
|
|
1530
|
-
// src/navigation/
|
|
1531
|
-
function
|
|
1532
|
-
|
|
1533
|
-
|
|
1787
|
+
// src/navigation/startup.ts
|
|
1788
|
+
function pickStartPage(startup, isLoggedIn, platform) {
|
|
1789
|
+
const useMobileCustom = startup.mobile_start_page_source === "custom_mobile_pages";
|
|
1790
|
+
if (isLoggedIn) {
|
|
1791
|
+
const lastVisited = platform === "mobile" ? startup.mobile_user_last_visited_page : startup.web_user_last_visited_page;
|
|
1792
|
+
const startMode = platform === "mobile" ? startup.mobile_user_start_mode : startup.web_user_start_mode;
|
|
1793
|
+
if (startMode === "last_visited_then_fixed_page" && lastVisited) {
|
|
1794
|
+
return lastVisited;
|
|
1795
|
+
}
|
|
1796
|
+
if (platform === "mobile" && useMobileCustom) {
|
|
1797
|
+
return startup.mobile_user_start_page;
|
|
1798
|
+
}
|
|
1799
|
+
if (platform === "mobile") {
|
|
1800
|
+
return startup.mobile_user_start_page ?? startup.web_user_start_page;
|
|
1801
|
+
}
|
|
1802
|
+
return startup.web_user_start_page;
|
|
1803
|
+
}
|
|
1804
|
+
if (platform === "mobile" && useMobileCustom) {
|
|
1805
|
+
return startup.mobile_guest_start_page;
|
|
1806
|
+
}
|
|
1807
|
+
if (platform === "mobile") {
|
|
1808
|
+
return startup.mobile_guest_start_page ?? startup.web_guest_start_page;
|
|
1809
|
+
}
|
|
1810
|
+
return startup.web_guest_start_page;
|
|
1534
1811
|
}
|
|
1535
|
-
function
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1812
|
+
function resolveMobileStartupRoute(startup, isLoggedIn) {
|
|
1813
|
+
const page = pickStartPage(startup, isLoggedIn, "mobile");
|
|
1814
|
+
if (!page) {
|
|
1815
|
+
return "/index";
|
|
1816
|
+
}
|
|
1817
|
+
return pageUrlToMobileRoute(page.url, page.keyword);
|
|
1818
|
+
}
|
|
1819
|
+
function resolveMobileStartupKeyword(startup, isLoggedIn) {
|
|
1820
|
+
const page = pickStartPage(startup, isLoggedIn, "mobile");
|
|
1821
|
+
return page?.keyword ?? "home";
|
|
1822
|
+
}
|
|
1823
|
+
function resolveWebStartupPath(startup, isLoggedIn) {
|
|
1824
|
+
const page = pickStartPage(startup, isLoggedIn, "web");
|
|
1825
|
+
if (!page) {
|
|
1826
|
+
return null;
|
|
1827
|
+
}
|
|
1828
|
+
if (page.url && page.url !== "") {
|
|
1829
|
+
return page.url.startsWith("/") ? page.url : `/${page.url}`;
|
|
1830
|
+
}
|
|
1831
|
+
if (page.keyword === "home") {
|
|
1832
|
+
return "/";
|
|
1833
|
+
}
|
|
1834
|
+
return `/${page.keyword}`;
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
// src/navigation/menuSearch.ts
|
|
1838
|
+
function haystacksForItem(item) {
|
|
1839
|
+
const page = item.page;
|
|
1840
|
+
const label = getNavigationItemLabel(item);
|
|
1841
|
+
const values = [label];
|
|
1842
|
+
if (page) {
|
|
1843
|
+
values.push(page.title ?? "", page.keyword ?? "", page.url ?? "");
|
|
1844
|
+
}
|
|
1845
|
+
return values.map((value) => value.trim().toLowerCase()).filter((value) => value !== "");
|
|
1538
1846
|
}
|
|
1539
|
-
function
|
|
1540
|
-
|
|
1847
|
+
function searchMenuPagesInPayload(payload, query, limit = 8) {
|
|
1848
|
+
const needle = query.trim().toLowerCase();
|
|
1849
|
+
const minChars = payload.search?.min_chars ?? 2;
|
|
1850
|
+
if (needle === "" || needle.length < minChars) {
|
|
1851
|
+
return [];
|
|
1852
|
+
}
|
|
1853
|
+
const hits = [];
|
|
1854
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1855
|
+
for (const menu of Object.values(payload.menus)) {
|
|
1856
|
+
if (!menu?.items?.length) {
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
for (const item of flattenMenuItems(menu.items)) {
|
|
1860
|
+
if (!item.page || seen.has(item.page.id)) {
|
|
1861
|
+
continue;
|
|
1862
|
+
}
|
|
1863
|
+
const matched = haystacksForItem(item).some((haystack) => haystack.includes(needle));
|
|
1864
|
+
if (!matched) {
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
seen.add(item.page.id);
|
|
1868
|
+
hits.push({
|
|
1869
|
+
page_id: item.page.id,
|
|
1870
|
+
keyword: item.page.keyword,
|
|
1871
|
+
url: getNavigationItemHref(item),
|
|
1872
|
+
title: getNavigationItemLabel(item)
|
|
1873
|
+
});
|
|
1874
|
+
if (hits.length >= limit) {
|
|
1875
|
+
return hits;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
return hits;
|
|
1541
1880
|
}
|
|
1542
1881
|
|
|
1543
1882
|
// src/utils/spacing.ts
|
|
@@ -1587,15 +1926,11 @@ function transformPageData(apiPage) {
|
|
|
1587
1926
|
url: apiPage.url ?? null,
|
|
1588
1927
|
parent_page_id: parentPageId,
|
|
1589
1928
|
is_headless: toBool(apiPage.is_headless),
|
|
1590
|
-
navPosition: apiPage.navPosition !== void 0 ? apiPage.navPosition : apiPage.nav_position ?? null,
|
|
1591
|
-
footerPosition: apiPage.footerPosition !== void 0 ? apiPage.footerPosition : apiPage.footer_position ?? null,
|
|
1592
1929
|
is_system: apiPage.is_system !== void 0 ? toBool(apiPage.is_system) : void 0,
|
|
1593
1930
|
title: apiPage.title ?? null,
|
|
1594
1931
|
description: apiPage.description ?? null,
|
|
1595
1932
|
icon: apiPage.icon ?? null,
|
|
1596
1933
|
mobile_icon: apiPage.mobile_icon ?? null,
|
|
1597
|
-
web_nav_render: apiPage.web_nav_render ?? null,
|
|
1598
|
-
mobile_nav_render: apiPage.mobile_nav_render ?? null,
|
|
1599
1934
|
children: apiPage.children?.map(transformPageData) ?? [],
|
|
1600
1935
|
id_users: apiPage.id_users,
|
|
1601
1936
|
id_pages: apiPage.id_pages ?? id,
|
|
@@ -1623,11 +1958,8 @@ export {
|
|
|
1623
1958
|
COLOR_PALETTE,
|
|
1624
1959
|
COLOR_SCALES,
|
|
1625
1960
|
CONTAINER_SIZE_PX,
|
|
1626
|
-
DEFAULT_MOBILE_GLOBAL_NAV_RENDER,
|
|
1627
1961
|
DEFAULT_MOBILE_ICON,
|
|
1628
|
-
|
|
1629
|
-
DEFAULT_WEB_GLOBAL_NAV_RENDER,
|
|
1630
|
-
DEFAULT_WEB_NAV_RENDER,
|
|
1962
|
+
DEFAULT_WEB_HEADER_PRESET,
|
|
1631
1963
|
ENDPOINTS,
|
|
1632
1964
|
FONT_SIZE_PX,
|
|
1633
1965
|
FULL_RADIUS_PX,
|
|
@@ -1636,8 +1968,6 @@ export {
|
|
|
1636
1968
|
LITERAL_CLASSES,
|
|
1637
1969
|
MOBILE_ICON_NAMES,
|
|
1638
1970
|
MOBILE_ICON_SET,
|
|
1639
|
-
MOBILE_NAV_RENDER_OPTIONS,
|
|
1640
|
-
MOBILE_NAV_RENDER_VALUES,
|
|
1641
1971
|
MOBILE_PREVIEW_ENDPOINTS,
|
|
1642
1972
|
PERMISSIONS,
|
|
1643
1973
|
PREVIEW_BRIDGE_MESSAGE,
|
|
@@ -1651,19 +1981,27 @@ export {
|
|
|
1651
1981
|
SPACING_VALUES,
|
|
1652
1982
|
STYLE_REGISTRY,
|
|
1653
1983
|
SYSTEM_ENDPOINTS,
|
|
1654
|
-
|
|
1655
|
-
|
|
1984
|
+
WEB_HEADER_PRESET_OPTIONS,
|
|
1985
|
+
WEB_HEADER_PRESET_VALUES,
|
|
1656
1986
|
_resetPluginStyleRegistry,
|
|
1657
1987
|
arePreviewPreferencesEqual,
|
|
1658
1988
|
buildConditionContext,
|
|
1659
1989
|
classifyClass,
|
|
1660
1990
|
classifyClassString,
|
|
1991
|
+
collectPageIdsFromMenuItems,
|
|
1661
1992
|
colorToHex,
|
|
1662
1993
|
evaluateCondition,
|
|
1663
1994
|
extendStyleRegistry,
|
|
1995
|
+
findMenuItemByPageId,
|
|
1996
|
+
findNearestBottomTabMenuItemForPage,
|
|
1997
|
+
findPageRefInNavigationPayload,
|
|
1664
1998
|
findRemap,
|
|
1665
|
-
|
|
1999
|
+
flattenMenuItems,
|
|
2000
|
+
flattenNavigationMenuItems,
|
|
1666
2001
|
getMergedStyleRegistry,
|
|
2002
|
+
getNavigationItemHref,
|
|
2003
|
+
getNavigationItemKeyword,
|
|
2004
|
+
getNavigationItemLabel,
|
|
1667
2005
|
getPluginStyleRegistry,
|
|
1668
2006
|
getRegistryEntry,
|
|
1669
2007
|
getRegistryEntryAny,
|
|
@@ -1672,17 +2010,22 @@ export {
|
|
|
1672
2010
|
getStylePluginId,
|
|
1673
2011
|
gridSpanToReactNativeColumn,
|
|
1674
2012
|
hasInlineFormatting,
|
|
2013
|
+
isBottomTabMenuItemActive,
|
|
1675
2014
|
isKnownStyleName,
|
|
1676
|
-
isMenuVisible,
|
|
1677
2015
|
isMobileIconName,
|
|
1678
|
-
|
|
1679
|
-
|
|
2016
|
+
isOnAnyMobileMenu,
|
|
2017
|
+
isOnAnyMobileMenuFromPayload,
|
|
2018
|
+
isPageInMenuTree,
|
|
2019
|
+
isPageInResolvedMenus,
|
|
2020
|
+
isPageOnAnyMenu,
|
|
2021
|
+
isPageOnMobileMenu,
|
|
2022
|
+
isPageOnWebMenu,
|
|
1680
2023
|
isPreviewBridgeMessage,
|
|
1681
2024
|
isRegisteredStyleName,
|
|
1682
2025
|
isStyleAllowedOnPage,
|
|
1683
2026
|
isStylePlacementAllowed,
|
|
1684
2027
|
isStyleSupportedOnPlatform,
|
|
1685
|
-
|
|
2028
|
+
isWebHeaderPreset,
|
|
1686
2029
|
mapAccordionVariantToHeroUiVariant,
|
|
1687
2030
|
mapChipVariantToHeroUiVariant,
|
|
1688
2031
|
mapDividerVariantToReactNative,
|
|
@@ -1694,6 +2037,7 @@ export {
|
|
|
1694
2037
|
mapSizeToHeroUi,
|
|
1695
2038
|
mapSizeToMantine,
|
|
1696
2039
|
mapSpacingToPx,
|
|
2040
|
+
pageUrlToMobileRoute,
|
|
1697
2041
|
parseDimensionToReactNative,
|
|
1698
2042
|
parseDimensionToWeb,
|
|
1699
2043
|
parseInlineRich,
|
|
@@ -1703,14 +2047,22 @@ export {
|
|
|
1703
2047
|
replaceCalcedValues,
|
|
1704
2048
|
resolveAssetSources,
|
|
1705
2049
|
resolveAssetUrl,
|
|
2050
|
+
resolveBranchNavGroup,
|
|
2051
|
+
resolveHolderRedirectPath,
|
|
1706
2052
|
resolveMantineVariant,
|
|
1707
2053
|
resolveMobileIcon,
|
|
1708
|
-
|
|
2054
|
+
resolveMobilePagePresentation,
|
|
2055
|
+
resolveMobileSegmentGroup,
|
|
2056
|
+
resolveMobileStartupKeyword,
|
|
2057
|
+
resolveMobileStartupRoute,
|
|
1709
2058
|
resolveSharedStyle,
|
|
1710
2059
|
resolveSharedStyleForMobile,
|
|
1711
2060
|
resolveSharedStyleForWeb,
|
|
1712
2061
|
resolveSharedStyleProps,
|
|
1713
|
-
|
|
2062
|
+
resolveWebBranchNavGroup,
|
|
2063
|
+
resolveWebHeaderPreset,
|
|
2064
|
+
resolveWebStartupPath,
|
|
2065
|
+
searchMenuPagesInPayload,
|
|
1714
2066
|
setToStylePlatform,
|
|
1715
2067
|
sharedTailwindExtend,
|
|
1716
2068
|
sharedTailwindPreset,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
package/src/api/endpoints.ts
CHANGED
|
@@ -48,6 +48,14 @@ export const ENDPOINTS = {
|
|
|
48
48
|
RESOLVE: (path: string): string =>
|
|
49
49
|
`${API_VERSION_PREFIX}/pages/resolve?path=${encodeURIComponent(path)}`,
|
|
50
50
|
},
|
|
51
|
+
NAVIGATION: {
|
|
52
|
+
GET: `${API_VERSION_PREFIX}/navigation`,
|
|
53
|
+
LAST_VISITED: `${API_VERSION_PREFIX}/navigation/last-visited`,
|
|
54
|
+
},
|
|
55
|
+
SEARCH: {
|
|
56
|
+
CONTENT: `${API_VERSION_PREFIX}/search`,
|
|
57
|
+
PAGES: `${API_VERSION_PREFIX}/search/pages`,
|
|
58
|
+
},
|
|
51
59
|
LANGUAGES: `${API_VERSION_PREFIX}/languages`,
|
|
52
60
|
FORMS: {
|
|
53
61
|
SUBMIT: `${API_VERSION_PREFIX}/forms/submit`,
|