refactor(editor): move zod schema with model for non surface blocks (#9876)

This commit is contained in:
doodlewind
2025-01-23 10:57:49 +00:00
parent d6cfbec5c9
commit 872a578bf7
6 changed files with 85 additions and 66 deletions

View File

@@ -2,39 +2,35 @@ import {
ColorSchema,
ConnectorMode,
DEFAULT_FRONT_END_POINT_STYLE,
DEFAULT_NOTE_BORDER_SIZE,
DEFAULT_NOTE_BORDER_STYLE,
DEFAULT_NOTE_CORNER,
DEFAULT_NOTE_SHADOW,
DEFAULT_REAR_END_POINT_STYLE,
DEFAULT_ROUGHNESS,
DefaultTheme,
EdgelessTextZodSchema,
FontFamily,
FontFamilySchema,
FontStyle,
FontStyleSchema,
FontWeight,
FontWeightSchema,
FrameZodSchema,
LayoutType,
LineWidth,
MindmapStyle,
NoteDisplayMode,
NoteShadowsSchema,
NoteZodSchema,
PointStyle,
ShapeStyle,
StrokeStyle,
StrokeStyleSchema,
TextAlign,
TextAlignSchema,
TextVerticalAlign,
} from '@blocksuite/affine-model';
import { z, ZodDefault, ZodObject, type ZodTypeAny, ZodUnion } from 'zod';
const ConnectorEndpointSchema = z.nativeEnum(PointStyle);
const StrokeStyleSchema = z.nativeEnum(StrokeStyle);
const LineWidthSchema = z.nativeEnum(LineWidth);
const ShapeStyleSchema = z.nativeEnum(ShapeStyle);
const FontFamilySchema = z.nativeEnum(FontFamily);
const FontWeightSchema = z.nativeEnum(FontWeight);
const FontStyleSchema = z.nativeEnum(FontStyle);
const TextAlignSchema = z.nativeEnum(TextAlign);
const TextVerticalAlignSchema = z.nativeEnum(TextVerticalAlign);
const NoteDisplayModeSchema = z.nativeEnum(NoteDisplayMode);
const ConnectorModeSchema = z.nativeEnum(ConnectorMode);
const LayoutTypeSchema = z.nativeEnum(LayoutType);
const MindmapStyleSchema = z.nativeEnum(MindmapStyle);
@@ -145,48 +141,6 @@ export const TextSchema = z
textAlign: TextAlign.Left,
});
export const EdgelessTextSchema = z
.object({
color: ColorSchema,
fontFamily: FontFamilySchema,
fontWeight: FontWeightSchema,
fontStyle: FontStyleSchema,
textAlign: TextAlignSchema,
})
.default({
color: DefaultTheme.textColor,
fontFamily: FontFamily.Inter,
fontWeight: FontWeight.Regular,
fontStyle: FontStyle.Normal,
textAlign: TextAlign.Left,
});
export const NoteSchema = z
.object({
background: ColorSchema,
displayMode: NoteDisplayModeSchema,
edgeless: z.object({
style: z.object({
borderRadius: z.number(),
borderSize: z.number(),
borderStyle: StrokeStyleSchema,
shadowType: NoteShadowsSchema,
}),
}),
})
.default({
background: DefaultTheme.noteBackgrounColor,
displayMode: NoteDisplayMode.EdgelessOnly,
edgeless: {
style: {
borderRadius: DEFAULT_NOTE_CORNER,
borderSize: DEFAULT_NOTE_BORDER_SIZE,
borderStyle: DEFAULT_NOTE_BORDER_STYLE,
shadowType: DEFAULT_NOTE_SHADOW,
},
},
});
export const MindmapSchema = z
.object({
layoutType: LayoutTypeSchema,
@@ -197,20 +151,14 @@ export const MindmapSchema = z
style: MindmapStyle.ONE,
});
export const FrameSchema = z
.object({
background: ColorSchema.optional(),
})
.default({});
export const NodePropsSchema = z.object({
connector: ConnectorSchema,
brush: BrushSchema,
text: TextSchema,
mindmap: MindmapSchema,
'affine:edgeless-text': EdgelessTextSchema,
'affine:note': NoteSchema,
'affine:frame': FrameSchema,
'affine:edgeless-text': EdgelessTextZodSchema,
'affine:note': NoteZodSchema,
'affine:frame': FrameZodSchema,
// shapes
'shape:diamond': ShapeSchema,
'shape:ellipse': ShapeSchema,