import { Handle } from 'hypermerge' ; import ContentTypes from '../../../ContentTypes' ; import Board , { BOARD_COLORS } from './Board' ; import BoardInBoard from './BoardInBoard' ; import BoardInList from './BoardInList' ; import { HypermergeUrl , PushpinUrl } from '../../../ShareLink' ; export type CardId = string & { cardId : true ; } ; export interface BoardDocCard { url : PushpinUrl ; x : number ; y : number ; height ? : number ; width ? : number ; } export interface BoardDoc { title : string ; backgroundColor : string ; cards : { [ id ] : BoardDocCard ; } ; hypermergeUrl : HypermergeUrl ; authorIds : HypermergeUrl [ ] ; } interface Attrs { title ? : string ; backgroundColor ? : string ; } const BOARD_COLOR_VALUES = Object . values ( BOARD_COLORS ) ; function randomColor ( ) { return BOARD_COLOR_VALUES [ Math . floor ( Math . random ( ) * BOARD_COLOR_VALUES . length ) ] ; } function initializeBoard ( { title = 'No Title' , backgroundColor = randomColor ( ) } , handle ) { handle . change ( ( board ) => { board . title = title ; board . backgroundColor = backgroundColor ; board . cards = { } ; board . authorIds = [ ] ; } ) ; } function create ( typeAttrs , handle , callback ) { initializeBoard ( typeAttrs , handle ) ; callback ( ) ; } ContentTypes . register ( { type : 'board' , contexts : { workspace : Board , board : BoardInBoard , list : BoardInList } , name : 'Board' , icon : 'copy' , create } ) ;