@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,56 @@
|
|
|
1
|
+
body {
|
|
2
|
+
font-family: PingFangSC-Regular, Roboto, Helvetica Neue, Helvetica, Tahoma, Arial, PingFang SC-Light, Microsoft YaHei;
|
|
3
|
+
font-size: 12px;
|
|
4
|
+
* {
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
body,
|
|
10
|
+
#lce-container {
|
|
11
|
+
position: fixed;
|
|
12
|
+
left: 0;
|
|
13
|
+
right: 0;
|
|
14
|
+
bottom: 0;
|
|
15
|
+
top: 0;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
padding: 0;
|
|
18
|
+
margin: 0;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
text-rendering: optimizeLegibility;
|
|
21
|
+
-webkit-user-select: none;
|
|
22
|
+
-webkit-user-drag: none;
|
|
23
|
+
-webkit-text-size-adjust: none;
|
|
24
|
+
-webkit-touch-callout: none;
|
|
25
|
+
-webkit-font-smoothing: antialiased;
|
|
26
|
+
#engine {
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: 100%;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
html {
|
|
33
|
+
min-width: 1024px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.save-sample {
|
|
37
|
+
width: 80px;
|
|
38
|
+
height: 30px;
|
|
39
|
+
background-color: #5584ff;
|
|
40
|
+
border: none;
|
|
41
|
+
outline: none;
|
|
42
|
+
border-radius: 4px;
|
|
43
|
+
color: white;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.load-assets {
|
|
48
|
+
width: 100px;
|
|
49
|
+
height: 30px;
|
|
50
|
+
background-color: #5584ff;
|
|
51
|
+
border: none;
|
|
52
|
+
outline: none;
|
|
53
|
+
border-radius: 4px;
|
|
54
|
+
color: white;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
}
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as CodeGenerator from '@dckj-npm/lowcode-code-generator/standalone-loader';
|
|
2
|
+
export interface ICodeGenPlugin {
|
|
3
|
+
generateCode: typeof CodeGenerator.generateCode;
|
|
4
|
+
}
|
|
5
|
+
export declare type CodeGenPluginOptions = {
|
|
6
|
+
/** 是否要禁用出码的动作按钮(默认: 否) */
|
|
7
|
+
disableCodeGenActionBtn?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const codeGeneratorPlugin: {
|
|
10
|
+
(ctx: any, options?: CodeGenPluginOptions): {
|
|
11
|
+
exports(): {
|
|
12
|
+
generateCode: typeof CodeGenerator.generateCode;
|
|
13
|
+
};
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
};
|
|
17
|
+
pluginName: string;
|
|
18
|
+
meta: {
|
|
19
|
+
dependencies: any[];
|
|
20
|
+
preferenceDeclaration: {
|
|
21
|
+
title: string;
|
|
22
|
+
properties: {
|
|
23
|
+
key: string;
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export default codeGeneratorPlugin;
|
package/es/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import * as CodeGenerator from '@dckj-npm/lowcode-code-generator/standalone-loader';
|
|
4
|
+
import { CodeGenActionBtn } from './components/CodeGenActionBtn';
|
|
5
|
+
var codeGeneratorPlugin = function codeGeneratorPlugin(ctx, options) {
|
|
6
|
+
return {
|
|
7
|
+
// 插件对外暴露的数据和方法
|
|
8
|
+
exports: function exports() {
|
|
9
|
+
return {
|
|
10
|
+
generateCode: CodeGenerator.generateCode
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
// 插件的初始化函数,在引擎初始化之后会立刻调用
|
|
14
|
+
init: function init() {
|
|
15
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
16
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
17
|
+
while (1) switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
_context.prev = 0;
|
|
20
|
+
if (!(options !== null && options !== void 0 && options.disableCodeGenActionBtn)) {
|
|
21
|
+
ctx.skeleton.add({
|
|
22
|
+
type: 'Custom',
|
|
23
|
+
name: 'code-generator',
|
|
24
|
+
area: 'topArea',
|
|
25
|
+
props: {
|
|
26
|
+
align: 'right',
|
|
27
|
+
width: 100
|
|
28
|
+
},
|
|
29
|
+
content: CodeGenActionBtn,
|
|
30
|
+
contentProps: {
|
|
31
|
+
ctx: ctx
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 提前初始化下,这样后面用的时候更快
|
|
37
|
+
CodeGenerator.init();
|
|
38
|
+
_context.next = 9;
|
|
39
|
+
break;
|
|
40
|
+
case 5:
|
|
41
|
+
_context.prev = 5;
|
|
42
|
+
_context.t0 = _context["catch"](0);
|
|
43
|
+
console.error('[plugin-code-geneator] failed to init: ', _context.t0);
|
|
44
|
+
throw _context.t0;
|
|
45
|
+
case 9:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}, _callee, null, [[0, 5]]);
|
|
50
|
+
}))();
|
|
51
|
+
},
|
|
52
|
+
destroy: function destroy() {}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
codeGeneratorPlugin.pluginName = 'codeGenerator';
|
|
56
|
+
codeGeneratorPlugin.meta = {
|
|
57
|
+
dependencies: [],
|
|
58
|
+
preferenceDeclaration: {
|
|
59
|
+
title: 'codeGenerator 的参数定义',
|
|
60
|
+
properties: [{
|
|
61
|
+
key: 'disableCodeGenActionBtn',
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
description: '是否要禁用出码的动作按钮'
|
|
64
|
+
}]
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export default codeGeneratorPlugin;
|
package/es/style.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SyncCodeGenResult';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SyncCodeGenResult';
|
package/es/typings.d.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import './CodeGenActionBtn.scss';
|
|
3
|
+
import type { ILowCodePluginContext } from '@alilc/lowcode-engine';
|
|
4
|
+
import { ProjectSchema } from '@alilc/lowcode-types';
|
|
5
|
+
export declare function CodeGenActionBtn({ ctx }: {
|
|
6
|
+
ctx: ILowCodePluginContext;
|
|
7
|
+
}): JSX.Element;
|
|
8
|
+
export declare function fixSchema(schema: ProjectSchema): Promise<ProjectSchema>;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.CodeGenActionBtn = CodeGenActionBtn;
|
|
6
|
+
exports.fixSchema = fixSchema;
|
|
7
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
require("./CodeGenActionBtn.scss");
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var CodeGenerator = _interopRequireWildcard(require("@dckj-npm/lowcode-code-generator/standalone-loader"));
|
|
13
|
+
var _lowcodeTypes = require("@alilc/lowcode-types");
|
|
14
|
+
var _next = require("@alifd/next");
|
|
15
|
+
var _coerce = _interopRequireDefault(require("semver/functions/coerce"));
|
|
16
|
+
var _CodeGenResult = require("../CodeGenResult");
|
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
19
|
+
function CodeGenActionBtn(_ref) {
|
|
20
|
+
var ctx = _ref.ctx;
|
|
21
|
+
var _useState = (0, _react.useState)({
|
|
22
|
+
visible: false,
|
|
23
|
+
hasError: false,
|
|
24
|
+
error: null,
|
|
25
|
+
loading: false,
|
|
26
|
+
result: null,
|
|
27
|
+
schema: null,
|
|
28
|
+
originalSchema: null
|
|
29
|
+
}),
|
|
30
|
+
state = _useState[0],
|
|
31
|
+
setState = _useState[1];
|
|
32
|
+
var handleClick = /*#__PURE__*/function () {
|
|
33
|
+
var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
34
|
+
var originalSchema, schema, result;
|
|
35
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
36
|
+
while (1) switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
_context.prev = 0;
|
|
39
|
+
// 打开基于 Gravity 的编辑器/出码预览器
|
|
40
|
+
setState(function (prev) {
|
|
41
|
+
return (0, _extends2["default"])({}, prev, {
|
|
42
|
+
loading: true,
|
|
43
|
+
visible: true,
|
|
44
|
+
hasError: false
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// 获取 schema,并修正
|
|
49
|
+
_context.next = 4;
|
|
50
|
+
return ctx.project.exportSchema(_lowcodeTypes.TransformStage.Save);
|
|
51
|
+
case 4:
|
|
52
|
+
originalSchema = _context.sent;
|
|
53
|
+
_context.next = 7;
|
|
54
|
+
return fixSchema(originalSchema);
|
|
55
|
+
case 7:
|
|
56
|
+
schema = _context.sent;
|
|
57
|
+
console.log('got schema:222222 ', schema);
|
|
58
|
+
setState(function (prev) {
|
|
59
|
+
return (0, _extends2["default"])({}, prev, {
|
|
60
|
+
schema: schema,
|
|
61
|
+
originalSchema: originalSchema
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 出码...
|
|
66
|
+
_context.next = 12;
|
|
67
|
+
return CodeGenerator.generateCode({
|
|
68
|
+
solution: 'vuejs3',
|
|
69
|
+
schema: schema,
|
|
70
|
+
flattenResult: true
|
|
71
|
+
});
|
|
72
|
+
case 12:
|
|
73
|
+
result = _context.sent;
|
|
74
|
+
console.log('generated: ', result);
|
|
75
|
+
setState(function (prev) {
|
|
76
|
+
return (0, _extends2["default"])({}, prev, {
|
|
77
|
+
loading: false,
|
|
78
|
+
result: result
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
_context.next = 21;
|
|
82
|
+
break;
|
|
83
|
+
case 17:
|
|
84
|
+
_context.prev = 17;
|
|
85
|
+
_context.t0 = _context["catch"](0);
|
|
86
|
+
console.error('failed to run code generator: ', _context.t0);
|
|
87
|
+
setState(function (prev) {
|
|
88
|
+
return (0, _extends2["default"])({}, prev, {
|
|
89
|
+
hasError: true,
|
|
90
|
+
error: _context.t0 instanceof Error ? _context.t0 : new Error("" + ((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message) || _context.t0))
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
case 21:
|
|
94
|
+
case "end":
|
|
95
|
+
return _context.stop();
|
|
96
|
+
}
|
|
97
|
+
}, _callee, null, [[0, 17]]);
|
|
98
|
+
}));
|
|
99
|
+
return function handleClick() {
|
|
100
|
+
return _ref2.apply(this, arguments);
|
|
101
|
+
};
|
|
102
|
+
}();
|
|
103
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_next.Button, {
|
|
104
|
+
type: "primary",
|
|
105
|
+
onClick: handleClick
|
|
106
|
+
}, "\u51FA\u7801"), /*#__PURE__*/_react["default"].createElement(_next.Drawer, {
|
|
107
|
+
visible: state.visible,
|
|
108
|
+
title: "\u51FA\u7801\u7ED3\u679C",
|
|
109
|
+
width: "95vw",
|
|
110
|
+
onClose: function onClose() {
|
|
111
|
+
setState(function (prev) {
|
|
112
|
+
return (0, _extends2["default"])({}, prev, {
|
|
113
|
+
visible: false
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
118
|
+
className: "code-gen-plugin-result"
|
|
119
|
+
}, function () {
|
|
120
|
+
if (state.hasError) {
|
|
121
|
+
var _state$error;
|
|
122
|
+
return /*#__PURE__*/_react["default"].createElement(_next.Message, {
|
|
123
|
+
type: "error",
|
|
124
|
+
title: "\u51FA\u9519\u4E86"
|
|
125
|
+
}, (_state$error = state.error) === null || _state$error === void 0 ? void 0 : _state$error.message);
|
|
126
|
+
}
|
|
127
|
+
if (state.loading) {
|
|
128
|
+
return /*#__PURE__*/_react["default"].createElement(_next.Loading, {
|
|
129
|
+
className: "code-gen-plugin-loading",
|
|
130
|
+
tip: "\u6B63\u5728\u51FA\u7801..."
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return /*#__PURE__*/_react["default"].createElement(_CodeGenResult.CodeGenResult, {
|
|
134
|
+
result: state.result,
|
|
135
|
+
schema: state.schema,
|
|
136
|
+
originalSchema: state.originalSchema
|
|
137
|
+
});
|
|
138
|
+
}())));
|
|
139
|
+
}
|
|
140
|
+
function fixSchema(_x) {
|
|
141
|
+
return _fixSchema.apply(this, arguments);
|
|
142
|
+
}
|
|
143
|
+
function _fixSchema() {
|
|
144
|
+
_fixSchema = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(schema) {
|
|
145
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
146
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
147
|
+
case 0:
|
|
148
|
+
return _context2.abrupt("return", deepClone((0, _extends2["default"])({}, schema, {
|
|
149
|
+
componentsMap: schema.componentsMap.filter(function (c) {
|
|
150
|
+
return c["package"];
|
|
151
|
+
}) // 去掉没有 package 的组件
|
|
152
|
+
.map(function (c) {
|
|
153
|
+
// 修正版本号(对于没有有效版本号的组件,默认使用 latest)
|
|
154
|
+
if (!isValidVersion(c.version)) {
|
|
155
|
+
console.warn('[WARN] got invalid version "%o" for component "%s", use "latest" as fallback', c.version, c);
|
|
156
|
+
return (0, _extends2["default"])({}, c, {
|
|
157
|
+
version: 'latest'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 修正 @alifd/pro-layout 的版本
|
|
162
|
+
// -- 这个包没有 ^0.1.0 的版本,这里暂且替换下
|
|
163
|
+
if (c["package"] === '@alifd/pro-layout' && c.version === '^0.1.0') {
|
|
164
|
+
console.warn('[WARN] got invalid version "%o" for "@alifd/pro-layout"! use "latest" as fallback', c.version);
|
|
165
|
+
return (0, _extends2["default"])({}, c, {
|
|
166
|
+
version: 'latest'
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return c;
|
|
170
|
+
})
|
|
171
|
+
})));
|
|
172
|
+
case 1:
|
|
173
|
+
case "end":
|
|
174
|
+
return _context2.stop();
|
|
175
|
+
}
|
|
176
|
+
}, _callee2);
|
|
177
|
+
}));
|
|
178
|
+
return _fixSchema.apply(this, arguments);
|
|
179
|
+
}
|
|
180
|
+
function deepClone(x) {
|
|
181
|
+
try {
|
|
182
|
+
return JSON.parse(JSON.stringify(x));
|
|
183
|
+
} catch (e) {
|
|
184
|
+
throw new Error("failed to clone schema -- " + e);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function isValidVersion(version) {
|
|
188
|
+
if (!version) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// 对于一些明显非法的版本号过滤下
|
|
193
|
+
if (version === '{{version}}' || version === 'null' || version === 'undefined') {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 对于 latest/beta/rc 这样的 tag 版本号要支持下
|
|
198
|
+
if (/^[a-z][a-z0-9]+([a-z0-9-]+)?$/i.test(version)) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 最后支持下所有 semver 能识别的版本
|
|
203
|
+
return (0, _coerce["default"])(version) !== null;
|
|
204
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeGenActionBtn';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var _CodeGenActionBtn = require("./CodeGenActionBtn");
|
|
5
|
+
Object.keys(_CodeGenActionBtn).forEach(function (key) {
|
|
6
|
+
if (key === "default" || key === "__esModule") return;
|
|
7
|
+
if (key in exports && exports[key] === _CodeGenActionBtn[key]) return;
|
|
8
|
+
exports[key] = _CodeGenActionBtn[key];
|
|
9
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GravityCode } from '../GravityCode';
|
|
2
|
+
import './CodeGenPreview.scss';
|
|
3
|
+
export declare type CodeGenPreviewProps = {
|
|
4
|
+
code: GravityCode | null;
|
|
5
|
+
height: string | number;
|
|
6
|
+
refresh: string | number;
|
|
7
|
+
};
|
|
8
|
+
export declare function CodeGenPreview(props: CodeGenPreviewProps): any;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.CodeGenPreview = CodeGenPreview;
|
|
6
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
|
+
var _next = require("@alifd/next");
|
|
8
|
+
var _useIsInIntranet = require("./useIsInIntranet");
|
|
9
|
+
var _GravityPreview = require("../GravityPreview");
|
|
10
|
+
var _CodeSandboxPreview = require("../CodeSandboxPreview");
|
|
11
|
+
var _ForceUpdate = require("../GravityPreview/ForceUpdate");
|
|
12
|
+
require("./CodeGenPreview.scss");
|
|
13
|
+
function CodeGenPreview(props) {
|
|
14
|
+
var isInIntranet = (0, _useIsInIntranet.useIsInIntranet)();
|
|
15
|
+
var previewPanes = [{
|
|
16
|
+
title: '基于 Gravity 预览',
|
|
17
|
+
available: isInIntranet,
|
|
18
|
+
render: function render() {
|
|
19
|
+
return /*#__PURE__*/_react["default"].createElement(_GravityPreview.GravityPreview, props);
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
title: '基于 CodeSandbox 预览',
|
|
23
|
+
available: true,
|
|
24
|
+
render: function render() {
|
|
25
|
+
return /*#__PURE__*/_react["default"].createElement(_CodeSandboxPreview.CodeSandboxPreview, props);
|
|
26
|
+
}
|
|
27
|
+
}];
|
|
28
|
+
var availablePreviewPanes = previewPanes.filter(function (pane) {
|
|
29
|
+
return pane.available;
|
|
30
|
+
});
|
|
31
|
+
if (availablePreviewPanes.length === 1) {
|
|
32
|
+
return availablePreviewPanes[0].render();
|
|
33
|
+
}
|
|
34
|
+
return /*#__PURE__*/_react["default"].createElement(_next.Tab, {
|
|
35
|
+
className: "code-gen-preview-tabs",
|
|
36
|
+
size: "small"
|
|
37
|
+
}, availablePreviewPanes.map(function (pane) {
|
|
38
|
+
return /*#__PURE__*/_react["default"].createElement(_next.Tab.Item, {
|
|
39
|
+
title: pane.title,
|
|
40
|
+
key: pane.title
|
|
41
|
+
}, /*#__PURE__*/_react["default"].createElement(_ForceUpdate.ForceUpdate, {
|
|
42
|
+
watchKey: props.refresh
|
|
43
|
+
}, pane.render()));
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.fixPreviewCode = fixPreviewCode;
|
|
6
|
+
var _extends4 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
7
|
+
// 默认生成的代码不符合在线预览的规则,需要处理下
|
|
8
|
+
function fixPreviewCode(code, unused) {
|
|
9
|
+
var _JSON$parse, _fixedCode$modules$P;
|
|
10
|
+
if (!code) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
var fixedModules = Object.entries(code.modules || {})
|
|
14
|
+
// 去掉隐藏文件和 html 以及 md 等无用文件:
|
|
15
|
+
.filter(function (_ref) {
|
|
16
|
+
var fpath = _ref[0];
|
|
17
|
+
return !fpath.startsWith('/.') && !fpath.endsWith('.html') && !fpath.endsWith('.md');
|
|
18
|
+
})
|
|
19
|
+
// 所有的 jsx 文件改成 js 文件(因为 gravity 不支持 jsx)
|
|
20
|
+
.map(function (_ref2) {
|
|
21
|
+
var fpath = _ref2[0],
|
|
22
|
+
module = _ref2[1];
|
|
23
|
+
return [fpath.replace(/\.jsx$/, '.js'), module];
|
|
24
|
+
}).map(function (_ref3) {
|
|
25
|
+
var fpath = _ref3[0],
|
|
26
|
+
module = _ref3[1];
|
|
27
|
+
return [fpath.replace(/\.scss$/, '.css'), module];
|
|
28
|
+
}).reduce(function (acc, _ref4) {
|
|
29
|
+
var _extends2;
|
|
30
|
+
var fpath = _ref4[0],
|
|
31
|
+
module = _ref4[1];
|
|
32
|
+
return (0, _extends4["default"])({}, acc, (_extends2 = {}, _extends2[fpath] = (0, _extends4["default"])({}, module, {
|
|
33
|
+
fpath: fpath,
|
|
34
|
+
code: module.code
|
|
35
|
+
// 所有的 import xxx from '@/yyy' 转换为 import xxx from '/src/yyy'
|
|
36
|
+
.replace(/import\s+([^\s]+)\s+from\s+['"]@\/([^'"]+)['"]/g, function (_, name, path) {
|
|
37
|
+
return "import " + name + " from '/src/" + path + "'";
|
|
38
|
+
})
|
|
39
|
+
// 所有的 import styles from 'xxx.scss' 转换为 import styles from '/src/xxx.css'
|
|
40
|
+
.replace(/import\s+([^\s]+)\s+from\s+['"]([^'"]+)\.scss['"]/g, function (_, name, path) {
|
|
41
|
+
return "import " + name + " from '" + path + ".css'";
|
|
42
|
+
})
|
|
43
|
+
}), _extends2));
|
|
44
|
+
}, {});
|
|
45
|
+
var fixedCode = (0, _extends4["default"])({}, code, {
|
|
46
|
+
modules: fixedModules
|
|
47
|
+
});
|
|
48
|
+
fixedCode.modules['/src/app.js'] = (0, _extends4["default"])({}, fixedCode.modules['/src/app.js'], {
|
|
49
|
+
code: "\n// \u6CE8\u610F\uFF1A\u4E3A\u4E86\u65B9\u4FBF\u5728\u6D4F\u89C8\u5668\u4E2D\u8FDB\u884C\u9884\u89C8\uFF0C\u8FD9\u91CC\u7B80\u5316\u4E86\u4E00\u4E9B\u5185\u5BB9\nimport './shims';\nimport './global.css';\n\nimport React from 'react';\nimport ReactDOM from 'react-dom';\n\nimport Page from '" + Object.keys(fixedModules).find(function (fpath) {
|
|
50
|
+
return fpath.startsWith('/src/pages/');
|
|
51
|
+
}) + "';\n\nReactDOM.render(<Page/>, document.getElementById('root'));\n"
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 一些垫片,用于解决一些不能被 gravity 解析的问题
|
|
55
|
+
// 1. @alilc/lowcode-materials 中有部分代码直接使用了全局变量 PropTypes...
|
|
56
|
+
fixedCode.modules['/src/shims.js'] = {
|
|
57
|
+
fpath: '/src/shims.js',
|
|
58
|
+
code: "\n// \u4E00\u4E9B\u57AB\u7247\u4EE3\u7801\uFF0C\u7528\u6765\u89E3\u51B3\u76F4\u63A5\u5728\u6D4F\u89C8\u5668\u4E2D\u9884\u89C8\u7684\u65F6\u5019\u7684\u95EE\u9898\nimport PropTypes from 'prop-types';\n\nwindow.PropTypes = PropTypes;\n"
|
|
59
|
+
};
|
|
60
|
+
fixedCode.modules['/package.json'] = (0, _extends4["default"])({}, fixedCode.modules['/package.json'], {
|
|
61
|
+
code: JSON.stringify({
|
|
62
|
+
name: 'demo',
|
|
63
|
+
version: '1.0.0',
|
|
64
|
+
dependencies: (0, _extends4["default"])({
|
|
65
|
+
react: '^16.8.3',
|
|
66
|
+
'react-dom': '^16.8.3'
|
|
67
|
+
}, (_JSON$parse = JSON.parse(((_fixedCode$modules$P = fixedCode.modules['/package.json']) === null || _fixedCode$modules$P === void 0 ? void 0 : _fixedCode$modules$P.code) || '{}')) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.dependencies)
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
fixedCode.modules = pickKeys(fixedCode.modules, [
|
|
71
|
+
// '/tsconfig.json',
|
|
72
|
+
// '/jsconfig.json',
|
|
73
|
+
// '/build.json',
|
|
74
|
+
// '/abc.json',
|
|
75
|
+
'/package.json', '/src/routes.js', '/src/app.js', '/src/constants.js', '/src/utils.js', '/src/i18n.js', '/src/global.css', '/src/index.js', '/src/shims.js'].concat(Object.keys(fixedModules).filter(function (fpath) {
|
|
76
|
+
return fpath.startsWith('/src/pages/');
|
|
77
|
+
})));
|
|
78
|
+
fixedCode.modules['/src/routes.js'] = (0, _extends4["default"])({}, fixedCode.modules['/src/routes.js'], {
|
|
79
|
+
code: "\n"
|
|
80
|
+
});
|
|
81
|
+
fixedCode.modules['/src/global.css'] = {
|
|
82
|
+
fpath: '/src/global.css',
|
|
83
|
+
code: "\nbody {\n -webkit-font-smoothing: antialiased;\n}\n"
|
|
84
|
+
};
|
|
85
|
+
Object.assign(fixedCode.modules, {
|
|
86
|
+
'/src/index.html': {
|
|
87
|
+
code: '<div id="root"></div>',
|
|
88
|
+
fpath: '/src/index.html'
|
|
89
|
+
},
|
|
90
|
+
'/src/index.less': {
|
|
91
|
+
fpath: '/src/index.less',
|
|
92
|
+
code: "\n@import \"~@alifd/next/dist/next.css\";\n@import '~@alifd/pro-layout/dist/AlifdProLayout.css';\n"
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
fixedCode.type = 'riddle';
|
|
96
|
+
return fixedCode;
|
|
97
|
+
}
|
|
98
|
+
function pickKeys(data, keys) {
|
|
99
|
+
return keys.reduce(function (acc, key) {
|
|
100
|
+
if (data[key]) {
|
|
101
|
+
var _extends3;
|
|
102
|
+
return (0, _extends4["default"])({}, acc, (_extends3 = {}, _extends3[key] = data[key], _extends3));
|
|
103
|
+
}
|
|
104
|
+
return acc;
|
|
105
|
+
}, {});
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeGenPreview';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var _CodeGenPreview = require("./CodeGenPreview");
|
|
5
|
+
Object.keys(_CodeGenPreview).forEach(function (key) {
|
|
6
|
+
if (key === "default" || key === "__esModule") return;
|
|
7
|
+
if (key in exports && exports[key] === _CodeGenPreview[key]) return;
|
|
8
|
+
exports[key] = _CodeGenPreview[key];
|
|
9
|
+
});
|