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