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);
|
||||
return () => obv.disconnect();
|
||||
}
|
||||
});
|
||||
}, [setPageClientWidth]);
|
||||
|
||||
return (
|
||||
<StyledEditorContainer
|
||||
|
@ -29,6 +29,7 @@ import { ErrorBoundary } from 'react-error-boundary';
|
||||
import { ErrorFallback } from './components/error-fallback';
|
||||
import { ZoomBar } from './components/zoom-bar';
|
||||
import { CommandPanel } from './components/command-panel';
|
||||
import { usePageClientWidth } from '@toeverything/datasource/state';
|
||||
|
||||
export interface TldrawProps extends TldrawAppCtorProps {
|
||||
/**
|
||||
@ -132,6 +133,9 @@ export function Tldraw({
|
||||
tools,
|
||||
}: TldrawProps) {
|
||||
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.
|
||||
const [app, setApp] = React.useState(() => {
|
||||
@ -140,6 +144,7 @@ export function Tldraw({
|
||||
callbacks,
|
||||
commands,
|
||||
getSession,
|
||||
editorShapeInitSize,
|
||||
tools,
|
||||
});
|
||||
return app;
|
||||
|
@ -73,6 +73,7 @@ import { StateManager } from './manager/state-manager';
|
||||
import { getClipboard, setClipboard } from './idb-clipboard';
|
||||
import type { Commands } from './types/commands';
|
||||
import type { BaseTool } from './types/tool';
|
||||
import { MIN_PAGE_WIDTH } from '@toeverything/components/editor-core';
|
||||
|
||||
const uuid = Utils.uniqueId();
|
||||
|
||||
@ -178,6 +179,7 @@ export interface TldrawAppCtorProps {
|
||||
getSession: (type: SessionType) => {
|
||||
new (app: TldrawApp, ...args: any[]): BaseSessionType;
|
||||
};
|
||||
editorShapeInitSize?: number;
|
||||
commands: Commands;
|
||||
tools: Record<string, { new (app: TldrawApp): BaseTool }>;
|
||||
}
|
||||
@ -223,6 +225,8 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||
|
||||
fileSystemHandle: FileSystemHandle | null = null;
|
||||
|
||||
editorShapeInitSize = MIN_PAGE_WIDTH;
|
||||
|
||||
viewport = Utils.getBoundsFromPoints([
|
||||
[0, 0],
|
||||
[100, 100],
|
||||
@ -285,6 +289,10 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||
return acc;
|
||||
}, {} as Record<string, BaseTool>);
|
||||
this.currentTool = this.tools['select'];
|
||||
|
||||
if (props.editorShapeInitSize) {
|
||||
this.editorShapeInitSize = props.editorShapeInitSize;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- Internal -------------------- */
|
||||
|
@ -18,6 +18,7 @@ export class EditorTool extends BaseTool {
|
||||
const {
|
||||
currentPoint,
|
||||
currentGrid,
|
||||
editorShapeInitSize,
|
||||
settings: { showGrid },
|
||||
appState: { currentPageId, currentStyle },
|
||||
document: { id: workspace },
|
||||
@ -47,6 +48,7 @@ export class EditorTool extends BaseTool {
|
||||
? Vec.snap(currentPoint, currentGrid)
|
||||
: currentPoint,
|
||||
style: { ...currentStyle },
|
||||
size: [editorShapeInitSize, 200],
|
||||
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]);
|
||||
|
Loading…
Reference in New Issue
Block a user