-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from studiopress/add/choices-description
Display the help text in the TextareaArray setting
- Loading branch information
Showing
36 changed files
with
2,675 additions
and
759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,7 @@ node_modules | |
vendor | ||
|
||
# Tests | ||
artifacts/ | ||
tests/data/ | ||
tests/includes/ | ||
coverage/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import * as React from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useBlock, useField } from '../hooks'; | ||
import { Fields } from '../../block-editor/components'; | ||
|
||
/** | ||
* The editor preview. | ||
* | ||
* @return {React.ReactElement} The editor preview. | ||
*/ | ||
const EditorPreview = () => { | ||
const { block, changeBlock } = useBlock(); | ||
const { getFields } = useField(); | ||
const { previewAttributes = {} } = block; | ||
const fields = getFields(); | ||
|
||
/** @param {Object} newAttributes Attribute (field) names and values. */ | ||
const setAttributes = ( newAttributes ) => { | ||
changeBlock( { | ||
previewAttributes: { | ||
...previewAttributes, | ||
...newAttributes, | ||
}, | ||
} ); | ||
}; | ||
|
||
return ( | ||
<div className="block-form"> | ||
{ | ||
Boolean( Object.keys( fields ).length ) | ||
? ( | ||
<Fields | ||
key="example-fields" | ||
fields={ fields } | ||
parentBlockProps={ { | ||
setAttributes, | ||
attributes: previewAttributes, | ||
} } | ||
parentBlock={ {} } | ||
/> | ||
) : ( | ||
<p> | ||
{ __( 'Please add a field to preview the block.', 'genesis-custom-blocks' ) } | ||
</p> | ||
) | ||
} | ||
</div> | ||
); | ||
}; | ||
|
||
export default EditorPreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import * as React from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { PostSavedState } from '@wordpress/editor'; | ||
import { __ } from '@wordpress/i18n'; | ||
import ServerSideRender from '@wordpress/server-side-render'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getBlock, getBlockNameWithNameSpace } from '../helpers'; | ||
|
||
/** | ||
* The front-end preview of the block. | ||
* | ||
* Gets the saved post with .getCurrentPost(), | ||
* not the edited post. | ||
* The server side only has access to the saved post. | ||
* So there can be an error in <ServerSideRender> | ||
* if it passes attributes that aren't yet saved. | ||
* | ||
* @return {React.ReactElement} The front-end preview. | ||
*/ | ||
const FrontEndPreview = () => { | ||
const currentPost = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); | ||
const isPostNew = useSelect( ( select ) => select( 'core/editor' ).isEditedPostNew() ); | ||
const isPostDirty = useSelect( ( select ) => select( 'core/editor' ).isEditedPostDirty() ); | ||
|
||
const fullBlock = getBlock( currentPost?.content ); | ||
const blockNameWithNameSpace = getBlockNameWithNameSpace( fullBlock ); | ||
const block = fullBlock[ blockNameWithNameSpace ] || {}; | ||
|
||
// There's nothing entered or saved, so <ServerSideRender> would have an error. | ||
if ( isPostNew && ! isPostDirty ) { | ||
return ( | ||
<p className="mt-4"> | ||
{ __( 'Please edit the block to preview it.', 'genesis-custom-blocks' ) } | ||
</p> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
{ | ||
isPostNew && isPostDirty | ||
? ( | ||
<div className="mt-4 flex flex-row items-center"> | ||
{ __( 'Please save your block to preview it:', 'genesis-custom-blocks' ) } | ||
| ||
<PostSavedState /> | ||
</div> | ||
) | ||
: ( | ||
<ServerSideRender | ||
block={ `genesis-custom-blocks/${ block?.name }` } | ||
attributes={ block?.previewAttributes } | ||
className="genesis-custom-blocks-editor__ssr" | ||
httpMethod="POST" | ||
/> | ||
) | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export default FrontEndPreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.