@jbrowse/app-core 5.0.0-beta.11 → 5.0.0-beta.13

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 (52) hide show
  1. package/esm/JBrowseConfig/RootConfiguration.d.ts +1 -8
  2. package/esm/JBrowseConfig/RootConfiguration.js +2 -6
  3. package/esm/JBrowseConfig/index.d.ts +1 -8
  4. package/esm/JBrowseModel/index.d.ts +1 -8
  5. package/esm/JbApi/jbApi.d.ts +2 -2
  6. package/esm/JbApi/jbApi.js +12 -10
  7. package/esm/SessionSpec/loadSessionSpec.js +2 -12
  8. package/esm/WorkspaceLayout/LayoutRenderer.d.ts +0 -10
  9. package/esm/WorkspaceLayout/LayoutRenderer.js +34 -101
  10. package/esm/WorkspaceLayout/PanelView.js +19 -45
  11. package/esm/WorkspaceLayout/TabStrip.d.ts +2 -2
  12. package/esm/WorkspaceLayout/TabStrip.js +36 -104
  13. package/esm/WorkspaceLayout/WorkspaceContainer.d.ts +0 -9
  14. package/esm/WorkspaceLayout/WorkspaceContainer.js +9 -34
  15. package/esm/WorkspaceLayout/WorkspacePanelActions.d.ts +1 -16
  16. package/esm/WorkspaceLayout/WorkspacePanelActions.js +45 -50
  17. package/esm/WorkspaceLayout/WorkspaceTab.d.ts +1 -16
  18. package/esm/WorkspaceLayout/WorkspaceTab.js +11 -47
  19. package/esm/WorkspaceLayout/dropZone.d.ts +7 -37
  20. package/esm/WorkspaceLayout/dropZone.js +7 -44
  21. package/esm/WorkspaceLayout/model.d.ts +42 -112
  22. package/esm/WorkspaceLayout/model.js +139 -268
  23. package/esm/WorkspaceLayout/panelChrome.d.ts +4 -7
  24. package/esm/WorkspaceLayout/panelChrome.js +0 -2
  25. package/esm/WorkspaceLayout/spec.d.ts +10 -51
  26. package/esm/WorkspaceLayout/spec.js +12 -80
  27. package/esm/WorkspaceLayout/splitter.d.ts +3 -19
  28. package/esm/WorkspaceLayout/splitter.js +5 -21
  29. package/esm/WorkspaceLayout/tabName.d.ts +8 -0
  30. package/esm/WorkspaceLayout/tabName.js +14 -0
  31. package/esm/WorkspaceLayout/tree.d.ts +19 -76
  32. package/esm/WorkspaceLayout/tree.js +29 -122
  33. package/esm/WorkspaceLayout/useLayoutDrag.d.ts +4 -22
  34. package/esm/WorkspaceLayout/useLayoutDrag.js +46 -174
  35. package/esm/WorkspaceLayout/usePointerGesture.d.ts +24 -0
  36. package/esm/WorkspaceLayout/usePointerGesture.js +83 -0
  37. package/esm/WorkspaceLayout/workspaceTheme.d.ts +27 -0
  38. package/esm/WorkspaceLayout/workspaceTheme.js +37 -0
  39. package/esm/ui/App/App.js +3 -0
  40. package/esm/ui/App/JBrowseTabMenu.js +1 -1
  41. package/esm/ui/App/ThemeModeButton.js +5 -4
  42. package/esm/ui/App/ViewMenu.js +47 -29
  43. package/esm/ui/App/ViewsContainer.js +3 -4
  44. package/esm/ui/App/lazyParts.d.ts +0 -5
  45. package/esm/ui/App/lazyParts.js +0 -1
  46. package/esm/ui/App/preloadAppShell.js +3 -6
  47. package/esm/ui/App/types.d.ts +3 -2
  48. package/package.json +4 -4
  49. package/esm/WorkspaceLayout/dockviewTheme.d.ts +0 -69
  50. package/esm/WorkspaceLayout/dockviewTheme.js +0 -82
  51. package/esm/ui/App/ClassicViewsContainer.d.ts +0 -6
  52. package/esm/ui/App/ClassicViewsContainer.js +0 -22
@@ -1,20 +1,13 @@
1
1
  import { createElementId } from '@jbrowse/core/util/types/mst';
2
2
  import { cast, getSnapshot, types } from '@jbrowse/mobx-state-tree';
3
- import { resolveLayoutSpec, specForPendingMove, tileLayoutSpec, treeFromSpec, viewIdsInSpec, } from './spec.js';
3
+ import { resolveLayoutSpec, tileLayoutSpec, treeFromSpec, viewIdsInSpec, } from './spec.js';
4
4
  import { activeTabIn, addTab, addViewToTab, findTab, homeViews, moveTabToPanel, normalize, panelContainingView, panels, pruneEmptyPanel, pruneEmptyTabIn, removePanel, removeTab, removeView, renameTab, setActiveTab, setSizes, splitPanel, tabContainingView, tabs, } from './tree.js';
5
5
  function sessionViewIds(self) {
6
6
  return self.views?.map(v => v.id);
7
7
  }
8
8
  /**
9
- * A caller-supplied view list narrowed to the views the session actually has.
10
- *
11
- * The list is the caller's snapshot, and `applyLayoutSpec` refuses an id no
12
- * view has — so a view added after the list was built, or removed between
13
- * building it and the call, would throw out of a sugar action no plugin wraps.
14
- * The arrangement a stale name asks for is still the one it means for every
15
- * view that IS there, so the name is dropped rather than the action. A repeat
16
- * is dropped for the same reason: it would seat one view in two cells, which
17
- * the resolver also refuses.
9
+ * A caller's view list narrowed to the session's views, deduplicated. The list
10
+ * may be stale, and `applyLayoutSpec` throws on an unknown or repeated id.
18
11
  */
19
12
  function liveViewIds(self, allViewIds) {
20
13
  const live = sessionViewIds(self);
@@ -25,22 +18,12 @@ function liveViewIds(self, allViewIds) {
25
18
  /**
26
19
  * #stateModel WorkspaceLayoutMixin
27
20
  *
28
- * The whole workspace, in one MST tree. There is no second owner, so there is
29
- * nothing to reconcile, no event to echo, and no window during which the two
30
- * disagree — which is the entire content of `useDockviewController`.
31
- *
32
- * Four levels, matching what the workspace actually has and what a generic
33
- * window manager cannot quite express:
21
+ * The whole workspace as one MST tree:
34
22
  *
35
23
  * branch (a split) > panel (a grid cell) > tab > views (stacked)
36
24
  *
37
- * dockview models the first three as branch/group/panel and stops there; the
38
- * vertical stack of views inside a tab is ours, which is why
39
- * `panelViewAssignments` had to exist alongside dockview's own serialized grid.
40
- * Here it is one tree, and a tab simply *contains* its views.
41
- *
42
25
  * Every action is `tree -> tree` through the pure functions in `tree.ts`, so
43
- * undo is `applySnapshot` on this node and nothing else has to be told.
26
+ * undo is `applySnapshot` on this node.
44
27
  */
45
28
  const LayoutTab = types.model('LayoutTab', {
46
29
  id: types.identifier,
@@ -60,19 +43,13 @@ const LayoutBranch = types.model('LayoutBranch', {
60
43
  direction: types.enumeration('LayoutDirection', ['row', 'column']),
61
44
  children: types.array(types.late(() => LayoutNode)),
62
45
  });
63
- // `children` is a union of both node kinds, resolved late because a branch
64
- // contains branches. The dispatcher keys off `direction`, which only a branch
65
- // has, so an ambiguous snapshot is impossible rather than merely unlikely.
46
+ // only a branch has `direction`, so the dispatcher is never ambiguous
66
47
  const LayoutNode = types.union({
67
48
  dispatcher: (snapshot) => snapshot.direction ? LayoutBranch : LayoutPanel,
68
49
  }, LayoutBranch, LayoutPanel);
69
50
  /**
70
- * Panel and tab ids.
71
- *
72
- * Random, NOT a counter. These are `types.identifier`, so they must be unique
73
- * within the tree — and a counter is reset by every page load while the restored
74
- * snapshot still holds `panel-1`, `tab-1`, .... The first tab a returning user
75
- * opened would mint an id the tree already had.
51
+ * Random, not a counter: a counter restarts on page load while a restored
52
+ * snapshot still holds its old ids, and these are `types.identifier`s.
76
53
  */
77
54
  function nextId(kind) {
78
55
  return `${kind}-${createElementId()}`;
@@ -92,30 +69,17 @@ export function WorkspaceLayoutMixin() {
92
69
  layout: types.optional(LayoutNode, emptyPanel),
93
70
  activePanelId: types.maybe(types.string),
94
71
  /**
95
- * Show only this cell, at the size of the whole workspace.
96
- *
97
- * Deliberately HERE and not a `maximized` flag on `PanelNode`. On the
98
- * node it would be inside `tree.ts`, the half that carries the risk and
99
- * is proven by a randomised operation sequence asserting canonical form
100
- * after every step — and every operation would then have to say what it
101
- * does to the flag: a split of a maximized panel, a drag of its last tab
102
- * out, a normalize that collapses it into its parent. Beside
103
- * `activePanelId` it is the same class of thing as `activePanelId`,
104
- * including its failure mode, which `livePanelIds` already repairs.
72
+ * Show only this cell, at the size of the whole workspace. Kept here
73
+ * rather than as a flag on `PanelNode` so no `tree.ts` operation has to
74
+ * say what it does to it.
105
75
  */
106
76
  maximizedPanelId: types.maybe(types.string),
107
77
  })
108
78
  .views(self => ({
109
79
  /**
110
- * The plain tree the pure functions take.
111
- *
112
- * `getSnapshot` is a `keepAlive` computed, so this is cached and
113
- * referentially stable — which also lets MST's reconcile short-circuit on
114
- * identity when `apply` writes an untouched subtree back.
115
- *
116
- * Uncast on purpose: the models below and the interfaces in `tree.ts` are
117
- * two spellings of one shape, and this assignment is the only thing that
118
- * checks they agree.
80
+ * Referentially stable, since `getSnapshot` is cached. Uncast on
81
+ * purpose: this assignment is what checks the models above agree with
82
+ * the interfaces in `tree.ts`.
119
83
  */
120
84
  get tree() {
121
85
  return getSnapshot(self.layout);
@@ -151,13 +115,9 @@ export function WorkspaceLayoutMixin() {
151
115
  return panel ? activeTabIn(panel) : undefined;
152
116
  },
153
117
  /**
154
- * What to render: the maximized cell alone, or the whole tree.
155
- *
156
- * Sized to 1 rather than handed over as it sits. A pane's `size` is its
157
- * share of its siblings, and CSS distributes free space by grow factor
158
- * only up to a total of 1 — so a cell that was a third of a row, alone
159
- * in the workspace with `flexGrow: 0.33`, draws a third of the window
160
- * and leaves the rest blank.
118
+ * The maximized cell alone, or the whole tree. The cell is resized to 1
119
+ * because CSS hands out free space by grow factor only up to a total of
120
+ * 1, so a third-of-a-row cell would draw a third of the window.
161
121
  */
162
122
  get visibleTree() {
163
123
  const maximized = panels(self.tree).find(p => p.id === self.maximizedPanelId);
@@ -166,20 +126,9 @@ export function WorkspaceLayoutMixin() {
166
126
  }))
167
127
  .actions(self => {
168
128
  /**
169
- * Both panel ids this model holds outside the tree must name a cell
170
- * that exists, whatever just stopped existing. A dangling
171
- * `activePanelId` puts homed views in a cell nobody draws; a dangling
172
- * `maximizedPanelId` draws nothing at all.
173
- *
174
- * Stated as the invariant rather than as "the panel I just closed",
175
- * because a removal collapses branches on the way out and the cell that
176
- * disappears is not always the one that was named.
177
- *
178
- * They fall back differently, and the difference is the whole reason
179
- * this is two lines rather than a loop. A workspace always shows some
180
- * cell, so `activePanelId` takes the first one; maximize is a mode the
181
- * user is IN, so losing its cell leaves the mode rather than picking an
182
- * arbitrary cell to hold the user in it.
129
+ * Both panel ids held outside the tree must name a live cell. A lost
130
+ * active cell falls back to the first; a lost maximized cell leaves the
131
+ * mode.
183
132
  */
184
133
  function livePanelIds() {
185
134
  if (self.activePanelId !== undefined &&
@@ -191,27 +140,19 @@ export function WorkspaceLayoutMixin() {
191
140
  self.maximizedPanelId = undefined;
192
141
  }
193
142
  }
194
- /**
195
- * Every write to the tree, and therefore the one place the invariant
196
- * above is repaired.
197
- *
198
- * It used to be a `keepActivePanel()` the two closing actions called,
199
- * which was right while a closing action was the only way to retire a
200
- * cell. `maximizedPanelId` is not reached that way: BOTH drop gestures
201
- * prune their emptied source panel, and `applyLayoutSpec` replaces every
202
- * id in the tree at once. That is five call sites for one rule, which is
203
- * the shape that ends with one of them missing.
204
- */
143
+ // a maximized cell is the active one, so activating any other leaves
144
+ // the mode rather than putting new views where nobody can see them
145
+ function activate(panelId) {
146
+ self.activePanelId = panelId;
147
+ if (self.maximizedPanelId !== panelId) {
148
+ self.maximizedPanelId = undefined;
149
+ }
150
+ }
151
+ /** Every write to the tree, so the one place `livePanelIds` runs. */
205
152
  function apply(next) {
206
153
  const before = panels(self.tree).length;
207
154
  self.layout = cast(normalize(next));
208
- // A cell appearing where it cannot be seen is the one thing maximize
209
- // must not do, so gaining one leaves the mode. Stated as the count
210
- // rather than at the three actions that split (`splitPanel`,
211
- // `dropTabInNewSplit`, `moveViewToSplitRight`) for the reason above —
212
- // and a fourth, `applyLayoutSpec`, arrives at it from the other side:
213
- // it replaces every id, so `livePanelIds` was going to clear the mode
214
- // regardless. Losing a cell needs nothing here; that IS `livePanelIds`.
155
+ // a new cell would appear where maximize hides it
215
156
  if (panels(self.tree).length > before) {
216
157
  self.maximizedPanelId = undefined;
217
158
  }
@@ -220,16 +161,6 @@ export function WorkspaceLayoutMixin() {
220
161
  function home(tree, viewIds) {
221
162
  return homeViews(tree, viewIds, self.activePanelId, () => nextId('tab'));
222
163
  }
223
- /**
224
- * The shape ViewMenu's two "give this view a home of its own" moves share.
225
- *
226
- * Homing first is what removed the old fork here — the live dockview api
227
- * when the workspace was up, an `init` when it was not — because from the
228
- * classic stack nothing has been assigned to a tab yet.
229
- *
230
- * Returns where the view came from, or `undefined` if it is not in the
231
- * session, in which case nothing is applied.
232
- */
233
164
  function everyViewId(action, allViewIds) {
234
165
  const ids = allViewIds ?? sessionViewIds(self);
235
166
  if (!ids) {
@@ -237,6 +168,11 @@ export function WorkspaceLayoutMixin() {
237
168
  }
238
169
  return ids;
239
170
  }
171
+ /**
172
+ * Homes every view first, since from the classic stack none has a tab
173
+ * yet. Returns where the view came from, or `undefined` if it is not in
174
+ * the session, in which case nothing is applied.
175
+ */
240
176
  function rehomeView(viewId, allViewIds, place) {
241
177
  const tree = home(self.tree, allViewIds);
242
178
  const from = tabContainingView(tree, viewId);
@@ -244,45 +180,40 @@ export function WorkspaceLayoutMixin() {
244
180
  return undefined;
245
181
  }
246
182
  const placed = place(removeView(tree, viewId), from);
247
- apply(pruneEmptyTabIn(placed, from.panel.id, from.tab.id));
183
+ const pruned = pruneEmptyTabIn(placed, from.panel.id, from.tab.id);
184
+ const source = panels(pruned).find(p => p.id === from.panel.id);
185
+ const emptiedCell = source?.tabs.length === 1 &&
186
+ source.tabs[0].id === from.tab.id &&
187
+ source.tabs[0].viewIds.length === 0;
188
+ apply(emptiedCell
189
+ ? pruneEmptyPanel(removeTab(pruned, from.tab.id), from.panel.id)
190
+ : pruned);
248
191
  return from;
249
192
  }
250
193
  /**
251
- * The panel a dropped tab is leaving, or `undefined` if the drop cannot
252
- * happen — which BOTH drop gestures have to establish before they touch
253
- * the tree, and for two different reasons. A missing tab leaves an
254
- * edge-drop's new cell behind empty; a missing target splits nothing while
255
- * the gesture goes on to point `activePanelId` at a cell nobody draws, and
256
- * makes `moveTabToPanel`'s remove-then-insert a deletion.
257
- *
258
- * One place, so the next drop gesture inherits the rule rather than
259
- * restating it — the two of them restating it is how one came to be
260
- * missing half of it.
194
+ * The panel a dropped tab is leaving, or `undefined` if the tab or the
195
+ * target is missing. Every drop gesture checks this before touching the
196
+ * tree.
261
197
  */
262
198
  function dropSource(tabId, targetPanelId) {
263
199
  const source = findTab(self.tree, tabId)?.panel;
264
200
  return source && self.hasPanel(targetPanelId) ? source : undefined;
265
201
  }
266
- // `apply` is deliberately not returned: it takes a whole tree, so as an
267
- // action it is a public "set the layout to this" on the session.
202
+ // `apply` stays private: as an action it would be a public "set layout"
268
203
  return {
269
204
  setActivePanelId(panelId) {
270
- self.activePanelId = panelId;
205
+ if (panelId === undefined) {
206
+ self.activePanelId = undefined;
207
+ }
208
+ else {
209
+ activate(panelId);
210
+ }
271
211
  },
272
212
  /**
273
- * Show one cell at the size of the workspace, or go back.
274
- *
275
- * A toggle rather than a pair, because the gesture is a toggle: the
276
- * strip's double-click and the cell menu's one item both mean "this
277
- * cell, or not any more". Maximizing a DIFFERENT cell while one is
278
- * already maximized moves the mode rather than restoring, which is
279
- * what the menu item on another cell's strip is asking for.
280
- *
281
- * Mounts no views that were not mounted — it is the same cell showing
282
- * the same tab — and unmounts every other cell's, so the WebGL2
283
- * context ceiling (`agent-docs/reference/GPU_PORTABILITY.md`) can
284
- * only go down. That is the reason it is this and not a `display:
285
- * none` over a still-mounted workspace.
213
+ * Show one cell at the size of the workspace, or go back; naming a
214
+ * different cell moves the mode. Unmounts every other cell's views
215
+ * rather than hiding them, to stay under the WebGL2 context ceiling
216
+ * (`agent-docs/reference/GPU_PORTABILITY.md`).
286
217
  */
287
218
  toggleMaximizedPanel(panelId) {
288
219
  if (!self.hasPanel(panelId)) {
@@ -299,7 +230,7 @@ export function WorkspaceLayoutMixin() {
299
230
  },
300
231
  setActiveTab(panelId, tabId) {
301
232
  apply(setActiveTab(self.tree, panelId, tabId));
302
- self.activePanelId = panelId;
233
+ activate(panelId);
303
234
  },
304
235
  renameTab(tabId, title) {
305
236
  apply(renameTab(self.tree, tabId, title));
@@ -308,13 +239,12 @@ export function WorkspaceLayoutMixin() {
308
239
  splitPanel(panelId, direction, before = false) {
309
240
  const panel = emptyPanel();
310
241
  apply(splitPanel(self.tree, panelId, direction, panel, before));
311
- // A split of a cell that is not there inserts nothing, so claiming
312
- // the id anyway would leave activePanelId naming a cell nobody draws
313
- // — and homing falls back on activePanelId.
242
+ // a split of a missing cell inserts nothing, and homing falls back
243
+ // on activePanelId
314
244
  if (!self.hasPanel(panel.id)) {
315
245
  return undefined;
316
246
  }
317
- self.activePanelId = panel.id;
247
+ activate(panel.id);
318
248
  return panel;
319
249
  },
320
250
  closePanel(panelId) {
@@ -327,22 +257,12 @@ export function WorkspaceLayoutMixin() {
327
257
  }
328
258
  const tab = { id: nextId('tab'), viewIds };
329
259
  apply(addTab(self.tree, panelId, tab));
330
- self.activePanelId = panelId;
260
+ activate(panelId);
331
261
  return tab;
332
262
  },
333
263
  /**
334
- * Close a tab, and the cell with it if that was its last.
335
- *
336
- * A cell whose tabs are all gone is the state `pruneEmptyPanel` was
337
- * written for — "dragging the last tab out of a split and leaving a
338
- * blank half is the one place an empty panel is clearly not what was
339
- * meant" — and closing that tab arrives at the identical half by a
340
- * different gesture. It rendered nothing at all, not even the launcher
341
- * an empty TAB shows, so the only way back out of it was the `+`.
342
- *
343
- * `pruneEmptyPanel` carries both guards already: a cell with tabs left
344
- * stays, and the last cell in the workspace stays whatever happens to
345
- * it, since there is nowhere for the tree to collapse to.
264
+ * Close a tab, and its cell too if that was the last tab and not the
265
+ * workspace's last cell: a tabless cell renders nothing at all.
346
266
  */
347
267
  closeTab(tabId) {
348
268
  const panelId = findTab(self.tree, tabId)?.panel.id;
@@ -354,42 +274,15 @@ export function WorkspaceLayoutMixin() {
354
274
  addViewToTab(tabId, viewId) {
355
275
  apply(addViewToTab(self.tree, tabId, viewId));
356
276
  },
357
- // NO `removeView` HERE. This mixin is composed into the session, where
358
- // `removeView(view)` is already the action that takes a view out of
359
- // `session.views` — part of AbstractSessionModel, and what every close
360
- // button and every host calls. A same-named action here does not extend
361
- // it, it *replaces* it (types.compose merges, last one wins), so the
362
- // session action stopped being reachable at all: closing a view pruned
363
- // the layout tree and left the view in the session forever, and
364
- // `session.removeView(view)` passed a model where this wanted an id, so
365
- // it matched nothing and even the pruning was a no-op.
366
- //
367
- // Nothing needs one either way: `home` below drops any tab entry whose
368
- // view is no longer in `session.views`, so removing the view is the
369
- // whole operation and the tree follows.
370
- /**
371
- * Drop a dragged tab into an existing panel, as a tab.
372
- *
373
- * One action, so the tree never exists in a state where the tab is in
374
- * both panels or neither. The imperative bridge needed an explicit
375
- * `runInAction` around the unassign+reassign pair for exactly this, and
376
- * a comment explaining that without it the reconcile autorun would
377
- * observe the gap and re-home the view.
378
- */
277
+ // NO `removeView` here: composed into the session it would replace
278
+ // `session.removeView`, and homing already drops a removed view
279
+ /** Drop a dragged tab into an existing panel, as a tab. */
379
280
  dropTabInPanel(tabId, targetPanelId, index) {
380
281
  const source = dropSource(tabId, targetPanelId);
381
282
  if (!source) {
382
283
  return;
383
284
  }
384
- // A drop on the BODY of the cell the tab is already in asks for
385
- // nothing. There is no gap under the pointer to state a position, and
386
- // the indicator washes the whole cell — which says "be a tab of this
387
- // cell", which it already is. Appending reordered the strip to say
388
- // something the gesture never said, and sent the tab to the end.
389
- // dockview declines a centre drop on the group a tab came from too.
390
- //
391
- // The rule is the gesture's, not `moveTabToPanel`'s: no index there
392
- // still means append, which is the only reading a total function has.
285
+ // a drop on the body of the tab's own cell asks for nothing
393
286
  if (source.id === targetPanelId && index === undefined) {
394
287
  return;
395
288
  }
@@ -398,7 +291,7 @@ export function WorkspaceLayoutMixin() {
398
291
  next = pruneEmptyPanel(next, source.id);
399
292
  }
400
293
  apply(next);
401
- self.activePanelId = targetPanelId;
294
+ activate(targetPanelId);
402
295
  },
403
296
  /** Drop a dragged tab on a panel edge: split, and land in the new half. */
404
297
  dropTabInNewSplit(tabId, targetPanelId, direction, before) {
@@ -413,33 +306,20 @@ export function WorkspaceLayoutMixin() {
413
306
  };
414
307
  let next = splitPanel(self.tree, targetPanelId, direction, panel, before);
415
308
  next = moveTabToPanel(next, tabId, panel.id);
416
- // Dragging a panel's only tab onto that same panel's edge prunes the
417
- // now-empty source, which collapses the split — the gesture undoes
418
- // itself rather than leaving a blank half, without needing a case.
309
+ // a panel's only tab dropped on its own edge collapses the split
419
310
  next = pruneEmptyPanel(next, source.id);
420
311
  apply(next);
421
- self.activePanelId = panel.id;
312
+ activate(panel.id);
422
313
  return panel.id;
423
314
  },
424
315
  setSizes(branchId, sizes) {
425
316
  apply(setSizes(self.tree, branchId, sizes));
426
317
  },
427
318
  /**
428
- * Arrange the workspace as a spec states.
429
- *
430
- * The spec is the same shape a session spec's `layout` takes: a leaf's
431
- * `views` names views by index into `session.views` or by id, so
432
- * `{ direction: 'horizontal', children: [{ views: [0] }, { views: [1] }] }`
433
- * means here what it means in a link. A leaf spelled any other way, an
434
- * index past the end or an id no view has throws rather than arranging
435
- * nothing — an untyped caller used to collapse the workspace into one
436
- * blank tab that way.
437
- *
438
- * There is no `init` property and no standing request: the spec is
439
- * converted and *becomes* the layout, here and now. `init` existed only
440
- * because dockview had to be told, could not be told before it mounted,
441
- * and had to be told again afterwards — three problems that all came
442
- * from the layout living somewhere this action could not reach.
319
+ * Arrange the workspace as a spec states, in the shape a session
320
+ * spec's `layout` takes: a leaf's `views` names views by index into
321
+ * `session.views` or by id. A malformed leaf, an index past the end or
322
+ * an unknown id throws.
443
323
  */
444
324
  applyLayoutSpec(spec) {
445
325
  const resolved = resolveLayoutSpec(spec, sessionViewIds(self));
@@ -449,10 +329,8 @@ export function WorkspaceLayoutMixin() {
449
329
  },
450
330
  /**
451
331
  * ViewMenu's "move to new tab": the view leaves its tab for a new one.
452
- *
453
332
  * `allViewIds` is EVERY view in the session, defaulting to the host's
454
- * own list — homing drops any view the list does not name, so the
455
- * `[viewId]` default this used to carry unhomed all the others.
333
+ * own list, since homing drops any view the list omits.
456
334
  */
457
335
  moveViewToNewTab(viewId, allViewIds) {
458
336
  const tab = { id: nextId('tab'), viewIds: [viewId] };
@@ -460,14 +338,14 @@ export function WorkspaceLayoutMixin() {
460
338
  if (!from) {
461
339
  return undefined;
462
340
  }
463
- self.activePanelId = from.panel.id;
341
+ activate(from.panel.id);
464
342
  return tab.id;
465
343
  },
466
344
  /**
467
- * ViewMenu's "move to split view": the view leaves for a new cell.
468
- * `allViewIds` is every view in the session — see `moveViewToNewTab`.
345
+ * ViewMenu's "move to split": the view leaves for a new cell to the
346
+ * right (`row`) or below (`column`) of its own.
469
347
  */
470
- moveViewToSplitRight(viewId, allViewIds) {
348
+ moveViewToSplit(viewId, direction, allViewIds) {
471
349
  const tabId = nextId('tab');
472
350
  const panel = {
473
351
  id: nextId('panel'),
@@ -475,111 +353,104 @@ export function WorkspaceLayoutMixin() {
475
353
  tabs: [{ id: tabId, viewIds: [viewId] }],
476
354
  activeTabId: tabId,
477
355
  };
478
- const from = rehomeView(viewId, everyViewId('moveViewToSplitRight', allViewIds), (tree, at) => splitPanel(tree, at.panel.id, 'row', panel));
356
+ const from = rehomeView(viewId, everyViewId('moveViewToSplit', allViewIds), (tree, at) => splitPanel(tree, at.panel.id, direction, panel));
479
357
  if (!from) {
480
358
  return undefined;
481
359
  }
482
- self.activePanelId = panel.id;
360
+ activate(panel.id);
483
361
  return panel.id;
484
362
  },
363
+ /**
364
+ * ViewMenu's "move to tab": the view joins an existing tab, which
365
+ * becomes the one shown.
366
+ */
367
+ moveViewToTab(viewId, tabId, allViewIds) {
368
+ const target = findTab(self.tree, tabId);
369
+ if (!target || target.tab.viewIds.includes(viewId)) {
370
+ return;
371
+ }
372
+ const from = rehomeView(viewId, everyViewId('moveViewToTab', allViewIds), tree => addViewToTab(tree, tabId, viewId));
373
+ const landed = findTab(self.tree, tabId);
374
+ if (from && landed) {
375
+ apply(setActiveTab(self.tree, landed.panel.id, tabId));
376
+ activate(landed.panel.id);
377
+ }
378
+ },
485
379
  homeUnassignedViews(viewIds) {
486
380
  apply(home(self.tree, viewIds));
487
381
  },
488
382
  };
489
383
  })
490
- /**
491
- * The two sugars, in their own block so they can reach the actions they are
492
- * sugar FOR through `self`.
493
- *
494
- * `this.applyLayoutSpec()` reaches sideways into the action literal the
495
- * block returned — the fork's `instantiateActions` does `fn.bind(actions)`
496
- * — so it is pinned to that block's implementation for good. A later block,
497
- * or a plugin's `extendStateModel`, replaces `self.applyLayoutSpec` and the
498
- * sideways hop goes on calling the one it replaced, with no error and no
499
- * type complaint. An extra layer costs a line.
500
- */
384
+ // a separate block so these reach the actions they wrap through `self`,
385
+ // where a later override still gets called
501
386
  .actions(self => ({
502
387
  /**
503
- * Move one view relative to the others. PUBLIC API: an external plugin
504
- * calls this behind a `'setPendingMove' in session` guard
505
- * (jbrowse-plugin-protein3d, putting a protein view beside its genome
506
- * view). It survived the last storage change by being kept as sugar, and
507
- * it survives this one the same way — a capability-detecting caller
508
- * cannot tell you it lost a capability.
509
- *
510
- * **`allViewIds` is therefore OPTIONAL, and has to stay that way.** The
511
- * plugin passes the move alone, because that was the whole signature when
512
- * its call site was written; requiring the second argument threw
513
- * `undefined.filter` out of a launch the plugin does not wrap, and the
514
- * figure was again the only thing that noticed. Keeping the NAME is half
515
- * of not breaking a runtime lookup — the call has to keep working as it
516
- * is spelled.
388
+ * Move one view to a new tab or a split beside its cell, keeping the
389
+ * rest of the arrangement. PUBLIC API: protein3d and msaview call it
390
+ * with the move alone, so `allViewIds` stays optional; it is read only
391
+ * on a host with no view list.
517
392
  */
518
393
  setPendingMove(move, allViewIds) {
519
- // Not `?? []`: homing drops every view the list does not name, so an
520
- // empty one would answer "put this view beside nothing" and unhome the
521
- // rest. Nothing to say is nothing to do.
522
- const ids = allViewIds ?? sessionViewIds(self);
523
- if (!move || !ids) {
394
+ // the session's own list wins over a plugin's possibly stale copy
395
+ const ids = sessionViewIds(self) ?? allViewIds;
396
+ if (!move || !ids?.includes(move.viewId)) {
524
397
  return;
525
398
  }
526
- const known = liveViewIds(self, ids);
527
- // Nothing to move: the view named is not in the session, so there is
528
- // no arrangement to state about it.
529
- if (sessionViewIds(self) && !known.includes(move.viewId)) {
530
- return;
399
+ if (ids.length === 1) {
400
+ self.homeUnassignedViews(ids);
401
+ }
402
+ else if (move.type === 'newTab') {
403
+ self.moveViewToNewTab(move.viewId, ids);
404
+ }
405
+ else {
406
+ self.moveViewToSplit(move.viewId, 'row', ids);
531
407
  }
532
- self.applyLayoutSpec(specForPendingMove(move, known));
533
- // Show where the view went. A spec states an arrangement and not a
534
- // selection, so `treeFromSpec` shows each cell's FIRST tab — and
535
- // `newTab` puts the moved view in a tab beside the others, which makes
536
- // it the one tab nobody can see. The plugin asking for this is asking
537
- // for its view to be on screen; `moveViewToNewTab`, the same gesture
538
- // from the View menu, has always ended with it there.
539
408
  const home = tabContainingView(self.tree, move.viewId);
540
409
  if (home) {
541
410
  self.setActiveTab(home.panel.id, home.tab.id);
542
411
  }
543
412
  },
544
413
  /**
545
- * The whole-workspace re-arrange: every view one cell, in one of four
546
- * shapes. Restored from the dockview header's four "Global:" commands,
547
- * which went with that component and were not reimplemented.
548
- *
549
- * `allViewIds` is passed in rather than read off the session for the same
550
- * reason `moveViewToNewTab` takes it: this mixin owns the tree and has no
551
- * view list of its own. Passing `session.views` order means the
552
- * arrangement it states is already the order views render in, so unlike a
553
- * session spec's layout there is nothing for `orderViews` to apply.
414
+ * Re-arrange the whole workspace, one view per cell, in one of four
415
+ * shapes. Pass `allViewIds` in `session.views` order so there is
416
+ * nothing for `orderViews` to apply.
554
417
  */
555
418
  tileViews(mode, allViewIds) {
556
419
  self.applyLayoutSpec(tileLayoutSpec(liveViewIds(self, allViewIds), mode));
557
420
  },
558
421
  /**
559
422
  * #action
560
- * Arrange the session's views into panels. Calls `applyLayoutSpec`,
561
- * turns workspaces mode on for this session (a layout renders nowhere
562
- * else), and orders `session.views` to the spec's top-to-bottom
563
- * order, which tabs read their order from. Without the last two steps
564
- * the layout applies but does not display, or the tabs appear in the
565
- * wrong order. Leaves take view ids or indexes into `session.views`; a
566
- * layout that seats no view throws rather than leaving a blank tab. A
567
- * session spec's `layout` and an agent's live re-layout both call it.
423
+ * Arrange the session's views into panels: `applyLayoutSpec`, then
424
+ * `session.views` ordered to the spec's top-to-bottom order, which tabs
425
+ * read their order from. Leaves take view ids or indexes into
426
+ * `session.views`; a layout that seats no view throws rather than
427
+ * leaving a blank tab. A session spec's `layout` and an agent's live
428
+ * re-layout both call it.
568
429
  */
569
430
  layoutViews(spec) {
570
431
  const host = self;
571
- if (!host.setUseWorkspaces || !host.orderViews) {
432
+ if (!host.orderViews) {
572
433
  throw new Error('This session has no view list to arrange: layoutViews needs a host composed with MultipleViewsSessionMixin');
573
434
  }
574
- host.setUseWorkspaces(true);
575
- const ids = self.applyLayoutSpec(spec);
576
- if (ids.length === 0) {
435
+ const seated = viewIdsInSpec(resolveLayoutSpec(spec, sessionViewIds(self)));
436
+ if (seated.length === 0) {
577
437
  throw new Error('The layout seats no views: a leaf names its views with "views" (view ids, or indexes into session.views) and a container nests "children"');
578
438
  }
439
+ const ids = self.applyLayoutSpec(spec);
579
440
  host.orderViews(ids);
580
441
  return ids;
581
442
  },
582
- })));
443
+ }))
444
+ // A session saved with workspaces off showed its views stacked whatever
445
+ // layout it carried, so it opens as one cell holding them all
446
+ .preProcessSnapshot(snap => {
447
+ if (snap?.useWorkspaces !==
448
+ false) {
449
+ return snap;
450
+ }
451
+ const { layout, activePanelId, maximizedPanelId, ...rest } = snap;
452
+ return rest;
453
+ }));
583
454
  }
584
455
  export function isSessionWithWorkspaceLayout(session) {
585
456
  return 'layout' in session && 'splitPanel' in session;