# TaskPanel

> 可组合参数页面的自适应任务外壳，支持底部面板、返回、关闭与原入口焦点。

网页来源：/components/task-panel

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

`QuireTaskPanel` 组合操作目录、日期选择或表单。同一个真实入口在桌面打开 Popover，在小于 768px 的布局视口打开底部面板；打开期间保持呈现方式和草稿 DOM，退出后再解析下一次呈现。

## 插入目录与参数页

`title` 命名当前页面，`canGoBack` 显示返回按钮，`back` 仅通知页内导航。业务草稿、页面路径和提交由调用方持有。`trigger` 插槽放一个真实按钮，`default` 与 `footer` 组合正文和提交操作。

示例在同一会话中搜索插入操作、进入参数页、返回保留查询，提交一次后关闭。取消、返回和搜索都不创建内容。搜索框没有自动焦点，用户点击后才进入输入。

### 示例：task-panel/insertion

文件：`insertion.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { quireIconRegistry, type QuireKitActionMenuEntry } from "@quirekit/ui";
import { QuireTaskPanel, QuireActionDirectory, QuireButton, QuireField, QuireInput, QuireIconProvider } from "@quirekit/ui/vue";
const open = ref(false), page = ref(""), query = ref(""), draft = ref(""), error = ref(""), count = ref(0), result = ref("尚未插入内容");
const task = ref<InstanceType<typeof QuireTaskPanel>>();
const actions: readonly QuireKitActionMenuEntry[] = [
  { kind: "command", value: "link", label: "链接", icon: "link", group: "插入" },
  { kind: "command", value: "image", label: "图片", icon: "image", group: "插入" },
  { kind: "command", value: "attachment", label: "附件", icon: "paperclip", disabled: true, group: "插入" },
];
/** @param value - One requested session, without a business mutation. */
function session(value: boolean): void { open.value = value; if (value) { page.value = ""; query.value = ""; draft.value = ""; error.value = ""; } }
/** @param value - Live enabled directory action. */
function navigate(value: string): void { page.value = value; error.value = ""; }
/** Validates the current draft before exactly one accepted local insertion. */
function submit(): void {
  if (!draft.value.startsWith("https://")) { error.value = "请填写 HTTPS 地址，草稿会保留。"; return; }
  count.value++; result.value = `${page.value}：${draft.value}`; task.value?.requestClose("action");
}
</script>
<template>
  <QuireIconProvider :registry="quireIconRegistry">
    <div class="grid justify-items-start gap-qk-group p-qk-surface">
      <QuireTaskPanel ref="task" :open="open" :title="page ? '插入参数' : '插入内容'" max-height="min(76dvh, 640px)" :can-go-back="!!page" @update:open="session" @back="page = ''; error = ''">
        <template #trigger><QuireButton color="primary">打开插入任务</QuireButton></template>
        <QuireActionDirectory v-show="!page" v-model:query="query" :actions="actions" layout="grid" searchable search-placeholder="搜索链接、图片…" @activate="navigate" />
        <QuireField v-if="page" label="资源地址" width="100%"><template #default="{ controlProps }"><QuireInput v-bind="controlProps" v-model="draft" type="url" placeholder="https://example.com/…" width="100%" /></template></QuireField>
        <p v-if="error" role="alert">{{ error }}</p>
        <template v-if="page" #footer><QuireButton color="primary" @click="submit">插入资源</QuireButton></template>
      </QuireTaskPanel>
      <p role="status" class="m-0">{{ result }} · 提交 {{ count }} 次</p>
    </div>
  </QuireIconProvider>
</template>
```

`QuireActionDirectory` 接收与 ActionMenu 相同的 `actions`，`layout="grid"` 展示两列触摸按钮。`searchable` 提供搜索输入，`searchPlaceholder` 提供查询示例，`v-model:query` 保留完整 Unicode 查询；默认搜索匹配名称、身份、组名和描述。自定义 `filter(action, query)` 可支持业务别名。分支导航由调用方处理，`activate` 仅通知一个启用动作，不执行任何业务操作。

## 会话和程序打开

用 `v-model:open` 控制会话，或使用非受控的 `defaultOpen`。程序打开没有 `trigger` 插槽时，必须用 `anchorEl` 指定当前 owner 的实际元素。`finalFocusEl` 指定退出后的焦点目标，省略时返回真实入口；`restoreFocus` 默认开启。把任务交给另一工作区时设置 `restoreFocus=false`，由接收方拥有焦点，避免退出动画再次抢回。Portal 默认位于该入口所属文档。

`busy` 阻止用户关闭和返回，宿主仍可结束会话。`onCloseRequest` 可同步调用 `preventDefault()` 拒绝当前关闭。组件实例的 `requestClose(reason)` 走同一关闭策略；提交成功后用 `requestClose('action')` 标记业务完成，其余关闭通过 `cancel` 报告原因及 `sessionId`。异步业务须由调用方管理取消和提交检查。

`title` 同时提供外壳的可访问名称。逻辑关闭立即停止正文交互并从辅助技术树隐藏；退出动画结束前仍保留原呈现和输入 DOM，避免旧目录重复执行或断点变化重挂草稿。

底部面板的高度与位置消费入口所属窗口的 VisualViewport；软键盘、缩放和窗口变化只更新几何，不重新挂载参数输入。正文滚动，标题和 footer 保持独立。底部面板使用 Tab/Shift+Tab 和普通按钮，Escape 关闭；搜索框不会因打开面板召唤键盘。

底部标题栏为 56px（44px 关闭/返回热区，上下各 6px 留白），标题使用 16px 语义字号。
正文使用 12px 紧凑留白，并独立消费安全区；调用方不再给目录嵌套滚动区。
`maxHeight` 可设置底部面板的 CSS 高度上限，例如 `min(76dvh, 640px)`；组件还会取
owner 可见视口的较小值。省略时保持按内容增长并受可见视口约束，桌面宽度仍由 `width` 控制。

`contentElementChange(element)` 在实际外壳挂载/释放时报告 `HTMLElement` 或 `null`，
页内标题、返回和参数变化不重发同一个节点。需要让底部面板参与宿主光标滚动时使用此
事件，宿主只在活动任务期间观察该元素；外壳不读取文本、选区，也不执行编辑器滚动。

只有目录动作的任务使用 [ActionMenu](/raw/components/action-menu.md)。有限单选值使用 [ChoicePicker](/raw/components/choice-picker.md)。

## API

### QuireTaskPanel

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| title | 是 | — | Accessible title of the current task page. |
| open | 否 | undefined | Controlled opening request. |
| defaultOpen | 否 | — | Initial uncontrolled request. |
| disabled | 否 | false | Authoritatively ends an unavailable task. |
| presentation | 否 | "auto" | Opening-time shell strategy, locked until physical exit. |
| busy | 否 | false | Current operation prevents user dismissal while it completes. |
| canGoBack | 否 | — | Shows the parent-page return action. |
| anchorEl | 否 | — | Explicit anchor for programmatic openings without a trigger slot. |
| finalFocusEl | 否 | — | Explicit destination after exit; otherwise returns to the actual trigger. |
| restoreFocus | 否 | true | Receiver owns focus when this task hands off to another workspace. |
| onCloseRequest | 否 | — | Synchronous host close policy. |
| placement | 否 | — | Desktop placement relative to the original entry. |
| width | 否 | — | Desktop width in CSS pixels or a CSS expression. |
| maxHeight | 否 | — | Optional bottom-panel CSS height limit, additionally clamped to the visible owner viewport. |
| portalTarget | 否 | — | Portal in the owning document; defaults to its body. |

**title**

```ts
string
```

**open**

```ts
boolean | undefined
```

**defaultOpen**

```ts
boolean | undefined
```

**disabled**

```ts
boolean | undefined
```

**presentation**

```ts
QuireKitTaskPresentation | undefined
```

```ts
undefined | "auto" | "desktop" | "bottom"
```

**busy**

```ts
boolean | undefined
```

**canGoBack**

```ts
boolean | undefined
```

**anchorEl**

```ts
(() => HTMLElement | null) | undefined
```

```ts
undefined | { (): HTMLElement | null; }
```

**finalFocusEl**

```ts
(() => HTMLElement | null) | undefined
```

```ts
undefined | { (): HTMLElement | null; }
```

**restoreFocus**

```ts
boolean | undefined
```

**onCloseRequest**

```ts
((request: QuireKitTaskCloseRequest) => void) | undefined
```

```ts
undefined | { (request: QuireKitTaskCloseRequest): void; }
```

**placement**

```ts
QuireKitPopoverPlacement | undefined
```

```ts
undefined | "bottom" | "top" | "top-start" | "top-end" | "right" | "right-start" | "right-end" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end"
```

**width**

```ts
string | number | undefined
```

```ts
undefined | string | number
```

**maxHeight**

```ts
string | undefined
```

```ts
undefined | string
```

**portalTarget**

```ts
string | HTMLElement | undefined
```

```ts
undefined | string | HTMLElement
```

#### Events

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| update\:open | 否 | — |  |
| openChange | 否 | — |  |
| cancel | 否 | — |  |
| back | 否 | — |  |
| contentElementChange | 否 | — |  |

**update:open**

```ts
[open: boolean]
```

**openChange**

```ts
[open: boolean]
```

**cancel**

```ts
[details: { reason: QuireKitTaskCancelReason; sessionId: string; }]
```

**back**

```ts
[]
```

**contentElementChange**

```ts
[element: HTMLElement | null]
```

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| trigger | 否 | — | Real stable opening button with delegated widget bindings. |
| default | 否 | — | Interactive task content. |
| footer | 否 | — | Explicit business submission and recovery controls. |

**trigger**

```ts
{ readonly open: boolean; }
```

```ts
{
  open: boolean;
}
```

**default**

```ts
any
```

**footer**

```ts
any
```

#### 公开实例成员

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| requestClose | 否 | — |  |

**requestClose**

```ts
(reason?: QuireKitTaskCloseReason) => boolean
```

```ts
{ (reason?: QuireKitTaskCloseReason): boolean; }
```

### QuireActionDirectory

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| actions | 是 | — | Current immutable directory level. |
| layout | 否 | "list" | List or two-column action tiles. |
| searchable | 否 | false | Show the accessible search field. |
| searchPlaceholder | 否 | — | Query examples shown inside the field; its accessible label remains separate. |
| query | 否 | undefined | Controlled full query; omission retains local input. |
| busy | 否 | false | Prevent action activation without removing keyboard focus. |
| filter | 否 | — | Optional product alias matching. |

**actions**

```ts
readonly QuireKitActionMenuEntry[]
```

```ts
readonly ({
  /** A command runs the task's execute callback. */
  kind: "command";
  /** Commands never own a child directory. */
  children?: undefined;
  /** 动作执行时返回的唯一值。 */
  value: string;
  /** 动作的可见名称与可访问名称。 */
  label: string;
  /** 动作说明，可用于解释禁用原因。 */
  description?: undefined | string;
  /** 由 QuireIconProvider 提供的图标名。 */
  icon?: string | undefined;
  /** 是否禁用动作。 */
  disabled?: boolean | undefined;
  /** 是否以危险色突出动作。 */
  danger?: boolean | undefined;
  /** 相邻同组动作的分组标题。 */
  group?: string | undefined;
} | {
  /** A branch reveals its child actions. */
  kind: "branch";
  /** Ordered child directory; an empty directory retains a return path. */
  children: readonly QuireKitActionMenuEntry[];
  /** 动作执行时返回的唯一值。 */
  value: string;
  /** 动作的可见名称与可访问名称。 */
  label: string;
  /** 动作说明，可用于解释禁用原因。 */
  description?: string | undefined;
  /** 由 QuireIconProvider 提供的图标名。 */
  icon?: string | undefined;
  /** 是否禁用动作。 */
  disabled?: boolean | undefined;
  /** 是否以危险色突出动作。 */
  danger?: boolean | undefined;
  /** 相邻同组动作的分组标题。 */
  group?: string | undefined;
})[]
```

**layout**

```ts
"list" | "grid" | undefined
```

```ts
undefined | "list" | "grid"
```

**searchable**

```ts
boolean | undefined
```

**searchPlaceholder**

```ts
string | undefined
```

```ts
undefined | string
```

**query**

```ts
string | undefined
```

```ts
undefined | string
```

**busy**

```ts
boolean | undefined
```

**filter**

```ts
((action: QuireKitActionMenuEntry, query: string) => boolean) | undefined
```

```ts
undefined | { (action: QuireKitActionMenuEntry, query: string): boolean; }
```

#### Events

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| activate | 否 | — |  |
| update\:query | 否 | — |  |

**activate**

```ts
[value: string]
```

**update:query**

```ts
[query: string]
```

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| icon | 否 | — | Decorative icon content, sharing ActionMenu's identity contract. |

**icon**

```ts
QuireKitActionMenuIconSlotProps
```

```ts
{
  /** Current immutable command or branch. */
  action: {
    /** A command runs the task's execute callback. */
    kind: "command";
    /** Commands never own a child directory. */
    children?: undefined;
    /** 动作执行时返回的唯一值。 */
    value: string;
    /** 动作的可见名称与可访问名称。 */
    label: string;
    /** 动作说明，可用于解释禁用原因。 */
    description?: undefined | string;
    /** 由 QuireIconProvider 提供的图标名。 */
    icon?: string | undefined;
    /** 是否禁用动作。 */
    disabled?: boolean | undefined;
    /** 是否以危险色突出动作。 */
    danger?: boolean | undefined;
    /** 相邻同组动作的分组标题。 */
    group?: string | undefined;
  } | {
    /** A branch reveals its child actions. */
    kind: "branch";
    /** Ordered child directory; an empty directory retains a return path. */
    children: readonly (QuireKitActionMenuEntry)[];
    /** 动作执行时返回的唯一值。 */
    value: string;
    /** 动作的可见名称与可访问名称。 */
    label: string;
    /** 动作说明，可用于解释禁用原因。 */
    description?: string | undefined;
    /** 由 QuireIconProvider 提供的图标名。 */
    icon?: string | undefined;
    /** 是否禁用动作。 */
    disabled?: boolean | undefined;
    /** 是否以危险色突出动作。 */
    danger?: boolean | undefined;
    /** 相邻同组动作的分组标题。 */
    group?: string | undefined;
  };
}
```

#### 公开实例成员

无。

#### 相关类型

```ts
type QuireKitActionMenuEntry = {
  /** A command runs the task's execute callback. */
  kind: "command";
  /** Commands never own a child directory. */
  children?: undefined;
  /** 动作执行时返回的唯一值。 */
  value: string;
  /** 动作的可见名称与可访问名称。 */
  label: string;
  /** 动作说明，可用于解释禁用原因。 */
  description?: undefined | string;
  /** 由 QuireIconProvider 提供的图标名。 */
  icon?: string | undefined;
  /** 是否禁用动作。 */
  disabled?: boolean | undefined;
  /** 是否以危险色突出动作。 */
  danger?: boolean | undefined;
  /** 相邻同组动作的分组标题。 */
  group?: string | undefined;
} | {
  /** A branch reveals its child actions. */
  kind: "branch";
  /** Ordered child directory; an empty directory retains a return path. */
  children: readonly (QuireKitActionMenuEntry)[];
  /** 动作执行时返回的唯一值。 */
  value: string;
  /** 动作的可见名称与可访问名称。 */
  label: string;
  /** 动作说明，可用于解释禁用原因。 */
  description?: string | undefined;
  /** 由 QuireIconProvider 提供的图标名。 */
  icon?: string | undefined;
  /** 是否禁用动作。 */
  disabled?: boolean | undefined;
  /** 是否以危险色突出动作。 */
  danger?: boolean | undefined;
  /** 相邻同组动作的分组标题。 */
  group?: string | undefined;
};
```

```ts
type QuireKitActionMenuCommand = {
  /** A command runs the task's execute callback. */
  kind: "command";
  /** Commands never own a child directory. */
  children?: undefined;
  /** 动作执行时返回的唯一值。 */
  value: string;
  /** 动作的可见名称与可访问名称。 */
  label: string;
  /** 动作说明，可用于解释禁用原因。 */
  description?: undefined | string;
  /** 由 QuireIconProvider 提供的图标名。 */
  icon?: string | undefined;
  /** 是否禁用动作。 */
  disabled?: boolean | undefined;
  /** 是否以危险色突出动作。 */
  danger?: boolean | undefined;
  /** 相邻同组动作的分组标题。 */
  group?: string | undefined;
};
```

```ts
type QuireKitActionMenuBranch = {
  /** A branch reveals its child actions. */
  kind: "branch";
  /** Ordered child directory; an empty directory retains a return path. */
  children: readonly (QuireKitActionMenuEntry)[];
  /** 动作执行时返回的唯一值。 */
  value: string;
  /** 动作的可见名称与可访问名称。 */
  label: string;
  /** 动作说明，可用于解释禁用原因。 */
  description?: string | undefined;
  /** 由 QuireIconProvider 提供的图标名。 */
  icon?: string | undefined;
  /** 是否禁用动作。 */
  disabled?: boolean | undefined;
  /** 是否以危险色突出动作。 */
  danger?: boolean | undefined;
  /** 相邻同组动作的分组标题。 */
  group?: string | undefined;
};
```

```ts
type QuireKitActionMenuIconSlotProps = {
  /** Current immutable command or branch. */
  action: {
    /** A command runs the task's execute callback. */
    kind: "command";
    /** Commands never own a child directory. */
    children?: undefined;
    /** 动作执行时返回的唯一值。 */
    value: string;
    /** 动作的可见名称与可访问名称。 */
    label: string;
    /** 动作说明，可用于解释禁用原因。 */
    description?: string | undefined;
    /** 由 QuireIconProvider 提供的图标名。 */
    icon?: string | undefined;
    /** 是否禁用动作。 */
    disabled?: boolean | undefined;
    /** 是否以危险色突出动作。 */
    danger?: boolean | undefined;
    /** 相邻同组动作的分组标题。 */
    group?: string | undefined;
  } | {
    /** A branch reveals its child actions. */
    kind: "branch";
    /** Ordered child directory; an empty directory retains a return path. */
    children: readonly QuireKitActionMenuEntry[];
    /** 动作执行时返回的唯一值。 */
    value: string;
    /** 动作的可见名称与可访问名称。 */
    label: string;
    /** 动作说明，可用于解释禁用原因。 */
    description?: string | undefined;
    /** 由 QuireIconProvider 提供的图标名。 */
    icon?: string | undefined;
    /** 是否禁用动作。 */
    disabled?: boolean | undefined;
    /** 是否以危险色突出动作。 */
    danger?: boolean | undefined;
    /** 相邻同组动作的分组标题。 */
    group?: string | undefined;
  };
};
```
