@univerjs/sheets-numfmt-ui 0.4.0-nightly.202410290723
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/README.md +58 -0
- package/lib/cjs/index.js +9 -0
- package/lib/es/index.js +1008 -0
- package/lib/index.css +1 -0
- package/lib/locale/en-US.json +38 -0
- package/lib/locale/fa-IR.json +38 -0
- package/lib/locale/ru-RU.json +38 -0
- package/lib/locale/vi-VN.json +38 -0
- package/lib/locale/zh-CN.json +38 -0
- package/lib/locale/zh-TW.json +38 -0
- package/lib/types/controllers/__tests__/cell-content.controller.spec.d.ts +16 -0
- package/lib/types/controllers/__tests__/editor.controller.spec.d.ts +16 -0
- package/lib/types/controllers/__tests__/test.util.d.ts +15 -0
- package/lib/types/controllers/config.schema.d.ts +7 -0
- package/lib/types/controllers/menu.d.ts +44 -0
- package/lib/types/controllers/menu.schema.d.ts +2 -0
- package/lib/types/controllers/numfmt.controller.d.ts +32 -0
- package/lib/types/controllers/numfmt.editor.controller.d.ts +20 -0
- package/lib/types/controllers/numfmt.menu.controller.d.ts +8 -0
- package/lib/types/controllers/user-habit.controller.d.ts +19 -0
- package/lib/types/index.d.ts +16 -0
- package/lib/types/locale/en-US.d.ts +3 -0
- package/lib/types/locale/fa-IR.d.ts +3 -0
- package/lib/types/locale/ru-RU.d.ts +3 -0
- package/lib/types/locale/vi-VN.d.ts +3 -0
- package/lib/types/locale/zh-CN.d.ts +54 -0
- package/lib/types/locale/zh-TW.d.ts +3 -0
- package/lib/types/plugin.d.ts +13 -0
- package/lib/types/views/components/accounting/index.d.ts +4 -0
- package/lib/types/views/components/currency/index.d.ts +4 -0
- package/lib/types/views/components/custom-format/index.d.ts +3 -0
- package/lib/types/views/components/date/index.d.ts +4 -0
- package/lib/types/views/components/general/index.d.ts +4 -0
- package/lib/types/views/components/index.d.ts +14 -0
- package/lib/types/views/components/interface.d.ts +7 -0
- package/lib/types/views/components/more-numfmt-type/MoreNumfmtType.d.ts +7 -0
- package/lib/types/views/components/stories/Panel.stories.d.ts +5 -0
- package/lib/types/views/components/thousandth-percentile/index.d.ts +4 -0
- package/lib/types/views/hooks/useCurrencyOptions.d.ts +19 -0
- package/lib/types/views/hooks/useNextTick.d.ts +16 -0
- package/lib/umd/index.js +9 -0
- package/package.json +96 -0
package/lib/es/index.js
ADDED
|
@@ -0,0 +1,1008 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key2, value) => __defNormalProp(obj, typeof key2 != "symbol" ? key2 + "" : key2, value);
|
|
5
|
+
import { Inject, ILocalStorageService, useDependency, LocaleService, numfmt, ThemeService, IUniverInstanceService, ICommandService, Disposable, UniverInstanceType, CellValueType, Range, toDisposable, DisposableCollection, InterceptorEffectEnum, Injector, Optional, useInjector, DependentOn, Plugin, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { currencySymbols, getDecimalFromPattern, getCurrencyType, setPatternDecimal, getCurrencyFormatOptions, isPatternEqualWithoutDecimal, CURRENCYFORMAT, DATEFMTLISG, NUMBERFORMAT, getDateFormatOptions, getNumberFormatOptions, isPatternHasDecimal, getPatternType, SetNumfmtCommand, CloseNumfmtPanelOperator, OpenNumfmtPanelOperator, getPatternPreviewIgnoreGeneral, MenuCurrencyService, countryCurrencyMap, SetCurrencyCommand, AddDecimalCommand, SubtractDecimalCommand, SetPercentCommand, getPatternPreview, UniverSheetsNumfmtPlugin } from "@univerjs/sheets-numfmt";
|
|
7
|
+
import { SheetSkeletonManagerService, IEditorBridgeService, getCurrentRangeDisable$, deriveStateFromActiveSheet$, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
|
|
8
|
+
import { ComponentManager, ISidebarService, MenuItemType, getMenuHiddenObservable, ILayoutService, RibbonStartGroup, IMenuManagerService, PLUGIN_CONFIG_KEY } from "@univerjs/ui";
|
|
9
|
+
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
10
|
+
import { SheetInterceptorService, SheetsSelectionsService, INumfmtService, INTERCEPTOR_POINT, RemoveNumfmtMutation, SetNumfmtMutation, SetRangeValuesCommand, transformCellsToRange, factorySetNumfmtUndoMutation, factoryRemoveNumfmtUndoMutation, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint } from "@univerjs/sheets";
|
|
11
|
+
import { Observable, combineLatest, merge } from "rxjs";
|
|
12
|
+
import { map, switchMap, tap, debounceTime } from "rxjs/operators";
|
|
13
|
+
import require$$0, { createContext, useState, useEffect, useRef, useContext, useMemo, forwardRef, createElement } from "react";
|
|
14
|
+
import { InputNumber, Select, SelectList, Input, Button } from "@univerjs/design";
|
|
15
|
+
import { DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
|
|
16
|
+
const defaultPluginConfig = {};
|
|
17
|
+
var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
18
|
+
/**
|
|
19
|
+
* @license React
|
|
20
|
+
* react-jsx-runtime.production.min.js
|
|
21
|
+
*
|
|
22
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the MIT license found in the
|
|
25
|
+
* LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/
|
|
27
|
+
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
28
|
+
function q(c, a, g) {
|
|
29
|
+
var b, d = {}, e = null, h = null;
|
|
30
|
+
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
31
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
32
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
33
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
34
|
+
}
|
|
35
|
+
__name(q, "q");
|
|
36
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
37
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
38
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
39
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
40
|
+
var jsxRuntimeExports = jsxRuntime.exports, __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
41
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
42
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
43
|
+
return kind && result && __defProp$4(target, key2, result), result;
|
|
44
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4");
|
|
45
|
+
const UserHabitCurrencyContext = createContext([]);
|
|
46
|
+
var _a;
|
|
47
|
+
let UserHabitController = (_a = class {
|
|
48
|
+
constructor(_localStorageService) {
|
|
49
|
+
this._localStorageService = _localStorageService;
|
|
50
|
+
}
|
|
51
|
+
_getKey(habit) {
|
|
52
|
+
return `userHabitController_${habit}`;
|
|
53
|
+
}
|
|
54
|
+
async addHabit(habit, initValue) {
|
|
55
|
+
const key2 = this._getKey(habit);
|
|
56
|
+
return this._localStorageService.getItem(key2).then((item) => {
|
|
57
|
+
item || this._localStorageService.setItem(key2, initValue);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
markHabit(habit, value) {
|
|
61
|
+
const key2 = this._getKey(habit);
|
|
62
|
+
this._localStorageService.getItem(key2).then((list) => {
|
|
63
|
+
if (list) {
|
|
64
|
+
const index = list.findIndex((item) => item === value);
|
|
65
|
+
index > -1 && list.splice(index, 1), list.unshift(value), this._localStorageService.setItem(key2, list);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async getHabit(habit, sortList) {
|
|
70
|
+
const key2 = this._getKey(habit), result = await this._localStorageService.getItem(key2);
|
|
71
|
+
if (sortList && result) {
|
|
72
|
+
const priority = result.map((item, index, arr) => {
|
|
73
|
+
const length = arr.length;
|
|
74
|
+
return {
|
|
75
|
+
value: item,
|
|
76
|
+
priority: length - index
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
return sortList.sort((a, b) => {
|
|
80
|
+
var _a6, _b;
|
|
81
|
+
const ap = ((_a6 = priority.find((item) => item.value === a)) == null ? void 0 : _a6.priority) || -1;
|
|
82
|
+
return (((_b = priority.find((item) => item.value === b)) == null ? void 0 : _b.priority) || -1) - ap;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return result || [];
|
|
86
|
+
}
|
|
87
|
+
deleteHabit(habit) {
|
|
88
|
+
this._localStorageService.removeItem(habit);
|
|
89
|
+
}
|
|
90
|
+
}, __name(_a, "UserHabitController"), _a);
|
|
91
|
+
UserHabitController = __decorateClass$4([
|
|
92
|
+
__decorateParam$4(0, Inject(ILocalStorageService))
|
|
93
|
+
], UserHabitController);
|
|
94
|
+
const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
|
|
95
|
+
const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
|
|
96
|
+
return useEffect(() => {
|
|
97
|
+
userHabitController.addHabit("numfmtCurrency", []).then(() => {
|
|
98
|
+
userHabitController.getHabit(key$1, [...currencySymbols]).then((list) => {
|
|
99
|
+
optionsSet(list), onOptionChange && onOptionChange(list);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}, []), { userHabitCurrency: options, mark: /* @__PURE__ */ __name((v) => {
|
|
103
|
+
userHabitController.markHabit(key$1, v);
|
|
104
|
+
}, "mark") };
|
|
105
|
+
}, "useCurrencyOptions"), useNextTick = /* @__PURE__ */ __name(() => {
|
|
106
|
+
const effectList = useRef([]), [value, dispatch] = useState({});
|
|
107
|
+
return useEffect(() => {
|
|
108
|
+
effectList.current.forEach((fn) => {
|
|
109
|
+
fn();
|
|
110
|
+
}), effectList.current = [];
|
|
111
|
+
}, [value]), /* @__PURE__ */ __name((fn) => {
|
|
112
|
+
effectList.current.push(fn), dispatch({});
|
|
113
|
+
}, "nextTick");
|
|
114
|
+
}, "useNextTick"), isAccountingPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && pattern.startsWith("_("), "isAccountingPanel"), AccountingPanel = /* @__PURE__ */ __name((props) => {
|
|
115
|
+
const { defaultPattern, action, onChange } = props, [decimal, decimalSet] = useState(() => getDecimalFromPattern(defaultPattern || "", 2)), userHabitCurrency = useContext(UserHabitCurrencyContext), [suffix, suffixSet] = useState(() => getCurrencyType(defaultPattern) || userHabitCurrency[0]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), []), t = useDependency(LocaleService).t;
|
|
116
|
+
action.current = () => setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal);
|
|
117
|
+
const onSelect = /* @__PURE__ */ __name((v) => {
|
|
118
|
+
suffixSet(v), onChange(setPatternDecimal(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
119
|
+
}, "onSelect"), onDecimalChange = /* @__PURE__ */ __name((v) => {
|
|
120
|
+
const decimal2 = v || 0;
|
|
121
|
+
decimalSet(decimal2), onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2 > 0 ? ".0" : ""}_)`, decimal2));
|
|
122
|
+
}, "onDecimalChange");
|
|
123
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
124
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
|
|
125
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
126
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
|
|
127
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
|
|
128
|
+
] }),
|
|
129
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
130
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
|
|
131
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
|
|
132
|
+
] })
|
|
133
|
+
] }),
|
|
134
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.accountingDes") })
|
|
135
|
+
] });
|
|
136
|
+
}, "AccountingPanel"), isCurrencyPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && !pattern.startsWith("_("), "isCurrencyPanel"), CurrencyPanel = /* @__PURE__ */ __name((props) => {
|
|
137
|
+
const t = useDependency(LocaleService).t, userHabitCurrency = useContext(UserHabitCurrencyContext), [suffix, suffixSet] = useState(() => getCurrencyType(props.defaultPattern) || userHabitCurrency[0]), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 2)), [pattern, patternSet] = useState(() => {
|
|
138
|
+
var _a6;
|
|
139
|
+
const negativeOptions2 = getCurrencyFormatOptions(suffix);
|
|
140
|
+
return ((_a6 = negativeOptions2.find((item) => isPatternEqualWithoutDecimal(item.value, props.defaultPattern))) == null ? void 0 : _a6.value) || negativeOptions2[0].value;
|
|
141
|
+
}), negativeOptions = useMemo(() => getCurrencyFormatOptions(suffix), [suffix]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), [userHabitCurrency]);
|
|
142
|
+
props.action.current = () => setPatternDecimal(pattern, decimal);
|
|
143
|
+
const onSelect = /* @__PURE__ */ __name((value) => {
|
|
144
|
+
if (value === void 0)
|
|
145
|
+
return;
|
|
146
|
+
suffixSet(value);
|
|
147
|
+
const pattern2 = getCurrencyFormatOptions(value)[0].value;
|
|
148
|
+
patternSet(pattern2), props.onChange(setPatternDecimal(pattern2, decimal));
|
|
149
|
+
}, "onSelect"), onChange = /* @__PURE__ */ __name((value) => {
|
|
150
|
+
value !== void 0 && (patternSet(value), props.onChange(setPatternDecimal(value, decimal)));
|
|
151
|
+
}, "onChange"), onDecimalChange = /* @__PURE__ */ __name((v) => {
|
|
152
|
+
decimalSet(v || 0), props.onChange(setPatternDecimal(pattern, v || 0));
|
|
153
|
+
}, "onDecimalChange");
|
|
154
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
155
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
|
|
156
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
157
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
|
|
158
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
|
|
159
|
+
] }),
|
|
160
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
161
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
|
|
162
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
|
|
163
|
+
] })
|
|
164
|
+
] }),
|
|
165
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.negType") }),
|
|
166
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange, options: negativeOptions, value: pattern }) }),
|
|
167
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.currencyDes") })
|
|
168
|
+
] });
|
|
169
|
+
}, "CurrencyPanel");
|
|
170
|
+
var __assign = function() {
|
|
171
|
+
return __assign = Object.assign || function(t) {
|
|
172
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
173
|
+
s = arguments[i];
|
|
174
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
|
|
175
|
+
}
|
|
176
|
+
return t;
|
|
177
|
+
}, __assign.apply(this, arguments);
|
|
178
|
+
}, __rest = function(s, e) {
|
|
179
|
+
var t = {};
|
|
180
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
|
|
181
|
+
if (s != null && typeof Object.getOwnPropertySymbols == "function")
|
|
182
|
+
for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
|
|
183
|
+
e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
|
|
184
|
+
return t;
|
|
185
|
+
}, IconBase = forwardRef(function(props, ref) {
|
|
186
|
+
var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
|
|
187
|
+
return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
|
|
188
|
+
});
|
|
189
|
+
function render(node, id, runtimeProps, rootProps, extend) {
|
|
190
|
+
return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
|
|
191
|
+
return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
__name(render, "render");
|
|
195
|
+
function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
|
|
196
|
+
var attrs = __assign({}, node.attrs);
|
|
197
|
+
extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
|
|
198
|
+
var defIds = runtimeProps.defIds;
|
|
199
|
+
return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a6) {
|
|
200
|
+
var key2 = _a6[0], value = _a6[1];
|
|
201
|
+
typeof value == "string" && (attrs[key2] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
|
|
202
|
+
})), attrs;
|
|
203
|
+
}
|
|
204
|
+
__name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
|
|
205
|
+
function replaceRuntimeIdsInDefs(node, runtimeProps) {
|
|
206
|
+
var _a6, defIds = runtimeProps.defIds;
|
|
207
|
+
return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a6 = node.children) === null || _a6 === void 0) && _a6.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
|
|
208
|
+
return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
|
|
209
|
+
}) }) : node;
|
|
210
|
+
}
|
|
211
|
+
__name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
|
|
212
|
+
function generateShortUuid() {
|
|
213
|
+
return Math.random().toString(36).substring(2, 8);
|
|
214
|
+
}
|
|
215
|
+
__name(generateShortUuid, "generateShortUuid");
|
|
216
|
+
IconBase.displayName = "UniverIcon";
|
|
217
|
+
var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, CheckMarkSingle = forwardRef(function(props, ref) {
|
|
218
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
219
|
+
id: "check-mark-single",
|
|
220
|
+
ref,
|
|
221
|
+
icon: element
|
|
222
|
+
}));
|
|
223
|
+
});
|
|
224
|
+
CheckMarkSingle.displayName = "CheckMarkSingle";
|
|
225
|
+
const customFormatTitle = "univer-custom-format-title", customFormatInput = "univer-custom-format-input", customFormatHistoryList = "univer-custom-format-history-list", customFormatHistoryListItem = "univer-custom-format-history-list-item", customFormatHistoryListItemIconWrap = "univer-custom-format-history-list-item-icon-wrap", customFormatDes = "univer-custom-format-des", styles = {
|
|
226
|
+
customFormatTitle,
|
|
227
|
+
customFormatInput,
|
|
228
|
+
customFormatHistoryList,
|
|
229
|
+
customFormatHistoryListItem,
|
|
230
|
+
customFormatHistoryListItemIconWrap,
|
|
231
|
+
customFormatDes
|
|
232
|
+
}, key = "customFormat", historyPatternKey = "numfmt_custom_pattern";
|
|
233
|
+
function CustomFormat(props) {
|
|
234
|
+
const { defaultPattern, action, onChange } = props, userHabitController = useDependency(UserHabitController), localStorageService = useDependency(ILocalStorageService), localeService = useDependency(LocaleService), [pattern, patternSet] = useState(defaultPattern);
|
|
235
|
+
action.current = () => (userHabitController.markHabit(key, pattern), localStorageService.getItem(historyPatternKey).then((list = []) => {
|
|
236
|
+
const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
|
|
237
|
+
localStorageService.setItem(historyPatternKey, _list);
|
|
238
|
+
}), pattern);
|
|
239
|
+
const [options, optionsSet] = useState([]);
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
localStorageService.getItem(historyPatternKey).then((historyList) => {
|
|
242
|
+
const list = [
|
|
243
|
+
...CURRENCYFORMAT.map((item) => item.suffix("$")),
|
|
244
|
+
...DATEFMTLISG.map((item) => item.suffix),
|
|
245
|
+
...NUMBERFORMAT.map((item) => item.suffix)
|
|
246
|
+
];
|
|
247
|
+
list.push(...historyList || []), userHabitController.addHabit(key, []).finally(() => {
|
|
248
|
+
userHabitController.getHabit(key, list).then((list2) => {
|
|
249
|
+
optionsSet([...new Set(list2)]);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}, []);
|
|
254
|
+
const handleClick = /* @__PURE__ */ __name((p2) => {
|
|
255
|
+
patternSet(p2), onChange(p2);
|
|
256
|
+
}, "handleClick"), handleBlur = /* @__PURE__ */ __name(() => {
|
|
257
|
+
onChange(pattern);
|
|
258
|
+
}, "handleBlur");
|
|
259
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.customFormat, children: [
|
|
260
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatTitle, children: localeService.t("sheet.numfmt.customFormat") }),
|
|
261
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: localeService.t("sheet.numfmt.customFormat"), onBlur: handleBlur, value: pattern, onChange: patternSet, className: styles.customFormatInput }),
|
|
262
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatHistoryList, children: options.map((p2) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { onClick: /* @__PURE__ */ __name(() => handleClick(p2), "onClick"), className: styles.customFormatHistoryListItem, children: [
|
|
263
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatHistoryListItemIconWrap, children: pattern === p2 && /* @__PURE__ */ jsxRuntimeExports.jsx(CheckMarkSingle, {}) }),
|
|
264
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: p2 })
|
|
265
|
+
] }, p2)) }),
|
|
266
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatDes, children: localeService.t("sheet.numfmt.customFormatDes") })
|
|
267
|
+
] });
|
|
268
|
+
}
|
|
269
|
+
__name(CustomFormat, "CustomFormat");
|
|
270
|
+
const isDatePanel = /* @__PURE__ */ __name((pattern) => {
|
|
271
|
+
const info = numfmt.getInfo(pattern);
|
|
272
|
+
return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
|
|
273
|
+
}, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
|
|
274
|
+
const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
|
|
275
|
+
if (props.defaultPattern) {
|
|
276
|
+
const item = options.find((item2) => item2.value === props.defaultPattern);
|
|
277
|
+
if (item)
|
|
278
|
+
return item.value;
|
|
279
|
+
}
|
|
280
|
+
return options[0].value;
|
|
281
|
+
});
|
|
282
|
+
props.action.current = () => suffix;
|
|
283
|
+
const onChange = /* @__PURE__ */ __name((v) => {
|
|
284
|
+
v !== void 0 && (suffixSet(v), props.onChange(v));
|
|
285
|
+
}, "onChange");
|
|
286
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
287
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
|
|
288
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { value: suffix, options, onChange }) }),
|
|
289
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
|
|
290
|
+
] });
|
|
291
|
+
}, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
|
|
292
|
+
const t = useDependency(LocaleService).t;
|
|
293
|
+
return props.action.current = () => "", /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
|
|
294
|
+
}, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
|
|
295
|
+
const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
|
|
296
|
+
const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
|
|
297
|
+
return (item == null ? void 0 : item.value) || options[0].value;
|
|
298
|
+
}), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
|
|
299
|
+
decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
|
|
300
|
+
}, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
|
|
301
|
+
v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
|
|
302
|
+
}, "handleClick");
|
|
303
|
+
return props.action.current = () => pattern, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
304
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
|
|
305
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
306
|
+
InputNumber,
|
|
307
|
+
{
|
|
308
|
+
disabled: isInputDisable,
|
|
309
|
+
value: decimal,
|
|
310
|
+
max: 20,
|
|
311
|
+
min: 0,
|
|
312
|
+
onChange: handleDecimalChange
|
|
313
|
+
}
|
|
314
|
+
) }),
|
|
315
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 label", children: [
|
|
316
|
+
" ",
|
|
317
|
+
localeService.t("sheet.numfmt.negType")
|
|
318
|
+
] }),
|
|
319
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
|
|
320
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
|
|
321
|
+
] });
|
|
322
|
+
}, "ThousandthPercentilePanel"), SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
|
|
323
|
+
const { defaultValue, defaultPattern, row, col } = props.value, localeService = useDependency(LocaleService), getCurrentPattern = useRef(() => ""), t = localeService.t, nextTick = useNextTick(), typeOptions = useMemo(
|
|
324
|
+
() => [
|
|
325
|
+
{ label: "sheet.numfmt.general", component: GeneralPanel },
|
|
326
|
+
{ label: "sheet.numfmt.accounting", component: AccountingPanel },
|
|
327
|
+
{ label: "sheet.numfmt.currency", component: CurrencyPanel },
|
|
328
|
+
{ label: "sheet.numfmt.date", component: DatePanel },
|
|
329
|
+
{ label: "sheet.numfmt.thousandthPercentile", component: ThousandthPercentilePanel },
|
|
330
|
+
{ label: "sheet.numfmt.customFormat", component: CustomFormat }
|
|
331
|
+
].map((item) => ({ ...item, label: t(item.label) })),
|
|
332
|
+
[]
|
|
333
|
+
), [type, typeSet] = useState(findDefaultType), [key2, keySet] = useState(() => `${row}_${col}`), { mark, userHabitCurrency } = useCurrencyOptions(() => keySet(`${row}_${col}_userCurrency'`)), BusinessComponent = useMemo(() => {
|
|
334
|
+
var _a6;
|
|
335
|
+
return (_a6 = typeOptions.find((item) => item.label === type)) == null ? void 0 : _a6.component;
|
|
336
|
+
}, [type]);
|
|
337
|
+
function findDefaultType() {
|
|
338
|
+
return [isGeneralPanel, isAccountingPanel, isCurrencyPanel, isDatePanel, isThousandthPercentilePanel].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
|
|
339
|
+
}
|
|
340
|
+
__name(findDefaultType, "findDefaultType");
|
|
341
|
+
const selectOptions = typeOptions.map((option) => ({
|
|
342
|
+
label: option.label,
|
|
343
|
+
value: option.label
|
|
344
|
+
})), handleSelect = /* @__PURE__ */ __name((value) => {
|
|
345
|
+
typeSet(value), nextTick(() => props.onChange({ type: "change", value: getCurrentPattern.current() || "" }));
|
|
346
|
+
}, "handleSelect"), handleChange = /* @__PURE__ */ __name((v) => {
|
|
347
|
+
props.onChange({ type: "change", value: v });
|
|
348
|
+
}, "handleChange"), handleConfirm = /* @__PURE__ */ __name(() => {
|
|
349
|
+
const pattern = getCurrentPattern.current() || "", currency = getCurrencyType(pattern);
|
|
350
|
+
currency && mark(currency), props.onChange({ type: "confirm", value: pattern });
|
|
351
|
+
}, "handleConfirm"), handleCancel = /* @__PURE__ */ __name(() => {
|
|
352
|
+
props.onChange({ type: "cancel", value: "" });
|
|
353
|
+
}, "handleCancel"), subProps = {
|
|
354
|
+
onChange: handleChange,
|
|
355
|
+
defaultValue,
|
|
356
|
+
defaultPattern,
|
|
357
|
+
action: getCurrentPattern
|
|
358
|
+
};
|
|
359
|
+
return useEffect(() => {
|
|
360
|
+
typeSet(findDefaultType()), keySet(`${row}_${col}`);
|
|
361
|
+
}, [row, col]), /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "numfmt-panel p-b-20", children: [
|
|
362
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
363
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label m-t-14", children: t("sheet.numfmt.numfmtType") }),
|
|
364
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: handleSelect, options: selectOptions, value: type, style: { width: "100%" } }) }),
|
|
365
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: BusinessComponent && /* @__PURE__ */ jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider, { value: userHabitCurrency, children: /* @__PURE__ */ createElement(BusinessComponent, { ...subProps, key: key2 }) }) })
|
|
366
|
+
] }),
|
|
367
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
|
|
368
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "small", onClick: handleCancel, className: "m-r-12", children: t("sheet.numfmt.cancel") }),
|
|
369
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
|
|
370
|
+
] })
|
|
371
|
+
] });
|
|
372
|
+
}, "SheetNumfmtPanel");
|
|
373
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
374
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
375
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
376
|
+
return kind && result && __defProp$3(target, key2, result), result;
|
|
377
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3");
|
|
378
|
+
const SHEET_NUMFMT_PANEL = "SHEET_NUMFMT_PANEL";
|
|
379
|
+
var _a2;
|
|
380
|
+
let SheetNumfmtUIController = (_a2 = class extends Disposable {
|
|
381
|
+
constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService) {
|
|
382
|
+
super();
|
|
383
|
+
/**
|
|
384
|
+
* If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
|
|
385
|
+
* @private
|
|
386
|
+
* @type {(string | null)}
|
|
387
|
+
* @memberof NumfmtController
|
|
388
|
+
*/
|
|
389
|
+
__publicField(this, "_previewPattern", "");
|
|
390
|
+
__publicField(this, "_sidebarDisposable", null);
|
|
391
|
+
this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this._selectionManagerService = _selectionManagerService, this._renderManagerService = _renderManagerService, this._numfmtService = _numfmtService, this._componentManager = _componentManager, this._sidebarService = _sidebarService, this._localeService = _localeService, this._initRealTimeRenderingInterceptor(), this._initPanel(), this._initCommands(), this._initCloseListener(), this._commandExecutedListener();
|
|
392
|
+
}
|
|
393
|
+
openPanel() {
|
|
394
|
+
var _a6;
|
|
395
|
+
const sidebarService = this._sidebarService, selectionManagerService = this._selectionManagerService, commandService = this._commandService, univerInstanceService = this._univerInstanceService, numfmtService = this._numfmtService, localeService = this._localeService, range = (((_a6 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a6.map((s) => s.range)) || [])[0];
|
|
396
|
+
if (!range)
|
|
397
|
+
return !1;
|
|
398
|
+
const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), sheet = workbook.getActiveSheet();
|
|
399
|
+
if (!sheet)
|
|
400
|
+
return !1;
|
|
401
|
+
const cellValue = sheet.getCellRaw(range.startRow, range.startColumn), numfmtValue = numfmtService.getValue(
|
|
402
|
+
workbook.getUnitId(),
|
|
403
|
+
sheet.getSheetId(),
|
|
404
|
+
range.startRow,
|
|
405
|
+
range.startColumn
|
|
406
|
+
);
|
|
407
|
+
let pattern = "";
|
|
408
|
+
numfmtValue && (pattern = numfmtValue.pattern);
|
|
409
|
+
const defaultValue = (cellValue == null ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678, props = {
|
|
410
|
+
onChange: /* @__PURE__ */ __name((config) => {
|
|
411
|
+
var _a7;
|
|
412
|
+
if (config.type === "change")
|
|
413
|
+
this._previewPattern = config.value, this._forceUpdate();
|
|
414
|
+
else if (config.type === "confirm") {
|
|
415
|
+
const selections2 = ((_a7 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a7.map((s) => s.range)) || [], params = { values: [] }, patternType = getPatternType(config.value);
|
|
416
|
+
selections2.forEach((rangeInfo) => {
|
|
417
|
+
Range.foreach(rangeInfo, (row, col) => {
|
|
418
|
+
params.values.push({
|
|
419
|
+
row,
|
|
420
|
+
col,
|
|
421
|
+
pattern: config.value,
|
|
422
|
+
type: patternType
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
}), commandService.executeCommand(SetNumfmtCommand.id, params), sidebarService.close();
|
|
426
|
+
} else config.type === "cancel" && sidebarService.close();
|
|
427
|
+
}, "onChange"),
|
|
428
|
+
value: { defaultPattern: pattern, defaultValue, row: range.startRow, col: range.startColumn }
|
|
429
|
+
};
|
|
430
|
+
return this._sidebarDisposable = sidebarService.open({
|
|
431
|
+
header: { title: localeService.t("sheet.numfmt.title") },
|
|
432
|
+
children: {
|
|
433
|
+
label: SHEET_NUMFMT_PANEL,
|
|
434
|
+
...props
|
|
435
|
+
// need passthrough to react props.
|
|
436
|
+
},
|
|
437
|
+
onClose: /* @__PURE__ */ __name(() => {
|
|
438
|
+
this._forceUpdate(), commandService.executeCommand(CloseNumfmtPanelOperator.id);
|
|
439
|
+
}, "onClose")
|
|
440
|
+
}), !0;
|
|
441
|
+
}
|
|
442
|
+
_forceUpdate(unitId) {
|
|
443
|
+
var _a6;
|
|
444
|
+
const renderUnit = this._renderManagerService.getRenderById(
|
|
445
|
+
unitId != null ? unitId : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId()
|
|
446
|
+
);
|
|
447
|
+
renderUnit == null || renderUnit.with(SheetSkeletonManagerService).reCalculate(), (_a6 = renderUnit == null ? void 0 : renderUnit.mainComponent) == null || _a6.makeDirty();
|
|
448
|
+
}
|
|
449
|
+
_initCommands() {
|
|
450
|
+
[
|
|
451
|
+
OpenNumfmtPanelOperator,
|
|
452
|
+
CloseNumfmtPanelOperator
|
|
453
|
+
].forEach((config) => {
|
|
454
|
+
this.disposeWithMe(this._commandService.registerCommand(config));
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
_initPanel() {
|
|
458
|
+
this._componentManager.register(SHEET_NUMFMT_PANEL, SheetNumfmtPanel);
|
|
459
|
+
}
|
|
460
|
+
_initRealTimeRenderingInterceptor() {
|
|
461
|
+
const isPanelOpenObserver = new Observable((subscriber) => {
|
|
462
|
+
this._commandService.onCommandExecuted((commandInfo) => {
|
|
463
|
+
commandInfo.id === OpenNumfmtPanelOperator.id && subscriber.next(!0), commandInfo.id === CloseNumfmtPanelOperator.id && subscriber.next(!1);
|
|
464
|
+
});
|
|
465
|
+
}), combineOpenAndSelection$ = combineLatest([
|
|
466
|
+
isPanelOpenObserver,
|
|
467
|
+
this._selectionManagerService.selectionMoveEnd$.pipe(
|
|
468
|
+
map((selectionInfos) => selectionInfos ? selectionInfos.map((selectionInfo) => selectionInfo.range) : [])
|
|
469
|
+
)
|
|
470
|
+
]);
|
|
471
|
+
this.disposeWithMe(
|
|
472
|
+
toDisposable(
|
|
473
|
+
combineOpenAndSelection$.pipe(
|
|
474
|
+
switchMap(
|
|
475
|
+
([isOpen, selectionRanges]) => new Observable((subscribe) => {
|
|
476
|
+
const disposableCollection = new DisposableCollection();
|
|
477
|
+
return isOpen && selectionRanges.length && subscribe.next({ selectionRanges, disposableCollection }), () => {
|
|
478
|
+
disposableCollection.dispose();
|
|
479
|
+
};
|
|
480
|
+
})
|
|
481
|
+
),
|
|
482
|
+
tap(() => {
|
|
483
|
+
this._previewPattern = null;
|
|
484
|
+
})
|
|
485
|
+
).subscribe(({ disposableCollection, selectionRanges }) => {
|
|
486
|
+
var _a6, _b;
|
|
487
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
488
|
+
this.openPanel(), disposableCollection.add(
|
|
489
|
+
this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
490
|
+
priority: 99,
|
|
491
|
+
effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
|
|
492
|
+
handler: /* @__PURE__ */ __name((cell, location, next) => {
|
|
493
|
+
const { row, col } = location, defaultValue = next(cell) || {};
|
|
494
|
+
if (selectionRanges.find(
|
|
495
|
+
(range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row
|
|
496
|
+
)) {
|
|
497
|
+
const rawValue = location.worksheet.getCellRaw(row, col), value = rawValue == null ? void 0 : rawValue.v, type = rawValue == null ? void 0 : rawValue.t;
|
|
498
|
+
if (value == null || type !== CellValueType.NUMBER || this._previewPattern === null)
|
|
499
|
+
return defaultValue;
|
|
500
|
+
const info = getPatternPreviewIgnoreGeneral(this._previewPattern, value, this._localeService.getCurrentLocale());
|
|
501
|
+
if (info.color) {
|
|
502
|
+
const color = this._themeService.getCurrentTheme()[`${info.color}500`];
|
|
503
|
+
return {
|
|
504
|
+
...defaultValue,
|
|
505
|
+
v: info.result,
|
|
506
|
+
t: CellValueType.STRING,
|
|
507
|
+
s: { cl: { rgb: color } }
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
...defaultValue,
|
|
512
|
+
v: info.result,
|
|
513
|
+
t: CellValueType.STRING
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return defaultValue;
|
|
517
|
+
}, "handler")
|
|
518
|
+
})
|
|
519
|
+
), (_b = (_a6 = this._renderManagerService.getRenderById(workbook.getUnitId())) == null ? void 0 : _a6.mainComponent) == null || _b.makeDirty();
|
|
520
|
+
})
|
|
521
|
+
)
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
_commandExecutedListener() {
|
|
525
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
|
|
526
|
+
this.disposeWithMe(
|
|
527
|
+
new Observable((subscribe) => {
|
|
528
|
+
const disposable = this._commandService.onCommandExecuted((command) => {
|
|
529
|
+
if (commandList.includes(command.id)) {
|
|
530
|
+
const params = command.params;
|
|
531
|
+
subscribe.next(params.unitId);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
return () => disposable.dispose();
|
|
535
|
+
}).pipe(debounceTime(16)).subscribe((unitId) => this._forceUpdate(unitId))
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
_initCloseListener() {
|
|
539
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
|
|
540
|
+
var _a6;
|
|
541
|
+
unit || ((_a6 = this._sidebarDisposable) == null || _a6.dispose(), this._sidebarDisposable = null);
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}, __name(_a2, "SheetNumfmtUIController"), _a2);
|
|
545
|
+
SheetNumfmtUIController = __decorateClass$3([
|
|
546
|
+
__decorateParam$3(0, Inject(SheetInterceptorService)),
|
|
547
|
+
__decorateParam$3(1, Inject(ThemeService)),
|
|
548
|
+
__decorateParam$3(2, IUniverInstanceService),
|
|
549
|
+
__decorateParam$3(3, ICommandService),
|
|
550
|
+
__decorateParam$3(4, Inject(SheetsSelectionsService)),
|
|
551
|
+
__decorateParam$3(5, IRenderManagerService),
|
|
552
|
+
__decorateParam$3(6, INumfmtService),
|
|
553
|
+
__decorateParam$3(7, Inject(ComponentManager)),
|
|
554
|
+
__decorateParam$3(8, ISidebarService),
|
|
555
|
+
__decorateParam$3(9, Inject(LocaleService))
|
|
556
|
+
], SheetNumfmtUIController);
|
|
557
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
558
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
559
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
560
|
+
return kind && result && __defProp$2(target, key2, result), result;
|
|
561
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2");
|
|
562
|
+
const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
|
|
563
|
+
let list = [];
|
|
564
|
+
return {
|
|
565
|
+
add: /* @__PURE__ */ __name((unitId, subUnitId, row, col, value) => list.push({ unitId, subUnitId, row, col, value }), "add"),
|
|
566
|
+
getEffects: /* @__PURE__ */ __name(() => list, "getEffects"),
|
|
567
|
+
clean: /* @__PURE__ */ __name(() => {
|
|
568
|
+
list = [];
|
|
569
|
+
}, "clean")
|
|
570
|
+
};
|
|
571
|
+
}, "createCollectEffectMutation");
|
|
572
|
+
var _a3;
|
|
573
|
+
let NumfmtEditorController = (_a3 = class extends Disposable {
|
|
574
|
+
constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
|
|
575
|
+
super();
|
|
576
|
+
// collect effect mutations when edit end and push this to commands stack in next commands progress
|
|
577
|
+
__publicField(this, "_collectEffectMutation", createCollectEffectMutation());
|
|
578
|
+
this._sheetInterceptorService = _sheetInterceptorService, this._numfmtService = _numfmtService, this._univerInstanceService = _univerInstanceService, this._injector = _injector, this._editorBridgeService = _editorBridgeService, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
|
|
579
|
+
}
|
|
580
|
+
_initInterceptorEditorStart() {
|
|
581
|
+
this._editorBridgeService && this.disposeWithMe(
|
|
582
|
+
toDisposable(
|
|
583
|
+
this._editorBridgeService.interceptor.intercept(
|
|
584
|
+
this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,
|
|
585
|
+
{
|
|
586
|
+
handler: /* @__PURE__ */ __name((value, context, next) => {
|
|
587
|
+
const row = context.row, col = context.col, numfmtCell = this._numfmtService.getValue(
|
|
588
|
+
context.unitId,
|
|
589
|
+
context.subUnitId,
|
|
590
|
+
row,
|
|
591
|
+
col
|
|
592
|
+
);
|
|
593
|
+
if (numfmtCell)
|
|
594
|
+
switch (getPatternType(numfmtCell.pattern)) {
|
|
595
|
+
case "scientific":
|
|
596
|
+
case "currency":
|
|
597
|
+
case "grouped":
|
|
598
|
+
case "number":
|
|
599
|
+
return context.worksheet.getCellRaw(row, col);
|
|
600
|
+
case "percent":
|
|
601
|
+
case "date":
|
|
602
|
+
case "time":
|
|
603
|
+
case "datetime":
|
|
604
|
+
default:
|
|
605
|
+
return next && next(value);
|
|
606
|
+
}
|
|
607
|
+
return next(value);
|
|
608
|
+
}, "handler")
|
|
609
|
+
}
|
|
610
|
+
)
|
|
611
|
+
)
|
|
612
|
+
);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Process the values after edit
|
|
616
|
+
* @private
|
|
617
|
+
* @memberof NumfmtService
|
|
618
|
+
*/
|
|
619
|
+
_initInterceptorEditorEnd() {
|
|
620
|
+
this._editorBridgeService && this.disposeWithMe(
|
|
621
|
+
toDisposable(
|
|
622
|
+
this._editorBridgeService.interceptor.intercept(
|
|
623
|
+
this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,
|
|
624
|
+
{
|
|
625
|
+
handler: /* @__PURE__ */ __name((value, context, next) => {
|
|
626
|
+
var _a6;
|
|
627
|
+
this._collectEffectMutation.clean();
|
|
628
|
+
const currentNumfmtValue = this._numfmtService.getValue(
|
|
629
|
+
context.unitId,
|
|
630
|
+
context.subUnitId,
|
|
631
|
+
context.row,
|
|
632
|
+
context.col
|
|
633
|
+
), currentNumfmtType = (_a6 = currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) != null ? _a6 : "", clean = /* @__PURE__ */ __name(() => {
|
|
634
|
+
currentNumfmtValue && this._collectEffectMutation.add(
|
|
635
|
+
context.unitId,
|
|
636
|
+
context.subUnitId,
|
|
637
|
+
context.row,
|
|
638
|
+
context.col,
|
|
639
|
+
null
|
|
640
|
+
);
|
|
641
|
+
}, "clean");
|
|
642
|
+
if (!(value != null && value.v))
|
|
643
|
+
return next(value);
|
|
644
|
+
const content = String(value.v), numfmtInfo = numfmt.parseDate(content) || numfmt.parseTime(content) || numfmt.parseNumber(content);
|
|
645
|
+
if (numfmtInfo) {
|
|
646
|
+
if (numfmtInfo.z) {
|
|
647
|
+
const v = Number(numfmtInfo.v);
|
|
648
|
+
return this._collectEffectMutation.add(
|
|
649
|
+
context.unitId,
|
|
650
|
+
context.subUnitId,
|
|
651
|
+
context.row,
|
|
652
|
+
context.col,
|
|
653
|
+
{
|
|
654
|
+
pattern: numfmtInfo.z
|
|
655
|
+
}
|
|
656
|
+
), { ...value, v, t: CellValueType.NUMBER };
|
|
657
|
+
}
|
|
658
|
+
} else (["date", "time", "datetime", "percent"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
|
|
659
|
+
return next(value);
|
|
660
|
+
}, "handler")
|
|
661
|
+
}
|
|
662
|
+
)
|
|
663
|
+
)
|
|
664
|
+
);
|
|
665
|
+
}
|
|
666
|
+
_initInterceptorCommands() {
|
|
667
|
+
const self = this;
|
|
668
|
+
this.disposeWithMe(
|
|
669
|
+
this._sheetInterceptorService.interceptCommand({
|
|
670
|
+
getMutations(command) {
|
|
671
|
+
var _a6;
|
|
672
|
+
switch (command.id) {
|
|
673
|
+
case SetRangeValuesCommand.id: {
|
|
674
|
+
const workbook = self._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), subUnitId = (_a6 = workbook.getActiveSheet()) == null ? void 0 : _a6.getSheetId();
|
|
675
|
+
if (!subUnitId)
|
|
676
|
+
return {
|
|
677
|
+
redos: [],
|
|
678
|
+
undos: []
|
|
679
|
+
};
|
|
680
|
+
const list = self._collectEffectMutation.getEffects();
|
|
681
|
+
if (self._collectEffectMutation.clean(), !list.length)
|
|
682
|
+
return {
|
|
683
|
+
redos: [],
|
|
684
|
+
undos: []
|
|
685
|
+
};
|
|
686
|
+
const cells = list.filter((item) => {
|
|
687
|
+
var _a7;
|
|
688
|
+
return !!((_a7 = item.value) != null && _a7.pattern);
|
|
689
|
+
}).map((item) => ({
|
|
690
|
+
row: item.row,
|
|
691
|
+
col: item.col,
|
|
692
|
+
pattern: item.value.pattern
|
|
693
|
+
})), removeCells = list.filter((item) => {
|
|
694
|
+
var _a7;
|
|
695
|
+
return !((_a7 = item.value) != null && _a7.pattern);
|
|
696
|
+
}).map((item) => ({
|
|
697
|
+
startRow: item.row,
|
|
698
|
+
endColumn: item.col,
|
|
699
|
+
startColumn: item.col,
|
|
700
|
+
endRow: item.row
|
|
701
|
+
})), redos = [], undos = [];
|
|
702
|
+
if (cells.length) {
|
|
703
|
+
const redo = {
|
|
704
|
+
id: SetNumfmtMutation.id,
|
|
705
|
+
params: transformCellsToRange(unitId, subUnitId, cells)
|
|
706
|
+
};
|
|
707
|
+
redos.push(redo), undos.push(...factorySetNumfmtUndoMutation(self._injector, redo.params));
|
|
708
|
+
}
|
|
709
|
+
if (removeCells.length) {
|
|
710
|
+
const redo = {
|
|
711
|
+
id: RemoveNumfmtMutation.id,
|
|
712
|
+
params: {
|
|
713
|
+
unitId,
|
|
714
|
+
subUnitId,
|
|
715
|
+
ranges: removeCells
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
redos.push(redo), undos.push(...factoryRemoveNumfmtUndoMutation(self._injector, redo.params));
|
|
719
|
+
}
|
|
720
|
+
return {
|
|
721
|
+
redos,
|
|
722
|
+
undos: undos.reverse()
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return {
|
|
727
|
+
redos: [],
|
|
728
|
+
undos: []
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
})
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
}, __name(_a3, "NumfmtEditorController"), _a3);
|
|
735
|
+
NumfmtEditorController = __decorateClass$2([
|
|
736
|
+
__decorateParam$2(0, Inject(SheetInterceptorService)),
|
|
737
|
+
__decorateParam$2(1, Inject(INumfmtService)),
|
|
738
|
+
__decorateParam$2(2, Inject(IUniverInstanceService)),
|
|
739
|
+
__decorateParam$2(3, Inject(Injector)),
|
|
740
|
+
__decorateParam$2(4, Optional(IEditorBridgeService))
|
|
741
|
+
], NumfmtEditorController);
|
|
742
|
+
function isNumeric(str) {
|
|
743
|
+
return /^-?\d+(\.\d+)?$/.test(str);
|
|
744
|
+
}
|
|
745
|
+
__name(isNumeric, "isNumeric");
|
|
746
|
+
const MENU_OPTIONS = [
|
|
747
|
+
{
|
|
748
|
+
label: "sheet.numfmt.general",
|
|
749
|
+
pattern: null
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
label: "sheet.numfmt.text",
|
|
753
|
+
pattern: DEFAULT_TEXT_FORMAT
|
|
754
|
+
},
|
|
755
|
+
"|",
|
|
756
|
+
{
|
|
757
|
+
label: "sheet.numfmt.number",
|
|
758
|
+
pattern: "0"
|
|
759
|
+
},
|
|
760
|
+
"|",
|
|
761
|
+
{
|
|
762
|
+
label: "sheet.numfmt.accounting",
|
|
763
|
+
pattern: '"¥" #,##0.00_);[Red]("¥"#,##0.00)'
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
label: "sheet.numfmt.financialValue",
|
|
767
|
+
pattern: "#,##0.00;[Red]#,##0.00"
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
label: "sheet.numfmt.currency",
|
|
771
|
+
pattern: '"¥"#,##0.00_);[Red]("¥"#,##0.00)'
|
|
772
|
+
},
|
|
773
|
+
{
|
|
774
|
+
label: "sheet.numfmt.roundingCurrency",
|
|
775
|
+
pattern: '"¥"#,##0;[Red]"¥"#,##0'
|
|
776
|
+
},
|
|
777
|
+
"|",
|
|
778
|
+
{
|
|
779
|
+
label: "sheet.numfmt.date",
|
|
780
|
+
pattern: "yyyy-mm-dd;@"
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
label: "sheet.numfmt.time",
|
|
784
|
+
pattern: 'am/pm h":"mm":"ss'
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
label: "sheet.numfmt.dateTime",
|
|
788
|
+
pattern: "yyyy-m-d am/pm h:mm"
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
label: "sheet.numfmt.timeDuration",
|
|
792
|
+
pattern: "h:mm:ss"
|
|
793
|
+
},
|
|
794
|
+
"|",
|
|
795
|
+
{
|
|
796
|
+
label: "sheet.numfmt.moreFmt",
|
|
797
|
+
pattern: ""
|
|
798
|
+
}
|
|
799
|
+
], CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
800
|
+
icon: new Observable((subscribe) => {
|
|
801
|
+
const menuCurrencyService = accessor.get(MenuCurrencyService);
|
|
802
|
+
function getIconKey(symbol2) {
|
|
803
|
+
return {
|
|
804
|
+
[countryCurrencyMap.US]: "DollarSingle",
|
|
805
|
+
[countryCurrencyMap.RU]: "RoubleSingle",
|
|
806
|
+
[countryCurrencyMap.CN]: "RmbSingle",
|
|
807
|
+
[countryCurrencyMap.AT]: "EuroSingle"
|
|
808
|
+
}[symbol2] || "DollarSingle";
|
|
809
|
+
}
|
|
810
|
+
__name(getIconKey, "getIconKey");
|
|
811
|
+
const symbol = countryCurrencyMap[menuCurrencyService.getCurrencySymbol()] || "$";
|
|
812
|
+
return subscribe.next(getIconKey(symbol)), menuCurrencyService.currencySymbol$.subscribe((code) => {
|
|
813
|
+
const symbol2 = countryCurrencyMap[code] || "$";
|
|
814
|
+
subscribe.next(getIconKey(symbol2));
|
|
815
|
+
});
|
|
816
|
+
}),
|
|
817
|
+
id: SetCurrencyCommand.id,
|
|
818
|
+
title: "sheet.numfmt.currency",
|
|
819
|
+
tooltip: "sheet.numfmt.currency",
|
|
820
|
+
type: MenuItemType.BUTTON,
|
|
821
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
822
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
823
|
+
}), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
824
|
+
icon: "AddDigitsSingle",
|
|
825
|
+
id: AddDecimalCommand.id,
|
|
826
|
+
title: "sheet.numfmt.addDecimal",
|
|
827
|
+
tooltip: "sheet.numfmt.addDecimal",
|
|
828
|
+
type: MenuItemType.BUTTON,
|
|
829
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
830
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
831
|
+
}), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
832
|
+
icon: "ReduceDigitsSingle",
|
|
833
|
+
id: SubtractDecimalCommand.id,
|
|
834
|
+
title: "sheet.numfmt.subtractDecimal",
|
|
835
|
+
tooltip: "sheet.numfmt.subtractDecimal",
|
|
836
|
+
type: MenuItemType.BUTTON,
|
|
837
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
838
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
839
|
+
}), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
840
|
+
icon: "PercentSingle",
|
|
841
|
+
id: SetPercentCommand.id,
|
|
842
|
+
title: "sheet.numfmt.percent",
|
|
843
|
+
tooltip: "sheet.numfmt.percent",
|
|
844
|
+
type: MenuItemType.BUTTON,
|
|
845
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
846
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
847
|
+
}), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
|
|
848
|
+
const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
|
|
849
|
+
(subscribe) => merge(
|
|
850
|
+
selectionManagerService.selectionMoveEnd$,
|
|
851
|
+
new Observable((commandSubscribe) => {
|
|
852
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
|
|
853
|
+
commandList.includes(commandInfo.id) && commandSubscribe.next(null);
|
|
854
|
+
});
|
|
855
|
+
return () => disposable.dispose();
|
|
856
|
+
})
|
|
857
|
+
).subscribe(() => {
|
|
858
|
+
var _a6, _b;
|
|
859
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
860
|
+
if (selections && selections[0]) {
|
|
861
|
+
const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = (_b = workbook.getStyles().get((_a6 = worksheet.getCell(row, col)) == null ? void 0 : _a6.s)) == null ? void 0 : _b.n, pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
|
|
862
|
+
let value = localeService.t("sheet.numfmt.general");
|
|
863
|
+
if (pattern) {
|
|
864
|
+
const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
|
|
865
|
+
(item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
|
|
866
|
+
);
|
|
867
|
+
item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
|
|
868
|
+
}
|
|
869
|
+
subscribe.next(value);
|
|
870
|
+
}
|
|
871
|
+
})
|
|
872
|
+
));
|
|
873
|
+
return {
|
|
874
|
+
label: MORE_NUMFMT_TYPE_KEY,
|
|
875
|
+
id: OpenNumfmtPanelOperator.id,
|
|
876
|
+
tooltip: "sheet.numfmt.title",
|
|
877
|
+
type: MenuItemType.SELECTOR,
|
|
878
|
+
selections: [
|
|
879
|
+
{
|
|
880
|
+
label: {
|
|
881
|
+
name: OPTIONS_KEY,
|
|
882
|
+
hoverable: !1
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
],
|
|
886
|
+
value$,
|
|
887
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
888
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
889
|
+
};
|
|
890
|
+
}, "FactoryOtherMenuItem"), MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
|
|
891
|
+
var _a6;
|
|
892
|
+
const localeService = useDependency(LocaleService), value = (_a6 = props.value) != null ? _a6 : localeService.t("sheet.numfmt.general");
|
|
893
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
|
|
894
|
+
}, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
|
|
895
|
+
const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), layoutService = useDependency(ILayoutService);
|
|
896
|
+
useInjector();
|
|
897
|
+
const selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
|
|
898
|
+
const selection = selectionManagerService.getCurrentLastSelection();
|
|
899
|
+
if (!selection)
|
|
900
|
+
return;
|
|
901
|
+
const range = selection.range, values = [];
|
|
902
|
+
Range.foreach(range, (row, col) => {
|
|
903
|
+
pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
|
|
904
|
+
}), commandService.executeCommand(SetNumfmtCommand.id, { values }), layoutService.focus();
|
|
905
|
+
}, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
|
|
906
|
+
if (index === 0)
|
|
907
|
+
setNumfmt(null);
|
|
908
|
+
else if (index === MENU_OPTIONS.length - 1)
|
|
909
|
+
commandService.executeCommand(OpenNumfmtPanelOperator.id);
|
|
910
|
+
else {
|
|
911
|
+
const item = MENU_OPTIONS[index];
|
|
912
|
+
item.pattern && setNumfmt(item.pattern);
|
|
913
|
+
}
|
|
914
|
+
}, "handleOnclick"), defaultValue = 1220;
|
|
915
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "more-numfmt-type-options", children: MENU_OPTIONS.map((item, index) => item === "|" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "line m-t-4", onClick: /* @__PURE__ */ __name((e) => e.stopPropagation(), "onClick") }, index) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
916
|
+
"div",
|
|
917
|
+
{
|
|
918
|
+
className: "option-item m-t-4",
|
|
919
|
+
onClick: /* @__PURE__ */ __name(() => {
|
|
920
|
+
handleOnclick(index);
|
|
921
|
+
}, "onClick"),
|
|
922
|
+
children: [
|
|
923
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
|
|
924
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
|
|
925
|
+
]
|
|
926
|
+
},
|
|
927
|
+
index
|
|
928
|
+
)) });
|
|
929
|
+
}, "Options"), menuSchema = {
|
|
930
|
+
[RibbonStartGroup.FORMULAS_INSERT]: {
|
|
931
|
+
[SetCurrencyCommand.id]: {
|
|
932
|
+
order: 4,
|
|
933
|
+
menuItemFactory: CurrencyMenuItem
|
|
934
|
+
},
|
|
935
|
+
[AddDecimalCommand.id]: {
|
|
936
|
+
order: 5,
|
|
937
|
+
menuItemFactory: AddDecimalMenuItem
|
|
938
|
+
},
|
|
939
|
+
[SubtractDecimalCommand.id]: {
|
|
940
|
+
order: 6,
|
|
941
|
+
menuItemFactory: SubtractDecimalMenuItem
|
|
942
|
+
},
|
|
943
|
+
[SetPercentCommand.id]: {
|
|
944
|
+
order: 7,
|
|
945
|
+
menuItemFactory: PercentMenuItem
|
|
946
|
+
},
|
|
947
|
+
[OpenNumfmtPanelOperator.id]: {
|
|
948
|
+
order: 8,
|
|
949
|
+
menuItemFactory: FactoryOtherMenuItem
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
954
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
955
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
956
|
+
return kind && result && __defProp$1(target, key2, result), result;
|
|
957
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1"), _a4;
|
|
958
|
+
let NumfmtMenuController = (_a4 = class extends Disposable {
|
|
959
|
+
constructor(_componentManager, _menuManagerService) {
|
|
960
|
+
super(), this._componentManager = _componentManager, this._menuManagerService = _menuManagerService, this._initMenu();
|
|
961
|
+
}
|
|
962
|
+
_initMenu() {
|
|
963
|
+
this._menuManagerService.mergeMenu(menuSchema), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
|
|
964
|
+
}
|
|
965
|
+
}, __name(_a4, "NumfmtMenuController"), _a4);
|
|
966
|
+
NumfmtMenuController = __decorateClass$1([
|
|
967
|
+
__decorateParam$1(0, Inject(ComponentManager)),
|
|
968
|
+
__decorateParam$1(1, IMenuManagerService)
|
|
969
|
+
], NumfmtMenuController);
|
|
970
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key2, value) => key2 in obj ? __defProp2(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
971
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
972
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
973
|
+
return kind && result && __defProp2(target, key2, result), result;
|
|
974
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key2, value) => __defNormalProp2(obj, typeof key2 != "symbol" ? key2 + "" : key2, value), "__publicField");
|
|
975
|
+
const SHEET_NUMFMT_UI_PLUGIN = "SHEET_NUMFMT_UI_PLUGIN";
|
|
976
|
+
var _a5;
|
|
977
|
+
let UniverSheetsNumfmtUIPlugin = (_a5 = class extends Plugin {
|
|
978
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
979
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService;
|
|
980
|
+
const { menu, ...rest } = this._config;
|
|
981
|
+
menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
|
|
982
|
+
}
|
|
983
|
+
onStarting() {
|
|
984
|
+
registerDependencies(this._injector, [
|
|
985
|
+
[SheetNumfmtUIController],
|
|
986
|
+
[NumfmtEditorController],
|
|
987
|
+
[UserHabitController],
|
|
988
|
+
[NumfmtMenuController]
|
|
989
|
+
]);
|
|
990
|
+
}
|
|
991
|
+
onRendered() {
|
|
992
|
+
touchDependencies(this._injector, [
|
|
993
|
+
[SheetNumfmtUIController],
|
|
994
|
+
[NumfmtEditorController],
|
|
995
|
+
[NumfmtMenuController]
|
|
996
|
+
]);
|
|
997
|
+
}
|
|
998
|
+
}, __name(_a5, "UniverSheetsNumfmtUIPlugin"), _a5);
|
|
999
|
+
__publicField2(UniverSheetsNumfmtUIPlugin, "pluginName", SHEET_NUMFMT_UI_PLUGIN);
|
|
1000
|
+
__publicField2(UniverSheetsNumfmtUIPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
1001
|
+
UniverSheetsNumfmtUIPlugin = __decorateClass([
|
|
1002
|
+
DependentOn(UniverSheetsUIPlugin, UniverSheetsNumfmtPlugin),
|
|
1003
|
+
__decorateParam(1, Inject(Injector)),
|
|
1004
|
+
__decorateParam(2, IConfigService)
|
|
1005
|
+
], UniverSheetsNumfmtUIPlugin);
|
|
1006
|
+
export {
|
|
1007
|
+
UniverSheetsNumfmtUIPlugin
|
|
1008
|
+
};
|