@rspress/plugin-playground 0.0.0-nightly-20230919160314

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/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@rspress/plugin-playground",
3
+ "version": "0.0.0-nightly-20230919160314",
4
+ "description": "A plugin for rspress to preview the code block in markdown/mdx file.",
5
+ "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/web-infra-dev/rspress",
9
+ "directory": "packages/plugin-preview"
10
+ },
11
+ "license": "MIT",
12
+ "types": "./dist/cli/esm/index.d.ts",
13
+ "main": "./dist/cli/cjs/index.js",
14
+ "module": "./dist/cli/esm/index.js",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/cli/esm/index.d.ts",
18
+ "import": "./dist/cli/esm/index.js",
19
+ "default": "./dist/cli/cjs/index.js"
20
+ },
21
+ "./web": {
22
+ "types": "./dist/web/esm/index.d.ts",
23
+ "import": "./dist/web/esm/index.js",
24
+ "default": "./dist/web/cjs/index.js"
25
+ }
26
+ },
27
+ "engines": {
28
+ "node": ">=14.17.6"
29
+ },
30
+ "eslintIgnore": [
31
+ "node_modules/",
32
+ "dist/"
33
+ ],
34
+ "dependencies": {
35
+ "@babel/standalone": "^7.22.17",
36
+ "@mdx-js/mdx": "2.2.1",
37
+ "@modern-js/utils": "2.34.0",
38
+ "@monaco-editor/react": "~4.4.6",
39
+ "@oxidation-compiler/napi": "^0.1.0",
40
+ "remark-gfm": "3.0.1",
41
+ "@rspress/shared": "0.0.0-nightly-20230919160314"
42
+ },
43
+ "devDependencies": {
44
+ "@babel/types": "^7.22.17",
45
+ "@types/babel__core": "^7.20.1",
46
+ "@types/babel__standalone": "^7.1.4",
47
+ "@types/babel__traverse": "^7.20.1",
48
+ "@types/mdast": "^3.0.10",
49
+ "@types/node": "^18.11.17",
50
+ "@types/react": "^18",
51
+ "@types/react-dom": "^18",
52
+ "mdast-util-mdxjs-esm": "^1.3.0",
53
+ "prettier": "^2.6.2",
54
+ "react": "^18",
55
+ "react-dom": "^18",
56
+ "react-router-dom": "^6.8.1",
57
+ "rspack-plugin-virtual-module": "0.1.11",
58
+ "typescript": "^5",
59
+ "unified": "^10.1.2",
60
+ "unist-util-visit": "^4.1.1"
61
+ },
62
+ "peerDependencies": {
63
+ "@rspress/core": "0.0.0-nightly-20230919160314",
64
+ "react": ">=17",
65
+ "react-router-dom": "^6.8.1"
66
+ },
67
+ "files": [
68
+ "dist",
69
+ "static"
70
+ ],
71
+ "publishConfig": {
72
+ "access": "public",
73
+ "provenance": true,
74
+ "registry": "https://registry.npmjs.org/"
75
+ },
76
+ "scripts": {
77
+ "dev": "modern build -w",
78
+ "build": "modern build",
79
+ "reset": "rimraf ./**/node_modules",
80
+ "lint": "modern lint",
81
+ "change": "modern change",
82
+ "bump": "modern bump",
83
+ "pre": "modern pre",
84
+ "change-status": "modern change-status",
85
+ "gen-release-note": "modern gen-release-note",
86
+ "release": "modern release",
87
+ "new": "modern new",
88
+ "test": "vitest run --passWithNoTests",
89
+ "upgrade": "modern upgrade"
90
+ }
91
+ }
@@ -0,0 +1,51 @@
1
+ import React, { HTMLAttributes, useCallback, useState } from 'react';
2
+ import getImport from '_rspress_playground_imports';
3
+ import { Editor, Runner } from '../../dist/web/esm';
4
+
5
+ interface PlaygroundProps extends HTMLAttributes<HTMLDivElement> {
6
+ code: string;
7
+ language: string;
8
+ direction?: 'horizontal' | 'vertical';
9
+ editorPosition?: 'left' | 'right';
10
+ }
11
+
12
+ export default function Playground(props: PlaygroundProps) {
13
+ const {
14
+ code: codeProp,
15
+ language,
16
+ className = '',
17
+ direction = 'horizontal',
18
+ editorPosition,
19
+ ...rest
20
+ } = props;
21
+
22
+ const [code, setCode] = useState(codeProp);
23
+
24
+ const handleCodeChange = useCallback((e?: string) => {
25
+ setCode(e || '');
26
+ }, []);
27
+
28
+ const useReverseLayout =
29
+ direction === 'horizontal' && editorPosition === 'left';
30
+
31
+ const monacoLanguage =
32
+ language === 'tsx' || language === 'ts' ? 'typescript' : 'javascript';
33
+
34
+ const classNames = [
35
+ 'rspress-playground',
36
+ `rspress-playground-${direction}`,
37
+ `rspress-playground-reverse-${useReverseLayout ? 'y' : 'n'}`,
38
+ className,
39
+ ].join(' ');
40
+
41
+ return (
42
+ <div className={classNames} {...rest}>
43
+ <Runner language={language} code={code} getImport={getImport} />
44
+ <Editor
45
+ value={code}
46
+ onChange={handleCodeChange}
47
+ language={monacoLanguage}
48
+ />
49
+ </div>
50
+ );
51
+ }
@@ -0,0 +1,51 @@
1
+ .rspress-playground {
2
+ display: flex;
3
+ border: 1px solid rgba(28, 31, 35, 0.08);
4
+ border-radius: 3px;
5
+ margin-top: 20px;
6
+ margin-bottom: 20px;
7
+ }
8
+
9
+ .rspress-playground-horizontal {
10
+ flex-direction: row;
11
+ height: 400px;
12
+ }
13
+
14
+ .rspress-playground-horizontal.rspress-playground-reverse-y {
15
+ flex-direction: row-reverse;
16
+ }
17
+
18
+ .rspress-playground-vertical {
19
+ flex-direction: column;
20
+ }
21
+
22
+ .rspress-playground > .rspress-playground-runner {
23
+ padding: 20px;
24
+ overflow: auto;
25
+ }
26
+
27
+ .rspress-playground-horizontal > .rspress-playground-runner {
28
+ width: 40%;
29
+ }
30
+
31
+ .rspress-playground-horizontal > .rspress-playground-editor {
32
+ width: 60%;
33
+ }
34
+
35
+ .rspress-playground-horizontal.rspress-playground-reverse-y
36
+ > .rspress-playground-editor {
37
+ border-right: 1px solid rgba(28, 31, 35, 0.08);
38
+ }
39
+
40
+ .rspress-playground-horizontal.rspress-playground-reverse-n
41
+ > .rspress-playground-editor {
42
+ border-left: 1px solid rgba(28, 31, 35, 0.08);
43
+ }
44
+
45
+ .rspress-playground-vertical > .rspress-playground-editor {
46
+ height: 300px;
47
+ }
48
+
49
+ .rspress-playground-vertical > .rspress-playground-editor {
50
+ border-top: 1px solid rgba(28, 31, 35, 0.08);
51
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types='@modern-js/module-tools/types' />
2
+
3
+ declare module '_rspress_playground_imports' {
4
+ const getImport: (name: string, getDefault?: boolean) => void;
5
+ export default getImport;
6
+ }