@ray-js/code-sandbox 0.0.6 → 0.0.7-beta-2
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,4 +1,4 @@
|
|
|
1
|
-
import { DrawerProps } from 'antd';
|
|
1
|
+
import { ButtonProps, DrawerProps } from 'antd';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { EditorAPI } from '@saber2pr/monaco';
|
|
4
4
|
export interface CodeSandboxProps {
|
|
@@ -12,6 +12,8 @@ export interface CodeSandboxProps {
|
|
|
12
12
|
emptyText?: string;
|
|
13
13
|
isZhLanguage?: boolean;
|
|
14
14
|
editorApi?: EditorAPI;
|
|
15
|
+
cssCode?: string;
|
|
16
|
+
styMap?: any;
|
|
15
17
|
}
|
|
16
18
|
export declare const CodeSandbox: React.FC<CodeSandboxProps>;
|
|
17
19
|
export declare const checkShowCodeSandbox: (code: string) => boolean;
|
|
@@ -28,8 +30,10 @@ export interface UseCodeSandboxDrawerOps {
|
|
|
28
30
|
code: string;
|
|
29
31
|
langKey?: string;
|
|
30
32
|
editorApi?: EditorAPI;
|
|
33
|
+
cssCode?: string;
|
|
34
|
+
styMap?: any;
|
|
31
35
|
}
|
|
32
|
-
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, }: UseCodeSandboxDrawerOps) => {
|
|
36
|
+
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, cssCode, styMap, }: UseCodeSandboxDrawerOps) => {
|
|
33
37
|
modal: React.JSX.Element;
|
|
34
38
|
show: boolean;
|
|
35
39
|
setShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
@@ -45,4 +49,5 @@ export declare const CodeSandboxButton: React.FC<{
|
|
|
45
49
|
emptyText?: string;
|
|
46
50
|
isZhLanguage?: boolean;
|
|
47
51
|
editorApi?: EditorAPI;
|
|
52
|
+
buttonProps?: ButtonProps;
|
|
48
53
|
}>;
|
|
@@ -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';
|
|
@@ -8,7 +10,7 @@ import { CodeSandboxOutlined } from '@ant-design/icons';
|
|
|
8
10
|
import { Demo } from '../demo';
|
|
9
11
|
import { CodeEditor } from './code-editor';
|
|
10
12
|
import { Contain, Content, DrawerContain, Main, Right } from './index.style';
|
|
11
|
-
import { postSandboxCode } from './postSandboxCode';
|
|
13
|
+
import { postSandboxCode, postSandboxStyleCode } from './postSandboxCode';
|
|
12
14
|
export const CodeSandbox = _ref => {
|
|
13
15
|
let {
|
|
14
16
|
txpCode,
|
|
@@ -20,7 +22,9 @@ export const CodeSandbox = _ref => {
|
|
|
20
22
|
langKey,
|
|
21
23
|
emptyText,
|
|
22
24
|
isZhLanguage,
|
|
23
|
-
editorApi
|
|
25
|
+
editorApi,
|
|
26
|
+
cssCode,
|
|
27
|
+
styMap
|
|
24
28
|
} = _ref;
|
|
25
29
|
const iframeRef = useRef();
|
|
26
30
|
const [ts, setTs] = useState(Date.now());
|
|
@@ -43,7 +47,23 @@ export const CodeSandbox = _ref => {
|
|
|
43
47
|
postSandboxCode(iframeRef.current, newCode, title);
|
|
44
48
|
}
|
|
45
49
|
}, 500), [show]);
|
|
46
|
-
|
|
50
|
+
const postStyleCode = useCallback(_.debounce(newCode => {
|
|
51
|
+
if (iframeRef.current && styMap) {
|
|
52
|
+
postSandboxStyleCode(iframeRef.current, newCode, styMap);
|
|
53
|
+
}
|
|
54
|
+
}, 500), [show, styMap]);
|
|
55
|
+
return /*#__PURE__*/React.createElement(Contain, null, /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(Main, null, styMap && /*#__PURE__*/React.createElement(CodeEditor, {
|
|
56
|
+
isZhLanguage: isZhLanguage,
|
|
57
|
+
baseUri: baseUri,
|
|
58
|
+
txpCode: cssCode,
|
|
59
|
+
height: `calc(90vh - 103px + 48px)`,
|
|
60
|
+
show: show,
|
|
61
|
+
title: title,
|
|
62
|
+
code: code,
|
|
63
|
+
onChange: newCode => {
|
|
64
|
+
postStyleCode(newCode);
|
|
65
|
+
}
|
|
66
|
+
}), /*#__PURE__*/React.createElement(CodeEditor, {
|
|
47
67
|
isZhLanguage: isZhLanguage,
|
|
48
68
|
baseUri: baseUri,
|
|
49
69
|
txpCode: txpCode,
|
|
@@ -88,7 +108,9 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
88
108
|
langKey,
|
|
89
109
|
baseUri,
|
|
90
110
|
code,
|
|
91
|
-
editorApi
|
|
111
|
+
editorApi,
|
|
112
|
+
cssCode,
|
|
113
|
+
styMap
|
|
92
114
|
} = _ref2;
|
|
93
115
|
const [show, setShow] = useState(false);
|
|
94
116
|
return {
|
|
@@ -118,7 +140,9 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
118
140
|
pageName: pageName,
|
|
119
141
|
show: show,
|
|
120
142
|
title: title,
|
|
121
|
-
code: code
|
|
143
|
+
code: code,
|
|
144
|
+
styMap: styMap,
|
|
145
|
+
cssCode: cssCode
|
|
122
146
|
})),
|
|
123
147
|
show,
|
|
124
148
|
setShow
|
|
@@ -126,7 +150,8 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
126
150
|
};
|
|
127
151
|
export const CodeSandboxButton = _ref3 => {
|
|
128
152
|
let {
|
|
129
|
-
tooltip
|
|
153
|
+
tooltip,
|
|
154
|
+
buttonProps
|
|
130
155
|
} = _ref3,
|
|
131
156
|
props = _objectWithoutProperties(_ref3, _excluded);
|
|
132
157
|
const api = useCodeSandboxDrawer(_objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -138,7 +163,7 @@ export const CodeSandboxButton = _ref3 => {
|
|
|
138
163
|
ref: ref
|
|
139
164
|
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
140
165
|
title: tooltip
|
|
141
|
-
}, /*#__PURE__*/React.createElement(Button, {
|
|
166
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
142
167
|
type: "link",
|
|
143
168
|
icon: /*#__PURE__*/React.createElement(CodeSandboxOutlined, {
|
|
144
169
|
style: {
|
|
@@ -152,5 +177,5 @@ export const CodeSandboxButton = _ref3 => {
|
|
|
152
177
|
justifyContent: 'center'
|
|
153
178
|
},
|
|
154
179
|
onClick: () => api.setShow(true)
|
|
155
|
-
})), api.modal);
|
|
180
|
+
}, buttonProps || {}))), api.modal);
|
|
156
181
|
};
|
|
@@ -38,4 +38,15 @@ export const postSandboxCode = (iframe, code, title) => {
|
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
};
|
|
42
|
+
export const postSandboxStyleCode = (iframe, code, styMap) => {
|
|
43
|
+
if (iframe) {
|
|
44
|
+
iframe.postMsg({
|
|
45
|
+
type: 'addStyle',
|
|
46
|
+
payload: {
|
|
47
|
+
code: Base64.encode(code),
|
|
48
|
+
styMap
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
41
52
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/code-sandbox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7-beta-2",
|
|
4
4
|
"description": "小程序 CodeSandbox 容器",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"files": [
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"start:tuya": "ray start ./example",
|
|
28
28
|
"start:wechat": "ray start ./example -t wechat --verbose",
|
|
29
29
|
"start:web": "ray start ./example -t web",
|
|
30
|
-
"prepublishOnly": "yarn build",
|
|
31
30
|
"release-it": "standard-version"
|
|
32
31
|
},
|
|
33
32
|
"peerDependencies": {
|
|
@@ -70,4 +69,4 @@
|
|
|
70
69
|
"git add"
|
|
71
70
|
]
|
|
72
71
|
}
|
|
73
|
-
}
|
|
72
|
+
}
|