@fc-components/monaco-editor 0.1.16 → 0.1.18
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.
- package/dist/index.d.ts +2 -0
- package/dist/monaco-editor.cjs.development.js +501 -12
- package/dist/monaco-editor.cjs.development.js.map +1 -1
- package/dist/monaco-editor.cjs.production.min.js +1 -1
- package/dist/monaco-editor.cjs.production.min.js.map +1 -1
- package/dist/monaco-editor.esm.js +501 -13
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/DataProvider.d.ts +3 -2
- package/dist/promql/index.d.ts +1 -0
- package/dist/promql/types.d.ts +1 -0
- package/dist/sql/completion/getCompletionProvider.d.ts +4 -0
- package/dist/sql/index.d.ts +17 -0
- package/dist/sql/sql.d.ts +85 -0
- package/dist/sql/types.d.ts +8 -0
- package/dist/sql/validation.d.ts +2 -0
- package/package.json +1 -1
- package/src/index.tsx +2 -0
- package/src/promql/completion/DataProvider.ts +22 -1
- package/src/promql/index.tsx +5 -0
- package/src/promql/types.ts +2 -0
- package/src/sql/README.md +140 -0
- package/src/sql/completion/getCompletionProvider.ts +125 -0
- package/src/sql/index.tsx +263 -0
- package/src/sql/sql.ts +250 -0
- package/src/sql/types.ts +8 -0
- package/src/sql/validation.ts +92 -0
package/dist/index.d.ts
CHANGED
|
@@ -880,6 +880,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
880
880
|
this.variablesNames = [];
|
|
881
881
|
this.httpMethod = 'GET';
|
|
882
882
|
this.apiPrefix = '/api/v1';
|
|
883
|
+
this.enableRequests = true;
|
|
883
884
|
this.customRequest = function (input, init) {
|
|
884
885
|
return fetch(input, init);
|
|
885
886
|
};
|
|
@@ -889,6 +890,12 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
889
890
|
return _regenerator().w(function (_context) {
|
|
890
891
|
while (1) switch (_context.n) {
|
|
891
892
|
case 0:
|
|
893
|
+
if (_this.enableRequests) {
|
|
894
|
+
_context.n = 1;
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
897
|
+
return _context.a(2, []);
|
|
898
|
+
case 1:
|
|
892
899
|
end = new Date();
|
|
893
900
|
start = new Date(end.getTime() - _this.lookbackInterval);
|
|
894
901
|
url = _this.apiPrefix + "/series";
|
|
@@ -905,14 +912,14 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
905
912
|
});
|
|
906
913
|
}
|
|
907
914
|
request = _this.buildRequest(url, new URLSearchParams(urlParams));
|
|
908
|
-
_context.n =
|
|
915
|
+
_context.n = 2;
|
|
909
916
|
return _this.request(request.uri, {
|
|
910
917
|
method: _this.httpMethod,
|
|
911
918
|
body: request.body
|
|
912
919
|
})["catch"](function () {
|
|
913
920
|
return [];
|
|
914
921
|
});
|
|
915
|
-
case
|
|
922
|
+
case 2:
|
|
916
923
|
return _context.a(2, _context.v);
|
|
917
924
|
}
|
|
918
925
|
}, _callee);
|
|
@@ -927,6 +934,12 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
927
934
|
return _regenerator().w(function (_context2) {
|
|
928
935
|
while (1) switch (_context2.n) {
|
|
929
936
|
case 0:
|
|
937
|
+
if (_this.enableRequests) {
|
|
938
|
+
_context2.n = 1;
|
|
939
|
+
break;
|
|
940
|
+
}
|
|
941
|
+
return _context2.a(2, []);
|
|
942
|
+
case 1:
|
|
930
943
|
end = new Date();
|
|
931
944
|
start = new Date(end.getTime() - _this.lookbackInterval);
|
|
932
945
|
url = _this.apiPrefix + "/labels";
|
|
@@ -938,7 +951,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
938
951
|
urlParams['match[]'] = selector;
|
|
939
952
|
}
|
|
940
953
|
request = _this.buildRequest(url, new URLSearchParams(urlParams));
|
|
941
|
-
_context2.n =
|
|
954
|
+
_context2.n = 2;
|
|
942
955
|
return _this.request(request.uri, {
|
|
943
956
|
method: _this.httpMethod,
|
|
944
957
|
body: request.body
|
|
@@ -948,7 +961,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
948
961
|
})["catch"](function () {
|
|
949
962
|
return [];
|
|
950
963
|
});
|
|
951
|
-
case
|
|
964
|
+
case 2:
|
|
952
965
|
return _context2.a(2, _context2.v);
|
|
953
966
|
}
|
|
954
967
|
}, _callee2);
|
|
@@ -963,6 +976,12 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
963
976
|
return _regenerator().w(function (_context3) {
|
|
964
977
|
while (1) switch (_context3.n) {
|
|
965
978
|
case 0:
|
|
979
|
+
if (_this.enableRequests) {
|
|
980
|
+
_context3.n = 1;
|
|
981
|
+
break;
|
|
982
|
+
}
|
|
983
|
+
return _context3.a(2, []);
|
|
984
|
+
case 1:
|
|
966
985
|
end = new Date();
|
|
967
986
|
start = new Date(end.getTime() - _this.lookbackInterval);
|
|
968
987
|
url = _this.apiPrefix + "/label/" + labelName + "/values";
|
|
@@ -974,14 +993,14 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
974
993
|
urlParams['match[]'] = selector;
|
|
975
994
|
}
|
|
976
995
|
request = _this.buildRequest(url, new URLSearchParams(urlParams));
|
|
977
|
-
_context3.n =
|
|
996
|
+
_context3.n = 2;
|
|
978
997
|
return _this.request(request.uri, {
|
|
979
998
|
method: _this.httpMethod,
|
|
980
999
|
body: request.body
|
|
981
1000
|
})["catch"](function () {
|
|
982
1001
|
return [];
|
|
983
1002
|
});
|
|
984
|
-
case
|
|
1003
|
+
case 2:
|
|
985
1004
|
return _context3.a(2, _context3.v);
|
|
986
1005
|
}
|
|
987
1006
|
}, _callee3);
|
|
@@ -1031,6 +1050,10 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
1031
1050
|
if (params.apiPrefix) {
|
|
1032
1051
|
this.apiPrefix = params.apiPrefix;
|
|
1033
1052
|
}
|
|
1053
|
+
// control whether DataProvider should actually send network requests
|
|
1054
|
+
if (typeof params.enableRequests !== 'undefined') {
|
|
1055
|
+
this.enableRequests = !!params.enableRequests;
|
|
1056
|
+
}
|
|
1034
1057
|
this.metrics = [];
|
|
1035
1058
|
this.labelKeys = [];
|
|
1036
1059
|
}
|
|
@@ -1094,18 +1117,24 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
1094
1117
|
return _regenerator().w(function (_context5) {
|
|
1095
1118
|
while (1) switch (_context5.n) {
|
|
1096
1119
|
case 0:
|
|
1120
|
+
if (this.enableRequests) {
|
|
1121
|
+
_context5.n = 1;
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
this.metricsMetadata = {};
|
|
1125
|
+
return _context5.a(2, this.metricsMetadata);
|
|
1126
|
+
case 1:
|
|
1097
1127
|
request = this.buildRequest(this.apiPrefix + "/metadata", new URLSearchParams({}));
|
|
1098
|
-
_context5.n =
|
|
1128
|
+
_context5.n = 2;
|
|
1099
1129
|
return this.request(request.uri, {
|
|
1100
1130
|
method: this.httpMethod,
|
|
1101
1131
|
body: request.body
|
|
1102
1132
|
})["catch"](function () {
|
|
1103
1133
|
return {};
|
|
1104
1134
|
});
|
|
1105
|
-
case 1:
|
|
1106
|
-
this.metricsMetadata = _context5.v;
|
|
1107
1135
|
case 2:
|
|
1108
|
-
|
|
1136
|
+
this.metricsMetadata = _context5.v;
|
|
1137
|
+
return _context5.a(2, this.metricsMetadata || {});
|
|
1109
1138
|
}
|
|
1110
1139
|
}, _callee5, this);
|
|
1111
1140
|
}));
|
|
@@ -2005,6 +2034,8 @@ function PromQLEditor(props) {
|
|
|
2005
2034
|
interpolateString = props.interpolateString,
|
|
2006
2035
|
_props$enableAutocomp = props.enableAutocomplete,
|
|
2007
2036
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
2037
|
+
_props$enableRequests = props.enableRequests,
|
|
2038
|
+
enableRequests = _props$enableRequests === void 0 ? true : _props$enableRequests,
|
|
2008
2039
|
_props$readOnly = props.readOnly,
|
|
2009
2040
|
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
2010
2041
|
_props$disabled = props.disabled,
|
|
@@ -2157,7 +2188,8 @@ function PromQLEditor(props) {
|
|
|
2157
2188
|
request: props.request,
|
|
2158
2189
|
httpMethod: props.httpMethod,
|
|
2159
2190
|
apiPrefix: props.apiPrefix,
|
|
2160
|
-
httpErrorHandler: props.httpErrorHandler
|
|
2191
|
+
httpErrorHandler: props.httpErrorHandler,
|
|
2192
|
+
enableRequests: enableRequests
|
|
2161
2193
|
});
|
|
2162
2194
|
dataProviderRef.current = dataProvider;
|
|
2163
2195
|
dataProvider.start();
|
|
@@ -2204,7 +2236,7 @@ function PromQLEditor(props) {
|
|
|
2204
2236
|
checkDecorators();
|
|
2205
2237
|
editor.onDidChangeModelContent(checkDecorators);
|
|
2206
2238
|
}
|
|
2207
|
-
}, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder]);
|
|
2239
|
+
}, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder, enableRequests]);
|
|
2208
2240
|
return React__default.createElement("div", {
|
|
2209
2241
|
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName : '') + (readOnly ? " " + containerReadOnlyClassName : '')
|
|
2210
2242
|
}, React__default.createElement("div", {
|
|
@@ -3182,6 +3214,463 @@ function YamlEditor(props) {
|
|
|
3182
3214
|
})));
|
|
3183
3215
|
}
|
|
3184
3216
|
|
|
3217
|
+
var languageConfiguration$2 = {
|
|
3218
|
+
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
|
3219
|
+
comments: {
|
|
3220
|
+
lineComment: '--',
|
|
3221
|
+
blockComment: ['/*', '*/']
|
|
3222
|
+
},
|
|
3223
|
+
brackets: [['{', '}'], ['[', ']'], ['(', ')']],
|
|
3224
|
+
autoClosingPairs: [{
|
|
3225
|
+
open: '{',
|
|
3226
|
+
close: '}'
|
|
3227
|
+
}, {
|
|
3228
|
+
open: '[',
|
|
3229
|
+
close: ']'
|
|
3230
|
+
}, {
|
|
3231
|
+
open: '(',
|
|
3232
|
+
close: ')'
|
|
3233
|
+
}, {
|
|
3234
|
+
open: '"',
|
|
3235
|
+
close: '"'
|
|
3236
|
+
}, {
|
|
3237
|
+
open: "'",
|
|
3238
|
+
close: "'"
|
|
3239
|
+
}, {
|
|
3240
|
+
open: '`',
|
|
3241
|
+
close: '`'
|
|
3242
|
+
}],
|
|
3243
|
+
surroundingPairs: [{
|
|
3244
|
+
open: '{',
|
|
3245
|
+
close: '}'
|
|
3246
|
+
}, {
|
|
3247
|
+
open: '[',
|
|
3248
|
+
close: ']'
|
|
3249
|
+
}, {
|
|
3250
|
+
open: '(',
|
|
3251
|
+
close: ')'
|
|
3252
|
+
}, {
|
|
3253
|
+
open: '"',
|
|
3254
|
+
close: '"'
|
|
3255
|
+
}, {
|
|
3256
|
+
open: "'",
|
|
3257
|
+
close: "'"
|
|
3258
|
+
}, {
|
|
3259
|
+
open: '`',
|
|
3260
|
+
close: '`'
|
|
3261
|
+
}],
|
|
3262
|
+
folding: {
|
|
3263
|
+
offSide: false
|
|
3264
|
+
}
|
|
3265
|
+
};
|
|
3266
|
+
// SQL keywords
|
|
3267
|
+
var keywords$2 = ['SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'NOT', 'JOIN', 'INNER', 'LEFT', 'RIGHT', 'FULL', 'OUTER', 'ON', 'ORDER', 'BY', 'GROUP', 'HAVING', 'LIMIT', 'OFFSET', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE', 'CREATE', 'TABLE', 'ALTER', 'DROP', 'PRIMARY', 'KEY', 'FOREIGN', 'CONSTRAINT', 'UNIQUE', 'INDEX', 'VIEW', 'DATABASE', 'SCHEMA', 'AS', 'DISTINCT', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END', 'CAST', 'BETWEEN', 'IN', 'LIKE', 'IS', 'NULL', 'TRUE', 'FALSE', 'WITH', 'UNION', 'EXCEPT', 'INTERSECT'];
|
|
3268
|
+
var language$2 = {
|
|
3269
|
+
defaultToken: '',
|
|
3270
|
+
tokenPostfix: '.sql',
|
|
3271
|
+
ignoreCase: true,
|
|
3272
|
+
brackets: [{
|
|
3273
|
+
open: '(',
|
|
3274
|
+
close: ')',
|
|
3275
|
+
token: 'delimiter.parenthesis'
|
|
3276
|
+
}, {
|
|
3277
|
+
open: '{',
|
|
3278
|
+
close: '}',
|
|
3279
|
+
token: 'delimiter.curly'
|
|
3280
|
+
}, {
|
|
3281
|
+
open: '[',
|
|
3282
|
+
close: ']',
|
|
3283
|
+
token: 'delimiter.square'
|
|
3284
|
+
}],
|
|
3285
|
+
keywords: keywords$2,
|
|
3286
|
+
operators: ['=', '>', '<', '!', '%', '&', '|', '^', '~', '?', ':', '+', '-', '*', '/'],
|
|
3287
|
+
builtinFunctions: ['COUNT', 'SUM', 'AVG', 'MIN', 'MAX', 'UPPER', 'LOWER', 'LENGTH', 'SUBSTRING', 'TRIM', 'ROUND', 'ABS', 'COALESCE', 'NULLIF', 'IFNULL', 'CONCAT', 'DATE', 'NOW', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'],
|
|
3288
|
+
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
3289
|
+
digits: /\d+(_+\d+)*/,
|
|
3290
|
+
octaldigits: /[0-7]+(_+[0-7]+)*/,
|
|
3291
|
+
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
|
|
3292
|
+
regexpctl: /[(){}\[\]\|;,.?*+^$\\]/,
|
|
3293
|
+
regexpattern: /(\{[0-9]+\})|(\{[0-9]*,[0-9]*\})|(\?(?:\?)?|[*+]|\^|\$|\|\\)/,
|
|
3294
|
+
tokenizer: {
|
|
3295
|
+
root: [{
|
|
3296
|
+
include: '@comments'
|
|
3297
|
+
}, {
|
|
3298
|
+
include: '@whitespace'
|
|
3299
|
+
}, {
|
|
3300
|
+
include: '@pseudo-columns'
|
|
3301
|
+
}, [/[;,.]/, 'delimiter'], [/[{}()\[\]]/, '@brackets'], {
|
|
3302
|
+
include: '@builtinVariables'
|
|
3303
|
+
}, {
|
|
3304
|
+
include: '@numbers'
|
|
3305
|
+
}, {
|
|
3306
|
+
include: '@strings'
|
|
3307
|
+
}, [/[a-zA-Z_#][a-zA-Z0-9_$#@]*(?=\s*\()/, {
|
|
3308
|
+
cases: {
|
|
3309
|
+
'@builtinFunctions': 'keyword.function',
|
|
3310
|
+
'@default': 'identifier.function'
|
|
3311
|
+
}
|
|
3312
|
+
}], [/[a-zA-Z_#][a-zA-Z0-9_$#@]*/, {
|
|
3313
|
+
cases: {
|
|
3314
|
+
'@keywords': 'keyword',
|
|
3315
|
+
'@default': 'identifier'
|
|
3316
|
+
}
|
|
3317
|
+
}], [/[<>=!%&+\-*/|~^]/, 'operator']],
|
|
3318
|
+
whitespace: [[/\s+/, 'white']],
|
|
3319
|
+
comments: [[/--+.*/, 'comment'], [/\/\*/, {
|
|
3320
|
+
token: 'comment.quote',
|
|
3321
|
+
next: '@comment'
|
|
3322
|
+
}]],
|
|
3323
|
+
comment: [[/[^*/]+/, 'comment'], [/\*\//, {
|
|
3324
|
+
token: 'comment.quote',
|
|
3325
|
+
next: '@pop'
|
|
3326
|
+
}], [/./, 'comment']],
|
|
3327
|
+
'pseudo-columns': [[/[$][A-Za-z_][A-Za-z0-9_]*/, {
|
|
3328
|
+
cases: {
|
|
3329
|
+
'@keywords': 'keyword',
|
|
3330
|
+
'@default': 'variable'
|
|
3331
|
+
}
|
|
3332
|
+
}], [/@[A-Za-z_][A-Za-z0-9_]*/, {
|
|
3333
|
+
cases: {
|
|
3334
|
+
'@keywords': 'keyword',
|
|
3335
|
+
'@default': 'variable'
|
|
3336
|
+
}
|
|
3337
|
+
}]],
|
|
3338
|
+
builtinVariables: [[/@@?[a-zA-Z_][a-zA-Z0-9_]*/, {
|
|
3339
|
+
cases: {
|
|
3340
|
+
'@keywords': 'keyword',
|
|
3341
|
+
'@default': 'variable'
|
|
3342
|
+
}
|
|
3343
|
+
}]],
|
|
3344
|
+
numbers: [[/0[xX][0-9a-fA-F]*[0-9a-fA-F]/, 'number.hex'], [/0[0-7]+(?!\d)/, 'number.octal'], [/(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?/, 'number']],
|
|
3345
|
+
strings: [[/'/, {
|
|
3346
|
+
token: 'string',
|
|
3347
|
+
next: '@string'
|
|
3348
|
+
}], [/"/, {
|
|
3349
|
+
token: 'string.double',
|
|
3350
|
+
next: '@string_double'
|
|
3351
|
+
}], [/`/, {
|
|
3352
|
+
token: 'string.backtick',
|
|
3353
|
+
next: '@string_backtick'
|
|
3354
|
+
}]],
|
|
3355
|
+
string: [[/[^'\\]+/, 'string'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/'/, {
|
|
3356
|
+
token: 'string',
|
|
3357
|
+
next: '@pop'
|
|
3358
|
+
}]],
|
|
3359
|
+
string_double: [[/[^"\\]+/, 'string.double'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/"/, {
|
|
3360
|
+
token: 'string.double',
|
|
3361
|
+
next: '@pop'
|
|
3362
|
+
}]],
|
|
3363
|
+
string_backtick: [[/[^`\\]+/, 'string.backtick'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/`/, {
|
|
3364
|
+
token: 'string.backtick',
|
|
3365
|
+
next: '@pop'
|
|
3366
|
+
}]]
|
|
3367
|
+
}
|
|
3368
|
+
};
|
|
3369
|
+
|
|
3370
|
+
var SQL_KEYWORDS = ['SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'NOT', 'JOIN', 'INNER', 'LEFT', 'RIGHT', 'FULL', 'OUTER', 'ON', 'ORDER', 'BY', 'GROUP', 'HAVING', 'LIMIT', 'OFFSET', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE', 'CREATE', 'TABLE', 'ALTER', 'DROP', 'PRIMARY', 'KEY', 'FOREIGN', 'CONSTRAINT', 'UNIQUE', 'INDEX', 'VIEW', 'DATABASE', 'SCHEMA', 'AS', 'DISTINCT', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END', 'CAST', 'BETWEEN', 'IN', 'LIKE', 'IS', 'NULL', 'TRUE', 'FALSE', 'WITH', 'UNION', 'EXCEPT', 'INTERSECT', 'ASC', 'DESC', 'ALL', 'ANY', 'EXISTS', 'CROSS'];
|
|
3371
|
+
var SQL_FUNCTIONS = [{
|
|
3372
|
+
name: 'COUNT',
|
|
3373
|
+
signature: 'COUNT(expression)',
|
|
3374
|
+
description: 'Returns the number of rows'
|
|
3375
|
+
}, {
|
|
3376
|
+
name: 'SUM',
|
|
3377
|
+
signature: 'SUM(expression)',
|
|
3378
|
+
description: 'Returns the sum of values'
|
|
3379
|
+
}, {
|
|
3380
|
+
name: 'AVG',
|
|
3381
|
+
signature: 'AVG(expression)',
|
|
3382
|
+
description: 'Returns the average value'
|
|
3383
|
+
}, {
|
|
3384
|
+
name: 'MIN',
|
|
3385
|
+
signature: 'MIN(expression)',
|
|
3386
|
+
description: 'Returns the minimum value'
|
|
3387
|
+
}, {
|
|
3388
|
+
name: 'MAX',
|
|
3389
|
+
signature: 'MAX(expression)',
|
|
3390
|
+
description: 'Returns the maximum value'
|
|
3391
|
+
}, {
|
|
3392
|
+
name: 'UPPER',
|
|
3393
|
+
signature: 'UPPER(string)',
|
|
3394
|
+
description: 'Converts string to uppercase'
|
|
3395
|
+
}, {
|
|
3396
|
+
name: 'LOWER',
|
|
3397
|
+
signature: 'LOWER(string)',
|
|
3398
|
+
description: 'Converts string to lowercase'
|
|
3399
|
+
}, {
|
|
3400
|
+
name: 'LENGTH',
|
|
3401
|
+
signature: 'LENGTH(string)',
|
|
3402
|
+
description: 'Returns the length of string'
|
|
3403
|
+
}, {
|
|
3404
|
+
name: 'SUBSTRING',
|
|
3405
|
+
signature: 'SUBSTRING(string, start, length)',
|
|
3406
|
+
description: 'Extracts substring'
|
|
3407
|
+
}, {
|
|
3408
|
+
name: 'TRIM',
|
|
3409
|
+
signature: 'TRIM(string)',
|
|
3410
|
+
description: 'Removes leading and trailing spaces'
|
|
3411
|
+
}, {
|
|
3412
|
+
name: 'ROUND',
|
|
3413
|
+
signature: 'ROUND(number, decimals)',
|
|
3414
|
+
description: 'Rounds a number'
|
|
3415
|
+
}, {
|
|
3416
|
+
name: 'ABS',
|
|
3417
|
+
signature: 'ABS(number)',
|
|
3418
|
+
description: 'Returns absolute value'
|
|
3419
|
+
}, {
|
|
3420
|
+
name: 'COALESCE',
|
|
3421
|
+
signature: 'COALESCE(value1, value2, ...)',
|
|
3422
|
+
description: 'Returns first non-null value'
|
|
3423
|
+
}, {
|
|
3424
|
+
name: 'NULLIF',
|
|
3425
|
+
signature: 'NULLIF(value1, value2)',
|
|
3426
|
+
description: 'Returns null if two values are equal'
|
|
3427
|
+
}, {
|
|
3428
|
+
name: 'IFNULL',
|
|
3429
|
+
signature: 'IFNULL(value, default)',
|
|
3430
|
+
description: 'Returns alternative if null'
|
|
3431
|
+
}, {
|
|
3432
|
+
name: 'CONCAT',
|
|
3433
|
+
signature: 'CONCAT(string1, string2, ...)',
|
|
3434
|
+
description: 'Concatenates strings'
|
|
3435
|
+
}, {
|
|
3436
|
+
name: 'DATE',
|
|
3437
|
+
signature: 'DATE(date)',
|
|
3438
|
+
description: 'Extracts date part'
|
|
3439
|
+
}, {
|
|
3440
|
+
name: 'NOW',
|
|
3441
|
+
signature: 'NOW()',
|
|
3442
|
+
description: 'Returns current date and time'
|
|
3443
|
+
}];
|
|
3444
|
+
var getSqlCompletionProvider = function getSqlCompletionProvider() {
|
|
3445
|
+
return {
|
|
3446
|
+
provideCompletionItems: function provideCompletionItems(model, position, _context, _token) {
|
|
3447
|
+
var word = model.getWordUntilPosition(position);
|
|
3448
|
+
var range = new monaco.Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
|
|
3449
|
+
var suggestions = [].concat(SQL_KEYWORDS.map(function (keyword) {
|
|
3450
|
+
return {
|
|
3451
|
+
label: keyword,
|
|
3452
|
+
kind: monaco.languages.CompletionItemKind.Keyword,
|
|
3453
|
+
insertText: keyword,
|
|
3454
|
+
range: range,
|
|
3455
|
+
sortText: '1' + keyword
|
|
3456
|
+
};
|
|
3457
|
+
}), SQL_FUNCTIONS.map(function (func) {
|
|
3458
|
+
return {
|
|
3459
|
+
label: func.name,
|
|
3460
|
+
kind: monaco.languages.CompletionItemKind.Function,
|
|
3461
|
+
insertText: func.name,
|
|
3462
|
+
detail: func.signature,
|
|
3463
|
+
documentation: func.description,
|
|
3464
|
+
range: range,
|
|
3465
|
+
sortText: '2' + func.name
|
|
3466
|
+
};
|
|
3467
|
+
}));
|
|
3468
|
+
return {
|
|
3469
|
+
suggestions: suggestions
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3472
|
+
};
|
|
3473
|
+
};
|
|
3474
|
+
|
|
3475
|
+
var _templateObject$2, _templateObject2$2;
|
|
3476
|
+
var SQL_LANG_ID = 'sql';
|
|
3477
|
+
var SIZE_MAP$2 = {
|
|
3478
|
+
small: {
|
|
3479
|
+
className: 'ant-input-sm',
|
|
3480
|
+
top: 1,
|
|
3481
|
+
bottom: 1
|
|
3482
|
+
},
|
|
3483
|
+
middle: {
|
|
3484
|
+
className: 'ant-input-md',
|
|
3485
|
+
top: 1,
|
|
3486
|
+
bottom: 1
|
|
3487
|
+
},
|
|
3488
|
+
large: {
|
|
3489
|
+
className: 'ant-input-lg',
|
|
3490
|
+
top: 3,
|
|
3491
|
+
bottom: 2
|
|
3492
|
+
}
|
|
3493
|
+
};
|
|
3494
|
+
var themeMap$2 = {
|
|
3495
|
+
light: 'sql-light',
|
|
3496
|
+
dark: 'sql-dark'
|
|
3497
|
+
};
|
|
3498
|
+
var containerDisabledClassName$2 = /*#__PURE__*/css.css(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
|
|
3499
|
+
var containerReadOnlyClassName$2 = /*#__PURE__*/css.css(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
|
|
3500
|
+
function SqlEditor(props) {
|
|
3501
|
+
var id = uuid.v4();
|
|
3502
|
+
var _props$size = props.size,
|
|
3503
|
+
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
3504
|
+
_props$theme = props.theme,
|
|
3505
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
3506
|
+
_props$value = props.value,
|
|
3507
|
+
value = _props$value === void 0 ? '' : _props$value,
|
|
3508
|
+
placeholder = props.placeholder,
|
|
3509
|
+
_props$enableAutocomp = props.enableAutocomplete,
|
|
3510
|
+
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
3511
|
+
_props$readOnly = props.readOnly,
|
|
3512
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
3513
|
+
_props$disabled = props.disabled,
|
|
3514
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
3515
|
+
onChange = props.onChange,
|
|
3516
|
+
onEnter = props.onEnter,
|
|
3517
|
+
onBlur = props.onBlur,
|
|
3518
|
+
editorDidMount = props.editorDidMount;
|
|
3519
|
+
var containerRef = React.useRef(null);
|
|
3520
|
+
var editorRef = React.useRef(null);
|
|
3521
|
+
var modelRef = React.useRef(null);
|
|
3522
|
+
var disposablesRef = React.useRef([]);
|
|
3523
|
+
React.useEffect(function () {
|
|
3524
|
+
// Register language
|
|
3525
|
+
if (!monaco.languages.getLanguages().some(function (lang) {
|
|
3526
|
+
return lang.id === SQL_LANG_ID;
|
|
3527
|
+
})) {
|
|
3528
|
+
monaco.languages.register({
|
|
3529
|
+
id: SQL_LANG_ID
|
|
3530
|
+
});
|
|
3531
|
+
monaco.languages.setMonarchTokensProvider(SQL_LANG_ID, language$2);
|
|
3532
|
+
monaco.languages.setLanguageConfiguration(SQL_LANG_ID, languageConfiguration$2);
|
|
3533
|
+
}
|
|
3534
|
+
// Register completion provider
|
|
3535
|
+
if (enableAutocomplete) {
|
|
3536
|
+
var disposable = monaco.languages.registerCompletionItemProvider(SQL_LANG_ID, getSqlCompletionProvider());
|
|
3537
|
+
disposablesRef.current.push(disposable);
|
|
3538
|
+
}
|
|
3539
|
+
return function () {
|
|
3540
|
+
disposablesRef.current.forEach(function (disposable) {
|
|
3541
|
+
return disposable.dispose();
|
|
3542
|
+
});
|
|
3543
|
+
disposablesRef.current = [];
|
|
3544
|
+
};
|
|
3545
|
+
}, [enableAutocomplete]);
|
|
3546
|
+
var handleEditorMount = function handleEditorMount(editor) {
|
|
3547
|
+
editorRef.current = editor;
|
|
3548
|
+
modelRef.current = editor.getModel();
|
|
3549
|
+
monaco.editor.defineTheme('sql-light', {
|
|
3550
|
+
base: 'vs',
|
|
3551
|
+
inherit: true,
|
|
3552
|
+
rules: [],
|
|
3553
|
+
colors: {
|
|
3554
|
+
'editor.background': '#00000000',
|
|
3555
|
+
focusBorder: '#00000000'
|
|
3556
|
+
}
|
|
3557
|
+
});
|
|
3558
|
+
monaco.editor.defineTheme('sql-dark', {
|
|
3559
|
+
base: 'vs-dark',
|
|
3560
|
+
inherit: true,
|
|
3561
|
+
rules: [],
|
|
3562
|
+
colors: {
|
|
3563
|
+
'editor.background': '#00000000',
|
|
3564
|
+
focusBorder: '#00000000'
|
|
3565
|
+
}
|
|
3566
|
+
});
|
|
3567
|
+
var isEditorFocused = editor.createContextKey('isEditorFocused' + id, false);
|
|
3568
|
+
// we setup on-blur
|
|
3569
|
+
editor.onDidBlurEditorWidget(function () {
|
|
3570
|
+
isEditorFocused.set(false);
|
|
3571
|
+
onBlur == null || onBlur(editor.getValue());
|
|
3572
|
+
// reset the selection to the current position
|
|
3573
|
+
var position = editor.getPosition();
|
|
3574
|
+
if (position) {
|
|
3575
|
+
var newSelection = new monaco.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
|
|
3576
|
+
editor.setSelection(newSelection);
|
|
3577
|
+
}
|
|
3578
|
+
});
|
|
3579
|
+
editor.onDidFocusEditorText(function () {
|
|
3580
|
+
isEditorFocused.set(true);
|
|
3581
|
+
});
|
|
3582
|
+
// set the height of the editor container
|
|
3583
|
+
var updateElementHeight = function updateElementHeight() {
|
|
3584
|
+
var containerDiv = containerRef.current;
|
|
3585
|
+
if (containerDiv !== null) {
|
|
3586
|
+
var pixelHeight = editor.getContentHeight();
|
|
3587
|
+
containerDiv.style.height = pixelHeight + "px";
|
|
3588
|
+
containerDiv.style.width = '100%';
|
|
3589
|
+
var pixelWidth = containerDiv.clientWidth;
|
|
3590
|
+
editor.layout({
|
|
3591
|
+
width: pixelWidth,
|
|
3592
|
+
height: pixelHeight
|
|
3593
|
+
});
|
|
3594
|
+
}
|
|
3595
|
+
};
|
|
3596
|
+
editor.onDidContentSizeChange(updateElementHeight);
|
|
3597
|
+
updateElementHeight();
|
|
3598
|
+
// Fixes Monaco capturing the search key binding and displaying a useless search box within the Editor.
|
|
3599
|
+
monaco.editor.addKeybindingRule({
|
|
3600
|
+
keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF,
|
|
3601
|
+
command: null
|
|
3602
|
+
});
|
|
3603
|
+
// 设置 Shift + Enter 为在光标位置换行
|
|
3604
|
+
editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, function () {
|
|
3605
|
+
// 在光标位置插入换行符
|
|
3606
|
+
var position = editor.getPosition();
|
|
3607
|
+
if (position) {
|
|
3608
|
+
editor.executeEdits('shift-enter', [{
|
|
3609
|
+
range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
|
3610
|
+
text: '\n'
|
|
3611
|
+
}]);
|
|
3612
|
+
// 将光标移动到新行
|
|
3613
|
+
editor.setPosition({
|
|
3614
|
+
lineNumber: position.lineNumber + 1,
|
|
3615
|
+
column: 1
|
|
3616
|
+
});
|
|
3617
|
+
}
|
|
3618
|
+
}, 'isEditorFocused' + id);
|
|
3619
|
+
// 完全阻止 Enter 键的默认行为(包括换行)
|
|
3620
|
+
monaco.editor.addKeybindingRule({
|
|
3621
|
+
keybinding: monaco.KeyCode.Enter,
|
|
3622
|
+
command: '-',
|
|
3623
|
+
when: '!suggestWidgetVisible'
|
|
3624
|
+
});
|
|
3625
|
+
// handle: enter - 只有在没有建议窗口时才执行自定义行为
|
|
3626
|
+
editor.addCommand(monaco.KeyCode.Enter, function () {
|
|
3627
|
+
onEnter == null || onEnter(editor.getValue());
|
|
3628
|
+
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
3629
|
+
editorDidMount == null || editorDidMount(editor);
|
|
3630
|
+
};
|
|
3631
|
+
var themeValue = themeMap$2[theme];
|
|
3632
|
+
return React__default.createElement("div", {
|
|
3633
|
+
className: 'ant-input' + (size ? " " + SIZE_MAP$2[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$2 : '') + (readOnly ? " " + containerReadOnlyClassName$2 : '')
|
|
3634
|
+
}, React__default.createElement("div", {
|
|
3635
|
+
ref: containerRef
|
|
3636
|
+
}, React__default.createElement(MonacoEditor, {
|
|
3637
|
+
width: '100%',
|
|
3638
|
+
height: '100%',
|
|
3639
|
+
language: SQL_LANG_ID,
|
|
3640
|
+
theme: themeValue,
|
|
3641
|
+
value: value,
|
|
3642
|
+
onChange: onChange,
|
|
3643
|
+
editorDidMount: handleEditorMount,
|
|
3644
|
+
options: {
|
|
3645
|
+
minimap: {
|
|
3646
|
+
enabled: false
|
|
3647
|
+
},
|
|
3648
|
+
autoClosingBrackets: 'always',
|
|
3649
|
+
autoClosingQuotes: 'always',
|
|
3650
|
+
autoIndent: 'full',
|
|
3651
|
+
formatOnPaste: true,
|
|
3652
|
+
formatOnType: true,
|
|
3653
|
+
readOnly: readOnly || disabled,
|
|
3654
|
+
scrollBeyondLastLine: false,
|
|
3655
|
+
smoothScrolling: true,
|
|
3656
|
+
tabSize: 2,
|
|
3657
|
+
wordWrap: 'on',
|
|
3658
|
+
automaticLayout: true,
|
|
3659
|
+
glyphMargin: false,
|
|
3660
|
+
lineNumbers: 'off',
|
|
3661
|
+
lineNumbersMinChars: 0,
|
|
3662
|
+
folding: false,
|
|
3663
|
+
lineDecorationsWidth: 0,
|
|
3664
|
+
overviewRulerBorder: false,
|
|
3665
|
+
overviewRulerLanes: 0,
|
|
3666
|
+
placeholder: placeholder,
|
|
3667
|
+
renderLineHighlight: 'none',
|
|
3668
|
+
occurrencesHighlight: 'off'
|
|
3669
|
+
}
|
|
3670
|
+
})));
|
|
3671
|
+
}
|
|
3672
|
+
|
|
3185
3673
|
exports.PromQLMonacoEditor = PromQLEditor;
|
|
3674
|
+
exports.SqlMonacoEditor = SqlEditor;
|
|
3186
3675
|
exports.YamlMonacoEditor = YamlEditor;
|
|
3187
3676
|
//# sourceMappingURL=monaco-editor.cjs.development.js.map
|