@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
|
@@ -874,6 +874,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
874
874
|
this.variablesNames = [];
|
|
875
875
|
this.httpMethod = 'GET';
|
|
876
876
|
this.apiPrefix = '/api/v1';
|
|
877
|
+
this.enableRequests = true;
|
|
877
878
|
this.customRequest = function (input, init) {
|
|
878
879
|
return fetch(input, init);
|
|
879
880
|
};
|
|
@@ -883,6 +884,12 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
883
884
|
return _regenerator().w(function (_context) {
|
|
884
885
|
while (1) switch (_context.n) {
|
|
885
886
|
case 0:
|
|
887
|
+
if (_this.enableRequests) {
|
|
888
|
+
_context.n = 1;
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
return _context.a(2, []);
|
|
892
|
+
case 1:
|
|
886
893
|
end = new Date();
|
|
887
894
|
start = new Date(end.getTime() - _this.lookbackInterval);
|
|
888
895
|
url = _this.apiPrefix + "/series";
|
|
@@ -899,14 +906,14 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
899
906
|
});
|
|
900
907
|
}
|
|
901
908
|
request = _this.buildRequest(url, new URLSearchParams(urlParams));
|
|
902
|
-
_context.n =
|
|
909
|
+
_context.n = 2;
|
|
903
910
|
return _this.request(request.uri, {
|
|
904
911
|
method: _this.httpMethod,
|
|
905
912
|
body: request.body
|
|
906
913
|
})["catch"](function () {
|
|
907
914
|
return [];
|
|
908
915
|
});
|
|
909
|
-
case
|
|
916
|
+
case 2:
|
|
910
917
|
return _context.a(2, _context.v);
|
|
911
918
|
}
|
|
912
919
|
}, _callee);
|
|
@@ -921,6 +928,12 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
921
928
|
return _regenerator().w(function (_context2) {
|
|
922
929
|
while (1) switch (_context2.n) {
|
|
923
930
|
case 0:
|
|
931
|
+
if (_this.enableRequests) {
|
|
932
|
+
_context2.n = 1;
|
|
933
|
+
break;
|
|
934
|
+
}
|
|
935
|
+
return _context2.a(2, []);
|
|
936
|
+
case 1:
|
|
924
937
|
end = new Date();
|
|
925
938
|
start = new Date(end.getTime() - _this.lookbackInterval);
|
|
926
939
|
url = _this.apiPrefix + "/labels";
|
|
@@ -932,7 +945,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
932
945
|
urlParams['match[]'] = selector;
|
|
933
946
|
}
|
|
934
947
|
request = _this.buildRequest(url, new URLSearchParams(urlParams));
|
|
935
|
-
_context2.n =
|
|
948
|
+
_context2.n = 2;
|
|
936
949
|
return _this.request(request.uri, {
|
|
937
950
|
method: _this.httpMethod,
|
|
938
951
|
body: request.body
|
|
@@ -942,7 +955,7 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
942
955
|
})["catch"](function () {
|
|
943
956
|
return [];
|
|
944
957
|
});
|
|
945
|
-
case
|
|
958
|
+
case 2:
|
|
946
959
|
return _context2.a(2, _context2.v);
|
|
947
960
|
}
|
|
948
961
|
}, _callee2);
|
|
@@ -957,6 +970,12 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
957
970
|
return _regenerator().w(function (_context3) {
|
|
958
971
|
while (1) switch (_context3.n) {
|
|
959
972
|
case 0:
|
|
973
|
+
if (_this.enableRequests) {
|
|
974
|
+
_context3.n = 1;
|
|
975
|
+
break;
|
|
976
|
+
}
|
|
977
|
+
return _context3.a(2, []);
|
|
978
|
+
case 1:
|
|
960
979
|
end = new Date();
|
|
961
980
|
start = new Date(end.getTime() - _this.lookbackInterval);
|
|
962
981
|
url = _this.apiPrefix + "/label/" + labelName + "/values";
|
|
@@ -968,14 +987,14 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
968
987
|
urlParams['match[]'] = selector;
|
|
969
988
|
}
|
|
970
989
|
request = _this.buildRequest(url, new URLSearchParams(urlParams));
|
|
971
|
-
_context3.n =
|
|
990
|
+
_context3.n = 2;
|
|
972
991
|
return _this.request(request.uri, {
|
|
973
992
|
method: _this.httpMethod,
|
|
974
993
|
body: request.body
|
|
975
994
|
})["catch"](function () {
|
|
976
995
|
return [];
|
|
977
996
|
});
|
|
978
|
-
case
|
|
997
|
+
case 2:
|
|
979
998
|
return _context3.a(2, _context3.v);
|
|
980
999
|
}
|
|
981
1000
|
}, _callee3);
|
|
@@ -1025,6 +1044,10 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
1025
1044
|
if (params.apiPrefix) {
|
|
1026
1045
|
this.apiPrefix = params.apiPrefix;
|
|
1027
1046
|
}
|
|
1047
|
+
// control whether DataProvider should actually send network requests
|
|
1048
|
+
if (typeof params.enableRequests !== 'undefined') {
|
|
1049
|
+
this.enableRequests = !!params.enableRequests;
|
|
1050
|
+
}
|
|
1028
1051
|
this.metrics = [];
|
|
1029
1052
|
this.labelKeys = [];
|
|
1030
1053
|
}
|
|
@@ -1088,18 +1111,24 @@ var DataProvider = /*#__PURE__*/function () {
|
|
|
1088
1111
|
return _regenerator().w(function (_context5) {
|
|
1089
1112
|
while (1) switch (_context5.n) {
|
|
1090
1113
|
case 0:
|
|
1114
|
+
if (this.enableRequests) {
|
|
1115
|
+
_context5.n = 1;
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
this.metricsMetadata = {};
|
|
1119
|
+
return _context5.a(2, this.metricsMetadata);
|
|
1120
|
+
case 1:
|
|
1091
1121
|
request = this.buildRequest(this.apiPrefix + "/metadata", new URLSearchParams({}));
|
|
1092
|
-
_context5.n =
|
|
1122
|
+
_context5.n = 2;
|
|
1093
1123
|
return this.request(request.uri, {
|
|
1094
1124
|
method: this.httpMethod,
|
|
1095
1125
|
body: request.body
|
|
1096
1126
|
})["catch"](function () {
|
|
1097
1127
|
return {};
|
|
1098
1128
|
});
|
|
1099
|
-
case 1:
|
|
1100
|
-
this.metricsMetadata = _context5.v;
|
|
1101
1129
|
case 2:
|
|
1102
|
-
|
|
1130
|
+
this.metricsMetadata = _context5.v;
|
|
1131
|
+
return _context5.a(2, this.metricsMetadata || {});
|
|
1103
1132
|
}
|
|
1104
1133
|
}, _callee5, this);
|
|
1105
1134
|
}));
|
|
@@ -1999,6 +2028,8 @@ function PromQLEditor(props) {
|
|
|
1999
2028
|
interpolateString = props.interpolateString,
|
|
2000
2029
|
_props$enableAutocomp = props.enableAutocomplete,
|
|
2001
2030
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
2031
|
+
_props$enableRequests = props.enableRequests,
|
|
2032
|
+
enableRequests = _props$enableRequests === void 0 ? true : _props$enableRequests,
|
|
2002
2033
|
_props$readOnly = props.readOnly,
|
|
2003
2034
|
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
2004
2035
|
_props$disabled = props.disabled,
|
|
@@ -2151,7 +2182,8 @@ function PromQLEditor(props) {
|
|
|
2151
2182
|
request: props.request,
|
|
2152
2183
|
httpMethod: props.httpMethod,
|
|
2153
2184
|
apiPrefix: props.apiPrefix,
|
|
2154
|
-
httpErrorHandler: props.httpErrorHandler
|
|
2185
|
+
httpErrorHandler: props.httpErrorHandler,
|
|
2186
|
+
enableRequests: enableRequests
|
|
2155
2187
|
});
|
|
2156
2188
|
dataProviderRef.current = dataProvider;
|
|
2157
2189
|
dataProvider.start();
|
|
@@ -2198,7 +2230,7 @@ function PromQLEditor(props) {
|
|
|
2198
2230
|
checkDecorators();
|
|
2199
2231
|
editor.onDidChangeModelContent(checkDecorators);
|
|
2200
2232
|
}
|
|
2201
|
-
}, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder]);
|
|
2233
|
+
}, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder, enableRequests]);
|
|
2202
2234
|
return React.createElement("div", {
|
|
2203
2235
|
className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName : '') + (readOnly ? " " + containerReadOnlyClassName : '')
|
|
2204
2236
|
}, React.createElement("div", {
|
|
@@ -3176,5 +3208,461 @@ function YamlEditor(props) {
|
|
|
3176
3208
|
})));
|
|
3177
3209
|
}
|
|
3178
3210
|
|
|
3179
|
-
|
|
3211
|
+
var languageConfiguration$2 = {
|
|
3212
|
+
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
|
3213
|
+
comments: {
|
|
3214
|
+
lineComment: '--',
|
|
3215
|
+
blockComment: ['/*', '*/']
|
|
3216
|
+
},
|
|
3217
|
+
brackets: [['{', '}'], ['[', ']'], ['(', ')']],
|
|
3218
|
+
autoClosingPairs: [{
|
|
3219
|
+
open: '{',
|
|
3220
|
+
close: '}'
|
|
3221
|
+
}, {
|
|
3222
|
+
open: '[',
|
|
3223
|
+
close: ']'
|
|
3224
|
+
}, {
|
|
3225
|
+
open: '(',
|
|
3226
|
+
close: ')'
|
|
3227
|
+
}, {
|
|
3228
|
+
open: '"',
|
|
3229
|
+
close: '"'
|
|
3230
|
+
}, {
|
|
3231
|
+
open: "'",
|
|
3232
|
+
close: "'"
|
|
3233
|
+
}, {
|
|
3234
|
+
open: '`',
|
|
3235
|
+
close: '`'
|
|
3236
|
+
}],
|
|
3237
|
+
surroundingPairs: [{
|
|
3238
|
+
open: '{',
|
|
3239
|
+
close: '}'
|
|
3240
|
+
}, {
|
|
3241
|
+
open: '[',
|
|
3242
|
+
close: ']'
|
|
3243
|
+
}, {
|
|
3244
|
+
open: '(',
|
|
3245
|
+
close: ')'
|
|
3246
|
+
}, {
|
|
3247
|
+
open: '"',
|
|
3248
|
+
close: '"'
|
|
3249
|
+
}, {
|
|
3250
|
+
open: "'",
|
|
3251
|
+
close: "'"
|
|
3252
|
+
}, {
|
|
3253
|
+
open: '`',
|
|
3254
|
+
close: '`'
|
|
3255
|
+
}],
|
|
3256
|
+
folding: {
|
|
3257
|
+
offSide: false
|
|
3258
|
+
}
|
|
3259
|
+
};
|
|
3260
|
+
// SQL keywords
|
|
3261
|
+
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'];
|
|
3262
|
+
var language$2 = {
|
|
3263
|
+
defaultToken: '',
|
|
3264
|
+
tokenPostfix: '.sql',
|
|
3265
|
+
ignoreCase: true,
|
|
3266
|
+
brackets: [{
|
|
3267
|
+
open: '(',
|
|
3268
|
+
close: ')',
|
|
3269
|
+
token: 'delimiter.parenthesis'
|
|
3270
|
+
}, {
|
|
3271
|
+
open: '{',
|
|
3272
|
+
close: '}',
|
|
3273
|
+
token: 'delimiter.curly'
|
|
3274
|
+
}, {
|
|
3275
|
+
open: '[',
|
|
3276
|
+
close: ']',
|
|
3277
|
+
token: 'delimiter.square'
|
|
3278
|
+
}],
|
|
3279
|
+
keywords: keywords$2,
|
|
3280
|
+
operators: ['=', '>', '<', '!', '%', '&', '|', '^', '~', '?', ':', '+', '-', '*', '/'],
|
|
3281
|
+
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'],
|
|
3282
|
+
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
3283
|
+
digits: /\d+(_+\d+)*/,
|
|
3284
|
+
octaldigits: /[0-7]+(_+[0-7]+)*/,
|
|
3285
|
+
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
|
|
3286
|
+
regexpctl: /[(){}\[\]\|;,.?*+^$\\]/,
|
|
3287
|
+
regexpattern: /(\{[0-9]+\})|(\{[0-9]*,[0-9]*\})|(\?(?:\?)?|[*+]|\^|\$|\|\\)/,
|
|
3288
|
+
tokenizer: {
|
|
3289
|
+
root: [{
|
|
3290
|
+
include: '@comments'
|
|
3291
|
+
}, {
|
|
3292
|
+
include: '@whitespace'
|
|
3293
|
+
}, {
|
|
3294
|
+
include: '@pseudo-columns'
|
|
3295
|
+
}, [/[;,.]/, 'delimiter'], [/[{}()\[\]]/, '@brackets'], {
|
|
3296
|
+
include: '@builtinVariables'
|
|
3297
|
+
}, {
|
|
3298
|
+
include: '@numbers'
|
|
3299
|
+
}, {
|
|
3300
|
+
include: '@strings'
|
|
3301
|
+
}, [/[a-zA-Z_#][a-zA-Z0-9_$#@]*(?=\s*\()/, {
|
|
3302
|
+
cases: {
|
|
3303
|
+
'@builtinFunctions': 'keyword.function',
|
|
3304
|
+
'@default': 'identifier.function'
|
|
3305
|
+
}
|
|
3306
|
+
}], [/[a-zA-Z_#][a-zA-Z0-9_$#@]*/, {
|
|
3307
|
+
cases: {
|
|
3308
|
+
'@keywords': 'keyword',
|
|
3309
|
+
'@default': 'identifier'
|
|
3310
|
+
}
|
|
3311
|
+
}], [/[<>=!%&+\-*/|~^]/, 'operator']],
|
|
3312
|
+
whitespace: [[/\s+/, 'white']],
|
|
3313
|
+
comments: [[/--+.*/, 'comment'], [/\/\*/, {
|
|
3314
|
+
token: 'comment.quote',
|
|
3315
|
+
next: '@comment'
|
|
3316
|
+
}]],
|
|
3317
|
+
comment: [[/[^*/]+/, 'comment'], [/\*\//, {
|
|
3318
|
+
token: 'comment.quote',
|
|
3319
|
+
next: '@pop'
|
|
3320
|
+
}], [/./, 'comment']],
|
|
3321
|
+
'pseudo-columns': [[/[$][A-Za-z_][A-Za-z0-9_]*/, {
|
|
3322
|
+
cases: {
|
|
3323
|
+
'@keywords': 'keyword',
|
|
3324
|
+
'@default': 'variable'
|
|
3325
|
+
}
|
|
3326
|
+
}], [/@[A-Za-z_][A-Za-z0-9_]*/, {
|
|
3327
|
+
cases: {
|
|
3328
|
+
'@keywords': 'keyword',
|
|
3329
|
+
'@default': 'variable'
|
|
3330
|
+
}
|
|
3331
|
+
}]],
|
|
3332
|
+
builtinVariables: [[/@@?[a-zA-Z_][a-zA-Z0-9_]*/, {
|
|
3333
|
+
cases: {
|
|
3334
|
+
'@keywords': 'keyword',
|
|
3335
|
+
'@default': 'variable'
|
|
3336
|
+
}
|
|
3337
|
+
}]],
|
|
3338
|
+
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']],
|
|
3339
|
+
strings: [[/'/, {
|
|
3340
|
+
token: 'string',
|
|
3341
|
+
next: '@string'
|
|
3342
|
+
}], [/"/, {
|
|
3343
|
+
token: 'string.double',
|
|
3344
|
+
next: '@string_double'
|
|
3345
|
+
}], [/`/, {
|
|
3346
|
+
token: 'string.backtick',
|
|
3347
|
+
next: '@string_backtick'
|
|
3348
|
+
}]],
|
|
3349
|
+
string: [[/[^'\\]+/, 'string'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/'/, {
|
|
3350
|
+
token: 'string',
|
|
3351
|
+
next: '@pop'
|
|
3352
|
+
}]],
|
|
3353
|
+
string_double: [[/[^"\\]+/, 'string.double'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/"/, {
|
|
3354
|
+
token: 'string.double',
|
|
3355
|
+
next: '@pop'
|
|
3356
|
+
}]],
|
|
3357
|
+
string_backtick: [[/[^`\\]+/, 'string.backtick'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/`/, {
|
|
3358
|
+
token: 'string.backtick',
|
|
3359
|
+
next: '@pop'
|
|
3360
|
+
}]]
|
|
3361
|
+
}
|
|
3362
|
+
};
|
|
3363
|
+
|
|
3364
|
+
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'];
|
|
3365
|
+
var SQL_FUNCTIONS = [{
|
|
3366
|
+
name: 'COUNT',
|
|
3367
|
+
signature: 'COUNT(expression)',
|
|
3368
|
+
description: 'Returns the number of rows'
|
|
3369
|
+
}, {
|
|
3370
|
+
name: 'SUM',
|
|
3371
|
+
signature: 'SUM(expression)',
|
|
3372
|
+
description: 'Returns the sum of values'
|
|
3373
|
+
}, {
|
|
3374
|
+
name: 'AVG',
|
|
3375
|
+
signature: 'AVG(expression)',
|
|
3376
|
+
description: 'Returns the average value'
|
|
3377
|
+
}, {
|
|
3378
|
+
name: 'MIN',
|
|
3379
|
+
signature: 'MIN(expression)',
|
|
3380
|
+
description: 'Returns the minimum value'
|
|
3381
|
+
}, {
|
|
3382
|
+
name: 'MAX',
|
|
3383
|
+
signature: 'MAX(expression)',
|
|
3384
|
+
description: 'Returns the maximum value'
|
|
3385
|
+
}, {
|
|
3386
|
+
name: 'UPPER',
|
|
3387
|
+
signature: 'UPPER(string)',
|
|
3388
|
+
description: 'Converts string to uppercase'
|
|
3389
|
+
}, {
|
|
3390
|
+
name: 'LOWER',
|
|
3391
|
+
signature: 'LOWER(string)',
|
|
3392
|
+
description: 'Converts string to lowercase'
|
|
3393
|
+
}, {
|
|
3394
|
+
name: 'LENGTH',
|
|
3395
|
+
signature: 'LENGTH(string)',
|
|
3396
|
+
description: 'Returns the length of string'
|
|
3397
|
+
}, {
|
|
3398
|
+
name: 'SUBSTRING',
|
|
3399
|
+
signature: 'SUBSTRING(string, start, length)',
|
|
3400
|
+
description: 'Extracts substring'
|
|
3401
|
+
}, {
|
|
3402
|
+
name: 'TRIM',
|
|
3403
|
+
signature: 'TRIM(string)',
|
|
3404
|
+
description: 'Removes leading and trailing spaces'
|
|
3405
|
+
}, {
|
|
3406
|
+
name: 'ROUND',
|
|
3407
|
+
signature: 'ROUND(number, decimals)',
|
|
3408
|
+
description: 'Rounds a number'
|
|
3409
|
+
}, {
|
|
3410
|
+
name: 'ABS',
|
|
3411
|
+
signature: 'ABS(number)',
|
|
3412
|
+
description: 'Returns absolute value'
|
|
3413
|
+
}, {
|
|
3414
|
+
name: 'COALESCE',
|
|
3415
|
+
signature: 'COALESCE(value1, value2, ...)',
|
|
3416
|
+
description: 'Returns first non-null value'
|
|
3417
|
+
}, {
|
|
3418
|
+
name: 'NULLIF',
|
|
3419
|
+
signature: 'NULLIF(value1, value2)',
|
|
3420
|
+
description: 'Returns null if two values are equal'
|
|
3421
|
+
}, {
|
|
3422
|
+
name: 'IFNULL',
|
|
3423
|
+
signature: 'IFNULL(value, default)',
|
|
3424
|
+
description: 'Returns alternative if null'
|
|
3425
|
+
}, {
|
|
3426
|
+
name: 'CONCAT',
|
|
3427
|
+
signature: 'CONCAT(string1, string2, ...)',
|
|
3428
|
+
description: 'Concatenates strings'
|
|
3429
|
+
}, {
|
|
3430
|
+
name: 'DATE',
|
|
3431
|
+
signature: 'DATE(date)',
|
|
3432
|
+
description: 'Extracts date part'
|
|
3433
|
+
}, {
|
|
3434
|
+
name: 'NOW',
|
|
3435
|
+
signature: 'NOW()',
|
|
3436
|
+
description: 'Returns current date and time'
|
|
3437
|
+
}];
|
|
3438
|
+
var getSqlCompletionProvider = function getSqlCompletionProvider() {
|
|
3439
|
+
return {
|
|
3440
|
+
provideCompletionItems: function provideCompletionItems(model, position, _context, _token) {
|
|
3441
|
+
var word = model.getWordUntilPosition(position);
|
|
3442
|
+
var range = new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
|
|
3443
|
+
var suggestions = [].concat(SQL_KEYWORDS.map(function (keyword) {
|
|
3444
|
+
return {
|
|
3445
|
+
label: keyword,
|
|
3446
|
+
kind: languages.CompletionItemKind.Keyword,
|
|
3447
|
+
insertText: keyword,
|
|
3448
|
+
range: range,
|
|
3449
|
+
sortText: '1' + keyword
|
|
3450
|
+
};
|
|
3451
|
+
}), SQL_FUNCTIONS.map(function (func) {
|
|
3452
|
+
return {
|
|
3453
|
+
label: func.name,
|
|
3454
|
+
kind: languages.CompletionItemKind.Function,
|
|
3455
|
+
insertText: func.name,
|
|
3456
|
+
detail: func.signature,
|
|
3457
|
+
documentation: func.description,
|
|
3458
|
+
range: range,
|
|
3459
|
+
sortText: '2' + func.name
|
|
3460
|
+
};
|
|
3461
|
+
}));
|
|
3462
|
+
return {
|
|
3463
|
+
suggestions: suggestions
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
};
|
|
3467
|
+
};
|
|
3468
|
+
|
|
3469
|
+
var _templateObject$2, _templateObject2$2;
|
|
3470
|
+
var SQL_LANG_ID = 'sql';
|
|
3471
|
+
var SIZE_MAP$2 = {
|
|
3472
|
+
small: {
|
|
3473
|
+
className: 'ant-input-sm',
|
|
3474
|
+
top: 1,
|
|
3475
|
+
bottom: 1
|
|
3476
|
+
},
|
|
3477
|
+
middle: {
|
|
3478
|
+
className: 'ant-input-md',
|
|
3479
|
+
top: 1,
|
|
3480
|
+
bottom: 1
|
|
3481
|
+
},
|
|
3482
|
+
large: {
|
|
3483
|
+
className: 'ant-input-lg',
|
|
3484
|
+
top: 3,
|
|
3485
|
+
bottom: 2
|
|
3486
|
+
}
|
|
3487
|
+
};
|
|
3488
|
+
var themeMap$2 = {
|
|
3489
|
+
light: 'sql-light',
|
|
3490
|
+
dark: 'sql-dark'
|
|
3491
|
+
};
|
|
3492
|
+
var containerDisabledClassName$2 = /*#__PURE__*/css(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
|
|
3493
|
+
var containerReadOnlyClassName$2 = /*#__PURE__*/css(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
|
|
3494
|
+
function SqlEditor(props) {
|
|
3495
|
+
var id = v4();
|
|
3496
|
+
var _props$size = props.size,
|
|
3497
|
+
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
3498
|
+
_props$theme = props.theme,
|
|
3499
|
+
theme = _props$theme === void 0 ? 'light' : _props$theme,
|
|
3500
|
+
_props$value = props.value,
|
|
3501
|
+
value = _props$value === void 0 ? '' : _props$value,
|
|
3502
|
+
placeholder = props.placeholder,
|
|
3503
|
+
_props$enableAutocomp = props.enableAutocomplete,
|
|
3504
|
+
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
3505
|
+
_props$readOnly = props.readOnly,
|
|
3506
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
3507
|
+
_props$disabled = props.disabled,
|
|
3508
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
3509
|
+
onChange = props.onChange,
|
|
3510
|
+
onEnter = props.onEnter,
|
|
3511
|
+
onBlur = props.onBlur,
|
|
3512
|
+
editorDidMount = props.editorDidMount;
|
|
3513
|
+
var containerRef = useRef(null);
|
|
3514
|
+
var editorRef = useRef(null);
|
|
3515
|
+
var modelRef = useRef(null);
|
|
3516
|
+
var disposablesRef = useRef([]);
|
|
3517
|
+
useEffect(function () {
|
|
3518
|
+
// Register language
|
|
3519
|
+
if (!languages.getLanguages().some(function (lang) {
|
|
3520
|
+
return lang.id === SQL_LANG_ID;
|
|
3521
|
+
})) {
|
|
3522
|
+
languages.register({
|
|
3523
|
+
id: SQL_LANG_ID
|
|
3524
|
+
});
|
|
3525
|
+
languages.setMonarchTokensProvider(SQL_LANG_ID, language$2);
|
|
3526
|
+
languages.setLanguageConfiguration(SQL_LANG_ID, languageConfiguration$2);
|
|
3527
|
+
}
|
|
3528
|
+
// Register completion provider
|
|
3529
|
+
if (enableAutocomplete) {
|
|
3530
|
+
var disposable = languages.registerCompletionItemProvider(SQL_LANG_ID, getSqlCompletionProvider());
|
|
3531
|
+
disposablesRef.current.push(disposable);
|
|
3532
|
+
}
|
|
3533
|
+
return function () {
|
|
3534
|
+
disposablesRef.current.forEach(function (disposable) {
|
|
3535
|
+
return disposable.dispose();
|
|
3536
|
+
});
|
|
3537
|
+
disposablesRef.current = [];
|
|
3538
|
+
};
|
|
3539
|
+
}, [enableAutocomplete]);
|
|
3540
|
+
var handleEditorMount = function handleEditorMount(editor$1) {
|
|
3541
|
+
editorRef.current = editor$1;
|
|
3542
|
+
modelRef.current = editor$1.getModel();
|
|
3543
|
+
editor.defineTheme('sql-light', {
|
|
3544
|
+
base: 'vs',
|
|
3545
|
+
inherit: true,
|
|
3546
|
+
rules: [],
|
|
3547
|
+
colors: {
|
|
3548
|
+
'editor.background': '#00000000',
|
|
3549
|
+
focusBorder: '#00000000'
|
|
3550
|
+
}
|
|
3551
|
+
});
|
|
3552
|
+
editor.defineTheme('sql-dark', {
|
|
3553
|
+
base: 'vs-dark',
|
|
3554
|
+
inherit: true,
|
|
3555
|
+
rules: [],
|
|
3556
|
+
colors: {
|
|
3557
|
+
'editor.background': '#00000000',
|
|
3558
|
+
focusBorder: '#00000000'
|
|
3559
|
+
}
|
|
3560
|
+
});
|
|
3561
|
+
var isEditorFocused = editor$1.createContextKey('isEditorFocused' + id, false);
|
|
3562
|
+
// we setup on-blur
|
|
3563
|
+
editor$1.onDidBlurEditorWidget(function () {
|
|
3564
|
+
isEditorFocused.set(false);
|
|
3565
|
+
onBlur == null || onBlur(editor$1.getValue());
|
|
3566
|
+
// reset the selection to the current position
|
|
3567
|
+
var position = editor$1.getPosition();
|
|
3568
|
+
if (position) {
|
|
3569
|
+
var newSelection = new Selection(position.lineNumber, position.column, position.lineNumber, position.column);
|
|
3570
|
+
editor$1.setSelection(newSelection);
|
|
3571
|
+
}
|
|
3572
|
+
});
|
|
3573
|
+
editor$1.onDidFocusEditorText(function () {
|
|
3574
|
+
isEditorFocused.set(true);
|
|
3575
|
+
});
|
|
3576
|
+
// set the height of the editor container
|
|
3577
|
+
var updateElementHeight = function updateElementHeight() {
|
|
3578
|
+
var containerDiv = containerRef.current;
|
|
3579
|
+
if (containerDiv !== null) {
|
|
3580
|
+
var pixelHeight = editor$1.getContentHeight();
|
|
3581
|
+
containerDiv.style.height = pixelHeight + "px";
|
|
3582
|
+
containerDiv.style.width = '100%';
|
|
3583
|
+
var pixelWidth = containerDiv.clientWidth;
|
|
3584
|
+
editor$1.layout({
|
|
3585
|
+
width: pixelWidth,
|
|
3586
|
+
height: pixelHeight
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
};
|
|
3590
|
+
editor$1.onDidContentSizeChange(updateElementHeight);
|
|
3591
|
+
updateElementHeight();
|
|
3592
|
+
// Fixes Monaco capturing the search key binding and displaying a useless search box within the Editor.
|
|
3593
|
+
editor.addKeybindingRule({
|
|
3594
|
+
keybinding: KeyMod.CtrlCmd | KeyCode.KeyF,
|
|
3595
|
+
command: null
|
|
3596
|
+
});
|
|
3597
|
+
// 设置 Shift + Enter 为在光标位置换行
|
|
3598
|
+
editor$1.addCommand(KeyMod.Shift | KeyCode.Enter, function () {
|
|
3599
|
+
// 在光标位置插入换行符
|
|
3600
|
+
var position = editor$1.getPosition();
|
|
3601
|
+
if (position) {
|
|
3602
|
+
editor$1.executeEdits('shift-enter', [{
|
|
3603
|
+
range: new Range(position.lineNumber, position.column, position.lineNumber, position.column),
|
|
3604
|
+
text: '\n'
|
|
3605
|
+
}]);
|
|
3606
|
+
// 将光标移动到新行
|
|
3607
|
+
editor$1.setPosition({
|
|
3608
|
+
lineNumber: position.lineNumber + 1,
|
|
3609
|
+
column: 1
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
}, 'isEditorFocused' + id);
|
|
3613
|
+
// 完全阻止 Enter 键的默认行为(包括换行)
|
|
3614
|
+
editor.addKeybindingRule({
|
|
3615
|
+
keybinding: KeyCode.Enter,
|
|
3616
|
+
command: '-',
|
|
3617
|
+
when: '!suggestWidgetVisible'
|
|
3618
|
+
});
|
|
3619
|
+
// handle: enter - 只有在没有建议窗口时才执行自定义行为
|
|
3620
|
+
editor$1.addCommand(KeyCode.Enter, function () {
|
|
3621
|
+
onEnter == null || onEnter(editor$1.getValue());
|
|
3622
|
+
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
3623
|
+
editorDidMount == null || editorDidMount(editor$1);
|
|
3624
|
+
};
|
|
3625
|
+
var themeValue = themeMap$2[theme];
|
|
3626
|
+
return React.createElement("div", {
|
|
3627
|
+
className: 'ant-input' + (size ? " " + SIZE_MAP$2[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$2 : '') + (readOnly ? " " + containerReadOnlyClassName$2 : '')
|
|
3628
|
+
}, React.createElement("div", {
|
|
3629
|
+
ref: containerRef
|
|
3630
|
+
}, React.createElement(MonacoEditor, {
|
|
3631
|
+
width: '100%',
|
|
3632
|
+
height: '100%',
|
|
3633
|
+
language: SQL_LANG_ID,
|
|
3634
|
+
theme: themeValue,
|
|
3635
|
+
value: value,
|
|
3636
|
+
onChange: onChange,
|
|
3637
|
+
editorDidMount: handleEditorMount,
|
|
3638
|
+
options: {
|
|
3639
|
+
minimap: {
|
|
3640
|
+
enabled: false
|
|
3641
|
+
},
|
|
3642
|
+
autoClosingBrackets: 'always',
|
|
3643
|
+
autoClosingQuotes: 'always',
|
|
3644
|
+
autoIndent: 'full',
|
|
3645
|
+
formatOnPaste: true,
|
|
3646
|
+
formatOnType: true,
|
|
3647
|
+
readOnly: readOnly || disabled,
|
|
3648
|
+
scrollBeyondLastLine: false,
|
|
3649
|
+
smoothScrolling: true,
|
|
3650
|
+
tabSize: 2,
|
|
3651
|
+
wordWrap: 'on',
|
|
3652
|
+
automaticLayout: true,
|
|
3653
|
+
glyphMargin: false,
|
|
3654
|
+
lineNumbers: 'off',
|
|
3655
|
+
lineNumbersMinChars: 0,
|
|
3656
|
+
folding: false,
|
|
3657
|
+
lineDecorationsWidth: 0,
|
|
3658
|
+
overviewRulerBorder: false,
|
|
3659
|
+
overviewRulerLanes: 0,
|
|
3660
|
+
placeholder: placeholder,
|
|
3661
|
+
renderLineHighlight: 'none',
|
|
3662
|
+
occurrencesHighlight: 'off'
|
|
3663
|
+
}
|
|
3664
|
+
})));
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3667
|
+
export { PromQLEditor as PromQLMonacoEditor, SqlEditor as SqlMonacoEditor, YamlEditor as YamlMonacoEditor };
|
|
3180
3668
|
//# sourceMappingURL=monaco-editor.esm.js.map
|