fix(editor): add missing zod schema for edgeless frame (#10024)

Related to https://github.com/toeverything/AFFiNE/pull/9970#discussion_r1944971309

### What changes:
- Add missing zod shcema for edgeless basic props
- Change `applyLastProps` to generic function for better return type inference of
- Fix: add `ZodIntersection` case to `makeDeepOptional`
This commit is contained in:
L-Sun
2025-02-07 12:49:59 +00:00
parent 36ed81bcc6
commit 459972fe6c
7 changed files with 80 additions and 28 deletions

View File

@@ -25,7 +25,14 @@ import {
TextAlignSchema,
TextVerticalAlign,
} from '@blocksuite/affine-model';
import { z, ZodDefault, ZodObject, type ZodTypeAny, ZodUnion } from 'zod';
import {
z,
ZodDefault,
ZodIntersection,
ZodObject,
type ZodTypeAny,
ZodUnion,
} from 'zod';
const ConnectorEndpointSchema = z.nativeEnum(PointStyle);
const LineWidthSchema = z.nativeEnum(LineWidth);
@@ -183,6 +190,11 @@ export function makeDeepOptional(schema: ZodTypeAny): ZodTypeAny {
return z.object(deepOptionalShape).optional();
} else if (schema instanceof ZodUnion) {
return schema.or(z.undefined());
} else if (schema instanceof ZodIntersection) {
return z.intersection(
makeDeepOptional(schema._def.left),
makeDeepOptional(schema._def.right)
);
} else {
return schema.optional();
}