@hailin-zheng/editor-core 2.2.2 → 2.2.4

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,7 +1,7 @@
1
1
  import { ContentMenuItem } from './framework/element-event-define';
2
2
  import { ElementReader } from './framework/element-reader';
3
3
  import { SelectionState } from './framework/selection/document-selection';
4
- import { BranchElement, Element, ICancelTokenFn, LeafElement, MarginProps, OrientType, PageLayoutMode, Position, Rect, SerializeProps, ViewOptions } from './framework/element-define';
4
+ import { BlockContainerElement, Element, ICancelTokenFn, LeafElement, MarginProps, OrientType, PageLayoutMode, Position, Rect, SerializeProps, ViewOptions } from './framework/element-define';
5
5
  import { DataElementInlineGroup, DataElementLeaf, DocumentElement, ParagraphElement, TableCellElement, TableElement, TableRowElement } from './framework/impl';
6
6
  import { CellDiagonal, ParagraphNumberType, ParagraphProps, TextProps } from './framework/element-props';
7
7
  import { EditorContext } from './framework/document-context';
@@ -10,8 +10,10 @@ import { Subject } from './framework/infrastructure/event-subject';
10
10
  import { init, VNode } from "snabbdom";
11
11
  import { IVNodeRenderFunc } from "./editor-core";
12
12
  import { DocRule } from "./doc-rule";
13
+ import { ISuggestionData, ISuggestionProvider } from './framework/suggestions/input-suggestions';
13
14
  export declare class DocEditor {
14
15
  private svgContainer;
16
+ __v_skip: boolean;
15
17
  private contentCtx;
16
18
  viewOptions: ViewOptions;
17
19
  docCtx: EditorContext;
@@ -43,14 +45,17 @@ export declare class DocEditor {
43
45
  onDestroy: Subject<void>;
44
46
  beforeNodePatch: Subject<void>;
45
47
  afterNodePatch: Subject<void>;
48
+ onTextChanged: Subject<void>;
49
+ onSuggestionsProcess: Subject<ISuggestionProvider>;
46
50
  private eventBus;
47
51
  private editInput;
48
52
  private scrollContainer;
53
+ onKeyDownEvent: Subject<KeyboardEvent>;
49
54
  constructor(svgContainer: HTMLElement);
50
55
  private createCanvasContext;
51
56
  private renderRoot;
52
57
  private updateViewOption;
53
- private adjustPageLayout;
58
+ adjustPageLayout(): void;
54
59
  private destroyDOM;
55
60
  createDocViewer(): void;
56
61
  measureMMToPixs(): number;
@@ -78,11 +83,16 @@ export declare class DocEditor {
78
83
  * @private
79
84
  */
80
85
  private updateSelection;
86
+ /**
87
+ * 根据当前选区,更新待输入文本字体信息
88
+ * @private
89
+ */
90
+ private updateInputFont;
81
91
  private hitInfoChanged;
82
92
  /**
83
93
  * 设置光标
84
94
  */
85
- private setCursor;
95
+ setCursor(): void;
86
96
  private getCursorRect;
87
97
  /**
88
98
  * 设置虚拟光标的可见性
@@ -174,6 +184,7 @@ export declare class DocEditor {
174
184
  * @param cols
175
185
  */
176
186
  insertTable(rows: number, cols: number): TableElement;
187
+ insertLayoutContainer(ele: BlockContainerElement): void;
177
188
  /**
178
189
  * 插入软换行符
179
190
  */
@@ -242,7 +253,7 @@ export declare class DocEditor {
242
253
  /**
243
254
  * 插入批注
244
255
  */
245
- insertComment(): void;
256
+ insertComment(text: string): void;
246
257
  /**
247
258
  * 清除所有批注
248
259
  */
@@ -278,7 +289,10 @@ export declare class DocEditor {
278
289
  * 是否可以恢复
279
290
  */
280
291
  canRedo(): boolean;
281
- switchTrackChanges(eleCtx?: BranchElement | null): void;
292
+ /**
293
+ * 切换文档留痕开关
294
+ */
295
+ switchTrackChanges(): void;
282
296
  get trackTipsChanged(): Subject<{
283
297
  pos: Position;
284
298
  tips: import("./framework/element-event-define").ITrackTips;
@@ -447,6 +461,24 @@ export declare class DocEditor {
447
461
  emit(event: string, args: any): void;
448
462
  createResizableElement(): VNode;
449
463
  private readDocChangeLog;
464
+ /**
465
+ * 处理候选词
466
+ * @private
467
+ */
468
+ private processSuggestionsHandle;
469
+ createAutoCompleteOptions(): void;
470
+ private processKeyDownEvent;
471
+ /**
472
+ * 处理候选词,键盘选择定位
473
+ * @private
474
+ */
475
+ private onSuggestionsKeydown;
476
+ /**
477
+ * 渲染联想、候选词
478
+ * @private
479
+ */
480
+ private renderSuggestions;
481
+ insertSuggestion(suggestion: ISuggestionData): void;
450
482
  }
451
483
  export interface IReaderManager {
452
484
  }
@@ -1,6 +1,6 @@
1
1
  import { DocumentInput, InputData } from "./document-input-cursor";
2
2
  import { SelectionState } from "./selection/document-selection";
3
- import { Element, LeafElement, SelectionContentRange } from "./element-define";
3
+ import { BlockContainerElement, Element, LeafElement, SelectionContentRange } from "./element-define";
4
4
  import { ParagraphElement, TableElement, TextGroupElement, TrackRunTypeEnum } from "./impl";
5
5
  import { ParagraphNumberType, ParagraphProps, TextProps } from "./element-props";
6
6
  import { ElementReader } from "./element-reader";
@@ -18,6 +18,7 @@ export declare class DocumentChange {
18
18
  private viewOptions;
19
19
  constructor(eleReader: ElementReader, docCtx: EditorContext, docComment: DocumentComment, documentInput: DocumentInput);
20
20
  newInput(data: InputData): void;
21
+ private correctInputEle;
21
22
  /**
22
23
  * 选中区域后进行输入
23
24
  * 需要处理将选中的区域删除后,进行输入的情况
@@ -142,6 +143,11 @@ export declare class DocumentChange {
142
143
  */
143
144
  private updateDeletedTrackText;
144
145
  private getNextTrackInputElement;
146
+ /**
147
+ * 创建一个待输入的文本元素
148
+ * @private
149
+ */
150
+ private createNewInputText;
145
151
  private getNextTrackElement;
146
152
  /**
147
153
  * 删除元素并定位光标
@@ -167,6 +173,11 @@ export declare class DocumentChange {
167
173
  * @returns
168
174
  */
169
175
  insertTable(tb: TableElement): void;
176
+ /**
177
+ * 插入布局容器,比如表格、数据容器等
178
+ * @param ele
179
+ */
180
+ insertLayoutContainer(ele: BlockContainerElement): void;
170
181
  /**
171
182
  * 分割当前段落用于插入表格或者粘贴的内容
172
183
  * @param insertItems 分割后插入的内容,内容需要是block或者表格对象
@@ -264,6 +275,14 @@ export declare class DocumentChange {
264
275
  * @param text
265
276
  */
266
277
  private pastePlainText;
278
+ /**
279
+ * 向当前光标追加文本
280
+ * @param appendStr
281
+ * @param inputOffset
282
+ * @param replaceLength
283
+ * @private
284
+ */
285
+ appendText(appendStr: string, replaceText: string): void;
267
286
  /**
268
287
  * 设置当前段落项目符号类型
269
288
  */
@@ -271,7 +290,7 @@ export declare class DocumentChange {
271
290
  /**
272
291
  * 插入批注
273
292
  */
274
- insertComment(): void;
293
+ insertComment(text: string): void;
275
294
  validate(): boolean;
276
295
  /**
277
296
  * 移除空字符串
@@ -4,6 +4,8 @@ import { ElementEvent, EventTypes } from "./element-event-define";
4
4
  import { DataElementValueStruct } from "./element-serialize";
5
5
  import { DataElementCheck, DataElementInlineGroup, DataElementLeaf, DocumentElement, TrackRunElement, TrackRunTypeEnum } from "./impl";
6
6
  import { DocumentChange } from "./document-change";
7
+ import { Subject } from "./infrastructure/event-subject";
8
+ import { DocInputSuggestions } from "./suggestions/input-suggestions";
7
9
  /**
8
10
  * 当前打开的文档的上下文信息,当前文档所有的属性设置都暴露在上下文中
9
11
  */
@@ -19,6 +21,8 @@ export declare class EditorContext {
19
21
  nextViewFns: Array<() => void>;
20
22
  commentFlag: boolean;
21
23
  trackFlag: boolean;
24
+ suggestions: DocInputSuggestions;
25
+ onKeyDownEvent: Subject<KeyboardEvent>;
22
26
  constructor(selectionState: SelectionState, viewOptions: ViewOptions);
23
27
  onNextView(cb: (() => void) | null): void;
24
28
  get document(): DocumentElement;
@@ -41,6 +45,7 @@ export declare class EditorContext {
41
45
  * 替换数据元
42
46
  */
43
47
  replaceDataElement(oldDataElement: DataElementLeaf | DataElementInlineGroup, newElement: DataElementLeaf | DataElementInlineGroup, ss: SelectionState): void;
48
+ currentRefreshType: RefreshType | null;
44
49
  get refreshType(): RefreshType | null;
45
50
  adaptiveScale(): number;
46
51
  }
@@ -7,8 +7,8 @@ export interface ICompositionStartInfo {
7
7
  }
8
8
  export interface InputData {
9
9
  composition?: boolean;
10
- compositionStartInfo?: ICompositionStartInfo;
11
- prevInputData?: string;
10
+ compositionStartInfo: ICompositionStartInfo;
11
+ prevInputDataLength?: number;
12
12
  data: string;
13
13
  }
14
14
  /**
@@ -17,25 +17,14 @@ export interface InputData {
17
17
  export declare class DocumentInput {
18
18
  private docCtx;
19
19
  onInputEvent: Subject<InputData>;
20
- onBackspaceEvent: Subject<KeyboardEvent>;
21
- onDeleteEvent: Subject<KeyboardEvent>;
22
- onEnterEvent: Subject<void>;
23
- onLeftEvent: Subject<void>;
24
- onRightEvent: Subject<void>;
25
20
  onCopyEvent: Subject<ClipboardEvent>;
26
21
  onCutEvent: Subject<ClipboardEvent>;
27
22
  onPasteEvent: Subject<ClipboardEvent>;
28
- onInsertBr: Subject<void>;
29
- onSelectAllEvent: Subject<void>;
30
- onHomeEvent: Subject<void>;
31
- onEndEvent: Subject<void>;
32
- onUpEvent: Subject<void>;
33
- onDownEvent: Subject<void>;
34
- onTabKeyEvent: Subject<void>;
23
+ onKeyDownEvent: Subject<KeyboardEvent>;
35
24
  constructor(docCtx: EditorContext);
36
25
  composition: boolean;
37
26
  inputTargetStrPosition: number;
38
- inputTargetStr: undefined | string;
27
+ inputTargetStrLength: number;
39
28
  inputEle: any;
40
29
  correctInputEle(ele: any, str: string | undefined, pos: number): void;
41
30
  getEventListener(): Object;
@@ -15,6 +15,7 @@ export interface SerializeProps {
15
15
  children?: Array<SerializeProps>;
16
16
  complete?: boolean;
17
17
  }
18
+ export declare const TEXT_HEIGHT_FACTOR = 1.4;
18
19
  /**
19
20
  * 刷新类型
20
21
  * 刷新外观,不需要进行测量,直接进入绘制
@@ -239,6 +240,7 @@ export declare type OrientType = 'landscape' | 'portrait';
239
240
  export declare type PageLayoutMode = 'singlePage' | 'multiPage' | 'fit-page';
240
241
  export declare class ViewOptions {
241
242
  copyRightInfo: string;
243
+ trialVersion: boolean;
242
244
  watermark?: string;
243
245
  drawLineRectColor: string;
244
246
  drawCharRectColor: string;
@@ -247,6 +249,8 @@ export declare class ViewOptions {
247
249
  editorVersion: string;
248
250
  defaultFontSize: number;
249
251
  defaultColor: string;
252
+ currentFontSize: number;
253
+ currentFontName: string;
250
254
  selectionOverlaysColor: string;
251
255
  dataEleOverlaysColor: string;
252
256
  dataEleFocusedBgColor: string;
@@ -284,6 +288,7 @@ export declare class ViewOptions {
284
288
  printHeaderFooterLine: boolean;
285
289
  showEnterSymbol: boolean;
286
290
  enableVisibleExpression: boolean;
291
+ shapeRendering: string;
287
292
  get fullPageView(): boolean;
288
293
  set fullPageView(value: boolean);
289
294
  mmToPixelsRatio: number;
@@ -308,6 +313,7 @@ export declare class ViewOptions {
308
313
  docMode: DocMode;
309
314
  private _showTrackChanges;
310
315
  private _showTrackChangesTip;
316
+ enableTrackChanges: boolean;
311
317
  get showTrackChanges(): boolean;
312
318
  set showTrackChanges(value: boolean);
313
319
  get showTrackChangesTip(): boolean;
@@ -317,6 +323,7 @@ export declare class ViewOptions {
317
323
  trackChangePeriod: number;
318
324
  onChange: Subject<'demand' | 'force'>;
319
325
  printMode: 'normal' | 'continuation';
326
+ enableSuggestions: boolean;
320
327
  constructor();
321
328
  }
322
329
  export declare class MarginProps {
@@ -43,13 +43,10 @@ export declare class ElementEvent {
43
43
  buttons: number;
44
44
  get selectionState(): import("./selection/document-selection").SelectionState;
45
45
  }
46
- export interface MenuListener {
47
- [listener: string]: <T extends Event>(evt: T) => void;
48
- }
49
46
  export declare class ContentMenuItem {
50
- icon: string;
51
47
  caption: string;
52
- eventObj: MenuListener;
48
+ checked?: boolean;
49
+ click?: () => void;
53
50
  subItems?: Array<ContentMenuItem>;
54
51
  }
55
52
  /**
@@ -5,5 +5,4 @@ import { ElementHandler } from "./element-define";
5
5
  * @param evt
6
6
  */
7
7
  export declare const deleteCurrentParagraph: ElementHandler<ContextMenuElementEvent>;
8
- export declare const setDataElementProps: ElementHandler<ContextMenuElementEvent>;
9
8
  export declare const onTableContextmenu: ElementHandler<ContextMenuElementEvent>;
@@ -0,0 +1,25 @@
1
+ import { BlockContainerElement, Element, ElementFactory, IBeginMeasureData, readElementProps, SerializeProps } from "../../element-define";
2
+ import { IEditorVNodeOptions, MuiltBlockLineRenderObject, RenderObject } from "../../render-define";
3
+ /**
4
+ * 数据块容器,包裹多个段落
5
+ */
6
+ export declare class DataContainerElement extends BlockContainerElement<DataContainerProps> {
7
+ constructor();
8
+ createRenderObject(): DataContainerRenderObject;
9
+ beginMeasure(data: IBeginMeasureData): void;
10
+ serialize(): SerializeProps;
11
+ clone(data: boolean): DataContainerElement;
12
+ }
13
+ export declare class DataContainerRenderObject extends MuiltBlockLineRenderObject<DataContainerElement> {
14
+ clone(cloneData?: boolean): RenderObject;
15
+ exportSVG(event: IEditorVNodeOptions): any;
16
+ }
17
+ export declare class DataContainerFactory extends ElementFactory<DataContainerProps> {
18
+ match(type: string): boolean;
19
+ createElement(data: readElementProps<DataContainerProps>): Element<any>;
20
+ }
21
+ export declare class DataContainerProps {
22
+ caption: string;
23
+ id: string;
24
+ name: string;
25
+ }
@@ -2,7 +2,6 @@ import { BlockContainerElement, Element, ElementFactory, IBeginMeasureData, Seri
2
2
  import { MouseElementEvent } from "../../element-event-define";
3
3
  import { IEditorVNodeOptions, MuiltBlockLineRenderObject, RenderObject } from "../../render-define";
4
4
  export declare class DocumentBodyElement extends BlockContainerElement {
5
- trackChanges: boolean;
6
5
  constructor();
7
6
  createRenderObject(): DocumentBodyRenderObject;
8
7
  serialize(): SerializeProps;
@@ -63,6 +63,7 @@ export declare class DocumentRenderObject extends BlockContainerRenderObject {
63
63
  private exportPageNumHTML;
64
64
  exportSVG(event: IEditorVNodeOptions): any;
65
65
  private exportPageCornerHTML;
66
+ private exportCopyRight;
66
67
  }
67
68
  export declare class DocumentFactory extends ElementFactory<DocumentProps> {
68
69
  match(type: string): boolean;
@@ -12,6 +12,7 @@ export * from './data-element/data-element-group-impl';
12
12
  export * from './data-element/data-element-image-impl';
13
13
  export * from './data-element/data-element-list-impl';
14
14
  export * from './data-element/data-element-text-impl';
15
+ export * from './data-element/data-container-impl';
15
16
  export * from './decorate/fill-null-space-imple';
16
17
  export * from './document/doc-body-impl';
17
18
  export * from './document/doc-body-part-impl';
@@ -1,4 +1,5 @@
1
1
  import { SelectionState } from "../../selection/document-selection";
2
+ import { TableElement } from "./table-impl";
2
3
  /**
3
4
  * 拆分单元格
4
5
  * 蜀道难,难于上青天;拆分单元格,头发秃,精神衰,眼睛昏,身体废。
@@ -81,12 +82,12 @@ export declare class TableSplitCell {
81
82
  * @param rowIndex
82
83
  * @param colIndex
83
84
  */
84
- private static getVMergeRowsCount;
85
+ static getVMergeRowsCount(tb: TableElement, rowIndex: number, colIndex: number): number;
85
86
  /**
86
87
  * 获取纵向合并的行数
87
88
  * @param tb
88
89
  * @param rowIndex
89
90
  * @param colIndex
90
91
  */
91
- private static getHMergeColsCount;
92
+ static getHMergeColsCount(tb: TableElement, rowIndex: number, colIndex: number): number;
92
93
  }
@@ -11,6 +11,7 @@ export declare abstract class Subscription<T = any> {
11
11
  export declare abstract class EventSourceCore<T> {
12
12
  protected closed: boolean;
13
13
  subs: Array<Subscription>;
14
+ state: 'pause' | 'running';
14
15
  next(data?: T): void;
15
16
  protected addSub(sub: Subscription): void;
16
17
  protected removeSub(sub: Subscription): void;
@@ -28,11 +28,7 @@ export declare class DocumentSelection {
28
28
  * @private
29
29
  */
30
30
  updateSelectionState(): boolean;
31
- /**
32
- * 获取当前选区区域内是否支持留痕
33
- * @private
34
- */
35
- private getEnableTrackChanges;
31
+ isSelectionChanged(): boolean;
36
32
  /**
37
33
  * 转换选区内容
38
34
  * 处理结束选区在开始选区之前
@@ -61,7 +57,6 @@ export declare class SelectionState {
61
57
  editable: boolean;
62
58
  renderContainer: DocumentContainerRender;
63
59
  cursorPos: Rect | null;
64
- enableTrackChanges: boolean;
65
60
  constructor();
66
61
  destroy(): void;
67
62
  clear(): void;
@@ -0,0 +1,29 @@
1
+ import { TextGroupElement } from "../impl";
2
+ /**
3
+ * 处理文档输入联想
4
+ */
5
+ export declare class DocInputSuggestions {
6
+ currentInputTextGroup: TextGroupElement | undefined;
7
+ currentMatchedText: string;
8
+ currentInputOffset: number;
9
+ suggestionsList: Array<ISuggestionData>;
10
+ prepareSuggestions: Array<ISuggestionData>;
11
+ selectedIndex: number;
12
+ clear(): void;
13
+ destroy(): void;
14
+ }
15
+ /**
16
+ * 联想词数据
17
+ */
18
+ export interface ISuggestionData {
19
+ label: string;
20
+ value?: string;
21
+ desc?: string;
22
+ action?: (data: ISuggestionData) => void;
23
+ }
24
+ export interface ISuggestionProvider {
25
+ filterSuggestions: Array<ISuggestionData>;
26
+ inputTextGroup: TextGroupElement;
27
+ inputOffset: number;
28
+ findText: string;
29
+ }
@@ -61,7 +61,7 @@ export declare class CommonUtil {
61
61
  static getNowDiffSeconds(date: Date | string): number;
62
62
  static isDate(str: string): boolean;
63
63
  static cloneValue(val: any): any;
64
- static cloneDeep<T>(source: T, visited?: WeakMap<object, any>): T;
64
+ static cloneDeep<T extends object>(source: T, visited?: WeakMap<object, any>): T;
65
65
  static isConstructor(f: any): boolean;
66
66
  static toArray<T>(item: Array<T> | T): Array<T>;
67
67
  static removeChild(ele: HTMLElement): void;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "hailin-zheng",
5
5
  "private": false,
6
6
  "license": "ISC",
7
- "version": "2.2.2",
7
+ "version": "2.2.4",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "moment": "^2.29.3",