mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 05:47:09 +08:00
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:
@@ -1,6 +1,5 @@
|
||||
import type {
|
||||
GfxBlockElementModel,
|
||||
GfxCompatibleProps,
|
||||
GfxElementGeometry,
|
||||
GfxGroupCompatibleInterface,
|
||||
GfxModel,
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
descendantElementsImpl,
|
||||
generateKeyBetweenV2,
|
||||
GfxCompatible,
|
||||
GfxCompatibleZodSchema,
|
||||
gfxGroupCompatibleSymbol,
|
||||
hasDescendantElementImpl,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
@@ -18,31 +18,33 @@ import { Bound } from '@blocksuite/global/utils';
|
||||
import { BlockModel, defineBlockSchema, type Text } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { type Color, ColorSchema } from '../../themes/index.js';
|
||||
|
||||
export type FrameBlockProps = {
|
||||
title: Text;
|
||||
background: Color;
|
||||
childElementIds?: Record<string, boolean>;
|
||||
presentationIndex?: string;
|
||||
} & GfxCompatibleProps;
|
||||
import { ColorSchema, DefaultTheme } from '../../themes/index.js';
|
||||
|
||||
export const FrameZodSchema = z
|
||||
.object({
|
||||
background: ColorSchema.optional(),
|
||||
background: ColorSchema,
|
||||
childElementIds: z.record(z.boolean()),
|
||||
presentationIndex: z.string(),
|
||||
})
|
||||
.default({});
|
||||
|
||||
export const FrameBlockSchema = defineBlockSchema({
|
||||
flavour: 'affine:frame',
|
||||
props: (internal): FrameBlockProps => ({
|
||||
title: internal.Text(),
|
||||
background: 'transparent',
|
||||
.and(GfxCompatibleZodSchema)
|
||||
.default({
|
||||
background: DefaultTheme.transparent,
|
||||
xywh: `[0,0,100,100]`,
|
||||
index: 'a0',
|
||||
childElementIds: Object.create(null),
|
||||
presentationIndex: generateKeyBetweenV2(null, null),
|
||||
lockedBySelf: false,
|
||||
});
|
||||
|
||||
export type FrameBlockProps = z.infer<typeof FrameZodSchema> & {
|
||||
title: Text;
|
||||
};
|
||||
|
||||
export const FrameBlockSchema = defineBlockSchema({
|
||||
flavour: 'affine:frame',
|
||||
props: (internal): FrameBlockProps => ({
|
||||
title: internal.Text(),
|
||||
...FrameZodSchema.parse(undefined),
|
||||
}),
|
||||
metadata: {
|
||||
version: 1,
|
||||
|
||||
Reference in New Issue
Block a user