@univerjs/sheets-numfmt 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -0
  3. package/lib/cjs/index.js +2844 -0
  4. package/lib/cjs/locale/en-US.js +50 -0
  5. package/lib/cjs/locale/zh-CN.js +50 -0
  6. package/lib/esm/index.js +2832 -0
  7. package/lib/esm/locale/en-US.js +29 -0
  8. package/lib/esm/locale/zh-CN.js +29 -0
  9. package/lib/index.css +78 -0
  10. package/lib/types/base/const/CURRENCY-SYMBOLS.d.ts +2 -0
  11. package/lib/types/base/const/CURRENCY-SYMBOLS.d.ts.map +1 -0
  12. package/lib/types/base/const/FORMATDETAIL.d.ts +23 -0
  13. package/lib/types/base/const/FORMATDETAIL.d.ts.map +1 -0
  14. package/lib/types/base/const/PLUGIN_NAME.d.ts +2 -0
  15. package/lib/types/base/const/PLUGIN_NAME.d.ts.map +1 -0
  16. package/lib/types/base/types/index.d.ts +8 -0
  17. package/lib/types/base/types/index.d.ts.map +1 -0
  18. package/lib/types/commands/commands/add.decimal.command.d.ts +3 -0
  19. package/lib/types/commands/commands/add.decimal.command.d.ts.map +1 -0
  20. package/lib/types/commands/commands/set.currency.command.d.ts +3 -0
  21. package/lib/types/commands/commands/set.currency.command.d.ts.map +1 -0
  22. package/lib/types/commands/commands/set.numfmt.command.d.ts +12 -0
  23. package/lib/types/commands/commands/set.numfmt.command.d.ts.map +1 -0
  24. package/lib/types/commands/commands/subtract.decimal.command.d.ts +3 -0
  25. package/lib/types/commands/commands/subtract.decimal.command.d.ts.map +1 -0
  26. package/lib/types/commands/operators/close.numfmt.panel.operator.d.ts +3 -0
  27. package/lib/types/commands/operators/close.numfmt.panel.operator.d.ts.map +1 -0
  28. package/lib/types/commands/operators/open.numfmt.panel.operator.d.ts +3 -0
  29. package/lib/types/commands/operators/open.numfmt.panel.operator.d.ts.map +1 -0
  30. package/lib/types/components/accounting/index.d.ts +5 -0
  31. package/lib/types/components/accounting/index.d.ts.map +1 -0
  32. package/lib/types/components/currency/index.d.ts +6 -0
  33. package/lib/types/components/currency/index.d.ts.map +1 -0
  34. package/lib/types/components/date/index.d.ts +5 -0
  35. package/lib/types/components/date/index.d.ts.map +1 -0
  36. package/lib/types/components/general/index.d.ts +5 -0
  37. package/lib/types/components/general/index.d.ts.map +1 -0
  38. package/lib/types/components/index.d.ts +16 -0
  39. package/lib/types/components/index.d.ts.map +1 -0
  40. package/lib/types/components/more-numfmt-type/MoreNumfmtType.d.ts +6 -0
  41. package/lib/types/components/more-numfmt-type/MoreNumfmtType.d.ts.map +1 -0
  42. package/lib/types/components/thousandth-percentile/index.d.ts +5 -0
  43. package/lib/types/components/thousandth-percentile/index.d.ts.map +1 -0
  44. package/lib/types/context/user-habit.d.ts +3 -0
  45. package/lib/types/context/user-habit.d.ts.map +1 -0
  46. package/lib/types/controllers/numfmt.controller.d.ts +42 -0
  47. package/lib/types/controllers/numfmt.controller.d.ts.map +1 -0
  48. package/lib/types/controllers/numfmt.editor.controller.d.ts +22 -0
  49. package/lib/types/controllers/numfmt.editor.controller.d.ts.map +1 -0
  50. package/lib/types/controllers/numfmt.ref-range.controller.d.ts +16 -0
  51. package/lib/types/controllers/numfmt.ref-range.controller.d.ts.map +1 -0
  52. package/lib/types/controllers/numfmt.sheet.controller.d.ts +12 -0
  53. package/lib/types/controllers/numfmt.sheet.controller.d.ts.map +1 -0
  54. package/lib/types/controllers/type.d.ts +5 -0
  55. package/lib/types/controllers/type.d.ts.map +1 -0
  56. package/lib/types/controllers/user-habit.controller.d.ts +19 -0
  57. package/lib/types/controllers/user-habit.controller.d.ts.map +1 -0
  58. package/lib/types/hooks/useCurrencyOptions.d.ts +5 -0
  59. package/lib/types/hooks/useCurrencyOptions.d.ts.map +1 -0
  60. package/lib/types/hooks/useNextTick.d.ts +2 -0
  61. package/lib/types/hooks/useNextTick.d.ts.map +1 -0
  62. package/lib/types/index.d.ts +2 -0
  63. package/lib/types/index.d.ts.map +1 -0
  64. package/lib/types/locale/en-US.d.ts +26 -0
  65. package/lib/types/locale/en-US.d.ts.map +1 -0
  66. package/lib/types/locale/index.d.ts +1 -0
  67. package/lib/types/locale/index.d.ts.map +1 -0
  68. package/lib/types/locale/zh-CN.d.ts +26 -0
  69. package/lib/types/locale/zh-CN.d.ts.map +1 -0
  70. package/lib/types/menu/menu.d.ts +32 -0
  71. package/lib/types/menu/menu.d.ts.map +1 -0
  72. package/lib/types/numfmt-plugin.d.ts +9 -0
  73. package/lib/types/numfmt-plugin.d.ts.map +1 -0
  74. package/lib/types/utils/currency.d.ts +2 -0
  75. package/lib/types/utils/currency.d.ts.map +1 -0
  76. package/lib/types/utils/decimal.d.ts +12 -0
  77. package/lib/types/utils/decimal.d.ts.map +1 -0
  78. package/lib/types/utils/options.d.ts +19 -0
  79. package/lib/types/utils/options.d.ts.map +1 -0
  80. package/lib/types/utils/pattern.d.ts +10 -0
  81. package/lib/types/utils/pattern.d.ts.map +1 -0
  82. package/package.json +68 -0
@@ -0,0 +1,2832 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _assert_this_initialized(self) {
13
+ if (self === void 0) {
14
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
15
+ }
16
+ return self;
17
+ }
18
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
19
+ try {
20
+ var info = gen[key](arg);
21
+ var value = info.value;
22
+ } catch (error) {
23
+ reject(error);
24
+ return;
25
+ }
26
+ if (info.done) {
27
+ resolve(value);
28
+ } else {
29
+ Promise.resolve(value).then(_next, _throw);
30
+ }
31
+ }
32
+ function _async_to_generator(fn) {
33
+ return function() {
34
+ var self = this, args = arguments;
35
+ return new Promise(function(resolve, reject) {
36
+ var gen = fn.apply(self, args);
37
+ function _next(value) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
39
+ }
40
+ function _throw(err) {
41
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
42
+ }
43
+ _next(undefined);
44
+ });
45
+ };
46
+ }
47
+ function _class_call_check(instance, Constructor) {
48
+ if (!(instance instanceof Constructor)) {
49
+ throw new TypeError("Cannot call a class as a function");
50
+ }
51
+ }
52
+ function _construct(Parent, args, Class) {
53
+ if (_is_native_reflect_construct()) {
54
+ _construct = Reflect.construct;
55
+ } else {
56
+ _construct = function construct(Parent, args, Class) {
57
+ var a = [
58
+ null
59
+ ];
60
+ a.push.apply(a, args);
61
+ var Constructor = Function.bind.apply(Parent, a);
62
+ var instance = new Constructor();
63
+ if (Class) _set_prototype_of(instance, Class.prototype);
64
+ return instance;
65
+ };
66
+ }
67
+ return _construct.apply(null, arguments);
68
+ }
69
+ function _defineProperties(target, props) {
70
+ for(var i = 0; i < props.length; i++){
71
+ var descriptor = props[i];
72
+ descriptor.enumerable = descriptor.enumerable || false;
73
+ descriptor.configurable = true;
74
+ if ("value" in descriptor) descriptor.writable = true;
75
+ Object.defineProperty(target, descriptor.key, descriptor);
76
+ }
77
+ }
78
+ function _create_class(Constructor, protoProps, staticProps) {
79
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
80
+ if (staticProps) _defineProperties(Constructor, staticProps);
81
+ return Constructor;
82
+ }
83
+ function _define_property(obj, key, value) {
84
+ if (key in obj) {
85
+ Object.defineProperty(obj, key, {
86
+ value: value,
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true
90
+ });
91
+ } else {
92
+ obj[key] = value;
93
+ }
94
+ return obj;
95
+ }
96
+ function _get_prototype_of(o) {
97
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
98
+ return o.__proto__ || Object.getPrototypeOf(o);
99
+ };
100
+ return _get_prototype_of(o);
101
+ }
102
+ function _inherits(subClass, superClass) {
103
+ if (typeof superClass !== "function" && superClass !== null) {
104
+ throw new TypeError("Super expression must either be null or a function");
105
+ }
106
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
107
+ constructor: {
108
+ value: subClass,
109
+ writable: true,
110
+ configurable: true
111
+ }
112
+ });
113
+ if (superClass) _set_prototype_of(subClass, superClass);
114
+ }
115
+ function _is_native_function(fn) {
116
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
117
+ }
118
+ function _iterable_to_array(iter) {
119
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
120
+ }
121
+ function _iterable_to_array_limit(arr, i) {
122
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
123
+ if (_i == null) return;
124
+ var _arr = [];
125
+ var _n = true;
126
+ var _d = false;
127
+ var _s, _e;
128
+ try {
129
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
130
+ _arr.push(_s.value);
131
+ if (i && _arr.length === i) break;
132
+ }
133
+ } catch (err) {
134
+ _d = true;
135
+ _e = err;
136
+ } finally{
137
+ try {
138
+ if (!_n && _i["return"] != null) _i["return"]();
139
+ } finally{
140
+ if (_d) throw _e;
141
+ }
142
+ }
143
+ return _arr;
144
+ }
145
+ function _non_iterable_rest() {
146
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
147
+ }
148
+ function _non_iterable_spread() {
149
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
150
+ }
151
+ function _object_spread(target) {
152
+ for(var i = 1; i < arguments.length; i++){
153
+ var source = arguments[i] != null ? arguments[i] : {};
154
+ var ownKeys = Object.keys(source);
155
+ if (typeof Object.getOwnPropertySymbols === "function") {
156
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
157
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
158
+ }));
159
+ }
160
+ ownKeys.forEach(function(key) {
161
+ _define_property(target, key, source[key]);
162
+ });
163
+ }
164
+ return target;
165
+ }
166
+ function ownKeys(object, enumerableOnly) {
167
+ var keys = Object.keys(object);
168
+ if (Object.getOwnPropertySymbols) {
169
+ var symbols = Object.getOwnPropertySymbols(object);
170
+ if (enumerableOnly) {
171
+ symbols = symbols.filter(function(sym) {
172
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
173
+ });
174
+ }
175
+ keys.push.apply(keys, symbols);
176
+ }
177
+ return keys;
178
+ }
179
+ function _object_spread_props(target, source) {
180
+ source = source != null ? source : {};
181
+ if (Object.getOwnPropertyDescriptors) {
182
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
183
+ } else {
184
+ ownKeys(Object(source)).forEach(function(key) {
185
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
186
+ });
187
+ }
188
+ return target;
189
+ }
190
+ function _possible_constructor_return(self, call) {
191
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
192
+ return call;
193
+ }
194
+ return _assert_this_initialized(self);
195
+ }
196
+ function _set_prototype_of(o, p) {
197
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
198
+ o.__proto__ = p;
199
+ return o;
200
+ };
201
+ return _set_prototype_of(o, p);
202
+ }
203
+ function _sliced_to_array(arr, i) {
204
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
205
+ }
206
+ function _to_consumable_array(arr) {
207
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
208
+ }
209
+ function _type_of(obj) {
210
+ "@swc/helpers - typeof";
211
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
212
+ }
213
+ function _unsupported_iterable_to_array(o, minLen) {
214
+ if (!o) return;
215
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
216
+ var n = Object.prototype.toString.call(o).slice(8, -1);
217
+ if (n === "Object" && o.constructor) n = o.constructor.name;
218
+ if (n === "Map" || n === "Set") return Array.from(n);
219
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
220
+ }
221
+ function _wrap_native_super(Class) {
222
+ var _cache = typeof Map === "function" ? new Map() : undefined;
223
+ _wrap_native_super = function wrapNativeSuper(Class) {
224
+ if (Class === null || !_is_native_function(Class)) return Class;
225
+ if (typeof Class !== "function") {
226
+ throw new TypeError("Super expression must either be null or a function");
227
+ }
228
+ if (typeof _cache !== "undefined") {
229
+ if (_cache.has(Class)) return _cache.get(Class);
230
+ _cache.set(Class, Wrapper);
231
+ }
232
+ function Wrapper() {
233
+ return _construct(Class, arguments, _get_prototype_of(this).constructor);
234
+ }
235
+ Wrapper.prototype = Object.create(Class.prototype, {
236
+ constructor: {
237
+ value: Wrapper,
238
+ enumerable: false,
239
+ writable: true,
240
+ configurable: true
241
+ }
242
+ });
243
+ return _set_prototype_of(Wrapper, Class);
244
+ };
245
+ return _wrap_native_super(Class);
246
+ }
247
+ function _is_native_reflect_construct() {
248
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
249
+ if (Reflect.construct.sham) return false;
250
+ if (typeof Proxy === "function") return true;
251
+ try {
252
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
253
+ return true;
254
+ } catch (e) {
255
+ return false;
256
+ }
257
+ }
258
+ function _create_super(Derived) {
259
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
260
+ return function _createSuperInternal() {
261
+ var Super = _get_prototype_of(Derived), result;
262
+ if (hasNativeReflectConstruct) {
263
+ var NewTarget = _get_prototype_of(this).constructor;
264
+ result = Reflect.construct(Super, arguments, NewTarget);
265
+ } else {
266
+ result = Super.apply(this, arguments);
267
+ }
268
+ return _possible_constructor_return(this, result);
269
+ };
270
+ }
271
+ function _ts_generator(thisArg, body) {
272
+ var f, y, t, g, _ = {
273
+ label: 0,
274
+ sent: function() {
275
+ if (t[0] & 1) throw t[1];
276
+ return t[1];
277
+ },
278
+ trys: [],
279
+ ops: []
280
+ };
281
+ return g = {
282
+ next: verb(0),
283
+ "throw": verb(1),
284
+ "return": verb(2)
285
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
286
+ return this;
287
+ }), g;
288
+ function verb(n) {
289
+ return function(v) {
290
+ return step([
291
+ n,
292
+ v
293
+ ]);
294
+ };
295
+ }
296
+ function step(op) {
297
+ if (f) throw new TypeError("Generator is already executing.");
298
+ while(_)try {
299
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
300
+ if (y = 0, t) op = [
301
+ op[0] & 2,
302
+ t.value
303
+ ];
304
+ switch(op[0]){
305
+ case 0:
306
+ case 1:
307
+ t = op;
308
+ break;
309
+ case 4:
310
+ _.label++;
311
+ return {
312
+ value: op[1],
313
+ done: false
314
+ };
315
+ case 5:
316
+ _.label++;
317
+ y = op[1];
318
+ op = [
319
+ 0
320
+ ];
321
+ continue;
322
+ case 7:
323
+ op = _.ops.pop();
324
+ _.trys.pop();
325
+ continue;
326
+ default:
327
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
328
+ _ = 0;
329
+ continue;
330
+ }
331
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
332
+ _.label = op[1];
333
+ break;
334
+ }
335
+ if (op[0] === 6 && _.label < t[1]) {
336
+ _.label = t[1];
337
+ t = op;
338
+ break;
339
+ }
340
+ if (t && _.label < t[2]) {
341
+ _.label = t[2];
342
+ _.ops.push(op);
343
+ break;
344
+ }
345
+ if (t[2]) _.ops.pop();
346
+ _.trys.pop();
347
+ continue;
348
+ }
349
+ op = body.call(thisArg, _);
350
+ } catch (e) {
351
+ op = [
352
+ 6,
353
+ e
354
+ ];
355
+ y = 0;
356
+ } finally{
357
+ f = t = 0;
358
+ }
359
+ if (op[0] & 5) throw op[1];
360
+ return {
361
+ value: op[0] ? op[1] : void 0,
362
+ done: true
363
+ };
364
+ }
365
+ }
366
+ var _class;
367
+ var __defProp = Object.defineProperty;
368
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
369
+ var __decorateClass = function(decorators, target, key2, kind) {
370
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target;
371
+ for(var i = decorators.length - 1, decorator; i >= 0; i--)if (decorator = decorators[i]) result = (kind ? decorator(target, key2, result) : decorator(result)) || result;
372
+ if (kind && result) __defProp(target, key2, result);
373
+ return result;
374
+ };
375
+ var __decorateParam = function(index, decorator) {
376
+ return function(target, key2) {
377
+ return decorator(target, key2, index);
378
+ };
379
+ };
380
+ // src/numfmt-plugin.ts
381
+ import { Plugin, PluginType } from "@univerjs/core";
382
+ import { Inject as Inject6, Injector as Injector5 } from "@wendellhu/redi";
383
+ // src/base/const/PLUGIN_NAME.ts
384
+ var SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN";
385
+ // src/controllers/numfmt.controller.ts
386
+ import { CellValueType, Disposable, DisposableCollection, ICommandService as ICommandService5, IUniverInstanceService as IUniverInstanceService5, LifecycleStages as LifecycleStages2, LocaleService as LocaleService6, LocaleType, ObjectMatrix, OnLifecycle, Range as Range4, Rectangle, ThemeService, toDisposable } from "@univerjs/core";
387
+ import { IRenderManagerService } from "@univerjs/engine-render";
388
+ import { ClearSelectionAllCommand, ClearSelectionFormatCommand, factorySetNumfmtUndoMutation as factorySetNumfmtUndoMutation2, INTERCEPTOR_POINT, INumfmtService as INumfmtService4, SelectionManagerService as SelectionManagerService5, SetNumfmtMutation as SetNumfmtMutation2, SheetInterceptorService } from "@univerjs/sheets";
389
+ import { APPLY_TYPE, getRepeatRange, IAutoFillService, SheetSkeletonManagerService } from "@univerjs/sheets-ui";
390
+ import { ComponentManager, IMenuService, ISidebarService } from "@univerjs/ui";
391
+ import { Inject as Inject2, Injector } from "@wendellhu/redi";
392
+ import { combineLatest, merge, Observable as Observable2 } from "rxjs";
393
+ import { debounceTime, distinctUntilChanged, map, switchMap, tap } from "rxjs/operators";
394
+ // src/commands/commands/add.decimal.command.ts
395
+ import { CommandType as CommandType2, ICommandService as ICommandService2, IUniverInstanceService as IUniverInstanceService2, Range } from "@univerjs/core";
396
+ import { INumfmtService, SelectionManagerService } from "@univerjs/sheets";
397
+ // src/utils/decimal.ts
398
+ import numfmt from "@univerjs/engine-numfmt";
399
+ var getDecimalFromPattern = function(pattern) {
400
+ var defaultValue = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
401
+ if (!pattern) {
402
+ return defaultValue;
403
+ }
404
+ var info = numfmt.getInfo(pattern);
405
+ var _info_maxDecimals;
406
+ return (_info_maxDecimals = info.maxDecimals) !== null && _info_maxDecimals !== void 0 ? _info_maxDecimals : defaultValue;
407
+ };
408
+ var isPatternEqualWithoutDecimal = function(patternA, patternB) {
409
+ if (patternA && !patternB || !patternA && patternB) {
410
+ return false;
411
+ }
412
+ var getString = function(tokens) {
413
+ return tokens.reduce(function(pre, cur) {
414
+ if (pre.isEnd) {
415
+ return pre;
416
+ }
417
+ var str = cur.value || cur.num;
418
+ if (cur.type === "point") {
419
+ pre.isEnd = true;
420
+ return pre;
421
+ }
422
+ return _object_spread_props(_object_spread({}, pre), {
423
+ result: pre.result + str
424
+ });
425
+ }, {
426
+ isEnd: false,
427
+ result: ""
428
+ }).result;
429
+ };
430
+ var partitionsA = numfmt.getInfo(patternA)._partitions;
431
+ var partitionsB = numfmt.getInfo(patternB)._partitions;
432
+ var A1 = getString(partitionsA[0].tokens);
433
+ var B1 = getString(partitionsB[0].tokens);
434
+ var A2 = getString(partitionsA[1].tokens);
435
+ var B2 = getString(partitionsB[1].tokens);
436
+ return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
437
+ };
438
+ var getDecimalString = function(length) {
439
+ return new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join("");
440
+ };
441
+ var setPatternDecimal = function(patterns, decimalLength) {
442
+ var tokens = patterns.split(";").map(function(pattern) {
443
+ if (/\.0?/.test(pattern)) {
444
+ return pattern.replace(/\.0*/g, "".concat(decimalLength > 0 ? "." : "").concat(getDecimalString(Number(decimalLength || 0))));
445
+ }
446
+ if (/0([^0]?)|0$/.test(pattern)) {
447
+ return pattern.replace(/0([^0]+)|0$/, "0".concat(decimalLength > 0 ? "." : "").concat(getDecimalString(Number(decimalLength || 0)), "$1"));
448
+ }
449
+ return pattern;
450
+ });
451
+ return tokens.join(";");
452
+ };
453
+ var isPatternHasDecimal = function(pattern) {
454
+ return /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern);
455
+ };
456
+ // src/commands/commands/set.numfmt.command.ts
457
+ import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from "@univerjs/core";
458
+ import { factorySetNumfmtUndoMutation, SetNumfmtMutation } from "@univerjs/sheets";
459
+ var SetNumfmtCommand = {
460
+ id: "sheet.command.numfmt.set.numfmt",
461
+ type: CommandType.COMMAND,
462
+ handler: function(accessor, params) {
463
+ if (!params) {
464
+ return false;
465
+ }
466
+ var commandService = accessor.get(ICommandService);
467
+ var univerInstanceService = accessor.get(IUniverInstanceService);
468
+ var undoRedoService = accessor.get(IUndoRedoService);
469
+ var workbook = univerInstanceService.getCurrentUniverSheetInstance();
470
+ var workbookId = workbook.getUnitId();
471
+ var worksheet = workbook.getActiveSheet();
472
+ var worksheetId = worksheet.getSheetId();
473
+ var redoOption = _object_spread_props(_object_spread({}, params), {
474
+ workbookId: workbookId,
475
+ worksheetId: worksheetId
476
+ });
477
+ var undoOption = factorySetNumfmtUndoMutation(accessor, redoOption);
478
+ var result = commandService.syncExecuteCommand(SetNumfmtMutation.id, redoOption);
479
+ if (result) {
480
+ undoRedoService.pushUndoRedo({
481
+ unitID: workbookId,
482
+ undoMutations: [
483
+ {
484
+ id: SetNumfmtMutation.id,
485
+ params: undoOption
486
+ }
487
+ ],
488
+ redoMutations: [
489
+ {
490
+ id: SetNumfmtMutation.id,
491
+ params: redoOption
492
+ }
493
+ ]
494
+ });
495
+ }
496
+ return result;
497
+ }
498
+ };
499
+ // src/commands/commands/add.decimal.command.ts
500
+ var AddDecimalCommand = {
501
+ id: "sheet.command.numfmt.add.decimal.command",
502
+ type: CommandType2.COMMAND,
503
+ handler: function() {
504
+ var _ref = _async_to_generator(function(accessor) {
505
+ var commandService, selectionManagerService, numfmtService, univerInstanceService, selections, workbook, sheet, workbookId, worksheetId, maxDecimals, decimals, pattern, values, result;
506
+ return _ts_generator(this, function(_state) {
507
+ switch(_state.label){
508
+ case 0:
509
+ commandService = accessor.get(ICommandService2);
510
+ selectionManagerService = accessor.get(SelectionManagerService);
511
+ numfmtService = accessor.get(INumfmtService);
512
+ univerInstanceService = accessor.get(IUniverInstanceService2);
513
+ selections = selectionManagerService.getSelections();
514
+ if (!selections || !selections.length) {
515
+ return [
516
+ 2,
517
+ false
518
+ ];
519
+ }
520
+ workbook = univerInstanceService.getCurrentUniverSheetInstance();
521
+ sheet = workbook.getActiveSheet();
522
+ workbookId = workbook.getUnitId();
523
+ worksheetId = sheet.getSheetId();
524
+ maxDecimals = 0;
525
+ selections.forEach(function(selection) {
526
+ Range.foreach(selection.range, function(row, col) {
527
+ var numfmtValue = numfmtService.getValue(workbookId, worksheetId, row, col);
528
+ if (!numfmtValue) {
529
+ return;
530
+ }
531
+ var decimals2 = getDecimalFromPattern(numfmtValue.pattern);
532
+ maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
533
+ });
534
+ });
535
+ decimals = maxDecimals + 1;
536
+ pattern = setPatternDecimal("0".concat(decimals > 0 ? ".0" : ""), decimals);
537
+ values = [];
538
+ selections.forEach(function(selection) {
539
+ Range.foreach(selection.range, function(row, col) {
540
+ var numfmtValue = numfmtService.getValue(workbookId, worksheetId, row, col);
541
+ if (!numfmtValue || isPatternEqualWithoutDecimal(numfmtValue.pattern, "0.0")) {
542
+ values.push({
543
+ row: row,
544
+ col: col,
545
+ pattern: pattern
546
+ });
547
+ } else {
548
+ var decimals2 = getDecimalFromPattern(numfmtValue.pattern);
549
+ var pattern2 = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
550
+ pattern2 !== numfmtValue.pattern && values.push({
551
+ row: row,
552
+ col: col,
553
+ pattern: pattern2
554
+ });
555
+ }
556
+ });
557
+ });
558
+ if (!values.length) return [
559
+ 3,
560
+ 2
561
+ ];
562
+ return [
563
+ 4,
564
+ commandService.executeCommand(SetNumfmtCommand.id, {
565
+ values: values
566
+ })
567
+ ];
568
+ case 1:
569
+ result = _state.sent();
570
+ return [
571
+ 2,
572
+ result
573
+ ];
574
+ case 2:
575
+ return [
576
+ 2,
577
+ false
578
+ ];
579
+ }
580
+ });
581
+ });
582
+ return function(accessor) {
583
+ return _ref.apply(this, arguments);
584
+ };
585
+ }()
586
+ };
587
+ // src/commands/commands/set.currency.command.ts
588
+ import { CommandType as CommandType3, ICommandService as ICommandService3, Range as Range2 } from "@univerjs/core";
589
+ import { SelectionManagerService as SelectionManagerService2 } from "@univerjs/sheets";
590
+ // src/base/const/FORMATDETAIL.ts
591
+ var DATEFMTLISG = [
592
+ {
593
+ label: "1930-08-05",
594
+ suffix: "yyyy-MM-dd"
595
+ },
596
+ {
597
+ label: "1930/08/05",
598
+ suffix: "yyyy/MM/dd"
599
+ },
600
+ {
601
+ label: "1930年08月05日",
602
+ suffix: 'yyyy"年"MM"月"dd"日"'
603
+ },
604
+ {
605
+ label: "08-05",
606
+ suffix: "MM-dd"
607
+ },
608
+ {
609
+ label: "8月5日",
610
+ suffix: 'M"月"d"日"'
611
+ },
612
+ {
613
+ label: "13:30:30",
614
+ suffix: "h:mm:ss"
615
+ },
616
+ {
617
+ label: "13:30",
618
+ suffix: "h:mm"
619
+ },
620
+ {
621
+ label: "下午01:30",
622
+ suffix: "A/P hh:mm"
623
+ },
624
+ {
625
+ label: "下午1:30",
626
+ suffix: "A/P h:mm"
627
+ },
628
+ {
629
+ label: "下午1:30:30",
630
+ suffix: "A/P h:mm:ss"
631
+ },
632
+ {
633
+ label: "08-05 下午 01:30",
634
+ suffix: "MM-dd A/P hh:mm"
635
+ }
636
+ ];
637
+ var NUMBERFORMAT = [
638
+ {
639
+ label: "(1,235)",
640
+ suffix: "#,##0_);(#,##0)"
641
+ },
642
+ {
643
+ label: "(1,235) ",
644
+ suffix: "#,##0_);[Red](#,##0)",
645
+ color: "red"
646
+ },
647
+ {
648
+ label: "1,234.56",
649
+ suffix: "#,##0.00_);#,##0.00"
650
+ },
651
+ {
652
+ label: "1,234.56",
653
+ suffix: "#,##0.00_);[Red]#,##0.00",
654
+ color: "red"
655
+ },
656
+ {
657
+ label: "-1,234.56",
658
+ suffix: "#,##0.00_);-#,##0.00"
659
+ },
660
+ {
661
+ label: "-1,234.56",
662
+ suffix: "#,##0.00_);[Red]-#,##0.00",
663
+ color: "red"
664
+ }
665
+ ];
666
+ var CURRENCYFORMAT = [
667
+ {
668
+ label: function(suffix) {
669
+ return "".concat(suffix, "1,235");
670
+ },
671
+ suffix: function(suffix) {
672
+ return '"'.concat(suffix, '"#,##0.00_);"').concat(suffix, '"#,##0.00');
673
+ }
674
+ },
675
+ {
676
+ label: function(suffix) {
677
+ return "".concat(suffix, "1,235");
678
+ },
679
+ suffix: function(suffix) {
680
+ return '"'.concat(suffix, '"#,##0.00_);[Red]"').concat(suffix, '"#,##0.00');
681
+ },
682
+ color: "red"
683
+ },
684
+ {
685
+ label: function(suffix) {
686
+ return "(".concat(suffix, "1,235)");
687
+ },
688
+ suffix: function(suffix) {
689
+ return '"'.concat(suffix, '"#,##0.00_);("').concat(suffix, '"#,##0.00)');
690
+ }
691
+ },
692
+ {
693
+ label: function(suffix) {
694
+ return "(".concat(suffix, "1,235)");
695
+ },
696
+ suffix: function(suffix) {
697
+ return '"'.concat(suffix, '"#,##0.00_);[Red]("').concat(suffix, '"#,##0.00)');
698
+ },
699
+ color: "red"
700
+ },
701
+ {
702
+ label: function(suffix) {
703
+ return "-".concat(suffix, "1,235");
704
+ },
705
+ suffix: function(suffix) {
706
+ return '"'.concat(suffix, '"#,##0.00_);-"').concat(suffix, '"#,##0.00');
707
+ }
708
+ },
709
+ {
710
+ label: function(suffix) {
711
+ return "-".concat(suffix, "1,235");
712
+ },
713
+ suffix: function(suffix) {
714
+ return '"'.concat(suffix, '"#,##0.00_);[Red]-"').concat(suffix, '"#,##0.00');
715
+ },
716
+ color: "red"
717
+ }
718
+ ];
719
+ // src/commands/commands/set.currency.command.ts
720
+ var SetCurrencyCommand = {
721
+ id: "sheet.command.numfmt.set.currency",
722
+ type: CommandType3.COMMAND,
723
+ handler: function() {
724
+ var _ref = _async_to_generator(function(accessor) {
725
+ var commandService, selectionManagerService, selections, values, suffix, result;
726
+ return _ts_generator(this, function(_state) {
727
+ switch(_state.label){
728
+ case 0:
729
+ commandService = accessor.get(ICommandService3);
730
+ selectionManagerService = accessor.get(SelectionManagerService2);
731
+ selections = selectionManagerService.getSelections();
732
+ if (!selections || !selections.length) {
733
+ return [
734
+ 2,
735
+ false
736
+ ];
737
+ }
738
+ values = [];
739
+ suffix = CURRENCYFORMAT[0].suffix("\xa5");
740
+ selections.forEach(function(selection) {
741
+ Range2.foreach(selection.range, function(row, col) {
742
+ values.push({
743
+ row: row,
744
+ col: col,
745
+ pattern: suffix,
746
+ type: "currency"
747
+ });
748
+ });
749
+ });
750
+ return [
751
+ 4,
752
+ commandService.executeCommand(SetNumfmtCommand.id, {
753
+ values: values
754
+ })
755
+ ];
756
+ case 1:
757
+ result = _state.sent();
758
+ return [
759
+ 2,
760
+ result
761
+ ];
762
+ }
763
+ });
764
+ });
765
+ return function(accessor) {
766
+ return _ref.apply(this, arguments);
767
+ };
768
+ }()
769
+ };
770
+ // src/commands/commands/subtract.decimal.command.ts
771
+ import { CommandType as CommandType4, ICommandService as ICommandService4, IUniverInstanceService as IUniverInstanceService3, Range as Range3 } from "@univerjs/core";
772
+ import { INumfmtService as INumfmtService2, SelectionManagerService as SelectionManagerService3 } from "@univerjs/sheets";
773
+ var SubtractDecimalCommand = {
774
+ id: "sheet.command.numfmt.subtract.decimal.command",
775
+ type: CommandType4.COMMAND,
776
+ handler: function() {
777
+ var _ref = _async_to_generator(function(accessor) {
778
+ var commandService, selectionManagerService, numfmtService, univerInstanceService, selections, workbook, sheet, workbookId, worksheetId, maxDecimals, decimals, pattern, values, result;
779
+ return _ts_generator(this, function(_state) {
780
+ switch(_state.label){
781
+ case 0:
782
+ commandService = accessor.get(ICommandService4);
783
+ selectionManagerService = accessor.get(SelectionManagerService3);
784
+ numfmtService = accessor.get(INumfmtService2);
785
+ univerInstanceService = accessor.get(IUniverInstanceService3);
786
+ selections = selectionManagerService.getSelections();
787
+ if (!selections || !selections.length) {
788
+ return [
789
+ 2,
790
+ false
791
+ ];
792
+ }
793
+ workbook = univerInstanceService.getCurrentUniverSheetInstance();
794
+ sheet = workbook.getActiveSheet();
795
+ workbookId = workbook.getUnitId();
796
+ worksheetId = sheet.getSheetId();
797
+ maxDecimals = 0;
798
+ selections.forEach(function(selection) {
799
+ Range3.foreach(selection.range, function(row, col) {
800
+ var numfmtValue = numfmtService.getValue(workbookId, worksheetId, row, col);
801
+ if (!numfmtValue) {
802
+ return;
803
+ }
804
+ var decimals2 = getDecimalFromPattern(numfmtValue.pattern);
805
+ maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
806
+ });
807
+ });
808
+ decimals = maxDecimals - 1;
809
+ pattern = setPatternDecimal("0".concat(decimals > 0 ? ".0" : "."), decimals);
810
+ values = [];
811
+ selections.forEach(function(selection) {
812
+ Range3.foreach(selection.range, function(row, col) {
813
+ var numfmtValue = numfmtService.getValue(workbookId, worksheetId, row, col);
814
+ if (!numfmtValue || isPatternEqualWithoutDecimal(numfmtValue.pattern, "0.0")) {
815
+ values.push({
816
+ row: row,
817
+ col: col,
818
+ pattern: pattern
819
+ });
820
+ } else {
821
+ var decimals2 = getDecimalFromPattern(numfmtValue.pattern);
822
+ values.push({
823
+ row: row,
824
+ col: col,
825
+ pattern: setPatternDecimal(numfmtValue.pattern, decimals2 - 1)
826
+ });
827
+ }
828
+ });
829
+ });
830
+ return [
831
+ 4,
832
+ commandService.executeCommand(SetNumfmtCommand.id, {
833
+ values: values
834
+ })
835
+ ];
836
+ case 1:
837
+ result = _state.sent();
838
+ return [
839
+ 2,
840
+ result
841
+ ];
842
+ }
843
+ });
844
+ });
845
+ return function(accessor) {
846
+ return _ref.apply(this, arguments);
847
+ };
848
+ }()
849
+ };
850
+ // src/commands/operators/close.numfmt.panel.operator.ts
851
+ import { CommandType as CommandType5 } from "@univerjs/core";
852
+ var CloseNumfmtPanelOperator = {
853
+ id: "sheet.operation.close.numfmt.panel",
854
+ type: CommandType5.OPERATION,
855
+ handler: function() {
856
+ return(// do nothing,just notify panel is closed
857
+ true);
858
+ }
859
+ };
860
+ // src/commands/operators/open.numfmt.panel.operator.ts
861
+ import { CommandType as CommandType6 } from "@univerjs/core";
862
+ // src/controllers/type.ts
863
+ import { LifecycleStages, runOnLifecycle } from "@univerjs/core";
864
+ import { createIdentifier } from "@wendellhu/redi";
865
+ var INumfmtController = createIdentifier("INumfmtController");
866
+ runOnLifecycle(LifecycleStages.Rendered, INumfmtController);
867
+ // src/commands/operators/open.numfmt.panel.operator.ts
868
+ var OpenNumfmtPanelOperator = {
869
+ id: "sheet.operation.open.numfmt.panel",
870
+ type: CommandType6.OPERATION,
871
+ handler: function(accessor) {
872
+ var numfmtController = accessor.get(INumfmtController);
873
+ numfmtController.openPanel();
874
+ return true;
875
+ }
876
+ };
877
+ // src/components/index.tsx
878
+ import { LocaleService as LocaleService5 } from "@univerjs/core";
879
+ import { Button, Select as Select3 } from "@univerjs/design";
880
+ import { useDependency as useDependency6 } from "@wendellhu/redi/react-bindings";
881
+ import React6, { useEffect as useEffect3, useMemo as useMemo5, useRef as useRef2, useState as useState7 } from "react";
882
+ // src/context/user-habit.ts
883
+ import { createContext } from "react";
884
+ var UserHabitCurrencyContext = createContext([]);
885
+ // src/hooks/useCurrencyOptions.ts
886
+ import { useDependency } from "@wendellhu/redi/react-bindings";
887
+ import { useEffect, useState } from "react";
888
+ // src/base/const/CURRENCY-SYMBOLS.ts
889
+ var currencySymbols = [
890
+ "$",
891
+ "\xa3",
892
+ "\xa5",
893
+ "\xa4",
894
+ "֏",
895
+ "؋",
896
+ "৳",
897
+ "฿",
898
+ // '៛',
899
+ "₡",
900
+ "₦",
901
+ "₩",
902
+ "₪",
903
+ "₫",
904
+ "€",
905
+ "₭",
906
+ "₮",
907
+ "₱",
908
+ "₲",
909
+ "₴",
910
+ "₸",
911
+ "₹",
912
+ "₺",
913
+ "₼",
914
+ "₽",
915
+ "₾",
916
+ "₿"
917
+ ];
918
+ // src/controllers/user-habit.controller.ts
919
+ import { ILocalStorageService } from "@univerjs/core";
920
+ import { Inject } from "@wendellhu/redi";
921
+ var UserHabitController = /*#__PURE__*/ function() {
922
+ "use strict";
923
+ function UserHabitController(_localStorageService) {
924
+ _class_call_check(this, UserHabitController);
925
+ this._localStorageService = _localStorageService;
926
+ }
927
+ _create_class(UserHabitController, [
928
+ {
929
+ key: "_getKey",
930
+ value: function _getKey(habit) {
931
+ return "userHabitController_".concat(habit);
932
+ }
933
+ },
934
+ {
935
+ key: "addHabit",
936
+ value: function addHabit(habit, initValue) {
937
+ var _this = this;
938
+ return _async_to_generator(function() {
939
+ var key2;
940
+ return _ts_generator(this, function(_state) {
941
+ key2 = _this._getKey(habit);
942
+ return [
943
+ 2,
944
+ _this._localStorageService.getItem(key2).then(function(item) {
945
+ if (!item) {
946
+ _this._localStorageService.setItem(key2, initValue);
947
+ }
948
+ })
949
+ ];
950
+ });
951
+ })();
952
+ }
953
+ },
954
+ {
955
+ key: "markHabit",
956
+ value: function markHabit(habit, value) {
957
+ var _this = this;
958
+ var key2 = this._getKey(habit);
959
+ this._localStorageService.getItem(key2).then(function(list) {
960
+ if (list) {
961
+ var index = list.findIndex(function(item) {
962
+ return item === value;
963
+ });
964
+ index > -1 && list.splice(index, 1);
965
+ list.unshift(value);
966
+ _this._localStorageService.setItem(key2, list);
967
+ }
968
+ });
969
+ }
970
+ },
971
+ {
972
+ key: "getHabit",
973
+ value: function getHabit(habit, sortList) {
974
+ var _this = this;
975
+ return _async_to_generator(function() {
976
+ var key2, result, priority;
977
+ return _ts_generator(this, function(_state) {
978
+ switch(_state.label){
979
+ case 0:
980
+ key2 = _this._getKey(habit);
981
+ return [
982
+ 4,
983
+ _this._localStorageService.getItem(key2)
984
+ ];
985
+ case 1:
986
+ result = _state.sent();
987
+ if (sortList && result) {
988
+ priority = result.map(function(item, index, arr) {
989
+ var length = arr.length;
990
+ return {
991
+ value: item,
992
+ priority: length - index
993
+ };
994
+ });
995
+ return [
996
+ 2,
997
+ sortList.sort(function(a, b) {
998
+ var _priority_find, _priority_find1;
999
+ var ap = ((_priority_find = priority.find(function(item) {
1000
+ return item.value === a;
1001
+ })) === null || _priority_find === void 0 ? void 0 : _priority_find.priority) || -1;
1002
+ var bp = ((_priority_find1 = priority.find(function(item) {
1003
+ return item.value === b;
1004
+ })) === null || _priority_find1 === void 0 ? void 0 : _priority_find1.priority) || -1;
1005
+ return bp - ap;
1006
+ })
1007
+ ];
1008
+ }
1009
+ return [
1010
+ 2,
1011
+ result || []
1012
+ ];
1013
+ }
1014
+ });
1015
+ })();
1016
+ }
1017
+ },
1018
+ {
1019
+ key: "deleteHabit",
1020
+ value: function deleteHabit(habit) {
1021
+ this._localStorageService.removeItem(habit);
1022
+ }
1023
+ }
1024
+ ]);
1025
+ return UserHabitController;
1026
+ }();
1027
+ UserHabitController = __decorateClass([
1028
+ __decorateParam(0, Inject(ILocalStorageService))
1029
+ ], UserHabitController);
1030
+ // src/hooks/useCurrencyOptions.ts
1031
+ var key = "numfmtCurrency";
1032
+ var useCurrencyOptions = function(onOptionChange) {
1033
+ var userHabitController = useDependency(UserHabitController);
1034
+ var _useState = _sliced_to_array(useState(currencySymbols), 2), options = _useState[0], optionsSet = _useState[1];
1035
+ useEffect(function() {
1036
+ userHabitController.addHabit("numfmtCurrency", []).then(function() {
1037
+ userHabitController.getHabit(key, _to_consumable_array(currencySymbols)).then(function(list) {
1038
+ optionsSet(list);
1039
+ onOptionChange && onOptionChange(list);
1040
+ });
1041
+ });
1042
+ }, []);
1043
+ var mark = function(v) {
1044
+ userHabitController.markHabit(key, v);
1045
+ };
1046
+ return {
1047
+ userHabitCurrency: options,
1048
+ mark: mark
1049
+ };
1050
+ };
1051
+ // src/hooks/useNextTick.ts
1052
+ import { useEffect as useEffect2, useRef, useState as useState2 } from "react";
1053
+ var useNextTick = function() {
1054
+ var effectList = useRef([]);
1055
+ var _useState2 = _sliced_to_array(useState2({}), 2), value = _useState2[0], dispatch = _useState2[1];
1056
+ useEffect2(function() {
1057
+ effectList.current.forEach(function(fn) {
1058
+ fn();
1059
+ });
1060
+ effectList.current = [];
1061
+ }, [
1062
+ value
1063
+ ]);
1064
+ var nextTick = function(fn) {
1065
+ effectList.current.push(fn);
1066
+ dispatch({});
1067
+ };
1068
+ return nextTick;
1069
+ };
1070
+ // src/utils/currency.ts
1071
+ var getCurrencyType = function(pattern) {
1072
+ var item = currencySymbols.find(function(code) {
1073
+ return pattern.includes(code);
1074
+ });
1075
+ return item;
1076
+ };
1077
+ // src/components/accounting/index.tsx
1078
+ import { LocaleService } from "@univerjs/core";
1079
+ import { InputNumber, Select } from "@univerjs/design";
1080
+ import { useDependency as useDependency2 } from "@wendellhu/redi/react-bindings";
1081
+ import React, { useContext, useMemo, useState as useState3 } from "react";
1082
+ var isAccountingPanel = function(pattern) {
1083
+ var type = getCurrencyType(pattern);
1084
+ return !!type && pattern.startsWith("_(");
1085
+ };
1086
+ var AccountingPanel = function(props) {
1087
+ var _useState3 = _sliced_to_array(useState3(function() {
1088
+ return getDecimalFromPattern(props.defaultPattern || "", 2);
1089
+ }), 2), decimal = _useState3[0], decimalSet = _useState3[1];
1090
+ var userHabitCurrency = useContext(UserHabitCurrencyContext);
1091
+ var _useState31 = _sliced_to_array(useState3(function() {
1092
+ return getCurrencyType(props.defaultPattern) || userHabitCurrency[0];
1093
+ }), 2), suffix = _useState31[0], suffixSet = _useState31[1];
1094
+ var options = useMemo(function() {
1095
+ return userHabitCurrency.map(function(key2) {
1096
+ return {
1097
+ label: key2,
1098
+ value: key2
1099
+ };
1100
+ });
1101
+ }, []);
1102
+ var localeService = useDependency2(LocaleService);
1103
+ var t = localeService.t;
1104
+ props.action.current = function() {
1105
+ return setPatternDecimal('_("'.concat(suffix, '"* #,##0').concat(decimal > 0 ? ".0" : "", "_)"), decimal);
1106
+ };
1107
+ var onSelect = function(v) {
1108
+ suffixSet(v);
1109
+ props.onChange(setPatternDecimal('_("'.concat(v, '"* #,##0').concat(decimal > 0 ? ".0" : "", "_)"), decimal));
1110
+ };
1111
+ var onDecimalChange = function(v) {
1112
+ var decimal2 = v || 0;
1113
+ decimalSet(decimal2);
1114
+ props.onChange(setPatternDecimal('_("'.concat(suffix, '"* #,##0').concat(decimal2 > 0 ? ".0" : "", "_)"), decimal2));
1115
+ };
1116
+ return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", {
1117
+ className: "m-t-16 options "
1118
+ }, /* @__PURE__ */ React.createElement("div", {
1119
+ className: "option"
1120
+ }, /* @__PURE__ */ React.createElement("div", {
1121
+ className: "label"
1122
+ }, t("sheet.numfmt.decimalLength")), /* @__PURE__ */ React.createElement("div", {
1123
+ className: "m-t-8 w-120"
1124
+ }, /* @__PURE__ */ React.createElement(InputNumber, {
1125
+ value: decimal,
1126
+ max: 20,
1127
+ min: 0,
1128
+ onChange: onDecimalChange
1129
+ }))), /* @__PURE__ */ React.createElement("div", {
1130
+ className: "option"
1131
+ }, /* @__PURE__ */ React.createElement("div", {
1132
+ className: "label"
1133
+ }, t("sheet.numfmt.currencyType")), /* @__PURE__ */ React.createElement("div", {
1134
+ className: "m-t-8 w-140"
1135
+ }, /* @__PURE__ */ React.createElement(Select, {
1136
+ onChange: onSelect,
1137
+ options: options,
1138
+ value: suffix
1139
+ })))), /* @__PURE__ */ React.createElement("div", {
1140
+ className: "describe m-t-14"
1141
+ }, t("sheet.numfmt.accountingDes")));
1142
+ };
1143
+ // src/components/currency/index.tsx
1144
+ import { LocaleService as LocaleService2 } from "@univerjs/core";
1145
+ import { InputNumber as InputNumber2, Select as Select2, SelectList } from "@univerjs/design";
1146
+ import { useDependency as useDependency3 } from "@wendellhu/redi/react-bindings";
1147
+ import React2, { useContext as useContext2, useMemo as useMemo2, useState as useState4 } from "react";
1148
+ // src/utils/options.ts
1149
+ var getCurrencyFormatOptions = function(suffix) {
1150
+ return CURRENCYFORMAT.map(function(item) {
1151
+ return {
1152
+ label: item.label(suffix),
1153
+ value: item.suffix(suffix),
1154
+ color: item.color
1155
+ };
1156
+ });
1157
+ };
1158
+ var getDateFormatOptions = function() {
1159
+ return DATEFMTLISG.map(function(item) {
1160
+ return {
1161
+ label: item.label,
1162
+ value: item.suffix
1163
+ };
1164
+ });
1165
+ };
1166
+ var getNumberFormatOptions = function() {
1167
+ return NUMBERFORMAT.map(function(item) {
1168
+ return {
1169
+ label: item.label,
1170
+ value: item.suffix,
1171
+ color: item.color
1172
+ };
1173
+ });
1174
+ };
1175
+ // src/components/currency/index.tsx
1176
+ var isCurrencyPanel = function(pattern) {
1177
+ var type = getCurrencyType(pattern);
1178
+ return !!type && !pattern.startsWith("_(");
1179
+ };
1180
+ var CurrencyPanel = function(props) {
1181
+ var localeService = useDependency3(LocaleService2);
1182
+ var t = localeService.t;
1183
+ var userHabitCurrency = useContext2(UserHabitCurrencyContext);
1184
+ var _useState4 = _sliced_to_array(useState4(function() {
1185
+ return getCurrencyType(props.defaultPattern) || userHabitCurrency[0];
1186
+ }), 2), suffix = _useState4[0], suffixSet = _useState4[1];
1187
+ var _useState41 = _sliced_to_array(useState4(function() {
1188
+ return getDecimalFromPattern(props.defaultPattern || "", 2);
1189
+ }), 2), decimal = _useState41[0], decimalSet = _useState41[1];
1190
+ var _useState42 = _sliced_to_array(useState4(function() {
1191
+ var _negativeOptions2_find;
1192
+ var negativeOptions2 = getCurrencyFormatOptions(suffix);
1193
+ var pattern2 = ((_negativeOptions2_find = negativeOptions2.find(function(item) {
1194
+ return isPatternEqualWithoutDecimal(item.value, props.defaultPattern);
1195
+ })) === null || _negativeOptions2_find === void 0 ? void 0 : _negativeOptions2_find.value) || negativeOptions2[0].value;
1196
+ return pattern2;
1197
+ }), 2), pattern = _useState42[0], patternSet = _useState42[1];
1198
+ var negativeOptions = useMemo2(function() {
1199
+ return getCurrencyFormatOptions(suffix);
1200
+ }, [
1201
+ suffix
1202
+ ]);
1203
+ var options = useMemo2(function() {
1204
+ return userHabitCurrency.map(function(key2) {
1205
+ return {
1206
+ label: key2,
1207
+ value: key2
1208
+ };
1209
+ });
1210
+ }, [
1211
+ userHabitCurrency
1212
+ ]);
1213
+ props.action.current = function() {
1214
+ return setPatternDecimal(pattern, decimal);
1215
+ };
1216
+ var onSelect = function(value) {
1217
+ suffixSet(value);
1218
+ var pattern2 = getCurrencyFormatOptions(value)[0].value;
1219
+ patternSet(pattern2);
1220
+ props.onChange(setPatternDecimal(pattern2, decimal));
1221
+ };
1222
+ var onChange = function(value) {
1223
+ patternSet(value);
1224
+ props.onChange(setPatternDecimal(value, decimal));
1225
+ };
1226
+ var onDecimalChange = function(v) {
1227
+ decimalSet(v || 0);
1228
+ props.onChange(setPatternDecimal(pattern, v || 0));
1229
+ };
1230
+ return /* @__PURE__ */ React2.createElement("div", null, /* @__PURE__ */ React2.createElement("div", {
1231
+ className: "m-t-16 options "
1232
+ }, /* @__PURE__ */ React2.createElement("div", {
1233
+ className: "option"
1234
+ }, /* @__PURE__ */ React2.createElement("div", {
1235
+ className: "label"
1236
+ }, t("sheet.numfmt.decimalLength")), /* @__PURE__ */ React2.createElement("div", {
1237
+ className: "m-t-8 w-120"
1238
+ }, /* @__PURE__ */ React2.createElement(InputNumber2, {
1239
+ value: decimal,
1240
+ max: 20,
1241
+ min: 0,
1242
+ onChange: onDecimalChange
1243
+ }))), /* @__PURE__ */ React2.createElement("div", {
1244
+ className: "option"
1245
+ }, /* @__PURE__ */ React2.createElement("div", {
1246
+ className: "label"
1247
+ }, " ", t("sheet.numfmt.currencyType")), /* @__PURE__ */ React2.createElement("div", {
1248
+ className: "m-t-8 w-140"
1249
+ }, /* @__PURE__ */ React2.createElement(Select2, {
1250
+ onChange: onSelect,
1251
+ options: options,
1252
+ value: suffix
1253
+ })))), /* @__PURE__ */ React2.createElement("div", {
1254
+ className: "m-t-16 label"
1255
+ }, " ", t("sheet.numfmt.negType")), /* @__PURE__ */ React2.createElement("div", {
1256
+ className: "m-t-8"
1257
+ }, /* @__PURE__ */ React2.createElement(SelectList, {
1258
+ onChange: onChange,
1259
+ options: negativeOptions,
1260
+ value: pattern
1261
+ })), /* @__PURE__ */ React2.createElement("div", {
1262
+ className: "describe m-t-14"
1263
+ }, t("sheet.numfmt.currencyDes")));
1264
+ };
1265
+ // src/components/date/index.tsx
1266
+ import { LocaleService as LocaleService3 } from "@univerjs/core";
1267
+ import { SelectList as SelectList2 } from "@univerjs/design";
1268
+ import numfmt2 from "@univerjs/engine-numfmt";
1269
+ import { useDependency as useDependency4 } from "@wendellhu/redi/react-bindings";
1270
+ import React3, { useMemo as useMemo3, useState as useState5 } from "react";
1271
+ var isDatePanel = function(pattern) {
1272
+ var info = numfmt2.getInfo(pattern);
1273
+ return getDateFormatOptions().map(function(item) {
1274
+ return item.value;
1275
+ }).includes(pattern) || [
1276
+ "date",
1277
+ "datetime",
1278
+ "time"
1279
+ ].includes(info.type);
1280
+ };
1281
+ var DatePanel = function(props) {
1282
+ var options = useMemo3(getDateFormatOptions, []);
1283
+ var localeService = useDependency4(LocaleService3);
1284
+ var t = localeService.t;
1285
+ var _useState5 = _sliced_to_array(useState5(function() {
1286
+ if (props.defaultPattern) {
1287
+ var item = options.find(function(item2) {
1288
+ return item2.value === props.defaultPattern;
1289
+ });
1290
+ if (item) {
1291
+ return item.value;
1292
+ }
1293
+ }
1294
+ return options[0].value;
1295
+ }), 2), suffix = _useState5[0], suffixSet = _useState5[1];
1296
+ props.action.current = function() {
1297
+ return suffix;
1298
+ };
1299
+ var onChange = function(v) {
1300
+ suffixSet(v);
1301
+ props.onChange(v);
1302
+ };
1303
+ return /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement("div", {
1304
+ className: "m-t-16 label"
1305
+ }, t("sheet.numfmt.dateType")), /* @__PURE__ */ React3.createElement("div", {
1306
+ className: "m-t-8"
1307
+ }, /* @__PURE__ */ React3.createElement(SelectList2, {
1308
+ value: suffix,
1309
+ options: options,
1310
+ onChange: onChange
1311
+ })), /* @__PURE__ */ React3.createElement("div", {
1312
+ className: "describe m-t-14"
1313
+ }, t("sheet.numfmt.dateDes")));
1314
+ };
1315
+ // src/components/general/index.tsx
1316
+ import { LocaleService as LocaleService4 } from "@univerjs/core";
1317
+ import { useDependency as useDependency5 } from "@wendellhu/redi/react-bindings";
1318
+ import React4 from "react";
1319
+ var isGeneralPanel = function(pattern) {
1320
+ return !pattern;
1321
+ };
1322
+ var GeneralPanel = function(props) {
1323
+ var localeService = useDependency5(LocaleService4);
1324
+ var t = localeService.t;
1325
+ props.action.current = function() {
1326
+ return "";
1327
+ };
1328
+ return /* @__PURE__ */ React4.createElement("div", null, /* @__PURE__ */ React4.createElement("div", {
1329
+ className: "describe m-t-14"
1330
+ }, t("sheet.numfmt.generalDes")));
1331
+ };
1332
+ // src/components/thousandth-percentile/index.tsx
1333
+ import { InputNumber as InputNumber3, SelectList as SelectList3 } from "@univerjs/design";
1334
+ import React5, { useMemo as useMemo4, useState as useState6 } from "react";
1335
+ var isThousandthPercentilePanel = function(pattern) {
1336
+ return getNumberFormatOptions().some(function(item) {
1337
+ return isPatternEqualWithoutDecimal(item.value, pattern);
1338
+ });
1339
+ };
1340
+ var ThousandthPercentilePanel = function(props) {
1341
+ var options = useMemo4(getNumberFormatOptions, []);
1342
+ var _useState6 = _sliced_to_array(useState6(function() {
1343
+ return getDecimalFromPattern(props.defaultPattern || "", 0);
1344
+ }), 2), decimal = _useState6[0], decimalSet = _useState6[1];
1345
+ var _useState61 = _sliced_to_array(useState6(function() {
1346
+ var item = options.find(function(item2) {
1347
+ return isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || "");
1348
+ });
1349
+ return (item === null || item === void 0 ? void 0 : item.value) || options[0].value;
1350
+ }), 2), suffix = _useState61[0], suffixSet = _useState61[1];
1351
+ var pattern = useMemo4(function() {
1352
+ return setPatternDecimal(suffix, Number(decimal || 0));
1353
+ }, [
1354
+ suffix,
1355
+ decimal
1356
+ ]);
1357
+ var isInputDisable = useMemo4(function() {
1358
+ return !isPatternHasDecimal(suffix);
1359
+ }, [
1360
+ suffix
1361
+ ]);
1362
+ var handleClick = function(v) {
1363
+ decimalSet(getDecimalFromPattern(v, 0));
1364
+ suffixSet(v);
1365
+ };
1366
+ props.action.current = function() {
1367
+ return pattern;
1368
+ };
1369
+ return /* @__PURE__ */ React5.createElement("div", null, /* @__PURE__ */ React5.createElement("div", {
1370
+ className: "m-t-16 label"
1371
+ }, "小数位数"), /* @__PURE__ */ React5.createElement("div", {
1372
+ className: "m-t-8"
1373
+ }, /* @__PURE__ */ React5.createElement(InputNumber3, {
1374
+ disabled: isInputDisable,
1375
+ value: decimal,
1376
+ max: 20,
1377
+ min: 0,
1378
+ onChange: function(value) {
1379
+ return decimalSet(value || 0);
1380
+ }
1381
+ })), /* @__PURE__ */ React5.createElement("div", {
1382
+ className: "m-t-16 label"
1383
+ }, " 负数类型"), /* @__PURE__ */ React5.createElement("div", {
1384
+ className: "m-t-8"
1385
+ }, /* @__PURE__ */ React5.createElement(SelectList3, {
1386
+ onChange: handleClick,
1387
+ options: options,
1388
+ value: suffix
1389
+ })), /* @__PURE__ */ React5.createElement("div", {
1390
+ className: "describe m-t-14"
1391
+ }, "数值格式用于一般数字的表示。货币和会计格式则提供货币值计算的专用格式。"));
1392
+ };
1393
+ // src/components/index.tsx
1394
+ var SheetNumfmtPanel = function(props) {
1395
+ var findDefaultType = function findDefaultType() {
1396
+ var list = [
1397
+ isGeneralPanel,
1398
+ isAccountingPanel,
1399
+ isCurrencyPanel,
1400
+ isDatePanel,
1401
+ isThousandthPercentilePanel
1402
+ ];
1403
+ return list.reduce(function(pre, curFn, index) {
1404
+ return pre || (curFn(defaultPattern) ? typeOptions[index].label : "");
1405
+ }, "") || typeOptions[0].label;
1406
+ };
1407
+ var _props_value = props.value, defaultValue = _props_value.defaultValue, defaultPattern = _props_value.defaultPattern, row = _props_value.row, col = _props_value.col;
1408
+ var localeService = useDependency6(LocaleService5);
1409
+ var getCurrentPattern = useRef2(function() {
1410
+ return "";
1411
+ });
1412
+ var t = localeService.t;
1413
+ var nextTick = useNextTick();
1414
+ var pattern = useRef2("");
1415
+ var typeOptions = useMemo5(function() {
1416
+ return [
1417
+ {
1418
+ label: "sheet.numfmt.general",
1419
+ component: GeneralPanel
1420
+ },
1421
+ {
1422
+ label: "sheet.numfmt.accounting",
1423
+ component: AccountingPanel
1424
+ },
1425
+ {
1426
+ label: "sheet.numfmt.currency",
1427
+ component: CurrencyPanel
1428
+ },
1429
+ {
1430
+ label: "sheet.numfmt.date",
1431
+ component: DatePanel
1432
+ },
1433
+ {
1434
+ label: "sheet.numfmt.thousandthPercentile",
1435
+ component: ThousandthPercentilePanel
1436
+ }
1437
+ ].map(function(item) {
1438
+ return _object_spread_props(_object_spread({}, item), {
1439
+ label: t(item.label)
1440
+ });
1441
+ });
1442
+ }, []);
1443
+ var _useState7 = _sliced_to_array(useState7(findDefaultType), 2), type = _useState7[0], typeSet = _useState7[1];
1444
+ var _useState71 = _sliced_to_array(useState7(function() {
1445
+ return "".concat(row, "_").concat(col);
1446
+ }), 2), key2 = _useState71[0], keySet = _useState71[1];
1447
+ var _useCurrencyOptions = useCurrencyOptions(function() {
1448
+ return keySet("".concat(row, "_").concat(col, "_userCurrency'"));
1449
+ }), mark = _useCurrencyOptions.mark, userHabitCurrency = _useCurrencyOptions.userHabitCurrency;
1450
+ var BusinessComponent = useMemo5(function() {
1451
+ var _typeOptions_find;
1452
+ return (_typeOptions_find = typeOptions.find(function(item) {
1453
+ return item.label === type;
1454
+ })) === null || _typeOptions_find === void 0 ? void 0 : _typeOptions_find.component;
1455
+ }, [
1456
+ type
1457
+ ]);
1458
+ var selectOptions = typeOptions.map(function(option) {
1459
+ return {
1460
+ label: option.label,
1461
+ value: option.label
1462
+ };
1463
+ });
1464
+ var handleSelect = function(value) {
1465
+ typeSet(value);
1466
+ nextTick(function() {
1467
+ return props.onChange({
1468
+ type: "change",
1469
+ value: getCurrentPattern.current() || ""
1470
+ });
1471
+ });
1472
+ };
1473
+ var handleChange = function(v) {
1474
+ pattern.current = v;
1475
+ props.onChange({
1476
+ type: "change",
1477
+ value: v
1478
+ });
1479
+ };
1480
+ var handleConfirm = function() {
1481
+ var currency = getCurrencyType(pattern.current);
1482
+ if (currency) {
1483
+ mark(currency);
1484
+ }
1485
+ props.onChange({
1486
+ type: "confirm",
1487
+ value: pattern.current
1488
+ });
1489
+ };
1490
+ var handleCancel = function() {
1491
+ props.onChange({
1492
+ type: "cancel",
1493
+ value: pattern.current
1494
+ });
1495
+ };
1496
+ var subProps = {
1497
+ onChange: handleChange,
1498
+ defaultValue: defaultValue,
1499
+ defaultPattern: defaultPattern,
1500
+ action: getCurrentPattern
1501
+ };
1502
+ useEffect3(function() {
1503
+ typeSet(findDefaultType());
1504
+ keySet("".concat(row, "_").concat(col));
1505
+ }, [
1506
+ row,
1507
+ col
1508
+ ]);
1509
+ return /* @__PURE__ */ React6.createElement("div", {
1510
+ className: "numfmt-panel p-b-20"
1511
+ }, /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("div", {
1512
+ className: "label m-t-14"
1513
+ }, t("sheet.numfmt.numfmtType")), /* @__PURE__ */ React6.createElement("div", {
1514
+ className: "m-t-8"
1515
+ }, /* @__PURE__ */ React6.createElement(Select3, {
1516
+ onChange: handleSelect,
1517
+ options: selectOptions,
1518
+ value: type
1519
+ })), /* @__PURE__ */ React6.createElement("div", null, BusinessComponent && /* @__PURE__ */ React6.createElement(UserHabitCurrencyContext.Provider, {
1520
+ value: userHabitCurrency
1521
+ }, /* @__PURE__ */ React6.createElement(BusinessComponent, _object_spread_props(_object_spread({}, subProps), {
1522
+ key: key2
1523
+ }))))), /* @__PURE__ */ React6.createElement("div", {
1524
+ className: "btn-list m-t-14 m-b-20"
1525
+ }, /* @__PURE__ */ React6.createElement(Button, {
1526
+ size: "small",
1527
+ onClick: handleCancel,
1528
+ className: "m-r-12"
1529
+ }, t("sheet.numfmt.cancel")), /* @__PURE__ */ React6.createElement(Button, {
1530
+ type: "primary",
1531
+ size: "small",
1532
+ onClick: handleConfirm
1533
+ }, t("sheet.numfmt.confirm"))));
1534
+ };
1535
+ // src/locale/zh-CN.ts
1536
+ var zhCn = {
1537
+ sheet: {
1538
+ numfmt: {
1539
+ title: "数据格式",
1540
+ numfmtType: "格式类型",
1541
+ cancel: "取消",
1542
+ confirm: "确认",
1543
+ general: "常规",
1544
+ accounting: "会计",
1545
+ currency: "货币",
1546
+ date: "日期",
1547
+ thousandthPercentile: "千分位符",
1548
+ preview: "示例",
1549
+ decimalLength: "小数位数",
1550
+ currencyType: "货币类型",
1551
+ currencyDes: "货币格式用于表示一般货币数值。会计格式可以对一列数值进行小数点对齐",
1552
+ accountingDes: "会计数字格式可对一列数值进行货币符号和小数点对齐",
1553
+ dateType: "日期类型",
1554
+ dateDes: "日期格式将日期和时间系列数值品示为日期值。",
1555
+ negType: "负数类型",
1556
+ generalDes: "常规格式不包含任何特定的数字格式。",
1557
+ thousandthPercentileDes: "千分位符格式用于一般数字的表示。货币和会计格式则提供货币值计算的专用格式。"
1558
+ }
1559
+ }
1560
+ };
1561
+ // src/menu/menu.ts
1562
+ import { IUniverInstanceService as IUniverInstanceService4 } from "@univerjs/core";
1563
+ import { AddDigitsSingle, MoreDownSingle as MoreDownSingle2, ReduceDigitsSingle, RmbSingle } from "@univerjs/icons";
1564
+ import { INumfmtService as INumfmtService3, SelectionManagerService as SelectionManagerService4 } from "@univerjs/sheets";
1565
+ import { MenuGroup, MenuItemType, MenuPosition } from "@univerjs/ui";
1566
+ import { Observable } from "rxjs";
1567
+ // src/components/more-numfmt-type/MoreNumfmtType.tsx
1568
+ import { MoreDownSingle } from "@univerjs/icons";
1569
+ import React7 from "react";
1570
+ var MoreNumfmtType = function(props) {
1571
+ var _props_value;
1572
+ var value = (_props_value = props.value) !== null && _props_value !== void 0 ? _props_value : "常规";
1573
+ return /* @__PURE__ */ React7.createElement("span", {
1574
+ className: "more-numfmt-type"
1575
+ }, value, /* @__PURE__ */ React7.createElement("div", {
1576
+ className: "icon"
1577
+ }, /* @__PURE__ */ React7.createElement(MoreDownSingle, null)));
1578
+ };
1579
+ // src/menu/menu.ts
1580
+ var CurrencyMenuItem = function(componentManager) {
1581
+ var iconKey = "icon-rmbSingle";
1582
+ componentManager.register(iconKey, RmbSingle);
1583
+ componentManager.register("MoreDownSingle", MoreDownSingle2);
1584
+ return function() {
1585
+ return {
1586
+ icon: iconKey,
1587
+ id: SetCurrencyCommand.id,
1588
+ title: "numfmt.menu.currency",
1589
+ tooltip: "numfmt.menu.currency",
1590
+ type: MenuItemType.BUTTON,
1591
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1592
+ positions: [
1593
+ MenuPosition.TOOLBAR_START
1594
+ ]
1595
+ };
1596
+ };
1597
+ };
1598
+ var AddDecimalMenuItem = function(componentManager) {
1599
+ var iconKey = "icon-addDigitsSingle";
1600
+ componentManager.register(iconKey, AddDigitsSingle);
1601
+ return function() {
1602
+ return {
1603
+ icon: iconKey,
1604
+ id: AddDecimalCommand.id,
1605
+ title: "numfmt.menu.add.decimal",
1606
+ tooltip: "numfmt.menu.add.decimal",
1607
+ type: MenuItemType.BUTTON,
1608
+ positions: [
1609
+ MenuPosition.TOOLBAR_START
1610
+ ],
1611
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT
1612
+ };
1613
+ };
1614
+ };
1615
+ var SubtractDecimalMenuItem = function(componentManager) {
1616
+ var iconKey = "icon-reduceDigitsSingle";
1617
+ componentManager.register(iconKey, ReduceDigitsSingle);
1618
+ return function() {
1619
+ return {
1620
+ icon: iconKey,
1621
+ id: SubtractDecimalCommand.id,
1622
+ title: "numfmt.menu.subtract.decimal",
1623
+ tooltip: "numfmt.menu.subtract.decimal",
1624
+ type: MenuItemType.BUTTON,
1625
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1626
+ positions: [
1627
+ MenuPosition.TOOLBAR_START
1628
+ ]
1629
+ };
1630
+ };
1631
+ };
1632
+ var FactoryOtherMenuItem = function(componentManager) {
1633
+ componentManager.register("sheet.numfmt.moreNumfmtType", MoreNumfmtType);
1634
+ return function(_accessor) {
1635
+ var numfmtService = _accessor.get(INumfmtService3);
1636
+ var univerInstanceService = _accessor.get(IUniverInstanceService4);
1637
+ var selectionManagerService = _accessor.get(SelectionManagerService4);
1638
+ var value$ = new Observable(function(subscribe) {
1639
+ return selectionManagerService.selectionInfo$.subscribe(function(selections) {
1640
+ if (selections && selections[0]) {
1641
+ var workbook = univerInstanceService.getCurrentUniverSheetInstance();
1642
+ var worksheet = workbook.getActiveSheet();
1643
+ var range = selections[0].range;
1644
+ var row = range.startRow;
1645
+ var col = range.startColumn;
1646
+ var numfmtValue = numfmtService.getValue(workbook.getUnitId(), worksheet.getSheetId(), row, col);
1647
+ var value = "常规";
1648
+ if (numfmtValue) {
1649
+ var pattern = numfmtValue.pattern;
1650
+ if (isAccountingPanel(pattern)) {
1651
+ value = "会计";
1652
+ }
1653
+ if (isCurrencyPanel(pattern)) {
1654
+ value = "货币";
1655
+ }
1656
+ if (isDatePanel(pattern)) {
1657
+ value = "日期";
1658
+ }
1659
+ if (isThousandthPercentilePanel(pattern)) {
1660
+ value = "千分位";
1661
+ }
1662
+ }
1663
+ subscribe.next(value);
1664
+ }
1665
+ });
1666
+ });
1667
+ return {
1668
+ // icon: 'MoreDownSingle',
1669
+ label: "sheet.numfmt.moreNumfmtType",
1670
+ id: OpenNumfmtPanelOperator.id,
1671
+ // title: 'numfmt.menu.preview',
1672
+ tooltip: "numfmt.menu.preview",
1673
+ type: MenuItemType.BUTTON,
1674
+ group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
1675
+ positions: [
1676
+ MenuPosition.TOOLBAR_START
1677
+ ],
1678
+ value$: value$
1679
+ };
1680
+ };
1681
+ };
1682
+ // src/utils/pattern.ts
1683
+ import numfmt3 from "@univerjs/engine-numfmt";
1684
+ var getPatternType = function(pattern) {
1685
+ return numfmt3.getInfo(pattern).type || "unknown";
1686
+ };
1687
+ var getPatternPreview = function(pattern, value) {
1688
+ var info = numfmt3.getInfo(pattern);
1689
+ var negInfo = info._partitions[1];
1690
+ var result = numfmt3.format(pattern, value, {
1691
+ locale: "zh-CN"
1692
+ });
1693
+ if (value < 0) {
1694
+ return {
1695
+ result: result,
1696
+ color: negInfo.color
1697
+ };
1698
+ }
1699
+ return {
1700
+ result: result
1701
+ };
1702
+ };
1703
+ // src/controllers/numfmt.controller.ts
1704
+ var NumfmtController = /*#__PURE__*/ function(Disposable) {
1705
+ "use strict";
1706
+ _inherits(NumfmtController, Disposable);
1707
+ var _super = _create_super(NumfmtController);
1708
+ function NumfmtController(_sheetInterceptorService, _themeService, _injector, _univerInstanceService, _sheetSkeletonManagerService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _menuService, _sidebarService, _localeService, _autoFillService) {
1709
+ _class_call_check(this, NumfmtController);
1710
+ var _this;
1711
+ _this = _super.call(this);
1712
+ /**
1713
+ * If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
1714
+ * @private
1715
+ * @type {(string | null)}
1716
+ * @memberof NumfmtController
1717
+ */ _define_property(_assert_this_initialized(_this), "_previewPattern", "");
1718
+ _define_property(_assert_this_initialized(_this), "openPanel", function() {
1719
+ var sidebarService = _this._sidebarService;
1720
+ var selectionManagerService = _this._selectionManagerService;
1721
+ var commandService = _this._commandService;
1722
+ var univerInstanceService = _this._univerInstanceService;
1723
+ var numfmtService = _this._numfmtService;
1724
+ var localeService = _this._localeService;
1725
+ var selections = selectionManagerService.getSelectionRanges() || [];
1726
+ var range = selections[0];
1727
+ if (!range) {
1728
+ return false;
1729
+ }
1730
+ var workbook = univerInstanceService.getCurrentUniverSheetInstance();
1731
+ var sheet = workbook.getActiveSheet();
1732
+ var cellValue = sheet.getCellRaw(range.startRow, range.startColumn);
1733
+ var numfmtValue = numfmtService.getValue(workbook.getUnitId(), sheet.getSheetId(), range.startRow, range.startColumn);
1734
+ var pattern = "";
1735
+ if (numfmtValue) {
1736
+ pattern = numfmtValue.pattern;
1737
+ }
1738
+ var defaultValue = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678;
1739
+ var props = {
1740
+ onChange: function(config) {
1741
+ if (config.type === "change") {
1742
+ var _this__renderManagerService_getRenderById_mainComponent, _this__renderManagerService_getRenderById;
1743
+ _this._previewPattern = config.value;
1744
+ _this._sheetSkeletonManagerService.reCalculate();
1745
+ (_this__renderManagerService_getRenderById = _this._renderManagerService.getRenderById(workbook.getUnitId())) === null || _this__renderManagerService_getRenderById === void 0 ? void 0 : (_this__renderManagerService_getRenderById_mainComponent = _this__renderManagerService_getRenderById.mainComponent) === null || _this__renderManagerService_getRenderById_mainComponent === void 0 ? void 0 : _this__renderManagerService_getRenderById_mainComponent.makeDirty();
1746
+ } else if (config.type === "confirm") {
1747
+ var selections2 = selectionManagerService.getSelectionRanges() || [];
1748
+ var params = {
1749
+ values: []
1750
+ };
1751
+ var patternType = getPatternType(config.value);
1752
+ selections2.forEach(function(rangeInfo) {
1753
+ Range4.foreach(rangeInfo, function(row, col) {
1754
+ params.values.push({
1755
+ row: row,
1756
+ col: col,
1757
+ pattern: config.value,
1758
+ type: patternType
1759
+ });
1760
+ });
1761
+ });
1762
+ commandService.executeCommand(SetNumfmtCommand.id, params);
1763
+ sidebarService.close();
1764
+ } else if (config.type === "cancel") {
1765
+ sidebarService.close();
1766
+ }
1767
+ },
1768
+ value: {
1769
+ defaultPattern: pattern,
1770
+ defaultValue: defaultValue,
1771
+ row: range.startRow,
1772
+ col: range.startColumn
1773
+ }
1774
+ };
1775
+ sidebarService.open({
1776
+ header: {
1777
+ title: localeService.t("sheet.numfmt.title")
1778
+ },
1779
+ children: _object_spread({
1780
+ label: SHEET_NUMFMT_PLUGIN
1781
+ }, props),
1782
+ onClose: function() {
1783
+ commandService.executeCommand(CloseNumfmtPanelOperator.id);
1784
+ }
1785
+ });
1786
+ });
1787
+ _define_property(_assert_this_initialized(_this), "_initLocal", function() {
1788
+ var _obj;
1789
+ _this._localeService.load((_obj = {}, _define_property(_obj, LocaleType.ZH_CN, zhCn), _define_property(_obj, LocaleType.EN_US, zhCn), _obj));
1790
+ });
1791
+ _this._sheetInterceptorService = _sheetInterceptorService;
1792
+ _this._themeService = _themeService;
1793
+ _this._injector = _injector;
1794
+ _this._univerInstanceService = _univerInstanceService;
1795
+ _this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
1796
+ _this._commandService = _commandService;
1797
+ _this._selectionManagerService = _selectionManagerService;
1798
+ _this._renderManagerService = _renderManagerService;
1799
+ _this._numfmtService = _numfmtService;
1800
+ _this._componentManager = _componentManager;
1801
+ _this._menuService = _menuService;
1802
+ _this._sidebarService = _sidebarService;
1803
+ _this._localeService = _localeService;
1804
+ _this._autoFillService = _autoFillService;
1805
+ _this._initInterceptorCommands();
1806
+ _this._initRealTimeRenderingInterceptor();
1807
+ _this._initPanel();
1808
+ _this._initCommands();
1809
+ _this._commandExecutedListener();
1810
+ _this._initMenu();
1811
+ _this._initInterceptorCellContent();
1812
+ _this._initLocal();
1813
+ _this._initAutoFill();
1814
+ return _this;
1815
+ }
1816
+ _create_class(NumfmtController, [
1817
+ {
1818
+ key: "_initAutoFill",
1819
+ value: function _initAutoFill() {
1820
+ var _this = this;
1821
+ var noopReturnFunc = function() {
1822
+ return {
1823
+ redos: [],
1824
+ undos: []
1825
+ };
1826
+ };
1827
+ var loopFunc = function(sourceStartCell, targetStartCell, relativeRange) {
1828
+ var workbookId = _this._univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
1829
+ var worksheetId = _this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
1830
+ var sourceRange = {
1831
+ startRow: sourceStartCell.row,
1832
+ startColumn: sourceStartCell.col,
1833
+ endColumn: sourceStartCell.col,
1834
+ endRow: sourceStartCell.row
1835
+ };
1836
+ var targetRange = {
1837
+ startRow: targetStartCell.row,
1838
+ startColumn: targetStartCell.col,
1839
+ endColumn: targetStartCell.col,
1840
+ endRow: targetStartCell.row
1841
+ };
1842
+ var values = [];
1843
+ Range4.foreach(relativeRange, function(row, col) {
1844
+ var sourcePositionRange = Rectangle.getPositionRange({
1845
+ startRow: row,
1846
+ startColumn: col,
1847
+ endColumn: col,
1848
+ endRow: row
1849
+ }, sourceRange);
1850
+ var oldNumfmtValue = _this._numfmtService.getValue(workbookId, worksheetId, sourcePositionRange.startRow, sourcePositionRange.startColumn);
1851
+ if (oldNumfmtValue) {
1852
+ var targetPositionRange = Rectangle.getPositionRange({
1853
+ startRow: row,
1854
+ startColumn: col,
1855
+ endColumn: col,
1856
+ endRow: row
1857
+ }, targetRange);
1858
+ values.push({
1859
+ pattern: oldNumfmtValue.pattern,
1860
+ type: oldNumfmtValue.type,
1861
+ row: targetPositionRange.startRow,
1862
+ col: targetPositionRange.startColumn
1863
+ });
1864
+ }
1865
+ });
1866
+ if (values.length) {
1867
+ var redo = {
1868
+ id: SetNumfmtMutation2.id,
1869
+ params: {
1870
+ values: values,
1871
+ workbookId: workbookId,
1872
+ worksheetId: worksheetId
1873
+ }
1874
+ };
1875
+ var undo = {
1876
+ id: SetNumfmtMutation2.id,
1877
+ params: {
1878
+ values: factorySetNumfmtUndoMutation2(_this._injector, redo.params),
1879
+ workbookId: workbookId,
1880
+ worksheetId: worksheetId
1881
+ }
1882
+ };
1883
+ return {
1884
+ redos: [
1885
+ redo
1886
+ ],
1887
+ undos: [
1888
+ undo
1889
+ ]
1890
+ };
1891
+ }
1892
+ return {
1893
+ redos: [],
1894
+ undos: []
1895
+ };
1896
+ };
1897
+ var generalApplyFunc = function(sourceRange, targetRange) {
1898
+ var totalUndos = [];
1899
+ var totalRedos = [];
1900
+ var sourceStartCell = {
1901
+ row: sourceRange.startRow,
1902
+ col: sourceRange.startColumn
1903
+ };
1904
+ var repeats = getRepeatRange(sourceRange, targetRange);
1905
+ repeats.forEach(function(repeat) {
1906
+ var _totalUndos, _totalRedos;
1907
+ var _loopFunc = loopFunc(sourceStartCell, repeat.repeatStartCell, repeat.relativeRange), undos = _loopFunc.undos, redos = _loopFunc.redos;
1908
+ (_totalUndos = totalUndos).push.apply(_totalUndos, _to_consumable_array(undos));
1909
+ (_totalRedos = totalRedos).push.apply(_totalRedos, _to_consumable_array(redos));
1910
+ });
1911
+ return {
1912
+ undos: totalUndos,
1913
+ redos: totalRedos
1914
+ };
1915
+ };
1916
+ var _obj;
1917
+ var hook = {
1918
+ hookName: SHEET_NUMFMT_PLUGIN,
1919
+ hook: (_obj = {}, _define_property(_obj, APPLY_TYPE.COPY, generalApplyFunc), _define_property(_obj, APPLY_TYPE.NO_FORMAT, noopReturnFunc), _define_property(_obj, APPLY_TYPE.ONLY_FORMAT, generalApplyFunc), _define_property(_obj, APPLY_TYPE.SERIES, generalApplyFunc), _obj)
1920
+ };
1921
+ this.disposeWithMe(this._autoFillService.addHook(hook));
1922
+ }
1923
+ },
1924
+ {
1925
+ key: "_initCommands",
1926
+ value: function _initCommands() {
1927
+ var _this = this;
1928
+ [
1929
+ AddDecimalCommand,
1930
+ SubtractDecimalCommand,
1931
+ SetCurrencyCommand,
1932
+ OpenNumfmtPanelOperator,
1933
+ CloseNumfmtPanelOperator,
1934
+ SetNumfmtCommand
1935
+ ].forEach(function(config) {
1936
+ _this.disposeWithMe(_this._commandService.registerCommand(config));
1937
+ });
1938
+ }
1939
+ },
1940
+ {
1941
+ key: "_initPanel",
1942
+ value: function _initPanel() {
1943
+ this._componentManager.register(SHEET_NUMFMT_PLUGIN, SheetNumfmtPanel);
1944
+ }
1945
+ },
1946
+ {
1947
+ key: "_initMenu",
1948
+ value: function _initMenu() {
1949
+ var _this = this;
1950
+ [
1951
+ AddDecimalMenuItem,
1952
+ SubtractDecimalMenuItem,
1953
+ CurrencyMenuItem,
1954
+ FactoryOtherMenuItem
1955
+ ].map(function(factory) {
1956
+ return factory(_this._componentManager);
1957
+ }).forEach(function(configFactory) {
1958
+ _this.disposeWithMe(_this._menuService.addMenuItem(configFactory(_this._injector)));
1959
+ });
1960
+ }
1961
+ },
1962
+ {
1963
+ key: "_initInterceptorCommands",
1964
+ value: function _initInterceptorCommands() {
1965
+ var self = this;
1966
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
1967
+ getMutations: function getMutations(command) {
1968
+ switch(command.id){
1969
+ case ClearSelectionAllCommand.id:
1970
+ case ClearSelectionFormatCommand.id:
1971
+ {
1972
+ var workbookId = self._univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
1973
+ var worksheetId = self._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
1974
+ var selections = self._selectionManagerService.getSelectionRanges();
1975
+ if (!(selections === null || selections === void 0 ? void 0 : selections.length)) {
1976
+ break;
1977
+ }
1978
+ var redos = {
1979
+ workbookId: workbookId,
1980
+ worksheetId: worksheetId,
1981
+ values: []
1982
+ };
1983
+ selections.forEach(function(range) {
1984
+ Range4.foreach(range, function(row, col) {
1985
+ redos.values.push({
1986
+ row: row,
1987
+ col: col
1988
+ });
1989
+ });
1990
+ });
1991
+ var undos = factorySetNumfmtUndoMutation2(self._injector, redos);
1992
+ return {
1993
+ redos: [
1994
+ {
1995
+ id: SetNumfmtMutation2.id,
1996
+ params: redos
1997
+ }
1998
+ ],
1999
+ undos: [
2000
+ {
2001
+ id: SetNumfmtMutation2.id,
2002
+ params: undos
2003
+ }
2004
+ ]
2005
+ };
2006
+ }
2007
+ }
2008
+ return {
2009
+ redos: [],
2010
+ undos: []
2011
+ };
2012
+ }
2013
+ }));
2014
+ }
2015
+ },
2016
+ {
2017
+ key: "_initInterceptorCellContent",
2018
+ value: function _initInterceptorCellContent() {
2019
+ var _this = this;
2020
+ var renderCache = new ObjectMatrix();
2021
+ this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
2022
+ handler: function(cell, location, next) {
2023
+ var workbookId = location.workbookId;
2024
+ var sheetId = location.worksheetId;
2025
+ var numfmtValue = _this._numfmtService.getValue(workbookId, sheetId, location.row, location.col);
2026
+ if (!numfmtValue) {
2027
+ return next(cell);
2028
+ }
2029
+ var originCellValue = cell;
2030
+ if (!originCellValue) {
2031
+ return next(cell);
2032
+ }
2033
+ if (originCellValue.t !== CellValueType.NUMBER) {
2034
+ return next(cell);
2035
+ }
2036
+ var numfmtRes = "";
2037
+ var cache = renderCache.getValue(location.row, location.col);
2038
+ if (cache && cache.parameters === originCellValue.v) {
2039
+ return _object_spread({}, cell, cache.result);
2040
+ }
2041
+ var info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v));
2042
+ numfmtRes = info.result;
2043
+ if (!numfmtRes) {
2044
+ return next(cell);
2045
+ }
2046
+ var res = {
2047
+ v: numfmtRes
2048
+ };
2049
+ if (info.color) {
2050
+ var color = _this._themeService.getCurrentTheme()["".concat(info.color, "500")];
2051
+ if (color) {
2052
+ res.s = {
2053
+ cl: {
2054
+ rgb: color
2055
+ }
2056
+ };
2057
+ }
2058
+ }
2059
+ renderCache.setValue(location.row, location.col, {
2060
+ result: res,
2061
+ parameters: originCellValue.v
2062
+ });
2063
+ return _object_spread({}, cell, res);
2064
+ }
2065
+ }));
2066
+ this.disposeWithMe(this._commandService.onCommandExecuted(function(commandInfo) {
2067
+ if (commandInfo.id === SetNumfmtMutation2.id) {
2068
+ var params = commandInfo.params;
2069
+ params.values.map(function(value) {
2070
+ return {
2071
+ row: value.row,
2072
+ col: value.col
2073
+ };
2074
+ }).forEach(function(param) {
2075
+ var row = param.row, col = param.col;
2076
+ renderCache.realDeleteValue(row, col);
2077
+ });
2078
+ }
2079
+ }));
2080
+ this.disposeWithMe(toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.pipe(map(function(skeleton) {
2081
+ return skeleton === null || skeleton === void 0 ? void 0 : skeleton.sheetId;
2082
+ }), distinctUntilChanged()).subscribe(function() {
2083
+ renderCache.reset();
2084
+ })));
2085
+ }
2086
+ },
2087
+ {
2088
+ key: "_initRealTimeRenderingInterceptor",
2089
+ value: function _initRealTimeRenderingInterceptor() {
2090
+ var _this = this;
2091
+ var isPanelOpenObserver = new Observable2(function(subscribe) {
2092
+ _this._commandService.onCommandExecuted(function(commandInfo) {
2093
+ if (commandInfo.id === OpenNumfmtPanelOperator.id) {
2094
+ subscribe.next(true);
2095
+ }
2096
+ if (commandInfo.id === CloseNumfmtPanelOperator.id) {
2097
+ subscribe.next(false);
2098
+ }
2099
+ });
2100
+ });
2101
+ var combineOpenAndSelection$ = combineLatest([
2102
+ isPanelOpenObserver,
2103
+ this._selectionManagerService.selectionInfo$.pipe(map(function(selectionInfos) {
2104
+ if (!selectionInfos) {
2105
+ return [];
2106
+ }
2107
+ return selectionInfos.map(function(selectionInfo) {
2108
+ return selectionInfo.range;
2109
+ });
2110
+ }))
2111
+ ]);
2112
+ this.disposeWithMe(toDisposable(combineOpenAndSelection$.pipe(switchMap(function(param) {
2113
+ var _param = _sliced_to_array(param, 2), isOpen = _param[0], selectionRanges = _param[1];
2114
+ return new Observable2(function(subscribe) {
2115
+ var disposableCollection = new DisposableCollection();
2116
+ isOpen && selectionRanges.length && subscribe.next({
2117
+ selectionRanges: selectionRanges,
2118
+ disposableCollection: disposableCollection
2119
+ });
2120
+ return function() {
2121
+ disposableCollection.dispose();
2122
+ };
2123
+ });
2124
+ }), tap(function() {
2125
+ _this._previewPattern = null;
2126
+ })).subscribe(function(param) {
2127
+ var disposableCollection = param.disposableCollection, selectionRanges = param.selectionRanges;
2128
+ var _this__renderManagerService_getRenderById_mainComponent, _this__renderManagerService_getRenderById;
2129
+ var workbook = _this._univerInstanceService.getCurrentUniverSheetInstance();
2130
+ _this.openPanel();
2131
+ disposableCollection.add(_this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
2132
+ priority: 99,
2133
+ handler: function(cell, location, next) {
2134
+ var row = location.row, col = location.col;
2135
+ if (selectionRanges.find(function(range) {
2136
+ return range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row;
2137
+ })) {
2138
+ var rawValue = location.worksheet.getCellRaw(row, col);
2139
+ var value = rawValue === null || rawValue === void 0 ? void 0 : rawValue.v;
2140
+ var type = rawValue === null || rawValue === void 0 ? void 0 : rawValue.t;
2141
+ if (value === void 0 || value === null || type !== CellValueType.NUMBER || _this._previewPattern === null) {
2142
+ return next(cell);
2143
+ }
2144
+ var info = getPatternPreview(_this._previewPattern, value);
2145
+ if (info.color) {
2146
+ var colorMap = _this._themeService.getCurrentTheme();
2147
+ var color = colorMap["".concat(info.color, "500")];
2148
+ return _object_spread_props(_object_spread({}, cell), {
2149
+ v: info.result,
2150
+ t: CellValueType.STRING,
2151
+ s: {
2152
+ cl: {
2153
+ rgb: color
2154
+ }
2155
+ }
2156
+ });
2157
+ }
2158
+ return _object_spread_props(_object_spread({}, cell), {
2159
+ v: info.result,
2160
+ t: CellValueType.STRING
2161
+ });
2162
+ }
2163
+ return next();
2164
+ }
2165
+ }));
2166
+ (_this__renderManagerService_getRenderById = _this._renderManagerService.getRenderById(workbook.getUnitId())) === null || _this__renderManagerService_getRenderById === void 0 ? void 0 : (_this__renderManagerService_getRenderById_mainComponent = _this__renderManagerService_getRenderById.mainComponent) === null || _this__renderManagerService_getRenderById_mainComponent === void 0 ? void 0 : _this__renderManagerService_getRenderById_mainComponent.makeDirty();
2167
+ })));
2168
+ }
2169
+ },
2170
+ {
2171
+ key: "_commandExecutedListener",
2172
+ value: function _commandExecutedListener() {
2173
+ var _this = this;
2174
+ this.disposeWithMe(toDisposable(merge(new Observable2(function(subscribe) {
2175
+ var disposable = _this._commandService.onCommandExecuted(function(command) {
2176
+ if (SetNumfmtMutation2.id === command.id) {
2177
+ var params = command.params;
2178
+ subscribe.next(params.workbookId);
2179
+ }
2180
+ });
2181
+ return function() {
2182
+ disposable.dispose();
2183
+ };
2184
+ }), this._numfmtService.modelReplace$).pipe(debounceTime(16)).subscribe(function(workbookId) {
2185
+ var _this__renderManagerService_getRenderById_mainComponent, _this__renderManagerService_getRenderById;
2186
+ _this._sheetSkeletonManagerService.reCalculate();
2187
+ (_this__renderManagerService_getRenderById = _this._renderManagerService.getRenderById(workbookId)) === null || _this__renderManagerService_getRenderById === void 0 ? void 0 : (_this__renderManagerService_getRenderById_mainComponent = _this__renderManagerService_getRenderById.mainComponent) === null || _this__renderManagerService_getRenderById_mainComponent === void 0 ? void 0 : _this__renderManagerService_getRenderById_mainComponent.makeDirty();
2188
+ })));
2189
+ }
2190
+ }
2191
+ ]);
2192
+ return NumfmtController;
2193
+ }(Disposable);
2194
+ NumfmtController = __decorateClass([
2195
+ OnLifecycle(LifecycleStages2.Rendered, NumfmtController),
2196
+ __decorateParam(0, Inject2(SheetInterceptorService)),
2197
+ __decorateParam(1, Inject2(ThemeService)),
2198
+ __decorateParam(2, Inject2(Injector)),
2199
+ __decorateParam(3, Inject2(IUniverInstanceService5)),
2200
+ __decorateParam(4, Inject2(SheetSkeletonManagerService)),
2201
+ __decorateParam(5, Inject2(ICommandService5)),
2202
+ __decorateParam(6, Inject2(SelectionManagerService5)),
2203
+ __decorateParam(7, Inject2(IRenderManagerService)),
2204
+ __decorateParam(8, Inject2(INumfmtService4)),
2205
+ __decorateParam(9, Inject2(ComponentManager)),
2206
+ __decorateParam(10, Inject2(IMenuService)),
2207
+ __decorateParam(11, Inject2(ISidebarService)),
2208
+ __decorateParam(12, Inject2(LocaleService6)),
2209
+ __decorateParam(13, Inject2(IAutoFillService))
2210
+ ], NumfmtController);
2211
+ // src/controllers/numfmt.editor.controller.ts
2212
+ import { CellValueType as CellValueType2, Disposable as Disposable2, IUniverInstanceService as IUniverInstanceService6, LifecycleStages as LifecycleStages3, OnLifecycle as OnLifecycle2, toDisposable as toDisposable2 } from "@univerjs/core";
2213
+ import numfmt4 from "@univerjs/engine-numfmt";
2214
+ import { factorySetNumfmtUndoMutation as factorySetNumfmtUndoMutation3, INumfmtService as INumfmtService5, SetNumfmtMutation as SetNumfmtMutation3, SetRangeValuesCommand, SheetInterceptorService as SheetInterceptorService2 } from "@univerjs/sheets";
2215
+ import { IEditorBridgeService } from "@univerjs/sheets-ui";
2216
+ import { Inject as Inject3, Injector as Injector2 } from "@wendellhu/redi";
2217
+ var createCollectEffectMutation = function() {
2218
+ var list = [];
2219
+ var add = function(workbookId, worksheetId, row, col, value) {
2220
+ return list.push({
2221
+ workbookId: workbookId,
2222
+ worksheetId: worksheetId,
2223
+ row: row,
2224
+ col: col,
2225
+ value: value
2226
+ });
2227
+ };
2228
+ var getEffects = function() {
2229
+ return list;
2230
+ };
2231
+ var clean = function() {
2232
+ list = [];
2233
+ };
2234
+ return {
2235
+ add: add,
2236
+ getEffects: getEffects,
2237
+ clean: clean
2238
+ };
2239
+ };
2240
+ var NumfmtEditorController = /*#__PURE__*/ function(Disposable2) {
2241
+ "use strict";
2242
+ _inherits(NumfmtEditorController, Disposable2);
2243
+ var _super = _create_super(NumfmtEditorController);
2244
+ function NumfmtEditorController(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
2245
+ _class_call_check(this, NumfmtEditorController);
2246
+ var _this;
2247
+ _this = _super.call(this);
2248
+ // collect effect mutations when edit end and push this to commands stack in next commands progress
2249
+ _define_property(_assert_this_initialized(_this), "_collectEffectMutation", createCollectEffectMutation());
2250
+ _this._sheetInterceptorService = _sheetInterceptorService;
2251
+ _this._numfmtService = _numfmtService;
2252
+ _this._univerInstanceService = _univerInstanceService;
2253
+ _this._injector = _injector;
2254
+ _this._editorBridgeService = _editorBridgeService;
2255
+ _this._initInterceptorEditorStart();
2256
+ _this._initInterceptorEditorEnd();
2257
+ _this._initInterceptorCommands();
2258
+ return _this;
2259
+ }
2260
+ _create_class(NumfmtEditorController, [
2261
+ {
2262
+ key: "_initInterceptorEditorStart",
2263
+ value: function _initInterceptorEditorStart() {
2264
+ var _this = this;
2265
+ this.disposeWithMe(toDisposable2(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT, {
2266
+ handler: function(value, context, next) {
2267
+ var row = context.row;
2268
+ var col = context.col;
2269
+ var numfmtCell = _this._numfmtService.getValue(context.workbookId, context.worksheetId, row, col);
2270
+ if (numfmtCell) {
2271
+ var type = getPatternType(numfmtCell.pattern);
2272
+ switch(type){
2273
+ case "scientific":
2274
+ case "percent":
2275
+ case "currency":
2276
+ case "grouped":
2277
+ case "number":
2278
+ {
2279
+ var cell = context.worksheet.getCellRaw(row, col);
2280
+ return cell ? filterAtr(cell, [
2281
+ "s"
2282
+ ]) : cell;
2283
+ }
2284
+ case "date":
2285
+ case "time":
2286
+ case "datetime":
2287
+ default:
2288
+ {
2289
+ return next && next(value);
2290
+ }
2291
+ }
2292
+ }
2293
+ return next(value);
2294
+ }
2295
+ })));
2296
+ }
2297
+ },
2298
+ {
2299
+ /**
2300
+ * Process the values after edit
2301
+ * @private
2302
+ * @memberof NumfmtService
2303
+ */ key: "_initInterceptorEditorEnd",
2304
+ value: function _initInterceptorEditorEnd() {
2305
+ var _this = this;
2306
+ this.disposeWithMe(toDisposable2(this._editorBridgeService.interceptor.intercept(this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT, {
2307
+ handler: function(value, context, next) {
2308
+ _this._collectEffectMutation.clean();
2309
+ var currentNumfmtValue = _this._numfmtService.getValue(context.workbookId, context.worksheetId, context.row, context.col);
2310
+ var clean = function() {
2311
+ currentNumfmtValue && _this._collectEffectMutation.add(context.workbookId, context.worksheetId, context.row, context.col, null);
2312
+ };
2313
+ if (!(value === null || value === void 0 ? void 0 : value.v)) {
2314
+ clean();
2315
+ return next(value);
2316
+ }
2317
+ var content = String(value.v);
2318
+ var dateInfo = numfmt4.parseDate(content) || numfmt4.parseTime(content);
2319
+ var isTranslateDate = !!dateInfo;
2320
+ if (isTranslateDate) {
2321
+ if (dateInfo && dateInfo.z) {
2322
+ var v = Number(dateInfo.v);
2323
+ _this._collectEffectMutation.add(context.workbookId, context.worksheetId, context.row, context.col, {
2324
+ type: "date",
2325
+ pattern: dateInfo.z
2326
+ });
2327
+ return _object_spread_props(_object_spread({}, value), {
2328
+ v: v,
2329
+ t: CellValueType2.NUMBER
2330
+ });
2331
+ }
2332
+ } else if ([
2333
+ "date",
2334
+ "time",
2335
+ "datetime"
2336
+ ].includes((currentNumfmtValue === null || currentNumfmtValue === void 0 ? void 0 : currentNumfmtValue.type) || "") || !isNumeric(content)) {
2337
+ clean();
2338
+ }
2339
+ return next(value);
2340
+ }
2341
+ })));
2342
+ }
2343
+ },
2344
+ {
2345
+ key: "_initInterceptorCommands",
2346
+ value: function _initInterceptorCommands() {
2347
+ var self = this;
2348
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
2349
+ getMutations: function getMutations(command) {
2350
+ switch(command.id){
2351
+ case SetRangeValuesCommand.id:
2352
+ {
2353
+ var workbookId = self._univerInstanceService.getCurrentUniverSheetInstance().getUnitId();
2354
+ var worksheetId = self._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
2355
+ var list = self._collectEffectMutation.getEffects();
2356
+ if (!list.length) {
2357
+ return {
2358
+ redos: [],
2359
+ undos: []
2360
+ };
2361
+ }
2362
+ var redos = {
2363
+ workbookId: workbookId,
2364
+ worksheetId: worksheetId,
2365
+ values: list.map(function(item) {
2366
+ var _item_value;
2367
+ return {
2368
+ pattern: item.value ? item.value.pattern : "",
2369
+ row: item.row,
2370
+ col: item.col,
2371
+ type: (_item_value = item.value) === null || _item_value === void 0 ? void 0 : _item_value.type
2372
+ };
2373
+ })
2374
+ };
2375
+ var undos = factorySetNumfmtUndoMutation3(self._injector, redos);
2376
+ return {
2377
+ redos: [
2378
+ {
2379
+ id: SetNumfmtMutation3.id,
2380
+ params: redos
2381
+ }
2382
+ ],
2383
+ undos: [
2384
+ {
2385
+ id: SetNumfmtMutation3.id,
2386
+ params: undos
2387
+ }
2388
+ ]
2389
+ };
2390
+ }
2391
+ }
2392
+ return {
2393
+ redos: [],
2394
+ undos: []
2395
+ };
2396
+ }
2397
+ }));
2398
+ }
2399
+ }
2400
+ ]);
2401
+ return NumfmtEditorController;
2402
+ }(Disposable2);
2403
+ NumfmtEditorController = __decorateClass([
2404
+ OnLifecycle2(LifecycleStages3.Rendered, NumfmtEditorController),
2405
+ __decorateParam(0, Inject3(SheetInterceptorService2)),
2406
+ __decorateParam(1, Inject3(INumfmtService5)),
2407
+ __decorateParam(2, Inject3(IUniverInstanceService6)),
2408
+ __decorateParam(3, Inject3(Injector2)),
2409
+ __decorateParam(4, Inject3(IEditorBridgeService))
2410
+ ], NumfmtEditorController);
2411
+ var filterAtr = function(obj, filterKey) {
2412
+ var keys = Object.keys(obj).filter(function(key2) {
2413
+ return !filterKey.includes(key2);
2414
+ });
2415
+ return keys.reduce(function(pre, cur) {
2416
+ pre[cur] = obj[cur];
2417
+ return pre;
2418
+ }, {});
2419
+ };
2420
+ function isNumeric(str) {
2421
+ return /^-?\d+(\.\d+)?$/.test(str);
2422
+ }
2423
+ // src/controllers/numfmt.ref-range.controller.ts
2424
+ import { Disposable as Disposable3, DisposableCollection as DisposableCollection2, ICommandService as ICommandService6, IUniverInstanceService as IUniverInstanceService7, LifecycleStages as LifecycleStages4, OnLifecycle as OnLifecycle3, toDisposable as toDisposable3 } from "@univerjs/core";
2425
+ import { EffectRefRangId, factorySetNumfmtUndoMutation as factorySetNumfmtUndoMutation4, handleDeleteRangeMoveLeft, handleDeleteRangeMoveUp, handleInsertCol, handleInsertRangeMoveDown, handleInsertRangeMoveRight, handleInsertRow, handleIRemoveCol, handleIRemoveRow, handleMoveRange, INumfmtService as INumfmtService6, RefRangeService, runRefRangeMutations, SetNumfmtMutation as SetNumfmtMutation4 } from "@univerjs/sheets";
2426
+ import { SheetSkeletonManagerService as SheetSkeletonManagerService2 } from "@univerjs/sheets-ui";
2427
+ import { Inject as Inject4, Injector as Injector3 } from "@wendellhu/redi";
2428
+ import { merge as merge2, Observable as Observable3 } from "rxjs";
2429
+ import { bufferTime, distinctUntilChanged as distinctUntilChanged2, filter, map as map2, switchMap as switchMap2 } from "rxjs/operators";
2430
+ var NumfmtRefRangeController = /*#__PURE__*/ function(Disposable3) {
2431
+ "use strict";
2432
+ _inherits(NumfmtRefRangeController, Disposable3);
2433
+ var _super = _create_super(NumfmtRefRangeController);
2434
+ function NumfmtRefRangeController(_numfmtService, _univerInstanceService, _injector, _refRangeService, _sheetSkeletonManagerService, _commandService) {
2435
+ _class_call_check(this, NumfmtRefRangeController);
2436
+ var _this;
2437
+ _this = _super.call(this);
2438
+ _this._numfmtService = _numfmtService;
2439
+ _this._univerInstanceService = _univerInstanceService;
2440
+ _this._injector = _injector;
2441
+ _this._refRangeService = _refRangeService;
2442
+ _this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
2443
+ _this._commandService = _commandService;
2444
+ _this._registerRefRange();
2445
+ _this._mergeRefMutations();
2446
+ return _this;
2447
+ }
2448
+ _create_class(NumfmtRefRangeController, [
2449
+ {
2450
+ key: "_mergeRefMutations",
2451
+ value: function _mergeRefMutations() {
2452
+ this.disposeWithMe(this._refRangeService.intercept({
2453
+ handler: function(list, current, next) {
2454
+ if (!list || !list.length || !current.length) {
2455
+ return next(list);
2456
+ }
2457
+ var theLastMutation = list[list.length - 1];
2458
+ var theFirstMutation = current[0];
2459
+ if (theLastMutation.id === SetNumfmtMutation4.id && theFirstMutation.id === SetNumfmtMutation4.id) {
2460
+ var theLastMutationParams = theLastMutation.params;
2461
+ var theFirstMutationParams = theFirstMutation.params;
2462
+ if (theLastMutationParams.workbookId === theFirstMutationParams.workbookId && theLastMutationParams.worksheetId === theFirstMutationParams.worksheetId) {
2463
+ var values = theLastMutationParams.values;
2464
+ current.forEach(function(mutation) {
2465
+ var params = mutation.params;
2466
+ params.values.forEach(function(item) {
2467
+ values.push(item);
2468
+ });
2469
+ });
2470
+ return list;
2471
+ }
2472
+ }
2473
+ return next(list);
2474
+ }
2475
+ }));
2476
+ }
2477
+ },
2478
+ {
2479
+ key: "_registerRefRange",
2480
+ value: function _registerRefRange() {
2481
+ var _this = this;
2482
+ this.disposeWithMe(toDisposable3(merge2(this._sheetSkeletonManagerService.currentSkeleton$.pipe(map2(function(skeleton) {
2483
+ return skeleton === null || skeleton === void 0 ? void 0 : skeleton.sheetId;
2484
+ }), distinctUntilChanged2()), this._numfmtService.modelReplace$).pipe(switchMap2(function() {
2485
+ return new Observable3(function(subscribe) {
2486
+ var disposableCollection = new DisposableCollection2();
2487
+ subscribe.next(disposableCollection);
2488
+ return function() {
2489
+ disposableCollection.dispose();
2490
+ };
2491
+ });
2492
+ })).subscribe(function(disposableCollection) {
2493
+ var workbook = _this._univerInstanceService.getCurrentUniverSheetInstance();
2494
+ var workbookId = workbook.getUnitId();
2495
+ var worksheetId = _this._univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
2496
+ var model = _this._numfmtService.getModel(workbookId, worksheetId);
2497
+ var disposableMap = /* @__PURE__ */ new Map();
2498
+ var register = function(commandInfo, preValues, row, col) {
2499
+ var targetRange = {
2500
+ startRow: row,
2501
+ startColumn: col,
2502
+ endRow: row,
2503
+ endColumn: col
2504
+ };
2505
+ var operators = [];
2506
+ switch(commandInfo.id){
2507
+ case EffectRefRangId.DeleteRangeMoveLeftCommandId:
2508
+ {
2509
+ operators = handleDeleteRangeMoveLeft(commandInfo, targetRange);
2510
+ break;
2511
+ }
2512
+ case EffectRefRangId.DeleteRangeMoveUpCommandId:
2513
+ {
2514
+ operators = handleDeleteRangeMoveUp(commandInfo, targetRange);
2515
+ break;
2516
+ }
2517
+ case EffectRefRangId.InsertColCommandId:
2518
+ {
2519
+ operators = handleInsertCol(commandInfo, targetRange);
2520
+ break;
2521
+ }
2522
+ case EffectRefRangId.InsertRangeMoveDownCommandId:
2523
+ {
2524
+ operators = handleInsertRangeMoveDown(commandInfo, targetRange);
2525
+ break;
2526
+ }
2527
+ case EffectRefRangId.InsertRangeMoveRightCommandId:
2528
+ {
2529
+ operators = handleInsertRangeMoveRight(commandInfo, targetRange);
2530
+ break;
2531
+ }
2532
+ case EffectRefRangId.InsertRowCommandId:
2533
+ {
2534
+ operators = handleInsertRow(commandInfo, targetRange);
2535
+ break;
2536
+ }
2537
+ case EffectRefRangId.MoveRangeCommandId:
2538
+ {
2539
+ operators = handleMoveRange(commandInfo, targetRange);
2540
+ break;
2541
+ }
2542
+ case EffectRefRangId.RemoveColCommandId:
2543
+ {
2544
+ operators = handleIRemoveCol(commandInfo, targetRange);
2545
+ break;
2546
+ }
2547
+ case EffectRefRangId.RemoveRowCommandId:
2548
+ {
2549
+ operators = handleIRemoveRow(commandInfo, targetRange);
2550
+ break;
2551
+ }
2552
+ }
2553
+ var resultRange = runRefRangeMutations(operators, targetRange);
2554
+ var isPreSetNumfmt = preValues.reduce(function(list, item) {
2555
+ var _list;
2556
+ (_list = list).push.apply(_list, _to_consumable_array(item.redos));
2557
+ return list;
2558
+ }, []).filter(function(item) {
2559
+ return item.id === SetNumfmtMutation4.id;
2560
+ }).some(function(mutation) {
2561
+ return mutation.params.values.some(function(item) {
2562
+ return item.row === row && item.col === col && !!item.pattern;
2563
+ });
2564
+ });
2565
+ if (!resultRange && !isPreSetNumfmt) {
2566
+ var redoParams = {
2567
+ workbookId: workbookId,
2568
+ worksheetId: worksheetId,
2569
+ values: [
2570
+ {
2571
+ row: row,
2572
+ col: col
2573
+ }
2574
+ ]
2575
+ };
2576
+ var undoParams = factorySetNumfmtUndoMutation4(_this._injector, redoParams);
2577
+ return {
2578
+ redos: [
2579
+ {
2580
+ id: SetNumfmtMutation4.id,
2581
+ params: redoParams
2582
+ }
2583
+ ],
2584
+ undos: [
2585
+ {
2586
+ id: SetNumfmtMutation4.id,
2587
+ params: undoParams
2588
+ }
2589
+ ]
2590
+ };
2591
+ }
2592
+ var numfmtValue = _this._numfmtService.getValue(workbookId, worksheetId, row, col);
2593
+ if (numfmtValue && resultRange) {
2594
+ var redoParams1 = {
2595
+ workbookId: workbookId,
2596
+ worksheetId: worksheetId,
2597
+ values: [
2598
+ _object_spread_props(_object_spread({}, numfmtValue), {
2599
+ row: resultRange.startRow,
2600
+ col: resultRange.startColumn
2601
+ })
2602
+ ]
2603
+ };
2604
+ if (!isPreSetNumfmt) {
2605
+ redoParams1.values.unshift({
2606
+ row: row,
2607
+ col: col
2608
+ });
2609
+ }
2610
+ var undoParams1 = factorySetNumfmtUndoMutation4(_this._injector, redoParams1);
2611
+ return {
2612
+ redos: [
2613
+ {
2614
+ id: SetNumfmtMutation4.id,
2615
+ params: redoParams1
2616
+ }
2617
+ ],
2618
+ undos: [
2619
+ {
2620
+ id: SetNumfmtMutation4.id,
2621
+ params: undoParams1
2622
+ }
2623
+ ]
2624
+ };
2625
+ }
2626
+ return {
2627
+ redos: [],
2628
+ undos: []
2629
+ };
2630
+ };
2631
+ model && model.forValue(function(row, col) {
2632
+ var targetRange = {
2633
+ startRow: row,
2634
+ startColumn: col,
2635
+ endRow: row,
2636
+ endColumn: col
2637
+ };
2638
+ var disposable = _this._refRangeService.registerRefRange(targetRange, function(commandInfo, preValues) {
2639
+ return register(commandInfo, preValues, row, col);
2640
+ });
2641
+ disposableMap.set("".concat(row, "_").concat(col), disposable);
2642
+ disposableCollection.add(disposable);
2643
+ });
2644
+ disposableCollection.add(toDisposable3(new Observable3(function(subscribe) {
2645
+ disposableCollection.add(_this._commandService.onCommandExecuted(function(commandInfo) {
2646
+ if (commandInfo.id === SetNumfmtMutation4.id) {
2647
+ subscribe.next(commandInfo.params);
2648
+ }
2649
+ }));
2650
+ }).pipe(filter(function(commandInfo) {
2651
+ return commandInfo.workbookId === workbookId && commandInfo.worksheetId === worksheetId;
2652
+ }), map2(function(commandInfo) {
2653
+ return commandInfo.values;
2654
+ }), bufferTime(300), // updating the listener moves to the next queue
2655
+ map2(function(values) {
2656
+ return values.reduce(function(pre, cur) {
2657
+ var _pre;
2658
+ (_pre = pre).push.apply(_pre, _to_consumable_array(cur));
2659
+ return pre;
2660
+ }, []);
2661
+ }), filter(function(values) {
2662
+ return !!values.length;
2663
+ })).subscribe(function(values) {
2664
+ values.forEach(function(value) {
2665
+ var row = value.row, col = value.col;
2666
+ var key2 = "".concat(row, "_").concat(col);
2667
+ var disposable = disposableMap.get(key2);
2668
+ disposableMap.delete(key2);
2669
+ disposable && disposable.dispose();
2670
+ if (value.pattern) {
2671
+ var targetRange = {
2672
+ startRow: row,
2673
+ startColumn: col,
2674
+ endRow: row,
2675
+ endColumn: col
2676
+ };
2677
+ var disposable2 = _this._refRangeService.registerRefRange(targetRange, function(commandInfo, preValues) {
2678
+ return register(commandInfo, preValues, row, col);
2679
+ });
2680
+ disposableMap.set(key2, disposable2);
2681
+ disposableCollection.add(disposable2);
2682
+ }
2683
+ });
2684
+ })));
2685
+ })));
2686
+ }
2687
+ }
2688
+ ]);
2689
+ return NumfmtRefRangeController;
2690
+ }(Disposable3);
2691
+ NumfmtRefRangeController = __decorateClass([
2692
+ OnLifecycle3(LifecycleStages4.Rendered, NumfmtRefRangeController),
2693
+ __decorateParam(0, Inject4(INumfmtService6)),
2694
+ __decorateParam(1, Inject4(IUniverInstanceService7)),
2695
+ __decorateParam(2, Inject4(Injector3)),
2696
+ __decorateParam(3, Inject4(RefRangeService)),
2697
+ __decorateParam(4, Inject4(SheetSkeletonManagerService2)),
2698
+ __decorateParam(5, Inject4(ICommandService6))
2699
+ ], NumfmtRefRangeController);
2700
+ // src/controllers/numfmt.sheet.controller.ts
2701
+ import { Disposable as Disposable4, IUniverInstanceService as IUniverInstanceService8, LifecycleStages as LifecycleStages5, OnLifecycle as OnLifecycle4 } from "@univerjs/core";
2702
+ import { factorySetNumfmtUndoMutation as factorySetNumfmtUndoMutation5, INumfmtService as INumfmtService7, RemoveSheetCommand, SetNumfmtMutation as SetNumfmtMutation5, SheetInterceptorService as SheetInterceptorService3 } from "@univerjs/sheets";
2703
+ import { Inject as Inject5, Injector as Injector4 } from "@wendellhu/redi";
2704
+ var NumfmtSheetController = /*#__PURE__*/ function(Disposable4) {
2705
+ "use strict";
2706
+ _inherits(NumfmtSheetController, Disposable4);
2707
+ var _super = _create_super(NumfmtSheetController);
2708
+ function NumfmtSheetController(_numfmtService, _sheetInterceptorService, _univerInstanceService, _injector) {
2709
+ _class_call_check(this, NumfmtSheetController);
2710
+ var _this;
2711
+ _this = _super.call(this);
2712
+ _this._numfmtService = _numfmtService;
2713
+ _this._sheetInterceptorService = _sheetInterceptorService;
2714
+ _this._univerInstanceService = _univerInstanceService;
2715
+ _this._injector = _injector;
2716
+ _this._initSheetChange();
2717
+ return _this;
2718
+ }
2719
+ _create_class(NumfmtSheetController, [
2720
+ {
2721
+ key: "_initSheetChange",
2722
+ value: function _initSheetChange() {
2723
+ var _this = this;
2724
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
2725
+ getMutations: function(commandInfo) {
2726
+ if (commandInfo.id === RemoveSheetCommand.id) {
2727
+ var params = commandInfo.params;
2728
+ var workbookId = params.workbookId || getWorkbookId(_this._univerInstanceService);
2729
+ var worksheetId = params.worksheetId || getWorksheetId(_this._univerInstanceService);
2730
+ var model = _this._numfmtService.getModel(workbookId, worksheetId);
2731
+ if (!model) {
2732
+ return {
2733
+ redos: [],
2734
+ undos: []
2735
+ };
2736
+ }
2737
+ var values = [];
2738
+ model.forValue(function(row, col) {
2739
+ values.push({
2740
+ row: row,
2741
+ col: col
2742
+ });
2743
+ });
2744
+ var redoParams = {
2745
+ workbookId: workbookId,
2746
+ worksheetId: worksheetId,
2747
+ values: values
2748
+ };
2749
+ var undoParams = factorySetNumfmtUndoMutation5(_this._injector, redoParams);
2750
+ return {
2751
+ redos: [
2752
+ {
2753
+ id: SetNumfmtMutation5.id,
2754
+ params: redoParams
2755
+ }
2756
+ ],
2757
+ undos: [
2758
+ {
2759
+ id: SetNumfmtMutation5.id,
2760
+ params: undoParams
2761
+ }
2762
+ ]
2763
+ };
2764
+ }
2765
+ return {
2766
+ redos: [],
2767
+ undos: []
2768
+ };
2769
+ }
2770
+ }));
2771
+ }
2772
+ }
2773
+ ]);
2774
+ return NumfmtSheetController;
2775
+ }(Disposable4);
2776
+ NumfmtSheetController = __decorateClass([
2777
+ OnLifecycle4(LifecycleStages5.Rendered, NumfmtSheetController),
2778
+ __decorateParam(0, Inject5(INumfmtService7)),
2779
+ __decorateParam(1, Inject5(SheetInterceptorService3)),
2780
+ __decorateParam(2, Inject5(IUniverInstanceService8)),
2781
+ __decorateParam(3, Inject5(Injector4))
2782
+ ], NumfmtSheetController);
2783
+ var getWorkbookId = function(u) {
2784
+ return u.getCurrentUniverSheetInstance().getUnitId();
2785
+ };
2786
+ var getWorksheetId = function(u) {
2787
+ return u.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();
2788
+ };
2789
+ // src/numfmt-plugin.ts
2790
+ var NumfmtPlugin = (_class = /*#__PURE__*/ function(Plugin) {
2791
+ "use strict";
2792
+ _inherits(_class, Plugin);
2793
+ var _super = _create_super(_class);
2794
+ function _class(_injector) {
2795
+ _class_call_check(this, _class);
2796
+ var _this;
2797
+ _this = _super.call(this, SHEET_NUMFMT_PLUGIN);
2798
+ _this._injector = _injector;
2799
+ return _this;
2800
+ }
2801
+ _create_class(_class, [
2802
+ {
2803
+ key: "onStarting",
2804
+ value: function onStarting() {
2805
+ this._injector.add([
2806
+ INumfmtController,
2807
+ {
2808
+ useClass: NumfmtController,
2809
+ lazy: false
2810
+ }
2811
+ ]);
2812
+ this._injector.add([
2813
+ NumfmtEditorController
2814
+ ]);
2815
+ this._injector.add([
2816
+ UserHabitController
2817
+ ]);
2818
+ this._injector.add([
2819
+ NumfmtRefRangeController
2820
+ ]);
2821
+ this._injector.add([
2822
+ NumfmtSheetController
2823
+ ]);
2824
+ }
2825
+ }
2826
+ ]);
2827
+ return _class;
2828
+ }(_wrap_native_super(Plugin)), _define_property(_class, "type", PluginType.Sheet), _class);
2829
+ NumfmtPlugin = __decorateClass([
2830
+ __decorateParam(0, Inject6(Injector5))
2831
+ ], NumfmtPlugin);
2832
+ export { NumfmtPlugin };