@docusaurus/theme-live-codeblock 3.0.0 → 3.1.0

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.
@@ -86,6 +86,9 @@ function EditorWithHeader() {
86
86
  </>
87
87
  );
88
88
  }
89
+ // this should rather be a stable function
90
+ // see https://github.com/facebook/docusaurus/issues/9630#issuecomment-1855682643
91
+ const DEFAULT_TRANSFORM_CODE = (code) => `${code};`;
89
92
  export default function Playground({children, transformCode, ...props}) {
90
93
  const {
91
94
  siteConfig: {themeConfig},
@@ -98,9 +101,9 @@ export default function Playground({children, transformCode, ...props}) {
98
101
  return (
99
102
  <div className={styles.playgroundContainer}>
100
103
  <LiveProvider
101
- code={children.replace(/\n$/, '')}
104
+ code={children?.replace(/\n$/, '')}
102
105
  noInline={noInline}
103
- transformCode={transformCode ?? ((code) => `${code};`)}
106
+ transformCode={transformCode ?? DEFAULT_TRANSFORM_CODE}
104
107
  theme={prismTheme}
105
108
  {...props}>
106
109
  {playgroundPosition === 'top' ? (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-live-codeblock",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Docusaurus live code block component.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-live-codeblock.d.ts",
@@ -23,18 +23,18 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@docusaurus/core": "3.0.0",
27
- "@docusaurus/theme-common": "3.0.0",
28
- "@docusaurus/theme-translations": "3.0.0",
29
- "@docusaurus/utils-validation": "3.0.0",
26
+ "@docusaurus/core": "3.1.0",
27
+ "@docusaurus/theme-common": "3.1.0",
28
+ "@docusaurus/theme-translations": "3.1.0",
29
+ "@docusaurus/utils-validation": "3.1.0",
30
30
  "@philpl/buble": "^0.19.7",
31
- "clsx": "^1.2.1",
31
+ "clsx": "^2.0.0",
32
32
  "fs-extra": "^11.1.1",
33
33
  "react-live": "^4.1.5",
34
34
  "tslib": "^2.6.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@docusaurus/types": "3.0.0",
37
+ "@docusaurus/types": "3.1.0",
38
38
  "@types/buble": "^0.20.1"
39
39
  },
40
40
  "peerDependencies": {
@@ -44,5 +44,5 @@
44
44
  "engines": {
45
45
  "node": ">=18.0"
46
46
  },
47
- "gitHead": "ca8b4638c47119d38838656c4a11ee3a5e7ba6f2"
47
+ "gitHead": "a5e675821f0e8b70b591fcebf19fd60a70d55548"
48
48
  }
@@ -98,6 +98,10 @@ function EditorWithHeader() {
98
98
  );
99
99
  }
100
100
 
101
+ // this should rather be a stable function
102
+ // see https://github.com/facebook/docusaurus/issues/9630#issuecomment-1855682643
103
+ const DEFAULT_TRANSFORM_CODE = (code: string) => `${code};`;
104
+
101
105
  export default function Playground({
102
106
  children,
103
107
  transformCode,
@@ -116,9 +120,9 @@ export default function Playground({
116
120
  return (
117
121
  <div className={styles.playgroundContainer}>
118
122
  <LiveProvider
119
- code={children.replace(/\n$/, '')}
123
+ code={children?.replace(/\n$/, '')}
120
124
  noInline={noInline}
121
- transformCode={transformCode ?? ((code) => `${code};`)}
125
+ transformCode={transformCode ?? DEFAULT_TRANSFORM_CODE}
122
126
  theme={prismTheme}
123
127
  {...props}>
124
128
  {playgroundPosition === 'top' ? (
@@ -24,7 +24,8 @@ declare module '@theme/Playground' {
24
24
  type LiveProviderProps = React.ComponentProps<typeof LiveProvider>;
25
25
 
26
26
  export interface Props extends CodeBlockProps, LiveProviderProps {
27
- children: string;
27
+ // Allow empty live playgrounds
28
+ children?: string;
28
29
  }
29
30
  export default function Playground(props: LiveProviderProps): JSX.Element;
30
31
  }