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): add more Facade API (#1029)

Wenzhao Hu6224b4f3e22c
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 15d9a8c5ad..f8281eb9c5 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -16,6 +16,7 @@ packages/design @jikkai @wzhudev
# common
packages/image @DR-Univer
packages/uniscript @wzhudev
+packages/find-replace @wzhudev
# docs
packages/docs @DR-Univer @Jocs
diff --git a/examples/package.json b/examples/package.json
index dc01b7a406..39d03ce640 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -14,6 +14,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
+ "@univerjs/find-replace": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.24",
"@univerjs/rpc": "workspace:*",
diff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.ts
index 213e6f12bf..8cc5226a0b 100644
--- a/examples/src/sheets/main.ts
+++ b/examples/src/sheets/main.ts
@@ -20,6 +20,7 @@ import { UniverDocsPlugin } from '@univerjs/docs';
import { UniverDocsUIPlugin } from '@univerjs/docs-ui';
import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula';
import { UniverRenderEnginePlugin } from '@univerjs/engine-render';
+import { UniverFindReplacePlugin } from '@univerjs/find-replace';
import type { IUniverRPCMainThreadConfig } from '@univerjs/rpc';
import { UniverRPCMainThreadPlugin } from '@univerjs/rpc';
import { UniverSheetsPlugin } from '@univerjs/sheets';
@@ -53,11 +54,14 @@ univer.registerPlugin(UniverUIPlugin, {
toolbar: true,
footer: true,
});
+univer.registerPlugin(UniverFindReplacePlugin);
+
+univer.registerPlugin(UniverDocsUIPlugin);
+
univer.registerPlugin(UniverSheetsPlugin, {
notExecuteFormula: true,
});
univer.registerPlugin(UniverSheetsUIPlugin);
-univer.registerPlugin(UniverDocsUIPlugin);
// sheet feature plugins
@@ -76,6 +80,7 @@ univer.registerPlugin(UniverRPCMainThreadPlugin, {
univer.createUniverSheet(DEFAULT_WORKBOOK_DATA_DEMO);
declare global {
+ // eslint-disable-next-line @typescript-eslint/naming-convention
interface Window {
univer?: Univer;
}
diff --git a/packages/core/src/services/command/command.service.spec.ts b/packages/core/src/services/command/__tests__/command.service.spec.ts
similarity index 96%
rename from packages/core/src/services/command/command.service.spec.ts
rename to packages/core/src/services/command/__tests__/command.service.spec.ts
index 2b040777e0..c181519bb9 100644
--- a/packages/core/src/services/command/command.service.spec.ts
+++ b/packages/core/src/services/command/__tests__/command.service.spec.ts
@@ -19,10 +19,16 @@
import { Injector } from '@wendellhu/redi';
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { ContextService, IContextService } from '../context/context.service';
-import { DesktopLogService, ILogService } from '../log/log.service';
-import type { IMultiCommand } from './command.service';
-import { CommandService, CommandType, ICommandService, sequenceExecute, sequenceExecuteAsync } from './command.service';
+import { ContextService, IContextService } from '../../context/context.service';
+import { DesktopLogService, ILogService } from '../../log/log.service';
+import type { IMultiCommand } from '../command.service';
+import {
+ CommandService,
+ CommandType,
+ ICommandService,
+ sequenceExecute,
+ sequenceExecuteAsync,
+} from '../command.service';
const commandID = 'emit-plural-error-command';
const anotherCommandID = 'another-command';
diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.ts
index 8e11e5f4c9..e30fe411ad 100644
--- a/packages/core/src/sheets/workbook.ts
+++ b/packages/core/src/sheets/workbook.ts
@@ -121,6 +121,10 @@ export class Workbook extends Disposable {
return this._snapshot;
}
+ getName(): string {
+ return this._snapshot.name;
+ }
+
getUnitId() {
return this._unitId;
}
diff --git a/packages/facade/package.json b/packages/facade/package.json
index 8a0544c265..9aa925801e 100644
--- a/packages/facade/package.json
+++ b/packages/facade/package.json
@@ -47,6 +47,7 @@
"@univerjs/sheets": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
+ "@univerjs/sheets-numfmt": "workspace:*",
"@wendellhu/redi": "^0.12.13",
"rxjs": "^7.8.1"
},
@@ -62,6 +63,8 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/sheets": "workspace:*",
+ "@univerjs/sheets-formula": "workspace:*",
+ "@univerjs/sheets-numfmt": "workspace:*",
"@wendellhu/redi": ">=0.12.13",
"rxjs": ">=7.0.0"
}
diff --git a/packages/facade/src/apis/facade.ts b/packages/facade/src/apis/facade.ts
index f3fd34d361..1d6d111a5a 100644
--- a/packages/facade/src/apis/facade.ts
+++ b/packages/facade/src/apis/facade.ts
@@ -14,10 +14,18 @@
* limitations under the License.
*/
-import type { IWorkbookData } from '@univerjs/core';
-import { ICommandService, IUniverInstanceService, Univer } from '@univerjs/core';
+import type { CommandListener, IWorkbookData } from '@univerjs/core';
+import {
+ BorderStyleTypes,
+ ICommandService,
+ IUniverInstanceService,
+ UndoCommand,
+ Univer,
+ WrapStrategy,
+} from '@univerjs/core';
import type { IRegisterFunctionParams, IUnregisterFunctionParams } from '@univerjs/sheets-formula';
import { IRegisterFunctionService } from '@univerjs/sheets-formula';
+import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { FWorkbook } from './sheet/f-workbook';
@@ -31,6 +39,9 @@ export class FUniver {
return injector.createInstance(FUniver);
}
+ static BorderStyle = BorderStyleTypes;
+ static WrapStrategy = WrapStrategy;
+
constructor(
@Inject(Injector) private readonly _injector: Injector,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@@ -38,12 +49,35 @@ export class FUniver {
@IRegisterFunctionService private readonly _registerFunctionService: IRegisterFunctionService
) {}
+ /**
+ * Create a new spreadsheet and get the API handler of that spreadsheet.
+ * @param data the snapshot of the spreadsheet.
+ * @returns Spreadsheet API instance.
+ */
createUniverSheet(data: IWorkbookData): FWorkbook {
const workbook = this._univerInstanceService.createSheet(data);
return this._injector.createInstance(FWorkbook, workbook);
}
- getCurrentSheet(): FWorkbook | null {
+ /**
+ * Get the spreadsheet API handler by the spreadsheet id.
+ * @param id the spreadsheet id.
+ * @returns Spreadsheet API instance.
+ */
+ getUniverSheet(id: string): FWorkbook | null {
+ const workbook = this._univerInstanceService.getUniverSheetInstance(id);
+ if (!workbook) {
+ return null;
+ }
+
+ return this._injector.createInstance(FWorkbook, workbook);
+ }
+
+ /**
+ * Get the currently focused Univer spreadsheet.
+ * @returns the currently focused Univer spreadsheet.
+ */
+ getActiveSheet(): FWorkbook | null {
const workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
if (!workbook) {
return null;
@@ -59,4 +93,43 @@ export class FUniver {
unregisterFunction(config: IUnregisterFunctionParams) {
this._registerFunctionService.unregisterFunctions(config);
}
+
+ // #region
+
+ /**
+ * Undo an editing on the currently focused document.
+ * @returns redo result
+ */
+ undo(): Promise<boolean> {
+ return this._commandService.executeCommand(UndoCommand.id);
+ }
+
+ /**
+ * Redo an editing on the currently focused document.
+ * @returns redo result
+ */
+ redo(): Promise<boolean> {
+ return this._commandService.executeCommand(UndoCommand.id);
+ }
+
+ // #endregion
+
+ // #region editing
+
+ // #callback
+
+ // #region listeners
+
+ /**
+ * Register a callback that will be triggered when a command is invoked.
+ * @param callback the callback.
+ * @returns A function to dispose the listening.
+ */
+ onCommandExecuted(callback: CommandListener): IDisposable {
+ return this._commandService.onCommandExecuted((command) => {
+ callback(command);
+ });
+ }
+
+ // @endregion
}
diff --git a/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts b/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts
index 3286da2cea..c0550a5b90 100644
--- a/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts
+++ b/packages/facade/src/apis/sheet/__tests__/f-range.spec.ts
@@ -14,7 +14,9 @@
* limitations under the License.
*/
-import type { ICellData, IStyleData, Nullable, Univer } from '@univerjs/core';
+/* eslint-disable no-magic-numbers */
+
+import type { ICellData, IStyleData, Nullable } from '@univerjs/core';
import { ICommandService, IUniverInstanceService } from '@univerjs/core';
import { SetRangeValuesCommand, SetRangeValuesMutation, SetStyleCommand } from '@univerjs/sheets';
import type { Injector } from '@wendellhu/redi';
@@ -24,7 +26,6 @@ import type { FUniver } from '../../facade';
import { createTestBed } from './create-test-bed';
describe('Test FRange', () => {
- let univer: Univer;
let get: Injector['get'];
let commandService: ICommandService;
let univerAPI: FUniver;
@@ -43,7 +44,6 @@ describe('Test FRange', () => {
beforeEach(() => {
const testBed = createTestBed();
- univer = testBed.univer;
get = testBed.get;
univerAPI = testBed.univerAPI;
@@ -79,7 +79,7 @@ describe('Test FRange', () => {
});
it('Range setValue', () => {
- const activeSheet = univerAPI.getCurrentSheet()?.getActiveSheet();
+ const activeSheet = univerAPI.getActiveSheet()?.getActiveSheet();
// A1 sets the number
const range1 = activeSheet?.getRange(0, 0, 1, 1);
@@ -117,7 +117,7 @@ describe('Test FRange', () => {
});
it('Range setValues', () => {
- const activeSheet = univerAPI.getCurrentSheet()?.getActiveSheet();
+ const activeSheet = univerAPI.getActiveSheet()?.getActiveSheet();
// B3:C4 sets value
const range1 = activeSheet?.getRange(2, 1, 2, 2);
@@ -176,7 +176,7 @@ describe('Test FRange', () => {
});
it('Range setFontWeight', () => {
- const activeSheet = univerAPI.getCurrentSheet()?.getActiveSheet();
+ const activeSheet = univerAPI.getActiveSheet()?.getActiveSheet();
// change A1 font weight
const range = activeSheet?.getRange(0, 0, 1, 1);
diff --git a/packages/facade/src/apis/sheet/f-range.ts b/packages/facade/src/apis/sheet/f-range.ts
index bfbe4b9846..9d2a031cb8 100644
--- a/packages/facade/src/apis/sheet/f-range.ts
+++ b/packages/facade/src/apis/sheet/f-range.ts
@@ -15,7 +15,6 @@
*/
import type {
- BooleanNumber,
ICellData,
ICellV,
IColorStyle,
@@ -24,12 +23,34 @@ import type {
Workbook,
Worksheet,
} from '@univerjs/core';
-import { ICommandService } from '@univerjs/core';
-import type { ISetStyleCommandParams, IStyleTypeValue } from '@univerjs/sheets';
-import { SetRangeValuesCommand, SetStyleCommand } from '@univerjs/sheets';
+import { BooleanNumber, ICommandService, WrapStrategy } from '@univerjs/core';
+import type {
+ ISetHorizontalTextAlignCommandParams,
+ ISetStyleCommandParams,
+ ISetTextWrapCommandParams,
+ ISetVerticalTextAlignCommandParams,
+ IStyleTypeValue,
+} from '@univerjs/sheets';
+import {
+ SetHorizontalTextAlignCommand,
+ SetRangeValuesCommand,
+ SetStyleCommand,
+ SetTextWrapCommand,
+ SetVerticalTextAlignCommand,
+} from '@univerjs/sheets';
+import type { ISetNumfmtCommandParams } from '@univerjs/sheets-numfmt';
+import { SetNumfmtCommand } from '@univerjs/sheets-numfmt';
import { Inject, Injector } from '@wendellhu/redi';
-import { covertCellValue, covertCellValues } from './utils';
+import type { FHorizontalAlignment, FVerticalAlignment } from './utils';
+import {
+ covertCellValue,
+ covertCellValues,
+ transformCoreHorizontalAlignment,
+ transformCoreVerticalAlignment,
+ transformFacadeHorizontalAlignment,
+ transformFacadeVerticalAlignment,
+} from './utils';
type FontWeight = 'bold' | 'normal';
@@ -62,8 +83,26 @@ export class FRange {
return this._worksheet.getCell(this._range.startRow, this._range.startColumn)?.v ?? null;
}
- setBackgroundColor(color: string): void {
- this._commandService.executeCommand(SetStyleCommand.id, {
+ getWrap(): boolean {
+ return this._worksheet.getRange(this._range).getWrap() === BooleanNumber.TRUE;
+ }
+
+ getWrapStrategy(): WrapStrategy {
+ return this._worksheet.getRange(this._range).getWrapStrategy();
+ }
+
+ getHorizontalAlignment(): string {
+ return transformCoreHorizontalAlignment(this._worksheet.getRange(this._range).getHorizontalAlignment());
+ }
+
+ getVerticalAlignment(): string {
+ return transformCoreVerticalAlignment(this._worksheet.getRange(this._range).getVerticalAlignment());
+ }
+
+ // #region editing
+
+ setBackgroundColor(color: string): Promise<boolean> {
+ return this._commandService.executeCommand(SetStyleCommand.id, {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
range: this._range,
@@ -80,14 +119,14 @@ export class FRange {
* The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
* @param value
*/
- setValue(value: ICellV | ICellData): void {
+ setValue(value: ICellV | ICellData): Promise<boolean> {
const realValue = covertCellValue(value);
if (!realValue) {
throw new Error('Invalid value');
}
- this._commandService.executeCommand(SetRangeValuesCommand.id, {
+ return this._commandService.executeCommand(SetRangeValuesCommand.id, {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
range: this._range,
@@ -95,16 +134,69 @@ export class FRange {
});
}
+ setWrap(isWrapEnabled: boolean): Promise<boolean> {
+ return this._commandService.executeCommand(SetTextWrapCommand.id, {
+ unitId: this._workbook.getUnitId(),
+ subUnitId: this._worksheet.getSheetId(),
+ range: this._range,
+ value: isWrapEnabled ? WrapStrategy.WRAP : WrapStrategy.UNSPECIFIED,
+ } as ISetTextWrapCommandParams);
+ }
+
+ setWrapStrategy(strategy: WrapStrategy): Promise<boolean> {
+ return this._commandService.executeCommand(SetTextWrapCommand.id, {
+ unitId: this._workbook.getUnitId(),
+ subUnitId: this._worksheet.getSheetId(),
+ range: this._range,
+ value: strategy,
+ } as ISetTextWrapCommandParams);
+ }
+
+ setVerticalAlignment(alignment: FVerticalAlignment): Promise<boolean> {
+ return this._commandService.executeCommand(SetVerticalTextAlignCommand.id, {
+ unitId: this._workbook.getUnitId(),
+ subUnitId: this._worksheet.getSheetId(),
+ range: this._range,
+ value: transformFacadeVerticalAlignment(alignment),
+ } as ISetVerticalTextAlignCommandParams);
+ }
+
+ setHorizontalAlignment(alignment: FHorizontalAlignment): Promise<boolean> {
+ return this._commandService.executeCommand(SetHorizontalTextAlignCommand.id, {
+ unitId: this._workbook.getUnitId(),
+ subUnitId: this._worksheet.getSheetId(),
+ range: this._range,
+ value: transformFacadeHorizontalAlignment(alignment),
+ } as ISetHorizontalTextAlignCommandParams);
+ }
+
+ /**
+ * Set the number format of the range.
+ * @param pattern number format pattern.
+ * @returns Execution result.
+ */
+ setNumberFormat(pattern: string): Promise<boolean> {
+ // TODO@Gggpound: the API should support other types of parameters
+ const values: ISetNumfmtCommandParams['values'] = [];
+
+ // Add number format info to the `values` array.
+ this.forEach((row, col) => values.push({ row, col, pattern }));
+ return this._commandService.executeCommand(SetNumfmtCommand.id, {
+ unitId: this._workbook.getUnitId(),
+ subUnitId: this._worksheet.getSheetId(),
+ } as ISetNumfmtCommandParams);
+ }
+
/**
* Sets a different value for each cell in the range. The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats. If a value begins with `=`, it is interpreted as a formula.
* @param value
*/
setValues(
value: ICellV[][] | IObjectMatrixPrimitiveType<ICellV> | ICellData[][] | IObjectMatrixPrimitiveType<ICellData>
- ): void {
+ ): Promise<boolean> {
const realValue = covertCellValues(value, this._range);
- this._commandService.executeCommand(SetRangeValuesCommand.id, {
+ return this._commandService.executeCommand(SetRangeValuesCommand.id, {
unitId: this._workbook.getUnitId(),
subUnitId: this._worksheet.getSheetId(),
range: this._range,
@@ -133,4 +225,20 @@ export class FRange {
this._commandService.executeCommand(SetStyleCommand.id, setStyleParams);
}
+
+ // #endregion editing
+
+ /**
+ * Iterate cells in this range. Merged cells will be respected.
+ * @param callback
+ */
+ forEach(callback: (row: number, col: number, cell: ICellData) => void): void {
+ // Iterate each cell in this range.
+ const { startColumn, startRow, endColumn, endRow } = this._range;
+ this._worksheet
+ .getMatrixWithMergedCells(startRow, startColumn, endRow, endColumn)
+ .forValue((row, col, value) => {
+ callback(row, col, value);
+ });
+ }
}
diff --git a/packages/facade/src/apis/sheet/f-workbook.ts b/packages/facade/src/apis/sheet/f-workbook.ts
index bdc7bb5f0a..baff0a2d68 100644
--- a/packages/facade/src/apis/sheet/f-workbook.ts
+++ b/packages/facade/src/apis/sheet/f-workbook.ts
@@ -14,19 +14,51 @@
* limitations under the License.
*/
-import { DEFAULT_WORKSHEET, ICommandService, Tools, type Workbook } from '@univerjs/core';
-import type { IInsertSheetCommandParams, ISetWorksheetActivateCommandParams } from '@univerjs/sheets';
-import { InsertSheetCommand, SetWorksheetActivateCommand } from '@univerjs/sheets';
+import type { CommandListener, ICommandInfo, IRange, IWorkbookData, Workbook } from '@univerjs/core';
+import {
+ DEFAULT_WORKSHEET,
+ ICommandService,
+ IUniverInstanceService,
+ RedoCommand,
+ toDisposable,
+ Tools,
+ UndoCommand,
+} from '@univerjs/core';
+import type {
+ IInsertSheetCommandParams,
+ ISetWorksheetActivateCommandParams,
+ ISheetCommandSharedParams,
+} from '@univerjs/sheets';
+import { InsertSheetCommand, SelectionManagerService, SetWorksheetActivateCommand } from '@univerjs/sheets';
+import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { FWorksheet } from './f-worksheet';
export class FWorkbook {
+ readonly id: string;
+
constructor(
private readonly _workbook: Workbook,
@Inject(Injector) private readonly _injector: Injector,
+ @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@ICommandService private readonly _commandService: ICommandService
- ) {}
+ ) {
+ this.id = this._workbook.getUnitId();
+ }
+
+ getId(): string {
+ return this._workbook.getUnitId();
+ }
+
+ getName(): string {
+ return this._workbook.getName();
+ }
+
+ getSnapshot(): IWorkbookData {
+ return this._workbook.getSnapshot();
+ }
/**
* Get the active sheet of the workbook.
@@ -67,4 +99,54 @@ export class FWorkbook {
return this._injector.createInstance(FWorksheet, this._workbook, this._workbook.getActiveSheet());
}
+
+ // #region editing
+
+ undo(): Promise<boolean> {
+ this._univerInstanceService.focusUniverInstance(this.id);
+ return this._commandService.executeCommand(UndoCommand.id);
+ }
+
+ redo(): Promise<boolean> {
+ this._univerInstanceService.focusUniverInstance(this.id);
+ return this._commandService.executeCommand(RedoCommand.id);
+ }
+
+ // #endregion
+
+ // #region callbacks
+
+ /**
+ * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
+ * @param callback the callback.
+ * @returns A function to dispose the listening.
+ */
+ onCommandExecuted(callback: CommandListener): IDisposable {
+ return this._commandService.onCommandExecuted((command) => {
+ if ((command as ICommandInfo<ISheetCommandSharedParams>).params?.unitId !== this.id) {
+ return;
+ }
+
+ callback(command);
+ });
+ }
+
+ onSelectionChange(callback: (selections: IRange[]) => void): IDisposable {
+ return toDisposable(
+ this._selectionManagerService.selectionMoveEnd$.subscribe((selections) => {
+ if (this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId() !== this.id) {
+ return;
+ }
+
+ if (!selections?.length) {
+ callback([]);
+ }
+
+ // TODO@wzhudev: filtered out ranges changes not other currently sheet
+ callback(selections!.map((s) => s.range));
+ })
+ );
+ }
+
+ // #region callbacks
}
diff --git a/packages/facade/src/apis/sheet/utils.ts b/packages/facade/src/apis/sheet/utils.ts
index b667065e8c..aeb20f5232 100644
--- a/packages/facade/src/apis/sheet/utils.ts
+++ b/packages/facade/src/apis/sheet/utils.ts
@@ -15,7 +15,70 @@
*/
import type { ICellData, ICellV, IObjectMatrixPrimitiveType, IRange, Nullable } from '@univerjs/core';
-import { isCellV, isFormulaString, isICellData, ObjectMatrix, Tools } from '@univerjs/core';
+import {
+ HorizontalAlign,
+ isCellV,
+ isFormulaString,
+ isICellData,
+ ObjectMatrix,
+ Tools,
+ VerticalAlign,
+} from '@univerjs/core';
+
+export type FHorizontalAlignment = 'left' | 'center' | 'normal';
+export type FVerticalAlignment = 'top' | 'middle' | 'bottom';
+
+export function transformFacadeHorizontalAlignment(value: FHorizontalAlignment): HorizontalAlign {
+ switch (value) {
+ case 'left':
+ return HorizontalAlign.LEFT;
+ case 'center':
+ return HorizontalAlign.CENTER;
+ case 'normal':
+ return HorizontalAlign.RIGHT;
+ default:
+ throw new Error(`Invalid horizontal alignment: ${value}`);
+ }
+}
+
+export function transformCoreHorizontalAlignment(value: HorizontalAlign): FHorizontalAlignment {
+ switch (value) {
+ case HorizontalAlign.LEFT:
+ return 'left';
+ case HorizontalAlign.CENTER:
+ return 'center';
+ case HorizontalAlign.RIGHT:
+ return 'normal';
+ default:
+ throw new Error(`Invalid horizontal alignment: ${value}`);
+ }
+}
+
+export function transformFacadeVerticalAlignment(value: FVerticalAlignment): VerticalAlign {
+ switch (value) {
+ case 'top':
+ return VerticalAlign.TOP;
+ case 'middle':
+ return VerticalAlign.MIDDLE;
+ case 'bottom':
+ return VerticalAlign.BOTTOM;
+ default:
+ throw new Error(`Invalid vertical alignment: ${value}`);
+ }
+}
+
+export function transformCoreVerticalAlignment(value: VerticalAlign): FVerticalAlignment {
+ switch (value) {
+ case VerticalAlign.TOP:
+ return 'top';
+ case VerticalAlign.MIDDLE:
+ return 'middle';
+ case VerticalAlign.BOTTOM:
+ return 'bottom';
+ default:
+ throw new Error(`Invalid vertical alignment: ${value}`);
+ }
+}
/**
* covert cell value to cell data
diff --git a/packages/find-replace/README.md b/packages/find-replace/README.md
new file mode 100644
index 0000000000..c8e3233b48
--- /dev/null
+++ b/packages/find-replace/README.md
@@ -0,0 +1,16 @@
+# @univerjs/find-replace
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/find-replace)](https://npmjs.org/packages/@univerjs/find-replace)
+[![license](https://img.shields.io/npm/l/@univerjs/find-replace)](https://img.shields.io/npm/l/@univerjs/find-replace)
+
+## Introduction
+
+> TODO: Introduction
+
+## Usage
+
+### Installation
+
+```shell
+npm i @univerjs/find-replace
+```
diff --git a/packages/find-replace/docs/README.md b/packages/find-replace/docs/README.md
new file mode 100644
index 0000000000..eb03becd14
--- /dev/null
+++ b/packages/find-replace/docs/README.md
@@ -0,0 +1,25 @@
+# Design Spec of Search & Replace
+
+Author: [@wzhudev](https://github/wzhudev)
+
+---
+
+## Introduction
+
+## Architecture
+
+由 find-replace 包提供查找替换的调度服务、接口以及 UI,业务包提供具体的查找替换方法
+
+* 输入查找内容
+* 确定搜索范围,当前 focused 的业务,或者全部的业务
+* 切换查找模式
+* 接收各个业务提供的查找结果(可能需要支持动态查找)
+* 定位查找项的位置
+* 结束查找
+* 执行替换或者全部替换
+
+各个包要做的事情
+
+* 根据查找字符串的变化来搜索并把结果塞给 find-replace
+* 查找高亮,定位到查找位置
+* 执行替换
\ No newline at end of file
diff --git a/packages/find-replace/docs/arch.excalidraw b/packages/find-replace/docs/arch.excalidraw
new file mode 100644
index 0000000000..6ede9d5a7c
--- /dev/null
+++ b/packages/find-replace/docs/arch.excalidraw
@@ -0,0 +1,41 @@
+{
+ "type": "excalidraw",
+ "version": 2,
+ "source": "https://marketplace.visualstudio.com/items?itemName=pomdtr.excalidraw-editor",
+ "elements": [
+ {
+ "id": "3k5lrIK0dFvyvu1cHvnQ4",
+ "type": "rectangle",
+ "x": 346,
+ "y": 347.5,
+ "width": 264,
+ "height": 73.5,
+ "angle": 0,
+ "strokeColor": "#1e1e1e",
+ "backgroundColor": "transparent",
+ "fillStyle": "solid",
+ "strokeWidth": 2,
+ "strokeStyle": "solid",
+ "roughness": 1,
+ "opacity": 100,
+ "groupIds": [],
+ "frameId": null,
+ "roundness": {
+ "type": 3
+ },
+ "seed": 1817001344,
+ "version": 49,
+ "versionNonce": 730611072,
+ "isDeleted": false,
+ "boundElements": null,
+ "updated": 1704457441440,
+ "link": null,
+ "locked": false
+ }
+ ],
+ "appState": {
+ "gridSize": null,
+ "viewBackgroundColor": "#ffffff"
+ },
+ "files": {}
+}
\ No newline at end of file
diff --git a/packages/find-replace/package.json b/packages/find-replace/package.json
new file mode 100644
index 0000000000..c9624021e0
--- /dev/null
+++ b/packages/find-replace/package.json
@@ -0,0 +1,65 @@
+{
+ "name": "@univerjs/find-replace",
+ "version": "0.1.0-beta.1",
+ "description": "",
+ "keywords": [],
+ "author": "DreamNum <[email protected]>",
+ "license": "Apache-2.0",
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/esm/index.js",
+ "types": "./lib/types/index.d.ts",
+ "publishConfig": {
+ "access": "public",
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "exports": {
+ ".": {
+ "import": "./lib/es/index.js",
+ "require": "./lib/cjs/index.js",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./*": {
+ "import": "./lib/es/*",
+ "require": "./lib/cjs/*",
+ "types": "./lib/types/index.d.ts"
+ }
+ }
+ },
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*"
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "private": false,
+ "scripts": {
+ "test": "vitest run",
+ "test:watch": "vitest",
+ "coverage": "vitest run --coverage",
+ "build": "tsc && vite build"
+ },
+ "dependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/ui": "workspace:*",
+ "@wendellhu/redi": "^0.12.13",
+ "rxjs": "^7.8.1"
+ },
+ "devDependencies": {
+ "@vitest/coverage-istanbul": "^1.1.1",
+ "typescript": "^5.3.3",
+ "vite": "^5.0.10",
+ "vite-plugin-dts": "^3.7.0",
+ "vite-plugin-externals": "^0.6.2",
+ "vitest": "^1.1.1"
+ },
+ "peerDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/ui": "workspace:*",
+ "@wendellhu/redi": ">=0.12.13",
+ "rxjs": ">=7.0.0"
+ }
+}
diff --git a/packages/find-replace/src/commands/operations/find-replace.operation.ts b/packages/find-replace/src/commands/operations/find-replace.operation.ts
new file mode 100644
index 0000000000..f36aa7dfb5
--- /dev/null
+++ b/packages/find-replace/src/commands/operations/find-replace.operation.ts
@@ -0,0 +1,28 @@
+/**
+ * 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 { IOperation } from '@univerjs/core';
+import { CommandType } from '@univerjs/core';
+
+export const ToggleFindReplaceDialogOperation: IOperation = {
+ type: CommandType.OPERATION,
+ id: 'ui.operation.toggle-find-replace-dialog',
+ handler: (accessor) => {
+ const a = 1;
+ // Toggle dialog
+ return true;
+ },
+};
diff --git a/packages/find-replace/src/controllers/find-replace.controller.ts b/packages/find-replace/src/controllers/find-replace.controller.ts
new file mode 100644
index 0000000000..aca3319c83
--- /dev/null
+++ b/packages/find-replace/src/controllers/find-replace.controller.ts
@@ -0,0 +1,35 @@
+/**
+ * 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 { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
+import { IMenuService } from '@univerjs/ui';
+import { Inject, Injector } from '@wendellhu/redi';
+
+import { FindReplaceMenuItemFactory } from './find-replace.menu';
+
+@OnLifecycle(LifecycleStages.Steady, FindReplaceController)
+export class FindReplaceController extends Disposable {
+ constructor(
+ @IMenuService private readonly _menuService: IMenuService,
+ @Inject(Injector) private readonly _injector: Injector
+ ) {
+ super();
+
+ [FindReplaceMenuItemFactory].forEach((f) => {
+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(f)));
+ });
+ }
+}
diff --git a/packages/find-replace/src/controllers/find-replace.menu.ts b/packages/find-replace/src/controllers/find-replace.menu.ts
new file mode 100644
index 0000000000..1808f76853
--- /dev/null
+++ b/packages/find-replace/src/controllers/find-replace.menu.ts
@@ -0,0 +1,31 @@
+/**
+ * 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 { IMenuButtonItem } from '@univerjs/ui';
+import { MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
+import type { IAccessor } from '@wendellhu/redi';
+
+import { ToggleFindReplaceDialogOperation } from '../commands/operations/find-replace.operation';
+
+export function FindReplaceMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ return {
+ id: ToggleFindReplaceDialogOperation.id,
+ tooltip: 'toolbar.find-replace',
+ group: MenuGroup.TOOLBAR_OTHERS,
+ type: MenuItemType.BUTTON,
+ positions: [MenuPosition.TOOLBAR_START],
+ };
+}
diff --git a/packages/find-replace/src/index.ts b/packages/find-replace/src/index.ts
new file mode 100644
index 0000000000..e16857f05b
--- /dev/null
+++ b/packages/find-replace/src/index.ts
@@ -0,0 +1,17 @@
+/**
+ * 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.
+ */
+
+export { UniverFindReplacePlugin } from './plugin';
diff --git a/packages/find-replace/src/plugin.ts b/packages/find-replace/src/plugin.ts
new file mode 100644
index 0000000000..5fbcfcd5b6
--- /dev/null
+++ b/packages/find-replace/src/plugin.ts
@@ -0,0 +1,34 @@
+/**
+ * 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 { Plugin } from '@univerjs/core';
+import type { Dependency, Injector } from '@wendellhu/redi';
+
+import { FindReplaceController } from './controllers/find-replace.controller';
+
+const PLUGIN_NAME = 'FIND_REPLACE';
+
+export class UniverFindReplacePlugin extends Plugin {
+ constructor(protected readonly _injector: Injector) {
+ super(PLUGIN_NAME);
+ }
+
+ override onStarting(injector: Injector): void {
+ ([[FindReplaceController]] as Dependency[]).forEach((d) => {
+ injector.add(d);
+ });
+ }
+}
diff --git a/packages/find-replace/src/services/find-replace.service.ts b/packages/find-replace/src/services/find-replace.service.ts
new file mode 100644
index 0000000000..3c99b2a076
--- /dev/null
+++ b/packages/find-replace/src/services/find-replace.service.ts
@@ -0,0 +1,26 @@
+/**
+ * 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 { createIdentifier } from '@wendellhu/redi';
+
+export const IFindReplaceService = createIdentifier<IFindReplaceService>('univer.find-replace-service');
+
+/**
+ *
+ */
+export interface IFindReplaceService {}
+
+export interface IFindReplaceHookd {}
diff --git a/packages/find-replace/src/vite-env.d.ts b/packages/find-replace/src/vite-env.d.ts
new file mode 100644
index 0000000000..11f02fe2a0
--- /dev/null
+++ b/packages/find-replace/src/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
diff --git a/packages/find-replace/tsconfig.json b/packages/find-replace/tsconfig.json
new file mode 100644
index 0000000000..ccde33f16e
--- /dev/null
+++ b/packages/find-replace/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "rootDir": ".",
+ "outDir": "lib",
+ "esModuleInterop": true,
+ "strictPropertyInitialization": false
+ },
+ "include": ["src/**/*"]
+}
diff --git a/packages/find-replace/vite.config.ts b/packages/find-replace/vite.config.ts
new file mode 100644
index 0000000000..10fa72578c
--- /dev/null
+++ b/packages/find-replace/vite.config.ts
@@ -0,0 +1,47 @@
+import { resolve } from 'path';
+import { defineConfig } from 'vitest/config';
+import dts from 'vite-plugin-dts';
+
+import { name } from './package.json';
+
+const libName = name
+ .replace('@univerjs/', 'univer-')
+ .split('-')
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
+ .join('');
+
+export default defineConfig(({ mode }) => ({
+ plugins: [
+ dts({
+ entryRoot: 'src',
+ outDir: 'lib/types',
+ }),
+ ],
+ define: {
+ 'process.env.NODE_ENV': JSON.stringify(mode),
+ },
+ build: {
+ outDir: 'lib',
+ lib: {
+ entry: resolve(__dirname, 'src/index.ts'),
+ name: libName,
+ fileName: (format) => `${format}/index.js`,
+ formats: ['es', 'umd', 'cjs'],
+ },
+ rollupOptions: {
+ external: ['@univerjs/core', '@wendellhu/redi', 'rxjs'],
+ output: {
+ globals: {
+ '@univerjs/core': 'UniverCore',
+ '@wendellhu/redi': '@wendellhu/redi',
+ rxjs: 'rxjs',
+ },
+ },
+ },
+ },
+ test: {
+ coverage: {
+ provider: 'istanbul',
+ },
+ },
+}));
diff --git a/packages/sheets-formula/src/index.ts b/packages/sheets-formula/src/index.ts
index a54bb44e6f..839dc85dfa 100644
--- a/packages/sheets-formula/src/index.ts
+++ b/packages/sheets-formula/src/index.ts
@@ -23,5 +23,5 @@ export {
IFormulaCustomFunctionService,
} from './services/formula-custom-function.service';
export type { IRegisterFunctionParams, IUnregisterFunctionParams } from './services/register-function.service';
-export { IRegisterFunctionService } from './services/register-function.service';
export { RegisterFunctionService } from './services/register-function.service';
+export { IRegisterFunctionService } from './services/register-function.service';
diff --git a/packages/sheets-numfmt/src/commands/commands/add.decimal.command.ts b/packages/sheets-numfmt/src/commands/commands/add-decimal.command.ts
similarity index 96%
rename from packages/sheets-numfmt/src/commands/commands/add.decimal.command.ts
rename to packages/sheets-numfmt/src/commands/commands/add-decimal.command.ts
index 4980e0d4f0..0a2afbb6fd 100644
--- a/packages/sheets-numfmt/src/commands/commands/add.decimal.command.ts
+++ b/packages/sheets-numfmt/src/commands/commands/add-decimal.command.ts
@@ -20,8 +20,8 @@ import { INumfmtService, SelectionManagerService } from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
import { getDecimalFromPattern, isPatternEqualWithoutDecimal, setPatternDecimal } from '../../utils/decimal';
-import type { ISetNumfmtCommandParams } from './set.numfmt.command';
-import { SetNumfmtCommand } from './set.numfmt.command';
+import type { ISetNumfmtCommandParams } from './set-numfmt.command';
+import { SetNumfmtCommand } from './set-numfmt.command';
export const AddDecimalCommand: ICommand = {
id: 'sheet.command.numfmt.add.decimal.command',
diff --git a/packages/sheets-numfmt/src/commands/commands/set.currency.command.ts b/packages/sheets-numfmt/src/commands/commands/set-currency.command.ts
similarity index 93%
rename from packages/sheets-numfmt/src/commands/commands/set.currency.command.ts
rename to packages/sheets-numfmt/src/commands/commands/set-currency.command.ts
index 35f00deea5..37c22cbbb2 100644
--- a/packages/sheets-numfmt/src/commands/commands/set.currency.command.ts
+++ b/packages/sheets-numfmt/src/commands/commands/set-currency.command.ts
@@ -20,8 +20,8 @@ import { SelectionManagerService } from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
import { CURRENCYFORMAT } from '../../base/const/FORMATDETAIL';
-import type { ISetNumfmtCommandParams } from './set.numfmt.command';
-import { SetNumfmtCommand } from './set.numfmt.command';
+import type { ISetNumfmtCommandParams } from './set-numfmt.command';
+import { SetNumfmtCommand } from './set-numfmt.command';
export const SetCurrencyCommand: ICommand = {
id: 'sheet.command.numfmt.set.currency',
diff --git a/packages/sheets-numfmt/src/commands/commands/set.numfmt.command.ts b/packages/sheets-numfmt/src/commands/commands/set-numfmt.command.ts
similarity index 98%
rename from packages/sheets-numfmt/src/commands/commands/set.numfmt.command.ts
rename to packages/sheets-numfmt/src/commands/commands/set-numfmt.command.ts
index 1cb9a5b5c4..1281720191 100644
--- a/packages/sheets-numfmt/src/commands/commands/set.numfmt.command.ts
+++ b/packages/sheets-numfmt/src/commands/commands/set-numfmt.command.ts
@@ -39,6 +39,8 @@ import {
import type { IAccessor } from '@wendellhu/redi';
export interface ISetNumfmtCommandParams {
+ unitId?: string;
+ subUnitId?: string;
values: Array<{ pattern?: string; row: number; col: number; type?: FormatType }>;
}
@@ -49,6 +51,7 @@ export const SetNumfmtCommand: ICommand<ISetNumfmtCommandParams> = {
if (!params) {
return false;
}
+
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const undoRedoService = accessor.get(IUndoRedoService);
diff --git a/packages/sheets-numfmt/src/commands/commands/subtract.decimal.command.ts b/packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.ts
similarity index 96%
rename from packages/sheets-numfmt/src/commands/commands/subtract.decimal.command.ts
rename to packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.ts
index 9f153ac874..ea1b00a9d7 100644
--- a/packages/sheets-numfmt/src/commands/commands/subtract.decimal.command.ts
+++ b/packages/sheets-numfmt/src/commands/commands/subtract-decimal.command.ts
@@ -20,8 +20,8 @@ import { INumfmtService, SelectionManagerService } from '@univerjs/sheets';
import type { IAccessor } from '@wendellhu/redi';
import { getDecimalFromPattern, isPatternEqualWithoutDecimal, setPatternDecimal } from '../../utils/decimal';
-import type { ISetNumfmtCommandParams } from './set.numfmt.command';
-import { SetNumfmtCommand } from './set.numfmt.command';
+import type { ISetNumfmtCommandParams } from './set-numfmt.command';
+import { SetNumfmtCommand } from './set-numfmt.command';
export const SubtractDecimalCommand: ICommand = {
id: 'sheet.command.numfmt.subtract.decimal.command',
diff --git a/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx b/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx
index 6a8e71b748..9f9f00d272 100644
--- a/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx
+++ b/packages/sheets-numfmt/src/components/more-numfmt-type/MoreNumfmtType.tsx
@@ -25,7 +25,7 @@ import { useDependency, useInjector } from '@wendellhu/redi/react-bindings';
import React from 'react';
import { MENU_OPTIONS } from '../../base/const/MENU-OPTIONS';
-import { SetNumfmtCommand } from '../../commands/commands/set.numfmt.command';
+import { SetNumfmtCommand } from '../../commands/commands/set-numfmt.command';
import { OpenNumfmtPanelOperator } from '../../commands/operations/open.numfmt.panel.operation';
import { getPatternType } from '../../utils/pattern';
diff --git a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
index b50efdff5b..811747129b 100644
--- a/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
+++ b/packages/sheets-numfmt/src/controllers/numfmt.controller.ts
@@ -50,11 +50,11 @@ import { combineLatest, merge, Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators';
import { SHEET_NUMFMT_PLUGIN } from '../base/const/PLUGIN_NAME';
-import { AddDecimalCommand } from '../commands/commands/add.decimal.command';
-import { SetCurrencyCommand } from '../commands/commands/set.currency.command';
-import type { ISetNumfmtCommandParams } from '../commands/commands/set.numfmt.command';
-import { SetNumfmtCommand } from '../commands/commands/set.numfmt.command';
-import { SubtractDecimalCommand } from '../commands/commands/subtract.decimal.command';
+import { AddDecimalCommand } from '../commands/commands/add-decimal.command';
+import { SetCurrencyCommand } from '../commands/commands/set-currency.command';
+import type { ISetNumfmtCommandParams } from '../commands/commands/set-numfmt.command';
+import { SetNumfmtCommand } from '../commands/commands/set-numfmt.command';
+import { SubtractDecimalCommand } from '../commands/commands/subtract-decimal.command';
import { CloseNumfmtPanelOperator } from '../commands/operations/close.numfmt.panel.operation';
import { OpenNumfmtPanelOperator } from '../commands/operations/open.numfmt.panel.operation';
import type { ISheetNumfmtPanelProps } from '../components/index';
diff --git a/packages/sheets-numfmt/src/index.ts b/packages/sheets-numfmt/src/index.ts
index 104d516ca5..e252b9ead6 100644
--- a/packages/sheets-numfmt/src/index.ts
+++ b/packages/sheets-numfmt/src/index.ts
@@ -14,5 +14,6 @@
* limitations under the License.
*/
+export { type ISetNumfmtCommandParams, SetNumfmtCommand } from './commands/commands/set-numfmt.command';
export { enUS, zhCN } from './locale';
-export * from './numfmt-plugin';
+export { UniverSheetsNumfmtPlugin } from './numfmt-plugin';
diff --git a/packages/sheets-numfmt/src/menu/menu.ts b/packages/sheets-numfmt/src/menu/menu.ts
index 9166202b7f..948f2ea5a2 100644
--- a/packages/sheets-numfmt/src/menu/menu.ts
+++ b/packages/sheets-numfmt/src/menu/menu.ts
@@ -29,9 +29,9 @@ import type { IAccessor } from '@wendellhu/redi';
import { merge, Observable } from 'rxjs';
import { MENU_OPTIONS } from '../base/const/MENU-OPTIONS';
-import { AddDecimalCommand } from '../commands/commands/add.decimal.command';
-import { SetCurrencyCommand } from '../commands/commands/set.currency.command';
-import { SubtractDecimalCommand } from '../commands/commands/subtract.decimal.command';
+import { AddDecimalCommand } from '../commands/commands/add-decimal.command';
+import { SetCurrencyCommand } from '../commands/commands/set-currency.command';
+import { SubtractDecimalCommand } from '../commands/commands/subtract-decimal.command';
import { OpenNumfmtPanelOperator } from '../commands/operations/open.numfmt.panel.operation';
import { MoreNumfmtType, Options } from '../components/more-numfmt-type/MoreNumfmtType';
import { isPatternEqualWithoutDecimal } from '../utils/decimal';
diff --git a/packages/sheets/src/commands/commands/set-border-command.ts b/packages/sheets/src/commands/commands/set-border-command.ts
index 7575d095d8..16bcc92b29 100644
--- a/packages/sheets/src/commands/commands/set-border-command.ts
+++ b/packages/sheets/src/commands/commands/set-border-command.ts
@@ -39,6 +39,7 @@ import { BorderStyleManagerService, type IBorderInfo } from '../../services/bord
import { SelectionManagerService } from '../../services/selection-manager.service';
import type { ISetRangeValuesMutationParams } from '../mutations/set-range-values.mutation';
import { SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../mutations/set-range-values.mutation';
+import { getCommandTarget } from '../utils/get-target';
function forEach(range: IRange, action: (row: number, column: number) => void): void {
const { startRow, startColumn, endRow, endColumn } = range;
@@ -49,14 +50,18 @@ function forEach(range: IRange, action: (row: number, column: number) => void):
}
}
-export interface ISetBorderBasicCommand {
+export interface ISetBorderBasicCommandParams {
+ unitId?: string;
+ subUnitId?: string;
+
value: IBorderInfo;
}
-export const SetBorderBasicCommand: ICommand<ISetBorderBasicCommand> = {
+export const SetBorderBasicCommand: ICommand<ISetBorderBasicCommandParams> = {
id: 'sheet.command.set-border-basic',
type: CommandType.COMMAND,
- handler: async (accessor: IAccessor, params: ISetBorderBasicCommand) => {
- const { type, color, style } = params.value;
+ handler: async (accessor: IAccessor, params: ISetBorderBasicCommandParams) => {
+ const { unitId, subUnitId, value } = params;
+ const { type, color, style } = value;
const commandService = accessor.get(ICommandService);
const borderManager = accessor.get(BorderStyleManagerService);
@@ -65,7 +70,10 @@ export const SetBorderBasicCommand: ICommand<ISetBorderBasicCommand> = {
borderManager.setColor(color);
borderManager.setStyle(style);
- return commandService.executeCommand(SetBorderCommand.id);
+ return commandService.executeCommand(SetBorderCommand.id, {
+ unitId,
+ subUnitId,
+ });
},
};
@@ -115,6 +123,11 @@ export const SetBorderColorCommand: ICommand<ISetBorderColorCommandParams> = {
},
};
+export interface ISetBorderCommandParams {
+ unitId?: string;
+ subUnitId?: string;
+}
+
/**
* The command to clear content in current selected ranges.
*/
@@ -122,18 +135,19 @@ export const SetBorderCommand: ICommand = {
id: 'sheet.command.set-border',
type: CommandType.COMMAND,
// eslint-disable-next-line max-lines-per-function
- handler: async (accessor: IAccessor) => {
+ handler: async (accessor: IAccessor, params?: ISetBorderCommandParams) => {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const selectionManagerService = accessor.get(SelectionManagerService);
const borderStyleManagerService = accessor.get(BorderStyleManagerService);
+ const { worksheet, unitId, subUnitId } = getCommandTarget(
+ univerInstanceService,
+ params?.unitId,
+ params?.subUnitId
+ );
const selections = selectionManagerService.getSelectionRanges();
- const workbook = univerInstanceService.getCurrentUniverSheetInstance();
- const unitId = workbook.getUnitId();
- const worksheet = workbook.getActiveSheet();
- const subUnitId = worksheet.getSheetId();
const mergeData = worksheet.getConfig().mergeData;
if (!selections?.length) {
return false;
diff --git a/packages/sheets/src/commands/commands/set-style.command.ts b/packages/sheets/src/commands/commands/set-style.command.ts
index a7ba3ada7b..c2e20a06ae 100644
--- a/packages/sheets/src/commands/commands/set-style.command.ts
+++ b/packages/sheets/src/commands/commands/set-style.command.ts
@@ -49,10 +49,13 @@ export interface IStyleTypeValue<T> {
value: T | T[][];
}
-export interface ISetStyleCommandParams<T> {
+interface ISetStyleCommonParams {
subUnitId?: string;
unitId?: string;
range?: IRange;
+}
+
+export interface ISetStyleCommandParams<T> extends ISetStyleCommonParams {
style: IStyleTypeValue<T>;
}
@@ -511,7 +514,7 @@ export const SetHorizontalTextAlignCommand: ICommand<ISetHorizontalTextAlignComm
},
};
-export interface ISetTextWrapCommandParams {
+export interface ISetTextWrapCommandParams extends ISetStyleCommonParams {
value: WrapStrategy;
}
diff --git a/packages/sheets/src/commands/utils/get-target.ts b/packages/sheets/src/commands/utils/get-target.ts
new file mode 100644
index 0000000000..bc89cd5965
--- /dev/null
+++ b/packages/sheets/src/commands/utils/get-target.ts
@@ -0,0 +1,57 @@
+/**
+ * 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 { IUniverInstanceService, Workbook, Worksheet } from '@univerjs/core';
+
+/**
+ * Get target workbook and worksheet.
+ * @param univerInstanceService
+ * @param unitId
+ * @param subUnitId
+ *
+ * @internal
+ *
+ * @returns
+ */
+export function getCommandTarget(
+ univerInstanceService: IUniverInstanceService,
+ unitId?: string,
+ subUnitId?: string
+): {
+ workbook: Workbook;
+ worksheet: Worksheet;
+ unitId: string;
+ subUnitId: string;
+} {
+ const workbook = unitId
+ ? univerInstanceService.getUniverSheetInstance(unitId)
+ : univerInstanceService.getCurrentUniverSheetInstance();
+ if (!workbook) {
+ throw new Error();
+ }
+
+ const worksheet = subUnitId ? workbook.getSheetBySheetId(subUnitId) : workbook.getActiveSheet();
+ if (!worksheet) {
+ throw new Error();
+ }
+
+ return {
+ workbook,
+ worksheet,
+ unitId: unitId ?? workbook.getUnitId(),
+ subUnitId: subUnitId ?? worksheet.getSheetId(),
+ };
+}
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index d2e072dc36..c912bf1d13 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -91,7 +91,9 @@ export type { IRemoveSheetCommandParams } from './commands/commands/remove-sheet
export { RemoveSheetCommand } from './commands/commands/remove-sheet.command';
export { RemoveWorksheetMergeCommand } from './commands/commands/remove-worksheet-merge.command';
export type {
+ ISetBorderBasicCommandParams,
ISetBorderColorCommandParams,
+ ISetBorderCommandParams,
ISetBorderPositionCommandParams,
ISetBorderStyleCommandParams,
} from './commands/commands/set-border-command';
@@ -117,7 +119,14 @@ export {
SetSpecificRowsVisibleCommand,
} from './commands/commands/set-row-visible.command';
export {
+ type ISetColorCommandParams,
+ type ISetFontFamilyCommandParams,
+ type ISetFontSizeCommandParams,
+ type ISetHorizontalTextAlignCommandParams,
type ISetStyleCommandParams,
+ type ISetTextRotationCommandParams,
+ type ISetTextWrapCommandParams,
+ type ISetVerticalTextAlignCommandParams,
type IStyleTypeValue,
ResetBackgroundColorCommand,
ResetTextColorCommand,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d0f7e35c92..4be0a8b13b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -155,6 +155,9 @@ importers:
'@univerjs/engine-render':
specifier: workspace:*
version: link:../packages/engine-render
+ '@univerjs/find-replace':
+ specifier: workspace:*
+ version: link:../packages/find-replace
'@univerjs/icons':
specifier: ^0.1.24
@@ -592,6 +595,9 @@ importers:
'@univerjs/sheets-formula':
specifier: workspace:*
version: link:../sheets-formula
+ '@univerjs/sheets-numfmt':
+ specifier: workspace:*
+ version: link:../sheets-numfmt
'@wendellhu/redi':
specifier: ^0.12.13
version: 0.12.13
@@ -621,6 +627,40 @@ importers:
specifier: ^1.1.1
version: 1.1.1(@types/[email protected])([email protected])
+ packages/find-replace:
+ dependencies:
+ '@univerjs/core':
+ specifier: workspace:*
+ version: link:../core
+ '@univerjs/ui':
+ specifier: workspace:*
+ version: link:../ui
+ '@wendellhu/redi':
+ specifier: ^0.12.13
+ version: 0.12.13
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
+ devDependencies:
+ '@vitest/coverage-istanbul':
+ specifier: ^1.1.1
+ version: 1.1.1([email protected])
+ typescript:
+ specifier: ^5.3.3
+ version: 5.3.3
+ vite:
+ specifier: ^5.0.10
+ version: 5.0.10(@types/[email protected])([email protected])
+ vite-plugin-dts:
+ specifier: ^3.7.0
+ vite-plugin-externals:
+ specifier: ^0.6.2
+ version: 0.6.2([email protected])
+ vitest:
+ specifier: ^1.1.1
+ version: 1.1.1(@types/[email protected])([email protected])
+
packages/image:
dependencies:
'@univerjs/core':
diff --git a/tsconfig.json b/tsconfig.json
index 1bd5a649b3..6b7b87cc5e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -3,12 +3,7 @@
"rootDir": ".",
"outDir": "lib",
"forceConsistentCasingInFileNames": true,
- "lib": [
- "ESNext",
- "DOM",
- "WebWorker",
- "dom.iterable"
- ],
+ "lib": ["ESNext", "DOM", "WebWorker", "dom.iterable"],
"target": "ESNext",
"module": "ESNext",
"experimentalDecorators": true,
@@ -26,9 +21,7 @@
"checkJs": false,
"skipLibCheck": true,
"isolatedModules": true,
- "types": [
- "node"
- ]
+ "types": ["node"]
},
"include": [],
"references": [
@@ -56,6 +49,9 @@
{
"path": "./packages/facade"
},
+ {
+ "path": "./packages/find-replace"
+ },
{
"path": "./packages/image"
},