react-tiling-workspace 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/components/LayoutPickerDialog-C-Sb3uOl.cjs +517 -0
- package/dist/components/LayoutPickerDialog-C-Sb3uOl.cjs.map +1 -0
- package/dist/components/LayoutPickerDialog-STglqYFI.mjs +500 -0
- package/dist/components/LayoutPickerDialog-STglqYFI.mjs.map +1 -0
- package/dist/components/icons-0kjsH_LJ.cjs +144 -0
- package/dist/components/icons-0kjsH_LJ.cjs.map +1 -0
- package/dist/components/icons-BgtEPXL8.mjs +97 -0
- package/dist/components/icons-BgtEPXL8.mjs.map +1 -0
- package/dist/components/layout-picker.cjs +5 -0
- package/dist/components/layout-picker.d.cts +22 -0
- package/dist/components/layout-picker.d.mts +22 -0
- package/dist/components/layout-picker.mjs +2 -0
- package/dist/components/mobile.cjs +575 -0
- package/dist/components/mobile.cjs.map +1 -0
- package/dist/components/mobile.d.cts +42 -0
- package/dist/components/mobile.d.mts +42 -0
- package/dist/components/mobile.mjs +574 -0
- package/dist/components/mobile.mjs.map +1 -0
- package/dist/components/topbar.cjs +94 -0
- package/dist/components/topbar.cjs.map +1 -0
- package/dist/components/topbar.d.cts +38 -0
- package/dist/components/topbar.d.mts +38 -0
- package/dist/components/topbar.mjs +93 -0
- package/dist/components/topbar.mjs.map +1 -0
- package/dist/components/types-DkwWFcD5.d.mts +32 -0
- package/dist/components/types-qsXC_48o.d.cts +32 -0
- package/dist/index.cjs +3336 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +243 -0
- package/dist/index.d.mts +243 -0
- package/dist/index.mjs +3320 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server/server.cjs +104 -0
- package/dist/server/server.cjs.map +1 -0
- package/dist/server/server.d.cts +71 -0
- package/dist/server/server.d.mts +71 -0
- package/dist/server/server.mjs +95 -0
- package/dist/server/server.mjs.map +1 -0
- package/dist/server/shortcuts.cjs +32 -0
- package/dist/server/shortcuts.cjs.map +1 -0
- package/dist/server/shortcuts.d.cts +6 -0
- package/dist/server/shortcuts.d.mts +6 -0
- package/dist/server/shortcuts.mjs +31 -0
- package/dist/server/shortcuts.mjs.map +1 -0
- package/dist/theme.css +119 -0
- package/package.json +113 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_shortcuts = require("./shortcuts.cjs");
|
|
3
|
+
// src/layout.ts
|
|
4
|
+
const MAX_WORKSPACE_SPLIT_DEPTH = 4;
|
|
5
|
+
function getPanelIds(tree) {
|
|
6
|
+
if (!tree) return [];
|
|
7
|
+
if (tree.type === "panel") return [tree.id];
|
|
8
|
+
return tree.children.flatMap((child) => getPanelIds(child));
|
|
9
|
+
}
|
|
10
|
+
function isNodeFolded(node, folds) {
|
|
11
|
+
if (node.type === "panel") return (folds[node.id] ?? "open") === "folded";
|
|
12
|
+
return node.children.length > 0 && node.children.every((child) => isNodeFolded(child, folds));
|
|
13
|
+
}
|
|
14
|
+
function normalizeLayoutTree(node) {
|
|
15
|
+
if (node.type === "panel") return node;
|
|
16
|
+
const rawSizes = node.children.map((_, index) => node.sizes?.[index] ?? 1);
|
|
17
|
+
const nextChildren = [];
|
|
18
|
+
const nextSizes = [];
|
|
19
|
+
let hasExplicitSizes = Boolean(node.sizes);
|
|
20
|
+
for (let i = 0; i < node.children.length; i += 1) {
|
|
21
|
+
const normalizedChild = normalizeLayoutTree(node.children[i]);
|
|
22
|
+
const weight = rawSizes[i];
|
|
23
|
+
if (normalizedChild.type === "split" && normalizedChild.direction === node.direction) {
|
|
24
|
+
const childSizes = normalizedChild.children.map((_, childIdx) => normalizedChild.sizes?.[childIdx] ?? 1);
|
|
25
|
+
const childTotal = childSizes.reduce((acc, value) => acc + value, 0) || 1;
|
|
26
|
+
for (let j = 0; j < normalizedChild.children.length; j += 1) {
|
|
27
|
+
nextChildren.push(normalizedChild.children[j]);
|
|
28
|
+
nextSizes.push(weight * (childSizes[j] / childTotal));
|
|
29
|
+
}
|
|
30
|
+
if (normalizedChild.sizes) hasExplicitSizes = true;
|
|
31
|
+
} else {
|
|
32
|
+
nextChildren.push(normalizedChild);
|
|
33
|
+
nextSizes.push(weight);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (nextChildren.length === 1) return nextChildren[0];
|
|
37
|
+
return hasExplicitSizes ? {
|
|
38
|
+
type: "split",
|
|
39
|
+
direction: node.direction,
|
|
40
|
+
children: nextChildren,
|
|
41
|
+
sizes: nextSizes
|
|
42
|
+
} : {
|
|
43
|
+
type: "split",
|
|
44
|
+
direction: node.direction,
|
|
45
|
+
children: nextChildren
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function validateLayoutTree(value, knownIds) {
|
|
49
|
+
const seen = /* @__PURE__ */ new Set();
|
|
50
|
+
function visit(node, splitDepthCount) {
|
|
51
|
+
if (!node || typeof node !== "object") return false;
|
|
52
|
+
const candidate = node;
|
|
53
|
+
if (candidate.type === "panel") {
|
|
54
|
+
if (typeof candidate.id !== "string" || !knownIds.has(candidate.id)) return false;
|
|
55
|
+
const id = candidate.id;
|
|
56
|
+
if (seen.has(id)) return false;
|
|
57
|
+
seen.add(id);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (candidate.type !== "split" || candidate.direction !== "horizontal" && candidate.direction !== "vertical" || !Array.isArray(candidate.children) || candidate.children.length < 2 || splitDepthCount >= 4) return false;
|
|
61
|
+
if (candidate.sizes !== void 0 && (!Array.isArray(candidate.sizes) || candidate.sizes.length !== candidate.children.length || candidate.sizes.some((size) => typeof size !== "number" || !Number.isFinite(size) || size <= 0))) return false;
|
|
62
|
+
return candidate.children.every((child) => visit(child, splitDepthCount + 1));
|
|
63
|
+
}
|
|
64
|
+
return visit(value, 0);
|
|
65
|
+
}
|
|
66
|
+
function layoutTemplateSignature(template) {
|
|
67
|
+
if (template.type === "panel") return "p";
|
|
68
|
+
return `${template.direction === "horizontal" ? "h" : "v"}(${template.children.map(layoutTemplateSignature).join(",")})`;
|
|
69
|
+
}
|
|
70
|
+
function layoutTreeSignature(tree) {
|
|
71
|
+
if (tree.type === "panel") return "p";
|
|
72
|
+
return `${tree.direction === "horizontal" ? "h" : "v"}(${tree.children.map(layoutTreeSignature).join(",")})`;
|
|
73
|
+
}
|
|
74
|
+
function equalizeSplitAtPath(node, path, index) {
|
|
75
|
+
if (path.length === 0) {
|
|
76
|
+
if (node.type !== "split") return node;
|
|
77
|
+
const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);
|
|
78
|
+
if (index < 0 || index + 1 >= sizes.length) return node;
|
|
79
|
+
const avg = (sizes[index] + sizes[index + 1]) / 2;
|
|
80
|
+
sizes[index] = avg;
|
|
81
|
+
sizes[index + 1] = avg;
|
|
82
|
+
return {
|
|
83
|
+
...node,
|
|
84
|
+
sizes
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (node.type !== "split") return node;
|
|
88
|
+
const [head, ...tail] = path;
|
|
89
|
+
return {
|
|
90
|
+
...node,
|
|
91
|
+
children: node.children.map((child, childIndex) => childIndex === head ? equalizeSplitAtPath(child, tail, index) : child)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.DEFAULT_WORKSPACE_SHORTCUTS = require_shortcuts.DEFAULT_WORKSPACE_SHORTCUTS;
|
|
95
|
+
exports.MAX_WORKSPACE_SPLIT_DEPTH = MAX_WORKSPACE_SPLIT_DEPTH;
|
|
96
|
+
exports.equalizeSplitAtPath = equalizeSplitAtPath;
|
|
97
|
+
exports.getPanelIds = getPanelIds;
|
|
98
|
+
exports.isNodeFolded = isNodeFolded;
|
|
99
|
+
exports.layoutTemplateSignature = layoutTemplateSignature;
|
|
100
|
+
exports.layoutTreeSignature = layoutTreeSignature;
|
|
101
|
+
exports.normalizeLayoutTree = normalizeLayoutTree;
|
|
102
|
+
exports.validateLayoutTree = validateLayoutTree;
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=server.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.cjs","names":[],"sources":["../../src/layout.ts"],"sourcesContent":["import type {\n FoldState,\n WorkspaceLayoutNode,\n WorkspaceLayoutTemplate,\n} from \"./types\";\n\nexport const MAX_WORKSPACE_SPLIT_DEPTH = 4;\n\nexport const HORIZONTAL_FOLD_SNAP_PX = 96;\nexport const VERTICAL_FOLD_SNAP_PX = 76;\nexport const HORIZONTAL_FOLDED_RAIL_PX = 46;\nexport const VERTICAL_FOLDED_BAR_PX = 44;\nexport const HORIZONTAL_UNFOLD_THRESHOLD_PX = 128;\nexport const VERTICAL_UNFOLD_THRESHOLD_PX = 104;\nexport const HORIZONTAL_MIN_OPEN_PX = 120;\nexport const VERTICAL_MIN_OPEN_PX = 92;\nexport const HORIZONTAL_READING_OPEN_PX = 320;\nexport const VERTICAL_READING_OPEN_PX = 220;\nexport const FOLD_APPROACH_MARGIN_PX = 38;\n\nexport function computeReadingTargetPx(\n direction: \"horizontal\" | \"vertical\",\n openTotalPx: number,\n openCount: number,\n): number {\n const minOpenPx = direction === \"horizontal\" ? HORIZONTAL_MIN_OPEN_PX : VERTICAL_MIN_OPEN_PX;\n const preferredReadingPx =\n direction === \"horizontal\" ? HORIZONTAL_READING_OPEN_PX : VERTICAL_READING_OPEN_PX;\n const equalSharePx = Math.floor(openTotalPx / Math.max(1, openCount));\n return Math.max(minOpenPx + 24, Math.min(preferredReadingPx, equalSharePx));\n}\n\nexport function findPanelPath<Id extends string>(\n node: WorkspaceLayoutNode<Id> | null | undefined,\n id: Id,\n): number[] | null {\n if (!node) return null;\n if (node.type === \"panel\") return node.id === id ? [] : null;\n for (let i = 0; i < node.children.length; i += 1) {\n const subPath = findPanelPath(node.children[i], id);\n if (subPath !== null) return [i, ...subPath];\n }\n return null;\n}\n\nexport function getResponsiveCompactAxis(\n widthPx: number,\n heightPx: number,\n): \"horizontal\" | \"vertical\" | null {\n if (widthPx < HORIZONTAL_MIN_OPEN_PX) return \"horizontal\";\n if (heightPx < VERTICAL_MIN_OPEN_PX) return \"vertical\";\n return null;\n}\n\nexport function getPanelIds<Id extends string>(\n tree: WorkspaceLayoutNode<Id> | null | undefined,\n): Id[] {\n if (!tree) return [];\n if (tree.type === \"panel\") return [tree.id];\n return tree.children.flatMap((child) => getPanelIds(child));\n}\n\nexport function isNodeFolded<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n folds: Partial<Record<Id, FoldState>>,\n): boolean {\n if (node.type === \"panel\") {\n return (folds[node.id] ?? \"open\") === \"folded\";\n }\n return node.children.length > 0 && node.children.every((child) => isNodeFolded(child, folds));\n}\n\nexport function setNodeFoldState<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n folds: Partial<Record<Id, FoldState>>,\n state: FoldState,\n): Partial<Record<Id, FoldState>> {\n const ids = getPanelIds(node);\n if (ids.length === 0) return folds;\n let changed = false;\n for (const id of ids) {\n if ((folds[id] ?? \"open\") !== state) {\n changed = true;\n break;\n }\n }\n if (!changed) return folds;\n const next: Partial<Record<Id, FoldState>> = { ...folds };\n for (const id of ids) {\n next[id] = state;\n }\n return next;\n}\n\nexport function normalizeLayoutTree<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n): WorkspaceLayoutNode<Id> {\n if (node.type === \"panel\") return node;\n\n const rawSizes = node.children.map((_, index) => node.sizes?.[index] ?? 1);\n const nextChildren: WorkspaceLayoutNode<Id>[] = [];\n const nextSizes: number[] = [];\n let hasExplicitSizes = Boolean(node.sizes);\n\n for (let i = 0; i < node.children.length; i += 1) {\n const normalizedChild = normalizeLayoutTree(node.children[i]);\n const weight = rawSizes[i];\n\n if (normalizedChild.type === \"split\" && normalizedChild.direction === node.direction) {\n const childSizes = normalizedChild.children.map(\n (_, childIdx) => normalizedChild.sizes?.[childIdx] ?? 1,\n );\n const childTotal = childSizes.reduce((acc, value) => acc + value, 0) || 1;\n for (let j = 0; j < normalizedChild.children.length; j += 1) {\n nextChildren.push(normalizedChild.children[j]);\n nextSizes.push(weight * (childSizes[j] / childTotal));\n }\n if (normalizedChild.sizes) hasExplicitSizes = true;\n } else {\n nextChildren.push(normalizedChild);\n nextSizes.push(weight);\n }\n }\n\n if (nextChildren.length === 1) return nextChildren[0];\n return hasExplicitSizes\n ? { type: \"split\", direction: node.direction, children: nextChildren, sizes: nextSizes }\n : { type: \"split\", direction: node.direction, children: nextChildren };\n}\n\nexport function validateLayoutTree<Id extends string>(\n value: unknown,\n knownIds: ReadonlySet<Id>,\n): value is WorkspaceLayoutNode<Id> {\n const seen = new Set<Id>();\n function visit(node: unknown, splitDepthCount: number): boolean {\n if (!node || typeof node !== \"object\") return false;\n const candidate = node as Record<string, unknown>;\n if (candidate.type === \"panel\") {\n if (typeof candidate.id !== \"string\" || !knownIds.has(candidate.id as Id)) return false;\n const id = candidate.id as Id;\n if (seen.has(id)) return false;\n seen.add(id);\n return true;\n }\n if (\n candidate.type !== \"split\" ||\n (candidate.direction !== \"horizontal\" && candidate.direction !== \"vertical\") ||\n !Array.isArray(candidate.children) ||\n candidate.children.length < 2 ||\n splitDepthCount >= MAX_WORKSPACE_SPLIT_DEPTH\n ) {\n return false;\n }\n if (\n candidate.sizes !== undefined &&\n (!Array.isArray(candidate.sizes) ||\n candidate.sizes.length !== candidate.children.length ||\n candidate.sizes.some(\n (size) => typeof size !== \"number\" || !Number.isFinite(size) || size <= 0,\n ))\n ) {\n return false;\n }\n return candidate.children.every((child) => visit(child, splitDepthCount + 1));\n }\n return visit(value, 0);\n}\n\nexport function createHorizontalTree<Id extends string>(\n ids: Id[],\n): WorkspaceLayoutNode<Id> | null {\n if (ids.length === 0) return null;\n const children = ids.map((id) => ({ type: \"panel\" as const, id }));\n return children.length === 1\n ? children[0]\n : { type: \"split\", direction: \"horizontal\", children };\n}\n\nexport function instantiateLayoutTemplate<Id extends string>(\n template: WorkspaceLayoutTemplate,\n ids: Id[],\n): WorkspaceLayoutNode<Id> | null {\n if (template.type === \"panel\") {\n const id = ids[template.index];\n return id === undefined ? null : { type: \"panel\", id };\n }\n const children = template.children\n .map((child) => instantiateLayoutTemplate(child, ids))\n .filter((child): child is WorkspaceLayoutNode<Id> => child !== null);\n if (children.length === 0) return null;\n if (children.length === 1) return children[0];\n return normalizeLayoutTree({ type: \"split\", direction: template.direction, children });\n}\n\nexport function layoutTemplateSignature(template: WorkspaceLayoutTemplate): string {\n if (template.type === \"panel\") return \"p\";\n return `${template.direction === \"horizontal\" ? \"h\" : \"v\"}(${template.children\n .map(layoutTemplateSignature)\n .join(\",\")})`;\n}\n\nexport function layoutTreeSignature<Id extends string>(\n tree: WorkspaceLayoutNode<Id>,\n): string {\n if (tree.type === \"panel\") return \"p\";\n return `${tree.direction === \"horizontal\" ? \"h\" : \"v\"}(${tree.children\n .map(layoutTreeSignature)\n .join(\",\")})`;\n}\n\nexport function removePanel<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n id: Id,\n): WorkspaceLayoutNode<Id> | null {\n if (node.type === \"panel\") return node.id === id ? null : node;\n const nextChildren: WorkspaceLayoutNode<Id>[] = [];\n const nextSizes: number[] = [];\n for (let i = 0; i < node.children.length; i += 1) {\n const child = removePanel(node.children[i], id);\n if (child !== null) {\n nextChildren.push(child);\n nextSizes.push(node.sizes?.[i] ?? 1);\n }\n }\n if (nextChildren.length === 0) return null;\n if (nextChildren.length === 1) return nextChildren[0];\n return normalizeLayoutTree({\n ...node,\n children: nextChildren,\n sizes: node.sizes ? nextSizes : undefined,\n });\n}\n\nexport function insertAtPanel<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n targetId: Id,\n inserted: WorkspaceLayoutNode<Id>,\n): WorkspaceLayoutNode<Id> {\n if (node.type === \"panel\") {\n return node.id === targetId ? inserted : node;\n }\n return normalizeLayoutTree({\n ...node,\n children: node.children.map((child) => insertAtPanel(child, targetId, inserted)),\n sizes: node.sizes,\n });\n}\n\nexport function insertBesidePanel<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n targetId: Id,\n sourceId: Id,\n position: \"left\" | \"right\" | \"top\" | \"bottom\",\n): WorkspaceLayoutNode<Id> {\n if (node.type === \"panel\") {\n if (node.id !== targetId) return node;\n const source: WorkspaceLayoutNode<Id> = { type: \"panel\", id: sourceId };\n const horizontal = position === \"left\" || position === \"right\";\n const children =\n position === \"left\" || position === \"top\" ? [source, node] : [node, source];\n return {\n type: \"split\",\n direction: horizontal ? \"horizontal\" : \"vertical\",\n children,\n };\n }\n return normalizeLayoutTree({\n ...node,\n children: node.children.map((child) =>\n insertBesidePanel(child, targetId, sourceId, position),\n ),\n sizes: node.sizes,\n });\n}\n\nexport function movePanelInTree<Id extends string>(\n tree: WorkspaceLayoutNode<Id> | null | undefined,\n sourceId: Id,\n targetId: Id,\n position: \"left\" | \"right\" | \"top\" | \"bottom\",\n knownIds: ReadonlySet<Id>,\n): WorkspaceLayoutNode<Id> | null {\n if (!tree || sourceId === targetId) return null;\n const stripped = removePanel(tree, sourceId);\n if (!stripped) {\n return { type: \"panel\", id: sourceId };\n }\n const candidate = insertBesidePanel(stripped, targetId, sourceId, position);\n if (splitDepth(candidate) > MAX_WORKSPACE_SPLIT_DEPTH || !validateLayoutTree(candidate, knownIds)) {\n return null;\n }\n return candidate;\n}\n\nexport function getSplitAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n): WorkspaceLayoutNode<Id> | null {\n let current = node;\n for (const index of path) {\n if (current.type !== \"split\" || !current.children[index]) return null;\n current = current.children[index];\n }\n return current;\n}\n\nexport function resizeSplitAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n index: number,\n firstSize: number,\n secondSize: number,\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\") return node;\n const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);\n if (index < 0 || index + 1 >= sizes.length) return node;\n const pairTotal = sizes[index] + sizes[index + 1];\n const measuredTotal = Math.max(1, firstSize + secondSize);\n sizes[index] = Math.max(0.05, pairTotal * (firstSize / measuredTotal));\n sizes[index + 1] = Math.max(0.05, pairTotal * (secondSize / measuredTotal));\n return { ...node, sizes };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head\n ? resizeSplitAtPath(child, tail, index, firstSize, secondSize)\n : child,\n ),\n };\n}\n\nexport function setSplitChildWeightsAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n weights: readonly number[],\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\" || weights.length !== node.children.length) return node;\n return { ...node, sizes: weights.map((weight) => Math.max(0.05, weight)) };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head ? setSplitChildWeightsAtPath(child, tail, weights) : child,\n ),\n };\n}\n\nexport function growSplitChildWeightsToMinimum(\n weights: readonly number[],\n sizesPx: readonly number[],\n foldedChildren: readonly boolean[],\n targetIndex: number,\n minimumTargetPx: number,\n minimumDonorPx = minimumTargetPx,\n): number[] | null {\n if (\n weights.length !== sizesPx.length ||\n sizesPx.length !== foldedChildren.length ||\n targetIndex < 0 ||\n targetIndex >= sizesPx.length ||\n foldedChildren[targetIndex]\n ) {\n return null;\n }\n\n const neededPx = minimumTargetPx - sizesPx[targetIndex];\n if (neededPx <= 0) return null;\n\n const desiredSizes = [...sizesPx];\n const donors = sizesPx\n .map((size, index) => ({\n index,\n spare: !foldedChildren[index] && index !== targetIndex\n ? Math.max(0, size - minimumDonorPx)\n : 0,\n }))\n .filter((donor) => donor.spare > 0)\n .sort((a, b) => b.spare - a.spare);\n\n let remainingPx = neededPx;\n for (const donor of donors) {\n const contribution = Math.min(remainingPx, donor.spare);\n desiredSizes[donor.index] -= contribution;\n remainingPx -= contribution;\n if (remainingPx <= 0) break;\n }\n\n const transferredPx = neededPx - remainingPx;\n if (transferredPx <= 0) return null;\n desiredSizes[targetIndex] += transferredPx;\n\n const openWeightTotal = weights.reduce(\n (total, weight, index) => total + (foldedChildren[index] ? 0 : weight),\n 0,\n );\n const openSizeTotal = sizesPx.reduce(\n (total, size, index) => total + (foldedChildren[index] ? 0 : size),\n 0,\n );\n if (openWeightTotal <= 0 || openSizeTotal <= 0) return null;\n\n const weightPerPixel = openWeightTotal / openSizeTotal;\n return weights.map((weight, index) =>\n foldedChildren[index] ? weight : desiredSizes[index] * weightPerPixel,\n );\n}\n\nexport function growChildWeightsWithFallback(\n weights: readonly number[],\n sizesPx: readonly number[],\n foldedChildren: readonly boolean[],\n targetIndex: number,\n desiredTargetPx: number,\n preferredDonorFloorPx: number,\n fallbackDonorFloorPx: number,\n): number[] | null {\n return (\n growSplitChildWeightsToMinimum(\n weights,\n sizesPx,\n foldedChildren,\n targetIndex,\n desiredTargetPx,\n preferredDonorFloorPx,\n ) ??\n growSplitChildWeightsToMinimum(\n weights,\n sizesPx,\n foldedChildren,\n targetIndex,\n desiredTargetPx,\n fallbackDonorFloorPx,\n )\n );\n}\n\nexport function equalizeSplitAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n index: number,\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\") return node;\n const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);\n if (index < 0 || index + 1 >= sizes.length) return node;\n const avg = (sizes[index] + sizes[index + 1]) / 2;\n sizes[index] = avg;\n sizes[index + 1] = avg;\n return { ...node, sizes };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head ? equalizeSplitAtPath(child, tail, index) : child,\n ),\n };\n}\n\nexport function setSplitPairWeightsAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n index: number,\n firstWeight: number,\n secondWeight: number,\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\") return node;\n const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);\n if (index < 0 || index + 1 >= sizes.length) return node;\n sizes[index] = Math.max(0.15, firstWeight);\n sizes[index + 1] = Math.max(0.15, secondWeight);\n return { ...node, sizes };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head\n ? setSplitPairWeightsAtPath(child, tail, index, firstWeight, secondWeight)\n : child,\n ),\n };\n}\n\nexport type ComputeResizeStepParams<Id extends string> = {\n tree: WorkspaceLayoutNode<Id>;\n folds: Partial<Record<Id, FoldState>>;\n path: number[];\n index: number;\n direction: \"horizontal\" | \"vertical\";\n startFirstPx: number;\n startSecondPx: number;\n deltaPx: number;\n};\n\nexport type ComputeResizeStepResult<Id extends string> = {\n tree: WorkspaceLayoutNode<Id>;\n folds: Partial<Record<Id, FoldState>>;\n nearFoldSide: \"first\" | \"second\" | null;\n snappedSide: \"first\" | \"second\" | null;\n};\n\n/**\n * Computes the next split tree and fold map for a single divider drag frame.\n * Supports recursive subtrees (folding all panels inside a nested column/row),\n * hysteresis when dragging a folded panel back open, and preserves the fold-point\n * proportions so unaffected siblings do not jump when a panel folds.\n */\nexport function computeResizeStep<Id extends string>({\n tree,\n folds,\n path,\n index,\n direction,\n startFirstPx,\n startSecondPx,\n deltaPx,\n}: ComputeResizeStepParams<Id>): ComputeResizeStepResult<Id> {\n const split = getSplitAtPath(tree, path);\n if (!split || split.type !== \"split\") {\n return { tree, folds, nearFoldSide: null, snappedSide: null };\n }\n const first = split.children[index];\n const second = split.children[index + 1];\n if (!first || !second) {\n return { tree, folds, nearFoldSide: null, snappedSide: null };\n }\n\n const snapThreshold =\n direction === \"horizontal\" ? HORIZONTAL_FOLD_SNAP_PX : VERTICAL_FOLD_SNAP_PX;\n const unfoldThreshold =\n direction === \"horizontal\" ? HORIZONTAL_UNFOLD_THRESHOLD_PX : VERTICAL_UNFOLD_THRESHOLD_PX;\n const minOpenPx = direction === \"horizontal\" ? HORIZONTAL_MIN_OPEN_PX : VERTICAL_MIN_OPEN_PX;\n\n const totalPx = Math.max(1, startFirstPx + startSecondPx);\n const rawFirstPx = startFirstPx + deltaPx;\n const rawSecondPx = totalPx - rawFirstPx;\n\n const firstFolded = isNodeFolded(first, folds);\n const secondFolded = isNodeFolded(second, folds);\n const pairFirstWeight = split.sizes?.[index] ?? 1;\n const pairSecondWeight = split.sizes?.[index + 1] ?? 1;\n const pairTotalWeight = pairFirstWeight + pairSecondWeight;\n const foldedSizePx =\n direction === \"horizontal\" ? HORIZONTAL_FOLDED_RAIL_PX : VERTICAL_FOLDED_BAR_PX;\n\n const foldChild = (side: \"first\" | \"second\"): ComputeResizeStepResult<Id> => {\n const foldedChild = side === \"first\" ? first : second;\n const nextFolds = setNodeFoldState(foldedChild, folds, \"folded\");\n const safeFirstPx = Math.max(0, Math.min(totalPx, rawFirstPx));\n const safeSecondPx = totalPx - safeFirstPx;\n const foldedWeight =\n pairTotalWeight * ((side === \"first\" ? safeFirstPx : safeSecondPx) / totalPx);\n const expandedNeighborWeight = pairTotalWeight * ((totalPx - foldedSizePx) / totalPx);\n\n return {\n tree: setSplitPairWeightsAtPath(\n tree,\n path,\n index,\n side === \"first\" ? foldedWeight : expandedNeighborWeight,\n side === \"second\" ? foldedWeight : expandedNeighborWeight,\n ),\n folds: nextFolds,\n nearFoldSide: null,\n snappedSide: side,\n };\n };\n\n // Check both sides before snapping either one: both siblings may be folded.\n const unfoldChild = (side: \"first\" | \"second\"): ComputeResizeStepResult<Id> => {\n const targetChild = side === \"first\" ? first : second;\n const nextFolds = setNodeFoldState(targetChild, folds, \"open\");\n if (firstFolded && secondFolded && pairTotalWeight < 1) {\n // Both siblings were previously snap-folded to tiny weights; give the newly\n // unfolded child a full unit weight while keeping the still-folded sibling small.\n const unfoldedWeight = Math.max(1, pairTotalWeight);\n const stillFoldedWeight = side === \"first\" ? pairSecondWeight : pairFirstWeight;\n return {\n tree: setSplitPairWeightsAtPath(\n tree,\n path,\n index,\n side === \"first\" ? unfoldedWeight : stillFoldedWeight,\n side === \"second\" ? unfoldedWeight : stillFoldedWeight,\n ),\n folds: nextFolds,\n nearFoldSide: null,\n snappedSide: null,\n };\n }\n const openTarget = Math.max(minOpenPx, side === \"first\" ? rawFirstPx : rawSecondPx);\n const openSibling = Math.max(minOpenPx, totalPx - openTarget);\n return {\n tree: resizeSplitAtPath(\n tree,\n path,\n index,\n side === \"first\" ? openTarget : openSibling,\n side === \"second\" ? openTarget : openSibling,\n ),\n folds: nextFolds,\n nearFoldSide: null,\n snappedSide: null,\n };\n };\n\n if (firstFolded && rawFirstPx >= unfoldThreshold) {\n return unfoldChild(\"first\");\n }\n\n if (secondFolded && rawSecondPx >= unfoldThreshold) {\n return unfoldChild(\"second\");\n }\n\n if (firstFolded) {\n return { tree, folds, nearFoldSide: null, snappedSide: \"first\" };\n }\n if (secondFolded) {\n return { tree, folds, nearFoldSide: null, snappedSide: \"second\" };\n }\n\n // Both children are open: check snap-fold thresholds (works for leaf panels AND nested splits!)\n if (rawFirstPx <= snapThreshold && totalPx > snapThreshold * 1.6) {\n return foldChild(\"first\");\n }\n\n if (rawSecondPx <= snapThreshold && totalPx > snapThreshold * 1.6) {\n return foldChild(\"second\");\n }\n\n // Normal live resize while open. When totalPx is too narrow for both children to\n // stay above snapThreshold + 4, scale the minimum clamp so resizing doesn't lock at 50/50.\n const minClampPx = Math.min(snapThreshold + 4, Math.max(1, Math.floor(totalPx * 0.25)));\n const clampedFirst = Math.max(minClampPx, Math.min(totalPx - minClampPx, rawFirstPx));\n const clampedSecond = Math.max(minClampPx, totalPx - clampedFirst);\n\n let nearFoldSide: \"first\" | \"second\" | null = null;\n if (totalPx > snapThreshold * 1.6) {\n if (rawFirstPx <= snapThreshold + FOLD_APPROACH_MARGIN_PX) {\n nearFoldSide = \"first\";\n } else if (rawSecondPx <= snapThreshold + FOLD_APPROACH_MARGIN_PX) {\n nearFoldSide = \"second\";\n }\n }\n\n return {\n tree: resizeSplitAtPath(tree, path, index, clampedFirst, clampedSecond),\n folds,\n nearFoldSide,\n snappedSide: null,\n };\n}\n\nexport function computeKeyboardResizeStep<Id extends string>({\n tree,\n folds,\n path,\n index,\n deltaRatio,\n}: {\n tree: WorkspaceLayoutNode<Id>;\n folds: Partial<Record<Id, FoldState>>;\n path: number[];\n index: number;\n deltaRatio: number;\n}): { tree: WorkspaceLayoutNode<Id>; folds: Partial<Record<Id, FoldState>> } {\n const split = getSplitAtPath(tree, path);\n if (!split || split.type !== \"split\") return { tree, folds };\n const first = split.children[index];\n const second = split.children[index + 1];\n if (!first || !second) return { tree, folds };\n\n const firstFolded = isNodeFolded(first, folds);\n const secondFolded = isNodeFolded(second, folds);\n const sizes = split.children.map((_, i) => split.sizes?.[i] ?? 1);\n const firstWeight = sizes[index] ?? 1;\n const secondWeight = sizes[index + 1] ?? 1;\n const total = firstWeight + secondWeight;\n\n if (firstFolded) {\n if (deltaRatio <= 0) return { tree, folds };\n const nextFolds = setNodeFoldState(first, folds, \"open\");\n const nextFirst = Math.max(total * 0.25, firstWeight);\n const nextSecond = Math.max(0.15, secondFolded ? secondWeight : total - nextFirst);\n return {\n tree: setSplitPairWeightsAtPath(tree, path, index, nextFirst, nextSecond),\n folds: nextFolds,\n };\n }\n\n if (secondFolded) {\n if (deltaRatio >= 0) return { tree, folds };\n const nextFolds = setNodeFoldState(second, folds, \"open\");\n const nextSecond = Math.max(total * 0.25, secondWeight);\n const nextFirst = Math.max(0.15, total - nextSecond);\n return {\n tree: setSplitPairWeightsAtPath(tree, path, index, nextFirst, nextSecond),\n folds: nextFolds,\n };\n }\n\n const nextFirst = Math.max(total * 0.15, Math.min(total * 0.85, firstWeight + total * deltaRatio));\n const nextSecond = total - nextFirst;\n return {\n tree: resizeSplitAtPath(tree, path, index, nextFirst, nextSecond),\n folds,\n };\n}\n\nexport function splitDepth<Id extends string>(node: WorkspaceLayoutNode<Id>): number {\n if (node.type === \"panel\") return 0;\n return 1 + Math.max(...node.children.map(splitDepth));\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { DEFAULT_WORKSPACE_SHORTCUTS, WorkspaceShortcutDefinition } from "./shortcuts.cjs";
|
|
3
|
+
/** Any React icon component accepting `className` and `aria-hidden` (Lucide, React Icons, Heroicons, or inline SVG). */
|
|
4
|
+
type WorkspaceIcon = ComponentType<{
|
|
5
|
+
className?: string;
|
|
6
|
+
"aria-hidden"?: boolean | "true" | "false";
|
|
7
|
+
}>;
|
|
8
|
+
type FoldState = "open" | "folded";
|
|
9
|
+
type DropPosition = "left" | "right" | "top" | "bottom";
|
|
10
|
+
type WorkspaceLayoutNode<Id extends string = string> = {
|
|
11
|
+
type: "panel";
|
|
12
|
+
id: Id;
|
|
13
|
+
} | {
|
|
14
|
+
type: "split";
|
|
15
|
+
direction: "horizontal" | "vertical";
|
|
16
|
+
children: WorkspaceLayoutNode<Id>[];
|
|
17
|
+
/** Relative child sizes. Omitted values distribute space evenly. */
|
|
18
|
+
sizes?: number[];
|
|
19
|
+
};
|
|
20
|
+
/** Preset leaves reference panels by their zero-based position in the active panel order. */
|
|
21
|
+
type WorkspaceLayoutTemplate = {
|
|
22
|
+
type: "panel";
|
|
23
|
+
index: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: "split";
|
|
26
|
+
direction: "horizontal" | "vertical";
|
|
27
|
+
children: WorkspaceLayoutTemplate[];
|
|
28
|
+
};
|
|
29
|
+
type WorkspacePanelDef<Id extends string = string> = {
|
|
30
|
+
id: Id;
|
|
31
|
+
title: string;
|
|
32
|
+
shortTitle?: string;
|
|
33
|
+
icon: ReactNode;
|
|
34
|
+
defaultOpen?: boolean;
|
|
35
|
+
content: ReactNode;
|
|
36
|
+
};
|
|
37
|
+
type WorkspaceLayoutState<Id extends string = string> = {
|
|
38
|
+
tree: WorkspaceLayoutNode<Id> | null;
|
|
39
|
+
folds: Partial<Record<Id, FoldState>>;
|
|
40
|
+
maximizedId: Id | null;
|
|
41
|
+
};
|
|
42
|
+
type WorkspaceCommands<Id extends string = string> = {
|
|
43
|
+
focusPanel: (id: Id) => void;
|
|
44
|
+
getFocusedPanelId: () => Id | null;
|
|
45
|
+
toggleFold: (id?: Id) => void;
|
|
46
|
+
toggleMaximize: (id?: Id) => void;
|
|
47
|
+
minimizePanel: (id?: Id) => void;
|
|
48
|
+
restorePanel: (id: Id) => void;
|
|
49
|
+
resetLayout: () => void;
|
|
50
|
+
};
|
|
51
|
+
type LayoutPreset = {
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
layout: WorkspaceLayoutTemplate;
|
|
55
|
+
};
|
|
56
|
+
type TooltipRenderProps = {
|
|
57
|
+
label: string;
|
|
58
|
+
shortcut?: string[];
|
|
59
|
+
side?: "top" | "bottom" | "left" | "right";
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
};
|
|
62
|
+
type RenderTooltip = (props: TooltipRenderProps) => ReactNode;
|
|
63
|
+
export declare const MAX_WORKSPACE_SPLIT_DEPTH = 4;
|
|
64
|
+
export declare function getPanelIds<Id extends string>(tree: WorkspaceLayoutNode<Id> | null | undefined): Id[];
|
|
65
|
+
export declare function isNodeFolded<Id extends string>(node: WorkspaceLayoutNode<Id>, folds: Partial<Record<Id, FoldState>>): boolean;
|
|
66
|
+
export declare function normalizeLayoutTree<Id extends string>(node: WorkspaceLayoutNode<Id>): WorkspaceLayoutNode<Id>;
|
|
67
|
+
export declare function validateLayoutTree<Id extends string>(value: unknown, knownIds: ReadonlySet<Id>): value is WorkspaceLayoutNode<Id>;
|
|
68
|
+
export declare function layoutTemplateSignature(template: WorkspaceLayoutTemplate): string;
|
|
69
|
+
export declare function layoutTreeSignature<Id extends string>(tree: WorkspaceLayoutNode<Id>): string;
|
|
70
|
+
export declare function equalizeSplitAtPath<Id extends string>(node: WorkspaceLayoutNode<Id>, path: number[], index: number): WorkspaceLayoutNode<Id>;
|
|
71
|
+
export { DEFAULT_WORKSPACE_SHORTCUTS, type DropPosition, type FoldState, type LayoutPreset, type RenderTooltip, type TooltipRenderProps, type WorkspaceCommands, type WorkspaceIcon, type WorkspaceLayoutNode, type WorkspaceLayoutState, type WorkspaceLayoutTemplate, type WorkspacePanelDef, type WorkspaceShortcutDefinition };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { DEFAULT_WORKSPACE_SHORTCUTS, WorkspaceShortcutDefinition } from "./shortcuts.mjs";
|
|
3
|
+
/** Any React icon component accepting `className` and `aria-hidden` (Lucide, React Icons, Heroicons, or inline SVG). */
|
|
4
|
+
type WorkspaceIcon = ComponentType<{
|
|
5
|
+
className?: string;
|
|
6
|
+
"aria-hidden"?: boolean | "true" | "false";
|
|
7
|
+
}>;
|
|
8
|
+
type FoldState = "open" | "folded";
|
|
9
|
+
type DropPosition = "left" | "right" | "top" | "bottom";
|
|
10
|
+
type WorkspaceLayoutNode<Id extends string = string> = {
|
|
11
|
+
type: "panel";
|
|
12
|
+
id: Id;
|
|
13
|
+
} | {
|
|
14
|
+
type: "split";
|
|
15
|
+
direction: "horizontal" | "vertical";
|
|
16
|
+
children: WorkspaceLayoutNode<Id>[];
|
|
17
|
+
/** Relative child sizes. Omitted values distribute space evenly. */
|
|
18
|
+
sizes?: number[];
|
|
19
|
+
};
|
|
20
|
+
/** Preset leaves reference panels by their zero-based position in the active panel order. */
|
|
21
|
+
type WorkspaceLayoutTemplate = {
|
|
22
|
+
type: "panel";
|
|
23
|
+
index: number;
|
|
24
|
+
} | {
|
|
25
|
+
type: "split";
|
|
26
|
+
direction: "horizontal" | "vertical";
|
|
27
|
+
children: WorkspaceLayoutTemplate[];
|
|
28
|
+
};
|
|
29
|
+
type WorkspacePanelDef<Id extends string = string> = {
|
|
30
|
+
id: Id;
|
|
31
|
+
title: string;
|
|
32
|
+
shortTitle?: string;
|
|
33
|
+
icon: ReactNode;
|
|
34
|
+
defaultOpen?: boolean;
|
|
35
|
+
content: ReactNode;
|
|
36
|
+
};
|
|
37
|
+
type WorkspaceLayoutState<Id extends string = string> = {
|
|
38
|
+
tree: WorkspaceLayoutNode<Id> | null;
|
|
39
|
+
folds: Partial<Record<Id, FoldState>>;
|
|
40
|
+
maximizedId: Id | null;
|
|
41
|
+
};
|
|
42
|
+
type WorkspaceCommands<Id extends string = string> = {
|
|
43
|
+
focusPanel: (id: Id) => void;
|
|
44
|
+
getFocusedPanelId: () => Id | null;
|
|
45
|
+
toggleFold: (id?: Id) => void;
|
|
46
|
+
toggleMaximize: (id?: Id) => void;
|
|
47
|
+
minimizePanel: (id?: Id) => void;
|
|
48
|
+
restorePanel: (id: Id) => void;
|
|
49
|
+
resetLayout: () => void;
|
|
50
|
+
};
|
|
51
|
+
type LayoutPreset = {
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
layout: WorkspaceLayoutTemplate;
|
|
55
|
+
};
|
|
56
|
+
type TooltipRenderProps = {
|
|
57
|
+
label: string;
|
|
58
|
+
shortcut?: string[];
|
|
59
|
+
side?: "top" | "bottom" | "left" | "right";
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
};
|
|
62
|
+
type RenderTooltip = (props: TooltipRenderProps) => ReactNode;
|
|
63
|
+
export declare const MAX_WORKSPACE_SPLIT_DEPTH = 4;
|
|
64
|
+
export declare function getPanelIds<Id extends string>(tree: WorkspaceLayoutNode<Id> | null | undefined): Id[];
|
|
65
|
+
export declare function isNodeFolded<Id extends string>(node: WorkspaceLayoutNode<Id>, folds: Partial<Record<Id, FoldState>>): boolean;
|
|
66
|
+
export declare function normalizeLayoutTree<Id extends string>(node: WorkspaceLayoutNode<Id>): WorkspaceLayoutNode<Id>;
|
|
67
|
+
export declare function validateLayoutTree<Id extends string>(value: unknown, knownIds: ReadonlySet<Id>): value is WorkspaceLayoutNode<Id>;
|
|
68
|
+
export declare function layoutTemplateSignature(template: WorkspaceLayoutTemplate): string;
|
|
69
|
+
export declare function layoutTreeSignature<Id extends string>(tree: WorkspaceLayoutNode<Id>): string;
|
|
70
|
+
export declare function equalizeSplitAtPath<Id extends string>(node: WorkspaceLayoutNode<Id>, path: number[], index: number): WorkspaceLayoutNode<Id>;
|
|
71
|
+
export { DEFAULT_WORKSPACE_SHORTCUTS, type DropPosition, type FoldState, type LayoutPreset, type RenderTooltip, type TooltipRenderProps, type WorkspaceCommands, type WorkspaceIcon, type WorkspaceLayoutNode, type WorkspaceLayoutState, type WorkspaceLayoutTemplate, type WorkspacePanelDef, type WorkspaceShortcutDefinition };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DEFAULT_WORKSPACE_SHORTCUTS } from "./shortcuts.mjs";
|
|
2
|
+
// src/layout.ts
|
|
3
|
+
const MAX_WORKSPACE_SPLIT_DEPTH = 4;
|
|
4
|
+
function getPanelIds(tree) {
|
|
5
|
+
if (!tree) return [];
|
|
6
|
+
if (tree.type === "panel") return [tree.id];
|
|
7
|
+
return tree.children.flatMap((child) => getPanelIds(child));
|
|
8
|
+
}
|
|
9
|
+
function isNodeFolded(node, folds) {
|
|
10
|
+
if (node.type === "panel") return (folds[node.id] ?? "open") === "folded";
|
|
11
|
+
return node.children.length > 0 && node.children.every((child) => isNodeFolded(child, folds));
|
|
12
|
+
}
|
|
13
|
+
function normalizeLayoutTree(node) {
|
|
14
|
+
if (node.type === "panel") return node;
|
|
15
|
+
const rawSizes = node.children.map((_, index) => node.sizes?.[index] ?? 1);
|
|
16
|
+
const nextChildren = [];
|
|
17
|
+
const nextSizes = [];
|
|
18
|
+
let hasExplicitSizes = Boolean(node.sizes);
|
|
19
|
+
for (let i = 0; i < node.children.length; i += 1) {
|
|
20
|
+
const normalizedChild = normalizeLayoutTree(node.children[i]);
|
|
21
|
+
const weight = rawSizes[i];
|
|
22
|
+
if (normalizedChild.type === "split" && normalizedChild.direction === node.direction) {
|
|
23
|
+
const childSizes = normalizedChild.children.map((_, childIdx) => normalizedChild.sizes?.[childIdx] ?? 1);
|
|
24
|
+
const childTotal = childSizes.reduce((acc, value) => acc + value, 0) || 1;
|
|
25
|
+
for (let j = 0; j < normalizedChild.children.length; j += 1) {
|
|
26
|
+
nextChildren.push(normalizedChild.children[j]);
|
|
27
|
+
nextSizes.push(weight * (childSizes[j] / childTotal));
|
|
28
|
+
}
|
|
29
|
+
if (normalizedChild.sizes) hasExplicitSizes = true;
|
|
30
|
+
} else {
|
|
31
|
+
nextChildren.push(normalizedChild);
|
|
32
|
+
nextSizes.push(weight);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (nextChildren.length === 1) return nextChildren[0];
|
|
36
|
+
return hasExplicitSizes ? {
|
|
37
|
+
type: "split",
|
|
38
|
+
direction: node.direction,
|
|
39
|
+
children: nextChildren,
|
|
40
|
+
sizes: nextSizes
|
|
41
|
+
} : {
|
|
42
|
+
type: "split",
|
|
43
|
+
direction: node.direction,
|
|
44
|
+
children: nextChildren
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function validateLayoutTree(value, knownIds) {
|
|
48
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49
|
+
function visit(node, splitDepthCount) {
|
|
50
|
+
if (!node || typeof node !== "object") return false;
|
|
51
|
+
const candidate = node;
|
|
52
|
+
if (candidate.type === "panel") {
|
|
53
|
+
if (typeof candidate.id !== "string" || !knownIds.has(candidate.id)) return false;
|
|
54
|
+
const id = candidate.id;
|
|
55
|
+
if (seen.has(id)) return false;
|
|
56
|
+
seen.add(id);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (candidate.type !== "split" || candidate.direction !== "horizontal" && candidate.direction !== "vertical" || !Array.isArray(candidate.children) || candidate.children.length < 2 || splitDepthCount >= 4) return false;
|
|
60
|
+
if (candidate.sizes !== void 0 && (!Array.isArray(candidate.sizes) || candidate.sizes.length !== candidate.children.length || candidate.sizes.some((size) => typeof size !== "number" || !Number.isFinite(size) || size <= 0))) return false;
|
|
61
|
+
return candidate.children.every((child) => visit(child, splitDepthCount + 1));
|
|
62
|
+
}
|
|
63
|
+
return visit(value, 0);
|
|
64
|
+
}
|
|
65
|
+
function layoutTemplateSignature(template) {
|
|
66
|
+
if (template.type === "panel") return "p";
|
|
67
|
+
return `${template.direction === "horizontal" ? "h" : "v"}(${template.children.map(layoutTemplateSignature).join(",")})`;
|
|
68
|
+
}
|
|
69
|
+
function layoutTreeSignature(tree) {
|
|
70
|
+
if (tree.type === "panel") return "p";
|
|
71
|
+
return `${tree.direction === "horizontal" ? "h" : "v"}(${tree.children.map(layoutTreeSignature).join(",")})`;
|
|
72
|
+
}
|
|
73
|
+
function equalizeSplitAtPath(node, path, index) {
|
|
74
|
+
if (path.length === 0) {
|
|
75
|
+
if (node.type !== "split") return node;
|
|
76
|
+
const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);
|
|
77
|
+
if (index < 0 || index + 1 >= sizes.length) return node;
|
|
78
|
+
const avg = (sizes[index] + sizes[index + 1]) / 2;
|
|
79
|
+
sizes[index] = avg;
|
|
80
|
+
sizes[index + 1] = avg;
|
|
81
|
+
return {
|
|
82
|
+
...node,
|
|
83
|
+
sizes
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (node.type !== "split") return node;
|
|
87
|
+
const [head, ...tail] = path;
|
|
88
|
+
return {
|
|
89
|
+
...node,
|
|
90
|
+
children: node.children.map((child, childIndex) => childIndex === head ? equalizeSplitAtPath(child, tail, index) : child)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export { DEFAULT_WORKSPACE_SHORTCUTS, MAX_WORKSPACE_SPLIT_DEPTH, equalizeSplitAtPath, getPanelIds, isNodeFolded, layoutTemplateSignature, layoutTreeSignature, normalizeLayoutTree, validateLayoutTree };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","names":[],"sources":["../../src/layout.ts"],"sourcesContent":["import type {\n FoldState,\n WorkspaceLayoutNode,\n WorkspaceLayoutTemplate,\n} from \"./types\";\n\nexport const MAX_WORKSPACE_SPLIT_DEPTH = 4;\n\nexport const HORIZONTAL_FOLD_SNAP_PX = 96;\nexport const VERTICAL_FOLD_SNAP_PX = 76;\nexport const HORIZONTAL_FOLDED_RAIL_PX = 46;\nexport const VERTICAL_FOLDED_BAR_PX = 44;\nexport const HORIZONTAL_UNFOLD_THRESHOLD_PX = 128;\nexport const VERTICAL_UNFOLD_THRESHOLD_PX = 104;\nexport const HORIZONTAL_MIN_OPEN_PX = 120;\nexport const VERTICAL_MIN_OPEN_PX = 92;\nexport const HORIZONTAL_READING_OPEN_PX = 320;\nexport const VERTICAL_READING_OPEN_PX = 220;\nexport const FOLD_APPROACH_MARGIN_PX = 38;\n\nexport function computeReadingTargetPx(\n direction: \"horizontal\" | \"vertical\",\n openTotalPx: number,\n openCount: number,\n): number {\n const minOpenPx = direction === \"horizontal\" ? HORIZONTAL_MIN_OPEN_PX : VERTICAL_MIN_OPEN_PX;\n const preferredReadingPx =\n direction === \"horizontal\" ? HORIZONTAL_READING_OPEN_PX : VERTICAL_READING_OPEN_PX;\n const equalSharePx = Math.floor(openTotalPx / Math.max(1, openCount));\n return Math.max(minOpenPx + 24, Math.min(preferredReadingPx, equalSharePx));\n}\n\nexport function findPanelPath<Id extends string>(\n node: WorkspaceLayoutNode<Id> | null | undefined,\n id: Id,\n): number[] | null {\n if (!node) return null;\n if (node.type === \"panel\") return node.id === id ? [] : null;\n for (let i = 0; i < node.children.length; i += 1) {\n const subPath = findPanelPath(node.children[i], id);\n if (subPath !== null) return [i, ...subPath];\n }\n return null;\n}\n\nexport function getResponsiveCompactAxis(\n widthPx: number,\n heightPx: number,\n): \"horizontal\" | \"vertical\" | null {\n if (widthPx < HORIZONTAL_MIN_OPEN_PX) return \"horizontal\";\n if (heightPx < VERTICAL_MIN_OPEN_PX) return \"vertical\";\n return null;\n}\n\nexport function getPanelIds<Id extends string>(\n tree: WorkspaceLayoutNode<Id> | null | undefined,\n): Id[] {\n if (!tree) return [];\n if (tree.type === \"panel\") return [tree.id];\n return tree.children.flatMap((child) => getPanelIds(child));\n}\n\nexport function isNodeFolded<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n folds: Partial<Record<Id, FoldState>>,\n): boolean {\n if (node.type === \"panel\") {\n return (folds[node.id] ?? \"open\") === \"folded\";\n }\n return node.children.length > 0 && node.children.every((child) => isNodeFolded(child, folds));\n}\n\nexport function setNodeFoldState<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n folds: Partial<Record<Id, FoldState>>,\n state: FoldState,\n): Partial<Record<Id, FoldState>> {\n const ids = getPanelIds(node);\n if (ids.length === 0) return folds;\n let changed = false;\n for (const id of ids) {\n if ((folds[id] ?? \"open\") !== state) {\n changed = true;\n break;\n }\n }\n if (!changed) return folds;\n const next: Partial<Record<Id, FoldState>> = { ...folds };\n for (const id of ids) {\n next[id] = state;\n }\n return next;\n}\n\nexport function normalizeLayoutTree<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n): WorkspaceLayoutNode<Id> {\n if (node.type === \"panel\") return node;\n\n const rawSizes = node.children.map((_, index) => node.sizes?.[index] ?? 1);\n const nextChildren: WorkspaceLayoutNode<Id>[] = [];\n const nextSizes: number[] = [];\n let hasExplicitSizes = Boolean(node.sizes);\n\n for (let i = 0; i < node.children.length; i += 1) {\n const normalizedChild = normalizeLayoutTree(node.children[i]);\n const weight = rawSizes[i];\n\n if (normalizedChild.type === \"split\" && normalizedChild.direction === node.direction) {\n const childSizes = normalizedChild.children.map(\n (_, childIdx) => normalizedChild.sizes?.[childIdx] ?? 1,\n );\n const childTotal = childSizes.reduce((acc, value) => acc + value, 0) || 1;\n for (let j = 0; j < normalizedChild.children.length; j += 1) {\n nextChildren.push(normalizedChild.children[j]);\n nextSizes.push(weight * (childSizes[j] / childTotal));\n }\n if (normalizedChild.sizes) hasExplicitSizes = true;\n } else {\n nextChildren.push(normalizedChild);\n nextSizes.push(weight);\n }\n }\n\n if (nextChildren.length === 1) return nextChildren[0];\n return hasExplicitSizes\n ? { type: \"split\", direction: node.direction, children: nextChildren, sizes: nextSizes }\n : { type: \"split\", direction: node.direction, children: nextChildren };\n}\n\nexport function validateLayoutTree<Id extends string>(\n value: unknown,\n knownIds: ReadonlySet<Id>,\n): value is WorkspaceLayoutNode<Id> {\n const seen = new Set<Id>();\n function visit(node: unknown, splitDepthCount: number): boolean {\n if (!node || typeof node !== \"object\") return false;\n const candidate = node as Record<string, unknown>;\n if (candidate.type === \"panel\") {\n if (typeof candidate.id !== \"string\" || !knownIds.has(candidate.id as Id)) return false;\n const id = candidate.id as Id;\n if (seen.has(id)) return false;\n seen.add(id);\n return true;\n }\n if (\n candidate.type !== \"split\" ||\n (candidate.direction !== \"horizontal\" && candidate.direction !== \"vertical\") ||\n !Array.isArray(candidate.children) ||\n candidate.children.length < 2 ||\n splitDepthCount >= MAX_WORKSPACE_SPLIT_DEPTH\n ) {\n return false;\n }\n if (\n candidate.sizes !== undefined &&\n (!Array.isArray(candidate.sizes) ||\n candidate.sizes.length !== candidate.children.length ||\n candidate.sizes.some(\n (size) => typeof size !== \"number\" || !Number.isFinite(size) || size <= 0,\n ))\n ) {\n return false;\n }\n return candidate.children.every((child) => visit(child, splitDepthCount + 1));\n }\n return visit(value, 0);\n}\n\nexport function createHorizontalTree<Id extends string>(\n ids: Id[],\n): WorkspaceLayoutNode<Id> | null {\n if (ids.length === 0) return null;\n const children = ids.map((id) => ({ type: \"panel\" as const, id }));\n return children.length === 1\n ? children[0]\n : { type: \"split\", direction: \"horizontal\", children };\n}\n\nexport function instantiateLayoutTemplate<Id extends string>(\n template: WorkspaceLayoutTemplate,\n ids: Id[],\n): WorkspaceLayoutNode<Id> | null {\n if (template.type === \"panel\") {\n const id = ids[template.index];\n return id === undefined ? null : { type: \"panel\", id };\n }\n const children = template.children\n .map((child) => instantiateLayoutTemplate(child, ids))\n .filter((child): child is WorkspaceLayoutNode<Id> => child !== null);\n if (children.length === 0) return null;\n if (children.length === 1) return children[0];\n return normalizeLayoutTree({ type: \"split\", direction: template.direction, children });\n}\n\nexport function layoutTemplateSignature(template: WorkspaceLayoutTemplate): string {\n if (template.type === \"panel\") return \"p\";\n return `${template.direction === \"horizontal\" ? \"h\" : \"v\"}(${template.children\n .map(layoutTemplateSignature)\n .join(\",\")})`;\n}\n\nexport function layoutTreeSignature<Id extends string>(\n tree: WorkspaceLayoutNode<Id>,\n): string {\n if (tree.type === \"panel\") return \"p\";\n return `${tree.direction === \"horizontal\" ? \"h\" : \"v\"}(${tree.children\n .map(layoutTreeSignature)\n .join(\",\")})`;\n}\n\nexport function removePanel<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n id: Id,\n): WorkspaceLayoutNode<Id> | null {\n if (node.type === \"panel\") return node.id === id ? null : node;\n const nextChildren: WorkspaceLayoutNode<Id>[] = [];\n const nextSizes: number[] = [];\n for (let i = 0; i < node.children.length; i += 1) {\n const child = removePanel(node.children[i], id);\n if (child !== null) {\n nextChildren.push(child);\n nextSizes.push(node.sizes?.[i] ?? 1);\n }\n }\n if (nextChildren.length === 0) return null;\n if (nextChildren.length === 1) return nextChildren[0];\n return normalizeLayoutTree({\n ...node,\n children: nextChildren,\n sizes: node.sizes ? nextSizes : undefined,\n });\n}\n\nexport function insertAtPanel<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n targetId: Id,\n inserted: WorkspaceLayoutNode<Id>,\n): WorkspaceLayoutNode<Id> {\n if (node.type === \"panel\") {\n return node.id === targetId ? inserted : node;\n }\n return normalizeLayoutTree({\n ...node,\n children: node.children.map((child) => insertAtPanel(child, targetId, inserted)),\n sizes: node.sizes,\n });\n}\n\nexport function insertBesidePanel<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n targetId: Id,\n sourceId: Id,\n position: \"left\" | \"right\" | \"top\" | \"bottom\",\n): WorkspaceLayoutNode<Id> {\n if (node.type === \"panel\") {\n if (node.id !== targetId) return node;\n const source: WorkspaceLayoutNode<Id> = { type: \"panel\", id: sourceId };\n const horizontal = position === \"left\" || position === \"right\";\n const children =\n position === \"left\" || position === \"top\" ? [source, node] : [node, source];\n return {\n type: \"split\",\n direction: horizontal ? \"horizontal\" : \"vertical\",\n children,\n };\n }\n return normalizeLayoutTree({\n ...node,\n children: node.children.map((child) =>\n insertBesidePanel(child, targetId, sourceId, position),\n ),\n sizes: node.sizes,\n });\n}\n\nexport function movePanelInTree<Id extends string>(\n tree: WorkspaceLayoutNode<Id> | null | undefined,\n sourceId: Id,\n targetId: Id,\n position: \"left\" | \"right\" | \"top\" | \"bottom\",\n knownIds: ReadonlySet<Id>,\n): WorkspaceLayoutNode<Id> | null {\n if (!tree || sourceId === targetId) return null;\n const stripped = removePanel(tree, sourceId);\n if (!stripped) {\n return { type: \"panel\", id: sourceId };\n }\n const candidate = insertBesidePanel(stripped, targetId, sourceId, position);\n if (splitDepth(candidate) > MAX_WORKSPACE_SPLIT_DEPTH || !validateLayoutTree(candidate, knownIds)) {\n return null;\n }\n return candidate;\n}\n\nexport function getSplitAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n): WorkspaceLayoutNode<Id> | null {\n let current = node;\n for (const index of path) {\n if (current.type !== \"split\" || !current.children[index]) return null;\n current = current.children[index];\n }\n return current;\n}\n\nexport function resizeSplitAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n index: number,\n firstSize: number,\n secondSize: number,\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\") return node;\n const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);\n if (index < 0 || index + 1 >= sizes.length) return node;\n const pairTotal = sizes[index] + sizes[index + 1];\n const measuredTotal = Math.max(1, firstSize + secondSize);\n sizes[index] = Math.max(0.05, pairTotal * (firstSize / measuredTotal));\n sizes[index + 1] = Math.max(0.05, pairTotal * (secondSize / measuredTotal));\n return { ...node, sizes };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head\n ? resizeSplitAtPath(child, tail, index, firstSize, secondSize)\n : child,\n ),\n };\n}\n\nexport function setSplitChildWeightsAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n weights: readonly number[],\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\" || weights.length !== node.children.length) return node;\n return { ...node, sizes: weights.map((weight) => Math.max(0.05, weight)) };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head ? setSplitChildWeightsAtPath(child, tail, weights) : child,\n ),\n };\n}\n\nexport function growSplitChildWeightsToMinimum(\n weights: readonly number[],\n sizesPx: readonly number[],\n foldedChildren: readonly boolean[],\n targetIndex: number,\n minimumTargetPx: number,\n minimumDonorPx = minimumTargetPx,\n): number[] | null {\n if (\n weights.length !== sizesPx.length ||\n sizesPx.length !== foldedChildren.length ||\n targetIndex < 0 ||\n targetIndex >= sizesPx.length ||\n foldedChildren[targetIndex]\n ) {\n return null;\n }\n\n const neededPx = minimumTargetPx - sizesPx[targetIndex];\n if (neededPx <= 0) return null;\n\n const desiredSizes = [...sizesPx];\n const donors = sizesPx\n .map((size, index) => ({\n index,\n spare: !foldedChildren[index] && index !== targetIndex\n ? Math.max(0, size - minimumDonorPx)\n : 0,\n }))\n .filter((donor) => donor.spare > 0)\n .sort((a, b) => b.spare - a.spare);\n\n let remainingPx = neededPx;\n for (const donor of donors) {\n const contribution = Math.min(remainingPx, donor.spare);\n desiredSizes[donor.index] -= contribution;\n remainingPx -= contribution;\n if (remainingPx <= 0) break;\n }\n\n const transferredPx = neededPx - remainingPx;\n if (transferredPx <= 0) return null;\n desiredSizes[targetIndex] += transferredPx;\n\n const openWeightTotal = weights.reduce(\n (total, weight, index) => total + (foldedChildren[index] ? 0 : weight),\n 0,\n );\n const openSizeTotal = sizesPx.reduce(\n (total, size, index) => total + (foldedChildren[index] ? 0 : size),\n 0,\n );\n if (openWeightTotal <= 0 || openSizeTotal <= 0) return null;\n\n const weightPerPixel = openWeightTotal / openSizeTotal;\n return weights.map((weight, index) =>\n foldedChildren[index] ? weight : desiredSizes[index] * weightPerPixel,\n );\n}\n\nexport function growChildWeightsWithFallback(\n weights: readonly number[],\n sizesPx: readonly number[],\n foldedChildren: readonly boolean[],\n targetIndex: number,\n desiredTargetPx: number,\n preferredDonorFloorPx: number,\n fallbackDonorFloorPx: number,\n): number[] | null {\n return (\n growSplitChildWeightsToMinimum(\n weights,\n sizesPx,\n foldedChildren,\n targetIndex,\n desiredTargetPx,\n preferredDonorFloorPx,\n ) ??\n growSplitChildWeightsToMinimum(\n weights,\n sizesPx,\n foldedChildren,\n targetIndex,\n desiredTargetPx,\n fallbackDonorFloorPx,\n )\n );\n}\n\nexport function equalizeSplitAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n index: number,\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\") return node;\n const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);\n if (index < 0 || index + 1 >= sizes.length) return node;\n const avg = (sizes[index] + sizes[index + 1]) / 2;\n sizes[index] = avg;\n sizes[index + 1] = avg;\n return { ...node, sizes };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head ? equalizeSplitAtPath(child, tail, index) : child,\n ),\n };\n}\n\nexport function setSplitPairWeightsAtPath<Id extends string>(\n node: WorkspaceLayoutNode<Id>,\n path: number[],\n index: number,\n firstWeight: number,\n secondWeight: number,\n): WorkspaceLayoutNode<Id> {\n if (path.length === 0) {\n if (node.type !== \"split\") return node;\n const sizes = node.children.map((_, childIndex) => node.sizes?.[childIndex] ?? 1);\n if (index < 0 || index + 1 >= sizes.length) return node;\n sizes[index] = Math.max(0.15, firstWeight);\n sizes[index + 1] = Math.max(0.15, secondWeight);\n return { ...node, sizes };\n }\n if (node.type !== \"split\") return node;\n const [head, ...tail] = path;\n return {\n ...node,\n children: node.children.map((child, childIndex) =>\n childIndex === head\n ? setSplitPairWeightsAtPath(child, tail, index, firstWeight, secondWeight)\n : child,\n ),\n };\n}\n\nexport type ComputeResizeStepParams<Id extends string> = {\n tree: WorkspaceLayoutNode<Id>;\n folds: Partial<Record<Id, FoldState>>;\n path: number[];\n index: number;\n direction: \"horizontal\" | \"vertical\";\n startFirstPx: number;\n startSecondPx: number;\n deltaPx: number;\n};\n\nexport type ComputeResizeStepResult<Id extends string> = {\n tree: WorkspaceLayoutNode<Id>;\n folds: Partial<Record<Id, FoldState>>;\n nearFoldSide: \"first\" | \"second\" | null;\n snappedSide: \"first\" | \"second\" | null;\n};\n\n/**\n * Computes the next split tree and fold map for a single divider drag frame.\n * Supports recursive subtrees (folding all panels inside a nested column/row),\n * hysteresis when dragging a folded panel back open, and preserves the fold-point\n * proportions so unaffected siblings do not jump when a panel folds.\n */\nexport function computeResizeStep<Id extends string>({\n tree,\n folds,\n path,\n index,\n direction,\n startFirstPx,\n startSecondPx,\n deltaPx,\n}: ComputeResizeStepParams<Id>): ComputeResizeStepResult<Id> {\n const split = getSplitAtPath(tree, path);\n if (!split || split.type !== \"split\") {\n return { tree, folds, nearFoldSide: null, snappedSide: null };\n }\n const first = split.children[index];\n const second = split.children[index + 1];\n if (!first || !second) {\n return { tree, folds, nearFoldSide: null, snappedSide: null };\n }\n\n const snapThreshold =\n direction === \"horizontal\" ? HORIZONTAL_FOLD_SNAP_PX : VERTICAL_FOLD_SNAP_PX;\n const unfoldThreshold =\n direction === \"horizontal\" ? HORIZONTAL_UNFOLD_THRESHOLD_PX : VERTICAL_UNFOLD_THRESHOLD_PX;\n const minOpenPx = direction === \"horizontal\" ? HORIZONTAL_MIN_OPEN_PX : VERTICAL_MIN_OPEN_PX;\n\n const totalPx = Math.max(1, startFirstPx + startSecondPx);\n const rawFirstPx = startFirstPx + deltaPx;\n const rawSecondPx = totalPx - rawFirstPx;\n\n const firstFolded = isNodeFolded(first, folds);\n const secondFolded = isNodeFolded(second, folds);\n const pairFirstWeight = split.sizes?.[index] ?? 1;\n const pairSecondWeight = split.sizes?.[index + 1] ?? 1;\n const pairTotalWeight = pairFirstWeight + pairSecondWeight;\n const foldedSizePx =\n direction === \"horizontal\" ? HORIZONTAL_FOLDED_RAIL_PX : VERTICAL_FOLDED_BAR_PX;\n\n const foldChild = (side: \"first\" | \"second\"): ComputeResizeStepResult<Id> => {\n const foldedChild = side === \"first\" ? first : second;\n const nextFolds = setNodeFoldState(foldedChild, folds, \"folded\");\n const safeFirstPx = Math.max(0, Math.min(totalPx, rawFirstPx));\n const safeSecondPx = totalPx - safeFirstPx;\n const foldedWeight =\n pairTotalWeight * ((side === \"first\" ? safeFirstPx : safeSecondPx) / totalPx);\n const expandedNeighborWeight = pairTotalWeight * ((totalPx - foldedSizePx) / totalPx);\n\n return {\n tree: setSplitPairWeightsAtPath(\n tree,\n path,\n index,\n side === \"first\" ? foldedWeight : expandedNeighborWeight,\n side === \"second\" ? foldedWeight : expandedNeighborWeight,\n ),\n folds: nextFolds,\n nearFoldSide: null,\n snappedSide: side,\n };\n };\n\n // Check both sides before snapping either one: both siblings may be folded.\n const unfoldChild = (side: \"first\" | \"second\"): ComputeResizeStepResult<Id> => {\n const targetChild = side === \"first\" ? first : second;\n const nextFolds = setNodeFoldState(targetChild, folds, \"open\");\n if (firstFolded && secondFolded && pairTotalWeight < 1) {\n // Both siblings were previously snap-folded to tiny weights; give the newly\n // unfolded child a full unit weight while keeping the still-folded sibling small.\n const unfoldedWeight = Math.max(1, pairTotalWeight);\n const stillFoldedWeight = side === \"first\" ? pairSecondWeight : pairFirstWeight;\n return {\n tree: setSplitPairWeightsAtPath(\n tree,\n path,\n index,\n side === \"first\" ? unfoldedWeight : stillFoldedWeight,\n side === \"second\" ? unfoldedWeight : stillFoldedWeight,\n ),\n folds: nextFolds,\n nearFoldSide: null,\n snappedSide: null,\n };\n }\n const openTarget = Math.max(minOpenPx, side === \"first\" ? rawFirstPx : rawSecondPx);\n const openSibling = Math.max(minOpenPx, totalPx - openTarget);\n return {\n tree: resizeSplitAtPath(\n tree,\n path,\n index,\n side === \"first\" ? openTarget : openSibling,\n side === \"second\" ? openTarget : openSibling,\n ),\n folds: nextFolds,\n nearFoldSide: null,\n snappedSide: null,\n };\n };\n\n if (firstFolded && rawFirstPx >= unfoldThreshold) {\n return unfoldChild(\"first\");\n }\n\n if (secondFolded && rawSecondPx >= unfoldThreshold) {\n return unfoldChild(\"second\");\n }\n\n if (firstFolded) {\n return { tree, folds, nearFoldSide: null, snappedSide: \"first\" };\n }\n if (secondFolded) {\n return { tree, folds, nearFoldSide: null, snappedSide: \"second\" };\n }\n\n // Both children are open: check snap-fold thresholds (works for leaf panels AND nested splits!)\n if (rawFirstPx <= snapThreshold && totalPx > snapThreshold * 1.6) {\n return foldChild(\"first\");\n }\n\n if (rawSecondPx <= snapThreshold && totalPx > snapThreshold * 1.6) {\n return foldChild(\"second\");\n }\n\n // Normal live resize while open. When totalPx is too narrow for both children to\n // stay above snapThreshold + 4, scale the minimum clamp so resizing doesn't lock at 50/50.\n const minClampPx = Math.min(snapThreshold + 4, Math.max(1, Math.floor(totalPx * 0.25)));\n const clampedFirst = Math.max(minClampPx, Math.min(totalPx - minClampPx, rawFirstPx));\n const clampedSecond = Math.max(minClampPx, totalPx - clampedFirst);\n\n let nearFoldSide: \"first\" | \"second\" | null = null;\n if (totalPx > snapThreshold * 1.6) {\n if (rawFirstPx <= snapThreshold + FOLD_APPROACH_MARGIN_PX) {\n nearFoldSide = \"first\";\n } else if (rawSecondPx <= snapThreshold + FOLD_APPROACH_MARGIN_PX) {\n nearFoldSide = \"second\";\n }\n }\n\n return {\n tree: resizeSplitAtPath(tree, path, index, clampedFirst, clampedSecond),\n folds,\n nearFoldSide,\n snappedSide: null,\n };\n}\n\nexport function computeKeyboardResizeStep<Id extends string>({\n tree,\n folds,\n path,\n index,\n deltaRatio,\n}: {\n tree: WorkspaceLayoutNode<Id>;\n folds: Partial<Record<Id, FoldState>>;\n path: number[];\n index: number;\n deltaRatio: number;\n}): { tree: WorkspaceLayoutNode<Id>; folds: Partial<Record<Id, FoldState>> } {\n const split = getSplitAtPath(tree, path);\n if (!split || split.type !== \"split\") return { tree, folds };\n const first = split.children[index];\n const second = split.children[index + 1];\n if (!first || !second) return { tree, folds };\n\n const firstFolded = isNodeFolded(first, folds);\n const secondFolded = isNodeFolded(second, folds);\n const sizes = split.children.map((_, i) => split.sizes?.[i] ?? 1);\n const firstWeight = sizes[index] ?? 1;\n const secondWeight = sizes[index + 1] ?? 1;\n const total = firstWeight + secondWeight;\n\n if (firstFolded) {\n if (deltaRatio <= 0) return { tree, folds };\n const nextFolds = setNodeFoldState(first, folds, \"open\");\n const nextFirst = Math.max(total * 0.25, firstWeight);\n const nextSecond = Math.max(0.15, secondFolded ? secondWeight : total - nextFirst);\n return {\n tree: setSplitPairWeightsAtPath(tree, path, index, nextFirst, nextSecond),\n folds: nextFolds,\n };\n }\n\n if (secondFolded) {\n if (deltaRatio >= 0) return { tree, folds };\n const nextFolds = setNodeFoldState(second, folds, \"open\");\n const nextSecond = Math.max(total * 0.25, secondWeight);\n const nextFirst = Math.max(0.15, total - nextSecond);\n return {\n tree: setSplitPairWeightsAtPath(tree, path, index, nextFirst, nextSecond),\n folds: nextFolds,\n };\n }\n\n const nextFirst = Math.max(total * 0.15, Math.min(total * 0.85, firstWeight + total * deltaRatio));\n const nextSecond = total - nextFirst;\n return {\n tree: resizeSplitAtPath(tree, path, index, nextFirst, nextSecond),\n folds,\n };\n}\n\nexport function splitDepth<Id extends string>(node: WorkspaceLayoutNode<Id>): number {\n if (node.type === \"panel\") return 0;\n return 1 + Math.max(...node.children.map(splitDepth));\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// src/shortcuts.ts
|
|
3
|
+
const DEFAULT_WORKSPACE_SHORTCUTS = [
|
|
4
|
+
{
|
|
5
|
+
id: "focus-panel",
|
|
6
|
+
label: "Focus or restore a panel",
|
|
7
|
+
keys: "1–9"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: "toggle-fold",
|
|
11
|
+
label: "Fold or unfold the focused panel",
|
|
12
|
+
keys: "F"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
id: "toggle-maximize",
|
|
16
|
+
label: "Maximize or restore the focused panel",
|
|
17
|
+
keys: "M"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "minimize-panel",
|
|
21
|
+
label: "Minimize the focused panel",
|
|
22
|
+
keys: "X"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: "reset-layout",
|
|
26
|
+
label: "Reset the workspace layout",
|
|
27
|
+
keys: "R"
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
exports.DEFAULT_WORKSPACE_SHORTCUTS = DEFAULT_WORKSPACE_SHORTCUTS;
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=shortcuts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcuts.cjs","names":[],"sources":["../../src/shortcuts.ts"],"sourcesContent":["export type WorkspaceShortcutDefinition = {\n id: \"focus-panel\" | \"toggle-fold\" | \"toggle-maximize\" | \"minimize-panel\" | \"reset-layout\";\n label: string;\n keys: string;\n};\n\nexport const DEFAULT_WORKSPACE_SHORTCUTS: readonly WorkspaceShortcutDefinition[] = [\n { id: \"focus-panel\", label: \"Focus or restore a panel\", keys: \"1–9\" },\n { id: \"toggle-fold\", label: \"Fold or unfold the focused panel\", keys: \"F\" },\n { id: \"toggle-maximize\", label: \"Maximize or restore the focused panel\", keys: \"M\" },\n { id: \"minimize-panel\", label: \"Minimize the focused panel\", keys: \"X\" },\n { id: \"reset-layout\", label: \"Reset the workspace layout\", keys: \"R\" },\n];\n"],"mappings":";;AAMA,MAAa,8BAAsE;CACjF;EAAE,IAAI;EAAe,OAAO;EAA4B,MAAM;CAAM;CACpE;EAAE,IAAI;EAAe,OAAO;EAAoC,MAAM;CAAI;CAC1E;EAAE,IAAI;EAAmB,OAAO;EAAyC,MAAM;CAAI;CACnF;EAAE,IAAI;EAAkB,OAAO;EAA8B,MAAM;CAAI;CACvE;EAAE,IAAI;EAAgB,OAAO;EAA8B,MAAM;CAAI;AACvE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/shortcuts.ts
|
|
2
|
+
const DEFAULT_WORKSPACE_SHORTCUTS = [
|
|
3
|
+
{
|
|
4
|
+
id: "focus-panel",
|
|
5
|
+
label: "Focus or restore a panel",
|
|
6
|
+
keys: "1–9"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
id: "toggle-fold",
|
|
10
|
+
label: "Fold or unfold the focused panel",
|
|
11
|
+
keys: "F"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "toggle-maximize",
|
|
15
|
+
label: "Maximize or restore the focused panel",
|
|
16
|
+
keys: "M"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "minimize-panel",
|
|
20
|
+
label: "Minimize the focused panel",
|
|
21
|
+
keys: "X"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "reset-layout",
|
|
25
|
+
label: "Reset the workspace layout",
|
|
26
|
+
keys: "R"
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
export { DEFAULT_WORKSPACE_SHORTCUTS };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=shortcuts.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortcuts.mjs","names":[],"sources":["../../src/shortcuts.ts"],"sourcesContent":["export type WorkspaceShortcutDefinition = {\n id: \"focus-panel\" | \"toggle-fold\" | \"toggle-maximize\" | \"minimize-panel\" | \"reset-layout\";\n label: string;\n keys: string;\n};\n\nexport const DEFAULT_WORKSPACE_SHORTCUTS: readonly WorkspaceShortcutDefinition[] = [\n { id: \"focus-panel\", label: \"Focus or restore a panel\", keys: \"1–9\" },\n { id: \"toggle-fold\", label: \"Fold or unfold the focused panel\", keys: \"F\" },\n { id: \"toggle-maximize\", label: \"Maximize or restore the focused panel\", keys: \"M\" },\n { id: \"minimize-panel\", label: \"Minimize the focused panel\", keys: \"X\" },\n { id: \"reset-layout\", label: \"Reset the workspace layout\", keys: \"R\" },\n];\n"],"mappings":";AAMA,MAAa,8BAAsE;CACjF;EAAE,IAAI;EAAe,OAAO;EAA4B,MAAM;CAAM;CACpE;EAAE,IAAI;EAAe,OAAO;EAAoC,MAAM;CAAI;CAC1E;EAAE,IAAI;EAAmB,OAAO;EAAyC,MAAM;CAAI;CACnF;EAAE,IAAI;EAAkB,OAAO;EAA8B,MAAM;CAAI;CACvE;EAAE,IAAI;EAAgB,OAAO;EAA8B,MAAM;CAAI;AACvE"}
|