import * as React from "react" ; import { Grip , Point } from "./geometry" ; export interface ShapeContent { content : JSX . Element ; settings ? : JSX . Element ; grips : Grip [ ] ; outline : Point [ ] ; offset ( delta ) : void ; commit ( keep ) : void ; dispose ( ) : void ; } export function placeholder ( type ) { type ; return { get content ( ) { return React . createElement ( "g" ) ; } , get settings ( ) { return React . createElement ( "div" ) ; } , offset ( ) { } , commit ( ) { } , grips : [ ] , outline : [ ] , json : undefined , dispose ( ) { } } as ShapeContent ; } ; const types = { } ; export const factory = { register ( type , displayName , alloc ) { if ( types [ type ] ) { throw new Error ( `Duplicate type: ${ type }` ) ; } types [ type ] = { displayName , alloc } ; } , alloc ( type ) { const registration = types [ type ] ; if ( ! registration ) { return placeholder ( type ) ; } return registration . alloc ( ) ; } , types ( ) { return Object . keys ( types ) ; } , displayName ( type ) { return ( types [ type ] || { displayName : `Unknown: ${ type }` } ) . displayName ; } } ;