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 }