@coveord/plasma-mantine 55.7.0 → 55.7.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 +54 -52
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.d.ts +7 -0
- package/dist/cjs/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/cjs/components/code-editor/CodeEditor.js +6 -3
- package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/cjs/components/modal/Modal.d.ts +2 -2
- package/dist/cjs/components/modal/Modal.d.ts.map +1 -1
- package/dist/cjs/components/modal/Modal.js.map +1 -1
- package/dist/cjs/components/table/use-url-synced-state.d.ts.map +1 -1
- package/dist/cjs/components/table/use-url-synced-state.js +29 -19
- package/dist/cjs/components/table/use-url-synced-state.js.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.d.ts +7 -0
- package/dist/esm/components/code-editor/CodeEditor.d.ts.map +1 -1
- package/dist/esm/components/code-editor/CodeEditor.js +4 -2
- package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
- package/dist/esm/components/modal/Modal.d.ts +2 -2
- package/dist/esm/components/modal/Modal.d.ts.map +1 -1
- package/dist/esm/components/modal/Modal.js.map +1 -1
- package/dist/esm/components/table/use-url-synced-state.d.ts.map +1 -1
- package/dist/esm/components/table/use-url-synced-state.js +26 -18
- package/dist/esm/components/table/use-url-synced-state.js.map +1 -1
- package/package.json +13 -13
- package/src/components/code-editor/CodeEditor.tsx +8 -1
- package/src/components/modal/Modal.tsx +2 -2
- package/src/components/table/__tests__/use-url-synced-state.unit.spec.ts +189 -138
- package/src/components/table/use-url-synced-state.ts +36 -18
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InputWrapperProps, StackProps } from '@mantine/core';
|
|
2
|
+
import { editor as monacoEditor } from 'monaco-editor';
|
|
2
3
|
import { FunctionComponent } from 'react';
|
|
3
4
|
interface CodeEditorProps extends Omit<InputWrapperProps, 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'>, Omit<StackProps, 'onChange'> {
|
|
4
5
|
/**
|
|
@@ -43,6 +44,12 @@ interface CodeEditorProps extends Omit<InputWrapperProps, 'inputContainer' | 'in
|
|
|
43
44
|
* @default 'local'
|
|
44
45
|
*/
|
|
45
46
|
monacoLoader?: 'cdn' | 'local';
|
|
47
|
+
/**
|
|
48
|
+
* Options to pass to the monaco editor.
|
|
49
|
+
* Currently only supporting [`tabSize`](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html#tabSize).
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
options?: Pick<monacoEditor.IStandaloneEditorConstructionOptions, 'tabSize'>;
|
|
46
53
|
}
|
|
47
54
|
export declare const CodeEditor: FunctionComponent<CodeEditorProps>;
|
|
48
55
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKH,iBAAiB,EAIjB,UAAU,EAKb,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKH,iBAAiB,EAIjB,UAAU,EAKb,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,iBAAiB,EAA8B,MAAM,OAAO,CAAC;AAQrE,UAAU,eACN,SAAQ,IAAI,CACJ,iBAAiB,EACjB,gBAAgB,GAAG,mBAAmB,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CACzF,EACD,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC;IACrF,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,IAAI,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,IAAI,IAAI,CAAC;IAChB,qDAAqD;IACrD,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,oCAAoC,EAAE,SAAS,CAAC,CAAC;CAChF;AASD,eAAO,MAAM,UAAU,EAAE,iBAAiB,CAAC,eAAe,CAmLzD,CAAC"}
|
|
@@ -35,7 +35,9 @@ var defaultProps = {
|
|
|
35
35
|
minHeight: 300
|
|
36
36
|
};
|
|
37
37
|
var CodeEditor = function(props) {
|
|
38
|
-
var _useProps = (0, _core.useProps)('CodeEditor', defaultProps, props), language = _useProps.language, defaultValue = _useProps.defaultValue, onChange = _useProps.onChange, onCopy = _useProps.onCopy, onSearch = _useProps.onSearch, onFocus = _useProps.onFocus, value = _useProps.value, label = _useProps.label, required = _useProps.required, labelProps = _useProps.labelProps, error = _useProps.error, errorProps = _useProps.errorProps, description = _useProps.description, descriptionProps = _useProps.descriptionProps, minHeight = _useProps.minHeight, maxHeight = _useProps.maxHeight, disabled = _useProps.disabled, monacoLoader = _useProps.monacoLoader,
|
|
38
|
+
var _useProps = (0, _core.useProps)('CodeEditor', defaultProps, props), language = _useProps.language, defaultValue = _useProps.defaultValue, onChange = _useProps.onChange, onCopy = _useProps.onCopy, onSearch = _useProps.onSearch, onFocus = _useProps.onFocus, value = _useProps.value, label = _useProps.label, required = _useProps.required, labelProps = _useProps.labelProps, error = _useProps.error, errorProps = _useProps.errorProps, description = _useProps.description, descriptionProps = _useProps.descriptionProps, minHeight = _useProps.minHeight, maxHeight = _useProps.maxHeight, disabled = _useProps.disabled, monacoLoader = _useProps.monacoLoader, tmp = _useProps.options, tabSize = (tmp === void 0 ? {
|
|
39
|
+
tabSize: 2
|
|
40
|
+
} : tmp).tabSize, others = _object_without_properties._(_useProps, [
|
|
39
41
|
"language",
|
|
40
42
|
"defaultValue",
|
|
41
43
|
"onChange",
|
|
@@ -53,7 +55,8 @@ var CodeEditor = function(props) {
|
|
|
53
55
|
"minHeight",
|
|
54
56
|
"maxHeight",
|
|
55
57
|
"disabled",
|
|
56
|
-
"monacoLoader"
|
|
58
|
+
"monacoLoader",
|
|
59
|
+
"options"
|
|
57
60
|
]);
|
|
58
61
|
var _useState = _sliced_to_array._((0, _react1.useState)(false), 2), loaded = _useState[0], setLoaded = _useState[1];
|
|
59
62
|
var _useUncontrolled = _sliced_to_array._((0, _hooks.useUncontrolled)({
|
|
@@ -196,7 +199,7 @@ var CodeEditor = function(props) {
|
|
|
196
199
|
formatOnPaste: true,
|
|
197
200
|
fontSize: (0, _core.px)(theme.fontSizes.xs),
|
|
198
201
|
readOnly: disabled,
|
|
199
|
-
tabSize:
|
|
202
|
+
tabSize: tabSize
|
|
200
203
|
},
|
|
201
204
|
value: _value,
|
|
202
205
|
onChange: handleChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n Group,\n Input,\n InputWrapperProps,\n Loader,\n Space,\n Stack,\n StackProps,\n px,\n useMantineColorScheme,\n useMantineTheme,\n useProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {Monaco, loader} from '@monaco-editor/react';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport cx from 'clsx';\nimport {useParentHeight} from '../../hooks';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport CodeEditorClasses from './CodeEditor.module.css';\nimport {XML} from './languages/xml';\nimport {Search} from './search';\ninterface CodeEditorProps\n extends Omit<\n InputWrapperProps,\n 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'\n >,\n Omit<StackProps, 'onChange'> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml' | (string & unknown);\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const registerThemes = (monaco: Monaco) => {\n monaco.editor.defineTheme('light-disabled', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.gray[2],\n },\n });\n monaco.editor.defineTheme('vs-dark-disabled', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.navy[7],\n },\n });\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n const [hasMonacoError, setHasMonacoError] = useState(false);\n const renderErrorOutline = !!error || hasMonacoError;\n const theme = useMantineTheme();\n const {colorScheme} = useMantineColorScheme();\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setHasMonacoError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group justify=\"right\" gap={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n let editorTheme = colorScheme === 'light' ? 'light' : 'vs-dark';\n if (disabled) {\n editorTheme += '-disabled';\n }\n\n const _editor = loaded ? (\n <Box\n p=\"md\"\n pl=\"xs\"\n className={cx(\n CodeEditorClasses.editor,\n {[CodeEditorClasses.valid]: !renderErrorOutline},\n {[CodeEditorClasses.error]: renderErrorOutline},\n {[CodeEditorClasses.disabled]: disabled},\n )}\n data-testid=\"editor-wrapper\"\n >\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={editorTheme}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs) as number,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n registerThemes(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={CodeEditorClasses.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack justify=\"flex-start\" gap={0} h={Math.max(parentHeight, minHeight)} mah={maxHeight} ref={ref} {...others}>\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CodeEditor","defaultProps","language","monacoLoader","defaultValue","minHeight","props","useProps","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","useState","loaded","setLoaded","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","editorRef","useRef","loadLocalMonaco","monacoInstance","loader","config","monaco","registerLanguages","XML","register","registerThemes","editor","defineTheme","base","inherit","rules","colors","theme","gray","navy","handleSearch","current","focus","trigger","hasMonacoError","setHasMonacoError","renderErrorOutline","useMantineTheme","colorScheme","useMantineColorScheme","useEffect","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Input","Label","_description","Description","_error","mt","Space","h","_header","Box","_buttons","Group","justify","gap","Search","CopyToClipboard","editorTheme","_editor","p","pl","className","cx","CodeEditorClasses","valid","data-testid","Editor","onValidate","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","px","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","Math","max","mah"],"mappings":";;;;+BAmFaA;;;eAAAA;;;;;;;;;;;;;oBArEN;qBACuB;+DACO;sBAEwB;6DAE9C;sBACe;+BACA;4EACA;mBACZ;sBACG;AAmDrB,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEO,IAAML,aAAiD,SAACM;IAC3D,IAoBIC,YAAAA,IAAAA,cAAQ,EAAC,cAAcN,cAAcK,QAnBrCJ,WAmBAK,UAnBAL,UACAE,eAkBAG,UAlBAH,cACAI,WAiBAD,UAjBAC,UACAC,SAgBAF,UAhBAE,QACAC,WAeAH,UAfAG,UACAC,UAcAJ,UAdAI,SACAC,QAaAL,UAbAK,OACAC,QAYAN,UAZAM,OACAC,WAWAP,UAXAO,UACAC,aAUAR,UAVAQ,YACAC,QASAT,UATAS,OACAC,aAQAV,UARAU,YACAC,cAOAX,UAPAW,aACAC,mBAMAZ,UANAY,kBACAd,YAKAE,UALAF,WACAe,YAIAb,UAJAa,WACAC,WAGAd,UAHAc,UACAlB,eAEAI,UAFAJ,cACGmB,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AE;QACFC,IAAG;QACHC,WAAWC,IAAAA,aAAE,EACTC,4BAAiB,CAACnD,MAAM,EACvB,uBAACmD,4BAAiB,CAACC,KAAK,EAAG,CAACrC,qBAC5B,uBAACoC,4BAAiB,CAAC/E,KAAK,EAAG2C,qBAC3B,uBAACoC,4BAAiB,CAAC1E,QAAQ,EAAGA;QAEnC4E,eAAY;kBAEZ,cAAA,qBAACC,cAAM;YACHC,YAAYnC;YACZoC,iBAAiBlG;YACjBgD,OAAOuC;YACPY,SAAS;gBACLC,SAAS;oBAACC,SAAS;gBAAK;gBACxBC,UAAU;gBACVC,sBAAsB;gBACtBC,eAAe;gBACfC,UAAUC,IAAAA,QAAE,EAAC1D,MAAM2D,SAAS,CAACC,EAAE;gBAC/BC,UAAU1F;gBACV2F,SAAS;YACb;YACApG,OAAOgB;YACPpB,UAAUqB;YACVoF,SAAS,SAACrE,QAAQL;gBACdN,UAAUqB,OAAO,GAAGV;gBACpBJ,kBAAkBD;gBAClBI,eAAeJ;gBACfK,OAAOsE,oBAAoB,CAAC;2BAAMvG,oBAAAA,8BAAAA;;gBAClCiC,OAAOuE,mBAAmB,qCAAC;;;;gCACvB;;oCAAMvE,OAAOwE,SAAS,CAAC,gCAAgCC,GAAG;;;gCAA1D;;;;;;gBACJ;YACJ;;uBAIR,qBAACC,YAAM;QAACzB,WAAWE,4BAAiB,CAACnD,MAAM;kBACvC,cAAA,qBAAC2E,YAAM;;IAIf,qBACI,sBAACC,WAAK;QAACnC,SAAQ;QAAaC,KAAK;QAAGN,GAAGyC,KAAKC,GAAG,CAAC3F,cAAc1B;QAAYsH,KAAKvG;QAAWY,KAAKA;OAASV;;YACnG2D;YACAE;YACAO;YACAb;;;AAGb"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n Group,\n Input,\n InputWrapperProps,\n Loader,\n Space,\n Stack,\n StackProps,\n px,\n useMantineColorScheme,\n useMantineTheme,\n useProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {Monaco, loader} from '@monaco-editor/react';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport cx from 'clsx';\nimport {useParentHeight} from '../../hooks';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport CodeEditorClasses from './CodeEditor.module.css';\nimport {XML} from './languages/xml';\nimport {Search} from './search';\ninterface CodeEditorProps\n extends Omit<\n InputWrapperProps,\n 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'\n >,\n Omit<StackProps, 'onChange'> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml' | (string & unknown);\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n /**\n * Options to pass to the monaco editor.\n * Currently only supporting [`tabSize`](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html#tabSize).\n *\n */\n options?: Pick<monacoEditor.IStandaloneEditorConstructionOptions, 'tabSize'>;\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n options: {tabSize} = {tabSize: 2},\n ...others\n } = useProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const registerThemes = (monaco: Monaco) => {\n monaco.editor.defineTheme('light-disabled', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.gray[2],\n },\n });\n monaco.editor.defineTheme('vs-dark-disabled', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.navy[7],\n },\n });\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n const [hasMonacoError, setHasMonacoError] = useState(false);\n const renderErrorOutline = !!error || hasMonacoError;\n const theme = useMantineTheme();\n const {colorScheme} = useMantineColorScheme();\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setHasMonacoError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group justify=\"right\" gap={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n let editorTheme = colorScheme === 'light' ? 'light' : 'vs-dark';\n if (disabled) {\n editorTheme += '-disabled';\n }\n\n const _editor = loaded ? (\n <Box\n p=\"md\"\n pl=\"xs\"\n className={cx(\n CodeEditorClasses.editor,\n {[CodeEditorClasses.valid]: !renderErrorOutline},\n {[CodeEditorClasses.error]: renderErrorOutline},\n {[CodeEditorClasses.disabled]: disabled},\n )}\n data-testid=\"editor-wrapper\"\n >\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={editorTheme}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs) as number,\n readOnly: disabled,\n tabSize,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n registerThemes(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={CodeEditorClasses.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack justify=\"flex-start\" gap={0} h={Math.max(parentHeight, minHeight)} mah={maxHeight} ref={ref} {...others}>\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["CodeEditor","defaultProps","language","monacoLoader","defaultValue","minHeight","props","useProps","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","options","tabSize","others","useState","loaded","setLoaded","useUncontrolled","finalValue","_value","handleChange","useParentHeight","parentHeight","ref","editorRef","useRef","loadLocalMonaco","monacoInstance","loader","config","monaco","registerLanguages","XML","register","registerThemes","editor","defineTheme","base","inherit","rules","colors","theme","gray","navy","handleSearch","current","focus","trigger","hasMonacoError","setHasMonacoError","renderErrorOutline","useMantineTheme","colorScheme","useMantineColorScheme","useEffect","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Input","Label","_description","Description","_error","mt","Space","h","_header","Box","_buttons","Group","justify","gap","Search","CopyToClipboard","editorTheme","_editor","p","pl","className","cx","CodeEditorClasses","valid","data-testid","Editor","onValidate","defaultLanguage","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","px","fontSizes","xs","readOnly","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Center","Loader","Stack","Math","max","mah"],"mappings":";;;;+BAyFaA;;;eAAAA;;;;;;;;;;;;;oBA3EN;qBACuB;+DACO;sBAEwB;6DAE9C;sBACe;+BACA;4EACA;mBACZ;sBACG;AAyDrB,IAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEO,IAAML,aAAiD,SAACM;IAC3D,IAqBIC,YAAAA,IAAAA,cAAQ,EAAC,cAAcN,cAAcK,QApBrCJ,WAoBAK,UApBAL,UACAE,eAmBAG,UAnBAH,cACAI,WAkBAD,UAlBAC,UACAC,SAiBAF,UAjBAE,QACAC,WAgBAH,UAhBAG,UACAC,UAeAJ,UAfAI,SACAC,QAcAL,UAdAK,OACAC,QAaAN,UAbAM,OACAC,WAYAP,UAZAO,UACAC,aAWAR,UAXAQ,YACAC,QAUAT,UAVAS,OACAC,aASAV,UATAU,YACAC,cAQAX,UARAW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E;YACAO;YACAb;;;AAGb"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ModalFactory as MantineModalFactory } from '@mantine/core';
|
|
2
|
-
import { ModalFooter } from './ModalFooter';
|
|
2
|
+
import { ModalFooter as PlasmaModalFooter } from './ModalFooter';
|
|
3
3
|
type PlasmaModalFactory = Omit<MantineModalFactory, 'staticComponents'> & {
|
|
4
4
|
staticComponents: MantineModalFactory['staticComponents'] & {
|
|
5
|
-
Footer: typeof
|
|
5
|
+
Footer: typeof PlasmaModalFooter;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export declare const Modal: import("@mantine/core").MantineComponent<PlasmaModalFactory>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,YAAY,IAAI,mBAAmB,EAEtC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,YAAY,IAAI,mBAAmB,EAEtC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAG/D,KAAK,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,GAAG;IACtE,gBAAgB,EAAE,mBAAmB,CAAC,kBAAkB,CAAC,GAAG;QACxD,MAAM,EAAE,OAAO,iBAAiB,CAAC;KACpC,CAAC;CACL,CAAC;AAiBF,eAAO,MAAM,KAAK,8DAAc,CAAC;AAEjC,MAAM,MAAM,YAAY,GAAG,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/modal/Modal.tsx"],"sourcesContent":["import {\n factory,\n Modal as MantineModal,\n ModalFactory as MantineModalFactory,\n ModalProps as MantineModalProps,\n} from '@mantine/core';\nimport {ModalFooter
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/modal/Modal.tsx"],"sourcesContent":["import {\n factory,\n Modal as MantineModal,\n ModalFactory as MantineModalFactory,\n ModalProps as MantineModalProps,\n} from '@mantine/core';\nimport {ModalFooter as PlasmaModalFooter} from './ModalFooter';\n\n// Need to redeclare the factory to override and add footer to the props type\ntype PlasmaModalFactory = Omit<MantineModalFactory, 'staticComponents'> & {\n staticComponents: MantineModalFactory['staticComponents'] & {\n Footer: typeof PlasmaModalFooter;\n };\n};\n\nconst PlasmaModal = factory<PlasmaModalFactory>((props: MantineModalProps, ref) => (\n <MantineModal ref={ref} {...props} />\n));\n\nPlasmaModal.displayName = '@coveord/plasma-mantine/Modal';\nPlasmaModal.Root = MantineModal.Root;\nPlasmaModal.Body = MantineModal.Body;\nPlasmaModal.Overlay = MantineModal.Overlay;\nPlasmaModal.Content = MantineModal.Content;\nPlasmaModal.Header = MantineModal.Header;\nPlasmaModal.Title = MantineModal.Title;\nPlasmaModal.CloseButton = MantineModal.CloseButton;\nPlasmaModal.Stack = MantineModal.Stack;\nPlasmaModal.Footer = PlasmaModalFooter;\n\nexport const Modal = PlasmaModal;\n\nexport type ModalFactory = PlasmaModalFactory;\n"],"names":["Modal","PlasmaModal","factory","props","ref","MantineModal","displayName","Root","Body","Overlay","Content","Header","Title","CloseButton","Stack","Footer","PlasmaModalFooter"],"mappings":";;;;+BA8BaA;;;eAAAA;;;;;oBAzBN;2BACwC;AAS/C,IAAMC,cAAcC,IAAAA,aAAO,EAAqB,SAACC,OAA0BC;yBACvE,qBAACC,WAAY;QAACD,KAAKA;OAASD;;AAGhCF,YAAYK,WAAW,GAAG;AAC1BL,YAAYM,IAAI,GAAGF,WAAY,CAACE,IAAI;AACpCN,YAAYO,IAAI,GAAGH,WAAY,CAACG,IAAI;AACpCP,YAAYQ,OAAO,GAAGJ,WAAY,CAACI,OAAO;AAC1CR,YAAYS,OAAO,GAAGL,WAAY,CAACK,OAAO;AAC1CT,YAAYU,MAAM,GAAGN,WAAY,CAACM,MAAM;AACxCV,YAAYW,KAAK,GAAGP,WAAY,CAACO,KAAK;AACtCX,YAAYY,WAAW,GAAGR,WAAY,CAACQ,WAAW;AAClDZ,YAAYa,KAAK,GAAGT,WAAY,CAACS,KAAK;AACtCb,YAAYc,MAAM,GAAGC,wBAAiB;AAE/B,IAAMhB,QAAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-url-synced-state.d.ts","sourceRoot":"","sources":["../../../../src/components/table/use-url-synced-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAoB,MAAM,OAAO,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-url-synced-state.d.ts","sourceRoot":"","sources":["../../../../src/components/table/use-url-synced-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAoB,MAAM,OAAO,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAuD7E,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACvC;;;;OAIG;IACH,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5B;;;;;;;;;OASG;IACH,UAAU,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC1D;;;;;;;;OAQG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9D;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAKD,eAAO,MAAM,iBAAiB,GAAI,CAAC,WAAW,wBAAwB,CAAC,CAAC,CAAC,8CAmDxE,CAAC"}
|
|
@@ -11,14 +11,22 @@ Object.defineProperty(exports, "useUrlSyncedState", {
|
|
|
11
11
|
var _instanceof = require("@swc/helpers/_/_instanceof");
|
|
12
12
|
var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
|
|
13
13
|
var _react = require("react");
|
|
14
|
+
var slice = Function.prototype.call.bind(Array.prototype.slice);
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
* Performs a nested search for '#/', to detect hash router urls and take the params of the hash in that case.
|
|
16
|
+
* Split a url into its parts.
|
|
17
17
|
*
|
|
18
|
-
* @param
|
|
19
|
-
* @returns The
|
|
20
|
-
*/ var
|
|
21
|
-
return
|
|
18
|
+
* @param href The url to extract the parts from.
|
|
19
|
+
* @returns The separate parts, all are an empty string if not present.
|
|
20
|
+
*/ var extractParts = function(href) {
|
|
21
|
+
return slice(/^([^?#]*)(\?[^#]*|)(#[^?]*|)(\?.*|)$/.exec(href !== null && href !== void 0 ? href : ''), 1, 5);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The index of the search parameter to use, e.g. hashSearch for hash routes (hash starts with '#/').
|
|
25
|
+
*
|
|
26
|
+
* @param parts: The url parts, as returned by `extractParts`.
|
|
27
|
+
* @returns The index of the search parameter to use (1 or 3).
|
|
28
|
+
*/ var searchIndex = function(parts) {
|
|
29
|
+
return /^#\//.test(parts[2]) ? 3 : 1;
|
|
22
30
|
};
|
|
23
31
|
/**
|
|
24
32
|
* Read the **current** search params from `window.location`, with support for detecting React's HashRouter.
|
|
@@ -26,9 +34,8 @@ var _react = require("react");
|
|
|
26
34
|
*
|
|
27
35
|
* @returns The `URLSearchParams` instance, and a function that can be used to get an updated href.
|
|
28
36
|
*/ var getSearchParams = function() {
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
return new URLSearchParams(searchStart < 0 ? undefined : href.substring(searchStart));
|
|
37
|
+
var parts = extractParts(window.location.href);
|
|
38
|
+
return new URLSearchParams(parts[searchIndex(parts)]);
|
|
32
39
|
};
|
|
33
40
|
/**
|
|
34
41
|
* Apply the search params to the current location, using `replaceState` (no navigation history).
|
|
@@ -37,13 +44,12 @@ var _react = require("react");
|
|
|
37
44
|
* @param params The parameters to apply.
|
|
38
45
|
*/ var applySearchParams = function(params) {
|
|
39
46
|
var currentHref = window.location.href;
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
window.history.replaceState(null, '', nextHref);
|
|
47
|
+
var parts = extractParts(currentHref);
|
|
48
|
+
var search = params.size > 0 ? "?".concat(params.toString()) : '';
|
|
49
|
+
var index = searchIndex(parts);
|
|
50
|
+
if (parts[index] !== search) {
|
|
51
|
+
parts[index] = search;
|
|
52
|
+
window.history.replaceState(null, '', parts.join(''));
|
|
47
53
|
}
|
|
48
54
|
};
|
|
49
55
|
var getInitialState = function(options) {
|
|
@@ -59,14 +65,18 @@ var useUrlSyncedState = function(options) {
|
|
|
59
65
|
var initialStateSerialized = (0, _react.useMemo)(function() {
|
|
60
66
|
var stateMap = new Map();
|
|
61
67
|
var initialize = null;
|
|
68
|
+
var needsApply = false;
|
|
62
69
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
63
70
|
try {
|
|
64
71
|
for(var _iterator = options.serializer(getInitialState(options))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
65
72
|
var _step_value = _sliced_to_array._(_step.value, 3), key = _step_value[0], value = _step_value[1], alwaysEmit = _step_value[2];
|
|
66
73
|
stateMap.set(key, value);
|
|
67
|
-
if (alwaysEmit && value) {
|
|
74
|
+
if (sync && alwaysEmit && value) {
|
|
68
75
|
initialize !== null && initialize !== void 0 ? initialize : initialize = getSearchParams();
|
|
69
|
-
initialize.
|
|
76
|
+
if (!initialize.has(key)) {
|
|
77
|
+
needsApply = true;
|
|
78
|
+
initialize.set(key, value);
|
|
79
|
+
}
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
} catch (err) {
|
|
@@ -83,7 +93,7 @@ var useUrlSyncedState = function(options) {
|
|
|
83
93
|
}
|
|
84
94
|
}
|
|
85
95
|
}
|
|
86
|
-
if (
|
|
96
|
+
if (needsApply) {
|
|
87
97
|
applySearchParams(initialize);
|
|
88
98
|
}
|
|
89
99
|
return stateMap;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/table/use-url-synced-state.ts"],"sourcesContent":["import {Dispatch, SetStateAction, useMemo, useState} from 'react';\n\n/**\n * A search param entry defines the encoded value of a search parameter as `[key, value, alwaysEmit?]`.\n * The third entry is an optional boolean that defaults to `false`.\n * Setting `alwaysEmit` to `true` means any non-nullish value is always written to the search params,\n * even if it matches the initial value. It is also written on initialization.\n */\nexport type SearchParamEntry = [string, string | null | undefined, boolean?];\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/table/use-url-synced-state.ts"],"sourcesContent":["import {Dispatch, SetStateAction, useMemo, useState} from 'react';\n\n/**\n * A search param entry defines the encoded value of a search parameter as `[key, value, alwaysEmit?]`.\n * The third entry is an optional boolean that defaults to `false`.\n * Setting `alwaysEmit` to `true` means any non-nullish value is always written to the search params,\n * even if it matches the initial value. It is also written on initialization.\n */\nexport type SearchParamEntry = [string, string | null | undefined, boolean?];\n\n/** A URL split into an array of length 4, as [pathname, search, hash, hashSearch] */\ntype UrlParts = [string, string, string, string];\n\nconst slice = Function.prototype.call.bind(Array.prototype.slice) as <T>(\n from: ArrayLike<T>,\n start?: number,\n end?: number,\n) => T[];\n\n/**\n * Split a url into its parts.\n *\n * @param href The url to extract the parts from.\n * @returns The separate parts, all are an empty string if not present.\n */\nconst extractParts = (href: string) => slice(/^([^?#]*)(\\?[^#]*|)(#[^?]*|)(\\?.*|)$/.exec(href ?? ''), 1, 5) as UrlParts;\n\n/**\n * The index of the search parameter to use, e.g. hashSearch for hash routes (hash starts with '#/').\n *\n * @param parts: The url parts, as returned by `extractParts`.\n * @returns The index of the search parameter to use (1 or 3).\n */\nconst searchIndex = (parts: UrlParts): 1 | 3 => (/^#\\//.test(parts[2]) ? 3 : 1);\n\n/**\n * Read the **current** search params from `window.location`, with support for detecting React's HashRouter.\n * Also returns a method that will yield the href (string) value, after any changes made on the params object.\n *\n * @returns The `URLSearchParams` instance, and a function that can be used to get an updated href.\n */\nconst getSearchParams = (): URLSearchParams => {\n const parts = extractParts(window.location.href);\n return new URLSearchParams(parts[searchIndex(parts)]);\n};\n\n/**\n * Apply the search params to the current location, using `replaceState` (no navigation history).\n * Note that only parameters in the `params` argument will be set, any other current params will be removed.\n *\n * @param params The parameters to apply.\n */\nconst applySearchParams = (params: URLSearchParams): void => {\n const currentHref = window.location.href;\n const parts = extractParts(currentHref);\n const search = params.size > 0 ? `?${params.toString()}` : '';\n const index = searchIndex(parts);\n if (parts[index] !== search) {\n parts[index] = search;\n window.history.replaceState(null, '', parts.join(''));\n }\n};\n\nexport interface UseUrlSyncedStateOptions<T> {\n /**\n * The initial state to use, if there would be no search params to deserialize from.\n * These values are also treated as defaults, and if the current state matches the initialState,\n * no value will be written to the search params.\n */\n initialState: T | (() => T);\n /**\n * The serializer function is used to determine how the state is translated to url search parameters.\n * Called each time the state changes.\n * Note that the serializer should always return entries for keys it controls, also if the current value is \"unset\" (`null` or empty).\n * This ensures params get removed from the search when they are being unset.\n *\n * @param stateValue The new state value to serialize.\n * @returns An iterable of `[key, value]` to set as url search parameters.\n * @example (filterValue) => [['filter', filterValue]] // ?filter=filterValue\n */\n serializer: (stateValue: T) => Iterable<SearchParamEntry>;\n /**\n * The deserializer function is used to determine how the url parameters influence the initial state.\n * May return a partial state, values that are not deserialed are taken from the `initialState`.\n * Called only once when initializing the state.\n * @param params All the search parameters of the current url.\n * @param initialState The initialState, can be used to take defaults from.\n * @returns The initial state based on the current url.\n * @example (params) => params.get('filter') ?? '',\n */\n deserializer: (params: URLSearchParams, initialState: T) => T;\n /**\n * Whether the state should be synced with the url, defaults to `true`.\n * When set to `false`, the hook behaves just like a regular `useState` hook from react.\n */\n sync?: boolean;\n}\n\nconst getInitialState = <T>(options: UseUrlSyncedStateOptions<T>): T =>\n options.initialState instanceof Function ? options.initialState() : options.initialState;\n\nexport const useUrlSyncedState = <T>(options: UseUrlSyncedStateOptions<T>) => {\n const sync = options.sync !== false;\n const [state, setState] = useState<T>(() => {\n const initialState = getInitialState(options);\n return sync ? options.deserializer(getSearchParams(), initialState) : initialState;\n });\n // Capture the initial state as a map (first render only!), to compare values and see if they should be set to the params.\n const initialStateSerialized = useMemo(() => {\n const stateMap = new Map<string, string>();\n let initialize: URLSearchParams | null = null;\n let needsApply = false;\n for (const [key, value, alwaysEmit] of options.serializer(getInitialState(options))) {\n stateMap.set(key, value);\n if (sync && alwaysEmit && value) {\n initialize ??= getSearchParams();\n if (!initialize.has(key)) {\n needsApply = true;\n initialize.set(key, value);\n }\n }\n }\n if (needsApply) {\n applySearchParams(initialize);\n }\n return stateMap;\n }, []);\n\n const enhancedSetState = useMemo<Dispatch<SetStateAction<T>>>(() => {\n if (!sync) {\n return setState;\n }\n return (updater: SetStateAction<T>) => {\n setState((old) => {\n const newValue = updater instanceof Function ? updater(old) : updater;\n\n const search = getSearchParams();\n for (const [key, value, alwaysEmit] of options.serializer(newValue)) {\n if (value && (alwaysEmit || !Object.is(initialStateSerialized.get(key), value))) {\n search.set(key, value);\n } else {\n search.delete(key);\n }\n }\n applySearchParams(search);\n\n return newValue;\n });\n };\n }, [sync]);\n\n return [state, enhancedSetState] as const;\n};\n"],"names":["useUrlSyncedState","slice","Function","prototype","call","bind","Array","extractParts","href","exec","searchIndex","parts","test","getSearchParams","window","location","URLSearchParams","applySearchParams","params","currentHref","search","size","toString","index","history","replaceState","join","getInitialState","options","initialState","sync","useState","deserializer","state","setState","initialStateSerialized","useMemo","stateMap","Map","initialize","needsApply","serializer","key","value","alwaysEmit","set","has","enhancedSetState","updater","old","newValue","Object","is","get","delete"],"mappings":";;;;+BAqGaA;;;eAAAA;;;;;qBArG6C;AAa1D,IAAMC,QAAQC,SAASC,SAAS,CAACC,IAAI,CAACC,IAAI,CAACC,MAAMH,SAAS,CAACF,KAAK;AAMhE;;;;;CAKC,GACD,IAAMM,eAAe,SAACC;WAAiBP,MAAM,uCAAuCQ,IAAI,CAACD,iBAAAA,kBAAAA,OAAQ,KAAK,GAAG;;AAEzG;;;;;CAKC,GACD,IAAME,cAAc,SAACC;WAA4B,OAAOC,IAAI,CAACD,KAAK,CAAC,EAAE,IAAI,IAAI;;AAE7E;;;;;CAKC,GACD,IAAME,kBAAkB;IACpB,IAAMF,QAAQJ,aAAaO,OAAOC,QAAQ,CAACP,IAAI;IAC/C,OAAO,IAAIQ,gBAAgBL,KAAK,CAACD,YAAYC,OAAO;AACxD;AAEA;;;;;CAKC,GACD,IAAMM,oBAAoB,SAACC;IACvB,IAAMC,cAAcL,OAAOC,QAAQ,CAACP,IAAI;IACxC,IAAMG,QAAQJ,aAAaY;IAC3B,IAAMC,SAASF,OAAOG,IAAI,GAAG,IAAI,AAAC,IAAqB,OAAlBH,OAAOI,QAAQ,MAAO;IAC3D,IAAMC,QAAQb,YAAYC;IAC1B,IAAIA,KAAK,CAACY,MAAM,KAAKH,QAAQ;QACzBT,KAAK,CAACY,MAAM,GAAGH;QACfN,OAAOU,OAAO,CAACC,YAAY,CAAC,MAAM,IAAId,MAAMe,IAAI,CAAC;IACrD;AACJ;AAqCA,IAAMC,kBAAkB,SAAIC;WACxBA,AAAoB,aAAY1B,CAAhC0B,QAAQC,YAAY,EAAY3B,YAAW0B,QAAQC,YAAY,KAAKD,QAAQC,YAAY;;AAErF,IAAM7B,oBAAoB,SAAI4B;IACjC,IAAME,OAAOF,QAAQE,IAAI,KAAK;IAC9B,IAA0BC,+BAAAA,IAAAA,eAA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MAAK,GAAI;4BAC7EvB,OAAOyB,GAAG,CAACH,KAAKC;wBACpB,OAAO;4BACHvB,OAAOkC,MAAM,CAACZ;wBAClB;oBACJ;;oBANK;oBAAA;;;6BAAA,6BAAA;4BAAA;;;4BAAA;kCAAA;;;;gBAOLzB,kBAAkBG;gBAElB,OAAO8B;YACX;QACJ;IACJ,GAAG;QAACpB;KAAK;IAET,OAAO;QAACG;QAAOc;KAAiB;AACpC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InputWrapperProps, StackProps } from '@mantine/core';
|
|
2
|
+
import { editor as monacoEditor } from 'monaco-editor';
|
|
2
3
|
import { FunctionComponent } from 'react';
|
|
3
4
|
interface CodeEditorProps extends Omit<InputWrapperProps, 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'>, Omit<StackProps, 'onChange'> {
|
|
4
5
|
/**
|
|
@@ -43,6 +44,12 @@ interface CodeEditorProps extends Omit<InputWrapperProps, 'inputContainer' | 'in
|
|
|
43
44
|
* @default 'local'
|
|
44
45
|
*/
|
|
45
46
|
monacoLoader?: 'cdn' | 'local';
|
|
47
|
+
/**
|
|
48
|
+
* Options to pass to the monaco editor.
|
|
49
|
+
* Currently only supporting [`tabSize`](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html#tabSize).
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
options?: Pick<monacoEditor.IStandaloneEditorConstructionOptions, 'tabSize'>;
|
|
46
53
|
}
|
|
47
54
|
export declare const CodeEditor: FunctionComponent<CodeEditorProps>;
|
|
48
55
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKH,iBAAiB,EAIjB,UAAU,EAKb,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeEdit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CAAC,eAAe,CAmLzD,CAAC"}
|
|
@@ -16,7 +16,9 @@ const defaultProps = {
|
|
|
16
16
|
minHeight: 300
|
|
17
17
|
};
|
|
18
18
|
export const CodeEditor = (props)=>{
|
|
19
|
-
const { language, defaultValue, onChange, onCopy, onSearch, onFocus, value, label, required, labelProps, error, errorProps, description, descriptionProps, minHeight, maxHeight, disabled, monacoLoader,
|
|
19
|
+
const { language, defaultValue, onChange, onCopy, onSearch, onFocus, value, label, required, labelProps, error, errorProps, description, descriptionProps, minHeight, maxHeight, disabled, monacoLoader, options: { tabSize } = {
|
|
20
|
+
tabSize: 2
|
|
21
|
+
}, ...others } = useProps('CodeEditor', defaultProps, props);
|
|
20
22
|
const [loaded, setLoaded] = useState(false);
|
|
21
23
|
const [_value, handleChange] = useUncontrolled({
|
|
22
24
|
value,
|
|
@@ -140,7 +142,7 @@ export const CodeEditor = (props)=>{
|
|
|
140
142
|
formatOnPaste: true,
|
|
141
143
|
fontSize: px(theme.fontSizes.xs),
|
|
142
144
|
readOnly: disabled,
|
|
143
|
-
tabSize
|
|
145
|
+
tabSize
|
|
144
146
|
},
|
|
145
147
|
value: _value,
|
|
146
148
|
onChange: handleChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n Group,\n Input,\n InputWrapperProps,\n Loader,\n Space,\n Stack,\n StackProps,\n px,\n useMantineColorScheme,\n useMantineTheme,\n useProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {Monaco, loader} from '@monaco-editor/react';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport cx from 'clsx';\nimport {useParentHeight} from '../../hooks';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport CodeEditorClasses from './CodeEditor.module.css';\nimport {XML} from './languages/xml';\nimport {Search} from './search';\ninterface CodeEditorProps\n extends Omit<\n InputWrapperProps,\n 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'\n >,\n Omit<StackProps, 'onChange'> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml' | (string & unknown);\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n ...others\n } = useProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const registerThemes = (monaco: Monaco) => {\n monaco.editor.defineTheme('light-disabled', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.gray[2],\n },\n });\n monaco.editor.defineTheme('vs-dark-disabled', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.navy[7],\n },\n });\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n const [hasMonacoError, setHasMonacoError] = useState(false);\n const renderErrorOutline = !!error || hasMonacoError;\n const theme = useMantineTheme();\n const {colorScheme} = useMantineColorScheme();\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setHasMonacoError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group justify=\"right\" gap={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n let editorTheme = colorScheme === 'light' ? 'light' : 'vs-dark';\n if (disabled) {\n editorTheme += '-disabled';\n }\n\n const _editor = loaded ? (\n <Box\n p=\"md\"\n pl=\"xs\"\n className={cx(\n CodeEditorClasses.editor,\n {[CodeEditorClasses.valid]: !renderErrorOutline},\n {[CodeEditorClasses.error]: renderErrorOutline},\n {[CodeEditorClasses.disabled]: disabled},\n )}\n data-testid=\"editor-wrapper\"\n >\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={editorTheme}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs) as number,\n readOnly: disabled,\n tabSize: 2,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n registerThemes(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={CodeEditorClasses.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack justify=\"flex-start\" gap={0} h={Math.max(parentHeight, minHeight)} mah={maxHeight} ref={ref} {...others}>\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["Box","Center","Group","Input","Loader","Space","Stack","px","useMantineColorScheme","useMantineTheme","useProps","useUncontrolled","Editor","loader","useEffect","useRef","useState","cx","useParentHeight","CopyToClipboard","CodeEditorClasses","XML","Search","defaultProps","language","monacoLoader","defaultValue","minHeight","CodeEditor","props","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","others","loaded","setLoaded","_value","handleChange","finalValue","parentHeight","ref","editorRef","loadLocalMonaco","monacoInstance","config","monaco","registerLanguages","register","registerThemes","editor","defineTheme","base","inherit","rules","colors","theme","gray","navy","handleSearch","current","focus","trigger","hasMonacoError","setHasMonacoError","renderErrorOutline","colorScheme","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Label","_description","Description","_error","mt","h","_header","_buttons","justify","gap","editorTheme","_editor","p","pl","className","valid","data-testid","onValidate","defaultLanguage","options","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","tabSize","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Math","max","mah"],"mappings":";AAAA,SACIA,GAAG,EACHC,MAAM,EACNC,KAAK,EACLC,KAAK,EAELC,MAAM,EACNC,KAAK,EACLC,KAAK,EAELC,EAAE,EACFC,qBAAqB,EACrBC,eAAe,EACfC,QAAQ,QACL,gBAAgB;AACvB,SAAQC,eAAe,QAAO,iBAAiB;AAC/C,OAAOC,UAAiBC,MAAM,QAAO,uBAAuB;AAE5D,SAA2BC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAO,QAAQ;AAErE,OAAOC,QAAQ,OAAO;AACtB,SAAQC,eAAe,QAAO,cAAc;AAC5C,SAAQC,eAAe,QAAO,qBAAqB;AACnD,OAAOC,uBAAuB,0BAA0B;AACxD,SAAQC,GAAG,QAAO,kBAAkB;AACpC,SAAQC,MAAM,QAAO,WAAW;AAmDhC,MAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEA,OAAO,MAAMC,aAAiD,CAACC;IAC3D,MAAM,EACFL,QAAQ,EACRE,YAAY,EACZI,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,KAAK,EACLC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,WAAW,EACXC,gBAAgB,EAChBd,SAAS,EACTe,SAAS,EACTC,QAAQ,EACRlB,YAAY,EACZ,GAAGmB,QACN,GAAGlC,SAAS,cAAca,cAAcM;IACzC,MAAM,CAACgB,QAAQC,UAAU,GAAG9B,SAAS;IACrC,MAAM,CAAC+B,QAAQC,aAAa,GAAGrC,gBAAwB;QACnDuB;QACAR;QACAI;QACAmB,YAAY;IAChB;IACA,MAAM,CAACC,cA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V;gBACpBH,kBAAkBD;gBAClBG,eAAeH;gBACfI,OAAOyD,oBAAoB,CAAC,IAAMpF;gBAClC2B,OAAO0D,mBAAmB,CAAC;oBACvB,MAAM1D,OAAO2D,SAAS,CAAC,gCAAgCC,GAAG;gBAC9D;YACJ;;uBAIR,KAACvH;QAAOmG,WAAWhF,kBAAkBwC,MAAM;kBACvC,cAAA,KAACxD;;IAIT,qBACI,MAACE;QAAMwF,SAAQ;QAAaC,KAAK;QAAGJ,GAAG8B,KAAKC,GAAG,CAACxE,cAAcvB;QAAYgG,KAAKjF;QAAWS,KAAKA;QAAM,GAAGP,MAAM;;YACzGgD;YACAC;YACAI;YACAR;;;AAGb,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/code-editor/CodeEditor.tsx"],"sourcesContent":["import {\n Box,\n Center,\n Group,\n Input,\n InputWrapperProps,\n Loader,\n Space,\n Stack,\n StackProps,\n px,\n useMantineColorScheme,\n useMantineTheme,\n useProps,\n} from '@mantine/core';\nimport {useUncontrolled} from '@mantine/hooks';\nimport Editor, {Monaco, loader} from '@monaco-editor/react';\nimport {editor as monacoEditor} from 'monaco-editor';\nimport {FunctionComponent, useEffect, useRef, useState} from 'react';\n\nimport cx from 'clsx';\nimport {useParentHeight} from '../../hooks';\nimport {CopyToClipboard} from '../copyToClipboard';\nimport CodeEditorClasses from './CodeEditor.module.css';\nimport {XML} from './languages/xml';\nimport {Search} from './search';\ninterface CodeEditorProps\n extends Omit<\n InputWrapperProps,\n 'inputContainer' | 'inputWrapperOrder' | 'classNames' | 'styles' | 'vars' | 'onChange'\n >,\n Omit<StackProps, 'onChange'> {\n /**\n * The language syntax of the editor\n *\n * @default 'plaintext'\n */\n language?: 'plaintext' | 'json' | 'markdown' | 'python' | 'xml' | (string & unknown);\n /** Default value for uncontrolled input */\n defaultValue?: string;\n /** Value for controlled input */\n value?: string;\n /** onChange value for controlled input */\n onChange?(value: string): void;\n /** Called whenever the search icon is clicked */\n onSearch?(): void;\n /** Called whenever the copy icon is clicked */\n onCopy?(): void;\n /** Called whenever the code editor gets the focus */\n onFocus?(): void;\n /**\n * The minimal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height is too short, it will use this value as minimum.\n *\n * @default 300\n */\n minHeight?: number;\n /**\n * The maximal height of the CodeEditor (label and description included)\n *\n * By default the CodeEditor is adjusted to fill its parent height.\n * In the case where the parent height would be too high for your liking, you can use this prop to set a maximum.\n */\n maxHeight?: number;\n disabled?: boolean;\n /**\n * Defines how the monaco editor files will be loaded.\n * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).\n *\n * @default 'local'\n */\n monacoLoader?: 'cdn' | 'local';\n /**\n * Options to pass to the monaco editor.\n * Currently only supporting [`tabSize`](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html#tabSize).\n *\n */\n options?: Pick<monacoEditor.IStandaloneEditorConstructionOptions, 'tabSize'>;\n}\n\nconst defaultProps: Partial<CodeEditorProps> = {\n language: 'plaintext',\n monacoLoader: 'local',\n defaultValue: '',\n minHeight: 300,\n};\n\nexport const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {\n const {\n language,\n defaultValue,\n onChange,\n onCopy,\n onSearch,\n onFocus,\n value,\n label,\n required,\n labelProps,\n error,\n errorProps,\n description,\n descriptionProps,\n minHeight,\n maxHeight,\n disabled,\n monacoLoader,\n options: {tabSize} = {tabSize: 2},\n ...others\n } = useProps('CodeEditor', defaultProps, props);\n const [loaded, setLoaded] = useState(false);\n const [_value, handleChange] = useUncontrolled<string>({\n value,\n defaultValue,\n onChange,\n finalValue: '',\n });\n const [parentHeight, ref] = useParentHeight();\n const editorRef = useRef(null);\n const loadLocalMonaco = async () => {\n const monacoInstance = await import('monaco-editor');\n loader.config({monaco: monacoInstance});\n setLoaded(true);\n };\n\n const registerLanguages = (monaco: Monaco) => {\n if (monaco && language === 'xml') {\n XML.register(monaco);\n }\n };\n\n const registerThemes = (monaco: Monaco) => {\n monaco.editor.defineTheme('light-disabled', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.gray[2],\n },\n });\n monaco.editor.defineTheme('vs-dark-disabled', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': theme.colors.navy[7],\n },\n });\n };\n\n const handleSearch = () => {\n if (editorRef.current) {\n editorRef.current.focus();\n editorRef.current.trigger('editor', 'actions.find', '');\n onSearch?.();\n }\n };\n\n const [hasMonacoError, setHasMonacoError] = useState(false);\n const renderErrorOutline = !!error || hasMonacoError;\n const theme = useMantineTheme();\n const {colorScheme} = useMantineColorScheme();\n\n useEffect(() => {\n if (monacoLoader === 'local') {\n loadLocalMonaco();\n } else {\n setLoaded(true);\n }\n }, []);\n\n const handleValidate = (markers: monacoEditor.IMarker[]) => {\n setHasMonacoError(\n markers.some((marker) => marker.severity === loader.__getMonacoInstance().MarkerSeverity.Error),\n );\n };\n\n const _label = label ? (\n <Input.Label required={required} {...labelProps}>\n {label}\n </Input.Label>\n ) : null;\n\n const _description = description ? (\n <Input.Description {...descriptionProps}>{description}</Input.Description>\n ) : null;\n\n const _error = error ? (\n <Input.Error mt=\"xs\" {...errorProps}>\n {error}\n </Input.Error>\n ) : (\n <Space h=\"xs\" />\n );\n\n const _header =\n _label || _description ? (\n <Box>\n {_label}\n {_description}\n </Box>\n ) : null;\n\n const _buttons = (\n <Group justify=\"right\" gap={0}>\n <Search handleSearch={handleSearch} />\n <CopyToClipboard value={_value} onCopy={() => onCopy?.()} />\n </Group>\n );\n let editorTheme = colorScheme === 'light' ? 'light' : 'vs-dark';\n if (disabled) {\n editorTheme += '-disabled';\n }\n\n const _editor = loaded ? (\n <Box\n p=\"md\"\n pl=\"xs\"\n className={cx(\n CodeEditorClasses.editor,\n {[CodeEditorClasses.valid]: !renderErrorOutline},\n {[CodeEditorClasses.error]: renderErrorOutline},\n {[CodeEditorClasses.disabled]: disabled},\n )}\n data-testid=\"editor-wrapper\"\n >\n <Editor\n onValidate={handleValidate}\n defaultLanguage={language}\n theme={editorTheme}\n options={{\n minimap: {enabled: false},\n wordWrap: 'on',\n scrollBeyondLastLine: false,\n formatOnPaste: true,\n fontSize: px(theme.fontSizes.xs) as number,\n readOnly: disabled,\n tabSize,\n }}\n value={_value}\n onChange={handleChange}\n onMount={(editor, monaco) => {\n editorRef.current = editor;\n registerLanguages(monaco);\n registerThemes(monaco);\n editor.onDidFocusEditorText(() => onFocus?.());\n editor.onDidBlurEditorText(async () => {\n await editor.getAction('editor.action.formatDocument').run();\n });\n }}\n />\n </Box>\n ) : (\n <Center className={CodeEditorClasses.editor}>\n <Loader />\n </Center>\n );\n\n return (\n <Stack justify=\"flex-start\" gap={0} h={Math.max(parentHeight, minHeight)} mah={maxHeight} ref={ref} {...others}>\n {_header}\n {_buttons}\n {_editor}\n {_error}\n </Stack>\n );\n};\n"],"names":["Box","Center","Group","Input","Loader","Space","Stack","px","useMantineColorScheme","useMantineTheme","useProps","useUncontrolled","Editor","loader","useEffect","useRef","useState","cx","useParentHeight","CopyToClipboard","CodeEditorClasses","XML","Search","defaultProps","language","monacoLoader","defaultValue","minHeight","CodeEditor","props","onChange","onCopy","onSearch","onFocus","value","label","required","labelProps","error","errorProps","description","descriptionProps","maxHeight","disabled","options","tabSize","others","loaded","setLoaded","_value","handleChange","finalValue","parentHeight","ref","editorRef","loadLocalMonaco","monacoInstance","config","monaco","registerLanguages","register","registerThemes","editor","defineTheme","base","inherit","rules","colors","theme","gray","navy","handleSearch","current","focus","trigger","hasMonacoError","setHasMonacoError","renderErrorOutline","colorScheme","handleValidate","markers","some","marker","severity","__getMonacoInstance","MarkerSeverity","Error","_label","Label","_description","Description","_error","mt","h","_header","_buttons","justify","gap","editorTheme","_editor","p","pl","className","valid","data-testid","onValidate","defaultLanguage","minimap","enabled","wordWrap","scrollBeyondLastLine","formatOnPaste","fontSize","fontSizes","xs","readOnly","onMount","onDidFocusEditorText","onDidBlurEditorText","getAction","run","Math","max","mah"],"mappings":";AAAA,SACIA,GAAG,EACHC,MAAM,EACNC,KAAK,EACLC,KAAK,EAELC,MAAM,EACNC,KAAK,EACLC,KAAK,EAELC,EAAE,EACFC,qBAAqB,EACrBC,eAAe,EACfC,QAAQ,QACL,gBAAgB;AACvB,SAAQC,eAAe,QAAO,iBAAiB;AAC/C,OAAOC,UAAiBC,MAAM,QAAO,uBAAuB;AAE5D,SAA2BC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAO,QAAQ;AAErE,OAAOC,QAAQ,OAAO;AACtB,SAAQC,eAAe,QAAO,cAAc;AAC5C,SAAQC,eAAe,QAAO,qBAAqB;AACnD,OAAOC,uBAAuB,0BAA0B;AACxD,SAAQC,GAAG,QAAO,kBAAkB;AACpC,SAAQC,MAAM,QAAO,WAAW;AAyDhC,MAAMC,eAAyC;IAC3CC,UAAU;IACVC,cAAc;IACdC,cAAc;IACdC,WAAW;AACf;AAEA,OAAO,MAAMC,aAAiD,CAACC;IAC3D,MAAM,EACFL,QAAQ,EACRE,YAAY,EACZI,QAAQ,EACRC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,KAAK,EACLC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,KAAK,EACLC,UAAU,EACVC,WAAW,EACXC,gBAAgB,EAChBd,SAAS,EACTe,SAAS,EACTC,QAAQ,EACRlB,YAAY,EACZmB,SAAS,EAACC,OAAO,EAAC,GAAG;QAACA,SAAS;IAAC,CAAC,EACjC,GAAGC,QACN,GAAGpC,SAAS,cAAca,cAAcM;IACzC,MAAM,CAACkB,QAAQC,UAAU,GAAGhC,SAAS;IACrC,MAAM,CAACiC,QAAQC,aAAa,GAAGvC,gBAAwB;QACnDuB;QACAR;QACAI;QACAqB,YAAY;IAChB;IACA,MAAM,CAACC,cAAcC,IAAI,GAAGnC;IAC5B,MAAMoC,YAAYvC,OAAO;IACzB,MAAMwC,kBAAkB;QACpB,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B,OAAOwD,mBAAmB,CAAC;oBACvB,MAAMxD,OAAOyD,SAAS,CAAC,gCAAgCC,GAAG;gBAC9D;YACJ;;uBAIR,KAACvH;QAAOqG,WAAWlF,kBAAkB0C,MAAM;kBACvC,cAAA,KAAC1D;;IAIT,qBACI,MAACE;QAAM0F,SAAQ;QAAaC,KAAK;QAAGJ,GAAG4B,KAAKC,GAAG,CAACtE,cAAczB;QAAYgG,KAAKjF;QAAWW,KAAKA;QAAM,GAAGP,MAAM;;YACzGgD;YACAC;YACAI;YACAR;;;AAGb,EAAE"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ModalFactory as MantineModalFactory } from '@mantine/core';
|
|
2
|
-
import { ModalFooter } from './ModalFooter';
|
|
2
|
+
import { ModalFooter as PlasmaModalFooter } from './ModalFooter';
|
|
3
3
|
type PlasmaModalFactory = Omit<MantineModalFactory, 'staticComponents'> & {
|
|
4
4
|
staticComponents: MantineModalFactory['staticComponents'] & {
|
|
5
|
-
Footer: typeof
|
|
5
|
+
Footer: typeof PlasmaModalFooter;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export declare const Modal: import("@mantine/core").MantineComponent<PlasmaModalFactory>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,YAAY,IAAI,mBAAmB,EAEtC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../../../../src/components/modal/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGH,YAAY,IAAI,mBAAmB,EAEtC,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,eAAe,CAAC;AAG/D,KAAK,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,GAAG;IACtE,gBAAgB,EAAE,mBAAmB,CAAC,kBAAkB,CAAC,GAAG;QACxD,MAAM,EAAE,OAAO,iBAAiB,CAAC;KACpC,CAAC;CACL,CAAC;AAiBF,eAAO,MAAM,KAAK,8DAAc,CAAC;AAEjC,MAAM,MAAM,YAAY,GAAG,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/modal/Modal.tsx"],"sourcesContent":["import {\n factory,\n Modal as MantineModal,\n ModalFactory as MantineModalFactory,\n ModalProps as MantineModalProps,\n} from '@mantine/core';\nimport {ModalFooter
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/modal/Modal.tsx"],"sourcesContent":["import {\n factory,\n Modal as MantineModal,\n ModalFactory as MantineModalFactory,\n ModalProps as MantineModalProps,\n} from '@mantine/core';\nimport {ModalFooter as PlasmaModalFooter} from './ModalFooter';\n\n// Need to redeclare the factory to override and add footer to the props type\ntype PlasmaModalFactory = Omit<MantineModalFactory, 'staticComponents'> & {\n staticComponents: MantineModalFactory['staticComponents'] & {\n Footer: typeof PlasmaModalFooter;\n };\n};\n\nconst PlasmaModal = factory<PlasmaModalFactory>((props: MantineModalProps, ref) => (\n <MantineModal ref={ref} {...props} />\n));\n\nPlasmaModal.displayName = '@coveord/plasma-mantine/Modal';\nPlasmaModal.Root = MantineModal.Root;\nPlasmaModal.Body = MantineModal.Body;\nPlasmaModal.Overlay = MantineModal.Overlay;\nPlasmaModal.Content = MantineModal.Content;\nPlasmaModal.Header = MantineModal.Header;\nPlasmaModal.Title = MantineModal.Title;\nPlasmaModal.CloseButton = MantineModal.CloseButton;\nPlasmaModal.Stack = MantineModal.Stack;\nPlasmaModal.Footer = PlasmaModalFooter;\n\nexport const Modal = PlasmaModal;\n\nexport type ModalFactory = PlasmaModalFactory;\n"],"names":["factory","Modal","MantineModal","ModalFooter","PlasmaModalFooter","PlasmaModal","props","ref","displayName","Root","Body","Overlay","Content","Header","Title","CloseButton","Stack","Footer"],"mappings":";AAAA,SACIA,OAAO,EACPC,SAASC,YAAY,QAGlB,gBAAgB;AACvB,SAAQC,eAAeC,iBAAiB,QAAO,gBAAgB;AAS/D,MAAMC,cAAcL,QAA4B,CAACM,OAA0BC,oBACvE,KAACL;QAAaK,KAAKA;QAAM,GAAGD,KAAK;;AAGrCD,YAAYG,WAAW,GAAG;AAC1BH,YAAYI,IAAI,GAAGP,aAAaO,IAAI;AACpCJ,YAAYK,IAAI,GAAGR,aAAaQ,IAAI;AACpCL,YAAYM,OAAO,GAAGT,aAAaS,OAAO;AAC1CN,YAAYO,OAAO,GAAGV,aAAaU,OAAO;AAC1CP,YAAYQ,MAAM,GAAGX,aAAaW,MAAM;AACxCR,YAAYS,KAAK,GAAGZ,aAAaY,KAAK;AACtCT,YAAYU,WAAW,GAAGb,aAAaa,WAAW;AAClDV,YAAYW,KAAK,GAAGd,aAAac,KAAK;AACtCX,YAAYY,MAAM,GAAGb;AAErB,OAAO,MAAMH,QAAQI,YAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-url-synced-state.d.ts","sourceRoot":"","sources":["../../../../src/components/table/use-url-synced-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAoB,MAAM,OAAO,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"use-url-synced-state.d.ts","sourceRoot":"","sources":["../../../../src/components/table/use-url-synced-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,cAAc,EAAoB,MAAM,OAAO,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;AAuD7E,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACvC;;;;OAIG;IACH,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5B;;;;;;;;;OASG;IACH,UAAU,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IAC1D;;;;;;;;OAQG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9D;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAKD,eAAO,MAAM,iBAAiB,GAAI,CAAC,WAAW,wBAAwB,CAAC,CAAC,CAAC,8CAmDxE,CAAC"}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { useMemo, useState } from 'react';
|
|
2
|
+
const slice = Function.prototype.call.bind(Array.prototype.slice);
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Performs a nested search for '#/', to detect hash router urls and take the params of the hash in that case.
|
|
4
|
+
* Split a url into its parts.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @returns The
|
|
8
|
-
*/ const
|
|
6
|
+
* @param href The url to extract the parts from.
|
|
7
|
+
* @returns The separate parts, all are an empty string if not present.
|
|
8
|
+
*/ const extractParts = (href)=>slice(/^([^?#]*)(\?[^#]*|)(#[^?]*|)(\?.*|)$/.exec(href ?? ''), 1, 5);
|
|
9
|
+
/**
|
|
10
|
+
* The index of the search parameter to use, e.g. hashSearch for hash routes (hash starts with '#/').
|
|
11
|
+
*
|
|
12
|
+
* @param parts: The url parts, as returned by `extractParts`.
|
|
13
|
+
* @returns The index of the search parameter to use (1 or 3).
|
|
14
|
+
*/ const searchIndex = (parts)=>/^#\//.test(parts[2]) ? 3 : 1;
|
|
9
15
|
/**
|
|
10
16
|
* Read the **current** search params from `window.location`, with support for detecting React's HashRouter.
|
|
11
17
|
* Also returns a method that will yield the href (string) value, after any changes made on the params object.
|
|
12
18
|
*
|
|
13
19
|
* @returns The `URLSearchParams` instance, and a function that can be used to get an updated href.
|
|
14
20
|
*/ const getSearchParams = ()=>{
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
return new URLSearchParams(searchStart < 0 ? undefined : href.substring(searchStart));
|
|
21
|
+
const parts = extractParts(window.location.href);
|
|
22
|
+
return new URLSearchParams(parts[searchIndex(parts)]);
|
|
18
23
|
};
|
|
19
24
|
/**
|
|
20
25
|
* Apply the search params to the current location, using `replaceState` (no navigation history).
|
|
@@ -23,13 +28,12 @@ import { useMemo, useState } from 'react';
|
|
|
23
28
|
* @param params The parameters to apply.
|
|
24
29
|
*/ const applySearchParams = (params)=>{
|
|
25
30
|
const currentHref = window.location.href;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
window.history.replaceState(null, '', nextHref);
|
|
31
|
+
const parts = extractParts(currentHref);
|
|
32
|
+
const search = params.size > 0 ? `?${params.toString()}` : '';
|
|
33
|
+
const index = searchIndex(parts);
|
|
34
|
+
if (parts[index] !== search) {
|
|
35
|
+
parts[index] = search;
|
|
36
|
+
window.history.replaceState(null, '', parts.join(''));
|
|
33
37
|
}
|
|
34
38
|
};
|
|
35
39
|
const getInitialState = (options)=>options.initialState instanceof Function ? options.initialState() : options.initialState;
|
|
@@ -43,14 +47,18 @@ export const useUrlSyncedState = (options)=>{
|
|
|
43
47
|
const initialStateSerialized = useMemo(()=>{
|
|
44
48
|
const stateMap = new Map();
|
|
45
49
|
let initialize = null;
|
|
50
|
+
let needsApply = false;
|
|
46
51
|
for (const [key, value, alwaysEmit] of options.serializer(getInitialState(options))){
|
|
47
52
|
stateMap.set(key, value);
|
|
48
|
-
if (alwaysEmit && value) {
|
|
53
|
+
if (sync && alwaysEmit && value) {
|
|
49
54
|
initialize ?? (initialize = getSearchParams());
|
|
50
|
-
initialize.
|
|
55
|
+
if (!initialize.has(key)) {
|
|
56
|
+
needsApply = true;
|
|
57
|
+
initialize.set(key, value);
|
|
58
|
+
}
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
|
-
if (
|
|
61
|
+
if (needsApply) {
|
|
54
62
|
applySearchParams(initialize);
|
|
55
63
|
}
|
|
56
64
|
return stateMap;
|