@coveord/plasma-mantine 48.17.5 → 48.18.1
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 +9 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.js +15 -3
- package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/cjs/components/code-editor/__mocks__/@monaco-editor/react.js +6 -0
- package/dist/cjs/components/code-editor/__mocks__/@monaco-editor/react.js.map +1 -1
- package/dist/cjs/components/code-editor/languages/xml.js +60 -0
- package/dist/cjs/components/code-editor/languages/xml.js.map +1 -0
- package/dist/cjs/components/collection/Collection.js +37 -7
- package/dist/cjs/components/collection/Collection.js.map +1 -1
- package/dist/cjs/components/collection/{Colllection.styles.js → Collection.styles.js} +1 -1
- package/dist/cjs/components/collection/Collection.styles.js.map +1 -0
- package/dist/cjs/components/collection/CollectionItem.js +4 -4
- package/dist/cjs/components/collection/CollectionItem.js.map +1 -1
- package/dist/definitions/components/code-editor/CodeEditor.d.ts +1 -1
- package/dist/definitions/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/definitions/components/code-editor/__mocks__/@monaco-editor/react.d.ts +2 -1
- package/dist/definitions/components/code-editor/__mocks__/@monaco-editor/react.d.ts.map +1 -1
- package/dist/definitions/components/code-editor/languages/xml.d.ts +5 -0
- package/dist/definitions/components/code-editor/languages/xml.d.ts.map +1 -0
- package/dist/definitions/components/collection/Collection.d.ts +3 -3
- package/dist/definitions/components/collection/Collection.d.ts.map +1 -1
- package/dist/definitions/components/collection/{Colllection.styles.d.ts → Collection.styles.d.ts} +1 -1
- package/dist/definitions/components/collection/Collection.styles.d.ts.map +1 -0
- package/dist/definitions/components/collection/CollectionItem.d.ts +1 -1
- package/dist/definitions/components/collection/CollectionItem.d.ts.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.js +16 -4
- package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/esm/components/code-editor/__mocks__/@monaco-editor/react.js +3 -0
- package/dist/esm/components/code-editor/__mocks__/@monaco-editor/react.js.map +1 -1
- package/dist/esm/components/code-editor/languages/xml.js +50 -0
- package/dist/esm/components/code-editor/languages/xml.js.map +1 -0
- package/dist/esm/components/collection/Collection.js +37 -7
- package/dist/esm/components/collection/Collection.js.map +1 -1
- package/dist/esm/components/collection/{Colllection.styles.js → Collection.styles.js} +1 -1
- package/dist/esm/components/collection/Collection.styles.js.map +1 -0
- package/dist/esm/components/collection/CollectionItem.js +1 -1
- package/dist/esm/components/collection/CollectionItem.js.map +1 -1
- package/package.json +1 -1
- package/src/components/code-editor/CodeEditor.tsx +14 -4
- package/src/components/code-editor/__mocks__/@monaco-editor/react.tsx +3 -1
- package/src/components/code-editor/__tests__/CodeEditor.spec.tsx +7 -0
- package/src/components/code-editor/languages/xml.ts +43 -0
- package/src/components/collection/{Colllection.styles.ts → Collection.styles.ts} +0 -0
- package/src/components/collection/Collection.tsx +38 -7
- package/src/components/collection/CollectionItem.tsx +1 -1
- package/dist/cjs/components/collection/Colllection.styles.js.map +0 -1
- package/dist/definitions/components/collection/Colllection.styles.d.ts.map +0 -1
- package/dist/esm/components/collection/Colllection.styles.js.map +0 -1
|
@@ -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,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,MAAM0E,SAAS,CAACC,EAAE;gBAC5BC,UAAU7C;gBACV8C,SAAS;YACb;YACAvD,OAAOe;YACPjB,UAAUkB;YACVwC,SAAS,SAAC5E,QAAW;gBACjBA,OAAO6E,oBAAoB,CAAC1D;gBAC5BnB,OAAO8E,mBAAmB,eAAC,oBAAA,WAAY;;;;gCACnC;;oCAAM9E,OAAO+E,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,KAACnG;QAAOiF,WAAW7B,QAAQjC,MAAM;kBAC7B,cAAA,KAACd;MAER;IAED,qBACI,MAACE;QACG6F,SAAQ;QACRnB,WAAW7B,QAAQlC,IAAI;QACvBmF,SAAS;QACTC,IAAI;YAACzE,QAAQ0E,KAAKC,GAAG,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,aA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AAE;QAAKC,IAAG;QAAKC,WAAW9B,QAAQpC,MAAM;kBACzC,cAAA,KAACV;YACG6E,iBAAiBvD;YACjBd,OAAOA,MAAMS,WAAW,KAAK,UAAU,UAAU,SAAS;YAC1D6D,SAAS;gBACLC,SAAS;oBAACC,SAAS,KAAK;gBAAA;gBACxBC,UAAU;gBACVC,kBAAkB;gBAClBC,sBAAsB,KAAK;gBAC3BC,eAAe,IAAI;gBACnBC,UAAU7E,MAAM8E,SAAS,CAACC,EAAE;gBAC5BC,UAAUjD;gBACVkD,SAAS;YACb;YACA3D,OAAOkB;YACPpB,UAAUqB;YACVyC,SAAS,SAAChF,QAAW;gBACjBA,OAAOiF,oBAAoB,CAAC9D;gBAC5BnB,OAAOkF,mBAAmB,eAAC,oBAAA,WAAY;;;;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/components/code-editor/__mocks__/@monaco-editor/react.tsx"],"sourcesContent":["import {
|
|
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"}
|
|
@@ -4,12 +4,12 @@ import _object_without_properties from "@swc/helpers/src/_object_without_propert
|
|
|
4
4
|
import _sliced_to_array from "@swc/helpers/src/_sliced_to_array.mjs";
|
|
5
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
import { AddSize16Px } from "@coveord/plasma-react-icons";
|
|
7
|
-
import { Box, Button, Group, Stack, Tooltip, useComponentDefaultProps } from "@mantine/core";
|
|
7
|
+
import { Box, Button, Group, Input, Stack, Tooltip, useComponentDefaultProps } from "@mantine/core";
|
|
8
8
|
import { useId } from "@mantine/hooks";
|
|
9
9
|
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
|
10
10
|
import { useControlledList } from "../../hooks";
|
|
11
11
|
import { CollectionItem } from "./CollectionItem";
|
|
12
|
-
import useStyles from "./
|
|
12
|
+
import useStyles from "./Collection.styles";
|
|
13
13
|
var defaultProps = {
|
|
14
14
|
draggable: false,
|
|
15
15
|
addLabel: "Add item",
|
|
@@ -19,7 +19,7 @@ var defaultProps = {
|
|
|
19
19
|
required: false
|
|
20
20
|
};
|
|
21
21
|
export var Collection = function(props) {
|
|
22
|
-
var _useComponentDefaultProps = useComponentDefaultProps("Collection", defaultProps, props), value = _useComponentDefaultProps.value, defaultValue = _useComponentDefaultProps.defaultValue, onChange = _useComponentDefaultProps.onChange, onRemoveItem = _useComponentDefaultProps.onRemoveItem, disabled = _useComponentDefaultProps.disabled, draggable = _useComponentDefaultProps.draggable, children = _useComponentDefaultProps.children, spacing = _useComponentDefaultProps.spacing, required = _useComponentDefaultProps.required, newItem = _useComponentDefaultProps.newItem, addLabel = _useComponentDefaultProps.addLabel, addDisabledTooltip = _useComponentDefaultProps.addDisabledTooltip, allowAdd = _useComponentDefaultProps.allowAdd, // Style props
|
|
22
|
+
var _useComponentDefaultProps = useComponentDefaultProps("Collection", defaultProps, props), value = _useComponentDefaultProps.value, defaultValue = _useComponentDefaultProps.defaultValue, onChange = _useComponentDefaultProps.onChange, onRemoveItem = _useComponentDefaultProps.onRemoveItem, disabled = _useComponentDefaultProps.disabled, draggable = _useComponentDefaultProps.draggable, children = _useComponentDefaultProps.children, spacing = _useComponentDefaultProps.spacing, required = _useComponentDefaultProps.required, newItem = _useComponentDefaultProps.newItem, addLabel = _useComponentDefaultProps.addLabel, addDisabledTooltip = _useComponentDefaultProps.addDisabledTooltip, allowAdd = _useComponentDefaultProps.allowAdd, label = _useComponentDefaultProps.label, labelProps = _useComponentDefaultProps.labelProps, description = _useComponentDefaultProps.description, descriptionProps = _useComponentDefaultProps.descriptionProps, error = _useComponentDefaultProps.error, errorProps = _useComponentDefaultProps.errorProps, // Style props
|
|
23
23
|
classNames = _useComponentDefaultProps.classNames, className = _useComponentDefaultProps.className, styles = _useComponentDefaultProps.styles, unstyled = _useComponentDefaultProps.unstyled, others = _object_without_properties(_useComponentDefaultProps, [
|
|
24
24
|
"value",
|
|
25
25
|
"defaultValue",
|
|
@@ -34,6 +34,12 @@ export var Collection = function(props) {
|
|
|
34
34
|
"addLabel",
|
|
35
35
|
"addDisabledTooltip",
|
|
36
36
|
"allowAdd",
|
|
37
|
+
"label",
|
|
38
|
+
"labelProps",
|
|
39
|
+
"description",
|
|
40
|
+
"descriptionProps",
|
|
41
|
+
"error",
|
|
42
|
+
"errorProps",
|
|
37
43
|
"classNames",
|
|
38
44
|
"className",
|
|
39
45
|
"styles",
|
|
@@ -58,6 +64,24 @@ export var Collection = function(props) {
|
|
|
58
64
|
onRemoveItem === null || onRemoveItem === void 0 ? void 0 : onRemoveItem(index);
|
|
59
65
|
};
|
|
60
66
|
};
|
|
67
|
+
var _label = label ? /*#__PURE__*/ _jsx(Input.Label, _object_spread_props(_object_spread({
|
|
68
|
+
required: required
|
|
69
|
+
}, labelProps), {
|
|
70
|
+
children: label
|
|
71
|
+
})) : null;
|
|
72
|
+
var _description = description ? /*#__PURE__*/ _jsx(Input.Description, _object_spread_props(_object_spread({}, descriptionProps), {
|
|
73
|
+
children: description
|
|
74
|
+
})) : null;
|
|
75
|
+
var _error = error ? /*#__PURE__*/ _jsx(Input.Error, _object_spread_props(_object_spread({}, errorProps), {
|
|
76
|
+
children: error
|
|
77
|
+
})) : null;
|
|
78
|
+
var _header = _label || _description ? /*#__PURE__*/ _jsxs(Stack, {
|
|
79
|
+
spacing: "xs",
|
|
80
|
+
children: [
|
|
81
|
+
_label,
|
|
82
|
+
_description
|
|
83
|
+
]
|
|
84
|
+
}) : null;
|
|
61
85
|
var items = values.map(function(item, index) {
|
|
62
86
|
return /*#__PURE__*/ _jsx(CollectionItem, {
|
|
63
87
|
disabled: disabled,
|
|
@@ -107,11 +131,17 @@ export var Collection = function(props) {
|
|
|
107
131
|
className: cx(classes.root, className)
|
|
108
132
|
}), others), {
|
|
109
133
|
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
110
|
-
spacing: spacing,
|
|
111
134
|
children: [
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
135
|
+
_header,
|
|
136
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
137
|
+
spacing: spacing,
|
|
138
|
+
children: [
|
|
139
|
+
items,
|
|
140
|
+
provided.placeholder,
|
|
141
|
+
_addButton,
|
|
142
|
+
_error
|
|
143
|
+
]
|
|
144
|
+
})
|
|
115
145
|
]
|
|
116
146
|
})
|
|
117
147
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {\n Box,\n Button,\n DefaultProps,\n Group,\n MantineNumberSize,\n Selectors,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useId} from '@mantine/hooks';\nimport {ReactNode} from 'react';\nimport {DragDropContext, Droppable} from 'react-beautiful-dnd';\n\nimport {useControlledList} from '../../hooks';\nimport {CollectionItem} from './CollectionItem';\nimport useStyles from './Colllection.styles';\n\ninterface CollectionProps<T> extends DefaultProps<Selectors<typeof useStyles>> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * The initial items of the collection (for uncontrolled usage only)\n */\n defaultValue?: T[];\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The spacing between the colleciton items\n *\n * @default 'xs'\n */\n spacing?: MantineNumberSize;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n spacing: 'xs',\n required: false,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T>) => {\n const {\n value,\n defaultValue,\n onChange,\n onRemoveItem,\n disabled,\n draggable,\n children,\n spacing,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n\n // Style props\n classNames,\n className,\n styles,\n unstyled,\n\n ...others\n } = useComponentDefaultProps('Collection', defaultProps as CollectionProps<T>, props);\n const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});\n const collectionID = useId('dnd-droppable');\n\n const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});\n const hasOnlyOneItem = values.length === 1;\n const removeItem = (index: number) => () => {\n remove(index);\n onRemoveItem?.(index);\n };\n\n const items = values.map((item, index) => (\n <CollectionItem\n key={index}\n disabled={disabled}\n draggable={draggable}\n index={index}\n onRemove={removeItem(index)}\n styles={styles}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(values) ?? true;\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftIcon={<AddSize16Px height={16} />}\n onClick={() => append(newItem)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n return (\n <DragDropContext\n onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}\n >\n <Droppable direction=\"vertical\" droppableId={collectionID}>\n {(provided) => (\n <Box\n {...provided.droppableProps}\n ref={provided.innerRef}\n className={cx(classes.root, className)}\n {...others}\n >\n <Stack spacing={spacing}>\n {items}\n {provided.placeholder}\n {_addButton}\n </Stack>\n </Box>\n )}\n </Droppable>\n </DragDropContext>\n );\n};\n"],"names":["AddSize16Px","Box","Button","Group","Stack","Tooltip","useComponentDefaultProps","useId","DragDropContext","Droppable","useControlledList","CollectionItem","useStyles","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","Collection","props","value","defaultValue","onChange","onRemoveItem","children","newItem","allowAdd","classNames","className","styles","unstyled","others","name","classes","cx","collectionID","values","append","remove","reorder","hasOnlyOneItem","length","removeItem","index","items","map","item","onRemove","removable","addAllowed","_addButton","label","variant","leftIcon","height","onClick","onDragEnd","destination","source","from","to","direction","droppableId","provided","droppableProps","ref","innerRef","root","placeholder"],"mappings":"AAAA;;;;;AAAA,SAAQA,WAAW,QAAO,8BAA8B;AACxD,SACIC,GAAG,EACHC,MAAM,EAENC,KAAK,EAGLC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,gBAAgB;AACvB,SAAQC,KAAK,QAAO,iBAAiB;AAErC,SAAQC,eAAe,EAAEC,SAAS,QAAO,sBAAsB;AAE/D,SAAQC,iBAAiB,QAAO,cAAc;AAC9C,SAAQC,cAAc,QAAO,mBAAmB;AAChD,OAAOC,eAAe,uBAAuB;AAqF7C,IAAMC,eAAkD;IACpDC,WAAW,KAAK;IAChBC,UAAU;IACVC,oBAAoB;IACpBC,UAAU,KAAK;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AEGM,UAAUA;YACVH,WAAWA;YACX+B,OAAOA;YACPI,UAAUL,WAAWC;YACrBd,QAAQA;YACRmB,WAAW,CAAE/B,CAAAA,YAAYuB,cAAa;sBAErChB,SAASsB,MAAMH;WARXA;;QAYMjB;IAAnB,IAAMuB,aAAavB,CAAAA,OAAAA,qBAAAA,sBAAAA,KAAAA,IAAAA,SAAWU,qBAAXV,kBAAAA,OAAsB,IAAI;IAE7C,IAAMwB,aAAanC,WAAW,IAAI,iBAC9B,KAACd;kBACG,cAAA,KAACE;YAAQgD,OAAOrC;YAAoBC,UAAUkC;sBAC1C,cAAA,KAAClD;0BACG,cAAA,KAACC;oBACGoD,SAAQ;oBACRC,wBAAU,KAACvD;wBAAYwD,QAAQ;;oBAC/BC,SAAS;+BAAMlB,OAAOZ;;oBACtBV,UAAU,CAACkC;8BAEVpC;;;;MAKpB;IAED,qBACI,KAACP;QACGkD,WAAW;gBAAEC,oBAAAA,aAAaC,eAAAA;YAAYnB,OAAAA,QAAQ;gBAACoB,MAAMD,OAAOf,KAAK;gBAAEiB,IAAIH,CAAAA,wBAAAA,yBAAAA,KAAAA,IAAAA,YAAad,KAAK,AAAD,KAAK;YAAC;;kBAE9F,cAAA,KAACpC;YAAUsD,WAAU;YAAWC,aAAa3B;sBACxC,SAAC4B;qCACE,KAAChE,iFACOgE,SAASC,cAAc;oBAC3BC,KAAKF,SAASG,QAAQ;oBACtBtC,WAAWM,GAAGD,QAAQkC,IAAI,EAAEvC;oBACxBG;8BAEJ,cAAA,MAAC7B;wBAAMc,SAASA;;4BACX4B;4BACAmB,SAASK,WAAW;4BACpBlB;;;;;;;AAO7B,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {\n Box,\n Button,\n DefaultProps,\n Group,\n Input,\n InputWrapperBaseProps,\n MantineNumberSize,\n Selectors,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useId} from '@mantine/hooks';\nimport {ReactNode} from 'react';\nimport {DragDropContext, Droppable} from 'react-beautiful-dnd';\nimport {useControlledList} from '../../hooks';\nimport {CollectionItem} from './CollectionItem';\nimport useStyles from './Collection.styles';\n\ninterface CollectionProps<T>\n extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,\n DefaultProps<Selectors<typeof useStyles>> {\n /**\n * The default value each new item should have\n */\n newItem: T;\n /**\n * A render function called for each item passed in the `value` prop.\n *\n * @param item The current item's value\n * @param index The current item's index\n */\n children: (item: T, index: number) => ReactNode;\n /**\n * The list of items to display inside the collection\n *\n * @default []\n */\n value?: T[];\n /**\n * The initial items of the collection (for uncontrolled usage only)\n */\n defaultValue?: T[];\n /**\n * Unused, has no effect\n */\n onFocus?: () => void;\n /**\n * Function called whenever the value needs to be updated\n *\n * @param value The whole list of items after the change\n */\n onChange?: (value: T[]) => void;\n /**\n * Function called after an item is removed from the collection using the remove button\n *\n * @param itemIndex The index of the item that was removed\n */\n onRemoveItem?: (itemIndex: number) => void;\n /**\n * Whether the collection should have drag and drop behavior enabled\n *\n * @default false\n */\n draggable?: boolean;\n /**\n * Whether the collection is disabled, or in other words in read only mode\n *\n * @default false\n */\n disabled?: boolean;\n /**\n * Function that determines if the add item button should be enabled given the current items of the collection.\n * The button is always enabled if this props remains undefined\n *\n * @param values The current items of the collection\n */\n allowAdd?: (values: T[]) => boolean;\n /**\n * The label of the add item button\n *\n * @default \"Add item\"\n */\n addLabel?: string;\n /**\n * The tooltip text displayed when hovering over the disabled add item button\n *\n * @default 'There is already an empty item'\n */\n addDisabledTooltip?: string;\n /**\n * The spacing between the colleciton items\n *\n * @default 'xs'\n */\n spacing?: MantineNumberSize;\n /**\n * Whether the collection is required. When required is true, the collection will hide the remove button if there is only one item\n *\n * @default false\n */\n required?: boolean;\n}\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n spacing: 'xs',\n required: false,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T>) => {\n const {\n value,\n defaultValue,\n onChange,\n onRemoveItem,\n disabled,\n draggable,\n children,\n spacing,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n label,\n labelProps,\n description,\n descriptionProps,\n error,\n errorProps,\n\n // Style props\n classNames,\n className,\n styles,\n unstyled,\n\n ...others\n } = useComponentDefaultProps('Collection', defaultProps as CollectionProps<T>, props);\n const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});\n const collectionID = useId('dnd-droppable');\n\n const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});\n const hasOnlyOneItem = values.length === 1;\n const removeItem = (index: number) => () => {\n remove(index);\n onRemoveItem?.(index);\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 const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;\n const _header =\n _label || _description ? (\n <Stack spacing=\"xs\">\n {_label}\n {_description}\n </Stack>\n ) : null;\n\n const items = values.map((item, index) => (\n <CollectionItem\n key={index}\n disabled={disabled}\n draggable={draggable}\n index={index}\n onRemove={removeItem(index)}\n styles={styles}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(values) ?? true;\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftIcon={<AddSize16Px height={16} />}\n onClick={() => append(newItem)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n return (\n <DragDropContext\n onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}\n >\n <Droppable direction=\"vertical\" droppableId={collectionID}>\n {(provided) => (\n <Box\n {...provided.droppableProps}\n ref={provided.innerRef}\n className={cx(classes.root, className)}\n {...others}\n >\n <Stack>\n {_header}\n <Stack spacing={spacing}>\n {items}\n {provided.placeholder}\n {_addButton}\n {_error}\n </Stack>\n </Stack>\n </Box>\n )}\n </Droppable>\n </DragDropContext>\n );\n};\n"],"names":["AddSize16Px","Box","Button","Group","Input","Stack","Tooltip","useComponentDefaultProps","useId","DragDropContext","Droppable","useControlledList","CollectionItem","useStyles","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","Collection","props","value","defaultValue","onChange","onRemoveItem","children","newItem","allowAdd","label","labelProps","description","descriptionProps","error","errorProps","classNames","className","styles","unstyled","others","name","classes","cx","collectionID","values","append","remove","reorder","hasOnlyOneItem","length","removeItem","index","_label","Label","_description","Description","_error","Error","_header","items","map","item","onRemove","removable","addAllowed","_addButton","variant","leftIcon","height","onClick","onDragEnd","destination","source","from","to","direction","droppableId","provided","droppableProps","ref","innerRef","root","placeholder"],"mappings":"AAAA;;;;;AAAA,SAAQA,WAAW,QAAO,8BAA8B;AACxD,SACIC,GAAG,EACHC,MAAM,EAENC,KAAK,EACLC,KAAK,EAILC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,gBAAgB;AACvB,SAAQC,KAAK,QAAO,iBAAiB;AAErC,SAAQC,eAAe,EAAEC,SAAS,QAAO,sBAAsB;AAC/D,SAAQC,iBAAiB,QAAO,cAAc;AAC9C,SAAQC,cAAc,QAAO,mBAAmB;AAChD,OAAOC,eAAe,sBAAsB;AAuF5C,IAAMC,eAAkD;IACpDC,WAAW,KAAK;IAChBC,UAAU;IACVC,oBAAoB;IACpBC,UAAU,KAAK;IACfC,SAAS;IACTC,UAAU,KAAK;AACnB;AAEA,OAAO,IAAMC,aAAa,SAAKC,OAA8B;IACzD,IA4BIf,4BAAAA,yBAAyB,cAAcO,cAAoCQ,QA3B3EC,QA2BAhB,0BA3BAgB,OACAC,eA0BAjB,0BA1BAiB,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QAAQ;oBACtB5C,WAAWM,GAAGD,QAAQwC,IAAI,EAAE7C;oBACxBG;8BAEJ,cAAA,MAACnC;;4BACIsD;0CACD,MAACtD;gCAAMc,SAASA;;oCACXyC;oCACAkB,SAASK,WAAW;oCACpBjB;oCACAT;;;;;;;;;AAQjC,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/collection/Collection.styles.ts"],"sourcesContent":["import {createStyles} from '@mantine/core';\n\nexport interface CollectionStylesParams {}\n\nexport default createStyles((theme) => ({\n root: {},\n item: {\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n alignItems: 'baseline',\n },\n itemDragging: {\n boxShadow: theme.shadows.sm,\n },\n}));\n"],"names":["createStyles","theme","root","item","backgroundColor","colorScheme","white","black","alignItems","itemDragging","boxShadow","shadows","sm"],"mappings":"AAAA,SAAQA,YAAY,QAAO,gBAAgB;AAI3C,eAAeA,aAAa,SAACC;WAAW;QACpCC,MAAM,CAAC;QACPC,MAAM;YACFC,iBAAiBH,MAAMI,WAAW,KAAK,UAAUJ,MAAMK,KAAK,GAAGL,MAAMM,KAAK;YAC1EC,YAAY;QAChB;QACAC,cAAc;YACVC,WAAWT,MAAMU,OAAO,CAACC,EAAE;QAC/B;IACJ;GAAI"}
|
|
@@ -6,7 +6,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
import { DragAndDropSize16Px, RemoveSize16Px } from "@coveord/plasma-react-icons";
|
|
7
7
|
import { ActionIcon, Group } from "@mantine/core";
|
|
8
8
|
import { Draggable } from "react-beautiful-dnd";
|
|
9
|
-
import useStyles from "./
|
|
9
|
+
import useStyles from "./Collection.styles";
|
|
10
10
|
var RemoveButton = function(param) {
|
|
11
11
|
var onClick = param.onClick;
|
|
12
12
|
return /*#__PURE__*/ _jsx(ActionIcon, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/CollectionItem.tsx"],"sourcesContent":["import {DragAndDropSize16Px, RemoveSize16Px} from '@coveord/plasma-react-icons';\nimport {ActionIcon, DefaultProps, Group, Selectors} from '@mantine/core';\nimport {FunctionComponent, PropsWithChildren} from 'react';\nimport {Draggable} from 'react-beautiful-dnd';\n\nimport useStyles from './
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/collection/CollectionItem.tsx"],"sourcesContent":["import {DragAndDropSize16Px, RemoveSize16Px} from '@coveord/plasma-react-icons';\nimport {ActionIcon, DefaultProps, Group, Selectors} from '@mantine/core';\nimport {FunctionComponent, PropsWithChildren} from 'react';\nimport {Draggable} from 'react-beautiful-dnd';\n\nimport useStyles from './Collection.styles';\n\ninterface CollectionItemProps extends CollectionItemSharedProps {\n draggable?: boolean;\n disabled: boolean;\n}\n\ninterface CollectionItemSharedProps extends DefaultProps<Selectors<typeof useStyles>> {\n index: number;\n onRemove?: React.MouseEventHandler<HTMLButtonElement>;\n removable?: boolean;\n}\n\nconst RemoveButton: FunctionComponent<{\n onClick: React.MouseEventHandler<HTMLButtonElement>;\n}> = ({onClick}) => (\n <ActionIcon variant=\"subtle\" onClick={onClick} color=\"action\">\n <RemoveSize16Px height={16} />\n </ActionIcon>\n);\n\nconst RemoveButtonPlaceholder = () => <div style={{width: 28}} />;\n\nconst StaticCollectionItem: FunctionComponent<PropsWithChildren<CollectionItemSharedProps>> = ({\n onRemove,\n removable = true,\n styles,\n children,\n}) => {\n const {classes, cx} = useStyles(null, {name: 'Collection', styles});\n const removeButton = removable && onRemove ? <RemoveButton onClick={onRemove} /> : <RemoveButtonPlaceholder />;\n\n return (\n <Group className={cx(classes.item)}>\n {children}\n {removeButton}\n </Group>\n );\n};\n\nconst DisabledCollectionItem: FunctionComponent<PropsWithChildren<CollectionItemSharedProps>> = ({children}) => {\n const {classes, cx} = useStyles();\n return <Group className={cx(classes.item)}>{children}</Group>;\n};\n\nconst DraggableCollectionItem: FunctionComponent<PropsWithChildren<CollectionItemSharedProps>> = ({\n index,\n onRemove,\n removable = true,\n styles,\n children,\n}) => {\n const {classes, cx} = useStyles(null, {name: 'Collection', styles});\n const removeButton = removable && onRemove ? <RemoveButton onClick={onRemove} /> : null;\n\n return (\n <Draggable index={index} draggableId={index.toString()}>\n {(provided, {isDragging}) => (\n <Group\n ref={provided.innerRef}\n {...provided.draggableProps}\n className={cx(classes.item, {[classes.itemDragging]: isDragging})}\n >\n <div {...provided.dragHandleProps}>\n <DragAndDropSize16Px height={16} />\n </div>\n {children}\n {removeButton}\n </Group>\n )}\n </Draggable>\n );\n};\n\nexport const CollectionItem: FunctionComponent<PropsWithChildren<CollectionItemProps>> = ({\n draggable,\n disabled,\n ...otherProps\n}) => {\n if (disabled) {\n return <DisabledCollectionItem {...otherProps} />;\n }\n if (draggable) {\n return <DraggableCollectionItem {...otherProps} />;\n }\n return <StaticCollectionItem {...otherProps} />;\n};\n"],"names":["DragAndDropSize16Px","RemoveSize16Px","ActionIcon","Group","Draggable","useStyles","RemoveButton","onClick","variant","color","height","RemoveButtonPlaceholder","div","style","width","StaticCollectionItem","onRemove","removable","styles","children","name","classes","cx","removeButton","className","item","DisabledCollectionItem","DraggableCollectionItem","index","draggableId","toString","provided","isDragging","ref","innerRef","draggableProps","itemDragging","dragHandleProps","CollectionItem","draggable","disabled","otherProps"],"mappings":"AAAA;;;;;AAAA,SAAQA,mBAAmB,EAAEC,cAAc,QAAO,8BAA8B;AAChF,SAAQC,UAAU,EAAgBC,KAAK,QAAkB,gBAAgB;AAEzE,SAAQC,SAAS,QAAO,sBAAsB;AAE9C,OAAOC,eAAe,sBAAsB;AAa5C,IAAMC,eAED;QAAEC,gBAAAA;yBACH,KAACL;QAAWM,SAAQ;QAASD,SAASA;QAASE,OAAM;kBACjD,cAAA,KAACR;YAAeS,QAAQ;;;;AAIhC,IAAMC,0BAA0B;yBAAM,KAACC;QAAIC,OAAO;YAACC,OAAO;QAAE;;;AAE5D,IAAMC,uBAAwF,gBAKxF;QAJFC,iBAAAA,mCACAC,WA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;IAGA,IAAIA,UAAU;QACV,qBAAO,KAACd,2CAA2Be;IACvC,CAAC;IACD,IAAIF,WAAW;QACX,qBAAO,KAACZ,4CAA4Bc;IACxC,CAAC;IACD,qBAAO,KAAC1B,yCAAyB0B;AACrC,EAAE"}
|
package/package.json
CHANGED
|
@@ -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
|
|
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 {
|
|
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};
|
|
File without changes
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
Button,
|
|
5
5
|
DefaultProps,
|
|
6
6
|
Group,
|
|
7
|
+
Input,
|
|
8
|
+
InputWrapperBaseProps,
|
|
7
9
|
MantineNumberSize,
|
|
8
10
|
Selectors,
|
|
9
11
|
Stack,
|
|
@@ -13,12 +15,13 @@ import {
|
|
|
13
15
|
import {useId} from '@mantine/hooks';
|
|
14
16
|
import {ReactNode} from 'react';
|
|
15
17
|
import {DragDropContext, Droppable} from 'react-beautiful-dnd';
|
|
16
|
-
|
|
17
18
|
import {useControlledList} from '../../hooks';
|
|
18
19
|
import {CollectionItem} from './CollectionItem';
|
|
19
|
-
import useStyles from './
|
|
20
|
+
import useStyles from './Collection.styles';
|
|
20
21
|
|
|
21
|
-
interface CollectionProps<T>
|
|
22
|
+
interface CollectionProps<T>
|
|
23
|
+
extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,
|
|
24
|
+
DefaultProps<Selectors<typeof useStyles>> {
|
|
22
25
|
/**
|
|
23
26
|
* The default value each new item should have
|
|
24
27
|
*/
|
|
@@ -125,6 +128,12 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
|
|
|
125
128
|
addLabel,
|
|
126
129
|
addDisabledTooltip,
|
|
127
130
|
allowAdd,
|
|
131
|
+
label,
|
|
132
|
+
labelProps,
|
|
133
|
+
description,
|
|
134
|
+
descriptionProps,
|
|
135
|
+
error,
|
|
136
|
+
errorProps,
|
|
128
137
|
|
|
129
138
|
// Style props
|
|
130
139
|
classNames,
|
|
@@ -144,6 +153,24 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
|
|
|
144
153
|
onRemoveItem?.(index);
|
|
145
154
|
};
|
|
146
155
|
|
|
156
|
+
const _label = label ? (
|
|
157
|
+
<Input.Label required={required} {...labelProps}>
|
|
158
|
+
{label}
|
|
159
|
+
</Input.Label>
|
|
160
|
+
) : null;
|
|
161
|
+
|
|
162
|
+
const _description = description ? (
|
|
163
|
+
<Input.Description {...descriptionProps}>{description}</Input.Description>
|
|
164
|
+
) : null;
|
|
165
|
+
const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;
|
|
166
|
+
const _header =
|
|
167
|
+
_label || _description ? (
|
|
168
|
+
<Stack spacing="xs">
|
|
169
|
+
{_label}
|
|
170
|
+
{_description}
|
|
171
|
+
</Stack>
|
|
172
|
+
) : null;
|
|
173
|
+
|
|
147
174
|
const items = values.map((item, index) => (
|
|
148
175
|
<CollectionItem
|
|
149
176
|
key={index}
|
|
@@ -189,10 +216,14 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
|
|
|
189
216
|
className={cx(classes.root, className)}
|
|
190
217
|
{...others}
|
|
191
218
|
>
|
|
192
|
-
<Stack
|
|
193
|
-
{
|
|
194
|
-
{
|
|
195
|
-
|
|
219
|
+
<Stack>
|
|
220
|
+
{_header}
|
|
221
|
+
<Stack spacing={spacing}>
|
|
222
|
+
{items}
|
|
223
|
+
{provided.placeholder}
|
|
224
|
+
{_addButton}
|
|
225
|
+
{_error}
|
|
226
|
+
</Stack>
|
|
196
227
|
</Stack>
|
|
197
228
|
</Box>
|
|
198
229
|
)}
|
|
@@ -3,7 +3,7 @@ import {ActionIcon, DefaultProps, Group, Selectors} from '@mantine/core';
|
|
|
3
3
|
import {FunctionComponent, PropsWithChildren} from 'react';
|
|
4
4
|
import {Draggable} from 'react-beautiful-dnd';
|
|
5
5
|
|
|
6
|
-
import useStyles from './
|
|
6
|
+
import useStyles from './Collection.styles';
|
|
7
7
|
|
|
8
8
|
interface CollectionItemProps extends CollectionItemSharedProps {
|
|
9
9
|
draggable?: boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/Colllection.styles.ts"],"sourcesContent":["import {createStyles} from '@mantine/core';\n\nexport interface CollectionStylesParams {}\n\nexport default createStyles((theme) => ({\n root: {},\n item: {\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n alignItems: 'baseline',\n },\n itemDragging: {\n boxShadow: theme.shadows.sm,\n },\n}));\n"],"names":["createStyles","theme","root","item","backgroundColor","colorScheme","white","black","alignItems","itemDragging","boxShadow","shadows","sm"],"mappings":"AAAA;;;;+BAIA;;;eAAA;;;oBAJ2B;IAI3B,WAAeA,IAAAA,kBAAY,EAAC,SAACC;WAAW;QACpCC,MAAM,CAAC;QACPC,MAAM;YACFC,iBAAiBH,MAAMI,WAAW,KAAK,UAAUJ,MAAMK,KAAK,GAAGL,MAAMM,KAAK;YAC1EC,YAAY;QAChB;QACAC,cAAc;YACVC,WAAWT,MAAMU,OAAO,CAACC,EAAE;QAC/B;IACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Colllection.styles.d.ts","sourceRoot":"","sources":["../../../../src/components/collection/Colllection.styles.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;CAAG;;;;;;AAE1C,wBASI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/collection/Colllection.styles.ts"],"sourcesContent":["import {createStyles} from '@mantine/core';\n\nexport interface CollectionStylesParams {}\n\nexport default createStyles((theme) => ({\n root: {},\n item: {\n backgroundColor: theme.colorScheme === 'light' ? theme.white : theme.black,\n alignItems: 'baseline',\n },\n itemDragging: {\n boxShadow: theme.shadows.sm,\n },\n}));\n"],"names":["createStyles","theme","root","item","backgroundColor","colorScheme","white","black","alignItems","itemDragging","boxShadow","shadows","sm"],"mappings":"AAAA,SAAQA,YAAY,QAAO,gBAAgB;AAI3C,eAAeA,aAAa,SAACC;WAAW;QACpCC,MAAM,CAAC;QACPC,MAAM;YACFC,iBAAiBH,MAAMI,WAAW,KAAK,UAAUJ,MAAMK,KAAK,GAAGL,MAAMM,KAAK;YAC1EC,YAAY;QAChB;QACAC,cAAc;YACVC,WAAWT,MAAMU,OAAO,CAACC,EAAE;QAC/B;IACJ;GAAI"}
|