ui-layout-manager-dev 0.0.1
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/.storybook/main.js +22 -0
- package/.storybook/manager.js +6 -0
- package/.storybook/preview.js +13 -0
- package/LICENSE +201 -0
- package/README.md +80 -0
- package/babel.config.js +6 -0
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/LayoutWorker.js +494 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/jsconfig.json +13 -0
- package/package.json +68 -0
- package/rollup.config.mjs +49 -0
- package/src/components/LayoutManager/Components/Container/Container.jsx +136 -0
- package/src/components/LayoutManager/Components/Container/Container.scss +23 -0
- package/src/components/LayoutManager/Components/HandleBar/HandleBar.jsx +183 -0
- package/src/components/LayoutManager/Components/HandleBar/HandleBar.scss +74 -0
- package/src/components/LayoutManager/Components/LazyLoader/LazyLoader.js +33 -0
- package/src/components/LayoutManager/Components/LazyLoader/LazyLoader.scss +7 -0
- package/src/components/LayoutManager/Components/RootContainer/RootContainer.jsx +106 -0
- package/src/components/LayoutManager/Components/RootContainer/RootContainer.scss +13 -0
- package/src/components/LayoutManager/Controller/LAYOUT_WORKER_PROTOCOL.js +11 -0
- package/src/components/LayoutManager/Controller/LayoutController.js +201 -0
- package/src/components/LayoutManager/Controller/TRANSFORMATION_TYPES.js +6 -0
- package/src/components/LayoutManager/Controller/Worker/HandleRulesEnforcer.js +179 -0
- package/src/components/LayoutManager/Controller/Worker/LayoutEditor.js +183 -0
- package/src/components/LayoutManager/Controller/Worker/LayoutWorker.js +41 -0
- package/src/components/LayoutManager/Controller/Worker/ParentRuleEnforcer.js +79 -0
- package/src/components/LayoutManager/Controller/Worker/Size.js +29 -0
- package/src/components/LayoutManager/LayoutManager.jsx +31 -0
- package/src/components/LayoutManager/LayoutManager.scss +0 -0
- package/src/components/LayoutManager/Providers/ComponentRegistryContext.js +7 -0
- package/src/components/LayoutManager/Providers/LayoutProvider.js +48 -0
- package/src/components/LayoutManager/docs/ui_layout_manager_system_diagram.JPG +0 -0
- package/src/components/LayoutManager/index.js +1 -0
- package/src/index.js +1 -0
- package/src/stories/LayoutManager.stories.js +64 -0
- package/src/stories/LayoutManager.stories.scss +7 -0
- package/src/stories/layouts/vsCode/default.json +195 -0
- package/src/stories/layouts/vsCode/sample1.json +151 -0
- package/src/stories/sample_components/editor/EditorVSCode.jsx +11 -0
- package/src/stories/sample_components/editor/filetree.json +1 -0
- package/src/stories/sample_components/flow/Flow.jsx +10 -0
- package/src/stories/sample_components/flow/SampleTree.json +8 -0
- package/src/stories/sample_components/map/MapSample.jsx +43 -0
- package/src/stories/sample_components/map/MapSample.scss +3 -0
- package/src/stories/sample_components/stack/Stack.jsx +21 -0
- package/tests/LayoutEditor/LayoutEditor.test.js +14 -0
- package/tests/LayoutEditor/layouts/default.json +195 -0
- package/vitest.config.js +8 -0
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
let LAYOUT_WORKER_PROTOCOL = {
|
|
2
|
+
INITIALIZE: 1,
|
|
3
|
+
INITIALIZE_FLEXBOX: 2,
|
|
4
|
+
APPLY_SIZES: 3,
|
|
5
|
+
ERROR: 4,
|
|
6
|
+
TRANSFORMATIONS: 5,
|
|
7
|
+
MOVE_HANDLE_BAR: 6
|
|
8
|
+
};
|
|
9
|
+
LAYOUT_WORKER_PROTOCOL = Object.freeze(LAYOUT_WORKER_PROTOCOL);
|
|
10
|
+
|
|
11
|
+
var LAYOUT_WORKER_PROTOCOL$1 = LAYOUT_WORKER_PROTOCOL;
|
|
12
|
+
|
|
13
|
+
let TRANSFORMATION_TYPES = {
|
|
14
|
+
UPDATE_SIZE: 1
|
|
15
|
+
};
|
|
16
|
+
TRANSFORMATION_TYPES = Object.freeze(TRANSFORMATION_TYPES);
|
|
17
|
+
|
|
18
|
+
var TRANSFORMATION_TYPES$1 = TRANSFORMATION_TYPES;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This class generates transformations based on the
|
|
22
|
+
* parents layout configuration. For example, it collapses
|
|
23
|
+
* a container if the parent size reaches a threshold
|
|
24
|
+
* or expands it if the is above a threshold.
|
|
25
|
+
*/
|
|
26
|
+
class ParentRuleEnforcer {
|
|
27
|
+
/**
|
|
28
|
+
* Initialize the rule enforcer.
|
|
29
|
+
* @param {Object} sizes
|
|
30
|
+
* @param {Object} parent
|
|
31
|
+
* @param {Object} child
|
|
32
|
+
*/
|
|
33
|
+
constructor (sizes, parent, child) {
|
|
34
|
+
this.sizes = sizes;
|
|
35
|
+
this.parent = parent;
|
|
36
|
+
this.child = child;
|
|
37
|
+
this.type = null;
|
|
38
|
+
this.args = {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get props given node orientation.
|
|
43
|
+
* @param {Object} node
|
|
44
|
+
*/
|
|
45
|
+
getProps(node) {
|
|
46
|
+
// Identify the dynamic property based on orientation.
|
|
47
|
+
if (node.orientation === "horizontal") {
|
|
48
|
+
return {"dynamic": "width", "fixed": "height"};
|
|
49
|
+
} else if (node.orientation === "vertical") {
|
|
50
|
+
return {"dynamic": "height", "fixed": "width"};
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error(`Unknown orientation "${node.orientation}" in LDF configuration`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Evaluate the rules based on parent and child sizes and
|
|
58
|
+
* the specified layout configuration.
|
|
59
|
+
*/
|
|
60
|
+
evaluate() {
|
|
61
|
+
if (this.child.hasOwnProperty("collapse") && this.child["collapse"]["relative"] === "parent") {
|
|
62
|
+
this.evaluateCollapseByParent();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Evaluate the collapse by parent property.
|
|
68
|
+
*/
|
|
69
|
+
evaluateCollapseByParent() {
|
|
70
|
+
const props = this.getProps(this.parent);
|
|
71
|
+
const parentSize = this.sizes[this.parent.id];
|
|
72
|
+
|
|
73
|
+
let args = {};
|
|
74
|
+
if (parentSize[props["dynamic"]] <= this.child.collapse.value && this.child.collapse.condition === "lessThan") {
|
|
75
|
+
// Collapse below threshold
|
|
76
|
+
if (!this.child.hidden) {
|
|
77
|
+
this.type = TRANSFORMATION_TYPES$1.UPDATE_SIZE;
|
|
78
|
+
args = {style: {"display":"none"}};
|
|
79
|
+
const prop = "min-" + props["dynamic"];
|
|
80
|
+
args.style[prop] = 0;
|
|
81
|
+
this.child.hidden = true;
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
// Expand above threshold
|
|
85
|
+
if (this.child.hidden) {
|
|
86
|
+
this.type = TRANSFORMATION_TYPES$1.UPDATE_SIZE;
|
|
87
|
+
args = {style: {"display":"flex"}};
|
|
88
|
+
if ("min" in this.child.size) {
|
|
89
|
+
const prop = "min-" + props["dynamic"];
|
|
90
|
+
args.style[prop] = this.child.size.min.value + this.child.size.min.unit;
|
|
91
|
+
}
|
|
92
|
+
this.child.hidden = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
Object.assign(this.args, args);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* This class generates transformations based on the handle
|
|
101
|
+
* bars movements. It sets up thresholds at which it collapses
|
|
102
|
+
* and expands the containers. This isn't the width of the container,
|
|
103
|
+
* it is the position of the handle bar in the parent container. So
|
|
104
|
+
* even if a container has a min width of 200px, when the handle bar
|
|
105
|
+
* reaches 50px from the left, it will collapse it.
|
|
106
|
+
*
|
|
107
|
+
* This will be expanded in the future to have different collapsed states.
|
|
108
|
+
* So rather than fully collapsing the container, it sets up a
|
|
109
|
+
* minimum size, this willl be useful for accordians and other containers.
|
|
110
|
+
*/
|
|
111
|
+
class HandleRulesEnforcer {
|
|
112
|
+
/**
|
|
113
|
+
* Initialize the child rule enforcer.
|
|
114
|
+
* @param {Object} parent
|
|
115
|
+
* @param {Object} sibling1
|
|
116
|
+
* @param {Object} sibling2
|
|
117
|
+
* @param {Object} handleMetadata
|
|
118
|
+
*/
|
|
119
|
+
constructor (parent, sibling1, sibling2, handleMetadata) {
|
|
120
|
+
this.parent = parent;
|
|
121
|
+
this.type = null;
|
|
122
|
+
this.args = {};
|
|
123
|
+
this.sibling1 = sibling1;
|
|
124
|
+
this.sibling2 = sibling2;
|
|
125
|
+
this.handleMetadata = handleMetadata;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get props given node orientation.
|
|
130
|
+
* @param {Object} node
|
|
131
|
+
*/
|
|
132
|
+
getProps(node) {
|
|
133
|
+
// Identify the dynamic property based on orientation.
|
|
134
|
+
if (node.orientation === "horizontal") {
|
|
135
|
+
return {"dynamic": "width", "fixed": "height"};
|
|
136
|
+
} else if (node.orientation === "vertical") {
|
|
137
|
+
return {"dynamic": "height", "fixed": "width"};
|
|
138
|
+
} else {
|
|
139
|
+
throw new Error(`Unknown orientation "${node.orientation}" in LDF configuration`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Evaluate the rules based on childs
|
|
145
|
+
*/
|
|
146
|
+
evaluate() {
|
|
147
|
+
this.activeSibling = null;
|
|
148
|
+
const props = this.getProps(this.parent);
|
|
149
|
+
if (props.dynamic === "width") {
|
|
150
|
+
this.processVerticalContainers();
|
|
151
|
+
} else if (props.dynamic === "height") {
|
|
152
|
+
this.processHorizontalContainers();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Process the vertical containers.
|
|
158
|
+
*/
|
|
159
|
+
processVerticalContainers () {
|
|
160
|
+
const totalWidth = this.handleMetadata.sizes[this.parent.id].width;
|
|
161
|
+
this.type = TRANSFORMATION_TYPES$1.UPDATE_SIZE;
|
|
162
|
+
|
|
163
|
+
// Currently only collapse the edge containers
|
|
164
|
+
// TODO: In the future add logic for middle containers (accordian style)
|
|
165
|
+
if (!this.checkIfEdgeContainer()) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (this.handleMetadata.handle.x < 100) {
|
|
170
|
+
this.args = {style: {"display":"none", "min-width":0}};
|
|
171
|
+
this.sibling1.hidden = true;
|
|
172
|
+
this.activeSibling = this.sibling1.id;
|
|
173
|
+
} else if (this.handleMetadata.handle.x > 100 && this.sibling1.hidden) {
|
|
174
|
+
this.args = {style: {"display":"flex"}};
|
|
175
|
+
const sibling = this.getSiblingProps(this.sibling1.id);
|
|
176
|
+
if ("min" in sibling.size) {
|
|
177
|
+
this.args.style["min-width"] = sibling.size.min.value + sibling.size.min.unit;
|
|
178
|
+
}
|
|
179
|
+
this.sibling1.hidden = false;
|
|
180
|
+
this.activeSibling = this.sibling1.id;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
if (this.handleMetadata.handle.x > totalWidth - 100) {
|
|
185
|
+
this.args = {style: {"display":"none", "min-width":0}};
|
|
186
|
+
this.sibling2.hidden = true;
|
|
187
|
+
this.activeSibling = this.sibling2.id;
|
|
188
|
+
} else if (this.handleMetadata.handle.x < totalWidth - 100 && this.sibling2.hidden) {
|
|
189
|
+
this.args = {style: {"display":"flex"}};
|
|
190
|
+
const sibling = this.getSiblingProps(this.sibling2.id);
|
|
191
|
+
if ("min" in sibling.size) {
|
|
192
|
+
this.args.style["min-width"] = sibling.size.min.value + sibling.size.min.unit;
|
|
193
|
+
}
|
|
194
|
+
this.sibling2.hidden = false;
|
|
195
|
+
this.activeSibling = this.sibling2.id;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Process the vertical containers.
|
|
202
|
+
*/
|
|
203
|
+
processHorizontalContainers () {
|
|
204
|
+
const totalHeight = this.handleMetadata.sizes[this.parent.id].height;
|
|
205
|
+
this.type = TRANSFORMATION_TYPES$1.UPDATE_SIZE;
|
|
206
|
+
|
|
207
|
+
// Currently only collapse the edge containers
|
|
208
|
+
// TODO: In the future add logic for middle containers (accordian style)
|
|
209
|
+
if (!this.checkIfEdgeContainer()) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (this.handleMetadata.handle.y < 100) {
|
|
214
|
+
this.args = {style: {"display":"none", "min-height":0}};
|
|
215
|
+
this.sibling1.hidden = true;
|
|
216
|
+
this.activeSibling = this.sibling1.id;
|
|
217
|
+
} else if (this.handleMetadata.handle.y > 100 && this.sibling1.hidden) {
|
|
218
|
+
this.args = {style: {"display":"flex"}};
|
|
219
|
+
const sibling = this.getSiblingProps(this.sibling1.id);
|
|
220
|
+
if ("min" in sibling.size) {
|
|
221
|
+
this.args.style["min-height"] = sibling.size.min.value + sibling.size.min.unit;
|
|
222
|
+
}
|
|
223
|
+
this.sibling1.hidden = false;
|
|
224
|
+
this.activeSibling = this.sibling1.id;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
if (this.handleMetadata.handle.y > totalHeight - 100) {
|
|
229
|
+
this.args = {style: {"display":"none", "min-height":0}};
|
|
230
|
+
this.sibling2.hidden = true;
|
|
231
|
+
this.activeSibling = this.sibling2.id;
|
|
232
|
+
} else if (this.handleMetadata.handle.y < totalHeight - 100 && this.sibling2.hidden) {
|
|
233
|
+
this.args = {style: {"display":"flex"}};
|
|
234
|
+
const sibling = this.getSiblingProps(this.sibling2.id);
|
|
235
|
+
if ("min" in sibling.size) {
|
|
236
|
+
this.args.style["min-height"] = sibling.size.min.value + sibling.size.min.unit;
|
|
237
|
+
}
|
|
238
|
+
this.sibling2.hidden = false;
|
|
239
|
+
this.activeSibling = this.sibling2.id;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Given the sibling ID, it returns the child properties from the parent.
|
|
245
|
+
* This includes the min-size and max-size. This is done because the actual
|
|
246
|
+
* min and max sizes are saved in the children of the parent, not in the actual
|
|
247
|
+
* container itself in the LDF file.
|
|
248
|
+
* @param {String} siblingId
|
|
249
|
+
*/
|
|
250
|
+
getSiblingProps (siblingId) {
|
|
251
|
+
for (let i = 0; i < this.parent.children.length; i++) {
|
|
252
|
+
const child = this.parent.children[i];
|
|
253
|
+
if (child.containerId === siblingId) {
|
|
254
|
+
return child;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Check if the handle bar is attached to the edge of the parent container.
|
|
262
|
+
* i.e. Is sibling1 on the very left or is sibling2 on the very right.
|
|
263
|
+
*/
|
|
264
|
+
checkIfEdgeContainer () {
|
|
265
|
+
const firstSibling = this.parent.children[0];
|
|
266
|
+
const lastSibling = this.parent.children[this.parent.children.length -1];
|
|
267
|
+
|
|
268
|
+
if (firstSibling.containerId === this.sibling1.id) {
|
|
269
|
+
return true;
|
|
270
|
+
} else if (lastSibling.containerId === this.sibling2.id) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
class LayoutEditor {
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Initializes the editor with the given ldf file.
|
|
282
|
+
* @param {Object} ldf
|
|
283
|
+
*/
|
|
284
|
+
constructor (ldf) {
|
|
285
|
+
this.ldf = ldf;
|
|
286
|
+
console.log("Created modifier with ", this.ldf);
|
|
287
|
+
this.transformations = [];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Initializes flexbox layout by processing LDF file.
|
|
292
|
+
*/
|
|
293
|
+
initializeFlexBox() {
|
|
294
|
+
this.initializeNode(this.ldf.containers[this.ldf.layoutRoot]);
|
|
295
|
+
postMessage({
|
|
296
|
+
type: LAYOUT_WORKER_PROTOCOL$1.INITIALIZE_FLEXBOX,
|
|
297
|
+
data: this.transformations
|
|
298
|
+
});
|
|
299
|
+
this.transformations = [];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Get props given node orientation.
|
|
304
|
+
* @param {Object} node
|
|
305
|
+
*/
|
|
306
|
+
getProps(node) {
|
|
307
|
+
// Identify the dynamic property based on orientation.
|
|
308
|
+
if (node.orientation === "horizontal") {
|
|
309
|
+
return {"dynamic": "width", "fixed": "height"};
|
|
310
|
+
} else if (node.orientation === "vertical") {
|
|
311
|
+
return {"dynamic": "height", "fixed": "width"};
|
|
312
|
+
} else {
|
|
313
|
+
throw new Error(`Unknown orientation "${node.orientation}" in LDF configuration`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Processes the node and applies the initial flex box styles. It recursively
|
|
319
|
+
* calls the initialization function on the nodes children until the entire
|
|
320
|
+
* layout is initialized.
|
|
321
|
+
*
|
|
322
|
+
* After initialization, the layout is recalculated when the handle bar moves
|
|
323
|
+
* or when the window is resized. In the future, I will add programatic control
|
|
324
|
+
* to modify the layout. This means that the API will ask to divide a container
|
|
325
|
+
* in two or to delete container.
|
|
326
|
+
*
|
|
327
|
+
* TODO: Implement the programmatic control of layout containers (see above).
|
|
328
|
+
*
|
|
329
|
+
* @param {Object} node Node to process.
|
|
330
|
+
*/
|
|
331
|
+
initializeNode (node) {
|
|
332
|
+
const isSplit = node.type ? node.type === "split": false;
|
|
333
|
+
|
|
334
|
+
// If node is not split, then it has no children and is a leaf node, so we return.
|
|
335
|
+
if (!isSplit) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const props = this.getProps(node);
|
|
340
|
+
|
|
341
|
+
for (const child of node.children) {
|
|
342
|
+
if (child.type === "container") {
|
|
343
|
+
let childStyle = {};
|
|
344
|
+
switch(child.size.initial.type) {
|
|
345
|
+
case "fixed":
|
|
346
|
+
childStyle[props["dynamic"]] = child.size.initial.value + "px" ;
|
|
347
|
+
childStyle["flex"] = "0 0 auto";
|
|
348
|
+
break;
|
|
349
|
+
case "fill":
|
|
350
|
+
childStyle["flexGrow"] = 1;
|
|
351
|
+
break;
|
|
352
|
+
default:
|
|
353
|
+
throw new Error(`Unknown size type "${child.size.initial.type}" in LDF configuration`);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if ("min" in child.size) {
|
|
357
|
+
childStyle["min-" + props["dynamic"]] = child.size.min.value + "px" ;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if ("max" in child.size) {
|
|
361
|
+
childStyle["max-" + props["dynamic"]] = child.size.max.value + "px" ;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const childContainer = this.ldf.containers[child.containerId];
|
|
365
|
+
childContainer.collapsed = false;
|
|
366
|
+
this.transformations.push(
|
|
367
|
+
{
|
|
368
|
+
id: childContainer.id,
|
|
369
|
+
type: TRANSFORMATION_TYPES$1.UPDATE_SIZE,
|
|
370
|
+
args: {style: childStyle}
|
|
371
|
+
}
|
|
372
|
+
);
|
|
373
|
+
this.initializeNode(childContainer);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Use the given sizes to perform layout calculations and generate
|
|
380
|
+
* transformations.
|
|
381
|
+
* @param {Object} sizes
|
|
382
|
+
*/
|
|
383
|
+
applySizes(sizes) {
|
|
384
|
+
this.sizes = sizes;
|
|
385
|
+
this.applyLayoutToNode(this.ldf.layoutRoot);
|
|
386
|
+
postMessage({
|
|
387
|
+
type: LAYOUT_WORKER_PROTOCOL$1.TRANSFORMATIONS,
|
|
388
|
+
data: this.transformations
|
|
389
|
+
});
|
|
390
|
+
this.transformations = [];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* This function moves the handlebar.
|
|
395
|
+
* @param {Object} metadata
|
|
396
|
+
*/
|
|
397
|
+
moveHandleBar(metadata) {
|
|
398
|
+
const parent = this.ldf.containers[metadata.parent];
|
|
399
|
+
const sibling1 = this.ldf.containers[metadata.sibling1];
|
|
400
|
+
const sibling2 = this.ldf.containers[metadata.sibling2];
|
|
401
|
+
const enforcer = new HandleRulesEnforcer(parent, sibling1, sibling2, metadata);
|
|
402
|
+
enforcer.evaluate();
|
|
403
|
+
|
|
404
|
+
if (enforcer.activeSibling !== null) {
|
|
405
|
+
this.transformations.push(
|
|
406
|
+
{
|
|
407
|
+
id: enforcer.activeSibling,
|
|
408
|
+
type: TRANSFORMATION_TYPES$1.UPDATE_SIZE,
|
|
409
|
+
args: enforcer.args
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
postMessage({
|
|
413
|
+
type: LAYOUT_WORKER_PROTOCOL$1.TRANSFORMATIONS,
|
|
414
|
+
data: this.transformations
|
|
415
|
+
});
|
|
416
|
+
this.transformations = [];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Applys the layout logic to the node with the given container id.
|
|
422
|
+
* @param {String} containerId
|
|
423
|
+
* @returns
|
|
424
|
+
*/
|
|
425
|
+
applyLayoutToNode(containerId) {
|
|
426
|
+
const parent = this.ldf.containers[containerId];
|
|
427
|
+
|
|
428
|
+
// If node is not split, then it has no children and is a leaf node, so we return.
|
|
429
|
+
if ((!parent.type ? parent.type === "split": false) || (!("children" in parent))) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (!this.sizes[containerId]) {
|
|
434
|
+
console.warn(`Parent size not found for node ${parent.id}. Skipping collapse checks.`);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
for (const child of parent.children) {
|
|
439
|
+
if (child.type === "container") {
|
|
440
|
+
const enforcer = new ParentRuleEnforcer(this.sizes, parent, child);
|
|
441
|
+
enforcer.evaluate();
|
|
442
|
+
if (enforcer.type) {
|
|
443
|
+
this.transformations.push(
|
|
444
|
+
{
|
|
445
|
+
id: this.ldf.containers[child.containerId].id,
|
|
446
|
+
type: enforcer.type,
|
|
447
|
+
args: enforcer.args,
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
this.applyLayoutToNode(child.containerId);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* This function receives messages from the main thread and executes
|
|
459
|
+
* the layout manipulation logic.
|
|
460
|
+
* @param {Object} e
|
|
461
|
+
*/
|
|
462
|
+
let editor;
|
|
463
|
+
self.onmessage = function (e) {
|
|
464
|
+
|
|
465
|
+
try {
|
|
466
|
+
const args = e.data.args;
|
|
467
|
+
switch (e.data.code) {
|
|
468
|
+
case LAYOUT_WORKER_PROTOCOL$1.INITIALIZE:
|
|
469
|
+
/** @type {LayoutEditor} */
|
|
470
|
+
editor = new LayoutEditor(args.ldf);
|
|
471
|
+
break;
|
|
472
|
+
case LAYOUT_WORKER_PROTOCOL$1.INITIALIZE_FLEXBOX:
|
|
473
|
+
editor.initializeFlexBox();
|
|
474
|
+
break;
|
|
475
|
+
case LAYOUT_WORKER_PROTOCOL$1.APPLY_SIZES:
|
|
476
|
+
editor.applySizes(args.sizes);
|
|
477
|
+
break;
|
|
478
|
+
case LAYOUT_WORKER_PROTOCOL$1.MOVE_HANDLE_BAR:
|
|
479
|
+
editor.moveHandleBar(args.metadata);
|
|
480
|
+
break;
|
|
481
|
+
default:
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
} catch (e) {
|
|
486
|
+
postMessage({
|
|
487
|
+
type: LAYOUT_WORKER_PROTOCOL$1.ERROR,
|
|
488
|
+
error: {
|
|
489
|
+
message: e.message,
|
|
490
|
+
stack: e.stack
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import e,{useMemo as n,useEffect as r,createContext as t,useContext as o,useRef as i,lazy as a,Suspense as c,useState as s,useCallback as l,useLayoutEffect as u}from"react";import{jsx as f}from"react/jsx-runtime";function p(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d,y={exports:{}},h={exports:{}},v={};var m,b,g,w,S,x,O,E,k,R,T,C,j,I,P,N={};
|
|
2
|
+
/** @license React v16.13.1
|
|
3
|
+
* react-is.development.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/function z(){return b||(b=1,"production"===process.env.NODE_ENV?h.exports=function(){if(d)return v;d=1;var e="function"==typeof Symbol&&Symbol.for,n=e?Symbol.for("react.element"):60103,r=e?Symbol.for("react.portal"):60106,t=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,i=e?Symbol.for("react.profiler"):60114,a=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,s=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,f=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,y=e?Symbol.for("react.memo"):60115,h=e?Symbol.for("react.lazy"):60116,m=e?Symbol.for("react.block"):60121,b=e?Symbol.for("react.fundamental"):60117,g=e?Symbol.for("react.responder"):60118,w=e?Symbol.for("react.scope"):60119;function S(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case n:switch(e=e.type){case s:case l:case t:case i:case o:case f:return e;default:switch(e=e&&e.$$typeof){case c:case u:case h:case y:case a:return e;default:return p}}case r:return p}}}function x(e){return S(e)===l}return v.AsyncMode=s,v.ConcurrentMode=l,v.ContextConsumer=c,v.ContextProvider=a,v.Element=n,v.ForwardRef=u,v.Fragment=t,v.Lazy=h,v.Memo=y,v.Portal=r,v.Profiler=i,v.StrictMode=o,v.Suspense=f,v.isAsyncMode=function(e){return x(e)||S(e)===s},v.isConcurrentMode=x,v.isContextConsumer=function(e){return S(e)===c},v.isContextProvider=function(e){return S(e)===a},v.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===n},v.isForwardRef=function(e){return S(e)===u},v.isFragment=function(e){return S(e)===t},v.isLazy=function(e){return S(e)===h},v.isMemo=function(e){return S(e)===y},v.isPortal=function(e){return S(e)===r},v.isProfiler=function(e){return S(e)===i},v.isStrictMode=function(e){return S(e)===o},v.isSuspense=function(e){return S(e)===f},v.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===t||e===l||e===i||e===o||e===f||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===h||e.$$typeof===y||e.$$typeof===a||e.$$typeof===c||e.$$typeof===u||e.$$typeof===b||e.$$typeof===g||e.$$typeof===w||e.$$typeof===m)},v.typeOf=S,v}():h.exports=(m||(m=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,n=e?Symbol.for("react.element"):60103,r=e?Symbol.for("react.portal"):60106,t=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,i=e?Symbol.for("react.profiler"):60114,a=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,s=e?Symbol.for("react.async_mode"):60111,l=e?Symbol.for("react.concurrent_mode"):60111,u=e?Symbol.for("react.forward_ref"):60112,f=e?Symbol.for("react.suspense"):60113,p=e?Symbol.for("react.suspense_list"):60120,d=e?Symbol.for("react.memo"):60115,y=e?Symbol.for("react.lazy"):60116,h=e?Symbol.for("react.block"):60121,v=e?Symbol.for("react.fundamental"):60117,m=e?Symbol.for("react.responder"):60118,b=e?Symbol.for("react.scope"):60119;function g(e){if("object"==typeof e&&null!==e){var p=e.$$typeof;switch(p){case n:var h=e.type;switch(h){case s:case l:case t:case i:case o:case f:return h;default:var v=h&&h.$$typeof;switch(v){case c:case u:case y:case d:case a:return v;default:return p}}case r:return p}}}var w=s,S=l,x=c,O=a,E=n,k=u,R=t,T=y,C=d,j=r,I=i,P=o,z=f,L=!1;function $(e){return g(e)===l}N.AsyncMode=w,N.ConcurrentMode=S,N.ContextConsumer=x,N.ContextProvider=O,N.Element=E,N.ForwardRef=k,N.Fragment=R,N.Lazy=T,N.Memo=C,N.Portal=j,N.Profiler=I,N.StrictMode=P,N.Suspense=z,N.isAsyncMode=function(e){return L||(L=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),$(e)||g(e)===s},N.isConcurrentMode=$,N.isContextConsumer=function(e){return g(e)===c},N.isContextProvider=function(e){return g(e)===a},N.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===n},N.isForwardRef=function(e){return g(e)===u},N.isFragment=function(e){return g(e)===t},N.isLazy=function(e){return g(e)===y},N.isMemo=function(e){return g(e)===d},N.isPortal=function(e){return g(e)===r},N.isProfiler=function(e){return g(e)===i},N.isStrictMode=function(e){return g(e)===o},N.isSuspense=function(e){return g(e)===f},N.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===t||e===l||e===i||e===o||e===f||e===p||"object"==typeof e&&null!==e&&(e.$$typeof===y||e.$$typeof===d||e.$$typeof===a||e.$$typeof===c||e.$$typeof===u||e.$$typeof===v||e.$$typeof===m||e.$$typeof===b||e.$$typeof===h)},N.typeOf=g}()),N)),h.exports}
|
|
10
|
+
/*
|
|
11
|
+
object-assign
|
|
12
|
+
(c) Sindre Sorhus
|
|
13
|
+
@license MIT
|
|
14
|
+
*/function L(){if(w)return g;w=1;var e=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;return g=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var n={},r=0;r<10;r++)n["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(n).map(function(e){return n[e]}).join(""))return!1;var t={};return"abcdefghijklmnopqrst".split("").forEach(function(e){t[e]=e}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},t)).join("")}catch(e){return!1}}()?Object.assign:function(t,o){for(var i,a,c=function(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}(t),s=1;s<arguments.length;s++){for(var l in i=Object(arguments[s]))n.call(i,l)&&(c[l]=i[l]);if(e){a=e(i);for(var u=0;u<a.length;u++)r.call(i,a[u])&&(c[a[u]]=i[a[u]])}}return c},g}function $(){if(x)return S;x=1;return S="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}function A(){return E?O:(E=1,O=Function.call.bind(Object.prototype.hasOwnProperty))}function _(){if(R)return k;R=1;var e=function(){};if("production"!==process.env.NODE_ENV){var n=$(),r={},t=A();e=function(e){var n="Warning: "+e;"undefined"!=typeof console&&console.error(n);try{throw new Error(n)}catch(e){}}}function o(o,i,a,c,s){if("production"!==process.env.NODE_ENV)for(var l in o)if(t(o,l)){var u;try{if("function"!=typeof o[l]){var f=Error((c||"React class")+": "+a+" type `"+l+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[l]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw f.name="Invariant Violation",f}u=o[l](i,l,c,a,null,n)}catch(e){u=e}if(!u||u instanceof Error||e((c||"React class")+": type specification of "+a+" `"+l+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof u+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),u instanceof Error&&!(u.message in r)){r[u.message]=!0;var p=s?s():"";e("Failed "+a+" type: "+u.message+(null!=p?p:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(r={})},k=o}function B(){if(C)return T;C=1;var e=z(),n=L(),r=$(),t=A(),o=_(),i=function(){};function a(){return null}return"production"!==process.env.NODE_ENV&&(i=function(e){var n="Warning: "+e;"undefined"!=typeof console&&console.error(n);try{throw new Error(n)}catch(e){}}),T=function(c,s){var l="function"==typeof Symbol&&Symbol.iterator;var u="<<anonymous>>",f={array:h("array"),bigint:h("bigint"),bool:h("boolean"),func:h("function"),number:h("number"),object:h("object"),string:h("string"),symbol:h("symbol"),any:y(a),arrayOf:function(e){return y(function(n,t,o,i,a){if("function"!=typeof e)return new d("Property `"+a+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var c=n[t];if(!Array.isArray(c))return new d("Invalid "+i+" `"+a+"` of type `"+b(c)+"` supplied to `"+o+"`, expected an array.");for(var s=0;s<c.length;s++){var l=e(c,s,o,i,a+"["+s+"]",r);if(l instanceof Error)return l}return null})},element:y(function(e,n,r,t,o){var i=e[n];return c(i)?null:new d("Invalid "+t+" `"+o+"` of type `"+b(i)+"` supplied to `"+r+"`, expected a single ReactElement.")}),elementType:y(function(n,r,t,o,i){var a=n[r];return e.isValidElementType(a)?null:new d("Invalid "+o+" `"+i+"` of type `"+b(a)+"` supplied to `"+t+"`, expected a single ReactElement type.")}),instanceOf:function(e){return y(function(n,r,t,o,i){if(!(n[r]instanceof e)){var a=e.name||u;return new d("Invalid "+o+" `"+i+"` of type `"+(((c=n[r]).constructor&&c.constructor.name?c.constructor.name:u)+"` supplied to `")+t+"`, expected instance of `"+a+"`.")}var c;return null})},node:y(function(e,n,r,t,o){return m(e[n])?null:new d("Invalid "+t+" `"+o+"` supplied to `"+r+"`, expected a ReactNode.")}),objectOf:function(e){return y(function(n,o,i,a,c){if("function"!=typeof e)return new d("Property `"+c+"` of component `"+i+"` has invalid PropType notation inside objectOf.");var s=n[o],l=b(s);if("object"!==l)return new d("Invalid "+a+" `"+c+"` of type `"+l+"` supplied to `"+i+"`, expected an object.");for(var u in s)if(t(s,u)){var f=e(s,u,i,a,c+"."+u,r);if(f instanceof Error)return f}return null})},oneOf:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&i(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),a;return y(function(n,r,t,o,i){for(var a=n[r],c=0;c<e.length;c++)if(p(a,e[c]))return null;var s=JSON.stringify(e,function(e,n){return"symbol"===g(n)?String(n):n});return new d("Invalid "+o+" `"+i+"` of value `"+String(a)+"` supplied to `"+t+"`, expected one of "+s+".")})},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&i("Invalid argument supplied to oneOfType, expected an instance of array."),a;for(var n=0;n<e.length;n++){var o=e[n];if("function"!=typeof o)return i("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+w(o)+" at index "+n+"."),a}return y(function(n,o,i,a,c){for(var s=[],l=0;l<e.length;l++){var u=(0,e[l])(n,o,i,a,c,r);if(null==u)return null;u.data&&t(u.data,"expectedType")&&s.push(u.data.expectedType)}return new d("Invalid "+a+" `"+c+"` supplied to `"+i+"`"+(s.length>0?", expected one of type ["+s.join(", ")+"]":"")+".")})},shape:function(e){return y(function(n,t,o,i,a){var c=n[t],s=b(c);if("object"!==s)return new d("Invalid "+i+" `"+a+"` of type `"+s+"` supplied to `"+o+"`, expected `object`.");for(var l in e){var u=e[l];if("function"!=typeof u)return v(o,i,a,l,g(u));var f=u(c,l,o,i,a+"."+l,r);if(f)return f}return null})},exact:function(e){return y(function(o,i,a,c,s){var l=o[i],u=b(l);if("object"!==u)return new d("Invalid "+c+" `"+s+"` of type `"+u+"` supplied to `"+a+"`, expected `object`.");var f=n({},o[i],e);for(var p in f){var y=e[p];if(t(e,p)&&"function"!=typeof y)return v(a,c,s,p,g(y));if(!y)return new d("Invalid "+c+" `"+s+"` key `"+p+"` supplied to `"+a+"`.\nBad object: "+JSON.stringify(o[i],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var h=y(l,p,a,c,s+"."+p,r);if(h)return h}return null})}};function p(e,n){return e===n?0!==e||1/e==1/n:e!=e&&n!=n}function d(e,n){this.message=e,this.data=n&&"object"==typeof n?n:{},this.stack=""}function y(e){if("production"!==process.env.NODE_ENV)var n={},t=0;function o(o,a,c,l,f,p,y){if(l=l||u,p=p||c,y!==r){if(s){var h=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");throw h.name="Invariant Violation",h}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var v=l+":"+c;!n[v]&&t<3&&(i("You are manually calling a React.PropTypes validation function for the `"+p+"` prop on `"+l+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),n[v]=!0,t++)}}return null==a[c]?o?null===a[c]?new d("The "+f+" `"+p+"` is marked as required in `"+l+"`, but its value is `null`."):new d("The "+f+" `"+p+"` is marked as required in `"+l+"`, but its value is `undefined`."):null:e(a,c,l,f,p)}var a=o.bind(null,!1);return a.isRequired=o.bind(null,!0),a}function h(e){return y(function(n,r,t,o,i,a){var c=n[r];return b(c)!==e?new d("Invalid "+o+" `"+i+"` of type `"+g(c)+"` supplied to `"+t+"`, expected `"+e+"`.",{expectedType:e}):null})}function v(e,n,r,t,o){return new d((e||"React class")+": "+n+" type `"+r+"."+t+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function m(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(m);if(null===e||c(e))return!0;var n=function(e){var n=e&&(l&&e[l]||e["@@iterator"]);if("function"==typeof n)return n}(e);if(!n)return!1;var r,t=n.call(e);if(n!==e.entries){for(;!(r=t.next()).done;)if(!m(r.value))return!1}else for(;!(r=t.next()).done;){var o=r.value;if(o&&!m(o[1]))return!1}return!0;default:return!1}}function b(e){var n=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,n){return"symbol"===e||!!n&&("Symbol"===n["@@toStringTag"]||"function"==typeof Symbol&&n instanceof Symbol)}(n,e)?"symbol":n}function g(e){if(null==e)return""+e;var n=b(e);if("object"===n){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return n}function w(e){var n=g(e);switch(n){case"array":case"object":return"an "+n;case"boolean":case"date":case"regexp":return"a "+n;default:return n}}return d.prototype=Error.prototype,f.checkPropTypes=o,f.resetWarningCache=o.resetWarningCache,f.PropTypes=f,f},T}function M(){if(I)return j;I=1;var e=$();function n(){}function r(){}return r.resetWarningCache=n,j=function(){function t(n,r,t,o,i,a){if(a!==e){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function o(){return t}t.isRequired=t;var i={array:t,bigint:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:o,element:t,elementType:t,instanceOf:o,node:t,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:r,resetWarningCache:n};return i.PropTypes=i,i}}function V(){if(P)return y.exports;if(P=1,"production"!==process.env.NODE_ENV){var e=z();y.exports=B()(e.isElement,true)}else y.exports=M()();return y.exports}var D=p(V());function F(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}function W(e,n,r){return n&&function(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,Y(t.key),t)}}(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function H(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=U(e))||n){r&&(e=r);var t=0,o=function(){};return{s:o,n:function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function q(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var t,o,i,a,c=[],s=!0,l=!1;try{if(i=(r=r.call(e)).next,0===n);else for(;!(s=(t=i.call(r)).done)&&(c.push(t.value),c.length!==n);s=!0);}catch(e){l=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(l)throw o}}return c}}(e,n)||U(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Y(e){var n=function(e,n){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var t=r.call(e,n);if("object"!=typeof t)return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof n?n:n+""}function U(e,n){if(e){if("string"==typeof e)return F(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?F(e,n):void 0}}var X={INITIALIZE:1,INITIALIZE_FLEXBOX:2,APPLY_SIZES:3,ERROR:4,TRANSFORMATIONS:5,MOVE_HANDLE_BAR:6},Z=X=Object.freeze(X),K={UPDATE_SIZE:1},J=K=Object.freeze(K),G=function(){return W(function e(n){!function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}(this,e),this.containers={},this.containerRefs={},this.ldf=n,this.numberOfContainers=0,this.registeredContainers=0,this.layoutLoaded=!1,this.numberOfContainers=this.ldf.containers?Object.keys(this.ldf.containers).length:0;try{this.worker=new Worker(new URL("./Worker/LayoutWorker.js",import.meta.url),{type:"module"}),this.worker.onmessage=this.handleWorkerMessage.bind(this),this.worker.onerror=function(e){return console.error("Worker error:",e)},this.sendToWorker(Z.INITIALIZE,{ldf:n})}catch(e){console.error("Failed to create worker:",e)}},[{key:"sendToWorker",value:function(e,n){this.worker.postMessage({code:e,args:n})}},{key:"registerContainer",value:function(e,n,r){e in this.containers||(this.registeredContainers+=1),this.containers[e]=n,this.containerRefs[e]=r,console.log("Registered container with id: ".concat(e," ")),this.registeredContainers!==this.numberOfContainers||this.layoutLoaded||(console.log("All containers registered, layout is ready."),this.sendToWorker(Z.INITIALIZE_FLEXBOX))}},{key:"unregisterContainer",value:function(e){delete this.containers[e]}},{key:"handleRootResize",value:function(){if(this.layoutLoaded){var e={};for(var n in this.containerRefs)if(this.containerRefs.hasOwnProperty(n)){var r=this.containerRefs[n].getBoundingClientRect();e[n]={width:r.width,height:r.height}}this.sendToWorker(Z.APPLY_SIZES,{sizes:e})}}},{key:"moveHandleBar",value:function(e){for(var n={},r=0,t=[e.parent,e.sibling1,e.sibling2];r<t.length;r++){var o=t[r],i=this.containerRefs[o].getBoundingClientRect();n[o]={width:i.width,height:i.height}}e.sizes=n,this.sendToWorker(Z.MOVE_HANDLE_BAR,{metadata:e}),this.handleRootResize()}},{key:"applyTransformations",value:function(e,n){var r=this;requestAnimationFrame(function(){var t,o=H(e);try{for(o.s();!(t=o.n()).done;){var i=t.value;switch(i.type){case J.UPDATE_SIZE:r.containers[i.id].current.updateStyles(i.args.style);break;case J.REMOVE_NODE:break;default:console.warn("Unknown transformation was requested.")}}}catch(e){o.e(e)}finally{o.f()}n&&(r.layoutLoaded=!0)})}},{key:"handleWorkerMessage",value:function(e){var n;switch(e.data.type){case Z.INITIALIZE_FLEXBOX:n=e.data.data,this.applyTransformations(n,!0);break;case Z.TRANSFORMATIONS:n=e.data.data,this.applyTransformations(n,!1);break;case Z.ERROR:console.error("Error from worker:",e.data)}}},{key:"destroy",value:function(){this.worker&&(this.worker.terminate(),this.worker=null)}}])}(),Q=t(null);function ee(e){var t=e.layout,o=e.children,i=n(function(){return new G(t)},[t]);return r(function(){return function(){i.destroy()}},[i]),f(Q.Provider,{value:i,children:o})}function ne(){var e=o(Q);if(!e)throw new Error("useLayoutController must be used within a LayoutControllerProvider");return e}function re(e,n){void 0===n&&(n={});var r=n.insertAt;if(e&&"undefined"!=typeof document){var t=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&t.firstChild?t.insertBefore(o,t.firstChild):t.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}ee.propTypes={layout:D.object.isRequired,children:D.node.isRequired};re(".handleBarHorizontalContainer {\n position: relative;\n width: 100%;\n height: 1px;\n background-color: #414141;\n}\n\n.handleBarHorizontal {\n position: absolute;\n top: 50%;\n height: 1px;\n left: 0;\n right: 0;\n transform: translateY(-50%);\n transition: all 0.2s ease;\n}\n\n.handleBarHorizontal:hover {\n background-color: #007acc;\n cursor: ns-resize;\n height: 5px;\n z-index: 10;\n}\n\n.handleBarHorizontalHover {\n background-color: #007acc;\n cursor: ns-resize;\n height: 5px;\n z-index: 10;\n}\n\n.handleBarVerticalContainer {\n position: relative;\n height: 100%;\n width: 1px;\n background-color: #414141;\n z-index: 1;\n}\n\n.handleBarVertical {\n position: absolute;\n top: 0;\n width: 1px;\n left: 50%;\n bottom: 0;\n transform: translateX(-50%);\n transition: all 0.3s ease;\n}\n\n.handleBarVertical:hover {\n background-color: #007acc;\n cursor: ew-resize;\n width: 5px;\n z-index: 10;\n}\n\n.handleBarVerticalHover {\n background-color: #007acc;\n cursor: ew-resize;\n width: 5px;\n z-index: 10;\n}");var te=function(n){var r=n.orientation,t=n.parent,o=n.sibling1,a=n.sibling2,c=ne(),s=i(null),l=i(null),u=i(null),p=function(e){var n,i,u;e.preventDefault(),e.stopPropagation(),document.addEventListener("mousemove",d),document.addEventListener("mouseup",y),"horizontal"===r?(n="clientY",i="height",u="handleBarHorizontalHover"):"vertical"===r&&(n="clientX",i="width",u="handleBarVerticalHover");for(var f,p,h=c.containerRefs[t],v=c.containerRefs[o],m=c.containerRefs[a],b=c.ldf.containers[t],g=0;g<b.children.length;g++)b.children[g].containerId===o?f=b.children[g].size:b.children[g].containerId===a&&(p=b.children[g].size);s.current={downValueY:e[n],hoverClass:u,downKey:n,propKey:i,parentSize:h.getBoundingClientRect()[i],parentRef:h,sibling1Ref:v,sibling2Ref:m,sibling1LayoutConfig:f,sibling2LayoutConfig:p,sibling1Size:v.getBoundingClientRect()[i],sibling2Size:m.getBoundingClientRect()[i]},l.current.classList.add(u)};var d=function(e){if(s.current){e.preventDefault(),e.stopPropagation();var n=s.current,r=e[n.downKey]-n.downValueY,i=n.sibling1Size+r,l=n.sibling2Size-r;clearTimeout(u.current),u.current=setTimeout(function(){var r,i,s;c.moveHandleBar({handle:(r=e,i=n.parentRef,s=i.getBoundingClientRect(),{x:r.clientX-s.left,y:r.clientY-s.top}),parent:t,sibling1:o,sibling2:a})},.1);var f=Object.keys(n.sibling1LayoutConfig);if(!(f.includes("min")&&i<=n.sibling1LayoutConfig.min.value||f.includes("max")&&i>=n.sibling1LayoutConfig.max.value)){var p=Object.keys(n.sibling2LayoutConfig);if(!(p.includes("min")&&l<=n.sibling2LayoutConfig.min.value||p.includes("max")&&l>=n.sibling2LayoutConfig.max.value)){var d=n.sibling1LayoutConfig.initial.type,y=n.sibling2LayoutConfig.initial.type;if("fill"===d&&"fill"===y&&i>50&&l>50)return c.containerRefs[o].style[n.propKey]=i+"px",void(c.containerRefs[a].style[n.propKey]=l+"px");"fill"!==d&&(c.containerRefs[o].style[n.propKey]=i+"px"),"fill"!==y&&(c.containerRefs[a].style[n.propKey]=l+"px")}}}},y=function(e){e.preventDefault(),e.stopPropagation(),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",y),l.current.classList.remove(s.current.hoverClass),s.current=null};return f(e.Fragment,{children:"horizontal"===r?f("div",{onMouseDown:function(e){return p(e)},className:"handleBarHorizontalContainer",children:f("div",{ref:l,className:"handleBarHorizontal"})}):"vertical"===r?f("div",{onMouseDown:function(e){return p(e)},className:"handleBarVerticalContainer",children:f("div",{ref:l,className:"handleBarVertical"})}):null})};te.propTypes={orientation:D.string,sibling1:D.string,sibling2:D.string,parent:D.string};re(".relative-container {\n position: relative;\n}\n\n.relative-container.hiding-horizontal {\n width: 0px !important;\n}\n\n.relative-container.hiding-vertical {\n height: 0px !important;\n}\n\n.verticalLine {\n height: 100%;\n width: 1px;\n background: red;\n}\n\n.horizontalLine {\n width: 100%;\n height: 1px;\n background: red;\n}");var oe=t({});oe.displayName="ComponentRegistryContext";re(".lazyContainer {\n position: absolute;\n top: 0px;\n bottom: 0px;\n left: 0px;\n right: 0px;\n}");var ie=function(e){var r=e.content,t=o(oe),i=n(function(){if(t&&r&&"component"in r&&r.component in t)return a(t[r.component])},[t,r]);return f("div",{className:"lazyContainer",children:f(c,{fallback:f("div",{children:"Loading..."}),children:i&&f(i,{})})})};ie.propTypes={content:D.object};var ae=function(e){var n=e.node,r=ne(),t=i(null),o=i(null),a=q(s(null),2),c=a[0],p=a[1],d=l(function(e){for(var n=[],t=0;t<e.children.length;t++){var o=e.children[t];if("container"===o.type){var i=r.ldf.containers[e.children[t].containerId];i.parent=e,n.push(f(ae,{meta:e.children[t],id:i.id,node:i},t))}else"handleBar"===o.type&&("horizontal"===e.orientation?n.push(f(te,{orientation:"vertical",parent:e.id,sibling1:o.sibling1,sibling2:o.sibling2},t)):"vertical"===e.orientation&&n.push(f(te,{orientation:"horizontal",parent:e.id,sibling1:o.sibling1,sibling2:o.sibling2},t)))}return n},[r]),y=i({});return y.current={updateStyles:function(e){var n="hiding-"+o.current;for(var r in e)if("display"===r&&"none"===e[r]){if(t.current.classList.contains(n))return;t.current.classList.add(n)}else if("display"===r&&"flex"===e[r]){if(!t.current.classList.contains(n))return;t.current.classList.remove(n)}else t.current.style[r]=e[r]}},u(function(){if(n&&r&&t.current){o.current=n.parent.orientation;var e=n.children&&n.children.length>0;return e?"horizontal"===n.orientation?(t.current.style.display="flex",t.current.style.flexDirection="row",t.current.style.width="100%"):"vertical"===n.orientation?(t.current.style.display="flex",t.current.style.flexDirection="column",t.current.style.height="100%"):console.warn("Unknown orientation:",n.orientation):n.background?t.current.style.background=n.background:t.current.style.background="transparent",p(e?d(n):f(ie,{content:n})),r.registerContainer(n.id,y,t.current),function(){r.unregisterContainer(n.id)}}},[n,r,d]),f("div",{ref:t,className:"relative-container",children:c})};ae.propTypes={node:D.object};re(".root-container {\n width: 100%;\n height: 100%;\n overflow: hidden;\n}\n\n.relative-container {\n position: relative;\n display: flex;\n width: 100%;\n height: 100%;\n overflow: hidden;\n}");var ce=function(){var e=ne(),n=i(null),r=i(null),t=i(!1),o=i({});o.current={};var a=q(s(null),2),c=a[0],p=a[1],d=l(function(n){for(var r=[],t=0;t<n.children.length;t++){var o=n.children[t];if("container"===o.type){var i=e.ldf.containers[n.children[t].containerId];i.parent=n,r.push(f(ae,{meta:n.children[t],id:i.id,node:i},t))}else"handleBar"===o.type&&("horizontal"===n.orientation?r.push(f("div",{className:"verticalLine"})):"vertical"===n.orientation&&r.push(f("div",{className:"horizontalLine"})))}return r},[e]);return u(function(){if(e){var i=e.ldf.containers[e.ldf.layoutRoot],a=i.children&&i.children.length>0;e.registerContainer(i.id,o,n.current),a&&("horizontal"===i.orientation?n.current.style.flexDirection="row":"vertical"===i.orientation&&(n.current.style.flexDirection="column")),p(a?d(i):null);var c=new ResizeObserver(function(n){t.current||(t.current=!0);var o,i=H(n);try{var a=function(){var n=o.value.contentRect,i=n.width,a=n.height;clearTimeout(r.current),r.current=setTimeout(function(){t.current=!1,e.handleRootResize(i,a)},1)};for(i.s();!(o=i.n()).done;)a()}catch(e){i.e(e)}finally{i.f()}});return c.observe(n.current),function(){e.unregisterContainer(e.ldf.layoutRoot),c.disconnect()}}},[e]),f("div",{className:"root-container",children:f("div",{ref:n,className:"relative-container",children:c})})};re("");var se=function(e){var n=e.ldf,r=e.registry;return f(ee,{layout:n,children:f(oe.Provider,{value:r,children:f(ce,{})})})};se.propTypes={ldf:D.object,registry:D.object};export{se as LayoutManager};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|