Skip to content

Commit

Permalink
feat(numfmt): currency shortcuts support internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Gggpound committed Aug 15, 2024
1 parent 2559483 commit bd100dd
Show file tree
Hide file tree
Showing 37 changed files with 1,003 additions and 111 deletions.
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@univerjs/engine-render": "workspace:*",
"@univerjs/facade": "workspace:*",
"@univerjs/find-replace": "workspace:*",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-docs-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-formula-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@univerjs/docs": "workspace:*",
"@univerjs/docs-ui": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/rpc": "workspace:*",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-formula/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@univerjs/core": "workspace:*"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-sheets-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uni-slides-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"react": "^16.9.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages-experimental/uniui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"dependencies": {
"@floating-ui/react-dom": "^2.1.1",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@xyflow/react": "^12.0.4",
"rc-util": "^5.43.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@rc-component/color-picker": "^2.0.1",
"@rc-component/trigger": "^2.2.1",
"@types/react-mentions": "^4.1.13",
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"rc-dialog": "^9.5.2",
"rc-dropdown": "^4.2.0",
"rc-input": "^1.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-hyper-link-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-thread-comment-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/drawing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"ot-json1": "^1.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/find-replace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/sheets-conditional-formatting-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2",
Expand All @@ -94,7 +94,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons-svg": "^0.1.72",
"@univerjs/icons-svg": "^0.1.74",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-formatting": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-conditional-formatting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/icons-svg": "^0.1.72",
"@univerjs/icons-svg": "^0.1.74",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
"dayjs": "^1.11.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-data-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-drawing-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-filter-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"rc-virtual-list": "^3.14.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-formula/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-hyper-link-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/sheets-hyper-link": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-numfmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@types/react": "^18.3.3",
Expand Down
18 changes: 18 additions & 0 deletions packages/sheets-numfmt/src/base/const/CURRENCY-SYMBOLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,21 @@ export const currencySymbols = [
'₾',
'₿',
];

export const currencyMap = {
US: '$', // United States Dollar
CA: 'C$', // Canadian Dollar
GB: '£', // British Pound Sterling
JP: '¥', // Japanese Yen
IN: '₹', // Indian Rupee
AU: 'A$', // Australian Dollar
ZH_CN: '¥', // Chinese Yuan
ZH_TW: '¥', // Chinese Yuan
KR: '₩', // South Korean Won
RU: '₽', // Russian Ruble
// Euro countries
AT: '€', BE: '€', CY: '€', EE: '€', FI: '€', FR: '€',
DE: '€', GR: '€', IE: '€', IT: '€', LV: '€', LT: '€',
LU: '€', MT: '€', NL: '€', PT: '€', SK: '€', SI: '€', ES: '€',
// Add more mappings as needed
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { CommandType, ICommandService, Range } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';

import { CURRENCYFORMAT } from '../../base/const/FORMATDETAIL';
import { currencyMap } from '../../base/const/CURRENCY-SYMBOLS';
import { NumfmtMenuController } from '../../controllers/numfmt.menu.controller';
import type { ISetNumfmtCommandParams } from './set-numfmt.command';
import { SetNumfmtCommand } from './set-numfmt.command';

Expand All @@ -28,14 +30,15 @@ export const SetCurrencyCommand: ICommand = {
handler: async (accessor: IAccessor) => {
const commandService = accessor.get(ICommandService);
const selectionManagerService = accessor.get(SheetsSelectionsService);

const numfmtMenuController = accessor.get(NumfmtMenuController);
const symbol = currencyMap[numfmtMenuController.getCurrencySymbol()] || '$';
const selections = selectionManagerService.getCurrentSelections();
if (!selections || !selections.length) {
return false;
}
const values: ISetNumfmtCommandParams['values'] = [];

const suffix = CURRENCYFORMAT[0].suffix('¥');
const suffix = CURRENCYFORMAT[0].suffix(symbol);

selections.forEach((selection) => {
Range.foreach(selection.range, (row, col) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/sheets-numfmt/src/controllers/numfmt.menu.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { Disposable, Inject, Injector, LifecycleStages, OnLifecycle } from '@uni
import type { MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuService } from '@univerjs/ui';

import { BehaviorSubject } from 'rxjs';
import { AddDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem, PercentMenuItem, SubtractDecimalMenuItem } from '../menu/menu';
import { MORE_NUMFMT_TYPE_KEY, MoreNumfmtType, Options, OPTIONS_KEY } from '../components/more-numfmt-type/MoreNumfmtType';
import type { currencyMap } from '../base/const/CURRENCY-SYMBOLS';

export interface IUniverSheetsNumfmtConfig {
menu: MenuConfig;
Expand All @@ -29,6 +31,8 @@ export const DefaultSheetNumfmtConfig = {};

@OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController)
export class NumfmtMenuController extends Disposable {
private _currencySymbol$ = new BehaviorSubject<keyof typeof currencyMap>('ZH_CN');
public currencySymbol$ = this._currencySymbol$.asObservable();
constructor(
private readonly _config: Partial<IUniverSheetsNumfmtConfig>,
@Inject(Injector) private _injector: Injector,
Expand All @@ -50,4 +54,12 @@ export class NumfmtMenuController extends Disposable {
this.disposeWithMe((this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)));
this.disposeWithMe((this._componentManager.register(OPTIONS_KEY, Options)));
}

public setCurrencySymbol(symbol: keyof typeof currencyMap) {
this._currencySymbol$.next(symbol);
}

public getCurrencySymbol() {
return this._currencySymbol$.getValue();
}
}
1 change: 1 addition & 0 deletions packages/sheets-numfmt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export { UniverSheetsNumfmtPlugin } from './numfmt-plugin';
export { getPatternPreview } from './utils/pattern';
export { NumfmtMenuController } from './controllers/numfmt.menu.controller';

// #region - all commands

Expand Down
25 changes: 21 additions & 4 deletions packages/sheets-numfmt/src/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import {
INumfmtService,
RangeProtectionPermissionEditPoint,
RemoveNumfmtMutation,
SetNumfmtMutation,
Expand All @@ -29,8 +28,9 @@ import type { IMenuSelectorItem } from '@univerjs/ui';
import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
import type { IAccessor } from '@univerjs/core';
import { merge, Observable } from 'rxjs';

import { deriveStateFromActiveSheet$, getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { currencyMap } from '../base/const/CURRENCY-SYMBOLS';

import { MENU_OPTIONS } from '../base/const/MENU-OPTIONS';
import { AddDecimalCommand } from '../commands/commands/add-decimal.command';
import { SetCurrencyCommand } from '../commands/commands/set-currency.command';
Expand All @@ -39,10 +39,28 @@ import { OpenNumfmtPanelOperator } from '../commands/operations/open.numfmt.pane
import { MORE_NUMFMT_TYPE_KEY, OPTIONS_KEY } from '../components/more-numfmt-type/MoreNumfmtType';
import { isPatternEqualWithoutDecimal } from '../utils/decimal';
import { SetPercentCommand } from '../commands/commands/set-percent.command';
import { NumfmtMenuController } from '../controllers/numfmt.menu.controller';

export const CurrencyMenuItem = (accessor: IAccessor) => {
return {
icon: 'RmbSingle',
icon: new Observable<string>((subscribe) => {
const numfmtMenuController = accessor.get(NumfmtMenuController);
function getIconKey(symbol: string) {
const iconMap: Record<string, string> = {
[currencyMap.US]: 'DollarSingle',
[currencyMap.RU]: 'RoubleSingle',
[currencyMap.ZH_CN]: 'RmbSingle',
[currencyMap.AT]: 'EuroSingle',
};
return iconMap[symbol] || 'DollarSingle';
}
const symbol = currencyMap[numfmtMenuController.getCurrencySymbol()] || '$';
subscribe.next(getIconKey(symbol));
return numfmtMenuController.currencySymbol$.subscribe((code) => {
const symbol = currencyMap[code] || '$';
subscribe.next(getIconKey(symbol));
});
}),
id: SetCurrencyCommand.id,
title: 'sheet.numfmt.currency',
tooltip: 'sheet.numfmt.currency',
Expand Down Expand Up @@ -99,7 +117,6 @@ export const PercentMenuItem = (accessor: IAccessor) => {
};

export const FactoryOtherMenuItem = (accessor: IAccessor): IMenuSelectorItem => {
const numfmtService = accessor.get(INumfmtService);
const univerInstanceService = accessor.get(IUniverInstanceService);
const commandService = accessor.get(ICommandService);
const localeService = accessor.get(LocaleService);
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-sort-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"rc-virtual-list": "^3.14.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-thread-comment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73"
"@univerjs/icons": "^0.1.74"
},
"devDependencies": {
"@univerjs/core": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/protocol": "0.1.39-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheets-zen-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"rxjs": ">=7.0.0"
},
"dependencies": {
"@univerjs/icons": "^0.1.73",
"@univerjs/icons": "^0.1.74",
"@univerjs/sheets": "workspace:*"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit bd100dd

Please sign in to comment.