@k-table/report 0.0.1 → 0.1.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,348 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export class KtStoreError extends Error {
4
+ readonly status?: number;
5
+ constructor(message: string, status?: number);
6
+ }
7
+ export class KtNotFoundError extends KtStoreError {
8
+ constructor(message?: string);
9
+ }
10
+ export class KtConflictError extends KtStoreError {
11
+ readonly current: unknown;
12
+ constructor(message: string, current: unknown);
13
+ }
14
+ export function errorFromHttp(status: number, message: string, body?: unknown): KtStoreError;
15
+
16
+ export type ArtifactKind = "master" | "record" | "report" | "sheet";
17
+ export interface Artifact {
18
+ id: string;
19
+ name: string;
20
+ kind: ArtifactKind;
21
+ ktl: string;
22
+ masterId?: string;
23
+ faces?: { fill?: string; report?: string };
24
+ commonFieldKeys?: string[];
25
+ etag?: string;
26
+ }
27
+ export interface ArtifactMeta {
28
+ id: string;
29
+ name: string;
30
+ kind: ArtifactKind;
31
+ updatedAt?: string;
32
+ }
33
+ export type ValueBag = Record<string, unknown>;
34
+ export interface CommonField {
35
+ key: string;
36
+ label: string;
37
+ dataType?: string;
38
+ zone?: string;
39
+ entryDefault?: unknown;
40
+ }
41
+ export interface ArtifactStore {
42
+ list(kind?: ArtifactKind): Promise<ArtifactMeta[]>;
43
+ get(id: string): Promise<Artifact>;
44
+ save(artifact: Artifact): Promise<Artifact>;
45
+ create?(input: Pick<Artifact, "name" | "kind">): Promise<Artifact>;
46
+ remove?(id: string): Promise<void>;
47
+ }
48
+ export interface InstanceRecord {
49
+ artifactId: string;
50
+ values: ValueBag;
51
+ common?: ValueBag;
52
+ tabCommon?: ValueBag;
53
+ }
54
+ export interface InstanceStore {
55
+ get(id: string): Promise<InstanceRecord>;
56
+ save(id: string, patch: { values?: ValueBag; common?: ValueBag; tabCommon?: ValueBag }): Promise<void>;
57
+ list?(artifactId?: string): Promise<{ id: string; artifactId: string }[]>;
58
+ create?(input: { artifactId: string }): Promise<{ id: string }>;
59
+ }
60
+ export interface VersionRev {
61
+ rev: string;
62
+ kind: string;
63
+ id: string;
64
+ at: string;
65
+ parent?: string | null;
66
+ by?: string | null;
67
+ note?: string | null;
68
+ files: Record<string, string>;
69
+ meta?: Record<string, unknown>;
70
+ }
71
+ export interface VersionStore {
72
+ log(kind: string, id: string): Promise<{ head: string | null; items: VersionRev[] }>;
73
+ get(rev: string): Promise<VersionRev>;
74
+ readFile(rev: string, path: string): Promise<Uint8Array>;
75
+ commit(input: {
76
+ kind: string;
77
+ id: string;
78
+ files?: Record<string, Uint8Array | string>;
79
+ by?: string;
80
+ note?: string;
81
+ meta?: Record<string, unknown>;
82
+ }): Promise<VersionRev>;
83
+ restore(kind: string, id: string, rev: string, by?: string): Promise<VersionRev>;
84
+ }
85
+ export interface FsStoreOptions {
86
+ driver: "fs";
87
+ root: string;
88
+ layout?: "content-addressed";
89
+ }
90
+ export type StoreDescriptor = { driver: "memory" } | FsStoreOptions;
91
+
92
+ export const ARTIFACT_FILE_META: "meta.json";
93
+ export const ARTIFACT_FILE_BODY: "body.ktl";
94
+ export const ARTIFACT_FILE_FILL: "faces/fill.ktl";
95
+ export const ARTIFACT_FILE_REPORT: "faces/report.ktl";
96
+ export function artifactToFiles(a: Artifact): Record<string, string>;
97
+ export function filesToArtifact(files: Record<string, string>, fallbackId?: string): Artifact;
98
+ export function filesEqual(a: Record<string, string>, b: Record<string, string>): boolean;
99
+
100
+ export function createMemoryArtifactStore(seed?: Artifact[]): ArtifactStore;
101
+ export function createMemoryInstanceStore(seed?: Record<string, InstanceRecord>): InstanceStore;
102
+ export function createMemoryVersionStore(artifacts: ArtifactStore): VersionStore;
103
+ export function createHttpArtifactStore(baseUrl: string): ArtifactStore;
104
+ export function createHttpInstanceStore(baseUrl: string): InstanceStore;
105
+ export function createHttpVersionStore(baseUrl: string): VersionStore;
106
+ export function isStoreInstance(v: unknown): boolean;
107
+
108
+ export type KtSku = "report" | "table";
109
+ export type KtColorScheme = "light" | "dark" | "system";
110
+ export type KtTypeScale = "sm" | "md" | "lg";
111
+ export type KtDensity = "compact" | "comfortable" | "spacious";
112
+ export type KtThemePresetId = "paper" | "blue" | "green" | "violet";
113
+ export type KtUiStyleId = "default" | "arco";
114
+ export type KtUiStyle = {
115
+ id: KtUiStyleId;
116
+ name: string;
117
+ token?: Record<string, unknown>;
118
+ components?: Record<string, unknown>;
119
+ };
120
+ export type KtChromeSlot =
121
+ | "pageBg"
122
+ | "headerBg"
123
+ | "border"
124
+ | "text"
125
+ | "textSecondary"
126
+ | "chromeBar"
127
+ | "chromeTab"
128
+ | "canvasPad"
129
+ | "previewHost";
130
+ export type KtChromeColors = Record<KtChromeSlot, string>;
131
+ export type KtThemeChrome = Partial<KtChromeColors> & { extra?: Record<string, string> };
132
+ export type KtColorPalette = { primary: string; success: string; warning: string; error: string };
133
+ export type KtThemePreset = {
134
+ id: KtThemePresetId;
135
+ name: string;
136
+ palette: KtColorPalette;
137
+ forms: { light: KtChromeColors; dark: KtChromeColors };
138
+ };
139
+ export interface KtTheme {
140
+ colorScheme?: KtColorScheme;
141
+ colorPrimary?: string;
142
+ colorSuccess?: string;
143
+ colorWarning?: string;
144
+ colorError?: string;
145
+ typeScale?: KtTypeScale;
146
+ density?: KtDensity;
147
+ radius?: number;
148
+ inheritHost?: boolean;
149
+ presetId?: KtThemePresetId;
150
+ chrome?: KtThemeChrome;
151
+ styleId?: KtUiStyleId;
152
+ }
153
+ export interface KtConfig {
154
+ sku: KtSku;
155
+ locale?: "zh-CN";
156
+ /** 商业授权串(kt1.<payload>.<sig>)。缺省 = 试用模式:预览/打印带水印。 */
157
+ license?: string;
158
+ storage: {
159
+ artifacts: ArtifactStore | { driver: "memory" } | FsStoreOptions;
160
+ instances?: InstanceStore | { driver: "memory" } | FsStoreOptions;
161
+ versions?: false | VersionStore | FsStoreOptions;
162
+ httpBaseUrl?: string;
163
+ };
164
+ versions?: { commitPolicy?: "promote" | "onSave"; kinds?: string[] };
165
+ ui?: { theme?: KtTheme; persistThemeKey?: string; licenseBanner?: boolean };
166
+ features?: {
167
+ master?: boolean;
168
+ fill?: boolean;
169
+ excelImport?: boolean;
170
+ sourceDrawer?: boolean;
171
+ formula?: boolean;
172
+ combo?: boolean;
173
+ versions?: boolean;
174
+ print?: boolean;
175
+ pdf?: boolean;
176
+ };
177
+ }
178
+ export interface ResolvedFeatures {
179
+ master: boolean;
180
+ fill: boolean;
181
+ excelImport: boolean;
182
+ sourceDrawer: boolean;
183
+ formula: boolean;
184
+ combo: boolean;
185
+ versions: boolean;
186
+ print: boolean;
187
+ pdf: boolean;
188
+ }
189
+ export function resolveFeatures(config: Pick<KtConfig, "sku" | "features">): ResolvedFeatures;
190
+ export function defaultKinds(config: KtConfig): string[];
191
+ export function versionsUiEnabled(config: KtConfig): boolean;
192
+ export function commitPolicyOf(config: KtConfig): "promote" | "onSave";
193
+ export function maybeCommitOnSave(
194
+ config: KtConfig,
195
+ versions: VersionStore | undefined,
196
+ saved: Artifact,
197
+ ): Promise<VersionRev | undefined>;
198
+ export function resolveStores(config: KtConfig): {
199
+ artifacts: ArtifactStore;
200
+ instances?: InstanceStore;
201
+ versions?: VersionStore;
202
+ };
203
+
204
+ export const KT_COLOR_PRIMARY: "#1677ff";
205
+ export const KT_COLOR_SUCCESS: "#52c41a";
206
+ export const KT_COLOR_WARNING: "#faad14";
207
+ export const KT_COLOR_ERROR: "#ff4d4f";
208
+ export const KT_INHERIT_HOST_DEFAULT: false;
209
+ export const DEFAULT_KT_PRESET_ID: "blue";
210
+ export const KT_THEME_PRESETS: readonly KtThemePreset[];
211
+ export const KT_CHROME_SLOTS: readonly KtChromeSlot[];
212
+ export const KT_CHROME_BG_SLOTS: readonly { key: KtChromeSlot; label: string }[];
213
+ export const KT_CHROME_CSS_VARS: Record<KtChromeSlot, string>;
214
+ export const FORMS_PAGE_BG: "var(--kt-forms-page-bg)";
215
+ export const FORMS_HEADER_BG: "var(--kt-forms-header-bg)";
216
+ export const FORMS_BORDER: "var(--kt-forms-border)";
217
+ export const FORMS_TEXT: "var(--kt-forms-text)";
218
+ export const FORMS_TEXT_SECONDARY: "var(--kt-forms-text-secondary)";
219
+ export const FORMS_CHROME_BAR: "var(--kt-forms-chrome-bar)";
220
+ export const FORMS_CHROME_TAB: "var(--kt-forms-chrome-tab)";
221
+ export const FORMS_CANVAS_PAD: "var(--kt-forms-canvas-pad)";
222
+ export const FORMS_PREVIEW_HOST: "var(--kt-forms-preview-host)";
223
+ export const DEFAULT_KT_UI_STYLE_ID: "default";
224
+ export const KT_UI_STYLES: readonly KtUiStyle[];
225
+ export function isKtUiStyleId(id: string): id is KtUiStyleId;
226
+ export function getKtUiStyle(id?: string): KtUiStyle;
227
+ export function isKtThemePresetId(id: string): id is KtThemePresetId;
228
+ export function getKtPreset(id?: string): KtThemePreset;
229
+ export function applyPresetToTheme(id: KtThemePresetId, prev: KtTheme): KtTheme;
230
+ export function mergeThemePatch(prev: KtTheme, patch: Partial<KtTheme>): KtTheme;
231
+ export function hydrateTheme(base: KtTheme, saved: Partial<KtTheme>): KtTheme;
232
+ export function resolveChrome(theme: KtTheme, scheme: "light" | "dark"): KtChromeColors;
233
+ export function chromeToCssVars(chrome: KtChromeColors, extra?: Record<string, string>): Record<string, string>;
234
+
235
+ export type KtThemeApi = {
236
+ theme: KtTheme;
237
+ scheme: "light" | "dark";
238
+ chrome: KtChromeColors;
239
+ setTheme: (patch: Partial<KtTheme>) => void;
240
+ applyPreset: (id: KtThemePresetId) => void;
241
+ applyStyle: (id: KtUiStyleId) => void;
242
+ };
243
+
244
+ export function KtProvider(props: {
245
+ config: KtConfig;
246
+ onThemeChange?: (theme: KtTheme) => void;
247
+ children: ReactNode;
248
+ }): JSX.Element;
249
+ export function useKt(): {
250
+ config: KtConfig;
251
+ stores: { artifacts: ArtifactStore; instances?: InstanceStore; versions?: VersionStore };
252
+ theme: KtTheme;
253
+ setTheme: (patch: Partial<KtTheme>) => void;
254
+ applyPreset: (id: KtThemePresetId) => void;
255
+ applyStyle: (id: KtUiStyleId) => void;
256
+ scheme: "light" | "dark";
257
+ chrome: KtChromeColors;
258
+ kinds: string[];
259
+ versionsUi: boolean;
260
+ features: ResolvedFeatures;
261
+ license: KtLicenseInfo;
262
+ };
263
+ export function useKtOptional(): ReturnType<typeof useKt> | null;
264
+ export function useKtTheme(): KtThemeApi;
265
+
266
+ export type KtLicenseStatus = "valid" | "missing" | "invalid" | "expired" | "domain-mismatch";
267
+ export interface KtLicensePayload {
268
+ customer: string;
269
+ expires: string;
270
+ sku: string[];
271
+ domains?: string[];
272
+ iat?: string;
273
+ note?: string;
274
+ }
275
+ export interface KtLicenseInfo {
276
+ status: KtLicenseStatus;
277
+ payload?: KtLicensePayload;
278
+ reason?: string;
279
+ }
280
+ export function verifyKtLicense(
281
+ license: string | undefined | null,
282
+ opts: { sku: KtSku; hostname?: string | null; now?: Date; publicKey?: string },
283
+ ): KtLicenseInfo;
284
+ export function useKtLicense(): KtLicenseInfo;
285
+ export function KtLicenseBanner(): JSX.Element | null;
286
+
287
+ export function readArtifactAtRev(store: VersionStore, rev: string): Promise<Artifact>;
288
+ export function KtVersionPanel(props: {
289
+ open: boolean;
290
+ kind: string;
291
+ id: string;
292
+ onClose: () => void;
293
+ onRestored?: () => void;
294
+ }): JSX.Element | null;
295
+
296
+ export type DesignerFormField = {
297
+ fieldId: string;
298
+ fieldCode: string;
299
+ label: string;
300
+ dataType: string;
301
+ sort: number;
302
+ formula?: string | null;
303
+ tableRelation?: number;
304
+ };
305
+ export function withSplitFaces(artifact: Artifact, workbook: unknown): Artifact;
306
+ export function previewKtlOf(artifact: Artifact): string;
307
+ export function KtReportDesigner(props: {
308
+ artifact?: Artifact;
309
+ artifactId?: string;
310
+ store?: ArtifactStore;
311
+ masters?: { id: string; name: string }[];
312
+ values?: Record<string, unknown>;
313
+ formFields?: DesignerFormField[];
314
+ sheetFaceEnabled?: boolean;
315
+ onSave?: (a: Artifact) => void;
316
+ onConflict?: (e: KtConflictError) => void;
317
+ extraActions?: ReactNode;
318
+ leadingActions?: ReactNode;
319
+ }): JSX.Element;
320
+ export function KtReportPreview(props: {
321
+ artifact?: Artifact;
322
+ artifactId?: string;
323
+ store?: ArtifactStore;
324
+ rev?: string;
325
+ values?: ValueBag;
326
+ common?: ValueBag;
327
+ print?: boolean;
328
+ showVersionPanel?: boolean;
329
+ extraActions?: ReactNode;
330
+ }): JSX.Element;
331
+ export function KtReportCatalog(props: {
332
+ store?: ArtifactStore;
333
+ kinds?: ArtifactKind[];
334
+ onOpenDesign: (id: string) => void;
335
+ onOpenPreview: (id: string) => void;
336
+ }): JSX.Element;
337
+ export function KtThemeBar(props?: { variant?: "default" | "onPrimary" }): JSX.Element;
338
+ export function KtBrandBar(props: { title: string; themeBar?: boolean }): JSX.Element;
339
+
340
+ export const EMPTY_KTL: string;
341
+ export const SAMPLE_A4_KTL: string;
342
+ export const SAMPLE_DEMO_KTL: string;
343
+ export const SAMPLE_MASTER_KTL: string;
344
+
345
+ export function composeKtlForPreview(
346
+ ktl: string,
347
+ fetchMasterKtl: (masterId: string) => Promise<string | null>,
348
+ ): Promise<{ workbook: unknown; masterId?: string; composed: boolean; error?: string }>;