mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-19 22:58:15 +00:00
修改编辑器语言提示的问题
This commit is contained in:
parent
56d9f5fe74
commit
954a64bf3a
@ -16,7 +16,7 @@ module.exports = ({ onGetWebpackConfig }) => {
|
|||||||
.plugin('MonacoWebpackPlugin')
|
.plugin('MonacoWebpackPlugin')
|
||||||
// 第一项为具体插件,第二项为插件参数
|
// 第一项为具体插件,第二项为插件参数
|
||||||
.use(new MonacoWebpackPlugin({
|
.use(new MonacoWebpackPlugin({
|
||||||
languages:["javascript","css","json"]
|
languages:["typescript","css","json"]
|
||||||
}), []);
|
}), []);
|
||||||
|
|
||||||
config.plugins.delete('hot');
|
config.plugins.delete('hot');
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import PageHistoryPane from '@ali/ve-page-history-pane';
|
|||||||
// import I18nPane from '@ali/ve-i18n-pane';
|
// import I18nPane from '@ali/ve-i18n-pane';
|
||||||
import I18nManagePane from '@ali/ve-i18n-manage-pane';
|
import I18nManagePane from '@ali/ve-i18n-manage-pane';
|
||||||
import ActionPane from '@ali/ve-action-pane';
|
import ActionPane from '@ali/ve-action-pane';
|
||||||
|
import SourceEditor from '@ali/lowcode-plugin-source-editor';
|
||||||
import fetchContext from '@ali/vu-legao-design-fetch-context';
|
import fetchContext from '@ali/vu-legao-design-fetch-context';
|
||||||
import EventBindDialog from '@ali/lowcode-plugin-event-bind-dialog';
|
import EventBindDialog from '@ali/lowcode-plugin-event-bind-dialog';
|
||||||
import loadUrls from './loader';
|
import loadUrls from './loader';
|
||||||
@ -95,16 +96,43 @@ function initDemoPanes() {
|
|||||||
type: 'Widget',
|
type: 'Widget',
|
||||||
content: EventBindDialog,
|
content: EventBindDialog,
|
||||||
});
|
});
|
||||||
skeleton.add({
|
|
||||||
area: 'leftArea',
|
// skeleton.add({
|
||||||
name: 'icon1',
|
// area: 'left',
|
||||||
type: 'Dock',
|
// name: 'sourceEditor',
|
||||||
props: {
|
// type: "PanelDock",
|
||||||
align: 'bottom',
|
// content: SourceEditor,
|
||||||
icon: 'set',
|
// props: {
|
||||||
description: '设置'
|
// align: undefined,
|
||||||
},
|
// description: "动作面板",
|
||||||
});
|
// onDestroy: undefined,
|
||||||
|
// icon: 'set',
|
||||||
|
// onInit: undefined
|
||||||
|
// },
|
||||||
|
// panelProps:{
|
||||||
|
// height: 300,
|
||||||
|
// help: undefined,
|
||||||
|
// hideTitleBar: true,
|
||||||
|
// maxHeight: 800,
|
||||||
|
// maxWidth: 1200,
|
||||||
|
// title: "动作面板",
|
||||||
|
// width: 600
|
||||||
|
// }
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
// skeleton.add({
|
||||||
|
// area: 'leftArea',
|
||||||
|
// name: 'icon1',
|
||||||
|
// type: 'PanelDock',
|
||||||
|
// props: {
|
||||||
|
// align: 'bottom',
|
||||||
|
// icon: 'set',
|
||||||
|
// description: '设置'
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
skeleton.add({
|
skeleton.add({
|
||||||
area: 'leftArea',
|
area: 'leftArea',
|
||||||
name: 'icon2',
|
name: 'icon2',
|
||||||
@ -129,6 +157,8 @@ function initDemoPanes() {
|
|||||||
children: '发布',
|
children: '发布',
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
skeleton.add({
|
skeleton.add({
|
||||||
area: 'topArea',
|
area: 'topArea',
|
||||||
type: 'Dock',
|
type: 'Dock',
|
||||||
@ -322,6 +352,7 @@ function initActionPane() {
|
|||||||
enableHeaderTip: true,
|
enableHeaderTip: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Panes.add(ActionPane, {
|
Panes.add(ActionPane, {
|
||||||
props,
|
props,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -19,5 +19,16 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.full-screen-container{
|
||||||
|
position: absolute;
|
||||||
|
top: 40px;
|
||||||
|
right: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
img{
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,9 +3,6 @@ import { Tab, Search, Input, Button } from '@alifd/next';
|
|||||||
import {Editor} from '@ali/lowcode-editor-core';
|
import {Editor} from '@ali/lowcode-editor-core';
|
||||||
import { js_beautify, css_beautify } from 'js-beautify';
|
import { js_beautify, css_beautify } from 'js-beautify';
|
||||||
import MonacoEditor from 'react-monaco-editor';
|
import MonacoEditor from 'react-monaco-editor';
|
||||||
|
|
||||||
// import lolizer from './sorceEditorPlugin',
|
|
||||||
|
|
||||||
import { Designer } from '@ali/lowcode-designer';
|
import { Designer } from '@ali/lowcode-designer';
|
||||||
const TAB_KEY = {
|
const TAB_KEY = {
|
||||||
JS_TAB: 'js_tab',
|
JS_TAB: 'js_tab',
|
||||||
@ -46,23 +43,33 @@ interface FunctionEventParam {
|
|||||||
|
|
||||||
export default class SourceEditor extends Component<{
|
export default class SourceEditor extends Component<{
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
panel?: any
|
|
||||||
}> {
|
}> {
|
||||||
private monocoEditer: any;
|
private monocoEditor: Object;
|
||||||
private editorCmd: any;
|
private editorCmd: Object;
|
||||||
|
private editorRef = React.createRef();
|
||||||
|
private editorNode: Object;
|
||||||
|
private editorParentNode: Object;
|
||||||
|
|
||||||
state: any = {
|
state = {
|
||||||
isShow: false,
|
isShow: false,
|
||||||
tabKey: TAB_KEY.JS_TAB,
|
tabKey: TAB_KEY.JS_TAB,
|
||||||
};
|
};
|
||||||
|
|
||||||
async componentWillMount() {
|
componentWillMount() {
|
||||||
const { editor } = this.props;
|
const { editor } = this.props;
|
||||||
editor.on('leftPanel.show', (key: String) => {
|
editor.on('leftPanel.show', (key: String) => {
|
||||||
if (key === 'sourceEditor' && !this.monocoEditer) {
|
debugger;
|
||||||
|
if (key === 'sourceEditor' && !this.monocoEditor) {
|
||||||
this.setState({
|
this.setState({
|
||||||
isShow: true,
|
isShow: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
setTimeout(()=>{
|
||||||
|
this.editorNode = this.editorRef.current; //记录当前dom节点;
|
||||||
|
this.editorParentNode = this.editorNode.parentNode; //记录父节点;
|
||||||
|
console.log(this.editorNode);
|
||||||
|
},0)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -76,9 +83,9 @@ export default class SourceEditor extends Component<{
|
|||||||
editor.on('sourceEditor.focusByFunction', (params: FunctionEventParam) => {
|
editor.on('sourceEditor.focusByFunction', (params: FunctionEventParam) => {
|
||||||
this.callEditorEvent('sourceEditor.focusByFunction', params);
|
this.callEditorEvent('sourceEditor.focusByFunction', params);
|
||||||
this.openPluginPannel();
|
this.openPluginPannel();
|
||||||
})
|
});
|
||||||
|
|
||||||
const designer = await editor.onceGot(Designer);
|
//editor.once('designer.mount', (designer: Designer) => {
|
||||||
// let schema = designer.project.getSchema();
|
// let schema = designer.project.getSchema();
|
||||||
// mock data
|
// mock data
|
||||||
let schema = {
|
let schema = {
|
||||||
@ -113,17 +120,28 @@ export default class SourceEditor extends Component<{
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.initCode(schema);
|
this.initCode(schema);
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(){
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openPluginPannel = () => {
|
openPluginPannel = () => {
|
||||||
const { panel } = this.props;
|
const { editor } = this.props;
|
||||||
if (panel) {
|
// 判断面板是否处于激活状态
|
||||||
panel.show();
|
if (!editor.leftNav || editor.leftNav != 'sourceEditor') {
|
||||||
}
|
// 打开面板
|
||||||
|
editor.emit('leftNav.change', 'sourceEditor');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
callEditorEvent = (eventName: any, params: any) => {
|
/**
|
||||||
if (!this.monocoEditer) {
|
* 执行编辑器事件
|
||||||
|
*/
|
||||||
|
callEditorEvent = (eventName, params) => {
|
||||||
|
if (!this.monocoEditor) {
|
||||||
this.editorCmd = {
|
this.editorCmd = {
|
||||||
eventName,
|
eventName,
|
||||||
params,
|
params,
|
||||||
@ -131,16 +149,24 @@ export default class SourceEditor extends Component<{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventName === 'sourceEditor.addFunction') {
|
if (this.state.selectTab == TAB_KEY.CSS_TAB) {
|
||||||
this.addFunction(params);
|
this.setState({
|
||||||
}else if (eventName === 'sourceEditor.focusByFunction'){
|
selectTab: TAB_KEY.JS_TAB,
|
||||||
this.focusByFunctionName(params);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (eventName === 'sourceEditor.addFunction') {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.addFunction(params);
|
||||||
|
}, 100);
|
||||||
|
} else if (eventName === 'sourceEditor.focusByFunction') {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.focusByFunctionName(params);
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
initCode = (schema: any) => {
|
initCode = (schema) => {
|
||||||
let jsCode = js_beautify(transfrom.schema2Code(schema), { indent_size: 2, indent_empty_lines: true });
|
let jsCode = js_beautify(transfrom.schema2Code(schema), { indent_size: 2, indent_empty_lines: true });
|
||||||
let css;
|
let css;
|
||||||
|
|
||||||
@ -160,19 +186,19 @@ export default class SourceEditor extends Component<{
|
|||||||
* @param params
|
* @param params
|
||||||
*/
|
*/
|
||||||
addFunction(params: FunctionEventParam) {
|
addFunction(params: FunctionEventParam) {
|
||||||
const count = this.monocoEditer.getModel().getLineCount() || 0;
|
const count = this.monocoEditor.getModel().getLineCount() || 0;
|
||||||
const range = new (window as any).monaco.Range(count, 1, count, 1);
|
const range = new monaco.Range(count, 1, count, 1);
|
||||||
const functionCode = transfrom.getNewFunctionCode(params.functionName);
|
const functionCode = transfrom.getNewFunctionCode(params.functionName);
|
||||||
this.monocoEditer.executeEdits('log-source', [
|
this.monocoEditor.executeEdits('log-source', [
|
||||||
{ identifier: 'event_id', range: range, text: functionCode, forceMoveMarkers: true },
|
{ identifier: 'event_id', range: range, text: functionCode, forceMoveMarkers: true },
|
||||||
]);
|
]);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let newPosition = new (window as any).monaco.Position(count + 1, 2);
|
let newPosition = new monaco.Position(count + 1, 2);
|
||||||
this.monocoEditer.setPosition(newPosition);
|
this.monocoEditor.setPosition(newPosition);
|
||||||
this.monocoEditer.focus();
|
this.monocoEditor.focus();
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
this.updateCode(this.monocoEditer.getModel().getValue());
|
this.updateCode(this.monocoEditor.getModel().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,30 +207,24 @@ export default class SourceEditor extends Component<{
|
|||||||
*/
|
*/
|
||||||
focusByFunctionName(params: FunctionEventParam) {
|
focusByFunctionName(params: FunctionEventParam) {
|
||||||
const functionName = params.functionName;
|
const functionName = params.functionName;
|
||||||
const matchedResult = this.monocoEditer
|
const matchedResult = this.monocoEditor
|
||||||
.getModel()
|
.getModel()
|
||||||
.findMatches(`${functionName}\\s*\\([\\s\\S]*\\)[\\s\\S]*\\{`, false, true)[0];
|
.findMatches(`${functionName}\\s*\\([\\s\\S]*\\)[\\s\\S]*\\{`, false, true)[0];
|
||||||
if (matchedResult) {
|
if (matchedResult) {
|
||||||
|
let monocoEditor = this.monocoEditor;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.monocoEditer.revealLineInCenter(matchedResult.range.startLineNumber);
|
monocoEditor.revealLineInCenter(matchedResult.range.startLineNumber);
|
||||||
this.monocoEditer.setPosition({
|
monocoEditor.setPosition({
|
||||||
column: matchedResult.range.endColumn,
|
column: matchedResult.range.endColumn,
|
||||||
lineNumber: matchedResult.range.endLineNumber,
|
lineNumber: matchedResult.range.endLineNumber,
|
||||||
});
|
});
|
||||||
|
monocoEditor.focus();
|
||||||
this.monocoEditer.focus();
|
}, 100);
|
||||||
},100)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
editorDidMount = (editor: any, monaco: any) => {
|
editorDidMount = (editor, monaco) => {
|
||||||
console.log('editorDidMount', editor);
|
console.log('editorDidMount', editor);
|
||||||
this.monocoEditer = editor;
|
|
||||||
|
|
||||||
if (this.editorCmd) {
|
|
||||||
this.callEditorEvent(this.editorCmd.eventName, this.editorCmd.params);
|
|
||||||
}
|
|
||||||
|
|
||||||
// var commandId = editor.addCommand(
|
// var commandId = editor.addCommand(
|
||||||
// 0,
|
// 0,
|
||||||
@ -215,39 +235,22 @@ export default class SourceEditor extends Component<{
|
|||||||
// '',
|
// '',
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// monaco.languages.registerCodeLensProvider('javascript', {
|
if (this.state.selectTab == TAB_KEY.JS_TAB) {
|
||||||
// provideCodeLenses: function(model, token) {
|
this.monocoEditor = editor;
|
||||||
// return {
|
}
|
||||||
// lenses: [
|
|
||||||
// {
|
if (this.editorCmd) {
|
||||||
// range: {
|
this.callEditorEvent(this.editorCmd.eventName, this.editorCmd.params);
|
||||||
// startLineNumber: 1,
|
}
|
||||||
// startColumn: 1,
|
|
||||||
// endLineNumber: 1,
|
|
||||||
// endColumn: 1,
|
|
||||||
// },
|
|
||||||
// id: 'First Line',
|
|
||||||
// command: {
|
|
||||||
// id: commandId,
|
|
||||||
// title: 'First Line',
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// };
|
|
||||||
// },
|
|
||||||
// resolveCodeLens: function(model, codeLens, token) {
|
|
||||||
// return codeLens;
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onTabChange = (key: any) => {
|
onTabChange = (key) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
selectTab: key,
|
selectTab: key,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
updateCode = (newCode: any) => {
|
updateCode = (newCode) => {
|
||||||
const { selectTab } = this.state;
|
const { selectTab } = this.state;
|
||||||
if (selectTab === TAB_KEY.JS_TAB) {
|
if (selectTab === TAB_KEY.JS_TAB) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -271,21 +274,27 @@ export default class SourceEditor extends Component<{
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="source-editor-container" >
|
<div className="source-editor-container" >
|
||||||
<Tab size="small" shape="wrapped" onChange={this.onTabChange}>
|
<Tab size="small" shape="wrapped" onChange={this.onTabChange} activeKey={selectTab}>
|
||||||
{tabs.map((item) => (
|
{tabs.map((item) => (
|
||||||
<Tab.Item key={item.key} title={item.tab}>
|
<Tab.Item key={item.key} title={item.tab}>
|
||||||
{isShow && (
|
{isShow && (
|
||||||
|
<div style={{ height: '100%' }} ref={this.editorRef}>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
value={selectTab == TAB_KEY.JS_TAB ? jsCode : css}
|
value={selectTab == TAB_KEY.JS_TAB ? jsCode : css}
|
||||||
{...defaultEditorOption as any}
|
{...defaultEditorOption}
|
||||||
{...{ language: selectTab == TAB_KEY.JS_TAB ? 'javascript' : 'css' }}
|
{...{ language: selectTab == TAB_KEY.JS_TAB ? 'typescript' : 'css' }}
|
||||||
onChange={(newCode) => this.updateCode(newCode)}
|
onChange={(newCode) => this.updateCode(newCode)}
|
||||||
editorDidMount={this.editorDidMount}
|
editorDidMount={(editor, monaco) => this.editorDidMount.call(this, editor, monaco)}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
</Tab.Item>
|
</Tab.Item>
|
||||||
))}
|
))}
|
||||||
</Tab>
|
</Tab>
|
||||||
|
|
||||||
|
<div className="full-screen-container" onClick={this.fullScreen}>
|
||||||
|
<img src="https://gw.alicdn.com/tfs/TB1d7XqE1T2gK0jSZFvXXXnFXXa-200-200.png"></img>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user