This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into merge/#8025-local-pickup-country-state-into…
…-same-field
- Loading branch information
Showing
104 changed files
with
1,252 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
assets/js/atomic/blocks/product-elements/product-image-gallery/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "woocommerce/product-image-gallery", | ||
"version": "1.0.0", | ||
"title": "Product Image Gallery", | ||
"icon": "gallery", | ||
"description": "Display a product's images.", | ||
"category": "woocommerce", | ||
"supports": { | ||
"align": true, | ||
"reusable": false | ||
}, | ||
"keywords": [ "WooCommerce" ], | ||
"usesContext": [ "postId", "postType", "queryId" ], | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2, | ||
"$schema": "https://schemas.wp.org/trunk/block.json" | ||
} |
64 changes: 64 additions & 0 deletions
64
assets/js/atomic/blocks/product-elements/product-image-gallery/edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { WC_BLOCKS_IMAGE_URL } from '@woocommerce/block-settings'; | ||
import { isEmptyObject } from '@woocommerce/types'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { BlockAttributes } from '@wordpress/blocks'; | ||
import { Disabled } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './editor.scss'; | ||
|
||
const Placeholder = () => { | ||
return ( | ||
<div className="wc-block-editor-product-gallery"> | ||
<img | ||
src={ `${ WC_BLOCKS_IMAGE_URL }block-placeholders/product-image-gallery.svg` } | ||
alt="Placeholder" | ||
/> | ||
<div className="wc-block-editor-product-gallery__other-images"> | ||
{ [ ...Array( 4 ).keys() ].map( ( index ) => { | ||
return ( | ||
<img | ||
key={ index } | ||
src={ `${ WC_BLOCKS_IMAGE_URL }block-placeholders/product-image-gallery.svg` } | ||
alt="Placeholder" | ||
/> | ||
); | ||
} ) } | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
type Context = { | ||
postId: string; | ||
postType: string; | ||
queryId: string; | ||
}; | ||
|
||
interface Props { | ||
attributes: BlockAttributes; | ||
context: Context; | ||
} | ||
|
||
const Edit = ( { context }: Props ) => { | ||
const blockProps = useBlockProps(); | ||
|
||
if ( isEmptyObject( context ) ) { | ||
return ( | ||
<div { ...blockProps }> | ||
<Disabled> | ||
<Placeholder /> | ||
</Disabled> | ||
</div> | ||
); | ||
} | ||
// We have work on this case when we will work on the Single Product block. | ||
return ''; | ||
}; | ||
|
||
export default Edit; |
13 changes: 13 additions & 0 deletions
13
assets/js/atomic/blocks/product-elements/product-image-gallery/editor.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.wc-block-editor-product-gallery { | ||
img { | ||
width: 500px; | ||
height: 500px; | ||
} | ||
.wc-block-editor-product-gallery__other-images { | ||
img { | ||
width: 100px; | ||
height: 100px; | ||
margin: 5px; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
assets/js/atomic/blocks/product-elements/product-image-gallery/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { gallery as icon } from '@wordpress/icons'; | ||
import { registerBlockType, unregisterBlockType } from '@wordpress/blocks'; | ||
import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import edit from './edit'; | ||
import metadata from './block.json'; | ||
|
||
registerBlockSingleProductTemplate( { | ||
registerBlockFn: () => { | ||
// @ts-expect-error: `registerBlockType` is a function that is typed in WordPress core. | ||
registerBlockType( metadata, { | ||
icon, | ||
edit, | ||
} ); | ||
}, | ||
unregisterBlockFn: () => { | ||
unregisterBlockType( metadata.name ); | ||
}, | ||
blockName: metadata.name, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
assets/js/atomic/utils/register-block-single-product-template.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { getBlockType } from '@wordpress/blocks'; | ||
import { subscribe, select } from '@wordpress/data'; | ||
|
||
export const registerBlockSingleProductTemplate = ( { | ||
registerBlockFn, | ||
unregisterBlockFn, | ||
blockName, | ||
}: { | ||
registerBlockFn: () => void; | ||
unregisterBlockFn: () => void; | ||
blockName: string; | ||
} ) => { | ||
let currentTemplateId: string | undefined; | ||
|
||
subscribe( () => { | ||
const previousTemplateId = currentTemplateId; | ||
const store = select( 'core/edit-site' ); | ||
currentTemplateId = store?.getEditedPostId() as string | undefined; | ||
|
||
if ( previousTemplateId === currentTemplateId ) { | ||
return; | ||
} | ||
|
||
const parsedTemplate = currentTemplateId?.split( '//' )[ 1 ]; | ||
|
||
if ( parsedTemplate === null || parsedTemplate === undefined ) { | ||
return; | ||
} | ||
|
||
const block = getBlockType( blockName ); | ||
|
||
if ( | ||
block === undefined && | ||
parsedTemplate.includes( 'single-product' ) | ||
) { | ||
registerBlockFn(); | ||
} | ||
|
||
if ( block !== undefined ) { | ||
unregisterBlockFn(); | ||
} | ||
}, 'core/edit-site' ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.