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