diff --git a/projects/plugins/jetpack/changelog/refactor-production-blocks-registration-3 b/projects/plugins/jetpack/changelog/refactor-production-blocks-registration-3 new file mode 100644 index 0000000000000..05e3d14792e79 --- /dev/null +++ b/projects/plugins/jetpack/changelog/refactor-production-blocks-registration-3 @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Refactor blocks registration diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/block.json b/projects/plugins/jetpack/extensions/blocks/mailchimp/block.json index da9b71caa8179..b20af4487b904 100644 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/block.json +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, + "apiVersion": 1, "name": "jetpack/mailchimp", "title": "Mailchimp", "description": "Allow readers to join a Mailchimp audience.", @@ -55,5 +55,19 @@ "default": false } }, - "editorScript": "file:../editor.js" + "example": { + "attributes": { + "preview": true + }, + "innerBlocks": [ + { + "name": "jetpack/button", + "attributes": { + "element": "button", + "text": "Join my Mailchimp audience", + "uniqueId": "mailchimp-widget-id" + } + } + ] + } } diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/edit.js b/projects/plugins/jetpack/extensions/blocks/mailchimp/edit.js index 0806afeed6c53..a6be46b104ab7 100644 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/edit.js @@ -1,4 +1,7 @@ -import { isCurrentUserConnected } from '@automattic/jetpack-shared-extension-utils'; +import { + isCurrentUserConnected, + getBlockIconComponent, +} from '@automattic/jetpack-shared-extension-utils'; import apiFetch from '@wordpress/api-fetch'; import { InnerBlocks, InspectorControls, RichText } from '@wordpress/block-editor'; import { Button, Placeholder, Spinner, TextControl, withNotices } from '@wordpress/components'; @@ -6,14 +9,24 @@ import { Fragment, Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { addQueryArgs } from '@wordpress/url'; import classnames from 'classnames'; +import metadata from './block.json'; import { NOTIFICATION_PROCESSING, NOTIFICATION_SUCCESS, NOTIFICATION_ERROR } from './constants'; import { MailChimpBlockControls } from './controls'; -import { icon, innerButtonBlock } from '.'; const API_STATE_LOADING = 0; const API_STATE_CONNECTED = 1; const API_STATE_NOTCONNECTED = 2; +const icon = getBlockIconComponent( metadata ); +const innerButtonBlock = { + name: 'jetpack/button', + attributes: { + element: 'button', + text: __( 'Join my Mailchimp audience', 'jetpack' ), + uniqueId: 'mailchimp-widget-id', + }, +}; + class MailchimpSubscribeEdit extends Component { constructor() { super( ...arguments ); diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/editor.js b/projects/plugins/jetpack/extensions/blocks/mailchimp/editor.js index d7ec194d817a1..6f1c92c648224 100644 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/editor.js +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/editor.js @@ -1,4 +1,15 @@ -import registerJetpackBlock from '../../shared/register-jetpack-block'; -import { name, settings } from '.'; +import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block'; +import metadata from './block.json'; +import deprecatedV1 from './deprecated/v1'; +import edit from './edit'; +import save from './save'; +import transforms from './transforms'; -registerJetpackBlock( name, settings ); +import './editor.scss'; + +registerJetpackBlockFromMetadata( metadata, { + edit, + save, + deprecated: [ deprecatedV1 ], + transforms, +} ); diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/index.js b/projects/plugins/jetpack/extensions/blocks/mailchimp/index.js deleted file mode 100644 index 67c3e43dc388e..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/index.js +++ /dev/null @@ -1,112 +0,0 @@ -import { InnerBlocks } from '@wordpress/block-editor'; -import { Path, SVG, G } from '@wordpress/components'; -import { __, _x } from '@wordpress/i18n'; -import { getIconColor } from '../../shared/block-icons'; -import deprecatedV1 from './deprecated/v1'; -import edit from './edit'; -import transforms from './transforms'; -import './editor.scss'; - -export const name = 'mailchimp'; - -export const icon = ( - - - - - - - - - - - - - -); - -export const innerButtonBlock = { - name: 'jetpack/button', - attributes: { - element: 'button', - text: __( 'Join my Mailchimp audience', 'jetpack' ), - uniqueId: 'mailchimp-widget-id', - }, -}; - -export const settings = { - title: __( 'Mailchimp', 'jetpack' ), - icon: { - src: icon, - foreground: getIconColor(), - }, - description: __( 'Allow readers to join a Mailchimp audience.', 'jetpack' ), - category: 'grow', - keywords: [ - _x( 'email', 'block search term', 'jetpack' ), - _x( 'subscription', 'block search term', 'jetpack' ), - _x( 'newsletter', 'block search term', 'jetpack' ), - ], - supports: { - align: [ 'wide', 'full' ], - color: { - gradients: true, - }, - spacing: { - padding: true, - margin: true, - }, - }, - attributes: { - emailPlaceholder: { - type: 'string', - default: __( 'Enter your email', 'jetpack' ), - }, - consentText: { - type: 'string', - default: __( - 'By clicking submit, you agree to share your email address with the site owner and Mailchimp to receive marketing, updates, and other emails from the site owner. Use the unsubscribe link in those emails to opt out at any time.', - 'jetpack' - ), - }, - interests: { - type: 'array', - default: [], - }, - processingLabel: { - type: 'string', - default: __( 'Processing…', 'jetpack' ), - }, - signupFieldTag: { - type: 'string', - }, - signupFieldValue: { - type: 'string', - }, - successLabel: { - type: 'string', - default: __( "Success! You're on the list.", 'jetpack' ), - }, - errorLabel: { - type: 'string', - default: __( - "Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.", - 'jetpack' - ), - }, - preview: { - type: 'boolean', - default: false, - }, - }, - edit, - save: () => , - example: { - attributes: { - preview: true, - }, - innerBlocks: [ innerButtonBlock ], - }, - deprecated: [ deprecatedV1 ], - transforms, -}; diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php b/projects/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php index 1e34d9757d5ac..fb6a1dca5f6cd 100644 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/mailchimp.php @@ -14,9 +14,6 @@ use Jetpack_Gutenberg; use Jetpack_Options; -const FEATURE_NAME = 'mailchimp'; -const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; - /** * Registers the block for use in Gutenberg * This is done via an action so that we can disable @@ -28,19 +25,9 @@ function register_block() { || Jetpack::is_connection_ready() ) { Blocks::jetpack_register_block( - BLOCK_NAME, + __DIR__, array( 'render_callback' => __NAMESPACE__ . '\load_assets', - 'supports' => array( - 'align' => array( 'wide', 'full' ), - 'color' => array( - 'gradients' => true, - ), - 'spacing' => array( - 'padding' => true, - 'margin' => true, - ), - ), ) ); } @@ -65,7 +52,7 @@ function load_assets( $attr, $content ) { $blog_id = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? get_current_blog_id() : Jetpack_Options::get_option( 'id' ); - Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); + Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); $wrapper_attributes = \WP_Block_Supports::get_instance()->apply_block_supports(); $classes = ! empty( $wrapper_attributes['class'] ) ? $wrapper_attributes['class'] : ''; $amp_form_action = sprintf( 'https://public-api.wordpress.com/rest/v1.1/sites/%s/email_follow/amp/subscribe/', $blog_id ); diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/save.js b/projects/plugins/jetpack/extensions/blocks/mailchimp/save.js new file mode 100644 index 0000000000000..db9e391b76f1f --- /dev/null +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/save.js @@ -0,0 +1,3 @@ +import { InnerBlocks } from '@wordpress/block-editor'; + +export default () => ; diff --git a/projects/plugins/jetpack/extensions/blocks/mailchimp/test/validate.js b/projects/plugins/jetpack/extensions/blocks/mailchimp/test/validate.js index d0fbd27e9213d..5622ac35a6119 100644 --- a/projects/plugins/jetpack/extensions/blocks/mailchimp/test/validate.js +++ b/projects/plugins/jetpack/extensions/blocks/mailchimp/test/validate.js @@ -1,21 +1,14 @@ -import { name, settings } from '../'; import runBlockFixtureTests from '../../../shared/test/block-fixtures'; import { settings as buttonSettings } from '../../button'; +import metadata from '../block.json'; +import deprecated from '../deprecated/v1'; +import edit from '../edit'; +import save from '../save'; -/** - * Update this array of blocks to contain the name and settings for all blocks - * involved in this set of tests. - * - * Example containing multiple blocks: - * ``` - * const blocks = [ - * { name: 'jetpack/whatsapp-button', settings }, - * { name: 'jetpack/send-a-message', settings: parentSettings }, - * ]; - * ``` - */ +const { name } = metadata; const blocks = [ - { name: `jetpack/${ name }`, settings }, + { name, settings: { ...metadata, edit, save, deprecated: [ deprecated ] } }, { name: `jetpack/button`, settings: buttonSettings }, ]; -runBlockFixtureTests( `jetpack/${ name }`, blocks, __dirname ); + +runBlockFixtureTests( name, blocks, __dirname ); diff --git a/projects/plugins/jetpack/extensions/blocks/map/block.json b/projects/plugins/jetpack/extensions/blocks/map/block.json index 8bf892bd24fed..8a2d6f7d36a8c 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/block.json +++ b/projects/plugins/jetpack/extensions/blocks/map/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, + "apiVersion": 1, "name": "jetpack/map", "title": "Map", "description": "Add an interactive map showing one or more locations.", @@ -57,5 +57,9 @@ "default": true } }, - "editorScript": "file:../editor.js" + "example": { + "attributes": { + "preview": true + } + } } diff --git a/projects/plugins/jetpack/extensions/blocks/map/controls.js b/projects/plugins/jetpack/extensions/blocks/map/controls.js index 307a6c6bbbfee..184dba0cdbe44 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/controls.js +++ b/projects/plugins/jetpack/extensions/blocks/map/controls.js @@ -10,10 +10,30 @@ import { ToolbarGroup, RangeControl, BaseControl, + SVG, + G, + Polygon, + Path, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import Locations from './locations'; -import { settings } from './settings.js'; + +const markerIcon = ( + /* Do not use SVG components from @wordpress/component to avoid frontend bloat */ + + + + + + + + +); export default ( { attributes, @@ -80,7 +100,7 @@ export default ( { /> diff --git a/projects/plugins/jetpack/extensions/blocks/map/edit.js b/projects/plugins/jetpack/extensions/blocks/map/edit.js index 7f5e739e7aafe..fe4b039db572f 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/map/edit.js @@ -1,3 +1,4 @@ +import { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils'; import apiFetch from '@wordpress/api-fetch'; import { BlockControls, InspectorControls } from '@wordpress/block-editor'; import { @@ -14,13 +15,16 @@ import { Component, createRef, Fragment } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { getActiveStyleName } from '../../shared/block-styles'; import AddPoint from './add-point'; +import metadata from './block.json'; import Map from './component'; import Controls from './controls'; import { getCoordinates } from './get-coordinates.js'; import previewPlaceholder from './map-preview.jpg'; -import { settings } from './settings.js'; +import styles from './styles'; import getMapProvider from './utils/get-map-provider'; +const icon = getBlockIconComponent( metadata ); + const API_STATE_LOADING = 0; const API_STATE_FAILURE = 1; const API_STATE_SUCCESS = 2; @@ -168,7 +172,7 @@ class MapEdit extends Component { } ); } getMapProvider = () => { - const mapStyle = getActiveStyleName( settings.styles, this.props?.attributes?.className ); + const mapStyle = getActiveStyleName( styles, this.props?.attributes?.className ); return getMapProvider( { mapStyle } ); }; @@ -278,7 +282,7 @@ class MapEdit extends Component { ); const placholderAPIStateLoading = ( - + ); @@ -298,7 +302,7 @@ class MapEdit extends Component {

); const placeholderAPIStateFailure = ( - + { instructions }
@@ -323,7 +327,7 @@ class MapEdit extends Component { ); // Only scroll to zoom when the block is selected, and there's 1 or less points. const allowScrollToZoom = isSelected && points.length <= 1; - const mapStyle = getActiveStyleName( settings.styles, attributes.className ); + const mapStyle = getActiveStyleName( styles, attributes.className ); const placeholderAPIStateSuccess = ( { inspectorControls } @@ -381,7 +385,7 @@ class MapEdit extends Component { ); - const mapStyleObject = settings.styles.find( styleObject => styleObject.name === mapStyle ); + const mapStyleObject = styles.find( styleObject => styleObject.name === mapStyle ); const placholderPreview = (
__NAMESPACE__ . '\load_assets', ) @@ -123,7 +120,7 @@ function load_assets( $attr, $content ) { ); } - Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); + Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); $map_provider = get_map_provider( $content ); if ( $map_provider === 'mapkit' ) { @@ -175,7 +172,7 @@ function render_single_block_page() { add_filter( 'jetpack_is_amp_request', '__return_false' ); - Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); + Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); wp_scripts()->do_items(); wp_styles()->do_items(); diff --git a/projects/plugins/jetpack/extensions/blocks/map/save.js b/projects/plugins/jetpack/extensions/blocks/map/save.js index 1d6da9f3f10d1..d01b486718c1d 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/save.js +++ b/projects/plugins/jetpack/extensions/blocks/map/save.js @@ -1,6 +1,6 @@ import { Component } from '@wordpress/element'; import { getActiveStyleName } from '../../shared/block-styles'; -import { settings } from './settings.js'; +import styles from './styles'; class MapSave extends Component { render() { @@ -17,7 +17,7 @@ class MapSave extends Component { mapHeight, showFullscreenButton, } = attributes; - const mapStyle = getActiveStyleName( settings.styles, className ); + const mapStyle = getActiveStyleName( styles, className ); const pointsList = points.map( ( point, index ) => { const { longitude, latitude } = point.coordinates; const url = 'https://www.google.com/maps/search/?api=1&query=' + latitude + ',' + longitude; diff --git a/projects/plugins/jetpack/extensions/blocks/map/settings.js b/projects/plugins/jetpack/extensions/blocks/map/settings.js deleted file mode 100644 index 82d63740ee180..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/map/settings.js +++ /dev/null @@ -1,140 +0,0 @@ -// Disable forbidden etc. so that frontend component does not depend on @wordpress/component -/* eslint-disable react/forbid-elements */ -import { __, _x } from '@wordpress/i18n'; -import blackAndWhiteTheme from './previews/map-theme_black_and_white.jpg'; -import blackAndWhiteThemeMapkit from './previews/map-theme_black_and_white_mapkit.jpg'; -import defaultTheme from './previews/map-theme_default.jpg'; -import defaultThemeMapkit from './previews/map-theme_default_mapkit.jpg'; -import satelliteTheme from './previews/map-theme_satellite.jpg'; -import satelliteThemeMapkit from './previews/map-theme_satellite_mapkit.jpg'; -import terrainTheme from './previews/map-theme_terrain.jpg'; -import { getMapProvider } from './utils'; - -const provider = getMapProvider(); - -export const settings = { - name: 'map', - prefix: 'jetpack', - title: __( 'Map', 'jetpack' ), - icon: ( - /* Do not use SVG components from @wordpress/component to avoid frontend bloat */ - - ), - category: 'embed', - keywords: [ - _x( 'maps', 'block search term', 'jetpack' ), - _x( 'location', 'block search term', 'jetpack' ), - _x( 'navigation', 'block search term', 'jetpack' ), - ], - description: __( 'Add an interactive map showing one or more locations.', 'jetpack' ), - attributes: { - align: { - type: 'string', - }, - points: { - type: 'array', - default: [], - }, - address: { - type: 'string', - default: '', - }, - mapDetails: { - type: 'boolean', - default: true, - }, - zoom: { - type: 'integer', - default: 13, - }, - mapCenter: { - type: 'object', - default: { - longitude: -122.41941550000001, - latitude: 37.7749295, - }, - }, - markerColor: { - type: 'string', - default: 'red', - }, - preview: { - type: 'boolean', - default: false, - }, - scrollToZoom: { - type: 'boolean', - default: false, - }, - mapHeight: { - type: 'integer', - }, - showFullscreenButton: { - type: 'boolean', - default: true, - }, - }, - supports: { - defaultStylePicker: false, - html: false, - }, - styles: [ - { - name: 'default', - label: __( 'Basic', 'jetpack' ), - preview: provider === 'mapkit' ? defaultThemeMapkit : defaultTheme, - isDefault: true, - }, - { - name: 'black_and_white', - label: - provider === 'mapkit' - ? __( 'Muted', 'jetpack', /* dummy arg to avoid bad minification */ 0 ) - : __( 'Black & White', 'jetpack' ), - preview: provider === 'mapkit' ? blackAndWhiteThemeMapkit : blackAndWhiteTheme, - }, - { - name: 'satellite', - label: __( 'Satellite', 'jetpack' ), - preview: provider === 'mapkit' ? satelliteThemeMapkit : satelliteTheme, - }, - { - name: 'terrain', - label: __( 'Terrain', 'jetpack' ), - preview: terrainTheme, - }, - ], - validAlignments: [ 'center', 'wide', 'full' ], - markerIcon: ( - /* Do not use SVG components from @wordpress/component to avoid frontend bloat */ - - - - - - - - - ), - example: { - attributes: { - preview: true, - }, - }, -}; diff --git a/projects/plugins/jetpack/extensions/blocks/map/style.scss b/projects/plugins/jetpack/extensions/blocks/map/style.scss index 2b96907f1c0ea..211e59dd4ba41 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/style.scss +++ b/projects/plugins/jetpack/extensions/blocks/map/style.scss @@ -6,7 +6,7 @@ overflow: hidden; background: $gray-200; min-height: 400px; - text-align: left; + text-align: start; } .mapkit-popup-content { diff --git a/projects/plugins/jetpack/extensions/blocks/map/styles.js b/projects/plugins/jetpack/extensions/blocks/map/styles.js new file mode 100644 index 0000000000000..b6dab917cd27a --- /dev/null +++ b/projects/plugins/jetpack/extensions/blocks/map/styles.js @@ -0,0 +1,38 @@ +import { __ } from '@wordpress/i18n'; +import blackAndWhiteTheme from './previews/map-theme_black_and_white.jpg'; +import blackAndWhiteThemeMapkit from './previews/map-theme_black_and_white_mapkit.jpg'; +import defaultTheme from './previews/map-theme_default.jpg'; +import defaultThemeMapkit from './previews/map-theme_default_mapkit.jpg'; +import satelliteTheme from './previews/map-theme_satellite.jpg'; +import satelliteThemeMapkit from './previews/map-theme_satellite_mapkit.jpg'; +import terrainTheme from './previews/map-theme_terrain.jpg'; +import { getMapProvider } from './utils'; + +const provider = getMapProvider(); + +export default [ + { + name: 'default', + label: __( 'Basic', 'jetpack' ), + preview: provider === 'mapkit' ? defaultThemeMapkit : defaultTheme, + isDefault: true, + }, + { + name: 'black_and_white', + label: + provider === 'mapkit' + ? __( 'Muted', 'jetpack', /* dummy arg to avoid bad minification */ 0 ) + : __( 'Black & White', 'jetpack' ), + preview: provider === 'mapkit' ? blackAndWhiteThemeMapkit : blackAndWhiteTheme, + }, + { + name: 'satellite', + label: __( 'Satellite', 'jetpack' ), + preview: provider === 'mapkit' ? satelliteThemeMapkit : satelliteTheme, + }, + { + name: 'terrain', + label: __( 'Terrain', 'jetpack' ), + preview: terrainTheme, + }, +]; diff --git a/projects/plugins/jetpack/extensions/blocks/map/test/validate.js b/projects/plugins/jetpack/extensions/blocks/map/test/validate.js index b72589b60b8dc..1d404d2e6a609 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/test/validate.js +++ b/projects/plugins/jetpack/extensions/blocks/map/test/validate.js @@ -1,5 +1,23 @@ -import { name, settings } from '../'; import runBlockFixtureTests from '../../../shared/test/block-fixtures'; +import metadata from '../block.json'; +import deprecatedV1 from '../deprecated/v1'; +import deprecatedV2 from '../deprecated/v2'; +import edit from '../edit'; +import save from '../save'; +import styles from '../styles'; -const blocks = [ { name: `jetpack/${ name }`, settings } ]; -runBlockFixtureTests( `jetpack/${ name }`, blocks, __dirname ); +const { name } = metadata; + +const blocks = [ + { + name, + settings: { + ...metadata, + edit, + save, + styles, + deprecated: [ deprecatedV2, deprecatedV1 ], + }, + }, +]; +runBlockFixtureTests( name, blocks, __dirname ); diff --git a/projects/plugins/jetpack/extensions/blocks/markdown/block.json b/projects/plugins/jetpack/extensions/blocks/markdown/block.json index 2e682af89aa6d..923cb19834acf 100644 --- a/projects/plugins/jetpack/extensions/blocks/markdown/block.json +++ b/projects/plugins/jetpack/extensions/blocks/markdown/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, + "apiVersion": 1, "name": "jetpack/markdown", "title": "Markdown", "description": "Add headings, lists, or links to plain text with ease.", @@ -22,5 +22,9 @@ } }, "attributes": { "source": { "type": "string" } }, - "editorScript": "file:../editor.js" + "example": { + "attributes": { + "source": "## ## Try Markdown\n\nMarkdown is a text formatting syntax that is converted into HTML. You can _emphasize_ text or **make it strong** with just a few characters." + } + } } diff --git a/projects/plugins/jetpack/extensions/blocks/markdown/editor.js b/projects/plugins/jetpack/extensions/blocks/markdown/editor.js index d7ec194d817a1..b952d5df5a0eb 100644 --- a/projects/plugins/jetpack/extensions/blocks/markdown/editor.js +++ b/projects/plugins/jetpack/extensions/blocks/markdown/editor.js @@ -1,4 +1,11 @@ -import registerJetpackBlock from '../../shared/register-jetpack-block'; -import { name, settings } from '.'; +import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block'; +import metadata from './block.json'; +import edit from './edit'; +import save from './save'; -registerJetpackBlock( name, settings ); +import './editor.scss'; + +registerJetpackBlockFromMetadata( metadata, { + edit, + save, +} ); diff --git a/projects/plugins/jetpack/extensions/blocks/markdown/index.js b/projects/plugins/jetpack/extensions/blocks/markdown/index.js deleted file mode 100644 index 1fda432a5cda7..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/markdown/index.js +++ /dev/null @@ -1,90 +0,0 @@ -import { isAtomicSite, isSimpleSite } from '@automattic/jetpack-shared-extension-utils'; -import { ExternalLink, Path, Rect, SVG } from '@wordpress/components'; -import { Fragment } from '@wordpress/element'; -import { __, _x } from '@wordpress/i18n'; -import { getIconColor } from '../../shared/block-icons'; -import getCategoryWithFallbacks from '../../shared/get-category-with-fallbacks'; -import edit from './edit'; -import save from './save'; - -import './editor.scss'; - -export const name = 'markdown'; - -const exampleTitle = __( 'Try Markdown', 'jetpack' ); -const exampleDescription = __( - 'Markdown is a text formatting syntax that is converted into HTML. You can _emphasize_ text or **make it strong** with just a few characters.', - 'jetpack' -); - -const icon = ( - - - - -); - -const supportLink = - isSimpleSite() || isAtomicSite() - ? 'https://en.support.wordpress.com/markdown-quick-reference/' - : 'https://jetpack.com/support/jetpack-blocks/markdown-block/'; - -export const settings = { - title: __( 'Markdown', 'jetpack' ), - - description: ( - -

{ __( 'Add headings, lists, or links to plain text with ease.', 'jetpack' ) }

- { __( 'Support reference', 'jetpack' ) } - - ), - - icon: { - src: icon, - foreground: getIconColor(), - }, - - category: getCategoryWithFallbacks( 'text', 'formatting' ), - keywords: [ - _x( 'formatting', 'block search term', 'jetpack' ), - _x( 'syntax', 'block search term', 'jetpack' ), - _x( 'markup', 'block search term', 'jetpack' ), - ], - - attributes: { - //The Markdown source is saved in the block content comments delimiter - source: { type: 'string' }, - }, - - supports: { - align: [ 'wide', 'full' ], - html: false, - spacing: { - padding: true, - margin: true, - __experimentalDefaultControls: { - padding: true, - margin: true, - }, - }, - }, - - edit, - - save, - - example: { - attributes: { - source: `## ## ${ exampleTitle }\n\n${ exampleDescription }`, - }, - }, -}; diff --git a/projects/plugins/jetpack/extensions/blocks/markdown/markdown.php b/projects/plugins/jetpack/extensions/blocks/markdown/markdown.php index 13a81fc858be4..fdbd1ff389937 100644 --- a/projects/plugins/jetpack/extensions/blocks/markdown/markdown.php +++ b/projects/plugins/jetpack/extensions/blocks/markdown/markdown.php @@ -11,15 +11,12 @@ use Automattic\Jetpack\Blocks; -const FEATURE_NAME = 'markdown'; -const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; - /** * Registers the block for use in Gutenberg * This is done via an action so that we can disable * registration if we need to. */ function register_block() { - Blocks::jetpack_register_block( BLOCK_NAME ); + Blocks::jetpack_register_block( __DIR__ ); } add_action( 'init', __NAMESPACE__ . '\register_block' ); diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/attributes.js b/projects/plugins/jetpack/extensions/blocks/opentable/attributes.js deleted file mode 100644 index f1d017d8afbf0..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/opentable/attributes.js +++ /dev/null @@ -1,68 +0,0 @@ -import { __ } from '@wordpress/i18n'; -import { compact, isEmpty } from 'lodash'; - -const optionValues = options => options.map( option => option.value ); - -export const languageOptions = [ - { value: 'en-US', label: 'English' }, - { value: 'fr-CA', label: 'Français' }, - { value: 'de-DE', label: 'Deutsch' }, - { value: 'es-MX', label: 'Español' }, - { value: 'ja-JP', label: '日本語' }, - { value: 'nl-NL', label: 'Nederlands' }, - { value: 'it-IT', label: 'Italiano' }, -]; -export const languageValues = optionValues( languageOptions ); - -export const buttonStyle = { - name: 'button', - label: __( 'Button (210 x 113 pixels)', 'jetpack' ), -}; - -export const getStyleOptions = rid => - compact( [ - { name: 'standard', label: __( 'Standard (224 x 301 pixels)', 'jetpack' ), isDefault: true }, - { name: 'tall', label: __( 'Tall (288 x 490 pixels)', 'jetpack' ) }, - { name: 'wide', label: __( 'Wide (840 x 150 pixels)', 'jetpack' ) }, - ( ! rid || rid.length === 1 ) && buttonStyle, - ] ); - -export const getStyleValues = rid => getStyleOptions( rid ).map( option => option.name ); - -const siteLocale = window?.Jetpack_Editor_Initial_State?.siteLocale ?? 'en-US'; - -const defaultLanguage = - ! isEmpty( siteLocale ) && languageValues.includes( siteLocale ) ? siteLocale : 'en-US'; - -export const defaultAttributes = { - rid: { - default: [], - type: 'array', - }, - style: { - default: 'standard', - type: 'string', - validValues: getStyleValues(), - }, - iframe: { - default: true, - type: 'boolean', - }, - domain: { - default: 'com', - type: 'string', - }, - lang: { - default: defaultLanguage, - type: 'string', - validValues: languageValues, - }, - newtab: { - default: false, - type: 'boolean', - }, - negativeMargin: { - default: false, - type: 'boolean', - }, -}; diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/block.json b/projects/plugins/jetpack/extensions/blocks/opentable/block.json index 94e1d9868bc55..391a8ec4e18fb 100644 --- a/projects/plugins/jetpack/extensions/blocks/opentable/block.json +++ b/projects/plugins/jetpack/extensions/blocks/opentable/block.json @@ -1,6 +1,6 @@ { "$schema": "https://schemas.wp.org/trunk/block.json", - "apiVersion": 3, + "apiVersion": 1, "name": "jetpack/opentable", "title": "OpenTable", "description": "Book a reservation with OpenTable.", @@ -10,5 +10,47 @@ "category": "earn", "icon": "", "supports": { "align": true, "html": false }, - "editorScript": "file:../editor.js" + "attributes": { + "rid": { + "default": [], + "type": "array" + }, + "style": { + "default": "standard", + "type": "string", + "enum": [ "button", "standard", "wide", "tall" ] + }, + "iframe": { + "default": true, + "type": "boolean" + }, + "domain": { + "default": "com", + "type": "string" + }, + "lang": { + "default": "en-US", + "type": "string", + "enum": [ "en-US", "fr-CA", "de-DE", "es-MX", "ja-JP", "nl-NL", "it-IT" ] + }, + "newtab": { + "default": false, + "type": "boolean" + }, + "negativeMargin": { + "default": false, + "type": "boolean" + } + }, + "example": { + "attributes": { + "rid": [ "1" ], + "style": "standard", + "iframe": true, + "domain": "com", + "lang": "en-US", + "newtab": false, + "negativeMargin": false + } + } } diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v1/index.js b/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v1/index.js index 39ed252db5221..129bd2d2d2fa0 100644 --- a/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v1/index.js +++ b/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v1/index.js @@ -1,7 +1,7 @@ -import { defaultAttributes } from '../../attributes'; +import metadata from '../../block.json'; export default { - attributes: defaultAttributes, + attributes: metadata.attributes, supports: { align: true, html: false, diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v2/index.js b/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v2/index.js index e2b7214787ac2..711a6d758de36 100644 --- a/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v2/index.js +++ b/projects/plugins/jetpack/extensions/blocks/opentable/deprecated/v2/index.js @@ -1,7 +1,7 @@ -import { defaultAttributes } from '../../attributes'; +import metadata from '../../block.json'; export default { - attributes: defaultAttributes, + attributes: metadata.attributes, migrate: attributes => { const { style, className } = attributes; const styleClassName = 'standard' === style ? '' : `is-style-${ style }`; diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/edit.js b/projects/plugins/jetpack/extensions/blocks/opentable/edit.js index 4391ee9816921..f9bbcdd877666 100644 --- a/projects/plugins/jetpack/extensions/blocks/opentable/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/opentable/edit.js @@ -1,4 +1,8 @@ -import { isAtomicSite, isSimpleSite } from '@automattic/jetpack-shared-extension-utils'; +import { + isAtomicSite, + isSimpleSite, + getBlockIconComponent, +} from '@automattic/jetpack-shared-extension-utils'; import { InspectorControls, InspectorAdvancedControls } from '@wordpress/block-editor'; import { getBlockDefaultClassName, @@ -17,22 +21,19 @@ import { useEffect } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import classnames from 'classnames'; import { isEmpty, isEqual, join } from 'lodash'; -import './editor.scss'; import { getActiveStyleName } from '../../shared/block-styles'; import { getValidatedAttributes } from '../../shared/get-validated-attributes'; -import { - buttonStyle, - defaultAttributes, - getStyleOptions, - getStyleValues, - languageOptions, - languageValues, -} from './attributes'; -import icon from './icon'; +import metadata from './block.json'; +import { languageOptions, languageValues } from './i18n'; import RestaurantPicker from './restaurant-picker'; +import { buttonStyle, getStyleOptions, getStyleValues } from './styles'; import usePrevious from './use-previous'; import { getAttributesFromEmbedCode } from './utils'; +import './editor.scss'; + +const icon = getBlockIconComponent( metadata ); + function OpenTableEdit( { attributes, className, @@ -44,7 +45,7 @@ function OpenTableEdit( { setAttributes, } ) { const defaultClassName = getBlockDefaultClassName( name ); - const validatedAttributes = getValidatedAttributes( defaultAttributes, attributes ); + const validatedAttributes = getValidatedAttributes( metadata.attributes, attributes ); if ( ! isEqual( validatedAttributes, attributes ) ) { setAttributes( validatedAttributes ); @@ -81,7 +82,7 @@ function OpenTableEdit( { // Don't allow button style with multiple restaurant IDs. useEffect( () => { - if ( 'button' === selectedStyle && Array.isArray( rid ) && rid.length > 1 ) { + if ( 'button' === selectedStyle && Array.isArray( rid ) && rid?.length > 1 ) { setAttributes( { className: '', style: '' } ); } }, [ rid, selectedStyle, setAttributes ] ); @@ -92,7 +93,7 @@ function OpenTableEdit( { return; } - if ( Array.isArray( rid ) && rid.length > 1 ) { + if ( Array.isArray( rid ) && rid?.length > 1 ) { unregisterBlockStyle( 'jetpack/opentable', [ 'button' ] ); } else { registerBlockStyle( 'jetpack/opentable', buttonStyle ); @@ -131,14 +132,14 @@ function OpenTableEdit( { ); } - const validatedNewAttributes = getValidatedAttributes( defaultAttributes, newAttributes ); + const validatedNewAttributes = getValidatedAttributes( metadata.attributes, newAttributes ); setAttributes( validatedNewAttributes ); noticeOperations.removeAllNotices(); }; const styleValues = getStyleValues( rid ); const getTypeAndTheme = fromStyle => - rid.length > 1 + rid?.length > 1 ? [ 'multi', 'button' !== fromStyle ? fromStyle : 'standard' ] : [ 'button' === fromStyle ? 'button' : 'standard', diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/editor.js b/projects/plugins/jetpack/extensions/blocks/opentable/editor.js index d7ec194d817a1..8b41382af5589 100644 --- a/projects/plugins/jetpack/extensions/blocks/opentable/editor.js +++ b/projects/plugins/jetpack/extensions/blocks/opentable/editor.js @@ -1,4 +1,45 @@ -import registerJetpackBlock from '../../shared/register-jetpack-block'; -import { name, settings } from '.'; +import { createBlock } from '@wordpress/blocks'; +import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block'; +import metadata from './block.json'; +import deprecatedV1 from './deprecated/v1'; +import deprecatedV2 from './deprecated/v2'; +import edit from './edit'; +import { getStyleOptions } from './styles'; +import { getAttributesFromEmbedCode, restRefRegex, ridRegex } from './utils'; -registerJetpackBlock( name, settings ); +import './editor.scss'; +import './view.scss'; + +registerJetpackBlockFromMetadata( metadata, { + edit, + save: ( { attributes: { rid } } ) => ( +
+ { rid?.map( ( restaurantId, restaurantIndex ) => ( + + { `https://www.opentable.com/restref/client/?rid=${ restaurantId }` } + + ) ) } +
+ ), + attributes: metadata.attributes, + styles: getStyleOptions(), + transforms: { + from: [ + { + type: 'raw', + isMatch: node => + node.nodeName === 'P' && + node.textContent.indexOf( 'http' ) === 0 && + ( ridRegex.test( node.textContent ) || restRefRegex.test( node.textContent ) ), + transform: node => { + const newAttributes = getAttributesFromEmbedCode( node.textContent ); + return createBlock( 'jetpack/opentable', newAttributes ); + }, + }, + ], + }, + deprecated: [ deprecatedV1, deprecatedV2 ], +} ); diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/i18n.js b/projects/plugins/jetpack/extensions/blocks/opentable/i18n.js new file mode 100644 index 0000000000000..3f34041ba8fa6 --- /dev/null +++ b/projects/plugins/jetpack/extensions/blocks/opentable/i18n.js @@ -0,0 +1,12 @@ +const optionValues = options => options.map( option => option.value ); + +export const languageOptions = [ + { value: 'en-US', label: 'English' }, + { value: 'fr-CA', label: 'Français' }, + { value: 'de-DE', label: 'Deutsch' }, + { value: 'es-MX', label: 'Español' }, + { value: 'ja-JP', label: '日本語' }, + { value: 'nl-NL', label: 'Nederlands' }, + { value: 'it-IT', label: 'Italiano' }, +]; +export const languageValues = optionValues( languageOptions ); diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/icon.js b/projects/plugins/jetpack/extensions/blocks/opentable/icon.js deleted file mode 100644 index c1cd082eb9866..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/opentable/icon.js +++ /dev/null @@ -1,7 +0,0 @@ -import { SVG, Path } from '@wordpress/components'; - -export default ( - - - -); diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/index.js b/projects/plugins/jetpack/extensions/blocks/opentable/index.js deleted file mode 100644 index ac57130d6ec95..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/opentable/index.js +++ /dev/null @@ -1,75 +0,0 @@ -import { createBlock } from '@wordpress/blocks'; -import { __, _x } from '@wordpress/i18n'; -import { getIconColor } from '../../shared/block-icons'; -import { defaultAttributes, getStyleOptions } from './attributes'; -import deprecatedV1 from './deprecated/v1'; -import deprecatedV2 from './deprecated/v2'; -import edit from './edit'; -import icon from './icon'; -import { getAttributesFromEmbedCode, restRefRegex, ridRegex } from './utils'; -import './editor.scss'; -import './view.scss'; - -export const name = 'opentable'; -export const title = __( 'OpenTable', 'jetpack' ); - -export const settings = { - title, - description: __( 'Book a reservation with OpenTable.', 'jetpack' ), - icon: { - src: icon, - foreground: getIconColor(), - }, - category: 'earn', - keywords: [ - _x( 'booking', 'block search term', 'jetpack' ), - _x( 'reservation', 'block search term', 'jetpack' ), - _x( 'restaurant', 'block search term', 'jetpack' ), - ], - supports: { - align: true, - html: false, - }, - edit, - save: ( { attributes: { rid } } ) => ( -
- { rid.map( ( restaurantId, restaurantIndex ) => ( - - { `https://www.opentable.com/restref/client/?rid=${ restaurantId }` } - - ) ) } -
- ), - attributes: defaultAttributes, - styles: getStyleOptions(), - example: { - attributes: { - rid: [ '1' ], - style: 'standard', - iframe: true, - domain: 'com', - lang: 'en-US', - newtab: false, - negativeMargin: false, - }, - }, - transforms: { - from: [ - { - type: 'raw', - isMatch: node => - node.nodeName === 'P' && - node.textContent.indexOf( 'http' ) === 0 && - ( ridRegex.test( node.textContent ) || restRefRegex.test( node.textContent ) ), - transform: node => { - const newAttributes = getAttributesFromEmbedCode( node.textContent ); - return createBlock( 'jetpack/opentable', newAttributes ); - }, - }, - ], - }, - deprecated: [ deprecatedV1, deprecatedV2 ], -}; diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/opentable.php b/projects/plugins/jetpack/extensions/blocks/opentable/opentable.php index 1a6bcb6212e6b..2e4f5b17194d4 100644 --- a/projects/plugins/jetpack/extensions/blocks/opentable/opentable.php +++ b/projects/plugins/jetpack/extensions/blocks/opentable/opentable.php @@ -12,9 +12,6 @@ use Automattic\Jetpack\Blocks; use Jetpack_Gutenberg; -const FEATURE_NAME = 'opentable'; -const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; - /** * Registers the block for use in Gutenberg * This is done via an action so that we can disable @@ -22,7 +19,7 @@ */ function register_block() { Blocks::jetpack_register_block( - BLOCK_NAME, + __DIR__, array( 'render_callback' => __NAMESPACE__ . '\load_assets', 'plan_check' => true, @@ -40,7 +37,7 @@ function register_block() { */ function load_assets( $attributes ) { - Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); + Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); $classes = array(); $class_name = get_attribute( $attributes, 'className' ); @@ -62,7 +59,7 @@ function load_assets( $attributes ) { if ( array_key_exists( 'negativeMargin', $attributes ) && $attributes['negativeMargin'] ) { $classes[] = 'has-no-margin'; } - $classes = Blocks::classes( FEATURE_NAME, $attributes, $classes ); + $classes = Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attributes, $classes ); $content = '
'; $script_url = build_embed_url( $attributes ); diff --git a/projects/plugins/jetpack/extensions/blocks/opentable/styles.js b/projects/plugins/jetpack/extensions/blocks/opentable/styles.js new file mode 100644 index 0000000000000..af6b0ec1cd5e8 --- /dev/null +++ b/projects/plugins/jetpack/extensions/blocks/opentable/styles.js @@ -0,0 +1,17 @@ +import { __ } from '@wordpress/i18n'; +import { compact } from 'lodash'; + +export const buttonStyle = { + name: 'button', + label: __( 'Button (210 x 113 pixels)', 'jetpack' ), +}; + +export const getStyleOptions = rid => + compact( [ + { name: 'standard', label: __( 'Standard (224 x 301 pixels)', 'jetpack' ), isDefault: true }, + { name: 'tall', label: __( 'Tall (288 x 490 pixels)', 'jetpack' ) }, + { name: 'wide', label: __( 'Wide (840 x 150 pixels)', 'jetpack' ) }, + ( ! rid || rid.length === 1 ) && buttonStyle, + ] ); + +export const getStyleValues = rid => getStyleOptions( rid ).map( option => option.name ); diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/block.json b/projects/plugins/jetpack/extensions/blocks/payment-buttons/block.json index 91c08b5f2ad86..4d2e47947fbc2 100644 --- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/block.json +++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/block.json @@ -64,6 +64,5 @@ } } }, - "attributes": {}, - "editorScript": "file:../editor.js" + "attributes": {} } diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/editor.js b/projects/plugins/jetpack/extensions/blocks/payment-buttons/editor.js index d7ec194d817a1..b952d5df5a0eb 100644 --- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/editor.js +++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/editor.js @@ -1,4 +1,11 @@ -import registerJetpackBlock from '../../shared/register-jetpack-block'; -import { name, settings } from '.'; +import { registerJetpackBlockFromMetadata } from '../../shared/register-jetpack-block'; +import metadata from './block.json'; +import edit from './edit'; +import save from './save'; -registerJetpackBlock( name, settings ); +import './editor.scss'; + +registerJetpackBlockFromMetadata( metadata, { + edit, + save, +} ); diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/index.js b/projects/plugins/jetpack/extensions/blocks/payment-buttons/index.js deleted file mode 100644 index 106745b4142e7..0000000000000 --- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/index.js +++ /dev/null @@ -1,70 +0,0 @@ -import { isAtomicSite, isSimpleSite } from '@automattic/jetpack-shared-extension-utils'; -import { Path, Rect, SVG, G, ExternalLink } from '@wordpress/components'; -import { Fragment } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; -import { getIconColor } from '../../shared/block-icons'; -import { settings as paymentButtonSettings } from '../recurring-payments'; -import edit from './edit'; -import save from './save'; -import './editor.scss'; - -export const name = 'payment-buttons'; -export const title = __( 'Payment Buttons', 'jetpack' ); -export const icon = ( - - - - - - -); - -const supportLink = - isSimpleSite() || isAtomicSite() - ? 'https://wordpress.com/support/video-tutorials-add-payments-features-to-your-site-with-our-guides/#how-to-use-the-payments-block-video' - : 'https://jetpack.com/support/jetpack-blocks/payments-block/'; - -export const settings = { - apiVersion: 2, - title, - icon: { - src: icon, - foreground: getIconColor(), - }, - description: ( - -

{ __( 'Sell products and subscriptions.', 'jetpack' ) }

- { __( 'Support reference', 'jetpack' ) } -
- ), - category: 'earn', - keywords: [ ...new Set( [ paymentButtonSettings.title, ...paymentButtonSettings.keywords ] ) ], - edit, - save, - supports: { - __experimentalExposeControlsToChildren: true, - align: [ 'wide', 'full' ], - spacing: { - blockGap: true, - margin: [ 'vertical' ], - __experimentalDefaultControls: { - blockGap: true, - }, - }, - __experimentalLayout: { - allowSwitching: false, - allowInheriting: false, - default: { - type: 'flex', - }, - }, - typography: { - fontSize: true, - __experimentalFontFamily: true, - __experimentalTextTransform: true, - __experimentalDefaultControls: { - fontSize: true, - }, - }, - }, -}; diff --git a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php index 892e2a19211dd..f75443f2d74d1 100644 --- a/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php +++ b/projects/plugins/jetpack/extensions/blocks/payment-buttons/payment-buttons.php @@ -11,9 +11,6 @@ use Automattic\Jetpack\Blocks; -const FEATURE_NAME = 'payment-buttons'; -const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; - /** * Registers the block for use in Gutenberg * This is done via an action so that we can disable @@ -27,7 +24,7 @@ function register_block() { require_once JETPACK__PLUGIN_DIR . '/modules/memberships/class-jetpack-memberships.php'; if ( \Jetpack_Memberships::is_enabled_jetpack_recurring_payments() ) { Blocks::jetpack_register_block( - BLOCK_NAME, + __DIR__, array( 'render_callback' => __NAMESPACE__ . '\render_block', 'supports' => array( @@ -44,7 +41,7 @@ function register_block() { } else { $required_plan = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? 'personal-bundle' : 'jetpack_personal'; \Jetpack_Gutenberg::set_extension_unavailable( - BLOCK_NAME, + Blocks::get_block_name( __DIR__ ), 'missing_plan', array( 'required_feature' => 'memberships', @@ -64,7 +61,7 @@ function register_block() { * @return string */ function render_block( $attributes, $content ) { - \Jetpack_Gutenberg::load_styles_as_required( FEATURE_NAME ); + \Jetpack_Gutenberg::load_styles_as_required( __DIR__ ); return $content; } diff --git a/projects/plugins/jetpack/extensions/blocks/payments-intro/variations.js b/projects/plugins/jetpack/extensions/blocks/payments-intro/variations.js index e757275fc53f6..95ad41bd99259 100644 --- a/projects/plugins/jetpack/extensions/blocks/payments-intro/variations.js +++ b/projects/plugins/jetpack/extensions/blocks/payments-intro/variations.js @@ -4,12 +4,12 @@ import { getBlockIconComponent } from '@automattic/jetpack-shared-extension-utils'; import donationMetadata from '../donations/block.json'; -import { name as paymentButtonsName, settings as paymentButtonsSettings } from '../payment-buttons'; +import paymentButtonsMetadata from '../payment-buttons/block.json'; import { name as premiumContentName, settings as premiumContentSettings } from '../premium-content'; const variations = [ [ donationMetadata.name, donationMetadata ], - [ paymentButtonsName, paymentButtonsSettings ], + [ paymentButtonsMetadata.name, paymentButtonsMetadata ], [ premiumContentName, premiumContentSettings ], ];