ronds-metadata 1.0.32 → 1.0.33

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,4 @@
1
+ export declare const SQL_DICO: {
2
+ className: string;
3
+ text: string;
4
+ }[];
@@ -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
+ }];
@@ -14,17 +14,45 @@ import 'codemirror/addon/fold/brace-fold';
14
14
  import 'codemirror/addon/fold/comment-fold';
15
15
  import './index.less';
16
16
  interface ISqlEditProps {
17
+ /**
18
+ * 编辑器内容
19
+ */
20
+ value?: string;
21
+ /**
22
+ * 主题
23
+ */
17
24
  theme?: 'neat' | 'neo' | 'panda-syntax' | 'idea';
25
+ /**
26
+ * 编辑器的格式
27
+ */
18
28
  mode?: 'text/javascript' | 'text/x-mysql' | 'application/json';
19
- isSetValue?: boolean;
29
+ /**
30
+ * 是否有行数标识
31
+ */
20
32
  isLineNumbers?: boolean;
21
- value?: string;
33
+ /**
34
+ * Json格式化是否可折叠
35
+ */
22
36
  isGutters?: boolean;
23
- isExtraDico?: boolean;
37
+ /**
38
+ * 联想提示说明
39
+ */
24
40
  extraDico?: any[];
41
+ /**
42
+ * 是否只读
43
+ */
25
44
  readOnly?: boolean;
26
- onCallback?: () => void;
45
+ /**
46
+ * 鼠标光标选中回调
47
+ */
48
+ onSelectChange?: (data: any) => void;
49
+ /**
50
+ * 编辑框输入值改变回调
51
+ */
27
52
  onChange?: (txt: string) => void;
53
+ /**
54
+ * Enter快捷键方法重写
55
+ */
28
56
  onReWriteEnter?: () => void;
29
57
  }
30
58
  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';
@@ -18,12 +17,11 @@ import 'codemirror/addon/fold/foldgutter';
18
17
  import 'codemirror/addon/fold/brace-fold';
19
18
  import 'codemirror/addon/fold/comment-fold';
20
19
  import "./index.css";
20
+ import { SQL_DICO } from './constant';
21
21
 
22
22
  var SqlEdit = function SqlEdit(props) {
23
23
  var _props$theme = props.theme,
24
24
  theme = _props$theme === void 0 ? 'idea' : _props$theme,
25
- _props$isExtraDico = props.isExtraDico,
26
- isExtraDico = _props$isExtraDico === void 0 ? false : _props$isExtraDico,
27
25
  _props$extraDico = props.extraDico,
28
26
  extraDico = _props$extraDico === void 0 ? [] : _props$extraDico,
29
27
  _props$mode = props.mode,
@@ -35,12 +33,12 @@ var SqlEdit = function SqlEdit(props) {
35
33
  _props$readOnly = props.readOnly,
36
34
  readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
37
35
  value = props.value,
38
- _props$isSetValue = props.isSetValue,
39
- isSetValue = _props$isSetValue === void 0 ? false : _props$isSetValue,
40
36
  onChange = props.onChange,
41
- onCallback = props.onCallback,
37
+ onSelectChange = props.onSelectChange,
42
38
  onReWriteEnter = props.onReWriteEnter;
43
39
  var textareaRef = React.useRef(null);
40
+ var firstLoadRef = React.useRef(true);
41
+ var editorRef = React.useRef();
44
42
  var extraKeys = React.useMemo(function () {
45
43
  var _extraKeys = {
46
44
  'Ctrl-Space': function CtrlSpace(__editor) {
@@ -65,121 +63,21 @@ var SqlEdit = function SqlEdit(props) {
65
63
 
66
64
  return _extraKeys;
67
65
  }, [mode, onReWriteEnter]);
66
+ var dico = React.useMemo(function () {
67
+ var res = SQL_DICO;
68
68
 
69
- var _React$useState = React.useState(null),
70
- _React$useState2 = _slicedToArray(_React$useState, 2),
71
- editor = _React$useState2[0],
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]);
69
+ if (extraDico.length > 0) {
70
+ res = [].concat(_toConsumableArray(SQL_DICO), _toConsumableArray(extraDico));
71
+ }
178
72
 
179
- var initEdit = function initEdit() {
73
+ return res;
74
+ }, [extraDico]);
75
+ var initEdit = React.useCallback(function () {
180
76
  if (textareaRef.current === null) return;
77
+ if (!firstLoadRef.current) return;
181
78
 
182
79
  var _editor = CodeMirror.fromTextArea(textareaRef.current, {
80
+ value: value,
183
81
  tabSize: 4,
184
82
  mode: mode,
185
83
  theme: theme,
@@ -206,8 +104,24 @@ var SqlEdit = function SqlEdit(props) {
206
104
  onChange && onChange(__editor.getValue());
207
105
  });
208
106
 
209
- setEditor(_editor);
210
- };
107
+ _editor.on('cursorActivity', function (__editor) {
108
+ onSelectChange && onSelectChange(__editor.getSelection());
109
+ });
110
+
111
+ editorRef.current = _editor;
112
+ firstLoadRef.current = false;
113
+ }, [dico, isGutters]);
114
+ React.useEffect(function () {
115
+ if (!textareaRef.current) return;
116
+ initEdit();
117
+ }, [textareaRef, initEdit]);
118
+ React.useEffect(function () {
119
+ if (!editorRef.current) return;
120
+
121
+ if (value) {
122
+ editorRef.current.setValue(value);
123
+ }
124
+ }, [value]);
211
125
 
212
126
  var hint = function hint(__editor) {
213
127
  var cur = __editor.getCursor();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "public": true,
3
3
  "name": "ronds-metadata",
4
- "version": "1.0.32",
4
+ "version": "1.0.33",
5
5
  "scripts": {
6
6
  "start": "dumi dev",
7
7
  "docs:build": "dumi build",