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