88 type ExtractPropTypes ,
99 type PropType ,
1010 type SetupContext ,
11- type WatchSource ,
1211} from 'vue'
1312import { getLocale } from '../locale'
1413import { FieldWrapper , TextPosition , type CronFormat , type Field , type Period } from '../types'
@@ -235,26 +234,43 @@ export function useCron(options: CronOptions) {
235234export type UseCronReturn = ReturnType < typeof useCron >
236235
237236export function setupCron (
238- options : CronOptions ,
239- modelValue : WatchSource < string | undefined > ,
240- { emit } : SetupContext < [ 'update:model-value' , 'error' ] > ,
237+ props : CronCoreProps ,
238+ { emit } : SetupContext < [ 'update:model-value' , 'update:period' , 'error' ] > ,
241239) : UseCronReturn {
240+ const options : CronOptions = {
241+ ...props ,
242+ initialValue : props . modelValue ,
243+ initialPeriod : props . period ,
244+ }
245+
242246 const cron = useCron ( options )
243247
244248 watch (
245- modelValue ,
249+ ( ) => props . modelValue ,
246250 ( value ) => {
247251 if ( value ) {
248252 cron . cron . value = value
249253 }
250254 } ,
251- { immediate : true } ,
255+ )
256+
257+ watch (
258+ ( ) => props . period ,
259+ ( value ) => {
260+ if ( value ) {
261+ cron . period . select ( value )
262+ }
263+ } ,
252264 )
253265
254266 watch ( cron . cron , ( value ) => {
255267 emit ( 'update:model-value' , value )
256268 } )
257269
270+ watch ( cron . period . selected , ( value ) => {
271+ emit ( 'update:period' , value . id )
272+ } )
273+
258274 watch ( cron . error , ( error ) => {
259275 emit ( 'error' , error )
260276 } )
@@ -276,7 +292,7 @@ export const cronCoreProps = () => ({
276292 *
277293 * @defaultValue last entry of `CronCoreProps.periods`
278294 */
279- initialPeriod : {
295+ period : {
280296 type : String ,
281297 } ,
282298 /**
@@ -349,26 +365,9 @@ export type CronCoreProps = Partial<ExtractPropTypes<ReturnType<typeof cronCoreP
349365export const CronCore = defineComponent ( {
350366 name : 'VueCronCore' ,
351367 props : cronCoreProps ( ) ,
352- emits : [ 'update:model-value' , 'error' ] ,
368+ emits : [ 'update:model-value' , 'update:period' , ' error'] ,
353369 setup ( props , ctx ) {
354- const { cron, error, selected, period } = useCron ( props )
355-
356- watch ( cron , ( value ) => {
357- ctx . emit ( 'update:model-value' , value )
358- } )
359-
360- watch ( error , ( value ) => {
361- ctx . emit ( 'error' , value )
362- } )
363-
364- watch (
365- ( ) => props . modelValue ,
366- ( value ) => {
367- if ( value ) {
368- cron . value = value
369- }
370- } ,
371- )
370+ const { error, selected, period } = setupCron ( props , ctx )
372371
373372 return ( ) => {
374373 const slotProps = {
0 commit comments