@nethru/ui 1.0.52 → 1.0.54
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 +12 -2
- package/dist/sidebar/MenuTree.js +2 -2
- package/dist/sidebar/SidebarContext.js +6 -2
- package/package.json +1 -1
package/dist/Editor.js
CHANGED
|
@@ -3,11 +3,12 @@ import { javascript } from '@codemirror/lang-javascript';
|
|
|
3
3
|
import { json } from '@codemirror/lang-json';
|
|
4
4
|
import { EditorView } from "@codemirror/view";
|
|
5
5
|
import { Box, Typography } from "@mui/material";
|
|
6
|
-
import { useMemo, useState } from "react";
|
|
6
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
9
|
export default function Editor({
|
|
10
10
|
readOnly = false,
|
|
11
|
+
value,
|
|
11
12
|
error = false,
|
|
12
13
|
helperText,
|
|
13
14
|
basicSetup,
|
|
@@ -17,18 +18,27 @@ export default function Editor({
|
|
|
17
18
|
style,
|
|
18
19
|
...props
|
|
19
20
|
}) {
|
|
21
|
+
const ref = useRef();
|
|
22
|
+
const [content, setContent] = useState('');
|
|
20
23
|
const [focused, setFocused] = useState(false);
|
|
21
24
|
const styles = useMemo(() => {
|
|
22
25
|
return {
|
|
26
|
+
maxWidth: ref.current ? `${ref.current.offsetWidth}px` : 'unset',
|
|
23
27
|
borderBottom: focused ? `3px solid ${error ? '#d32f2f' : '#1976d2'}` : `${!readOnly ? '2px' : '0px'} solid rgba(0, 0, 0, 0.42)`
|
|
24
28
|
};
|
|
25
|
-
|
|
29
|
+
// eslint-disable-next-line
|
|
30
|
+
}, [readOnly, error, focused, ref.current]);
|
|
26
31
|
const handleUpdate = viewUpdate => {
|
|
27
32
|
setFocused(viewUpdate.view.hasFocus);
|
|
28
33
|
if (onUpdate) onUpdate(viewUpdate);
|
|
29
34
|
};
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
setTimeout(() => setContent(value), 100);
|
|
37
|
+
}, [value]);
|
|
30
38
|
return /*#__PURE__*/_jsxs(Box, {
|
|
39
|
+
ref: ref,
|
|
31
40
|
children: [/*#__PURE__*/_jsx(CodeMirror, {
|
|
41
|
+
value: content,
|
|
32
42
|
editable: !readOnly,
|
|
33
43
|
extensions: [jsonFormat ? json() : javascript({
|
|
34
44
|
jsx: true
|
package/dist/sidebar/MenuTree.js
CHANGED
|
@@ -24,7 +24,7 @@ export default function MenuTree({
|
|
|
24
24
|
backgroundColor: 'transparent'
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
const
|
|
27
|
+
const navigate = useNavigate();
|
|
28
28
|
const {
|
|
29
29
|
states,
|
|
30
30
|
dispatch
|
|
@@ -40,7 +40,7 @@ export default function MenuTree({
|
|
|
40
40
|
hasChildren: hasChildren(event.target)
|
|
41
41
|
});
|
|
42
42
|
const node = getNode(ids);
|
|
43
|
-
if (node && node.href)
|
|
43
|
+
if (node && node.href) navigate(node.href instanceof Array ? node.href[0] : node.href);
|
|
44
44
|
};
|
|
45
45
|
const handleToggle = (event, ids) => {
|
|
46
46
|
dispatch({
|
|
@@ -91,7 +91,7 @@ function updateActiveItems(draft, menu, href) {
|
|
|
91
91
|
function updateActiveSection(sections) {
|
|
92
92
|
if (!sections) return;
|
|
93
93
|
for (let section of sections) {
|
|
94
|
-
if (
|
|
94
|
+
if (startsWith(section.href)) {
|
|
95
95
|
draft.activeSecondaryItem = section.id;
|
|
96
96
|
return true;
|
|
97
97
|
}
|
|
@@ -104,7 +104,7 @@ function updateActiveItems(draft, menu, href) {
|
|
|
104
104
|
function updateActiveSubmenuItems(id, submenu) {
|
|
105
105
|
if (!submenu) return;
|
|
106
106
|
for (let item of submenu) {
|
|
107
|
-
if (
|
|
107
|
+
if (startsWith(item.href)) {
|
|
108
108
|
if (!(id in draft.menuTrees)) draft.menuTrees[id] = emptyState();
|
|
109
109
|
draft.activeSecondaryItem = item.id;
|
|
110
110
|
return true;
|
|
@@ -115,4 +115,8 @@ function updateActiveItems(draft, menu, href) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
+
function startsWith(hrefs) {
|
|
119
|
+
const menuHrefs = hrefs instanceof Array ? hrefs : [hrefs];
|
|
120
|
+
return menuHrefs.some(menuHref => href.startsWith(menuHref));
|
|
121
|
+
}
|
|
118
122
|
}
|