@@ -17,6 +17,8 @@ import {
1717 InspectorBottomTip ,
1818 AdvancedToggleControl ,
1919 useBlockCssGenerator ,
20+ ControlSeparator ,
21+ AdvancedSelectControl ,
2022} from '~stackable/components'
2123import {
2224 BlockDiv ,
@@ -38,6 +40,8 @@ import {
3840 withQueryLoopContext ,
3941} from '~stackable/higher-order'
4042
43+ import { timezones as TIMEZONE_OPTIONS } from '../countdown'
44+
4145/**
4246 * WordPress dependencies
4347 */
@@ -46,6 +50,8 @@ import { InnerBlocks } from '@wordpress/block-editor'
4650import { __ } from '@wordpress/i18n'
4751import { addFilter } from '@wordpress/hooks'
4852import { memo } from '@wordpress/element'
53+ import { DateTimePicker } from '@wordpress/components'
54+ import { getSettings as getDateSettings } from '@wordpress/date'
4955
5056export const defaultIcon = '<svg data-prefix="fas" data-icon="play" class="svg-inline--fa fa-play fa-w-14" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" aria-hidden="true"><path fill="currentColor" d="M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"></path></svg>'
5157
@@ -104,7 +110,10 @@ const Edit = props => {
104110 setAttributes = { setAttributes }
105111 videoLink = { attributes . videoLink }
106112 videoId = { attributes . videoId }
107-
113+ videoName = { attributes . videoName }
114+ videoUploadDate = { attributes . videoUploadDate }
115+ videoDescription = { attributes . videoDescription }
116+ videoUploadDateTimezone = { attributes . videoUploadDateTimezone }
108117 />
109118
110119 { blockCss && < style key = "block-css" > { blockCss } </ style > }
@@ -129,14 +138,36 @@ const Edit = props => {
129138}
130139
131140const InspectorControls = memo ( props => {
141+ const getUploadDate = ( uploadDate , timezone ) => {
142+ // If it uses local timezone, get offset from WordPress settings
143+ if ( ! timezone ) {
144+ const { timezone : localTimezone } = getDateSettings ( )
145+ const offset = Number ( localTimezone . offset )
146+ const hours = Math . floor ( Math . abs ( offset ) )
147+ const minutes = Math . round ( ( Math . abs ( offset ) % 1 ) * 60 )
148+
149+ return uploadDate + ( offset >= 0 ? '+' : '-' ) +
150+ String ( hours ) . padStart ( 2 , '0' ) + ':' +
151+ String ( minutes ) . padStart ( 2 , '0' )
152+ }
153+
154+ const date = new Date ( uploadDate )
155+ const offset = new Intl . DateTimeFormat ( 'en-US' , {
156+ timeZone : timezone ,
157+ timeZoneName : 'longOffset' ,
158+ } ) . format ( date ) . slice ( - 6 )
159+
160+ return uploadDate + offset
161+ }
162+
132163 return (
133164 < >
134165 < InspectorTabs hasLayoutPanel = { false } />
135166
136167 < InspectorStyleControls >
137168 < PanelAdvancedSettings
138169 title = { __ ( 'General' , i18n ) }
139- id = "general "
170+ id = "video-popup "
140171 initialOpen = { true }
141172 >
142173 < ImageControl2
@@ -146,11 +177,17 @@ const InspectorControls = memo( props => {
146177 onRemove = { ( ) => props . setAttributes ( {
147178 videoLink : '' ,
148179 videoId : '' ,
180+ videoName : '' ,
181+ videoDescription : '' ,
182+ videoUploadDate : '' ,
149183 } ) }
150184 onChange = { media => {
151185 props . setAttributes ( {
152186 videoLink : media . url ,
153187 videoId : media . url ,
188+ videoName : media . title , // Use title, description and date from media library for video schema
189+ videoDescription : media . description ,
190+ videoUploadDate : media . date . toISOString ( ) ,
154191 } )
155192 } }
156193 imageId = { urlIsVideo ( props . videoLink ) ? props . videoId : '' }
@@ -164,10 +201,16 @@ const InspectorControls = memo( props => {
164201 isFormatType = { false }
165202 placeholder = "https://"
166203 value = { ! urlIsVideo ( props . videoLink ) ? props . videoLink : '' }
167- onChange = { videoLink => props . setAttributes ( {
168- videoLink,
169- videoId : getVideoProviderFromURL ( videoLink ) . id ,
170- } ) }
204+ onChange = { videoLink => {
205+ const videoProvider = getVideoProviderFromURL ( videoLink )
206+ props . setAttributes ( {
207+ videoLink,
208+ videoId : videoProvider . id ,
209+ videoName : '' ,
210+ videoDescription : '' ,
211+ videoUploadDate : '' ,
212+ } )
213+ } }
171214 />
172215 { isVideoFile ( props . videoLink ) && < >
173216 < AdvancedToggleControl
@@ -186,6 +229,43 @@ const InspectorControls = memo( props => {
186229 defaultValue = { false }
187230 />
188231 </ > }
232+ { props . videoLink && < >
233+ < ControlSeparator />
234+ < p > { __ ( 'Note: The following attributes are used to create the video schema.' , i18n ) } </ p >
235+ < AdvancedTextControl
236+ label = { __ ( 'Video name' , i18n ) }
237+ value = { props . videoName }
238+ onChange = { videoName => props . setAttributes ( { videoName } ) }
239+ />
240+ < AdvancedTextControl
241+ label = { __ ( 'Video description' , i18n ) }
242+ value = { props . videoDescription }
243+ onChange = { videoDescription => props . setAttributes ( { videoDescription } ) }
244+ isMultiline = { true }
245+ />
246+ < AdvancedTextControl
247+ // The date picker below always highlights a date even if there is no `videoUploadDate` attribute
248+ // This text control allows users to see if a date has been set/removed
249+ className = "stk-components-datetime__date-input"
250+ label = { __ ( 'Video upload date' , i18n ) }
251+ value = { props . videoUploadDate ? getUploadDate ( props . videoUploadDate , props . videoUploadDateTimezone ) : '' }
252+ onChange = { videoUploadDate => props . setAttributes ( { videoUploadDate } ) }
253+ inputType = "date"
254+ readOnly = { true }
255+ />
256+ < DateTimePicker
257+ currentDate = { props . videoUploadDate }
258+ is12Hour = { true }
259+ onChange = { videoUploadDate => props . setAttributes ( { videoUploadDate } ) }
260+ />
261+ < AdvancedSelectControl
262+ label = { __ ( 'Timezone' , i18n ) }
263+ options = { TIMEZONE_OPTIONS }
264+ attribute = "videoUploadDateTimezone"
265+ allowReset = { false }
266+ />
267+ </ > }
268+
189269 </ PanelAdvancedSettings >
190270
191271 </ InspectorStyleControls >
0 commit comments