From 369c173fab3e1ca9d4f35ce01b543c688f224001 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 19 Feb 2020 14:41:48 +0100 Subject: [PATCH 01/15] Jetpack editor basic setup --- .gitmodules | 3 ++ jetpack | 1 + src/index.js | 2 ++ src/jetpack-editor-setup.js | 56 +++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 160000 jetpack create mode 100644 src/jetpack-editor-setup.js diff --git a/.gitmodules b/.gitmodules index e0461622a7..6db1dc2b72 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "gutenberg"] path = gutenberg url = ../../WordPress/gutenberg.git +[submodule "jetpack"] + path = jetpack + url = ../../Automattic/jetpack.git diff --git a/jetpack b/jetpack new file mode 160000 index 0000000000..d9bbec6d07 --- /dev/null +++ b/jetpack @@ -0,0 +1 @@ +Subproject commit d9bbec6d07f3e40614525fd1dc956297e6196316 diff --git a/src/index.js b/src/index.js index 31630914f8..7e420ff65a 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,7 @@ import './globals'; import { getTranslation } from '../i18n-cache'; import initialHtml from './initial-html'; import setupApiFetch from './api-fetch-setup'; +import setupJetpackEditor from './jetpack-editor-setup'; const gutenbergSetup = () => { const wpData = require( '@wordpress/data' ); @@ -56,6 +57,7 @@ export class RootComponent extends React.Component { setupLocale( props.locale, props.translations ); setupApiFetch(); require( '@wordpress/edit-post' ).initializeEditor(); + setupJetpackEditor( props.jetpackState || { blogId: 1, isJetpackActive: true } ); const isHermes = () => global.HermesInternal !== null; // eslint-disable-next-line no-console diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js new file mode 100644 index 0000000000..e32a0b59d4 --- /dev/null +++ b/src/jetpack-editor-setup.js @@ -0,0 +1,56 @@ +/** @format */ + +/** + * External dependencies + */ +import { JETPACK_DATA_PATH } from '../jetpack/extensions/shared/get-jetpack-data'; + +/** + * WordPress dependencies + */ +import apiFetch from '@wordpress/api-fetch'; + +const contactInfo = '../jetpack/extensions/blocks/contact-info/editor.js'; +const supportedJetpackBlocks = { + 'contact-info': { + available: true + } +}; + +const setInitialState = async ( { + isJetpackActive = false, + userData = null, + siteFragment = null, + blogId, +} ) => { + let availableBlocks = {}; + if ( isJetpackActive ) { + availableBlocks = supportedJetpackBlocks;//await apiFetch( { path: `/wp/v2/gutenberg/available-extensions` } ); + } + const jetpackEditorInitialState = { + available_blocks: availableBlocks, + jetpack: { + is_active: isJetpackActive, + }, + siteFragment: siteFragment, + tracksUserData: userData, + wpcomBlogId: blogId, + }; + global.window[ JETPACK_DATA_PATH ] = jetpackEditorInitialState; + return jetpackEditorInitialState; +}; + +export default async ( jetpackState ) => { + if ( ! jetpackState.isJetpackActive ) { + return; + } + + require( '../jetpack/extensions/editor' ); + + const jetpackEditorInitialState = await setInitialState( jetpackState ); + + //jetpackEditorInitialState.available_blocks + console.log( 'requiring jetpack/contact-info' ); + require( contactInfo ); +}; + From 4527d761a11e20f047fb892bc96b49df8ac29911 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 19 Feb 2020 14:42:15 +0100 Subject: [PATCH 02/15] prettier --- src/jetpack-editor-setup.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index e32a0b59d4..ef10653d61 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -3,6 +3,9 @@ /** * External dependencies */ +/** + * Internal dependencies + */ import { JETPACK_DATA_PATH } from '../jetpack/extensions/shared/get-jetpack-data'; /** @@ -13,26 +16,26 @@ import apiFetch from '@wordpress/api-fetch'; const contactInfo = '../jetpack/extensions/blocks/contact-info/editor.js'; const supportedJetpackBlocks = { 'contact-info': { - available: true - } + available: true, + }, }; const setInitialState = async ( { - isJetpackActive = false, - userData = null, - siteFragment = null, - blogId, + isJetpackActive = false, + userData = null, + siteFragment = null, + blogId, } ) => { let availableBlocks = {}; if ( isJetpackActive ) { - availableBlocks = supportedJetpackBlocks;//await apiFetch( { path: `/wp/v2/gutenberg/available-extensions` } ); + availableBlocks = supportedJetpackBlocks; //await apiFetch( { path: `/wp/v2/gutenberg/available-extensions` } ); } const jetpackEditorInitialState = { available_blocks: availableBlocks, jetpack: { is_active: isJetpackActive, }, - siteFragment: siteFragment, + siteFragment, tracksUserData: userData, wpcomBlogId: blogId, }; @@ -53,4 +56,3 @@ export default async ( jetpackState ) => { console.log( 'requiring jetpack/contact-info' ); require( contactInfo ); }; - From 99fb15a42d4cad2780bcfc1bb2c1bc63953f78f6 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Thu, 20 Feb 2020 10:46:52 +0100 Subject: [PATCH 03/15] Add support for contact-info inner blocks: address email and phone --- jetpack | 2 +- package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/jetpack b/jetpack index d9bbec6d07..b34e858230 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit d9bbec6d07f3e40614525fd1dc956297e6196316 +Subproject commit b34e858230be2ea4155288bb7ead0bd2b5ac7a6f diff --git a/package.json b/package.json index a13ce10426..83cfb26307 100644 --- a/package.json +++ b/package.json @@ -146,6 +146,7 @@ "classnames": "^2.2.5", "dom-react": "^2.2.1", "domutils": "^1.7.0", + "email-validator": "2.0.4", "fast-average-color": "^4.3.0", "gettext-parser": "^4.0.2", "hpq": "^1.2.0", diff --git a/yarn.lock b/yarn.lock index 9d2f54e5f1..f946435668 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5671,6 +5671,11 @@ elliptic@^6.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.0" +email-validator@2.0.4: + version "2.0.4" + resolved "https://registry.yarnpkg.com/email-validator/-/email-validator-2.0.4.tgz#b8dfaa5d0dae28f1b03c95881d904d4e40bfe7ed" + integrity sha512-gYCwo7kh5S3IDyZPLZf6hSS0MnZT8QmJFqYvbqlDZSbwdZlY6QZWxJ4i/6UhITOJ4XzyI647Bm2MXKCLqnJ4nQ== + emitter-listener@^1.1.1: version "1.1.2" resolved "https://registry.yarnpkg.com/emitter-listener/-/emitter-listener-1.1.2.tgz#56b140e8f6992375b3d7cb2cab1cc7432d9632e8" From d1c4d905e54407c6511c9b0d3cd0d023856dd55c Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 26 Feb 2020 12:11:59 +0100 Subject: [PATCH 04/15] Try fetching /gutenberg/available-extensions --- gutenberg | 2 +- src/api-fetch-setup.js | 5 ++++- src/jetpack-editor-setup.js | 7 ++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gutenberg b/gutenberg index 5870cafa74..dcfcb47bdb 160000 --- a/gutenberg +++ b/gutenberg @@ -1 +1 @@ -Subproject commit 5870cafa74aee22b1c59c26451561a722c769c73 +Subproject commit dcfcb47bdbb91d7b8abb57c68533d1ebaa8929be diff --git a/src/api-fetch-setup.js b/src/api-fetch-setup.js index 0dc5708a39..21852c9150 100644 --- a/src/api-fetch-setup.js +++ b/src/api-fetch-setup.js @@ -41,7 +41,10 @@ const fetchHandler = ( { path }, retries = 20, retryCount = 1 ) => { }; export const isPathSupported = ( path ) => - [ /wp\/v2\/media\/?\d*?.*/i ].some( ( pattern ) => pattern.test( path ) ); + [ + /wp\/v2\/media\/?\d*?.*/i, + /wpcom\/v2\/gutenberg\/.*/i, + ].some( ( pattern ) => pattern.test( path ) ); export default () => { apiFetch.setFetchHandler( ( options ) => fetchHandler( options ) ); diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index ef10653d61..b508608465 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -28,7 +28,12 @@ const setInitialState = async ( { } ) => { let availableBlocks = {}; if ( isJetpackActive ) { - availableBlocks = supportedJetpackBlocks; //await apiFetch( { path: `/wp/v2/gutenberg/available-extensions` } ); + console.log( 'Fetching /wpcom/v2/gutenberg/available-extensions' ); + try { + availableBlocks = await apiFetch( { path: `/wpcom/v2/gutenberg/available-extensions` } ); + } catch ( error ) { + console.error( 'Error while fetching available extensions', error ); + } } const jetpackEditorInitialState = { available_blocks: availableBlocks, From 9a526187d3b7e475cfd0520f5652a19713af4fd0 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 26 Feb 2020 16:29:40 +0100 Subject: [PATCH 05/15] Explicitely import native compatible blocks --- .eslintignore | 1 + jetpack | 2 +- src/jetpack-editor-setup.js | 11 ++++------- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.eslintignore b/.eslintignore index 31b736e524..d5a70128a7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,3 +4,4 @@ symlinked-packages symlinked-packages-in-parent react-native-aztec bundle +jetpack diff --git a/jetpack b/jetpack index b34e858230..276e42512e 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit b34e858230be2ea4155288bb7ead0bd2b5ac7a6f +Subproject commit 276e42512e1baae09727d1e1ef129c263a5b207d diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index b508608465..6c727ce6da 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -13,7 +13,6 @@ import { JETPACK_DATA_PATH } from '../jetpack/extensions/shared/get-jetpack-data */ import apiFetch from '@wordpress/api-fetch'; -const contactInfo = '../jetpack/extensions/blocks/contact-info/editor.js'; const supportedJetpackBlocks = { 'contact-info': { available: true, @@ -32,7 +31,9 @@ const setInitialState = async ( { try { availableBlocks = await apiFetch( { path: `/wpcom/v2/gutenberg/available-extensions` } ); } catch ( error ) { - console.error( 'Error while fetching available extensions', error ); + console.warn( 'Error while fetching available extensions', error ); + // manually set availableBlocks while WP REST API auth is being worked on + availableBlocks = supportedJetpackBlocks; } } const jetpackEditorInitialState = { @@ -55,9 +56,5 @@ export default async ( jetpackState ) => { require( '../jetpack/extensions/editor' ); - const jetpackEditorInitialState = await setInitialState( jetpackState ); - - //jetpackEditorInitialState.available_blocks - console.log( 'requiring jetpack/contact-info' ); - require( contactInfo ); + return setInitialState( jetpackState ); }; From ded8fff809a06cca07daac36c26d17ff3606e8f7 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 18 Mar 2020 13:05:10 +0100 Subject: [PATCH 06/15] Skip apiFetch for now while WP REST API Auth is not yet supported --- src/api-fetch-setup.js | 7 +++---- src/jetpack-editor-setup.js | 18 +++++------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/api-fetch-setup.js b/src/api-fetch-setup.js index 21852c9150..40ec858a70 100644 --- a/src/api-fetch-setup.js +++ b/src/api-fetch-setup.js @@ -41,10 +41,9 @@ const fetchHandler = ( { path }, retries = 20, retryCount = 1 ) => { }; export const isPathSupported = ( path ) => - [ - /wp\/v2\/media\/?\d*?.*/i, - /wpcom\/v2\/gutenberg\/.*/i, - ].some( ( pattern ) => pattern.test( path ) ); + [ /wp\/v2\/media\/?\d*?.*/i, /wpcom\/v2\/gutenberg\/.*/i ].some( ( pattern ) => + pattern.test( path ) + ); export default () => { apiFetch.setFetchHandler( ( options ) => fetchHandler( options ) ); diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index 6c727ce6da..b6ddde001f 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -19,23 +19,13 @@ const supportedJetpackBlocks = { }, }; -const setInitialState = async ( { +const setJetpackData = async ( { isJetpackActive = false, userData = null, siteFragment = null, blogId, } ) => { - let availableBlocks = {}; - if ( isJetpackActive ) { - console.log( 'Fetching /wpcom/v2/gutenberg/available-extensions' ); - try { - availableBlocks = await apiFetch( { path: `/wpcom/v2/gutenberg/available-extensions` } ); - } catch ( error ) { - console.warn( 'Error while fetching available extensions', error ); - // manually set availableBlocks while WP REST API auth is being worked on - availableBlocks = supportedJetpackBlocks; - } - } + const availableBlocks = supportedJetpackBlocks; const jetpackEditorInitialState = { available_blocks: availableBlocks, jetpack: { @@ -54,7 +44,9 @@ export default async ( jetpackState ) => { return; } + const jetpackData = await setJetpackData( jetpackState ); + require( '../jetpack/extensions/editor' ); - return setInitialState( jetpackState ); + return jetpackData; }; From 2cbb7a6df0e4f5283a80489babd8c7a2d78ee97b Mon Sep 17 00:00:00 2001 From: Cameron Voell Date: Fri, 27 Mar 2020 01:11:26 -0700 Subject: [PATCH 07/15] Update jetpack reference --- jetpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetpack b/jetpack index 276e42512e..09d73e94da 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit 276e42512e1baae09727d1e1ef129c263a5b207d +Subproject commit 09d73e94da3b5005578b6d5d2ba490de690e186c From 81d7799a763f61335fe336b5b4ded5a6a2de5d3c Mon Sep 17 00:00:00 2001 From: Cameron Voell Date: Mon, 6 Apr 2020 11:17:11 -0700 Subject: [PATCH 08/15] Update gutenberg ref --- gutenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gutenberg b/gutenberg index dcfcb47bdb..3077c6ac54 160000 --- a/gutenberg +++ b/gutenberg @@ -1 +1 @@ -Subproject commit dcfcb47bdbb91d7b8abb57c68533d1ebaa8929be +Subproject commit 3077c6ac54dcf127f8573d241489f4c5a3bbdc9d From b3c364c84dc0434d5c3890da9012038a41eb989e Mon Sep 17 00:00:00 2001 From: Cameron Voell Date: Tue, 7 Apr 2020 19:32:35 -0700 Subject: [PATCH 09/15] Register jetpack blocks before html parsing --- src/index.js | 2 +- src/jetpack-editor-setup.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 0ff3dcef92..ea05b3719d 100644 --- a/src/index.js +++ b/src/index.js @@ -56,8 +56,8 @@ export class RootComponent extends React.Component { super( props ); setupLocale( props.locale, props.translations ); setupApiFetch(); - require( '@wordpress/edit-post' ).initializeEditor(); setupJetpackEditor( props.jetpackState || { blogId: 1, isJetpackActive: true } ); + require( '@wordpress/edit-post' ).initializeEditor(); const isHermes = () => global.HermesInternal !== null; // eslint-disable-next-line no-console diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index b6ddde001f..a566ea4837 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -19,7 +19,7 @@ const supportedJetpackBlocks = { }, }; -const setJetpackData = async ( { +const setJetpackData = ( { isJetpackActive = false, userData = null, siteFragment = null, @@ -39,12 +39,12 @@ const setJetpackData = async ( { return jetpackEditorInitialState; }; -export default async ( jetpackState ) => { +export default ( jetpackState ) => { if ( ! jetpackState.isJetpackActive ) { return; } - const jetpackData = await setJetpackData( jetpackState ); + const jetpackData = setJetpackData( jetpackState ); require( '../jetpack/extensions/editor' ); From 98d5259cc7deae0518adb0b5692c05885ffd3df0 Mon Sep 17 00:00:00 2001 From: Cameron Voell Date: Thu, 9 Apr 2020 01:20:27 -0700 Subject: [PATCH 10/15] Update jetpack ref to fix inner block focus --- jetpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetpack b/jetpack index 09d73e94da..97092d79b0 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit 09d73e94da3b5005578b6d5d2ba490de690e186c +Subproject commit 97092d79b00e33869d0f97e57ef1327ab7994639 From ce92adf9de4e9529b558c00ee4187c1d01e77e0f Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 15 Apr 2020 16:37:17 +0200 Subject: [PATCH 11/15] Update jetpack ref --- jetpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetpack b/jetpack index 97092d79b0..3052f50ead 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit 97092d79b00e33869d0f97e57ef1327ab7994639 +Subproject commit 3052f50ead87fd1c59f37ebfb0f381dbe1e9c14e From 064013a93f338f8811a6ed78d2241f6ee545a165 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Wed, 15 Apr 2020 19:40:03 +0200 Subject: [PATCH 12/15] Update jetpack ref --- jetpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetpack b/jetpack index 3052f50ead..91ed9da32c 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit 3052f50ead87fd1c59f37ebfb0f381dbe1e9c14e +Subproject commit 91ed9da32c963e6ed50c38616c5013afe257af52 From 96d86b9ec472ece54579872090aea8006c50b08a Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Thu, 16 Apr 2020 16:26:57 +0200 Subject: [PATCH 13/15] Remove unused dependency in jetpack-editor-setup --- src/jetpack-editor-setup.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index a566ea4837..ea03ceb2da 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -8,11 +8,6 @@ */ import { JETPACK_DATA_PATH } from '../jetpack/extensions/shared/get-jetpack-data'; -/** - * WordPress dependencies - */ -import apiFetch from '@wordpress/api-fetch'; - const supportedJetpackBlocks = { 'contact-info': { available: true, From 6bfa3ab85184273063bc7f4291b494990d9c64d5 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Thu, 16 Apr 2020 16:28:28 +0200 Subject: [PATCH 14/15] Target final jetpack ref in master --- jetpack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetpack b/jetpack index 91ed9da32c..f6f313d268 160000 --- a/jetpack +++ b/jetpack @@ -1 +1 @@ -Subproject commit 91ed9da32c963e6ed50c38616c5013afe257af52 +Subproject commit f6f313d268c336491c8bca1afcf3e5d3663597ce From f0d0b84bce92ce702ed92e6db82eab42c3f16e49 Mon Sep 17 00:00:00 2001 From: Tugdual de Kerviler Date: Thu, 16 Apr 2020 16:42:46 +0200 Subject: [PATCH 15/15] Hide in production --- src/jetpack-editor-setup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js index ea03ceb2da..3f1d2eb019 100644 --- a/src/jetpack-editor-setup.js +++ b/src/jetpack-editor-setup.js @@ -41,7 +41,9 @@ export default ( jetpackState ) => { const jetpackData = setJetpackData( jetpackState ); - require( '../jetpack/extensions/editor' ); + if ( __DEV__ ) { + require( '../jetpack/extensions/editor' ); + } return jetpackData; };