@coveord/plasma-mantine 52.18.0 → 52.19.0
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/.turbo/turbo-build.log +3 -3
- package/.turbo/turbo-test.log +31 -31
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.d.ts +3 -1
- package/dist/cjs/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.js +16 -3
- package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.d.ts +3 -1
- package/dist/esm/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.js +17 -4
- package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
- package/package.json +3 -3
- package/src/components/code-editor/CodeEditor.tsx +15 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DefaultProps, InputWrapperBaseProps, Selectors } from '@mantine/core';
|
|
2
2
|
import { FunctionComponent } from 'react';
|
|
3
|
-
declare const useStyles: (params:
|
|
3
|
+
declare const useStyles: (params: {
|
|
4
|
+
error?: boolean;
|
|
5
|
+
}, options?: import("@mantine/core").UseStylesOptions<string>) => {
|
|
4
6
|
classes: {
|
|
5
7
|
root: string;
|
|
6
8
|
editor: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIH,YAAY,EAGZ,qBAAqB,EAGrB,SAAS,EAIZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIH,YAAY,EAGZ,qBAAqB,EAGrB,SAAS,EAIZ,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAC,iBAAiB,EAA8B,MAAM,OAAO,CAAC;AAOrE,QAAA,MAAM,SAAS;YAA0C,OAAO;;;;;;;;CAW7D,CAAC;AAEJ,UAAU,eACN,SAAQ,IAAI,CAAC,qBAAqB,EAAE,gBAAgB,GAAG,mBAAmB,CAAC,EACvE,YAAY,CAAC,SAAS,CAAC,OAAO,SAAS,CAAC,CAAC;IAC7C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;IAChE,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,IAAI,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,IAAI,IAAI,CAAC;IAChB,qDAAqD;IACrD,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAClC;AASD,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,CAoJzD,CAAC"}
|
|
@@ -24,14 +24,18 @@ var _hooks1 = require("../../hooks");
|
|
|
24
24
|
var _xml = require("./languages/xml");
|
|
25
25
|
var _copyToClipboard = require("../copyToClipboard");
|
|
26
26
|
var _search = require("./search");
|
|
27
|
-
var useStyles = (0, _core.createStyles)(function(theme) {
|
|
27
|
+
var useStyles = (0, _core.createStyles)(function(theme, param) {
|
|
28
|
+
var error = param.error;
|
|
28
29
|
return {
|
|
29
30
|
root: {},
|
|
30
31
|
editor: {
|
|
31
32
|
border: "1px solid ".concat(theme.colors.gray[2]),
|
|
32
33
|
borderRadius: theme.defaultRadius,
|
|
33
34
|
backgroundColor: theme.colorScheme === "light" ? theme.white : theme.black,
|
|
34
|
-
height: "100%"
|
|
35
|
+
height: "100%",
|
|
36
|
+
outlineColor: error ? theme.colors.red[6] : null,
|
|
37
|
+
outlineStyle: error ? "solid" : "none",
|
|
38
|
+
outlineWidth: "thin"
|
|
35
39
|
}
|
|
36
40
|
};
|
|
37
41
|
});
|
|
@@ -63,7 +67,10 @@ var CodeEditor = function(props) {
|
|
|
63
67
|
"monacoLoader"
|
|
64
68
|
]);
|
|
65
69
|
var _useState = _sliced_to_array._((0, _react1.useState)(false), 2), loaded = _useState[0], setLoaded = _useState[1];
|
|
66
|
-
var
|
|
70
|
+
var _useState1 = _sliced_to_array._((0, _react1.useState)(false), 2), containsError = _useState1[0], setContainsError = _useState1[1];
|
|
71
|
+
var _useStyles = useStyles({
|
|
72
|
+
error: containsError
|
|
73
|
+
}), classes = _useStyles.classes, theme = _useStyles.theme;
|
|
67
74
|
var _useUncontrolled = _sliced_to_array._((0, _hooks.useUncontrolled)({
|
|
68
75
|
value: value,
|
|
69
76
|
defaultValue: defaultValue,
|
|
@@ -120,6 +127,11 @@ var CodeEditor = function(props) {
|
|
|
120
127
|
setLoaded(true);
|
|
121
128
|
}
|
|
122
129
|
}, []);
|
|
130
|
+
var handleValidate = function(markers) {
|
|
131
|
+
setContainsError(markers.some(function(marker) {
|
|
132
|
+
return marker.severity === _react.loader.__getMonacoInstance().MarkerSeverity.Error;
|
|
133
|
+
}));
|
|
134
|
+
};
|
|
123
135
|
var _label = label ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_core.Input.Label, _object_spread_props._(_object_spread._({
|
|
124
136
|
required: required
|
|
125
137
|
}, labelProps), {
|
|
@@ -162,6 +174,7 @@ var CodeEditor = function(props) {
|
|
|
162
174
|
pl: "xs",
|
|
163
175
|
className: classes.editor,
|
|
164
176
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_react.default, {
|
|
177
|
+
onValidate: handleValidate,
|
|
165
178
|
defaultLanguage: language,
|
|
166
179
|
theme: theme.colorScheme === "light" ? "light" : "vs-dark",
|
|
167
180
|
options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n px,\n Selectors,\n Space,\n Stack,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {loader, Monaco} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useState, useRef} from 'react';\n\nimport {useParentHeight} from '../../hooks';\nimport {XML} from './languages/xml';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport {Search} from './search';\n\nconst useStyles = createStyles((theme) => ({\n root: {},\n editor: {\n border: `1px solid ${theme.colors.gray[2]}`,\n borderRadius: theme.defaultRadius,\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n height: '100%',\n },\n}));\n\ninterface CodeEditorProps\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml';\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useComponentDefaultProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const {classes, theme} = useStyles();\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group position=\"right\" spacing={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n\n const _editor = loaded ? (\n <Box p=\"md\" pl=\"xs\" className={classes.editor}>\n <Editor\n defaultLanguage={language}\n theme={theme.colorScheme === 'light' ? 'light' : 'vs-dark'}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs),\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={classes.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack\n justify=\"flex-start\"\n className={classes.root}\n spacing={0}\n sx={{height: Math.max(parentHeight, minHeight), maxHeight}}\n ref={ref}\n {...others}\n >\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CodeEditor","useStyles","createStyles","theme","root","editor","border","colors","gray","borderRadius","defaultRadius","backgroundColor","colorScheme","white","black","height","defaultProps","language","monacoLoader","defaultValue","minHeight","props","useComponentDefaultProps","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","classes","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","editorRef","useRef","loadLocalMonaco","monacoInstance","loader","config","monaco","registerLanguages","XML","register","handleSearch","current","focus","trigger","useEffect","_label","Input","Label","_description","Description","_error","Error","mt","Space","h","_header","Box","_buttons","Group","position","spacing","Search","CopyToClipboard","_editor","p","pl","className","Editor","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","px","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","justify","sx","Math","max"],"mappings":";;;;+BAwFaA;;;eAAAA;;;;;;;;;;;oBA1EN;qBACuB;+DACO;sBACwB;sBAE/B;mBACZ;+BACY;sBACT;AAErB,IAAMC,YAAYC,IAAAA,kBAAY,EAAC,SAACC;WAAW;QACvCC,MAAM,CAAC;QACPC,QAAQ;YACJC,QAAQ,AAAC,aAAiC,OAArBH,MAAMI,MAAM,CAACC,IAAI,CAAC,EAAE;YACzCC,cAAcN,MAAMO,aAAa;YACjCC,iBAAiBR,MAAMS,WAAW,KAAK,UAAUT,MAAMU,KAAK,GAAGV,MAAMW,KAAK;YAC1EC,QAAQ;QACZ;IACJ;;AAiDA,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEO,IAAMpB,aAAiD,SAACqB;IAC3D,IAoBIC,4BAAAA,IAAAA,8BAAwB,EAAC,cAAcN,cAAcK,QAnBrDJ,WAmBAK,0BAnBAL,UACAE,eAkBAG,0BAlBAH,cACAI,WAiBAD,0BAjBAC,UACAC,SAgBAF,0BAhBAE,QACAC,WAeAH,0BAfAG,UACAC,UAcAJ,0BAdAI,SACAC,QAaAL,0BAbAK,OACAC,QAYAN,0BAZAM,OACAC,WAWAP,0BAXAO,UACAC,aAUAR,0BAVAQ,YACAC,QASAT,0BATAS,OACAC,aAQAV,0BARAU,YACAC,cAOAX,0BAPAW,aACAC,mBAMAZ,0BANAY,kBACAd,YAKAE,0BALAF,WACAe,YAIAb,0BAJAa,WACAC,WAGAd,0BAHAc,UACAlB,eAEAI,0BAFAJ,cACGmB,sCACHf;QAnBAL;QACAE;QACAI;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC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,IAAI;YAAC9F,QAAQ+F,KAAKC,GAAG,CAAChE,cAAc3B;YAAYe,WAAAA;QAAS;QACzDa,KAAKA;OACDX;;YAEHqC;YACAE;YACAM;YACAb;;;AAGb"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n px,\n Selectors,\n Space,\n Stack,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport Editor, {loader, Monaco} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport {useParentHeight} from '../../hooks';\nimport {XML} from './languages/xml';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport {Search} from './search';\n\nconst useStyles = createStyles((theme, {error}: {error?: boolean}) => ({\n root: {},\n editor: {\n border: `1px solid ${theme.colors.gray[2]}`,\n borderRadius: theme.defaultRadius,\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n height: '100%',\n outlineColor: error ? theme.colors.red[6] : null,\n outlineStyle: error ? 'solid' : 'none',\n outlineWidth: 'thin',\n },\n}));\n\ninterface CodeEditorProps\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml';\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useComponentDefaultProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [containsError, setContainsError] = useState(false);\n const {classes, theme} = useStyles({error: containsError});\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setContainsError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group position=\"right\" spacing={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n\n const _editor = loaded ? (\n <Box p=\"md\" pl=\"xs\" className={classes.editor}>\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={theme.colorScheme === 'light' ? 'light' : 'vs-dark'}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs),\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={classes.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack\n justify=\"flex-start\"\n className={classes.root}\n spacing={0}\n sx={{height: Math.max(parentHeight, minHeight), maxHeight}}\n ref={ref}\n {...others}\n >\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CodeEditor","useStyles","createStyles","theme","error","root","editor","border","colors","gray","borderRadius","defaultRadius","backgroundColor","colorScheme","white","black","height","outlineColor","red","outlineStyle","outlineWidth","defaultProps","language","monacoLoader","defaultValue","minHeight","props","useComponentDefaultProps","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","containsError","setContainsError","classes","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","editorRef","useRef","loadLocalMonaco","monacoInstance","loader","config","monaco","registerLanguages","XML","register","handleSearch","current","focus","trigger","useEffect","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Input","Label","_description","Description","_error","mt","Space","h","_header","Box","_buttons","Group","position","spacing","Search","CopyToClipboard","_editor","p","pl","className","Editor","onValidate","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","px","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","justify","sx","Math","max"],"mappings":";;;;+BA4FaA;;;eAAAA;;;;;;;;;;;oBA9EN;qBACuB;+DAEO;sBACwB;sBAE/B;mBACZ;+BACY;sBACT;AAErB,IAAMC,YAAYC,IAAAA,kBAAY,EAAC,SAACC;QAAQC,cAAAA;WAA+B;QACnEC,MAAM,CAAC;QACPC,QAAQ;YACJC,QAAQ,AAAC,aAAiC,OAArBJ,MAAMK,MAAM,CAACC,IAAI,CAAC,EAAE;YACzCC,cAAcP,MAAMQ,aAAa;YACjCC,iBAAiBT,MAAMU,WAAW,KAAK,UAAUV,MAAMW,KAAK,GAAGX,MAAMY,KAAK;YAC1EC,QAAQ;YACRC,cAAcb,QAAQD,MAAMK,MAAM,CAACU,GAAG,CAAC,EAAE,GAAG;YAC5CC,cAAcf,QAAQ,UAAU;YAChCgB,cAAc;QAClB;IACJ;;AAiDA,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEO,IAAMzB,aAAiD,SAAC0B;IAC3D,IAoBIC,4BAAAA,IAAAA,8BAAwB,EAAC,cAAcN,cAAcK,QAnBrDJ,WAmBAK,0BAnBAL,UACAE,eAkBAG,0BAlBAH,cACAI,WAiBAD,0BAj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E;YACjBnB,OAAOA,MAAMU,WAAW,KAAK,UAAU,UAAU;YACjDyF,SAAS;gBACLC,SAAS;oBAACC,SAAS;gBAAK;gBACxBC,UAAU;gBACVC,sBAAsB;gBACtBC,eAAe;gBACfC,UAAUC,IAAAA,QAAE,EAAC1G,MAAM2G,SAAS,CAACC,EAAE;gBAC/BC,UAAUxE;gBACVyE,SAAS;YACb;YACAjF,OAAOkB;YACPtB,UAAUuB;YACV+D,SAAS,SAAC5G,QAAQuD;gBACdN,UAAUW,OAAO,GAAG5D;gBACpBwD,kBAAkBD;gBAClBvD,OAAO6G,oBAAoB,CAAC;wBAAMpF;4BAAAA,WAAAA,qBAAAA,+BAAAA;;gBAClCzB,OAAO8G,mBAAmB,eAAC,sBAAA;;;;gCACvB;;oCAAM9G,OAAO+G,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,qBAACC,YAAM;QAACrB,WAAWnD,QAAQzC,MAAM;kBAC7B,cAAA,qBAACkH,YAAM;;IAIf,qBACI,sBAACC,WAAK;QACFC,SAAQ;QACRxB,WAAWnD,QAAQ1C,IAAI;QACvBuF,SAAS;QACT+B,IAAI;YAAC3G,QAAQ4G,KAAKC,GAAG,CAACxE,cAAc5B;YAAYc,WAAAA;QAAS;QACzDe,KAAKA;OACDb;;YAEH8C;YACAE;YACAM;YACAZ;;;AAGb"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DefaultProps, InputWrapperBaseProps, Selectors } from '@mantine/core';
|
|
2
2
|
import { FunctionComponent } from 'react';
|
|
3
|
-
declare const useStyles: (params:
|
|
3
|
+
declare const useStyles: (params: {
|
|
4
|
+
error?: boolean;
|
|
5
|
+
}, options?: import("@mantine/core").UseStylesOptions<string>) => {
|
|
4
6
|
classes: {
|
|
5
7
|
root: string;
|
|
6
8
|
editor: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIH,YAAY,EAGZ,qBAAqB,EAGrB,SAAS,EAIZ,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIH,YAAY,EAGZ,qBAAqB,EAGrB,SAAS,EAIZ,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAC,iBAAiB,EAA8B,MAAM,OAAO,CAAC;AAOrE,QAAA,MAAM,SAAS;YAA0C,OAAO;;;;;;;;CAW7D,CAAC;AAEJ,UAAU,eACN,SAAQ,IAAI,CAAC,qBAAqB,EAAE,gBAAgB,GAAG,mBAAmB,CAAC,EACvE,YAAY,CAAC,SAAS,CAAC,OAAO,SAAS,CAAC,CAAC;IAC7C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;IAChE,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,IAAI,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,IAAI,IAAI,CAAC;IAChB,qDAAqD;IACrD,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAClC;AASD,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,CAoJzD,CAAC"}
|
|
@@ -8,19 +8,23 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
8
8
|
import { Box, Center, createStyles, Group, Input, Loader, px, Space, Stack, useComponentDefaultProps } from "@mantine/core";
|
|
9
9
|
import { useUncontrolled } from "@mantine/hooks";
|
|
10
10
|
import Editor, { loader } from "@monaco-editor/react";
|
|
11
|
-
import { useEffect,
|
|
11
|
+
import { useEffect, useRef, useState } from "react";
|
|
12
12
|
import { useParentHeight } from "../../hooks";
|
|
13
13
|
import { XML } from "./languages/xml";
|
|
14
14
|
import { CopyToClipboard } from "../copyToClipboard";
|
|
15
15
|
import { Search } from "./search";
|
|
16
|
-
var useStyles = createStyles(function(theme) {
|
|
16
|
+
var useStyles = createStyles(function(theme, param) {
|
|
17
|
+
var error = param.error;
|
|
17
18
|
return {
|
|
18
19
|
root: {},
|
|
19
20
|
editor: {
|
|
20
21
|
border: "1px solid ".concat(theme.colors.gray[2]),
|
|
21
22
|
borderRadius: theme.defaultRadius,
|
|
22
23
|
backgroundColor: theme.colorScheme === "light" ? theme.white : theme.black,
|
|
23
|
-
height: "100%"
|
|
24
|
+
height: "100%",
|
|
25
|
+
outlineColor: error ? theme.colors.red[6] : null,
|
|
26
|
+
outlineStyle: error ? "solid" : "none",
|
|
27
|
+
outlineWidth: "thin"
|
|
24
28
|
}
|
|
25
29
|
};
|
|
26
30
|
});
|
|
@@ -52,7 +56,10 @@ export var CodeEditor = function(props) {
|
|
|
52
56
|
"monacoLoader"
|
|
53
57
|
]);
|
|
54
58
|
var _useState = _sliced_to_array(useState(false), 2), loaded = _useState[0], setLoaded = _useState[1];
|
|
55
|
-
var
|
|
59
|
+
var _useState1 = _sliced_to_array(useState(false), 2), containsError = _useState1[0], setContainsError = _useState1[1];
|
|
60
|
+
var _useStyles = useStyles({
|
|
61
|
+
error: containsError
|
|
62
|
+
}), classes = _useStyles.classes, theme = _useStyles.theme;
|
|
56
63
|
var _useUncontrolled = _sliced_to_array(useUncontrolled({
|
|
57
64
|
value: value,
|
|
58
65
|
defaultValue: defaultValue,
|
|
@@ -107,6 +114,11 @@ export var CodeEditor = function(props) {
|
|
|
107
114
|
setLoaded(true);
|
|
108
115
|
}
|
|
109
116
|
}, []);
|
|
117
|
+
var handleValidate = function(markers) {
|
|
118
|
+
setContainsError(markers.some(function(marker) {
|
|
119
|
+
return marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error;
|
|
120
|
+
}));
|
|
121
|
+
};
|
|
110
122
|
var _label = label ? /*#__PURE__*/ _jsx(Input.Label, _object_spread_props(_object_spread({
|
|
111
123
|
required: required
|
|
112
124
|
}, labelProps), {
|
|
@@ -149,6 +161,7 @@ export var CodeEditor = function(props) {
|
|
|
149
161
|
pl: "xs",
|
|
150
162
|
className: classes.editor,
|
|
151
163
|
children: /*#__PURE__*/ _jsx(Editor, {
|
|
164
|
+
onValidate: handleValidate,
|
|
152
165
|
defaultLanguage: language,
|
|
153
166
|
theme: theme.colorScheme === "light" ? "light" : "vs-dark",
|
|
154
167
|
options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n px,\n Selectors,\n Space,\n Stack,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {loader, Monaco} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useState, useRef} from 'react';\n\nimport {useParentHeight} from '../../hooks';\nimport {XML} from './languages/xml';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport {Search} from './search';\n\nconst useStyles = createStyles((theme) => ({\n root: {},\n editor: {\n border: `1px solid ${theme.colors.gray[2]}`,\n borderRadius: theme.defaultRadius,\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n height: '100%',\n },\n}));\n\ninterface CodeEditorProps\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml';\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useComponentDefaultProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const {classes, theme} = useStyles();\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group position=\"right\" spacing={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n\n const _editor = loaded ? (\n <Box p=\"md\" pl=\"xs\" className={classes.editor}>\n <Editor\n defaultLanguage={language}\n theme={theme.colorScheme === 'light' ? 'light' : 'vs-dark'}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs),\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={classes.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack\n justify=\"flex-start\"\n className={classes.root}\n spacing={0}\n sx={{height: Math.max(parentHeight, minHeight), maxHeight}}\n ref={ref}\n {...others}\n >\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["Box","Center","createStyles","Group","Input","Loader","px","Space","Stack","useComponentDefaultProps","useUncontrolled","Editor","loader","useEffect","useState","useRef","useParentHeight","XML","CopyToClipboard","Search","useStyles","theme","root","editor","border","colors","gray","borderRadius","defaultRadius","backgroundColor","colorScheme","white","black","height","defaultProps","language","monacoLoader","defaultValue","minHeight","CodeEditor","props","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","loaded","setLoaded","classes","finalValue","_value","handleChange","parentHeight","ref","editorRef","loadLocalMonaco","monacoInstance","config","monaco","registerLanguages","register","handleSearch","current","focus","trigger","_label","Label","_description","Description","_error","Error","mt","h","_header","_buttons","position","spacing","_editor","p","pl","className","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","justify","sx","Math","max"],"mappings":";;;;;;;AAAA,SACIA,GAAG,EACHC,MAAM,EACNC,YAAY,EAEZC,KAAK,EACLC,KAAK,EAELC,MAAM,EACNC,EAAE,EAEFC,KAAK,EACLC,KAAK,EACLC,wBAAwB,QACrB,gBAAgB;AACvB,SAAQC,eAAe,QAAO,iBAAiB;AAC/C,OAAOC,UAASC,MAAM,QAAe,uBAAuB;AAC5D,SAA2BC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,QAAO,QAAQ;AAErE,SAAQC,eAAe,QAAO,cAAc;AAC5C,SAAQC,GAAG,QAAO,kBAAkB;AACpC,SAAQC,eAAe,QAAO,qBAAqB;AACnD,SAAQC,MAAM,QAAO,WAAW;AAEhC,IAAMC,YAAYlB,aAAa,SAACmB;WAAW;QACvCC,MAAM,CAAC;QACPC,QAAQ;YACJC,QAAQ,AAAC,aAAiC,OAArBH,MAAMI,MAAM,CAACC,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;YACGgF,iBAAiBxD;YACjBd,OAAOA,MAAMS,WAAW,KAAK,UAAU,UAAU;YACjD8D,SAAS;gBACLC,SAAS;oBAACC,SAAS;gBAAK;gBACxBC,UAAU;gBACVC,sBAAsB;gBACtBC,eAAe;gBACfC,UAAU5F,GAAGe,MAAM8E,SAAS,CAACC,EAAE;gBAC/BC,UAAU/C;gBACVgD,SAAS;YACb;YACAzD,OAAOe;YACPnB,UAAUoB;YACV0C,SAAS,SAAChF,QAAQ6C;gBACdJ,UAAUQ,OAAO,GAAGjD;gBACpB8C,kBAAkBD;gBAClB7C,OAAOiF,oBAAoB,CAAC;wBAAM5D;4BAAAA,WAAAA,qBAAAA,+BAAAA;;gBAClCrB,OAAOkF,mBAAmB,eAAC,oBAAA;;;;gCACvB;;oCAAMlF,OAAOmF,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,KAAC1G;QAAOyF,WAAWhC,QAAQnC,MAAM;kBAC7B,cAAA,KAAClB;;IAIT,qBACI,MAACG;QACGoG,SAAQ;QACRlB,WAAWhC,QAAQpC,IAAI;QACvBgE,SAAS;QACTuB,IAAI;YAAC5E,QAAQ6E,KAAKC,GAAG,CAACjD,cAAcxB;YAAYe,WAAAA;QAAS;QACzDU,KAAKA;OACDR;;YAEH4B;YACAC;YACAG;YACAR;;;AAGb,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n px,\n Selectors,\n Space,\n Stack,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport Editor, {loader, Monaco} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport {useParentHeight} from '../../hooks';\nimport {XML} from './languages/xml';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport {Search} from './search';\n\nconst useStyles = createStyles((theme, {error}: {error?: boolean}) => ({\n root: {},\n editor: {\n border: `1px solid ${theme.colors.gray[2]}`,\n borderRadius: theme.defaultRadius,\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n height: '100%',\n outlineColor: error ? theme.colors.red[6] : null,\n outlineStyle: error ? 'solid' : 'none',\n outlineWidth: 'thin',\n },\n}));\n\ninterface CodeEditorProps\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml';\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useComponentDefaultProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [containsError, setContainsError] = useState(false);\n const {classes, theme} = useStyles({error: containsError});\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setContainsError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group position=\"right\" spacing={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n\n const _editor = loaded ? (\n <Box p=\"md\" pl=\"xs\" className={classes.editor}>\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={theme.colorScheme === 'light' ? 'light' : 'vs-dark'}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs),\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={classes.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack\n justify=\"flex-start\"\n className={classes.root}\n spacing={0}\n sx={{height: Math.max(parentHeight, minHeight), maxHeight}}\n ref={ref}\n {...others}\n >\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["Box","Center","createStyles","Group","Input","Loader","px","Space","Stack","useComponentDefaultProps","useUncontrolled","Editor","loader","useEffect","useRef","useState","useParentHeight","XML","CopyToClipboard","Search","useStyles","theme","error","root","editor","border","colors","gray","borderRadius","defaultRadius","backgroundColor","colorScheme","white","black","height","outlineColor","red","outlineStyle","outlineWidth","defaultProps","language","monacoLoader","defaultValue","minHeight","CodeEditor","props","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","errorProps","description","descriptionProps","maxHeight","disabled","others","loaded","setLoaded","containsError","setContainsError","classes","finalValue","_value","handleChange","parentHeight","ref","editorRef","loadLocalMonaco","monacoInstance","config","monaco","registerLanguages","register","handleSearch","current","focus","trigger","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Label","_description","Description","_error","mt","h","_header","_buttons","position","spacing","_editor","p","pl","className","onValidate","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","justify","sx","Math","max"],"mappings":";;;;;;;AAAA,SACIA,GAAG,EAC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,GAAGtD;gBACpBmD,kBAAkBD;gBAClBlD,OAAO8F,oBAAoB,CAAC;wBAAMrE;4BAAAA,WAAAA,qBAAAA,+BAAAA;;gBAClCzB,OAAO+F,mBAAmB,eAAC,oBAAA;;;;gCACvB;;oCAAM/F,OAAOgG,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,KAACxH;QAAOsG,WAAWvC,QAAQxC,MAAM;kBAC7B,cAAA,KAACnB;;IAIT,qBACI,MAACG;QACGkH,SAAQ;QACRnB,WAAWvC,QAAQzC,IAAI;QACvB4E,SAAS;QACTwB,IAAI;YAACzF,QAAQ0F,KAAKC,GAAG,CAACzD,cAAczB;YAAYc,WAAAA;QAAS;QACzDY,KAAKA;OACDV;;YAEHqC;YACAC;YACAG;YACAP;;;AAGb,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coveord/plasma-mantine",
|
|
3
|
-
"version": "52.
|
|
3
|
+
"version": "52.19.0",
|
|
4
4
|
"description": "A Plasma flavoured Mantine theme",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plasma",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@mantine/utils": "6.0.19",
|
|
35
35
|
"@monaco-editor/react": "4.5.1",
|
|
36
36
|
"@swc/helpers": "0.5.1",
|
|
37
|
-
"@tanstack/react-table": "8.10.
|
|
38
|
-
"@tanstack/table-core": "8.10.
|
|
37
|
+
"@tanstack/react-table": "8.10.3",
|
|
38
|
+
"@tanstack/table-core": "8.10.3",
|
|
39
39
|
"dayjs": "1.11.9",
|
|
40
40
|
"fast-deep-equal": "3.1.3",
|
|
41
41
|
"lodash.debounce": "4.0.8",
|
|
@@ -14,21 +14,25 @@ import {
|
|
|
14
14
|
useComponentDefaultProps,
|
|
15
15
|
} from '@mantine/core';
|
|
16
16
|
import {useUncontrolled} from '@mantine/hooks';
|
|
17
|
+
import {editor as monacoEditor} from 'monaco-editor';
|
|
17
18
|
import Editor, {loader, Monaco} from '@monaco-editor/react';
|
|
18
|
-
import {FunctionComponent, useEffect,
|
|
19
|
+
import {FunctionComponent, useEffect, useRef, useState} from 'react';
|
|
19
20
|
|
|
20
21
|
import {useParentHeight} from '../../hooks';
|
|
21
22
|
import {XML} from './languages/xml';
|
|
22
23
|
import {CopyToClipboard} from '../copyToClipboard';
|
|
23
24
|
import {Search} from './search';
|
|
24
25
|
|
|
25
|
-
const useStyles = createStyles((theme) => ({
|
|
26
|
+
const useStyles = createStyles((theme, {error}: {error?: boolean}) => ({
|
|
26
27
|
root: {},
|
|
27
28
|
editor: {
|
|
28
29
|
border: `1px solid ${theme.colors.gray[2]}`,
|
|
29
30
|
borderRadius: theme.defaultRadius,
|
|
30
31
|
backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,
|
|
31
32
|
height: '100%',
|
|
33
|
+
outlineColor: error ? theme.colors.red[6] : null,
|
|
34
|
+
outlineStyle: error ? 'solid' : 'none',
|
|
35
|
+
outlineWidth: 'thin',
|
|
32
36
|
},
|
|
33
37
|
}));
|
|
34
38
|
|
|
@@ -109,7 +113,8 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
|
|
|
109
113
|
...others
|
|
110
114
|
} = useComponentDefaultProps('CodeEditor', defaultProps, props);
|
|
111
115
|
const [loaded, setLoaded] = useState(false);
|
|
112
|
-
const
|
|
116
|
+
const [containsError, setContainsError] = useState(false);
|
|
117
|
+
const {classes, theme} = useStyles({error: containsError});
|
|
113
118
|
const [_value, handleChange] = useUncontrolled<string>({
|
|
114
119
|
value,
|
|
115
120
|
defaultValue,
|
|
@@ -118,7 +123,6 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
|
|
|
118
123
|
});
|
|
119
124
|
const [parentHeight, ref] = useParentHeight();
|
|
120
125
|
const editorRef = useRef(null);
|
|
121
|
-
|
|
122
126
|
const loadLocalMonaco = async () => {
|
|
123
127
|
const monacoInstance = await import('monaco-editor');
|
|
124
128
|
loader.config({monaco: monacoInstance});
|
|
@@ -147,6 +151,12 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
|
|
|
147
151
|
}
|
|
148
152
|
}, []);
|
|
149
153
|
|
|
154
|
+
const handleValidate = (markers: monacoEditor.IMarker[]) => {
|
|
155
|
+
setContainsError(
|
|
156
|
+
markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
150
160
|
const _label = label ? (
|
|
151
161
|
<Input.Label required={required} {...labelProps}>
|
|
152
162
|
{label}
|
|
@@ -183,6 +193,7 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
|
|
|
183
193
|
const _editor = loaded ? (
|
|
184
194
|
<Box p="md" pl="xs" className={classes.editor}>
|
|
185
195
|
<Editor
|
|
196
|
+
onValidate={handleValidate}
|
|
186
197
|
defaultLanguage={language}
|
|
187
198
|
theme={theme.colorScheme === 'light' ? 'light' : 'vs-dark'}
|
|
188
199
|
options={{
|