ui-layout-manager-dev 0.0.34-dev → 0.0.36-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": "ui-layout-manager-dev",
3
- "version": "0.0.34-dev",
3
+ "version": "0.0.36-dev",
4
4
  "description": "A react component to manage layout and themes in single page applications.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -36,7 +36,9 @@ export const RootContainer = () => {
36
36
  const rootContainerAPI = useRef({});
37
37
  rootContainerAPI.current = {
38
38
  hideLoadingScreen: () => {
39
- setShowLoadingScreen(false);
39
+ if (showLoadingScreen) {
40
+ setShowLoadingScreen(false);
41
+ }
40
42
  }
41
43
  };
42
44
 
@@ -75,11 +75,12 @@ export class LayoutController {
75
75
  this.containers[id] = containerApi;
76
76
  this.containerRefs[id] = containerRef;
77
77
 
78
- console.log(`Registered container with id: ${id} `);
78
+ // console.log(`Registered container with id: ${id} `);
79
79
 
80
80
  if (this.registeredContainers === this.numberOfContainers && !this.layoutLoaded) {
81
- console.log("All containers registered, layout is ready.");
82
- this.sendToWorker(LAYOUT_WORKER_PROTOCOL.INITIALIZE_FLEXBOX);
81
+ // console.log("All containers registered, layout is ready.");
82
+ this.sendToWorker(LAYOUT_WORKER_PROTOCOL.INITIALIZE_FLEXBOX,
83
+ { sizes: this.getContainerSizes() });
83
84
  }
84
85
  }
85
86
 
@@ -91,26 +92,35 @@ export class LayoutController {
91
92
  delete this.containers[id];
92
93
  }
93
94
 
95
+
94
96
  /**
95
- * This function is called when the root container is resized.
96
- * It will notify the worker to process the layout changes.
97
+ * Retuns the sizes of the containers.
98
+ * @return {Object} Size of containers.
97
99
  */
98
- handleRootResize() {
99
- if (!this.layoutLoaded) return;
100
- // console.log("Root container resized to:", width, height);
101
- const sizes = {};
100
+ getContainerSizes() {
101
+ const containerSizes = {};
102
102
  for (const id in this.containerRefs) {
103
103
  if (this.containerRefs.hasOwnProperty(id)) {
104
104
  const boundingRect = this.containerRefs[id].getBoundingClientRect();
105
- sizes[id] = {
105
+ containerSizes[id] = {
106
106
  width: boundingRect.width,
107
107
  height: boundingRect.height
108
108
  };
109
109
  }
110
110
  }
111
+ return containerSizes;
112
+ }
113
+
114
+ /**
115
+ * This function is called when the root container is resized.
116
+ * It will notify the worker to process the layout changes.
117
+ */
118
+ handleRootResize() {
119
+ if (!this.layoutLoaded) return;
120
+ // console.log("Root container resized to:", width, height);
111
121
  this.sendToWorker(
112
122
  LAYOUT_WORKER_PROTOCOL.APPLY_SIZES,
113
- { sizes: sizes }
123
+ { sizes: this.getContainerSizes() }
114
124
  );
115
125
  }
116
126
 
@@ -169,16 +179,11 @@ export class LayoutController {
169
179
  break;
170
180
  }
171
181
  };
172
- if (this.layoutLoaded) {
182
+ if (isInitial) {
173
183
  // After the initial transformations have been applied, we can hide
174
184
  // the loading screen for the root container.
175
185
  this.containers[this.ldf.layoutRoot].current.hideLoadingScreen();
176
- }
177
- if (isInitial) {
178
- this.layoutLoaded = true;
179
- // Call root resize to apply the layout rules after initial transformations
180
- // are applied, this applies the layout rules to hide the containers.
181
- this.handleRootResize();
186
+ console.log("Layout is ready, hiding loading screen.");
182
187
  }
183
188
  });
184
189
  };
@@ -17,9 +17,12 @@ export class LayoutEditor {
17
17
 
18
18
  /**
19
19
  * Initializes flexbox layout by processing LDF file.
20
+ * @param {Object} sizes Initial sizes of the containers.
20
21
  */
21
- initializeFlexBox() {
22
- this.initializeNode(this.ldf.containers[this.ldf.layoutRoot]);
22
+ initializeFlexBox(sizes) {
23
+ this.initializeNode(this.ldf.containers[this.ldf.layoutRoot]);
24
+ this.sizes = sizes;
25
+ this.applyLayoutToNode(this.ldf.layoutRoot);
23
26
  postMessage({
24
27
  type: LAYOUT_WORKER_PROTOCOL.INITIALIZE_FLEXBOX,
25
28
  data: this.transformations
@@ -17,7 +17,7 @@ self.onmessage = function (e) {
17
17
  editor = new LayoutEditor(args.ldf);
18
18
  break;
19
19
  case LAYOUT_WORKER_PROTOCOL.INITIALIZE_FLEXBOX:
20
- editor.initializeFlexBox();
20
+ editor.initializeFlexBox(args.sizes);
21
21
  break;
22
22
  case LAYOUT_WORKER_PROTOCOL.APPLY_SIZES:
23
23
  editor.applySizes(args.sizes);