chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions
@@ -0,0 +1,62 @@
import {
type ReferenceParams,
ReferenceParamsSchema,
} from '@blocksuite/affine-model';
import { BaseSelection, SelectionExtension } from '@blocksuite/block-std';
export class HighlightSelection extends BaseSelection {
static override group = 'scene';
static override type = 'highlight';
readonly blockIds: string[] = [];
readonly elementIds: string[] = [];
readonly mode: 'page' | 'edgeless' = 'page';
constructor({ mode, blockIds, elementIds }: ReferenceParams) {
super({ blockId: '[scene-highlight]' });
this.mode = mode ?? 'page';
this.blockIds = blockIds ?? [];
this.elementIds = elementIds ?? [];
}
static override fromJSON(json: Record<string, unknown>): HighlightSelection {
const result = ReferenceParamsSchema.parse(json);
return new HighlightSelection(result);
}
override equals(other: HighlightSelection): boolean {
return (
this.mode === other.mode &&
this.blockId === other.blockId &&
this.blockIds.length === other.blockIds.length &&
this.elementIds.length === other.elementIds.length &&
this.blockIds.every((id, n) => id === other.blockIds[n]) &&
this.elementIds.every((id, n) => id === other.elementIds[n])
);
}
override toJSON(): Record<string, unknown> {
return {
type: 'highlight',
mode: this.mode,
blockId: this.blockId,
blockIds: this.blockIds,
elementIds: this.elementIds,
};
}
}
declare global {
namespace BlockSuite {
interface Selection {
highlight: typeof HighlightSelection;
}
}
}
export const HighlightSelectionExtension =
SelectionExtension(HighlightSelection);
@@ -0,0 +1,41 @@
import { BaseSelection, SelectionExtension } from '@blocksuite/block-std';
import z from 'zod';
const ImageSelectionSchema = z.object({
blockId: z.string(),
});
export class ImageSelection extends BaseSelection {
static override group = 'note';
static override type = 'image';
static override fromJSON(json: Record<string, unknown>): ImageSelection {
const result = ImageSelectionSchema.parse(json);
return new ImageSelection(result);
}
override equals(other: BaseSelection): boolean {
if (other instanceof ImageSelection) {
return this.blockId === other.blockId;
}
return false;
}
override toJSON(): Record<string, unknown> {
return {
type: this.type,
blockId: this.blockId,
};
}
}
declare global {
namespace BlockSuite {
interface Selection {
image: typeof ImageSelection;
}
}
}
export const ImageSelectionExtension = SelectionExtension(ImageSelection);
@@ -0,0 +1,5 @@
export {
HighlightSelection,
HighlightSelectionExtension,
} from './hightlight.js';
export { ImageSelection, ImageSelectionExtension } from './image.js';