---
url: /reference/resource/extensions/wiki-document-block.md
---

# 页面 - 文档内容块

页面详情编辑插入菜单扩展模块，允许在编辑页面的插入项中添加自定义菜单：

![页面_编辑器菜单.png](../../../assets/d8fbbc3f11dbb10d42d80e367c3bd300fdc87b34.png)

![页面_文档内容块.png](../../../assets/eea17c59ea28b26f9bf87207e33041dca4451cee.png)

## 配置

配置结构：

```yaml
extensions []
├─ key (string) [Mandatory]
├─ target (string) [Mandatory]
├─ title (string | i18n) [Mandatory]
├─ icon (string) [Optional]
├─ resource (string) [Mandatory]
├─ resolver {} [Mandatory]
├─ layout ("block" | "bodied" | "inline") [Optional]
├─ behavior (string) [Mandatory]
├─ emitReadyEvent (boolean) [Optional]
├─ edit {} [Optional]
│  ├─ icon (string) [Optional]
│  ├─ title (string | i18n) [Optional]
│  ├─ resource (string) [Mandatory]
│  ├─ viewport {} [Optional]
│  │  └─ size (string) [Optional]
│  └─ openOnInsert (boolean) [Optional]
└─ fullscreen {} [Optional]
   ├─ resource (string) [Optional]
   └─ enabled (boolean) [Optional]
```

配置示例：

```yaml
extensions:
  - key: example-document-block
    target: "pcm:wiki:document:block"
    title: Block title
    icon: "resource:example-resource/icons/icon.svg"
    resource: main
    resolver:
      function: resolver
    behavior: modal
    emitReadyEvent: true
    edit:
      icon: "resource:example-resource/icons/icon.svg"
      title: Edit title
      resource: main
      viewport:
        size: medium
      openOnInsert: true
    fullscreen:
      resource: main
```

## 属性

配置属性：

## 布局

`layout` 决定内容块在文档中的形态：

## Bodied 内容块

设置 `layout: bodied` 后，应用可以在内容块中安排一个或多个 Wiki 可编辑正文区域。例如，标签页应用负责标签名称和切换，Wiki 编辑器负责每个标签内的正文。

Bodied 内容块的 **展示资源必须使用 Native UI** ，以便 Wiki 编辑器找到 `NxBlockContent` 占位并挂载正文。块编辑界面的 `edit.resource` 可以独立选择 Native UI 或 Custom UI。

### 声明扩展

```javascript
extensions:
  - key: tabs
    target: pcm:wiki:document:block
    title: 标签页
    resource: tabs-view
    behavior: modal
    layout: bodied
    edit:
      title: 配置标签页
      resource: tabs-edit
      openOnInsert: true
    resolver:
      function: resolver

resources:
  - key: tabs-view
    path: web/tabs-view/main.tsx
    render: native
  - key: tabs-edit
    path: web/tabs-edit/main.tsx
    render: native
```

### 提交配置和可编辑正文规则

配置界面提交两份对应的数据： `config.tabs` 保存标签的 ID 和标题， `body` 声明每个标签对应的正文区域。 `body` **不传正文文本** 。用户输入由 Wiki 编辑器管理.

```javascript
import { view } from "@pc-nexus/bridge";

async function saveTabs() {
  await view.submit({
    config: {
      tabs: [
        { id: "fbaccc3d-4c74-4a02-8195-69545cd42234", title: "Overview" },
        { id: "e2f88b6c-f0c0-4cac-9b04-471053707cf6", title: "Details" },
      ],
    },
    body: [
      { id: "fbaccc3d-4c74-4a02-8195-69545cd42234" },
      { id: "e2f88b6c-f0c0-4cac-9b04-471053707cf6" },
    ],
  });
}
```

首次插入 Bodied 内容块时，必须提交至少一个 `body` 区域。之后只修改标签的其他配置时，可以省略 `body` ，已有正文区域会保留；提交 `body` 时，数组中的 ID 和顺序决定正文区域的保留、新增、删除与排列。删除某个 ID 会连同该区域的正文一起删除。ID 应在当前内容块内保持唯一；目前不支持传入正文默认内容。

### 放置可编辑正文占位

展示界面为每个标签放一个 `NxBlockContent` 。 `contentId` 必须对应提交时 `body` 中的 `id` ：

```typescript
import { NxBlockContent, NxTab, NxTabs } from "@pc-nexus/react";

const tabs = [
  { id: "fbaccc3d-4c74-4a02-8195-69545cd42234", title: "Overview" },
  { id: "e2f88b6c-f0c0-4cac-9b04-471053707cf6", title: "Details" },
];

export function TabsView({ activeIndex }: { activeIndex: number }) {
  return (
    <>
      <NxTabs activeTab={activeIndex}>
        {tabs.map((tab) => (
          <NxTab key={tab.id} title={tab.title} />
        ))}
      </NxTabs>

      {tabs.map((tab, index) => (
        <NxBlockContent
          key={tab.id}
          contentId={tab.id}
          hidden={index !== activeIndex}
        />
      ))}
    </>
  );
}
```

只有一个正文区域时，可以省略 `contentId` 。设置 `hidden` 可以暂时隐藏区域，例如未激活的标签页；隐藏不会删除正文。

## 扩展数据

当前模块可访问的扩展数据：

## 限制

每个扩展模块对应的数量限制：

## 桥接方法

当前扩展模块不支持以下桥接方法，详情请参考 [view](/reference/interface/bridge/view) 。
