@deephaven/dashboard 0.42.1-beta.2 → 0.43.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 (55) hide show
  1. package/package.json +10 -10
  2. package/dist/Dashboard.css +0 -5
  3. package/dist/Dashboard.css.map +0 -1
  4. package/dist/Dashboard.js +0 -93
  5. package/dist/Dashboard.js.map +0 -1
  6. package/dist/DashboardConstants.js +0 -3
  7. package/dist/DashboardConstants.js.map +0 -1
  8. package/dist/DashboardLayout.js +0 -181
  9. package/dist/DashboardLayout.js.map +0 -1
  10. package/dist/DashboardPanelWrapper.js +0 -10
  11. package/dist/DashboardPanelWrapper.js.map +0 -1
  12. package/dist/DashboardPlugin.js +0 -22
  13. package/dist/DashboardPlugin.js.map +0 -1
  14. package/dist/DashboardUtils.js +0 -62
  15. package/dist/DashboardUtils.js.map +0 -1
  16. package/dist/PanelErrorBoundary.css +0 -8
  17. package/dist/PanelErrorBoundary.css.map +0 -1
  18. package/dist/PanelErrorBoundary.js +0 -55
  19. package/dist/PanelErrorBoundary.js.map +0 -1
  20. package/dist/PanelEvent.js +0 -32
  21. package/dist/PanelEvent.js.map +0 -1
  22. package/dist/PanelManager.js +0 -255
  23. package/dist/PanelManager.js.map +0 -1
  24. package/dist/PanelPlaceholder.css +0 -15
  25. package/dist/PanelPlaceholder.css.map +0 -1
  26. package/dist/PanelPlaceholder.js +0 -18
  27. package/dist/PanelPlaceholder.js.map +0 -1
  28. package/dist/declaration.d.js +0 -2
  29. package/dist/declaration.d.js.map +0 -1
  30. package/dist/index.js +0 -15
  31. package/dist/index.js.map +0 -1
  32. package/dist/layout/GLPropTypes.js +0 -37
  33. package/dist/layout/GLPropTypes.js.map +0 -1
  34. package/dist/layout/GoldenLayout.css +0 -581
  35. package/dist/layout/GoldenLayout.css.map +0 -1
  36. package/dist/layout/LayoutUtils.js +0 -690
  37. package/dist/layout/LayoutUtils.js.map +0 -1
  38. package/dist/layout/hooks.js +0 -11
  39. package/dist/layout/hooks.js.map +0 -1
  40. package/dist/layout/index.js +0 -5
  41. package/dist/layout/index.js.map +0 -1
  42. package/dist/layout/usePanelRegistration.js +0 -23
  43. package/dist/layout/usePanelRegistration.js.map +0 -1
  44. package/dist/redux/actionTypes.js +0 -3
  45. package/dist/redux/actionTypes.js.map +0 -1
  46. package/dist/redux/actions.js +0 -27
  47. package/dist/redux/actions.js.map +0 -1
  48. package/dist/redux/index.js +0 -10
  49. package/dist/redux/index.js.map +0 -1
  50. package/dist/redux/reducers/dashboardData.js +0 -7
  51. package/dist/redux/reducers/dashboardData.js.map +0 -1
  52. package/dist/redux/reducers/index.js +0 -5
  53. package/dist/redux/reducers/index.js.map +0 -1
  54. package/dist/redux/selectors.js +0 -40
  55. package/dist/redux/selectors.js.map +0 -1
@@ -1,690 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
- import deepEqual from 'deep-equal';
7
- import shortid from 'shortid';
8
- import isMatch from 'lodash.ismatch';
9
- import Log from '@deephaven/log';
10
- import { isComponent, isRoot, isStack, GoldenLayoutThemeExport } from '@deephaven/golden-layout';
11
- import { assertNotNull } from '@deephaven/utils';
12
- var log = Log.module('LayoutUtils');
13
- function isComponentConfig(config) {
14
- return config.componentName !== undefined;
15
- }
16
- export function isReactComponentConfig(config) {
17
- var reactConfig = config;
18
- // Golden layout sets the type to 'component' and componentName to 'lm-react-component' in `createContentItem`, then changes it back in `toConfig`
19
- // For our purposes, we need to check both.
20
- return (isComponentConfig(config) && config.componentName === 'lm-react-component' || config.type === 'react-component') && reactConfig.component !== undefined;
21
- }
22
- function isHTMLElement(element) {
23
- return element.focus !== undefined;
24
- }
25
- function isStackItemConfig(config) {
26
- return config.type === 'stack';
27
- }
28
- class LayoutUtils {
29
- static activateTab(root, config) {
30
- var stack = LayoutUtils.getStackForRoot(root, config, false);
31
- if (!stack) {
32
- log.error('Could not find stack for config', config);
33
- return;
34
- }
35
- // Find the tab with the specified table and activate it
36
- var contentItem = LayoutUtils.getContentItemInStack(stack, config);
37
- if (contentItem) {
38
- stack.setActiveContentItem(contentItem);
39
- }
40
- }
41
-
42
- /**
43
- * Is the tab with the given config active
44
- * @param root A GoldenLayout content item with the tab
45
- * @param config Tab config to match
46
- * @returns True if the tab is active
47
- */
48
- static isActiveTab(root, config) {
49
- var stack = LayoutUtils.getStackForRoot(root, config, false);
50
- if (!stack) {
51
- log.error('Could not find stack for config', config);
52
- return false;
53
- }
54
- // Find the item with the specified config and compare with active item
55
- var contentItem = LayoutUtils.getContentItemInStack(stack, config);
56
- var activeItem = stack.getActiveContentItem();
57
- return activeItem === contentItem;
58
- }
59
-
60
- /**
61
- * Adds a stack to the root layout specified. Adds to the first row/column with only one item
62
- * @param parent A GoldenLayout content item to add the stack to
63
- * @returns The newly created stack.
64
- */
65
- static addStack(parent) {
66
- var columnPreferred = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
67
- var type = columnPreferred ? 'column' : 'row';
68
- if (isRoot(parent)) {
69
- if (parent.contentItems == null || parent.contentItems.length === 0) {
70
- parent.addChild({
71
- type
72
- });
73
- }
74
- var child = parent.contentItems[0];
75
- var _isCorrectType = columnPreferred ? child.isColumn : child.isRow;
76
- if (!_isCorrectType) {
77
- parent.removeChild(child, true);
78
- parent.addChild({
79
- type
80
- });
81
-
82
- // The addChild may cause the element that has focus to be removed from the DOM, which changes focus to the body
83
- // Try and maintain the focus as best we can. The unfocused element may still send a blur/focus event so that needs to be handled correctly.
84
- var maintainFocusElement = document.activeElement;
85
- parent.contentItems[0].addChild(child);
86
- if (maintainFocusElement && maintainFocusElement.focus != null) {
87
- maintainFocusElement.focus();
88
- }
89
- }
90
- return this.addStack(parent.contentItems[0], columnPreferred);
91
- }
92
- if (parent.contentItems.length < 2) {
93
- parent.addChild({
94
- type: 'stack'
95
- });
96
- return parent.contentItems[parent.contentItems.length - 1];
97
- }
98
- var newParent = parent.contentItems[parent.contentItems.length - 1];
99
- var isCorrectType = !columnPreferred ? newParent.isColumn : newParent.isRow;
100
- if (!isCorrectType) {
101
- parent.addChild({
102
- type: !columnPreferred ? 'column' : 'row'
103
- });
104
- parent.removeChild(newParent, true);
105
- parent.contentItems[parent.contentItems.length - 1].addChild(newParent);
106
- newParent = parent.contentItems[parent.contentItems.length - 1];
107
- }
108
- return this.addStack(newParent, !columnPreferred);
109
- }
110
-
111
- /**
112
- * Gets the first stack which contains a contentItem with the given config values
113
- * @param item Golden layout content item to search for the stack
114
- * @param config The item properties to match
115
- */
116
- static getStackForConfig(item) {
117
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
118
- var allowEmptyStack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
119
- if (allowEmptyStack && isStack(item) && item.contentItems.length === 0) {
120
- return item;
121
- }
122
- if (item.contentItems == null) {
123
- return null;
124
- }
125
- for (var i = 0; i < item.contentItems.length; i += 1) {
126
- var contentItem = item.contentItems[i];
127
- if (contentItem.isComponent && contentItem.config != null) {
128
- if (isMatch(contentItem.config, config)) {
129
- return item;
130
- }
131
- }
132
- var stack = this.getStackForConfig(contentItem, config, allowEmptyStack);
133
- if (stack) {
134
- return stack;
135
- }
136
- }
137
- return null;
138
- }
139
-
140
- /**
141
- * Gets a stack matching the specified config
142
- * @param root The root GoldenLayout element
143
- * @param config The item config type to match, eg. { component: 'IrisGridPanel', title: 'Table Name' }
144
- * @param createIfNecessary Whether to create the stack if it does not exist.
145
- * @param matchComponentType If the config doesn't match exactly, just find another one of the same component type
146
- * @param allowEmptyStack If no configs match, search for an empty stack that can be used
147
- */
148
- static getStackForRoot(root, config) {
149
- var createIfNecessary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
150
- var matchComponentType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
151
- var allowEmptyStack = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
152
- var stack = this.getStackForConfig(root, config);
153
- if (!stack && matchComponentType) {
154
- stack = this.getStackForConfig(root, {
155
- component: config.component
156
- }, allowEmptyStack);
157
- }
158
- if (!stack && createIfNecessary) {
159
- stack = this.addStack(root);
160
- }
161
- return stack;
162
- }
163
-
164
- /**
165
- * Gets a stack matching one of the specified types, creates new stack if necessary
166
- * @param root The GoldenLayout root to find or create the stack in
167
- * @param types The array of component types to match
168
- * @param createIfNecessary Whether to create the stack if it does not exist
169
- * @param matchComponentType If the config doesn't match exactly, just find another one of the same component type
170
- * @param allowEmptyStack If no configs match, search for an empty stack that can be used
171
- */
172
- static getStackForComponentTypes(root, types) {
173
- var createIfNecessary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
174
- var matchComponentType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
175
- var allowEmptyStack = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
176
- for (var i = 0; i < types.length; i += 1) {
177
- var component = types[i];
178
- var isLastType = i === types.length - 1;
179
- var stack = LayoutUtils.getStackForRoot(root, {
180
- component
181
- }, createIfNecessary && isLastType, matchComponentType, allowEmptyStack);
182
- if (stack) {
183
- return stack;
184
- }
185
- }
186
- return null;
187
- }
188
-
189
- /**
190
- * Gets first content item with the specified config in stack.
191
- * @param stack The stack to search for the item
192
- * @param config The item config type to match, eg. { component: 'IrisGridPanel', title: 'Table Name' }
193
- * @returns Returns the found content item, null if not found.
194
- */
195
- static getContentItemInStack(stack, config) {
196
- if (!stack) {
197
- return null;
198
- }
199
- for (var i = 0; i < stack.contentItems.length; i += 1) {
200
- var contentItem = stack.contentItems[i];
201
- if (contentItem.isComponent && contentItem.config != null) {
202
- if (isMatch(contentItem.config, config)) {
203
- return contentItem;
204
- }
205
- }
206
- }
207
- return null;
208
- }
209
-
210
- /**
211
- * Removes dynamic props from components in the given config so this config could be serialized
212
- * @param config Config objec
213
- * @returns Dehydrated config
214
- */
215
- static dehydrateLayoutConfig(config, dehydrateComponent) {
216
- if (config == null || !config.length) {
217
- return [];
218
- }
219
- var dehydratedConfig = [];
220
- for (var i = 0; i < config.length; i += 1) {
221
- var itemConfig = config[i];
222
- var {
223
- component,
224
- content
225
- } = itemConfig;
226
- if (component) {
227
- var dehydratedComponent = dehydrateComponent(component, itemConfig);
228
- if (dehydratedComponent != null) {
229
- dehydratedConfig.push(dehydratedComponent);
230
- } else {
231
- log.debug2("dehydrateLayoutConfig: skipping unmapped component \"".concat(component, "\""));
232
- }
233
- } else if (content) {
234
- var layoutItemConfig = _objectSpread(_objectSpread({}, itemConfig), {}, {
235
- content: LayoutUtils.dehydrateLayoutConfig(content, dehydrateComponent)
236
- });
237
- dehydratedConfig.push(layoutItemConfig);
238
- } else {
239
- dehydratedConfig.push(itemConfig);
240
- }
241
- }
242
- return dehydratedConfig;
243
- }
244
- static getTabPoint(glContainer) {
245
- var {
246
- tab
247
- } = glContainer;
248
- if (tab == null) {
249
- throw new Error("Cannot get tab for panel container ".concat(glContainer));
250
- }
251
- var tabRect = tab.element[0].getBoundingClientRect();
252
- return [tabRect.left + tabRect.width * 0.5, tabRect.bottom - 8];
253
- }
254
-
255
- /**
256
- * Drop minor changes in Layout Configuration for deep comparison
257
- * @param config Layout Configuration
258
- *
259
- * minor changes:
260
- * 1. sorts in grid
261
- * 2. quick filters in grid
262
- * 3. active item
263
- *
264
- * item id is also removed
265
- */
266
- static dropLayoutMinorChange(config) {
267
- for (var i = 0; i < config.length; i += 1) {
268
- var itemConfig = config[i];
269
- var {
270
- content
271
- } = itemConfig;
272
- if (content !== undefined) {
273
- if (isStackItemConfig(itemConfig)) {
274
- delete itemConfig.activeItemIndex;
275
- }
276
- LayoutUtils.dropLayoutMinorChange(content);
277
- } else if (isReactComponentConfig(itemConfig) && itemConfig.component === 'IrisGridPanel') {
278
- if (itemConfig.props.panelState != null) {
279
- delete itemConfig.id;
280
- itemConfig.props.panelState.irisGridState.sorts = [];
281
- itemConfig.props.panelState.irisGridState.quickFilters = [];
282
- }
283
- }
284
- }
285
- }
286
-
287
- /**
288
- * Compare two layouts to see if they are equivalent
289
- * @param layout1 A Golden Layout config object
290
- * @param layout2 Another Golden layout config object
291
- * @param major When true, will ignore "minor" property differences (eg. sorts)
292
- */
293
- static isEqual(layout1, layout2) {
294
- var major = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
295
- if (major) {
296
- var layout1Clone = LayoutUtils.cloneLayout(layout1);
297
- var layout2Clone = LayoutUtils.cloneLayout(layout2);
298
- LayoutUtils.dropLayoutMinorChange(layout1Clone);
299
- LayoutUtils.dropLayoutMinorChange(layout2Clone);
300
- return deepEqual(layout1Clone, layout2Clone);
301
- }
302
- return deepEqual(layout1, layout2);
303
- }
304
- static cloneLayout(layout) {
305
- return JSON.parse(JSON.stringify(layout));
306
- }
307
-
308
- /**
309
- * Adds dynamic props to components in the given config so this config could be used to initialize a layout
310
- * @param config Dehydrated config object
311
- * @param hydrateComponent Function to hydrate the component
312
- * @returns Hydrated config
313
- */
314
- static hydrateLayoutConfig(config, hydrateComponent) {
315
- if (config == null || !config.length) {
316
- return [];
317
- }
318
- var hydratedConfig = [];
319
- for (var i = 0; i < config.length; i += 1) {
320
- var itemConfig = config[i];
321
- if (isReactComponentConfig(itemConfig)) {
322
- var _itemConfig$id;
323
- var {
324
- component,
325
- props = {}
326
- } = itemConfig;
327
- hydratedConfig.push(_objectSpread(_objectSpread({}, itemConfig), {}, {
328
- id: (_itemConfig$id = itemConfig === null || itemConfig === void 0 ? void 0 : itemConfig.id) !== null && _itemConfig$id !== void 0 ? _itemConfig$id : shortid(),
329
- props: hydrateComponent(component, props)
330
- }));
331
- } else if (itemConfig.content !== undefined) {
332
- var contentConfig = LayoutUtils.hydrateLayoutConfig(itemConfig.content, hydrateComponent);
333
- if (isStackItemConfig(itemConfig) && itemConfig.activeItemIndex != null && itemConfig.activeItemIndex >= contentConfig.length) {
334
- log.warn('Fixing bad activeItemIndex!', itemConfig.activeItemIndex, itemConfig);
335
- itemConfig.activeItemIndex = 0;
336
- }
337
- hydratedConfig.push(_objectSpread(_objectSpread({}, itemConfig), {}, {
338
- content: contentConfig
339
- }));
340
- } else {
341
- hydratedConfig.push(itemConfig);
342
- }
343
- }
344
- return hydratedConfig;
345
- }
346
-
347
- /**
348
- * Opens a component. It will try and open the component in an existing stack of the same component.
349
- * If `replaceExisting` is true and there is a component found with the same `config.id`, it will replace that component with this one.
350
- * If `allowStack` is true and there is a component of the same type found, it will open in that stack (potentially covering up a panel).
351
- * @param root The GoldenLayout root to open the component in
352
- * @param config The component config definition to open
353
- * @param replaceExisting Whether it should replace the existing one matching component type and id, or open a new one
354
- * @param replaceConfig The component config to replace
355
- * @param createNewStack True to force opening in a new stack, false to try and open in a stack with the same type of component.
356
- * @param focusElement The element to focus on
357
- * @param dragEvent Whether component is being created with a drag, mouse event is initial position for drag proxy
358
- */
359
- static openComponent() {
360
- var {
361
- root,
362
- config: configParam,
363
- replaceExisting = true,
364
- replaceConfig = undefined,
365
- createNewStack = false,
366
- focusElement = undefined,
367
- dragEvent = undefined
368
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
369
- // attempt to retain focus after dom manipulation, which can break focus
370
- var maintainFocusElement = document.activeElement;
371
- var config = _objectSpread({}, configParam);
372
- if (config.id == null) {
373
- config.id = shortid.generate();
374
- }
375
- if (dragEvent != null) {
376
- root === null || root === void 0 ? void 0 : root.layoutManager.createDragSourceFromEvent(config, dragEvent);
377
- return;
378
- }
379
- var searchConfig = replaceConfig || {
380
- id: config.id,
381
- component: config.component
382
- };
383
- assertNotNull(root);
384
- var stack = createNewStack ? LayoutUtils.addStack(root) : LayoutUtils.getStackForRoot(root, searchConfig);
385
- assertNotNull(stack);
386
- var oldContentItem = LayoutUtils.getContentItemInStack(stack, searchConfig);
387
- if (focusElement != null) {
388
- // We need to listen for when the stack is created
389
- var onComponentCreated = event => {
390
- log.debug('Component created, focusing element', focusElement);
391
- stack.off('componentCreated', onComponentCreated);
392
- var {
393
- element
394
- } = event.origin;
395
-
396
- // Need to wait until the component actually renders.
397
- requestAnimationFrame(() => {
398
- LayoutUtils.focusElement(element[0], focusElement);
399
- });
400
- };
401
- stack.on('componentCreated', onComponentCreated);
402
- }
403
- if (replaceExisting && oldContentItem) {
404
- var index = stack.contentItems.indexOf(oldContentItem);
405
-
406
- // Using remove/add here instead of replaceChild because I was getting errors with replaceChild... should be the same.
407
- // Add first so that the stack doesn't get screwed up
408
- stack.addChild(config, index + 1);
409
- stack.removeChild(oldContentItem);
410
- stack.setActiveContentItem(stack.contentItems[index]);
411
- } else {
412
- stack.addChild(config);
413
- }
414
- if (focusElement == null && maintainFocusElement && isHTMLElement(maintainFocusElement)) {
415
- maintainFocusElement.focus();
416
- }
417
- }
418
-
419
- /**
420
- * Opens a component in an given stack.
421
- * If `replaceExisting` is true and there is a component found with the same `config.id`, it will replace that component with this one
422
- * @param stack The GoldenLayout stack to open the component in
423
- * @param config The component config definition to open
424
- * @param replaceExisting Whether it should replace the existing one matching component type and id, or open a new one
425
- */
426
- static openComponentInStack(stack, config) {
427
- var replaceExisting = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
428
- var maintainFocusElement = document.activeElement; // attempt to retain focus after dom manipulation, which can break focus
429
-
430
- var searchConfig = {
431
- id: config.id
432
- };
433
- var oldContentItem = LayoutUtils.getContentItemInStack(stack, searchConfig);
434
- if (replaceExisting && oldContentItem && stack) {
435
- var index = stack === null || stack === void 0 ? void 0 : stack.contentItems.indexOf(oldContentItem);
436
-
437
- // Using remove/add here instead of replaceChild because I was getting errors with replaceChild... should be the same.
438
- // Add first so that the stack doesn't get screwed up
439
- stack.addChild(config, index + 1);
440
- stack.removeChild(oldContentItem);
441
- stack.setActiveContentItem(stack.contentItems[index]);
442
- } else {
443
- stack === null || stack === void 0 ? void 0 : stack.addChild(config);
444
- }
445
- if (maintainFocusElement && isHTMLElement(maintainFocusElement)) {
446
- maintainFocusElement.focus();
447
- }
448
- }
449
-
450
- /**
451
- * Close the specified component and remove it from the stack it's currently in
452
- * @param root The GoldenLayout root to search and close the component in
453
- * @param config The GoldenLayout component config definition to close, eg. { component: 'IrisGridPanel', id: 'table-t' }
454
- */
455
- static closeComponent(root, config, closeOptions) {
456
- var stack = LayoutUtils.getStackForRoot(root, config, false, false, false);
457
- if (!stack) {
458
- log.warn('Cannot find stack for component, ignoring close', config);
459
- return;
460
- }
461
-
462
- // Find the tab with the specified config and remove it
463
- // Same component was used to get the stack above, so getContentItemInStack shouldn't return null
464
- var oldContentItem = LayoutUtils.getContentItemInStack(stack, config);
465
- var maintainFocusElement = document.activeElement; // attempt to retain focus after dom manipulation, which can break focus
466
- if (oldContentItem) {
467
- if (isComponent(oldContentItem)) {
468
- oldContentItem.container.close(closeOptions);
469
- } else {
470
- stack.removeChild(oldContentItem);
471
- }
472
- }
473
- // if focused element is still in dom restore focus, note it could have been in the removed panel so check first
474
- if (maintainFocusElement && document.contains(maintainFocusElement) && isHTMLElement(maintainFocusElement)) {
475
- maintainFocusElement.focus();
476
- }
477
- }
478
- static renameComponent(root, config, newTitle) {
479
- var stack = LayoutUtils.getStackForRoot(root, config, false);
480
- if (!stack) {
481
- log.error('Could not find stack for config', config);
482
- return;
483
- }
484
- // Find the tab with the specified config and rename it
485
- var contentItem = LayoutUtils.getContentItemInStack(stack, config);
486
- if (contentItem) {
487
- contentItem.setTitle(newTitle);
488
- }
489
- }
490
-
491
- /**
492
- * Create a component clone based on the given config
493
- * @param root The GoldenLayout root to clone the component in
494
- * @param config The config to clone
495
- * @returns Clone config
496
- */
497
- static cloneComponent(root, config) {
498
- var stack = LayoutUtils.getStackForRoot(root, config, false);
499
- if (!stack) {
500
- log.error('Could not find stack for config', config);
501
- return null;
502
- }
503
- var {
504
- props = {}
505
- } = config;
506
- var panelState = LayoutUtils.getPanelComponentState(config);
507
- var cloneConfig = {
508
- type: 'react-component',
509
- component: config.component,
510
- props: _objectSpread(_objectSpread({}, props), {}, {
511
- panelState
512
- }),
513
- title: "".concat(config.title, " Copy"),
514
- id: shortid.generate()
515
- };
516
- LayoutUtils.openComponentInStack(stack, cloneConfig);
517
- return cloneConfig;
518
- }
519
-
520
- /**
521
- * Get panel component state for the given config
522
- * @param config Panel config
523
- * @returns Panel state
524
- */
525
- static getPanelComponentState(config) {
526
- if (isComponentConfig(config)) {
527
- var _config$componentStat;
528
- return (_config$componentStat = config.componentState) === null || _config$componentStat === void 0 ? void 0 : _config$componentStat.panelState;
529
- }
530
- if (isReactComponentConfig(config)) {
531
- var _config$props;
532
- return (_config$props = config.props) === null || _config$props === void 0 ? void 0 : _config$props.panelState;
533
- }
534
- return null;
535
- }
536
- static makeDefaultLayout() {
537
- return {
538
- dimensions: {
539
- headerHeight: GoldenLayoutThemeExport.tabHeight,
540
- borderWidth: GoldenLayoutThemeExport.dragBorderWidth,
541
- borderGrabWidth: 10
542
- },
543
- settings: {
544
- showPopoutIcon: false,
545
- showCloseIcon: false,
546
- constrainDragToContainer: false
547
- }
548
- };
549
- }
550
-
551
- /**
552
- * Gets a containers root node
553
- * @param container The Golden Layout container to get the root for
554
- */
555
- static getRootFromContainer(container) {
556
- return container.layoutManager.root;
557
- }
558
-
559
- /**
560
- * Gets the config for the panel component given a glContainer
561
- * @param container The Golden Layout container to get the config for
562
- */
563
- static getComponentConfigFromContainer(container) {
564
- if (container) {
565
- if (container.tab != null && container.tab.contentItem != null) {
566
- return container.tab.contentItem.config;
567
- }
568
-
569
- // If the container hasn't populated the tab yet, just get the config directly from the container
570
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
571
- // @ts-ignore private api usage
572
- // eslint-disable-next-line no-underscore-dangle
573
- return container._config;
574
- }
575
- return null;
576
- }
577
- static getTitleFromContainer(container) {
578
- if (container != null && container.tab != null && container.tab.contentItem != null) {
579
- return container.tab.contentItem.config.title;
580
- }
581
- return null;
582
- }
583
- static getTitleFromTab(tab) {
584
- if (tab != null && tab.contentItem != null) {
585
- return tab.contentItem.config.title;
586
- }
587
- return null;
588
- }
589
-
590
- /**
591
- * Retrieve the panel ID for the provided golden layout container
592
- * @param glContainer The container to get the panel ID for
593
- * @returns Panel ID
594
- */
595
- static getIdFromContainer(glContainer) {
596
- var config = LayoutUtils.getComponentConfigFromContainer(glContainer);
597
- if (config) {
598
- return config.id;
599
- }
600
- return null;
601
- }
602
-
603
- /**
604
- * Retrieve the ID of the panel provided
605
- * @param panel The panel to get the ID for
606
- * @returns Panel ID
607
- */
608
- static getIdFromPanel(panel) {
609
- var {
610
- glContainer
611
- } = panel.props;
612
- return LayoutUtils.getIdFromContainer(glContainer);
613
- }
614
-
615
- /**
616
- * Get component name from the panel instance
617
- * @param panel Panel to get component name for
618
- * @returns Component name or null if unable to retrieve name
619
- */
620
- static getComponentNameFromPanel(panel) {
621
- var {
622
- glContainer
623
- } = panel.props;
624
- var config = LayoutUtils.getComponentConfigFromContainer(glContainer);
625
- if (config && isReactComponentConfig(config)) {
626
- var _config$component;
627
- return (_config$component = config.component) !== null && _config$component !== void 0 ? _config$component : null;
628
- }
629
- return null;
630
- }
631
-
632
- /**
633
- * Get component name for wrapped and un-wrapped components
634
- * @param component Component to get name for
635
- * @returns Component name
636
- * @throws If displayName for the component is not defined
637
- */
638
- static getComponentName(component) {
639
- var _component$WrappedCom, _component$WrappedCom2;
640
- var name = (_component$WrappedCom = (_component$WrappedCom2 = component.WrappedComponent) === null || _component$WrappedCom2 === void 0 ? void 0 : _component$WrappedCom2.displayName) !== null && _component$WrappedCom !== void 0 ? _component$WrappedCom : component.displayName;
641
- if (name == null) {
642
- throw new Error("Component displayName not defined ".concat(component));
643
- }
644
- return name;
645
- }
646
-
647
- /**
648
- * Put focus on the first "input" element (input, button, select, textarea) within an element
649
- * If element is null or input element not found, does nothing
650
- * @param element The element to put focus in.
651
- * @param selector The first element matching this selector will be focused.
652
- * @returns The element that was focused, null if not focused
653
- */
654
- static focusElement(element) {
655
- var selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : LayoutUtils.DEFAULT_FOCUS_SELECTOR;
656
- if (element == null) {
657
- return null;
658
- }
659
- var focusElement = element.querySelector(selector);
660
- if (focusElement == null) {
661
- return null;
662
- }
663
- if (isHTMLElement(focusElement)) {
664
- focusElement.focus();
665
- }
666
- return focusElement;
667
- }
668
-
669
- /**
670
- * Get a promise that initializes when layout is initialized
671
- * @param layout The layout to await initialization on
672
- * @returns Promise that resolves when layout is initialized
673
- */
674
- static onInitialized(layout) {
675
- return new Promise(resolve => {
676
- if (layout.isInitialised) {
677
- resolve();
678
- return;
679
- }
680
- var onInit = () => {
681
- layout.off('initialised', onInit);
682
- resolve();
683
- };
684
- layout.on('initialised', onInit);
685
- });
686
- }
687
- }
688
- _defineProperty(LayoutUtils, "DEFAULT_FOCUS_SELECTOR", 'input, select, textarea, button');
689
- export default LayoutUtils;
690
- //# sourceMappingURL=LayoutUtils.js.map