@dnanpm/ui-components 0.6.0 → 0.8.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/dist/components/AccordionItem/AccordionItem.css +16 -16
- package/dist/components/AccordionItem/AccordionItem.module.css.cjs +11 -11
- package/dist/components/AccordionItem/AccordionItem.module.css.js +11 -11
- package/dist/components/Breadcrumb/Breadcrumb.css +9 -9
- package/dist/components/Breadcrumb/Breadcrumb.module.css.cjs +6 -6
- package/dist/components/Breadcrumb/Breadcrumb.module.css.js +6 -6
- package/dist/components/Button/Button.css +32 -30
- package/dist/components/Button/Button.module.css.cjs +11 -11
- package/dist/components/Button/Button.module.css.js +11 -11
- package/dist/components/ButtonCard/ButtonCard.cjs +105 -0
- package/dist/components/ButtonCard/ButtonCard.cjs.map +1 -0
- package/dist/components/ButtonCard/ButtonCard.css +167 -0
- package/dist/components/ButtonCard/ButtonCard.d.ts +3 -0
- package/dist/components/ButtonCard/ButtonCard.d.ts.map +1 -0
- package/dist/components/ButtonCard/ButtonCard.js +105 -0
- package/dist/components/ButtonCard/ButtonCard.js.map +1 -0
- package/dist/components/ButtonCard/ButtonCard.module.css.cjs +18 -0
- package/dist/components/ButtonCard/ButtonCard.module.css.cjs.map +1 -0
- package/dist/components/ButtonCard/ButtonCard.module.css.js +19 -0
- package/dist/components/ButtonCard/ButtonCard.module.css.js.map +1 -0
- package/dist/components/ButtonCard/ButtonCard.types.d.ts +103 -0
- package/dist/components/ButtonCard/ButtonCard.types.d.ts.map +1 -0
- package/dist/components/ButtonCard/index.d.ts +3 -0
- package/dist/components/ButtonCard/index.d.ts.map +1 -0
- package/dist/components/Drawer/Drawer.cjs +101 -0
- package/dist/components/Drawer/Drawer.cjs.map +1 -0
- package/dist/components/Drawer/Drawer.css +219 -0
- package/dist/components/Drawer/Drawer.d.ts +3 -0
- package/dist/components/Drawer/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer/Drawer.js +101 -0
- package/dist/components/Drawer/Drawer.js.map +1 -0
- package/dist/components/Drawer/Drawer.module.css.cjs +37 -0
- package/dist/components/Drawer/Drawer.module.css.cjs.map +1 -0
- package/dist/components/Drawer/Drawer.module.css.js +37 -0
- package/dist/components/Drawer/Drawer.module.css.js.map +1 -0
- package/dist/components/Drawer/Drawer.types.d.ts +63 -0
- package/dist/components/Drawer/Drawer.types.d.ts.map +1 -0
- package/dist/components/Drawer/index.d.ts +3 -0
- package/dist/components/Drawer/index.d.ts.map +1 -0
- package/dist/components/Footer/Footer.cjs +272 -0
- package/dist/components/Footer/Footer.cjs.map +1 -0
- package/dist/components/Footer/Footer.css +473 -0
- package/dist/components/Footer/Footer.d.ts +3 -0
- package/dist/components/Footer/Footer.d.ts.map +1 -0
- package/dist/components/Footer/Footer.js +272 -0
- package/dist/components/Footer/Footer.js.map +1 -0
- package/dist/components/Footer/Footer.module.css.cjs +80 -0
- package/dist/components/Footer/Footer.module.css.cjs.map +1 -0
- package/dist/components/Footer/Footer.module.css.js +80 -0
- package/dist/components/Footer/Footer.module.css.js.map +1 -0
- package/dist/components/Footer/Footer.types.d.ts +128 -0
- package/dist/components/Footer/Footer.types.d.ts.map +1 -0
- package/dist/components/Footer/Footer.utils.cjs +41 -0
- package/dist/components/Footer/Footer.utils.cjs.map +1 -0
- package/dist/components/Footer/Footer.utils.d.ts +13 -0
- package/dist/components/Footer/Footer.utils.d.ts.map +1 -0
- package/dist/components/Footer/Footer.utils.js +41 -0
- package/dist/components/Footer/Footer.utils.js.map +1 -0
- package/dist/components/Footer/assets/app-store-badge.svg.cjs +4 -0
- package/dist/components/Footer/assets/app-store-badge.svg.cjs.map +1 -0
- package/dist/components/Footer/assets/app-store-badge.svg.js +5 -0
- package/dist/components/Footer/assets/app-store-badge.svg.js.map +1 -0
- package/dist/components/Footer/assets/google-play-badge.svg.cjs +4 -0
- package/dist/components/Footer/assets/google-play-badge.svg.cjs.map +1 -0
- package/dist/components/Footer/assets/google-play-badge.svg.js +5 -0
- package/dist/components/Footer/assets/google-play-badge.svg.js.map +1 -0
- package/dist/components/Footer/index.d.ts +3 -0
- package/dist/components/Footer/index.d.ts.map +1 -0
- package/dist/components/FunctionButton/FunctionButton.cjs +34 -0
- package/dist/components/FunctionButton/FunctionButton.cjs.map +1 -0
- package/dist/components/FunctionButton/FunctionButton.css +125 -0
- package/dist/components/FunctionButton/FunctionButton.d.ts +3 -0
- package/dist/components/FunctionButton/FunctionButton.d.ts.map +1 -0
- package/dist/components/FunctionButton/FunctionButton.js +34 -0
- package/dist/components/FunctionButton/FunctionButton.js.map +1 -0
- package/dist/components/FunctionButton/FunctionButton.module.css.cjs +11 -0
- package/dist/components/FunctionButton/FunctionButton.module.css.cjs.map +1 -0
- package/dist/components/FunctionButton/FunctionButton.module.css.js +12 -0
- package/dist/components/FunctionButton/FunctionButton.module.css.js.map +1 -0
- package/dist/components/FunctionButton/FunctionButton.types.d.ts +21 -0
- package/dist/components/FunctionButton/FunctionButton.types.d.ts.map +1 -0
- package/dist/components/FunctionButton/index.d.ts +3 -0
- package/dist/components/FunctionButton/index.d.ts.map +1 -0
- package/dist/components/Hero/Hero.cjs +44 -30
- package/dist/components/Hero/Hero.cjs.map +1 -1
- package/dist/components/Hero/Hero.css +89 -100
- package/dist/components/Hero/Hero.d.ts +1 -1
- package/dist/components/Hero/Hero.d.ts.map +1 -1
- package/dist/components/Hero/Hero.js +45 -31
- package/dist/components/Hero/Hero.js.map +1 -1
- package/dist/components/Hero/Hero.module.css.cjs +17 -20
- package/dist/components/Hero/Hero.module.css.cjs.map +1 -1
- package/dist/components/Hero/Hero.module.css.js +17 -20
- package/dist/components/Hero/Hero.module.css.js.map +1 -1
- package/dist/components/Hero/Hero.types.d.ts +8 -3
- package/dist/components/Hero/Hero.types.d.ts.map +1 -1
- package/dist/components/Hero/Hero.utils.cjs +5 -8
- package/dist/components/Hero/Hero.utils.cjs.map +1 -1
- package/dist/components/Hero/Hero.utils.d.ts +2 -2
- package/dist/components/Hero/Hero.utils.d.ts.map +1 -1
- package/dist/components/Hero/Hero.utils.js +5 -8
- package/dist/components/Hero/Hero.utils.js.map +1 -1
- package/dist/components/IconButton/IconButton.css +31 -32
- package/dist/components/IconButton/IconButton.module.css.cjs +9 -9
- package/dist/components/IconButton/IconButton.module.css.js +9 -9
- package/dist/components/MainNavigation/MainNavigation.cjs +1094 -0
- package/dist/components/MainNavigation/MainNavigation.cjs.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.css +948 -0
- package/dist/components/MainNavigation/MainNavigation.d.ts +3 -0
- package/dist/components/MainNavigation/MainNavigation.d.ts.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.js +1094 -0
- package/dist/components/MainNavigation/MainNavigation.js.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.module.css.cjs +74 -0
- package/dist/components/MainNavigation/MainNavigation.module.css.cjs.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.module.css.js +75 -0
- package/dist/components/MainNavigation/MainNavigation.module.css.js.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.types.d.ts +149 -0
- package/dist/components/MainNavigation/MainNavigation.types.d.ts.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.utils.cjs +168 -0
- package/dist/components/MainNavigation/MainNavigation.utils.cjs.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.utils.d.ts +29 -0
- package/dist/components/MainNavigation/MainNavigation.utils.d.ts.map +1 -0
- package/dist/components/MainNavigation/MainNavigation.utils.js +168 -0
- package/dist/components/MainNavigation/MainNavigation.utils.js.map +1 -0
- package/dist/components/MainNavigation/index.d.ts +3 -0
- package/dist/components/MainNavigation/index.d.ts.map +1 -0
- package/dist/components/Modal/Modal.cjs +101 -0
- package/dist/components/Modal/Modal.cjs.map +1 -0
- package/dist/components/Modal/Modal.css +205 -0
- package/dist/components/Modal/Modal.d.ts +3 -0
- package/dist/components/Modal/Modal.d.ts.map +1 -0
- package/dist/components/Modal/Modal.js +101 -0
- package/dist/components/Modal/Modal.js.map +1 -0
- package/dist/components/Modal/Modal.module.css.cjs +39 -0
- package/dist/components/Modal/Modal.module.css.cjs.map +1 -0
- package/dist/components/Modal/Modal.module.css.js +39 -0
- package/dist/components/Modal/Modal.module.css.js.map +1 -0
- package/dist/components/Modal/Modal.types.d.ts +62 -0
- package/dist/components/Modal/Modal.types.d.ts.map +1 -0
- package/dist/components/Modal/index.d.ts +3 -0
- package/dist/components/Modal/index.d.ts.map +1 -0
- package/dist/components/Modal/useDialogDismissal.cjs +41 -0
- package/dist/components/Modal/useDialogDismissal.cjs.map +1 -0
- package/dist/components/Modal/useDialogDismissal.d.ts +17 -0
- package/dist/components/Modal/useDialogDismissal.d.ts.map +1 -0
- package/dist/components/Modal/useDialogDismissal.js +41 -0
- package/dist/components/Modal/useDialogDismissal.js.map +1 -0
- package/dist/components/Modal/useNativeDialog.cjs +126 -0
- package/dist/components/Modal/useNativeDialog.cjs.map +1 -0
- package/dist/components/Modal/useNativeDialog.d.ts +14 -0
- package/dist/components/Modal/useNativeDialog.d.ts.map +1 -0
- package/dist/components/Modal/useNativeDialog.js +126 -0
- package/dist/components/Modal/useNativeDialog.js.map +1 -0
- package/dist/components/Pictograph/Pictograph.css +69 -57
- package/dist/components/Pictograph/Pictograph.module.css.cjs +11 -11
- package/dist/components/Pictograph/Pictograph.module.css.js +11 -11
- package/dist/components/Pictograph/Pictograph.types.d.ts +2 -2
- package/dist/components/Pictograph/PictographItem.cjs +15 -4
- package/dist/components/Pictograph/PictographItem.cjs.map +1 -1
- package/dist/components/Pictograph/PictographItem.css +26 -23
- package/dist/components/Pictograph/PictographItem.d.ts.map +1 -1
- package/dist/components/Pictograph/PictographItem.js +15 -4
- package/dist/components/Pictograph/PictographItem.js.map +1 -1
- package/dist/components/Pictograph/PictographItem.module.css.cjs +3 -3
- package/dist/components/Pictograph/PictographItem.module.css.js +3 -3
- package/dist/components/Quote/Quote.cjs +32 -0
- package/dist/components/Quote/Quote.cjs.map +1 -0
- package/dist/components/Quote/Quote.css +95 -0
- package/dist/components/Quote/Quote.d.ts +3 -0
- package/dist/components/Quote/Quote.d.ts.map +1 -0
- package/dist/components/Quote/Quote.js +32 -0
- package/dist/components/Quote/Quote.js.map +1 -0
- package/dist/components/Quote/Quote.module.css.cjs +22 -0
- package/dist/components/Quote/Quote.module.css.cjs.map +1 -0
- package/dist/components/Quote/Quote.module.css.js +22 -0
- package/dist/components/Quote/Quote.module.css.js.map +1 -0
- package/dist/components/Quote/Quote.types.d.ts +12 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -0
- package/dist/components/Quote/index.d.ts +3 -0
- package/dist/components/Quote/index.d.ts.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/styles/utils/elevation.module.css.cjs +3 -0
- package/dist/styles/utils/elevation.module.css.cjs.map +1 -1
- package/dist/styles/utils/elevation.module.css.js +4 -1
- package/dist/styles/utils/elevation.module.css.js.map +1 -1
- package/dist/styles/utils/focus.css +21 -13
- package/dist/styles/utils/focus.module.css.cjs +3 -3
- package/dist/styles/utils/focus.module.css.js +3 -3
- package/dist/styles/utils/overlay.css +37 -0
- package/dist/styles/utils/overlay.module.css.cjs +13 -0
- package/dist/styles/utils/overlay.module.css.cjs.map +1 -0
- package/dist/styles/utils/overlay.module.css.js +13 -0
- package/dist/styles/utils/overlay.module.css.js.map +1 -0
- package/dist/styles/utils/text-decoration.css +9 -1
- package/dist/styles/utils/text-decoration.module.css.cjs +5 -2
- package/dist/styles/utils/text-decoration.module.css.cjs.map +1 -1
- package/dist/styles/utils/text-decoration.module.css.js +6 -3
- package/dist/styles/utils/text-decoration.module.css.js.map +1 -1
- package/dist/styles.css +24 -7
- package/package.json +4 -3
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const relativeNavigationBaseUrl = "https://navigation.local";
|
|
4
|
+
const safeLinkProtocols = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
5
|
+
const isDesktopViewportByEnvironment = (windowObject) => {
|
|
6
|
+
if (windowObject == null) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (typeof windowObject.matchMedia === "function") {
|
|
10
|
+
return windowObject.matchMedia("(min-width: 1024px)").matches;
|
|
11
|
+
}
|
|
12
|
+
return windowObject.innerWidth >= 1024;
|
|
13
|
+
};
|
|
14
|
+
const isMobileViewportByEnvironment = (windowObject) => {
|
|
15
|
+
if (windowObject == null) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (typeof windowObject.matchMedia === "function") {
|
|
19
|
+
return windowObject.matchMedia("(max-width: 1023px)").matches;
|
|
20
|
+
}
|
|
21
|
+
return windowObject.innerWidth < 1024;
|
|
22
|
+
};
|
|
23
|
+
const isMobileIosDeviceByEnvironment = (windowObject, navigatorObject) => {
|
|
24
|
+
if (windowObject == null || navigatorObject == null) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const isIOS = /iPad|iPhone|iPod/.test(navigatorObject.userAgent) && !("MSStream" in windowObject);
|
|
28
|
+
return isIOS && windowObject.innerWidth < 768;
|
|
29
|
+
};
|
|
30
|
+
const isExternalTarget = (target) => target === "_blank";
|
|
31
|
+
const isExternalLink = (link) => {
|
|
32
|
+
if (link.external != null) {
|
|
33
|
+
return link.external;
|
|
34
|
+
}
|
|
35
|
+
return isExternalTarget(link.target);
|
|
36
|
+
};
|
|
37
|
+
const getLinkRel = (target) => isExternalTarget(target) ? "noopener noreferrer" : void 0;
|
|
38
|
+
const getLinkTarget = (target) => isExternalTarget(target) ? "_blank" : void 0;
|
|
39
|
+
const normalizePathname = (value) => {
|
|
40
|
+
const path = value.split("?")[0].split("#")[0] || "/";
|
|
41
|
+
const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
|
|
42
|
+
if (withLeadingSlash === "/") {
|
|
43
|
+
return "/";
|
|
44
|
+
}
|
|
45
|
+
return withLeadingSlash.replace(/\/+$/, "");
|
|
46
|
+
};
|
|
47
|
+
const toNavigableHref = (href) => {
|
|
48
|
+
const normalizedHref = href.trim();
|
|
49
|
+
if (normalizedHref === "") {
|
|
50
|
+
return "#";
|
|
51
|
+
}
|
|
52
|
+
const hrefWithProtocol = normalizedHref.toLowerCase().startsWith("www.") ? `https://${normalizedHref}` : normalizedHref;
|
|
53
|
+
if (hrefWithProtocol.startsWith("./") || hrefWithProtocol.startsWith("../")) {
|
|
54
|
+
return hrefWithProtocol;
|
|
55
|
+
}
|
|
56
|
+
if (hrefWithProtocol.startsWith("/") || hrefWithProtocol.startsWith("#") || hrefWithProtocol.startsWith("?")) {
|
|
57
|
+
return hrefWithProtocol;
|
|
58
|
+
}
|
|
59
|
+
const hasScheme = /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(hrefWithProtocol);
|
|
60
|
+
if (!hasScheme) {
|
|
61
|
+
return hrefWithProtocol;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const protocol = new URL(
|
|
65
|
+
hrefWithProtocol,
|
|
66
|
+
relativeNavigationBaseUrl
|
|
67
|
+
).protocol.toLowerCase();
|
|
68
|
+
if (safeLinkProtocols.has(protocol)) {
|
|
69
|
+
return hrefWithProtocol;
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
return "#";
|
|
73
|
+
}
|
|
74
|
+
return "#";
|
|
75
|
+
};
|
|
76
|
+
const toPathname = (href) => {
|
|
77
|
+
if (href == null || href.trim() === "" || href === "#") {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
if (href.startsWith("/")) {
|
|
81
|
+
return normalizePathname(href);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return normalizePathname(new URL(href).pathname);
|
|
85
|
+
} catch {
|
|
86
|
+
return normalizePathname(href);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const matchesPath = (currentPathname, linkPathname) => {
|
|
90
|
+
if (linkPathname === "/") {
|
|
91
|
+
return currentPathname === "/";
|
|
92
|
+
}
|
|
93
|
+
return currentPathname === linkPathname || currentPathname.startsWith(`${linkPathname}/`);
|
|
94
|
+
};
|
|
95
|
+
const isLinkInCurrentPath = (link, currentPathname) => {
|
|
96
|
+
if (link.current) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (isExternalLink(link)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (currentPathname == null) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const linkPathname = toPathname(toNavigableHref(link.href));
|
|
106
|
+
if (linkPathname == null) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return matchesPath(normalizePathname(currentPathname), linkPathname);
|
|
110
|
+
};
|
|
111
|
+
const hasHref = (item) => typeof item.href === "string" && item.href.trim().length > 0;
|
|
112
|
+
const isItemInCurrentPath = (item, currentPathname) => {
|
|
113
|
+
if (hasHref(item) && isLinkInCurrentPath(item, currentPathname)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (item.panel?.columns?.some(
|
|
117
|
+
(column) => column.links.some((link) => isLinkInCurrentPath(link, currentPathname))
|
|
118
|
+
)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return item.panel?.featureLinks?.some((link) => isLinkInCurrentPath(link, currentPathname)) ?? false;
|
|
122
|
+
};
|
|
123
|
+
const isLinkInCurrentPage = (link, currentPathname) => {
|
|
124
|
+
if (link.current) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if (isExternalLink(link)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (currentPathname == null) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
const linkPathname = toPathname(toNavigableHref(link.href));
|
|
134
|
+
if (linkPathname == null) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return normalizePathname(currentPathname) === linkPathname;
|
|
138
|
+
};
|
|
139
|
+
const isRefObject = (target) => typeof target === "object" && target !== null && "current" in target;
|
|
140
|
+
const assignRef = (target, value) => {
|
|
141
|
+
if (target == null) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (typeof target === "function") {
|
|
145
|
+
target(value);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (isRefObject(target)) {
|
|
149
|
+
target.current = value;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
exports.assignRef = assignRef;
|
|
153
|
+
exports.getLinkRel = getLinkRel;
|
|
154
|
+
exports.getLinkTarget = getLinkTarget;
|
|
155
|
+
exports.hasHref = hasHref;
|
|
156
|
+
exports.isDesktopViewportByEnvironment = isDesktopViewportByEnvironment;
|
|
157
|
+
exports.isExternalLink = isExternalLink;
|
|
158
|
+
exports.isExternalTarget = isExternalTarget;
|
|
159
|
+
exports.isItemInCurrentPath = isItemInCurrentPath;
|
|
160
|
+
exports.isLinkInCurrentPage = isLinkInCurrentPage;
|
|
161
|
+
exports.isLinkInCurrentPath = isLinkInCurrentPath;
|
|
162
|
+
exports.isMobileIosDeviceByEnvironment = isMobileIosDeviceByEnvironment;
|
|
163
|
+
exports.isMobileViewportByEnvironment = isMobileViewportByEnvironment;
|
|
164
|
+
exports.matchesPath = matchesPath;
|
|
165
|
+
exports.normalizePathname = normalizePathname;
|
|
166
|
+
exports.toNavigableHref = toNavigableHref;
|
|
167
|
+
exports.toPathname = toPathname;
|
|
168
|
+
//# sourceMappingURL=MainNavigation.utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MainNavigation.utils.cjs","sources":["../../../src/components/MainNavigation/MainNavigation.utils.ts"],"sourcesContent":["import type { Ref } from 'react';\nimport type { MainNavigationItem, MainNavigationLink } from './MainNavigation.types';\n\nconst relativeNavigationBaseUrl = 'https://navigation.local';\nconst safeLinkProtocols = new Set(['http:', 'https:', 'mailto:', 'tel:']);\n\nexport type MainNavigationWindowLike = {\n innerWidth: number;\n matchMedia?: (query: string) => Pick<MediaQueryList, 'matches'>;\n MSStream?: unknown;\n};\n\nexport type MainNavigationNavigatorLike = {\n userAgent: string;\n};\n\nexport const isDesktopViewportByEnvironment = (\n windowObject: MainNavigationWindowLike | undefined,\n) => {\n if (windowObject == null) {\n return false;\n }\n\n if (typeof windowObject.matchMedia === 'function') {\n return windowObject.matchMedia('(min-width: 1024px)').matches;\n }\n\n return windowObject.innerWidth >= 1024;\n};\n\nexport const isMobileViewportByEnvironment = (\n windowObject: MainNavigationWindowLike | undefined,\n) => {\n if (windowObject == null) {\n return false;\n }\n\n if (typeof windowObject.matchMedia === 'function') {\n return windowObject.matchMedia('(max-width: 1023px)').matches;\n }\n\n return windowObject.innerWidth < 1024;\n};\n\nexport const isMobileIosDeviceByEnvironment = (\n windowObject: MainNavigationWindowLike | undefined,\n navigatorObject: MainNavigationNavigatorLike | undefined,\n) => {\n if (windowObject == null || navigatorObject == null) {\n return false;\n }\n\n const isIOS =\n /iPad|iPhone|iPod/.test(navigatorObject.userAgent) && !('MSStream' in windowObject);\n return isIOS && windowObject.innerWidth < 768;\n};\n\nexport const isExternalTarget = (target?: string) => target === '_blank';\n\nexport const isExternalLink = (link: Pick<MainNavigationLink, 'target' | 'external'>) => {\n if (link.external != null) {\n return link.external;\n }\n\n return isExternalTarget(link.target);\n};\n\nexport const getLinkRel = (target?: string) =>\n isExternalTarget(target) ? 'noopener noreferrer' : undefined;\n\nexport const getLinkTarget = (target?: string) => (isExternalTarget(target) ? '_blank' : undefined);\n\nexport const normalizePathname = (value: string) => {\n const path = value.split('?')[0].split('#')[0] || '/';\n const withLeadingSlash = path.startsWith('/') ? path : `/${path}`;\n\n if (withLeadingSlash === '/') {\n return '/';\n }\n\n return withLeadingSlash.replace(/\\/+$/, '');\n};\n\nexport const toNavigableHref = (href: string) => {\n const normalizedHref = href.trim();\n\n if (normalizedHref === '') {\n return '#';\n }\n\n const hrefWithProtocol = normalizedHref.toLowerCase().startsWith('www.')\n ? `https://${normalizedHref}`\n : normalizedHref;\n\n if (hrefWithProtocol.startsWith('./') || hrefWithProtocol.startsWith('../')) {\n return hrefWithProtocol;\n }\n\n if (\n hrefWithProtocol.startsWith('/') ||\n hrefWithProtocol.startsWith('#') ||\n hrefWithProtocol.startsWith('?')\n ) {\n return hrefWithProtocol;\n }\n\n const hasScheme = /^[a-zA-Z][a-zA-Z\\d+\\-.]*:/.test(hrefWithProtocol);\n\n if (!hasScheme) {\n return hrefWithProtocol;\n }\n\n try {\n const protocol = new URL(\n hrefWithProtocol,\n relativeNavigationBaseUrl,\n ).protocol.toLowerCase();\n if (safeLinkProtocols.has(protocol)) {\n return hrefWithProtocol;\n }\n } catch {\n return '#';\n }\n\n return '#';\n};\n\nexport const toPathname = (href?: string) => {\n if (href == null || href.trim() === '' || href === '#') {\n return null;\n }\n\n if (href.startsWith('/')) {\n return normalizePathname(href);\n }\n\n try {\n return normalizePathname(new URL(href).pathname);\n } catch {\n return normalizePathname(href);\n }\n};\n\nexport const matchesPath = (currentPathname: string, linkPathname: string) => {\n if (linkPathname === '/') {\n return currentPathname === '/';\n }\n\n return currentPathname === linkPathname || currentPathname.startsWith(`${linkPathname}/`);\n};\n\nexport const isLinkInCurrentPath = (link: MainNavigationLink, currentPathname?: string) => {\n if (link.current) {\n return true;\n }\n\n if (isExternalLink(link)) {\n return false;\n }\n\n if (currentPathname == null) {\n return false;\n }\n\n const linkPathname = toPathname(toNavigableHref(link.href));\n\n if (linkPathname == null) {\n return false;\n }\n\n return matchesPath(normalizePathname(currentPathname), linkPathname);\n};\n\nexport const hasHref = (item: MainNavigationItem): item is MainNavigationItem & { href: string } =>\n typeof item.href === 'string' && item.href.trim().length > 0;\n\nexport const isItemInCurrentPath = (item: MainNavigationItem, currentPathname?: string) => {\n if (hasHref(item) && isLinkInCurrentPath(item, currentPathname)) {\n return true;\n }\n\n if (\n item.panel?.columns?.some((column) =>\n column.links.some((link) => isLinkInCurrentPath(link, currentPathname)),\n )\n ) {\n return true;\n }\n\n return (\n item.panel?.featureLinks?.some((link) => isLinkInCurrentPath(link, currentPathname)) ??\n false\n );\n};\n\nexport const isLinkInCurrentPage = (link: MainNavigationLink, currentPathname?: string) => {\n if (link.current) {\n return true;\n }\n\n if (isExternalLink(link)) {\n return false;\n }\n\n if (currentPathname == null) {\n return false;\n }\n\n const linkPathname = toPathname(toNavigableHref(link.href));\n\n if (linkPathname == null) {\n return false;\n }\n\n return normalizePathname(currentPathname) === linkPathname;\n};\n\nconst isRefObject = <T>(target: Ref<T>): target is { current: T | null } =>\n typeof target === 'object' && target !== null && 'current' in target;\n\nexport const assignRef = <T>(target: Ref<T> | undefined, value: T | null) => {\n if (target == null) {\n return;\n }\n\n if (typeof target === 'function') {\n target(value);\n return;\n }\n\n if (isRefObject(target)) {\n target.current = value;\n }\n};\n"],"names":[],"mappings":";;AAGA,MAAM,4BAA4B;AAClC,MAAM,wCAAwB,IAAI,CAAC,SAAS,UAAU,WAAW,MAAM,CAAC;AAYjE,MAAM,iCAAiC,CAC1C,iBACC;AACD,MAAI,gBAAgB,MAAM;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,OAAO,aAAa,eAAe,YAAY;AAC/C,WAAO,aAAa,WAAW,qBAAqB,EAAE;AAAA,EAC1D;AAEA,SAAO,aAAa,cAAc;AACtC;AAEO,MAAM,gCAAgC,CACzC,iBACC;AACD,MAAI,gBAAgB,MAAM;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,OAAO,aAAa,eAAe,YAAY;AAC/C,WAAO,aAAa,WAAW,qBAAqB,EAAE;AAAA,EAC1D;AAEA,SAAO,aAAa,aAAa;AACrC;AAEO,MAAM,iCAAiC,CAC1C,cACA,oBACC;AACD,MAAI,gBAAgB,QAAQ,mBAAmB,MAAM;AACjD,WAAO;AAAA,EACX;AAEA,QAAM,QACF,mBAAmB,KAAK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M,eAAe,CAAC;AAAA,EAAA,GAE5E;AACE,WAAO;AAAA,EACX;AAEA,SACI,KAAK,OAAO,cAAc,KAAK,CAAC,SAAS,oBAAoB,MAAM,eAAe,CAAC,KACnF;AAER;AAEO,MAAM,sBAAsB,CAAC,MAA0B,oBAA6B;AACvF,MAAI,KAAK,SAAS;AACd,WAAO;AAAA,EACX;AAEA,MAAI,eAAe,IAAI,GAAG;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,mBAAmB,MAAM;AACzB,WAAO;AAAA,EACX;AAEA,QAAM,eAAe,WAAW,gBAAgB,KAAK,IAAI,CAAC;AAE1D,MAAI,gBAAgB,MAAM;AACtB,WAAO;AAAA,EACX;AAEA,SAAO,kBAAkB,eAAe,MAAM;AAClD;AAEA,MAAM,cAAc,CAAI,WACpB,OAAO,WAAW,YAAY,WAAW,QAAQ,aAAa;AAE3D,MAAM,YAAY,CAAI,QAA4B,UAAoB;AACzE,MAAI,UAAU,MAAM;AAChB;AAAA,EACJ;AAEA,MAAI,OAAO,WAAW,YAAY;AAC9B,WAAO,KAAK;AACZ;AAAA,EACJ;AAEA,MAAI,YAAY,MAAM,GAAG;AACrB,WAAO,UAAU;AAAA,EACrB;AACJ;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Ref } from 'react';
|
|
2
|
+
import { MainNavigationItem, MainNavigationLink } from './MainNavigation.types';
|
|
3
|
+
export type MainNavigationWindowLike = {
|
|
4
|
+
innerWidth: number;
|
|
5
|
+
matchMedia?: (query: string) => Pick<MediaQueryList, 'matches'>;
|
|
6
|
+
MSStream?: unknown;
|
|
7
|
+
};
|
|
8
|
+
export type MainNavigationNavigatorLike = {
|
|
9
|
+
userAgent: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const isDesktopViewportByEnvironment: (windowObject: MainNavigationWindowLike | undefined) => boolean;
|
|
12
|
+
export declare const isMobileViewportByEnvironment: (windowObject: MainNavigationWindowLike | undefined) => boolean;
|
|
13
|
+
export declare const isMobileIosDeviceByEnvironment: (windowObject: MainNavigationWindowLike | undefined, navigatorObject: MainNavigationNavigatorLike | undefined) => boolean;
|
|
14
|
+
export declare const isExternalTarget: (target?: string) => target is "_blank";
|
|
15
|
+
export declare const isExternalLink: (link: Pick<MainNavigationLink, "target" | "external">) => boolean;
|
|
16
|
+
export declare const getLinkRel: (target?: string) => "noopener noreferrer" | undefined;
|
|
17
|
+
export declare const getLinkTarget: (target?: string) => "_blank" | undefined;
|
|
18
|
+
export declare const normalizePathname: (value: string) => string;
|
|
19
|
+
export declare const toNavigableHref: (href: string) => string;
|
|
20
|
+
export declare const toPathname: (href?: string) => string | null;
|
|
21
|
+
export declare const matchesPath: (currentPathname: string, linkPathname: string) => boolean;
|
|
22
|
+
export declare const isLinkInCurrentPath: (link: MainNavigationLink, currentPathname?: string) => boolean;
|
|
23
|
+
export declare const hasHref: (item: MainNavigationItem) => item is MainNavigationItem & {
|
|
24
|
+
href: string;
|
|
25
|
+
};
|
|
26
|
+
export declare const isItemInCurrentPath: (item: MainNavigationItem, currentPathname?: string) => boolean;
|
|
27
|
+
export declare const isLinkInCurrentPage: (link: MainNavigationLink, currentPathname?: string) => boolean;
|
|
28
|
+
export declare const assignRef: <T>(target: Ref<T> | undefined, value: T | null) => void;
|
|
29
|
+
//# sourceMappingURL=MainNavigation.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MainNavigation.utils.d.ts","sourceRoot":"","sources":["../../../src/components/MainNavigation/MainNavigation.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAKrF,MAAM,MAAM,wBAAwB,GAAG;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,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BAAmB,GAAI,MAAM,kBAAkB,EAAE,kBAAkB,MAAM,YAoBrF,CAAC;AAKF,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,OAAO,CAAC,GAAG,IAAI,SAavE,CAAC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
const relativeNavigationBaseUrl = "https://navigation.local";
|
|
2
|
+
const safeLinkProtocols = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]);
|
|
3
|
+
const isDesktopViewportByEnvironment = (windowObject) => {
|
|
4
|
+
if (windowObject == null) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (typeof windowObject.matchMedia === "function") {
|
|
8
|
+
return windowObject.matchMedia("(min-width: 1024px)").matches;
|
|
9
|
+
}
|
|
10
|
+
return windowObject.innerWidth >= 1024;
|
|
11
|
+
};
|
|
12
|
+
const isMobileViewportByEnvironment = (windowObject) => {
|
|
13
|
+
if (windowObject == null) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (typeof windowObject.matchMedia === "function") {
|
|
17
|
+
return windowObject.matchMedia("(max-width: 1023px)").matches;
|
|
18
|
+
}
|
|
19
|
+
return windowObject.innerWidth < 1024;
|
|
20
|
+
};
|
|
21
|
+
const isMobileIosDeviceByEnvironment = (windowObject, navigatorObject) => {
|
|
22
|
+
if (windowObject == null || navigatorObject == null) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const isIOS = /iPad|iPhone|iPod/.test(navigatorObject.userAgent) && !("MSStream" in windowObject);
|
|
26
|
+
return isIOS && windowObject.innerWidth < 768;
|
|
27
|
+
};
|
|
28
|
+
const isExternalTarget = (target) => target === "_blank";
|
|
29
|
+
const isExternalLink = (link) => {
|
|
30
|
+
if (link.external != null) {
|
|
31
|
+
return link.external;
|
|
32
|
+
}
|
|
33
|
+
return isExternalTarget(link.target);
|
|
34
|
+
};
|
|
35
|
+
const getLinkRel = (target) => isExternalTarget(target) ? "noopener noreferrer" : void 0;
|
|
36
|
+
const getLinkTarget = (target) => isExternalTarget(target) ? "_blank" : void 0;
|
|
37
|
+
const normalizePathname = (value) => {
|
|
38
|
+
const path = value.split("?")[0].split("#")[0] || "/";
|
|
39
|
+
const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
|
|
40
|
+
if (withLeadingSlash === "/") {
|
|
41
|
+
return "/";
|
|
42
|
+
}
|
|
43
|
+
return withLeadingSlash.replace(/\/+$/, "");
|
|
44
|
+
};
|
|
45
|
+
const toNavigableHref = (href) => {
|
|
46
|
+
const normalizedHref = href.trim();
|
|
47
|
+
if (normalizedHref === "") {
|
|
48
|
+
return "#";
|
|
49
|
+
}
|
|
50
|
+
const hrefWithProtocol = normalizedHref.toLowerCase().startsWith("www.") ? `https://${normalizedHref}` : normalizedHref;
|
|
51
|
+
if (hrefWithProtocol.startsWith("./") || hrefWithProtocol.startsWith("../")) {
|
|
52
|
+
return hrefWithProtocol;
|
|
53
|
+
}
|
|
54
|
+
if (hrefWithProtocol.startsWith("/") || hrefWithProtocol.startsWith("#") || hrefWithProtocol.startsWith("?")) {
|
|
55
|
+
return hrefWithProtocol;
|
|
56
|
+
}
|
|
57
|
+
const hasScheme = /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(hrefWithProtocol);
|
|
58
|
+
if (!hasScheme) {
|
|
59
|
+
return hrefWithProtocol;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const protocol = new URL(
|
|
63
|
+
hrefWithProtocol,
|
|
64
|
+
relativeNavigationBaseUrl
|
|
65
|
+
).protocol.toLowerCase();
|
|
66
|
+
if (safeLinkProtocols.has(protocol)) {
|
|
67
|
+
return hrefWithProtocol;
|
|
68
|
+
}
|
|
69
|
+
} catch {
|
|
70
|
+
return "#";
|
|
71
|
+
}
|
|
72
|
+
return "#";
|
|
73
|
+
};
|
|
74
|
+
const toPathname = (href) => {
|
|
75
|
+
if (href == null || href.trim() === "" || href === "#") {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (href.startsWith("/")) {
|
|
79
|
+
return normalizePathname(href);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return normalizePathname(new URL(href).pathname);
|
|
83
|
+
} catch {
|
|
84
|
+
return normalizePathname(href);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const matchesPath = (currentPathname, linkPathname) => {
|
|
88
|
+
if (linkPathname === "/") {
|
|
89
|
+
return currentPathname === "/";
|
|
90
|
+
}
|
|
91
|
+
return currentPathname === linkPathname || currentPathname.startsWith(`${linkPathname}/`);
|
|
92
|
+
};
|
|
93
|
+
const isLinkInCurrentPath = (link, currentPathname) => {
|
|
94
|
+
if (link.current) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (isExternalLink(link)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (currentPathname == null) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const linkPathname = toPathname(toNavigableHref(link.href));
|
|
104
|
+
if (linkPathname == null) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return matchesPath(normalizePathname(currentPathname), linkPathname);
|
|
108
|
+
};
|
|
109
|
+
const hasHref = (item) => typeof item.href === "string" && item.href.trim().length > 0;
|
|
110
|
+
const isItemInCurrentPath = (item, currentPathname) => {
|
|
111
|
+
if (hasHref(item) && isLinkInCurrentPath(item, currentPathname)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
if (item.panel?.columns?.some(
|
|
115
|
+
(column) => column.links.some((link) => isLinkInCurrentPath(link, currentPathname))
|
|
116
|
+
)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
return item.panel?.featureLinks?.some((link) => isLinkInCurrentPath(link, currentPathname)) ?? false;
|
|
120
|
+
};
|
|
121
|
+
const isLinkInCurrentPage = (link, currentPathname) => {
|
|
122
|
+
if (link.current) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if (isExternalLink(link)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (currentPathname == null) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const linkPathname = toPathname(toNavigableHref(link.href));
|
|
132
|
+
if (linkPathname == null) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return normalizePathname(currentPathname) === linkPathname;
|
|
136
|
+
};
|
|
137
|
+
const isRefObject = (target) => typeof target === "object" && target !== null && "current" in target;
|
|
138
|
+
const assignRef = (target, value) => {
|
|
139
|
+
if (target == null) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (typeof target === "function") {
|
|
143
|
+
target(value);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (isRefObject(target)) {
|
|
147
|
+
target.current = value;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
export {
|
|
151
|
+
assignRef,
|
|
152
|
+
getLinkRel,
|
|
153
|
+
getLinkTarget,
|
|
154
|
+
hasHref,
|
|
155
|
+
isDesktopViewportByEnvironment,
|
|
156
|
+
isExternalLink,
|
|
157
|
+
isExternalTarget,
|
|
158
|
+
isItemInCurrentPath,
|
|
159
|
+
isLinkInCurrentPage,
|
|
160
|
+
isLinkInCurrentPath,
|
|
161
|
+
isMobileIosDeviceByEnvironment,
|
|
162
|
+
isMobileViewportByEnvironment,
|
|
163
|
+
matchesPath,
|
|
164
|
+
normalizePathname,
|
|
165
|
+
toNavigableHref,
|
|
166
|
+
toPathname
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=MainNavigation.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MainNavigation.utils.js","sources":["../../../src/components/MainNavigation/MainNavigation.utils.ts"],"sourcesContent":["import type { Ref } from 'react';\nimport type { MainNavigationItem, MainNavigationLink } from './MainNavigation.types';\n\nconst relativeNavigationBaseUrl = 'https://navigation.local';\nconst safeLinkProtocols = new Set(['http:', 'https:', 'mailto:', 'tel:']);\n\nexport type MainNavigationWindowLike = {\n innerWidth: number;\n matchMedia?: (query: string) => Pick<MediaQueryList, 'matches'>;\n MSStream?: unknown;\n};\n\nexport type MainNavigationNavigatorLike = {\n userAgent: string;\n};\n\nexport const isDesktopViewportByEnvironment = (\n windowObject: MainNavigationWindowLike | undefined,\n) => {\n if (windowObject == null) {\n return false;\n }\n\n if (typeof windowObject.matchMedia === 'function') {\n return windowObject.matchMedia('(min-width: 1024px)').matches;\n }\n\n return windowObject.innerWidth >= 1024;\n};\n\nexport const isMobileViewportByEnvironment = (\n windowObject: MainNavigationWindowLike | undefined,\n) => {\n if (windowObject == null) {\n return false;\n }\n\n if (typeof windowObject.matchMedia === 'function') {\n return windowObject.matchMedia('(max-width: 1023px)').matches;\n }\n\n return windowObject.innerWidth < 1024;\n};\n\nexport const isMobileIosDeviceByEnvironment = (\n windowObject: MainNavigationWindowLike | undefined,\n navigatorObject: MainNavigationNavigatorLike | undefined,\n) => {\n if (windowObject == null || navigatorObject == null) {\n return false;\n }\n\n const isIOS =\n /iPad|iPhone|iPod/.test(navigatorObject.userAgent) && !('MSStream' in windowObject);\n return isIOS && windowObject.innerWidth < 768;\n};\n\nexport const isExternalTarget = (target?: string) => target === '_blank';\n\nexport const isExternalLink = (link: Pick<MainNavigationLink, 'target' | 'external'>) => {\n if (link.external != null) {\n return link.external;\n }\n\n return isExternalTarget(link.target);\n};\n\nexport const getLinkRel = (target?: string) =>\n isExternalTarget(target) ? 'noopener noreferrer' : undefined;\n\nexport const getLinkTarget = (target?: string) => (isExternalTarget(target) ? '_blank' : undefined);\n\nexport const normalizePathname = (value: string) => {\n const path = value.split('?')[0].split('#')[0] || '/';\n const withLeadingSlash = path.startsWith('/') ? path : `/${path}`;\n\n if (withLeadingSlash === '/') {\n return '/';\n }\n\n return withLeadingSlash.replace(/\\/+$/, '');\n};\n\nexport const toNavigableHref = (href: string) => {\n const normalizedHref = href.trim();\n\n if (normalizedHref === '') {\n return '#';\n }\n\n const hrefWithProtocol = normalizedHref.toLowerCase().startsWith('www.')\n ? `https://${normalizedHref}`\n : normalizedHref;\n\n if (hrefWithProtocol.startsWith('./') || hrefWithProtocol.startsWith('../')) {\n return hrefWithProtocol;\n }\n\n if (\n hrefWithProtocol.startsWith('/') ||\n hrefWithProtocol.startsWith('#') ||\n hrefWithProtocol.startsWith('?')\n ) {\n return hrefWithProtocol;\n }\n\n const hasScheme = /^[a-zA-Z][a-zA-Z\\d+\\-.]*:/.test(hrefWithProtocol);\n\n if (!hasScheme) {\n return hrefWithProtocol;\n }\n\n try {\n const protocol = new URL(\n hrefWithProtocol,\n relativeNavigationBaseUrl,\n ).protocol.toLowerCase();\n if (safeLinkProtocols.has(protocol)) {\n return hrefWithProtocol;\n }\n } catch {\n return '#';\n }\n\n return '#';\n};\n\nexport const toPathname = (href?: string) => {\n if (href == null || href.trim() === '' || href === '#') {\n return null;\n }\n\n if (href.startsWith('/')) {\n return normalizePathname(href);\n }\n\n try {\n return normalizePathname(new URL(href).pathname);\n } catch {\n return normalizePathname(href);\n }\n};\n\nexport const matchesPath = (currentPathname: string, linkPathname: string) => {\n if (linkPathname === '/') {\n return currentPathname === '/';\n }\n\n return currentPathname === linkPathname || currentPathname.startsWith(`${linkPathname}/`);\n};\n\nexport const isLinkInCurrentPath = (link: MainNavigationLink, currentPathname?: string) => {\n if (link.current) {\n return true;\n }\n\n if (isExternalLink(link)) {\n return false;\n }\n\n if (currentPathname == null) {\n return false;\n }\n\n const linkPathname = toPathname(toNavigableHref(link.href));\n\n if (linkPathname == null) {\n return false;\n }\n\n return matchesPath(normalizePathname(currentPathname), linkPathname);\n};\n\nexport const hasHref = (item: MainNavigationItem): item is MainNavigationItem & { href: string } =>\n typeof item.href === 'string' && item.href.trim().length > 0;\n\nexport const isItemInCurrentPath = (item: MainNavigationItem, currentPathname?: string) => {\n if (hasHref(item) && isLinkInCurrentPath(item, currentPathname)) {\n return true;\n }\n\n if (\n item.panel?.columns?.some((column) =>\n column.links.some((link) => isLinkInCurrentPath(link, currentPathname)),\n )\n ) {\n return true;\n }\n\n return (\n item.panel?.featureLinks?.some((link) => isLinkInCurrentPath(link, currentPathname)) ??\n false\n );\n};\n\nexport const isLinkInCurrentPage = (link: MainNavigationLink, currentPathname?: string) => {\n if (link.current) {\n return true;\n }\n\n if (isExternalLink(link)) {\n return false;\n }\n\n if (currentPathname == null) {\n return false;\n }\n\n const linkPathname = toPathname(toNavigableHref(link.href));\n\n if (linkPathname == null) {\n return false;\n }\n\n return normalizePathname(currentPathname) === linkPathname;\n};\n\nconst isRefObject = <T>(target: Ref<T>): target is { current: T | null } =>\n typeof target === 'object' && target !== null && 'current' in target;\n\nexport const assignRef = <T>(target: Ref<T> | undefined, value: T | null) => {\n if (target == null) {\n return;\n }\n\n if (typeof target === 'function') {\n target(value);\n return;\n }\n\n if (isRefObject(target)) {\n target.current = value;\n }\n};\n"],"names":[],"mappings":"AAGA,MAAM,4BAA4B;AAClC,MAAM,wCAAwB,IAAI,CAAC,SAAS,UAAU,WAAW,MAAM,CAAC;AAYjE,MAAM,iCAAiC,CAC1C,iBACC;AACD,MAAI,gBAAgB,MAAM;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,OAAO,aAAa,eAAe,YAAY;AAC/C,WAAO,aAAa,WAAW,qBAAqB,EAAE;AAAA,EAC1D;AAEA,SAAO,aAAa,cAAc;AACtC;AAEO,MAAM,gCAAgC,CACzC,iBACC;AACD,MAAI,gBAAgB,MAAM;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,OAAO,aAAa,eAAe,YAAY;AAC/C,WAAO,aAAa,WAAW,qBAAqB,EAAE;AAAA,EAC1D;AAEA,SAAO,aAAa,aAAa;AACrC;AAEO,MAAM,iCAAiC,CAC1C,cACA,oBACC;AACD,MAAI,gBAAgB,QAAQ,mBAAmB,MAAM;AACjD,WAAO;AAAA,EACX;AAEA,QAA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C,SAAS,oBAAoB,MAAM,eAAe,CAAC;AAAA,EAAA,GAE5E;AACE,WAAO;AAAA,EACX;AAEA,SACI,KAAK,OAAO,cAAc,KAAK,CAAC,SAAS,oBAAoB,MAAM,eAAe,CAAC,KACnF;AAER;AAEO,MAAM,sBAAsB,CAAC,MAA0B,oBAA6B;AACvF,MAAI,KAAK,SAAS;AACd,WAAO;AAAA,EACX;AAEA,MAAI,eAAe,IAAI,GAAG;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,mBAAmB,MAAM;AACzB,WAAO;AAAA,EACX;AAEA,QAAM,eAAe,WAAW,gBAAgB,KAAK,IAAI,CAAC;AAE1D,MAAI,gBAAgB,MAAM;AACtB,WAAO;AAAA,EACX;AAEA,SAAO,kBAAkB,eAAe,MAAM;AAClD;AAEA,MAAM,cAAc,CAAI,WACpB,OAAO,WAAW,YAAY,WAAW,QAAQ,aAAa;AAE3D,MAAM,YAAY,CAAI,QAA4B,UAAoB;AACzE,MAAI,UAAU,MAAM;AAChB;AAAA,EACJ;AAEA,MAAI,OAAO,WAAW,YAAY;AAC9B,WAAO,KAAK;AACZ;AAAA,EACJ;AAEA,MAAI,YAAY,MAAM,GAAG;AACrB,WAAO,UAAU;AAAA,EACrB;AACJ;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { MainNavigation } from './MainNavigation';
|
|
2
|
+
export type { MainNavigationItem, MainNavigationLink, MainNavigationOrganizationLink, MainNavigationPanel, MainNavigationProps, MainNavigationSubmenuColumn, } from './MainNavigation.types';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/MainNavigation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACR,kBAAkB,EAClB,kBAAkB,EAClB,8BAA8B,EAC9B,mBAAmB,EACnB,mBAAmB,EACnB,2BAA2B,GAC9B,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const react = require("react");
|
|
5
|
+
const icons = require("@dnanpm/icons");
|
|
6
|
+
const elevation_module = require("../../styles/utils/elevation.module.css.cjs");
|
|
7
|
+
const focus_module = require("../../styles/utils/focus.module.css.cjs");
|
|
8
|
+
const Modal_module = require("./Modal.module.css.cjs");
|
|
9
|
+
const useDialogDismissal = require("./useDialogDismissal.cjs");
|
|
10
|
+
const useNativeDialog = require("./useNativeDialog.cjs");
|
|
11
|
+
const cn = require("../../utils/cn/cn.cjs");
|
|
12
|
+
const Modal = ({
|
|
13
|
+
open,
|
|
14
|
+
onOpenChange,
|
|
15
|
+
title,
|
|
16
|
+
description,
|
|
17
|
+
children,
|
|
18
|
+
footer,
|
|
19
|
+
size = "medium",
|
|
20
|
+
headerStyle = "light",
|
|
21
|
+
fixedTitle = false,
|
|
22
|
+
alignToTop = false,
|
|
23
|
+
disableCloseOptions = false,
|
|
24
|
+
closeLabel = "Sulje dialogi",
|
|
25
|
+
keepMounted = false,
|
|
26
|
+
className,
|
|
27
|
+
ref,
|
|
28
|
+
onKeyDown,
|
|
29
|
+
onClick,
|
|
30
|
+
onPointerDown,
|
|
31
|
+
"aria-label": ariaLabel,
|
|
32
|
+
"aria-labelledby": ariaLabelledBy,
|
|
33
|
+
"aria-describedby": ariaDescribedBy,
|
|
34
|
+
...props
|
|
35
|
+
}) => {
|
|
36
|
+
const titleId = react.useId();
|
|
37
|
+
const descriptionId = react.useId();
|
|
38
|
+
const { dialogRef, close, phase, isPresent } = useNativeDialog.useNativeDialog({
|
|
39
|
+
open: open ?? false,
|
|
40
|
+
keepMounted,
|
|
41
|
+
onOpenChange
|
|
42
|
+
});
|
|
43
|
+
const describedBy = [description ? descriptionId : void 0, ariaDescribedBy].filter(Boolean).join(" ") || void 0;
|
|
44
|
+
const dialogDismissalProps = useDialogDismissal.useDialogDismissal({
|
|
45
|
+
close,
|
|
46
|
+
disableCloseOptions,
|
|
47
|
+
onClick,
|
|
48
|
+
onKeyDown,
|
|
49
|
+
onPointerDown
|
|
50
|
+
});
|
|
51
|
+
if (!isPresent) return null;
|
|
52
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
53
|
+
"dialog",
|
|
54
|
+
{
|
|
55
|
+
...props,
|
|
56
|
+
ref: (node) => {
|
|
57
|
+
dialogRef.current = node;
|
|
58
|
+
if (typeof ref === "function") ref(node);
|
|
59
|
+
else if (ref) ref.current = node;
|
|
60
|
+
},
|
|
61
|
+
className: cn.cn(
|
|
62
|
+
Modal_module.default.modal,
|
|
63
|
+
elevation_module.default.elevationHigh,
|
|
64
|
+
Modal_module.default[`modal--${size}`],
|
|
65
|
+
Modal_module.default[`modal--${headerStyle}`],
|
|
66
|
+
{ [Modal_module.default["modal--fixed-title"]]: fixedTitle },
|
|
67
|
+
{ [Modal_module.default["modal--align-top"]]: alignToTop },
|
|
68
|
+
{ [Modal_module.default["modal--opening"]]: phase !== "closing" },
|
|
69
|
+
{ [Modal_module.default["modal--closing"]]: phase === "closing" },
|
|
70
|
+
className
|
|
71
|
+
),
|
|
72
|
+
"aria-label": ariaLabel,
|
|
73
|
+
"aria-labelledby": ariaLabelledBy ?? (!ariaLabel && title ? titleId : void 0),
|
|
74
|
+
"aria-describedby": describedBy,
|
|
75
|
+
...dialogDismissalProps,
|
|
76
|
+
children: [
|
|
77
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: Modal_module.default.modal__container, children: [
|
|
78
|
+
!disableCloseOptions && /* @__PURE__ */ jsxRuntime.jsx(
|
|
79
|
+
"button",
|
|
80
|
+
{
|
|
81
|
+
type: "button",
|
|
82
|
+
className: cn.cn(Modal_module.default.modal__close, focus_module.default.focusable),
|
|
83
|
+
"aria-label": closeLabel,
|
|
84
|
+
"data-dialog-autofocus": "true",
|
|
85
|
+
onClick: close,
|
|
86
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Close, { "aria-hidden": "true" })
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
(title || description) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: Modal_module.default.modal__title, children: [
|
|
90
|
+
title && /* @__PURE__ */ jsxRuntime.jsx("h2", { id: titleId, className: Modal_module.default.modal__heading, children: title }),
|
|
91
|
+
description && /* @__PURE__ */ jsxRuntime.jsx("div", { id: descriptionId, className: Modal_module.default.modal__description, children: description })
|
|
92
|
+
] }),
|
|
93
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: Modal_module.default.modal__content, children })
|
|
94
|
+
] }),
|
|
95
|
+
footer && /* @__PURE__ */ jsxRuntime.jsx("div", { className: Modal_module.default["modal__bottom-bar"], children: footer })
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
exports.Modal = Modal;
|
|
101
|
+
//# sourceMappingURL=Modal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.cjs","sources":["../../../src/components/Modal/Modal.tsx"],"sourcesContent":["import { useId } from 'react';\nimport { Close } from '@dnanpm/icons';\nimport { cn } from '../../utils/cn';\nimport elevationStyles from '../../styles/utils/elevation.module.css';\nimport focusStyles from '../../styles/utils/focus.module.css';\nimport styles from './Modal.module.css';\nimport { useDialogDismissal } from './useDialogDismissal';\nimport { useNativeDialog } from './useNativeDialog';\nimport type { ModalProps } from './Modal.types';\n\nexport const Modal = ({\n open,\n onOpenChange,\n title,\n description,\n children,\n footer,\n size = 'medium',\n headerStyle = 'light',\n fixedTitle = false,\n alignToTop = false,\n disableCloseOptions = false,\n closeLabel = 'Sulje dialogi',\n keepMounted = false,\n className,\n ref,\n onKeyDown,\n onClick,\n onPointerDown,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n ...props\n}: ModalProps) => {\n const titleId = useId();\n const descriptionId = useId();\n const { dialogRef, close, phase, isPresent } = useNativeDialog({\n open: open ?? false,\n keepMounted,\n onOpenChange,\n });\n const describedBy =\n [description ? descriptionId : undefined, ariaDescribedBy].filter(Boolean).join(' ') ||\n undefined;\n const dialogDismissalProps = useDialogDismissal({\n close,\n disableCloseOptions,\n onClick,\n onKeyDown,\n onPointerDown,\n });\n\n if (!isPresent) return null;\n\n return (\n <dialog\n {...props}\n ref={(node) => {\n dialogRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn(\n styles.modal,\n elevationStyles.elevationHigh,\n styles[`modal--${size}`],\n styles[`modal--${headerStyle}`],\n { [styles['modal--fixed-title']]: fixedTitle },\n { [styles['modal--align-top']]: alignToTop },\n { [styles['modal--opening']]: phase !== 'closing' },\n { [styles['modal--closing']]: phase === 'closing' },\n className,\n )}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy ?? (!ariaLabel && title ? titleId : undefined)}\n aria-describedby={describedBy}\n {...dialogDismissalProps}\n >\n <div className={styles.modal__container}>\n {!disableCloseOptions && (\n <button\n type=\"button\"\n className={cn(styles.modal__close, focusStyles.focusable)}\n aria-label={closeLabel}\n data-dialog-autofocus=\"true\"\n onClick={close}\n >\n <Close aria-hidden=\"true\" />\n </button>\n )}\n {(title || description) && (\n <div className={styles.modal__title}>\n {title && (\n <h2 id={titleId} className={styles.modal__heading}>\n {title}\n </h2>\n )}\n {description && (\n <div id={descriptionId} className={styles.modal__description}>\n {description}\n </div>\n )}\n </div>\n )}\n <div className={styles.modal__content}>{children}</div>\n </div>\n {footer && <div className={styles['modal__bottom-bar']}>{footer}</div>}\n </dialog>\n );\n};\n"],"names":["useId","useNativeDialog","useDialogDismissal","jsxs","cn","styles","elevationStyles","jsx","focusStyles","Close"],"mappings":";;;;;;;;;;;AAUO,MAAM,QAAQ,CAAC;AAAA,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