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: add date and conditional formatting quick inserts (#7295)

白熱d37bfc187814
diff --git a/common/debugger/package.json b/common/debugger/package.json
index 136e316de4..ecb4ed410d 100644
--- a/common/debugger/package.json
+++ b/common/debugger/package.json
@@ -35,7 +35,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/docs-drawing-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/mockdata": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-drawing-ui": "workspace:*",
diff --git a/common/shared/package.json b/common/shared/package.json
index 16881ed4e2..f36ba7502c 100644
--- a/common/shared/package.json
+++ b/common/shared/package.json
@@ -51,8 +51,8 @@
"vitest": "^4.1.10"
},
"devDependencies": {
- "@univerjs/icons": "1.25.0",
- "@univerjs/icons-svg": "^1.25.0",
+ "@univerjs/icons": "1.29.0",
+ "@univerjs/icons-svg": "^1.29.0",
"typescript": "^6.0.3",
"vue-tsc": "^3.3.6"
}
diff --git a/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png b/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png
index 7333df49fd..4a677889c3 100644
Binary files a/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png and b/e2e/visual-comparison/docs/docs-visual-comparison.spec.ts-snapshots/default-doc-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png
index 4237539485..bbcc3eb35d 100644
Binary files a/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-switching-render-unit.spec.ts-snapshots/switching-render-unit-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png
index e46e723891..394a8d2273 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png
index b136cda94b..f2efbb1630 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png differ
diff --git a/examples/package.json b/examples/package.json
index ff2922f285..8bea78702c 100644
--- a/examples/package.json
+++ b/examples/package.json
@@ -36,7 +36,7 @@
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/find-replace": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/mockdata": "workspace:*",
"@univerjs/network": "workspace:*",
"@univerjs/preset-docs-core": "workspace:*",
diff --git a/packages/action-recorder/package.json b/packages/action-recorder/package.json
index 6aca0dffe2..1c7a414927 100644
--- a/packages/action-recorder/package.json
+++ b/packages/action-recorder/package.json
@@ -76,7 +76,7 @@
"dependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/design/package.json b/packages/design/package.json
index 7a2d0e77b8..d7ccce4973 100644
--- a/packages/design/package.json
+++ b/packages/design/package.json
@@ -81,7 +81,7 @@
"@radix-ui/react-popover": "^1.1.19",
"@radix-ui/react-separator": "^1.1.11",
"@radix-ui/react-slot": "^1.3.0",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"react-transition-group": "^4.4.5",
diff --git a/packages/docs-hyper-link-ui/package.json b/packages/docs-hyper-link-ui/package.json
index 9e46b639eb..9c26046dab 100644
--- a/packages/docs-hyper-link-ui/package.json
+++ b/packages/docs-hyper-link-ui/package.json
@@ -80,7 +80,7 @@
"@univerjs/docs-hyper-link": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/docs-quick-insert-ui/package.json b/packages/docs-quick-insert-ui/package.json
index 89ccba6027..457fc41b3a 100644
--- a/packages/docs-quick-insert-ui/package.json
+++ b/packages/docs-quick-insert-ui/package.json
@@ -83,7 +83,7 @@
"@univerjs/drawing": "workspace:*",
"@univerjs/drawing-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/docs-thread-comment-ui/package.json b/packages/docs-thread-comment-ui/package.json
index 37229226e8..bc8c91a713 100644
--- a/packages/docs-thread-comment-ui/package.json
+++ b/packages/docs-thread-comment-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/thread-comment": "workspace:*",
"@univerjs/thread-comment-ui": "workspace:*",
"@univerjs/ui": "workspace:*"
diff --git a/packages/docs-ui/package.json b/packages/docs-ui/package.json
index 6e66361f1c..7c55c5919b 100644
--- a/packages/docs-ui/package.json
+++ b/packages/docs-ui/package.json
@@ -89,7 +89,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/docs": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/docs-ui/src/menu/schema.ts b/packages/docs-ui/src/menu/schema.ts
index 7ccdc9b21a..096d3209df 100644
--- a/packages/docs-ui/src/menu/schema.ts
+++ b/packages/docs-ui/src/menu/schema.ts
@@ -271,6 +271,10 @@ export const menuSchema: MenuSchemaType = {
order: 8,
menuItemFactory: BulletListMenuItemFactory,
},
+ [CheckListCommand.id]: {
+ order: 9,
+ menuItemFactory: CheckListMenuItemFactory,
+ },
[OpenHeaderFooterPanelCommand.id]: {
order: 10,
menuItemFactory: HeaderFooterMenuItemFactory,
@@ -297,10 +301,6 @@ export const menuSchema: MenuSchemaType = {
order: 3,
menuItemFactory: HorizontalLineFactory,
},
- [CheckListCommand.id]: {
- order: 4,
- menuItemFactory: CheckListMenuItemFactory,
- },
},
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.QUICK]: ({
diff --git a/packages/docs-ui/src/services/__tests__/doc-menu-style.service.spec.ts b/packages/docs-ui/src/services/__tests__/doc-menu-style.service.spec.ts
index d8181b3db2..ddd80865ef 100644
--- a/packages/docs-ui/src/services/__tests__/doc-menu-style.service.spec.ts
+++ b/packages/docs-ui/src/services/__tests__/doc-menu-style.service.spec.ts
@@ -30,7 +30,12 @@ import {
UniverInstanceService,
} from '@univerjs/core';
import { DocSelectionManagerService, SetTextSelectionsOperation } from '@univerjs/docs';
-import { DocumentEditArea, IRenderManagerService, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, RenderManagerService } from '@univerjs/engine-render';
+import {
+ DocumentEditArea,
+ IRenderManagerService,
+ NORMAL_TEXT_SELECTION_PLUGIN_STYLE,
+ RenderManagerService,
+} from '@univerjs/engine-render';
import { describe, expect, it } from 'vitest';
import { DocMenuStyleService } from '../doc-menu-style.service';
diff --git a/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts b/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts
index 81d6ae9a0b..3c6260c051 100644
--- a/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts
+++ b/packages/docs-ui/src/services/__tests__/doc-paragraph-menu.service.spec.ts
@@ -15,11 +15,21 @@
*/
import type { IMutiPageParagraphBound, ITableBound } from '../doc-event-manager.service';
-import { BlockType, DataStreamTreeTokenType, DOC_RANGE_TYPE, DocumentBlockRangeType, DocumentBlockType, PresetListType } from '@univerjs/core';
+import {
+ BlockType,
+ DataStreamTreeTokenType,
+ DOC_RANGE_TYPE,
+ DocumentBlockRangeType,
+ DocumentBlockType,
+ PresetListType,
+} from '@univerjs/core';
import { DocumentEditArea } from '@univerjs/engine-render';
import { BehaviorSubject, Subject } from 'rxjs';
import { describe, expect, it, vi } from 'vitest';
-import { DOC_PARAGRAPH_MENU_COMPONENT_KEY, DOC_TABLE_BLOCK_MENU_COMPONENT_KEY } from '../../views/paragraph-menu/component-keys';
+import {
+ DOC_PARAGRAPH_MENU_COMPONENT_KEY,
+ DOC_TABLE_BLOCK_MENU_COMPONENT_KEY,
+} from '../../views/paragraph-menu/component-keys';
import {
getPreferredParagraphBoundsInRange,
getTableBlockMenuHoverRect,
diff --git a/packages/docs-ui/src/services/__tests__/doc-view-scale.spec.ts b/packages/docs-ui/src/services/__tests__/doc-view-scale.spec.ts
index 87ab589f58..aa04435b8b 100644
--- a/packages/docs-ui/src/services/__tests__/doc-view-scale.spec.ts
+++ b/packages/docs-ui/src/services/__tests__/doc-view-scale.spec.ts
@@ -21,7 +21,12 @@
import { DocumentFlavor, MODERN_DOCUMENT_WIDTH, ModernDocumentWidthMode } from '@univerjs/core';
import { afterEach, describe, expect, it } from 'vitest';
import { DEFAULT_DOC_FIT_TO_WIDTH_OPTIONS } from '../../config/config';
-import { calcDocFitToWidthScale, DocViewScaleService, resolveDocFitBaseWidth, resolveDocViewScale } from '../doc-view-scale';
+import {
+ calcDocFitToWidthScale,
+ DocViewScaleService,
+ resolveDocFitBaseWidth,
+ resolveDocViewScale,
+} from '../doc-view-scale';
describe('doc view scale helpers', () => {
afterEach(() => {
diff --git a/packages/drawing-ui/package.json b/packages/drawing-ui/package.json
index 876398c502..721db01d4a 100644
--- a/packages/drawing-ui/package.json
+++ b/packages/drawing-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/find-replace/package.json b/packages/find-replace/package.json
index ca05f28b2f..c2d9c4983f 100644
--- a/packages/find-replace/package.json
+++ b/packages/find-replace/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/ui": "workspace:*"
},
"devDependencies": {
diff --git a/packages/sheets-conditional-formatting-ui/package.json b/packages/sheets-conditional-formatting-ui/package.json
index 0ba26d0e47..efb658db97 100644
--- a/packages/sheets-conditional-formatting-ui/package.json
+++ b/packages/sheets-conditional-formatting-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
diff --git a/packages/sheets-conditional-formatting-ui/src/commands/commands/__tests__/add-conditional-formatting.command.spec.ts b/packages/sheets-conditional-formatting-ui/src/commands/commands/__tests__/add-conditional-formatting.command.spec.ts
index 0f3a669a8a..3f175cedfa 100644
--- a/packages/sheets-conditional-formatting-ui/src/commands/commands/__tests__/add-conditional-formatting.command.spec.ts
+++ b/packages/sheets-conditional-formatting-ui/src/commands/commands/__tests__/add-conditional-formatting.command.spec.ts
@@ -21,6 +21,9 @@ import {
CFSubRuleType,
CFTextOperator,
CFTimePeriodOperator,
+ CFValueType,
+ ClearRangeCfCommand,
+ IIconSetType,
} from '@univerjs/sheets-conditional-formatting';
import { afterEach, describe, expect, it } from 'vitest';
import { createCfUiTestBed } from '../../../__tests__/create-cf-ui-test-bed';
@@ -28,6 +31,7 @@ import { AddAverageCfCommand } from '../add-average-cf.command';
import { AddColorScaleConditionalRuleCommand } from '../add-color-scale-cf.command';
import { AddDataBarConditionalRuleCommand } from '../add-data-bar-cf.command';
import { AddDuplicateValuesCfCommand } from '../add-duplicate-values-cf.command';
+import { AddIconSetConditionalRuleCommand } from '../add-icon-set-cf.command';
import { AddNumberCfCommand } from '../add-number-cf.command';
import { AddRankCfCommand } from '../add-rank-cf.command';
import { AddTextCfCommand } from '../add-text-cf.command';
@@ -159,6 +163,104 @@ describe('conditional formatting add commands', () => {
testBed.univer.dispose();
});
+ it('adds a data bar to the current selection when ranges are omitted', async () => {
+ const testBed = createCfUiTestBed();
+ testBed.commandService.registerCommand(AddDataBarConditionalRuleCommand);
+ testBed.setSelection(range);
+
+ expect(await testBed.commandService.executeCommand(AddDataBarConditionalRuleCommand.id, {
+ min: { type: CFValueType.min },
+ max: { type: CFValueType.max },
+ nativeColor: '#ddd',
+ positiveColor: '#0f0',
+ isGradient: false,
+ isShowValue: true,
+ })).toBe(true);
+
+ expect(testBed.ruleModel.getSubunitRules(testBed.unitId, testBed.subUnitId)?.[0].ranges).toMatchObject([range]);
+
+ testBed.univer.dispose();
+ });
+
+ it('adds an icon set to the current selection', async () => {
+ const testBed = createCfUiTestBed();
+ testBed.commandService.registerCommand(AddIconSetConditionalRuleCommand);
+ testBed.setSelection(range);
+
+ const config = [
+ {
+ iconType: IIconSetType.threeStars,
+ iconId: '0',
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.percent, value: 67 },
+ },
+ {
+ iconType: IIconSetType.threeStars,
+ iconId: '1',
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.percent, value: 33 },
+ },
+ {
+ iconType: IIconSetType.threeStars,
+ iconId: '2',
+ operator: CFNumberOperator.lessThan,
+ value: { type: CFValueType.percent, value: Number.MAX_SAFE_INTEGER },
+ },
+ ];
+
+ expect(await testBed.commandService.executeCommand(AddIconSetConditionalRuleCommand.id, {
+ config,
+ isShowValue: true,
+ })).toBe(true);
+
+ expect(testBed.ruleModel.getSubunitRules(testBed.unitId, testBed.subUnitId)?.[0]).toMatchObject({
+ ranges: [range],
+ rule: {
+ type: CFRuleType.iconSet,
+ config,
+ isShowValue: true,
+ },
+ });
+
+ testBed.univer.dispose();
+ });
+
+ it('clears only the requested conditional formatting type', async () => {
+ const testBed = createCfUiTestBed();
+ testBed.commandService.registerCommand(AddDataBarConditionalRuleCommand);
+ testBed.commandService.registerCommand(AddIconSetConditionalRuleCommand);
+
+ await testBed.commandService.executeCommand(AddDataBarConditionalRuleCommand.id, {
+ ranges: [range],
+ min: { type: CFValueType.min },
+ max: { type: CFValueType.max },
+ nativeColor: '#ddd',
+ positiveColor: '#0f0',
+ isGradient: false,
+ isShowValue: true,
+ });
+ await testBed.commandService.executeCommand(AddIconSetConditionalRuleCommand.id, {
+ ranges: [range],
+ config: [{
+ iconType: IIconSetType.threeStars,
+ iconId: '0',
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.num, value: 0 },
+ }],
+ isShowValue: true,
+ });
+
+ expect(testBed.commandService.syncExecuteCommand(ClearRangeCfCommand.id, {
+ ranges: [range],
+ types: [CFRuleType.dataBar],
+ })).toBe(true);
+ expect(testBed.ruleModel.getSubunitRules(testBed.unitId, testBed.subUnitId)).toMatchObject([{
+ rule: { type: CFRuleType.iconSet },
+ }]);
+
+ testBed.univer.dispose();
+ });
+
it('adds rank highlight rules for bottom percent scenarios', async () => {
const testBed = createCfUiTestBed();
testBed.commandService.registerCommand(AddRankCfCommand);
diff --git a/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts b/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts
index a6c5023f2d..a83ba45392 100644
--- a/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts
+++ b/packages/sheets-conditional-formatting-ui/src/commands/commands/add-data-bar-cf.command.ts
@@ -21,11 +21,11 @@ import {
ICommandService,
IUniverInstanceService,
} from '@univerjs/core';
-import { getSheetCommandTarget } from '@univerjs/sheets';
+import { getSheetCommandTarget, SheetsSelectionsService } from '@univerjs/sheets';
import { AddConditionalRuleMutation, CFRuleType, ConditionalFormattingRuleModel } from '@univerjs/sheets-conditional-formatting';
interface IAddUniqueValuesConditionalRuleParams {
- ranges: IRange[];
+ ranges?: IRange[];
stopIfTrue?: boolean;
min: IDataBar['config']['min'];
max: IDataBar['config']['max'];
@@ -42,7 +42,9 @@ export const AddDataBarConditionalRuleCommand: ICommand<IAddUniqueValuesConditio
if (!params) {
return false;
}
- const { ranges, min, max, nativeColor, positiveColor, isGradient, stopIfTrue, isShowValue } = params;
+ const { min, max, nativeColor, positiveColor, isGradient, stopIfTrue, isShowValue } = params;
+ const ranges = params.ranges ?? accessor.get(SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
+ if (!ranges.length) return false;
const conditionalFormattingRuleModel = accessor.get(ConditionalFormattingRuleModel);
const univerInstanceService = accessor.get(IUniverInstanceService);
diff --git a/packages/sheets-conditional-formatting-ui/src/commands/commands/add-icon-set-cf.command.ts b/packages/sheets-conditional-formatting-ui/src/commands/commands/add-icon-set-cf.command.ts
new file mode 100644
index 0000000000..a8b46e8759
--- /dev/null
+++ b/packages/sheets-conditional-formatting-ui/src/commands/commands/add-icon-set-cf.command.ts
@@ -0,0 +1,60 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { ICommand, IRange } from '@univerjs/core';
+import type { IAddConditionalRuleMutationParams, IConditionFormattingRule, IIconSet } from '@univerjs/sheets-conditional-formatting';
+import { CommandType, ICommandService, IUniverInstanceService } from '@univerjs/core';
+import { getSheetCommandTarget, SheetsSelectionsService } from '@univerjs/sheets';
+import { AddConditionalRuleMutation, CFRuleType, ConditionalFormattingRuleModel } from '@univerjs/sheets-conditional-formatting';
+
+interface IAddIconSetConditionalRuleParams {
+ ranges?: IRange[];
+ stopIfTrue?: boolean;
+ config: IIconSet['config'];
+ isShowValue: IIconSet['isShowValue'];
+}
+
+export const AddIconSetConditionalRuleCommand: ICommand<IAddIconSetConditionalRuleParams> = {
+ type: CommandType.COMMAND,
+ id: 'sheet.command.add-icon-set-conditional-rule',
+ handler(accessor, params) {
+ if (!params) return false;
+
+ const ranges = params.ranges ?? accessor.get(SheetsSelectionsService).getCurrentSelections().map((selection) => selection.range);
+ if (!ranges.length) return false;
+
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
+ if (!target) return false;
+
+ const { unitId, subUnitId } = target;
+ const rule: IConditionFormattingRule = {
+ ranges,
+ cfId: accessor.get(ConditionalFormattingRuleModel).createCfId(unitId, subUnitId),
+ stopIfTrue: !!params.stopIfTrue,
+ rule: {
+ type: CFRuleType.iconSet,
+ config: params.config,
+ isShowValue: params.isShowValue,
+ },
+ };
+
+ return accessor.get(ICommandService).executeCommand(AddConditionalRuleMutation.id, {
+ unitId,
+ subUnitId,
+ rule,
+ } as IAddConditionalRuleMutationParams);
+ },
+};
diff --git a/packages/sheets-conditional-formatting-ui/src/controllers/components.controller.ts b/packages/sheets-conditional-formatting-ui/src/controllers/components.controller.ts
index 95847899f0..a6c7957344 100644
--- a/packages/sheets-conditional-formatting-ui/src/controllers/components.controller.ts
+++ b/packages/sheets-conditional-formatting-ui/src/controllers/components.controller.ts
@@ -15,7 +15,7 @@
*/
import { Disposable, Inject } from '@univerjs/core';
-import { ConditionsDoubleIcon } from '@univerjs/icons';
+import { ConditionsDoubleIcon, DataBarIcon, RatingIcon } from '@univerjs/icons';
import { ComponentManager, IconManager } from '@univerjs/ui';
import { ConditionFormattingPanel } from '../views/ConditionFormattingPanel';
@@ -41,6 +41,8 @@ export class ComponentsController extends Disposable {
private _registerIcons(): void {
this.disposeWithMe(this._iconManager.register({
ConditionsDoubleIcon,
+ DataBarIcon,
+ RatingIcon,
}));
}
}
diff --git a/packages/sheets-conditional-formatting-ui/src/index.ts b/packages/sheets-conditional-formatting-ui/src/index.ts
index ee25b3f381..c237d2c331 100644
--- a/packages/sheets-conditional-formatting-ui/src/index.ts
+++ b/packages/sheets-conditional-formatting-ui/src/index.ts
@@ -20,6 +20,7 @@ export { AddAverageCfCommand } from './commands/commands/add-average-cf.command'
export { AddColorScaleConditionalRuleCommand } from './commands/commands/add-color-scale-cf.command';
export { AddDataBarConditionalRuleCommand } from './commands/commands/add-data-bar-cf.command';
export { AddDuplicateValuesCfCommand } from './commands/commands/add-duplicate-values-cf.command';
+export { AddIconSetConditionalRuleCommand } from './commands/commands/add-icon-set-cf.command';
export { AddNumberCfCommand } from './commands/commands/add-number-cf.command';
export { AddRankCfCommand } from './commands/commands/add-rank-cf.command';
export { AddTextCfCommand } from './commands/commands/add-text-cf.command';
diff --git a/packages/sheets-conditional-formatting-ui/src/menu/quick-insert.menu.ts b/packages/sheets-conditional-formatting-ui/src/menu/quick-insert.menu.ts
new file mode 100644
index 0000000000..103de8e283
--- /dev/null
+++ b/packages/sheets-conditional-formatting-ui/src/menu/quick-insert.menu.ts
@@ -0,0 +1,161 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IAccessor } from '@univerjs/core';
+import type { IIconSet } from '@univerjs/sheets-conditional-formatting';
+import type { IMenuSelectorItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
+import { UniverInstanceType } from '@univerjs/core';
+import {
+ RangeProtectionPermissionEditPoint,
+ WorkbookEditablePermission,
+ WorksheetEditPermission,
+ WorksheetSetCellStylePermission,
+} from '@univerjs/sheets';
+import {
+ CFNumberOperator,
+ CFRuleType,
+ CFValueType,
+ ClearRangeCfCommand,
+ defaultDataBarNativeColor,
+ defaultDataBarPositiveColor,
+ IIconSetType,
+} from '@univerjs/sheets-conditional-formatting';
+import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
+import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
+import { AddDataBarConditionalRuleCommand } from '../commands/commands/add-data-bar-cf.command';
+import { AddIconSetConditionalRuleCommand } from '../commands/commands/add-icon-set-cf.command';
+import { CF_MENU_OPERATION, OpenConditionalFormattingOperator } from '../commands/operations/open-conditional-formatting-panel';
+
+const DATA_BAR_PARAMS = {
+ min: { type: CFValueType.min },
+ max: { type: CFValueType.max },
+ nativeColor: defaultDataBarNativeColor,
+ positiveColor: defaultDataBarPositiveColor,
+ isGradient: false,
+ isShowValue: true,
+};
+
+function createIconSetParams(iconType: IIconSetType): { config: IIconSet['config']; isShowValue: boolean } {
+ return {
+ config: [
+ {
+ iconType,
+ iconId: '0',
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.percent, value: 67 },
+ },
+ {
+ iconType,
+ iconId: '1',
+ operator: CFNumberOperator.greaterThanOrEqual,
+ value: { type: CFValueType.percent, value: 33 },
+ },
+ {
+ iconType,
+ iconId: '2',
+ operator: CFNumberOperator.lessThanOrEqual,
+ value: { type: CFValueType.percent, value: Number.MAX_SAFE_INTEGER },
+ },
+ ],
+ isShowValue: true,
+ };
+}
+
+function getQuickConditionalFormattingMenuState(accessor: IAccessor) {
+ return {
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ disabled$: getCurrentRangeDisable$(accessor, {
+ workbookTypes: [WorkbookEditablePermission],
+ worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
+ rangeTypes: [RangeProtectionPermissionEditPoint],
+ }),
+ };
+}
+
+export function quickDataBarMenuFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
+ return {
+ id: AddDataBarConditionalRuleCommand.id,
+ type: MenuItemType.BUTTON_SELECTOR,
+ icon: 'DataBarIcon',
+ tooltip: 'sheets-conditional-formatting-ui.ruleType.dataBar',
+ params: DATA_BAR_PARAMS,
+ selectionsCommandId: AddDataBarConditionalRuleCommand.id,
+ selections: [
+ {
+ label: 'sheets-conditional-formatting-ui.ruleType.dataBar',
+ value: CFRuleType.dataBar,
+ params: DATA_BAR_PARAMS,
+ },
+ {
+ id: OpenConditionalFormattingOperator.id,
+ label: 'sheets-conditional-formatting-ui.menu.createConditionalFormatting',
+ value: CF_MENU_OPERATION.dataBar,
+ params: { value: CF_MENU_OPERATION.dataBar },
+ },
+ {
+ id: ClearRangeCfCommand.id,
+ label: 'sheets-conditional-formatting-ui.menu.clearRangeRules',
+ value: CFRuleType.dataBar,
+ params: { types: [CFRuleType.dataBar] },
+ },
+ ],
+ ...getQuickConditionalFormattingMenuState(accessor),
+ };
+}
+
+export function quickIconSetMenuFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
+ const ratingParams = createIconSetParams(IIconSetType.threeStars);
+
+ return {
+ id: AddIconSetConditionalRuleCommand.id,
+ type: MenuItemType.BUTTON_SELECTOR,
+ icon: 'RatingIcon',
+ tooltip: 'sheets-conditional-formatting-ui.ruleType.iconSet',
+ params: ratingParams,
+ selectionsCommandId: AddIconSetConditionalRuleCommand.id,
+ selections: [
+ {
+ label: 'sheets-conditional-formatting-ui.iconSet.rank',
+ value: IIconSetType.threeStars,
+ params: ratingParams,
+ },
+ {
+ label: 'sheets-conditional-formatting-ui.iconSet.shape',
+ value: IIconSetType.threeTrafficLights1,
+ params: createIconSetParams(IIconSetType.threeTrafficLights1),
+ },
+ {
+ label: 'sheets-conditional-formatting-ui.iconSet.direction',
+ value: IIconSetType.threeArrows,
+ params: createIconSetParams(IIconSetType.threeArrows),
+ },
+ {
+ id: OpenConditionalFormattingOperator.id,
+ label: 'sheets-conditional-formatting-ui.menu.createConditionalFormatting',
+ value: CF_MENU_OPERATION.icon,
+ params: { value: CF_MENU_OPERATION.icon },
+ },
+ {
+ id: ClearRangeCfCommand.id,
+ label: 'sheets-conditional-formatting-ui.menu.clearRangeRules',
+ value: CFRuleType.iconSet,
+ params: { types: [CFRuleType.iconSet] },
+ },
+ ],
+ ...getQuickConditionalFormattingMenuState(accessor),
+ };
+}
diff --git a/packages/sheets-conditional-formatting-ui/src/menu/schema.ts b/packages/sheets-conditional-formatting-ui/src/menu/schema.ts
index e5aa5c8932..4c7a5d605c 100644
--- a/packages/sheets-conditional-formatting-ui/src/menu/schema.ts
+++ b/packages/sheets-conditional-formatting-ui/src/menu/schema.ts
@@ -15,11 +15,24 @@
*/
import type { MenuSchemaType } from '@univerjs/ui';
-import { RibbonDataGroup } from '@univerjs/ui';
+import { RibbonDataGroup, RibbonInsertGroup } from '@univerjs/ui';
+import { AddDataBarConditionalRuleCommand } from '../commands/commands/add-data-bar-cf.command';
+import { AddIconSetConditionalRuleCommand } from '../commands/commands/add-icon-set-cf.command';
import { OpenConditionalFormattingOperator } from '../commands/operations/open-conditional-formatting-panel';
import { FactoryManageConditionalFormattingRule } from './manage-rule';
+import { quickDataBarMenuFactory, quickIconSetMenuFactory } from './quick-insert.menu';
export const menuSchema: MenuSchemaType = {
+ [RibbonInsertGroup.CELL]: {
+ [AddDataBarConditionalRuleCommand.id]: {
+ order: 3,
+ menuItemFactory: quickDataBarMenuFactory,
+ },
+ [AddIconSetConditionalRuleCommand.id]: {
+ order: 4,
+ menuItemFactory: quickIconSetMenuFactory,
+ },
+ },
[RibbonDataGroup.RULES]: {
[OpenConditionalFormattingOperator.id]: {
order: 1,
diff --git a/packages/sheets-conditional-formatting-ui/src/mobile-plugin.ts b/packages/sheets-conditional-formatting-ui/src/mobile-plugin.ts
index 6ac486616d..5b198efa2d 100644
--- a/packages/sheets-conditional-formatting-ui/src/mobile-plugin.ts
+++ b/packages/sheets-conditional-formatting-ui/src/mobile-plugin.ts
@@ -31,6 +31,7 @@ import { AddAverageCfCommand } from './commands/commands/add-average-cf.command'
import { AddColorScaleConditionalRuleCommand } from './commands/commands/add-color-scale-cf.command';
import { AddDataBarConditionalRuleCommand } from './commands/commands/add-data-bar-cf.command';
import { AddDuplicateValuesCfCommand } from './commands/commands/add-duplicate-values-cf.command';
+import { AddIconSetConditionalRuleCommand } from './commands/commands/add-icon-set-cf.command';
import { AddNumberCfCommand } from './commands/commands/add-number-cf.command';
import { AddRankCfCommand } from './commands/commands/add-rank-cf.command';
import { AddTextCfCommand } from './commands/commands/add-text-cf.command';
@@ -84,6 +85,7 @@ export class UniverSheetsConditionalFormattingMobileUIPlugin extends Plugin {
AddAverageCfCommand,
AddColorScaleConditionalRuleCommand,
AddDataBarConditionalRuleCommand,
+ AddIconSetConditionalRuleCommand,
AddDuplicateValuesCfCommand,
AddNumberCfCommand,
AddRankCfCommand,
diff --git a/packages/sheets-conditional-formatting-ui/src/plugin.ts b/packages/sheets-conditional-formatting-ui/src/plugin.ts
index 4db081e860..fff4336a69 100644
--- a/packages/sheets-conditional-formatting-ui/src/plugin.ts
+++ b/packages/sheets-conditional-formatting-ui/src/plugin.ts
@@ -34,6 +34,7 @@ import { AddAverageCfCommand } from './commands/commands/add-average-cf.command'
import { AddColorScaleConditionalRuleCommand } from './commands/commands/add-color-scale-cf.command';
import { AddDataBarConditionalRuleCommand } from './commands/commands/add-data-bar-cf.command';
import { AddDuplicateValuesCfCommand } from './commands/commands/add-duplicate-values-cf.command';
+import { AddIconSetConditionalRuleCommand } from './commands/commands/add-icon-set-cf.command';
import { AddNumberCfCommand } from './commands/commands/add-number-cf.command';
import { AddRankCfCommand } from './commands/commands/add-rank-cf.command';
import { AddTextCfCommand } from './commands/commands/add-text-cf.command';
@@ -133,6 +134,7 @@ export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
AddAverageCfCommand,
AddColorScaleConditionalRuleCommand,
AddDataBarConditionalRuleCommand,
+ AddIconSetConditionalRuleCommand,
AddDuplicateValuesCfCommand,
AddNumberCfCommand,
AddRankCfCommand,
diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
index 8bec7ff626..96a3273ac8 100644
--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx
@@ -35,8 +35,8 @@ import {
IIconSetType,
} from '@univerjs/sheets-conditional-formatting';
import { FormulaEditor } from '@univerjs/sheets-formula-ui';
-import { ILayoutService, useDependency, useObservable, useScrollYOverContainer, useSidebarClick } from '@univerjs/ui';
-import { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
+import { useDependency, useObservable, useSidebarClick } from '@univerjs/ui';
+import { useEffect, useMemo, useRef, useState } from 'react';
const getIcon = (iconType: IIconSetType, iconId: string | number) => {
const arr = iconMap[iconType] || [];
@@ -114,50 +114,72 @@ interface IIconGroupListProps {
onClick: (iconType: IIconSetType) => void;
iconType?: IIconSetType;
};
-const IconGroupList = forwardRef<HTMLDivElement, IIconGroupListProps>((props, ref) => {
- const { onClick } = props;
+const IconGroupList = (props: IIconGroupListProps) => {
+ const { iconType, onClick } = props;
const localeService = useDependency(LocaleService);
const direction = useObservable(localeService.direction$, localeService.getDirection());
- const handleClick = (iconType: IIconSetType) => {
- onClick(iconType);
- };
return (
- <div ref={ref} dir={direction} className="univer-w-80">
- {iconGroup.map((group, index) => {
+ <div dir={direction} className="univer-w-80">
+ {iconGroup.map((group) => {
return (
- <div key={index} className="univer-mb-3">
- <div className="univer-mb-1 univer-text-sm">
+ <div
+ key={group.title}
+ className="
+ univer-mb-4
+ last:univer-mb-0
+ "
+ >
+ <div
+ className="
+ univer-mb-2 univer-px-1 univer-text-xs univer-font-medium univer-text-gray-500
+ dark:!univer-text-gray-400
+ "
+ >
{localeService.t(group.title)}
</div>
- <div className="univer-flex univer-flex-wrap">
- {group.group.map((groupItem) => {
+ <div className="univer-grid univer-grid-cols-2 univer-gap-1">
+ {group.group.map((groupItem, groupItemIndex) => {
+ const selected = groupItem.name === iconType;
return (
- <div
+ <button
key={groupItem.name}
- className="
- univer-mb-1 univer-flex univer-w-1/2 univer-items-center
- rtl:univer-flex-row-reverse rtl:univer-justify-end
- "
- onClick={() => { handleClick(groupItem.name); }}
+ type="button"
+ aria-label={`${localeService.t(group.title)} ${groupItemIndex + 1}`}
+ aria-pressed={selected}
+ className={clsx(
+ `
+ univer-flex univer-h-8 univer-w-full univer-cursor-pointer
+ univer-items-center univer-rounded-md univer-border-0
+ univer-bg-transparent univer-px-2 univer-outline-none
+ univer-transition-colors
+ focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600
+ rtl:univer-flex-row-reverse
+ `,
+ selected
+ ? `
+ univer-bg-primary-50 univer-ring-1 univer-ring-primary-600
+ dark:!univer-bg-primary-900
+ `
+ : `
+ hover:univer-bg-gray-100
+ dark:hover:!univer-bg-gray-700
+ `
+ )}
+ onClick={() => { onClick(groupItem.name); }}
>
- <a
- className={`
- univer-flex univer-cursor-pointer univer-rounded
- hover:univer-bg-gray-100
- dark:hover:!univer-bg-gray-700
- `}
- >
+ <span className="univer-flex univer-items-center univer-gap-0.5">
{groupItem.list.map((base64, index) => (
<img
key={index}
+ alt=""
className="univer-size-5"
src={base64}
draggable={false}
/>
))}
- </a>
- </div>
+ </span>
+ </button>
);
})}
</div>
@@ -166,7 +188,7 @@ const IconGroupList = forwardRef<HTMLDivElement, IIconGroupListProps>((props, re
})}
</div>
);
-});
+};
const IconItemList = (props: { onClick: (iconType: IIconSetType, iconId: string) => void; iconType?: IIconSetType; iconId: string }) => {
const { onClick } = props;
@@ -591,11 +613,6 @@ export const IconSet = (props: IStyleEditorProps<unknown, IIconSet>) => {
});
setConfigList([...configList]);
};
- const layoutService = useDependency(ILayoutService);
- const [iconGroupListEl, setIconGroupListEl] = useState<HTMLDivElement>();
-
- useScrollYOverContainer(iconGroupListEl, layoutService.rootContainerElement);
-
return (
<div data-u-comp="cf-icon-set-editor" dir={direction}>
<div className="univer-mt-4 univer-text-sm univer-text-gray-600">
@@ -604,11 +621,8 @@ export const IconSet = (props: IStyleEditorProps<unknown, IIconSet>) => {
<div className="univer-mt-3">
<Dropdown
overlay={(
- <div dir={direction} className="univer-rounded-lg univer-p-4">
+ <div dir={direction} className="univer-rounded-lg univer-p-3">
<IconGroupList
- ref={(el) => {
- !iconGroupListEl && el && setIconGroupListEl(el);
- }}
iconType={currentIconType}
onClick={handleClickIconList}
/>
diff --git a/packages/sheets-conditional-formatting/package.json b/packages/sheets-conditional-formatting/package.json
index ef1c9489da..88614a3106 100644
--- a/packages/sheets-conditional-formatting/package.json
+++ b/packages/sheets-conditional-formatting/package.json
@@ -92,7 +92,7 @@
},
"devDependencies": {
"@univerjs-infra/shared": "workspace:*",
- "@univerjs/icons-svg": "^1.25.0",
+ "@univerjs/icons-svg": "^1.29.0",
"@univerjs/sheets-formula": "workspace:*",
"rxjs": "^7.8.2",
"typescript": "^6.0.3",
diff --git a/packages/sheets-conditional-formatting/scripts/build-icons.mts b/packages/sheets-conditional-formatting/scripts/build-icons.mts
index 6e1565aafa..ae5a6736e8 100644
--- a/packages/sheets-conditional-formatting/scripts/build-icons.mts
+++ b/packages/sheets-conditional-formatting/scripts/build-icons.mts
@@ -25,9 +25,9 @@ const progress = [
];
const star = [
- ['starEmpty', '@univerjs/icons-svg/double/star-empty-double-icon.svg', { black: '#FFBD37', '#E5E5E5': '#fff' }],
- ['starIncomplete', '@univerjs/icons-svg/double/star-incomplete-double-icon.svg', { black: '#FFBD37', '#E5E5E5': '#fff' }],
- ['starFull', '@univerjs/icons-svg/double/star-full-double-icon.svg', { black: '#FFBD37', '#E5E5E5': '#fff' }],
+ ['starEmpty', '@univerjs/icons-svg/double/star-empty-double-icon.svg', { black: '#FFBD37' }],
+ ['starIncomplete', '@univerjs/icons-svg/double/star-incomplete-double-icon.svg', { black: '#FFBD37' }],
+ ['starFull', '@univerjs/icons-svg/double/star-full-double-icon.svg', { black: '#FFBD37' }],
];
const feeling = [
diff --git a/packages/sheets-conditional-formatting/src/commands/commands/clear-range-cf.command.ts b/packages/sheets-conditional-formatting/src/commands/commands/clear-range-cf.command.ts
index 291b3492ce..8bfaec8efe 100644
--- a/packages/sheets-conditional-formatting/src/commands/commands/clear-range-cf.command.ts
+++ b/packages/sheets-conditional-formatting/src/commands/commands/clear-range-cf.command.ts
@@ -15,6 +15,7 @@
*/
import type { ICommand, IMutationInfo, IRange } from '@univerjs/core';
+import type { CFRuleType } from '../../base/const';
import type { IConditionFormattingRule } from '../../models/type';
import type { IDeleteConditionalRuleMutationParams } from '../mutations/delete-conditional-rule.mutation';
import type { ISetConditionalRuleMutationParams } from '../mutations/set-conditional-rule.mutation';
@@ -35,6 +36,7 @@ export interface IClearRangeCfParams {
ranges?: IRange[];
unitId?: string;
subUnitId?: string;
+ types?: CFRuleType[];
}
export const ClearRangeCfCommand: ICommand<IClearRangeCfParams> = {
type: CommandType.COMMAND,
@@ -55,7 +57,9 @@ export const ClearRangeCfCommand: ICommand<IClearRangeCfParams> = {
const { unitId, subUnitId } = target;
const ranges = params.ranges ?? selectionManagerService.getCurrentSelections()?.map((selection) => selection.range) ?? [];
- const allRuleList = conditionalFormattingRangeIndexModel.getRulesByRanges(unitId, subUnitId, ranges);
+ const allRuleList = conditionalFormattingRangeIndexModel
+ .getRulesByRanges(unitId, subUnitId, ranges)
+ .filter((rule) => !params.types?.length || params.types.includes(rule.rule.type as CFRuleType));
if (!allRuleList?.length || !ranges.length) {
return false;
}
diff --git a/packages/sheets-crosshair-highlight/package.json b/packages/sheets-crosshair-highlight/package.json
index e0f8ffeadf..c2643643de 100644
--- a/packages/sheets-crosshair-highlight/package.json
+++ b/packages/sheets-crosshair-highlight/package.json
@@ -88,7 +88,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*"
diff --git a/packages/sheets-crosshair-highlight/src/controllers/crosshair.controller.spec.tsx b/packages/sheets-crosshair-highlight/src/controllers/crosshair.controller.spec.tsx
index c1ec7128ec..e90512100c 100644
--- a/packages/sheets-crosshair-highlight/src/controllers/crosshair.controller.spec.tsx
+++ b/packages/sheets-crosshair-highlight/src/controllers/crosshair.controller.spec.tsx
@@ -15,6 +15,7 @@
*/
import { CrossHighlightingIcon } from '@univerjs/icons';
+import { RibbonViewGroup } from '@univerjs/ui';
import { describe, expect, it, vi } from 'vitest';
import {
DisableCrosshairHighlightOperation,
@@ -45,6 +46,8 @@ describe('SheetsCrosshairHighlightController', () => {
expect(mergeMenu).toHaveBeenCalledWith(menuSchema);
expect(Object.keys(menuSchema).length).toBeGreaterThan(0);
+ const viewVisibility = (menuSchema as Record<string, Record<string, unknown>>)[RibbonViewGroup.VISIBILITY];
+ expect(viewVisibility).toHaveProperty(ToggleCrosshairHighlightOperation.id);
controller.dispose();
});
diff --git a/packages/sheets-crosshair-highlight/src/menu/schema.ts b/packages/sheets-crosshair-highlight/src/menu/schema.ts
index fe26debd44..14a68b2912 100644
--- a/packages/sheets-crosshair-highlight/src/menu/schema.ts
+++ b/packages/sheets-crosshair-highlight/src/menu/schema.ts
@@ -15,11 +15,17 @@
*/
import type { MenuSchemaType } from '@univerjs/ui';
-import { ContextMenuGroup, ContextMenuPosition } from '@univerjs/ui';
+import { ContextMenuGroup, ContextMenuPosition, RibbonViewGroup } from '@univerjs/ui';
import { ToggleCrosshairHighlightOperation } from '../commands/operations/operation';
import { CrosshairHighlightMenuItemFactory } from './crosshair.menu';
export const menuSchema: MenuSchemaType = {
+ [RibbonViewGroup.VISIBILITY]: {
+ [ToggleCrosshairHighlightOperation.id]: {
+ order: 1,
+ menuItemFactory: CrosshairHighlightMenuItemFactory,
+ },
+ },
[ContextMenuPosition.FOOTER_MENU]: {
[ContextMenuGroup.OTHERS]: {
[ToggleCrosshairHighlightOperation.id]: {
diff --git a/packages/sheets-data-validation-ui/package.json b/packages/sheets-data-validation-ui/package.json
index 8ed80caeb8..018d467d20 100644
--- a/packages/sheets-data-validation-ui/package.json
+++ b/packages/sheets-data-validation-ui/package.json
@@ -80,7 +80,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
diff --git a/packages/sheets-data-validation-ui/src/commands/commands/__tests__/data-validation-ui.command.spec.ts b/packages/sheets-data-validation-ui/src/commands/commands/__tests__/data-validation-ui.command.spec.ts
index 068bf5315f..3e621be04a 100644
--- a/packages/sheets-data-validation-ui/src/commands/commands/__tests__/data-validation-ui.command.spec.ts
+++ b/packages/sheets-data-validation-ui/src/commands/commands/__tests__/data-validation-ui.command.spec.ts
@@ -286,6 +286,28 @@ describe('AddSheetDataValidationAndOpenCommand', () => {
expect(addParams.rule.operator).toBeUndefined();
});
+ it('inserts a date-time picker rule into the current selection', () => {
+ testBed = createTestBed();
+ const commandService = testBed.get(ICommandService);
+
+ expect(commandService.syncExecuteCommand(InsertQuickSheetDataValidationCommand.id, {
+ rule: {
+ type: DataValidationType.DATE,
+ operator: undefined,
+ formula1: undefined,
+ formula2: undefined,
+ bizInfo: { showTime: true },
+ },
+ })).toBe(true);
+
+ const addParams = testBed.executedCommands[0].params as { rule: IDataValidationRule };
+ expect(addParams.rule).toMatchObject({
+ type: DataValidationType.DATE,
+ ranges: [SELECTION_RANGE],
+ bizInfo: { showTime: true },
+ });
+ });
+
it('adds a dropdown rule and opens the existing panel to edit it', () => {
testBed = createTestBed();
const commandService = testBed.get(ICommandService);
diff --git a/packages/sheets-data-validation-ui/src/controllers/components.controller.ts b/packages/sheets-data-validation-ui/src/controllers/components.controller.ts
index bfbf107b3e..ada68d4676 100644
--- a/packages/sheets-data-validation-ui/src/controllers/components.controller.ts
+++ b/packages/sheets-data-validation-ui/src/controllers/components.controller.ts
@@ -15,7 +15,7 @@
*/
import { Disposable, Inject } from '@univerjs/core';
-import { CheckboxIcon, DataValidationIcon, DropdownListIcon } from '@univerjs/icons';
+import { CheckboxIcon, DataValidationIcon, DatePickerIcon, DropdownListIcon } from '@univerjs/icons';
import { ComponentManager, IconManager } from '@univerjs/ui';
import { DATA_VALIDATION_PANEL } from '../commands/operations/data-validation.operation';
import { DataValidationPanel } from '../views/components';
@@ -39,6 +39,7 @@ export class ComponentsController extends Disposable {
this.disposeWithMe(this._iconManager.register({
CheckboxIcon,
DataValidationIcon,
+ DatePickerIcon,
DropdownListIcon,
}));
}
diff --git a/packages/sheets-data-validation-ui/src/locale/ar-SA.ts b/packages/sheets-data-validation-ui/src/locale/ar-SA.ts
index 3dc55827da..6b9969cd1b 100644
--- a/packages/sheets-data-validation-ui/src/locale/ar-SA.ts
+++ b/packages/sheets-data-validation-ui/src/locale/ar-SA.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'تطبيق إعداد مسبق:',
editDropdown: 'تحرير الخيارات',
clearDropdown: 'مسح القائمة المنسدلة',
+ dateTime: 'التاريخ والوقت',
presets: {
yes: 'نعم',
no: 'لا',
diff --git a/packages/sheets-data-validation-ui/src/locale/ca-ES.ts b/packages/sheets-data-validation-ui/src/locale/ca-ES.ts
index 6f5ffaed6b..63bdcc8fcd 100644
--- a/packages/sheets-data-validation-ui/src/locale/ca-ES.ts
+++ b/packages/sheets-data-validation-ui/src/locale/ca-ES.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Aplica una predefinició:',
editDropdown: 'Edita les opcions',
clearDropdown: 'Esborra el menú desplegable',
+ dateTime: 'Data i hora',
presets: {
yes: 'Sí',
no: 'No',
diff --git a/packages/sheets-data-validation-ui/src/locale/de-DE.ts b/packages/sheets-data-validation-ui/src/locale/de-DE.ts
index 54fed4d187..9513a31e6f 100644
--- a/packages/sheets-data-validation-ui/src/locale/de-DE.ts
+++ b/packages/sheets-data-validation-ui/src/locale/de-DE.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Vorlage anwenden:',
editDropdown: 'Optionen bearbeiten',
clearDropdown: 'Dropdown löschen',
+ dateTime: 'Datum und Uhrzeit',
presets: {
yes: 'Ja',
no: 'Nein',
diff --git a/packages/sheets-data-validation-ui/src/locale/en-US.ts b/packages/sheets-data-validation-ui/src/locale/en-US.ts
index edc8f577d9..1c57e030f1 100644
--- a/packages/sheets-data-validation-ui/src/locale/en-US.ts
+++ b/packages/sheets-data-validation-ui/src/locale/en-US.ts
@@ -23,6 +23,7 @@ const locale = {
dropdownPresetTitle: 'Apply a preset:',
editDropdown: 'Edit options',
clearDropdown: 'Clear Dropdown',
+ dateTime: 'Date & Time',
presets: {
yes: 'Yes',
no: 'No',
diff --git a/packages/sheets-data-validation-ui/src/locale/es-ES.ts b/packages/sheets-data-validation-ui/src/locale/es-ES.ts
index a9e2e2b80a..7aed205bbe 100644
--- a/packages/sheets-data-validation-ui/src/locale/es-ES.ts
+++ b/packages/sheets-data-validation-ui/src/locale/es-ES.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Aplicar un preajuste:',
editDropdown: 'Editar opciones',
clearDropdown: 'Borrar lista desplegable',
+ dateTime: 'Fecha y hora',
presets: {
yes: 'Sí',
no: 'No',
diff --git a/packages/sheets-data-validation-ui/src/locale/fa-IR.ts b/packages/sheets-data-validation-ui/src/locale/fa-IR.ts
index 509e0dd7aa..370a0c54fc 100644
--- a/packages/sheets-data-validation-ui/src/locale/fa-IR.ts
+++ b/packages/sheets-data-validation-ui/src/locale/fa-IR.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'اعمال یک پیش‌تنظیم:',
editDropdown: 'ویرایش گزینه‌ها',
clearDropdown: 'پاک کردن فهرست کشویی',
+ dateTime: 'تاریخ و زمان',
presets: {
yes: 'بله',
no: 'خیر',
diff --git a/packages/sheets-data-validation-ui/src/locale/fr-FR.ts b/packages/sheets-data-validation-ui/src/locale/fr-FR.ts
index 8b496e5d7f..8f910c71ee 100644
--- a/packages/sheets-data-validation-ui/src/locale/fr-FR.ts
+++ b/packages/sheets-data-validation-ui/src/locale/fr-FR.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Appliquer un préréglage :',
editDropdown: 'Modifier les options',
clearDropdown: 'Effacer la liste déroulante',
+ dateTime: 'Date et heure',
presets: {
yes: 'Oui',
no: 'Non',
diff --git a/packages/sheets-data-validation-ui/src/locale/id-ID.ts b/packages/sheets-data-validation-ui/src/locale/id-ID.ts
index c819a554eb..add38293f4 100644
--- a/packages/sheets-data-validation-ui/src/locale/id-ID.ts
+++ b/packages/sheets-data-validation-ui/src/locale/id-ID.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Terapkan preset:',
editDropdown: 'Edit opsi',
clearDropdown: 'Hapus Dropdown',
+ dateTime: 'Tanggal dan waktu',
presets: {
yes: 'Ya',
no: 'Tidak',
diff --git a/packages/sheets-data-validation-ui/src/locale/it-IT.ts b/packages/sheets-data-validation-ui/src/locale/it-IT.ts
index fc5f7b04b8..0b393fa188 100644
--- a/packages/sheets-data-validation-ui/src/locale/it-IT.ts
+++ b/packages/sheets-data-validation-ui/src/locale/it-IT.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Applica una preimpostazione:',
editDropdown: 'Modifica opzioni',
clearDropdown: 'Cancella elenco a discesa',
+ dateTime: 'Data e ora',
presets: {
yes: 'Sì',
no: 'No',
diff --git a/packages/sheets-data-validation-ui/src/locale/ja-JP.ts b/packages/sheets-data-validation-ui/src/locale/ja-JP.ts
index 31c1a0e2c3..4e05263eaa 100644
--- a/packages/sheets-data-validation-ui/src/locale/ja-JP.ts
+++ b/packages/sheets-data-validation-ui/src/locale/ja-JP.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'プリセットを適用:',
editDropdown: 'オプションを編集',
clearDropdown: 'プルダウンをクリア',
+ dateTime: '日付と時刻',
presets: {
yes: 'はい',
no: 'いいえ',
diff --git a/packages/sheets-data-validation-ui/src/locale/ko-KR.ts b/packages/sheets-data-validation-ui/src/locale/ko-KR.ts
index b5127d9dc7..b643dac54a 100644
--- a/packages/sheets-data-validation-ui/src/locale/ko-KR.ts
+++ b/packages/sheets-data-validation-ui/src/locale/ko-KR.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: '프리셋 적용:',
editDropdown: '옵션 편집',
clearDropdown: '드롭다운 지우기',
+ dateTime: '날짜 및 시간',
presets: {
yes: '예',
no: '아니요',
diff --git a/packages/sheets-data-validation-ui/src/locale/pl-PL.ts b/packages/sheets-data-validation-ui/src/locale/pl-PL.ts
index aadbd24aec..670ad41d7c 100644
--- a/packages/sheets-data-validation-ui/src/locale/pl-PL.ts
+++ b/packages/sheets-data-validation-ui/src/locale/pl-PL.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Zastosuj ustawienie wstępne:',
editDropdown: 'Edytuj opcje',
clearDropdown: 'Wyczyść listę rozwijaną',
+ dateTime: 'Data i czas',
presets: {
yes: 'Tak',
no: 'Nie',
diff --git a/packages/sheets-data-validation-ui/src/locale/pt-BR.ts b/packages/sheets-data-validation-ui/src/locale/pt-BR.ts
index b435bb8b32..04f1848307 100644
--- a/packages/sheets-data-validation-ui/src/locale/pt-BR.ts
+++ b/packages/sheets-data-validation-ui/src/locale/pt-BR.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Aplicar predefinição:',
editDropdown: 'Editar opções',
clearDropdown: 'Limpar lista suspensa',
+ dateTime: 'Data e hora',
presets: {
yes: 'Sim',
no: 'Não',
diff --git a/packages/sheets-data-validation-ui/src/locale/ru-RU.ts b/packages/sheets-data-validation-ui/src/locale/ru-RU.ts
index c8facfb449..419c1ba2fc 100644
--- a/packages/sheets-data-validation-ui/src/locale/ru-RU.ts
+++ b/packages/sheets-data-validation-ui/src/locale/ru-RU.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Применить шаблон:',
editDropdown: 'Изменить варианты',
clearDropdown: 'Очистить раскрывающийся список',
+ dateTime: 'Дата и время',
presets: {
yes: 'Да',
no: 'Нет',
diff --git a/packages/sheets-data-validation-ui/src/locale/sk-SK.ts b/packages/sheets-data-validation-ui/src/locale/sk-SK.ts
index e8b952f635..14d12e7f2d 100644
--- a/packages/sheets-data-validation-ui/src/locale/sk-SK.ts
+++ b/packages/sheets-data-validation-ui/src/locale/sk-SK.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Použiť predvoľbu:',
editDropdown: 'Upraviť možnosti',
clearDropdown: 'Vymazať rozbaľovací zoznam',
+ dateTime: 'Dátum a čas',
presets: {
yes: 'Áno',
no: 'Nie',
diff --git a/packages/sheets-data-validation-ui/src/locale/vi-VN.ts b/packages/sheets-data-validation-ui/src/locale/vi-VN.ts
index f5102ae3af..9bba4c6d44 100644
--- a/packages/sheets-data-validation-ui/src/locale/vi-VN.ts
+++ b/packages/sheets-data-validation-ui/src/locale/vi-VN.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: 'Áp dụng mẫu:',
editDropdown: 'Chỉnh sửa tùy chọn',
clearDropdown: 'Xóa danh sách thả xuống',
+ dateTime: 'Ngày giờ',
presets: {
yes: 'Có',
no: 'Không',
diff --git a/packages/sheets-data-validation-ui/src/locale/zh-CN.ts b/packages/sheets-data-validation-ui/src/locale/zh-CN.ts
index a9a3b03c5a..e8b0cf65c9 100644
--- a/packages/sheets-data-validation-ui/src/locale/zh-CN.ts
+++ b/packages/sheets-data-validation-ui/src/locale/zh-CN.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: '应用预设:',
editDropdown: '编辑选项',
clearDropdown: '清除下拉菜单',
+ dateTime: '日期时间',
presets: {
yes: '是',
no: '否',
diff --git a/packages/sheets-data-validation-ui/src/locale/zh-HK.ts b/packages/sheets-data-validation-ui/src/locale/zh-HK.ts
index 2c464a3a0a..ed0afeebc0 100644
--- a/packages/sheets-data-validation-ui/src/locale/zh-HK.ts
+++ b/packages/sheets-data-validation-ui/src/locale/zh-HK.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: '套用預設:',
editDropdown: '編輯選項',
clearDropdown: '清除下拉式選單',
+ dateTime: '日期時間',
presets: {
yes: '是',
no: '否',
diff --git a/packages/sheets-data-validation-ui/src/locale/zh-TW.ts b/packages/sheets-data-validation-ui/src/locale/zh-TW.ts
index 3880891d0f..2475ddcb6c 100644
--- a/packages/sheets-data-validation-ui/src/locale/zh-TW.ts
+++ b/packages/sheets-data-validation-ui/src/locale/zh-TW.ts
@@ -25,6 +25,7 @@ const locale: typeof enUS = {
dropdownPresetTitle: '套用預設:',
editDropdown: '編輯選項',
clearDropdown: '清除下拉式選單',
+ dateTime: '日期時間',
presets: {
yes: '是',
no: '否',
diff --git a/packages/sheets-data-validation-ui/src/menu/dv.menu.ts b/packages/sheets-data-validation-ui/src/menu/dv.menu.ts
index 99f1720a0b..8eee890dba 100644
--- a/packages/sheets-data-validation-ui/src/menu/dv.menu.ts
+++ b/packages/sheets-data-validation-ui/src/menu/dv.menu.ts
@@ -38,6 +38,7 @@ import { DROPDOWN_PRESETS_COMPONENT } from '../views/components/DropdownPresets'
export const DATA_VALIDATION_MENU_ID = 'sheet.menu.data-validation';
export const QUICK_DROPDOWN_MENU_ID = 'sheet.menu.quick-dropdown';
+export const QUICK_DATE_MENU_ID = 'sheet.menu.quick-date';
const CHECKBOX_RULE_INPUT: IQuickDataValidationRuleInput = {
type: DataValidationType.CHECKBOX,
@@ -46,6 +47,18 @@ const CHECKBOX_RULE_INPUT: IQuickDataValidationRuleInput = {
formula2: undefined,
};
+const DATE_RULE_INPUT: IQuickDataValidationRuleInput = {
+ type: DataValidationType.DATE,
+ operator: undefined,
+ formula1: undefined,
+ formula2: undefined,
+};
+
+const DATE_TIME_RULE_INPUT: IQuickDataValidationRuleInput = {
+ ...DATE_RULE_INPUT,
+ bizInfo: { showTime: true },
+};
+
function createDropdownRuleInput(formula1: string): IQuickDataValidationRuleInput {
return {
type: DataValidationType.LIST,
@@ -150,6 +163,43 @@ export function quickDropdownMenuFactory(accessor: IAccessor): IMenuSelectorItem
};
}
+export function quickDateMenuFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
+ return {
+ id: QUICK_DATE_MENU_ID,
+ commandId: InsertQuickSheetDataValidationCommand.id,
+ type: MenuItemType.BUTTON_SELECTOR,
+ icon: 'DatePickerIcon',
+ tooltip: 'sheets-data-validation-ui.date.title',
+ params: { rule: DATE_RULE_INPUT },
+ selectionsCommandId: InsertQuickSheetDataValidationCommand.id,
+ selections: [
+ {
+ label: 'sheets-data-validation-ui.date.title',
+ value: DataValidationType.DATE,
+ params: { rule: DATE_RULE_INPUT },
+ },
+ {
+ label: 'sheets-data-validation-ui.ribbon.dateTime',
+ value: DataValidationType.DATE,
+ params: { rule: DATE_TIME_RULE_INPUT },
+ },
+ {
+ id: AddSheetDataValidationAndOpenCommand.id,
+ label: 'sheets-data-validation-ui.list.edit',
+ value: DataValidationType.DATE,
+ params: { rule: DATE_RULE_INPUT },
+ },
+ {
+ id: ClearQuickSheetDataValidationCommand.id,
+ label: 'sheets-data-validation-ui.panel.removeRule',
+ value: DataValidationType.DATE,
+ params: { types: [DataValidationType.DATE] },
+ },
+ ],
+ ...getQuickDataValidationMenuState(accessor),
+ };
+}
+
export function openDataValidationMenuFactory(): IMenuItem<LocaleKey> {
return {
id: OpenValidationPanelOperation.id,
diff --git a/packages/sheets-data-validation-ui/src/menu/schema.ts b/packages/sheets-data-validation-ui/src/menu/schema.ts
index f6130b5d63..751edebd68 100644
--- a/packages/sheets-data-validation-ui/src/menu/schema.ts
+++ b/packages/sheets-data-validation-ui/src/menu/schema.ts
@@ -26,8 +26,10 @@ import {
DATA_VALIDATION_MENU_ID,
dataValidationMenuFactory,
openDataValidationMenuFactory,
+ QUICK_DATE_MENU_ID,
QUICK_DROPDOWN_MENU_ID,
quickCheckboxMenuFactory,
+ quickDateMenuFactory,
quickDropdownMenuFactory,
} from './dv.menu';
@@ -41,6 +43,10 @@ export const menuSchema: MenuSchemaType = {
order: 1,
menuItemFactory: quickDropdownMenuFactory,
},
+ [QUICK_DATE_MENU_ID]: {
+ order: 2,
+ menuItemFactory: quickDateMenuFactory,
+ },
},
[RibbonDataGroup.RULES]: {
[DATA_VALIDATION_MENU_ID]: {
diff --git a/packages/sheets-filter-ui/package.json b/packages/sheets-filter-ui/package.json
index 4620f28215..9edab8f4d7 100644
--- a/packages/sheets-filter-ui/package.json
+++ b/packages/sheets-filter-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
diff --git a/packages/sheets-formula-ui/package.json b/packages/sheets-formula-ui/package.json
index 34721d96ef..9e7d10b264 100644
--- a/packages/sheets-formula-ui/package.json
+++ b/packages/sheets-formula-ui/package.json
@@ -91,7 +91,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-formula-ui/src/menu/schema.ts b/packages/sheets-formula-ui/src/menu/schema.ts
index 02a3524ce9..5eb8b00975 100644
--- a/packages/sheets-formula-ui/src/menu/schema.ts
+++ b/packages/sheets-formula-ui/src/menu/schema.ts
@@ -50,82 +50,42 @@ export const menuSchema: MenuSchemaType = {
[`${InsertFunctionOperation.id}.financial`]: {
order: 1,
menuItemFactory: InsertFinancialFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.logical`]: {
order: 2,
menuItemFactory: InsertLogicalFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.text`]: {
order: 3,
menuItemFactory: InsertTextFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.date`]: {
order: 4,
menuItemFactory: InsertDateFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.lookup`]: {
order: 5,
menuItemFactory: InsertLookupFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.math`]: {
order: 6,
menuItemFactory: InsertMathFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.statistical`]: {
order: 7,
menuItemFactory: InsertStatisticalFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.engineering`]: {
order: 8,
menuItemFactory: InsertEngineeringFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.information`]: {
order: 9,
menuItemFactory: InsertInformationFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
[`${InsertFunctionOperation.id}.database`]: {
order: 10,
menuItemFactory: InsertDatabaseFunctionMenuItemFactory,
- [MoreFunctionsOperation.id]: {
- order: 0,
- menuItemFactory: AllFunctionsMenuItemFactory,
- },
},
},
[COPY_SPECIAL_MENU_ID]: {
diff --git a/packages/sheets-hyper-link-ui/package.json b/packages/sheets-hyper-link-ui/package.json
index 7344ca865f..88cae31522 100644
--- a/packages/sheets-hyper-link-ui/package.json
+++ b/packages/sheets-hyper-link-ui/package.json
@@ -91,7 +91,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
diff --git a/packages/sheets-note-ui/package.json b/packages/sheets-note-ui/package.json
index 700b719121..bb69e4adc4 100644
--- a/packages/sheets-note-ui/package.json
+++ b/packages/sheets-note-ui/package.json
@@ -74,7 +74,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-note": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-numfmt-ui/package.json b/packages/sheets-numfmt-ui/package.json
index 89918e76e7..2f7378edbd 100644
--- a/packages/sheets-numfmt-ui/package.json
+++ b/packages/sheets-numfmt-ui/package.json
@@ -78,7 +78,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-sort-ui/package.json b/packages/sheets-sort-ui/package.json
index 0d0fb6f954..83ce1e71d5 100644
--- a/packages/sheets-sort-ui/package.json
+++ b/packages/sheets-sort-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-sort": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-table-ui/package.json b/packages/sheets-table-ui/package.json
index 66831c6402..d1f815d61a 100644
--- a/packages/sheets-table-ui/package.json
+++ b/packages/sheets-table-ui/package.json
@@ -79,7 +79,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-formula-ui": "workspace:*",
"@univerjs/sheets-sort": "workspace:*",
diff --git a/packages/sheets-thread-comment-ui/package.json b/packages/sheets-thread-comment-ui/package.json
index 3c75a055ba..321c501518 100644
--- a/packages/sheets-thread-comment-ui/package.json
+++ b/packages/sheets-thread-comment-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-thread-comment": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
diff --git a/packages/sheets-ui/package.json b/packages/sheets-ui/package.json
index 605465d318..2c81d9c189 100644
--- a/packages/sheets-ui/package.json
+++ b/packages/sheets-ui/package.json
@@ -91,7 +91,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/protocol": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/telemetry": "workspace:*",
diff --git a/packages/sheets-ui/src/commands/commands/__tests__/command-behavior.spec.ts b/packages/sheets-ui/src/commands/commands/__tests__/command-behavior.spec.ts
deleted file mode 100644
index 580e8cb9d4..0000000000
--- a/packages/sheets-ui/src/commands/commands/__tests__/command-behavior.spec.ts
+++ /dev/null
@@ -1,612 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 {
- EDITOR_ACTIVATED,
- ICommandService,
- IConfigService,
- IConfirmService,
- IContextService,
- IUndoRedoService,
- IUniverInstanceService,
- LocaleService,
- ThemeService,
-} from '@univerjs/core';
-import {
- SetInlineFormatBoldCommand,
- SetInlineFormatFontFamilyCommand,
- SetInlineFormatFontSizeCommand,
- SetInlineFormatItalicCommand,
- SetInlineFormatStrikethroughCommand,
- SetInlineFormatSubscriptCommand,
- SetInlineFormatSuperscriptCommand,
- SetInlineFormatTextColorCommand,
- SetInlineFormatUnderlineCommand,
-} from '@univerjs/docs-ui';
-import { IRenderManagerService } from '@univerjs/engine-render';
-import {
- AddRangeProtectionMutation,
- AddWorksheetProtectionCommand,
- DeleteRangeProtectionMutation,
- DeleteWorksheetProtectionCommand,
- RangeProtectionRuleModel,
- RemoveSheetCommand,
- SetBoldCommand,
- SetFontFamilyCommand,
- SetFontSizeCommand,
- SetItalicCommand,
- SetStrikeThroughCommand,
- SetTextColorCommand,
- SetUnderlineCommand,
- SheetsSelectionsService,
- WorksheetProtectionRuleModel,
-} from '@univerjs/sheets';
-import { describe, expect, it, vi } from 'vitest';
-import { SHEET_VIEW_KEY, SHEET_ZOOM_RANGE } from '../../../common/keys';
-import { AutoWidthController } from '../../../controllers/auto-width.controller';
-import * as menuUtils from '../../../menu/utils';
-import { IEditorBridgeService } from '../../../services/editor-bridge.service';
-import { ISheetBarService } from '../../../services/sheet-bar/sheet-bar.service';
-import { SetScrollOperation } from '../../operations/scroll.operation';
-import { SetZoomRatioOperation } from '../../operations/set-zoom-ratio.operation';
-import { SheetPermissionOpenPanelOperation } from '../../operations/sheet-permission-open-panel.operation';
-import { SetColumnHeaderHeightCommand, SetRowHeaderWidthCommand } from '../headersize-changed.command';
-import {
- ResetRangeTextColorCommand,
- SetRangeBoldCommand,
- SetRangeFontDecreaseCommand,
- SetRangeFontFamilyCommand,
- SetRangeFontIncreaseCommand,
- SetRangeFontSizeCommand,
- SetRangeItalicCommand,
- SetRangeStrickThroughCommand,
- SetRangeSubscriptCommand,
- SetRangeSuperscriptCommand,
- SetRangeTextColorCommand,
- SetRangeUnderlineCommand,
-} from '../inline-format.command';
-import {
- AddRangeProtectionFromContextMenuCommand,
- AddRangeProtectionFromSheetBarCommand,
- AddRangeProtectionFromToolbarCommand,
- DeleteRangeProtectionFromContextMenuCommand,
- SetRangeProtectionFromContextMenuCommand,
- ViewSheetPermissionFromContextMenuCommand,
- ViewSheetPermissionFromSheetBarCommand,
-} from '../range-protection.command';
-import { RemoveSheetConfirmCommand } from '../remove-sheet-confirm.command';
-import { ResetScrollCommand, ScrollCommand, ScrollToCellCommand, SetScrollRelativeCommand } from '../set-scroll.command';
-import { SetWorksheetColAutoWidthCommand } from '../set-worksheet-auto-col-width.command';
-import { ChangeZoomRatioCommand, SetZoomRatioCommand } from '../set-zoom-ratio.command';
-import { ShowMenuListCommand } from '../unhide.command';
-import {
- ChangeSheetProtectionFromSheetBarCommand,
- DeleteWorksheetProtectionFormSheetBarCommand,
-} from '../worksheet-protection.command';
-
-function createAccessor(pairs: Array<[unknown, unknown]>) {
- const map = new Map<unknown, unknown>(pairs);
- return {
- get(token: unknown) {
- if (!map.has(token)) {
- throw new Error(`Unknown token: ${String(token)}`);
- }
- return map.get(token);
- },
- has(token: unknown) {
- return map.has(token);
- },
- } as any;
-}
-
-describe('sheets-ui command behaviors', () => {
- it('routes inline-format commands according to editor focus', async () => {
- const executeCommand = vi.fn(async () => true);
- const getContextValue = vi.fn((key: unknown) => key === EDITOR_ACTIVATED);
- const commandService = { executeCommand };
- const contextService = { getContextValue };
- const baseAccessor = createAccessor([
- [ICommandService, commandService],
- [IContextService, contextService],
- [ThemeService, { getColorFromTheme: vi.fn(() => '#111111') }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getActiveSheet: () => ({ getComposedCellStyle: () => ({ fs: 9 }) }) }) }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => ({ primary: { startRow: 0, startColumn: 0 } }) }],
- ]);
-
- await SetRangeBoldCommand.handler(baseAccessor, undefined as any);
- await SetRangeItalicCommand.handler(baseAccessor, undefined as any);
- await SetRangeUnderlineCommand.handler(baseAccessor, undefined as any);
- await SetRangeStrickThroughCommand.handler(baseAccessor, undefined as any);
- await SetRangeSubscriptCommand.handler(baseAccessor, undefined as any);
- await SetRangeSuperscriptCommand.handler(baseAccessor, undefined as any);
- await SetRangeFontSizeCommand.handler(baseAccessor, { value: 10 } as any);
- await SetRangeFontFamilyCommand.handler(baseAccessor, { value: 'Arial' } as any);
- await SetRangeTextColorCommand.handler(baseAccessor, { value: '#fff' } as any);
- await ResetRangeTextColorCommand.handler(baseAccessor, undefined as any);
-
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatBoldCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatItalicCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatUnderlineCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatStrikethroughCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatSubscriptCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatSuperscriptCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatFontSizeCommand.id, { value: 10 });
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatFontFamilyCommand.id, { value: 'Arial' });
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatTextColorCommand.id, { value: '#fff' });
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatTextColorCommand.id, { value: null });
- });
-
- it('routes inline-format commands to sheet commands in non-editor mode', async () => {
- const executeCommand = vi.fn(async () => true);
- const commandService = { executeCommand };
- const contextService = { getContextValue: vi.fn(() => false) };
- const baseAccessor = createAccessor([
- [ICommandService, commandService],
- [IContextService, contextService],
- [ThemeService, { getColorFromTheme: vi.fn(() => '#000000') }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getActiveSheet: () => ({ getComposedCellStyle: () => ({ fs: 12 }) }) }) }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => ({ primary: { startRow: 0, startColumn: 0 } }) }],
- ]);
-
- await SetRangeBoldCommand.handler(baseAccessor, undefined as any);
- await SetRangeItalicCommand.handler(baseAccessor, undefined as any);
- await SetRangeUnderlineCommand.handler(baseAccessor, undefined as any);
- await SetRangeStrickThroughCommand.handler(baseAccessor, undefined as any);
- await SetRangeFontSizeCommand.handler(baseAccessor, { value: 14 } as any);
- await SetRangeFontFamilyCommand.handler(baseAccessor, { value: 'Times New Roman' } as any);
- await SetRangeTextColorCommand.handler(baseAccessor, { value: '#123456' } as any);
- await ResetRangeTextColorCommand.handler(baseAccessor, undefined as any);
-
- expect(executeCommand).toHaveBeenCalledWith(SetBoldCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetItalicCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetUnderlineCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetStrikeThroughCommand.id);
- expect(executeCommand).toHaveBeenCalledWith(SetFontSizeCommand.id, { value: 14 });
- expect(executeCommand).toHaveBeenCalledWith(SetFontFamilyCommand.id, { value: 'Times New Roman' });
- expect(executeCommand).toHaveBeenCalledWith(SetTextColorCommand.id, { value: '#123456' });
- expect(executeCommand).toHaveBeenCalledWith(SetTextColorCommand.id, { value: '#000000' });
- });
-
- it('returns false for subscript/superscript when not in editor mode', async () => {
- const accessor = createAccessor([
- [ICommandService, { executeCommand: vi.fn(async () => true) }],
- [IContextService, { getContextValue: vi.fn(() => false) }],
- ]);
-
- expect(await SetRangeSubscriptCommand.handler(accessor, undefined as any)).toBe(false);
- expect(await SetRangeSuperscriptCommand.handler(accessor, undefined as any)).toBe(false);
- });
-
- it('handles font increase/decrease bounds and empty selection', async () => {
- const executeCommand = vi.fn(async () => true);
- const getFontStyleAtCursor = vi.spyOn(menuUtils, 'getFontStyleAtCursor');
-
- getFontStyleAtCursor.mockReturnValueOnce({ ts: { fs: 400 } } as any);
- const increaseInEditorAccessor = createAccessor([
- [ICommandService, { executeCommand }],
- [IContextService, { getContextValue: vi.fn((key: unknown) => key === EDITOR_ACTIVATED) }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getActiveSheet: () => ({ getComposedCellStyle: () => ({ fs: 11 }) }) }) }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => ({ primary: { startRow: 1, startColumn: 1 } }) }],
- ]);
-
- expect(await SetRangeFontIncreaseCommand.handler(increaseInEditorAccessor, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SetInlineFormatFontSizeCommand.id, { value: 400 });
-
- const decreaseInCellAccessor = createAccessor([
- [ICommandService, { executeCommand }],
- [IContextService, { getContextValue: vi.fn(() => false) }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getActiveSheet: () => ({ getComposedCellStyle: () => ({ fs: 6 }) }) }) }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => ({ primary: { startRow: 2, startColumn: 2 } }) }],
- ]);
-
- expect(await SetRangeFontDecreaseCommand.handler(decreaseInCellAccessor, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SetFontSizeCommand.id, { value: 6 });
-
- const noSelectionAccessor = createAccessor([
- [ICommandService, { executeCommand }],
- [IContextService, { getContextValue: vi.fn(() => false) }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getActiveSheet: () => ({ getComposedCellStyle: () => ({ fs: 10 }) }) }) }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => null }],
- ]);
- expect(await SetRangeFontIncreaseCommand.handler(noSelectionAccessor, undefined as any)).toBe(false);
- });
-
- it('updates header sizes and custom header components', async () => {
- const rowHeader = { setCustomHeader: vi.fn() };
- const colHeader = { setCustomHeader: vi.fn() };
- const setRowHeaderSize = vi.fn();
- const setColumnHeaderSize = vi.fn();
- const render = {
- with: vi.fn(() => ({ setRowHeaderSize, setColumnHeaderSize })),
- components: new Map([
- [SHEET_VIEW_KEY.ROW, rowHeader],
- [SHEET_VIEW_KEY.COLUMN, colHeader],
- ]),
- };
- const renderManager = { getRenderById: vi.fn(() => render) };
- const accessor = createAccessor([[IRenderManagerService, renderManager]]);
-
- expect(await SetRowHeaderWidthCommand.handler(accessor, { unitId: 'u1', subUnitId: 's1', size: 32 })).toBe(true);
- expect(await SetColumnHeaderHeightCommand.handler(accessor, { unitId: 'u1', subUnitId: 's1', size: 26 })).toBe(true);
- expect(setRowHeaderSize).toHaveBeenCalledWith(render, 's1', 32);
- expect(setColumnHeaderSize).toHaveBeenCalledWith(render, 's1', 26);
- expect(rowHeader.setCustomHeader).toHaveBeenCalledWith({ headerStyle: { size: 32 } }, 's1');
- expect(colHeader.setCustomHeader).toHaveBeenCalledWith({ headerStyle: { size: 26 } }, 's1');
- });
-
- it('guards header-size commands when params or render manager are missing', async () => {
- const accessor = createAccessor([[IRenderManagerService, null]]);
- expect(await SetRowHeaderWidthCommand.handler(accessor, undefined as any)).toBe(false);
- expect(await SetColumnHeaderHeightCommand.handler(accessor, undefined as any)).toBe(false);
- });
-
- it('handles scroll commands with target and fallback branches', async () => {
- const executeCommand = vi.fn(async () => true);
- const syncExecuteCommand = vi.fn(() => true);
- const worksheet = { getSheetId: () => 'sheet-1', getConfig: () => ({ freeze: { xSplit: 2, ySplit: 1 } }) };
- const workbook = {
- getUnitId: () => 'unit-1',
- getActiveSheet: () => worksheet,
- getSheetBySheetId: (sheetId: string) => sheetId === 'sheet-1' ? worksheet : undefined,
- };
- const embeddedWorksheet = { getSheetId: () => 'embedded-sheet', getConfig: () => ({ freeze: { xSplit: 0, ySplit: 0 } }) };
- const embeddedWorkbook = {
- getUnitId: () => 'embedded-unit',
- getActiveSheet: () => embeddedWorksheet,
- getSheetBySheetId: (sheetId: string) => sheetId === 'embedded-sheet' ? embeddedWorksheet : undefined,
- };
- const renderManager = {
- getRenderById: vi.fn(() => ({
- with: vi.fn(() => ({
- getCurrentScrollState: () => ({
- sheetViewStartRow: 4,
- sheetViewStartColumn: 5,
- offsetX: 12,
- offsetY: 30,
- }),
- })),
- })),
- };
- const univerInstanceService = {
- getCurrentUnitOfType: () => workbook,
- getUnit: (unitId: string) => unitId === 'embedded-unit' ? embeddedWorkbook : undefined,
- };
-
- const accessor = createAccessor([
- [ICommandService, { executeCommand, syncExecuteCommand }],
- [IUniverInstanceService, univerInstanceService],
- [IRenderManagerService, renderManager],
- ]);
-
- expect(await SetScrollRelativeCommand.handler(accessor, { offsetX: -2, offsetY: 5 })).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SetScrollOperation.id, expect.objectContaining({
- unitId: 'unit-1',
- sheetId: 'sheet-1',
- offsetX: 10,
- offsetY: 35,
- sheetViewStartRow: 4,
- sheetViewStartColumn: 5,
- }));
-
- expect(ScrollCommand.handler(accessor, { offsetX: 66 } as any)).toBe(true);
- expect(syncExecuteCommand).toHaveBeenCalledWith(SetScrollOperation.id, expect.objectContaining({
- unitId: 'unit-1',
- sheetId: 'sheet-1',
- sheetViewStartRow: 4,
- sheetViewStartColumn: 5,
- offsetX: 66,
- offsetY: 30,
- }));
-
- expect(ScrollCommand.handler(accessor, { unitId: 'embedded-unit', sheetId: 'embedded-sheet', offsetX: 7 } as any)).toBe(true);
- expect(renderManager.getRenderById).toHaveBeenLastCalledWith('embedded-unit');
- expect(syncExecuteCommand).toHaveBeenCalledWith(SetScrollOperation.id, expect.objectContaining({
- unitId: 'embedded-unit',
- sheetId: 'embedded-sheet',
- offsetX: 7,
- }));
-
- const scrollToRange = vi.fn(() => true);
- const scrollAccessor = createAccessor([
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getUnitId: () => 'unit-1' }) }],
- [IRenderManagerService, { getRenderById: () => ({ with: () => ({ scrollToRange }) }) }],
- ]);
- expect(ScrollToCellCommand.handler(scrollAccessor, { range: { startRow: 1, endRow: 1, startColumn: 2, endColumn: 2 } as any })).toBe(true);
- expect(scrollToRange).toHaveBeenCalledWith({ startRow: 1, endRow: 1, startColumn: 2, endColumn: 2 }, undefined, undefined);
-
- expect(await ResetScrollCommand.handler(accessor, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SetScrollOperation.id, {
- unitId: 'unit-1',
- sheetId: 'sheet-1',
- sheetViewStartRow: 0,
- sheetViewStartColumn: 0,
- });
- });
-
- it('guards scroll commands when params or targets are missing', async () => {
- const accessor = createAccessor([
- [ICommandService, { executeCommand: vi.fn(), syncExecuteCommand: vi.fn() }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => null }],
- [IRenderManagerService, { getRenderById: vi.fn() }],
- ]);
-
- expect(await SetScrollRelativeCommand.handler(accessor, { offsetX: 1, offsetY: 1 })).toBe(false);
- expect(ScrollCommand.handler(accessor, undefined as any)).toBe(false);
- expect(ScrollCommand.handler(accessor, { offsetY: 10 } as any)).toBe(false);
- expect(await ResetScrollCommand.handler(accessor, undefined as any)).toBe(false);
- });
-
- it('handles zoom ratio commands with clamp and editor-visible guards', async () => {
- const executeCommand = vi.fn(() => true);
- const worksheet = {
- getSheetId: () => 'sheet-1',
- getConfig: () => ({ zoomRatio: 4 }),
- };
- const workbook = {
- getUnitId: () => 'unit-1',
- getActiveSheet: () => worksheet,
- };
- const accessor = createAccessor([
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- [ICommandService, { executeCommand }],
- [IEditorBridgeService, { isVisible: () => ({ visible: false, unitId: 'other' }) }],
- ]);
-
- expect(ChangeZoomRatioCommand.handler(accessor, { delta: 0.5 })).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SetZoomRatioOperation.id, {
- unitId: 'unit-1',
- subUnitId: 'sheet-1',
- zoomRatio: SHEET_ZOOM_RANGE[1] / 100,
- });
-
- expect(SetZoomRatioCommand.handler(accessor, { unitId: 'unit-1', subUnitId: 'sheet-1', zoomRatio: 1.25 })).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SetZoomRatioOperation.id, {
- unitId: 'unit-1',
- subUnitId: 'sheet-1',
- zoomRatio: 1.25,
- });
-
- const hiddenByEditorAccessor = createAccessor([
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- [ICommandService, { executeCommand }],
- [IEditorBridgeService, { isVisible: () => ({ visible: true, unitId: 'unit-1' }) }],
- ]);
- expect(ChangeZoomRatioCommand.handler(hiddenByEditorAccessor, { delta: -0.1 })).toBe(false);
- expect(SetZoomRatioCommand.handler(hiddenByEditorAccessor, { unitId: 'unit-1', subUnitId: 'sheet-1', zoomRatio: 1 })).toBe(false);
- });
-
- it('guards zoom commands for invalid params or missing targets', () => {
- const accessor = createAccessor([
- [IUniverInstanceService, { getCurrentUnitOfType: () => null }],
- [ICommandService, { executeCommand: vi.fn() }],
- [IEditorBridgeService, { isVisible: () => ({ visible: false, unitId: 'none' }) }],
- ]);
- expect(ChangeZoomRatioCommand.handler(accessor, undefined as any)).toBe(false);
- expect(ChangeZoomRatioCommand.handler(accessor, { delta: 0.1 })).toBe(false);
- expect(SetZoomRatioCommand.handler(accessor, undefined as any)).toBe(false);
- });
-
- it('executes auto-width command with undo/redo and guards empty ranges', () => {
- const syncExecuteCommand = vi.fn(() => true);
- const pushUndoRedo = vi.fn();
- const accessor = createAccessor([
- [ICommandService, { syncExecuteCommand }],
- [IUndoRedoService, { pushUndoRedo }],
- [SheetsSelectionsService, {
- getCurrentSelections: () => [{ range: { startRow: 0, endRow: 1, startColumn: 0, endColumn: 1 } }],
- }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getUnitId: () => 'unit-1', getActiveSheet: () => ({ getSheetId: () => 'sheet-1' }) }) }],
- [AutoWidthController, {
- getUndoRedoParamsOfColWidth: vi.fn(() => ({
- redos: [{ id: 'redo-1', params: { a: 1 } }],
- undos: [{ id: 'undo-1', params: { b: 2 } }],
- })),
- }],
- ]);
-
- expect(SetWorksheetColAutoWidthCommand.handler(accessor, undefined as any)).toBe(true);
- expect(syncExecuteCommand).toHaveBeenCalledWith('redo-1', { a: 1 }, undefined);
- expect(pushUndoRedo).toHaveBeenCalledWith({
- unitID: 'unit-1',
- undoMutations: [{ id: 'undo-1', params: { b: 2 } }],
- redoMutations: [{ id: 'redo-1', params: { a: 1 } }],
- });
-
- const emptySelectionAccessor = createAccessor([
- [ICommandService, { syncExecuteCommand: vi.fn(() => true) }],
- [IUndoRedoService, { pushUndoRedo: vi.fn() }],
- [SheetsSelectionsService, { getCurrentSelections: () => [] }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getUnitId: () => 'unit-1', getActiveSheet: () => ({ getSheetId: () => 'sheet-1' }) }) }],
- [AutoWidthController, { getUndoRedoParamsOfColWidth: vi.fn(() => ({ redos: [], undos: [] })) }],
- ]);
- expect(SetWorksheetColAutoWidthCommand.handler(emptySelectionAccessor, undefined as any)).toBe(false);
- });
-
- it('handles remove-sheet confirmation for both confirm and cancel', async () => {
- const executeCommand = vi.fn(async () => true);
- const confirm = vi.fn()
- .mockResolvedValueOnce(false)
- .mockResolvedValueOnce(true);
- const worksheet = {
- getCellMatrix: () => ({
- forEach: (fn: (...args: unknown[]) => void) => {
- fn();
- fn();
- },
- }),
- getSheetId: () => 'sheet-1',
- };
- const workbook = {
- getUnitId: () => 'unit-1',
- getSheetBySheetId: (subUnitId: string) => (subUnitId === 'sheet-1' ? worksheet : null),
- };
-
- const accessor = createAccessor([
- [IConfirmService, { confirm }],
- [ICommandService, { executeCommand }],
- [LocaleService, { t: (key: string) => key }],
- [IConfigService, { getConfig: () => ({ largeSheetOperation: { largeSheetCellCountThreshold: 1 } }) }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- ]);
-
- expect(await RemoveSheetConfirmCommand.handler(accessor, { subUnitId: 'sheet-1' } as any)).toBe(false);
- expect(await RemoveSheetConfirmCommand.handler(accessor, { subUnitId: 'sheet-1' } as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(RemoveSheetCommand.id, { subUnitId: 'sheet-1' });
- });
-
- it('guards remove-sheet command when target sheet is missing', async () => {
- const accessor = createAccessor([
- [IConfirmService, { confirm: vi.fn() }],
- [ICommandService, { executeCommand: vi.fn() }],
- [LocaleService, { t: (key: string) => key }],
- [IConfigService, { getConfig: () => ({}) }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => null }],
- ]);
- expect(await RemoveSheetConfirmCommand.handler(accessor, { subUnitId: 'sheet-1' } as any)).toBe(false);
- });
-
- it('handles worksheet protection commands', async () => {
- const executeCommand = vi.fn()
- .mockResolvedValueOnce(true)
- .mockResolvedValueOnce(true);
- const pushUndoRedo = vi.fn();
- const worksheet = { getSheetId: () => 'sheet-1' };
- const workbook = {
- getUnitId: () => 'unit-1',
- getActiveSheet: () => worksheet,
- };
- const accessor = createAccessor([
- [ICommandService, { executeCommand }],
- [IUndoRedoService, { pushUndoRedo }],
- [WorksheetProtectionRuleModel, { getRule: () => ({ permissionId: 'perm-1' }) }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- ]);
-
- expect(await DeleteWorksheetProtectionFormSheetBarCommand.handler(accessor, { ok: true } as any)).toBe(true);
- expect(pushUndoRedo).toHaveBeenCalledWith({
- unitID: 'unit-1',
- redoMutations: [{ id: DeleteWorksheetProtectionCommand.id, params: { unitId: 'unit-1', subUnitId: 'sheet-1' } }],
- undoMutations: [{ id: AddWorksheetProtectionCommand.id, params: { unitId: 'unit-1', rule: { permissionId: 'perm-1' } } }],
- });
-
- expect(await ChangeSheetProtectionFromSheetBarCommand.handler(accessor, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith('sheet-permission.operation.openDialog');
-
- const noWorksheetAccessor = createAccessor([
- [ICommandService, { executeCommand: vi.fn() }],
- [IUndoRedoService, { pushUndoRedo: vi.fn() }],
- [WorksheetProtectionRuleModel, { getRule: vi.fn() }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => ({ getUnitId: () => 'unit-1', getActiveSheet: () => null }) }],
- ]);
- expect(await DeleteWorksheetProtectionFormSheetBarCommand.handler(noWorksheetAccessor, { ok: true } as any)).toBe(false);
- expect(await DeleteWorksheetProtectionFormSheetBarCommand.handler(noWorksheetAccessor, undefined as any)).toBe(false);
- });
-
- it('opens and deletes range protection from toolbar/context/sheet-bar', async () => {
- const executeCommand = vi.fn(async () => true);
- const accessor = createAccessor([[ICommandService, { executeCommand }]]);
-
- expect(await AddRangeProtectionFromToolbarCommand.handler(accessor, undefined as any)).toBe(true);
- expect(await AddRangeProtectionFromContextMenuCommand.handler(accessor, undefined as any)).toBe(true);
- expect(await ViewSheetPermissionFromContextMenuCommand.handler(accessor, undefined as any)).toBe(true);
- expect(await AddRangeProtectionFromSheetBarCommand.handler(accessor, undefined as any)).toBe(true);
- expect(await ViewSheetPermissionFromSheetBarCommand.handler(accessor, undefined as any)).toBe(true);
-
- expect(executeCommand).toHaveBeenCalledWith(SheetPermissionOpenPanelOperation.id, { showDetail: true });
- expect(executeCommand).toHaveBeenCalledWith(SheetPermissionOpenPanelOperation.id, { showDetail: false });
- expect(executeCommand).toHaveBeenCalledWith(SheetPermissionOpenPanelOperation.id, { fromSheetBar: true, showDetail: true });
- });
-
- it('handles delete/set range protection command branches', async () => {
- const executeCommand = vi.fn()
- .mockResolvedValueOnce(true)
- .mockResolvedValueOnce(true)
- .mockResolvedValueOnce(true)
- .mockResolvedValueOnce(true);
- const pushUndoRedo = vi.fn();
- const worksheet = { getSheetId: () => 'sheet-1' };
- const workbook = { getUnitId: () => 'unit-1', getActiveSheet: () => worksheet };
- const overlapRule = {
- id: 'rule-1',
- permissionId: 'perm-1',
- ranges: [{ startRow: 1, endRow: 3, startColumn: 1, endColumn: 3 }],
- };
-
- const accessorWithWorksheetRule = createAccessor([
- [ICommandService, { executeCommand }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- [IUndoRedoService, { pushUndoRedo }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => ({ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }) }],
- [WorksheetProtectionRuleModel, { getRule: () => ({ permissionId: 'sheet-perm' }) }],
- [RangeProtectionRuleModel, { getSubunitRuleList: () => [overlapRule] }],
- ]);
-
- expect(await DeleteRangeProtectionFromContextMenuCommand.handler(accessorWithWorksheetRule, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(DeleteWorksheetProtectionCommand.id, {
- unitId: 'unit-1',
- subUnitId: 'sheet-1',
- rule: { permissionId: 'sheet-perm' },
- });
-
- expect(await SetRangeProtectionFromContextMenuCommand.handler(accessorWithWorksheetRule, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(SheetPermissionOpenPanelOperation.id, expect.objectContaining({
- showDetail: true,
- rule: expect.objectContaining({ unitId: 'unit-1', subUnitId: 'sheet-1' }),
- }));
-
- const accessorWithRangeRule = createAccessor([
- [ICommandService, { executeCommand }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- [IUndoRedoService, { pushUndoRedo }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => ({ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }) }],
- [WorksheetProtectionRuleModel, { getRule: () => null }],
- [RangeProtectionRuleModel, { getSubunitRuleList: () => [overlapRule] }],
- ]);
-
- expect(await DeleteRangeProtectionFromContextMenuCommand.handler(accessorWithRangeRule, undefined as any)).toBe(true);
- expect(executeCommand).toHaveBeenCalledWith(DeleteRangeProtectionMutation.id, {
- unitId: 'unit-1',
- subUnitId: 'sheet-1',
- ruleIds: ['rule-1'],
- });
- expect(pushUndoRedo).toHaveBeenCalledWith(expect.objectContaining({
- unitID: 'unit-1',
- redoMutations: [{ id: DeleteRangeProtectionMutation.id, params: { unitId: 'unit-1', subUnitId: 'sheet-1', ruleIds: ['rule-1'] } }],
- undoMutations: [{ id: AddRangeProtectionMutation.id, params: { unitId: 'unit-1', subUnitId: 'sheet-1', rules: [overlapRule] } }],
- }));
-
- expect(await SetRangeProtectionFromContextMenuCommand.handler(accessorWithRangeRule, undefined as any)).toBe(true);
-
- const accessorNoSelection = createAccessor([
- [ICommandService, { executeCommand }],
- [IUniverInstanceService, { getCurrentUnitOfType: () => workbook }],
- [IUndoRedoService, { pushUndoRedo }],
- [SheetsSelectionsService, { getCurrentLastSelection: () => null }],
- [WorksheetProtectionRuleModel, { getRule: () => null }],
- [RangeProtectionRuleModel, { getSubunitRuleList: () => [] }],
- ]);
-
- expect(await DeleteRangeProtectionFromContextMenuCommand.handler(accessorNoSelection, undefined as any)).toBe(false);
- expect(await SetRangeProtectionFromContextMenuCommand.handler(accessorNoSelection, undefined as any)).toBe(false);
- });
-
- it('handles show-menu-list command', async () => {
- const triggerSheetBarMenu = vi.fn();
- const accessor = createAccessor([[ISheetBarService, { triggerSheetBarMenu }]]);
- expect(await ShowMenuListCommand.handler(accessor)).toBe(true);
- expect(triggerSheetBarMenu).toHaveBeenCalledTimes(1);
- });
-});
diff --git a/packages/sheets-ui/src/commands/commands/set-zoom-ratio-from-toolbar.command.ts b/packages/sheets-ui/src/commands/commands/set-zoom-ratio-from-toolbar.command.ts
new file mode 100644
index 0000000000..3dcf677c7e
--- /dev/null
+++ b/packages/sheets-ui/src/commands/commands/set-zoom-ratio-from-toolbar.command.ts
@@ -0,0 +1,43 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { ICommand } from '@univerjs/core';
+import { CommandType, ICommandService, IUniverInstanceService } from '@univerjs/core';
+import { getSheetCommandTarget } from '@univerjs/sheets';
+import { SHEET_ZOOM_RANGE } from '../../common/keys';
+import { SetZoomRatioCommand } from './set-zoom-ratio.command';
+
+export interface ISetZoomRatioFromToolbarCommandParams {
+ value: number;
+}
+
+export const SetZoomRatioFromToolbarCommand: ICommand<ISetZoomRatioFromToolbarCommandParams> = {
+ id: 'sheet.command.set-zoom-ratio-from-toolbar',
+ type: CommandType.COMMAND,
+ handler: (accessor, params) => {
+ if (!params || !Number.isFinite(params.value)) return false;
+
+ const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
+ if (!target) return false;
+
+ const zoom = Math.min(SHEET_ZOOM_RANGE[1], Math.max(SHEET_ZOOM_RANGE[0], params.value));
+ return accessor.get(ICommandService).executeCommand(SetZoomRatioCommand.id, {
+ unitId: target.unitId,
+ subUnitId: target.subUnitId,
+ zoomRatio: zoom / 100,
+ });
+ },
+};
diff --git a/packages/sheets-ui/src/controllers/components.controller.ts b/packages/sheets-ui/src/controllers/components.controller.ts
index df7d32367c..2931383301 100644
--- a/packages/sheets-ui/src/controllers/components.controller.ts
+++ b/packages/sheets-ui/src/controllers/components.controller.ts
@@ -52,7 +52,7 @@ import {
FreezeRowIcon,
FreezeToSelectedIcon,
HideDoubleIcon,
- HideGridlinesDoubleIcon,
+ HideGridlinesIcon,
HorizontalBorderDoubleIcon,
HorizontallyIcon,
HorizontalMergeIcon,
@@ -123,6 +123,7 @@ import { MENU_ITEM_INPUT_COMPONENT, MenuItemInput } from '../views/menu-item-inp
import { SheetPermissionDialog, SheetPermissionPanel, SheetPermissionUserDialog } from '../views/permission';
import { AlertDialog } from '../views/permission/AlertDialog';
import { UNIVER_SHEET_PERMISSION_ALERT_DIALOG } from '../views/permission/error-msg-dialog/interface';
+import { SHEET_ZOOM_INPUT_COMPONENT, SheetZoomInput } from '../views/sheet-slider/SheetZoomInput';
export class ComponentsController extends Disposable {
constructor(
@@ -173,6 +174,7 @@ export class ComponentsController extends Disposable {
// init custom components
this.disposeWithMe(componentManager.register(MENU_ITEM_INPUT_COMPONENT, MenuItemInput));
this.disposeWithMe(componentManager.register(MENU_ITEM_FROZEN_COMPONENT, MenuItemFrozen));
+ this.disposeWithMe(componentManager.register(SHEET_ZOOM_INPUT_COMPONENT, SheetZoomInput));
this.disposeWithMe(componentManager.register(BORDER_PANEL_COMPONENT, BorderPanel));
this.disposeWithMe(componentManager.register(DEFINED_NAME_CONTAINER, DefinedNameContainer));
this.disposeWithMe(componentManager.register(CELL_POPUP_COMPONENT_KEY, CellPopup));
@@ -225,7 +227,7 @@ export class ComponentsController extends Disposable {
FreezeRowIcon,
FreezeToSelectedIcon,
HideDoubleIcon,
- HideGridlinesDoubleIcon,
+ HideGridlinesIcon,
HorizontalBorderDoubleIcon,
HorizontalMergeIcon,
HorizontallyIcon,
@@ -260,8 +262,8 @@ export class ComponentsController extends Disposable {
RightJustifyingIcon,
RightRotationFortyFiveDegreesIcon,
RightRotationNinetyDegreesIcon,
- SlashDoubleIcon,
ShrinkToFitIcon,
+ SlashDoubleIcon,
StrikethroughIcon,
SubscriptIcon,
SuperscriptIcon,
diff --git a/packages/sheets-ui/src/controllers/ui.controller.ts b/packages/sheets-ui/src/controllers/ui.controller.ts
index 32de97af77..0ad6ef7618 100644
--- a/packages/sheets-ui/src/controllers/ui.controller.ts
+++ b/packages/sheets-ui/src/controllers/ui.controller.ts
@@ -79,6 +79,7 @@ import {
SelectAllCommand,
} from '../commands/commands/set-selection.command';
import { SetWorksheetColAutoWidthCommand } from '../commands/commands/set-worksheet-auto-col-width.command';
+import { SetZoomRatioFromToolbarCommand } from '../commands/commands/set-zoom-ratio-from-toolbar.command';
import { ChangeZoomRatioCommand, SetZoomRatioCommand } from '../commands/commands/set-zoom-ratio.command';
import { ShowMenuListCommand } from '../commands/commands/unhide.command';
import { ChangeSheetProtectionFromSheetBarCommand, DeleteWorksheetProtectionFormSheetBarCommand } from '../commands/commands/worksheet-protection.command';
@@ -228,6 +229,7 @@ export class SheetUIController extends Disposable {
SetFirstColumnFrozenCommand,
ScrollToRangeOperation,
SetUnderlineCommand,
+ SetZoomRatioFromToolbarCommand,
SetZoomRatioCommand,
SetZoomRatioOperation,
ShowMenuListCommand,
diff --git a/packages/sheets-ui/src/locale/ar-SA.ts b/packages/sheets-ui/src/locale/ar-SA.ts
index a32887ddf2..cb56916c89 100644
--- a/packages/sheets-ui/src/locale/ar-SA.ts
+++ b/packages/sheets-ui/src/locale/ar-SA.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'المزيد',
toggleGridlines: 'تبديل خطوط الشبكة',
+ fullscreen: 'ملء الشاشة',
},
align: {
left: 'يسار',
diff --git a/packages/sheets-ui/src/locale/ca-ES.ts b/packages/sheets-ui/src/locale/ca-ES.ts
index 0f9e5e6d99..98b371ba22 100644
--- a/packages/sheets-ui/src/locale/ca-ES.ts
+++ b/packages/sheets-ui/src/locale/ca-ES.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Més',
toggleGridlines: 'Alternar línies de quadrícula',
+ fullscreen: 'Pantalla completa',
},
align: {
left: 'esquerra',
diff --git a/packages/sheets-ui/src/locale/de-DE.ts b/packages/sheets-ui/src/locale/de-DE.ts
index 827e029518..9eb5441780 100644
--- a/packages/sheets-ui/src/locale/de-DE.ts
+++ b/packages/sheets-ui/src/locale/de-DE.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Mehr',
toggleGridlines: 'Gitterlinien ein-/ausblenden',
+ fullscreen: 'Vollbild',
},
align: {
left: 'links',
diff --git a/packages/sheets-ui/src/locale/en-US.ts b/packages/sheets-ui/src/locale/en-US.ts
index 4812c1f264..af5baa869b 100644
--- a/packages/sheets-ui/src/locale/en-US.ts
+++ b/packages/sheets-ui/src/locale/en-US.ts
@@ -66,6 +66,7 @@ const locale = {
},
more: 'More',
toggleGridlines: 'Toggle Gridlines',
+ fullscreen: 'Fullscreen',
},
align: {
left: 'left',
diff --git a/packages/sheets-ui/src/locale/es-ES.ts b/packages/sheets-ui/src/locale/es-ES.ts
index 684e83309d..f41ce5d0ce 100644
--- a/packages/sheets-ui/src/locale/es-ES.ts
+++ b/packages/sheets-ui/src/locale/es-ES.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Más',
toggleGridlines: 'Alternar líneas de cuadrícula',
+ fullscreen: 'Pantalla completa',
},
align: {
left: 'izquierda',
diff --git a/packages/sheets-ui/src/locale/fa-IR.ts b/packages/sheets-ui/src/locale/fa-IR.ts
index 60edfa0f6f..3cc35a8e3c 100644
--- a/packages/sheets-ui/src/locale/fa-IR.ts
+++ b/packages/sheets-ui/src/locale/fa-IR.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'بیشتر',
toggleGridlines: 'تغییر وضعیت خطوط شبکه',
+ fullscreen: 'تمام‌صفحه',
},
align: {
left: 'چپ',
diff --git a/packages/sheets-ui/src/locale/fr-FR.ts b/packages/sheets-ui/src/locale/fr-FR.ts
index c902da3da7..552f9f2948 100644
--- a/packages/sheets-ui/src/locale/fr-FR.ts
+++ b/packages/sheets-ui/src/locale/fr-FR.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Plus',
toggleGridlines: 'Activer/désactiver le quadrillage',
+ fullscreen: 'Plein écran',
},
align: {
left: 'gauche',
diff --git a/packages/sheets-ui/src/locale/id-ID.ts b/packages/sheets-ui/src/locale/id-ID.ts
index bb2bfe7e21..fe46acdd04 100644
--- a/packages/sheets-ui/src/locale/id-ID.ts
+++ b/packages/sheets-ui/src/locale/id-ID.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Lainnya',
toggleGridlines: 'Alihkan garis kisi',
+ fullscreen: 'Layar penuh',
},
align: {
left: 'kiri',
diff --git a/packages/sheets-ui/src/locale/it-IT.ts b/packages/sheets-ui/src/locale/it-IT.ts
index 1d7e1183d7..b838bbd328 100644
--- a/packages/sheets-ui/src/locale/it-IT.ts
+++ b/packages/sheets-ui/src/locale/it-IT.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Altro',
toggleGridlines: 'Mostra/Nascondi griglia',
+ fullscreen: 'Schermo intero',
},
align: {
left: 'sinistra',
diff --git a/packages/sheets-ui/src/locale/ja-JP.ts b/packages/sheets-ui/src/locale/ja-JP.ts
index 67d3116abc..10f86cce66 100644
--- a/packages/sheets-ui/src/locale/ja-JP.ts
+++ b/packages/sheets-ui/src/locale/ja-JP.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'その他',
toggleGridlines: 'グリッド線の表示/非表示',
+ fullscreen: '全画面表示',
},
align: {
left: '左寄せ',
diff --git a/packages/sheets-ui/src/locale/ko-KR.ts b/packages/sheets-ui/src/locale/ko-KR.ts
index fd7bb26eed..38f561cb81 100644
--- a/packages/sheets-ui/src/locale/ko-KR.ts
+++ b/packages/sheets-ui/src/locale/ko-KR.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: '더 보기',
toggleGridlines: '눈금선 표시/숨기기',
+ fullscreen: '전체 화면',
},
align: {
left: '왼쪽',
diff --git a/packages/sheets-ui/src/locale/pl-PL.ts b/packages/sheets-ui/src/locale/pl-PL.ts
index 578058d0f6..24299f9df2 100644
--- a/packages/sheets-ui/src/locale/pl-PL.ts
+++ b/packages/sheets-ui/src/locale/pl-PL.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Więcej',
toggleGridlines: 'Przełącz linie siatki',
+ fullscreen: 'Pełny ekran',
},
align: {
left: 'lewo',
diff --git a/packages/sheets-ui/src/locale/pt-BR.ts b/packages/sheets-ui/src/locale/pt-BR.ts
index 6af06c49d8..f3cb23129d 100644
--- a/packages/sheets-ui/src/locale/pt-BR.ts
+++ b/packages/sheets-ui/src/locale/pt-BR.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Mais',
toggleGridlines: 'Mostrar/Ocultar linhas de grade',
+ fullscreen: 'Tela cheia',
},
align: {
left: 'esquerda',
diff --git a/packages/sheets-ui/src/locale/ru-RU.ts b/packages/sheets-ui/src/locale/ru-RU.ts
index c5ef4d1a5f..041637a5df 100644
--- a/packages/sheets-ui/src/locale/ru-RU.ts
+++ b/packages/sheets-ui/src/locale/ru-RU.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Больше',
toggleGridlines: 'Переключить сетку',
+ fullscreen: 'Полноэкранный режим',
},
align: {
left: 'Лево',
diff --git a/packages/sheets-ui/src/locale/sk-SK.ts b/packages/sheets-ui/src/locale/sk-SK.ts
index 97f4e86da2..4646b040ab 100644
--- a/packages/sheets-ui/src/locale/sk-SK.ts
+++ b/packages/sheets-ui/src/locale/sk-SK.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Viac',
toggleGridlines: 'Prepnúť mriežku',
+ fullscreen: 'Celá obrazovka',
},
align: {
left: 'vľavo',
diff --git a/packages/sheets-ui/src/locale/vi-VN.ts b/packages/sheets-ui/src/locale/vi-VN.ts
index 19c40ab35f..06c68d8afc 100644
--- a/packages/sheets-ui/src/locale/vi-VN.ts
+++ b/packages/sheets-ui/src/locale/vi-VN.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: 'Thêm',
toggleGridlines: 'Chuyển đổi đường lưới',
+ fullscreen: 'Toàn màn hình',
},
align: {
left: 'Căn trái',
diff --git a/packages/sheets-ui/src/locale/zh-CN.ts b/packages/sheets-ui/src/locale/zh-CN.ts
index dc6e2bc955..b3a173464b 100644
--- a/packages/sheets-ui/src/locale/zh-CN.ts
+++ b/packages/sheets-ui/src/locale/zh-CN.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: '更多',
toggleGridlines: '切换网格线',
+ fullscreen: '全屏',
},
align: {
left: '左对齐',
diff --git a/packages/sheets-ui/src/locale/zh-HK.ts b/packages/sheets-ui/src/locale/zh-HK.ts
index a0c2093324..87162cf246 100644
--- a/packages/sheets-ui/src/locale/zh-HK.ts
+++ b/packages/sheets-ui/src/locale/zh-HK.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: '更多',
toggleGridlines: '切換網格線',
+ fullscreen: '全螢幕',
},
align: {
left: '靠左對齊',
diff --git a/packages/sheets-ui/src/locale/zh-TW.ts b/packages/sheets-ui/src/locale/zh-TW.ts
index a0c2093324..87162cf246 100644
--- a/packages/sheets-ui/src/locale/zh-TW.ts
+++ b/packages/sheets-ui/src/locale/zh-TW.ts
@@ -68,6 +68,7 @@ const locale: typeof enUS = {
},
more: '更多',
toggleGridlines: '切換網格線',
+ fullscreen: '全螢幕',
},
align: {
left: '靠左對齊',
diff --git a/packages/sheets-ui/src/menu/__tests__/create-menu-test-bed.ts b/packages/sheets-ui/src/menu/__tests__/create-menu-test-bed.ts
deleted file mode 100644
index 1114d0dfa2..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/create-menu-test-bed.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 { IWorkbookData } from '@univerjs/core';
-import { Inject, Injector, LocaleType, Plugin, Univer, UniverInstanceType } from '@univerjs/core';
-import { IRenderManagerService, RenderManagerService } from '@univerjs/engine-render';
-import {
- RangeProtectionCache,
- RangeProtectionRefRangeService,
- RangeProtectionRenderModel,
- RangeProtectionRuleModel,
- RangeProtectionService,
- RefRangeService,
- SheetInterceptorService,
- SheetSkeletonService,
- SheetsSelectionsService,
- WorkbookPermissionService,
- WorksheetPermissionService,
- WorksheetProtectionPointModel,
- WorksheetProtectionRuleModel,
-} from '@univerjs/sheets';
-import { IMenuManagerService, IPlatformService, IShortcutService, MenuManagerService, PlatformService, ShortcutService } from '@univerjs/ui';
-
-const TEST_WORKBOOK_DATA_DEMO: IWorkbookData = {
- id: 'test',
- appVersion: '3.0.0-alpha',
- sheets: {
- sheet1: {
- id: 'sheet1',
- cellData: {
- 0: {
- 0: {
- v: 'A1',
- },
- },
- },
- },
- },
- locale: LocaleType.ZH_CN,
- name: '',
- sheetOrder: [],
- styles: {},
-};
-
-export function createMenuTestBed() {
- const univer = new Univer();
- const injector = univer.__getInjector();
- const get = injector.get.bind(injector);
-
- class TestPlugin extends Plugin {
- static override pluginName = 'test-plugin';
-
- static override type = UniverInstanceType.UNIVER_SHEET;
-
- constructor(_config: unknown, @Inject(Injector) override readonly _injector: Injector) {
- super();
- }
-
- override onStarting(): void {
- const injector = this._injector;
- injector.add([IPlatformService, { useClass: PlatformService }]);
- injector.add([SheetsSelectionsService]);
- injector.add([IShortcutService, { useClass: ShortcutService }]);
- injector.add([IMenuManagerService, { useClass: MenuManagerService }]);
- injector.add([WorkbookPermissionService]);
- injector.add([WorksheetPermissionService]);
- injector.add([WorksheetProtectionPointModel]);
- injector.add([SheetInterceptorService]);
- injector.add([WorksheetProtectionRuleModel]);
- injector.add([IRenderManagerService, { useClass: RenderManagerService }]);
- injector.add([RefRangeService]);
-
- injector.add([RangeProtectionRefRangeService]);
- injector.add([RangeProtectionRenderModel]);
- injector.add([RangeProtectionCache]);
- injector.add([RangeProtectionRuleModel]);
- injector.add([RangeProtectionService]);
- injector.add([SheetSkeletonService]);
-
- this._injector.get(SheetInterceptorService);
- this._injector.get(WorkbookPermissionService);
- this._injector.get(WorksheetPermissionService);
- }
- }
-
- univer.registerPlugin(TestPlugin);
- const sheet = univer.createUnit(UniverInstanceType.UNIVER_SHEET, TEST_WORKBOOK_DATA_DEMO);
-
- return {
- univer,
- get,
- sheet,
- };
-}
diff --git a/packages/sheets-ui/src/menu/__tests__/menu-advanced.spec.ts b/packages/sheets-ui/src/menu/__tests__/menu-advanced.spec.ts
deleted file mode 100644
index a8775eaa73..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/menu-advanced.spec.ts
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 { Univer } from '@univerjs/core';
-import { ICommandService, Injector, RANGE_TYPE, ThemeService } from '@univerjs/core';
-import { SetRangeValuesMutation, SetSelectionsOperation, SheetsSelectionsService } from '@univerjs/sheets';
-import { firstValueFrom, take } from 'rxjs';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import {
- BackgroundColorSelectorMenuItemFactory,
- FontFamilySelectorMenuItemFactory,
- HorizontalAlignMenuItemFactory,
- ItalicMenuItemFactory,
- ShrinkToFitMenuItemFactory,
- StrikeThroughMenuItemFactory,
- TextColorSelectorMenuItemFactory,
- TextRotateMenuItemFactory,
- UnderlineMenuItemFactory,
- VerticalAlignMenuItemFactory,
- WrapTextMenuItemFactory,
-} from '../menu';
-import { createMenuTestBed } from './create-menu-test-bed';
-
-describe('advanced menu state streams', () => {
- let univer: Univer;
- let get: any;
- let commandService: ICommandService;
- let selectionService: SheetsSelectionsService;
-
- beforeEach(() => {
- const testBed = createMenuTestBed();
- univer = testBed.univer;
- get = testBed.get;
- commandService = get(ICommandService);
- selectionService = get(SheetsSelectionsService);
- commandService.registerCommand(SetSelectionsOperation);
- commandService.registerCommand(SetRangeValuesMutation);
- selectionService.setSelections([
- {
- range: { startRow: 0, startColumn: 0, endRow: 0, endColumn: 0, rangeType: RANGE_TYPE.NORMAL },
- primary: {
- startRow: 0,
- startColumn: 0,
- endRow: 0,
- endColumn: 0,
- actualRow: 0,
- actualColumn: 0,
- isMerged: false,
- isMergedMainCell: false,
- },
- style: null,
- },
- ]);
- });
-
- afterEach(() => {
- univer.dispose();
- });
-
- it('resolves formatting menu states from current cell', async () => {
- const injector = get(Injector);
- const italic = injector.invoke(ItalicMenuItemFactory);
- const underline = injector.invoke(UnderlineMenuItemFactory);
- const strike = injector.invoke(StrikeThroughMenuItemFactory);
- const fontFamily = injector.invoke(FontFamilySelectorMenuItemFactory);
-
- expect(await firstValueFrom(italic.activated$!.pipe(take(1)))).toBeTypeOf('boolean');
- expect(await firstValueFrom(underline.activated$!.pipe(take(1)))).toBeTypeOf('boolean');
- expect(await firstValueFrom(strike.activated$!.pipe(take(1)))).toBeTypeOf('boolean');
- expect(await firstValueFrom(fontFamily.value$!.pipe(take(1)))).toBeTypeOf('string');
- expect(await firstValueFrom(fontFamily.disabled$!.pipe(take(1)))).toBeTypeOf('boolean');
- });
-
- it('resolves color/alignment/wrap/rotation selector streams', async () => {
- const injector = get(Injector);
- const textColor = injector.invoke(TextColorSelectorMenuItemFactory);
- const bgColor = injector.invoke(BackgroundColorSelectorMenuItemFactory);
- const horizontal = injector.invoke(HorizontalAlignMenuItemFactory);
- const vertical = injector.invoke(VerticalAlignMenuItemFactory);
- const wrap = injector.invoke(WrapTextMenuItemFactory);
- const rotate = injector.invoke(TextRotateMenuItemFactory);
-
- const textColorSelections = textColor.selections as any[];
- const bgColorSelections = bgColor.selections as any[];
- const themeBackgroundColor = get(ThemeService).getColorFromTheme('primary.600');
-
- expect(await firstValueFrom(textColor.value$!.pipe(take(1)))).toBeTypeOf('string');
- expect(await firstValueFrom(textColorSelections[0].value$!.pipe(take(1)))).toBeTypeOf('string');
- expect(await firstValueFrom(bgColor.value$!.pipe(take(1)))).toBe(themeBackgroundColor);
- expect(await firstValueFrom(bgColorSelections[0].value$!.pipe(take(1)))).toBe(themeBackgroundColor);
- expect(await firstValueFrom(horizontal.value$!.pipe(take(1)))).not.toBeUndefined();
- expect(await firstValueFrom(vertical.value$!.pipe(take(1)))).not.toBeUndefined();
- expect(await firstValueFrom(wrap.value$!.pipe(take(1)))).not.toBeUndefined();
- expect(await firstValueFrom(rotate.value$!.pipe(take(1)))).not.toBeUndefined();
- });
-
- it('exposes shrink to fit as an activated ribbon button', async () => {
- const item = get(Injector).invoke(ShrinkToFitMenuItemFactory);
-
- expect(item.id).toBe('sheet.command.set-shrink-to-fit');
- expect(item.icon).toBe('ShrinkToFitIcon');
- expect(await firstValueFrom(item.activated$!.pipe(take(1)))).toBe(false);
- expect(await firstValueFrom(item.disabled$!.pipe(take(1)))).toBeTypeOf('boolean');
- });
-});
diff --git a/packages/sheets-ui/src/menu/__tests__/menu-factories.spec.ts b/packages/sheets-ui/src/menu/__tests__/menu-factories.spec.ts
deleted file mode 100644
index 044167ca31..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/menu-factories.spec.ts
+++ /dev/null
@@ -1,292 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 { IRange, Univer, Workbook } from '@univerjs/core';
-import type { Observable } from 'rxjs';
-import {
- BooleanNumber,
- BorderStyleTypes,
- FOCUSING_COMMON_DRAWINGS,
- ICommandService,
- IContextService,
- Injector,
-
- IUniverInstanceService,
- RANGE_TYPE,
- UniverInstanceType,
-} from '@univerjs/core';
-import {
- BorderStyleManagerService,
- IExclusiveRangeService,
- MergeCellController,
- SetBorderBasicCommand,
- SetBorderCommand,
- SetRangeValuesMutation,
- SetSelectionsOperation,
- SetWorksheetHideCommand,
- SheetsSelectionsService,
- ToggleGridlinesCommand,
- ToggleGridlinesMutation,
-} from '@univerjs/sheets';
-import { firstValueFrom, of, skip, take } from 'rxjs';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import {
- SetRangeFontDecreaseCommand,
- SetRangeFontIncreaseCommand,
- SetRangeFontSizeCommand,
-} from '../../commands/commands/inline-format.command';
-import { ShowMenuListCommand } from '../../commands/commands/unhide.command';
-import { CellBorderSelectorMenuItemFactory } from '../border.menu';
-import {
- FontSizeDecreaseMenuItemFactory,
- FontSizeIncreaseMenuItemFactory,
- FontSizeSelectorMenuItemFactory,
-} from '../font.menu';
-import { ToggleGridlinesMenuFactory } from '../gridlines.menu';
-import {
- ColInsertMenuItemFactory,
- InsertColAfterMenuItemFactory,
- InsertColBeforeMenuItemFactory,
- InsertColLeftCellMenuItemFactory,
- InsertMultiColsLeftHeaderMenuItemFactory,
- InsertMultiColsRightHeaderMenuItemFactory,
- InsertMultiRowsAboveHeaderMenuItemFactory,
- InsertMultiRowsAfterHeaderMenuItemFactory,
- InsertRangeMoveDownMenuItemFactory,
- InsertRangeMoveRightMenuItemFactory,
- InsertRowAfterMenuItemFactory,
- InsertRowBeforeCellMenuItemFactory,
- InsertRowBeforeMenuItemFactory,
- RowInsertMenuItemFactory,
-} from '../insert.menu';
-import { CellMergeMenuItemFactory } from '../merge.menu';
-import {
- ChangeColorSheetMenuItemFactory,
- CopySheetMenuItemFactory,
- DeleteSheetMenuItemFactory,
- HideSheetMenuItemFactory,
- RenameSheetMenuItemFactory,
- ShowMenuItemFactory,
- UnHideSheetMenuItemFactory,
-} from '../sheet.menu';
-import { createMenuTestBed } from './create-menu-test-bed';
-
-describe('menu factories', () => {
- let univer: Univer;
- let get: Injector['get'];
- let commandService: ICommandService;
- let selectionService: SheetsSelectionsService;
-
- beforeEach(() => {
- const testBed = createMenuTestBed();
- univer = testBed.univer;
- get = testBed.get;
- commandService = get(ICommandService);
- selectionService = get(SheetsSelectionsService);
- commandService.registerCommand(SetSelectionsOperation);
- });
-
- afterEach(() => {
- univer.dispose();
- });
-
- function createSelection(startRow: number, startColumn: number, endRow: number, endColumn: number) {
- return {
- range: { startRow, startColumn, endRow, endColumn, rangeType: RANGE_TYPE.NORMAL },
- primary: {
- startRow,
- startColumn,
- endRow,
- endColumn,
- actualRow: startRow,
- actualColumn: startColumn,
- isMerged: false,
- isMergedMainCell: false,
- },
- style: null,
- };
- }
-
- function setSelections(ranges: IRange[]) {
- selectionService.setSelections(ranges.map((range) => createSelection(range.startRow, range.startColumn, range.endRow, range.endColumn)), 2);
- }
-
- function setSingleSelection(startRow: number, startColumn: number, endRow: number, endColumn: number) {
- setSelections([{ startRow, startColumn, endRow, endColumn }]);
- }
-
- it('creates base insert selectors and header insert commands', async () => {
- const injector = get(Injector);
- const colInsert = injector.invoke(ColInsertMenuItemFactory);
- const rowInsert = injector.invoke(RowInsertMenuItemFactory);
- const insertRowBefore = injector.invoke(InsertRowBeforeMenuItemFactory);
- const insertRowAfter = injector.invoke(InsertRowAfterMenuItemFactory);
- const insertColBefore = injector.invoke(InsertColBeforeMenuItemFactory);
- const insertColAfter = injector.invoke(InsertColAfterMenuItemFactory);
- const insertMoveRight = injector.invoke(InsertRangeMoveRightMenuItemFactory);
- const insertMoveDown = injector.invoke(InsertRangeMoveDownMenuItemFactory);
-
- expect(colInsert.id).toBe('sheet.menu.col-insert');
- expect(rowInsert.id).toBe('sheet.menu.row-insert');
- expect(insertRowBefore.id).toBe('sheet.command.insert-row-before');
- expect(insertRowAfter.id).toBe('sheet.command.insert-row-after');
- expect(insertColBefore.id).toBe('sheet.command.insert-col-before');
- expect(insertColAfter.id).toBe('sheet.command.insert-col-after');
- expect(insertMoveRight.id).toBe('sheet.command.insert-range-move-right-confirm');
- expect(insertMoveDown.id).toBe('sheet.command.insert-range-move-down-confirm');
-
- expect(await firstValueFrom(colInsert.hidden$!.pipe(take(1)))).toBeTypeOf('boolean');
- expect(await firstValueFrom(rowInsert.hidden$!.pipe(take(1)))).toBeTypeOf('boolean');
- });
-
- it('computes row-based insert input menu values from current selection height', async () => {
- setSingleSelection(2, 1, 5, 4);
- const injector = get(Injector);
- const beforeCell = injector.invoke(InsertRowBeforeCellMenuItemFactory);
- const rowsAfter = injector.invoke(InsertMultiRowsAfterHeaderMenuItemFactory);
- const rowsAbove = injector.invoke(InsertMultiRowsAboveHeaderMenuItemFactory);
-
- expect(await firstValueFrom(beforeCell.value$!.pipe(take(1)))).toBe(4);
- expect(await firstValueFrom(rowsAfter.value$!.pipe(take(1)))).toBe(4);
- expect(await firstValueFrom(rowsAbove.value$!.pipe(take(1)))).toBe(4);
- });
-
- it('computes column-based insert input menu values from current selection width', async () => {
- setSingleSelection(1, 3, 4, 7);
- const injector = get(Injector);
- const leftCell = injector.invoke(InsertColLeftCellMenuItemFactory);
- const colsLeft = injector.invoke(InsertMultiColsLeftHeaderMenuItemFactory);
- const colsRight = injector.invoke(InsertMultiColsRightHeaderMenuItemFactory);
-
- expect(await firstValueFrom(leftCell.value$!.pipe(take(1)))).toBe(5);
- expect(await firstValueFrom(colsLeft.value$!.pipe(take(1)))).toBe(5);
- expect(await firstValueFrom(colsRight.value$!.pipe(take(1)))).toBe(5);
- });
-
- it('creates sheet menu items and resolves default disable states', async () => {
- const injector = get(Injector);
- const deleteSheet = injector.invoke(DeleteSheetMenuItemFactory);
- const copySheet = injector.invoke(CopySheetMenuItemFactory);
- const renameSheet = injector.invoke(RenameSheetMenuItemFactory);
- const colorSheet = injector.invoke(ChangeColorSheetMenuItemFactory);
- const hideSheet = injector.invoke(HideSheetMenuItemFactory);
- const unhideSheet = injector.invoke(UnHideSheetMenuItemFactory);
- const showMenu = injector.invoke(ShowMenuItemFactory);
-
- expect(deleteSheet.id).toBe('sheet.command.remove-sheet-confirm');
- expect(copySheet.id).toBe('sheet.command.copy-sheet');
- expect(renameSheet.id).toBe('sheet.operation.rename-sheet');
- expect(colorSheet.id).toBe('sheet.command.set-tab-color');
- expect(hideSheet.id).toBe(SetWorksheetHideCommand.id);
- expect(unhideSheet.id).toBe('sheet.command.set-worksheet-show');
- expect(showMenu.id).toBe(ShowMenuListCommand.id);
-
- expect(await firstValueFrom(deleteSheet.disabled$!.pipe(take(1)))).toBe(true);
- expect(await firstValueFrom(hideSheet.disabled$!.pipe(take(1)))).toBe(true);
- expect(await firstValueFrom(unhideSheet.disabled$!.pipe(take(1)))).toBe(true);
- expect(await firstValueFrom(showMenu.disabled$!.pipe(take(1)))).toBe(true);
- expect(await firstValueFrom((unhideSheet.selections as Observable<unknown[]>).pipe(take(1)))).toEqual([]);
- });
-
- it('updates gridlines menu activation after toggling sheet gridlines', async () => {
- const injector = get(Injector);
- const instanceService = get(IUniverInstanceService);
- commandService.registerCommand(ToggleGridlinesCommand);
- commandService.registerCommand(ToggleGridlinesMutation);
-
- const menuItem = injector.invoke(ToggleGridlinesMenuFactory);
- const worksheet = instanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getActiveSheet();
- const initial = await firstValueFrom(menuItem.activated$!.pipe(take(1)));
- expect(await firstValueFrom(menuItem.disabled$!.pipe(take(1)))).toBeTypeOf('boolean');
-
- expect(await commandService.executeCommand(ToggleGridlinesCommand.id)).toBe(true);
- const activatedAfterToggle = await firstValueFrom(menuItem.activated$!.pipe(take(1)));
- expect(activatedAfterToggle).toBe(worksheet.getConfig().showGridlines === BooleanNumber.TRUE);
- expect(activatedAfterToggle).not.toBe(initial);
- });
-
- it('updates border menu icon and hidden state from real border commands', async () => {
- const injector = get(Injector);
- const contextService = get(IContextService);
- setSingleSelection(0, 0, 1, 1);
-
- injector.add([BorderStyleManagerService]);
- commandService.registerCommand(SetBorderBasicCommand);
- commandService.registerCommand(SetBorderCommand);
- commandService.registerCommand(SetRangeValuesMutation);
-
- const menuItem = injector.invoke(CellBorderSelectorMenuItemFactory);
- expect(await firstValueFrom((menuItem.icon as Observable<string>).pipe(take(1)))).toBe('AllBorderIcon');
- expect(await firstValueFrom(menuItem.disabled$!.pipe(take(1)))).toBe(false);
-
- const nextIcon = firstValueFrom((menuItem.icon as Observable<string>).pipe(skip(1), take(1)));
- expect(await commandService.executeCommand(SetBorderBasicCommand.id, {
- unitId: 'test',
- subUnitId: 'sheet1',
- ranges: [{ startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 }],
- value: { type: 'top', color: '#123456', style: BorderStyleTypes.DASHED },
- })).toBe(true);
- expect(await nextIcon).toBe('UpBorderDoubleIcon');
- expect(get(BorderStyleManagerService).getBorderInfo().type).toBe('top');
-
- const hiddenState = firstValueFrom(menuItem.hidden$!.pipe(skip(1), take(1)));
- contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, true);
- expect(await hiddenState).toBe(true);
- });
-
- it('disables merge menu for overlapping multi-selections and hides it while drawing is focused', async () => {
- const injector = get(Injector);
- const contextService = get(IContextService);
- injector.add([IExclusiveRangeService, { useValue: {
- exclusiveRangesChange$: of({ unitId: 'test', subUnitId: 'sheet1', ranges: [] }),
- addExclusiveRange: () => {},
- getExclusiveRanges: () => undefined,
- clearExclusiveRanges: () => {},
- clearExclusiveRangesByGroupId: () => {},
- getInterestGroupId: () => [],
- } }]);
- injector.add([MergeCellController]);
-
- setSingleSelection(0, 0, 1, 1);
- const menuItem = injector.invoke(CellMergeMenuItemFactory);
- expect(await firstValueFrom(menuItem.disabled$!.pipe(take(1)))).toBe(false);
- expect(await firstValueFrom(menuItem.hidden$!.pipe(take(1)))).toBeTypeOf('boolean');
-
- setSelections([
- { startRow: 0, startColumn: 0, endRow: 1, endColumn: 1 },
- { startRow: 1, startColumn: 1, endRow: 2, endColumn: 2 },
- ]);
- expect(await firstValueFrom(menuItem.disabled$!.pipe(take(1)))).toBe(true);
-
- const hiddenState = firstValueFrom(menuItem.hidden$!.pipe(skip(1), take(1)));
- contextService.setContextValue(FOCUSING_COMMON_DRAWINGS, true);
- expect(await hiddenState).toBe(true);
- });
-
- it('creates font-size menu items and exposes selector current value stream', async () => {
- setSingleSelection(0, 0, 0, 0);
- const injector = get(Injector);
- const sizeSelector = injector.invoke(FontSizeSelectorMenuItemFactory);
- const increase = injector.invoke(FontSizeIncreaseMenuItemFactory);
- const decrease = injector.invoke(FontSizeDecreaseMenuItemFactory);
-
- expect(sizeSelector.id).toBe(SetRangeFontSizeCommand.id);
- expect(increase.id).toBe(SetRangeFontIncreaseCommand.id);
- expect(decrease.id).toBe(SetRangeFontDecreaseCommand.id);
- expect(await firstValueFrom(sizeSelector.value$!.pipe(take(1)))).toBeTypeOf('number');
- expect(await firstValueFrom(sizeSelector.disabled$!.pipe(take(1)))).toBeTypeOf('boolean');
- });
-});
diff --git a/packages/sheets-ui/src/menu/__tests__/menu-util.spec.ts b/packages/sheets-ui/src/menu/__tests__/menu-util.spec.ts
deleted file mode 100644
index fa2e865532..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/menu-util.spec.ts
+++ /dev/null
@@ -1,259 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 {
- FOCUSING_COMMON_DRAWINGS,
- FOCUSING_FX_BAR_EDITOR,
- FOCUSING_SHAPE_TEXT_EDITOR,
- IContextService,
- IPermissionService,
- IUniverInstanceService,
- UserManagerService,
-} from '@univerjs/core';
-import {
- IExclusiveRangeService,
- RangeProtectionRuleModel,
- SheetsSelectionsService,
- WorkbookEditablePermission,
- WorksheetProtectionRuleModel,
-} from '@univerjs/sheets';
-import { BehaviorSubject, firstValueFrom, of, skip, take } from 'rxjs';
-import { describe, expect, it } from 'vitest';
-import { IEditorBridgeService } from '../../services/editor-bridge.service';
-import {
- deriveStateFromActiveSheet$,
- getBaseRangeMenuHidden$,
- getCellMenuHidden$,
- getCurrentExclusiveRangeInterest$,
- getCurrentRangeDisable$,
- getDeleteMenuHidden$,
- getInsertAfterMenuHidden$,
- getInsertBeforeMenuHidden$,
- getObservableWithExclusiveRange$,
- getWorkbookPermissionDisable$,
-} from '../menu-util';
-
-function createAccessor(pairs: Array<[unknown, unknown]>) {
- const map = new Map<unknown, unknown>(pairs);
- return {
- get(token: unknown) {
- if (!map.has(token)) {
- throw new Error(`Unknown token: ${String(token)}`);
- }
- return map.get(token);
- },
- has(token: unknown) {
- return map.has(token);
- },
- } as any;
-}
-
-function firstValue<T>(obs: { pipe: (...args: any[]) => any }) {
- return firstValueFrom(obs.pipe(take(1)));
-}
-
-interface IMenuAccessorOption {
- workbook?: any;
- worksheet?: any;
- selections?: any[] | undefined;
- subUnitRules?: any[];
- worksheetRule?: any;
- composePermissionAllTrue?: boolean;
- editorVisible?: any;
- hasEditorBridge?: boolean;
- formulaFocus?: boolean;
- drawingFocus?: boolean;
- shapeEditorFocus?: boolean;
- interestGroupIds?: string[];
-}
-
-function createMenuAccessor(option: Partial<IMenuAccessorOption> = {}) {
- const worksheet = option.worksheet ?? {
- getSheetId: () => 'sheet-1',
- getRowCount: () => 20,
- getColumnCount: () => 10,
- };
-
- const workbook = option.workbook ?? {
- getUnitId: () => 'unit-1',
- getActiveSheet: () => worksheet,
- activeSheet$: of(worksheet),
- };
-
- const selections = option.selections ?? [{ range: { startRow: 2, endRow: 2, startColumn: 2, endColumn: 2 } }];
- const selectionMoveEnd$ = new BehaviorSubject(selections);
- const selectionChanged$ = new BehaviorSubject(selections);
- const selectionService = {
- selectionMoveEnd$,
- selectionChanged$,
- getCurrentSelections: () => selections,
- getCurrentLastSelection: () => selections[0] ?? null,
- getWorkbookSelections: () => ({
- getSelectionsOfWorksheet: () => selections,
- }),
- };
-
- const subUnitRules = option.subUnitRules ?? [];
- const rangeProtectionRuleModel = {
- ruleChange$: new BehaviorSubject(null),
- getSubunitRuleList: () => subUnitRules,
- };
-
- const worksheetRule = option.worksheetRule ?? null;
- const worksheetProtectionRuleModel = {
- ruleChange$: new BehaviorSubject(null),
- getRule: () => worksheetRule,
- };
-
- const composePermissionAllTrue = option.composePermissionAllTrue ?? true;
- const permissionService = {
- composePermission$: (ids: string[]) => of(ids.map(() => ({ value: composePermissionAllTrue }))),
- composePermission: (ids: string[]) => ids.map((_id, index) => ({ value: index === 0 ? true : composePermissionAllTrue })),
- permissionPointUpdate$: new BehaviorSubject(null),
- };
-
- const formulaFocus = option.formulaFocus ?? false;
- const drawingFocus = option.drawingFocus ?? false;
- const shapeEditorFocus = option.shapeEditorFocus ?? false;
- const contextService = {
- subscribeContextValue$: (key: unknown) => {
- if (key === FOCUSING_FX_BAR_EDITOR) {
- return of(formulaFocus);
- }
- if (key === FOCUSING_COMMON_DRAWINGS) {
- return of(drawingFocus);
- }
- if (key === FOCUSING_SHAPE_TEXT_EDITOR) {
- return of(shapeEditorFocus);
- }
- return of(false);
- },
- };
-
- const interestGroupIds = option.interestGroupIds ?? [];
- const exclusiveRangeService = {
- getInterestGroupId: () => interestGroupIds,
- };
-
- const pairs: Array<[unknown, unknown]> = [
- [IUniverInstanceService, { getCurrentTypeOfUnit$: () => of(workbook), getCurrentUnitOfType: () => workbook }],
- [SheetsSelectionsService, selectionService],
- [RangeProtectionRuleModel, rangeProtectionRuleModel],
- [WorksheetProtectionRuleModel, worksheetProtectionRuleModel],
- [IPermissionService, permissionService],
- [UserManagerService, { currentUser$: of({ userID: 'u1' }) }],
- [IContextService, contextService],
- [IExclusiveRangeService, exclusiveRangeService],
- ];
-
- if (option.hasEditorBridge) {
- pairs.push([IEditorBridgeService, { visible$: of(option.editorVisible ?? null) }]);
- }
-
- return createAccessor(pairs);
-}
-
-describe('menu-util', () => {
- it('deriveStateFromActiveSheet$ returns default without active sheet and callback value with active sheet', async () => {
- const noActive = { getCurrentTypeOfUnit$: () => of(null) };
- expect(await firstValue(deriveStateFromActiveSheet$(noActive as any, 'DEFAULT', () => of('ACTIVE')))).toBe('DEFAULT');
-
- const worksheet = { getSheetId: () => 'sheet-1' };
- const workbook = { activeSheet$: of(worksheet) };
- const withActive = { getCurrentTypeOfUnit$: () => of(workbook) };
- expect(await firstValue(deriveStateFromActiveSheet$(withActive as any, 'DEFAULT', () => of('ACTIVE')))).toBe('ACTIVE');
- });
-
- it('handles exclusive-range interest and derived observable state', async () => {
- const accessor = createMenuAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- interestGroupIds: ['group-a', 'group-b'],
- });
-
- expect(await firstValue(getCurrentExclusiveRangeInterest$(accessor))).toBe(true);
- expect(await firstValue(getCurrentExclusiveRangeInterest$(accessor, new Set(['group-z'])))).toBe(false);
- expect(await firstValue(getCurrentExclusiveRangeInterest$(accessor, new Set(['group-b'])))).toBe(true);
- expect(await firstValue(getObservableWithExclusiveRange$(accessor, of(false), new Set(['group-b'])))).toBe(true);
- });
-
- it('computes current-range disable with workbook/editor/drawing/permission states', async () => {
- const noWorkbookAccessor = createAccessor([
- [IUniverInstanceService, { getCurrentTypeOfUnit$: () => of(null) }],
- [UserManagerService, { currentUser$: of({ userID: 'u1' }) }],
- [IContextService, { subscribeContextValue$: () => of(false) }],
- ]);
- expect(await firstValue(getCurrentRangeDisable$(noWorkbookAccessor))).toBe(true);
-
- const editorVisibleAccessor = createMenuAccessor({
- hasEditorBridge: true,
- editorVisible: { visible: true, unitId: 'unit-1' },
- });
- expect(await firstValue(getCurrentRangeDisable$(editorVisibleAccessor))).toBe(true);
-
- const drawingFocusedAccessor = createMenuAccessor({
- drawingFocus: true,
- shapeEditorFocus: false,
- composePermissionAllTrue: true,
- });
- expect(await firstValueFrom(getCurrentRangeDisable$(drawingFocusedAccessor).pipe(skip(1), take(1)))).toBe(true);
-
- const enabledAccessor = createMenuAccessor({
- composePermissionAllTrue: true,
- drawingFocus: false,
- worksheetRule: null,
- subUnitRules: [],
- });
- expect(await firstValue(getCurrentRangeDisable$(enabledAccessor))).toBe(false);
- });
-
- it('computes base/insert/delete/cell menu hidden observables', async () => {
- const accessor = createMenuAccessor({
- composePermissionAllTrue: false,
- subUnitRules: [{ permissionId: 'r1', ranges: [{ startRow: 0, endRow: 5, startColumn: 0, endColumn: 5 }] }],
- selections: [{ range: { startRow: 2, endRow: 2, startColumn: 2, endColumn: 2 } }],
- });
-
- expect(await firstValue(getBaseRangeMenuHidden$(accessor))).toBe(true);
- expect(await firstValue(getInsertAfterMenuHidden$(accessor, 'row'))).toBe(true);
- expect(await firstValue(getInsertBeforeMenuHidden$(accessor, 'col'))).toBe(true);
- expect(await firstValue(getDeleteMenuHidden$(accessor, 'row'))).toBe(true);
- expect(await firstValue(getCellMenuHidden$(accessor, 'col'))).toBe(true);
- });
-
- it('computes workbook-permission disable with protection rules', async () => {
- const noWorkbookAccessor = createAccessor([
- [IUniverInstanceService, { getCurrentTypeOfUnit$: () => of(null) }],
- [WorksheetProtectionRuleModel, { getRule: () => null }],
- [RangeProtectionRuleModel, { getSubunitRuleList: () => [] }],
- [IPermissionService, { composePermission$: () => of([{ value: true }]) }],
- [UserManagerService, { currentUser$: of({ userID: 'u1' }) }],
- ]);
- expect(await firstValue(getWorkbookPermissionDisable$(noWorkbookAccessor, [WorkbookEditablePermission]))).toBe(true);
-
- const hasWorksheetRuleAccessor = createMenuAccessor({
- composePermissionAllTrue: true,
- worksheetRule: { permissionId: 'sheet-rule' },
- });
- expect(await firstValue(getWorkbookPermissionDisable$(hasWorksheetRuleAccessor, [WorkbookEditablePermission]))).toBe(true);
-
- const enabledAccessor = createMenuAccessor({
- composePermissionAllTrue: true,
- worksheetRule: null,
- subUnitRules: [],
- });
- expect(await firstValue(getWorkbookPermissionDisable$(enabledAccessor, [WorkbookEditablePermission]))).toBe(false);
- });
-});
diff --git a/packages/sheets-ui/src/menu/__tests__/permission-menu-util.spec.ts b/packages/sheets-ui/src/menu/__tests__/permission-menu-util.spec.ts
deleted file mode 100644
index a73b898379..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/permission-menu-util.spec.ts
+++ /dev/null
@@ -1,344 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 {
- FOCUSING_COMMON_DRAWINGS,
- FOCUSING_FX_BAR_EDITOR,
- IContextService,
- IPermissionService,
- IUniverInstanceService,
- RANGE_TYPE,
- UserManagerService,
-} from '@univerjs/core';
-import { UnitAction } from '@univerjs/protocol';
-import {
- RangeProtectionCache,
- RangeProtectionRuleModel,
- SheetsSelectionsService,
- WorksheetProtectionRuleModel,
-} from '@univerjs/sheets';
-import { BehaviorSubject, firstValueFrom, of, skip, take } from 'rxjs';
-import { describe, expect, it } from 'vitest';
-import { IEditorBridgeService } from '../../services/editor-bridge.service';
-import {
- getAddPermissionDisableBase$,
- getAddPermissionFromSheetBarDisable$,
- getAddPermissionHidden$,
- getEditPermissionHidden$,
- getPermissionDisableBase$,
- getRemovePermissionDisable$,
- getRemovePermissionFromSheetBarDisable$,
- getSetPermissionFromSheetBarDisable$,
- getViewPermissionDisable$,
-} from '../permission-menu-util';
-
-function createAccessor(pairs: Array<[unknown, unknown]>) {
- const map = new Map<unknown, unknown>(pairs);
- return {
- get(token: unknown) {
- if (!map.has(token)) {
- throw new Error(`Unknown token: ${String(token)}`);
- }
- return map.get(token);
- },
- has(token: unknown) {
- return map.has(token);
- },
- } as any;
-}
-
-function firstValue<T>(obs: { pipe: (...args: any[]) => any }) {
- return firstValueFrom(obs.pipe(take(1)));
-}
-
-interface IMockOption {
- workbook: any;
- worksheet: any;
- selections?: any[] | undefined;
- subUnitRules?: any[];
- worksheetRule?: any;
- permissionAllTrue?: boolean;
- permissionPointValue?: boolean;
- formulaEditorFocus?: boolean;
- focusingDrawing?: boolean;
- editorVisible?: any;
- hasEditorBridge?: boolean;
- cellInfoByCoord?: Record<string, Record<string, boolean>>;
-}
-
-function createPermissionAccessor(option: Partial<IMockOption> = {}) {
- const worksheet = option.worksheet ?? { getSheetId: () => 'sheet-1' };
- const workbook = option.workbook ?? { getUnitId: () => 'unit-1', activeSheet$: of(worksheet) };
- const selections = option.selections;
-
- const selectionMoveEnd$ = new BehaviorSubject(null);
- const selectionService = {
- selectionMoveEnd$,
- getCurrentSelections: () => selections,
- };
-
- const subUnitRules = option.subUnitRules ?? [];
- const rangeProtectionRuleModel = {
- ruleChange$: new BehaviorSubject(null),
- getSubunitRuleList: () => subUnitRules,
- };
-
- const worksheetRule = option.worksheetRule ?? null;
- const worksheetProtectionRuleModel = {
- ruleChange$: new BehaviorSubject(null),
- getRule: () => worksheetRule,
- };
-
- const permissionAllTrue = option.permissionAllTrue ?? true;
- const permissionPointValue = option.permissionPointValue ?? true;
- const permissionService = {
- composePermission$: (ids: string[]) => of(ids.map(() => ({ value: permissionAllTrue }))),
- getPermissionPoint: () => ({ value: permissionPointValue }),
- getPermissionPoint$: () => of({ value: permissionPointValue }),
- };
-
- const formulaEditorFocus = option.formulaEditorFocus ?? false;
- const focusingDrawing = option.focusingDrawing ?? false;
- const contextService = {
- subscribeContextValue$: (key: unknown) => {
- if (key === FOCUSING_FX_BAR_EDITOR) {
- return of(formulaEditorFocus);
- }
- if (key === FOCUSING_COMMON_DRAWINGS) {
- return of(focusingDrawing);
- }
- return of(false);
- },
- };
-
- const cellInfoByCoord = option.cellInfoByCoord ?? {};
- const rangeProtectionCache = {
- getCellInfo: (_unitId: string, _subUnitId: string, row: number, col: number) => {
- return cellInfoByCoord[`${row},${col}`] ?? null;
- },
- };
-
- const pairs: Array<[unknown, unknown]> = [
- [IUniverInstanceService, { getCurrentTypeOfUnit$: () => of(workbook) }],
- [UserManagerService, { currentUser$: of({ userID: 'u1' }) }],
- [SheetsSelectionsService, selectionService],
- [RangeProtectionRuleModel, rangeProtectionRuleModel],
- [WorksheetProtectionRuleModel, worksheetProtectionRuleModel],
- [IPermissionService, permissionService],
- [IContextService, contextService],
- [RangeProtectionCache, rangeProtectionCache],
- ];
-
- if (option.hasEditorBridge) {
- pairs.push([IEditorBridgeService, { visible$: of(option.editorVisible ?? null) }]);
- }
-
- return createAccessor(pairs);
-}
-
-describe('permission-menu-util', () => {
- it('computes add-permission hidden by worksheet rule or range overlap', async () => {
- const overlapAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- subUnitRules: [{ ranges: [{ startRow: 0, endRow: 2, startColumn: 0, endColumn: 2 }] }],
- });
- expect(await firstValue(getAddPermissionHidden$(overlapAccessor))).toBe(true);
-
- const worksheetRuleAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 3, endRow: 3, startColumn: 3, endColumn: 3 } }],
- worksheetRule: { permissionId: 'sheet-permission' },
- subUnitRules: [],
- });
- expect(await firstValue(getAddPermissionHidden$(worksheetRuleAccessor))).toBe(true);
-
- const emptySelectionAccessor = createPermissionAccessor({
- selections: undefined,
- subUnitRules: [{ ranges: [{ startRow: 0, endRow: 2, startColumn: 0, endColumn: 2 }] }],
- });
- expect(await firstValue(getAddPermissionHidden$(emptySelectionAccessor))).toBe(false);
- });
-
- it('computes edit-permission hidden with selection/rule/cell-action checks', async () => {
- const multiSelectionAccessor = createPermissionAccessor({
- selections: [
- { range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } },
- { range: { startRow: 2, endRow: 2, startColumn: 2, endColumn: 2 } },
- ],
- });
- expect(await firstValue(getEditPermissionHidden$(multiSelectionAccessor))).toBe(true);
-
- const worksheetRuleAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- worksheetRule: { permissionId: 'sheet-rule' },
- permissionPointValue: false,
- });
- expect(await firstValue(getEditPermissionHidden$(worksheetRuleAccessor))).toBe(true);
-
- const blockedByCellAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- subUnitRules: [{ ranges: [{ startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 }] }],
- cellInfoByCoord: { '1,1': { [UnitAction.ManageCollaborator]: false } },
- });
- expect(await firstValue(getEditPermissionHidden$(blockedByCellAccessor))).toBe(true);
-
- const allowedCellAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- subUnitRules: [{ ranges: [{ startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 }] }],
- cellInfoByCoord: { '1,1': { [UnitAction.ManageCollaborator]: true } },
- });
- expect(await firstValue(getEditPermissionHidden$(allowedCellAccessor))).toBe(false);
- });
-
- it('computes base permission disable with permission result and selection count', async () => {
- const noPermissionAccessor = createPermissionAccessor({
- permissionAllTrue: false,
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- });
- expect(await firstValue(getPermissionDisableBase$(noPermissionAccessor))).toBe(true);
-
- const oneSelectionAccessor = createPermissionAccessor({
- permissionAllTrue: true,
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- });
- expect(await firstValue(getPermissionDisableBase$(oneSelectionAccessor))).toBe(false);
-
- const multiSelectionAccessor = createPermissionAccessor({
- permissionAllTrue: true,
- selections: [
- { range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } },
- { range: { startRow: 2, endRow: 2, startColumn: 2, endColumn: 2 } },
- ],
- });
- expect(await firstValue(getPermissionDisableBase$(multiSelectionAccessor))).toBe(true);
- });
-
- it('computes add-permission disable base with editor/drawing/overlap checks', async () => {
- const editorVisibleAccessor = createPermissionAccessor({
- hasEditorBridge: true,
- editorVisible: { visible: true, unitId: 'unit-1' },
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- });
- expect(await firstValue(getAddPermissionDisableBase$(editorVisibleAccessor))).toBe(true);
-
- const focusingDrawingAccessor = createPermissionAccessor({
- focusingDrawing: true,
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- permissionAllTrue: true,
- });
- expect(await firstValueFrom(getAddPermissionDisableBase$(focusingDrawingAccessor).pipe(skip(1), take(1)))).toBe(true);
-
- const enabledAccessor = createPermissionAccessor({
- permissionAllTrue: true,
- selections: [{ range: { startRow: 5, endRow: 5, startColumn: 5, endColumn: 5 } }],
- subUnitRules: [{ ranges: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn: 0 }] }],
- });
- expect(await firstValue(getAddPermissionDisableBase$(enabledAccessor))).toBe(false);
- });
-
- it('computes sheet-bar add/remove/set disable states', async () => {
- const addAllowedAccessor = createPermissionAccessor({
- permissionAllTrue: true,
- subUnitRules: [{ permissionId: undefined }],
- });
- expect(await firstValue(getAddPermissionFromSheetBarDisable$(addAllowedAccessor))).toBe(false);
-
- const addDisabledAccessor = createPermissionAccessor({
- permissionAllTrue: true,
- subUnitRules: [{ permissionId: 'r1' }],
- });
- expect(await firstValue(getAddPermissionFromSheetBarDisable$(addDisabledAccessor))).toBe(true);
-
- const removeNoRuleAccessor = createPermissionAccessor({
- worksheetRule: null,
- });
- expect(await firstValue(getRemovePermissionFromSheetBarDisable$(removeNoRuleAccessor))).toBe(true);
-
- const removeWithRuleAccessor = createPermissionAccessor({
- worksheetRule: { permissionId: 'sheet-rule' },
- permissionPointValue: true,
- });
- expect(await firstValue(getRemovePermissionFromSheetBarDisable$(removeWithRuleAccessor))).toBe(false);
-
- const setDisabledAccessor = createPermissionAccessor({
- permissionAllTrue: false,
- subUnitRules: [],
- });
- expect(await firstValue(getSetPermissionFromSheetBarDisable$(setDisabledAccessor))).toBe(true);
-
- const setEnabledAccessor = createPermissionAccessor({
- permissionAllTrue: true,
- worksheetRule: { permissionId: 'sheet-rule' },
- });
- expect(await firstValue(getSetPermissionFromSheetBarDisable$(setEnabledAccessor))).toBe(false);
- });
-
- it('computes remove-permission disable from selection and permission detail', async () => {
- const noSelectionAccessor = createPermissionAccessor({
- selections: undefined,
- });
- expect(await firstValue(getRemovePermissionDisable$(noSelectionAccessor))).toBe(true);
-
- const rowSelectionAccessor = createPermissionAccessor({
- selections: [{
- range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1, rangeType: RANGE_TYPE.ROW },
- }],
- });
- expect(await firstValue(getRemovePermissionDisable$(rowSelectionAccessor))).toBe(true);
-
- const worksheetRuleAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- worksheetRule: { permissionId: 'sheet-rule' },
- permissionPointValue: false,
- });
- expect(await firstValue(getRemovePermissionDisable$(worksheetRuleAccessor))).toBe(true);
-
- const blockedCellAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- subUnitRules: [{ ranges: [{ startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 }] }],
- cellInfoByCoord: { '1,1': { [UnitAction.Delete]: false } },
- });
- expect(await firstValue(getRemovePermissionDisable$(blockedCellAccessor))).toBe(true);
-
- const allowedAccessor = createPermissionAccessor({
- selections: [{ range: { startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 } }],
- subUnitRules: [{ ranges: [{ startRow: 1, endRow: 1, startColumn: 1, endColumn: 1 }] }],
- cellInfoByCoord: { '1,1': { [UnitAction.Delete]: true } },
- });
- expect(await firstValue(getRemovePermissionDisable$(allowedAccessor))).toBe(false);
- });
-
- it('computes view-permission disable with workbook/editor/permission states', async () => {
- const noWorkbookAccessor = createAccessor([
- [IUniverInstanceService, { getCurrentTypeOfUnit$: () => of(null) }],
- [UserManagerService, { currentUser$: of({ userID: 'u1' }) }],
- [IPermissionService, { getPermissionPoint$: () => of({ value: true }) }],
- [IContextService, { subscribeContextValue$: () => of(false) }],
- ]);
- expect(await firstValue(getViewPermissionDisable$(noWorkbookAccessor))).toBe(true);
-
- const editorVisibleAccessor = createPermissionAccessor({
- hasEditorBridge: true,
- editorVisible: { visible: true, unitId: 'unit-1' },
- permissionPointValue: true,
- });
- expect(await firstValue(getViewPermissionDisable$(editorVisibleAccessor))).toBe(true);
-
- const allowedAccessor = createPermissionAccessor({
- permissionPointValue: true,
- });
- expect(await firstValue(getViewPermissionDisable$(allowedAccessor))).toBe(false);
- });
-});
diff --git a/packages/sheets-ui/src/menu/__tests__/row-col.menu.spec.ts b/packages/sheets-ui/src/menu/__tests__/row-col.menu.spec.ts
deleted file mode 100644
index f5d942a68d..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/row-col.menu.spec.ts
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 { Univer, Workbook } from '@univerjs/core';
-import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
-import {
- DisposableCollection,
- ICommandService,
- Injector,
- IUniverInstanceService,
- RANGE_TYPE,
- toDisposable,
- UniverInstanceType,
-} from '@univerjs/core';
-import {
- SetColHiddenCommand,
- SetColHiddenMutation,
- SetColVisibleMutation,
- SetRowHiddenCommand,
- SetRowHiddenMutation,
- SetRowVisibleMutation,
- SetSelectedColsVisibleCommand,
- SetSelectedRowsVisibleCommand,
- SetSelectionsOperation,
- SetSpecificColsVisibleCommand,
- SetSpecificRowsVisibleCommand,
-} from '@univerjs/sheets';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import { ShowColMenuItemFactory, ShowRowMenuItemFactory } from '../menu';
-import { createMenuTestBed } from './create-menu-test-bed';
-
-describe('Test row col menu items', () => {
- let univer: Univer;
- let get: Injector['get'];
- let commandService: ICommandService;
- let disposableCollection: DisposableCollection;
-
- beforeEach(() => {
- const testBed = createMenuTestBed();
-
- univer = testBed.univer;
- get = testBed.get;
- commandService = get(ICommandService);
-
- [
- SetRowHiddenCommand,
- SetRowHiddenMutation,
- SetColHiddenCommand,
- SetColHiddenMutation,
- SetSelectedRowsVisibleCommand,
- SetSelectedColsVisibleCommand,
- SetRowVisibleMutation,
- SetColVisibleMutation,
- SetSelectionsOperation,
- SetSpecificColsVisibleCommand,
- SetSpecificRowsVisibleCommand,
- ].forEach((command) => {
- commandService.registerCommand(command);
- });
-
- disposableCollection = new DisposableCollection();
- });
-
- afterEach(() => univer.dispose());
-
- function getRowCount(): number {
- const currentService = get(IUniverInstanceService);
- const workbook = currentService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
- const worksheet = workbook.getActiveSheet()!;
- return worksheet.getRowCount();
- }
-
- function getColCount(): number {
- const currentService = get(IUniverInstanceService);
- const workbook = currentService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
- const worksheet = workbook.getActiveSheet()!;
- return worksheet.getColumnCount();
- }
-
- async function selectRow(rowStart: number, rowEnd: number): Promise<boolean> {
- const currentService = get(IUniverInstanceService);
- const workbook = currentService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
- const worksheet = workbook.getActiveSheet()!;
- const endColumn = getColCount() - 1;
- return commandService.executeCommand<ISetSelectionsOperationParams, boolean>(SetSelectionsOperation.id, {
- unitId: workbook.getUnitId(),
- subUnitId: worksheet.getSheetId(),
-
- selections: [
- {
- range: { startRow: rowStart, startColumn: 0, endColumn, endRow: rowEnd, rangeType: RANGE_TYPE.ROW },
- primary: {
- startRow: rowStart,
- endRow: rowEnd,
- startColumn: 0,
- endColumn,
- actualColumn: 0,
- actualRow: rowStart,
- isMerged: false,
- isMergedMainCell: false,
- },
- style: null,
- },
- ],
- });
- }
-
- async function selectColumn(columnStart: number, columnEnd: number): Promise<boolean> {
- const currentService = get(IUniverInstanceService);
- const workbook = currentService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
- const worksheet = workbook.getActiveSheet()!;
- const endRow = getRowCount() - 1;
- return commandService.executeCommand<ISetSelectionsOperationParams, boolean>(SetSelectionsOperation.id, {
- unitId: workbook.getUnitId(),
- subUnitId: worksheet.getSheetId(),
-
- selections: [
- {
- range: {
- startRow: 0,
- startColumn: columnStart,
- endColumn: columnEnd,
- endRow,
- rangeType: RANGE_TYPE.COLUMN,
- },
- primary: {
- startRow: 0,
- endRow,
- startColumn: columnStart,
- endColumn: columnEnd,
- actualColumn: columnStart,
- actualRow: 0,
- isMerged: false,
- isMergedMainCell: false,
- },
- style: null,
- },
- ],
- });
- }
-
- describe('Test row col hide/unhide menu items', () => {
- it('Should only show "Show Hidden Rows" when there are hidden rows in current selections', async () => {
- let hidden = false;
-
- const menuItem = get(Injector).invoke(ShowRowMenuItemFactory);
- disposableCollection.add(toDisposable(menuItem.hidden$!.subscribe((v: boolean) => (hidden = v))));
- expect(hidden).toBeTruthy();
-
- await selectRow(1, 1);
- await commandService.executeCommand(SetRowHiddenCommand.id);
- await selectRow(0, 2);
- expect(hidden).toBeFalsy();
-
- await commandService.executeCommand(SetSelectedRowsVisibleCommand.id);
- expect(hidden).toBeTruthy();
- });
-
- it('Should only show "Show Hidden Cols" when there are hidden cols in current selections', async () => {
- let hidden = false;
-
- const menuItem = get(Injector).invoke(ShowColMenuItemFactory);
- disposableCollection.add(toDisposable(menuItem.hidden$!.subscribe((v: boolean) => (hidden = v))));
- expect(hidden).toBeTruthy();
-
- await selectColumn(1, 1);
- await commandService.executeCommand(SetColHiddenCommand.id);
- await selectColumn(0, 2);
- expect(hidden).toBeFalsy();
-
- await commandService.executeCommand(SetSelectedColsVisibleCommand.id);
- expect(hidden).toBeTruthy();
- });
- });
-});
diff --git a/packages/sheets-ui/src/menu/__tests__/utils.spec.ts b/packages/sheets-ui/src/menu/__tests__/utils.spec.ts
deleted file mode 100644
index dd278457e5..0000000000
--- a/packages/sheets-ui/src/menu/__tests__/utils.spec.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Copyright 2023-present DreamNum Co., Ltd.
- *
- * 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 { DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { DocSelectionManagerService } from '@univerjs/docs';
-import { IEditorService } from '@univerjs/docs-ui';
-import { describe, expect, it, vi } from 'vitest';
-import { getFontStyleAtCursor } from '../utils';
-
-function createAccessor(pairs: Array<[unknown, unknown]>) {
- const map = new Map<unknown, unknown>(pairs);
- return {
- get(token: unknown) {
- if (!map.has(token)) {
- throw new Error(`Unknown token: ${String(token)}`);
- }
- return map.get(token);
- },
- } as any;
-}
-
-describe('menu utils', () => {
- it('returns null when editor model or active range is missing', () => {
- const getUnit = vi.fn();
- getUnit.mockReturnValue(null);
- const getActiveTextRange = vi.fn();
- getActiveTextRange.mockReturnValue({ startOffset: 0, endOffset: 1 });
- const univerInstanceService = { getUnit };
- const textSelectionService = { getActiveTextRange };
- const editorService = { getFocusId: vi.fn(() => 'doc-1') };
- const accessor = createAccessor([
- [IUniverInstanceService, univerInstanceService],
- [DocSelectionManagerService, textSelectionService],
- [IEditorService, editorService],
- ]);
-
- expect(getFontStyleAtCursor(accessor)).toBeNull();
-
- getUnit.mockReturnValue({ getBody: () => ({ textRuns: [] }) });
- getActiveTextRange.mockReturnValue(null);
- expect(getFontStyleAtCursor(accessor)).toBeNull();
- });
-
- it('returns undefined when editor model body has no textRuns', () => {
- const accessor = createAccessor([
- [IUniverInstanceService, { getUnit: vi.fn(() => ({ getBody: () => ({}) })) }],
- [DocSelectionManagerService, { getActiveTextRange: vi.fn(() => ({ startOffset: 1, endOffset: 2 })) }],
- [IEditorService, { getFocusId: vi.fn(() => 'doc-1') }],
- ]);
-
- expect(getFontStyleAtCursor(accessor)).toBeUndefined();
- });
-
- it('uses default editor id and returns the text run at cursor', () => {
- const matchRun = { st: 10, ed: 20, ts: { bl: true } };
- const getUnit = vi.fn(() => ({
- getBody: () => ({
- textRuns: [{ st: 0, ed: 9 }, matchRun, { st: 21, ed: 30 }],
- }),
- }));
-
- const accessor = createAccessor([
- [IUniverInstanceService, { getUnit }],
- [DocSelectionManagerService, { getActiveTextRange: () => ({ startOffset: 12, endOffset: 18 }) }],
- [IEditorService, { getFocusId: () => undefined }],
- ]);
-
- expect(getFontStyleAtCursor(accessor)).toBe(matchRun);
- expect(getUnit).toHaveBeenCalledWith(DOCS_NORMAL_EDITOR_UNIT_ID_KEY, UniverInstanceType.UNIVER_DOC);
- });
-});
diff --git a/packages/sheets-ui/src/menu/frozen.menu.ts b/packages/sheets-ui/src/menu/frozen.menu.ts
index 759047026a..b8fcf8ec35 100644
--- a/packages/sheets-ui/src/menu/frozen.menu.ts
+++ b/packages/sheets-ui/src/menu/frozen.menu.ts
@@ -71,6 +71,61 @@ const getMenuHiddenByCurrentSelectionChangedObservable$ = (accessor: IAccessor,
};
export const SHEET_FROZEN_MENU_ID = 'sheet.menu.sheet-frozen';
+export const SHEET_FROZEN_TOOLBAR_MENU_ID = 'sheet.toolbar.sheet-frozen';
+
+export function SheetFrozenToolbarMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
+ return {
+ id: SHEET_FROZEN_TOOLBAR_MENU_ID,
+ type: MenuItemType.SUBITEMS,
+ tooltip: 'sheets-ui.rightClick.freeze',
+ icon: 'FreezeToSelectedIcon',
+ selections: [
+ {
+ id: SetSelectionFrozenCommand.id,
+ value: SetSelectionFrozenCommand.id,
+ params: {},
+ icon: 'FreezeToSelectedIcon',
+ label: { name: MENU_ITEM_FROZEN_COMPONENT, selectable: false, props: { type: 'all' } },
+ },
+ {
+ id: SetRowFrozenCommand.id,
+ value: SetRowFrozenCommand.id,
+ params: {},
+ icon: 'FreezeRowIcon',
+ label: { name: MENU_ITEM_FROZEN_COMPONENT, selectable: false, props: { type: 'row' } },
+ },
+ {
+ id: SetColumnFrozenCommand.id,
+ value: SetColumnFrozenCommand.id,
+ params: {},
+ icon: 'FreezeColumnIcon',
+ label: { name: MENU_ITEM_FROZEN_COMPONENT, selectable: false, props: { type: 'col' } },
+ },
+ {
+ id: SetFirstRowFrozenCommand.id,
+ value: SetFirstRowFrozenCommand.id,
+ params: {},
+ icon: 'FreezeRowIcon',
+ label: { name: 'sheets-ui.rightClick.freezeFirstRow', selectable: false },
+ },
+ {
+ id: SetFirstColumnFrozenCommand.id,
+ value: SetFirstColumnFrozenCommand.id,
+ params: {},
+ icon: 'FreezeColumnIcon',
+ label: { name: 'sheets-ui.rightClick.freezeFirstCol', selectable: false },
+ },
+ {
+ id: CancelFrozenCommand.id,
+ value: CancelFrozenCommand.id,
+ params: {},
+ icon: 'CancelFreezeIcon',
+ label: { name: 'sheets-ui.rightClick.cancelFreeze', selectable: false },
+ },
+ ],
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ };
+}
export function SheetFrozenMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<LocaleKey> {
return {
diff --git a/packages/sheets-ui/src/menu/fullscreen.menu.ts b/packages/sheets-ui/src/menu/fullscreen.menu.ts
new file mode 100644
index 0000000000..28506aec52
--- /dev/null
+++ b/packages/sheets-ui/src/menu/fullscreen.menu.ts
@@ -0,0 +1,41 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IAccessor } from '@univerjs/core';
+import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
+import { UniverInstanceType } from '@univerjs/core';
+import { getMenuHiddenObservable, ILayoutService, MenuItemType, ToggleFullscreenOperation } from '@univerjs/ui';
+import { distinctUntilChanged, fromEvent, map, merge, of } from 'rxjs';
+
+export function FullscreenMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {
+ const root = accessor.get(ILayoutService).rootContainerElement;
+ const fullscreen$ = root
+ ? merge(of(null), fromEvent(root.ownerDocument, 'fullscreenchange')).pipe(
+ map(() => root.ownerDocument.fullscreenElement === root),
+ distinctUntilChanged()
+ )
+ : of(false);
+
+ return {
+ id: ToggleFullscreenOperation.id,
+ type: MenuItemType.BUTTON,
+ tooltip: 'sheets-ui.toolbar.fullscreen',
+ icon: fullscreen$.pipe(map((fullscreen) => fullscreen ? 'ShrinkIcon' : 'ExpandIcon')),
+ activated$: fullscreen$,
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ };
+}
diff --git a/packages/sheets-ui/src/menu/gridlines.menu.ts b/packages/sheets-ui/src/menu/gridlines.menu.ts
index 0760e57101..4e61049f7d 100644
--- a/packages/sheets-ui/src/menu/gridlines.menu.ts
+++ b/packages/sheets-ui/src/menu/gridlines.menu.ts
@@ -43,7 +43,7 @@ export function ToggleGridlinesMenuFactory(accessor: IAccessor): IMenuButtonItem
id: ToggleGridlinesCommand.id,
type: MenuItemType.BUTTON,
tooltip: 'sheets-ui.toolbar.toggleGridlines',
- icon: 'HideGridlinesDoubleIcon',
+ icon: 'HideGridlinesIcon',
activated$: new Observable<boolean>((observer) => {
const getValue = () => {
const workbook = instanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET);
diff --git a/packages/sheets-ui/src/menu/schema.ts b/packages/sheets-ui/src/menu/schema.ts
index 5c6fb3420f..905ff9fcc2 100644
--- a/packages/sheets-ui/src/menu/schema.ts
+++ b/packages/sheets-ui/src/menu/schema.ts
@@ -50,7 +50,14 @@ import {
SetWorksheetRowIsAutoHeightCommand,
ToggleGridlinesCommand,
} from '@univerjs/sheets';
-import { ContextMenuGroup, ContextMenuPosition, RibbonPosition, RibbonStartGroup } from '@univerjs/ui';
+import {
+ ContextMenuGroup,
+ ContextMenuPosition,
+ RibbonPosition,
+ RibbonStartGroup,
+ RibbonViewGroup,
+ ToggleFullscreenOperation,
+} from '@univerjs/ui';
import {
SheetCopyCommand,
SheetCutCommand,
@@ -88,7 +95,13 @@ import {
import { RemoveColConfirmCommand, RemoveRowConfirmCommand } from '../commands/commands/remove-row-col-confirm.command';
import { RemoveSheetConfirmCommand } from '../commands/commands/remove-sheet-confirm.command';
import { SetOnceFormatPainterCommand } from '../commands/commands/set-format-painter.command';
-import { SetColumnFrozenCommand, SetFirstColumnFrozenCommand, SetFirstRowFrozenCommand, SetRowFrozenCommand, SetSelectionFrozenCommand } from '../commands/commands/set-frozen.command';
+import {
+ SetColumnFrozenCommand,
+ SetFirstColumnFrozenCommand,
+ SetFirstRowFrozenCommand,
+ SetRowFrozenCommand,
+ SetSelectionFrozenCommand,
+} from '../commands/commands/set-frozen.command';
import { SetWorksheetColAutoWidthCommand } from '../commands/commands/set-worksheet-auto-col-width.command';
import { ShowMenuListCommand } from '../commands/commands/unhide.command';
import {
@@ -97,9 +110,27 @@ import {
} from '../commands/commands/worksheet-protection.command';
import { RenameSheetOperation } from '../commands/operations/rename-sheet.operation';
import { CellBorderSelectorMenuItemFactory } from './border.menu';
-import { CLEAR_SELECTION_MENU_ID, ClearSelectionAllMenuItemFactory, ClearSelectionAllToolbarMenuItemFactory, ClearSelectionContentMenuItemFactory, ClearSelectionFormatMenuItemFactory, ClearSelectionMenuItemFactory } from './clear.menu';
-import { DELETE_RANGE_MENU_ID, DeleteRangeMenuItemFactory, DeleteRangeMoveLeftMenuItemFactory, DeleteRangeMoveUpMenuItemFactory, RemoveColMenuItemFactory, RemoveRowMenuItemFactory } from './delete.menu';
-import { FontSizeDecreaseMenuItemFactory, FontSizeIncreaseMenuItemFactory, FontSizeSelectorMenuItemFactory } from './font.menu';
+import {
+ CLEAR_SELECTION_MENU_ID,
+ ClearSelectionAllMenuItemFactory,
+ ClearSelectionAllToolbarMenuItemFactory,
+ ClearSelectionContentMenuItemFactory,
+ ClearSelectionFormatMenuItemFactory,
+ ClearSelectionMenuItemFactory,
+} from './clear.menu';
+import {
+ DELETE_RANGE_MENU_ID,
+ DeleteRangeMenuItemFactory,
+ DeleteRangeMoveLeftMenuItemFactory,
+ DeleteRangeMoveUpMenuItemFactory,
+ RemoveColMenuItemFactory,
+ RemoveRowMenuItemFactory,
+} from './delete.menu';
+import {
+ FontSizeDecreaseMenuItemFactory,
+ FontSizeIncreaseMenuItemFactory,
+ FontSizeSelectorMenuItemFactory,
+} from './font.menu';
import {
CancelFrozenMenuItemFactory,
FrozenColMenuItemFactory,
@@ -110,10 +141,13 @@ import {
SHEET_FROZEN_COLUMN_HEADER_MENU_ID,
SHEET_FROZEN_MENU_ID,
SHEET_FROZEN_ROW_HEADER_MENU_ID,
+ SHEET_FROZEN_TOOLBAR_MENU_ID,
SheetFrozenColumnHeaderMenuItemFactory,
SheetFrozenMenuItemFactory,
SheetFrozenRowHeaderMenuItemFactory,
+ SheetFrozenToolbarMenuItemFactory,
} from './frozen.menu';
+import { FullscreenMenuItemFactory } from './fullscreen.menu';
import { ToggleGridlinesMenuFactory } from './gridlines.menu';
import {
CELL_INSERT_MENU_ID,
@@ -163,7 +197,13 @@ import {
VerticalAlignMenuItemFactory,
WrapTextMenuItemFactory,
} from './menu';
-import { CellMergeAllMenuItemFactory, CellMergeCancelMenuItemFactory, CellMergeHorizontalMenuItemFactory, CellMergeMenuItemFactory, CellMergeVerticalMenuItemFactory } from './merge.menu';
+import {
+ CellMergeAllMenuItemFactory,
+ CellMergeCancelMenuItemFactory,
+ CellMergeHorizontalMenuItemFactory,
+ CellMergeMenuItemFactory,
+ CellMergeVerticalMenuItemFactory,
+} from './merge.menu';
import {
SHEET_PERMISSION_CONTEXT_MENU_ID,
sheetPermissionAddProtectContextMenuFactory,
@@ -186,6 +226,7 @@ import {
ShowMenuItemFactory,
} from './sheet.menu';
import { Text2NumberContextMenuItemFactory, TEXT_TO_NUMBER_CONTEXT_MENU_ID } from './text-to-number.menu';
+import { ZOOM_RATIO_MENU_ID, ZoomRatioMenuItemFactory } from './zoom.menu';
export const menuSchema: MenuSchemaType = {
[RibbonPosition.START]: {
@@ -302,6 +343,28 @@ export const menuSchema: MenuSchemaType = {
},
},
},
+ [RibbonPosition.VIEW]: {
+ [RibbonViewGroup.DISPLAY]: {
+ [SHEET_FROZEN_TOOLBAR_MENU_ID]: {
+ order: 0,
+ menuItemFactory: SheetFrozenToolbarMenuItemFactory,
+ },
+ [ZOOM_RATIO_MENU_ID]: {
+ order: 1,
+ menuItemFactory: ZoomRatioMenuItemFactory,
+ },
+ [ToggleFullscreenOperation.id]: {
+ order: 2,
+ menuItemFactory: FullscreenMenuItemFactory,
+ },
+ },
+ [RibbonViewGroup.VISIBILITY]: {
+ [ToggleGridlinesCommand.id]: {
+ order: 0,
+ menuItemFactory: ToggleGridlinesMenuFactory,
+ },
+ },
+ },
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.QUICK]: ({
quickLayout: 'tile',
diff --git a/packages/sheets-ui/src/menu/zoom.menu.ts b/packages/sheets-ui/src/menu/zoom.menu.ts
new file mode 100644
index 0000000000..1ba23958c9
--- /dev/null
+++ b/packages/sheets-ui/src/menu/zoom.menu.ts
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IAccessor } from '@univerjs/core';
+import type { IMenuButtonItem } from '@univerjs/ui';
+import type { LocaleKey } from '../locale/types';
+import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
+import { Observable } from 'rxjs';
+import { SetZoomRatioFromToolbarCommand } from '../commands/commands/set-zoom-ratio-from-toolbar.command';
+import { SetZoomRatioOperation } from '../commands/operations/set-zoom-ratio.operation';
+import { SHEET_ZOOM_RANGE } from '../common/keys';
+import { SHEET_ZOOM_INPUT_COMPONENT } from '../views/sheet-slider/SheetZoomInput';
+import { deriveStateFromActiveSheet$ } from './menu-util';
+
+export const ZOOM_RATIO_MENU_ID = 'sheet.menu.zoom-ratio';
+
+const ZOOM_RATIO_LIST = [50, 75, 100, 125, 150, 175, 200, 400];
+
+function getZoomRatioValue$(accessor: IAccessor) {
+ const commandService = accessor.get(ICommandService);
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+
+ return deriveStateFromActiveSheet$(univerInstanceService, 100, ({ worksheet }) => new Observable<number>((subscriber) => {
+ const update = () => subscriber.next(Math.round(worksheet.getZoomRatio() * 100));
+ const disposable = commandService.onCommandExecuted((command) => {
+ if (command.id === SetZoomRatioOperation.id) update();
+ });
+
+ update();
+ return disposable.dispose;
+ }));
+}
+
+export function ZoomRatioMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey, number> {
+ return {
+ id: ZOOM_RATIO_MENU_ID,
+ commandId: SetZoomRatioFromToolbarCommand.id,
+ type: MenuItemType.BUTTON,
+ label: {
+ name: SHEET_ZOOM_INPUT_COMPONENT,
+ props: {
+ min: SHEET_ZOOM_RANGE[0],
+ max: SHEET_ZOOM_RANGE[1],
+ shortcuts: ZOOM_RATIO_LIST,
+ },
+ },
+ value$: getZoomRatioValue$(accessor),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
+ };
+}
diff --git a/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx b/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx
index 4e0d731404..2c002b5145 100644
--- a/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx
+++ b/packages/sheets-ui/src/views/menu-item-frozen/MenuItemFrozen.tsx
@@ -19,7 +19,7 @@ import type { LocaleKey } from '../../locale/types';
import type { IMenuItemFrozenProps } from './interface';
import { LocaleService, Tools } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';
-import { IContextMenuService, useDependency } from '@univerjs/ui';
+import { useDependency } from '@univerjs/ui';
import { useEffect, useState } from 'react';
const defaultValue = {
@@ -27,38 +27,34 @@ const defaultValue = {
col: 'A',
};
+function getFrozenValue(selection?: ISelectionWithStyle | null) {
+ if (!selection) return defaultValue;
+
+ const { primary, range } = selection;
+ const row = primary?.startRow ?? range.startRow;
+ const col = primary?.startColumn ?? range.startColumn;
+
+ return {
+ row: row === 0 ? '1' : String(row),
+ col: col === 0 ? 'A' : Tools.chatAtABC(col - 1),
+ };
+}
+
export const MenuItemFrozen = (props: IMenuItemFrozenProps) => {
const { type } = props;
const localeService = useDependency(LocaleService);
- const contextMenuService = useDependency(IContextMenuService);
const selectionManagerService = useDependency(SheetsSelectionsService);
- const [value, setValue] = useState<{
- row: string;
- col: string;
- }>(defaultValue);
-
- const updateValue = (selection: ISelectionWithStyle) => {
- if (!selection) {
- return;
- }
+ const [value, setValue] = useState(() => getFrozenValue(selectionManagerService.getCurrentLastSelection() as ISelectionWithStyle));
- const { primary, range } = selection;
- const row = primary?.startRow ?? range.startRow;
- const col = primary?.startColumn ?? range.startColumn;
-
- setValue({
- row: row === 0 ? '1' : String(row),
- col: col === 0 ? 'A' : Tools.chatAtABC(col - 1),
+ useEffect(() => {
+ const subscription = selectionManagerService.selectionChanged$.subscribe((selections) => {
+ setValue(getFrozenValue(selections?.[selections.length - 1]));
});
- };
- useEffect(() => {
- if (contextMenuService.visible) {
- updateValue(selectionManagerService.getCurrentLastSelection() as ISelectionWithStyle);
- }
- }, [contextMenuService.visible]);
+ return () => subscription.unsubscribe();
+ }, [selectionManagerService]);
return (
<>
diff --git a/packages/sheets-ui/src/views/sheet-slider/SheetZoomInput.tsx b/packages/sheets-ui/src/views/sheet-slider/SheetZoomInput.tsx
new file mode 100644
index 0000000000..44a7e4bf38
--- /dev/null
+++ b/packages/sheets-ui/src/views/sheet-slider/SheetZoomInput.tsx
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IZoomInputProps } from '@univerjs/ui';
+import { ICommandService } from '@univerjs/core';
+import { useDependency, ZoomInput } from '@univerjs/ui';
+import { SetZoomRatioFromToolbarCommand } from '../../commands/commands/set-zoom-ratio-from-toolbar.command';
+
+export const SHEET_ZOOM_INPUT_COMPONENT = 'SHEET_ZOOM_INPUT_COMPONENT';
+
+export function SheetZoomInput(props: Omit<IZoomInputProps, 'className' | 'onChange'>) {
+ const commandService = useDependency(ICommandService);
+
+ return (
+ <ZoomInput
+ {...props}
+ className="
+ !univer-bg-transparent
+ dark:!univer-bg-transparent
+ "
+ onChange={(value) => commandService.executeCommand(SetZoomRatioFromToolbarCommand.id, { value })}
+ />
+ );
+}
diff --git a/packages/slides-ui/package.json b/packages/slides-ui/package.json
index fe2efb2199..9c0c342fb9 100644
--- a/packages/slides-ui/package.json
+++ b/packages/slides-ui/package.json
@@ -80,7 +80,7 @@
"@univerjs/docs-ui": "workspace:*",
"@univerjs/drawing": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/slides": "workspace:*",
"@univerjs/ui": "workspace:*"
},
diff --git a/packages/thread-comment-ui/package.json b/packages/thread-comment-ui/package.json
index b4c2592d02..d866ac121f 100644
--- a/packages/thread-comment-ui/package.json
+++ b/packages/thread-comment-ui/package.json
@@ -77,7 +77,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@univerjs/thread-comment": "workspace:*",
"@univerjs/ui": "workspace:*"
},
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 5b2ef4f482..9407990a81 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -90,7 +90,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/design": "workspace:*",
"@univerjs/engine-render": "workspace:*",
- "@univerjs/icons": "1.25.0",
+ "@univerjs/icons": "1.29.0",
"@wendellhu/redi": "1.1.2"
},
"devDependencies": {
diff --git a/packages/ui/src/commands/operations/__tests__/toggle-fullscreen.operation.spec.ts b/packages/ui/src/commands/operations/__tests__/toggle-fullscreen.operation.spec.ts
new file mode 100644
index 0000000000..2fdd114746
--- /dev/null
+++ b/packages/ui/src/commands/operations/__tests__/toggle-fullscreen.operation.spec.ts
@@ -0,0 +1,59 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IAccessor } from '@univerjs/core';
+import { describe, expect, it, vi } from 'vitest';
+import { ILayoutService } from '../../../services/layout/layout.service';
+import { ToggleFullscreenOperation } from '../toggle-fullscreen.operation';
+
+function createAccessor(rootContainerElement: HTMLElement | null) {
+ return {
+ get: (token: unknown) => {
+ if (token === ILayoutService) return { rootContainerElement };
+ throw new Error('Unknown token');
+ },
+ } as IAccessor;
+}
+
+describe('ToggleFullscreenOperation', () => {
+ it('requests fullscreen for the Univer root container', () => {
+ const requestFullscreen = vi.fn(async () => undefined);
+ const root = {
+ ownerDocument: { fullscreenElement: null },
+ requestFullscreen,
+ } as unknown as HTMLElement;
+
+ expect(ToggleFullscreenOperation.handler(createAccessor(root), {})).toBe(true);
+ expect(requestFullscreen).toHaveBeenCalledOnce();
+ });
+
+ it('exits fullscreen when the Univer root container is fullscreen', () => {
+ const exitFullscreen = vi.fn(async () => undefined);
+ const root = {} as HTMLElement;
+ Object.assign(root, {
+ ownerDocument: { fullscreenElement: root, exitFullscreen },
+ requestFullscreen: vi.fn(),
+ });
+
+ expect(ToggleFullscreenOperation.handler(createAccessor(root), {})).toBe(true);
+ expect(exitFullscreen).toHaveBeenCalledOnce();
+ expect(root.requestFullscreen).not.toHaveBeenCalled();
+ });
+
+ it('does nothing when the root container is unavailable', () => {
+ expect(ToggleFullscreenOperation.handler(createAccessor(null), {})).toBe(false);
+ });
+});
diff --git a/packages/ui/src/commands/operations/toggle-fullscreen.operation.ts b/packages/ui/src/commands/operations/toggle-fullscreen.operation.ts
new file mode 100644
index 0000000000..a667b2ffb0
--- /dev/null
+++ b/packages/ui/src/commands/operations/toggle-fullscreen.operation.ts
@@ -0,0 +1,44 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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';
+import { ILayoutService } from '../../services/layout/layout.service';
+
+export const ToggleFullscreenOperation: IOperation = {
+ id: 'base-ui.operation.toggle-fullscreen',
+ type: CommandType.OPERATION,
+ handler: (accessor) => {
+ const root = accessor.get(ILayoutService).rootContainerElement;
+ if (!root) return false;
+
+ const document = root.ownerDocument;
+
+ try {
+ if (document.fullscreenElement) {
+ if (!document.exitFullscreen) return false;
+ void document.exitFullscreen().catch(() => {});
+ } else {
+ if (!root.requestFullscreen) return false;
+ void root.requestFullscreen().catch(() => {});
+ }
+
+ return true;
+ } catch {
+ return false;
+ }
+ },
+};
diff --git a/packages/ui/src/controllers/__tests__/shared-shortcut.controller.spec.ts b/packages/ui/src/controllers/__tests__/shared-shortcut.controller.spec.ts
index a7e4decacd..8faa6d4598 100644
--- a/packages/ui/src/controllers/__tests__/shared-shortcut.controller.spec.ts
+++ b/packages/ui/src/controllers/__tests__/shared-shortcut.controller.spec.ts
@@ -71,9 +71,11 @@ describe('shared shortcut items', () => {
describe('SharedController', () => {
it('should register clipboard commands and shared shortcuts on initialize', () => {
const registerMultipleCommand = vi.fn(() => ({ dispose: vi.fn() }));
+ const registerCommand = vi.fn(() => ({ dispose: vi.fn() }));
const registerShortcut = vi.fn(() => ({ dispose: vi.fn() }));
const commandService = {
+ registerCommand,
registerMultipleCommand,
};
const shortcutService = {
@@ -83,6 +85,9 @@ describe('SharedController', () => {
const controller = new SharedController(shortcutService as any, commandService as any);
expect(registerMultipleCommand).toHaveBeenCalledTimes(3);
+ expect(registerCommand).toHaveBeenCalledWith(expect.objectContaining({
+ id: 'base-ui.operation.toggle-fullscreen',
+ }));
expect(registerShortcut).toHaveBeenCalledTimes(5);
controller.dispose();
diff --git a/packages/ui/src/controllers/components.controller.ts b/packages/ui/src/controllers/components.controller.ts
index 38346011e8..48694a18f7 100644
--- a/packages/ui/src/controllers/components.controller.ts
+++ b/packages/ui/src/controllers/components.controller.ts
@@ -16,7 +16,7 @@
import { Disposable, Inject } from '@univerjs/core';
import { ColorPicker } from '@univerjs/design';
-import { IncreaseIcon, MoreDownIcon, RedoIcon, ReduceIcon, ShortcutIcon, UndoIcon } from '@univerjs/icons';
+import { ExpandIcon, IncreaseIcon, MoreDownIcon, RedoIcon, ReduceIcon, ShortcutIcon, ShrinkIcon, UndoIcon } from '@univerjs/icons';
import { ShortcutPanelComponentName } from '../commands/operations/toggle-shortcut-panel.operation';
import { ComponentManager, IconManager } from '../common';
import { COLOR_PICKER_COMPONENT } from '../views/color-picker/interface';
@@ -46,11 +46,13 @@ export class ComponentsController extends Disposable {
private _registerIcons(): void {
this.disposeWithMe(this._iconManager.register({
+ ExpandIcon,
IncreaseIcon,
MoreDownIcon,
RedoIcon,
ReduceIcon,
ShortcutIcon,
+ ShrinkIcon,
UndoIcon,
}));
}
diff --git a/packages/ui/src/controllers/shared-shortcut.controller.ts b/packages/ui/src/controllers/shared-shortcut.controller.ts
index 3786935bb5..5b6ef65561 100644
--- a/packages/ui/src/controllers/shared-shortcut.controller.ts
+++ b/packages/ui/src/controllers/shared-shortcut.controller.ts
@@ -25,6 +25,7 @@ import {
RedoCommand,
UndoCommand,
} from '@univerjs/core';
+import { ToggleFullscreenOperation } from '../commands/operations/toggle-fullscreen.operation';
import { CopyCommand, CutCommand, PasteCommand } from '../services/clipboard/clipboard.command';
import { KeyCode, MetaKeys } from '../services/shortcut/keycode';
import { IShortcutService } from '../services/shortcut/shortcut.service';
@@ -121,6 +122,7 @@ export class SharedController extends Disposable {
}
private _registerCommands(): void {
+ this.disposeWithMe(this._commandService.registerCommand(ToggleFullscreenOperation));
[CutCommand, CopyCommand, PasteCommand].forEach((command) =>
this.disposeWithMe(this._commandService.registerMultipleCommand(command))
);
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index 2b2ae7b7f2..9c5cd902d9 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -16,6 +16,7 @@
import './global.css';
+export { ToggleFullscreenOperation } from './commands/operations/toggle-fullscreen.operation';
export { ToggleShortcutPanelOperation } from './commands/operations/toggle-shortcut-panel.operation';
export * from './common';
export { getHeaderFooterMenuHiddenObservable, getMenuHiddenObservable } from './common/menu-hidden-observable';
diff --git a/packages/ui/src/services/font.service.spec.ts b/packages/ui/src/services/font.service.spec.ts
index 8fea146850..cee9d07db3 100644
--- a/packages/ui/src/services/font.service.spec.ts
+++ b/packages/ui/src/services/font.service.spec.ts
@@ -58,6 +58,27 @@ describe('FontService', () => {
expect(service.getFontByValue('Inter')).toBeUndefined();
});
+ it('uses the filtered reference catalog as the default font list', () => {
+ const values = createService().getFonts().map((font) => font.value);
+
+ expect(values).toHaveLength(197);
+ expect(values.slice(0, 8)).toEqual([
+ '宋体',
+ 'Arial',
+ 'Baskerville',
+ 'Comic Sans MS',
+ 'Courier New',
+ 'Helvetica',
+ 'Times New Roman',
+ 'Verdana',
+ ]);
+ expect(values).toContain('Zapfino');
+ expect(values).not.toContain('Microsoft YaHei');
+ expect(values).not.toContain('正文字体');
+ expect(values.some((value) => value.startsWith('MiSans'))).toBe(false);
+ expect(values.some((value) => value.toUpperCase().includes('WPS'))).toBe(false);
+ });
+
it('rejects duplicate font values to keep font selection stable', () => {
const service = createService();
const arial = service.getFontByValue('Arial')!;
diff --git a/packages/ui/src/services/font.service.ts b/packages/ui/src/services/font.service.ts
index 55680fda45..44da1767f7 100644
--- a/packages/ui/src/services/font.service.ts
+++ b/packages/ui/src/services/font.service.ts
@@ -44,59 +44,207 @@ export interface IFontConfig {
category?: 'sans-serif' | 'serif' | 'monospace' | 'display' | 'handwriting';
}
-const DEFAULT_FONT_LIST: IFontConfig[] = [{
- value: 'Arial',
- label: 'ui.fontFamily.arial',
- category: 'sans-serif',
-}, {
- value: 'Times New Roman',
- label: 'ui.fontFamily.times-new-roman',
- category: 'serif',
-}, {
- value: 'Tahoma',
- label: 'ui.fontFamily.tahoma',
- category: 'sans-serif',
-}, {
- value: 'Verdana',
- label: 'ui.fontFamily.verdana',
- category: 'sans-serif',
-}, {
- value: 'Microsoft YaHei',
- label: 'ui.fontFamily.microsoft-yahei',
- category: 'sans-serif',
-}, {
- value: 'SimSun',
- label: 'ui.fontFamily.simsun',
- category: 'serif',
-}, {
- value: 'SimHei',
- label: 'ui.fontFamily.simhei',
- category: 'sans-serif',
-}, {
- value: 'Kaiti',
- label: 'ui.fontFamily.kaiti',
- category: 'serif',
-}, {
- value: 'FangSong',
- label: 'ui.fontFamily.fangsong',
- category: 'serif',
-}, {
- value: 'NSimSun',
- label: 'ui.fontFamily.nsimsun',
- category: 'serif',
-}, {
- value: 'STXinwei',
- label: 'ui.fontFamily.stxinwei',
- category: 'serif',
-}, {
- value: 'STXingkai',
- label: 'ui.fontFamily.stxingkai',
- category: 'serif',
-}, {
- value: 'STLiti',
- label: 'ui.fontFamily.stliti',
- category: 'serif',
-}];
+const DEFAULT_FONT_NAMES = [
+ '宋体',
+ 'Arial',
+ 'Baskerville',
+ 'Comic Sans MS',
+ 'Courier New',
+ 'Helvetica',
+ 'Times New Roman',
+ 'Verdana',
+ 'Apple LiGothic',
+ 'Apple LiSung',
+ 'Hei',
+ 'Kai',
+ 'LiHei Pro',
+ 'LiSong Pro',
+ 'STFangsong',
+ 'STHeiti',
+ 'STKaiti',
+ 'STSong',
+ '报隶-繁',
+ '报隶-简',
+ '冬青黑体简体中文',
+ '黑体-繁',
+ '黑体-简',
+ '华文仿宋',
+ '华文楷体',
+ '华文宋体',
+ '楷体-繁',
+ '楷体-简',
+ '兰亭黑-繁',
+ '兰亭黑-简',
+ '隶变-繁',
+ '隶变-简',
+ '凌慧体-繁',
+ '凌慧体-简',
+ '翩翩体-繁',
+ '翩翩体-简',
+ '苹方-繁',
+ '苹方-港',
+ '苹方-简',
+ '手札体-繁',
+ '手札体-简',
+ '宋体-繁',
+ '宋体-简',
+ '娃娃体-繁',
+ '娃娃体-简',
+ '魏碑-繁',
+ '魏碑-简',
+ '行楷-繁',
+ '行楷-简',
+ '雅痞-繁',
+ '雅痞-简',
+ '圆体-繁',
+ '圆体-简',
+ 'Arial Black',
+ 'Big Caslon',
+ 'Courier',
+ 'Didot',
+ 'Futura',
+ 'Georgia',
+ 'Helvetica Neue',
+ 'Optima',
+ 'Times',
+ 'Tahoma',
+ 'BIZ UDGothic',
+ 'BIZ UDMincho',
+ 'Hiragino Maru Gothic Pro',
+ 'Hiragino Maru Gothic ProN',
+ 'Hiragino Mincho Pro',
+ 'Hiragino Mincho ProN',
+ 'Hiragino Sans',
+ 'Klee',
+ 'Osaka',
+ 'Toppan Bunkyu Gothic',
+ 'Toppan Bunkyu Midashi Gothic',
+ 'Toppan Bunkyu Midashi Mincho',
+ 'Toppan Bunkyu Mincho',
+ 'Tsukushi A Round Gothic',
+ 'Tsukushi B Round Gothic',
+ 'YuKyokasho',
+ 'YuKyokasho Yoko',
+ 'YuMincho +36p Kana',
+ 'American Typewriter',
+ 'Andale Mono',
+ 'Apple Chancery',
+ 'Apple SD Gothic Neo',
+ 'Apple Symbols',
+ 'AppleGothic',
+ 'AppleMyungjo',
+ 'Arial Unicode MS',
+ 'Athelas',
+ 'Avenir',
+ 'Avenir Next',
+ 'Avenir Next Condensed',
+ 'Ayuthaya',
+ 'Bangla MN',
+ 'Bangla Sangam MN',
+ 'Bauhaus 93',
+ 'Bodoni 72',
+ 'Bodoni 72 Oldstyle',
+ 'Bodoni 72 Smallcaps',
+ 'Bodoni Ornaments',
+ 'Bookshelf Symbol 7',
+ 'Bradley Hand',
+ 'Chalkboard',
+ 'Chalkboard SE',
+ 'Chalkduster',
+ 'Charter',
+ 'Cochin',
+ 'Copperplate',
+ 'Devanagari Sangam MN',
+ 'Din Alternate',
+ 'Euphemia UCAS',
+ 'Galvji',
+ 'Geneva',
+ 'Gill Sans',
+ 'Gujarati Sangam MN',
+ 'GungSeo',
+ 'Gurmukhi MN',
+ 'Gurmukhi Sangam MN',
+ 'HeadLineA',
+ 'Herculanum',
+ 'Hiragino Kaku Gothic Pro',
+ 'Hiragino Kaku Gothic ProN',
+ 'Hiragino Kaku Gothic Std',
+ 'Hiragino Kaku Gothic StdN',
+ 'Hoefler Text',
+ 'Impact',
+ 'InaiMathi',
+ 'Iowan Old Style',
+ 'Kannada MN',
+ 'Kannada Sangam MN',
+ 'Kefa',
+ 'Khmer MN',
+ 'Khmer Sangam MN',
+ 'Kohinoor Bangla',
+ 'Kohinoor Devanagari',
+ 'Kohinoor Telugu',
+ 'Krungthep',
+ 'Lao MN',
+ 'Lao Sangam MN',
+ 'Lucida Grande',
+ 'Luminari',
+ 'Malayalam MN',
+ 'Malayalam Sangam MN',
+ 'Marion',
+ 'Marker Felt',
+ 'Menlo',
+ 'Microsoft Sans Serif',
+ 'Modern No. 20',
+ 'Monaco',
+ 'Mukta Mahee',
+ 'Nanum Brush Script',
+ 'Nanum Gothic',
+ 'Nanum Myeongjo',
+ 'Nanum Pen Script',
+ 'Noteworthy',
+ 'Oriya MN',
+ 'Oriya Sangam MN',
+ 'Palatino',
+ 'Papyrus',
+ 'PCMyungjo',
+ 'Phosphate',
+ 'PilGi',
+ 'Plantagenet Cherokee',
+ 'PT Mono',
+ 'PT Sans',
+ 'PT Sans Caption',
+ 'PT Serif',
+ 'PT Serif Caption',
+ 'Rockwell',
+ 'Sathu',
+ 'Savoye LET',
+ 'Seravek',
+ 'Shree Devanagari 714',
+ 'SignPainter',
+ 'Silom',
+ 'Sinhala MN',
+ 'Sinhala Sangam MN',
+ 'Skia',
+ 'Snell Roundhand',
+ 'STIXGeneral',
+ 'Sukhumvit Set',
+ 'Superclarendon',
+ 'Tamil MN',
+ 'Tamil Sangam MN',
+ 'Telugu MN',
+ 'Telugu Sangam MN',
+ 'Trattatello',
+ 'Trebuchet MS',
+ 'Webdings',
+ 'Wingdings',
+ 'Wingdings 2',
+ 'Wingdings 3',
+ 'YuGothic',
+ 'YuGothic Light',
+ 'YuGothic Medium',
+ 'Zapfino',
+] as const;
+
+const DEFAULT_FONT_LIST: IFontConfig[] = DEFAULT_FONT_NAMES.map((value) => ({ value, label: value }));
export interface IFontService {
/**
diff --git a/packages/ui/src/services/menu/menu-manager.service.ts b/packages/ui/src/services/menu/menu-manager.service.ts
index d1c73351f2..6902e03e4c 100644
--- a/packages/ui/src/services/menu/menu-manager.service.ts
+++ b/packages/ui/src/services/menu/menu-manager.service.ts
@@ -95,10 +95,10 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
[RibbonInsertGroup.EDIT]: {
order: 0,
},
- [RibbonInsertGroup.CELL]: {
+ [RibbonInsertGroup.MEDIA]: {
order: 1,
},
- [RibbonInsertGroup.MEDIA]: {
+ [RibbonInsertGroup.CELL]: {
order: 2,
},
[RibbonInsertGroup.OTHERS]: {
diff --git a/packages/ui/src/views/index.ts b/packages/ui/src/views/index.ts
index 10a5615959..6177f5e521 100644
--- a/packages/ui/src/views/index.ts
+++ b/packages/ui/src/views/index.ts
@@ -21,4 +21,4 @@ export * from './HeadingItem';
export { useScrollYOverContainer } from './hooks/layout';
-export { type ISliderProps, Slider } from './slider/index';
+export { type ISliderProps, type IZoomInputProps, Slider, ZoomInput } from './slider/index';
diff --git a/packages/ui/src/views/slider/Slider.tsx b/packages/ui/src/views/slider/Slider.tsx
index d6d795c593..63c28412ff 100644
--- a/packages/ui/src/views/slider/Slider.tsx
+++ b/packages/ui/src/views/slider/Slider.tsx
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-import type { IDropdownMenuProps } from '@univerjs/design';
import type { PointerEvent as ReactPointerEvent } from 'react';
import { LocaleService } from '@univerjs/core';
-import { borderClassName, Button, clsx, DropdownMenu, Input } from '@univerjs/design';
+import { borderClassName, Button, clsx } from '@univerjs/design';
import { useEffect, useRef, useState } from 'react';
import { IconManager } from '../../common';
import { useDependency, useObservable } from '../../utils/di';
+import { ZoomInput } from './ZoomInput';
export interface ISliderProps {
/** The value of slider. When range is false, use number, otherwise, use [number, number] */
@@ -72,21 +72,12 @@ export function Slider(props: ISliderProps) {
const isRtl = direction === 'rtl';
const sliderInnerRailRef = useRef<HTMLDivElement>(null);
- const isEditingZoomRef = useRef(false);
const dragValueRef = useRef(value);
const pendingDragValueRef = useRef<number | null>(null);
const lastCommittedDragValueRef = useRef(value);
const dragCommitTimerRef = useRef<number | null>(null);
- const [zoomListVisible, setZoomListVisible] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const [dragValue, setDragValue] = useState(value);
- const [zoomInputValue, setZoomInputValue] = useState(() => `${value}%`);
-
- useEffect(() => {
- if (!isEditingZoomRef.current) {
- setZoomInputValue(`${value}%`);
- }
- }, [value]);
useEffect(() => () => {
clearDragCommitTimer();
@@ -243,79 +234,12 @@ export function Slider(props: ISliderProps) {
window.addEventListener('pointerout', onPointerOut);
}
- function handleSelectZoomLevel(value: number) {
- if (disabled) return;
-
- setZoomListVisible(false);
- onChange && onChange(value);
- }
-
- function parseExactZoomInput(rawValue: string) {
- const normalizedValue = rawValue.trim().replace(/%$/, '').trim();
- if (normalizedValue === '') {
- return null;
- }
-
- const parsedValue = Number(normalizedValue);
- if (!Number.isFinite(parsedValue)) {
- return null;
- }
-
- return Math.round(clampValue(parsedValue));
- }
-
- function handleExactZoomFocus() {
- if (disabled) return;
-
- isEditingZoomRef.current = true;
- setZoomInputValue(String(value));
- }
-
- function commitExactZoomInput() {
- if (disabled) return;
- if (!isEditingZoomRef.current) return;
-
- const parsedValue = parseExactZoomInput(zoomInputValue);
- isEditingZoomRef.current = false;
-
- if (parsedValue == null) {
- setZoomInputValue(`${value}%`);
- return;
- }
-
- setZoomInputValue(`${parsedValue}%`);
- if (parsedValue !== value) {
- onChange && onChange(parsedValue);
- }
- }
-
- function handleExactZoomChange(value: string) {
- setZoomInputValue(value);
- }
-
- function handleInputKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
- e.stopPropagation();
-
- if (e.key === 'Enter') {
- e.preventDefault();
- commitExactZoomInput();
- e.currentTarget.blur();
- }
- }
-
- const items: IDropdownMenuProps['items'] = [{
- type: 'radio',
- value: value.toString(),
- options: shortcuts.map((item) => ({ value: item.toString(), label: `${item}%` })),
- onSelect: (value: string) => handleSelectZoomLevel(+value),
- }];
const visualValue = isDragging ? dragValue : value;
const sliderOffset = Math.min(Math.max(getSliderOffset(visualValue) ?? 0, 0), 100);
const handleOffset = isRtl ? 100 - sliderOffset : sliderOffset;
const ReduceIcon = iconManager.get('ReduceIcon');
const IncreaseIcon = iconManager.get('IncreaseIcon');
- const MoreDownIcon = iconManager.get('MoreDownIcon');
return (
<div
@@ -417,56 +341,14 @@ export function Slider(props: ISliderProps) {
<IncreaseIcon className="univer-text-gray-500" />
</Button>
- <div
- className={clsx(`
- univer-flex univer-h-6 univer-w-[68px] univer-flex-shrink-0 univer-items-center univer-overflow-hidden
- univer-rounded-md univer-border univer-border-gray-200 univer-bg-white
- dark:!univer-border-gray-600 dark:!univer-bg-gray-800
- `, {
- 'univer-opacity-60': disabled,
- })}
- >
- <Input
- className={`
- univer-box-border univer-h-6 univer-w-[52px] univer-border-none univer-bg-transparent
- [&_input:focus]:!univer-ring-0
- [&_input]:univer-h-6 [&_input]:univer-w-[52px] [&_input]:univer-border-none
- [&_input]:!univer-bg-transparent [&_input]:univer-px-1 [&_input]:univer-text-center
- [&_input]:univer-text-xs [&_input]:univer-tabular-nums
- `}
- inputClass="univer-w-[52px]"
- size="mini"
- value={zoomInputValue}
- disabled={disabled}
- type="text"
- onChange={handleExactZoomChange}
- onFocus={handleExactZoomFocus}
- onBlur={commitExactZoomInput}
- onKeyDown={handleInputKeyDown}
- />
-
- <DropdownMenu
- align="end"
- items={items}
- open={zoomListVisible}
- disabled={disabled}
- onOpenChange={setZoomListVisible}
- >
- <Button
- className="univer-h-6 univer-w-4 univer-rounded-none univer-p-0"
- size="small"
- variant="text"
- disabled={disabled}
- >
- <MoreDownIcon
- className="
- univer-size-3 univer-text-gray-500
- dark:!univer-text-gray-300
- "
- />
- </Button>
- </DropdownMenu>
- </div>
+ <ZoomInput
+ value={value}
+ min={min}
+ max={max}
+ shortcuts={shortcuts}
+ disabled={disabled}
+ onChange={onChange}
+ />
</div>
);
}
diff --git a/packages/ui/src/views/slider/ZoomInput.tsx b/packages/ui/src/views/slider/ZoomInput.tsx
new file mode 100644
index 0000000000..6ad2f54de2
--- /dev/null
+++ b/packages/ui/src/views/slider/ZoomInput.tsx
@@ -0,0 +1,170 @@
+/**
+ * Copyright 2023-present DreamNum Co., Ltd.
+ *
+ * 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 { IDropdownMenuProps } from '@univerjs/design';
+import { Button, clsx, DropdownMenu, Input } from '@univerjs/design';
+import { useEffect, useRef, useState } from 'react';
+import { IconManager } from '../../common';
+import { useDependency } from '../../utils/di';
+
+export interface IZoomInputProps {
+ value?: number;
+ min?: number;
+ max?: number;
+ shortcuts: number[];
+ disabled?: boolean;
+ className?: string;
+ onChange?: (value: number) => void;
+}
+
+export function ZoomInput(props: IZoomInputProps) {
+ const iconManager = useDependency(IconManager);
+ const {
+ value = 100,
+ min = 0,
+ max = 400,
+ shortcuts,
+ disabled = false,
+ className,
+ onChange,
+ } = props;
+ const isEditingRef = useRef(false);
+ const [listVisible, setListVisible] = useState(false);
+ const [inputValue, setInputValue] = useState(() => `${value}%`);
+
+ useEffect(() => {
+ if (!isEditingRef.current) {
+ setInputValue(`${value}%`);
+ }
+ }, [value]);
+
+ function clampValue(value: number) {
+ return Math.min(Math.max(value, min), max);
+ }
+
+ function handleSelect(value: number) {
+ if (disabled) return;
+
+ setListVisible(false);
+ onChange?.(value);
+ }
+
+ function parseInput(rawValue: string) {
+ const normalizedValue = rawValue.trim().replace(/%$/, '').trim();
+ if (normalizedValue === '') return null;
+
+ const parsedValue = Number(normalizedValue);
+ if (!Number.isFinite(parsedValue)) return null;
+
+ return Math.round(clampValue(parsedValue));
+ }
+
+ function handleFocus() {
+ if (disabled) return;
+
+ isEditingRef.current = true;
+ setInputValue(String(value));
+ }
+
+ function commitInput() {
+ if (disabled || !isEditingRef.current) return;
+
+ const parsedValue = parseInput(inputValue);
+ isEditingRef.current = false;
+
+ if (parsedValue == null) {
+ setInputValue(`${value}%`);
+ return;
+ }
+
+ setInputValue(`${parsedValue}%`);
+ if (parsedValue !== value) {
+ onChange?.(parsedValue);
+ }
+ }
+
+ function handleKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
+ e.stopPropagation();
+
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ commitInput();
+ e.currentTarget.blur();
+ }
+ }
+
+ const items: IDropdownMenuProps['items'] = [{
+ type: 'radio',
+ value: value.toString(),
+ options: shortcuts.map((item) => ({ value: item.toString(), label: `${item}%` })),
+ onSelect: (value: string) => handleSelect(+value),
+ }];
+ const MoreDownIcon = iconManager.get('MoreDownIcon');
+
+ return (
+ <div
+ className={clsx(`
+ univer-flex univer-h-6 univer-w-[68px] univer-flex-shrink-0 univer-items-center univer-overflow-hidden
+ univer-rounded-md univer-border univer-border-gray-200 univer-bg-white
+ dark:!univer-border-gray-600 dark:!univer-bg-gray-800
+ `, className, {
+ 'univer-opacity-60': disabled,
+ })}
+ onClick={(e) => e.stopPropagation()}
+ >
+ <Input
+ className={`
+ univer-box-border univer-h-6 univer-w-[52px] univer-border-none univer-bg-transparent
+ [&_input:focus]:!univer-ring-0
+ [&_input]:univer-h-6 [&_input]:univer-w-[52px] [&_input]:univer-border-none
+ [&_input]:!univer-bg-transparent [&_input]:univer-px-1 [&_input]:univer-text-center
+ [&_input]:univer-text-xs [&_input]:univer-tabular-nums
+ `}
+ inputClass="univer-w-[52px]"
+ size="mini"
+ value={inputValue}
+ disabled={disabled}
+ type="text"
+ onChange={setInputValue}
+ onFocus={handleFocus}
+ onBlur={commitInput}
+ onKeyDown={handleKeyDown}
+ />
+
+ <DropdownMenu
+ align="end"
+ items={items}
+ open={listVisible}
+ disabled={disabled}
+ onOpenChange={setListVisible}
+ >
+ <Button
+ className="univer-h-6 univer-w-4 univer-rounded-none univer-p-0"
+ size="small"
+ variant="text"
+ disabled={disabled}
+ >
+ <MoreDownIcon
+ className="
+ univer-size-3 univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ />
+ </Button>
+ </DropdownMenu>
+ </div>
+ );
+}
diff --git a/packages/ui/src/views/slider/index.ts b/packages/ui/src/views/slider/index.ts
index 8a2ed8d4fa..0fed34e666 100644
--- a/packages/ui/src/views/slider/index.ts
+++ b/packages/ui/src/views/slider/index.ts
@@ -15,3 +15,4 @@
*/
export { type ISliderProps, Slider } from './Slider';
+export { type IZoomInputProps, ZoomInput } from './ZoomInput';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 79a69b2872..66e4fcc121 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -112,8 +112,8 @@ importers:
specifier: workspace:*
version: link:../../packages/engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/mockdata':
specifier: workspace:*
version: link:../mockdata
@@ -355,11 +355,11 @@ importers:
devDependencies:
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/icons-svg':
- specifier: ^1.25.0
- version: 1.25.0
+ specifier: ^1.29.0
+ version: 1.29.0
typescript:
specifier: ^6.0.3
version: 6.0.3
@@ -500,8 +500,8 @@ importers:
specifier: workspace:*
version: link:../packages/find-replace
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/mockdata':
specifier: workspace:*
version: link:../common/mockdata
@@ -738,8 +738,8 @@ importers:
specifier: workspace:*
version: link:../design
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -873,8 +873,8 @@ importers:
specifier: ^1.3.0
version: 1.3.0(@types/[email protected])([email protected])
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1
@@ -1064,8 +1064,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1165,8 +1165,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1208,8 +1208,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/thread-comment':
specifier: workspace:*
version: link:../thread-comment
@@ -1257,8 +1257,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1331,8 +1331,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1442,8 +1442,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/ui':
specifier: workspace:*
version: link:../ui
@@ -1602,8 +1602,8 @@ importers:
specifier: workspace:*
version: link:../../common/shared
'@univerjs/icons-svg':
- specifier: ^1.25.0
- version: 1.25.0
+ specifier: ^1.29.0
+ version: 1.29.0
'@univerjs/sheets-formula':
specifier: workspace:*
version: link:../sheets-formula
@@ -1632,8 +1632,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -1687,8 +1687,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -1773,8 +1773,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -1945,8 +1945,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/rpc':
specifier: workspace:*
version: link:../rpc
@@ -2074,8 +2074,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2160,8 +2160,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2246,8 +2246,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2323,8 +2323,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2394,8 +2394,8 @@ importers:
specifier: workspace:*
version: link:../engine-formula
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2480,8 +2480,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2563,8 +2563,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
@@ -2627,8 +2627,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/protocol':
specifier: workspace:*
version: link:../protocol
@@ -2710,8 +2710,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/slides':
specifier: workspace:*
version: link:../slides
@@ -2794,8 +2794,8 @@ importers:
specifier: workspace:*
version: link:../docs-ui
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@univerjs/thread-comment':
specifier: workspace:*
version: link:../thread-comment
@@ -2840,8 +2840,8 @@ importers:
specifier: workspace:*
version: link:../engine-render
'@univerjs/icons':
- specifier: 1.25.0
+ specifier: 1.29.0
'@wendellhu/redi':
specifier: 1.1.2
version: 1.1.2([email protected])
@@ -6823,11 +6823,11 @@ packages:
resolution: {integrity: sha512-UexrHGnGTpbuQHct2ExOc2ZcFbGUS9FOesCxxqdBGcpI1BxYu/LZ6U8Aq6/72XtF/qRBk9nhuGHFJIXXMhPMdw==}
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
- '@univerjs/[email protected]':
- resolution: {integrity: sha512-s/uZnO9tzbPNmP3KSj5kLtCc8yrdjYJAkHapLCdUUzwjxV8ywNqMYv0SYvGMjJTkYyZ1Fj98Oo/A6qToKY6Nww==}
+ '@univerjs/[email protected]':
+ resolution: {integrity: sha512-aPCQrlIcI6XqHW6UG0AZoswlTHUKjiUWL3iArfmv+D0ORQhfEMkF5jeYbwXx3C0a0a8EkDc5JtMu0zo0SOjIfQ==}
- '@univerjs/[email protected]':
- resolution: {integrity: sha512-sd1tkGuHIarNPJ/zFtS4B1gPfFj119PN61pgZvPIpdnadT07RGMVT01GfOIkoDdVhhVGrR3/KszT+XsBs6CnHQ==}
+ '@univerjs/[email protected]':
+ resolution: {integrity: sha512-j+CwSb7aXVxG38EEfF/Q/Q6ay54pLbI4xpLeXO0I2ZRFyCJW7w1kP5a9mqGeEpGy0N0RpWMpxz/7la5rkUKCqg==}
peerDependencies:
react: 19.2.7
react-dom: 19.2.7
@@ -14515,9 +14515,9 @@ snapshots:
'@typescript-eslint/types': 8.63.0
eslint-visitor-keys: 5.0.1
- '@univerjs/[email protected]': {}
+ '@univerjs/[email protected]': {}
dependencies:
react: 19.2.7
react-dom: 19.2.7([email protected])