@clipbus/plugin-sdk 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -900,7 +900,7 @@ function renderChrome(root, scenarios, opts, handlers) {
900
900
  header.appendChild(controls);
901
901
  const viewOptions = [
902
902
  { value: "attachmentRenderer", label: "Renderer" },
903
- { value: "action", label: "Action" }
903
+ { value: "action", label: "Draft Action" }
904
904
  ];
905
905
  const viewSelect = buildSelect("cbp-wb-view", "Surface", viewOptions, selectedView, controls);
906
906
  const scenarioAreaWrapper = div("cbp-wb__control");
@@ -1190,7 +1190,7 @@ function renderChrome(root, scenarios, opts, handlers) {
1190
1190
  }
1191
1191
  function updateWorkspaceHead() {
1192
1192
  const scenario = activeScenario();
1193
- const modeLabel = scenario.mode === "attachmentRenderer" ? "attachmentRenderer" : "action";
1193
+ const modeLabel = scenario.mode === "attachmentRenderer" ? "attachmentRenderer" : "draftAction";
1194
1194
  wsChip.textContent = `${modeLabel} \xB7 ${scenario.label}`;
1195
1195
  wsDims.textContent = `${currentWidth} \xD7 ${currentBodyHeightLabel()}`;
1196
1196
  }
@@ -857,7 +857,7 @@ function renderChrome(root, scenarios, opts, handlers) {
857
857
  header.appendChild(controls);
858
858
  const viewOptions = [
859
859
  { value: "attachmentRenderer", label: "Renderer" },
860
- { value: "action", label: "Action" }
860
+ { value: "action", label: "Draft Action" }
861
861
  ];
862
862
  const viewSelect = buildSelect("cbp-wb-view", "Surface", viewOptions, selectedView, controls);
863
863
  const scenarioAreaWrapper = div("cbp-wb__control");
@@ -1147,7 +1147,7 @@ function renderChrome(root, scenarios, opts, handlers) {
1147
1147
  }
1148
1148
  function updateWorkspaceHead() {
1149
1149
  const scenario = activeScenario();
1150
- const modeLabel = scenario.mode === "attachmentRenderer" ? "attachmentRenderer" : "action";
1150
+ const modeLabel = scenario.mode === "attachmentRenderer" ? "attachmentRenderer" : "draftAction";
1151
1151
  wsChip.textContent = `${modeLabel} \xB7 ${scenario.label}`;
1152
1152
  wsDims.textContent = `${currentWidth} \xD7 ${currentBodyHeightLabel()}`;
1153
1153
  }
@@ -27,7 +27,7 @@ export interface WireSection {
27
27
  /**
28
28
  * Classify wire payload sections into display order with open/collapsed defaults.
29
29
  *
30
- * Fixed order: context · item · attachment(renderer)/draft+actionInput(action) · theme · locale
30
+ * Fixed order: context · item · attachment(renderer)/draft+actionInput(Draft Action) · theme · locale
31
31
  * content: item + attachment/draft/actionInput — defaultOpen true
32
32
  * infra: context + theme + locale — defaultOpen false (plumbing, low signal)
33
33
  */
@@ -25,9 +25,12 @@ export interface PreviewScenario {
25
25
  item: PluginClipboardItem;
26
26
  /** Attachment renderer mode payload. */
27
27
  attachment?: PluginAttachmentPayload;
28
- /** Action mode draft payload. */
28
+ /** Draft Action surface payload. */
29
29
  draft?: Record<string, unknown>;
30
- /** Sanitized current Action value; never include real filesystem paths. */
30
+ /**
31
+ * Sanitized current Action value. This may differ in kind from `item`, which
32
+ * remains the original clipboard item identity. Never include real paths.
33
+ */
31
34
  actionInput?: PluginActionUIInput;
32
35
  buttons?: {
33
36
  id: string;
package/docs/preview.md CHANGED
@@ -4,9 +4,9 @@
4
4
 
5
5
  `@clipbus/plugin-sdk/preview` 提供**框架中立**(纯 DOM/TypeScript,不依赖 Vue 或任何 UI 框架)的**开发期**预览 harness。无需真实 macOS 宿主进程,即可在浏览器里迭代插件 UI 的外观与行为。
6
6
 
7
- - **宿主 → 插件注入**:wire payload(bootstrap、item、attachment、theme、draft……)由 harness 根据 scenario 定义按宿主协议生成,与真实宿主注入方式同源。
7
+ - **宿主 → 插件注入**:wire payload(bootstrap、item、attachment、theme、draft、actionInput……)由 harness 根据 scenario 定义按宿主协议生成,与真实宿主注入方式同源。
8
8
  - **插件 → 宿主调用**:所有 `clipbus.*` native 调用被拦截并实时追加到「调用日志」面板;`clipbus.window.setHeight` 额外驱动视口高度;其他调用返回安全默认应答,不抛错。
9
- - **视口**:宽度按模式默认(renderer 720 / action 350;renderer 取自 native 主面板全宽 workspace 区,action 为紧凑 action 卡宽),可被 `scenario.viewport.width` 覆盖,宽度滑杆按 view 切换范围(renderer [560,900]、action [300,500]);高度跟随插件真实调用的 `clipbus.window.setHeight`(`auto`/`bounded` 策略,统一封顶 native 硬上限 800),行为贴近 native。
9
+ - **视口**:宽度按模式默认(renderer 720 / Draft Action 350;renderer 取自 native 主面板全宽 workspace 区,Draft Action 为紧凑卡片宽度),可被 `scenario.viewport.width` 覆盖,宽度滑杆按 view 切换范围(renderer [560,900]、Draft Action [300,500]);高度跟随插件真实调用的 `clipbus.window.setHeight`(`auto`/`bounded` 策略,统一封顶 native 硬上限 800),行为贴近 native。
10
10
 
11
11
  **这是纯开发期工具**,不打包进线上 plugin 产物。
12
12
 
@@ -63,7 +63,8 @@ interface PreviewScenario {
63
63
  accentHex?: string;
64
64
  item: PluginClipboardItem;
65
65
  attachment?: PluginAttachmentPayload; // attachmentRenderer 模式
66
- draft?: Record<string, unknown>; // action 模式
66
+ draft?: Record<string, unknown>; // Draft Action 模式
67
+ actionInput?: PluginActionUIInput; // 当前级联值,可与原始 item 类型不同
67
68
  buttons?: { id: string; title: string; isEnabled: boolean }[];
68
69
  defaultButtonID?: string;
69
70
  viewport?: PreviewViewport;
@@ -75,17 +76,20 @@ interface PreviewScenario {
75
76
  |---|---|
76
77
  | `id` | scenario 唯一标识符 |
77
78
  | `label` | 选择器里显示的名称 |
78
- | `mode` | `'attachmentRenderer'`(渲染器 WebView)或 `'action'`(draft action WebView) |
79
+ | `mode` | `'attachmentRenderer'`(渲染器 WebView)或 `'action'`(Draft Action WebView;内部 wire key 保持 `action`) |
79
80
  | `pluginID` | 注入给插件 `context.pluginID` 的插件 ID;若 attachment.owner 校验依赖此字段,应显式设置;未设置时 harness 使用占位符 |
80
81
  | `accentHex` | 强调色十六进制字符串(e.g. `'#0f766e'`) |
81
- | `item` | 当前 clipboard item(`PluginClipboardItem`) |
82
+ | `item` | 原始 clipboard item 身份(`PluginClipboardItem`);级联过程中保持不变 |
82
83
  | `attachment` | attachmentRenderer 模式的 attachment payload(`PluginAttachmentPayload`) |
83
- | `draft` | action 模式的 initialDraft(`Record<string, unknown>`) |
84
+ | `draft` | Draft Action 模式的 initialDraft(`Record<string, unknown>`) |
85
+ | `actionInput` | 进入当前 Action 的已净化级联值(`PluginActionUIInput`);类型可以与 `item.type` 不同,路径只允许展示安全引用,不能放真实文件路径 |
84
86
  | `buttons` | 按钮条种子:id / title / isEnabled |
85
87
  | `defaultButtonID` | 默认高亮按钮的 id |
86
88
  | `viewport` | 该 scenario 的视口配置;未设置时使用 `opts.defaultViewport` |
87
89
  | `view` | 透传给 `mount` adapter 的不透明 hint(e.g. `'compact'`/`'expanded'`) |
88
90
 
91
+ > **Draft Action 是终点 lifecycle。** `clipbus.action.complete()` 把一个最终结果交回宿主,不会继续进入下一个级联 Action。Preview 因而只模拟 Draft 交互与结果提交,不提供“下一步 Action”状态机。
92
+
89
93
  ---
90
94
 
91
95
  ## `PreviewViewport` 字段参考
@@ -124,11 +128,11 @@ Wire Bench 在右侧 dock 的 IN 卡片中展示**完整 wire 注入内容**(`
124
128
  |---|---|---|
125
129
  | `context` | infra | 折叠 |
126
130
  | `item` | **content** | **展开** |
127
- | `attachment`(renderer)/ `draft`(action)| **content** | **展开** |
131
+ | `attachment`(renderer)/ `draft` + `actionInput`(Draft Action)| **content** | **展开** |
128
132
  | `theme` | infra | 折叠 |
129
133
  | `locale` | infra | 折叠 |
130
134
 
131
- - **content 段**(item + attachment/draft)默认展开,方便与右侧 OUT 输出对照。
135
+ - **content 段**(item + attachment,或 item + draft + actionInput)默认展开,方便对照原始 item、当前级联输入与右侧 OUT 输出。
132
136
  - **infra 段**(context / theme / locale)默认折叠,减少干扰。
133
137
  - 每段独立折叠,互不影响(仅 OUT 是单开 accordion)。
134
138
  - `attachment.payloadJson` 字段:若为合法 JSON 字符串则**解析为可读嵌套 JSON**;解析失败回退原样字符串(不静默吞错)。
@@ -140,7 +144,7 @@ Wire Bench 在右侧 dock 的 IN 卡片中展示**完整 wire 注入内容**(`
140
144
 
141
145
  harness 安装一个最小双向 fake host:
142
146
 
143
- - **host → plugin**:按 scenario 字段生成 wire payload 并注入;bootstrap、item、attachment、theme 等不需要真实宿主
147
+ - **host → plugin**:按 scenario 字段生成 wire payload 并注入;bootstrap、item、attachment、draft、actionInput、theme 等不需要真实宿主
144
148
  - **plugin → host**:所有 `clipbus.*` native 调用被拦截,实时追加到右侧 dock 的 OUT 卡片;`clipbus.window.setHeight` 额外驱动视口高度;其他调用返回安全默认应答
145
149
 
146
150
  OUT 卡片使用**单开 accordion**:
@@ -197,14 +201,14 @@ npm run dev
197
201
 
198
202
  Vite 启动后,工作台提供:
199
203
 
200
- - **两级模式导航**:顶层 Surface 选择器在 **Renderer**(attachmentRenderer)和 **Action** 两种模式间切换;两种模式的 scenario 均用 `<select>` 下拉选择(文案取自 `scenario.label`)。任何时刻只渲染当前选中 scenario。URL query `?view=&scenario=&theme=` 同步,刷新不丢。
204
+ - **两级模式导航**:顶层 Surface 选择器在 **Renderer**(`attachmentRenderer`)和 **Draft Action**(内部值仍为 `action`)两种 UI surface 间切换;auto-run Action 没有插件 UI,因此不属于 preview surface。两种模式的 scenario 均用 `<select>` 下拉选择(文案取自 `scenario.label`)。任何时刻只渲染当前选中 scenario。URL query `?view=&scenario=&theme=` 同步,刷新不丢。
201
205
  - **主题切换**(4 预设:Graphite · Ember · Porcelain · Sand):切换时三重作用:① 重注入 wire 主题 topic,插件已注册的 `clipbus.theme.on()` 回调立即触发;② 仅重着色**卡片壳与插件内容**(chrome 本身配色保持稳定,见下方[主题解耦](#主题解耦chrome-稳定--卡片跟-native));③ 在插件挂载槽上更新 `--clipbus-*` CSS 变量——不触发 remount,与 native `theme.onChange` 行为一致。注意:插件的 `--clipbus-accent` 是**全局主题 accent**;`scenario.accentHex` 是该附件的 **tintColor**,只染**卡片边框**(对应 native `record.tintColor`),不进插件配色。
202
206
  - **Workspace(主工作区,左列)**:标本卡(frozen specimen)居中展示,下方有**生长地板**标注 `native ceiling ≈ 800px`,把卡片下方空白变成"到硬上限的余量"这一有意义信息。卡片再高只撑左列,不影响右侧 dock。
203
207
  - **Dock(右列,`position:sticky`)**:卡片变高时右侧不被推走——IN / OUT 两张附件卡始终在视野内。
204
208
  - **IN · Wire Input 面板**:见[上文 Wire Input 面板](#wire-input-面板in--hostplugin)。
205
209
  - **OUT · Native Calls 面板**:见[上文 Native Calls 面板](#native-calls-面板out--pluginhost与-fake-host)。
206
210
  - **Native 卡片壳**:卡片框(10 px padding / 7 px 圆角(native `radius.panelInner`)/ 1 px 描边(色取 `scenario.accentHex` 附件 tint,回退主题 accent)/ surfaceElevated 背景)是**外层卡片**,纵向堆叠 **body(插件挂载槽 `slotEl`)+ 按钮条**,对应 native `AttachmentRenderCardShell` 的 `VStack { body; actions }`。卡片宽度由滑杆控制,webview 按卡片 chrome(每边 11 px = 10 padding + 1 border)内嵌;卡片高度自动包裹 body + 按钮条。
207
- - **宽度滑杆**:拖动**卡片外层宽度**(webview 随之按 chrome 内嵌),范围随 view 切换。模式默认(取自 native):renderer 初始 720 px、范围 [560,900];action 初始 350 px、范围 [300,500]。`scenario.viewport.width` 可覆盖初始值;`viewport.widthMin`/`widthMax` 可覆盖滑杆范围。
211
+ - **宽度滑杆**:拖动**卡片外层宽度**(webview 随之按 chrome 内嵌),范围随 view 切换。模式默认(取自 native):renderer 初始 720 px、范围 [560,900];Draft Action 初始 350 px、范围 [300,500]。`scenario.viewport.width` 可覆盖初始值;`viewport.widthMin`/`widthMax` 可覆盖滑杆范围。
208
212
  - **body 高度**:高度**由插件驱动**。native **没有**宿主侧"量内容定高":`auto` 在 native 解析为 `bounded(80, 800)`,且只认 `clipbus.window.setHeight`——插件**必须**用 SDK `autoFit`(或手动 `setHeight`)自撑,否则卡在 policy 最小高度被裁。harness 在插件首个 `setHeight` 前以内容高度做种子(宽松的预览便利,**非** native 行为)。所有策略统一封顶 native 硬上限 **800**(`AttachmentRenderHeightConstants.ceiling`)。
209
213
  - **按钮条**:源自 `scenario.buttons`(及插件 `setButtons`),位于**卡片内部、body 下方、左对齐**(native action row 布局);无按钮时不占位。
210
214
  - **主题感知滚动条**:工作台内所有滚动区域(dock 面板 + 插件内容)统一为细、半透明的滚动条,使用稳定的 bench 调色(不随主题变色)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipbus/plugin-sdk",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "type": "module",
5
5
  "description": "Typed SDK for authoring Clipbus plugins — runtime (Node.js) and UI (WebView) helpers generated from the Clipbus plugin wire contract.",
6
6
  "keywords": [