@@ -4,6 +4,8 @@ import { default as ColorPicker } from "antd/es/color-picker";
44import { trans , getCalendarLocale } from "../../i18n/comps" ;
55import { createRef , useContext , useRef , useState , useEffect , useCallback } from "react" ;
66import dayjs from "dayjs" ;
7+ import utc from "dayjs/plugin/utc" ;
8+ import timezone from "dayjs/plugin/timezone" ;
79import FullCalendar from "@fullcalendar/react" ;
810import resourceTimelinePlugin from "@fullcalendar/resource-timeline" ;
911import resourceTimeGridPlugin from "@fullcalendar/resource-timegrid" ;
@@ -54,6 +56,7 @@ import {
5456 migrateOldData ,
5557 controlItem ,
5658 depsConfig ,
59+ stringExposingStateControl
5760} from 'lowcoder-sdk' ;
5861
5962import {
@@ -80,6 +83,10 @@ import {
8083} from "./calendarConstants" ;
8184import { EventOptionControl } from "./eventOptionsControl" ;
8285import { timeZoneOptions } from "./timeZone" ;
86+ import { Select } from 'antd' ;
87+
88+ dayjs . extend ( utc ) ;
89+ dayjs . extend ( timezone ) ;
8390
8491function fixOldData ( oldData : any ) {
8592 if ( ! Boolean ( oldData ) ) return ;
@@ -152,6 +159,8 @@ let childrenMap: any = {
152159 currentPremiumView : dropdownControl ( DefaultWithPremiumViewOptions , "resourceTimelineDay" ) ,
153160 animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
154161 timeZone : dropdownControl ( timeZoneOptions , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
162+ showVerticalScrollbar : withDefault ( BoolControl , false ) ,
163+ userTimeZone : stringExposingStateControl ( "userTimeZone" , Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ) ,
155164} ;
156165
157166// this should ensure backwards compatibility with older versions of the SDK
@@ -191,6 +200,8 @@ let CalendarBasicComp = (function () {
191200 animationStyle ?:any ;
192201 modalStyle ?:any ;
193202 timeZone ?: string ;
203+ showVerticalScrollbar ?:boolean
204+ userTimeZone ?:any
194205 } ) => {
195206 const comp = useContext ( EditorContext ) ?. getUICompByName (
196207 useContext ( CompNameContext )
@@ -208,6 +219,12 @@ let CalendarBasicComp = (function () {
208219 setLicensed ( props . licenseKey !== "" ) ;
209220 } , [ props . licenseKey ] ) ;
210221
222+ useEffect ( ( ) => {
223+ form . setFieldsValue ( {
224+ userTimeZone : Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ,
225+ } ) ;
226+ } , [ ] ) ;
227+
211228 let currentView = licensed ? props . currentPremiumView : props . currentFreeView ;
212229 let currentEvents = currentView == "resourceTimelineDay" || currentView == "resourceTimeGridDay"
213230 ? props . events . filter ( ( event : { resourceId : any ; } ) => Boolean ( event . resourceId ) )
@@ -318,7 +335,8 @@ let CalendarBasicComp = (function () {
318335 licenseKey,
319336 resourceName,
320337 modalStyle,
321- timeZone
338+ timeZone,
339+ showVerticalScrollbar
322340 } = props ;
323341
324342 const handleEventDataChange = useCallback ( ( data : Array < Record < string , any > > ) => {
@@ -445,6 +463,12 @@ let CalendarBasicComp = (function () {
445463 }
446464 }
447465 } ;
466+ const handleDateZoneChange = ( newTimeZone : any ) => {
467+ props . userTimeZone . onChange ( newTimeZone )
468+ form . setFieldsValue ( {
469+ userTimeZone :newTimeZone
470+ } ) ;
471+ }
448472
449473 const handleCreate = ( info : DateSelectArg ) => {
450474 const event = {
@@ -502,19 +526,26 @@ let CalendarBasicComp = (function () {
502526 name = "detail"
503527 >
504528 < Input />
505- </ Form . Item >
506- < Form . Item
507- label = { trans ( "calendar.timeZone" ) }
508- name = "timeZone"
509- >
510- < Input />
511- </ Form . Item >
529+ </ Form . Item >
512530 < Form . Item
513531 label = { trans ( "calendar.timeRange" ) }
514532 name = "timeRange"
515533 >
516534 < Input />
517535 </ Form . Item >
536+ { props . timeZone === "UserChoice" &&
537+ < Form . Item
538+ label = { trans ( "calendar.timeZone" ) }
539+ name = "userTimeZone"
540+ >
541+ < Select
542+ // defaultValue={form.getFieldValue('userTimeZone')}
543+ value = { form . getFieldValue ( 'userTimeZone' ) }
544+ style = { { width : 340 , borderRadius :2 } }
545+ onChange = { ( value ) => { handleDateZoneChange ( value ) } }
546+ options = { timeZoneOptions . filter ( option => option . value !== 'UserChoice' ) }
547+ />
548+ </ Form . Item > }
518549 </ FormWrapper >
519550 </ Tabs . TabPane >
520551 < Tabs . TabPane tab = { trans ( "calendar.advanced" ) } key = "2" >
@@ -669,6 +700,8 @@ let CalendarBasicComp = (function () {
669700 detail,
670701 groupId,
671702 resourceId,
703+ userTimeZone,
704+ timeRange,
672705 color,
673706 backgroundColor,
674707 titleColor,
@@ -695,11 +728,13 @@ let CalendarBasicComp = (function () {
695728 if ( item . id === eventId ) {
696729 return {
697730 ...item ,
698- label,
699- detail,
700- id ,
731+ ... ( label !== undefined ? { label } : null ) ,
732+ ... ( detail !== undefined ? { detail } : null ) ,
733+ ... ( id !== undefined ? { id } : null ) ,
701734 ...( groupId !== undefined ? { groupId } : null ) ,
702735 ...( resourceId !== undefined ? { resourceId } : null ) ,
736+ ...( userTimeZone !== undefined ? { userTimeZone } : null ) ,
737+ ...( timeRange !== undefined ? { timeRange } : null ) ,
703738 ...( color !== undefined ? { color } : null ) ,
704739 ...( backgroundColor !== undefined ? { backgroundColor } : null ) ,
705740 ...( titleColor !== undefined ? { titleColor } : null ) ,
@@ -734,6 +769,8 @@ let CalendarBasicComp = (function () {
734769 animationDelay,
735770 animationDuration,
736771 animationIterationCount,
772+ ...( userTimeZone !== undefined ? { userTimeZone } : null ) ,
773+ ...( timeRange !== undefined ? { timeRange } : null ) ,
737774 ...( groupId !== undefined ? { groupId } : null ) ,
738775 ...( resourceId !== undefined ? { resourceId } : null ) ,
739776 ...( color !== undefined ? { color } : null ) ,
@@ -765,6 +802,7 @@ let CalendarBasicComp = (function () {
765802 $editable = { editable }
766803 $style = { style }
767804 $theme = { theme ?. theme }
805+ $showVerticalScrollbar = { showVerticalScrollbar }
768806 onDoubleClick = { handleDbClick }
769807 $left = { left }
770808 key = { initialDate ? currentView + initialDate : currentView }
@@ -893,8 +931,9 @@ let CalendarBasicComp = (function () {
893931 style : { getPropertyView : ( ) => any ; } ;
894932 animationStyle : { getPropertyView : ( ) => any ; } ;
895933 modalStyle : { getPropertyView : ( ) => any ; } ;
896- licenseKey : { getView : ( ) => any ; propertyView : ( arg0 : { label : string ; tooltip : string ; } ) => any ; } ;
934+ licenseKey : { getView : ( ) => any ; propertyView : ( arg0 : { label : string ; } ) => any ; } ;
897935 timeZone : { propertyView : ( arg0 : { label : string ; } ) => any ; } ;
936+ showVerticalScrollbar : { propertyView : ( arg0 : { label : string ; } ) => any ; } ;
898937 } ) => {
899938 const license = children . licenseKey . getView ( ) ;
900939
@@ -942,6 +981,7 @@ let CalendarBasicComp = (function () {
942981 ? children . currentFreeView . propertyView ( { label : trans ( "calendar.defaultView" ) , tooltip : trans ( "calendar.defaultViewTooltip" ) , } )
943982 : children . currentPremiumView . propertyView ( { label : trans ( "calendar.defaultView" ) , tooltip : trans ( "calendar.defaultViewTooltip" ) , } ) }
944983 { children . firstDay . propertyView ( { label : trans ( "calendar.startWeek" ) , } ) }
984+ { children . showVerticalScrollbar . propertyView ( { label : trans ( "calendar.showVerticalScrollbar" ) } ) }
945985 </ Section >
946986 < Section name = { sectionNames . style } >
947987 { children . style . getPropertyView ( ) }
@@ -958,6 +998,17 @@ let CalendarBasicComp = (function () {
958998 . build ( ) ;
959999} ) ( ) ;
9601000
1001+ const getTimeZoneInfo = ( timeZone : any , otherTimeZone : any ) => {
1002+ const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone ;
1003+
1004+ const dateInTz = dayjs ( ) . tz ( tz ) ;
1005+ const offset = dateInTz . format ( 'Z' ) ;
1006+ const timeZoneName = new Intl . DateTimeFormat ( 'en-US' , { timeZone : tz , timeZoneName : 'short' } )
1007+ . formatToParts ( ) . find ( part => part . type === 'timeZoneName' ) ?. value ;
1008+
1009+ return { TimeZone : tz , Offset : offset , Name : timeZoneName } ;
1010+ } ;
1011+
9611012CalendarBasicComp = class extends CalendarBasicComp {
9621013 override autoHeight ( ) : boolean {
9631014 return false ;
@@ -993,6 +1044,12 @@ const TmpCalendarComp = withExposingConfigs(CalendarBasicComp, [
9931044 return input . events . filter ( event => Boolean ( event . resourceId ) ) ;
9941045 } ,
9951046 } ) ,
1047+ depsConfig ( {
1048+ name : "timeZone" ,
1049+ desc : trans ( "calendar.timeZone" ) ,
1050+ depKeys : [ "timeZone" , ] ,
1051+ func : ( input : { timeZone : any ; userTimeZone : any ; } ) => getTimeZoneInfo ( input . timeZone , input . userTimeZone )
1052+ } ) ,
9961053] ) ;
9971054
9981055let CalendarComp = withMethodExposing ( TmpCalendarComp , [
0 commit comments