ht-emr 0.6.2 → 0.6.3

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.
@@ -1,6 +1,6 @@
1
1
  import './assets/css/index.css';
2
2
  import { IEditorData, IEditorOption, IEditorResult, IFormModeTraceOption } from './interface/Editor';
3
- import { IElement, IMacroConfig, IMacroElement, IGetMacroValueOption, IMacroValueResult, ISetMacroValueOption, IUpdateMacroPropertiesOption, ISubTemplateElement } from './interface/Element';
3
+ import { IElement, IMacroConfig, IMacroElement, ILogicTemplateDisplayRule, ILogicTemplateElement, IGetMacroValueOption, IMacroValueResult, ISetMacroValueOption, IUpdateMacroPropertiesOption, ISubTemplateElement } from './interface/Element';
4
4
  import { Command } from './core/command/Command';
5
5
  import { Listener } from './core/listener/Listener';
6
6
  import { RowFlex } from './dataset/enum/Row';
@@ -40,24 +40,82 @@ import { AreaMode } from './dataset/enum/Area';
40
40
  import { IBadge } from './interface/Badge';
41
41
  import { WatermarkType } from './dataset/enum/Watermark';
42
42
  import { INTERNAL_SHORTCUT_KEY } from './dataset/constant/Shortcut';
43
+ /**
44
+ * Canvas编辑器主类
45
+ *
46
+ * 这是编辑器的入口点,提供:
47
+ * - 编辑器实例创建和销毁
48
+ * - 命令执行接口(通过command属性)
49
+ * - 事件监听和事件总线
50
+ * - 插件扩展机制
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const editor = new Editor(container, data, options);
55
+ * editor.command.executeBold(); // 执行加粗命令
56
+ * editor.listener.contentChange = () => { }; // 监听内容变化
57
+ * editor.destroy(); // 销毁编辑器
58
+ * ```
59
+ */
43
60
  export default class Editor {
61
+ /** 命令执行器,提供所有编辑操作的接口 */
44
62
  command: Command;
63
+ /** 编辑器版本号 */
45
64
  version: string;
65
+ /** 事件监听器,用于设置各种回调函数 */
46
66
  listener: Listener;
67
+ /** 事件总线,用于发布/订阅编辑器事件 */
47
68
  eventBus: EventBus<EventBusMap>;
69
+ /** 覆盖器,用于自定义内部行为 */
48
70
  override: Override;
71
+ /** 注册器,用于注册自定义菜单、快捷键等 */
49
72
  register: Register;
73
+ /** 销毁编辑器的方法 */
50
74
  destroy: () => void;
75
+ /** 插件使用方法 */
51
76
  use: UsePlugin;
77
+ /** 核心渲染引擎 */
52
78
  private draw;
79
+ /**
80
+ * 创建编辑器实例
81
+ *
82
+ * @param container - 编辑器容器元素
83
+ * @param data - 编辑器数据,可以是元素数组或包含header/main/footer的对象
84
+ * @param options - 编辑器配置选项
85
+ */
53
86
  constructor(container: HTMLDivElement, data: IEditorData | IElement[], options?: IEditorOption);
87
+ /**
88
+ * 设置表单模式追踪选项
89
+ * @param payload - 表单模式追踪配置
90
+ */
54
91
  setFormModeTrace(payload: IFormModeTraceOption): void;
92
+ /**
93
+ * 暂停用户交互
94
+ *
95
+ * 调用后编辑器将不响应用户输入事件。
96
+ */
55
97
  pauseInteraction(): void;
98
+ /**
99
+ * 恢复用户交互
100
+ *
101
+ * 恢复编辑器对用户输入事件的响应。
102
+ */
56
103
  resumeInteraction(): void;
104
+ /**
105
+ * 设置覆盖层激活状态
106
+ *
107
+ * 当外部模态框、下拉菜单等覆盖层打开时调用。
108
+ *
109
+ * @param payload - 是否激活
110
+ */
57
111
  setOverlayActive(payload: boolean): void;
112
+ /**
113
+ * 暂停/恢复全局快捷键
114
+ * @param payload - true暂停,false恢复
115
+ */
58
116
  suspendGlobalShortcut(payload: boolean): void;
59
117
  }
60
118
  export { splitText, createDomFromElementList, getElementListByHTML, getTextFromElementList };
61
119
  export { EDITOR_COMPONENT, LETTER_CLASS, INTERNAL_CONTEXT_MENU_KEY, INTERNAL_SHORTCUT_KEY, EDITOR_CLIPBOARD };
62
120
  export { Editor, RowFlex, VerticalAlign, EditorZone, EditorMode, ElementType, ControlType, EditorComponent, PageMode, RenderMode, ImageDisplay, Command, KeyMap, BlockType, PaperDirection, TableBorder, TdBorder, TdSlash, MaxHeightRatio, NumberType, TitleLevel, ListType, ListStyle, WordBreak, ControlIndentation, ControlComponent, BackgroundRepeat, BackgroundSize, TextDecorationStyle, LineNumberType, LocationPosition, AreaMode, ControlState, FlexDirection, WatermarkType };
63
- export type { IElement, IEditorData, IEditorOption, IEditorResult, IFormModeTraceOption, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, IBadge, IGetElementListByHTMLOption, IMacroConfig, IMacroElement, IGetMacroValueOption, IMacroValueResult, ISetMacroValueOption, IUpdateMacroPropertiesOption, ISubTemplateElement };
121
+ export type { IElement, IEditorData, IEditorOption, IEditorResult, IFormModeTraceOption, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, IBadge, IGetElementListByHTMLOption, IMacroConfig, IMacroElement, ILogicTemplateDisplayRule, ILogicTemplateElement, IGetMacroValueOption, IMacroValueResult, ISetMacroValueOption, IUpdateMacroPropertiesOption, ISubTemplateElement };
@@ -16,6 +16,7 @@ import { ITitle } from './Title';
16
16
  import { IColgroup } from './table/Colgroup';
17
17
  import { ITr } from './table/Tr';
18
18
  import { VerticalAlign } from '../dataset/enum/VerticalAlign';
19
+ import { EditorMode } from '../dataset/enum/Editor';
19
20
  export interface IElementBasic {
20
21
  id?: string;
21
22
  type?: ElementType;
@@ -256,6 +257,31 @@ export interface IReusableItemElement {
256
257
  /** 复用项目配置 */
257
258
  reusableItemConfig?: IReusableItemConfig;
258
259
  }
260
+ export type LogicTemplateValueSource = 'auto' | 'control' | 'macro';
261
+ export interface ILogicTemplateDisplayRule {
262
+ /** 用于匹配值的字段,默认按控件 label / 宏 label / dictCode / 元素 id 自动查找 */
263
+ field: string;
264
+ /** 正则表达式字符串 */
265
+ regexp: string;
266
+ /** 正则标志,例如 i、g */
267
+ flags?: string;
268
+ /** 取值来源,默认 auto */
269
+ source?: LogicTemplateValueSource;
270
+ /** 生效模式,默认 [FORM, PRINT] */
271
+ modes?: Array<EditorMode.FORM | EditorMode.PRINT>;
272
+ }
273
+ export interface ILogicTemplateElement {
274
+ /** 逻辑模板分组 ID */
275
+ logicTemplateId?: string;
276
+ /** 逻辑模板名称 */
277
+ logicTemplateName?: string;
278
+ /** 逻辑模板引用的模板 ID */
279
+ logicTemplateTemplateId?: string;
280
+ /** 显示规则 */
281
+ logicTemplateDisplayRule?: ILogicTemplateDisplayRule;
282
+ /** 当前模式下是否被逻辑模板规则隐藏 */
283
+ logicTemplateHidden?: boolean;
284
+ }
259
285
  /**
260
286
  * 子模板元素属性接口
261
287
  * Sub template element properties interface
@@ -268,7 +294,7 @@ export interface ISubTemplateElement {
268
294
  /** 子模板是否展开(表单模式下使用) */
269
295
  subTemplateExpanded?: boolean;
270
296
  }
271
- export type IElement = IElementBasic & IElementStyle & IElementRule & IElementGroup & ITable & IHyperlinkElement & ISuperscriptSubscript & ISeparator & IControlElement & ICheckboxElement & IRadioElement & ILaTexElement & IDateElement & IImageElement & IBlockElement & ITitleElement & IListElement & IAreaElement & ILabelElement & IMenstrualHistoryElement & IFetalHeartPositionElement & IToothPositionElement & IMacroElement & IReusableItemElement & ISubTemplateElement;
297
+ export type IElement = IElementBasic & IElementStyle & IElementRule & IElementGroup & ITable & IHyperlinkElement & ISuperscriptSubscript & ISeparator & IControlElement & ICheckboxElement & IRadioElement & ILaTexElement & IDateElement & IImageElement & IBlockElement & ITitleElement & IListElement & IAreaElement & ILabelElement & IMenstrualHistoryElement & IFetalHeartPositionElement & IToothPositionElement & IMacroElement & IReusableItemElement & ILogicTemplateElement & ISubTemplateElement;
272
298
  export interface IElementMetrics {
273
299
  width: number;
274
300
  height: number;
@@ -69,5 +69,7 @@ export declare function getIsBlockElement(element?: IElement): boolean;
69
69
  export declare function replaceHTMLElementTag(oldDom: HTMLElement, tagName: keyof HTMLElementTagNameMap): HTMLElement;
70
70
  export declare function pickSurroundElementList(elementList: IElement[]): IElement[];
71
71
  export declare function deleteSurroundElementList(elementList: IElement[], pageNo: number): void;
72
+ export declare function isElementHidden(element?: IElement | null): boolean;
73
+ export declare function isElementVisible(element?: IElement | null): boolean;
72
74
  export declare function getNonHideElementIndex(elementList: IElement[], index: number, position?: LocationPosition): number;
73
75
  export {};
@@ -0,0 +1,9 @@
1
+ import { EditorMode } from '../dataset/enum/Editor';
2
+ import { IElement, ILogicTemplateDisplayRule, ILogicTemplateElement } from '../interface/Element';
3
+ export declare const LOGIC_TEMPLATE_DEFAULT_MODES: readonly [EditorMode.FORM, EditorMode.PRINT];
4
+ export interface ILogicTemplateMeta extends Pick<ILogicTemplateElement, 'logicTemplateId' | 'logicTemplateName' | 'logicTemplateTemplateId' | 'logicTemplateDisplayRule'> {
5
+ }
6
+ export declare function visitLogicTemplateElements(elementList: IElement[], visitor: (element: IElement) => void): void;
7
+ export declare function applyLogicTemplateMeta(elementList: IElement[], meta: ILogicTemplateMeta): void;
8
+ export declare function collectLogicTemplateList(elementList: IElement[]): ILogicTemplateElement[];
9
+ export declare function isLogicTemplateModeMatched(rule: ILogicTemplateDisplayRule | undefined, mode: EditorMode): boolean;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "ht-emr",
3
3
  "author": "swj",
4
4
  "license": "MIT",
5
- "version": "0.6.2",
5
+ "version": "0.6.3",
6
6
  "description": "rich text editor by canvas/svg",
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org/",