@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.
- package/dist/editor/ReportEditorCore.d.ts +137 -0
- package/dist/editor/createReportEditor.d.ts +3 -0
- package/dist/extensions/DropdownFieldNode.d.ts +15 -0
- package/dist/extensions/FontSizeExtension.d.ts +11 -0
- package/dist/extensions/HiddenParagraphExtension.d.ts +11 -0
- package/dist/extensions/IndentationExtension.d.ts +13 -0
- package/dist/extensions/LineHeightExtension.d.ts +12 -0
- package/dist/extensions/PageBreakNode.d.ts +11 -0
- package/dist/extensions/ReportNumberedBlockNode.d.ts +10 -0
- package/dist/extensions/StructuredFieldNode.d.ts +15 -0
- package/dist/extensions/TextColorExtension.d.ts +11 -0
- package/dist/extensions/VisibilityGroupMark.d.ts +6 -0
- package/dist/extensions/index.d.ts +29 -0
- package/dist/group/ReportEditorGroupManager.d.ts +45 -0
- package/dist/history/SharedHistoryManager.d.ts +96 -0
- package/dist/identity/ControlIdentityService.d.ts +48 -0
- package/dist/identity/PageBreakIdentityService.d.ts +29 -0
- package/dist/identity/VisibilityGroupIdentityService.d.ts +24 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5326 -0
- package/dist/nodeViews/BaseControlNodeView.d.ts +82 -0
- package/dist/nodeViews/ControlClipboard.d.ts +10 -0
- package/dist/nodeViews/ControlInputAutosize.d.ts +2 -0
- package/dist/nodeViews/DropdownFieldNodeView.d.ts +57 -0
- package/dist/nodeViews/FieldNodeViews.d.ts +4 -0
- package/dist/nodeViews/PageBreakNodeView.d.ts +20 -0
- package/dist/nodeViews/StructuredFieldNodeView.d.ts +24 -0
- package/dist/plugins/ControlGapCursor.d.ts +21 -0
- package/dist/plugins/ControlSelectionLifecycle.d.ts +3 -0
- package/dist/plugins/ControlShortcuts.d.ts +40 -0
- package/dist/plugins/ControlTransactionMeta.d.ts +10 -0
- package/dist/plugins/NumberingPlugin.d.ts +15 -0
- package/dist/plugins/NumberingService.d.ts +29 -0
- package/dist/plugins/PasteSanitizer.d.ts +32 -0
- package/dist/registry/ReportFeatureRegistry.d.ts +16 -0
- package/dist/registry/builtinReportNodes.d.ts +19 -0
- package/dist/selection/SelectionManager.d.ts +18 -0
- package/dist/serializer/ReportSerializer.d.ts +57 -0
- package/dist/serializer/VisibilityGroupResolver.d.ts +20 -0
- package/dist/template/ReportTemplateEngine.d.ts +41 -0
- package/dist/types/index.d.ts +401 -0
- package/dist/utils/ReportErrorDispatcher.d.ts +13 -0
- package/dist/utils/controlAttrs.d.ts +10 -0
- package/dist/utils/controlTextSegments.d.ts +15 -0
- package/dist/utils/html.d.ts +33 -0
- package/dist/utils/reportDocument.d.ts +11 -0
- package/dist/utils/reportDocumentValidation.d.ts +16 -0
- package/package.json +37 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { NodeViewRendererProps } from '@tiptap/core';
|
|
2
|
+
import { type Node as ProseMirrorNode } from '@tiptap/pm/model';
|
|
3
|
+
import type { NodeView } from '@tiptap/pm/view';
|
|
4
|
+
import type { StructuredFieldAttrs, StructuredFieldValue } from '../types/index.js';
|
|
5
|
+
import { type ControlNavigationDirection, type ReportControlShortcutRuntime } from '../plugins/ControlShortcuts.js';
|
|
6
|
+
export type FieldNodeName = 'structuredField' | 'dropdownField' | string;
|
|
7
|
+
/** 控件 NodeView 基类,统一处理选择、拖拽、剪贴板和快捷键导航。 */
|
|
8
|
+
export declare abstract class BaseControlNodeView<TAttrs extends StructuredFieldAttrs> implements NodeView {
|
|
9
|
+
protected readonly props: NodeViewRendererProps;
|
|
10
|
+
protected readonly nodeName: FieldNodeName;
|
|
11
|
+
protected readonly controlShortcutRuntime: ReportControlShortcutRuntime;
|
|
12
|
+
readonly dom: HTMLElement;
|
|
13
|
+
protected node: ProseMirrorNode;
|
|
14
|
+
private selected;
|
|
15
|
+
private editable;
|
|
16
|
+
/** 创建控件根 DOM 并绑定通用交互事件。 */
|
|
17
|
+
constructor(props: NodeViewRendererProps, nodeName: FieldNodeName, controlShortcutRuntime?: ReportControlShortcutRuntime);
|
|
18
|
+
/** 接收 ProseMirror 节点更新并重新同步 DOM。 */
|
|
19
|
+
update(node: ProseMirrorNode): boolean;
|
|
20
|
+
/** 标记整个控件节点被 ProseMirror 选中。 */
|
|
21
|
+
selectNode(): void;
|
|
22
|
+
/** 清除整个控件节点的选中态。 */
|
|
23
|
+
deselectNode(): void;
|
|
24
|
+
/** 决定事件由控件内部处理还是交给 ProseMirror。 */
|
|
25
|
+
stopEvent(event: Event): boolean;
|
|
26
|
+
/** 忽略控件内部 DOM 变化,状态以节点 attrs 为准。 */
|
|
27
|
+
ignoreMutation(): boolean;
|
|
28
|
+
/** 返回当前节点属性的强类型视图。 */
|
|
29
|
+
protected get attrs(): TAttrs;
|
|
30
|
+
/** 同步控件焦点样式和数据属性。 */
|
|
31
|
+
protected setFocused(focused: boolean): void;
|
|
32
|
+
/** 将控件输入值提交回 ProseMirror 节点 attrs。 */
|
|
33
|
+
protected commitValue(value: StructuredFieldValue): void;
|
|
34
|
+
/** 完成当前输入,并按配置跳转到下一个控件。 */
|
|
35
|
+
protected completeInputAndMaybeFocusNext(event: KeyboardEvent): boolean;
|
|
36
|
+
/** 从当前控件出发移动焦点到相邻控件。 */
|
|
37
|
+
protected focusAdjacentControlFromCurrent(direction: ControlNavigationDirection, selectText?: boolean): boolean;
|
|
38
|
+
/** 同步根元素上的控件身份、空值、只读和拖拽状态。 */
|
|
39
|
+
protected syncRootAttributes(): void;
|
|
40
|
+
/** 判断控件值是否应被视为空值。 */
|
|
41
|
+
protected isValueEmpty(value: StructuredFieldValue | undefined): boolean;
|
|
42
|
+
/** 处理控件内部输入元素上的快捷键导航。 */
|
|
43
|
+
private handleShortcutKeyDown;
|
|
44
|
+
/** 将单个控件写入剪贴板。 */
|
|
45
|
+
private copyControl;
|
|
46
|
+
/** 剪切单个控件并从文档中删除节点。 */
|
|
47
|
+
private cutControl;
|
|
48
|
+
/** 根据点击目标进入控件编辑或整节点选择。 */
|
|
49
|
+
private handleMouseDown;
|
|
50
|
+
/** 控件内部获得焦点时释放整节点选择。 */
|
|
51
|
+
private handleFocusIn;
|
|
52
|
+
/** 将当前控件设为 NodeSelection 以支持整节点拖拽。 */
|
|
53
|
+
private selectNodeForDrag;
|
|
54
|
+
/** 从整节点选择切回临近文本选区,允许编辑控件内部输入。 */
|
|
55
|
+
private releaseNodeSelectionForControlEditing;
|
|
56
|
+
/** 判断鼠标事件是否应该触发整节点选择。 */
|
|
57
|
+
private shouldSelectNodeFromEvent;
|
|
58
|
+
/** 判断方向键是否已经到达输入边界并可跳转控件。 */
|
|
59
|
+
private shouldNavigateFromInteractiveTarget;
|
|
60
|
+
/** 判断事件目标是否为控件内部可交互元素。 */
|
|
61
|
+
private isInteractiveTarget;
|
|
62
|
+
/** 判断事件是否属于拖拽流程。 */
|
|
63
|
+
private isDragEvent;
|
|
64
|
+
/** 生成控件 HTML 和纯文本并写入剪贴板。 */
|
|
65
|
+
private writeControlToClipboard;
|
|
66
|
+
/** Deletes an empty control and restores the editor caret at the removed node position. */
|
|
67
|
+
private deleteEmptyControlFromInput;
|
|
68
|
+
/** 允许子类追加节点特有的剪贴板属性。 */
|
|
69
|
+
protected decorateClipboardElement(_element: HTMLSpanElement): void;
|
|
70
|
+
/** 返回控件根元素 class。 */
|
|
71
|
+
protected abstract rootClassName(): string;
|
|
72
|
+
/** 返回控件聚焦态 class。 */
|
|
73
|
+
protected abstract focusedClassName(): string;
|
|
74
|
+
/** 返回控件选中态 class。 */
|
|
75
|
+
protected abstract selectedClassName(): string;
|
|
76
|
+
/** 返回 data-report-node 使用的节点名。 */
|
|
77
|
+
protected abstract reportNodeName(): string;
|
|
78
|
+
/** 返回复制到纯文本剪贴板的展示文本。 */
|
|
79
|
+
protected abstract clipboardText(): string;
|
|
80
|
+
/** 根据当前 attrs 重新渲染控件内部 DOM。 */
|
|
81
|
+
protected abstract renderControl(): void;
|
|
82
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StructuredFieldAttrs } from '../types/index.js';
|
|
2
|
+
/** 控件剪贴板工具,负责生成可被编辑器重新识别的 HTML。 */
|
|
3
|
+
export declare class ControlClipboard {
|
|
4
|
+
/** 判断输入框内部是否已有文本选区,避免覆盖原生复制。 */
|
|
5
|
+
static hasSelectedInputText(target: EventTarget | null): boolean;
|
|
6
|
+
/** 写入控件 HTML 和纯文本到剪贴板。 */
|
|
7
|
+
static write(event: ClipboardEvent, element: HTMLElement, text: string): boolean;
|
|
8
|
+
/** 根据控件属性创建剪贴板 HTML 元素。 */
|
|
9
|
+
static createElement(attrs: StructuredFieldAttrs, rootClassName: string, reportNodeName: string, text: string): HTMLSpanElement;
|
|
10
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NodeViewRendererProps } from '@tiptap/core';
|
|
2
|
+
import type { DropdownFieldAttrs } from '../types/index.js';
|
|
3
|
+
import { type ReportControlShortcutRuntime } from '../plugins/ControlShortcuts.js';
|
|
4
|
+
import { BaseControlNodeView } from './BaseControlNodeView.js';
|
|
5
|
+
/** 下拉控件的 NodeView,支持输入文本和选项菜单。 */
|
|
6
|
+
export declare class DropdownFieldNodeView extends BaseControlNodeView<DropdownFieldAttrs> {
|
|
7
|
+
private readonly combo;
|
|
8
|
+
private readonly input;
|
|
9
|
+
private readonly menu;
|
|
10
|
+
private open;
|
|
11
|
+
private activeOptionIndex;
|
|
12
|
+
private menuPortaled;
|
|
13
|
+
/** 创建输入框和菜单 DOM。 */
|
|
14
|
+
constructor(props: NodeViewRendererProps, controlShortcutRuntime: ReportControlShortcutRuntime);
|
|
15
|
+
/** Removes a portaled menu and its page-level listeners with the NodeView. */
|
|
16
|
+
destroy(): void;
|
|
17
|
+
/** 返回根元素 class。 */
|
|
18
|
+
protected rootClassName(): string;
|
|
19
|
+
/** 返回聚焦态 class。 */
|
|
20
|
+
protected focusedClassName(): string;
|
|
21
|
+
/** 返回选中态 class。 */
|
|
22
|
+
protected selectedClassName(): string;
|
|
23
|
+
/** 返回序列化 HTML 中的报告节点名。 */
|
|
24
|
+
protected reportNodeName(): string;
|
|
25
|
+
/** 生成复制下拉控件时的纯文本展示值。 */
|
|
26
|
+
protected clipboardText(): string;
|
|
27
|
+
/** 将下拉选项和自定义输入开关写入剪贴板 HTML。 */
|
|
28
|
+
protected decorateClipboardElement(element: HTMLSpanElement): void;
|
|
29
|
+
/** 根据节点 attrs 同步输入框和菜单。 */
|
|
30
|
+
protected renderControl(): void;
|
|
31
|
+
/** 渲染下拉选项菜单并绑定选项提交。 */
|
|
32
|
+
private renderMenu;
|
|
33
|
+
/** 切换菜单展开状态。 */
|
|
34
|
+
private setOpen;
|
|
35
|
+
/** Ports the active menu to the document body so editor overflow cannot clip it. */
|
|
36
|
+
private mountMenu;
|
|
37
|
+
/** Returns a closed menu to the NodeView and releases global listeners. */
|
|
38
|
+
private unmountMenu;
|
|
39
|
+
/** Repositions the body-level menu after editor/page scrolling or viewport resizing. */
|
|
40
|
+
private readonly handleViewportChange;
|
|
41
|
+
/** Anchors the fixed menu to the combo, flipping above when the viewport requires it. */
|
|
42
|
+
private positionMenu;
|
|
43
|
+
/** 处理下拉选项切换、选中、展开和关闭快捷键。 */
|
|
44
|
+
private handleDropdownShortcut;
|
|
45
|
+
/** 使用方向键移动当前高亮选项。 */
|
|
46
|
+
private moveActiveOption;
|
|
47
|
+
/** 用键盘提交当前高亮选项。 */
|
|
48
|
+
private selectActiveOptionFromKeyboard;
|
|
49
|
+
/** 按当前值同步键盘高亮选项。 */
|
|
50
|
+
private syncActiveOptionFromValue;
|
|
51
|
+
/** 同步菜单选项的键盘高亮状态。 */
|
|
52
|
+
private syncActiveOptionState;
|
|
53
|
+
/** 根据当前输入文本同步自动显示长度。 */
|
|
54
|
+
private syncAutoWidth;
|
|
55
|
+
/** 将 attrs 中的选项归一化为数组。 */
|
|
56
|
+
private normalizeOptions;
|
|
57
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model';
|
|
2
|
+
import type { NodeViewRendererProps } from '@tiptap/core';
|
|
3
|
+
import type { NodeView } from '@tiptap/pm/view';
|
|
4
|
+
/** 分页符编辑态 NodeView,仅提供视觉提示和整体选中反馈。 */
|
|
5
|
+
export declare class PageBreakNodeView implements NodeView {
|
|
6
|
+
readonly dom: HTMLSpanElement;
|
|
7
|
+
private node;
|
|
8
|
+
private selected;
|
|
9
|
+
constructor(props: NodeViewRendererProps);
|
|
10
|
+
/** 同步分页符 ID。 */
|
|
11
|
+
update(node: ProseMirrorNode): boolean;
|
|
12
|
+
/** 显示整体选中样式。 */
|
|
13
|
+
selectNode(): void;
|
|
14
|
+
/** 清除整体选中样式。 */
|
|
15
|
+
deselectNode(): void;
|
|
16
|
+
/** 原子节点不接收 DOM 内容变更。 */
|
|
17
|
+
ignoreMutation(): boolean;
|
|
18
|
+
/** 渲染编辑态分隔线和提示文本。 */
|
|
19
|
+
private render;
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { NodeViewRendererProps } from '@tiptap/core';
|
|
2
|
+
import type { StructuredFieldAttrs } from '../types/index.js';
|
|
3
|
+
import type { ReportControlShortcutRuntime } from '../plugins/ControlShortcuts.js';
|
|
4
|
+
import { BaseControlNodeView } from './BaseControlNodeView.js';
|
|
5
|
+
/** 结构化输入控件的 NodeView。 */
|
|
6
|
+
export declare class StructuredFieldNodeView extends BaseControlNodeView<StructuredFieldAttrs> {
|
|
7
|
+
private readonly input;
|
|
8
|
+
/** 创建文本输入框并绑定值提交事件。 */
|
|
9
|
+
constructor(props: NodeViewRendererProps, controlShortcutRuntime: ReportControlShortcutRuntime);
|
|
10
|
+
/** 返回根元素 class。 */
|
|
11
|
+
protected rootClassName(): string;
|
|
12
|
+
/** 返回聚焦态 class。 */
|
|
13
|
+
protected focusedClassName(): string;
|
|
14
|
+
/** 返回选中态 class。 */
|
|
15
|
+
protected selectedClassName(): string;
|
|
16
|
+
/** 返回序列化 HTML 中的报告节点名。 */
|
|
17
|
+
protected reportNodeName(): string;
|
|
18
|
+
/** 生成复制结构化输入时的纯文本。 */
|
|
19
|
+
protected clipboardText(): string;
|
|
20
|
+
/** 根据节点 attrs 同步输入框内容和只读状态。 */
|
|
21
|
+
protected renderControl(): void;
|
|
22
|
+
/** 根据当前输入文本同步自动显示长度。 */
|
|
23
|
+
private syncAutoWidth;
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import type { EditorState, Transaction } from '@tiptap/pm/state';
|
|
3
|
+
import { type EditorView } from '@tiptap/pm/view';
|
|
4
|
+
/** 创建相邻行内控件间隙的鼠标光标映射扩展。 */
|
|
5
|
+
export declare function createControlGapCursorExtension(controlNodeNames?: string[]): Extension;
|
|
6
|
+
/** Marks a collapsed text selection that needs an explicit caret beside an atom control. */
|
|
7
|
+
export declare function showControlBoundaryCaret(transaction: Transaction, pos: number): Transaction;
|
|
8
|
+
/** Returns the document position of the temporary caret left by control deletion. */
|
|
9
|
+
export declare function getControlBoundaryCaretPosition(state: EditorState): number | null;
|
|
10
|
+
/** Clears a temporary boundary caret before keyboard focus moves into another control. */
|
|
11
|
+
export declare function clearControlBoundaryCaret(transaction: Transaction): Transaction;
|
|
12
|
+
/**
|
|
13
|
+
* 让 core 把间隙输入处理器作为 EditorView 直接 prop 安装。
|
|
14
|
+
* 直接 prop 先于 Tiptap 聚合的 input-rules 插件运行,防止规则按浏览器吸附位置提前消费输入。
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleControlGapTextInput(view: EditorView, from: number, to: number, text: string, defaultTransaction: () => Transaction): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 让 composition 生命周期先于 Tiptap input-rules 插件排队收尾,
|
|
19
|
+
* 确保规则是在文本回到规范边界后再检查最终输入。
|
|
20
|
+
*/
|
|
21
|
+
export declare function handleControlGapDOMEvent(view: EditorView, event: Event): boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import type { EditorView } from '@tiptap/pm/view';
|
|
3
|
+
import type { ReportEditorGroupManager } from '../group/ReportEditorGroupManager.js';
|
|
4
|
+
import type { ReportControlShortcutOptions } from '../types/index.js';
|
|
5
|
+
/** 控件快捷键导航方向。 */
|
|
6
|
+
export type ControlNavigationDirection = 'next' | 'previous';
|
|
7
|
+
/** 归一化后的控件快捷键配置。 */
|
|
8
|
+
export type ResolvedReportControlShortcuts = {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
nextControl: string;
|
|
11
|
+
previousControl: string;
|
|
12
|
+
openDropdown: string;
|
|
13
|
+
closeDropdown: string;
|
|
14
|
+
nextDropdownOption: string;
|
|
15
|
+
previousDropdownOption: string;
|
|
16
|
+
selectDropdownOption: string;
|
|
17
|
+
submitInput: string;
|
|
18
|
+
autoFocusNextOnEnter: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** 控件快捷键运行时依赖。 */
|
|
21
|
+
export type ReportControlShortcutRuntime = {
|
|
22
|
+
shortcuts: ResolvedReportControlShortcuts;
|
|
23
|
+
controlNodeNames: string[];
|
|
24
|
+
controlReportNodeNames: string[];
|
|
25
|
+
editorGroup?: ReportEditorGroupManager;
|
|
26
|
+
};
|
|
27
|
+
/** 创建控件快捷键运行时配置。 */
|
|
28
|
+
export declare function createReportControlShortcutRuntime(options?: ReportControlShortcutOptions, controlNodeNames?: string[], controlReportNodeNames?: string[], editorGroup?: ReportEditorGroupManager): ReportControlShortcutRuntime;
|
|
29
|
+
/** 合并业务配置和默认快捷键。 */
|
|
30
|
+
export declare function resolveReportControlShortcuts(options?: ReportControlShortcutOptions): ResolvedReportControlShortcuts;
|
|
31
|
+
/** 根据键盘事件解析控件导航方向。 */
|
|
32
|
+
export declare function controlNavigationDirectionFromEvent(event: KeyboardEvent, shortcuts: ResolvedReportControlShortcuts): ControlNavigationDirection | undefined;
|
|
33
|
+
/** 判断键盘事件是否匹配一个无修饰键快捷键。 */
|
|
34
|
+
export declare function matchesControlShortcut(event: KeyboardEvent, shortcutKey: string): boolean;
|
|
35
|
+
/** 判断键盘事件是否为左右方向键。 */
|
|
36
|
+
export declare function isHorizontalArrowKey(event: KeyboardEvent): boolean;
|
|
37
|
+
/** 在当前范围内移动焦点到上一个或下一个控件。 */
|
|
38
|
+
export declare function focusAdjacentControl(view: EditorView, currentPos: number, runtime: ReportControlShortcutRuntime, direction: ControlNavigationDirection, selectText?: boolean): boolean;
|
|
39
|
+
/** 创建处理整节点选中态快捷键的 ProseMirror 插件扩展。 */
|
|
40
|
+
export declare function createControlShortcutExtension(runtime: ReportControlShortcutRuntime): Extension;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Transaction } from '@tiptap/pm/state';
|
|
2
|
+
export type ControlAttrsTransactionMeta = {
|
|
3
|
+
controlIds: string[];
|
|
4
|
+
};
|
|
5
|
+
/** Marks a validated transaction that only changes attrs on existing controls. */
|
|
6
|
+
export declare function markControlAttrsTransaction(transaction: Transaction, controlIds: Iterable<string>): Transaction;
|
|
7
|
+
/** Reads and validates the internal existing-control attrs transaction marker. */
|
|
8
|
+
export declare function readControlAttrsTransaction(transaction: Transaction): ControlAttrsTransactionMeta | undefined;
|
|
9
|
+
/** True when every document-changing transaction is a validated control attrs update. */
|
|
10
|
+
export declare function onlyControlAttrsChanged(transactions: readonly Transaction[]): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin } from '@tiptap/pm/state';
|
|
2
|
+
import { Extension } from '@tiptap/core';
|
|
3
|
+
import { NumberingService } from './NumberingService.js';
|
|
4
|
+
/** 创建自动维护编号块的 ProseMirror 插件。 */
|
|
5
|
+
export declare class NumberingPluginFactory {
|
|
6
|
+
private readonly nodeName;
|
|
7
|
+
private readonly service;
|
|
8
|
+
/** 绑定编号节点名和编号服务。 */
|
|
9
|
+
constructor(nodeName?: string, service?: NumberingService);
|
|
10
|
+
/** 创建 appendTransaction 编号修复插件。 */
|
|
11
|
+
create(): Plugin;
|
|
12
|
+
}
|
|
13
|
+
/** 创建 Tiptap 编号扩展。 */
|
|
14
|
+
export declare function createNumberingExtension(nodeName?: string): Extension<any, any>;
|
|
15
|
+
export declare const NumberingExtension: Extension<any, any>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model';
|
|
3
|
+
import type { Transaction } from '@tiptap/pm/state';
|
|
4
|
+
/** 编号块需要写回的新编号。 */
|
|
5
|
+
export type NumberingUpdate = {
|
|
6
|
+
pos: number;
|
|
7
|
+
number: string;
|
|
8
|
+
};
|
|
9
|
+
/** 编号块在 ProseMirror 文档中的位置。 */
|
|
10
|
+
export type NumberedBlockPosition = {
|
|
11
|
+
pos: number;
|
|
12
|
+
node: ProseMirrorNode;
|
|
13
|
+
};
|
|
14
|
+
/** 编号块服务,负责收集、重排和写回自动编号。 */
|
|
15
|
+
export declare class NumberingService {
|
|
16
|
+
private readonly nodeName;
|
|
17
|
+
/** 绑定需要维护编号的节点名。 */
|
|
18
|
+
constructor(nodeName?: string);
|
|
19
|
+
/** 收集文档中所有编号块。 */
|
|
20
|
+
collectBlocks(doc: ProseMirrorNode): NumberedBlockPosition[];
|
|
21
|
+
/** 计算所有自动编号块需要更新的编号。 */
|
|
22
|
+
collectUpdates(doc: ProseMirrorNode): NumberingUpdate[];
|
|
23
|
+
/** 将编号更新写入已有事务。 */
|
|
24
|
+
applyToTransaction(tr: Transaction): Transaction;
|
|
25
|
+
/** 直接将编号更新应用到编辑器。 */
|
|
26
|
+
applyToEditor(editor: Editor, addToHistory?: boolean): boolean;
|
|
27
|
+
/** 按索引移动编号块并重新计算编号。 */
|
|
28
|
+
moveBlock(editor: Editor, fromIndex: number, toIndex: number): boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import type { ReportEditorGroupManager } from '../group/ReportEditorGroupManager.js';
|
|
3
|
+
import type { ReportFeatureRegistry } from '../types/index.js';
|
|
4
|
+
export type InvalidControlAttrsHandler = (detail: {
|
|
5
|
+
nodeName: string;
|
|
6
|
+
attrs: Record<string, unknown>;
|
|
7
|
+
error: unknown;
|
|
8
|
+
}) => void;
|
|
9
|
+
export type InvalidVisibilityGroupDetail = {
|
|
10
|
+
nodeName: string;
|
|
11
|
+
attrs: Record<string, unknown>;
|
|
12
|
+
error: unknown;
|
|
13
|
+
};
|
|
14
|
+
export type InvalidVisibilityGroupHandler = (detail: InvalidVisibilityGroupDetail) => void;
|
|
15
|
+
/** 粘贴 HTML 清洗器,保留安全标签、样式和报告 data 属性。 */
|
|
16
|
+
export declare class PasteSanitizer {
|
|
17
|
+
/** 清洗粘贴 HTML,浏览器环境优先使用 DOMParser。 */
|
|
18
|
+
sanitize(html: string): string;
|
|
19
|
+
/** 拒绝会在 schema 解析时静默丢失条件隐藏语义的旧或非法报告 HTML。 */
|
|
20
|
+
private assertSupportedReportMarkup;
|
|
21
|
+
/** 递归清洗子元素并扁平化不支持标签。 */
|
|
22
|
+
private sanitizeChildren;
|
|
23
|
+
/** 移除事件属性和非白名单属性。 */
|
|
24
|
+
private sanitizeAttributes;
|
|
25
|
+
/** 只保留安全的内联样式声明。 */
|
|
26
|
+
private sanitizeStyle;
|
|
27
|
+
/** 在没有 DOMParser 的环境下做保守字符串清洗。 */
|
|
28
|
+
private regexFallback;
|
|
29
|
+
}
|
|
30
|
+
/** 创建粘贴清洗和控件 ID/批次修复扩展。 */
|
|
31
|
+
export declare function createPasteSanitizerExtension(registry?: ReportFeatureRegistry, getCurrentBatchId?: () => string | undefined, onInvalidControlAttrs?: InvalidControlAttrsHandler, onInvalidVisibilityGroup?: InvalidVisibilityGroupHandler, editorGroup?: ReportEditorGroupManager): Extension<any, any>;
|
|
32
|
+
export declare const PasteSanitizerExtension: Extension<any, any>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReportFeatureDescriptor, ReportFeatureRegistry as ReportFeatureRegistryContract, ReportMarkDescriptor, ReportNodeDescriptor } from '../types/index.js';
|
|
2
|
+
/** 定义普通报告节点描述符,保留传入对象的精确类型。 */
|
|
3
|
+
export declare function defineReportNode<TDescriptor extends ReportNodeDescriptor>(descriptor: TDescriptor): TDescriptor;
|
|
4
|
+
/** 定义结构化控件节点描述符,并自动标记为控件。 */
|
|
5
|
+
export declare function defineReportControl<TDescriptor extends ReportNodeDescriptor>(descriptor: TDescriptor): TDescriptor & {
|
|
6
|
+
isControl: true;
|
|
7
|
+
isInline: TDescriptor extends {
|
|
8
|
+
isInline: infer TInline extends boolean;
|
|
9
|
+
} ? TInline : true;
|
|
10
|
+
};
|
|
11
|
+
/** 定义报告 mark 描述符,保留传入对象的精确类型。 */
|
|
12
|
+
export declare function defineReportMark<TDescriptor extends ReportMarkDescriptor>(descriptor: TDescriptor): TDescriptor;
|
|
13
|
+
/** 定义 feature 描述符,保留业务扩展的精确类型。 */
|
|
14
|
+
export declare function defineReportFeature<TDescriptor extends ReportFeatureDescriptor>(descriptor: TDescriptor): TDescriptor;
|
|
15
|
+
/** 创建包含内置 feature 和业务 feature 的注册表。 */
|
|
16
|
+
export declare function createReportFeatureRegistry(features?: ReportFeatureDescriptor[]): ReportFeatureRegistryContract;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReportFeatureDescriptor, ReportMarkDescriptor, ReportNodeDescriptor } from '../types/index.js';
|
|
2
|
+
/** 内置富文本 mark 的 HTML 和纯文本序列化规则。 */
|
|
3
|
+
export declare const builtinReportMarkDescriptors: ReportMarkDescriptor[];
|
|
4
|
+
/** 结构化输入控件的模板转换、校验和序列化描述。 */
|
|
5
|
+
export declare const structuredFieldDescriptor: ReportNodeDescriptor;
|
|
6
|
+
/** 下拉控件的模板转换、校验和序列化描述。 */
|
|
7
|
+
export declare const dropdownFieldDescriptor: ReportNodeDescriptor;
|
|
8
|
+
/** 报告编号块的模板转换、编号展示和纯文本描述。 */
|
|
9
|
+
export declare const reportNumberedBlockDescriptor: ReportNodeDescriptor;
|
|
10
|
+
/** 手动分页符模板转换和外部 HTML 合约。 */
|
|
11
|
+
export declare const pageBreakDescriptor: ReportNodeDescriptor;
|
|
12
|
+
/** 内置报告节点描述符集合。 */
|
|
13
|
+
export declare const builtinReportNodeDescriptors: ReportNodeDescriptor[];
|
|
14
|
+
/** 基础 Tiptap 能力和内置 mark feature。 */
|
|
15
|
+
export declare const builtinBaseFeature: ReportFeatureDescriptor;
|
|
16
|
+
/** 报告业务节点 feature。 */
|
|
17
|
+
export declare const builtinReportNodesFeature: ReportFeatureDescriptor;
|
|
18
|
+
/** 默认随 core 启用的全部 feature。 */
|
|
19
|
+
export declare const builtinReportFeatures: ReportFeatureDescriptor[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { SavedSelection } from '../types/index.js';
|
|
3
|
+
import { ReportErrorDispatcher } from '../utils/ReportErrorDispatcher.js';
|
|
4
|
+
/** 选区管理器,负责保存和安全恢复编辑器选区。 */
|
|
5
|
+
export declare class SelectionManager {
|
|
6
|
+
private readonly errors;
|
|
7
|
+
private savedSelection;
|
|
8
|
+
/** 创建选区管理器并绑定错误派发器。 */
|
|
9
|
+
constructor(errors?: ReportErrorDispatcher);
|
|
10
|
+
/** 保存当前编辑器选区。 */
|
|
11
|
+
save(editor: Editor): SavedSelection;
|
|
12
|
+
/** 尝试恢复指定选区,失败时回退到最近有效位置。 */
|
|
13
|
+
restore(editor: Editor, selection?: SavedSelection | null): boolean;
|
|
14
|
+
/** 将选区恢复到文档末尾附近。 */
|
|
15
|
+
restoreToDocumentEnd(editor: Editor): boolean;
|
|
16
|
+
/** 将位置限制在文档有效范围内。 */
|
|
17
|
+
private clamp;
|
|
18
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { HtmlOutputMode, ProseMirrorNode, ReportDocument, ReportFeatureRegistry, ReportPlainTextOptions } from '../types/index.js';
|
|
3
|
+
import { ReportErrorDispatcher } from '../utils/ReportErrorDispatcher.js';
|
|
4
|
+
/** 报告序列化器,负责 JSON、HTML 和纯文本输出。 */
|
|
5
|
+
export declare class ReportSerializer {
|
|
6
|
+
private readonly documentVersion;
|
|
7
|
+
private readonly errors;
|
|
8
|
+
private readonly registry;
|
|
9
|
+
/** 创建序列化器并绑定版本、错误派发器和 feature 注册表。 */
|
|
10
|
+
constructor(documentVersion?: string, errors?: ReportErrorDispatcher, registry?: ReportFeatureRegistry);
|
|
11
|
+
/** 从 Tiptap editor 导出报告 JSON。 */
|
|
12
|
+
toJSON(editor: Editor): ReportDocument;
|
|
13
|
+
/** 按编辑、预览或打印模式导出完整 HTML 外层。 */
|
|
14
|
+
toHTML(editor: Editor, mode?: HtmlOutputMode): string;
|
|
15
|
+
/** 从已导出的报告 JSON 渲染完整 HTML 外层,避免重复读取编辑器文档。 */
|
|
16
|
+
toHTMLFromJSON(json: ReportDocument, mode?: HtmlOutputMode): string;
|
|
17
|
+
/** 导出报告纯文本,供搜索、复制或后端摘要使用。 */
|
|
18
|
+
toPlainText(editor: Editor, options?: ReportPlainTextOptions): string;
|
|
19
|
+
/** 渲染一组 ProseMirror 节点为 HTML。 */
|
|
20
|
+
private renderContent;
|
|
21
|
+
/** 将单个 ProseMirror 节点分派到内置或自定义渲染器。 */
|
|
22
|
+
private renderNode;
|
|
23
|
+
/** 渲染段落并在预览/打印模式中过滤整段隐藏和条件隐藏产生的空段。 */
|
|
24
|
+
private renderParagraph;
|
|
25
|
+
/** 使用注册表中的 mark 描述符渲染内联格式。 */
|
|
26
|
+
private applyMark;
|
|
27
|
+
/** 读取节点唯一允许携带的 visibilityGroup mark。 */
|
|
28
|
+
private getVisibilityGroupMark;
|
|
29
|
+
/** 判断相邻成员是否属于同一分组,从而输出单一连续 wrapper。 */
|
|
30
|
+
private isSameVisibilityGroup;
|
|
31
|
+
/** 渲染块级节点通用 class、缩进和行高属性。 */
|
|
32
|
+
renderBlockAttrs(node: ProseMirrorNode, className: string): string;
|
|
33
|
+
/** 渲染列表结构,并清理分页符归一化后留下的空容器。 */
|
|
34
|
+
private renderStructuralContainer;
|
|
35
|
+
/** 判断报告节点子树是否包含分页符。 */
|
|
36
|
+
private containsPageBreak;
|
|
37
|
+
/** 判断子树是否包含被条件组过滤的成员,用于清理随空段留下的列表容器。 */
|
|
38
|
+
private containsHiddenVisibilityMember;
|
|
39
|
+
/** 只渲染隐藏内容树中的分页符,不输出被隐藏的正文或容器。 */
|
|
40
|
+
private renderPageBreaksOnly;
|
|
41
|
+
/** 计算 preview/print 中位于两段有效可见内容之间的首个分页符。 */
|
|
42
|
+
private collectRetainedPageBreakIds;
|
|
43
|
+
/** 按输出可见性将文档压缩成有效内容和分页符 token。 */
|
|
44
|
+
private collectOutputTokens;
|
|
45
|
+
/** 使用控件 descriptor 的真实 preview/print 输出判断其是否形成分页有效内容。 */
|
|
46
|
+
private rendersVisibleControlContent;
|
|
47
|
+
/** 归一化纯文本导出选项。 */
|
|
48
|
+
private normalizePlainTextOptions;
|
|
49
|
+
/** 渲染一组 ProseMirror 节点为纯文本。 */
|
|
50
|
+
private renderTextContent;
|
|
51
|
+
/** 将单个节点分派到纯文本渲染规则。 */
|
|
52
|
+
private renderTextNode;
|
|
53
|
+
/** 让自定义 mark 有机会转换纯文本输出。 */
|
|
54
|
+
private renderTextMarks;
|
|
55
|
+
/** 对同一未知节点或 mark 只派发一次序列化警告。 */
|
|
56
|
+
private warnUnsupported;
|
|
57
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ProseMirrorNode, ReportFeatureRegistry } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* 对整篇文档的条件隐藏组做一次预扫描。
|
|
4
|
+
*
|
|
5
|
+
* groupId 是全文身份,因此解析不依赖成员是否相邻、是否位于同一段落。
|
|
6
|
+
*/
|
|
7
|
+
export declare class VisibilityGroupResolver {
|
|
8
|
+
private readonly registry;
|
|
9
|
+
private readonly hiddenGroupIds;
|
|
10
|
+
constructor(content: ProseMirrorNode[] | undefined, registry: ReportFeatureRegistry);
|
|
11
|
+
/** 判断节点是否属于任一满足隐藏条件的分组。 */
|
|
12
|
+
isNodeHidden(node: ProseMirrorNode): boolean;
|
|
13
|
+
/** 判断节点是否携带 visibilityGroup 语义。 */
|
|
14
|
+
isGrouped(node: ProseMirrorNode): boolean;
|
|
15
|
+
/** 返回已判定隐藏的组 ID 快照,便于诊断和测试。 */
|
|
16
|
+
hiddenGroups(): ReadonlySet<string>;
|
|
17
|
+
private scan;
|
|
18
|
+
private groupMarks;
|
|
19
|
+
private isRawContent;
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { ReportDocument, ReportFeatureRegistry, ReportTemplate } from '../types/index.js';
|
|
3
|
+
import { ControlIdentityService } from '../identity/ControlIdentityService.js';
|
|
4
|
+
import { ReportErrorDispatcher } from '../utils/ReportErrorDispatcher.js';
|
|
5
|
+
/** 模板引擎,负责校验模板并转换为 ProseMirror 文档。 */
|
|
6
|
+
export declare class ReportTemplateEngine {
|
|
7
|
+
private readonly errors;
|
|
8
|
+
private readonly identity;
|
|
9
|
+
private readonly registry;
|
|
10
|
+
/** 创建模板引擎并绑定错误派发、控件身份和 feature 注册表。 */
|
|
11
|
+
constructor(errors?: ReportErrorDispatcher, identity?: ControlIdentityService, registry?: ReportFeatureRegistry);
|
|
12
|
+
/** 校验模板根结构和所有子节点。 */
|
|
13
|
+
validate(template: ReportTemplate): void;
|
|
14
|
+
/** 将业务模板转换为报告 JSON 文档。 */
|
|
15
|
+
toDocument(template: ReportTemplate, batchId?: string): ReportDocument;
|
|
16
|
+
/** 用模板生成的文档替换当前编辑器内容。 */
|
|
17
|
+
applyTemplate(editor: Editor, template: ReportTemplate, batchId?: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 将模板内容追加到当前选区之后。
|
|
20
|
+
*
|
|
21
|
+
* 折叠选区使用光标位置,非折叠选区使用 selection.to,绝不替换选中内容;
|
|
22
|
+
* 选区不可用时回退到文档末尾。成功后由 insertContentAt 将选区放到新增内容末端。
|
|
23
|
+
*/
|
|
24
|
+
appendTemplate(editor: Editor, template: ReportTemplate, batchId?: string): boolean;
|
|
25
|
+
/** 返回当前选区之后的插入位置;缺失、越界或不可解析时使用文档末尾。 */
|
|
26
|
+
private resolveAppendPosition;
|
|
27
|
+
/** 递归校验模板节点和自定义节点约束。 */
|
|
28
|
+
private validateNode;
|
|
29
|
+
/** 校验模板期条件隐藏组的位置、条件和 inline-only 内容约束。 */
|
|
30
|
+
private validateVisibilityGroup;
|
|
31
|
+
/** 根据内置文本或节点 descriptor 的能力声明判断模板节点是否为 inline。 */
|
|
32
|
+
private isInlineTemplateNode;
|
|
33
|
+
/** 将模板节点转换为 ProseMirror 节点 JSON。 */
|
|
34
|
+
private toProseMirrorNode;
|
|
35
|
+
/** 模板只能通过 visibilityGroup 容器创建运行时分组 mark。 */
|
|
36
|
+
private validateTemplateMarks;
|
|
37
|
+
/** 防止自定义 descriptor 绕过模板容器直接制造运行时 visibilityGroup mark。 */
|
|
38
|
+
private assertNoRuntimeVisibilityMarks;
|
|
39
|
+
/** 转换一组模板子节点。 */
|
|
40
|
+
private toContent;
|
|
41
|
+
}
|