woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection/frontend.tsx

186 lines
4.9 KiB
TypeScript
Raw Normal View History

Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
/**
* External dependencies
*/
import {
store,
navigate,
prefetch,
getElement,
getContext,
} from '@woocommerce/interactivity';
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
/**
* Internal dependencies
*/
import './style.scss';
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
export type ProductCollectionStoreContext = {
isPrefetchNextOrPreviousLink: boolean;
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
animation: 'start' | 'finish';
Improve Accessibility in Product Collection Navigation (#44599) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Enhance accessibility for product collection navigation This commit introduces several improvements to enhance accessibility and user experience. Specifically, it adds new context properties to manage accessibility messages during the navigation process, including messages for loading and when a page has loaded. These changes ensure that screen reader users receive appropriate feedback during navigation. Changes made: - Added `accessibilityMessage`, `accessibilityLoadingMessage`, and `accessibilityLoadedMessage` properties to the `ProductCollectionStoreContext`. These properties store messages to be announced by screen readers during different stages of page navigation. - Implemented logic in the product collection store to update the `accessibilityMessage` during the start of navigation (showing a loading message) and upon completion (showing a loaded message). - Utilized a technique to ensure that consecutive identical messages are still announced by screen readers, by appending a no-break space to the message if it is the same as the previous one. This follows a pattern similar to the `@wordpress/a11y` package. - In `ProductCollection.php`, enhanced the block's HTML output to include these new accessibility messages and integrated them with the existing interactive data attributes. This ensures that the front-end components are fully prepared to handle these accessibility enhancements. - Added a new `div` with `class="screen-reader-text"` and `aria-live="polite"` attributes, which dynamically displays the accessibility message based on the navigation state. This div complements the visual pagination animation with an accessibility-focused mechanism for announcing the page load states to screen reader users. By addressing accessibility considerations with these enhancements, we're making Product Collection navigation more inclusive and user-friendly for all users. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-19 06:05:14 +00:00
accessibilityMessage: string;
accessibilityLoadingMessage: string;
accessibilityLoadedMessage: string;
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
};
const isValidLink = ( ref: HTMLAnchorElement ) =>
ref &&
ref instanceof window.HTMLAnchorElement &&
ref.href &&
( ! ref.target || ref.target === '_self' ) &&
ref.origin === window.location.origin;
const isValidEvent = ( event: MouseEvent ) =>
event.button === 0 && // Left clicks only.
! event.metaKey && // Open in new tab (Mac).
! event.ctrlKey && // Open in new tab (Windows).
! event.altKey && // Download.
! event.shiftKey &&
! event.defaultPrevented;
Product Collection: Disable client side navigation if blocks incompatible with Interactivity API are detected (#45435) * Add dummy Force Page Reload control to Inspector Advanced Control * Add enhancedPagination attribute that decides if client side navigation is enabled * Consume the enhancedPagination attribute * Force client side navigation when incompatible blocks detected * Dummy util to detect incompatible blocks * Detect incompatible blocks in the Editor * Switch to WordPress Interactivity package in Product Collection * Add initial implementation of the incompatible blocks detection in frontend * Remove leftover * Revert to using internal version of interactivity API * There's no Interactivity store config available in the internal Interactivity implementation so remove it * Disable client side navigation if the incompatible block is detected * Add default attribute value * Switch from enmhancedPagination attribute to forcePageReload * Fixed some misclicked line order change * Switch from enhancedPagination to forcePageReload in PHP code * Apply the correct filter * Fix the incorrect condition to detect incompatible block * Initial implementation of orange dot to bring attention * Cleanup * Remove the orange dot indicator * Refactor checking for unsupported blocks * Add changelog * Fix PHP lint errors * Bring back empty line at the end of pnpm-lock * Bring pnpm-lock.yaml file to original state * Fix incorrect function call * Add visibility description to function * Switch private method to public * More linted fixes
2024-03-18 07:24:03 +00:00
const forcePageReload = ( href: string ) => {
window.location.assign( href );
// It's function called in generator expecting asyncFunc return.
// eslint-disable-next-line @typescript-eslint/no-empty-function
return new Promise( () => {} );
};
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
/**
* Ensures the visibility of the first product in the collection.
* Scrolls the page to the first product if it's not in the viewport.
*
* @param {string} wcNavigationId Unique ID for each Product Collection block on page/post.
*/
function scrollToFirstProductIfNotVisible( wcNavigationId?: string ) {
if ( ! wcNavigationId ) {
return;
}
const productSelector = `[data-wc-navigation-id=${ wcNavigationId }] .wc-block-product-template .wc-block-product`;
const product = document.querySelector( productSelector );
if ( product ) {
const rect = product.getBoundingClientRect();
const isVisible =
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
( window.innerHeight ||
document.documentElement.clientHeight ) &&
rect.right <=
( window.innerWidth || document.documentElement.clientWidth );
// If the product is not visible, scroll to it.
if ( ! isVisible ) {
product.scrollIntoView( {
behavior: 'smooth',
block: 'start',
} );
}
}
}
const productCollectionStore = {
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
state: {
get startAnimation() {
return (
getContext< ProductCollectionStoreContext >().animation ===
'start'
);
},
get finishAnimation() {
return (
getContext< ProductCollectionStoreContext >().animation ===
'finish'
);
},
},
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
actions: {
*navigate( event: MouseEvent ) {
const ctx = getContext< ProductCollectionStoreContext >();
const { ref } = getElement();
const wcNavigationId = (
ref?.closest( '[data-wc-navigation-id]' ) as HTMLDivElement
)?.dataset?.wcNavigationId;
Product Collection: Disable client side navigation if blocks incompatible with Interactivity API are detected (#45435) * Add dummy Force Page Reload control to Inspector Advanced Control * Add enhancedPagination attribute that decides if client side navigation is enabled * Consume the enhancedPagination attribute * Force client side navigation when incompatible blocks detected * Dummy util to detect incompatible blocks * Detect incompatible blocks in the Editor * Switch to WordPress Interactivity package in Product Collection * Add initial implementation of the incompatible blocks detection in frontend * Remove leftover * Revert to using internal version of interactivity API * There's no Interactivity store config available in the internal Interactivity implementation so remove it * Disable client side navigation if the incompatible block is detected * Add default attribute value * Switch from enmhancedPagination attribute to forcePageReload * Fixed some misclicked line order change * Switch from enhancedPagination to forcePageReload in PHP code * Apply the correct filter * Fix the incorrect condition to detect incompatible block * Initial implementation of orange dot to bring attention * Cleanup * Remove the orange dot indicator * Refactor checking for unsupported blocks * Add changelog * Fix PHP lint errors * Bring back empty line at the end of pnpm-lock * Bring pnpm-lock.yaml file to original state * Fix incorrect function call * Add visibility description to function * Switch private method to public * More linted fixes
2024-03-18 07:24:03 +00:00
const isDisabled = (
ref?.closest( '[data-wc-navigation-id]' ) as HTMLDivElement
)?.dataset.wcNavigationDisabled;
if ( isDisabled ) {
yield forcePageReload( ref.href );
}
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
if ( isValidLink( ref ) && isValidEvent( event ) ) {
event.preventDefault();
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
// Don't start animation if it doesn't take long to navigate.
const timeout = setTimeout( () => {
Improve Accessibility in Product Collection Navigation (#44599) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Enhance accessibility for product collection navigation This commit introduces several improvements to enhance accessibility and user experience. Specifically, it adds new context properties to manage accessibility messages during the navigation process, including messages for loading and when a page has loaded. These changes ensure that screen reader users receive appropriate feedback during navigation. Changes made: - Added `accessibilityMessage`, `accessibilityLoadingMessage`, and `accessibilityLoadedMessage` properties to the `ProductCollectionStoreContext`. These properties store messages to be announced by screen readers during different stages of page navigation. - Implemented logic in the product collection store to update the `accessibilityMessage` during the start of navigation (showing a loading message) and upon completion (showing a loaded message). - Utilized a technique to ensure that consecutive identical messages are still announced by screen readers, by appending a no-break space to the message if it is the same as the previous one. This follows a pattern similar to the `@wordpress/a11y` package. - In `ProductCollection.php`, enhanced the block's HTML output to include these new accessibility messages and integrated them with the existing interactive data attributes. This ensures that the front-end components are fully prepared to handle these accessibility enhancements. - Added a new `div` with `class="screen-reader-text"` and `aria-live="polite"` attributes, which dynamically displays the accessibility message based on the navigation state. This div complements the visual pagination animation with an accessibility-focused mechanism for announcing the page load states to screen reader users. By addressing accessibility considerations with these enhancements, we're making Product Collection navigation more inclusive and user-friendly for all users. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-19 06:05:14 +00:00
ctx.accessibilityMessage = ctx.accessibilityLoadingMessage;
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
ctx.animation = 'start';
}, 400 );
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
yield navigate( ref.href );
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
// Clear the timeout if the navigation is fast.
clearTimeout( timeout );
Improve Accessibility in Product Collection Navigation (#44599) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Enhance accessibility for product collection navigation This commit introduces several improvements to enhance accessibility and user experience. Specifically, it adds new context properties to manage accessibility messages during the navigation process, including messages for loading and when a page has loaded. These changes ensure that screen reader users receive appropriate feedback during navigation. Changes made: - Added `accessibilityMessage`, `accessibilityLoadingMessage`, and `accessibilityLoadedMessage` properties to the `ProductCollectionStoreContext`. These properties store messages to be announced by screen readers during different stages of page navigation. - Implemented logic in the product collection store to update the `accessibilityMessage` during the start of navigation (showing a loading message) and upon completion (showing a loaded message). - Utilized a technique to ensure that consecutive identical messages are still announced by screen readers, by appending a no-break space to the message if it is the same as the previous one. This follows a pattern similar to the `@wordpress/a11y` package. - In `ProductCollection.php`, enhanced the block's HTML output to include these new accessibility messages and integrated them with the existing interactive data attributes. This ensures that the front-end components are fully prepared to handle these accessibility enhancements. - Added a new `div` with `class="screen-reader-text"` and `aria-live="polite"` attributes, which dynamically displays the accessibility message based on the navigation state. This div complements the visual pagination animation with an accessibility-focused mechanism for announcing the page load states to screen reader users. By addressing accessibility considerations with these enhancements, we're making Product Collection navigation more inclusive and user-friendly for all users. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-19 06:05:14 +00:00
// Announce that the page has been loaded. If the message is the
// same, we use a no-break space similar to the @wordpress/a11y
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
ctx.accessibilityMessage =
ctx.accessibilityLoadedMessage +
( ctx.accessibilityMessage ===
ctx.accessibilityLoadedMessage
? '\u00A0'
: '' );
Product Collection: Add loading indicator for client-side pagination (#44571) * Add animation for client-side pagination This includes: - Addition of animation state management in the frontend file to control the visual transition between pagination states. - Introduction of new SCSS rules for the start and finish animations, ensuring a seamless and visually appealing pagination experience. - Modification of the PHP logic to inject necessary HTML for the animation to be applied. These updates aim to provide a more engaging and responsive interface for users navigating through product collection. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Allow user clicks under product collection's loading animation This commit enhances the user experience of the loading animation for the product collection block. Changes include: - Specifying `transform-origin: 0% 0%;` directly within the block's initial style to indicate the animation should start from the left - Adding `pointer-events: none;` to allow user interactions with elements underneath the loading animation, thus improving usability by not blocking clicks. Additionally, redundant `transform-origin` properties were removed from the `@keyframes` declaration to clean up the code and avoid unnecessary repetition. This simplification contributes to both the maintainability and readability of the stylesheet. * Fix linting errors in SCSS file --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-16 10:13:58 +00:00
ctx.animation = 'finish';
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
ctx.isPrefetchNextOrPreviousLink = !! ref.href;
scrollToFirstProductIfNotVisible( wcNavigationId );
}
},
/**
* We prefetch the next or previous button page on hover.
* Optimizes user experience by preloading content for faster access.
*/
*prefetchOnHover() {
const { ref } = getElement();
Product Collection: Disable client side navigation if blocks incompatible with Interactivity API are detected (#45435) * Add dummy Force Page Reload control to Inspector Advanced Control * Add enhancedPagination attribute that decides if client side navigation is enabled * Consume the enhancedPagination attribute * Force client side navigation when incompatible blocks detected * Dummy util to detect incompatible blocks * Detect incompatible blocks in the Editor * Switch to WordPress Interactivity package in Product Collection * Add initial implementation of the incompatible blocks detection in frontend * Remove leftover * Revert to using internal version of interactivity API * There's no Interactivity store config available in the internal Interactivity implementation so remove it * Disable client side navigation if the incompatible block is detected * Add default attribute value * Switch from enmhancedPagination attribute to forcePageReload * Fixed some misclicked line order change * Switch from enhancedPagination to forcePageReload in PHP code * Apply the correct filter * Fix the incorrect condition to detect incompatible block * Initial implementation of orange dot to bring attention * Cleanup * Remove the orange dot indicator * Refactor checking for unsupported blocks * Add changelog * Fix PHP lint errors * Bring back empty line at the end of pnpm-lock * Bring pnpm-lock.yaml file to original state * Fix incorrect function call * Add visibility description to function * Switch private method to public * More linted fixes
2024-03-18 07:24:03 +00:00
const isDisabled = (
ref?.closest( '[data-wc-navigation-id]' ) as HTMLDivElement
)?.dataset.wcNavigationDisabled;
if ( isDisabled ) {
return;
}
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
if ( isValidLink( ref ) ) {
yield prefetch( ref.href );
}
},
},
callbacks: {
/**
* Prefetches content for next or previous links after initial user interaction.
* Reduces perceived load times for subsequent page navigations.
*/
*prefetch() {
const { ref } = getElement();
Product Collection: Disable client side navigation if blocks incompatible with Interactivity API are detected (#45435) * Add dummy Force Page Reload control to Inspector Advanced Control * Add enhancedPagination attribute that decides if client side navigation is enabled * Consume the enhancedPagination attribute * Force client side navigation when incompatible blocks detected * Dummy util to detect incompatible blocks * Detect incompatible blocks in the Editor * Switch to WordPress Interactivity package in Product Collection * Add initial implementation of the incompatible blocks detection in frontend * Remove leftover * Revert to using internal version of interactivity API * There's no Interactivity store config available in the internal Interactivity implementation so remove it * Disable client side navigation if the incompatible block is detected * Add default attribute value * Switch from enmhancedPagination attribute to forcePageReload * Fixed some misclicked line order change * Switch from enhancedPagination to forcePageReload in PHP code * Apply the correct filter * Fix the incorrect condition to detect incompatible block * Initial implementation of orange dot to bring attention * Cleanup * Remove the orange dot indicator * Refactor checking for unsupported blocks * Add changelog * Fix PHP lint errors * Bring back empty line at the end of pnpm-lock * Bring pnpm-lock.yaml file to original state * Fix incorrect function call * Add visibility description to function * Switch private method to public * More linted fixes
2024-03-18 07:24:03 +00:00
const isDisabled = (
ref?.closest( '[data-wc-navigation-id]' ) as HTMLDivElement
)?.dataset.wcNavigationDisabled;
if ( isDisabled ) {
return;
}
const context = getContext< ProductCollectionStoreContext >();
Product Collection: Return to top after page change (#43817) * Initial working version * Update scrolling behavior in product collection block frontend This commit updates the scrolling behavior in the product collection block's frontend script. Previously, the code focused on the first anchor or button within a product collection block. This approach was taken to maintain accessibility and ensure that the focused element was scrolled into view. However, this behavior has been changed to improve the user experience. The updated code now directly scrolls to the first product in the collection. This is achieved by selecting the product using a new selector that targets the `.wc-block-product` class within the `.wc-block-product-template` of the specified `data-wc-navigation-id`. Once the product is selected, the `scrollIntoView` method is used with smooth behavior and start block alignment, offering a more visually appealing scroll effect. This change enhances the user experience by smoothly directing attention to the beginning of the product collection, making it easier for users to browse products. * Remove code related to animation * Fix the issue related to pagination block rendering - I have improved the code by breaking it into smaller functions - Added unique `data-wc-key` to each anchor tag * Enhance Product Collection Block with Interactive Prefetching * Refine Prefetch Logic & other improvements This commit further refines the prefetch logic and interactivity in the Product Collection block. It focuses on enhancing code clarity and improving the prefetch behavior based on user interactions. Key changes include: 1. Renamed 'isPrefetchNextAndPreviousLink' to 'isPrefetchNextOrPreviousLink' in ProductCollectionStoreContext for better readability and accuracy. 2. Modified the scrollToFirstProductIfNotVisible function to accept a wcNavigationId as a parameter instead of a reference 3. Introduced checks for the existence of wcNavigationId in scrollToFirstProductIfNotVisible to prevent unnecessary executions. 4. Updated comments throughout frontend.tsx for enhanced clarity, explaining the prefetch logic and its triggers in detail. 5. Adjusted the logic in the navigate and prefetch functions to align with the new context structure and prefetch strategy. 6. In ProductCollection.php, updated data attributes to align with the revised prefetch strategy. 7. Refined the attribute setting in process_pagination_links function to correctly implement the updated interactivity and prefetch logic. These changes aim to optimize the prefetch functionality, reduce unnecessary prefetching on initial page load, and ensure a smoother and more efficient navigation experience within the Product Collection block. * Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce * Improve comments * Use wp_json_encode for data-wc-interactive attribute This commit updates the `ProductCollection` class to use `wp_json_encode` for setting the `data-wc-interactive` attribute value. Previously, the attribute value was hardcoded as a JSON string. Now, by utilizing `wp_json_encode`, we ensure the JSON encoding is handled correctly by WordPress standards, enhancing readability and maintainability of the code. --------- Co-authored-by: github-actions <github-actions@github.com>
2024-02-02 06:37:29 +00:00
if ( context?.isPrefetchNextOrPreviousLink && isValidLink( ref ) ) {
yield prefetch( ref.href );
}
},
},
};
store( 'woocommerce/product-collection', productCollectionStore );