Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Dec 5, 2024
1 parent d9fbc25 commit c79a28d
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 139 deletions.
155 changes: 78 additions & 77 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,34 +741,34 @@ Returns the currently selected block, or null if there is no selected block.
_Usage_

```js
import { select } from '@wordpress/data';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { select } from '@wordpress/data'
import { store as blockEditorStore } from '@wordpress/block-editor'

// Set initial active block client ID
let activeBlockClientId = null;
let activeBlockClientId = null

const getActiveBlockData = () => {
const activeBlock = select( blockEditorStore ).getSelectedBlock();
const activeBlock = select(blockEditorStore).getSelectedBlock()

if ( activeBlock && activeBlock.clientId !== activeBlockClientId ) {
activeBlockClientId = activeBlock.clientId;
if (activeBlock && activeBlock.clientId !== activeBlockClientId) {
activeBlockClientId = activeBlock.clientId

// Get active block name and attributes
const activeBlockName = activeBlock.name;
const activeBlockAttributes = activeBlock.attributes;
const activeBlockName = activeBlock.name
const activeBlockAttributes = activeBlock.attributes

// Log active block name and attributes
console.log( activeBlockName, activeBlockAttributes );
console.log(activeBlockName, activeBlockAttributes)
}
}
};

// Subscribe to changes in the editor
// wp.data.subscribe(() => {
// getActiveBlockData()
// })
// Subscribe to changes in the editor
// wp.data.subscribe(() => {
// getActiveBlockData()
// })

// Update active block data on click
// onclick="getActiveBlockData()"
// Update active block data on click
// onclick="getActiveBlockData()"
```

_Parameters_
Expand Down Expand Up @@ -869,7 +869,7 @@ Returns the defined block template

_Parameters_

- _state_ `boolean`:
- _state_ `boolean`:

_Returns_

Expand All @@ -890,7 +890,7 @@ _Returns_

### hasBlockMovingClientId

> **Deprecated**
> **Deprecated**
Returns whether block moving mode is enabled.

Expand Down Expand Up @@ -1092,7 +1092,7 @@ _Returns_

### isCaretWithinFormattedText

> **Deprecated**
> **Deprecated**
Returns true if the caret is within formatted text, or false otherwise.

Expand Down Expand Up @@ -1221,7 +1221,7 @@ Returns whether the blocks matches the template or not.

_Parameters_

- _state_ `boolean`:
- _state_ `boolean`:

_Returns_

Expand Down Expand Up @@ -1261,12 +1261,12 @@ Action that duplicates a list of blocks.

_Parameters_

- _clientIds_ `string[]`:
- _updateSelection_ `boolean`:
- _clientIds_ `string[]`:
- _updateSelection_ `boolean`:

### enterFormattedText

> **Deprecated**
> **Deprecated**
Returns an action object used in signalling that the caret has entered formatted text.

Expand All @@ -1276,7 +1276,7 @@ _Returns_

### exitFormattedText

> **Deprecated**
> **Deprecated**
Returns an action object used in signalling that the user caret has exited formatted text.

Expand Down Expand Up @@ -1314,15 +1314,15 @@ Action that inserts a default block after a given block.

_Parameters_

- _clientId_ `string`:
- _clientId_ `string`:

### insertBeforeBlock

Action that inserts a default block before a given block.

_Parameters_

- _clientId_ `string`:
- _clientId_ `string`:

### insertBlock

Expand Down Expand Up @@ -1353,7 +1353,7 @@ _Parameters_
- _blocks_ `Object[]`: Block objects to insert.
- _index_ `?number`: Index at which block should be inserted.
- _rootClientId_ `?string`: Optional root client ID of block list on which to insert.
- _updateSelection_ `?boolean`: If true block selection will be updated. If false, block selection will not change. Defaults to true.
- _updateSelection_ `?boolean`: If true block selection will be updated. If false, block selection will not change. Defaults to true.
- _initialPosition_ `0|-1|null`: Initial focus position. Setting it to null prevent focusing the inserted block.
- _meta_ `?Object`: Optional Meta values to be passed to the action object.

Expand Down Expand Up @@ -1422,7 +1422,7 @@ _Parameters_

### receiveBlocks

> **Deprecated**
> **Deprecated**
Returns an action object used in signalling that blocks have been received. Unlike resetBlocks, these should be appended to the existing known set, not replacing.

Expand Down Expand Up @@ -1466,54 +1466,54 @@ _Properties_
_Usage_

```js
wp.data.dispatch( 'core/block-editor' ).registerInserterMediaCategory( {
name: 'openverse',
labels: {
name: 'Openverse',
search_items: 'Search Openverse',
},
mediaType: 'image',
async fetch( query = {} ) {
const defaultArgs = {
mature: false,
excluded_source: 'flickr,inaturalist,wikimedia',
license: 'pdm,cc0',
};
const finalQuery = { ...query, ...defaultArgs };
// Sometimes you might need to map the supported request params according to `InserterMediaRequest`.
// interface. In this example the `search` query param is named `q`.
const mapFromInserterMediaRequest = {
per_page: 'page_size',
search: 'q',
};
const url = new URL( 'https://api.openverse.org/v1/images/' );
Object.entries( finalQuery ).forEach( ( [ key, value ] ) => {
const queryKey = mapFromInserterMediaRequest[ key ] || key;
url.searchParams.set( queryKey, value );
} );
const response = await window.fetch( url, {
headers: {
'User-Agent': 'WordPress/inserter-media-fetch',
},
} );
const jsonResponse = await response.json();
const results = jsonResponse.results;
return results.map( ( result ) => ( {
...result,
// If your response result includes an `id` prop that you want to access later, it should
// be mapped to `InserterMediaItem`'s `sourceId` prop. This can be useful if you provide
// a report URL getter.
// Additionally you should always clear the `id` value of your response results because
// it is used to identify WordPress media items.
sourceId: result.id,
id: undefined,
caption: result.caption,
previewUrl: result.thumbnail,
} ) );
},
getReportUrl: ( { sourceId } ) =>
`https://wordpress.org/openverse/image/${ sourceId }/report/`,
isExternalResource: true,
wp.data.dispatch('core/block-editor').registerInserterMediaCategory( {
name: 'openverse',
labels: {
name: 'Openverse',
search_items: 'Search Openverse',
},
mediaType: 'image',
async fetch( query = {} ) {
const defaultArgs = {
mature: false,
excluded_source: 'flickr,inaturalist,wikimedia',
license: 'pdm,cc0',
};
const finalQuery = { ...query, ...defaultArgs };
// Sometimes you might need to map the supported request params according to `InserterMediaRequest`.
// interface. In this example the `search` query param is named `q`.
const mapFromInserterMediaRequest = {
per_page: 'page_size',
search: 'q',
};
const url = new URL( 'https://api.openverse.org/v1/images/' );
Object.entries( finalQuery ).forEach( ( [ key, value ] ) => {
const queryKey = mapFromInserterMediaRequest[ key ] || key;
url.searchParams.set( queryKey, value );
} );
const response = await window.fetch( url, {
headers: {
'User-Agent': 'WordPress/inserter-media-fetch',
},
} );
const jsonResponse = await response.json();
const results = jsonResponse.results;
return results.map( ( result ) => ( {
...result,
// If your response result includes an `id` prop that you want to access later, it should
// be mapped to `InserterMediaItem`'s `sourceId` prop. This can be useful if you provide
// a report URL getter.
// Additionally you should always clear the `id` value of your response results because
// it is used to identify WordPress media items.
sourceId: result.id,
id: undefined,
caption: result.caption,
previewUrl: result.thumbnail,
} ) );
},
getReportUrl: ( { sourceId } ) =>
`https://wordpress.org/openverse/image/${ sourceId }/report/`,
isExternalResource: true,
} );
```

Expand Down Expand Up @@ -1688,7 +1688,7 @@ _Returns_

### setBlockMovingClientId

> **Deprecated**
> **Deprecated**
Set the block moving client ID.

Expand Down Expand Up @@ -1921,4 +1921,5 @@ _Parameters_

- _blocks_ `Array`: Array of blocks.


<!-- END TOKEN(Autogenerated actions|../../../packages/block-editor/src/store/actions.js) -->
Loading

0 comments on commit c79a28d

Please sign in to comment.