@docusaurus/theme-common 2.0.0-beta.1 → 2.0.0-beta.10
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/copyUntypedFiles.js +20 -0
- package/lib/.tsbuildinfo +1 -1
- package/lib/components/Collapsible/index.d.ts +35 -0
- package/lib/components/Collapsible/index.js +139 -0
- package/lib/components/Details/index.d.ts +12 -0
- package/lib/components/Details/index.js +64 -0
- package/lib/components/Details/styles.module.css +58 -0
- package/lib/index.d.ts +24 -4
- package/lib/index.js +18 -3
- package/lib/utils/ThemeClassNames.d.ts +36 -12
- package/lib/utils/ThemeClassNames.js +36 -3
- package/lib/utils/announcementBarUtils.d.ts +17 -0
- package/lib/utils/announcementBarUtils.js +69 -0
- package/lib/utils/codeBlockUtils.d.ts +10 -0
- package/lib/utils/codeBlockUtils.js +119 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +2 -2
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +2 -2
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +1 -3
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +11 -3
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +1 -2
- package/lib/utils/docsUtils.d.ts +20 -0
- package/lib/utils/docsUtils.js +106 -0
- package/lib/utils/generalUtils.d.ts +6 -0
- package/lib/utils/generalUtils.js +2 -2
- package/lib/utils/historyUtils.d.ts +11 -0
- package/lib/utils/historyUtils.js +39 -0
- package/lib/utils/jsUtils.d.ts +19 -0
- package/lib/utils/jsUtils.js +25 -0
- package/lib/utils/mobileSecondaryMenu.d.ts +20 -0
- package/lib/utils/mobileSecondaryMenu.js +49 -0
- package/lib/utils/pathUtils.js +1 -3
- package/lib/utils/reactUtils.d.ts +9 -0
- package/lib/utils/reactUtils.js +26 -0
- package/lib/utils/regexpUtils.d.ts +10 -0
- package/lib/utils/regexpUtils.js +16 -0
- package/lib/utils/scrollUtils.d.ts +52 -0
- package/lib/utils/scrollUtils.js +135 -0
- package/lib/utils/storageUtils.d.ts +4 -0
- package/lib/utils/storageUtils.js +29 -3
- package/lib/utils/tagsUtils.d.ts +18 -0
- package/lib/utils/tagsUtils.js +33 -0
- package/lib/utils/tocUtils.d.ts +15 -0
- package/lib/utils/tocUtils.js +34 -0
- package/lib/utils/useContextualSearchFilters.d.ts +11 -0
- package/lib/utils/useContextualSearchFilters.js +36 -0
- package/lib/utils/{useChangeRoute.d.ts → useLocalPathname.d.ts} +1 -1
- package/lib/utils/useLocalPathname.js +16 -0
- package/lib/utils/useLocationChange.d.ts +14 -0
- package/lib/utils/useLocationChange.js +23 -0
- package/lib/utils/usePluralForm.js +1 -3
- package/{src/utils/docsUtils.ts → lib/utils/usePrevious.d.ts} +1 -5
- package/lib/utils/usePrevious.js +15 -0
- package/lib/utils/useTOCHighlight.d.ts +14 -0
- package/lib/utils/useTOCHighlight.js +124 -0
- package/lib/utils/useThemeConfig.d.ts +21 -3
- package/package.json +18 -12
- package/src/components/Collapsible/index.tsx +242 -0
- package/src/components/Details/index.tsx +94 -0
- package/src/components/Details/styles.module.css +58 -0
- package/src/index.ts +73 -3
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +42 -4
- package/src/utils/__tests__/codeBlockUtils.test.ts +2 -2
- package/src/utils/__tests__/docsUtils.test.tsx +331 -0
- package/src/utils/__tests__/jsUtils.test.ts +33 -0
- package/src/utils/__tests__/tagUtils.test.ts +66 -0
- package/src/utils/__tests__/tocUtils.test.ts +197 -0
- package/src/utils/announcementBarUtils.tsx +120 -0
- package/src/utils/codeBlockUtils.ts +151 -0
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +7 -6
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +2 -3
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +14 -14
- package/src/utils/docsUtils.tsx +185 -0
- package/src/utils/generalUtils.ts +3 -2
- package/src/utils/historyUtils.ts +50 -0
- package/src/utils/jsUtils.ts +33 -0
- package/src/utils/mobileSecondaryMenu.tsx +114 -0
- package/src/utils/pathUtils.ts +2 -3
- package/src/utils/reactUtils.tsx +34 -0
- package/src/utils/regexpUtils.ts +23 -0
- package/src/utils/scrollUtils.tsx +237 -0
- package/src/utils/storageUtils.ts +27 -4
- package/src/utils/tagsUtils.ts +48 -0
- package/src/utils/tocUtils.ts +55 -0
- package/src/utils/useAlternatePageUtils.ts +9 -1
- package/src/utils/useContextualSearchFilters.ts +50 -0
- package/src/utils/useLocalPathname.ts +20 -0
- package/src/utils/useLocationChange.ts +35 -0
- package/src/utils/usePluralForm.ts +5 -4
- package/src/utils/usePrevious.ts +19 -0
- package/src/utils/useTOCHighlight.ts +179 -0
- package/src/utils/useThemeConfig.ts +20 -3
- package/lib/utils/useChangeRoute.js +0 -18
- package/src/utils/useChangeRoute.ts +0 -21
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
9
|
+
import React, {
|
|
10
|
+
useState,
|
|
11
|
+
useEffect,
|
|
12
|
+
useRef,
|
|
13
|
+
useCallback,
|
|
14
|
+
RefObject,
|
|
15
|
+
Dispatch,
|
|
16
|
+
SetStateAction,
|
|
17
|
+
ReactNode,
|
|
18
|
+
useLayoutEffect,
|
|
19
|
+
} from 'react';
|
|
20
|
+
|
|
21
|
+
const DefaultAnimationEasing = 'ease-in-out';
|
|
22
|
+
|
|
23
|
+
export type UseCollapsibleConfig = {
|
|
24
|
+
initialState: boolean | (() => boolean);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type UseCollapsibleReturns = {
|
|
28
|
+
collapsed: boolean;
|
|
29
|
+
setCollapsed: Dispatch<SetStateAction<boolean>>;
|
|
30
|
+
toggleCollapsed: () => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// This hook just define the state
|
|
34
|
+
export function useCollapsible({
|
|
35
|
+
initialState,
|
|
36
|
+
}: UseCollapsibleConfig): UseCollapsibleReturns {
|
|
37
|
+
const [collapsed, setCollapsed] = useState(initialState ?? false);
|
|
38
|
+
|
|
39
|
+
const toggleCollapsed = useCallback(() => {
|
|
40
|
+
setCollapsed((expanded) => !expanded);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
collapsed,
|
|
45
|
+
setCollapsed,
|
|
46
|
+
toggleCollapsed,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const CollapsedStyles = {
|
|
51
|
+
display: 'none',
|
|
52
|
+
overflow: 'hidden',
|
|
53
|
+
height: '0px',
|
|
54
|
+
} as const;
|
|
55
|
+
|
|
56
|
+
const ExpandedStyles = {
|
|
57
|
+
display: 'block',
|
|
58
|
+
overflow: 'visible',
|
|
59
|
+
height: 'auto',
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
function applyCollapsedStyle(el: HTMLElement, collapsed: boolean) {
|
|
63
|
+
const collapsedStyles = collapsed ? CollapsedStyles : ExpandedStyles;
|
|
64
|
+
el.style.display = collapsedStyles.display;
|
|
65
|
+
el.style.overflow = collapsedStyles.overflow;
|
|
66
|
+
el.style.height = collapsedStyles.height;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
Lex111: Dynamic transition duration is used in Material design, this technique is good for a large number of items.
|
|
71
|
+
https://material.io/archive/guidelines/motion/duration-easing.html#duration-easing-dynamic-durations
|
|
72
|
+
https://github.com/mui-org/material-ui/blob/e724d98eba018e55e1a684236a2037e24bcf050c/packages/material-ui/src/styles/createTransitions.js#L40-L43
|
|
73
|
+
*/
|
|
74
|
+
function getAutoHeightDuration(height: number) {
|
|
75
|
+
const constant = height / 36;
|
|
76
|
+
return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type CollapsibleAnimationConfig = {
|
|
80
|
+
duration?: number;
|
|
81
|
+
easing?: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
function useCollapseAnimation({
|
|
85
|
+
collapsibleRef,
|
|
86
|
+
collapsed,
|
|
87
|
+
animation,
|
|
88
|
+
}: {
|
|
89
|
+
collapsibleRef: RefObject<HTMLElement>;
|
|
90
|
+
collapsed: boolean;
|
|
91
|
+
animation?: CollapsibleAnimationConfig;
|
|
92
|
+
}) {
|
|
93
|
+
const mounted = useRef(false);
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
const el = collapsibleRef.current!;
|
|
97
|
+
|
|
98
|
+
function getTransitionStyles() {
|
|
99
|
+
const height = el.scrollHeight;
|
|
100
|
+
const duration = animation?.duration ?? getAutoHeightDuration(height);
|
|
101
|
+
const easing = animation?.easing ?? DefaultAnimationEasing;
|
|
102
|
+
return {
|
|
103
|
+
transition: `height ${duration}ms ${easing}`,
|
|
104
|
+
height: `${height}px`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function applyTransitionStyles() {
|
|
109
|
+
const transitionStyles = getTransitionStyles();
|
|
110
|
+
el.style.transition = transitionStyles.transition;
|
|
111
|
+
el.style.height = transitionStyles.height;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// On mount, we just apply styles, no animated transition
|
|
115
|
+
if (!mounted.current) {
|
|
116
|
+
applyCollapsedStyle(el, collapsed);
|
|
117
|
+
mounted.current = true;
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
el.style.willChange = 'height';
|
|
122
|
+
|
|
123
|
+
function startAnimation() {
|
|
124
|
+
const animationFrame = requestAnimationFrame(() => {
|
|
125
|
+
// When collapsing
|
|
126
|
+
if (collapsed) {
|
|
127
|
+
applyTransitionStyles();
|
|
128
|
+
|
|
129
|
+
requestAnimationFrame(() => {
|
|
130
|
+
el.style.height = CollapsedStyles.height;
|
|
131
|
+
el.style.overflow = CollapsedStyles.overflow;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// When expanding
|
|
135
|
+
else {
|
|
136
|
+
el.style.display = 'block';
|
|
137
|
+
requestAnimationFrame(() => {
|
|
138
|
+
applyTransitionStyles();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return () => cancelAnimationFrame(animationFrame);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return startAnimation();
|
|
147
|
+
}, [collapsibleRef, collapsed, animation]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type CollapsibleElementType = React.ElementType<
|
|
151
|
+
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
// Prevent hydration layout shift before anims are handled imperatively with JS
|
|
155
|
+
function getSSRStyle(collapsed: boolean) {
|
|
156
|
+
if (ExecutionEnvironment.canUseDOM) {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
return collapsed ? CollapsedStyles : ExpandedStyles;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
type CollapsibleBaseProps = {
|
|
163
|
+
as?: CollapsibleElementType;
|
|
164
|
+
collapsed: boolean;
|
|
165
|
+
children: ReactNode;
|
|
166
|
+
animation?: CollapsibleAnimationConfig;
|
|
167
|
+
onCollapseTransitionEnd?: (collapsed: boolean) => void;
|
|
168
|
+
className?: string;
|
|
169
|
+
|
|
170
|
+
// This is mostly useful for details/summary component where ssrStyle is not needed (as details are hidden natively)
|
|
171
|
+
// and can mess-up with the default native behavior of the browser when JS fails to load or is disabled
|
|
172
|
+
disableSSRStyle?: boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
function CollapsibleBase({
|
|
176
|
+
as: As = 'div',
|
|
177
|
+
collapsed,
|
|
178
|
+
children,
|
|
179
|
+
animation,
|
|
180
|
+
onCollapseTransitionEnd,
|
|
181
|
+
className,
|
|
182
|
+
disableSSRStyle,
|
|
183
|
+
}: CollapsibleBaseProps) {
|
|
184
|
+
// any because TS is a pain for HTML element refs, see https://twitter.com/sebastienlorber/status/1412784677795110914
|
|
185
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
186
|
+
const collapsibleRef = useRef<any>(null);
|
|
187
|
+
|
|
188
|
+
useCollapseAnimation({collapsibleRef, collapsed, animation});
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<As
|
|
192
|
+
// @ts-expect-error: the "too complicated type" is produced from "CollapsibleElementType" being a huge union
|
|
193
|
+
ref={collapsibleRef}
|
|
194
|
+
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
|
195
|
+
onTransitionEnd={(e: React.TransitionEvent) => {
|
|
196
|
+
if (e.propertyName !== 'height') {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
applyCollapsedStyle(collapsibleRef.current!, collapsed);
|
|
201
|
+
onCollapseTransitionEnd?.(collapsed);
|
|
202
|
+
}}
|
|
203
|
+
className={className}>
|
|
204
|
+
{children}
|
|
205
|
+
</As>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
|
|
210
|
+
const [mounted, setMounted] = useState(!collapsed);
|
|
211
|
+
|
|
212
|
+
useLayoutEffect(() => {
|
|
213
|
+
if (!collapsed) {
|
|
214
|
+
setMounted(true);
|
|
215
|
+
}
|
|
216
|
+
}, [collapsed]);
|
|
217
|
+
|
|
218
|
+
// lazyCollapsed updated in effect so that the first expansion transition can work
|
|
219
|
+
const [lazyCollapsed, setLazyCollapsed] = useState(collapsed);
|
|
220
|
+
useLayoutEffect(() => {
|
|
221
|
+
if (mounted) {
|
|
222
|
+
setLazyCollapsed(collapsed);
|
|
223
|
+
}
|
|
224
|
+
}, [mounted, collapsed]);
|
|
225
|
+
|
|
226
|
+
return mounted ? (
|
|
227
|
+
<CollapsibleBase {...props} collapsed={lazyCollapsed} />
|
|
228
|
+
) : null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
type CollapsibleProps = CollapsibleBaseProps & {
|
|
232
|
+
// Lazy allows to delay the rendering when collapsed => it will render children only after hydration, on first expansion
|
|
233
|
+
// Required prop: it forces to think if content should be server-rendered or not!
|
|
234
|
+
// This has perf impact on the SSR output and html file sizes
|
|
235
|
+
// See https://github.com/facebook/docusaurus/issues/4753
|
|
236
|
+
lazy: boolean;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
export function Collapsible({lazy, ...props}: CollapsibleProps): JSX.Element {
|
|
240
|
+
const Comp = lazy ? CollapsibleLazy : CollapsibleBase;
|
|
241
|
+
return <Comp {...props} />;
|
|
242
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, {ComponentProps, ReactElement, useRef, useState} from 'react';
|
|
9
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
import {useCollapsible, Collapsible} from '../Collapsible';
|
|
12
|
+
import styles from './styles.module.css';
|
|
13
|
+
|
|
14
|
+
function isInSummary(node: HTMLElement | null): boolean {
|
|
15
|
+
if (!node) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return node.tagName === 'SUMMARY' || isInSummary(node.parentElement);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function hasParent(node: HTMLElement | null, parent: HTMLElement): boolean {
|
|
22
|
+
if (!node) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return node === parent || hasParent(node.parentElement, parent);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type DetailsProps = {
|
|
29
|
+
summary?: ReactElement;
|
|
30
|
+
} & ComponentProps<'details'>;
|
|
31
|
+
|
|
32
|
+
function Details({summary, children, ...props}: DetailsProps): JSX.Element {
|
|
33
|
+
const isBrowser = useIsBrowser();
|
|
34
|
+
const detailsRef = useRef<HTMLDetailsElement>(null);
|
|
35
|
+
|
|
36
|
+
const {collapsed, setCollapsed} = useCollapsible({
|
|
37
|
+
initialState: !props.open,
|
|
38
|
+
});
|
|
39
|
+
// We use a separate prop because it must be set only after animation completes
|
|
40
|
+
// Otherwise close anim won't work
|
|
41
|
+
const [open, setOpen] = useState(props.open);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<details
|
|
45
|
+
{...props}
|
|
46
|
+
ref={detailsRef}
|
|
47
|
+
open={open}
|
|
48
|
+
data-collapsed={collapsed}
|
|
49
|
+
className={clsx(
|
|
50
|
+
styles.details,
|
|
51
|
+
{[styles.isBrowser]: isBrowser},
|
|
52
|
+
props.className,
|
|
53
|
+
)}
|
|
54
|
+
onMouseDown={(e) => {
|
|
55
|
+
const target = e.target as HTMLElement;
|
|
56
|
+
// Prevent a double-click to highlight summary text
|
|
57
|
+
if (isInSummary(target) && e.detail > 1) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
}
|
|
60
|
+
}}
|
|
61
|
+
onClick={(e) => {
|
|
62
|
+
e.stopPropagation(); // For isolation of multiple nested details/summary
|
|
63
|
+
const target = e.target as HTMLElement;
|
|
64
|
+
const shouldToggle =
|
|
65
|
+
isInSummary(target) && hasParent(target, detailsRef.current!);
|
|
66
|
+
if (!shouldToggle) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
if (collapsed) {
|
|
71
|
+
setCollapsed(false);
|
|
72
|
+
setOpen(true);
|
|
73
|
+
} else {
|
|
74
|
+
setCollapsed(true);
|
|
75
|
+
// setOpen(false); // Don't do this, it breaks close animation!
|
|
76
|
+
}
|
|
77
|
+
}}>
|
|
78
|
+
{summary}
|
|
79
|
+
|
|
80
|
+
<Collapsible
|
|
81
|
+
lazy={false} // Content might matter for SEO in this case
|
|
82
|
+
collapsed={collapsed}
|
|
83
|
+
disableSSRStyle // Allows component to work fine even with JS disabled!
|
|
84
|
+
onCollapseTransitionEnd={(newCollapsed) => {
|
|
85
|
+
setCollapsed(newCollapsed);
|
|
86
|
+
setOpen(!newCollapsed);
|
|
87
|
+
}}>
|
|
88
|
+
<div className={styles.collapsibleContent}>{children}</div>
|
|
89
|
+
</Collapsible>
|
|
90
|
+
</details>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default Details;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
CSS variables, meant to be overriden by final theme
|
|
10
|
+
*/
|
|
11
|
+
.details {
|
|
12
|
+
--docusaurus-details-summary-arrow-size: 0.38rem;
|
|
13
|
+
--docusaurus-details-transition: transform 200ms ease;
|
|
14
|
+
--docusaurus-details-decoration-color: grey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.details > summary {
|
|
18
|
+
position: relative;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
list-style: none;
|
|
21
|
+
padding-left: 1rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* TODO: deprecation, need to remove this after Safari will support `::marker` */
|
|
25
|
+
.details > summary::-webkit-details-marker {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.details > summary:before {
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: 0.45rem;
|
|
32
|
+
left: 0;
|
|
33
|
+
|
|
34
|
+
/* CSS-only Arrow */
|
|
35
|
+
content: '';
|
|
36
|
+
border-width: var(--docusaurus-details-summary-arrow-size);
|
|
37
|
+
border-style: solid;
|
|
38
|
+
border-color: transparent transparent transparent
|
|
39
|
+
var(--docusaurus-details-decoration-color);
|
|
40
|
+
|
|
41
|
+
/* Arrow rotation anim */
|
|
42
|
+
transform: rotate(0deg);
|
|
43
|
+
transition: var(--docusaurus-details-transition);
|
|
44
|
+
transform-origin: calc(var(--docusaurus-details-summary-arrow-size) / 2) 50%;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* When JS disabled/failed to load: we use the open property for arrow animation: */
|
|
48
|
+
.details[open]:not(.isBrowser) > summary:before,
|
|
49
|
+
/* When JS works: we use the data-attribute for arrow animation */
|
|
50
|
+
.details[data-collapsed='false'].isBrowser > summary:before {
|
|
51
|
+
transform: rotate(90deg);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.collapsibleContent {
|
|
55
|
+
margin-top: 1rem;
|
|
56
|
+
border-top: 1px solid var(--docusaurus-details-decoration-color);
|
|
57
|
+
padding-top: 1rem;
|
|
58
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,23 +9,42 @@ export {useThemeConfig} from './utils/useThemeConfig';
|
|
|
9
9
|
|
|
10
10
|
export type {
|
|
11
11
|
ThemeConfig,
|
|
12
|
+
UserThemeConfig,
|
|
12
13
|
Navbar,
|
|
13
14
|
NavbarItem,
|
|
14
15
|
NavbarLogo,
|
|
15
16
|
Footer,
|
|
16
17
|
FooterLinks,
|
|
17
18
|
FooterLinkItem,
|
|
19
|
+
ColorModeConfig,
|
|
18
20
|
} from './utils/useThemeConfig';
|
|
19
21
|
|
|
20
22
|
export {createStorageSlot, listStorageKeys} from './utils/storageUtils';
|
|
21
23
|
|
|
22
24
|
export {useAlternatePageUtils} from './utils/useAlternatePageUtils';
|
|
23
25
|
|
|
24
|
-
export {
|
|
26
|
+
export {useContextualSearchFilters} from './utils/useContextualSearchFilters';
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
parseCodeBlockTitle,
|
|
30
|
+
parseLanguage,
|
|
31
|
+
parseLines,
|
|
32
|
+
} from './utils/codeBlockUtils';
|
|
25
33
|
|
|
26
34
|
export {docVersionSearchTag, DEFAULT_SEARCH_TAG} from './utils/searchUtils';
|
|
27
35
|
|
|
28
|
-
export {
|
|
36
|
+
export {
|
|
37
|
+
isDocsPluginEnabled,
|
|
38
|
+
DocsVersionProvider,
|
|
39
|
+
useDocsVersion,
|
|
40
|
+
useDocById,
|
|
41
|
+
DocsSidebarProvider,
|
|
42
|
+
useDocsSidebar,
|
|
43
|
+
findSidebarCategory,
|
|
44
|
+
findFirstCategoryLink,
|
|
45
|
+
useCurrentSidebarCategory,
|
|
46
|
+
isActiveSidebarItem,
|
|
47
|
+
} from './utils/docsUtils';
|
|
29
48
|
|
|
30
49
|
export {isSamePath} from './utils/pathUtils';
|
|
31
50
|
|
|
@@ -33,13 +52,64 @@ export {useTitleFormatter} from './utils/generalUtils';
|
|
|
33
52
|
|
|
34
53
|
export {usePluralForm} from './utils/usePluralForm';
|
|
35
54
|
|
|
36
|
-
export {
|
|
55
|
+
export {useLocationChange} from './utils/useLocationChange';
|
|
56
|
+
|
|
57
|
+
export {usePrevious} from './utils/usePrevious';
|
|
58
|
+
|
|
59
|
+
export {useCollapsible, Collapsible} from './components/Collapsible';
|
|
60
|
+
export type {
|
|
61
|
+
UseCollapsibleConfig,
|
|
62
|
+
UseCollapsibleReturns,
|
|
63
|
+
} from './components/Collapsible';
|
|
64
|
+
|
|
65
|
+
export {default as Details} from './components/Details';
|
|
66
|
+
export type {DetailsProps} from './components/Details';
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
MobileSecondaryMenuProvider,
|
|
70
|
+
MobileSecondaryMenuFiller,
|
|
71
|
+
useMobileSecondaryMenuRenderer,
|
|
72
|
+
} from './utils/mobileSecondaryMenu';
|
|
73
|
+
export type {MobileSecondaryMenuComponent} from './utils/mobileSecondaryMenu';
|
|
37
74
|
|
|
38
75
|
export {
|
|
39
76
|
useDocsPreferredVersion,
|
|
40
77
|
useDocsPreferredVersionByPluginId,
|
|
41
78
|
} from './utils/docsPreferredVersion/useDocsPreferredVersion';
|
|
42
79
|
|
|
80
|
+
export {duplicates, uniq} from './utils/jsUtils';
|
|
81
|
+
|
|
43
82
|
export {DocsPreferredVersionContextProvider} from './utils/docsPreferredVersion/DocsPreferredVersionProvider';
|
|
44
83
|
|
|
45
84
|
export {ThemeClassNames} from './utils/ThemeClassNames';
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
AnnouncementBarProvider,
|
|
88
|
+
useAnnouncementBar,
|
|
89
|
+
} from './utils/announcementBarUtils';
|
|
90
|
+
|
|
91
|
+
export {useLocalPathname} from './utils/useLocalPathname';
|
|
92
|
+
|
|
93
|
+
export {translateTagsPageTitle, listTagsByLetters} from './utils/tagsUtils';
|
|
94
|
+
export type {TagLetterEntry} from './utils/tagsUtils';
|
|
95
|
+
|
|
96
|
+
export {useHistoryPopHandler} from './utils/historyUtils';
|
|
97
|
+
|
|
98
|
+
export {default as useTOCHighlight} from './utils/useTOCHighlight';
|
|
99
|
+
export type {TOCHighlightConfig} from './utils/useTOCHighlight';
|
|
100
|
+
|
|
101
|
+
export {useTOCFilter} from './utils/tocUtils';
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
ScrollControllerProvider,
|
|
105
|
+
useScrollController,
|
|
106
|
+
useScrollPosition,
|
|
107
|
+
useScrollPositionBlocker,
|
|
108
|
+
} from './utils/scrollUtils';
|
|
109
|
+
|
|
110
|
+
export {
|
|
111
|
+
useIsomorphicLayoutEffect,
|
|
112
|
+
useDynamicCallback,
|
|
113
|
+
} from './utils/reactUtils';
|
|
114
|
+
|
|
115
|
+
export {isRegexpStringMatch} from './utils/regexpUtils';
|
package/src/types.d.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/* eslint-disable import/no-duplicates */
|
|
9
|
-
/* eslint-disable spaced-comment */
|
|
10
8
|
/// <reference types="@docusaurus/module-type-aliases" />
|
|
11
9
|
/// <reference types="@docusaurus/plugin-content-blog" />
|
|
12
10
|
/// <reference types="@docusaurus/plugin-content-docs" />
|
|
@@ -6,19 +6,57 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// These class names are used to style page layouts in Docusaurus
|
|
9
|
+
// Those are meant to be targeted by user-provided custom CSS selectors
|
|
10
|
+
// /!\ Please do not modify the classnames! This is a breaking change, and annoying for users!
|
|
9
11
|
export const ThemeClassNames = {
|
|
10
12
|
page: {
|
|
11
13
|
blogListPage: 'blog-list-page',
|
|
12
14
|
blogPostPage: 'blog-post-page',
|
|
13
15
|
blogTagsListPage: 'blog-tags-list-page',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
blogTagPostListPage: 'blog-tags-post-list-page',
|
|
17
|
+
|
|
18
|
+
docsDocPage: 'docs-doc-page',
|
|
19
|
+
docsTagsListPage: 'docs-tags-list-page', // List of tags
|
|
20
|
+
docsTagDocListPage: 'docs-tags-doc-list-page', // Docs for a tag
|
|
21
|
+
|
|
16
22
|
mdxPage: 'mdx-page',
|
|
17
23
|
},
|
|
18
24
|
wrapper: {
|
|
19
25
|
main: 'main-wrapper',
|
|
20
26
|
blogPages: 'blog-wrapper',
|
|
21
|
-
|
|
27
|
+
docsPages: 'docs-wrapper',
|
|
22
28
|
mdxPages: 'mdx-wrapper',
|
|
23
29
|
},
|
|
24
|
-
|
|
30
|
+
|
|
31
|
+
// /!\ Please keep the naming convention consistent!
|
|
32
|
+
// Something like: "theme-{blog,doc,version,page}?-<suffix>"
|
|
33
|
+
common: {
|
|
34
|
+
editThisPage: 'theme-edit-this-page',
|
|
35
|
+
lastUpdated: 'theme-last-updated',
|
|
36
|
+
backToTopButton: 'theme-back-to-top-button',
|
|
37
|
+
},
|
|
38
|
+
layout: {
|
|
39
|
+
// TODO add other stable classNames here
|
|
40
|
+
},
|
|
41
|
+
docs: {
|
|
42
|
+
docVersionBanner: 'theme-doc-version-banner',
|
|
43
|
+
docVersionBadge: 'theme-doc-version-badge',
|
|
44
|
+
docMarkdown: 'theme-doc-markdown',
|
|
45
|
+
docTocMobile: 'theme-doc-toc-mobile',
|
|
46
|
+
docTocDesktop: 'theme-doc-toc-desktop',
|
|
47
|
+
docFooter: 'theme-doc-footer',
|
|
48
|
+
docFooterTagsRow: 'theme-doc-footer-tags-row',
|
|
49
|
+
docFooterEditMetaRow: 'theme-doc-footer-edit-meta-row',
|
|
50
|
+
docSidebarMenu: 'theme-doc-sidebar-menu',
|
|
51
|
+
docSidebarItemCategory: 'theme-doc-sidebar-item-category',
|
|
52
|
+
docSidebarItemLink: 'theme-doc-sidebar-item-link',
|
|
53
|
+
docSidebarItemCategoryLevel: (level: number) =>
|
|
54
|
+
`theme-doc-sidebar-item-category-level-${level}` as const,
|
|
55
|
+
docSidebarItemLinkLevel: (level: number) =>
|
|
56
|
+
`theme-doc-sidebar-item-link-level-${level}` as const,
|
|
57
|
+
// TODO add other stable classNames here
|
|
58
|
+
},
|
|
59
|
+
blog: {
|
|
60
|
+
// TODO add other stable classNames here
|
|
61
|
+
},
|
|
62
|
+
} as const;
|
|
@@ -28,13 +28,13 @@ describe('parseCodeBlockTitle', () => {
|
|
|
28
28
|
expect(parseCodeBlockTitle(`{1,2-3}`)).toEqual(``);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
test('should parse with multiple
|
|
31
|
+
test('should parse with multiple metadata title first', () => {
|
|
32
32
|
expect(parseCodeBlockTitle(`title="index.js" label="JavaScript"`)).toEqual(
|
|
33
33
|
`index.js`,
|
|
34
34
|
);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
test('should parse with multiple
|
|
37
|
+
test('should parse with multiple metadata title last', () => {
|
|
38
38
|
expect(parseCodeBlockTitle(`label="JavaScript" title="index.js"`)).toEqual(
|
|
39
39
|
`index.js`,
|
|
40
40
|
);
|