@ray-js/code-sandbox 0.0.5 → 0.0.7

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.
@@ -1,5 +1,6 @@
1
- import { DrawerProps } from 'antd';
1
+ import { ButtonProps, DrawerProps } from 'antd';
2
2
  import React from 'react';
3
+ import { EditorAPI } from '@saber2pr/monaco';
3
4
  export interface CodeSandboxProps {
4
5
  code: string;
5
6
  title: string;
@@ -10,6 +11,7 @@ export interface CodeSandboxProps {
10
11
  langKey?: string;
11
12
  emptyText?: string;
12
13
  isZhLanguage?: boolean;
14
+ editorApi?: EditorAPI;
13
15
  }
14
16
  export declare const CodeSandbox: React.FC<CodeSandboxProps>;
15
17
  export declare const checkShowCodeSandbox: (code: string) => boolean;
@@ -25,8 +27,9 @@ export interface UseCodeSandboxDrawerOps {
25
27
  isZhLanguage?: boolean;
26
28
  code: string;
27
29
  langKey?: string;
30
+ editorApi?: EditorAPI;
28
31
  }
29
- export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, }: UseCodeSandboxDrawerOps) => {
32
+ export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, }: UseCodeSandboxDrawerOps) => {
30
33
  modal: React.JSX.Element;
31
34
  show: boolean;
32
35
  setShow: React.Dispatch<React.SetStateAction<boolean>>;
@@ -41,4 +44,6 @@ export declare const CodeSandboxButton: React.FC<{
41
44
  baseUri: string;
42
45
  emptyText?: string;
43
46
  isZhLanguage?: boolean;
47
+ editorApi?: EditorAPI;
48
+ buttonProps?: ButtonProps;
44
49
  }>;
@@ -1,6 +1,8 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- const _excluded = ["tooltip"];
4
+ const _excluded = ["tooltip", "buttonProps"];
5
+ /* eslint-disable react/self-closing-comp */
4
6
  import { Button, Drawer, Tooltip } from 'antd';
5
7
  import _ from 'lodash';
6
8
  import React, { useCallback, useEffect, useRef, useState } from 'react';
@@ -19,11 +21,12 @@ export const CodeSandbox = _ref => {
19
21
  baseUri,
20
22
  langKey,
21
23
  emptyText,
22
- isZhLanguage
24
+ isZhLanguage,
25
+ editorApi
23
26
  } = _ref;
24
27
  const iframeRef = useRef();
25
28
  const [ts, setTs] = useState(Date.now());
26
- const apiRef = useRef();
29
+ const apiRef = useRef(editorApi);
27
30
  useEffect(() => {
28
31
  const handle = event => {
29
32
  var _event$data;
@@ -86,7 +89,8 @@ export const useCodeSandboxDrawer = _ref2 => {
86
89
  emptyText,
87
90
  langKey,
88
91
  baseUri,
89
- code
92
+ code,
93
+ editorApi
90
94
  } = _ref2;
91
95
  const [show, setShow] = useState(false);
92
96
  return {
@@ -107,6 +111,7 @@ export const useCodeSandboxDrawer = _ref2 => {
107
111
  setShow(false);
108
112
  }
109
113
  }, /*#__PURE__*/React.createElement(CodeSandbox, {
114
+ editorApi: editorApi,
110
115
  isZhLanguage: isZhLanguage,
111
116
  emptyText: emptyText,
112
117
  langKey: langKey,
@@ -123,7 +128,8 @@ export const useCodeSandboxDrawer = _ref2 => {
123
128
  };
124
129
  export const CodeSandboxButton = _ref3 => {
125
130
  let {
126
- tooltip
131
+ tooltip,
132
+ buttonProps
127
133
  } = _ref3,
128
134
  props = _objectWithoutProperties(_ref3, _excluded);
129
135
  const api = useCodeSandboxDrawer(_objectSpread(_objectSpread({}, props), {}, {
@@ -135,7 +141,7 @@ export const CodeSandboxButton = _ref3 => {
135
141
  ref: ref
136
142
  }, /*#__PURE__*/React.createElement(Tooltip, {
137
143
  title: tooltip
138
- }, /*#__PURE__*/React.createElement(Button, {
144
+ }, /*#__PURE__*/React.createElement(Button, _extends({
139
145
  type: "link",
140
146
  icon: /*#__PURE__*/React.createElement(CodeSandboxOutlined, {
141
147
  style: {
@@ -149,5 +155,5 @@ export const CodeSandboxButton = _ref3 => {
149
155
  justifyContent: 'center'
150
156
  },
151
157
  onClick: () => api.setShow(true)
152
- })), api.modal);
158
+ }, buttonProps || {}))), api.modal);
153
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/code-sandbox",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "小程序 CodeSandbox 容器",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix",
20
- "build": "patch-package && ray build --type=component",
20
+ "build": "export BROWSERSLIST='Last 3 versions' && patch-package && ray build --type=component",
21
21
  "watch": "ray start --type=component --output ./example/src/lib",
22
22
  "build:tuya": "ray build ./example",
23
23
  "build:wechat": "ray build ./example --target=wechat",
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 方法暂不支持。