mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
feat(core): frame editor settings (#9970)
Co-authored-by: L-Sun <zover.v@gmail.com> Co-authored-by: Mirone <Saul-Mirone@outlook.com>
This commit is contained in:
@@ -29,10 +29,8 @@ export {
|
||||
export {
|
||||
GfxBlockElementModel,
|
||||
type GfxCommonBlockProps,
|
||||
GfxCommonBlockZodSchema,
|
||||
GfxCompatibleBlockModel as GfxCompatible,
|
||||
type GfxCompatibleProps,
|
||||
GfxCompatibleZodSchema,
|
||||
} from './model/gfx-block-model.js';
|
||||
export { type GfxModel } from './model/model.js';
|
||||
export {
|
||||
|
||||
@@ -15,10 +15,8 @@ import {
|
||||
polygonGetPointTangent,
|
||||
polygonNearestPoint,
|
||||
rotatePoints,
|
||||
SerializedXYWHZodSchema,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { BlockModel } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
isLockedByAncestorImpl,
|
||||
@@ -35,24 +33,20 @@ import type { SurfaceBlockModel } from './surface/surface-model.js';
|
||||
/**
|
||||
* The props that a graphics block model should have.
|
||||
*/
|
||||
export const GfxCompatibleZodSchema = z.object({
|
||||
xywh: SerializedXYWHZodSchema,
|
||||
index: z.string(),
|
||||
lockedBySelf: z.boolean().optional(),
|
||||
});
|
||||
export type GfxCompatibleProps = z.infer<typeof GfxCompatibleZodSchema>;
|
||||
export type GfxCompatibleProps = {
|
||||
xywh: SerializedXYWH;
|
||||
index: string;
|
||||
lockedBySelf?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* This type include the common props for the graphic block model.
|
||||
* You can use this type with Omit to define the props of a graphic block model.
|
||||
*/
|
||||
export const GfxCommonBlockZodSchema = GfxCompatibleZodSchema.and(
|
||||
z.object({
|
||||
rotate: z.number(),
|
||||
scale: z.number(),
|
||||
})
|
||||
);
|
||||
export type GfxCommonBlockProps = z.infer<typeof GfxCommonBlockZodSchema>;
|
||||
export type GfxCommonBlockProps = GfxCompatibleProps & {
|
||||
rotate: number;
|
||||
scale: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* The graphic block model that can be rendered in the graphics mode.
|
||||
|
||||
@@ -16,5 +16,4 @@ export * from './slot.js';
|
||||
export * from './types.js';
|
||||
export * from './with-disposable.js';
|
||||
export type { SerializedXYWH, XYWH } from './xywh.js';
|
||||
export { SerializedXYWHZodSchema } from './xywh.js';
|
||||
export { deserializeXYWH, serializeXYWH } from './xywh.js';
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* XYWH represents the x, y, width, and height of an element or block.
|
||||
*/
|
||||
@@ -10,30 +8,6 @@ export type XYWH = [number, number, number, number];
|
||||
*/
|
||||
export type SerializedXYWH = `[${number},${number},${number},${number}]`;
|
||||
|
||||
export const SerializedXYWHZodSchema = z.custom<SerializedXYWH>((val: any) => {
|
||||
if (typeof val !== 'string') {
|
||||
throw new Error('SerializedXYWH should be a string');
|
||||
}
|
||||
|
||||
if (!val.startsWith('[') || !val.endsWith(']')) {
|
||||
throw new Error('SerializedXYWH should be wrapped in square brackets');
|
||||
}
|
||||
|
||||
const parts = val.slice(1, -1).split(',');
|
||||
|
||||
if (parts.length !== 4) {
|
||||
throw new Error('SerializedXYWH should have 4 parts');
|
||||
}
|
||||
|
||||
for (const part of parts) {
|
||||
if (!/^\d+$/.test(part)) {
|
||||
throw new Error('Each part of SerializedXYWH should be a number');
|
||||
}
|
||||
}
|
||||
|
||||
return val as SerializedXYWH;
|
||||
});
|
||||
|
||||
export function serializeXYWH(
|
||||
x: number,
|
||||
y: number,
|
||||
|
||||
Reference in New Issue
Block a user