ronds-metadata 1.0.32 → 1.0.35
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.
@@ -0,0 +1,87 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: wangxain
|
3
|
+
* @Date: 2022-03-03 09:08:06
|
4
|
+
* @LastEditTime: 2022-03-03 09:09:28
|
5
|
+
*/
|
6
|
+
export var SQL_DICO = [{
|
7
|
+
className: 'sql',
|
8
|
+
text: 'SELECT'
|
9
|
+
}, {
|
10
|
+
className: 'sql',
|
11
|
+
text: 'FROM'
|
12
|
+
}, {
|
13
|
+
className: 'sql',
|
14
|
+
text: 'WHERE'
|
15
|
+
}, {
|
16
|
+
className: 'sql',
|
17
|
+
text: 'LEFT'
|
18
|
+
}, {
|
19
|
+
className: 'sql',
|
20
|
+
text: 'RIGHT'
|
21
|
+
}, {
|
22
|
+
className: 'sql',
|
23
|
+
text: 'INNER'
|
24
|
+
}, {
|
25
|
+
className: 'sql',
|
26
|
+
text: 'JOIN'
|
27
|
+
}, {
|
28
|
+
className: 'sql',
|
29
|
+
text: 'UNION'
|
30
|
+
}, {
|
31
|
+
className: 'sql',
|
32
|
+
text: 'EXEC'
|
33
|
+
}, {
|
34
|
+
className: 'sql',
|
35
|
+
text: 'INSERT'
|
36
|
+
}, {
|
37
|
+
className: 'sql',
|
38
|
+
text: 'INTO'
|
39
|
+
}, {
|
40
|
+
className: 'sql',
|
41
|
+
text: 'VALUES'
|
42
|
+
}, {
|
43
|
+
className: 'sql',
|
44
|
+
text: 'UPDATE'
|
45
|
+
}, {
|
46
|
+
className: 'sql',
|
47
|
+
text: 'DELETE'
|
48
|
+
}, {
|
49
|
+
className: 'sql',
|
50
|
+
text: 'GROUP'
|
51
|
+
}, {
|
52
|
+
className: 'sql',
|
53
|
+
text: 'BY'
|
54
|
+
}, {
|
55
|
+
className: 'sql',
|
56
|
+
text: 'HAVING'
|
57
|
+
}, {
|
58
|
+
className: 'sql',
|
59
|
+
text: 'IS'
|
60
|
+
}, {
|
61
|
+
className: 'sql',
|
62
|
+
text: 'DISTINCT'
|
63
|
+
}, {
|
64
|
+
className: 'sql',
|
65
|
+
text: 'OUTER'
|
66
|
+
}, {
|
67
|
+
className: 'sql',
|
68
|
+
text: 'TOP'
|
69
|
+
}, {
|
70
|
+
className: 'sql',
|
71
|
+
text: 'EXISTS'
|
72
|
+
}, {
|
73
|
+
className: 'sql',
|
74
|
+
text: 'WHEN'
|
75
|
+
}, {
|
76
|
+
className: 'sql',
|
77
|
+
text: 'CASE'
|
78
|
+
}, {
|
79
|
+
className: 'sql',
|
80
|
+
text: 'CAST'
|
81
|
+
}, {
|
82
|
+
className: 'sql',
|
83
|
+
text: 'IN'
|
84
|
+
}, {
|
85
|
+
className: 'sql',
|
86
|
+
text: 'NULL'
|
87
|
+
}];
|
@@ -5,6 +5,9 @@ import 'codemirror/theme/neat.css';
|
|
5
5
|
import 'codemirror/theme/idea.css';
|
6
6
|
import 'codemirror/mode/sql/sql.js';
|
7
7
|
import 'codemirror/mode/javascript/javascript.js';
|
8
|
+
import 'codemirror/mode/shell/shell.js';
|
9
|
+
import 'codemirror/mode/perl/perl.js';
|
10
|
+
import 'codemirror/mode/python/python.js';
|
8
11
|
import 'codemirror/addon/hint/show-hint.js';
|
9
12
|
import 'codemirror/addon/hint/show-hint.css';
|
10
13
|
import 'codemirror/addon/fold/foldgutter.css';
|
@@ -12,19 +15,50 @@ import 'codemirror/addon/fold/foldcode';
|
|
12
15
|
import 'codemirror/addon/fold/foldgutter';
|
13
16
|
import 'codemirror/addon/fold/brace-fold';
|
14
17
|
import 'codemirror/addon/fold/comment-fold';
|
18
|
+
import 'codemirror/addon/selection/active-line';
|
19
|
+
import 'codemirror/addon/edit/closeBrackets';
|
20
|
+
import 'codemirror/addon/edit/matchBrackets';
|
15
21
|
import './index.less';
|
16
22
|
interface ISqlEditProps {
|
23
|
+
/**
|
24
|
+
* 编辑器内容
|
25
|
+
*/
|
26
|
+
value?: string;
|
27
|
+
/**
|
28
|
+
* 主题
|
29
|
+
*/
|
17
30
|
theme?: 'neat' | 'neo' | 'panda-syntax' | 'idea';
|
18
|
-
|
19
|
-
|
31
|
+
/**
|
32
|
+
* 编辑器的格式
|
33
|
+
*/
|
34
|
+
mode?: 'text/javascript' | 'text/x-mysql' | 'application/json' | 'shell' | 'perl' | 'python';
|
35
|
+
/**
|
36
|
+
* 是否有行数标识
|
37
|
+
*/
|
20
38
|
isLineNumbers?: boolean;
|
21
|
-
|
39
|
+
/**
|
40
|
+
* Json格式化是否可折叠
|
41
|
+
*/
|
22
42
|
isGutters?: boolean;
|
23
|
-
|
43
|
+
/**
|
44
|
+
* 联想提示说明
|
45
|
+
*/
|
24
46
|
extraDico?: any[];
|
47
|
+
/**
|
48
|
+
* 是否只读
|
49
|
+
*/
|
25
50
|
readOnly?: boolean;
|
26
|
-
|
51
|
+
/**
|
52
|
+
* 鼠标光标选中回调
|
53
|
+
*/
|
54
|
+
onSelectChange?: (data: any) => void;
|
55
|
+
/**
|
56
|
+
* 编辑框输入值改变回调
|
57
|
+
*/
|
27
58
|
onChange?: (txt: string) => void;
|
59
|
+
/**
|
60
|
+
* Enter快捷键方法重写
|
61
|
+
*/
|
28
62
|
onReWriteEnter?: () => void;
|
29
63
|
}
|
30
64
|
declare const SqlEdit: (props: ISqlEditProps) => JSX.Element;
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4
3
|
import React from 'react';
|
5
4
|
import CodeMirror from 'codemirror';
|
6
5
|
import 'codemirror/lib/codemirror.css';
|
@@ -10,6 +9,9 @@ import 'codemirror/theme/neat.css';
|
|
10
9
|
import 'codemirror/theme/idea.css';
|
11
10
|
import 'codemirror/mode/sql/sql.js';
|
12
11
|
import 'codemirror/mode/javascript/javascript.js';
|
12
|
+
import 'codemirror/mode/shell/shell.js';
|
13
|
+
import 'codemirror/mode/perl/perl.js';
|
14
|
+
import 'codemirror/mode/python/python.js';
|
13
15
|
import 'codemirror/addon/hint/show-hint.js';
|
14
16
|
import 'codemirror/addon/hint/show-hint.css';
|
15
17
|
import 'codemirror/addon/fold/foldgutter.css';
|
@@ -17,13 +19,15 @@ import 'codemirror/addon/fold/foldcode';
|
|
17
19
|
import 'codemirror/addon/fold/foldgutter';
|
18
20
|
import 'codemirror/addon/fold/brace-fold';
|
19
21
|
import 'codemirror/addon/fold/comment-fold';
|
22
|
+
import 'codemirror/addon/selection/active-line';
|
23
|
+
import 'codemirror/addon/edit/closeBrackets';
|
24
|
+
import 'codemirror/addon/edit/matchBrackets';
|
20
25
|
import "./index.css";
|
26
|
+
import { SQL_DICO } from './constant';
|
21
27
|
|
22
28
|
var SqlEdit = function SqlEdit(props) {
|
23
29
|
var _props$theme = props.theme,
|
24
30
|
theme = _props$theme === void 0 ? 'idea' : _props$theme,
|
25
|
-
_props$isExtraDico = props.isExtraDico,
|
26
|
-
isExtraDico = _props$isExtraDico === void 0 ? false : _props$isExtraDico,
|
27
31
|
_props$extraDico = props.extraDico,
|
28
32
|
extraDico = _props$extraDico === void 0 ? [] : _props$extraDico,
|
29
33
|
_props$mode = props.mode,
|
@@ -35,12 +39,12 @@ var SqlEdit = function SqlEdit(props) {
|
|
35
39
|
_props$readOnly = props.readOnly,
|
36
40
|
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
37
41
|
value = props.value,
|
38
|
-
_props$isSetValue = props.isSetValue,
|
39
|
-
isSetValue = _props$isSetValue === void 0 ? false : _props$isSetValue,
|
40
42
|
onChange = props.onChange,
|
41
|
-
|
43
|
+
onSelectChange = props.onSelectChange,
|
42
44
|
onReWriteEnter = props.onReWriteEnter;
|
43
45
|
var textareaRef = React.useRef(null);
|
46
|
+
var firstLoadRef = React.useRef(true);
|
47
|
+
var editorRef = React.useRef();
|
44
48
|
var extraKeys = React.useMemo(function () {
|
45
49
|
var _extraKeys = {
|
46
50
|
'Ctrl-Space': function CtrlSpace(__editor) {
|
@@ -65,121 +69,21 @@ var SqlEdit = function SqlEdit(props) {
|
|
65
69
|
|
66
70
|
return _extraKeys;
|
67
71
|
}, [mode, onReWriteEnter]);
|
72
|
+
var dico = React.useMemo(function () {
|
73
|
+
var res = SQL_DICO;
|
68
74
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
setEditor = _React$useState2[1];
|
73
|
-
|
74
|
-
var _React$useState3 = React.useState([{
|
75
|
-
className: 'sql',
|
76
|
-
text: 'SELECT'
|
77
|
-
}, {
|
78
|
-
className: 'sql',
|
79
|
-
text: 'FROM'
|
80
|
-
}, {
|
81
|
-
className: 'sql',
|
82
|
-
text: 'WHERE'
|
83
|
-
}, {
|
84
|
-
className: 'sql',
|
85
|
-
text: 'INNER'
|
86
|
-
}, {
|
87
|
-
className: 'sql',
|
88
|
-
text: 'JOIN'
|
89
|
-
}, {
|
90
|
-
className: 'sql',
|
91
|
-
text: 'UNION'
|
92
|
-
}, {
|
93
|
-
className: 'sql',
|
94
|
-
text: 'EXEC'
|
95
|
-
}, {
|
96
|
-
className: 'sql',
|
97
|
-
text: 'INSERT'
|
98
|
-
}, {
|
99
|
-
className: 'sql',
|
100
|
-
text: 'INTO'
|
101
|
-
}, {
|
102
|
-
className: 'sql',
|
103
|
-
text: 'VALUES'
|
104
|
-
}, {
|
105
|
-
className: 'sql',
|
106
|
-
text: 'UPDATE'
|
107
|
-
}, {
|
108
|
-
className: 'sql',
|
109
|
-
text: 'DELETE'
|
110
|
-
}, {
|
111
|
-
className: 'sql',
|
112
|
-
text: 'GROUP'
|
113
|
-
}, {
|
114
|
-
className: 'sql',
|
115
|
-
text: 'BY'
|
116
|
-
}, {
|
117
|
-
className: 'sql',
|
118
|
-
text: 'HAVING'
|
119
|
-
}, {
|
120
|
-
className: 'sql',
|
121
|
-
text: 'IS'
|
122
|
-
}, {
|
123
|
-
className: 'sql',
|
124
|
-
text: 'DISTINCT'
|
125
|
-
}, {
|
126
|
-
className: 'sql',
|
127
|
-
text: 'OUTER'
|
128
|
-
}, {
|
129
|
-
className: 'sql',
|
130
|
-
text: 'TOP'
|
131
|
-
}, {
|
132
|
-
className: 'sql',
|
133
|
-
text: 'EXISTS'
|
134
|
-
}, {
|
135
|
-
className: 'sql',
|
136
|
-
text: 'WHEN'
|
137
|
-
}, {
|
138
|
-
className: 'sql',
|
139
|
-
text: 'CASE'
|
140
|
-
}, {
|
141
|
-
className: 'sql',
|
142
|
-
text: 'CAST'
|
143
|
-
}, {
|
144
|
-
className: 'sql',
|
145
|
-
text: 'IN'
|
146
|
-
}, {
|
147
|
-
className: 'sql',
|
148
|
-
text: 'NULL'
|
149
|
-
}]),
|
150
|
-
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
151
|
-
dico = _React$useState4[0],
|
152
|
-
setDico = _React$useState4[1];
|
153
|
-
|
154
|
-
React.useEffect(function () {
|
155
|
-
if (isExtraDico) {
|
156
|
-
setDico([].concat(_toConsumableArray(dico), _toConsumableArray(extraDico)));
|
157
|
-
} // eslint-disable-next-line
|
158
|
-
|
159
|
-
}, [extraDico, isExtraDico]);
|
160
|
-
React.useEffect(function () {
|
161
|
-
if (editor && isSetValue) {
|
162
|
-
editor.setValue(value);
|
163
|
-
onCallback && onCallback();
|
164
|
-
setTimeout(function () {
|
165
|
-
editor.refresh();
|
166
|
-
}, 100);
|
167
|
-
} // eslint-disable-next-line
|
168
|
-
|
169
|
-
}, [value, isSetValue]);
|
170
|
-
React.useEffect(function () {
|
171
|
-
if (!isExtraDico) {
|
172
|
-
initEdit();
|
173
|
-
} else if (dico.length > 25) {
|
174
|
-
initEdit();
|
175
|
-
} // eslint-disable-next-line
|
176
|
-
|
177
|
-
}, [textareaRef, dico, isGutters]);
|
75
|
+
if (extraDico.length > 0) {
|
76
|
+
res = [].concat(_toConsumableArray(SQL_DICO), _toConsumableArray(extraDico));
|
77
|
+
}
|
178
78
|
|
179
|
-
|
79
|
+
return res;
|
80
|
+
}, [extraDico]);
|
81
|
+
var initEdit = React.useCallback(function () {
|
180
82
|
if (textareaRef.current === null) return;
|
83
|
+
if (!firstLoadRef.current) return;
|
181
84
|
|
182
85
|
var _editor = CodeMirror.fromTextArea(textareaRef.current, {
|
86
|
+
value: value,
|
183
87
|
tabSize: 4,
|
184
88
|
mode: mode,
|
185
89
|
theme: theme,
|
@@ -193,6 +97,8 @@ var SqlEdit = function SqlEdit(props) {
|
|
193
97
|
completeSingle: false,
|
194
98
|
hint: hint
|
195
99
|
},
|
100
|
+
matchBrackets: true,
|
101
|
+
autoCloseBrackets: true,
|
196
102
|
extraKeys: extraKeys
|
197
103
|
});
|
198
104
|
|
@@ -206,8 +112,31 @@ var SqlEdit = function SqlEdit(props) {
|
|
206
112
|
onChange && onChange(__editor.getValue());
|
207
113
|
});
|
208
114
|
|
209
|
-
|
210
|
-
|
115
|
+
_editor.on('cursorActivity', function (__editor) {
|
116
|
+
onSelectChange && onSelectChange(__editor.getSelection());
|
117
|
+
});
|
118
|
+
|
119
|
+
editorRef.current = _editor;
|
120
|
+
firstLoadRef.current = false;
|
121
|
+
}, [dico, isGutters, readOnly, isLineNumbers]);
|
122
|
+
React.useEffect(function () {
|
123
|
+
if (!textareaRef.current) return;
|
124
|
+
initEdit();
|
125
|
+
}, [textareaRef, initEdit]);
|
126
|
+
React.useEffect(function () {
|
127
|
+
if (!editorRef.current) return;
|
128
|
+
|
129
|
+
if (value) {
|
130
|
+
editorRef.current.setValue(value);
|
131
|
+
}
|
132
|
+
}, [value]);
|
133
|
+
React.useEffect(function () {
|
134
|
+
if (!editorRef.current) return;
|
135
|
+
debugger;
|
136
|
+
editorRef.current.setOption('readOnly', readOnly);
|
137
|
+
editorRef.current.setOption('lineNumbers', isLineNumbers);
|
138
|
+
editorRef.current.setOption('gutters', isGutters ? ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'] : []);
|
139
|
+
}, [readOnly, isLineNumbers, isGutters]);
|
211
140
|
|
212
141
|
var hint = function hint(__editor) {
|
213
142
|
var cur = __editor.getCursor();
|