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): doc-rename (#2891)

zhangw307d1debbc0d
diff --git a/packages/docs/src/commands/mutations/docs-rename.mutation.ts b/packages/docs/src/commands/mutations/docs-rename.mutation.ts
new file mode 100644
index 0000000000..f142a66863
--- /dev/null
+++ b/packages/docs/src/commands/mutations/docs-rename.mutation.ts
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { DocumentDataModel, ICommand } from '@univerjs/core';
+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+
+export interface IDocsRenameMutationParams {
+ name: string;
+ unitId: string;
+}
+
+export const DocsRenameMutation: ICommand = {
+ id: 'doc.mutation.rename-doc',
+ type: CommandType.MUTATION,
+ handler: (accessor, params: IDocsRenameMutationParams) => {
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const doc = univerInstanceService.getUnit<DocumentDataModel>(params.unitId, UniverInstanceType.UNIVER_DOC);
+ if (!doc) {
+ return false;
+ }
+ doc.setName(params.name);
+ return true;
+ },
+};
diff --git a/packages/docs/src/doc-plugin.ts b/packages/docs/src/doc-plugin.ts
index a9a0669177..c938b47ce8 100644
--- a/packages/docs/src/doc-plugin.ts
+++ b/packages/docs/src/doc-plugin.ts
@@ -58,6 +58,7 @@ import { DocStateChangeManagerService } from './services/doc-state-change-manage
import { AlignCenterCommand, AlignJustifyCommand, AlignLeftCommand, AlignOperationCommand, AlignRightCommand } from './commands/commands/paragraph-align.command';
import { DocCustomRangeService } from './services/doc-custom-range.service';
import { DocCustomRangeController } from './controllers/custom-range.controller';
+import { DocsRenameMutation } from './commands/mutations/docs-rename.mutation';
export interface IUniverDocsConfig {
hasScroll?: boolean;
@@ -121,6 +122,7 @@ export class UniverDocsPlugin extends Plugin {
AlignRightCommand,
AlignOperationCommand,
AlignJustifyCommand,
+ DocsRenameMutation,
] as ICommand[]
).forEach((command) => {
this._injector.get(ICommandService).registerCommand(command);