From 15d46e478ca4bde6850b1115f290fdc6f3a8cf30 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Mon, 30 Oct 2023 10:52:00 -0400 Subject: [PATCH 1/4] Add PostTypeContext --- .../js/product-editor/src/components/editor/editor.tsx | 9 +++++++-- .../src/contexts/post-type-context/index.ts | 6 ++++++ packages/js/product-editor/src/index.ts | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 packages/js/product-editor/src/contexts/post-type-context/index.ts diff --git a/packages/js/product-editor/src/components/editor/editor.tsx b/packages/js/product-editor/src/components/editor/editor.tsx index 042b0afb4ae..ecb1bc121e0 100644 --- a/packages/js/product-editor/src/components/editor/editor.tsx +++ b/packages/js/product-editor/src/components/editor/editor.tsx @@ -37,6 +37,7 @@ import { FullscreenMode, InterfaceSkeleton } from '@wordpress/interface'; */ import { Header } from '../header'; import { BlockEditor } from '../block-editor'; +import { PostTypeContext } from '../../contexts/post-type-context'; import { ValidationProvider } from '../../contexts/validation-context'; export type ProductEditorSettings = Partial< @@ -90,8 +91,12 @@ export function Editor( { postId: product.id, } } /> - { /* @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated. */ } - + + { /* @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated. */ } + + } /> diff --git a/packages/js/product-editor/src/contexts/post-type-context/index.ts b/packages/js/product-editor/src/contexts/post-type-context/index.ts new file mode 100644 index 00000000000..968e2962631 --- /dev/null +++ b/packages/js/product-editor/src/contexts/post-type-context/index.ts @@ -0,0 +1,6 @@ +/** + * External dependencies + */ +import { createContext } from '@wordpress/element'; + +export const PostTypeContext = createContext( 'product' ); diff --git a/packages/js/product-editor/src/index.ts b/packages/js/product-editor/src/index.ts index 878a63d638a..ad5ae2a28fb 100644 --- a/packages/js/product-editor/src/index.ts +++ b/packages/js/product-editor/src/index.ts @@ -20,5 +20,6 @@ export * from './utils'; * Hooks */ export * from './hooks'; +export { PostTypeContext } from './contexts/post-type-context'; export { useValidation, useValidations } from './contexts/validation-context'; export * from './contexts/validation-context/types'; From fc2fa8598bf5ca8a06e9725241446e60b31ef135 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Mon, 30 Oct 2023 16:43:08 -0400 Subject: [PATCH 2/4] Changelog --- .../changelog/update-add-post-type-context-product-editor | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 packages/js/product-editor/changelog/update-add-post-type-context-product-editor diff --git a/packages/js/product-editor/changelog/update-add-post-type-context-product-editor b/packages/js/product-editor/changelog/update-add-post-type-context-product-editor new file mode 100644 index 00000000000..2ad018f462b --- /dev/null +++ b/packages/js/product-editor/changelog/update-add-post-type-context-product-editor @@ -0,0 +1,4 @@ +Significance: minor +Type: update + +Add PostTypeContext so that plugins can get post type. From afbe61a4f7da62e44e014d35a84d2d3ee5f7149d Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Wed, 1 Nov 2023 08:54:46 -0400 Subject: [PATCH 3/4] Move PluginArea into BlockEditor so plugins can get block info --- .../src/components/block-editor/block-editor.tsx | 7 +++++++ .../js/product-editor/src/components/editor/editor.tsx | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/js/product-editor/src/components/block-editor/block-editor.tsx b/packages/js/product-editor/src/components/block-editor/block-editor.tsx index f58e44659e1..526c6507cbb 100644 --- a/packages/js/product-editor/src/components/block-editor/block-editor.tsx +++ b/packages/js/product-editor/src/components/block-editor/block-editor.tsx @@ -5,6 +5,7 @@ import { synchronizeBlocksWithTemplate, Template } from '@wordpress/blocks'; import { createElement, useMemo, useLayoutEffect } from '@wordpress/element'; import { useDispatch, useSelect, select as WPSelect } from '@wordpress/data'; import { uploadMedia } from '@wordpress/media-utils'; +import { PluginArea } from '@wordpress/plugins'; import { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore No types for this exist yet. @@ -32,6 +33,7 @@ import { */ import { useConfirmUnsavedProductChanges } from '../../hooks/use-confirm-unsaved-product-changes'; import { ProductEditorContext } from '../../types'; +import { PostTypeContext } from '../../contexts/post-type-context'; type BlockEditorProps = { context: Partial< ProductEditorContext >; @@ -120,6 +122,11 @@ export function BlockEditor( { + { /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */ } + + { /* @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated. */ } + + diff --git a/packages/js/product-editor/src/components/editor/editor.tsx b/packages/js/product-editor/src/components/editor/editor.tsx index ecb1bc121e0..e5b3f177871 100644 --- a/packages/js/product-editor/src/components/editor/editor.tsx +++ b/packages/js/product-editor/src/components/editor/editor.tsx @@ -7,7 +7,6 @@ import { Fragment, useState, } from '@wordpress/element'; -import { PluginArea } from '@wordpress/plugins'; import { LayoutContextProvider, useExtendLayout, @@ -37,7 +36,6 @@ import { FullscreenMode, InterfaceSkeleton } from '@wordpress/interface'; */ import { Header } from '../header'; import { BlockEditor } from '../block-editor'; -import { PostTypeContext } from '../../contexts/post-type-context'; import { ValidationProvider } from '../../contexts/validation-context'; export type ProductEditorSettings = Partial< @@ -91,12 +89,6 @@ export function Editor( { postId: product.id, } } /> - - { /* @ts-expect-error 'scope' does exist. @types/wordpress__plugins is outdated. */ } - - } /> From 18faf14db7ab4d858831eb238298f0a0c45c732d Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Wed, 1 Nov 2023 19:51:40 -0400 Subject: [PATCH 4/4] Update changelog --- .../changelog/update-add-post-type-context-product-editor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/js/product-editor/changelog/update-add-post-type-context-product-editor b/packages/js/product-editor/changelog/update-add-post-type-context-product-editor index 2ad018f462b..a0ef51e308b 100644 --- a/packages/js/product-editor/changelog/update-add-post-type-context-product-editor +++ b/packages/js/product-editor/changelog/update-add-post-type-context-product-editor @@ -1,4 +1,4 @@ Significance: minor Type: update -Add PostTypeContext so that plugins can get post type. +Allow plugins to access PostTypeContext and blocks (through core/block-editor data store).