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.
Files changed (103) hide show
  1. package/lib/es5/dock-spawn-ts.js +1 -1
  2. package/lib/js/ContainerType.d.ts +6 -6
  3. package/lib/js/ContainerType.js +7 -7
  4. package/lib/js/Dialog.d.ts +43 -43
  5. package/lib/js/Dialog.js +136 -136
  6. package/lib/js/DockConfig.d.ts +7 -7
  7. package/lib/js/DockConfig.js +8 -8
  8. package/lib/js/DockGraphDeserializer.d.ts +18 -18
  9. package/lib/js/DockGraphDeserializer.js +116 -116
  10. package/lib/js/DockGraphSerializer.d.ts +13 -13
  11. package/lib/js/DockGraphSerializer.js +40 -40
  12. package/lib/js/DockLayoutEngine.d.ts +35 -35
  13. package/lib/js/DockLayoutEngine.js +319 -319
  14. package/lib/js/DockManager.d.ts +153 -153
  15. package/lib/js/DockManager.js +728 -728
  16. package/lib/js/DockManagerContext.d.ts +9 -9
  17. package/lib/js/DockManagerContext.js +9 -9
  18. package/lib/js/DockModel.d.ts +8 -8
  19. package/lib/js/DockModel.js +5 -5
  20. package/lib/js/DockNode.d.ts +15 -15
  21. package/lib/js/DockNode.js +61 -61
  22. package/lib/js/DockWheel.d.ts +40 -40
  23. package/lib/js/DockWheel.js +200 -200
  24. package/lib/js/DockWheelItem.d.ts +15 -15
  25. package/lib/js/DockWheelItem.js +27 -27
  26. package/lib/js/DocumentManagerContainer.d.ts +16 -16
  27. package/lib/js/DocumentManagerContainer.js +28 -28
  28. package/lib/js/DocumentTabPage.d.ts +14 -14
  29. package/lib/js/DocumentTabPage.js +26 -26
  30. package/lib/js/DraggableContainer.d.ts +52 -52
  31. package/lib/js/DraggableContainer.js +183 -183
  32. package/lib/js/EventHandler.d.ts +7 -7
  33. package/lib/js/EventHandler.js +11 -11
  34. package/lib/js/Exports.d.ts +30 -30
  35. package/lib/js/Exports.js +30 -30
  36. package/lib/js/FillDockContainer.d.ts +33 -33
  37. package/lib/js/FillDockContainer.js +69 -69
  38. package/lib/js/HorizontalDockContainer.d.ts +6 -6
  39. package/lib/js/HorizontalDockContainer.js +9 -9
  40. package/lib/js/PanelContainer.d.ts +101 -101
  41. package/lib/js/PanelContainer.js +384 -384
  42. package/lib/js/PanelContainer.js.map +1 -1
  43. package/lib/js/Point.d.ts +5 -5
  44. package/lib/js/Point.js +6 -6
  45. package/lib/js/ResizableContainer.d.ts +55 -55
  46. package/lib/js/ResizableContainer.js +241 -241
  47. package/lib/js/ResizeHandle.d.ts +15 -15
  48. package/lib/js/ResizeHandle.js +48 -48
  49. package/lib/js/SplitterBar.d.ts +35 -35
  50. package/lib/js/SplitterBar.js +149 -149
  51. package/lib/js/SplitterDockContainer.d.ts +35 -35
  52. package/lib/js/SplitterDockContainer.js +65 -65
  53. package/lib/js/SplitterPanel.d.ts +26 -26
  54. package/lib/js/SplitterPanel.js +191 -191
  55. package/lib/js/TabHandle.d.ts +55 -55
  56. package/lib/js/TabHandle.js +261 -260
  57. package/lib/js/TabHandle.js.map +1 -1
  58. package/lib/js/TabHost.d.ts +46 -46
  59. package/lib/js/TabHost.js +223 -223
  60. package/lib/js/TabHost.js.map +1 -1
  61. package/lib/js/TabPage.d.ts +19 -19
  62. package/lib/js/TabPage.js +74 -73
  63. package/lib/js/TabPage.js.map +1 -1
  64. package/lib/js/UndockInitiator.d.ts +31 -31
  65. package/lib/js/UndockInitiator.js +140 -140
  66. package/lib/js/Utils.d.ts +14 -14
  67. package/lib/js/Utils.js +70 -69
  68. package/lib/js/Utils.js.map +1 -1
  69. package/lib/js/VerticalDockContainer.d.ts +6 -6
  70. package/lib/js/VerticalDockContainer.js +9 -9
  71. package/lib/js/enums/PanelType.d.ts +4 -4
  72. package/lib/js/enums/PanelType.js +5 -5
  73. package/lib/js/enums/TabHostDirection.d.ts +6 -6
  74. package/lib/js/enums/TabHostDirection.js +7 -7
  75. package/lib/js/enums/WheelTypes.d.ts +11 -11
  76. package/lib/js/enums/WheelTypes.js +14 -14
  77. package/lib/js/interfaces/IDockContainer.d.ts +25 -25
  78. package/lib/js/interfaces/IDockContainer.js +1 -1
  79. package/lib/js/interfaces/IDockContainerWithSize.d.ts +5 -5
  80. package/lib/js/interfaces/IDockContainerWithSize.js +1 -1
  81. package/lib/js/interfaces/ILayoutEventListener.d.ts +26 -26
  82. package/lib/js/interfaces/ILayoutEventListener.js +1 -1
  83. package/lib/js/interfaces/IMouseOrTouchEvent.d.ts +6 -6
  84. package/lib/js/interfaces/IMouseOrTouchEvent.js +1 -1
  85. package/lib/js/interfaces/INodeInfo.d.ts +7 -7
  86. package/lib/js/interfaces/INodeInfo.js +1 -1
  87. package/lib/js/interfaces/IPanelInfo.d.ts +9 -9
  88. package/lib/js/interfaces/IPanelInfo.js +1 -1
  89. package/lib/js/interfaces/IRectangle.d.ts +6 -6
  90. package/lib/js/interfaces/IRectangle.js +1 -1
  91. package/lib/js/interfaces/ISize.d.ts +4 -4
  92. package/lib/js/interfaces/ISize.js +1 -1
  93. package/lib/js/interfaces/IState.d.ts +10 -10
  94. package/lib/js/interfaces/IState.js +1 -1
  95. package/lib/js/interfaces/IThickness.d.ts +6 -6
  96. package/lib/js/interfaces/IThickness.js +1 -1
  97. package/lib/js/webcomponent/DockSpawnTsWebcomponent.d.ts +30 -30
  98. package/lib/js/webcomponent/DockSpawnTsWebcomponent.js +153 -152
  99. package/lib/js/webcomponent/DockSpawnTsWebcomponent.js.map +1 -1
  100. package/package.json +6 -6
  101. package/src/PanelContainer.ts +1 -1
  102. package/src/TabHost.ts +5 -5
  103. package/src/TabPage.ts +4 -3
@@ -1,385 +1,385 @@
1
- import { Utils } from "./Utils.js";
2
- import { UndockInitiator } from "./UndockInitiator.js";
3
- import { ContainerType } from "./ContainerType.js";
4
- import { EventHandler } from "./EventHandler.js";
5
- import { PanelType } from "./enums/PanelType.js";
6
- /**
7
- * This dock container wraps the specified element on a panel frame with a title bar and close button
8
- */
9
- export class PanelContainer {
10
- constructor(elementContent, dockManager, title, panelType, hideCloseButton) {
11
- if (!title)
12
- title = 'Panel';
13
- if (!panelType)
14
- panelType = PanelType.panel;
15
- this.panelType = panelType;
16
- elementContent._dockSpawnPanelContainer = this;
17
- this.elementContent = elementContent;
18
- elementContent.style.position = 'absolute';
19
- elementContent.style.width = '100%';
20
- elementContent.style.height = '100%';
21
- elementContent.style.top = '0';
22
- elementContent.style.bottom = '0';
23
- elementContent.hidden = false;
24
- this.elementContentContainer = document.createElement('div');
25
- this.elementContentContainer.className = 'panel-element-content-container';
26
- this.elementContentContainer.style.position = 'absolute';
27
- this.elementContentContainer._panel = this;
28
- this.elementContentContainer.addEventListener('pointerdown', () => {
29
- if (this.isDialog) {
30
- this._floatingDialog.bringToFront();
31
- }
32
- else {
33
- if (this.tabPage)
34
- this.tabPage.setSelected(true);
35
- }
36
- this.dockManager.activePanel = this;
37
- });
38
- this.elementContentContainer.appendChild(elementContent);
39
- dockManager.config.dialogRootElement.appendChild(this.elementContentContainer);
40
- this.dockManager = dockManager;
41
- this.title = title;
42
- this.containerType = ContainerType.panel;
43
- this.icon = null;
44
- this.minimumAllowedChildNodes = 0;
45
- this._floatingDialog = undefined;
46
- this.isDialog = false;
47
- this._canUndock = dockManager._undockEnabled;
48
- this.eventListeners = [];
49
- this._hideCloseButton = hideCloseButton;
50
- this._initialize();
51
- }
52
- canUndock(state) {
53
- this._canUndock = state;
54
- this.undockInitiator.enabled = state;
55
- this.eventListeners.forEach((listener) => {
56
- if (listener.onDockEnabled) {
57
- listener.onDockEnabled({ self: this, state: state });
58
- }
59
- });
60
- }
61
- addListener(listener) {
62
- this.eventListeners.push(listener);
63
- }
64
- removeListener(listener) {
65
- this.eventListeners.splice(this.eventListeners.indexOf(listener), 1);
66
- }
67
- get floatingDialog() {
68
- return this._floatingDialog;
69
- }
70
- set floatingDialog(value) {
71
- this._floatingDialog = value;
72
- let canUndock = (this._floatingDialog === undefined);
73
- this.undockInitiator.enabled = canUndock;
74
- }
75
- static async loadFromState(state, dockManager) {
76
- let elementContent;
77
- let title;
78
- if (!dockManager.getElementCallback) {
79
- let elementName = state.element;
80
- elementContent = document.getElementById(elementName);
81
- }
82
- else {
83
- let res = await dockManager.getElementCallback(state);
84
- elementContent = res.element;
85
- title = res.title;
86
- }
87
- if (elementContent === null) {
88
- return null;
89
- }
90
- let ret = new PanelContainer(elementContent, dockManager, title);
91
- ret.loadState(state);
92
- return ret;
93
- }
94
- saveState(state) {
95
- state.element = this.elementContent.id;
96
- state.width = this.width;
97
- state.height = this.height;
98
- state.canUndock = this._canUndock;
99
- state.hideCloseButton = this._hideCloseButton;
100
- state.panelType = this.panelType;
101
- }
102
- loadState(state) {
103
- this.width = state.width;
104
- this.height = state.height;
105
- this.state = { width: state.width, height: state.height };
106
- this.canUndock(state.canUndock);
107
- this.hideCloseButton(state.hideCloseButton);
108
- this.panelType = state.panelType;
109
- }
110
- setActiveChild( /*child*/) {
111
- }
112
- get containerElement() {
113
- return this.elementPanel;
114
- }
115
- grayOut(show) {
116
- if (!show && this._grayOut) {
117
- this.elementContentWrapper.removeChild(this._grayOut);
118
- this.elementButtonClose.style.display = this._hideCloseButton ? 'none' : 'block';
119
- this._grayOut = null;
120
- if (!this._hideCloseButton)
121
- this.eventListeners.forEach((listener) => {
122
- if (listener.onHideCloseButton) {
123
- listener.onHideCloseButton({ self: this, state: this._hideCloseButton });
124
- }
125
- });
126
- }
127
- else if (show && !this._grayOut) {
128
- this._grayOut = document.createElement('div');
129
- this._grayOut.className = 'panel-grayout';
130
- this.elementButtonClose.style.display = 'none';
131
- this.elementContentWrapper.appendChild(this._grayOut);
132
- this.eventListeners.forEach((listener) => {
133
- if (listener.onHideCloseButton) {
134
- listener.onHideCloseButton({ self: this, state: true });
135
- }
136
- });
137
- }
138
- }
139
- _initialize() {
140
- this.name = Utils.getNextId('panel_');
141
- this.elementPanel = document.createElement('div');
142
- this.elementPanel.tabIndex = 0;
143
- this.elementTitle = document.createElement('div');
144
- this.elementTitleText = document.createElement('div');
145
- this.elementContentHost = document.createElement('div');
146
- this.elementButtonClose = document.createElement('div');
147
- this.elementPanel.appendChild(this.elementTitle);
148
- this.elementTitle.appendChild(this.elementTitleText);
149
- this.elementTitle.appendChild(this.elementButtonClose);
150
- this.elementButtonClose.classList.add('panel-titlebar-button-close');
151
- this.elementButtonClose.style.display = this._hideCloseButton ? 'none' : 'block';
152
- this.elementPanel.appendChild(this.elementContentHost);
153
- this.elementPanel.classList.add('panel-base');
154
- this.elementTitle.classList.add('panel-titlebar');
155
- this.elementTitle.classList.add('disable-selection');
156
- this.elementTitleText.classList.add('panel-titlebar-text');
157
- this.elementContentHost.classList.add('panel-content');
158
- // set the size of the dialog elements based on the panel's size
159
- let panelWidth = this.elementContentContainer.clientWidth;
160
- let panelHeight = this.elementContentContainer.clientHeight;
161
- let titleHeight = this.elementTitle.clientHeight;
162
- this.elementContentWrapper = document.createElement("div");
163
- this.elementContentWrapper.classList.add('panel-content-wrapper');
164
- this._setPanelDimensions(panelWidth, panelHeight + titleHeight);
165
- if (!this._hideCloseButton) {
166
- this.closeButtonClickedHandler =
167
- new EventHandler(this.elementButtonClose, 'mousedown', this.onCloseButtonClicked.bind(this));
168
- this.closeButtonTouchedHandler =
169
- new EventHandler(this.elementButtonClose, 'touchstart', this.onCloseButtonClicked.bind(this));
170
- }
171
- Utils.removeNode(this.elementContentWrapper);
172
- this.elementContentHost.appendChild(this.elementContentWrapper);
173
- // Extract the title from the content element's attribute
174
- let contentTitle = this.elementContent.dataset.panelCaption;
175
- let contentIcon = this.elementContent.dataset.panelIcon;
176
- if (contentTitle)
177
- this.title = contentTitle;
178
- if (contentIcon)
179
- this.icon = contentIcon;
180
- this._updateTitle();
181
- this.undockInitiator = new UndockInitiator(this.elementTitle, this.performUndockToDialog.bind(this));
182
- delete this.floatingDialog;
183
- this.mouseDownHandler = new EventHandler(this.elementPanel, 'mousedown', this.onMouseDown.bind(this));
184
- this.touchDownHandler = new EventHandler(this.elementPanel, 'touchstart', this.onMouseDown.bind(this));
185
- this.elementContent.removeAttribute("hidden");
186
- }
187
- onMouseDown() {
188
- this.dockManager.activePanel = this;
189
- }
190
- hideCloseButton(state) {
191
- this._hideCloseButton = state;
192
- this.elementButtonClose.style.display = state ? 'none' : 'block';
193
- this.eventListeners.forEach((listener) => {
194
- if (listener.onHideCloseButton) {
195
- listener.onHideCloseButton({ self: this, state: state });
196
- }
197
- });
198
- }
199
- destroy() {
200
- if (this.mouseDownHandler) {
201
- this.mouseDownHandler.cancel();
202
- delete this.mouseDownHandler;
203
- }
204
- if (this.touchDownHandler) {
205
- this.touchDownHandler.cancel();
206
- delete this.touchDownHandler;
207
- }
208
- Utils.removeNode(this.elementPanel);
209
- if (this.closeButtonClickedHandler) {
210
- this.closeButtonClickedHandler.cancel();
211
- delete this.closeButtonClickedHandler;
212
- }
213
- if (this.closeButtonTouchedHandler) {
214
- this.closeButtonTouchedHandler.cancel();
215
- delete this.closeButtonTouchedHandler;
216
- }
217
- }
218
- /**
219
- * Undocks the panel and and converts it to a dialog box
220
- */
221
- performUndockToDialog(e, dragOffset) {
222
- this.isDialog = true;
223
- this.undockInitiator.enabled = false;
224
- this.elementContentWrapper.style.display = "block";
225
- this.elementPanel.style.position = "";
226
- return this.dockManager.requestUndockToDialog(this, e, dragOffset);
227
- }
228
- /**
229
- * Closes the panel
230
- */
231
- performClose() {
232
- this.isDialog = true;
233
- this.undockInitiator.enabled = false;
234
- this.elementContentWrapper.style.display = "block";
235
- this.elementContentContainer.style.display = 'none';
236
- this.elementPanel.style.position = "";
237
- this.dockManager.requestClose(this);
238
- }
239
- /**
240
- * Undocks the container and from the layout hierarchy
241
- * The container would be removed from the DOM
242
- */
243
- performUndock() {
244
- this.undockInitiator.enabled = false;
245
- this.dockManager.requestUndock(this);
246
- }
247
- ;
248
- prepareForDocking() {
249
- this.isDialog = false;
250
- this.undockInitiator.enabled = this._canUndock;
251
- if (this.elementContentContainer.parentElement != this.dockManager.config.dialogRootElement)
252
- this.dockManager.config.dialogRootElement.appendChild(this.elementContentContainer);
253
- }
254
- get width() {
255
- return this._cachedWidth;
256
- }
257
- set width(value) {
258
- if (value !== this._cachedWidth) {
259
- this._cachedWidth = value;
260
- this.elementPanel.style.width = value + 'px';
261
- }
262
- }
263
- get height() {
264
- return this._cachedHeight;
265
- }
266
- set height(value) {
267
- if (value !== this._cachedHeight) {
268
- this._cachedHeight = value;
269
- this.elementPanel.style.height = value + 'px';
270
- }
271
- }
272
- resize(width, height) {
273
- // if (this._cachedWidth === width && this._cachedHeight === height)
274
- // {
275
- // // Already in the desired size
276
- // return;
277
- // }
278
- this.setVisible(true);
279
- this._setPanelDimensions(width, height);
280
- this._cachedWidth = width;
281
- this._cachedHeight = height;
282
- try {
283
- if (this.elementContent != undefined && (typeof this.elementContent.resizeHandler == 'function'))
284
- this.elementContent.resizeHandler(width, height - this.elementTitle.clientHeight);
285
- }
286
- catch (err) {
287
- console.log("error calling resizeHandler:", err, " elt:", this.elementContent);
288
- }
289
- }
290
- _setPanelDimensions(width, height) {
291
- this.elementTitle.style.width = width + 'px';
292
- this.elementContentHost.style.width = width + 'px';
293
- this.elementContentContainer.style.width = width + 'px';
294
- this.elementPanel.style.width = width + 'px';
295
- let titleBarHeight = this.elementTitle.clientHeight;
296
- let contentHeight = height - titleBarHeight;
297
- this.elementContentHost.style.height = contentHeight + 'px';
298
- this.elementContentContainer.style.height = contentHeight + 'px';
299
- this.elementPanel.style.height = height + 'px';
300
- //if (this.elementContentContainer.parentElement != this.dockManager.config.dialogRootElement)
301
- // this.dockManager.config.dialogRootElement.appendChild(this.elementContentContainer);
302
- const rect = this.elementContentWrapper.getBoundingClientRect();
303
- const rootRect = this.dockManager.config.dialogRootElement.getBoundingClientRect();
304
- this.elementContentContainer.style.left = (rect.x /*- rootRect.x*/) + 'px';
305
- this.elementContentContainer.style.top = (rect.y - rootRect.y) + 'px';
306
- this.elementContentContainer.style.width = rect.width + 'px';
307
- this.elementContentContainer.style.height = rect.height + 'px';
308
- }
309
- setDialogPosition(x, y) {
310
- const rootRect = this.dockManager.config.dialogRootElement.getBoundingClientRect();
311
- this.elementContentContainer.style.left = (x - rootRect.x) + 'px';
312
- //todo, 25px if it is a dialog, is it always 25px? where do we know...
313
- this.elementContentContainer.style.top = (y + this.elementTitle.clientHeight /*- rootRect.y*/) + 'px';
314
- }
315
- setVisible(isVisible) {
316
- this.elementContentContainer.style.display = isVisible ? 'block' : 'none';
317
- }
318
- setTitle(title) {
319
- this.title = title;
320
- this._updateTitle();
321
- if (this.onTitleChanged)
322
- this.onTitleChanged(this, title);
323
- }
324
- setTitleIcon(icon) {
325
- this.icon = icon;
326
- this._updateTitle();
327
- if (this.onTitleChanged)
328
- this.onTitleChanged(this, this.title);
329
- }
330
- setHasChanges(changes) {
331
- this.hasChanges = changes;
332
- this._updateTitle();
333
- if (changes) {
334
- this.elementTitleText.classList.add('panel-has-changes');
335
- }
336
- else {
337
- this.elementTitleText.classList.remove('panel-has-changes');
338
- }
339
- if (this.onTitleChanged)
340
- this.onTitleChanged(this, this.title);
341
- }
342
- setCloseIconTemplate(closeIconTemplate) {
343
- this.elementButtonClose.innerHTML = closeIconTemplate;
344
- }
345
- _updateTitle() {
346
- if (this.icon !== null) {
347
- this.elementTitleText.innerHTML = '<img class="panel-titlebar-icon" src="' + this.icon + '"><span>' + this.title + '</span>';
348
- return;
349
- }
350
- this.elementTitleText.innerHTML = this.title;
351
- }
352
- getRawTitle() {
353
- return this.elementTitleText.innerHTML;
354
- }
355
- performLayout(children, relayoutEvenIfEqual) {
356
- }
357
- onCloseButtonClicked(e) {
358
- e.preventDefault();
359
- e.stopPropagation();
360
- this.close();
361
- }
362
- async close() {
363
- let close = true;
364
- if (this.elementContentContainer.parentElement === this.dockManager.config.dialogRootElement) {
365
- this.dockManager.config.dialogRootElement.removeChild(this.elementContentContainer);
366
- if (this.closePanelContainerCallback)
367
- close = await this.closePanelContainerCallback(this);
368
- else if (this.dockManager.closePanelContainerCallback)
369
- close = await this.dockManager.closePanelContainerCallback(this);
370
- if (close) {
371
- if (this.isDialog) {
372
- if (this.floatingDialog) {
373
- //this.floatingDialog.hide();
374
- this.floatingDialog.close(); // fires onClose notification
375
- }
376
- }
377
- else {
378
- this.performClose();
379
- this.dockManager.notifyOnClosePanel(this);
380
- }
381
- }
382
- }
383
- }
384
- }
1
+ import { Utils } from "./Utils.js";
2
+ import { UndockInitiator } from "./UndockInitiator.js";
3
+ import { ContainerType } from "./ContainerType.js";
4
+ import { EventHandler } from "./EventHandler.js";
5
+ import { PanelType } from "./enums/PanelType.js";
6
+ /**
7
+ * This dock container wraps the specified element on a panel frame with a title bar and close button
8
+ */
9
+ export class PanelContainer {
10
+ constructor(elementContent, dockManager, title, panelType, hideCloseButton) {
11
+ if (!title)
12
+ title = 'Panel';
13
+ if (!panelType)
14
+ panelType = PanelType.panel;
15
+ this.panelType = panelType;
16
+ elementContent._dockSpawnPanelContainer = this;
17
+ this.elementContent = elementContent;
18
+ elementContent.style.position = 'absolute';
19
+ elementContent.style.width = '100%';
20
+ elementContent.style.height = '100%';
21
+ elementContent.style.top = '0';
22
+ elementContent.style.bottom = '0';
23
+ elementContent.hidden = false;
24
+ this.elementContentContainer = document.createElement('div');
25
+ this.elementContentContainer.className = 'panel-element-content-container';
26
+ this.elementContentContainer.style.position = 'absolute';
27
+ this.elementContentContainer._panel = this;
28
+ this.elementContentContainer.addEventListener('pointerdown', () => {
29
+ if (this.isDialog) {
30
+ this._floatingDialog.bringToFront();
31
+ }
32
+ else {
33
+ if (this.tabPage)
34
+ this.tabPage.setSelected(true, true);
35
+ }
36
+ this.dockManager.activePanel = this;
37
+ });
38
+ this.elementContentContainer.appendChild(elementContent);
39
+ dockManager.config.dialogRootElement.appendChild(this.elementContentContainer);
40
+ this.dockManager = dockManager;
41
+ this.title = title;
42
+ this.containerType = ContainerType.panel;
43
+ this.icon = null;
44
+ this.minimumAllowedChildNodes = 0;
45
+ this._floatingDialog = undefined;
46
+ this.isDialog = false;
47
+ this._canUndock = dockManager._undockEnabled;
48
+ this.eventListeners = [];
49
+ this._hideCloseButton = hideCloseButton;
50
+ this._initialize();
51
+ }
52
+ canUndock(state) {
53
+ this._canUndock = state;
54
+ this.undockInitiator.enabled = state;
55
+ this.eventListeners.forEach((listener) => {
56
+ if (listener.onDockEnabled) {
57
+ listener.onDockEnabled({ self: this, state: state });
58
+ }
59
+ });
60
+ }
61
+ addListener(listener) {
62
+ this.eventListeners.push(listener);
63
+ }
64
+ removeListener(listener) {
65
+ this.eventListeners.splice(this.eventListeners.indexOf(listener), 1);
66
+ }
67
+ get floatingDialog() {
68
+ return this._floatingDialog;
69
+ }
70
+ set floatingDialog(value) {
71
+ this._floatingDialog = value;
72
+ let canUndock = (this._floatingDialog === undefined);
73
+ this.undockInitiator.enabled = canUndock;
74
+ }
75
+ static async loadFromState(state, dockManager) {
76
+ let elementContent;
77
+ let title;
78
+ if (!dockManager.getElementCallback) {
79
+ let elementName = state.element;
80
+ elementContent = document.getElementById(elementName);
81
+ }
82
+ else {
83
+ let res = await dockManager.getElementCallback(state);
84
+ elementContent = res.element;
85
+ title = res.title;
86
+ }
87
+ if (elementContent === null) {
88
+ return null;
89
+ }
90
+ let ret = new PanelContainer(elementContent, dockManager, title);
91
+ ret.loadState(state);
92
+ return ret;
93
+ }
94
+ saveState(state) {
95
+ state.element = this.elementContent.id;
96
+ state.width = this.width;
97
+ state.height = this.height;
98
+ state.canUndock = this._canUndock;
99
+ state.hideCloseButton = this._hideCloseButton;
100
+ state.panelType = this.panelType;
101
+ }
102
+ loadState(state) {
103
+ this.width = state.width;
104
+ this.height = state.height;
105
+ this.state = { width: state.width, height: state.height };
106
+ this.canUndock(state.canUndock);
107
+ this.hideCloseButton(state.hideCloseButton);
108
+ this.panelType = state.panelType;
109
+ }
110
+ setActiveChild( /*child*/) {
111
+ }
112
+ get containerElement() {
113
+ return this.elementPanel;
114
+ }
115
+ grayOut(show) {
116
+ if (!show && this._grayOut) {
117
+ this.elementContentWrapper.removeChild(this._grayOut);
118
+ this.elementButtonClose.style.display = this._hideCloseButton ? 'none' : 'block';
119
+ this._grayOut = null;
120
+ if (!this._hideCloseButton)
121
+ this.eventListeners.forEach((listener) => {
122
+ if (listener.onHideCloseButton) {
123
+ listener.onHideCloseButton({ self: this, state: this._hideCloseButton });
124
+ }
125
+ });
126
+ }
127
+ else if (show && !this._grayOut) {
128
+ this._grayOut = document.createElement('div');
129
+ this._grayOut.className = 'panel-grayout';
130
+ this.elementButtonClose.style.display = 'none';
131
+ this.elementContentWrapper.appendChild(this._grayOut);
132
+ this.eventListeners.forEach((listener) => {
133
+ if (listener.onHideCloseButton) {
134
+ listener.onHideCloseButton({ self: this, state: true });
135
+ }
136
+ });
137
+ }
138
+ }
139
+ _initialize() {
140
+ this.name = Utils.getNextId('panel_');
141
+ this.elementPanel = document.createElement('div');
142
+ this.elementPanel.tabIndex = 0;
143
+ this.elementTitle = document.createElement('div');
144
+ this.elementTitleText = document.createElement('div');
145
+ this.elementContentHost = document.createElement('div');
146
+ this.elementButtonClose = document.createElement('div');
147
+ this.elementPanel.appendChild(this.elementTitle);
148
+ this.elementTitle.appendChild(this.elementTitleText);
149
+ this.elementTitle.appendChild(this.elementButtonClose);
150
+ this.elementButtonClose.classList.add('panel-titlebar-button-close');
151
+ this.elementButtonClose.style.display = this._hideCloseButton ? 'none' : 'block';
152
+ this.elementPanel.appendChild(this.elementContentHost);
153
+ this.elementPanel.classList.add('panel-base');
154
+ this.elementTitle.classList.add('panel-titlebar');
155
+ this.elementTitle.classList.add('disable-selection');
156
+ this.elementTitleText.classList.add('panel-titlebar-text');
157
+ this.elementContentHost.classList.add('panel-content');
158
+ // set the size of the dialog elements based on the panel's size
159
+ let panelWidth = this.elementContentContainer.clientWidth;
160
+ let panelHeight = this.elementContentContainer.clientHeight;
161
+ let titleHeight = this.elementTitle.clientHeight;
162
+ this.elementContentWrapper = document.createElement("div");
163
+ this.elementContentWrapper.classList.add('panel-content-wrapper');
164
+ this._setPanelDimensions(panelWidth, panelHeight + titleHeight);
165
+ if (!this._hideCloseButton) {
166
+ this.closeButtonClickedHandler =
167
+ new EventHandler(this.elementButtonClose, 'mousedown', this.onCloseButtonClicked.bind(this));
168
+ this.closeButtonTouchedHandler =
169
+ new EventHandler(this.elementButtonClose, 'touchstart', this.onCloseButtonClicked.bind(this));
170
+ }
171
+ Utils.removeNode(this.elementContentWrapper);
172
+ this.elementContentHost.appendChild(this.elementContentWrapper);
173
+ // Extract the title from the content element's attribute
174
+ let contentTitle = this.elementContent.dataset.panelCaption;
175
+ let contentIcon = this.elementContent.dataset.panelIcon;
176
+ if (contentTitle)
177
+ this.title = contentTitle;
178
+ if (contentIcon)
179
+ this.icon = contentIcon;
180
+ this._updateTitle();
181
+ this.undockInitiator = new UndockInitiator(this.elementTitle, this.performUndockToDialog.bind(this));
182
+ delete this.floatingDialog;
183
+ this.mouseDownHandler = new EventHandler(this.elementPanel, 'mousedown', this.onMouseDown.bind(this));
184
+ this.touchDownHandler = new EventHandler(this.elementPanel, 'touchstart', this.onMouseDown.bind(this));
185
+ this.elementContent.removeAttribute("hidden");
186
+ }
187
+ onMouseDown() {
188
+ this.dockManager.activePanel = this;
189
+ }
190
+ hideCloseButton(state) {
191
+ this._hideCloseButton = state;
192
+ this.elementButtonClose.style.display = state ? 'none' : 'block';
193
+ this.eventListeners.forEach((listener) => {
194
+ if (listener.onHideCloseButton) {
195
+ listener.onHideCloseButton({ self: this, state: state });
196
+ }
197
+ });
198
+ }
199
+ destroy() {
200
+ if (this.mouseDownHandler) {
201
+ this.mouseDownHandler.cancel();
202
+ delete this.mouseDownHandler;
203
+ }
204
+ if (this.touchDownHandler) {
205
+ this.touchDownHandler.cancel();
206
+ delete this.touchDownHandler;
207
+ }
208
+ Utils.removeNode(this.elementPanel);
209
+ if (this.closeButtonClickedHandler) {
210
+ this.closeButtonClickedHandler.cancel();
211
+ delete this.closeButtonClickedHandler;
212
+ }
213
+ if (this.closeButtonTouchedHandler) {
214
+ this.closeButtonTouchedHandler.cancel();
215
+ delete this.closeButtonTouchedHandler;
216
+ }
217
+ }
218
+ /**
219
+ * Undocks the panel and and converts it to a dialog box
220
+ */
221
+ performUndockToDialog(e, dragOffset) {
222
+ this.isDialog = true;
223
+ this.undockInitiator.enabled = false;
224
+ this.elementContentWrapper.style.display = "block";
225
+ this.elementPanel.style.position = "";
226
+ return this.dockManager.requestUndockToDialog(this, e, dragOffset);
227
+ }
228
+ /**
229
+ * Closes the panel
230
+ */
231
+ performClose() {
232
+ this.isDialog = true;
233
+ this.undockInitiator.enabled = false;
234
+ this.elementContentWrapper.style.display = "block";
235
+ this.elementContentContainer.style.display = 'none';
236
+ this.elementPanel.style.position = "";
237
+ this.dockManager.requestClose(this);
238
+ }
239
+ /**
240
+ * Undocks the container and from the layout hierarchy
241
+ * The container would be removed from the DOM
242
+ */
243
+ performUndock() {
244
+ this.undockInitiator.enabled = false;
245
+ this.dockManager.requestUndock(this);
246
+ }
247
+ ;
248
+ prepareForDocking() {
249
+ this.isDialog = false;
250
+ this.undockInitiator.enabled = this._canUndock;
251
+ if (this.elementContentContainer.parentElement != this.dockManager.config.dialogRootElement)
252
+ this.dockManager.config.dialogRootElement.appendChild(this.elementContentContainer);
253
+ }
254
+ get width() {
255
+ return this._cachedWidth;
256
+ }
257
+ set width(value) {
258
+ if (value !== this._cachedWidth) {
259
+ this._cachedWidth = value;
260
+ this.elementPanel.style.width = value + 'px';
261
+ }
262
+ }
263
+ get height() {
264
+ return this._cachedHeight;
265
+ }
266
+ set height(value) {
267
+ if (value !== this._cachedHeight) {
268
+ this._cachedHeight = value;
269
+ this.elementPanel.style.height = value + 'px';
270
+ }
271
+ }
272
+ resize(width, height) {
273
+ // if (this._cachedWidth === width && this._cachedHeight === height)
274
+ // {
275
+ // // Already in the desired size
276
+ // return;
277
+ // }
278
+ this.setVisible(true);
279
+ this._setPanelDimensions(width, height);
280
+ this._cachedWidth = width;
281
+ this._cachedHeight = height;
282
+ try {
283
+ if (this.elementContent != undefined && (typeof this.elementContent.resizeHandler == 'function'))
284
+ this.elementContent.resizeHandler(width, height - this.elementTitle.clientHeight);
285
+ }
286
+ catch (err) {
287
+ console.log("error calling resizeHandler:", err, " elt:", this.elementContent);
288
+ }
289
+ }
290
+ _setPanelDimensions(width, height) {
291
+ this.elementTitle.style.width = width + 'px';
292
+ this.elementContentHost.style.width = width + 'px';
293
+ this.elementContentContainer.style.width = width + 'px';
294
+ this.elementPanel.style.width = width + 'px';
295
+ let titleBarHeight = this.elementTitle.clientHeight;
296
+ let contentHeight = height - titleBarHeight;
297
+ this.elementContentHost.style.height = contentHeight + 'px';
298
+ this.elementContentContainer.style.height = contentHeight + 'px';
299
+ this.elementPanel.style.height = height + 'px';
300
+ //if (this.elementContentContainer.parentElement != this.dockManager.config.dialogRootElement)
301
+ // this.dockManager.config.dialogRootElement.appendChild(this.elementContentContainer);
302
+ const rect = this.elementContentWrapper.getBoundingClientRect();
303
+ const rootRect = this.dockManager.config.dialogRootElement.getBoundingClientRect();
304
+ this.elementContentContainer.style.left = (rect.x /*- rootRect.x*/) + 'px';
305
+ this.elementContentContainer.style.top = (rect.y - rootRect.y) + 'px';
306
+ this.elementContentContainer.style.width = rect.width + 'px';
307
+ this.elementContentContainer.style.height = rect.height + 'px';
308
+ }
309
+ setDialogPosition(x, y) {
310
+ const rootRect = this.dockManager.config.dialogRootElement.getBoundingClientRect();
311
+ this.elementContentContainer.style.left = (x - rootRect.x) + 'px';
312
+ //todo, 25px if it is a dialog, is it always 25px? where do we know...
313
+ this.elementContentContainer.style.top = (y + this.elementTitle.clientHeight /*- rootRect.y*/) + 'px';
314
+ }
315
+ setVisible(isVisible) {
316
+ this.elementContentContainer.style.display = isVisible ? 'block' : 'none';
317
+ }
318
+ setTitle(title) {
319
+ this.title = title;
320
+ this._updateTitle();
321
+ if (this.onTitleChanged)
322
+ this.onTitleChanged(this, title);
323
+ }
324
+ setTitleIcon(icon) {
325
+ this.icon = icon;
326
+ this._updateTitle();
327
+ if (this.onTitleChanged)
328
+ this.onTitleChanged(this, this.title);
329
+ }
330
+ setHasChanges(changes) {
331
+ this.hasChanges = changes;
332
+ this._updateTitle();
333
+ if (changes) {
334
+ this.elementTitleText.classList.add('panel-has-changes');
335
+ }
336
+ else {
337
+ this.elementTitleText.classList.remove('panel-has-changes');
338
+ }
339
+ if (this.onTitleChanged)
340
+ this.onTitleChanged(this, this.title);
341
+ }
342
+ setCloseIconTemplate(closeIconTemplate) {
343
+ this.elementButtonClose.innerHTML = closeIconTemplate;
344
+ }
345
+ _updateTitle() {
346
+ if (this.icon !== null) {
347
+ this.elementTitleText.innerHTML = '<img class="panel-titlebar-icon" src="' + this.icon + '"><span>' + this.title + '</span>';
348
+ return;
349
+ }
350
+ this.elementTitleText.innerHTML = this.title;
351
+ }
352
+ getRawTitle() {
353
+ return this.elementTitleText.innerHTML;
354
+ }
355
+ performLayout(children, relayoutEvenIfEqual) {
356
+ }
357
+ onCloseButtonClicked(e) {
358
+ e.preventDefault();
359
+ e.stopPropagation();
360
+ this.close();
361
+ }
362
+ async close() {
363
+ let close = true;
364
+ if (this.elementContentContainer.parentElement === this.dockManager.config.dialogRootElement) {
365
+ this.dockManager.config.dialogRootElement.removeChild(this.elementContentContainer);
366
+ if (this.closePanelContainerCallback)
367
+ close = await this.closePanelContainerCallback(this);
368
+ else if (this.dockManager.closePanelContainerCallback)
369
+ close = await this.dockManager.closePanelContainerCallback(this);
370
+ if (close) {
371
+ if (this.isDialog) {
372
+ if (this.floatingDialog) {
373
+ //this.floatingDialog.hide();
374
+ this.floatingDialog.close(); // fires onClose notification
375
+ }
376
+ }
377
+ else {
378
+ this.performClose();
379
+ this.dockManager.notifyOnClosePanel(this);
380
+ }
381
+ }
382
+ }
383
+ }
384
+ }
385
385
  //# sourceMappingURL=PanelContainer.js.map