@k-table/report 0.0.1 → 1.0.0

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.
@@ -0,0 +1,827 @@
1
+ import type { ReactNode } from "react";
2
+ import type * as React from "react";
3
+
4
+ /** 预览/打印数据袋(b=绑定袋 m=映射袋 params=参数袋);与 @k-table/sheet-core 同形 */
5
+ export type ReportFieldData = {
6
+ m?: Record<string, unknown>;
7
+ b?: Record<string, unknown>;
8
+ params?: Record<string, unknown>;
9
+ [key: string]: unknown;
10
+ };
11
+ /** 模板工作簿状态(KTL 解析后);结构化细节见 @k-table/sheet-core */
12
+ export type TemplateWorkbookState = any;
13
+ export const SHEET_TEMPLATE_JSON_VERSION: 2;
14
+
15
+ export class KtStoreError extends Error {
16
+ readonly status?: number;
17
+ constructor(message: string, status?: number);
18
+ }
19
+ export class KtNotFoundError extends KtStoreError {
20
+ constructor(message?: string);
21
+ }
22
+ export class KtConflictError extends KtStoreError {
23
+ readonly current: unknown;
24
+ constructor(message: string, current: unknown);
25
+ }
26
+ export function errorFromHttp(status: number, message: string, body?: unknown): KtStoreError;
27
+
28
+ export type ArtifactKind = "master" | "record" | "report" | "sheet";
29
+ export type ArtifactField = {
30
+ fieldId: string;
31
+ fieldCode: string;
32
+ label: string;
33
+ dataType: string;
34
+ sort: number;
35
+ formula?: string | null;
36
+ tableRelation?: number;
37
+ dictCode?: string | null;
38
+ paramId?: string | null;
39
+ roundKind?: string | null;
40
+ roundDigits?: number | null;
41
+ readOnly?: boolean;
42
+ defaultValue?: string | null;
43
+ optionsJson?: string | null;
44
+ inputKind?: string | null;
45
+ sampleAttrKey?: string | null;
46
+ };
47
+ export interface Artifact {
48
+ id: string;
49
+ name: string;
50
+ kind: ArtifactKind;
51
+ ktl: string;
52
+ masterId?: string;
53
+ faces?: { fill?: string; report?: string };
54
+ commonFieldKeys?: string[];
55
+ /** 字段目录(设计器字段/公式面板数据源) */
56
+ fields?: ArtifactField[];
57
+ /** 录入面/报表面显示闸(缺省 = 两面都显示) */
58
+ showFaces?: { entry?: boolean; report?: boolean };
59
+ /** 宿主角色语义,透传不解释 */
60
+ formRole?: string;
61
+ etag?: string;
62
+ }
63
+ export interface ArtifactMeta {
64
+ id: string;
65
+ name: string;
66
+ kind: ArtifactKind;
67
+ updatedAt?: string;
68
+ }
69
+ export type ValueBag = Record<string, unknown>;
70
+ export interface CommonField {
71
+ key: string;
72
+ label: string;
73
+ dataType?: string;
74
+ zone?: string;
75
+ entryDefault?: unknown;
76
+ }
77
+ export interface ArtifactStore {
78
+ list(kind?: ArtifactKind): Promise<ArtifactMeta[]>;
79
+ get(id: string): Promise<Artifact>;
80
+ save(artifact: Artifact): Promise<Artifact>;
81
+ create?(input: Pick<Artifact, "name" | "kind">): Promise<Artifact>;
82
+ remove?(id: string): Promise<void>;
83
+ }
84
+ export interface InstanceRecord {
85
+ artifactId: string;
86
+ values: ValueBag;
87
+ common?: ValueBag;
88
+ tabCommon?: ValueBag;
89
+ }
90
+ export interface InstanceStore {
91
+ get(id: string): Promise<InstanceRecord>;
92
+ save(id: string, patch: { values?: ValueBag; common?: ValueBag; tabCommon?: ValueBag }): Promise<void>;
93
+ list?(artifactId?: string): Promise<{ id: string; artifactId: string }[]>;
94
+ create?(input: { artifactId: string }): Promise<{ id: string }>;
95
+ }
96
+ export interface VersionRev {
97
+ rev: string;
98
+ kind: string;
99
+ id: string;
100
+ at: string;
101
+ parent?: string | null;
102
+ by?: string | null;
103
+ note?: string | null;
104
+ files: Record<string, string>;
105
+ meta?: Record<string, unknown>;
106
+ }
107
+ export interface VersionStore {
108
+ log(kind: string, id: string): Promise<{ head: string | null; items: VersionRev[] }>;
109
+ get(rev: string): Promise<VersionRev>;
110
+ readFile(rev: string, path: string): Promise<Uint8Array>;
111
+ commit(input: {
112
+ kind: string;
113
+ id: string;
114
+ files?: Record<string, Uint8Array | string>;
115
+ by?: string;
116
+ note?: string;
117
+ meta?: Record<string, unknown>;
118
+ }): Promise<VersionRev>;
119
+ restore(kind: string, id: string, rev: string, by?: string): Promise<VersionRev>;
120
+ }
121
+ export interface FsStoreOptions {
122
+ driver: "fs";
123
+ root: string;
124
+ layout?: "content-addressed";
125
+ }
126
+ export type StoreDescriptor = { driver: "memory" } | FsStoreOptions;
127
+
128
+ export const ARTIFACT_FILE_META: "meta.json";
129
+ export const ARTIFACT_FILE_BODY: "body.ktl";
130
+ export const ARTIFACT_FILE_FILL: "faces/fill.ktl";
131
+ export const ARTIFACT_FILE_REPORT: "faces/report.ktl";
132
+ export function artifactToFiles(a: Artifact): Record<string, string>;
133
+ export function filesToArtifact(files: Record<string, string>, fallbackId?: string): Artifact;
134
+ export function filesEqual(a: Record<string, string>, b: Record<string, string>): boolean;
135
+
136
+ export function createMemoryArtifactStore(seed?: Artifact[]): ArtifactStore;
137
+ export function createMemoryInstanceStore(seed?: Record<string, InstanceRecord>): InstanceStore;
138
+ export function createMemoryVersionStore(artifacts: ArtifactStore): VersionStore;
139
+ export function createHttpArtifactStore(baseUrl: string): ArtifactStore;
140
+ export function createHttpInstanceStore(baseUrl: string): InstanceStore;
141
+ export function createHttpVersionStore(baseUrl: string): VersionStore;
142
+ export function isStoreInstance(v: unknown): boolean;
143
+
144
+ export type KtSku = "report" | "table";
145
+ export type KtColorScheme = "light" | "dark" | "system";
146
+ export type KtTypeScale = "sm" | "md" | "lg";
147
+ export type KtDensity = "compact" | "comfortable" | "spacious";
148
+ export type KtThemePresetId = "paper" | "blue" | "green" | "violet";
149
+ export type KtUiStyleId = "default" | "arco";
150
+ export type KtUiStyle = {
151
+ id: KtUiStyleId;
152
+ name: string;
153
+ token?: Record<string, unknown>;
154
+ components?: Record<string, unknown>;
155
+ };
156
+ export type KtChromeSlot =
157
+ | "pageBg"
158
+ | "headerBg"
159
+ | "border"
160
+ | "text"
161
+ | "textSecondary"
162
+ | "chromeBar"
163
+ | "chromeTab"
164
+ | "canvasPad"
165
+ | "previewHost";
166
+ export type KtChromeColors = Record<KtChromeSlot, string>;
167
+ export type KtThemeChrome = Partial<KtChromeColors> & { extra?: Record<string, string> };
168
+ export type KtColorPalette = { primary: string; success: string; warning: string; error: string };
169
+ export type KtThemePreset = {
170
+ id: KtThemePresetId;
171
+ name: string;
172
+ palette: KtColorPalette;
173
+ forms: { light: KtChromeColors; dark: KtChromeColors };
174
+ };
175
+ export interface KtTheme {
176
+ colorScheme?: KtColorScheme;
177
+ colorPrimary?: string;
178
+ colorSuccess?: string;
179
+ colorWarning?: string;
180
+ colorError?: string;
181
+ typeScale?: KtTypeScale;
182
+ density?: KtDensity;
183
+ radius?: number;
184
+ inheritHost?: boolean;
185
+ presetId?: KtThemePresetId;
186
+ chrome?: KtThemeChrome;
187
+ styleId?: KtUiStyleId;
188
+ }
189
+ export interface KtPdfExportRequest {
190
+ title?: string;
191
+ pageRanges?: string;
192
+ pageSizeMm?: { width: number; height: number };
193
+ landscape?: boolean;
194
+ }
195
+ export interface KtPdfExportResult {
196
+ canceled?: boolean;
197
+ filePath?: string;
198
+ }
199
+ export interface KtPrintHooks {
200
+ /** 打印前(可异步);返回 false 取消本次打印 */
201
+ beforePrint?: (ctx: { title?: string }) => void | boolean | Promise<void | boolean>;
202
+ afterPrint?: () => void;
203
+ /** PDF 导出器(宿主注入桌面桥);缺省 = 浏览器「另存为 PDF」提示 */
204
+ pdfExporter?: (req: KtPdfExportRequest) => Promise<KtPdfExportResult>;
205
+ /** 「打印选项」菜单追加项 */
206
+ extraOptions?: { label: string; onClick: () => void }[];
207
+ /** 打印记忆 localStorage key 前缀;缺省 "kt-preview-print-mem" */
208
+ memoryKey?: string;
209
+ }
210
+ export interface KtPreviewHooks {
211
+ /** 灌数后处理:业务 enrich / 图表与签名图槽数据注入 */
212
+ enrichFieldData?: (
213
+ fieldData: ReportFieldData,
214
+ ctx: { artifactId?: string; instanceId?: string },
215
+ ) => ReportFieldData | Promise<ReportFieldData>;
216
+ /** 页眉页脚 chrome 数据(审批意见/二维码/审核人区);null = 无 */
217
+ pageChrome?: (ctx: { artifactId?: string; instanceId?: string }) => Promise<{
218
+ showOpinion: boolean;
219
+ showQr: boolean;
220
+ showReviewer: boolean;
221
+ } | null>;
222
+ onPageChromeCommit?: (
223
+ next: { showOpinion: boolean; showQr: boolean; showReviewer: boolean },
224
+ remember: { rememberUnit?: boolean; rememberMaster?: boolean },
225
+ ctx: { artifactId?: string },
226
+ ) => void;
227
+ }
228
+ export interface KtDesignerHooks {
229
+ /** 业务绑定字段目录,并入设计器字段面板 */
230
+ bindingSchemas?: unknown[];
231
+ /** 公式试算(宿主业务 API,按字段);缺省时公式面板只编辑不试算 */
232
+ trialFormula?: (ctx: {
233
+ artifactId?: string;
234
+ fieldCode: string;
235
+ formula: string;
236
+ roundKind?: string | null;
237
+ roundDigits?: number | null;
238
+ }) => Promise<{ rounded?: string; raw?: string; source?: string }>;
239
+ /** prepage 规则面板的字典选项源(dictCode → 选项);缺省隐藏字典相关入口 */
240
+ prepageDicts?: () => Promise<Record<string, { value: string; label: string }[]>>;
241
+ /** 服务端设计包导入(宿主自弹 UI);返回 "reload" 让设计器重取 artifact */
242
+ importDesignPack?: (ctx: {
243
+ artifactId: string;
244
+ name?: string;
245
+ masterId?: string;
246
+ ktl?: string;
247
+ hasFields?: boolean;
248
+ }) => Promise<"reload" | null>;
249
+ /** 实例联排数据源;缺省隐藏实例模式 */
250
+ instances?: {
251
+ list: (artifactId: string) => Promise<{ id: string; title: string }[]>;
252
+ fieldData: (instanceId: string, ctx: { artifactId: string }) => Promise<ReportFieldData>;
253
+ };
254
+ }
255
+ export interface KtFillHooks {
256
+ /** 录入画布字典选项(dictCode → 选项);缺省无字典下拉 */
257
+ dicts?: () => Promise<Record<string, { value: string; label: string }[]>>;
258
+ /** 预览公共袋最后加工(单位名/人员签名等宿主语义);在包内 enrich 之后执行 */
259
+ enrichCommon?: (bag: Record<string, string>, ctx: { instanceId?: string }) => Record<string, string>;
260
+ }
261
+ export interface KtHooks {
262
+ print?: KtPrintHooks;
263
+ preview?: KtPreviewHooks;
264
+ designer?: KtDesignerHooks;
265
+ fill?: KtFillHooks;
266
+ }
267
+ export interface KtConfig {
268
+ sku: KtSku;
269
+ locale?: "zh-CN";
270
+ /** 商业授权串(kt1.<payload>.<sig>)。缺省 = 试用模式:预览/打印带水印。 */
271
+ license?: string;
272
+ storage: {
273
+ artifacts: ArtifactStore | { driver: "memory" } | FsStoreOptions;
274
+ instances?: InstanceStore | { driver: "memory" } | FsStoreOptions;
275
+ versions?: false | VersionStore | FsStoreOptions;
276
+ httpBaseUrl?: string;
277
+ };
278
+ versions?: { commitPolicy?: "promote" | "onSave"; kinds?: string[] };
279
+ ui?: { theme?: KtTheme; persistThemeKey?: string; licenseBanner?: boolean };
280
+ features?: {
281
+ master?: boolean;
282
+ fill?: boolean;
283
+ excelImport?: boolean;
284
+ sourceDrawer?: boolean;
285
+ formula?: boolean;
286
+ combo?: boolean;
287
+ versions?: boolean;
288
+ print?: boolean;
289
+ pdf?: boolean;
290
+ };
291
+ /** 宿主钩子:打印/PDF/预览灌数/设计器字段目录。全部可选。 */
292
+ hooks?: KtHooks;
293
+ }
294
+ export interface ResolvedFeatures {
295
+ master: boolean;
296
+ fill: boolean;
297
+ excelImport: boolean;
298
+ sourceDrawer: boolean;
299
+ formula: boolean;
300
+ combo: boolean;
301
+ versions: boolean;
302
+ print: boolean;
303
+ pdf: boolean;
304
+ }
305
+ export function resolveFeatures(config: Pick<KtConfig, "sku" | "features">): ResolvedFeatures;
306
+ export function defaultKinds(config: KtConfig): string[];
307
+ export function versionsUiEnabled(config: KtConfig): boolean;
308
+ export function commitPolicyOf(config: KtConfig): "promote" | "onSave";
309
+ export function maybeCommitOnSave(
310
+ config: KtConfig,
311
+ versions: VersionStore | undefined,
312
+ saved: Artifact,
313
+ ): Promise<VersionRev | undefined>;
314
+ export function resolveStores(config: KtConfig): {
315
+ artifacts: ArtifactStore;
316
+ instances?: InstanceStore;
317
+ versions?: VersionStore;
318
+ };
319
+
320
+ export const KT_COLOR_PRIMARY: "#1677ff";
321
+ export const KT_COLOR_SUCCESS: "#52c41a";
322
+ export const KT_COLOR_WARNING: "#faad14";
323
+ export const KT_COLOR_ERROR: "#ff4d4f";
324
+ export const KT_INHERIT_HOST_DEFAULT: false;
325
+ export const DEFAULT_KT_PRESET_ID: "blue";
326
+ export const KT_THEME_PRESETS: readonly KtThemePreset[];
327
+ export const KT_CHROME_SLOTS: readonly KtChromeSlot[];
328
+ export const KT_CHROME_BG_SLOTS: readonly { key: KtChromeSlot; label: string }[];
329
+ export const KT_CHROME_CSS_VARS: Record<KtChromeSlot, string>;
330
+ export const FORMS_PAGE_BG: "var(--kt-forms-page-bg)";
331
+ export const FORMS_HEADER_BG: "var(--kt-forms-header-bg)";
332
+ export const FORMS_BORDER: "var(--kt-forms-border)";
333
+ export const FORMS_TEXT: "var(--kt-forms-text)";
334
+ export const FORMS_TEXT_SECONDARY: "var(--kt-forms-text-secondary)";
335
+ export const FORMS_CHROME_BAR: "var(--kt-forms-chrome-bar)";
336
+ export const FORMS_CHROME_TAB: "var(--kt-forms-chrome-tab)";
337
+ export const FORMS_CANVAS_PAD: "var(--kt-forms-canvas-pad)";
338
+ export const FORMS_PREVIEW_HOST: "var(--kt-forms-preview-host)";
339
+ export const DEFAULT_KT_UI_STYLE_ID: "default";
340
+ export const KT_UI_STYLES: readonly KtUiStyle[];
341
+ export function isKtUiStyleId(id: string): id is KtUiStyleId;
342
+ export function getKtUiStyle(id?: string): KtUiStyle;
343
+ export function isKtThemePresetId(id: string): id is KtThemePresetId;
344
+ export function getKtPreset(id?: string): KtThemePreset;
345
+ export function applyPresetToTheme(id: KtThemePresetId, prev: KtTheme): KtTheme;
346
+ export function mergeThemePatch(prev: KtTheme, patch: Partial<KtTheme>): KtTheme;
347
+ export function hydrateTheme(base: KtTheme, saved: Partial<KtTheme>): KtTheme;
348
+ export function resolveChrome(theme: KtTheme, scheme: "light" | "dark"): KtChromeColors;
349
+ export function chromeToCssVars(chrome: KtChromeColors, extra?: Record<string, string>): Record<string, string>;
350
+
351
+ export type KtThemeApi = {
352
+ theme: KtTheme;
353
+ scheme: "light" | "dark";
354
+ chrome: KtChromeColors;
355
+ setTheme: (patch: Partial<KtTheme>) => void;
356
+ applyPreset: (id: KtThemePresetId) => void;
357
+ applyStyle: (id: KtUiStyleId) => void;
358
+ };
359
+
360
+ export function KtProvider(props: {
361
+ config: KtConfig;
362
+ onThemeChange?: (theme: KtTheme) => void;
363
+ children: ReactNode;
364
+ }): JSX.Element;
365
+ export function useKt(): {
366
+ config: KtConfig;
367
+ stores: { artifacts: ArtifactStore; instances?: InstanceStore; versions?: VersionStore };
368
+ theme: KtTheme;
369
+ setTheme: (patch: Partial<KtTheme>) => void;
370
+ applyPreset: (id: KtThemePresetId) => void;
371
+ applyStyle: (id: KtUiStyleId) => void;
372
+ scheme: "light" | "dark";
373
+ chrome: KtChromeColors;
374
+ kinds: string[];
375
+ versionsUi: boolean;
376
+ features: ResolvedFeatures;
377
+ license: KtLicenseInfo;
378
+ };
379
+ export function useKtOptional(): ReturnType<typeof useKt> | null;
380
+ export function useKtTheme(): KtThemeApi;
381
+
382
+ export type KtLicenseStatus = "valid" | "missing" | "invalid" | "expired" | "domain-mismatch";
383
+ export interface KtLicensePayload {
384
+ customer: string;
385
+ expires: string;
386
+ sku: string[];
387
+ domains?: string[];
388
+ iat?: string;
389
+ note?: string;
390
+ }
391
+ export interface KtLicenseInfo {
392
+ status: KtLicenseStatus;
393
+ payload?: KtLicensePayload;
394
+ reason?: string;
395
+ }
396
+ export function verifyKtLicense(
397
+ license: string | undefined | null,
398
+ opts: { sku: KtSku; hostname?: string | null; now?: Date; publicKey?: string },
399
+ ): KtLicenseInfo;
400
+ export function useKtLicense(): KtLicenseInfo;
401
+ export function KtLicenseBanner(): JSX.Element | null;
402
+
403
+ export function readArtifactAtRev(store: VersionStore, rev: string): Promise<Artifact>;
404
+ export function KtVersionPanel(props: {
405
+ open: boolean;
406
+ kind: string;
407
+ id: string;
408
+ onClose: () => void;
409
+ onRestored?: () => void;
410
+ }): JSX.Element | null;
411
+
412
+ /** 向后兼容别名;正本为 ArtifactField(Artifact.fields 元素型) */
413
+ export type DesignerFormField = ArtifactField;
414
+ export function withSplitFaces(artifact: Artifact, workbook: unknown): Artifact;
415
+ export function previewKtlOf(artifact: Artifact): string;
416
+ export function KtReportDesigner(props: {
417
+ artifact?: Artifact;
418
+ artifactId?: string;
419
+ store?: ArtifactStore;
420
+ /** 母版清单/读取的独立 store(如目录 defs 适配器 + reports 母版);缺省同 store */
421
+ masterStore?: ArtifactStore;
422
+ masters?: { id: string; name: string }[];
423
+ values?: Record<string, unknown>;
424
+ formFields?: DesignerFormField[];
425
+ sheetFaceEnabled?: boolean;
426
+ onSave?: (a: Artifact) => void;
427
+ onConflict?: (e: KtConflictError) => void;
428
+ /** 提供则铬层出现「另存」,参数为当前内存稿(含未保存改动) */
429
+ onSaveAs?: (a: Artifact) => void;
430
+ /** true = 铬层名称可编辑(随保存落库) */
431
+ nameEditable?: boolean;
432
+ /** true 且 hooks.designer.importDesignPack 存在时,导入按钮带「导入设计包(服务端)」入口 */
433
+ allowImportPack?: boolean;
434
+ extraActions?: ReactNode;
435
+ leadingActions?: ReactNode;
436
+ }): JSX.Element;
437
+ export function KtReportPreview(props: {
438
+ artifact?: Artifact;
439
+ artifactId?: string;
440
+ store?: ArtifactStore;
441
+ rev?: string;
442
+ values?: ValueBag;
443
+ common?: ValueBag;
444
+ /** false = 极简纸面(无打印条);缺省走完整预览壳 */
445
+ print?: boolean;
446
+ showVersionPanel?: boolean;
447
+ extraActions?: ReactNode;
448
+ onBack?: () => void;
449
+ backDisabled?: boolean;
450
+ preferSampleContent?: boolean;
451
+ /** 当次附加绑定字段(与 hooks.designer.bindingSchemas 合并) */
452
+ bindingSchema?: unknown[];
453
+ /** 打印空白:空袋求值后的合成稿;null = 有闸门无默认不打页 */
454
+ blankWorkbook?: unknown;
455
+ blankEmptyHint?: string;
456
+ fieldDataForSheet?: (sheetId: string) => ReportFieldData;
457
+ /** 实例上下文:透传给 hooks 的 ctx.instanceId */
458
+ instanceId?: string;
459
+ /** 打印记忆表 key;缺省 artifact.id */
460
+ tableKey?: string;
461
+ /** 打印记忆种类(以下空白分槽);缺省按 artifact.kind 映射 */
462
+ printKind?: "record" | "report" | "consign";
463
+ /** 页眉页脚 chrome(优先于 hooks.preview.pageChrome) */
464
+ pageChrome?: { showOpinion: boolean; showQr: boolean; showReviewer: boolean } | null;
465
+ onPageChromeCommit?: (
466
+ next: { showOpinion: boolean; showQr: boolean; showReviewer: boolean },
467
+ remember: { rememberUnit?: boolean; rememberMaster?: boolean },
468
+ ) => void;
469
+ }): JSX.Element;
470
+ // C3:低层逃生舱与通用预览工具
471
+ export type PageChromeRegions = { showOpinion: boolean; showQr: boolean; showReviewer: boolean };
472
+ export type PageChromePartial = Partial<PageChromeRegions>;
473
+ export type PageChromeRemember = { rememberUnit?: boolean; rememberMaster?: boolean };
474
+ export const DEFAULT_PAGE_CHROME: PageChromeRegions;
475
+ export function overlayPageChrome(...layers: Array<PageChromePartial | null | undefined>): PageChromeRegions;
476
+ export function pageChromeEquals(a: PageChromeRegions, b: PageChromeRegions): boolean;
477
+ export function parsePageChromeFromBag(bag: Record<string, unknown> | null | undefined): PageChromePartial | null;
478
+ export function parsePageChromeFromSearch(search: { get(name: string): string | null } | null | undefined): PageChromePartial | null;
479
+ export function parsePageChromePartial(raw: unknown): PageChromePartial | null;
480
+ export function stringifyPageChrome(chrome: PageChromeRegions): string;
481
+ export function writePageChromeToBag(bag: Record<string, string>, chrome: PageChromeRegions): Record<string, string>;
482
+ export type PreviewPrintKind = "record" | "report" | "consign";
483
+ export function resolvePrintMemoryTableKey(legacyCode?: string | null, formDefId?: string | null): string;
484
+ export type BindingField = { label: string; value: string; group?: string };
485
+ export function mergeBindingSchema(base: BindingField[], extra?: BindingField[]): BindingField[];
486
+ export function bindingFieldsFromFieldData(fieldData?: ReportFieldData | null): BindingField[];
487
+ export function bindingFieldsFromWorkbook(workbook: unknown): BindingField[];
488
+ export function readBindingExtras(workbook: unknown): BindingField[];
489
+ export const SAMPLE_FIELD_DATA: ReportFieldData;
490
+ export function applySampleInfoCompose(
491
+ bag: Record<string, string>,
492
+ keys: string[],
493
+ labelOf: (key: string) => string,
494
+ ): Record<string, string>;
495
+ export const SAMPLE_INFO_PAPER_LABEL: string;
496
+ export function enrichLabNameFieldData(fieldData?: ReportFieldData | null, fallbackLabName?: string): ReportFieldData;
497
+ export function resolvePreviewLabName(
498
+ bag?: Record<string, unknown> | null,
499
+ extras?: { queryLabName?: string; homeOrgName?: string },
500
+ ): string;
501
+ // C3:导入设计包/母版拼接工具
502
+ export type MasterZones = any;
503
+ export type MasterComposeFail = { fail: true; reason?: string; [key: string]: unknown };
504
+ export function isMasterFail(v: unknown): boolean;
505
+ export function deriveMasterZones(sheet: unknown): MasterZones | MasterComposeFail;
506
+ export function fitWorkbookToMasterBodySlot(
507
+ workbook: TemplateWorkbookState,
508
+ master: unknown,
509
+ masterId?: string,
510
+ opts?: { resetBorder?: boolean; sheetIds?: string[] },
511
+ ): TemplateWorkbookState;
512
+ export function normalizeWorkbookBordersToThinSolid(workbook: TemplateWorkbookState): TemplateWorkbookState;
513
+ export function mergeImportedPrepage(
514
+ currentEntryKtl: string | null | undefined,
515
+ incomingEntryKtl: string | null | undefined,
516
+ opts: { replaceLayout: boolean; replaceRules: boolean },
517
+ ): string;
518
+ export function prepageDisplayName(raw?: string | null): string;
519
+ export function KtReportPreviewSurface(props: {
520
+ workbook: unknown;
521
+ blankWorkbook?: unknown;
522
+ blankEmptyHint?: string;
523
+ fieldData?: ReportFieldData;
524
+ fieldDataForSheet?: (sheetId: string) => ReportFieldData;
525
+ bindingSchema?: BindingField[];
526
+ preferSampleContent?: boolean;
527
+ title?: string;
528
+ composeWarn?: string | null;
529
+ chrome?: "page" | "modal";
530
+ onBack?: () => void;
531
+ backDisabled?: boolean;
532
+ extraActions?: ReactNode;
533
+ tableKey?: string;
534
+ printKind?: PreviewPrintKind;
535
+ fallbackLabName?: string;
536
+ pageChrome?: PageChromeRegions | null;
537
+ onPageChromeCommit?: (next: PageChromeRegions, remember: PageChromeRemember) => void;
538
+ watermarkOverride?: unknown;
539
+ }): JSX.Element;
540
+ export function KtReportCatalog(props: {
541
+ store?: ArtifactStore;
542
+ kinds?: ArtifactKind[];
543
+ onOpenDesign: (id: string) => void;
544
+ onOpenPreview: (id: string) => void;
545
+ /** 提供且 features.fill 开启时,行内出现「录入」入口 */
546
+ onOpenFill?: (id: string) => void;
547
+ }): JSX.Element;
548
+ export function KtThemeBar(props?: { variant?: "default" | "onPrimary" }): JSX.Element;
549
+ export function KtBrandBar(props: { title: string; themeBar?: boolean }): JSX.Element;
550
+
551
+ export const EMPTY_KTL: string;
552
+ export const SAMPLE_A4_KTL: string;
553
+ export const SAMPLE_DEMO_KTL: string;
554
+ export const SAMPLE_MASTER_KTL: string;
555
+
556
+ export function composeKtlForPreview(
557
+ ktl: string,
558
+ fetchMasterKtl: (masterId: string) => Promise<string | null>,
559
+ ): Promise<{ workbook: unknown; masterId?: string; composed: boolean; error?: string }>;
560
+
561
+ // ---- C1c:目录设计器适配器用纯函数 ----
562
+ export function splitFormFaceKtls(workbook: unknown): { entryKtl: string; reportKtl: string };
563
+ export function mergeFormFaceKtls(entryKtl?: string | null, reportKtl?: string | null): string;
564
+ export function hasUsableFaceLayout(ktl: string): boolean;
565
+ export function mergeMiddleComposeMeta(
566
+ workbook: unknown,
567
+ meta: { masterId?: string; importColWidths?: number[]; importRowHeights?: number[] },
568
+ ): unknown;
569
+ export function readMiddleComposeMeta(workbook: unknown): {
570
+ masterId?: string;
571
+ importColWidths?: number[];
572
+ importRowHeights?: number[];
573
+ columnPrecisionMul?: number;
574
+ } | null;
575
+ export function validateFieldsFormulas(fields: FormulaField[]): string | null;
576
+ export function prepageSaveError(workbook: unknown): string | null;
577
+ export function readPrepage(workbook: unknown): { sheetId?: string; rules: unknown[] } | null;
578
+ export function isPrepageSheet(workbook: unknown, sheetId: string): boolean;
579
+ export function parseKtlSafe(ktl: string): { workbook: any; diagnostics: { severity: string; message: string }[] };
580
+ export function workbookToKtlText(workbook: unknown): string;
581
+
582
+ // ---- C2a:实例填报(KtReportFill + 画布三件套) ----
583
+ export interface SheetCommonStore {
584
+ legacy: Record<string, string>;
585
+ byReport: Record<string, Record<string, string>>;
586
+ }
587
+ export function parseSheetCommonStore(raw?: string | null): SheetCommonStore;
588
+ export function stringifySheetCommonStore(store?: SheetCommonStore | null): string;
589
+
590
+ export type KtFillCommonField = { fieldKey: string; label: string; dataType?: string; enabled?: boolean };
591
+ export type KtFillSheet = {
592
+ sheetId: string;
593
+ formDefId: string;
594
+ formName?: string;
595
+ tabTitle?: string;
596
+ formRole?: string;
597
+ entryMiddleKtl?: string | null;
598
+ reportMiddleKtl?: string | null;
599
+ middleKtl?: string | null;
600
+ showEntry?: boolean;
601
+ showReport?: boolean;
602
+ commonFieldKeys?: string[];
603
+ fields?: ArtifactField[];
604
+ };
605
+ export type KtFillComboMember = { formDefId: string; tabTitle?: string; formRole?: string };
606
+ export type ComboMapRule = {
607
+ sourceFormDefId: string;
608
+ sourceFieldCode: string;
609
+ targetFormDefId: string;
610
+ targetFieldCode: string;
611
+ mode?: string;
612
+ formula?: string;
613
+ whenMode?: string;
614
+ sourceRoundKind?: string;
615
+ sourceRoundDigits?: number | null;
616
+ targetRoundKind?: string;
617
+ targetRoundDigits?: number | null;
618
+ sourceSlot?: number | null;
619
+ };
620
+ export type KtFillSnapshot = {
621
+ common: Record<string, string>;
622
+ tabCommons: Record<string, SheetCommonStore>;
623
+ values: Record<string, Record<string, string>>;
624
+ handEdited: Record<string, string[]>;
625
+ };
626
+ export interface KtReportFillHandle {
627
+ collect(): KtFillSnapshot;
628
+ getCommonField(key: string): string;
629
+ setCommonField(key: string, val: string): void;
630
+ }
631
+ export type KtCommonFieldCtx = {
632
+ value: string;
633
+ readOnly: boolean;
634
+ setValue: (v: string) => void;
635
+ setField: (key: string, v: string) => void;
636
+ bag: (key: string) => string;
637
+ label: string;
638
+ };
639
+ export const KtReportFill: React.ForwardRefExoticComponent<
640
+ React.RefAttributes<KtReportFillHandle> & {
641
+ instanceId: string;
642
+ kind: string;
643
+ sheets: KtFillSheet[];
644
+ commonFields: KtFillCommonField[];
645
+ comboMembers?: KtFillComboMember[];
646
+ comboMappings?: ComboMapRule[];
647
+ comboCommonFieldKeys?: string[];
648
+ initialCommon?: Record<string, string>;
649
+ initialTabCommons?: Record<string, SheetCommonStore>;
650
+ initialValues?: Record<string, Record<string, string>>;
651
+ initialHandEdited?: Record<string, string[]>;
652
+ version?: unknown;
653
+ readOnly?: boolean;
654
+ onSnapshot?: (snap: KtFillSnapshot) => void;
655
+ onActiveSheetChange?: (sheet: KtFillSheet | undefined) => void;
656
+ previewBar?: ReactNode;
657
+ toolbar?: ReactNode;
658
+ hint?: ReactNode;
659
+ title?: string;
660
+ leftTitle?: string;
661
+ renderCommonField?: (f: KtFillCommonField, ctx: KtCommonFieldCtx) => ReactNode;
662
+ leftFooter?: ReactNode;
663
+ withPreview?: boolean;
664
+ previewExtra?: {
665
+ fallbackLabName?: string;
666
+ staffSigners?: unknown[];
667
+ sampleComposeKeys?: string[] | null;
668
+ sampleFieldLabel?: (key: string) => string;
669
+ pageChrome?: unknown;
670
+ request?: <T>(path: string, init?: RequestInit) => Promise<T>;
671
+ scheme?: any;
672
+ onSchemeChange?: (s: any, b: any) => void;
673
+ };
674
+ dicts?: Record<string, { value: string; label: string }[]>;
675
+ className?: string;
676
+ }
677
+ >;
678
+ export function InstanceFillSheet(props: {
679
+ ktl?: string | null;
680
+ fields?: ArtifactField[];
681
+ values?: Record<string, string>;
682
+ readOnly?: boolean;
683
+ hideBoundCodesHint?: boolean;
684
+ showBoundCodes?: boolean;
685
+ mappedCodes?: string[];
686
+ handEditedCodes?: string[];
687
+ mappingTips?: Record<string, string>;
688
+ dicts?: Record<string, { value: string; label: string }[]>;
689
+ digitOverlays?: unknown;
690
+ omitTrailingZerosOverride?: boolean;
691
+ reportSheets?: { id: string; name: string }[];
692
+ reportSheetId?: string;
693
+ onReportSheetChange?: (id: string) => void;
694
+ /** 组合设计:点绑定格挑字段 */
695
+ onPickBind?: (info: { fieldCode: string; bagKey: string }) => void;
696
+ pickedBagKey?: string | null;
697
+ face?: "entry" | "report";
698
+ onChange?: (code: string, val: string, meta?: { handEdit?: boolean; restore?: boolean; blur?: boolean; remove?: boolean }) => void;
699
+ }): JSX.Element;
700
+ export function InstanceFillLayout(props: any): JSX.Element;
701
+ // ---- C2b:宿主薄壳用纯函数 ----
702
+ export function applyComboMappingsToSheets(
703
+ valuesBySheet: Record<string, Record<string, string>>,
704
+ sheets: { sheetId: string; formDefId: string; fields?: any[] }[],
705
+ mappings: ComboMapRule[],
706
+ handsBySheet: Record<string, string[]>,
707
+ ): Record<string, Record<string, string>>;
708
+ export function applyComboMappings(...args: any[]): any;
709
+ export function mappingLine(opts: any): string;
710
+ export function applySheetFormulas(bag: Record<string, string>, fields: any[], hands?: string[]): Record<string, string>;
711
+ export function codesMatch(list: string[] | undefined, code: string): boolean;
712
+ export function fieldCodeFromBindKey(bindKey: string): string | null;
713
+ export function fieldHasFormula(field: any): boolean;
714
+ export function evalFormula(formula: string, bag: Record<string, string>): string | null;
715
+ export function validateFormula(formula?: string | null, knownCodes?: string[]): string | null;
716
+ // C2c:公式引擎全量面(正本单源)
717
+ export type FormulaField = {
718
+ fieldCode: string;
719
+ formula?: string | null;
720
+ roundKind?: string | null;
721
+ roundDigits?: number | null;
722
+ readOnly?: boolean;
723
+ tableRelation?: number | null;
724
+ };
725
+ export const FORMULA_FNS: { label: string; insert: string }[];
726
+ export function normalizeDialect(formula: string): string;
727
+ export function currentToken(text: string, caret: number): { start: number; end: number; token: string };
728
+ export function suggestFormulaTokens(
729
+ text: string,
730
+ caret: number,
731
+ fields: { fieldCode: string; label: string }[],
732
+ ): { insert: string; label: string; kind: "field" | "fn" }[];
733
+ export const OMIT_TRAILING_ZEROS_KEY: string;
734
+ export const OMIT_TRAILING_ZEROS_EVENT: string;
735
+ export function loadOmitTrailingZeros(): boolean;
736
+ export function saveOmitTrailingZeros(on: boolean): void;
737
+ export function applyRound(raw: string, kind?: string | null, digits?: number | null): string;
738
+ export function formatRoundDisplay(raw: string, kind?: string | null, digits?: number | null, omitTrailingZeros?: boolean): string;
739
+ export function formatFieldBag(
740
+ bag: Record<string, string>,
741
+ fields: { fieldCode: string; roundKind?: string | null; roundDigits?: number | null }[],
742
+ omitTrailingZeros?: boolean,
743
+ ): Record<string, string>;
744
+ export function formatReportFieldData<T extends { m?: Record<string, unknown> }>(
745
+ data: T,
746
+ fields: { fieldCode: string; roundKind?: string | null; roundDigits?: number | null }[],
747
+ omitTrailingZeros?: boolean,
748
+ ): T;
749
+ export function stripFieldDataTrailingZeros<T extends { m?: Record<string, unknown> }>(data: T): T;
750
+ export function expandFormulaFns(formula: string): string;
751
+ export function isSubField(f: { fieldCode: string; tableRelation?: number | null }): boolean;
752
+ export function isSubtableField(f: FormulaField | undefined, fieldCode: string): boolean;
753
+ export function markLabel(code?: string | null): string;
754
+ export function listSubRows(bag: Record<string, string>): { sid: number; slot: number }[];
755
+ export function projectRow(bag: Record<string, string>, sid: number, slot: number): Record<string, string>;
756
+ export function fieldHandLocked(hands: Set<string>, code: string, sid?: number, slot?: number): boolean;
757
+ export function readFieldSlots(
758
+ bag: Record<string, string>,
759
+ fieldCode: string,
760
+ ): { key: string; value: string; sid?: number; slot: number }[];
761
+ export function inferSubSid(field: FormulaField | undefined, bag: Record<string, string>, fieldCode: string, srcSid?: number): number;
762
+ export function writeMappedValue(
763
+ bag: Record<string, string>,
764
+ field: FormulaField | undefined,
765
+ fieldCode: string,
766
+ value: string,
767
+ srcSid: number | undefined,
768
+ slot: number,
769
+ ): void;
770
+ export function extractFieldRefs(formula: string): string[];
771
+ export function trialFormula(formula: string, fields: { fieldCode: string }[], kind?: string | null, digits?: number | null): string | null;
772
+ export function emptySheetCommonStore(): SheetCommonStore;
773
+ export const FILL_LEFT_COLLAPSED_KEY: string;
774
+ export const FILL_LEFT_COMMON: string;
775
+ export const FILL_LEFT_MEMBER: string;
776
+ export function loadFillLeftCollapsed(): boolean;
777
+ export function saveFillLeftCollapsed(collapsed: boolean): void;
778
+ export function coalesceCommon(
779
+ inst: Record<string, string>,
780
+ tab: Record<string, string>,
781
+ skipNos?: boolean,
782
+ ): Record<string, string>;
783
+ export function isSignCommonField(fieldKey?: string | null): boolean;
784
+ export const RECORD_SIGN_LABELS: Record<string, string>;
785
+ export const REPORT_SIGN_LABELS: Record<string, string>;
786
+ export const SHEET_COMMON_BY_REPORT: string;
787
+ export function coalesceMemberCommon(inst: Record<string, string>, store?: SheetCommonStore | null): Record<string, string>;
788
+ export function coalesceReportPageCommon(inst: Record<string, string>, store: SheetCommonStore | null | undefined, reportSheetId: string): Record<string, string>;
789
+ export function reportPageOverlay(store: SheetCommonStore | null | undefined, reportSheetId: string): Record<string, string>;
790
+ export function setReportPageOverlayField(store: SheetCommonStore | null | undefined, reportSheetId: string, key: string, val: string): SheetCommonStore;
791
+ export function setSheetLegacyField(store: SheetCommonStore | null | undefined, key: string, val: string): SheetCommonStore;
792
+ export function commonFieldLabel(key: string, kind: string | undefined, fallback?: string): string;
793
+ export function orderFillEntryFields<T extends { fieldKey: string }>(fields: T[]): T[];
794
+ export function isFillNoKey(key: string): boolean;
795
+ export function enrichPreviewCommon(common: Record<string, string>, opts?: any): Record<string, string>;
796
+ export function stripFillDefaultBag(bag: Record<string, string>): Record<string, string>;
797
+ export function stripFillDefaultStore(store?: SheetCommonStore | null): SheetCommonStore;
798
+ export function recordNoLabelForKind(kind?: string): string;
799
+ export const DEFAULT_SAMPLE_COMPOSE_KEYS: string[];
800
+ export const SAMPLE_INFO_KEY: string;
801
+ export const SAMPLE_INFO_LABEL: string;
802
+ export function normalizeSampleComposeKeys(keys?: string[] | null): string[];
803
+ export function parseSampleComposeKeys(raw?: string | null): string[];
804
+ export function listVisibleReportSheets(reportKtl?: string | null, entryKtl?: string | null, bag?: any, opts?: { showReport?: boolean }): { id: string; name: string }[];
805
+ export function reportWorkbookForPreview(reportKtl: string | null | undefined, entryKtl: string | null | undefined, bag: any, opts?: { treatAsEmpty?: boolean; showReport?: boolean }): { workbook: any; emptyHint: string };
806
+ export const PREPAGE_EMPTY_HINT: string;
807
+ export type KtFormField = ArtifactField;
808
+ export type StaffSignerLite = { staffId: string; displayName: string; certNos: string[]; hasSignImage?: boolean; signImageSrc?: string };
809
+ export const PERSON_SIGN_SLOTS: readonly { personKey: string; label: string }[];
810
+ export function staffIdKey(personKey: string): string;
811
+ export function certNoKey(personKey: string): string;
812
+ export function formatTestDateCn(raw?: string): string;
813
+ export function formatTestDateText(start?: string, end?: string): string;
814
+ export function sampleNoFromRecordNo(recordNo?: string): string;
815
+ export function useFillLeftScope(
816
+ reportSheets: { id: string; name: string }[],
817
+ resetKey?: string,
818
+ combo?: boolean,
819
+ ): {
820
+ leftScope: string;
821
+ scopeLocked: boolean;
822
+ editingMember: boolean;
823
+ editingReport: boolean;
824
+ previewSheetId?: string;
825
+ onLeftScopeChange: (v: string) => void;
826
+ };
827
+ export function InstanceFillPreviewPane(props: any): JSX.Element;