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.

fix(sheet): sheet bar menu style (#917)

Dushusir2fa1683febe6
diff --git a/examples/src/data/sheets/demo/default-workbook-data-demo.ts b/examples/src/data/sheets/demo/default-workbook-data-demo.ts
index 403d2d0791..41c4239b14 100644
--- a/examples/src/data/sheets/demo/default-workbook-data-demo.ts
+++ b/examples/src/data/sheets/demo/default-workbook-data-demo.ts
@@ -23187,7 +23187,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
w: 60,
},
},
- status: 0,
+ status: 1,
showGridlines: 1,
hideRow: [],
hideColumn: [],
diff --git a/packages/core/src/sheets/__tests__/create-core-test-bed.ts b/packages/core/src/sheets/__tests__/create-core-test-bed.ts
index 094de208dc..b8476984fc 100644
--- a/packages/core/src/sheets/__tests__/create-core-test-bed.ts
+++ b/packages/core/src/sheets/__tests__/create-core-test-bed.ts
@@ -40,6 +40,7 @@ const TEST_WORKBOOK_DATA: IWorkbookData = {
},
},
},
+ name: 'Sheet-001',
},
},
locale: LocaleType.ZH_CN,
diff --git a/packages/core/src/sheets/__tests__/workbook.spec.ts b/packages/core/src/sheets/__tests__/workbook.spec.ts
new file mode 100644
index 0000000000..ddb1bae54f
--- /dev/null
+++ b/packages/core/src/sheets/__tests__/workbook.spec.ts
@@ -0,0 +1,62 @@
+/**
+ * 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 { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import type { Univer } from '../../basics/univer';
+import type { Workbook } from '../workbook';
+import { createCoreTestBed } from './create-core-test-bed';
+
+describe('Test workbook', () => {
+ let univer: Univer;
+ let workbook: Workbook;
+
+ beforeEach(() => {
+ const testBed = createCoreTestBed();
+ univer = testBed.univer;
+ workbook = testBed.sheet;
+ });
+
+ afterEach(() => univer.dispose());
+
+ describe('Test workbook function', () => {
+ it('function uniqueSheetName', () => {
+ const newSheetName = workbook.uniqueSheetName('Sheet-002');
+ expect(newSheetName).toBe('Sheet-002');
+
+ workbook.addWorksheet('sheet2', 1, {
+ id: 'sheet2',
+ name: newSheetName,
+ });
+
+ const newSheetName2 = workbook.uniqueSheetName('Sheet-002');
+ expect(newSheetName2).toBe('Sheet-0021');
+ });
+
+ it('function generateNewSheetName', () => {
+ const newSheetName = workbook.generateNewSheetName('Sheet');
+ expect(newSheetName).toBe('Sheet1');
+
+ workbook.addWorksheet('sheet3', 1, {
+ id: 'sheet3',
+ name: newSheetName,
+ });
+
+ const newSheetName2 = workbook.generateNewSheetName('Sheet');
+ expect(newSheetName2).toBe('Sheet2');
+ });
+ });
+});
diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.ts
index e30fe411ad..9e9cb6bea3 100644
--- a/packages/core/src/sheets/workbook.ts
+++ b/packages/core/src/sheets/workbook.ts
@@ -361,12 +361,22 @@ export class Workbook extends Disposable {
this._snapshot = config;
}
+ /**
+ * Check if sheet name is unique
+ * @param name sheet name
+ * @returns True if sheet name is unique
+ */
checkSheetName(name: string): boolean {
const sheetsName = this.getSheetsName();
return sheetsName.includes(name);
}
- uniqueSheetName(name: string = 'sheet1'): string {
+ /**
+ * Check whether the sheet name is unique and generate a new unique sheet name
+ * @param name sheet name
+ * @returns Unique sheet name
+ */
+ uniqueSheetName(name: string = 'Sheet1'): string {
let output = name;
while (this.checkSheetName(output)) {
output = name + this._count;
@@ -375,6 +385,20 @@ export class Workbook extends Disposable {
return output;
}
+ /**
+ * Automatically generate new sheet name
+ * @param name sheet name
+ * @returns New sheet name
+ */
+ generateNewSheetName(name: string) {
+ let output = name + this._count;
+ while (this.checkSheetName(output)) {
+ output = name + this._count;
+ this._count++;
+ }
+ return output;
+ }
+
/**
* Get the range array based on the range string and sheet id
*
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/index.module.less b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/index.module.less
index 9ad0074fe3..9152439cec 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/index.module.less
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/index.module.less
@@ -48,6 +48,13 @@
}
&-hide &-icon {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ width: 16px;
+ height: 16px;
+
color: rgb(var(--grey-400));
}
@@ -57,6 +64,13 @@
}
&-select &-icon {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ width: 16px;
+ height: 16px;
+
color: rgb(var(--primary-color));
}
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
index d55b0ab53f..47f17e30cc 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarItem.tsx
@@ -85,7 +85,7 @@ export function SheetBarItem(props: IBaseSheetBarProps) {
color: !currentSelected && color ? getTextColor(color) : '',
boxShadow:
currentSelected && color
- ? `0px 0px 12px rgba(0, 0, 0, 0.2), inset 0px -2px 0px 0px ${color}`
+ ? `0px 0px 8px rgba(0, 0, 0, 0.08), inset 0px -2px 0px 0px ${color}`
: '',
}}
>
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/index.module.less b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/index.module.less
index 26f657488f..6fb6ebae3f 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/index.module.less
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/index.module.less
@@ -35,6 +35,7 @@ Tab Item, Put outside to be compatible with drag styles
margin: 0 var(--margin-xxs);
font-size: var(--font-size-xs);
+ line-height: 16px;
color: rgb(var(--grey-1000));
border-radius: var(--border-radius-base);
diff --git a/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts b/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts
index 5c77ff6b13..909465cdf9 100644
--- a/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts
+++ b/packages/sheets/src/commands/commands/__tests__/create-command-test-bed.ts
@@ -19,6 +19,7 @@ import {
BooleanNumber,
ILogService,
IUniverInstanceService,
+ LocaleService,
LocaleType,
LogLevel,
Plugin,
@@ -28,6 +29,7 @@ import {
import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
+import enUS from '../../../locale/en-US';
import { BorderStyleManagerService } from '../../../services/border-style-manager.service';
import { SelectionManagerService } from '../../../services/selection-manager.service';
import { SheetInterceptorService } from '../../../services/sheet-interceptor/sheet-interceptor.service';
@@ -38,6 +40,7 @@ const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
sheets: {
sheet1: {
id: 'sheet1',
+ name: 'sheet1',
cellData: {
'0': {
'0': {
@@ -106,6 +109,9 @@ export function createCommandTestBed(workbookConfig?: IWorkbookData, dependencie
logService.setLogLevel(LogLevel.SILENT); // change this to `LogLevel.VERBOSE` to debug tests via logs
+ const localeService = injector.get(LocaleService);
+ localeService.load({ enUS });
+
return {
univer,
get: injector.get.bind(injector),
diff --git a/packages/sheets/src/commands/commands/insert-sheet.command.ts b/packages/sheets/src/commands/commands/insert-sheet.command.ts
index b0502d6429..2e91212884 100644
--- a/packages/sheets/src/commands/commands/insert-sheet.command.ts
+++ b/packages/sheets/src/commands/commands/insert-sheet.command.ts
@@ -21,6 +21,7 @@ import {
ICommandService,
IUndoRedoService,
IUniverInstanceService,
+ LocaleService,
Tools,
} from '@univerjs/core';
import type { IAccessor } from '@wendellhu/redi';
@@ -48,6 +49,7 @@ export const InsertSheetCommand: ICommand = {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
const univerInstanceService = accessor.get(IUniverInstanceService);
+ const localeService = accessor.get(LocaleService);
let unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
@@ -66,11 +68,11 @@ export const InsertSheetCommand: ICommand = {
sheetConfig = params.sheet;
} else {
sheetConfig.id = Tools.generateRandomId();
- sheetConfig.name = `工作表${++workbook.getSheets().length}`; // Todo: 表名
+ sheetConfig.name = workbook.generateNewSheetName(`${localeService.t('sheets.sheet')}`);
}
} else {
sheetConfig.id = Tools.generateRandomId();
- sheetConfig.name = `工作表${++workbook.getSheets().length}`; // Todo: 表名
+ sheetConfig.name = workbook.generateNewSheetName(`${localeService.t('sheets.sheet')}`);
}
// prepare do mutations
diff --git a/packages/sheets/src/locale/en-US.ts b/packages/sheets/src/locale/en-US.ts
index 3f7d62412f..5c01acfd75 100644
--- a/packages/sheets/src/locale/en-US.ts
+++ b/packages/sheets/src/locale/en-US.ts
@@ -17,5 +17,6 @@
export default {
sheets: {
sheetCopy: '(Copy)',
+ sheet: 'Sheet',
},
};
diff --git a/packages/sheets/src/locale/zh-CN.ts b/packages/sheets/src/locale/zh-CN.ts
index 69d2c04765..7ad01d31b0 100644
--- a/packages/sheets/src/locale/zh-CN.ts
+++ b/packages/sheets/src/locale/zh-CN.ts
@@ -17,5 +17,6 @@
export default {
sheets: {
sheetCopy: '(副本)',
+ sheet: '工作表',
},
};