@selfhelp/shared 1.20.0 → 1.21.0
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 +12 -0
- package/dist/index.d.mts +158 -108
- package/dist/index.d.ts +158 -108
- package/dist/index.js +421 -107
- package/dist/index.mjs +392 -92
- package/package.json +1 -1
- package/src/api/endpoints.ts +8 -0
- package/src/navigation/__tests__/navigation.test.ts +152 -64
- package/src/navigation/__tests__/startup.test.ts +33 -0
- package/src/navigation/branchNav.ts +216 -0
- package/src/navigation/headerPreset.ts +52 -0
- package/src/navigation/index.ts +9 -7
- package/src/navigation/menuMembership.ts +63 -0
- package/src/navigation/menuSearch.ts +68 -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,279 @@ 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
|
+
|
|
1477
|
+
// src/navigation/mobileRoute.ts
|
|
1478
|
+
function pageUrlToMobileRoute(url, keyword) {
|
|
1479
|
+
const normalizedKeyword = keyword.trim().toLowerCase();
|
|
1480
|
+
if (normalizedKeyword === "profile") {
|
|
1481
|
+
return "/profile";
|
|
1482
|
+
}
|
|
1483
|
+
if (normalizedKeyword === "home" || url === "/" || url === "" || url == null) {
|
|
1484
|
+
return "/index";
|
|
1485
|
+
}
|
|
1486
|
+
return `/${normalizedKeyword}`;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// src/navigation/branchNav.ts
|
|
1490
|
+
function itemLabel(item) {
|
|
1491
|
+
return item.label || item.page?.title || item.page?.keyword || "";
|
|
1492
|
+
}
|
|
1493
|
+
function toSegment(item) {
|
|
1494
|
+
if (!item.page) {
|
|
1495
|
+
return null;
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
pageId: item.page.id,
|
|
1499
|
+
keyword: item.page.keyword,
|
|
1500
|
+
url: item.page.url,
|
|
1501
|
+
label: itemLabel(item),
|
|
1502
|
+
icon: item.icon ?? item.page.icon,
|
|
1503
|
+
mobile_icon: item.page.mobile_icon
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
function findParentItem(items, pageId, parent = null) {
|
|
1507
|
+
for (const item of items) {
|
|
1508
|
+
if (item.page?.id === pageId) {
|
|
1509
|
+
return { parent, siblings: items };
|
|
1510
|
+
}
|
|
1511
|
+
if (item.children?.length) {
|
|
1512
|
+
const found = findParentItem(item.children, pageId, item);
|
|
1513
|
+
if (found) {
|
|
1514
|
+
return found;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
return null;
|
|
1519
|
+
}
|
|
1520
|
+
function menuVisibleChildItems(item) {
|
|
1521
|
+
return (item.children ?? []).filter((child) => child.page != null && child.is_active !== false);
|
|
1522
|
+
}
|
|
1523
|
+
function findMenuItemByPageId2(items, pageId) {
|
|
1524
|
+
for (const item of items) {
|
|
1525
|
+
if (item.page?.id === pageId) {
|
|
1526
|
+
return item;
|
|
1527
|
+
}
|
|
1528
|
+
if (item.children?.length) {
|
|
1529
|
+
const nested = findMenuItemByPageId2(item.children, pageId);
|
|
1530
|
+
if (nested) {
|
|
1531
|
+
return nested;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return null;
|
|
1536
|
+
}
|
|
1537
|
+
function selfSegment(item) {
|
|
1538
|
+
return toSegment(item);
|
|
1539
|
+
}
|
|
1540
|
+
function resolveBranchNavGroup(payload, currentPageId, menuKeys) {
|
|
1541
|
+
const allItems = [];
|
|
1542
|
+
for (const key of menuKeys) {
|
|
1543
|
+
const menu = payload.menus[key];
|
|
1544
|
+
if (menu?.items) {
|
|
1545
|
+
allItems.push(...menu.items);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
for (const root of allItems) {
|
|
1549
|
+
const selfChildren = menuVisibleChildItems(root);
|
|
1550
|
+
if (root.page?.id === currentPageId && selfChildren.length > 0) {
|
|
1551
|
+
const segments = selfChildren.map(toSegment).filter((s) => s != null);
|
|
1552
|
+
return segments.length > 0 ? segments : null;
|
|
1553
|
+
}
|
|
1554
|
+
const located = findParentItem([root], currentPageId);
|
|
1555
|
+
if (located) {
|
|
1556
|
+
const directChildren = menuVisibleChildItems(
|
|
1557
|
+
located.parent ?? { id: 0, item_type: "group", label: "", position: 0, children: located.siblings }
|
|
1558
|
+
);
|
|
1559
|
+
if (located.parent && located.parent.page?.id === currentPageId && directChildren.length > 0) {
|
|
1560
|
+
const segments = directChildren.map(toSegment).filter((s) => s != null);
|
|
1561
|
+
return segments.length > 0 ? segments : null;
|
|
1562
|
+
}
|
|
1563
|
+
const siblings = located.siblings.filter((s) => s.page != null && s.is_active !== false);
|
|
1564
|
+
if (siblings.length > 1) {
|
|
1565
|
+
const segments = siblings.map(toSegment).filter((s) => s != null);
|
|
1566
|
+
return segments.length > 0 ? segments : null;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
return null;
|
|
1571
|
+
}
|
|
1572
|
+
function resolveMobileSegmentGroup(payload, currentPageId) {
|
|
1573
|
+
const allItems = [];
|
|
1574
|
+
for (const key of ["mobile_drawer", "mobile_bottom_tabs"]) {
|
|
1575
|
+
const menu = payload.menus[key];
|
|
1576
|
+
if (menu?.items) {
|
|
1577
|
+
allItems.push(...menu.items);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
const currentItem = findMenuItemByPageId2(allItems, currentPageId);
|
|
1581
|
+
if (currentItem) {
|
|
1582
|
+
const selfChildren = menuVisibleChildItems(currentItem);
|
|
1583
|
+
if (selfChildren.length > 0) {
|
|
1584
|
+
const childSegments = selfChildren.map(toSegment).filter((segment) => segment != null);
|
|
1585
|
+
if (childSegments.length > 0) {
|
|
1586
|
+
if (currentItem.page?.has_content) {
|
|
1587
|
+
const self = selfSegment(currentItem);
|
|
1588
|
+
return self ? [self, ...childSegments] : childSegments;
|
|
1589
|
+
}
|
|
1590
|
+
return childSegments;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
return resolveBranchNavGroup(payload, currentPageId, ["mobile_drawer", "mobile_bottom_tabs"]);
|
|
1463
1595
|
}
|
|
1464
|
-
function
|
|
1465
|
-
return
|
|
1596
|
+
function resolveWebBranchNavGroup(payload, currentPageId) {
|
|
1597
|
+
return resolveBranchNavGroup(payload, currentPageId, ["web_header", "web_footer"]);
|
|
1466
1598
|
}
|
|
1467
|
-
function
|
|
1468
|
-
return
|
|
1599
|
+
function resolveMobilePagePresentation(payload, pageId) {
|
|
1600
|
+
return isOnAnyMobileMenuFromPayload(payload, pageId) ? "route" : "modal";
|
|
1469
1601
|
}
|
|
1470
|
-
function
|
|
1471
|
-
|
|
1602
|
+
function isOnAnyMobileMenuFromPayload(payload, pageId) {
|
|
1603
|
+
const drawerIds = collectPageIdsFromMenuItems(payload.menus.mobile_drawer?.items ?? []);
|
|
1604
|
+
const tabIds = collectPageIdsFromMenuItems(payload.menus.mobile_bottom_tabs?.items ?? []);
|
|
1605
|
+
return drawerIds.has(pageId) || tabIds.has(pageId);
|
|
1606
|
+
}
|
|
1607
|
+
function resolveHolderRedirectPath(payload, currentPageId, platform, hasContent) {
|
|
1608
|
+
if (hasContent) {
|
|
1609
|
+
return null;
|
|
1610
|
+
}
|
|
1611
|
+
const segments = platform === "mobile" ? resolveMobileSegmentGroup(payload, currentPageId) : resolveWebBranchNavGroup(payload, currentPageId);
|
|
1612
|
+
if (!segments || segments.length === 0) {
|
|
1613
|
+
return null;
|
|
1614
|
+
}
|
|
1615
|
+
const target = segments.find((segment) => segment.pageId !== currentPageId) ?? segments[0];
|
|
1616
|
+
if (target.pageId === currentPageId) {
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1619
|
+
if (platform === "mobile") {
|
|
1620
|
+
return pageUrlToMobileRoute(target.url, target.keyword);
|
|
1621
|
+
}
|
|
1622
|
+
if (target.url && target.url !== "") {
|
|
1623
|
+
return target.url.startsWith("/") ? target.url : `/${target.url}`;
|
|
1624
|
+
}
|
|
1625
|
+
return target.keyword === "home" ? "/" : `/${target.keyword}`;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
// src/navigation/navLinks.ts
|
|
1629
|
+
function getNavigationItemLabel(item) {
|
|
1630
|
+
return item.label || item.page?.title || item.page?.keyword || "";
|
|
1631
|
+
}
|
|
1632
|
+
function getNavigationItemHref(item) {
|
|
1633
|
+
if (item.item_type === "external_url" && item.external_url) {
|
|
1634
|
+
return item.external_url;
|
|
1635
|
+
}
|
|
1636
|
+
const page = item.page;
|
|
1637
|
+
if (!page) {
|
|
1638
|
+
return "#";
|
|
1639
|
+
}
|
|
1640
|
+
if (page.url) {
|
|
1641
|
+
return page.url;
|
|
1642
|
+
}
|
|
1643
|
+
return page.keyword === "home" ? "/" : `/${page.keyword}`;
|
|
1644
|
+
}
|
|
1645
|
+
function flattenNavigationMenuItems(items) {
|
|
1646
|
+
const out = [];
|
|
1647
|
+
for (const item of items) {
|
|
1648
|
+
out.push(item);
|
|
1649
|
+
if (item.children?.length) {
|
|
1650
|
+
out.push(...flattenNavigationMenuItems(item.children));
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
return out;
|
|
1654
|
+
}
|
|
1655
|
+
function getNavigationItemKeyword(item) {
|
|
1656
|
+
return item.page?.keyword ?? null;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
// src/navigation/menuVisibility.ts
|
|
1660
|
+
var WEB_MENU_KEYS = ["web_header", "web_footer"];
|
|
1661
|
+
var MOBILE_MENU_KEYS = ["mobile_drawer", "mobile_bottom_tabs"];
|
|
1662
|
+
var ALL_MENU_KEYS = [...WEB_MENU_KEYS, ...MOBILE_MENU_KEYS];
|
|
1663
|
+
function isPageOnAnyMenu(payload, pageId) {
|
|
1664
|
+
return isPageInResolvedMenus(payload.menus, ALL_MENU_KEYS, pageId);
|
|
1665
|
+
}
|
|
1666
|
+
function isPageOnWebMenu(payload, pageId) {
|
|
1667
|
+
return isPageInResolvedMenus(payload.menus, WEB_MENU_KEYS, pageId);
|
|
1668
|
+
}
|
|
1669
|
+
function isPageOnMobileMenu(payload, pageId) {
|
|
1670
|
+
return isPageInResolvedMenus(payload.menus, MOBILE_MENU_KEYS, pageId);
|
|
1671
|
+
}
|
|
1672
|
+
function flattenMenuItems(items) {
|
|
1673
|
+
const out = [];
|
|
1674
|
+
for (const item of items) {
|
|
1675
|
+
out.push(item);
|
|
1676
|
+
if (item.children?.length) {
|
|
1677
|
+
out.push(...flattenMenuItems(item.children));
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
return out;
|
|
1472
1681
|
}
|
|
1473
1682
|
|
|
1474
1683
|
// src/navigation/mobileIcons.ts
|
|
@@ -1527,17 +1736,98 @@ function resolveMobileIcon(value) {
|
|
|
1527
1736
|
return isMobileIconName(value) ? value : DEFAULT_MOBILE_ICON;
|
|
1528
1737
|
}
|
|
1529
1738
|
|
|
1530
|
-
// src/navigation/
|
|
1531
|
-
function
|
|
1532
|
-
|
|
1533
|
-
|
|
1739
|
+
// src/navigation/startup.ts
|
|
1740
|
+
function pickStartPage(startup, isLoggedIn, platform) {
|
|
1741
|
+
const useMobileCustom = startup.mobile_start_page_source === "custom_mobile_pages";
|
|
1742
|
+
if (isLoggedIn) {
|
|
1743
|
+
const lastVisited = platform === "mobile" ? startup.mobile_user_last_visited_page : startup.web_user_last_visited_page;
|
|
1744
|
+
const startMode = platform === "mobile" ? startup.mobile_user_start_mode : startup.web_user_start_mode;
|
|
1745
|
+
if (startMode === "last_visited_then_fixed_page" && lastVisited) {
|
|
1746
|
+
return lastVisited;
|
|
1747
|
+
}
|
|
1748
|
+
if (platform === "mobile" && useMobileCustom) {
|
|
1749
|
+
return startup.mobile_user_start_page;
|
|
1750
|
+
}
|
|
1751
|
+
if (platform === "mobile") {
|
|
1752
|
+
return startup.mobile_user_start_page ?? startup.web_user_start_page;
|
|
1753
|
+
}
|
|
1754
|
+
return startup.web_user_start_page;
|
|
1755
|
+
}
|
|
1756
|
+
if (platform === "mobile" && useMobileCustom) {
|
|
1757
|
+
return startup.mobile_guest_start_page;
|
|
1758
|
+
}
|
|
1759
|
+
if (platform === "mobile") {
|
|
1760
|
+
return startup.mobile_guest_start_page ?? startup.web_guest_start_page;
|
|
1761
|
+
}
|
|
1762
|
+
return startup.web_guest_start_page;
|
|
1763
|
+
}
|
|
1764
|
+
function resolveMobileStartupRoute(startup, isLoggedIn) {
|
|
1765
|
+
const page = pickStartPage(startup, isLoggedIn, "mobile");
|
|
1766
|
+
if (!page) {
|
|
1767
|
+
return "/index";
|
|
1768
|
+
}
|
|
1769
|
+
return pageUrlToMobileRoute(page.url, page.keyword);
|
|
1534
1770
|
}
|
|
1535
|
-
function
|
|
1536
|
-
const
|
|
1537
|
-
return
|
|
1771
|
+
function resolveMobileStartupKeyword(startup, isLoggedIn) {
|
|
1772
|
+
const page = pickStartPage(startup, isLoggedIn, "mobile");
|
|
1773
|
+
return page?.keyword ?? "home";
|
|
1538
1774
|
}
|
|
1539
|
-
function
|
|
1540
|
-
|
|
1775
|
+
function resolveWebStartupPath(startup, isLoggedIn) {
|
|
1776
|
+
const page = pickStartPage(startup, isLoggedIn, "web");
|
|
1777
|
+
if (!page) {
|
|
1778
|
+
return null;
|
|
1779
|
+
}
|
|
1780
|
+
if (page.url && page.url !== "") {
|
|
1781
|
+
return page.url.startsWith("/") ? page.url : `/${page.url}`;
|
|
1782
|
+
}
|
|
1783
|
+
if (page.keyword === "home") {
|
|
1784
|
+
return "/";
|
|
1785
|
+
}
|
|
1786
|
+
return `/${page.keyword}`;
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
// src/navigation/menuSearch.ts
|
|
1790
|
+
function haystacksForItem(item) {
|
|
1791
|
+
const page = item.page;
|
|
1792
|
+
const label = getNavigationItemLabel(item);
|
|
1793
|
+
const values = [label];
|
|
1794
|
+
if (page) {
|
|
1795
|
+
values.push(page.title ?? "", page.keyword ?? "", page.url ?? "");
|
|
1796
|
+
}
|
|
1797
|
+
return values.map((value) => value.trim().toLowerCase()).filter((value) => value !== "");
|
|
1798
|
+
}
|
|
1799
|
+
function searchMenuPagesInPayload(payload, query, limit = 8) {
|
|
1800
|
+
const needle = query.trim().toLowerCase();
|
|
1801
|
+
if (needle === "") {
|
|
1802
|
+
return [];
|
|
1803
|
+
}
|
|
1804
|
+
const hits = [];
|
|
1805
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1806
|
+
for (const menu of Object.values(payload.menus)) {
|
|
1807
|
+
if (!menu?.items?.length) {
|
|
1808
|
+
continue;
|
|
1809
|
+
}
|
|
1810
|
+
for (const item of flattenMenuItems(menu.items)) {
|
|
1811
|
+
if (!item.page || seen.has(item.page.id)) {
|
|
1812
|
+
continue;
|
|
1813
|
+
}
|
|
1814
|
+
const matched = haystacksForItem(item).some((haystack) => haystack.includes(needle));
|
|
1815
|
+
if (!matched) {
|
|
1816
|
+
continue;
|
|
1817
|
+
}
|
|
1818
|
+
seen.add(item.page.id);
|
|
1819
|
+
hits.push({
|
|
1820
|
+
page_id: item.page.id,
|
|
1821
|
+
keyword: item.page.keyword,
|
|
1822
|
+
url: getNavigationItemHref(item),
|
|
1823
|
+
title: getNavigationItemLabel(item)
|
|
1824
|
+
});
|
|
1825
|
+
if (hits.length >= limit) {
|
|
1826
|
+
return hits;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
return hits;
|
|
1541
1831
|
}
|
|
1542
1832
|
|
|
1543
1833
|
// src/utils/spacing.ts
|
|
@@ -1587,15 +1877,11 @@ function transformPageData(apiPage) {
|
|
|
1587
1877
|
url: apiPage.url ?? null,
|
|
1588
1878
|
parent_page_id: parentPageId,
|
|
1589
1879
|
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
1880
|
is_system: apiPage.is_system !== void 0 ? toBool(apiPage.is_system) : void 0,
|
|
1593
1881
|
title: apiPage.title ?? null,
|
|
1594
1882
|
description: apiPage.description ?? null,
|
|
1595
1883
|
icon: apiPage.icon ?? null,
|
|
1596
1884
|
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
1885
|
children: apiPage.children?.map(transformPageData) ?? [],
|
|
1600
1886
|
id_users: apiPage.id_users,
|
|
1601
1887
|
id_pages: apiPage.id_pages ?? id,
|
|
@@ -1623,11 +1909,8 @@ export {
|
|
|
1623
1909
|
COLOR_PALETTE,
|
|
1624
1910
|
COLOR_SCALES,
|
|
1625
1911
|
CONTAINER_SIZE_PX,
|
|
1626
|
-
DEFAULT_MOBILE_GLOBAL_NAV_RENDER,
|
|
1627
1912
|
DEFAULT_MOBILE_ICON,
|
|
1628
|
-
|
|
1629
|
-
DEFAULT_WEB_GLOBAL_NAV_RENDER,
|
|
1630
|
-
DEFAULT_WEB_NAV_RENDER,
|
|
1913
|
+
DEFAULT_WEB_HEADER_PRESET,
|
|
1631
1914
|
ENDPOINTS,
|
|
1632
1915
|
FONT_SIZE_PX,
|
|
1633
1916
|
FULL_RADIUS_PX,
|
|
@@ -1636,8 +1919,6 @@ export {
|
|
|
1636
1919
|
LITERAL_CLASSES,
|
|
1637
1920
|
MOBILE_ICON_NAMES,
|
|
1638
1921
|
MOBILE_ICON_SET,
|
|
1639
|
-
MOBILE_NAV_RENDER_OPTIONS,
|
|
1640
|
-
MOBILE_NAV_RENDER_VALUES,
|
|
1641
1922
|
MOBILE_PREVIEW_ENDPOINTS,
|
|
1642
1923
|
PERMISSIONS,
|
|
1643
1924
|
PREVIEW_BRIDGE_MESSAGE,
|
|
@@ -1651,19 +1932,25 @@ export {
|
|
|
1651
1932
|
SPACING_VALUES,
|
|
1652
1933
|
STYLE_REGISTRY,
|
|
1653
1934
|
SYSTEM_ENDPOINTS,
|
|
1654
|
-
|
|
1655
|
-
|
|
1935
|
+
WEB_HEADER_PRESET_OPTIONS,
|
|
1936
|
+
WEB_HEADER_PRESET_VALUES,
|
|
1656
1937
|
_resetPluginStyleRegistry,
|
|
1657
1938
|
arePreviewPreferencesEqual,
|
|
1658
1939
|
buildConditionContext,
|
|
1659
1940
|
classifyClass,
|
|
1660
1941
|
classifyClassString,
|
|
1942
|
+
collectPageIdsFromMenuItems,
|
|
1661
1943
|
colorToHex,
|
|
1662
1944
|
evaluateCondition,
|
|
1663
1945
|
extendStyleRegistry,
|
|
1946
|
+
findMenuItemByPageId,
|
|
1664
1947
|
findRemap,
|
|
1665
|
-
|
|
1948
|
+
flattenMenuItems,
|
|
1949
|
+
flattenNavigationMenuItems,
|
|
1666
1950
|
getMergedStyleRegistry,
|
|
1951
|
+
getNavigationItemHref,
|
|
1952
|
+
getNavigationItemKeyword,
|
|
1953
|
+
getNavigationItemLabel,
|
|
1667
1954
|
getPluginStyleRegistry,
|
|
1668
1955
|
getRegistryEntry,
|
|
1669
1956
|
getRegistryEntryAny,
|
|
@@ -1673,16 +1960,20 @@ export {
|
|
|
1673
1960
|
gridSpanToReactNativeColumn,
|
|
1674
1961
|
hasInlineFormatting,
|
|
1675
1962
|
isKnownStyleName,
|
|
1676
|
-
isMenuVisible,
|
|
1677
1963
|
isMobileIconName,
|
|
1678
|
-
|
|
1679
|
-
|
|
1964
|
+
isOnAnyMobileMenu,
|
|
1965
|
+
isOnAnyMobileMenuFromPayload,
|
|
1966
|
+
isPageInMenuTree,
|
|
1967
|
+
isPageInResolvedMenus,
|
|
1968
|
+
isPageOnAnyMenu,
|
|
1969
|
+
isPageOnMobileMenu,
|
|
1970
|
+
isPageOnWebMenu,
|
|
1680
1971
|
isPreviewBridgeMessage,
|
|
1681
1972
|
isRegisteredStyleName,
|
|
1682
1973
|
isStyleAllowedOnPage,
|
|
1683
1974
|
isStylePlacementAllowed,
|
|
1684
1975
|
isStyleSupportedOnPlatform,
|
|
1685
|
-
|
|
1976
|
+
isWebHeaderPreset,
|
|
1686
1977
|
mapAccordionVariantToHeroUiVariant,
|
|
1687
1978
|
mapChipVariantToHeroUiVariant,
|
|
1688
1979
|
mapDividerVariantToReactNative,
|
|
@@ -1694,6 +1985,7 @@ export {
|
|
|
1694
1985
|
mapSizeToHeroUi,
|
|
1695
1986
|
mapSizeToMantine,
|
|
1696
1987
|
mapSpacingToPx,
|
|
1988
|
+
pageUrlToMobileRoute,
|
|
1697
1989
|
parseDimensionToReactNative,
|
|
1698
1990
|
parseDimensionToWeb,
|
|
1699
1991
|
parseInlineRich,
|
|
@@ -1703,14 +1995,22 @@ export {
|
|
|
1703
1995
|
replaceCalcedValues,
|
|
1704
1996
|
resolveAssetSources,
|
|
1705
1997
|
resolveAssetUrl,
|
|
1998
|
+
resolveBranchNavGroup,
|
|
1999
|
+
resolveHolderRedirectPath,
|
|
1706
2000
|
resolveMantineVariant,
|
|
1707
2001
|
resolveMobileIcon,
|
|
1708
|
-
|
|
2002
|
+
resolveMobilePagePresentation,
|
|
2003
|
+
resolveMobileSegmentGroup,
|
|
2004
|
+
resolveMobileStartupKeyword,
|
|
2005
|
+
resolveMobileStartupRoute,
|
|
1709
2006
|
resolveSharedStyle,
|
|
1710
2007
|
resolveSharedStyleForMobile,
|
|
1711
2008
|
resolveSharedStyleForWeb,
|
|
1712
2009
|
resolveSharedStyleProps,
|
|
1713
|
-
|
|
2010
|
+
resolveWebBranchNavGroup,
|
|
2011
|
+
resolveWebHeaderPreset,
|
|
2012
|
+
resolveWebStartupPath,
|
|
2013
|
+
searchMenuPagesInPayload,
|
|
1714
2014
|
setToStylePlatform,
|
|
1715
2015
|
sharedTailwindExtend,
|
|
1716
2016
|
sharedTailwindPreset,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
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`,
|