ui-layout-manager-dev 0.0.18 → 0.0.20

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.
Files changed (34) hide show
  1. package/dist/cjs/index.js +3 -3
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/esm/Worker/LayoutWorker.js +38 -1
  4. package/dist/esm/index.js +3 -3
  5. package/dist/esm/index.js.map +1 -1
  6. package/package.json +3 -3
  7. package/src/components/LayoutManager/Components/Container/Container.jsx +1 -1
  8. package/src/components/LayoutManager/Components/HandleBar/HandleBar.jsx +6 -16
  9. package/src/components/LayoutManager/Components/LazyLoader/LazyLoader.js +74 -9
  10. package/src/components/LayoutManager/Components/LazyLoader/LazyLoader.scss +38 -1
  11. package/src/components/LayoutManager/Components/LazyLoader/MenuBar/MenuBar.js +40 -0
  12. package/src/components/LayoutManager/Components/LazyLoader/MenuBar/MenuBar.scss +22 -0
  13. package/src/components/LayoutManager/Components/LazyLoader/Tabs/Tabs.js +51 -0
  14. package/src/components/LayoutManager/Components/LazyLoader/Tabs/Tabs.scss +34 -0
  15. package/src/components/LayoutManager/Components/RootContainer/DragController.js +79 -0
  16. package/src/components/LayoutManager/Components/RootContainer/RootContainer.jsx +21 -21
  17. package/src/components/LayoutManager/Components/RootContainer/RootContainer.scss +1 -0
  18. package/src/components/LayoutManager/Controller/LAYOUT_WORKER_PROTOCOL.js +2 -1
  19. package/src/components/LayoutManager/Controller/LayoutController.js +14 -0
  20. package/src/components/LayoutManager/Controller/LayoutEventController.js +55 -0
  21. package/src/components/LayoutManager/Controller/Worker/HandleRulesEnforcer.js +4 -0
  22. package/src/components/LayoutManager/Controller/Worker/LayoutEditor.js +29 -0
  23. package/src/components/LayoutManager/Controller/Worker/LayoutWorker.js +3 -0
  24. package/src/components/LayoutManager/LayoutManager.jsx +5 -5
  25. package/src/components/LayoutManager/Providers/LayoutEventProvider.js +55 -0
  26. package/src/components/LayoutManager/index.js +1 -2
  27. package/src/stories/LayoutManager.stories.js +17 -0
  28. package/src/stories/layouts/vsCode/workbench.json +22 -5
  29. package/src/stories/layouts/vsCode/workbench2.json +176 -0
  30. package/src/stories/layouts/vsCode/workbench3.json +176 -0
  31. package/src/stories/sample_components/fileeditor/FileEditor.jsx +45 -21
  32. package/src/stories/sample_components/fileeditor/helper.js +22 -0
  33. package/src/stories/sample_components/filetree/FileTree.jsx +11 -5
  34. package/src/components/LayoutManager/Providers/DragProvider.js +0 -87
@@ -83,6 +83,7 @@ export class HandleRulesEnforcer {
83
83
  const sibling = this.getSiblingProps(this.sibling1.id);
84
84
  if ("min" in sibling.size) {
85
85
  this.args.style["min-width"] = sibling.size.min.value + sibling.size.min.unit;
86
+ this.args.style["width"] = sibling.size.min.value + sibling.size.min.unit;
86
87
  }
87
88
  this.sibling1.hidden = false;
88
89
  this.activeSibling = this.sibling1.id;
@@ -99,6 +100,7 @@ export class HandleRulesEnforcer {
99
100
  const sibling = this.getSiblingProps(this.sibling2.id);
100
101
  if ("min" in sibling.size) {
101
102
  this.args.style["min-width"] = sibling.size.min.value + sibling.size.min.unit;
103
+ this.args.style["width"] = sibling.size.min.value + sibling.size.min.unit;
102
104
  }
103
105
  this.sibling2.hidden = false;
104
106
  this.activeSibling = this.sibling2.id;
@@ -131,6 +133,7 @@ export class HandleRulesEnforcer {
131
133
  const sibling = this.getSiblingProps(this.sibling1.id);
132
134
  if ("min" in sibling.size) {
133
135
  this.args.style["min-height"] = sibling.size.min.value + sibling.size.min.unit;
136
+ this.args.style["height"] = sibling.size.min.value + sibling.size.min.unit;
134
137
  }
135
138
  this.sibling1.hidden = false;
136
139
  this.activeSibling = this.sibling1.id;
@@ -148,6 +151,7 @@ export class HandleRulesEnforcer {
148
151
  const sibling = this.getSiblingProps(this.sibling2.id);
149
152
  if ("min" in sibling.size) {
150
153
  this.args.style["min-height"] = sibling.size.min.value + sibling.size.min.unit;
154
+ this.args.style["height"] = sibling.size.min.value + sibling.size.min.unit;
151
155
  }
152
156
  this.sibling2.hidden = false;
153
157
  this.activeSibling = this.sibling2.id;
@@ -180,4 +180,33 @@ export class LayoutEditor {
180
180
  }
181
181
  }
182
182
  }
183
+
184
+ /**
185
+ * Invoke a specific action on the given id.
186
+ * @param {Object} args
187
+ */
188
+ invokeAction({id, action, args}) {
189
+ const props = this.getProps(this.ldf.containers[id].parent);
190
+
191
+ const style = {};
192
+ if (action === "close") {
193
+ style["min-" + props["dynamic"]] = 0;
194
+ style["display"] = "none";
195
+ } else if (action === "open") {
196
+ style["display"] = "flex";
197
+ }
198
+
199
+ this.transformations.push(
200
+ {
201
+ id: id,
202
+ type: TRANSFORMATION_TYPES.UPDATE_SIZE,
203
+ args: {style: style}
204
+ }
205
+ );
206
+ postMessage({
207
+ type: LAYOUT_WORKER_PROTOCOL.TRANSFORMATIONS,
208
+ data: this.transformations
209
+ });
210
+ this.transformations = [];
211
+ }
183
212
  };
@@ -25,6 +25,9 @@ self.onmessage = function (e) {
25
25
  case LAYOUT_WORKER_PROTOCOL.MOVE_HANDLE_BAR:
26
26
  editor.moveHandleBar(args.metadata);
27
27
  break;
28
+ case LAYOUT_WORKER_PROTOCOL.INVOKE_ACTION:
29
+ editor.invokeAction(args);
30
+ break;
28
31
  default:
29
32
  break;
30
33
  }
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { RootContainer } from "./Components/RootContainer/RootContainer";
4
4
  import ComponentRegistryContext from "./Providers/ComponentRegistryContext";
5
5
  import { LayoutControllerProvider } from "./Providers/LayoutProvider";
6
- import { DragProvider } from "./Providers/DragProvider";
6
+ import { LayoutEventProvider } from "./Providers/LayoutEventProvider";
7
7
 
8
8
  import "./LayoutManager.scss";
9
9
 
@@ -19,13 +19,13 @@ export const LayoutManager = ({ldf, registry}) => {
19
19
 
20
20
 
21
21
  return (
22
- <DragProvider>
23
- <LayoutControllerProvider layout={ldf}>
22
+ <LayoutControllerProvider layout={ldf}>
23
+ <LayoutEventProvider>
24
24
  <ComponentRegistryContext.Provider value={registry}>
25
25
  <RootContainer/>
26
26
  </ComponentRegistryContext.Provider>
27
- </LayoutControllerProvider>
28
- </DragProvider>
27
+ </LayoutEventProvider>
28
+ </LayoutControllerProvider>
29
29
  );
30
30
  }
31
31
 
@@ -0,0 +1,55 @@
1
+ import React, { createContext, useContext, useEffect, useMemo, useRef } from "react";
2
+ import LayoutEventController from "../Controller/LayoutEventController";
3
+
4
+ const LayoutEventContext = createContext(null);
5
+
6
+ export function LayoutEventProvider({ children }) {
7
+ const controller = useMemo(() => new LayoutEventController(), []);
8
+
9
+ return (
10
+ <LayoutEventContext.Provider value={controller}>
11
+ {children}
12
+ </LayoutEventContext.Provider>
13
+ );
14
+ }
15
+
16
+ /**
17
+ * Hook to publish an event.
18
+ * @returns
19
+ */
20
+ export function useLayoutEventPublisher() {
21
+ const controller = useContext(LayoutEventContext);
22
+
23
+ if (!controller) {
24
+ throw new Error("useLayoutPublisher must be used within LayoutEventProvider");
25
+ }
26
+
27
+ // Return publish that is bound to the controller
28
+ return controller.publish.bind(controller);
29
+ }
30
+
31
+ /**
32
+ * Hook to subscribe to event.
33
+ * @param {String} type
34
+ * @param {Function} handler
35
+ */
36
+ export function useLayoutEventSubscription(type, handler) {
37
+ const controller = useContext(LayoutEventContext);
38
+ const handlerRef = useRef(handler);
39
+
40
+ // Handler is saved in ref and passed into the subscription, this causes
41
+ // the publisher to invoke the handler and notify the subscriber
42
+ handlerRef.current = handler;
43
+
44
+ useEffect(() => {
45
+ if (!controller) {
46
+ throw new Error("useLayoutSubscription must be used within LayoutEventProvider");
47
+ }
48
+
49
+ // controller.subscribe returns unsubscribe function, so it is called automatically
50
+ // when the component is unmounted
51
+ return controller.subscribe(type, (event) => {
52
+ handlerRef.current(event);
53
+ });
54
+ }, [controller, type]);
55
+ }
@@ -1,2 +1 @@
1
- export * from "./LayoutManager.jsx"
2
- export {useDragState} from "./Providers/DragProvider.js"
1
+ export * from "./LayoutManager.jsx"
@@ -4,6 +4,8 @@ import { LayoutManager } from "../components/LayoutManager";
4
4
  import defaultLayoutJSON from "./layouts/vsCode/default.json";
5
5
  import sample1JSON from "./layouts/vsCode/sample1.json";
6
6
  import workbenchJSON from "./layouts/vsCode/workbench.json";
7
+ import workbench2JSON from "./layouts/vsCode/workbench2.json";
8
+ import workbench3JSON from "./layouts/vsCode/workbench3.json";
7
9
 
8
10
  import "./LayoutManager.stories.scss";
9
11
 
@@ -74,3 +76,18 @@ workbench.args = {
74
76
  ldf: workbenchJSON
75
77
  }
76
78
 
79
+
80
+ export const workbench2 = Template.bind({})
81
+
82
+ workbench2.args = {
83
+ ldf: workbench2JSON
84
+ }
85
+
86
+
87
+ export const workbench3 = Template.bind({})
88
+
89
+ workbench3.args = {
90
+ ldf: workbench3JSON
91
+ }
92
+
93
+
@@ -39,8 +39,7 @@
39
39
  "containerId": "sidebar",
40
40
  "type": "container",
41
41
  "size": { "initial": { "value": 50, "unit": "px", "type": "fixed" }},
42
- "collapse": { "value": 400, "condition": "lessThan", "relative": "parent" },
43
- "showHandlebar": true
42
+ "collapse": { "value": 400, "condition": "lessThan", "relative": "parent" }
44
43
  },
45
44
  {
46
45
  "containerId": "contentContainer",
@@ -78,7 +77,20 @@
78
77
  },
79
78
  "terminal": {
80
79
  "id": "terminal",
81
- "component": "Flow",
80
+ "tabsBar": {
81
+ "tabs": [
82
+ {
83
+ "name": "Flow",
84
+ "component": "Flow"
85
+ },
86
+ {
87
+ "name": "FileTree",
88
+ "component": "FileTree"
89
+ }
90
+ ],
91
+ "showClose": true,
92
+ "closeContainerId": "terminal"
93
+ },
82
94
  "background": "#252526"
83
95
  },
84
96
  "content": {
@@ -91,9 +103,9 @@
91
103
  "containerId": "menuContainer",
92
104
  "type": "container",
93
105
  "size": {
94
- "initial": { "value": 400, "unit": "px", "type": "fixed" },
106
+ "initial": { "value": 250, "unit": "px", "type": "fixed" },
95
107
  "min": { "value": 200, "unit": "px"},
96
- "max": { "value": 500, "unit": "px"}
108
+ "max": { "value": 400, "unit": "px"}
97
109
  },
98
110
  "collapse": { "value": 700, "condition": "lessThan", "relative": "parent" }
99
111
  },
@@ -133,6 +145,11 @@
133
145
  "fileTabsContainer": {
134
146
  "id": "fileTabsContainer",
135
147
  "component": "FileTree",
148
+ "menuBar": {
149
+ "showClose": true,
150
+ "closeContainerId": "menuContainer",
151
+ "title": "EXPLORER"
152
+ },
136
153
  "background": "#1e1e1e"
137
154
  },
138
155
  "editorContainer": {
@@ -0,0 +1,176 @@
1
+ {
2
+ "title": "Workbench Layout Configuration A",
3
+ "layoutRoot": "root",
4
+ "containers": {
5
+ "root": {
6
+ "id": "root",
7
+ "type": "split",
8
+ "orientation": "vertical",
9
+ "children": [
10
+ {
11
+ "containerId": "header",
12
+ "type": "container",
13
+ "size": { "initial": { "value": 25, "unit": "px", "type": "fixed" }}
14
+ },
15
+ {
16
+ "containerId": "mainBody",
17
+ "type": "container",
18
+ "size": { "initial": { "type": "fill" }}
19
+ },
20
+ {
21
+ "containerId": "footer",
22
+ "type": "container",
23
+ "size": { "initial": { "value": 25, "unit": "px", "type": "fixed" }},
24
+ "collapse": { "value": 400, "condition": "lessThan", "relative": "parent" }
25
+ }
26
+ ]
27
+ },
28
+ "header": {
29
+ "id": "header",
30
+ "background": "#3c3c3c"
31
+ },
32
+ "mainBody": {
33
+ "id": "mainBody",
34
+ "background": "#3c3c3c",
35
+ "type": "split",
36
+ "orientation": "horizontal",
37
+ "children": [
38
+ {
39
+ "containerId": "sidebar",
40
+ "type": "container",
41
+ "size": { "initial": { "value": 50, "unit": "px", "type": "fixed" }},
42
+ "collapse": { "value": 400, "condition": "lessThan", "relative": "parent" }
43
+ },
44
+ {
45
+ "containerId": "contentContainer",
46
+ "type": "container",
47
+ "size": { "initial": { "type": "fill" }}
48
+ }
49
+ ]
50
+ },
51
+ "contentContainer": {
52
+ "id": "contentContainer",
53
+ "background": "#3c3c3c",
54
+ "type": "split",
55
+ "orientation": "vertical",
56
+ "children": [
57
+ {
58
+ "containerId": "content",
59
+ "type": "container",
60
+ "size": { "initial": { "type": "fill" }}
61
+ },
62
+ {
63
+ "type": "handleBar",
64
+ "sibling1": "content",
65
+ "sibling2": "terminal"
66
+ },
67
+ {
68
+ "containerId": "terminal",
69
+ "type": "container",
70
+ "size": {
71
+ "initial": { "value": 200, "unit": "px", "type": "fixed" },
72
+ "min": { "value": 100, "unit": "px"}
73
+ },
74
+ "collapse": { "value": 500, "condition": "lessThan", "relative": "parent" }
75
+ }
76
+ ]
77
+ },
78
+ "terminal": {
79
+ "id": "terminal",
80
+ "tabsBar": {
81
+ "tabs": [
82
+ {
83
+ "name": "Flow",
84
+ "component": "Flow"
85
+ },
86
+ {
87
+ "name": "FileTree",
88
+ "component": "FileTree"
89
+ }
90
+ ],
91
+ "showClose": true,
92
+ "closeContainerId": "terminal"
93
+ },
94
+ "background": "#252526"
95
+ },
96
+ "content": {
97
+ "id": "content",
98
+ "background": "#007acc",
99
+ "type": "split",
100
+ "orientation": "horizontal",
101
+ "children": [
102
+ {
103
+ "containerId": "menuContainer",
104
+ "type": "container",
105
+ "size": {
106
+ "initial": { "value": 250, "unit": "px", "type": "fixed" },
107
+ "min": { "value": 200, "unit": "px"},
108
+ "max": { "value": 400, "unit": "px"}
109
+ },
110
+ "collapse": { "value": 700, "condition": "lessThan", "relative": "parent" }
111
+ },
112
+ {
113
+ "type": "handleBar",
114
+ "sibling1": "menuContainer",
115
+ "sibling2": "editorContainer"
116
+ },
117
+ {
118
+ "containerId": "editorContainer",
119
+ "type": "container",
120
+ "size": { "initial": { "type": "fill" }}
121
+ },
122
+ {
123
+ "type": "handleBar",
124
+ "sibling1": "editorContainer",
125
+ "sibling2": "editorContainer2"
126
+ },
127
+ {
128
+ "containerId": "editorContainer2",
129
+ "type": "container",
130
+ "size": { "initial": { "type": "fill" }}
131
+ }
132
+ ]
133
+ },
134
+ "footer": {
135
+ "id": "footer",
136
+ "background": "#007acc"
137
+ },
138
+ "sidebar": {
139
+ "id": "sidebar",
140
+ "background": "#333"
141
+ },
142
+ "menuContainer": {
143
+ "id": "menuContainer",
144
+ "background": "#252526",
145
+ "type": "split",
146
+ "orientation": "vertical",
147
+ "children": [
148
+ {
149
+ "containerId": "fileTabsContainer",
150
+ "type": "container",
151
+ "size": { "initial": { "type": "fill" }}
152
+ }
153
+ ]
154
+ },
155
+ "fileTabsContainer": {
156
+ "id": "fileTabsContainer",
157
+ "component": "FileTree",
158
+ "menuBar": {
159
+ "showClose": true,
160
+ "closeContainerId": "menuContainer",
161
+ "title": "EXPLORER"
162
+ },
163
+ "background": "#1e1e1e"
164
+ },
165
+ "editorContainer": {
166
+ "id": "editorContainer",
167
+ "component": "FileEditor",
168
+ "background": "#1e1e1e"
169
+ },
170
+ "editorContainer2": {
171
+ "id": "editorContainer2",
172
+ "component": "FileEditor",
173
+ "background": "#1e1e1e"
174
+ }
175
+ }
176
+ }
@@ -0,0 +1,176 @@
1
+ {
2
+ "title": "Workbench Layout Configuration A",
3
+ "layoutRoot": "root",
4
+ "containers": {
5
+ "root": {
6
+ "id": "root",
7
+ "type": "split",
8
+ "orientation": "vertical",
9
+ "children": [
10
+ {
11
+ "containerId": "header",
12
+ "type": "container",
13
+ "size": { "initial": { "value": 25, "unit": "px", "type": "fixed" }}
14
+ },
15
+ {
16
+ "containerId": "mainBody",
17
+ "type": "container",
18
+ "size": { "initial": { "type": "fill" }}
19
+ },
20
+ {
21
+ "containerId": "footer",
22
+ "type": "container",
23
+ "size": { "initial": { "value": 25, "unit": "px", "type": "fixed" }},
24
+ "collapse": { "value": 400, "condition": "lessThan", "relative": "parent" }
25
+ }
26
+ ]
27
+ },
28
+ "header": {
29
+ "id": "header",
30
+ "background": "#3c3c3c"
31
+ },
32
+ "mainBody": {
33
+ "id": "mainBody",
34
+ "background": "#3c3c3c",
35
+ "type": "split",
36
+ "orientation": "horizontal",
37
+ "children": [
38
+ {
39
+ "containerId": "sidebar",
40
+ "type": "container",
41
+ "size": { "initial": { "value": 50, "unit": "px", "type": "fixed" }},
42
+ "collapse": { "value": 400, "condition": "lessThan", "relative": "parent" }
43
+ },
44
+ {
45
+ "containerId": "contentContainer",
46
+ "type": "container",
47
+ "size": { "initial": { "type": "fill" }}
48
+ }
49
+ ]
50
+ },
51
+ "contentContainer": {
52
+ "id": "contentContainer",
53
+ "background": "#3c3c3c",
54
+ "type": "split",
55
+ "orientation": "vertical",
56
+ "children": [
57
+ {
58
+ "containerId": "content",
59
+ "type": "container",
60
+ "size": { "initial": { "type": "fill" }}
61
+ },
62
+ {
63
+ "type": "handleBar",
64
+ "sibling1": "content",
65
+ "sibling2": "terminal"
66
+ },
67
+ {
68
+ "containerId": "terminal",
69
+ "type": "container",
70
+ "size": {
71
+ "initial": { "value": 300, "unit": "px", "type": "fixed" },
72
+ "min": { "value": 100, "unit": "px"}
73
+ },
74
+ "collapse": { "value": 500, "condition": "lessThan", "relative": "parent" }
75
+ }
76
+ ]
77
+ },
78
+ "terminal": {
79
+ "id": "terminal",
80
+ "tabsBar": {
81
+ "tabs": [
82
+ {
83
+ "name": "Flow",
84
+ "component": "Flow"
85
+ },
86
+ {
87
+ "name": "FileTree",
88
+ "component": "FileTree"
89
+ }
90
+ ],
91
+ "showClose": true,
92
+ "closeContainerId": "terminal"
93
+ },
94
+ "background": "#252526"
95
+ },
96
+ "content": {
97
+ "id": "content",
98
+ "background": "#007acc",
99
+ "type": "split",
100
+ "orientation": "horizontal",
101
+ "children": [
102
+ {
103
+ "containerId": "menuContainer",
104
+ "type": "container",
105
+ "size": {
106
+ "initial": { "value": 250, "unit": "px", "type": "fixed" },
107
+ "min": { "value": 200, "unit": "px"},
108
+ "max": { "value": 400, "unit": "px"}
109
+ },
110
+ "collapse": { "value": 700, "condition": "lessThan", "relative": "parent" }
111
+ },
112
+ {
113
+ "type": "handleBar",
114
+ "sibling1": "menuContainer",
115
+ "sibling2": "editorContainer"
116
+ },
117
+ {
118
+ "containerId": "editorContainer",
119
+ "type": "container",
120
+ "size": { "initial": { "type": "fill" }}
121
+ },
122
+ {
123
+ "type": "handleBar",
124
+ "sibling1": "editorContainer",
125
+ "sibling2": "editorContainer2"
126
+ },
127
+ {
128
+ "containerId": "editorContainer2",
129
+ "type": "container",
130
+ "size": { "initial": { "type": "fill" }}
131
+ }
132
+ ]
133
+ },
134
+ "footer": {
135
+ "id": "footer",
136
+ "background": "#007acc"
137
+ },
138
+ "sidebar": {
139
+ "id": "sidebar",
140
+ "background": "#333"
141
+ },
142
+ "menuContainer": {
143
+ "id": "menuContainer",
144
+ "background": "#252526",
145
+ "type": "split",
146
+ "orientation": "vertical",
147
+ "children": [
148
+ {
149
+ "containerId": "fileTabsContainer",
150
+ "type": "container",
151
+ "size": { "initial": { "type": "fill" }}
152
+ }
153
+ ]
154
+ },
155
+ "fileTabsContainer": {
156
+ "id": "fileTabsContainer",
157
+ "component": "FileTree",
158
+ "menuBar": {
159
+ "showClose": true,
160
+ "closeContainerId": "menuContainer",
161
+ "title": "EXPLORER"
162
+ },
163
+ "background": "#1e1e1e"
164
+ },
165
+ "editorContainer": {
166
+ "id": "editorContainer",
167
+ "component": "FileEditor",
168
+ "background": "#1e1e1e"
169
+ },
170
+ "editorContainer2": {
171
+ "id": "editorContainer2",
172
+ "component": "FileEditor",
173
+ "background": "#1e1e1e"
174
+ }
175
+ }
176
+ }