dockview-react 6.6.1 → 7.0.2

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 (85) hide show
  1. package/dist/cjs/dockview/defaultTab.d.ts +7 -0
  2. package/dist/cjs/dockview/defaultTab.js +99 -0
  3. package/dist/cjs/dockview/dockview.d.ts +33 -0
  4. package/dist/cjs/dockview/dockview.js +285 -0
  5. package/dist/cjs/dockview/headerActionsRenderer.d.ts +24 -0
  6. package/dist/cjs/dockview/headerActionsRenderer.js +86 -0
  7. package/dist/cjs/dockview/reactContentPart.d.ts +21 -0
  8. package/dist/cjs/dockview/reactContentPart.js +52 -0
  9. package/dist/cjs/dockview/reactContextMenuItemPart.d.ts +14 -0
  10. package/dist/cjs/dockview/reactContextMenuItemPart.js +31 -0
  11. package/dist/cjs/dockview/reactGroupDragGhostPart.d.ts +20 -0
  12. package/dist/cjs/dockview/reactGroupDragGhostPart.js +32 -0
  13. package/dist/cjs/dockview/reactHeaderPart.d.ts +17 -0
  14. package/dist/cjs/dockview/reactHeaderPart.js +46 -0
  15. package/dist/cjs/dockview/reactTabGroupChipPart.d.ts +23 -0
  16. package/dist/cjs/dockview/reactTabGroupChipPart.js +36 -0
  17. package/dist/cjs/dockview/reactWatermarkPart.d.ts +18 -0
  18. package/dist/cjs/dockview/reactWatermarkPart.js +47 -0
  19. package/dist/cjs/gridview/gridview.d.ts +17 -0
  20. package/dist/cjs/gridview/gridview.js +105 -0
  21. package/dist/cjs/gridview/view.d.ts +9 -0
  22. package/dist/cjs/gridview/view.js +41 -0
  23. package/dist/cjs/index.d.ts +9 -0
  24. package/dist/cjs/index.js +7 -0
  25. package/dist/cjs/paneview/paneview.d.ts +20 -0
  26. package/dist/cjs/paneview/paneview.js +137 -0
  27. package/dist/cjs/paneview/view.d.ts +19 -0
  28. package/dist/cjs/paneview/view.js +44 -0
  29. package/dist/cjs/react.d.ts +35 -0
  30. package/dist/cjs/react.js +183 -0
  31. package/dist/cjs/splitview/splitview.d.ts +17 -0
  32. package/dist/cjs/splitview/splitview.js +105 -0
  33. package/dist/cjs/splitview/view.d.ts +9 -0
  34. package/dist/cjs/splitview/view.js +39 -0
  35. package/dist/cjs/svg.d.ts +3 -0
  36. package/dist/cjs/svg.js +15 -0
  37. package/dist/cjs/types.d.ts +4 -0
  38. package/dist/cjs/types.js +2 -0
  39. package/dist/dockview-react.js +21650 -11
  40. package/dist/dockview-react.min.js +21 -2
  41. package/dist/dockview-react.min.js.map +1 -1
  42. package/dist/esm/dockview/defaultTab.d.ts +7 -0
  43. package/dist/esm/dockview/defaultTab.js +65 -0
  44. package/dist/esm/dockview/dockview.d.ts +33 -0
  45. package/dist/esm/dockview/dockview.js +252 -0
  46. package/dist/esm/dockview/headerActionsRenderer.d.ts +24 -0
  47. package/dist/esm/dockview/headerActionsRenderer.js +72 -0
  48. package/dist/esm/dockview/reactContentPart.d.ts +21 -0
  49. package/dist/esm/dockview/reactContentPart.js +43 -0
  50. package/dist/esm/dockview/reactContextMenuItemPart.d.ts +14 -0
  51. package/dist/esm/dockview/reactContextMenuItemPart.js +22 -0
  52. package/dist/esm/dockview/reactGroupDragGhostPart.d.ts +20 -0
  53. package/dist/esm/dockview/reactGroupDragGhostPart.js +23 -0
  54. package/dist/esm/dockview/reactHeaderPart.d.ts +17 -0
  55. package/dist/esm/dockview/reactHeaderPart.js +37 -0
  56. package/dist/esm/dockview/reactTabGroupChipPart.d.ts +23 -0
  57. package/dist/esm/dockview/reactTabGroupChipPart.js +27 -0
  58. package/dist/esm/dockview/reactWatermarkPart.d.ts +18 -0
  59. package/dist/esm/dockview/reactWatermarkPart.js +38 -0
  60. package/dist/esm/gridview/gridview.d.ts +17 -0
  61. package/dist/esm/gridview/gridview.js +72 -0
  62. package/dist/esm/gridview/view.d.ts +9 -0
  63. package/dist/esm/gridview/view.js +19 -0
  64. package/dist/esm/index.d.ts +9 -0
  65. package/dist/esm/index.js +7 -0
  66. package/dist/esm/paneview/paneview.d.ts +20 -0
  67. package/dist/esm/paneview/paneview.js +104 -0
  68. package/dist/esm/paneview/view.d.ts +19 -0
  69. package/dist/esm/paneview/view.js +35 -0
  70. package/dist/esm/react.d.ts +35 -0
  71. package/dist/esm/react.js +134 -0
  72. package/dist/esm/splitview/splitview.d.ts +17 -0
  73. package/dist/esm/splitview/splitview.js +72 -0
  74. package/dist/esm/splitview/view.d.ts +9 -0
  75. package/dist/esm/splitview/view.js +17 -0
  76. package/dist/esm/svg.d.ts +3 -0
  77. package/dist/esm/svg.js +7 -0
  78. package/dist/esm/types.d.ts +4 -0
  79. package/dist/esm/types.js +1 -0
  80. package/dist/package/main.cjs.js +1037 -5
  81. package/dist/package/main.cjs.min.js +2 -2
  82. package/dist/package/main.esm.min.mjs +2 -8
  83. package/dist/package/main.esm.mjs +1027 -1
  84. package/dist/styles/dockview.css +275 -13
  85. package/package.json +15 -2
@@ -1,18 +1,1050 @@
1
1
  /**
2
2
  * dockview-react
3
- * @version 6.6.1
3
+ * @version 7.0.2
4
4
  * @link https://github.com/mathuo/dockview
5
5
  * @license MIT
6
6
  */
7
7
  'use strict';
8
8
 
9
+ Object.defineProperty(exports, '__esModule', { value: true });
10
+
9
11
  var dockview = require('dockview');
12
+ var React = require('react');
13
+ var ReactDOM = require('react-dom');
14
+
15
+ /**
16
+ * This component is intended to interface between vanilla-js and React hence we need to be
17
+ * creative in how we update props.
18
+ * A ref of the component is exposed with an update method; which when called stores the props
19
+ * as a ref within this component and forcefully triggers a re-render of the component using
20
+ * the ref of props we just set on the renderered component as the props passed to the inner
21
+ * component
22
+ */
23
+ const ReactComponentBridge = (props, ref) => {
24
+ const [, triggerRender] = React.useState(0);
25
+ const _props = React.useRef(props.componentProps);
26
+ React.useImperativeHandle(ref, () => ({
27
+ update: (componentProps) => {
28
+ _props.current = Object.assign(Object.assign({}, _props.current), componentProps);
29
+ /**
30
+ * setting a arbitrary piece of state within this component will
31
+ * trigger a re-render.
32
+ * we use this rather than updating through a prop since we can
33
+ * pass a ref into the vanilla-js world.
34
+ *
35
+ * Use a monotonic counter rather than `Date.now()` so two
36
+ * updates within the same millisecond still produce distinct
37
+ * state values and avoid React's bailout.
38
+ */
39
+ triggerRender((n) => n + 1);
40
+ },
41
+ }), []);
42
+ return React.createElement(props.component, _props.current);
43
+ };
44
+ ReactComponentBridge.displayName = 'DockviewReactJsBridge';
45
+ /**
46
+ * Since we are storing the React.Portal references in a rendered array they
47
+ * require a key property like any other React element rendered in an array
48
+ * to prevent excessive re-rendering
49
+ */
50
+ const uniquePortalKeyGenerator = (() => {
51
+ let value = 1;
52
+ return { next: () => `dockview_react_portal_key_${(value++).toString()}` };
53
+ })();
54
+ const ReactPartContext = React.createContext({});
55
+ class ReactPart {
56
+ constructor(parent, portalStore, component, parameters, context) {
57
+ this.parent = parent;
58
+ this.portalStore = portalStore;
59
+ this.component = component;
60
+ this.parameters = parameters;
61
+ this.context = context;
62
+ this._initialProps = {};
63
+ this.disposed = false;
64
+ this.createPortal();
65
+ }
66
+ update(props) {
67
+ if (this.disposed) {
68
+ throw new Error('invalid operation: resource is already disposed');
69
+ }
70
+ if (!this.componentInstance) {
71
+ // if the component is yet to be mounted store the props
72
+ this._initialProps = Object.assign(Object.assign({}, this._initialProps), props);
73
+ }
74
+ else {
75
+ this.componentInstance.update(props);
76
+ }
77
+ }
78
+ createPortal() {
79
+ if (this.disposed) {
80
+ throw new Error('invalid operation: resource is already disposed');
81
+ }
82
+ if (!isReactComponent(this.component)) {
83
+ /**
84
+ * we know this isn't a React.FunctionComponent so throw an error here.
85
+ * if we do not intercept then React library will throw a very obsure error
86
+ * for the same reason... at least at this point we will emit a sensible stacktrace.
87
+ */
88
+ throw new Error('Dockview: Only React.memo(...), React.ForwardRef(...) and functional components are accepted as components');
89
+ }
90
+ const bridgeComponent = React.createElement(React.forwardRef(ReactComponentBridge), {
91
+ component: this
92
+ .component,
93
+ componentProps: this.parameters,
94
+ ref: (element) => {
95
+ this.componentInstance = element;
96
+ if (Object.keys(this._initialProps).length > 0) {
97
+ this.componentInstance.update(this._initialProps);
98
+ this._initialProps = {}; // don't keep a reference to the users object once no longer required
99
+ }
100
+ },
101
+ });
102
+ const node = this.context
103
+ ? React.createElement(ReactPartContext.Provider, { value: this.context }, bridgeComponent)
104
+ : bridgeComponent;
105
+ const portal = ReactDOM.createPortal(node, this.parent, uniquePortalKeyGenerator.next());
106
+ this.ref = {
107
+ portal,
108
+ disposable: this.portalStore.addPortal(portal),
109
+ };
110
+ }
111
+ dispose() {
112
+ var _a;
113
+ (_a = this.ref) === null || _a === void 0 ? void 0 : _a.disposable.dispose();
114
+ this.disposed = true;
115
+ }
116
+ }
117
+ /**
118
+ * A React Hook that returns an array of portals to be rendered by the user of this hook
119
+ * and a disposable function to add a portal. Calling dispose removes this portal from the
120
+ * portal array
121
+ */
122
+ const usePortalsLifecycle = () => {
123
+ const [portals, setPortals] = React.useState([]);
124
+ React.useDebugValue(`Portal count: ${portals.length}`);
125
+ const addPortal = React.useCallback((portal) => {
126
+ setPortals((existingPortals) => [...existingPortals, portal]);
127
+ let disposed = false;
128
+ return dockview.DockviewDisposable.from(() => {
129
+ if (disposed) {
130
+ throw new Error('invalid operation: resource already disposed');
131
+ }
132
+ disposed = true;
133
+ setPortals((existingPortals) => existingPortals.filter((p) => p !== portal));
134
+ });
135
+ }, []);
136
+ return [portals, addPortal];
137
+ };
138
+ function isReactComponent(component) {
139
+ /**
140
+ * Yes, we could use "react-is" but that would introduce an unwanted peer dependency
141
+ * so for now we will check in a rather crude fashion...
142
+ */
143
+ return (typeof component === 'function' /** Functional Componnts */ ||
144
+ !!(component === null || component === void 0 ? void 0 : component.$$typeof) /** React.memo(...) Components */);
145
+ }
146
+
147
+ class ReactPanelContentPart {
148
+ get element() {
149
+ return this._element;
150
+ }
151
+ constructor(id, component, reactPortalStore) {
152
+ this.id = id;
153
+ this.component = component;
154
+ this.reactPortalStore = reactPortalStore;
155
+ this._onDidFocus = new dockview.DockviewEmitter();
156
+ this.onDidFocus = this._onDidFocus.event;
157
+ this._onDidBlur = new dockview.DockviewEmitter();
158
+ this.onDidBlur = this._onDidBlur.event;
159
+ this._element = document.createElement('div');
160
+ this._element.className = 'dv-react-part';
161
+ this._element.style.height = '100%';
162
+ this._element.style.width = '100%';
163
+ }
164
+ focus() {
165
+ // TODO
166
+ }
167
+ init(parameters) {
168
+ this.part = new ReactPart(this.element, this.reactPortalStore, this.component, {
169
+ params: parameters.params,
170
+ api: parameters.api,
171
+ containerApi: parameters.containerApi,
172
+ });
173
+ }
174
+ update(event) {
175
+ var _a;
176
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update({ params: event.params });
177
+ }
178
+ layout(_width, _height) {
179
+ // noop
180
+ }
181
+ dispose() {
182
+ var _a;
183
+ this._onDidFocus.dispose();
184
+ this._onDidBlur.dispose();
185
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
186
+ }
187
+ }
188
+
189
+ class ReactPanelHeaderPart {
190
+ get element() {
191
+ return this._element;
192
+ }
193
+ constructor(id, component, reactPortalStore) {
194
+ this.id = id;
195
+ this.component = component;
196
+ this.reactPortalStore = reactPortalStore;
197
+ this._element = document.createElement('div');
198
+ this._element.className = 'dv-react-part';
199
+ this._element.style.height = '100%';
200
+ this._element.style.width = '100%';
201
+ }
202
+ focus() {
203
+ //noop
204
+ }
205
+ init(parameters) {
206
+ this.part = new ReactPart(this.element, this.reactPortalStore, this.component, {
207
+ params: parameters.params,
208
+ api: parameters.api,
209
+ containerApi: parameters.containerApi,
210
+ tabLocation: parameters.tabLocation,
211
+ });
212
+ }
213
+ update(event) {
214
+ var _a;
215
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update({ params: event.params });
216
+ }
217
+ layout(_width, _height) {
218
+ // noop - retrieval from api
219
+ }
220
+ dispose() {
221
+ var _a;
222
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
223
+ }
224
+ }
225
+
226
+ class ReactWatermarkPart {
227
+ get element() {
228
+ return this._element;
229
+ }
230
+ constructor(id, component, reactPortalStore) {
231
+ this.id = id;
232
+ this.component = component;
233
+ this.reactPortalStore = reactPortalStore;
234
+ this._element = document.createElement('div');
235
+ this._element.className = 'dv-react-part';
236
+ this._element.style.height = '100%';
237
+ this._element.style.width = '100%';
238
+ }
239
+ init(parameters) {
240
+ this.part = new ReactPart(this.element, this.reactPortalStore, this.component, {
241
+ group: parameters.group,
242
+ containerApi: parameters.containerApi,
243
+ });
244
+ }
245
+ focus() {
246
+ // noop
247
+ }
248
+ update(params) {
249
+ var _a, _b, _c;
250
+ if (this.parameters) {
251
+ this.parameters.params = params.params;
252
+ }
253
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update({ params: (_c = (_b = this.parameters) === null || _b === void 0 ? void 0 : _b.params) !== null && _c !== void 0 ? _c : {} });
254
+ }
255
+ layout(_width, _height) {
256
+ // noop - retrieval from api
257
+ }
258
+ dispose() {
259
+ var _a;
260
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
261
+ }
262
+ }
263
+
264
+ class ReactHeaderActionsRendererPart {
265
+ get element() {
266
+ return this._element;
267
+ }
268
+ get part() {
269
+ return this._part;
270
+ }
271
+ constructor(component, reactPortalStore, _group) {
272
+ this.component = component;
273
+ this.reactPortalStore = reactPortalStore;
274
+ this._group = _group;
275
+ this.mutableDisposable = new dockview.DockviewMutableDisposable();
276
+ this._element = document.createElement('div');
277
+ this._element.className = 'dv-react-part';
278
+ this._element.style.height = '100%';
279
+ this._element.style.width = '100%';
280
+ }
281
+ init(parameters) {
282
+ this.mutableDisposable.value = new dockview.DockviewCompositeDisposable(this._group.model.onDidAddPanel(() => {
283
+ this.updatePanels();
284
+ }), this._group.model.onDidRemovePanel(() => {
285
+ this.updatePanels();
286
+ }), this._group.model.onDidActivePanelChange(() => {
287
+ this.updateActivePanel();
288
+ }), parameters.api.onDidActiveChange(() => {
289
+ this.updateGroupActive();
290
+ }), parameters.api.onDidLocationChange((event) => {
291
+ this.updateLocation(event.location);
292
+ }));
293
+ this._part = new ReactPart(this.element, this.reactPortalStore, this.component, {
294
+ api: parameters.api,
295
+ containerApi: parameters.containerApi,
296
+ panels: this._group.model.panels,
297
+ activePanel: this._group.model.activePanel,
298
+ isGroupActive: this._group.api.isActive,
299
+ group: this._group,
300
+ headerPosition: this._group.model.headerPosition,
301
+ location: parameters.api.location,
302
+ });
303
+ }
304
+ dispose() {
305
+ var _a;
306
+ this.mutableDisposable.dispose();
307
+ (_a = this._part) === null || _a === void 0 ? void 0 : _a.dispose();
308
+ }
309
+ update(event) {
310
+ var _a;
311
+ (_a = this._part) === null || _a === void 0 ? void 0 : _a.update(event.params);
312
+ }
313
+ updatePanels() {
314
+ this.update({ params: { panels: this._group.model.panels } });
315
+ }
316
+ updateActivePanel() {
317
+ this.update({
318
+ params: {
319
+ activePanel: this._group.model.activePanel,
320
+ },
321
+ });
322
+ }
323
+ updateGroupActive() {
324
+ this.update({
325
+ params: {
326
+ isGroupActive: this._group.api.isActive,
327
+ },
328
+ });
329
+ }
330
+ updateLocation(location) {
331
+ this.update({ params: { location } });
332
+ }
333
+ }
334
+
335
+ class ReactContextMenuItemPart {
336
+ get element() {
337
+ return this._element;
338
+ }
339
+ constructor(id, component, reactPortalStore) {
340
+ this.id = id;
341
+ this.component = component;
342
+ this.reactPortalStore = reactPortalStore;
343
+ this._element = document.createElement('div');
344
+ this._element.className = 'dv-react-part';
345
+ this._element.style.height = '100%';
346
+ this._element.style.width = '100%';
347
+ }
348
+ init(props) {
349
+ this.part = new ReactPart(this._element, this.reactPortalStore, this.component, props);
350
+ }
351
+ dispose() {
352
+ var _a;
353
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
354
+ }
355
+ }
356
+
357
+ class ReactTabGroupChipPart {
358
+ get element() {
359
+ return this._element;
360
+ }
361
+ constructor(component, reactPortalStore) {
362
+ this.component = component;
363
+ this.reactPortalStore = reactPortalStore;
364
+ this._element = document.createElement('div');
365
+ this._element.className = 'dv-react-part';
366
+ this._element.style.display = 'inline-flex';
367
+ }
368
+ init(params) {
369
+ this.part = new ReactPart(this._element, this.reactPortalStore, this.component, {
370
+ tabGroup: params.tabGroup,
371
+ api: params.api,
372
+ });
373
+ }
374
+ update(params) {
375
+ var _a;
376
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update({ tabGroup: params.tabGroup });
377
+ }
378
+ dispose() {
379
+ var _a;
380
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
381
+ }
382
+ }
10
383
 
384
+ class ReactGroupDragGhostPart {
385
+ get element() {
386
+ return this._element;
387
+ }
388
+ constructor(component, reactPortalStore) {
389
+ this.component = component;
390
+ this.reactPortalStore = reactPortalStore;
391
+ this._element = document.createElement('div');
392
+ this._element.className = 'dv-react-part';
393
+ this._element.style.display = 'inline-flex';
394
+ }
395
+ init(params) {
396
+ this.part = new ReactPart(this._element, this.reactPortalStore, this.component, {
397
+ group: params.group,
398
+ api: params.api,
399
+ });
400
+ }
401
+ dispose() {
402
+ var _a;
403
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
404
+ }
405
+ }
11
406
 
407
+ function createGroupControlElement(component, store) {
408
+ return component
409
+ ? (groupPanel) => {
410
+ return new ReactHeaderActionsRendererPart(component, store, groupPanel);
411
+ }
412
+ : undefined;
413
+ }
414
+ const DEFAULT_REACT_TAB = 'props.defaultTabComponent';
415
+ function extractCoreOptions$3(props) {
416
+ const coreOptions = dockview.PROPERTY_KEYS_DOCKVIEW.reduce((obj, key) => {
417
+ if (key in props) {
418
+ obj[key] = props[key];
419
+ }
420
+ return obj;
421
+ }, {});
422
+ return coreOptions;
423
+ }
424
+ const DockviewReact = React.forwardRef((props, ref) => {
425
+ const domRef = React.useRef(null);
426
+ const dockviewRef = React.useRef(undefined);
427
+ const [portals, addPortal] = usePortalsLifecycle();
428
+ React.useImperativeHandle(ref, () => domRef.current, []);
429
+ const prevProps = React.useRef({});
430
+ React.useEffect(() => {
431
+ const changes = {};
432
+ dockview.PROPERTY_KEYS_DOCKVIEW.forEach((propKey) => {
433
+ const key = propKey;
434
+ const propValue = props[key];
435
+ if (key in props && propValue !== prevProps.current[key]) {
436
+ changes[key] = propValue;
437
+ }
438
+ });
439
+ if (dockviewRef.current) {
440
+ dockviewRef.current.updateOptions(changes);
441
+ }
442
+ prevProps.current = props;
443
+ }, dockview.PROPERTY_KEYS_DOCKVIEW.map((key) => props[key]));
444
+ React.useEffect(() => {
445
+ var _a;
446
+ if (!domRef.current) {
447
+ return;
448
+ }
449
+ const frameworkTabComponents = (_a = props.tabComponents) !== null && _a !== void 0 ? _a : {};
450
+ if (props.defaultTabComponent) {
451
+ frameworkTabComponents[DEFAULT_REACT_TAB] =
452
+ props.defaultTabComponent;
453
+ }
454
+ const frameworkOptions = {
455
+ createLeftHeaderActionComponent: createGroupControlElement(props.leftHeaderActionsComponent, { addPortal }),
456
+ createRightHeaderActionComponent: createGroupControlElement(props.rightHeaderActionsComponent, { addPortal }),
457
+ createPrefixHeaderActionComponent: createGroupControlElement(props.prefixHeaderActionsComponent, { addPortal }),
458
+ createComponent: (options) => {
459
+ return new ReactPanelContentPart(options.id, props.components[options.name], {
460
+ addPortal,
461
+ });
462
+ },
463
+ createTabComponent(options) {
464
+ return new ReactPanelHeaderPart(options.id, frameworkTabComponents[options.name], {
465
+ addPortal,
466
+ });
467
+ },
468
+ createWatermarkComponent: props.watermarkComponent
469
+ ? () => {
470
+ return new ReactWatermarkPart('watermark', props.watermarkComponent, {
471
+ addPortal,
472
+ });
473
+ }
474
+ : undefined,
475
+ defaultTabComponent: props.defaultTabComponent
476
+ ? DEFAULT_REACT_TAB
477
+ : undefined,
478
+ createContextMenuItemComponent: (options) => {
479
+ if (!options.component) {
480
+ return undefined;
481
+ }
482
+ return new ReactContextMenuItemPart(options.id, options.component, { addPortal });
483
+ },
484
+ };
485
+ const coreOptions = extractCoreOptions$3(props);
486
+ if (props.tabGroupChipComponent) {
487
+ const chipComponent = props.tabGroupChipComponent;
488
+ coreOptions.createTabGroupChipComponent = () => {
489
+ return new ReactTabGroupChipPart(chipComponent, {
490
+ addPortal,
491
+ });
492
+ };
493
+ }
494
+ if (props.groupDragGhostComponent) {
495
+ const ghostComponent = props.groupDragGhostComponent;
496
+ coreOptions.createGroupDragGhostComponent = () => {
497
+ return new ReactGroupDragGhostPart(ghostComponent, {
498
+ addPortal,
499
+ });
500
+ };
501
+ }
502
+ const api = dockview.createDockview(domRef.current, Object.assign(Object.assign({}, coreOptions), frameworkOptions));
503
+ const { clientWidth, clientHeight } = domRef.current;
504
+ api.layout(clientWidth, clientHeight);
505
+ if (props.onReady) {
506
+ props.onReady({ api });
507
+ }
508
+ dockviewRef.current = api;
509
+ return () => {
510
+ dockviewRef.current = undefined;
511
+ api.dispose();
512
+ };
513
+ }, []);
514
+ React.useEffect(() => {
515
+ if (!dockviewRef.current) {
516
+ return () => {
517
+ // noop
518
+ };
519
+ }
520
+ const disposable = dockviewRef.current.onDidDrop((event) => {
521
+ if (props.onDidDrop) {
522
+ props.onDidDrop(event);
523
+ }
524
+ });
525
+ return () => {
526
+ disposable.dispose();
527
+ };
528
+ }, [props.onDidDrop]);
529
+ React.useEffect(() => {
530
+ if (!dockviewRef.current) {
531
+ return () => {
532
+ // noop
533
+ };
534
+ }
535
+ const disposable = dockviewRef.current.onWillDrop((event) => {
536
+ if (props.onWillDrop) {
537
+ props.onWillDrop(event);
538
+ }
539
+ });
540
+ return () => {
541
+ disposable.dispose();
542
+ };
543
+ }, [props.onWillDrop]);
544
+ React.useEffect(() => {
545
+ if (!dockviewRef.current) {
546
+ return;
547
+ }
548
+ dockviewRef.current.updateOptions({
549
+ createTabGroupChipComponent: props.tabGroupChipComponent
550
+ ? () => {
551
+ return new ReactTabGroupChipPart(props.tabGroupChipComponent, {
552
+ addPortal,
553
+ });
554
+ }
555
+ : undefined,
556
+ });
557
+ }, [props.tabGroupChipComponent]);
558
+ React.useEffect(() => {
559
+ if (!dockviewRef.current) {
560
+ return;
561
+ }
562
+ dockviewRef.current.updateOptions({
563
+ createGroupDragGhostComponent: props.groupDragGhostComponent
564
+ ? () => {
565
+ return new ReactGroupDragGhostPart(props.groupDragGhostComponent, {
566
+ addPortal,
567
+ });
568
+ }
569
+ : undefined,
570
+ });
571
+ }, [props.groupDragGhostComponent]);
572
+ React.useEffect(() => {
573
+ if (!dockviewRef.current) {
574
+ return;
575
+ }
576
+ dockviewRef.current.updateOptions({
577
+ createComponent: (options) => {
578
+ return new ReactPanelContentPart(options.id, props.components[options.name], {
579
+ addPortal,
580
+ });
581
+ },
582
+ });
583
+ }, [props.components]);
584
+ React.useEffect(() => {
585
+ var _a;
586
+ if (!dockviewRef.current) {
587
+ return;
588
+ }
589
+ const frameworkTabComponents = (_a = props.tabComponents) !== null && _a !== void 0 ? _a : {};
590
+ if (props.defaultTabComponent) {
591
+ frameworkTabComponents[DEFAULT_REACT_TAB] =
592
+ props.defaultTabComponent;
593
+ }
594
+ dockviewRef.current.updateOptions({
595
+ defaultTabComponent: props.defaultTabComponent
596
+ ? DEFAULT_REACT_TAB
597
+ : undefined,
598
+ createTabComponent(options) {
599
+ return new ReactPanelHeaderPart(options.id, frameworkTabComponents[options.name], {
600
+ addPortal,
601
+ });
602
+ },
603
+ });
604
+ }, [props.tabComponents, props.defaultTabComponent]);
605
+ React.useEffect(() => {
606
+ if (!dockviewRef.current) {
607
+ return;
608
+ }
609
+ dockviewRef.current.updateOptions({
610
+ createWatermarkComponent: props.watermarkComponent
611
+ ? () => {
612
+ return new ReactWatermarkPart('watermark', props.watermarkComponent, {
613
+ addPortal,
614
+ });
615
+ }
616
+ : undefined,
617
+ });
618
+ }, [props.watermarkComponent]);
619
+ React.useEffect(() => {
620
+ if (!dockviewRef.current) {
621
+ return;
622
+ }
623
+ dockviewRef.current.updateOptions({
624
+ createRightHeaderActionComponent: createGroupControlElement(props.rightHeaderActionsComponent, { addPortal }),
625
+ });
626
+ }, [props.rightHeaderActionsComponent]);
627
+ React.useEffect(() => {
628
+ if (!dockviewRef.current) {
629
+ return;
630
+ }
631
+ dockviewRef.current.updateOptions({
632
+ createLeftHeaderActionComponent: createGroupControlElement(props.leftHeaderActionsComponent, { addPortal }),
633
+ });
634
+ }, [props.leftHeaderActionsComponent]);
635
+ React.useEffect(() => {
636
+ if (!dockviewRef.current) {
637
+ return;
638
+ }
639
+ dockviewRef.current.updateOptions({
640
+ createPrefixHeaderActionComponent: createGroupControlElement(props.prefixHeaderActionsComponent, { addPortal }),
641
+ });
642
+ }, [props.prefixHeaderActionsComponent]);
643
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
644
+ });
645
+ DockviewReact.displayName = 'DockviewComponent';
646
+
647
+ /******************************************************************************
648
+ Copyright (c) Microsoft Corporation.
649
+
650
+ Permission to use, copy, modify, and/or distribute this software for any
651
+ purpose with or without fee is hereby granted.
652
+
653
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
654
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
655
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
656
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
657
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
658
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
659
+ PERFORMANCE OF THIS SOFTWARE.
660
+ ***************************************************************************** */
661
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
662
+
663
+
664
+ function __rest(s, e) {
665
+ var t = {};
666
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
667
+ t[p] = s[p];
668
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
669
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
670
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
671
+ t[p[i]] = s[p[i]];
672
+ }
673
+ return t;
674
+ }
675
+
676
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
677
+ var e = new Error(message);
678
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
679
+ };
680
+
681
+ const CloseButton = () => (React.createElement("svg", { height: "11", width: "11", viewBox: "0 0 28 28", "aria-hidden": 'false', focusable: false, className: "dv-svg" },
682
+ React.createElement("path", { d: "M2.1 27.3L0 25.2L11.55 13.65L0 2.1L2.1 0L13.65 11.55L25.2 0L27.3 2.1L15.75 13.65L27.3 25.2L25.2 27.3L13.65 15.75L2.1 27.3Z" })));
683
+
684
+ function useTitle(api) {
685
+ const [title, setTitle] = React.useState(api.title);
686
+ React.useEffect(() => {
687
+ const disposable = api.onDidTitleChange((event) => {
688
+ setTitle(event.title);
689
+ });
690
+ // Depending on the order in which React effects are run, the title may already be out of sync (cf. issue #1003).
691
+ if (title !== api.title) {
692
+ setTitle(api.title);
693
+ }
694
+ return () => {
695
+ disposable.dispose();
696
+ };
697
+ }, [api]);
698
+ return title;
699
+ }
700
+ const DockviewDefaultTab = (_a) => {
701
+ var { api, containerApi: _containerApi, params: _params, hideClose, closeActionOverride, onPointerDown, onPointerUp, onPointerLeave, tabLocation } = _a, rest = __rest(_a, ["api", "containerApi", "params", "hideClose", "closeActionOverride", "onPointerDown", "onPointerUp", "onPointerLeave", "tabLocation"]);
702
+ const title = useTitle(api);
703
+ const isMiddleMouseButton = React.useRef(false);
704
+ const onClose = React.useCallback((event) => {
705
+ event.preventDefault();
706
+ if (closeActionOverride) {
707
+ closeActionOverride();
708
+ }
709
+ else {
710
+ api.close();
711
+ }
712
+ }, [api, closeActionOverride]);
713
+ const onBtnPointerDown = React.useCallback((event) => {
714
+ event.preventDefault();
715
+ }, []);
716
+ const _onPointerDown = React.useCallback((event) => {
717
+ isMiddleMouseButton.current = event.button === 1;
718
+ onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown(event);
719
+ }, [onPointerDown]);
720
+ const _onPointerUp = React.useCallback((event) => {
721
+ if (isMiddleMouseButton && event.button === 1 && !hideClose) {
722
+ isMiddleMouseButton.current = false;
723
+ onClose(event);
724
+ }
725
+ onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp(event);
726
+ }, [onPointerUp, onClose, hideClose]);
727
+ const _onPointerLeave = React.useCallback((event) => {
728
+ isMiddleMouseButton.current = false;
729
+ onPointerLeave === null || onPointerLeave === void 0 ? void 0 : onPointerLeave(event);
730
+ }, [onPointerLeave]);
731
+ return (React.createElement("div", Object.assign({ "data-testid": "dockview-dv-default-tab" }, rest, { onPointerDown: _onPointerDown, onPointerUp: _onPointerUp, onPointerLeave: _onPointerLeave, className: "dv-default-tab" }),
732
+ React.createElement("span", { className: "dv-default-tab-content" }, title),
733
+ !hideClose && (React.createElement("div", { className: "dv-default-tab-action", onPointerDown: onBtnPointerDown, onClick: onClose },
734
+ React.createElement(CloseButton, null)))));
735
+ };
736
+
737
+ class ReactPanelView extends dockview.SplitviewPanel {
738
+ constructor(id, component, reactComponent, reactPortalStore) {
739
+ super(id, component);
740
+ this.reactComponent = reactComponent;
741
+ this.reactPortalStore = reactPortalStore;
742
+ }
743
+ getComponent() {
744
+ var _a, _b;
745
+ return new ReactPart(this.element, this.reactPortalStore, this.reactComponent, {
746
+ params: (_b = (_a = this._params) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : {},
747
+ api: this.api,
748
+ containerApi: new dockview.SplitviewApi(this._params.accessor),
749
+ });
750
+ }
751
+ }
752
+
753
+ function extractCoreOptions$2(props) {
754
+ const coreOptions = dockview.PROPERTY_KEYS_SPLITVIEW.reduce((obj, key) => {
755
+ if (key in props) {
756
+ obj[key] = props[key];
757
+ }
758
+ return obj;
759
+ }, {});
760
+ return coreOptions;
761
+ }
762
+ const SplitviewReact = React.forwardRef((props, ref) => {
763
+ const domRef = React.useRef(null);
764
+ const splitviewRef = React.useRef(undefined);
765
+ const [portals, addPortal] = usePortalsLifecycle();
766
+ React.useImperativeHandle(ref, () => domRef.current, []);
767
+ const prevProps = React.useRef({});
768
+ React.useEffect(() => {
769
+ const changes = {};
770
+ dockview.PROPERTY_KEYS_SPLITVIEW.forEach((propKey) => {
771
+ const key = propKey;
772
+ const propValue = props[key];
773
+ if (key in props && propValue !== prevProps.current[key]) {
774
+ changes[key] = propValue;
775
+ }
776
+ });
777
+ if (splitviewRef.current) {
778
+ splitviewRef.current.updateOptions(changes);
779
+ }
780
+ prevProps.current = props;
781
+ }, dockview.PROPERTY_KEYS_SPLITVIEW.map((key) => props[key]));
782
+ React.useEffect(() => {
783
+ if (!domRef.current) {
784
+ return () => {
785
+ // noop
786
+ };
787
+ }
788
+ const frameworkOptions = {
789
+ createComponent: (options) => {
790
+ return new ReactPanelView(options.id, options.name, props.components[options.name], { addPortal });
791
+ },
792
+ };
793
+ const api = dockview.createSplitview(domRef.current, Object.assign(Object.assign({}, extractCoreOptions$2(props)), frameworkOptions));
794
+ const { clientWidth, clientHeight } = domRef.current;
795
+ api.layout(clientWidth, clientHeight);
796
+ if (props.onReady) {
797
+ props.onReady({ api });
798
+ }
799
+ splitviewRef.current = api;
800
+ return () => {
801
+ splitviewRef.current = undefined;
802
+ api.dispose();
803
+ };
804
+ }, []);
805
+ React.useEffect(() => {
806
+ if (!splitviewRef.current) {
807
+ return;
808
+ }
809
+ splitviewRef.current.updateOptions({
810
+ createComponent: (options) => {
811
+ return new ReactPanelView(options.id, options.name, props.components[options.name], { addPortal });
812
+ },
813
+ });
814
+ }, [props.components]);
815
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
816
+ });
817
+ SplitviewReact.displayName = 'SplitviewComponent';
818
+
819
+ class ReactGridPanelView extends dockview.GridviewPanel {
820
+ constructor(id, component, reactComponent, reactPortalStore) {
821
+ super(id, component);
822
+ this.reactComponent = reactComponent;
823
+ this.reactPortalStore = reactPortalStore;
824
+ }
825
+ getComponent() {
826
+ var _a, _b;
827
+ return new ReactPart(this.element, this.reactPortalStore, this.reactComponent, {
828
+ params: (_b = (_a = this._params) === null || _a === void 0 ? void 0 : _a.params) !== null && _b !== void 0 ? _b : {},
829
+ api: this.api,
830
+ // TODO: fix casting hack
831
+ containerApi: new dockview.GridviewApi(this._params
832
+ .accessor),
833
+ });
834
+ }
835
+ }
836
+
837
+ function extractCoreOptions$1(props) {
838
+ const coreOptions = dockview.PROPERTY_KEYS_GRIDVIEW.reduce((obj, key) => {
839
+ if (key in props) {
840
+ obj[key] = props[key];
841
+ }
842
+ return obj;
843
+ }, {});
844
+ return coreOptions;
845
+ }
846
+ const GridviewReact = React.forwardRef((props, ref) => {
847
+ const domRef = React.useRef(null);
848
+ const gridviewRef = React.useRef(undefined);
849
+ const [portals, addPortal] = usePortalsLifecycle();
850
+ React.useImperativeHandle(ref, () => domRef.current, []);
851
+ const prevProps = React.useRef({});
852
+ React.useEffect(() => {
853
+ const changes = {};
854
+ dockview.PROPERTY_KEYS_GRIDVIEW.forEach((propKey) => {
855
+ const key = propKey;
856
+ const propValue = props[key];
857
+ if (key in props && propValue !== prevProps.current[key]) {
858
+ changes[key] = propValue;
859
+ }
860
+ });
861
+ if (gridviewRef.current) {
862
+ gridviewRef.current.updateOptions(changes);
863
+ }
864
+ prevProps.current = props;
865
+ }, dockview.PROPERTY_KEYS_GRIDVIEW.map((key) => props[key]));
866
+ React.useEffect(() => {
867
+ if (!domRef.current) {
868
+ return () => {
869
+ // noop
870
+ };
871
+ }
872
+ const frameworkOptions = {
873
+ createComponent: (options) => {
874
+ return new ReactGridPanelView(options.id, options.name, props.components[options.name], { addPortal });
875
+ },
876
+ };
877
+ const api = dockview.createGridview(domRef.current, Object.assign(Object.assign({}, extractCoreOptions$1(props)), frameworkOptions));
878
+ const { clientWidth, clientHeight } = domRef.current;
879
+ api.layout(clientWidth, clientHeight);
880
+ if (props.onReady) {
881
+ props.onReady({ api });
882
+ }
883
+ gridviewRef.current = api;
884
+ return () => {
885
+ gridviewRef.current = undefined;
886
+ api.dispose();
887
+ };
888
+ }, []);
889
+ React.useEffect(() => {
890
+ if (!gridviewRef.current) {
891
+ return;
892
+ }
893
+ gridviewRef.current.updateOptions({
894
+ createComponent: (options) => {
895
+ return new ReactGridPanelView(options.id, options.name, props.components[options.name], { addPortal });
896
+ },
897
+ });
898
+ }, [props.components]);
899
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
900
+ });
901
+ GridviewReact.displayName = 'GridviewComponent';
902
+
903
+ class PanePanelSection {
904
+ get element() {
905
+ return this._element;
906
+ }
907
+ constructor(id, component, reactPortalStore) {
908
+ this.id = id;
909
+ this.component = component;
910
+ this.reactPortalStore = reactPortalStore;
911
+ this._element = document.createElement('div');
912
+ this._element.style.height = '100%';
913
+ this._element.style.width = '100%';
914
+ }
915
+ init(parameters) {
916
+ this.part = new ReactPart(this.element, this.reactPortalStore, this.component, {
917
+ params: parameters.params,
918
+ api: parameters.api,
919
+ title: parameters.title,
920
+ containerApi: parameters.containerApi,
921
+ });
922
+ }
923
+ toJSON() {
924
+ return {
925
+ id: this.id,
926
+ };
927
+ }
928
+ update(params) {
929
+ var _a;
930
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.update(params.params);
931
+ }
932
+ dispose() {
933
+ var _a;
934
+ (_a = this.part) === null || _a === void 0 ? void 0 : _a.dispose();
935
+ }
936
+ }
937
+
938
+ function extractCoreOptions(props) {
939
+ const coreOptions = dockview.PROPERTY_KEYS_PANEVIEW.reduce((obj, key) => {
940
+ if (key in props) {
941
+ obj[key] = props[key];
942
+ }
943
+ return obj;
944
+ }, {});
945
+ return coreOptions;
946
+ }
947
+ const PaneviewReact = React.forwardRef((props, ref) => {
948
+ const domRef = React.useRef(null);
949
+ const paneviewRef = React.useRef(undefined);
950
+ const [portals, addPortal] = usePortalsLifecycle();
951
+ React.useImperativeHandle(ref, () => domRef.current, []);
952
+ const prevProps = React.useRef({});
953
+ React.useEffect(() => {
954
+ const changes = {};
955
+ dockview.PROPERTY_KEYS_PANEVIEW.forEach((propKey) => {
956
+ const key = propKey;
957
+ const propValue = props[key];
958
+ if (key in props && propValue !== prevProps.current[key]) {
959
+ changes[key] = propValue;
960
+ }
961
+ });
962
+ if (paneviewRef.current) {
963
+ paneviewRef.current.updateOptions(changes);
964
+ }
965
+ prevProps.current = props;
966
+ }, dockview.PROPERTY_KEYS_PANEVIEW.map((key) => props[key]));
967
+ React.useEffect(() => {
968
+ var _a;
969
+ if (!domRef.current) {
970
+ return () => {
971
+ // noop
972
+ };
973
+ }
974
+ const headerComponents = (_a = props.headerComponents) !== null && _a !== void 0 ? _a : {};
975
+ const frameworkOptions = {
976
+ createComponent: (options) => {
977
+ return new PanePanelSection(options.id, props.components[options.name], { addPortal });
978
+ },
979
+ createHeaderComponent: (options) => {
980
+ return new PanePanelSection(options.id, headerComponents[options.name], { addPortal });
981
+ },
982
+ };
983
+ const api = dockview.createPaneview(domRef.current, Object.assign(Object.assign({}, extractCoreOptions(props)), frameworkOptions));
984
+ const { clientWidth, clientHeight } = domRef.current;
985
+ api.layout(clientWidth, clientHeight);
986
+ if (props.onReady) {
987
+ props.onReady({ api });
988
+ }
989
+ paneviewRef.current = api;
990
+ return () => {
991
+ paneviewRef.current = undefined;
992
+ api.dispose();
993
+ };
994
+ }, []);
995
+ React.useEffect(() => {
996
+ if (!paneviewRef.current) {
997
+ return;
998
+ }
999
+ paneviewRef.current.updateOptions({
1000
+ createComponent: (options) => {
1001
+ return new PanePanelSection(options.id, props.components[options.name], { addPortal });
1002
+ },
1003
+ });
1004
+ }, [props.components]);
1005
+ React.useEffect(() => {
1006
+ var _a;
1007
+ if (!paneviewRef.current) {
1008
+ return;
1009
+ }
1010
+ const headerComponents = (_a = props.headerComponents) !== null && _a !== void 0 ? _a : {};
1011
+ paneviewRef.current.updateOptions({
1012
+ createHeaderComponent: (options) => {
1013
+ return new PanePanelSection(options.id, headerComponents[options.name], { addPortal });
1014
+ },
1015
+ });
1016
+ }, [props.headerComponents]);
1017
+ React.useEffect(() => {
1018
+ if (!paneviewRef.current) {
1019
+ return () => {
1020
+ // noop
1021
+ };
1022
+ }
1023
+ const disposable = paneviewRef.current.onDidDrop((event) => {
1024
+ if (props.onDidDrop) {
1025
+ props.onDidDrop(event);
1026
+ }
1027
+ });
1028
+ return () => {
1029
+ disposable.dispose();
1030
+ };
1031
+ }, [props.onDidDrop]);
1032
+ return (React.createElement("div", { style: { height: '100%', width: '100%' }, ref: domRef }, portals));
1033
+ });
1034
+ PaneviewReact.displayName = 'PaneviewComponent';
12
1035
 
1036
+ exports.DockviewDefaultTab = DockviewDefaultTab;
1037
+ exports.DockviewReact = DockviewReact;
1038
+ exports.GridviewReact = GridviewReact;
1039
+ exports.PaneviewReact = PaneviewReact;
1040
+ exports.ReactPart = ReactPart;
1041
+ exports.ReactPartContext = ReactPartContext;
1042
+ exports.SplitviewReact = SplitviewReact;
1043
+ exports.isReactComponent = isReactComponent;
1044
+ exports.usePortalsLifecycle = usePortalsLifecycle;
13
1045
  Object.keys(dockview).forEach(function (k) {
14
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
15
- enumerable: true,
16
- get: function () { return dockview[k]; }
17
- });
1046
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
1047
+ enumerable: true,
1048
+ get: function () { return dockview[k]; }
1049
+ });
18
1050
  });