@univerjs/sheets-numfmt-ui 0.25.1 → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1002 -933
- package/lib/es/index.js +1008 -939
- package/lib/index.js +1008 -939
- package/lib/types/controllers/components.controller.d.ts +24 -0
- package/lib/types/controllers/numfmt-alert-render.controller.d.ts +1 -4
- package/lib/types/controllers/{numfmt.controller.d.ts → ui.controller.d.ts} +0 -1
- package/lib/types/locale/types.d.ts +18 -0
- package/lib/types/menu/menu.d.ts +8 -41
- package/lib/types/views/{components/index.d.ts → SheetNumfmtPanel.d.ts} +1 -2
- package/lib/types/views/components/Accounting.d.ts +1 -2
- package/lib/types/views/components/Currency.d.ts +1 -2
- package/lib/types/views/components/CustomFormat.d.ts +1 -1
- package/lib/types/views/components/Date.d.ts +1 -1
- package/lib/types/views/components/General.d.ts +1 -2
- package/lib/types/views/components/MoreNumfmtType.d.ts +2 -2
- package/lib/types/views/components/ThousandthPercentile.d.ts +1 -1
- package/lib/types/views/components/interface.d.ts +1 -2
- package/lib/types/views/components/stories/Panel.stories.d.ts +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/es/index.js
CHANGED
|
@@ -2,19 +2,19 @@ import { CellValueType, CommandType, DEFAULT_TEXT_FORMAT_EXCEL, DependentOn, Dis
|
|
|
2
2
|
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
3
3
|
import { AddDecimalCommand, CURRENCYFORMAT, DATEFMTLISG, NUMBERFORMAT, SHEETS_NUMFMT_PLUGIN_CONFIG_KEY, SetCurrencyCommand, SetNumfmtCommand, SetPercentCommand, SheetsNumfmtCellContentController, SubtractDecimalCommand, UniverSheetsNumfmtPlugin, getCurrencyFormatOptions, getCurrencySymbolByLocale, getCurrencySymbolIconByLocale, getCurrencyType, getDateFormatOptions, getDecimalFromPattern, getNumberFormatOptions, getPatternPreview, getPatternPreviewIgnoreGeneral, getPatternType, isPatternHasDecimal, localeCurrencySymbolMap, setPatternDecimal } from "@univerjs/sheets-numfmt";
|
|
4
4
|
import { CellAlertManagerService, CellAlertType, HoverManagerService, IEditorBridgeService, IRepeatLastActionService, RepeatLastActionPermission, SheetSkeletonManagerService, UniverSheetsUIPlugin, deriveStateFromActiveSheet$, getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
|
|
5
|
+
import { AddDigitsIcon, CheckMarkIcon, DollarIcon, EuroIcon, PercentIcon, ReduceDigitsIcon, RmbIcon, RoubleIcon } from "@univerjs/icons";
|
|
6
|
+
import { ComponentManager, ILayoutService, IMenuManagerService, ISidebarService, IconManager, MenuItemType, RibbonStartGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
7
|
+
import { Button, Input, InputNumber, Select, SelectList, Separator, borderClassName, clsx, scrollbarClassName } from "@univerjs/design";
|
|
5
8
|
import { AFTER_CELL_EDIT, BEFORE_CELL_EDIT, INTERCEPTOR_POINT, INumfmtService, RangeProtectionPermissionEditPoint, RemoveNumfmtMutation, SetNumfmtMutation, SetRangeValuesCommand, SheetInterceptorService, SheetsSelectionsService, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, factoryRemoveNumfmtUndoMutation, factorySetNumfmtUndoMutation, transformCellsToRange } from "@univerjs/sheets";
|
|
6
|
-
import {
|
|
9
|
+
import { createContext, createElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
7
10
|
import { Observable, combineLatest, debounceTime, filter, merge as merge$1 } from "rxjs";
|
|
8
11
|
import { debounceTime as debounceTime$1, map, switchMap, tap } from "rxjs/operators";
|
|
9
|
-
import { Button, Input, InputNumber, Select, SelectList, Separator, borderClassName, clsx, scrollbarClassName } from "@univerjs/design";
|
|
10
|
-
import { createContext, createElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
11
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { CheckMarkIcon } from "@univerjs/icons";
|
|
13
13
|
import { stripErrorMargin } from "@univerjs/engine-formula";
|
|
14
14
|
|
|
15
15
|
//#region package.json
|
|
16
16
|
var name = "@univerjs/sheets-numfmt-ui";
|
|
17
|
-
var version = "0.
|
|
17
|
+
var version = "1.0.0-alpha.1";
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/config/config.ts
|
|
@@ -23,7 +23,57 @@ const configSymbol = Symbol(SHEETS_NUMFMT_UI_PLUGIN_CONFIG_KEY);
|
|
|
23
23
|
const defaultPluginConfig = {};
|
|
24
24
|
|
|
25
25
|
//#endregion
|
|
26
|
-
//#region
|
|
26
|
+
//#region src/commands/operations/close.numfmt.panel.operation.ts
|
|
27
|
+
const CloseNumfmtPanelOperator = {
|
|
28
|
+
id: "sheet.operation.close.numfmt.panel",
|
|
29
|
+
type: CommandType.OPERATION,
|
|
30
|
+
handler: () => true
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
35
|
+
function _typeof(o) {
|
|
36
|
+
"@babel/helpers - typeof";
|
|
37
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
38
|
+
return typeof o;
|
|
39
|
+
} : function(o) {
|
|
40
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
41
|
+
}, _typeof(o);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
46
|
+
function toPrimitive(t, r) {
|
|
47
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
48
|
+
var e = t[Symbol.toPrimitive];
|
|
49
|
+
if (void 0 !== e) {
|
|
50
|
+
var i = e.call(t, r || "default");
|
|
51
|
+
if ("object" != _typeof(i)) return i;
|
|
52
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
53
|
+
}
|
|
54
|
+
return ("string" === r ? String : Number)(t);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
59
|
+
function toPropertyKey(t) {
|
|
60
|
+
var i = toPrimitive(t, "string");
|
|
61
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
66
|
+
function _defineProperty(e, r, t) {
|
|
67
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
68
|
+
value: t,
|
|
69
|
+
enumerable: !0,
|
|
70
|
+
configurable: !0,
|
|
71
|
+
writable: !0
|
|
72
|
+
}) : e[r] = t, e;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
27
77
|
function __decorateParam(paramIndex, decorator) {
|
|
28
78
|
return function(target, key) {
|
|
29
79
|
decorator(target, key, paramIndex);
|
|
@@ -31,7 +81,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
31
81
|
}
|
|
32
82
|
|
|
33
83
|
//#endregion
|
|
34
|
-
//#region \0@oxc-project+runtime@0.
|
|
84
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
35
85
|
function __decorate(decorators, target, key, desc) {
|
|
36
86
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
37
87
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -40,332 +90,584 @@ function __decorate(decorators, target, key, desc) {
|
|
|
40
90
|
}
|
|
41
91
|
|
|
42
92
|
//#endregion
|
|
43
|
-
//#region src/controllers/
|
|
44
|
-
const
|
|
45
|
-
let
|
|
46
|
-
constructor(
|
|
93
|
+
//#region src/controllers/ui.controller.ts
|
|
94
|
+
const SHEET_NUMFMT_PANEL$1 = "SHEET_NUMFMT_PANEL";
|
|
95
|
+
let SheetNumfmtUIController = class SheetNumfmtUIController extends Disposable {
|
|
96
|
+
constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService, _sheetsNumfmtCellContentController) {
|
|
47
97
|
super();
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
98
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
99
|
+
this._themeService = _themeService;
|
|
100
|
+
this._univerInstanceService = _univerInstanceService;
|
|
101
|
+
this._commandService = _commandService;
|
|
102
|
+
this._selectionManagerService = _selectionManagerService;
|
|
103
|
+
this._renderManagerService = _renderManagerService;
|
|
53
104
|
this._numfmtService = _numfmtService;
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this
|
|
59
|
-
this
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const workbook = this._context.unit;
|
|
66
|
-
const worksheet = workbook.getActiveSheet();
|
|
67
|
-
if (!worksheet) return this._hideAlert();
|
|
68
|
-
const unitId = location.unitId;
|
|
69
|
-
const sheetId = location.subUnitId;
|
|
70
|
-
let numfmtValue;
|
|
71
|
-
const cellData = worksheet.getCell(location.row, location.col);
|
|
72
|
-
if (cellData === null || cellData === void 0 ? void 0 : cellData.s) {
|
|
73
|
-
const style = workbook.getStyles().get(cellData.s);
|
|
74
|
-
if (style === null || style === void 0 ? void 0 : style.n) numfmtValue = style.n;
|
|
75
|
-
}
|
|
76
|
-
if (!numfmtValue) numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);
|
|
77
|
-
if (!numfmtValue) {
|
|
78
|
-
this._hideAlert();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (isTextFormat(numfmtValue.pattern) && Tools.isDefine(cellData === null || cellData === void 0 ? void 0 : cellData.v) && isRealNum(cellData.v)) {
|
|
82
|
-
var _this$_configService$, _currentAlert$alert;
|
|
83
|
-
if ((_this$_configService$ = this._configService.getConfig(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY)) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.disableTextFormatAlert) return;
|
|
84
|
-
const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
|
|
85
|
-
const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
|
|
86
|
-
if (currentLoc && currentLoc.row === location.row && currentLoc.col === location.col && currentLoc.subUnitId === location.subUnitId && currentLoc.unitId === location.unitId) {
|
|
87
|
-
this._hideAlert();
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
this._cellAlertManagerService.showAlert({
|
|
91
|
-
type: CellAlertType.ERROR,
|
|
92
|
-
title: this._localeService.t("sheets-numfmt-ui.info.error"),
|
|
93
|
-
message: this._localeService.t("sheets-numfmt-ui.info.forceStringInfo"),
|
|
94
|
-
location,
|
|
95
|
-
width: 200,
|
|
96
|
-
height: 74,
|
|
97
|
-
key: ALERT_KEY
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
this._hideAlert();
|
|
103
|
-
}));
|
|
105
|
+
this._componentManager = _componentManager;
|
|
106
|
+
this._sidebarService = _sidebarService;
|
|
107
|
+
this._localeService = _localeService;
|
|
108
|
+
this._sheetsNumfmtCellContentController = _sheetsNumfmtCellContentController;
|
|
109
|
+
_defineProperty(this, "_previewPattern", "");
|
|
110
|
+
_defineProperty(this, "_sidebarDisposable", null);
|
|
111
|
+
this._initRealTimeRenderingInterceptor();
|
|
112
|
+
this._initCommands();
|
|
113
|
+
this._initCloseListener();
|
|
114
|
+
this._commandExecutedListener();
|
|
115
|
+
this._initNumfmtLocalChange();
|
|
104
116
|
}
|
|
105
|
-
|
|
106
|
-
this.disposeWithMe(this.
|
|
107
|
-
|
|
117
|
+
_initNumfmtLocalChange() {
|
|
118
|
+
this.disposeWithMe(merge$1(this._sheetsNumfmtCellContentController.locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
119
|
+
this._forceUpdate();
|
|
108
120
|
}));
|
|
109
121
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
let
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
newValues.push({
|
|
148
|
-
row,
|
|
149
|
-
col,
|
|
150
|
-
pattern,
|
|
151
|
-
type
|
|
122
|
+
openPanel() {
|
|
123
|
+
var _selectionManagerServ;
|
|
124
|
+
const sidebarService = this._sidebarService;
|
|
125
|
+
const selectionManagerService = this._selectionManagerService;
|
|
126
|
+
const commandService = this._commandService;
|
|
127
|
+
const univerInstanceService = this._univerInstanceService;
|
|
128
|
+
const numfmtService = this._numfmtService;
|
|
129
|
+
const localeService = this._localeService;
|
|
130
|
+
const range = (((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range)) || [])[0];
|
|
131
|
+
if (!range) return false;
|
|
132
|
+
const workbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
133
|
+
const sheet = workbook.getActiveSheet();
|
|
134
|
+
if (!sheet) return false;
|
|
135
|
+
const cellValue = sheet.getCellRaw(range.startRow, range.startColumn);
|
|
136
|
+
const numfmtValue = numfmtService.getValue(workbook.getUnitId(), sheet.getSheetId(), range.startRow, range.startColumn);
|
|
137
|
+
let pattern = "";
|
|
138
|
+
if (numfmtValue) pattern = numfmtValue.pattern;
|
|
139
|
+
const defaultValue = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678;
|
|
140
|
+
const props = {
|
|
141
|
+
onChange: (config) => {
|
|
142
|
+
if (config.type === "change") {
|
|
143
|
+
this._previewPattern = config.value;
|
|
144
|
+
this._forceUpdate();
|
|
145
|
+
} else if (config.type === "confirm") {
|
|
146
|
+
var _selectionManagerServ2;
|
|
147
|
+
const selections = ((_selectionManagerServ2 = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ2 === void 0 ? void 0 : _selectionManagerServ2.map((s) => s.range)) || [];
|
|
148
|
+
const params = { values: [] };
|
|
149
|
+
const patternType = getPatternType(config.value);
|
|
150
|
+
selections.forEach((rangeInfo) => {
|
|
151
|
+
Range.foreach(rangeInfo, (row, col) => {
|
|
152
|
+
params.values.push({
|
|
153
|
+
row,
|
|
154
|
+
col,
|
|
155
|
+
pattern: config.value,
|
|
156
|
+
type: patternType
|
|
157
|
+
});
|
|
158
|
+
});
|
|
152
159
|
});
|
|
153
|
-
|
|
160
|
+
commandService.executeCommand(SetNumfmtCommand.id, params);
|
|
161
|
+
sidebarService.close();
|
|
162
|
+
} else if (config.type === "cancel") sidebarService.close();
|
|
163
|
+
},
|
|
164
|
+
value: {
|
|
165
|
+
defaultPattern: pattern,
|
|
166
|
+
defaultValue,
|
|
167
|
+
row: range.startRow,
|
|
168
|
+
col: range.startColumn
|
|
154
169
|
}
|
|
155
|
-
return {
|
|
156
|
-
...params,
|
|
157
|
-
values: newValues
|
|
158
|
-
};
|
|
159
170
|
};
|
|
160
|
-
this.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/commands/operations/open.numfmt.panel.operation.ts
|
|
175
|
-
const OpenNumfmtPanelOperator = {
|
|
176
|
-
id: "sheet.operation.open.numfmt.panel",
|
|
177
|
-
type: CommandType.OPERATION,
|
|
178
|
-
handler: (accessor) => {
|
|
179
|
-
accessor.get(SheetNumfmtUIController).openPanel();
|
|
171
|
+
this._sidebarDisposable = sidebarService.open({
|
|
172
|
+
header: { title: localeService.t("sheets-numfmt-ui.title") },
|
|
173
|
+
children: {
|
|
174
|
+
label: SHEET_NUMFMT_PANEL$1,
|
|
175
|
+
...props
|
|
176
|
+
},
|
|
177
|
+
onClose: () => {
|
|
178
|
+
this._forceUpdate();
|
|
179
|
+
commandService.executeCommand(CloseNumfmtPanelOperator.id);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
180
182
|
return true;
|
|
181
183
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* Copyright 2023-present DreamNum Co., Ltd.
|
|
188
|
-
*
|
|
189
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
190
|
-
* you may not use this file except in compliance with the License.
|
|
191
|
-
* You may obtain a copy of the License at
|
|
192
|
-
*
|
|
193
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
194
|
-
*
|
|
195
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
196
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
197
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
198
|
-
* See the License for the specific language governing permissions and
|
|
199
|
-
* limitations under the License.
|
|
200
|
-
*/
|
|
201
|
-
const UserHabitCurrencyContext = createContext([]);
|
|
202
|
-
let UserHabitController = class UserHabitController {
|
|
203
|
-
constructor(_localStorageService) {
|
|
204
|
-
this._localStorageService = _localStorageService;
|
|
205
|
-
}
|
|
206
|
-
_getKey(habit) {
|
|
207
|
-
return `userHabitController_${habit}`;
|
|
208
|
-
}
|
|
209
|
-
async addHabit(habit, initValue) {
|
|
210
|
-
const key = this._getKey(habit);
|
|
211
|
-
return this._localStorageService.getItem(key).then((item) => {
|
|
212
|
-
if (!item) this._localStorageService.setItem(key, initValue);
|
|
213
|
-
});
|
|
184
|
+
_forceUpdate(unitId) {
|
|
185
|
+
var _renderUnit$mainCompo;
|
|
186
|
+
const renderUnit = this._renderManagerService.getRenderById(unitId !== null && unitId !== void 0 ? unitId : this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId());
|
|
187
|
+
renderUnit === null || renderUnit === void 0 || renderUnit.with(SheetSkeletonManagerService).reCalculate();
|
|
188
|
+
renderUnit === null || renderUnit === void 0 || (_renderUnit$mainCompo = renderUnit.mainComponent) === null || _renderUnit$mainCompo === void 0 || _renderUnit$mainCompo.makeDirty();
|
|
214
189
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (list) {
|
|
219
|
-
const index = list.findIndex((item) => item === value);
|
|
220
|
-
index > -1 && list.splice(index, 1);
|
|
221
|
-
list.unshift(value);
|
|
222
|
-
this._localStorageService.setItem(key, list);
|
|
223
|
-
}
|
|
190
|
+
_initCommands() {
|
|
191
|
+
[OpenNumfmtPanelOperator, CloseNumfmtPanelOperator].forEach((config) => {
|
|
192
|
+
this.disposeWithMe(this._commandService.registerCommand(config));
|
|
224
193
|
});
|
|
225
194
|
}
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
value: item,
|
|
233
|
-
priority: arr.length - index
|
|
234
|
-
};
|
|
195
|
+
_initRealTimeRenderingInterceptor() {
|
|
196
|
+
const combineOpenAndSelection$ = combineLatest([new Observable((subscriber) => {
|
|
197
|
+
this._commandService.onCommandExecuted((commandInfo) => {
|
|
198
|
+
if (commandInfo.id === OpenNumfmtPanelOperator.id) subscriber.next(true);
|
|
199
|
+
if (commandInfo.id === CloseNumfmtPanelOperator.id) subscriber.next(false);
|
|
235
200
|
});
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
201
|
+
}), this._selectionManagerService.selectionMoveEnd$.pipe(map((selectionInfos) => {
|
|
202
|
+
if (!selectionInfos) return [];
|
|
203
|
+
return selectionInfos.map((selectionInfo) => selectionInfo.range);
|
|
204
|
+
}))]);
|
|
205
|
+
this.disposeWithMe(toDisposable(combineOpenAndSelection$.pipe(switchMap(([isOpen, selectionRanges]) => new Observable((subscribe) => {
|
|
206
|
+
const disposableCollection = new DisposableCollection();
|
|
207
|
+
isOpen && selectionRanges.length && subscribe.next({
|
|
208
|
+
selectionRanges,
|
|
209
|
+
disposableCollection
|
|
240
210
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
211
|
+
return () => {
|
|
212
|
+
disposableCollection.dispose();
|
|
213
|
+
};
|
|
214
|
+
})), tap(() => {
|
|
215
|
+
this._previewPattern = null;
|
|
216
|
+
})).subscribe(({ disposableCollection, selectionRanges }) => {
|
|
217
|
+
var _this$_renderManagerS;
|
|
218
|
+
const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
219
|
+
this.openPanel();
|
|
220
|
+
disposableCollection.add(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
221
|
+
priority: 99,
|
|
222
|
+
effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
|
|
223
|
+
handler: (cell, location, next) => {
|
|
224
|
+
const { row, col } = location;
|
|
225
|
+
const defaultValue = next(cell) || {};
|
|
226
|
+
if (selectionRanges.find((range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row)) {
|
|
227
|
+
const rawValue = location.worksheet.getCellRaw(row, col);
|
|
228
|
+
const value = rawValue === null || rawValue === void 0 ? void 0 : rawValue.v;
|
|
229
|
+
const type = rawValue === null || rawValue === void 0 ? void 0 : rawValue.t;
|
|
230
|
+
if (value === void 0 || value === null || type !== CellValueType.NUMBER || this._previewPattern === null) return defaultValue;
|
|
231
|
+
const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value, this._sheetsNumfmtCellContentController.locale);
|
|
232
|
+
if (info.color) {
|
|
233
|
+
var _this$_themeService$g;
|
|
234
|
+
const color = (_this$_themeService$g = this._themeService.getColorFromTheme(`${info.color}.500`)) !== null && _this$_themeService$g !== void 0 ? _this$_themeService$g : info.color;
|
|
235
|
+
return {
|
|
236
|
+
...defaultValue,
|
|
237
|
+
v: info.result,
|
|
238
|
+
t: CellValueType.STRING,
|
|
239
|
+
s: { cl: { rgb: color } }
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
...defaultValue,
|
|
244
|
+
v: info.result,
|
|
245
|
+
t: CellValueType.STRING
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return defaultValue;
|
|
249
|
+
}
|
|
250
|
+
}));
|
|
251
|
+
(_this$_renderManagerS = this._renderManagerService.getRenderById(workbook.getUnitId())) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.mainComponent) === null || _this$_renderManagerS === void 0 || _this$_renderManagerS.makeDirty();
|
|
252
|
+
})));
|
|
246
253
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
256
|
-
* you may not use this file except in compliance with the License.
|
|
257
|
-
* You may obtain a copy of the License at
|
|
258
|
-
*
|
|
259
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
260
|
-
*
|
|
261
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
262
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
263
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
264
|
-
* See the License for the specific language governing permissions and
|
|
265
|
-
* limitations under the License.
|
|
266
|
-
*/
|
|
267
|
-
const key$1 = "numfmtCurrency";
|
|
268
|
-
const useCurrencyOptions = (onOptionChange) => {
|
|
269
|
-
const userHabitController = useDependency(UserHabitController);
|
|
270
|
-
const [options, setOptions] = useState(currencySymbols);
|
|
271
|
-
useEffect(() => {
|
|
272
|
-
userHabitController.addHabit("numfmtCurrency", []).then(() => {
|
|
273
|
-
userHabitController.getHabit(key$1, [...currencySymbols]).then((list) => {
|
|
274
|
-
setOptions(list);
|
|
275
|
-
onOptionChange && onOptionChange(list);
|
|
254
|
+
_commandExecutedListener() {
|
|
255
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
|
|
256
|
+
this.disposeWithMe(new Observable((subscribe) => {
|
|
257
|
+
const disposable = this._commandService.onCommandExecuted((command) => {
|
|
258
|
+
if (commandList.includes(command.id)) {
|
|
259
|
+
const params = command.params;
|
|
260
|
+
subscribe.next(params.unitId);
|
|
261
|
+
}
|
|
276
262
|
});
|
|
263
|
+
return () => disposable.dispose();
|
|
264
|
+
}).pipe(debounceTime$1(16)).subscribe((unitId) => this._forceUpdate(unitId)));
|
|
265
|
+
}
|
|
266
|
+
_initCloseListener() {
|
|
267
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
|
|
268
|
+
if (!unit) {
|
|
269
|
+
var _this$_sidebarDisposa;
|
|
270
|
+
(_this$_sidebarDisposa = this._sidebarDisposable) === null || _this$_sidebarDisposa === void 0 || _this$_sidebarDisposa.dispose();
|
|
271
|
+
this._sidebarDisposable = null;
|
|
272
|
+
}
|
|
277
273
|
});
|
|
278
|
-
}
|
|
279
|
-
const mark = (v) => {
|
|
280
|
-
userHabitController.markHabit(key$1, v);
|
|
281
|
-
};
|
|
282
|
-
return {
|
|
283
|
-
userHabitCurrency: options,
|
|
284
|
-
mark
|
|
285
|
-
};
|
|
274
|
+
}
|
|
286
275
|
};
|
|
276
|
+
SheetNumfmtUIController = __decorate([
|
|
277
|
+
__decorateParam(0, Inject(SheetInterceptorService)),
|
|
278
|
+
__decorateParam(1, Inject(ThemeService)),
|
|
279
|
+
__decorateParam(2, IUniverInstanceService),
|
|
280
|
+
__decorateParam(3, ICommandService),
|
|
281
|
+
__decorateParam(4, Inject(SheetsSelectionsService)),
|
|
282
|
+
__decorateParam(5, IRenderManagerService),
|
|
283
|
+
__decorateParam(6, INumfmtService),
|
|
284
|
+
__decorateParam(7, Inject(ComponentManager)),
|
|
285
|
+
__decorateParam(8, ISidebarService),
|
|
286
|
+
__decorateParam(9, Inject(LocaleService)),
|
|
287
|
+
__decorateParam(10, Inject(SheetsNumfmtCellContentController))
|
|
288
|
+
], SheetNumfmtUIController);
|
|
287
289
|
|
|
288
290
|
//#endregion
|
|
289
|
-
//#region src/
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
298
|
-
*
|
|
299
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
300
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
301
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
302
|
-
* See the License for the specific language governing permissions and
|
|
303
|
-
* limitations under the License.
|
|
304
|
-
*/
|
|
305
|
-
const useNextTick = () => {
|
|
306
|
-
const effectList = useRef([]);
|
|
307
|
-
const [value, dispatch] = useState({});
|
|
308
|
-
useEffect(() => {
|
|
309
|
-
effectList.current.forEach((fn) => {
|
|
310
|
-
fn();
|
|
311
|
-
});
|
|
312
|
-
effectList.current = [];
|
|
313
|
-
}, [value]);
|
|
314
|
-
const nextTick = (fn) => {
|
|
315
|
-
effectList.current.push(fn);
|
|
316
|
-
dispatch({});
|
|
317
|
-
};
|
|
318
|
-
return nextTick;
|
|
291
|
+
//#region src/commands/operations/open.numfmt.panel.operation.ts
|
|
292
|
+
const OpenNumfmtPanelOperator = {
|
|
293
|
+
id: "sheet.operation.open.numfmt.panel",
|
|
294
|
+
type: CommandType.OPERATION,
|
|
295
|
+
handler: (accessor) => {
|
|
296
|
+
accessor.get(SheetNumfmtUIController).openPanel();
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
319
299
|
};
|
|
320
300
|
|
|
321
301
|
//#endregion
|
|
322
|
-
//#region src/
|
|
323
|
-
const
|
|
324
|
-
return
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
302
|
+
//#region src/menu/menu.ts
|
|
303
|
+
const MENU_OPTIONS = (currencySymbol) => {
|
|
304
|
+
return [
|
|
305
|
+
{
|
|
306
|
+
label: "sheets-numfmt-ui.general",
|
|
307
|
+
pattern: null
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
label: "sheets-numfmt-ui.text",
|
|
311
|
+
pattern: DEFAULT_TEXT_FORMAT_EXCEL
|
|
312
|
+
},
|
|
313
|
+
"|",
|
|
314
|
+
{
|
|
315
|
+
label: "sheets-numfmt-ui.number",
|
|
316
|
+
pattern: "0"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
label: "sheets-numfmt-ui.percent",
|
|
320
|
+
pattern: "0.00%"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
label: "sheets-numfmt-ui.scientific",
|
|
324
|
+
pattern: "0.00E+00"
|
|
325
|
+
},
|
|
326
|
+
"|",
|
|
327
|
+
{
|
|
328
|
+
label: "sheets-numfmt-ui.accounting",
|
|
329
|
+
pattern: `"${currencySymbol}" #,##0.00_);[Red]("${currencySymbol}"#,##0.00)`
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
label: "sheets-numfmt-ui.financialValue",
|
|
333
|
+
pattern: "#,##0.00;[Red]#,##0.00"
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
label: "sheets-numfmt-ui.currency",
|
|
337
|
+
pattern: `"${currencySymbol}"#,##0.00_);[Red]("${currencySymbol}"#,##0.00)`
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
label: "sheets-numfmt-ui.roundingCurrency",
|
|
341
|
+
pattern: `"${currencySymbol}"#,##0;[Red]"${currencySymbol}"#,##0`
|
|
342
|
+
},
|
|
343
|
+
"|",
|
|
344
|
+
{
|
|
345
|
+
label: "sheets-numfmt-ui.date",
|
|
346
|
+
pattern: "yyyy-mm-dd;@"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
label: "sheets-numfmt-ui.time",
|
|
350
|
+
pattern: "am/pm h\":\"mm\":\"ss"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
label: "sheets-numfmt-ui.dateTime",
|
|
354
|
+
pattern: "yyyy-m-d am/pm h:mm"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
label: "sheets-numfmt-ui.timeDuration",
|
|
358
|
+
pattern: "h:mm:ss"
|
|
359
|
+
},
|
|
360
|
+
"|",
|
|
361
|
+
{
|
|
362
|
+
label: "sheets-numfmt-ui.moreFmt",
|
|
363
|
+
pattern: ""
|
|
364
|
+
}
|
|
365
|
+
];
|
|
366
|
+
};
|
|
367
|
+
function CurrencySymbolIconMenuItem(accessor) {
|
|
368
|
+
return {
|
|
369
|
+
icon: new Observable((subscribe) => {
|
|
370
|
+
const localeService = accessor.get(LocaleService);
|
|
371
|
+
subscribe.next(getCurrencySymbolIconByLocale(localeService.getCurrentLocale()).icon);
|
|
372
|
+
return localeService.localeChanged$.subscribe(() => {
|
|
373
|
+
subscribe.next(getCurrencySymbolIconByLocale(localeService.getCurrentLocale()).icon);
|
|
374
|
+
});
|
|
375
|
+
}),
|
|
376
|
+
id: SetCurrencyCommand.id,
|
|
377
|
+
title: "sheets-numfmt-ui.currency",
|
|
378
|
+
tooltip: "sheets-numfmt-ui.currency",
|
|
379
|
+
type: MenuItemType.BUTTON,
|
|
380
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
381
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
382
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
383
|
+
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
384
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
385
|
+
})
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function AddDecimalMenuItem(accessor) {
|
|
389
|
+
return {
|
|
390
|
+
icon: "AddDigitsIcon",
|
|
391
|
+
id: AddDecimalCommand.id,
|
|
392
|
+
title: "sheets-numfmt-ui.addDecimal",
|
|
393
|
+
tooltip: "sheets-numfmt-ui.addDecimal",
|
|
394
|
+
type: MenuItemType.BUTTON,
|
|
395
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
396
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
397
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
398
|
+
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
399
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
400
|
+
})
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function SubtractDecimalMenuItem(accessor) {
|
|
404
|
+
return {
|
|
405
|
+
icon: "ReduceDigitsIcon",
|
|
406
|
+
id: SubtractDecimalCommand.id,
|
|
407
|
+
title: "sheets-numfmt-ui.subtractDecimal",
|
|
408
|
+
tooltip: "sheets-numfmt-ui.subtractDecimal",
|
|
409
|
+
type: MenuItemType.BUTTON,
|
|
410
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
411
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
412
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
413
|
+
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
414
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
415
|
+
})
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function PercentMenuItem(accessor) {
|
|
419
|
+
return {
|
|
420
|
+
icon: "PercentIcon",
|
|
421
|
+
id: SetPercentCommand.id,
|
|
422
|
+
title: "sheets-numfmt-ui.percent",
|
|
423
|
+
tooltip: "sheets-numfmt-ui.percent",
|
|
424
|
+
type: MenuItemType.BUTTON,
|
|
425
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
426
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
427
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
428
|
+
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
429
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
430
|
+
})
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function FactoryOtherMenuItem(accessor) {
|
|
434
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
435
|
+
const commandService = accessor.get(ICommandService);
|
|
436
|
+
const localeService = accessor.get(LocaleService);
|
|
437
|
+
const selectionManagerService = accessor.get(SheetsSelectionsService);
|
|
438
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
|
|
439
|
+
const value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable((subscribe) => merge$1(selectionManagerService.selectionMoveEnd$, fromCallback(commandService.onCommandExecuted.bind(commandService)).pipe(filter(([commandInfo]) => commandList.includes(commandInfo.id)))).subscribe(() => {
|
|
440
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
441
|
+
if (selections && selections[0]) {
|
|
442
|
+
var _workbook$getStyles$g, _worksheet$getCell;
|
|
443
|
+
const range = selections[0].range;
|
|
444
|
+
const row = range.startRow;
|
|
445
|
+
const col = range.startColumn;
|
|
446
|
+
const numfmtValue = (_workbook$getStyles$g = workbook.getStyles().get((_worksheet$getCell = worksheet.getCell(row, col)) === null || _worksheet$getCell === void 0 ? void 0 : _worksheet$getCell.s)) === null || _workbook$getStyles$g === void 0 ? void 0 : _workbook$getStyles$g.n;
|
|
447
|
+
const pattern = numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern;
|
|
448
|
+
const currencySymbol = getCurrencySymbolByLocale(localeService.getCurrentLocale());
|
|
449
|
+
let value = localeService.t("sheets-numfmt-ui.general");
|
|
450
|
+
if (isDefaultFormat(pattern)) {
|
|
451
|
+
subscribe.next(value);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
if (pattern) {
|
|
455
|
+
const item = MENU_OPTIONS(currencySymbol).filter((item) => typeof item === "object" && item.pattern).find((item) => isPatternEqualWithoutDecimal(pattern, item.pattern));
|
|
456
|
+
if (item && typeof item === "object" && item.pattern) value = localeService.t(item.label);
|
|
457
|
+
else value = localeService.t("sheets-numfmt-ui.moreFmt");
|
|
458
|
+
}
|
|
459
|
+
subscribe.next(value);
|
|
460
|
+
}
|
|
461
|
+
})));
|
|
462
|
+
return {
|
|
463
|
+
label: MORE_NUMFMT_TYPE_KEY,
|
|
464
|
+
id: OpenNumfmtPanelOperator.id,
|
|
465
|
+
tooltip: "sheets-numfmt-ui.title",
|
|
466
|
+
type: MenuItemType.SELECTOR,
|
|
467
|
+
slot: true,
|
|
468
|
+
selections: [{ label: {
|
|
469
|
+
name: OPTIONS_KEY,
|
|
470
|
+
hoverable: false,
|
|
471
|
+
selectable: false
|
|
472
|
+
} }],
|
|
473
|
+
value$,
|
|
474
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
475
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
476
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
477
|
+
worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
|
|
478
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
479
|
+
})
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region src/views/components/MoreNumfmtType.tsx
|
|
485
|
+
const MORE_NUMFMT_TYPE_KEY = "sheets-numfmt-ui.moreNumfmtType";
|
|
486
|
+
const OPTIONS_KEY = "sheets-numfmt-ui.moreNumfmtType.options";
|
|
487
|
+
function MoreNumfmtType(props) {
|
|
488
|
+
const { value } = props;
|
|
489
|
+
const localeService = useDependency(LocaleService);
|
|
490
|
+
return /* @__PURE__ */ jsx("span", {
|
|
491
|
+
className: "univer-text-sm",
|
|
492
|
+
children: value !== null && value !== void 0 ? value : localeService.t("sheets-numfmt-ui.general")
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
function Options() {
|
|
496
|
+
const commandService = useDependency(ICommandService);
|
|
497
|
+
const localeService = useDependency(LocaleService);
|
|
498
|
+
const layoutService = useDependency(ILayoutService);
|
|
499
|
+
const sheetsNumfmtCellContentController = useDependency(SheetsNumfmtCellContentController);
|
|
500
|
+
const selectionManagerService = useDependency(SheetsSelectionsService);
|
|
501
|
+
const setNumfmt = (pattern) => {
|
|
502
|
+
const selection = selectionManagerService.getCurrentLastSelection();
|
|
503
|
+
if (!selection) return;
|
|
504
|
+
const range = selection.range;
|
|
505
|
+
const values = [];
|
|
506
|
+
Range.foreach(range, (row, col) => {
|
|
507
|
+
if (pattern) values.push({
|
|
508
|
+
row,
|
|
509
|
+
col,
|
|
510
|
+
pattern,
|
|
511
|
+
type: getPatternType(pattern)
|
|
512
|
+
});
|
|
513
|
+
else values.push({
|
|
514
|
+
row,
|
|
515
|
+
col
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
519
|
+
layoutService.focus();
|
|
520
|
+
};
|
|
521
|
+
const menuOptions = useMemo(() => {
|
|
522
|
+
return MENU_OPTIONS(localeCurrencySymbolMap.get(localeService.getCurrentLocale()));
|
|
523
|
+
}, [localeService]);
|
|
524
|
+
const handleClick = (index) => {
|
|
525
|
+
if (index === 0) setNumfmt(null);
|
|
526
|
+
else if (index === menuOptions.length - 1) {
|
|
527
|
+
commandService.executeCommand(OpenNumfmtPanelOperator.id);
|
|
528
|
+
layoutService.focus();
|
|
529
|
+
} else {
|
|
530
|
+
const item = menuOptions[index];
|
|
531
|
+
item.pattern && setNumfmt(item.pattern);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
const defaultValue = 1220;
|
|
535
|
+
return /* @__PURE__ */ jsx("div", {
|
|
536
|
+
className: "univer-grid univer-gap-1 univer-p-1.5",
|
|
537
|
+
children: menuOptions.map((item, index) => {
|
|
538
|
+
if (item === "|") return /* @__PURE__ */ jsx(Separator, {}, index);
|
|
539
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
540
|
+
className: "univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
|
|
541
|
+
onClick: () => handleClick(index),
|
|
542
|
+
children: [/* @__PURE__ */ jsx("span", { children: localeService.t(item.label) }), /* @__PURE__ */ jsx("span", {
|
|
543
|
+
className: "univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",
|
|
544
|
+
children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, sheetsNumfmtCellContentController.locale).result.trim() : ""
|
|
545
|
+
})]
|
|
546
|
+
}, index);
|
|
547
|
+
})
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region src/controllers/user-habit.controller.ts
|
|
553
|
+
/**
|
|
554
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
555
|
+
*
|
|
556
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
557
|
+
* you may not use this file except in compliance with the License.
|
|
558
|
+
* You may obtain a copy of the License at
|
|
559
|
+
*
|
|
560
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
561
|
+
*
|
|
562
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
563
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
564
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
565
|
+
* See the License for the specific language governing permissions and
|
|
566
|
+
* limitations under the License.
|
|
567
|
+
*/
|
|
568
|
+
const UserHabitCurrencyContext = createContext([]);
|
|
569
|
+
let UserHabitController = class UserHabitController {
|
|
570
|
+
constructor(_localStorageService) {
|
|
571
|
+
this._localStorageService = _localStorageService;
|
|
572
|
+
}
|
|
573
|
+
_getKey(habit) {
|
|
574
|
+
return `userHabitController_${habit}`;
|
|
575
|
+
}
|
|
576
|
+
async addHabit(habit, initValue) {
|
|
577
|
+
const key = this._getKey(habit);
|
|
578
|
+
return this._localStorageService.getItem(key).then((item) => {
|
|
579
|
+
if (!item) this._localStorageService.setItem(key, initValue);
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
markHabit(habit, value) {
|
|
583
|
+
const key = this._getKey(habit);
|
|
584
|
+
this._localStorageService.getItem(key).then((list) => {
|
|
585
|
+
if (list) {
|
|
586
|
+
const index = list.findIndex((item) => item === value);
|
|
587
|
+
index > -1 && list.splice(index, 1);
|
|
588
|
+
list.unshift(value);
|
|
589
|
+
this._localStorageService.setItem(key, list);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
async getHabit(habit, sortList) {
|
|
594
|
+
const key = this._getKey(habit);
|
|
595
|
+
const result = await this._localStorageService.getItem(key);
|
|
596
|
+
if (sortList && result) {
|
|
597
|
+
const priority = result.map((item, index, arr) => {
|
|
598
|
+
return {
|
|
599
|
+
value: item,
|
|
600
|
+
priority: arr.length - index
|
|
601
|
+
};
|
|
602
|
+
});
|
|
603
|
+
return sortList.sort((a, b) => {
|
|
604
|
+
var _priority$find, _priority$find2;
|
|
605
|
+
const ap = ((_priority$find = priority.find((item) => item.value === a)) === null || _priority$find === void 0 ? void 0 : _priority$find.priority) || -1;
|
|
606
|
+
return (((_priority$find2 = priority.find((item) => item.value === b)) === null || _priority$find2 === void 0 ? void 0 : _priority$find2.priority) || -1) - ap;
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
return result || [];
|
|
610
|
+
}
|
|
611
|
+
deleteHabit(habit) {
|
|
612
|
+
this._localStorageService.removeItem(habit);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
UserHabitController = __decorate([__decorateParam(0, Inject(ILocalStorageService))], UserHabitController);
|
|
616
|
+
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/views/components/Accounting.tsx
|
|
619
|
+
const isAccountingPanel = (pattern) => {
|
|
620
|
+
return !!getCurrencyType(pattern) && pattern.startsWith("_(");
|
|
621
|
+
};
|
|
622
|
+
function AccountingPanel(props) {
|
|
623
|
+
const { defaultPattern, onActionChange, onChange } = props;
|
|
624
|
+
const [decimal, setDecimal] = useState(() => getDecimalFromPattern(defaultPattern || "", 2));
|
|
625
|
+
const userHabitCurrency = useContext(UserHabitCurrencyContext);
|
|
626
|
+
const [suffix, setSuffix] = useState(() => getCurrencyType(defaultPattern) || userHabitCurrency[0]);
|
|
627
|
+
const options = useMemo(() => userHabitCurrency.map((key) => ({
|
|
628
|
+
label: key,
|
|
629
|
+
value: key
|
|
630
|
+
})), []);
|
|
631
|
+
const localeService = useDependency(LocaleService);
|
|
632
|
+
useLayoutEffect(() => {
|
|
633
|
+
onActionChange(() => setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
634
|
+
}, [
|
|
635
|
+
decimal,
|
|
636
|
+
onActionChange,
|
|
637
|
+
suffix
|
|
638
|
+
]);
|
|
639
|
+
const handleSelect = (v) => {
|
|
640
|
+
setSuffix(v);
|
|
641
|
+
onChange(setPatternDecimal(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
642
|
+
};
|
|
643
|
+
const handleDecimalChange = (v) => {
|
|
644
|
+
const decimal = v || 0;
|
|
645
|
+
setDecimal(decimal);
|
|
646
|
+
onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
647
|
+
};
|
|
648
|
+
return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
|
|
649
|
+
className: "univer-mt-4 univer-flex univer-justify-between",
|
|
650
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
651
|
+
className: "option",
|
|
652
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
653
|
+
className: "univer-text-sm univer-text-gray-400",
|
|
654
|
+
children: localeService.t("sheets-numfmt-ui.decimalLength")
|
|
655
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
656
|
+
className: "univer-mt-2 univer-w-32",
|
|
657
|
+
children: /* @__PURE__ */ jsx(InputNumber, {
|
|
658
|
+
value: decimal,
|
|
659
|
+
step: 1,
|
|
660
|
+
precision: 0,
|
|
661
|
+
max: 20,
|
|
662
|
+
min: 0,
|
|
663
|
+
onChange: handleDecimalChange
|
|
664
|
+
})
|
|
665
|
+
})]
|
|
666
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
667
|
+
className: "option",
|
|
366
668
|
children: [/* @__PURE__ */ jsx("div", {
|
|
367
669
|
className: "univer-text-sm univer-text-gray-400",
|
|
368
|
-
children: t("sheets-numfmt-ui.currencyType")
|
|
670
|
+
children: localeService.t("sheets-numfmt-ui.currencyType")
|
|
369
671
|
}), /* @__PURE__ */ jsx("div", {
|
|
370
672
|
className: "univer-mt-2 univer-w-36",
|
|
371
673
|
children: /* @__PURE__ */ jsx(Select, {
|
|
@@ -377,17 +679,18 @@ const AccountingPanel = (props) => {
|
|
|
377
679
|
})]
|
|
378
680
|
}), /* @__PURE__ */ jsx("div", {
|
|
379
681
|
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
380
|
-
children: t("sheets-numfmt-ui.accountingDes")
|
|
682
|
+
children: localeService.t("sheets-numfmt-ui.accountingDes")
|
|
381
683
|
})] });
|
|
382
|
-
}
|
|
684
|
+
}
|
|
383
685
|
|
|
384
686
|
//#endregion
|
|
385
687
|
//#region src/views/components/Currency.tsx
|
|
386
688
|
const isCurrencyPanel = (pattern) => {
|
|
387
689
|
return !!getCurrencyType(pattern) && !pattern.startsWith("_(");
|
|
388
690
|
};
|
|
389
|
-
|
|
390
|
-
const
|
|
691
|
+
function CurrencyPanel(props) {
|
|
692
|
+
const { onActionChange, onChange: onValueChange } = props;
|
|
693
|
+
const localeService = useDependency(LocaleService);
|
|
391
694
|
const userHabitCurrency = useContext(UserHabitCurrencyContext);
|
|
392
695
|
const [suffix, setSuffix] = useState(() => getCurrencyType(props.defaultPattern) || userHabitCurrency[0]);
|
|
393
696
|
const [decimal, setDecimal] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 2));
|
|
@@ -401,22 +704,28 @@ const CurrencyPanel = (props) => {
|
|
|
401
704
|
label: key,
|
|
402
705
|
value: key
|
|
403
706
|
})), [userHabitCurrency]);
|
|
404
|
-
|
|
707
|
+
useLayoutEffect(() => {
|
|
708
|
+
onActionChange(() => setPatternDecimal(pattern, decimal));
|
|
709
|
+
}, [
|
|
710
|
+
decimal,
|
|
711
|
+
onActionChange,
|
|
712
|
+
pattern
|
|
713
|
+
]);
|
|
405
714
|
const onSelect = (value) => {
|
|
406
715
|
if (value === void 0) return;
|
|
407
716
|
setSuffix(value);
|
|
408
717
|
const pattern = getCurrencyFormatOptions(value)[0].value;
|
|
409
718
|
setPattern(pattern);
|
|
410
|
-
|
|
719
|
+
onValueChange(setPatternDecimal(pattern, decimal));
|
|
411
720
|
};
|
|
412
721
|
const onChange = (value) => {
|
|
413
722
|
if (value === void 0) return;
|
|
414
723
|
setPattern(value);
|
|
415
|
-
|
|
724
|
+
onValueChange(setPatternDecimal(value, decimal));
|
|
416
725
|
};
|
|
417
726
|
const onDecimalChange = (v) => {
|
|
418
727
|
setDecimal(v || 0);
|
|
419
|
-
|
|
728
|
+
onValueChange(setPatternDecimal(pattern, v || 0));
|
|
420
729
|
};
|
|
421
730
|
return /* @__PURE__ */ jsxs("div", { children: [
|
|
422
731
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -425,7 +734,7 @@ const CurrencyPanel = (props) => {
|
|
|
425
734
|
className: "option",
|
|
426
735
|
children: [/* @__PURE__ */ jsx("div", {
|
|
427
736
|
className: "univer-text-sm univer-text-gray-400",
|
|
428
|
-
children: t("sheets-numfmt-ui.decimalLength")
|
|
737
|
+
children: localeService.t("sheets-numfmt-ui.decimalLength")
|
|
429
738
|
}), /* @__PURE__ */ jsx("div", {
|
|
430
739
|
className: "univer-mt-2 univer-w-32",
|
|
431
740
|
children: /* @__PURE__ */ jsx(InputNumber, {
|
|
@@ -439,7 +748,7 @@ const CurrencyPanel = (props) => {
|
|
|
439
748
|
className: "option",
|
|
440
749
|
children: [/* @__PURE__ */ jsx("div", {
|
|
441
750
|
className: "univer-text-sm univer-text-gray-400",
|
|
442
|
-
children: t("sheets-numfmt-ui.currencyType")
|
|
751
|
+
children: localeService.t("sheets-numfmt-ui.currencyType")
|
|
443
752
|
}), /* @__PURE__ */ jsx("div", {
|
|
444
753
|
className: "univer-mt-2 univer-w-36",
|
|
445
754
|
children: /* @__PURE__ */ jsx(Select, {
|
|
@@ -452,7 +761,7 @@ const CurrencyPanel = (props) => {
|
|
|
452
761
|
}),
|
|
453
762
|
/* @__PURE__ */ jsx("div", {
|
|
454
763
|
className: "label univer-mt-4",
|
|
455
|
-
children: t("sheets-numfmt-ui.negType")
|
|
764
|
+
children: localeService.t("sheets-numfmt-ui.negType")
|
|
456
765
|
}),
|
|
457
766
|
/* @__PURE__ */ jsx("div", {
|
|
458
767
|
className: "univer-mt-2",
|
|
@@ -464,29 +773,36 @@ const CurrencyPanel = (props) => {
|
|
|
464
773
|
}),
|
|
465
774
|
/* @__PURE__ */ jsx("div", {
|
|
466
775
|
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
467
|
-
children: t("sheets-numfmt-ui.currencyDes")
|
|
776
|
+
children: localeService.t("sheets-numfmt-ui.currencyDes")
|
|
468
777
|
})
|
|
469
778
|
] });
|
|
470
|
-
}
|
|
779
|
+
}
|
|
471
780
|
|
|
472
781
|
//#endregion
|
|
473
782
|
//#region src/views/components/CustomFormat.tsx
|
|
474
|
-
const key = "customFormat";
|
|
783
|
+
const key$1 = "customFormat";
|
|
475
784
|
const historyPatternKey = "numfmt_custom_pattern";
|
|
476
785
|
function CustomFormat(props) {
|
|
477
|
-
const { defaultPattern,
|
|
786
|
+
const { defaultPattern, onActionChange, onChange } = props;
|
|
478
787
|
const userHabitController = useDependency(UserHabitController);
|
|
479
788
|
const localStorageService = useDependency(ILocalStorageService);
|
|
480
789
|
const localeService = useDependency(LocaleService);
|
|
481
790
|
const [pattern, setPattern] = useState(defaultPattern);
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
791
|
+
useLayoutEffect(() => {
|
|
792
|
+
onActionChange(() => {
|
|
793
|
+
userHabitController.markHabit(key$1, pattern);
|
|
794
|
+
localStorageService.getItem(historyPatternKey).then((list = []) => {
|
|
795
|
+
const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
|
|
796
|
+
localStorageService.setItem(historyPatternKey, _list);
|
|
797
|
+
});
|
|
798
|
+
return pattern;
|
|
487
799
|
});
|
|
488
|
-
|
|
489
|
-
|
|
800
|
+
}, [
|
|
801
|
+
localStorageService,
|
|
802
|
+
onActionChange,
|
|
803
|
+
pattern,
|
|
804
|
+
userHabitController
|
|
805
|
+
]);
|
|
490
806
|
const [options, setOptions] = useState([]);
|
|
491
807
|
useEffect(() => {
|
|
492
808
|
localStorageService.getItem(historyPatternKey).then((historyList) => {
|
|
@@ -496,8 +812,8 @@ function CustomFormat(props) {
|
|
|
496
812
|
...NUMBERFORMAT.map((item) => item.suffix)
|
|
497
813
|
];
|
|
498
814
|
list.push(...historyList || []);
|
|
499
|
-
userHabitController.addHabit(key, []).finally(() => {
|
|
500
|
-
userHabitController.getHabit(key, list).then((list) => {
|
|
815
|
+
userHabitController.addHabit(key$1, []).finally(() => {
|
|
816
|
+
userHabitController.getHabit(key$1, list).then((list) => {
|
|
501
817
|
setOptions([...new Set(list)]);
|
|
502
818
|
});
|
|
503
819
|
});
|
|
@@ -551,7 +867,7 @@ const isDatePanel = (pattern) => {
|
|
|
551
867
|
].includes(info.type);
|
|
552
868
|
};
|
|
553
869
|
function DatePanel(props) {
|
|
554
|
-
const { onChange, defaultPattern } = props;
|
|
870
|
+
const { onActionChange, onChange, defaultPattern } = props;
|
|
555
871
|
const options = useMemo(getDateFormatOptions, []);
|
|
556
872
|
const localeService = useDependency(LocaleService);
|
|
557
873
|
const [suffix, setSuffix] = useState(() => {
|
|
@@ -561,7 +877,9 @@ function DatePanel(props) {
|
|
|
561
877
|
}
|
|
562
878
|
return options[0].value;
|
|
563
879
|
});
|
|
564
|
-
|
|
880
|
+
useLayoutEffect(() => {
|
|
881
|
+
onActionChange(() => suffix);
|
|
882
|
+
}, [onActionChange, suffix]);
|
|
565
883
|
const handleChange = (v) => {
|
|
566
884
|
if (v === void 0) return;
|
|
567
885
|
setSuffix(v);
|
|
@@ -590,19 +908,23 @@ function DatePanel(props) {
|
|
|
590
908
|
//#endregion
|
|
591
909
|
//#region src/views/components/General.tsx
|
|
592
910
|
const isGeneralPanel = (pattern) => !pattern;
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
911
|
+
function GeneralPanel(props) {
|
|
912
|
+
const localeService = useDependency(LocaleService);
|
|
913
|
+
const { onActionChange } = props;
|
|
914
|
+
useLayoutEffect(() => {
|
|
915
|
+
onActionChange(() => "");
|
|
916
|
+
}, [onActionChange]);
|
|
596
917
|
return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("div", {
|
|
597
918
|
className: "univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
598
|
-
children: t("sheets-numfmt-ui.generalDes")
|
|
919
|
+
children: localeService.t("sheets-numfmt-ui.generalDes")
|
|
599
920
|
}) });
|
|
600
|
-
}
|
|
921
|
+
}
|
|
601
922
|
|
|
602
923
|
//#endregion
|
|
603
924
|
//#region src/views/components/ThousandthPercentile.tsx
|
|
604
925
|
const isThousandthPercentilePanel = (pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern));
|
|
605
926
|
function ThousandthPercentilePanel(props) {
|
|
927
|
+
const { onActionChange, onChange } = props;
|
|
606
928
|
const localeService = useDependency(LocaleService);
|
|
607
929
|
const options = useMemo(getNumberFormatOptions, []);
|
|
608
930
|
const [decimal, setDecimal] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0));
|
|
@@ -614,89 +936,163 @@ function ThousandthPercentilePanel(props) {
|
|
|
614
936
|
const isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]);
|
|
615
937
|
const handleDecimalChange = (decimal) => {
|
|
616
938
|
setDecimal(decimal || 0);
|
|
617
|
-
|
|
939
|
+
onChange(setPatternDecimal(suffix, Number(decimal || 0)));
|
|
618
940
|
};
|
|
619
941
|
const handleClick = (v) => {
|
|
620
942
|
if (v === void 0) return;
|
|
621
943
|
setDecimal(getDecimalFromPattern(v, 0));
|
|
622
944
|
setSuffix(v);
|
|
623
|
-
|
|
945
|
+
onChange(v);
|
|
946
|
+
};
|
|
947
|
+
useLayoutEffect(() => {
|
|
948
|
+
onActionChange(() => pattern);
|
|
949
|
+
}, [onActionChange, pattern]);
|
|
950
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
951
|
+
/* @__PURE__ */ jsx("div", {
|
|
952
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
953
|
+
children: localeService.t("sheets-numfmt-ui.decimalLength")
|
|
954
|
+
}),
|
|
955
|
+
/* @__PURE__ */ jsx("div", {
|
|
956
|
+
className: "univer-mt-2",
|
|
957
|
+
children: /* @__PURE__ */ jsx(InputNumber, {
|
|
958
|
+
disabled: isInputDisable,
|
|
959
|
+
value: decimal,
|
|
960
|
+
max: 20,
|
|
961
|
+
min: 0,
|
|
962
|
+
onChange: handleDecimalChange
|
|
963
|
+
})
|
|
964
|
+
}),
|
|
965
|
+
/* @__PURE__ */ jsxs("div", {
|
|
966
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
967
|
+
children: [" ", localeService.t("sheets-numfmt-ui.negType")]
|
|
968
|
+
}),
|
|
969
|
+
/* @__PURE__ */ jsx("div", {
|
|
970
|
+
className: "univer-mt-2",
|
|
971
|
+
children: /* @__PURE__ */ jsx(SelectList, {
|
|
972
|
+
onChange: handleClick,
|
|
973
|
+
options,
|
|
974
|
+
value: suffix
|
|
975
|
+
})
|
|
976
|
+
}),
|
|
977
|
+
/* @__PURE__ */ jsx("div", {
|
|
978
|
+
className: "univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
979
|
+
children: localeService.t("sheets-numfmt-ui.thousandthPercentileDes")
|
|
980
|
+
})
|
|
981
|
+
] });
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region src/views/hooks/use-currency-options.ts
|
|
986
|
+
/**
|
|
987
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
988
|
+
*
|
|
989
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
990
|
+
* you may not use this file except in compliance with the License.
|
|
991
|
+
* You may obtain a copy of the License at
|
|
992
|
+
*
|
|
993
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
994
|
+
*
|
|
995
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
996
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
997
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
998
|
+
* See the License for the specific language governing permissions and
|
|
999
|
+
* limitations under the License.
|
|
1000
|
+
*/
|
|
1001
|
+
const key = "numfmtCurrency";
|
|
1002
|
+
const useCurrencyOptions = (onOptionChange) => {
|
|
1003
|
+
const userHabitController = useDependency(UserHabitController);
|
|
1004
|
+
const [options, setOptions] = useState(currencySymbols);
|
|
1005
|
+
useEffect(() => {
|
|
1006
|
+
userHabitController.addHabit("numfmtCurrency", []).then(() => {
|
|
1007
|
+
userHabitController.getHabit(key, [...currencySymbols]).then((list) => {
|
|
1008
|
+
setOptions(list);
|
|
1009
|
+
onOptionChange && onOptionChange(list);
|
|
1010
|
+
});
|
|
1011
|
+
});
|
|
1012
|
+
}, []);
|
|
1013
|
+
const mark = (v) => {
|
|
1014
|
+
userHabitController.markHabit(key, v);
|
|
1015
|
+
};
|
|
1016
|
+
return {
|
|
1017
|
+
userHabitCurrency: options,
|
|
1018
|
+
mark
|
|
1019
|
+
};
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
//#endregion
|
|
1023
|
+
//#region src/views/hooks/use-next-tick.ts
|
|
1024
|
+
/**
|
|
1025
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1026
|
+
*
|
|
1027
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1028
|
+
* you may not use this file except in compliance with the License.
|
|
1029
|
+
* You may obtain a copy of the License at
|
|
1030
|
+
*
|
|
1031
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1032
|
+
*
|
|
1033
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1034
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1035
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1036
|
+
* See the License for the specific language governing permissions and
|
|
1037
|
+
* limitations under the License.
|
|
1038
|
+
*/
|
|
1039
|
+
const useNextTick = () => {
|
|
1040
|
+
const effectList = useRef([]);
|
|
1041
|
+
const [value, dispatch] = useState({});
|
|
1042
|
+
useEffect(() => {
|
|
1043
|
+
effectList.current.forEach((fn) => {
|
|
1044
|
+
fn();
|
|
1045
|
+
});
|
|
1046
|
+
effectList.current = [];
|
|
1047
|
+
}, [value]);
|
|
1048
|
+
const nextTick = (fn) => {
|
|
1049
|
+
effectList.current.push(fn);
|
|
1050
|
+
dispatch({});
|
|
624
1051
|
};
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
/* @__PURE__ */ jsx("div", {
|
|
628
|
-
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
629
|
-
children: localeService.t("sheets-numfmt-ui.decimalLength")
|
|
630
|
-
}),
|
|
631
|
-
/* @__PURE__ */ jsx("div", {
|
|
632
|
-
className: "univer-mt-2",
|
|
633
|
-
children: /* @__PURE__ */ jsx(InputNumber, {
|
|
634
|
-
disabled: isInputDisable,
|
|
635
|
-
value: decimal,
|
|
636
|
-
max: 20,
|
|
637
|
-
min: 0,
|
|
638
|
-
onChange: handleDecimalChange
|
|
639
|
-
})
|
|
640
|
-
}),
|
|
641
|
-
/* @__PURE__ */ jsxs("div", {
|
|
642
|
-
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
643
|
-
children: [" ", localeService.t("sheets-numfmt-ui.negType")]
|
|
644
|
-
}),
|
|
645
|
-
/* @__PURE__ */ jsx("div", {
|
|
646
|
-
className: "univer-mt-2",
|
|
647
|
-
children: /* @__PURE__ */ jsx(SelectList, {
|
|
648
|
-
onChange: handleClick,
|
|
649
|
-
options,
|
|
650
|
-
value: suffix
|
|
651
|
-
})
|
|
652
|
-
}),
|
|
653
|
-
/* @__PURE__ */ jsx("div", {
|
|
654
|
-
className: "univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
655
|
-
children: localeService.t("sheets-numfmt-ui.thousandthPercentileDes")
|
|
656
|
-
})
|
|
657
|
-
] });
|
|
658
|
-
}
|
|
1052
|
+
return nextTick;
|
|
1053
|
+
};
|
|
659
1054
|
|
|
660
1055
|
//#endregion
|
|
661
|
-
//#region src/views/
|
|
662
|
-
|
|
1056
|
+
//#region src/views/SheetNumfmtPanel.tsx
|
|
1057
|
+
function SheetNumfmtPanel(props) {
|
|
663
1058
|
const { defaultValue, defaultPattern, row, col } = props.value;
|
|
664
1059
|
const localeService = useDependency(LocaleService);
|
|
665
|
-
const
|
|
666
|
-
const t = localeService.t;
|
|
1060
|
+
const currentPatternRef = useRef(() => "");
|
|
667
1061
|
const nextTick = useNextTick();
|
|
668
|
-
const typeOptions = useMemo(() =>
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1062
|
+
const typeOptions = useMemo(() => {
|
|
1063
|
+
return [
|
|
1064
|
+
{
|
|
1065
|
+
label: "sheets-numfmt-ui.general",
|
|
1066
|
+
component: GeneralPanel
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
label: "sheets-numfmt-ui.accounting",
|
|
1070
|
+
component: AccountingPanel
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
label: "sheets-numfmt-ui.currency",
|
|
1074
|
+
component: CurrencyPanel
|
|
1075
|
+
},
|
|
1076
|
+
{
|
|
1077
|
+
label: "sheets-numfmt-ui.date",
|
|
1078
|
+
component: DatePanel
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
label: "sheets-numfmt-ui.thousandthPercentile",
|
|
1082
|
+
component: ThousandthPercentilePanel
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
label: "sheets-numfmt-ui.customFormat",
|
|
1086
|
+
component: CustomFormat
|
|
1087
|
+
}
|
|
1088
|
+
].map((item) => ({
|
|
1089
|
+
...item,
|
|
1090
|
+
label: localeService.t(item.label)
|
|
1091
|
+
}));
|
|
1092
|
+
}, [localeService]);
|
|
697
1093
|
const [type, setType] = useState(findDefaultType);
|
|
698
|
-
const [key, setKey] = useState(() => `${row}_${col}`);
|
|
699
|
-
const { mark, userHabitCurrency } = useCurrencyOptions(() => setKey(`${row}_${col}_userCurrency
|
|
1094
|
+
const [key, setKey] = useState(() => `${row}_${col}_${defaultPattern}`);
|
|
1095
|
+
const { mark, userHabitCurrency } = useCurrencyOptions(() => setKey(`${row}_${col}_${defaultPattern}_userCurrency`));
|
|
700
1096
|
const BusinessComponent = useMemo(() => {
|
|
701
1097
|
var _typeOptions$find;
|
|
702
1098
|
return (_typeOptions$find = typeOptions.find((item) => item.label === type)) === null || _typeOptions$find === void 0 ? void 0 : _typeOptions$find.component;
|
|
@@ -718,7 +1114,7 @@ const SheetNumfmtPanel = (props) => {
|
|
|
718
1114
|
setType(value);
|
|
719
1115
|
nextTick(() => props.onChange({
|
|
720
1116
|
type: "change",
|
|
721
|
-
value:
|
|
1117
|
+
value: currentPatternRef.current() || ""
|
|
722
1118
|
}));
|
|
723
1119
|
};
|
|
724
1120
|
const handleChange = useCallback((v) => {
|
|
@@ -727,8 +1123,11 @@ const SheetNumfmtPanel = (props) => {
|
|
|
727
1123
|
value: v
|
|
728
1124
|
});
|
|
729
1125
|
}, []);
|
|
1126
|
+
const handleActionChange = useCallback((action) => {
|
|
1127
|
+
currentPatternRef.current = action;
|
|
1128
|
+
}, []);
|
|
730
1129
|
const handleConfirm = () => {
|
|
731
|
-
const pattern =
|
|
1130
|
+
const pattern = currentPatternRef.current() || "";
|
|
732
1131
|
const currency = getCurrencyType(pattern);
|
|
733
1132
|
if (currency) mark(currency);
|
|
734
1133
|
props.onChange({
|
|
@@ -744,295 +1143,216 @@ const SheetNumfmtPanel = (props) => {
|
|
|
744
1143
|
};
|
|
745
1144
|
const subProps = {
|
|
746
1145
|
onChange: handleChange,
|
|
1146
|
+
onActionChange: handleActionChange,
|
|
747
1147
|
defaultValue,
|
|
748
|
-
defaultPattern
|
|
749
|
-
action: getCurrentPattern
|
|
1148
|
+
defaultPattern
|
|
750
1149
|
};
|
|
751
1150
|
useEffect(() => {
|
|
752
1151
|
setType(findDefaultType());
|
|
753
|
-
setKey(`${row}_${col}`);
|
|
754
|
-
}, [
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
/* @__PURE__ */ jsx("div", {
|
|
763
|
-
className: "univer-mt-
|
|
764
|
-
children:
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
children: t("sheets-numfmt-ui.
|
|
788
|
-
})
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
//#endregion
|
|
825
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
826
|
-
function _defineProperty(e, r, t) {
|
|
827
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
828
|
-
value: t,
|
|
829
|
-
enumerable: !0,
|
|
830
|
-
configurable: !0,
|
|
831
|
-
writable: !0
|
|
832
|
-
}) : e[r] = t, e;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
//#endregion
|
|
836
|
-
//#region src/controllers/numfmt.controller.ts
|
|
837
|
-
const SHEET_NUMFMT_PANEL = "SHEET_NUMFMT_PANEL";
|
|
838
|
-
let SheetNumfmtUIController = class SheetNumfmtUIController extends Disposable {
|
|
839
|
-
constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService, _sheetsNumfmtCellContentController) {
|
|
840
|
-
super();
|
|
841
|
-
this._sheetInterceptorService = _sheetInterceptorService;
|
|
842
|
-
this._themeService = _themeService;
|
|
843
|
-
this._univerInstanceService = _univerInstanceService;
|
|
844
|
-
this._commandService = _commandService;
|
|
845
|
-
this._selectionManagerService = _selectionManagerService;
|
|
846
|
-
this._renderManagerService = _renderManagerService;
|
|
847
|
-
this._numfmtService = _numfmtService;
|
|
848
|
-
this._componentManager = _componentManager;
|
|
849
|
-
this._sidebarService = _sidebarService;
|
|
850
|
-
this._localeService = _localeService;
|
|
851
|
-
this._sheetsNumfmtCellContentController = _sheetsNumfmtCellContentController;
|
|
852
|
-
_defineProperty(this, "_previewPattern", "");
|
|
853
|
-
_defineProperty(this, "_sidebarDisposable", null);
|
|
854
|
-
this._initRealTimeRenderingInterceptor();
|
|
855
|
-
this._initPanel();
|
|
856
|
-
this._initCommands();
|
|
857
|
-
this._initCloseListener();
|
|
858
|
-
this._commandExecutedListener();
|
|
859
|
-
this._initNumfmtLocalChange();
|
|
860
|
-
}
|
|
861
|
-
_initNumfmtLocalChange() {
|
|
862
|
-
this.disposeWithMe(merge$1(this._sheetsNumfmtCellContentController.locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
863
|
-
this._forceUpdate();
|
|
864
|
-
}));
|
|
865
|
-
}
|
|
866
|
-
openPanel() {
|
|
867
|
-
var _selectionManagerServ;
|
|
868
|
-
const sidebarService = this._sidebarService;
|
|
869
|
-
const selectionManagerService = this._selectionManagerService;
|
|
870
|
-
const commandService = this._commandService;
|
|
871
|
-
const univerInstanceService = this._univerInstanceService;
|
|
872
|
-
const numfmtService = this._numfmtService;
|
|
873
|
-
const localeService = this._localeService;
|
|
874
|
-
const range = (((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range)) || [])[0];
|
|
875
|
-
if (!range) return false;
|
|
876
|
-
const workbook = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
877
|
-
const sheet = workbook.getActiveSheet();
|
|
878
|
-
if (!sheet) return false;
|
|
879
|
-
const cellValue = sheet.getCellRaw(range.startRow, range.startColumn);
|
|
880
|
-
const numfmtValue = numfmtService.getValue(workbook.getUnitId(), sheet.getSheetId(), range.startRow, range.startColumn);
|
|
881
|
-
let pattern = "";
|
|
882
|
-
if (numfmtValue) pattern = numfmtValue.pattern;
|
|
883
|
-
const defaultValue = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678;
|
|
884
|
-
const props = {
|
|
885
|
-
onChange: (config) => {
|
|
886
|
-
if (config.type === "change") {
|
|
887
|
-
this._previewPattern = config.value;
|
|
888
|
-
this._forceUpdate();
|
|
889
|
-
} else if (config.type === "confirm") {
|
|
890
|
-
var _selectionManagerServ2;
|
|
891
|
-
const selections = ((_selectionManagerServ2 = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ2 === void 0 ? void 0 : _selectionManagerServ2.map((s) => s.range)) || [];
|
|
892
|
-
const params = { values: [] };
|
|
893
|
-
const patternType = getPatternType(config.value);
|
|
894
|
-
selections.forEach((rangeInfo) => {
|
|
895
|
-
Range.foreach(rangeInfo, (row, col) => {
|
|
896
|
-
params.values.push({
|
|
897
|
-
row,
|
|
898
|
-
col,
|
|
899
|
-
pattern: config.value,
|
|
900
|
-
type: patternType
|
|
901
|
-
});
|
|
902
|
-
});
|
|
903
|
-
});
|
|
904
|
-
commandService.executeCommand(SetNumfmtCommand.id, params);
|
|
905
|
-
sidebarService.close();
|
|
906
|
-
} else if (config.type === "cancel") sidebarService.close();
|
|
907
|
-
},
|
|
908
|
-
value: {
|
|
909
|
-
defaultPattern: pattern,
|
|
910
|
-
defaultValue,
|
|
911
|
-
row: range.startRow,
|
|
912
|
-
col: range.startColumn
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
this._sidebarDisposable = sidebarService.open({
|
|
916
|
-
header: { title: localeService.t("sheets-numfmt-ui.title") },
|
|
917
|
-
children: {
|
|
918
|
-
label: SHEET_NUMFMT_PANEL,
|
|
919
|
-
...props
|
|
920
|
-
},
|
|
921
|
-
onClose: () => {
|
|
922
|
-
this._forceUpdate();
|
|
923
|
-
commandService.executeCommand(CloseNumfmtPanelOperator.id);
|
|
924
|
-
}
|
|
925
|
-
});
|
|
926
|
-
return true;
|
|
1152
|
+
setKey(`${row}_${col}_${defaultPattern}`);
|
|
1153
|
+
}, [
|
|
1154
|
+
row,
|
|
1155
|
+
col,
|
|
1156
|
+
defaultPattern
|
|
1157
|
+
]);
|
|
1158
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1159
|
+
className: clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5", scrollbarClassName),
|
|
1160
|
+
children: [/* @__PURE__ */ jsxs("div", { children: [
|
|
1161
|
+
/* @__PURE__ */ jsx("div", {
|
|
1162
|
+
className: "univer-mt-3.5 univer-text-sm univer-text-gray-400",
|
|
1163
|
+
children: localeService.t("sheets-numfmt-ui.numfmtType")
|
|
1164
|
+
}),
|
|
1165
|
+
/* @__PURE__ */ jsx("div", {
|
|
1166
|
+
className: "univer-mt-2",
|
|
1167
|
+
children: /* @__PURE__ */ jsx(Select, {
|
|
1168
|
+
className: "univer-w-full",
|
|
1169
|
+
value: type,
|
|
1170
|
+
options: selectOptions,
|
|
1171
|
+
onChange: handleSelect
|
|
1172
|
+
})
|
|
1173
|
+
}),
|
|
1174
|
+
/* @__PURE__ */ jsx("div", { children: BusinessComponent && /* @__PURE__ */ jsx(UserHabitCurrencyContext.Provider, {
|
|
1175
|
+
value: userHabitCurrency,
|
|
1176
|
+
children: /* @__PURE__ */ createElement(BusinessComponent, {
|
|
1177
|
+
...subProps,
|
|
1178
|
+
key
|
|
1179
|
+
})
|
|
1180
|
+
}) })
|
|
1181
|
+
] }), /* @__PURE__ */ jsxs("div", {
|
|
1182
|
+
className: "univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",
|
|
1183
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
1184
|
+
onClick: handleCancel,
|
|
1185
|
+
className: "univer-mr-3",
|
|
1186
|
+
children: localeService.t("sheets-numfmt-ui.cancel")
|
|
1187
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
1188
|
+
variant: "primary",
|
|
1189
|
+
onClick: handleConfirm,
|
|
1190
|
+
children: localeService.t("sheets-numfmt-ui.confirm")
|
|
1191
|
+
})]
|
|
1192
|
+
})]
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
//#endregion
|
|
1197
|
+
//#region src/controllers/components.controller.ts
|
|
1198
|
+
/**
|
|
1199
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1200
|
+
*
|
|
1201
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1202
|
+
* you may not use this file except in compliance with the License.
|
|
1203
|
+
* You may obtain a copy of the License at
|
|
1204
|
+
*
|
|
1205
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1206
|
+
*
|
|
1207
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1208
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1209
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1210
|
+
* See the License for the specific language governing permissions and
|
|
1211
|
+
* limitations under the License.
|
|
1212
|
+
*/
|
|
1213
|
+
const SHEET_NUMFMT_PANEL = "SHEET_NUMFMT_PANEL";
|
|
1214
|
+
let ComponentsController = class ComponentsController extends Disposable {
|
|
1215
|
+
constructor(_componentManager, _iconManager) {
|
|
1216
|
+
super();
|
|
1217
|
+
this._componentManager = _componentManager;
|
|
1218
|
+
this._iconManager = _iconManager;
|
|
1219
|
+
this._registerComponents();
|
|
1220
|
+
this._registerIcons();
|
|
927
1221
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1222
|
+
_registerIcons() {
|
|
1223
|
+
this.disposeWithMe(this._iconManager.register({
|
|
1224
|
+
AddDigitsIcon,
|
|
1225
|
+
DollarIcon,
|
|
1226
|
+
EuroIcon,
|
|
1227
|
+
PercentIcon,
|
|
1228
|
+
ReduceDigitsIcon,
|
|
1229
|
+
RmbIcon,
|
|
1230
|
+
RoubleIcon
|
|
1231
|
+
}));
|
|
933
1232
|
}
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
1233
|
+
_registerComponents() {
|
|
1234
|
+
this.disposeWithMe(this._componentManager.register(SHEET_NUMFMT_PANEL, SheetNumfmtPanel));
|
|
1235
|
+
[[MORE_NUMFMT_TYPE_KEY, MoreNumfmtType], [OPTIONS_KEY, Options]].forEach(([key, comp]) => {
|
|
1236
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
937
1237
|
});
|
|
938
1238
|
}
|
|
939
|
-
|
|
940
|
-
|
|
1239
|
+
};
|
|
1240
|
+
ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], ComponentsController);
|
|
1241
|
+
|
|
1242
|
+
//#endregion
|
|
1243
|
+
//#region src/controllers/numfmt-alert-render.controller.ts
|
|
1244
|
+
const ALERT_KEY = "SHEET_NUMFMT_ALERT";
|
|
1245
|
+
let NumfmtAlertRenderController = class NumfmtAlertRenderController extends Disposable {
|
|
1246
|
+
constructor(_context, _hoverManagerService, _cellAlertManagerService, _localeService, _numfmtService, _configService) {
|
|
1247
|
+
super();
|
|
1248
|
+
this._context = _context;
|
|
1249
|
+
this._hoverManagerService = _hoverManagerService;
|
|
1250
|
+
this._cellAlertManagerService = _cellAlertManagerService;
|
|
1251
|
+
this._localeService = _localeService;
|
|
1252
|
+
this._numfmtService = _numfmtService;
|
|
1253
|
+
this._configService = _configService;
|
|
1254
|
+
this._init();
|
|
941
1255
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
this._commandService.onCommandExecuted((commandInfo) => {
|
|
945
|
-
if (commandInfo.id === OpenNumfmtPanelOperator.id) subscriber.next(true);
|
|
946
|
-
if (commandInfo.id === CloseNumfmtPanelOperator.id) subscriber.next(false);
|
|
947
|
-
});
|
|
948
|
-
}), this._selectionManagerService.selectionMoveEnd$.pipe(map((selectionInfos) => {
|
|
949
|
-
if (!selectionInfos) return [];
|
|
950
|
-
return selectionInfos.map((selectionInfo) => selectionInfo.range);
|
|
951
|
-
}))]);
|
|
952
|
-
this.disposeWithMe(toDisposable(combineOpenAndSelection$.pipe(switchMap(([isOpen, selectionRanges]) => new Observable((subscribe) => {
|
|
953
|
-
const disposableCollection = new DisposableCollection();
|
|
954
|
-
isOpen && selectionRanges.length && subscribe.next({
|
|
955
|
-
selectionRanges,
|
|
956
|
-
disposableCollection
|
|
957
|
-
});
|
|
958
|
-
return () => {
|
|
959
|
-
disposableCollection.dispose();
|
|
960
|
-
};
|
|
961
|
-
})), tap(() => {
|
|
962
|
-
this._previewPattern = null;
|
|
963
|
-
})).subscribe(({ disposableCollection, selectionRanges }) => {
|
|
964
|
-
var _this$_renderManagerS;
|
|
965
|
-
const workbook = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);
|
|
966
|
-
this.openPanel();
|
|
967
|
-
disposableCollection.add(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
968
|
-
priority: 99,
|
|
969
|
-
effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
|
|
970
|
-
handler: (cell, location, next) => {
|
|
971
|
-
const { row, col } = location;
|
|
972
|
-
const defaultValue = next(cell) || {};
|
|
973
|
-
if (selectionRanges.find((range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row)) {
|
|
974
|
-
const rawValue = location.worksheet.getCellRaw(row, col);
|
|
975
|
-
const value = rawValue === null || rawValue === void 0 ? void 0 : rawValue.v;
|
|
976
|
-
const type = rawValue === null || rawValue === void 0 ? void 0 : rawValue.t;
|
|
977
|
-
if (value === void 0 || value === null || type !== CellValueType.NUMBER || this._previewPattern === null) return defaultValue;
|
|
978
|
-
const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value, this._sheetsNumfmtCellContentController.locale);
|
|
979
|
-
if (info.color) {
|
|
980
|
-
var _this$_themeService$g;
|
|
981
|
-
const color = (_this$_themeService$g = this._themeService.getColorFromTheme(`${info.color}.500`)) !== null && _this$_themeService$g !== void 0 ? _this$_themeService$g : info.color;
|
|
982
|
-
return {
|
|
983
|
-
...defaultValue,
|
|
984
|
-
v: info.result,
|
|
985
|
-
t: CellValueType.STRING,
|
|
986
|
-
s: { cl: { rgb: color } }
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
return {
|
|
990
|
-
...defaultValue,
|
|
991
|
-
v: info.result,
|
|
992
|
-
t: CellValueType.STRING
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
return defaultValue;
|
|
996
|
-
}
|
|
997
|
-
}));
|
|
998
|
-
(_this$_renderManagerS = this._renderManagerService.getRenderById(workbook.getUnitId())) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.mainComponent) === null || _this$_renderManagerS === void 0 || _this$_renderManagerS.makeDirty();
|
|
999
|
-
})));
|
|
1256
|
+
_init() {
|
|
1257
|
+
this._initCellAlertPopup();
|
|
1000
1258
|
}
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1259
|
+
_initCellAlertPopup() {
|
|
1260
|
+
this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(debounceTime(100)).subscribe((cellPos) => {
|
|
1261
|
+
if (cellPos) {
|
|
1262
|
+
const location = cellPos.location;
|
|
1263
|
+
const workbook = this._context.unit;
|
|
1264
|
+
const worksheet = workbook.getActiveSheet();
|
|
1265
|
+
if (!worksheet) return this._hideAlert();
|
|
1266
|
+
const unitId = location.unitId;
|
|
1267
|
+
const sheetId = location.subUnitId;
|
|
1268
|
+
let numfmtValue;
|
|
1269
|
+
const cellData = worksheet.getCell(location.row, location.col);
|
|
1270
|
+
if (cellData === null || cellData === void 0 ? void 0 : cellData.s) {
|
|
1271
|
+
const style = workbook.getStyles().get(cellData.s);
|
|
1272
|
+
if (style === null || style === void 0 ? void 0 : style.n) numfmtValue = style.n;
|
|
1273
|
+
}
|
|
1274
|
+
if (!numfmtValue) numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);
|
|
1275
|
+
if (!numfmtValue) {
|
|
1276
|
+
this._hideAlert();
|
|
1277
|
+
return;
|
|
1278
|
+
}
|
|
1279
|
+
if (isTextFormat(numfmtValue.pattern) && Tools.isDefine(cellData === null || cellData === void 0 ? void 0 : cellData.v) && isRealNum(cellData.v)) {
|
|
1280
|
+
var _this$_configService$, _currentAlert$alert;
|
|
1281
|
+
if ((_this$_configService$ = this._configService.getConfig(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY)) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.disableTextFormatAlert) return;
|
|
1282
|
+
const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
|
|
1283
|
+
const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
|
|
1284
|
+
if (currentLoc && currentLoc.row === location.row && currentLoc.col === location.col && currentLoc.subUnitId === location.subUnitId && currentLoc.unitId === location.unitId) {
|
|
1285
|
+
this._hideAlert();
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
this._cellAlertManagerService.showAlert({
|
|
1289
|
+
type: CellAlertType.ERROR,
|
|
1290
|
+
title: this._localeService.t("sheets-numfmt-ui.info.error"),
|
|
1291
|
+
message: this._localeService.t("sheets-numfmt-ui.info.forceStringInfo"),
|
|
1292
|
+
location,
|
|
1293
|
+
width: 200,
|
|
1294
|
+
height: 74,
|
|
1295
|
+
key: ALERT_KEY
|
|
1296
|
+
});
|
|
1297
|
+
return;
|
|
1008
1298
|
}
|
|
1009
|
-
});
|
|
1010
|
-
return () => disposable.dispose();
|
|
1011
|
-
}).pipe(debounceTime$1(16)).subscribe((unitId) => this._forceUpdate(unitId)));
|
|
1012
|
-
}
|
|
1013
|
-
_initCloseListener() {
|
|
1014
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
|
|
1015
|
-
if (!unit) {
|
|
1016
|
-
var _this$_sidebarDisposa;
|
|
1017
|
-
(_this$_sidebarDisposa = this._sidebarDisposable) === null || _this$_sidebarDisposa === void 0 || _this$_sidebarDisposa.dispose();
|
|
1018
|
-
this._sidebarDisposable = null;
|
|
1019
1299
|
}
|
|
1020
|
-
|
|
1300
|
+
this._hideAlert();
|
|
1301
|
+
}));
|
|
1302
|
+
}
|
|
1303
|
+
_hideAlert() {
|
|
1304
|
+
this._cellAlertManagerService.removeAlert(ALERT_KEY);
|
|
1021
1305
|
}
|
|
1022
1306
|
};
|
|
1023
|
-
|
|
1024
|
-
__decorateParam(
|
|
1025
|
-
__decorateParam(
|
|
1026
|
-
__decorateParam(
|
|
1027
|
-
__decorateParam(
|
|
1028
|
-
__decorateParam(
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1307
|
+
NumfmtAlertRenderController = __decorate([
|
|
1308
|
+
__decorateParam(1, Inject(HoverManagerService)),
|
|
1309
|
+
__decorateParam(2, Inject(CellAlertManagerService)),
|
|
1310
|
+
__decorateParam(3, Inject(LocaleService)),
|
|
1311
|
+
__decorateParam(4, Inject(INumfmtService)),
|
|
1312
|
+
__decorateParam(5, IConfigService)
|
|
1313
|
+
], NumfmtAlertRenderController);
|
|
1314
|
+
|
|
1315
|
+
//#endregion
|
|
1316
|
+
//#region src/controllers/numfmt-repeat-last-action.controller.ts
|
|
1317
|
+
let NumfmtRepeatLastActionController = class NumfmtRepeatLastActionController extends Disposable {
|
|
1318
|
+
constructor(_repeatLastActionService) {
|
|
1319
|
+
super();
|
|
1320
|
+
this._repeatLastActionService = _repeatLastActionService;
|
|
1321
|
+
this._initCommandRecording();
|
|
1322
|
+
}
|
|
1323
|
+
_initCommandRecording() {
|
|
1324
|
+
if (!this._repeatLastActionService) return;
|
|
1325
|
+
const handler = (selections, params) => {
|
|
1326
|
+
if (!params) return;
|
|
1327
|
+
const { values } = params;
|
|
1328
|
+
const numfmtCell = values.find((cell) => cell.pattern);
|
|
1329
|
+
if (!numfmtCell) return;
|
|
1330
|
+
const { pattern, type } = numfmtCell;
|
|
1331
|
+
const newValues = [];
|
|
1332
|
+
const cache = /* @__PURE__ */ new Set();
|
|
1333
|
+
for (const selection of selections) {
|
|
1334
|
+
const { startRow, startColumn, endRow, endColumn } = selection;
|
|
1335
|
+
for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
|
|
1336
|
+
const key = `${row}-${col}`;
|
|
1337
|
+
if (cache.has(key)) continue;
|
|
1338
|
+
cache.add(key);
|
|
1339
|
+
newValues.push({
|
|
1340
|
+
row,
|
|
1341
|
+
col,
|
|
1342
|
+
pattern,
|
|
1343
|
+
type
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
return {
|
|
1348
|
+
...params,
|
|
1349
|
+
values: newValues
|
|
1350
|
+
};
|
|
1351
|
+
};
|
|
1352
|
+
this.disposeWithMe(this._repeatLastActionService.registerRepeatableCommand(SetNumfmtCommand.id, handler, RepeatLastActionPermission.CellStyle));
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
NumfmtRepeatLastActionController = __decorate([__decorateParam(0, Optional(IRepeatLastActionService))], NumfmtRepeatLastActionController);
|
|
1036
1356
|
|
|
1037
1357
|
//#endregion
|
|
1038
1358
|
//#region src/controllers/numfmt.editor.controller.ts
|
|
@@ -1243,256 +1563,6 @@ function canConvertRichTextToNumfmt(body) {
|
|
|
1243
1563
|
}) || paragraphs.some((paragraph) => paragraph.bullet) || paragraphs.length >= 2 || Boolean(customRanges === null || customRanges === void 0 ? void 0 : customRanges.length) || customBlocks.length > 0);
|
|
1244
1564
|
}
|
|
1245
1565
|
|
|
1246
|
-
//#endregion
|
|
1247
|
-
//#region src/menu/menu.ts
|
|
1248
|
-
const MENU_OPTIONS = (currencySymbol) => {
|
|
1249
|
-
return [
|
|
1250
|
-
{
|
|
1251
|
-
label: "sheets-numfmt-ui.general",
|
|
1252
|
-
pattern: null
|
|
1253
|
-
},
|
|
1254
|
-
{
|
|
1255
|
-
label: "sheets-numfmt-ui.text",
|
|
1256
|
-
pattern: DEFAULT_TEXT_FORMAT_EXCEL
|
|
1257
|
-
},
|
|
1258
|
-
"|",
|
|
1259
|
-
{
|
|
1260
|
-
label: "sheets-numfmt-ui.number",
|
|
1261
|
-
pattern: "0"
|
|
1262
|
-
},
|
|
1263
|
-
{
|
|
1264
|
-
label: "sheets-numfmt-ui.percent",
|
|
1265
|
-
pattern: "0.00%"
|
|
1266
|
-
},
|
|
1267
|
-
{
|
|
1268
|
-
label: "sheets-numfmt-ui.scientific",
|
|
1269
|
-
pattern: "0.00E+00"
|
|
1270
|
-
},
|
|
1271
|
-
"|",
|
|
1272
|
-
{
|
|
1273
|
-
label: "sheets-numfmt-ui.accounting",
|
|
1274
|
-
pattern: `"${currencySymbol}" #,##0.00_);[Red]("${currencySymbol}"#,##0.00)`
|
|
1275
|
-
},
|
|
1276
|
-
{
|
|
1277
|
-
label: "sheets-numfmt-ui.financialValue",
|
|
1278
|
-
pattern: "#,##0.00;[Red]#,##0.00"
|
|
1279
|
-
},
|
|
1280
|
-
{
|
|
1281
|
-
label: "sheets-numfmt-ui.currency",
|
|
1282
|
-
pattern: `"${currencySymbol}"#,##0.00_);[Red]("${currencySymbol}"#,##0.00)`
|
|
1283
|
-
},
|
|
1284
|
-
{
|
|
1285
|
-
label: "sheets-numfmt-ui.roundingCurrency",
|
|
1286
|
-
pattern: `"${currencySymbol}"#,##0;[Red]"${currencySymbol}"#,##0`
|
|
1287
|
-
},
|
|
1288
|
-
"|",
|
|
1289
|
-
{
|
|
1290
|
-
label: "sheets-numfmt-ui.date",
|
|
1291
|
-
pattern: "yyyy-mm-dd;@"
|
|
1292
|
-
},
|
|
1293
|
-
{
|
|
1294
|
-
label: "sheets-numfmt-ui.time",
|
|
1295
|
-
pattern: "am/pm h\":\"mm\":\"ss"
|
|
1296
|
-
},
|
|
1297
|
-
{
|
|
1298
|
-
label: "sheets-numfmt-ui.dateTime",
|
|
1299
|
-
pattern: "yyyy-m-d am/pm h:mm"
|
|
1300
|
-
},
|
|
1301
|
-
{
|
|
1302
|
-
label: "sheets-numfmt-ui.timeDuration",
|
|
1303
|
-
pattern: "h:mm:ss"
|
|
1304
|
-
},
|
|
1305
|
-
"|",
|
|
1306
|
-
{
|
|
1307
|
-
label: "sheets-numfmt-ui.moreFmt",
|
|
1308
|
-
pattern: ""
|
|
1309
|
-
}
|
|
1310
|
-
];
|
|
1311
|
-
};
|
|
1312
|
-
const CurrencySymbolIconMenuItem = (accessor) => {
|
|
1313
|
-
return {
|
|
1314
|
-
icon: new Observable((subscribe) => {
|
|
1315
|
-
const localeService = accessor.get(LocaleService);
|
|
1316
|
-
subscribe.next(getCurrencySymbolIconByLocale(localeService.getCurrentLocale()).icon);
|
|
1317
|
-
return localeService.localeChanged$.subscribe(() => {
|
|
1318
|
-
subscribe.next(getCurrencySymbolIconByLocale(localeService.getCurrentLocale()).icon);
|
|
1319
|
-
});
|
|
1320
|
-
}),
|
|
1321
|
-
id: SetCurrencyCommand.id,
|
|
1322
|
-
title: "sheets-numfmt-ui.currency",
|
|
1323
|
-
tooltip: "sheets-numfmt-ui.currency",
|
|
1324
|
-
type: MenuItemType.BUTTON,
|
|
1325
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1326
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
1327
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
1328
|
-
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
1329
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
1330
|
-
})
|
|
1331
|
-
};
|
|
1332
|
-
};
|
|
1333
|
-
const AddDecimalMenuItem = (accessor) => {
|
|
1334
|
-
return {
|
|
1335
|
-
icon: "AddDigitsIcon",
|
|
1336
|
-
id: AddDecimalCommand.id,
|
|
1337
|
-
title: "sheets-numfmt-ui.addDecimal",
|
|
1338
|
-
tooltip: "sheets-numfmt-ui.addDecimal",
|
|
1339
|
-
type: MenuItemType.BUTTON,
|
|
1340
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1341
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
1342
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
1343
|
-
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
1344
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
1345
|
-
})
|
|
1346
|
-
};
|
|
1347
|
-
};
|
|
1348
|
-
const SubtractDecimalMenuItem = (accessor) => {
|
|
1349
|
-
return {
|
|
1350
|
-
icon: "ReduceDigitsIcon",
|
|
1351
|
-
id: SubtractDecimalCommand.id,
|
|
1352
|
-
title: "sheets-numfmt-ui.subtractDecimal",
|
|
1353
|
-
tooltip: "sheets-numfmt-ui.subtractDecimal",
|
|
1354
|
-
type: MenuItemType.BUTTON,
|
|
1355
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1356
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
1357
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
1358
|
-
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
1359
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
1360
|
-
})
|
|
1361
|
-
};
|
|
1362
|
-
};
|
|
1363
|
-
const PercentMenuItem = (accessor) => {
|
|
1364
|
-
return {
|
|
1365
|
-
icon: "PercentIcon",
|
|
1366
|
-
id: SetPercentCommand.id,
|
|
1367
|
-
title: "sheets-numfmt-ui.percent",
|
|
1368
|
-
tooltip: "sheets-numfmt-ui.percent",
|
|
1369
|
-
type: MenuItemType.BUTTON,
|
|
1370
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1371
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
1372
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
1373
|
-
worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission],
|
|
1374
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
1375
|
-
})
|
|
1376
|
-
};
|
|
1377
|
-
};
|
|
1378
|
-
const FactoryOtherMenuItem = (accessor) => {
|
|
1379
|
-
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1380
|
-
const commandService = accessor.get(ICommandService);
|
|
1381
|
-
const localeService = accessor.get(LocaleService);
|
|
1382
|
-
const selectionManagerService = accessor.get(SheetsSelectionsService);
|
|
1383
|
-
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
|
|
1384
|
-
const value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable((subscribe) => merge$1(selectionManagerService.selectionMoveEnd$, fromCallback(commandService.onCommandExecuted.bind(commandService)).pipe(filter(([commandInfo]) => commandList.includes(commandInfo.id)))).subscribe(() => {
|
|
1385
|
-
const selections = selectionManagerService.getCurrentSelections();
|
|
1386
|
-
if (selections && selections[0]) {
|
|
1387
|
-
var _workbook$getStyles$g, _worksheet$getCell;
|
|
1388
|
-
const range = selections[0].range;
|
|
1389
|
-
const row = range.startRow;
|
|
1390
|
-
const col = range.startColumn;
|
|
1391
|
-
const numfmtValue = (_workbook$getStyles$g = workbook.getStyles().get((_worksheet$getCell = worksheet.getCell(row, col)) === null || _worksheet$getCell === void 0 ? void 0 : _worksheet$getCell.s)) === null || _workbook$getStyles$g === void 0 ? void 0 : _workbook$getStyles$g.n;
|
|
1392
|
-
const pattern = numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern;
|
|
1393
|
-
const currencySymbol = getCurrencySymbolByLocale(localeService.getCurrentLocale());
|
|
1394
|
-
let value = localeService.t("sheets-numfmt-ui.general");
|
|
1395
|
-
if (isDefaultFormat(pattern)) {
|
|
1396
|
-
subscribe.next(value);
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
if (pattern) {
|
|
1400
|
-
const item = MENU_OPTIONS(currencySymbol).filter((item) => typeof item === "object" && item.pattern).find((item) => isPatternEqualWithoutDecimal(pattern, item.pattern));
|
|
1401
|
-
if (item && typeof item === "object" && item.pattern) value = localeService.t(item.label);
|
|
1402
|
-
else value = localeService.t("sheets-numfmt-ui.moreFmt");
|
|
1403
|
-
}
|
|
1404
|
-
subscribe.next(value);
|
|
1405
|
-
}
|
|
1406
|
-
})));
|
|
1407
|
-
return {
|
|
1408
|
-
label: MORE_NUMFMT_TYPE_KEY,
|
|
1409
|
-
id: OpenNumfmtPanelOperator.id,
|
|
1410
|
-
tooltip: "sheets-numfmt-ui.title",
|
|
1411
|
-
type: MenuItemType.SELECTOR,
|
|
1412
|
-
slot: true,
|
|
1413
|
-
selections: [{ label: {
|
|
1414
|
-
name: OPTIONS_KEY,
|
|
1415
|
-
hoverable: false,
|
|
1416
|
-
selectable: false
|
|
1417
|
-
} }],
|
|
1418
|
-
value$,
|
|
1419
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1420
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
1421
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
1422
|
-
worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission],
|
|
1423
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
1424
|
-
})
|
|
1425
|
-
};
|
|
1426
|
-
};
|
|
1427
|
-
|
|
1428
|
-
//#endregion
|
|
1429
|
-
//#region src/views/components/MoreNumfmtType.tsx
|
|
1430
|
-
const MORE_NUMFMT_TYPE_KEY = "sheets-numfmt-ui.moreNumfmtType";
|
|
1431
|
-
const OPTIONS_KEY = "sheets-numfmt-ui.moreNumfmtType.options";
|
|
1432
|
-
function MoreNumfmtType(props) {
|
|
1433
|
-
const { value } = props;
|
|
1434
|
-
const localeService = useDependency(LocaleService);
|
|
1435
|
-
return /* @__PURE__ */ jsx("span", {
|
|
1436
|
-
className: "univer-text-sm",
|
|
1437
|
-
children: value !== null && value !== void 0 ? value : localeService.t("sheets-numfmt-ui.general")
|
|
1438
|
-
});
|
|
1439
|
-
}
|
|
1440
|
-
function Options() {
|
|
1441
|
-
const commandService = useDependency(ICommandService);
|
|
1442
|
-
const localeService = useDependency(LocaleService);
|
|
1443
|
-
const layoutService = useDependency(ILayoutService);
|
|
1444
|
-
const sheetsNumfmtCellContentController = useDependency(SheetsNumfmtCellContentController);
|
|
1445
|
-
const selectionManagerService = useDependency(SheetsSelectionsService);
|
|
1446
|
-
const setNumfmt = (pattern) => {
|
|
1447
|
-
const selection = selectionManagerService.getCurrentLastSelection();
|
|
1448
|
-
if (!selection) return;
|
|
1449
|
-
const range = selection.range;
|
|
1450
|
-
const values = [];
|
|
1451
|
-
Range.foreach(range, (row, col) => {
|
|
1452
|
-
if (pattern) values.push({
|
|
1453
|
-
row,
|
|
1454
|
-
col,
|
|
1455
|
-
pattern,
|
|
1456
|
-
type: getPatternType(pattern)
|
|
1457
|
-
});
|
|
1458
|
-
else values.push({
|
|
1459
|
-
row,
|
|
1460
|
-
col
|
|
1461
|
-
});
|
|
1462
|
-
});
|
|
1463
|
-
commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
1464
|
-
layoutService.focus();
|
|
1465
|
-
};
|
|
1466
|
-
const menuOptions = useMemo(() => {
|
|
1467
|
-
return MENU_OPTIONS(localeCurrencySymbolMap.get(localeService.getCurrentLocale()));
|
|
1468
|
-
}, [localeService]);
|
|
1469
|
-
const handleClick = (index) => {
|
|
1470
|
-
if (index === 0) setNumfmt(null);
|
|
1471
|
-
else if (index === menuOptions.length - 1) {
|
|
1472
|
-
commandService.executeCommand(OpenNumfmtPanelOperator.id);
|
|
1473
|
-
layoutService.focus();
|
|
1474
|
-
} else {
|
|
1475
|
-
const item = menuOptions[index];
|
|
1476
|
-
item.pattern && setNumfmt(item.pattern);
|
|
1477
|
-
}
|
|
1478
|
-
};
|
|
1479
|
-
const defaultValue = 1220;
|
|
1480
|
-
return /* @__PURE__ */ jsx("div", {
|
|
1481
|
-
className: "univer-grid univer-gap-1 univer-p-1.5",
|
|
1482
|
-
children: menuOptions.map((item, index) => {
|
|
1483
|
-
if (item === "|") return /* @__PURE__ */ jsx(Separator, {}, index);
|
|
1484
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
1485
|
-
className: "univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",
|
|
1486
|
-
onClick: () => handleClick(index),
|
|
1487
|
-
children: [/* @__PURE__ */ jsx("span", { children: localeService.t(item.label) }), /* @__PURE__ */ jsx("span", {
|
|
1488
|
-
className: "univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",
|
|
1489
|
-
children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, sheetsNumfmtCellContentController.locale).result.trim() : ""
|
|
1490
|
-
})]
|
|
1491
|
-
}, index);
|
|
1492
|
-
})
|
|
1493
|
-
});
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
1566
|
//#endregion
|
|
1497
1567
|
//#region src/menu/schema.ts
|
|
1498
1568
|
const menuSchema = { [RibbonStartGroup.LAYOUT]: {
|
|
@@ -1544,9 +1614,6 @@ let NumfmtMenuController = class NumfmtMenuController extends Disposable {
|
|
|
1544
1614
|
}
|
|
1545
1615
|
_initMenu() {
|
|
1546
1616
|
this._menuManagerService.mergeMenu(menuSchema);
|
|
1547
|
-
[[MORE_NUMFMT_TYPE_KEY, MoreNumfmtType], [OPTIONS_KEY, Options]].forEach(([key, comp]) => {
|
|
1548
|
-
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1549
|
-
});
|
|
1550
1617
|
}
|
|
1551
1618
|
};
|
|
1552
1619
|
NumfmtMenuController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, IMenuManagerService)], NumfmtMenuController);
|
|
@@ -1565,6 +1632,8 @@ let UniverSheetsNumfmtUIPlugin = class UniverSheetsNumfmtUIPlugin extends Plugin
|
|
|
1565
1632
|
this._configService.setConfig("sheets-numfmt-ui.config", rest);
|
|
1566
1633
|
}
|
|
1567
1634
|
onStarting() {
|
|
1635
|
+
this._injector.add([ComponentsController]);
|
|
1636
|
+
this._injector.get(ComponentsController);
|
|
1568
1637
|
registerDependencies(this._injector, [
|
|
1569
1638
|
[SheetNumfmtUIController],
|
|
1570
1639
|
[NumfmtEditorController],
|