| 1 |
// eslint-disable-next-line import/named |
| 2 |
import { BlockInstance } from '@wordpress/blocks'; |
| 3 |
import { dispatch } from '@wordpress/data'; |
| 4 |
|
| 5 |
/** |
| 6 |
* Defines typings for core/block-editor functions, to avoid intellisense errors |
| 7 |
* in function calls. |
| 8 |
* |
| 9 |
* This can be removed once Gutenberg provides typings for these functions. |
| 10 |
* |
| 11 |
* @since 3.12.0 |
| 12 |
*/ |
| 13 |
export interface GutenbergFunction { |
| 14 |
getBlock: ( clientId: string ) => BlockInstance | null; |
| 15 |
getBlockParents: ( clientId: string ) => string[]; |
| 16 |
getBlocks: () => BlockInstance[]; |
| 17 |
getCurrentPostAttribute: ( attribute: string ) => string; |
| 18 |
getCurrentPostId: () => number | undefined; |
| 19 |
getEditedPostAttribute: ( attribute: string ) => string; |
| 20 |
getEditedPostContent: () => string; |
| 21 |
getPermalink: () => string | null; |
| 22 |
getSelectedBlock: () => BlockInstance | null; |
| 23 |
hasMetaBoxes: () => boolean; |
| 24 |
isAutosavingPost: () => boolean; |
| 25 |
isSavingPost: () => boolean; |
| 26 |
removeEditorPanel: ( panelName: string ) => void; |
| 27 |
selectBlock: ( clientId: string, initialPosition?: number ) => void; |
| 28 |
updateBlockAttributes: ( clientId: string, attributes: Record<string, unknown> ) => void; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Defines typings for core/editor functions, to avoid intellisense errors in |
| 33 |
* function calls. |
| 34 |
* |
| 35 |
* This can be removed once Gutenberg provides typings for these functions. |
| 36 |
* |
| 37 |
* @since 3.17.0 Moved from the GutenbergFunction interface. |
| 38 |
*/ |
| 39 |
export interface GutenbergCoreEditorFunction { |
| 40 |
editPost: ( edits: Record<string, unknown> ) => void; |
| 41 |
lockPostAutosaving: ( lockName: string ) => void; |
| 42 |
lockPostSaving: ( lockName: string ) => void; |
| 43 |
unlockPostAutosaving: ( lockName: string ) => void; |
| 44 |
unlockPostSaving: ( lockName: string ) => void; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Alias for dispatch( 'core/block-editor' ) calls that prevents intellisense |
| 49 |
* errors. |
| 50 |
* |
| 51 |
* @since 3.16.0 |
| 52 |
*/ |
| 53 |
export const dispatchCoreBlockEditor = dispatch( 'core/block-editor' ) as GutenbergFunction; |
| 54 |
|
| 55 |
/** |
| 56 |
* Alias for dispatch( 'core/editor' ) calls that prevents intellisense errors. |
| 57 |
* |
| 58 |
* @since 3.16.0 |
| 59 |
*/ |
| 60 |
export const dispatchCoreEditor = dispatch( 'core/editor' ) as unknown as GutenbergCoreEditorFunction; |
| 61 |
|
| 62 |
/** |
| 63 |
* Alias for dispatch( 'core/edit-post' ) calls that prevents intellisense |
| 64 |
* errors. |
| 65 |
* |
| 66 |
* @since 3.16.0 |
| 67 |
*/ |
| 68 |
export const dispatchCoreEditPost = dispatch( 'core/edit-post' ); |
| 69 |
|