mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-18 08:41:56 +03:00
fix(whiteboard): editor init size when creating new editor
This commit is contained in:
parent
fbe9add924
commit
62cd0b4424
@ -148,7 +148,7 @@ const EditorContainer = ({
|
|||||||
obv.observe(scrollContainerRef.current);
|
obv.observe(scrollContainerRef.current);
|
||||||
return () => obv.disconnect();
|
return () => obv.disconnect();
|
||||||
}
|
}
|
||||||
});
|
}, [setPageClientWidth]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledEditorContainer
|
<StyledEditorContainer
|
||||||
|
@ -29,6 +29,7 @@ import { ErrorBoundary } from 'react-error-boundary';
|
|||||||
import { ErrorFallback } from './components/error-fallback';
|
import { ErrorFallback } from './components/error-fallback';
|
||||||
import { ZoomBar } from './components/zoom-bar';
|
import { ZoomBar } from './components/zoom-bar';
|
||||||
import { CommandPanel } from './components/command-panel';
|
import { CommandPanel } from './components/command-panel';
|
||||||
|
import { usePageClientWidth } from '@toeverything/datasource/state';
|
||||||
|
|
||||||
export interface TldrawProps extends TldrawAppCtorProps {
|
export interface TldrawProps extends TldrawAppCtorProps {
|
||||||
/**
|
/**
|
||||||
@ -132,6 +133,9 @@ export function Tldraw({
|
|||||||
tools,
|
tools,
|
||||||
}: TldrawProps) {
|
}: TldrawProps) {
|
||||||
const [sId, set_sid] = React.useState(id);
|
const [sId, set_sid] = React.useState(id);
|
||||||
|
const { pageClientWidth } = usePageClientWidth();
|
||||||
|
// page padding left and right total 300px
|
||||||
|
const editorShapeInitSize = pageClientWidth - 300;
|
||||||
|
|
||||||
// Create a new app when the component mounts.
|
// Create a new app when the component mounts.
|
||||||
const [app, setApp] = React.useState(() => {
|
const [app, setApp] = React.useState(() => {
|
||||||
@ -140,6 +144,7 @@ export function Tldraw({
|
|||||||
callbacks,
|
callbacks,
|
||||||
commands,
|
commands,
|
||||||
getSession,
|
getSession,
|
||||||
|
editorShapeInitSize,
|
||||||
tools,
|
tools,
|
||||||
});
|
});
|
||||||
return app;
|
return app;
|
||||||
|
@ -73,6 +73,7 @@ import { StateManager } from './manager/state-manager';
|
|||||||
import { getClipboard, setClipboard } from './idb-clipboard';
|
import { getClipboard, setClipboard } from './idb-clipboard';
|
||||||
import type { Commands } from './types/commands';
|
import type { Commands } from './types/commands';
|
||||||
import type { BaseTool } from './types/tool';
|
import type { BaseTool } from './types/tool';
|
||||||
|
import { MIN_PAGE_WIDTH } from '@toeverything/components/editor-core';
|
||||||
|
|
||||||
const uuid = Utils.uniqueId();
|
const uuid = Utils.uniqueId();
|
||||||
|
|
||||||
@ -178,6 +179,7 @@ export interface TldrawAppCtorProps {
|
|||||||
getSession: (type: SessionType) => {
|
getSession: (type: SessionType) => {
|
||||||
new (app: TldrawApp, ...args: any[]): BaseSessionType;
|
new (app: TldrawApp, ...args: any[]): BaseSessionType;
|
||||||
};
|
};
|
||||||
|
editorShapeInitSize?: number;
|
||||||
commands: Commands;
|
commands: Commands;
|
||||||
tools: Record<string, { new (app: TldrawApp): BaseTool }>;
|
tools: Record<string, { new (app: TldrawApp): BaseTool }>;
|
||||||
}
|
}
|
||||||
@ -223,6 +225,8 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
|||||||
|
|
||||||
fileSystemHandle: FileSystemHandle | null = null;
|
fileSystemHandle: FileSystemHandle | null = null;
|
||||||
|
|
||||||
|
editorShapeInitSize = MIN_PAGE_WIDTH;
|
||||||
|
|
||||||
viewport = Utils.getBoundsFromPoints([
|
viewport = Utils.getBoundsFromPoints([
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[100, 100],
|
[100, 100],
|
||||||
@ -285,6 +289,10 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
|||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, BaseTool>);
|
}, {} as Record<string, BaseTool>);
|
||||||
this.currentTool = this.tools['select'];
|
this.currentTool = this.tools['select'];
|
||||||
|
|
||||||
|
if (props.editorShapeInitSize) {
|
||||||
|
this.editorShapeInitSize = props.editorShapeInitSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Internal -------------------- */
|
/* -------------------- Internal -------------------- */
|
||||||
|
@ -18,6 +18,7 @@ export class EditorTool extends BaseTool {
|
|||||||
const {
|
const {
|
||||||
currentPoint,
|
currentPoint,
|
||||||
currentGrid,
|
currentGrid,
|
||||||
|
editorShapeInitSize,
|
||||||
settings: { showGrid },
|
settings: { showGrid },
|
||||||
appState: { currentPageId, currentStyle },
|
appState: { currentPageId, currentStyle },
|
||||||
document: { id: workspace },
|
document: { id: workspace },
|
||||||
@ -47,6 +48,7 @@ export class EditorTool extends BaseTool {
|
|||||||
? Vec.snap(currentPoint, currentGrid)
|
? Vec.snap(currentPoint, currentGrid)
|
||||||
: currentPoint,
|
: currentPoint,
|
||||||
style: { ...currentStyle },
|
style: { ...currentStyle },
|
||||||
|
size: [editorShapeInitSize, 200],
|
||||||
workspace,
|
workspace,
|
||||||
});
|
});
|
||||||
// In order to make the cursor just positioned at the beginning of the first line, it needs to be adjusted according to the padding newShape.point = Vec.sub(newShape.point, [50, 30]);
|
// In order to make the cursor just positioned at the beginning of the first line, it needs to be adjusted according to the padding newShape.point = Vec.sub(newShape.point, [50, 30]);
|
||||||
|
Loading…
Reference in New Issue
Block a user