Skip to content

Commit

Permalink
Add documentation for the EditorProvider and ExperimentalEditorProvid…
Browse files Browse the repository at this point in the history
…er components (#61739)

* Add documentation for the EditorProvider and ExperimentalEditorProvider components

* Address ESLint warning react-hooks/exhaustive-deps

* Refine EditorProvider editor component JSDocs

* Auto-generate EditorProvider editor docs

* Revert "Address ESLint warning react-hooks/exhaustive-deps"

This reverts commit 3f15d73.

---------

Co-authored-by: Damon Cook <damonacook@gmail.com>
  • Loading branch information
nateinaction and colorful-tones committed May 31, 2024
1 parent dfaad6d commit eb2b8a5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 38 deletions.
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

1 comment on commit eb2b8a5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in eb2b8a5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9316681443
📝 Reported issues:

Please sign in to comment.