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