@jbrowse/app-core 4.3.0 → 5.0.0-beta.10

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 (165) hide show
  1. package/esm/AppSession/AppRootModel.d.ts +30 -0
  2. package/esm/AppSession/AppRootModel.js +1 -0
  3. package/esm/AppSession/AppSessionMixin.d.ts +1324 -0
  4. package/esm/AppSession/AppSessionMixin.js +62 -0
  5. package/esm/AppSession/index.d.ts +2 -0
  6. package/esm/AppSession/index.js +1 -0
  7. package/esm/Assemblies/AssembliesMixin.d.ts +294 -0
  8. package/esm/Assemblies/AssembliesMixin.js +154 -0
  9. package/esm/Assemblies/index.d.ts +1 -2
  10. package/esm/Assemblies/index.js +1 -2
  11. package/esm/HistoryManagement/index.d.ts +11 -0
  12. package/esm/HistoryManagement/index.js +43 -10
  13. package/esm/JBrowseConfig/RootConfiguration.d.ts +123 -78
  14. package/esm/JBrowseConfig/RootConfiguration.js +79 -7
  15. package/esm/JBrowseConfig/defaultShareUrl.d.ts +1 -0
  16. package/esm/JBrowseConfig/defaultShareUrl.js +5 -0
  17. package/esm/JBrowseConfig/index.d.ts +175 -84
  18. package/esm/JBrowseConfig/index.js +64 -2
  19. package/esm/JBrowseModel/index.d.ts +175 -97
  20. package/esm/JBrowseModel/index.js +132 -31
  21. package/esm/JbApi/index.d.ts +2 -0
  22. package/esm/JbApi/index.js +1 -0
  23. package/esm/JbApi/jbApi.d.ts +2767 -0
  24. package/esm/JbApi/jbApi.js +1383 -0
  25. package/esm/RootMenu/index.d.ts +69 -3
  26. package/esm/RootMenu/index.js +96 -61
  27. package/esm/SessionSpec/index.d.ts +6 -0
  28. package/esm/SessionSpec/index.js +3 -0
  29. package/esm/SessionSpec/lgvUrlInit.d.ts +79 -0
  30. package/esm/SessionSpec/lgvUrlInit.js +161 -0
  31. package/esm/SessionSpec/loadSessionSpec.d.ts +75 -0
  32. package/esm/SessionSpec/loadSessionSpec.js +473 -0
  33. package/esm/SessionSpec/parseSessionSpecUrl.d.ts +7 -0
  34. package/esm/SessionSpec/parseSessionSpecUrl.js +181 -0
  35. package/esm/SessionSpec/types.d.ts +37 -0
  36. package/esm/SessionSpec/types.js +1 -0
  37. package/esm/WorkspaceLayout/LayoutRenderer.d.ts +24 -0
  38. package/esm/WorkspaceLayout/LayoutRenderer.js +185 -0
  39. package/esm/WorkspaceLayout/PanelView.d.ts +13 -0
  40. package/esm/WorkspaceLayout/PanelView.js +99 -0
  41. package/esm/WorkspaceLayout/TabStrip.d.ts +14 -0
  42. package/esm/WorkspaceLayout/TabStrip.js +226 -0
  43. package/esm/WorkspaceLayout/WorkspaceContainer.d.ts +16 -0
  44. package/esm/WorkspaceLayout/WorkspaceContainer.js +107 -0
  45. package/esm/WorkspaceLayout/WorkspacePanelActions.d.ts +24 -0
  46. package/esm/WorkspaceLayout/WorkspacePanelActions.js +120 -0
  47. package/esm/WorkspaceLayout/WorkspaceTab.d.ts +27 -0
  48. package/esm/WorkspaceLayout/WorkspaceTab.js +105 -0
  49. package/esm/WorkspaceLayout/dockviewTheme.d.ts +69 -0
  50. package/esm/WorkspaceLayout/dockviewTheme.js +82 -0
  51. package/esm/WorkspaceLayout/dropZone.d.ts +105 -0
  52. package/esm/WorkspaceLayout/dropZone.js +113 -0
  53. package/esm/WorkspaceLayout/index.d.ts +8 -0
  54. package/esm/WorkspaceLayout/index.js +4 -0
  55. package/esm/WorkspaceLayout/model.d.ts +260 -0
  56. package/esm/WorkspaceLayout/model.js +586 -0
  57. package/esm/WorkspaceLayout/panelChrome.d.ts +19 -0
  58. package/esm/WorkspaceLayout/panelChrome.js +4 -0
  59. package/esm/WorkspaceLayout/spec.d.ts +88 -0
  60. package/esm/WorkspaceLayout/spec.js +226 -0
  61. package/esm/WorkspaceLayout/splitter.d.ts +25 -0
  62. package/esm/WorkspaceLayout/splitter.js +37 -0
  63. package/esm/WorkspaceLayout/tree.d.ts +158 -0
  64. package/esm/WorkspaceLayout/tree.js +379 -0
  65. package/esm/WorkspaceLayout/useLayoutDrag.d.ts +34 -0
  66. package/esm/WorkspaceLayout/useLayoutDrag.js +232 -0
  67. package/esm/index.d.ts +18 -9
  68. package/esm/index.js +16 -9
  69. package/esm/menus.d.ts +55 -68
  70. package/esm/menus.js +117 -86
  71. package/esm/queryParams.d.ts +9 -0
  72. package/esm/queryParams.js +93 -0
  73. package/esm/sessionModelFactory.d.ts +18 -0
  74. package/esm/sessionModelFactory.js +1 -0
  75. package/esm/ui/App/App.d.ts +3 -14
  76. package/esm/ui/App/App.js +39 -19
  77. package/esm/ui/App/AppFab.d.ts +12 -3
  78. package/esm/ui/App/AppFab.js +15 -8
  79. package/esm/ui/App/AppToolbar.d.ts +2 -14
  80. package/esm/ui/App/AppToolbar.js +45 -31
  81. package/esm/ui/App/ClassicViewsContainer.d.ts +4 -10
  82. package/esm/ui/App/ClassicViewsContainer.js +9 -8
  83. package/esm/ui/App/DialogQueue.d.ts +17 -1
  84. package/esm/ui/App/DialogQueue.js +30 -1
  85. package/esm/ui/App/Drawer.d.ts +1 -1
  86. package/esm/ui/App/Drawer.js +10 -39
  87. package/esm/ui/App/DrawerHeader.d.ts +2 -3
  88. package/esm/ui/App/DrawerHeader.js +24 -11
  89. package/esm/ui/App/DrawerHeaderHelpButton.d.ts +1 -1
  90. package/esm/ui/App/DrawerHeaderHelpButton.js +3 -3
  91. package/esm/ui/App/DrawerHeaderHelpDialog.d.ts +2 -2
  92. package/esm/ui/App/DrawerHeaderHelpDialog.js +3 -4
  93. package/esm/ui/App/DrawerWidget.d.ts +1 -1
  94. package/esm/ui/App/DrawerWidget.js +9 -21
  95. package/esm/ui/App/JBrowseTabMenu.d.ts +2 -3
  96. package/esm/ui/App/JBrowseTabMenu.js +24 -5
  97. package/esm/ui/App/ThemeModeButton.d.ts +12 -0
  98. package/esm/ui/App/ThemeModeButton.js +34 -0
  99. package/esm/ui/App/ViewButtons.d.ts +2 -4
  100. package/esm/ui/App/ViewButtons.js +15 -3
  101. package/esm/ui/App/ViewContainer.d.ts +3 -2
  102. package/esm/ui/App/ViewContainer.js +128 -24
  103. package/esm/ui/App/ViewContainerTitle.d.ts +1 -1
  104. package/esm/ui/App/ViewContainerTitle.js +21 -11
  105. package/esm/ui/App/ViewErrorFallback.d.ts +18 -0
  106. package/esm/ui/App/ViewErrorFallback.js +42 -0
  107. package/esm/ui/App/ViewHeader.d.ts +3 -4
  108. package/esm/ui/App/ViewHeader.js +28 -17
  109. package/esm/ui/App/ViewLauncher.d.ts +2 -8
  110. package/esm/ui/App/ViewLauncher.js +7 -5
  111. package/esm/ui/App/ViewMenu.d.ts +3 -5
  112. package/esm/ui/App/ViewMenu.js +87 -92
  113. package/esm/ui/App/ViewStack.d.ts +7 -0
  114. package/esm/ui/App/ViewStack.js +48 -0
  115. package/esm/ui/App/ViewWrapper.d.ts +15 -1
  116. package/esm/ui/App/ViewWrapper.js +26 -10
  117. package/esm/ui/App/ViewsContainer.d.ts +4 -11
  118. package/esm/ui/App/ViewsContainer.js +6 -9
  119. package/esm/ui/App/index.d.ts +2 -1
  120. package/esm/ui/App/index.js +3 -2
  121. package/esm/ui/App/lazyChunk.d.ts +13 -0
  122. package/esm/ui/App/lazyChunk.js +91 -0
  123. package/esm/ui/App/lazyParts.d.ts +32 -0
  124. package/esm/ui/App/lazyParts.js +8 -0
  125. package/esm/ui/App/preloadAppShell.d.ts +14 -0
  126. package/esm/ui/App/preloadAppShell.js +41 -0
  127. package/esm/ui/App/types.d.ts +17 -3
  128. package/esm/ui/App/types.js +1 -1
  129. package/esm/ui/App/useViewVisibility.d.ts +35 -0
  130. package/esm/ui/App/useViewVisibility.js +88 -0
  131. package/esm/ui/App/viewTitle.d.ts +12 -0
  132. package/esm/ui/App/viewTitle.js +17 -0
  133. package/esm/ui/index.d.ts +1 -1
  134. package/esm/ui/index.js +1 -1
  135. package/package.json +12 -17
  136. package/esm/AppFocus/index.d.ts +0 -5
  137. package/esm/AppFocus/index.js +0 -12
  138. package/esm/Assemblies/SessionAssembliesMixin.d.ts +0 -92
  139. package/esm/Assemblies/SessionAssembliesMixin.js +0 -53
  140. package/esm/Assemblies/TemporaryAssembliesMixin.d.ts +0 -10
  141. package/esm/Assemblies/TemporaryAssembliesMixin.js +0 -37
  142. package/esm/DockviewLayout/index.d.ts +0 -35
  143. package/esm/DockviewLayout/index.js +0 -111
  144. package/esm/ui/App/DockviewContext.d.ts +0 -22
  145. package/esm/ui/App/DockviewContext.js +0 -29
  146. package/esm/ui/App/DockviewLeftHeaderActions.d.ts +0 -2
  147. package/esm/ui/App/DockviewLeftHeaderActions.js +0 -58
  148. package/esm/ui/App/DockviewRightHeaderActions.d.ts +0 -2
  149. package/esm/ui/App/DockviewRightHeaderActions.js +0 -100
  150. package/esm/ui/App/DrawerControls.d.ts +0 -5
  151. package/esm/ui/App/DrawerControls.js +0 -25
  152. package/esm/ui/App/DrawerWidgetSelector.d.ts +0 -5
  153. package/esm/ui/App/DrawerWidgetSelector.js +0 -47
  154. package/esm/ui/App/JBrowseViewPanel.d.ts +0 -8
  155. package/esm/ui/App/JBrowseViewPanel.js +0 -40
  156. package/esm/ui/App/JBrowseViewTab.d.ts +0 -8
  157. package/esm/ui/App/JBrowseViewTab.js +0 -97
  158. package/esm/ui/App/ModalWidget.d.ts +0 -6
  159. package/esm/ui/App/ModalWidget.js +0 -48
  160. package/esm/ui/App/TiledViewsContainer.d.ts +0 -6
  161. package/esm/ui/App/TiledViewsContainer.js +0 -366
  162. package/esm/ui/App/copyView.d.ts +0 -1
  163. package/esm/ui/App/copyView.js +0 -29
  164. package/esm/ui/App/dockviewUtils.d.ts +0 -46
  165. package/esm/ui/App/dockviewUtils.js +0 -55
@@ -0,0 +1,586 @@
1
+ import { createElementId } from '@jbrowse/core/util/types/mst';
2
+ import { cast, getSnapshot, types } from '@jbrowse/mobx-state-tree';
3
+ import { resolveLayoutSpec, specForPendingMove, tileLayoutSpec, treeFromSpec, viewIdsInSpec, } from './spec.js';
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
+ function sessionViewIds(self) {
6
+ return self.views?.map(v => v.id);
7
+ }
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.
18
+ */
19
+ function liveViewIds(self, allViewIds) {
20
+ const live = sessionViewIds(self);
21
+ return [
22
+ ...new Set(live ? allViewIds.filter(id => live.includes(id)) : allViewIds),
23
+ ];
24
+ }
25
+ /**
26
+ * #stateModel WorkspaceLayoutMixin
27
+ *
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:
34
+ *
35
+ * branch (a split) > panel (a grid cell) > tab > views (stacked)
36
+ *
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
+ * 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.
44
+ */
45
+ const LayoutTab = types.model('LayoutTab', {
46
+ id: types.identifier,
47
+ viewIds: types.array(types.string),
48
+ /** set only by an explicit rename; otherwise the name is derived from views */
49
+ title: types.maybe(types.string),
50
+ });
51
+ const LayoutPanel = types.model('LayoutPanel', {
52
+ id: types.identifier,
53
+ size: types.optional(types.number, 1),
54
+ tabs: types.array(LayoutTab),
55
+ activeTabId: types.maybe(types.string),
56
+ });
57
+ const LayoutBranch = types.model('LayoutBranch', {
58
+ id: types.identifier,
59
+ size: types.optional(types.number, 1),
60
+ direction: types.enumeration('LayoutDirection', ['row', 'column']),
61
+ children: types.array(types.late(() => LayoutNode)),
62
+ });
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.
66
+ const LayoutNode = types.union({
67
+ dispatcher: (snapshot) => snapshot.direction ? LayoutBranch : LayoutPanel,
68
+ }, LayoutBranch, LayoutPanel);
69
+ /**
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.
76
+ */
77
+ function nextId(kind) {
78
+ return `${kind}-${createElementId()}`;
79
+ }
80
+ function emptyPanel() {
81
+ const tabId = nextId('tab');
82
+ return {
83
+ id: nextId('panel'),
84
+ size: 1,
85
+ tabs: [{ id: tabId, viewIds: [] }],
86
+ activeTabId: tabId,
87
+ };
88
+ }
89
+ export function WorkspaceLayoutMixin() {
90
+ return (types
91
+ .model({
92
+ layout: types.optional(LayoutNode, emptyPanel),
93
+ activePanelId: types.maybe(types.string),
94
+ /**
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.
105
+ */
106
+ maximizedPanelId: types.maybe(types.string),
107
+ })
108
+ .views(self => ({
109
+ /**
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.
119
+ */
120
+ get tree() {
121
+ return getSnapshot(self.layout);
122
+ },
123
+ }))
124
+ .views(self => ({
125
+ get panels() {
126
+ return panels(self.tree);
127
+ },
128
+ get tabs() {
129
+ return tabs(self.tree);
130
+ },
131
+ hasPanel(panelId) {
132
+ return panels(self.tree).some(p => p.id === panelId);
133
+ },
134
+ findTab(tabId) {
135
+ return findTab(self.tree, tabId);
136
+ },
137
+ tabContainingView(viewId) {
138
+ return tabContainingView(self.tree, viewId);
139
+ },
140
+ panelContainingView(viewId) {
141
+ return panelContainingView(self.tree, viewId);
142
+ },
143
+ /** The views a tab renders: its members, in `session.views` order. */
144
+ viewIdsForTab(tabId, order) {
145
+ const members = new Set(findTab(self.tree, tabId)?.tab.viewIds ?? []);
146
+ return order.filter(id => members.has(id));
147
+ },
148
+ /** The tab a panel is showing, or its first. */
149
+ activeTabOf(panelId) {
150
+ const panel = panels(self.tree).find(p => p.id === panelId);
151
+ return panel ? activeTabIn(panel) : undefined;
152
+ },
153
+ /**
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.
161
+ */
162
+ get visibleTree() {
163
+ const maximized = panels(self.tree).find(p => p.id === self.maximizedPanelId);
164
+ return maximized ? { ...maximized, size: 1 } : self.tree;
165
+ },
166
+ }))
167
+ .actions(self => {
168
+ /**
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.
183
+ */
184
+ function livePanelIds() {
185
+ if (self.activePanelId !== undefined &&
186
+ !self.hasPanel(self.activePanelId)) {
187
+ self.activePanelId = panels(self.tree)[0]?.id;
188
+ }
189
+ if (self.maximizedPanelId !== undefined &&
190
+ !self.hasPanel(self.maximizedPanelId)) {
191
+ self.maximizedPanelId = undefined;
192
+ }
193
+ }
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
+ */
205
+ function apply(next) {
206
+ const before = panels(self.tree).length;
207
+ 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`.
215
+ if (panels(self.tree).length > before) {
216
+ self.maximizedPanelId = undefined;
217
+ }
218
+ livePanelIds();
219
+ }
220
+ function home(tree, viewIds) {
221
+ return homeViews(tree, viewIds, self.activePanelId, () => nextId('tab'));
222
+ }
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
+ function everyViewId(action, allViewIds) {
234
+ const ids = allViewIds ?? sessionViewIds(self);
235
+ if (!ids) {
236
+ throw new Error(`${action}(viewId, allViewIds): allViewIds is every view id in the session, and this session has no view list to default it from`);
237
+ }
238
+ return ids;
239
+ }
240
+ function rehomeView(viewId, allViewIds, place) {
241
+ const tree = home(self.tree, allViewIds);
242
+ const from = tabContainingView(tree, viewId);
243
+ if (!from) {
244
+ return undefined;
245
+ }
246
+ const placed = place(removeView(tree, viewId), from);
247
+ apply(pruneEmptyTabIn(placed, from.panel.id, from.tab.id));
248
+ return from;
249
+ }
250
+ /**
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.
261
+ */
262
+ function dropSource(tabId, targetPanelId) {
263
+ const source = findTab(self.tree, tabId)?.panel;
264
+ return source && self.hasPanel(targetPanelId) ? source : undefined;
265
+ }
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.
268
+ return {
269
+ setActivePanelId(panelId) {
270
+ self.activePanelId = panelId;
271
+ },
272
+ /**
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_CONTEXT_BUDGET.md`) can
284
+ * only go down. That is the reason it is this and not a `display:
285
+ * none` over a still-mounted workspace.
286
+ */
287
+ toggleMaximizedPanel(panelId) {
288
+ if (!self.hasPanel(panelId)) {
289
+ return;
290
+ }
291
+ self.maximizedPanelId =
292
+ self.maximizedPanelId === panelId ? undefined : panelId;
293
+ if (self.maximizedPanelId !== undefined) {
294
+ self.activePanelId = panelId;
295
+ }
296
+ },
297
+ restorePanels() {
298
+ self.maximizedPanelId = undefined;
299
+ },
300
+ setActiveTab(panelId, tabId) {
301
+ apply(setActiveTab(self.tree, panelId, tabId));
302
+ self.activePanelId = panelId;
303
+ },
304
+ renameTab(tabId, title) {
305
+ apply(renameTab(self.tree, tabId, title));
306
+ },
307
+ /** Split a grid cell; the new cell gets one empty tab. */
308
+ splitPanel(panelId, direction, before = false) {
309
+ const panel = emptyPanel();
310
+ 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.
314
+ if (!self.hasPanel(panel.id)) {
315
+ return undefined;
316
+ }
317
+ self.activePanelId = panel.id;
318
+ return panel;
319
+ },
320
+ closePanel(panelId) {
321
+ apply(removePanel(self.tree, panelId));
322
+ },
323
+ /** "New empty tab": a tab in an existing cell, showing the launcher. */
324
+ addTab(panelId, viewIds = []) {
325
+ if (!self.hasPanel(panelId)) {
326
+ return undefined;
327
+ }
328
+ const tab = { id: nextId('tab'), viewIds };
329
+ apply(addTab(self.tree, panelId, tab));
330
+ self.activePanelId = panelId;
331
+ return tab;
332
+ },
333
+ /**
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.
346
+ */
347
+ closeTab(tabId) {
348
+ const panelId = findTab(self.tree, tabId)?.panel.id;
349
+ if (panelId === undefined) {
350
+ return;
351
+ }
352
+ apply(pruneEmptyPanel(removeTab(self.tree, tabId), panelId));
353
+ },
354
+ addViewToTab(tabId, viewId) {
355
+ apply(addViewToTab(self.tree, tabId, viewId));
356
+ },
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
+ */
379
+ dropTabInPanel(tabId, targetPanelId, index) {
380
+ const source = dropSource(tabId, targetPanelId);
381
+ if (!source) {
382
+ return;
383
+ }
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.
393
+ if (source.id === targetPanelId && index === undefined) {
394
+ return;
395
+ }
396
+ let next = moveTabToPanel(self.tree, tabId, targetPanelId, index);
397
+ if (source.id !== targetPanelId) {
398
+ next = pruneEmptyPanel(next, source.id);
399
+ }
400
+ apply(next);
401
+ self.activePanelId = targetPanelId;
402
+ },
403
+ /** Drop a dragged tab on a panel edge: split, and land in the new half. */
404
+ dropTabInNewSplit(tabId, targetPanelId, direction, before) {
405
+ const source = dropSource(tabId, targetPanelId);
406
+ if (!source) {
407
+ return undefined;
408
+ }
409
+ const panel = {
410
+ id: nextId('panel'),
411
+ size: 1,
412
+ tabs: [],
413
+ };
414
+ let next = splitPanel(self.tree, targetPanelId, direction, panel, before);
415
+ 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.
419
+ next = pruneEmptyPanel(next, source.id);
420
+ apply(next);
421
+ self.activePanelId = panel.id;
422
+ return panel.id;
423
+ },
424
+ setSizes(branchId, sizes) {
425
+ apply(setSizes(self.tree, branchId, sizes));
426
+ },
427
+ /**
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.
443
+ */
444
+ applyLayoutSpec(spec) {
445
+ const resolved = resolveLayoutSpec(spec, sessionViewIds(self));
446
+ apply(treeFromSpec(resolved, nextId));
447
+ self.activePanelId = panels(self.tree)[0]?.id;
448
+ return viewIdsInSpec(resolved);
449
+ },
450
+ /**
451
+ * ViewMenu's "move to new tab": the view leaves its tab for a new one.
452
+ *
453
+ * `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.
456
+ */
457
+ moveViewToNewTab(viewId, allViewIds) {
458
+ const tab = { id: nextId('tab'), viewIds: [viewId] };
459
+ const from = rehomeView(viewId, everyViewId('moveViewToNewTab', allViewIds), (tree, at) => addTab(tree, at.panel.id, tab));
460
+ if (!from) {
461
+ return undefined;
462
+ }
463
+ self.activePanelId = from.panel.id;
464
+ return tab.id;
465
+ },
466
+ /**
467
+ * ViewMenu's "move to split view": the view leaves for a new cell.
468
+ * `allViewIds` is every view in the session — see `moveViewToNewTab`.
469
+ */
470
+ moveViewToSplitRight(viewId, allViewIds) {
471
+ const tabId = nextId('tab');
472
+ const panel = {
473
+ id: nextId('panel'),
474
+ size: 1,
475
+ tabs: [{ id: tabId, viewIds: [viewId] }],
476
+ activeTabId: tabId,
477
+ };
478
+ const from = rehomeView(viewId, everyViewId('moveViewToSplitRight', allViewIds), (tree, at) => splitPanel(tree, at.panel.id, 'row', panel));
479
+ if (!from) {
480
+ return undefined;
481
+ }
482
+ self.activePanelId = panel.id;
483
+ return panel.id;
484
+ },
485
+ homeUnassignedViews(viewIds) {
486
+ apply(home(self.tree, viewIds));
487
+ },
488
+ };
489
+ })
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
+ */
501
+ .actions(self => ({
502
+ /**
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.
517
+ */
518
+ 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) {
524
+ return;
525
+ }
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;
531
+ }
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
+ const home = tabContainingView(self.tree, move.viewId);
540
+ if (home) {
541
+ self.setActiveTab(home.panel.id, home.tab.id);
542
+ }
543
+ },
544
+ /**
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.
554
+ */
555
+ tileViews(mode, allViewIds) {
556
+ self.applyLayoutSpec(tileLayoutSpec(liveViewIds(self, allViewIds), mode));
557
+ },
558
+ /**
559
+ * #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.
568
+ */
569
+ layoutViews(spec) {
570
+ const host = self;
571
+ if (!host.setUseWorkspaces || !host.orderViews) {
572
+ throw new Error('This session has no view list to arrange: layoutViews needs a host composed with MultipleViewsSessionMixin');
573
+ }
574
+ host.setUseWorkspaces(true);
575
+ const ids = self.applyLayoutSpec(spec);
576
+ if (ids.length === 0) {
577
+ 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
+ }
579
+ host.orderViews(ids);
580
+ return ids;
581
+ },
582
+ })));
583
+ }
584
+ export function isSessionWithWorkspaceLayout(session) {
585
+ return 'layout' in session && 'splitPanel' in session;
586
+ }
@@ -0,0 +1,19 @@
1
+ import type { PanelNode, TabNode } from './tree.ts';
2
+ import type { TabDragHandlers } from './useLayoutDrag.ts';
3
+ /**
4
+ * The app's half of a panel — what a tab is *called* and what it *contains*.
5
+ *
6
+ * One object rather than five props because every one is forwarded unchanged
7
+ * down the whole recursion, and because one object can be memoised: it reaches
8
+ * every panel, so a fresh one per render re-renders the entire workspace.
9
+ */
10
+ export interface PanelChrome {
11
+ renderTabLabel: (tab: TabNode) => React.ReactNode;
12
+ renderTabContent: (tab: TabNode) => React.ReactNode;
13
+ renderPanelActions?: (panel: PanelNode) => React.ReactNode;
14
+ dragHandlers: TabDragHandlers;
15
+ /** middle-click; the caller pairs it with closing that tab's views */
16
+ onTabClose?: (tabId: string) => void;
17
+ }
18
+ export declare const tabDomId: (tabId: string) => string;
19
+ export declare const tabPanelDomId: (panelId: string) => string;
@@ -0,0 +1,4 @@
1
+ // The tablist wires `aria-controls`/`aria-labelledby` with these, and the strip
2
+ // mints one end of each pair while the tabpanel mints the other.
3
+ export const tabDomId = (tabId) => `jbrowse-tab-${tabId}`;
4
+ export const tabPanelDomId = (panelId) => `jbrowse-tabpanel-${panelId}`;