feat: persist grid gap

This commit is contained in:
mathuo 2024-11-15 21:26:41 +00:00
parent 25489bf48e
commit 622810ac2e
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
2 changed files with 16 additions and 5 deletions

View File

@ -121,6 +121,7 @@ export interface SerializedDockview {
width: number; width: number;
orientation: Orientation; orientation: Orientation;
}; };
gridGap?: number;
panels: Record<string, GroupviewPanelState>; panels: Record<string, GroupviewPanelState>;
activeGroup?: string; activeGroup?: string;
floatingGroups?: SerializedFloatingGroup[]; floatingGroups?: SerializedFloatingGroup[];
@ -1216,6 +1217,12 @@ export class DockviewComponent
result.popoutGroups = popoutGroups; result.popoutGroups = popoutGroups;
} }
const gap = this.gap;
if (gap !== 0) {
result.gridGap = gap;
}
return result; return result;
} }
@ -1232,6 +1239,8 @@ export class DockviewComponent
throw new Error('root must be of type branch'); throw new Error('root must be of type branch');
} }
this.gridview.margin = data.gridGap ?? 0;
try { try {
// take note of the existing dimensions // take note of the existing dimensions
const width = this.width; const width = this.width;

View File

@ -103,6 +103,8 @@ export const GridActions = (props: {
if (state) { if (state) {
try { try {
props.api?.fromJSON(JSON.parse(state)); props.api?.fromJSON(JSON.parse(state));
setGap(props.api?.gap ?? 0);
} catch (err) { } catch (err) {
console.error('failed to load state', err); console.error('failed to load state', err);
localStorage.removeItem('dv-demo-state'); localStorage.removeItem('dv-demo-state');
@ -154,10 +156,6 @@ export const GridActions = (props: {
const [gap, setGap] = React.useState(0); const [gap, setGap] = React.useState(0);
React.useEffect(() => {
props.api?.setGap(gap);
}, [gap, props.api]);
return ( return (
<div className="action-container"> <div className="action-container">
<div className="button-group"> <div className="button-group">
@ -208,7 +206,11 @@ export const GridActions = (props: {
max={99} max={99}
step={1} step={1}
value={gap} value={gap}
onChange={(event) => setGap(Number(event.target.value))} onChange={(event) => {
const value = Number(event.target.value);
setGap(value);
props.api?.setGap(value);
}}
/> />
</div> </div>
</div> </div>