@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,183 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { useRef, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
// const GRAVITY_PREFIX = 'lowcodeGravityPreview';
|
|
5
|
+
// const GRAVITY_PREFIX = 'gravityDemoSdk';
|
|
6
|
+
var GRAVITY_PREFIX = 'gravityRiddleSdk';
|
|
7
|
+
var defaultProps = {
|
|
8
|
+
// src: "https://gw.alipayobjects.com/as/g/Gravity/gravity/5.0.0-beta.10/gravityDemoSdk/index.html"
|
|
9
|
+
src: 'https://gw.alipayobjects.com/as/g/Gravity/gravity/5.0.0-beta.10/gravityRiddleSdk/index.html',
|
|
10
|
+
code: {},
|
|
11
|
+
target: null,
|
|
12
|
+
style: {
|
|
13
|
+
backgroundColor: '#fff',
|
|
14
|
+
border: 'none',
|
|
15
|
+
position: null,
|
|
16
|
+
display: 'block',
|
|
17
|
+
overflow: null
|
|
18
|
+
},
|
|
19
|
+
scrolling: null,
|
|
20
|
+
importance: null,
|
|
21
|
+
sandbox: null,
|
|
22
|
+
loading: null,
|
|
23
|
+
styles: null,
|
|
24
|
+
name: null,
|
|
25
|
+
className: null,
|
|
26
|
+
referrerPolicy: null,
|
|
27
|
+
title: null,
|
|
28
|
+
allow: 'clipboard-read;clipboard-write;camera;microphone',
|
|
29
|
+
id: null,
|
|
30
|
+
'aria-labelledby': null,
|
|
31
|
+
'aria-hidden': null,
|
|
32
|
+
'aria-label': null,
|
|
33
|
+
width: null,
|
|
34
|
+
height: null,
|
|
35
|
+
onLoad: null,
|
|
36
|
+
onMouseOver: null,
|
|
37
|
+
onMouseOut: null
|
|
38
|
+
};
|
|
39
|
+
var height;
|
|
40
|
+
var boostState;
|
|
41
|
+
var iframe;
|
|
42
|
+
var isPrivate;
|
|
43
|
+
export function getHeight() {
|
|
44
|
+
return height;
|
|
45
|
+
}
|
|
46
|
+
export function refresh() {
|
|
47
|
+
var channel = GRAVITY_PREFIX;
|
|
48
|
+
if (iframe) {
|
|
49
|
+
iframe.current.contentWindow.postMessage({
|
|
50
|
+
type: channel + "_reload"
|
|
51
|
+
}, '*');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function clear() {
|
|
55
|
+
var channel = GRAVITY_PREFIX;
|
|
56
|
+
if (iframe) {
|
|
57
|
+
iframe.current.contentWindow.postMessage({
|
|
58
|
+
type: channel + "_remove_cache"
|
|
59
|
+
}, '*');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function getBoostState() {
|
|
63
|
+
return boostState;
|
|
64
|
+
}
|
|
65
|
+
export function toggleBoostState() {
|
|
66
|
+
var channel = GRAVITY_PREFIX;
|
|
67
|
+
if (iframe) {
|
|
68
|
+
iframe.current.contentWindow.postMessage({
|
|
69
|
+
type: channel + "_toggle_boost_state"
|
|
70
|
+
}, '*');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function isPrivateMode() {
|
|
74
|
+
return isPrivate;
|
|
75
|
+
}
|
|
76
|
+
export function change(filename, content) {
|
|
77
|
+
var channel = GRAVITY_PREFIX;
|
|
78
|
+
if (iframe) {
|
|
79
|
+
iframe.current.contentWindow.postMessage({
|
|
80
|
+
type: channel + "_file_change",
|
|
81
|
+
filename: filename,
|
|
82
|
+
content: content
|
|
83
|
+
}, '*');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export default (function (props) {
|
|
87
|
+
var iframeEl = useRef(null);
|
|
88
|
+
iframe = iframeEl;
|
|
89
|
+
// let iframeElOnload = useRef(false);
|
|
90
|
+
useEffect(function () {
|
|
91
|
+
// iframeEl.current.contentWindow.location.reload();
|
|
92
|
+
var channel = GRAVITY_PREFIX;
|
|
93
|
+
iframeEl.current.contentWindow.postMessage({
|
|
94
|
+
type: channel + "_reload"
|
|
95
|
+
}, '*');
|
|
96
|
+
function handler(msg) {
|
|
97
|
+
var channel = GRAVITY_PREFIX;
|
|
98
|
+
var type = msg.data.type;
|
|
99
|
+
if (type) {
|
|
100
|
+
if (type === channel + "_force_update") {
|
|
101
|
+
if (props.force) {
|
|
102
|
+
props.force();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (type === channel + "_code_fetch") {
|
|
106
|
+
if (props.code && props.code.modules) {
|
|
107
|
+
var modules = props.code.modules;
|
|
108
|
+
var imn = '';
|
|
109
|
+
var im = Object.keys(modules).some(function (m) {
|
|
110
|
+
if (modules[m].code === null || modules[m].code === undefined) {
|
|
111
|
+
imn = m;
|
|
112
|
+
return m;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
});
|
|
116
|
+
if (!im) {
|
|
117
|
+
iframeEl.current.contentWindow.postMessage({
|
|
118
|
+
type: channel + "_code_fetch",
|
|
119
|
+
code: props.code
|
|
120
|
+
}, '*');
|
|
121
|
+
} else {
|
|
122
|
+
console.warn("\u6A21\u5757 " + imn + " \u4EE3\u7801\u5B58\u5728\u5F02\u5E38\uFF0Ccode \u4E3A " + modules[imn].code);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (type === channel + "_get_height") {
|
|
127
|
+
height = msg.data && msg.data.height || 0;
|
|
128
|
+
}
|
|
129
|
+
if (type === channel + "_boost_state") {
|
|
130
|
+
boostState = msg.data && msg.data.boostState;
|
|
131
|
+
}
|
|
132
|
+
if (type === channel + "_is_private_mode") {
|
|
133
|
+
isPrivate = msg.data && msg.data.isPrivateMode;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
window.addEventListener('message', handler);
|
|
138
|
+
return function () {
|
|
139
|
+
window.removeEventListener('message', handler);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// return iframeEl.current.addEventListener('load', () => {
|
|
143
|
+
// iframeElOnload = true;
|
|
144
|
+
// iframeEl.current.contentWindow.postMessage({
|
|
145
|
+
// type: 'demo_fetch_code',
|
|
146
|
+
// code,
|
|
147
|
+
// });
|
|
148
|
+
// });
|
|
149
|
+
}, [props.code]);
|
|
150
|
+
|
|
151
|
+
// useEffect(() => {
|
|
152
|
+
// if (iframeElOnload) {
|
|
153
|
+
// iframeEl.current.contentWindow.postMessage({
|
|
154
|
+
// type: 'demo_fetch_code',
|
|
155
|
+
// code,
|
|
156
|
+
// });
|
|
157
|
+
// }
|
|
158
|
+
// }, [
|
|
159
|
+
// props.code
|
|
160
|
+
// ]);
|
|
161
|
+
|
|
162
|
+
var newProps = _extends({}, defaultProps, props);
|
|
163
|
+
var _final = Object.create(null);
|
|
164
|
+
for (var _i = 0, _Object$keys = Object.keys(newProps); _i < _Object$keys.length; _i++) {
|
|
165
|
+
var prop = _Object$keys[_i];
|
|
166
|
+
if (newProps[prop] != null) {
|
|
167
|
+
_final[prop] = newProps[prop];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (var _i2 = 0, _Object$keys2 = Object.keys(_final.style); _i2 < _Object$keys2.length; _i2++) {
|
|
171
|
+
var i = _Object$keys2[_i2];
|
|
172
|
+
if (_final.style[i] == null) {
|
|
173
|
+
delete _final.style[i];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return (
|
|
177
|
+
/*#__PURE__*/
|
|
178
|
+
// eslint-disable-next-line
|
|
179
|
+
React.createElement("iframe", _extends({
|
|
180
|
+
ref: iframeEl
|
|
181
|
+
}, _final))
|
|
182
|
+
);
|
|
183
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GravityPreview';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GravityPreview';
|
|
@@ -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,197 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import './SourcesView.scss';
|
|
3
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
4
|
+
import naturalCompare from 'string-natural-compare';
|
|
5
|
+
import { Tree } from '@alifd/next';
|
|
6
|
+
import Editor from '@alilc/lowcode-plugin-base-monaco-editor';
|
|
7
|
+
import '@alilc/lowcode-plugin-base-monaco-editor/lib/style';
|
|
8
|
+
import { FileTypeIcon } from '../FileTypeIcon';
|
|
9
|
+
var FILE_TYPES_ICON_MAP = {
|
|
10
|
+
js: 'js',
|
|
11
|
+
jsx: 'jsx',
|
|
12
|
+
ts: 'ts',
|
|
13
|
+
tsx: 'ts',
|
|
14
|
+
json: 'json'
|
|
15
|
+
};
|
|
16
|
+
var DEBOUNCE_UPDATE_INTERVAL_IN_MS = 500;
|
|
17
|
+
export function SourcesView(_ref) {
|
|
18
|
+
var _state$currentFile, _state$currentFile2, _state$currentFile3;
|
|
19
|
+
var height = _ref.height,
|
|
20
|
+
code = _ref.code,
|
|
21
|
+
onCodeChange = _ref.onCodeChange;
|
|
22
|
+
var _useState = useState(function () {
|
|
23
|
+
var allFiles = Object.values(code.modules);
|
|
24
|
+
var currentFile = [allFiles.find(function (x) {
|
|
25
|
+
return /pages.+(js|ts)x?$/.test(x.fpath);
|
|
26
|
+
}), allFiles.find(function (m) {
|
|
27
|
+
return m.entry;
|
|
28
|
+
})].filter(Boolean)[0];
|
|
29
|
+
return {
|
|
30
|
+
currentFile: currentFile,
|
|
31
|
+
selectedKeys: [currentFile === null || currentFile === void 0 ? void 0 : currentFile.fpath]
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
state = _useState[0],
|
|
35
|
+
setState = _useState[1];
|
|
36
|
+
var ref = useRef({
|
|
37
|
+
debounceTimer: null
|
|
38
|
+
});
|
|
39
|
+
var fileTreeNodes = useMemo(function () {
|
|
40
|
+
var files = Object.values(code.modules);
|
|
41
|
+
var rootNodes = [];
|
|
42
|
+
files.forEach(function (file) {
|
|
43
|
+
var _addFileToNodes = function addFileToNodes(currentNodes, basePath, path, file) {
|
|
44
|
+
var _path$split$filter = path.split('/').filter(Boolean),
|
|
45
|
+
head = _path$split$filter[0],
|
|
46
|
+
tail = _path$split$filter.slice(1);
|
|
47
|
+
if (tail.length === 0) {
|
|
48
|
+
currentNodes.push({
|
|
49
|
+
label: head,
|
|
50
|
+
key: file.fpath,
|
|
51
|
+
children: [],
|
|
52
|
+
icon: getFileIcon(file.fpath)
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
var parentNode = currentNodes.find(function (node) {
|
|
56
|
+
return node.label === head;
|
|
57
|
+
});
|
|
58
|
+
if (!parentNode) {
|
|
59
|
+
parentNode = {
|
|
60
|
+
label: head,
|
|
61
|
+
key: basePath + "/" + head,
|
|
62
|
+
children: [],
|
|
63
|
+
icon: /*#__PURE__*/React.createElement(FileTypeIcon, {
|
|
64
|
+
type: "folder"
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
currentNodes.push(parentNode);
|
|
68
|
+
}
|
|
69
|
+
parentNode.children = parentNode.children || [];
|
|
70
|
+
_addFileToNodes(parentNode.children, basePath + "/" + head, tail.join('/'), file);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
_addFileToNodes(rootNodes, '/', file.fpath, file);
|
|
74
|
+
});
|
|
75
|
+
return sortNodes(rootNodes);
|
|
76
|
+
}, [code]);
|
|
77
|
+
var defaultExpandedKeys = useMemo(function () {
|
|
78
|
+
return Array.from(new Set([].concat(fileTreeNodes.filter(function (node) {
|
|
79
|
+
var _node$children;
|
|
80
|
+
return (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length;
|
|
81
|
+
}).map(function (node) {
|
|
82
|
+
return node.key;
|
|
83
|
+
}), state.selectedKeys, ['src', 'src/pages'])).values());
|
|
84
|
+
}, [fileTreeNodes, state.selectedKeys]);
|
|
85
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
86
|
+
className: "code-gen-sources-view",
|
|
87
|
+
style: {
|
|
88
|
+
height: height
|
|
89
|
+
}
|
|
90
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
91
|
+
className: "sources-panes"
|
|
92
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
93
|
+
className: "file-tree-pane"
|
|
94
|
+
}, /*#__PURE__*/React.createElement(Tree, {
|
|
95
|
+
dataSource: fileTreeNodes,
|
|
96
|
+
selectable: true,
|
|
97
|
+
selectedKeys: state.selectedKeys,
|
|
98
|
+
defaultExpandedKeys: defaultExpandedKeys,
|
|
99
|
+
onSelect: function onSelect(keys) {
|
|
100
|
+
setState(function (prev) {
|
|
101
|
+
if (ref.current.debounceTimer) {
|
|
102
|
+
ref.current.debounceTimer = null;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
selectedKeys: keys,
|
|
106
|
+
currentFile: code.modules[keys[0]] || prev.currentFile
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
111
|
+
className: "source-code-pane",
|
|
112
|
+
style: {
|
|
113
|
+
height: height
|
|
114
|
+
}
|
|
115
|
+
}, /*#__PURE__*/React.createElement(Editor, {
|
|
116
|
+
height: calcHeightInPx(height) - 2 // 注意:这里的编辑器会有边框所以要减掉一点
|
|
117
|
+
,
|
|
118
|
+
language: getFileLanguage((_state$currentFile = state.currentFile) === null || _state$currentFile === void 0 ? void 0 : _state$currentFile.fpath),
|
|
119
|
+
saveViewState: true,
|
|
120
|
+
defaultValue: (_state$currentFile2 = state.currentFile) === null || _state$currentFile2 === void 0 ? void 0 : _state$currentFile2.code,
|
|
121
|
+
path: (_state$currentFile3 = state.currentFile) === null || _state$currentFile3 === void 0 ? void 0 : _state$currentFile3.fpath,
|
|
122
|
+
onChange: function onChange(value) {
|
|
123
|
+
console.debug('[monaco editor] onChange: %o (currentFile: %o)', {
|
|
124
|
+
value: value
|
|
125
|
+
}, state.currentFile);
|
|
126
|
+
var currentFile = state.currentFile;
|
|
127
|
+
if (currentFile) {
|
|
128
|
+
if (ref.current.debounceTimer) {
|
|
129
|
+
clearTimeout(ref.current.debounceTimer);
|
|
130
|
+
}
|
|
131
|
+
ref.current.debounceTimer = setTimeout(function () {
|
|
132
|
+
var _extends2;
|
|
133
|
+
ref.current.debounceTimer = null;
|
|
134
|
+
onCodeChange(_extends({}, code, {
|
|
135
|
+
modules: _extends({}, code.modules, (_extends2 = {}, _extends2[currentFile.fpath] = _extends({}, currentFile, {
|
|
136
|
+
code: value || ''
|
|
137
|
+
}), _extends2))
|
|
138
|
+
}));
|
|
139
|
+
}, DEBOUNCE_UPDATE_INTERVAL_IN_MS);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}))));
|
|
143
|
+
}
|
|
144
|
+
function getFileIcon(file) {
|
|
145
|
+
var type = FILE_TYPES_ICON_MAP[(file || '').split('.').pop() || ''] || 'text';
|
|
146
|
+
return /*#__PURE__*/React.createElement(FileTypeIcon, {
|
|
147
|
+
type: type
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function getFileLanguage(file) {
|
|
151
|
+
switch ((file || '').split('.').pop()) {
|
|
152
|
+
case 'ts':
|
|
153
|
+
case 'tsx':
|
|
154
|
+
return 'typescript';
|
|
155
|
+
case 'js':
|
|
156
|
+
case 'jsx':
|
|
157
|
+
return 'javascript';
|
|
158
|
+
case 'css':
|
|
159
|
+
return 'css';
|
|
160
|
+
case 'scss':
|
|
161
|
+
return 'scss';
|
|
162
|
+
case 'less':
|
|
163
|
+
return 'less';
|
|
164
|
+
case 'json':
|
|
165
|
+
return 'json';
|
|
166
|
+
case 'md':
|
|
167
|
+
return 'markdown';
|
|
168
|
+
default:
|
|
169
|
+
return 'text';
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function sortNodes(nodes) {
|
|
173
|
+
return nodes.sort(function (a, b) {
|
|
174
|
+
var _a$children, _b$children, _a$children2, _b$children2;
|
|
175
|
+
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)) {
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
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) {
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
return naturalCompare(a.label, b.label);
|
|
182
|
+
}).map(function (node) {
|
|
183
|
+
var _node$children2;
|
|
184
|
+
if ((_node$children2 = node.children) !== null && _node$children2 !== void 0 && _node$children2.length) {
|
|
185
|
+
return _extends({}, node, {
|
|
186
|
+
children: sortNodes(node.children)
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return node;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function calcHeightInPx(height) {
|
|
193
|
+
var div = document.createElement('div');
|
|
194
|
+
div.setAttribute('style', "position:fixed;top:0;left:0;width:0;height:" + height + ";");
|
|
195
|
+
document.body.appendChild(div);
|
|
196
|
+
return Number(div.getBoundingClientRect().height.toFixed(0));
|
|
197
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
export * from './SourcesView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.scss';
|
package/es/demo/index.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import './index.scss';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { init, plugins } from '@alilc/lowcode-engine';
|
|
6
|
+
import ComponentsPane from '@alilc/lowcode-plugin-components-pane';
|
|
7
|
+
import Inject, { injectAssets } from '@alilc/lowcode-plugin-inject';
|
|
8
|
+
import CodeGenPlugin from '../';
|
|
9
|
+
var preference = new Map();
|
|
10
|
+
preference.set('DataSourcePane', {
|
|
11
|
+
importPlugins: [],
|
|
12
|
+
dataSourceTypes: [{
|
|
13
|
+
type: 'fetch'
|
|
14
|
+
}, {
|
|
15
|
+
type: 'jsonp'
|
|
16
|
+
}]
|
|
17
|
+
});
|
|
18
|
+
(function () {
|
|
19
|
+
var _main = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
20
|
+
var setterRegistry;
|
|
21
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
22
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
_context4.next = 2;
|
|
25
|
+
return plugins.register(Inject);
|
|
26
|
+
case 2:
|
|
27
|
+
_context4.next = 4;
|
|
28
|
+
return plugins.register(Object.assign(function (ctx) {
|
|
29
|
+
return {
|
|
30
|
+
name: 'editor-init',
|
|
31
|
+
init: function init() {
|
|
32
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
33
|
+
var assets, schema;
|
|
34
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
_context.next = 2;
|
|
38
|
+
return fetchJSON('/assets.json');
|
|
39
|
+
case 2:
|
|
40
|
+
assets = _context.sent;
|
|
41
|
+
_context.t0 = ctx.material;
|
|
42
|
+
_context.next = 6;
|
|
43
|
+
return injectAssets(assets);
|
|
44
|
+
case 6:
|
|
45
|
+
_context.t1 = _context.sent;
|
|
46
|
+
_context.t0.setAssets.call(_context.t0, _context.t1);
|
|
47
|
+
_context.next = 10;
|
|
48
|
+
return fetchJSON('/schema.json');
|
|
49
|
+
case 10:
|
|
50
|
+
schema = _context.sent;
|
|
51
|
+
// 加载 schema
|
|
52
|
+
ctx.project.openDocument(schema);
|
|
53
|
+
case 12:
|
|
54
|
+
case "end":
|
|
55
|
+
return _context.stop();
|
|
56
|
+
}
|
|
57
|
+
}, _callee);
|
|
58
|
+
}))();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}, {
|
|
62
|
+
pluginName: 'editorInit'
|
|
63
|
+
}));
|
|
64
|
+
case 4:
|
|
65
|
+
_context4.next = 6;
|
|
66
|
+
return plugins.register(Object.assign(function (ctx) {
|
|
67
|
+
return {
|
|
68
|
+
name: 'builtin-plugin-registry',
|
|
69
|
+
init: function init() {
|
|
70
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
71
|
+
var _componentsPane$disab;
|
|
72
|
+
var skeleton, project, componentsPane;
|
|
73
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
74
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
skeleton = ctx.skeleton, project = ctx.project; // 注册组件面板
|
|
77
|
+
componentsPane = skeleton.add({
|
|
78
|
+
area: 'leftArea',
|
|
79
|
+
type: 'PanelDock',
|
|
80
|
+
name: 'componentsPane',
|
|
81
|
+
content: ComponentsPane,
|
|
82
|
+
contentProps: {},
|
|
83
|
+
props: {
|
|
84
|
+
align: 'top',
|
|
85
|
+
icon: 'zujianku',
|
|
86
|
+
description: '组件库'
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
componentsPane === null || componentsPane === void 0 ? void 0 : (_componentsPane$disab = componentsPane.disable) === null || _componentsPane$disab === void 0 ? void 0 : _componentsPane$disab.call(componentsPane);
|
|
90
|
+
project.onSimulatorRendererReady(function () {
|
|
91
|
+
var _componentsPane$enabl;
|
|
92
|
+
componentsPane === null || componentsPane === void 0 ? void 0 : (_componentsPane$enabl = componentsPane.enable) === null || _componentsPane$enabl === void 0 ? void 0 : _componentsPane$enabl.call(componentsPane);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// 注册 logo 面板
|
|
96
|
+
skeleton.add({
|
|
97
|
+
area: 'topArea',
|
|
98
|
+
type: 'Widget',
|
|
99
|
+
name: 'logo',
|
|
100
|
+
content: /*#__PURE__*/React.createElement("div", {
|
|
101
|
+
className: "editor-logo"
|
|
102
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
103
|
+
width: "137",
|
|
104
|
+
height: "26",
|
|
105
|
+
src: "https://img.alicdn.com/imgextra/i4/O1CN013w2bmQ25WAIha4Hx9_!!6000000007533-55-tps-137-26.svg"
|
|
106
|
+
}), /*#__PURE__*/React.createElement("strong", {
|
|
107
|
+
style: {
|
|
108
|
+
lineHeight: '26px',
|
|
109
|
+
fontSize: '20px',
|
|
110
|
+
verticalAlign: '6px',
|
|
111
|
+
marginLeft: '4px'
|
|
112
|
+
}
|
|
113
|
+
}, "\u51FA\u7801\u793A\u4F8B")),
|
|
114
|
+
props: {
|
|
115
|
+
align: 'left'
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
case 5:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context2.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee2);
|
|
123
|
+
}))();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}, {
|
|
127
|
+
pluginName: 'builtinPluginRegistry'
|
|
128
|
+
}));
|
|
129
|
+
case 6:
|
|
130
|
+
_context4.next = 8;
|
|
131
|
+
return plugins.register(CodeGenPlugin);
|
|
132
|
+
case 8:
|
|
133
|
+
// 设置内置 setter 和事件绑定、插件绑定面板
|
|
134
|
+
setterRegistry = function setterRegistry(ctx) {
|
|
135
|
+
var _AliLowCodeEngineExt = window.AliLowCodeEngineExt,
|
|
136
|
+
setterMap = _AliLowCodeEngineExt.setterMap,
|
|
137
|
+
pluginMap = _AliLowCodeEngineExt.pluginMap;
|
|
138
|
+
return {
|
|
139
|
+
name: 'ext-setters-registry',
|
|
140
|
+
init: function init() {
|
|
141
|
+
return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
142
|
+
var setters, skeleton;
|
|
143
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
144
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
145
|
+
case 0:
|
|
146
|
+
setters = ctx.setters, skeleton = ctx.skeleton; // 注册setterMap
|
|
147
|
+
setters.registerSetter(setterMap);
|
|
148
|
+
// 注册插件
|
|
149
|
+
// 注册事件绑定面板
|
|
150
|
+
skeleton.add({
|
|
151
|
+
area: 'centerArea',
|
|
152
|
+
type: 'Widget',
|
|
153
|
+
content: pluginMap.EventBindDialog,
|
|
154
|
+
name: 'eventBindDialog',
|
|
155
|
+
props: {}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// 注册变量绑定面板
|
|
159
|
+
skeleton.add({
|
|
160
|
+
area: 'centerArea',
|
|
161
|
+
type: 'Widget',
|
|
162
|
+
content: pluginMap.VariableBindDialog,
|
|
163
|
+
name: 'variableBindDialog',
|
|
164
|
+
props: {}
|
|
165
|
+
});
|
|
166
|
+
case 4:
|
|
167
|
+
case "end":
|
|
168
|
+
return _context3.stop();
|
|
169
|
+
}
|
|
170
|
+
}, _callee3);
|
|
171
|
+
}))();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
setterRegistry.pluginName = 'setterRegistry';
|
|
176
|
+
_context4.next = 12;
|
|
177
|
+
return plugins.register(setterRegistry);
|
|
178
|
+
case 12:
|
|
179
|
+
// 初始化设计器
|
|
180
|
+
init(document.getElementById('lce-container'), {
|
|
181
|
+
// designMode: 'live',
|
|
182
|
+
// locale: 'zh-CN',
|
|
183
|
+
enableCondition: true,
|
|
184
|
+
enableCanvasLock: true,
|
|
185
|
+
// 默认绑定变量
|
|
186
|
+
supportVariableGlobally: true,
|
|
187
|
+
// simulatorUrl 在当 engine-core.js 同一个路径下时是不需要配置的!!!
|
|
188
|
+
// 这里因为用的是 unpkg,在不同 npm 包,engine-core.js 和 react-simulator-renderer.js 是不同路径
|
|
189
|
+
simulatorUrl: ['https://alifd.alicdn.com/npm/@alilc/lowcode-react-simulator-renderer@beta/dist/css/react-simulator-renderer.css', 'https://alifd.alicdn.com/npm/@alilc/lowcode-react-simulator-renderer@beta/dist/js/react-simulator-renderer.js']
|
|
190
|
+
}, preference);
|
|
191
|
+
case 13:
|
|
192
|
+
case "end":
|
|
193
|
+
return _context4.stop();
|
|
194
|
+
}
|
|
195
|
+
}, _callee4);
|
|
196
|
+
}));
|
|
197
|
+
function main() {
|
|
198
|
+
return _main.apply(this, arguments);
|
|
199
|
+
}
|
|
200
|
+
return main;
|
|
201
|
+
})()();
|
|
202
|
+
function fetchJSON(_x) {
|
|
203
|
+
return _fetchJSON.apply(this, arguments);
|
|
204
|
+
}
|
|
205
|
+
function _fetchJSON() {
|
|
206
|
+
_fetchJSON = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url) {
|
|
207
|
+
var res;
|
|
208
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
209
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
210
|
+
case 0:
|
|
211
|
+
_context5.next = 2;
|
|
212
|
+
return fetch(url);
|
|
213
|
+
case 2:
|
|
214
|
+
res = _context5.sent;
|
|
215
|
+
return _context5.abrupt("return", res.json());
|
|
216
|
+
case 4:
|
|
217
|
+
case "end":
|
|
218
|
+
return _context5.stop();
|
|
219
|
+
}
|
|
220
|
+
}, _callee5);
|
|
221
|
+
}));
|
|
222
|
+
return _fetchJSON.apply(this, arguments);
|
|
223
|
+
}
|