sample-ui-component-library 0.0.27-dev → 0.0.29-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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sample-ui-component-library",
3
- "version": "0.0.27-dev",
3
+ "version": "0.0.29-dev",
4
4
  "description": "A library which contains sample UI elements that can be used for populating layouts.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,7 +1,8 @@
1
1
  export const initialState = {
2
- tabs: [],
3
- activeTab: null,
4
- parentTabGroupId: null
2
+ uid: crypto.randomUUID(),
3
+ tabs: [],
4
+ activeTab: null,
5
+ parentTabGroupId: null
5
6
  };
6
7
 
7
8
  export const editorReducer = (state, action) => {
@@ -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.
@@ -56,9 +59,29 @@ export const MonacoInstance = ({ }) => {
56
59
  renderWhitespace: "none",
57
60
  wordWrap: "on",
58
61
  scrollBeyondLastLine: false,
59
- readOnly: true
62
+ readOnly: true,
63
+ automaticLayout: false
60
64
  }
61
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
+
62
85
  /**
63
86
  * Render the editor if there is an active tab, otherwise render a placeholder message.
64
87
  * @returns JSX
@@ -80,7 +103,7 @@ export const MonacoInstance = ({ }) => {
80
103
  }
81
104
 
82
105
  return (
83
- <div className="editor-container">
106
+ <div className="editor-container" ref={containerRef}>
84
107
  {renderEditor()}
85
108
  </div>
86
109
  )
@@ -19,10 +19,10 @@ export const Tabs = () => {
19
19
  const [tabsList, setTabsList] = useState();
20
20
 
21
21
  useEffect(() => {
22
- if (state.tabs?.length >= 0 && state.parentTabGroupId != null) {
23
- drawTabs(state.tabs, state.parentTabGroupId);
22
+ if (state.tabs?.length >= 0) {
23
+ drawTabs(state.tabs, state.uid);
24
24
  }
25
- }, [state.tabs, state.parentTabGroupId]);
25
+ }, [state.tabs, state.uid]);
26
26
 
27
27
  /**
28
28
  * Draw the tabs provided in the tabs info. This includes the gutters
@@ -1,9 +1,7 @@
1
1
  import { setDefaultCollapsed, collapseTree, flattenTree } from "./helper";
2
2
 
3
- //TODO: I should set a unique id for each reducer state and use it
4
- // for all the ids of the components to make them unique. I could
5
- // also manually set the ID like I do in the editor reducer.
6
3
  export const initialState = {
4
+ uid: crypto.randomUUID(),
7
5
  tree: {},
8
6
  flattenedTree: {},
9
7
  selectedNode: null,
@@ -18,19 +18,20 @@ export const Tree = ({}) => {
18
18
 
19
19
  useEffect(() => {
20
20
  if(state.collapsedTree && state.collapsedTree.length > 0) {
21
- drawTree(state.collapsedTree);
21
+ drawTree(state.collapsedTree, state.uid);
22
22
  }
23
23
  }, [state.collapsedTree]);
24
24
 
25
25
  /**
26
26
  * Draws the tree given the nodes and the collapsed state of each node.
27
27
  */
28
- const drawTree = (collapsedTree) => {
28
+ const drawTree = (collapsedTree, parentId) => {
29
29
  const rows = [];
30
30
  collapsedTree.forEach((node) => {
31
31
  rows.push(
32
32
  <TreeNode
33
- key={node.uid}
33
+ key={parentId + "-" + node.uid}
34
+ parentId={parentId}
34
35
  node={node}
35
36
  id={"tree-node-" + node.uid}
36
37
  />,
@@ -15,12 +15,13 @@ import { useCallback } from "react";
15
15
  /**
16
16
  * Renders a single node in the file tree.
17
17
  */
18
- export const TreeNode = ({ id, node }) => {
18
+ export const TreeNode = ({ id, parentId, node }) => {
19
19
  const { attributes, listeners, setNodeRef, transform } = useDraggable(
20
20
  {
21
21
  id,
22
22
  data: {
23
23
  type: "FileTreeNode",
24
+ parentId: parentId,
24
25
  node: node,
25
26
  preview: <TreeNodePreview node={node} />
26
27
  }