@kimposoft/plugin-sdk 0.0.0-stage → 1.1.0-tp.20
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.
- package/LICENSE +202 -0
- package/NOTICE +9 -0
- package/README.md +48 -2
- package/package.json +141 -4
- package/src/action-designer.ts +250 -0
- package/src/attachment-url.ts +195 -0
- package/src/auth/index.ts +6 -0
- package/src/auth/qrcode.ts +519 -0
- package/src/auth/types.ts +261 -0
- package/src/display-style.ts +250 -0
- package/src/editor-frame.ts +623 -0
- package/src/editor-session.ts +1214 -0
- package/src/editor-testing.ts +838 -0
- package/src/editor.ts +1641 -0
- package/src/frame-transport.ts +491 -0
- package/src/frontend-routes.ts +99 -0
- package/src/hooks.ts +48 -0
- package/src/host-caps.ts +93 -0
- package/src/i18n.ts +238 -0
- package/src/im-panel.ts +132 -0
- package/src/image-tools.ts +91 -0
- package/src/index.ts +118 -0
- package/src/interactive-session.ts +94 -0
- package/src/nahida-im.ts +391 -0
- package/src/nahida-ws.ts +23 -0
- package/src/org-directory.ts +78 -0
- package/src/oz-realtime.ts +144 -0
- package/src/page.ts +404 -0
- package/src/print.ts +393 -0
- package/src/surface.ts +281 -0
- package/src/theme-mocks.ts +140 -0
- package/src/theme.ts +125 -0
- package/src/ui-fixtures/confirm.ts +16 -0
- package/src/ui-fixtures/entity-picker.ts +24 -0
- package/src/ui-fixtures/expression-editor.ts +52 -0
- package/src/ui-fixtures/image-cropper.ts +23 -0
- package/src/ui-fixtures/index.ts +16 -0
- package/src/ui-fixtures/org-tri-picker.ts +19 -0
- package/src/ui-fixtures/prompt.ts +19 -0
- package/src/ui-fixtures/record-picker.ts +17 -0
- package/src/ui-fixtures/template-picker.ts +13 -0
- package/src/ui-mocks.ts +250 -0
- package/src/ui.ts +479 -0
- package/src/workflow-designer.ts +475 -0
package/src/print.ts
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
// 打印方案 B 档(capabilities.print_modes[].spec_source = "frontend")前端契约。
|
|
2
|
+
//
|
|
3
|
+
// 第三方打印扩展的 buildSpec 在宿主创建的隐藏沙箱 iframe 中执行(与第三方挂载点同一套沙箱框架):
|
|
4
|
+
// 宿主把可 JSON 化的打印上下文经框架桥传进来,插件返回 PrintJobSpec,宿主校验后交给表格编辑器渲染预览 / 打印。
|
|
5
|
+
// 旧写法(UMD 脚本把 buildSpec 挂到 window 全局、由宿主同源注入)对第三方不再生效,须改用本文件的
|
|
6
|
+
// definePrintModeBuildSpec 重新打包。
|
|
7
|
+
//
|
|
8
|
+
// 用法(插件前端入口,打成 manifest capabilities.frontend.bundle 指向的单文件):
|
|
9
|
+
//
|
|
10
|
+
// import { definePrintModeBuildSpec } from '@kimposoft/plugin-sdk';
|
|
11
|
+
// export const buildSpec = definePrintModeBuildSpec(ctx => {
|
|
12
|
+
// ctx.log.info(`rows=${Object.keys(ctx.record.detailRows).length}`);
|
|
13
|
+
// return { version: 1, target: { scope: 'activeContainer', leafId: null }, output: { kind: 'print' } };
|
|
14
|
+
// });
|
|
15
|
+
//
|
|
16
|
+
// 沙箱框架里 definePrintModeBuildSpec 会自动启动打印运行时;不在框架里(Node 本地自测、同源档)时只是
|
|
17
|
+
// 原样返回 fn,可直接调用做单测。
|
|
18
|
+
//
|
|
19
|
+
// 桥协议(复用沙箱框架协议 v1,宿主侧已封装,插件不必关心):
|
|
20
|
+
// 宿主 → 框架:init(握手后首条)/ expose({id, method: <entry>, args: [context]})/ destroy
|
|
21
|
+
// 框架 → 宿主:mounted(运行时就绪)/ mount-error / expose-result({id, ok, value | error})/ log
|
|
22
|
+
// method 为 manifest print_modes[].entry(缺省 "buildSpec")。
|
|
23
|
+
|
|
24
|
+
import { FRAME_PROTOCOL_VERSION, createFrameClient, isKimpoFrameContext, readKimpoFrameMeta } from './frame-transport';
|
|
25
|
+
|
|
26
|
+
// ==================== 上下文 ====================
|
|
27
|
+
|
|
28
|
+
/** 打印场景:设计态预览 / 填报态预览 / 填报态打印 / 动作触发。 */
|
|
29
|
+
export type PrintModeJobScene = 'design-preview' | 'form-preview' | 'form-print' | 'action';
|
|
30
|
+
|
|
31
|
+
/** 单个字段值:display 为显示串,raw 为原始值。 */
|
|
32
|
+
export interface PrintModeFieldValue {
|
|
33
|
+
display: string;
|
|
34
|
+
raw: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 字段映射:键优先取字段编码,编码为空时退回字段 ID。 */
|
|
38
|
+
export type PrintModeFieldMap = Record<string, PrintModeFieldValue>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 明细行:以明细表的 dataTableId 为键,值是行数组;每行是「字段编码(为空时字段 ID)→ {display, raw}」。
|
|
42
|
+
* 没有明细表目录,按 Object.keys(detailRows) 遍历即可。
|
|
43
|
+
*/
|
|
44
|
+
export type PrintModeDetailRows = Record<string, Array<PrintModeFieldMap>>;
|
|
45
|
+
|
|
46
|
+
/** buildSpec 内的日志口:写入宿主前端日志中心,归类为 module = plugin:<插件ID>(插件无法冒用其他 ID)。 */
|
|
47
|
+
export interface PrintModeLogger {
|
|
48
|
+
debug(message: string, ...detail: unknown[]): void;
|
|
49
|
+
info(message: string, ...detail: unknown[]): void;
|
|
50
|
+
warn(message: string, ...detail: unknown[]): void;
|
|
51
|
+
error(message: string, ...detail: unknown[]): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** buildSpec(context) 的入参。除 log 外均为纯数据。 */
|
|
55
|
+
export interface PrintModeBuildSpecContext {
|
|
56
|
+
record: {
|
|
57
|
+
/** 单据 ID;新增未保存与设计态为空串。 */
|
|
58
|
+
id: string;
|
|
59
|
+
/** 主表字段。 */
|
|
60
|
+
fields: PrintModeFieldMap;
|
|
61
|
+
/** 明细行,见 PrintModeDetailRows。 */
|
|
62
|
+
detailRows: PrintModeDetailRows;
|
|
63
|
+
};
|
|
64
|
+
/** 制单用户。 */
|
|
65
|
+
user: { id: string; name: string; department?: string };
|
|
66
|
+
/** 模板。 */
|
|
67
|
+
template: { id: string; name: string; version?: string };
|
|
68
|
+
job: { scene: PrintModeJobScene; capabilities: { canPrint: boolean; canExportPdf: boolean } };
|
|
69
|
+
/** manifest params 默认值与设计者配置合并后的值(数字参数可能以字符串到达,按需解析校验)。 */
|
|
70
|
+
params: Record<string, unknown>;
|
|
71
|
+
/** 宿主当前语言区域(BCP-47 连字符形式,如 "zh-CN"、"en-US")。 */
|
|
72
|
+
locale: string;
|
|
73
|
+
/** 设计态预览没有真实单据时为 true:record 内容是按模板字段生成的占位样例(文本用字段名、数字 0、日期取今天、明细 2 行)。 */
|
|
74
|
+
isSample: boolean;
|
|
75
|
+
/** 日志口。 */
|
|
76
|
+
log: PrintModeLogger;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ==================== PrintJobSpec ====================
|
|
80
|
+
|
|
81
|
+
/** 打印范围(打什么)。leafId=null 指当前活动叶子。 */
|
|
82
|
+
export interface PrintTarget {
|
|
83
|
+
scope: 'activeContainer' | 'leaf' | 'selection' | 'printArea';
|
|
84
|
+
leafId?: string | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 水印图层。text 支持 {{...}} 表达式(可用的根见 PrintTextContent)。 */
|
|
88
|
+
export interface PrintWatermarkLayer {
|
|
89
|
+
type: 'watermark';
|
|
90
|
+
text: string;
|
|
91
|
+
/** 旋转角度(度)。 */
|
|
92
|
+
angle: number;
|
|
93
|
+
/** 不透明度 0~1。 */
|
|
94
|
+
opacity: number;
|
|
95
|
+
/** 字号,单位**像素 px**(注意:文本框 style.size 是 pt,两者口径不同)。 */
|
|
96
|
+
font: { size: number };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** 背景(套打底图)图层:assetId(宿主资产)与 url 二选一。 */
|
|
100
|
+
export interface PrintBackgroundLayer {
|
|
101
|
+
type: 'background';
|
|
102
|
+
assetId?: string;
|
|
103
|
+
url?: string;
|
|
104
|
+
fit: 'page';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 全页图层(数组顺序即绘制顺序)。 */
|
|
108
|
+
export type PrintLayer = PrintWatermarkLayer | PrintBackgroundLayer;
|
|
109
|
+
|
|
110
|
+
/** 内容框:内嵌表格渲染片段。 */
|
|
111
|
+
export interface PrintSheetFragmentContent {
|
|
112
|
+
type: 'sheetFragment';
|
|
113
|
+
scope: 'activeContainer' | 'leaf' | 'selection' | 'printArea';
|
|
114
|
+
leafId?: string | null;
|
|
115
|
+
fit: 'width' | 'contain';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 内容框:文本。
|
|
120
|
+
*
|
|
121
|
+
* expr(必填、非空)支持:
|
|
122
|
+
* - `{{...}}` 表达式:点路径、单引号字符串、`==` / `!=`、三元 `a ? b : c`;不支持数字字面量、函数、运算符,不执行 JS。
|
|
123
|
+
* 可用的根:`record.<键>`(显示串;`.raw` 取原始值)、`item.<键>`(仅 pageTemplate.repeat 的格子内)、
|
|
124
|
+
* `user.name / id / department`、`template.name / id / version`、`params.<键>`。没有 `now`、`record.id`、`detailRows`。
|
|
125
|
+
* `<键>` 是字段编码,编码为空时退回字段 ID;路径里只允许 `[A-Za-z0-9_]`。注意表达式里写 `{{record.amount}}`,
|
|
126
|
+
* **不是** buildSpec context 里的 `record.fields.amount`。未知路径按空串降级(记一条警告,不中断)。
|
|
127
|
+
* `user.*` / `template.*` 取当前登录用户与当前模板(SDK 1.1.0-tp.10 对应宿主起;`user.department` 仍为空);
|
|
128
|
+
* 新增未保存单据按当前填写值取 `record`,设计态预览按模板字段生成占位样例(文本为字段名、数字 0、日期为今天)。
|
|
129
|
+
* 更早的宿主上 `user.id` / `template.id` 为空、没有单据 ID 时 `record` / `item` 为空。
|
|
130
|
+
* - 页码代码 `&P`(页码)/ `&N`(总页数)/ `&D`(日期)/ `&T`(时间)。
|
|
131
|
+
* - 换行只认 `\n`(行高 1.2 倍),文字顶对齐;超出框的部分被裁掉。
|
|
132
|
+
*
|
|
133
|
+
* 不支持:边框、底色、自动换行、自动缩字、垂直对齐、斜体、选字体(字体固定为系统无衬线体)。
|
|
134
|
+
* 需要边框 / 格线时用套打底图(background 图层或 image 框)。
|
|
135
|
+
*/
|
|
136
|
+
export interface PrintTextContent {
|
|
137
|
+
type: 'text';
|
|
138
|
+
expr: string;
|
|
139
|
+
/** size:字号,单位**磅 pt**(缺省 9);align 缺省 left;color 缺省 #000。 */
|
|
140
|
+
style?: { size: number; align: 'left' | 'center' | 'right'; bold?: boolean; color?: string };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 内容框:图片(assetId 与 url 至少给一个,都给时用 url;加载失败只告警、该框留空)。 */
|
|
144
|
+
export interface PrintImageContent {
|
|
145
|
+
type: 'image';
|
|
146
|
+
assetId?: string;
|
|
147
|
+
url?: string;
|
|
148
|
+
fit: 'contain' | 'cover' | 'fill';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 内容框:条码。**当前只实现二维码**(format 只能是 'qrcode',其他值校验失败);一维条码(Code128 等)未实现。
|
|
153
|
+
* 二维码纠错级别 M、版本自动,取框的短边画成居中正方形(四周留约 8% 白边)。
|
|
154
|
+
* expr 必填,支持 `{{...}}` 表达式(同文本框),但**不处理** `&P` / `&N` 等页码代码;求值为空串时不画。
|
|
155
|
+
*/
|
|
156
|
+
export interface PrintBarcodeContent {
|
|
157
|
+
type: 'barcode';
|
|
158
|
+
format: 'qrcode';
|
|
159
|
+
expr: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type PrintFrameContent = PrintSheetFragmentContent | PrintTextContent | PrintImageContent | PrintBarcodeContent;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 页面模板内容框。rect 单位 mm,x / y / w / h 须为非负数;越界不报错,超出部分被裁掉。
|
|
166
|
+
* 坐标原点:不在 repeat.frameSetPerItem 里的框相对**内容区左上角**(纸张扣掉 margins 之后),每页都画;
|
|
167
|
+
* 在 frameSetPerItem 里的框相对**所在格子左上角**。frames 按数组顺序绘制,后画的盖在上面。
|
|
168
|
+
*/
|
|
169
|
+
export interface PrintFrame {
|
|
170
|
+
id: string;
|
|
171
|
+
rect: { x: number; y: number; w: number; h: number };
|
|
172
|
+
content: PrintFrameContent;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 迭代规则:把 frameSetPerItem 里的框当成一个「格子」,在内容区里按行优先(先排满一行再换行)重复摆放。
|
|
177
|
+
*
|
|
178
|
+
* - 格子尺寸 = frameSetPerItem 各框外接矩形(max(x+w) × max(y+h));格距 gap 单位 mm,缺省 0。
|
|
179
|
+
* - cols 缺省 1;rows 缺省按内容区高度能放下的行数自动计算(至少 1)。显式 rows 过大时格子会画到纸外被裁掉。
|
|
180
|
+
* - `kind: 'grid'` 与 `kind: 'records'`:**当前实现相同**——都按 dataSource 指向的明细行逐行填格(格内 `{{item.<键>}}`
|
|
181
|
+
* 取该行),每页放 cols×rows 格、按行数自动分页;grid 校验时要求 cols / rows ≥ 1,records 要求 dataSource 非空。
|
|
182
|
+
* 没有 dataSource(或明细为空)时只画非重复框。超过 1000 页拒绝,超过 200 页告警。
|
|
183
|
+
* - `kind: 'copies'`:只出 1 页,画 cols×rows 个**内容完全相同**的格子(不注入 item、忽略 dataSource),用于一页多联。
|
|
184
|
+
* - dataSource 写 `detailRows.<明细表 dataTableId>`(前缀可省);**不能**按主表字段或多张单据重复。
|
|
185
|
+
*/
|
|
186
|
+
export interface PrintRepeatSpec {
|
|
187
|
+
kind: 'grid' | 'records' | 'copies';
|
|
188
|
+
cols?: number;
|
|
189
|
+
rows?: number;
|
|
190
|
+
gap?: { x: number; y: number };
|
|
191
|
+
dataSource?: string;
|
|
192
|
+
frameSetPerItem: string[];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 纸张名(区分大小写)。未知值(含 'a4'、'Custom')**静默回落 A4**,不报错;pageTemplate 不支持自定义纸张尺寸
|
|
197
|
+
* (标签纸等非标尺寸请在 A4 等标准纸上按坐标拼版,或用 repeat 网格)。
|
|
198
|
+
* 尺寸(mm,纵向):A4 210×297、A3 297×420、A5 148×210、B4 250×353、B5 176×250、
|
|
199
|
+
* Letter 215.9×279.4、Legal 215.9×355.6、Tabloid 279.4×431.8。
|
|
200
|
+
*/
|
|
201
|
+
export type PrintPaperSize = 'A4' | 'A3' | 'A5' | 'B4' | 'B5' | 'Letter' | 'Legal' | 'Tabloid';
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 框式页面编排。**存在时接管整个版面**:PrintJobSpec 的 target、pageSetupOverride 与模板页眉页脚都不再生效;
|
|
205
|
+
* 绘制顺序为 background 图层 → frames → watermark 图层。导出 PDF 时是整页位图嵌入(不是矢量)。
|
|
206
|
+
*/
|
|
207
|
+
export interface PrintPageTemplateSpec {
|
|
208
|
+
/** 纸张名,见 PrintPaperSize(类型保留 string 兼容旧代码,未知值回落 A4)。 */
|
|
209
|
+
paper: PrintPaperSize | (string & {});
|
|
210
|
+
/** landscape 时宽高对调。 */
|
|
211
|
+
orientation: 'portrait' | 'landscape';
|
|
212
|
+
/** 页边距,单位 mm(应为非负数;宿主只校验是数字)。内容区 = 纸张 − 四边距。 */
|
|
213
|
+
margins: { t: number; b: number; l: number; r: number };
|
|
214
|
+
frames: PrintFrame[];
|
|
215
|
+
repeat?: PrintRepeatSpec;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** 出口。fileName 支持 {{...}} 表达式。 */
|
|
219
|
+
export interface PrintOutputSpec {
|
|
220
|
+
kind: 'print' | 'pdf' | 'pdfBlob';
|
|
221
|
+
fileName?: string;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* PrintJobSpec:插件声明「打什么、怎么排版」的 JSON,宿主校验后执行。
|
|
226
|
+
* pageSetupOverride 是对模板页面设置的增量覆盖(页眉页脚、纸张、边距等),未设置的字段沿用模板保存值。
|
|
227
|
+
*/
|
|
228
|
+
export interface PrintJobSpec {
|
|
229
|
+
version: 1;
|
|
230
|
+
target: PrintTarget;
|
|
231
|
+
pageSetupOverride?: Record<string, unknown>;
|
|
232
|
+
layers?: PrintLayer[];
|
|
233
|
+
pageTemplate?: PrintPageTemplateSpec;
|
|
234
|
+
output: PrintOutputSpec;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** buildSpec 函数签名,可返回 Promise。 */
|
|
238
|
+
export type PrintModeBuildSpecFn = (context: PrintModeBuildSpecContext) => PrintJobSpec | Promise<PrintJobSpec>;
|
|
239
|
+
|
|
240
|
+
/** definePrintModeBuildSpec 的可选项。 */
|
|
241
|
+
export interface PrintModeBuildSpecOptions {
|
|
242
|
+
/** 对应 manifest print_modes[].entry;缺省 "buildSpec"。一个插件有多个打印方案时按 entry 分别登记。 */
|
|
243
|
+
entry?: string;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// ==================== 沙箱框架运行时 ====================
|
|
247
|
+
|
|
248
|
+
const DEFAULT_ENTRY = 'buildSpec';
|
|
249
|
+
const PRINT_RUNTIME_STARTED = Symbol.for('kimpo.frame.print.runtime.started');
|
|
250
|
+
/** entry → buildSpec 登记表(模块级)。 */
|
|
251
|
+
const registered = new Map<string, PrintModeBuildSpecFn>();
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 登记 B 档 buildSpec。沙箱框架里同时启动打印运行时(幂等),宿主经 expose 调用;
|
|
255
|
+
* 返回 fn 本身,便于 export 与本地单测。
|
|
256
|
+
*/
|
|
257
|
+
export function definePrintModeBuildSpec(fn: PrintModeBuildSpecFn, options: PrintModeBuildSpecOptions = {}): PrintModeBuildSpecFn {
|
|
258
|
+
registered.set(options.entry || DEFAULT_ENTRY, fn);
|
|
259
|
+
if (isKimpoFrameContext()) startPrintModeFrameRuntime();
|
|
260
|
+
return fn;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** startPrintModeFrameRuntime 的可注入依赖(默认取浏览器全局,单测可替换)。 */
|
|
264
|
+
export interface PrintModeFrameRuntimeOptions {
|
|
265
|
+
win?: Window;
|
|
266
|
+
doc?: Document;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 启动打印运行时(幂等):等待宿主握手,应答 expose 调用。不在沙箱框架里返回 false。
|
|
271
|
+
* 一般不必直接调用——definePrintModeBuildSpec 在框架里会自动调用。
|
|
272
|
+
*/
|
|
273
|
+
export function startPrintModeFrameRuntime(options: PrintModeFrameRuntimeOptions = {}): boolean {
|
|
274
|
+
const win = options.win ?? (typeof window === 'undefined' ? undefined : window);
|
|
275
|
+
const doc = options.doc ?? (typeof document === 'undefined' ? undefined : document);
|
|
276
|
+
if (!win || !doc) return false;
|
|
277
|
+
if (!readKimpoFrameMeta(doc)) return false;
|
|
278
|
+
const flagHost = win as unknown as Record<symbol, boolean>;
|
|
279
|
+
if (flagHost[PRINT_RUNTIME_STARTED]) return true;
|
|
280
|
+
flagHost[PRINT_RUNTIME_STARTED] = true;
|
|
281
|
+
|
|
282
|
+
const onInit = (event: MessageEvent) => {
|
|
283
|
+
// 只认父窗口的第一次握手;其余 window 层消息一律忽略。
|
|
284
|
+
if (event.source !== win.parent) return;
|
|
285
|
+
const data = event.data as Record<string, unknown> | null;
|
|
286
|
+
if (!data || typeof data !== 'object' || data.kimpoFrame !== 'init' || !event.ports?.[0]) return;
|
|
287
|
+
win.removeEventListener('message', onInit);
|
|
288
|
+
bootPrintOnPort(event.ports[0], win);
|
|
289
|
+
};
|
|
290
|
+
win.addEventListener('message', onInit);
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
295
|
+
|
|
296
|
+
/** 把日志参数拼成一行文本(对象按 JSON 输出)。 */
|
|
297
|
+
function formatLog(message: string, detail: unknown[]): string {
|
|
298
|
+
if (detail.length === 0) return String(message);
|
|
299
|
+
const parts = detail.map(item => {
|
|
300
|
+
if (typeof item === 'string') return item;
|
|
301
|
+
if (item instanceof Error) return item.message;
|
|
302
|
+
try {
|
|
303
|
+
return JSON.stringify(item);
|
|
304
|
+
} catch {
|
|
305
|
+
return String(item);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
return `${String(message)} ${parts.join(' ')}`;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
312
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** 宿主传入的上下文 → 带默认值与日志口的完整上下文(宿主缺字段时不让插件拿到 undefined)。 */
|
|
316
|
+
function buildContext(raw: unknown, logger: PrintModeLogger, fallbackLocale: string): PrintModeBuildSpecContext {
|
|
317
|
+
const src = isRecord(raw) ? raw : {};
|
|
318
|
+
const record = isRecord(src.record) ? src.record : {};
|
|
319
|
+
const user = isRecord(src.user) ? src.user : {};
|
|
320
|
+
const template = isRecord(src.template) ? src.template : {};
|
|
321
|
+
const job = isRecord(src.job) ? src.job : {};
|
|
322
|
+
const caps = isRecord(job.capabilities) ? job.capabilities : {};
|
|
323
|
+
return {
|
|
324
|
+
record: {
|
|
325
|
+
id: typeof record.id === 'string' ? record.id : '',
|
|
326
|
+
fields: (isRecord(record.fields) ? record.fields : {}) as PrintModeFieldMap,
|
|
327
|
+
detailRows: (isRecord(record.detailRows) ? record.detailRows : {}) as PrintModeDetailRows
|
|
328
|
+
},
|
|
329
|
+
user: {
|
|
330
|
+
id: typeof user.id === 'string' ? user.id : '',
|
|
331
|
+
name: typeof user.name === 'string' ? user.name : '',
|
|
332
|
+
...(typeof user.department === 'string' ? { department: user.department } : {})
|
|
333
|
+
},
|
|
334
|
+
template: {
|
|
335
|
+
id: typeof template.id === 'string' ? template.id : '',
|
|
336
|
+
name: typeof template.name === 'string' ? template.name : '',
|
|
337
|
+
...(typeof template.version === 'string' ? { version: template.version } : {})
|
|
338
|
+
},
|
|
339
|
+
job: {
|
|
340
|
+
scene: (typeof job.scene === 'string' ? job.scene : 'form-preview') as PrintModeJobScene,
|
|
341
|
+
capabilities: { canPrint: caps.canPrint === true, canExportPdf: caps.canExportPdf === true }
|
|
342
|
+
},
|
|
343
|
+
params: isRecord(src.params) ? src.params : {},
|
|
344
|
+
locale: typeof src.locale === 'string' && src.locale ? src.locale : fallbackLocale,
|
|
345
|
+
isSample: src.isSample === true,
|
|
346
|
+
log: logger
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function bootPrintOnPort(port: MessagePort, win: Window): void {
|
|
351
|
+
const client = createFrameClient(port);
|
|
352
|
+
const post = (level: LogLevel, message: string) => client.post({ t: 'log', level, message });
|
|
353
|
+
const logger: PrintModeLogger = {
|
|
354
|
+
debug: (m, ...d) => post('debug', formatLog(m, d)),
|
|
355
|
+
info: (m, ...d) => post('info', formatLog(m, d)),
|
|
356
|
+
warn: (m, ...d) => post('warn', formatLog(m, d)),
|
|
357
|
+
error: (m, ...d) => post('error', formatLog(m, d))
|
|
358
|
+
};
|
|
359
|
+
win.addEventListener('error', event => post('error', String((event as ErrorEvent).message ?? event)));
|
|
360
|
+
win.addEventListener('unhandledrejection', event => post('error', `unhandled rejection: ${String((event as PromiseRejectionEvent).reason)}`));
|
|
361
|
+
|
|
362
|
+
// 握手后宿主发 init:核对协议版本,回 mounted 表示可以接受 buildSpec 调用。
|
|
363
|
+
client.on('init', msg => {
|
|
364
|
+
if (msg.v !== FRAME_PROTOCOL_VERSION) {
|
|
365
|
+
client.post({ t: 'mount-error', message: `unsupported frame protocol version ${String(msg.v)}` });
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (registered.size === 0) {
|
|
369
|
+
client.post({ t: 'mount-error', message: 'no print buildSpec registered (use definePrintModeBuildSpec)' });
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
client.post({ t: 'mounted' });
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// 宿主经 expose 调用 buildSpec:method = manifest print_modes[].entry,args[0] = 上下文。
|
|
376
|
+
client.on('expose', async msg => {
|
|
377
|
+
const method = typeof msg.method === 'string' && msg.method ? msg.method : DEFAULT_ENTRY;
|
|
378
|
+
try {
|
|
379
|
+
const fn = registered.get(method);
|
|
380
|
+
if (!fn) throw new Error(`print buildSpec "${method}" is not registered`);
|
|
381
|
+
const args = Array.isArray(msg.args) ? msg.args : [];
|
|
382
|
+
const navLocale = typeof navigator !== 'undefined' && navigator.language ? navigator.language : '';
|
|
383
|
+
const context = buildContext(client.decode(args[0]), logger, client.locale || navLocale);
|
|
384
|
+
const spec = await fn(context);
|
|
385
|
+
client.post({ t: 'expose-result', id: msg.id, ok: true, value: client.encodeArg(spec) });
|
|
386
|
+
} catch (error) {
|
|
387
|
+
client.post({ t: 'expose-result', id: msg.id, ok: false, error: { message: error instanceof Error ? error.message : String(error) } });
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// 打印框架无组件可卸载,destroy 无需处理。
|
|
392
|
+
client.on('destroy', () => undefined);
|
|
393
|
+
}
|
package/src/surface.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// 通用 surface 类型契约——插件前端通过 definePluginSurface 声明挂载工厂。
|
|
2
|
+
// 宿主按 surfaceType 精确命中并调用;editor 插件可同时导出 createEditor(旧)+ createSurface(新),
|
|
3
|
+
// 宿主优先调用 createSurface,缺失时降级 createEditor(向后兼容)。
|
|
4
|
+
//
|
|
5
|
+
// 挂载档:同一份 createSurface 在两种档下都能用——同源档由宿主直接调用;
|
|
6
|
+
// 沙箱档(第三方插件一律如此)由 definePluginSurface 自动启动框架运行时(frame-transport.ts)在 iframe 里调用。
|
|
7
|
+
|
|
8
|
+
import { isKimpoFrameContext, registerFrameSurfaceFactory } from './frame-transport';
|
|
9
|
+
|
|
10
|
+
/** 平台支持的挂载点类型枚举(前后端对齐,见 Go SurfaceDecl.Type)。 */
|
|
11
|
+
export type SurfaceType =
|
|
12
|
+
| 'designer'
|
|
13
|
+
| 'runtime'
|
|
14
|
+
| 'action-config'
|
|
15
|
+
| 'login-form'
|
|
16
|
+
| 'page-slot'
|
|
17
|
+
| 'config-form'
|
|
18
|
+
// 流程引擎目前只有 'workflow-designer' 这一个设计器 surface(页面级挂载点)。早期版本的
|
|
19
|
+
// 'workflow-binding-config' / 'workflow-form-runtime' / 'workflow-task-center' /
|
|
20
|
+
// 'workflow-task-detail-actions' / 'workflow-progress' / 'workflow-admin' 等挂载点已移除,
|
|
21
|
+
// 填报态与任务中心由宿主自身承担。
|
|
22
|
+
| 'workflow-designer'
|
|
23
|
+
// IM 前端(消息引擎前端插件)悬浮窗容器。宿主经 resolvePluginSurfaces
|
|
24
|
+
// 命中并挂载,窗口显隐由宿主 v-show 控制(不销毁组件、不断 WS)。
|
|
25
|
+
| 'im-panel'
|
|
26
|
+
// 动作设计器整面 surface:宿主在模板设计器与定时任务设计里挂载(契约见 action-designer.ts)。
|
|
27
|
+
| 'action-designer'
|
|
28
|
+
// KimpoAI 产品对话面悬浮窗容器:宿主经 resolvePluginSurfaces 按 priority 最高单提供者
|
|
29
|
+
// 命中并挂在页面根级,窗口显隐由宿主单例控制(同 im-panel 范式)。
|
|
30
|
+
| 'kimpoai-panel';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* surface 挂载档(manifest capabilities.frontend.surfaces[].mount)。
|
|
34
|
+
* - `iframe`:沙箱档,第三方插件的缺省与唯一选择;
|
|
35
|
+
* - `same-origin`:同源档,只允许官方签名包;第三方包声明它会在安装检查时被阻断
|
|
36
|
+
* (blocked_reason = third_party_same_origin_mount)。
|
|
37
|
+
*/
|
|
38
|
+
export type SurfaceMount = 'iframe' | 'same-origin';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 本阶段支持沙箱档的 surface(与宿主 plugin.IframeMountSupported 同口径):page-slot 的 template.records / auth.login、
|
|
42
|
+
* action-config、print-mode(打印方案 B 档隐藏框架),1.1.0-tp.5 起的 im-panel(IM 浮窗)与 action-designer(动作设计器),
|
|
43
|
+
* 以及 1.1.0-tp.14 起的编辑器 designer / runtime(入口见 './editor-frame' 的 defineEditorSurface,需支持编辑器解耦的宿主)。
|
|
44
|
+
* 流程设计器(workflow-designer)尚不支持。
|
|
45
|
+
*/
|
|
46
|
+
export function isIframeMountSupported(surfaceType: string, slot?: string): boolean {
|
|
47
|
+
if (
|
|
48
|
+
surfaceType === 'action-config' ||
|
|
49
|
+
surfaceType === 'im-panel' ||
|
|
50
|
+
surfaceType === 'action-designer' ||
|
|
51
|
+
// 打印方案 B 档的隐藏框架(与 Go plugin.IframeMountSupported、宿主同口径)。
|
|
52
|
+
surfaceType === 'print-mode' ||
|
|
53
|
+
surfaceType === 'designer' ||
|
|
54
|
+
surfaceType === 'runtime'
|
|
55
|
+
) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return surfaceType === 'page-slot' && (slot === 'template.records' || slot === 'auth.login');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 插件自检:第三方包的 surfaces 不得声明 same-origin,且沙箱档只能用于已支持的 surface。
|
|
63
|
+
* 返回错误说明列表(空数组即通过);宿主安装检查是权威实现。
|
|
64
|
+
*/
|
|
65
|
+
export function validateSurfaceMounts(
|
|
66
|
+
surfaces: ReadonlyArray<{ type?: string; slot?: string; mount?: string }>,
|
|
67
|
+
options: { official?: boolean } = {}
|
|
68
|
+
): string[] {
|
|
69
|
+
const errors: string[] = [];
|
|
70
|
+
surfaces.forEach((surface, i) => {
|
|
71
|
+
const mount = surface.mount ?? '';
|
|
72
|
+
if (mount !== '' && mount !== 'iframe' && mount !== 'same-origin') {
|
|
73
|
+
errors.push(`surfaces[${i}].mount "${mount}" must be "iframe" or "same-origin"`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const effective = options.official ? (mount === 'iframe' ? 'iframe' : 'same-origin') : 'iframe';
|
|
77
|
+
if (!options.official && mount === 'same-origin') {
|
|
78
|
+
errors.push(`surfaces[${i}]: third-party packages must not declare mount "same-origin" (inspect blocks it)`);
|
|
79
|
+
}
|
|
80
|
+
if (effective === 'iframe' && !isIframeMountSupported(String(surface.type ?? ''), surface.slot)) {
|
|
81
|
+
errors.push(`surfaces[${i}]: surface "${surface.type ?? ''}${surface.slot ? `:${surface.slot}` : ''}" is not supported in the iframe mount yet`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return errors;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ── 前端域自检(frontend.surface 加载期校验)──
|
|
88
|
+
//
|
|
89
|
+
// 三道闸同表同码的第三道:沙箱框架里宿主在 init 时随 input 下发宿主前端域代际表(hostSchemaGenerations),
|
|
90
|
+
// definePluginSurface 在调用插件工厂前比对「本 SDK 构建对齐的代际」,不满足即抛错,由框架运行时回 mount-error
|
|
91
|
+
// (复用沙箱框架已有的 mount-error 消息类型)。需求表与宿主安装闸、宿主前端加载闸同口径,改一处须同步三处。
|
|
92
|
+
|
|
93
|
+
/** 本 SDK 对齐的 frontend.surface 代际。 */
|
|
94
|
+
export const FRONTEND_SURFACE_GENERATION = 1;
|
|
95
|
+
/** 本 SDK 对齐的 frontend.interactive-session 代际。 */
|
|
96
|
+
export const FRONTEND_INTERACTIVE_SESSION_GENERATION = 1;
|
|
97
|
+
|
|
98
|
+
/** 加载期错误码(与宿主同名)。 */
|
|
99
|
+
export const SURFACE_DOMAIN_MISSING = 'plugin_surface_domain_missing';
|
|
100
|
+
export const SURFACE_DOMAIN_TOO_NEW = 'plugin_surface_domain_too_new';
|
|
101
|
+
export const SURFACE_DOMAIN_TOO_OLD = 'plugin_surface_domain_too_old';
|
|
102
|
+
|
|
103
|
+
/** 宿主下发的单个域代际(线上形态,与宿主活跃插件元数据 host_schema_generations 一致)。 */
|
|
104
|
+
export interface HostSchemaGenerationWire {
|
|
105
|
+
current: number;
|
|
106
|
+
min_supported: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** 会话型 surface(另需 frontend.interactive-session)。 */
|
|
110
|
+
const INTERACTIVE_SESSION_SURFACE_TYPES = new Set(['designer', 'runtime', 'action-designer', 'action-config', 'workflow-designer']);
|
|
111
|
+
|
|
112
|
+
/** 某 surface 类型必需的前端域及本 SDK 对齐的代际。 */
|
|
113
|
+
export function requiredSurfaceDomainGenerations(surfaceType: string): Record<string, number> {
|
|
114
|
+
const out: Record<string, number> = { 'frontend.surface': FRONTEND_SURFACE_GENERATION };
|
|
115
|
+
if (INTERACTIVE_SESSION_SURFACE_TYPES.has(surfaceType)) {
|
|
116
|
+
out['frontend.interactive-session'] = FRONTEND_INTERACTIVE_SESSION_GENERATION;
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 域自检失败(code 为上面三个错误码之一)。 */
|
|
122
|
+
export class SurfaceDomainCheckError extends Error {
|
|
123
|
+
code: string;
|
|
124
|
+
constructor(code: string, message: string) {
|
|
125
|
+
super(`${code}: ${message}`);
|
|
126
|
+
this.name = 'SurfaceDomainCheckError';
|
|
127
|
+
this.code = code;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 比对宿主下发的代际表:返回 null 表示通过,否则返回错误。
|
|
133
|
+
* 宿主未下发代际表(undefined,不支持前端域闸的旧宿主)时不判定——这类宿主自身也不做域闸,SDK 无从比对。
|
|
134
|
+
*/
|
|
135
|
+
export function checkHostSurfaceGenerations(
|
|
136
|
+
surfaceType: string,
|
|
137
|
+
hostGenerations: Record<string, HostSchemaGenerationWire> | undefined,
|
|
138
|
+
/** 本 SDK 对齐的代际(缺省按需求表;测试注入点)。 */
|
|
139
|
+
sdkGenerations: Record<string, number> = requiredSurfaceDomainGenerations(surfaceType)
|
|
140
|
+
): SurfaceDomainCheckError | null {
|
|
141
|
+
if (hostGenerations === undefined) return null;
|
|
142
|
+
for (const [domain, sdkGeneration] of Object.entries(sdkGenerations)) {
|
|
143
|
+
const host = hostGenerations?.[domain];
|
|
144
|
+
const current = Number(host?.current);
|
|
145
|
+
if (!host || !Number.isInteger(current) || current < 1) {
|
|
146
|
+
return new SurfaceDomainCheckError(SURFACE_DOMAIN_MISSING, `host does not provide ${domain} (surface=${surfaceType})`);
|
|
147
|
+
}
|
|
148
|
+
if (sdkGeneration > current) {
|
|
149
|
+
return new SurfaceDomainCheckError(
|
|
150
|
+
SURFACE_DOMAIN_TOO_NEW,
|
|
151
|
+
`${domain} sdk=${sdkGeneration} host_current=${current} (surface=${surfaceType}); upgrade the host`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
const minSupported = Number(host.min_supported);
|
|
155
|
+
if (Number.isInteger(minSupported) && minSupported > 0 && sdkGeneration < minSupported) {
|
|
156
|
+
return new SurfaceDomainCheckError(
|
|
157
|
+
SURFACE_DOMAIN_TOO_OLD,
|
|
158
|
+
`${domain} sdk=${sdkGeneration} host_min_supported=${minSupported} (surface=${surfaceType}); rebuild with a newer SDK`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 按数据动作种类回落的 action-config 绑定前缀(`bind: "operation_kind:<kind>"`)。
|
|
167
|
+
* 动作设计器先找 `bind == 动作名` 的面板,找不到且动作带 `operation_kind` 时再找本前缀的面板。
|
|
168
|
+
* **只对官方保留命名空间插件生效**(官方标准取数 / 写配置面板据此服务所有同种类动作),第三方声明时宿主忽略、
|
|
169
|
+
* manifest 预检告警;第三方数据动作不需要也不能自带取数 / 写配置面板。
|
|
170
|
+
*/
|
|
171
|
+
export const OPERATION_KIND_BIND_PREFIX = 'operation_kind:';
|
|
172
|
+
|
|
173
|
+
/** 宿主调用 createSurface 时传入的上下文。 */
|
|
174
|
+
export interface SurfaceCreateInput {
|
|
175
|
+
/** 本次挂载的 surface 类型。 */
|
|
176
|
+
surfaceType: SurfaceType;
|
|
177
|
+
/** action-config 类 surface 的绑定标识:动作名,或官方面板的 `operation_kind:<kind>`(见 OPERATION_KIND_BIND_PREFIX)。 */
|
|
178
|
+
bind?: string;
|
|
179
|
+
/** 多槽 surface 的槽标识。 */
|
|
180
|
+
slot?: string;
|
|
181
|
+
/**
|
|
182
|
+
* 宿主按白名单裁剪后注入的宿主能力键列表(surface manifest 声明的 host_caps 与宿主白名单取交集)。
|
|
183
|
+
* 插件仅能使用此列表内的能力,宿主不保证列表外的键存在于 hostBridge 上。
|
|
184
|
+
*/
|
|
185
|
+
hostCaps: string[];
|
|
186
|
+
/** 宿主透传的上下文(DesignerHostContext 等,插件端按实际类型断言)。 */
|
|
187
|
+
hostContext: unknown;
|
|
188
|
+
/** 宿主运行时实例上下文(仅 editor 类 surface 有效)。 */
|
|
189
|
+
runtime: unknown;
|
|
190
|
+
/** 宿主建议的初始 props(不含插件自行计算的 props)。 */
|
|
191
|
+
props: Record<string, unknown>;
|
|
192
|
+
/**
|
|
193
|
+
* 宿主桥接对象(与 EditorHostBridge 同结构,但类型为 unknown 避免反向依赖)。
|
|
194
|
+
* 其上的 `theme`(宿主设计数值)常驻可见:不需要在 hostCaps 声明,
|
|
195
|
+
* 读取请用 `readHostTheme(hostBridge)`(from './theme'),老宿主缺失时得 null。
|
|
196
|
+
*/
|
|
197
|
+
hostBridge: unknown;
|
|
198
|
+
/**
|
|
199
|
+
* 宿主前端域代际表(沙箱档由宿主在 init 时下发;同源档宿主可不传)。
|
|
200
|
+
* definePluginSurface 在框架里据此自检,插件一般无需读取。
|
|
201
|
+
*/
|
|
202
|
+
hostSchemaGenerations?: Record<string, HostSchemaGenerationWire>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** createSurface 工厂的返回值,宿主据此挂载 Vue 组件。 */
|
|
206
|
+
export interface SurfaceMountResult {
|
|
207
|
+
/** 要渲染的 Vue 组件(宿主通过 markRaw + <component :is> 挂载)。 */
|
|
208
|
+
component: unknown;
|
|
209
|
+
/** 额外的 props 覆盖(合并在 input.props 之后)。 */
|
|
210
|
+
props?: Record<string, unknown>;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 给挂载工厂包一层前端域自检(definePluginSurface 在沙箱框架里自动使用;不走 definePluginSurface 的 bundle 可手动包)。
|
|
215
|
+
* 自检不通过时抛 SurfaceDomainCheckError,由框架运行时转成 mount-error。
|
|
216
|
+
*/
|
|
217
|
+
export function withSurfaceDomainCheck<T extends SurfaceCreateInput>(
|
|
218
|
+
factory: (input: T) => SurfaceMountResult
|
|
219
|
+
): (input: T) => SurfaceMountResult {
|
|
220
|
+
return (input: T): SurfaceMountResult => {
|
|
221
|
+
const error = checkHostSurfaceGenerations(String(input?.surfaceType ?? ''), input?.hostSchemaGenerations);
|
|
222
|
+
if (error) throw error;
|
|
223
|
+
return factory(input);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* definePluginSurface —— 声明挂载工厂,给插件作者提供类型推导。
|
|
229
|
+
* 同源档里是 identity;在宿主沙箱框架里还会登记工厂并启动框架运行时,
|
|
230
|
+
* 插件作者无需感知两种挂载档的差异(见 frame-transport.ts 顶部说明)。
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* export const createSurface = definePluginSurface((input) => {
|
|
235
|
+
* return { component: MyConfigPanel, props: { bind: input.bind } };
|
|
236
|
+
* });
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export function definePluginSurface<T extends SurfaceCreateInput>(
|
|
240
|
+
factory: (input: T) => SurfaceMountResult
|
|
241
|
+
): (input: T) => SurfaceMountResult {
|
|
242
|
+
if (isKimpoFrameContext()) {
|
|
243
|
+
// 沙箱框架里先做前端域自检:不满足即抛错,框架运行时据此回 mount-error,插件工厂不会被调用。
|
|
244
|
+
const guarded = withSurfaceDomainCheck(factory);
|
|
245
|
+
registerFrameSurfaceFactory(guarded as unknown as (input: SurfaceCreateInput) => SurfaceMountResult);
|
|
246
|
+
return guarded;
|
|
247
|
+
}
|
|
248
|
+
return factory;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* 动作配置面板(surfaceType='action-config')的通用参数契约。
|
|
253
|
+
*
|
|
254
|
+
* 宿主动作设计器在用户编辑一个**非取数/写动作**的节点时,若该动作名有插件声明的 action-config
|
|
255
|
+
* surface(`bind` = 动作名),挂载组件并以组件 prop `input` 传入 `ActionConfigSurfaceInput`:
|
|
256
|
+
* - `input.props.params`:当前节点的动作参数对象(副本);
|
|
257
|
+
* - `input.props.onUpdateParams(next)`:整体回写参数(宿主随后按动作的 params_schema 与插件
|
|
258
|
+
* ValidateParams 在保存时校验,面板不必自己保存);
|
|
259
|
+
* - `input.props.readonly`:只读打开时为 true,面板应禁用编辑;
|
|
260
|
+
* - `input.props.paramsSchema`:动作在 GetActions 中声明的参数 schema,便于面板渲染默认值。
|
|
261
|
+
*
|
|
262
|
+
* 取数 / 写动作(params_schema 顶层 `x-editor` 为 `extract-v4` / `write-v4`)走宿主内置的表达式
|
|
263
|
+
* 配置面,props 为另一套 V4 表达式模型(modelValue / onUpdateModel),不在本契约范围。
|
|
264
|
+
*/
|
|
265
|
+
export interface ActionConfigSurfaceProps {
|
|
266
|
+
params: Record<string, unknown>;
|
|
267
|
+
onUpdateParams(next: Record<string, unknown>): void;
|
|
268
|
+
readonly: boolean;
|
|
269
|
+
paramsSchema?: Record<string, unknown>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** action-config 面板组件收到的 `input` prop。 */
|
|
273
|
+
export interface ActionConfigSurfaceInput {
|
|
274
|
+
surfaceType: 'action-config';
|
|
275
|
+
/** 绑定的动作名(与 GetActions 中的动作 name 一致)。 */
|
|
276
|
+
bind?: string;
|
|
277
|
+
hostContext: { appId: string; templateId: string; actionName: string };
|
|
278
|
+
props: ActionConfigSurfaceProps;
|
|
279
|
+
/** 按 manifest host_caps 裁剪后的宿主桥(含 log / i18n 等)。 */
|
|
280
|
+
hostBridge: Record<string, unknown>;
|
|
281
|
+
}
|