@ray-js/code-sandbox 0.0.2 → 0.0.3-beta-2

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/README.md CHANGED
@@ -4,7 +4,7 @@ English | [简体中文](./README-zh_CN.md)
4
4
 
5
5
  [![latest](https://img.shields.io/npm/v/@ray/code-sandbox/latest.svg)](https://www.npmjs.com/package/@ray/code-sandbox) [![download](https://img.shields.io/npm/dt/@ray/code-sandbox.svg)](https://www.npmjs.com/package/@ray/code-sandbox)
6
6
 
7
- > 小程序 CodeSandbox 容器
7
+ > CodeSandBox container
8
8
 
9
9
  ## Installation
10
10
 
@@ -25,15 +25,15 @@ yarn start:tuya
25
25
 
26
26
  ## Usage
27
27
 
28
- ### 小程序对接
28
+ ### Mini -program docking
29
29
 
30
- 安装必须的依赖
30
+ Must -dependencies in installation
31
31
 
32
32
  ```sh
33
33
  yarn add @ray/code-sandbox @ray-js/ray @ray-js/smart-ui @tuya-miniapp/smart-ui
34
34
  ```
35
35
 
36
- pages 目录下新建 playground 页面,内容如下
36
+ Create a new Playground page in the PAGES directory, the content is as follows
37
37
 
38
38
  ```tsx
39
39
  import React from 'react';
@@ -46,7 +46,7 @@ export default function Home() {
46
46
  <CodeSandbox
47
47
  defaultTitle="CodeSandbox"
48
48
  context={{
49
- // CodeSandbox 中可 import from 的三方库
49
+ // The three -party library of Import from in CODESANDBOX
50
50
  '@ray-js/ray': RayComponents,
51
51
  }}
52
52
  />
@@ -54,7 +54,7 @@ export default function Home() {
54
54
  }
55
55
  ```
56
56
 
57
- 页面 index.config 配置自定义 Topbar
57
+ Page index.config Configuration Custom Topbar
58
58
 
59
59
  ```tsx
60
60
  export default {
@@ -63,21 +63,21 @@ export default {
63
63
 
64
64
  ```
65
65
 
66
- ### 平台对接
66
+ ### Platform docking
67
67
 
68
- 安装必须的依赖
68
+ Must -dependencies in installation
69
69
 
70
70
  ```sh
71
71
  yarn add @ray/code-sandbox antd axios styled-components lodash @saber2pr/monaco
72
72
  ```
73
73
 
74
- 方式1: 引入 CodeSandbox 编辑器到页面中:
74
+ Method 1: Introduce Codesandbox editor to the page:
75
75
 
76
76
  ```tsx
77
77
  import { CodeSandboxButton } from '@ray/code-sandbox/lib/txp'
78
78
 
79
79
  <CodeSandboxButton
80
- title="Playground" // 编辑器弹窗的标题
80
+ title="Playground" // The title of Editor's pop -up window
81
81
  code={`
82
82
  import { Button } from '@ray-js/smartui';
83
83
 
@@ -86,20 +86,20 @@ return <Button>测试</Button>
86
86
  }
87
87
 
88
88
  `}
89
- txpCode="SmartUi" // 这里填写 TxP 上的组件code
90
- pageName="playground" // 小程序项目中引入 codesandbox 组件的页面名,例如pages/playground/index,pageName就是playground
89
+ txpCode="SmartUi" // Fill in the component Code on TXP here
90
+ pageName="playground" // The page name of the CodeSandBox component is introduced in the applet project, such as Pages/Playground/Index, and Pagename is Playgroundd
91
91
  />
92
92
  ```
93
93
 
94
- 点击按钮后就会弹窗打开 codesandbox 编辑器
94
+ After clicking the button, you will pop up the window to open the CodesandBox editor
95
95
 
96
- 方式2: 不使用按钮弹窗,直接接入编辑器+模拟器:
96
+ Method 2: Do not use the button pop -up window, directly access the editor+simulator:
97
97
 
98
98
  ```tsx
99
99
  import { CodeSandbox } from '@ray/code-sandbox/lib/txp'
100
100
 
101
101
  <CodeSandbox
102
- title="Button 组件" // demo 容器中的标题
102
+ title="Button 组件" // The title in DEMO container
103
103
  code={`
104
104
  import { Button } from '@ray-js/smartui';
105
105
 
@@ -108,14 +108,14 @@ export default function Demo() {
108
108
  }
109
109
 
110
110
  `}
111
- txpCode="SmartUi" // 这里填写 TxP 上的组件code
112
- pageName="playground" // 小程序项目中引入 codesandbox 组件的页面名,例如pages/playground/index,pageName就是playground
111
+ txpCode="SmartUi" // Fill in the component Code on TXP here
112
+ pageName="playground" // The page name of the CodeSandBox component is introduced in the applet project, such as Pages/Playground/Index, and Pagename is Playgroundd
113
113
  />
114
114
  ```
115
115
 
116
- ### 注意
116
+ ### Notice
117
117
 
118
- 1. txpCode 指定的组件,需要在 TxP 平台上经过 ci Demo构建才可以接入到 CodeSandbox 模拟器中。
118
+ 1. The components specified by TXPCODE need to be built through CI DEMO on the TXP platform before they can be connected to the Codesandbox simulator.
119
119
 
120
- 2. 编辑器涉及的资源、组件 Demo 容器都已上传到涂鸦 CDN,可在对外项目中使用。
121
- 3. 模拟器中大部分 BaseKit 能力支持,部分设备相关的 TTT 方法暂不支持。
120
+ 2. The resources and component DEMO containers involved in the editor have been uploaded to the graffiti CDN, which can be used in external projects.
121
+ 3. Most Basekit capabilities in the simulator support, some device -related TTT methods do not support it.
@@ -3,6 +3,9 @@ interface State {
3
3
  hasError: boolean;
4
4
  }
5
5
  interface IProps {
6
+ loadingText?: string;
7
+ grammarErrText?: string;
8
+ refreshButtonText?: string;
6
9
  }
7
10
  export default class CatchError extends React.Component<IProps, State> {
8
11
  static defaultProps: IProps;
@@ -17,7 +17,10 @@ export default class CatchError extends React.Component {
17
17
  render() {
18
18
  if (this.state.hasError) {
19
19
  return /*#__PURE__*/React.createElement(SandboxLoading, {
20
- type: "crash"
20
+ type: "crash",
21
+ loadingText: this.props.loadingText,
22
+ grammarErrText: this.props.grammarErrText,
23
+ refreshButtonText: this.props.refreshButtonText
21
24
  });
22
25
  }
23
26
  return this.props.children;
@@ -2,6 +2,9 @@ import React from 'react';
2
2
  export interface SandboxProps {
3
3
  defaultTitle?: string;
4
4
  context: any;
5
+ loadingText?: string;
6
+ grammarErrText?: string;
7
+ refreshButtonText?: string;
5
8
  }
6
9
  declare const CodeSandbox: React.FC<SandboxProps>;
7
10
  export default CodeSandbox;
@@ -7,13 +7,20 @@ import { ScrollView, View } from '@ray-js/ray';
7
7
  const CodeSandbox = _ref => {
8
8
  let {
9
9
  context: __ctx,
10
- defaultTitle = 'CodeSandbox'
10
+ defaultTitle = 'CodeSandbox',
11
+ loadingText,
12
+ grammarErrText,
13
+ refreshButtonText
11
14
  } = _ref;
12
15
  // 创建上下文对象
13
16
  // 设置上下文可用的组件
14
17
  const context = _objectSpread(_objectSpread({}, __ctx || {}), {}, {
15
18
  ___setContent___: () => /*#__PURE__*/React.createElement(React.Fragment, null),
16
- __loading__: SandboxLoading,
19
+ __loading__: () => /*#__PURE__*/React.createElement(SandboxLoading, {
20
+ loadingText: loadingText,
21
+ grammarErrText: grammarErrText,
22
+ refreshButtonText: refreshButtonText
23
+ }),
17
24
  // CodeSandbox 中可 import from 的三方库
18
25
  React,
19
26
  react: ReactLib
@@ -33,6 +40,9 @@ const CodeSandbox = _ref => {
33
40
  scrollY: true,
34
41
  refresherTriggered: false
35
42
  }, /*#__PURE__*/React.createElement(Decoder, {
43
+ loadingText: loadingText,
44
+ grammarErrText: grammarErrText,
45
+ refreshButtonText: refreshButtonText,
36
46
  onCodeChange: code => {
37
47
  // 获取到txp编辑器发送的js代码
38
48
  // 闭包保留变量名
@@ -2,6 +2,9 @@ import React from 'react';
2
2
  export interface DecoderProps {
3
3
  onCodeChange(code: string): void;
4
4
  children?: React.ReactNode;
5
+ loadingText?: string;
6
+ grammarErrText?: string;
7
+ refreshButtonText?: string;
5
8
  }
6
9
  export declare const Decoder: React.FC<DecoderProps>;
7
10
  export default Decoder;
@@ -5,9 +5,16 @@ import CatchError from '../catch-error';
5
5
  export const Decoder = _ref => {
6
6
  let {
7
7
  onCodeChange,
8
- children
8
+ children,
9
+ loadingText,
10
+ grammarErrText,
11
+ refreshButtonText
9
12
  } = _ref;
10
- return /*#__PURE__*/React.createElement(CatchError, null, /*#__PURE__*/React.createElement(Channel, {
13
+ return /*#__PURE__*/React.createElement(CatchError, {
14
+ loadingText: loadingText,
15
+ grammarErrText: grammarErrText,
16
+ refreshButtonText: refreshButtonText
17
+ }, /*#__PURE__*/React.createElement(Channel, {
11
18
  binddata: event => {
12
19
  const code = Bases64.decode(event.detail);
13
20
  onCodeChange(code);
@@ -1,5 +1,8 @@
1
1
  import React from 'react';
2
2
  export interface SandboxLoadingProps {
3
3
  type?: 'compile' | 'crash';
4
+ loadingText?: string;
5
+ grammarErrText?: string;
6
+ refreshButtonText?: string;
4
7
  }
5
8
  export declare const SandboxLoading: React.FC<SandboxLoadingProps>;
@@ -4,7 +4,10 @@ import { Loading, Button } from '@ray-js/smart-ui';
4
4
  import styles from './index.module.less';
5
5
  export const SandboxLoading = _ref => {
6
6
  let {
7
- type = 'compile'
7
+ type = 'compile',
8
+ refreshButtonText = '点击刷新',
9
+ loadingText = '小程序 CodeSandbox 编译中',
10
+ grammarErrText = '语法错误,请修正后刷新'
8
11
  } = _ref;
9
12
  return /*#__PURE__*/React.createElement(View, {
10
13
  className: styles.loading
@@ -14,9 +17,9 @@ export const SandboxLoading = _ref => {
14
17
  // @ts-ignore
15
18
  ty.reloadSandbox();
16
19
  }
17
- }, "\u70B9\u51FB\u5237\u65B0")), /*#__PURE__*/React.createElement(View, {
20
+ }, refreshButtonText)), /*#__PURE__*/React.createElement(View, {
18
21
  style: {
19
22
  marginTop: 16
20
23
  }
21
- }, type === 'compile' ? `小程序 CodeSandbox 编译中` : '语法错误,请修正后刷新'));
24
+ }, type === 'compile' ? loadingText : grammarErrText));
22
25
  };
@@ -7,6 +7,7 @@ export interface CodeEditorProps {
7
7
  height: string;
8
8
  txpCode: string;
9
9
  baseUri: string;
10
+ isZhLanguage?: boolean;
10
11
  }
11
12
  export declare const CodeEditor: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<{
12
13
  monaco: typeof import("monaco-editor");
@@ -14,7 +14,8 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
14
14
  show,
15
15
  height,
16
16
  txpCode,
17
- baseUri
17
+ baseUri,
18
+ isZhLanguage = true
18
19
  } = _ref;
19
20
  const [initloading, setInitLoading] = useState(true);
20
21
  const ref = useRef();
@@ -107,20 +108,23 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
107
108
  };
108
109
  }, [show]);
109
110
  useImperativeHandle(parentRef, () => ref.current);
111
+ const loaderConfig = {
112
+ paths: {
113
+ vs: `${baseUri}/static/txp-static-txp-monaco-editor/min/vs`
114
+ },
115
+ themeUri: `${baseUri}/static/txp-static-txp-monaco-editor/themes/`
116
+ };
117
+ if (isZhLanguage) {
118
+ loaderConfig['vs/nls'] = {
119
+ availableLanguages: {
120
+ '*': 'zh-cn'
121
+ }
122
+ };
123
+ }
110
124
  return /*#__PURE__*/React.createElement(Spin, {
111
125
  spinning: initloading
112
126
  }, code && /*#__PURE__*/React.createElement(Editor, {
113
- loaderConfig: {
114
- paths: {
115
- vs: `${baseUri}/static/txp-static-txp-monaco-editor/min/vs`
116
- },
117
- 'vs/nls': {
118
- availableLanguages: {
119
- '*': 'zh-cn'
120
- }
121
- },
122
- themeUri: `${baseUri}/static/txp-static-txp-monaco-editor/themes/`
123
- },
127
+ loaderConfig: loaderConfig,
124
128
  theme: "monokai-bright",
125
129
  style: {
126
130
  height
@@ -6,6 +6,8 @@ export interface CodeSandboxProps {
6
6
  txpCode: string;
7
7
  pageName: string;
8
8
  baseUri: string;
9
+ langKey?: string;
10
+ emptyText?: string;
9
11
  }
10
12
  export declare const CodeSandbox: React.FC<CodeSandboxProps>;
11
13
  export declare const checkShowCodeSandbox: (code: string) => boolean;
@@ -16,4 +18,6 @@ export declare const CodeSandboxButton: React.FC<{
16
18
  tooltip?: string;
17
19
  pageName: string;
18
20
  baseUri: string;
21
+ langKey?: string;
22
+ emptyText?: string;
19
23
  }>;
@@ -13,7 +13,9 @@ export const CodeSandbox = _ref => {
13
13
  title,
14
14
  show,
15
15
  pageName = 'playground',
16
- baseUri
16
+ baseUri,
17
+ langKey,
18
+ emptyText
17
19
  } = _ref;
18
20
  const iframeRef = useRef();
19
21
  const [ts, setTs] = useState(Date.now());
@@ -48,6 +50,8 @@ export const CodeSandbox = _ref => {
48
50
  postCode(newCode);
49
51
  }
50
52
  })), /*#__PURE__*/React.createElement(Right, null, /*#__PURE__*/React.createElement(Demo, {
53
+ emptyText: emptyText,
54
+ langKey: langKey,
51
55
  baseUri: baseUri,
52
56
  txpCode: txpCode,
53
57
  ts: ts,
@@ -72,7 +76,9 @@ export const CodeSandboxButton = _ref2 => {
72
76
  txpCode,
73
77
  tooltip = '在线编辑预览效果!',
74
78
  pageName,
75
- baseUri
79
+ baseUri,
80
+ emptyText,
81
+ langKey
76
82
  } = _ref2;
77
83
  const [show, setShow] = useState(false);
78
84
  const ref = useRef();
@@ -111,6 +117,8 @@ export const CodeSandboxButton = _ref2 => {
111
117
  setShow(false);
112
118
  }
113
119
  }, /*#__PURE__*/React.createElement(CodeSandbox, {
120
+ emptyText: emptyText,
121
+ langKey: langKey,
114
122
  baseUri: baseUri,
115
123
  txpCode: txpCode,
116
124
  pageName: pageName,
@@ -6,6 +6,8 @@ export interface DemoProps {
6
6
  ts?: number;
7
7
  txpCode: string;
8
8
  baseUri: string;
9
+ langKey?: string;
10
+ emptyText: string;
9
11
  }
10
12
  export interface DemoRef {
11
13
  postMsg(data: any): void;
@@ -11,10 +11,12 @@ export const Demo = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
11
11
  style,
12
12
  ts,
13
13
  txpCode,
14
- baseUri
14
+ baseUri,
15
+ langKey = 'zh',
16
+ emptyText
15
17
  } = _ref;
16
18
  let path = `${createCompnentUri(baseUri, txpCode, `index.html`)}?t=${ts || Date.now()}`;
17
- path += `#!/pages/${comId}/index`;
19
+ path += `#!/pages/${comId}/index&langKey=${langKey}`;
18
20
  const ref = useRef();
19
21
  useImperativeHandle(parentRef, () => ({
20
22
  postMsg: data => {
@@ -49,6 +51,7 @@ export const Demo = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
49
51
  src: path,
50
52
  style: {
51
53
  borderRadius: 0
52
- }
54
+ },
55
+ emptyText: emptyText
53
56
  }));
54
57
  });
@@ -3,5 +3,6 @@ export interface SandboxProps {
3
3
  src: string;
4
4
  style?: React.CSSProperties;
5
5
  sandboxId?: string;
6
+ emptyText?: string;
6
7
  }
7
8
  export declare const Sandbox: React.ForwardRefExoticComponent<SandboxProps & React.RefAttributes<HTMLIFrameElement>>;
@@ -5,14 +5,15 @@ export const Sandbox = /*#__PURE__*/React.forwardRef((_ref, ref) => {
5
5
  let {
6
6
  src,
7
7
  style,
8
- sandboxId
8
+ sandboxId,
9
+ emptyText = '暂无演示'
9
10
  } = _ref;
10
11
  const {
11
12
  data: hasUri,
12
13
  loading
13
14
  } = useTestUri(src);
14
15
  let content = /*#__PURE__*/React.createElement(SandboxEmpty, {
15
- description: "\u6682\u65E0\u6F14\u793A"
16
+ description: emptyText
16
17
  });
17
18
  if (loading) {
18
19
  content = /*#__PURE__*/React.createElement(SandboxSkeleton, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/code-sandbox",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-beta-2",
4
4
  "description": "小程序 CodeSandbox 容器",
5
5
  "main": "lib/index",
6
6
  "files": [