@docusaurus/theme-classic 0.0.0-4432 → 0.0.0-4436

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/lib/index.js CHANGED
@@ -101,8 +101,7 @@ function getInfimaCSSFile(direction) {
101
101
  return `infima/dist/css/default/default${direction === 'rtl' ? '-rtl' : ''}.css`;
102
102
  }
103
103
 
104
- function docusaurusThemeClassic(context, // TODO: LoadContext is missing some of properties
105
- options) {
104
+ function docusaurusThemeClassic(context, options) {
106
105
  const {
107
106
  siteConfig: {
108
107
  themeConfig: roughlyTypedThemeConfig
@@ -178,7 +177,10 @@ options) {
178
177
  configureWebpack() {
179
178
  const prismLanguages = additionalLanguages.map(lang => `prism-${lang}`).join('|');
180
179
  return {
181
- plugins: [new ContextReplacementPlugin(/prismjs[\\/]components$/, new RegExp(`^./(${prismLanguages})$`))]
180
+ plugins: [// This allows better optimization by only bundling those components
181
+ // that the user actually needs, because the modules are dynamically
182
+ // required and can't be known during compile time.
183
+ new ContextReplacementPlugin(/prismjs[\\/]components$/, new RegExp(`^./(${prismLanguages})$`))]
182
184
  };
183
185
  },
184
186
 
@@ -37,9 +37,9 @@ export default function CodeBlock({
37
37
 
38
38
  useEffect(() => {
39
39
  setMounted(true);
40
- }, []); // TODO: the title is provided by MDX as props automatically
41
- // so we probably don't need to parse the metastring
42
- // (note: title="xyz" => title prop still has the quotes)
40
+ }, []); // We still parse the metastring in case we want to support more syntax in the
41
+ // future. Note that MDX doesn't strip quotes when parsing metastring:
42
+ // "title=\"xyz\"" => title: "\"xyz\""
43
43
 
44
44
  const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
45
45
  const prismTheme = usePrismTheme(); // <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
@@ -10,12 +10,19 @@ import siteConfig from '@generated/docusaurus.config';
10
10
  const prismIncludeLanguages = (PrismObject) => {
11
11
  if (ExecutionEnvironment.canUseDOM) {
12
12
  const {
13
- themeConfig: {prism = {}},
13
+ themeConfig: {prism},
14
14
  } = siteConfig;
15
- const {additionalLanguages = []} = prism;
15
+ const {additionalLanguages} = prism; // Prism components work on the Prism instance on the window, while
16
+ // prism-react-renderer uses its own Prism instance. We temporarily mount
17
+ // the instance onto window, import components to enhance it, then remove it
18
+ // to avoid polluting global namespace.
19
+ // You can mutate this object: registering plugins, deleting languages... As
20
+ // long as you don't re-assign it
21
+
16
22
  window.Prism = PrismObject;
17
23
  additionalLanguages.forEach((lang) => {
18
- require(`prismjs/components/prism-${lang}`); // eslint-disable-line
24
+ // eslint-disable-next-line global-require, import/no-dynamic-require
25
+ require(`prismjs/components/prism-${lang}`);
19
26
  });
20
27
  delete window.Prism;
21
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4432",
3
+ "version": "0.0.0-4436",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -23,14 +23,14 @@
23
23
  "update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
24
24
  },
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4432",
27
- "@docusaurus/plugin-content-blog": "0.0.0-4432",
28
- "@docusaurus/plugin-content-docs": "0.0.0-4432",
29
- "@docusaurus/plugin-content-pages": "0.0.0-4432",
30
- "@docusaurus/theme-common": "0.0.0-4432",
31
- "@docusaurus/theme-translations": "0.0.0-4432",
32
- "@docusaurus/utils": "0.0.0-4432",
33
- "@docusaurus/utils-validation": "0.0.0-4432",
26
+ "@docusaurus/core": "0.0.0-4436",
27
+ "@docusaurus/plugin-content-blog": "0.0.0-4436",
28
+ "@docusaurus/plugin-content-docs": "0.0.0-4436",
29
+ "@docusaurus/plugin-content-pages": "0.0.0-4436",
30
+ "@docusaurus/theme-common": "0.0.0-4436",
31
+ "@docusaurus/theme-translations": "0.0.0-4436",
32
+ "@docusaurus/utils": "0.0.0-4436",
33
+ "@docusaurus/utils-validation": "0.0.0-4436",
34
34
  "@mdx-js/mdx": "^1.6.21",
35
35
  "@mdx-js/react": "^1.6.21",
36
36
  "clsx": "^1.1.1",
@@ -45,8 +45,8 @@
45
45
  "rtlcss": "^3.3.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@docusaurus/module-type-aliases": "0.0.0-4432",
49
- "@docusaurus/types": "0.0.0-4432",
48
+ "@docusaurus/module-type-aliases": "0.0.0-4436",
49
+ "@docusaurus/types": "0.0.0-4436",
50
50
  "@types/mdx-js__react": "^1.5.4",
51
51
  "@types/parse-numeric-range": "^0.0.1",
52
52
  "@types/rtlcss": "^3.1.1",
@@ -61,5 +61,5 @@
61
61
  "engines": {
62
62
  "node": ">=14"
63
63
  },
64
- "gitHead": "1221cc7c66b95d2207c935645d303be70642514b"
64
+ "gitHead": "3b2e15935a716c69bd530fe10942e1620b36ddc4"
65
65
  }
package/src/index.ts CHANGED
@@ -5,11 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import type {
9
- DocusaurusContext,
10
- Plugin,
11
- PostCssOptions,
12
- } from '@docusaurus/types';
8
+ import type {LoadContext, Plugin, PostCssOptions} from '@docusaurus/types';
13
9
  import type {ThemeConfig} from '@docusaurus/theme-common';
14
10
  import {getTranslationFiles, translateThemeConfig} from './translations';
15
11
  import path from 'path';
@@ -18,13 +14,13 @@ import type {Plugin as PostCssPlugin} from 'postcss';
18
14
  import rtlcss from 'rtlcss';
19
15
  import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
20
16
  import type {Options} from '@docusaurus/theme-classic';
17
+ import type webpack from 'webpack';
21
18
 
22
19
  const requireFromDocusaurusCore = createRequire(
23
20
  require.resolve('@docusaurus/core/package.json'),
24
21
  );
25
- const ContextReplacementPlugin = requireFromDocusaurusCore(
26
- 'webpack/lib/ContextReplacementPlugin',
27
- );
22
+ const ContextReplacementPlugin: typeof webpack.ContextReplacementPlugin =
23
+ requireFromDocusaurusCore('webpack/lib/ContextReplacementPlugin');
28
24
 
29
25
  // Need to be inlined to prevent dark mode FOUC
30
26
  // Make sure that the 'storageKey' is the same as the one in `/theme/hooks/useTheme.js`
@@ -95,7 +91,7 @@ function getInfimaCSSFile(direction: string) {
95
91
  }
96
92
 
97
93
  export default function docusaurusThemeClassic(
98
- context: DocusaurusContext, // TODO: LoadContext is missing some of properties
94
+ context: LoadContext,
99
95
  options: Options,
100
96
  ): Plugin<void> {
101
97
  const {
@@ -172,6 +168,9 @@ export default function docusaurusThemeClassic(
172
168
 
173
169
  return {
174
170
  plugins: [
171
+ // This allows better optimization by only bundling those components
172
+ // that the user actually needs, because the modules are dynamically
173
+ // required and can't be known during compile time.
175
174
  new ContextReplacementPlugin(
176
175
  /prismjs[\\/]components$/,
177
176
  new RegExp(`^./(${prismLanguages})$`),
@@ -44,9 +44,9 @@ export default function CodeBlock({
44
44
  setMounted(true);
45
45
  }, []);
46
46
 
47
- // TODO: the title is provided by MDX as props automatically
48
- // so we probably don't need to parse the metastring
49
- // (note: title="xyz" => title prop still has the quotes)
47
+ // We still parse the metastring in case we want to support more syntax in the
48
+ // future. Note that MDX doesn't strip quotes when parsing metastring:
49
+ // "title=\"xyz\"" => title: "\"xyz\""
50
50
  const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
51
51
  const prismTheme = usePrismTheme();
52
52
 
@@ -16,7 +16,7 @@ import type {Types, Props} from '@theme/NavbarItem';
16
16
 
17
17
  const NavbarItemComponents: Record<
18
18
  Exclude<Types, undefined>,
19
- // TODO: properly type this
19
+ // Not really worth typing, as we pass all props down immediately
20
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
21
  () => (props: any) => JSX.Element
22
22
  > = {
@@ -12,14 +12,21 @@ import type * as PrismNamespace from 'prismjs';
12
12
  const prismIncludeLanguages = (PrismObject: typeof PrismNamespace): void => {
13
13
  if (ExecutionEnvironment.canUseDOM) {
14
14
  const {
15
- themeConfig: {prism = {}},
15
+ themeConfig: {prism},
16
16
  } = siteConfig;
17
- const {additionalLanguages = []} = prism as {additionalLanguages: string[]};
17
+ const {additionalLanguages} = prism as {additionalLanguages: string[]};
18
18
 
19
+ // Prism components work on the Prism instance on the window, while
20
+ // prism-react-renderer uses its own Prism instance. We temporarily mount
21
+ // the instance onto window, import components to enhance it, then remove it
22
+ // to avoid polluting global namespace.
23
+ // You can mutate this object: registering plugins, deleting languages... As
24
+ // long as you don't re-assign it
19
25
  window.Prism = PrismObject;
20
26
 
21
27
  additionalLanguages.forEach((lang) => {
22
- require(`prismjs/components/prism-${lang}`); // eslint-disable-line
28
+ // eslint-disable-next-line global-require, import/no-dynamic-require
29
+ require(`prismjs/components/prism-${lang}`);
23
30
  });
24
31
 
25
32
  delete (window as Window & {Prism?: typeof PrismNamespace}).Prism;