@ray-js/code-sandbox 0.0.7-beta-10 → 0.0.7-beta-12
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.
|
@@ -11,6 +11,7 @@ export interface CodeEditorProps {
|
|
|
11
11
|
style?: React.CSSProperties;
|
|
12
12
|
fileName?: string;
|
|
13
13
|
cssParse?: (css: string) => Promise<string>;
|
|
14
|
+
noTypeInit?: boolean;
|
|
14
15
|
}
|
|
15
16
|
export declare const CodeEditor: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<{
|
|
16
17
|
monaco: typeof import("monaco-editor");
|
|
@@ -19,7 +19,8 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
19
19
|
isZhLanguage = true,
|
|
20
20
|
style,
|
|
21
21
|
fileName = 'main.tsx',
|
|
22
|
-
cssParse
|
|
22
|
+
cssParse,
|
|
23
|
+
noTypeInit = false
|
|
23
24
|
} = _ref;
|
|
24
25
|
const [initloading, setInitLoading] = useState(true);
|
|
25
26
|
const ref = useRef();
|
|
@@ -44,29 +45,30 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
44
45
|
editor.addExtraLib(smartUiTypes, name);
|
|
45
46
|
} catch (error) {}
|
|
46
47
|
};
|
|
48
|
+
if (!noTypeInit) {
|
|
49
|
+
// react
|
|
50
|
+
await addTypeLib('react.d.ts');
|
|
51
|
+
// @ray-js/smartui
|
|
52
|
+
await addTypeLib('smartui.d.ts');
|
|
53
|
+
// @ray-js/ray
|
|
54
|
+
await addTypeLib('ray.d.ts');
|
|
55
|
+
// csstypes
|
|
56
|
+
await addTypeLib('csstype.d.ts', 'csstype');
|
|
57
|
+
// prop-types
|
|
58
|
+
await addTypeLib('prop-types.d.ts', 'prop-types');
|
|
47
59
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// prop-types
|
|
57
|
-
await addTypeLib('prop-types.d.ts', 'prop-types');
|
|
60
|
+
// BaseKit Kit types
|
|
61
|
+
await addTypeLib('BaseKit.d.ts');
|
|
62
|
+
// BizKit Kit types
|
|
63
|
+
await addTypeLib('BizKit.d.ts');
|
|
64
|
+
// Device Kit types
|
|
65
|
+
await addTypeLib('DeviceKit.d.ts');
|
|
66
|
+
// MiniKit Kit types
|
|
67
|
+
await addTypeLib('MiniKit.d.ts');
|
|
58
68
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await addTypeLib('BizKit.d.ts');
|
|
63
|
-
// Device Kit types
|
|
64
|
-
await addTypeLib('DeviceKit.d.ts');
|
|
65
|
-
// MiniKit Kit types
|
|
66
|
-
await addTypeLib('MiniKit.d.ts');
|
|
67
|
-
|
|
68
|
-
// rayKit
|
|
69
|
-
await addTypeLib('rayKit.d.ts');
|
|
69
|
+
// rayKit
|
|
70
|
+
await addTypeLib('rayKit.d.ts');
|
|
71
|
+
}
|
|
70
72
|
};
|
|
71
73
|
useEffect(() => {
|
|
72
74
|
const handle = async event => {
|
|
@@ -6,7 +6,7 @@ export interface CodeSandboxProps {
|
|
|
6
6
|
title: string;
|
|
7
7
|
show?: boolean;
|
|
8
8
|
txpCode: string;
|
|
9
|
-
pageName
|
|
9
|
+
pageName?: string;
|
|
10
10
|
baseUri: string;
|
|
11
11
|
langKey?: string;
|
|
12
12
|
emptyText?: string;
|
|
@@ -15,6 +15,7 @@ export interface CodeSandboxProps {
|
|
|
15
15
|
cssCode?: string;
|
|
16
16
|
styMap?: any;
|
|
17
17
|
cssParse?: (css: string) => Promise<string>;
|
|
18
|
+
noTypeInit?: boolean;
|
|
18
19
|
}
|
|
19
20
|
export declare const CodeSandbox: React.FC<CodeSandboxProps>;
|
|
20
21
|
export declare const checkShowCodeSandbox: (code: string) => boolean;
|
|
@@ -24,7 +25,7 @@ export interface UseCodeSandboxDrawerOps {
|
|
|
24
25
|
height?: string;
|
|
25
26
|
placement?: DrawerProps['placement'];
|
|
26
27
|
txpCode: string;
|
|
27
|
-
pageName
|
|
28
|
+
pageName?: string;
|
|
28
29
|
baseUri: string;
|
|
29
30
|
emptyText?: string;
|
|
30
31
|
isZhLanguage?: boolean;
|
|
@@ -34,8 +35,9 @@ export interface UseCodeSandboxDrawerOps {
|
|
|
34
35
|
cssCode?: string;
|
|
35
36
|
styMap?: any;
|
|
36
37
|
cssParse?: (css: string) => Promise<string>;
|
|
38
|
+
noTypeInit?: boolean;
|
|
37
39
|
}
|
|
38
|
-
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, cssCode, styMap, cssParse, }: UseCodeSandboxDrawerOps) => {
|
|
40
|
+
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, cssCode, styMap, cssParse, noTypeInit, }: UseCodeSandboxDrawerOps) => {
|
|
39
41
|
modal: React.JSX.Element;
|
|
40
42
|
show: boolean;
|
|
41
43
|
setShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
@@ -46,7 +48,7 @@ export declare const CodeSandboxButton: React.FC<{
|
|
|
46
48
|
langKey?: string;
|
|
47
49
|
tooltip?: string;
|
|
48
50
|
txpCode: string;
|
|
49
|
-
pageName
|
|
51
|
+
pageName?: string;
|
|
50
52
|
baseUri: string;
|
|
51
53
|
emptyText?: string;
|
|
52
54
|
isZhLanguage?: boolean;
|
|
@@ -54,5 +56,6 @@ export declare const CodeSandboxButton: React.FC<{
|
|
|
54
56
|
buttonProps?: ButtonProps;
|
|
55
57
|
cssCode?: string;
|
|
56
58
|
styMap?: any;
|
|
59
|
+
noTypeInit?: boolean;
|
|
57
60
|
cssParse?: (css: string) => Promise<string>;
|
|
58
61
|
}>;
|
|
@@ -25,7 +25,8 @@ export const CodeSandbox = _ref => {
|
|
|
25
25
|
editorApi,
|
|
26
26
|
cssCode,
|
|
27
27
|
styMap,
|
|
28
|
-
cssParse
|
|
28
|
+
cssParse,
|
|
29
|
+
noTypeInit
|
|
29
30
|
} = _ref;
|
|
30
31
|
const iframeRef = useRef();
|
|
31
32
|
const [ts, setTs] = useState(Date.now());
|
|
@@ -54,6 +55,7 @@ export const CodeSandbox = _ref => {
|
|
|
54
55
|
}
|
|
55
56
|
}, 500), [show, styMap]);
|
|
56
57
|
return /*#__PURE__*/React.createElement(Contain, null, /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(Main, null, styMap ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MainHeader, null, /*#__PURE__*/React.createElement(MainHeaderItem, null, "CSS Style Sheet"), /*#__PURE__*/React.createElement(MainHeaderItem, null, "Js Code")), /*#__PURE__*/React.createElement(MainContent, null, /*#__PURE__*/React.createElement(CodeEditor, {
|
|
58
|
+
noTypeInit: true,
|
|
57
59
|
isZhLanguage: isZhLanguage,
|
|
58
60
|
baseUri: baseUri,
|
|
59
61
|
txpCode: txpCode,
|
|
@@ -70,6 +72,7 @@ export const CodeSandbox = _ref => {
|
|
|
70
72
|
},
|
|
71
73
|
cssParse: cssParse
|
|
72
74
|
}), /*#__PURE__*/React.createElement(CodeEditor, {
|
|
75
|
+
noTypeInit: noTypeInit,
|
|
73
76
|
isZhLanguage: isZhLanguage,
|
|
74
77
|
baseUri: baseUri,
|
|
75
78
|
txpCode: txpCode,
|
|
@@ -88,6 +91,7 @@ export const CodeSandbox = _ref => {
|
|
|
88
91
|
}))) : /*#__PURE__*/React.createElement(CodeEditor, {
|
|
89
92
|
isZhLanguage: isZhLanguage,
|
|
90
93
|
baseUri: baseUri,
|
|
94
|
+
noTypeInit: noTypeInit,
|
|
91
95
|
txpCode: txpCode,
|
|
92
96
|
height: "calc(90vh - 103px + 48px)",
|
|
93
97
|
ref: apiRef,
|
|
@@ -97,7 +101,7 @@ export const CodeSandbox = _ref => {
|
|
|
97
101
|
onChange: newCode => {
|
|
98
102
|
postCode(newCode);
|
|
99
103
|
}
|
|
100
|
-
})), /*#__PURE__*/React.createElement(Right, null, /*#__PURE__*/React.createElement(Demo, {
|
|
104
|
+
})), pageName && /*#__PURE__*/React.createElement(Right, null, /*#__PURE__*/React.createElement(Demo, {
|
|
101
105
|
emptyText: emptyText,
|
|
102
106
|
langKey: langKey,
|
|
103
107
|
baseUri: baseUri,
|
|
@@ -133,7 +137,8 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
133
137
|
editorApi,
|
|
134
138
|
cssCode,
|
|
135
139
|
styMap,
|
|
136
|
-
cssParse
|
|
140
|
+
cssParse,
|
|
141
|
+
noTypeInit
|
|
137
142
|
} = _ref2;
|
|
138
143
|
const [show, setShow] = useState(false);
|
|
139
144
|
return {
|
|
@@ -154,6 +159,7 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
154
159
|
setShow(false);
|
|
155
160
|
}
|
|
156
161
|
}, /*#__PURE__*/React.createElement(CodeSandbox, {
|
|
162
|
+
noTypeInit: noTypeInit,
|
|
157
163
|
editorApi: editorApi,
|
|
158
164
|
isZhLanguage: isZhLanguage,
|
|
159
165
|
emptyText: emptyText,
|
package/package.json
CHANGED
package/README-zh_CN.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
[English](./README.md) | 简体中文
|
|
2
|
-
|
|
3
|
-
# @ray-js/code-sandbox
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@ray-js/code-sandbox) [](https://www.npmjs.com/package/@ray-js/code-sandbox)
|
|
6
|
-
|
|
7
|
-
> 小程序 CodeSandbox 容器
|
|
8
|
-
|
|
9
|
-
## 安装
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
$ npm install @ray-js/code-sandbox
|
|
13
|
-
// 或者
|
|
14
|
-
$ yarn add @ray-js/code-sandbox
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## 开发
|
|
18
|
-
|
|
19
|
-
```sh
|
|
20
|
-
# 实时编译组件代码
|
|
21
|
-
yarn watch
|
|
22
|
-
# 实时编译Demo代码
|
|
23
|
-
yarn start:tuya
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## 使用
|
|
27
|
-
|
|
28
|
-
### 小程序对接
|
|
29
|
-
|
|
30
|
-
安装必须的依赖
|
|
31
|
-
|
|
32
|
-
```sh
|
|
33
|
-
yarn add @ray-js/code-sandbox
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
pages 目录下新建 playground 页面,内容如下
|
|
37
|
-
|
|
38
|
-
```tsx
|
|
39
|
-
import React from 'react';
|
|
40
|
-
import CodeSandbox from '@ray-js/code-sandbox';
|
|
41
|
-
|
|
42
|
-
import * as RayComponents from '@ray-js/ray';
|
|
43
|
-
|
|
44
|
-
export default function Home() {
|
|
45
|
-
return (
|
|
46
|
-
<CodeSandbox
|
|
47
|
-
defaultTitle="CodeSandbox"
|
|
48
|
-
context={{
|
|
49
|
-
// CodeSandbox 中可 import from 的三方库
|
|
50
|
-
'@ray-js/ray': RayComponents,
|
|
51
|
-
}}
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
页面 index.config 配置自定义 Topbar
|
|
58
|
-
|
|
59
|
-
```tsx
|
|
60
|
-
export default {
|
|
61
|
-
navigationStyle: 'custom',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### 平台对接
|
|
67
|
-
|
|
68
|
-
安装必须的依赖
|
|
69
|
-
|
|
70
|
-
```sh
|
|
71
|
-
yarn add @ray-js/code-sandbox antd axios styled-components lodash @saber2pr/monaco
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
方式1: 引入 CodeSandbox 编辑器到页面中:
|
|
75
|
-
|
|
76
|
-
```tsx
|
|
77
|
-
import { CodeSandboxButton } from '@ray-js/code-sandbox/lib/txp'
|
|
78
|
-
|
|
79
|
-
<CodeSandboxButton
|
|
80
|
-
title="Playground" // 编辑器弹窗的标题
|
|
81
|
-
code={`
|
|
82
|
-
import { Button } from '@ray-js/smartui';
|
|
83
|
-
|
|
84
|
-
export default function Demo() {
|
|
85
|
-
return <Button>测试</Button>
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
`}
|
|
89
|
-
txpCode="SmartUi" // 这里填写 TxP 上的组件code
|
|
90
|
-
pageName="playground" // 小程序项目中引入 codesandbox 组件的页面名,例如pages/playground/index,pageName就是playground
|
|
91
|
-
/>
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
点击按钮后就会弹窗打开 codesandbox 编辑器
|
|
95
|
-
|
|
96
|
-
方式2: 不使用按钮弹窗,直接接入编辑器+模拟器:
|
|
97
|
-
|
|
98
|
-
```tsx
|
|
99
|
-
import { CodeSandbox } from '@ray-js/code-sandbox/lib/txp'
|
|
100
|
-
|
|
101
|
-
<CodeSandbox
|
|
102
|
-
title="Button 组件" // demo 容器中的标题
|
|
103
|
-
code={`
|
|
104
|
-
import { Button } from '@ray-js/smartui';
|
|
105
|
-
|
|
106
|
-
export default function Demo() {
|
|
107
|
-
return <Button>测试</Button>
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
`}
|
|
111
|
-
txpCode="SmartUi" // 这里填写 TxP 上的组件code
|
|
112
|
-
pageName="playground" // 小程序项目中引入 codesandbox 组件的页面名,例如pages/playground/index,pageName就是playground
|
|
113
|
-
/>
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### 注意
|
|
117
|
-
|
|
118
|
-
1. txpCode 指定的组件,需要在 TxP 平台上经过 ci Demo构建才可以接入到 CodeSandbox 模拟器中。
|
|
119
|
-
|
|
120
|
-
2. 编辑器涉及的资源、组件 Demo 容器都已上传到涂鸦 CDN,可在对外项目中使用。
|
|
121
|
-
3. 模拟器中大部分 BaseKit 能力支持,部分设备相关的 TTT 方法暂不支持。
|