@ray-js/code-sandbox 0.0.2 → 0.0.3-beta-1
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 +21 -21
- package/lib/catch-error/index.d.ts +3 -0
- package/lib/catch-error/index.js +4 -1
- package/lib/codesandbox/index.d.ts +3 -0
- package/lib/codesandbox/index.js +12 -2
- package/lib/decoder/index.d.ts +3 -0
- package/lib/decoder/index.js +9 -2
- package/lib/loading/index.d.ts +3 -0
- package/lib/loading/index.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ English | [简体中文](./README-zh_CN.md)
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@ray/code-sandbox) [](https://www.npmjs.com/package/@ray/code-sandbox)
|
|
6
6
|
|
|
7
|
-
>
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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" //
|
|
90
|
-
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
|
-
|
|
94
|
+
After clicking the button, you will pop up the window to open the CodesandBox editor
|
|
95
95
|
|
|
96
|
-
|
|
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 组件" //
|
|
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" //
|
|
112
|
-
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.
|
|
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.
|
|
121
|
-
3.
|
|
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.
|
package/lib/catch-error/index.js
CHANGED
|
@@ -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;
|
package/lib/codesandbox/index.js
CHANGED
|
@@ -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
|
// 闭包保留变量名
|
package/lib/decoder/index.d.ts
CHANGED
|
@@ -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;
|
package/lib/decoder/index.js
CHANGED
|
@@ -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,
|
|
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);
|
package/lib/loading/index.d.ts
CHANGED
package/lib/loading/index.js
CHANGED
|
@@ -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
|
-
},
|
|
20
|
+
}, refreshButtonText)), /*#__PURE__*/React.createElement(View, {
|
|
18
21
|
style: {
|
|
19
22
|
marginTop: 16
|
|
20
23
|
}
|
|
21
|
-
}, type === 'compile' ?
|
|
24
|
+
}, type === 'compile' ? loadingText : grammarErrText));
|
|
22
25
|
};
|