@rspress/plugin-playground 2.0.17 → 2.0.19

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/dist/cli/index.js CHANGED
@@ -8,7 +8,6 @@ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
8
8
  import { dirname as __rspack_dirname } from "node:path";
9
9
  var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
10
10
  const DEFAULT_BABEL_URL = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';
11
- const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
12
11
  const parseImports = (code, sourceExt)=>{
13
12
  const parsed = napi.parseSync(code, {
14
13
  sourceType: 'module',
@@ -91,10 +90,6 @@ function pluginPlayground(options) {
91
90
  const playgroundVirtualModule = new RspackVirtualModulePlugin({});
92
91
  const getRouteMeta = ()=>cli_routeMeta;
93
92
  if (render && !/Playground\.(jsx?|tsx?)$/.test(render)) throw new Error('[Playground]: render should ends with Playground.(jsx?|tsx?)');
94
- const preloads = [];
95
- const monacoPrefix = (monacoLoader.paths?.vs || DEFAULT_MONACO_URL).replace(/\/+$/, '');
96
- preloads.push(`${monacoPrefix}/loader.js`);
97
- preloads.push(`${monacoPrefix}/editor/editor.main.js`);
98
93
  return {
99
94
  name: '@rspress/plugin-playground',
100
95
  config (config) {
@@ -204,17 +199,6 @@ function pluginPlayground(options) {
204
199
  pkgRootPath
205
200
  ]
206
201
  },
207
- html: {
208
- tags: preloads.map((url)=>({
209
- tag: 'link',
210
- head: true,
211
- attrs: {
212
- rel: 'preload',
213
- href: url,
214
- as: "script"
215
- }
216
- }))
217
- },
218
202
  tools: {
219
203
  rspack: {
220
204
  plugins: [
package/dist/web/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import react, { loader } from "@monaco-editor/react";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
- import { useDark } from "@rspress/core/runtime";
3
+ import { safePreload, useDark } from "@rspress/core/runtime";
4
4
  import react_0, { Component, useMemo } from "react";
5
5
  const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
6
- function initLoader() {
6
+ function getLoaderConfig() {
7
7
  let loaderConfig = {
8
8
  paths: {
9
9
  vs: DEFAULT_MONACO_URL
@@ -13,9 +13,11 @@ function initLoader() {
13
13
  const keys = Object.keys(__PLAYGROUND_MONACO_LOADER__);
14
14
  if (keys.length > 0) loaderConfig = __PLAYGROUND_MONACO_LOADER__;
15
15
  } catch (_e) {}
16
- loader.config(loaderConfig);
16
+ return loaderConfig;
17
17
  }
18
- initLoader();
18
+ const editor_loaderConfig = getLoaderConfig();
19
+ const monacoPrefix = (editor_loaderConfig.paths?.vs || DEFAULT_MONACO_URL).replace(/\/+$/, '');
20
+ loader.config(editor_loaderConfig);
19
21
  function getMonacoOptions() {
20
22
  try {
21
23
  return __PLAYGROUND_MONACO_OPTIONS__;
@@ -23,6 +25,12 @@ function getMonacoOptions() {
23
25
  return {};
24
26
  }
25
27
  function Editor(props) {
28
+ safePreload?.(`${monacoPrefix}/loader.js`, {
29
+ as: "script"
30
+ });
31
+ safePreload?.(`${monacoPrefix}/editor/editor.main.js`, {
32
+ as: "script"
33
+ });
26
34
  const { options, className = '', theme: themeProp, ...rest } = props || {};
27
35
  const dark = useDark();
28
36
  const theme = useMemo(()=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-playground",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "description": "A plugin for rspress to preview the code block in markdown/mdx file.",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "devDependencies": {
38
38
  "@babel/types": "^7.29.7",
39
39
  "@rsbuild/plugin-react": "~2.1.0",
40
- "@rslib/core": "0.23.2",
40
+ "@rslib/core": "1.0.0-beta.1",
41
41
  "@types/babel__core": "^7.20.5",
42
42
  "@types/babel__standalone": "^7.1.9",
43
43
  "@types/babel__traverse": "^7.28.0",
@@ -46,12 +46,12 @@
46
46
  "@types/react": "^19.2.17",
47
47
  "@types/react-dom": "^19.2.3",
48
48
  "mdast-util-mdx-jsx": "^3.2.0",
49
- "react": "^19.2.7",
50
- "react-dom": "^19.2.7",
49
+ "react": "^19.2.8",
50
+ "react-dom": "^19.2.8",
51
51
  "rsbuild-plugin-publint": "^1.0.0",
52
52
  "typescript": "^6.0.3",
53
53
  "unified": "^11.0.5",
54
- "@rspress/plugin-playground": "2.0.17"
54
+ "@rspress/plugin-playground": "2.0.19"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@rspress/core": "^2.0.10",
@@ -6,6 +6,7 @@ import {
6
6
  type HTMLAttributes,
7
7
  type ReactNode,
8
8
  useCallback,
9
+ useEffect,
9
10
  useState,
10
11
  } from 'react';
11
12
 
@@ -67,6 +68,9 @@ export default function Playground(props: PlaygroundProps) {
67
68
  const direction = useDirection(props);
68
69
 
69
70
  const [code, setCode] = useState(codeProp);
71
+ useEffect(() => {
72
+ setCode(codeProp);
73
+ }, [codeProp]);
70
74
 
71
75
  const handleCodeChange = useCallback((e?: string) => {
72
76
  setCode(e || '');