docs
This commit is contained in:
20
docs/reference-guides/data/README.md
Normal file
20
docs/reference-guides/data/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# 数据模块参考
|
||||
|
||||
- [**core**:WordPress 核心数据](/docs/reference-guides/data/data-core.md)
|
||||
- [**core/annotations**:注释](/docs/reference-guides/data/data-core-annotations.md)
|
||||
- [**core/block-directory**:区块目录](/docs/reference-guides/data/data-core-block-directory.md)
|
||||
- [**core/block-editor**:区块编辑器的数据](/docs/reference-guides/data/data-core-block-editor.md)
|
||||
- [**core/blocks**:区块类型数据](/docs/reference-guides/data/data-core-blocks.md)
|
||||
- [**core/commands**:命令面板](/docs/reference-guides/data/data-core-commands.md)
|
||||
- [**core/customize-widgets**:自定义小工具](/docs/reference-guides/data/data-core-customize-widgets.md)
|
||||
- [**core/edit-post**:编辑器界面数据](/docs/reference-guides/data/data-core-edit-post.md)
|
||||
- [**core/edit-site**:编辑站点](/docs/reference-guides/data/data-core-edit-site.md)
|
||||
- [**core/edit-widgets**:编辑小工具](/docs/reference-guides/data/data-core-edit-widgets.md)
|
||||
- [**core/editor**:文章编辑器的数据](/docs/reference-guides/data/data-core-editor.md)
|
||||
- [**core/keyboard-shortcuts**:键盘快捷键数据](/docs/reference-guides/data/data-core-keyboard-shortcuts.md)
|
||||
- [**core/notices**:通知数据](/docs/reference-guides/data/data-core-notices.md)
|
||||
- [**core/nux**:NUX(新用户体验)数据](/docs/reference-guides/data/data-core-nux.md)
|
||||
- [**core/preferences**:偏好设置](/docs/reference-guides/data/data-core-preferences.md)
|
||||
- [**core/reusable-blocks**:可复用区块](/docs/reference-guides/data/data-core-reusable-blocks.md)
|
||||
- [**core/rich-text**:富文本](/docs/reference-guides/data/data-core-rich-text.md)
|
||||
- [**core/viewport**:视口数据](/docs/reference-guides/data/data-core-viewport.md)
|
||||
23
docs/reference-guides/data/data-core-annotations.md
Normal file
23
docs/reference-guides/data/data-core-annotations.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 注释功能
|
||||
|
||||
命名空间:`core/annotations`。
|
||||
|
||||
<div class="callout callout-alert">
|
||||
本功能包仍处于实验阶段。“实验性”意味着这是早期实现版本,可能发生重大且不兼容的变更。
|
||||
</div>
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/annotations/src/store/selectors.js) -->
|
||||
|
||||
暂无内容需要记录。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/annotations/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/annotations/src/store/actions.js) -->
|
||||
|
||||
暂无内容需要记录。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/annotations/src/store/actions.js) -->
|
||||
223
docs/reference-guides/data/data-core-block-directory.md
Normal file
223
docs/reference-guides/data/data-core-block-directory.md
Normal file
@@ -0,0 +1,223 @@
|
||||
# 区块目录
|
||||
|
||||
命名空间:`core/block-directory`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/block-directory/src/store/selectors.js) -->
|
||||
|
||||
### getDownloadableBlocks
|
||||
|
||||
返回可用的未安装区块。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _filterValue_ `string`: 搜索关键词
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 可下载区块列表
|
||||
|
||||
### getErrorNoticeForBlock
|
||||
|
||||
返回指定区块的错误通知。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _blockId_ `string`: 区块插件ID,例如:my-block
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string|boolean`: 错误文本,若无错误则返回 false
|
||||
|
||||
### getErrorNotices
|
||||
|
||||
返回所有区块错误通知。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 包含错误通知的对象
|
||||
|
||||
### getInstalledBlockTypes
|
||||
|
||||
返回当前会话中已在服务器上安装的区块类型。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 区块类型项
|
||||
|
||||
### getNewBlockTypes
|
||||
|
||||
返回已在服务器安装并在当前文章中使用的区块类型。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 区块类型项
|
||||
|
||||
### getUnusedBlockTypes
|
||||
|
||||
返回已在服务器安装但未在当前文章中使用的区块类型。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 区块类型项
|
||||
|
||||
### isInstalling
|
||||
|
||||
判断区块插件是否正在安装中。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _blockId_ `string`: 区块ID
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 该区块是否正在安装
|
||||
|
||||
### isRequestingDownloadableBlocks
|
||||
|
||||
判断应用是否正在请求可下载区块。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _filterValue_ `string`: 搜索关键词
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否正在请求区块列表
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/block-directory/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/block-directory/src/store/actions.js) -->
|
||||
|
||||
### addInstalledBlockType
|
||||
|
||||
返回用于将区块类型添加到"新安装"跟踪列表的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _item_ `Object`: 包含区块ID和名称的区块项
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### clearErrorNotice
|
||||
|
||||
清空指定区块的错误通知。
|
||||
|
||||
_参数_
|
||||
|
||||
- _blockId_ `string`: 区块插件ID,例如:my-block
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### fetchDownloadableBlocks
|
||||
|
||||
返回用于表示正在请求和加载可下载区块的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _filterValue_ `string`: 搜索关键词
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### installBlockType
|
||||
|
||||
触发安装区块插件的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _block_ `Object`: 搜索返回的区块项
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 区块是否成功安装和加载
|
||||
|
||||
### receiveDownloadableBlocks
|
||||
|
||||
返回用于表示可下载区块已更新的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _downloadableBlocks_ `Array`: 可下载区块
|
||||
- _filterValue_ `string`: 搜索关键词
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### removeInstalledBlockType
|
||||
|
||||
返回用于从"新安装"跟踪列表中移除区块类型的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _item_ `string`: 包含区块ID和名称的区块项
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### setErrorNotice
|
||||
|
||||
设置要为用户显示的指定区块错误通知。
|
||||
|
||||
_参数_
|
||||
|
||||
- _blockId_ `string`: 区块插件ID,例如:my-block
|
||||
- _message_ `string`: 通知中显示的消息
|
||||
- _isFatal_ `boolean`: 用户是否可以从错误中恢复
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### setIsInstalling
|
||||
|
||||
返回用于指示安装进度的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _blockId_ `string`:
|
||||
- _isInstalling_ `boolean`:
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### uninstallBlockType
|
||||
|
||||
触发卸载区块插件的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _block_ `Object`: 区块类型对象
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/block-directory/src/store/actions.js) -->
|
||||
1878
docs/reference-guides/data/data-core-block-editor.md
Normal file
1878
docs/reference-guides/data/data-core-block-editor.md
Normal file
File diff suppressed because it is too large
Load Diff
721
docs/reference-guides/data/data-core-blocks.md
Normal file
721
docs/reference-guides/data/data-core-blocks.md
Normal file
@@ -0,0 +1,721 @@
|
||||
### hasChildBlocksWithInserterSupport
|
||||
|
||||
返回一个布尔值,用于指示某个区块是否至少拥有一个支持插入器的子区块。
|
||||
|
||||
_使用示例_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const navigationBlockHasChildBlocksWithInserterSupport = useSelect(
|
||||
( select ) =>
|
||||
select( blocksStore ).hasChildBlocksWithInserterSupport(
|
||||
'core/navigation'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__(
|
||||
'core/navigation 区块拥有支持插入器的子区块:%s'
|
||||
),
|
||||
navigationBlockHasChildBlocksWithInserterSupport
|
||||
) }
|
||||
</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数说明_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _blockName_ `string`: 区块类型名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 如果区块包含至少一个支持插入器的子区块则返回 true,否则返回 false。
|
||||
|
||||
### isMatchingSearchTerm
|
||||
|
||||
如果给定名称或对象值的区块类型与搜索词匹配则返回 true,否则返回 false。
|
||||
|
||||
_使用示例_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const termFound = useSelect(
|
||||
( select ) =>
|
||||
select( blocksStore ).isMatchingSearchTerm(
|
||||
'core/navigation',
|
||||
'theme'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__(
|
||||
'在 block.json 的标题、关键词、分类或描述中找到搜索词:%s'
|
||||
),
|
||||
termFound
|
||||
) }
|
||||
</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数说明_
|
||||
|
||||
- _state_ `Object`: 区块状态。
|
||||
- _nameOrType_ `(string|Object)`: 区块名称或类型对象。
|
||||
- _searchTerm_ `string`: 用于筛选的搜索词。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object[]`: 区块类型是否与搜索词匹配。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/blocks/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
此包中的操作不应直接使用。请改用[公共 API](/packages/blocks/README.md) 中列出的函数。
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) -->
|
||||
|
||||
### reapplyBlockTypeFilters
|
||||
|
||||
发出信号表示应重新计算所有区块类型。该操作使用存储的未处理区块类型和最近注册的所有筛选器列表。
|
||||
|
||||
它解决了第三方区块筛选器在第三方区块之后注册的问题。示例顺序:1. 筛选器 A → 2. 区块 B → 3. 区块 C → 4. 筛选器 D → 5. 筛选器 E → 6. 区块 F → 7. 筛选器 G。在此场景中,部分筛选器因注册过晚而无法应用于所有区块。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) -->
|
||||
|
||||
### getFreeformFallbackBlockName
|
||||
|
||||
返回用于处理非区块内容的区块名称。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const freeformFallbackBlockName = useSelect(
|
||||
( select ) => select( blocksStore ).getFreeformFallbackBlockName(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
freeformFallbackBlockName && (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( '自由形态降级区块名称:%s' ),
|
||||
freeformFallbackBlockName
|
||||
) }
|
||||
</p>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 用于处理非区块内容的区块名称。
|
||||
|
||||
### getGroupingBlockName
|
||||
|
||||
返回用于处理区块分组的区块名称。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const groupingBlockName = useSelect(
|
||||
( select ) => select( blocksStore ).getGroupingBlockName(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
groupingBlockName && (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( '默认分组区块名称:%s' ),
|
||||
groupingBlockName
|
||||
) }
|
||||
</p>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 用于处理区块分组的区块名称。
|
||||
|
||||
### getUnregisteredFallbackBlockName
|
||||
|
||||
返回用于处理未注册区块的区块名称。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const unregisteredFallbackBlockName = useSelect(
|
||||
( select ) => select( blocksStore ).getUnregisteredFallbackBlockName(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
unregisteredFallbackBlockName && (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( '未注册降级区块名称:%s' ),
|
||||
unregisteredFallbackBlockName
|
||||
) }
|
||||
</p>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 用于处理未注册区块的区块名称。
|
||||
|
||||
### hasBlockSupport
|
||||
|
||||
如果区块定义了特定功能的支持则返回 true,否则返回 false。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const paragraphBlockSupportClassName = useSelect( ( select ) =>
|
||||
select( blocksStore ).hasBlockSupport( 'core/paragraph', 'className' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( 'core/paragraph 是否支持自定义类名:%s' ),
|
||||
paragraphBlockSupportClassName
|
||||
) }
|
||||
</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _nameOrType_ `(string|Object)`: 区块名称或类型对象。
|
||||
- _feature_ `string`: 要测试的功能特性。
|
||||
- _defaultSupports_ `boolean`: 未显式定义时是否默认支持该功能。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 区块是否支持该功能。
|
||||
|
||||
### hasChildBlocks
|
||||
|
||||
返回一个布尔值,指示区块是否包含子区块。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const navigationBlockHasChildBlocks = useSelect(
|
||||
( select ) => select( blocksStore ).hasChildBlocks( 'core/navigation' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( 'core/navigation 是否包含子区块:%s' ),
|
||||
navigationBlockHasChildBlocks
|
||||
) }
|
||||
</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _blockName_ `string`: 区块类型名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 如果区块包含子区块则为 true,否则为 false。
|
||||
|
||||
# 区块类型数据
|
||||
|
||||
命名空间:`core/blocks`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/blocks/src/store/selectors.js) -->
|
||||
|
||||
### getActiveBlockVariation
|
||||
|
||||
根据区块属性返回指定区块的激活变体。变体通过其 `isActive` 属性确定,该属性可以是区块属性键的数组或函数。
|
||||
|
||||
当为区块属性键数组时,将使用严格相等性检查将 `attributes` 与变体的属性进行比较。
|
||||
|
||||
当为函数类型时,该函数应接受区块属性和变体属性,并确定变体是否处于激活状态。该函数接受区块属性和变体属性,并确定变体是否处于激活状态。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { store as blockEditorStore } from '@wordpress/block-editor';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
// 此示例假设 core/embed 区块是区块编辑器中的第一个区块
|
||||
const activeBlockVariation = useSelect( ( select ) => {
|
||||
// 获取区块列表
|
||||
const [ firstBlock ] = select( blockEditorStore ).getBlocks();
|
||||
|
||||
// 返回第一个区块的激活区块变体
|
||||
return select( blocksStore ).getActiveBlockVariation(
|
||||
firstBlock.name,
|
||||
firstBlock.attributes
|
||||
);
|
||||
}, [] );
|
||||
|
||||
return activeBlockVariation && activeBlockVariation.name === 'spotify' ? (
|
||||
<p>{ __( 'Spotify 变体' ) }</p>
|
||||
) : (
|
||||
<p>{ __( '其他变体' ) }</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态
|
||||
- _blockName_ `string`: 区块名称(例如:"core/columns")
|
||||
- _attributes_ `Object`: 用于确定激活变体的区块属性
|
||||
- _scope_ `[WPBlockVariationScope]`: 区块变体作用域名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `(WPBlockVariation|undefined)`: 激活的区块变体
|
||||
|
||||
### getBlockStyles
|
||||
|
||||
通过区块名称返回区块样式。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const buttonBlockStyles = useSelect(
|
||||
( select ) => select( blocksStore ).getBlockStyles( 'core/button' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ buttonBlockStyles &&
|
||||
buttonBlockStyles.map( ( style ) => (
|
||||
<li key={ style.name }>{ style.label }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态
|
||||
- _name_ `string`: 区块类型名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array?`: 区块样式
|
||||
|
||||
### getBlockSupport
|
||||
|
||||
返回指定功能的区块支持值(如果已定义)。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const paragraphBlockSupportValue = useSelect(
|
||||
( select ) =>
|
||||
select( blocksStore ).getBlockSupport( 'core/paragraph', 'anchor' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( 'core/paragraph 支持的 anchor 值:%s' ),
|
||||
paragraphBlockSupportValue
|
||||
) }
|
||||
</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态
|
||||
- _nameOrType_ `(string|Object)`: 区块名称或类型对象
|
||||
- _feature_ `Array|string`: 要检索的功能
|
||||
- _defaultSupports_ `*`: 未明确定义时返回的默认值
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?*`: 区块支持值
|
||||
|
||||
### getBlockType
|
||||
|
||||
通过名称返回区块类型。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const paragraphBlock = useSelect(
|
||||
( select ) => ( select ) =>
|
||||
select( blocksStore ).getBlockType( 'core/paragraph' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ paragraphBlock &&
|
||||
Object.entries( paragraphBlock.supports ).map(
|
||||
( blockSupportsEntry ) => {
|
||||
const [ propertyName, value ] = blockSupportsEntry;
|
||||
return (
|
||||
<li
|
||||
key={ propertyName }
|
||||
>{ `${ propertyName } : ${ value }` }</li>
|
||||
);
|
||||
}
|
||||
) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态
|
||||
- _name_ `string`: 区块类型名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?Object`: 区块类型
|
||||
|
||||
### getBlockTypes
|
||||
|
||||
返回所有可用的区块类型。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const blockTypes = useSelect(
|
||||
( select ) => select( blocksStore ).getBlockTypes(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ blockTypes.map( ( block ) => (
|
||||
<li key={ block.name }>{ block.title }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 区块类型数组。
|
||||
|
||||
### getBlockVariations
|
||||
|
||||
根据区块名称返回区块变体。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const socialLinkVariations = useSelect(
|
||||
( select ) =>
|
||||
select( blocksStore ).getBlockVariations( 'core/social-link' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ socialLinkVariations &&
|
||||
socialLinkVariations.map( ( variation ) => (
|
||||
<li key={ variation.name }>{ variation.title }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _blockName_ `string`: 区块类型名称。
|
||||
- _scope_ `[WPBlockVariationScope]`: 区块变体作用域名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `(WPBlockVariation[]|void)`: 区块变体数组。
|
||||
|
||||
### getCategories
|
||||
|
||||
返回所有可用的区块分类。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const blockCategories = useSelect(
|
||||
( select ) => select( blocksStore ).getCategories(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ blockCategories.map( ( category ) => (
|
||||
<li key={ category.slug }>{ category.title }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `WPBlockCategory[]`: 分类列表。
|
||||
|
||||
### getChildBlockNames
|
||||
|
||||
返回指定区块的子区块数组。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const childBlockNames = useSelect(
|
||||
( select ) =>
|
||||
select( blocksStore ).getChildBlockNames( 'core/navigation' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ childBlockNames &&
|
||||
childBlockNames.map( ( child ) => (
|
||||
<li key={ child }>{ child }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _blockName_ `string`: 区块类型名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 子区块名称数组。
|
||||
|
||||
### getCollections
|
||||
|
||||
返回所有可用的集合。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const blockCollections = useSelect(
|
||||
( select ) => select( blocksStore ).getCollections(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{ Object.values( blockCollections ).length > 0 &&
|
||||
Object.values( blockCollections ).map( ( collection ) => (
|
||||
<li key={ collection.title }>{ collection.title }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 集合列表。
|
||||
|
||||
### getDefaultBlockName
|
||||
|
||||
返回默认区块名称。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const defaultBlockName = useSelect(
|
||||
( select ) => select( blocksStore ).getDefaultBlockName(),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
defaultBlockName && (
|
||||
<p>
|
||||
{ sprintf( __( '默认区块名称: %s' ), defaultBlockName ) }
|
||||
</p>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 默认区块名称。
|
||||
|
||||
### getDefaultBlockVariation
|
||||
|
||||
返回指定区块类型的默认区块变体。当存在多个标记为默认的变体时,将选择最后添加的项。这简化了注册覆盖操作。当未设置默认变体时,返回第一个项。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as blocksStore } from '@wordpress/blocks';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const defaultEmbedBlockVariation = useSelect(
|
||||
( select ) =>
|
||||
select( blocksStore ).getDefaultBlockVariation( 'core/embed' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
defaultEmbedBlockVariation && (
|
||||
<p>
|
||||
{ sprintf(
|
||||
__( 'core/embed 默认变体: %s' ),
|
||||
defaultEmbedBlockVariation.title
|
||||
) }
|
||||
</p>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _blockName_ `string`: 区块类型名称。
|
||||
- _scope_ `[WPBlockVariationScope]`: 区块变体作用域名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?WPBlockVariation`: 默认区块变体。
|
||||
129
docs/reference-guides/data/data-core-commands.md
Normal file
129
docs/reference-guides/data/data-core-commands.md
Normal file
@@ -0,0 +1,129 @@
|
||||
# 命令数据
|
||||
|
||||
命名空间:`core/commands`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.js) -->
|
||||
|
||||
### getCommandLoaders
|
||||
|
||||
返回已注册的命令加载器。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 状态树
|
||||
- _contextual_ `boolean`: 是否仅返回上下文相关的命令加载器
|
||||
|
||||
_返回值_
|
||||
|
||||
- `import('./actions').WPCommandLoaderConfig[]`: 已注册的命令加载器列表
|
||||
|
||||
### getCommands
|
||||
|
||||
返回已注册的静态命令。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 状态树
|
||||
- _contextual_ `boolean`: 是否仅返回上下文相关的命令
|
||||
|
||||
_返回值_
|
||||
|
||||
- `import('./actions').WPCommandConfig[]`: 已注册的命令列表
|
||||
|
||||
### getContext
|
||||
|
||||
返回当前活动上下文。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 状态树
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string`: 上下文
|
||||
|
||||
### isOpen
|
||||
|
||||
返回命令面板是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 状态树
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 返回命令面板是否打开
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/commands/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.js) -->
|
||||
|
||||
### close
|
||||
|
||||
关闭命令面板。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### open
|
||||
|
||||
打开命令面板。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### registerCommand
|
||||
|
||||
返回用于注册新命令的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _config_ `WPCommandConfig`: 命令配置
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### registerCommandLoader
|
||||
|
||||
注册命令加载器。
|
||||
|
||||
_参数_
|
||||
|
||||
- _config_ `WPCommandLoaderConfig`: 命令加载器配置
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### unregisterCommand
|
||||
|
||||
返回用于取消注册命令的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _name_ `string`: 命令名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### unregisterCommandLoader
|
||||
|
||||
取消注册命令加载器钩子。
|
||||
|
||||
_参数_
|
||||
|
||||
- _name_ `string`: 命令加载器名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/commands/src/store/actions.js) -->
|
||||
86
docs/reference-guides/data/data-core-customize-widgets.md
Normal file
86
docs/reference-guides/data/data-core-customize-widgets.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# 自定义小工具
|
||||
|
||||
命名空间:`core/customize-widgets`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/customize-widgets/src/store/selectors.js) -->
|
||||
|
||||
### isInserterOpened
|
||||
|
||||
判断插入器是否开启时返回 true
|
||||
|
||||
_使用示例_
|
||||
|
||||
```js
|
||||
import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { isInserterOpened } = useSelect(
|
||||
( select ) => select( customizeWidgetsStore ),
|
||||
[]
|
||||
);
|
||||
|
||||
return isInserterOpened()
|
||||
? __( '插入器已开启' )
|
||||
: __( '插入器已关闭' );
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 插入器是否开启
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/customize-widgets/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/customize-widgets/src/store/actions.js) -->
|
||||
|
||||
### setIsInserterOpened
|
||||
|
||||
返回用于开启/关闭插入器的操作对象
|
||||
|
||||
_使用示例_
|
||||
|
||||
```js
|
||||
import { useState } from 'react';
|
||||
import { store as customizeWidgetsStore } from '@wordpress/customize-widgets';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { setIsInserterOpened } = useDispatch( customizeWidgetsStore );
|
||||
const [ isOpen, setIsOpen ] = useState( false );
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={ () => {
|
||||
setIsInserterOpened( ! isOpen );
|
||||
setIsOpen( ! isOpen );
|
||||
} }
|
||||
>
|
||||
{ __( '开启/关闭插入器' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _value_ `boolean|Object`: 插入器应开启(true)或关闭(false)。要指定插入位置,请使用对象格式
|
||||
- _value.rootClientId_ `string`: 要插入的根客户端ID
|
||||
- _value.insertionIndex_ `number`: 要插入的索引位置
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/customize-widgets/src/store/actions.js) -->
|
||||
559
docs/reference-guides/data/data-core-edit-post.md
Normal file
559
docs/reference-guides/data/data-core-edit-post.md
Normal file
@@ -0,0 +1,559 @@
|
||||
### openPublishSidebar
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于通知用户已打开发布侧边栏的动作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`:动作对象
|
||||
|
||||
### removeEditorPanel
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于从编辑器中移除面板的动作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _panelName_ `string`:标识要移除的面板的字符串。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`:动作对象。
|
||||
|
||||
### requestMetaBoxUpdates
|
||||
|
||||
更新元数据框。
|
||||
|
||||
### setAvailableMetaBoxesPerLocation
|
||||
|
||||
存储关于哪些元数据框在哪些位置可用的信息。
|
||||
|
||||
_参数_
|
||||
|
||||
- _metaBoxesPerLocation_ `Object`:每个位置的元数据框。
|
||||
|
||||
### setIsEditingTemplate
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于切换到模板编辑的动作对象。
|
||||
|
||||
### setIsInserterOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于打开/关闭插入器的动作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _value_ `boolean|Object`:插入器应打开(true)还是关闭(false)。
|
||||
|
||||
### setIsListViewOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于打开/关闭列表视图的动作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _isOpen_ `boolean`:表示列表视图应打开还是关闭的布尔值。
|
||||
|
||||
### showBlockTypes
|
||||
|
||||
将提供的区块类型更新为可见。
|
||||
|
||||
_参数_
|
||||
|
||||
- _blockNames_ `string[]`:要显示的区块类型的名称。
|
||||
|
||||
### switchEditorMode
|
||||
|
||||
> **已弃用**
|
||||
|
||||
触发用于切换编辑器模式的动作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _mode_ `string`:编辑器模式。
|
||||
|
||||
### toggleDistractionFree
|
||||
|
||||
> **已弃用**
|
||||
|
||||
切换无干扰模式的动作。无干扰模式下预期没有侧边栏,因为设置的 z-index 值会导致无法关闭侧边栏。
|
||||
|
||||
### toggleEditorPanelEnabled
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于启用或禁用编辑器中面板的动作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _panelName_ `string`:标识要启用或禁用的面板的字符串。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`:动作对象。
|
||||
|
||||
### toggleEditorPanelOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
打开已关闭的面板并关闭已打开的面板。
|
||||
|
||||
_参数_
|
||||
|
||||
- _panelName_ `string`:标识要打开或关闭的面板的字符串。
|
||||
|
||||
### toggleFeature
|
||||
|
||||
触发用于切换功能标志的动作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _feature_ `string`:功能名称。
|
||||
|
||||
### toggleFullscreenMode
|
||||
|
||||
切换全屏模式视图选项的动作。
|
||||
|
||||
### togglePinnedPluginItem
|
||||
|
||||
触发用于切换插件名称标志的动作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _pluginName_ `string`:插件名称。
|
||||
|
||||
### togglePublishSidebar
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于通知用户切换发布侧边栏的动作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`:动作对象
|
||||
|
||||
### updatePreferredStyleVariations
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于通知在创建区块时应自动应用样式的动作对象。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/edit-post/src/store/actions.js) -->
|
||||
|
||||
# 编辑器界面数据
|
||||
|
||||
命名空间:`core/edit-post`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/edit-post/src/store/selectors.js) -->
|
||||
|
||||
### areMetaBoxesInitialized
|
||||
|
||||
判断元框是否已完成初始化。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 元框是否已初始化
|
||||
|
||||
### getActiveGeneralSidebarName
|
||||
|
||||
返回当前活动的通用侧边栏名称,若无活动侧边栏则返回null。活动通用侧边栏是用于识别编辑器或插件侧边栏的唯一名称。
|
||||
|
||||
示例:
|
||||
|
||||
- `edit-post/document`
|
||||
- `my-plugin/insert-image-sidebar`
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 活动通用侧边栏名称
|
||||
|
||||
### getActiveMetaBoxLocations
|
||||
|
||||
返回活动元框位置的数组。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 文章编辑器状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string[]`: 活动元框位置
|
||||
|
||||
### getAllMetaBoxes
|
||||
|
||||
返回所有可用元框的列表。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 元框列表
|
||||
|
||||
### getEditedPostTemplate
|
||||
|
||||
获取当前编辑文章的模板。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?Object`: 文章模板
|
||||
|
||||
### getEditorMode
|
||||
|
||||
返回当前编辑模式。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string`: 编辑模式
|
||||
|
||||
### getHiddenBlockTypes
|
||||
|
||||
返回被隐藏的区块数组。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 隐藏区块类型列表
|
||||
|
||||
### getMetaBoxesPerLocation
|
||||
|
||||
返回指定位置的所有可用元框列表。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _location_ `string`: 要检测的元框位置
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?Array`: 元框列表
|
||||
|
||||
### getPreference
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _preferenceKey_ `string`: 偏好设置键名
|
||||
- _defaultValue_ `*`: 默认值
|
||||
|
||||
_返回值_
|
||||
|
||||
- `*`: 偏好设置值
|
||||
|
||||
### getPreferences
|
||||
|
||||
返回偏好设置(这些设置会在本地持久化保存)。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 偏好设置对象
|
||||
|
||||
### hasMetaBoxes
|
||||
|
||||
判断文章是否正在使用元框。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否存在元框
|
||||
|
||||
### isEditingTemplate
|
||||
|
||||
> **已弃用**
|
||||
|
||||
判断是否启用了模板编辑模式。
|
||||
|
||||
### isEditorPanelEnabled
|
||||
|
||||
> **已弃用**
|
||||
|
||||
判断指定面板是否启用,面板默认处于启用状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _panelName_ `string`: 面板标识字符串
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 面板是否启用
|
||||
|
||||
### isEditorPanelOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
判断指定面板是否打开,面板默认处于关闭状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _panelName_ `string`: 面板标识字符串
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 面板是否打开
|
||||
|
||||
### isEditorPanelRemoved
|
||||
|
||||
> **已弃用**
|
||||
|
||||
判断指定面板是否已被程序化移除,所有面板默认不会被移除。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _panelName_ `string`: 面板标识字符串
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 面板是否已被移除
|
||||
|
||||
### isEditorSidebarOpened
|
||||
|
||||
判断编辑器侧边栏是否打开。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 编辑器侧边栏是否打开
|
||||
|
||||
### isFeatureActive
|
||||
|
||||
判断指定功能是否启用。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态
|
||||
- _feature_ `string`: 功能标识符
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否处于活动状态
|
||||
|
||||
### isInserterOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回插入器是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 插入器是否已打开。
|
||||
|
||||
### isListViewOpened
|
||||
|
||||
返回列表视图是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 列表视图是否已打开。
|
||||
|
||||
### isMetaBoxLocationActive
|
||||
|
||||
如果给定位置存在活动的元框则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 文章编辑器状态。
|
||||
- _location_ `string`: 要测试的元框位置。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 元框位置是否处于活动状态。
|
||||
|
||||
### isMetaBoxLocationVisible
|
||||
|
||||
如果元框位置处于活动状态且可见则返回 true。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 文章编辑器状态。
|
||||
- _location_ `string`: 要测试的元框位置。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 元框位置是否处于活动且可见状态。
|
||||
|
||||
### isModalActive
|
||||
|
||||
> **已弃用**(自 WP 6.3 起,请改用 `core/interface` 存储中间名选择器)
|
||||
|
||||
如果模态框处于活动状态则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
- _modalName_ `string`: 唯一标识模态框的字符串。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 模态框是否处于活动状态。
|
||||
|
||||
### isPluginItemPinned
|
||||
|
||||
如果插件项已固定到标题区域则返回 true。未设置值时默认返回 true。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
- _pluginName_ `string`: 插件项名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 插件项是否已固定。
|
||||
|
||||
### isPluginSidebarOpened
|
||||
|
||||
返回插件侧边栏是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 插件侧边栏是否已打开。
|
||||
|
||||
### isPublishSidebarOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回发布侧边栏是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 发布侧边栏是否已打开。
|
||||
|
||||
### isSavingMetaBoxes
|
||||
|
||||
如果元框正在保存则返回 true。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 元框是否正在保存。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/edit-post/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/edit-post/src/store/actions.js) -->
|
||||
|
||||
### closeGeneralSidebar
|
||||
|
||||
返回表示用户关闭侧边栏的操作对象。
|
||||
|
||||
### closeModal
|
||||
|
||||
> **已弃用**(自 WP 6.3 起,请改用 `core/interface` 存储中间名操作)
|
||||
|
||||
返回表示用户关闭模态框的操作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### closePublishSidebar
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回表示用户关闭发布侧边栏的操作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### hideBlockTypes
|
||||
|
||||
将指定区块类型设置为隐藏状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _blockNames_ `string[]`: 需要隐藏的区块类型名称。
|
||||
|
||||
### initializeMetaBoxes
|
||||
|
||||
初始化 WordPress `postboxes` 脚本及元框保存逻辑。
|
||||
|
||||
### metaBoxUpdatesFailure
|
||||
|
||||
返回表示元框更新失败的操作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### metaBoxUpdatesSuccess
|
||||
|
||||
返回表示元框更新成功的操作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### openGeneralSidebar
|
||||
|
||||
返回表示用户打开编辑器侧边栏的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _name_ `?string`: 要打开的侧边栏名称。
|
||||
|
||||
### openModal
|
||||
|
||||
> **已弃用**(自 WP 6.3 起,请改用 `core/interface` 存储中间名操作)
|
||||
|
||||
返回表示用户打开模态框的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _name_ `string`: 唯一标识模态框的字符串。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
448
docs/reference-guides/data/data-core-edit-site.md
Normal file
448
docs/reference-guides/data/data-core-edit-site.md
Normal file
@@ -0,0 +1,448 @@
|
||||
# 编辑站点
|
||||
|
||||
命名空间:`core/edit-site`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/edit-site/src/store/selectors.js) -->
|
||||
|
||||
### getCanUserCreateMedia
|
||||
|
||||
返回当前用户是否可创建媒体。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 当前用户是否可创建媒体。
|
||||
|
||||
### getCurrentTemplateNavigationPanelSubMenu
|
||||
|
||||
> **已弃用**
|
||||
|
||||
### getCurrentTemplateTemplateParts
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回当前编辑模板的模板部件及其区块。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 包含模板部件及其区块的数组。
|
||||
|
||||
### getEditedPostContext
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回已编辑文章的背景对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 页面对象。
|
||||
|
||||
### getEditedPostId
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回当前编辑的模板或模板部件的ID。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 文章ID。
|
||||
|
||||
### getEditedPostType
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回当前编辑的文章类型(wp_template 或 wp_template_part)。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?TemplateType`: 模板类型。
|
||||
|
||||
### getEditorMode
|
||||
|
||||
返回当前编辑模式。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string`: 编辑模式。
|
||||
|
||||
### getHomeTemplateId
|
||||
|
||||
> **已弃用**
|
||||
|
||||
### getNavigationPanelActiveMenu
|
||||
|
||||
> **已弃用**
|
||||
|
||||
### getPage
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回当前页面对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 页面对象。
|
||||
|
||||
### getReusableBlocks
|
||||
|
||||
返回所有可用的可重用区块。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 可用的可重用区块。
|
||||
|
||||
### getSettings
|
||||
|
||||
返回站点编辑器设置。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 设置对象。
|
||||
|
||||
### hasPageContentFocus
|
||||
|
||||
> **已弃用**
|
||||
|
||||
判断编辑器是否仅允许编辑页面内容。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否聚焦于编辑页面内容。
|
||||
|
||||
### isFeatureActive
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回指定功能是否启用。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
- _featureName_ `string`: 功能标识符。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否启用。
|
||||
|
||||
### isInserterOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
如果插入器已打开则返回true。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 插入器是否打开。
|
||||
|
||||
### isListViewOpened
|
||||
|
||||
如果列表视图已打开则返回true。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 列表视图是否打开。
|
||||
|
||||
### isNavigationOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
### isPage
|
||||
|
||||
> **已弃用**
|
||||
|
||||
判断编辑器是否已加载页面。
|
||||
|
||||
_相关_
|
||||
|
||||
- setPage
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 编辑器是否已加载页面。
|
||||
|
||||
### isSaveViewOpened
|
||||
|
||||
返回保存面板当前的打开/关闭状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 如果保存面板应打开则为true,关闭则为false。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/edit-site/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/edit-site/src/store/actions.js) -->
|
||||
|
||||
### addTemplate
|
||||
|
||||
> **已弃用**
|
||||
|
||||
添加新模板并设置为当前模板的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _template_ `Object`: 模板对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 用于设置当前模板的操作对象。
|
||||
|
||||
### closeGeneralSidebar
|
||||
|
||||
关闭侧边栏的操作。
|
||||
|
||||
### openGeneralSidebar
|
||||
|
||||
打开编辑器侧边栏的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _name_ `?string`: 要打开的侧边栏名称。
|
||||
|
||||
### openNavigationPanelToMenu
|
||||
|
||||
> **已弃用**
|
||||
|
||||
同时打开导航面板并设置其活动菜单。
|
||||
|
||||
### removeTemplate
|
||||
|
||||
移除模板的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _template_ `Object`: 模板对象。
|
||||
|
||||
### revertTemplate
|
||||
|
||||
将模板恢复至原始主题提供的文件。
|
||||
|
||||
_参数_
|
||||
|
||||
- _template_ `Object`: 要恢复的模板。
|
||||
- _options_ `[Object]`:
|
||||
- _options.allowUndo_ `[boolean]`: 是否允许用户撤销恢复模板操作。默认为true。
|
||||
|
||||
### setEditedEntity
|
||||
|
||||
> **已弃用**
|
||||
|
||||
设置已编辑实体的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _postType_ `string`: 实体的文章类型。
|
||||
- _postId_ `string`: 实体的ID。
|
||||
- _context_ `Object`: 实体的上下文。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setEditedPostContext
|
||||
|
||||
> **已弃用**
|
||||
|
||||
设置当前区块编辑器上下文。
|
||||
|
||||
_参数_
|
||||
|
||||
- _context_ `Object`: 上下文对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setHasPageContentFocus
|
||||
|
||||
设置编辑器是否仅允许编辑页面内容。
|
||||
|
||||
_参数_
|
||||
|
||||
- _hasPageContentFocus_ `boolean`: 为true时仅允许编辑页面内容,为false时允许编辑模板。
|
||||
|
||||
### setHomeTemplateId
|
||||
|
||||
> **已弃用**
|
||||
|
||||
### setIsInserterOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于打开/关闭插入器的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _value_ `boolean|Object`: 插入器应打开(true)或关闭(false)。
|
||||
|
||||
### setIsListViewOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
返回用于打开/关闭列表视图的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _isOpen_ `boolean`: 表示列表视图应打开或关闭的布尔值。
|
||||
|
||||
### setIsNavigationPanelOpened
|
||||
|
||||
> **已弃用**
|
||||
|
||||
设置导航面板是否应打开。
|
||||
|
||||
### setIsSaveViewOpened
|
||||
|
||||
设置保存视图面板是否应打开。
|
||||
|
||||
_参数_
|
||||
|
||||
- _isOpen_ `boolean`: 为true时打开保存视图,为false时关闭。此操作不切换状态,而是直接设置状态。
|
||||
|
||||
### setNavigationMenu
|
||||
|
||||
> **已弃用**
|
||||
|
||||
设置导航菜单的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _navigationMenuId_ `string`: 导航菜单文章ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setNavigationPanelActiveMenu
|
||||
|
||||
> **已弃用**
|
||||
|
||||
设置活动导航面板菜单的操作。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setPage
|
||||
|
||||
> **已弃用**
|
||||
|
||||
解析页面模板并同时显示两者。如果未提供路径,则尝试使用postId生成类似`?p=${ postId }`的路径。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setTemplate
|
||||
|
||||
设置模板的操作,可选择从REST API获取。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setTemplatePart
|
||||
|
||||
> **已弃用**
|
||||
|
||||
设置模板部件的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _templatePartId_ `string`: 模板部件ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### switchEditorMode
|
||||
|
||||
> **已弃用**
|
||||
|
||||
触发用于切换编辑器模式的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _mode_ `string`: 编辑器模式。
|
||||
|
||||
### toggleDistractionFree
|
||||
|
||||
> **已弃用**
|
||||
|
||||
切换无干扰模式的操作。无干扰模式下预期无侧边栏,因为设置的z-index值会导致无法关闭侧边栏。
|
||||
|
||||
### toggleFeature
|
||||
|
||||
触发切换功能标志的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _featureName_ `string`: 功能名称。
|
||||
|
||||
### updateSettings
|
||||
|
||||
返回用于更新设置的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _settings_ `Object`: 新设置。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/edit-site/src/store/actions.js) -->
|
||||
362
docs/reference-guides/data/data-core-edit-widgets.md
Normal file
362
docs/reference-guides/data/data-core-edit-widgets.md
Normal file
@@ -0,0 +1,362 @@
|
||||
# 编辑小工具
|
||||
|
||||
命名空间:`core/edit-widgets`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/edit-widgets/src/store/selectors.js) -->
|
||||
|
||||
### canInsertBlockInWidgetArea
|
||||
|
||||
判断是否可以将区块插入到小工具区域。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Array`: 小工具区域的打开状态。
|
||||
- _blockName_ `string`: 要插入的区块名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 如果区块可以插入到小工具区域则返回 true。
|
||||
|
||||
### getEditedWidgetAreas
|
||||
|
||||
返回所有已编辑的小工具区域实体记录。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object[]`: 已编辑的小工具区域实体记录列表。
|
||||
|
||||
### getIsWidgetAreaOpen
|
||||
|
||||
获取小工具区域是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Array`: 小工具区域的打开状态。
|
||||
- _clientId_ `string`: 小工具区域的客户端 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 如果小工具区域处于打开状态则返回 true。
|
||||
|
||||
### getParentWidgetAreaBlock
|
||||
|
||||
根据子级客户端 ID 返回父级小工具区域区块。
|
||||
|
||||
_参数_
|
||||
|
||||
- _clientId_ `string`: 小工具区域中某个区块的客户端 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `WPBlock`: 小工具区域区块。
|
||||
|
||||
### getReferenceWidgetBlocks
|
||||
|
||||
返回所有表示引用小工具的区块。
|
||||
|
||||
_参数_
|
||||
|
||||
- _referenceWidgetName_ `string`: 可选参数。如果指定,则只返回具有此名称的引用小工具。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 表示引用小工具的所有区块列表。
|
||||
|
||||
### getWidget
|
||||
|
||||
返回特定小工具 ID 的 API 小工具数据。
|
||||
|
||||
_参数_
|
||||
|
||||
- _id_ `number`: 小工具 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 特定小工具 ID 的 API 小工具数据。
|
||||
|
||||
### getWidgetAreaForWidgetId
|
||||
|
||||
返回包含指定 widgetId 所标识区块的小工具区域。
|
||||
|
||||
_参数_
|
||||
|
||||
- _widgetId_ `string`: 小工具的 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 包含小工具区域的对象。
|
||||
|
||||
### getWidgetAreas
|
||||
|
||||
返回所有 API 小工具区域。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object[]`: API 小工具区域列表。
|
||||
|
||||
### getWidgets
|
||||
|
||||
返回所有 API 小工具。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object[]`: API 小工具列表。
|
||||
|
||||
### isInserterOpened
|
||||
|
||||
判断插入器是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 插入器是否处于打开状态。
|
||||
|
||||
### isListViewOpened
|
||||
|
||||
判断列表视图是否处于打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 列表视图是否处于打开状态。
|
||||
|
||||
### isSavingWidgetAreas
|
||||
|
||||
判断是否有小工具区域正在被保存。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 如果有小工具区域正在被保存则返回 true,否则返回 false。
|
||||
|
||||
### isWidgetSavingLocked
|
||||
|
||||
返回小工具保存是否被锁定。
|
||||
|
||||
_用法_
|
||||
|
||||
```jsx
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { store as widgetStore } from '@wordpress/edit-widgets';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const isSavingLocked = useSelect(
|
||||
( select ) => select( widgetStore ).isWidgetSavingLocked(),
|
||||
[]
|
||||
);
|
||||
|
||||
return isSavingLocked ? (
|
||||
<p>{ __( '小工具保存已被锁定' ) }</p>
|
||||
) : (
|
||||
<p>{ __( '小工具保存未被锁定' ) }</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否被锁定。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/edit-widgets/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/edit-widgets/src/store/actions.js) -->
|
||||
|
||||
### closeGeneralSidebar
|
||||
|
||||
返回表示用户关闭侧边栏的操作对象。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作创建器。
|
||||
|
||||
### lockWidgetSaving
|
||||
|
||||
返回用于表示小工具保存被锁定的操作对象。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as widgetStore } from '@wordpress/edit-widgets';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { lockWidgetSaving } = useDispatch( widgetStore );
|
||||
return (
|
||||
<Button onClick={ () => lockWidgetSaving( 'lockName' ) }>
|
||||
{ __( '锁定小工具保存' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _lockName_ `string`: 锁名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### moveBlockToWidgetArea
|
||||
|
||||
处理在小工具区域之间移动区块的操作。
|
||||
|
||||
_参数_
|
||||
|
||||
- _clientId_ `string`: 要移动区块的客户端 ID。
|
||||
- _widgetAreaId_ `string`: 要将区块移动到的目标小工具区域 ID。
|
||||
|
||||
### persistStubPost
|
||||
|
||||
将指定 ID 的存根文章持久化到核心数据存储中。该文章仅存在于内存中,不应通过 API 保存。
|
||||
|
||||
_参数_
|
||||
|
||||
- _id_ `string`: 文章 ID。
|
||||
- _blocks_ `Array`: 文章应包含的区块。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 文章对象。
|
||||
|
||||
### saveEditedWidgetAreas
|
||||
|
||||
将已编辑小工具区域中的所有区块转换为小工具,并提交批量请求一次性保存所有内容。
|
||||
|
||||
在成功或出错时创建 snackbar 通知。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Function`: 操作创建器。
|
||||
|
||||
### saveWidgetArea
|
||||
|
||||
将指定 ID 的小工具区域中的所有区块转换为小工具,并提交批量请求一次性保存所有内容。
|
||||
|
||||
_参数_
|
||||
|
||||
- _widgetAreaId_ `string`: 要处理的小工具区域 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Function`: 操作创建器。
|
||||
|
||||
### saveWidgetAreas
|
||||
|
||||
将指定小工具区域中的所有区块转换为小工具,并提交批量请求一次性保存所有内容。
|
||||
|
||||
_参数_
|
||||
|
||||
- _widgetAreas_ `Object[]`: 要保存的小工具区域。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Function`: 操作创建器。
|
||||
|
||||
### setIsInserterOpened
|
||||
|
||||
返回用于打开/关闭插入器的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _value_ `boolean|Object`: 插入器应打开(true)还是关闭(false)。要指定插入点,请使用对象。
|
||||
- _value.rootClientId_ `string`: 要插入的根客户端 ID。
|
||||
- _value.insertionIndex_ `number`: 要插入的索引位置。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setIsListViewOpened
|
||||
|
||||
返回用于打开/关闭列表视图的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _isOpen_ `boolean`: 表示列表视图应打开还是关闭的布尔值。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### setIsWidgetAreaOpen
|
||||
|
||||
设置小工具区域的打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _clientId_ `string`: 小工具区域的客户端 ID。
|
||||
- _isOpen_ `boolean`: 小工具区域是否应打开。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作。
|
||||
|
||||
### setWidgetAreasOpenState
|
||||
|
||||
设置所有小工具区域的打开状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _widgetAreasOpenState_ `Object`: 所有小工具区域的打开状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作。
|
||||
|
||||
### setWidgetIdForClientId
|
||||
|
||||
设置特定 widgetId 对应的客户端 ID。
|
||||
|
||||
_参数_
|
||||
|
||||
- _clientId_ `number`: 客户端 ID。
|
||||
- _widgetId_ `number`: 小工具 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作。
|
||||
|
||||
### unlockWidgetSaving
|
||||
|
||||
返回用于表示小工具保存已解锁的操作对象。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { store as widgetStore } from '@wordpress/edit-widgets';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { unlockWidgetSaving } = useDispatch( widgetStore );
|
||||
return (
|
||||
<Button onClick={ () => unlockWidgetSaving( 'lockName' ) }>
|
||||
{ __( '解锁小工具保存' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _lockName_ `string`: 锁名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/edit-widgets/src/store/actions.js) -->
|
||||
1721
docs/reference-guides/data/data-core-editor.md
Normal file
1721
docs/reference-guides/data/data-core-editor.md
Normal file
File diff suppressed because it is too large
Load Diff
440
docs/reference-guides/data/data-core-keyboard-shortcuts.md
Normal file
440
docs/reference-guides/data/data-core-keyboard-shortcuts.md
Normal file
@@ -0,0 +1,440 @@
|
||||
### 注销快捷键
|
||||
|
||||
返回用于注销键盘快捷键的操作对象。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { useEffect } from 'react';
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect, useDispatch } from '@wordpress/data';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
const 示例组件 = () => {
|
||||
const { 注销快捷键 } = useDispatch( keyboardShortcutsStore );
|
||||
|
||||
useEffect( () => {
|
||||
注销快捷键( 'core/editor/next-region' );
|
||||
}, [] );
|
||||
|
||||
const 快捷键 = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).获取快捷键组合(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return 快捷键 ? (
|
||||
<p>{ __( '快捷键未注销。' ) }</p>
|
||||
) : (
|
||||
<p>{ __( '快捷键已注销。' ) }</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _名称_ `字符串`: 快捷键名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `对象`: 操作对象。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/keyboard-shortcuts/src/store/actions.js) -->
|
||||
|
||||
# 键盘快捷键数据
|
||||
|
||||
命名空间:`core/keyboard-shortcuts`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/keyboard-shortcuts/src/store/selectors.js) -->
|
||||
|
||||
### getAllShortcutKeyCombinations
|
||||
|
||||
返回包含指定快捷键名称别名的所有快捷键组合。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { createInterpolateElement } from '@wordpress/element';
|
||||
import { sprintf } from '@wordpress/i18n';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const allShortcutKeyCombinations = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
allShortcutKeyCombinations.length > 0 && (
|
||||
<ul>
|
||||
{ allShortcutKeyCombinations.map(
|
||||
( { character, modifier }, index ) => (
|
||||
<li key={ index }>
|
||||
{ createInterpolateElement(
|
||||
sprintf(
|
||||
'字符:<code>%s</code> / 修饰键:<code>%s</code>',
|
||||
character,
|
||||
modifier
|
||||
),
|
||||
{
|
||||
code: <code />,
|
||||
}
|
||||
) }
|
||||
</li>
|
||||
)
|
||||
) }
|
||||
</ul>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态
|
||||
- _name_ `string`: 快捷键名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `WPShortcutKeyCombination[]`: 按键组合数组
|
||||
|
||||
### getAllShortcutRawKeyCombinations
|
||||
|
||||
返回指定快捷键名称的所有键盘组合的原始表示形式。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { createInterpolateElement } from '@wordpress/element';
|
||||
import { sprintf } from '@wordpress/i18n';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const allShortcutRawKeyCombinations = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
allShortcutRawKeyCombinations.length > 0 && (
|
||||
<ul>
|
||||
{ allShortcutRawKeyCombinations.map(
|
||||
( shortcutRawKeyCombination, index ) => (
|
||||
<li key={ index }>
|
||||
{ createInterpolateElement(
|
||||
sprintf(
|
||||
' <code>%s</code>',
|
||||
shortcutRawKeyCombination
|
||||
),
|
||||
{
|
||||
code: <code />,
|
||||
}
|
||||
) }
|
||||
</li>
|
||||
)
|
||||
) }
|
||||
</ul>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态
|
||||
- _name_ `string`: 快捷键名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string[]`: 快捷键数组
|
||||
|
||||
### getCategoryShortcuts
|
||||
|
||||
返回指定分类名称的快捷键名称列表。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const categoryShortcuts = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getCategoryShortcuts( 'block' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
categoryShortcuts.length > 0 && (
|
||||
<ul>
|
||||
{ categoryShortcuts.map( ( categoryShortcut ) => (
|
||||
<li key={ categoryShortcut }>{ categoryShortcut }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态
|
||||
- _name_ `string`: 分类名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `string[]`: 快捷键名称数组
|
||||
|
||||
### getShortcutAliases
|
||||
|
||||
返回指定快捷键名称的别名。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { createInterpolateElement } from '@wordpress/element';
|
||||
import { sprintf } from '@wordpress/i18n';
|
||||
const ExampleComponent = () => {
|
||||
const shortcutAliases = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getShortcutAliases(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
shortcutAliases.length > 0 && (
|
||||
<ul>
|
||||
{ shortcutAliases.map( ( { character, modifier }, index ) => (
|
||||
<li key={ index }>
|
||||
{ createInterpolateElement(
|
||||
sprintf(
|
||||
'字符:<code>%s</code> / 修饰键:<code>%s</code>',
|
||||
character,
|
||||
modifier
|
||||
),
|
||||
{
|
||||
code: <code />,
|
||||
}
|
||||
) }
|
||||
</li>
|
||||
) ) }
|
||||
</ul>
|
||||
)
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态
|
||||
- _name_ `string`: 快捷键名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `WPShortcutKeyCombination[]`: 按键组合数组
|
||||
|
||||
### getShortcutDescription
|
||||
|
||||
返回指定名称的快捷键描述。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
const ExampleComponent = () => {
|
||||
const shortcutDescription = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getShortcutDescription(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return shortcutDescription ? (
|
||||
<div>{ shortcutDescription }</div>
|
||||
) : (
|
||||
<div>{ __( '无描述信息。' ) }</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态。
|
||||
- _name_ `string`: 快捷键名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 快捷键描述。
|
||||
|
||||
### getShortcutKeyCombination
|
||||
|
||||
返回指定快捷键名称的主键组合。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { createInterpolateElement } from '@wordpress/element';
|
||||
import { sprintf } from '@wordpress/i18n';
|
||||
const ExampleComponent = () => {
|
||||
const { character, modifier } = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{ createInterpolateElement(
|
||||
sprintf(
|
||||
'字符:<code>%s</code> / 修饰键:<code>%s</code>',
|
||||
character,
|
||||
modifier
|
||||
),
|
||||
{
|
||||
code: <code />,
|
||||
}
|
||||
) }
|
||||
</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态。
|
||||
- _name_ `string`: 快捷键名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `WPShortcutKeyCombination?`: 键位组合。
|
||||
|
||||
### getShortcutRepresentation
|
||||
|
||||
返回表示指定快捷键名称主键组合的字符串。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { sprintf } from '@wordpress/i18n';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { display, raw, ariaLabel } = useSelect( ( select ) => {
|
||||
return {
|
||||
display: select( keyboardShortcutsStore ).getShortcutRepresentation(
|
||||
'core/editor/next-region'
|
||||
),
|
||||
raw: select( keyboardShortcutsStore ).getShortcutRepresentation(
|
||||
'core/editor/next-region',
|
||||
'raw'
|
||||
),
|
||||
ariaLabel: select(
|
||||
keyboardShortcutsStore
|
||||
).getShortcutRepresentation(
|
||||
'core/editor/next-region',
|
||||
'ariaLabel'
|
||||
),
|
||||
};
|
||||
}, [] );
|
||||
|
||||
return (
|
||||
<ul>
|
||||
<li>{ sprintf( '显示字符串:%s', display ) }</li>
|
||||
<li>{ sprintf( '原始字符串:%s', raw ) }</li>
|
||||
<li>{ sprintf( '无障碍标签字符串:%s', ariaLabel ) }</li>
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局状态。
|
||||
- _name_ `string`: 快捷键名称。
|
||||
- _representation_ `keyof FORMATTING_METHODS`: 表示类型(display, raw, ariaLabel)。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?string`: 快捷键表示形式。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/keyboard-shortcuts/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/keyboard-shortcuts/src/store/actions.js) -->
|
||||
|
||||
### registerShortcut
|
||||
|
||||
返回用于注册新键盘快捷键的操作对象。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { useEffect } from 'react';
|
||||
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
||||
import { useSelect, useDispatch } from '@wordpress/data';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { registerShortcut } = useDispatch( keyboardShortcutsStore );
|
||||
|
||||
useEffect( () => {
|
||||
registerShortcut( {
|
||||
name: 'custom/my-custom-shortcut',
|
||||
category: 'my-category',
|
||||
description: __( '我的自定义快捷键' ),
|
||||
keyCombination: {
|
||||
modifier: 'primary',
|
||||
character: 'j',
|
||||
},
|
||||
} );
|
||||
}, [] );
|
||||
|
||||
const shortcut = useSelect(
|
||||
( select ) =>
|
||||
select( keyboardShortcutsStore ).getShortcutKeyCombination(
|
||||
'custom/my-custom-shortcut'
|
||||
),
|
||||
[]
|
||||
);
|
||||
|
||||
return shortcut ? (
|
||||
<p>{ __( '快捷键已注册。' ) }</p>
|
||||
) : (
|
||||
<p>{ __( '快捷键未注册。' ) }</p>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _config_ `WPShortcutConfig`: 快捷键配置。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
406
docs/reference-guides/data/data-core-notices.md
Normal file
406
docs/reference-guides/data/data-core-notices.md
Normal file
@@ -0,0 +1,406 @@
|
||||
### removeNotices
|
||||
|
||||
返回一个用于指示需要移除多个通知的动作对象。
|
||||
|
||||
**用法**
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const notices = useSelect( ( select ) =>
|
||||
select( noticesStore ).getNotices()
|
||||
);
|
||||
const { removeNotices } = useDispatch( noticesStore );
|
||||
return (
|
||||
<>
|
||||
<ul>
|
||||
{ notices.map( ( notice ) => (
|
||||
<li key={ notice.id }>{ notice.content }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
<Button
|
||||
onClick={ () =>
|
||||
removeNotices( notices.map( ( { id } ) => id ) )
|
||||
}
|
||||
>
|
||||
{ __( '清除所有通知' ) }
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
**参数**
|
||||
|
||||
- _ids_ `string[]`: 唯一通知标识符列表。
|
||||
- _context_ `[string]`: 可选参数,指定通知显示的情境(分组)。默认为默认情境。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`: 动作对象。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/notices/src/store/actions.js) -->
|
||||
|
||||
### createSuccessNotice
|
||||
|
||||
返回用于指示创建成功通知的操作对象。有关选项说明,请参阅 `createNotice`。
|
||||
|
||||
**相关**
|
||||
|
||||
- createNotice
|
||||
|
||||
**用法**
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { createSuccessNotice } = useDispatch( noticesStore );
|
||||
return (
|
||||
<Button
|
||||
onClick={ () =>
|
||||
createSuccessNotice( __( 'Success!' ), {
|
||||
type: 'snackbar',
|
||||
icon: '🔥',
|
||||
} )
|
||||
}
|
||||
>
|
||||
{ __( 'Generate a snackbar success notice!' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
**参数**
|
||||
|
||||
- _content_ `string`: 通知消息。
|
||||
- _options_ `[Object]`: 可选的通知选项。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### createWarningNotice
|
||||
|
||||
返回用于指示创建警告通知的操作对象。有关选项说明,请参阅 `createNotice`。
|
||||
|
||||
**相关**
|
||||
|
||||
- createNotice
|
||||
|
||||
**用法**
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { createWarningNotice, createInfoNotice } =
|
||||
useDispatch( noticesStore );
|
||||
return (
|
||||
<Button
|
||||
onClick={ () =>
|
||||
createWarningNotice( __( 'Warning!' ), {
|
||||
onDismiss: () => {
|
||||
createInfoNotice(
|
||||
__( 'The warning has been dismissed!' )
|
||||
);
|
||||
},
|
||||
} )
|
||||
}
|
||||
>
|
||||
{ __( 'Generates a warning notice with onDismiss callback' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
**参数**
|
||||
|
||||
- _content_ `string`: 通知消息。
|
||||
- _options_ `[Object]`: 可选的通知选项。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### removeAllNotices
|
||||
|
||||
从给定上下文中移除所有通知。默认为默认上下文。
|
||||
|
||||
**用法**
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
export const ExampleComponent = () => {
|
||||
const notices = useSelect( ( select ) =>
|
||||
select( noticesStore ).getNotices()
|
||||
);
|
||||
const { removeAllNotices } = useDispatch( noticesStore );
|
||||
return (
|
||||
<>
|
||||
<ul>
|
||||
{ notices.map( ( notice ) => (
|
||||
<li key={ notice.id }>{ notice.content }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
<Button onClick={ () => removeAllNotices() }>
|
||||
{ __( 'Clear all notices', 'woo-gutenberg-products-block' ) }
|
||||
</Button>
|
||||
<Button onClick={ () => removeAllNotices( 'snackbar' ) }>
|
||||
{ __(
|
||||
'Clear all snackbar notices',
|
||||
'woo-gutenberg-products-block'
|
||||
) }
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
**参数**
|
||||
|
||||
- _noticeType_ `string`: 要移除所有通知的上下文。
|
||||
- _context_ `string`: 要移除所有通知的上下文。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### removeNotice
|
||||
|
||||
返回用于指示移除通知的操作对象。
|
||||
|
||||
**用法**
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const notices = useSelect( ( select ) =>
|
||||
select( noticesStore ).getNotices()
|
||||
);
|
||||
const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
onClick={ () =>
|
||||
createWarningNotice( __( 'Warning!' ), {
|
||||
isDismissible: false,
|
||||
} )
|
||||
}
|
||||
>
|
||||
{ __( 'Generate a notice' ) }
|
||||
</Button>
|
||||
{ notices.length > 0 && (
|
||||
<Button onClick={ () => removeNotice( notices[ 0 ].id ) }>
|
||||
{ __( 'Remove the notice' ) }
|
||||
</Button>
|
||||
) }
|
||||
</>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
**参数**
|
||||
|
||||
- _id_ `string`: 通知的唯一标识符。
|
||||
- _context_ `[string]`: 通知出现的可选上下文(分组)。默认为默认上下文。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
# 通知数据
|
||||
|
||||
命名空间:`core/notices`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/notices/src/store/selectors.js) -->
|
||||
|
||||
### getNotices
|
||||
|
||||
以数组形式返回所有通知,可选择指定上下文。默认为全局上下文。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const notices = useSelect( ( select ) =>
|
||||
select( noticesStore ).getNotices()
|
||||
);
|
||||
return (
|
||||
<ul>
|
||||
{ notices.map( ( notice ) => (
|
||||
<li key={ notice.ID }>{ notice.content }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 通知状态
|
||||
- _context_ `?string`: 可选的分组上下文
|
||||
|
||||
_返回值_
|
||||
|
||||
- `WPNotice[]`: 通知数组
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/notices/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/notices/src/store/actions.js) -->
|
||||
|
||||
### createErrorNotice
|
||||
|
||||
返回用于指示创建错误通知的操作对象。选项文档请参考 `createNotice`。
|
||||
|
||||
_相关_
|
||||
|
||||
- createNotice
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { createErrorNotice } = useDispatch( noticesStore );
|
||||
return (
|
||||
<Button
|
||||
onClick={ () =>
|
||||
createErrorNotice( __( '发生错误!' ), {
|
||||
type: 'snackbar',
|
||||
explicitDismiss: true,
|
||||
} )
|
||||
}
|
||||
>
|
||||
{ __(
|
||||
'生成带有显式关闭按钮的snackbar错误通知'
|
||||
) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _content_ `string`: 通知消息
|
||||
- _options_ `[Object]`: 可选的通知选项
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### createInfoNotice
|
||||
|
||||
返回用于指示创建信息通知的操作对象。选项文档请参考 `createNotice`。
|
||||
|
||||
_相关_
|
||||
|
||||
- createNotice
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { createInfoNotice } = useDispatch( noticesStore );
|
||||
return (
|
||||
<Button
|
||||
onClick={ () =>
|
||||
createInfoNotice( __( '有情况发生!' ), {
|
||||
isDismissible: false,
|
||||
} )
|
||||
}
|
||||
>
|
||||
{ __( '生成一个不可关闭的通知' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _content_ `string`: 通知消息
|
||||
- _options_ `[Object]`: 可选的通知选项
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### createNotice
|
||||
|
||||
返回用于指示创建通知的操作对象。
|
||||
|
||||
_用法_
|
||||
|
||||
```js
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useDispatch } from '@wordpress/data';
|
||||
import { store as noticesStore } from '@wordpress/notices';
|
||||
import { Button } from '@wordpress/components';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { createNotice } = useDispatch( noticesStore );
|
||||
return (
|
||||
<Button
|
||||
onClick={ () => createNotice( 'success', __( '通知消息' ) ) }
|
||||
>
|
||||
{ __( '生成成功通知!' ) }
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _status_ `string|undefined`: 通知状态(如果传入undefined则为"info")
|
||||
- _content_ `string`: 通知消息
|
||||
- _options_ `[Object]`: 通知选项
|
||||
- _options.context_ `[string]`: 通知分组上下文
|
||||
- _options.id_ `[string]`: 通知标识符。未指定时自动分配
|
||||
- _options.isDismissible_ `[boolean]`: 用户是否可关闭通知
|
||||
- _options.type_ `[string]`: 通知类型,可选 `default` 或 `snackbar`
|
||||
- _options.speak_ `[boolean]`: 是否向屏幕阅读器播报通知内容
|
||||
- _options.actions_ `[Array<WPNoticeAction>]`: 与通知一起显示的用户操作
|
||||
- _options.icon_ `[string]`: 通知显示的图标。仅当类型设置为 `snackbar` 时使用
|
||||
- _options.explicitDismiss_ `[boolean]`: 通知是否包含显式关闭按钮且不能通过点击通知主体关闭。仅当类型设置为 `snackbar` 时适用
|
||||
- _options.onDismiss_ `[Function]`: 通知关闭时调用的函数
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/notices/src/store/actions.js) -->
|
||||
93
docs/reference-guides/data/data-core-nux.md
Normal file
93
docs/reference-guides/data/data-core-nux.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# NUX(新用户体验)数据
|
||||
|
||||
命名空间:`core/nux`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/nux/src/store/selectors.js) -->
|
||||
|
||||
### areTipsEnabled
|
||||
|
||||
返回提示功能是否全局启用。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 提示功能是否全局启用。
|
||||
|
||||
### getAssociatedGuide
|
||||
|
||||
返回描述给定提示所属引导(如果存在)的对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
- _tipId_ `string`: 要查询的提示。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?NUXGuideInfo`: 关联引导的信息。
|
||||
|
||||
### isTipVisible
|
||||
|
||||
判断指定提示是否正在显示。如果提示被禁用、已被关闭或不是所在引导中的当前提示,则不会显示。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 全局应用状态。
|
||||
- _tipId_ `string`: 要查询的提示。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 指定提示是否正在显示。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/nux/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/nux/src/store/actions.js) -->
|
||||
|
||||
### disableTips
|
||||
|
||||
返回一个操作对象,当被分发时,将阻止所有提示再次显示。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### dismissTip
|
||||
|
||||
返回一个操作对象,当被分发时,将关闭指定提示。被关闭的提示将不再显示。
|
||||
|
||||
_参数_
|
||||
|
||||
- _id_ `string`: 要关闭的提示。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### enableTips
|
||||
|
||||
返回一个操作对象,当被分发时,将重新启用所有提示显示。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
### triggerGuide
|
||||
|
||||
返回一个操作对象,当被分发时,将呈现一个引导,逐步引导用户完成一系列提示。
|
||||
|
||||
_参数_
|
||||
|
||||
- _tipIds_ `string[]`: 引导中要显示的提示列表。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/nux/src/store/actions.js) -->
|
||||
84
docs/reference-guides/data/data-core-preferences.md
Normal file
84
docs/reference-guides/data/data-core-preferences.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# 偏好设置
|
||||
|
||||
命名空间:`core/preferences`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/preferences/src/store/selectors.js) -->
|
||||
|
||||
### get
|
||||
|
||||
返回一个布尔值,指示特定作用域中的偏好设置是否处于启用状态。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 存储状态
|
||||
- _scope_ `string`: 功能的作用域(例如:core/edit-post)
|
||||
- _name_ `string`: 功能名称
|
||||
|
||||
_返回值_
|
||||
|
||||
- `*`: 该功能是否启用?
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/preferences/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/preferences/src/store/actions.js) -->
|
||||
|
||||
### set
|
||||
|
||||
返回用于指示应将偏好设置设定为特定值的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _scope_ `string`: 偏好设置作用域(例如:core/edit-post)
|
||||
- _name_ `string`: 偏好设置名称
|
||||
- _value_ `*`: 要设定的值
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### setDefaults
|
||||
|
||||
返回用于指示应设定偏好设置默认值的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _scope_ `string`: 偏好设置作用域(例如:core/edit-post)
|
||||
- _defaults_ `Object<string, *>`: 偏好设置名称与值的键值映射表
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### setPersistenceLayer
|
||||
|
||||
设置持久化层。
|
||||
|
||||
当设置持久化层后,偏好设置存储将:
|
||||
|
||||
- 立即调用 `get` 方法,并将存储状态更新为返回的值
|
||||
- 当偏好设置值发生变更时,调用 `set` 方法更新所有偏好设置
|
||||
|
||||
理想情况下,应在应用程序生命周期开始时、在向偏好设置存储分发任何其他操作之前分发 `setPersistenceLayer`。
|
||||
|
||||
_参数_
|
||||
|
||||
- _persistenceLayer_ `WPPreferencesPersistenceLayer`: 持久化层
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Object`: 操作对象
|
||||
|
||||
### toggle
|
||||
|
||||
返回用于指示应切换偏好设置状态的操作对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _scope_ `string`: 偏好设置作用域(例如:core/edit-post)
|
||||
- _name_ `string`: 偏好设置名称
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/preferences/src/store/actions.js) -->
|
||||
23
docs/reference-guides/data/data-core-reusable-blocks.md
Normal file
23
docs/reference-guides/data/data-core-reusable-blocks.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 可复用区块
|
||||
|
||||
命名空间:`core/reusable-blocks`。
|
||||
|
||||
<div class="callout callout-alert">
|
||||
本软件包仍处于实验阶段。"实验性"意味着这是早期实现版本,可能发生剧烈且不兼容的变更。
|
||||
</div>
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/reusable-blocks/src/store/selectors.js) -->
|
||||
|
||||
暂无内容需要记录。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/reusable-blocks/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/reusable-blocks/src/store/actions.js) -->
|
||||
|
||||
暂无内容需要记录。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/reusable-blocks/src/store/actions.js) -->
|
||||
162
docs/reference-guides/data/data-core-rich-text.md
Normal file
162
docs/reference-guides/data/data-core-rich-text.md
Normal file
@@ -0,0 +1,162 @@
|
||||
# 富文本
|
||||
|
||||
命名空间:`core/rich-text`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/rich-text/src/store/selectors.js) -->
|
||||
|
||||
### getFormatType
|
||||
|
||||
通过名称返回格式类型。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as richTextStore } from '@wordpress/rich-text';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { getFormatType } = useSelect(
|
||||
( select ) => select( richTextStore ),
|
||||
[]
|
||||
);
|
||||
|
||||
const boldFormat = getFormatType( 'core/bold' );
|
||||
|
||||
return boldFormat ? (
|
||||
<ul>
|
||||
{ Object.entries( boldFormat )?.map( ( [ key, value ] ) => (
|
||||
<li>
|
||||
{ key } : { value }
|
||||
</li>
|
||||
) ) }
|
||||
</ul>
|
||||
) : (
|
||||
__( '未找到' )
|
||||
;
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _name_ `string`: 格式类型名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?Object`: 格式类型。
|
||||
|
||||
### getFormatTypeForBareElement
|
||||
|
||||
获取可以处理裸元素(不带 data-format-type 属性)的格式类型(如果有),给定该元素的标签名称。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as richTextStore } from '@wordpress/rich-text';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { getFormatTypeForBareElement } = useSelect(
|
||||
( select ) => select( richTextStore ),
|
||||
[]
|
||||
);
|
||||
|
||||
const format = getFormatTypeForBareElement( 'strong' );
|
||||
|
||||
return format && <p>{ sprintf( __( '格式名称: %s' ), format.name ) }</p>;
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _bareElementTagName_ `string`: 要查找格式类型的元素的标签名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?Object`: 格式类型。
|
||||
|
||||
### getFormatTypeForClassName
|
||||
|
||||
获取可以处理元素的格式类型(如果有),给定其类名。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as richTextStore } from '@wordpress/rich-text';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { getFormatTypeForClassName } = useSelect(
|
||||
( select ) => select( richTextStore ),
|
||||
[]
|
||||
);
|
||||
|
||||
const format = getFormatTypeForClassName( 'has-inline-color' );
|
||||
|
||||
return format && <p>{ sprintf( __( '格式名称: %s' ), format.name ) }</p>;
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
- _elementClassName_ `string`: 要查找格式类型的元素的类名。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `?Object`: 格式类型。
|
||||
|
||||
### getFormatTypes
|
||||
|
||||
返回所有可用的格式类型。
|
||||
|
||||
_使用方法_
|
||||
|
||||
```js
|
||||
import { __, sprintf } from '@wordpress/i18n';
|
||||
import { store as richTextStore } from '@wordpress/rich-text';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
|
||||
const ExampleComponent = () => {
|
||||
const { getFormatTypes } = useSelect(
|
||||
( select ) => select( richTextStore ),
|
||||
[]
|
||||
);
|
||||
|
||||
const availableFormats = getFormatTypes();
|
||||
|
||||
return availableFormats ? (
|
||||
<ul>
|
||||
{ availableFormats?.map( ( format ) => (
|
||||
<li>{ format.name }</li>
|
||||
) ) }
|
||||
</ul>
|
||||
) : (
|
||||
__( '无可用格式' )
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `Object`: 数据状态。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Array`: 格式类型。
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/rich-text/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/rich-text/src/store/actions.js) -->
|
||||
|
||||
暂无内容需要记录。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/rich-text/src/store/actions.js) -->
|
||||
52
docs/reference-guides/data/data-core-viewport.md
Normal file
52
docs/reference-guides/data/data-core-viewport.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# 视口数据
|
||||
|
||||
命名空间:`core/viewport`
|
||||
|
||||
## 选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/viewport/src/store/selectors.js) -->
|
||||
|
||||
### isViewportMatch
|
||||
|
||||
若视口匹配指定查询条件则返回 true,否则返回 false。
|
||||
|
||||
_使用示例_
|
||||
|
||||
```js
|
||||
import { store as viewportStore } from '@wordpress/viewport';
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
const ExampleComponent = () => {
|
||||
const isMobile = useSelect(
|
||||
( select ) => select( viewportStore ).isViewportMatch( '< small' ),
|
||||
[]
|
||||
);
|
||||
|
||||
return isMobile ? (
|
||||
<div>{ __( '移动端' ) }</div>
|
||||
) : (
|
||||
<div>{ __( '非移动端' ) }</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
_参数说明_
|
||||
|
||||
- _state_ `Object`: 视口状态对象
|
||||
- _query_ `string`: 查询字符串。包含运算符和断点名称,以空格分隔。运算符默认为 >=
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 视口是否匹配查询条件
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/viewport/src/store/selectors.js) -->
|
||||
|
||||
## 操作
|
||||
|
||||
此包中的操作不应直接使用。
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/viewport/src/store/actions.js) -->
|
||||
|
||||
暂无需要说明的内容
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/viewport/src/store/actions.js) -->
|
||||
938
docs/reference-guides/data/data-core.md
Normal file
938
docs/reference-guides/data/data-core.md
Normal file
@@ -0,0 +1,938 @@
|
||||
### 撤销
|
||||
|
||||
触发此操作可撤销对实体记录的最后一次编辑(如果存在)。
|
||||
|
||||
<!-- END TOKEN(Autogenerated actions|../../../packages/core-data/src/actions.js) -->
|
||||
|
||||
### hasEntityRecord
|
||||
|
||||
若给定参数对应的实体记录已接收则返回 true,否则返回 false。
|
||||
|
||||
注意:若本地状态中不存在该实体记录,此操作不会触发从 API 请求实体记录。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
- _kind_ `string`: 实体类型
|
||||
- _name_ `string`: 实体名称
|
||||
- _key_ `EntityRecordKey`: 记录主键
|
||||
- _query_ `GetRecordsHttpQuery`: 可选查询条件
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否已接收到实体记录
|
||||
|
||||
### hasEntityRecords
|
||||
|
||||
若给定参数对应的实体记录集已接收则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
- _kind_ `string`: 实体类型
|
||||
- _name_ `string`: 实体名称
|
||||
- _query_ `GetRecordsHttpQuery`: 可选筛选查询。有效查询参数请参阅 REST API 手册中的[参考文档](https://developer.wordpress.org/rest-api/reference/),选择对应实体类型后查看“列出[实体类型]”可用参数。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否已接收到实体记录集
|
||||
|
||||
### hasFetchedAutosaves
|
||||
|
||||
若自动保存记录的 REST 请求已完成则返回 true。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
- _postType_ `string`: 父级文章类型
|
||||
- _postId_ `EntityRecordKey`: 父级文章ID
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: REST 请求是否已完成
|
||||
|
||||
### hasRedo
|
||||
|
||||
若实体记录编辑历史中存在当前撤销偏移量之后的下一个编辑操作则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否存在后续编辑操作
|
||||
|
||||
### hasUndo
|
||||
|
||||
若实体记录编辑历史中存在当前撤销偏移量之前的上一编辑操作则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否存在先前编辑操作
|
||||
|
||||
### isAutosavingEntityRecord
|
||||
|
||||
若指定实体记录正在自动保存则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
- _kind_ `string`: 实体类型
|
||||
- _name_ `string`: 实体名称
|
||||
- _recordId_ `EntityRecordKey`: 记录ID
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 实体记录是否正在自动保存
|
||||
|
||||
### isDeletingEntityRecord
|
||||
|
||||
若指定实体记录正在删除则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
- _kind_ `string`: 实体类型
|
||||
- _name_ `string`: 实体名称
|
||||
- _recordId_ `EntityRecordKey`: 记录ID
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 实体记录是否正在删除
|
||||
|
||||
### isPreviewEmbedFallback
|
||||
|
||||
判断返回的预览是否为 oEmbed 链接回退方案。
|
||||
|
||||
当 WordPress 检测到某个 URL 无法嵌入时,可配置为返回该 URL 的简单链接。我们需要根据 oEmbed 预览 API 的返回结果来判断 URL 是否可嵌入。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 数据状态
|
||||
- _url_ `string`: 嵌入的 URL
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 该 URL 的预览是否为 oEmbed 链接回退
|
||||
|
||||
### isRequestingEmbedPreview
|
||||
|
||||
若正在请求嵌入预览数据则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 数据状态
|
||||
- _url_ `string`: 预览对应的 URL
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 是否正在请求嵌入预览
|
||||
|
||||
### isSavingEntityRecord
|
||||
|
||||
若指定实体记录正在保存则返回 true,否则返回 false。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`: 状态树
|
||||
- _kind_ `string`: 实体类型
|
||||
- _name_ `string`: 实体名称
|
||||
- _recordId_ `EntityRecordKey`: 记录ID
|
||||
|
||||
_返回值_
|
||||
|
||||
- `boolean`: 实体记录是否正在保存
|
||||
|
||||
<!-- END TOKEN(Autogenerated selectors|../../../packages/core-data/src/selectors.ts) -->
|
||||
|
||||
## 操作
|
||||
|
||||
<!-- START TOKEN(Autogenerated actions|../../../packages/core-data/src/actions.js) -->
|
||||
|
||||
### getEntity
|
||||
|
||||
> **已弃用** 自 WordPress 6.0 起。请改用 getEntityConfig
|
||||
|
||||
根据实体的种类和名称返回其配置。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `any`:实体配置
|
||||
|
||||
### getEntityConfig
|
||||
|
||||
根据实体的种类和名称返回其配置。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `any`:实体配置
|
||||
|
||||
### getEntityRecord
|
||||
|
||||
根据键返回实体的记录对象。如果值尚未接收,则返回 `null`;如果已知该实体不存在,则返回 `undefined`;如果实体存在且已接收,则返回实体对象。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
- _key_ `EntityRecordKey`:可选的记录键。如果请求全局记录(例如站点设置),可以省略键。如果请求特定项目,则必须始终包含键。
|
||||
- _query_ `GetRecordsHttpQuery`:可选的查询。如果请求特定字段,字段必须始终包含 ID。有关有效的查询参数,请参阅 REST API 手册中的[参考](https://developer.wordpress.org/rest-api/reference/),并选择实体种类。然后查看“检索 [实体种类]”可用的参数。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `EntityRecord | undefined`:记录。
|
||||
|
||||
### getEntityRecordEdits
|
||||
|
||||
返回指定实体记录的编辑内容。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordId_ `EntityRecordKey`:记录 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Optional< any >`:实体记录的编辑内容。
|
||||
|
||||
### getEntityRecordNonTransientEdits
|
||||
|
||||
返回指定实体记录的非临时编辑内容。
|
||||
|
||||
临时编辑不会创建撤销级别,并且不会用于变更检测。它们在实体的配置中定义。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordId_ `EntityRecordKey`:记录 ID。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `Optional< any >`:实体记录的非临时编辑内容。
|
||||
|
||||
### getEntityRecords
|
||||
|
||||
返回实体的记录。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
- _query_ `GetRecordsHttpQuery`:可选的查询条件。如果请求特定字段,字段必须始终包含 ID。有关有效的查询参数,请参阅 REST API 手册中的[参考](https://developer.wordpress.org/rest-api/reference/),并选择实体种类。然后查看“列出 [实体种类]”可用的参数。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `EntityRecord[] | null`:记录。
|
||||
|
||||
### getEntityRecordsTotalItems
|
||||
|
||||
返回给定查询下实体的总可用记录数(忽略分页)。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
- _query_ `GetRecordsHttpQuery`:可选的查询条件。如果请求特定字段,字段必须始终包含 ID。有关有效的查询参数,请参阅 REST API 手册中的[参考](https://developer.wordpress.org/rest-api/reference/),并选择实体种类。然后查看“列出 [实体种类]”可用的参数。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `number | null`:数字或 null。
|
||||
|
||||
### getEntityRecordsTotalPages
|
||||
|
||||
返回给定查询下的可用页数。
|
||||
|
||||
_参数_
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体种类。
|
||||
- _name_ `string`:实体名称。
|
||||
- _query_ `GetRecordsHttpQuery`:可选的查询条件。如果请求特定字段,字段必须始终包含 ID。有关有效的查询参数,请参阅 REST API 手册中的[参考](https://developer.wordpress.org/rest-api/reference/),并选择实体种类。然后查看“列出 [实体种类]”可用的参数。
|
||||
|
||||
_返回值_
|
||||
|
||||
- `number | null`:数字或 null。
|
||||
|
||||
# WordPress 核心数据
|
||||
|
||||
命名空间:`core`
|
||||
|
||||
## 动态生成的选择器
|
||||
|
||||
这里提供了一系列用户友好的选择器,它们是对通用选择器 `getEntityRecord` 和 `getEntityRecords` 的封装,可用于获取各类实体的信息。
|
||||
|
||||
### getPostType
|
||||
|
||||
返回指定文章类型的信息。
|
||||
|
||||
*使用示例*
|
||||
|
||||
```javascript
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { store as coreDataStore } from '@wordpress/core-data';
|
||||
|
||||
const postType = useSelect(
|
||||
( select ) => select( coreDataStore ).getPostType( 'post' )
|
||||
|
||||
// 等价于:select( coreDataStore ).getEntityRecord( 'root', 'postType', 'post' )
|
||||
);
|
||||
```
|
||||
|
||||
*参数*
|
||||
|
||||
- postType `string`
|
||||
|
||||
*返回值*
|
||||
|
||||
- `EntityRecord | undefined`: 记录对象
|
||||
|
||||
### getPostTypes
|
||||
|
||||
返回文章类型的信息。
|
||||
|
||||
*使用示例*
|
||||
|
||||
```javascript
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { store as coreDataStore } from '@wordpress/core-data';
|
||||
|
||||
const postTypes = useSelect( ( select ) => {
|
||||
return select( coreDataStore ).getPostTypes( { per_page: 4 } );
|
||||
|
||||
// 等价于:
|
||||
// select( coreDataStore ).getEntityRecords( 'root', 'postType', { per_page: 4 } );
|
||||
} );
|
||||
```
|
||||
|
||||
*参数*
|
||||
|
||||
- _query_ `GetRecordsHttpQuery`: 可选的查询条件。如需请求特定字段,字段必须始终包含ID。有效查询参数请参阅REST API手册中的[参考文档](https://developer.wordpress.org/rest-api/reference/),选择实体类型后查看"列出[实体类型]"可用的参数。
|
||||
|
||||
*返回值*
|
||||
|
||||
- `EntityRecord[] | null`: 记录数组
|
||||
|
||||
### getTaxonomy
|
||||
|
||||
返回指定分类法的信息。
|
||||
|
||||
*使用示例*
|
||||
|
||||
```javascript
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { store as coreDataStore } from '@wordpress/core-data';
|
||||
|
||||
const taxonomy = useSelect( ( select ) => {
|
||||
return select( coreDataStore ).getTaxonomy( 'category' );
|
||||
|
||||
// 等价于:
|
||||
// select( coreDataStore ).getEntityRecord( 'root', 'taxonomy', 'category' );
|
||||
} );
|
||||
```
|
||||
|
||||
*参数*
|
||||
|
||||
- taxonomy `string`
|
||||
|
||||
*返回值*
|
||||
|
||||
- `EntityRecord | undefined`: 记录对象
|
||||
|
||||
### getTaxonomies
|
||||
|
||||
返回分类法的信息。
|
||||
|
||||
*使用示例*
|
||||
|
||||
```javascript
|
||||
import { useSelect } from '@wordpress/data';
|
||||
import { store as coreDataStore } from '@wordpress/core-data';
|
||||
|
||||
const taxonomies = useSelect( ( select ) => {
|
||||
return select( coreDataStore ).getTaxonomies( { type: 'post' } );
|
||||
|
||||
// 等价于:
|
||||
// select( coreDataStore ).getEntityRecords( 'root', 'taxonomy', { type: 'post' } );
|
||||
} );
|
||||
```
|
||||
|
||||
*参数*
|
||||
|
||||
- _query_ `GetRecordsHttpQuery`: 可选的查询条件。如需请求特定字段,字段必须始终包含ID。有效查询参数请参阅REST API手册中的[参考文档](https://developer.wordpress.org/rest-api/reference/),选择实体类型后查看"列出[实体类型]"可用的参数。
|
||||
|
||||
*返回值*
|
||||
|
||||
- `EntityRecord[] | null`: 记录数组
|
||||
|
||||
## 其他选择器
|
||||
|
||||
<!-- START TOKEN(Autogenerated selectors|../../../packages/core-data/src/selectors.ts) -->
|
||||
|
||||
### canUser
|
||||
|
||||
返回当前用户是否可以对指定REST资源执行给定操作。
|
||||
|
||||
调用此方法可能通过 `canUser()` 解析器触发对REST API的OPTIONS请求。
|
||||
|
||||
<https://developer.wordpress.org/rest-api/reference/>
|
||||
|
||||
*参数*
|
||||
|
||||
- _state_ `State`: 数据状态
|
||||
- _action_ `string`: 要检查的操作。可选值:'create'、'read'、'update'、'delete'
|
||||
- _resource_ `string | EntityResource`: 要检查的实体资源。接受实体对象 `{ kind: 'postType', name: 'attachment', id: 1 }` 或字符串形式的REST基础路径 - `media`
|
||||
- _id_ `EntityRecordKey`: 要检查的REST资源ID(可选)
|
||||
|
||||
*返回值*
|
||||
|
||||
- `boolean | undefined`: 用户是否能执行该操作,如果OPTIONS请求仍在进行中则返回 `undefined`
|
||||
|
||||
### canUserEditEntityRecord
|
||||
|
||||
返回当前用户是否可以编辑指定实体。
|
||||
|
||||
调用此方法可能通过 `canUser()` 解析器触发对REST API的OPTIONS请求。
|
||||
|
||||
<https://developer.wordpress.org/rest-api/reference/>
|
||||
|
||||
*参数*
|
||||
|
||||
- _state_ `State`: 数据状态
|
||||
- _kind_ `string`: 实体类型
|
||||
- _name_ `string`: 实体名称
|
||||
- _recordId_ `EntityRecordKey`: 记录ID
|
||||
|
||||
*返回值*
|
||||
|
||||
- `boolean | undefined`: 用户是否可以编辑,如果OPTIONS请求仍在进行中则返回 `undefined`
|
||||
|
||||
### getLastEntityDeleteError
|
||||
|
||||
返回指定实体记录的最后删除错误。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordId_ `EntityRecordKey`:记录ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `any`:实体记录的保存错误。
|
||||
|
||||
### getLastEntitySaveError
|
||||
|
||||
返回指定实体记录的最后保存错误。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordId_ `EntityRecordKey`:记录ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `any`:实体记录的保存错误。
|
||||
|
||||
### getRawEntityRecord
|
||||
|
||||
通过键返回实体的记录对象,其属性映射为原始值。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _key_ `EntityRecordKey`:记录的键。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `EntityRecord | undefined`:包含实体原始属性的对象。
|
||||
|
||||
### getRedoEdit
|
||||
|
||||
> 自 6.3 版本起**已弃用**
|
||||
|
||||
从当前撤销偏移量中返回实体记录编辑历史中的下一个编辑(如果有)。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Optional< any >`:编辑内容。
|
||||
|
||||
### getReferenceByDistinctEdits
|
||||
|
||||
当编辑值发生变化时返回一个新的引用。这在通过严格相等比较返回值来推断状态之间是否发生编辑时非常有用。
|
||||
|
||||
**用法**
|
||||
|
||||
const hasEditOccurred = (
|
||||
getReferenceByDistinctEdits( beforeState ) !==
|
||||
getReferenceByDistinctEdits( afterState )
|
||||
);
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ 编辑器状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- 一个仅在编辑发生时引用才会改变的值。
|
||||
|
||||
### getRevision
|
||||
|
||||
返回父实体的单个特定修订版本。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordKey_ `EntityRecordKey`:要获取修订版本的实体记录的键。
|
||||
- _revisionKey_ `EntityRecordKey`:修订版本的键。
|
||||
- _query_ `GetRecordsHttpQuery`:可选查询。如果请求特定字段,字段必须始终包含ID。有关有效查询参数,请参阅 [REST API 手册](https://developer.wordpress.org/rest-api/reference/) 中的修订模式,然后查看“检索 [实体类型]”可用的参数。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `RevisionRecord | Record< PropertyKey, never > | undefined`:记录。
|
||||
|
||||
### getRevisions
|
||||
|
||||
返回实体的修订版本。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordKey_ `EntityRecordKey`:要获取修订版本的实体记录的键。
|
||||
- _query_ `GetRecordsHttpQuery`:可选查询。如果请求特定字段,字段必须始终包含ID。有关有效查询参数,请参阅 [REST API 手册](https://developer.wordpress.org/rest-api/reference/) 中的修订模式,然后查看“检索 [实体类型]”可用的参数。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `RevisionRecord[] | null`:记录。
|
||||
|
||||
### getThemeSupports
|
||||
|
||||
返回索引中的主题支持数据。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `any`:索引数据。
|
||||
|
||||
### getUndoEdit
|
||||
|
||||
> 自 6.3 版本起**已弃用**
|
||||
|
||||
从当前撤销偏移量中返回实体记录编辑历史中的上一个编辑(如果有)。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Optional< any >`:编辑内容。
|
||||
|
||||
### getUserPatternCategories
|
||||
|
||||
检索已注册的用户模式分类。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< UserPatternCategory >`:用户模式分类数组。
|
||||
|
||||
### getUserQueryResults
|
||||
|
||||
返回由查询ID返回的所有用户。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _queryID_ `string`:查询ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `ET.User< 'edit' >[]`:用户列表。
|
||||
|
||||
### hasEditsForEntityRecord
|
||||
|
||||
如果指定的实体记录有编辑,则返回 true,否则返回 false。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordId_ `EntityRecordKey`:记录ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `boolean`:实体记录是否有编辑。
|
||||
|
||||
### getAuthors(获取作者列表)
|
||||
|
||||
> **已弃用**(自 11.3 版本起)。调用方应改用 `select( 'core' ).getUsers({ who: 'authors' })`。
|
||||
|
||||
返回所有可用的作者。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _query_ `GetRecordsHttpQuery`:可选的查询参数对象,随请求一同发送。有关有效的查询参数,请参阅 REST API 手册中的[用户页面](https://developer.wordpress.org/rest-api/reference/users/),并查看[列出用户](https://developer.wordpress.org/rest-api/reference/users/#list-users)和[检索用户](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user)的参数说明。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `ET.User[]`:作者列表。
|
||||
|
||||
### getAutosave(获取自动保存内容)
|
||||
|
||||
返回文章和作者的自动保存内容。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _postType_ `string`:父文章的类型。
|
||||
- _postId_ `EntityRecordKey`:父文章的 ID。
|
||||
- _authorId_ `EntityRecordKey`:作者的 ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `EntityRecord | undefined`:文章和作者的自动保存内容。
|
||||
|
||||
### getAutosaves(获取自动保存列表)
|
||||
|
||||
返回文章的最新自动保存内容。
|
||||
|
||||
由于后端会为每篇文章的每位作者存储一个自动保存内容,因此可能返回多个自动保存记录。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _postType_ `string`:父文章的类型。
|
||||
- _postId_ `EntityRecordKey`:父文章的 ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< any > | undefined`:文章的自动保存内容数组,如果没有则返回 `undefined`。
|
||||
|
||||
### getBlockPatternCategories(获取区块模式分类)
|
||||
|
||||
检索已注册的区块模式分类列表。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< any >`:区块模式分类列表。
|
||||
|
||||
### getBlockPatterns(获取区块模式)
|
||||
|
||||
检索已注册的区块模式列表。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< any >`:区块模式列表。
|
||||
|
||||
### getCurrentTheme(获取当前主题)
|
||||
|
||||
返回当前主题。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `any`:当前主题。
|
||||
|
||||
### getCurrentThemeGlobalStylesRevisions(获取当前主题全局样式修订版本)
|
||||
|
||||
> **已弃用**(自 WordPress 6.5.0 起)。调用方应改用 `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )`,其中 `recordKey` 是全局样式父文章的 ID。
|
||||
|
||||
返回当前全局样式主题的修订版本。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< object > | null`:当前全局样式。
|
||||
|
||||
### getCurrentUser(获取当前用户)
|
||||
|
||||
返回当前用户。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `ET.User< 'view' >`:当前用户对象。
|
||||
|
||||
### getDefaultTemplateId(获取默认模板 ID)
|
||||
|
||||
返回用于渲染指定查询的默认模板。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _query_ `TemplateQuery`:查询参数。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `string`:指定查询的默认模板 ID。
|
||||
|
||||
### getEditedEntityRecord(获取编辑后的实体记录)
|
||||
|
||||
返回指定的实体记录,并合并其编辑内容。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:状态树。
|
||||
- _kind_ `string`:实体类型。
|
||||
- _name_ `string`:实体名称。
|
||||
- _recordId_ `EntityRecordKey`:记录 ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `ET.Updatable< EntityRecord > | false`:合并编辑内容后的实体记录。
|
||||
|
||||
### getEmbedPreview(获取嵌入预览)
|
||||
|
||||
返回指定 URL 的嵌入预览内容。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _url_ `string`:嵌入的 URL。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `any`:如果预览尚未获取,则返回 `undefined`;否则返回从嵌入预览 API 获取的预览内容。
|
||||
|
||||
### getEntitiesByKind(按类型获取实体)
|
||||
|
||||
> **已弃用**(自 WordPress 6.0 起)。请改用 `getEntitiesConfig`。
|
||||
|
||||
返回指定类型的已加载实体。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _kind_ `string`:实体类型。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< any >`:与类型匹配的实体配置数组。
|
||||
|
||||
### getEntitiesConfig(获取实体配置)
|
||||
|
||||
返回指定类型的已加载实体。
|
||||
|
||||
**参数**
|
||||
|
||||
- _state_ `State`:数据状态。
|
||||
- _kind_ `string`:实体类型。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Array< any >`:与类型匹配的实体配置数组。
|
||||
|
||||
### addEntities(添加实体)
|
||||
|
||||
返回用于添加新实体的操作对象。
|
||||
|
||||
**参数**
|
||||
|
||||
- _entities_ `Array`:接收到的实体。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### deleteEntityRecord(删除实体记录)
|
||||
|
||||
触发删除实体记录的操作。
|
||||
|
||||
**参数**
|
||||
|
||||
- _kind_ `string`:被删除实体的类型。
|
||||
- _name_ `string`:被删除实体的名称。
|
||||
- _recordId_ `number|string`:被删除实体的记录 ID。
|
||||
- _query_ `?Object`:DELETE API 调用的特殊查询参数。
|
||||
- _options_ `[Object]`:删除选项。
|
||||
- _options.\_\_unstableFetch_ `[Function]`:仅限内部使用。用于替代 `apiFetch()` 调用的函数,必须返回一个 Promise。
|
||||
- _options.throwOnError_ `[boolean]`:如果为 false,此操作将抑制所有异常,默认为 false。
|
||||
|
||||
### editEntityRecord(编辑实体记录)
|
||||
|
||||
返回触发对实体记录进行编辑的操作对象。
|
||||
|
||||
**参数**
|
||||
|
||||
- _kind_ `string`:被编辑实体记录的类型。
|
||||
- _name_ `string`:被编辑实体记录的名称。
|
||||
- _recordId_ `number|string`:被编辑实体记录的记录 ID。
|
||||
- _edits_ `Object`:编辑内容。
|
||||
- _options_ `Object`:编辑选项。
|
||||
- _options.undoIgnore_ `[boolean]`:是否在撤销历史中忽略此编辑。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### receiveDefaultTemplateId(接收默认模板 ID)
|
||||
|
||||
返回用于为给定查询设置模板的操作对象。
|
||||
|
||||
**参数**
|
||||
|
||||
- _query_ `Object`:查询对象。
|
||||
- _templateId_ `string`:解析后的模板 ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### receiveEntityRecords(接收实体记录)
|
||||
|
||||
返回用于表示已接收到实体记录的操作对象。
|
||||
|
||||
**参数**
|
||||
|
||||
- _kind_ `string`:接收到的实体记录的类型。
|
||||
- _name_ `string`:接收到的实体记录的名称。
|
||||
- _records_ `Array|Object`:接收到的记录。
|
||||
- _query_ `?Object`:查询对象。
|
||||
- _invalidateCache_ `?boolean`:是否应使查询缓存失效。
|
||||
- _edits_ `?Object`:要重置的编辑内容。
|
||||
- _meta_ `?Object`:分页相关的元信息。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### receiveNavigationFallbackId(接收导航回退 ID)
|
||||
|
||||
返回表示已接收到回退导航菜单 ID 的操作对象。
|
||||
|
||||
**参数**
|
||||
|
||||
- _fallbackId_ `integer`:回退导航菜单的 ID。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### receiveRevisions(接收修订版本)
|
||||
|
||||
触发接收修订条目的操作。
|
||||
|
||||
**参数**
|
||||
|
||||
- _kind_ `string`:接收到的实体记录修订的类型。
|
||||
- _name_ `string`:接收到的实体记录修订的名称。
|
||||
- _recordKey_ `number|string`:要获取修订的实体记录的键。
|
||||
- _records_ `Array|Object`:接收到的修订内容。
|
||||
- _query_ `?Object`:查询对象。
|
||||
- _invalidateCache_ `?boolean`:是否应使查询缓存失效。
|
||||
- _meta_ `?Object`:分页相关的元信息。
|
||||
|
||||
### receiveThemeSupports(接收主题支持功能)
|
||||
|
||||
> 自 WP 5.9 起**已弃用**,不再有用,请直接使用选择器。
|
||||
|
||||
返回用于表示已接收到索引的操作对象。
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### receiveUploadPermissions(接收上传权限)
|
||||
|
||||
> 自 WP 5.9 起**已弃用**,请使用 receiveUserPermission 替代。
|
||||
|
||||
返回用于表示已接收到上传权限的操作对象。
|
||||
|
||||
**参数**
|
||||
|
||||
- _hasUploadPermissions_ `boolean`:用户是否有上传文件的权限?
|
||||
|
||||
**返回值**
|
||||
|
||||
- `Object`:操作对象。
|
||||
|
||||
### redo(重做)
|
||||
|
||||
触发重做上一次对实体记录的撤销编辑(如果有的话)。
|
||||
|
||||
### saveEditedEntityRecord(保存已编辑的实体记录)
|
||||
|
||||
触发保存实体记录的编辑内容。
|
||||
|
||||
**参数**
|
||||
|
||||
- _kind_ `string`:实体的类型。
|
||||
- _name_ `string`:实体的名称。
|
||||
- _recordId_ `Object`:记录的 ID。
|
||||
- _options_ `Object=`:保存选项。
|
||||
|
||||
### saveEntityRecord(保存实体记录)
|
||||
|
||||
触发保存实体记录的操作。
|
||||
|
||||
**参数**
|
||||
|
||||
- _kind_ `string`:接收到的实体的类型。
|
||||
- _name_ `string`:接收到的实体的名称。
|
||||
- _record_ `Object`:要保存的记录。
|
||||
- _options_ `Object`:保存选项。
|
||||
- _options.isAutosave_ `[boolean]`:是否为自动保存。
|
||||
- _options.\_\_unstableFetch_ `[Function]`:仅限内部使用。用于替代 `apiFetch()` 调用的函数,必须返回一个 Promise。
|
||||
- _options.throwOnError_ `[boolean]`:如果为 false,此操作将抑制所有异常,默认为 false。
|
||||
Reference in New Issue
Block a user