@dckj-npm/lowcode-plugin-code-generator 1.0.0
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/LICENSE +21 -0
- package/README.md +52 -0
- package/es/components/CodeGenActionBtn/CodeGenActionBtn.d.ts +8 -0
- package/es/components/CodeGenActionBtn/CodeGenActionBtn.js +196 -0
- package/es/components/CodeGenActionBtn/CodeGenActionBtn.scss +13 -0
- package/es/components/CodeGenActionBtn/index.d.ts +1 -0
- package/es/components/CodeGenActionBtn/index.js +1 -0
- package/es/components/CodeGenPreview/CodeGenPreview.d.ts +8 -0
- package/es/components/CodeGenPreview/CodeGenPreview.js +40 -0
- package/es/components/CodeGenPreview/CodeGenPreview.scss +16 -0
- package/es/components/CodeGenPreview/fixPreviewCode.d.ts +2 -0
- package/es/components/CodeGenPreview/fixPreviewCode.js +101 -0
- package/es/components/CodeGenPreview/index.d.ts +1 -0
- package/es/components/CodeGenPreview/index.js +1 -0
- package/es/components/CodeGenPreview/useIsInIntranet.d.ts +4 -0
- package/es/components/CodeGenPreview/useIsInIntranet.js +66 -0
- package/es/components/CodeGenResult/CodeGenResult.d.ts +9 -0
- package/es/components/CodeGenResult/CodeGenResult.js +162 -0
- package/es/components/CodeGenResult/CodeGenResult.scss +7 -0
- package/es/components/CodeGenResult/index.d.ts +1 -0
- package/es/components/CodeGenResult/index.js +1 -0
- package/es/components/CodeSandboxPreview/CodeSandboxPreview.d.ts +4 -0
- package/es/components/CodeSandboxPreview/CodeSandboxPreview.js +186 -0
- package/es/components/CodeSandboxPreview/CodeSandboxPreview.scss +18 -0
- package/es/components/CodeSandboxPreview/index.d.ts +1 -0
- package/es/components/CodeSandboxPreview/index.js +1 -0
- package/es/components/FileTypeIcon/FileTypeIcon.d.ts +6 -0
- package/es/components/FileTypeIcon/FileTypeIcon.js +12 -0
- package/es/components/FileTypeIcon/FileTypeIcon.scss +36 -0
- package/es/components/FileTypeIcon/index.d.ts +1 -0
- package/es/components/FileTypeIcon/index.js +1 -0
- package/es/components/GravityCode/GravityCode.d.ts +9 -0
- package/es/components/GravityCode/GravityCode.js +1 -0
- package/es/components/GravityCode/index.d.ts +1 -0
- package/es/components/GravityCode/index.js +1 -0
- package/es/components/GravityPreview/ForceUpdate.d.ts +6 -0
- package/es/components/GravityPreview/ForceUpdate.js +12 -0
- package/es/components/GravityPreview/GravityPreview.d.ts +7 -0
- package/es/components/GravityPreview/GravityPreview.js +37 -0
- package/es/components/GravityPreview/GravitySdk.d.ts +10 -0
- package/es/components/GravityPreview/GravitySdk.js +183 -0
- package/es/components/GravityPreview/index.d.ts +1 -0
- package/es/components/GravityPreview/index.js +1 -0
- package/es/components/SourcesView/SourcesView.d.ts +9 -0
- package/es/components/SourcesView/SourcesView.js +197 -0
- package/es/components/SourcesView/SourcesView.scss +24 -0
- package/es/components/SourcesView/index.d.ts +1 -0
- package/es/components/SourcesView/index.js +1 -0
- package/es/demo/index.d.ts +1 -0
- package/es/demo/index.js +223 -0
- package/es/demo/index.scss +56 -0
- package/es/index.d.ts +30 -0
- package/es/index.js +67 -0
- package/es/style.js +2 -0
- package/es/types/SyncCodeGenResult.d.ts +7 -0
- package/es/types/SyncCodeGenResult.js +1 -0
- package/es/types/index.d.ts +1 -0
- package/es/types/index.js +1 -0
- package/es/typings.d.js +0 -0
- package/lib/components/CodeGenActionBtn/CodeGenActionBtn.d.ts +8 -0
- package/lib/components/CodeGenActionBtn/CodeGenActionBtn.js +204 -0
- package/lib/components/CodeGenActionBtn/CodeGenActionBtn.scss +13 -0
- package/lib/components/CodeGenActionBtn/index.d.ts +1 -0
- package/lib/components/CodeGenActionBtn/index.js +9 -0
- package/lib/components/CodeGenPreview/CodeGenPreview.d.ts +8 -0
- package/lib/components/CodeGenPreview/CodeGenPreview.js +45 -0
- package/lib/components/CodeGenPreview/CodeGenPreview.scss +16 -0
- package/lib/components/CodeGenPreview/fixPreviewCode.d.ts +2 -0
- package/lib/components/CodeGenPreview/fixPreviewCode.js +106 -0
- package/lib/components/CodeGenPreview/index.d.ts +1 -0
- package/lib/components/CodeGenPreview/index.js +9 -0
- package/lib/components/CodeGenPreview/useIsInIntranet.d.ts +4 -0
- package/lib/components/CodeGenPreview/useIsInIntranet.js +72 -0
- package/lib/components/CodeGenResult/CodeGenResult.d.ts +9 -0
- package/lib/components/CodeGenResult/CodeGenResult.js +169 -0
- package/lib/components/CodeGenResult/CodeGenResult.scss +7 -0
- package/lib/components/CodeGenResult/index.d.ts +1 -0
- package/lib/components/CodeGenResult/index.js +9 -0
- package/lib/components/CodeSandboxPreview/CodeSandboxPreview.d.ts +4 -0
- package/lib/components/CodeSandboxPreview/CodeSandboxPreview.js +193 -0
- package/lib/components/CodeSandboxPreview/CodeSandboxPreview.scss +18 -0
- package/lib/components/CodeSandboxPreview/index.d.ts +1 -0
- package/lib/components/CodeSandboxPreview/index.js +9 -0
- package/lib/components/FileTypeIcon/FileTypeIcon.d.ts +6 -0
- package/lib/components/FileTypeIcon/FileTypeIcon.js +17 -0
- package/lib/components/FileTypeIcon/FileTypeIcon.scss +36 -0
- package/lib/components/FileTypeIcon/index.d.ts +1 -0
- package/lib/components/FileTypeIcon/index.js +9 -0
- package/lib/components/GravityCode/GravityCode.d.ts +9 -0
- package/lib/components/GravityCode/GravityCode.js +3 -0
- package/lib/components/GravityCode/index.d.ts +1 -0
- package/lib/components/GravityCode/index.js +9 -0
- package/lib/components/GravityPreview/ForceUpdate.d.ts +6 -0
- package/lib/components/GravityPreview/ForceUpdate.js +17 -0
- package/lib/components/GravityPreview/GravityPreview.d.ts +7 -0
- package/lib/components/GravityPreview/GravityPreview.js +44 -0
- package/lib/components/GravityPreview/GravitySdk.d.ts +10 -0
- package/lib/components/GravityPreview/GravitySdk.js +196 -0
- package/lib/components/GravityPreview/index.d.ts +1 -0
- package/lib/components/GravityPreview/index.js +9 -0
- package/lib/components/SourcesView/SourcesView.d.ts +9 -0
- package/lib/components/SourcesView/SourcesView.js +204 -0
- package/lib/components/SourcesView/SourcesView.scss +24 -0
- package/lib/components/SourcesView/index.d.ts +1 -0
- package/lib/components/SourcesView/index.js +9 -0
- package/lib/demo/index.d.ts +1 -0
- package/lib/demo/index.js +228 -0
- package/lib/demo/index.scss +56 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +74 -0
- package/lib/style.js +2 -0
- package/lib/types/SyncCodeGenResult.d.ts +7 -0
- package/lib/types/SyncCodeGenResult.js +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +9 -0
- package/lib/typings.d.js +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import './CodeGenResult.scss';
|
|
5
|
+
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import FileSaver from 'file-saver';
|
|
7
|
+
import JSZip from 'jszip';
|
|
8
|
+
import { Collapse, Message } from '@alifd/next';
|
|
9
|
+
import { CodeGenPreview } from '../CodeGenPreview';
|
|
10
|
+
import { SourcesView } from '../SourcesView';
|
|
11
|
+
export function CodeGenResult(_ref) {
|
|
12
|
+
var result = _ref.result,
|
|
13
|
+
schema = _ref.schema;
|
|
14
|
+
var _useState = useState({
|
|
15
|
+
expandedKeys: ['sources', 'preview']
|
|
16
|
+
}),
|
|
17
|
+
paneState = _useState[0],
|
|
18
|
+
setPaneState = _useState[1];
|
|
19
|
+
var _useState2 = useState(null),
|
|
20
|
+
gravityCode = _useState2[0],
|
|
21
|
+
setGravityCode = _useState2[1];
|
|
22
|
+
var _useState3 = useState(0),
|
|
23
|
+
refresh = _useState3[0],
|
|
24
|
+
setRefresh = _useState3[1];
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
setGravityCode(convertCodeGenResult(result, schema));
|
|
27
|
+
}, [result]);
|
|
28
|
+
if (!result) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
var sourcesViewHeight = paneState.expandedKeys.includes('preview') ? '40vh' : '80vh';
|
|
32
|
+
var gravityDemoHeight = paneState.expandedKeys.includes('sources') ? '40vh' : '80vh';
|
|
33
|
+
var handleDownloadSources = /*#__PURE__*/function () {
|
|
34
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(e) {
|
|
35
|
+
var zip;
|
|
36
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
37
|
+
while (1) switch (_context.prev = _context.next) {
|
|
38
|
+
case 0:
|
|
39
|
+
_context.prev = 0;
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
zip = new JSZip();
|
|
43
|
+
Object.values((gravityCode === null || gravityCode === void 0 ? void 0 : gravityCode.modules) || {}).forEach(function (file) {
|
|
44
|
+
zip.file(file.fpath.replace(/^\/+/, ''), file.code);
|
|
45
|
+
});
|
|
46
|
+
_context.next = 7;
|
|
47
|
+
return zip.generateAsync({
|
|
48
|
+
type: 'blob'
|
|
49
|
+
}).then(function (content) {
|
|
50
|
+
FileSaver.saveAs(content, 'ali-lowcode-generated-sources.zip');
|
|
51
|
+
});
|
|
52
|
+
case 7:
|
|
53
|
+
_context.next = 13;
|
|
54
|
+
break;
|
|
55
|
+
case 9:
|
|
56
|
+
_context.prev = 9;
|
|
57
|
+
_context.t0 = _context["catch"](0);
|
|
58
|
+
console.log('failed to download sources: ', _context.t0);
|
|
59
|
+
Message.error('下载失败!');
|
|
60
|
+
case 13:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee, null, [[0, 9]]);
|
|
65
|
+
}));
|
|
66
|
+
return function handleDownloadSources(_x) {
|
|
67
|
+
return _ref2.apply(this, arguments);
|
|
68
|
+
};
|
|
69
|
+
}();
|
|
70
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: "code-gen-result"
|
|
72
|
+
}, /*#__PURE__*/React.createElement(Collapse, {
|
|
73
|
+
expandedKeys: paneState.expandedKeys,
|
|
74
|
+
onExpand: function onExpand(expandedKeys) {
|
|
75
|
+
setPaneState({
|
|
76
|
+
expandedKeys: expandedKeys
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}, /*#__PURE__*/React.createElement(Collapse.Panel, {
|
|
80
|
+
title: /*#__PURE__*/React.createElement("span", null, "\u51FA\u7801\u751F\u6210\u7684\u6E90\u4EE3\u7801", ' ', /*#__PURE__*/React.createElement("a", {
|
|
81
|
+
href: "javascript:void(0)",
|
|
82
|
+
onClick: handleDownloadSources
|
|
83
|
+
}, "\u5BFC\u51FA/\u4E0B\u8F7D zip \u5305")),
|
|
84
|
+
key: "sources"
|
|
85
|
+
}, gravityCode != null && /*#__PURE__*/React.createElement(SourcesView, {
|
|
86
|
+
height: sourcesViewHeight,
|
|
87
|
+
code: gravityCode,
|
|
88
|
+
onCodeChange: setGravityCode
|
|
89
|
+
})), /*#__PURE__*/React.createElement(Collapse.Panel, {
|
|
90
|
+
title: /*#__PURE__*/React.createElement("span", null, "\u5728\u7EBF\u9884\u89C8", ' ', /*#__PURE__*/React.createElement("a", {
|
|
91
|
+
href: "#refresh",
|
|
92
|
+
onClick: function onClick(e) {
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
setRefresh(Date.now());
|
|
96
|
+
}
|
|
97
|
+
}, "\u5237\u65B0")),
|
|
98
|
+
key: "preview"
|
|
99
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
100
|
+
className: "code-gen-result-gravity-demo",
|
|
101
|
+
style: {
|
|
102
|
+
height: gravityDemoHeight
|
|
103
|
+
}
|
|
104
|
+
}, /*#__PURE__*/React.createElement(CodeGenPreview, {
|
|
105
|
+
code: gravityCode,
|
|
106
|
+
height: gravityDemoHeight,
|
|
107
|
+
refresh: refresh
|
|
108
|
+
})))));
|
|
109
|
+
}
|
|
110
|
+
function convertCodeGenResult(result, schema) {
|
|
111
|
+
var schemaFiles = {
|
|
112
|
+
'/.project-schema.json': {
|
|
113
|
+
fpath: '/.project-schema.json',
|
|
114
|
+
code: JSON.stringify(schema, null, 2) + "\n"
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
if (!result || !Array.isArray(result) || !result.length) {
|
|
118
|
+
return {
|
|
119
|
+
type: 'demo',
|
|
120
|
+
modules: schemaFiles
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
var code = {
|
|
124
|
+
type: 'demo',
|
|
125
|
+
modules: result.reduce(function (acc, file) {
|
|
126
|
+
var _extends2;
|
|
127
|
+
return _extends({}, acc, (_extends2 = {}, _extends2["/" + file.pathName] = {
|
|
128
|
+
fpath: "/" + file.pathName,
|
|
129
|
+
code: file.content,
|
|
130
|
+
entry: undefined,
|
|
131
|
+
packagejson: ['package.json'].includes(file.pathName) ? 1 : undefined
|
|
132
|
+
}, _extends2));
|
|
133
|
+
}, {})
|
|
134
|
+
};
|
|
135
|
+
var foundEntry = false;
|
|
136
|
+
|
|
137
|
+
// 设置入口文件
|
|
138
|
+
['index.js', 'index.ts', 'index.tsx', 'app.js', 'app.ts', 'app.tsx'].forEach(function (fileName) {
|
|
139
|
+
if (!foundEntry) {
|
|
140
|
+
var filePath = "/src/" + fileName;
|
|
141
|
+
if (code.modules[filePath]) {
|
|
142
|
+
foundEntry = true;
|
|
143
|
+
if (fileName === 'index.js') {
|
|
144
|
+
code.modules[filePath].entry = 1;
|
|
145
|
+
} else {
|
|
146
|
+
code.modules['/src/index.js'] = {
|
|
147
|
+
fpath: '/src/index.js',
|
|
148
|
+
entry: 1,
|
|
149
|
+
code: "import \"./" + fileName.replace(/\.\w+$/, '') + "\""
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
if (!foundEntry) {
|
|
156
|
+
console.warn('Failed to find entry file for demo.');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 补充 schema 文件
|
|
160
|
+
Object.assign(code.modules, schemaFiles);
|
|
161
|
+
return code;
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeGenResult';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeGenResult';
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import React, { useMemo, useState, useEffect } from 'react';
|
|
5
|
+
import { Button, Loading, Message } from '@alifd/next';
|
|
6
|
+
import { fixPreviewCode } from '../CodeGenPreview/fixPreviewCode';
|
|
7
|
+
import './CodeSandboxPreview.scss';
|
|
8
|
+
// 使用 CodeSandbox 来进行预览
|
|
9
|
+
// @see https://codesandbox.io/docs/api#get-request
|
|
10
|
+
export function CodeSandboxPreview(_ref) {
|
|
11
|
+
var code = _ref.code,
|
|
12
|
+
height = _ref.height;
|
|
13
|
+
var parameters = useMemo(function () {
|
|
14
|
+
var files = {};
|
|
15
|
+
if (code && code.modules) {
|
|
16
|
+
var fixedCode = fixPreviewCode(code);
|
|
17
|
+
Object.values(fixedCode.modules).forEach(function (file) {
|
|
18
|
+
var _file$fpath;
|
|
19
|
+
files[file === null || file === void 0 ? void 0 : (_file$fpath = file.fpath) === null || _file$fpath === void 0 ? void 0 : _file$fpath.slice(1)] = {
|
|
20
|
+
isBinary: false,
|
|
21
|
+
content: file.code
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// 入口文件需要顺便引入下样式
|
|
26
|
+
files['src/index.js'] = {
|
|
27
|
+
isBinary: false,
|
|
28
|
+
content: "\n// \u76EE\u524D\u9700\u8981\u5355\u72EC\u5F15\u5165\u4E0B\u6837\u5F0F\u6587\u4EF6\nimport \"@alifd/next/dist/next.css\";\nimport \"@alifd/pro-layout/dist/AlifdProLayout.css\";\n\n// \u5F15\u5165\u5165\u53E3\u6587\u4EF6\nimport './app';\n"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
files: files,
|
|
33
|
+
template: 'create-react-app'
|
|
34
|
+
};
|
|
35
|
+
}, [code]);
|
|
36
|
+
var _useState = useState({
|
|
37
|
+
parameters: parameters,
|
|
38
|
+
sandboxId: '',
|
|
39
|
+
isCreating: false,
|
|
40
|
+
hasError: false,
|
|
41
|
+
error: null
|
|
42
|
+
}),
|
|
43
|
+
state = _useState[0],
|
|
44
|
+
setState = _useState[1];
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
if (state.parameters !== parameters || state.sandboxId === 'retry' || !state.sandboxId) {
|
|
47
|
+
var hasCanceled = false;
|
|
48
|
+
setState(function (prev) {
|
|
49
|
+
return _extends({}, prev, {
|
|
50
|
+
hasError: false,
|
|
51
|
+
code: code,
|
|
52
|
+
parameters: parameters,
|
|
53
|
+
isCreating: true
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
57
|
+
var sandboxId;
|
|
58
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
59
|
+
while (1) switch (_context.prev = _context.next) {
|
|
60
|
+
case 0:
|
|
61
|
+
_context.prev = 0;
|
|
62
|
+
_context.next = 3;
|
|
63
|
+
return createCodeSandbox(parameters);
|
|
64
|
+
case 3:
|
|
65
|
+
sandboxId = _context.sent;
|
|
66
|
+
if (!hasCanceled) {
|
|
67
|
+
setState(function (prev) {
|
|
68
|
+
return _extends({}, prev, {
|
|
69
|
+
hasError: false,
|
|
70
|
+
isCreating: false,
|
|
71
|
+
sandboxId: sandboxId
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
_context.next = 10;
|
|
76
|
+
break;
|
|
77
|
+
case 7:
|
|
78
|
+
_context.prev = 7;
|
|
79
|
+
_context.t0 = _context["catch"](0);
|
|
80
|
+
if (!hasCanceled) {
|
|
81
|
+
setState(function (prev) {
|
|
82
|
+
return _extends({}, prev, {
|
|
83
|
+
hasError: true,
|
|
84
|
+
error: _context.t0,
|
|
85
|
+
isCreating: false
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
case 10:
|
|
90
|
+
case "end":
|
|
91
|
+
return _context.stop();
|
|
92
|
+
}
|
|
93
|
+
}, _callee, null, [[0, 7]]);
|
|
94
|
+
}))();
|
|
95
|
+
return function () {
|
|
96
|
+
hasCanceled = true;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return function () {};
|
|
100
|
+
}, [parameters, state.sandboxId, state.parameters]);
|
|
101
|
+
var handleRetry = function handleRetry() {
|
|
102
|
+
setState(function (prev) {
|
|
103
|
+
return _extends({}, prev, {
|
|
104
|
+
hasError: false,
|
|
105
|
+
sandboxId: 'retry'
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
110
|
+
className: "code-gen-plugin-code-sandbox-preview",
|
|
111
|
+
style: {
|
|
112
|
+
height: height
|
|
113
|
+
},
|
|
114
|
+
"data-code-sandbox-id": state.sandboxId
|
|
115
|
+
}, function () {
|
|
116
|
+
if (state.hasError) {
|
|
117
|
+
return /*#__PURE__*/React.createElement(Message, {
|
|
118
|
+
title: "\u751F\u6210 CodeSandbox \u9884\u89C8\u5E94\u7528\u5931\u8D25"
|
|
119
|
+
}, /*#__PURE__*/React.createElement("p", null, "\u8BE6\u7EC6\u9519\u8BEF\uFF1A", "" + (state.error || '网络开小差了')), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(Button, {
|
|
120
|
+
onClick: handleRetry
|
|
121
|
+
}, "\u91CD\u65B0\u5C1D\u8BD5\u4E0B")));
|
|
122
|
+
}
|
|
123
|
+
return state.sandboxId ? /*#__PURE__*/React.createElement("iframe", {
|
|
124
|
+
src: "https://codesandbox.io/embed/" + state.sandboxId + "?autoresize=1&fontsize=14&hidenavigation=1&theme=dark&view=preview",
|
|
125
|
+
title: "CodeSandbox Preview",
|
|
126
|
+
allow: "accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking",
|
|
127
|
+
sandbox: "allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
128
|
+
}) : /*#__PURE__*/React.createElement(Loading, {
|
|
129
|
+
tip: "\u6B63\u5728\u751F\u6210 CodeSandbox \u9884\u89C8\u5E94\u7528..."
|
|
130
|
+
});
|
|
131
|
+
}());
|
|
132
|
+
}
|
|
133
|
+
function createCodeSandbox(_x) {
|
|
134
|
+
return _createCodeSandbox.apply(this, arguments);
|
|
135
|
+
}
|
|
136
|
+
function _createCodeSandbox() {
|
|
137
|
+
_createCodeSandbox = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(parameters) {
|
|
138
|
+
var res, json, _ref3, sandbox_id;
|
|
139
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
140
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
141
|
+
case 0:
|
|
142
|
+
if (Object.entries((parameters === null || parameters === void 0 ? void 0 : parameters.files) || {}).length) {
|
|
143
|
+
_context2.next = 2;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
return _context2.abrupt("return", '');
|
|
147
|
+
case 2:
|
|
148
|
+
_context2.next = 4;
|
|
149
|
+
return fetch('https://codesandbox.io/api/v1/sandboxes/define?json=1', {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
headers: {
|
|
152
|
+
'Content-Type': 'application/json',
|
|
153
|
+
Accept: 'application/json'
|
|
154
|
+
},
|
|
155
|
+
body: JSON.stringify(parameters)
|
|
156
|
+
});
|
|
157
|
+
case 4:
|
|
158
|
+
res = _context2.sent;
|
|
159
|
+
if (res.ok) {
|
|
160
|
+
_context2.next = 7;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
throw new Error("\u521B\u5EFA CodeSandbox \u5931\u8D25\uFF0C\u9519\u8BEF\u7801\uFF1A" + res.status + " " + res.statusText);
|
|
164
|
+
case 7:
|
|
165
|
+
_context2.next = 9;
|
|
166
|
+
return res.json()["catch"](function (err) {
|
|
167
|
+
throw new Error("\u521B\u5EFA CodeSandbox \u5931\u8D25\uFF0C\u670D\u52A1\u5F02\u5E38(" + ((err === null || err === void 0 ? void 0 : err.message) || err || '未知异常') + ")");
|
|
168
|
+
});
|
|
169
|
+
case 9:
|
|
170
|
+
json = _context2.sent;
|
|
171
|
+
_ref3 = json || {}, sandbox_id = _ref3.sandbox_id;
|
|
172
|
+
if (!(!sandbox_id || typeof sandbox_id !== 'string')) {
|
|
173
|
+
_context2.next = 13;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
throw new Error("\u521B\u5EFA CodeSandbox \u5931\u8D25\uFF0C\u670D\u52A1\u54CD\u5E94\u5F02\u5E38");
|
|
177
|
+
case 13:
|
|
178
|
+
return _context2.abrupt("return", sandbox_id);
|
|
179
|
+
case 14:
|
|
180
|
+
case "end":
|
|
181
|
+
return _context2.stop();
|
|
182
|
+
}
|
|
183
|
+
}, _callee2);
|
|
184
|
+
}));
|
|
185
|
+
return _createCodeSandbox.apply(this, arguments);
|
|
186
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.code-gen-plugin-code-sandbox-preview {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
align-items: center;
|
|
5
|
+
align-content: center;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
justify-items: center;
|
|
8
|
+
height: 100%;
|
|
9
|
+
|
|
10
|
+
iframe {
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
min-height: 300px;
|
|
14
|
+
border: 0;
|
|
15
|
+
border-radius: 0;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeSandboxPreview';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeSandboxPreview';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["type"];
|
|
4
|
+
import './FileTypeIcon.scss';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
export function FileTypeIcon(_ref) {
|
|
7
|
+
var type = _ref.type,
|
|
8
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
9
|
+
return /*#__PURE__*/React.createElement("i", _extends({}, props, {
|
|
10
|
+
className: "file-types-iconfont file-types-icon-" + type + " " + (props.className || '')
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// source: https://at.alicdn.com/t/font_2997782_rtal7ux80t.css
|
|
2
|
+
|
|
3
|
+
@font-face {
|
|
4
|
+
font-family: "file-types-iconfont"; /* Project id 2997782 */
|
|
5
|
+
src: url('//at.alicdn.com/t/font_2997782_rtal7ux80t.woff2?t=1638951976966') format('woff2'),
|
|
6
|
+
url('//at.alicdn.com/t/font_2997782_rtal7ux80t.woff?t=1638951976966') format('woff'),
|
|
7
|
+
url('//at.alicdn.com/t/font_2997782_rtal7ux80t.ttf?t=1638951976966') format('truetype');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.file-types-iconfont {
|
|
11
|
+
font-family: "file-types-iconfont" !important;
|
|
12
|
+
font-size: 16px;
|
|
13
|
+
font-style: normal;
|
|
14
|
+
-webkit-font-smoothing: antialiased;
|
|
15
|
+
-moz-osx-font-smoothing: grayscale;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.file-types-icon-folder:before {
|
|
19
|
+
content: "\e6e9";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.file-types-icon-text:before {
|
|
23
|
+
content: "\e6a7";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.file-types-icon-jsx:before {
|
|
27
|
+
content: "\e63b";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.file-types-icon-js:before {
|
|
31
|
+
content: "\e618";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.file-types-icon-json:before {
|
|
35
|
+
content: "\e642";
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FileTypeIcon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FileTypeIcon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GravityCode';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GravityCode';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export function ForceUpdate(_ref) {
|
|
3
|
+
var watchKey = _ref.watchKey,
|
|
4
|
+
children = _ref.children;
|
|
5
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, [/*#__PURE__*/React.createElement(ForceUpdateContent, {
|
|
6
|
+
key: watchKey
|
|
7
|
+
}, children)]);
|
|
8
|
+
}
|
|
9
|
+
function ForceUpdateContent(_ref2) {
|
|
10
|
+
var children = _ref2.children;
|
|
11
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import GravityDemoSDK from './GravitySdk';
|
|
3
|
+
import { ForceUpdate } from './ForceUpdate';
|
|
4
|
+
import { fixPreviewCode } from '../CodeGenPreview/fixPreviewCode';
|
|
5
|
+
export function GravityPreview(_ref) {
|
|
6
|
+
var code = _ref.code,
|
|
7
|
+
height = _ref.height,
|
|
8
|
+
refresh = _ref.refresh;
|
|
9
|
+
var fixedCode = useMemo(function () {
|
|
10
|
+
return fixGravityCode(code, refresh);
|
|
11
|
+
}, [code, refresh]);
|
|
12
|
+
if (!code || !fixedCode) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
console.log('GravityPreview', fixedCode);
|
|
16
|
+
return /*#__PURE__*/React.createElement(ForceUpdate, {
|
|
17
|
+
watchKey: refresh
|
|
18
|
+
}, /*#__PURE__*/React.createElement(GravityDemoSDK, {
|
|
19
|
+
code: fixedCode,
|
|
20
|
+
width: "100%",
|
|
21
|
+
height: height
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function fixGravityCode(code, refresh) {
|
|
25
|
+
if (!code) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
var fixed = fixPreviewCode(code);
|
|
29
|
+
Object.assign(fixed.modules, {
|
|
30
|
+
'/src/html.js': {
|
|
31
|
+
fpath: '/src/html.js',
|
|
32
|
+
code: "function runScript(script){\n const newScript = document.createElement('script');\n newScript.innerHTML = script.innerHTML;\n const src = script.getAttribute('src');\n if (src) newScript.setAttribute('src', src);\n\n document.head.appendChild(newScript);\n document.head.removeChild(newScript);\n}\n\nfunction setHTMLWithScript(container, rawHTML){\n container.innerHTML = rawHTML;\n const scripts = container.querySelectorAll('script');\n for (let script of scripts) {\n runScript(script);\n }\n} var html = window.BrowserFS.BFSRequire('fs').readFileSync('/~/src/index.html').toString();setHTMLWithScript(document.getElementById(\"riddleContainer\"), html);",
|
|
33
|
+
entry: 1
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return fixed;
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function getHeight(): any;
|
|
3
|
+
export declare function refresh(): void;
|
|
4
|
+
export declare function clear(): void;
|
|
5
|
+
export declare function getBoostState(): any;
|
|
6
|
+
export declare function toggleBoostState(): void;
|
|
7
|
+
export declare function isPrivateMode(): any;
|
|
8
|
+
export declare function change(filename: any, content: any): void;
|
|
9
|
+
declare const _default: (props: any) => JSX.Element;
|
|
10
|
+
export default _default;
|