1- import React , { useRef , useState } from 'react' ;
1+ import React , { useMemo , useRef , useState } from 'react' ;
22import ReactDOM from 'react-dom' ;
33import { IAppInstance , AppRenderer , SlotLocation , AppRenderer2 } from '@alipay/alex' ;
44import '@alipay/alex/languages/sql' ;
@@ -9,12 +9,12 @@ import {
99 setMonacoEnvironment ,
1010} from '@alipay/alex-sql-service' ;
1111import { Button } from '@opensumi/ide-components' ;
12- import * as SQLPlugin from './sql.plugin' ;
12+ import SqlPlugin from './sql.plugin' ;
1313import { IEditor } from '@opensumi/ide-editor' ;
1414import { Popover , Radio } from 'antd' ;
1515import 'antd/dist/antd.css' ;
1616import odcTheme from '@alipay/alex/extensions/alex.odc-theme' ;
17- import { SQLRender } from './sqlRender'
17+ import { SQLRender } from './sqlRender' ;
1818
1919setMonacoEnvironment ( ) ;
2020
@@ -24,34 +24,15 @@ const layoutConfig = {
2424 } ,
2525} ;
2626
27- function format ( ) {
28- SQLPlugin . api . commands ?. executeCommand ( 'editor.action.formatDocument' ) ;
29- }
30-
31- function updatePrefeence ( perferenceName , value ) {
32- // 设置首选项
33- SQLPlugin . api . commands ?. executeCommand ( 'alex.setDefaultPreference' , perferenceName , value ) ;
34- }
3527
36- async function addLine ( ) {
37- const editor = ( await SQLPlugin . api . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
38- editor ?. monacoEditor . trigger ( 'editor' , 'type' , { text : '\n' } ) ;
39- }
40-
41- function openFile ( ) {
42- /** COMMAND alex.sql.open
43- * @param {string } uri - 文件uri
44- * @param {string } content - 文件内容 无内容时创建并注入默认内容
45- */
46- SQLPlugin . api . commands ?. executeCommand ( 'alex.sql.open' , 'test1.sql' , '默认内容' ) ;
47- }
48-
49- async function editor ( ) {
50- const editor = ( await SQLPlugin . api . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
51- console . log ( editor ?. monacoEditor . getValue ( ) ) ;
52- }
5328
5429const App = ( ) => {
30+ const PluginID = 1
31+
32+ const SQLPlugin = useMemo ( ( ) => {
33+ return new SqlPlugin ( PluginID ) ;
34+ } , [ ] ) ;
35+
5536 const [ fontValue , setFontValue ] = useState ( 16 ) ;
5637 const [ encoding , setEncoding ] = useState ( 'utf8' ) ;
5738 const [ editorNumber , setEditorNumber ] = useState ( 1 ) ;
@@ -80,6 +61,10 @@ const App = () => {
8061 } ,
8162 ] ) ;
8263 }
64+
65+
66+
67+
8368 const onChangeFont = ( e ) => {
8469 setFontValue ( e . target . value ) ;
8570 updatePrefeence ( 'editor.fontSize' , e . target . value ) ;
@@ -91,7 +76,35 @@ const App = () => {
9176
9277 function editorNumberUpdate ( ) {
9378 console . log ( 'editorNumberUpdate' , editorNumber ) ;
94- setEditorNumber ( editorNumber + 1 )
79+ setEditorNumber ( editorNumber + 1 ) ;
80+ }
81+
82+
83+ function format ( ) {
84+ SQLPlugin . commands ?. executeCommand ( 'editor.action.formatDocument' ) ;
85+ }
86+
87+ function updatePrefeence ( perferenceName , value ) {
88+ // 设置首选项
89+ SQLPlugin . commands ?. executeCommand ( 'alex.setDefaultPreference' , perferenceName , value ) ;
90+ }
91+
92+ async function addLine ( ) {
93+ const editor = ( await SQLPlugin . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
94+ editor ?. monacoEditor . trigger ( 'editor' , 'type' , { text : '\n' } ) ;
95+ }
96+
97+ function openFile ( ) {
98+ /** COMMAND alex.sql.open
99+ * @param {string } uri - 文件uri
100+ * @param {string } content - 文件内容 无内容时创建并注入默认内容
101+ */
102+ SQLPlugin . commands ?. executeCommand ( 'alex.sql.open' , 'test1.sql' , '默认内容' ) ;
103+ }
104+
105+ async function editor ( ) {
106+ const editor = ( await SQLPlugin . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
107+ console . log ( editor ?. monacoEditor . getValue ( ) ) ;
95108 }
96109
97110 const content = ( ) => (
@@ -112,7 +125,7 @@ const App = () => {
112125
113126 return (
114127 < div style = { { height : '100%' , overflow : 'scroll' } } >
115- < div style = { { height : '500px ' } } >
128+ < div style = { { height : '300px ' } } >
116129 < div style = { { margin : '20px' } } >
117130 < Button onClick = { ( ) => format ( ) } > 格式化</ Button >
118131 < Button onClick = { ( ) => addLine ( ) } > 添加行</ Button >
@@ -273,7 +286,7 @@ const App = () => {
273286 'editor.autoSaveDelay' : 1000 ,
274287 'editor.fixedOverflowWidgets' : true , // widget editor 默认改为 fixed
275288 'files.encoding' : 'utf8' , // 默认编码
276- 'editor.fontSize' : 12
289+ 'editor.fontSize' : 12 ,
277290 } ,
278291 } }
279292 runtimeConfig = { {
@@ -303,12 +316,23 @@ const App = () => {
303316 } ,
304317 } ,
305318 } }
306- />
319+ />
307320 </ div >
308-
309- { editorNumber > 1 ? < div > < SQLRender /> </ div > : null }
310- { editorNumber > 2 ? < div > < SQLRender /> </ div > : null }
311-
321+ { editorNumber > 1 ? (
322+ < div >
323+ < SQLRender />
324+ </ div >
325+ ) : null }
326+ { editorNumber > 2 ? (
327+ < div >
328+ < SQLRender />
329+ </ div >
330+ ) : null }
331+ { editorNumber > 3 ? (
332+ < div >
333+ < SQLRender />
334+ </ div >
335+ ) : null }
312336 </ div >
313337 ) ;
314338} ;
0 commit comments