mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-25 22:38:56 +08:00
init: the first public commit for AFFiNE
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import type {
|
||||
TldrawCommand,
|
||||
TDPage,
|
||||
} from '@toeverything/components/board-types';
|
||||
import { Utils, TLPageState } from '@tldraw/core';
|
||||
import type { TldrawApp } from '@toeverything/components/board-state';
|
||||
|
||||
export function createPage(
|
||||
app: TldrawApp,
|
||||
center: number[],
|
||||
pageId = Utils.uniqueId()
|
||||
): TldrawCommand {
|
||||
const { currentPageId } = app;
|
||||
|
||||
const topPage = Object.values(app.state.document.pages).sort(
|
||||
(a, b) => (b.childIndex || 0) - (a.childIndex || 0)
|
||||
)[0];
|
||||
|
||||
const nextChildIndex = topPage?.childIndex ? topPage?.childIndex + 1 : 1;
|
||||
|
||||
// TODO: Iterate the name better
|
||||
const nextName = `New Page`;
|
||||
|
||||
const page: TDPage = {
|
||||
id: pageId,
|
||||
name: nextName,
|
||||
childIndex: nextChildIndex,
|
||||
shapes: {},
|
||||
bindings: {},
|
||||
};
|
||||
|
||||
const pageState: TLPageState = {
|
||||
id: pageId,
|
||||
selectedIds: [],
|
||||
camera: { point: center, zoom: 1 },
|
||||
editingId: undefined,
|
||||
bindingId: undefined,
|
||||
hoveredId: undefined,
|
||||
pointedId: undefined,
|
||||
};
|
||||
|
||||
return {
|
||||
id: 'create_page',
|
||||
before: {
|
||||
appState: {
|
||||
currentPageId,
|
||||
},
|
||||
document: {
|
||||
pages: {
|
||||
[pageId]: undefined,
|
||||
},
|
||||
pageStates: {
|
||||
[pageId]: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
after: {
|
||||
appState: {
|
||||
currentPageId: page.id,
|
||||
},
|
||||
document: {
|
||||
pages: {
|
||||
[pageId]: page,
|
||||
},
|
||||
pageStates: {
|
||||
[pageId]: pageState,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user