@gant-lowcode/plugin-code-generator 2.0.16 → 2.0.18
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/es/components/code-gen-action/index.js +82 -88
- package/es/components/code-gen-result/index.js +24 -27
- package/es/components/codesandbox-preview/index.js +35 -38
- package/es/index.js +16 -15
- package/lib/components/code-gen-action/index.js +82 -88
- package/lib/components/code-gen-result/index.js +25 -31
- package/lib/components/codesandbox-preview/index.js +36 -40
- package/lib/components/file-tree/index.js +1 -2
- package/lib/components/sources-view/index.js +1 -2
- package/lib/index.js +17 -17
- package/package.json +7 -7
|
@@ -6,7 +6,8 @@ import _Alert from "antd/es/alert";
|
|
|
6
6
|
import _message from "antd/es/message";
|
|
7
7
|
import _extends from "@babel/runtime/helpers/extends";
|
|
8
8
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
9
|
-
|
|
9
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
10
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
10
11
|
import { useRef, useState } from "react";
|
|
11
12
|
import { generateCode } from "@gant-lowcode/code-generator/standalone-loader";
|
|
12
13
|
import { IPublicEnumTransformStage } from "@gant-lowcode/lowcode-types";
|
|
@@ -32,12 +33,12 @@ export function CodeGenActionBtn(_ref) {
|
|
|
32
33
|
setState = _useState[1];
|
|
33
34
|
var codeGenResultRef = useRef(null);
|
|
34
35
|
var handleClick = /*#__PURE__*/function () {
|
|
35
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/
|
|
36
|
-
var getProjectSchema, originalSchema, schema, result;
|
|
37
|
-
return
|
|
38
|
-
while (1) switch (_context.
|
|
36
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
37
|
+
var getProjectSchema, originalSchema, schema, result, _t;
|
|
38
|
+
return _regenerator().w(function (_context) {
|
|
39
|
+
while (1) switch (_context.p = _context.n) {
|
|
39
40
|
case 0:
|
|
40
|
-
_context.
|
|
41
|
+
_context.p = 0;
|
|
41
42
|
// 打开基于 Gravity 的编辑器/出码预览器
|
|
42
43
|
setState(function (prev) {
|
|
43
44
|
return _extends({}, prev, {
|
|
@@ -49,25 +50,25 @@ export function CodeGenActionBtn(_ref) {
|
|
|
49
50
|
console.log("--ctx", ctx);
|
|
50
51
|
getProjectSchema = ctx.config.get("getProjectSchema");
|
|
51
52
|
if (!getProjectSchema) {
|
|
52
|
-
_context.
|
|
53
|
+
_context.n = 2;
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
|
-
_context.
|
|
56
|
+
_context.n = 1;
|
|
56
57
|
return getProjectSchema();
|
|
57
|
-
case
|
|
58
|
-
originalSchema = _context.
|
|
59
|
-
_context.
|
|
58
|
+
case 1:
|
|
59
|
+
originalSchema = _context.v;
|
|
60
|
+
_context.n = 4;
|
|
60
61
|
break;
|
|
61
|
-
case
|
|
62
|
-
_context.
|
|
62
|
+
case 2:
|
|
63
|
+
_context.n = 3;
|
|
63
64
|
return ctx.project.exportSchema(IPublicEnumTransformStage.Save);
|
|
64
|
-
case
|
|
65
|
-
originalSchema = _context.
|
|
66
|
-
case
|
|
67
|
-
_context.
|
|
65
|
+
case 3:
|
|
66
|
+
originalSchema = _context.v;
|
|
67
|
+
case 4:
|
|
68
|
+
_context.n = 5;
|
|
68
69
|
return fixSchema(originalSchema);
|
|
69
|
-
case
|
|
70
|
-
schema = _context.
|
|
70
|
+
case 5:
|
|
71
|
+
schema = _context.v;
|
|
71
72
|
console.log("got schema: ", schema);
|
|
72
73
|
setState(function (prev) {
|
|
73
74
|
return _extends({}, prev, {
|
|
@@ -77,7 +78,7 @@ export function CodeGenActionBtn(_ref) {
|
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
// 出码...
|
|
80
|
-
_context.
|
|
81
|
+
_context.n = 6;
|
|
81
82
|
return generateCode({
|
|
82
83
|
solution: "gantLegacy",
|
|
83
84
|
schema: schema,
|
|
@@ -89,8 +90,8 @@ export function CodeGenActionBtn(_ref) {
|
|
|
89
90
|
configPaths: []
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
|
-
case
|
|
93
|
-
result = _context.
|
|
93
|
+
case 6:
|
|
94
|
+
result = _context.v;
|
|
94
95
|
console.log("generated: ", result);
|
|
95
96
|
setState(function (prev) {
|
|
96
97
|
return _extends({}, prev, {
|
|
@@ -98,74 +99,71 @@ export function CodeGenActionBtn(_ref) {
|
|
|
98
99
|
result: result
|
|
99
100
|
});
|
|
100
101
|
});
|
|
101
|
-
_context.
|
|
102
|
+
_context.n = 8;
|
|
102
103
|
break;
|
|
103
|
-
case
|
|
104
|
-
_context.
|
|
105
|
-
|
|
106
|
-
console.error("failed to run code generator: ",
|
|
104
|
+
case 7:
|
|
105
|
+
_context.p = 7;
|
|
106
|
+
_t = _context.v;
|
|
107
|
+
console.error("failed to run code generator: ", _t);
|
|
107
108
|
setState(function (prev) {
|
|
108
109
|
return _extends({}, prev, {
|
|
109
110
|
hasError: true,
|
|
110
|
-
error:
|
|
111
|
+
error: _t instanceof Error ? _t : new Error("" + ((_t === null || _t === void 0 ? void 0 : _t.message) || _t))
|
|
111
112
|
});
|
|
112
113
|
});
|
|
113
|
-
case
|
|
114
|
-
|
|
115
|
-
return _context.stop();
|
|
114
|
+
case 8:
|
|
115
|
+
return _context.a(2);
|
|
116
116
|
}
|
|
117
|
-
}, _callee, null, [[0,
|
|
117
|
+
}, _callee, null, [[0, 7]]);
|
|
118
118
|
}));
|
|
119
119
|
return function handleClick() {
|
|
120
120
|
return _ref2.apply(this, arguments);
|
|
121
121
|
};
|
|
122
122
|
}();
|
|
123
|
-
var _useRequest = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/
|
|
124
|
-
var codeGen, content;
|
|
125
|
-
return
|
|
126
|
-
while (1) switch (_context2.
|
|
123
|
+
var _useRequest = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
124
|
+
var codeGen, content, _t2;
|
|
125
|
+
return _regenerator().w(function (_context2) {
|
|
126
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
127
127
|
case 0:
|
|
128
|
-
_context2.
|
|
128
|
+
_context2.p = 0;
|
|
129
129
|
codeGen = codeGenResultRef.current;
|
|
130
130
|
if (codeGen) {
|
|
131
|
-
_context2.
|
|
131
|
+
_context2.n = 1;
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
134
|
-
return _context2.
|
|
135
|
-
case
|
|
136
|
-
_context2.
|
|
134
|
+
return _context2.a(2);
|
|
135
|
+
case 1:
|
|
136
|
+
_context2.n = 2;
|
|
137
137
|
return codeGen.codeZip();
|
|
138
|
-
case
|
|
139
|
-
content = _context2.
|
|
138
|
+
case 2:
|
|
139
|
+
content = _context2.v;
|
|
140
140
|
FileSaver.saveAs(content, "gant-lowcode-generated-sources.zip");
|
|
141
|
-
_context2.
|
|
141
|
+
_context2.n = 4;
|
|
142
142
|
break;
|
|
143
|
-
case
|
|
144
|
-
_context2.
|
|
145
|
-
|
|
146
|
-
console.log("failed to download sources: ",
|
|
143
|
+
case 3:
|
|
144
|
+
_context2.p = 3;
|
|
145
|
+
_t2 = _context2.v;
|
|
146
|
+
console.log("failed to download sources: ", _t2);
|
|
147
147
|
_message.error("下载失败!");
|
|
148
|
-
case
|
|
149
|
-
|
|
150
|
-
return _context2.stop();
|
|
148
|
+
case 4:
|
|
149
|
+
return _context2.a(2);
|
|
151
150
|
}
|
|
152
|
-
}, _callee2, null, [[0,
|
|
151
|
+
}, _callee2, null, [[0, 3]]);
|
|
153
152
|
})), {
|
|
154
153
|
manual: true
|
|
155
154
|
}),
|
|
156
155
|
run = _useRequest.run,
|
|
157
156
|
downloading = _useRequest.loading;
|
|
158
157
|
var handleDownload = /*#__PURE__*/function () {
|
|
159
|
-
var _ref4 = _asyncToGenerator(/*#__PURE__*/
|
|
160
|
-
return
|
|
161
|
-
while (1) switch (_context3.
|
|
158
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e) {
|
|
159
|
+
return _regenerator().w(function (_context3) {
|
|
160
|
+
while (1) switch (_context3.n) {
|
|
162
161
|
case 0:
|
|
163
162
|
e.preventDefault();
|
|
164
163
|
e.stopPropagation();
|
|
165
164
|
run();
|
|
166
|
-
case
|
|
167
|
-
|
|
168
|
-
return _context3.stop();
|
|
165
|
+
case 1:
|
|
166
|
+
return _context3.a(2);
|
|
169
167
|
}
|
|
170
168
|
}, _callee3);
|
|
171
169
|
}));
|
|
@@ -173,45 +171,44 @@ export function CodeGenActionBtn(_ref) {
|
|
|
173
171
|
return _ref4.apply(this, arguments);
|
|
174
172
|
};
|
|
175
173
|
}();
|
|
176
|
-
var _useRequest2 = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/
|
|
177
|
-
var codeGen, blob, setCodeUpload;
|
|
178
|
-
return
|
|
179
|
-
while (1) switch (_context4.
|
|
174
|
+
var _useRequest2 = useRequest(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
175
|
+
var codeGen, blob, setCodeUpload, _t3;
|
|
176
|
+
return _regenerator().w(function (_context4) {
|
|
177
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
180
178
|
case 0:
|
|
181
179
|
codeGen = codeGenResultRef.current;
|
|
182
180
|
if (codeGen) {
|
|
183
|
-
_context4.
|
|
181
|
+
_context4.n = 1;
|
|
184
182
|
break;
|
|
185
183
|
}
|
|
186
|
-
return _context4.
|
|
187
|
-
case
|
|
188
|
-
_context4.
|
|
189
|
-
_context4.
|
|
184
|
+
return _context4.a(2);
|
|
185
|
+
case 1:
|
|
186
|
+
_context4.p = 1;
|
|
187
|
+
_context4.n = 2;
|
|
190
188
|
return codeGen.codeZip();
|
|
191
|
-
case
|
|
192
|
-
blob = _context4.
|
|
189
|
+
case 2:
|
|
190
|
+
blob = _context4.v;
|
|
193
191
|
setCodeUpload = ctx.config.get("setCodeUpload");
|
|
194
192
|
if (!setCodeUpload) {
|
|
195
|
-
_context4.
|
|
193
|
+
_context4.n = 3;
|
|
196
194
|
break;
|
|
197
195
|
}
|
|
198
|
-
_context4.
|
|
196
|
+
_context4.n = 3;
|
|
199
197
|
return setCodeUpload({
|
|
200
198
|
zipFile: blob
|
|
201
199
|
});
|
|
202
|
-
case
|
|
203
|
-
_context4.
|
|
200
|
+
case 3:
|
|
201
|
+
_context4.n = 5;
|
|
204
202
|
break;
|
|
205
|
-
case
|
|
206
|
-
_context4.
|
|
207
|
-
|
|
208
|
-
console.log("failed to git push: ",
|
|
203
|
+
case 4:
|
|
204
|
+
_context4.p = 4;
|
|
205
|
+
_t3 = _context4.v;
|
|
206
|
+
console.log("failed to git push: ", _t3);
|
|
209
207
|
_message.error("上传失败!");
|
|
210
|
-
case
|
|
211
|
-
|
|
212
|
-
return _context4.stop();
|
|
208
|
+
case 5:
|
|
209
|
+
return _context4.a(2);
|
|
213
210
|
}
|
|
214
|
-
}, _callee4, null, [[
|
|
211
|
+
}, _callee4, null, [[1, 4]]);
|
|
215
212
|
})), {
|
|
216
213
|
manual: true
|
|
217
214
|
}),
|
|
@@ -269,11 +266,11 @@ export function fixSchema(_x2) {
|
|
|
269
266
|
return _fixSchema.apply(this, arguments);
|
|
270
267
|
}
|
|
271
268
|
function _fixSchema() {
|
|
272
|
-
_fixSchema = _asyncToGenerator(/*#__PURE__*/
|
|
273
|
-
return
|
|
274
|
-
while (1) switch (_context5.
|
|
269
|
+
_fixSchema = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(schema) {
|
|
270
|
+
return _regenerator().w(function (_context5) {
|
|
271
|
+
while (1) switch (_context5.n) {
|
|
275
272
|
case 0:
|
|
276
|
-
return _context5.
|
|
273
|
+
return _context5.a(2, deepClone(_extends({}, schema, {
|
|
277
274
|
componentsMap: schema.componentsMap.filter(function (c) {
|
|
278
275
|
return c["package"];
|
|
279
276
|
}) // 去掉没有 package 的组件
|
|
@@ -295,9 +292,6 @@ function _fixSchema() {
|
|
|
295
292
|
return c;
|
|
296
293
|
})
|
|
297
294
|
})));
|
|
298
|
-
case 1:
|
|
299
|
-
case "end":
|
|
300
|
-
return _context5.stop();
|
|
301
295
|
}
|
|
302
296
|
}, _callee5);
|
|
303
297
|
}));
|
|
@@ -2,7 +2,8 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _Empty from "antd/es/empty";
|
|
3
3
|
import _message from "antd/es/message";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
|
-
|
|
5
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
6
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
6
7
|
import React, { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
|
7
8
|
import FileSaver from "file-saver";
|
|
8
9
|
import JSZip from "jszip";
|
|
@@ -28,24 +29,21 @@ export var CodeGenResult = /*#__PURE__*/forwardRef(function CodeGenResult(_ref,
|
|
|
28
29
|
setGravityCode(convertCodeGenResult(result, schema));
|
|
29
30
|
}, [result]);
|
|
30
31
|
var codeZip = /*#__PURE__*/function () {
|
|
31
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/
|
|
32
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
32
33
|
var zip;
|
|
33
|
-
return
|
|
34
|
-
while (1) switch (_context.
|
|
34
|
+
return _regenerator().w(function (_context) {
|
|
35
|
+
while (1) switch (_context.n) {
|
|
35
36
|
case 0:
|
|
36
37
|
zip = new JSZip();
|
|
37
38
|
Object.values((gravityCode === null || gravityCode === void 0 ? void 0 : gravityCode.modules) || {}).forEach(function (file) {
|
|
38
39
|
zip.file(file.fpath.replace(/^\/+/, ""), file.code);
|
|
39
40
|
});
|
|
40
|
-
_context.
|
|
41
|
+
_context.n = 1;
|
|
41
42
|
return zip.generateAsync({
|
|
42
43
|
type: "blob"
|
|
43
44
|
});
|
|
44
|
-
case
|
|
45
|
-
return _context.
|
|
46
|
-
case 5:
|
|
47
|
-
case "end":
|
|
48
|
-
return _context.stop();
|
|
45
|
+
case 1:
|
|
46
|
+
return _context.a(2, _context.v);
|
|
49
47
|
}
|
|
50
48
|
}, _callee);
|
|
51
49
|
}));
|
|
@@ -62,31 +60,30 @@ export var CodeGenResult = /*#__PURE__*/forwardRef(function CodeGenResult(_ref,
|
|
|
62
60
|
return null;
|
|
63
61
|
}
|
|
64
62
|
var handleDownloadSources = /*#__PURE__*/function () {
|
|
65
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/
|
|
66
|
-
var content;
|
|
67
|
-
return
|
|
68
|
-
while (1) switch (_context2.
|
|
63
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
|
|
64
|
+
var content, _t;
|
|
65
|
+
return _regenerator().w(function (_context2) {
|
|
66
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
69
67
|
case 0:
|
|
70
|
-
_context2.
|
|
68
|
+
_context2.p = 0;
|
|
71
69
|
e.preventDefault();
|
|
72
70
|
e.stopPropagation();
|
|
73
|
-
_context2.
|
|
71
|
+
_context2.n = 1;
|
|
74
72
|
return codeZip();
|
|
75
|
-
case
|
|
76
|
-
content = _context2.
|
|
73
|
+
case 1:
|
|
74
|
+
content = _context2.v;
|
|
77
75
|
FileSaver.saveAs(content, "gant-lowcode-generated-sources.zip");
|
|
78
|
-
_context2.
|
|
76
|
+
_context2.n = 3;
|
|
79
77
|
break;
|
|
80
|
-
case
|
|
81
|
-
_context2.
|
|
82
|
-
|
|
83
|
-
console.log("failed to download sources: ",
|
|
78
|
+
case 2:
|
|
79
|
+
_context2.p = 2;
|
|
80
|
+
_t = _context2.v;
|
|
81
|
+
console.log("failed to download sources: ", _t);
|
|
84
82
|
_message.error("下载失败!");
|
|
85
|
-
case
|
|
86
|
-
|
|
87
|
-
return _context2.stop();
|
|
83
|
+
case 3:
|
|
84
|
+
return _context2.a(2);
|
|
88
85
|
}
|
|
89
|
-
}, _callee2, null, [[0,
|
|
86
|
+
}, _callee2, null, [[0, 2]]);
|
|
90
87
|
}));
|
|
91
88
|
return function handleDownloadSources(_x) {
|
|
92
89
|
return _ref3.apply(this, arguments);
|
|
@@ -3,7 +3,8 @@ import _Alert from "antd/es/alert";
|
|
|
3
3
|
import _Button from "antd/es/button";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
5
|
import _extends from "@babel/runtime/helpers/extends";
|
|
6
|
-
|
|
6
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
7
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
7
8
|
import React, { useMemo, useState, useEffect } from "react";
|
|
8
9
|
import { fixPreviewCode } from "../code-gen-preview/fixPreviewCode";
|
|
9
10
|
import "./index.less";
|
|
@@ -57,16 +58,16 @@ export function CodeSandboxPreview(_ref) {
|
|
|
57
58
|
isCreating: true
|
|
58
59
|
});
|
|
59
60
|
});
|
|
60
|
-
_asyncToGenerator(/*#__PURE__*/
|
|
61
|
-
var sandboxId;
|
|
62
|
-
return
|
|
63
|
-
while (1) switch (_context.
|
|
61
|
+
_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
62
|
+
var sandboxId, _t;
|
|
63
|
+
return _regenerator().w(function (_context) {
|
|
64
|
+
while (1) switch (_context.p = _context.n) {
|
|
64
65
|
case 0:
|
|
65
|
-
_context.
|
|
66
|
-
_context.
|
|
66
|
+
_context.p = 0;
|
|
67
|
+
_context.n = 1;
|
|
67
68
|
return createCodeSandbox(parameters);
|
|
68
|
-
case
|
|
69
|
-
sandboxId = _context.
|
|
69
|
+
case 1:
|
|
70
|
+
sandboxId = _context.v;
|
|
70
71
|
if (!hasCanceled) {
|
|
71
72
|
setState(function (prev) {
|
|
72
73
|
return _extends({}, prev, {
|
|
@@ -76,25 +77,24 @@ export function CodeSandboxPreview(_ref) {
|
|
|
76
77
|
});
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
_context.
|
|
80
|
+
_context.n = 3;
|
|
80
81
|
break;
|
|
81
|
-
case
|
|
82
|
-
_context.
|
|
83
|
-
|
|
82
|
+
case 2:
|
|
83
|
+
_context.p = 2;
|
|
84
|
+
_t = _context.v;
|
|
84
85
|
if (!hasCanceled) {
|
|
85
86
|
setState(function (prev) {
|
|
86
87
|
return _extends({}, prev, {
|
|
87
88
|
hasError: true,
|
|
88
|
-
error:
|
|
89
|
+
error: _t,
|
|
89
90
|
isCreating: false
|
|
90
91
|
});
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
|
-
case
|
|
94
|
-
|
|
95
|
-
return _context.stop();
|
|
94
|
+
case 3:
|
|
95
|
+
return _context.a(2);
|
|
96
96
|
}
|
|
97
|
-
}, _callee, null, [[0,
|
|
97
|
+
}, _callee, null, [[0, 2]]);
|
|
98
98
|
}))();
|
|
99
99
|
return function () {
|
|
100
100
|
hasCanceled = true;
|
|
@@ -140,18 +140,18 @@ function createCodeSandbox(_x) {
|
|
|
140
140
|
return _createCodeSandbox.apply(this, arguments);
|
|
141
141
|
}
|
|
142
142
|
function _createCodeSandbox() {
|
|
143
|
-
_createCodeSandbox = _asyncToGenerator(/*#__PURE__*/
|
|
143
|
+
_createCodeSandbox = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(parameters) {
|
|
144
144
|
var res, json, _ref3, sandbox_id;
|
|
145
|
-
return
|
|
146
|
-
while (1) switch (_context2.
|
|
145
|
+
return _regenerator().w(function (_context2) {
|
|
146
|
+
while (1) switch (_context2.n) {
|
|
147
147
|
case 0:
|
|
148
148
|
if (Object.entries((parameters === null || parameters === void 0 ? void 0 : parameters.files) || {}).length) {
|
|
149
|
-
_context2.
|
|
149
|
+
_context2.n = 1;
|
|
150
150
|
break;
|
|
151
151
|
}
|
|
152
|
-
return _context2.
|
|
153
|
-
case
|
|
154
|
-
_context2.
|
|
152
|
+
return _context2.a(2, "");
|
|
153
|
+
case 1:
|
|
154
|
+
_context2.n = 2;
|
|
155
155
|
return fetch("https://codesandbox.io/api/v1/sandboxes/define?json=1", {
|
|
156
156
|
method: "POST",
|
|
157
157
|
headers: {
|
|
@@ -160,31 +160,28 @@ function _createCodeSandbox() {
|
|
|
160
160
|
},
|
|
161
161
|
body: JSON.stringify(parameters)
|
|
162
162
|
});
|
|
163
|
-
case
|
|
164
|
-
res = _context2.
|
|
163
|
+
case 2:
|
|
164
|
+
res = _context2.v;
|
|
165
165
|
if (res.ok) {
|
|
166
|
-
_context2.
|
|
166
|
+
_context2.n = 3;
|
|
167
167
|
break;
|
|
168
168
|
}
|
|
169
169
|
throw new Error("\u521B\u5EFA CodeSandbox \u5931\u8D25\uFF0C\u9519\u8BEF\u7801\uFF1A" + res.status + " " + res.statusText);
|
|
170
|
-
case
|
|
171
|
-
_context2.
|
|
170
|
+
case 3:
|
|
171
|
+
_context2.n = 4;
|
|
172
172
|
return res.json()["catch"](function (err) {
|
|
173
173
|
throw new Error("\u521B\u5EFA CodeSandbox \u5931\u8D25\uFF0C\u670D\u52A1\u5F02\u5E38(" + ((err === null || err === void 0 ? void 0 : err.message) || err || "未知异常") + ")");
|
|
174
174
|
});
|
|
175
|
-
case
|
|
176
|
-
json = _context2.
|
|
175
|
+
case 4:
|
|
176
|
+
json = _context2.v;
|
|
177
177
|
_ref3 = json || {}, sandbox_id = _ref3.sandbox_id;
|
|
178
178
|
if (!(!sandbox_id || typeof sandbox_id !== "string")) {
|
|
179
|
-
_context2.
|
|
179
|
+
_context2.n = 5;
|
|
180
180
|
break;
|
|
181
181
|
}
|
|
182
182
|
throw new Error("\u521B\u5EFA CodeSandbox \u5931\u8D25\uFF0C\u670D\u52A1\u54CD\u5E94\u5F02\u5E38");
|
|
183
|
-
case
|
|
184
|
-
return _context2.
|
|
185
|
-
case 14:
|
|
186
|
-
case "end":
|
|
187
|
-
return _context2.stop();
|
|
183
|
+
case 5:
|
|
184
|
+
return _context2.a(2, sandbox_id);
|
|
188
185
|
}
|
|
189
186
|
}, _callee2);
|
|
190
187
|
}));
|
package/es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
|
|
2
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
3
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
3
4
|
import * as CodeGenerator from "@gant-lowcode/code-generator/standalone-loader";
|
|
4
5
|
import { CodeGenActionBtn } from "./components/code-gen-action";
|
|
5
6
|
var plugin = function plugin(ctx, options) {
|
|
@@ -12,11 +13,12 @@ var plugin = function plugin(ctx, options) {
|
|
|
12
13
|
},
|
|
13
14
|
// 插件的初始化函数,在引擎初始化之后会立刻调用
|
|
14
15
|
init: function init() {
|
|
15
|
-
return _asyncToGenerator(/*#__PURE__*/
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
17
|
+
var _t;
|
|
18
|
+
return _regenerator().w(function (_context) {
|
|
19
|
+
while (1) switch (_context.p = _context.n) {
|
|
18
20
|
case 0:
|
|
19
|
-
_context.
|
|
21
|
+
_context.p = 0;
|
|
20
22
|
if (!(options !== null && options !== void 0 && options.disableCodeGenActionBtn)) {
|
|
21
23
|
ctx.skeleton.add({
|
|
22
24
|
type: "Custom",
|
|
@@ -35,18 +37,17 @@ var plugin = function plugin(ctx, options) {
|
|
|
35
37
|
|
|
36
38
|
// 提前初始化下,这样后面用的时候更快
|
|
37
39
|
CodeGenerator.init();
|
|
38
|
-
_context.
|
|
40
|
+
_context.n = 2;
|
|
39
41
|
break;
|
|
40
|
-
case
|
|
41
|
-
_context.
|
|
42
|
-
|
|
43
|
-
console.error("[plugin-code-geneator] failed to init: ",
|
|
44
|
-
throw
|
|
45
|
-
case
|
|
46
|
-
|
|
47
|
-
return _context.stop();
|
|
42
|
+
case 1:
|
|
43
|
+
_context.p = 1;
|
|
44
|
+
_t = _context.v;
|
|
45
|
+
console.error("[plugin-code-geneator] failed to init: ", _t);
|
|
46
|
+
throw _t;
|
|
47
|
+
case 2:
|
|
48
|
+
return _context.a(2);
|
|
48
49
|
}
|
|
49
|
-
}, _callee, null, [[0,
|
|
50
|
+
}, _callee, null, [[0, 1]]);
|
|
50
51
|
}))();
|
|
51
52
|
},
|
|
52
53
|
destroy: function destroy() {}
|