@fc-components/monaco-editor 0.1.17 → 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.
@@ -3208,5 +3208,461 @@ 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
+ 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 };
3212
3668
  //# sourceMappingURL=monaco-editor.esm.js.map