import { BaseRecord } from '@bigbluebutton/store' import { Expand, JsonObject } from '@bigbluebutton/utils' import { T } from '@bigbluebutton/validate' import { TLOpacityType, opacityValidator } from '../misc/TLOpacity' import { idValidator } from '../misc/id-validator' import { TLParentId, TLShapeId } from '../records/TLShape' /** @public */ export interface TLBaseShape extends BaseRecord<'shape', TLShapeId> { type: Type x: number y: number rotation: number index: string parentId: TLParentId isLocked: boolean opacity: TLOpacityType props: Props meta: JsonObject whiteboardId?: string } /** @public */ export const parentIdValidator = T.string.refine((id) => { if (!id.startsWith('page:') && !id.startsWith('shape:')) { throw new Error('Parent ID must start with "page:" or "shape:"') } return id as TLParentId }) /** @public */ export const shapeIdValidator = idValidator('shape') /** @public */ export function createShapeValidator< Type extends string, Props extends JsonObject, Meta extends JsonObject >( type: Type, props?: { [K in keyof Props]: T.Validatable }, meta?: { [K in keyof Meta]: T.Validatable } ) { return T.object>({ id: shapeIdValidator, typeName: T.literal('shape'), x: T.number, y: T.number, rotation: T.number, index: T.string, parentId: parentIdValidator, type: T.literal(type), isLocked: T.boolean, opacity: opacityValidator, props: props ? T.object(props) : (T.jsonValue as T.ObjectValidator), meta: meta ? T.object(meta) : (T.jsonValue as T.ObjectValidator), whiteboardId: T.optional(T.string), // Needed when akka-bbb-apps sends data to the whiteboard }) } /** @public */ export type ShapeProps> = { [K in keyof Shape['props']]: T.Validatable } export type ShapePropsType>> = Expand<{ [K in keyof Config]: T.TypeOf }>