Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for the EditorProvider and ExperimentalEditorProvider components #61739

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,35 @@ _Returns_

### EditorProvider

Undocumented declaration.
This component establishes a new post editing context, and serves as the entry point for a new post editor (or post with template editor).

It supports a large number of post types, including post, page, templates, custom post types, patterns, template parts.

All modification and changes are performed to the `@wordpress/core-data` store.

_Usage_

```jsx
<EditorProvider
post={ post }
settings={ settings }
__unstableTemplate={ template }
>
{ children }
</EditorProvider>
```

_Parameters_

- _props_ `Object`: The component props.
- _props.post_ `[Object]`: The post object to edit. This is required.
- _props.\_\_unstableTemplate_ `[Object]`: The template object wrapper the edited post. This is optional and can only be used when the post type supports templates (like posts and pages).
- _props.settings_ `[Object]`: The settings object to use for the editor. This is optional and can be used to override the default settings.
- _props.children_ `[Element]`: Children elements for which the BlockEditorProvider context should apply. This is optional.

_Returns_

- `JSX.Element`: The rendered EditorProvider component.

### EditorSnackbars

Expand Down
37 changes: 0 additions & 37 deletions packages/editor/src/components/provider/README.md

This file was deleted.

62 changes: 62 additions & 0 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const NON_CONTEXTUAL_POST_TYPES = [
* @param {Array} post Block list.
* @param {boolean} template Whether the page content has focus (and the surrounding template is inert). If `true` return page content blocks. Default `false`.
* @param {string} mode Rendering mode.
*
* @example
* ```jsx
* const [ blocks, onInput, onChange ] = useBlockEditorProps( post, template, mode );
* ```
*
* @return {Array} Block editor props.
*/
function useBlockEditorProps( post, template, mode ) {
Expand Down Expand Up @@ -118,6 +124,32 @@ function useBlockEditorProps( post, template, mode ) {
];
}

/**
* This component provides the editor context and manages the state of the block editor.
*
* @param {Object} props The component props.
* @param {Object} props.post The post object.
* @param {Object} props.settings The editor settings.
* @param {boolean} props.recovery Indicates if the editor is in recovery mode.
* @param {Array} props.initialEdits The initial edits for the editor.
* @param {Object} props.children The child components.
* @param {Object} [props.BlockEditorProviderComponent] The block editor provider component to use. Defaults to ExperimentalBlockEditorProvider.
* @param {Object} [props.__unstableTemplate] The template object.
*
* @example
* ```jsx
* <ExperimentalEditorProvider
* post={ post }
* settings={ settings }
* recovery={ recovery }
* initialEdits={ initialEdits }
* __unstableTemplate={ template }
* >
* { children }
* </ExperimentalEditorProvider>
*
* @return {Object} The rendered ExperimentalEditorProvider component.
*/
export const ExperimentalEditorProvider = withRegistryProvider(
( {
post,
Expand Down Expand Up @@ -293,6 +325,36 @@ export const ExperimentalEditorProvider = withRegistryProvider(
}
);

/**
* This component establishes a new post editing context, and serves as the entry point for a new post editor (or post with template editor).
*
* It supports a large number of post types, including post, page, templates,
* custom post types, patterns, template parts.
*
* All modification and changes are performed to the `@wordpress/core-data` store.
*
* @param {Object} props The component props.
* @param {Object} [props.post] The post object to edit. This is required.
* @param {Object} [props.__unstableTemplate] The template object wrapper the edited post.
* This is optional and can only be used when the post type supports templates (like posts and pages).
* @param {Object} [props.settings] The settings object to use for the editor.
* This is optional and can be used to override the default settings.
* @param {Element} [props.children] Children elements for which the BlockEditorProvider context should apply.
* This is optional.
*
* @example
* ```jsx
* <EditorProvider
* post={ post }
* settings={ settings }
* __unstableTemplate={ template }
* >
* { children }
* </EditorProvider>
* ```
*
* @return {JSX.Element} The rendered EditorProvider component.
*/
export function EditorProvider( props ) {
return (
<ExperimentalEditorProvider
Expand Down
Loading