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/.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..f6f313d268 --- /dev/null +++ b/jetpack @@ -0,0 +1 @@ +Subproject commit f6f313d268c336491c8bca1afcf3e5d3663597ce diff --git a/package.json b/package.json index 7a935d3085..ad06cf4621 100644 --- a/package.json +++ b/package.json @@ -149,6 +149,7 @@ "classnames": "^2.2.5", "dom-react": "^2.2.1", "domutils": "^1.7.0", + "email-validator": "2.0.4", "emotion": "^10.0.27", "emotion-theming": "^10.0.27", "fast-average-color": "^4.3.0", diff --git a/src/api-fetch-setup.js b/src/api-fetch-setup.js index efd0141902..79e68588e0 100644 --- a/src/api-fetch-setup.js +++ b/src/api-fetch-setup.js @@ -41,7 +41,9 @@ const fetchHandler = ( { path }, retries = 20, retryCount = 1 ) => { }; export const isPathSupported = ( path ) => - [ /wp\/v2\/(media|categories)\/?\d*?.*/i ].some( ( pattern ) => pattern.test( path ) ); + [ /wp\/v2\/(media|categories)\/?\d*?.*/i, /wpcom\/v2\/gutenberg\/.*/i ].some( ( pattern ) => + pattern.test( path ) + ); export default () => { apiFetch.setFetchHandler( ( options ) => fetchHandler( options ) ); diff --git a/src/index.js b/src/index.js index 8a30c5a3e0..ea05b3719d 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' ); @@ -55,6 +56,7 @@ export class RootComponent extends React.Component { super( props ); setupLocale( props.locale, props.translations ); setupApiFetch(); + setupJetpackEditor( props.jetpackState || { blogId: 1, isJetpackActive: true } ); require( '@wordpress/edit-post' ).initializeEditor(); const isHermes = () => global.HermesInternal !== null; diff --git a/src/jetpack-editor-setup.js b/src/jetpack-editor-setup.js new file mode 100644 index 0000000000..3f1d2eb019 --- /dev/null +++ b/src/jetpack-editor-setup.js @@ -0,0 +1,49 @@ +/** @format */ + +/** + * External dependencies + */ +/** + * Internal dependencies + */ +import { JETPACK_DATA_PATH } from '../jetpack/extensions/shared/get-jetpack-data'; + +const supportedJetpackBlocks = { + 'contact-info': { + available: true, + }, +}; + +const setJetpackData = ( { + isJetpackActive = false, + userData = null, + siteFragment = null, + blogId, +} ) => { + const availableBlocks = supportedJetpackBlocks; + const jetpackEditorInitialState = { + available_blocks: availableBlocks, + jetpack: { + is_active: isJetpackActive, + }, + siteFragment, + tracksUserData: userData, + wpcomBlogId: blogId, + }; + global.window[ JETPACK_DATA_PATH ] = jetpackEditorInitialState; + return jetpackEditorInitialState; +}; + +export default ( jetpackState ) => { + if ( ! jetpackState.isJetpackActive ) { + return; + } + + const jetpackData = setJetpackData( jetpackState ); + + if ( __DEV__ ) { + require( '../jetpack/extensions/editor' ); + } + + return jetpackData; +}; diff --git a/yarn.lock b/yarn.lock index c92557b80d..85641f08fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6430,6 +6430,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"