sample-ui-component-library 0.0.8-dev → 0.0.10-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/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Editor/Editor.jsx +2 -2
- package/src/components/Editor/EditorReducer.js +21 -3
- package/src/components/Editor/Tabs/Gutter/Gutter.jsx +1 -1
- package/src/components/Editor/Tabs/Tab/Tab.jsx +1 -1
- package/src/components/FileBrowser/FileBrowser.jsx +7 -1
- package/src/components/FileBrowser/FileBrowserReducer.js +5 -2
- package/src/components/FileBrowser/TreeNode/TreeNode.jsx +1 -0
- package/src/components/FileBrowser/helper.js +0 -12
- package/src/stories/Editor.stories.js +11 -1
- package/src/stories/FileBrowser.stories.js +2 -4
package/package.json
CHANGED
|
@@ -37,8 +37,8 @@ export const Editor = forwardRef(({ }, ref) => {
|
|
|
37
37
|
dispatch({ type: "MOVE_TAB", payload: { tabId, newIndex } });
|
|
38
38
|
}, []);
|
|
39
39
|
|
|
40
|
-
const addTab = useCallback((tab) => {
|
|
41
|
-
dispatch({ type: "ADD_TAB", payload: tab });
|
|
40
|
+
const addTab = useCallback((tab, index) => {
|
|
41
|
+
dispatch({ type: "ADD_TAB", payload: { tab, index } });
|
|
42
42
|
}, []);
|
|
43
43
|
|
|
44
44
|
const setTabGroupId = useCallback((id) => {
|
|
@@ -8,11 +8,29 @@ export const editorReducer = (state, action) => {
|
|
|
8
8
|
switch (action.type) {
|
|
9
9
|
|
|
10
10
|
case "ADD_TAB": {
|
|
11
|
-
|
|
11
|
+
const { tab, index } = action.payload;
|
|
12
|
+
|
|
13
|
+
const tabInfo = state.tabs.find(obj => obj.uid === tab.uid);
|
|
14
|
+
if (tabInfo) {
|
|
15
|
+
console.warn(`Tab with id ${tabInfo.uid} already exists`);
|
|
16
|
+
return {
|
|
17
|
+
...state,
|
|
18
|
+
activeTab: tabInfo
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Insert tab at specific location if it was provided.
|
|
23
|
+
let tabs = [...state.tabs];
|
|
24
|
+
if (index !== undefined && index < state.tabs.length) {
|
|
25
|
+
tabs.splice(index, 0, tab);
|
|
26
|
+
} else {
|
|
27
|
+
tabs.push(tab);
|
|
28
|
+
}
|
|
29
|
+
|
|
12
30
|
return {
|
|
13
31
|
...state,
|
|
14
|
-
tabs:
|
|
15
|
-
activeTab:
|
|
32
|
+
tabs: tabs,
|
|
33
|
+
activeTab: tab
|
|
16
34
|
};
|
|
17
35
|
}
|
|
18
36
|
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
useCallback,
|
|
6
6
|
useContext,
|
|
7
7
|
useImperativeHandle,
|
|
8
|
+
useEffect,
|
|
8
9
|
} from "react";
|
|
9
10
|
import "./FileBrowser.scss";
|
|
10
11
|
|
|
@@ -20,13 +21,18 @@ import { fileBrowserReducer, initialState } from "./FileBrowserReducer";
|
|
|
20
21
|
*
|
|
21
22
|
* @return {JSX}
|
|
22
23
|
*/
|
|
23
|
-
export const FileBrowser = forwardRef(({
|
|
24
|
+
export const FileBrowser = forwardRef(({onSelectFile}, ref) => {
|
|
24
25
|
const [state, dispatch] = useReducer(fileBrowserReducer, initialState);
|
|
25
26
|
|
|
26
27
|
const addFileTree = useCallback((tree) => {
|
|
27
28
|
dispatch({ type: "ADD_FILE_TREE", payload: tree });
|
|
28
29
|
}, []);
|
|
29
30
|
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (state.selectedNode && state.selectedNode.type === "file") {
|
|
33
|
+
onSelectFile(state.selectedNode);
|
|
34
|
+
}
|
|
35
|
+
}, [state.selectedNode]);
|
|
30
36
|
|
|
31
37
|
const selectNode = useCallback((node) => {
|
|
32
38
|
dispatch({ type: "SELECT_NODE", payload: node });
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
setDefaultCollapsed,
|
|
3
3
|
collapseTree,
|
|
4
|
-
selectNode,
|
|
5
4
|
flattenTree,
|
|
6
5
|
} from "./helper";
|
|
7
6
|
|
|
8
7
|
export const initialState = {
|
|
9
8
|
tree: {},
|
|
10
9
|
flattenedTree: {},
|
|
10
|
+
selectedNode: null,
|
|
11
11
|
collapsedTree: [],
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -28,8 +28,10 @@ export const fileBrowserReducer = (state, action) => {
|
|
|
28
28
|
|
|
29
29
|
case "SELECT_NODE": {
|
|
30
30
|
const tree = [...state.flattenedTree];
|
|
31
|
+
let selectedNode;
|
|
31
32
|
tree.forEach((n) => {
|
|
32
33
|
if (n.uid === action.payload) {
|
|
34
|
+
selectedNode = n;
|
|
33
35
|
n.selected = true;
|
|
34
36
|
n.collapsed = !n.collapsed;
|
|
35
37
|
} else {
|
|
@@ -40,7 +42,8 @@ export const fileBrowserReducer = (state, action) => {
|
|
|
40
42
|
return {
|
|
41
43
|
...state,
|
|
42
44
|
flattenedTree: tree,
|
|
43
|
-
collapsedTree: collapsedTree
|
|
45
|
+
collapsedTree: collapsedTree,
|
|
46
|
+
selectedNode: selectedNode
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
}
|
|
@@ -8,7 +8,6 @@ export const setDefaultCollapsed = (tree) => {
|
|
|
8
8
|
return tree;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
/**
|
|
13
12
|
* Given a file tree, it flattens the tree into a list of nodes with the level of each node in the tree.
|
|
14
13
|
*
|
|
@@ -58,14 +57,3 @@ export const collapseTree = (tree) => {
|
|
|
58
57
|
}
|
|
59
58
|
return rows;
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Selects the given node and deselects all other nodes in the tree.
|
|
64
|
-
*/
|
|
65
|
-
export const selectNode = (tree, node) => {
|
|
66
|
-
tree.forEach((n) => {
|
|
67
|
-
n.selected = false;
|
|
68
|
-
});
|
|
69
|
-
node.selected = true;
|
|
70
|
-
node.collapsed = !node.collapsed;
|
|
71
|
-
}
|
|
@@ -51,6 +51,16 @@ const Template = (args) => {
|
|
|
51
51
|
editorRef.current.addTab(node);
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
const node = {
|
|
57
|
+
"name": "SAMPLE",
|
|
58
|
+
"type": "file",
|
|
59
|
+
"uid": "dissr-f6459410-1634-4dbc-8d76-35896822158d",
|
|
60
|
+
"content": "1234"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
editorRef.current.addTab(node,2);
|
|
54
64
|
}, []);
|
|
55
65
|
|
|
56
66
|
const onDragStart = (event) => {
|
|
@@ -71,7 +81,7 @@ const Template = (args) => {
|
|
|
71
81
|
return;
|
|
72
82
|
}
|
|
73
83
|
|
|
74
|
-
if (active.data.current.type === "
|
|
84
|
+
if (active.data.current.type === "EditorTab" && over.data.current.type === "EditorTabGutter") {
|
|
75
85
|
editorRef.current.moveTab(active.data.current.node.uid, over.data.current.index);
|
|
76
86
|
}
|
|
77
87
|
}
|
|
@@ -39,18 +39,16 @@ const Template = (args) => {
|
|
|
39
39
|
|
|
40
40
|
const [dragPreviewLabel, setDragPreviewLabel] = useState(<></>);
|
|
41
41
|
|
|
42
|
-
const
|
|
42
|
+
const onSelectFile = (selectedFile) => {
|
|
43
43
|
action('Selected Node:')(selectedFile);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
useEffect(() => {
|
|
47
|
-
updateArgs({
|
|
47
|
+
updateArgs({onSelectFile : onSelectFile});
|
|
48
48
|
}, []);
|
|
49
49
|
|
|
50
|
-
|
|
51
50
|
useLayoutEffect(() => {
|
|
52
51
|
fileBrowserRef.current.addFileTree(args.tree);
|
|
53
|
-
|
|
54
52
|
setTimeout(() => {
|
|
55
53
|
fileBrowserRef.current.selectNode("dir-f6459410-1634-4dbc-8d76-35896822158d");
|
|
56
54
|
}, 3000);
|