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(facade): command execute event callback add options parameters (#4945)

wpxp12345613ce55c05f23
diff --git a/packages/core/src/facade/f-event.ts b/packages/core/src/facade/f-event.ts
index 03703f0d48..e649455ea7 100644
--- a/packages/core/src/facade/f-event.ts
+++ b/packages/core/src/facade/f-event.ts
@@ -16,7 +16,7 @@
/* eslint-disable ts/explicit-function-return-type */
-import type { CommandType, IDocumentData, LifecycleStages, UniverInstanceType } from '@univerjs/core';
+import type { CommandType, IDocumentData, IExecutionOptions, LifecycleStages, UniverInstanceType } from '@univerjs/core';
import type { FDoc } from './f-doc';
/**
@@ -81,6 +81,8 @@ export interface ICommandEvent extends IEventBase {
id: string;
/** Type of the command */
type: CommandType;
+ /** optional execution options for the command */
+ options?: IExecutionOptions;
}
/**
@@ -259,7 +261,7 @@ export class FEventName {
* @example
* ```ts
* const disposable = univerAPI.addEvent(univerAPI.Event.CommandExecuted, (event) => {
- * const { params, id, type } = event;
+ * const { params, id, type, options } = event;
* console.log('command executed', event);
* });
*
@@ -276,7 +278,7 @@ export class FEventName {
* @example
* ```ts
* const disposable = univerAPI.addEvent(univerAPI.Event.BeforeCommandExecute, (event) => {
- * const { params, id, type } = event;
+ * const { params, id, type, options } = event;
* console.log('before command executed', event);
*
* // Cancel the command execution
diff --git a/packages/core/src/facade/f-univer.ts b/packages/core/src/facade/f-univer.ts
index e370f07cd2..e1f5272574 100644
--- a/packages/core/src/facade/f-univer.ts
+++ b/packages/core/src/facade/f-univer.ts
@@ -162,11 +162,11 @@ export class FUniver extends Disposable {
this.registerEventHandler(
this.Event.CommandExecuted,
- () => commandService.onCommandExecuted((commandInfo) => {
+ () => commandService.onCommandExecuted((commandInfo, options) => {
const { id, type: propType, params } = commandInfo;
if (commandInfo.id !== RedoCommand.id && commandInfo.id !== UndoCommand.id) {
const type = propType!;
- const eventParams: ICommandEvent = { id, type, params };
+ const eventParams: ICommandEvent = { id, type, params, options };
this.fireEvent(this.Event.CommandExecuted, eventParams);
}
})
@@ -210,11 +210,11 @@ export class FUniver extends Disposable {
this.registerEventHandler(
this.Event.BeforeCommandExecute,
- () => commandService.beforeCommandExecuted((commandInfo) => {
+ () => commandService.beforeCommandExecuted((commandInfo, options) => {
const { id, type: propType, params } = commandInfo;
if (commandInfo.id !== RedoCommand.id && commandInfo.id !== UndoCommand.id) {
const type = propType!;
- const eventParams: ICommandEvent = { id, type, params };
+ const eventParams: ICommandEvent = { id, type, params, options };
this.fireEvent(this.Event.BeforeCommandExecute, eventParams);
if (eventParams.cancel) {
diff --git a/packages/sheets/src/facade/f-univer.ts b/packages/sheets/src/facade/f-univer.ts
index 978dd2b9cd..465550475c 100644
--- a/packages/sheets/src/facade/f-univer.ts
+++ b/packages/sheets/src/facade/f-univer.ts
@@ -138,7 +138,8 @@ export interface IFUniverSheetsMixin {
* @returns {Nullable<{ workbook: FWorkbook; worksheet: FWorksheet }>} - The target of the sheet.
* @example
* ```ts
- * univerAPI.addEvent(univerAPI.Event.CommandExecuted, (commandInfo) => {
+ * univerAPI.addEvent(univerAPI.Event.CommandExecuted, (event) => {
+ * const { options, ...commandInfo } = event;
* const target = univerAPI.getCommandSheetTarget(commandInfo);
* if (!target) return;
* const { workbook, worksheet } = target;