@fc-components/monaco-editor 0.1.17 → 0.1.19

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 CHANGED
@@ -1,4 +1,6 @@
1
1
  import promql from './promql';
2
2
  import yaml from './yaml';
3
+ import sql from './sql';
3
4
  export { promql as PromQLMonacoEditor };
4
5
  export { yaml as YamlMonacoEditor };
6
+ export { sql as SqlMonacoEditor };
@@ -3214,6 +3214,465 @@ function YamlEditor(props) {
3214
3214
  })));
3215
3215
  }
3216
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
+ onFocus = props.onFocus,
3519
+ editorDidMount = props.editorDidMount;
3520
+ var containerRef = React.useRef(null);
3521
+ var editorRef = React.useRef(null);
3522
+ var modelRef = React.useRef(null);
3523
+ var disposablesRef = React.useRef([]);
3524
+ React.useEffect(function () {
3525
+ // Register language
3526
+ if (!monaco.languages.getLanguages().some(function (lang) {
3527
+ return lang.id === SQL_LANG_ID;
3528
+ })) {
3529
+ monaco.languages.register({
3530
+ id: SQL_LANG_ID
3531
+ });
3532
+ monaco.languages.setMonarchTokensProvider(SQL_LANG_ID, language$2);
3533
+ monaco.languages.setLanguageConfiguration(SQL_LANG_ID, languageConfiguration$2);
3534
+ }
3535
+ // Register completion provider
3536
+ if (enableAutocomplete) {
3537
+ var disposable = monaco.languages.registerCompletionItemProvider(SQL_LANG_ID, getSqlCompletionProvider());
3538
+ disposablesRef.current.push(disposable);
3539
+ }
3540
+ return function () {
3541
+ disposablesRef.current.forEach(function (disposable) {
3542
+ return disposable.dispose();
3543
+ });
3544
+ disposablesRef.current = [];
3545
+ };
3546
+ }, [enableAutocomplete]);
3547
+ var handleEditorMount = function handleEditorMount(editor) {
3548
+ editorRef.current = editor;
3549
+ modelRef.current = editor.getModel();
3550
+ monaco.editor.defineTheme('sql-light', {
3551
+ base: 'vs',
3552
+ inherit: true,
3553
+ rules: [],
3554
+ colors: {
3555
+ 'editor.background': '#00000000',
3556
+ focusBorder: '#00000000'
3557
+ }
3558
+ });
3559
+ monaco.editor.defineTheme('sql-dark', {
3560
+ base: 'vs-dark',
3561
+ inherit: true,
3562
+ rules: [],
3563
+ colors: {
3564
+ 'editor.background': '#00000000',
3565
+ focusBorder: '#00000000'
3566
+ }
3567
+ });
3568
+ var isEditorFocused = editor.createContextKey('isEditorFocused' + id, false);
3569
+ // we setup on-blur
3570
+ editor.onDidBlurEditorWidget(function () {
3571
+ isEditorFocused.set(false);
3572
+ onBlur == null || onBlur(editor.getValue());
3573
+ // reset the selection to the current position
3574
+ var position = editor.getPosition();
3575
+ if (position) {
3576
+ var newSelection = new monaco.Selection(position.lineNumber, position.column, position.lineNumber, position.column);
3577
+ editor.setSelection(newSelection);
3578
+ }
3579
+ });
3580
+ editor.onDidFocusEditorText(function () {
3581
+ isEditorFocused.set(true);
3582
+ onFocus == null || onFocus(editor.getValue());
3583
+ });
3584
+ // set the height of the editor container
3585
+ var updateElementHeight = function updateElementHeight() {
3586
+ var containerDiv = containerRef.current;
3587
+ if (containerDiv !== null) {
3588
+ var pixelHeight = editor.getContentHeight();
3589
+ containerDiv.style.height = pixelHeight + "px";
3590
+ containerDiv.style.width = '100%';
3591
+ var pixelWidth = containerDiv.clientWidth;
3592
+ editor.layout({
3593
+ width: pixelWidth,
3594
+ height: pixelHeight
3595
+ });
3596
+ }
3597
+ };
3598
+ editor.onDidContentSizeChange(updateElementHeight);
3599
+ updateElementHeight();
3600
+ // Fixes Monaco capturing the search key binding and displaying a useless search box within the Editor.
3601
+ monaco.editor.addKeybindingRule({
3602
+ keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyF,
3603
+ command: null
3604
+ });
3605
+ // 设置 Shift + Enter 为在光标位置换行
3606
+ editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Enter, function () {
3607
+ // 在光标位置插入换行符
3608
+ var position = editor.getPosition();
3609
+ if (position) {
3610
+ editor.executeEdits('shift-enter', [{
3611
+ range: new monaco.Range(position.lineNumber, position.column, position.lineNumber, position.column),
3612
+ text: '\n'
3613
+ }]);
3614
+ // 将光标移动到新行
3615
+ editor.setPosition({
3616
+ lineNumber: position.lineNumber + 1,
3617
+ column: 1
3618
+ });
3619
+ }
3620
+ }, 'isEditorFocused' + id);
3621
+ // 完全阻止 Enter 键的默认行为(包括换行)
3622
+ monaco.editor.addKeybindingRule({
3623
+ keybinding: monaco.KeyCode.Enter,
3624
+ command: '-',
3625
+ when: '!suggestWidgetVisible'
3626
+ });
3627
+ // handle: enter - 只有在没有建议窗口时才执行自定义行为
3628
+ editor.addCommand(monaco.KeyCode.Enter, function () {
3629
+ onEnter == null || onEnter(editor.getValue());
3630
+ }, '!suggestWidgetVisible && isEditorFocused' + id);
3631
+ editorDidMount == null || editorDidMount(editor);
3632
+ };
3633
+ var themeValue = themeMap$2[theme];
3634
+ return React__default.createElement("div", {
3635
+ className: 'ant-input' + (size ? " " + SIZE_MAP$2[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$2 : '') + (readOnly ? " " + containerReadOnlyClassName$2 : '')
3636
+ }, React__default.createElement("div", {
3637
+ ref: containerRef
3638
+ }, React__default.createElement(MonacoEditor, {
3639
+ width: '100%',
3640
+ height: '100%',
3641
+ language: SQL_LANG_ID,
3642
+ theme: themeValue,
3643
+ value: value,
3644
+ onChange: onChange,
3645
+ editorDidMount: handleEditorMount,
3646
+ options: {
3647
+ minimap: {
3648
+ enabled: false
3649
+ },
3650
+ autoClosingBrackets: 'always',
3651
+ autoClosingQuotes: 'always',
3652
+ autoIndent: 'full',
3653
+ formatOnPaste: true,
3654
+ formatOnType: true,
3655
+ readOnly: readOnly || disabled,
3656
+ scrollBeyondLastLine: false,
3657
+ smoothScrolling: true,
3658
+ tabSize: 2,
3659
+ wordWrap: 'on',
3660
+ automaticLayout: true,
3661
+ glyphMargin: false,
3662
+ lineNumbers: 'off',
3663
+ lineNumbersMinChars: 0,
3664
+ folding: false,
3665
+ lineDecorationsWidth: 0,
3666
+ overviewRulerBorder: false,
3667
+ overviewRulerLanes: 0,
3668
+ placeholder: placeholder,
3669
+ renderLineHighlight: 'none',
3670
+ occurrencesHighlight: 'off'
3671
+ }
3672
+ })));
3673
+ }
3674
+
3217
3675
  exports.PromQLMonacoEditor = PromQLEditor;
3676
+ exports.SqlMonacoEditor = SqlEditor;
3218
3677
  exports.YamlMonacoEditor = YamlEditor;
3219
3678
  //# sourceMappingURL=monaco-editor.cjs.development.js.map