Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const [ status, setStatus ] = useEntityProp(
'postType',
'wp_template_part',
'status'
);
const initialBlocks = useMemo( () => {
if ( status !== 'publish' ) {
// Publish if still an auto-draft.
setStatus( 'publish' );
}
if ( typeof content !== 'function' ) {
const parsedContent = parse( content );
return parsedContent.length ? parsedContent : undefined;
}
}, [] );
const [ blocks = initialBlocks, setBlocks ] = useEntityProp(
'postType',
'wp_template_part',
'blocks'
);
const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
'postType',
'wp_template_part',
saveProps
);
const saveContent = useCallback( () => {
_setContent( content( { blocks } ) );
save();
}, [ content, blocks ] );
const setContent = useCallback( () => {
_setContent( ( { blocks: blocksForSerialization = [] } ) =>
serializeBlocks( blocksForSerialization )
export default function SaveButton() {
const [ , setStatus ] = useEntityProp( 'postType', 'wp_template', 'status' );
const [ , setTitle ] = useEntityProp( 'postType', 'wp_template', 'title' );
const [ slug ] = useEntityProp( 'postType', 'wp_template', 'slug' );
// Publish template if not done yet.
useEffect( () => {
setStatus( 'publish' );
setTitle( slug );
}, [ slug ] );
const { isDirty, isSaving } = useSelect( ( select ) => {
const { getEntityRecordChangesByRecord, isSavingEntityRecord } = select(
'core'
);
const entityRecordChangesByRecord = getEntityRecordChangesByRecord();
const changedKinds = Object.keys( entityRecordChangesByRecord );
return {
isDirty: changedKinds.length > 0,
isSaving: changedKinds.some( ( changedKind ) =>
Object.keys(
export default function SaveButton() {
const [ , setStatus ] = useEntityProp( 'postType', 'wp_template', 'status' );
const [ , setTitle ] = useEntityProp( 'postType', 'wp_template', 'title' );
const [ slug ] = useEntityProp( 'postType', 'wp_template', 'slug' );
// Publish template if not done yet.
useEffect( () => {
setStatus( 'publish' );
setTitle( slug );
}, [ slug ] );
const { isDirty, isSaving } = useSelect( ( select ) => {
const { getEntityRecordChangesByRecord, isSavingEntityRecord } = select(
'core'
);
const entityRecordChangesByRecord = getEntityRecordChangesByRecord();
const changedKinds = Object.keys( entityRecordChangesByRecord );
return {
isDirty: changedKinds.length > 0,
( BlockEdit ) => ( { attributes, setAttributes, ...props } ) => {
const postType = useSelect( ( select ) => select( 'core/editor' ).getCurrentPostType(), [] );
const [ meta, setMeta ] = useEntityProp( 'postType', postType, 'meta' );
const mergedAttributes = useMemo(
() => ( {
...attributes,
...mapValues( metaAttributes, ( metaKey ) => meta[ metaKey ] ),
} ),
[ attributes, meta ]
);
return (
{
const nextMeta = mapKeys(
// Filter to intersection of keys between the updated
// attributes and those with an associated meta key.
function TemplatePart() {
const [ content, _setContent ] = useEntityProp(
'postType',
'wp_template_part',
'content'
);
const [ status, setStatus ] = useEntityProp(
'postType',
'wp_template_part',
'status'
);
const initialBlocks = useMemo( () => {
if ( status !== 'publish' ) {
// Publish if still an auto-draft.
setStatus( 'publish' );
}
if ( typeof content !== 'function' ) {
const parsedContent = parse( content );
const initialBlocks = useMemo( () => {
if ( status !== 'publish' ) {
// Publish if still an auto-draft.
setStatus( 'publish' );
}
if ( typeof content !== 'function' ) {
const parsedContent = parse( content );
return parsedContent.length ? parsedContent : undefined;
}
}, [] );
const [ blocks = initialBlocks, setBlocks ] = useEntityProp(
'postType',
'wp_template_part',
'blocks'
);
const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
'postType',
'wp_template_part',
saveProps
);
const saveContent = useCallback( () => {
_setContent( content( { blocks } ) );
save();
}, [ content, blocks ] );
const setContent = useCallback( () => {
_setContent( ( { blocks: blocksForSerialization = [] } ) =>
serializeBlocks( blocksForSerialization )
);
}, [] );
return (
<>
export default function SiteTitleEdit() {
const [ title, setTitle ] = useEntityProp( 'root', 'site', 'title' );
return (
);
}
export default function PostContentEdit() {
const [ content, setContent ] = useEntityProp( 'postType', 'post', 'content' );
const initialBlocks = useMemo( () => {
const parsedContent = parse( content );
return parsedContent.length ? parsedContent : undefined;
}, [] );
const [ blocks = initialBlocks, setBlocks ] = useEntityProp(
'postType',
'post',
'blocks'
);
const [ isDirty, isSaving, save ] = useEntitySaving(
'postType',
'post',
'content'
);
return (
<>
function SiteDescriptionEdit( {
attributes,
backgroundColor,
className,
fontSize,
insertDefaultBlock,
setAttributes,
setBackgroundColor,
setFontSize,
setTextColor,
textColor,
} ) {
const [ description, setDescription ] = useEntityProp( 'root', 'site', 'description' );
const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
'root',
'site',
'description'
);
const { customFontSize, textAlign } = attributes;
const actualFontSize = customFontSize || fontSize.size;
const preventNewlines = ( event ) => {
if ( event.keyCode === ENTER ) {
event.preventDefault();
insertDefaultBlock();
}
};
export default function PostTitleEdit() {
const [ title, setTitle ] = useEntityProp( 'postType', 'post', 'title' );
const [ , setSlug ] = useEntityProp( 'postType', 'post', 'slug' );
const [ isDirty, isSaving, save ] = __experimentalUseEntitySaving(
'postType',
'post',
saveProps
);
return (
<>
<button title="" disabled="{">
{ __( 'Update' ) }
</button>