@fc-components/monaco-editor 0.3.1 → 0.3.2
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/monaco-editor.cjs.development.js +68 -5
- 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 +69 -6
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/sql/format.d.ts +1 -0
- package/dist/sql/index.d.ts +9 -2
- package/package.json +2 -1
- package/src/sql/format.ts +13 -0
- package/src/sql/index.tsx +91 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useEffect } from 'react';
|
|
1
|
+
import React, { useRef, useEffect, forwardRef, useCallback, useImperativeHandle } from 'react';
|
|
2
2
|
import MonacoEditor from 'react-monaco-editor';
|
|
3
3
|
import * as monaco from 'monaco-editor';
|
|
4
4
|
import { languages, Range, editor, Selection, KeyMod, KeyCode, MarkerSeverity } from 'monaco-editor';
|
|
@@ -6,6 +6,7 @@ import { promLanguageDefinition } from 'monaco-promql';
|
|
|
6
6
|
import { parser as parser$1, LabelName, UnquotedLabelMatcher, LabelMatchers, VectorSelector, PromQL, Identifier, FunctionCallBody, StringLiteral, BinaryExpr, NumberDurationLiteralInDurationContext, MatrixSelector, GroupingLabels, WithExpr, WithAssignment, AggregateModifier, AggregateExpr, MatchOp, EqlSingle, EqlRegex, Neq, NeqRegex } from '@fc-components/lezer-metricsql';
|
|
7
7
|
import { v4 } from 'uuid';
|
|
8
8
|
import { css } from '@emotion/css';
|
|
9
|
+
import { format } from 'sql-formatter';
|
|
9
10
|
|
|
10
11
|
function _arrayLikeToArray(r, a) {
|
|
11
12
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -3659,7 +3660,19 @@ var getSqlCompletionProvider = function getSqlCompletionProvider() {
|
|
|
3659
3660
|
};
|
|
3660
3661
|
};
|
|
3661
3662
|
|
|
3662
|
-
|
|
3663
|
+
function formatSql(sql) {
|
|
3664
|
+
try {
|
|
3665
|
+
return format(sql, {
|
|
3666
|
+
tabWidth: 2,
|
|
3667
|
+
keywordCase: 'upper'
|
|
3668
|
+
});
|
|
3669
|
+
} catch (_unused) {
|
|
3670
|
+
// If formatting fails, return the original SQL
|
|
3671
|
+
return sql;
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
|
|
3675
|
+
var _templateObject$2, _templateObject2$2, _templateObject3;
|
|
3663
3676
|
var SQL_LANG_ID = 'sql';
|
|
3664
3677
|
var SIZE_MAP$2 = {
|
|
3665
3678
|
small: {
|
|
@@ -3687,7 +3700,8 @@ var themeMap$2 = {
|
|
|
3687
3700
|
};
|
|
3688
3701
|
var containerDisabledClassName$2 = /*#__PURE__*/css(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor {\n user-select: none;\n pointer-events: none;\n }\n"])));
|
|
3689
3702
|
var containerReadOnlyClassName$2 = /*#__PURE__*/css(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
|
|
3690
|
-
|
|
3703
|
+
var formatBtnClassName = /*#__PURE__*/css(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: absolute;\n top: 4px;\n right: 4px;\n z-index: 10;\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n padding: 0;\n border: none;\n background: transparent;\n border-radius: 4px;\n cursor: pointer;\n color: inherit;\n opacity: 0.6;\n transition: opacity 0.15s;\n\n &:hover {\n opacity: 1;\n background: var(--format-btn-hover-bg, rgba(128, 128, 128, 0.15));\n }\n"])));
|
|
3704
|
+
var SqlEditor = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
3691
3705
|
var id = v4();
|
|
3692
3706
|
var className = props.className,
|
|
3693
3707
|
maxHeight = props.maxHeight,
|
|
@@ -3699,6 +3713,8 @@ function SqlEditor(props) {
|
|
|
3699
3713
|
_props$value = props.value,
|
|
3700
3714
|
value = _props$value === void 0 ? '' : _props$value,
|
|
3701
3715
|
placeholder = props.placeholder,
|
|
3716
|
+
_props$enableFormat = props.enableFormat,
|
|
3717
|
+
enableFormat = _props$enableFormat === void 0 ? false : _props$enableFormat,
|
|
3702
3718
|
_props$enableAutocomp = props.enableAutocomplete,
|
|
3703
3719
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
3704
3720
|
_props$readOnly = props.readOnly,
|
|
@@ -3709,7 +3725,8 @@ function SqlEditor(props) {
|
|
|
3709
3725
|
onEnter = props.onEnter,
|
|
3710
3726
|
onBlur = props.onBlur,
|
|
3711
3727
|
onFocus = props.onFocus,
|
|
3712
|
-
editorDidMount = props.editorDidMount
|
|
3728
|
+
editorDidMount = props.editorDidMount,
|
|
3729
|
+
renderFormatButton = props.renderFormatButton;
|
|
3713
3730
|
var containerRef = useRef(null);
|
|
3714
3731
|
var editorRef = useRef(null);
|
|
3715
3732
|
var modelRef = useRef(null);
|
|
@@ -3823,6 +3840,18 @@ function SqlEditor(props) {
|
|
|
3823
3840
|
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
3824
3841
|
editorDidMount == null || editorDidMount(editor$1);
|
|
3825
3842
|
};
|
|
3843
|
+
var handleFormat = useCallback(function () {
|
|
3844
|
+
var editor = editorRef.current;
|
|
3845
|
+
if (!editor) return;
|
|
3846
|
+
var currentValue = editor.getValue();
|
|
3847
|
+
var formatted = formatSql(currentValue);
|
|
3848
|
+
editor.setValue(formatted);
|
|
3849
|
+
}, []);
|
|
3850
|
+
useImperativeHandle(ref, function () {
|
|
3851
|
+
return {
|
|
3852
|
+
format: handleFormat
|
|
3853
|
+
};
|
|
3854
|
+
});
|
|
3826
3855
|
var themeValue = themeMap$2[theme];
|
|
3827
3856
|
return React.createElement("div", {
|
|
3828
3857
|
className: 'ant-input' + (size ? " " + SIZE_MAP$2[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$2 : '') + (readOnly ? " " + containerReadOnlyClassName$2 : '') + (className ? " " + className : ''),
|
|
@@ -3830,6 +3859,7 @@ function SqlEditor(props) {
|
|
|
3830
3859
|
display: 'block',
|
|
3831
3860
|
resize: 'vertical',
|
|
3832
3861
|
overflow: 'auto',
|
|
3862
|
+
position: 'relative',
|
|
3833
3863
|
minHeight: SIZE_MAP$2[size].minHeight,
|
|
3834
3864
|
maxHeight: maxHeight
|
|
3835
3865
|
}
|
|
@@ -3879,8 +3909,41 @@ function SqlEditor(props) {
|
|
|
3879
3909
|
alwaysConsumeMouseWheel: false
|
|
3880
3910
|
}
|
|
3881
3911
|
}
|
|
3882
|
-
})))
|
|
3883
|
-
|
|
3912
|
+
})), enableFormat && (renderFormatButton ? renderFormatButton(handleFormat) : React.createElement("button", {
|
|
3913
|
+
onClick: handleFormat,
|
|
3914
|
+
className: formatBtnClassName,
|
|
3915
|
+
title: 'Format SQL',
|
|
3916
|
+
style: {
|
|
3917
|
+
'--format-btn-hover-bg': theme === 'dark' ? 'rgba(255,255,255,0.2)' : 'rgba(128,128,128,0.15)'
|
|
3918
|
+
}
|
|
3919
|
+
}, React.createElement("svg", {
|
|
3920
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
3921
|
+
width: '16',
|
|
3922
|
+
height: '16',
|
|
3923
|
+
viewBox: '0 0 24 24',
|
|
3924
|
+
fill: 'none',
|
|
3925
|
+
stroke: 'currentColor',
|
|
3926
|
+
strokeWidth: '2',
|
|
3927
|
+
strokeLinecap: 'round',
|
|
3928
|
+
strokeLinejoin: 'round'
|
|
3929
|
+
}, React.createElement("path", {
|
|
3930
|
+
d: 'm21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72'
|
|
3931
|
+
}), React.createElement("path", {
|
|
3932
|
+
d: 'm14 7 3 3'
|
|
3933
|
+
}), React.createElement("path", {
|
|
3934
|
+
d: 'M5 6v4'
|
|
3935
|
+
}), React.createElement("path", {
|
|
3936
|
+
d: 'M19 14v4'
|
|
3937
|
+
}), React.createElement("path", {
|
|
3938
|
+
d: 'M10 2v2'
|
|
3939
|
+
}), React.createElement("path", {
|
|
3940
|
+
d: 'M7 8H3'
|
|
3941
|
+
}), React.createElement("path", {
|
|
3942
|
+
d: 'M21 16h-4'
|
|
3943
|
+
}), React.createElement("path", {
|
|
3944
|
+
d: 'M11 3H9'
|
|
3945
|
+
})))));
|
|
3946
|
+
});
|
|
3884
3947
|
|
|
3885
3948
|
var languageConfiguration$3 = {
|
|
3886
3949
|
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|