@fc-components/monaco-editor 0.3.1 → 0.3.3
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 +89 -3
|
@@ -12,6 +12,7 @@ var monacoPromql = require('monaco-promql');
|
|
|
12
12
|
var lezerMetricsql = require('@fc-components/lezer-metricsql');
|
|
13
13
|
var uuid = require('uuid');
|
|
14
14
|
var css = require('@emotion/css');
|
|
15
|
+
var sqlFormatter = require('sql-formatter');
|
|
15
16
|
|
|
16
17
|
function _arrayLikeToArray(r, a) {
|
|
17
18
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -3665,7 +3666,19 @@ var getSqlCompletionProvider = function getSqlCompletionProvider() {
|
|
|
3665
3666
|
};
|
|
3666
3667
|
};
|
|
3667
3668
|
|
|
3668
|
-
|
|
3669
|
+
function formatSql(sql) {
|
|
3670
|
+
try {
|
|
3671
|
+
return sqlFormatter.format(sql, {
|
|
3672
|
+
tabWidth: 2,
|
|
3673
|
+
keywordCase: 'upper'
|
|
3674
|
+
});
|
|
3675
|
+
} catch (_unused) {
|
|
3676
|
+
// If formatting fails, return the original SQL
|
|
3677
|
+
return sql;
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
|
|
3681
|
+
var _templateObject$2, _templateObject2$2, _templateObject3;
|
|
3669
3682
|
var SQL_LANG_ID = 'sql';
|
|
3670
3683
|
var SIZE_MAP$2 = {
|
|
3671
3684
|
small: {
|
|
@@ -3693,7 +3706,8 @@ var themeMap$2 = {
|
|
|
3693
3706
|
};
|
|
3694
3707
|
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"])));
|
|
3695
3708
|
var containerReadOnlyClassName$2 = /*#__PURE__*/css.css(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n .monaco-editor .cursors-layer > .cursor {\n opacity: 0 !important;\n }\n"])));
|
|
3696
|
-
|
|
3709
|
+
var formatBtnClassName = /*#__PURE__*/css.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: 1;\n transition: opacity 0.15s;\n\n &:hover {\n background: var(--format-btn-hover-bg, rgba(128, 128, 128, 0.15));\n }\n"])));
|
|
3710
|
+
var SqlEditor = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
3697
3711
|
var id = uuid.v4();
|
|
3698
3712
|
var className = props.className,
|
|
3699
3713
|
maxHeight = props.maxHeight,
|
|
@@ -3705,6 +3719,8 @@ function SqlEditor(props) {
|
|
|
3705
3719
|
_props$value = props.value,
|
|
3706
3720
|
value = _props$value === void 0 ? '' : _props$value,
|
|
3707
3721
|
placeholder = props.placeholder,
|
|
3722
|
+
_props$enableFormat = props.enableFormat,
|
|
3723
|
+
enableFormat = _props$enableFormat === void 0 ? false : _props$enableFormat,
|
|
3708
3724
|
_props$enableAutocomp = props.enableAutocomplete,
|
|
3709
3725
|
enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
|
|
3710
3726
|
_props$readOnly = props.readOnly,
|
|
@@ -3715,7 +3731,8 @@ function SqlEditor(props) {
|
|
|
3715
3731
|
onEnter = props.onEnter,
|
|
3716
3732
|
onBlur = props.onBlur,
|
|
3717
3733
|
onFocus = props.onFocus,
|
|
3718
|
-
editorDidMount = props.editorDidMount
|
|
3734
|
+
editorDidMount = props.editorDidMount,
|
|
3735
|
+
renderFormatButton = props.renderFormatButton;
|
|
3719
3736
|
var containerRef = React.useRef(null);
|
|
3720
3737
|
var editorRef = React.useRef(null);
|
|
3721
3738
|
var modelRef = React.useRef(null);
|
|
@@ -3829,6 +3846,18 @@ function SqlEditor(props) {
|
|
|
3829
3846
|
}, '!suggestWidgetVisible && isEditorFocused' + id);
|
|
3830
3847
|
editorDidMount == null || editorDidMount(editor);
|
|
3831
3848
|
};
|
|
3849
|
+
var handleFormat = React.useCallback(function () {
|
|
3850
|
+
var editor = editorRef.current;
|
|
3851
|
+
if (!editor) return;
|
|
3852
|
+
var currentValue = editor.getValue();
|
|
3853
|
+
var formatted = formatSql(currentValue);
|
|
3854
|
+
editor.setValue(formatted);
|
|
3855
|
+
}, []);
|
|
3856
|
+
React.useImperativeHandle(ref, function () {
|
|
3857
|
+
return {
|
|
3858
|
+
format: handleFormat
|
|
3859
|
+
};
|
|
3860
|
+
});
|
|
3832
3861
|
var themeValue = themeMap$2[theme];
|
|
3833
3862
|
return React__default.createElement("div", {
|
|
3834
3863
|
className: 'ant-input' + (size ? " " + SIZE_MAP$2[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName$2 : '') + (readOnly ? " " + containerReadOnlyClassName$2 : '') + (className ? " " + className : ''),
|
|
@@ -3836,6 +3865,7 @@ function SqlEditor(props) {
|
|
|
3836
3865
|
display: 'block',
|
|
3837
3866
|
resize: 'vertical',
|
|
3838
3867
|
overflow: 'auto',
|
|
3868
|
+
position: 'relative',
|
|
3839
3869
|
minHeight: SIZE_MAP$2[size].minHeight,
|
|
3840
3870
|
maxHeight: maxHeight
|
|
3841
3871
|
}
|
|
@@ -3885,8 +3915,41 @@ function SqlEditor(props) {
|
|
|
3885
3915
|
alwaysConsumeMouseWheel: false
|
|
3886
3916
|
}
|
|
3887
3917
|
}
|
|
3888
|
-
})))
|
|
3889
|
-
|
|
3918
|
+
})), enableFormat && (renderFormatButton ? renderFormatButton(handleFormat) : React__default.createElement("button", {
|
|
3919
|
+
onClick: handleFormat,
|
|
3920
|
+
className: formatBtnClassName,
|
|
3921
|
+
title: 'Format SQL',
|
|
3922
|
+
style: {
|
|
3923
|
+
'--format-btn-hover-bg': theme === 'dark' ? 'rgba(255,255,255,0.2)' : 'rgba(128,128,128,0.15)'
|
|
3924
|
+
}
|
|
3925
|
+
}, React__default.createElement("svg", {
|
|
3926
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
3927
|
+
width: '12',
|
|
3928
|
+
height: '12',
|
|
3929
|
+
viewBox: '0 0 24 24',
|
|
3930
|
+
fill: 'none',
|
|
3931
|
+
stroke: 'currentColor',
|
|
3932
|
+
strokeWidth: '1',
|
|
3933
|
+
strokeLinecap: 'round',
|
|
3934
|
+
strokeLinejoin: 'round'
|
|
3935
|
+
}, React__default.createElement("path", {
|
|
3936
|
+
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'
|
|
3937
|
+
}), React__default.createElement("path", {
|
|
3938
|
+
d: 'm14 7 3 3'
|
|
3939
|
+
}), React__default.createElement("path", {
|
|
3940
|
+
d: 'M5 6v4'
|
|
3941
|
+
}), React__default.createElement("path", {
|
|
3942
|
+
d: 'M19 14v4'
|
|
3943
|
+
}), React__default.createElement("path", {
|
|
3944
|
+
d: 'M10 2v2'
|
|
3945
|
+
}), React__default.createElement("path", {
|
|
3946
|
+
d: 'M7 8H3'
|
|
3947
|
+
}), React__default.createElement("path", {
|
|
3948
|
+
d: 'M21 16h-4'
|
|
3949
|
+
}), React__default.createElement("path", {
|
|
3950
|
+
d: 'M11 3H9'
|
|
3951
|
+
})))));
|
|
3952
|
+
});
|
|
3890
3953
|
|
|
3891
3954
|
var languageConfiguration$3 = {
|
|
3892
3955
|
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|