Skip to content

Commit

Permalink
Implement API
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Nov 20, 2024
1 parent 3012632 commit 7443615
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,18 @@ _Parameters_
- _name_ `string`: Entity name.
- _config_ `Action`: Action configuration.

### registerEntityField

Registers a new DataViews field.

This is an experimental API and is subject to change. it's only available in the Gutenberg plugin for now.

_Parameters_

- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _config_ `Field`: Field configuration.

### RichText

> **Deprecated** since 5.3, use `wp.blockEditor.RichText` instead.
Expand Down Expand Up @@ -1697,6 +1709,18 @@ _Parameters_
- _name_ `string`: Entity name.
- _actionId_ `string`: Action ID.

### unregisterEntityField

Unregisters a DataViews field.

This is an experimental API and is subject to change. it's only available in the Gutenberg plugin for now.

_Parameters_

- _kind_ `string`: Entity kind.
- _name_ `string`: Entity name.
- _fieldId_ `string`: Field ID.

### UnsavedChangesWarning

Warns the user if there are unsaved changes before leaving the editor. Compatible with Post Editor and Site Editor.
Expand Down
41 changes: 41 additions & 0 deletions packages/editor/src/dataviews/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { store as editorStore } from '../store';

/**
* @typedef {import('@wordpress/dataviews').Action} Action
* @typedef {import('@wordpress/dataviews').Field} Field
*/

/**
Expand Down Expand Up @@ -53,3 +54,43 @@ export function unregisterEntityAction( kind, name, actionId ) {
_unregisterEntityAction( kind, name, actionId );
}
}

/**
* Registers a new DataViews field.
*
* This is an experimental API and is subject to change.
* it's only available in the Gutenberg plugin for now.
*
* @param {string} kind Entity kind.
* @param {string} name Entity name.
* @param {Field} config Field configuration.
*/
export function registerEntityField( kind, name, config ) {
const { registerEntityField: _registerEntityField } = unlock(
dispatch( editorStore )
);

if ( globalThis.IS_GUTENBERG_PLUGIN ) {
_registerEntityField( kind, name, config );
}
}

/**
* Unregisters a DataViews field.
*
* This is an experimental API and is subject to change.
* it's only available in the Gutenberg plugin for now.
*
* @param {string} kind Entity kind.
* @param {string} name Entity name.
* @param {string} fieldId Field ID.
*/
export function unregisterEntityField( kind, name, fieldId ) {
const { unregisterEntityField: _unregisterEntityField } = unlock(
dispatch( editorStore )
);

if ( globalThis.IS_GUTENBERG_PLUGIN ) {
_unregisterEntityField( kind, name, fieldId );
}
}

0 comments on commit 7443615

Please sign in to comment.