( model: WorkspaceModel<TabData, TabsetData>, tabId: string, rect: FloatingTabsetRect )
| 17 | * ℹ️ The only tab of a floating tabset (that isn't kept when empty) is left where it is, since moving it would leave the model unchanged. |
| 18 | */ |
| 19 | export function floatTab<TabData, TabsetData>( |
| 20 | model: WorkspaceModel<TabData, TabsetData>, |
| 21 | tabId: string, |
| 22 | rect: FloatingTabsetRect |
| 23 | ): WorkspaceModel<TabData, TabsetData> { |
| 24 | const current = findTabsetContainingTab(model, tabId); |
| 25 | if ( |
| 26 | !current || |
| 27 | (isFloatingTabset(model, current) && |
| 28 | current.tabs.length === 1 && |
| 29 | !current.keepWhenEmpty) |
| 30 | ) { |
| 31 | return model; |
| 32 | } |
| 33 | |
| 34 | const next = copyModel(model); |
| 35 | const source = findTabsetContainingTab(next, tabId); |
| 36 | const tab = source?.tabs.find(({ id }) => id === tabId); |
| 37 | if (!source || !tab) { |
| 38 | return model; |
| 39 | } |
| 40 | |
| 41 | removeTab(source, tabId); |
| 42 | |
| 43 | const { size: _, ...tabset } = createTabset<TabData, TabsetData>([tab]); |
| 44 | const floating: FloatingTabsetNode<TabData, TabsetData> = { |
| 45 | ...tabset, |
| 46 | ...rect |
| 47 | }; |
| 48 | next.floating = [...(next.floating ?? []), floating]; |
| 49 | |
| 50 | return normalizeCopiedModel(next); |
| 51 | } |
no test coverage detected