Product Editor: Add PostTypeContext and blocks access to plugins (#41106)
This commit is contained in:
commit
ab51a761a3
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: minor
|
||||||
|
Type: update
|
||||||
|
|
||||||
|
Allow plugins to access PostTypeContext and blocks (through core/block-editor data store).
|
|
@ -5,6 +5,7 @@ import { synchronizeBlocksWithTemplate, Template } from '@wordpress/blocks';
|
||||||
import { createElement, useMemo, useLayoutEffect } from '@wordpress/element';
|
import { createElement, useMemo, useLayoutEffect } from '@wordpress/element';
|
||||||
import { useDispatch, useSelect, select as WPSelect } from '@wordpress/data';
|
import { useDispatch, useSelect, select as WPSelect } from '@wordpress/data';
|
||||||
import { uploadMedia } from '@wordpress/media-utils';
|
import { uploadMedia } from '@wordpress/media-utils';
|
||||||
|
import { PluginArea } from '@wordpress/plugins';
|
||||||
import {
|
import {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
// @ts-ignore No types for this exist yet.
|
// @ts-ignore No types for this exist yet.
|
||||||
|
@ -32,6 +33,7 @@ import {
|
||||||
*/
|
*/
|
||||||
import { useConfirmUnsavedProductChanges } from '../../hooks/use-confirm-unsaved-product-changes';
|
import { useConfirmUnsavedProductChanges } from '../../hooks/use-confirm-unsaved-product-changes';
|
||||||
import { ProductEditorContext } from '../../types';
|
import { ProductEditorContext } from '../../types';
|
||||||
|
import { PostTypeContext } from '../../contexts/post-type-context';
|
||||||
|
|
||||||
type BlockEditorProps = {
|
type BlockEditorProps = {
|
||||||
context: Partial< ProductEditorContext >;
|
context: Partial< ProductEditorContext >;
|
||||||
|
@ -120,6 +122,11 @@ export function BlockEditor( {
|
||||||
<BlockList className="woocommerce-product-block-editor__block-list" />
|
<BlockList className="woocommerce-product-block-editor__block-list" />
|
||||||
</ObserveTyping>
|
</ObserveTyping>
|
||||||
</BlockTools>
|
</BlockTools>
|
||||||
|
{ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */ }
|
||||||
|
<PostTypeContext.Provider value={ context.postType! }>
|
||||||
|
{ /* @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated. */ }
|
||||||
|
<PluginArea scope="woocommerce-product-block-editor" />
|
||||||
|
</PostTypeContext.Provider>
|
||||||
</BlockEditorProvider>
|
</BlockEditorProvider>
|
||||||
</BlockContextProvider>
|
</BlockContextProvider>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
Fragment,
|
Fragment,
|
||||||
useState,
|
useState,
|
||||||
} from '@wordpress/element';
|
} from '@wordpress/element';
|
||||||
import { PluginArea } from '@wordpress/plugins';
|
|
||||||
import {
|
import {
|
||||||
LayoutContextProvider,
|
LayoutContextProvider,
|
||||||
useExtendLayout,
|
useExtendLayout,
|
||||||
|
@ -90,8 +89,6 @@ export function Editor( {
|
||||||
postId: product.id,
|
postId: product.id,
|
||||||
} }
|
} }
|
||||||
/>
|
/>
|
||||||
{ /* @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated. */ }
|
|
||||||
<PluginArea scope="woocommerce-product-block-editor" />
|
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
import { createContext } from '@wordpress/element';
|
||||||
|
|
||||||
|
export const PostTypeContext = createContext( 'product' );
|
|
@ -20,5 +20,6 @@ export * from './utils';
|
||||||
* Hooks
|
* Hooks
|
||||||
*/
|
*/
|
||||||
export * from './hooks';
|
export * from './hooks';
|
||||||
|
export { PostTypeContext } from './contexts/post-type-context';
|
||||||
export { useValidation, useValidations } from './contexts/validation-context';
|
export { useValidation, useValidations } from './contexts/validation-context';
|
||||||
export * from './contexts/validation-context/types';
|
export * from './contexts/validation-context/types';
|
||||||
|
|
Loading…
Reference in New Issue