Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(doc): doc editor

DR-Univer4ff1e403e216
diff --git a/packages/base-docs/src/Basic/DemoData.ts b/packages/base-docs/src/Basic/DemoData.ts
index eb4057c69a..d30af85e51 100644
--- a/packages/base-docs/src/Basic/DemoData.ts
+++ b/packages/base-docs/src/Basic/DemoData.ts
@@ -12,7 +12,7 @@ import {
WrapTextType,
} from '@univer/core';
-export const docsDemoData: IDocumentData = {
+export const DOCS_DEMO_DATA: IDocumentData = {
documentId: 'd',
drawings: {
shapeTest1: {
diff --git a/packages/base-docs/src/Controller/DocContainerController.ts b/packages/base-docs/src/Controller/DocContainerController.ts
deleted file mode 100644
index 6c25206d23..0000000000
--- a/packages/base-docs/src/Controller/DocContainerController.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { BooleanNumber, CommandManager } from '@univer/core';
-import { DocPlugin } from '../DocPlugin';
-
-export class DocContainerController {
- private _plugin: DocPlugin;
-
- constructor(plugin: DocPlugin) {
- this._plugin = plugin;
-
- this._initialize();
- }
-
- private _initialize() {}
-}
diff --git a/packages/base-docs/src/Controller/DocumentController.ts b/packages/base-docs/src/Controller/DocumentController.ts
new file mode 100644
index 0000000000..63123d3ffa
--- /dev/null
+++ b/packages/base-docs/src/Controller/DocumentController.ts
@@ -0,0 +1,14 @@
+import { BooleanNumber, CommandManager } from '@univer/core';
+import { DocPlugin, IDocPluginConfig } from '../DocPlugin';
+import { InputController } from './InputController';
+
+export class DocumentController {
+ private _inputController: InputController;
+ constructor(private _plugin: DocPlugin, private _config: Partial<IDocPluginConfig> = {}) {
+ this._initialize();
+ }
+
+ private _initialize() {
+ this._inputController = new InputController(this._plugin);
+ }
+}
diff --git a/packages/base-docs/src/Controller/InputController.ts b/packages/base-docs/src/Controller/InputController.ts
new file mode 100644
index 0000000000..2334e9ce5f
--- /dev/null
+++ b/packages/base-docs/src/Controller/InputController.ts
@@ -0,0 +1,172 @@
+import { Documents, IDocumentSkeletonSpan, SpanType } from '@univer/base-render';
+import { TextSelection } from '@univer/base-render/src/Component/Docs/Common/TextSelection';
+import { KeyboardKeyType, Logger, Nullable } from '@univer/core';
+import { DocPlugin } from '../DocPlugin';
+
+export class InputController {
+ constructor(private _plugin: DocPlugin) {
+ this._plugin.getObserver('onDocContainerDidMountObservable')?.add(() => {
+ this._initialize();
+ });
+ }
+
+ private _previousIMEContent: string = '';
+
+ private _previousIMEStart: number;
+
+ private _initialize() {
+ const events = this._plugin.getInputEvent();
+ if (!events) {
+ return;
+ }
+ const { onInputObservable, onCompositionstartObservable, onCompositionupdateObservable, onCompositionendObservable, onKeydownObservable } = events;
+
+ const docsModel = this._plugin.context.getDocument();
+
+ onKeydownObservable.add((config) => {
+ const { event, document, selection } = config;
+ let e = event as KeyboardEvent;
+
+ const cursor = selection?.getCursor() || 0;
+
+ const skeleton = document.getSkeleton();
+
+ if (!skeleton) {
+ return;
+ }
+
+ if (e.key === KeyboardKeyType.backspace) {
+ const selectionRemain = document.remainActiveSelection();
+
+ const content = document.findNodeByCharIndex(cursor - 1)?.content || '';
+
+ docsModel.deleteText(content, cursor);
+
+ skeleton.calculate();
+
+ const span = document.findNodeByCharIndex(cursor - 2);
+
+ this._adjustSelection(document, selectionRemain, span);
+ }
+ });
+
+ onInputObservable.add((config) => {
+ const { event, content = '', document, selection } = config;
+
+ const cursor = selection?.getCursor() || 0;
+
+ const skeleton = document.getSkeleton();
+
+ if (!skeleton) {
+ return;
+ }
+
+ const selectionRemain = document.remainActiveSelection();
+
+ docsModel.insertText(content, cursor);
+
+ skeleton.calculate();
+
+ const span = document.findNodeByCharIndex(cursor + content.length - 1);
+
+ this._adjustSelection(document, selectionRemain, span);
+ });
+
+ onCompositionstartObservable.add((config) => {
+ const { selection } = config;
+
+ const cursor = selection?.getCursor() || 0;
+
+ this._previousIMEStart = cursor;
+
+ // console.log('_previousIMEStart', this._previousIMEStart);
+ });
+
+ onCompositionupdateObservable.add((config) => {
+ const { event, content = '', document } = config;
+
+ const cursor = this._previousIMEStart;
+
+ const skeleton = document.getSkeleton();
+
+ if (!skeleton) {
+ return;
+ }
+
+ const e = event as CompositionEvent;
+
+ if (content === this._previousIMEContent) {
+ return;
+ }
+
+ const selectionRemain = document.remainActiveSelection();
+
+ // const increaseText = this._getIncreaseText(content, this._previousIMEContent);
+
+ // docsModel.insertText(increaseText, cursor);
+
+ docsModel.updateText(content, this._previousIMEContent, cursor);
+
+ skeleton.calculate();
+
+ const span = document.findNodeByCharIndex(cursor + content.length - 1);
+
+ // console.log('Compositionupdate', content, this._previousIMEContent, e.data, cursor, span);
+
+ this._adjustSelection(document, selectionRemain, span);
+
+ this._previousIMEContent = content;
+ });
+
+ onCompositionendObservable.add((config) => {
+ this._previousIMEContent = '';
+
+ this._previousIMEStart = -1;
+ });
+ }
+
+ private _getIncreaseText(current: string, old: string) {
+ const oldLen = old.length;
+ return current.slice(oldLen);
+ }
+
+ private _adjustSelection(document: Documents, selectionRemain?: TextSelection, span?: Nullable<IDocumentSkeletonSpan>) {
+ if (span == null) {
+ return;
+ }
+
+ const position = document.findPositionBySpan(span);
+
+ if (position == null || selectionRemain == null) {
+ return;
+ }
+
+ if (this._hasListSpan(span)) {
+ position.span += 1;
+ }
+
+ const newPos = { ...position, isBack: false };
+
+ document.addSelection(selectionRemain);
+
+ selectionRemain.startNodePosition = newPos;
+
+ selectionRemain.endNodePosition = undefined;
+
+ selectionRemain.refresh(document);
+
+ document.syncSelection();
+ }
+
+ private _hasListSpan(span: Nullable<IDocumentSkeletonSpan>) {
+ const divide = span?.parent;
+
+ if (divide == null) {
+ return false;
+ }
+
+ const spanGroup = divide.spanGroup;
+
+ return spanGroup[0]?.spanType === SpanType.LIST;
+ }
+}
diff --git a/packages/base-docs/src/DocPlugin.tsx b/packages/base-docs/src/DocPlugin.tsx
index 05a57f0aeb..4cb4cb09cd 100644
--- a/packages/base-docs/src/DocPlugin.tsx
+++ b/packages/base-docs/src/DocPlugin.tsx
@@ -4,11 +4,12 @@ import { IOCContainer } from '@univer/core';
import { Component, getRefElement, isElement, ISlotProps, RefObject, render } from '@univer/base-component';
import { DocPluginObserve, install } from './Basic/Observer';
import { ToolBarController } from './Controller/ToolBarController';
-import { DocContainerController } from './Controller/DocContainerController';
+import { DocumentController } from './Controller/DocumentController';
import { BaseDocContainerConfig, defaultLayout, DocContainer, IDocPluginConfigBase, ILayout } from './View/UI/DocContainer';
import { InfoBarController } from './Controller/InfoBarController';
import { Engine, RenderEngine } from '@univer/base-render';
import { CanvasView } from './View/Render/CanvasView';
+import { CANVAS_VIEW_KEY } from './View/Render';
export interface IDocPluginConfig extends IDocPluginConfigBase {
container: HTMLElement | string;
@@ -43,7 +44,9 @@ export class DocPlugin extends Plugin<DocPluginObserve, DocContext> {
private _canvasEngine: Engine;
private _toolBarControl: ToolBarController;
- private _docContainerController: DocContainerController;
+
+ private _documentController: DocumentController;
+
private _componentList: Map<string, any>;
constructor(config: Partial<IDocPluginConfig> = {}) {
@@ -88,7 +91,7 @@ export class DocPlugin extends Plugin<DocPluginObserve, DocContext> {
this._toolBarControl = new ToolBarController(this);
this._infoBarControl = new InfoBarController(this);
- this._docContainerController = new DocContainerController(this);
+ this._documentController = new DocumentController(this, this.config);
const docContainer = this._initContainer(this._config.container);
@@ -174,6 +177,30 @@ export class DocPlugin extends Plugin<DocPluginObserve, DocContext> {
return this._config;
}
+ getCanvasEngine() {
+ return this._canvasEngine;
+ }
+
+ getCanvasView() {
+ return this._canvasView;
+ }
+
+ getMainScene() {
+ return this._canvasEngine.getScene(CANVAS_VIEW_KEY.MAIN_SCENE);
+ }
+
+ getDocsView() {
+ return this.getCanvasView().getDocsView();
+ }
+
+ getMainComponent() {
+ return this.getDocsView().getDocs();
+ }
+
+ getInputEvent() {
+ return this.getMainComponent().getEditorInputEvent();
+ }
+
getContentRef(): RefObject<HTMLDivElement> {
return this._contentRef;
}
diff --git a/packages/base-docs/src/View/Render/CanvasView.ts b/packages/base-docs/src/View/Render/CanvasView.ts
index d48ccd82aa..7a9c994713 100644
--- a/packages/base-docs/src/View/Render/CanvasView.ts
+++ b/packages/base-docs/src/View/Render/CanvasView.ts
@@ -66,7 +66,7 @@ export class CanvasView {
engine.runRenderLoop(() => {
scene.render();
const app = document.getElementById('app');
- if(app){
+ if (app) {
app.innerText = `fps:${Math.round(engine.getFps()).toString()}`;
}
});
diff --git a/packages/base-docs/src/View/Render/Views/DocsView.ts b/packages/base-docs/src/View/Render/Views/DocsView.ts
index 0ae280eec2..500fc59935 100644
--- a/packages/base-docs/src/View/Render/Views/DocsView.ts
+++ b/packages/base-docs/src/View/Render/Views/DocsView.ts
@@ -1,5 +1,5 @@
import { getColor, Rect, Documents, DocumentSkeleton } from '@univer/base-render';
-import { docsDemoData } from '../../../Basic/DemoData';
+import { IDocumentData } from '@univer/core';
import { BaseView, CanvasViewRegistry } from '../BaseView';
import { CANVAS_VIEW_KEY } from '../BaseView';
@@ -20,7 +20,9 @@ export class DocsView extends BaseView {
const scene = this.getScene();
const context = this.getContext();
- const documentSkeleton = this._buildSkeleton();
+ const docsModel = context.getDocument();
+
+ const documentSkeleton = this._buildSkeleton(docsModel.getSnapshot());
const documents = new Documents(DOCS_VIEW_KEY.MAIN, documentSkeleton);
documents.zIndex = 1000;
@@ -76,10 +78,10 @@ export class DocsView extends BaseView {
return this._documents;
}
- private _buildSkeleton() {
+ private _buildSkeleton(snapshot: IDocumentData) {
const context = this.getContext();
- const docsSkeleton = DocumentSkeleton.create(docsDemoData, context);
+ const docsSkeleton = DocumentSkeleton.create(snapshot, context);
return docsSkeleton;
}
diff --git a/packages/base-docs/src/main.tsx b/packages/base-docs/src/main.tsx
index b81ebca114..8d21e8dade 100644
--- a/packages/base-docs/src/main.tsx
+++ b/packages/base-docs/src/main.tsx
@@ -2,8 +2,9 @@ import { UniverDoc } from '@univer/core';
import { RenderEngine } from '@univer/base-render';
import { UniverComponentSheet } from '@univer/style-universheet';
import { DocPlugin } from './DocPlugin';
+import { DOCS_DEMO_DATA } from './Basic/DemoData';
-const univerDocUp = UniverDoc.newInstance();
+const univerDocUp = UniverDoc.newInstance(DOCS_DEMO_DATA);
univerDocUp.installPlugin(new RenderEngine());
univerDocUp.installPlugin(new UniverComponentSheet());
diff --git a/packages/base-formula-engine/src/Dependency/FormulaDependency.ts b/packages/base-formula-engine/src/Dependency/FormulaDependency.ts
index 53b413aef7..e8d637dfa3 100644
--- a/packages/base-formula-engine/src/Dependency/FormulaDependency.ts
+++ b/packages/base-formula-engine/src/Dependency/FormulaDependency.ts
@@ -145,8 +145,6 @@ export class FormulaDependencyGenerator {
private _includeTree(tree: FormulaDependencyTree) {
const unitId = tree.unitId;
const sheetId = tree.sheetId;
- // const row = tree.row;
- // const column = tree.column;
if (!this._updateRangeFlattenCache.has(unitId)) {
return false;
@@ -164,10 +162,6 @@ export class FormulaDependencyGenerator {
return true;
}
- // if (rangeObjectMatrix.getValue(row, column)) {
- // return true;
- // }
-
return false;
}
@@ -187,6 +181,11 @@ export class FormulaDependencyGenerator {
}
}
+ /**
+ * forceCalculate: Mandatory calculation, adding all formulas to dependencies
+ * tree.dependencyRange: Formula dependent modification range
+ * includeTree: modification range contains formula
+ */
if ((this._forceCalculate || tree.dependencyRange(this._updateRangeFlattenCache) || this._includeTree(tree)) && !existTree.has(tree)) {
newTreeList.push(tree);
existTree.add(tree);
diff --git a/packages/base-render/src/Basics/IDocumentSkeletonCached.ts b/packages/base-render/src/Basics/IDocumentSkeletonCached.ts
index 15618184e9..3aeda0f058 100644
--- a/packages/base-render/src/Basics/IDocumentSkeletonCached.ts
+++ b/packages/base-render/src/Basics/IDocumentSkeletonCached.ts
@@ -1,4 +1,15 @@
-import { BulletAlignment, ColumnSeparatorType, IDrawing, INestingLevel, IParagraphStyle, ITextStyle, IDocumentRenderConfig, IIndentStart, PageOrientType } from '@univer/core';
+import {
+ BulletAlignment,
+ ColumnSeparatorType,
+ IDrawing,
+ INestingLevel,
+ IParagraphStyle,
+ ITextStyle,
+ IDocumentRenderConfig,
+ IIndentStart,
+ PageOrientType,
+ IElement,
+} from '@univer/core';
export interface IDocumentSkeletonCached extends ISkeletonResourceReference {
pages: IDocumentSkeletonPage[];
@@ -14,12 +25,13 @@ export interface ISkeletonResourceReference {
/* Global cache, does not participate in rendering, only helps skeleton generation */
skeListLevel?: Map<string, IDocumentSkeletonBullet[]>; // 有序列表缓存,id:{ level: max(width)的bullet }
blockAnchor?: Map<string, IDocumentSkeletonBlockAnchor>; // Anchor point to assist floating element positioning
+ features?: Map<string, IDocumentSkeletonSpanFeature>;
}
export interface IDocumentSkeletonBlockAnchor {
elements: IDocumentSkeletonLine[]; // element: lines, tr
blockId: string; // block id
- top: number; // top 相对于上一个block的高度
+ top: number; // relative height for previous block
}
export interface IDocumentSkeletonHeaderFooterBase {
@@ -71,8 +83,8 @@ export interface IDocumentSkeletonSection {
// section坐标系相对于page
height: number; // 设置的高度, 如果未指定则与pageContentHeight相同 = pageHeight - marginTop - marginBottom
top: number; // 根据pre height计算下一个section开始位置
- st?: number; // startIndex 文本开始索引
- ed?: number; // endIndex 文本结束索引
+ st: number; // startIndex 文本开始索引
+ ed: number; // endIndex 文本结束索引
parent?: IDocumentSkeletonPage;
}
@@ -137,16 +149,17 @@ export interface IDocumentSkeletonSpan {
// word or letter or image or custom
eId?: string; // elementId, For custom cases
spanType: SpanType; // SpanType
- width: number; // 总宽度
- bBox: IDocumentSkeletonBoundingBox; // bBox Span的宽高信息
- paddingLeft: number; // paddingLeft,左侧间隔,调整文字在内部的对齐
+ width: number; // cum width
+ bBox: IDocumentSkeletonBoundingBox; // bBox: size of Span
+ paddingLeft: number; // paddingLeft, adjust text align in span
left: number; // left
count?: number; // count, content,default 1
content?: string; // content
- ts?: ITextStyle; // 文字样式
- fontStyle?: IDocumentSkeletonFontStyle; // fontStyle 从ITextStyle转换为canvas font
+ ts?: ITextStyle; // text style
+ fontStyle?: IDocumentSkeletonFontStyle; // fontStyle : ITextStyle convert to canvas font
parent?: IDocumentSkeletonDivide;
- url?: string; // image url链接;
+ url?: string; // image url
+ featureId?: string; // support interaction for feature ,eg. hyperLine person
}
export interface IDocumentSkeletonBullet extends IIndentStart {
@@ -175,6 +188,11 @@ export interface IDocumentSkeletonDrawing {
drawingOrigin: IDrawing;
}
+export interface IDocumentSkeletonSpanFeature {
+ featureId: string;
+ element: IElement;
+}
+
export interface IDocumentSkeletonFontStyle {
fontString: string;
fontSize: number;
diff --git a/packages/base-render/src/Basics/Interfaces.ts b/packages/base-render/src/Basics/Interfaces.ts
index 9313aeb813..2b1119ec4e 100644
--- a/packages/base-render/src/Basics/Interfaces.ts
+++ b/packages/base-render/src/Basics/Interfaces.ts
@@ -1,4 +1,6 @@
import { BooleanNumber, GridType, IDocStyleBase, IDocumentLayout, IParagraphStyle, IReferenceSource, ISectionBreakBase, ITextStyle } from '@univer/core';
+import { TextSelection } from '../Component/Docs/Common/TextSelection';
+import { Documents } from '../Component/Docs/Document';
import {
IDocumentSkeletonBlockAnchor,
IDocumentSkeletonBullet,
@@ -121,6 +123,13 @@ export interface IFontCreateConfig {
pageWidth?: number;
}
+export interface IEditorInputConfig {
+ event: Event | CompositionEvent | KeyboardEvent;
+ content?: string;
+ document: Documents;
+ selection?: TextSelection;
+}
+
// export interface IPageConfig {
// pageNumberStart: number;
// pageSize: ISizeData;
diff --git a/packages/base-render/src/Component/Docs/Common/TextSelection.ts b/packages/base-render/src/Component/Docs/Common/TextSelection.ts
index e4bf842c4c..857b246945 100644
--- a/packages/base-render/src/Component/Docs/Common/TextSelection.ts
+++ b/packages/base-render/src/Component/Docs/Common/TextSelection.ts
@@ -568,11 +568,9 @@ export class TextSelection {
const firstCursor = cursorList[0];
this._cursor = firstCursor.cursorStart;
-
- console.log('this._cursor', this._cursor);
}
- get cursor() {
+ getCursor() {
return this._cursor;
}
diff --git a/packages/base-render/src/Component/Docs/Document.Editor.ts b/packages/base-render/src/Component/Docs/Document.Editor.ts
index 212ba52fe3..309b888eba 100644
--- a/packages/base-render/src/Component/Docs/Document.Editor.ts
+++ b/packages/base-render/src/Component/Docs/Document.Editor.ts
@@ -1,4 +1,4 @@
-import { Nullable, Observer } from '@univer/core';
+import { Nullable, Observable, Observer } from '@univer/core';
import { IDocumentSkeletonCached, IDocumentSkeletonSpan } from '../../Basics/IDocumentSkeletonCached';
import { CURSOR_TYPE } from '../../Basics/Const';
import { IMouseEvent, IPointerEvent } from '../../Basics/IEvents';
@@ -10,7 +10,9 @@ import { INodePosition, TextSelection } from './Common/TextSelection';
import { IScrollObserverParam, Viewport } from '../../Viewport';
import { checkStyle, injectStyle } from '../../Basics/Tools';
-import { Vector2 } from '../../Basics';
+import { Vector2 } from '../../Basics/Vector2';
+
+import { IEditorInputConfig } from '../../Basics/Interfaces';
interface INodeInfo {
node: IDocumentSkeletonSpan;
@@ -39,18 +41,12 @@ export class DocsEditor {
private _skeletonObserver: Nullable<Observer<IDocumentSkeletonCached>>;
- private _startOffsetX: number;
-
- private _startOffsetY: number;
-
private _viewportScrollX: number;
private _viewportScrollY: number;
private _textSelectionList: TextSelection[] = [];
- private _startNodePosition: INodePosition;
-
private _activeViewport: Nullable<Viewport>;
private _viewPortObserverMap = new Map<
@@ -61,6 +57,16 @@ export class DocsEditor {
}
>();
+ onKeydownObservable = new Observable<IEditorInputConfig>();
+
+ onInputObservable = new Observable<IEditorInputConfig>();
+
+ onCompositionstartObservable = new Observable<IEditorInputConfig>();
+
+ onCompositionupdateObservable = new Observable<IEditorInputConfig>();
+
+ onCompositionendObservable = new Observable<IEditorInputConfig>();
+
constructor(private _documents?: Documents) {
this._initialDom();
@@ -209,41 +215,14 @@ export class DocsEditor {
const { node: span, ratioX, ratioY } = node;
- const divide = span.parent;
+ const position = this._documents?.findPositionBySpan(span);
- const line = divide?.parent;
-
- const column = line?.parent;
-
- const section = column?.parent;
-
- const page = section?.parent;
-
- const skeletonData = this._getSkeletonData();
-
- if (!divide || !column || !section || !page || !skeletonData) {
+ if (position == null) {
return;
}
- const spanIndex = divide.spanGroup.indexOf(span);
-
- const divideIndex = line.divides.indexOf(divide);
-
- const lineIndex = column.lines.indexOf(line);
-
- const columnIndex = section.columns.indexOf(column);
-
- const sectionIndex = page.sections.indexOf(section);
-
- const pageIndex = skeletonData.pages.indexOf(page);
-
return {
- span: spanIndex,
- divide: divideIndex,
- line: lineIndex,
- column: columnIndex,
- section: sectionIndex,
- page: pageIndex,
+ ...position,
isBack: ratioX < 0.5,
};
}
@@ -346,7 +325,7 @@ export class DocsEditor {
this._cursor.style.height = `${height}px`;
- console.log('_syncDomToSelection', left, top, absoluteCoord?.x || 0, absoluteCoord?.y || 0);
+ // console.log('_syncDomToSelection', left, top, absoluteCoord?.x || 0, absoluteCoord?.y || 0);
let { left: canvasLeft, top: canvasTop } = this._getCanvasOffset();
@@ -359,8 +338,8 @@ export class DocsEditor {
private _moving(moveOffsetX: number, moveOffsetY: number, scrollTimer: ScrollTimer) {
const { scrollX, scrollY } = getCurrentScrollXY(scrollTimer);
- const endX = moveOffsetX - this._viewportScrollX + scrollX;
- const endY = moveOffsetY - this._viewportScrollY + scrollY;
+ // const endX = moveOffsetX - this._viewportScrollX + scrollX;
+ // const endY = moveOffsetY - this._viewportScrollY + scrollY;
if (!this._documents) {
return;
@@ -451,44 +430,103 @@ export class DocsEditor {
private _isIMEInputApply = false;
private _attachInputEvent() {
+ this._input.addEventListener('keydown', (e) => {
+ if (this._isIMEInputApply) {
+ return;
+ }
+ const selection = this._getActiveTextSelection();
+ if (this._documents == null) {
+ return;
+ }
+ this.onKeydownObservable.notifyObservers({
+ event: e,
+ content: '',
+ document: this._documents,
+ selection,
+ });
+ });
+
this._input.addEventListener('input', (e) => {
if (this._isIMEInputApply) {
return;
}
- const content = this._input.innerHTML;
+ const content = this._input.textContent || '';
- const selection = this._getActiveTextSelection();
+ this._input.innerHTML = '';
- const inputStart = selection?.getStart();
+ const selection = this._getActiveTextSelection();
- if (!inputStart) {
+ if (this._documents == null) {
return;
}
- console.log(1);
+ this.onInputObservable.notifyObservers({
+ event: e,
+ content,
+ document: this._documents,
+ selection,
+ });
});
this._input.addEventListener('compositionstart', (e) => {
this._isIMEInputApply = true;
+
+ const content = this._input.textContent || '';
+
+ this._input.innerHTML = '';
+
+ const selection = this._getActiveTextSelection();
+
+ if (this._documents == null) {
+ return;
+ }
+
+ this.onCompositionstartObservable.notifyObservers({
+ event: e,
+ content,
+ document: this._documents,
+ selection,
+ });
});
this._input.addEventListener('compositionend', (e) => {
this._isIMEInputApply = false;
- const content = this._input.innerHTML;
+ const content = this._input.textContent || '';
+
+ this._input.innerHTML = '';
+
+ const selection = this._getActiveTextSelection();
+
+ if (this._documents == null) {
+ return;
+ }
+
+ this.onCompositionendObservable.notifyObservers({
+ event: e,
+ content,
+ document: this._documents,
+ selection,
+ });
});
this._input.addEventListener('compositionupdate', (e) => {
- console.log('onCompositionUpdate', this._input.innerHTML);
- const content = this._input.innerHTML;
- // ctx.fillText(content, 10, 90);
- // const measure = ctx.measureText(content);
- // const { width, fontBoundingBoxAscent, fontBoundingBoxDescent } = measure;
- // ctx.beginPath();
- // ctx.setLineDash([1, 2]);
- // ctx.moveTo(10, 90 + fontBoundingBoxDescent);
- // ctx.lineTo(10 + width, 90 + fontBoundingBoxDescent);
- // ctx.stroke();
+ const content = this._input.textContent || '';
+
+ this._input.innerHTML = '';
+
+ const selection = this._getActiveTextSelection();
+
+ if (this._documents == null) {
+ return;
+ }
+
+ this.onCompositionupdateObservable.notifyObservers({
+ event: e,
+ content,
+ document: this._documents,
+ selection,
+ });
});
}
@@ -505,8 +543,6 @@ export class DocsEditor {
this._downObserver = documents.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent, state) => {
const { offsetX: evtOffsetX, offsetY: evtOffsetY } = evt;
- this._startOffsetX = evtOffsetX;
- this._startOffsetY = evtOffsetY;
if (!this._documents) {
return;
@@ -536,8 +572,6 @@ export class DocsEditor {
this._syncDomToSelection();
- this._startNodePosition = position;
-
scene.disableEvent();
const scrollTimer = ScrollTimer.create(scene);
@@ -574,6 +608,11 @@ export class DocsEditor {
documents.onPointerLeaveObserver.remove(this._moveOutObserver);
documents.onPointerDownObserver.remove(this._downObserver);
documents.getSkeleton()?.onRecalculateChangeObservable.remove(this._skeletonObserver);
+ this.onKeydownObservable.clear();
+ this.onInputObservable.clear();
+ this.onCompositionstartObservable.clear();
+ this.onCompositionupdateObservable.clear();
+ this.onCompositionendObservable.clear();
}
private _activeSelectionRefresh() {
@@ -585,6 +624,24 @@ export class DocsEditor {
activeSelection?.refresh(this._documents);
}
+ add(textSelection: TextSelection) {
+ this._addTextSelection(textSelection);
+ }
+
+ remain() {
+ const activeSelection = this._getActiveTextSelection();
+ if (activeSelection == null) {
+ return;
+ }
+ const index = this._textSelectionList.indexOf(activeSelection);
+
+ return this._textSelectionList.splice(index, 1)[0];
+ }
+
+ sync() {
+ this._syncDomToSelection();
+ }
+
active(x: number, y: number) {
this._container.style.left = `${x}px`;
this._container.style.top = `${y}px`;
diff --git a/packages/base-render/src/Component/Docs/Document.ts b/packages/base-render/src/Component/Docs/Document.ts
index 249da54a11..3941142408 100644
--- a/packages/base-render/src/Component/Docs/Document.ts
+++ b/packages/base-render/src/Component/Docs/Document.ts
@@ -1,6 +1,6 @@
import { BooleanNumber, HorizontalAlign, Nullable, Observable, Observer, VerticalAlign, WrapStrategy } from '@univer/core';
import { DocComponent } from './DocComponent';
-import { IDocumentSkeletonCached, IDocumentSkeletonPage, LineType, PageLayoutType } from '../../Basics/IDocumentSkeletonCached';
+import { IDocumentSkeletonCached, IDocumentSkeletonPage, IDocumentSkeletonSpan, LineType, PageLayoutType } from '../../Basics/IDocumentSkeletonCached';
import { IBoundRect, Vector2 } from '../../Basics/Vector2';
import { DocumentsSpanAndLineExtensionRegistry, IExtensionConfig } from '../Extension';
import { DocumentSkeleton } from './DocSkeleton';
@@ -11,6 +11,7 @@ import { fixLineWidthByScale, getScale, degToRad } from '../../Basics/Tools';
import { DocsEditor } from './Document.Editor';
import { Liquid } from './Common';
import { Scene } from '../../Scene';
+import { TextSelection } from './Common/TextSelection';
export interface IDocumentsConfig {
pageMarginLeft?: number;
@@ -212,6 +213,36 @@ export class Documents extends DocComponent {
this._hasEditor = false;
}
+ getEditorInputEvent() {
+ if (!this._hasEditor) {
+ return;
+ }
+ const { onInputObservable, onCompositionstartObservable, onCompositionupdateObservable, onCompositionendObservable, onKeydownObservable } = this._editor;
+ return { onInputObservable, onCompositionstartObservable, onCompositionupdateObservable, onCompositionendObservable, onKeydownObservable };
+ }
+
+ remainActiveSelection() {
+ if (!this._hasEditor) {
+ return;
+ }
+ return this._editor.remain();
+ }
+
+ addSelection(textSelection: TextSelection) {
+ if (!this._hasEditor) {
+ return;
+ }
+ return this._editor.add(textSelection);
+ }
+
+ syncSelection() {
+ if (!this._hasEditor) {
+ return;
+ }
+
+ return this._editor.sync();
+ }
+
get hasEditor() {
return this._hasEditor;
}
@@ -433,6 +464,105 @@ export class Documents extends DocComponent {
return this;
}
+ findPositionBySpan(span: IDocumentSkeletonSpan) {
+ const divide = span.parent;
+
+ const line = divide?.parent;
+
+ const column = line?.parent;
+
+ const section = column?.parent;
+
+ const page = section?.parent;
+
+ const skeletonData = this.getSkeleton()?.getSkeletonData();
+
+ if (!divide || !column || !section || !page || !skeletonData) {
+ return;
+ }
+
+ let spanIndex = divide.spanGroup.indexOf(span);
+
+ const divideIndex = line.divides.indexOf(divide);
+
+ const lineIndex = column.lines.indexOf(line);
+
+ const columnIndex = section.columns.indexOf(column);
+
+ const sectionIndex = page.sections.indexOf(section);
+
+ const pageIndex = skeletonData.pages.indexOf(page);
+
+ return {
+ span: spanIndex,
+ divide: divideIndex,
+ line: lineIndex,
+ column: columnIndex,
+ section: sectionIndex,
+ page: pageIndex,
+ };
+ }
+
+ findNodeByCharIndex(charIndex: number): Nullable<IDocumentSkeletonSpan> {
+ const skeleton = this.getSkeleton();
+
+ if (!skeleton) {
+ return;
+ }
+
+ const skeletonData = skeleton.getSkeletonData();
+
+ const pages = skeletonData.pages;
+
+ for (let page of pages) {
+ const { sections, st, ed } = page;
+
+ if (charIndex < st || charIndex > ed) {
+ continue;
+ }
+
+ for (let section of sections) {
+ const { columns, st, ed } = section;
+
+ if (charIndex < st || charIndex > ed) {
+ continue;
+ }
+
+ for (let column of columns) {
+ const { lines, st, ed } = column;
+
+ if (charIndex < st || charIndex > ed) {
+ continue;
+ }
+
+ for (let line of lines) {
+ const { divides, lineHeight, st, ed } = line;
+ const divideLength = divides.length;
+
+ if (charIndex < st || charIndex > ed) {
+ continue;
+ }
+
+ for (let i = 0; i < divideLength; i++) {
+ const divide = divides[i];
+ const { spanGroup, st, ed } = divide;
+
+ if (charIndex < st || charIndex > ed) {
+ continue;
+ }
+
+ const span = spanGroup[charIndex - st];
+
+ if (span) {
+ return span;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
findNodeByCoord(offsetX: number, offsetY: number) {
const scene = this.getScene() as Scene;
const originCoord = scene.transformToSceneCoord(Vector2.FromArray([offsetX, offsetY]));
diff --git a/packages/core/src/Basics/DocContext.ts b/packages/core/src/Basics/DocContext.ts
index bce1fb1a1e..df36aff4b0 100644
--- a/packages/core/src/Basics/DocContext.ts
+++ b/packages/core/src/Basics/DocContext.ts
@@ -1,22 +1,22 @@
import { IDocumentData } from '../Interfaces';
import { ContextBase } from './ContextBase';
-import { Document } from '../Docs/Domain/Document';
+import { DocumentModel } from '../Docs/Domain/DocumentModel';
/**
* Core context, mount important instances, managers
*/
export class DocContext extends ContextBase {
- protected _document: Document;
+ protected _document: DocumentModel;
constructor(univerDocData: Partial<IDocumentData> = {}) {
super();
this._locale.initialize(univerDocData.locale);
- this._document = new Document(univerDocData, this);
+ this._document = new DocumentModel(univerDocData, this);
}
protected _setObserver(): void {}
- getDocument(): Document {
+ getDocument(): DocumentModel {
return this._document;
}
}
diff --git a/packages/core/src/Command/Command.ts b/packages/core/src/Command/Command.ts
index 8b8711a9f2..149712dfdd 100644
--- a/packages/core/src/Command/Command.ts
+++ b/packages/core/src/Command/Command.ts
@@ -2,14 +2,14 @@ import { Class, Nullable } from '../Shared';
import { Workbook } from '../Sheets/Domain';
import { ActionBase, IActionData } from './ActionBase';
import { ActionType } from './ActionObservers';
-import { Document } from '../Docs/Domain/Document';
+import { DocumentModel } from '../Docs/Domain/DocumentModel';
import { CommandInjector } from './CommandInjectorObservers';
import { CommandManager } from './CommandManager';
export class CommandUnit {
WorkBookUnit?: Workbook;
- DocumentUnit?: Document;
+ DocumentUnit?: DocumentModel;
}
/**
diff --git a/packages/core/src/Command/DocActionBase.ts b/packages/core/src/Command/DocActionBase.ts
index 92d28c3a83..54d288eb68 100644
--- a/packages/core/src/Command/DocActionBase.ts
+++ b/packages/core/src/Command/DocActionBase.ts
@@ -1,5 +1,5 @@
import { ActionBase, IActionData } from './ActionBase';
-import { Document } from '../Docs/Domain/Document';
+import { DocumentModel } from '../Docs/Domain/DocumentModel';
import { CommandUnit } from './Command';
import { ActionObservers } from './ActionObservers';
@@ -10,7 +10,7 @@ export abstract class DocActionBase<
O extends IDocActionData = D,
R = void
> extends ActionBase<D, O, R> {
- protected _document: Document;
+ protected _document: DocumentModel;
protected constructor(
actionData: D,
@@ -24,7 +24,7 @@ export abstract class DocActionBase<
this._document = commandUnit.DocumentUnit;
}
- getDocument(): Document {
+ getDocument(): DocumentModel {
return this._document;
}
}
diff --git a/packages/core/src/Command/RegisterAction.ts b/packages/core/src/Command/RegisterAction.ts
index 0df0a24e08..0267433fe9 100644
--- a/packages/core/src/Command/RegisterAction.ts
+++ b/packages/core/src/Command/RegisterAction.ts
@@ -45,6 +45,7 @@ import {
import { CommandManager } from './CommandManager';
import { DOC_ACTION_NAMES } from '../Const/DOC_ACTION_NAMES';
import { InsertTextAction } from '../Docs/Action/InsertTextAction';
+import { DeleteTextAction } from '../Docs';
/**
* All Commands are registered statically. For each new Command, a static registration method must be added here.
@@ -129,3 +130,4 @@ CommandManager.register(ACTION_NAMES.SET_ZOOM_RATIO_ACTION, SetZoomRatioAction);
///====================================================================================================
CommandManager.register(DOC_ACTION_NAMES.INSERT_TEXT_ACTION_NAME, InsertTextAction);
+CommandManager.register(DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME, DeleteTextAction);
diff --git a/packages/core/src/Const/DOC_ACTION_NAMES.ts b/packages/core/src/Const/DOC_ACTION_NAMES.ts
index afc25a1712..824f636df8 100644
--- a/packages/core/src/Const/DOC_ACTION_NAMES.ts
+++ b/packages/core/src/Const/DOC_ACTION_NAMES.ts
@@ -1,3 +1,4 @@
export enum DOC_ACTION_NAMES {
INSERT_TEXT_ACTION_NAME = 'InsertTextAction',
+ DELETE_TEXT_ACTION_NAME = 'DeleteTextAction',
}
diff --git a/packages/core/src/Docs/Action/ClearTextStyleAction.ts b/packages/core/src/Docs/Action/ClearTextStyleAction.ts
new file mode 100644
index 0000000000..8297789af9
--- /dev/null
+++ b/packages/core/src/Docs/Action/ClearTextStyleAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IClearTextStyleActionData extends IDocActionData {
+ text: string;
+}
+
+export class ClearTextStyleAction extends DocActionBase<
+ IClearTextStyleActionData,
+ IClearTextStyleActionData
+> {
+ constructor(
+ actionData: IClearTextStyleActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/DeleteParagraphAction.ts b/packages/core/src/Docs/Action/DeleteParagraphAction.ts
new file mode 100644
index 0000000000..47f3c18df4
--- /dev/null
+++ b/packages/core/src/Docs/Action/DeleteParagraphAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IDeleteParagraphActionData extends IDocActionData {
+ text: string;
+}
+
+export class DeleteParagraphAction extends DocActionBase<
+ IDeleteParagraphActionData,
+ IDeleteParagraphActionData
+> {
+ constructor(
+ actionData: IDeleteParagraphActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/DeleteTextAction.ts b/packages/core/src/Docs/Action/DeleteTextAction.ts
new file mode 100644
index 0000000000..be26e1d334
--- /dev/null
+++ b/packages/core/src/Docs/Action/DeleteTextAction.ts
@@ -0,0 +1,52 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+import { DeleteTextApply } from '../Apply/DeleteTextApply';
+import { IInsertTextActionData } from './InsertTextAction';
+import { InsertTextApply } from '../Apply/InsertTextApply';
+
+export interface IDeleteTextActionData extends IDocActionData {
+ text: string;
+ start: number;
+ length: number;
+ segmentId?: string; //The ID of the header, footer or footnote the location is in. An empty segment ID signifies the document's body.
+}
+
+export class DeleteTextAction extends DocActionBase<
+ IDeleteTextActionData,
+ IInsertTextActionData
+> {
+ constructor(
+ actionData: IDeleteTextActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ const { length, start } = actionData;
+ this._oldActionData = { ...actionData, start: start - length };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ const { length, start } = actionData;
+ DeleteTextApply(document, { length, start });
+ }
+
+ undo(): void {
+ // TODO ...
+ const actionData = this.getOldActionDaa();
+ const document = this.getDocument();
+ const { text, start, length } = actionData;
+ InsertTextApply(document, { text, start, length });
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/InsertTextAction.ts b/packages/core/src/Docs/Action/InsertTextAction.ts
index 259530d16a..9306ef8448 100644
--- a/packages/core/src/Docs/Action/InsertTextAction.ts
+++ b/packages/core/src/Docs/Action/InsertTextAction.ts
@@ -1,14 +1,19 @@
import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
-import { ActionObservers, CommandUnit } from '../../Command';
+import { ActionObservers, ActionType, CommandUnit } from '../../Command';
import { InsertTextApply } from '../Apply/InsertTextApply';
+import { IDeleteTextActionData } from './DeleteTextAction';
+import { DeleteTextApply } from '../Apply/DeleteTextApply';
export interface IInsertTextActionData extends IDocActionData {
text: string;
+ start: number;
+ length: number;
+ segmentId?: string; //The ID of the header, footer or footnote the location is in. An empty segment ID signifies the document's body.
}
export class InsertTextAction extends DocActionBase<
IInsertTextActionData,
- IInsertTextActionData
+ IDeleteTextActionData
> {
constructor(
actionData: IInsertTextActionData,
@@ -18,7 +23,8 @@ export class InsertTextAction extends DocActionBase<
super(actionData, commandUnit, observers);
this._doActionData = { ...actionData };
this.do();
- this._oldActionData = { ...actionData };
+ const { length, start } = actionData;
+ this._oldActionData = { ...actionData, start: start + length };
}
redo(): void {
@@ -28,12 +34,27 @@ export class InsertTextAction extends DocActionBase<
do(): void {
const actionData = this.getDoActionData();
const document = this.getDocument();
- InsertTextApply(document, actionData.text);
+ const { text, start, length, segmentId } = actionData;
+ InsertTextApply(document, { text, start, length, segmentId });
+
+ this._observers.notifyObservers({
+ type: ActionType.REDO,
+ data: this._doActionData,
+ action: this,
+ });
}
undo(): void {
- // TODO ...
- // ...
+ const actionData = this.getOldActionDaa();
+ const document = this.getDocument();
+ const { length, start, segmentId } = actionData;
+ DeleteTextApply(document, { length, start, segmentId });
+
+ this._observers.notifyObservers({
+ type: ActionType.UNDO,
+ data: this._oldActionData,
+ action: this,
+ });
}
validate(): boolean {
diff --git a/packages/core/src/Docs/Action/MergeParagraphAction.ts b/packages/core/src/Docs/Action/MergeParagraphAction.ts
new file mode 100644
index 0000000000..0aa4a534ce
--- /dev/null
+++ b/packages/core/src/Docs/Action/MergeParagraphAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IMergeParagraphActionData extends IDocActionData {
+ text: string;
+}
+
+export class MergeParagraphAction extends DocActionBase<
+ IMergeParagraphActionData,
+ IMergeParagraphActionData
+> {
+ constructor(
+ actionData: IMergeParagraphActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/MoveParagraphAction.ts b/packages/core/src/Docs/Action/MoveParagraphAction.ts
new file mode 100644
index 0000000000..d9b52a126e
--- /dev/null
+++ b/packages/core/src/Docs/Action/MoveParagraphAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IMoveParagraphActionData extends IDocActionData {
+ text: string;
+}
+
+export class MoveParagraphAction extends DocActionBase<
+ IMoveParagraphActionData,
+ IMoveParagraphActionData
+> {
+ constructor(
+ actionData: IMoveParagraphActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/SetTextStyleAction.ts b/packages/core/src/Docs/Action/SetTextStyleAction.ts
new file mode 100644
index 0000000000..4e0591cba1
--- /dev/null
+++ b/packages/core/src/Docs/Action/SetTextStyleAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface ISetTextStyleActionData extends IDocActionData {
+ text: string;
+}
+
+export class SetTextStyleAction extends DocActionBase<
+ ISetTextStyleActionData,
+ ISetTextStyleActionData
+> {
+ constructor(
+ actionData: ISetTextStyleActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/SplitParagraphAction.ts b/packages/core/src/Docs/Action/SplitParagraphAction.ts
new file mode 100644
index 0000000000..53456b1917
--- /dev/null
+++ b/packages/core/src/Docs/Action/SplitParagraphAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface ISplitParagraphAction extends IDocActionData {
+ text: string;
+}
+
+export class SplitParagraphAction extends DocActionBase<
+ ISplitParagraphAction,
+ ISplitParagraphAction
+> {
+ constructor(
+ actionData: ISplitParagraphAction,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/UpdateDocumentAction.ts b/packages/core/src/Docs/Action/UpdateDocumentAction.ts
new file mode 100644
index 0000000000..3f5c63b1f0
--- /dev/null
+++ b/packages/core/src/Docs/Action/UpdateDocumentAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IUpdateDocumentActionData extends IDocActionData {
+ text: string;
+}
+
+export class UpdateDocumentAction extends DocActionBase<
+ IUpdateDocumentActionData,
+ IUpdateDocumentActionData
+> {
+ constructor(
+ actionData: IUpdateDocumentActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/UpdateParagraphAction.ts b/packages/core/src/Docs/Action/UpdateParagraphAction.ts
new file mode 100644
index 0000000000..66872d6b8e
--- /dev/null
+++ b/packages/core/src/Docs/Action/UpdateParagraphAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IUpdateParagraphActionData extends IDocActionData {
+ text: string;
+}
+
+export class UpdateParagraphAction extends DocActionBase<
+ IUpdateParagraphActionData,
+ IUpdateParagraphActionData
+> {
+ constructor(
+ actionData: IUpdateParagraphActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/UpdateSectionAction.ts b/packages/core/src/Docs/Action/UpdateSectionAction.ts
new file mode 100644
index 0000000000..d307731b36
--- /dev/null
+++ b/packages/core/src/Docs/Action/UpdateSectionAction.ts
@@ -0,0 +1,41 @@
+import { DocActionBase, IDocActionData } from '../../Command/DocActionBase';
+import { ActionObservers, CommandUnit } from '../../Command';
+
+export interface IUpdateSectionActionData extends IDocActionData {
+ text: string;
+}
+
+export class UpdateSectionAction extends DocActionBase<
+ IUpdateSectionActionData,
+ IUpdateSectionActionData
+> {
+ constructor(
+ actionData: IUpdateSectionActionData,
+ commandUnit: CommandUnit,
+ observers: ActionObservers
+ ) {
+ super(actionData, commandUnit, observers);
+ this._doActionData = { ...actionData };
+ this.do();
+ this._oldActionData = { ...actionData };
+ }
+
+ redo(): void {
+ this.do();
+ }
+
+ do(): void {
+ const actionData = this.getDoActionData();
+ const document = this.getDocument();
+ // InsertTextApply(document, actionData.text);
+ }
+
+ undo(): void {
+ // TODO ...
+ // ...
+ }
+
+ validate(): boolean {
+ return false;
+ }
+}
diff --git a/packages/core/src/Docs/Action/index.ts b/packages/core/src/Docs/Action/index.ts
new file mode 100644
index 0000000000..dbf5cdcf6d
--- /dev/null
+++ b/packages/core/src/Docs/Action/index.ts
@@ -0,0 +1,11 @@
+export * from './InsertTextAction';
+export * from './ClearTextStyleAction';
+export * from './DeleteParagraphAction';
+export * from './DeleteTextAction';
+export * from './MergeParagraphAction';
+export * from './MoveParagraphAction';
+export * from './SetTextStyleAction';
+export * from './SplitParagraphAction';
+export * from './UpdateDocumentAction';
+export * from './UpdateParagraphAction';
+export * from './UpdateSectionAction';
diff --git a/packages/core/src/Docs/Apply/Common.ts b/packages/core/src/Docs/Apply/Common.ts
new file mode 100644
index 0000000000..4ff7521059
--- /dev/null
+++ b/packages/core/src/Docs/Apply/Common.ts
@@ -0,0 +1,39 @@
+import { IBlockElement, IElement } from '../../Interfaces/IDocumentData';
+
+export function getTextStartByAnchor(start: number) {
+ let textStart = start - 1;
+
+ textStart = textStart < 0 ? 0 : textStart;
+
+ return textStart;
+}
+
+export function insertTextToContent(content: string, start: number, text: string) {
+ return content.slice(0, start) + text + content.slice(start);
+}
+
+export function deleteContent(content: string, start: number, length: number) {
+ const startDeleteIndex = start - length < 0 ? 0 : start - length;
+ return content.slice(0, startDeleteIndex) + content.slice(start);
+}
+
+export function moveElementCharIndex(element?: IElement, moveIndex: number = 0) {
+ if (element == null) {
+ return;
+ }
+
+ element.st += moveIndex;
+ element.ed += moveIndex;
+}
+
+export function moveBlockCharIndex(
+ blockElement?: IBlockElement,
+ moveIndex: number = 0
+) {
+ if (blockElement == null) {
+ return;
+ }
+
+ blockElement.st += moveIndex;
+ blockElement.ed += moveIndex;
+}
diff --git a/packages/core/src/Docs/Apply/DeleteTextApply.ts b/packages/core/src/Docs/Apply/DeleteTextApply.ts
new file mode 100644
index 0000000000..d00c9b2da7
--- /dev/null
+++ b/packages/core/src/Docs/Apply/DeleteTextApply.ts
@@ -0,0 +1,136 @@
+import { BooleanNumber } from '../../Enum/TextStyle';
+import {
+ BlockType,
+ IParagraph,
+ ParagraphElementType,
+} from '../../Interfaces/IDocumentData';
+import { DocumentModel } from '../Domain/DocumentModel';
+import {
+ deleteContent,
+ getTextStartByAnchor,
+ moveBlockCharIndex,
+ moveElementCharIndex,
+} from './Common';
+
+export function DeleteTextApply(
+ document: DocumentModel,
+ config: { start: number; length: number; segmentId?: string }
+) {
+ const doc = document.getSnapshot();
+ const { start, length, segmentId } = config;
+
+ const textStart = getTextStartByAnchor(start);
+
+ let body = doc.body;
+
+ if (length === 0) {
+ return;
+ }
+
+ if (segmentId) {
+ const { headers, footers } = doc;
+ if (headers?.[segmentId]) {
+ body = headers[segmentId].body;
+ } else if (footers?.[segmentId]) {
+ body = footers[segmentId].body;
+ }
+ }
+
+ if (body == null) {
+ throw new Error('no body has changed');
+ }
+
+ const { blockElements, blockElementOrder } = body;
+
+ let isApplied = false;
+
+ for (let blockId of blockElementOrder) {
+ const blockElement = blockElements[blockId];
+ if (blockElement == null) {
+ continue;
+ }
+
+ const { st, ed, blockType } = blockElement;
+
+ if (isApplied) {
+ switch (blockType) {
+ case BlockType.PARAGRAPH:
+ moveBlockCharIndex(blockElement, -length);
+ break;
+ }
+ continue;
+ }
+
+ if (textStart < st || textStart > ed) {
+ continue;
+ }
+
+ switch (blockType) {
+ case BlockType.PARAGRAPH:
+ isApplied = paragraphApply(
+ start,
+ textStart,
+ length,
+ blockElement.paragraph
+ );
+ blockElement.ed -= length;
+ break;
+ }
+ }
+}
+
+function paragraphApply(
+ start: number,
+ textStart: number,
+ length: number,
+ paragraph?: IParagraph
+) {
+ let isApply = false;
+
+ if (paragraph == null) {
+ return isApply;
+ }
+
+ const { elements, elementOrder } = paragraph;
+
+ for (let elementInfo of elementOrder) {
+ const { elementId, paragraphElementType } = elementInfo;
+ const element = elements[elementId];
+
+ const { st, ed, tr } = element;
+
+ if (isApply) {
+ moveElementCharIndex(element, -length);
+ }
+
+ if (textStart < st || textStart > ed) {
+ continue;
+ }
+
+ if (tr == null) {
+ continue;
+ }
+
+ if (paragraphElementType === ParagraphElementType.TEXT_RUN) {
+ let relative = textStart - st + 1;
+
+ if (start === 0) {
+ relative = 0;
+ }
+
+ isApply = true;
+
+ if (tr.tab === BooleanNumber.TRUE) {
+ continue;
+ }
+
+ const newContent = deleteContent(tr.ct || '', relative, length);
+
+ tr.ct = newContent;
+
+ element.ed += length;
+ }
+ }
+
+ return isApply;
+}
diff --git a/packages/core/src/Docs/Apply/InsertTextApply.ts b/packages/core/src/Docs/Apply/InsertTextApply.ts
index de8f025b5b..89351819a8 100644
--- a/packages/core/src/Docs/Apply/InsertTextApply.ts
+++ b/packages/core/src/Docs/Apply/InsertTextApply.ts
@@ -1,5 +1,152 @@
-import { Document } from '../Domain/Document';
+import { BooleanNumber } from '../../Enum/TextStyle';
+import {
+ BlockType,
+ IBlockElement,
+ IParagraph,
+ ParagraphElementType,
+} from '../../Interfaces/IDocumentData';
+import { DocumentModel } from '../Domain/DocumentModel';
+import {
+ getTextStartByAnchor,
+ insertTextToContent,
+ moveBlockCharIndex,
+ moveElementCharIndex,
+} from './Common';
-export function InsertTextApply(document: Document, text: string) {
- // TODO ...
+export function InsertTextApply(
+ document: DocumentModel,
+ config: { text: string; start: number; length: number; segmentId?: string }
+) {
+ const doc = document.getSnapshot();
+ const { text, start, length, segmentId } = config;
+
+ const textStart = getTextStartByAnchor(start);
+
+ let body = doc.body;
+
+ if (length === 0) {
+ return;
+ }
+
+ if (segmentId) {
+ const { headers, footers } = doc;
+ if (headers?.[segmentId]) {
+ body = headers[segmentId].body;
+ } else if (footers?.[segmentId]) {
+ body = footers[segmentId].body;
+ }
+ }
+
+ if (body == null) {
+ throw new Error('no body has changed');
+ }
+
+ const { blockElements, blockElementOrder } = body;
+
+ let isApplied = false;
+
+ for (let blockId of blockElementOrder) {
+ const blockElement = blockElements[blockId];
+ if (blockElement == null) {
+ continue;
+ }
+
+ const { blockType } = blockElement;
+
+ switch (blockType) {
+ case BlockType.PARAGRAPH:
+ isApplied = paragraphApply(
+ text,
+ start,
+ textStart,
+ length,
+ blockElement,
+ blockElement.paragraph,
+ isApplied
+ );
+ blockElement.ed += length;
+ break;
+ }
+ }
+}
+
+function paragraphApply(
+ text: string,
+ start: number,
+ textStart: number,
+ length: number,
+ blockElement: IBlockElement,
+ paragraph?: IParagraph,
+ isApplied: boolean = false
+) {
+ if (isApplied) {
+ moveBlockCharIndex(blockElement, length);
+ }
+
+ const { st, ed } = blockElement;
+
+ let isApply = false;
+
+ if (textStart < st) {
+ return isApply;
+ }
+
+ if (paragraph == null) {
+ return isApply;
+ }
+
+ const { elements, elementOrder } = paragraph;
+
+ for (let elementInfo of elementOrder) {
+ const { elementId, paragraphElementType } = elementInfo;
+ const element = elements[elementId];
+
+ if (paragraphElementType === ParagraphElementType.DRAWING) {
+ continue;
+ }
+
+ const { st, ed, tr } = element;
+
+ if (isApply || isApplied) {
+ moveElementCharIndex(element, length);
+ }
+
+ if (isApplied) {
+ continue;
+ }
+
+ if (textStart < st || textStart > ed) {
+ continue;
+ }
+
+ if (tr == null) {
+ continue;
+ }
+
+ if (paragraphElementType === ParagraphElementType.TEXT_RUN) {
+ let relative = textStart - st + 1;
+
+ if (start === 0) {
+ relative = 0;
+ }
+
+ isApply = true;
+
+ if (tr.tab === BooleanNumber.TRUE) {
+ continue;
+ }
+
+ const newContent = insertTextToContent(tr.ct || '', relative, text);
+
+ tr.ct = newContent;
+
+ element.ed += length;
+ }
+ }
+
+ if (isApplied) {
+ return true;
+ }
+
+ return isApply;
}
diff --git a/packages/core/src/Docs/Apply/index.ts b/packages/core/src/Docs/Apply/index.ts
new file mode 100644
index 0000000000..78fd705807
--- /dev/null
+++ b/packages/core/src/Docs/Apply/index.ts
@@ -0,0 +1,2 @@
+export * from './InsertTextApply';
+export * from './DeleteTextApply';
diff --git a/packages/core/src/Docs/Domain/Document.ts b/packages/core/src/Docs/Domain/Document.ts
deleted file mode 100644
index 514852b574..0000000000
--- a/packages/core/src/Docs/Domain/Document.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import { nanoid } from 'nanoid';
-import { DocContext } from '../../Basics';
-import { Command } from '../../Command';
-import { IDocumentData } from '../../Interfaces';
-import { DEFAULT_DOC } from '../../Const';
-
-export class Document {
- private _config: IDocumentData;
-
- private _context: DocContext;
-
- private _unitId: string;
-
- constructor(config: Partial<IDocumentData>, context: DocContext) {
- this._context = context;
- this._config = { ...DEFAULT_DOC, ...config };
- this._unitId = this._config.documentId ?? nanoid(6);
- }
-
- getUnitId(): string {
- return this._unitId;
- }
-
- insertText(text: string): Document {
- const { _context } = this;
- const _commandManager = _context.getCommandManager();
- const insertTextAction = {
- actionName: 'InsertTextAction',
- text,
- };
- const command = new Command(
- {
- DocumentUnit: this,
- },
- insertTextAction
- );
- _commandManager.invoke(command);
- return this;
- }
-}
diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.ts
new file mode 100644
index 0000000000..65731402a0
--- /dev/null
+++ b/packages/core/src/Docs/Domain/DocumentModel.ts
@@ -0,0 +1,97 @@
+import { nanoid } from 'nanoid';
+import { DocContext } from '../../Basics';
+import { Command } from '../../Command';
+import { IDocumentData } from '../../Interfaces';
+import { DEFAULT_DOC } from '../../Const';
+import { DOC_ACTION_NAMES } from '../../Const/DOC_ACTION_NAMES';
+
+export class DocumentModel {
+ private _snapshot: IDocumentData;
+
+ private _context: DocContext;
+
+ private _unitId: string;
+
+ constructor(snapshot: Partial<IDocumentData>, context: DocContext) {
+ this._context = context;
+ this._snapshot = { ...DEFAULT_DOC, ...snapshot };
+ this._unitId = this._snapshot.documentId ?? nanoid(6);
+ }
+
+ getSnapshot() {
+ return this._snapshot;
+ }
+
+ getUnitId(): string {
+ return this._unitId;
+ }
+
+ insertText(text: string, start: number, segmentId?: string): DocumentModel {
+ const { _context } = this;
+ const _commandManager = _context.getCommandManager();
+ const insertTextAction = {
+ actionName: DOC_ACTION_NAMES.INSERT_TEXT_ACTION_NAME,
+ text,
+ start,
+ length: text.length,
+ segmentId,
+ };
+ const command = new Command(
+ {
+ DocumentUnit: this,
+ },
+ insertTextAction
+ );
+ _commandManager.invoke(command);
+ return this;
+ }
+
+ deleteText(text: string, start: number, segmentId?: string): DocumentModel {
+ const { _context } = this;
+ const _commandManager = _context.getCommandManager();
+ const deleteTextAction = {
+ actionName: DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME,
+ text,
+ start,
+ length: text.length,
+ segmentId,
+ };
+ const command = new Command(
+ {
+ DocumentUnit: this,
+ },
+ deleteTextAction
+ );
+ _commandManager.invoke(command);
+ return this;
+ }
+
+ updateText(newText: string, oldText: string, start: number, segmentId?: string) {
+ const { _context } = this;
+ const _commandManager = _context.getCommandManager();
+
+ const deleteTextAction = {
+ actionName: DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME,
+ text: oldText,
+ start: start + oldText.length,
+ length: oldText.length,
+ segmentId,
+ };
+ const insertTextAction = {
+ actionName: DOC_ACTION_NAMES.INSERT_TEXT_ACTION_NAME,
+ text: newText,
+ start,
+ length: newText.length,
+ segmentId,
+ };
+ const command = new Command(
+ {
+ DocumentUnit: this,
+ },
+ deleteTextAction,
+ insertTextAction
+ );
+ _commandManager.invoke(command);
+ return this;
+ }
+}
diff --git a/packages/core/src/Docs/Domain/index.ts b/packages/core/src/Docs/Domain/index.ts
new file mode 100644
index 0000000000..94fa326abe
--- /dev/null
+++ b/packages/core/src/Docs/Domain/index.ts
@@ -0,0 +1 @@
+export * from './DocumentModel';
diff --git a/packages/core/src/Docs/index.ts b/packages/core/src/Docs/index.ts
index e69de29bb2..5eac8de3bd 100644
--- a/packages/core/src/Docs/index.ts
+++ b/packages/core/src/Docs/index.ts
@@ -0,0 +1,3 @@
+export * from './Action';
+export * from './Apply';
+export * from './Domain';
diff --git a/packages/core/src/Enum/KeyCode.ts b/packages/core/src/Enum/KeyCode.ts
index 5a796423f1..cd3831b9e5 100644
--- a/packages/core/src/Enum/KeyCode.ts
+++ b/packages/core/src/Enum/KeyCode.ts
@@ -42,3 +42,11 @@ export enum KeyCode {
NUM_LOCK = 144,
SCROLL_LOCK = 145,
}
+
+/**
+ * https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/
+ */
+export enum KeyboardKeyType {
+ backspace = 'Backspace',
+ delete = 'Delete',
+}
diff --git a/packages/core/src/Interfaces/IDocumentData.ts b/packages/core/src/Interfaces/IDocumentData.ts
index 51036cbf7d..8024494836 100644
--- a/packages/core/src/Interfaces/IDocumentData.ts
+++ b/packages/core/src/Interfaces/IDocumentData.ts
@@ -13,7 +13,7 @@ import {
* Properties of document
*/
export interface IDocumentData extends IReferenceSource {
- documentId: string;
+ documentId: string; // unit id
locale?: LocaleType;
title?: string;
body?: IDocumentBody;
diff --git a/packages/core/src/Interfaces/ISlideData.ts b/packages/core/src/Interfaces/ISlideData.ts
index cfb33f7aba..bc34287ff0 100644
--- a/packages/core/src/Interfaces/ISlideData.ts
+++ b/packages/core/src/Interfaces/ISlideData.ts
@@ -1,7 +1,100 @@
-import { LocaleType } from '../Enum';
+import { LocaleType, ThemeColorType } from '../Enum';
+import { ICustomBlock, ILists, ISizeData } from './IDocumentData';
+import { IColorStyle } from './IStyleData';
-export interface ISlideData {
- slideId: string;
+export interface ISlideData extends IReferenceSource {
+ id: string; // unit id
locale?: LocaleType;
title?: string;
+ pageSize: ISizeData;
+ body: ISlidePageBody;
+}
+
+interface IReferenceSource {
+ master?: { [id: string]: ISlidePage };
+ handoutMaster?: { [id: string]: ISlidePage };
+ notesMaster?: { [id: string]: ISlidePage };
+ layouts?: { [id: string]: ISlidePage };
+ lists?: ILists;
+}
+
+interface ISlidePageBody {
+ slides: { [id: string]: ISlidePage };
+ slideOrder: string[];
+}
+
+export interface ISlidePage {
+ id: string;
+ pageType: PageType;
+ title: string;
+ description: string;
+ pageBackgroundFill: IColorStyle;
+ colorScheme?: ThemeColorType;
+ pageElements: { [elementId: string]: IPageElement };
+ pageElementOrder: string[];
+ // Union field properties. Properties that are specific for each page type. Masters do not require any additional properties. properties can be only one of the following:
+ slideProperties?: ISlideProperties;
+ layoutProperties?: ILayoutProperties;
+ notesProperties?: INotesProperties;
+ handoutProperties?: IHandoutProperties;
+ masterProperties?: IMasterProperties;
+}
+
+interface ISlideProperties {
+ layoutObjectId: string;
+ masterObjectId: string;
+ isSkipped: boolean;
+}
+
+interface ILayoutProperties {
+ masterObjectId: string;
+ name: string;
+}
+
+interface INotesProperties {
+ name: string;
+}
+
+interface IHandoutProperties {
+ name: string;
+}
+
+interface IMasterProperties {
+ name: string;
+}
+
+export interface IPageElement {
+ id: string;
+ left: number;
+ top: number;
+ width: number;
+ height: number;
+ angle: number;
+ scaleX: number;
+ scaleY: number;
+ skewX: number;
+ skewY: number;
+ flipX: boolean;
+ flipY: boolean;
+
+ title: string;
+ description: string;
+
+ // Union field element_kind can be only one of the following:
+ // elementGroup: IGroup;
+ // shape: IShapeProperties;
+ // image: IImageProperties;
+ // video: IVideo;
+ // line: ILine;
+ // table: ITable;
+ // chart: IChartProperties;
+ customBlock?: ICustomBlock; // customBlock 用户通过插件自定义的block
+}
+
+export enum PageType {
+ SLIDE, // A slide page.
+ MASTER, // A master slide page.
+ LAYOUT, // A layout page.
+ HANDOUT_MASTER, // A handout master page.
+ NOTES_MASTER, // A notes master page.
}
diff --git a/packages/core/src/Interfaces/IWorkbookData.ts b/packages/core/src/Interfaces/IWorkbookData.ts
index dff2f8d511..e4a6c92ff4 100644
--- a/packages/core/src/Interfaces/IWorkbookData.ts
+++ b/packages/core/src/Interfaces/IWorkbookData.ts
@@ -10,7 +10,7 @@ import { INamedRange } from './INamedRange';
export interface IWorkbookConfig {
createdTime: string;
lastModifiedBy: string;
- id: string;
+ id: string; // unit id
locale: LocaleType;
name: string;
theme: string;
diff --git a/packages/core/src/Shared/Logger.ts b/packages/core/src/Shared/Logger.ts
index f8580281ce..3e0049d802 100644
--- a/packages/core/src/Shared/Logger.ts
+++ b/packages/core/src/Shared/Logger.ts
@@ -2,12 +2,18 @@
* Logging tool
*/
export class Logger {
- static info(...value: unknown[]): void {
+ static log(...value: unknown[]): void {
if (console) {
console.log(...value);
}
}
+ static info(...value: unknown[]): void {
+ if (console) {
+ console.info(...value);
+ }
+ }
+
static error(...value: unknown[]): void {
if (console) {
console.error(...value);
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index ba0b913f1e..55cb8ffcad 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -17,6 +17,7 @@ export * from './Command';
export * from './Const';
export * from './Convertor';
export * from './Sheets/Domain';
+export * from './Docs/Domain';
export * from './Enum';
export * from './Interfaces';
export * from './IOC';