@nethru/ui 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Editor.js +57 -0
- package/dist/index.js +1 -0
- package/dist/samples/global.sample.css +11 -0
- package/package.json +10 -2
package/dist/Editor.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import CodeMirror from '@uiw/react-codemirror';
|
|
2
|
+
import { javascript } from '@codemirror/lang-javascript';
|
|
3
|
+
import { json } from '@codemirror/lang-json';
|
|
4
|
+
import { Box, Typography } from "@mui/material";
|
|
5
|
+
import { useMemo, useState } from "react";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
export default function Editor({
|
|
9
|
+
editable = true,
|
|
10
|
+
error = false,
|
|
11
|
+
helperText,
|
|
12
|
+
basicSetup,
|
|
13
|
+
extensions = [],
|
|
14
|
+
jsonFormat = false,
|
|
15
|
+
onUpdate,
|
|
16
|
+
style,
|
|
17
|
+
...props
|
|
18
|
+
}) {
|
|
19
|
+
const [focused, setFocused] = useState(false);
|
|
20
|
+
const styles = useMemo(() => {
|
|
21
|
+
return {
|
|
22
|
+
borderBottom: focused ? `3px solid ${error ? '#d32f2f' : '#1976d2'}` : '2px solid rgba(0, 0, 0, 0.42)'
|
|
23
|
+
};
|
|
24
|
+
}, [error, focused]);
|
|
25
|
+
const handleUpdate = viewUpdate => {
|
|
26
|
+
setFocused(viewUpdate.view.hasFocus);
|
|
27
|
+
if (onUpdate) onUpdate(viewUpdate);
|
|
28
|
+
};
|
|
29
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
30
|
+
children: [/*#__PURE__*/_jsx(CodeMirror, {
|
|
31
|
+
editable: editable,
|
|
32
|
+
extensions: [jsonFormat ? json() : javascript({
|
|
33
|
+
jsx: true
|
|
34
|
+
}), ...extensions],
|
|
35
|
+
basicSetup: {
|
|
36
|
+
...basicSetup,
|
|
37
|
+
highlightActiveLineGutter: false,
|
|
38
|
+
highlightActiveLine: editable
|
|
39
|
+
},
|
|
40
|
+
onUpdate: handleUpdate,
|
|
41
|
+
style: {
|
|
42
|
+
...style,
|
|
43
|
+
...styles
|
|
44
|
+
},
|
|
45
|
+
...props
|
|
46
|
+
}), focused && error && helperText && /*#__PURE__*/_jsx(Typography, {
|
|
47
|
+
sx: helperTextStyles,
|
|
48
|
+
children: helperText
|
|
49
|
+
})]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const helperTextStyles = {
|
|
53
|
+
color: '#d32f2f',
|
|
54
|
+
fontSize: 12,
|
|
55
|
+
ml: '14px',
|
|
56
|
+
mt: '3px'
|
|
57
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { default as Checkbox } from "./Checkbox";
|
|
|
8
8
|
export { default as ConfirmDialog } from "./ConfirmDialog";
|
|
9
9
|
export { default as DataGrid } from "./DataGrid";
|
|
10
10
|
export { default as Dialog } from "./Dialog";
|
|
11
|
+
export { default as Editor } from "./Editor";
|
|
11
12
|
export { default as FormLabel } from "./FormLabel";
|
|
12
13
|
export { default as Frame } from "./Frame";
|
|
13
14
|
export { default as GroupSelect } from "./GroupSelect";
|
|
@@ -45,4 +45,15 @@ html, body {
|
|
|
45
45
|
border: 1px solid #ccc;
|
|
46
46
|
border-radius: 3px;
|
|
47
47
|
padding: 8px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/* CodeMirror */
|
|
52
|
+
.cm-theme-light {
|
|
53
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
|
|
54
|
+
font-size: 14px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.cm-editor, .cm-editor.cm-focused {
|
|
58
|
+
outline: 1px solid #eaeaea;
|
|
48
59
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nethru/ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist"
|
|
7
7
|
],
|
|
8
8
|
"dependencies": {
|
|
9
|
+
"@codemirror/lang-javascript": "^6.2.1",
|
|
10
|
+
"@codemirror/lang-json": "^6.0.1",
|
|
9
11
|
"@emotion/react": "^11.11.1",
|
|
10
12
|
"@emotion/styled": "^11.11.0",
|
|
11
13
|
"@fontsource/roboto": "^5.0.8",
|
|
@@ -17,6 +19,7 @@
|
|
|
17
19
|
"@testing-library/jest-dom": "^5.17.0",
|
|
18
20
|
"@testing-library/react": "^13.4.0",
|
|
19
21
|
"@testing-library/user-event": "^13.5.0",
|
|
22
|
+
"@uiw/react-codemirror": "^4.21.21",
|
|
20
23
|
"days": "^1.1.1",
|
|
21
24
|
"immer": "^10.0.3",
|
|
22
25
|
"react": "^18.2.0",
|
|
@@ -33,7 +36,12 @@
|
|
|
33
36
|
},
|
|
34
37
|
"babel": {
|
|
35
38
|
"presets": [
|
|
36
|
-
[
|
|
39
|
+
[
|
|
40
|
+
"@babel/preset-react",
|
|
41
|
+
{
|
|
42
|
+
"runtime": "automatic"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
37
45
|
]
|
|
38
46
|
},
|
|
39
47
|
"eslintConfig": {
|