Skip to content

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

feat(docs-ui): doc daily optimization (#2869)

zhangwf0b6410362e8
diff --git a/packages/core/src/docs/data-model/document-data-model.ts b/packages/core/src/docs/data-model/document-data-model.ts
index 9a35a5a754..994fa73a6f 100644
--- a/packages/core/src/docs/data-model/document-data-model.ts
+++ b/packages/core/src/docs/data-model/document-data-model.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import { BehaviorSubject } from 'rxjs';
import type { Nullable } from '../../shared';
import { Tools } from '../../shared/tools';
import type {
@@ -205,6 +206,9 @@ export class DocumentDataModel extends DocumentDataModelSimple {
footerModelMap: Map<string, DocumentDataModel> = new Map();
+ private _name$ = new BehaviorSubject('');
+ readonly name$ = this._name$.asObservable();
+
constructor(snapshot: Partial<IDocumentData>) {
super(Tools.isEmptyObject(snapshot) ? getEmptySnapshot() : snapshot);
@@ -213,9 +217,16 @@ export class DocumentDataModel extends DocumentDataModelSimple {
this._unitId = this.snapshot.id ?? Tools.generateRandomId(UNIT_ID_LENGTH);
this._initializeHeaderFooterModel();
+ this._name$.next(this.snapshot.title ?? '');
+ }
+
+ setName(name: string) {
+ this.snapshot.title = name;
+ this._name$.next(name);
}
override dispose() {
+ super.dispose();
this.headerModelMap.forEach((header) => {
header.dispose();
});
@@ -223,6 +234,8 @@ export class DocumentDataModel extends DocumentDataModelSimple {
this.footerModelMap.forEach((footer) => {
footer.dispose();
});
+
+ this._name$.complete();
}
getDrawings() {
diff --git a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts
index 697355f89e..c9ec597c4d 100644
--- a/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts
+++ b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-clipboard.controller.ts
@@ -15,9 +15,10 @@
*/
import type { DocumentDataModel } from '@univerjs/core';
-import { CustomRangeType, Disposable, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, Tools, UniverInstanceType, updateAttributeByDelete } from '@univerjs/core';
+import { CustomRangeType, Disposable, ICommandService, Inject, IUniverInstanceService, LifecycleStages, OnLifecycle, Tools, UniverInstanceType, updateAttributeByDelete } from '@univerjs/core';
import { TextSelectionManagerService } from '@univerjs/docs';
-import { DocHyperLinkModel } from '@univerjs/docs-hyper-link';
+import type { IAddDocHyperLinkMutationParams } from '@univerjs/docs-hyper-link';
+import { AddDocHyperLinkMutation, DocHyperLinkModel } from '@univerjs/docs-hyper-link';
import { IDocClipboardService } from '@univerjs/docs-ui';
@OnLifecycle(LifecycleStages.Ready, DocHyperLinkClipboardController)
@@ -26,7 +27,8 @@ export class DocHyperLinkClipboardController extends Disposable {
@Inject(IDocClipboardService) private readonly _docClipboardService: IDocClipboardService,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(DocHyperLinkModel) private readonly _hyperLinkModel: DocHyperLinkModel,
- @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService
+ @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
+ @ICommandService private readonly _commandService: ICommandService
) {
super();
@@ -65,25 +67,39 @@ export class DocHyperLinkClipboardController extends Disposable {
}
return bodyWithoutLink;
} else {
+ const unitId = doc.getUnitId();
const customRangeIds = new Set(customRanges?.map((i) => i.rangeType === CustomRangeType.HYPERLINK && i.rangeId));
body.customRanges?.forEach((range) => {
if (range.rangeType === CustomRangeType.HYPERLINK) {
if (customRangeIds.has(range.rangeId)) {
- const link = this._hyperLinkModel.getLink(doc.getUnitId(), range.rangeId);
+ const link = this._hyperLinkModel.getLink(unitId, range.rangeId);
if (link) {
const newId = Tools.generateRandomId();
- this._hyperLinkModel.addLink(doc.getUnitId(), {
- payload: link.payload,
- id: newId,
- });
+ this._commandService.executeCommand(
+ AddDocHyperLinkMutation.id,
+ {
+ unitId,
+ link: {
+ id: newId,
+ payload: link.payload,
+ },
+ } as IAddDocHyperLinkMutationParams
+ );
+
range.rangeId = newId;
}
} else if (body.payloads?.[range.rangeId]) {
const url = body.payloads[range.rangeId];
- this._hyperLinkModel.addLink(doc.getUnitId(), {
- payload: url,
- id: range.rangeId,
- });
+ this._commandService.executeCommand(
+ AddDocHyperLinkMutation.id,
+ {
+ unitId,
+ link: {
+ id: range.rangeId,
+ payload: url,
+ },
+ } as IAddDocHyperLinkMutationParams
+ );
}
}
});
diff --git a/packages/docs-hyper-link/src/controllers/doc-hyper-link-custom-range.controller.ts b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-custom-range.controller.ts
similarity index 62%
rename from packages/docs-hyper-link/src/controllers/doc-hyper-link-custom-range.controller.ts
rename to packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-custom-range.controller.ts
index f4c154ee21..9fa276636f 100644
--- a/packages/docs-hyper-link/src/controllers/doc-hyper-link-custom-range.controller.ts
+++ b/packages/docs-hyper-link-ui/src/controllers/doc-hyper-link-custom-range.controller.ts
@@ -14,15 +14,17 @@
* limitations under the License.
*/
-import { CustomRangeType, Disposable, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
+import { CustomRangeType, Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
import { DocCustomRangeService } from '@univerjs/docs';
-import { DocHyperLinkModel } from '../models/hyper-link.model';
+import type { IAddDocHyperLinkMutationParams } from '@univerjs/docs-hyper-link';
+import { AddDocHyperLinkMutation, DocHyperLinkModel } from '@univerjs/docs-hyper-link';
@OnLifecycle(LifecycleStages.Ready, DocHyperLinkCustomRangeController)
export class DocHyperLinkCustomRangeController extends Disposable {
constructor(
@Inject(DocCustomRangeService) private readonly _docCustomRangeService: DocCustomRangeService,
- @Inject(DocHyperLinkModel) private readonly _docHyperLinkModel: DocHyperLinkModel
+ @Inject(DocHyperLinkModel) private readonly _docHyperLinkModel: DocHyperLinkModel,
+ @ICommandService private readonly _commandService: ICommandService
) {
super();
@@ -37,10 +39,16 @@ export class DocHyperLinkCustomRangeController extends Disposable {
if (rangeType === CustomRangeType.HYPERLINK) {
if (data) {
const id = Tools.generateRandomId();
- this._docHyperLinkModel.addLink(unitId, {
- id,
- payload: data,
- });
+ this._commandService.executeCommand(
+ AddDocHyperLinkMutation.id,
+ {
+ unitId,
+ link: {
+ id,
+ payload: data,
+ },
+ } as IAddDocHyperLinkMutationParams
+ );
return {
...range,
rangeId: id,
@@ -51,10 +59,16 @@ export class DocHyperLinkCustomRangeController extends Disposable {
return range;
}
const newId = Tools.generateRandomId();
- this._docHyperLinkModel.addLink(unitId, {
- id: newId,
- payload: link.payload,
- });
+ this._commandService.executeCommand(
+ AddDocHyperLinkMutation.id,
+ {
+ unitId,
+ link: {
+ id: newId,
+ payload: link.payload,
+ },
+ } as IAddDocHyperLinkMutationParams
+ );
return {
...ext,
diff --git a/packages/docs-hyper-link-ui/src/plugin.ts b/packages/docs-hyper-link-ui/src/plugin.ts
index d8f96754de..b21a76769a 100644
--- a/packages/docs-hyper-link-ui/src/plugin.ts
+++ b/packages/docs-hyper-link-ui/src/plugin.ts
@@ -25,6 +25,7 @@ import { DocHyperLinkPopupService } from './services/hyper-link-popup.service';
import { DocHyperLinkSelectionController } from './controllers/doc-hyper-link-selection.controller';
import { DocHyperLinkRenderController } from './controllers/render-controllers/render.controller';
import { DocHyperLinkClipboardController } from './controllers/doc-hyper-link-clipboard.controller';
+import { DocHyperLinkCustomRangeController } from './controllers/doc-hyper-link-custom-range.controller';
@DependentOn(UniverDocsHyperLinkPlugin)
export class UniverDocsHyperLinkUIPlugin extends Plugin {
@@ -49,6 +50,7 @@ export class UniverDocsHyperLinkUIPlugin extends Plugin {
],
[DocHyperLinkSelectionController],
[DocHyperLinkClipboardController],
+ [DocHyperLinkCustomRangeController],
];
deps.forEach((dep) => {
diff --git a/packages/docs-hyper-link/package.json b/packages/docs-hyper-link/package.json
index de7b7dd54a..0dde799900 100644
--- a/packages/docs-hyper-link/package.json
+++ b/packages/docs-hyper-link/package.json
@@ -58,7 +58,6 @@
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
- "@univerjs/docs": "workspace:*",
"rxjs": ">=7.0.0"
},
"devDependencies": {
diff --git a/packages/docs-hyper-link/src/plugin.ts b/packages/docs-hyper-link/src/plugin.ts
index 9b763590f7..2020165623 100644
--- a/packages/docs-hyper-link/src/plugin.ts
+++ b/packages/docs-hyper-link/src/plugin.ts
@@ -14,16 +14,13 @@
* limitations under the License.
*/
-import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
+import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
-import { UniverDocsPlugin } from '@univerjs/docs';
import { DOC_HYPER_LINK_PLUGIN } from './types/const';
import { DocHyperLinkModel } from './models/hyper-link.model';
import { DocHyperLinkController } from './controllers/hyper-link.controller';
import { DocHyperLinkResourceController } from './controllers/resource.controller';
-import { DocHyperLinkCustomRangeController } from './controllers/doc-hyper-link-custom-range.controller';
-@DependentOn(UniverDocsPlugin)
export class UniverDocsHyperLinkPlugin extends Plugin {
static override pluginName = DOC_HYPER_LINK_PLUGIN;
static override type = UniverInstanceType.UNIVER_DOC;
@@ -40,7 +37,6 @@ export class UniverDocsHyperLinkPlugin extends Plugin {
[DocHyperLinkModel],
[DocHyperLinkController],
[DocHyperLinkResourceController],
- [DocHyperLinkCustomRangeController],
];
deps.forEach((dep) => {
diff --git a/packages/docs-mention/src/controllers/doc-mention-custom-range.controller.ts b/packages/docs-mention-ui/src/controllers/doc-mention-custom-range.controller.ts
similarity index 71%
rename from packages/docs-mention/src/controllers/doc-mention-custom-range.controller.ts
rename to packages/docs-mention-ui/src/controllers/doc-mention-custom-range.controller.ts
index 4ca28f183d..4955ec1387 100644
--- a/packages/docs-mention/src/controllers/doc-mention-custom-range.controller.ts
+++ b/packages/docs-mention-ui/src/controllers/doc-mention-custom-range.controller.ts
@@ -14,15 +14,17 @@
* limitations under the License.
*/
-import { CustomRangeType, Disposable, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
+import { CustomRangeType, Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
import { DocCustomRangeService } from '@univerjs/docs';
-import { DocMentionModel } from '../models/doc-mention.model';
+import type { IAddDocMentionMutationParams } from '@univerjs/docs-mention';
+import { AddDocMentionMutation, DocMentionModel } from '@univerjs/docs-mention';
@OnLifecycle(LifecycleStages.Ready, DocMentionCustomRangeController)
export class DocMentionCustomRangeController extends Disposable {
constructor(
@Inject(DocCustomRangeService) private readonly _docCustomRangeService: DocCustomRangeService,
- @Inject(DocMentionModel) private readonly _docMentionModel: DocMentionModel
+ @Inject(DocMentionModel) private readonly _docMentionModel: DocMentionModel,
+ @ICommandService private readonly _commandService: ICommandService
) {
super();
@@ -46,14 +48,21 @@ export class DocMentionCustomRangeController extends Disposable {
rangeId: id,
};
}
- const link = this._docMentionModel.copyMention(unitId, rangeId);
- if (!link) {
+ const mention = this._docMentionModel.copyMention(unitId, rangeId);
+ this._commandService.executeCommand(
+ AddDocMentionMutation.id,
+ {
+ unitId,
+ mention,
+ } as IAddDocMentionMutationParams
+ );
+ if (!mention) {
return range;
}
return {
...ext,
- rangeId: link.id,
+ rangeId: mention.id,
rangeType,
};
}
diff --git a/packages/docs-mention-ui/src/plugin.ts b/packages/docs-mention-ui/src/plugin.ts
index fd86bbdef8..7d1df4cb01 100644
--- a/packages/docs-mention-ui/src/plugin.ts
+++ b/packages/docs-mention-ui/src/plugin.ts
@@ -21,6 +21,7 @@ import { DOC_MENTION_UI_PLUGIN } from './types/const/const';
import { DocMentionPopupService } from './services/doc-mention-popup.service';
import { DocMentionUIController } from './controllers/doc-mention-ui.controller';
import { DocMentionTriggerController } from './controllers/doc-mention-trigger.controller';
+import { DocMentionCustomRangeController } from './controllers/doc-mention-custom-range.controller';
@DependentOn(UniverDocsMentionPlugin)
export class UniverDocsMentionUIPlugin extends Plugin {
@@ -39,6 +40,7 @@ export class UniverDocsMentionUIPlugin extends Plugin {
[DocMentionPopupService],
[DocMentionUIController],
[DocMentionTriggerController],
+ [DocMentionCustomRangeController],
];
deps.forEach((dep) => {
diff --git a/packages/docs-mention/src/models/doc-mention.model.ts b/packages/docs-mention/src/models/doc-mention.model.ts
index d0fb61cce1..cae1185ff1 100644
--- a/packages/docs-mention/src/models/doc-mention.model.ts
+++ b/packages/docs-mention/src/models/doc-mention.model.ts
@@ -50,7 +50,6 @@ export class DocMentionModel extends Disposable {
const newId = Tools.generateRandomId();
const newMention = { ...mention, id: newId };
- this.addMention(unitId, newMention);
return newMention;
}
diff --git a/packages/docs-mention/src/plugin.ts b/packages/docs-mention/src/plugin.ts
index 1427676e52..5c835d6606 100644
--- a/packages/docs-mention/src/plugin.ts
+++ b/packages/docs-mention/src/plugin.ts
@@ -14,17 +14,14 @@
* limitations under the License.
*/
-import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
+import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
-import { UniverDocsPlugin } from '@univerjs/docs';
import { DOC_MENTION_PLUGIN } from './types/const/const';
import { DocMentionModel } from './models/doc-mention.model';
import { DocMentionController } from './controllers/doc-mention.controller';
-import { DocMentionCustomRangeController } from './controllers/doc-mention-custom-range.controller';
import { DocMentionService } from './services/doc-mention.service';
import { DocMentionResourceController } from './controllers/doc-mention-resource.controller';
-@DependentOn(UniverDocsPlugin)
export class UniverDocsMentionPlugin extends Plugin {
static override pluginName = DOC_MENTION_PLUGIN;
static override type = UniverInstanceType.UNIVER_DOC;
@@ -40,9 +37,7 @@ export class UniverDocsMentionPlugin extends Plugin {
const deps: Dependency[] = [
[DocMentionModel],
[DocMentionService],
-
[DocMentionController],
- [DocMentionCustomRangeController],
[DocMentionResourceController],
];
diff --git a/packages/docs-thread-comment-ui/src/commands/commands/add-doc-comment.command.ts b/packages/docs-thread-comment-ui/src/commands/commands/add-doc-comment.command.ts
index 0808833cf5..86c214097f 100644
--- a/packages/docs-thread-comment-ui/src/commands/commands/add-doc-comment.command.ts
+++ b/packages/docs-thread-comment-ui/src/commands/commands/add-doc-comment.command.ts
@@ -18,7 +18,7 @@ import type { ICommand, ITextRange } from '@univerjs/core';
import { CommandType, CustomDecorationType, ICommandService, sequenceExecuteAsync } from '@univerjs/core';
import { addCustomDecorationBySelectionFactory } from '@univerjs/docs';
import type { IThreadComment } from '@univerjs/thread-comment';
-import { AddCommentCommand, IThreadCommentDataSourceService } from '@univerjs/thread-comment';
+import { AddCommentMutation, IThreadCommentDataSourceService } from '@univerjs/thread-comment';
import { SetActiveCommentOperation } from '@univerjs/thread-comment-ui';
import { DEFAULT_DOC_SUBUNIT_ID } from '../../common/const';
@@ -49,7 +49,7 @@ export const AddDocCommentComment: ICommand<IAddDocCommentComment> = {
);
if (doMutation) {
const addComment = {
- id: AddCommentCommand.id,
+ id: AddCommentMutation.id,
params: {
unitId,
subUnitId: DEFAULT_DOC_SUBUNIT_ID,