| 1 |
/** |
| 2 |
* This file is used to wrap original Gutenberg components to avoid TypeScript errors. |
| 3 |
* |
| 4 |
* The original Gutenberg components are imported conditionally based on the environment. |
| 5 |
* This is needed since these Gutenberg components have changed their location to a different package in WordPress 6.6. |
| 6 |
* |
| 7 |
* @since 3.17.0 |
| 8 |
* |
| 9 |
* @see https://make.wordpress.org/core/2024/06/18/editor-unified-extensibility-apis-in-6-6/ |
| 10 |
*/ |
| 11 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 12 |
import type { ComponentType } from 'react'; |
| 13 |
|
| 14 |
// Import the original Gutenberg components. |
| 15 |
import { |
| 16 |
PluginDocumentSettingPanel as OriginalPluginDocumentSettingPanel, |
| 17 |
PluginSidebar as OriginalPluginSidebar, |
| 18 |
} from '@wordpress/edit-post'; |
| 19 |
|
| 20 |
// Define the types for the props of the original Gutenberg components. |
| 21 |
type PluginDocumentSettingPanelProps = React.ComponentProps<typeof OriginalPluginDocumentSettingPanel>; |
| 22 |
type PluginSidebarProps = React.ComponentProps<typeof OriginalPluginSidebar>; |
| 23 |
|
| 24 |
// Define the types for the original Gutenberg components. |
| 25 |
let PluginDocumentSettingPanel: ComponentType<PluginDocumentSettingPanelProps>; |
| 26 |
let PluginSidebar: ComponentType<PluginSidebarProps>; |
| 27 |
|
| 28 |
// Use the correct Gutenberg components based on the environment. |
| 29 |
if ( typeof window.wp !== 'undefined' ) { |
| 30 |
PluginDocumentSettingPanel = window.wp.editor?.PluginDocumentSettingPanel ?? |
| 31 |
( window.wp.editPost?.PluginDocumentSettingPanel ?? window.wp.editSite?.PluginDocumentSettingPanel ); |
| 32 |
PluginSidebar = window.wp.editor?.PluginSidebar ?? |
| 33 |
( window.wp.editPost?.PluginSidebar ?? window.wp.editSite?.PluginSidebar ); |
| 34 |
} |
| 35 |
|
| 36 |
// Export the wrapped Gutenberg components. |
| 37 |
export { |
| 38 |
PluginDocumentSettingPanel, |
| 39 |
PluginSidebar, |
| 40 |
}; |
| 41 |
|