mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat(draw): lock shape
This commit is contained in:
@@ -22,3 +22,4 @@ export * from './translate-shapes';
|
||||
export * from './ungroup-shapes';
|
||||
export * from './update-shapes';
|
||||
export * from './set-shapes-props';
|
||||
export * from './set-shapes-lock-status';
|
||||
|
||||
59
libs/components/board-commands/src/set-shapes-lock-status.ts
Normal file
59
libs/components/board-commands/src/set-shapes-lock-status.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import type {
|
||||
TDShape,
|
||||
TldrawCommand,
|
||||
} from '@toeverything/components/board-types';
|
||||
import type { TldrawApp } from '@toeverything/components/board-state';
|
||||
|
||||
export function setShapesLockStatus<T extends TDShape>(
|
||||
app: TldrawApp,
|
||||
ids: string[],
|
||||
isLocked: boolean
|
||||
): TldrawCommand {
|
||||
const { currentPageId, selectedIds } = app;
|
||||
|
||||
const initialShapes = ids.map(id => app.getShape<T>(id));
|
||||
|
||||
const before: Record<string, Partial<TDShape>> = {};
|
||||
const after: Record<string, Partial<TDShape>> = {};
|
||||
|
||||
initialShapes.forEach(shape => {
|
||||
before[shape.id] = {
|
||||
isLocked: shape.isLocked,
|
||||
};
|
||||
after[shape.id] = {
|
||||
isLocked,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
id: 'set_shapes_lock_status',
|
||||
before: {
|
||||
document: {
|
||||
pages: {
|
||||
[currentPageId]: {
|
||||
shapes: before,
|
||||
},
|
||||
},
|
||||
pageStates: {
|
||||
[currentPageId]: {
|
||||
selectedIds,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
after: {
|
||||
document: {
|
||||
pages: {
|
||||
[currentPageId]: {
|
||||
shapes: after,
|
||||
},
|
||||
},
|
||||
pageStates: {
|
||||
[currentPageId]: {
|
||||
selectedIds,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user