@kimposoft/plugin-sdk 1.1.0-tp.20 → 1.1.0-tp.22
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/README.md +3 -3
- package/package.json +5 -1
- package/src/action-designer.ts +19 -2
- package/src/attachment-open.ts +574 -0
- package/src/attachment-url.ts +48 -8
- package/src/display-style.ts +287 -5
- package/src/editor-frame.ts +3 -1
- package/src/editor.ts +80 -1
- package/src/frame-transport.ts +30 -5
- package/src/index.ts +7 -0
- package/src/page.ts +188 -1
- package/src/surface.ts +32 -3
- package/src/ui-fixtures/attachment.ts +24 -0
- package/src/ui-fixtures/index.ts +1 -0
- package/src/ui-mocks.ts +16 -2
- package/src/ui.ts +14 -2
- package/src/workflow-designer.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -30,11 +30,18 @@ export * from './i18n';
|
|
|
30
30
|
export * from './page';
|
|
31
31
|
// 字段展示样式格式化纯函数:formatDisplayStyleValue / isDateTimeDisplayStyle /
|
|
32
32
|
// isNumericDisplayStyle,口径逐档对齐表格编辑器填报态单元格,供记录列表等其他消费方复用。
|
|
33
|
+
// 同文件还导出日期时间「自定义」展示样式(440)格式串函数:CUSTOM_DATETIME_DISPLAY_STYLE /
|
|
34
|
+
// renderDatetimePattern / validateDatetimePattern / datetimePatternGrain / datetimePatternToExcelNumFmt /
|
|
35
|
+
// readDatetimePattern 等,消费方从字段 format_rule_json 读格式串后传给 formatDisplayStyleValue。
|
|
33
36
|
export * from './display-style';
|
|
34
37
|
// 附件值 → 地址纯函数:parseAttachmentItems / attachmentItemUrls / attachmentItemsSummary /
|
|
35
38
|
// isImageItem / isAttachmentField / isImageField / isImageDisplayStyle,表格编辑器候选、历史记录页、宿主内置
|
|
36
39
|
// 回退视图与视图设计器预览共用,各处不得自行拼接宿主图片 / 附件端点;地址自动携带查询上下文读票据(qt)。
|
|
37
40
|
export * from './attachment-url';
|
|
41
|
+
// 附件插件(surface attachment.open)前端契约:AttachmentOpenDecl / AttachmentOpenContext / AttachmentEditSession /
|
|
42
|
+
// OpenAttachmentRequest / defineAttachmentOpenSurface / matchesAttachmentOpenAccepts。宿主附件外壳按 manifest
|
|
43
|
+
// capabilities.attachment_open 路由并挂载;调用方统一经 ui.openAttachment 打开附件,不再自带查看器。
|
|
44
|
+
export * from './attachment-open';
|
|
38
45
|
// 登录页插件(auth.login slot)前端契约:AuthKind / LoginMethod / LoginPageProps / LoginOutcome /
|
|
39
46
|
// AuthErrorCode / AuthLoginHostBridge / definePluginLoginSurface / QrCodeRenderer,
|
|
40
47
|
// 使用说明见 SDK 第三方指南 docs/third-party/auth-and-hooks.md。
|
package/src/page.ts
CHANGED
|
@@ -74,6 +74,8 @@ export interface PageDataTableInfo {
|
|
|
74
74
|
/** 后端权威角色:'main'=主表,其余(如 'extension')=明细/扩展表;勿靠 sort_no 猜。 */
|
|
75
75
|
table_role?: string;
|
|
76
76
|
extension_mode?: string;
|
|
77
|
+
/** 扩展表设为「历史记录中隐藏」时为 true;缺省 / false = 显示,主表恒不下发。 */
|
|
78
|
+
history_hidden?: boolean;
|
|
77
79
|
sort_no: number;
|
|
78
80
|
field_count: number;
|
|
79
81
|
version_no: number;
|
|
@@ -98,6 +100,10 @@ export interface PageFieldInfo {
|
|
|
98
100
|
is_list_visible?: boolean;
|
|
99
101
|
format_rule_json?: Record<string, unknown> | string | null;
|
|
100
102
|
option_source_json?: Record<string, unknown> | string | null;
|
|
103
|
+
/** 字段是否唯一(宿主下发;老宿主缺席按 false)。导入「判定字段」默认取主表的唯一字段。 */
|
|
104
|
+
is_unique?: boolean;
|
|
105
|
+
/** 字段是否必填(宿主下发;老宿主缺席按 false)。 */
|
|
106
|
+
is_required?: boolean;
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
/** 记录列表排序项(对照宿主 RuntimeRecordSort 类型)。 */
|
|
@@ -169,7 +175,73 @@ export interface PageRecordListPayload {
|
|
|
169
175
|
offset: number;
|
|
170
176
|
}
|
|
171
177
|
|
|
172
|
-
export type PageRecordExportPayload = Omit<PageRecordListPayload, 'limit' | 'offset'
|
|
178
|
+
export type PageRecordExportPayload = Omit<PageRecordListPayload, 'limit' | 'offset'> & {
|
|
179
|
+
/** 只导这些主记录(与筛选、数据范围求交);缺省按筛选导出全部。老宿主忽略。 */
|
|
180
|
+
record_ids?: string[];
|
|
181
|
+
/**
|
|
182
|
+
* 工作簿版式:主表首列「记录编号」、extension_table_ids 中的扩展表各占一张工作表、另带隐藏表记录列身份,
|
|
183
|
+
* 导出文件可改后经 startImport 直接导回。缺省为单表版式。老宿主忽略(仍出单表)。
|
|
184
|
+
*/
|
|
185
|
+
workbook?: boolean;
|
|
186
|
+
/** 工作簿版式下一并导出的扩展表。 */
|
|
187
|
+
extension_table_ids?: string[];
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/** 导出数据转后台任务的主表单据数阈值:超过即应改走 createDataExportTask。 */
|
|
191
|
+
export const PAGE_RECORD_DATA_EXPORT_ASYNC_THRESHOLD = 1000;
|
|
192
|
+
|
|
193
|
+
/** 导入选项:重复数据三档(不检查 / 跳过 / 覆盖已有单据)+ 判定字段 + 出错处理。 */
|
|
194
|
+
export interface PageRecordImportOptions {
|
|
195
|
+
duplicate_mode: 'none' | 'skip' | 'overwrite';
|
|
196
|
+
/** 判定字段:主表字段 ID,或 'record_id'(记录编号);duplicate_mode 为 skip/overwrite 时必填。 */
|
|
197
|
+
key_field_ids?: string[];
|
|
198
|
+
/** rollback_all 整批回滚 / skip_failed 跳过出错单据。 */
|
|
199
|
+
error_mode: 'rollback_all' | 'skip_failed';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** 导入问题(预检或写入时发现);message 已按用户语言翻译。 */
|
|
203
|
+
export interface PageRecordImportIssue {
|
|
204
|
+
sheet: string;
|
|
205
|
+
row: number;
|
|
206
|
+
ref?: string;
|
|
207
|
+
column?: string;
|
|
208
|
+
code: string;
|
|
209
|
+
message: string;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** 导入作业(getImportJob 轮询返回)。status:prechecking → ready → executing → done;failed 为整作业失败。 */
|
|
213
|
+
export interface PageRecordImportJob {
|
|
214
|
+
job_id: string;
|
|
215
|
+
status: 'prechecking' | 'ready' | 'executing' | 'done' | 'failed';
|
|
216
|
+
/** 当前阶段:read 读取文件 / validate 校验 / write 写入单据 / index 更新索引。 */
|
|
217
|
+
stage: 'read' | 'validate' | 'write' | 'index';
|
|
218
|
+
/** 当前阶段已处理 / 总数(按主表单据计),用于真实进度条。 */
|
|
219
|
+
processed: number;
|
|
220
|
+
total: number;
|
|
221
|
+
options: PageRecordImportOptions;
|
|
222
|
+
summary: {
|
|
223
|
+
main_records: number;
|
|
224
|
+
to_create: number;
|
|
225
|
+
to_overwrite: number;
|
|
226
|
+
duplicates_skipped: number;
|
|
227
|
+
error_records: number;
|
|
228
|
+
issue_count: number;
|
|
229
|
+
extension_rows: Array<{ data_table_id: string; table_name: string; rows: number }> | null;
|
|
230
|
+
created: number;
|
|
231
|
+
overwritten: number;
|
|
232
|
+
failed: number;
|
|
233
|
+
extension_written: number;
|
|
234
|
+
rolled_back: boolean;
|
|
235
|
+
};
|
|
236
|
+
/** 前 500 条问题(全部问题在错误报告里)。 */
|
|
237
|
+
issues: PageRecordImportIssue[] | null;
|
|
238
|
+
ignored_columns: Array<{ sheet: string; column: string; code: string; message: string }> | null;
|
|
239
|
+
error_message?: string;
|
|
240
|
+
file_name?: string;
|
|
241
|
+
created_at: string;
|
|
242
|
+
started_at?: string;
|
|
243
|
+
finished_at?: string;
|
|
244
|
+
}
|
|
173
245
|
|
|
174
246
|
/** 单条运行态记录(对照宿主 RuntimeRecord 类型)。 */
|
|
175
247
|
export interface PageRuntimeRecord {
|
|
@@ -187,6 +259,51 @@ export interface PageRuntimeRecord {
|
|
|
187
259
|
* 「已知未锁定」以外的任何含义(例如误判为加载失败)。
|
|
188
260
|
*/
|
|
189
261
|
lock?: PageRecordLockState;
|
|
262
|
+
/**
|
|
263
|
+
* 保存后动作链最近一次运行的未完成 / 异常状态:只有该记录最新一次运行不是成功时
|
|
264
|
+
* 才下发;从未运行、最新一次已成功、回收站 / 非主表列表、老宿主均缺席——缺席即「无需提示」。
|
|
265
|
+
*/
|
|
266
|
+
action_run?: PageRecordActionRun;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 保存后动作链运行状态码(对照宿主 action_chain_run.status_code;succeeded 不下发)。
|
|
271
|
+
* foreground=前台执行中;background=后台执行中;failed/canceled/timed_out/rolled_back 为终态异常。
|
|
272
|
+
* 宿主后续可能新增状态码,插件对未知值应按中性样式展示原文,不得报错。
|
|
273
|
+
*/
|
|
274
|
+
export type PageRecordActionRunStatus =
|
|
275
|
+
| 'foreground'
|
|
276
|
+
| 'background'
|
|
277
|
+
| 'failed'
|
|
278
|
+
| 'canceled'
|
|
279
|
+
| 'timed_out'
|
|
280
|
+
| 'rolled_back'
|
|
281
|
+
| (string & {});
|
|
282
|
+
|
|
283
|
+
/** 记录列表上的保存后动作链运行状态(对照宿主 RuntimeRecordActionRun)。 */
|
|
284
|
+
export interface PageRecordActionRun {
|
|
285
|
+
status: PageRecordActionRunStatus;
|
|
286
|
+
/** 触发该动作链的事件键(如保存后事件)。 */
|
|
287
|
+
event_key: string;
|
|
288
|
+
error_code?: string;
|
|
289
|
+
/** 失败原因原文,供悬浮提示展示。 */
|
|
290
|
+
error_message?: string;
|
|
291
|
+
failed_node_id?: string;
|
|
292
|
+
/** 开始时间,RFC3339 UTC;展示时按宿主时间格式化换算到用户时区。 */
|
|
293
|
+
started_at: string;
|
|
294
|
+
/** 结束时间,RFC3339 UTC;仍在执行中时缺席。 */
|
|
295
|
+
finished_at?: string;
|
|
296
|
+
/**
|
|
297
|
+
* 动作链事务模式:global=整链一个事务(失败已整体回滚,重试天然可重复);
|
|
298
|
+
* individual=逐节点各自提交(失败前的节点已落库,重试会从头再执行所有动作)。
|
|
299
|
+
* 老宿主不下发该字段,缺席时插件应按 individual 处理(宁可多问一次确认)。
|
|
300
|
+
*/
|
|
301
|
+
transaction_mode?: 'global' | 'individual';
|
|
302
|
+
/**
|
|
303
|
+
* 本次运行是由哪次运行重试而来:被重试的那次运行的 mutation_id;
|
|
304
|
+
* 首次运行或老宿主缺席。仅用于展示溯源,不可作为重试入参。
|
|
305
|
+
*/
|
|
306
|
+
retry_of_mutation_id?: string;
|
|
190
307
|
}
|
|
191
308
|
|
|
192
309
|
/** 记录列表查询结果(对照宿主 RuntimeRecordListResult 类型)。 */
|
|
@@ -262,6 +379,30 @@ export interface PagePluginConfigSnapshot {
|
|
|
262
379
|
updated_by_name: string;
|
|
263
380
|
/** RFC3339 UTC 字符串;从未保存为 null。 */
|
|
264
381
|
updated_at: string | null;
|
|
382
|
+
/**
|
|
383
|
+
* 当前用户能否保存个人配置(没有应用设计权限的用户为 true)。老宿主不带此项,按 false 处理。
|
|
384
|
+
* 仅用于 UI,不是安全边界(后端另判)。
|
|
385
|
+
*/
|
|
386
|
+
can_personalize?: boolean;
|
|
387
|
+
/** 当前用户的个人配置;没有、不能个人化或老宿主时为 null / 缺省。上面的 config 是管理员默认。 */
|
|
388
|
+
personal?: PagePluginPersonalConfig | null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 当前用户在本模板下的个人配置(宿主不解读;如何覆盖管理员默认由插件决定)。
|
|
393
|
+
* version 是个人配置自己的乐观并发版本号,与默认配置的 version 无关。
|
|
394
|
+
*/
|
|
395
|
+
export interface PagePluginPersonalConfig {
|
|
396
|
+
config: unknown;
|
|
397
|
+
version: number;
|
|
398
|
+
/** RFC3339 UTC 字符串。 */
|
|
399
|
+
updated_at: string | null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** 个人配置保存结果。 */
|
|
403
|
+
export interface PagePluginPersonalSaveResult {
|
|
404
|
+
version: number;
|
|
405
|
+
updated_at: string | null;
|
|
265
406
|
}
|
|
266
407
|
|
|
267
408
|
/** 保存结果:新版本号与最近更新人信息。 */
|
|
@@ -280,10 +421,18 @@ export interface PageHostError extends Error {
|
|
|
280
421
|
* 插件模板级配置客户端(hostBridge['plugin-config'])。
|
|
281
422
|
* 配置按「当前模板 + 当前挂载插件」存取,插件标识由宿主桥填入,插件不传。
|
|
282
423
|
* 配置体上限 64 KB;保存时 version 传读到的版本(首次保存传 0),冲突抛 PLUGIN_CONFIG_VERSION_CONFLICT。
|
|
424
|
+
*
|
|
425
|
+
* 两层配置:save 写管理员默认(需应用设计权限,每模板一份);没有应用设计权限的用户可用
|
|
426
|
+
* savePersonal / deletePersonal 维护自己的个人配置(每人每模板一份)。个人配置方法在老宿主上缺省,
|
|
427
|
+
* 调用前先判断是否存在。有应用设计权限的人调用 savePersonal 抛 PLUGIN_CONFIG_PERSONAL_NOT_ALLOWED。
|
|
283
428
|
*/
|
|
284
429
|
export interface PagePluginConfigClient {
|
|
285
430
|
get(): Promise<PagePluginConfigSnapshot>;
|
|
286
431
|
save(config: unknown, version: number): Promise<PagePluginConfigSaveResult>;
|
|
432
|
+
/** 保存当前用户的个人配置;version 传读到的 personal.version(没有个人配置传 0)。 */
|
|
433
|
+
savePersonal?(config: unknown, version: number): Promise<PagePluginPersonalSaveResult>;
|
|
434
|
+
/** 删除当前用户的个人配置(恢复默认);幂等。 */
|
|
435
|
+
deletePersonal?(): Promise<void>;
|
|
287
436
|
}
|
|
288
437
|
|
|
289
438
|
/**
|
|
@@ -331,6 +480,40 @@ export interface PageRecordListClient {
|
|
|
331
480
|
recordIds: string[],
|
|
332
481
|
locked: boolean
|
|
333
482
|
): Promise<{ locked: boolean; changedRecordIds: string[]; unchangedRecordIds: string[] }>;
|
|
483
|
+
/**
|
|
484
|
+
* 重新执行某条记录最近一次未成功的保存后动作链(「重试」)。可选方法:老宿主未实现时
|
|
485
|
+
* 缺席,插件应静默隐藏重试入口(不报错、不 polyfill)。
|
|
486
|
+
* 仅对 action_run 处于终态异常(failed / canceled / timed_out / rolled_back)的记录可用;
|
|
487
|
+
* 执行中(foreground / background)或无 action_run 的记录宿主会拒绝。
|
|
488
|
+
* 宿主以新的 mutation_id 重新派发,返回新运行的 mutation_id 与受理时的状态码:链在宿主前台等待窗口内跑完时
|
|
489
|
+
* status 为新运行终态(succeeded / failed / timed_out / canceled / rolled_back);超窗时为 'running'——链已转
|
|
490
|
+
* 宿主服务端继续执行,终态经宿主通知送达(插件宜提示「已开始执行」并刷新列表)。
|
|
491
|
+
* 失败按宿主标准错误信封抛出(错误对象带原因文本)。
|
|
492
|
+
*/
|
|
493
|
+
retryActionRun?(recordId: string): Promise<{ mutation_id: string; status: string }>;
|
|
494
|
+
/**
|
|
495
|
+
* 导出数据(后台任务)。可选方法:老宿主未实现时缺席。主表单据超过
|
|
496
|
+
* PAGE_RECORD_DATA_EXPORT_ASYNC_THRESHOLD 时调用,入参同 exportRecords 的工作簿版式;完成后宿主发站内通知,
|
|
497
|
+
* 文件在下载中心。宿主按「查看 + 导出」操作位与数据范围裁决。
|
|
498
|
+
*/
|
|
499
|
+
createDataExportTask?(dataTableId: string, payload: PageRecordExportPayload): Promise<{ taskId: string; totalCount: number }>;
|
|
500
|
+
/**
|
|
501
|
+
* 以下为历史记录导入(均为可选方法,老宿主未实现时缺席,插件应隐藏导入入口)。导入按「新建」操作位裁决,
|
|
502
|
+
* 覆盖已有单据另需「修改」操作位且单据在修改范围内(宿主逐张核对并在预检里报出)。写入不经编辑器,
|
|
503
|
+
* 经宿主表单数据权威层的写前围栏判定;不触发保存后动作、通知与流程。
|
|
504
|
+
*/
|
|
505
|
+
/** 下载空白导入模板(主表 + 所选扩展表);下载动作由宿主执行。 */
|
|
506
|
+
downloadImportTemplate?(dataTableId: string, extensionTableIds: string[]): Promise<void>;
|
|
507
|
+
/** 上传文件建导入作业并开始预检(预检不写库),返回作业,之后用 getImportJob 轮询。 */
|
|
508
|
+
startImport?(dataTableId: string, file: File, options: PageRecordImportOptions): Promise<PageRecordImportJob>;
|
|
509
|
+
/** 查询导入作业。 */
|
|
510
|
+
getImportJob?(jobId: string): Promise<PageRecordImportJob>;
|
|
511
|
+
/** 预检完成后开始写入(整批回滚且预检有问题时宿主拒绝)。 */
|
|
512
|
+
executeImport?(jobId: string): Promise<PageRecordImportJob>;
|
|
513
|
+
/** 下载错误报告(原行 + 错误原因列)。 */
|
|
514
|
+
downloadImportReport?(jobId: string): Promise<void>;
|
|
515
|
+
/** 丢弃未写入的作业。 */
|
|
516
|
+
cancelImport?(jobId: string): Promise<void>;
|
|
334
517
|
}
|
|
335
518
|
|
|
336
519
|
/**
|
|
@@ -354,6 +537,10 @@ export interface PageTemplatePermissionSummary {
|
|
|
354
537
|
export: boolean;
|
|
355
538
|
print: boolean;
|
|
356
539
|
exportPdf: boolean;
|
|
540
|
+
// 单据导出 Excel 独立授权位(导出拆三项:export=导出表数据、exportXlsx=单据导出 Excel、
|
|
541
|
+
// exportPdf=单据导出 PDF)。可选:旧宿主未注入该字段时,插件应回落到 `export` 判定
|
|
542
|
+
// (即 `exportXlsx ?? export`),保持与拆分前一致的行为。
|
|
543
|
+
exportXlsx?: boolean;
|
|
357
544
|
// 单据锁定与解锁独立授权位。可选:兼容尚未升级到本版本 SDK 的旧宿主
|
|
358
545
|
// (未注入该字段时插件应视为未知/不可用,不擅自猜测为 true)。
|
|
359
546
|
lock?: boolean;
|
package/src/surface.ts
CHANGED
|
@@ -27,7 +27,10 @@ export type SurfaceType =
|
|
|
27
27
|
| 'action-designer'
|
|
28
28
|
// KimpoAI 产品对话面悬浮窗容器:宿主经 resolvePluginSurfaces 按 priority 最高单提供者
|
|
29
29
|
// 命中并挂在页面根级,窗口显隐由宿主单例控制(同 im-panel 范式)。
|
|
30
|
-
| 'kimpoai-panel'
|
|
30
|
+
| 'kimpoai-panel'
|
|
31
|
+
// 附件插件(1.1.0-tp.21 起):宿主附件外壳按 manifest capabilities.attachment_open.accepts 路由并挂载,
|
|
32
|
+
// 组件以 prop `ctx: AttachmentOpenContext` 收上下文(契约见 attachment-open.ts)。1.1.0-tp.22 起沙箱档也支持。
|
|
33
|
+
| 'attachment.open';
|
|
31
34
|
|
|
32
35
|
/**
|
|
33
36
|
* surface 挂载档(manifest capabilities.frontend.surfaces[].mount)。
|
|
@@ -40,7 +43,8 @@ export type SurfaceMount = 'iframe' | 'same-origin';
|
|
|
40
43
|
/**
|
|
41
44
|
* 本阶段支持沙箱档的 surface(与宿主 plugin.IframeMountSupported 同口径):page-slot 的 template.records / auth.login、
|
|
42
45
|
* action-config、print-mode(打印方案 B 档隐藏框架),1.1.0-tp.5 起的 im-panel(IM 浮窗)与 action-designer(动作设计器),
|
|
43
|
-
*
|
|
46
|
+
* 1.1.0-tp.14 起的编辑器 designer / runtime(入口见 './editor-frame' 的 defineEditorSurface,需支持编辑器解耦的宿主),
|
|
47
|
+
* 以及 1.1.0-tp.22 起的附件插件 attachment.open(跨帧桥见 './attachment-open',需同阶段宿主)。
|
|
44
48
|
* 流程设计器(workflow-designer)尚不支持。
|
|
45
49
|
*/
|
|
46
50
|
export function isIframeMountSupported(surfaceType: string, slot?: string): boolean {
|
|
@@ -51,7 +55,9 @@ export function isIframeMountSupported(surfaceType: string, slot?: string): bool
|
|
|
51
55
|
// 打印方案 B 档的隐藏框架(与 Go plugin.IframeMountSupported、宿主同口径)。
|
|
52
56
|
surfaceType === 'print-mode' ||
|
|
53
57
|
surfaceType === 'designer' ||
|
|
54
|
-
surfaceType === 'runtime'
|
|
58
|
+
surfaceType === 'runtime' ||
|
|
59
|
+
// 附件插件:宿主附件外壳在沙箱档经跨帧桥下发 ctx。
|
|
60
|
+
surfaceType === 'attachment.open'
|
|
55
61
|
) {
|
|
56
62
|
return true;
|
|
57
63
|
}
|
|
@@ -200,6 +206,29 @@ export interface SurfaceCreateInput {
|
|
|
200
206
|
* definePluginSurface 在框架里据此自检,插件一般无需读取。
|
|
201
207
|
*/
|
|
202
208
|
hostSchemaGenerations?: Record<string, HostSchemaGenerationWire>;
|
|
209
|
+
/**
|
|
210
|
+
* 插件前端入口所在目录的地址(以 / 结尾,如 `/api/v1/plugins/<id>/assets/frontend/`),随包资源
|
|
211
|
+
* (pdf.js 的 CMap / 字体 / wasm、按需加载的引擎包等)按相对路径拼在它后面取用,见 resolvePluginAssetUrl。
|
|
212
|
+
* 宿主以已验证字节经 blob: 地址执行插件包,插件里 document.currentScript.src 取不到真实地址,所以由宿主显式给出;
|
|
213
|
+
* 老宿主缺此键时插件可退回自身脚本地址(只在本地调试页有效)。
|
|
214
|
+
*/
|
|
215
|
+
assetBaseUrl?: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 把随包资源的相对路径拼到宿主给的 assetBaseUrl 上。
|
|
220
|
+
* 取不到可用基地址(老宿主缺键、不是 http(s))或相对路径非法(空、绝对、含 ..)时返回空串,由调用方决定退路。
|
|
221
|
+
*/
|
|
222
|
+
export function resolvePluginAssetUrl(input: Pick<SurfaceCreateInput, 'assetBaseUrl'> | null | undefined, relativePath: string): string {
|
|
223
|
+
const base = input?.assetBaseUrl?.trim() ?? '';
|
|
224
|
+
const rel = relativePath.trim();
|
|
225
|
+
if (!base || !rel || rel.startsWith('/') || rel.split('/').includes('..') || /^[a-z][a-z0-9+.-]*:/i.test(rel)) return '';
|
|
226
|
+
try {
|
|
227
|
+
const url = new URL(rel, base.endsWith('/') ? base : `${base}/`);
|
|
228
|
+
return url.protocol === 'http:' || url.protocol === 'https:' ? url.href : '';
|
|
229
|
+
} catch {
|
|
230
|
+
return '';
|
|
231
|
+
}
|
|
203
232
|
}
|
|
204
233
|
|
|
205
234
|
/** createSurface 工厂的返回值,宿主据此挂载 Vue 组件。 */
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// 附件打开服务(attachment)的请求/结果夹具。
|
|
2
|
+
import type { OpenAttachmentRequest, OpenAttachmentResult } from '../attachment-open';
|
|
3
|
+
|
|
4
|
+
/** 典型请求:同一附件字段的两条条目,从第一条打开,带修改态单据上下文。 */
|
|
5
|
+
export const uiAttachmentRequestFixture: OpenAttachmentRequest = {
|
|
6
|
+
items: [
|
|
7
|
+
{ assetId: 'ast_fixture_contract', name: '合同.pdf', contentType: 'application/pdf', byteSize: 102400 },
|
|
8
|
+
{ assetId: 'ast_fixture_notes', name: '说明.txt', contentType: 'text/plain', byteSize: 2048 }
|
|
9
|
+
],
|
|
10
|
+
index: 0,
|
|
11
|
+
recordContext: {
|
|
12
|
+
appId: 'app_fixture',
|
|
13
|
+
templateId: 'tpl_fixture',
|
|
14
|
+
dataTableId: 'tbl_fixture_main',
|
|
15
|
+
fieldId: 'fld_fixture_attachment',
|
|
16
|
+
recordId: 'rec_fixture_1',
|
|
17
|
+
formMode: 'edit'
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** 对应的结果夹具:用户在本次打开期间保存过一次编辑。 */
|
|
22
|
+
export const uiAttachmentResultFixture: OpenAttachmentResult = {
|
|
23
|
+
edited: true
|
|
24
|
+
};
|
package/src/ui-fixtures/index.ts
CHANGED
|
@@ -14,3 +14,4 @@ export { uiTemplatePickerRequestFixture, uiTemplatePickerResultFixture } from '.
|
|
|
14
14
|
export { uiOrgTriPickerRequestFixture, uiOrgTriPickerResultFixture } from './org-tri-picker';
|
|
15
15
|
export { uiConfirmRequestFixture, uiConfirmResultFixture } from './confirm';
|
|
16
16
|
export { uiPromptRequestFixture, uiPromptResultFixture } from './prompt';
|
|
17
|
+
export { uiAttachmentRequestFixture, uiAttachmentResultFixture } from './attachment';
|
package/src/ui-mocks.ts
CHANGED
|
@@ -54,6 +54,7 @@ export interface HostUiMockOverrides {
|
|
|
54
54
|
orgTriPicker?: HostUiMockOutcome | HostUi['openOrgTriPicker'];
|
|
55
55
|
confirm?: HostUiMockOutcome | HostUi['openConfirm'];
|
|
56
56
|
prompt?: HostUiMockOutcome | HostUi['openPrompt'];
|
|
57
|
+
attachment?: HostUiMockOutcome | HostUi['openAttachment'];
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
// ---------------------------------------------------------------------------
|
|
@@ -178,6 +179,14 @@ function resolvePromptImpl(outcome: HostUiMockOutcome | HostUi['openPrompt'] | u
|
|
|
178
179
|
return async () => ({ confirmed: true, value: MOCK_PROMPT_VALUE });
|
|
179
180
|
}
|
|
180
181
|
|
|
182
|
+
function resolveAttachmentImpl(outcome: HostUiMockOutcome | HostUi['openAttachment'] | undefined): HostUi['openAttachment'] {
|
|
183
|
+
if (typeof outcome === 'function') return outcome;
|
|
184
|
+
if (outcome === 'not-wired') return createNotWiredHostUi().openAttachment;
|
|
185
|
+
// 附件外壳没有「确认 / 取消」之分,只有关闭;confirm 档模拟「看过并保存了一次编辑」,cancel 档模拟「只看没改就关了」。
|
|
186
|
+
if (outcome === 'cancel') return async () => ({ edited: false });
|
|
187
|
+
return async () => ({ edited: true });
|
|
188
|
+
}
|
|
189
|
+
|
|
181
190
|
/**
|
|
182
191
|
* 构造满足 HostUi 接口的 mock(插件侧窄化调用面,即 createHostUi() 的产出形状)。
|
|
183
192
|
* 适合在插件自己的 playground/单测里直接替代 `createHostUi(hostBridge)` 的返回值。
|
|
@@ -193,7 +202,8 @@ export function createMockHostUi(overrides?: HostUiMockOverrides): HostUi {
|
|
|
193
202
|
templatePicker: overrides?.templatePicker !== 'not-wired',
|
|
194
203
|
orgTriPicker: overrides?.orgTriPicker !== 'not-wired',
|
|
195
204
|
confirm: overrides?.confirm !== 'not-wired',
|
|
196
|
-
prompt: overrides?.prompt !== 'not-wired'
|
|
205
|
+
prompt: overrides?.prompt !== 'not-wired',
|
|
206
|
+
attachment: overrides?.attachment !== 'not-wired'
|
|
197
207
|
};
|
|
198
208
|
|
|
199
209
|
return {
|
|
@@ -205,7 +215,8 @@ export function createMockHostUi(overrides?: HostUiMockOverrides): HostUi {
|
|
|
205
215
|
openTemplatePicker: resolveTemplatePickerImpl(overrides?.templatePicker),
|
|
206
216
|
openOrgTriPicker: resolveOrgTriPickerImpl(overrides?.orgTriPicker),
|
|
207
217
|
openConfirm: resolveConfirmImpl(overrides?.confirm),
|
|
208
|
-
openPrompt: resolvePromptImpl(overrides?.prompt)
|
|
218
|
+
openPrompt: resolvePromptImpl(overrides?.prompt),
|
|
219
|
+
openAttachment: resolveAttachmentImpl(overrides?.attachment)
|
|
209
220
|
};
|
|
210
221
|
}
|
|
211
222
|
|
|
@@ -246,5 +257,8 @@ export function createMockHostUiBridge(overrides?: HostUiMockOverrides): HostUiB
|
|
|
246
257
|
if (overrides?.prompt !== 'not-wired') {
|
|
247
258
|
bridge.prompt = { open: resolvePromptImpl(overrides?.prompt) };
|
|
248
259
|
}
|
|
260
|
+
if (overrides?.attachment !== 'not-wired') {
|
|
261
|
+
bridge.attachment = { open: resolveAttachmentImpl(overrides?.attachment) };
|
|
262
|
+
}
|
|
249
263
|
return bridge;
|
|
250
264
|
}
|
package/src/ui.ts
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
// 而不是等到沙箱化那天才断。
|
|
16
16
|
|
|
17
17
|
import type { ImageCropperOptions, ImageCropperResult } from './image-tools';
|
|
18
|
+
// 附件打开服务:请求 / 结果类型随附件插件契约放在 attachment-open.ts,这里只接进总线。
|
|
19
|
+
import type { OpenAttachmentRequest, OpenAttachmentResult } from './attachment-open';
|
|
18
20
|
|
|
19
21
|
// ---------------------------------------------------------------------------
|
|
20
22
|
// 服务一:全局表达式编辑器
|
|
@@ -347,7 +349,9 @@ export type HostUiServiceName =
|
|
|
347
349
|
| 'templatePicker'
|
|
348
350
|
| 'orgTriPicker'
|
|
349
351
|
| 'confirm'
|
|
350
|
-
| 'prompt'
|
|
352
|
+
| 'prompt'
|
|
353
|
+
// 附件打开(1.1.0-tp.21 起):宿主附件外壳 + 附件插件;能力键 ui.attachment。
|
|
354
|
+
| 'attachment';
|
|
351
355
|
|
|
352
356
|
/** 单个服务域。留成对象而非裸函数,方便将来加 open 之外的动词而不破坏调用面。 */
|
|
353
357
|
export interface HostUiServiceBridge<Req, Res> {
|
|
@@ -367,6 +371,7 @@ export interface HostUiBridge {
|
|
|
367
371
|
orgTriPicker?: HostUiServiceBridge<OrgTriPickerRequest, OrgTriPickerResult>;
|
|
368
372
|
confirm?: HostUiServiceBridge<OpenConfirmRequest, OpenConfirmResult>;
|
|
369
373
|
prompt?: HostUiServiceBridge<OpenPromptRequest, OpenPromptResult>;
|
|
374
|
+
attachment?: HostUiServiceBridge<OpenAttachmentRequest, OpenAttachmentResult>;
|
|
370
375
|
}
|
|
371
376
|
|
|
372
377
|
/** 插件侧好用的窄化调用面。 */
|
|
@@ -383,6 +388,8 @@ export interface HostUi {
|
|
|
383
388
|
openConfirm(req: OpenConfirmRequest): Promise<OpenConfirmResult>;
|
|
384
389
|
/** 输入框:取代 window.prompt。 */
|
|
385
390
|
openPrompt(req: OpenPromptRequest): Promise<OpenPromptResult>;
|
|
391
|
+
/** 打开附件(查看 / 编辑):宿主外壳按类型路由到附件插件;调用方不再自带查看器。 */
|
|
392
|
+
openAttachment(req: OpenAttachmentRequest): Promise<OpenAttachmentResult>;
|
|
386
393
|
}
|
|
387
394
|
|
|
388
395
|
/** createNotWiredHostUi 的 reject 错误码(error.code),SDK 1.1.0-tp.19 起。 */
|
|
@@ -409,7 +416,8 @@ export function createNotWiredHostUi(): HostUi {
|
|
|
409
416
|
openTemplatePicker: reject('templatePicker'),
|
|
410
417
|
openOrgTriPicker: reject('orgTriPicker'),
|
|
411
418
|
openConfirm: reject('confirm'),
|
|
412
|
-
openPrompt: reject('prompt')
|
|
419
|
+
openPrompt: reject('prompt'),
|
|
420
|
+
openAttachment: reject('attachment')
|
|
413
421
|
};
|
|
414
422
|
}
|
|
415
423
|
|
|
@@ -474,6 +482,10 @@ export function createHostUi(hostBridge: unknown): HostUi {
|
|
|
474
482
|
openPrompt: req => {
|
|
475
483
|
const domain = resolve('prompt');
|
|
476
484
|
return domain ? domain.open(req) : fallback.openPrompt(req);
|
|
485
|
+
},
|
|
486
|
+
openAttachment: req => {
|
|
487
|
+
const domain = resolve('attachment');
|
|
488
|
+
return domain ? domain.open(req) : fallback.openAttachment(req);
|
|
477
489
|
}
|
|
478
490
|
};
|
|
479
491
|
}
|
package/src/workflow-designer.ts
CHANGED
|
@@ -461,7 +461,7 @@ export interface WorkflowDesignerHostContext {
|
|
|
461
461
|
/**
|
|
462
462
|
* hostBridge 上与流程设计器相关的键(经 hostCaps 白名单裁剪,manifest 须声明
|
|
463
463
|
* platform.interactiveSession / domain:workflow-designer / domain:alice-v4 / domain:expression / i18n)。
|
|
464
|
-
* SDK 不依赖表达式编辑器包,两个表达式桥的类型以泛型留给插件(官方插件用 @
|
|
464
|
+
* SDK 不依赖表达式编辑器包,两个表达式桥的类型以泛型留给插件(官方插件用 @kimposoft/expression-editor 的
|
|
465
465
|
* AliceV4Host / ExpressionHost)。
|
|
466
466
|
*/
|
|
467
467
|
export interface WorkflowDesignerHostBridge<TAliceV4Host = unknown, TExpressionHost = unknown> {
|