@hmg-report-editor/core 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.
Files changed (49) hide show
  1. package/dist/editor/ReportEditorCore.d.ts +137 -0
  2. package/dist/editor/createReportEditor.d.ts +3 -0
  3. package/dist/extensions/DropdownFieldNode.d.ts +15 -0
  4. package/dist/extensions/FontSizeExtension.d.ts +11 -0
  5. package/dist/extensions/HiddenParagraphExtension.d.ts +11 -0
  6. package/dist/extensions/IndentationExtension.d.ts +13 -0
  7. package/dist/extensions/LineHeightExtension.d.ts +12 -0
  8. package/dist/extensions/PageBreakNode.d.ts +11 -0
  9. package/dist/extensions/ReportNumberedBlockNode.d.ts +10 -0
  10. package/dist/extensions/StructuredFieldNode.d.ts +15 -0
  11. package/dist/extensions/TextColorExtension.d.ts +11 -0
  12. package/dist/extensions/VisibilityGroupMark.d.ts +6 -0
  13. package/dist/extensions/index.d.ts +29 -0
  14. package/dist/group/ReportEditorGroupManager.d.ts +45 -0
  15. package/dist/history/SharedHistoryManager.d.ts +96 -0
  16. package/dist/identity/ControlIdentityService.d.ts +48 -0
  17. package/dist/identity/PageBreakIdentityService.d.ts +29 -0
  18. package/dist/identity/VisibilityGroupIdentityService.d.ts +24 -0
  19. package/dist/index.cjs +5 -0
  20. package/dist/index.d.ts +7 -0
  21. package/dist/index.js +5326 -0
  22. package/dist/nodeViews/BaseControlNodeView.d.ts +82 -0
  23. package/dist/nodeViews/ControlClipboard.d.ts +10 -0
  24. package/dist/nodeViews/ControlInputAutosize.d.ts +2 -0
  25. package/dist/nodeViews/DropdownFieldNodeView.d.ts +57 -0
  26. package/dist/nodeViews/FieldNodeViews.d.ts +4 -0
  27. package/dist/nodeViews/PageBreakNodeView.d.ts +20 -0
  28. package/dist/nodeViews/StructuredFieldNodeView.d.ts +24 -0
  29. package/dist/plugins/ControlGapCursor.d.ts +21 -0
  30. package/dist/plugins/ControlSelectionLifecycle.d.ts +3 -0
  31. package/dist/plugins/ControlShortcuts.d.ts +40 -0
  32. package/dist/plugins/ControlTransactionMeta.d.ts +10 -0
  33. package/dist/plugins/NumberingPlugin.d.ts +15 -0
  34. package/dist/plugins/NumberingService.d.ts +29 -0
  35. package/dist/plugins/PasteSanitizer.d.ts +32 -0
  36. package/dist/registry/ReportFeatureRegistry.d.ts +16 -0
  37. package/dist/registry/builtinReportNodes.d.ts +19 -0
  38. package/dist/selection/SelectionManager.d.ts +18 -0
  39. package/dist/serializer/ReportSerializer.d.ts +57 -0
  40. package/dist/serializer/VisibilityGroupResolver.d.ts +20 -0
  41. package/dist/template/ReportTemplateEngine.d.ts +41 -0
  42. package/dist/types/index.d.ts +401 -0
  43. package/dist/utils/ReportErrorDispatcher.d.ts +13 -0
  44. package/dist/utils/controlAttrs.d.ts +10 -0
  45. package/dist/utils/controlTextSegments.d.ts +15 -0
  46. package/dist/utils/html.d.ts +33 -0
  47. package/dist/utils/reportDocument.d.ts +11 -0
  48. package/dist/utils/reportDocumentValidation.d.ts +16 -0
  49. package/package.json +37 -0
@@ -0,0 +1,401 @@
1
+ /** core 包共享类型,定义报告文档、模板、编辑器实例和扩展协议。 */
2
+ import type { Editor, Extensions } from '@tiptap/core';
3
+ import type { ReportEditorGroupManager } from '../group/ReportEditorGroupManager.js';
4
+ /** HTML 导出模式:编辑、预览和打印。 */
5
+ export type HtmlOutputMode = 'edit' | 'preview' | 'print';
6
+ /** 纯文本导出配置。 */
7
+ export type ReportPlainTextOptions = {
8
+ hideVisibilityGroups?: boolean;
9
+ };
10
+ /** 条件隐藏组当前支持的判定语义。 */
11
+ export type VisibilityGroupCondition = 'all-controls-empty';
12
+ /** 运行时 visibilityGroup mark 的稳定身份与判定条件。 */
13
+ export type VisibilityGroupMarkAttrs = {
14
+ groupId: string;
15
+ condition: VisibilityGroupCondition;
16
+ };
17
+ /** 结构化控件可保存的基础值类型。 */
18
+ export type StructuredFieldValue = string | number | boolean | null;
19
+ /** 报告控件值的语义别名。 */
20
+ export type ReportControlValue = StructuredFieldValue;
21
+ /** 结构化控件的键盘快捷键配置。 */
22
+ export type ReportControlShortcutOptions = {
23
+ enabled?: boolean;
24
+ nextControl?: string;
25
+ previousControl?: string;
26
+ openDropdown?: string;
27
+ closeDropdown?: string;
28
+ nextDropdownOption?: string;
29
+ previousDropdownOption?: string;
30
+ selectDropdownOption?: string;
31
+ submitInput?: string;
32
+ autoFocusNextOnEnter?: boolean;
33
+ };
34
+ /** 结构化控件规则条件配置。 */
35
+ export type ReportControlRulePremise = {
36
+ condition: string;
37
+ conditionDes?: string;
38
+ conditionRange?: {
39
+ symbol1?: string;
40
+ symbol2?: string;
41
+ number1?: string | number;
42
+ number2?: string | number;
43
+ };
44
+ entryType: 'input' | 'math';
45
+ inputSerialMath: string;
46
+ };
47
+ /** 结构化控件规则结果配置。 */
48
+ export type ReportControlRuleResult = {
49
+ type: 'content' | 'math' | string;
50
+ value: string;
51
+ style?: boolean;
52
+ bStyle?: boolean;
53
+ styleValue?: string;
54
+ exact?: boolean;
55
+ exactNum?: number;
56
+ exactType?: '1' | '2' | '3' | string;
57
+ };
58
+ /** 一组前提条件和对应结果。兼容历史 premiss 命名。 */
59
+ export type ReportControlRuleContent = {
60
+ premises?: ReportControlRulePremise[];
61
+ premiss?: ReportControlRulePremise[];
62
+ result: ReportControlRuleResult;
63
+ };
64
+ /** 单个结构化控件规则。兼容历史 list 命名。 */
65
+ export type ReportControlRule = {
66
+ title: string;
67
+ contents?: ReportControlRuleContent[];
68
+ list?: ReportControlRuleContent[];
69
+ };
70
+ /** ProseMirror mark 的序列化形态。 */
71
+ export type ProseMirrorMark = {
72
+ type: string;
73
+ attrs?: Record<string, unknown>;
74
+ };
75
+ /** 结构化控件内部富文本分段。 */
76
+ export type ReportControlTextSegment = {
77
+ text: string;
78
+ marks?: ProseMirrorMark[];
79
+ };
80
+ /** ProseMirror node 的轻量 JSON 形态。 */
81
+ export type ProseMirrorNode = {
82
+ type: string;
83
+ attrs?: Record<string, unknown>;
84
+ content?: ProseMirrorNode[];
85
+ text?: string;
86
+ marks?: ProseMirrorMark[];
87
+ };
88
+ /** 报告编辑器对外保存的权威 JSON 文档。 */
89
+ export type ReportDocument = {
90
+ version: string;
91
+ type: 'doc';
92
+ content: ProseMirrorNode[];
93
+ };
94
+ /** 下拉控件的选项项。 */
95
+ export type DropdownOption = {
96
+ label: string;
97
+ value: string;
98
+ };
99
+ /** 所有结构化控件共享的属性。 */
100
+ export type ReportControlAttrs = {
101
+ controlId?: string;
102
+ batchId?: string;
103
+ templateId?: string;
104
+ widgetNumber?: string;
105
+ fieldId: string;
106
+ fieldName: string;
107
+ value: StructuredFieldValue;
108
+ defaultValue?: StructuredFieldValue;
109
+ placeholder?: string;
110
+ required?: boolean;
111
+ hideWhenEmpty?: boolean;
112
+ noMatchDefault?: boolean;
113
+ rules?: ReportControlRule[];
114
+ nextWidgetNumber?: string;
115
+ ruleStyleColor?: string | null;
116
+ } & Record<string, unknown>;
117
+ export type StructuredFieldAttrs = ReportControlAttrs;
118
+ /** 下拉控件属性,扩展共享控件属性并携带可选项。 */
119
+ export type DropdownFieldAttrs = StructuredFieldAttrs & {
120
+ options: DropdownOption[];
121
+ allowCustomText?: boolean;
122
+ };
123
+ /** 隐藏段落的节点属性。 */
124
+ export type HiddenParagraphAttrs = {
125
+ hidden: boolean;
126
+ };
127
+ /** 编号块的节点属性。 */
128
+ export type NumberedBlockAttrs = {
129
+ number?: string;
130
+ manualNumber?: boolean;
131
+ };
132
+ /** 手动分页符持久化属性。 */
133
+ export type ReportPageBreakAttrs = {
134
+ id: string;
135
+ };
136
+ /** 手动分页符在当前文档中的定位快照。 */
137
+ export type ReportPageBreakSnapshot = {
138
+ id: string;
139
+ pos: number;
140
+ };
141
+ /** 模板段落节点。 */
142
+ export type TemplateParagraphNode = {
143
+ type: 'paragraph';
144
+ hidden?: boolean;
145
+ content?: TemplateNode[];
146
+ };
147
+ /** 模板文本节点。 */
148
+ export type TemplateTextNode = {
149
+ type: 'text';
150
+ text: string;
151
+ marks?: ProseMirrorMark[];
152
+ };
153
+ /** 模板结构化输入控件节点。 */
154
+ export type TemplateStructuredFieldNode = {
155
+ type: 'structuredField';
156
+ attrs: StructuredFieldAttrs;
157
+ };
158
+ /** 模板下拉控件节点。 */
159
+ export type TemplateDropdownFieldNode = {
160
+ type: 'dropdownField';
161
+ attrs: DropdownFieldAttrs;
162
+ };
163
+ /** 模板编号块节点。 */
164
+ export type TemplateNumberedBlockNode = {
165
+ type: 'numberedBlock';
166
+ attrs?: NumberedBlockAttrs;
167
+ content?: TemplateNode[];
168
+ };
169
+ /** 模板期条件隐藏组;编译后展平为带 visibilityGroup mark 的行内节点。 */
170
+ export type TemplateVisibilityGroupNode = {
171
+ type: 'visibilityGroup';
172
+ attrs?: {
173
+ condition?: VisibilityGroupCondition;
174
+ };
175
+ content: TemplateNode[];
176
+ };
177
+ /** 模板中的手动分页符,每次应用时生成新的实例 ID。 */
178
+ export type TemplatePageBreakNode = {
179
+ type: 'pageBreak';
180
+ };
181
+ /** 业务方通过 feature 扩展的自定义模板节点。 */
182
+ export type TemplateCustomNode<TAttrs extends Record<string, unknown> = Record<string, unknown>> = {
183
+ type: string;
184
+ attrs?: TAttrs;
185
+ content?: TemplateNode[];
186
+ text?: string;
187
+ marks?: ProseMirrorMark[];
188
+ };
189
+ /** 当前模板支持的节点联合类型。 */
190
+ export type TemplateNode = TemplateParagraphNode | TemplateTextNode | TemplateStructuredFieldNode | TemplateDropdownFieldNode | TemplateNumberedBlockNode | TemplateVisibilityGroupNode | TemplatePageBreakNode | TemplateCustomNode;
191
+ /** 后端或业务系统传入编辑器的报告模板。 */
192
+ export type ReportTemplate = {
193
+ version: string;
194
+ title?: string;
195
+ content: TemplateNode[];
196
+ };
197
+ /** 编辑器内部和对外事件使用的错误码。 */
198
+ export type ReportEditorErrorCode = 'INVALID_DOCUMENT' | 'TEMPLATE_PARSE_FAILED' | 'INVALID_FIELD_CONFIG' | 'DROPDOWN_OPTION_NOT_FOUND' | 'PASTE_SANITIZE_FAILED' | 'SELECTION_RESTORE_FAILED' | 'UNSUPPORTED_SERIALIZATION' | 'CONTROL_PLUGIN_FAILED' | 'CONTROL_RULE_FAILED' | 'COMMAND_FAILED';
199
+ /** 编辑器错误或警告事件。 */
200
+ export type ReportEditorError = {
201
+ code: ReportEditorErrorCode;
202
+ level: 'warning' | 'error';
203
+ message: string;
204
+ detail?: unknown;
205
+ };
206
+ /** 文档变更时对外派发的数据。 */
207
+ export type ReportChangePayload = {
208
+ json: ReportDocument;
209
+ html: string;
210
+ tiptapEditor: Editor;
211
+ };
212
+ /** 选区变更时对外派发的数据。 */
213
+ export type ReportSelectionPayload = {
214
+ from: number;
215
+ to: number;
216
+ empty: boolean;
217
+ };
218
+ /** 编辑器内单个结构化控件的快照。 */
219
+ export type ReportControlSnapshot = {
220
+ editorId: string;
221
+ nodeType: string;
222
+ controlId: string;
223
+ attrs: ReportControlAttrs;
224
+ pos: number;
225
+ };
226
+ /** 控件生命周期插件可使用的编辑器上下文。 */
227
+ export type ReportControlPluginContext = {
228
+ editorId: string;
229
+ editor: Editor;
230
+ getControl(controlId: string): ReportControlSnapshot | undefined;
231
+ getControls(): ReportControlSnapshot[];
232
+ updateControlAttrs(controlId: string, attrs: Partial<ReportControlAttrs>): boolean;
233
+ warn(code: ReportEditorErrorCode, message: string, detail?: unknown): void;
234
+ };
235
+ /** 控件生命周期插件收到的变更信息。 */
236
+ export type ReportControlChangePayload = {
237
+ previous: ReportControlSnapshot;
238
+ current: ReportControlSnapshot;
239
+ };
240
+ /** 结构化控件插件协议。 */
241
+ export type ReportControlPlugin = {
242
+ name?: string;
243
+ getCurrentBatchId?: () => string | undefined;
244
+ onEditorReady?: (context: ReportControlPluginContext) => void;
245
+ onEditorDestroyed?: (context: ReportControlPluginContext) => void;
246
+ onControlAdded?: (control: ReportControlSnapshot, context: ReportControlPluginContext) => void;
247
+ onControlRemoved?: (control: ReportControlSnapshot, context: ReportControlPluginContext) => void;
248
+ onControlValueChanged?: (change: ReportControlChangePayload, context: ReportControlPluginContext) => void;
249
+ onControlMetadataChanged?: (change: ReportControlChangePayload, context: ReportControlPluginContext) => void;
250
+ };
251
+ /** 创建 core 编辑器实例的配置。 */
252
+ export type ReportEditorOptions = {
253
+ editorId?: string;
254
+ element?: HTMLElement;
255
+ content?: ReportDocument | string;
256
+ template?: ReportTemplate;
257
+ features?: ReportFeatureDescriptor[];
258
+ controlPlugins?: ReportControlPlugin[];
259
+ editorGroup?: ReportEditorGroupManager;
260
+ controlShortcuts?: ReportControlShortcutOptions;
261
+ readonly?: boolean;
262
+ documentVersion?: string;
263
+ emitInitialContent?: boolean;
264
+ onChange?: (payload: ReportChangePayload) => void;
265
+ onSelectionChange?: (payload: ReportSelectionPayload) => void;
266
+ onReady?: (instance: ReportEditorInstance) => void;
267
+ onError?: (error: ReportEditorError) => void;
268
+ };
269
+ /** core 编辑器实例对外暴露的命令和查询 API。 */
270
+ export type ReportEditorInstance = {
271
+ getEditorId(): string;
272
+ getTiptapEditor(): Editor;
273
+ focus(): void;
274
+ destroy(): void;
275
+ undo(): boolean;
276
+ redo(): boolean;
277
+ getJSON(): ReportDocument;
278
+ getHTML(mode?: HtmlOutputMode): string;
279
+ getPlainText(options?: ReportPlainTextOptions): string;
280
+ setContent(content: ReportDocument | string): void;
281
+ clearContent(): void;
282
+ applyTemplate(template: ReportTemplate): boolean;
283
+ appendTemplate(template: ReportTemplate): boolean;
284
+ insertControl(nodeType: string, attrs: ReportControlAttrs): boolean;
285
+ updateControlAttrs(controlId: string, attrs: Partial<ReportControlAttrs>): boolean;
286
+ updateControlValue(controlId: string, value: StructuredFieldValue): boolean;
287
+ updateControlValueByFieldName(fieldName: string, value: StructuredFieldValue): boolean;
288
+ getControls(): ReportControlSnapshot[];
289
+ getControl(controlId: string): ReportControlSnapshot | undefined;
290
+ insertPageBreak(): boolean;
291
+ deletePageBreak(id?: string): boolean;
292
+ getPageBreaks(): ReportPageBreakSnapshot[];
293
+ toggleHiddenParagraph(): boolean;
294
+ setParagraphHidden(hidden: boolean): boolean;
295
+ moveNumberedBlock(fromIndex: number, toIndex: number): boolean;
296
+ setEditable(editable: boolean): void;
297
+ };
298
+ /** 可恢复选区的快照。 */
299
+ export type SavedSelection = {
300
+ from: number;
301
+ to: number;
302
+ anchor: number;
303
+ head: number;
304
+ timestamp: number;
305
+ };
306
+ /** 跨编辑器共享历史的一条变更记录。 */
307
+ export type SharedHistoryEntry = {
308
+ editorId: string;
309
+ before: ReportDocument;
310
+ after: ReportDocument;
311
+ timestamp: number;
312
+ label?: string;
313
+ };
314
+ /** 共享历史状态变更 payload。 */
315
+ export type SharedHistoryChangePayload = {
316
+ canUndo: boolean;
317
+ canRedo: boolean;
318
+ undoDepth: number;
319
+ redoDepth: number;
320
+ activeEditorId?: string;
321
+ };
322
+ /** 共享历史管理器配置。 */
323
+ export type SharedHistoryManagerOptions = {
324
+ /** 单个撤销/重做栈最多保留的记录数,默认 30,最大 30。 */
325
+ maxDepth?: number;
326
+ editorGroup?: ReportEditorGroupManager;
327
+ onChange?: (payload: SharedHistoryChangePayload) => void;
328
+ onRestore?: (entry: SharedHistoryEntry, direction: 'undo' | 'redo') => void;
329
+ };
330
+ /** 传给 Tiptap 的 doc JSON。 */
331
+ export type TiptapDocument = {
332
+ type: 'doc';
333
+ content?: ProseMirrorNode[];
334
+ };
335
+ /** 自定义节点模板校验上下文。 */
336
+ export type ReportTemplateValidationContext = {
337
+ validateChildren(nodes: TemplateNode[] | undefined): void;
338
+ };
339
+ /** 自定义节点模板转 ProseMirror 时的上下文。 */
340
+ export type ReportTemplateConversionContext = {
341
+ toContent(nodes: TemplateNode[] | undefined): ProseMirrorNode[];
342
+ withFreshControlId<TAttrs extends ReportControlAttrs>(attrs: TAttrs): TAttrs;
343
+ };
344
+ /** 自定义节点和 mark 渲染 HTML 时的上下文。 */
345
+ export type ReportHtmlRenderContext = {
346
+ mode: HtmlOutputMode;
347
+ renderContent(content: ProseMirrorNode[] | undefined, mode?: HtmlOutputMode): string;
348
+ renderBlockAttrs(node: ProseMirrorNode, className: string): string;
349
+ warn(code: ReportEditorErrorCode, message: string, detail?: unknown): void;
350
+ };
351
+ /** 自定义节点和 mark 渲染纯文本时的上下文。 */
352
+ export type ReportPlainTextRenderContext = {
353
+ hideVisibilityGroups: boolean;
354
+ renderContent(content: ProseMirrorNode[] | undefined): string;
355
+ warn(code: ReportEditorErrorCode, message: string, detail?: unknown): void;
356
+ };
357
+ /** 单个报告节点的扩展描述。 */
358
+ export type ReportNodeDescriptor = {
359
+ nodeName: string;
360
+ templateType: string;
361
+ dataNode?: string;
362
+ extension: Extensions[number];
363
+ isInline?: boolean;
364
+ isControl?: boolean;
365
+ supportsBlockFormatting?: boolean;
366
+ isNumberedBlock?: boolean;
367
+ validateAttrs?: (attrs: Record<string, unknown>) => void;
368
+ validateTemplate?: (node: TemplateCustomNode, context: ReportTemplateValidationContext) => void;
369
+ toProseMirrorNode?: (node: TemplateCustomNode, context: ReportTemplateConversionContext) => ProseMirrorNode;
370
+ renderHTML?: (node: ProseMirrorNode, context: ReportHtmlRenderContext) => string;
371
+ renderText?: (node: ProseMirrorNode, context: ReportPlainTextRenderContext) => string;
372
+ };
373
+ /** 单个报告 mark 的序列化描述。 */
374
+ export type ReportMarkDescriptor = {
375
+ markName: string;
376
+ validateAttrs?: (attrs: Record<string, unknown>) => void;
377
+ renderHTML?: (mark: ProseMirrorMark, html: string, context: ReportHtmlRenderContext) => string;
378
+ renderText?: (mark: ProseMirrorMark, text: string, context: ReportPlainTextRenderContext) => string;
379
+ };
380
+ /** 一组可插拔报告能力的描述。 */
381
+ export type ReportFeatureDescriptor = {
382
+ name: string;
383
+ extensions?: Extensions;
384
+ nodes?: ReportNodeDescriptor[];
385
+ marks?: ReportMarkDescriptor[];
386
+ };
387
+ /** feature 注册表对模板、序列化和扩展工厂提供的查询接口。 */
388
+ export type ReportFeatureRegistry = {
389
+ features(): ReportFeatureDescriptor[];
390
+ descriptors(): ReportNodeDescriptor[];
391
+ markDescriptors(): ReportMarkDescriptor[];
392
+ extensions(): Extensions;
393
+ getByNodeName(nodeName: string): ReportNodeDescriptor | undefined;
394
+ getByTemplateType(templateType: string): ReportNodeDescriptor | undefined;
395
+ getMarkDescriptor(markName: string): ReportMarkDescriptor | undefined;
396
+ isControlNode(nodeName: string): boolean;
397
+ isNumberedBlockNode(nodeName: string): boolean;
398
+ controlNodeNames(): string[];
399
+ blockFormattingNodeNames(): string[];
400
+ numberedBlockNodeNames(): string[];
401
+ };
@@ -0,0 +1,13 @@
1
+ import type { ReportEditorError } from '../types/index.js';
2
+ /** 统一派发编辑器警告和错误事件。 */
3
+ export declare class ReportErrorDispatcher {
4
+ private readonly listener?;
5
+ /** 创建错误派发器并绑定可选监听器。 */
6
+ constructor(listener?: ((error: ReportEditorError) => void) | undefined);
7
+ /** 派发 warning 级别事件。 */
8
+ warning(code: ReportEditorError['code'], message: string, detail?: unknown): void;
9
+ /** 派发 error 级别事件。 */
10
+ error(code: ReportEditorError['code'], message: string, detail?: unknown): void;
11
+ /** 调用外部错误监听器。 */
12
+ private emit;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { DropdownOption, StructuredFieldValue } from '../types/index.js';
2
+ export type SerializedControlValueType = 'string' | 'number' | 'boolean' | 'null';
3
+ /** 判断值是否符合结构化控件的持久化值类型。 */
4
+ export declare function isStructuredFieldValue(value: unknown): value is StructuredFieldValue;
5
+ /** 生成 edit HTML 中用于无损恢复控件值的类型标签。 */
6
+ export declare function controlValueType(value: unknown): SerializedControlValueType;
7
+ /** 从 edit HTML 的字符串属性恢复结构化控件值。 */
8
+ export declare function parseTypedControlValue(value: string | null, type: string | null): StructuredFieldValue;
9
+ /** 将未知下拉选项输入归一为可安全渲染的选项数组。 */
10
+ export declare function normalizeDropdownOptions(value: unknown): DropdownOption[];
@@ -0,0 +1,15 @@
1
+ import type { ProseMirrorMark, ReportControlTextSegment, StructuredFieldValue } from '../types/index.js';
2
+ /** 安全解析控件内部富文本分段 JSON。 */
3
+ export declare function parseControlTextSegments(value: string | null): ReportControlTextSegment[] | undefined;
4
+ /** 将控件值和可选分段归一为可渲染分段。 */
5
+ export declare function normalizeControlTextSegments(value: StructuredFieldValue | undefined, segments: unknown): ReportControlTextSegment[];
6
+ /** 序列化控件内部富文本分段,空分段不输出。 */
7
+ export declare function serializeControlTextSegments(segments: ReportControlTextSegment[] | undefined): string | undefined;
8
+ /** 从分段中读取纯文本。 */
9
+ export declare function controlTextFromSegments(segments: ReportControlTextSegment[]): string;
10
+ /** 将分段渲染为内置富文本 HTML。 */
11
+ export declare function renderControlTextSegmentsHTML(segments: ReportControlTextSegment[], fallbackText: StructuredFieldValue | undefined): string;
12
+ /** 判断两组 marks 是否等价。 */
13
+ export declare function sameControlTextMarks(left: ProseMirrorMark[] | undefined, right: ProseMirrorMark[] | undefined): boolean;
14
+ /** 合并相邻且 marks 相同的分段。 */
15
+ export declare function mergeAdjacentSegments(segments: ReportControlTextSegment[]): ReportControlTextSegment[];
@@ -0,0 +1,33 @@
1
+ import type { StructuredFieldValue } from '../types/index.js';
2
+ /** HTML 转义工具。 */
3
+ export declare class HtmlEscaper {
4
+ /** 转义文本节点内容。 */
5
+ static text(value: unknown): string;
6
+ /** 转义 HTML 属性值。 */
7
+ static attr(value: unknown): string;
8
+ }
9
+ /** 构建安全 style 属性字符串的工具。 */
10
+ export declare class HtmlStyleBuilder {
11
+ private readonly declarations;
12
+ /** 添加非空字符串或有限数字样式声明。 */
13
+ add(name: string, value: unknown): this;
14
+ /** 添加经过 CSS 值白名单校验的样式声明。 */
15
+ addSafe(name: string, value: unknown): this;
16
+ /** 输出完整 style 属性字符串。 */
17
+ toAttribute(): string;
18
+ }
19
+ /** CSS 样式值白名单清洗工具。 */
20
+ export declare class CssValueSanitizer {
21
+ /** 按 CSS 属性名清洗单个样式值,非法值返回 undefined。 */
22
+ static sanitize(name: string, value: unknown): string | undefined;
23
+ private static hasUnsafeSyntax;
24
+ private static isSafeColor;
25
+ private static isSafeLength;
26
+ private static isSafeNumber;
27
+ private static isSafeFontFamily;
28
+ }
29
+ /** 结构化控件值判断工具。 */
30
+ export declare class FieldValue {
31
+ /** 判断控件值是否为空。 */
32
+ static isEmpty(value: StructuredFieldValue | undefined): boolean;
33
+ }
@@ -0,0 +1,11 @@
1
+ import type { ReportDocument, TiptapDocument } from '../types/index.js';
2
+ export declare const DEFAULT_REPORT_DOCUMENT_VERSION = "1.0.3";
3
+ /** 报告文档和 Tiptap doc JSON 的转换工具。 */
4
+ export declare class ReportDocumentMapper {
5
+ /** 将报告文档转换为 Tiptap setContent 可接受的内容。 */
6
+ static toTiptapContent(content: ReportDocument | string | undefined): TiptapDocument | string | undefined;
7
+ /** 将 Tiptap JSON 包装为报告文档。 */
8
+ static fromTiptapJSON(json: unknown, version?: string): ReportDocument;
9
+ /** 创建空报告文档。 */
10
+ static empty(version?: string): ReportDocument;
11
+ }
@@ -0,0 +1,16 @@
1
+ import type { Schema } from '@tiptap/pm/model';
2
+ import type { ReportDocument, ReportEditorErrorCode, ReportFeatureRegistry } from '../types/index.js';
3
+ /** 文档输入校验失败,携带应派发给业务方的错误码。 */
4
+ export declare class ReportDocumentValidationError extends Error {
5
+ readonly code: ReportEditorErrorCode;
6
+ readonly detail?: unknown | undefined;
7
+ constructor(code: ReportEditorErrorCode, message: string, detail?: unknown | undefined);
8
+ }
9
+ /** 校验报告文档根结构和版本。 */
10
+ export declare function assertReportDocumentRoot(value: unknown, expectedVersion: string): asserts value is ReportDocument;
11
+ /** 校验文档节点的 JSON 形态和所有结构化控件 attrs。 */
12
+ export declare function validateReportDocumentNodes(document: ReportDocument, registry: ReportFeatureRegistry): void;
13
+ /** 使用 ProseMirror schema 做严格内容模型校验。 */
14
+ export declare function validateProseMirrorDocument(document: ReportDocument, schema: Schema): void;
15
+ /** 将任意 ProseMirror JSON 包装成报告文档后执行完整校验。 */
16
+ export declare function validateReportDocument(document: ReportDocument, registry: ReportFeatureRegistry, schema: Schema): void;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@hmg-report-editor/core",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "vite build && tsc -p tsconfig.build.json && node ../../scripts/finalize-package-types.mjs .",
24
+ "typecheck": "tsc -p tsconfig.json --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "@tiptap/core": "^2.12.0",
28
+ "@tiptap/extension-font-family": "^2.12.0",
29
+ "@tiptap/extension-text-style": "^2.12.0",
30
+ "@tiptap/extension-underline": "^2.12.0",
31
+ "@tiptap/pm": "^2.12.0",
32
+ "@tiptap/starter-kit": "^2.12.0"
33
+ },
34
+ "peerDependencies": {
35
+ "@tiptap/core": "^2.12.0"
36
+ }
37
+ }