Commit inicial powerservice
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase -- This filename format is required to dynamically load the necessary block dependencies.
|
||||
/**
|
||||
* Block script dependencies.
|
||||
*
|
||||
* @package RankMath
|
||||
* @subpackage RankMath\Schema
|
||||
* @author Rank Math <support@rankmath.com>
|
||||
*/
|
||||
|
||||
return [
|
||||
'dependencies' => [
|
||||
'wp-blocks',
|
||||
'wp-block-editor',
|
||||
'wp-components',
|
||||
'wp-data',
|
||||
'wp-element',
|
||||
'wp-hooks',
|
||||
'wp-i18n',
|
||||
'lodash',
|
||||
],
|
||||
'version' => rank_math()->version,
|
||||
];
|
||||
+1
File diff suppressed because one or more lines are too long
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { map } from 'lodash'
|
||||
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n'
|
||||
import { withSelect } from '@wordpress/data'
|
||||
import { InspectorControls } from '@wordpress/block-editor'
|
||||
import { PanelBody, SelectControl, TextControl } from '@wordpress/components'
|
||||
|
||||
/**
|
||||
* Format array of image sizes.
|
||||
*
|
||||
* @param {Array} imageSizes Array of image sizes.
|
||||
* @return {Array} Formatted array.
|
||||
*/
|
||||
const getImageSizeOptions = ( imageSizes ) => {
|
||||
return map( imageSizes, ( { name, slug } ) => ( {
|
||||
value: slug,
|
||||
label: name,
|
||||
} ) )
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds controls to the editor sidebar to control params.
|
||||
*
|
||||
* @param {Object} props This component's props.
|
||||
*/
|
||||
const Inspector = ( { imageSizes, attributes, setAttributes } ) => {
|
||||
const imageSizeOptions = getImageSizeOptions( imageSizes )
|
||||
|
||||
return (
|
||||
<InspectorControls key={ 'inspector' }>
|
||||
<PanelBody title={ __( 'FAQ Options', 'seo-by-rank-math' ) }>
|
||||
<SelectControl
|
||||
label={ __( 'List Style', 'seo-by-rank-math' ) }
|
||||
value={ attributes.listStyle }
|
||||
options={ [
|
||||
{
|
||||
value: '',
|
||||
label: __( 'None', 'seo-by-rank-math' ),
|
||||
},
|
||||
{
|
||||
value: 'numbered',
|
||||
label: __( 'Numbered', 'seo-by-rank-math' ),
|
||||
},
|
||||
{
|
||||
value: 'unordered',
|
||||
label: __( 'Unordered', 'seo-by-rank-math' ),
|
||||
},
|
||||
] }
|
||||
onChange={ ( listStyle ) => {
|
||||
setAttributes( { listStyle } )
|
||||
} }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
|
||||
<SelectControl
|
||||
label={ __( 'Title Wrapper', 'seo-by-rank-math' ) }
|
||||
value={ attributes.titleWrapper }
|
||||
options={ [
|
||||
{ value: 'h2', label: __( 'H2', 'seo-by-rank-math' ) },
|
||||
{ value: 'h3', label: __( 'H3', 'seo-by-rank-math' ) },
|
||||
{ value: 'h4', label: __( 'H4', 'seo-by-rank-math' ) },
|
||||
{ value: 'h5', label: __( 'H5', 'seo-by-rank-math' ) },
|
||||
{ value: 'h6', label: __( 'H6', 'seo-by-rank-math' ) },
|
||||
{ value: 'p', label: __( 'P', 'seo-by-rank-math' ) },
|
||||
{ value: 'div', label: __( 'DIV', 'seo-by-rank-math' ) },
|
||||
] }
|
||||
onChange={ ( titleWrapper ) => {
|
||||
setAttributes( { titleWrapper } )
|
||||
} }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
|
||||
<SelectControl
|
||||
label={ __( 'Image Size', 'seo-by-rank-math' ) }
|
||||
value={ attributes.sizeSlug }
|
||||
options={ imageSizeOptions }
|
||||
onChange={ ( sizeSlug ) => {
|
||||
setAttributes( { sizeSlug } )
|
||||
} }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
</PanelBody>
|
||||
|
||||
<PanelBody title={ __( 'Styling Options', 'seo-by-rank-math' ) }>
|
||||
<TextControl
|
||||
label={ __( 'Title Wrapper CSS Class(es)', 'seo-by-rank-math' ) }
|
||||
value={ attributes.titleCssClasses }
|
||||
onChange={ ( titleCssClasses ) => {
|
||||
setAttributes( { titleCssClasses } )
|
||||
} }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
|
||||
<TextControl
|
||||
label={ __( 'Content Wrapper CSS Class(es)', 'seo-by-rank-math' ) }
|
||||
value={ attributes.contentCssClasses }
|
||||
onChange={ ( contentCssClasses ) => {
|
||||
setAttributes( { contentCssClasses } )
|
||||
} }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
|
||||
<TextControl
|
||||
label={ __( 'List CSS Class(es)', 'seo-by-rank-math' ) }
|
||||
value={ attributes.listCssClasses }
|
||||
onChange={ ( listCssClasses ) => {
|
||||
setAttributes( { listCssClasses } )
|
||||
} }
|
||||
__next40pxDefaultSize={ true }
|
||||
__nextHasNoMarginBottom={ true }
|
||||
/>
|
||||
</PanelBody>
|
||||
</InspectorControls>
|
||||
)
|
||||
}
|
||||
|
||||
export default withSelect( ( select, props ) => {
|
||||
const { getSettings } = select( 'core/block-editor' )
|
||||
const { imageSizes } = getSettings()
|
||||
|
||||
return {
|
||||
...props,
|
||||
imageSizes,
|
||||
}
|
||||
} )( Inspector )
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import classnames from 'classnames'
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import MediaUploader from '@blocks/shared/MediaUploader'
|
||||
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n'
|
||||
import { applyFilters } from '@wordpress/hooks'
|
||||
import { Button } from '@wordpress/components'
|
||||
import { Component, createRef } from '@wordpress/element'
|
||||
import { RichText, MediaUpload } from '@wordpress/block-editor'
|
||||
|
||||
/**
|
||||
* A Question and answer pair within FAQ block.
|
||||
*/
|
||||
class Question extends Component {
|
||||
contentRef = createRef()
|
||||
|
||||
addImageRef = createRef()
|
||||
|
||||
/**
|
||||
* Move focus to the answer input when tabbing forward from the delete button.
|
||||
*
|
||||
* @param {KeyboardEvent} event Keyboard event.
|
||||
*/
|
||||
handleDeleteKeyDown = ( event ) => {
|
||||
if ( event.key === 'Tab' && ! event.shiftKey ) {
|
||||
event.preventDefault()
|
||||
const contentArea = this.contentRef.current
|
||||
if ( contentArea ) {
|
||||
const focusable = contentArea.querySelector( '[contenteditable]' )
|
||||
if ( focusable ) {
|
||||
focusable.focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move focus to the Add Image button when tabbing forward from the answer input.
|
||||
*
|
||||
* @param {KeyboardEvent} event Keyboard event.
|
||||
*/
|
||||
handleAnswerKeyDown = ( event ) => {
|
||||
if ( event.key === 'Tab' && ! event.shiftKey ) {
|
||||
event.preventDefault()
|
||||
if ( this.addImageRef.current ) {
|
||||
this.addImageRef.current.focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the component.
|
||||
*
|
||||
* @return {Component} Question editor.
|
||||
*/
|
||||
render() {
|
||||
const {
|
||||
title,
|
||||
content,
|
||||
visible,
|
||||
imageID,
|
||||
sizeSlug,
|
||||
titleWrapper,
|
||||
titleCssClasses,
|
||||
contentCssClasses,
|
||||
} = this.props
|
||||
const wrapperClasses = classnames( 'rank-math-question-wrapper', {
|
||||
'question-not-visible': ! visible,
|
||||
} )
|
||||
|
||||
return (
|
||||
<div className={ wrapperClasses }>
|
||||
<div className="rank-math-item-header">
|
||||
<RichText
|
||||
tagName={ titleWrapper }
|
||||
className={
|
||||
'rank-math-faq-question rank-math-block-title' +
|
||||
titleCssClasses
|
||||
}
|
||||
value={ title }
|
||||
onChange={ ( newTitle ) => {
|
||||
this.setQuestionProp( 'title', newTitle )
|
||||
} }
|
||||
placeholder={ __( 'Question…', 'seo-by-rank-math' ) }
|
||||
/>
|
||||
|
||||
<div className="rank-math-block-actions">
|
||||
{ applyFilters( 'rank_math_block_faq_actions', '', this.props, this ) }
|
||||
|
||||
<Button
|
||||
className="rank-math-item-visbility"
|
||||
icon={ visible ? 'visibility' : 'hidden' }
|
||||
onClick={ this.toggleVisibility }
|
||||
label={ __( 'Hide Question', 'seo-by-rank-math' ) }
|
||||
showTooltip={ true }
|
||||
/>
|
||||
|
||||
<Button
|
||||
icon="trash"
|
||||
className="rank-math-item-delete"
|
||||
onClick={ this.deleteQuestion }
|
||||
onKeyDown={ this.handleDeleteKeyDown }
|
||||
label={ __( 'Delete Question', 'seo-by-rank-math' ) }
|
||||
showTooltip={ true }
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rank-math-item-content" ref={ this.contentRef }>
|
||||
<RichText
|
||||
tagName="div"
|
||||
className={ 'rank-math-faq-answer ' + contentCssClasses }
|
||||
value={ content }
|
||||
onChange={ ( newContent ) => {
|
||||
this.setQuestionProp( 'content', newContent )
|
||||
} }
|
||||
onKeyDown={ this.handleAnswerKeyDown }
|
||||
placeholder={ __(
|
||||
'Enter the answer to the question',
|
||||
'seo-by-rank-math'
|
||||
) }
|
||||
/>
|
||||
|
||||
<MediaUpload
|
||||
allowedTypes={ [ 'image' ] }
|
||||
multiple={ false }
|
||||
value={ imageID }
|
||||
render={ ( { open } ) => (
|
||||
<MediaUploader
|
||||
imageID={ imageID }
|
||||
sizeSlug={ sizeSlug }
|
||||
open={ open }
|
||||
addImageRef={ this.addImageRef }
|
||||
removeImage={ () => {
|
||||
this.setQuestionProp( 'imageID', 0 )
|
||||
} }
|
||||
/>
|
||||
) }
|
||||
onSelect={ ( image ) => {
|
||||
this.setQuestionProp( 'imageID', image.id )
|
||||
} }
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update question properties.
|
||||
*
|
||||
* @param {string} prop Poperty name.
|
||||
* @param {string} value Property value.
|
||||
*/
|
||||
setQuestionProp( prop, value ) {
|
||||
const { setAttributes, index } = this.props
|
||||
const questions = [ ...this.props.questions ]
|
||||
questions[ index ][ prop ] = value
|
||||
|
||||
setAttributes( { questions } )
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle question visibility.
|
||||
*/
|
||||
toggleVisibility = () => {
|
||||
const { setAttributes, index } = this.props
|
||||
const questions = [ ...this.props.questions ]
|
||||
questions[ index ].visible = ! this.props.visible
|
||||
|
||||
setAttributes( { questions } )
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete question from block.
|
||||
*/
|
||||
deleteQuestion = () => {
|
||||
const { setAttributes, index } = this.props
|
||||
const questions = [ ...this.props.questions ]
|
||||
questions.splice( index, 1 )
|
||||
|
||||
setAttributes( { questions } )
|
||||
}
|
||||
}
|
||||
|
||||
export default Question
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n'
|
||||
import { Fragment } from '@wordpress/element'
|
||||
import { Button, Dashicon } from '@wordpress/components'
|
||||
import { BlockControls, AlignmentToolbar, useBlockProps } from '@wordpress/block-editor'
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import getLink from '@helpers/getLink'
|
||||
import Inspector from './components/Inspector'
|
||||
import Question from './components/Question'
|
||||
import generateId from '@helpers/generateId'
|
||||
|
||||
/**
|
||||
* Render Quetion component.
|
||||
*
|
||||
* @param {Object} props Block attributes
|
||||
*
|
||||
* @return {Array} Array of question editor.
|
||||
*/
|
||||
const renderQuestions = ( props ) => {
|
||||
const {
|
||||
sizeSlug,
|
||||
titleWrapper,
|
||||
titleCssClasses,
|
||||
contentCssClasses,
|
||||
} = props.attributes
|
||||
let { questions } = props.attributes
|
||||
if ( isEmpty( questions ) ) {
|
||||
questions = [
|
||||
{
|
||||
id: generateId( 'faq-question' ),
|
||||
title: '',
|
||||
content: '',
|
||||
visible: true,
|
||||
},
|
||||
]
|
||||
props.setAttributes( { questions } )
|
||||
}
|
||||
|
||||
return questions.map( ( question, index ) => {
|
||||
return (
|
||||
<li key={ question.id }>
|
||||
<Question
|
||||
{ ...question }
|
||||
index={ index }
|
||||
key={ question.id + '-question' }
|
||||
questions={ questions }
|
||||
setAttributes={ props.setAttributes }
|
||||
sizeSlug={ sizeSlug }
|
||||
titleWrapper={ titleWrapper }
|
||||
titleCssClasses={ titleCssClasses }
|
||||
contentCssClasses={ contentCssClasses }
|
||||
/>
|
||||
</li>
|
||||
)
|
||||
} )
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an empty Question into block.
|
||||
*
|
||||
* @param {Object} props Block props.
|
||||
*/
|
||||
const addNew = ( props ) => {
|
||||
const questions = [ ...props.attributes.questions ]
|
||||
questions.push( {
|
||||
id: generateId( 'faq-question' ),
|
||||
title: '',
|
||||
content: '',
|
||||
visible: true,
|
||||
} )
|
||||
|
||||
props.setAttributes( { questions } )
|
||||
}
|
||||
|
||||
/**
|
||||
* FAQ block edit component.
|
||||
*
|
||||
* @param {Object} props Block props.
|
||||
*/
|
||||
export default ( props ) => {
|
||||
const { className, isSelected } = props
|
||||
const { textAlign } = props.attributes
|
||||
const blockProps = useBlockProps()
|
||||
|
||||
return (
|
||||
<div { ...blockProps }>
|
||||
<div
|
||||
id="rank-math-faq"
|
||||
className={ 'rank-math-block ' + className }
|
||||
>
|
||||
{ isSelected && <Inspector { ...props } /> }
|
||||
{ isSelected && (
|
||||
<Fragment>
|
||||
<BlockControls>
|
||||
<AlignmentToolbar
|
||||
value={ textAlign }
|
||||
onChange={ ( nextTextAlignment ) =>
|
||||
props.setAttributes( {
|
||||
textAlign: nextTextAlignment,
|
||||
} )
|
||||
}
|
||||
/>
|
||||
</BlockControls>
|
||||
</Fragment>
|
||||
) }
|
||||
|
||||
<ul style={ { textAlign } }>{ renderQuestions( props ) }</ul>
|
||||
|
||||
<Button
|
||||
variant="primary"
|
||||
onClick={ () => {
|
||||
addNew( props )
|
||||
} }
|
||||
>
|
||||
{ __( 'Add New FAQ', 'seo-by-rank-math' ) }
|
||||
</Button>
|
||||
|
||||
<a
|
||||
href={ getLink( 'faq-schema-block', 'Add New FAQ' ) }
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
title={ __( 'More Info', 'seo-by-rank-math' ) }
|
||||
className={ 'rank-math-block-info' }
|
||||
>
|
||||
<Dashicon icon="info" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* FAQ eample for in block preview pane.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
export default {
|
||||
attributes: {
|
||||
questions: [
|
||||
{
|
||||
visible: true,
|
||||
titleWrapper: 'div',
|
||||
title: 'Question',
|
||||
content:
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { registerBlockType } from '@wordpress/blocks'
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import example from './example'
|
||||
import edit from './edit'
|
||||
import transforms from './transforms'
|
||||
import save from './save'
|
||||
|
||||
/**
|
||||
* Register FAQ block.
|
||||
*/
|
||||
registerBlockType(
|
||||
'rank-math/faq-block',
|
||||
{
|
||||
example,
|
||||
edit,
|
||||
save,
|
||||
transforms,
|
||||
}
|
||||
)
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { RichText, useBlockProps } from '@wordpress/block-editor'
|
||||
|
||||
/**
|
||||
* Save block for display on front
|
||||
*
|
||||
* @param {Object} props This component's props.
|
||||
*/
|
||||
export default ( props ) => {
|
||||
const { questions, titleWrapper } = props.attributes
|
||||
|
||||
if ( isEmpty( questions ) ) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div { ...useBlockProps.save() }>
|
||||
{ questions.map( ( question, index ) => {
|
||||
if (
|
||||
isEmpty( question.title ) ||
|
||||
isEmpty( question.content ) ||
|
||||
false === question.visible
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="rank-math-faq-item" key={ index }>
|
||||
<RichText.Content
|
||||
tagName={ titleWrapper }
|
||||
value={ question.title }
|
||||
className="rank-math-question"
|
||||
/>
|
||||
|
||||
<RichText.Content
|
||||
tagName="div"
|
||||
value={ question.content }
|
||||
className="rank-math-answer"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
} ) }
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* WordPress dependencies
|
||||
*/
|
||||
import { createBlock } from '@wordpress/blocks'
|
||||
|
||||
/**
|
||||
* Transform yoast faq block.
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
export default {
|
||||
from: [
|
||||
{
|
||||
type: 'block',
|
||||
blocks: [ 'yoast/faq-block' ],
|
||||
transform: ( yoast ) => {
|
||||
const questions = yoast.questions.map( ( question ) => {
|
||||
return {
|
||||
title: question.jsonQuestion,
|
||||
content: question.jsonAnswer,
|
||||
visible: true,
|
||||
}
|
||||
} )
|
||||
|
||||
const attributes = {
|
||||
titleWrapper: 'h3',
|
||||
questions,
|
||||
className: yoast.className,
|
||||
}
|
||||
|
||||
return createBlock( 'rank-math/faq-block', attributes )
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user