import { appendChild } from '../../utils/element' ; import { findInputElement } from '../../utils/findInputElement' ; import { updatePicker } from '../picker/update-picker' ; import { ComponentStatus , State } from '../../types/store' ; import { daysInMonth , getNext , getPre , joinDate , monthStartDay , } from '../../utils/date' ; import { getFormatDate } from '../util/format' ; import { getDate } from '../util/method' ; function options ( ) { this . page = this . type . replace ( 'week' , 'date' ) ; this . reference && ( this . reference . placeholder = this . placeholder ) ; } function appendPopover ( ) { if ( this . popover === null ) return ; const { insertTo } = this ; appendChild ( this . popover , insertTo === 'body' ? undefined : ( this . reference ?. parentNode as HTMLElement ) ) ; } function dispatchDateChange ( ) { const date = getDate ( this ) ; this . onChange ?. ( date ) ; if ( this . binding && this . reference ) { this . reference . value = getFormatDate . call ( this , date , this . format ) ; } } function updateDays ( this ) { const { month , year , _date } = this . start ; const [ preMonth , preYear ] = getPre ( month , year ) ; const preDays = daysInMonth ( preYear , preMonth ) ; const [ fd , days ] = [ monthStartDay ( year , month , this . locale . weekStart ) , daysInMonth ( year , month ) , ] ; _date . forEach ( ( item , index ) => { const idx = index + 1 ; const currentIdx = idx - fd ; const status = index < fd ? 'pre' : fd + days <= index ? 'next' : '' ; item . status = status ; const newDate = { pre ( ) { const day = preDays + currentIdx ; return [ String ( day ) , joinDate ( getPre ( month , year ) , day ) ] ; } , next ( ) { const day = currentIdx - days ; return [ String ( day ) , joinDate ( getNext ( month , year ) , day ) ] ; } , other ( ) { const date = joinDate ( month , year , currentIdx ) ; return [ String ( currentIdx ) , date ] ; } , } ; [ item . text , item . date ] = newDate [ status || 'other' ] ( ) ; } ) ; } function findReference ( ) { const { reference } = this ; if ( reference && ! ( reference instanceof HTMLInputElement ) ) { this . reference = findInputElement ( reference ) ; } } export default [ options , appendPopover , updatePicker , findReference , updateDays , dispatchDateChange , ] ;