Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function PostSchedule( { date, onUpdateDate } ) {
const settings = __experimentalGetSettings();
// To know if the current timezone is a 12 hour time with look for "a" in the time format
// We also make sure this a is not escaped by a "/"
const is12HourTime = /a(?!\\)/i.test(
settings.formats.time
.toLowerCase() // Test only the lower case a
.replace( /\\\\/g, '' ) // Replace "//" with empty strings
.split( '' ).reverse().join( '' ) // Reverse the string and test for "a" not followed by a slash
);
return (
} = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( 'core/editor' );
const { getAuthors } = select( 'core' );
const { getSettings } = select( 'core/block-editor' );
const attributeValue = getEditedPostAttribute( attribute );
let blockContent;
let loading = false;
// Todo: Maybe pass callbacks as props instead.
switch ( attribute ) {
case 'date':
const dateSettings = getDateSettings();
const dateFormat = dateSettings.formats.date;
const date = attributeValue || new Date();
blockContent = dateI18n( dateFormat, date );
break;
case 'author':
const author = getAuthors().find( ( { id } ) => id === attributeValue );
blockContent = author ? author.name : __( 'Anonymous', 'amp' );
loading = ! author;
break;
default:
blockContent = attributeValue;
}
const hasFeaturedImage = some( displayPosts, 'featured_media_object' );
const toolbarControls = [ {
icon: icons.imageLeft,
title: __( 'Image on left', 'coblocks' ),
isActive: listPosition === 'left',
onClick: () => setAttributes( { listPosition: 'left' } ),
}, {
icon: icons.imageRight,
title: __( 'Image on right', 'coblocks' ),
isActive: listPosition === 'right',
onClick: () => setAttributes( { listPosition: 'right' } ),
} ];
const dateFormat = __experimentalGetSettings().formats.date; // eslint-disable-line no-restricted-syntax
if ( ! hasPosts && postFeedType === 'internal' ) {
return (
}
case 'DateTimePicker': {
const dateFormat = __experimentalGetSettings().formats.datetime;
return (
<div name="">
<time datetime="{">
{ dateI18n( dateFormat, fieldValue ) }
</time>
</div>
);
}
case 'NumberControl': {
let { locale } = __experimentalGetSettings().l10n;
locale = locale.replace( '_', '-' );
return (
<div name="">
{ !! fieldValue && fieldValue.toLocaleString( locale ) }
</div>
);
}
case 'MediaUpload': {
return (
<div name="">
{ fieldValue && fieldValue.url || 'N/A' }
</div>
);
}
export function PostScheduleLabel( { date, isFloating } ) {
const settings = __experimentalGetSettings();
return date && ! isFloating ?
dateI18n( settings.formats.datetimeAbbreviated, date ) :
__( 'Immediately' );
}
<span value="">
{ value.label }
{ ( index < values.length - 1 ) ? ', ' : '' }
</span>
)
} )
: 'N/A' }
);
}
}
case 'DateTimePicker': {
const dateFormat = __experimentalGetSettings().formats.datetime;
return (
<div name="">
<time datetime="{">
{ dateI18n( dateFormat, fieldValue ) }
</time>
</div>
);
}
case 'NumberControl': {
let { locale } = __experimentalGetSettings().l10n;
locale = locale.replace( '_', '-' );
const { days } = attributes;
const { localization, hasFetched } = this.state;
const { startOfWeek } = localization;
const localizedWeek = days.concat( days.slice( 0, startOfWeek ) ).slice( startOfWeek );
if ( ! hasFetched ) {
return (
}
label={ __( 'Loading business hours', 'jetpack' ) }
/>
);
}
if ( ! isSelected ) {
const settings = __experimentalGetSettings();
const {
formats: { time },
} = settings;
return (
<dl>
{ localizedWeek.map( ( day, key ) => {
return (
);
} ) }
</dl>
const { days } = attributes;
const { localization, hasFetched } = this.state;
const { startOfWeek } = localization;
const localizedWeek = days.concat( days.slice( 0, startOfWeek ) ).slice( startOfWeek );
if ( ! hasFetched ) {
return (
}
label={ __( 'Loading business hours' ) }
/>
);
}
if ( ! isSelected ) {
const settings = __experimentalGetSettings();
const {
formats: { time },
} = settings;
return (
<dl>
{ localizedWeek.map( ( day, key ) => {
return (
);
} ) }
</dl>
.replace( /<[^<>]+>/g, '' )
.slice( 0, 30 );
}
label = content.length > 0 ? content : blockType.title;
break;
case 'amp/amp-story-post-author':
const author = getAuthors().find( ( { id } ) => id === getEditedPostAttribute( 'author' ) );
label = author ? author.name : __( 'Post Author', 'amp' );
break;
case 'amp/amp-story-post-date':
const postDate = getEditedPostAttribute( 'date' );
const dateSettings = getDateSettings();
const dateFormat = dateSettings.formats.date;
const date = postDate || new Date();
label = dateI18n( dateFormat, date );
break;
case 'amp/amp-story-post-title':
label = getEditedPostAttribute( 'title' ) || blockType.title;
break;
default:
break;
}
return {
content: label,