mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-10 22:56:24 +08:00
205cd7a86d
Closes: BS-2946
34 lines
823 B
TypeScript
34 lines
823 B
TypeScript
import { BaseSelection, SelectionExtension } from '@blocksuite/store';
|
|
import z from 'zod';
|
|
|
|
const BlockSelectionSchema = z.object({
|
|
blockId: z.string(),
|
|
});
|
|
|
|
export class BlockSelection extends BaseSelection {
|
|
static override group = 'note';
|
|
|
|
static override type = 'block';
|
|
|
|
static override fromJSON(json: Record<string, unknown>): BlockSelection {
|
|
const result = BlockSelectionSchema.parse(json);
|
|
return new BlockSelection(result);
|
|
}
|
|
|
|
override equals(other: BaseSelection): boolean {
|
|
if (other instanceof BlockSelection) {
|
|
return this.blockId === other.blockId;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
override toJSON(): Record<string, unknown> {
|
|
return {
|
|
type: 'block',
|
|
blockId: this.blockId,
|
|
};
|
|
}
|
|
}
|
|
|
|
export const BlockSelectionExtension = SelectionExtension(BlockSelection);
|