sample-ui-component-library 0.0.26-dev → 0.0.28-dev
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/package.json
CHANGED
|
Binary file
|
|
@@ -14,6 +14,8 @@ export const MonacoInstance = ({ }) => {
|
|
|
14
14
|
|
|
15
15
|
const editorRef = useRef(null);
|
|
16
16
|
const content = useRef();
|
|
17
|
+
const containerRef = useRef(null);
|
|
18
|
+
const frameRef = useRef(0);
|
|
17
19
|
|
|
18
20
|
useEffect(() => {
|
|
19
21
|
if (state.activeTab) {
|
|
@@ -41,6 +43,7 @@ export const MonacoInstance = ({ }) => {
|
|
|
41
43
|
if (content?.current) {
|
|
42
44
|
editorRef.current.setValue(content.current);
|
|
43
45
|
}
|
|
46
|
+
editorRef.current.layout();
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
// Editor options for Monaco Editor.
|
|
@@ -60,6 +63,25 @@ export const MonacoInstance = ({ }) => {
|
|
|
60
63
|
automaticLayout: false
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
// Disable automatic layout and Manually layout the editor to avoid resize observer loops
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!containerRef.current) return;
|
|
69
|
+
|
|
70
|
+
const ro = new ResizeObserver(() => {
|
|
71
|
+
cancelAnimationFrame(frameRef.current);
|
|
72
|
+
frameRef.current = requestAnimationFrame(() => {
|
|
73
|
+
editorRef.current?.layout();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
ro.observe(containerRef.current);
|
|
78
|
+
|
|
79
|
+
return () => {
|
|
80
|
+
cancelAnimationFrame(frameRef.current);
|
|
81
|
+
ro.disconnect();
|
|
82
|
+
};
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
63
85
|
/**
|
|
64
86
|
* Render the editor if there is an active tab, otherwise render a placeholder message.
|
|
65
87
|
* @returns JSX
|
|
@@ -81,7 +103,7 @@ export const MonacoInstance = ({ }) => {
|
|
|
81
103
|
}
|
|
82
104
|
|
|
83
105
|
return (
|
|
84
|
-
<div className="editor-container">
|
|
106
|
+
<div className="editor-container" ref={containerRef}>
|
|
85
107
|
{renderEditor()}
|
|
86
108
|
</div>
|
|
87
109
|
)
|