diff --git a/projects/packages/jetpack-mu-wpcom/.phan/baseline.php b/projects/packages/jetpack-mu-wpcom/.phan/baseline.php index f8dea226fcd09..6865fcfd0af51 100644 --- a/projects/packages/jetpack-mu-wpcom/.phan/baseline.php +++ b/projects/packages/jetpack-mu-wpcom/.phan/baseline.php @@ -9,46 +9,31 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 35+ occurrences - // PhanPluginDuplicateConditionalNullCoalescing : 20+ occurrences - // PhanUndeclaredClassMethod : 20+ occurrences + // PhanTypeMismatchArgument : 15+ occurrences // PhanTypeMismatchArgumentProbablyReal : 15+ occurrences - // PhanTypeMismatchReturnProbablyReal : 10+ occurrences - // PhanUndeclaredFunction : 10+ occurrences - // PhanTypeMismatchReturn : 8 occurrences - // PhanUndeclaredConstant : 7 occurrences - // PhanTypeArraySuspiciousNullable : 6 occurrences + // PhanPluginDuplicateConditionalNullCoalescing : 8 occurrences + // PhanTypeMismatchReturn : 6 occurrences + // PhanUndeclaredClassMethod : 6 occurrences // PhanNoopNew : 5 occurrences - // PhanParamTooMany : 4 occurrences - // PhanUnextractableAnnotationSuffix : 4 occurrences - // PhanDeprecatedProperty : 3 occurrences - // PhanPluginDuplicateExpressionAssignmentOperation : 3 occurrences + // PhanTypeMismatchArgumentInternal : 4 occurrences + // PhanTypeMismatchReturnProbablyReal : 4 occurrences // PhanTypePossiblyInvalidDimOffset : 3 occurrences - // PhanTypeSuspiciousNonTraversableForeach : 3 occurrences - // PhanUndeclaredClassReference : 3 occurrences - // PhanUndeclaredGlobalVariable : 3 occurrences // PhanEmptyFQSENInCallable : 2 occurrences - // PhanPluginMixedKeyNoKey : 2 occurrences + // PhanParamTooMany : 2 occurrences // PhanTypeArraySuspicious : 2 occurrences - // PhanTypeMismatchArgumentInternal : 2 occurrences + // PhanTypeArraySuspiciousNullable : 2 occurrences // PhanTypeMismatchDefault : 2 occurrences // PhanTypeMissingReturn : 2 occurrences + // PhanUndeclaredFunction : 2 occurrences // PhanDeprecatedFunction : 1 occurrence // PhanImpossibleTypeComparison : 1 occurrence // PhanNonClassMethodCall : 1 occurrence // PhanNoopArrayAccess : 1 occurrence - // PhanPluginRedundantAssignment : 1 occurrence // PhanPluginSimplifyExpressionBool : 1 occurrence - // PhanPossiblyUndeclaredVariable : 1 occurrence // PhanRedefineFunction : 1 occurrence // PhanRedundantCondition : 1 occurrence // PhanTypeComparisonToArray : 1 occurrence - // PhanTypeInvalidLeftOperandOfBitwiseOp : 1 occurrence - // PhanTypeInvalidRightOperandOfBitwiseOp : 1 occurrence - // PhanTypeMismatchArgumentNullable : 1 occurrence - // PhanTypeMismatchArgumentNullableInternal : 1 occurrence // PhanTypeMismatchDimFetch : 1 occurrence - // PhanTypeMismatchProperty : 1 occurrence // PhanTypeMismatchReturnNullable : 1 occurrence // PhanTypeNonVarPassByRef : 1 occurrence // PhanTypeVoidArgument : 1 occurrence @@ -68,14 +53,6 @@ 'src/features/launchpad/launchpad.php' => ['PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'], 'src/features/marketplace-products-updater/class-marketplace-products-updater.php' => ['PhanTypeMismatchDimFetch', 'PhanTypeMismatchReturn'], 'src/features/media/heif-support.php' => ['PhanPluginSimplifyExpressionBool'], - 'src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/view.php' => ['PhanParamTooMany', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturnProbablyReal'], - 'src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php' => ['PhanTypeArraySuspiciousNullable'], - 'src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/article.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable'], - 'src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/articles-list.php' => ['PhanUndeclaredGlobalVariable'], - 'src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/articles-loop.php' => ['PhanUndeclaredGlobalVariable'], - 'src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/view.php' => ['PhanPluginDuplicateExpressionAssignmentOperation', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod'], - 'src/features/newspack-blocks/synced-newspack-blocks/class-newspack-blocks-api.php' => ['PhanParamTooMany', 'PhanTypeMismatchArgument', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanUndeclaredClassMethod', 'PhanUndeclaredFunction', 'PhanUnextractableAnnotationSuffix'], - 'src/features/newspack-blocks/synced-newspack-blocks/class-newspack-blocks.php' => ['PhanDeprecatedProperty', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPluginMixedKeyNoKey', 'PhanPluginRedundantAssignment', 'PhanTypeInvalidLeftOperandOfBitwiseOp', 'PhanTypeInvalidRightOperandOfBitwiseOp', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty', 'PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredConstant', 'PhanUndeclaredFunction'], 'src/features/verbum-comments/class-verbum-comments.php' => ['PhanImpossibleTypeComparison', 'PhanNoopNew', 'PhanParamTooMany', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredFunction'], 'src/features/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-launchpad.php' => ['PhanPluginDuplicateConditionalNullCoalescing'], 'src/features/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-site-migration-migrate-guru-key.php' => ['PhanUndeclaredClassMethod'], diff --git a/projects/packages/jetpack-mu-wpcom/.phan/config.php b/projects/packages/jetpack-mu-wpcom/.phan/config.php index 8680d589c96a7..b69eda7cb1aef 100644 --- a/projects/packages/jetpack-mu-wpcom/.phan/config.php +++ b/projects/packages/jetpack-mu-wpcom/.phan/config.php @@ -32,6 +32,8 @@ // This file breaks analysis, Phan gets lost recursing in trying to figure out some types. // @todo Add type declarations so Phan won't have to do it itself. Or update to a modern less lib. 'src/features/custom-css/custom-css/preprocessors/lessc.inc.php', + // This is synced from the Newspack Blocks repo. + 'src/features/newspack-blocks/synced-newspack-blocks/', ), ) ); diff --git a/projects/packages/jetpack-mu-wpcom/.phpcsignore b/projects/packages/jetpack-mu-wpcom/.phpcsignore new file mode 100644 index 0000000000000..6a0ddf86aeb10 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/.phpcsignore @@ -0,0 +1 @@ +src/features/newspack-blocks/synced-newspack-blocks diff --git a/projects/packages/jetpack-mu-wpcom/bin/sync-newspack-blocks.sh b/projects/packages/jetpack-mu-wpcom/bin/sync-newspack-blocks.sh index 55fda6a5bac10..89a1cf6b9c348 100755 --- a/projects/packages/jetpack-mu-wpcom/bin/sync-newspack-blocks.sh +++ b/projects/packages/jetpack-mu-wpcom/bin/sync-newspack-blocks.sh @@ -14,7 +14,7 @@ fi # pick up value considering that the argument # has the --key=value shape. -key_value=$(echo ${1} | cut -d'=' -f 2) +key_value=$(echo "${1}" | cut -d'=' -f 2) # Set mode depending on first argument if [[ $1 =~ ^--release= ]] then @@ -44,7 +44,7 @@ then echo --branch=master echo "--nodemodules (to use defined in package.json)" echo "--path=/path/to/newspack-blocks" - echo --release=v2.0.0 + echo --release=v4.0.0 echo echo You can find the latest release ID on https://github.com/Automattic/newspack-blocks/releases/latest echo @@ -52,7 +52,6 @@ then fi TARGET=./src/features/newspack-blocks/synced-newspack-blocks -ENTRY=./src/features/newspack-blocks/index.php if [[ ( "$MODE" != "path" ) && ( "$MODE" != "npm" ) ]]; then @@ -62,20 +61,23 @@ then if [[ "$CURRENT_VERSION" == "$NAME" ]]; then echo "The current version $CURRENT_VERSION of the newspack-blocks is synced." - exit 0 + read -rp "Do you want to proceed anyway? (y/N): " proceed + if [[ ! "$proceed" =~ ^[Yy]$ ]]; then + exit 0 + fi fi fi # make a temp directory - TEMP_DIR=`mktemp -d` + TEMP_DIR=$(mktemp -d) CODE=$TEMP_DIR/code # download zip file - echo Downloading $MODE $NAME into $TEMP_DIR - (cd $TEMP_DIR && curl -L --fail -s -O $URL) + echo "Downloading $MODE $NAME into $TEMP_DIR" + (cd "$TEMP_DIR" && curl -L --fail -s -O "$URL") # handle download error - ZIPS=( $TEMP_DIR/*.zip ) + ZIPS=( "$TEMP_DIR"/*.zip ) ZIP=${ZIPS[0]} if [ ! -f "$ZIP" ]; then echo "Tried to download $URL" @@ -90,13 +92,13 @@ then fi # extract zip - echo Extracting into $CODE - mkdir -p $CODE - unzip -q $ZIP -d $CODE + echo "Extracting into $CODE" + mkdir -p "$CODE" + unzip -q "$ZIP" -d "$CODE" # find the main file and use its directory as the root of our source dir - MAIN_FILE=`find $CODE -name "newspack-blocks.php"` - CODE=`dirname $MAIN_FILE` + MAIN_FILE=$(find "$CODE" -name "newspack-blocks.php") + CODE=$(dirname "$MAIN_FILE") # handle unzip error if [ ! -f "$CODE/newspack-blocks.php" ]; then @@ -127,18 +129,22 @@ mkdir -p $TARGET/components mkdir -p $TARGET/shared mkdir -p $TARGET/types -# copy files and directories -NEW_VERSION=v`jq -r .version $CODE/package.json` +# Update Newspack Blocks version number in the package. +NEW_VERSION=v$(jq -r .version "$CODE"/package.json) echo "$NEW_VERSION" > $TARGET/version.txt -cp $CODE/includes/class-newspack-blocks-api.php $TARGET/ -cp $CODE/includes/class-newspack-blocks.php $TARGET/ -cp -R $CODE/src/blocks/homepage-articles $TARGET/blocks/ -cp -R $CODE/src/blocks/carousel $TARGET/blocks/ -cp -R $CODE/src/shared $TARGET/ -cp -R $CODE/src/components $TARGET/ +sed -E -i.bak "s|^define\( 'NEWSPACK_BLOCKS__VERSION', '.*' \);$|define( 'NEWSPACK_BLOCKS__VERSION', '$NEW_VERSION' );|" "$TARGET"/../index.php +rm "$TARGET"/../index.php.bak + +# copy files and directories +cp "$CODE"/includes/class-newspack-blocks-api.php $TARGET/ +cp "$CODE"/includes/class-newspack-blocks.php $TARGET/ +cp -R "$CODE"/src/blocks/homepage-articles $TARGET/blocks/ +cp -R "$CODE"/src/blocks/carousel $TARGET/blocks/ +cp -R "$CODE"/src/shared $TARGET/ +cp -R "$CODE"/src/components $TARGET/ # Get Typescript working by copying the main type defs over. -cp $CODE/src/types/index.d.ts $TARGET/types/ +cp "$CODE"/src/types/index.d.ts $TARGET/types/ # Function types need to be capitalized in our system. We only match " function" # beginning with a space to avoid matching it as a substring. (Not perfect, but # imperfections will be caught by CI with failing tsc, etc.) @@ -146,12 +152,61 @@ sed "${sedi[@]}" -e "s| function| Function|g" "$TARGET/types/index.d.ts" # Note: I would have used eslint-nibble, but it doesn't support autofixing via the CLI. echo "Changing JS textdomain to match jetpack-mu-wpcom..." -pnpm --package=eslint@8.57.0 dlx eslint --no-ignore --rule '"@wordpress/i18n-text-domain":["error",{"allowedTextDomain":"jetpack-mu-wpcom"}]' --fix $TARGET > /dev/null +BASE=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../../../.. && pwd) +FULLTARGET="$PWD/$TARGET" + +# Add a temporary single-rule eslint.config.mjs file. +cat > "$TARGET/eslint.config.mjs" < ( { ...block, rules: {} } ) ), + // Enable just this one rule. + { + rules: { + "@wordpress/i18n-text-domain": [ "error", { allowedTextDomain: "jetpack-mu-wpcom" } ], + } + }, +]; +EOF +( cd "$BASE" && pnpm run lint-file --no-inline-config --no-ignore --fix "$FULLTARGET" ) +rm "$TARGET/eslint.config.mjs" echo "Changing JS translation function call to avoid bad minification..." pnpm --package=jscodeshift dlx jscodeshift -t ./bin/sync-newspack-blocks-formatter.js --extensions=js $TARGET +# Add temporary PHPCS config file. +PHPCSSTANDARDFILE="$TARGET/phpcs.tmp.xml" +cat > "$PHPCSSTANDARDFILE" < + + + + + + + + + + + + + + + + +EOF echo "Changing PHP textdomain to match jetpack-mu-wpcom..." -../../../vendor/bin/phpcbf --standard=./.phpcs.dir.xml --filter=../../../vendor/automattic/jetpack-phpcs-filter/src/PhpcsFilter.php --runtime-set jetpack-filter-no-ignore -q $TARGET - +"$BASE"/vendor/bin/phpcbf --standard="$PHPCSSTANDARDFILE" "$TARGET" +rm "$PHPCSSTANDARDFILE" + +# Add textdomain to block.json +echo "Adding textdomain to all block.json files..." +for block_json_file in "$TARGET"/blocks/*/block.json; do + TMPFILE=$(mktemp) + jq --tab '. += {"textdomain": "jetpack-mu-wpcom"}' "$block_json_file" > "$TMPFILE" + mv "$TMPFILE" "$block_json_file" +done echo Sync done. diff --git a/projects/packages/jetpack-mu-wpcom/changelog/update-synced_newspack_blocks b/projects/packages/jetpack-mu-wpcom/changelog/update-synced_newspack_blocks new file mode 100644 index 0000000000000..15206e680281d --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/update-synced_newspack_blocks @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Newspack Blocks: Updated to version 4.5.2. diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/README.md b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/README.md index a4cc12220990b..b712c4428c0cd 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/README.md +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/README.md @@ -1,56 +1,56 @@ # Newspack Blocks -Some of the Newspack blocks were added to this repository in order to make it available to other parts of the FSE plugin, such as Starter Page Templates where these blocks will be used. +Some of the Newspack blocks were added to this repository so they would be available to other parts of the FSE plugin where these blocks will be used, such as Starter Page Templates. ## Block Posts Block This block allows you to list your posts in various layouts and filter them by criteria like category, tag or author. -It originally comes from the [Newspack Blocks collection](https://github.com/automattic/newspack-blocks) and the block is still being developed there. +It originally comes from the [Newspack Blocks collection](https://github.com/automattic/newspack-blocks) and the block is still being developed there as the `homepage-articles` block. -## Post Carousel Block +## Carousel Block -This block allows you to create a carousel of post's featured images and filter them by criteria like category, tag or author. +This block allows you to create a carousel of post featured images and filter them by criteria (e.g. category, tag or author). -It originally comes from the [Newspack Blocks collection](https://github.com/automattic/newspack-blocks) and the block is still being developed there. +It originally comes from the [Newspack Blocks collection](https://github.com/automattic/newspack-blocks) and the block is still being developed there as the `carousel` block. ## Structure ``` index.php — main entry file, registers the blocks on backend -blog-posts-block-editor.min.js — assets for the blog-posts-block editor -blog-posts-block-view.min.js — assets for the blog-posts-block rendered on frontend -carousel-block-editor.min.js — assets for the carousel-block editor -carousel-block-view.min.js — assets for the carousel-block rendered on frontend -synced-newspack-blocks/** — source code synced from the Newspack Blocks repository, not tracked in Jetpack git repo +blog-posts/ — assets for the blog-posts block frontend and editor +carousel/ — assets for the carousel block frontend and editor +synced-newspack-blocks/ — source code synced from the Newspack Blocks repository ``` -`blog-posts-block-editor.min.js`, `blog-posts-block-view.min.js`, `carousel-block-editor.min.js`, `carousel-block-view.min.js` and `index.php` are files written in order to bridge the parent plugin with the Newspack Blocks. It changes the block names to an `a8c/` namespace and does things like registering REST fields or styles and scripts. In these files we are free to do all those changes because they are not shared with Newspack and only live here in this repository. +Other than the `synced-newspack-blocks` directory, the above are files written in order to bridge the parent plugin with Newspack Blocks. They change the block names to an `a8c/` namespace and register REST fields, styles, and scripts. In these files we are free to make changes because they are not shared with Newspack and only live here in this repository. + ### Synchronizing the code -You can see that `synced-newspack-blocks` is being synced with the Newspack Blocks repository. Please make all improvements and additions on the Newspack side. Please don't make any direct changes to files in this directory as the next synchronization will overwrite them. Synced files are not being tracked in git and they are always downloaded fresh using the sync script explained further in this document. +The `synced-newspack-blocks` is synced with the Newspack Blocks repository. *Please make all improvements and additions upstream in the Newspack Blocks repo. Do not make any direct changes to files in this directory, as the next synchronization will overwrite them.* -Once your changes land on the Newspack side, coordinate with the team (over issues/PRs) to [make a new release](https://github.com/Automattic/newspack-blocks/releases) and once you have the release ID, you can pull the code into here. +Once your changes land in the Newspack Blocks repo, coordinate with the team (over issues/PRs) to [make a new release](https://github.com/Automattic/newspack-blocks/releases). Once you have the release ID (e.g. `v4.0.0`, you start a sync. -While being in `projects/packages/jetpack-mu-wpcom` directory, you can run: +While in the `projects/packages/jetpack-mu-wpcom` directory, run the following: ``` pnpm run sync:newspack-blocks --release= ``` -This will pull the code from the release and integrate it into this repository. Please: - 1. Review changes - 2. Keep the PHPCS config if still necessary - 3. Ensure [htmlentities uses ENT_COMPAT](https://github.com/Automattic/jetpack/pull/38873/commits/16f57e6f01b6eed98a19cd0299261ce5ac075b8e) - 4. Update the phan baseline with `jetpack phan --update-baseline packages/jetpack-mu-wpcom` - 4. Update `NEWSPACK_BLOCKS__VERSION` in [index.php](./index.php) - 5. Ensure that the blocks `block.json` has `"textdomain": "jetpack-mu-wpcom"` - 6. Commit. +This will pull the code from the release into this repository and perform the following tasks: +* Copies TypeScript types into place. +* Changes JS and PHP textdomain refs to `jetpack-mu-wpcom`. +* Adjusts JS translation function calls to avoid minification issues. +* Checks for potential places where `ENT_COMPAT` should be used. + +Once the script has completed: +1. Ensure the changes shown match the changes in the release. +2. Commit. ### Local development -Sometimes, probably, you will need to sync the NHA code straight in your local environment. It means you will get working on both projects at the same time. For this situation, you'd like to reference the code source through the `path` bin script argument. +Sometimes, probably, you will need to sync the code straight in your local environment. It means you will get working on both projects at the same time. For this situation, you'd like to reference the code source through the `path` bin script argument. ``` pnpm run sync:newspack-blocks --path=/Absolute/path/of/newspack-blocks/ diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/index.php b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/index.php index 83bbe4855c5d9..f5e9e3b03bdbe 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/index.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/index.php @@ -11,7 +11,7 @@ define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', Jetpack_Mu_Wpcom::BASE_DIR . 'build/' ); define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); -define( 'NEWSPACK_BLOCKS__VERSION', '4.0.1' ); +define( 'NEWSPACK_BLOCKS__VERSION', 'v4.5.2' ); require_once __DIR__ . '/../../utils.php'; require_once __DIR__ . '/synced-newspack-blocks/class-newspack-blocks.php'; diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/.phpcs.dir.xml b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/.phpcs.dir.xml deleted file mode 100644 index c49f51983d12d..0000000000000 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/.phpcs.dir.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/create-swiper.js b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/create-swiper.js index 151b9a0000201..661d61244b2ae 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/create-swiper.js +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/create-swiper.js @@ -14,8 +14,8 @@ const autoplayClassName = 'wp-block-newspack-blocks-carousel__autoplay-playing'; /** * A helper for IE11-compatible iteration over NodeList elements. * - * @param {object} nodeList - List of nodes to be iterated over. - * @param {Function} cb - Invoked for each iteratee. + * @param {Object} nodeList List of nodes to be iterated over. + * @param {Function} cb Invoked for each iteratee. */ function forEachNode( nodeList, cb ) { /** @@ -29,7 +29,7 @@ function forEachNode( nodeList, cb ) { /** * Modifies attributes on slide HTML to make it accessible. * - * @param {HTMLElement} slide - Slide DOM element + * @param {HTMLElement} slide Slide DOM element */ function activateSlide( slide ) { if ( slide ) { @@ -41,7 +41,7 @@ function activateSlide( slide ) { /** * Modifies attributes on slide HTML to make it accessible. * - * @param {HTMLElement} slide - Slide DOM element + * @param {HTMLElement} slide Slide DOM element */ function deactivateSlide( slide ) { if ( slide ) { @@ -54,15 +54,15 @@ function deactivateSlide( slide ) { * Creates a Swiper instance with predefined config used by the Articles * Carousel block in both front-end and editor. * - * @param {object} els - Swiper elements - * @param {Element} els.block - Block element - * @param {Element} els.container - Swiper container element - * @param {Element} els.next - Next button element - * @param {Element} els.prev - Previous button element - * @param {Element} els.play - Play button element - * @param {Element} els.pause - Pause button element - * @param {Element} els.pagination - Pagination element - * @param {Object} config - Swiper config + * @param {Object} els Swiper elements + * @param {Element} els.block Block element + * @param {Element} els.container Swiper container element + * @param {Element} els.next Next button element + * @param {Element} els.prev Previous button element + * @param {Element} els.play Play button element + * @param {Element} els.pause Pause button element + * @param {Element} els.pagination Pagination element + * @param {Object} config Swiper config * @return {Object} Swiper instance */ export default function createSwiper( els, config = {} ) { @@ -161,13 +161,13 @@ export default function createSwiper( els, config = {} ) { escapeHTML( `${ currentSlide.innerText }, ${ - alt - ? /* translators: the title of the image. */ sprintf( - __( 'Image: %s, ', 'jetpack-mu-wpcom' ), - alt - ) - : '' - } + alt + ? /* translators: the title of the image. */ sprintf( + __( 'Image: %s, ', 'jetpack-mu-wpcom' ), + alt + ) + : '' +} ${ slideInfo }` ), 'assertive' diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/edit.js b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/edit.js index c4a066ae61f1f..62a738282263b 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/edit.js +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/edit.js @@ -3,12 +3,17 @@ /** * External dependencies */ +import { isEqual } from 'lodash'; +import classnames from 'classnames'; /** * WordPress dependencies */ +import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; // eslint-disable-next-line @wordpress/no-unsafe-wp-apis +import { dateI18n, __experimentalGetSettings } from '@wordpress/date'; +import { Component, createRef, Fragment, RawHTML } from '@wordpress/element'; import { BaseControl, Button, @@ -20,20 +25,16 @@ import { Spinner, ToggleControl, } from '@wordpress/components'; -import { compose } from '@wordpress/compose'; import { withDispatch, withSelect } from '@wordpress/data'; -import { dateI18n, __experimentalGetSettings } from '@wordpress/date'; -import { Component, createRef, Fragment, RawHTML } from '@wordpress/element'; +import { compose } from '@wordpress/compose'; import { decodeEntities } from '@wordpress/html-entities'; -import { __ } from '@wordpress/i18n'; -import classnames from 'classnames'; -import { isEqual } from 'lodash'; /** * Internal dependencies */ -import { PostTypesPanel, PostStatusesPanel } from '../../components/editor-panels'; import QueryControls from '../../components/query-controls'; +import { PostTypesPanel, PostStatusesPanel } from '../../components/editor-panels'; +import createSwiper from './create-swiper'; import { formatAvatars, formatByline, @@ -43,7 +44,6 @@ import { } from '../../shared/js/utils'; // Use same posts store as Homepage Posts block. import { postsBlockSelector, postsBlockDispatch, shouldReflow } from '../homepage-articles/utils'; -import createSwiper from './create-swiper'; // Max number of slides that can be shown at once. const MAX_NUMBER_OF_SLIDES = 6; @@ -242,9 +242,7 @@ class Edit extends Component {
{ hasNoPosts && ( -
- { __( 'Sorry, no posts were found.', 'jetpack-mu-wpcom' ) } -
+
{ __( 'Sorry, no posts were found.', 'jetpack-mu-wpcom' ) }
) } { ( ! this.state.swiperInitialized || ! latestPosts ) && ( @@ -302,9 +300,7 @@ class Edit extends Component { ) } { showCategory && ( ! post.newspack_post_sponsors || - post.newspack_sponsors_show_categories ) && ( - { decodeEntities( post.newspack_category_info ) } - ) } + post.newspack_sponsors_show_categories ) && ( { decodeEntities( post.newspack_category_info ) } ) }
) } { showTitle && ( @@ -337,15 +333,14 @@ class Edit extends Component { { dateI18n( dateFormat, post.date ) } ) } - { ( showCaption || showCredit ) && - post.newspack_featured_image_caption && ( -
- ) } + { ( showCaption || showCredit ) && post.newspack_featured_image_caption && ( +
+ ) }
) } @@ -433,10 +428,9 @@ class Edit extends Component { help={ 'cover' === imageFit ? __( - 'The image will fill the entire slide and will be cropped if necessary.', - 'jetpack-mu-wpcom' - ) - : __( + 'The image will fill the entire slide and will be cropped if necessary.', + 'jetpack-mu-wpcom' + ) : __( 'The image will be resized to fit inside the slide without being cropped.', 'jetpack-mu-wpcom', 0 @@ -470,10 +464,7 @@ class Edit extends Component { { setAttributes( { hideControls: _hideControls } ); diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/index.js b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/index.js index 37b562d71a759..796eacfc27460 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/index.js +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/index.js @@ -36,11 +36,7 @@ export const settings = { foreground: '#36f', }, category: 'newspack', - keywords: [ - __( 'posts', 'jetpack-mu-wpcom' ), - __( 'slideshow', 'jetpack-mu-wpcom' ), - __( 'carousel', 'jetpack-mu-wpcom' ), - ], + keywords: [ __( 'posts', 'jetpack-mu-wpcom' ), __( 'slideshow', 'jetpack-mu-wpcom' ), __( 'carousel', 'jetpack-mu-wpcom' ) ], description: __( 'A carousel of posts.', 'jetpack-mu-wpcom' ), attributes: { className: { diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/view.php b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/view.php index 87000f1e301fd..3d32080ba2eb2 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/view.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/carousel/view.php @@ -19,7 +19,7 @@ function newspack_blocks_render_block_carousel( $attributes ) { // This will let the FSE plugin know we need CSS/JS now. do_action( 'newspack_blocks_render_post_carousel' ); - ++$newspack_blocks_carousel_id; + $newspack_blocks_carousel_id++; $autoplay = isset( $attributes['autoplay'] ) ? $attributes['autoplay'] : false; $delay = isset( $attributes['delay'] ) ? absint( $attributes['delay'] ) : 3; $authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array(); @@ -47,10 +47,10 @@ function newspack_blocks_render_block_carousel( $attributes ) { $authors = Newspack_Blocks::prepare_authors(); $newspack_blocks_post_id[ $post_id ] = true; - $article_classes = array( + $article_classes = [ 'post-has-image', 'swiper-slide', - ); + ]; // Add classes based on the post's assigned categories and tags. $article_classes[] = Newspack_Blocks::get_term_classes( $post_id ); @@ -58,7 +58,7 @@ function newspack_blocks_render_block_carousel( $attributes ) { // Get sponsors for this post. $sponsors = Newspack_Blocks::get_all_sponsors( $post_id ); - ++$counter; + $counter++; $has_featured_image = has_post_thumbnail(); $post_type = get_post_type(); $post_link = Newspack_Blocks::get_post_link( $post_id ); @@ -72,7 +72,7 @@ function newspack_blocks_render_block_carousel( $attributes ) { $show_credit = $attributes['showCredit']; // Validate the value of the "image fit" attribute. - $image_fits = array( 'cover', 'contain' ); + $image_fits = [ 'cover', 'contain' ]; $image_fit = in_array( $attributes['imageFit'], $image_fits, true ) ? $attributes['imageFit'] : $image_fits[0]; ?> @@ -129,7 +129,7 @@ function newspack_blocks_render_block_carousel( $attributes ) { ) } { RichText.isEmpty( sectionHeader ) ? ( @@ -206,11 +207,16 @@ class Edit extends Component< HomepageArticlesProps > { { post.meta.newspack_post_subtitle || '' } ) } - { showExcerpt && ( + { showExcerpt && ! showFullContent && ( { post.excerpt.rendered } ) } + { ! showExcerpt && showFullContent && ( + + { post.full_content } + + ) } { showReadMore && post.post_link && ( { readMoreLabel } @@ -280,7 +286,9 @@ class Edit extends Component< HomepageArticlesProps > { mobileStack, minHeight, moreButton, + infiniteScroll, showExcerpt, + showFullContent, showReadMore, readMoreLabel, excerptLength, @@ -434,11 +442,20 @@ class Edit extends Component< HomepageArticlesProps > { ) : ( ! specificMode && ( - setAttributes( { moreButton: ! moreButton } ) } - /> + <> + setAttributes( { moreButton: ! moreButton } ) } + /> + { moreButton && ( + setAttributes( { infiniteScroll: ! infiniteScroll } ) } + /> + ) } + ) ) } { setAttributes( { showExcerpt: ! showExcerpt } ) } + onChange={ () => { + setAttributes({ + showExcerpt: !showExcerpt, + showFullContent: showFullContent ? false : showFullContent + }) + } } /> { showExcerpt && ( - setAttributes( { excerptLength: value } ) } - min={ 10 } - max={ 100 } - /> + + setAttributes( { excerptLength: value } ) } + min={ 10 } + max={ 100 } + /> + ) } - setAttributes( { showReadMore: ! showReadMore } ) } - /> + + { + setAttributes({ + showFullContent: !showFullContent, + showExcerpt: showExcerpt ? false : showExcerpt + }) + } } + /> + + + setAttributes( { showReadMore: ! showReadMore } ) } + /> + { showReadMore && ( { yield put( { type: 'DISABLE_UI' } ); - // Ensure innerBlocks are populated for widget area blocks. - // See https://github.com/WordPress/gutenberg/issues/32607#issuecomment-890728216. - const blocks = getBlocks().map( block => { - const innerBlocks = select( 'core/block-editor' ).getBlocks( block.clientId ); - return { - ...block, - innerBlocks, - }; - } ); + const blocks = recursivelyGetBlocks( getBlocks ); const blockQueries = getBlockQueries( blocks, blockNames ); diff --git a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/article.php b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/article.php index 2a0f2e109f2e0..eb74101785a04 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/article.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/blocks/homepage-articles/templates/article.php @@ -7,7 +7,7 @@ */ call_user_func( - function ( $data ) { + function( $data ) { $attributes = apply_filters( 'newspack_blocks_homepage_posts_block_attributes', $data['attributes'] ); $authors = Newspack_Blocks::prepare_authors(); $classes = array(); @@ -42,14 +42,14 @@ function ( $data ) { // This global will be used by the newspack_blocks_filter_hpb_srcset filter. global $newspack_blocks_hpb_rendering_context; - $newspack_blocks_hpb_rendering_context = array( 'attrs' => $attributes ); + $newspack_blocks_hpb_rendering_context = [ 'attrs' => $attributes ]; // Disable lazy loading by using an arbitraty `loading` attribute other than `lazy`. // Empty string or `false` would still result in `lazy`. if ( $attributes['disableImageLazyLoad'] ) { $thumbnail_args['loading'] = 'none'; } - if ( $attributes['fetchPriority'] && in_array( $attributes['fetchPriority'], array( 'high', 'low', 'auto' ), true ) ) { + if ( $attributes['fetchPriority'] && in_array( $attributes['fetchPriority'], [ 'high', 'low', 'auto' ], true ) ) { $thumbnail_args['fetchpriority'] = $attributes['fetchPriority']; } @@ -147,9 +147,12 @@ class="" @@ -162,7 +165,7 @@ class="" -