dockview 7.0.3 → 8.0.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.
@@ -1,953 +1,20 @@
1
1
  /**
2
2
  * dockview
3
- * @version 7.0.3
4
- * @link https://github.com/mathuo/dockview
3
+ * @version 8.0.0
4
+ * @link https://github.com/dockview/dockview
5
5
  * @license MIT
6
6
  */
7
- import { defineModule, DockviewCompositeDisposable, DockviewDisposable, findRelativeZIndexParent, LiveRegionModule, resolveMessages, registerModules, markDockviewPackageLoaded } from 'dockview-core';
8
- export * from 'dockview-core';
7
+ export * from "dockview-core"
9
8
 
9
+ //#region src/index.ts
10
10
  /**
11
- * dockview-modules
12
- * @version 7.0.3
13
- * @link https://github.com/mathuo/dockview
14
- * @license MIT
15
- */
16
-
17
- class TabGroupChipsService {
18
- constructor(host) {
19
- this._host = host;
20
- }
21
- attachToGroup(group) {
22
- return new DockviewCompositeDisposable(group.model.onDidCreateTabGroup((e) => {
23
- this._host.fireDidCreateTabGroup(e);
24
- }), group.model.onDidDestroyTabGroup((e) => {
25
- this._host.fireDidDestroyTabGroup(e);
26
- }), group.model.onDidAddPanelToTabGroup((e) => {
27
- this._host.fireDidAddPanelToTabGroup(e);
28
- }), group.model.onDidRemovePanelFromTabGroup((e) => {
29
- this._host.fireDidRemovePanelFromTabGroup(e);
30
- }), group.model.onDidTabGroupChange((e) => {
31
- this._host.fireDidTabGroupChange(e);
32
- }), group.model.onDidTabGroupCollapsedChange((e) => {
33
- this._host.fireDidTabGroupCollapsedChange(e);
34
- }));
35
- }
36
- dispose() {
37
- // No internal state to tear down — emitters live on the host.
38
- }
39
- }
40
- const TabGroupChipsModule = defineModule({
41
- name: 'TabGroupChips',
42
- serviceKey: 'tabGroupChipsService',
43
- create: (host) => new TabGroupChipsService(host),
44
- init: (host, service) => {
45
- // Self-attach to existing and future groups; tear down when groups
46
- // are removed. Component doesn't need to know about this wiring.
47
- const perGroupDisposables = new Map();
48
- return new DockviewCompositeDisposable(host.onDidAddGroup((group) => {
49
- perGroupDisposables.set(group, service.attachToGroup(group));
50
- }), host.onDidRemoveGroup((group) => {
51
- var _a;
52
- (_a = perGroupDisposables.get(group)) === null || _a === void 0 ? void 0 : _a.dispose();
53
- perGroupDisposables.delete(group);
54
- }), {
55
- dispose: () => {
56
- for (const d of perGroupDisposables.values()) {
57
- d.dispose();
58
- }
59
- perGroupDisposables.clear();
60
- },
61
- });
62
- },
63
- });
64
-
65
- function popoverZIndexFor(target) {
66
- if (!(target instanceof HTMLElement)) {
67
- return undefined;
68
- }
69
- // Floating overlays live in the shell as siblings of the popover anchor
70
- // and the AriaLevelTracker sets their inline z-index. Without this, a
71
- // popover opened from inside a floating group would render behind it
72
- // because they share the shell stacking context.
73
- const relativeParent = findRelativeZIndexParent(target);
74
- return (relativeParent === null || relativeParent === void 0 ? void 0 : relativeParent.style.zIndex)
75
- ? `calc(${relativeParent.style.zIndex} * 2)`
76
- : undefined;
77
- }
78
- let _nextId = 0;
79
- const nextContextMenuItemId = () => `dv-ctx-menu-item-${_nextId++}`;
80
- function isItemConfig(item) {
81
- return typeof item === 'object';
82
- }
83
- function buildItem(label, close, action, disabled) {
84
- const el = document.createElement('div');
85
- el.className = 'dv-context-menu-item';
86
- el.setAttribute('role', 'menuitem');
87
- if (disabled) {
88
- el.classList.add('dv-context-menu-item--disabled');
89
- el.setAttribute('aria-disabled', 'true');
90
- }
91
- el.textContent = label;
92
- if (!disabled) {
93
- el.addEventListener('click', () => {
94
- action();
95
- close();
96
- });
97
- }
98
- return el;
99
- }
100
- function buildSeparator() {
101
- const el = document.createElement('div');
102
- el.className = 'dv-context-menu-separator';
103
- el.setAttribute('role', 'separator');
104
- return el;
105
- }
106
- function isCoarsePrimaryInput() {
107
- if (globalThis.window === undefined || !globalThis.matchMedia) {
108
- return false;
109
- }
110
- const coarse = globalThis.matchMedia('(pointer: coarse)').matches;
111
- const fine = globalThis.matchMedia('(pointer: fine)').matches;
112
- return coarse && !fine;
113
- }
114
- function buildRenameInput(tabGroup) {
115
- const wrapper = document.createElement('div');
116
- wrapper.className = 'dv-context-menu-rename';
117
- const input = document.createElement('input');
118
- input.className = 'dv-context-menu-rename-input';
119
- input.type = 'text';
120
- input.placeholder = 'Name This Group';
121
- input.value = tabGroup.label;
122
- input.addEventListener('input', () => {
123
- tabGroup.setLabel(input.value);
124
- });
125
- input.addEventListener('keydown', (e) => {
126
- if (e.key !== 'Escape' && e.key !== 'Enter') {
127
- e.stopPropagation();
128
- }
129
- });
130
- input.addEventListener('click', (e) => {
131
- e.stopPropagation();
132
- });
133
- wrapper.appendChild(input);
134
- // Skip auto-focus on touch-primary devices: focusing the input pops the
135
- // on-screen keyboard, which fires `window resize`, which `PopupService`
136
- // listens to and uses to dismiss the popover — so the menu opens, the
137
- // keyboard appears, and the menu immediately closes before the user can
138
- // type. The user can still tap the input to focus it intentionally.
139
- if (!isCoarsePrimaryInput()) {
140
- requestAnimationFrame(() => {
141
- input.focus();
142
- input.select();
143
- });
144
- }
145
- return wrapper;
146
- }
147
- function buildColorPicker(tabGroup, palette) {
148
- const wrapper = document.createElement('div');
149
- wrapper.className = 'dv-context-menu-color-picker';
150
- if (!palette.enabled) {
151
- // Opt-out: render no swatches. Returning a wrapper rather than null
152
- // keeps the call site simple; the wrapper is empty and visually inert.
153
- return wrapper;
154
- }
155
- for (const entry of palette.entries()) {
156
- const swatch = document.createElement('div');
157
- swatch.className = 'dv-context-menu-color-swatch';
158
- // Use a CSS custom property rather than setting `backgroundColor`
159
- // directly: the IDL setter validates the value against a color
160
- // grammar and rejects `var(...)` references in some environments
161
- // (notably jsdom; some browsers have historically had similar
162
- // quirks). The matching SCSS rule reads the var at use time.
163
- swatch.style.setProperty('--dv-tab-group-color', entry.value);
164
- if (entry.label) {
165
- swatch.title = entry.label;
166
- }
167
- if (tabGroup.color === entry.id) {
168
- swatch.classList.add('dv-context-menu-color-swatch--selected');
169
- }
170
- swatch.addEventListener('click', () => {
171
- tabGroup.setColor(entry.id);
172
- });
173
- wrapper.appendChild(swatch);
174
- }
175
- return wrapper;
176
- }
177
- class ContextMenuController {
178
- constructor(accessor) {
179
- this.accessor = accessor;
180
- }
181
- show(panel, group, event) {
182
- var _a, _b;
183
- if (!this.accessor.options.getTabContextMenuItems) {
184
- return;
185
- }
186
- const items = this.accessor.options.getTabContextMenuItems({
187
- panel,
188
- group,
189
- api: this.accessor.api,
190
- event,
191
- });
192
- if (items.length === 0) {
193
- return;
194
- }
195
- event.preventDefault();
196
- const popupService = this.accessor.getPopupServiceForGroup(group);
197
- const close = () => popupService.close();
198
- const menuEl = document.createElement('div');
199
- menuEl.className = 'dv-context-menu';
200
- menuEl.setAttribute('role', 'menu');
201
- for (const item of items) {
202
- if (item === 'separator') {
203
- menuEl.appendChild(buildSeparator());
204
- }
205
- else if (item === 'close') {
206
- menuEl.appendChild(buildItem('Close', close, () => panel.api.close()));
207
- }
208
- else if (item === 'closeOthers') {
209
- menuEl.appendChild(buildItem('Close Others', close, () => {
210
- group.panels
211
- .filter((p) => p !== panel)
212
- .forEach((p) => p.api.close());
213
- }));
214
- }
215
- else if (item === 'closeAll') {
216
- menuEl.appendChild(buildItem('Close All', close, () => {
217
- [...group.panels].forEach((p) => p.api.close());
218
- }));
219
- }
220
- else if (isItemConfig(item) && item.element) {
221
- menuEl.appendChild(item.element);
222
- }
223
- else if (isItemConfig(item) && item.component) {
224
- const renderer = (_b = (_a = this.accessor.options).createContextMenuItemComponent) === null || _b === void 0 ? void 0 : _b.call(_a, {
225
- id: nextContextMenuItemId(),
226
- component: item.component,
227
- });
228
- if (renderer) {
229
- renderer.init({
230
- panel,
231
- group,
232
- api: this.accessor.api,
233
- close,
234
- componentProps: item.componentProps,
235
- });
236
- menuEl.appendChild(renderer.element);
237
- }
238
- }
239
- else if (isItemConfig(item) && item.label) {
240
- menuEl.appendChild(buildItem(item.label, close, () => { var _a; return (_a = item.action) === null || _a === void 0 ? void 0 : _a.call(item); }, item.disabled));
241
- }
242
- }
243
- popupService.openPopover(menuEl, {
244
- x: event.clientX,
245
- y: event.clientY,
246
- zIndex: popoverZIndexFor(event.target),
247
- });
248
- }
249
- showForChip(tabGroup, group, event) {
250
- if (!this.accessor.options.getTabGroupChipContextMenuItems) {
251
- return;
252
- }
253
- const items = this.accessor.options.getTabGroupChipContextMenuItems({
254
- tabGroup,
255
- group,
256
- api: this.accessor.api,
257
- event,
258
- });
259
- if (items.length === 0) {
260
- return;
261
- }
262
- event.preventDefault();
263
- const popupService = this.accessor.getPopupServiceForGroup(group);
264
- const close = () => popupService.close();
265
- const menuEl = document.createElement('div');
266
- menuEl.className = 'dv-context-menu';
267
- menuEl.setAttribute('role', 'menu');
268
- for (const item of items) {
269
- if (item === 'separator') {
270
- menuEl.appendChild(buildSeparator());
271
- }
272
- else if (item === 'rename') {
273
- menuEl.appendChild(buildRenameInput(tabGroup));
274
- }
275
- else if (item === 'colorPicker') {
276
- menuEl.appendChild(buildColorPicker(tabGroup, this.accessor.tabGroupColorPalette));
277
- }
278
- else if (isItemConfig(item) && item.element) {
279
- menuEl.appendChild(item.element);
280
- }
281
- else if (isItemConfig(item) && item.label) {
282
- menuEl.appendChild(buildItem(item.label, close, () => { var _a; return (_a = item.action) === null || _a === void 0 ? void 0 : _a.call(item); }, item.disabled));
283
- }
284
- }
285
- popupService.openPopover(menuEl, {
286
- x: event.clientX,
287
- y: event.clientY,
288
- zIndex: popoverZIndexFor(event.target),
289
- });
290
- }
291
- }
292
- const ContextMenuModule = defineModule({
293
- name: 'ContextMenu',
294
- serviceKey: 'contextMenuService',
295
- create: (host) => new ContextMenuController(host),
296
- });
297
-
298
- /** Cursor offset of the group drag ghost, matched to the long-shipped default. */
299
- const GROUP_DRAG_GHOST_OFFSET_X = 30;
300
- const GROUP_DRAG_GHOST_OFFSET_Y = -10;
301
- /**
302
- * The narrow surface the {@link AdvancedDnDService} needs from the host
303
- * (the `DockviewComponent`).
304
- *
305
- * The `onWill*` emitters stay on the component so the public event shape is
306
- * unchanged whether or not this module is registered — the service is only the
307
- * dispatch point those fires are routed through. Engine policy (e.g. the
308
- * `disableDnd` guard) stays on the component, ahead of the dispatch.
309
- */
310
- /**
311
- * Owns the dispatch of the advanced drag-and-drop hooks — `onWillDragPanel`,
312
- * `onWillDragGroup`, `onWillDrop` and `onWillShowOverlay`.
313
- *
314
- * At this stage the service is a thin dispatcher that forwards to the host's
315
- * emitters; the customisation surface it gates (custom drop overlays, custom
316
- * group drag ghosts, hook veto/transform behaviour) is currently inlined in
317
- * core and is extracted into this service in later phases. Routing the
318
- * dispatch through a module slot is what lets that customisation layer move
319
- * into a separately-distributed package in a future major version without
320
- * changing the public event surface.
321
- *
322
- * The service holds no drag state of its own — the gesture is driven by the
323
- * DnD backends, and the per-group subscriptions live on the component's group
324
- * lifecycle (so groups created mid-move are not missed).
325
- */
326
- class AdvancedDnDService {
327
- constructor(host) {
328
- this.host = host;
329
- }
330
- dispatchWillDragPanel(event) {
331
- this.host.fireWillDragPanel(event);
332
- }
333
- dispatchWillDragGroup(event) {
334
- this.host.fireWillDragGroup(event);
335
- }
336
- dispatchWillDrop(event) {
337
- this.host.fireWillDrop(event);
338
- }
339
- dispatchWillShowOverlay(event) {
340
- this.host.fireWillShowOverlay(event);
341
- }
342
- buildGroupDragGhost(group) {
343
- const createGhost = this.host.options.createGroupDragGhostComponent;
344
- if (!createGhost) {
345
- return undefined;
346
- }
347
- const renderer = createGhost(group);
348
- renderer.init({ group, api: this.host.api });
349
- return {
350
- element: renderer.element,
351
- offsetX: GROUP_DRAG_GHOST_OFFSET_X,
352
- offsetY: GROUP_DRAG_GHOST_OFFSET_Y,
353
- dispose: renderer.dispose ? () => { var _a; return (_a = renderer.dispose) === null || _a === void 0 ? void 0 : _a.call(renderer); } : undefined,
354
- };
355
- }
356
- resolveOverlayModel(location, group) {
357
- var _a, _b;
358
- return (_b = (_a = this.host.options).dropOverlayModel) === null || _b === void 0 ? void 0 : _b.call(_a, { location, group });
359
- }
360
- showPreviewOverlay(group, position) {
361
- const target = group.model.contentDropTarget;
362
- target.showOverlay(position);
363
- return DockviewDisposable.from(() => target.clearOverlay());
364
- }
365
- dispose() {
366
- // no-op — see class doc: the service holds no state to tear down.
367
- }
368
- }
369
- const AdvancedDnDModule = defineModule({
370
- name: 'AdvancedDnD',
371
- serviceKey: 'advancedDnDService',
372
- create: (host) => new AdvancedDnDService(host),
373
- });
11
+ * `dockview` is the recommended free entry point: a thin re-export of
12
+ * `dockview-core`. The separable enterprise feature modules now live in the
13
+ * separately-published `dockview-enterprise` package (which depends on and
14
+ * re-exports `dockview`); install that to opt into them.
15
+ *
16
+ * This module has no side effects (it's a pure re-export), so bundlers can
17
+ * fully tree-shake unused exports out of consumer builds.
18
+ */
374
19
 
375
- /**
376
- * Marks (on the dockview root element) that a keyboard move is in progress, so
377
- * the default navigation listener stands down while the advanced docking module
378
- * drives the keys. A neutral DOM signal keeps the two listeners coordinated
379
- * without either service holding a reference to the other.
380
- */
381
- const KEYBOARD_MOVE_ATTRIBUTE = 'data-dv-kbd-moving';
382
- /**
383
- * Does `e` match a binding string like `'ctrl+]'` / `'shift+f6'`? Modifiers are
384
- * matched exactly (a binding without `shift` will not fire while Shift is held),
385
- * and the final part is compared to `KeyboardEvent.key`, lower-cased.
386
- */
387
- function matchesBinding(e, binding) {
388
- const parts = binding.toLowerCase().split('+');
389
- const key = parts[parts.length - 1];
390
- const mods = parts.slice(0, -1);
391
- return (e.ctrlKey === mods.includes('ctrl') &&
392
- e.shiftKey === mods.includes('shift') &&
393
- e.altKey === mods.includes('alt') &&
394
- e.metaKey === (mods.includes('meta') || mods.includes('cmd')) &&
395
- e.key.toLowerCase() === key);
396
- }
397
- /**
398
- * Resolve the `keyboardNavigation` opt-in to its options object, or `undefined`
399
- * when keyboard support is off. Both keyboard modules read the same opt-in.
400
- */
401
- function readKeyboardNavigation(options) {
402
- const opt = options.keyboardNavigation;
403
- if (!opt) {
404
- return undefined;
405
- }
406
- return opt === true ? {} : opt;
407
- }
408
-
409
- const DEFAULT_KEYMAP$1 = {
410
- nextTab: 'ctrl+]',
411
- prevTab: 'ctrl+[',
412
- focusNextGroup: 'f6',
413
- focusPrevGroup: 'shift+f6',
414
- focusTabs: 'ctrl+shift+\\',
415
- };
416
- /**
417
- * Keyboard navigation & focus management — operate the dock without a mouse.
418
- * Opt-in via `keyboardNavigation`, with a rebindable {@link DockviewKeybindings}
419
- * keymap.
420
- *
421
- * - **Switch tab** (`Ctrl+]` / `Ctrl+[`) — cycle the focused group's tabs.
422
- * - **Focus group** (`F6` / `Shift+F6`) — move focus to the next / previous
423
- * group in sequence.
424
- * - **Focus the tab strip** (`Ctrl+Shift+\`) — jump focus from panel content to
425
- * the active group's tab strip (the strip's roving-tabindex takes over).
426
- * - **Focus restore on close** — when removing a panel/group pulls focus out of
427
- * the dock, focus returns to the neighbour the layout just activated instead
428
- * of being stranded on `<body>`.
429
- * - **Floating `Esc`** — `Esc` inside a floating group returns focus to the
430
- * control that had it before entering the float (polite: bubble phase,
431
- * respects `defaultPrevented`, so panel content keeps `Esc`).
432
- * - **Floating Tab-containment** — Tab wraps within the floating group so focus
433
- * doesn't leak to the grid behind it.
434
- *
435
- * Stands down while an advanced keyboard move is in progress (see
436
- * {@link KEYBOARD_MOVE_ATTRIBUTE}) so the docking module owns the keys then.
437
- */
438
- class AccessibilityService extends DockviewCompositeDisposable {
439
- constructor(host) {
440
- super();
441
- this.host = host;
442
- this._focusWasInside = false;
443
- // Listen on the document (capture) rather than the dockview element:
444
- // edge groups live in the shell *outside* the gridview, and the shell
445
- // is created after this service, so a fixed element would miss them.
446
- const doc = host.rootElement.ownerDocument;
447
- const onKeyDown = (e) => this._onKeyDown(e);
448
- doc.addEventListener('keydown', onKeyDown, true);
449
- // Remember the last control focused in the main dock (outside any
450
- // float) so Esc inside a floating group can return focus to its
451
- // invoking control. Observe-only — never consumes.
452
- const onFocusIn = (e) => {
453
- const t = e.target;
454
- if (t instanceof HTMLElement &&
455
- this.host.rootElement.contains(t) &&
456
- !t.closest('[role="dialog"]')) {
457
- this._lastNonFloatFocus = t;
458
- }
459
- };
460
- doc.addEventListener('focusin', onFocusIn, true);
461
- // Esc-from-float restore runs in the BUBBLE phase and respects
462
- // defaultPrevented, so panel content that uses Esc keeps priority.
463
- const onEscape = (e) => this._onFloatingEscape(e);
464
- doc.addEventListener('keydown', onEscape, false);
465
- this.addDisposables({
466
- dispose: () => doc.removeEventListener('keydown', onKeyDown, true),
467
- }, {
468
- dispose: () => doc.removeEventListener('focusin', onFocusIn, true),
469
- }, {
470
- dispose: () => doc.removeEventListener('keydown', onEscape, false),
471
- },
472
- // When a close pulls focus out of the dock, return it to the
473
- // neighbour the component just activated rather than leaving it
474
- // stranded on <body>. Snapshot before the teardown (focus still on
475
- // the closing panel), restore after.
476
- host.onWillMutateLayout((e) => {
477
- if (e.kind === 'remove' && this._nav) {
478
- this._focusWasInside = this._isFocusInside();
479
- }
480
- }), host.onDidMutateLayout((e) => {
481
- if (e.kind === 'remove' &&
482
- this._nav &&
483
- this._focusWasInside &&
484
- !this._isFocusInside()) {
485
- this._restoreFocus();
486
- }
487
- }));
488
- }
489
- get _moveActive() {
490
- return this.host.rootElement.hasAttribute(KEYBOARD_MOVE_ATTRIBUTE);
491
- }
492
- _isFocusInside() {
493
- const active = this.host.rootElement.ownerDocument.activeElement;
494
- return active instanceof Node && this.host.rootElement.contains(active);
495
- }
496
- _onFloatingEscape(e) {
497
- if (!this._nav ||
498
- this._moveActive ||
499
- e.defaultPrevented ||
500
- e.key !== 'Escape') {
501
- return;
502
- }
503
- const target = e.target;
504
- if (!(target instanceof Element)) {
505
- return;
506
- }
507
- // Only when focus is inside one of *this* dock's floating groups.
508
- const float = target.closest('[role="dialog"]');
509
- if (!float || !this.host.rootElement.contains(float)) {
510
- return;
511
- }
512
- e.preventDefault();
513
- e.stopPropagation();
514
- this._returnFocusFromFloat();
515
- }
516
- /**
517
- * Keep Tab inside the floating group that holds focus: at the last tabbable
518
- * Tab wraps to the first, at the first Shift+Tab wraps to the last. Returns
519
- * true if it handled the event. No-op outside a float.
520
- */
521
- _trapFloatTab(e) {
522
- const target = e.target;
523
- if (!(target instanceof Element)) {
524
- return false;
525
- }
526
- const float = target.closest('[role="dialog"]');
527
- if (!float || !this.host.rootElement.contains(float)) {
528
- return false;
529
- }
530
- // Always manage Tab inside a float, never just at the boundary: focus
531
- // often sits on non-tabbable plumbing (the content container, which is
532
- // tabindex="-1"), and the browser's default Tab from there escapes to
533
- // the grid behind. Drive the cursor through the float's tabbables
534
- // ourselves and swallow the default so it can't leak out.
535
- e.preventDefault();
536
- const tabbables = this._tabbables(float);
537
- if (tabbables.length === 0) {
538
- return true;
539
- }
540
- const active = float.ownerDocument.activeElement;
541
- const index = active instanceof HTMLElement ? tabbables.indexOf(active) : -1;
542
- const n = tabbables.length;
543
- const next = index === -1
544
- ? e.shiftKey
545
- ? n - 1
546
- : 0
547
- : (index + (e.shiftKey ? -1 : 1) + n) % n;
548
- tabbables[next].focus();
549
- return true;
550
- }
551
- _tabbables(root) {
552
- const nodes = root.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), ' +
553
- 'select:not([disabled]), textarea:not([disabled]), [tabindex]');
554
- // tabIndex >= 0 keeps naturally-focusable controls and roving anchors
555
- // (the active tab) while dropping tabindex="-1" plumbing (content
556
- // containers, inactive tabs).
557
- return Array.from(nodes).filter((el) => el.tabIndex >= 0);
558
- }
559
- _returnFocusFromFloat() {
560
- var _a;
561
- const prev = this._lastNonFloatFocus;
562
- if (prev &&
563
- prev.isConnected &&
564
- this.host.rootElement.contains(prev) &&
565
- !prev.closest('[role="dialog"]')) {
566
- prev.focus();
567
- return;
568
- }
569
- // Invoking control is gone — fall back to a grid group's content.
570
- (_a = this.host.groups
571
- .find((g) => g.api.location.type === 'grid')) === null || _a === void 0 ? void 0 : _a.model.focusContent();
572
- }
573
- get _nav() {
574
- return readKeyboardNavigation(this.host.options);
575
- }
576
- get _keymap() {
577
- var _a;
578
- return Object.assign(Object.assign({}, DEFAULT_KEYMAP$1), (_a = this._nav) === null || _a === void 0 ? void 0 : _a.keymap);
579
- }
580
- _onKeyDown(e) {
581
- if (!this._nav) {
582
- return;
583
- }
584
- // Stand down while the docking module is driving a keyboard move.
585
- if (this._moveActive) {
586
- return;
587
- }
588
- // Only act on events originating inside *this* dockview.
589
- if (!(e.target instanceof Node) ||
590
- !this.host.rootElement.contains(e.target)) {
591
- return;
592
- }
593
- // Trap Tab within a floating group so focus doesn't leak to the grid
594
- // behind it (the float is non-modal, but its Tab order should be).
595
- if (e.key === 'Tab' && this._trapFloatTab(e)) {
596
- return;
597
- }
598
- const keymap = this._keymap;
599
- if (matchesBinding(e, keymap.nextTab)) {
600
- this._consume(e);
601
- this._switchTab(false);
602
- }
603
- else if (matchesBinding(e, keymap.prevTab)) {
604
- this._consume(e);
605
- this._switchTab(true);
606
- }
607
- else if (matchesBinding(e, keymap.focusNextGroup)) {
608
- this._consume(e);
609
- this._cycleGroup(false);
610
- }
611
- else if (matchesBinding(e, keymap.focusPrevGroup)) {
612
- this._consume(e);
613
- this._cycleGroup(true);
614
- }
615
- else if (matchesBinding(e, keymap.focusTabs)) {
616
- this._consume(e);
617
- this._focusTabs();
618
- }
619
- }
620
- // --- navigation (uses the public group API + the adjacentGroup primitive) ---
621
- _focusTabs() {
622
- var _a;
623
- // Jump from panel content to the active group's tab strip; the
624
- // tablist's own roving-tabindex handler takes over from there.
625
- (_a = this.host.activeGroup) === null || _a === void 0 ? void 0 : _a.model.focusActiveTab();
626
- }
627
- _switchTab(reverse) {
628
- const group = this.host.activeGroup;
629
- if (!group) {
630
- return;
631
- }
632
- if (reverse) {
633
- group.model.moveToPrevious();
634
- }
635
- else {
636
- group.model.moveToNext();
637
- }
638
- // Keep DOM focus inside the dock: switching hides the previously
639
- // focused content, which would otherwise drop focus to <body> and
640
- // leave the keymap unable to see the next key.
641
- group.model.focusContent();
642
- }
643
- _cycleGroup(reverse) {
644
- const current = this.host.activeGroup;
645
- const target = current
646
- ? this.host.adjacentGroup(current, reverse)
647
- : this.host.groups[0];
648
- this._focusGroup(target);
649
- }
650
- _focusGroup(target) {
651
- if (!target) {
652
- return;
653
- }
654
- target.api.setActive();
655
- target.model.focusContent();
656
- }
657
- /** Return DOM focus to the active group's content, keeping it in the dock. */
658
- _restoreFocus() {
659
- var _a;
660
- (_a = this.host.activeGroup) === null || _a === void 0 ? void 0 : _a.model.focusContent();
661
- }
662
- _consume(e) {
663
- e.preventDefault();
664
- e.stopPropagation();
665
- }
666
- }
667
- const AccessibilityModule = defineModule({
668
- name: 'Accessibility',
669
- serviceKey: 'accessibilityService',
670
- create: (host) => new AccessibilityService(host),
671
- });
672
-
673
- const EDGE_FROM_KEY = {
674
- ArrowLeft: 'left',
675
- ArrowRight: 'right',
676
- ArrowUp: 'top',
677
- ArrowDown: 'bottom',
678
- };
679
- const DEFAULT_KEYMAP = {
680
- focusGroupLeft: 'ctrl+shift+arrowleft',
681
- focusGroupRight: 'ctrl+shift+arrowright',
682
- focusGroupUp: 'ctrl+shift+arrowup',
683
- focusGroupDown: 'ctrl+shift+arrowdown',
684
- dock: 'ctrl+m',
685
- };
686
- /**
687
- * Advanced keyboard control — drive the layout itself without a mouse. Opt-in
688
- * via `keyboardNavigation` (shared with the default navigation module).
689
- *
690
- * - **Spatial group focus** (`Ctrl+Shift+Arrows`) — move focus to the visually
691
- * adjacent group via the `adjacentGroupInDirection` geometry primitive.
692
- * - **Keyboard docking** (`Ctrl+M`) — arms a two-phase move of the active panel
693
- * with a live drop preview + screen-reader narration:
694
- * 1. PICK TARGET — arrows cycle the groups (incl. the panel's own, so a tab
695
- * can be split out); `Enter` selects one.
696
- * 2. PICK EDGE — arrows choose a split edge (left/right/top/bottom) or the
697
- * centre (tab-into); `Enter` commits, `Escape` steps back.
698
- * `Escape` from the target phase cancels.
699
- *
700
- * While a move is in progress it marks the root with
701
- * {@link KEYBOARD_MOVE_ATTRIBUTE} so the default navigation listener stands
702
- * down and the move keys aren't double-handled.
703
- */
704
- class KeyboardDockingService extends DockviewCompositeDisposable {
705
- constructor(host) {
706
- super();
707
- this.host = host;
708
- this._move = null;
709
- // Capture phase, on the document — matches the navigation listener so
710
- // edge groups (outside the gridview) are covered.
711
- const doc = host.rootElement.ownerDocument;
712
- const onKeyDown = (e) => this._onKeyDown(e);
713
- doc.addEventListener('keydown', onKeyDown, true);
714
- this.addDisposables({ dispose: () => this._exit() }, {
715
- dispose: () => doc.removeEventListener('keydown', onKeyDown, true),
716
- });
717
- }
718
- get _enabled() {
719
- return !!readKeyboardNavigation(this.host.options);
720
- }
721
- get _keymap() {
722
- var _a, _b, _c, _d, _e, _f, _g;
723
- // The public `keyboardNavigation.keymap` carries the default-navigation
724
- // bindings; this module's bindings are read from the same object when
725
- // present (so a consumer can rebind them too).
726
- const overrides = ((_b = (_a = readKeyboardNavigation(this.host.options)) === null || _a === void 0 ? void 0 : _a.keymap) !== null && _b !== void 0 ? _b : {});
727
- return {
728
- focusGroupLeft: (_c = overrides.focusGroupLeft) !== null && _c !== void 0 ? _c : DEFAULT_KEYMAP.focusGroupLeft,
729
- focusGroupRight: (_d = overrides.focusGroupRight) !== null && _d !== void 0 ? _d : DEFAULT_KEYMAP.focusGroupRight,
730
- focusGroupUp: (_e = overrides.focusGroupUp) !== null && _e !== void 0 ? _e : DEFAULT_KEYMAP.focusGroupUp,
731
- focusGroupDown: (_f = overrides.focusGroupDown) !== null && _f !== void 0 ? _f : DEFAULT_KEYMAP.focusGroupDown,
732
- dock: (_g = overrides.dock) !== null && _g !== void 0 ? _g : DEFAULT_KEYMAP.dock,
733
- };
734
- }
735
- get _messages() {
736
- return resolveMessages(this.host.options.messages);
737
- }
738
- _onKeyDown(e) {
739
- if (!this._enabled) {
740
- return;
741
- }
742
- if (this._move) {
743
- this._onMoveKey(e);
744
- return;
745
- }
746
- // Only act on events originating inside *this* dockview.
747
- if (!(e.target instanceof Node) ||
748
- !this.host.rootElement.contains(e.target)) {
749
- return;
750
- }
751
- const keymap = this._keymap;
752
- if (matchesBinding(e, keymap.dock)) {
753
- this._enterMoveMode(e);
754
- }
755
- else if (matchesBinding(e, keymap.focusGroupLeft)) {
756
- this._consume(e);
757
- this._focusGroupInDirection('left');
758
- }
759
- else if (matchesBinding(e, keymap.focusGroupRight)) {
760
- this._consume(e);
761
- this._focusGroupInDirection('right');
762
- }
763
- else if (matchesBinding(e, keymap.focusGroupUp)) {
764
- this._consume(e);
765
- this._focusGroupInDirection('up');
766
- }
767
- else if (matchesBinding(e, keymap.focusGroupDown)) {
768
- this._consume(e);
769
- this._focusGroupInDirection('down');
770
- }
771
- }
772
- // --- spatial focus ---
773
- _focusGroupInDirection(direction) {
774
- const current = this.host.activeGroup;
775
- if (!current) {
776
- return;
777
- }
778
- // Geometry lives on the host as the shared `adjacentGroupInDirection`
779
- // primitive (also public on the api), so mouse and keyboard navigation
780
- // agree on what "the group to the left" is.
781
- this._focusGroup(this.host.adjacentGroupInDirection(current, direction));
782
- }
783
- _focusGroup(target) {
784
- if (!target) {
785
- return;
786
- }
787
- target.api.setActive();
788
- target.model.focusContent();
789
- }
790
- _restoreFocus() {
791
- var _a;
792
- (_a = this.host.activeGroup) === null || _a === void 0 ? void 0 : _a.model.focusContent();
793
- }
794
- // --- keyboard docking (move mode) ---
795
- _enterMoveMode(e) {
796
- const source = this.host.activePanel;
797
- const groups = this.host.groups;
798
- if (!source || groups.length === 0) {
799
- return;
800
- }
801
- e.preventDefault();
802
- e.stopPropagation();
803
- // Start on the panel's own group so a single group of tabs can still
804
- // split a tab out via the edge phase.
805
- const groupIndex = Math.max(0, groups.indexOf(source.group));
806
- this._move = {
807
- source,
808
- groups,
809
- groupIndex,
810
- phase: 'target',
811
- position: 'center',
812
- };
813
- // Signal the navigation module to stand down while the move runs.
814
- this.host.rootElement.setAttribute(KEYBOARD_MOVE_ATTRIBUTE, '');
815
- this._render();
816
- }
817
- _onMoveKey(e) {
818
- const move = this._move;
819
- if (e.key === 'Escape') {
820
- this._consume(e);
821
- if (move.phase === 'edge') {
822
- move.phase = 'target';
823
- move.position = 'center';
824
- this._render();
825
- }
826
- else {
827
- this._exit();
828
- this.host.announce(this._messages.moveCancelled());
829
- this._restoreFocus();
830
- }
831
- return;
832
- }
833
- if (e.key === 'Enter') {
834
- this._consume(e);
835
- if (move.phase === 'target') {
836
- move.phase = 'edge';
837
- move.position = 'center';
838
- this._render();
839
- }
840
- else {
841
- this._commit();
842
- }
843
- return;
844
- }
845
- if (move.phase === 'target') {
846
- const n = move.groups.length;
847
- if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
848
- this._consume(e);
849
- move.groupIndex = (move.groupIndex + 1) % n;
850
- this._render();
851
- }
852
- else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
853
- this._consume(e);
854
- move.groupIndex = (move.groupIndex - 1 + n) % n;
855
- this._render();
856
- }
857
- return;
858
- }
859
- // edge phase
860
- const edge = EDGE_FROM_KEY[e.key];
861
- if (edge) {
862
- this._consume(e);
863
- move.position = edge;
864
- this._render();
865
- }
866
- else if (e.key === ' ' || e.key === 'c' || e.key === 'C') {
867
- this._consume(e);
868
- move.position = 'center';
869
- this._render();
870
- }
871
- }
872
- _render() {
873
- var _a, _b;
874
- const move = this._move;
875
- const group = move.groups[move.groupIndex];
876
- this._clearPreview();
877
- this._preview = this.host.showDropPreview(group, move.position);
878
- const name = (_b = (_a = group.activePanel) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : group.id;
879
- const m = this._messages;
880
- if (move.phase === 'target') {
881
- this.host.announce(m.movePickTarget(this._label(move.source), name, move.groupIndex + 1, move.groups.length));
882
- }
883
- else {
884
- this.host.announce(m.movePickEdge(move.position, name));
885
- }
886
- }
887
- _commit() {
888
- var _a, _b;
889
- const move = this._move;
890
- const group = move.groups[move.groupIndex];
891
- const position = move.position;
892
- const source = move.source;
893
- const name = (_b = (_a = group.activePanel) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : group.id;
894
- const m = this._messages;
895
- this._exit();
896
- try {
897
- this.host.dockPanel(source, group, position);
898
- this.host.announce(m.moveCommitted(this._label(source), name, position));
899
- }
900
- catch (_c) {
901
- this.host.announce(m.moveNotAllowed());
902
- }
903
- // The move re-renders the grid; pull focus back into the dock so the
904
- // keymap keeps working without a click.
905
- this._restoreFocus();
906
- }
907
- _exit() {
908
- this._clearPreview();
909
- this._move = null;
910
- this.host.rootElement.removeAttribute(KEYBOARD_MOVE_ATTRIBUTE);
911
- }
912
- _clearPreview() {
913
- var _a;
914
- (_a = this._preview) === null || _a === void 0 ? void 0 : _a.dispose();
915
- this._preview = undefined;
916
- }
917
- _consume(e) {
918
- e.preventDefault();
919
- e.stopPropagation();
920
- }
921
- _label(panel) {
922
- var _a;
923
- return (_a = panel.title) !== null && _a !== void 0 ? _a : panel.id;
924
- }
925
- }
926
- defineModule({
927
- name: 'KeyboardDocking',
928
- serviceKey: 'keyboardDockingService',
929
- create: (host) => new KeyboardDockingService(host),
930
- dependsOn: [AdvancedDnDModule, LiveRegionModule],
931
- });
932
-
933
- /**
934
- * The set of modules provided by this package. `dockview` registers these via
935
- * `registerModules(Modules)` so they are available to every component.
936
- */
937
- const Modules = [
938
- TabGroupChipsModule,
939
- ContextMenuModule,
940
- AdvancedDnDModule,
941
- AccessibilityModule,
942
- ];
943
-
944
- /**
945
- * `dockview` is the batteries-included entry point: it re-exports the core API
946
- * and registers the separable feature modules so every component gets the full
947
- * feature set out of the box. Consumers who want only the core can depend on
948
- * `dockview-core` directly.
949
- */
950
- registerModules(Modules);
951
- // Mark the public package as loaded so `dockview-core` doesn't warn about
952
- // direct usage. Purely drives that developer warning — no functional effect.
953
- markDockviewPackageLoaded();
20
+ //#endregion