@gant-lowcode/plugin-code-generator 1.0.9 → 2.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/{dist → es}/components/code-gen-action/index.d.ts +2 -1
  3. package/es/components/code-gen-action/index.js +330 -0
  4. package/es/components/code-gen-action/index.less +20 -0
  5. package/es/components/code-gen-preview/fixPreviewCode.js +100 -0
  6. package/{dist → es}/components/code-gen-preview/index.d.ts +3 -2
  7. package/es/components/code-gen-preview/index.js +5 -0
  8. package/es/components/code-gen-preview/index.less +16 -0
  9. package/{dist → es}/components/code-gen-result/index.d.ts +2 -2
  10. package/es/components/code-gen-result/index.js +207 -0
  11. package/es/components/code-gen-result/index.less +20 -0
  12. package/{dist → es}/components/codesandbox-preview/index.d.ts +2 -1
  13. package/es/components/codesandbox-preview/index.js +192 -0
  14. package/es/components/codesandbox-preview/index.less +18 -0
  15. package/{dist → es}/components/file-tree/index.d.ts +3 -2
  16. package/es/components/file-tree/index.js +162 -0
  17. package/es/components/file-tree/index.less +54 -0
  18. package/{dist → es}/components/file-type-icon/index.d.ts +2 -2
  19. package/es/components/file-type-icon/index.js +12 -0
  20. package/es/components/file-type-icon/index.less +77 -0
  21. package/{dist → es}/components/sources-view/index.d.ts +2 -1
  22. package/es/components/sources-view/index.js +128 -0
  23. package/es/components/sources-view/index.less +12 -0
  24. package/{dist → es}/index.d.ts +3 -4
  25. package/es/index.js +67 -0
  26. package/es/style.js +9 -0
  27. package/{dist → es}/types/index.d.ts +3 -3
  28. package/es/types/index.js +1 -0
  29. package/lib/components/code-gen-action/index.d.ts +7 -0
  30. package/lib/components/code-gen-action/index.js +336 -0
  31. package/lib/components/code-gen-action/index.less +20 -0
  32. package/lib/components/code-gen-preview/fixPreviewCode.d.ts +2 -0
  33. package/lib/components/code-gen-preview/fixPreviewCode.js +105 -0
  34. package/lib/components/code-gen-preview/index.d.ts +9 -0
  35. package/lib/components/code-gen-preview/index.js +9 -0
  36. package/lib/components/code-gen-preview/index.less +16 -0
  37. package/lib/components/code-gen-result/index.d.ts +14 -0
  38. package/lib/components/code-gen-result/index.js +215 -0
  39. package/lib/components/code-gen-result/index.less +20 -0
  40. package/lib/components/codesandbox-preview/index.d.ts +4 -0
  41. package/lib/components/codesandbox-preview/index.js +199 -0
  42. package/lib/components/codesandbox-preview/index.less +18 -0
  43. package/lib/components/file-tree/index.d.ts +21 -0
  44. package/lib/components/file-tree/index.js +170 -0
  45. package/lib/components/file-tree/index.less +54 -0
  46. package/lib/components/file-type-icon/index.d.ts +6 -0
  47. package/lib/components/file-type-icon/index.js +17 -0
  48. package/lib/components/file-type-icon/index.less +77 -0
  49. package/lib/components/sources-view/index.d.ts +8 -0
  50. package/lib/components/sources-view/index.js +135 -0
  51. package/lib/components/sources-view/index.less +12 -0
  52. package/lib/index.d.ts +27 -0
  53. package/lib/index.js +74 -0
  54. package/lib/style.js +9 -0
  55. package/lib/types/index.d.ts +17 -0
  56. package/lib/types/index.js +3 -0
  57. package/package.json +27 -19
  58. package/dist/components/code-gen-action/index.css +0 -18
  59. package/dist/components/code-gen-action/index.js +0 -203
  60. package/dist/components/code-gen-preview/fixPreviewCode.js +0 -119
  61. package/dist/components/code-gen-preview/index.css +0 -18
  62. package/dist/components/code-gen-preview/index.js +0 -9
  63. package/dist/components/code-gen-result/index.css +0 -18
  64. package/dist/components/code-gen-result/index.js +0 -147
  65. package/dist/components/codesandbox-preview/index.css +0 -17
  66. package/dist/components/codesandbox-preview/index.js +0 -147
  67. package/dist/components/file-tree/index.css +0 -55
  68. package/dist/components/file-tree/index.js +0 -138
  69. package/dist/components/file-type-icon/index.css +0 -73
  70. package/dist/components/file-type-icon/index.js +0 -10
  71. package/dist/components/sources-view/index.css +0 -11
  72. package/dist/components/sources-view/index.js +0 -128
  73. package/dist/index.js +0 -50
  74. package/dist/types/index.js +0 -1
  75. /package/{dist → es}/components/code-gen-preview/fixPreviewCode.d.ts +0 -0
@@ -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 './index.less';
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,77 @@
1
+ @font-face {
2
+ font-family: "file-types-iconfont"; /* Project id 4778352 */
3
+ /* Color fonts */
4
+ src:
5
+ url('//at.alicdn.com/t/c/font_4778352_c4wg236tblh.woff2?t=1734587113843') format('woff2'),
6
+ url('//at.alicdn.com/t/c/font_4778352_c4wg236tblh.woff?t=1734587113843') format('woff'),
7
+ url('//at.alicdn.com/t/c/font_4778352_c4wg236tblh.ttf?t=1734587113843') format('truetype');
8
+ }
9
+
10
+ .file-types-iconfont {
11
+ font-family: "file-types-iconfont" !important;
12
+ font-size: 14px;
13
+ font-style: normal;
14
+ -webkit-font-smoothing: antialiased;
15
+ -moz-osx-font-smoothing: grayscale;
16
+ }
17
+
18
+ .file-types-icon-css:before {
19
+ content: "\e61e";
20
+ }
21
+
22
+ .file-types-icon-editorconfig:before {
23
+ content: "\e628";
24
+ }
25
+
26
+ .file-types-icon-eslintignore:before {
27
+ content: "\e62a";
28
+ }
29
+
30
+ .file-types-icon-gitignore:before {
31
+ content: "\e62d";
32
+ }
33
+
34
+ .file-types-icon-git:before {
35
+ content: "\e897";
36
+ }
37
+
38
+ .file-types-icon-html:before {
39
+ content: "\e68c";
40
+ }
41
+
42
+ .file-types-icon-tsconfig:before {
43
+ content: "\e622";
44
+ }
45
+
46
+ .file-types-icon-less:before {
47
+ content: "\e63d";
48
+ }
49
+
50
+ .file-types-icon-scss:before {
51
+ content: "\e657";
52
+ }
53
+
54
+ .file-types-icon-json:before {
55
+ content: "\e7bd";
56
+ }
57
+
58
+ .file-types-icon-text:before {
59
+ content: "\e734";
60
+ }
61
+
62
+ .file-types-icon-js:before {
63
+ content: "\e63b";
64
+ }
65
+
66
+ .file-types-icon-jsx:before {
67
+ content: "\e63c";
68
+ }
69
+
70
+ .file-types-icon-ts:before {
71
+ content: "\e664";
72
+ }
73
+
74
+ .file-types-icon-tsx:before {
75
+ content: "\e665";
76
+ }
77
+
@@ -1,7 +1,8 @@
1
+ /// <reference types="react" />
1
2
  import "@gant-lowcode/lowcode-plugin-base-monaco-editor/lib/style.js";
2
3
  import { GravityCode } from "../../types";
3
4
  import "./index.less";
4
5
  export declare function SourcesView({ code, onCodeChange, }: {
5
6
  code: GravityCode;
6
7
  onCodeChange: (code: GravityCode) => void;
7
- }): import("react/jsx-runtime").JSX.Element;
8
+ }): JSX.Element;
@@ -0,0 +1,128 @@
1
+ import _Splitter from "antd/es/splitter";
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import React, { useEffect, useRef, useState } from "react";
4
+ import Editor from "@gant-lowcode/lowcode-plugin-base-monaco-editor";
5
+ import "@gant-lowcode/lowcode-plugin-base-monaco-editor/lib/style.js";
6
+ import { FileTree } from "../file-tree/index";
7
+ import "./index.less";
8
+ var DEBOUNCE_UPDATE_INTERVAL_IN_MS = 500;
9
+ export function SourcesView(_ref) {
10
+ var _state$currentFile, _state$currentFile2, _state$currentFile3, _state$currentFile4, _state$currentFile5;
11
+ var code = _ref.code,
12
+ onCodeChange = _ref.onCodeChange;
13
+ var editorContainerRef = useRef(null);
14
+ var _useState = useState(function () {
15
+ var allFiles = Object.values(code.modules);
16
+ var currentFile = [allFiles.find(function (x) {
17
+ return /pages.+(js|ts)x?$/.test(x.fpath);
18
+ }), allFiles.find(function (m) {
19
+ return m.entry;
20
+ })].filter(Boolean)[0];
21
+ return {
22
+ currentFile: currentFile,
23
+ selectedKeys: [currentFile === null || currentFile === void 0 ? void 0 : currentFile.fpath]
24
+ };
25
+ }),
26
+ state = _useState[0],
27
+ setState = _useState[1];
28
+ var _useState2 = useState(0),
29
+ height = _useState2[0],
30
+ setHeight = _useState2[1];
31
+ useEffect(function () {
32
+ var observer = new ResizeObserver(function () {
33
+ if (editorContainerRef.current) {
34
+ var _editorContainerRef$c = editorContainerRef.current.getBoundingClientRect(),
35
+ _height = _editorContainerRef$c.height;
36
+ setHeight(_height - 2);
37
+ }
38
+ });
39
+ if (editorContainerRef.current) {
40
+ observer.observe(editorContainerRef.current);
41
+ }
42
+ return function () {
43
+ if (editorContainerRef.current) {
44
+ observer.unobserve(editorContainerRef.current);
45
+ }
46
+ };
47
+ }, []);
48
+ var ref = useRef({
49
+ debounceTimer: null
50
+ });
51
+ var onSelect = function onSelect(key) {
52
+ setState(function (prev) {
53
+ if (ref.current.debounceTimer) {
54
+ ref.current.debounceTimer = null;
55
+ }
56
+ return _extends({}, prev, {
57
+ currentFile: code.modules[key] || prev.currentFile
58
+ });
59
+ });
60
+ };
61
+ return /*#__PURE__*/React.createElement(_Splitter, {
62
+ className: "sources-panes"
63
+ }, /*#__PURE__*/React.createElement(_Splitter.Panel, {
64
+ defaultSize: 300,
65
+ min: 300,
66
+ max: "70%",
67
+ className: "file-tree-pane"
68
+ }, /*#__PURE__*/React.createElement(FileTree, {
69
+ modules: code.modules,
70
+ onSelect: onSelect,
71
+ selectedKeys: (_state$currentFile = state.currentFile) !== null && _state$currentFile !== void 0 && _state$currentFile.fpath ? [(_state$currentFile2 = state.currentFile) === null || _state$currentFile2 === void 0 ? void 0 : _state$currentFile2.fpath] : undefined
72
+ })), /*#__PURE__*/React.createElement(_Splitter.Panel, {
73
+ className: "source-code-pane"
74
+ }, /*#__PURE__*/React.createElement("div", {
75
+ ref: editorContainerRef,
76
+ style: {
77
+ height: "100%"
78
+ }
79
+ }, /*#__PURE__*/React.createElement(Editor, {
80
+ height: height,
81
+ language: getFileLanguage((_state$currentFile3 = state.currentFile) === null || _state$currentFile3 === void 0 ? void 0 : _state$currentFile3.fpath),
82
+ saveViewState: true,
83
+ defaultValue: (_state$currentFile4 = state.currentFile) === null || _state$currentFile4 === void 0 ? void 0 : _state$currentFile4.code,
84
+ path: (_state$currentFile5 = state.currentFile) === null || _state$currentFile5 === void 0 ? void 0 : _state$currentFile5.fpath,
85
+ onChange: function onChange(value) {
86
+ console.debug("[monaco editor] onChange: %o (currentFile: %o)", {
87
+ value: value
88
+ }, state.currentFile);
89
+ var currentFile = state.currentFile;
90
+ if (currentFile) {
91
+ if (ref.current.debounceTimer) {
92
+ clearTimeout(ref.current.debounceTimer);
93
+ }
94
+ ref.current.debounceTimer = setTimeout(function () {
95
+ var _extends2;
96
+ ref.current.debounceTimer = null;
97
+ onCodeChange(_extends({}, code, {
98
+ modules: _extends({}, code.modules, (_extends2 = {}, _extends2[currentFile.fpath] = _extends({}, currentFile, {
99
+ code: value || ""
100
+ }), _extends2))
101
+ }));
102
+ }, DEBOUNCE_UPDATE_INTERVAL_IN_MS);
103
+ }
104
+ }
105
+ }))));
106
+ }
107
+ function getFileLanguage(file) {
108
+ switch ((file || "").split(".").pop()) {
109
+ case "ts":
110
+ case "tsx":
111
+ return "typescript";
112
+ case "js":
113
+ case "jsx":
114
+ return "javascript";
115
+ case "css":
116
+ return "css";
117
+ case "scss":
118
+ return "scss";
119
+ case "less":
120
+ return "less";
121
+ case "json":
122
+ return "json";
123
+ case "md":
124
+ return "markdown";
125
+ default:
126
+ return "text";
127
+ }
128
+ }
@@ -0,0 +1,12 @@
1
+ .sources-panes {
2
+ .file-tree-pane {
3
+ overflow: hidden;
4
+ border-right: 1px solid #e0e0e0;
5
+ }
6
+ .source-code-pane {
7
+ flex: 1;
8
+ overflow-y: auto;
9
+ height: 100%;
10
+ }
11
+ }
12
+
@@ -1,20 +1,19 @@
1
1
  import type { IPublicModelPluginContext } from "@gant-lowcode/lowcode-types";
2
- import * as CodeGenerator from "@gant-lowcode/code-generator/standalone-loader";
3
- export type CodeGenPluginOptions = {
2
+ export declare type CodeGenPluginOptions = {
4
3
  /** 是否要禁用出码的动作按钮(默认: 否) */
5
4
  disableCodeGenActionBtn?: boolean;
6
5
  };
7
6
  declare const plugin: {
8
7
  (ctx: IPublicModelPluginContext, options?: CodeGenPluginOptions): {
9
8
  exports(): {
10
- generateCode: typeof CodeGenerator.generateCode;
9
+ generateCode: any;
11
10
  };
12
11
  init(): Promise<void>;
13
12
  destroy(): void;
14
13
  };
15
14
  pluginName: string;
16
15
  meta: {
17
- dependencies: never[];
16
+ dependencies: any[];
18
17
  preferenceDeclaration: {
19
18
  title: string;
20
19
  properties: {
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 "@gant-lowcode/code-generator/standalone-loader";
4
+ import { CodeGenActionBtn } from "./components/code-gen-action";
5
+ var plugin = function plugin(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
+ plugin.pluginName = "codeGenerator";
56
+ plugin.meta = {
57
+ dependencies: [],
58
+ preferenceDeclaration: {
59
+ title: "codeGenerator 的参数定义",
60
+ properties: [{
61
+ key: "disableCodeGenActionBtn",
62
+ type: "boolean",
63
+ description: "是否要禁用出码的动作按钮"
64
+ }]
65
+ }
66
+ };
67
+ export default plugin;
package/es/style.js ADDED
@@ -0,0 +1,9 @@
1
+ import 'antd/es/drawer/style';
2
+ import 'antd/es/space/style';
3
+ import 'antd/es/button/style';
4
+ import 'antd/es/spin/style';
5
+ import 'antd/es/alert/style';
6
+ import 'antd/es/message/style';
7
+ import 'antd/es/empty/style';
8
+ import 'antd/es/splitter/style';
9
+ import '@gant-lowcode/lowcode-plugin-base-monaco-editor/es/style';
@@ -1,17 +1,17 @@
1
- export type SyncCodeGenResult = {
1
+ export declare type SyncCodeGenResult = {
2
2
  type: "SYNC_RESULT";
3
3
  sourceFiles: Array<{
4
4
  pathName: string;
5
5
  content: string;
6
6
  }>;
7
7
  };
8
- export type CodeModules = Record<string, {
8
+ export declare type CodeModules = Record<string, {
9
9
  entry?: 1;
10
10
  packagejson?: 1;
11
11
  code: string;
12
12
  fpath: string;
13
13
  }>;
14
- export type GravityCode = {
14
+ export declare type GravityCode = {
15
15
  type: string;
16
16
  modules: CodeModules;
17
17
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { IPublicTypeProjectSchema, IPublicModelPluginContext } from "@gant-lowcode/lowcode-types";
3
+ import "./index.less";
4
+ export declare function CodeGenActionBtn({ ctx }: {
5
+ ctx: IPublicModelPluginContext;
6
+ }): import("react").JSX.Element;
7
+ export declare function fixSchema(schema: IPublicTypeProjectSchema): Promise<IPublicTypeProjectSchema>;