From 69408f4413e2b63391fcbab92b87123d43f8e0d1 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 4 Feb 2021 15:31:29 -0600 Subject: [PATCH 01/21] Display the help text for the TextareaArray setting Without this, it's really hard to know what to enter. This existed before, but it usually had markup. So instead of doing __dangerouslySetInnerHTML={}, enter the markup in the React file, and use other help text if it exists. --- js/src/edit-block/components/editor.js | 10 +++++++ js/src/edit-block/components/input.js | 2 +- js/src/edit-block/components/select.js | 2 +- .../components/settings/checkbox.js | 2 +- .../edit-block/components/settings/email.js | 2 +- .../components/settings/location.js | 2 +- .../components/settings/new-line-format.js | 2 +- .../settings/number-non-negative.js | 2 +- .../edit-block/components/settings/number.js | 2 +- js/src/edit-block/components/settings/text.js | 2 +- .../components/settings/textarea-array.js | 30 ++++++++++++++++++- .../components/settings/textarea.js | 2 +- .../edit-block/components/settings/width.js | 2 +- .../helpers/getSettingsComponent.js | 2 +- .../edit-block/helpers/getSettingsDefaults.js | 15 +--------- php/Blocks/Controls/Multiselect.php | 10 ++----- php/Blocks/Controls/Radio.php | 8 +---- php/Blocks/Controls/Select.php | 8 +---- .../Unit/Blocks/Controls/TestMultiselect.php | 4 +-- tests/php/Unit/Blocks/Controls/TestRadio.php | 2 +- tests/php/Unit/Blocks/Controls/TestSelect.php | 2 +- 21 files changed, 60 insertions(+), 53 deletions(-) diff --git a/js/src/edit-block/components/editor.js b/js/src/edit-block/components/editor.js index 6c5ee15a3..69cd000d7 100644 --- a/js/src/edit-block/components/editor.js +++ b/js/src/edit-block/components/editor.js @@ -74,6 +74,16 @@ import { * @property {string} [width] The width, like '25'. */ +/** + * @typedef {Object} Setting A field setting. + * @see PHP class Genesis\CustomBlocks\Blocks\Controls\ControlSetting + * @property {string} name The name of the setting. + * @property {string} label The label of the setting to display in the GCB editor. + * @property {string} help A help value that display in the GCB editor. + * @property {string} type The setting type, like 'width' or 'text', not a data type like boolean. + * @property {*} default The default value. + */ + /** * The editor component. * diff --git a/js/src/edit-block/components/input.js b/js/src/edit-block/components/input.js index 24d7f47d8..fc6b11121 100644 --- a/js/src/edit-block/components/input.js +++ b/js/src/edit-block/components/input.js @@ -6,7 +6,7 @@ import * as React from 'react'; /** * @typedef {Object} InputProps The component props. * @property {Function} handleOnChange Handles a change in this setting. - * @property {Object} setting This setting. + * @property {import('./editor').Setting} setting This setting. * @property {string} type The type of , like 'text'. * @property {string|undefined} value The setting value. * @property {number} [min] The min attribute of an input[type="number"]. diff --git a/js/src/edit-block/components/select.js b/js/src/edit-block/components/select.js index a0f87863e..2720ad94c 100644 --- a/js/src/edit-block/components/select.js +++ b/js/src/edit-block/components/select.js @@ -8,7 +8,7 @@ import * as React from 'react'; * @property {Function} handleOnChange Handles a change in this setting. * @property {string} id The id attribute. * @property {Array} options The options, including their label and value. - * @property {Object} setting This setting. + * @property {import('./editor').Setting} setting This setting. * @property {string|undefined} value The setting value. */ diff --git a/js/src/edit-block/components/settings/checkbox.js b/js/src/edit-block/components/settings/checkbox.js index be1afdce1..ccc5ea58f 100644 --- a/js/src/edit-block/components/settings/checkbox.js +++ b/js/src/edit-block/components/settings/checkbox.js @@ -6,7 +6,7 @@ import * as React from 'react'; /** * @typedef {Object} CheckboxProps The component props. * @property {Function} handleOnChange Handles a change in this setting. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {boolean|undefined} value The setting value. */ diff --git a/js/src/edit-block/components/settings/email.js b/js/src/edit-block/components/settings/email.js index 6e5d308b2..955e60c36 100644 --- a/js/src/edit-block/components/settings/email.js +++ b/js/src/edit-block/components/settings/email.js @@ -10,7 +10,7 @@ import { Input } from '../'; /** * @typedef {Object} EmailProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change in this setting. */ diff --git a/js/src/edit-block/components/settings/location.js b/js/src/edit-block/components/settings/location.js index 36e2c4dba..c330f22d7 100644 --- a/js/src/edit-block/components/settings/location.js +++ b/js/src/edit-block/components/settings/location.js @@ -11,7 +11,7 @@ import { LOCATIONS_WITH_LABEL, LOCATIONS } from '../../constants'; /** * @typedef {Object} LocationProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change to this setting. * @property {Function} setCurrentLocation Sets the selected location, like 'editor'. diff --git a/js/src/edit-block/components/settings/new-line-format.js b/js/src/edit-block/components/settings/new-line-format.js index bc22c061e..2967fba58 100644 --- a/js/src/edit-block/components/settings/new-line-format.js +++ b/js/src/edit-block/components/settings/new-line-format.js @@ -15,7 +15,7 @@ import { Select } from '../'; /** * @typedef {Object} NewLineFormatProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change to this setting. */ diff --git a/js/src/edit-block/components/settings/number-non-negative.js b/js/src/edit-block/components/settings/number-non-negative.js index 8dfa4a669..5fefce7d5 100644 --- a/js/src/edit-block/components/settings/number-non-negative.js +++ b/js/src/edit-block/components/settings/number-non-negative.js @@ -10,7 +10,7 @@ import { Input } from '../'; /** * @typedef {Object} NumberNonNegativeProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change in this setting. */ diff --git a/js/src/edit-block/components/settings/number.js b/js/src/edit-block/components/settings/number.js index 63251f299..e0a4f31a1 100644 --- a/js/src/edit-block/components/settings/number.js +++ b/js/src/edit-block/components/settings/number.js @@ -10,7 +10,7 @@ import { Input } from '../'; /** * @typedef {Object} NumberProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change in this setting. */ diff --git a/js/src/edit-block/components/settings/text.js b/js/src/edit-block/components/settings/text.js index 6036c6cc2..a1f141335 100644 --- a/js/src/edit-block/components/settings/text.js +++ b/js/src/edit-block/components/settings/text.js @@ -10,7 +10,7 @@ import { Input } from '../'; /** * @typedef {Object} TextProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change in this setting. */ diff --git a/js/src/edit-block/components/settings/textarea-array.js b/js/src/edit-block/components/settings/textarea-array.js index 9eb324f52..a2b0761e7 100644 --- a/js/src/edit-block/components/settings/textarea-array.js +++ b/js/src/edit-block/components/settings/textarea-array.js @@ -3,6 +3,11 @@ */ import * as React from 'react'; +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + /** * Internal dependencies */ @@ -11,7 +16,7 @@ import { convertSettingsStringToArray, convertSettingsArrayToString } from '../. /** * @typedef {Object} TextareaArrayProps The component props. * @property {Function} handleOnChange Handles a change in this setting. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {Array|undefined} value The setting value. */ @@ -25,6 +30,7 @@ const TextareaArray = ( { handleOnChange, setting, value } ) => { const id = `setting-textarea-array-${ setting.name }`; const stringValue = convertSettingsArrayToString( value ); const textAreaValue = undefined === stringValue ? setting.default : stringValue; + const helpClass = 'block italic text-xs mt-1'; return ( <> @@ -40,6 +46,28 @@ const TextareaArray = ( { handleOnChange, setting, value } ) => { } } value={ textAreaValue } /> + { Boolean( setting.help ) + ? ( +

+ { setting.help } +

+ ) : ( + <> +

+ { __( + 'Each choice on a new line. To specify the value and label separately, use this format:', + 'genesis-custom-blocks' + ) } +

+

+ foo : Foo +

+

+ bar : Bar +

+ + ) + } ); }; diff --git a/js/src/edit-block/components/settings/textarea.js b/js/src/edit-block/components/settings/textarea.js index 204f83be5..f95a986cd 100644 --- a/js/src/edit-block/components/settings/textarea.js +++ b/js/src/edit-block/components/settings/textarea.js @@ -6,7 +6,7 @@ import * as React from 'react'; /** * @typedef {Object} TextareaProps The component props. * @property {Function} handleOnChange Handles a change in this setting. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. */ diff --git a/js/src/edit-block/components/settings/width.js b/js/src/edit-block/components/settings/width.js index 955d1b8e2..7035521aa 100644 --- a/js/src/edit-block/components/settings/width.js +++ b/js/src/edit-block/components/settings/width.js @@ -11,7 +11,7 @@ import { __ } from '@wordpress/i18n'; /** * @typedef {Object} WidthProps The component props. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {string|undefined} value The setting value. * @property {Function} handleOnChange Handles a change in this setting. */ diff --git a/js/src/edit-block/helpers/getSettingsComponent.js b/js/src/edit-block/helpers/getSettingsComponent.js index 2f2b2c89e..c5de62363 100644 --- a/js/src/edit-block/helpers/getSettingsComponent.js +++ b/js/src/edit-block/helpers/getSettingsComponent.js @@ -17,7 +17,7 @@ import { snakeCaseToPascalCase } from '../../common/helpers'; /** * @typedef {Object} SettingsComponentProps The component props. * @property {Function} handleOnChange Handles a change in this setting. - * @property {Object} setting This setting. + * @property {import('../editor').Setting} setting This setting. * @property {boolean|undefined} value The setting value. * @property {Function} setCurrentLocation Sets the current location, like 'editor'. */ diff --git a/js/src/edit-block/helpers/getSettingsDefaults.js b/js/src/edit-block/helpers/getSettingsDefaults.js index 32772e890..1bff1f91c 100644 --- a/js/src/edit-block/helpers/getSettingsDefaults.js +++ b/js/src/edit-block/helpers/getSettingsDefaults.js @@ -1,16 +1,3 @@ -/** - * @typedef {Object} Setting A field setting. - * @see PHP class Genesis\CustomBlocks\Blocks\Controls\ControlSetting - * @property {string} name Setting name (slug). - * @property {string} label Setting label. - * @property {string} type Setting type, not a data type like 'object'. - * @property {*} default Setting default value. - * @property {string} help Setting help text for the editor. - * @property {*} sanitize To sanitize the setting value. - * @property {*} validate To validate the value. - * @property {*} value The current value. - */ - /** * Gets the settings defaults for a given control. * @@ -31,7 +18,7 @@ const getSettingsDefaults = ( controlName, controls ) => { return controls[ controlName ].settings.reduce( /** * @param {Object} accumulator The reducer's accumulator. - * @param {Setting} setting The field setting. + * @param {import('../components/editor').Setting} setting The field setting. * @return {Object} Key/value pairs of a setting name to its default value. */ ( accumulator, setting ) => ( { diff --git a/php/Blocks/Controls/Multiselect.php b/php/Blocks/Controls/Multiselect.php index 7a138a28c..7a009a43c 100644 --- a/php/Blocks/Controls/Multiselect.php +++ b/php/Blocks/Controls/Multiselect.php @@ -53,13 +53,7 @@ public function register_settings() { 'label' => __( 'Choices', 'genesis-custom-blocks' ), 'type' => 'textarea_array', 'default' => '', - 'help' => sprintf( - '%s %s
%s
%s', - __( 'Enter each choice on a new line.', 'genesis-custom-blocks' ), - __( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ), - _x( 'foo : Foo', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ), - _x( 'bar : Bar', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ) - ), + 'help' => '', 'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], ] ); @@ -69,7 +63,7 @@ public function register_settings() { 'label' => __( 'Default Value', 'genesis-custom-blocks' ), 'type' => 'textarea_array', 'default' => '', - 'help' => __( 'Enter each default value on a new line.', 'genesis-custom-blocks' ), + 'help' => __( 'Each default value on a new line.', 'genesis-custom-blocks' ), 'sanitize' => [ $this, 'sanitize_textarea_array' ], 'validate' => [ $this, 'validate_options' ], ] diff --git a/php/Blocks/Controls/Radio.php b/php/Blocks/Controls/Radio.php index 9c3203dc9..03e0dc257 100644 --- a/php/Blocks/Controls/Radio.php +++ b/php/Blocks/Controls/Radio.php @@ -46,13 +46,7 @@ public function register_settings() { 'label' => __( 'Choices', 'genesis-custom-blocks' ), 'type' => 'textarea_array', 'default' => '', - 'help' => sprintf( - '%s %s
%s
%s', - __( 'Enter each choice on a new line.', 'genesis-custom-blocks' ), - __( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ), - _x( 'foo : Foo', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ), - _x( 'bar : Bar', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ) - ), + 'help' => '', 'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], ] ); diff --git a/php/Blocks/Controls/Select.php b/php/Blocks/Controls/Select.php index b894dd976..c4069ba89 100644 --- a/php/Blocks/Controls/Select.php +++ b/php/Blocks/Controls/Select.php @@ -46,13 +46,7 @@ public function register_settings() { 'label' => __( 'Choices', 'genesis-custom-blocks' ), 'type' => 'textarea_array', 'default' => '', - 'help' => sprintf( - '%s %s
%s
%s', - __( 'Enter each choice on a new line.', 'genesis-custom-blocks' ), - __( 'To specify the value and label separately, use this format:', 'genesis-custom-blocks' ), - _x( 'foo : Foo', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ), - _x( 'bar : Bar', 'Format for the menu values. option_value : Option Name', 'genesis-custom-blocks' ) - ), + 'help' => '', 'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], ] ); diff --git a/tests/php/Unit/Blocks/Controls/TestMultiselect.php b/tests/php/Unit/Blocks/Controls/TestMultiselect.php index 3ab57a665..1d49ea5d8 100644 --- a/tests/php/Unit/Blocks/Controls/TestMultiselect.php +++ b/tests/php/Unit/Blocks/Controls/TestMultiselect.php @@ -85,7 +85,7 @@ public function test_register_settings() { 'label' => 'Choices', 'type' => 'textarea_array', 'default' => '', - 'help' => 'Enter each choice on a new line. To specify the value and label separately, use this format:
foo : Foo
bar : Bar', + 'help' => '', 'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ], 'validate' => '', 'value' => null, @@ -95,7 +95,7 @@ public function test_register_settings() { 'label' => 'Default Value', 'type' => 'textarea_array', 'default' => '', - 'help' => 'Enter each default value on a new line.', + 'help' => 'Each default value on a new line.', 'sanitize' => [ $this->instance, 'sanitize_textarea_array' ], 'validate' => [ $this->instance, 'validate_options' ], 'value' => null, diff --git a/tests/php/Unit/Blocks/Controls/TestRadio.php b/tests/php/Unit/Blocks/Controls/TestRadio.php index ca90ae0e7..4f04dcb7c 100644 --- a/tests/php/Unit/Blocks/Controls/TestRadio.php +++ b/tests/php/Unit/Blocks/Controls/TestRadio.php @@ -85,7 +85,7 @@ public function test_register_settings() { 'label' => 'Choices', 'type' => 'textarea_array', 'default' => '', - 'help' => 'Enter each choice on a new line. To specify the value and label separately, use this format:
foo : Foo
bar : Bar', + 'help' => '', 'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ], 'validate' => '', 'value' => null, diff --git a/tests/php/Unit/Blocks/Controls/TestSelect.php b/tests/php/Unit/Blocks/Controls/TestSelect.php index 241c482da..d8ab7a07c 100644 --- a/tests/php/Unit/Blocks/Controls/TestSelect.php +++ b/tests/php/Unit/Blocks/Controls/TestSelect.php @@ -85,7 +85,7 @@ public function test_register_settings() { 'label' => 'Choices', 'type' => 'textarea_array', 'default' => '', - 'help' => 'Enter each choice on a new line. To specify the value and label separately, use this format:
foo : Foo
bar : Bar', + 'help' => '', 'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ], 'validate' => '', 'value' => null, From 9176d61b7ed41fa9b688a80c944b2df8e7f6b60f Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Thu, 4 Feb 2021 15:36:54 -0600 Subject: [PATCH 02/21] Let e2e tests run by changing to wp-env It looks like it has to be wp-env in CircleCI. --- .circleci/config.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d47b65fb6..1eb3e604a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -108,7 +108,7 @@ jobs: node-version: lts - nodegit-workaround - set-up-packages - - run: npm run env start && npm run test:e2e + - run: npm run wp-env start && npm run test:e2e svn-deploy: executor: diff --git a/package.json b/package.json index b2167ff08..05d6aa239 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "check-licenses": "wp-scripts check-licenses --prod --gpl2", "build": "wp-scripts build", "dev": "wp-scripts start", - "env": "wp-env", + "wp-env": "wp-env", "gulp": "gulp", "lint": "npm-run-all --parallel lint:*", "lint:css": "wp-scripts lint-style '**/*.scss'", From e0c1fc57b48e03081881f998d54500fe19dc7b01 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Fri, 30 Apr 2021 14:54:37 -0500 Subject: [PATCH 03/21] Remove sanitize and validate values from settings ControlSetting doesn't have a ->sanitize or ->validate property anymore. So no need to pass that. These settings are saved in React, and are not validated. --- php/Blocks/Controls/Multiselect.php | 23 +++++----- php/Blocks/Controls/Radio.php | 11 +++-- php/Blocks/Controls/Select.php | 11 +++-- .../php/Unit/Blocks/Controls/TestCheckbox.php | 42 ++++++++----------- .../Unit/Blocks/Controls/TestMultiselect.php | 28 ++++++------- tests/php/Unit/Blocks/Controls/TestRadio.php | 14 +++---- tests/php/Unit/Blocks/Controls/TestSelect.php | 14 +++---- 7 files changed, 62 insertions(+), 81 deletions(-) diff --git a/php/Blocks/Controls/Multiselect.php b/php/Blocks/Controls/Multiselect.php index 7a009a43c..467e1ffe2 100644 --- a/php/Blocks/Controls/Multiselect.php +++ b/php/Blocks/Controls/Multiselect.php @@ -49,23 +49,20 @@ public function register_settings() { $this->settings[] = new ControlSetting( $this->settings_config['help'] ); $this->settings[] = new ControlSetting( [ - 'name' => 'options', - 'label' => __( 'Choices', 'genesis-custom-blocks' ), - 'type' => 'textarea_array', - 'default' => '', - 'help' => '', - 'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], + 'name' => 'options', + 'label' => __( 'Choices', 'genesis-custom-blocks' ), + 'type' => 'textarea_array', + 'default' => '', + 'help' => '', ] ); $this->settings[] = new ControlSetting( [ - 'name' => 'default', - 'label' => __( 'Default Value', 'genesis-custom-blocks' ), - 'type' => 'textarea_array', - 'default' => '', - 'help' => __( 'Each default value on a new line.', 'genesis-custom-blocks' ), - 'sanitize' => [ $this, 'sanitize_textarea_array' ], - 'validate' => [ $this, 'validate_options' ], + 'name' => 'default', + 'label' => __( 'Default Value', 'genesis-custom-blocks' ), + 'type' => 'textarea_array', + 'default' => '', + 'help' => __( 'Each default value on a new line.', 'genesis-custom-blocks' ), ] ); } diff --git a/php/Blocks/Controls/Radio.php b/php/Blocks/Controls/Radio.php index 4cb51430d..17dac9349 100644 --- a/php/Blocks/Controls/Radio.php +++ b/php/Blocks/Controls/Radio.php @@ -42,12 +42,11 @@ public function register_settings() { $this->settings[] = new ControlSetting( $this->settings_config['help'] ); $this->settings[] = new ControlSetting( [ - 'name' => 'options', - 'label' => __( 'Choices', 'genesis-custom-blocks' ), - 'type' => 'textarea_array', - 'default' => '', - 'help' => '', - 'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], + 'name' => 'options', + 'label' => __( 'Choices', 'genesis-custom-blocks' ), + 'type' => 'textarea_array', + 'default' => '', + 'help' => '', ] ); $this->settings[] = new ControlSetting( diff --git a/php/Blocks/Controls/Select.php b/php/Blocks/Controls/Select.php index 39e9ab5a9..3b101615b 100644 --- a/php/Blocks/Controls/Select.php +++ b/php/Blocks/Controls/Select.php @@ -42,12 +42,11 @@ public function register_settings() { $this->settings[] = new ControlSetting( $this->settings_config['help'] ); $this->settings[] = new ControlSetting( [ - 'name' => 'options', - 'label' => __( 'Choices', 'genesis-custom-blocks' ), - 'type' => 'textarea_array', - 'default' => '', - 'help' => '', - 'sanitize' => [ $this, 'sanitize_textarea_assoc_array' ], + 'name' => 'options', + 'label' => __( 'Choices', 'genesis-custom-blocks' ), + 'type' => 'textarea_array', + 'default' => '', + 'help' => '', ] ); $this->settings[] = new ControlSetting( diff --git a/tests/php/Unit/Blocks/Controls/TestCheckbox.php b/tests/php/Unit/Blocks/Controls/TestCheckbox.php index 7f476e135..8d17bb3f6 100644 --- a/tests/php/Unit/Blocks/Controls/TestCheckbox.php +++ b/tests/php/Unit/Blocks/Controls/TestCheckbox.php @@ -52,34 +52,28 @@ public function test_construct() { public function test_register_settings() { $expected_settings = [ [ - 'name' => 'location', - 'label' => 'Field Location', - 'type' => 'location', - 'default' => 'editor', - 'help' => '', - 'sanitize' => [ $this->instance, 'sanitize_location' ], - 'validate' => '', - 'value' => null, + 'name' => 'location', + 'label' => 'Field Location', + 'type' => 'location', + 'default' => 'editor', + 'help' => '', + 'value' => null, ], [ - 'name' => 'width', - 'label' => 'Field Width', - 'type' => 'width', - 'default' => '100', - 'help' => '', - 'sanitize' => 'sanitize_text_field', - 'validate' => '', - 'value' => null, + 'name' => 'width', + 'label' => 'Field Width', + 'type' => 'width', + 'default' => '100', + 'help' => '', + 'value' => null, ], [ - 'name' => 'help', - 'label' => 'Help Text', - 'type' => 'text', - 'default' => '', - 'help' => '', - 'sanitize' => 'sanitize_text_field', - 'validate' => '', - 'value' => null, + 'name' => 'help', + 'label' => 'Help Text', + 'type' => 'text', + 'default' => '', + 'help' => '', + 'value' => null, ], [ 'name' => 'default', diff --git a/tests/php/Unit/Blocks/Controls/TestMultiselect.php b/tests/php/Unit/Blocks/Controls/TestMultiselect.php index 11f2b843b..32cc31f43 100644 --- a/tests/php/Unit/Blocks/Controls/TestMultiselect.php +++ b/tests/php/Unit/Blocks/Controls/TestMultiselect.php @@ -75,24 +75,20 @@ public function test_register_settings() { 'value' => null, ], [ - 'name' => 'options', - 'label' => 'Choices', - 'type' => 'textarea_array', - 'default' => '', - 'help' => '', - 'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ], - 'validate' => '', - 'value' => null, + 'name' => 'options', + 'label' => 'Choices', + 'type' => 'textarea_array', + 'default' => '', + 'help' => '', + 'value' => null, ], [ - 'name' => 'default', - 'label' => 'Default Value', - 'type' => 'textarea_array', - 'default' => '', - 'help' => 'Each default value on a new line.', - 'sanitize' => [ $this->instance, 'sanitize_textarea_array' ], - 'validate' => [ $this->instance, 'validate_options' ], - 'value' => null, + 'name' => 'default', + 'label' => 'Default Value', + 'type' => 'textarea_array', + 'default' => '', + 'help' => 'Each default value on a new line.', + 'value' => null, ], ]; $this->assert_correct_settings( $expected_settings, $this->instance->settings ); diff --git a/tests/php/Unit/Blocks/Controls/TestRadio.php b/tests/php/Unit/Blocks/Controls/TestRadio.php index ffcc925f8..0f3c0f86b 100644 --- a/tests/php/Unit/Blocks/Controls/TestRadio.php +++ b/tests/php/Unit/Blocks/Controls/TestRadio.php @@ -75,14 +75,12 @@ public function test_register_settings() { 'value' => null, ], [ - 'name' => 'options', - 'label' => 'Choices', - 'type' => 'textarea_array', - 'default' => '', - 'help' => '', - 'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ], - 'validate' => '', - 'value' => null, + 'name' => 'options', + 'label' => 'Choices', + 'type' => 'textarea_array', + 'default' => '', + 'help' => '', + 'value' => null, ], [ 'name' => 'default', diff --git a/tests/php/Unit/Blocks/Controls/TestSelect.php b/tests/php/Unit/Blocks/Controls/TestSelect.php index 9d33d6aca..ff64fc3fb 100644 --- a/tests/php/Unit/Blocks/Controls/TestSelect.php +++ b/tests/php/Unit/Blocks/Controls/TestSelect.php @@ -75,14 +75,12 @@ public function test_register_settings() { 'value' => null, ], [ - 'name' => 'options', - 'label' => 'Choices', - 'type' => 'textarea_array', - 'default' => '', - 'help' => '', - 'sanitize' => [ $this->instance, 'sanitize_textarea_assoc_array' ], - 'validate' => '', - 'value' => null, + 'name' => 'options', + 'label' => 'Choices', + 'type' => 'textarea_array', + 'default' => '', + 'help' => '', + 'value' => null, ], [ 'name' => 'default', From 4af23d443d1fb531d523059629104180758747bf Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Sun, 2 May 2021 23:59:37 -0500 Subject: [PATCH 04/21] If a field is deleted, also delete it from the previewAttributes If the field no longer exists, there's no need to add it to the block's attributes. --- js/src/edit-block/hooks/useField.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/js/src/edit-block/hooks/useField.js b/js/src/edit-block/hooks/useField.js index 19f9b990f..dd6537302 100644 --- a/js/src/edit-block/hooks/useField.js +++ b/js/src/edit-block/hooks/useField.js @@ -320,6 +320,7 @@ const useField = () => { */ const deleteField = ( selectedField ) => { const newBlock = { ...block }; + if ( selectedField.hasOwnProperty( 'parent' ) && newBlock.fields[ selectedField.parent ] && @@ -328,6 +329,7 @@ const useField = () => { delete newBlock.fields[ selectedField.parent ].sub_fields[ selectedField.name ]; } else { delete newBlock.fields[ selectedField.name ]; + delete newBlock?.previewAttributes[ selectedField.name ]; } editBlock( newBlock ); From a344c514e1d1094676859f5744ad64cbd3b5fa05 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 14:20:37 -0500 Subject: [PATCH 05/21] See if upgrading server-side-render is possible There's a new package that was just released 3 days ago. --- package-lock.json | 522 ++++++++++++++++++++++++++++++++++++++++------ package.json | 2 +- 2 files changed, 459 insertions(+), 65 deletions(-) diff --git a/package-lock.json b/package-lock.json index 843f6eeb7..617c1435d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7156,104 +7156,498 @@ } }, "@wordpress/server-side-render": { - "version": "1.19.5", - "resolved": "https://registry.npmjs.org/@wordpress/server-side-render/-/server-side-render-1.19.5.tgz", - "integrity": "sha512-dqGgD1Sva+qKAQ7YcbDO4Y/vE4N0gVJOxo4cvCOG880I9geiTF9fzOUG3KToZM19H3Ct4UC+Cv3ARFVdQZZk3A==", - "dev": true, - "requires": { - "@babel/runtime": "^7.11.2", - "@wordpress/api-fetch": "^3.20.0", - "@wordpress/components": "^11.1.5", - "@wordpress/data": "^4.25.0", - "@wordpress/deprecated": "^2.10.0", - "@wordpress/element": "^2.18.0", - "@wordpress/i18n": "^3.16.0", - "@wordpress/url": "^2.19.0", + "version": "1.21.3", + "resolved": "https://registry.npmjs.org/@wordpress/server-side-render/-/server-side-render-1.21.3.tgz", + "integrity": "sha512-pS2+LmTQX8S61TvaC+UyXqmFnQSXcJ3wcr3RPX1EwmpvlMuXlqdW8N5Y1TWuOT1G/ZDAwvTilLAlxeAMqrYSXA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/api-fetch": "^4.0.0", + "@wordpress/blocks": "^8.0.3", + "@wordpress/components": "^13.0.3", + "@wordpress/compose": "^3.25.3", + "@wordpress/data": "^4.27.3", + "@wordpress/deprecated": "^2.12.3", + "@wordpress/element": "^2.20.3", + "@wordpress/i18n": "^3.20.0", + "@wordpress/url": "^2.22.2", "lodash": "^4.17.19" }, "dependencies": { + "@types/react": { + "version": "16.14.5", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.5.tgz", + "integrity": "sha512-YRRv9DNZhaVTVRh9Wmmit7Y0UFhEVqXqCSw3uazRWMxa2x85hWQZ5BN24i7GXZbaclaLXEcodEeIHsjBA8eAMw==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@wordpress/a11y": { + "version": "2.15.3", + "resolved": "https://registry.npmjs.org/@wordpress/a11y/-/a11y-2.15.3.tgz", + "integrity": "sha512-uoCznHY3/TaNWeXutLI6juC198ykaBwZ34P51PNHHQqi3WzVoBhFx6AnAR/9Uupl3tZcekefpkVHy7AJHMAPIA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/dom-ready": "^2.13.2", + "@wordpress/i18n": "^3.20.0" + } + }, + "@wordpress/api-fetch": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-4.0.0.tgz", + "integrity": "sha512-4nWH/gEpG7/VnEJbjbOWS0AWBnX5snPc3ZaKcXNZsLQlv9YgsS8idL/BNkUl9/ylZeez/UX4lJLVkOR5clvg8A==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/i18n": "^3.20.0", + "@wordpress/url": "^2.22.2" + } + }, + "@wordpress/autop": { + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/@wordpress/autop/-/autop-2.12.2.tgz", + "integrity": "sha512-c3taxJCmf1Bib33GPm7ihrgFvuzKHycdyE+XWnpa9G3JgZUJTpssFSC5rC3VZ3u+QD8agStBtlOBOyxj6pjQSA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/blob": { + "version": "2.13.2", + "resolved": "https://registry.npmjs.org/@wordpress/blob/-/blob-2.13.2.tgz", + "integrity": "sha512-Us71BMrvjiMjW9WTV1UzZbEBd+Q7W05P0WW+Tfo6qHJLBMYXPDN9dP9s6JhK6fzzL+U/PzotMJwA6P85BqL30w==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/block-serialization-default-parser": { + "version": "3.10.2", + "resolved": "https://registry.npmjs.org/@wordpress/block-serialization-default-parser/-/block-serialization-default-parser-3.10.2.tgz", + "integrity": "sha512-0vyHHTcEw3ijY+stJqCf0iVR4bHpb84dbTZVaT2VSzISGzeVuAJpcYhIJMHvDTMcX1E2pgAfanIL8xloS6W7gQ==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/blocks": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/@wordpress/blocks/-/blocks-8.0.3.tgz", + "integrity": "sha512-/zXk5gEI/TCzsVSUIht5cmO+pFC6u3mpNV8ye0Cy4CEQVtauW969GvgEM+LVf8Mk8R5NcLdLPE88n8xxsFaRoQ==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/autop": "^2.12.2", + "@wordpress/blob": "^2.13.2", + "@wordpress/block-serialization-default-parser": "^3.10.2", + "@wordpress/compose": "^3.25.3", + "@wordpress/data": "^4.27.3", + "@wordpress/deprecated": "^2.12.3", + "@wordpress/dom": "^2.18.0", + "@wordpress/element": "^2.20.3", + "@wordpress/hooks": "^2.12.3", + "@wordpress/html-entities": "^2.11.2", + "@wordpress/i18n": "^3.20.0", + "@wordpress/icons": "^2.10.3", + "@wordpress/is-shallow-equal": "^3.1.3", + "@wordpress/shortcode": "^2.13.2", + "hpq": "^1.3.0", + "lodash": "^4.17.19", + "rememo": "^3.0.0", + "showdown": "^1.9.1", + "simple-html-tokenizer": "^0.5.7", + "tinycolor2": "^1.4.2", + "uuid": "^8.3.0" + } + }, "@wordpress/components": { - "version": "11.1.5", - "resolved": "https://registry.npmjs.org/@wordpress/components/-/components-11.1.5.tgz", - "integrity": "sha512-XOVD4HgqvizuqMtY1XzppNiw2ET2VefGtdclewb3sB/eBxkNtqb2hl9mHBG547Au0QZnsOylK9AOAZI0eYhMOw==", + "version": "13.0.3", + "resolved": "https://registry.npmjs.org/@wordpress/components/-/components-13.0.3.tgz", + "integrity": "sha512-L5cCeZvhFsLlGVxuAIFwqZotLqrwrisFjikd6a0Aj8jlTZrb9vNQ4mDXU1Zz2toHCH3NegIUAHMHOs3Jf46tWg==", "dev": true, "requires": { - "@babel/runtime": "^7.11.2", - "@emotion/core": "^10.0.22", + "@babel/runtime": "^7.13.10", + "@emotion/cache": "^10.0.27", + "@emotion/core": "^10.1.1", "@emotion/css": "^10.0.22", + "@emotion/hash": "^0.8.0", "@emotion/native": "^10.0.22", "@emotion/styled": "^10.0.23", - "@wordpress/a11y": "^2.13.0", - "@wordpress/compose": "^3.22.0", - "@wordpress/date": "^3.12.0", - "@wordpress/deprecated": "^2.10.0", - "@wordpress/dom": "^2.15.0", - "@wordpress/element": "^2.18.0", - "@wordpress/hooks": "^2.10.0", - "@wordpress/i18n": "^3.16.0", - "@wordpress/icons": "^2.8.0", - "@wordpress/is-shallow-equal": "^2.3.0", - "@wordpress/keycodes": "^2.16.0", - "@wordpress/primitives": "^1.10.0", - "@wordpress/rich-text": "^3.23.0", - "@wordpress/warning": "^1.3.0", + "@wordpress/a11y": "^2.15.3", + "@wordpress/compose": "^3.25.3", + "@wordpress/date": "^3.15.1", + "@wordpress/deprecated": "^2.12.3", + "@wordpress/dom": "^2.18.0", + "@wordpress/element": "^2.20.3", + "@wordpress/hooks": "^2.12.3", + "@wordpress/i18n": "^3.20.0", + "@wordpress/icons": "^2.10.3", + "@wordpress/is-shallow-equal": "^3.1.3", + "@wordpress/keycodes": "^2.19.3", + "@wordpress/primitives": "^1.12.3", + "@wordpress/rich-text": "^3.25.3", + "@wordpress/warning": "^1.4.2", + "@wp-g2/components": "^0.0.160", + "@wp-g2/context": "^0.0.160", + "@wp-g2/styles": "^0.0.160", + "@wp-g2/utils": "^0.0.160", "classnames": "^2.2.5", "dom-scroll-into-view": "^1.2.1", - "downshift": "^5.4.0", + "downshift": "^6.0.15", "gradient-parser": "^0.1.5", + "highlight-words-core": "^1.2.2", "lodash": "^4.17.19", "memize": "^1.1.0", "moment": "^2.22.1", "re-resizable": "^6.4.0", "react-dates": "^17.1.1", - "react-merge-refs": "^1.0.0", - "react-resize-aware": "^3.0.1", + "react-resize-aware": "^3.1.0", "react-spring": "^8.0.20", - "react-use-gesture": "^7.0.15", - "reakit": "^1.1.0", + "react-use-gesture": "^9.0.0", + "reakit": "^1.3.5", "rememo": "^3.0.0", - "tinycolor2": "^1.4.1", - "uuid": "^7.0.2" + "tinycolor2": "^1.4.2", + "uuid": "^8.3.0" + } + }, + "@wordpress/compose": { + "version": "3.25.3", + "resolved": "https://registry.npmjs.org/@wordpress/compose/-/compose-3.25.3.tgz", + "integrity": "sha512-tCO2EnJCkCH548OqA0uU8V1k/1skz2QwBlHs8ZQSpimqUS4OWWsAlndCEFe4U4vDTqFt2ow7tzAir+05Cw8MAg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/deprecated": "^2.12.3", + "@wordpress/dom": "^2.18.0", + "@wordpress/element": "^2.20.3", + "@wordpress/is-shallow-equal": "^3.1.3", + "@wordpress/keycodes": "^2.19.3", + "@wordpress/priority-queue": "^1.11.2", + "clipboard": "^2.0.1", + "lodash": "^4.17.19", + "memize": "^1.1.0", + "mousetrap": "^1.6.5", + "react-resize-aware": "^3.1.0", + "use-memo-one": "^1.1.1" + } + }, + "@wordpress/data": { + "version": "4.27.3", + "resolved": "https://registry.npmjs.org/@wordpress/data/-/data-4.27.3.tgz", + "integrity": "sha512-5763NgNV9IIa1CC3Q80dAvrH6108tJtj3IrHfUCZmUk1atSNsOMBCkLdQ7tGTTi2JFejeGEMg1LJI22JD5zM6Q==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/compose": "^3.25.3", + "@wordpress/deprecated": "^2.12.3", + "@wordpress/element": "^2.20.3", + "@wordpress/is-shallow-equal": "^3.1.3", + "@wordpress/priority-queue": "^1.11.2", + "@wordpress/redux-routine": "^3.14.2", + "equivalent-key-map": "^0.2.2", + "is-promise": "^4.0.0", + "lodash": "^4.17.19", + "memize": "^1.1.0", + "redux": "^4.0.0", + "turbo-combine-reducers": "^1.0.2", + "use-memo-one": "^1.1.1" + } + }, + "@wordpress/date": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/@wordpress/date/-/date-3.15.1.tgz", + "integrity": "sha512-SuHiObvjbegL8RpaSQ6JqFnG+QyGP+oUhx1FZDMdt1nOQA9HE7D5ssVlZFlMEAdo6iS8xMuW+4SgJN3Eo1fb4w==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "moment": "^2.22.1", + "moment-timezone": "^0.5.31" + } + }, + "@wordpress/deprecated": { + "version": "2.12.3", + "resolved": "https://registry.npmjs.org/@wordpress/deprecated/-/deprecated-2.12.3.tgz", + "integrity": "sha512-qr+yDfTQfI3M4h6oY6IeHWwoHr4jxbILjSlV+Ht6Jjto9Owap6OuzSqR13Ev4xqIoG4C7b5B3gZXVfwVDae1zg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/hooks": "^2.12.3" + } + }, + "@wordpress/dom": { + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/@wordpress/dom/-/dom-2.18.0.tgz", + "integrity": "sha512-tM2WeQuSObl3nzWjUTF0/dyLnA7sdl/MXaSe32D64OF89bjSyJvjUipI7gjKzI3kJ7ddGhwcTggGvSB06MOoCQ==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "lodash": "^4.17.19" + } + }, + "@wordpress/dom-ready": { + "version": "2.13.2", + "resolved": "https://registry.npmjs.org/@wordpress/dom-ready/-/dom-ready-2.13.2.tgz", + "integrity": "sha512-COH7n2uZfBq4FtluSbl37N3nCEcdMXzV42ETCWKUcumiP1Zd3qnkfQKcsxTaHWY8aVt/358RvJ7ghWe3xAd+fg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/element": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-2.20.3.tgz", + "integrity": "sha512-f4ZPTDf9CxiiOXiMxc4v1K7jcBMT4dsiehVOpkKzCDKboNXp4qVf8oe5PE23VGZNEjcOj5Mkg9hB57R0nqvMTw==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@types/react": "^16.9.0", + "@types/react-dom": "^16.9.0", + "@wordpress/escape-html": "^1.12.2", + "lodash": "^4.17.19", + "react": "^16.13.1", + "react-dom": "^16.13.1" + } + }, + "@wordpress/escape-html": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-1.12.2.tgz", + "integrity": "sha512-FabgSwznhdaUwe6hr1CsGpgxQbzqEoGevv73WIL1B9GvlZ6csRWodgHfWh4P6fYqpzxFL4WYB8wPJ1PdO32XFA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/hooks": { + "version": "2.12.3", + "resolved": "https://registry.npmjs.org/@wordpress/hooks/-/hooks-2.12.3.tgz", + "integrity": "sha512-LmKiwKldZt6UYqOxV/a6+eUFXdvALFnB/pQx3RmrMvO64sgFhfR6dhrlv+uVbuuezSuv8dce1jx8lUWAT0krMA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/html-entities": { + "version": "2.11.2", + "resolved": "https://registry.npmjs.org/@wordpress/html-entities/-/html-entities-2.11.2.tgz", + "integrity": "sha512-WIdEGO9/o7tuTV3jpLHhFC/NBBnNdJeG9nRZbEyb37CL1fvqJA85hTugyDOhGzOVIAtpFTc6kr/gMJK1oTdopw==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/i18n": { + "version": "3.20.0", + "resolved": "https://registry.npmjs.org/@wordpress/i18n/-/i18n-3.20.0.tgz", + "integrity": "sha512-SIoOJFB4UrrYAScS4H91CYCLW9dX3Ghv8pBKc/yHGculb1AdGr6gRMlmJxZV62Cn3CZ4Ga86c+FfR+GiBu0JPg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/hooks": "^2.12.3", + "gettext-parser": "^1.3.1", + "lodash": "^4.17.19", + "memize": "^1.1.0", + "sprintf-js": "^1.1.1", + "tannin": "^1.2.0" + } + }, + "@wordpress/icons": { + "version": "2.10.3", + "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-2.10.3.tgz", + "integrity": "sha512-hVXArGOHLE5pL1G3rHNzsUEuTR4/G6lB+enKYwhYSSIqWuSbyXbZq3nvibxpepPrLy9B3d5t6aR6QUmjMVzIcQ==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/element": "^2.20.3", + "@wordpress/primitives": "^1.12.3" } }, "@wordpress/is-shallow-equal": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@wordpress/is-shallow-equal/-/is-shallow-equal-2.3.0.tgz", - "integrity": "sha512-BUVCYZNDoT5fRJGoam/nI2Sn8QELu5z/pFe7UL+szFqQqNnMibdWqN/KoW/YO7WLJqqqTRhAs/Fa51g4oXRyHQ==", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@wordpress/is-shallow-equal/-/is-shallow-equal-3.1.3.tgz", + "integrity": "sha512-eDLhfC4aaSgklzqwc6F/F4zmJVpTVTAvhqX+q0SP/8LPcP2HuKErPHVrEc75PMWqIutja2wJg98YSNPdewrj1w==", "dev": true, "requires": { - "@babel/runtime": "^7.11.2" + "@babel/runtime": "^7.13.10" } }, - "downshift": { - "version": "5.4.7", - "resolved": "https://registry.npmjs.org/downshift/-/downshift-5.4.7.tgz", - "integrity": "sha512-xaH0RNqwJ5pAsyk9qBmR9XJWmg1OOWMfrhzYv0NH2NjJxn77S3zBcfClw341UfhGyKg5v+qVqg/CQzvAgBNCXQ==", + "@wordpress/keycodes": { + "version": "2.19.3", + "resolved": "https://registry.npmjs.org/@wordpress/keycodes/-/keycodes-2.19.3.tgz", + "integrity": "sha512-8rNdmP5M1ifTgLIL0dt/N1uTGsq/Rx1ydCXy+gg24WdxBRhyu5sudNVCtascVXo26aIfOH9OJRdqRZZTEORhog==", "dev": true, "requires": { - "@babel/runtime": "^7.10.2", - "compute-scroll-into-view": "^1.0.14", - "prop-types": "^15.7.2", - "react-is": "^16.13.1" + "@babel/runtime": "^7.13.10", + "@wordpress/i18n": "^3.20.0", + "lodash": "^4.17.19" } }, - "react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "dev": true + "@wordpress/primitives": { + "version": "1.12.3", + "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-1.12.3.tgz", + "integrity": "sha512-LIF44bVlJS7CJEVmk6TLuV6HZMdj5iwkyM8do4ukGY6qnZIzrXpBablgJeDBcyjzWrWRLn+w+tiZ/8l+2egoVA==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/element": "^2.20.3", + "classnames": "^2.2.5" + } + }, + "@wordpress/priority-queue": { + "version": "1.11.2", + "resolved": "https://registry.npmjs.org/@wordpress/priority-queue/-/priority-queue-1.11.2.tgz", + "integrity": "sha512-ulwmUOklY3orn1xXpcPnTyGWV5B/oycxI+cHZ6EevBVgM5sq+BW3xo0PKLR/MMm6UNBtFTu/71QAJrNZcD6V1g==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10" + } + }, + "@wordpress/redux-routine": { + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/@wordpress/redux-routine/-/redux-routine-3.14.2.tgz", + "integrity": "sha512-aqi4UtvMP/+NhULxyCR8ktG0v4BJVTRcMpByAqDg7Oabq2sz2LPuShxd5UY8vxQYQY9t1uUJbslhom4ytcohWg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "is-promise": "^4.0.0", + "lodash": "^4.17.19", + "rungen": "^0.3.2" + } + }, + "@wordpress/rich-text": { + "version": "3.25.3", + "resolved": "https://registry.npmjs.org/@wordpress/rich-text/-/rich-text-3.25.3.tgz", + "integrity": "sha512-FdqL1/rHTsRxZ1gW1UEWuy0URmUEqMzj5hcAbOhHFPO5m0ENrkzC9bBa195KqZBSNSmBmXnDZdHu4UJUolzcZg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "@wordpress/compose": "^3.25.3", + "@wordpress/data": "^4.27.3", + "@wordpress/dom": "^2.18.0", + "@wordpress/element": "^2.20.3", + "@wordpress/escape-html": "^1.12.2", + "@wordpress/is-shallow-equal": "^3.1.3", + "@wordpress/keycodes": "^2.19.3", + "classnames": "^2.2.5", + "lodash": "^4.17.19", + "memize": "^1.1.0", + "rememo": "^3.0.0" + } + }, + "@wordpress/shortcode": { + "version": "2.13.2", + "resolved": "https://registry.npmjs.org/@wordpress/shortcode/-/shortcode-2.13.2.tgz", + "integrity": "sha512-n4O5O66ARGY+h1SCvt0uOIQAJ6B4hd6EjULAWRNYgQuuF9mdhcczpGvSH76BssuvLN6bJU1RjsVy7m56kqO5xw==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "lodash": "^4.17.19", + "memize": "^1.1.0" + } }, - "react-use-gesture": { - "version": "7.0.16", - "resolved": "https://registry.npmjs.org/react-use-gesture/-/react-use-gesture-7.0.16.tgz", - "integrity": "sha512-gwgX+E+WQG0T1uFVl3z8j3ZwH3QQGIgVl7VtQEC2m0IscSs668sSps4Ss3CFp3Vns8xx0j9TVK4aBXH6+YrpEg==", + "@wordpress/url": { + "version": "2.22.2", + "resolved": "https://registry.npmjs.org/@wordpress/url/-/url-2.22.2.tgz", + "integrity": "sha512-aqpYKQXzyzkCOm+GzZRYlLb+wh58g0cwR1PaKAl0UXaBS4mdS+X6biMriylb4P8CVC/RR7CSw5XI20JC24KDwQ==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "lodash": "^4.17.19", + "react-native-url-polyfill": "^1.1.2" + } + }, + "@wordpress/warning": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@wordpress/warning/-/warning-1.4.2.tgz", + "integrity": "sha512-MjrkSp6Jyfx+92AE32A83P503noUtGb6//BYUH4GiWzzzSNhDHgbQ0UcOJwJaEYK166DxSNpMk/JXc4YENi1Cw==", "dev": true }, - "uuid": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", - "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==", + "@wp-g2/components": { + "version": "0.0.160", + "resolved": "https://registry.npmjs.org/@wp-g2/components/-/components-0.0.160.tgz", + "integrity": "sha512-44qUtiF5Nl/srD7Vzbpcd0im/EIej04fOdDfa0lfDxXJDNK3RRtSSEwCRhok/M5SKCmvYbZKRUx2K0ugXNqK0Q==", + "dev": true, + "requires": { + "@popperjs/core": "^2.5.4", + "@wp-g2/context": "^0.0.160", + "@wp-g2/styles": "^0.0.160", + "@wp-g2/utils": "^0.0.160", + "csstype": "^3.0.3", + "downshift": "^6.0.15", + "framer-motion": "^2.1.0", + "highlight-words-core": "^1.2.2", + "history": "^4.9.0", + "lodash": "^4.17.19", + "path-to-regexp": "^1.7.0", + "react-colorful": "4.4.4", + "react-textarea-autosize": "^8.2.0", + "react-use-gesture": "^9.0.0", + "reakit": "^1.3.4" + } + }, + "@wp-g2/context": { + "version": "0.0.160", + "resolved": "https://registry.npmjs.org/@wp-g2/context/-/context-0.0.160.tgz", + "integrity": "sha512-50wSQCZkdZEexP88Ljutskn7/klT2Id1ks4GpzKDSBM8kadrfNdr2iabjgJdFLIH33S+r4dzEnzLs9SFtqUgwg==", + "dev": true, + "requires": { + "@wp-g2/create-styles": "^0.0.160", + "@wp-g2/styles": "^0.0.160", + "@wp-g2/utils": "^0.0.160", + "lodash": "^4.17.19" + } + }, + "@wp-g2/styles": { + "version": "0.0.160", + "resolved": "https://registry.npmjs.org/@wp-g2/styles/-/styles-0.0.160.tgz", + "integrity": "sha512-o91jxb0ZwEDRJrtVVjnqn3qTAXjnxZ1fX5KF3Q7oz776lMZPHsyfC0hvqnOz0w7zqaZZpdWtVQRShgrYXN6JHw==", + "dev": true, + "requires": { + "@wp-g2/create-styles": "^0.0.160", + "@wp-g2/utils": "^0.0.160" + } + }, + "@wp-g2/utils": { + "version": "0.0.160", + "resolved": "https://registry.npmjs.org/@wp-g2/utils/-/utils-0.0.160.tgz", + "integrity": "sha512-4FhezjKyeYVb+3PZahW1kmqXpCvVvuJM97EcGqkKf+u4Qf66J3n1niHgfnRbn8aNydYK6EFze+6/UL48U35z1w==", + "dev": true, + "requires": { + "copy-to-clipboard": "^3.3.1", + "create-emotion": "^10.0.27", + "deepmerge": "^4.2.2", + "fast-deep-equal": "^3.1.3", + "hoist-non-react-statics": "^3.3.2", + "json2mq": "^0.2.0", + "lodash": "^4.17.19", + "memize": "^1.1.0", + "react-merge-refs": "^1.1.0", + "react-resize-aware": "^3.1.0", + "tinycolor2": "^1.4.2", + "use-enhanced-state": "^0.0.13", + "use-isomorphic-layout-effect": "^1.0.0" + } + }, + "csstype": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.8.tgz", + "integrity": "sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==", "dev": true + }, + "downshift": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/downshift/-/downshift-6.1.3.tgz", + "integrity": "sha512-RA1MuaNcTbt0j+sVLhSs8R2oZbBXYAtdQP/V+uHhT3DoDteZzJPjlC+LQVm9T07Wpvo84QXaZtUCePLDTDwGXg==", + "dev": true, + "requires": { + "@babel/runtime": "^7.13.10", + "compute-scroll-into-view": "^1.0.17", + "prop-types": "^15.7.2", + "react-is": "^17.0.2" + } } } }, diff --git a/package.json b/package.json index 7f7796edd..829285afb 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@wordpress/notices": "2.13.0", "@wordpress/postcss-plugins-preset": "2.1.0", "@wordpress/scripts": "14.1.0", - "@wordpress/server-side-render": "1.19.5", + "@wordpress/server-side-render": "1.21.3", "@wordpress/url": "2.22.0", "ace-builds": "1.4.12", "autoprefixer": "10.1.0", From 5e84929aacfd09ccd9ec8fcac22cf90ab7e71207 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 14:31:07 -0500 Subject: [PATCH 06/21] Revert "See if upgrading server-side-render is possible" This reverts commit a344c514e1d1094676859f5744ad64cbd3b5fa05. --- package-lock.json | 522 ++++++---------------------------------------- package.json | 2 +- 2 files changed, 65 insertions(+), 459 deletions(-) diff --git a/package-lock.json b/package-lock.json index 617c1435d..843f6eeb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7156,498 +7156,104 @@ } }, "@wordpress/server-side-render": { - "version": "1.21.3", - "resolved": "https://registry.npmjs.org/@wordpress/server-side-render/-/server-side-render-1.21.3.tgz", - "integrity": "sha512-pS2+LmTQX8S61TvaC+UyXqmFnQSXcJ3wcr3RPX1EwmpvlMuXlqdW8N5Y1TWuOT1G/ZDAwvTilLAlxeAMqrYSXA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/api-fetch": "^4.0.0", - "@wordpress/blocks": "^8.0.3", - "@wordpress/components": "^13.0.3", - "@wordpress/compose": "^3.25.3", - "@wordpress/data": "^4.27.3", - "@wordpress/deprecated": "^2.12.3", - "@wordpress/element": "^2.20.3", - "@wordpress/i18n": "^3.20.0", - "@wordpress/url": "^2.22.2", + "version": "1.19.5", + "resolved": "https://registry.npmjs.org/@wordpress/server-side-render/-/server-side-render-1.19.5.tgz", + "integrity": "sha512-dqGgD1Sva+qKAQ7YcbDO4Y/vE4N0gVJOxo4cvCOG880I9geiTF9fzOUG3KToZM19H3Ct4UC+Cv3ARFVdQZZk3A==", + "dev": true, + "requires": { + "@babel/runtime": "^7.11.2", + "@wordpress/api-fetch": "^3.20.0", + "@wordpress/components": "^11.1.5", + "@wordpress/data": "^4.25.0", + "@wordpress/deprecated": "^2.10.0", + "@wordpress/element": "^2.18.0", + "@wordpress/i18n": "^3.16.0", + "@wordpress/url": "^2.19.0", "lodash": "^4.17.19" }, "dependencies": { - "@types/react": { - "version": "16.14.5", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.5.tgz", - "integrity": "sha512-YRRv9DNZhaVTVRh9Wmmit7Y0UFhEVqXqCSw3uazRWMxa2x85hWQZ5BN24i7GXZbaclaLXEcodEeIHsjBA8eAMw==", - "dev": true, - "requires": { - "@types/prop-types": "*", - "@types/scheduler": "*", - "csstype": "^3.0.2" - } - }, - "@wordpress/a11y": { - "version": "2.15.3", - "resolved": "https://registry.npmjs.org/@wordpress/a11y/-/a11y-2.15.3.tgz", - "integrity": "sha512-uoCznHY3/TaNWeXutLI6juC198ykaBwZ34P51PNHHQqi3WzVoBhFx6AnAR/9Uupl3tZcekefpkVHy7AJHMAPIA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/dom-ready": "^2.13.2", - "@wordpress/i18n": "^3.20.0" - } - }, - "@wordpress/api-fetch": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@wordpress/api-fetch/-/api-fetch-4.0.0.tgz", - "integrity": "sha512-4nWH/gEpG7/VnEJbjbOWS0AWBnX5snPc3ZaKcXNZsLQlv9YgsS8idL/BNkUl9/ylZeez/UX4lJLVkOR5clvg8A==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/i18n": "^3.20.0", - "@wordpress/url": "^2.22.2" - } - }, - "@wordpress/autop": { - "version": "2.12.2", - "resolved": "https://registry.npmjs.org/@wordpress/autop/-/autop-2.12.2.tgz", - "integrity": "sha512-c3taxJCmf1Bib33GPm7ihrgFvuzKHycdyE+XWnpa9G3JgZUJTpssFSC5rC3VZ3u+QD8agStBtlOBOyxj6pjQSA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/blob": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/@wordpress/blob/-/blob-2.13.2.tgz", - "integrity": "sha512-Us71BMrvjiMjW9WTV1UzZbEBd+Q7W05P0WW+Tfo6qHJLBMYXPDN9dP9s6JhK6fzzL+U/PzotMJwA6P85BqL30w==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/block-serialization-default-parser": { - "version": "3.10.2", - "resolved": "https://registry.npmjs.org/@wordpress/block-serialization-default-parser/-/block-serialization-default-parser-3.10.2.tgz", - "integrity": "sha512-0vyHHTcEw3ijY+stJqCf0iVR4bHpb84dbTZVaT2VSzISGzeVuAJpcYhIJMHvDTMcX1E2pgAfanIL8xloS6W7gQ==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/blocks": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/@wordpress/blocks/-/blocks-8.0.3.tgz", - "integrity": "sha512-/zXk5gEI/TCzsVSUIht5cmO+pFC6u3mpNV8ye0Cy4CEQVtauW969GvgEM+LVf8Mk8R5NcLdLPE88n8xxsFaRoQ==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/autop": "^2.12.2", - "@wordpress/blob": "^2.13.2", - "@wordpress/block-serialization-default-parser": "^3.10.2", - "@wordpress/compose": "^3.25.3", - "@wordpress/data": "^4.27.3", - "@wordpress/deprecated": "^2.12.3", - "@wordpress/dom": "^2.18.0", - "@wordpress/element": "^2.20.3", - "@wordpress/hooks": "^2.12.3", - "@wordpress/html-entities": "^2.11.2", - "@wordpress/i18n": "^3.20.0", - "@wordpress/icons": "^2.10.3", - "@wordpress/is-shallow-equal": "^3.1.3", - "@wordpress/shortcode": "^2.13.2", - "hpq": "^1.3.0", - "lodash": "^4.17.19", - "rememo": "^3.0.0", - "showdown": "^1.9.1", - "simple-html-tokenizer": "^0.5.7", - "tinycolor2": "^1.4.2", - "uuid": "^8.3.0" - } - }, "@wordpress/components": { - "version": "13.0.3", - "resolved": "https://registry.npmjs.org/@wordpress/components/-/components-13.0.3.tgz", - "integrity": "sha512-L5cCeZvhFsLlGVxuAIFwqZotLqrwrisFjikd6a0Aj8jlTZrb9vNQ4mDXU1Zz2toHCH3NegIUAHMHOs3Jf46tWg==", + "version": "11.1.5", + "resolved": "https://registry.npmjs.org/@wordpress/components/-/components-11.1.5.tgz", + "integrity": "sha512-XOVD4HgqvizuqMtY1XzppNiw2ET2VefGtdclewb3sB/eBxkNtqb2hl9mHBG547Au0QZnsOylK9AOAZI0eYhMOw==", "dev": true, "requires": { - "@babel/runtime": "^7.13.10", - "@emotion/cache": "^10.0.27", - "@emotion/core": "^10.1.1", + "@babel/runtime": "^7.11.2", + "@emotion/core": "^10.0.22", "@emotion/css": "^10.0.22", - "@emotion/hash": "^0.8.0", "@emotion/native": "^10.0.22", "@emotion/styled": "^10.0.23", - "@wordpress/a11y": "^2.15.3", - "@wordpress/compose": "^3.25.3", - "@wordpress/date": "^3.15.1", - "@wordpress/deprecated": "^2.12.3", - "@wordpress/dom": "^2.18.0", - "@wordpress/element": "^2.20.3", - "@wordpress/hooks": "^2.12.3", - "@wordpress/i18n": "^3.20.0", - "@wordpress/icons": "^2.10.3", - "@wordpress/is-shallow-equal": "^3.1.3", - "@wordpress/keycodes": "^2.19.3", - "@wordpress/primitives": "^1.12.3", - "@wordpress/rich-text": "^3.25.3", - "@wordpress/warning": "^1.4.2", - "@wp-g2/components": "^0.0.160", - "@wp-g2/context": "^0.0.160", - "@wp-g2/styles": "^0.0.160", - "@wp-g2/utils": "^0.0.160", + "@wordpress/a11y": "^2.13.0", + "@wordpress/compose": "^3.22.0", + "@wordpress/date": "^3.12.0", + "@wordpress/deprecated": "^2.10.0", + "@wordpress/dom": "^2.15.0", + "@wordpress/element": "^2.18.0", + "@wordpress/hooks": "^2.10.0", + "@wordpress/i18n": "^3.16.0", + "@wordpress/icons": "^2.8.0", + "@wordpress/is-shallow-equal": "^2.3.0", + "@wordpress/keycodes": "^2.16.0", + "@wordpress/primitives": "^1.10.0", + "@wordpress/rich-text": "^3.23.0", + "@wordpress/warning": "^1.3.0", "classnames": "^2.2.5", "dom-scroll-into-view": "^1.2.1", - "downshift": "^6.0.15", + "downshift": "^5.4.0", "gradient-parser": "^0.1.5", - "highlight-words-core": "^1.2.2", "lodash": "^4.17.19", "memize": "^1.1.0", "moment": "^2.22.1", "re-resizable": "^6.4.0", "react-dates": "^17.1.1", - "react-resize-aware": "^3.1.0", + "react-merge-refs": "^1.0.0", + "react-resize-aware": "^3.0.1", "react-spring": "^8.0.20", - "react-use-gesture": "^9.0.0", - "reakit": "^1.3.5", + "react-use-gesture": "^7.0.15", + "reakit": "^1.1.0", "rememo": "^3.0.0", - "tinycolor2": "^1.4.2", - "uuid": "^8.3.0" - } - }, - "@wordpress/compose": { - "version": "3.25.3", - "resolved": "https://registry.npmjs.org/@wordpress/compose/-/compose-3.25.3.tgz", - "integrity": "sha512-tCO2EnJCkCH548OqA0uU8V1k/1skz2QwBlHs8ZQSpimqUS4OWWsAlndCEFe4U4vDTqFt2ow7tzAir+05Cw8MAg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/deprecated": "^2.12.3", - "@wordpress/dom": "^2.18.0", - "@wordpress/element": "^2.20.3", - "@wordpress/is-shallow-equal": "^3.1.3", - "@wordpress/keycodes": "^2.19.3", - "@wordpress/priority-queue": "^1.11.2", - "clipboard": "^2.0.1", - "lodash": "^4.17.19", - "memize": "^1.1.0", - "mousetrap": "^1.6.5", - "react-resize-aware": "^3.1.0", - "use-memo-one": "^1.1.1" - } - }, - "@wordpress/data": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@wordpress/data/-/data-4.27.3.tgz", - "integrity": "sha512-5763NgNV9IIa1CC3Q80dAvrH6108tJtj3IrHfUCZmUk1atSNsOMBCkLdQ7tGTTi2JFejeGEMg1LJI22JD5zM6Q==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/compose": "^3.25.3", - "@wordpress/deprecated": "^2.12.3", - "@wordpress/element": "^2.20.3", - "@wordpress/is-shallow-equal": "^3.1.3", - "@wordpress/priority-queue": "^1.11.2", - "@wordpress/redux-routine": "^3.14.2", - "equivalent-key-map": "^0.2.2", - "is-promise": "^4.0.0", - "lodash": "^4.17.19", - "memize": "^1.1.0", - "redux": "^4.0.0", - "turbo-combine-reducers": "^1.0.2", - "use-memo-one": "^1.1.1" - } - }, - "@wordpress/date": { - "version": "3.15.1", - "resolved": "https://registry.npmjs.org/@wordpress/date/-/date-3.15.1.tgz", - "integrity": "sha512-SuHiObvjbegL8RpaSQ6JqFnG+QyGP+oUhx1FZDMdt1nOQA9HE7D5ssVlZFlMEAdo6iS8xMuW+4SgJN3Eo1fb4w==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "moment": "^2.22.1", - "moment-timezone": "^0.5.31" - } - }, - "@wordpress/deprecated": { - "version": "2.12.3", - "resolved": "https://registry.npmjs.org/@wordpress/deprecated/-/deprecated-2.12.3.tgz", - "integrity": "sha512-qr+yDfTQfI3M4h6oY6IeHWwoHr4jxbILjSlV+Ht6Jjto9Owap6OuzSqR13Ev4xqIoG4C7b5B3gZXVfwVDae1zg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/hooks": "^2.12.3" - } - }, - "@wordpress/dom": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/@wordpress/dom/-/dom-2.18.0.tgz", - "integrity": "sha512-tM2WeQuSObl3nzWjUTF0/dyLnA7sdl/MXaSe32D64OF89bjSyJvjUipI7gjKzI3kJ7ddGhwcTggGvSB06MOoCQ==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "lodash": "^4.17.19" - } - }, - "@wordpress/dom-ready": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/@wordpress/dom-ready/-/dom-ready-2.13.2.tgz", - "integrity": "sha512-COH7n2uZfBq4FtluSbl37N3nCEcdMXzV42ETCWKUcumiP1Zd3qnkfQKcsxTaHWY8aVt/358RvJ7ghWe3xAd+fg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/element": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/@wordpress/element/-/element-2.20.3.tgz", - "integrity": "sha512-f4ZPTDf9CxiiOXiMxc4v1K7jcBMT4dsiehVOpkKzCDKboNXp4qVf8oe5PE23VGZNEjcOj5Mkg9hB57R0nqvMTw==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@types/react": "^16.9.0", - "@types/react-dom": "^16.9.0", - "@wordpress/escape-html": "^1.12.2", - "lodash": "^4.17.19", - "react": "^16.13.1", - "react-dom": "^16.13.1" - } - }, - "@wordpress/escape-html": { - "version": "1.12.2", - "resolved": "https://registry.npmjs.org/@wordpress/escape-html/-/escape-html-1.12.2.tgz", - "integrity": "sha512-FabgSwznhdaUwe6hr1CsGpgxQbzqEoGevv73WIL1B9GvlZ6csRWodgHfWh4P6fYqpzxFL4WYB8wPJ1PdO32XFA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/hooks": { - "version": "2.12.3", - "resolved": "https://registry.npmjs.org/@wordpress/hooks/-/hooks-2.12.3.tgz", - "integrity": "sha512-LmKiwKldZt6UYqOxV/a6+eUFXdvALFnB/pQx3RmrMvO64sgFhfR6dhrlv+uVbuuezSuv8dce1jx8lUWAT0krMA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/html-entities": { - "version": "2.11.2", - "resolved": "https://registry.npmjs.org/@wordpress/html-entities/-/html-entities-2.11.2.tgz", - "integrity": "sha512-WIdEGO9/o7tuTV3jpLHhFC/NBBnNdJeG9nRZbEyb37CL1fvqJA85hTugyDOhGzOVIAtpFTc6kr/gMJK1oTdopw==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/i18n": { - "version": "3.20.0", - "resolved": "https://registry.npmjs.org/@wordpress/i18n/-/i18n-3.20.0.tgz", - "integrity": "sha512-SIoOJFB4UrrYAScS4H91CYCLW9dX3Ghv8pBKc/yHGculb1AdGr6gRMlmJxZV62Cn3CZ4Ga86c+FfR+GiBu0JPg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/hooks": "^2.12.3", - "gettext-parser": "^1.3.1", - "lodash": "^4.17.19", - "memize": "^1.1.0", - "sprintf-js": "^1.1.1", - "tannin": "^1.2.0" - } - }, - "@wordpress/icons": { - "version": "2.10.3", - "resolved": "https://registry.npmjs.org/@wordpress/icons/-/icons-2.10.3.tgz", - "integrity": "sha512-hVXArGOHLE5pL1G3rHNzsUEuTR4/G6lB+enKYwhYSSIqWuSbyXbZq3nvibxpepPrLy9B3d5t6aR6QUmjMVzIcQ==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/element": "^2.20.3", - "@wordpress/primitives": "^1.12.3" + "tinycolor2": "^1.4.1", + "uuid": "^7.0.2" } }, "@wordpress/is-shallow-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/@wordpress/is-shallow-equal/-/is-shallow-equal-3.1.3.tgz", - "integrity": "sha512-eDLhfC4aaSgklzqwc6F/F4zmJVpTVTAvhqX+q0SP/8LPcP2HuKErPHVrEc75PMWqIutja2wJg98YSNPdewrj1w==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/keycodes": { - "version": "2.19.3", - "resolved": "https://registry.npmjs.org/@wordpress/keycodes/-/keycodes-2.19.3.tgz", - "integrity": "sha512-8rNdmP5M1ifTgLIL0dt/N1uTGsq/Rx1ydCXy+gg24WdxBRhyu5sudNVCtascVXo26aIfOH9OJRdqRZZTEORhog==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/i18n": "^3.20.0", - "lodash": "^4.17.19" - } - }, - "@wordpress/primitives": { - "version": "1.12.3", - "resolved": "https://registry.npmjs.org/@wordpress/primitives/-/primitives-1.12.3.tgz", - "integrity": "sha512-LIF44bVlJS7CJEVmk6TLuV6HZMdj5iwkyM8do4ukGY6qnZIzrXpBablgJeDBcyjzWrWRLn+w+tiZ/8l+2egoVA==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/element": "^2.20.3", - "classnames": "^2.2.5" - } - }, - "@wordpress/priority-queue": { - "version": "1.11.2", - "resolved": "https://registry.npmjs.org/@wordpress/priority-queue/-/priority-queue-1.11.2.tgz", - "integrity": "sha512-ulwmUOklY3orn1xXpcPnTyGWV5B/oycxI+cHZ6EevBVgM5sq+BW3xo0PKLR/MMm6UNBtFTu/71QAJrNZcD6V1g==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10" - } - }, - "@wordpress/redux-routine": { - "version": "3.14.2", - "resolved": "https://registry.npmjs.org/@wordpress/redux-routine/-/redux-routine-3.14.2.tgz", - "integrity": "sha512-aqi4UtvMP/+NhULxyCR8ktG0v4BJVTRcMpByAqDg7Oabq2sz2LPuShxd5UY8vxQYQY9t1uUJbslhom4ytcohWg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "is-promise": "^4.0.0", - "lodash": "^4.17.19", - "rungen": "^0.3.2" - } - }, - "@wordpress/rich-text": { - "version": "3.25.3", - "resolved": "https://registry.npmjs.org/@wordpress/rich-text/-/rich-text-3.25.3.tgz", - "integrity": "sha512-FdqL1/rHTsRxZ1gW1UEWuy0URmUEqMzj5hcAbOhHFPO5m0ENrkzC9bBa195KqZBSNSmBmXnDZdHu4UJUolzcZg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "@wordpress/compose": "^3.25.3", - "@wordpress/data": "^4.27.3", - "@wordpress/dom": "^2.18.0", - "@wordpress/element": "^2.20.3", - "@wordpress/escape-html": "^1.12.2", - "@wordpress/is-shallow-equal": "^3.1.3", - "@wordpress/keycodes": "^2.19.3", - "classnames": "^2.2.5", - "lodash": "^4.17.19", - "memize": "^1.1.0", - "rememo": "^3.0.0" - } - }, - "@wordpress/shortcode": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/@wordpress/shortcode/-/shortcode-2.13.2.tgz", - "integrity": "sha512-n4O5O66ARGY+h1SCvt0uOIQAJ6B4hd6EjULAWRNYgQuuF9mdhcczpGvSH76BssuvLN6bJU1RjsVy7m56kqO5xw==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@wordpress/is-shallow-equal/-/is-shallow-equal-2.3.0.tgz", + "integrity": "sha512-BUVCYZNDoT5fRJGoam/nI2Sn8QELu5z/pFe7UL+szFqQqNnMibdWqN/KoW/YO7WLJqqqTRhAs/Fa51g4oXRyHQ==", "dev": true, "requires": { - "@babel/runtime": "^7.13.10", - "lodash": "^4.17.19", - "memize": "^1.1.0" + "@babel/runtime": "^7.11.2" } }, - "@wordpress/url": { - "version": "2.22.2", - "resolved": "https://registry.npmjs.org/@wordpress/url/-/url-2.22.2.tgz", - "integrity": "sha512-aqpYKQXzyzkCOm+GzZRYlLb+wh58g0cwR1PaKAl0UXaBS4mdS+X6biMriylb4P8CVC/RR7CSw5XI20JC24KDwQ==", + "downshift": { + "version": "5.4.7", + "resolved": "https://registry.npmjs.org/downshift/-/downshift-5.4.7.tgz", + "integrity": "sha512-xaH0RNqwJ5pAsyk9qBmR9XJWmg1OOWMfrhzYv0NH2NjJxn77S3zBcfClw341UfhGyKg5v+qVqg/CQzvAgBNCXQ==", "dev": true, "requires": { - "@babel/runtime": "^7.13.10", - "lodash": "^4.17.19", - "react-native-url-polyfill": "^1.1.2" + "@babel/runtime": "^7.10.2", + "compute-scroll-into-view": "^1.0.14", + "prop-types": "^15.7.2", + "react-is": "^16.13.1" } }, - "@wordpress/warning": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/@wordpress/warning/-/warning-1.4.2.tgz", - "integrity": "sha512-MjrkSp6Jyfx+92AE32A83P503noUtGb6//BYUH4GiWzzzSNhDHgbQ0UcOJwJaEYK166DxSNpMk/JXc4YENi1Cw==", + "react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", "dev": true }, - "@wp-g2/components": { - "version": "0.0.160", - "resolved": "https://registry.npmjs.org/@wp-g2/components/-/components-0.0.160.tgz", - "integrity": "sha512-44qUtiF5Nl/srD7Vzbpcd0im/EIej04fOdDfa0lfDxXJDNK3RRtSSEwCRhok/M5SKCmvYbZKRUx2K0ugXNqK0Q==", - "dev": true, - "requires": { - "@popperjs/core": "^2.5.4", - "@wp-g2/context": "^0.0.160", - "@wp-g2/styles": "^0.0.160", - "@wp-g2/utils": "^0.0.160", - "csstype": "^3.0.3", - "downshift": "^6.0.15", - "framer-motion": "^2.1.0", - "highlight-words-core": "^1.2.2", - "history": "^4.9.0", - "lodash": "^4.17.19", - "path-to-regexp": "^1.7.0", - "react-colorful": "4.4.4", - "react-textarea-autosize": "^8.2.0", - "react-use-gesture": "^9.0.0", - "reakit": "^1.3.4" - } - }, - "@wp-g2/context": { - "version": "0.0.160", - "resolved": "https://registry.npmjs.org/@wp-g2/context/-/context-0.0.160.tgz", - "integrity": "sha512-50wSQCZkdZEexP88Ljutskn7/klT2Id1ks4GpzKDSBM8kadrfNdr2iabjgJdFLIH33S+r4dzEnzLs9SFtqUgwg==", - "dev": true, - "requires": { - "@wp-g2/create-styles": "^0.0.160", - "@wp-g2/styles": "^0.0.160", - "@wp-g2/utils": "^0.0.160", - "lodash": "^4.17.19" - } - }, - "@wp-g2/styles": { - "version": "0.0.160", - "resolved": "https://registry.npmjs.org/@wp-g2/styles/-/styles-0.0.160.tgz", - "integrity": "sha512-o91jxb0ZwEDRJrtVVjnqn3qTAXjnxZ1fX5KF3Q7oz776lMZPHsyfC0hvqnOz0w7zqaZZpdWtVQRShgrYXN6JHw==", - "dev": true, - "requires": { - "@wp-g2/create-styles": "^0.0.160", - "@wp-g2/utils": "^0.0.160" - } - }, - "@wp-g2/utils": { - "version": "0.0.160", - "resolved": "https://registry.npmjs.org/@wp-g2/utils/-/utils-0.0.160.tgz", - "integrity": "sha512-4FhezjKyeYVb+3PZahW1kmqXpCvVvuJM97EcGqkKf+u4Qf66J3n1niHgfnRbn8aNydYK6EFze+6/UL48U35z1w==", - "dev": true, - "requires": { - "copy-to-clipboard": "^3.3.1", - "create-emotion": "^10.0.27", - "deepmerge": "^4.2.2", - "fast-deep-equal": "^3.1.3", - "hoist-non-react-statics": "^3.3.2", - "json2mq": "^0.2.0", - "lodash": "^4.17.19", - "memize": "^1.1.0", - "react-merge-refs": "^1.1.0", - "react-resize-aware": "^3.1.0", - "tinycolor2": "^1.4.2", - "use-enhanced-state": "^0.0.13", - "use-isomorphic-layout-effect": "^1.0.0" - } - }, - "csstype": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.8.tgz", - "integrity": "sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==", + "react-use-gesture": { + "version": "7.0.16", + "resolved": "https://registry.npmjs.org/react-use-gesture/-/react-use-gesture-7.0.16.tgz", + "integrity": "sha512-gwgX+E+WQG0T1uFVl3z8j3ZwH3QQGIgVl7VtQEC2m0IscSs668sSps4Ss3CFp3Vns8xx0j9TVK4aBXH6+YrpEg==", "dev": true }, - "downshift": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/downshift/-/downshift-6.1.3.tgz", - "integrity": "sha512-RA1MuaNcTbt0j+sVLhSs8R2oZbBXYAtdQP/V+uHhT3DoDteZzJPjlC+LQVm9T07Wpvo84QXaZtUCePLDTDwGXg==", - "dev": true, - "requires": { - "@babel/runtime": "^7.13.10", - "compute-scroll-into-view": "^1.0.17", - "prop-types": "^15.7.2", - "react-is": "^17.0.2" - } + "uuid": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-7.0.3.tgz", + "integrity": "sha512-DPSke0pXhTZgoF/d+WSt2QaKMCFSfx7QegxEWT+JOuHF5aWrKEn0G+ztjuJg/gG8/ItK+rbPCD/yNv8yyih6Cg==", + "dev": true } } }, diff --git a/package.json b/package.json index 829285afb..7f7796edd 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@wordpress/notices": "2.13.0", "@wordpress/postcss-plugins-preset": "2.1.0", "@wordpress/scripts": "14.1.0", - "@wordpress/server-side-render": "1.21.3", + "@wordpress/server-side-render": "1.19.5", "@wordpress/url": "2.22.0", "ace-builds": "1.4.12", "autoprefixer": "10.1.0", From 81c182055e82200d60806393d9285e30ae9f8a71 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 15:16:19 -0500 Subject: [PATCH 07/21] When changing a field name, change the name in the previewAttributes Without this, could have a network error. --- js/src/block-editor/components/repeater-rows.js | 11 +++++++---- js/src/edit-block/hooks/useField.js | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/js/src/block-editor/components/repeater-rows.js b/js/src/block-editor/components/repeater-rows.js index 7787fc80f..9553db969 100644 --- a/js/src/block-editor/components/repeater-rows.js +++ b/js/src/block-editor/components/repeater-rows.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import * as React from 'react'; + /** * WordPress dependencies */ @@ -135,10 +140,8 @@ class RepeaterRows extends Component { const attribute = attr[ parentName ]; const repeaterRows = this.getRows( attribute ); - /* - * Calling slice() essentially creates a copy of repeaterRows. - * Without this, it looks like setAttributes() doesn't recognize a change to the array, and the component doesn't re-render. - */ + // Calling slice() essentially creates a copy of repeaterRows. + // Without this, it looks like setAttributes() doesn't recognize a change to the array, and the component doesn't re-render. const rows = repeaterRows.slice(); [ rows[ from ], rows[ to ] ] = [ rows[ to ], rows[ from ] ]; diff --git a/js/src/edit-block/hooks/useField.js b/js/src/edit-block/hooks/useField.js index dd6537302..bf4efb948 100644 --- a/js/src/edit-block/hooks/useField.js +++ b/js/src/edit-block/hooks/useField.js @@ -177,6 +177,8 @@ const useField = () => { */ const changeFieldName = ( fields, previousName, newName ) => { const newFields = { ...fields }; + const newBlock = { ...block }; + // If this is a repeater, change the parent property of its sub_fields. if ( newFields[ previousName ] && newFields[ previousName ].hasOwnProperty( 'sub_fields' ) ) { newFields[ previousName ].sub_fields = getFieldsAsObject( @@ -192,6 +194,13 @@ const useField = () => { newFields[ newName ] = { ...newFields[ previousName ], name: newName }; delete newFields[ previousName ]; + if ( newBlock?.previewAttributes?.hasOwnProperty( previousName ) ) { + newBlock.previewAttributes[ newName ] = newBlock.previewAttributes[ previousName ]; + delete newBlock?.previewAttributes[ previousName ]; + } + + editBlock( newBlock ); + return newFields; }; From 66452fe8428876cfaa3daee98a1d9c89b3efc313 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 15:31:35 -0500 Subject: [PATCH 08/21] On changing the field type, delete the previewAttribute The attribute could be of a different type. For example, changing from a Url field to Image, the type will change from from string to integer. So this prevents an error in ServerSideRender. --- js/src/edit-block/hooks/useField.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/edit-block/hooks/useField.js b/js/src/edit-block/hooks/useField.js index bf4efb948..fc3465b96 100644 --- a/js/src/edit-block/hooks/useField.js +++ b/js/src/edit-block/hooks/useField.js @@ -158,6 +158,7 @@ const useField = () => { newBlock.fields[ fieldToChange.parent ].sub_fields[ fieldToChange.name ] = newField; } else { newBlock.fields[ fieldToChange.name ] = newField; + delete newBlock?.previewAttributes[ fieldToChange.name ]; } editBlock( newBlock ); From f1c4aff4fbce574795f3c13e1ff1e0e1990b99dc Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 15:47:33 -0500 Subject: [PATCH 09/21] Refactor preview into component --- js/src/edit-block/components/editor.js | 10 +++--- .../components/front-end-preview.js | 34 +++++++++++++++++++ js/src/edit-block/components/index.js | 1 + 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 js/src/edit-block/components/front-end-preview.js diff --git a/js/src/edit-block/components/editor.js b/js/src/edit-block/components/editor.js index 032dd94d2..cd9f4521d 100644 --- a/js/src/edit-block/components/editor.js +++ b/js/src/edit-block/components/editor.js @@ -13,7 +13,6 @@ import { UnsavedChangesWarning, } from '@wordpress/editor'; import { StrictMode, useState } from '@wordpress/element'; -import ServerSideRender from '@wordpress/server-side-render'; /** * Internal dependencies @@ -24,6 +23,7 @@ import { EditorProvider, FieldPanel, FieldsGrid, + FrontEndPreview, Header, LocationButtons, Main, @@ -176,11 +176,9 @@ const Editor = ( { onError, postId, postType, settings } ) => { } { FRONT_END_PREVIEW_EDITING_MODE === editorMode ? ( - ) : null } diff --git a/js/src/edit-block/components/front-end-preview.js b/js/src/edit-block/components/front-end-preview.js new file mode 100644 index 000000000..3e74ddc1a --- /dev/null +++ b/js/src/edit-block/components/front-end-preview.js @@ -0,0 +1,34 @@ +/** + * External dependencies + */ +import * as React from 'react'; + +/** + * WordPress dependencies + */ +import ServerSideRender from '@wordpress/server-side-render'; + +/** + * @typedef {Object} FrontEndPreviewProps The header component props. + * @property {string} blockName The name of the block, without the namespace. + * @property {Object} previewAttributes The attributes to display in the preview. + */ + +/** + * The front-end previews of the block. + * + * @param {FrontEndPreviewProps} props + * @return {React.ReactElement} The fields displayed in a grid. + */ +const FrontEndPreview = ( { blockName, previewAttributes } ) => { + return ( + + ); +}; + +export default FrontEndPreview; diff --git a/js/src/edit-block/components/index.js b/js/src/edit-block/components/index.js index c6dd20188..baa72dc1c 100644 --- a/js/src/edit-block/components/index.js +++ b/js/src/edit-block/components/index.js @@ -9,6 +9,7 @@ export { default as Field } from './field'; export { default as FieldPanel } from './field-panel'; export { default as FieldsGrid } from './fields-grid'; export { default as FieldSettings } from './field-settings'; +export { default as FrontEndPreview } from './front-end-preview'; export { default as Header } from './header'; export { default as IconSection } from './icon-section'; export { default as Input } from './input'; From 67ae09b48072fa9a2ab1461a93ca22e546bfeb2a Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 17:14:55 -0500 Subject: [PATCH 10/21] Possible approach to handling error --- .../components/front-end-preview.js | 53 ++++++++++++++++++- js/src/edit-block/components/header.js | 5 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/js/src/edit-block/components/front-end-preview.js b/js/src/edit-block/components/front-end-preview.js index 3e74ddc1a..6fbd9bb36 100644 --- a/js/src/edit-block/components/front-end-preview.js +++ b/js/src/edit-block/components/front-end-preview.js @@ -6,6 +6,11 @@ import * as React from 'react'; /** * WordPress dependencies */ +import { Placeholder } from '@wordpress/components'; +import { useSelect } from '@wordpress/data'; +import { PostPublishButton } from '@wordpress/editor'; +import { useEffect } from '@wordpress/element'; +import { __, sprintf } from '@wordpress/i18n'; import ServerSideRender from '@wordpress/server-side-render'; /** @@ -14,19 +19,65 @@ import ServerSideRender from '@wordpress/server-side-render'; * @property {Object} previewAttributes The attributes to display in the preview. */ +/** + * @typedef {Object} ErrorResponsePlaceholderProps The header component props. + * @property {Object} response The response from the endpoint. + * @property {string} className The class name to display. + */ + +/** + * Forked from @wordpress/server-side-render. + * + * @see https://github.com/WordPress/gutenberg/blob/3da717b8d0ac7d7821fc6d0475695ccf3ae2829f/packages/server-side-render/src/server-side-render.js#L33 + * + * @param {ErrorResponsePlaceholderProps} props + * @return {React.ReactElement} The error placeholder. + */ +const ErrorResponsePlaceholder = ( { response, className } ) => { + const isEditedPostDirty = useSelect( ( select ) => select( 'core/editor' ).isEditedPostDirty() ); + + const errorMessage = sprintf( + // translators: %s: error message describing the problem + __( 'Error loading block: %s.' ), + response.errorMsg + ); + return ( + + { errorMessage } + { + isEditedPostDirty + ? ( + <> +   + { __( 'Clicking here might prevent it:', 'genesis-custom-blocks' ) } +   + + + ) + : null + } + + ); +}; + /** * The front-end previews of the block. * * @param {FrontEndPreviewProps} props - * @return {React.ReactElement} The fields displayed in a grid. + * @return {React.ReactElement} The front-end preview. */ const FrontEndPreview = ( { blockName, previewAttributes } ) => { + const isEditedPostDirty = useSelect( ( select ) => select( 'core/editor' ).isEditedPostDirty() ); + + useEffect( () => {}, [ isEditedPostDirty ] ); + return ( ); }; diff --git a/js/src/edit-block/components/header.js b/js/src/edit-block/components/header.js index 3b2e3820f..463ddae41 100644 --- a/js/src/edit-block/components/header.js +++ b/js/src/edit-block/components/header.js @@ -109,10 +109,7 @@ const Header = ( { editorMode, setEditorMode } ) => {
- + From 236e8856e61ffc854d8c00ce64fdd5f5f5b88d17 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 17:30:37 -0500 Subject: [PATCH 11/21] Simpler approach to front-end preview (if it works) The server-side will only have the saved post values. So pass the saved previewAttributes, not just the edited ones. This looks to prevent errors in . --- js/src/edit-block/components/editor.js | 8 +-- .../components/front-end-preview.js | 71 ++++--------------- 2 files changed, 17 insertions(+), 62 deletions(-) diff --git a/js/src/edit-block/components/editor.js b/js/src/edit-block/components/editor.js index cd9f4521d..41beb00f2 100644 --- a/js/src/edit-block/components/editor.js +++ b/js/src/edit-block/components/editor.js @@ -175,12 +175,8 @@ const Editor = ( { onError, postId, postType, settings } ) => { ) : null } { FRONT_END_PREVIEW_EDITING_MODE === editorMode - ? ( - - ) : null + ? + : null } { TEMPLATE_EDITOR_EDITING_MODE === editorMode ? diff --git a/js/src/edit-block/components/front-end-preview.js b/js/src/edit-block/components/front-end-preview.js index 6fbd9bb36..cf5cbd9a9 100644 --- a/js/src/edit-block/components/front-end-preview.js +++ b/js/src/edit-block/components/front-end-preview.js @@ -6,78 +6,37 @@ import * as React from 'react'; /** * WordPress dependencies */ -import { Placeholder } from '@wordpress/components'; import { useSelect } from '@wordpress/data'; -import { PostPublishButton } from '@wordpress/editor'; -import { useEffect } from '@wordpress/element'; -import { __, sprintf } from '@wordpress/i18n'; import ServerSideRender from '@wordpress/server-side-render'; /** - * @typedef {Object} FrontEndPreviewProps The header component props. - * @property {string} blockName The name of the block, without the namespace. - * @property {Object} previewAttributes The attributes to display in the preview. + * Internal dependencies */ +import { getBlock, getBlockNameWithNameSpace } from '../helpers'; /** - * @typedef {Object} ErrorResponsePlaceholderProps The header component props. - * @property {Object} response The response from the endpoint. - * @property {string} className The class name to display. - */ - -/** - * Forked from @wordpress/server-side-render. + * The front-end preview of the block. * - * @see https://github.com/WordPress/gutenberg/blob/3da717b8d0ac7d7821fc6d0475695ccf3ae2829f/packages/server-side-render/src/server-side-render.js#L33 + * Gets the saved post with .getCurrentPost(), + * not the edited post. + * The server side only has access to the saved post. + * So there can be an error in + * if it passes attributes that aren't yet saved. * - * @param {ErrorResponsePlaceholderProps} props - * @return {React.ReactElement} The error placeholder. - */ -const ErrorResponsePlaceholder = ( { response, className } ) => { - const isEditedPostDirty = useSelect( ( select ) => select( 'core/editor' ).isEditedPostDirty() ); - - const errorMessage = sprintf( - // translators: %s: error message describing the problem - __( 'Error loading block: %s.' ), - response.errorMsg - ); - return ( - - { errorMessage } - { - isEditedPostDirty - ? ( - <> -   - { __( 'Clicking here might prevent it:', 'genesis-custom-blocks' ) } -   - - - ) - : null - } - - ); -}; - -/** - * The front-end previews of the block. - * - * @param {FrontEndPreviewProps} props * @return {React.ReactElement} The front-end preview. */ -const FrontEndPreview = ( { blockName, previewAttributes } ) => { - const isEditedPostDirty = useSelect( ( select ) => select( 'core/editor' ).isEditedPostDirty() ); - - useEffect( () => {}, [ isEditedPostDirty ] ); +const FrontEndPreview = () => { + const currentPost = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); + const fullBlock = getBlock( currentPost?.content ); + const blockNameWithNameSpace = getBlockNameWithNameSpace( fullBlock ); + const block = fullBlock[ blockNameWithNameSpace ] || {}; return ( ); }; From 19632aa6c12b56ece2611d5ab362f715352e6894 Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 18:16:55 -0500 Subject: [PATCH 12/21] Handle the Front-end preview for new post If there is nothing saved, there will be nothing to preview. --- .../components/front-end-preview.js | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/js/src/edit-block/components/front-end-preview.js b/js/src/edit-block/components/front-end-preview.js index cf5cbd9a9..cd735771c 100644 --- a/js/src/edit-block/components/front-end-preview.js +++ b/js/src/edit-block/components/front-end-preview.js @@ -7,6 +7,8 @@ import * as React from 'react'; * WordPress dependencies */ import { useSelect } from '@wordpress/data'; +import { PostSavedState } from '@wordpress/editor'; +import { __ } from '@wordpress/i18n'; import ServerSideRender from '@wordpress/server-side-render'; /** @@ -27,17 +29,43 @@ import { getBlock, getBlockNameWithNameSpace } from '../helpers'; */ const FrontEndPreview = () => { const currentPost = useSelect( ( select ) => select( 'core/editor' ).getCurrentPost() ); + const isPostNew = useSelect( ( select ) => select( 'core/editor' ).isEditedPostNew() ); + const isPostDirty = useSelect( ( select ) => select( 'core/editor' ).isEditedPostDirty() ); + const fullBlock = getBlock( currentPost?.content ); const blockNameWithNameSpace = getBlockNameWithNameSpace( fullBlock ); const block = fullBlock[ blockNameWithNameSpace ] || {}; + // There's nothing entered or saved, so would have an error. + if ( isPostNew && ! isPostDirty ) { + return ( +

+ { __( 'Please add fields to the block to preview it.', 'genesis-custom-blocks' ) } +

+ ); + } + return ( - + <> + { + isPostNew && isPostDirty + ? ( +
+ { __( 'Please save your block to preview it:', 'genesis-custom-blocks' ) } +   + +
+ ) + : ( + + ) + } + ); }; From 7cb75dbd027fe47862ce8b10c1d87d2b84df4d7e Mon Sep 17 00:00:00 2001 From: Ryan Kienstra Date: Mon, 3 May 2021 18:41:22 -0500 Subject: [PATCH 13/21] If there is no field to preview, suggest that they add a field Maybe if this were more effortless, it would allow them to click a