MCPcopy Create free account
hub / github.com/bvaughn/react-resizable-panels / floatTab

Function floatTab

lib/workspace/models/floatTab.ts:19–51  ·  view source on GitHub ↗
(
  model: WorkspaceModel<TabData, TabsetData>,
  tabId: string,
  rect: FloatingTabsetRect
)

Source from the content-addressed store, hash-verified

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 */
19export 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}

Callers 2

WorkspaceComponentFunction · 0.90
floating.test.tsFile · 0.90

Calls 6

findTabsetContainingTabFunction · 0.90
isFloatingTabsetFunction · 0.90
copyModelFunction · 0.90
removeTabFunction · 0.90
createTabsetFunction · 0.90
normalizeCopiedModelFunction · 0.90

Tested by

no test coverage detected