dock-spawn-ts 2.513.1 → 2.514.0
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/lib/es5/dock-spawn-ts.js +1 -1
- package/lib/js/ContainerType.d.ts +6 -6
- package/lib/js/ContainerType.js +7 -7
- package/lib/js/Dialog.d.ts +43 -43
- package/lib/js/Dialog.js +136 -136
- package/lib/js/DockConfig.d.ts +7 -7
- package/lib/js/DockConfig.js +8 -8
- package/lib/js/DockGraphDeserializer.d.ts +18 -18
- package/lib/js/DockGraphDeserializer.js +116 -116
- package/lib/js/DockGraphSerializer.d.ts +13 -13
- package/lib/js/DockGraphSerializer.js +40 -40
- package/lib/js/DockLayoutEngine.d.ts +35 -35
- package/lib/js/DockLayoutEngine.js +319 -319
- package/lib/js/DockManager.d.ts +153 -153
- package/lib/js/DockManager.js +728 -728
- package/lib/js/DockManagerContext.d.ts +9 -9
- package/lib/js/DockManagerContext.js +9 -9
- package/lib/js/DockModel.d.ts +8 -8
- package/lib/js/DockModel.js +5 -5
- package/lib/js/DockNode.d.ts +15 -15
- package/lib/js/DockNode.js +61 -61
- package/lib/js/DockWheel.d.ts +40 -40
- package/lib/js/DockWheel.js +200 -200
- package/lib/js/DockWheelItem.d.ts +15 -15
- package/lib/js/DockWheelItem.js +27 -27
- package/lib/js/DocumentManagerContainer.d.ts +16 -16
- package/lib/js/DocumentManagerContainer.js +28 -28
- package/lib/js/DocumentTabPage.d.ts +14 -14
- package/lib/js/DocumentTabPage.js +26 -26
- package/lib/js/DraggableContainer.d.ts +52 -52
- package/lib/js/DraggableContainer.js +183 -183
- package/lib/js/EventHandler.d.ts +7 -7
- package/lib/js/EventHandler.js +11 -11
- package/lib/js/Exports.d.ts +30 -30
- package/lib/js/Exports.js +30 -30
- package/lib/js/FillDockContainer.d.ts +33 -33
- package/lib/js/FillDockContainer.js +69 -69
- package/lib/js/HorizontalDockContainer.d.ts +6 -6
- package/lib/js/HorizontalDockContainer.js +9 -9
- package/lib/js/PanelContainer.d.ts +101 -101
- package/lib/js/PanelContainer.js +384 -384
- package/lib/js/PanelContainer.js.map +1 -1
- package/lib/js/Point.d.ts +5 -5
- package/lib/js/Point.js +6 -6
- package/lib/js/ResizableContainer.d.ts +55 -55
- package/lib/js/ResizableContainer.js +241 -241
- package/lib/js/ResizeHandle.d.ts +15 -15
- package/lib/js/ResizeHandle.js +48 -48
- package/lib/js/SplitterBar.d.ts +35 -35
- package/lib/js/SplitterBar.js +149 -149
- package/lib/js/SplitterDockContainer.d.ts +35 -35
- package/lib/js/SplitterDockContainer.js +65 -65
- package/lib/js/SplitterPanel.d.ts +26 -26
- package/lib/js/SplitterPanel.js +191 -191
- package/lib/js/TabHandle.d.ts +55 -55
- package/lib/js/TabHandle.js +261 -260
- package/lib/js/TabHandle.js.map +1 -1
- package/lib/js/TabHost.d.ts +46 -46
- package/lib/js/TabHost.js +223 -223
- package/lib/js/TabHost.js.map +1 -1
- package/lib/js/TabPage.d.ts +19 -19
- package/lib/js/TabPage.js +74 -73
- package/lib/js/TabPage.js.map +1 -1
- package/lib/js/UndockInitiator.d.ts +31 -31
- package/lib/js/UndockInitiator.js +140 -140
- package/lib/js/Utils.d.ts +14 -14
- package/lib/js/Utils.js +70 -69
- package/lib/js/Utils.js.map +1 -1
- package/lib/js/VerticalDockContainer.d.ts +6 -6
- package/lib/js/VerticalDockContainer.js +9 -9
- package/lib/js/enums/PanelType.d.ts +4 -4
- package/lib/js/enums/PanelType.js +5 -5
- package/lib/js/enums/TabHostDirection.d.ts +6 -6
- package/lib/js/enums/TabHostDirection.js +7 -7
- package/lib/js/enums/WheelTypes.d.ts +11 -11
- package/lib/js/enums/WheelTypes.js +14 -14
- package/lib/js/interfaces/IDockContainer.d.ts +25 -25
- package/lib/js/interfaces/IDockContainer.js +1 -1
- package/lib/js/interfaces/IDockContainerWithSize.d.ts +5 -5
- package/lib/js/interfaces/IDockContainerWithSize.js +1 -1
- package/lib/js/interfaces/ILayoutEventListener.d.ts +26 -26
- package/lib/js/interfaces/ILayoutEventListener.js +1 -1
- package/lib/js/interfaces/IMouseOrTouchEvent.d.ts +6 -6
- package/lib/js/interfaces/IMouseOrTouchEvent.js +1 -1
- package/lib/js/interfaces/INodeInfo.d.ts +7 -7
- package/lib/js/interfaces/INodeInfo.js +1 -1
- package/lib/js/interfaces/IPanelInfo.d.ts +9 -9
- package/lib/js/interfaces/IPanelInfo.js +1 -1
- package/lib/js/interfaces/IRectangle.d.ts +6 -6
- package/lib/js/interfaces/IRectangle.js +1 -1
- package/lib/js/interfaces/ISize.d.ts +4 -4
- package/lib/js/interfaces/ISize.js +1 -1
- package/lib/js/interfaces/IState.d.ts +10 -10
- package/lib/js/interfaces/IState.js +1 -1
- package/lib/js/interfaces/IThickness.d.ts +6 -6
- package/lib/js/interfaces/IThickness.js +1 -1
- package/lib/js/webcomponent/DockSpawnTsWebcomponent.d.ts +30 -30
- package/lib/js/webcomponent/DockSpawnTsWebcomponent.js +153 -152
- package/lib/js/webcomponent/DockSpawnTsWebcomponent.js.map +1 -1
- package/package.json +6 -6
- package/src/PanelContainer.ts +1 -1
- package/src/TabHost.ts +5 -5
- package/src/TabPage.ts +4 -3
|
@@ -1,320 +1,320 @@
|
|
|
1
|
-
import { DockNode } from "./DockNode.js";
|
|
2
|
-
import { Utils } from "./Utils.js";
|
|
3
|
-
import { HorizontalDockContainer } from "./HorizontalDockContainer.js";
|
|
4
|
-
import { VerticalDockContainer } from "./VerticalDockContainer.js";
|
|
5
|
-
import { FillDockContainer } from "./FillDockContainer.js";
|
|
6
|
-
export class DockLayoutEngine {
|
|
7
|
-
constructor(dockManager) {
|
|
8
|
-
this._forceResizeCompositeContainer = (container) => {
|
|
9
|
-
let width = container.containerElement.clientWidth;
|
|
10
|
-
let height = container.containerElement.clientHeight;
|
|
11
|
-
container.resize(width, height);
|
|
12
|
-
};
|
|
13
|
-
this.dockManager = dockManager;
|
|
14
|
-
}
|
|
15
|
-
/** docks the [newNode] to the left of [referenceNode] */
|
|
16
|
-
dockLeft(referenceNode, newNode) {
|
|
17
|
-
this._performDock(referenceNode, newNode, 'horizontal', true);
|
|
18
|
-
}
|
|
19
|
-
/** docks the [newNode] to the right of [referenceNode] */
|
|
20
|
-
dockRight(referenceNode, newNode) {
|
|
21
|
-
this._performDock(referenceNode, newNode, 'horizontal', false);
|
|
22
|
-
}
|
|
23
|
-
/** docks the [newNode] to the top of [referenceNode] */
|
|
24
|
-
dockUp(referenceNode, newNode) {
|
|
25
|
-
this._performDock(referenceNode, newNode, 'vertical', true);
|
|
26
|
-
}
|
|
27
|
-
/** docks the [newNode] to the bottom of [referenceNode] */
|
|
28
|
-
dockDown(referenceNode, newNode) {
|
|
29
|
-
this._performDock(referenceNode, newNode, 'vertical', false);
|
|
30
|
-
}
|
|
31
|
-
/** docks the [newNode] by creating a new tab inside [referenceNode] */
|
|
32
|
-
dockFill(referenceNode, newNode) {
|
|
33
|
-
this._performDock(referenceNode, newNode, 'fill', false);
|
|
34
|
-
}
|
|
35
|
-
undock(node) {
|
|
36
|
-
let parentNode = node.parent;
|
|
37
|
-
if (!parentNode)
|
|
38
|
-
throw new Error('Cannot undock. panel is not a leaf node');
|
|
39
|
-
// Get the position of the node relative to it's siblings
|
|
40
|
-
let siblingIndex = parentNode.children.indexOf(node);
|
|
41
|
-
// Detach the node from the dock manager's tree hierarchy
|
|
42
|
-
node.detachFromParent();
|
|
43
|
-
// Fix the node's parent hierarchy
|
|
44
|
-
if (parentNode.children.length < parentNode.container.minimumAllowedChildNodes) {
|
|
45
|
-
// If the child count falls below the minimum threshold, destroy the parent and merge
|
|
46
|
-
// the children with their grandparents
|
|
47
|
-
let grandParent = parentNode.parent;
|
|
48
|
-
for (let i = 0; i < parentNode.children.length; i++) {
|
|
49
|
-
let otherChild = parentNode.children[i];
|
|
50
|
-
if (grandParent) {
|
|
51
|
-
// parent node is not a root node
|
|
52
|
-
grandParent.addChildAfter(parentNode, otherChild);
|
|
53
|
-
parentNode.detachFromParent();
|
|
54
|
-
let width = parentNode.container.containerElement.clientWidth;
|
|
55
|
-
let height = parentNode.container.containerElement.clientHeight;
|
|
56
|
-
parentNode.container.destroy();
|
|
57
|
-
otherChild.container.resize(width, height);
|
|
58
|
-
grandParent.performLayout(false);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
// Parent is a root node.
|
|
62
|
-
// Make the other child the root node
|
|
63
|
-
parentNode.detachFromParent();
|
|
64
|
-
parentNode.container.destroy();
|
|
65
|
-
this.dockManager.setRootNode(otherChild);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
// the node to be removed has 2 or more other siblings. So it is safe to continue
|
|
71
|
-
// using the parent composite container.
|
|
72
|
-
parentNode.performLayout(false);
|
|
73
|
-
// Set the next sibling as the active child (e.g. for a Tab host, it would select it as the active tab)
|
|
74
|
-
if (parentNode.children.length > 0) {
|
|
75
|
-
let nextActiveSibling = parentNode.children[Math.max(0, siblingIndex - 1)];
|
|
76
|
-
parentNode.container.setActiveChild(nextActiveSibling.container);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
this.dockManager.invalidate();
|
|
80
|
-
this.dockManager.notifyOnUnDock(node);
|
|
81
|
-
}
|
|
82
|
-
close(node) {
|
|
83
|
-
let parentNode = node === null || node === void 0 ? void 0 : node.parent;
|
|
84
|
-
if (!parentNode)
|
|
85
|
-
throw new Error('Cannot undock. panel is not a leaf node');
|
|
86
|
-
//check if closed tab was the active one
|
|
87
|
-
let activetabClosed = false;
|
|
88
|
-
if (parentNode.children.length > 0) {
|
|
89
|
-
if (parentNode.container.tabHost != null) {
|
|
90
|
-
let activeTab = parentNode.container.tabHost.getActiveTab();
|
|
91
|
-
activetabClosed = activeTab.container == node.container;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// Get the position of the node relative to it's siblings
|
|
95
|
-
let siblingIndex = parentNode.children.indexOf(node);
|
|
96
|
-
// Detach the node from the dock manager's tree hierarchy
|
|
97
|
-
node.detachFromParent();
|
|
98
|
-
if (parentNode.children.length < parentNode.container.minimumAllowedChildNodes) {
|
|
99
|
-
// If the child count falls below the minimum threshold, destroy the parent and merge
|
|
100
|
-
// the children with their grandparents
|
|
101
|
-
let grandParent = parentNode.parent;
|
|
102
|
-
for (let i = 0; i < parentNode.children.length; i++) {
|
|
103
|
-
let otherChild = parentNode.children[i];
|
|
104
|
-
if (grandParent) {
|
|
105
|
-
// parent node is not a root node
|
|
106
|
-
grandParent.addChildAfter(parentNode, otherChild);
|
|
107
|
-
parentNode.detachFromParent();
|
|
108
|
-
let width = parentNode.container.containerElement.clientWidth;
|
|
109
|
-
let height = parentNode.container.containerElement.clientHeight;
|
|
110
|
-
otherChild.container.resize(width, height);
|
|
111
|
-
parentNode.container.destroy();
|
|
112
|
-
grandParent.performLayout(false);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// Parent is a root node.
|
|
116
|
-
// Make the other child the root node
|
|
117
|
-
parentNode.detachFromParent();
|
|
118
|
-
parentNode.container.destroy();
|
|
119
|
-
this.dockManager.setRootNode(otherChild);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
// the node to be removed has 2 or more other siblings. So it is safe to continue
|
|
125
|
-
// using the parent composite container.
|
|
126
|
-
parentNode.performLayout(false);
|
|
127
|
-
if (activetabClosed) {
|
|
128
|
-
let nextActiveSibling = parentNode.children[Math.max(0, siblingIndex - 1)];
|
|
129
|
-
if (nextActiveSibling != null)
|
|
130
|
-
parentNode.container.setActiveChild(nextActiveSibling.container);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
this.dockManager.invalidate();
|
|
134
|
-
this.dockManager.notifyOnUnDock(node);
|
|
135
|
-
}
|
|
136
|
-
reorderTabs(node, handle, state, index) {
|
|
137
|
-
let N = node.children.length;
|
|
138
|
-
let nodeIndexToDelete = state === 'left' ? index : index + 1;
|
|
139
|
-
if (state == 'right' && nodeIndexToDelete >= node.children.length)
|
|
140
|
-
return;
|
|
141
|
-
if (state == 'left' && nodeIndexToDelete == 0)
|
|
142
|
-
return;
|
|
143
|
-
let indexes = Array.apply(null, { length: N }).map(Number.call, Number);
|
|
144
|
-
let indexValue = indexes.splice(nodeIndexToDelete, 1)[0]; //remove element
|
|
145
|
-
indexes.splice(state === 'left' ? index - 1 : index, 0, indexValue); //insert
|
|
146
|
-
node.children = Utils.orderByIndexes(node.children, indexes); //apply
|
|
147
|
-
node.container.tabHost.performTabsLayout(indexes);
|
|
148
|
-
this.dockManager.notifyOnTabsReorder(node);
|
|
149
|
-
}
|
|
150
|
-
_performDock(referenceNode, newNode, direction, insertBeforeReference) {
|
|
151
|
-
if (referenceNode.parent && referenceNode.parent.container.containerType === 'fill')
|
|
152
|
-
referenceNode = referenceNode.parent;
|
|
153
|
-
if (direction === 'fill' && referenceNode.container.containerType === 'fill') {
|
|
154
|
-
referenceNode.addChild(newNode);
|
|
155
|
-
referenceNode.performLayout(false);
|
|
156
|
-
referenceNode.container.setActiveChild(newNode.container);
|
|
157
|
-
this.dockManager.invalidate();
|
|
158
|
-
this.dockManager.notifyOnDock(newNode);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
// Check if reference node is root node
|
|
162
|
-
let model = this.dockManager.context.model, compositeContainer, compositeNode, referenceParent;
|
|
163
|
-
if (referenceNode === model.rootNode) {
|
|
164
|
-
if (insertBeforeReference) {
|
|
165
|
-
compositeContainer = this._createDockContainer(direction, newNode, referenceNode);
|
|
166
|
-
compositeNode = new DockNode(compositeContainer);
|
|
167
|
-
compositeNode.addChild(newNode);
|
|
168
|
-
compositeNode.addChild(referenceNode);
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
compositeContainer = this._createDockContainer(direction, referenceNode, newNode);
|
|
172
|
-
compositeNode = new DockNode(compositeContainer);
|
|
173
|
-
compositeNode.addChild(referenceNode);
|
|
174
|
-
compositeNode.addChild(newNode);
|
|
175
|
-
}
|
|
176
|
-
// Attach the root node to the dock manager's DOM
|
|
177
|
-
this.dockManager.setRootNode(compositeNode);
|
|
178
|
-
this.dockManager.rebuildLayout(this.dockManager.context.model.rootNode);
|
|
179
|
-
compositeNode.container.setActiveChild(newNode.container);
|
|
180
|
-
this.dockManager.invalidate();
|
|
181
|
-
this.dockManager.notifyOnDock(newNode);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (referenceNode.parent.container.containerType !== direction) {
|
|
185
|
-
referenceParent = referenceNode.parent;
|
|
186
|
-
// Get the dimensions of the reference node, for resizing later on
|
|
187
|
-
let referenceNodeWidth = referenceNode.container.containerElement.clientWidth;
|
|
188
|
-
let referenceNodeHeight = referenceNode.container.containerElement.clientHeight;
|
|
189
|
-
// Get the dimensions of the reference node, for resizing later on
|
|
190
|
-
let referenceNodeParentWidth = referenceParent.container.containerElement.clientWidth;
|
|
191
|
-
let referenceNodeParentHeight = referenceParent.container.containerElement.clientHeight;
|
|
192
|
-
// Replace the reference node with a new composite node with the reference and new node as it's children
|
|
193
|
-
compositeContainer = this._createDockContainer(direction, newNode, referenceNode);
|
|
194
|
-
compositeNode = new DockNode(compositeContainer);
|
|
195
|
-
referenceParent.addChildAfter(referenceNode, compositeNode);
|
|
196
|
-
referenceNode.detachFromParent();
|
|
197
|
-
Utils.removeNode(referenceNode.container.containerElement);
|
|
198
|
-
if (insertBeforeReference) {
|
|
199
|
-
compositeNode.addChild(newNode);
|
|
200
|
-
compositeNode.addChild(referenceNode);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
compositeNode.addChild(referenceNode);
|
|
204
|
-
compositeNode.addChild(newNode);
|
|
205
|
-
}
|
|
206
|
-
referenceParent.performLayout(false);
|
|
207
|
-
compositeNode.performLayout(true);
|
|
208
|
-
compositeNode.container.setActiveChild(newNode.container);
|
|
209
|
-
compositeNode.container.resize(referenceNodeWidth, referenceNodeHeight);
|
|
210
|
-
referenceParent.container.resize(referenceNodeParentWidth, referenceNodeParentHeight);
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
// Add as a sibling, since the parent of the reference node is of the right composite type
|
|
214
|
-
referenceParent = referenceNode.parent;
|
|
215
|
-
if (insertBeforeReference)
|
|
216
|
-
referenceParent.addChildBefore(referenceNode, newNode);
|
|
217
|
-
else
|
|
218
|
-
referenceParent.addChildAfter(referenceNode, newNode);
|
|
219
|
-
referenceParent.performLayout(false);
|
|
220
|
-
referenceParent.container.setActiveChild(newNode.container);
|
|
221
|
-
}
|
|
222
|
-
// force resize the panel
|
|
223
|
-
let containerWidth = newNode.container.containerElement.clientWidth;
|
|
224
|
-
let containerHeight = newNode.container.containerElement.clientHeight;
|
|
225
|
-
newNode.container.resize(containerWidth, containerHeight);
|
|
226
|
-
this.dockManager.invalidate();
|
|
227
|
-
this.dockManager.notifyOnDock(newNode);
|
|
228
|
-
}
|
|
229
|
-
_createDockContainer(containerType, newNode, referenceNode) {
|
|
230
|
-
if (containerType === 'horizontal')
|
|
231
|
-
return new HorizontalDockContainer(this.dockManager, [newNode.container, referenceNode.container]);
|
|
232
|
-
if (containerType === 'vertical')
|
|
233
|
-
return new VerticalDockContainer(this.dockManager, [newNode.container, referenceNode.container]);
|
|
234
|
-
if (containerType === 'fill')
|
|
235
|
-
return new FillDockContainer(this.dockManager);
|
|
236
|
-
throw new Error('Failed to create dock container of type: ' + containerType);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Gets the bounds of the new node if it were to dock with the specified configuration
|
|
240
|
-
* The state is not modified in this function. It is used for showing a preview of where
|
|
241
|
-
* the panel would be docked when hovered over a dock wheel button
|
|
242
|
-
*/
|
|
243
|
-
getDockBounds(referenceNode, containerToDock, direction, insertBeforeReference) {
|
|
244
|
-
let compositeNode; // The node that contains the splitter / fill node
|
|
245
|
-
let childCount;
|
|
246
|
-
let childPosition;
|
|
247
|
-
let bounds;
|
|
248
|
-
if (direction === 'fill') {
|
|
249
|
-
// Since this is a fill operation, the highlight bounds is the same as the reference node
|
|
250
|
-
// TODO: Create a tab handle highlight to show that it's going to be docked in a tab
|
|
251
|
-
let targetElement = referenceNode.container.containerElement;
|
|
252
|
-
let outerRect = this.dockManager.element.getBoundingClientRect();
|
|
253
|
-
let targetElementRect = targetElement.getBoundingClientRect();
|
|
254
|
-
return { x: targetElementRect.left - outerRect.left, y: targetElementRect.top - outerRect.top, width: targetElement.clientWidth, height: targetElement.clientHeight };
|
|
255
|
-
}
|
|
256
|
-
if (referenceNode.parent && referenceNode.parent.container.containerType === 'fill')
|
|
257
|
-
// Ignore the fill container's child and move one level up
|
|
258
|
-
referenceNode = referenceNode.parent;
|
|
259
|
-
// Flag to indicate of the renference node was replaced with a new composite node with 2 children
|
|
260
|
-
let hierarchyModified = false;
|
|
261
|
-
if (referenceNode.parent && referenceNode.parent.container.containerType === direction) {
|
|
262
|
-
// The parent already is of the desired composite type. Will be inserted as sibling to the reference node
|
|
263
|
-
compositeNode = referenceNode.parent;
|
|
264
|
-
childCount = compositeNode.children.length;
|
|
265
|
-
childPosition = compositeNode.children.indexOf(referenceNode) + (insertBeforeReference ? 0 : 1);
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
// The reference node will be replaced with a new composite node of the desired type with 2 children
|
|
269
|
-
compositeNode = referenceNode;
|
|
270
|
-
childCount = 1; // The newly inserted composite node will contain the reference node
|
|
271
|
-
childPosition = (insertBeforeReference ? 0 : 1);
|
|
272
|
-
hierarchyModified = true;
|
|
273
|
-
}
|
|
274
|
-
let splitBarSize = 5; // TODO: Get from DOM
|
|
275
|
-
let targetPanelSize = 0;
|
|
276
|
-
let targetPanelStart = 0;
|
|
277
|
-
if (direction === 'vertical' || direction === 'horizontal') {
|
|
278
|
-
// Existing size of the composite container (without the splitter bars).
|
|
279
|
-
// This will also be the final size of the composite (splitter / fill)
|
|
280
|
-
// container after the new panel has been docked
|
|
281
|
-
let compositeSize = this._getVaringDimension(compositeNode.container, direction) - (childCount - 1) * splitBarSize;
|
|
282
|
-
// size of the newly added panel
|
|
283
|
-
let newPanelOriginalSize = this._getVaringDimension(containerToDock, direction);
|
|
284
|
-
let scaleMultiplier = compositeSize / (compositeSize + newPanelOriginalSize);
|
|
285
|
-
// Size of the panel after it has been docked and scaled
|
|
286
|
-
targetPanelSize = newPanelOriginalSize * scaleMultiplier;
|
|
287
|
-
if (hierarchyModified)
|
|
288
|
-
targetPanelStart = insertBeforeReference ? 0 : compositeSize * scaleMultiplier;
|
|
289
|
-
else {
|
|
290
|
-
for (let i = 0; i < childPosition; i++)
|
|
291
|
-
targetPanelStart += this._getVaringDimension(compositeNode.children[i].container, direction);
|
|
292
|
-
targetPanelStart *= scaleMultiplier;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
bounds = {};
|
|
296
|
-
let outerRect = this.dockManager.element.getBoundingClientRect();
|
|
297
|
-
let rect = compositeNode.container.containerElement.getBoundingClientRect();
|
|
298
|
-
if (direction === 'vertical') {
|
|
299
|
-
bounds.x = rect.left - outerRect.left;
|
|
300
|
-
bounds.y = rect.top - outerRect.top + targetPanelStart;
|
|
301
|
-
bounds.width = compositeNode.container.width;
|
|
302
|
-
bounds.height = targetPanelSize;
|
|
303
|
-
}
|
|
304
|
-
else if (direction === 'horizontal') {
|
|
305
|
-
bounds.x = rect.left - outerRect.left + targetPanelStart;
|
|
306
|
-
bounds.y = rect.top - outerRect.top;
|
|
307
|
-
bounds.width = targetPanelSize;
|
|
308
|
-
bounds.height = compositeNode.container.height;
|
|
309
|
-
}
|
|
310
|
-
return bounds;
|
|
311
|
-
}
|
|
312
|
-
_getVaringDimension(container, direction) {
|
|
313
|
-
if (direction === 'vertical')
|
|
314
|
-
return container.height;
|
|
315
|
-
if (direction === 'horizontal')
|
|
316
|
-
return container.width;
|
|
317
|
-
return 0;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
1
|
+
import { DockNode } from "./DockNode.js";
|
|
2
|
+
import { Utils } from "./Utils.js";
|
|
3
|
+
import { HorizontalDockContainer } from "./HorizontalDockContainer.js";
|
|
4
|
+
import { VerticalDockContainer } from "./VerticalDockContainer.js";
|
|
5
|
+
import { FillDockContainer } from "./FillDockContainer.js";
|
|
6
|
+
export class DockLayoutEngine {
|
|
7
|
+
constructor(dockManager) {
|
|
8
|
+
this._forceResizeCompositeContainer = (container) => {
|
|
9
|
+
let width = container.containerElement.clientWidth;
|
|
10
|
+
let height = container.containerElement.clientHeight;
|
|
11
|
+
container.resize(width, height);
|
|
12
|
+
};
|
|
13
|
+
this.dockManager = dockManager;
|
|
14
|
+
}
|
|
15
|
+
/** docks the [newNode] to the left of [referenceNode] */
|
|
16
|
+
dockLeft(referenceNode, newNode) {
|
|
17
|
+
this._performDock(referenceNode, newNode, 'horizontal', true);
|
|
18
|
+
}
|
|
19
|
+
/** docks the [newNode] to the right of [referenceNode] */
|
|
20
|
+
dockRight(referenceNode, newNode) {
|
|
21
|
+
this._performDock(referenceNode, newNode, 'horizontal', false);
|
|
22
|
+
}
|
|
23
|
+
/** docks the [newNode] to the top of [referenceNode] */
|
|
24
|
+
dockUp(referenceNode, newNode) {
|
|
25
|
+
this._performDock(referenceNode, newNode, 'vertical', true);
|
|
26
|
+
}
|
|
27
|
+
/** docks the [newNode] to the bottom of [referenceNode] */
|
|
28
|
+
dockDown(referenceNode, newNode) {
|
|
29
|
+
this._performDock(referenceNode, newNode, 'vertical', false);
|
|
30
|
+
}
|
|
31
|
+
/** docks the [newNode] by creating a new tab inside [referenceNode] */
|
|
32
|
+
dockFill(referenceNode, newNode) {
|
|
33
|
+
this._performDock(referenceNode, newNode, 'fill', false);
|
|
34
|
+
}
|
|
35
|
+
undock(node) {
|
|
36
|
+
let parentNode = node.parent;
|
|
37
|
+
if (!parentNode)
|
|
38
|
+
throw new Error('Cannot undock. panel is not a leaf node');
|
|
39
|
+
// Get the position of the node relative to it's siblings
|
|
40
|
+
let siblingIndex = parentNode.children.indexOf(node);
|
|
41
|
+
// Detach the node from the dock manager's tree hierarchy
|
|
42
|
+
node.detachFromParent();
|
|
43
|
+
// Fix the node's parent hierarchy
|
|
44
|
+
if (parentNode.children.length < parentNode.container.minimumAllowedChildNodes) {
|
|
45
|
+
// If the child count falls below the minimum threshold, destroy the parent and merge
|
|
46
|
+
// the children with their grandparents
|
|
47
|
+
let grandParent = parentNode.parent;
|
|
48
|
+
for (let i = 0; i < parentNode.children.length; i++) {
|
|
49
|
+
let otherChild = parentNode.children[i];
|
|
50
|
+
if (grandParent) {
|
|
51
|
+
// parent node is not a root node
|
|
52
|
+
grandParent.addChildAfter(parentNode, otherChild);
|
|
53
|
+
parentNode.detachFromParent();
|
|
54
|
+
let width = parentNode.container.containerElement.clientWidth;
|
|
55
|
+
let height = parentNode.container.containerElement.clientHeight;
|
|
56
|
+
parentNode.container.destroy();
|
|
57
|
+
otherChild.container.resize(width, height);
|
|
58
|
+
grandParent.performLayout(false);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Parent is a root node.
|
|
62
|
+
// Make the other child the root node
|
|
63
|
+
parentNode.detachFromParent();
|
|
64
|
+
parentNode.container.destroy();
|
|
65
|
+
this.dockManager.setRootNode(otherChild);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// the node to be removed has 2 or more other siblings. So it is safe to continue
|
|
71
|
+
// using the parent composite container.
|
|
72
|
+
parentNode.performLayout(false);
|
|
73
|
+
// Set the next sibling as the active child (e.g. for a Tab host, it would select it as the active tab)
|
|
74
|
+
if (parentNode.children.length > 0) {
|
|
75
|
+
let nextActiveSibling = parentNode.children[Math.max(0, siblingIndex - 1)];
|
|
76
|
+
parentNode.container.setActiveChild(nextActiveSibling.container);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this.dockManager.invalidate();
|
|
80
|
+
this.dockManager.notifyOnUnDock(node);
|
|
81
|
+
}
|
|
82
|
+
close(node) {
|
|
83
|
+
let parentNode = node === null || node === void 0 ? void 0 : node.parent;
|
|
84
|
+
if (!parentNode)
|
|
85
|
+
throw new Error('Cannot undock. panel is not a leaf node');
|
|
86
|
+
//check if closed tab was the active one
|
|
87
|
+
let activetabClosed = false;
|
|
88
|
+
if (parentNode.children.length > 0) {
|
|
89
|
+
if (parentNode.container.tabHost != null) {
|
|
90
|
+
let activeTab = parentNode.container.tabHost.getActiveTab();
|
|
91
|
+
activetabClosed = activeTab.container == node.container;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Get the position of the node relative to it's siblings
|
|
95
|
+
let siblingIndex = parentNode.children.indexOf(node);
|
|
96
|
+
// Detach the node from the dock manager's tree hierarchy
|
|
97
|
+
node.detachFromParent();
|
|
98
|
+
if (parentNode.children.length < parentNode.container.minimumAllowedChildNodes) {
|
|
99
|
+
// If the child count falls below the minimum threshold, destroy the parent and merge
|
|
100
|
+
// the children with their grandparents
|
|
101
|
+
let grandParent = parentNode.parent;
|
|
102
|
+
for (let i = 0; i < parentNode.children.length; i++) {
|
|
103
|
+
let otherChild = parentNode.children[i];
|
|
104
|
+
if (grandParent) {
|
|
105
|
+
// parent node is not a root node
|
|
106
|
+
grandParent.addChildAfter(parentNode, otherChild);
|
|
107
|
+
parentNode.detachFromParent();
|
|
108
|
+
let width = parentNode.container.containerElement.clientWidth;
|
|
109
|
+
let height = parentNode.container.containerElement.clientHeight;
|
|
110
|
+
otherChild.container.resize(width, height);
|
|
111
|
+
parentNode.container.destroy();
|
|
112
|
+
grandParent.performLayout(false);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Parent is a root node.
|
|
116
|
+
// Make the other child the root node
|
|
117
|
+
parentNode.detachFromParent();
|
|
118
|
+
parentNode.container.destroy();
|
|
119
|
+
this.dockManager.setRootNode(otherChild);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// the node to be removed has 2 or more other siblings. So it is safe to continue
|
|
125
|
+
// using the parent composite container.
|
|
126
|
+
parentNode.performLayout(false);
|
|
127
|
+
if (activetabClosed) {
|
|
128
|
+
let nextActiveSibling = parentNode.children[Math.max(0, siblingIndex - 1)];
|
|
129
|
+
if (nextActiveSibling != null)
|
|
130
|
+
parentNode.container.setActiveChild(nextActiveSibling.container);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.dockManager.invalidate();
|
|
134
|
+
this.dockManager.notifyOnUnDock(node);
|
|
135
|
+
}
|
|
136
|
+
reorderTabs(node, handle, state, index) {
|
|
137
|
+
let N = node.children.length;
|
|
138
|
+
let nodeIndexToDelete = state === 'left' ? index : index + 1;
|
|
139
|
+
if (state == 'right' && nodeIndexToDelete >= node.children.length)
|
|
140
|
+
return;
|
|
141
|
+
if (state == 'left' && nodeIndexToDelete == 0)
|
|
142
|
+
return;
|
|
143
|
+
let indexes = Array.apply(null, { length: N }).map(Number.call, Number);
|
|
144
|
+
let indexValue = indexes.splice(nodeIndexToDelete, 1)[0]; //remove element
|
|
145
|
+
indexes.splice(state === 'left' ? index - 1 : index, 0, indexValue); //insert
|
|
146
|
+
node.children = Utils.orderByIndexes(node.children, indexes); //apply
|
|
147
|
+
node.container.tabHost.performTabsLayout(indexes);
|
|
148
|
+
this.dockManager.notifyOnTabsReorder(node);
|
|
149
|
+
}
|
|
150
|
+
_performDock(referenceNode, newNode, direction, insertBeforeReference) {
|
|
151
|
+
if (referenceNode.parent && referenceNode.parent.container.containerType === 'fill')
|
|
152
|
+
referenceNode = referenceNode.parent;
|
|
153
|
+
if (direction === 'fill' && referenceNode.container.containerType === 'fill') {
|
|
154
|
+
referenceNode.addChild(newNode);
|
|
155
|
+
referenceNode.performLayout(false);
|
|
156
|
+
referenceNode.container.setActiveChild(newNode.container);
|
|
157
|
+
this.dockManager.invalidate();
|
|
158
|
+
this.dockManager.notifyOnDock(newNode);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// Check if reference node is root node
|
|
162
|
+
let model = this.dockManager.context.model, compositeContainer, compositeNode, referenceParent;
|
|
163
|
+
if (referenceNode === model.rootNode) {
|
|
164
|
+
if (insertBeforeReference) {
|
|
165
|
+
compositeContainer = this._createDockContainer(direction, newNode, referenceNode);
|
|
166
|
+
compositeNode = new DockNode(compositeContainer);
|
|
167
|
+
compositeNode.addChild(newNode);
|
|
168
|
+
compositeNode.addChild(referenceNode);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
compositeContainer = this._createDockContainer(direction, referenceNode, newNode);
|
|
172
|
+
compositeNode = new DockNode(compositeContainer);
|
|
173
|
+
compositeNode.addChild(referenceNode);
|
|
174
|
+
compositeNode.addChild(newNode);
|
|
175
|
+
}
|
|
176
|
+
// Attach the root node to the dock manager's DOM
|
|
177
|
+
this.dockManager.setRootNode(compositeNode);
|
|
178
|
+
this.dockManager.rebuildLayout(this.dockManager.context.model.rootNode);
|
|
179
|
+
compositeNode.container.setActiveChild(newNode.container);
|
|
180
|
+
this.dockManager.invalidate();
|
|
181
|
+
this.dockManager.notifyOnDock(newNode);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (referenceNode.parent.container.containerType !== direction) {
|
|
185
|
+
referenceParent = referenceNode.parent;
|
|
186
|
+
// Get the dimensions of the reference node, for resizing later on
|
|
187
|
+
let referenceNodeWidth = referenceNode.container.containerElement.clientWidth;
|
|
188
|
+
let referenceNodeHeight = referenceNode.container.containerElement.clientHeight;
|
|
189
|
+
// Get the dimensions of the reference node, for resizing later on
|
|
190
|
+
let referenceNodeParentWidth = referenceParent.container.containerElement.clientWidth;
|
|
191
|
+
let referenceNodeParentHeight = referenceParent.container.containerElement.clientHeight;
|
|
192
|
+
// Replace the reference node with a new composite node with the reference and new node as it's children
|
|
193
|
+
compositeContainer = this._createDockContainer(direction, newNode, referenceNode);
|
|
194
|
+
compositeNode = new DockNode(compositeContainer);
|
|
195
|
+
referenceParent.addChildAfter(referenceNode, compositeNode);
|
|
196
|
+
referenceNode.detachFromParent();
|
|
197
|
+
Utils.removeNode(referenceNode.container.containerElement);
|
|
198
|
+
if (insertBeforeReference) {
|
|
199
|
+
compositeNode.addChild(newNode);
|
|
200
|
+
compositeNode.addChild(referenceNode);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
compositeNode.addChild(referenceNode);
|
|
204
|
+
compositeNode.addChild(newNode);
|
|
205
|
+
}
|
|
206
|
+
referenceParent.performLayout(false);
|
|
207
|
+
compositeNode.performLayout(true);
|
|
208
|
+
compositeNode.container.setActiveChild(newNode.container);
|
|
209
|
+
compositeNode.container.resize(referenceNodeWidth, referenceNodeHeight);
|
|
210
|
+
referenceParent.container.resize(referenceNodeParentWidth, referenceNodeParentHeight);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
// Add as a sibling, since the parent of the reference node is of the right composite type
|
|
214
|
+
referenceParent = referenceNode.parent;
|
|
215
|
+
if (insertBeforeReference)
|
|
216
|
+
referenceParent.addChildBefore(referenceNode, newNode);
|
|
217
|
+
else
|
|
218
|
+
referenceParent.addChildAfter(referenceNode, newNode);
|
|
219
|
+
referenceParent.performLayout(false);
|
|
220
|
+
referenceParent.container.setActiveChild(newNode.container);
|
|
221
|
+
}
|
|
222
|
+
// force resize the panel
|
|
223
|
+
let containerWidth = newNode.container.containerElement.clientWidth;
|
|
224
|
+
let containerHeight = newNode.container.containerElement.clientHeight;
|
|
225
|
+
newNode.container.resize(containerWidth, containerHeight);
|
|
226
|
+
this.dockManager.invalidate();
|
|
227
|
+
this.dockManager.notifyOnDock(newNode);
|
|
228
|
+
}
|
|
229
|
+
_createDockContainer(containerType, newNode, referenceNode) {
|
|
230
|
+
if (containerType === 'horizontal')
|
|
231
|
+
return new HorizontalDockContainer(this.dockManager, [newNode.container, referenceNode.container]);
|
|
232
|
+
if (containerType === 'vertical')
|
|
233
|
+
return new VerticalDockContainer(this.dockManager, [newNode.container, referenceNode.container]);
|
|
234
|
+
if (containerType === 'fill')
|
|
235
|
+
return new FillDockContainer(this.dockManager);
|
|
236
|
+
throw new Error('Failed to create dock container of type: ' + containerType);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Gets the bounds of the new node if it were to dock with the specified configuration
|
|
240
|
+
* The state is not modified in this function. It is used for showing a preview of where
|
|
241
|
+
* the panel would be docked when hovered over a dock wheel button
|
|
242
|
+
*/
|
|
243
|
+
getDockBounds(referenceNode, containerToDock, direction, insertBeforeReference) {
|
|
244
|
+
let compositeNode; // The node that contains the splitter / fill node
|
|
245
|
+
let childCount;
|
|
246
|
+
let childPosition;
|
|
247
|
+
let bounds;
|
|
248
|
+
if (direction === 'fill') {
|
|
249
|
+
// Since this is a fill operation, the highlight bounds is the same as the reference node
|
|
250
|
+
// TODO: Create a tab handle highlight to show that it's going to be docked in a tab
|
|
251
|
+
let targetElement = referenceNode.container.containerElement;
|
|
252
|
+
let outerRect = this.dockManager.element.getBoundingClientRect();
|
|
253
|
+
let targetElementRect = targetElement.getBoundingClientRect();
|
|
254
|
+
return { x: targetElementRect.left - outerRect.left, y: targetElementRect.top - outerRect.top, width: targetElement.clientWidth, height: targetElement.clientHeight };
|
|
255
|
+
}
|
|
256
|
+
if (referenceNode.parent && referenceNode.parent.container.containerType === 'fill')
|
|
257
|
+
// Ignore the fill container's child and move one level up
|
|
258
|
+
referenceNode = referenceNode.parent;
|
|
259
|
+
// Flag to indicate of the renference node was replaced with a new composite node with 2 children
|
|
260
|
+
let hierarchyModified = false;
|
|
261
|
+
if (referenceNode.parent && referenceNode.parent.container.containerType === direction) {
|
|
262
|
+
// The parent already is of the desired composite type. Will be inserted as sibling to the reference node
|
|
263
|
+
compositeNode = referenceNode.parent;
|
|
264
|
+
childCount = compositeNode.children.length;
|
|
265
|
+
childPosition = compositeNode.children.indexOf(referenceNode) + (insertBeforeReference ? 0 : 1);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// The reference node will be replaced with a new composite node of the desired type with 2 children
|
|
269
|
+
compositeNode = referenceNode;
|
|
270
|
+
childCount = 1; // The newly inserted composite node will contain the reference node
|
|
271
|
+
childPosition = (insertBeforeReference ? 0 : 1);
|
|
272
|
+
hierarchyModified = true;
|
|
273
|
+
}
|
|
274
|
+
let splitBarSize = 5; // TODO: Get from DOM
|
|
275
|
+
let targetPanelSize = 0;
|
|
276
|
+
let targetPanelStart = 0;
|
|
277
|
+
if (direction === 'vertical' || direction === 'horizontal') {
|
|
278
|
+
// Existing size of the composite container (without the splitter bars).
|
|
279
|
+
// This will also be the final size of the composite (splitter / fill)
|
|
280
|
+
// container after the new panel has been docked
|
|
281
|
+
let compositeSize = this._getVaringDimension(compositeNode.container, direction) - (childCount - 1) * splitBarSize;
|
|
282
|
+
// size of the newly added panel
|
|
283
|
+
let newPanelOriginalSize = this._getVaringDimension(containerToDock, direction);
|
|
284
|
+
let scaleMultiplier = compositeSize / (compositeSize + newPanelOriginalSize);
|
|
285
|
+
// Size of the panel after it has been docked and scaled
|
|
286
|
+
targetPanelSize = newPanelOriginalSize * scaleMultiplier;
|
|
287
|
+
if (hierarchyModified)
|
|
288
|
+
targetPanelStart = insertBeforeReference ? 0 : compositeSize * scaleMultiplier;
|
|
289
|
+
else {
|
|
290
|
+
for (let i = 0; i < childPosition; i++)
|
|
291
|
+
targetPanelStart += this._getVaringDimension(compositeNode.children[i].container, direction);
|
|
292
|
+
targetPanelStart *= scaleMultiplier;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
bounds = {};
|
|
296
|
+
let outerRect = this.dockManager.element.getBoundingClientRect();
|
|
297
|
+
let rect = compositeNode.container.containerElement.getBoundingClientRect();
|
|
298
|
+
if (direction === 'vertical') {
|
|
299
|
+
bounds.x = rect.left - outerRect.left;
|
|
300
|
+
bounds.y = rect.top - outerRect.top + targetPanelStart;
|
|
301
|
+
bounds.width = compositeNode.container.width;
|
|
302
|
+
bounds.height = targetPanelSize;
|
|
303
|
+
}
|
|
304
|
+
else if (direction === 'horizontal') {
|
|
305
|
+
bounds.x = rect.left - outerRect.left + targetPanelStart;
|
|
306
|
+
bounds.y = rect.top - outerRect.top;
|
|
307
|
+
bounds.width = targetPanelSize;
|
|
308
|
+
bounds.height = compositeNode.container.height;
|
|
309
|
+
}
|
|
310
|
+
return bounds;
|
|
311
|
+
}
|
|
312
|
+
_getVaringDimension(container, direction) {
|
|
313
|
+
if (direction === 'vertical')
|
|
314
|
+
return container.height;
|
|
315
|
+
if (direction === 'horizontal')
|
|
316
|
+
return container.width;
|
|
317
|
+
return 0;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
320
|
//# sourceMappingURL=DockLayoutEngine.js.map
|