@ray-js/code-sandbox 0.0.7-beta-9 → 0.0.7-beta-11

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.
@@ -5,6 +5,7 @@ export interface DecoderProps {
5
5
  loadingText?: string;
6
6
  grammarErrText?: string;
7
7
  refreshButtonText?: string;
8
+ channel?: string;
8
9
  }
9
10
  export declare const Decoder: React.FC<DecoderProps>;
10
11
  export default Decoder;
@@ -8,13 +8,15 @@ export const Decoder = _ref => {
8
8
  children,
9
9
  loadingText,
10
10
  grammarErrText,
11
- refreshButtonText
11
+ refreshButtonText,
12
+ channel
12
13
  } = _ref;
13
14
  return /*#__PURE__*/React.createElement(CatchError, {
14
15
  loadingText: loadingText,
15
16
  grammarErrText: grammarErrText,
16
17
  refreshButtonText: refreshButtonText
17
18
  }, /*#__PURE__*/React.createElement(Channel, {
19
+ channel: channel,
18
20
  binddata: event => {
19
21
  const code = Bases64.decode(event.detail);
20
22
  onCodeChange(code);
@@ -2,6 +2,7 @@
2
2
  import React from 'react';
3
3
 
4
4
  export interface ChannelProps {
5
+ channel?: string;
5
6
  binddata(event: { detail: string });
6
7
  }
7
8
 
@@ -1,5 +1,8 @@
1
1
  Component({
2
2
  properties: {
3
- instanceId: String
3
+ channel: {
4
+ type: String,
5
+ value: 'sandbox-jsrun'
6
+ }
4
7
  }
5
8
  });
@@ -1,7 +1,8 @@
1
1
  module.exports = {
2
2
  init(newVal, oldVal, ownerInstance) {
3
- ownerInstance.eventChannel.on('sandbox-jsrun', event => {
4
- console.log(`[sandbox] trigger `, event);
3
+ const eventName = newVal || 'sandbox-jsrun';
4
+ ownerInstance.eventChannel.on(eventName, event => {
5
+ console.log(`[sandbox] trigger `, eventName, event);
5
6
  ownerInstance.triggerEvent('data', event);
6
7
  });
7
8
  },
@@ -1,6 +1,6 @@
1
1
  <sjs src="./index.sjs" module="computed"></sjs>
2
2
 
3
3
  <view
4
- id="{{instanceId}}"
5
- change:id="{{computed.init}}"
4
+ channel="{{channel}}"
5
+ change:channel="{{computed.init}}"
6
6
  ></view>
@@ -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
- // react
49
- await addTypeLib('react.d.ts');
50
- // @ray-js/smartui
51
- await addTypeLib('smartui.d.ts');
52
- // @ray-js/ray
53
- await addTypeLib('ray.d.ts');
54
- // csstypes
55
- await addTypeLib('csstype.d.ts', 'csstype');
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
- // BaseKit Kit types
60
- await addTypeLib('BaseKit.d.ts');
61
- // BizKit Kit types
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: string;
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: string;
28
+ pageName?: string;
28
29
  baseUri: string;
29
30
  emptyText?: string;
30
31
  isZhLanguage?: boolean;
@@ -46,7 +47,7 @@ export declare const CodeSandboxButton: React.FC<{
46
47
  langKey?: string;
47
48
  tooltip?: string;
48
49
  txpCode: string;
49
- pageName: string;
50
+ pageName?: string;
50
51
  baseUri: string;
51
52
  emptyText?: string;
52
53
  isZhLanguage?: boolean;
@@ -54,5 +55,6 @@ export declare const CodeSandboxButton: React.FC<{
54
55
  buttonProps?: ButtonProps;
55
56
  cssCode?: string;
56
57
  styMap?: any;
58
+ noTypeInit?: boolean;
57
59
  cssParse?: (css: string) => Promise<string>;
58
60
  }>;
@@ -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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/code-sandbox",
3
- "version": "0.0.7-beta-9",
3
+ "version": "0.0.7-beta-11",
4
4
  "description": "小程序 CodeSandbox 容器",
5
5
  "main": "lib/index",
6
6
  "files": [
package/README-zh_CN.md DELETED
@@ -1,121 +0,0 @@
1
- [English](./README.md) | 简体中文
2
-
3
- # @ray-js/code-sandbox
4
-
5
- [![latest](https://img.shields.io/npm/v/@ray-js/code-sandbox/latest.svg)](https://www.npmjs.com/package/@ray-js/code-sandbox) [![download](https://img.shields.io/npm/dt/@ray-js/code-sandbox.svg)](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 方法暂不支持。