@selfhelp/shared 1.18.0 → 1.19.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 +24 -0
- package/dist/index.d.mts +128 -1
- package/dist/index.d.ts +128 -1
- package/dist/index.js +187 -0
- package/dist/index.mjs +167 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/navigation/__tests__/navigation.test.ts +106 -0
- package/src/navigation/index.ts +12 -0
- package/src/navigation/menuVisibility.ts +38 -0
- package/src/navigation/mobileIcons.ts +86 -0
- package/src/navigation/navRender.ts +132 -0
- package/src/types/pages.ts +17 -0
- package/src/utils/__tests__/transformPageData.test.ts +23 -0
- package/src/utils/transformPageData.ts +17 -0
package/dist/index.js
CHANGED
|
@@ -41,12 +41,21 @@ __export(index_exports, {
|
|
|
41
41
|
COLOR_PALETTE: () => COLOR_PALETTE,
|
|
42
42
|
COLOR_SCALES: () => COLOR_SCALES,
|
|
43
43
|
CONTAINER_SIZE_PX: () => CONTAINER_SIZE_PX,
|
|
44
|
+
DEFAULT_MOBILE_GLOBAL_NAV_RENDER: () => DEFAULT_MOBILE_GLOBAL_NAV_RENDER,
|
|
45
|
+
DEFAULT_MOBILE_ICON: () => DEFAULT_MOBILE_ICON,
|
|
46
|
+
DEFAULT_MOBILE_NAV_RENDER: () => DEFAULT_MOBILE_NAV_RENDER,
|
|
47
|
+
DEFAULT_WEB_GLOBAL_NAV_RENDER: () => DEFAULT_WEB_GLOBAL_NAV_RENDER,
|
|
48
|
+
DEFAULT_WEB_NAV_RENDER: () => DEFAULT_WEB_NAV_RENDER,
|
|
44
49
|
ENDPOINTS: () => ENDPOINTS,
|
|
45
50
|
FONT_SIZE_PX: () => FONT_SIZE_PX,
|
|
46
51
|
FULL_RADIUS_PX: () => FULL_RADIUS_PX,
|
|
47
52
|
HEADER_CLIENT_TYPE: () => HEADER_CLIENT_TYPE,
|
|
48
53
|
LINE_HEIGHT: () => LINE_HEIGHT,
|
|
49
54
|
LITERAL_CLASSES: () => LITERAL_CLASSES,
|
|
55
|
+
MOBILE_ICON_NAMES: () => MOBILE_ICON_NAMES,
|
|
56
|
+
MOBILE_ICON_SET: () => MOBILE_ICON_SET,
|
|
57
|
+
MOBILE_NAV_RENDER_OPTIONS: () => MOBILE_NAV_RENDER_OPTIONS,
|
|
58
|
+
MOBILE_NAV_RENDER_VALUES: () => MOBILE_NAV_RENDER_VALUES,
|
|
50
59
|
MOBILE_PREVIEW_ENDPOINTS: () => MOBILE_PREVIEW_ENDPOINTS,
|
|
51
60
|
PERMISSIONS: () => PERMISSIONS,
|
|
52
61
|
PREVIEW_BRIDGE_MESSAGE: () => PREVIEW_BRIDGE_MESSAGE,
|
|
@@ -60,6 +69,8 @@ __export(index_exports, {
|
|
|
60
69
|
SPACING_VALUES: () => SPACING_VALUES,
|
|
61
70
|
STYLE_REGISTRY: () => STYLE_REGISTRY,
|
|
62
71
|
SYSTEM_ENDPOINTS: () => SYSTEM_ENDPOINTS,
|
|
72
|
+
WEB_NAV_RENDER_OPTIONS: () => WEB_NAV_RENDER_OPTIONS,
|
|
73
|
+
WEB_NAV_RENDER_VALUES: () => WEB_NAV_RENDER_VALUES,
|
|
63
74
|
_resetPluginStyleRegistry: () => _resetPluginStyleRegistry,
|
|
64
75
|
arePreviewPreferencesEqual: () => arePreviewPreferencesEqual,
|
|
65
76
|
buildConditionContext: () => buildConditionContext,
|
|
@@ -69,6 +80,7 @@ __export(index_exports, {
|
|
|
69
80
|
evaluateCondition: () => evaluateCondition,
|
|
70
81
|
extendStyleRegistry: () => extendStyleRegistry,
|
|
71
82
|
findRemap: () => findRemap,
|
|
83
|
+
getMenuVisibleChildren: () => getMenuVisibleChildren,
|
|
72
84
|
getMergedStyleRegistry: () => getMergedStyleRegistry,
|
|
73
85
|
getPluginStyleRegistry: () => getPluginStyleRegistry,
|
|
74
86
|
getRegistryEntry: () => getRegistryEntry,
|
|
@@ -79,11 +91,16 @@ __export(index_exports, {
|
|
|
79
91
|
gridSpanToReactNativeColumn: () => gridSpanToReactNativeColumn,
|
|
80
92
|
hasInlineFormatting: () => hasInlineFormatting,
|
|
81
93
|
isKnownStyleName: () => isKnownStyleName,
|
|
94
|
+
isMenuVisible: () => isMenuVisible,
|
|
95
|
+
isMobileIconName: () => isMobileIconName,
|
|
96
|
+
isMobileNavRender: () => isMobileNavRender,
|
|
97
|
+
isNavigationPage: () => isNavigationPage,
|
|
82
98
|
isPreviewBridgeMessage: () => isPreviewBridgeMessage,
|
|
83
99
|
isRegisteredStyleName: () => isRegisteredStyleName,
|
|
84
100
|
isStyleAllowedOnPage: () => isStyleAllowedOnPage,
|
|
85
101
|
isStylePlacementAllowed: () => isStylePlacementAllowed,
|
|
86
102
|
isStyleSupportedOnPlatform: () => isStyleSupportedOnPlatform,
|
|
103
|
+
isWebNavRender: () => isWebNavRender,
|
|
87
104
|
mapAccordionVariantToHeroUiVariant: () => mapAccordionVariantToHeroUiVariant,
|
|
88
105
|
mapChipVariantToHeroUiVariant: () => mapChipVariantToHeroUiVariant,
|
|
89
106
|
mapDividerVariantToReactNative: () => mapDividerVariantToReactNative,
|
|
@@ -105,10 +122,13 @@ __export(index_exports, {
|
|
|
105
122
|
resolveAssetSources: () => resolveAssetSources,
|
|
106
123
|
resolveAssetUrl: () => resolveAssetUrl,
|
|
107
124
|
resolveMantineVariant: () => resolveMantineVariant,
|
|
125
|
+
resolveMobileIcon: () => resolveMobileIcon,
|
|
126
|
+
resolveMobileNavRender: () => resolveMobileNavRender,
|
|
108
127
|
resolveSharedStyle: () => resolveSharedStyle,
|
|
109
128
|
resolveSharedStyleForMobile: () => resolveSharedStyleForMobile,
|
|
110
129
|
resolveSharedStyleForWeb: () => resolveSharedStyleForWeb,
|
|
111
130
|
resolveSharedStyleProps: () => resolveSharedStyleProps,
|
|
131
|
+
resolveWebNavRender: () => resolveWebNavRender,
|
|
112
132
|
setToStylePlatform: () => setToStylePlatform,
|
|
113
133
|
sharedTailwindExtend: () => sharedTailwindExtend,
|
|
114
134
|
sharedTailwindPreset: () => sharedTailwindPreset,
|
|
@@ -1524,6 +1544,149 @@ function stripHtmlToText(value) {
|
|
|
1524
1544
|
return out.replace(/\s+/g, " ").trim();
|
|
1525
1545
|
}
|
|
1526
1546
|
|
|
1547
|
+
// src/navigation/navRender.ts
|
|
1548
|
+
var WEB_NAV_RENDER_VALUES = [
|
|
1549
|
+
"header-dropdown",
|
|
1550
|
+
"tabs",
|
|
1551
|
+
"sidebar-drawer",
|
|
1552
|
+
"hero-cards"
|
|
1553
|
+
];
|
|
1554
|
+
var MOBILE_NAV_RENDER_VALUES = [
|
|
1555
|
+
"segmented-tabs",
|
|
1556
|
+
"bottom-tabs",
|
|
1557
|
+
"drawer",
|
|
1558
|
+
"hero-cards"
|
|
1559
|
+
];
|
|
1560
|
+
var DEFAULT_WEB_NAV_RENDER = "tabs";
|
|
1561
|
+
var DEFAULT_MOBILE_NAV_RENDER = "segmented-tabs";
|
|
1562
|
+
var DEFAULT_WEB_GLOBAL_NAV_RENDER = "header-dropdown";
|
|
1563
|
+
var DEFAULT_MOBILE_GLOBAL_NAV_RENDER = "bottom-tabs";
|
|
1564
|
+
var WEB_NAV_RENDER_OPTIONS = [
|
|
1565
|
+
{
|
|
1566
|
+
value: "header-dropdown",
|
|
1567
|
+
label: "Header dropdown",
|
|
1568
|
+
description: "Classic top menu; child pages appear in a dropdown. Best for the global website menu."
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
value: "tabs",
|
|
1572
|
+
label: "Tabs",
|
|
1573
|
+
description: "Show child pages as horizontal tabs. Best for a navigation page with a few children."
|
|
1574
|
+
},
|
|
1575
|
+
{
|
|
1576
|
+
value: "sidebar-drawer",
|
|
1577
|
+
label: "Sidebar drawer",
|
|
1578
|
+
description: "Side drawer / hamburger menu. Best for large or deep navigation."
|
|
1579
|
+
},
|
|
1580
|
+
{
|
|
1581
|
+
value: "hero-cards",
|
|
1582
|
+
label: "Hero cards",
|
|
1583
|
+
description: "Dashboard-style card grid. Best for landing pages and CMS app dashboards."
|
|
1584
|
+
}
|
|
1585
|
+
];
|
|
1586
|
+
var MOBILE_NAV_RENDER_OPTIONS = [
|
|
1587
|
+
{
|
|
1588
|
+
value: "segmented-tabs",
|
|
1589
|
+
label: "Segmented tabs",
|
|
1590
|
+
description: "Top segmented control for first-level children. Best for a few child pages."
|
|
1591
|
+
},
|
|
1592
|
+
{
|
|
1593
|
+
value: "bottom-tabs",
|
|
1594
|
+
label: "Bottom tabs",
|
|
1595
|
+
description: "Bottom tab bar for 3\u20135 main app-like destinations."
|
|
1596
|
+
},
|
|
1597
|
+
{
|
|
1598
|
+
value: "drawer",
|
|
1599
|
+
label: "Drawer",
|
|
1600
|
+
description: "Hamburger / side drawer for larger navigation."
|
|
1601
|
+
},
|
|
1602
|
+
{
|
|
1603
|
+
value: "hero-cards",
|
|
1604
|
+
label: "Hero cards",
|
|
1605
|
+
description: "Card grid for dashboards and CMS app pages."
|
|
1606
|
+
}
|
|
1607
|
+
];
|
|
1608
|
+
function isWebNavRender(value) {
|
|
1609
|
+
return typeof value === "string" && WEB_NAV_RENDER_VALUES.includes(value);
|
|
1610
|
+
}
|
|
1611
|
+
function isMobileNavRender(value) {
|
|
1612
|
+
return typeof value === "string" && MOBILE_NAV_RENDER_VALUES.includes(value);
|
|
1613
|
+
}
|
|
1614
|
+
function resolveWebNavRender(value, fallback = DEFAULT_WEB_NAV_RENDER) {
|
|
1615
|
+
return isWebNavRender(value) ? value : fallback;
|
|
1616
|
+
}
|
|
1617
|
+
function resolveMobileNavRender(value, fallback = DEFAULT_MOBILE_NAV_RENDER) {
|
|
1618
|
+
return isMobileNavRender(value) ? value : fallback;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
// src/navigation/mobileIcons.ts
|
|
1622
|
+
var MOBILE_ICON_SET = [
|
|
1623
|
+
{ name: "House", label: "Home" },
|
|
1624
|
+
{ name: "LayoutDashboard", label: "Dashboard" },
|
|
1625
|
+
{ name: "User", label: "User" },
|
|
1626
|
+
{ name: "Users", label: "Users / Team" },
|
|
1627
|
+
{ name: "Settings", label: "Settings" },
|
|
1628
|
+
{ name: "FileText", label: "Document" },
|
|
1629
|
+
{ name: "Files", label: "Files" },
|
|
1630
|
+
{ name: "Folder", label: "Folder" },
|
|
1631
|
+
{ name: "Info", label: "Info" },
|
|
1632
|
+
{ name: "CircleQuestionMark", label: "Help" },
|
|
1633
|
+
{ name: "Mail", label: "Mail" },
|
|
1634
|
+
{ name: "Phone", label: "Phone" },
|
|
1635
|
+
{ name: "Calendar", label: "Calendar" },
|
|
1636
|
+
{ name: "Bell", label: "Notifications" },
|
|
1637
|
+
{ name: "Search", label: "Search" },
|
|
1638
|
+
{ name: "Star", label: "Star" },
|
|
1639
|
+
{ name: "Heart", label: "Heart" },
|
|
1640
|
+
{ name: "Bookmark", label: "Bookmark" },
|
|
1641
|
+
{ name: "Map", label: "Map" },
|
|
1642
|
+
{ name: "MapPin", label: "Location" },
|
|
1643
|
+
{ name: "Image", label: "Image" },
|
|
1644
|
+
{ name: "Video", label: "Video" },
|
|
1645
|
+
{ name: "Music", label: "Music" },
|
|
1646
|
+
{ name: "ShoppingCart", label: "Shopping cart" },
|
|
1647
|
+
{ name: "CreditCard", label: "Payment" },
|
|
1648
|
+
{ name: "ChartBar", label: "Bar chart" },
|
|
1649
|
+
{ name: "ChartPie", label: "Pie chart" },
|
|
1650
|
+
{ name: "Activity", label: "Activity" },
|
|
1651
|
+
{ name: "Shield", label: "Shield" },
|
|
1652
|
+
{ name: "Lock", label: "Lock" },
|
|
1653
|
+
{ name: "Globe", label: "Globe" },
|
|
1654
|
+
{ name: "Compass", label: "Compass" },
|
|
1655
|
+
{ name: "Flag", label: "Flag" },
|
|
1656
|
+
{ name: "Award", label: "Award" },
|
|
1657
|
+
{ name: "Briefcase", label: "Work" },
|
|
1658
|
+
{ name: "Building", label: "Building" },
|
|
1659
|
+
{ name: "BookOpen", label: "Book" },
|
|
1660
|
+
{ name: "MessageSquare", label: "Messages" },
|
|
1661
|
+
{ name: "ClipboardList", label: "Tasks" },
|
|
1662
|
+
{ name: "CircleCheck", label: "Check" },
|
|
1663
|
+
{ name: "List", label: "List" },
|
|
1664
|
+
{ name: "LayoutGrid", label: "Grid" },
|
|
1665
|
+
{ name: "Menu", label: "Menu" },
|
|
1666
|
+
{ name: "Database", label: "Data" }
|
|
1667
|
+
];
|
|
1668
|
+
var MOBILE_ICON_NAMES = MOBILE_ICON_SET.map((entry) => entry.name);
|
|
1669
|
+
var DEFAULT_MOBILE_ICON = "Circle";
|
|
1670
|
+
function isMobileIconName(value) {
|
|
1671
|
+
return typeof value === "string" && MOBILE_ICON_NAMES.includes(value);
|
|
1672
|
+
}
|
|
1673
|
+
function resolveMobileIcon(value) {
|
|
1674
|
+
return isMobileIconName(value) ? value : DEFAULT_MOBILE_ICON;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
// src/navigation/menuVisibility.ts
|
|
1678
|
+
function isMenuVisible(page) {
|
|
1679
|
+
if (page.is_headless) return false;
|
|
1680
|
+
return page.navPosition !== null && page.navPosition !== void 0;
|
|
1681
|
+
}
|
|
1682
|
+
function getMenuVisibleChildren(page) {
|
|
1683
|
+
const children = page.children ?? [];
|
|
1684
|
+
return children.filter(isMenuVisible).sort((a, b) => (a.navPosition ?? 0) - (b.navPosition ?? 0));
|
|
1685
|
+
}
|
|
1686
|
+
function isNavigationPage(page) {
|
|
1687
|
+
return getMenuVisibleChildren(page).length > 0;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1527
1690
|
// src/utils/spacing.ts
|
|
1528
1691
|
var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
|
|
1529
1692
|
function parseSpacing(raw) {
|
|
@@ -1576,6 +1739,10 @@ function transformPageData(apiPage) {
|
|
|
1576
1739
|
is_system: apiPage.is_system !== void 0 ? toBool(apiPage.is_system) : void 0,
|
|
1577
1740
|
title: apiPage.title ?? null,
|
|
1578
1741
|
description: apiPage.description ?? null,
|
|
1742
|
+
icon: apiPage.icon ?? null,
|
|
1743
|
+
mobile_icon: apiPage.mobile_icon ?? null,
|
|
1744
|
+
web_nav_render: apiPage.web_nav_render ?? null,
|
|
1745
|
+
mobile_nav_render: apiPage.mobile_nav_render ?? null,
|
|
1579
1746
|
children: apiPage.children?.map(transformPageData) ?? [],
|
|
1580
1747
|
id_users: apiPage.id_users,
|
|
1581
1748
|
id_pages: apiPage.id_pages ?? id,
|
|
@@ -1604,12 +1771,21 @@ function transformPagesData(pages) {
|
|
|
1604
1771
|
COLOR_PALETTE,
|
|
1605
1772
|
COLOR_SCALES,
|
|
1606
1773
|
CONTAINER_SIZE_PX,
|
|
1774
|
+
DEFAULT_MOBILE_GLOBAL_NAV_RENDER,
|
|
1775
|
+
DEFAULT_MOBILE_ICON,
|
|
1776
|
+
DEFAULT_MOBILE_NAV_RENDER,
|
|
1777
|
+
DEFAULT_WEB_GLOBAL_NAV_RENDER,
|
|
1778
|
+
DEFAULT_WEB_NAV_RENDER,
|
|
1607
1779
|
ENDPOINTS,
|
|
1608
1780
|
FONT_SIZE_PX,
|
|
1609
1781
|
FULL_RADIUS_PX,
|
|
1610
1782
|
HEADER_CLIENT_TYPE,
|
|
1611
1783
|
LINE_HEIGHT,
|
|
1612
1784
|
LITERAL_CLASSES,
|
|
1785
|
+
MOBILE_ICON_NAMES,
|
|
1786
|
+
MOBILE_ICON_SET,
|
|
1787
|
+
MOBILE_NAV_RENDER_OPTIONS,
|
|
1788
|
+
MOBILE_NAV_RENDER_VALUES,
|
|
1613
1789
|
MOBILE_PREVIEW_ENDPOINTS,
|
|
1614
1790
|
PERMISSIONS,
|
|
1615
1791
|
PREVIEW_BRIDGE_MESSAGE,
|
|
@@ -1623,6 +1799,8 @@ function transformPagesData(pages) {
|
|
|
1623
1799
|
SPACING_VALUES,
|
|
1624
1800
|
STYLE_REGISTRY,
|
|
1625
1801
|
SYSTEM_ENDPOINTS,
|
|
1802
|
+
WEB_NAV_RENDER_OPTIONS,
|
|
1803
|
+
WEB_NAV_RENDER_VALUES,
|
|
1626
1804
|
_resetPluginStyleRegistry,
|
|
1627
1805
|
arePreviewPreferencesEqual,
|
|
1628
1806
|
buildConditionContext,
|
|
@@ -1632,6 +1810,7 @@ function transformPagesData(pages) {
|
|
|
1632
1810
|
evaluateCondition,
|
|
1633
1811
|
extendStyleRegistry,
|
|
1634
1812
|
findRemap,
|
|
1813
|
+
getMenuVisibleChildren,
|
|
1635
1814
|
getMergedStyleRegistry,
|
|
1636
1815
|
getPluginStyleRegistry,
|
|
1637
1816
|
getRegistryEntry,
|
|
@@ -1642,11 +1821,16 @@ function transformPagesData(pages) {
|
|
|
1642
1821
|
gridSpanToReactNativeColumn,
|
|
1643
1822
|
hasInlineFormatting,
|
|
1644
1823
|
isKnownStyleName,
|
|
1824
|
+
isMenuVisible,
|
|
1825
|
+
isMobileIconName,
|
|
1826
|
+
isMobileNavRender,
|
|
1827
|
+
isNavigationPage,
|
|
1645
1828
|
isPreviewBridgeMessage,
|
|
1646
1829
|
isRegisteredStyleName,
|
|
1647
1830
|
isStyleAllowedOnPage,
|
|
1648
1831
|
isStylePlacementAllowed,
|
|
1649
1832
|
isStyleSupportedOnPlatform,
|
|
1833
|
+
isWebNavRender,
|
|
1650
1834
|
mapAccordionVariantToHeroUiVariant,
|
|
1651
1835
|
mapChipVariantToHeroUiVariant,
|
|
1652
1836
|
mapDividerVariantToReactNative,
|
|
@@ -1668,10 +1852,13 @@ function transformPagesData(pages) {
|
|
|
1668
1852
|
resolveAssetSources,
|
|
1669
1853
|
resolveAssetUrl,
|
|
1670
1854
|
resolveMantineVariant,
|
|
1855
|
+
resolveMobileIcon,
|
|
1856
|
+
resolveMobileNavRender,
|
|
1671
1857
|
resolveSharedStyle,
|
|
1672
1858
|
resolveSharedStyleForMobile,
|
|
1673
1859
|
resolveSharedStyleForWeb,
|
|
1674
1860
|
resolveSharedStyleProps,
|
|
1861
|
+
resolveWebNavRender,
|
|
1675
1862
|
setToStylePlatform,
|
|
1676
1863
|
sharedTailwindExtend,
|
|
1677
1864
|
sharedTailwindPreset,
|
package/dist/index.mjs
CHANGED
|
@@ -1397,6 +1397,149 @@ function stripHtmlToText(value) {
|
|
|
1397
1397
|
return out.replace(/\s+/g, " ").trim();
|
|
1398
1398
|
}
|
|
1399
1399
|
|
|
1400
|
+
// src/navigation/navRender.ts
|
|
1401
|
+
var WEB_NAV_RENDER_VALUES = [
|
|
1402
|
+
"header-dropdown",
|
|
1403
|
+
"tabs",
|
|
1404
|
+
"sidebar-drawer",
|
|
1405
|
+
"hero-cards"
|
|
1406
|
+
];
|
|
1407
|
+
var MOBILE_NAV_RENDER_VALUES = [
|
|
1408
|
+
"segmented-tabs",
|
|
1409
|
+
"bottom-tabs",
|
|
1410
|
+
"drawer",
|
|
1411
|
+
"hero-cards"
|
|
1412
|
+
];
|
|
1413
|
+
var DEFAULT_WEB_NAV_RENDER = "tabs";
|
|
1414
|
+
var DEFAULT_MOBILE_NAV_RENDER = "segmented-tabs";
|
|
1415
|
+
var DEFAULT_WEB_GLOBAL_NAV_RENDER = "header-dropdown";
|
|
1416
|
+
var DEFAULT_MOBILE_GLOBAL_NAV_RENDER = "bottom-tabs";
|
|
1417
|
+
var WEB_NAV_RENDER_OPTIONS = [
|
|
1418
|
+
{
|
|
1419
|
+
value: "header-dropdown",
|
|
1420
|
+
label: "Header dropdown",
|
|
1421
|
+
description: "Classic top menu; child pages appear in a dropdown. Best for the global website menu."
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
value: "tabs",
|
|
1425
|
+
label: "Tabs",
|
|
1426
|
+
description: "Show child pages as horizontal tabs. Best for a navigation page with a few children."
|
|
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."
|
|
1437
|
+
}
|
|
1438
|
+
];
|
|
1439
|
+
var MOBILE_NAV_RENDER_OPTIONS = [
|
|
1440
|
+
{
|
|
1441
|
+
value: "segmented-tabs",
|
|
1442
|
+
label: "Segmented tabs",
|
|
1443
|
+
description: "Top segmented control for first-level children. Best for a few child pages."
|
|
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."
|
|
1459
|
+
}
|
|
1460
|
+
];
|
|
1461
|
+
function isWebNavRender(value) {
|
|
1462
|
+
return typeof value === "string" && WEB_NAV_RENDER_VALUES.includes(value);
|
|
1463
|
+
}
|
|
1464
|
+
function isMobileNavRender(value) {
|
|
1465
|
+
return typeof value === "string" && MOBILE_NAV_RENDER_VALUES.includes(value);
|
|
1466
|
+
}
|
|
1467
|
+
function resolveWebNavRender(value, fallback = DEFAULT_WEB_NAV_RENDER) {
|
|
1468
|
+
return isWebNavRender(value) ? value : fallback;
|
|
1469
|
+
}
|
|
1470
|
+
function resolveMobileNavRender(value, fallback = DEFAULT_MOBILE_NAV_RENDER) {
|
|
1471
|
+
return isMobileNavRender(value) ? value : fallback;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// src/navigation/mobileIcons.ts
|
|
1475
|
+
var MOBILE_ICON_SET = [
|
|
1476
|
+
{ name: "House", label: "Home" },
|
|
1477
|
+
{ name: "LayoutDashboard", label: "Dashboard" },
|
|
1478
|
+
{ name: "User", label: "User" },
|
|
1479
|
+
{ name: "Users", label: "Users / Team" },
|
|
1480
|
+
{ name: "Settings", label: "Settings" },
|
|
1481
|
+
{ name: "FileText", label: "Document" },
|
|
1482
|
+
{ name: "Files", label: "Files" },
|
|
1483
|
+
{ name: "Folder", label: "Folder" },
|
|
1484
|
+
{ name: "Info", label: "Info" },
|
|
1485
|
+
{ name: "CircleQuestionMark", label: "Help" },
|
|
1486
|
+
{ name: "Mail", label: "Mail" },
|
|
1487
|
+
{ name: "Phone", label: "Phone" },
|
|
1488
|
+
{ name: "Calendar", label: "Calendar" },
|
|
1489
|
+
{ name: "Bell", label: "Notifications" },
|
|
1490
|
+
{ name: "Search", label: "Search" },
|
|
1491
|
+
{ name: "Star", label: "Star" },
|
|
1492
|
+
{ name: "Heart", label: "Heart" },
|
|
1493
|
+
{ name: "Bookmark", label: "Bookmark" },
|
|
1494
|
+
{ name: "Map", label: "Map" },
|
|
1495
|
+
{ name: "MapPin", label: "Location" },
|
|
1496
|
+
{ name: "Image", label: "Image" },
|
|
1497
|
+
{ name: "Video", label: "Video" },
|
|
1498
|
+
{ name: "Music", label: "Music" },
|
|
1499
|
+
{ name: "ShoppingCart", label: "Shopping cart" },
|
|
1500
|
+
{ name: "CreditCard", label: "Payment" },
|
|
1501
|
+
{ name: "ChartBar", label: "Bar chart" },
|
|
1502
|
+
{ name: "ChartPie", label: "Pie chart" },
|
|
1503
|
+
{ name: "Activity", label: "Activity" },
|
|
1504
|
+
{ name: "Shield", label: "Shield" },
|
|
1505
|
+
{ name: "Lock", label: "Lock" },
|
|
1506
|
+
{ name: "Globe", label: "Globe" },
|
|
1507
|
+
{ name: "Compass", label: "Compass" },
|
|
1508
|
+
{ name: "Flag", label: "Flag" },
|
|
1509
|
+
{ name: "Award", label: "Award" },
|
|
1510
|
+
{ name: "Briefcase", label: "Work" },
|
|
1511
|
+
{ name: "Building", label: "Building" },
|
|
1512
|
+
{ name: "BookOpen", label: "Book" },
|
|
1513
|
+
{ name: "MessageSquare", label: "Messages" },
|
|
1514
|
+
{ name: "ClipboardList", label: "Tasks" },
|
|
1515
|
+
{ name: "CircleCheck", label: "Check" },
|
|
1516
|
+
{ name: "List", label: "List" },
|
|
1517
|
+
{ name: "LayoutGrid", label: "Grid" },
|
|
1518
|
+
{ name: "Menu", label: "Menu" },
|
|
1519
|
+
{ name: "Database", label: "Data" }
|
|
1520
|
+
];
|
|
1521
|
+
var MOBILE_ICON_NAMES = MOBILE_ICON_SET.map((entry) => entry.name);
|
|
1522
|
+
var DEFAULT_MOBILE_ICON = "Circle";
|
|
1523
|
+
function isMobileIconName(value) {
|
|
1524
|
+
return typeof value === "string" && MOBILE_ICON_NAMES.includes(value);
|
|
1525
|
+
}
|
|
1526
|
+
function resolveMobileIcon(value) {
|
|
1527
|
+
return isMobileIconName(value) ? value : DEFAULT_MOBILE_ICON;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// src/navigation/menuVisibility.ts
|
|
1531
|
+
function isMenuVisible(page) {
|
|
1532
|
+
if (page.is_headless) return false;
|
|
1533
|
+
return page.navPosition !== null && page.navPosition !== void 0;
|
|
1534
|
+
}
|
|
1535
|
+
function getMenuVisibleChildren(page) {
|
|
1536
|
+
const children = page.children ?? [];
|
|
1537
|
+
return children.filter(isMenuVisible).sort((a, b) => (a.navPosition ?? 0) - (b.navPosition ?? 0));
|
|
1538
|
+
}
|
|
1539
|
+
function isNavigationPage(page) {
|
|
1540
|
+
return getMenuVisibleChildren(page).length > 0;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1400
1543
|
// src/utils/spacing.ts
|
|
1401
1544
|
var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
|
|
1402
1545
|
function parseSpacing(raw) {
|
|
@@ -1449,6 +1592,10 @@ function transformPageData(apiPage) {
|
|
|
1449
1592
|
is_system: apiPage.is_system !== void 0 ? toBool(apiPage.is_system) : void 0,
|
|
1450
1593
|
title: apiPage.title ?? null,
|
|
1451
1594
|
description: apiPage.description ?? null,
|
|
1595
|
+
icon: apiPage.icon ?? null,
|
|
1596
|
+
mobile_icon: apiPage.mobile_icon ?? null,
|
|
1597
|
+
web_nav_render: apiPage.web_nav_render ?? null,
|
|
1598
|
+
mobile_nav_render: apiPage.mobile_nav_render ?? null,
|
|
1452
1599
|
children: apiPage.children?.map(transformPageData) ?? [],
|
|
1453
1600
|
id_users: apiPage.id_users,
|
|
1454
1601
|
id_pages: apiPage.id_pages ?? id,
|
|
@@ -1476,12 +1623,21 @@ export {
|
|
|
1476
1623
|
COLOR_PALETTE,
|
|
1477
1624
|
COLOR_SCALES,
|
|
1478
1625
|
CONTAINER_SIZE_PX,
|
|
1626
|
+
DEFAULT_MOBILE_GLOBAL_NAV_RENDER,
|
|
1627
|
+
DEFAULT_MOBILE_ICON,
|
|
1628
|
+
DEFAULT_MOBILE_NAV_RENDER,
|
|
1629
|
+
DEFAULT_WEB_GLOBAL_NAV_RENDER,
|
|
1630
|
+
DEFAULT_WEB_NAV_RENDER,
|
|
1479
1631
|
ENDPOINTS,
|
|
1480
1632
|
FONT_SIZE_PX,
|
|
1481
1633
|
FULL_RADIUS_PX,
|
|
1482
1634
|
HEADER_CLIENT_TYPE,
|
|
1483
1635
|
LINE_HEIGHT,
|
|
1484
1636
|
LITERAL_CLASSES,
|
|
1637
|
+
MOBILE_ICON_NAMES,
|
|
1638
|
+
MOBILE_ICON_SET,
|
|
1639
|
+
MOBILE_NAV_RENDER_OPTIONS,
|
|
1640
|
+
MOBILE_NAV_RENDER_VALUES,
|
|
1485
1641
|
MOBILE_PREVIEW_ENDPOINTS,
|
|
1486
1642
|
PERMISSIONS,
|
|
1487
1643
|
PREVIEW_BRIDGE_MESSAGE,
|
|
@@ -1495,6 +1651,8 @@ export {
|
|
|
1495
1651
|
SPACING_VALUES,
|
|
1496
1652
|
STYLE_REGISTRY,
|
|
1497
1653
|
SYSTEM_ENDPOINTS,
|
|
1654
|
+
WEB_NAV_RENDER_OPTIONS,
|
|
1655
|
+
WEB_NAV_RENDER_VALUES,
|
|
1498
1656
|
_resetPluginStyleRegistry,
|
|
1499
1657
|
arePreviewPreferencesEqual,
|
|
1500
1658
|
buildConditionContext,
|
|
@@ -1504,6 +1662,7 @@ export {
|
|
|
1504
1662
|
evaluateCondition,
|
|
1505
1663
|
extendStyleRegistry,
|
|
1506
1664
|
findRemap,
|
|
1665
|
+
getMenuVisibleChildren,
|
|
1507
1666
|
getMergedStyleRegistry,
|
|
1508
1667
|
getPluginStyleRegistry,
|
|
1509
1668
|
getRegistryEntry,
|
|
@@ -1514,11 +1673,16 @@ export {
|
|
|
1514
1673
|
gridSpanToReactNativeColumn,
|
|
1515
1674
|
hasInlineFormatting,
|
|
1516
1675
|
isKnownStyleName,
|
|
1676
|
+
isMenuVisible,
|
|
1677
|
+
isMobileIconName,
|
|
1678
|
+
isMobileNavRender,
|
|
1679
|
+
isNavigationPage,
|
|
1517
1680
|
isPreviewBridgeMessage,
|
|
1518
1681
|
isRegisteredStyleName,
|
|
1519
1682
|
isStyleAllowedOnPage,
|
|
1520
1683
|
isStylePlacementAllowed,
|
|
1521
1684
|
isStyleSupportedOnPlatform,
|
|
1685
|
+
isWebNavRender,
|
|
1522
1686
|
mapAccordionVariantToHeroUiVariant,
|
|
1523
1687
|
mapChipVariantToHeroUiVariant,
|
|
1524
1688
|
mapDividerVariantToReactNative,
|
|
@@ -1540,10 +1704,13 @@ export {
|
|
|
1540
1704
|
resolveAssetSources,
|
|
1541
1705
|
resolveAssetUrl,
|
|
1542
1706
|
resolveMantineVariant,
|
|
1707
|
+
resolveMobileIcon,
|
|
1708
|
+
resolveMobileNavRender,
|
|
1543
1709
|
resolveSharedStyle,
|
|
1544
1710
|
resolveSharedStyleForMobile,
|
|
1545
1711
|
resolveSharedStyleForWeb,
|
|
1546
1712
|
resolveSharedStyleProps,
|
|
1713
|
+
resolveWebNavRender,
|
|
1547
1714
|
setToStylePlatform,
|
|
1548
1715
|
sharedTailwindExtend,
|
|
1549
1716
|
sharedTailwindPreset,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.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/index.ts
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import type { IPageItem } from '../../types/pages';
|
|
7
|
+
import {
|
|
8
|
+
DEFAULT_MOBILE_NAV_RENDER,
|
|
9
|
+
DEFAULT_WEB_NAV_RENDER,
|
|
10
|
+
isMobileNavRender,
|
|
11
|
+
isWebNavRender,
|
|
12
|
+
MOBILE_NAV_RENDER_OPTIONS,
|
|
13
|
+
resolveMobileNavRender,
|
|
14
|
+
resolveWebNavRender,
|
|
15
|
+
WEB_NAV_RENDER_OPTIONS,
|
|
16
|
+
} from '../navRender';
|
|
17
|
+
import { DEFAULT_MOBILE_ICON, isMobileIconName, MOBILE_ICON_SET, resolveMobileIcon } from '../mobileIcons';
|
|
18
|
+
import { getMenuVisibleChildren, isMenuVisible, isNavigationPage } from '../menuVisibility';
|
|
19
|
+
|
|
20
|
+
function page(partial: Partial<IPageItem>): IPageItem {
|
|
21
|
+
return {
|
|
22
|
+
id: 0,
|
|
23
|
+
keyword: 'k',
|
|
24
|
+
url: null,
|
|
25
|
+
parent_page_id: null,
|
|
26
|
+
is_headless: false,
|
|
27
|
+
navPosition: null,
|
|
28
|
+
footerPosition: null,
|
|
29
|
+
...partial,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('navRender', () => {
|
|
34
|
+
it('validates web/mobile render values', () => {
|
|
35
|
+
expect(isWebNavRender('tabs')).toBe(true);
|
|
36
|
+
expect(isWebNavRender('bottom-tabs')).toBe(false); // mobile-only value
|
|
37
|
+
expect(isMobileNavRender('bottom-tabs')).toBe(true);
|
|
38
|
+
expect(isMobileNavRender('header-dropdown')).toBe(false); // web-only value
|
|
39
|
+
expect(isWebNavRender(null)).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('resolves to the value when valid and falls back otherwise', () => {
|
|
43
|
+
expect(resolveWebNavRender('hero-cards')).toBe('hero-cards');
|
|
44
|
+
expect(resolveWebNavRender('nope')).toBe(DEFAULT_WEB_NAV_RENDER);
|
|
45
|
+
expect(resolveWebNavRender(null, 'header-dropdown')).toBe('header-dropdown');
|
|
46
|
+
expect(resolveMobileNavRender('drawer')).toBe('drawer');
|
|
47
|
+
expect(resolveMobileNavRender(undefined)).toBe(DEFAULT_MOBILE_NAV_RENDER);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('option metadata covers every value with a label + description', () => {
|
|
51
|
+
for (const opt of WEB_NAV_RENDER_OPTIONS) {
|
|
52
|
+
expect(isWebNavRender(opt.value)).toBe(true);
|
|
53
|
+
expect(opt.label.length).toBeGreaterThan(0);
|
|
54
|
+
expect(opt.description.length).toBeGreaterThan(0);
|
|
55
|
+
}
|
|
56
|
+
for (const opt of MOBILE_NAV_RENDER_OPTIONS) {
|
|
57
|
+
expect(isMobileNavRender(opt.value)).toBe(true);
|
|
58
|
+
expect(opt.label.length).toBeGreaterThan(0);
|
|
59
|
+
expect(opt.description.length).toBeGreaterThan(0);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('mobileIcons', () => {
|
|
65
|
+
it('exposes a non-empty curated set with unique names', () => {
|
|
66
|
+
expect(MOBILE_ICON_SET.length).toBeGreaterThan(10);
|
|
67
|
+
const names = MOBILE_ICON_SET.map((entry) => entry.name);
|
|
68
|
+
expect(new Set(names).size).toBe(names.length);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('validates and resolves icon names with a default fallback', () => {
|
|
72
|
+
expect(isMobileIconName('House')).toBe(true);
|
|
73
|
+
expect(isMobileIconName('NotAnIcon')).toBe(false);
|
|
74
|
+
expect(resolveMobileIcon('Users')).toBe('Users');
|
|
75
|
+
expect(resolveMobileIcon('NotAnIcon')).toBe(DEFAULT_MOBILE_ICON);
|
|
76
|
+
expect(resolveMobileIcon(null)).toBe(DEFAULT_MOBILE_ICON);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('menuVisibility', () => {
|
|
81
|
+
it('treats a page with a nav position and not headless as a menu page', () => {
|
|
82
|
+
expect(isMenuVisible(page({ navPosition: 1 }))).toBe(true);
|
|
83
|
+
expect(isMenuVisible(page({ navPosition: null }))).toBe(false);
|
|
84
|
+
expect(isMenuVisible(page({ navPosition: 1, is_headless: true }))).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('returns only menu-visible children in nav order', () => {
|
|
88
|
+
const parent = page({
|
|
89
|
+
keyword: 'team',
|
|
90
|
+
navPosition: 1,
|
|
91
|
+
children: [
|
|
92
|
+
page({ keyword: 'b', navPosition: 2 }),
|
|
93
|
+
page({ keyword: 'a', navPosition: 1 }),
|
|
94
|
+
page({ keyword: 'hidden', navPosition: null }),
|
|
95
|
+
page({ keyword: 'headless', navPosition: 3, is_headless: true }),
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
const visible = getMenuVisibleChildren(parent);
|
|
99
|
+
expect(visible.map((child) => child.keyword)).toEqual(['a', 'b']);
|
|
100
|
+
expect(isNavigationPage(parent)).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('a leaf page (no menu-visible children) is not a navigation page', () => {
|
|
104
|
+
expect(isNavigationPage(page({ navPosition: 1, children: [] }))).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Navigation contract: render types + option metadata, the curated mobile icon
|
|
7
|
+
* set, and the shared menu-visibility predicate. Imported by the web frontend
|
|
8
|
+
* (admin selects + renderers) and the mobile app (renderers).
|
|
9
|
+
*/
|
|
10
|
+
export * from './navRender';
|
|
11
|
+
export * from './mobileIcons';
|
|
12
|
+
export * from './menuVisibility';
|