@docusaurus/core 0.0.0-4923 → 0.0.0-4927

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.
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  /// <reference types="react" />
8
- import './clientLifecyclesDispatcher';
8
+ import '@generated/client-modules';
9
9
  export default function App(): JSX.Element;
package/lib/client/App.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
+ import '@generated/client-modules';
8
9
  import routes from '@generated/routes';
9
10
  import { useLocation } from '@docusaurus/router';
10
11
  import normalizeLocation from './normalizeLocation';
@@ -16,7 +17,6 @@ import BaseUrlIssueBanner from './BaseUrlIssueBanner';
16
17
  import SiteMetadataDefaults from './SiteMetadataDefaults';
17
18
  import Root from '@theme/Root';
18
19
  import SiteMetadata from '@theme/SiteMetadata';
19
- import './clientLifecyclesDispatcher';
20
20
  // TODO, quick fix for CSS insertion order
21
21
  import ErrorBoundary from '@docusaurus/ErrorBoundary';
22
22
  import Error from '@theme/Error';
@@ -30,7 +30,7 @@ export default function App() {
30
30
  <SiteMetadataDefaults />
31
31
  <SiteMetadata />
32
32
  <BaseUrlIssueBanner />
33
- <PendingNavigation location={normalizeLocation(location)} delay={200}>
33
+ <PendingNavigation location={normalizeLocation(location)}>
34
34
  {routeElement}
35
35
  </PendingNavigation>
36
36
  </Root>
@@ -0,0 +1,16 @@
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
+ import { type ReactElement } from 'react';
8
+ import type { ClientModule } from '@docusaurus/types';
9
+ import type { Location } from 'history';
10
+ export declare function dispatchLifecycleAction<K extends keyof ClientModule>(lifecycleAction: K, ...args: Parameters<NonNullable<ClientModule[K]>>): () => void;
11
+ declare function ClientLifecyclesDispatcher({ children, location, previousLocation, }: {
12
+ children: ReactElement;
13
+ location: Location;
14
+ previousLocation: Location | null;
15
+ }): JSX.Element;
16
+ export default ClientLifecyclesDispatcher;
@@ -0,0 +1,34 @@
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
+ import { useLayoutEffect } from 'react';
8
+ import clientModules from '@generated/client-modules';
9
+ export function dispatchLifecycleAction(lifecycleAction, ...args) {
10
+ const callbacks = clientModules.map((clientModule) => {
11
+ const lifecycleFunction = (clientModule?.default?.[lifecycleAction] ??
12
+ clientModule[lifecycleAction]);
13
+ return lifecycleFunction?.(...args);
14
+ });
15
+ return () => callbacks.forEach((cb) => cb?.());
16
+ }
17
+ function ClientLifecyclesDispatcher({ children, location, previousLocation, }) {
18
+ useLayoutEffect(() => {
19
+ if (previousLocation !== location) {
20
+ const { hash } = location;
21
+ if (!hash) {
22
+ window.scrollTo(0, 0);
23
+ }
24
+ else {
25
+ const id = decodeURIComponent(hash.substring(1));
26
+ const element = document.getElementById(id);
27
+ element?.scrollIntoView();
28
+ }
29
+ dispatchLifecycleAction('onRouteDidUpdate', { previousLocation, location });
30
+ }
31
+ }, [previousLocation, location]);
32
+ return children;
33
+ }
34
+ export default ClientLifecyclesDispatcher;
@@ -6,9 +6,7 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import type { Location } from 'history';
9
- import './nprogress.css';
10
9
  declare type Props = {
11
- readonly delay: number;
12
10
  readonly location: Location;
13
11
  readonly children: JSX.Element;
14
12
  };
@@ -17,12 +15,9 @@ declare type State = {
17
15
  };
18
16
  declare class PendingNavigation extends React.Component<Props, State> {
19
17
  private previousLocation;
20
- private progressBarTimeout;
18
+ private routeUpdateCleanupCb;
21
19
  constructor(props: Props);
22
20
  shouldComponentUpdate(nextProps: Props, nextState: State): boolean;
23
- private clearProgressBarTimeout;
24
- private startProgressBar;
25
- private stopProgressBar;
26
21
  render(): JSX.Element;
27
22
  }
28
23
  export default PendingNavigation;
@@ -6,17 +6,20 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import { Route } from 'react-router-dom';
9
- import nprogress from 'nprogress';
10
- import clientLifecyclesDispatcher from './clientLifecyclesDispatcher';
9
+ import ClientLifecyclesDispatcher, { dispatchLifecycleAction, } from './ClientLifecyclesDispatcher';
10
+ import ExecutionEnvironment from './exports/ExecutionEnvironment';
11
11
  import preload from './preload';
12
- import './nprogress.css';
13
- nprogress.configure({ showSpinner: false });
14
12
  class PendingNavigation extends React.Component {
15
13
  constructor(props) {
16
14
  super(props);
17
15
  // previousLocation doesn't affect rendering, hence not stored in state.
18
16
  this.previousLocation = null;
19
- this.progressBarTimeout = null;
17
+ this.routeUpdateCleanupCb = ExecutionEnvironment.canUseDOM
18
+ ? dispatchLifecycleAction('onRouteUpdate', {
19
+ previousLocation: null,
20
+ location: this.props.location,
21
+ })
22
+ : () => { };
20
23
  this.state = {
21
24
  nextRouteHasLoaded: true,
22
25
  };
@@ -35,52 +38,26 @@ class PendingNavigation extends React.Component {
35
38
  // Save the location first.
36
39
  this.previousLocation = this.props.location;
37
40
  this.setState({ nextRouteHasLoaded: false });
38
- this.startProgressBar();
41
+ this.routeUpdateCleanupCb = dispatchLifecycleAction('onRouteUpdate', {
42
+ previousLocation: this.previousLocation,
43
+ location: nextLocation,
44
+ });
39
45
  // Load data while the old screen remains.
40
46
  preload(nextLocation.pathname)
41
47
  .then(() => {
42
- clientLifecyclesDispatcher.onRouteUpdate({
43
- previousLocation: this.previousLocation,
44
- location: nextLocation,
45
- });
46
- this.setState({ nextRouteHasLoaded: true }, this.stopProgressBar);
47
- const { hash } = nextLocation;
48
- if (!hash) {
49
- window.scrollTo(0, 0);
50
- }
51
- else {
52
- const id = decodeURIComponent(hash.substring(1));
53
- const element = document.getElementById(id);
54
- element?.scrollIntoView();
55
- }
48
+ this.routeUpdateCleanupCb?.();
49
+ this.setState({ nextRouteHasLoaded: true });
56
50
  })
57
51
  .catch((e) => console.warn(e));
58
52
  return false;
59
53
  }
60
- clearProgressBarTimeout() {
61
- if (this.progressBarTimeout) {
62
- window.clearTimeout(this.progressBarTimeout);
63
- this.progressBarTimeout = null;
64
- }
65
- }
66
- startProgressBar() {
67
- this.clearProgressBarTimeout();
68
- this.progressBarTimeout = window.setTimeout(() => {
69
- clientLifecyclesDispatcher.onRouteUpdateDelayed({
70
- location: this.props.location,
71
- });
72
- nprogress.start();
73
- }, this.props.delay);
74
- }
75
- stopProgressBar() {
76
- this.clearProgressBarTimeout();
77
- nprogress.done();
78
- }
79
54
  render() {
80
55
  const { children, location } = this.props;
81
56
  // Use a controlled <Route> to trick all descendants into rendering the old
82
57
  // location.
83
- return <Route location={location} render={() => children}/>;
58
+ return (<ClientLifecyclesDispatcher previousLocation={this.previousLocation} location={location}>
59
+ <Route location={location} render={() => children}/>
60
+ </ClientLifecyclesDispatcher>);
84
61
  }
85
62
  }
86
63
  export default PendingNavigation;
@@ -4,6 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ // Should we translate theme-fallback?
8
+ /* eslint-disable @docusaurus/no-untranslated-text */
7
9
  import React from 'react';
8
10
  import Layout from '@theme/Layout';
9
11
  import ErrorBoundary from '@docusaurus/ErrorBoundary';
@@ -4,6 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ // Should we translate theme-fallback?
8
+ /* eslint-disable @docusaurus/no-untranslated-text */
7
9
  import React from 'react';
8
10
  export default function Loading({ error, retry, pastDelay, }) {
9
11
  if (error) {
@@ -4,6 +4,8 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ // Should we translate theme-fallback?
8
+ /* eslint-disable @docusaurus/no-untranslated-text */
7
9
  import React from 'react';
8
10
  import Layout from '@theme/Layout';
9
11
  import Head from '@docusaurus/Head';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "0.0.0-4923",
4
+ "version": "0.0.0-4927",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -41,13 +41,13 @@
41
41
  "@babel/runtime": "^7.17.9",
42
42
  "@babel/runtime-corejs3": "^7.17.9",
43
43
  "@babel/traverse": "^7.17.9",
44
- "@docusaurus/cssnano-preset": "0.0.0-4923",
45
- "@docusaurus/logger": "0.0.0-4923",
46
- "@docusaurus/mdx-loader": "0.0.0-4923",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4927",
45
+ "@docusaurus/logger": "0.0.0-4927",
46
+ "@docusaurus/mdx-loader": "0.0.0-4927",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4923",
49
- "@docusaurus/utils-common": "0.0.0-4923",
50
- "@docusaurus/utils-validation": "0.0.0-4923",
48
+ "@docusaurus/utils": "0.0.0-4927",
49
+ "@docusaurus/utils-common": "0.0.0-4927",
50
+ "@docusaurus/utils-validation": "0.0.0-4927",
51
51
  "@slorber/static-site-generator-webpack-plugin": "^4.0.4",
52
52
  "@svgr/webpack": "^6.2.1",
53
53
  "autoprefixer": "^10.4.4",
@@ -77,7 +77,6 @@
77
77
  "leven": "^3.1.0",
78
78
  "lodash": "^4.17.21",
79
79
  "mini-css-extract-plugin": "^2.6.0",
80
- "nprogress": "^0.2.0",
81
80
  "postcss": "^8.4.12",
82
81
  "postcss-loader": "^6.2.1",
83
82
  "prompts": "^2.4.2",
@@ -105,10 +104,9 @@
105
104
  "webpackbar": "^5.0.2"
106
105
  },
107
106
  "devDependencies": {
108
- "@docusaurus/module-type-aliases": "0.0.0-4923",
109
- "@docusaurus/types": "0.0.0-4923",
107
+ "@docusaurus/module-type-aliases": "0.0.0-4927",
108
+ "@docusaurus/types": "0.0.0-4927",
110
109
  "@types/detect-port": "^1.3.2",
111
- "@types/nprogress": "^0.2.0",
112
110
  "@types/react-dom": "^18.0.2",
113
111
  "@types/react-router-config": "^5.0.6",
114
112
  "@types/rtl-detect": "^1.0.0",
@@ -127,5 +125,5 @@
127
125
  "engines": {
128
126
  "node": ">=14"
129
127
  },
130
- "gitHead": "0d7f61e267384e2c272cc3c0df059bdfe16609fd"
128
+ "gitHead": "1c97d81e5046a346360d7c79d5c1e715b37a94d9"
131
129
  }
@@ -1,9 +0,0 @@
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
- import type { ClientModule } from '@docusaurus/types';
8
- declare const clientLifecyclesDispatchers: Required<ClientModule>;
9
- export default clientLifecyclesDispatchers;
@@ -1,23 +0,0 @@
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
- import clientModules from '@generated/client-modules';
8
- function dispatchLifecycleAction(lifecycleAction, args) {
9
- clientModules.forEach((clientModule) => {
10
- const lifecycleFunction = (clientModule?.default?.[lifecycleAction] ??
11
- clientModule[lifecycleAction]);
12
- lifecycleFunction?.(...args);
13
- });
14
- }
15
- const clientLifecyclesDispatchers = {
16
- onRouteUpdate(...args) {
17
- dispatchLifecycleAction('onRouteUpdate', args);
18
- },
19
- onRouteUpdateDelayed(...args) {
20
- dispatchLifecycleAction('onRouteUpdateDelayed', args);
21
- },
22
- };
23
- export default clientLifecyclesDispatchers;
@@ -1,36 +0,0 @@
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
- * Styles for NProgress
10
- * Copied over to remove unused styles for the spinner.
11
- * https://github.com/rstacruz/nprogress/blob/master/nprogress.css
12
- */
13
-
14
- #nprogress {
15
- pointer-events: none;
16
- }
17
-
18
- #nprogress .bar {
19
- background: #29d;
20
- position: fixed;
21
- z-index: 1031;
22
- top: 0;
23
- left: 0;
24
- width: 100%;
25
- height: 2px;
26
- }
27
-
28
- #nprogress .peg {
29
- position: absolute;
30
- right: 0;
31
- width: 100px;
32
- height: 100%;
33
- box-shadow: 0 0 10px #29d, 0 0 5px #29d;
34
- opacity: 1;
35
- transform: rotate(3deg) translate(0, -4px);
36
- }