mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 08:47:10 +08:00
init: the first public commit for AFFiNE
This commit is contained in:
69
libs/components/board-commands/src/duplicate-page.ts
Normal file
69
libs/components/board-commands/src/duplicate-page.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import type { TldrawCommand } from '@toeverything/components/board-types';
|
||||
import { Utils } from '@tldraw/core';
|
||||
import type { TldrawApp } from '@toeverything/components/board-state';
|
||||
|
||||
export function duplicatePage(app: TldrawApp, pageId: string): TldrawCommand {
|
||||
const newId = Utils.uniqueId();
|
||||
const {
|
||||
currentPageId,
|
||||
page,
|
||||
pageState: { camera },
|
||||
} = app;
|
||||
|
||||
const nextPage = {
|
||||
...page,
|
||||
id: newId,
|
||||
name: page.name + ' Copy',
|
||||
shapes: Object.fromEntries(
|
||||
Object.entries(page.shapes).map(([id, shape]) => {
|
||||
return [
|
||||
id,
|
||||
{
|
||||
...shape,
|
||||
parentId:
|
||||
shape.parentId === pageId ? newId : shape.parentId,
|
||||
},
|
||||
];
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
return {
|
||||
id: 'duplicate_page',
|
||||
before: {
|
||||
appState: {
|
||||
currentPageId,
|
||||
},
|
||||
document: {
|
||||
pages: {
|
||||
[newId]: undefined,
|
||||
},
|
||||
pageStates: {
|
||||
[newId]: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
after: {
|
||||
appState: {
|
||||
currentPageId: newId,
|
||||
},
|
||||
document: {
|
||||
pages: {
|
||||
[newId]: nextPage,
|
||||
},
|
||||
pageStates: {
|
||||
[newId]: {
|
||||
...page,
|
||||
id: newId,
|
||||
selectedIds: [],
|
||||
camera: { ...camera },
|
||||
editingId: undefined,
|
||||
bindingId: undefined,
|
||||
hoveredId: undefined,
|
||||
pointedId: undefined,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user