@docusaurus/theme-live-codeblock 2.0.0-beta.15 → 2.0.0-beta.16

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.
@@ -4,6 +4,6 @@
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
- import { features as bubleFeatures, type TransformOptions, type TransformOutput } from '@philpl/buble';
8
- export { bubleFeatures as features };
7
+ import { type TransformOptions, type TransformOutput } from '@philpl/buble';
8
+ export { features } from '@philpl/buble';
9
9
  export declare function transform(source: string, options: TransformOptions): TransformOutput;
@@ -1,26 +1,25 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Facebook, Inc. and its affiliates.
4
3
  *
5
4
  * This source code is licensed under the MIT license found in the
6
5
  * LICENSE file in the root directory of this source tree.
7
6
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.transform = exports.features = void 0;
10
7
  // fork of Buble which removes Buble's large dependency and weighs in
11
8
  // at a smaller size of ~51kB
12
9
  // https://github.com/FormidableLabs/react-live#what-bundle-size-can-i-expect
13
- const buble_1 = require("@philpl/buble");
14
- Object.defineProperty(exports, "features", { enumerable: true, get: function () { return buble_1.features; } });
15
- function transform(source, options) {
16
- return (0, buble_1.transform)(source, {
17
- ...options,
18
- transforms: {
19
- asyncAwait: false,
20
- classes: false,
21
- getterSetter: false,
22
- ...options.transforms,
23
- },
24
- });
10
+ import {transform as bubleTransform} from '@philpl/buble';
11
+ // This file is designed to mimic what's written in
12
+ // https://github.com/kitten/buble/blob/mini/src/index.js, with custom transforms options,
13
+ // so that webpack can consume it correctly.
14
+ export {features} from '@philpl/buble';
15
+ export function transform(source, options) {
16
+ return bubleTransform(source, {
17
+ ...options,
18
+ transforms: {
19
+ asyncAwait: false,
20
+ classes: false,
21
+ getterSetter: false,
22
+ ...options.transforms,
23
+ },
24
+ });
25
25
  }
26
- exports.transform = transform;
package/lib/index.d.ts CHANGED
@@ -4,6 +4,6 @@
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
- import type { DocusaurusContext, Plugin } from '@docusaurus/types';
8
- export default function theme(context: DocusaurusContext): Plugin;
7
+ import type { LoadContext, Plugin } from '@docusaurus/types';
8
+ export default function themeLiveCodeblock(context: LoadContext): Plugin;
9
9
  export { validateThemeConfig } from './validateThemeConfig';
package/lib/index.js CHANGED
@@ -1,39 +1,49 @@
1
- "use strict";
1
+ 'use strict';
2
2
  /**
3
3
  * Copyright (c) Facebook, Inc. and its affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
8
+ Object.defineProperty(exports, '__esModule', {value: true});
9
9
  exports.validateThemeConfig = void 0;
10
- const tslib_1 = require("tslib");
11
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
- const theme_translations_1 = require("@docusaurus/theme-translations");
13
- function theme(context) {
14
- const { i18n: { currentLocale }, } = context;
15
- return {
16
- name: 'docusaurus-theme-live-codeblock',
17
- getThemePath() {
18
- return path_1.default.resolve(__dirname, './theme');
10
+ const tslib_1 = require('tslib');
11
+ const path_1 = (0, tslib_1.__importDefault)(require('path'));
12
+ const theme_translations_1 = require('@docusaurus/theme-translations');
13
+ function themeLiveCodeblock(context) {
14
+ const {
15
+ i18n: {currentLocale},
16
+ } = context;
17
+ return {
18
+ name: 'docusaurus-theme-live-codeblock',
19
+ getThemePath() {
20
+ return path_1.default.resolve(__dirname, '../lib/theme');
21
+ },
22
+ getTypeScriptThemePath() {
23
+ return path_1.default.resolve(__dirname, '../src/theme');
24
+ },
25
+ getDefaultCodeTranslationMessages() {
26
+ return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
27
+ locale: currentLocale,
28
+ name: 'theme-live-codeblock',
29
+ });
30
+ },
31
+ configureWebpack() {
32
+ return {
33
+ resolve: {
34
+ alias: {
35
+ buble: path_1.default.resolve(__dirname, './custom-buble.js'),
36
+ },
19
37
  },
20
- getDefaultCodeTranslationMessages() {
21
- return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
22
- locale: currentLocale,
23
- name: 'theme-live-codeblock',
24
- });
25
- },
26
- configureWebpack() {
27
- return {
28
- resolve: {
29
- alias: {
30
- buble: path_1.default.resolve(__dirname, './custom-buble.js'),
31
- },
32
- },
33
- };
34
- },
35
- };
38
+ };
39
+ },
40
+ };
36
41
  }
37
- exports.default = theme;
38
- var validateThemeConfig_1 = require("./validateThemeConfig");
39
- Object.defineProperty(exports, "validateThemeConfig", { enumerable: true, get: function () { return validateThemeConfig_1.validateThemeConfig; } });
42
+ exports.default = themeLiveCodeblock;
43
+ var validateThemeConfig_1 = require('./validateThemeConfig');
44
+ Object.defineProperty(exports, 'validateThemeConfig', {
45
+ enumerable: true,
46
+ get: function () {
47
+ return validateThemeConfig_1.validateThemeConfig;
48
+ },
49
+ });
@@ -0,0 +1,9 @@
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 Props } from '@theme-init/CodeBlock';
8
+ declare const _default: (props: Props) => JSX.Element;
9
+ export default _default;
@@ -4,22 +4,18 @@
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
-
8
7
  import React from 'react';
9
8
  import Playground from '@theme/Playground';
10
9
  import ReactLiveScope from '@theme/ReactLiveScope';
11
10
  import CodeBlock from '@theme-init/CodeBlock';
12
-
13
11
  const withLiveEditor = (Component) => {
14
12
  function WrappedComponent(props) {
15
13
  if (props.live) {
14
+ // @ts-expect-error: we have deliberately widened the type of language prop
16
15
  return <Playground scope={ReactLiveScope} {...props} />;
17
16
  }
18
-
19
17
  return <Component {...props} />;
20
18
  }
21
-
22
19
  return WrappedComponent;
23
20
  };
24
-
25
21
  export default withLiveEditor(CodeBlock);
@@ -0,0 +1,9 @@
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
+ /// <reference types="react" />
8
+ import type { Props } from '@theme/Playground';
9
+ export default function Playground({ children, transformCode, ...props }: Props): JSX.Element;
@@ -4,8 +4,7 @@
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
-
8
- import * as React from 'react';
7
+ import React from 'react';
9
8
  import {LiveProvider, LiveEditor, LiveError, LivePreview} from 'react-live';
10
9
  import clsx from 'clsx';
11
10
  import Translate from '@docusaurus/Translate';
@@ -14,16 +13,13 @@ import BrowserOnly from '@docusaurus/BrowserOnly';
14
13
  import {usePrismTheme} from '@docusaurus/theme-common';
15
14
  import styles from './styles.module.css';
16
15
  import useIsBrowser from '@docusaurus/useIsBrowser';
17
-
18
16
  function Header({children}) {
19
17
  return <div className={clsx(styles.playgroundHeader)}>{children}</div>;
20
18
  }
21
-
22
19
  function LivePreviewLoader() {
23
20
  // Is it worth improving/translating?
24
21
  return <div>Loading...</div>;
25
22
  }
26
-
27
23
  function ResultWithHeader() {
28
24
  return (
29
25
  <>
@@ -48,19 +44,17 @@ function ResultWithHeader() {
48
44
  </>
49
45
  );
50
46
  }
51
-
52
47
  function ThemedLiveEditor() {
53
48
  const isBrowser = useIsBrowser();
54
49
  return (
55
50
  <LiveEditor
56
51
  // We force remount the editor on hydration,
57
52
  // otherwise dark prism theme is not applied
58
- key={isBrowser}
53
+ key={String(isBrowser)}
59
54
  className={styles.playgroundEditor}
60
55
  />
61
56
  );
62
57
  }
63
-
64
58
  function EditorWithHeader() {
65
59
  return (
66
60
  <>
@@ -75,19 +69,17 @@ function EditorWithHeader() {
75
69
  </>
76
70
  );
77
71
  }
78
-
79
72
  export default function Playground({children, transformCode, ...props}) {
80
73
  const {
81
- siteConfig: {
82
- themeConfig: {
83
- liveCodeBlock: {playgroundPosition},
84
- },
85
- },
74
+ siteConfig: {themeConfig},
86
75
  } = useDocusaurusContext();
76
+ const {
77
+ liveCodeBlock: {playgroundPosition},
78
+ } = themeConfig;
87
79
  const prismTheme = usePrismTheme();
88
-
89
80
  return (
90
81
  <div className={styles.playgroundContainer}>
82
+ {/* @ts-expect-error: type incompatibility with refs */}
91
83
  <LiveProvider
92
84
  code={children.replace(/\n$/, '')}
93
85
  transformCode={transformCode || ((code) => `${code};`)}
@@ -0,0 +1,71 @@
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 React from 'react';
8
+ declare const ReactLiveScope: {
9
+ createFactory<T extends HTMLElement>(type: keyof React.ReactHTML): React.HTMLFactory<T>;
10
+ createFactory(type: keyof React.ReactSVG): React.SVGFactory;
11
+ createFactory<P extends React.DOMAttributes<T_1>, T_1 extends Element>(type: string): React.DOMFactory<P, T_1>;
12
+ createFactory<P_1>(type: React.FunctionComponent<P_1>): React.FunctionComponentFactory<P_1>;
13
+ createFactory<P_2>(type: React.ClassType<P_2, React.ClassicComponent<P_2, any>, React.ClassicComponentClass<P_2>>): React.CFactory<P_2, React.ClassicComponent<P_2, any>>;
14
+ createFactory<P_3, T_2 extends React.Component<P_3, any, any>, C extends React.ComponentClass<P_3, any>>(type: React.ClassType<P_3, T_2, C>): React.CFactory<P_3, T_2>;
15
+ createFactory<P_4>(type: React.ComponentClass<P_4, any>): React.Factory<P_4>;
16
+ createElement(type: "input", props?: (React.InputHTMLAttributes<HTMLInputElement> & React.ClassAttributes<HTMLInputElement>) | null | undefined, ...children: React.ReactNode[]): React.DetailedReactHTMLElement<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
17
+ createElement<P_5 extends React.HTMLAttributes<T_3>, T_3 extends HTMLElement>(type: keyof React.ReactHTML, props?: (React.ClassAttributes<T_3> & P_5) | null | undefined, ...children: React.ReactNode[]): React.DetailedReactHTMLElement<P_5, T_3>;
18
+ createElement<P_6 extends React.SVGAttributes<T_4>, T_4 extends SVGElement>(type: keyof React.ReactSVG, props?: (React.ClassAttributes<T_4> & P_6) | null | undefined, ...children: React.ReactNode[]): React.ReactSVGElement;
19
+ createElement<P_7 extends React.DOMAttributes<T_5>, T_5 extends Element>(type: string, props?: (React.ClassAttributes<T_5> & P_7) | null | undefined, ...children: React.ReactNode[]): React.DOMElement<P_7, T_5>;
20
+ createElement<P_8 extends {}>(type: React.FunctionComponent<P_8>, props?: (React.Attributes & P_8) | null | undefined, ...children: React.ReactNode[]): React.FunctionComponentElement<P_8>;
21
+ createElement<P_9 extends {}>(type: React.ClassType<P_9, React.ClassicComponent<P_9, any>, React.ClassicComponentClass<P_9>>, props?: (React.ClassAttributes<React.ClassicComponent<P_9, any>> & P_9) | null | undefined, ...children: React.ReactNode[]): React.CElement<P_9, React.ClassicComponent<P_9, any>>;
22
+ createElement<P_10 extends {}, T_6 extends React.Component<P_10, any, any>, C_1 extends React.ComponentClass<P_10, any>>(type: React.ClassType<P_10, T_6, C_1>, props?: (React.ClassAttributes<T_6> & P_10) | null | undefined, ...children: React.ReactNode[]): React.CElement<P_10, T_6>;
23
+ createElement<P_11 extends {}>(type: string | React.FunctionComponent<P_11> | React.ComponentClass<P_11, any>, props?: (React.Attributes & P_11) | null | undefined, ...children: React.ReactNode[]): React.ReactElement<P_11, string | React.JSXElementConstructor<any>>;
24
+ cloneElement<P_12 extends React.HTMLAttributes<T_7>, T_7 extends HTMLElement>(element: React.DetailedReactHTMLElement<P_12, T_7>, props?: P_12 | undefined, ...children: React.ReactNode[]): React.DetailedReactHTMLElement<P_12, T_7>;
25
+ cloneElement<P_13 extends React.HTMLAttributes<T_8>, T_8 extends HTMLElement>(element: React.ReactHTMLElement<T_8>, props?: P_13 | undefined, ...children: React.ReactNode[]): React.ReactHTMLElement<T_8>;
26
+ cloneElement<P_14 extends React.SVGAttributes<T_9>, T_9 extends SVGElement>(element: React.ReactSVGElement, props?: P_14 | undefined, ...children: React.ReactNode[]): React.ReactSVGElement;
27
+ cloneElement<P_15 extends React.DOMAttributes<T_10>, T_10 extends Element>(element: React.DOMElement<P_15, T_10>, props?: (React.DOMAttributes<T_10> & P_15) | undefined, ...children: React.ReactNode[]): React.DOMElement<P_15, T_10>;
28
+ cloneElement<P_16>(element: React.FunctionComponentElement<P_16>, props?: (Partial<P_16> & React.Attributes) | undefined, ...children: React.ReactNode[]): React.FunctionComponentElement<P_16>;
29
+ cloneElement<P_17, T_11 extends React.Component<P_17, any, any>>(element: React.CElement<P_17, T_11>, props?: (Partial<P_17> & React.ClassAttributes<T_11>) | undefined, ...children: React.ReactNode[]): React.CElement<P_17, T_11>;
30
+ cloneElement<P_18>(element: React.ReactElement<P_18, string | React.JSXElementConstructor<any>>, props?: (Partial<P_18> & React.Attributes) | undefined, ...children: React.ReactNode[]): React.ReactElement<P_18, string | React.JSXElementConstructor<any>>;
31
+ createContext<T_12>(defaultValue: T_12): React.Context<T_12>;
32
+ isValidElement<P_19>(object: {} | null | undefined): object is React.ReactElement<P_19, string | React.JSXElementConstructor<any>>;
33
+ createRef<T_13>(): React.RefObject<T_13>;
34
+ forwardRef<T_14, P_20 = {}>(render: React.ForwardRefRenderFunction<T_14, P_20>): React.ForwardRefExoticComponent<React.PropsWithoutRef<P_20> & React.RefAttributes<T_14>>;
35
+ memo<P_21 extends object>(Component: React.FunctionComponent<P_21>, propsAreEqual?: ((prevProps: Readonly<React.PropsWithChildren<P_21>>, nextProps: Readonly<React.PropsWithChildren<P_21>>) => boolean) | undefined): React.NamedExoticComponent<P_21>;
36
+ memo<T_15 extends React.ComponentType<any>>(Component: T_15, propsAreEqual?: ((prevProps: Readonly<React.ComponentProps<T_15>>, nextProps: Readonly<React.ComponentProps<T_15>>) => boolean) | undefined): React.MemoExoticComponent<T_15>;
37
+ lazy<T_16 extends React.ComponentType<any>>(factory: () => Promise<{
38
+ default: T_16;
39
+ }>): React.LazyExoticComponent<T_16>;
40
+ useContext<T_17>(context: React.Context<T_17>): T_17;
41
+ useState<S>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>];
42
+ useState<S_1 = undefined>(): [S_1 | undefined, React.Dispatch<React.SetStateAction<S_1 | undefined>>];
43
+ useReducer<R extends React.ReducerWithoutAction<any>, I>(reducer: R, initializerArg: I, initializer: (arg: I) => React.ReducerStateWithoutAction<R>): [React.ReducerStateWithoutAction<R>, React.DispatchWithoutAction];
44
+ useReducer<R_1 extends React.ReducerWithoutAction<any>>(reducer: R_1, initializerArg: React.ReducerStateWithoutAction<R_1>, initializer?: undefined): [React.ReducerStateWithoutAction<R_1>, React.DispatchWithoutAction];
45
+ useReducer<R_2 extends React.Reducer<any, any>, I_1>(reducer: R_2, initializerArg: I_1 & React.ReducerState<R_2>, initializer: (arg: I_1 & React.ReducerState<R_2>) => React.ReducerState<R_2>): [React.ReducerState<R_2>, React.Dispatch<React.ReducerAction<R_2>>];
46
+ useReducer<R_3 extends React.Reducer<any, any>, I_2>(reducer: R_3, initializerArg: I_2, initializer: (arg: I_2) => React.ReducerState<R_3>): [React.ReducerState<R_3>, React.Dispatch<React.ReducerAction<R_3>>];
47
+ useReducer<R_4 extends React.Reducer<any, any>>(reducer: R_4, initialState: React.ReducerState<R_4>, initializer?: undefined): [React.ReducerState<R_4>, React.Dispatch<React.ReducerAction<R_4>>];
48
+ useRef<T_18>(initialValue: T_18): React.MutableRefObject<T_18>;
49
+ useRef<T_19>(initialValue: T_19 | null): React.RefObject<T_19>;
50
+ useRef<T_20 = undefined>(): React.MutableRefObject<T_20 | undefined>;
51
+ useLayoutEffect(effect: React.EffectCallback, deps?: React.DependencyList | undefined): void;
52
+ useEffect(effect: React.EffectCallback, deps?: React.DependencyList | undefined): void;
53
+ useImperativeHandle<T_21, R_5 extends T_21>(ref: React.Ref<T_21> | undefined, init: () => R_5, deps?: React.DependencyList | undefined): void;
54
+ useCallback<T_22 extends (...args: any[]) => any>(callback: T_22, deps: React.DependencyList): T_22;
55
+ useMemo<T_23>(factory: () => T_23, deps: React.DependencyList | undefined): T_23;
56
+ useDebugValue<T_24>(value: T_24, format?: ((value: T_24) => any) | undefined): void;
57
+ Children: React.ReactChildren;
58
+ Fragment: React.ExoticComponent<{
59
+ children?: React.ReactNode;
60
+ }>;
61
+ StrictMode: React.ExoticComponent<{
62
+ children?: React.ReactNode;
63
+ }>;
64
+ Suspense: React.ExoticComponent<React.SuspenseProps>;
65
+ version: string;
66
+ Profiler: React.ExoticComponent<React.ProfilerProps>;
67
+ Component: typeof React.Component;
68
+ PureComponent: typeof React.PureComponent;
69
+ React: typeof React;
70
+ };
71
+ export default ReactLiveScope;
@@ -4,13 +4,10 @@
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
-
8
7
  import React from 'react';
9
-
10
8
  // Add react-live imports you need here
11
9
  const ReactLiveScope = {
12
10
  React,
13
11
  ...React,
14
12
  };
15
-
16
13
  export default ReactLiveScope;
@@ -6,12 +6,11 @@
6
6
  */
7
7
  import { Joi } from '@docusaurus/utils-validation';
8
8
  import type { ThemeConfig, Validate, ValidationResult } from '@docusaurus/types';
9
- declare const DEFAULT_CONFIG: {
9
+ export declare const DEFAULT_CONFIG: {
10
10
  playgroundPosition: string;
11
11
  };
12
- declare const Schema: Joi.ObjectSchema<any>;
13
- declare function validateThemeConfig({ validate, themeConfig, }: {
12
+ export declare const Schema: Joi.ObjectSchema<any>;
13
+ export declare function validateThemeConfig({ validate, themeConfig, }: {
14
14
  validate: Validate<ThemeConfig>;
15
15
  themeConfig: ThemeConfig;
16
16
  }): ValidationResult<ThemeConfig>;
17
- export { DEFAULT_CONFIG, Schema, validateThemeConfig };
@@ -1,28 +1,26 @@
1
- "use strict";
1
+ 'use strict';
2
2
  /**
3
3
  * Copyright (c) Facebook, Inc. and its affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
8
+ Object.defineProperty(exports, '__esModule', {value: true});
9
9
  exports.validateThemeConfig = exports.Schema = exports.DEFAULT_CONFIG = void 0;
10
- const utils_validation_1 = require("@docusaurus/utils-validation");
11
- const DEFAULT_CONFIG = {
12
- playgroundPosition: 'bottom',
10
+ const utils_validation_1 = require('@docusaurus/utils-validation');
11
+ exports.DEFAULT_CONFIG = {
12
+ playgroundPosition: 'bottom',
13
13
  };
14
- exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
15
- const Schema = utils_validation_1.Joi.object({
16
- liveCodeBlock: utils_validation_1.Joi.object({
17
- playgroundPosition: utils_validation_1.Joi.string()
18
- .equal('top', 'bottom')
19
- .default(DEFAULT_CONFIG.playgroundPosition),
20
- })
21
- .label('themeConfig.liveCodeBlock')
22
- .default(DEFAULT_CONFIG),
14
+ exports.Schema = utils_validation_1.Joi.object({
15
+ liveCodeBlock: utils_validation_1.Joi.object({
16
+ playgroundPosition: utils_validation_1.Joi.string()
17
+ .equal('top', 'bottom')
18
+ .default(exports.DEFAULT_CONFIG.playgroundPosition),
19
+ })
20
+ .label('themeConfig.liveCodeBlock')
21
+ .default(exports.DEFAULT_CONFIG),
23
22
  });
24
- exports.Schema = Schema;
25
- function validateThemeConfig({ validate, themeConfig, }) {
26
- return validate(Schema, themeConfig);
23
+ function validateThemeConfig({validate, themeConfig}) {
24
+ return validate(exports.Schema, themeConfig);
27
25
  }
28
26
  exports.validateThemeConfig = validateThemeConfig;
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-live-codeblock",
3
- "version": "2.0.0-beta.15",
3
+ "version": "2.0.0-beta.16",
4
4
  "description": "Docusaurus live code block component.",
5
5
  "main": "lib/index.js",
6
+ "types": "src/theme-live-codeblock.d.ts",
6
7
  "publishConfig": {
7
8
  "access": "public"
8
9
  },
9
10
  "scripts": {
10
- "build": "tsc && node copyUntypedFiles.mjs",
11
- "watch": "node copyUntypedFiles.mjs && tsc --watch"
11
+ "build": "yarn build:server && yarn build:client && yarn build:copy && yarn build:format",
12
+ "build:server": "tsc --project tsconfig.server.json",
13
+ "build:client": "tsc --project tsconfig.client.json",
14
+ "build:copy": "node copyUntypedFiles.mjs",
15
+ "build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
12
16
  },
13
17
  "repository": {
14
18
  "type": "git",
@@ -17,20 +21,18 @@
17
21
  },
18
22
  "license": "MIT",
19
23
  "dependencies": {
20
- "@docusaurus/core": "2.0.0-beta.15",
21
- "@docusaurus/theme-common": "2.0.0-beta.15",
22
- "@docusaurus/theme-translations": "2.0.0-beta.15",
23
- "@docusaurus/utils-validation": "2.0.0-beta.15",
24
+ "@docusaurus/core": "2.0.0-beta.16",
25
+ "@docusaurus/theme-common": "2.0.0-beta.16",
26
+ "@docusaurus/theme-translations": "2.0.0-beta.16",
27
+ "@docusaurus/utils-validation": "2.0.0-beta.16",
24
28
  "@philpl/buble": "^0.19.7",
25
29
  "clsx": "^1.1.1",
26
- "fs-extra": "^10.0.0",
27
- "parse-numeric-range": "^1.3.0",
28
- "prism-react-renderer": "^1.2.1",
30
+ "fs-extra": "^10.0.1",
29
31
  "react-live": "2.2.3",
30
32
  "tslib": "^2.3.1"
31
33
  },
32
34
  "devDependencies": {
33
- "@docusaurus/types": "2.0.0-beta.15",
35
+ "@docusaurus/types": "2.0.0-beta.16",
34
36
  "@types/buble": "^0.20.1"
35
37
  },
36
38
  "peerDependencies": {
@@ -40,5 +42,5 @@
40
42
  "engines": {
41
43
  "node": ">=14"
42
44
  },
43
- "gitHead": "6cfad16436c07d8d11e5c2e1486dc59afd483e33"
45
+ "gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
44
46
  }
@@ -10,7 +10,6 @@
10
10
  // https://github.com/FormidableLabs/react-live#what-bundle-size-can-i-expect
11
11
  import {
12
12
  transform as bubleTransform,
13
- features as bubleFeatures,
14
13
  type TransformOptions,
15
14
  type TransformOutput,
16
15
  } from '@philpl/buble';
@@ -18,7 +17,7 @@ import {
18
17
  // This file is designed to mimic what's written in
19
18
  // https://github.com/kitten/buble/blob/mini/src/index.js, with custom transforms options,
20
19
  // so that webpack can consume it correctly.
21
- export {bubleFeatures as features};
20
+ export {features} from '@philpl/buble';
22
21
 
23
22
  export function transform(
24
23
  source: string,
package/src/deps.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  declare module '@philpl/buble' {
9
9
  import type {TransformOptions as OriginalTransformOptions} from 'buble';
10
- // eslint-disable-next-line import/no-extraneous-dependencies
10
+ // eslint-disable-next-line import/no-extraneous-dependencies, no-restricted-syntax
11
11
  export * from 'buble';
12
12
  export const features: string[];
13
13
  export interface TransformOptions extends OriginalTransformOptions {
package/src/index.ts CHANGED
@@ -7,9 +7,9 @@
7
7
 
8
8
  import path from 'path';
9
9
  import {readDefaultCodeTranslationMessages} from '@docusaurus/theme-translations';
10
- import type {DocusaurusContext, Plugin} from '@docusaurus/types';
10
+ import type {LoadContext, Plugin} from '@docusaurus/types';
11
11
 
12
- export default function theme(context: DocusaurusContext): Plugin {
12
+ export default function themeLiveCodeblock(context: LoadContext): Plugin {
13
13
  const {
14
14
  i18n: {currentLocale},
15
15
  } = context;
@@ -18,7 +18,10 @@ export default function theme(context: DocusaurusContext): Plugin {
18
18
  name: 'docusaurus-theme-live-codeblock',
19
19
 
20
20
  getThemePath() {
21
- return path.resolve(__dirname, './theme');
21
+ return path.resolve(__dirname, '../lib/theme');
22
+ },
23
+ getTypeScriptThemePath() {
24
+ return path.resolve(__dirname, '../src/theme');
22
25
  },
23
26
 
24
27
  getDefaultCodeTranslationMessages() {
@@ -8,11 +8,12 @@
8
8
  import React from 'react';
9
9
  import Playground from '@theme/Playground';
10
10
  import ReactLiveScope from '@theme/ReactLiveScope';
11
- import CodeBlock from '@theme-init/CodeBlock';
11
+ import CodeBlock, {type Props} from '@theme-init/CodeBlock';
12
12
 
13
- const withLiveEditor = (Component) => {
14
- function WrappedComponent(props) {
13
+ const withLiveEditor = (Component: typeof CodeBlock) => {
14
+ function WrappedComponent(props: Props) {
15
15
  if (props.live) {
16
+ // @ts-expect-error: we have deliberately widened the type of language prop
16
17
  return <Playground scope={ReactLiveScope} {...props} />;
17
18
  }
18
19
 
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import * as React from 'react';
8
+ import React from 'react';
9
9
  import {LiveProvider, LiveEditor, LiveError, LivePreview} from 'react-live';
10
10
  import clsx from 'clsx';
11
11
  import Translate from '@docusaurus/Translate';
@@ -14,8 +14,10 @@ import BrowserOnly from '@docusaurus/BrowserOnly';
14
14
  import {usePrismTheme} from '@docusaurus/theme-common';
15
15
  import styles from './styles.module.css';
16
16
  import useIsBrowser from '@docusaurus/useIsBrowser';
17
+ import type {Props} from '@theme/Playground';
18
+ import type {ThemeConfig} from '@docusaurus/theme-live-codeblock';
17
19
 
18
- function Header({children}) {
20
+ function Header({children}: {children: React.ReactNode}) {
19
21
  return <div className={clsx(styles.playgroundHeader)}>{children}</div>;
20
22
  }
21
23
 
@@ -55,7 +57,7 @@ function ThemedLiveEditor() {
55
57
  <LiveEditor
56
58
  // We force remount the editor on hydration,
57
59
  // otherwise dark prism theme is not applied
58
- key={isBrowser}
60
+ key={String(isBrowser)}
59
61
  className={styles.playgroundEditor}
60
62
  />
61
63
  );
@@ -76,18 +78,22 @@ function EditorWithHeader() {
76
78
  );
77
79
  }
78
80
 
79
- export default function Playground({children, transformCode, ...props}) {
81
+ export default function Playground({
82
+ children,
83
+ transformCode,
84
+ ...props
85
+ }: Props): JSX.Element {
80
86
  const {
81
- siteConfig: {
82
- themeConfig: {
83
- liveCodeBlock: {playgroundPosition},
84
- },
85
- },
87
+ siteConfig: {themeConfig},
86
88
  } = useDocusaurusContext();
89
+ const {
90
+ liveCodeBlock: {playgroundPosition},
91
+ } = themeConfig as ThemeConfig;
87
92
  const prismTheme = usePrismTheme();
88
93
 
89
94
  return (
90
95
  <div className={styles.playgroundContainer}>
96
+ {/* @ts-expect-error: type incompatibility with refs */}
91
97
  <LiveProvider
92
98
  code={children.replace(/\n$/, '')}
93
99
  transformCode={transformCode || ((code) => `${code};`)}
File without changes
@@ -0,0 +1,32 @@
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
+ declare module '@docusaurus/theme-live-codeblock' {
9
+ export type ThemeConfig = {
10
+ liveCodeBlock: {
11
+ playgroundPosition: 'top' | 'bottom';
12
+ };
13
+ };
14
+ }
15
+
16
+ declare module '@theme/Playground' {
17
+ import type {LiveProviderProps} from 'react-live';
18
+
19
+ export interface Props extends LiveProviderProps {
20
+ children: string;
21
+ }
22
+ export default function Playground(props: LiveProviderProps): JSX.Element;
23
+ }
24
+
25
+ declare module '@theme/ReactLiveScope' {
26
+ interface Scope {
27
+ [key: string]: unknown;
28
+ }
29
+
30
+ const ReactLiveScope: Scope;
31
+ export default ReactLiveScope;
32
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,18 @@
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
+ /// <reference types="@docusaurus/theme-classic" />
9
+
10
+ declare module '@theme-init/CodeBlock' {
11
+ import type CodeBlock, {Props as BaseProps} from '@theme/CodeBlock';
12
+
13
+ export interface Props extends BaseProps {
14
+ live?: boolean;
15
+ }
16
+ const CodeBlockComp: typeof CodeBlock;
17
+ export default CodeBlockComp;
18
+ }
@@ -8,11 +8,11 @@
8
8
  import {Joi} from '@docusaurus/utils-validation';
9
9
  import type {ThemeConfig, Validate, ValidationResult} from '@docusaurus/types';
10
10
 
11
- const DEFAULT_CONFIG = {
11
+ export const DEFAULT_CONFIG = {
12
12
  playgroundPosition: 'bottom',
13
13
  };
14
14
 
15
- const Schema = Joi.object({
15
+ export const Schema = Joi.object({
16
16
  liveCodeBlock: Joi.object({
17
17
  playgroundPosition: Joi.string()
18
18
  .equal('top', 'bottom')
@@ -22,7 +22,7 @@ const Schema = Joi.object({
22
22
  .default(DEFAULT_CONFIG),
23
23
  });
24
24
 
25
- function validateThemeConfig({
25
+ export function validateThemeConfig({
26
26
  validate,
27
27
  themeConfig,
28
28
  }: {
@@ -31,5 +31,3 @@ function validateThemeConfig({
31
31
  }): ValidationResult<ThemeConfig> {
32
32
  return validate(Schema, themeConfig);
33
33
  }
34
-
35
- export {DEFAULT_CONFIG, Schema, validateThemeConfig};