Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(resize): impl target size on panel registration, use for soup preview (#3234)

Seamusc7f3c56434c9
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index 6a25d286b4..990f52feb2 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -1083,7 +1083,11 @@ export const SoupViewList = (props: SoupViewListProps) => {
</div>
</Resize.Panel>
<Show when={previewVisible()}>
- <Resize.Panel id="soup-preview" minSize={300}>
+ <Resize.Panel
+ id="soup-preview"
+ minSize={300}
+ target={{ kind: 'percent', percent: 70 }}
+ >
<PreviewPanel
selectedEntity={soup.focus.item()}
orchestrator={orchestrator}
diff --git a/js/app/packages/core/component/Resize/Resize.tsx b/js/app/packages/core/component/Resize/Resize.tsx
index 3ba779bafa..76bb0c6f59 100644
--- a/js/app/packages/core/component/Resize/Resize.tsx
+++ b/js/app/packages/core/component/Resize/Resize.tsx
@@ -13,7 +13,12 @@ import {
useContext,
} from 'solid-js';
import { createResizeSolver } from './solver';
-import type { PanelConfig, PanelId, ResizeZoneCtx } from './types';
+import type {
+ PanelConfig,
+ PanelId,
+ PanelSizeSpec,
+ ResizeZoneCtx,
+} from './types';
export const ResizeZoneContext = createContext<ResizeZoneCtx>();
@@ -190,6 +195,14 @@ type PanelProps = {
id: PanelId;
minSize: number;
maxSize?: number;
+ /**
+ * Initial target size for the panel at registration time.
+ * - number: interpreted as a percentage (e.g., 25 = 25%)
+ * - PanelSizeSpec: explicit spec like { kind: 'percent', percent: 25 } or { kind: 'px', px: 300 }
+ *
+ * After initial layout, the panel resizes normally via drag handles.
+ */
+ target?: number | PanelSizeSpec;
collapsed?: () => boolean;
hidden?: () => boolean;
/** The index position for this panel in the layout order */
@@ -227,6 +240,15 @@ function Panel(props: ParentProps<PanelProps>) {
const ctx = useContext(ResizeZoneContext);
if (!ctx) throw new Error('<Resize.Panel> must be inside <Resize.Zone>');
+ // Convert shorthand number (percentage) to PanelSizeSpec
+ const getTarget = (): PanelSizeSpec | undefined => {
+ if (props.target === undefined) return undefined;
+ if (typeof props.target === 'number') {
+ return { kind: 'percent', percent: props.target };
+ }
+ return props.target;
+ };
+
onMount(() => {
if (props.collapsed?.() === false) return;
ctx.register(
@@ -234,6 +256,7 @@ function Panel(props: ParentProps<PanelProps>) {
id: props.id,
minSize: props.minSize,
maxSize: props.maxSize ?? Infinity,
+ target: getTarget(),
},
props.index
);
@@ -257,6 +280,7 @@ function Panel(props: ParentProps<PanelProps>) {
id: props.id,
minSize: props.minSize,
maxSize: props.maxSize ?? Infinity,
+ target: getTarget(),
},
props.index
);
@@ -282,6 +306,7 @@ function Panel(props: ParentProps<PanelProps>) {
id: props.id,
minSize: props.minSize,
maxSize: props.maxSize ?? Infinity,
+ target: getTarget(),
},
props.index
);
diff --git a/js/app/packages/core/component/Resize/solver.ts b/js/app/packages/core/component/Resize/solver.ts
index 9d0da6bfe2..4e62866a8b 100644
--- a/js/app/packages/core/component/Resize/solver.ts
+++ b/js/app/packages/core/component/Resize/solver.ts
@@ -264,26 +264,38 @@ export function createResizeSolver(params: {
let index = ndx != null && ndx < order().length ? ndx : order().length;
- // default is the "equal size" share
+ const usableSize = getUsable(nextLength, params.size(), params.gutter());
+
+ // Calculate incoming share based on target spec, defaulting to equal share
let incomingShare = 1 / nextLength;
- // check max size constraint
- if (length > 0) {
- const usableSize = getUsable(
- nextLength,
- params.size(),
- params.gutter()
- );
-
- if (usableSize > 0) {
- const equalPx = usableSize / nextLength;
- const maxPx = panel.maxSize ?? Infinity;
- if (maxPx < equalPx) {
- incomingShare = Math.min(maxPx / usableSize, 1 / nextLength);
- }
+ if (panel.target && usableSize > 0) {
+ switch (panel.target.kind) {
+ case 'percent':
+ incomingShare = panel.target.percent / 100;
+ break;
+ case 'px':
+ incomingShare = panel.target.px / usableSize;
+ break;
+ case 'fr':
+ // fr needs total fr units across all panels - not supported yet, use equal
+ break;
+ default:
+ // keep equal share
+ break;
}
}
+ // Clamp to max size constraint
+ if (length > 0 && usableSize > 0) {
+ const maxPx = panel.maxSize ?? Infinity;
+ const maxShare = maxPx / usableSize;
+ incomingShare = Math.min(incomingShare, maxShare);
+ }
+
+ // Clamp share to [0, 1] for sanity
+ incomingShare = Math.max(0, Math.min(1, incomingShare));
+
panelData[panel.id] = {
...initPanel(panel),
share: incomingShare,