ronds-metadata 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. package/es/api/index.js +249 -0
  2. package/es/comps/DynamicPorts/comps/ContextMenu.js +44 -0
  3. package/es/comps/DynamicPorts/comps/DragNode.js +55 -0
  4. package/es/comps/DynamicPorts/comps/GraphHandler/index.js +51 -0
  5. package/es/comps/DynamicPorts/comps/NodeElement.js +30 -0
  6. package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +42 -0
  7. package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +40 -0
  8. package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +55 -0
  9. package/es/comps/DynamicPorts/comps/shape/connector.js +19 -0
  10. package/es/comps/DynamicPorts/comps/shape/edge.js +91 -0
  11. package/es/comps/DynamicPorts/comps/shape/node.js +190 -0
  12. package/es/comps/DynamicPorts/constant/index.js +19 -0
  13. package/es/comps/DynamicPorts/graph.js +697 -0
  14. package/es/comps/DynamicPorts/index.js +143 -0
  15. package/es/comps/DynamicPorts/interface.js +6 -0
  16. package/es/comps/DynamicPorts/utils.js +127 -0
  17. package/es/comps/Editable/DataCell/ButtonCell.js +45 -0
  18. package/es/comps/Editable/DataCell/ColorPicker.js +33 -0
  19. package/es/comps/Editable/DataCell/Input.js +54 -0
  20. package/es/comps/Editable/DataCell/Number.js +44 -0
  21. package/es/comps/Editable/DataCell/Select.js +48 -0
  22. package/es/comps/Editable/DataCell/Switch.js +33 -0
  23. package/es/comps/Editable/comps/EditableAction.js +110 -0
  24. package/es/comps/Editable/comps/EditableCell.js +108 -0
  25. package/es/comps/Editable/comps/EditableHeardCell.js +172 -0
  26. package/es/comps/Editable/comps/EditableRow.js +118 -0
  27. package/es/comps/Editable/comps/Texty.js +277 -0
  28. package/es/comps/Editable/index.js +386 -0
  29. package/es/comps/Editable/interface.js +8 -0
  30. package/es/comps/Editable/utils.js +46 -0
  31. package/es/comps/FileView/index.js +198 -0
  32. package/es/comps/FormGenerator/Provider.js +8 -0
  33. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Checkbox.js +69 -0
  34. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Color.js +17 -0
  35. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +16 -0
  36. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Input.js +17 -0
  37. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +50 -0
  38. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +55 -0
  39. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +14 -0
  40. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +50 -0
  41. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Password.js +17 -0
  42. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Radio.js +69 -0
  43. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +55 -0
  44. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +13 -0
  45. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Table.js +50 -0
  46. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +14 -0
  47. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Upload.js +27 -0
  48. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +261 -0
  49. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +62 -0
  50. package/es/comps/FormGenerator/comps/Canvas/core/index.js +315 -0
  51. package/es/comps/FormGenerator/comps/Canvas/index.js +120 -0
  52. package/es/comps/FormGenerator/comps/Settings/index.js +150 -0
  53. package/es/comps/FormGenerator/comps/Sidebar/Elements.js +48 -0
  54. package/es/comps/FormGenerator/comps/Sidebar/index.js +37 -0
  55. package/es/comps/FormGenerator/index.js +68 -0
  56. package/es/comps/FormGenerator/settings/index.js +367 -0
  57. package/es/comps/FormGenerator/settings/ruleConfig.js +557 -0
  58. package/es/comps/FormGenerator/transformer.js +300 -0
  59. package/es/comps/Icons/index.js +23 -0
  60. package/es/comps/JsonEdit/constant/index.js +87 -0
  61. package/es/comps/JsonEdit/index.js +221 -0
  62. package/es/comps/JsonView/index.js +109 -0
  63. package/es/comps/MdEdit/index.js +41 -0
  64. package/es/comps/MdNavbar/index.js +180 -0
  65. package/es/comps/MdNavbar/utils.js +34 -0
  66. package/es/comps/MdView/index.js +70 -0
  67. package/es/comps/MetadataEdit/components/MetaFieldsEdit.js +419 -0
  68. package/es/comps/MetadataEdit/components/MetaPropsEdit.js +368 -0
  69. package/es/comps/MetadataEdit/constant/index.js +69 -0
  70. package/es/comps/MetadataEdit/hooks/index.js +43 -0
  71. package/es/comps/MetadataEdit/index.js +255 -0
  72. package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +237 -0
  73. package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +367 -0
  74. package/es/comps/MetadataEditV2/constant/index.js +69 -0
  75. package/es/comps/MetadataEditV2/hooks/index.js +43 -0
  76. package/es/comps/MetadataEditV2/index.js +298 -0
  77. package/es/comps/MetadataForm/DataCell/Array.js +148 -0
  78. package/es/comps/MetadataForm/DataCell/Input.js +198 -0
  79. package/es/comps/MetadataForm/DataCell/Number.js +130 -0
  80. package/es/comps/MetadataForm/DataCell/Ref.js +326 -0
  81. package/es/comps/MetadataForm/DataCell/Select.js +557 -0
  82. package/es/comps/MetadataForm/DataCell/Switch.js +115 -0
  83. package/es/comps/MetadataForm/DataCell/layout/TableArray.js +359 -0
  84. package/es/comps/MetadataForm/HOC/index.js +125 -0
  85. package/es/comps/MetadataForm/constants.js +11 -0
  86. package/es/comps/MetadataForm/hooks/index.js +128 -0
  87. package/es/comps/MetadataForm/index.js +268 -0
  88. package/es/comps/MetadataForm/interface.js +8 -0
  89. package/es/comps/MetadataForm/utils.js +112 -0
  90. package/es/comps/locales/en-US.js +24 -0
  91. package/es/comps/locales/index.js +8 -0
  92. package/es/comps/locales/zh-CN.js +24 -0
  93. package/es/config.js +50 -0
  94. package/es/framework/graph/index.js +515 -0
  95. package/es/framework/hooks/use-async-memo.js +32 -0
  96. package/es/framework/hooks/use-sync-scroll.js +106 -0
  97. package/es/framework/http/cache.js +137 -0
  98. package/es/framework/http/cancel.js +44 -0
  99. package/es/framework/http/index.js +392 -0
  100. package/es/framework/http/msgpack.js +34 -0
  101. package/es/framework/http/msgpack5/index.js +84 -0
  102. package/es/framework/http/msgpack5/lib/codecs/DateCodec.js +71 -0
  103. package/es/framework/http/msgpack5/lib/decoder.js +287 -0
  104. package/es/framework/http/msgpack5/lib/encoder.js +252 -0
  105. package/es/framework/http/msgpack5/lib/helpers.js +23 -0
  106. package/es/framework/http/msgpack5/lib/streams.js +93 -0
  107. package/es/framework/http/types.js +1 -0
  108. package/es/framework/libs/jquery.min.js +4022 -0
  109. package/es/framework/locale/dil8/di18n.js +132 -0
  110. package/es/framework/locale/dil8/index.js +3 -0
  111. package/es/framework/locale/dil8/translate.js +76 -0
  112. package/es/framework/locale/dil8/util.js +17 -0
  113. package/es/framework/locale/index.js +26 -0
  114. package/es/framework/metadata/MetadataService.js +169 -0
  115. package/es/framework/metadata/index.js +384 -0
  116. package/es/framework/rxjs-hooks/useMemoSubject.js +16 -0
  117. package/es/framework/rxjs-hooks/useObservable.js +22 -0
  118. package/es/framework/rxjs-hooks/useObservableState.js +45 -0
  119. package/es/index.js +27 -0
  120. package/es/utils.js +138 -0
  121. package/package.json +1 -1
@@ -0,0 +1,300 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+
4
+ /*
5
+ * @Author: wangxian
6
+ * @Date: 2023-02-08 14:45:46
7
+ * @LastEditTime: 2023-02-27 16:38:58
8
+ */
9
+ import { deepClone } from '../../utils';
10
+ import { basicComps, complexComps, layoutComps } from './settings';
11
+ var EMPTY_OBJ = [{
12
+ id: 'FormGenerator',
13
+ type: 'object',
14
+ properties: [],
15
+ fields: [{
16
+ id: 'com.ronds.schema.default.Rule.Form',
17
+ type: 'ref',
18
+ refId: 'com.ronds.schema.default.Rule.Form',
19
+ value: {}
20
+ }]
21
+ }];
22
+ var EMPTY_PROP = {
23
+ id: '',
24
+ type: '',
25
+ fields: [{
26
+ id: 'com.ronds.schema.default.Rule.Form',
27
+ type: 'ref',
28
+ refId: 'com.ronds.schema.default.Rule.Form',
29
+ value: {}
30
+ }]
31
+ };
32
+
33
+ var renderProp = function renderProp(node, setting) {
34
+ var _prop = deepClone(EMPTY_PROP);
35
+
36
+ var _setting = setting && deepClone(setting) || {};
37
+
38
+ _prop.id = (_setting === null || _setting === void 0 ? void 0 : _setting.id) || node.id;
39
+ _prop.type = node.param.type; // ref类型加上refId
40
+
41
+ if (node.param.type === 'ref') {
42
+ _prop.refId = "".concat(_prop.id, "_ref");
43
+ } // array类型加上 items
44
+
45
+
46
+ if (node.param.type === 'array') {
47
+ var _items = {
48
+ type: 'ref',
49
+ refId: "".concat(_prop.id, "_ref")
50
+ };
51
+ _prop.items = _items;
52
+ }
53
+
54
+ var typeValue = _setting[node.param.type];
55
+ delete _setting[node.param.type];
56
+ _prop.fields[0].value = _defineProperty({
57
+ common: _objectSpread(_objectSpread({}, _setting), {}, {
58
+ label: (_setting === null || _setting === void 0 ? void 0 : _setting.label) || node.name
59
+ })
60
+ }, node.param.type, _objectSpread(_objectSpread({}, node.param.rule || {}), typeValue));
61
+ return _prop;
62
+ }; // FG配置生成 metedata
63
+
64
+
65
+ export var transFG2Schema = function transFG2Schema(nodes, settings, _types, schemaId) {
66
+ try {
67
+ var schema = deepClone(EMPTY_OBJ);
68
+
69
+ if (schemaId) {
70
+ schema[0].id = schemaId;
71
+ }
72
+
73
+ var props = [];
74
+ var types = [];
75
+
76
+ for (var i = 0; i < nodes.length; i++) {
77
+ var _prop = renderProp(nodes[i], settings && settings[nodes[i].id]);
78
+
79
+ props.push(_prop);
80
+ }
81
+
82
+ schema[0].properties = [].concat(props);
83
+
84
+ if (settings && (settings === null || settings === void 0 ? void 0 : settings.formSetting)) {
85
+ schema[0].fields[0].value = deepClone(settings.formSetting);
86
+ } else {
87
+ delete schema[0].fields;
88
+ }
89
+
90
+ if (_types) {
91
+ var typeKeys = Object.keys(_types);
92
+
93
+ for (var _i = 0; _i < typeKeys.length; _i++) {
94
+ var _type = transFG2Schema(_types[typeKeys[_i]].nodes, settings["".concat(typeKeys[_i], "_ref")], undefined, "".concat(_types[typeKeys[_i]].id, "_ref"));
95
+
96
+ types.push(_type[0]);
97
+ }
98
+ }
99
+
100
+ if (types.length > 0) {
101
+ schema[0].types = [].concat(types);
102
+ }
103
+
104
+ return schema;
105
+ } catch (error) {
106
+ console.warn('transFG2Schema.err', error);
107
+ }
108
+ };
109
+
110
+ var renderJson = function renderJson(comps, type, id, field) {
111
+ var _comps = deepClone(comps);
112
+
113
+ var node = _comps.find(function (it) {
114
+ return it.type === type;
115
+ });
116
+
117
+ if (node) {
118
+ var _field$common;
119
+
120
+ node.id = id;
121
+ node.name = (field === null || field === void 0 ? void 0 : (_field$common = field.common) === null || _field$common === void 0 ? void 0 : _field$common.label) || node.name;
122
+ }
123
+
124
+ var setting = {};
125
+
126
+ if (field) {
127
+ var _field = deepClone(field);
128
+
129
+ _field = _objectSpread(_objectSpread({}, _field), _field.common);
130
+ _field.id = id;
131
+ delete _field.common;
132
+ setting = _defineProperty({}, id, _objectSpread({}, _field));
133
+ }
134
+
135
+ return {
136
+ node: node,
137
+ setting: setting
138
+ };
139
+ };
140
+
141
+ var getTypeJson = function getTypeJson(id, type, field) {
142
+ var res = {
143
+ node: {},
144
+ setting: {}
145
+ };
146
+
147
+ if (type === 'text') {
148
+ var _field$text, _field$text2, _field$text4, _field$text6, _field$text8, _field$text10;
149
+
150
+ // input
151
+ if (!(field === null || field === void 0 ? void 0 : (_field$text = field.text) === null || _field$text === void 0 ? void 0 : _field$text.type)) {
152
+ res = renderJson(basicComps, 'input', id, field);
153
+ } // textarea
154
+
155
+
156
+ if ((field === null || field === void 0 ? void 0 : (_field$text2 = field.text) === null || _field$text2 === void 0 ? void 0 : _field$text2.type) === 'textarea') {
157
+ var _field$text3;
158
+
159
+ field === null || field === void 0 ? true : (_field$text3 = field.text) === null || _field$text3 === void 0 ? true : delete _field$text3.type;
160
+ res = renderJson(basicComps, 'textarea', id, field);
161
+ } // date
162
+
163
+
164
+ if ((field === null || field === void 0 ? void 0 : (_field$text4 = field.text) === null || _field$text4 === void 0 ? void 0 : _field$text4.type) === 'datePicker') {
165
+ var _field$text5;
166
+
167
+ field === null || field === void 0 ? true : (_field$text5 = field.text) === null || _field$text5 === void 0 ? true : delete _field$text5.type;
168
+ res = renderJson(basicComps, 'date', id, field);
169
+ } // color
170
+
171
+
172
+ if ((field === null || field === void 0 ? void 0 : (_field$text6 = field.text) === null || _field$text6 === void 0 ? void 0 : _field$text6.type) === 'colorPicker') {
173
+ var _field$text7;
174
+
175
+ field === null || field === void 0 ? true : (_field$text7 = field.text) === null || _field$text7 === void 0 ? true : delete _field$text7.type;
176
+ res = renderJson(complexComps, 'color', id, field);
177
+ } // password
178
+
179
+
180
+ if ((field === null || field === void 0 ? void 0 : (_field$text8 = field.text) === null || _field$text8 === void 0 ? void 0 : _field$text8.type) === 'password') {
181
+ var _field$text9;
182
+
183
+ field === null || field === void 0 ? true : (_field$text9 = field.text) === null || _field$text9 === void 0 ? true : delete _field$text9.type;
184
+ res = renderJson(complexComps, 'password', id, field);
185
+ } // upload
186
+
187
+
188
+ if ((field === null || field === void 0 ? void 0 : (_field$text10 = field.text) === null || _field$text10 === void 0 ? void 0 : _field$text10.type) === 'upload') {
189
+ var _field$text11;
190
+
191
+ field === null || field === void 0 ? true : (_field$text11 = field.text) === null || _field$text11 === void 0 ? true : delete _field$text11.type;
192
+ res = renderJson(complexComps, 'upload', id, field);
193
+ }
194
+ } // number
195
+
196
+
197
+ if (type === 'number') {
198
+ res = renderJson(basicComps, 'number', id, field);
199
+ } // switch
200
+
201
+
202
+ if (type === 'bool') {
203
+ res = renderJson(basicComps, 'switch', id, field);
204
+ } // enum
205
+
206
+
207
+ if (type === 'enum') {
208
+ var _field$enum, _field$enum2, _field$enum3, _field$enum4;
209
+
210
+ // select
211
+ if ((field === null || field === void 0 ? void 0 : (_field$enum = field.enum) === null || _field$enum === void 0 ? void 0 : _field$enum.type) !== 'checkbox' && !field.enum.isMutiple) {
212
+ res = renderJson(basicComps, 'select', id, field);
213
+ } // mutiSelect
214
+
215
+
216
+ if ((field === null || field === void 0 ? void 0 : (_field$enum2 = field.enum) === null || _field$enum2 === void 0 ? void 0 : _field$enum2.type) !== 'checkbox' && field.enum.isMutiple) {
217
+ res = renderJson(basicComps, 'mutiSelect', id, field);
218
+ } // checkbox
219
+
220
+
221
+ if ((field === null || field === void 0 ? void 0 : (_field$enum3 = field.enum) === null || _field$enum3 === void 0 ? void 0 : _field$enum3.type) === 'checkbox' && field.enum.isMutiple) {
222
+ res = renderJson(complexComps, 'checkbox', id, field);
223
+ } // radio
224
+
225
+
226
+ if ((field === null || field === void 0 ? void 0 : (_field$enum4 = field.enum) === null || _field$enum4 === void 0 ? void 0 : _field$enum4.type) === 'checkbox' && !field.enum.isMutiple) {
227
+ res = renderJson(complexComps, 'radio', id, field);
228
+ }
229
+ } // obj
230
+
231
+
232
+ if (type === 'ref') {
233
+ res = renderJson(layoutComps, 'obj', id, field);
234
+ } // list
235
+
236
+
237
+ if (type === 'array') {
238
+ res = renderJson(layoutComps, 'list', id, field);
239
+ }
240
+
241
+ return res;
242
+ };
243
+
244
+ var processProps = function processProps(prop) {
245
+ // 获取是什么类型的组件
246
+ var obj = getTypeJson(prop.id, prop.type, (prop === null || prop === void 0 ? void 0 : prop.fields) && (prop === null || prop === void 0 ? void 0 : prop.fields[0].value));
247
+ return obj;
248
+ };
249
+
250
+ var getTypeParent = function getTypeParent(refId, _props) {
251
+ var _ = _props.find(function (it) {
252
+ var _it$items;
253
+
254
+ return (it === null || it === void 0 ? void 0 : it.refId) === refId || (it === null || it === void 0 ? void 0 : (_it$items = it.items) === null || _it$items === void 0 ? void 0 : _it$items.refId) === refId;
255
+ });
256
+
257
+ return _;
258
+ }; // metadata 生成FG配置
259
+
260
+
261
+ export var transSchema2FG = function transSchema2FG(schema) {
262
+ var _schema$;
263
+
264
+ var res = {
265
+ nodes: [],
266
+ settings: {},
267
+ types: {}
268
+ };
269
+ var _props = schema[0].properties;
270
+
271
+ for (var i = 0; i < _props.length; i++) {
272
+ var obj = processProps(_props[i]);
273
+ res.nodes.push(obj.node);
274
+ res.settings = _objectSpread(_objectSpread({}, res.settings), obj.setting);
275
+ }
276
+
277
+ var _types = (_schema$ = schema[0]) === null || _schema$ === void 0 ? void 0 : _schema$.types;
278
+
279
+ if (_types && _types.length > 0) {
280
+ for (var _i2 = 0; _i2 < _types.length; _i2++) {
281
+ var _parent = getTypeParent(_types[_i2].id, _props);
282
+
283
+ if (_parent) {
284
+ var _schema = deepClone(_types[_i2]);
285
+
286
+ _schema.id = "".concat(_parent.id, "_ref");
287
+
288
+ var _ = transSchema2FG([_schema]);
289
+
290
+ res.types[_parent.id] = {
291
+ id: _parent.id,
292
+ nodes: _.nodes
293
+ };
294
+ res.settings[_schema.id] = _.settings;
295
+ }
296
+ }
297
+ }
298
+
299
+ return res;
300
+ };
@@ -0,0 +1,23 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import React from "react";
3
+
4
+ /*
5
+ * @Author: wangxian
6
+ * @Date: 2022-05-28 11:04:20
7
+ * @LastEditTime: 2023-02-24 09:09:51
8
+ */
9
+ import '../../framework/libs/iconfont/iconfont.css';
10
+
11
+ var Icon = function Icon(props) {
12
+ var type = props.type,
13
+ _props$className = props.className,
14
+ className = _props$className === void 0 ? '' : _props$className,
15
+ _props$style = props.style,
16
+ style = _props$style === void 0 ? {} : _props$style;
17
+ return /*#__PURE__*/React.createElement("span", {
18
+ className: "mt mt-".concat(type, " ").concat(className),
19
+ style: _objectSpread({}, style)
20
+ });
21
+ };
22
+
23
+ export default Icon;
@@ -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
+ }];
@@ -0,0 +1,221 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import React from 'react';
4
+ import CodeMirror from 'codemirror';
5
+ import 'codemirror/lib/codemirror.css';
6
+ import 'codemirror/theme/neo.css';
7
+ import 'codemirror/theme/panda-syntax.css';
8
+ import 'codemirror/theme/neat.css';
9
+ import 'codemirror/theme/idea.css';
10
+ import 'codemirror/mode/sql/sql.js';
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';
15
+ import 'codemirror/addon/hint/show-hint.js';
16
+ import 'codemirror/addon/hint/show-hint.css';
17
+ import 'codemirror/addon/fold/foldgutter.css';
18
+ import 'codemirror/addon/fold/foldcode';
19
+ import 'codemirror/addon/fold/foldgutter';
20
+ import 'codemirror/addon/fold/brace-fold';
21
+ import 'codemirror/addon/fold/comment-fold';
22
+ import 'codemirror/addon/selection/active-line.js';
23
+ import 'codemirror/addon/edit/closebrackets.js';
24
+ import 'codemirror/addon/edit/matchbrackets.js';
25
+ import './index.less';
26
+ import { SQL_DICO } from './constant';
27
+
28
+ var SqlEdit = function SqlEdit(props) {
29
+ var _props$theme = props.theme,
30
+ theme = _props$theme === void 0 ? 'idea' : _props$theme,
31
+ _props$extraDico = props.extraDico,
32
+ extraDico = _props$extraDico === void 0 ? [] : _props$extraDico,
33
+ _props$mode = props.mode,
34
+ mode = _props$mode === void 0 ? 'text/x-mysql' : _props$mode,
35
+ _props$isLineNumbers = props.isLineNumbers,
36
+ isLineNumbers = _props$isLineNumbers === void 0 ? true : _props$isLineNumbers,
37
+ _props$isGutters = props.isGutters,
38
+ isGutters = _props$isGutters === void 0 ? true : _props$isGutters,
39
+ _props$readOnly = props.readOnly,
40
+ readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
41
+ _props$styleActiveLin = props.styleActiveLine,
42
+ styleActiveLine = _props$styleActiveLin === void 0 ? false : _props$styleActiveLin,
43
+ value = props.value,
44
+ onChange = props.onChange,
45
+ onSelectChange = props.onSelectChange,
46
+ onReWriteEnter = props.onReWriteEnter;
47
+ var textareaRef = React.useRef(null);
48
+ var firstLoadRef = React.useRef(true);
49
+ var editorRef = React.useRef();
50
+ var extraKeys = React.useMemo(function () {
51
+ var _extraKeys = {
52
+ 'Ctrl-Space': function CtrlSpace(__editor) {
53
+ if (mode === 'text/x-mysql') {
54
+ __editor.showHint();
55
+ }
56
+ },
57
+ F7: function F7(__editor) {
58
+ var textJson = JSON.parse(__editor.getValue());
59
+ var result = JSON.stringify(textJson, undefined, 2);
60
+
61
+ __editor.setValue(result);
62
+ } // 代码格式化
63
+
64
+ };
65
+
66
+ if (onReWriteEnter) {
67
+ _extraKeys.Enter = function (__editor) {
68
+ onReWriteEnter();
69
+ };
70
+ }
71
+
72
+ return _extraKeys;
73
+ }, [mode, onReWriteEnter]);
74
+ var dico = React.useMemo(function () {
75
+ var res = SQL_DICO;
76
+
77
+ if (extraDico.length > 0) {
78
+ res = [].concat(_toConsumableArray(SQL_DICO), _toConsumableArray(extraDico));
79
+ }
80
+
81
+ return res;
82
+ }, [extraDico]);
83
+ var initEdit = React.useCallback(function () {
84
+ if (textareaRef.current === null) return;
85
+ if (!firstLoadRef.current) return;
86
+
87
+ var _editor = CodeMirror.fromTextArea(textareaRef.current, {
88
+ value: value,
89
+ tabSize: 4,
90
+ mode: mode,
91
+ theme: theme,
92
+ readOnly: readOnly,
93
+ lineNumbers: isLineNumbers,
94
+ lineWrapping: true,
95
+ foldGutter: true,
96
+ lint: true,
97
+ gutters: isGutters ? ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'] : [],
98
+ hintOptions: {
99
+ completeSingle: false,
100
+ hint: hint
101
+ },
102
+ matchBrackets: true,
103
+ autoCloseBrackets: true,
104
+ smartIndent: true,
105
+ styleActiveLine: styleActiveLine,
106
+ extraKeys: extraKeys
107
+ });
108
+
109
+ _editor.on('keypress', function (__editor) {
110
+ if (mode === 'text/x-mysql') {
111
+ __editor.showHint();
112
+ }
113
+ });
114
+
115
+ _editor.on('change', function (__editor) {
116
+ onChange && onChange(__editor.getValue());
117
+ });
118
+
119
+ _editor.on('cursorActivity', function (__editor) {
120
+ onSelectChange && onSelectChange(__editor.getSelection());
121
+ });
122
+
123
+ editorRef.current = _editor;
124
+ firstLoadRef.current = false;
125
+ }, [dico, isGutters, readOnly, isLineNumbers]);
126
+ React.useEffect(function () {
127
+ if (!textareaRef.current) return;
128
+ initEdit();
129
+ }, [textareaRef, initEdit]);
130
+ React.useEffect(function () {
131
+ if (!editorRef.current) return;
132
+
133
+ if (value || value === '') {
134
+ editorRef.current.setValue(value);
135
+ editorRef.current.focus();
136
+ editorRef.current.setCursor(editorRef.current.lineCount(), 0);
137
+ }
138
+ }, [value]);
139
+ React.useEffect(function () {
140
+ if (!editorRef.current) return;
141
+ editorRef.current.setOption('readOnly', readOnly ? 'nocursor' : readOnly);
142
+ editorRef.current.setOption('lineNumbers', isLineNumbers);
143
+ editorRef.current.setOption('gutters', isGutters ? ['CodeMirror-linenumbers', 'CodeMirror-foldgutter', 'CodeMirror-lint-markers'] : []);
144
+ }, [readOnly, isLineNumbers, isGutters]);
145
+
146
+ var hint = function hint(__editor) {
147
+ var cur = __editor.getCursor();
148
+
149
+ var token = __editor.getTokenAt(cur);
150
+
151
+ var searchString = token.string;
152
+ return {
153
+ list: suggest(searchString),
154
+ from: CodeMirror.Pos(cur.line, token.start),
155
+ to: CodeMirror.Pos(cur.line, token.end)
156
+ };
157
+ };
158
+
159
+ var suggest = function suggest(searchString) {
160
+ /*
161
+ we will score which suggesion should appears first, the higer the score, the higer is the appearance order
162
+ */
163
+ var token = searchString;
164
+ var isDot = false;
165
+
166
+ if (searchString.startsWith('.')) {
167
+ token = searchString.substring(1);
168
+ isDot = true;
169
+ }
170
+
171
+ token = searchString.toLowerCase();
172
+ var resu = [];
173
+ var N = dico.length; // init scoring: only retains and score suggestions which contain the searchString
174
+
175
+ for (var i = 0; i < N; i++) {
176
+ var suggestion = null; // 支持.之后联想
177
+
178
+ var _suggestion = {
179
+ className: dico[i].className,
180
+ text: "".concat(isDot ? '.' : '').concat(dico[i].text)
181
+ };
182
+
183
+ var keyword = _suggestion.text.toLowerCase();
184
+
185
+ if (keyword.startsWith(token)) {
186
+ // add N to the score of keywords which begin with the token to make them raise up in the suggestion list
187
+ suggestion = _objectSpread(_objectSpread({}, {
188
+ score: N + (N - i)
189
+ }), _suggestion);
190
+ } else if (keyword.includes(token)) {
191
+ suggestion = _objectSpread(_objectSpread({}, {
192
+ score: N - i
193
+ }), _suggestion);
194
+ }
195
+
196
+ if (suggestion) resu.push(suggestion);
197
+ } // case suggestion for "."
198
+
199
+
200
+ if (searchString.startsWith('.')) {
201
+ // raise score of columns, decrease the score of sql keyword
202
+ resu.forEach(function (s) {
203
+ if (s.className === 'column') s.score += N;else if (s.className === 'sql') s.score -= N;
204
+ return s;
205
+ });
206
+ } // console.log(searchString);
207
+
208
+
209
+ return resu.sort(function (a, b) {
210
+ return b.score - a.score;
211
+ });
212
+ };
213
+
214
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("textarea", {
215
+ ref: textareaRef,
216
+ defaultValue: value,
217
+ className: "my-txt"
218
+ }));
219
+ };
220
+
221
+ export default SqlEdit;