@ray-js/code-sandbox 0.0.3-beta-8 → 0.0.4-beta.1
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/lib/codesandbox/index.js +1 -1
- package/lib/decoder/index.d.ts +1 -0
- package/lib/decoder/index.js +3 -1
- package/lib/listener/index.d.ts +1 -0
- package/lib/listener/index.js +4 -1
- package/lib/listener/index.sjs +3 -2
- package/lib/listener/index.tyml +2 -2
- package/lib/loading/index.js +1 -1
- package/lib/loading/ray-loading/index.d.ts +4 -0
- package/lib/loading/ray-loading/index.js +32 -0
- package/lib/loading/ray-loading/index.module.less +17 -0
- package/lib/loading/ray-loading/props.d.ts +26 -0
- package/lib/loading/ray-loading/props.js +4 -0
- package/lib/txp/codesandbox/code-editor/index.d.ts +5 -1
- package/lib/txp/codesandbox/code-editor/index.js +67 -47
- package/lib/txp/codesandbox/index.d.ts +25 -5
- package/lib/txp/codesandbox/index.js +81 -14
- package/lib/txp/codesandbox/index.style.d.ts +3 -0
- package/lib/txp/codesandbox/index.style.js +20 -1
- package/lib/txp/codesandbox/postSandboxCode.d.ts +1 -0
- package/lib/txp/codesandbox/postSandboxCode.js +11 -0
- package/package.json +10 -11
package/lib/codesandbox/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const CodeSandbox = _ref => {
|
|
|
26
26
|
react: ReactLib
|
|
27
27
|
});
|
|
28
28
|
const [title, setTitle] = React.useState(defaultTitle);
|
|
29
|
-
const [content, setContent] = React.useState(
|
|
29
|
+
const [content, setContent] = React.useState(/*#__PURE__*/React.createElement(context.__loading__, null));
|
|
30
30
|
// @ts-ignore
|
|
31
31
|
context.___setContent___ = setContent;
|
|
32
32
|
// @ts-ignore
|
package/lib/decoder/index.d.ts
CHANGED
package/lib/decoder/index.js
CHANGED
|
@@ -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);
|
package/lib/listener/index.d.ts
CHANGED
package/lib/listener/index.js
CHANGED
package/lib/listener/index.sjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
init(newVal, oldVal, ownerInstance) {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
},
|
package/lib/listener/index.tyml
CHANGED
package/lib/loading/index.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-disable react/self-closing-comp */
|
|
2
|
+
/* eslint-disable react/no-unknown-property */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import styles from './index.module.less';
|
|
5
|
+
import { defaultProps } from './props';
|
|
6
|
+
import { View } from '@ray-js/ray';
|
|
7
|
+
function createSvgIcon(svg) {
|
|
8
|
+
return `data:image/svg+xml,${encodeURIComponent(`${svg}`)}`;
|
|
9
|
+
}
|
|
10
|
+
function CircularLoading(_ref) {
|
|
11
|
+
let {
|
|
12
|
+
color = '#1989FA'
|
|
13
|
+
} = _ref;
|
|
14
|
+
return createSvgIcon(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="none" version="1.1" width="32" height="32" viewBox="0 0 32 32"><defs><clipPath id="master_svg0_1695_29273"><rect x="0" y="0" width="32" height="32" rx="0"/></clipPath></defs><g clip-path="url(#master_svg0_1695_29273)"><g><path d="M14.73077392578125,8.807690000000001L14.73077392578125,6.26923C14.73077392578125,5.568254,15.29902692578125,5,16.00000392578125,5C16.70097392578125,5,17.26923392578125,5.568254,17.26923392578125,6.26923L17.26923392578125,8.807690000000001C17.26923392578125,9.50867,16.70097392578125,10.07693,16.00000392578125,10.07693C15.29902692578125,10.07693,14.73077392578125,9.50867,14.73077392578125,8.807690000000001Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(0.7071067690849304,0.7071067690849304,-0.7071067690849304,0.7071067690849304,11.880707750418878,-14.033822285849965)" style="opacity:0.05000000074505806;"><path d="M22.88067626953125,11.132061337890626L22.88067626953125,8.593601337890625C22.88067626953125,7.892624337890625,23.44892926953125,7.324371337890625,24.14990626953125,7.324371337890625C24.85088626953125,7.324371337890625,25.41913626953125,7.892624337890625,25.41913626953125,8.593601337890625L25.41913626953125,11.132061337890626C25.41913626953125,11.833041337890625,24.85088626953125,12.401291337890626,24.14990626953125,12.401291337890626C23.44892926953125,12.401291337890626,22.88067626953125,11.833041337890625,22.88067626953125,11.132061337890626Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(0,1,-1,0,41.73081970214844,-12.269180297851562)" style="opacity:0.10000000149011612;"><path d="M27,18.53850970214844L27,16.000049702148438C27,15.299072702148438,27.568253,14.730819702148438,28.26923,14.730819702148438C28.97021,14.730819702148438,29.53846,15.299072702148438,29.53846,16.000049702148438L29.53846,18.53850970214844C29.53846,19.23948970214844,28.97021,19.80773970214844,28.26923,19.80773970214844C27.568253,19.80773970214844,27,19.23948970214844,27,18.53850970214844Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(-0.7071067690849304,0.7071067690849304,-0.7071067690849304,-0.7071067690849304,58.30294381839121,21.611726407169044)" style="opacity:0.15000000596046448;"><path d="M24.675537109375,26.68848833984375L24.675537109375,24.15002833984375C24.675537109375,23.44905133984375,25.243790109375,22.88079833984375,25.944767109375,22.88079833984375C26.645747109375,22.88079833984375,27.213997109375,23.44905133984375,27.213997109375,24.15002833984375L27.213997109375,26.68848833984375C27.213997109375,27.389468339843752,26.645747109375,27.95771833984375,25.944767109375,27.95771833984375C25.243790109375,27.95771833984375,24.675537109375,27.389468339843752,24.675537109375,26.68848833984375Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(-1,0,0,-1,34.5384521484375,54)" style="opacity:0.30000001192092896;"><path d="M17.26922607421875,30.80769L17.26922607421875,28.26923C17.26922607421875,27.568254,17.83747907421875,27,18.53845607421875,27C19.23942607421875,27,19.80768607421875,27.568254,19.80768607421875,28.26923L19.80768607421875,30.80769C19.80768607421875,31.508670000000002,19.23942607421875,32.07693,18.53845607421875,32.07693C17.83747907421875,32.07693,17.26922607421875,31.508670000000002,17.26922607421875,30.80769Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(-0.7071068286895752,-0.7071067094802856,0.7071067094802856,-0.7071068286895752,-1.8805817391439632,48.572416538932885)" style="opacity:0.550000011920929;"><path d="M9.119384765625,28.483379697265626L9.119384765625,25.944919697265625C9.119384765625,25.243942697265624,9.687637765625,24.675689697265625,10.388614765625,24.675689697265625C11.089594765625,24.675689697265625,11.657844765625,25.243942697265624,11.657844765625,25.944919697265625L11.657844765625,28.483379697265626C11.657844765625,29.184359697265627,11.089594765625,29.752609697265626,10.388614765625,29.752609697265626C9.687637765625,29.752609697265626,9.119384765625,29.184359697265627,9.119384765625,28.483379697265626Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(0,-1,1,0,-12.269241333007812,22.269241333007812)" style="opacity:0.699999988079071;"><path d="M5,21.076931333007813L5,18.538471333007813C5,17.83749433300781,5.568253,17.269241333007812,6.26923,17.269241333007812C6.97021,17.269241333007812,7.538460000000001,17.83749433300781,7.538460000000001,18.538471333007813L7.538460000000001,21.076931333007813C7.538460000000001,21.777911333007815,6.97021,22.346161333007814,6.26923,22.346161333007814C5.568253,22.346161333007814,5,21.777911333007815,5,21.076931333007813Z" fill="#3678E3" fill-opacity="1"/></g><g transform="matrix(0.7071066498756409,-0.70710688829422,0.70710688829422,0.7071066498756409,-4.303046450104375,7.850115344526785)" style="opacity:0.8500000238418579;"><path d="M7.32440185546875,12.926983212890626L7.32440185546875,10.388523212890625C7.32440185546875,9.687546212890625,7.89265485546875,9.119293212890625,8.59363185546875,9.119293212890625C9.29461185546875,9.119293212890625,9.86286185546875,9.687546212890625,9.86286185546875,10.388523212890625L9.86286185546875,12.926983212890626C9.86286185546875,13.627963212890625,9.29461185546875,14.196213212890626,8.59363185546875,14.196213212890626C7.89265485546875,14.196213212890626,7.32440185546875,13.627963212890625,7.32440185546875,12.926983212890626Z" fill="#3678E3" fill-opacity="1"/></g></g></svg>`);
|
|
15
|
+
}
|
|
16
|
+
const Loading = props => {
|
|
17
|
+
const icon = CircularLoading({
|
|
18
|
+
color: '#1989FA'
|
|
19
|
+
});
|
|
20
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
21
|
+
className: styles.loading,
|
|
22
|
+
style: {
|
|
23
|
+
backgroundImage: `url('${icon}')`,
|
|
24
|
+
backgroundSize: `${props.size} ${props.size}`,
|
|
25
|
+
width: props.size,
|
|
26
|
+
height: props.size
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Loading.displayName = 'Loading';
|
|
31
|
+
Loading.defaultProps = defaultProps;
|
|
32
|
+
export default Loading;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
@keyframes animation-rotate {
|
|
2
|
+
0% {
|
|
3
|
+
transform: rotate(0deg);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
100% {
|
|
7
|
+
transform: rotate(360deg);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.loading {
|
|
12
|
+
animation-duration: 0.5s;
|
|
13
|
+
animation-delay: 0s;
|
|
14
|
+
animation-name: animation-rotate;
|
|
15
|
+
animation-timing-function: steps(8);
|
|
16
|
+
animation-iteration-count: infinite;
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface IProps {
|
|
3
|
+
/**
|
|
4
|
+
* @description.zh 类名
|
|
5
|
+
* @description.en class name
|
|
6
|
+
*/
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* @description.zh 样式
|
|
10
|
+
* @description.en Style
|
|
11
|
+
*/
|
|
12
|
+
style?: React.CSSProperties;
|
|
13
|
+
/**
|
|
14
|
+
* @description.zh 颜色
|
|
15
|
+
* @description.en Color
|
|
16
|
+
* @default '#000000'
|
|
17
|
+
*/
|
|
18
|
+
color?: string;
|
|
19
|
+
/**
|
|
20
|
+
* @description.zh 加载图标大小
|
|
21
|
+
* @description.en Size of loading icon
|
|
22
|
+
* @default '60rpx'
|
|
23
|
+
*/
|
|
24
|
+
size?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const defaultProps: IProps;
|
|
@@ -4,10 +4,14 @@ export interface CodeEditorProps {
|
|
|
4
4
|
onChange(code: string): void;
|
|
5
5
|
title: string;
|
|
6
6
|
show: boolean;
|
|
7
|
-
height
|
|
7
|
+
height?: string;
|
|
8
8
|
txpCode: string;
|
|
9
9
|
baseUri: string;
|
|
10
10
|
isZhLanguage: boolean;
|
|
11
|
+
style?: React.CSSProperties;
|
|
12
|
+
fileName?: string;
|
|
13
|
+
cssParse?: (css: string) => Promise<string>;
|
|
14
|
+
noTypeInit?: boolean;
|
|
11
15
|
}
|
|
12
16
|
export declare const CodeEditor: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<{
|
|
13
17
|
monaco: typeof import("monaco-editor");
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
/* eslint-disable no-await-in-loop */
|
|
3
|
+
import { Skeleton } from 'antd';
|
|
2
4
|
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
3
5
|
import { getComponentResource } from '../../services';
|
|
4
6
|
import { Editor } from '@saber2pr/monaco';
|
|
@@ -15,7 +17,11 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
15
17
|
height,
|
|
16
18
|
txpCode,
|
|
17
19
|
baseUri,
|
|
18
|
-
isZhLanguage = true
|
|
20
|
+
isZhLanguage = true,
|
|
21
|
+
style,
|
|
22
|
+
fileName = 'main.tsx',
|
|
23
|
+
cssParse,
|
|
24
|
+
noTypeInit = false
|
|
19
25
|
} = _ref;
|
|
20
26
|
const [initloading, setInitLoading] = useState(true);
|
|
21
27
|
const ref = useRef();
|
|
@@ -23,8 +29,13 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
23
29
|
ref.current = editor;
|
|
24
30
|
editor.setValue(`${code}`);
|
|
25
31
|
editor.getModel().onDidChangeContent(async () => {
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
if (/\.(tsx|ts|jsx|js)$/.test(fileName)) {
|
|
33
|
+
const result = await editor.compileTS();
|
|
34
|
+
onChange(result.output);
|
|
35
|
+
} else {
|
|
36
|
+
const cssCode = editor.getValue(fileName);
|
|
37
|
+
onChange(cssParse ? await cssParse(cssCode) : cssCode);
|
|
38
|
+
}
|
|
28
39
|
});
|
|
29
40
|
const addTypeLib = async (name, wrapName) => {
|
|
30
41
|
try {
|
|
@@ -35,29 +46,30 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
35
46
|
editor.addExtraLib(smartUiTypes, name);
|
|
36
47
|
} catch (error) {}
|
|
37
48
|
};
|
|
49
|
+
if (!noTypeInit) {
|
|
50
|
+
// react
|
|
51
|
+
await addTypeLib('react.d.ts');
|
|
52
|
+
// @ray-js/smartui
|
|
53
|
+
await addTypeLib('smartui.d.ts');
|
|
54
|
+
// @ray-js/ray
|
|
55
|
+
await addTypeLib('ray.d.ts');
|
|
56
|
+
// csstypes
|
|
57
|
+
await addTypeLib('csstype.d.ts', 'csstype');
|
|
58
|
+
// prop-types
|
|
59
|
+
await addTypeLib('prop-types.d.ts', 'prop-types');
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
// prop-types
|
|
48
|
-
await addTypeLib('prop-types.d.ts', 'prop-types');
|
|
49
|
-
|
|
50
|
-
// BaseKit Kit types
|
|
51
|
-
await addTypeLib('BaseKit.d.ts');
|
|
52
|
-
// BizKit Kit types
|
|
53
|
-
await addTypeLib('BizKit.d.ts');
|
|
54
|
-
// Device Kit types
|
|
55
|
-
await addTypeLib('DeviceKit.d.ts');
|
|
56
|
-
// MiniKit Kit types
|
|
57
|
-
await addTypeLib('MiniKit.d.ts');
|
|
61
|
+
// BaseKit Kit types
|
|
62
|
+
await addTypeLib('BaseKit.d.ts');
|
|
63
|
+
// BizKit Kit types
|
|
64
|
+
await addTypeLib('BizKit.d.ts');
|
|
65
|
+
// Device Kit types
|
|
66
|
+
await addTypeLib('DeviceKit.d.ts');
|
|
67
|
+
// MiniKit Kit types
|
|
68
|
+
await addTypeLib('MiniKit.d.ts');
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
// rayKit
|
|
71
|
+
await addTypeLib('rayKit.d.ts');
|
|
72
|
+
}
|
|
61
73
|
};
|
|
62
74
|
useEffect(() => {
|
|
63
75
|
const handle = async event => {
|
|
@@ -80,8 +92,13 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
80
92
|
await timeout(500);
|
|
81
93
|
}
|
|
82
94
|
if (editor) {
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
if (/\.(tsx|ts|jsx|js)$/.test(fileName)) {
|
|
96
|
+
const result = await editor.compileTS();
|
|
97
|
+
onChange(result.output);
|
|
98
|
+
} else {
|
|
99
|
+
const cssCode = editor.getValue(fileName);
|
|
100
|
+
onChange(cssParse ? await cssParse(cssCode) : cssCode);
|
|
101
|
+
}
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
};
|
|
@@ -89,24 +106,18 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
89
106
|
return () => {
|
|
90
107
|
window.removeEventListener('message', handle);
|
|
91
108
|
};
|
|
92
|
-
}, [show]);
|
|
109
|
+
}, [show, fileName]);
|
|
93
110
|
useEffect(() => {
|
|
94
|
-
|
|
111
|
+
return () => {
|
|
95
112
|
const api = ref.current;
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
model.dispose();
|
|
101
|
-
}
|
|
113
|
+
if (api) {
|
|
114
|
+
const model = api.getModel();
|
|
115
|
+
if (model) {
|
|
116
|
+
model.dispose();
|
|
102
117
|
}
|
|
103
118
|
}
|
|
104
119
|
};
|
|
105
|
-
|
|
106
|
-
return () => {
|
|
107
|
-
destroyOnClose();
|
|
108
|
-
};
|
|
109
|
-
}, [show]);
|
|
120
|
+
}, []);
|
|
110
121
|
useImperativeHandle(parentRef, () => ref.current);
|
|
111
122
|
const loaderConfig = {
|
|
112
123
|
paths: {
|
|
@@ -121,14 +132,12 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
121
132
|
}
|
|
122
133
|
};
|
|
123
134
|
}
|
|
124
|
-
return /*#__PURE__*/React.createElement(
|
|
125
|
-
spinning: initloading
|
|
126
|
-
}, code && /*#__PURE__*/React.createElement(Editor, {
|
|
135
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, code && /*#__PURE__*/React.createElement(Editor, {
|
|
127
136
|
loaderConfig: loaderConfig,
|
|
128
137
|
theme: "monokai-bright",
|
|
129
|
-
style: {
|
|
138
|
+
style: _objectSpread(_objectSpread({}, style || {}), {}, {
|
|
130
139
|
height
|
|
131
|
-
},
|
|
140
|
+
}),
|
|
132
141
|
options: {
|
|
133
142
|
minimap: {
|
|
134
143
|
enabled: false
|
|
@@ -137,7 +146,7 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
137
146
|
},
|
|
138
147
|
deps: [title, code],
|
|
139
148
|
modalFiles: {
|
|
140
|
-
|
|
149
|
+
[fileName]: ''
|
|
141
150
|
},
|
|
142
151
|
tsconfig: {
|
|
143
152
|
strict: false,
|
|
@@ -152,5 +161,16 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
152
161
|
initMonaco(editor);
|
|
153
162
|
setInitLoading(false);
|
|
154
163
|
}
|
|
155
|
-
})
|
|
164
|
+
}), initloading && /*#__PURE__*/React.createElement("div", {
|
|
165
|
+
style: _objectSpread(_objectSpread({
|
|
166
|
+
position: 'absolute',
|
|
167
|
+
zIndex: 10
|
|
168
|
+
}, style || {}), {}, {
|
|
169
|
+
height
|
|
170
|
+
})
|
|
171
|
+
}, /*#__PURE__*/React.createElement(Skeleton, {
|
|
172
|
+
active: true,
|
|
173
|
+
title: true,
|
|
174
|
+
paragraph: true
|
|
175
|
+
})));
|
|
156
176
|
});
|
|
@@ -1,15 +1,21 @@
|
|
|
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;
|
|
6
7
|
show?: boolean;
|
|
7
8
|
txpCode: string;
|
|
8
|
-
pageName
|
|
9
|
+
pageName?: string;
|
|
9
10
|
baseUri: string;
|
|
10
11
|
langKey?: string;
|
|
11
12
|
emptyText?: string;
|
|
12
13
|
isZhLanguage?: boolean;
|
|
14
|
+
editorApi?: EditorAPI;
|
|
15
|
+
cssCode?: string;
|
|
16
|
+
styMap?: any;
|
|
17
|
+
cssParse?: (css: string) => Promise<string>;
|
|
18
|
+
noTypeInit?: boolean;
|
|
13
19
|
}
|
|
14
20
|
export declare const CodeSandbox: React.FC<CodeSandboxProps>;
|
|
15
21
|
export declare const checkShowCodeSandbox: (code: string) => boolean;
|
|
@@ -19,14 +25,20 @@ export interface UseCodeSandboxDrawerOps {
|
|
|
19
25
|
height?: string;
|
|
20
26
|
placement?: DrawerProps['placement'];
|
|
21
27
|
txpCode: string;
|
|
22
|
-
pageName
|
|
28
|
+
pageName?: string;
|
|
23
29
|
baseUri: string;
|
|
24
30
|
emptyText?: string;
|
|
25
31
|
isZhLanguage?: boolean;
|
|
26
32
|
code: string;
|
|
27
33
|
langKey?: string;
|
|
34
|
+
editorApi?: EditorAPI;
|
|
35
|
+
cssCode?: string;
|
|
36
|
+
styMap?: any;
|
|
37
|
+
cssParse?: (css: string) => Promise<string>;
|
|
38
|
+
noTypeInit?: boolean;
|
|
39
|
+
extra?: React.ReactNode;
|
|
28
40
|
}
|
|
29
|
-
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, }: UseCodeSandboxDrawerOps) => {
|
|
41
|
+
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, cssCode, styMap, cssParse, noTypeInit, extra, }: UseCodeSandboxDrawerOps) => {
|
|
30
42
|
modal: React.JSX.Element;
|
|
31
43
|
show: boolean;
|
|
32
44
|
setShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
@@ -37,8 +49,16 @@ export declare const CodeSandboxButton: React.FC<{
|
|
|
37
49
|
langKey?: string;
|
|
38
50
|
tooltip?: string;
|
|
39
51
|
txpCode: string;
|
|
40
|
-
pageName
|
|
52
|
+
pageName?: string;
|
|
41
53
|
baseUri: string;
|
|
42
54
|
emptyText?: string;
|
|
43
55
|
isZhLanguage?: boolean;
|
|
56
|
+
editorApi?: EditorAPI;
|
|
57
|
+
buttonProps?: ButtonProps;
|
|
58
|
+
cssCode?: string;
|
|
59
|
+
styMap?: any;
|
|
60
|
+
noTypeInit?: boolean;
|
|
61
|
+
cssParse?: (css: string) => Promise<string>;
|
|
62
|
+
drawerGetContainer?: DrawerProps['getContainer'];
|
|
63
|
+
extra?: React.ReactNode;
|
|
44
64
|
}>;
|
|
@@ -1,14 +1,16 @@
|
|
|
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", "extra", "drawerGetContainer"];
|
|
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';
|
|
7
9
|
import { CodeSandboxOutlined } from '@ant-design/icons';
|
|
8
10
|
import { Demo } from '../demo';
|
|
9
11
|
import { CodeEditor } from './code-editor';
|
|
10
|
-
import { Contain, Content, DrawerContain, Main, Right } from './index.style';
|
|
11
|
-
import { postSandboxCode } from './postSandboxCode';
|
|
12
|
+
import { Contain, Content, DrawerContain, Main, MainContent, MainHeader, MainHeaderItem, Right } from './index.style';
|
|
13
|
+
import { postSandboxCode, postSandboxStyleCode } from './postSandboxCode';
|
|
12
14
|
export const CodeSandbox = _ref => {
|
|
13
15
|
let {
|
|
14
16
|
txpCode,
|
|
@@ -19,11 +21,16 @@ export const CodeSandbox = _ref => {
|
|
|
19
21
|
baseUri,
|
|
20
22
|
langKey,
|
|
21
23
|
emptyText,
|
|
22
|
-
isZhLanguage
|
|
24
|
+
isZhLanguage,
|
|
25
|
+
editorApi,
|
|
26
|
+
cssCode,
|
|
27
|
+
styMap,
|
|
28
|
+
cssParse,
|
|
29
|
+
noTypeInit
|
|
23
30
|
} = _ref;
|
|
24
31
|
const iframeRef = useRef();
|
|
25
32
|
const [ts, setTs] = useState(Date.now());
|
|
26
|
-
const apiRef = useRef();
|
|
33
|
+
const apiRef = useRef(editorApi);
|
|
27
34
|
useEffect(() => {
|
|
28
35
|
const handle = event => {
|
|
29
36
|
var _event$data;
|
|
@@ -42,19 +49,63 @@ export const CodeSandbox = _ref => {
|
|
|
42
49
|
postSandboxCode(iframeRef.current, newCode, title);
|
|
43
50
|
}
|
|
44
51
|
}, 500), [show]);
|
|
45
|
-
|
|
52
|
+
const postStyleCode = useCallback(_.debounce(newCode => {
|
|
53
|
+
if (iframeRef.current && styMap) {
|
|
54
|
+
postSandboxStyleCode(iframeRef.current, newCode, styMap);
|
|
55
|
+
}
|
|
56
|
+
}, 500), [show, styMap]);
|
|
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,
|
|
59
|
+
isZhLanguage: isZhLanguage,
|
|
60
|
+
baseUri: baseUri,
|
|
61
|
+
txpCode: txpCode,
|
|
62
|
+
style: {
|
|
63
|
+
width: '50%'
|
|
64
|
+
},
|
|
65
|
+
show: show,
|
|
66
|
+
title: title,
|
|
67
|
+
fileName: `${txpCode || 'main'}.less`,
|
|
68
|
+
code: cssCode,
|
|
69
|
+
onChange: newCode => {
|
|
70
|
+
postStyleCode(newCode);
|
|
71
|
+
},
|
|
72
|
+
cssParse: cssParse
|
|
73
|
+
}), /*#__PURE__*/React.createElement(CodeEditor, {
|
|
74
|
+
noTypeInit: noTypeInit,
|
|
75
|
+
isZhLanguage: isZhLanguage,
|
|
76
|
+
baseUri: baseUri,
|
|
77
|
+
txpCode: txpCode,
|
|
78
|
+
fileName: `${txpCode || 'main'}.tsx`,
|
|
79
|
+
style: {
|
|
80
|
+
width: '50%'
|
|
81
|
+
},
|
|
82
|
+
ref: apiRef,
|
|
83
|
+
show: show,
|
|
84
|
+
title: title,
|
|
85
|
+
code: code,
|
|
86
|
+
onChange: newCode => {
|
|
87
|
+
postCode(newCode);
|
|
88
|
+
}
|
|
89
|
+
}))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MainHeader, null, /*#__PURE__*/React.createElement(MainHeaderItem, {
|
|
90
|
+
style: {
|
|
91
|
+
width: '100%'
|
|
92
|
+
}
|
|
93
|
+
}, "Js Code")), /*#__PURE__*/React.createElement(MainContent, null, /*#__PURE__*/React.createElement(CodeEditor, {
|
|
46
94
|
isZhLanguage: isZhLanguage,
|
|
47
95
|
baseUri: baseUri,
|
|
96
|
+
noTypeInit: noTypeInit,
|
|
48
97
|
txpCode: txpCode,
|
|
49
|
-
height: `calc(90vh - 103px + 48px)`,
|
|
50
98
|
ref: apiRef,
|
|
51
99
|
show: show,
|
|
100
|
+
style: {
|
|
101
|
+
width: '100%'
|
|
102
|
+
},
|
|
52
103
|
title: title,
|
|
53
104
|
code: code,
|
|
54
105
|
onChange: newCode => {
|
|
55
106
|
postCode(newCode);
|
|
56
107
|
}
|
|
57
|
-
})), /*#__PURE__*/React.createElement(Right, null, /*#__PURE__*/React.createElement(Demo, {
|
|
108
|
+
})))), pageName && /*#__PURE__*/React.createElement(Right, null, /*#__PURE__*/React.createElement(Demo, {
|
|
58
109
|
emptyText: emptyText,
|
|
59
110
|
langKey: langKey,
|
|
60
111
|
baseUri: baseUri,
|
|
@@ -86,7 +137,13 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
86
137
|
emptyText,
|
|
87
138
|
langKey,
|
|
88
139
|
baseUri,
|
|
89
|
-
code
|
|
140
|
+
code,
|
|
141
|
+
editorApi,
|
|
142
|
+
cssCode,
|
|
143
|
+
styMap,
|
|
144
|
+
cssParse,
|
|
145
|
+
noTypeInit,
|
|
146
|
+
extra
|
|
90
147
|
} = _ref2;
|
|
91
148
|
const [show, setShow] = useState(false);
|
|
92
149
|
return {
|
|
@@ -100,6 +157,7 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
100
157
|
style: {
|
|
101
158
|
padding: 0
|
|
102
159
|
},
|
|
160
|
+
extra: extra,
|
|
103
161
|
placement: placement,
|
|
104
162
|
destroyOnClose: true,
|
|
105
163
|
open: show,
|
|
@@ -107,6 +165,8 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
107
165
|
setShow(false);
|
|
108
166
|
}
|
|
109
167
|
}, /*#__PURE__*/React.createElement(CodeSandbox, {
|
|
168
|
+
noTypeInit: noTypeInit,
|
|
169
|
+
editorApi: editorApi,
|
|
110
170
|
isZhLanguage: isZhLanguage,
|
|
111
171
|
emptyText: emptyText,
|
|
112
172
|
langKey: langKey,
|
|
@@ -115,7 +175,10 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
115
175
|
pageName: pageName,
|
|
116
176
|
show: show,
|
|
117
177
|
title: title,
|
|
118
|
-
code: code
|
|
178
|
+
code: code,
|
|
179
|
+
styMap: styMap,
|
|
180
|
+
cssCode: cssCode,
|
|
181
|
+
cssParse: cssParse
|
|
119
182
|
})),
|
|
120
183
|
show,
|
|
121
184
|
setShow
|
|
@@ -123,19 +186,23 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
123
186
|
};
|
|
124
187
|
export const CodeSandboxButton = _ref3 => {
|
|
125
188
|
let {
|
|
126
|
-
tooltip
|
|
189
|
+
tooltip,
|
|
190
|
+
buttonProps,
|
|
191
|
+
extra,
|
|
192
|
+
drawerGetContainer
|
|
127
193
|
} = _ref3,
|
|
128
194
|
props = _objectWithoutProperties(_ref3, _excluded);
|
|
129
195
|
const api = useCodeSandboxDrawer(_objectSpread(_objectSpread({}, props), {}, {
|
|
130
196
|
height: '90vh',
|
|
131
|
-
getContainer: () => ref.current
|
|
197
|
+
getContainer: drawerGetContainer || (() => ref.current),
|
|
198
|
+
extra
|
|
132
199
|
}));
|
|
133
200
|
const ref = useRef();
|
|
134
201
|
return /*#__PURE__*/React.createElement(DrawerContain, {
|
|
135
202
|
ref: ref
|
|
136
203
|
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
137
204
|
title: tooltip
|
|
138
|
-
}, /*#__PURE__*/React.createElement(Button, {
|
|
205
|
+
}, /*#__PURE__*/React.createElement(Button, _extends({
|
|
139
206
|
type: "link",
|
|
140
207
|
icon: /*#__PURE__*/React.createElement(CodeSandboxOutlined, {
|
|
141
208
|
style: {
|
|
@@ -149,5 +216,5 @@ export const CodeSandboxButton = _ref3 => {
|
|
|
149
216
|
justifyContent: 'center'
|
|
150
217
|
},
|
|
151
218
|
onClick: () => api.setShow(true)
|
|
152
|
-
})), api.modal);
|
|
219
|
+
}, buttonProps || {}))), api.modal);
|
|
153
220
|
};
|
|
@@ -3,5 +3,8 @@ export declare const Contain: import("styled-components/dist/types").IStyledComp
|
|
|
3
3
|
export declare const Bottom: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
4
4
|
export declare const Content: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
5
5
|
export declare const Main: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
6
|
+
export declare const MainHeader: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
7
|
+
export declare const MainHeaderItem: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
8
|
+
export declare const MainContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
6
9
|
export declare const Right: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
7
10
|
export declare const DrawerContain: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
@@ -14,6 +14,25 @@ export const Content = styled.div`
|
|
|
14
14
|
`;
|
|
15
15
|
export const Main = styled.div`
|
|
16
16
|
flex-grow: 1;
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
min-width: 0;
|
|
20
|
+
`;
|
|
21
|
+
export const MainHeader = styled.div`
|
|
22
|
+
display: flex;
|
|
23
|
+
border-bottom: 1px solid #0078d4;
|
|
24
|
+
`;
|
|
25
|
+
export const MainHeaderItem = styled.div`
|
|
26
|
+
background-color: #1f1f1f;
|
|
27
|
+
font-size: 16px;
|
|
28
|
+
font-weight: bold;
|
|
29
|
+
width: 50%;
|
|
30
|
+
color: #e2e2e2;
|
|
31
|
+
padding: 0 28px;
|
|
32
|
+
`;
|
|
33
|
+
export const MainContent = styled.div`
|
|
34
|
+
display: flex;
|
|
35
|
+
flex: 1;
|
|
17
36
|
`;
|
|
18
37
|
export const Right = styled.div`
|
|
19
38
|
display: flex;
|
|
@@ -23,6 +42,6 @@ export const Right = styled.div`
|
|
|
23
42
|
`;
|
|
24
43
|
export const DrawerContain = styled.div`
|
|
25
44
|
.ant-drawer-body {
|
|
26
|
-
padding:
|
|
45
|
+
padding: 20;
|
|
27
46
|
}
|
|
28
47
|
`;
|
|
@@ -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.4-beta.1",
|
|
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": "
|
|
20
|
+
"build": "export BROWSERSLIST='Last 3 versions' && 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",
|
|
@@ -27,8 +27,8 @@
|
|
|
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
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"release-it": "standard-version",
|
|
31
|
+
"prepublishOnly": "yarn build"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@ray-js/ray": "^1.4.9"
|
|
@@ -37,15 +37,17 @@
|
|
|
37
37
|
"clsx": "^1.2.1",
|
|
38
38
|
"js-base64": "^3.7.7"
|
|
39
39
|
},
|
|
40
|
+
"resolutions": {
|
|
41
|
+
"axios": "1.13.5"
|
|
42
|
+
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@commitlint/cli": "^7.2.1",
|
|
42
45
|
"@commitlint/config-conventional": "^9.0.1",
|
|
43
|
-
"@ray-js/cli": "^1.
|
|
44
|
-
"@ray-js/
|
|
45
|
-
"@ray-js/ray": "^1.4.9",
|
|
46
|
+
"@ray-js/cli": "^1.5.45",
|
|
47
|
+
"@ray-js/ray": "^1.5.45",
|
|
46
48
|
"@saber2pr/monaco": "^0.0.90",
|
|
47
49
|
"antd": "^5.20.2",
|
|
48
|
-
"axios": "^1.
|
|
50
|
+
"axios": "^1.13.5",
|
|
49
51
|
"core-js": "^3.19.1",
|
|
50
52
|
"eslint-config-tuya-panel": "^0.4.2",
|
|
51
53
|
"husky": "^1.2.0",
|
|
@@ -55,9 +57,6 @@
|
|
|
55
57
|
"standard-version": "9.3.2",
|
|
56
58
|
"styled-components": "^6.1.12"
|
|
57
59
|
},
|
|
58
|
-
"resolutions": {
|
|
59
|
-
"@ray-js/builder-mp": "1.4.15"
|
|
60
|
-
},
|
|
61
60
|
"husky": {
|
|
62
61
|
"hooks": {
|
|
63
62
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS --config commitlint.config.js",
|