@coveord/plasma-mantine 48.17.5 → 48.18.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.
Files changed (26) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +9 -9
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/code-editor/CodeEditor.js +15 -3
  5. package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
  6. package/dist/cjs/components/code-editor/__mocks__/@monaco-editor/react.js +6 -0
  7. package/dist/cjs/components/code-editor/__mocks__/@monaco-editor/react.js.map +1 -1
  8. package/dist/cjs/components/code-editor/languages/xml.js +60 -0
  9. package/dist/cjs/components/code-editor/languages/xml.js.map +1 -0
  10. package/dist/definitions/components/code-editor/CodeEditor.d.ts +1 -1
  11. package/dist/definitions/components/code-editor/CodeEditor.d.ts.map +1 -1
  12. package/dist/definitions/components/code-editor/__mocks__/@monaco-editor/react.d.ts +2 -1
  13. package/dist/definitions/components/code-editor/__mocks__/@monaco-editor/react.d.ts.map +1 -1
  14. package/dist/definitions/components/code-editor/languages/xml.d.ts +5 -0
  15. package/dist/definitions/components/code-editor/languages/xml.d.ts.map +1 -0
  16. package/dist/esm/components/code-editor/CodeEditor.js +16 -4
  17. package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
  18. package/dist/esm/components/code-editor/__mocks__/@monaco-editor/react.js +3 -0
  19. package/dist/esm/components/code-editor/__mocks__/@monaco-editor/react.js.map +1 -1
  20. package/dist/esm/components/code-editor/languages/xml.js +50 -0
  21. package/dist/esm/components/code-editor/languages/xml.js.map +1 -0
  22. package/package.json +1 -1
  23. package/src/components/code-editor/CodeEditor.tsx +14 -4
  24. package/src/components/code-editor/__mocks__/@monaco-editor/react.tsx +3 -1
  25. package/src/components/code-editor/__tests__/CodeEditor.spec.tsx +7 -0
  26. package/src/components/code-editor/languages/xml.ts +43 -0
@@ -22,6 +22,7 @@ var _hooks = require("@mantine/hooks");
22
22
  var _react = /*#__PURE__*/ _interopRequireWildcard(require("@monaco-editor/react"));
23
23
  var _react1 = require("react");
24
24
  var _hooks1 = require("../../hooks");
25
+ var _xml = require("./languages/xml");
25
26
  var useStyles = (0, _core.createStyles)(function(theme) {
26
27
  return {
27
28
  root: {},
@@ -59,6 +60,8 @@ var CodeEditor = function(props) {
59
60
  "monacoLoader"
60
61
  ]);
61
62
  var _useState = _slicedToArray((0, _react1.useState)(false), 2), loaded = _useState[0], setLoaded = _useState[1];
63
+ var _useState1 = _slicedToArray((0, _react1.useState)(false), 2), registered = _useState1[0], setRegistered = _useState1[1];
64
+ var monaco = (0, _react.useMonaco)();
62
65
  var _useStyles = useStyles(), classes = _useStyles.classes, theme = _useStyles.theme;
63
66
  var _useUncontrolled = _slicedToArray((0, _hooks.useUncontrolled)({
64
67
  value: value,
@@ -69,7 +72,7 @@ var CodeEditor = function(props) {
69
72
  var _useParentHeight = _slicedToArray((0, _hooks1.useParentHeight)(), 2), parentHeight = _useParentHeight[0], ref = _useParentHeight[1];
70
73
  var loadLocalMonaco = function() {
71
74
  var _ref = _asyncToGenerator(function() {
72
- var monaco;
75
+ var monacoInstance;
73
76
  return _tsGenerator(this, function(_state) {
74
77
  switch(_state.label){
75
78
  case 0:
@@ -80,9 +83,9 @@ var CodeEditor = function(props) {
80
83
  })
81
84
  ];
82
85
  case 1:
83
- monaco = _state.sent();
86
+ monacoInstance = _state.sent();
84
87
  _react.loader.config({
85
- monaco: monaco
88
+ monaco: monacoInstance
86
89
  });
87
90
  setLoaded(true);
88
91
  return [
@@ -102,6 +105,15 @@ var CodeEditor = function(props) {
102
105
  setLoaded(true);
103
106
  }
104
107
  }, []);
108
+ (0, _react1.useEffect)(function() {
109
+ if (monaco && language === "xml" && !registered) {
110
+ _xml.XML.register(monaco);
111
+ setRegistered(true);
112
+ }
113
+ }, [
114
+ monaco,
115
+ language
116
+ ]);
105
117
  var _label = label ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_core.Input.Label, _objectSpreadProps(_objectSpread({
106
118
  required: required
107
119
  }, labelProps), {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';\nimport {\n ActionIcon,\n Box,\n Center,\n CopyButton,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n Selectors,\n Space,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {loader} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useState} from 'react';\n\nimport {useParentHeight} from '../../hooks';\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';\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 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 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\n const loadLocalMonaco = async () => {\n const monaco = await import('monaco-editor');\n loader.config({monaco});\n setLoaded(true);\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 mt=\"xs\" {...descriptionProps}>\n {description}\n </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 _copyButton = (\n <Group position=\"right\">\n <CopyButton value={_value} timeout={2000}>\n {({copied, copy}) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position=\"right\">\n <ActionIcon color={copied ? 'lime' : 'gray'} onClick={copy}>\n {copied ? <CheckSize16Px height={16} /> : <CopySize16Px height={16} />}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\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 wrappingStrategy: 'advanced',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: theme.fontSizes.xs,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor) => {\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 {_copyButton}\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","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","classes","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","loadLocalMonaco","monaco","loader","config","useEffect","_label","Input","Label","_description","Description","mt","_error","Error","Space","h","_header","Box","_copyButton","Group","position","CopyButton","timeout","copied","copy","Tooltip","withArrow","ActionIcon","color","onClick","CheckSize16Px","CopySize16Px","_editor","p","pl","className","Editor","defaultLanguage","options","minimap","enabled","wordWrap","wrappingStrategy","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","justify","spacing","sx","Math","max"],"mappings":"AAAA;;;;+BAoFaA;;;eAAAA;;;;;;;;;;;gCApF6B;oBAiBnC;qBACuB;2DACD;sBACwB;sBAEvB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,SAAG;QAACgB,GAAE;QAAKC,IAAG;QAAKC,WAAW1C,QAAQlC,MAAM;kBACzC,cAAA,qBAAC6E,cAAM;YACHC,iBAAiBlE;YACjBd,OAAOA,MAAMS,WAAW,KAAK,UAAU,UAAU,SAAS;YAC1DwE,SAAS;gBACLC,SAAS;oBAACC,SAAS,KAAK;gBAAA;gBACxBC,UAAU;gBACVC,kBAAkB;gBAClBC,sBAAsB,KAAK;gBAC3BC,eAAe,IAAI;gBACnBC,UAAUxF,MAAMyF,SAAS,CAACC,EAAE;gBAC5BC,UAAU5D;gBACV6D,SAAS;YACb;YACAtE,OAAOiB;YACPnB,UAAUoB;YACVqD,SAAS,SAAC3F,QAAW;gBACjBA,OAAO4F,oBAAoB,CAACzE;gBAC5BnB,OAAO6F,mBAAmB,eAAC,kBAAA,WAAY;;;;gCACnC;;oCAAM7F,OAAO8F,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,qBAACC,YAAM;QAACpB,WAAW1C,QAAQlC,MAAM;kBAC7B,cAAA,qBAACiG,YAAM;MAEd;IAED,qBACI,sBAACC,WAAK;QACFC,SAAQ;QACRvB,WAAW1C,QAAQnC,IAAI;QACvBqG,SAAS;QACTC,IAAI;YAAC3F,QAAQ4F,KAAKC,GAAG,CAAC/D,cAAczB;YAAYa,WAAAA;QAAS;QACzDa,KAAKA;OACDX;;YAEH2B;YACAE;YACAc;YACApB;;;AAGb"}
1
+ {"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';\nimport {\n ActionIcon,\n Box,\n Center,\n CopyButton,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n Selectors,\n Space,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {loader, useMonaco} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useState} from 'react';\n\nimport {useParentHeight} from '../../hooks';\nimport {XML} from './languages/xml';\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 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 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 [registered, setRegistered] = useState(false);\n const monaco = useMonaco();\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\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n useEffect(() => {\n if (monaco && language === 'xml' && !registered) {\n XML.register(monaco);\n setRegistered(true);\n }\n }, [monaco, language]);\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 mt=\"xs\" {...descriptionProps}>\n {description}\n </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 _copyButton = (\n <Group position=\"right\">\n <CopyButton value={_value} timeout={2000}>\n {({copied, copy}) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position=\"right\">\n <ActionIcon color={copied ? 'lime' : 'gray'} onClick={copy}>\n {copied ? <CheckSize16Px height={16} /> : <CopySize16Px height={16} />}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\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 wrappingStrategy: 'advanced',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: theme.fontSizes.xs,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor) => {\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 {_copyButton}\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","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","registered","setRegistered","monaco","useMonaco","classes","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","loadLocalMonaco","monacoInstance","loader","config","useEffect","XML","register","_label","Input","Label","_description","Description","mt","_error","Error","Space","h","_header","Box","_copyButton","Group","position","CopyButton","timeout","copied","copy","Tooltip","withArrow","ActionIcon","color","onClick","CheckSize16Px","CopySize16Px","_editor","p","pl","className","Editor","defaultLanguage","options","minimap","enabled","wordWrap","wrappingStrategy","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","justify","spacing","sx","Math","max"],"mappings":"AAAA;;;;+BAqFaA;;;eAAAA;;;;;;;;;;;gCArF6B;oBAiBnC;qBACuB;2DACU;sBACa;sBAEvB;mBACZ;AAElB,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,iB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QAAQ;2CAAS,qBAACoE,8BAAY;4BAACpE,QAAQ;0BAAM;;;;;;IAQ9F,IAAMqE,UAAU/C,uBACZ,qBAACgC,SAAG;QAACgB,GAAE;QAAKC,IAAG;QAAKC,WAAW5C,QAAQtC,MAAM;kBACzC,cAAA,qBAACmF,cAAM;YACHC,iBAAiBxE;YACjBd,OAAOA,MAAMS,WAAW,KAAK,UAAU,UAAU,SAAS;YAC1D8E,SAAS;gBACLC,SAAS;oBAACC,SAAS,KAAK;gBAAA;gBACxBC,UAAU;gBACVC,kBAAkB;gBAClBC,sBAAsB,KAAK;gBAC3BC,eAAe,IAAI;gBACnBC,UAAU9F,MAAM+F,SAAS,CAACC,EAAE;gBAC5BC,UAAUlE;gBACVmE,SAAS;YACb;YACA5E,OAAOqB;YACPvB,UAAUwB;YACVuD,SAAS,SAACjG,QAAW;gBACjBA,OAAOkG,oBAAoB,CAAC/E;gBAC5BnB,OAAOmG,mBAAmB,eAAC,kBAAA,WAAY;;;;gCACnC;;oCAAMnG,OAAOoG,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,qBAACC,YAAM;QAACpB,WAAW5C,QAAQtC,MAAM;kBAC7B,cAAA,qBAACuG,YAAM;MAEd;IAED,qBACI,sBAACC,WAAK;QACFC,SAAQ;QACRvB,WAAW5C,QAAQvC,IAAI;QACvB2G,SAAS;QACTC,IAAI;YAACjG,QAAQkG,KAAKC,GAAG,CAACjE,cAAc7B;YAAYa,WAAAA;QAAS;QACzDiB,KAAKA;OACDf;;YAEHiC;YACAE;YACAc;YACApB;;;AAGb"}
@@ -14,6 +14,9 @@ _export(exports, {
14
14
  },
15
15
  loader: function() {
16
16
  return loader;
17
+ },
18
+ useMonaco: function() {
19
+ return useMonaco;
17
20
  }
18
21
  });
19
22
  var _jsxRuntime = require("react/jsx-runtime");
@@ -26,5 +29,8 @@ var _default = MockedEditor;
26
29
  var loader = {
27
30
  config: jest.fn()
28
31
  };
32
+ var useMonaco = function() {
33
+ return jest.fn();
34
+ };
29
35
 
30
36
  //# sourceMappingURL=react.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"sourcesContent":["import {type EditorProps} from '@monaco-editor/react';\nimport {FunctionComponent} from 'react';\n\nconst MockedEditor: FunctionComponent<EditorProps> = (props) => <div data-testid=\"monaco-editor\" />;\n\nexport default MockedEditor;\n\nexport const loader = {\n config: jest.fn(),\n};\n"],"names":["loader","MockedEditor","props","div","data-testid","config","jest","fn"],"mappings":"AAAA;;;;;;;;;;;IAKA,OAA4B;eAA5B;;IAEaA,MAAM;eAANA;;;;AAJb,IAAMC,eAA+C,SAACC;yBAAU,qBAACC;QAAIC,eAAY;;;IAEjF,WAAeH;AAER,IAAMD,SAAS;IAClBK,QAAQC,KAAKC,EAAE;AACnB"}
1
+ {"version":3,"sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"sourcesContent":["import {EditorProps} from '@monaco-editor/react';\nimport {FunctionComponent} from 'react';\n\nconst MockedEditor: FunctionComponent<EditorProps> = (props) => <div data-testid=\"monaco-editor\" />;\n\nexport default MockedEditor;\n\nexport const loader = {\n config: jest.fn(),\n};\n\nexport const useMonaco = () => jest.fn();\n"],"names":["loader","useMonaco","MockedEditor","props","div","data-testid","config","jest","fn"],"mappings":"AAAA;;;;;;;;;;;IAKA,OAA4B;eAA5B;;IAEaA,MAAM;eAANA;;IAIAC,SAAS;eAATA;;;;AARb,IAAMC,eAA+C,SAACC;yBAAU,qBAACC;QAAIC,eAAY;;;IAEjF,WAAeH;AAER,IAAMF,SAAS;IAClBM,QAAQC,KAAKC,EAAE;AACnB;AAEO,IAAMP,YAAY;WAAMM,KAAKC,EAAE"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "XML", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return XML;
9
+ }
10
+ });
11
+ var _asyncToGenerator = require("@swc/helpers/lib/_async_to_generator.js").default;
12
+ var _tsGenerator = require("@swc/helpers/lib/_ts_generator.js").default;
13
+ var format = function(xml) {
14
+ // https://stackoverflow.com/questions/57039218/doesnt-monaco-editor-support-xml-language-by-default
15
+ var PADDING = " ".repeat(2);
16
+ var reg = /(>)(<)(\/*)/g;
17
+ var pad = 0;
18
+ xml = xml.replace(reg, "$1\r\n$2$3");
19
+ return xml.split("\r\n").map(function(node) {
20
+ var indent = 0;
21
+ if (node.match(/.+<\/\w[^>]*>$/)) {
22
+ indent = 0;
23
+ } else if (node.match(/^<\/\w/) && pad > 0) {
24
+ pad -= 1;
25
+ } else if (node.match(/^<\w[^>]*[^/]>.*$/)) {
26
+ indent = 1;
27
+ } else {
28
+ indent = 0;
29
+ }
30
+ pad += indent;
31
+ return PADDING.repeat(pad - indent) + node;
32
+ }).join("\r\n");
33
+ };
34
+ var register = function(monaco) {
35
+ monaco.languages.registerDocumentFormattingEditProvider("xml", {
36
+ provideDocumentFormattingEdits: function() {
37
+ var _ref = _asyncToGenerator(function(model) {
38
+ return _tsGenerator(this, function(_state) {
39
+ return [
40
+ 2,
41
+ [
42
+ {
43
+ range: model.getFullModelRange(),
44
+ text: format(model.getValue())
45
+ }
46
+ ]
47
+ ];
48
+ });
49
+ });
50
+ return function(model) {
51
+ return _ref.apply(this, arguments);
52
+ };
53
+ }()
54
+ });
55
+ };
56
+ var XML = {
57
+ register: register
58
+ };
59
+
60
+ //# sourceMappingURL=xml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/components/code-editor/languages/xml.ts"],"sourcesContent":["import {Monaco} from '@monaco-editor/react';\n\nconst format = (xml: string): string => {\n // https://stackoverflow.com/questions/57039218/doesnt-monaco-editor-support-xml-language-by-default\n const PADDING = ' '.repeat(2);\n const reg = /(>)(<)(\\/*)/g;\n let pad = 0;\n\n xml = xml.replace(reg, '$1\\r\\n$2$3');\n\n return xml\n .split('\\r\\n')\n .map((node) => {\n let indent = 0;\n if (node.match(/.+<\\/\\w[^>]*>$/)) {\n indent = 0;\n } else if (node.match(/^<\\/\\w/) && pad > 0) {\n pad -= 1;\n } else if (node.match(/^<\\w[^>]*[^/]>.*$/)) {\n indent = 1;\n } else {\n indent = 0;\n }\n\n pad += indent;\n\n return PADDING.repeat(pad - indent) + node;\n })\n .join('\\r\\n');\n};\n\nconst register = (monaco: Monaco): void => {\n monaco.languages.registerDocumentFormattingEditProvider('xml', {\n provideDocumentFormattingEdits: async (model) => [\n {\n range: model.getFullModelRange(),\n text: format(model.getValue()),\n },\n ],\n });\n};\n\nexport const XML = {register};\n"],"names":["XML","format","xml","PADDING","repeat","reg","pad","replace","split","map","node","indent","match","join","register","monaco","languages","registerDocumentFormattingEditProvider","provideDocumentFormattingEdits","model","range","getFullModelRange","text","getValue"],"mappings":"AAAA;;;;+BA0CaA;;;eAAAA;;;;;AAxCb,IAAMC,SAAS,SAACC,KAAwB;IACpC,oGAAoG;IACpG,IAAMC,UAAU,IAAIC,MAAM,CAAC;IAC3B,IAAMC,MAAM;IACZ,IAAIC,MAAM;IAEVJ,MAAMA,IAAIK,OAAO,CAACF,KAAK;IAEvB,OAAOH,IACFM,KAAK,CAAC,QACNC,GAAG,CAAC,SAACC,MAAS;QACX,IAAIC,SAAS;QACb,IAAID,KAAKE,KAAK,CAAC,mBAAmB;YAC9BD,SAAS;QACb,OAAO,IAAID,KAAKE,KAAK,CAAC,aAAaN,MAAM,GAAG;YACxCA,OAAO;QACX,OAAO,IAAII,KAAKE,KAAK,CAAC,sBAAsB;YACxCD,SAAS;QACb,OAAO;YACHA,SAAS;QACb,CAAC;QAEDL,OAAOK;QAEP,OAAOR,QAAQC,MAAM,CAACE,MAAMK,UAAUD;IAC1C,GACCG,IAAI,CAAC;AACd;AAEA,IAAMC,WAAW,SAACC,QAAyB;IACvCA,OAAOC,SAAS,CAACC,sCAAsC,CAAC,OAAO;QAC3DC,8BAA8B;uBAAE,kBAAA,SAAOC;;oBAAU;;;4BAC7C;gCACIC,OAAOD,MAAME,iBAAiB;gCAC9BC,MAAMrB,OAAOkB,MAAMI,QAAQ;4BAC/B;;;;;4BAJmCJ;;;;IAM3C;AACJ;AAEO,IAAMnB,MAAM;IAACc,UAAAA;AAAQ"}
@@ -11,7 +11,7 @@ interface CodeEditorProps extends Omit<InputWrapperBaseProps, 'inputContainer' |
11
11
  *
12
12
  * @default 'plaintext'
13
13
  */
14
- language?: 'plaintext' | 'json' | 'markdown' | 'python';
14
+ language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml';
15
15
  /** Default value for uncontrolled input */
16
16
  defaultValue?: string;
17
17
  /** Value for controlled input */
@@ -1 +1 @@
1
- {"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AACA,OAAO,EAMH,YAAY,EAGZ,qBAAqB,EAErB,SAAS,EAKZ,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAC,iBAAiB,EAAsB,MAAM,OAAO,CAAC;AAI7D,QAAA,MAAM,SAAS;;;;CAQZ,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,CAAC;IACxD,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,qDAAqD;IACrD,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;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9 +1,10 @@
1
1
  /// <reference types="jest" />
2
- import { type EditorProps } from '@monaco-editor/react';
2
+ import { EditorProps } from '@monaco-editor/react';
3
3
  import { FunctionComponent } from 'react';
4
4
  declare const MockedEditor: FunctionComponent<EditorProps>;
5
5
  export default MockedEditor;
6
6
  export declare const loader: {
7
7
  config: jest.Mock<any, any>;
8
8
  };
9
+ export declare const useMonaco: () => jest.Mock<any, any>;
9
10
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAExC,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,WAAW,CAAkD,CAAC;AAEpG,eAAe,YAAY,CAAC;AAE5B,eAAO,MAAM,MAAM;;CAElB,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAExC,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,WAAW,CAAkD,CAAC;AAEpG,eAAe,YAAY,CAAC;AAE5B,eAAO,MAAM,MAAM;;CAElB,CAAC;AAEF,eAAO,MAAM,SAAS,2BAAkB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Monaco } from '@monaco-editor/react';
2
+ export declare const XML: {
3
+ register: (monaco: Monaco) => void;
4
+ };
5
+ //# sourceMappingURL=xml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml.d.ts","sourceRoot":"","sources":["../../../../../src/components/code-editor/languages/xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AA0C5C,eAAO,MAAM,GAAG;uBAXU,MAAM,KAAG,IAAI;CAWV,CAAC"}
@@ -8,9 +8,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
8
  import { CheckSize16Px, CopySize16Px } from "@coveord/plasma-react-icons";
9
9
  import { ActionIcon, Box, Center, CopyButton, createStyles, Group, Input, Loader, Space, Stack, Tooltip, useComponentDefaultProps } from "@mantine/core";
10
10
  import { useUncontrolled } from "@mantine/hooks";
11
- import Editor, { loader } from "@monaco-editor/react";
11
+ import Editor, { loader, useMonaco } from "@monaco-editor/react";
12
12
  import { useEffect, useState } from "react";
13
13
  import { useParentHeight } from "../../hooks";
14
+ import { XML } from "./languages/xml";
14
15
  var useStyles = createStyles(function(theme) {
15
16
  return {
16
17
  root: {},
@@ -48,6 +49,8 @@ export var CodeEditor = function(props) {
48
49
  "monacoLoader"
49
50
  ]);
50
51
  var _useState = _sliced_to_array(useState(false), 2), loaded = _useState[0], setLoaded = _useState[1];
52
+ var _useState1 = _sliced_to_array(useState(false), 2), registered = _useState1[0], setRegistered = _useState1[1];
53
+ var monaco = useMonaco();
51
54
  var _useStyles = useStyles(), classes = _useStyles.classes, theme = _useStyles.theme;
52
55
  var _useUncontrolled = _sliced_to_array(useUncontrolled({
53
56
  value: value,
@@ -58,7 +61,7 @@ export var CodeEditor = function(props) {
58
61
  var _useParentHeight = _sliced_to_array(useParentHeight(), 2), parentHeight = _useParentHeight[0], ref = _useParentHeight[1];
59
62
  var loadLocalMonaco = function() {
60
63
  var _ref = _async_to_generator(function() {
61
- var monaco;
64
+ var monacoInstance;
62
65
  return _ts_generator(this, function(_state) {
63
66
  switch(_state.label){
64
67
  case 0:
@@ -67,9 +70,9 @@ export var CodeEditor = function(props) {
67
70
  import("monaco-editor")
68
71
  ];
69
72
  case 1:
70
- monaco = _state.sent();
73
+ monacoInstance = _state.sent();
71
74
  loader.config({
72
- monaco: monaco
75
+ monaco: monacoInstance
73
76
  });
74
77
  setLoaded(true);
75
78
  return [
@@ -89,6 +92,15 @@ export var CodeEditor = function(props) {
89
92
  setLoaded(true);
90
93
  }
91
94
  }, []);
95
+ useEffect(function() {
96
+ if (monaco && language === "xml" && !registered) {
97
+ XML.register(monaco);
98
+ setRegistered(true);
99
+ }
100
+ }, [
101
+ monaco,
102
+ language
103
+ ]);
92
104
  var _label = label ? /*#__PURE__*/ _jsx(Input.Label, _object_spread_props(_object_spread({
93
105
  required: required
94
106
  }, labelProps), {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';\nimport {\n ActionIcon,\n Box,\n Center,\n CopyButton,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n Selectors,\n Space,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {loader} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useState} from 'react';\n\nimport {useParentHeight} from '../../hooks';\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';\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 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 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\n const loadLocalMonaco = async () => {\n const monaco = await import('monaco-editor');\n loader.config({monaco});\n setLoaded(true);\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 mt=\"xs\" {...descriptionProps}>\n {description}\n </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 _copyButton = (\n <Group position=\"right\">\n <CopyButton value={_value} timeout={2000}>\n {({copied, copy}) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position=\"right\">\n <ActionIcon color={copied ? 'lime' : 'gray'} onClick={copy}>\n {copied ? <CheckSize16Px height={16} /> : <CopySize16Px height={16} />}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\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 wrappingStrategy: 'advanced',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: theme.fontSizes.xs,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor) => {\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 {_copyButton}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CheckSize16Px","CopySize16Px","ActionIcon","Box","Center","CopyButton","createStyles","Group","Input","Loader","Space","Stack","Tooltip","useComponentDefaultProps","useUncontrolled","Editor","loader","useEffect","useState","useParentHeight","useStyles","theme","root","editor","border","colors","gray","borderRadius","defaultRadius","backgroundColor","colorScheme","white","black","height","defaultProps","language","monacoLoader","defaultValue","minHeight","CodeEditor","props","onChange","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","loaded","setLoaded","classes","finalValue","_value","handleChange","parentHeight","ref","loadLocalMonaco","monaco","config","_label","Label","_description","Description","mt","_error","Error","h","_header","_copyButton","position","timeout","copied","copy","withArrow","color","onClick","_editor","p","pl","className","defaultLanguage","options","minimap","enabled","wordWrap","wrappingStrategy","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","justify","spacing","sx","Math","max"],"mappings":"AAAA;;;;;;;AAAA,SAAQA,aAAa,EAAEC,YAAY,QAAO,8BAA8B;AACxE,SACIC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,YAAY,EAEZC,KAAK,EACLC,KAAK,EAELC,MAAM,EAENC,KAAK,EACLC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,gBAAgB;AACvB,SAAQC,eAAe,QAAO,iBAAiB;AAC/C,OAAOC,UAASC,MAAM,QAAO,uBAAuB;AACpD,SAA2BC,SAAS,EAAEC,QAAQ,QAAO,QAAQ;AAE7D,SAAQC,eAAe,QAAO,cAAc;AAE5C,IAAMC,YAAYd,aAAa,SAACe;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;;AA6CA,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEA,OAAO,IAAMC,aAAiD,SAACC,OAAU;IACrE,IAkBI3B,4BAAAA,yBAAyB,cAAcqB,cAAcM,QAjBrDL,WAiBAtB,0BAjBAsB,UACAE,eAgBAxB,0BAhBAwB,cACAI,WAeA5B,0BAfA4B,UACAC,UAcA7B,0BAdA6B,SACAC,QAaA9B,0BAbA8B,OACAC,QAYA/B,0BAZA+B,OACAC,WAWAhC,0BAXAgC,UACAC,aAUAjC,0BAVAiC,YACAC,QASAlC,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AAG,CAAChD,cAActB;YAAYa,WAAAA;QAAS;QACzDU,KAAKA;OACDR;;YAEHoB;YACAC;YACAQ;YACAZ;;;AAGb,EAAE"}
1
+ {"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';\nimport {\n ActionIcon,\n Box,\n Center,\n CopyButton,\n createStyles,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n Loader,\n Selectors,\n Space,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {loader, useMonaco} from '@monaco-editor/react';\nimport {FunctionComponent, useEffect, useState} from 'react';\n\nimport {useParentHeight} from '../../hooks';\nimport {XML} from './languages/xml';\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 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 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 [registered, setRegistered] = useState(false);\n const monaco = useMonaco();\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\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n useEffect(() => {\n if (monaco && language === 'xml' && !registered) {\n XML.register(monaco);\n setRegistered(true);\n }\n }, [monaco, language]);\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 mt=\"xs\" {...descriptionProps}>\n {description}\n </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 _copyButton = (\n <Group position=\"right\">\n <CopyButton value={_value} timeout={2000}>\n {({copied, copy}) => (\n <Tooltip label={copied ? 'Copied' : 'Copy'} withArrow position=\"right\">\n <ActionIcon color={copied ? 'lime' : 'gray'} onClick={copy}>\n {copied ? <CheckSize16Px height={16} /> : <CopySize16Px height={16} />}\n </ActionIcon>\n </Tooltip>\n )}\n </CopyButton>\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 wrappingStrategy: 'advanced',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: theme.fontSizes.xs,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor) => {\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 {_copyButton}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CheckSize16Px","CopySize16Px","ActionIcon","Box","Center","CopyButton","createStyles","Group","Input","Loader","Space","Stack","Tooltip","useComponentDefaultProps","useUncontrolled","Editor","loader","useMonaco","useEffect","useState","useParentHeight","XML","useStyles","theme","root","editor","border","colors","gray","borderRadius","defaultRadius","backgroundColor","colorScheme","white","black","height","defaultProps","language","monacoLoader","defaultValue","minHeight","CodeEditor","props","onChange","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","loaded","setLoaded","registered","setRegistered","monaco","classes","finalValue","_value","handleChange","parentHeight","ref","loadLocalMonaco","monacoInstance","config","register","_label","Label","_description","Description","mt","_error","Error","h","_header","_copyButton","position","timeout","copied","copy","withArrow","color","onClick","_editor","p","pl","className","defaultLanguage","options","minimap","enabled","wordWrap","wrappingStrategy","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","justify","spacing","sx","Math","max"],"mappings":"AAAA;;;;;;;AAAA,SAAQA,aAAa,EAAEC,YAAY,QAAO,8BAA8B;AACxE,SACIC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,YAAY,EAEZC,KAAK,EACLC,KAAK,EAELC,MAAM,EAENC,KAAK,EACLC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,gBAAgB;AACvB,SAAQC,eAAe,QAAO,iBAAiB;AAC/C,OAAOC,UAASC,MAAM,EAAEC,SAAS,QAAO,uBAAuB;AAC/D,SAA2BC,SAAS,EAAEC,QAAQ,QAAO,QAAQ;AAE7D,SAAQC,eAAe,QAAO,cAAc;AAC5C,SAAQC,GAAG,QAAO,kBAAkB;AAEpC,IAAMC,YAAYhB,aAAa,SAACiB;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;;AA6CA,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEA,OAAO,IAAMC,aAAiD,SAACC,OAAU;IACrE,IAkBI7B,4BAAAA,yBAAyB,cAAcuB,cAAcM,QAjBrDL,WAiBAxB,0BAjBAwB,UACAE,eAgBA1B,0BAhBA0B,cACAI,WAeA9B,0BAfA8B,UACAC,UAcA/B,0BAdA+B,SACAC,QAaAhC,0BAbAgC,OACAC,QAYAjC,0BAZAiC,OACAC,WAWAlC,0BAXAkC,UACAC,aAUAnC,0BAVAmC,YACAC,QASAp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Y;;;;gCACnC;;oCAAMlF,OAAOmF,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,KAACzG;QAAOuF,WAAW9B,QAAQpC,MAAM;kBAC7B,cAAA,KAAChB;MAER;IAED,qBACI,MAACE;QACGmG,SAAQ;QACRnB,WAAW9B,QAAQrC,IAAI;QACvBuF,SAAS;QACTC,IAAI;YAAC7E,QAAQ8E,KAAKC,GAAG,CAACjD,cAAczB;YAAYa,WAAAA;QAAS;QACzDa,KAAKA;OACDX;;YAEHwB;YACAC;YACAQ;YACAZ;;;AAGb,EAAE"}
@@ -8,5 +8,8 @@ export default MockedEditor;
8
8
  export var loader = {
9
9
  config: jest.fn()
10
10
  };
11
+ export var useMonaco = function() {
12
+ return jest.fn();
13
+ };
11
14
 
12
15
  //# sourceMappingURL=react.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"sourcesContent":["import {type EditorProps} from '@monaco-editor/react';\nimport {FunctionComponent} from 'react';\n\nconst MockedEditor: FunctionComponent<EditorProps> = (props) => <div data-testid=\"monaco-editor\" />;\n\nexport default MockedEditor;\n\nexport const loader = {\n config: jest.fn(),\n};\n"],"names":["MockedEditor","props","div","data-testid","loader","config","jest","fn"],"mappings":"AAAA;AAGA,IAAMA,eAA+C,SAACC;yBAAU,KAACC;QAAIC,eAAY;;;AAEjF,eAAeH,aAAa;AAE5B,OAAO,IAAMI,SAAS;IAClBC,QAAQC,KAAKC,EAAE;AACnB,EAAE"}
1
+ {"version":3,"sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"sourcesContent":["import {EditorProps} from '@monaco-editor/react';\nimport {FunctionComponent} from 'react';\n\nconst MockedEditor: FunctionComponent<EditorProps> = (props) => <div data-testid=\"monaco-editor\" />;\n\nexport default MockedEditor;\n\nexport const loader = {\n config: jest.fn(),\n};\n\nexport const useMonaco = () => jest.fn();\n"],"names":["MockedEditor","props","div","data-testid","loader","config","jest","fn","useMonaco"],"mappings":"AAAA;AAGA,IAAMA,eAA+C,SAACC;yBAAU,KAACC;QAAIC,eAAY;;;AAEjF,eAAeH,aAAa;AAE5B,OAAO,IAAMI,SAAS;IAClBC,QAAQC,KAAKC,EAAE;AACnB,EAAE;AAEF,OAAO,IAAMC,YAAY;WAAMF,KAAKC,EAAE;EAAG"}
@@ -0,0 +1,50 @@
1
+ import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
2
+ import _ts_generator from "@swc/helpers/src/_ts_generator.mjs";
3
+ var format = function(xml) {
4
+ // https://stackoverflow.com/questions/57039218/doesnt-monaco-editor-support-xml-language-by-default
5
+ var PADDING = " ".repeat(2);
6
+ var reg = /(>)(<)(\/*)/g;
7
+ var pad = 0;
8
+ xml = xml.replace(reg, "$1\r\n$2$3");
9
+ return xml.split("\r\n").map(function(node) {
10
+ var indent = 0;
11
+ if (node.match(/.+<\/\w[^>]*>$/)) {
12
+ indent = 0;
13
+ } else if (node.match(/^<\/\w/) && pad > 0) {
14
+ pad -= 1;
15
+ } else if (node.match(/^<\w[^>]*[^/]>.*$/)) {
16
+ indent = 1;
17
+ } else {
18
+ indent = 0;
19
+ }
20
+ pad += indent;
21
+ return PADDING.repeat(pad - indent) + node;
22
+ }).join("\r\n");
23
+ };
24
+ var register = function(monaco) {
25
+ monaco.languages.registerDocumentFormattingEditProvider("xml", {
26
+ provideDocumentFormattingEdits: function() {
27
+ var _ref = _async_to_generator(function(model) {
28
+ return _ts_generator(this, function(_state) {
29
+ return [
30
+ 2,
31
+ [
32
+ {
33
+ range: model.getFullModelRange(),
34
+ text: format(model.getValue())
35
+ }
36
+ ]
37
+ ];
38
+ });
39
+ });
40
+ return function(model) {
41
+ return _ref.apply(this, arguments);
42
+ };
43
+ }()
44
+ });
45
+ };
46
+ export var XML = {
47
+ register: register
48
+ };
49
+
50
+ //# sourceMappingURL=xml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/components/code-editor/languages/xml.ts"],"sourcesContent":["import {Monaco} from '@monaco-editor/react';\n\nconst format = (xml: string): string => {\n // https://stackoverflow.com/questions/57039218/doesnt-monaco-editor-support-xml-language-by-default\n const PADDING = ' '.repeat(2);\n const reg = /(>)(<)(\\/*)/g;\n let pad = 0;\n\n xml = xml.replace(reg, '$1\\r\\n$2$3');\n\n return xml\n .split('\\r\\n')\n .map((node) => {\n let indent = 0;\n if (node.match(/.+<\\/\\w[^>]*>$/)) {\n indent = 0;\n } else if (node.match(/^<\\/\\w/) && pad > 0) {\n pad -= 1;\n } else if (node.match(/^<\\w[^>]*[^/]>.*$/)) {\n indent = 1;\n } else {\n indent = 0;\n }\n\n pad += indent;\n\n return PADDING.repeat(pad - indent) + node;\n })\n .join('\\r\\n');\n};\n\nconst register = (monaco: Monaco): void => {\n monaco.languages.registerDocumentFormattingEditProvider('xml', {\n provideDocumentFormattingEdits: async (model) => [\n {\n range: model.getFullModelRange(),\n text: format(model.getValue()),\n },\n ],\n });\n};\n\nexport const XML = {register};\n"],"names":["format","xml","PADDING","repeat","reg","pad","replace","split","map","node","indent","match","join","register","monaco","languages","registerDocumentFormattingEditProvider","provideDocumentFormattingEdits","model","range","getFullModelRange","text","getValue","XML"],"mappings":"AAAA;;AAEA,IAAMA,SAAS,SAACC,KAAwB;IACpC,oGAAoG;IACpG,IAAMC,UAAU,IAAIC,MAAM,CAAC;IAC3B,IAAMC,MAAM;IACZ,IAAIC,MAAM;IAEVJ,MAAMA,IAAIK,OAAO,CAACF,KAAK;IAEvB,OAAOH,IACFM,KAAK,CAAC,QACNC,GAAG,CAAC,SAACC,MAAS;QACX,IAAIC,SAAS;QACb,IAAID,KAAKE,KAAK,CAAC,mBAAmB;YAC9BD,SAAS;QACb,OAAO,IAAID,KAAKE,KAAK,CAAC,aAAaN,MAAM,GAAG;YACxCA,OAAO;QACX,OAAO,IAAII,KAAKE,KAAK,CAAC,sBAAsB;YACxCD,SAAS;QACb,OAAO;YACHA,SAAS;QACb,CAAC;QAEDL,OAAOK;QAEP,OAAOR,QAAQC,MAAM,CAACE,MAAMK,UAAUD;IAC1C,GACCG,IAAI,CAAC;AACd;AAEA,IAAMC,WAAW,SAACC,QAAyB;IACvCA,OAAOC,SAAS,CAACC,sCAAsC,CAAC,OAAO;QAC3DC,8BAA8B;uBAAE,oBAAA,SAAOC;;oBAAU;;;4BAC7C;gCACIC,OAAOD,MAAME,iBAAiB;gCAC9BC,MAAMrB,OAAOkB,MAAMI,QAAQ;4BAC/B;;;;;4BAJmCJ;;;;IAM3C;AACJ;AAEA,OAAO,IAAMK,MAAM;IAACV,UAAAA;AAAQ,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveord/plasma-mantine",
3
- "version": "48.17.5",
3
+ "version": "48.18.0",
4
4
  "description": "A Plasma flavoured Mantine theme",
5
5
  "keywords": [
6
6
  "plasma",
@@ -17,10 +17,11 @@ import {
17
17
  useComponentDefaultProps,
18
18
  } from '@mantine/core';
19
19
  import {useUncontrolled} from '@mantine/hooks';
20
- import Editor, {loader} from '@monaco-editor/react';
20
+ import Editor, {loader, useMonaco} from '@monaco-editor/react';
21
21
  import {FunctionComponent, useEffect, useState} from 'react';
22
22
 
23
23
  import {useParentHeight} from '../../hooks';
24
+ import {XML} from './languages/xml';
24
25
 
25
26
  const useStyles = createStyles((theme) => ({
26
27
  root: {},
@@ -40,7 +41,7 @@ interface CodeEditorProps
40
41
  *
41
42
  * @default 'plaintext'
42
43
  */
43
- language?: 'plaintext' | 'json' | 'markdown' | 'python';
44
+ language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml';
44
45
  /** Default value for uncontrolled input */
45
46
  defaultValue?: string;
46
47
  /** Value for controlled input */
@@ -103,6 +104,8 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
103
104
  ...others
104
105
  } = useComponentDefaultProps('CodeEditor', defaultProps, props);
105
106
  const [loaded, setLoaded] = useState(false);
107
+ const [registered, setRegistered] = useState(false);
108
+ const monaco = useMonaco();
106
109
  const {classes, theme} = useStyles();
107
110
  const [_value, handleChange] = useUncontrolled<string>({
108
111
  value,
@@ -113,8 +116,8 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
113
116
  const [parentHeight, ref] = useParentHeight();
114
117
 
115
118
  const loadLocalMonaco = async () => {
116
- const monaco = await import('monaco-editor');
117
- loader.config({monaco});
119
+ const monacoInstance = await import('monaco-editor');
120
+ loader.config({monaco: monacoInstance});
118
121
  setLoaded(true);
119
122
  };
120
123
 
@@ -126,6 +129,13 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
126
129
  }
127
130
  }, []);
128
131
 
132
+ useEffect(() => {
133
+ if (monaco && language === 'xml' && !registered) {
134
+ XML.register(monaco);
135
+ setRegistered(true);
136
+ }
137
+ }, [monaco, language]);
138
+
129
139
  const _label = label ? (
130
140
  <Input.Label required={required} {...labelProps}>
131
141
  {label}
@@ -1,4 +1,4 @@
1
- import {type EditorProps} from '@monaco-editor/react';
1
+ import {EditorProps} from '@monaco-editor/react';
2
2
  import {FunctionComponent} from 'react';
3
3
 
4
4
  const MockedEditor: FunctionComponent<EditorProps> = (props) => <div data-testid="monaco-editor" />;
@@ -8,3 +8,5 @@ export default MockedEditor;
8
8
  export const loader = {
9
9
  config: jest.fn(),
10
10
  };
11
+
12
+ export const useMonaco = () => jest.fn();
@@ -3,6 +3,7 @@ import {loader} from '@monaco-editor/react';
3
3
  import {render, screen, waitForElementToBeRemoved, within} from '@test-utils';
4
4
 
5
5
  import {CodeEditor} from '../CodeEditor';
6
+ import {XML} from '../languages/xml';
6
7
 
7
8
  describe('CodeEditor', () => {
8
9
  beforeEach(() => {
@@ -53,4 +54,10 @@ describe('CodeEditor', () => {
53
54
  expect(loader.config).not.toHaveBeenCalled();
54
55
  expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
55
56
  });
57
+
58
+ it('loads the xml language in the monaco instance if the editor language is xml', () => {
59
+ const xmlLanguageSpy = jest.spyOn(XML, 'register').mockImplementation();
60
+ render(<CodeEditor label="label" description="description" monacoLoader="cdn" language="xml" />);
61
+ expect(xmlLanguageSpy).toHaveBeenCalledTimes(1);
62
+ });
56
63
  });
@@ -0,0 +1,43 @@
1
+ import {Monaco} from '@monaco-editor/react';
2
+
3
+ const format = (xml: string): string => {
4
+ // https://stackoverflow.com/questions/57039218/doesnt-monaco-editor-support-xml-language-by-default
5
+ const PADDING = ' '.repeat(2);
6
+ const reg = /(>)(<)(\/*)/g;
7
+ let pad = 0;
8
+
9
+ xml = xml.replace(reg, '$1\r\n$2$3');
10
+
11
+ return xml
12
+ .split('\r\n')
13
+ .map((node) => {
14
+ let indent = 0;
15
+ if (node.match(/.+<\/\w[^>]*>$/)) {
16
+ indent = 0;
17
+ } else if (node.match(/^<\/\w/) && pad > 0) {
18
+ pad -= 1;
19
+ } else if (node.match(/^<\w[^>]*[^/]>.*$/)) {
20
+ indent = 1;
21
+ } else {
22
+ indent = 0;
23
+ }
24
+
25
+ pad += indent;
26
+
27
+ return PADDING.repeat(pad - indent) + node;
28
+ })
29
+ .join('\r\n');
30
+ };
31
+
32
+ const register = (monaco: Monaco): void => {
33
+ monaco.languages.registerDocumentFormattingEditProvider('xml', {
34
+ provideDocumentFormattingEdits: async (model) => [
35
+ {
36
+ range: model.getFullModelRange(),
37
+ text: format(model.getValue()),
38
+ },
39
+ ],
40
+ });
41
+ };
42
+
43
+ export const XML = {register};