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

Connnect gutenberg widgets screen to widget area endpoints #15074

1 change: 1 addition & 0 deletions bin/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const packages = [
'Autogenerated selectors': 'src/selectors.js',
} ],
'data',
'data-controls',
'date',
'deprecated',
'dom',
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest-devhub.json
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,12 @@
"markdown_source": "../packages/custom-templated-path-webpack-plugin/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data-controls",
"slug": "packages-data-controls",
"markdown_source": "../packages/data-controls/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data",
"slug": "packages-data",
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/custom-templated-path-webpack-plugin/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data-controls",
"slug": "packages-data-controls",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/data-controls/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data",
"slug": "packages-data",
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@wordpress/compose": "file:packages/compose",
"@wordpress/core-data": "file:packages/core-data",
"@wordpress/data": "file:packages/data",
"@wordpress/data-controls": "file:packages/data-controls",
"@wordpress/date": "file:packages/date",
"@wordpress/deprecated": "file:packages/deprecated",
"@wordpress/dom": "file:packages/dom",
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const defaultEntities = [
{ name: 'postType', kind: 'root', key: 'slug', baseURL: '/wp/v2/types' },
{ name: 'media', kind: 'root', baseURL: '/wp/v2/media', plural: 'mediaItems' },
{ name: 'taxonomy', kind: 'root', key: 'slug', baseURL: '/wp/v2/taxonomies', plural: 'taxonomies' },
{ name: 'widgetArea', kind: 'root', baseURL: '/__experimental/widget-areas', plural: 'widgetAreas' },
];

export const kinds = [
Expand Down
3 changes: 3 additions & 0 deletions packages/data-controls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Master

Initial release of the @wordpress/data-controls package.
136 changes: 136 additions & 0 deletions packages/data-controls/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Data Controls

The data controls module is a module intended to simplify implementation of common controls used with the [`@wordpress/data`](/packages/data/README.md) package.

**Note:** It is assumed that the registry being used has the controls plugin enabled on it (see [more details on controls here](https://github.com/WordPress/gutenberg/tree/master/packages/data#controls))

## Installation

Install the module

```bash
npm install @wordpress/data-controls --save
```

_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._

The following controls are available on the object returned by the module:

## API

<!-- START TOKEN(Autogenerated API docs) -->

<a name="apiFetch" href="#apiFetch">#</a> **apiFetch**

Dispatches a control action for triggering an api fetch call.

_Usage_

```js
import { apiFetch } from '@wordpress/data-controls';

// Action generator using apiFetch
export function* myAction {
const path = '/v2/my-api/items';
const items = yield apiFetch( { path } );
// do something with the items.
}
```

_Parameters_

- _request_ `Object`: Arguments for the fetch request.

_Returns_

- `Object`: The control descriptor.

<a name="controls" href="#controls">#</a> **controls**

The default export is what you use to register the controls with your custom
store.

_Usage_

```js
// WordPress dependencies
import { controls } from '@wordpress/data-controls';
import { registerStore } from '@wordpress/data';

// Internal dependencies
import reducer from './reducer';
import * as selectors from './selectors';
import * as actions from './actions';
import * as resolvers from './resolvers';

registerStore ( 'my-custom-store', {
reducer,
controls,
actions,
selectors,
resolvers,
} );
```

_Returns_

- `Object`: An object for registering the default controls with the store.

<a name="dispatch" href="#dispatch">#</a> **dispatch**

Dispatches a control action for triggering a registry dispatch.

_Usage_

```js
import { dispatch } from '@wordpress/data-controls';

// Action generator using dispatch
export function* myAction {
yield dispatch( 'core/edit-post' ).togglePublishSidebar();
// do some other things.
}
```

_Parameters_

- _storeKey_ `string`: The key for the store the action belongs to
- _actionName_ `string`: The name of the action to dispatch
- _args_ `Array`: Arguments for the dispatch action.

_Returns_

- `Object`: The control descriptor.

<a name="select" href="#select">#</a> **select**

Dispatches a control action for triggering a registry select.

Note: when this control action is handled, it automatically considers
selectors that may have a resolver. It will await and return the resolved
value when the selector has not been resolved yet.

_Usage_

```js
import { select } from '@wordpress/data-controls';

// Action generator using select
export function* myAction {
const isSidebarOpened = yield select( 'core/edit-post', 'isEditorSideBarOpened' );
// do stuff with the result from the select.
}
```

_Parameters_

- _storeKey_ `string`: The key for the store the selector belongs to
- _selectorName_ `string`: The name of the selector
- _args_ `Array`: Arguments for the select.

_Returns_

- `Object`: The control descriptor.


<!-- END TOKEN(Autogenerated API docs) -->
31 changes: 31 additions & 0 deletions packages/data-controls/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@wordpress/data-controls",
"version": "1.0.0-beta.1",
"description": "A set of common controls for the @wordpress/data api.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"data",
"controls"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/data-controls/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/data-controls"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"main": "build/index.js",
"module": "build-module/index.js",
"react-native": "src/index",
"dependencies": {
"@wordpress/api-fetch": "file:../api-fetch",
"@wordpress/data": "file:../data"
},
"publishConfig": {
"access": "public"
}
}
Loading