2020-07-07 09:05:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const { omit } = require( 'lodash' );
|
2020-07-22 12:05:56 +00:00
|
|
|
const glob = require( 'glob' );
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2020-07-22 12:05:56 +00:00
|
|
|
// List of blocks that should be used as webpack entry points. They are expected
|
|
|
|
// to be in `/assets/js/blocks/[BLOCK_NAME]`. If they are not, their relative
|
|
|
|
// path should be defined in the `customDir` property. The scripts below will
|
|
|
|
// take care of looking for `index.js`, `frontend.js` and `*.scss` files in each
|
|
|
|
// block directory.
|
|
|
|
// If a block is experimental, it should be marked with the `isExperimental`
|
|
|
|
// property.
|
|
|
|
const blocks = {
|
2023-01-12 07:34:45 +00:00
|
|
|
'active-filters': {},
|
2023-02-16 10:43:37 +00:00
|
|
|
'add-to-cart-form': {},
|
2023-01-12 07:34:45 +00:00
|
|
|
'all-products': {
|
|
|
|
customDir: 'products/all-products',
|
2022-05-19 16:16:46 +00:00
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
'all-reviews': {
|
|
|
|
customDir: 'reviews/all-reviews',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
2023-01-12 07:34:45 +00:00
|
|
|
'attribute-filter': {},
|
2023-01-27 17:31:13 +00:00
|
|
|
breadcrumbs: {},
|
2023-01-12 07:34:45 +00:00
|
|
|
cart: {},
|
2023-01-17 15:20:10 +00:00
|
|
|
'catalog-sorting': {},
|
2023-01-12 07:34:45 +00:00
|
|
|
checkout: {},
|
|
|
|
'customer-account': {},
|
2022-05-19 16:16:46 +00:00
|
|
|
'featured-category': {
|
|
|
|
customDir: 'featured-items/featured-category',
|
|
|
|
},
|
2023-01-12 07:34:45 +00:00
|
|
|
'featured-product': {
|
|
|
|
customDir: 'featured-items/featured-product',
|
|
|
|
},
|
|
|
|
'filter-wrapper': {},
|
|
|
|
'handpicked-products': {},
|
|
|
|
// We need to keep the legacy-template id, so we need to add a custom config to point to the renamed classic-template folder
|
|
|
|
'legacy-template': {
|
|
|
|
customDir: 'classic-template',
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
2022-04-08 08:51:21 +00:00
|
|
|
'mini-cart': {},
|
2021-11-19 11:47:48 +00:00
|
|
|
'mini-cart-contents': {
|
2022-04-07 13:47:58 +00:00
|
|
|
customDir: 'mini-cart/mini-cart-contents',
|
2021-11-19 11:47:48 +00:00
|
|
|
},
|
2023-01-18 12:40:30 +00:00
|
|
|
'store-notices': {},
|
2023-01-12 07:34:45 +00:00
|
|
|
'price-filter': {},
|
|
|
|
'product-best-sellers': {},
|
|
|
|
'product-category': {},
|
|
|
|
'product-categories': {},
|
|
|
|
'product-new': {},
|
|
|
|
'product-on-sale': {},
|
|
|
|
'product-query': {
|
2020-07-22 12:05:56 +00:00
|
|
|
isExperimental: true,
|
|
|
|
},
|
2023-01-17 15:19:42 +00:00
|
|
|
'product-results-count': {},
|
2023-01-12 07:34:45 +00:00
|
|
|
'product-search': {},
|
|
|
|
'product-tag': {},
|
|
|
|
'product-top-rated': {},
|
|
|
|
'products-by-attribute': {},
|
|
|
|
'rating-filter': {},
|
|
|
|
'reviews-by-category': {
|
|
|
|
customDir: 'reviews/reviews-by-category',
|
2022-03-22 22:34:43 +00:00
|
|
|
},
|
2023-01-12 07:34:45 +00:00
|
|
|
'reviews-by-product': {
|
|
|
|
customDir: 'reviews/reviews-by-product',
|
|
|
|
},
|
2023-04-06 18:40:43 +00:00
|
|
|
'single-product': {
|
|
|
|
isExperimental: true,
|
|
|
|
},
|
2023-01-12 07:34:45 +00:00
|
|
|
'stock-filter': {},
|
Foundation of New Product Collection Block (https://github.com/woocommerce/woocommerce-blocks/pull/9352)
* Add Products Collection block scaffolding
This commit adds the initial scaffolding for the new Products Collection block. It includes the creation of new files (block.json, edit.tsx, index.tsx and ProductsCollection.php) and additions to existing files (webpack-entries.js and BlockTypesController.php). The block is marked as experimental and currently displays a static "Product collection" text in both the editor and the frontend.
* Add Product Template block and integrate with Products Collection block
This commit introduces the new Product Template block and integrates it with the existing Products Collection block. The changes include:
- Creation of the Product Template block, including its block.json, edit.tsx, icon.tsx, index.tsx, and save.tsx files.
- Modification of the Products Collection block, adding an icon.tsx file and updating its edit.tsx and index.tsx files.
- Updates to the webpack-entries.js file to include the new Product Template block.
- Addition of the ProductTemplate class in the src/BlockTypes directory.
- Inclusion of the ProductTemplate class in the src/BlockTypesController.php file.
* Enhance product-template block with context and styling
This commit adds various enhancements to the product-template block. It includes:
- Introduce `usesContext` and `supports` properties to the block.json file
- Update the edit.tsx file to use BlockContextProvider and add query logic
- Add an editor.scss file for styling the product-template block in the editor
- Extend the products-collection block.json file with new properties
- Modify the products-collection edit.tsx file to include instanceId and useEffect
These changes improve the product-template block by providing better context handling and styling options.
* Add 'woocommerce/product-template' to supported inner blocks and improve product-template editing
This commit adds 'woocommerce/product-template' as a supported inner block for various product elements, including button, image, rating, sale-badge, SKU, and stock-indicator. It also improves the editing experience for the product-template block by memoizing the block previews and rendering them more efficiently. This should lead to a smoother editing experience and better performance in the block editor.
* Add product title and summary variations for Products Collection block
- Add default spacing between product elements in `style.scss`
- Register product title and summary element variations in `products-collection` block
- Create utility for registering element variations
- Extend core elements with WooCommerce namespace
* Set inherit to false by default and other improvements
This commit introduces several changes to the ProductsCollection block:
1. Set the "inherit" property to false in block.json, disabling inheritance by default.
2. Remove the default styles for inner blocks in the edit.tsx file.
3. Add a save function in the index.tsx file, and create a save.tsx file to handle saving the block.
4. Update the ProductTemplate.php file to properly render the block content based on the changes.
5. Remove the render function from the ProductsCollection.php file, as it is no longer necessary.
These changes improve the functionality and flexibility of the ProductsCollection block, allowing for better customization and control over the block's appearance and behavior.
* Fix pagination issue
* Minor code quality improvments
* Register product blocks only in experimental builds
- Wrap registerBlockType calls in product-template and products-collection with isExperimentalBuild check to enable block registration only in experimental builds.
- Update the default value for the perPage property in products-collection/block.json from null to 9, setting a default display of 9 items per page.
* Add experimental flag to PHP file
* Update documentation for feature flags
- Add Products Collection and Product Template blocks to the list of experimental flags in the feature-flags-and-experimental-interfaces.md file.
- Include references to PHP and webpack flags for both blocks.
* Change default order and orderBy values in block.json
- Update the default 'order' value from 'desc' to 'asc'.
- Update the default 'orderBy' value from 'date' to 'title'.
* Refactor experimental block registration and remove unused file
- Replace `isExperimentalBuild()` with `registerExperimentalBlockType()` in product-template/index.tsx.
- Remove unused file types.ts in product-template directory.
- Add `get_block_type_script()` function to ProductTemplate.php and ProductsCollection.php to return null.
* Update variation names in product summary and product title elements
Updated variation names for product summary and product title elements to match the new products-collection namespace. The previous variation names used the product-query namespace which will be deprecated. This change ensures that the correct variation names are used for these elements in the products-collection block.
* Rename 'Products Collection' to 'Product Collection'
- Renamed all instances of "products-collection" to "product-collection" across multiple files.
- Adjusted related types and method calls to match the new naming convention.
- Updated documentation and feature flags to reflect the name change.
- Made necessary changes in `BlockTypesController.php` and `bin/webpack-entries.js`.
* Hide product-template block from inserter
- Added "woocommerce/product-collection" to the list of parent blocks in `product-template/block.json`.
- Added `"inserter": false` to the "supports" section to disable the option of inserting this block through the editor inserter component.
* Fix Eslint error
2023-05-15 08:51:49 +00:00
|
|
|
'product-collection': {
|
|
|
|
isExperimental: true,
|
|
|
|
},
|
|
|
|
'product-template': {
|
|
|
|
isExperimental: true,
|
|
|
|
},
|
2020-07-22 12:05:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Returns the entries for each block given a relative path (ie: `index.js`,
|
|
|
|
// `**/*.scss`...).
|
|
|
|
// It also filters out elements with undefined props and experimental blocks.
|
|
|
|
const getBlockEntries = ( relativePath ) => {
|
|
|
|
const experimental =
|
|
|
|
! parseInt( process.env.WOOCOMMERCE_BLOCKS_PHASE, 10 ) < 3;
|
|
|
|
|
|
|
|
return Object.fromEntries(
|
|
|
|
Object.entries( blocks )
|
|
|
|
.filter(
|
|
|
|
( [ , config ] ) =>
|
|
|
|
! config.isExperimental ||
|
|
|
|
config.isExperimental === experimental
|
|
|
|
)
|
|
|
|
.map( ( [ blockCode, config ] ) => {
|
|
|
|
const filePaths = glob.sync(
|
|
|
|
`./assets/js/blocks/${ config.customDir || blockCode }/` +
|
|
|
|
relativePath
|
|
|
|
);
|
|
|
|
if ( filePaths.length > 0 ) {
|
|
|
|
return [ blockCode, filePaths ];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
} )
|
|
|
|
.filter( Boolean )
|
|
|
|
);
|
|
|
|
};
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2020-07-22 12:05:56 +00:00
|
|
|
const entries = {
|
|
|
|
styling: {
|
2020-07-07 09:05:06 +00:00
|
|
|
// @wordpress/components styles
|
|
|
|
'custom-select-control-style':
|
|
|
|
'./node_modules/wordpress-components/src/custom-select-control/style.scss',
|
|
|
|
'snackbar-notice-style':
|
|
|
|
'./node_modules/wordpress-components/src/snackbar/style.scss',
|
2021-08-12 16:30:42 +00:00
|
|
|
'combobox-control-style':
|
|
|
|
'./node_modules/wordpress-components/src/combobox-control/style.scss',
|
2022-08-01 12:00:59 +00:00
|
|
|
'form-token-field-style':
|
|
|
|
'./node_modules/wordpress-components/src/form-token-field/style.scss',
|
2020-07-07 09:05:06 +00:00
|
|
|
|
2020-07-22 12:05:56 +00:00
|
|
|
'general-style': glob.sync( './assets/**/*.scss', {
|
|
|
|
ignore: [
|
|
|
|
// Block styles are added below.
|
|
|
|
'./assets/js/blocks/*/*.scss',
|
|
|
|
],
|
|
|
|
} ),
|
|
|
|
|
2021-01-07 12:02:21 +00:00
|
|
|
'packages-style': glob.sync( './packages/**/*.scss' ),
|
|
|
|
|
2020-07-29 14:07:21 +00:00
|
|
|
'reviews-style': './assets/js/blocks/reviews/editor.scss',
|
2020-07-22 12:05:56 +00:00
|
|
|
...getBlockEntries( '**/*.scss' ),
|
|
|
|
},
|
|
|
|
core: {
|
|
|
|
wcBlocksRegistry: './assets/js/blocks-registry/index.js',
|
2021-04-22 11:37:27 +00:00
|
|
|
wcSettings: './assets/js/settings/shared/index.ts',
|
2021-08-13 13:28:41 +00:00
|
|
|
wcBlocksData: './assets/js/data/index.ts',
|
2020-07-22 12:05:56 +00:00
|
|
|
wcBlocksMiddleware: './assets/js/middleware/index.js',
|
2021-06-09 14:09:42 +00:00
|
|
|
wcBlocksSharedContext: './assets/js/shared/context/index.js',
|
|
|
|
wcBlocksSharedHocs: './assets/js/shared/hocs/index.js',
|
2021-02-04 15:30:28 +00:00
|
|
|
priceFormat: './packages/prices/index.js',
|
2021-01-11 12:12:26 +00:00
|
|
|
blocksCheckout: './packages/checkout/index.js',
|
2020-07-22 12:05:56 +00:00
|
|
|
},
|
|
|
|
main: {
|
|
|
|
// Shared blocks code
|
2021-06-09 14:09:42 +00:00
|
|
|
'wc-blocks': './assets/js/index.js',
|
2020-07-07 09:05:06 +00:00
|
|
|
|
|
|
|
// Blocks
|
2021-06-09 14:09:42 +00:00
|
|
|
...getBlockEntries( 'index.{t,j}s{,x}' ),
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
frontend: {
|
|
|
|
reviews: './assets/js/blocks/reviews/frontend.js',
|
2021-06-09 14:09:42 +00:00
|
|
|
...getBlockEntries( 'frontend.{t,j}s{,x}' ),
|
2021-08-25 15:42:55 +00:00
|
|
|
'mini-cart-component':
|
2022-04-07 13:47:58 +00:00
|
|
|
'./assets/js/blocks/mini-cart/component-frontend.tsx',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
|
|
|
payments: {
|
|
|
|
'wc-payment-method-cheque':
|
2022-11-11 16:17:49 +00:00
|
|
|
'./assets/js/extensions/payment-methods/cheque/index.js',
|
2020-07-07 09:05:06 +00:00
|
|
|
'wc-payment-method-paypal':
|
2022-11-11 16:17:49 +00:00
|
|
|
'./assets/js/extensions/payment-methods/paypal/index.js',
|
2020-07-08 00:39:16 +00:00
|
|
|
'wc-payment-method-bacs':
|
2022-11-11 16:17:49 +00:00
|
|
|
'./assets/js/extensions/payment-methods/bacs/index.js',
|
2020-07-15 14:14:41 +00:00
|
|
|
'wc-payment-method-cod':
|
2022-11-11 16:17:49 +00:00
|
|
|
'./assets/js/extensions/payment-methods/cod/index.js',
|
2020-07-07 09:05:06 +00:00
|
|
|
},
|
2021-03-16 11:40:22 +00:00
|
|
|
extensions: {
|
|
|
|
'wc-blocks-google-analytics':
|
|
|
|
'./assets/js/extensions/google-analytics/index.ts',
|
2022-11-11 16:17:49 +00:00
|
|
|
'wc-shipping-method-pickup-location':
|
|
|
|
'./assets/js/extensions/shipping-methods/pickup-location/index.js',
|
2021-03-16 11:40:22 +00:00
|
|
|
},
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const getEntryConfig = ( type = 'main', exclude = [] ) => {
|
2020-07-22 12:05:56 +00:00
|
|
|
return omit( entries[ type ], exclude );
|
2020-07-07 09:05:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getEntryConfig,
|
|
|
|
};
|