@ray-js/code-sandbox 0.0.3-beta-4 → 0.0.3-beta-6

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
@@ -1,17 +1,17 @@
1
1
  English | [简体中文](./README-zh_CN.md)
2
2
 
3
- # @ray/code-sandbox
3
+ # @ray-js/code-sandbox
4
4
 
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)
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
6
 
7
7
  > CodeSandBox container
8
8
 
9
9
  ## Installation
10
10
 
11
11
  ```sh
12
- $ npm install @ray/code-sandbox
12
+ $ npm install @ray-js/code-sandbox
13
13
  # or
14
- $ yarn add @ray/code-sandbox
14
+ $ yarn add @ray-js/code-sandbox
15
15
  ```
16
16
 
17
17
  ## Develop
@@ -30,14 +30,14 @@ yarn start:tuya
30
30
  Must -dependencies in installation
31
31
 
32
32
  ```sh
33
- yarn add @ray/code-sandbox @ray-js/ray @ray-js/smart-ui @tuya-miniapp/smart-ui
33
+ yarn add @ray-js/code-sandbox @ray-js/ray
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';
40
- import CodeSandbox from '@ray/code-sandbox';
40
+ import CodeSandbox from '@ray-js/code-sandbox';
41
41
 
42
42
  import * as RayComponents from '@ray-js/ray';
43
43
 
@@ -68,13 +68,13 @@ export default {
68
68
  Must -dependencies in installation
69
69
 
70
70
  ```sh
71
- yarn add @ray/code-sandbox antd axios styled-components lodash @saber2pr/monaco
71
+ yarn add @ray-js/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
- import { CodeSandboxButton } from '@ray/code-sandbox/lib/txp'
77
+ import { CodeSandboxButton } from '@ray-js/code-sandbox/lib/txp'
78
78
 
79
79
  <CodeSandboxButton
80
80
  title="Playground" // The title of Editor's pop -up window
@@ -96,7 +96,7 @@ After clicking the button, you will pop up the window to open the CodesandBox ed
96
96
  Method 2: Do not use the button pop -up window, directly access the editor+simulator:
97
97
 
98
98
  ```tsx
99
- import { CodeSandbox } from '@ray/code-sandbox/lib/txp'
99
+ import { CodeSandbox } from '@ray-js/code-sandbox/lib/txp'
100
100
 
101
101
  <CodeSandbox
102
102
  title="Button 组件" // The title in DEMO container
@@ -1,6 +1,6 @@
1
- import { View } from '@ray-js/ray';
1
+ import { Button, View } from '@ray-js/ray';
2
2
  import React from 'react';
3
- import { Loading, Button } from '@ray-js/smart-ui';
3
+ import Loading from '@ray-js/components-ty-loading';
4
4
  import styles from './index.module.less';
5
5
  export const SandboxLoading = _ref => {
6
6
  let {
@@ -11,7 +11,9 @@ export const SandboxLoading = _ref => {
11
11
  } = _ref;
12
12
  return /*#__PURE__*/React.createElement(View, {
13
13
  className: styles.loading
14
- }, /*#__PURE__*/React.createElement(View, null, type === 'compile' ? /*#__PURE__*/React.createElement(Loading, null) : /*#__PURE__*/React.createElement(Button, {
14
+ }, /*#__PURE__*/React.createElement(View, null, type === 'compile' ? /*#__PURE__*/React.createElement(Loading, {
15
+ size: "100rpx"
16
+ }) : /*#__PURE__*/React.createElement(Button, {
15
17
  onClick: () => {
16
18
  // reloadSandbox 方法是 ci 打包时注入的 api,和 txp 平台交互(postmessage)
17
19
  // @ts-ignore
@@ -1,6 +1,6 @@
1
1
  import { Spin } from 'antd';
2
- import { getComponentResource } from '../../services';
3
2
  import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
3
+ import { getComponentResource } from '../../services';
4
4
  import { Editor } from '@saber2pr/monaco';
5
5
  const timeout = function () {
6
6
  let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1000;
@@ -1,3 +1,4 @@
1
+ import { DrawerProps } from 'antd';
1
2
  import React from 'react';
2
3
  export interface CodeSandboxProps {
3
4
  code: string;
@@ -12,14 +13,32 @@ export interface CodeSandboxProps {
12
13
  }
13
14
  export declare const CodeSandbox: React.FC<CodeSandboxProps>;
14
15
  export declare const checkShowCodeSandbox: (code: string) => boolean;
16
+ export interface UseCodeSandboxDrawerOps {
17
+ getContainer?: DrawerProps['getContainer'];
18
+ title: string;
19
+ height?: string;
20
+ placement?: DrawerProps['placement'];
21
+ txpCode: string;
22
+ pageName: string;
23
+ baseUri: string;
24
+ emptyText?: string;
25
+ isZhLanguage?: boolean;
26
+ code: string;
27
+ langKey?: string;
28
+ }
29
+ export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, }: UseCodeSandboxDrawerOps) => {
30
+ modal: React.JSX.Element;
31
+ show: boolean;
32
+ setShow: React.Dispatch<React.SetStateAction<boolean>>;
33
+ };
15
34
  export declare const CodeSandboxButton: React.FC<{
16
35
  code: string;
17
36
  title: string;
18
- txpCode: string;
37
+ langKey?: string;
19
38
  tooltip?: string;
39
+ txpCode: string;
20
40
  pageName: string;
21
41
  baseUri: string;
22
- langKey?: string;
23
42
  emptyText?: string;
24
43
  isZhLanguage?: boolean;
25
44
  }>;
@@ -1,3 +1,6 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ const _excluded = ["tooltip"];
1
4
  import { Button, Drawer, Tooltip } from 'antd';
2
5
  import _ from 'lodash';
3
6
  import React, { useCallback, useEffect, useRef, useState } from 'react';
@@ -71,19 +74,62 @@ export const checkShowCodeSandbox = code => {
71
74
  }
72
75
  return false;
73
76
  };
74
- export const CodeSandboxButton = _ref2 => {
77
+ export const useCodeSandboxDrawer = _ref2 => {
75
78
  let {
76
- code,
79
+ getContainer,
77
80
  title,
78
- txpCode,
79
- tooltip = '在线编辑预览效果!',
81
+ height = '90vh',
82
+ placement = 'bottom',
83
+ isZhLanguage,
80
84
  pageName,
81
- baseUri,
85
+ txpCode,
82
86
  emptyText,
83
87
  langKey,
84
- isZhLanguage
88
+ baseUri,
89
+ code
85
90
  } = _ref2;
86
91
  const [show, setShow] = useState(false);
92
+ return {
93
+ modal: /*#__PURE__*/React.createElement(Drawer, {
94
+ getContainer: getContainer,
95
+ title: `${title}`,
96
+ height: height,
97
+ contentWrapperStyle: {
98
+ padding: 0
99
+ },
100
+ style: {
101
+ padding: 0
102
+ },
103
+ placement: placement,
104
+ destroyOnClose: true,
105
+ open: show,
106
+ onClose: () => {
107
+ setShow(false);
108
+ }
109
+ }, /*#__PURE__*/React.createElement(CodeSandbox, {
110
+ isZhLanguage: isZhLanguage,
111
+ emptyText: emptyText,
112
+ langKey: langKey,
113
+ baseUri: baseUri,
114
+ txpCode: txpCode,
115
+ pageName: pageName,
116
+ show: show,
117
+ title: title,
118
+ code: code
119
+ })),
120
+ show,
121
+ setShow
122
+ };
123
+ };
124
+ export const CodeSandboxButton = _ref3 => {
125
+ let {
126
+ tooltip
127
+ } = _ref3,
128
+ props = _objectWithoutProperties(_ref3, _excluded);
129
+ const api = useCodeSandboxDrawer(_objectSpread(_objectSpread({}, props), {}, {
130
+ height: '90vh',
131
+ getContainer: () => ref.current
132
+ }));
87
133
  const ref = useRef();
88
134
  return /*#__PURE__*/React.createElement(DrawerContain, {
89
135
  ref: ref
@@ -102,32 +148,6 @@ export const CodeSandboxButton = _ref2 => {
102
148
  alignItems: 'center',
103
149
  justifyContent: 'center'
104
150
  },
105
- onClick: () => setShow(true)
106
- })), /*#__PURE__*/React.createElement(Drawer, {
107
- getContainer: () => ref.current,
108
- title: `${title}`,
109
- height: "90vh",
110
- contentWrapperStyle: {
111
- padding: 0
112
- },
113
- style: {
114
- padding: 0
115
- },
116
- placement: "bottom",
117
- destroyOnClose: true,
118
- open: show,
119
- onClose: () => {
120
- setShow(false);
121
- }
122
- }, /*#__PURE__*/React.createElement(CodeSandbox, {
123
- isZhLanguage: isZhLanguage,
124
- emptyText: emptyText,
125
- langKey: langKey,
126
- baseUri: baseUri,
127
- txpCode: txpCode,
128
- pageName: pageName,
129
- show: show,
130
- title: title,
131
- code: code
132
- })));
151
+ onClick: () => api.setShow(true)
152
+ })), api.modal);
133
153
  };
@@ -1,3 +1,3 @@
1
- import { CodeSandboxButton, CodeSandbox } from './codesandbox';
1
+ import { CodeSandboxButton, CodeSandbox, useCodeSandboxDrawer } from './codesandbox';
2
2
  export * from './codesandbox';
3
- export { CodeSandbox, CodeSandboxButton };
3
+ export { CodeSandbox, CodeSandboxButton, useCodeSandboxDrawer };
package/lib/txp/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { CodeSandboxButton, CodeSandbox } from './codesandbox';
1
+ import { CodeSandboxButton, CodeSandbox, useCodeSandboxDrawer } from './codesandbox';
2
2
  export * from './codesandbox';
3
- export { CodeSandbox, CodeSandboxButton };
3
+ export { CodeSandbox, CodeSandboxButton, useCodeSandboxDrawer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/code-sandbox",
3
- "version": "0.0.3-beta-4",
3
+ "version": "0.0.3-beta-6",
4
4
  "description": "小程序 CodeSandbox 容器",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -40,10 +40,9 @@
40
40
  "@commitlint/cli": "^7.2.1",
41
41
  "@commitlint/config-conventional": "^9.0.1",
42
42
  "@ray-js/cli": "^1.4.9",
43
+ "@ray-js/components-ty-loading": "^0.1.1",
43
44
  "@ray-js/ray": "^1.4.9",
44
- "@ray-js/smart-ui": "^1.2.0",
45
45
  "@saber2pr/monaco": "^0.0.90",
46
- "@tuya-miniapp/smart-ui": "^1.2.0",
47
46
  "antd": "^5.20.2",
48
47
  "axios": "^1.7.4",
49
48
  "core-js": "^3.19.1",