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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
refactor: move mutations to new command service (#111)
Wenzhao Hua572446aeebc
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex 6d9d78ea8d..004b5b58e5 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -34,11 +34,12 @@ univer.registerPlugin(SheetUIPlugin, {},},});-univer.registerPlugin(NumfmtPlugin);-univer.registerPlugin(FindPlugin);-univer.registerPlugin(FormulaPlugin, DEFAULT_FORMULA_DATA_DEMO);-univer.registerPlugin(ImportXlsxPlugin);-univer.registerPlugin(ImagePlugin);++// univer.registerPlugin(NumfmtPlugin);+// univer.registerPlugin(FindPlugin);+// univer.registerPlugin(FormulaPlugin, DEFAULT_FORMULA_DATA_DEMO);+// univer.registerPlugin(ImportXlsxPlugin);+// univer.registerPlugin(ImagePlugin);// univer.registerPlugin(OperationPlugin);// use for console testdiff --git a/packages/base-docs/src/Controller/InputController.ts b/packages/base-docs/src/Controller/InputController.tsindex 01285fdbb3..1c20603d66 100644--- a/packages/base-docs/src/Controller/InputController.ts+++ b/packages/base-docs/src/Controller/InputController.ts@@ -13,9 +13,10 @@ import {isSameLine,TextSelection,} from '@univerjs/base-render';-import { DataStreamTreeTokenType, Direction, DocumentModel, ICurrentUniverService, IParagraph, Nullable, Observable, UpdateDocsAttributeType } from '@univerjs/core';+import { DataStreamTreeTokenType, Direction, DocumentModel, ICommandService, ICurrentUniverService, IParagraph, Nullable, Observable } from '@univerjs/core';import { Inject } from '@wendellhu/redi';+import { DeleteCommand, IMEInputCommand, InsertCommand, UpdateCommand } from '../commands/commands/core-editing.command';import { CanvasView } from '../View/Render/CanvasView';import { DocsView } from '../View/Render/Views';@@ -26,7 +27,11 @@ export class InputController {private _currentNodePosition: Nullable<INodePosition>;- constructor(@Inject(CanvasView) private readonly _canvasView: CanvasView, @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService) {+ constructor(+ @Inject(CanvasView) private readonly _canvasView: CanvasView,+ @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,+ @ICommandService private readonly _commandService: ICommandService+ ) {this._initialize();}@@ -175,18 +180,21 @@ export class InputController {}}- docsModel.update(- { dataStream: '', paragraphs: [{ ...updateParagraph }] },- {+ this._commandService.executeCommand(UpdateCommand.id, {+ unitId: docsModel.getUnitId(),+ body: {+ dataStream: '',+ paragraphs: [{ ...updateParagraph }],+ },+ range: {cursorStart: paragraphIndex,cursorEnd: paragraphIndex,isEndBack: false,isStartBack: false,isCollapse: true,},- UpdateDocsAttributeType.REPLACE,- segmentId- );+ segmentId,+ });} else {const endNodePosition = activeSelection?.getEnd();if (endNodePosition != null) {@@ -195,10 +203,15 @@ export class InputController {activeRange.cursorEnd -= 1;}}- docsModel.delete(activeRange, segmentId);++ this._commandService.executeCommand(DeleteCommand.id, {+ unitId: docsModel.getUnitId(),+ range: activeRange,+ segmentId,+ });}- skeleton.calculate();+ skeleton?.calculate();let isBack = false;@@ -242,14 +255,15 @@ export class InputController {const selectionRemain = document.remainActiveSelection() as TextSelection | undefined;- docsModel.insert(- {+ this._commandService.executeCommand(InsertCommand.id, {+ unitId: docsModel.getUnitId(),+ body: {dataStream: DataStreamTreeTokenType.PARAGRAPH,paragraphs: this._generateParagraph(DataStreamTreeTokenType.PARAGRAPH),},- activeRange,- segmentId- );+ range: activeRange,+ segmentId,+ });skeleton?.calculate();@@ -288,7 +302,14 @@ export class InputController {const selectionRemain = document.remainActiveSelection() as TextSelection | undefined;- docsModel.insert({ dataStream: content }, activeRange, segmentId);+ this._commandService.executeCommand(InsertCommand.id, {+ unitId: docsModel.getUnitId(),+ body: {+ dataStream: content,+ },+ range: activeRange,+ segmentId,+ });skeleton.calculate();@@ -325,7 +346,7 @@ export class InputController {this._previousIMEStart = cursor;});- onCompositionupdateObservable.add((config) => {+ onCompositionupdateObservable.add(async (config) => {const { event, document, activeSelection } = config;let cursor = this._previousIMEStart;@@ -348,7 +369,13 @@ export class InputController {const selectionRemain = document.remainActiveSelection() as TextSelection | undefined;- docsModel.IMEInput(content, this._previousIMEContent.length, cursor, segmentId);+ await this._commandService.executeCommand(IMEInputCommand.id, {+ unitId: docsModel.getUnitId(),+ newText: content,+ oldTextLen: this._previousIMEContent.length,+ start: cursor,+ segmentId,+ });skeleton.calculate();diff --git a/packages/base-docs/src/DocPlugin.ts b/packages/base-docs/src/DocPlugin.tsindex d2794dd44d..90c587bc53 100644--- a/packages/base-docs/src/DocPlugin.ts+++ b/packages/base-docs/src/DocPlugin.ts@@ -4,7 +4,8 @@ import { ICommandService, LocaleService, ObserverManager, Plugin, PLUGIN_NAMES,import { Dependency, Inject, Injector } from '@wendellhu/redi';import { DocPluginObserve, install } from './Basics/Observer';-import { BreakLineCommand, DeleteLeftCommand } from './commands/commands/core-editing.command';+import { BreakLineCommand, DeleteCommand, DeleteLeftCommand, IMEInputCommand, InsertCommand, UpdateCommand } from './commands/commands/core-editing.command';+import { RichTextEditingMutation } from './commands/mutations/core-editing.mutation';import { MoveCursorOperation } from './commands/operations/cursor.operation';import { DocumentController } from './Controller/DocumentController';import { en, zh } from './Locale';@@ -39,6 +40,7 @@ export class DocPlugin extends Plugin<DocPluginObserve> {this._config = Object.assign(DEFAULT_DOCUMENT_PLUGIN_DATA, config);this._initializeDependencies(_injector);+ this.initializeCommands();}initialize(): void {@@ -49,15 +51,17 @@ export class DocPlugin extends Plugin<DocPluginObserve> {install(this);- [MoveCursorOperation, DeleteLeftCommand, BreakLineCommand].forEach((command) => {+ this.listenEventManager();+ }++ initializeCommands(): void {+ [MoveCursorOperation, DeleteLeftCommand, BreakLineCommand, InsertCommand, DeleteCommand, UpdateCommand, IMEInputCommand, RichTextEditingMutation].forEach((command) => {this._injector.get(ICommandService).registerCommand(command);});[MoveCursorUpShortcut, MoveCursorDownShortcut, MoveCursorRightShortcut, MoveCursorLeftShortcut, DeleteLeftShortcut, BreakLineShortcut].forEach((shortcut) => {this._injector.get(IShortcutService).registerShortcut(shortcut);});-- this.listenEventManager();}initializeAfterUI() {diff --git a/packages/base-docs/src/commands/commands/core-editing.command.ts b/packages/base-docs/src/commands/commands/core-editing.command.tsindex 0b72fcfc19..b8eba20ba2 100644--- a/packages/base-docs/src/commands/commands/core-editing.command.ts+++ b/packages/base-docs/src/commands/commands/core-editing.command.ts@@ -1,6 +1,17 @@-import { CommandType, ICommand } from '@univerjs/core';+import {+ CommandType,+ getTextIndexByCursor,+ ICommand,+ ICommandInfo,+ ICommandService,+ IDocumentBody,+ ITextSelectionRange,+ IUndoRedoService,+ UpdateDocsAttributeType,+} from '@univerjs/core';import { InputController } from '../../Controller/InputController';+import { IDeleteMutationParams, IRetainMutationParams, IRichTextEditingMutationParams, RichTextEditingMutation } from '../mutations/core-editing.mutation';export const DeleteLeftCommand: ICommand = {id: 'doc.command.delete-left',@@ -21,3 +32,284 @@ export const BreakLineCommand: ICommand = {return true;},};++export interface IInsertCommandParams {+ unitId: string;+ body: IDocumentBody;+ range: ITextSelectionRange;+ segmentId?: string;+}++/**+ * The command to insert text. The changed range could be non-collapsed.+ */+export const InsertCommand: ICommand<IInsertCommandParams> = {+ id: 'doc.command.insert-text',+ type: CommandType.COMMAND,+ handler: async (accessor, params: IInsertCommandParams) => {+ const undoRedoService = accessor.get(IUndoRedoService);+ const commandService = accessor.get(ICommandService);++ const { range, segmentId, body, unitId } = params;+ const { cursorStart, cursorEnd, isEndBack, isStartBack, isCollapse } = range;+ const textStart = getTextIndexByCursor(cursorStart, isStartBack);++ const doMutation: ICommandInfo<IRichTextEditingMutationParams> = {+ id: RichTextEditingMutation.id,+ params: {+ unitId,+ mutations: [],+ },+ };+ if (isCollapse) {+ doMutation.params!.mutations.push({+ t: 'r',+ len: textStart + 1,+ segmentId,+ });+ } else {+ doMutation.params!.mutations.push(...getRetainAndDeleteFromReplace(range, segmentId));+ }+ doMutation.params!.mutations.push({+ t: 'i',+ body,+ len: body.dataStream.length,+ line: 0, // FIXME: line shouldn't be 0 here?+ segmentId,+ });++ const undoMutation: ICommandInfo<IRichTextEditingMutationParams> = {+ id: RichTextEditingMutation.id,+ params: {+ unitId,+ mutations: [],+ },+ };++ // TODO@wzhudev: prepare undo mutation++ const result = await commandService.executeCommand<IRichTextEditingMutationParams, IRichTextEditingMutationParams>(doMutation.id, doMutation.params);+ if (result) {+ undoRedoService.pushUndoRedo({+ URI: 'doc',+ undo() {+ commandService.executeCommand(RichTextEditingMutation.id, result);+ return true;+ },+ redo() {+ commandService.executeCommand(RichTextEditingMutation.id, doMutation.params);+ return true;+ },+ });++ return true;+ }++ return false;+ },+};++export interface IDeleteCommandParams {+ unitId: string;+ range: ITextSelectionRange;+ segmentId?: string;+}++/**+ * The command to delete text.+ */+export const DeleteCommand: ICommand<IDeleteCommandParams> = {+ id: 'doc.command.delete-text',+ type: CommandType.COMMAND,+ handler: async (accessor, params) => {+ if (!params) {+ throw new Error();+ }++ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);++ const { range, segmentId, unitId } = params;+ const doMutation: ICommandInfo<IRichTextEditingMutationParams> = {+ id: RichTextEditingMutation.id,+ params: {+ unitId,+ mutations: [],+ },+ };++ doMutation.params!.mutations.push(...getRetainAndDeleteFromReplace(range, segmentId));++ const result = await commandService.executeCommand<IRichTextEditingMutationParams, IRichTextEditingMutationParams>(doMutation.id, doMutation.params);+ if (result) {+ undoRedoService.pushUndoRedo({+ URI: 'doc',+ undo() {+ commandService.executeCommand(RichTextEditingMutation.id, result);+ return true;+ },+ redo() {+ commandService.executeCommand(doMutation.id, doMutation.params);+ return true;+ },+ });+ return false;+ }++ return false;+ },+};++export interface IUpdateCommandParams {+ unitId: string;+ updateBody: IDocumentBody;+ range: ITextSelectionRange;+ coverType: UpdateDocsAttributeType;+ segmentId?: string;+}++/**+ * The command to update text properties.+ */+export const UpdateCommand: ICommand<IUpdateCommandParams> = {+ id: 'doc.command.update-text',+ type: CommandType.COMMAND,+ handler: async (accessor, params) => {+ if (!params) {+ throw new Error();+ }++ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);++ const { range, segmentId, updateBody, coverType, unitId } = params;+ const doMutation: ICommandInfo<IRichTextEditingMutationParams> = {+ id: RichTextEditingMutation.id,+ params: {+ unitId,+ mutations: [],+ },+ };++ const { cursorStart, cursorEnd, isEndBack, isStartBack, isCollapse } = range;+ const textStart = getTextIndexByCursor(cursorStart, isStartBack);+ const textEnd = getTextIndexByCursor(cursorEnd, isEndBack);++ doMutation.params!.mutations.push({+ t: 'r',+ len: textStart + 1,+ segmentId,+ });++ doMutation.params!.mutations.push({+ t: 'r',+ body: updateBody,+ len: textEnd - textStart + 1,+ segmentId,+ coverType,+ });++ const result = await commandService.executeCommand<IRichTextEditingMutationParams, IRichTextEditingMutationParams>(doMutation.id, doMutation.params);+ if (result) {+ undoRedoService.pushUndoRedo({+ URI: 'doc',+ undo() {+ commandService.executeCommand(RichTextEditingMutation.id, result);+ return true;+ },+ redo() {+ commandService.executeCommand(RichTextEditingMutation.id, doMutation.params);+ return true;+ },+ });++ return true;+ }++ return false;+ },+};++export interface IIMEInputCommandParams {+ newText: string;+ oldTextLen: number;+ start: number;+ segmentId?: string;+ unitId: string;+}++export const IMEInputCommand: ICommand<IIMEInputCommandParams> = {+ id: 'doc.command.ime-input',+ type: CommandType.COMMAND,+ handler: async (accessor, params: IIMEInputCommandParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);++ const { unitId, newText, oldTextLen, start, segmentId } = params;+ const doMutation: ICommandInfo<IRichTextEditingMutationParams> = {+ id: RichTextEditingMutation.id,+ params: {+ unitId,+ mutations: [],+ },+ };++ doMutation.params!.mutations.push({+ t: 'r',+ len: start + 1,+ segmentId,+ });++ if (oldTextLen > 0) {+ doMutation.params!.mutations.push({+ t: 'd',+ len: oldTextLen,+ line: 0,+ segmentId,+ });+ }++ doMutation.params!.mutations.push({+ t: 'i',+ body: {+ dataStream: newText,+ },+ len: newText.length,+ line: 0,+ segmentId,+ });++ const result = await commandService.executeCommand(doMutation.id, doMutation.params);+ if (!result) {+ // NOTE: maybe we should throw an error here?+ return false;+ }++ return true;+ },+};++function getRetainAndDeleteFromReplace(range: ITextSelectionRange, segmentId?: string): Array<IRetainMutationParams | IDeleteMutationParams> {+ const { cursorStart, cursorEnd, isEndBack, isStartBack, isCollapse } = range;+ const dos: Array<IRetainMutationParams | IDeleteMutationParams> = [];++ const textStart = getTextIndexByCursor(cursorStart, isStartBack) + (isCollapse ? 0 : 1);+ const textEnd = getTextIndexByCursor(cursorEnd, isEndBack);++ if (textStart > 0) {+ dos.push({+ t: 'r',+ len: textStart,+ segmentId,+ });+ }++ dos.push({+ t: 'd',+ len: textEnd - textStart + 1,+ line: 0,+ segmentId,+ });++ return dos;+}diff --git a/packages/base-docs/src/commands/commands/delete.command.ts b/packages/base-docs/src/commands/commands/delete.command.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/base-docs/src/commands/commands/insert.command.ts b/packages/base-docs/src/commands/commands/insert.command.tsdeleted file mode 100644index 9d56ebc157..0000000000--- a/packages/base-docs/src/commands/commands/insert.command.ts+++ /dev/null@@ -1,11 +0,0 @@-import { CommandType, ICommand } from '@univerjs/core';--export const InsertCommand: ICommand = {- id: 'doc.command.insert',- type: CommandType.COMMAND,- handler: async (accessor) => {- // TODO- const a = 0;- return true;- },-};diff --git a/packages/base-docs/src/commands/commands/replace.command.ts b/packages/base-docs/src/commands/commands/replace.command.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/base-docs/src/commands/mutations/core-editing.mutation.ts b/packages/base-docs/src/commands/mutations/core-editing.mutation.tsnew file mode 100644index 0000000000..d9d86d3944--- /dev/null+++ b/packages/base-docs/src/commands/mutations/core-editing.mutation.ts@@ -0,0 +1,115 @@+import { CommandType, ICurrentUniverService, IDocumentBody, IMutation, UpdateDocsAttributeType } from '@univerjs/core';++import { DeleteApply } from './functions/delete-apply';+import { InsertApply } from './functions/insert';+import { UpdateAttributeApply } from './functions/update';++/**+ * Retain mutation is used to move the cursor or to update properties of the text in the given range.+ */+export interface IRetainMutationParams {+ t: 'r';+ len: number;+ segmentId?: string;+ body?: IDocumentBody;+ coverType?: UpdateDocsAttributeType;+}++/**+ * Insert mutation is used to insert text (maybe with rich text properties) at the given position.+ */+export interface IInsertMutationParams {+ t: 'i';+ body: IDocumentBody;+ len: number;+ line: number;+ segmentId?: string;+}++/**+ * Delete mutation is used to delete text at the given position.+ */+export interface IDeleteMutationParams {+ t: 'd';+ line: number;+ len: number;+ segmentId?: string;+}++export interface IRichTextEditingMutationParams {+ unitId: string;+ mutations: Array<IRetainMutationParams | IInsertMutationParams | IDeleteMutationParams>;+}++/**+ * The core mutator to change rich text mutations. The execution result would be undo mutation params. Could be directly+ * send to undo redo service (will be used by the triggering command).+ */+export const RichTextEditingMutation: IMutation<IRichTextEditingMutationParams, IRichTextEditingMutationParams> = {+ id: 'doc.mutation.rich-text-editing',+ type: CommandType.MUTATION,+ handler: async (accessor, params) => {+ const { unitId, mutations } = params;+ const currentUniverService = accessor.get(ICurrentUniverService);++ const document = currentUniverService.getUniverDocInstance(unitId)?.getDocument();+ if (!document) {+ throw new Error(`Document not found for unitId: ${unitId}`);+ }++ const undoMutations: Array<IRetainMutationParams | IInsertMutationParams | IDeleteMutationParams> = [];+ const commonParameter = new CommonParameter();+ commonParameter.reset();+ mutations.forEach((mutation) => {+ if (mutation.t === 'r') {+ const { coverType, body, len, segmentId } = mutation;+ const documentBody = UpdateAttributeApply(document, body, len, commonParameter.cursor, coverType, segmentId);+ commonParameter.moveCursor(len);+ undoMutations.push({+ ...mutation,+ t: 'r',+ coverType: UpdateDocsAttributeType.REPLACE,+ body: documentBody,+ });+ } else if (mutation.t === 'i') {+ const { body, len, segmentId, line } = mutation;+ InsertApply(document, body!, len, commonParameter.cursor, segmentId);+ commonParameter.moveCursor(len);+ undoMutations.push({+ t: 'd',+ len,+ line,+ segmentId,+ });+ } else if (mutation.t === 'd') {+ const { len, segmentId } = mutation;+ const documentBody = DeleteApply(document, len, commonParameter.cursor, segmentId);+ undoMutations.push({+ ...mutation,+ t: 'i',+ body: documentBody,+ });+ } else {+ throw new Error(`Unknown mutation type for mutation: ${mutation}.`);+ }+ });++ return {+ unitId,+ mutations: undoMutations,+ };+ },+};++class CommonParameter {+ cursor: number;++ reset() {+ this.cursor = 0;+ return this;+ }++ moveCursor(pos: number) {+ this.cursor += pos;+ }+}diff --git a/packages/core/src/Docs/Apply/Common.ts b/packages/base-docs/src/commands/mutations/functions/common.tssimilarity index 97%rename from packages/core/src/Docs/Apply/Common.tsrename to packages/base-docs/src/commands/mutations/functions/common.tsindex dbef4c0bae..72aa87a5c6 100644--- a/packages/core/src/Docs/Apply/Common.ts+++ b/packages/base-docs/src/commands/mutations/functions/common.ts@@ -1,9 +1,17 @@-import { isSameStyleTextRun } from '../../Shared/Compare';-import { horizontalLineSegmentsSubtraction } from '../../Shared/DocTool';-import { sortRulesFactory } from '../../Shared/SortRules';-import { Nullable } from '../../Shared/Types';-import { ICustomBlock, ICustomRange, IDocumentBody, IParagraph, ISectionBreak, ITable, ITextRun } from '../../Types/Interfaces/IDocumentData';-import { DataStreamTreeTokenType } from '../Domain/Types';+import {+ DataStreamTreeTokenType,+ horizontalLineSegmentsSubtraction,+ ICustomBlock,+ ICustomRange,+ IDocumentBody,+ IParagraph,+ ISectionBreak,+ isSameStyleTextRun,+ ITable,+ ITextRun,+ Nullable,+ sortRulesFactory,+} from '@univerjs/core';export function insertTextRuns(body: IDocumentBody, insertBody: IDocumentBody, textLength: number, currentIndex: number) {const { textRuns } = body;diff --git a/packages/core/src/Docs/Apply/DeleteApply.ts b/packages/base-docs/src/commands/mutations/functions/delete-apply.tssimilarity index 86%rename from packages/core/src/Docs/Apply/DeleteApply.tsrename to packages/base-docs/src/commands/mutations/functions/delete-apply.tsindex 1f062f8d91..86809e6a4f 100644--- a/packages/core/src/Docs/Apply/DeleteApply.ts+++ b/packages/base-docs/src/commands/mutations/functions/delete-apply.ts@@ -1,8 +1,6 @@-import { DocumentModel } from '../Domain/DocumentModel';-import { getDocsUpdateBody } from '../../Shared/Common';-import { deleteContent } from '../../Shared/DocTool';-import { IDocumentBody } from '../../Types/Interfaces/IDocumentData';-import { deleteCustomBlocks, deleteCustomRanges, deleteParagraphs, deleteSectionBreaks, deleteTables, deleteTextRuns } from './Common';+import { deleteContent, DocumentModel, getDocsUpdateBody, IDocumentBody } from '@univerjs/core';++import { deleteCustomBlocks, deleteCustomRanges, deleteParagraphs, deleteSectionBreaks, deleteTables, deleteTextRuns } from './common';export function DeleteApply(document: DocumentModel, textLength: number, currentIndex: number, segmentId?: string): IDocumentBody {const doc = document.snapshot;diff --git a/packages/core/src/Docs/Apply/InsertApply.ts b/packages/base-docs/src/commands/mutations/functions/insert.tssimilarity index 81%rename from packages/core/src/Docs/Apply/InsertApply.tsrename to packages/base-docs/src/commands/mutations/functions/insert.tsindex de71deff87..a23f0e041e 100644--- a/packages/core/src/Docs/Apply/InsertApply.ts+++ b/packages/base-docs/src/commands/mutations/functions/insert.ts@@ -1,8 +1,6 @@-import { getDocsUpdateBody } from '../../Shared/Common';-import { insertTextToContent } from '../../Shared/DocTool';-import { IDocumentBody } from '../../Types/Interfaces/IDocumentData';-import { DocumentModel } from '../Domain/DocumentModel';-import { insertCustomBlocks, insertCustomRanges, insertParagraphs, insertSectionBreaks, insertTables, insertTextRuns } from './Common';+import { DocumentModel, getDocsUpdateBody, IDocumentBody, insertTextToContent } from '@univerjs/core';++import { insertCustomBlocks, insertCustomRanges, insertParagraphs, insertSectionBreaks, insertTables, insertTextRuns } from './common';export function InsertApply(document: DocumentModel, insertBody: IDocumentBody, textLength: number, currentIndex: number, segmentId?: string) {const doc = document.snapshot;diff --git a/packages/core/src/Docs/Apply/UpdateAttributeApply.ts b/packages/base-docs/src/commands/mutations/functions/update.tssimilarity index 97%rename from packages/core/src/Docs/Apply/UpdateAttributeApply.tsrename to packages/base-docs/src/commands/mutations/functions/update.tsindex 97cdc9b51a..cf7f687772 100644--- a/packages/core/src/Docs/Apply/UpdateAttributeApply.ts+++ b/packages/base-docs/src/commands/mutations/functions/update.ts@@ -1,7 +1,17 @@-import { DocumentModel } from '../Domain/DocumentModel';-import { getDocsUpdateBody } from '../../Shared/Common';-import { UpdateDocsAttributeType } from '../../Shared/CommandEnum';-import { Nullable } from '../../Shared/Types';+import {+ DocumentModel,+ getDocsUpdateBody,+ ICustomBlock,+ ICustomRange,+ IDocumentBody,+ IParagraph,+ ISectionBreak,+ ITable,+ ITextRun,+ Nullable,+ UpdateDocsAttributeType,+} from '@univerjs/core';+import {deleteCustomBlocks,deleteCustomRanges,@@ -13,8 +23,7 @@ import {insertParagraphs,insertTables,insertTextRuns,-} from './Common';-import { ICustomBlock, ICustomRange, IDocumentBody, IParagraph, ISectionBreak, ITable, ITextRun } from '../../Types/Interfaces/IDocumentData';+} from './common';export function UpdateAttributeApply(document: DocumentModel,@@ -23,7 +32,7 @@ export function UpdateAttributeApply(currentIndex: number,coverType = UpdateDocsAttributeType.COVER,segmentId?: string-) {+): IDocumentBody {if (updateBody == null) {return;}diff --git a/packages/base-docs/src/commands/mutations/insert.mutation.ts b/packages/base-docs/src/commands/mutations/insert.mutation.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/packages/base-render/src/Engine.ts b/packages/base-render/src/Engine.tsindex 040734812f..cfce011dd8 100644--- a/packages/base-render/src/Engine.ts+++ b/packages/base-render/src/Engine.ts@@ -1,17 +1,13 @@import { Observable } from '@univerjs/core';-import { DeviceType, IKeyboardEvent, IPointerEvent, PointerInput } from './Basics/IEvents';--import { getSizeForDom, getPointerPrefix, IsSafari, requestNewFrame } from './Basics/Tools';+import { CURSOR_TYPE } from './Basics/Const';+import { DeviceType, IKeyboardEvent, IPointerEvent, PointerInput } from './Basics/IEvents';import { TRANSFORM_CHANGE_OBSERVABLE_TYPE } from './Basics/Interfaces';-import { PerformanceMonitor } from './Basics/PerformanceMonitor';-+import { getPointerPrefix, getSizeForDom, IsSafari, requestNewFrame } from './Basics/Tools';import { Canvas } from './Canvas';-import { Scene } from './Scene';import { ThinEngine } from './ThinEngine';-import { CURSOR_TYPE } from './Basics/Const';export class Engine extends ThinEngine<Scene> {renderEvenInBackground = true;@@ -535,4 +531,4 @@ export class Engine extends ThinEngine<Scene> {return deviceType;}-}\ No newline at end of file+}diff --git a/packages/base-render/src/RenderEngine.ts b/packages/base-render/src/RenderEngine.tsindex 7eacb9c2d2..c89c250e08 100644--- a/packages/base-render/src/RenderEngine.ts+++ b/packages/base-render/src/RenderEngine.ts@@ -1,5 +1,5 @@-import { Injector, Optional, createIdentifier } from '@wendellhu/redi';-import { Plugin, PluginType, PLUGIN_NAMES } from '@univerjs/core';+import { Plugin, PLUGIN_NAMES, PluginType } from '@univerjs/core';+import { createIdentifier, Injector, Optional } from '@wendellhu/redi';import { Engine } from './Engine';@@ -21,4 +21,4 @@ export class RenderEngine extends Plugin {getEngine(): Engine {return this._engine;}-}\ No newline at end of file+}diff --git a/packages/base-sheets/src/Controller/EditTooltipsController.ts b/packages/base-sheets/src/Controller/EditTooltipsController.tsindex 71bf8a6799..9f5322b02f 100644--- a/packages/base-sheets/src/Controller/EditTooltipsController.ts+++ b/packages/base-sheets/src/Controller/EditTooltipsController.ts@@ -1,5 +1,5 @@import { Engine, IRenderingEngine, Layer } from '@univerjs/base-render';-import { CommandManager, ICurrentUniverService, SetWorkSheetActivateAction } from '@univerjs/core';+import { ICurrentUniverService } from '@univerjs/core';import { CANVAS_VIEW_KEY } from '../View';import { EditTooltips, EditTooltipsProps } from '../View/Views';@@ -11,12 +11,6 @@ export class EditTooltipsController {constructor(@IRenderingEngine private readonly _engine: Engine, @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService) {this._editTooltipsPage = new Map();- CommandManager.getActionObservers().add((event) => {- const data = event.data;- if (data.actionName === SetWorkSheetActivateAction.NAME) {- this.refreshEditTooltips();- }- });}removeEditTooltipsByKey(key: string): EditTooltips | null {diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.tsindex 7783d65dc5..596073eabf 100644--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts@@ -1,7 +1,6 @@import { SetSelectionsOperation } from '@Commands/Operations/selection.operation';import { IMouseEvent, IPointerEvent, Rect, ScrollTimer, Spreadsheet, SpreadsheetColumnTitle, SpreadsheetRowTitle } from '@univerjs/base-render';import {- CommandManager,DEFAULT_CELL,DEFAULT_SELECTION,Direction,@@ -30,7 +29,7 @@ import { SheetView } from '../../View/Views/SheetView';import { ColumnTitleController } from './ColumnTitleController';import { DragLineController } from './DragLineController';import { RowTitleController } from './RowTitleController';-import { SelectionController, SELECTION_TYPE } from './SelectionController';+import { SELECTION_TYPE, SelectionController } from './SelectionController';/*** TODO 注册selection拦截,可能在有公式ArrayObject时,fx公式栏显示不同@@ -72,7 +71,6 @@ export class SelectionManager {private readonly _config: ISheetPluginConfig,@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,/** @deprecated use ICommandService instead */- @Inject(CommandManager) private readonly _commandManager: CommandManager,@ICommandService private readonly _commandService: ICommandService,@Inject(Injector) private readonly _injector: Injector,@Inject(ObserverManager) private readonly _observerManager: ObserverManager,@@ -1019,4 +1017,4 @@ export class SelectionManager {private getWorksheetId(): string {return this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();}-}\ No newline at end of file+}diff --git a/packages/base-sheets/src/Controller/SheetContainerController.ts b/packages/base-sheets/src/Controller/SheetContainerController.tsindex c26a80e6ae..dab71c28da 100644--- a/packages/base-sheets/src/Controller/SheetContainerController.ts+++ b/packages/base-sheets/src/Controller/SheetContainerController.ts@@ -1,4 +1,4 @@-import { CommandManager, Disposable, ICommandInfo, ICommandService, ICurrentUniverService, ISheetActionData, SheetActionBase } from '@univerjs/core';+import { Disposable, ICommandInfo, ICommandService, ICurrentUniverService } from '@univerjs/core';import { Inject } from '@wendellhu/redi';import { SetWorksheetActivateMutation } from '../Commands/Mutations/set-worksheet-activate.mutation';@@ -28,40 +28,5 @@ export class SheetContainerController extends Disposable {}}));-- // Monitor all command changes and automatically trigger the refresh of the canvas- CommandManager.getCommandObservers().add(({ actions }) => {- if (!actions || actions.length === 0) return;-- const action = actions[0] as SheetActionBase<ISheetActionData, ISheetActionData, void>;-- const currentUnitId = this._currentUniverService.getCurrentUniverSheetInstance().getUnitId();- // TODO not use try catch- try {- action.getWorkBook();- } catch (error) {- return;- }-- const actionUnitId = action.getWorkBook().getUnitId();-- if (currentUnitId !== actionUnitId) return;-- // Only the currently active worksheet needs to be refreshed- const worksheet = action.getWorkBook().getActiveSheet();- if (worksheet) {- try {- const canvasView = this.canvasView;- if (canvasView) {- this._selectionManager.updateToSheet(worksheet);- canvasView.updateToSheet(worksheet);- this.canvasView.getSheetView().getSpreadsheet().makeDirty(true);- this._selectionManager.renderCurrentControls(false);- }- } catch (error) {- console.info(error);- }- }- });}}diff --git a/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.ts b/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.tsindex 708b0cda46..bdf50645b3 100644--- a/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.ts+++ b/packages/base-slides/src/View/Render/Adaptors/DocsAdaptor.ts@@ -13,7 +13,7 @@ import {ScrollBar,Viewport,} from '@univerjs/base-render';-import { CommandManager, DocumentModel, EventState, IPageElement, LocaleService, PageElementType } from '@univerjs/core';+import { DocumentModel, EventState, IPageElement, LocaleService, PageElementType } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';import { ObjectAdaptor, CanvasObjectProviderRegistry } from '../Adaptor';@@ -31,7 +31,7 @@ export class DocsAdaptor extends ObjectAdaptor {private _liquid = new Liquid();- constructor(@Inject(CommandManager) private readonly _commandManager: CommandManager, @Inject(LocaleService) private readonly _localeService: LocaleService) {+ constructor(@Inject(LocaleService) private readonly _localeService: LocaleService) {super();}@@ -48,7 +48,7 @@ export class DocsAdaptor extends ObjectAdaptor {return;}- const documentSkeleton = DocumentSkeleton.create(new DocumentModel(documentData, this._commandManager), this._localeService);+ const documentSkeleton = DocumentSkeleton.create(new DocumentModel(documentData), this._localeService);const documents = new Documents(DOCS_VIEW_KEY.MAIN, documentSkeleton);diff --git a/packages/base-ui/src/Basics/Register/Paste/PasteExtensionFactory.ts b/packages/base-ui/src/Basics/Register/Paste/PasteExtensionFactory.tsdeleted file mode 100644index b640906686..0000000000--- a/packages/base-ui/src/Basics/Register/Paste/PasteExtensionFactory.ts+++ /dev/null@@ -1,46 +0,0 @@-import { IActionData, Plugin } from '@univerjs/core';-import { IPasteData } from '../../Interfaces/IPasteData';--/**- * 转化table html/json为json- */-export class BasePasteExtension<T extends Plugin = Plugin> {- // protected _json: IKeyValue;- constructor(protected _data: IPasteData, protected _plugin: T) {}-- /**- * Execute the core logic after the check is successful- */- execute(): IActionData[] {- return [{ actionName: '' }];- }-}--/**- * Determine whether to intercept and create BasePasteExtension- */-export class BasePasteExtensionFactory<T extends Plugin = Plugin> {- constructor(protected _plugin: T) {}-- get zIndex() {- return 0;- }-- /**- * Generate Extension- * @param data- * @returns- */- create(data: IPasteData): BasePasteExtension {- return new BasePasteExtension(data, this._plugin);- }-- /**- * Check if this cell needs to be intercepted currently- * @param data- * @returns- */- check(data: IPasteData): false | BasePasteExtension {- return false;- }-}diff --git a/packages/base-ui/src/Basics/Register/Paste/PasteExtensionManager.ts b/packages/base-ui/src/Basics/Register/Paste/PasteExtensionManager.tsdeleted file mode 100644index 5258570024..0000000000--- a/packages/base-ui/src/Basics/Register/Paste/PasteExtensionManager.ts+++ /dev/null@@ -1,102 +0,0 @@-import { Inject } from '@wendellhu/redi';-import { Command, CommandManager, IActionData, ICurrentUniverService } from '@univerjs/core';-import { IPasteData } from '../../Interfaces';-import { PasteType } from '../../Interfaces/PasteType';-import { BasePasteExtension, BasePasteExtensionFactory } from './PasteExtensionFactory';-import { PasteExtensionRegister } from './PasteExtensionRegister';-import { Clipboard } from '../../Shared/Clipboard';--export class PasteExtensionManager {- private _pasteExtensionFactoryList: BasePasteExtensionFactory[];-- // mounted on the instance- private _register: PasteExtensionRegister;-- constructor(@Inject(CommandManager) private readonly _commandManager: CommandManager, @ICurrentUniverService private readonly _currentUniver: ICurrentUniverService) {- this._register = new PasteExtensionRegister();- }-- getRegister(): PasteExtensionRegister {- return this._register;- }-- /**- * inject all actions- */- handle(data: IPasteData) {- const clipboardExtensionFactoryList = this._register?.pasteExtensionFactoryList;- if (!clipboardExtensionFactoryList) return;- // get the sorted list- // get the dynamically added list- this._pasteExtensionFactoryList = clipboardExtensionFactoryList;- this._checkExtension(data);- // const extension = this._checkExtension(data);-- // Need to handle multiple extensions- // if (extension) {- // extension.execute();- // }- }-- pasteResolver(evt?: ClipboardEvent) {- return new Promise((resolve: (value: IPasteData) => void, reject) => {- Clipboard.read(evt).then((file: string | Array<PasteType | null> | null) => {- if (!file) return [];- const data: IPasteData = {};- if (typeof file === 'string') {- data.html = file;- } else {- const HtmlIndex = file.findIndex((item: PasteType | null, index: number) => item && item.type === 'text/html');- const PlainIndex = file.findIndex((item: PasteType | null, index: number) => item && item.type === 'text/plain');-- if (HtmlIndex > -1) {- const html = file[HtmlIndex]?.result as string;- data.html = html;- }- if (PlainIndex > -1) {- const plain = file[PlainIndex]?.result as string;- data.plain = plain;- }- }-- resolve(data);- });- });- }-- protected _invokeAction(actionDataList: IActionData[]) {- // FIXME: this file is inside base-ui but it knows about current univer "sheet"? That is incorrect.- const workbook = this._currentUniver.getCurrentUniverSheetInstance().getWorkBook()!;-- const command = new Command(- {- WorkBookUnit: workbook,- },- ...actionDataList- );-- this._commandManager.invoke(command);- }-- /**- * Execute when the action is matched- *- * @param data- *- * @returns- */- private _checkExtension(data: IPasteData) {- if (!this._pasteExtensionFactoryList) return false;- let actionDataList: IActionData[] = [];- let extension: BasePasteExtension | false = false;- for (let index = 0; index < this._pasteExtensionFactoryList.length; index++) {- const extensionFactory = this._pasteExtensionFactoryList[index];- extension = extensionFactory.check(data);- if (extension !== false) {- const extensionActionList = extension.execute();- actionDataList = actionDataList.concat(extensionActionList);- }- }- this._invokeAction(actionDataList);- }-}diff --git a/packages/base-ui/src/Basics/Register/Paste/PasteExtensionRegister.ts b/packages/base-ui/src/Basics/Register/Paste/PasteExtensionRegister.tsdeleted file mode 100644index 25fb87175f..0000000000--- a/packages/base-ui/src/Basics/Register/Paste/PasteExtensionRegister.ts+++ /dev/null@@ -1,20 +0,0 @@-import { sortRules } from '@univerjs/core';-import { BasePasteExtensionFactory } from './PasteExtensionFactory';--export class PasteExtensionRegister {- private _pasteExtensionFactoryList: BasePasteExtensionFactory[] = [];-- get pasteExtensionFactoryList(): BasePasteExtensionFactory[] {- return this._pasteExtensionFactoryList;- }-- add(...extensionFactoryList: BasePasteExtensionFactory[]) {- this._pasteExtensionFactoryList.push(...extensionFactoryList);- this._pasteExtensionFactoryList.sort(sortRules);- }-- delete(extensionFactory: BasePasteExtensionFactory) {- const index = this._pasteExtensionFactoryList.indexOf(extensionFactory);- this._pasteExtensionFactoryList.splice(index, 1);- }-}diff --git a/packages/base-ui/src/Basics/Register/Paste/index.ts b/packages/base-ui/src/Basics/Register/Paste/index.tsdeleted file mode 100644index 095f1c754e..0000000000--- a/packages/base-ui/src/Basics/Register/Paste/index.ts+++ /dev/null@@ -1,6 +0,0 @@-// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)--export * from './PasteExtensionFactory';-export * from './PasteExtensionManager';-export * from './PasteExtensionRegister';-// @endindexdiff --git a/packages/base-ui/src/Basics/Register/index.ts b/packages/base-ui/src/Basics/Register/index.tsindex a386588783..87bb36e79f 100644--- a/packages/base-ui/src/Basics/Register/index.ts+++ b/packages/base-ui/src/Basics/Register/index.ts@@ -1,7 +1,6 @@-// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)-export * from './CellEditRegister/index';-export * from './CellInputRegister/index';-export * from './Paste/index';-export * from './Copy/index';-export * from './DragAndDrop/index';-// @endindex+// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)+export * from './CellEditRegister/index';+export * from './CellInputRegister/index';+export * from './Copy/index';+export * from './DragAndDrop/index';+// @endindexdiff --git a/packages/base-ui/src/Common/RegisterManager.ts b/packages/base-ui/src/Common/RegisterManager.tsdeleted file mode 100644index 5a6c92018b..0000000000--- a/packages/base-ui/src/Common/RegisterManager.ts+++ /dev/null@@ -1,86 +0,0 @@-import { CommandManager, ICurrentUniverService, ObserverManager } from '@univerjs/core';-import { Inject } from '@wendellhu/redi';-import { IPasteData, IDragAndDropData } from '../Basics/Interfaces';-import { PasteExtensionManager, DragAndDropExtensionManager, CopyExtensionManager } from '../Basics/Register';--export class RegisterManager {- private _pasteExtensionManager: PasteExtensionManager;-- private _copyExtensionManager: CopyExtensionManager;-- private _dragAndDropExtensionManager: DragAndDropExtensionManager;-- constructor(- @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,- @Inject(CommandManager) private readonly _comandManager: CommandManager,- @ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService- ) {- this.initialize();- }-- initialize(): void {- this.setClipboardExtensionManager();- this.setDragAndDropExtensionManager();- }-- setClipboardExtensionManager() {- this._pasteExtensionManager = new PasteExtensionManager(this._comandManager, this._currentUniverService);- this._copyExtensionManager = new CopyExtensionManager();- const onKeyPasteObservable = this._globalObserverManager.getObserver<ClipboardEvent>('onKeyPasteObservable', 'core');- const onKeyCopyObservable = this._globalObserverManager.getObserver<ClipboardEvent>('onKeyCopyObservable', 'core');-- if (onKeyPasteObservable && !onKeyPasteObservable.hasObservers()) {- onKeyPasteObservable.add((evt: ClipboardEvent) => {- this._pasteExtensionManager.pasteResolver(evt).then((data: IPasteData) => {- this._pasteExtensionManager.handle(data);- });- });- }- if (onKeyCopyObservable && !onKeyCopyObservable.hasObservers()) {- onKeyCopyObservable.add((evt: ClipboardEvent) => {- this._copyExtensionManager.handle();- });- }- }-- setDragAndDropExtensionManager() {- this._dragAndDropExtensionManager = new DragAndDropExtensionManager();-- const onDropObservable = this._globalObserverManager.getObserver<DragEvent>('onDropObservable', 'core');-- if (onDropObservable && !onDropObservable.hasObservers()) {- onDropObservable.add((evt: DragEvent) => {- this._dragAndDropExtensionManager.dragResolver(evt).then((dataList: IDragAndDropData[]) => {- if (dataList.length === 0) return;- this._dragAndDropExtensionManager.handle(dataList);- });- });- }- }-- /**- * usage this._pasteExtensionManager.handle(data);- * @returns- */- getPasteExtensionManager(): PasteExtensionManager {- return this._pasteExtensionManager;- }-- /**- * usage this._pasteExtensionManager.handle(data);- * @returns- */- getCopyExtensionManager(): CopyExtensionManager {- return this._copyExtensionManager;- }-- getDragAndDropExtensionManager(): DragAndDropExtensionManager {- return this._dragAndDropExtensionManager;- }-- onMounted(): void {- this.initialize();- }-- onDestroy(): void {}-}\ No newline at end of filediff --git a/packages/base-ui/src/Common/index.ts b/packages/base-ui/src/Common/index.tsindex 50902947e3..76d92a6cd5 100644--- a/packages/base-ui/src/Common/index.ts+++ b/packages/base-ui/src/Common/index.ts@@ -1,7 +1,6 @@export * from './AppContext';-export * from './KeyboardManager';-export * from './DragManager';export * from './ComponentManager';-export * from './RegisterManager';+export * from './DragManager';+export * from './KeyboardManager';export * from './SlotManager';export * from './ZIndexManager';diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.tsindex bbb318565e..7651f2273c 100644--- a/packages/core/src/Basics/Univer.ts+++ b/packages/core/src/Basics/Univer.ts@@ -1,6 +1,5 @@import { Ctor, Injector } from '@wendellhu/redi';-import { CommandManager, UndoManager } from '../Command';import { ObserverManager } from '../Observer';import { Plugin, PluginCtor, PluginRegistry, PluginStore, PluginType } from '../Plugin';import { CommandService, ICommandService } from '../services/command/command.service';@@ -137,9 +136,7 @@ export class Univer {return new Injector([[ObserverManager],[ICurrentUniverService, { useClass: CurrentUniverService }],- [CommandManager],[LocaleService],- [UndoManager],[ILogService, { useClass: DesktopLogService, lazy: true }],[ICommandService, { useClass: CommandService, lazy: true }],[IUndoRedoService, { useClass: LocalUndoRedoService, lazy: true }],diff --git a/packages/core/src/Command/ActionBase.ts b/packages/core/src/Command/ActionBase.tsdeleted file mode 100644index 316046eda7..0000000000--- a/packages/core/src/Command/ActionBase.ts+++ /dev/null@@ -1,89 +0,0 @@-import { ActionObservers, CommonParameter } from './index';--/**- * Format of action data param- */-export interface IActionData {- actionName: string;- memberId?: string;- operation?: ActionOperationType;-}--/**- * Action Operation Type- */-export enum ActionOperationType {- /**- * send obs- */- OBSERVER_ACTION = 0x00000001,-- /**- * send server- */- SERVER_ACTION = 0x00000002,-- /**- * push to UNDO/REDO stack- */- UNDO_ACTION = 0x00000004,-- /**- * action extension- */- EXTENSION_ACTION = 0x00000008,-- /**- * default obs- */- DEFAULT_ACTION = ActionOperationType.OBSERVER_ACTION | ActionOperationType.SERVER_ACTION | ActionOperationType.UNDO_ACTION | ActionOperationType.EXTENSION_ACTION,-}--/**- * Basics class for action- *- * @beta- */-export abstract class ActionBase<D extends IActionData, O extends IActionData = D, R = void> {- protected _observers: ActionObservers;-- protected _doActionData: D;-- protected _oldActionData: O;-- protected _operation: ActionOperationType;-- protected constructor(actionData: D, observers: ActionObservers) {- this._doActionData = actionData;- this._observers = observers;- this._operation = ActionOperationType.OBSERVER_ACTION;- }-- getDoActionData() {- return this._doActionData;- }-- getOldActionData() {- return this._oldActionData;- }-- hasOperation(operation: ActionOperationType): boolean {- return (this._operation & operation) === operation;- }-- addOperation(operation: ActionOperationType) {- this._operation |= operation;- }-- removeOperation(operation: ActionOperationType) {- this._operation &= ~operation;- }-- abstract redo(commonParameter?: CommonParameter): void;-- abstract undo(commonParameter?: CommonParameter): void;-- abstract do(commonParameter?: CommonParameter): R;-- abstract validate(): boolean;-}diff --git a/packages/core/src/Command/ActionExtensionFactory.ts b/packages/core/src/Command/ActionExtensionFactory.tsdeleted file mode 100644index 41f7102244..0000000000--- a/packages/core/src/Command/ActionExtensionFactory.ts+++ /dev/null@@ -1,56 +0,0 @@-import type { IActionData } from './ActionBase';--/**- * Manipulate the list of actions in a command- */-export class BaseActionExtension {- constructor(protected actionDataList: IActionData[]) {}-- getActionDataList(): IActionData[] {- return this.actionDataList;- }-- /**- * Must use internal method to add action- * @param actionData- */- push(actionData: IActionData) {- this.actionDataList.push(actionData);- }-- /**- * Modify the data of action- */- setValue() {}-- /**- * Execute the core logic after the check is successful- */- execute() {}-}--/**- * Determine whether to intercept and create BaseActionExtension- */-export class BaseActionExtensionFactory {- get zIndex() {- return 0;- }-- /**- * Generate Action Extension- * @param actionDataList- * @returns- */- create(actionDataList: IActionData[]): BaseActionExtension {- return new BaseActionExtension(actionDataList);- }-- /**- * Intercept actionDataList- * @returns- */- check(actionDataList: IActionData[]): false | BaseActionExtension {- return this.create(actionDataList);- }-}diff --git a/packages/core/src/Command/ActionExtensionManager.ts b/packages/core/src/Command/ActionExtensionManager.tsdeleted file mode 100644index fba1904c39..0000000000--- a/packages/core/src/Command/ActionExtensionManager.ts+++ /dev/null@@ -1,55 +0,0 @@-import {- IActionData,- ActionExtensionRegister,- BaseActionExtensionFactory,-} from './index';--export class ActionExtensionManager {- private _actionExtensionFactoryList: BaseActionExtensionFactory[];-- // mounted on the instance- private _register: ActionExtensionRegister;-- constructor() {- this._register = new ActionExtensionRegister();- this._register.initialize();- }-- getRegister(): ActionExtensionRegister {- return this._register;- }-- /**- * inject all actions- * @param command- */- handle(actions: IActionData[]) {- const actionExtensionFactoryList =- this._register?.actionExtensionFactoryList;- if (!actionExtensionFactoryList) return;- // get the sorted list- // get the dynamically added list- this._actionExtensionFactoryList = actionExtensionFactoryList;-- if (actions.length === 0) return;-- this._checkExtension(actions);- }-- /**- * Execute when the action is matched- * @param command- * @returns- */- private _checkExtension(actions: IActionData[]) {- if (!this._actionExtensionFactoryList) return false;-- this._actionExtensionFactoryList.forEach((actionExtensionFactory) => {- const extension = actionExtensionFactory.check(actions);- // Both formula and formatting need to execute- if (extension !== false) {- extension.execute();- }- });- }-}diff --git a/packages/core/src/Command/ActionExtensionRegister.ts b/packages/core/src/Command/ActionExtensionRegister.tsdeleted file mode 100644index 3a41c4fa47..0000000000--- a/packages/core/src/Command/ActionExtensionRegister.ts+++ /dev/null@@ -1,30 +0,0 @@-import { sortRules } from '../Shared';-import { BaseActionExtensionFactory, REGISTRY_ACTION_FACTORY } from './index';--export class ActionExtensionRegister {- private _actionExtensionFactoryList: BaseActionExtensionFactory[] = [];-- get actionExtensionFactoryList(): BaseActionExtensionFactory[] {- return this._actionExtensionFactoryList;- }-- initialize() {- this._initExtensions();- }-- add(...extensionFactoryList: BaseActionExtensionFactory[]) {- this._actionExtensionFactoryList.push(...extensionFactoryList);- this._actionExtensionFactoryList.sort(sortRules);- }-- delete(extensionFactory: BaseActionExtensionFactory) {- const index = this._actionExtensionFactoryList.indexOf(extensionFactory);- this._actionExtensionFactoryList.splice(index, 1);- }-- private _initExtensions() {- this._actionExtensionFactoryList.push(- ...REGISTRY_ACTION_FACTORY.getData().sort(sortRules)- );- }-}diff --git a/packages/core/src/Command/ActionObservers.ts b/packages/core/src/Command/ActionObservers.tsdeleted file mode 100644index 0a5818644b..0000000000--- a/packages/core/src/Command/ActionObservers.ts+++ /dev/null@@ -1,27 +0,0 @@-import { Observable } from '../Observer';-import { IActionData, ActionBase, CommonParameter } from './index';--/**- * Action type- */-export enum ActionType {- REDO,- UNDO,-}--/**- * Action observer props- */-export interface IActionObserverProps {- type: ActionType;- data: IActionData;- action: ActionBase<IActionData, IActionData>;- commonParameter?: CommonParameter;-}--/**- * WorkBookObserver for action base- *- * @beta- */-export class ActionObservers extends Observable<IActionObserverProps> {}diff --git a/packages/core/src/Command/ActionOperation.ts b/packages/core/src/Command/ActionOperation.tsdeleted file mode 100644index 73df60536b..0000000000--- a/packages/core/src/Command/ActionOperation.ts+++ /dev/null@@ -1,86 +0,0 @@-import { ActionOperationType, IActionData } from './index';--export class ActionOperation<T extends IActionData> {- protected _action: T;-- protected constructor(action: T) {- this._action = action;- }-- static hasObserver<U extends IActionData>(action: U): boolean {- if (action.operation) {- return (- (action.operation & ActionOperationType.OBSERVER_ACTION) ===- ActionOperationType.OBSERVER_ACTION- );- }- return true;- }-- static hasUndo<U extends IActionData>(action: U): boolean {- if (action.operation) {- return (- (action.operation & ActionOperationType.UNDO_ACTION) ===- ActionOperationType.UNDO_ACTION- );- }- return true;- }-- static hasCollaboration<U extends IActionData>(action: U): boolean {- if (action.operation) {- return (- (action.operation & ActionOperationType.SERVER_ACTION) ===- ActionOperationType.SERVER_ACTION- );- }- return true;- }-- static hasExtension<U extends IActionData>(action: U): boolean {- if (action.operation) {- return (- (action.operation & ActionOperationType.EXTENSION_ACTION) ===- ActionOperationType.EXTENSION_ACTION- );- }- return true;- }-- static make<U extends IActionData>(action: U) {- action.operation = ActionOperationType.DEFAULT_ACTION;- return new ActionOperation<U>(action);- }-- removeObserver() {- if (this._action.operation) {- this._action.operation &= ~ActionOperationType.OBSERVER_ACTION;- }- return this;- }-- removeUndo() {- if (this._action.operation) {- this._action.operation &= ~ActionOperationType.UNDO_ACTION;- }- return this;- }-- removeCollaboration() {- if (this._action.operation) {- this._action.operation &= ~ActionOperationType.SERVER_ACTION;- }- return this;- }-- removeExtension() {- if (this._action.operation) {- this._action.operation &= ~ActionOperationType.EXTENSION_ACTION;- }- return this;- }-- getAction(): T {- return this._action;- }-}diff --git a/packages/core/src/Command/Command.ts b/packages/core/src/Command/Command.tsdeleted file mode 100644index 3cb28c1533..0000000000--- a/packages/core/src/Command/Command.ts+++ /dev/null@@ -1,106 +0,0 @@-import { Class, Nullable } from '../Shared';-import { Workbook } from '../Sheets';-import { IActionData, ActionType, ActionBase, CommandInjector, CommandManager, ActionOperation, CommonParameter } from './index';-import { DocumentModel } from '../Docs/Domain/DocumentModel';--export class CommandUnit {- WorkBookUnit?: Workbook;-- DocumentUnit?: DocumentModel;-}--/**- * Execute the undo-redo command- *- */-export class Command {- actionDataList: IActionData[];-- unit: CommandUnit;-- actionList: Array<ActionBase<IActionData>>;-- private _commonParameter = new CommonParameter();-- constructor(commandUnit: CommandUnit, ...list: IActionData[]) {- this.unit = commandUnit;- this.actionDataList = list;- this.actionList = [];- }-- redo(): void {- this.actionList.forEach((action) => {- if (ActionOperation.hasUndo(action.getDoActionData())) {- action.redo(this._commonParameter.reset());- }- });- CommandManager.getCommandObservers().notifyObservers({- type: ActionType.REDO,- actions: this.actionList,- });- }-- undo(): void {- // Reverse is required, such as moving C:E to the back of column A, after copying the data of C:E- // 1. removeColumn C:E 2.insertColumnData A,- // when undo, it should be- // 1. removeColumn A, 2. insertColumnData C:E- this.actionList.forEach((action) => {- if (ActionOperation.hasUndo(action.getOldActionData())) {- action.undo(this._commonParameter.reset());- }- });- CommandManager.getCommandObservers().notifyObservers({- type: ActionType.UNDO,- actions: this.actionList,- });- }-- invoke(): void {- this._commonParameter.reset();- this.actionDataList.forEach((data) => {- const ActionClass = CommandManager.getAction(data.actionName);- if (!ActionClass) return;- const observers = CommandManager.getActionObservers();- const action = new ActionClass(data, this.unit, observers, this._commonParameter);-- this.actionList.push(action);- });-- CommandManager.getCommandInjectorObservers().notifyObservers(this.getInjector());- CommandManager.getCommandObservers().notifyObservers({- type: ActionType.REDO,- actions: this.actionList,- });- }-- getOldData(): IActionData[] {- return this.actionList.map((action) => action.getOldActionData());- }-- getDoData(): IActionData[] {- return this.actionList.map((action) => action.getDoActionData());- }-- getInjector(): CommandInjector {- const commandThis = this;- return new (class implements CommandInjector {- injectAction(action: ActionBase<IActionData, IActionData, void>): void {- commandThis.actionList.push(action);- }-- getActions(): Array<ActionBase<IActionData>> {- return commandThis.actionList.concat([]);- }-- include<T>(action: Class<T>): Nullable<T> {- for (let i = 0; i < commandThis.actionList.length; i++) {- if (commandThis.actionList[i] instanceof action) {- return commandThis.actionList[i] as unknown as Nullable<T>;- }- }- return null;- }- })();- }-}diff --git a/packages/core/src/Command/CommandInjectorObservers.ts b/packages/core/src/Command/CommandInjectorObservers.tsdeleted file mode 100644index 75ad92993c..0000000000--- a/packages/core/src/Command/CommandInjectorObservers.ts+++ /dev/null@@ -1,19 +0,0 @@-import { Observable } from '../Observer';-import { Class, Nullable } from '../Shared';-import { ActionBase, IActionData } from './index';--/**- * Command injector, after the core triggers the Command, the plug-in receives the Command WorkBookObserver message, inserts its own Action, and combines it into one Command, which is convenient for undo/redo to be executed as a command.- *- * @privateRemarks- * zh: Command injector, 核心触发的Command后,插件接受到Command Observer消息之后,插入自己的Action,组合为一个Command,方便撤销重做作为一个指令执行。- */-export interface CommandInjector {- injectAction(action: ActionBase<IActionData>): void;-- include<T>(action: Class<T>): Nullable<T>;-- getActions(): Array<ActionBase<IActionData>>;-}--export class CommandInjectorObservers extends Observable<CommandInjector> {}diff --git a/packages/core/src/Command/CommandManager.ts b/packages/core/src/Command/CommandManager.tsdeleted file mode 100644index 6c513df9ec..0000000000--- a/packages/core/src/Command/CommandManager.ts+++ /dev/null@@ -1,89 +0,0 @@-import { Inject } from '@wendellhu/redi';-import { Class } from '../Shared/Types';-import { ActionBase, IActionData } from './ActionBase';-import { CommandObservers } from './CommandObservers';-import { ActionObservers } from './ActionObservers';-import { CommandInjectorObservers } from './CommandInjectorObservers';-import { UndoManager } from './UndoManager';-import { ActionExtensionManager } from './ActionExtensionManager';-import { Command } from './Command';--/**- * Manage command- */-export class CommandManager {- private static _actionClass: Map<string, Class<ActionBase<IActionData>>>;-- private static _commandObservers: CommandObservers;-- private static _actionObservers: ActionObservers;-- private static _commandInjectorObservers: CommandInjectorObservers;-- private _actionExtensionManager: ActionExtensionManager;-- constructor(@Inject(UndoManager) private readonly _undoManager: UndoManager) {- this._actionExtensionManager = new ActionExtensionManager();- }-- static staticInitialize() {- this._actionClass = new Map<string, Class<ActionBase<IActionData>>>();- this._actionObservers = new ActionObservers();- this._commandObservers = new CommandObservers();- this._commandInjectorObservers = new CommandInjectorObservers();- }-- static getAction(name: string) {- return this._actionClass.get(name);- }-- static getActionObservers(): ActionObservers {- return this._actionObservers;- }-- static getCommandObservers(): CommandObservers {- return this._commandObservers;- }-- static register(name: string, clazz: Class<ActionBase<IActionData>>) {- this._actionClass.set(name, clazz);- }-- static getCommandInjectorObservers(): CommandInjectorObservers {- return this._commandInjectorObservers;- }-- getActionExtensionManager(): ActionExtensionManager {- return this._actionExtensionManager;- }-- undo(): void {- const { _undoManager } = this;- const command = _undoManager.undo();- if (command) {- command.undo();- }- }-- redo(): void {- const { _undoManager } = this;- const command = _undoManager.redo();- if (command) {- command.redo();- }- }-- invoke(command: Command): void {- const { _undoManager } = this;- const { actionDataList } = command;-- // Action may be added or reissued- this._actionExtensionManager.handle(actionDataList);-- command.invoke();-- _undoManager.push(command);- }-}--CommandManager.staticInitialize();diff --git a/packages/core/src/Command/CommandObservers.ts b/packages/core/src/Command/CommandObservers.tsdeleted file mode 100644index 17c924a2ec..0000000000--- a/packages/core/src/Command/CommandObservers.ts+++ /dev/null@@ -1,15 +0,0 @@-import { Observable } from '../Observer';-import { ActionBase, IActionData, ActionType } from './index';--/**- * Command observer props- */-interface ICommandObserverProps {- type: ActionType;- actions: Array<ActionBase<IActionData>>;-}--/**- * Command observers- */-export class CommandObservers extends Observable<ICommandObserverProps> {}diff --git a/packages/core/src/Command/CommonParameter.ts b/packages/core/src/Command/CommonParameter.tsdeleted file mode 100644index 906b614975..0000000000--- a/packages/core/src/Command/CommonParameter.ts+++ /dev/null@@ -1,12 +0,0 @@-export class CommonParameter {- cursor: number;-- reset() {- this.cursor = 0;- return this;- }-- moveCursor(pos: number) {- this.cursor += pos;- }-}diff --git a/packages/core/src/Command/DocActionBase.ts b/packages/core/src/Command/DocActionBase.tsdeleted file mode 100644index 8c7397d902..0000000000--- a/packages/core/src/Command/DocActionBase.ts+++ /dev/null@@ -1,28 +0,0 @@-import { ActionBase, IActionData, CommandUnit, ActionObservers } from './index';-import { DocumentModel } from '../Docs/Domain/DocumentModel';--export interface IDocActionData extends IActionData {}--export abstract class DocActionBase<- D extends IDocActionData,- O extends IDocActionData = D,- R = void-> extends ActionBase<D, O, R> {- protected _document: DocumentModel;-- protected constructor(- actionData: D,- commandUnit: CommandUnit,- observers: ActionObservers- ) {- super(actionData, observers);- if (commandUnit.DocumentUnit == null) {- throw new Error('action document domain can not be null!');- }- this._document = commandUnit.DocumentUnit;- }-- getDocument(): DocumentModel {- return this._document;- }-}diff --git a/packages/core/src/Command/RegisterAction.ts b/packages/core/src/Command/RegisterAction.tsdeleted file mode 100644index 80920bf7fe..0000000000--- a/packages/core/src/Command/RegisterAction.ts+++ /dev/null@@ -1,206 +0,0 @@-import {- AddMergeAction,- AddNamedRangeAction,- DeleteNamedRangeAction,- DeleteRangeAction,- InsertColumnAction,- InsertColumnDataAction,- InsertRangeAction,- InsertRowAction,- InsertRowDataAction,- InsertSheetAction,- RemoveColumnAction,- RemoveColumnDataAction,- RemoveMergeAction,- RemoveRowAction,- RemoveRowDataAction,- RemoveSheetAction,- SetBorderAction,- SetColumnHideAction,- SetColumnShowAction,- SetColumnWidthAction,- SetHiddenGridlinesAction,- SetNamedRangeAction,- SetRangeDataAction,- SetRangeNoteAction,- SetRangeStyleAction,- SetRangeFormattedValueAction,- SetRightToLeftAction,- SetRowHeightAction,- SetRowHideAction,- SetRowShowAction,- SetSelectionActivateAction,- SetSheetOrderAction,- SetTabColorAction,- SetWorkSheetActivateAction,- SetWorkSheetHideAction,- SetWorkSheetNameAction,- SetWorkSheetStatusAction,- SetZoomRatioAction,-} from '../Sheets/Action';-import { CommandManager } from './CommandManager';-import { DOC_ACTION_NAMES } from '../Types/Const/DOC_ACTION_NAMES';-import {- InsertTextAction,- DeleteTextAction,- ClearTextStyleAction,- DeleteParagraphAction,- InsertParagraphAction,- MergeParagraphAction,- MoveParagraphAction,- SetTextStyleAction,- SplitParagraphAction,- UpdateDocumentAction,- UpdateParagraphAction,- UpdateSectionAction,- DeleteBulletAction,- DeleteParagraphBulletAction,- DeleteSectionAction,- InsertBulletAction,- InsertParagraphBulletAction,- InsertSectionAction,- UpdateBulletAction,- UpdateParagraphBulletAction,- TextIndexAdjustAction,-} from '../Docs';--/**- * All Commands are registered statically. For each new Command, a static registration method must be added here.- */--CommandManager.register(InsertRowDataAction.NAME, InsertRowDataAction);-CommandManager.register(InsertRowAction.NAME, InsertRowAction);-CommandManager.register(RemoveRowDataAction.NAME, RemoveRowDataAction);-CommandManager.register(RemoveRowAction.NAME, RemoveRowAction);-CommandManager.register(SetRangeStyleAction.NAME, SetRangeStyleAction);-CommandManager.register(SetWorkSheetStatusAction.NAME, SetWorkSheetStatusAction);-CommandManager.register(SetSelectionActivateAction.NAME, SetSelectionActivateAction);-CommandManager.register(SetRangeDataAction.NAME, SetRangeDataAction);-CommandManager.register(- SetRangeFormattedValueAction.NAME,- SetRangeFormattedValueAction-);-CommandManager.register(DeleteRangeAction.NAME, DeleteRangeAction);-CommandManager.register(InsertRangeAction.NAME, InsertRangeAction);-CommandManager.register(SetTabColorAction.NAME, SetTabColorAction);-CommandManager.register(SetWorkSheetHideAction.NAME, SetWorkSheetHideAction);-CommandManager.register(SetWorkSheetActivateAction.NAME, SetWorkSheetActivateAction);-CommandManager.register(SetRowHideAction.NAME, SetRowHideAction);-CommandManager.register(SetRowShowAction.NAME, SetRowShowAction);-CommandManager.register(SetColumnHideAction.NAME, SetColumnHideAction);-CommandManager.register(SetColumnShowAction.NAME, SetColumnShowAction);-CommandManager.register(AddMergeAction.NAME, AddMergeAction);-CommandManager.register(RemoveMergeAction.NAME, RemoveMergeAction);-CommandManager.register(SetWorkSheetNameAction.NAME, SetWorkSheetNameAction);-CommandManager.register(SetHiddenGridlinesAction.NAME, SetHiddenGridlinesAction);-CommandManager.register(SetColumnWidthAction.NAME, SetColumnWidthAction);-CommandManager.register(SetRowHeightAction.NAME, SetRowHeightAction);-CommandManager.register(SetBorderAction.NAME, SetBorderAction);-CommandManager.register(SetRightToLeftAction.NAME, SetRightToLeftAction);-CommandManager.register(InsertColumnDataAction.NAME, InsertColumnDataAction);-CommandManager.register(RemoveColumnDataAction.NAME, RemoveColumnDataAction);-CommandManager.register(InsertColumnAction.NAME, InsertColumnAction);-CommandManager.register(RemoveColumnAction.NAME, RemoveColumnAction);-CommandManager.register(DeleteNamedRangeAction.NAME, DeleteNamedRangeAction);-CommandManager.register(SetNamedRangeAction.NAME, SetNamedRangeAction);-CommandManager.register(AddNamedRangeAction.NAME, AddNamedRangeAction);-CommandManager.register(SetRangeNoteAction.NAME, SetRangeNoteAction);-CommandManager.register(InsertSheetAction.NAME, InsertSheetAction);-CommandManager.register(RemoveSheetAction.NAME, RemoveSheetAction);-CommandManager.register(SetSheetOrderAction.NAME, SetSheetOrderAction);-CommandManager.register(SetSheetOrderAction.NAME, SetSheetOrderAction);-CommandManager.register(SetZoomRatioAction.NAME, SetZoomRatioAction);--///====================================================================================================-///====================================================================================================-///====================================================================================================-///====================================================================================================--CommandManager.register(DOC_ACTION_NAMES.INSERT_TEXT_ACTION_NAME, InsertTextAction);-CommandManager.register(DOC_ACTION_NAMES.DELETE_TEXT_ACTION_NAME, DeleteTextAction);--CommandManager.register(- DOC_ACTION_NAMES.CLEAR_TEXT_STYLE_ACTION_NAME,- ClearTextStyleAction-);-CommandManager.register(- DOC_ACTION_NAMES.DELETE_PARAGRAPH_ACTION_NAME,- DeleteParagraphAction-);-CommandManager.register(- DOC_ACTION_NAMES.INSERT_PARAGRAPH_ACTION_NAME,- InsertParagraphAction-);-CommandManager.register(- DOC_ACTION_NAMES.MERGE_PARAGRAPH_ACTION_NAME,- MergeParagraphAction-);-CommandManager.register(- DOC_ACTION_NAMES.MOVE_PARAGRAPH_ACTION_NAME,- MoveParagraphAction-);-CommandManager.register(- DOC_ACTION_NAMES.SET_TEXT_STYLE_ACTION_NAME,- SetTextStyleAction-);-CommandManager.register(- DOC_ACTION_NAMES.SPLIT_PARAGRAPH_ACTION_NAME,- SplitParagraphAction-);-CommandManager.register(- DOC_ACTION_NAMES.UPDATE_DOCUMENT_STYLE_ACTION_NAME,- UpdateDocumentAction-);-CommandManager.register(- DOC_ACTION_NAMES.UPDATE_PARAGRAPH_STYLE_ACTION_NAME,- UpdateParagraphAction-);-CommandManager.register(- DOC_ACTION_NAMES.UPDATE_SECTION_ACTION_NAME,- UpdateSectionAction-);--CommandManager.register(- DOC_ACTION_NAMES.DELETE_BULLET_ACTION_NAME,- DeleteBulletAction-);--CommandManager.register(- DOC_ACTION_NAMES.DELETE_PARAGRAPH_BULLET_ACTION_NAME,- DeleteParagraphBulletAction-);--CommandManager.register(- DOC_ACTION_NAMES.DELETE_SECTION_ACTION_NAME,- DeleteSectionAction-);--CommandManager.register(- DOC_ACTION_NAMES.INSERT_BULLET_ACTION_NAME,- InsertBulletAction-);--CommandManager.register(- DOC_ACTION_NAMES.INSERT_PARAGRAPH_BULLET_ACTION_NAME,- InsertParagraphBulletAction-);--CommandManager.register(- DOC_ACTION_NAMES.INSERT_SECTION_ACTION_NAME,- InsertSectionAction-);--CommandManager.register(- DOC_ACTION_NAMES.UPDATE_BULLET_ACTION_NAME,- UpdateBulletAction-);--CommandManager.register(- DOC_ACTION_NAMES.UPDATE_PARAGRAPH_BULLET_ACTION_NAME,- UpdateParagraphBulletAction-);--CommandManager.register(- DOC_ACTION_NAMES.TEXT_INDEX_ADJUST_ACTION_NAME,- TextIndexAdjustAction-);diff --git a/packages/core/src/Command/RegistryFactory.ts b/packages/core/src/Command/RegistryFactory.tsdeleted file mode 100644index 7385a0634f..0000000000--- a/packages/core/src/Command/RegistryFactory.ts+++ /dev/null@@ -1,23 +0,0 @@-// import { Registry } from '../Basics';-class Registry {- private _data: any[] = [];-- static create() {- return new Registry();- }-- add(dataInstance: any) {- this._data.push(dataInstance);- }-- delete(dataInstance: any) {- const index = this._data.indexOf(dataInstance);- this._data.splice(index, 1);- }-- getData() {- return this._data;- }-}--export const REGISTRY_ACTION_FACTORY = Registry.create();diff --git a/packages/core/src/Command/SheetActionBase.ts b/packages/core/src/Command/SheetActionBase.tsdeleted file mode 100644index 7e5f4ef930..0000000000--- a/packages/core/src/Command/SheetActionBase.ts+++ /dev/null@@ -1,47 +0,0 @@-import { Injector } from '@wendellhu/redi';-import { Workbook, Worksheet } from '../Sheets/Domain';-import { ActionBase, IActionData, ActionObservers, CommandUnit } from './index';--// TODO: @wzhudev: rename this interface to ISheetMutationData-/**- * Format of action data param- */-export interface ISheetActionData extends IActionData {- sheetId: string;- rangeRef?: string;- injector?: Injector;- actionName: string;- memberId?: string;- operation?: ActionOperationType;-}--/**- * Basics class for action- *- * TODO: SlideAction/DocAction- * @beta- */-export abstract class SheetActionBase<D extends ISheetActionData, O extends ISheetActionData = D, R = void> extends ActionBase<D, O, R> {- protected _commandUnit: CommandUnit;-- protected _workbook: Workbook;-- protected constructor(actionData: D, commandUnit: CommandUnit, observers: ActionObservers) {- super(actionData, observers);- if (commandUnit.WorkBookUnit == null) {- throw new Error('action workbook domain can not be null!');- }- this._commandUnit = commandUnit;- this._workbook = commandUnit.WorkBookUnit;- }-- getWorkSheet(): Worksheet {- const { _workbook, _doActionData } = this;- const { sheetId } = _doActionData;- return _workbook.getSheetBySheetId(sheetId) as Worksheet;- }-- getWorkBook(): Workbook {- return this._workbook;- }-}diff --git a/packages/core/src/Command/UndoManager.ts b/packages/core/src/Command/UndoManager.tsdeleted file mode 100644index 955fdb447f..0000000000--- a/packages/core/src/Command/UndoManager.ts+++ /dev/null@@ -1,37 +0,0 @@-import { Command } from './index';--/**- * Manage Undo Redo- */-export class UndoManager {- private _undoStack: Command[];-- private _redoStack: Command[];-- constructor() {- this._undoStack = [];- this._redoStack = [];- }-- push(command: Command): void {- this._redoStack.push(command);-- this._undoStack.length = 0;- }-- undo(): Command | undefined {- const command = this._redoStack.pop();- if (command) {- this._undoStack.push(command);- return command;- }- }-- redo(): Command | undefined {- const command = this._undoStack.pop();- if (command) {- this._redoStack.push(command);- return command;- }- }-}\ No newline at end of filediff --git a/packages/core/src/Command/index.ts b/packages/core/src/Command/index.tsdeleted file mode 100644index 13a266eb84..0000000000--- a/packages/core/src/Command/index.ts+++ /dev/null@@ -1,16 +0,0 @@-// @index(['./*.ts','./Action/index.ts'], f => `export * from '${f.path}'`);-export * from './CommonParameter';-export * from './ActionBase';-export * from './ActionObservers';-export * from './CommandInjectorObservers';-export * from './CommandObservers';-export * from './CommandManager';-export * from './SheetActionBase';-export * from './Command';-export * from './UndoManager';-export * from './ActionExtensionManager';-export * from './ActionExtensionFactory';-export * from './RegistryFactory';-export * from './ActionExtensionRegister';-export * from './ActionOperation';-// @endindexdiff --git a/packages/core/src/Docs/Action/ActionDataInterface.ts b/packages/core/src/Docs/Action/ActionDataInterface.tsdeleted file mode 100644index 85bbe1d40e..0000000000--- a/packages/core/src/Docs/Action/ActionDataInterface.ts+++ /dev/null@@ -1,38 +0,0 @@-import { IDocActionData } from '../../Command/DocActionBase';-import { Nullable } from '../../Shared';-import { UpdateDocsAttributeType } from '../../Shared/CommandEnum';-import { IDocumentBody } from '../../Types/Interfaces/IDocumentData';--export enum UpdateAttributeType {- TEXT_RUN,- PARAGRAPH,- SECTION,- CUSTOM_BLOCK,- TABLE,- CUSTOM_RANGE,-}-export interface IDeleteActionData extends IDocActionData {- len: number;- line: number;- segmentId?: string;-}--export interface IInsertActionData extends IDocActionData {- body: IDocumentBody;- len: number;- line: 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 interface IRetainActionData extends IDocActionData {- body?: Nullable<IDocumentBody>;- len: number;- coverType?: UpdateDocsAttributeType;- segmentId?: string;-}--export interface IUpdateDocumentActionData extends IDocActionData {- text: string;-}--export type DocActionType = IDeleteActionData | IInsertActionData | IRetainActionData;diff --git a/packages/core/src/Docs/Action/DeleteAction.ts b/packages/core/src/Docs/Action/DeleteAction.tsdeleted file mode 100644index c30674e218..0000000000--- a/packages/core/src/Docs/Action/DeleteAction.ts+++ /dev/null@@ -1,78 +0,0 @@-import { ActionObservers, ActionType, CommandManager, CommandUnit, CommonParameter } from '../../Command';-import { DocActionBase } from '../../Command/DocActionBase';-import { DOC_ACTION_NAMES } from '../../Types/Const/DOC_ACTION_NAMES';-import { IDocumentBody } from '../../Types/Interfaces';-import { DeleteApply } from '../Apply/DeleteApply';-import { InsertApply } from '../Apply/InsertApply';-import { IDeleteActionData, IInsertActionData } from './ActionDataInterface';--export class DeleteAction extends DocActionBase<IDeleteActionData, IInsertActionData> {- static Name = 'DeleteAction';-- constructor(actionData: IDeleteActionData, commandUnit: CommandUnit, observers: ActionObservers, commonParameter: CommonParameter) {- super(actionData, commandUnit, observers);- this._doActionData = { ...actionData };- const { len, line, segmentId } = actionData;-- this._oldActionData = {- ...actionData,- actionName: DOC_ACTION_NAMES.INSERT_ACTION_NAME,- body: this.do(commonParameter),- };-- // this._oldActionData = {- // actionName: DOC_ACTION_NAMES.INSERT_TEXT_ACTION_NAME,- // text,- // textLength,- // cursorStart,- // isStartBack,- // segmentId,- // };- }-- redo(commonParameter: CommonParameter): void {- this.do(commonParameter);- }-- do(commonParameter: CommonParameter): IDocumentBody {- const actionData = this.getDoActionData();- const document = this.getDocument();- const { len, segmentId } = actionData;-- const body = DeleteApply(document, len, commonParameter.cursor, segmentId);-- // commonParameter.moveCursor(len);-- this._observers.notifyObservers({- type: ActionType.REDO,- data: this._doActionData,- action: this,- commonParameter,- });-- return body;- }-- undo(commonParameter: CommonParameter): void {- const actionData = this.getOldActionData();- const document = this.getDocument();- const { body, len, segmentId } = actionData;-- InsertApply(document, body, len, commonParameter.cursor, segmentId);-- commonParameter.moveCursor(len);-- this._observers.notifyObservers({- type: ActionType.UNDO,- data: this._oldActionData,- action: this,- commonParameter,- });- }-- validate(): boolean {- return false;- }-}--CommandManager.register(DeleteAction.Name, DeleteAction);diff --git a/packages/core/src/Docs/Action/InsertAction.ts b/packages/core/src/Docs/Action/InsertAction.tsdeleted file mode 100644index a6138fb2dd..0000000000--- a/packages/core/src/Docs/Action/InsertAction.ts+++ /dev/null@@ -1,68 +0,0 @@-import { ActionObservers, ActionType, CommandManager, CommandUnit, CommonParameter } from '../../Command';-import { DocActionBase } from '../../Command/DocActionBase';-import { DOC_ACTION_NAMES } from '../../Types/Const/DOC_ACTION_NAMES';-import { DeleteApply } from '../Apply/DeleteApply';-import { InsertApply } from '../Apply/InsertApply';-import { IDeleteActionData, IInsertActionData } from './ActionDataInterface';--export class InsertAction extends DocActionBase<IInsertActionData, IDeleteActionData> {- static NAME = 'InsertAction';-- constructor(actionData: IInsertActionData, commandUnit: CommandUnit, observers: ActionObservers, commonParameter: CommonParameter) {- super(actionData, commandUnit, observers);- this._doActionData = { ...actionData };- this.do(commonParameter);- const { segmentId, line, len } = actionData;- this._oldActionData = {- actionName: DOC_ACTION_NAMES.DELETE_ACTION_NAME,- len,- line,- segmentId,- };- }-- redo(commonParameter: CommonParameter): void {- this.do(commonParameter);- }-- do(commonParameter: CommonParameter): void {- const actionData = this.getDoActionData();- const document = this.getDocument();- const { body, len, segmentId } = actionData;-- InsertApply(document, body, len, commonParameter.cursor, segmentId);-- this._observers.notifyObservers({- type: ActionType.REDO,- data: this._doActionData,- action: this,- commonParameter,- });-- commonParameter.moveCursor(len);- }-- undo(commonParameter: CommonParameter): void {- const actionData = this.getOldActionData();- const document = this.getDocument();- const { len, segmentId } = actionData;-- DeleteApply(document, len, commonParameter.cursor, segmentId);-- // commonParameter.moveCursor(len);- // DeleteTextApply(document, { ...actionData });-- this._observers.notifyObservers({- type: ActionType.UNDO,- data: this._oldActionData,- action: this,- commonParameter,- });- }-- validate(): boolean {- return false;- }-}--CommandManager.register(InsertAction.NAME, InsertAction);diff --git a/packages/core/src/Docs/Action/RetainAction.ts b/packages/core/src/Docs/Action/RetainAction.tsdeleted file mode 100644index 9fce2742e0..0000000000--- a/packages/core/src/Docs/Action/RetainAction.ts+++ /dev/null@@ -1,53 +0,0 @@-import { ActionObservers, CommandManager, CommandUnit, CommonParameter } from '../../Command';-import { DocActionBase } from '../../Command/DocActionBase';-import { Nullable } from '../../Shared';-import { UpdateDocsAttributeType } from '../../Shared/CommandEnum';-import { IDocumentBody } from '../../Types/Interfaces';-import { UpdateAttributeApply } from '../Apply/UpdateAttributeApply';-import { IRetainActionData } from './ActionDataInterface';--export class RetainAction extends DocActionBase<IRetainActionData, IRetainActionData> {- static NAME = 'RetainAction';-- constructor(actionData: IRetainActionData, commandUnit: CommandUnit, observers: ActionObservers, commonParameter: CommonParameter) {- super(actionData, commandUnit, observers);- this._doActionData = { ...actionData };- this._oldActionData = {- ...actionData,- coverType: UpdateDocsAttributeType.REPLACE,- body: this.do(commonParameter),- };- }-- redo(commonParameter: CommonParameter): void {- this.do(commonParameter);- }-- do(commonParameter: CommonParameter): Nullable<IDocumentBody> {- const actionData = this.getDoActionData();- const document = this.getDocument();- const { len, segmentId, body, coverType } = actionData;-- const result: Nullable<IDocumentBody> = UpdateAttributeApply(document, body, len, commonParameter.cursor, coverType, segmentId);-- commonParameter.moveCursor(len);-- return result;- }-- undo(commonParameter: CommonParameter): void {- const actionData = this.getOldActionData();- const document = this.getDocument();- const { len, segmentId, body, coverType } = actionData;-- if (body) UpdateAttributeApply(document, body, len, commonParameter.cursor, coverType, segmentId);-- commonParameter.moveCursor(len);- }-- validate(): boolean {- return false;- }-}--CommandManager.register(RetainAction.NAME, RetainAction);diff --git a/packages/core/src/Docs/Action/UpdateDocumentAction.ts b/packages/core/src/Docs/Action/UpdateDocumentAction.tsdeleted file mode 100644index 9ea45fa329..0000000000--- a/packages/core/src/Docs/Action/UpdateDocumentAction.ts+++ /dev/null@@ -1,35 +0,0 @@-import { ActionObservers, CommandManager, CommandUnit } from '../../Command';-import { DocActionBase } from '../../Command/DocActionBase';-import { IUpdateDocumentActionData } from './ActionDataInterface';--export class UpdateDocumentAction extends DocActionBase<IUpdateDocumentActionData, IUpdateDocumentActionData> {- static NAME = 'UpdateDocumentAction';-- 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;- }-}--CommandManager.register(UpdateDocumentAction.NAME, UpdateDocumentAction);diff --git a/packages/core/src/Docs/Action/index.ts b/packages/core/src/Docs/Action/index.tsdeleted file mode 100644index 09cbdf6011..0000000000--- a/packages/core/src/Docs/Action/index.ts+++ /dev/null@@ -1,4 +0,0 @@-export * from './DeleteAction';-export * from './InsertAction';-export * from './RetainAction';-export * from './UpdateDocumentAction';diff --git a/packages/core/src/Docs/Apply/UpdateDocumentApply.ts b/packages/core/src/Docs/Apply/UpdateDocumentApply.tsdeleted file mode 100644index dfe383d995..0000000000--- a/packages/core/src/Docs/Apply/UpdateDocumentApply.ts+++ /dev/null@@ -1,18 +0,0 @@-import { DocumentModel } from '../Domain/DocumentModel';-import { getDocsUpdateBody } from '../../Shared/Common';--export function UpdateDocumentApply(document: DocumentModel, textLength: number, currentIndex: number, segmentId?: string) {- const doc = document.snapshot;-- const bodyModel = document.getBodyModel(segmentId);-- const body = getDocsUpdateBody(doc, segmentId);-- if (textLength === 0) {- return;- }-- if (body == null) {- throw new Error('no body has changed');- }-}diff --git a/packages/core/src/Docs/Apply/index.ts b/packages/core/src/Docs/Apply/index.tsdeleted file mode 100644index 66e86d4ad7..0000000000--- a/packages/core/src/Docs/Apply/index.ts+++ /dev/null@@ -1,4 +0,0 @@-export * from './InsertApply';-export * from './DeleteApply';-export * from './UpdateAttributeApply';-export * from './UpdateDocumentApply';diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.tsindex da6da0c68e..74e744289e 100644--- a/packages/core/src/Docs/Domain/DocumentModel.ts+++ b/packages/core/src/Docs/Domain/DocumentModel.ts@@ -1,13 +1,7 @@-import { Inject } from '@wendellhu/redi';-import { Command, CommandManager } from '../../Command';-import { IDocumentBody, IDocumentData } from '../../Types/Interfaces/IDocumentData';-import { ITextSelectionRange } from '../../Types/Interfaces/ISelectionData';-import { DOC_ACTION_NAMES } from '../../Types/Const/DOC_ACTION_NAMES';-import { Tools, getTextIndexByCursor } from '../../Shared';-import { DocumentBodyModel } from './DocumentBodyModel';+import { Tools } from '../../Shared';import { DEFAULT_DOC } from '../../Types/Const';-import { UpdateDocsAttributeType } from '../../Shared/CommandEnum';-import { DocActionType } from '../Action/ActionDataInterface';+import { IDocumentData } from '../../Types/Interfaces/IDocumentData';+import { DocumentBodyModel } from './DocumentBodyModel';interface IDrawingUpdateConfig {left: number;@@ -114,12 +108,14 @@ export class DocumentModelSimple {}}+const UNIT_ID_LENGTH = 6;+export class DocumentModel extends DocumentModelSimple {private _unitId: string;- constructor(snapshot: Partial<IDocumentData>, @Inject(CommandManager) private readonly _commandManager: CommandManager) {+ constructor(snapshot: Partial<IDocumentData>) {super(snapshot);- this._unitId = this.snapshot.id ?? Tools.generateRandomId(6);+ this._unitId = this.snapshot.id ?? Tools.generateRandomId(UNIT_ID_LENGTH);this.initializeRowColTree();}@@ -128,124 +124,6 @@ export class DocumentModel extends DocumentModelSimple {return this._unitId;}- insert(body: IDocumentBody, range: ITextSelectionRange, segmentId?: string): DocumentModel {- const { cursorStart, cursorEnd, isEndBack, isStartBack, isCollapse } = range;-- const textStart = getTextIndexByCursor(cursorStart, isStartBack);-- const actionList = [];-- if (isCollapse) {- actionList.push({- actionName: DOC_ACTION_NAMES.RETAIN_ACTION_NAME,- len: textStart + 1,- segmentId,- });- } else {- actionList.push(...this._getDeleteAction(range, segmentId));- }-- actionList.push({- actionName: DOC_ACTION_NAMES.INSERT_ACTION_NAME,- body,- len: body.dataStream.length,- line: 0,- segmentId,- });-- const command = new Command(- {- DocumentUnit: this,- },- ...actionList- );- this._commandManager.invoke(command);- return this;- }-- delete(range: ITextSelectionRange, segmentId?: string): DocumentModel {- const deleteActionList = this._getDeleteAction(range, segmentId);-- const command = new Command(- {- DocumentUnit: this,- },- ...deleteActionList- );- this._commandManager.invoke(command);- return this;- }-- update(updateBody: IDocumentBody, range: ITextSelectionRange, coverType = UpdateDocsAttributeType.COVER, segmentId?: string) {- const { cursorStart, cursorEnd, isEndBack, isStartBack } = range;- const actionList = [];-- const textStart = getTextIndexByCursor(cursorStart, isStartBack);-- const textEnd = getTextIndexByCursor(cursorEnd, isEndBack);-- actionList.push({- actionName: DOC_ACTION_NAMES.RETAIN_ACTION_NAME,- len: textStart,- segmentId,- });-- actionList.push({- actionName: DOC_ACTION_NAMES.RETAIN_ACTION_NAME,- len: textEnd - textStart + 1,- coverType,- body: updateBody,- segmentId,- });-- const command = new Command(- {- DocumentUnit: this,- },- ...actionList- );- this._commandManager.invoke(command);- return this;- }-- IMEInput(newText: string, oldTextLen: number, start: number, segmentId?: string) {- const actionList = [];-- actionList.push({- actionName: DOC_ACTION_NAMES.RETAIN_ACTION_NAME,- len: start + 1,- segmentId,- });-- if (oldTextLen > 0) {- actionList.push({- actionName: DOC_ACTION_NAMES.DELETE_ACTION_NAME,- len: oldTextLen,- line: 0,- segmentId,- });- }-- actionList.push({- actionName: DOC_ACTION_NAMES.INSERT_ACTION_NAME,- body: {- dataStream: newText,- },- len: newText.length,- line: 0,- segmentId,- });-- const command = new Command(- {- DocumentUnit: this,- },- ...actionList- );- this._commandManager.invoke(command);- return this;- }-private initializeRowColTree() {this.headerTreeMap = new Map();this.footerTreeMap = new Map();@@ -266,30 +144,4 @@ export class DocumentModel extends DocumentModelSimple {}}}-- private _getDeleteAction(range: ITextSelectionRange, segmentId?: string) {- const { cursorStart, cursorEnd, isEndBack, isStartBack, isCollapse } = range;- const actionList: DocActionType[] = [];-- const textStart = getTextIndexByCursor(cursorStart, isStartBack) + (isCollapse ? 0 : 1);-- const textEnd = getTextIndexByCursor(cursorEnd, isEndBack);-- if (textStart > 0) {- actionList.push({- actionName: DOC_ACTION_NAMES.RETAIN_ACTION_NAME,- len: textStart,- segmentId,- });- }-- actionList.push({- actionName: DOC_ACTION_NAMES.DELETE_ACTION_NAME,- len: textEnd - textStart + 1,- line: 0,- segmentId,- });-- return actionList;- }}diff --git a/packages/core/src/Docs/index.ts b/packages/core/src/Docs/index.tsindex 5eac8de3bd..f764cf325d 100644--- a/packages/core/src/Docs/index.ts+++ b/packages/core/src/Docs/index.ts@@ -1,3 +1 @@-export * from './Action';-export * from './Apply';export * from './Domain';diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 18b38ab31a..a0b1821cd2 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -12,10 +12,7 @@**/-import './Docs/Action';-export * from './Basics';-export * from './Command';export * from './Docs/Domain';export * from './Observer';export * from './Plugin';diff --git a/packages/core/src/services/command/command.service.ts b/packages/core/src/services/command/command.service.tsindex 6c1a07bef2..e19abd0348 100644--- a/packages/core/src/services/command/command.service.ts+++ b/packages/core/src/services/command/command.service.ts@@ -1,6 +1,5 @@import { createIdentifier, IAccessor, IDisposable, Inject, Injector, Optional, SkipSelf } from '@wendellhu/redi';-import { ActionType, CommandManager, IActionData } from '../../Command';import { toDisposable } from '../../Shared/Lifecycle';import { ILogService } from '../log/log.service';@@ -61,7 +60,7 @@ export type CommandListener = (commandInfo: Readonly<ICommandInfo>) => void;export interface ICommandService {registerCommand(command: ICommand): IDisposable;- executeCommand(id: string, params?: object, options?: IExecutionOptions): Promise<boolean> | boolean;+ executeCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): Promise<R> | R;/*** Register a hook that will be triggered when the@@ -197,7 +196,7 @@ export class CommandService implements ICommandService {throw new Error('Could not add a listener twice.');}- async executeCommand(id: string, params?: object): Promise<boolean> {+ async executeCommand<P extends object = object, R = boolean>(id: string, params?: P): Promise<R> {if (this._parentCommandService) {return this._parentCommandService.executeCommand(id, params);}@@ -207,7 +206,7 @@ export class CommandService implements ICommandService {const command = item[0];const injector = item[1];- await this._execute(command, injector, params);+ const result = await this._execute<P, R>(command as ICommand<P, R>, injector, params);const commandInfo: ICommandInfo = {id: command.id,@@ -217,7 +216,7 @@ export class CommandService implements ICommandService {// emit command execution infothis._commandExecutedListeners.forEach((l) => l(commandInfo));- return true;+ return result;}throw new Error(`Command "${id}" is not registered.`);@@ -232,11 +231,11 @@ export class CommandService implements ICommandService {}// eslint-disable-next-line @typescript-eslint/no-explicit-any- private async _execute(command: ICommand, injector: Injector, params?: object): Promise<boolean> {+ private async _execute<P extends object, R = boolean>(command: ICommand<P, R>, injector: Injector, params?: P): Promise<R> {this._log.log(`${'|-'.repeat(this._commandExecutingLevel)}[ICommandService]: executing command "${command.id}".`);this._commandExecutingLevel++;- let result: boolean;+ let result: R | boolean;try {result = await injector.invoke(command.handler, params);this._commandExecutingLevel--;@@ -247,16 +246,6 @@ export class CommandService implements ICommandService {throw e;}- // TODO: remove from old command manager- if (command.type === CommandType.MUTATION) {- CommandManager.getActionObservers().notifyObservers({- type: ActionType.REDO,- data: result as unknown as IActionData,- // eslint-disable-next-line @typescript-eslint/no-explicit-any- action: null as any,- });- }-return result;}}diff --git a/packages/core/src/services/undoredo/undoredo.service.ts b/packages/core/src/services/undoredo/undoredo.service.tsindex 469acc31cb..da4990a56c 100644--- a/packages/core/src/services/undoredo/undoredo.service.ts+++ b/packages/core/src/services/undoredo/undoredo.service.ts@@ -165,4 +165,4 @@ export const RedoCommand = new (class extends MultiImplementationCommand implemereturn false;}-})();\ No newline at end of file+})();diff --git a/packages/core/test/ContainerStartUp.ts b/packages/core/test/ContainerStartUp.tsindex 15e6cca704..8d7ec8f2ba 100644--- a/packages/core/test/ContainerStartUp.ts+++ b/packages/core/test/ContainerStartUp.ts@@ -1,22 +1,15 @@-import { SheetContext, Environment } from '../src/Basics';-import { CommandManager, UndoManager } from '../src/Command';-import { Workbook, Worksheet } from '../src/Sheets/Domain';-import { BooleanNumber } from '../src/Types/Enum';-import { IWorkbookConfig, IWorksheetConfig } from '../src/Types/Interfaces';+import { Injector } from '../src';+import { Environment, SheetContext } from '../src/Basics';import { HooksManager } from '../src/Observer/HooksManager';import { ObserverManager } from '../src/Observer/ObserverManager';import { PluginManager } from '../src/Plugin';-import {- IServerSocketWorkbookConfig,- ServerHttp,- ServerSocket,-} from '../src/Server';+import { IServerSocketWorkbookConfig, ServerHttp, ServerSocket } from '../src/Server';import { Locale } from '../src/Shared';-import { Injector } from '../src';+import { Workbook, Worksheet } from '../src/Sheets/Domain';+import { BooleanNumber } from '../src/Types/Enum';+import { IWorkbookConfig, IWorksheetConfig } from '../src/Types/Interfaces';-export function createCoreTestContainer(- workbookConfig?: Partial<IWorkbookConfig>-): Injector {+export function createCoreTestContainer(workbookConfig?: Partial<IWorkbookConfig>): Injector {const configure = {value: {appVersion: '',@@ -50,8 +43,6 @@ export function createCoreTestContainer(['WorkBook', { useClass: Workbook }],['Locale', { useClass: Locale }],['Context', { useClass: SheetContext }],- ['UndoManager', { useClass: UndoManager }],- ['CommandManager', { useClass: CommandManager }],['PluginManager', { useClass: PluginManager }],['ObserverManager', { useClass: ObserverManager }],['ObservableHooksManager', { useClass: HooksManager }],@@ -147,19 +138,11 @@ export function TestInitTwoSheet() {status: 0,};- const worksheetOne = container.createInstance(- Worksheet,- context,- sheetOneConfigure- );+ const worksheetOne = container.createInstance(Worksheet, context, sheetOneConfigure);workbook.insertSheet(worksheetOne);worksheetOne.setCommandManager(commandManager);- const worksheetTwo = container.createInstance(- Worksheet,- context,- sheetTwoConfigure- );+ const worksheetTwo = container.createInstance(Worksheet, context, sheetTwoConfigure);workbook.insertSheet(worksheetTwo);worksheetTwo.setCommandManager(commandManager);diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.tsindex 6000957ba1..b277d49996 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts@@ -1,12 +1,12 @@import { InsertSheetMutation, RemoveSheetMutation, SetWorksheetActivateCommand, SetWorksheetOrderCommand } from '@univerjs/base-sheets';import { BaseMenuItem, BaseUlProps, ColorPicker, ComponentManager, ICustomComponent, IMenuService } from '@univerjs/base-ui';-import { CommandManager, Disposable, ICommandService, ICurrentUniverService, Nullable, ObserverManager, SheetActionBase, UIObserver } from '@univerjs/core';+import { Disposable, ICommandService, ICurrentUniverService, Nullable, ObserverManager, UIObserver } from '@univerjs/core';import { Inject, Injector, SkipSelf } from '@wendellhu/redi';import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const';import { SheetBar } from '../View/SheetBar';import styles from '../View/SheetBar/index.module.less';-import { SheetBarMenuItem } from '../View/SheetBar/SheetBarMenu';+import { ISheetBarMenuItem } from '../View/SheetBar/SheetBarMenu';import {ChangeColorSheetMenuItemFactory,CopySheetMenuItemFactory,@@ -38,7 +38,7 @@ export class SheetBarUIController extends Disposable {protected _sheetList: SheetUlProps[];- protected _menuList: SheetBarMenuItem[];+ protected _menuList: ISheetBarMenuItem[];// eslint-disable-next-line max-lines-per-functionconstructor(@@ -132,24 +132,6 @@ export class SheetBarUIController extends Disposable {}));- CommandManager.getActionObservers().add((event) => {- const action = event.action as SheetActionBase<any>;- const data = event.data;-- // TODO Do not use try catch-- try {- action.getWorkBook();- } catch (error) {- return;- }-- const workbook = action.getWorkBook();- const unitId = workbook.getUnitId();- const currentWorkbook = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook();- const currentUnitId = currentWorkbook.getUnitId();- });-this._componentManager.register(SHEET_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker);}@@ -174,7 +156,7 @@ export class SheetBarUIController extends Disposable {return this._sheetList;}- getMenuList(): SheetBarMenuItem[] {+ getMenuList(): ISheetBarMenuItem[] {return this._menuList;}diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsindex 50ea52f2eb..e322575091 100644--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts@@ -3,7 +3,6 @@ import { Plugin, Tools, PluginType, LocaleService, IUndoRedoService } from '@uniimport {ComponentManager,getRefElement,- RegisterManager,KeyboardManager,SlotComponent,ZIndexManager,@@ -32,8 +31,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {private _keyboardManager: KeyboardManager;- private _registerManager: RegisterManager;-private _config: ISheetUIPluginConfig;private _zIndexManager: ZIndexManager;@@ -106,14 +103,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {return this._zIndexManager;}- /**- * usage this._clipboardExtensionManager.handle(data);- * @returns- */- getRegisterManager(): RegisterManager {- return this._registerManager;- }-/*** usage this._clipboardExtensionManager.handle(data);* @returns@@ -159,7 +148,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {const dependencies: Dependency[] = [[DragManager],[KeyboardManager],- [RegisterManager],[ComponentManager],[ZIndexManager],[SlotManager],@@ -175,7 +163,6 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {this._componentManager = this._injector.get(ComponentManager);this._keyboardManager = this._injector.get(KeyboardManager);this._zIndexManager = this._injector.get(ZIndexManager);- this._registerManager = this._injector.get(RegisterManager);this._appUIController = this._injector.createInstance(AppUIController, this._config);this._injector.add([AppUIController, { useValue: this._appUIController }]);diff --git a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.tsindex c2bc749dff..9c54025da3 100644--- a/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts+++ b/packages/ui-plugin-slides/src/Controller/ToolbarUIController.ts@@ -1,7 +1,7 @@import { BorderInfo } from '@univerjs/base-slides';import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentManager } from '@univerjs/base-ui';import { ComponentChildren } from 'preact';-import { BorderType, CommandManager, HorizontalAlign, ICurrentUniverService, IKeyValue, ObserverManager, Tools, UIObserver, VerticalAlign, WrapStrategy } from '@univerjs/core';+import { BorderType, HorizontalAlign, ICurrentUniverService, IKeyValue, ObserverManager, Tools, UIObserver, VerticalAlign, WrapStrategy } from '@univerjs/core';import { Inject, SkipSelf } from '@wendellhu/redi';import { DefaultToolbarConfig, SlideToolbarConfig, SLIDE_UI_PLUGIN_NAME } from '../Basics';import { ColorSelect, LineBold, LineColor, Toolbar } from '../View';@@ -262,19 +262,6 @@ export class ToolbarUIController {this._componentManager.register(SLIDE_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker);this._componentManager.register(SLIDE_UI_PLUGIN_NAME + LineColor.name, LineColor);this._componentManager.register(SLIDE_UI_PLUGIN_NAME + LineBold.name, LineBold);-- CommandManager.getCommandObservers().add(({ actions }) => {- // if (!actions || actions.length === 0) return;- // const action = actions[0] as SlideActionBase<ISlideActionData, ISlideActionData, void>;- // const currentUnitId = this._plugin.getContext().getUniver().getCurrentUniverSlideInstance().UniverSlideConfig.id;- // const actionUnitId = action.getWorkBook().getUnitId();- // if (currentUnitId !== actionUnitId) return;- // const manager = this._slidePlugin.getSelectionManager();- // const range = manager?.getCurrentCell();- // if (range) {- // this._changeToolbarState(range);- // }- });}}diff --git a/packages/ui-plugin-slides/src/SlideUIPlugin.ts b/packages/ui-plugin-slides/src/SlideUIPlugin.tsindex e22de9c1b9..6d1ac170d4 100644--- a/packages/ui-plugin-slides/src/SlideUIPlugin.ts+++ b/packages/ui-plugin-slides/src/SlideUIPlugin.ts@@ -1,8 +1,9 @@import { Plugin, Tools, LocaleService, PluginType } from '@univerjs/core';-import { RegisterManager, ComponentManager, getRefElement, DragManager } from '@univerjs/base-ui';+import { ComponentManager, getRefElement, DragManager } from '@univerjs/base-ui';import { IRenderingEngine } from '@univerjs/base-render';import { Inject, Injector } from '@wendellhu/redi';import { CanvasView } from '@univerjs/base-slides';+import { zh, en } from './Locale';import { SLIDE_UI_PLUGIN_NAME } from './Basics/Const/PLUGIN_NAME';import { AppUIController } from './Controller/AppUIController';@@ -14,8 +15,6 @@ export class SlideUIPlugin extends Plugin<SlideUIPluginObserve> {private _appUIController: AppUIController;- private _registerManager: RegisterManager;-private _config: ISlideUIPluginConfig;private _dragManager: DragManager;@@ -88,14 +87,6 @@ export class SlideUIPlugin extends Plugin<SlideUIPluginObserve> {return this._componentManager;}- /**- * usage this._clipboardExtensionManager.handle(data);- * @returns- */- getRegisterManager(): RegisterManager {- return this._registerManager;- }-/*** This API is used in plugins for initialization that depends on UI rendering* @param cb@@ -115,13 +106,11 @@ export class SlideUIPlugin extends Plugin<SlideUIPluginObserve> {private initializeDependencies(): void {this._injector.add([DragManager]);- this._injector.add([RegisterManager]);this._injector.add([ComponentManager]);// TODO: maybe we don't have to instantiate these dependencies manuallythis._dragManager = this._injector.get(DragManager);this._componentManager = this._injector.get(ComponentManager);- this._registerManager = this._injector.get(RegisterManager);this._appUIController = this._injector.createInstance(AppUIController, this._config);}