@@ -306,7 +306,7 @@ let CalendarBasicComp = (function () {
306306 ...( item . groupId ? { groupId : item . groupId } : { } ) ,
307307 backgroundColor : item . backgroundColor ,
308308 extendedProps : { // Ensure color is in extendedProps
309- color : isValidColor ( item . color || "" ) ? item . color : theme ?. theme ?. primary ,
309+ color : isValidColor ( item . color || "" ) ? item . color : theme ?. theme ?. primary ,
310310 detail : item . detail ,
311311 titleColor :item . titleColor ,
312312 detailColor :item . detailColor ,
@@ -324,22 +324,13 @@ let CalendarBasicComp = (function () {
324324 } , [ currentEvents , theme ] )
325325
326326 useEffect ( ( ) => {
327+ if ( initData . current ) return ;
328+
327329 const mapData : Record < string , number > = { } ;
328330 events ?. forEach ( ( item : any , index : number ) => {
329331 mapData [ `${ item . id } ` ] = index ;
330332 } )
331333
332- if ( initData . current ) {
333- const difference = differenceWith ( events , props . initialData , isEqual ) ;
334- const inserted = differenceBy ( difference , Object . keys ( initDataMap ) ?. map ( id => ( { id } ) ) , 'id' )
335- const updated = filter ( difference , obj => includes ( Object . keys ( initDataMap ) , String ( obj . id ) ) ) ;
336- const deleted = differenceBy ( props . initialData , Object . keys ( mapData ) ?. map ( id => ( { id } ) ) , 'id' )
337-
338- comp . children ?. comp . children ?. updatedEvents . dispatchChangeValueAction ( updated ) ;
339- comp . children ?. comp . children ?. insertedEvents . dispatchChangeValueAction ( inserted ) ;
340- comp . children ?. comp . children ?. deletedEvents . dispatchChangeValueAction ( deleted ) ;
341- }
342-
343334 if ( ! initData . current && events ?. length && comp ?. children ?. comp ?. children ?. initialData ) {
344335 setInitDataMap ( mapData ) ;
345336 comp ?. children ?. comp ?. children ?. initialData ?. dispatch ?.(
@@ -407,7 +398,54 @@ let CalendarBasicComp = (function () {
407398 }
408399 } , [ slotLabelFormat , slotLabelFormatWeek , slotLabelFormatMonth ] ) ;
409400
410- const handleEventDataChange = useCallback ( ( data : Array < Record < string , any > > ) => {
401+ const findUpdatedInsertedDeletedEvents = useCallback ( ( data : Array < EventType > ) => {
402+ if ( ! initData . current ) return ;
403+
404+ let eventsData : Array < Record < string , any > > = currentView == "resourceTimelineDay" || currentView == "resourceTimeGridDay"
405+ ? data . filter ( ( event : { resourceId ?: string ; } ) => Boolean ( event . resourceId ) )
406+ : data . filter ( ( event : { resourceId ?: string ; } ) => ! Boolean ( event . resourceId ) ) ;
407+
408+ eventsData = eventsData . map ( ( item ) => ( {
409+ title : item . label ,
410+ id : item . id ,
411+ start : dayjs ( item . start , DateParser ) . format ( ) ,
412+ end : dayjs ( item . end , DateParser ) . format ( ) ,
413+ allDay : item . allDay ,
414+ ...( item . resourceId ? { resourceId : item . resourceId } : { } ) ,
415+ ...( item . groupId ? { groupId : item . groupId } : { } ) ,
416+ backgroundColor : item . backgroundColor ,
417+ extendedProps : { // Ensure color is in extendedProps
418+ color : isValidColor ( item . color || "" ) ? item . color : theme ?. theme ?. primary ,
419+ detail : item . detail ,
420+ titleColor :item . titleColor ,
421+ detailColor :item . detailColor ,
422+ titleFontWeight :item . titleFontWeight ,
423+ titleFontStyle :item . titleFontStyle ,
424+ detailFontWeight :item . detailFontWeight ,
425+ detailFontStyle :item . detailFontStyle ,
426+ animation :item ?. animation ,
427+ animationDelay :item ?. animationDelay ,
428+ animationDuration :item ?. animationDuration ,
429+ animationIterationCount :item ?. animationIterationCount
430+ }
431+ } ) ) ;
432+
433+ const mapData : Record < string , number > = { } ;
434+ eventsData ?. forEach ( ( item : any , index : number ) => {
435+ mapData [ `${ item . id } ` ] = index ;
436+ } )
437+
438+ const difference = differenceWith ( eventsData , props . initialData , isEqual ) ;
439+ const inserted = differenceBy ( difference , Object . keys ( initDataMap ) ?. map ( id => ( { id } ) ) , 'id' )
440+ const updated = filter ( difference , obj => includes ( Object . keys ( initDataMap ) , String ( obj . id ) ) ) ;
441+ const deleted = differenceBy ( props . initialData , Object . keys ( mapData ) ?. map ( id => ( { id } ) ) , 'id' )
442+
443+ comp ?. children ?. comp ?. children ?. updatedEvents . dispatchChangeValueAction ( updated ) ;
444+ comp ?. children ?. comp ?. children ?. insertedEvents . dispatchChangeValueAction ( inserted ) ;
445+ comp ?. children ?. comp ?. children ?. deletedEvents . dispatchChangeValueAction ( deleted ) ;
446+ } , [ initDataMap , currentView , props . initialData , initData . current ] ) ;
447+
448+ const handleEventDataChange = useCallback ( ( data : Array < EventType > ) => {
411449 comp ?. children ?. comp . children . events . children . manual . children . manual . dispatch (
412450 comp ?. children ?. comp . children . events . children . manual . children . manual . setChildrensAction (
413451 data
@@ -416,6 +454,9 @@ let CalendarBasicComp = (function () {
416454 comp ?. children ?. comp . children . events . children . mapData . children . data . dispatchChangeValueAction (
417455 JSON . stringify ( data )
418456 ) ;
457+
458+ findUpdatedInsertedDeletedEvents ( data ) ;
459+
419460 props . onEvent ( "change" ) ;
420461 } , [ comp , props . onEvent ] ) ;
421462
@@ -955,9 +996,9 @@ let CalendarBasicComp = (function () {
955996 changeEvents . push ( event ) ;
956997 }
957998 } ) ;
958- if ( needChange ) {
959- props . onEvent ( "change" ) ;
960- }
999+ // if (needChange) {
1000+ // props.onEvent("change");
1001+ // }
9611002 } }
9621003 eventDragStart = { ( ) => {
9631004 if ( typeof props . onDropEvent === 'function' ) {
0 commit comments