( model: WorkspaceModel<TabData, TabsetData>, tabsetId: string, rect: FloatingTabsetRect )
| 16 | * ℹ️ The root tabset (which fills the workspace) and tabsets that are already floating are left unchanged. |
| 17 | */ |
| 18 | export function floatTabset<TabData, TabsetData>( |
| 19 | model: WorkspaceModel<TabData, TabsetData>, |
| 20 | tabsetId: string, |
| 21 | rect: FloatingTabsetRect |
| 22 | ): WorkspaceModel<TabData, TabsetData> { |
| 23 | const current = findTabset(model, tabsetId); |
| 24 | if (!current || isFloatingTabset(model, current)) { |
| 25 | return model; |
| 26 | } |
| 27 | |
| 28 | const next = copyModel(model); |
| 29 | const tabset = findTabset(next, tabsetId); |
| 30 | const parent = findParent(next.root, tabsetId); |
| 31 | if (!tabset || !parent) { |
| 32 | return model; |
| 33 | } |
| 34 | |
| 35 | parent.children.splice(parent.children.indexOf(tabset), 1); |
| 36 | |
| 37 | // A collapsed tabset floats expanded (it can be collapsed again; see FloatingTabsetNode) |
| 38 | const { collapsed: _c, collapsible: _cs, size: _s, ...rest } = tabset; |
| 39 | const floating: FloatingTabsetNode<TabData, TabsetData> = { |
| 40 | ...rest, |
| 41 | ...rect |
| 42 | }; |
| 43 | next.floating = [...(next.floating ?? []), floating]; |
| 44 | |
| 45 | // A maximized tabset is restored first (floating tabsets can't be maximized) |
| 46 | if (next.maximizedTabsetId === tabsetId) { |
| 47 | delete next.maximizedTabsetId; |
| 48 | } |
| 49 | |
| 50 | return normalizeCopiedModel(next); |
| 51 | } |
no test coverage detected