import * as React from "react" ; import { memberIsWindup , Windup , lastPlayedMember , isUnplayed } from "../Windup" ; import { HookMetadata } from "./useWindup" ; type OnCharProps = { fn : ( char : string ) => void ; } ; const OnChar = ( { children } ) => { return < > { children } < />; } ; export function isOnCharElement ( element ) { return element . type === OnChar ; } export function onCharsFromWindup < M extends HookMetadata , W extends Windup < string , M > > ( windup ) { const [ , remaining , metadata ] = windup ; const lastPlayed = lastPlayedMember ( windup ) ; const [ firstRemaining ] = remaining ; let onChars = [ ] ; if ( lastPlayed && memberIsWindup ( lastPlayed ) ) { onChars . push ( ... onCharsFromWindup ( lastPlayed ) ) ; } if ( firstRemaining && memberIsWindup ( firstRemaining ) && ! isUnplayed ( firstRemaining ) ) { onChars . push ( ... onCharsFromWindup ( firstRemaining ) ) ; } if ( metadata . onChar ) { onChars . push ( metadata . onChar ) ; } return onChars ; } export default OnChar ;