@brillout/docpress 0.8.11 → 0.8.13-commit-8740149
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/Layout.tsx +35 -23
- package/MenuModal.tsx +23 -11
- package/config/resolveHeadingsData.ts +2 -6
- package/css/colorize-on-hover.css +10 -1
- package/dist/Layout.d.ts +11 -0
- package/dist/Layout.js +243 -0
- package/dist/Links.d.ts +6 -0
- package/dist/Links.js +58 -0
- package/dist/MenuModal.d.ts +9 -0
- package/dist/MenuModal.js +131 -0
- package/dist/autoScrollNav.d.ts +3 -0
- package/dist/autoScrollNav.js +35 -0
- package/dist/components/EditPageNote.d.ts +7 -0
- package/dist/components/EditPageNote.js +11 -0
- package/dist/config/resolveHeadingsData.d.ts +0 -1
- package/dist/config/resolveHeadingsData.js +2 -6
- package/dist/config/resolvePageContext.d.ts +0 -1
- package/dist/docsearch/SearchLink.d.ts +4 -0
- package/dist/docsearch/SearchLink.js +25 -0
- package/dist/docsearch/toggleDocsearchModal.d.ts +4 -0
- package/dist/docsearch/toggleDocsearchModal.js +26 -0
- package/dist/navigation/Navigation.d.ts +2 -1
- package/dist/navigation/Navigation.js +69 -38
- package/dist/renderer/determineColumnEntries.d.ts +3 -0
- package/dist/renderer/{getStyleColumnLayout.js → determineColumnEntries.js} +16 -64
- package/dist/utils/PassTrough.d.ts +3 -0
- package/dist/utils/PassTrough.js +6 -0
- package/dist/utils/getViewportWidth.d.ts +1 -0
- package/dist/utils/getViewportWidth.js +4 -0
- package/docsearch/SearchLink.tsx +3 -12
- package/navigation/Navigation.css +2 -1
- package/navigation/Navigation.tsx +94 -63
- package/package.json +1 -1
- package/renderer/{getStyleColumnLayout.ts → determineColumnEntries.ts} +20 -90
- package/renderer/onRenderHtml.tsx +0 -4
- package/utils/getViewportWidth.ts +4 -0
- package/dist/renderer/getStyleColumnLayout.d.ts +0 -7
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
+
return cooked;
|
|
4
|
+
};
|
|
5
|
+
export { MenuModal };
|
|
6
|
+
export { toggleMenuModal };
|
|
7
|
+
export { openMenuModal };
|
|
8
|
+
export { closeMenuModal };
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import { usePageContext } from './renderer/usePageContext';
|
|
11
|
+
import { NavigationContent } from './navigation/Navigation';
|
|
12
|
+
import { css } from './utils/css';
|
|
13
|
+
import { containerQueryMobile } from './Layout';
|
|
14
|
+
import { Links } from './Links';
|
|
15
|
+
import { isBrowser } from './utils/isBrowser';
|
|
16
|
+
import { getViewportWidth } from './utils/getViewportWidth';
|
|
17
|
+
initCloseListeners();
|
|
18
|
+
function MenuModal() {
|
|
19
|
+
return (React.createElement(React.Fragment, null,
|
|
20
|
+
React.createElement("style", null, getStyle()),
|
|
21
|
+
React.createElement("div", { id: "menu-modal", className: "link-hover-animation", style: {
|
|
22
|
+
position: 'fixed',
|
|
23
|
+
width: '100%',
|
|
24
|
+
/* Do this once Firefox supports `dvh`: https://caniuse.com/?search=dvh
|
|
25
|
+
* - Then also replace all `vh` values with `dvh` values.
|
|
26
|
+
* - https://stackoverflow.com/questions/37112218/css3-100vh-not-constant-in-mobile-browser/72245072#72245072
|
|
27
|
+
height: '100dh',
|
|
28
|
+
/*/
|
|
29
|
+
height: 'calc(100vh - var(--top-nav-height))',
|
|
30
|
+
//*/
|
|
31
|
+
top: 'calc(var(--top-nav-height) + var(--block-margin))',
|
|
32
|
+
left: 0,
|
|
33
|
+
zIndex: 9999,
|
|
34
|
+
overflow: 'scroll',
|
|
35
|
+
background: '#eaeaea',
|
|
36
|
+
// background: '#ededef',
|
|
37
|
+
// boxShadow: 'rgba(0, 0, 0, 0.35) 0 0 13px 3px',
|
|
38
|
+
// boxShadow: 'rgba(6, 24, 44, 0.4) 0px 0px 0px 2px, rgba(6, 24, 44, 0.65) 0px 4px 13px -1px, rgba(255, 255, 255, 0.08) 0px 1px 0px inset',
|
|
39
|
+
boxShadow: 'rgb(6 24 44 / 8%) 0px 0px 0px 3px, rgba(6, 24, 44, 0.65) 0px 4px 13px -1px, rgba(255, 255, 255, 0.28) 0px 1px 0px inset',
|
|
40
|
+
transition: 'opacity 0.3s ease-in-out',
|
|
41
|
+
}, onMouseEnter: openMenuModal, onMouseLeave: closeMenuModal },
|
|
42
|
+
React.createElement("div", { style: {
|
|
43
|
+
// Place <LinksBottom /> to the bottom
|
|
44
|
+
display: 'flex',
|
|
45
|
+
flexDirection: 'column',
|
|
46
|
+
minHeight: 'calc(100vh - var(--top-nav-height))',
|
|
47
|
+
justifyContent: 'space-between',
|
|
48
|
+
// We don't set `container` to parent beacuse of a Chrome bug (showing a blank <MenuModal>)
|
|
49
|
+
containerType: 'inline-size',
|
|
50
|
+
} },
|
|
51
|
+
React.createElement(Nav, null)))));
|
|
52
|
+
}
|
|
53
|
+
function Nav() {
|
|
54
|
+
var pageContext = usePageContext();
|
|
55
|
+
var navItems = pageContext.navItemsAll;
|
|
56
|
+
return React.createElement(NavigationContent, { columnLayout: true, navItems: navItems });
|
|
57
|
+
}
|
|
58
|
+
// TODO: remove
|
|
59
|
+
function LinksBottom() {
|
|
60
|
+
return (React.createElement("div", { style: {
|
|
61
|
+
display: 'flex',
|
|
62
|
+
justifyContent: 'center',
|
|
63
|
+
} },
|
|
64
|
+
React.createElement(Links, { style: { height: 70 } })));
|
|
65
|
+
}
|
|
66
|
+
function getStyle() {
|
|
67
|
+
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\nhtml:not(.menu-modal-show) #menu-modal {\n opacity: 0;\n pointer-events:none;\n}\n// disable scroll of main view\nhtml.menu-modal-show {\n overflow: hidden !important;\n}\n@container(min-width: ", "px) {\n #menu-modal .nav-item-level-3 {\n display: none;\n }\n}\n"], ["\nhtml:not(.menu-modal-show) #menu-modal {\n opacity: 0;\n pointer-events:none;\n}\n// disable scroll of main view\nhtml.menu-modal-show {\n overflow: hidden !important;\n}\n@container(min-width: ", "px) {\n #menu-modal .nav-item-level-3 {\n display: none;\n }\n}\n"])), containerQueryMobile);
|
|
68
|
+
}
|
|
69
|
+
// TODO: remove?
|
|
70
|
+
function CloseButton() {
|
|
71
|
+
return (React.createElement("div", { onClick: toggleMenuModal, style: { position: 'fixed', top: 0, right: 0, zIndex: 10, padding: 11, cursor: 'pointer' }, "aria-label": 'Escape\nCtrl\xa0+\xa0M', "data-label-shift": true },
|
|
72
|
+
React.createElement("svg", { width: "48.855", height: "48.855", version: "1.1", viewBox: "0 0 22.901 22.901", xmlns: "http://www.w3.org/2000/svg" },
|
|
73
|
+
React.createElement("circle", { cx: "11.45", cy: "11.45", r: "10.607", fill: "#ececec", stroke: "#666", strokeDashoffset: "251.44", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "1.6875", style: { paintOrder: 'normal' } }),
|
|
74
|
+
React.createElement("path", { d: "m7.5904 6.2204 3.86 3.86 3.84-3.84a0.92 0.92 0 0 1 0.66-0.29 1 1 0 0 1 1 1 0.9 0.9 0 0 1-0.27 0.66l-3.89 3.84 3.89 3.89a0.9 0.9 0 0 1 0.27 0.61 1 1 0 0 1-1 1 0.92 0.92 0 0 1-0.69-0.27l-3.81-3.86-3.85 3.85a0.92 0.92 0 0 1-0.65 0.28 1 1 0 0 1-1-1 0.9 0.9 0 0 1 0.27-0.66l3.89-3.84-3.89-3.89a0.9 0.9 0 0 1-0.27-0.61 1 1 0 0 1 1-1c0.24 3e-3 0.47 0.1 0.64 0.27z", fill: "#666", stroke: "#666", strokeWidth: ".11719" }))));
|
|
75
|
+
}
|
|
76
|
+
function toggleMenuModal() {
|
|
77
|
+
document.documentElement.classList.toggle('menu-modal-show');
|
|
78
|
+
if (document.documentElement.classList.contains('menu-modal-show') && getViewportWidth() < containerQueryMobile) {
|
|
79
|
+
autoScroll();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function autoScroll() {
|
|
83
|
+
var nav = document.querySelector('#menu-modal .navigation-content');
|
|
84
|
+
var href = window.location.pathname;
|
|
85
|
+
var navLinks = Array.from(nav.querySelectorAll("a[href=\"".concat(href, "\"]")));
|
|
86
|
+
var navLink = navLinks[0];
|
|
87
|
+
if (!navLink)
|
|
88
|
+
return;
|
|
89
|
+
navLink.scrollIntoView({
|
|
90
|
+
behavior: 'instant',
|
|
91
|
+
block: 'center',
|
|
92
|
+
inline: 'start',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function openMenuModal() {
|
|
96
|
+
document.documentElement.classList.add('menu-modal-show');
|
|
97
|
+
}
|
|
98
|
+
function closeMenuModal() {
|
|
99
|
+
document.documentElement.classList.remove('menu-modal-show');
|
|
100
|
+
}
|
|
101
|
+
function initCloseListeners() {
|
|
102
|
+
if (!isBrowser())
|
|
103
|
+
return;
|
|
104
|
+
document.addEventListener('click', onLinkClick);
|
|
105
|
+
// It's redundant (and onLinkClick() is enough), but just to be sure.
|
|
106
|
+
addEventListener('hashchange', closeMenuModal);
|
|
107
|
+
}
|
|
108
|
+
function onLinkClick(ev) {
|
|
109
|
+
if (ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey)
|
|
110
|
+
return;
|
|
111
|
+
var linkTag = findLinkTag(ev.target);
|
|
112
|
+
if (!linkTag)
|
|
113
|
+
return;
|
|
114
|
+
var href = linkTag.getAttribute('href');
|
|
115
|
+
if (!href)
|
|
116
|
+
return;
|
|
117
|
+
if (!href.startsWith('/') && !href.startsWith('#'))
|
|
118
|
+
return;
|
|
119
|
+
closeMenuModal();
|
|
120
|
+
}
|
|
121
|
+
function findLinkTag(target) {
|
|
122
|
+
while (target.tagName !== 'A') {
|
|
123
|
+
var parentNode = target.parentNode;
|
|
124
|
+
if (!parentNode) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
target = parentNode;
|
|
128
|
+
}
|
|
129
|
+
return target;
|
|
130
|
+
}
|
|
131
|
+
var templateObject_1;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export { autoScrollNav };
|
|
2
|
+
export var autoScrollNav_SSR = "autoScrollNav();".concat(autoScrollNav.toString());
|
|
3
|
+
// - We cannot use TypeScript syntax because of autoScrollNav_SSR
|
|
4
|
+
// - We have to save & restore `document.documentElement.scrollTop` because scrollIntoView() scrolls the main view. (I don't know why).
|
|
5
|
+
// - Failed alternatives:
|
|
6
|
+
// - scrollIntoViewIfNeeded() (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded) would work (it doesn't scroll the main view) but Firefox doesn't support it.
|
|
7
|
+
// - Doesn't work: the scrolling is off by hundreds of px (I guess because this function runs too early while the page is still rendering).
|
|
8
|
+
// ```js
|
|
9
|
+
// const offset = navLink.offsetTop - (window.innerHeight / 2)
|
|
10
|
+
// navigationContainerEl.scrollTop = offset
|
|
11
|
+
// ```
|
|
12
|
+
// - Doesn't work: scrollIntoView() still scrolls the main view
|
|
13
|
+
// ```js
|
|
14
|
+
// const overflowOriginal = document.documentElement.style.overflow
|
|
15
|
+
// document.documentElement.style.overflow = 'hidden'
|
|
16
|
+
// // ...
|
|
17
|
+
// document.documentElement.style.overflow = overflowOriginal
|
|
18
|
+
// ```
|
|
19
|
+
function autoScrollNav() {
|
|
20
|
+
var nav = document.querySelector('#nav-left .navigation-content');
|
|
21
|
+
if (!nav)
|
|
22
|
+
return;
|
|
23
|
+
var href = window.location.pathname;
|
|
24
|
+
var navLinks = Array.from(nav.querySelectorAll("a[href=\"".concat(href, "\"]")));
|
|
25
|
+
var navLink = navLinks[0];
|
|
26
|
+
if (!navLink)
|
|
27
|
+
return;
|
|
28
|
+
var scrollTopOriginal = document.documentElement.scrollTop;
|
|
29
|
+
navLink.scrollIntoView({
|
|
30
|
+
behavior: 'instant',
|
|
31
|
+
block: 'center',
|
|
32
|
+
inline: 'start',
|
|
33
|
+
});
|
|
34
|
+
document.documentElement.scrollTop = scrollTopOriginal;
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RepoLink } from './RepoLink';
|
|
3
|
+
export { EditPageNote };
|
|
4
|
+
function EditPageNote(_a) {
|
|
5
|
+
var pageContext = _a.pageContext;
|
|
6
|
+
var text = (React.createElement(React.Fragment, null,
|
|
7
|
+
React.createElement("span", { style: { fontFamily: 'emoji' } }, "\u270D"),
|
|
8
|
+
" Edit this page"));
|
|
9
|
+
return (React.createElement("div", { style: { marginTop: 50 } },
|
|
10
|
+
React.createElement(RepoLink, { path: '/docs/pages' + pageContext.urlPathname + '/+Page.mdx', text: text, editMode: true })));
|
|
11
|
+
}
|
|
@@ -23,7 +23,7 @@ import { assert, isBrowser, jsxToTextContent } from '../utils/server';
|
|
|
23
23
|
import { getConfig } from './getConfig';
|
|
24
24
|
import pc from '@brillout/picocolors';
|
|
25
25
|
import { parseTitle } from '../parseTitle';
|
|
26
|
-
import {
|
|
26
|
+
import { determineColumnEntries } from '../renderer/determineColumnEntries';
|
|
27
27
|
assert(!isBrowser());
|
|
28
28
|
function resolveHeadingsData(pageContext) {
|
|
29
29
|
var config = getConfig();
|
|
@@ -41,14 +41,12 @@ function resolveHeadingsData(pageContext) {
|
|
|
41
41
|
// TODO/refactor: remove navItems
|
|
42
42
|
var navItems;
|
|
43
43
|
var navItemsAll;
|
|
44
|
-
var columnLayouts;
|
|
45
44
|
{
|
|
46
45
|
var navItemsPageSections = pageSectionsResolved
|
|
47
46
|
.filter(function (pageSection) { return pageSection.pageSectionLevel === 2; })
|
|
48
47
|
.map(pageSectionToNavItem);
|
|
49
48
|
navItemsAll = headingsResolved.map(headingToNavItem);
|
|
50
|
-
|
|
51
|
-
columnLayouts = res.columnLayouts;
|
|
49
|
+
determineColumnEntries(navItemsAll);
|
|
52
50
|
if (isDetachedPage) {
|
|
53
51
|
navItems = __spreadArray([headingToNavItem(activeHeading)], navItemsPageSections, true);
|
|
54
52
|
}
|
|
@@ -70,8 +68,6 @@ function resolveHeadingsData(pageContext) {
|
|
|
70
68
|
pageTitle: pageTitle,
|
|
71
69
|
documentTitle: documentTitle,
|
|
72
70
|
// TODO: don't pass to client-side
|
|
73
|
-
columnLayouts: columnLayouts,
|
|
74
|
-
// TODO: don't pass to client-side
|
|
75
71
|
activeCategory: activeCategory,
|
|
76
72
|
};
|
|
77
73
|
return pageContextAddendum;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
export { SearchLink };
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import { openDocsearchModal } from './toggleDocsearchModal';
|
|
15
|
+
function SearchLink(props) {
|
|
16
|
+
return (React.createElement("a", __assign({}, props, { style: __assign({ height: '100%', display: 'flex', alignItems: 'center', cursor: 'pointer' }, props.style), className: "colorize-on-hover", onClick: function (ev) {
|
|
17
|
+
ev.preventDefault();
|
|
18
|
+
openDocsearchModal();
|
|
19
|
+
}, "aria-label": 'Ctrl\xa0+\xa0K' }),
|
|
20
|
+
React.createElement(SearchIcon, null),
|
|
21
|
+
"Search"));
|
|
22
|
+
}
|
|
23
|
+
function SearchIcon() {
|
|
24
|
+
return (React.createElement("span", { style: { marginRight: 'var(--icon-text-padding)', fontSize: '1.1em' }, className: "decolorize-7" }, "\uD83D\uDD0D"));
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { closeDocsearchModal };
|
|
2
|
+
export { openDocsearchModal };
|
|
3
|
+
import { assert } from '../utils/client';
|
|
4
|
+
function closeDocsearchModal() {
|
|
5
|
+
if (isClosed())
|
|
6
|
+
return;
|
|
7
|
+
toggle();
|
|
8
|
+
}
|
|
9
|
+
function openDocsearchModal() {
|
|
10
|
+
if (!isClosed())
|
|
11
|
+
return;
|
|
12
|
+
toggle();
|
|
13
|
+
}
|
|
14
|
+
// There doesn't seem be an official API to open/close the DocSearch modal:
|
|
15
|
+
// - https://github.com/algolia/docsearch/issues/2321
|
|
16
|
+
// - https://github.com/algolia/docsearch/blob/90f3c6aabbc324fe49e9a1dfe0906fcd4d90f27b/packages/docsearch-react/src/DocSearch.tsx#L52
|
|
17
|
+
function toggle() {
|
|
18
|
+
// Trigger https://github.com/algolia/docsearch/blob/90f3c6aabbc324fe49e9a1dfe0906fcd4d90f27b/packages/docsearch-react/src/useDocSearchKeyboardEvents.ts#L71
|
|
19
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'k', ctrlKey: true }));
|
|
20
|
+
}
|
|
21
|
+
function isClosed() {
|
|
22
|
+
var test1 = !document.body.classList.contains('DocSearch--active');
|
|
23
|
+
var test2 = document.getElementsByClassName('DocSearch-Modal').length === 0;
|
|
24
|
+
assert(test1 === test2);
|
|
25
|
+
return test1 || test2;
|
|
26
|
+
}
|
|
@@ -14,10 +14,11 @@ type NavItem = {
|
|
|
14
14
|
menuModalFullWidth?: true;
|
|
15
15
|
};
|
|
16
16
|
type NavItemAll = NavItem & {
|
|
17
|
-
|
|
17
|
+
isColumnEntry?: ColumnMap;
|
|
18
18
|
};
|
|
19
19
|
declare function NavigationContent(props: {
|
|
20
20
|
navItems: NavItem[];
|
|
21
21
|
showOnlyRelevant?: true;
|
|
22
22
|
columnLayout?: true;
|
|
23
23
|
}): React.JSX.Element;
|
|
24
|
+
type ColumnMap = Record<number, number>;
|
|
@@ -11,13 +11,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
// TODO/refactor: rename file and/or component
|
|
13
13
|
export { NavigationContent };
|
|
14
|
-
import React from 'react';
|
|
14
|
+
import React, { useEffect, useState } from 'react';
|
|
15
15
|
import { assert, assertWarning, jsxToTextContent } from '../utils/server';
|
|
16
16
|
import './Navigation.css';
|
|
17
17
|
import { parseTitle } from '../parseTitle';
|
|
18
18
|
import { usePageContext } from '../renderer/usePageContext';
|
|
19
19
|
import '@docsearch/css';
|
|
20
20
|
import '../global.d.ts';
|
|
21
|
+
import { getViewportWidth } from '../utils/getViewportWidth';
|
|
22
|
+
import { navWidthMax, navWidthMin } from '../Layout';
|
|
21
23
|
function NavigationContent(props) {
|
|
22
24
|
var pageContext = usePageContext();
|
|
23
25
|
var navItemsWithComputed = getNavItemsWithComputed(props.navItems, pageContext.urlPathname);
|
|
@@ -29,38 +31,46 @@ function NavigationContent(props) {
|
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
33
|
assert(!props.showOnlyRelevant);
|
|
32
|
-
|
|
33
|
-
var paddingBottom_1 = 40;
|
|
34
|
-
navContent = (React.createElement(React.Fragment, null, navItemsColumnLayout.map(function (_a, i) {
|
|
35
|
-
var navItemsColumnEntries = _a.navItemsColumnEntries, isFullWidth = _a.isFullWidth;
|
|
36
|
-
return (React.createElement("div", { key: i, style: {
|
|
37
|
-
display: 'flex',
|
|
38
|
-
justifyContent: 'center',
|
|
39
|
-
} },
|
|
40
|
-
React.createElement("div", { className: "column-layout-".concat(i) + (!isFullWidth ? '' : ' nav-category nav-category-full-width'), style: {
|
|
41
|
-
flexGrow: 1,
|
|
42
|
-
columnGap: 20,
|
|
43
|
-
paddingBottom: isFullWidth ? paddingBottom_1 : undefined,
|
|
44
|
-
} },
|
|
45
|
-
navItemsColumnEntries.map(function (navItemColumnEntry, j) { return (React.createElement("div", { key: j, className: 'column-layout-entry' + (isFullWidth ? '' : ' nav-category'), style: {
|
|
46
|
-
breakInside: 'avoid',
|
|
47
|
-
paddingBottom: !isFullWidth ? paddingBottom_1 : undefined,
|
|
48
|
-
paddingTop: isFullWidth ? undefined : 0,
|
|
49
|
-
width: '100%',
|
|
50
|
-
} },
|
|
51
|
-
React.createElement(NavItemComponent, { navItem: navItemColumnEntry }),
|
|
52
|
-
navItemColumnEntry.navItemChilds.map(function (navItem, k) { return (React.createElement(NavItemComponent, { navItem: navItem, key: k })); }),
|
|
53
|
-
React.createElement(CategoryBorder, { navItemLevel1: isFullWidth ? undefined : navItemColumnEntry, paddingBottom: paddingBottom_1 }))); }),
|
|
54
|
-
React.createElement(CategoryBorder, { navItemLevel1: !isFullWidth ? undefined : navItemsColumnEntries[0], paddingBottom: paddingBottom_1 }))));
|
|
55
|
-
})));
|
|
34
|
+
navContent = React.createElement(NavigationColumnLayout, { navItemsWithComputed: navItemsWithComputed });
|
|
56
35
|
}
|
|
57
36
|
return (React.createElement("div", { className: "navigation-content", style: { marginTop: 10 } }, navContent));
|
|
58
37
|
}
|
|
38
|
+
function NavigationColumnLayout(props) {
|
|
39
|
+
var _a = useState(), viewportWidth = _a[0], setViewportWidth = _a[1];
|
|
40
|
+
var updateviewportwidth = function () { return setViewportWidth(getViewportWidth()); };
|
|
41
|
+
useEffect(function () {
|
|
42
|
+
updateviewportwidth();
|
|
43
|
+
window.addEventListener('resize', updateviewportwidth, { passive: true });
|
|
44
|
+
});
|
|
45
|
+
var navItemsByColumnLayouts = getNavItemsByColumnLayouts(props.navItemsWithComputed, viewportWidth);
|
|
46
|
+
var margin = 40;
|
|
47
|
+
return (React.createElement(React.Fragment, null, navItemsByColumnLayouts.map(function (_a, i) {
|
|
48
|
+
var columns = _a.columns, isFullWidth = _a.isFullWidth;
|
|
49
|
+
return (React.createElement("div", { key: i, style: {
|
|
50
|
+
display: 'flex',
|
|
51
|
+
width: columns.length * (navWidthMax + 20),
|
|
52
|
+
justifyContent: 'space-between',
|
|
53
|
+
maxWidth: '100%',
|
|
54
|
+
margin: 'auto',
|
|
55
|
+
marginTop: i === 0 ? -1 * margin : undefined,
|
|
56
|
+
marginBottom: margin,
|
|
57
|
+
} },
|
|
58
|
+
columns.map(function (columnEntry, j) { return (React.createElement("div", { key: j, style: {
|
|
59
|
+
flexGrow: 1,
|
|
60
|
+
maxWidth: navWidthMax,
|
|
61
|
+
display: 'flex',
|
|
62
|
+
flexDirection: 'column',
|
|
63
|
+
paddingTop: isFullWidth && j !== 0 ? 36 : undefined,
|
|
64
|
+
} }, columnEntry.map(function (navItems, k) { return (React.createElement("div", { key: k, style: { marginTop: isFullWidth ? undefined : margin } },
|
|
65
|
+
navItems.map(function (navItem, l) { return (React.createElement(NavItemComponent, { navItem: navItem, key: l })); }),
|
|
66
|
+
React.createElement(CategoryBorder, { navItemLevel1: isFullWidth ? undefined : navItems[0] }))); }))); }),
|
|
67
|
+
React.createElement(CategoryBorder, { navItemLevel1: !isFullWidth ? undefined : columns[0][0][0] })));
|
|
68
|
+
})));
|
|
69
|
+
}
|
|
59
70
|
function CategoryBorder(_a) {
|
|
60
|
-
var navItemLevel1 = _a.navItemLevel1
|
|
71
|
+
var navItemLevel1 = _a.navItemLevel1;
|
|
61
72
|
return !navItemLevel1 ? null : (React.createElement("div", { className: "category-border", style: {
|
|
62
73
|
background: navItemLevel1.color,
|
|
63
|
-
height: "calc(100% - ".concat(paddingBottom, "px - 53px)"),
|
|
64
74
|
} }));
|
|
65
75
|
}
|
|
66
76
|
function NavItemComponent(_a) {
|
|
@@ -108,33 +118,54 @@ function NavItemComponent(_a) {
|
|
|
108
118
|
return React.createElement("span", __assign({}, props));
|
|
109
119
|
}
|
|
110
120
|
}
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
var
|
|
121
|
+
function getNavItemsByColumnLayouts(navItems, viewportWidth) {
|
|
122
|
+
if (viewportWidth === void 0) { viewportWidth = 0; }
|
|
123
|
+
var navItemsByColumnEntries = getNavItemsByColumnEntries(navItems);
|
|
124
|
+
var numberOfColumnsMax = Math.floor(viewportWidth / navWidthMin) || 1;
|
|
125
|
+
var navItemsByColumnLayouts = navItemsByColumnEntries.map(function (_a) {
|
|
126
|
+
var columnEntries = _a.columnEntries, isFullWidth = _a.isFullWidth;
|
|
127
|
+
var numberOfColumns = Math.min(numberOfColumnsMax, columnEntries.length);
|
|
128
|
+
var columns = [];
|
|
129
|
+
columnEntries.forEach(function (columnEntry) {
|
|
130
|
+
var _a;
|
|
131
|
+
var idx = numberOfColumns === 1 ? 0 : columnEntry.columnMap[numberOfColumns];
|
|
132
|
+
assert(idx >= 0);
|
|
133
|
+
(_a = columns[idx]) !== null && _a !== void 0 ? _a : (columns[idx] = []);
|
|
134
|
+
columns[idx].push(columnEntry.navItems);
|
|
135
|
+
});
|
|
136
|
+
var navItemsByColumnLayout = { columns: columns, isFullWidth: isFullWidth };
|
|
137
|
+
return navItemsByColumnLayout;
|
|
138
|
+
});
|
|
139
|
+
return navItemsByColumnLayouts;
|
|
140
|
+
}
|
|
141
|
+
function getNavItemsByColumnEntries(navItems) {
|
|
142
|
+
var navItemsByColumnEntries = [];
|
|
143
|
+
var columnEntries = [];
|
|
144
|
+
var columnEntry;
|
|
114
145
|
var isFullWidth;
|
|
115
146
|
navItems.forEach(function (navItem) {
|
|
116
147
|
if (navItem.level === 1) {
|
|
117
148
|
var isFullWidthPrevious = isFullWidth;
|
|
118
149
|
isFullWidth = !!navItem.menuModalFullWidth;
|
|
119
150
|
if (isFullWidthPrevious !== undefined && isFullWidthPrevious !== isFullWidth) {
|
|
120
|
-
|
|
121
|
-
|
|
151
|
+
navItemsByColumnEntries.push({ columnEntries: columnEntries, isFullWidth: isFullWidthPrevious });
|
|
152
|
+
columnEntries = [];
|
|
122
153
|
}
|
|
123
154
|
}
|
|
124
155
|
assert(isFullWidth !== undefined);
|
|
125
|
-
if (navItem.
|
|
156
|
+
if (navItem.isColumnEntry) {
|
|
126
157
|
assert(navItem.level === 1 || navItem.level === 4);
|
|
127
|
-
|
|
128
|
-
|
|
158
|
+
columnEntry = { navItems: [navItem], columnMap: navItem.isColumnEntry };
|
|
159
|
+
columnEntries.push(columnEntry);
|
|
129
160
|
}
|
|
130
161
|
else {
|
|
131
162
|
assert(navItem.level !== 1);
|
|
132
|
-
|
|
163
|
+
columnEntry.navItems.push(navItem);
|
|
133
164
|
}
|
|
134
165
|
});
|
|
135
166
|
assert(isFullWidth !== undefined);
|
|
136
|
-
|
|
137
|
-
return
|
|
167
|
+
navItemsByColumnEntries.push({ columnEntries: columnEntries, isFullWidth: isFullWidth });
|
|
168
|
+
return navItemsByColumnEntries;
|
|
138
169
|
}
|
|
139
170
|
function getNavItemsWithComputed(navItems, currentUrl) {
|
|
140
171
|
var navItemIdx;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
|
2
|
-
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
3
|
-
return cooked;
|
|
4
|
-
};
|
|
5
1
|
var __assign = (this && this.__assign) || function () {
|
|
6
2
|
__assign = Object.assign || function(t) {
|
|
7
3
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -22,14 +18,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
22
18
|
}
|
|
23
19
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
24
20
|
};
|
|
25
|
-
export {
|
|
26
|
-
export { determineColumnLayoutEntries };
|
|
27
|
-
import { css } from '../utils/css';
|
|
21
|
+
export { determineColumnEntries };
|
|
28
22
|
import { assert, assertUsage, isBrowser } from '../utils/server';
|
|
29
23
|
assert(!isBrowser());
|
|
30
|
-
|
|
31
|
-
var columnWidthMax = 350;
|
|
32
|
-
function determineColumnLayoutEntries(navItems) {
|
|
24
|
+
function determineColumnEntries(navItems) {
|
|
33
25
|
var navItemsWithLength = navItems.map(function (navItem) { return (__assign(__assign({}, navItem), { numberOfHeadings: navItem.level === 1 || navItem.level === 4 ? 0 : null })); });
|
|
34
26
|
var navItemLevel1;
|
|
35
27
|
var navItemLevel4;
|
|
@@ -54,7 +46,7 @@ function determineColumnLayoutEntries(navItems) {
|
|
|
54
46
|
}
|
|
55
47
|
});
|
|
56
48
|
var columnLayouts = [];
|
|
57
|
-
var
|
|
49
|
+
var columnEntries = [];
|
|
58
50
|
var isFullWidth;
|
|
59
51
|
navItemsWithLength.forEach(function (navItem, i) {
|
|
60
52
|
var isFullWidthBegin = false;
|
|
@@ -64,8 +56,8 @@ function determineColumnLayoutEntries(navItems) {
|
|
|
64
56
|
if (isFullWidth)
|
|
65
57
|
isFullWidthBegin = true;
|
|
66
58
|
if (isFullWidthPrevious !== undefined && isFullWidthPrevious !== isFullWidth) {
|
|
67
|
-
columnLayouts.push(
|
|
68
|
-
|
|
59
|
+
columnLayouts.push(columnEntries);
|
|
60
|
+
columnEntries = [];
|
|
69
61
|
}
|
|
70
62
|
}
|
|
71
63
|
var navItemPrevious = navItemsWithLength[i - 1];
|
|
@@ -87,64 +79,25 @@ function determineColumnLayoutEntries(navItems) {
|
|
|
87
79
|
assert(navItemNext.numberOfHeadings);
|
|
88
80
|
numberOfHeadings = navItemNext.numberOfHeadings;
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
navItems[i].isColumnLayoutElement = true;
|
|
82
|
+
columnEntries.push({ navItemLeader: navItems[i], numberOfEntries: numberOfHeadings });
|
|
92
83
|
}
|
|
93
84
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
function getStyleColumnLayout(columnLayouts) {
|
|
98
|
-
var style = '\n' + css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n.column-layout-entry {\n break-before: avoid;\n}\n"], ["\n.column-layout-entry {\n break-before: avoid;\n}\n"])));
|
|
99
|
-
style += '\n';
|
|
100
|
-
columnLayouts.forEach(function (columns, i) {
|
|
85
|
+
assert(columnEntries);
|
|
86
|
+
columnLayouts.push(columnEntries);
|
|
87
|
+
columnLayouts.forEach(function (columnEntries) {
|
|
101
88
|
var _loop_1 = function (numberOfColumns) {
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return;
|
|
109
|
-
styleGivenNumberOfColumns.push(css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n.column-layout-", " .column-layout-entry:nth-child(", ") {\n break-before: column;\n padding-top: 36px;\n}\n"], ["\n.column-layout-", " .column-layout-entry:nth-child(", ") {\n break-before: column;\n padding-top: 36px;\n}\n"])), i, columnUngroupedId + 1));
|
|
89
|
+
var columnsIdMap = determineColumns(columnEntries.map(function (columnEntry) { return columnEntry.numberOfEntries; }), numberOfColumns);
|
|
90
|
+
columnEntries.forEach(function (columnEntry, i) {
|
|
91
|
+
var _a;
|
|
92
|
+
var _b;
|
|
93
|
+
(_a = (_b = columnEntry.navItemLeader).isColumnEntry) !== null && _a !== void 0 ? _a : (_b.isColumnEntry = {});
|
|
94
|
+
columnEntry.navItemLeader.isColumnEntry[numberOfColumns] = columnsIdMap[i];
|
|
110
95
|
});
|
|
111
|
-
{
|
|
112
|
-
assert(styleGivenNumberOfColumns.length > 0);
|
|
113
|
-
var getMaxWidth = function (columns) { return (columns + 1) * columnWidthMin - 1; };
|
|
114
|
-
var isFirst = numberOfColumns === 1;
|
|
115
|
-
var isLast = numberOfColumns === columns.length;
|
|
116
|
-
var query = [
|
|
117
|
-
!isFirst && "(min-width: ".concat(getMaxWidth(numberOfColumns - 1) + 1, "px)"),
|
|
118
|
-
!isLast && "(max-width: ".concat(getMaxWidth(numberOfColumns), "px)"),
|
|
119
|
-
]
|
|
120
|
-
.filter(Boolean)
|
|
121
|
-
.join(' and ');
|
|
122
|
-
if (query) {
|
|
123
|
-
styleGivenNumberOfColumns = __spreadArray(__spreadArray(["@container ".concat(query, " {")], styleGivenNumberOfColumns, true), ["}"], false);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
style += styleGivenNumberOfColumns.join('\n') + '\n';
|
|
127
96
|
};
|
|
128
|
-
for (var numberOfColumns =
|
|
97
|
+
for (var numberOfColumns = columnEntries.length; numberOfColumns >= 1; numberOfColumns--) {
|
|
129
98
|
_loop_1(numberOfColumns);
|
|
130
99
|
}
|
|
131
100
|
});
|
|
132
|
-
return style;
|
|
133
|
-
}
|
|
134
|
-
function determineColumnBreakPoints(columnsIdMap) {
|
|
135
|
-
assert(columnsIdMap[0] === 0);
|
|
136
|
-
var columnGroupedIdBefore = 0;
|
|
137
|
-
var columnBreakPoints = columnsIdMap.map(function (columnGroupedId) {
|
|
138
|
-
assert([
|
|
139
|
-
//
|
|
140
|
-
columnGroupedIdBefore,
|
|
141
|
-
columnGroupedIdBefore + 1,
|
|
142
|
-
].includes(columnGroupedId));
|
|
143
|
-
var val = columnGroupedId !== columnGroupedIdBefore;
|
|
144
|
-
columnGroupedIdBefore = columnGroupedId;
|
|
145
|
-
return val;
|
|
146
|
-
});
|
|
147
|
-
return columnBreakPoints;
|
|
148
101
|
}
|
|
149
102
|
function determineColumns(columnsUnmerged, numberOfColumns) {
|
|
150
103
|
assert(numberOfColumns <= columnsUnmerged.length);
|
|
@@ -188,4 +141,3 @@ function mergeColumns(columnsMerging, numberOfColumns) {
|
|
|
188
141
|
assert(columnsMergingMod.length === columnsMerging.length - 1);
|
|
189
142
|
return mergeColumns(columnsMergingMod, numberOfColumns);
|
|
190
143
|
}
|
|
191
|
-
var templateObject_1, templateObject_2, templateObject_3;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getViewportWidth(): number;
|