Skip to content

Commit

Permalink
feat: persist grid gap
Browse files Browse the repository at this point in the history
  • Loading branch information
mathuo committed Dec 20, 2024
1 parent 25489bf commit 622810a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions packages/dockview-core/src/dockview/dockviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface SerializedDockview {
width: number;
orientation: Orientation;
};
gridGap?: number;
panels: Record<string, GroupviewPanelState>;
activeGroup?: string;
floatingGroups?: SerializedFloatingGroup[];
Expand Down Expand Up @@ -1216,6 +1217,12 @@ export class DockviewComponent
result.popoutGroups = popoutGroups;
}

const gap = this.gap;

if (gap !== 0) {
result.gridGap = gap;
}

return result;
}

Expand All @@ -1232,6 +1239,8 @@ export class DockviewComponent
throw new Error('root must be of type branch');
}

this.gridview.margin = data.gridGap ?? 0;

try {
// take note of the existing dimensions
const width = this.width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export const GridActions = (props: {
if (state) {
try {
props.api?.fromJSON(JSON.parse(state));

setGap(props.api?.gap ?? 0);
} catch (err) {
console.error('failed to load state', err);
localStorage.removeItem('dv-demo-state');
Expand Down Expand Up @@ -154,10 +156,6 @@ export const GridActions = (props: {

const [gap, setGap] = React.useState(0);

React.useEffect(() => {
props.api?.setGap(gap);
}, [gap, props.api]);

return (
<div className="action-container">
<div className="button-group">
Expand Down Expand Up @@ -208,7 +206,11 @@ export const GridActions = (props: {
max={99}
step={1}
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>
Expand Down

0 comments on commit 622810a

Please sign in to comment.