@ray-js/code-sandbox 0.0.7-beta-4 → 0.0.7-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/lib/txp/codesandbox/code-editor/index.d.ts +2 -0
- package/lib/txp/codesandbox/code-editor/index.js +31 -15
- package/lib/txp/codesandbox/index.d.ts +4 -1
- package/lib/txp/codesandbox/index.js +27 -10
- package/lib/txp/codesandbox/index.style.d.ts +3 -0
- package/lib/txp/codesandbox/index.style.js +14 -0
- package/package.json +1 -1
|
@@ -9,6 +9,8 @@ export interface CodeEditorProps {
|
|
|
9
9
|
baseUri: string;
|
|
10
10
|
isZhLanguage: boolean;
|
|
11
11
|
style?: React.CSSProperties;
|
|
12
|
+
fileName?: string;
|
|
13
|
+
cssParse?: (css: string) => Promise<string>;
|
|
12
14
|
}
|
|
13
15
|
export declare const CodeEditor: React.ForwardRefExoticComponent<CodeEditorProps & React.RefAttributes<{
|
|
14
16
|
monaco: typeof import("monaco-editor");
|
|
@@ -17,7 +17,9 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
17
17
|
txpCode,
|
|
18
18
|
baseUri,
|
|
19
19
|
isZhLanguage = true,
|
|
20
|
-
style
|
|
20
|
+
style,
|
|
21
|
+
fileName = 'main.tsx',
|
|
22
|
+
cssParse
|
|
21
23
|
} = _ref;
|
|
22
24
|
const [initloading, setInitLoading] = useState(true);
|
|
23
25
|
const ref = useRef();
|
|
@@ -25,8 +27,13 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
25
27
|
ref.current = editor;
|
|
26
28
|
editor.setValue(`${code}`);
|
|
27
29
|
editor.getModel().onDidChangeContent(async () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
if (/\.(tsx|ts|jsx|js)$/.test(fileName)) {
|
|
31
|
+
const result = await editor.compileTS();
|
|
32
|
+
onChange(result.output);
|
|
33
|
+
} else {
|
|
34
|
+
const cssCode = editor.getValue(fileName);
|
|
35
|
+
onChange(cssParse ? await cssParse(cssCode) : cssCode);
|
|
36
|
+
}
|
|
30
37
|
});
|
|
31
38
|
const addTypeLib = async (name, wrapName) => {
|
|
32
39
|
try {
|
|
@@ -82,8 +89,13 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
82
89
|
await timeout(500);
|
|
83
90
|
}
|
|
84
91
|
if (editor) {
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
if (/\.(tsx|ts|jsx|js)$/.test(fileName)) {
|
|
93
|
+
const result = await editor.compileTS();
|
|
94
|
+
onChange(result.output);
|
|
95
|
+
} else {
|
|
96
|
+
const cssCode = editor.getValue(fileName);
|
|
97
|
+
onChange(cssParse ? await cssParse(cssCode) : cssCode);
|
|
98
|
+
}
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
101
|
};
|
|
@@ -91,7 +103,7 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
91
103
|
return () => {
|
|
92
104
|
window.removeEventListener('message', handle);
|
|
93
105
|
};
|
|
94
|
-
}, [show]);
|
|
106
|
+
}, [show, fileName]);
|
|
95
107
|
useEffect(() => {
|
|
96
108
|
const destroyOnClose = () => {
|
|
97
109
|
const api = ref.current;
|
|
@@ -123,13 +135,6 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
123
135
|
}
|
|
124
136
|
};
|
|
125
137
|
}
|
|
126
|
-
if (initloading) {
|
|
127
|
-
return /*#__PURE__*/React.createElement(Skeleton, {
|
|
128
|
-
active: true,
|
|
129
|
-
title: true,
|
|
130
|
-
paragraph: true
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
138
|
return /*#__PURE__*/React.createElement(React.Fragment, null, code && /*#__PURE__*/React.createElement(Editor, {
|
|
134
139
|
loaderConfig: loaderConfig,
|
|
135
140
|
theme: "monokai-bright",
|
|
@@ -144,7 +149,7 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
144
149
|
},
|
|
145
150
|
deps: [title, code],
|
|
146
151
|
modalFiles: {
|
|
147
|
-
|
|
152
|
+
[fileName]: ''
|
|
148
153
|
},
|
|
149
154
|
tsconfig: {
|
|
150
155
|
strict: false,
|
|
@@ -159,5 +164,16 @@ export const CodeEditor = /*#__PURE__*/React.forwardRef((_ref, parentRef) => {
|
|
|
159
164
|
initMonaco(editor);
|
|
160
165
|
setInitLoading(false);
|
|
161
166
|
}
|
|
162
|
-
})
|
|
167
|
+
}), initloading && /*#__PURE__*/React.createElement("div", {
|
|
168
|
+
style: _objectSpread(_objectSpread({
|
|
169
|
+
position: 'absolute',
|
|
170
|
+
zIndex: 10
|
|
171
|
+
}, style || {}), {}, {
|
|
172
|
+
height
|
|
173
|
+
})
|
|
174
|
+
}, /*#__PURE__*/React.createElement(Skeleton, {
|
|
175
|
+
active: true,
|
|
176
|
+
title: true,
|
|
177
|
+
paragraph: true
|
|
178
|
+
})));
|
|
163
179
|
});
|
|
@@ -14,6 +14,7 @@ export interface CodeSandboxProps {
|
|
|
14
14
|
editorApi?: EditorAPI;
|
|
15
15
|
cssCode?: string;
|
|
16
16
|
styMap?: any;
|
|
17
|
+
cssParse?: (css: string) => Promise<string>;
|
|
17
18
|
}
|
|
18
19
|
export declare const CodeSandbox: React.FC<CodeSandboxProps>;
|
|
19
20
|
export declare const checkShowCodeSandbox: (code: string) => boolean;
|
|
@@ -32,8 +33,10 @@ export interface UseCodeSandboxDrawerOps {
|
|
|
32
33
|
editorApi?: EditorAPI;
|
|
33
34
|
cssCode?: string;
|
|
34
35
|
styMap?: any;
|
|
36
|
+
fileName?: string;
|
|
37
|
+
cssParse?: (css: string) => Promise<string>;
|
|
35
38
|
}
|
|
36
|
-
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, cssCode, styMap, }: UseCodeSandboxDrawerOps) => {
|
|
39
|
+
export declare const useCodeSandboxDrawer: ({ getContainer, title, height, placement, isZhLanguage, pageName, txpCode, emptyText, langKey, baseUri, code, editorApi, cssCode, styMap, cssParse, }: UseCodeSandboxDrawerOps) => {
|
|
37
40
|
modal: React.JSX.Element;
|
|
38
41
|
show: boolean;
|
|
39
42
|
setShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
@@ -9,7 +9,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
9
9
|
import { CodeSandboxOutlined } from '@ant-design/icons';
|
|
10
10
|
import { Demo } from '../demo';
|
|
11
11
|
import { CodeEditor } from './code-editor';
|
|
12
|
-
import { Contain, Content, DrawerContain, Main, Right } from './index.style';
|
|
12
|
+
import { Contain, Content, DrawerContain, Main, MainContent, MainHeader, MainHeaderItem, Right } from './index.style';
|
|
13
13
|
import { postSandboxCode, postSandboxStyleCode } from './postSandboxCode';
|
|
14
14
|
export const CodeSandbox = _ref => {
|
|
15
15
|
let {
|
|
@@ -24,7 +24,8 @@ export const CodeSandbox = _ref => {
|
|
|
24
24
|
isZhLanguage,
|
|
25
25
|
editorApi,
|
|
26
26
|
cssCode,
|
|
27
|
-
styMap
|
|
27
|
+
styMap,
|
|
28
|
+
cssParse
|
|
28
29
|
} = _ref;
|
|
29
30
|
const iframeRef = useRef();
|
|
30
31
|
const [ts, setTs] = useState(Date.now());
|
|
@@ -52,27 +53,29 @@ export const CodeSandbox = _ref => {
|
|
|
52
53
|
postSandboxStyleCode(iframeRef.current, newCode, styMap);
|
|
53
54
|
}
|
|
54
55
|
}, 500), [show, styMap]);
|
|
55
|
-
return /*#__PURE__*/React.createElement(Contain, null, /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(Main, null, styMap
|
|
56
|
+
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, {
|
|
56
57
|
isZhLanguage: isZhLanguage,
|
|
57
58
|
baseUri: baseUri,
|
|
58
|
-
txpCode:
|
|
59
|
+
txpCode: txpCode,
|
|
59
60
|
height: `calc(90vh - 103px + 48px)`,
|
|
60
61
|
style: {
|
|
61
|
-
|
|
62
|
+
width: '50%'
|
|
62
63
|
},
|
|
63
64
|
show: show,
|
|
64
65
|
title: title,
|
|
65
|
-
|
|
66
|
+
fileName: "main.less",
|
|
67
|
+
code: cssCode,
|
|
66
68
|
onChange: newCode => {
|
|
67
69
|
postStyleCode(newCode);
|
|
68
|
-
}
|
|
70
|
+
},
|
|
71
|
+
cssParse: cssParse
|
|
69
72
|
}), /*#__PURE__*/React.createElement(CodeEditor, {
|
|
70
73
|
isZhLanguage: isZhLanguage,
|
|
71
74
|
baseUri: baseUri,
|
|
72
75
|
txpCode: txpCode,
|
|
73
76
|
height: `calc(90vh - 103px + 48px)`,
|
|
74
77
|
style: {
|
|
75
|
-
|
|
78
|
+
width: '50%'
|
|
76
79
|
},
|
|
77
80
|
ref: apiRef,
|
|
78
81
|
show: show,
|
|
@@ -81,6 +84,18 @@ export const CodeSandbox = _ref => {
|
|
|
81
84
|
onChange: newCode => {
|
|
82
85
|
postCode(newCode);
|
|
83
86
|
}
|
|
87
|
+
}))) : /*#__PURE__*/React.createElement(CodeEditor, {
|
|
88
|
+
isZhLanguage: isZhLanguage,
|
|
89
|
+
baseUri: baseUri,
|
|
90
|
+
txpCode: txpCode,
|
|
91
|
+
height: `calc(90vh - 103px + 48px)`,
|
|
92
|
+
ref: apiRef,
|
|
93
|
+
show: show,
|
|
94
|
+
title: title,
|
|
95
|
+
code: code,
|
|
96
|
+
onChange: newCode => {
|
|
97
|
+
postCode(newCode);
|
|
98
|
+
}
|
|
84
99
|
})), /*#__PURE__*/React.createElement(Right, null, /*#__PURE__*/React.createElement(Demo, {
|
|
85
100
|
emptyText: emptyText,
|
|
86
101
|
langKey: langKey,
|
|
@@ -116,7 +131,8 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
116
131
|
code,
|
|
117
132
|
editorApi,
|
|
118
133
|
cssCode,
|
|
119
|
-
styMap
|
|
134
|
+
styMap,
|
|
135
|
+
cssParse
|
|
120
136
|
} = _ref2;
|
|
121
137
|
const [show, setShow] = useState(false);
|
|
122
138
|
return {
|
|
@@ -148,7 +164,8 @@ export const useCodeSandboxDrawer = _ref2 => {
|
|
|
148
164
|
title: title,
|
|
149
165
|
code: code,
|
|
150
166
|
styMap: styMap,
|
|
151
|
-
cssCode: cssCode
|
|
167
|
+
cssCode: cssCode,
|
|
168
|
+
cssParse: cssParse
|
|
152
169
|
})),
|
|
153
170
|
show,
|
|
154
171
|
setShow
|
|
@@ -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,20 @@ export const Content = styled.div`
|
|
|
14
14
|
`;
|
|
15
15
|
export const Main = styled.div`
|
|
16
16
|
flex-grow: 1;
|
|
17
|
+
`;
|
|
18
|
+
export const MainHeader = styled.div`
|
|
19
|
+
display: flex;
|
|
20
|
+
border-bottom: 1px solid #0078d4;
|
|
21
|
+
`;
|
|
22
|
+
export const MainHeaderItem = styled.div`
|
|
23
|
+
background-color: #1f1f1f;
|
|
24
|
+
font-size: 16px;
|
|
25
|
+
font-weight: bold;
|
|
26
|
+
width: 50%;
|
|
27
|
+
color: #e2e2e2;
|
|
28
|
+
padding: 0 28px;
|
|
29
|
+
`;
|
|
30
|
+
export const MainContent = styled.div`
|
|
17
31
|
display: flex;
|
|
18
32
|
`;
|
|
19
33
|
export const Right = styled.div`
|