@brillout/docpress 0.8.14 → 0.8.15

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.
Files changed (48) hide show
  1. package/Layout.tsx +254 -177
  2. package/MenuModal.tsx +42 -48
  3. package/{Links.tsx → NavSecondaryContent.tsx} +5 -8
  4. package/components/HorizontalLine.tsx +4 -3
  5. package/config/resolveHeadingsData.ts +7 -10
  6. package/css/code/block.css +5 -5
  7. package/css/code/inline.css +1 -1
  8. package/css/colorize-on-hover.css +2 -2
  9. package/dist/Layout.d.ts +10 -6
  10. package/dist/Layout.js +165 -120
  11. package/dist/MenuModal.js +34 -47
  12. package/dist/{Links.d.ts → NavSecondaryContent.d.ts} +3 -2
  13. package/dist/{Links.js → NavSecondaryContent.js} +5 -7
  14. package/dist/components/HorizontalLine.d.ts +1 -1
  15. package/dist/components/HorizontalLine.js +3 -2
  16. package/dist/config/resolveHeadingsData.d.ts +3 -4
  17. package/dist/config/resolveHeadingsData.js +5 -8
  18. package/dist/config/resolvePageContext.d.ts +2 -3
  19. package/dist/docsearch/SearchLink.js +1 -1
  20. package/dist/navigation/Collapsible.d.ts +10 -0
  21. package/dist/navigation/Collapsible.js +35 -0
  22. package/dist/navigation/Navigation.d.ts +0 -3
  23. package/dist/navigation/Navigation.js +106 -55
  24. package/dist/renderer/determineNavItemsColumnLayout.d.ts +3 -0
  25. package/dist/renderer/{determineColumnEntries.js → determineNavItemsColumnLayout.js} +34 -28
  26. package/dist/renderer/usePageContext.d.ts +2 -2
  27. package/dist/renderer/usePageContext.js +2 -4
  28. package/dist/utils/Style.d.ts +5 -0
  29. package/dist/utils/Style.js +6 -0
  30. package/dist/utils/cls.d.ts +3 -0
  31. package/dist/utils/cls.js +5 -0
  32. package/dist/utils/throttle.d.ts +1 -0
  33. package/dist/utils/throttle.js +14 -0
  34. package/docsearch/SearchLink.tsx +1 -1
  35. package/global.d.ts +1 -1
  36. package/navigation/Collapsible.css +11 -0
  37. package/navigation/Collapsible.tsx +64 -0
  38. package/navigation/Navigation.css +12 -6
  39. package/navigation/Navigation.tsx +191 -80
  40. package/package.json +1 -1
  41. package/renderer/{determineColumnEntries.ts → determineNavItemsColumnLayout.ts} +35 -29
  42. package/renderer/initOnNavigation.ts +37 -0
  43. package/renderer/onRenderClient.tsx +2 -0
  44. package/renderer/usePageContext.tsx +2 -5
  45. package/utils/Style.tsx +7 -0
  46. package/utils/cls.ts +8 -0
  47. package/utils/throttle.ts +10 -0
  48. package/dist/renderer/determineColumnEntries.d.ts +0 -3
@@ -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 { determineColumnEntries } from '../renderer/determineColumnEntries';
26
+ import { determineNavItemsColumnLayout } from '../renderer/determineNavItemsColumnLayout';
27
27
  assert(!isBrowser());
28
28
  function resolveHeadingsData(pageContext) {
29
29
  var config = getConfig();
@@ -38,20 +38,18 @@ function resolveHeadingsData(pageContext) {
38
38
  var _b = getTitles(activeHeading, pageContext, config), documentTitle = _b.documentTitle, isLandingPage = _b.isLandingPage, pageTitle = _b.pageTitle;
39
39
  var pageSectionsResolved = getPageSectionsResolved(pageContext, activeHeading);
40
40
  var linksAll = __spreadArray(__spreadArray(__spreadArray([], pageSectionsResolved.map(pageSectionToLinkData), true), headingsResolved.map(headingToLinkData), true), headingsDetachedResolved.map(headingToLinkData), true);
41
- // TODO/refactor: remove navItems
42
- var navItems;
43
41
  var navItemsAll;
42
+ var navItemsDetached;
44
43
  {
45
44
  var navItemsPageSections = pageSectionsResolved
46
45
  .filter(function (pageSection) { return pageSection.pageSectionLevel === 2; })
47
46
  .map(pageSectionToNavItem);
48
47
  navItemsAll = headingsResolved.map(headingToNavItem);
49
- determineColumnEntries(navItemsAll);
48
+ determineNavItemsColumnLayout(navItemsAll);
50
49
  if (isDetachedPage) {
51
- navItems = __spreadArray([headingToNavItem(activeHeading)], navItemsPageSections, true);
50
+ navItemsDetached = __spreadArray([headingToNavItem(activeHeading)], navItemsPageSections, true);
52
51
  }
53
52
  else {
54
- navItems = navItemsAll;
55
53
  var activeHeadingIndex_1 = navItemsAll.findIndex(function (navItem) { return navItem.url === pageContext.urlPathname; });
56
54
  assert(activeHeadingIndex_1 >= 0);
57
55
  navItemsPageSections.forEach(function (navItem, i) {
@@ -60,9 +58,8 @@ function resolveHeadingsData(pageContext) {
60
58
  }
61
59
  }
62
60
  var pageContextAddendum = {
63
- isDetachedPage: isDetachedPage,
64
- navItems: navItems,
65
61
  navItemsAll: navItemsAll,
62
+ navItemsDetached: navItemsDetached,
66
63
  linksAll: linksAll,
67
64
  isLandingPage: isLandingPage,
68
65
  pageTitle: pageTitle,
@@ -10,9 +10,8 @@ type Exports = {
10
10
  type PageContextOriginal = PageContextServer;
11
11
  type PageContextResolved = ReturnType<typeof resolvePageContext>;
12
12
  declare function resolvePageContext(pageContext: PageContextOriginal): {
13
- isDetachedPage: boolean;
14
- navItems: import("../navigation/Navigation").NavItem[];
15
- navItemsAll: import("../navigation/Navigation").NavItemAll[];
13
+ navItemsAll: import("../navigation/Navigation").NavItem[];
14
+ navItemsDetached: import("../navigation/Navigation").NavItem[] | undefined;
16
15
  linksAll: import("../components").LinkData[];
17
16
  isLandingPage: boolean;
18
17
  pageTitle: string | null;
@@ -13,7 +13,7 @@ export { SearchLink };
13
13
  import React from 'react';
14
14
  import { openDocsearchModal } from './toggleDocsearchModal';
15
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) {
16
+ return (React.createElement("a", __assign({}, props, { style: __assign({ height: '100%', display: 'flex', alignItems: 'center', cursor: 'pointer' }, props.style), className: ['colorize-on-hover', props.className].filter(Boolean).join(' '), onClick: function (ev) {
17
17
  ev.preventDefault();
18
18
  openDocsearchModal();
19
19
  }, "aria-label": 'Ctrl\xa0+\xa0K' }),
@@ -0,0 +1,10 @@
1
+ export { Collapsible };
2
+ import React from 'react';
3
+ import './Collapsible.css';
4
+ declare function Collapsible({ head, children, disabled, collapsedInit, marginBottomOnExpand, }: {
5
+ head: (onClick: () => void) => React.ReactNode;
6
+ children: React.ReactNode;
7
+ disabled: boolean;
8
+ collapsedInit: boolean;
9
+ marginBottomOnExpand?: number;
10
+ }): React.JSX.Element;
@@ -0,0 +1,35 @@
1
+ export { Collapsible };
2
+ import React, { useRef, useState } from 'react';
3
+ import { cls } from '../utils/cls';
4
+ import './Collapsible.css';
5
+ function Collapsible(_a) {
6
+ var head = _a.head, children = _a.children, _b = _a.disabled, disabled = _b === void 0 ? false : _b, collapsedInit = _a.collapsedInit, marginBottomOnExpand = _a.marginBottomOnExpand;
7
+ var _c = useState(collapsedInit), collapsed = _c[0], setCollapsed = _c[1];
8
+ var _d = useState(false), isAnimating = _d[0], setIsAnimating = _d[1];
9
+ var contentRef = useRef(null);
10
+ var onClick = function () {
11
+ if (!disabled) {
12
+ setIsAnimating(true);
13
+ if (!collapsed) {
14
+ // If expanding, set height to current scroll height before animation
15
+ contentRef.current.style.height = "".concat(contentRef.current.scrollHeight, "px");
16
+ // Force a reflow
17
+ contentRef.current.offsetHeight;
18
+ }
19
+ setCollapsed(function (prev) { return !prev; });
20
+ }
21
+ };
22
+ var onTransitionEnd = function () {
23
+ setIsAnimating(false);
24
+ };
25
+ var showContent = disabled ? true : !collapsed;
26
+ return (React.createElement("div", { className: cls(['collapsible', !disabled && (showContent ? 'collapsible-expanded' : 'collapsible-collapsed')]) },
27
+ head(onClick),
28
+ React.createElement("div", { ref: contentRef, onTransitionEnd: onTransitionEnd, style: {
29
+ height: !showContent ? 0 : isAnimating ? contentRef.current.scrollHeight : 'auto',
30
+ overflow: 'hidden',
31
+ transition: 'none 0.3s ease',
32
+ transitionProperty: 'height, margin-bottom',
33
+ marginBottom: (showContent && marginBottomOnExpand) || undefined,
34
+ }, "aria-expanded": showContent }, children)));
35
+ }
@@ -1,6 +1,5 @@
1
1
  export { NavigationContent };
2
2
  export type { NavItem };
3
- export type { NavItemAll };
4
3
  import React from 'react';
5
4
  import './Navigation.css';
6
5
  import '@docsearch/css';
@@ -12,8 +11,6 @@ type NavItem = {
12
11
  title: string;
13
12
  titleInNav: string;
14
13
  menuModalFullWidth?: true;
15
- };
16
- type NavItemAll = NavItem & {
17
14
  isColumnEntry?: ColumnMap;
18
15
  };
19
16
  declare function NavigationContent(props: {
@@ -19,64 +19,77 @@ import { usePageContext } from '../renderer/usePageContext';
19
19
  import '@docsearch/css';
20
20
  import '../global.d.ts';
21
21
  import { getViewportWidth } from '../utils/getViewportWidth';
22
- import { navWidthMax, navWidthMin } from '../Layout';
22
+ import { navLeftWidthMax, navLeftWidthMin } from '../Layout';
23
+ import { throttle } from '../utils/throttle';
24
+ import { Collapsible } from './Collapsible';
23
25
  function NavigationContent(props) {
24
26
  var pageContext = usePageContext();
25
27
  var navItemsWithComputed = getNavItemsWithComputed(props.navItems, pageContext.urlPathname);
26
28
  var navContent;
27
29
  if (!props.columnLayout) {
28
- navContent = navItemsWithComputed
29
- .filter(function (navItemGroup) { return !props.showOnlyRelevant || navItemGroup.isRelevant; })
30
- .map(function (navItem, i) { return React.createElement(NavItemComponent, { navItem: navItem, key: i }); });
30
+ var navItemsRelevant = navItemsWithComputed;
31
+ if (props.showOnlyRelevant)
32
+ navItemsRelevant = navItemsRelevant.filter(function (navItemGroup) { return navItemGroup.isRelevant; });
33
+ navContent = navItemsRelevant.map(function (navItem, i) { return React.createElement(NavItemComponent, { navItem: navItem, key: i }); });
31
34
  }
32
35
  else {
33
36
  assert(!props.showOnlyRelevant);
34
- navContent = React.createElement(NavigationColumnLayout, { navItemsWithComputed: navItemsWithComputed });
37
+ navContent = React.createElement(NavigationWithColumnLayout, { navItemsWithComputed: navItemsWithComputed });
35
38
  }
36
39
  return (React.createElement("div", { className: "navigation-content", style: { marginTop: 10 } }, navContent));
37
40
  }
38
- function NavigationColumnLayout(props) {
41
+ function NavigationWithColumnLayout(props) {
39
42
  var _a = useState(), viewportWidth = _a[0], setViewportWidth = _a[1];
40
43
  var updateviewportwidth = function () { return setViewportWidth(getViewportWidth()); };
41
44
  useEffect(function () {
42
45
  updateviewportwidth();
43
- window.addEventListener('resize', updateviewportwidth, { passive: true });
46
+ window.addEventListener('resize', throttle(updateviewportwidth, 300), { passive: true });
44
47
  });
45
48
  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
- })));
49
+ return (React.createElement(React.Fragment, null, navItemsByColumnLayouts.map(function (columnLayout, i) { return (React.createElement("div", { key: i }, columnLayout.isFullWidthCategory ? (React.createElement("div", { style: { marginTop: 0 } },
50
+ React.createElement(ColumnsWrapper, { numberOfColumns: columnLayout.columns.length },
51
+ React.createElement(Collapsible, { head: function (onClick) { return React.createElement(NavItemComponent, { navItem: columnLayout.navItemLevel1, onClick: onClick }); }, disabled: columnLayout.columns.length > 1, collapsedInit: !columnLayout.navItemLevel1.isRelevant, marginBottomOnExpand: 10 },
52
+ React.createElement(ColumnsLayout, { className: "collapsible" },
53
+ columnLayout.columns.map(function (column, j) { return (React.createElement(Column, { key: j }, column.navItems.map(function (navItem, k) { return (React.createElement(NavItemComponent, { key: k, navItem: navItem })); }))); }),
54
+ React.createElement(CategoryBorder, { navItemLevel1: columnLayout.navItemLevel1 })))))) : (React.createElement(ColumnsWrapper, { numberOfColumns: columnLayout.columns.length },
55
+ React.createElement(ColumnsLayout, null, columnLayout.columns.map(function (column, j) { return (React.createElement(Column, { key: j }, column.categories.map(function (category, k) { return (React.createElement("div", { key: k, style: { marginBottom: 0 } },
56
+ React.createElement(Collapsible, { head: function (onClick) { return React.createElement(NavItemComponent, { navItem: category.navItemLevel1, onClick: onClick }); }, disabled: columnLayout.columns.length > 1, collapsedInit: !category.navItemLevel1.isRelevant, marginBottomOnExpand: 40 },
57
+ category.navItems.map(function (navItem, l) { return (React.createElement(NavItemComponent, { key: l, navItem: navItem })); }),
58
+ React.createElement(CategoryBorder, { navItemLevel1: category.navItemLevel1 })))); }))); })))))); })));
59
+ }
60
+ function Column(_a) {
61
+ var children = _a.children;
62
+ return (React.createElement("div", { style: {
63
+ flexGrow: 1,
64
+ maxWidth: navLeftWidthMax,
65
+ display: 'flex',
66
+ flexDirection: 'column',
67
+ } }, children));
68
+ }
69
+ function ColumnsWrapper(_a) {
70
+ var children = _a.children, numberOfColumns = _a.numberOfColumns;
71
+ return (React.createElement("div", { style: {
72
+ width: numberOfColumns * (navLeftWidthMax + 20),
73
+ maxWidth: '100%',
74
+ margin: 'auto',
75
+ } }, children));
76
+ }
77
+ function ColumnsLayout(_a) {
78
+ var children = _a.children, className = _a.className;
79
+ return (React.createElement("div", { className: className, style: {
80
+ display: 'flex',
81
+ justifyContent: 'space-between',
82
+ } }, children));
69
83
  }
70
84
  function CategoryBorder(_a) {
71
85
  var navItemLevel1 = _a.navItemLevel1;
72
- return !navItemLevel1 ? null : (React.createElement("div", { className: "category-border", style: {
73
- background: navItemLevel1.color,
74
- } }));
86
+ assert(navItemLevel1.level === 1);
87
+ return React.createElement("div", { className: "category-border", style: { background: navItemLevel1.color } });
75
88
  }
76
89
  function NavItemComponent(_a) {
77
90
  var _b;
78
91
  var _c;
79
- var navItem = _a.navItem;
92
+ var navItem = _a.navItem, onClick = _a.onClick;
80
93
  assert([1, 2, 3, 4].includes(navItem.level), navItem);
81
94
  var titleJsx = parseTitle(navItem.title);
82
95
  var titleInNavJsx = parseTitle(navItem.titleInNav);
@@ -93,9 +106,16 @@ function NavItemComponent(_a) {
93
106
  */
94
107
  ].join(' '));
95
108
  }
109
+ var children = titleInNavJsx;
110
+ if (navItem.level === 1) {
111
+ children = (React.createElement(React.Fragment, null,
112
+ children,
113
+ React.createElement(Chevron, { className: "collapsible-icon", height: 9 })));
114
+ }
96
115
  var props = {
97
116
  href: (_c = navItem.url) !== null && _c !== void 0 ? _c : undefined,
98
- children: titleInNavJsx,
117
+ children: children,
118
+ onClick: onClick,
99
119
  className: [
100
120
  'nav-item',
101
121
  'nav-item-level-' + navItem.level,
@@ -121,20 +141,47 @@ function NavItemComponent(_a) {
121
141
  function getNavItemsByColumnLayouts(navItems, viewportWidth) {
122
142
  if (viewportWidth === void 0) { viewportWidth = 0; }
123
143
  var navItemsByColumnEntries = getNavItemsByColumnEntries(navItems);
124
- var numberOfColumnsMax = Math.floor(viewportWidth / navWidthMin) || 1;
144
+ var numberOfColumnsMax = Math.floor(viewportWidth / navLeftWidthMin) || 1;
125
145
  var navItemsByColumnLayouts = navItemsByColumnEntries.map(function (_a) {
126
- var columnEntries = _a.columnEntries, isFullWidth = _a.isFullWidth;
146
+ var columnEntries = _a.columnEntries, isFullWidthCategory = _a.isFullWidthCategory;
127
147
  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;
148
+ if (!isFullWidthCategory) {
149
+ var columns_1 = [];
150
+ columnEntries.forEach(function (columnEntry) {
151
+ var _a;
152
+ var idx = numberOfColumns === 1 ? 0 : columnEntry.columnMap[numberOfColumns];
153
+ assert(idx >= 0);
154
+ (_a = columns_1[idx]) !== null && _a !== void 0 ? _a : (columns_1[idx] = { categories: [] });
155
+ var navItemLevel1 = columnEntry.navItems[0];
156
+ var navItems = columnEntry.navItems.slice(1);
157
+ columns_1[idx].categories.push({ navItemLevel1: navItemLevel1, navItems: navItems });
158
+ });
159
+ var navItemsByColumnLayout = { columns: columns_1, isFullWidthCategory: isFullWidthCategory };
160
+ return navItemsByColumnLayout;
161
+ }
162
+ else {
163
+ var navItemLevel1_1;
164
+ var columns_2 = [];
165
+ columnEntries.forEach(function (columnEntry, i) {
166
+ var _a;
167
+ var _b;
168
+ var idx = numberOfColumns === 1 ? 0 : columnEntry.columnMap[numberOfColumns];
169
+ assert(idx >= 0);
170
+ (_b = columns_2[idx]) !== null && _b !== void 0 ? _b : (columns_2[idx] = { navItems: [] });
171
+ var navItems = columnEntry.navItems;
172
+ if (i === 0) {
173
+ navItemLevel1_1 = navItems[0];
174
+ navItems = navItems.slice(1);
175
+ }
176
+ (_a = columns_2[idx].navItems).push.apply(_a, navItems);
177
+ });
178
+ var navItemsByColumnLayout = {
179
+ columns: columns_2,
180
+ navItemLevel1: navItemLevel1_1,
181
+ isFullWidthCategory: isFullWidthCategory,
182
+ };
183
+ return navItemsByColumnLayout;
184
+ }
138
185
  });
139
186
  return navItemsByColumnLayouts;
140
187
  }
@@ -142,17 +189,17 @@ function getNavItemsByColumnEntries(navItems) {
142
189
  var navItemsByColumnEntries = [];
143
190
  var columnEntries = [];
144
191
  var columnEntry;
145
- var isFullWidth;
192
+ var isFullWidthCategory;
146
193
  navItems.forEach(function (navItem) {
147
194
  if (navItem.level === 1) {
148
- var isFullWidthPrevious = isFullWidth;
149
- isFullWidth = !!navItem.menuModalFullWidth;
150
- if (isFullWidthPrevious !== undefined && isFullWidthPrevious !== isFullWidth) {
151
- navItemsByColumnEntries.push({ columnEntries: columnEntries, isFullWidth: isFullWidthPrevious });
195
+ var isFullWidthCategoryPrevious = isFullWidthCategory;
196
+ isFullWidthCategory = !!navItem.menuModalFullWidth;
197
+ if (isFullWidthCategoryPrevious !== undefined && isFullWidthCategoryPrevious !== isFullWidthCategory) {
198
+ navItemsByColumnEntries.push({ columnEntries: columnEntries, isFullWidthCategory: isFullWidthCategoryPrevious });
152
199
  columnEntries = [];
153
200
  }
154
201
  }
155
- assert(isFullWidth !== undefined);
202
+ assert(isFullWidthCategory !== undefined);
156
203
  if (navItem.isColumnEntry) {
157
204
  assert(navItem.level === 1 || navItem.level === 4);
158
205
  columnEntry = { navItems: [navItem], columnMap: navItem.isColumnEntry };
@@ -163,8 +210,8 @@ function getNavItemsByColumnEntries(navItems) {
163
210
  columnEntry.navItems.push(navItem);
164
211
  }
165
212
  });
166
- assert(isFullWidth !== undefined);
167
- navItemsByColumnEntries.push({ columnEntries: columnEntries, isFullWidth: isFullWidth });
213
+ assert(isFullWidthCategory !== undefined);
214
+ navItemsByColumnEntries.push({ columnEntries: columnEntries, isFullWidthCategory: isFullWidthCategory });
168
215
  return navItemsByColumnEntries;
169
216
  }
170
217
  function getNavItemsWithComputed(navItems, currentUrl) {
@@ -202,3 +249,7 @@ function getNavItemsWithComputed(navItems, currentUrl) {
202
249
  }
203
250
  return navItemsWithComputed;
204
251
  }
252
+ function Chevron(props) {
253
+ return (React.createElement("svg", __assign({ viewBox: "0 0 512 292.52", xmlns: "http://www.w3.org/2000/svg" }, props),
254
+ React.createElement("path", { fill: "#aaa", d: "M10.725 82.42L230.125 261.82c6.8 6.8 16.2 10.7 25.9 10.7s19.1-3.9 25.9-10.7l219.4-179.4c14.3-14.3 14.3-37.4 0-51.7s-37.4-14.3-51.7 0l-193.6 153.6-193.6-153.6c-14.3-14.3-37.4-14.3-51.7 0s-14.3 37.5 0 51.7z" })));
255
+ }
@@ -0,0 +1,3 @@
1
+ export { determineNavItemsColumnLayout };
2
+ import { type NavItem } from '../navigation/Navigation';
3
+ declare function determineNavItemsColumnLayout(navItems: NavItem[]): undefined;
@@ -18,10 +18,27 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
18
  }
19
19
  return to.concat(ar || Array.prototype.slice.call(from));
20
20
  };
21
- export { determineColumnEntries };
21
+ export { determineNavItemsColumnLayout };
22
22
  import { assert, assertUsage, isBrowser } from '../utils/server';
23
23
  assert(!isBrowser());
24
- function determineColumnEntries(navItems) {
24
+ function determineNavItemsColumnLayout(navItems) {
25
+ var columnLayouts = getColumnEntries(navItems);
26
+ columnLayouts.forEach(function (columnEntries) {
27
+ var _loop_1 = function (numberOfColumns) {
28
+ var columnMapping = determineColumnLayout(columnEntries.map(function (columnEntry) { return columnEntry.numberOfEntries; }), numberOfColumns);
29
+ columnEntries.forEach(function (columnEntry, i) {
30
+ var _a;
31
+ var _b;
32
+ (_a = (_b = columnEntry.navItemLeader).isColumnEntry) !== null && _a !== void 0 ? _a : (_b.isColumnEntry = {});
33
+ columnEntry.navItemLeader.isColumnEntry[numberOfColumns] = columnMapping[i];
34
+ });
35
+ };
36
+ for (var numberOfColumns = columnEntries.length; numberOfColumns >= 1; numberOfColumns--) {
37
+ _loop_1(numberOfColumns);
38
+ }
39
+ });
40
+ }
41
+ function getColumnEntries(navItems) {
25
42
  var navItemsWithLength = navItems.map(function (navItem) { return (__assign(__assign({}, navItem), { numberOfHeadings: navItem.level === 1 || navItem.level === 4 ? 0 : null })); });
26
43
  var navItemLevel1;
27
44
  var navItemLevel4;
@@ -47,31 +64,33 @@ function determineColumnEntries(navItems) {
47
64
  });
48
65
  var columnLayouts = [];
49
66
  var columnEntries = [];
50
- var isFullWidth;
67
+ var isFullWidthCategory;
51
68
  navItemsWithLength.forEach(function (navItem, i) {
52
- var isFullWidthBegin = false;
69
+ var isFullWidthCategoryBegin = false;
53
70
  if (navItem.level === 1) {
54
- var isFullWidthPrevious = isFullWidth;
55
- isFullWidth = !!navItem.menuModalFullWidth;
56
- if (isFullWidth)
57
- isFullWidthBegin = true;
58
- if (isFullWidthPrevious !== undefined && isFullWidthPrevious !== isFullWidth) {
71
+ var isFullWidthCategoryPrevious = isFullWidthCategory;
72
+ isFullWidthCategory = !!navItem.menuModalFullWidth;
73
+ if (isFullWidthCategory)
74
+ isFullWidthCategoryBegin = true;
75
+ if (isFullWidthCategoryPrevious !== undefined && isFullWidthCategoryPrevious !== isFullWidthCategory) {
59
76
  columnLayouts.push(columnEntries);
60
77
  columnEntries = [];
61
78
  }
62
79
  }
63
80
  var navItemPrevious = navItemsWithLength[i - 1];
64
81
  var navItemNext = navItemsWithLength[i + 1];
65
- if (!isFullWidth ? navItem.level === 1 : (navItem.level === 4 && navItemPrevious.level !== 1) || isFullWidthBegin) {
66
- if (isFullWidth) {
67
- assert(navItem.level === 4 || (navItem.level === 1 && isFullWidthBegin));
82
+ if (!isFullWidthCategory
83
+ ? navItem.level === 1
84
+ : (navItem.level === 4 && navItemPrevious.level !== 1) || isFullWidthCategoryBegin) {
85
+ if (isFullWidthCategory) {
86
+ assert(navItem.level === 4 || (navItem.level === 1 && isFullWidthCategoryBegin));
68
87
  }
69
88
  else {
70
89
  assert(navItem.level === 1);
71
90
  }
72
91
  var numberOfHeadings = navItem.numberOfHeadings;
73
92
  assert(numberOfHeadings !== null);
74
- if (isFullWidthBegin) {
93
+ if (isFullWidthCategoryBegin) {
75
94
  assert(navItem.level === 1);
76
95
  assertUsage(navItemNext && navItemNext.level === 4,
77
96
  // We can lift this requirement, but it isn't trivial to implement.
@@ -84,22 +103,9 @@ function determineColumnEntries(navItems) {
84
103
  });
85
104
  assert(columnEntries);
86
105
  columnLayouts.push(columnEntries);
87
- columnLayouts.forEach(function (columnEntries) {
88
- var _loop_1 = function (numberOfColumns) {
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];
95
- });
96
- };
97
- for (var numberOfColumns = columnEntries.length; numberOfColumns >= 1; numberOfColumns--) {
98
- _loop_1(numberOfColumns);
99
- }
100
- });
106
+ return columnLayouts;
101
107
  }
102
- function determineColumns(columnsUnmerged, numberOfColumns) {
108
+ function determineColumnLayout(columnsUnmerged, numberOfColumns) {
103
109
  assert(numberOfColumns <= columnsUnmerged.length);
104
110
  var columnsMergingInit = columnsUnmerged.map(function (columnHeight, i) { return ({
105
111
  columnIdsMerged: [i],
@@ -1,8 +1,8 @@
1
+ export { usePageContext };
2
+ export { PageContextProvider };
1
3
  import React from 'react';
2
4
  import type { PageContextResolved } from '../config/resolvePageContext';
3
5
  import type { PageContext } from 'vike/types';
4
- export { PageContextProvider };
5
- export { usePageContext };
6
6
  declare function PageContextProvider({ pageContext, children, }: {
7
7
  pageContext: PageContextResolved;
8
8
  children: React.ReactNode;
@@ -1,8 +1,6 @@
1
- // `usePageContext` allows us to access `pageContext` in any React component.
2
- // More infos: https://vike.dev/pageContext-anywhere
3
- import React, { useContext } from 'react';
4
- export { PageContextProvider };
5
1
  export { usePageContext };
2
+ export { PageContextProvider };
3
+ import React, { useContext } from 'react';
6
4
  var Context = React.createContext(undefined);
7
5
  function PageContextProvider(_a) {
8
6
  var pageContext = _a.pageContext, children = _a.children;
@@ -0,0 +1,5 @@
1
+ export { Style };
2
+ import React from 'react';
3
+ declare function Style({ children }: {
4
+ children: string;
5
+ }): React.JSX.Element;
@@ -0,0 +1,6 @@
1
+ export { Style };
2
+ import React from 'react';
3
+ function Style(_a) {
4
+ var children = _a.children;
5
+ return React.createElement("style", { dangerouslySetInnerHTML: { __html: children } });
6
+ }
@@ -0,0 +1,3 @@
1
+ export { cls };
2
+ type Class = string | boolean | undefined;
3
+ declare function cls(className: Class | Class[]): string;
@@ -0,0 +1,5 @@
1
+ export { cls };
2
+ function cls(className) {
3
+ var classNames = Array.isArray(className) ? className : [className];
4
+ return classNames.filter(Boolean).join(' ');
5
+ }
@@ -0,0 +1 @@
1
+ export declare function throttle<T extends (...args: any[]) => void>(func: T, limit: number): T;
@@ -0,0 +1,14 @@
1
+ export function throttle(func, limit) {
2
+ var inThrottle;
3
+ return function () {
4
+ var args = [];
5
+ for (var _i = 0; _i < arguments.length; _i++) {
6
+ args[_i] = arguments[_i];
7
+ }
8
+ if (!inThrottle) {
9
+ func.apply(this, args);
10
+ inThrottle = true;
11
+ setTimeout(function () { return (inThrottle = false); }, limit);
12
+ }
13
+ };
14
+ }
@@ -15,7 +15,7 @@ function SearchLink(props: PropsAnchor) {
15
15
  cursor: 'pointer',
16
16
  ...props.style,
17
17
  }}
18
- className="colorize-on-hover"
18
+ className={['colorize-on-hover', props.className].filter(Boolean).join(' ')}
19
19
  onClick={(ev) => {
20
20
  ev.preventDefault()
21
21
  openDocsearchModal()
package/global.d.ts CHANGED
@@ -2,6 +2,6 @@
2
2
  import 'react'
3
3
  declare module 'react' {
4
4
  interface CSSProperties {
5
- [key: `--${string}`]: string | number
5
+ [key: `--${string}`]: string | number | undefined
6
6
  }
7
7
  }
@@ -0,0 +1,11 @@
1
+ .collapsible-icon {
2
+ display: none;
3
+ }
4
+ .collapsible-expanded .collapsible-icon,
5
+ .collapsible-collapsed .collapsible-icon {
6
+ transition: transform 0.3s ease-in-out !important;
7
+ display: initial;
8
+ }
9
+ .collapsible-collapsed .collapsible-icon {
10
+ transform: rotate(-90deg);
11
+ }
@@ -0,0 +1,64 @@
1
+ export { Collapsible }
2
+
3
+ import React, { useRef, useState } from 'react'
4
+ import { cls } from '../utils/cls'
5
+ import './Collapsible.css'
6
+
7
+ function Collapsible({
8
+ head,
9
+ children,
10
+ disabled = false,
11
+ collapsedInit,
12
+ marginBottomOnExpand,
13
+ }: {
14
+ head: (onClick: () => void) => React.ReactNode
15
+ children: React.ReactNode
16
+ disabled: boolean
17
+ collapsedInit: boolean
18
+ marginBottomOnExpand?: number
19
+ }) {
20
+ const [collapsed, setCollapsed] = useState(collapsedInit)
21
+ const [isAnimating, setIsAnimating] = useState(false)
22
+ const contentRef = useRef<HTMLDivElement>(null)
23
+
24
+ const onClick = () => {
25
+ if (!disabled) {
26
+ setIsAnimating(true)
27
+ if (!collapsed) {
28
+ // If expanding, set height to current scroll height before animation
29
+ contentRef.current!.style.height = `${contentRef.current!.scrollHeight}px`
30
+ // Force a reflow
31
+ contentRef.current!.offsetHeight
32
+ }
33
+ setCollapsed((prev) => !prev)
34
+ }
35
+ }
36
+
37
+ const onTransitionEnd = () => {
38
+ setIsAnimating(false)
39
+ }
40
+
41
+ const showContent = disabled ? true : !collapsed
42
+
43
+ return (
44
+ <div
45
+ className={cls(['collapsible', !disabled && (showContent ? 'collapsible-expanded' : 'collapsible-collapsed')])}
46
+ >
47
+ {head(onClick)}
48
+ <div
49
+ ref={contentRef}
50
+ onTransitionEnd={onTransitionEnd}
51
+ style={{
52
+ height: !showContent ? 0 : isAnimating ? contentRef.current!.scrollHeight : 'auto',
53
+ overflow: 'hidden',
54
+ transition: 'none 0.3s ease',
55
+ transitionProperty: 'height, margin-bottom',
56
+ marginBottom: (showContent && marginBottomOnExpand) || undefined,
57
+ }}
58
+ aria-expanded={showContent}
59
+ >
60
+ {children}
61
+ </div>
62
+ </div>
63
+ )
64
+ }