@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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/es/components/CodeGenActionBtn/CodeGenActionBtn.d.ts +8 -0
  4. package/es/components/CodeGenActionBtn/CodeGenActionBtn.js +196 -0
  5. package/es/components/CodeGenActionBtn/CodeGenActionBtn.scss +13 -0
  6. package/es/components/CodeGenActionBtn/index.d.ts +1 -0
  7. package/es/components/CodeGenActionBtn/index.js +1 -0
  8. package/es/components/CodeGenPreview/CodeGenPreview.d.ts +8 -0
  9. package/es/components/CodeGenPreview/CodeGenPreview.js +40 -0
  10. package/es/components/CodeGenPreview/CodeGenPreview.scss +16 -0
  11. package/es/components/CodeGenPreview/fixPreviewCode.d.ts +2 -0
  12. package/es/components/CodeGenPreview/fixPreviewCode.js +101 -0
  13. package/es/components/CodeGenPreview/index.d.ts +1 -0
  14. package/es/components/CodeGenPreview/index.js +1 -0
  15. package/es/components/CodeGenPreview/useIsInIntranet.d.ts +4 -0
  16. package/es/components/CodeGenPreview/useIsInIntranet.js +66 -0
  17. package/es/components/CodeGenResult/CodeGenResult.d.ts +9 -0
  18. package/es/components/CodeGenResult/CodeGenResult.js +162 -0
  19. package/es/components/CodeGenResult/CodeGenResult.scss +7 -0
  20. package/es/components/CodeGenResult/index.d.ts +1 -0
  21. package/es/components/CodeGenResult/index.js +1 -0
  22. package/es/components/CodeSandboxPreview/CodeSandboxPreview.d.ts +4 -0
  23. package/es/components/CodeSandboxPreview/CodeSandboxPreview.js +186 -0
  24. package/es/components/CodeSandboxPreview/CodeSandboxPreview.scss +18 -0
  25. package/es/components/CodeSandboxPreview/index.d.ts +1 -0
  26. package/es/components/CodeSandboxPreview/index.js +1 -0
  27. package/es/components/FileTypeIcon/FileTypeIcon.d.ts +6 -0
  28. package/es/components/FileTypeIcon/FileTypeIcon.js +12 -0
  29. package/es/components/FileTypeIcon/FileTypeIcon.scss +36 -0
  30. package/es/components/FileTypeIcon/index.d.ts +1 -0
  31. package/es/components/FileTypeIcon/index.js +1 -0
  32. package/es/components/GravityCode/GravityCode.d.ts +9 -0
  33. package/es/components/GravityCode/GravityCode.js +1 -0
  34. package/es/components/GravityCode/index.d.ts +1 -0
  35. package/es/components/GravityCode/index.js +1 -0
  36. package/es/components/GravityPreview/ForceUpdate.d.ts +6 -0
  37. package/es/components/GravityPreview/ForceUpdate.js +12 -0
  38. package/es/components/GravityPreview/GravityPreview.d.ts +7 -0
  39. package/es/components/GravityPreview/GravityPreview.js +37 -0
  40. package/es/components/GravityPreview/GravitySdk.d.ts +10 -0
  41. package/es/components/GravityPreview/GravitySdk.js +183 -0
  42. package/es/components/GravityPreview/index.d.ts +1 -0
  43. package/es/components/GravityPreview/index.js +1 -0
  44. package/es/components/SourcesView/SourcesView.d.ts +9 -0
  45. package/es/components/SourcesView/SourcesView.js +197 -0
  46. package/es/components/SourcesView/SourcesView.scss +24 -0
  47. package/es/components/SourcesView/index.d.ts +1 -0
  48. package/es/components/SourcesView/index.js +1 -0
  49. package/es/demo/index.d.ts +1 -0
  50. package/es/demo/index.js +223 -0
  51. package/es/demo/index.scss +56 -0
  52. package/es/index.d.ts +30 -0
  53. package/es/index.js +67 -0
  54. package/es/style.js +2 -0
  55. package/es/types/SyncCodeGenResult.d.ts +7 -0
  56. package/es/types/SyncCodeGenResult.js +1 -0
  57. package/es/types/index.d.ts +1 -0
  58. package/es/types/index.js +1 -0
  59. package/es/typings.d.js +0 -0
  60. package/lib/components/CodeGenActionBtn/CodeGenActionBtn.d.ts +8 -0
  61. package/lib/components/CodeGenActionBtn/CodeGenActionBtn.js +204 -0
  62. package/lib/components/CodeGenActionBtn/CodeGenActionBtn.scss +13 -0
  63. package/lib/components/CodeGenActionBtn/index.d.ts +1 -0
  64. package/lib/components/CodeGenActionBtn/index.js +9 -0
  65. package/lib/components/CodeGenPreview/CodeGenPreview.d.ts +8 -0
  66. package/lib/components/CodeGenPreview/CodeGenPreview.js +45 -0
  67. package/lib/components/CodeGenPreview/CodeGenPreview.scss +16 -0
  68. package/lib/components/CodeGenPreview/fixPreviewCode.d.ts +2 -0
  69. package/lib/components/CodeGenPreview/fixPreviewCode.js +106 -0
  70. package/lib/components/CodeGenPreview/index.d.ts +1 -0
  71. package/lib/components/CodeGenPreview/index.js +9 -0
  72. package/lib/components/CodeGenPreview/useIsInIntranet.d.ts +4 -0
  73. package/lib/components/CodeGenPreview/useIsInIntranet.js +72 -0
  74. package/lib/components/CodeGenResult/CodeGenResult.d.ts +9 -0
  75. package/lib/components/CodeGenResult/CodeGenResult.js +169 -0
  76. package/lib/components/CodeGenResult/CodeGenResult.scss +7 -0
  77. package/lib/components/CodeGenResult/index.d.ts +1 -0
  78. package/lib/components/CodeGenResult/index.js +9 -0
  79. package/lib/components/CodeSandboxPreview/CodeSandboxPreview.d.ts +4 -0
  80. package/lib/components/CodeSandboxPreview/CodeSandboxPreview.js +193 -0
  81. package/lib/components/CodeSandboxPreview/CodeSandboxPreview.scss +18 -0
  82. package/lib/components/CodeSandboxPreview/index.d.ts +1 -0
  83. package/lib/components/CodeSandboxPreview/index.js +9 -0
  84. package/lib/components/FileTypeIcon/FileTypeIcon.d.ts +6 -0
  85. package/lib/components/FileTypeIcon/FileTypeIcon.js +17 -0
  86. package/lib/components/FileTypeIcon/FileTypeIcon.scss +36 -0
  87. package/lib/components/FileTypeIcon/index.d.ts +1 -0
  88. package/lib/components/FileTypeIcon/index.js +9 -0
  89. package/lib/components/GravityCode/GravityCode.d.ts +9 -0
  90. package/lib/components/GravityCode/GravityCode.js +3 -0
  91. package/lib/components/GravityCode/index.d.ts +1 -0
  92. package/lib/components/GravityCode/index.js +9 -0
  93. package/lib/components/GravityPreview/ForceUpdate.d.ts +6 -0
  94. package/lib/components/GravityPreview/ForceUpdate.js +17 -0
  95. package/lib/components/GravityPreview/GravityPreview.d.ts +7 -0
  96. package/lib/components/GravityPreview/GravityPreview.js +44 -0
  97. package/lib/components/GravityPreview/GravitySdk.d.ts +10 -0
  98. package/lib/components/GravityPreview/GravitySdk.js +196 -0
  99. package/lib/components/GravityPreview/index.d.ts +1 -0
  100. package/lib/components/GravityPreview/index.js +9 -0
  101. package/lib/components/SourcesView/SourcesView.d.ts +9 -0
  102. package/lib/components/SourcesView/SourcesView.js +204 -0
  103. package/lib/components/SourcesView/SourcesView.scss +24 -0
  104. package/lib/components/SourcesView/index.d.ts +1 -0
  105. package/lib/components/SourcesView/index.js +9 -0
  106. package/lib/demo/index.d.ts +1 -0
  107. package/lib/demo/index.js +228 -0
  108. package/lib/demo/index.scss +56 -0
  109. package/lib/index.d.ts +30 -0
  110. package/lib/index.js +74 -0
  111. package/lib/style.js +2 -0
  112. package/lib/types/SyncCodeGenResult.d.ts +7 -0
  113. package/lib/types/SyncCodeGenResult.js +3 -0
  114. package/lib/types/index.d.ts +1 -0
  115. package/lib/types/index.js +9 -0
  116. package/lib/typings.d.js +1 -0
  117. package/package.json +94 -0
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.GravityPreview = GravityPreview;
6
+ var _react = _interopRequireWildcard(require("react"));
7
+ var _GravitySdk = _interopRequireDefault(require("./GravitySdk"));
8
+ var _ForceUpdate = require("./ForceUpdate");
9
+ var _fixPreviewCode = require("../CodeGenPreview/fixPreviewCode");
10
+ 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); }
11
+ 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; }
12
+ function GravityPreview(_ref) {
13
+ var code = _ref.code,
14
+ height = _ref.height,
15
+ refresh = _ref.refresh;
16
+ var fixedCode = (0, _react.useMemo)(function () {
17
+ return fixGravityCode(code, refresh);
18
+ }, [code, refresh]);
19
+ if (!code || !fixedCode) {
20
+ return null;
21
+ }
22
+ console.log('GravityPreview', fixedCode);
23
+ return /*#__PURE__*/_react["default"].createElement(_ForceUpdate.ForceUpdate, {
24
+ watchKey: refresh
25
+ }, /*#__PURE__*/_react["default"].createElement(_GravitySdk["default"], {
26
+ code: fixedCode,
27
+ width: "100%",
28
+ height: height
29
+ }));
30
+ }
31
+ function fixGravityCode(code, refresh) {
32
+ if (!code) {
33
+ return null;
34
+ }
35
+ var fixed = (0, _fixPreviewCode.fixPreviewCode)(code);
36
+ Object.assign(fixed.modules, {
37
+ '/src/html.js': {
38
+ fpath: '/src/html.js',
39
+ 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);",
40
+ entry: 1
41
+ }
42
+ });
43
+ return fixed;
44
+ }
@@ -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;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.change = change;
6
+ exports.clear = clear;
7
+ exports["default"] = void 0;
8
+ exports.getBoostState = getBoostState;
9
+ exports.getHeight = getHeight;
10
+ exports.isPrivateMode = isPrivateMode;
11
+ exports.refresh = refresh;
12
+ exports.toggleBoostState = toggleBoostState;
13
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
+ var _react = _interopRequireWildcard(require("react"));
15
+ 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); }
16
+ 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; }
17
+ // const GRAVITY_PREFIX = 'lowcodeGravityPreview';
18
+ // const GRAVITY_PREFIX = 'gravityDemoSdk';
19
+ var GRAVITY_PREFIX = 'gravityRiddleSdk';
20
+ var defaultProps = {
21
+ // src: "https://gw.alipayobjects.com/as/g/Gravity/gravity/5.0.0-beta.10/gravityDemoSdk/index.html"
22
+ src: 'https://gw.alipayobjects.com/as/g/Gravity/gravity/5.0.0-beta.10/gravityRiddleSdk/index.html',
23
+ code: {},
24
+ target: null,
25
+ style: {
26
+ backgroundColor: '#fff',
27
+ border: 'none',
28
+ position: null,
29
+ display: 'block',
30
+ overflow: null
31
+ },
32
+ scrolling: null,
33
+ importance: null,
34
+ sandbox: null,
35
+ loading: null,
36
+ styles: null,
37
+ name: null,
38
+ className: null,
39
+ referrerPolicy: null,
40
+ title: null,
41
+ allow: 'clipboard-read;clipboard-write;camera;microphone',
42
+ id: null,
43
+ 'aria-labelledby': null,
44
+ 'aria-hidden': null,
45
+ 'aria-label': null,
46
+ width: null,
47
+ height: null,
48
+ onLoad: null,
49
+ onMouseOver: null,
50
+ onMouseOut: null
51
+ };
52
+ var height;
53
+ var boostState;
54
+ var iframe;
55
+ var isPrivate;
56
+ function getHeight() {
57
+ return height;
58
+ }
59
+ function refresh() {
60
+ var channel = GRAVITY_PREFIX;
61
+ if (iframe) {
62
+ iframe.current.contentWindow.postMessage({
63
+ type: channel + "_reload"
64
+ }, '*');
65
+ }
66
+ }
67
+ function clear() {
68
+ var channel = GRAVITY_PREFIX;
69
+ if (iframe) {
70
+ iframe.current.contentWindow.postMessage({
71
+ type: channel + "_remove_cache"
72
+ }, '*');
73
+ }
74
+ }
75
+ function getBoostState() {
76
+ return boostState;
77
+ }
78
+ function toggleBoostState() {
79
+ var channel = GRAVITY_PREFIX;
80
+ if (iframe) {
81
+ iframe.current.contentWindow.postMessage({
82
+ type: channel + "_toggle_boost_state"
83
+ }, '*');
84
+ }
85
+ }
86
+ function isPrivateMode() {
87
+ return isPrivate;
88
+ }
89
+ function change(filename, content) {
90
+ var channel = GRAVITY_PREFIX;
91
+ if (iframe) {
92
+ iframe.current.contentWindow.postMessage({
93
+ type: channel + "_file_change",
94
+ filename: filename,
95
+ content: content
96
+ }, '*');
97
+ }
98
+ }
99
+ var _default = exports["default"] = function _default(props) {
100
+ var iframeEl = (0, _react.useRef)(null);
101
+ iframe = iframeEl;
102
+ // let iframeElOnload = useRef(false);
103
+ (0, _react.useEffect)(function () {
104
+ // iframeEl.current.contentWindow.location.reload();
105
+ var channel = GRAVITY_PREFIX;
106
+ iframeEl.current.contentWindow.postMessage({
107
+ type: channel + "_reload"
108
+ }, '*');
109
+ function handler(msg) {
110
+ var channel = GRAVITY_PREFIX;
111
+ var type = msg.data.type;
112
+ if (type) {
113
+ if (type === channel + "_force_update") {
114
+ if (props.force) {
115
+ props.force();
116
+ }
117
+ }
118
+ if (type === channel + "_code_fetch") {
119
+ if (props.code && props.code.modules) {
120
+ var modules = props.code.modules;
121
+ var imn = '';
122
+ var im = Object.keys(modules).some(function (m) {
123
+ if (modules[m].code === null || modules[m].code === undefined) {
124
+ imn = m;
125
+ return m;
126
+ }
127
+ return false;
128
+ });
129
+ if (!im) {
130
+ iframeEl.current.contentWindow.postMessage({
131
+ type: channel + "_code_fetch",
132
+ code: props.code
133
+ }, '*');
134
+ } else {
135
+ console.warn("\u6A21\u5757 " + imn + " \u4EE3\u7801\u5B58\u5728\u5F02\u5E38\uFF0Ccode \u4E3A " + modules[imn].code);
136
+ }
137
+ }
138
+ }
139
+ if (type === channel + "_get_height") {
140
+ height = msg.data && msg.data.height || 0;
141
+ }
142
+ if (type === channel + "_boost_state") {
143
+ boostState = msg.data && msg.data.boostState;
144
+ }
145
+ if (type === channel + "_is_private_mode") {
146
+ isPrivate = msg.data && msg.data.isPrivateMode;
147
+ }
148
+ }
149
+ }
150
+ window.addEventListener('message', handler);
151
+ return function () {
152
+ window.removeEventListener('message', handler);
153
+ };
154
+
155
+ // return iframeEl.current.addEventListener('load', () => {
156
+ // iframeElOnload = true;
157
+ // iframeEl.current.contentWindow.postMessage({
158
+ // type: 'demo_fetch_code',
159
+ // code,
160
+ // });
161
+ // });
162
+ }, [props.code]);
163
+
164
+ // useEffect(() => {
165
+ // if (iframeElOnload) {
166
+ // iframeEl.current.contentWindow.postMessage({
167
+ // type: 'demo_fetch_code',
168
+ // code,
169
+ // });
170
+ // }
171
+ // }, [
172
+ // props.code
173
+ // ]);
174
+
175
+ var newProps = (0, _extends2["default"])({}, defaultProps, props);
176
+ var _final = Object.create(null);
177
+ for (var _i = 0, _Object$keys = Object.keys(newProps); _i < _Object$keys.length; _i++) {
178
+ var prop = _Object$keys[_i];
179
+ if (newProps[prop] != null) {
180
+ _final[prop] = newProps[prop];
181
+ }
182
+ }
183
+ for (var _i2 = 0, _Object$keys2 = Object.keys(_final.style); _i2 < _Object$keys2.length; _i2++) {
184
+ var i = _Object$keys2[_i2];
185
+ if (_final.style[i] == null) {
186
+ delete _final.style[i];
187
+ }
188
+ }
189
+ return (
190
+ /*#__PURE__*/
191
+ // eslint-disable-next-line
192
+ _react["default"].createElement("iframe", (0, _extends2["default"])({
193
+ ref: iframeEl
194
+ }, _final))
195
+ );
196
+ };
@@ -0,0 +1 @@
1
+ export * from './GravityPreview';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _GravityPreview = require("./GravityPreview");
5
+ Object.keys(_GravityPreview).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _GravityPreview[key]) return;
8
+ exports[key] = _GravityPreview[key];
9
+ });
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import './SourcesView.scss';
3
+ import '@alilc/lowcode-plugin-base-monaco-editor/lib/style';
4
+ import { GravityCode } from '../GravityCode';
5
+ export declare function SourcesView({ height, code, onCodeChange }: {
6
+ height: string;
7
+ code: GravityCode;
8
+ onCodeChange: (code: GravityCode) => void;
9
+ }): JSX.Element;
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.SourcesView = SourcesView;
6
+ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
+ require("./SourcesView.scss");
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _stringNaturalCompare = _interopRequireDefault(require("string-natural-compare"));
10
+ var _next = require("@alifd/next");
11
+ var _lowcodePluginBaseMonacoEditor = _interopRequireDefault(require("@alilc/lowcode-plugin-base-monaco-editor"));
12
+ require("@alilc/lowcode-plugin-base-monaco-editor/lib/style");
13
+ var _FileTypeIcon = require("../FileTypeIcon");
14
+ 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); }
15
+ 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; }
16
+ var FILE_TYPES_ICON_MAP = {
17
+ js: 'js',
18
+ jsx: 'jsx',
19
+ ts: 'ts',
20
+ tsx: 'ts',
21
+ json: 'json'
22
+ };
23
+ var DEBOUNCE_UPDATE_INTERVAL_IN_MS = 500;
24
+ function SourcesView(_ref) {
25
+ var _state$currentFile, _state$currentFile2, _state$currentFile3;
26
+ var height = _ref.height,
27
+ code = _ref.code,
28
+ onCodeChange = _ref.onCodeChange;
29
+ var _useState = (0, _react.useState)(function () {
30
+ var allFiles = Object.values(code.modules);
31
+ var currentFile = [allFiles.find(function (x) {
32
+ return /pages.+(js|ts)x?$/.test(x.fpath);
33
+ }), allFiles.find(function (m) {
34
+ return m.entry;
35
+ })].filter(Boolean)[0];
36
+ return {
37
+ currentFile: currentFile,
38
+ selectedKeys: [currentFile === null || currentFile === void 0 ? void 0 : currentFile.fpath]
39
+ };
40
+ }),
41
+ state = _useState[0],
42
+ setState = _useState[1];
43
+ var ref = (0, _react.useRef)({
44
+ debounceTimer: null
45
+ });
46
+ var fileTreeNodes = (0, _react.useMemo)(function () {
47
+ var files = Object.values(code.modules);
48
+ var rootNodes = [];
49
+ files.forEach(function (file) {
50
+ var _addFileToNodes = function addFileToNodes(currentNodes, basePath, path, file) {
51
+ var _path$split$filter = path.split('/').filter(Boolean),
52
+ head = _path$split$filter[0],
53
+ tail = _path$split$filter.slice(1);
54
+ if (tail.length === 0) {
55
+ currentNodes.push({
56
+ label: head,
57
+ key: file.fpath,
58
+ children: [],
59
+ icon: getFileIcon(file.fpath)
60
+ });
61
+ } else {
62
+ var parentNode = currentNodes.find(function (node) {
63
+ return node.label === head;
64
+ });
65
+ if (!parentNode) {
66
+ parentNode = {
67
+ label: head,
68
+ key: basePath + "/" + head,
69
+ children: [],
70
+ icon: /*#__PURE__*/_react["default"].createElement(_FileTypeIcon.FileTypeIcon, {
71
+ type: "folder"
72
+ })
73
+ };
74
+ currentNodes.push(parentNode);
75
+ }
76
+ parentNode.children = parentNode.children || [];
77
+ _addFileToNodes(parentNode.children, basePath + "/" + head, tail.join('/'), file);
78
+ }
79
+ };
80
+ _addFileToNodes(rootNodes, '/', file.fpath, file);
81
+ });
82
+ return sortNodes(rootNodes);
83
+ }, [code]);
84
+ var defaultExpandedKeys = (0, _react.useMemo)(function () {
85
+ return Array.from(new Set([].concat(fileTreeNodes.filter(function (node) {
86
+ var _node$children;
87
+ return (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length;
88
+ }).map(function (node) {
89
+ return node.key;
90
+ }), state.selectedKeys, ['src', 'src/pages'])).values());
91
+ }, [fileTreeNodes, state.selectedKeys]);
92
+ return /*#__PURE__*/_react["default"].createElement("div", {
93
+ className: "code-gen-sources-view",
94
+ style: {
95
+ height: height
96
+ }
97
+ }, /*#__PURE__*/_react["default"].createElement("div", {
98
+ className: "sources-panes"
99
+ }, /*#__PURE__*/_react["default"].createElement("div", {
100
+ className: "file-tree-pane"
101
+ }, /*#__PURE__*/_react["default"].createElement(_next.Tree, {
102
+ dataSource: fileTreeNodes,
103
+ selectable: true,
104
+ selectedKeys: state.selectedKeys,
105
+ defaultExpandedKeys: defaultExpandedKeys,
106
+ onSelect: function onSelect(keys) {
107
+ setState(function (prev) {
108
+ if (ref.current.debounceTimer) {
109
+ ref.current.debounceTimer = null;
110
+ }
111
+ return {
112
+ selectedKeys: keys,
113
+ currentFile: code.modules[keys[0]] || prev.currentFile
114
+ };
115
+ });
116
+ }
117
+ })), /*#__PURE__*/_react["default"].createElement("div", {
118
+ className: "source-code-pane",
119
+ style: {
120
+ height: height
121
+ }
122
+ }, /*#__PURE__*/_react["default"].createElement(_lowcodePluginBaseMonacoEditor["default"], {
123
+ height: calcHeightInPx(height) - 2 // 注意:这里的编辑器会有边框所以要减掉一点
124
+ ,
125
+ language: getFileLanguage((_state$currentFile = state.currentFile) === null || _state$currentFile === void 0 ? void 0 : _state$currentFile.fpath),
126
+ saveViewState: true,
127
+ defaultValue: (_state$currentFile2 = state.currentFile) === null || _state$currentFile2 === void 0 ? void 0 : _state$currentFile2.code,
128
+ path: (_state$currentFile3 = state.currentFile) === null || _state$currentFile3 === void 0 ? void 0 : _state$currentFile3.fpath,
129
+ onChange: function onChange(value) {
130
+ console.debug('[monaco editor] onChange: %o (currentFile: %o)', {
131
+ value: value
132
+ }, state.currentFile);
133
+ var currentFile = state.currentFile;
134
+ if (currentFile) {
135
+ if (ref.current.debounceTimer) {
136
+ clearTimeout(ref.current.debounceTimer);
137
+ }
138
+ ref.current.debounceTimer = setTimeout(function () {
139
+ var _extends2;
140
+ ref.current.debounceTimer = null;
141
+ onCodeChange((0, _extends3["default"])({}, code, {
142
+ modules: (0, _extends3["default"])({}, code.modules, (_extends2 = {}, _extends2[currentFile.fpath] = (0, _extends3["default"])({}, currentFile, {
143
+ code: value || ''
144
+ }), _extends2))
145
+ }));
146
+ }, DEBOUNCE_UPDATE_INTERVAL_IN_MS);
147
+ }
148
+ }
149
+ }))));
150
+ }
151
+ function getFileIcon(file) {
152
+ var type = FILE_TYPES_ICON_MAP[(file || '').split('.').pop() || ''] || 'text';
153
+ return /*#__PURE__*/_react["default"].createElement(_FileTypeIcon.FileTypeIcon, {
154
+ type: type
155
+ });
156
+ }
157
+ function getFileLanguage(file) {
158
+ switch ((file || '').split('.').pop()) {
159
+ case 'ts':
160
+ case 'tsx':
161
+ return 'typescript';
162
+ case 'js':
163
+ case 'jsx':
164
+ return 'javascript';
165
+ case 'css':
166
+ return 'css';
167
+ case 'scss':
168
+ return 'scss';
169
+ case 'less':
170
+ return 'less';
171
+ case 'json':
172
+ return 'json';
173
+ case 'md':
174
+ return 'markdown';
175
+ default:
176
+ return 'text';
177
+ }
178
+ }
179
+ function sortNodes(nodes) {
180
+ return nodes.sort(function (a, b) {
181
+ var _a$children, _b$children, _a$children2, _b$children2;
182
+ if ((_a$children = a.children) !== null && _a$children !== void 0 && _a$children.length && !((_b$children = b.children) !== null && _b$children !== void 0 && _b$children.length)) {
183
+ return -1;
184
+ }
185
+ if (!((_a$children2 = a.children) !== null && _a$children2 !== void 0 && _a$children2.length) && (_b$children2 = b.children) !== null && _b$children2 !== void 0 && _b$children2.length) {
186
+ return 1;
187
+ }
188
+ return (0, _stringNaturalCompare["default"])(a.label, b.label);
189
+ }).map(function (node) {
190
+ var _node$children2;
191
+ if ((_node$children2 = node.children) !== null && _node$children2 !== void 0 && _node$children2.length) {
192
+ return (0, _extends3["default"])({}, node, {
193
+ children: sortNodes(node.children)
194
+ });
195
+ }
196
+ return node;
197
+ });
198
+ }
199
+ function calcHeightInPx(height) {
200
+ var div = document.createElement('div');
201
+ div.setAttribute('style', "position:fixed;top:0;left:0;width:0;height:" + height + ";");
202
+ document.body.appendChild(div);
203
+ return Number(div.getBoundingClientRect().height.toFixed(0));
204
+ }
@@ -0,0 +1,24 @@
1
+ .code-gen-sources-view {
2
+ height: 100%;
3
+ .sources-panes {
4
+ display: flex;
5
+ flex-direction: row;
6
+ height: 100%;
7
+ }
8
+ .file-tree-pane {
9
+ width: 230px;
10
+ overflow-y: auto;
11
+ height: 100%;
12
+ border-right: 1px solid #e0e0e0;
13
+ .file-types-iconfont {
14
+ font-size: 12px;
15
+ margin-right: 4px;
16
+ margin-left: -10px;
17
+ }
18
+ }
19
+ .source-code-pane {
20
+ flex: 1;
21
+ overflow-y: auto;
22
+ height: 100%;
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ export * from './SourcesView';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _SourcesView = require("./SourcesView");
5
+ Object.keys(_SourcesView).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _SourcesView[key]) return;
8
+ exports[key] = _SourcesView[key];
9
+ });
@@ -0,0 +1 @@
1
+ import './index.scss';