@univerjs/sheets-numfmt 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +932 -826
- package/lib/index.css +1 -1
- package/lib/locale/en-US.json +3 -1
- package/lib/locale/ru-RU.json +3 -1
- package/lib/locale/vi-VN.json +3 -1
- package/lib/locale/zh-CN.json +3 -1
- package/lib/locale/zh-TW.json +6 -4
- package/lib/types/components/custom-format/index.d.ts +4 -0
- package/lib/types/controllers/__tests__/test.util.d.ts +7 -8
- package/lib/types/controllers/numfmt.editor.controller.d.ts +1 -2
- package/lib/types/controllers/numfmt.menu.controller.d.ts +1 -2
- package/lib/types/controllers/type.d.ts +1 -1
- package/lib/types/locale/zh-CN.d.ts +2 -0
- package/lib/types/menu/menu.d.ts +1 -1
- package/lib/types/numfmt-plugin.d.ts +1 -2
- package/lib/umd/index.js +2 -2
- package/package.json +21 -23
package/lib/es/index.js
CHANGED
|
@@ -1,208 +1,207 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import { Inject
|
|
6
|
-
import { INTERCEPTOR_POINT
|
|
7
|
-
import { SheetSkeletonManagerService
|
|
8
|
-
import { switchMap
|
|
9
|
-
import { numfmt
|
|
10
|
-
import { IRenderManagerService
|
|
11
|
-
import { ComponentManager
|
|
12
|
-
import { map
|
|
13
|
-
import
|
|
14
|
-
import { InputNumber
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
color: i.color
|
|
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 { LocaleType, Disposable, ObjectMatrix, CellValueType, Range, UniverInstanceType, OnLifecycle, LifecycleStages, Inject, ThemeService, ICommandService, LocaleService, IUniverInstanceService, CommandType, IUndoRedoService, sequenceExecute, createIdentifier, runOnLifecycle, ILocalStorageService, useDependency, toDisposable, DisposableCollection, Injector, Optional, useInjector, Plugin, Tools, DependentOn } from "@univerjs/core";
|
|
6
|
+
import { INTERCEPTOR_POINT, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, INumfmtService, getSheetCommandTarget, transformCellsToRange, rangeMerge, factorySetNumfmtUndoMutation, RemoveNumfmtMutation, factoryRemoveNumfmtUndoMutation, SheetsSelectionsService, SetRangeValuesCommand, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, RangeProtectionPermissionEditPoint, UniverSheetsPlugin } from "@univerjs/sheets";
|
|
7
|
+
import { SheetSkeletonManagerService, IEditorBridgeService, getCurrentRangeDisable$, deriveStateFromActiveSheet$, UniverSheetsUIPlugin } from "@univerjs/sheets-ui";
|
|
8
|
+
import { switchMap, of, skip, Observable, combineLatest, merge } from "rxjs";
|
|
9
|
+
import { numfmt, DEFAULT_TEXT_FORMAT } from "@univerjs/engine-numfmt";
|
|
10
|
+
import { IRenderManagerService, ITextSelectionRenderManager } from "@univerjs/engine-render";
|
|
11
|
+
import { ComponentManager, ISidebarService, MenuItemType, MenuGroup, MenuPosition, getMenuHiddenObservable, IMenuService } from "@univerjs/ui";
|
|
12
|
+
import { map, switchMap as switchMap$1, 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
|
+
const SHEET_NUMFMT_PLUGIN = "SHEET_NUMFMT_PLUGIN", getPatternType = /* @__PURE__ */ __name((pattern) => numfmt.getInfo(pattern).type || "unknown", "getPatternType"), getPatternPreview = /* @__PURE__ */ __name((pattern, value, _locale) => {
|
|
16
|
+
const info = numfmt.getInfo(pattern), locale = _locale === LocaleType.ZH_CN ? "zh-CN" : "en", negInfo = info._partitions[1], result = numfmt.format(pattern, value, { locale });
|
|
17
|
+
return value < 0 ? {
|
|
18
|
+
result,
|
|
19
|
+
color: negInfo.color
|
|
21
20
|
} : {
|
|
22
|
-
result
|
|
21
|
+
result
|
|
23
22
|
};
|
|
24
|
-
};
|
|
25
|
-
var
|
|
26
|
-
for (var
|
|
27
|
-
(
|
|
28
|
-
return
|
|
29
|
-
},
|
|
30
|
-
let
|
|
31
|
-
constructor(
|
|
32
|
-
super(), this._instanceService =
|
|
23
|
+
}, "getPatternPreview");
|
|
24
|
+
var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
25
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
26
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
27
|
+
return kind && result && __defProp$6(target, key2, result), result;
|
|
28
|
+
}, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$6"), _a;
|
|
29
|
+
let SheetsNumfmtCellContentController = (_a = class extends Disposable {
|
|
30
|
+
constructor(_instanceService, _sheetInterceptorService, _themeService, _commandService, _numfmtService, _localeService) {
|
|
31
|
+
super(), this._instanceService = _instanceService, this._sheetInterceptorService = _sheetInterceptorService, this._themeService = _themeService, this._commandService = _commandService, this._numfmtService = _numfmtService, this._localeService = _localeService, this._initInterceptorCellContent();
|
|
33
32
|
}
|
|
34
33
|
_initInterceptorCellContent() {
|
|
35
|
-
const
|
|
36
|
-
this.disposeWithMe(this._sheetInterceptorService.intercept(
|
|
37
|
-
handler: (
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
return
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
43
|
-
return
|
|
44
|
-
let
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
return
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
return
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
|
|
34
|
+
const renderCache = new ObjectMatrix();
|
|
35
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
36
|
+
handler: /* @__PURE__ */ __name((cell, location, next) => {
|
|
37
|
+
const unitId = location.unitId, sheetId = location.subUnitId, numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);
|
|
38
|
+
if (!numfmtValue)
|
|
39
|
+
return next(cell);
|
|
40
|
+
const originCellValue = cell;
|
|
41
|
+
if (!originCellValue || originCellValue.t !== CellValueType.NUMBER)
|
|
42
|
+
return next(cell);
|
|
43
|
+
let numfmtRes = "";
|
|
44
|
+
const cache = renderCache.getValue(location.row, location.col);
|
|
45
|
+
if (cache && cache.parameters === originCellValue.v)
|
|
46
|
+
return next({ ...cell, ...cache.result });
|
|
47
|
+
const info = getPatternPreview(numfmtValue.pattern, Number(originCellValue.v), this._localeService.getCurrentLocale());
|
|
48
|
+
if (numfmtRes = info.result, !numfmtRes)
|
|
49
|
+
return next(cell);
|
|
50
|
+
const res = { v: numfmtRes };
|
|
51
|
+
if (info.color) {
|
|
52
|
+
const color = this._themeService.getCurrentTheme()[`${info.color}500`];
|
|
53
|
+
color && (res.interceptorStyle = { cl: { rgb: color } });
|
|
55
54
|
}
|
|
56
|
-
return
|
|
57
|
-
result:
|
|
58
|
-
parameters:
|
|
59
|
-
}),
|
|
60
|
-
},
|
|
55
|
+
return renderCache.setValue(location.row, location.col, {
|
|
56
|
+
result: res,
|
|
57
|
+
parameters: originCellValue.v
|
|
58
|
+
}), next({ ...cell, ...res });
|
|
59
|
+
}, "handler"),
|
|
61
60
|
priority: 10
|
|
62
|
-
})), this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
Object.keys(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
})), this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
62
|
+
if (commandInfo.id === SetNumfmtMutation.id) {
|
|
63
|
+
const params = commandInfo.params;
|
|
64
|
+
Object.keys(params.values).forEach((key2) => {
|
|
65
|
+
params.values[key2].ranges.forEach((range) => {
|
|
66
|
+
Range.foreach(range, (row, col) => {
|
|
67
|
+
renderCache.realDeleteValue(row, col);
|
|
69
68
|
});
|
|
70
69
|
});
|
|
71
70
|
});
|
|
72
|
-
} else if (
|
|
73
|
-
const
|
|
74
|
-
new
|
|
75
|
-
|
|
71
|
+
} else if (commandInfo.id === SetRangeValuesMutation.id) {
|
|
72
|
+
const params = commandInfo.params;
|
|
73
|
+
new ObjectMatrix(params.cellValue).forValue((row, col) => {
|
|
74
|
+
renderCache.realDeleteValue(row, col);
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
})), this.disposeWithMe(
|
|
79
|
-
this._instanceService.getCurrentTypeOfUnit$(
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
return (
|
|
78
|
+
this._instanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(
|
|
79
|
+
switchMap((workbook) => {
|
|
80
|
+
var _a8;
|
|
81
|
+
return (_a8 = workbook == null ? void 0 : workbook.activeSheet$) != null ? _a8 : of(null);
|
|
83
82
|
}),
|
|
84
|
-
|
|
85
|
-
).subscribe(() =>
|
|
83
|
+
skip(1)
|
|
84
|
+
).subscribe(() => renderCache.reset())
|
|
86
85
|
);
|
|
87
86
|
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
],
|
|
98
|
-
const
|
|
99
|
-
var
|
|
100
|
-
return
|
|
101
|
-
},
|
|
102
|
-
if (
|
|
87
|
+
}, __name(_a, "SheetsNumfmtCellContentController"), _a);
|
|
88
|
+
SheetsNumfmtCellContentController = __decorateClass$6([
|
|
89
|
+
OnLifecycle(LifecycleStages.Rendered, SheetsNumfmtCellContentController),
|
|
90
|
+
__decorateParam$6(0, IUniverInstanceService),
|
|
91
|
+
__decorateParam$6(1, Inject(SheetInterceptorService)),
|
|
92
|
+
__decorateParam$6(2, Inject(ThemeService)),
|
|
93
|
+
__decorateParam$6(3, Inject(ICommandService)),
|
|
94
|
+
__decorateParam$6(4, Inject(INumfmtService)),
|
|
95
|
+
__decorateParam$6(5, Inject(LocaleService))
|
|
96
|
+
], SheetsNumfmtCellContentController);
|
|
97
|
+
const getDecimalFromPattern = /* @__PURE__ */ __name((pattern, defaultValue = 0) => {
|
|
98
|
+
var _a8;
|
|
99
|
+
return pattern && (_a8 = numfmt.getInfo(pattern).maxDecimals) != null ? _a8 : defaultValue;
|
|
100
|
+
}, "getDecimalFromPattern"), isPatternEqualWithoutDecimal = /* @__PURE__ */ __name((patternA, patternB) => {
|
|
101
|
+
if (patternA && !patternB || !patternA && patternB)
|
|
103
102
|
return !1;
|
|
104
|
-
const
|
|
105
|
-
(
|
|
106
|
-
if (
|
|
107
|
-
return
|
|
108
|
-
const
|
|
109
|
-
return
|
|
103
|
+
const getString = /* @__PURE__ */ __name((tokens) => tokens.reduce(
|
|
104
|
+
(pre, cur) => {
|
|
105
|
+
if (pre.isEnd)
|
|
106
|
+
return pre;
|
|
107
|
+
const str = cur.value || cur.num;
|
|
108
|
+
return cur.type === "point" ? (pre.isEnd = !0, pre) : { ...pre, result: pre.result + str };
|
|
110
109
|
},
|
|
111
110
|
{ isEnd: !1, result: "" }
|
|
112
|
-
).result,
|
|
113
|
-
return
|
|
114
|
-
},
|
|
111
|
+
).result, "getString"), partitionsA = numfmt.getInfo(patternA)._partitions, partitionsB = numfmt.getInfo(patternB)._partitions, A1 = getString(partitionsA[0].tokens), B1 = getString(partitionsB[0].tokens), A2 = getString(partitionsA[1].tokens), B2 = getString(partitionsB[1].tokens);
|
|
112
|
+
return A1 === B1 && A2 === B2 && partitionsA[1].color === partitionsB[1].color;
|
|
113
|
+
}, "isPatternEqualWithoutDecimal"), getDecimalString = /* @__PURE__ */ __name((length) => new Array(Math.min(Math.max(0, Number(length)), 30)).fill(0).join(""), "getDecimalString"), setPatternDecimal = /* @__PURE__ */ __name((patterns, decimalLength) => patterns.split(";").map((pattern) => /\.0?/.test(pattern) ? pattern.replace(
|
|
115
114
|
/\.0*/g,
|
|
116
|
-
`${
|
|
117
|
-
) : /0([^0]?)|0$/.test(
|
|
115
|
+
`${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}`
|
|
116
|
+
) : /0([^0]?)|0$/.test(pattern) ? pattern.replace(
|
|
118
117
|
/0([^0]+)|0$/,
|
|
119
|
-
`0${
|
|
120
|
-
) :
|
|
118
|
+
`0${decimalLength > 0 ? "." : ""}${getDecimalString(Number(decimalLength || 0))}$1`
|
|
119
|
+
) : pattern).join(";"), "setPatternDecimal"), isPatternHasDecimal = /* @__PURE__ */ __name((pattern) => /\.0?/.test(pattern) || /0([^0]?)|0$/.test(pattern), "isPatternHasDecimal"), SetNumfmtCommand = {
|
|
121
120
|
id: "sheet.command.numfmt.set.numfmt",
|
|
122
|
-
type:
|
|
123
|
-
handler: (
|
|
124
|
-
if (!
|
|
121
|
+
type: CommandType.COMMAND,
|
|
122
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
123
|
+
if (!params)
|
|
125
124
|
return !1;
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
128
|
-
const { unitId
|
|
129
|
-
unitId
|
|
130
|
-
subUnitId
|
|
131
|
-
ranges:
|
|
132
|
-
startColumn:
|
|
133
|
-
startRow:
|
|
134
|
-
endColumn:
|
|
135
|
-
endRow:
|
|
125
|
+
const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), undoRedoService = accessor.get(IUndoRedoService), target = getSheetCommandTarget(univerInstanceService, params);
|
|
126
|
+
if (!target) return !1;
|
|
127
|
+
const { unitId, subUnitId } = target, setCells = params.values.filter((value) => !!value.pattern), removeCells = params.values.filter((value) => !value.pattern), setRedos = transformCellsToRange(unitId, subUnitId, setCells), removeRedos = {
|
|
128
|
+
unitId,
|
|
129
|
+
subUnitId,
|
|
130
|
+
ranges: removeCells.map((cell) => ({
|
|
131
|
+
startColumn: cell.col,
|
|
132
|
+
startRow: cell.row,
|
|
133
|
+
endColumn: cell.col,
|
|
134
|
+
endRow: cell.row
|
|
136
135
|
}))
|
|
137
|
-
},
|
|
138
|
-
if (
|
|
139
|
-
Object.keys(
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
}),
|
|
143
|
-
id:
|
|
144
|
-
params:
|
|
136
|
+
}, redos = [], undos = [];
|
|
137
|
+
if (setCells.length) {
|
|
138
|
+
Object.keys(setRedos.values).forEach((key2) => {
|
|
139
|
+
const v = setRedos.values[key2];
|
|
140
|
+
v.ranges = rangeMerge(v.ranges);
|
|
141
|
+
}), redos.push({
|
|
142
|
+
id: SetNumfmtMutation.id,
|
|
143
|
+
params: setRedos
|
|
145
144
|
});
|
|
146
|
-
const
|
|
147
|
-
|
|
145
|
+
const undo = factorySetNumfmtUndoMutation(accessor, setRedos);
|
|
146
|
+
undos.push(...undo);
|
|
148
147
|
}
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
id:
|
|
152
|
-
params:
|
|
148
|
+
if (removeCells.length) {
|
|
149
|
+
removeRedos.ranges = rangeMerge(removeRedos.ranges), redos.push({
|
|
150
|
+
id: RemoveNumfmtMutation.id,
|
|
151
|
+
params: removeRedos
|
|
153
152
|
});
|
|
154
|
-
const
|
|
155
|
-
|
|
153
|
+
const undo = factoryRemoveNumfmtUndoMutation(accessor, removeRedos);
|
|
154
|
+
undos.push(...undo);
|
|
156
155
|
}
|
|
157
|
-
const
|
|
158
|
-
return
|
|
159
|
-
unitID:
|
|
160
|
-
undoMutations:
|
|
161
|
-
redoMutations:
|
|
162
|
-
}),
|
|
163
|
-
}
|
|
164
|
-
},
|
|
156
|
+
const result = sequenceExecute(redos, commandService).result;
|
|
157
|
+
return result && undoRedoService.pushUndoRedo({
|
|
158
|
+
unitID: unitId,
|
|
159
|
+
undoMutations: undos,
|
|
160
|
+
redoMutations: redos
|
|
161
|
+
}), result;
|
|
162
|
+
}, "handler")
|
|
163
|
+
}, AddDecimalCommand = {
|
|
165
164
|
id: "sheet.command.numfmt.add.decimal.command",
|
|
166
|
-
type:
|
|
167
|
-
handler: async (
|
|
168
|
-
const
|
|
169
|
-
if (!
|
|
165
|
+
type: CommandType.COMMAND,
|
|
166
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
167
|
+
const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
|
|
168
|
+
if (!selections || !selections.length)
|
|
170
169
|
return !1;
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
173
|
-
const { unitId
|
|
174
|
-
let
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
if (!
|
|
170
|
+
const target = getSheetCommandTarget(univerInstanceService);
|
|
171
|
+
if (!target) return !1;
|
|
172
|
+
const { unitId, subUnitId } = target;
|
|
173
|
+
let maxDecimals = 0;
|
|
174
|
+
selections.forEach((selection) => {
|
|
175
|
+
Range.foreach(selection.range, (row, col) => {
|
|
176
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
177
|
+
if (!numfmtValue)
|
|
179
178
|
return;
|
|
180
|
-
const
|
|
181
|
-
|
|
179
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
180
|
+
maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
|
|
182
181
|
});
|
|
183
182
|
});
|
|
184
|
-
const
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
if (!
|
|
189
|
-
|
|
190
|
-
row
|
|
191
|
-
col
|
|
192
|
-
pattern:
|
|
183
|
+
const decimals = maxDecimals + 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : ""}`, decimals), values = [];
|
|
184
|
+
return selections.forEach((selection) => {
|
|
185
|
+
Range.foreach(selection.range, (row, col) => {
|
|
186
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
187
|
+
if (!numfmtValue)
|
|
188
|
+
values.push({
|
|
189
|
+
row,
|
|
190
|
+
col,
|
|
191
|
+
pattern: defaultPattern
|
|
193
192
|
});
|
|
194
193
|
else {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
row
|
|
198
|
-
col
|
|
199
|
-
pattern
|
|
194
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern), pattern = setPatternDecimal(numfmtValue.pattern, decimals2 + 1);
|
|
195
|
+
pattern !== numfmtValue.pattern && values.push({
|
|
196
|
+
row,
|
|
197
|
+
col,
|
|
198
|
+
pattern
|
|
200
199
|
});
|
|
201
200
|
}
|
|
202
201
|
});
|
|
203
|
-
}),
|
|
204
|
-
}
|
|
205
|
-
},
|
|
202
|
+
}), values.length ? await commandService.executeCommand(SetNumfmtCommand.id, { values }) : !1;
|
|
203
|
+
}, "handler")
|
|
204
|
+
}, DATEFMTLISG = [
|
|
206
205
|
{
|
|
207
206
|
label: "1930-08-05",
|
|
208
207
|
suffix: "yyyy-MM-dd"
|
|
@@ -247,7 +246,7 @@ const j = (e, t = 0) => {
|
|
|
247
246
|
label: "08-05 下午 01:30",
|
|
248
247
|
suffix: "MM-dd A/P hh:mm"
|
|
249
248
|
}
|
|
250
|
-
],
|
|
249
|
+
], NUMBERFORMAT = [
|
|
251
250
|
{
|
|
252
251
|
label: "(1,235)",
|
|
253
252
|
suffix: "#,##0_);(#,##0)"
|
|
@@ -275,104 +274,104 @@ const j = (e, t = 0) => {
|
|
|
275
274
|
suffix: "#,##0.00_);[Red]-#,##0.00",
|
|
276
275
|
color: "red"
|
|
277
276
|
}
|
|
278
|
-
],
|
|
277
|
+
], CURRENCYFORMAT = [
|
|
279
278
|
{
|
|
280
|
-
label: (
|
|
281
|
-
suffix: (
|
|
279
|
+
label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
|
|
280
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);"${suffix}"#,##0.00`, "suffix")
|
|
282
281
|
},
|
|
283
282
|
{
|
|
284
|
-
label: (
|
|
285
|
-
suffix: (
|
|
283
|
+
label: /* @__PURE__ */ __name((suffix) => `${suffix}1,235`, "label"),
|
|
284
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]"${suffix}"#,##0.00`, "suffix"),
|
|
286
285
|
color: "red"
|
|
287
286
|
},
|
|
288
287
|
{
|
|
289
|
-
label: (
|
|
290
|
-
suffix: (
|
|
288
|
+
label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
|
|
289
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);("${suffix}"#,##0.00)`, "suffix")
|
|
291
290
|
},
|
|
292
291
|
{
|
|
293
|
-
label: (
|
|
294
|
-
suffix: (
|
|
292
|
+
label: /* @__PURE__ */ __name((suffix) => `(${suffix}1,235)`, "label"),
|
|
293
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]("${suffix}"#,##0.00)`, "suffix"),
|
|
295
294
|
color: "red"
|
|
296
295
|
},
|
|
297
296
|
{
|
|
298
|
-
label: (
|
|
299
|
-
suffix: (
|
|
297
|
+
label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
|
|
298
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);-"${suffix}"#,##0.00`, "suffix")
|
|
300
299
|
},
|
|
301
300
|
{
|
|
302
|
-
label: (
|
|
303
|
-
suffix: (
|
|
301
|
+
label: /* @__PURE__ */ __name((suffix) => `-${suffix}1,235`, "label"),
|
|
302
|
+
suffix: /* @__PURE__ */ __name((suffix) => `"${suffix}"#,##0.00_);[Red]-"${suffix}"#,##0.00`, "suffix"),
|
|
304
303
|
color: "red"
|
|
305
304
|
}
|
|
306
|
-
],
|
|
305
|
+
], SetCurrencyCommand = {
|
|
307
306
|
id: "sheet.command.numfmt.set.currency",
|
|
308
|
-
type:
|
|
309
|
-
handler: async (
|
|
310
|
-
const
|
|
311
|
-
if (!
|
|
307
|
+
type: CommandType.COMMAND,
|
|
308
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
309
|
+
const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
310
|
+
if (!selections || !selections.length)
|
|
312
311
|
return !1;
|
|
313
|
-
const
|
|
314
|
-
return
|
|
315
|
-
|
|
316
|
-
|
|
312
|
+
const values = [], suffix = CURRENCYFORMAT[0].suffix("¥");
|
|
313
|
+
return selections.forEach((selection) => {
|
|
314
|
+
Range.foreach(selection.range, (row, col) => {
|
|
315
|
+
values.push({ row, col, pattern: suffix, type: "currency" });
|
|
317
316
|
});
|
|
318
|
-
}), await
|
|
319
|
-
}
|
|
320
|
-
},
|
|
317
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
318
|
+
}, "handler")
|
|
319
|
+
}, SubtractDecimalCommand = {
|
|
321
320
|
id: "sheet.command.numfmt.subtract.decimal.command",
|
|
322
|
-
type:
|
|
323
|
-
handler: async (
|
|
324
|
-
const
|
|
325
|
-
if (!
|
|
321
|
+
type: CommandType.COMMAND,
|
|
322
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
323
|
+
const commandService = accessor.get(ICommandService), selectionManagerService = accessor.get(SheetsSelectionsService), numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), selections = selectionManagerService.getCurrentSelections();
|
|
324
|
+
if (!selections || !selections.length)
|
|
326
325
|
return !1;
|
|
327
|
-
const
|
|
328
|
-
if (!
|
|
329
|
-
const { unitId
|
|
330
|
-
let
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
if (!
|
|
326
|
+
const target = getSheetCommandTarget(univerInstanceService);
|
|
327
|
+
if (!target) return !1;
|
|
328
|
+
const { unitId, subUnitId } = target;
|
|
329
|
+
let maxDecimals = 0;
|
|
330
|
+
selections.forEach((selection) => {
|
|
331
|
+
Range.foreach(selection.range, (row, col) => {
|
|
332
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
333
|
+
if (!numfmtValue)
|
|
335
334
|
return;
|
|
336
|
-
const
|
|
337
|
-
|
|
335
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
336
|
+
maxDecimals = decimals2 > maxDecimals ? decimals2 : maxDecimals;
|
|
338
337
|
});
|
|
339
338
|
});
|
|
340
|
-
const
|
|
341
|
-
return
|
|
342
|
-
|
|
343
|
-
const
|
|
344
|
-
if (!
|
|
345
|
-
|
|
346
|
-
row
|
|
347
|
-
col
|
|
348
|
-
pattern:
|
|
339
|
+
const decimals = maxDecimals - 1, defaultPattern = setPatternDecimal(`0${decimals > 0 ? ".0" : "."}`, decimals), values = [];
|
|
340
|
+
return selections.forEach((selection) => {
|
|
341
|
+
Range.foreach(selection.range, (row, col) => {
|
|
342
|
+
const numfmtValue = numfmtService.getValue(unitId, subUnitId, row, col);
|
|
343
|
+
if (!numfmtValue)
|
|
344
|
+
values.push({
|
|
345
|
+
row,
|
|
346
|
+
col,
|
|
347
|
+
pattern: defaultPattern
|
|
349
348
|
});
|
|
350
349
|
else {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
row
|
|
354
|
-
col
|
|
355
|
-
pattern:
|
|
350
|
+
const decimals2 = getDecimalFromPattern(numfmtValue.pattern);
|
|
351
|
+
values.push({
|
|
352
|
+
row,
|
|
353
|
+
col,
|
|
354
|
+
pattern: setPatternDecimal(numfmtValue.pattern, decimals2 - 1)
|
|
356
355
|
});
|
|
357
356
|
}
|
|
358
357
|
});
|
|
359
|
-
}), await
|
|
360
|
-
}
|
|
361
|
-
},
|
|
358
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
359
|
+
}, "handler")
|
|
360
|
+
}, CloseNumfmtPanelOperator = {
|
|
362
361
|
id: "sheet.operation.close.numfmt.panel",
|
|
363
|
-
type:
|
|
364
|
-
handler: () => (
|
|
362
|
+
type: CommandType.OPERATION,
|
|
363
|
+
handler: /* @__PURE__ */ __name(() => (
|
|
365
364
|
// do nothing,just notify panel is closed
|
|
366
365
|
!0
|
|
367
|
-
)
|
|
368
|
-
},
|
|
369
|
-
|
|
370
|
-
const
|
|
366
|
+
), "handler")
|
|
367
|
+
}, INumfmtController = createIdentifier("INumfmtController");
|
|
368
|
+
runOnLifecycle(LifecycleStages.Rendered, INumfmtController);
|
|
369
|
+
const OpenNumfmtPanelOperator = {
|
|
371
370
|
id: "sheet.operation.open.numfmt.panel",
|
|
372
|
-
type:
|
|
373
|
-
handler: (
|
|
371
|
+
type: CommandType.OPERATION,
|
|
372
|
+
handler: /* @__PURE__ */ __name((accessor) => (accessor.get(INumfmtController).openPanel(), !0), "handler")
|
|
374
373
|
};
|
|
375
|
-
var
|
|
374
|
+
var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
376
375
|
/**
|
|
377
376
|
* @license React
|
|
378
377
|
* react-jsx-runtime.production.min.js
|
|
@@ -382,20 +381,21 @@ var tt = { exports: {} }, Se = {};
|
|
|
382
381
|
* This source code is licensed under the MIT license found in the
|
|
383
382
|
* LICENSE file in the root directory of this source tree.
|
|
384
383
|
*/
|
|
385
|
-
var
|
|
386
|
-
function
|
|
387
|
-
var
|
|
388
|
-
|
|
389
|
-
for (
|
|
390
|
-
if (
|
|
391
|
-
return { $$typeof:
|
|
384
|
+
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 };
|
|
385
|
+
function q(c, a, g) {
|
|
386
|
+
var b, d = {}, e = null, h = null;
|
|
387
|
+
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
388
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
389
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
390
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
392
391
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
392
|
+
__name(q, "q");
|
|
393
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
394
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
395
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
396
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
397
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
398
|
+
const UserHabitCurrencyContext = createContext([]), currencySymbols = [
|
|
399
399
|
"$",
|
|
400
400
|
"£",
|
|
401
401
|
"¥",
|
|
@@ -424,259 +424,362 @@ const Ae = Kt([]), Me = [
|
|
|
424
424
|
"₾",
|
|
425
425
|
"₿"
|
|
426
426
|
];
|
|
427
|
-
var
|
|
428
|
-
for (var
|
|
429
|
-
(
|
|
430
|
-
return
|
|
431
|
-
},
|
|
432
|
-
let
|
|
433
|
-
constructor(
|
|
434
|
-
this._localStorageService =
|
|
427
|
+
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
428
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
429
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
430
|
+
return kind && result && __defProp$5(target, key2, result), result;
|
|
431
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$5"), _a2;
|
|
432
|
+
let UserHabitController = (_a2 = class {
|
|
433
|
+
constructor(_localStorageService) {
|
|
434
|
+
this._localStorageService = _localStorageService;
|
|
435
435
|
}
|
|
436
|
-
_getKey(
|
|
437
|
-
return `userHabitController_${
|
|
436
|
+
_getKey(habit) {
|
|
437
|
+
return `userHabitController_${habit}`;
|
|
438
438
|
}
|
|
439
|
-
async addHabit(
|
|
440
|
-
const
|
|
441
|
-
return this._localStorageService.getItem(
|
|
442
|
-
|
|
439
|
+
async addHabit(habit, initValue) {
|
|
440
|
+
const key2 = this._getKey(habit);
|
|
441
|
+
return this._localStorageService.getItem(key2).then((item) => {
|
|
442
|
+
item || this._localStorageService.setItem(key2, initValue);
|
|
443
443
|
});
|
|
444
444
|
}
|
|
445
|
-
markHabit(
|
|
446
|
-
const
|
|
447
|
-
this._localStorageService.getItem(
|
|
448
|
-
if (
|
|
449
|
-
const
|
|
450
|
-
|
|
445
|
+
markHabit(habit, value) {
|
|
446
|
+
const key2 = this._getKey(habit);
|
|
447
|
+
this._localStorageService.getItem(key2).then((list) => {
|
|
448
|
+
if (list) {
|
|
449
|
+
const index = list.findIndex((item) => item === value);
|
|
450
|
+
index > -1 && list.splice(index, 1), list.unshift(value), this._localStorageService.setItem(key2, list);
|
|
451
451
|
}
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
|
-
async getHabit(
|
|
455
|
-
const
|
|
456
|
-
if (
|
|
457
|
-
const
|
|
458
|
-
const
|
|
454
|
+
async getHabit(habit, sortList) {
|
|
455
|
+
const key2 = this._getKey(habit), result = await this._localStorageService.getItem(key2);
|
|
456
|
+
if (sortList && result) {
|
|
457
|
+
const priority = result.map((item, index, arr) => {
|
|
458
|
+
const length = arr.length;
|
|
459
459
|
return {
|
|
460
|
-
value:
|
|
461
|
-
priority:
|
|
460
|
+
value: item,
|
|
461
|
+
priority: length - index
|
|
462
462
|
};
|
|
463
463
|
});
|
|
464
|
-
return
|
|
465
|
-
var
|
|
466
|
-
const
|
|
467
|
-
return (((
|
|
464
|
+
return sortList.sort((a, b) => {
|
|
465
|
+
var _a8, _b;
|
|
466
|
+
const ap = ((_a8 = priority.find((item) => item.value === a)) == null ? void 0 : _a8.priority) || -1;
|
|
467
|
+
return (((_b = priority.find((item) => item.value === b)) == null ? void 0 : _b.priority) || -1) - ap;
|
|
468
468
|
});
|
|
469
469
|
}
|
|
470
|
-
return
|
|
470
|
+
return result || [];
|
|
471
471
|
}
|
|
472
|
-
deleteHabit(
|
|
473
|
-
this._localStorageService.removeItem(
|
|
472
|
+
deleteHabit(habit) {
|
|
473
|
+
this._localStorageService.removeItem(habit);
|
|
474
474
|
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
],
|
|
479
|
-
const
|
|
480
|
-
const
|
|
481
|
-
return
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
475
|
+
}, __name(_a2, "UserHabitController"), _a2);
|
|
476
|
+
UserHabitController = __decorateClass$5([
|
|
477
|
+
__decorateParam$5(0, Inject(ILocalStorageService))
|
|
478
|
+
], UserHabitController);
|
|
479
|
+
const key$1 = "numfmtCurrency", useCurrencyOptions = /* @__PURE__ */ __name((onOptionChange) => {
|
|
480
|
+
const userHabitController = useDependency(UserHabitController), [options, optionsSet] = useState(currencySymbols);
|
|
481
|
+
return useEffect(() => {
|
|
482
|
+
userHabitController.addHabit("numfmtCurrency", []).then(() => {
|
|
483
|
+
userHabitController.getHabit(key$1, [...currencySymbols]).then((list) => {
|
|
484
|
+
optionsSet(list), onOptionChange && onOptionChange(list);
|
|
485
485
|
});
|
|
486
486
|
});
|
|
487
|
-
}, []), { userHabitCurrency:
|
|
488
|
-
|
|
489
|
-
} };
|
|
490
|
-
},
|
|
491
|
-
const
|
|
492
|
-
return
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}),
|
|
496
|
-
}, [
|
|
497
|
-
|
|
498
|
-
};
|
|
499
|
-
},
|
|
500
|
-
const [
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
},
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
};
|
|
508
|
-
return /* @__PURE__ */
|
|
509
|
-
/* @__PURE__ */
|
|
510
|
-
/* @__PURE__ */
|
|
511
|
-
/* @__PURE__ */
|
|
512
|
-
/* @__PURE__ */
|
|
487
|
+
}, []), { userHabitCurrency: options, mark: /* @__PURE__ */ __name((v) => {
|
|
488
|
+
userHabitController.markHabit(key$1, v);
|
|
489
|
+
}, "mark") };
|
|
490
|
+
}, "useCurrencyOptions"), useNextTick = /* @__PURE__ */ __name(() => {
|
|
491
|
+
const effectList = useRef([]), [value, dispatch] = useState({});
|
|
492
|
+
return useEffect(() => {
|
|
493
|
+
effectList.current.forEach((fn) => {
|
|
494
|
+
fn();
|
|
495
|
+
}), effectList.current = [];
|
|
496
|
+
}, [value]), /* @__PURE__ */ __name((fn) => {
|
|
497
|
+
effectList.current.push(fn), dispatch({});
|
|
498
|
+
}, "nextTick");
|
|
499
|
+
}, "useNextTick"), getCurrencyType = /* @__PURE__ */ __name((pattern) => currencySymbols.find((code) => pattern.includes(code)), "getCurrencyType"), isAccountingPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && pattern.startsWith("_("), "isAccountingPanel"), AccountingPanel = /* @__PURE__ */ __name((props) => {
|
|
500
|
+
const [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 2)), userHabitCurrency = useContext(UserHabitCurrencyContext), [suffix, suffixSet] = useState(() => getCurrencyType(props.defaultPattern) || userHabitCurrency[0]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), []), t = useDependency(LocaleService).t;
|
|
501
|
+
props.action.current = () => setPatternDecimal(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal);
|
|
502
|
+
const onSelect = /* @__PURE__ */ __name((v) => {
|
|
503
|
+
suffixSet(v), props.onChange(setPatternDecimal(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
504
|
+
}, "onSelect"), onDecimalChange = /* @__PURE__ */ __name((v) => {
|
|
505
|
+
const decimal2 = v || 0;
|
|
506
|
+
decimalSet(decimal2), props.onChange(setPatternDecimal(`_("${suffix}"* #,##0${decimal2 > 0 ? ".0" : ""}_)`, decimal2));
|
|
507
|
+
}, "onDecimalChange");
|
|
508
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
509
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
|
|
510
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
511
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
|
|
512
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
|
|
513
513
|
] }),
|
|
514
|
-
/* @__PURE__ */
|
|
515
|
-
/* @__PURE__ */
|
|
516
|
-
/* @__PURE__ */
|
|
514
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
515
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
|
|
516
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
|
|
517
517
|
] })
|
|
518
518
|
] }),
|
|
519
|
-
/* @__PURE__ */
|
|
519
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.accountingDes") })
|
|
520
520
|
] });
|
|
521
|
-
},
|
|
522
|
-
label:
|
|
523
|
-
value:
|
|
524
|
-
color:
|
|
525
|
-
})),
|
|
526
|
-
const
|
|
527
|
-
var
|
|
528
|
-
const
|
|
529
|
-
return ((
|
|
530
|
-
}),
|
|
531
|
-
|
|
532
|
-
const
|
|
533
|
-
if (
|
|
521
|
+
}, "AccountingPanel"), getCurrencyFormatOptions = /* @__PURE__ */ __name((suffix) => CURRENCYFORMAT.map((item) => ({
|
|
522
|
+
label: item.label(suffix),
|
|
523
|
+
value: item.suffix(suffix),
|
|
524
|
+
color: item.color
|
|
525
|
+
})), "getCurrencyFormatOptions"), getDateFormatOptions = /* @__PURE__ */ __name(() => DATEFMTLISG.map((item) => ({ label: item.label, value: item.suffix })), "getDateFormatOptions"), getNumberFormatOptions = /* @__PURE__ */ __name(() => NUMBERFORMAT.map((item) => ({ label: item.label, value: item.suffix, color: item.color })), "getNumberFormatOptions"), isCurrencyPanel = /* @__PURE__ */ __name((pattern) => !!getCurrencyType(pattern) && !pattern.startsWith("_("), "isCurrencyPanel"), CurrencyPanel = /* @__PURE__ */ __name((props) => {
|
|
526
|
+
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(() => {
|
|
527
|
+
var _a8;
|
|
528
|
+
const negativeOptions2 = getCurrencyFormatOptions(suffix);
|
|
529
|
+
return ((_a8 = negativeOptions2.find((item) => isPatternEqualWithoutDecimal(item.value, props.defaultPattern))) == null ? void 0 : _a8.value) || negativeOptions2[0].value;
|
|
530
|
+
}), negativeOptions = useMemo(() => getCurrencyFormatOptions(suffix), [suffix]), options = useMemo(() => userHabitCurrency.map((key2) => ({ label: key2, value: key2 })), [userHabitCurrency]);
|
|
531
|
+
props.action.current = () => setPatternDecimal(pattern, decimal);
|
|
532
|
+
const onSelect = /* @__PURE__ */ __name((value) => {
|
|
533
|
+
if (value === void 0)
|
|
534
534
|
return;
|
|
535
|
-
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
},
|
|
541
|
-
|
|
542
|
-
};
|
|
543
|
-
return /* @__PURE__ */
|
|
544
|
-
/* @__PURE__ */
|
|
545
|
-
/* @__PURE__ */
|
|
546
|
-
/* @__PURE__ */
|
|
547
|
-
/* @__PURE__ */
|
|
535
|
+
suffixSet(value);
|
|
536
|
+
const pattern2 = getCurrencyFormatOptions(value)[0].value;
|
|
537
|
+
patternSet(pattern2), props.onChange(setPatternDecimal(pattern2, decimal));
|
|
538
|
+
}, "onSelect"), onChange = /* @__PURE__ */ __name((value) => {
|
|
539
|
+
value !== void 0 && (patternSet(value), props.onChange(setPatternDecimal(value, decimal)));
|
|
540
|
+
}, "onChange"), onDecimalChange = /* @__PURE__ */ __name((v) => {
|
|
541
|
+
decimalSet(v || 0), props.onChange(setPatternDecimal(pattern, v || 0));
|
|
542
|
+
}, "onDecimalChange");
|
|
543
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
544
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 options ", children: [
|
|
545
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
546
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.decimalLength") }),
|
|
547
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-120", children: /* @__PURE__ */ jsxRuntimeExports.jsx(InputNumber, { value: decimal, max: 20, min: 0, onChange: onDecimalChange }) })
|
|
548
548
|
] }),
|
|
549
|
-
/* @__PURE__ */
|
|
550
|
-
/* @__PURE__ */
|
|
551
|
-
/* @__PURE__ */
|
|
549
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "option", children: [
|
|
550
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label", children: t("sheet.numfmt.currencyType") }),
|
|
551
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8 w-140", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: onSelect, options, value: suffix }) })
|
|
552
552
|
] })
|
|
553
553
|
] }),
|
|
554
|
-
/* @__PURE__ */
|
|
555
|
-
/* @__PURE__ */
|
|
556
|
-
/* @__PURE__ */
|
|
554
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.negType") }),
|
|
555
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange, options: negativeOptions, value: pattern }) }),
|
|
556
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.currencyDes") })
|
|
557
557
|
] });
|
|
558
|
-
},
|
|
559
|
-
const
|
|
560
|
-
return
|
|
561
|
-
},
|
|
562
|
-
const
|
|
563
|
-
if (
|
|
564
|
-
const
|
|
565
|
-
if (
|
|
566
|
-
return
|
|
558
|
+
}, "CurrencyPanel"), isDatePanel = /* @__PURE__ */ __name((pattern) => {
|
|
559
|
+
const info = numfmt.getInfo(pattern);
|
|
560
|
+
return getDateFormatOptions().map((item) => item.value).includes(pattern) || ["date", "datetime", "time"].includes(info.type);
|
|
561
|
+
}, "isDatePanel"), DatePanel = /* @__PURE__ */ __name((props) => {
|
|
562
|
+
const options = useMemo(getDateFormatOptions, []), t = useDependency(LocaleService).t, [suffix, suffixSet] = useState(() => {
|
|
563
|
+
if (props.defaultPattern) {
|
|
564
|
+
const item = options.find((item2) => item2.value === props.defaultPattern);
|
|
565
|
+
if (item)
|
|
566
|
+
return item.value;
|
|
567
567
|
}
|
|
568
|
-
return
|
|
568
|
+
return options[0].value;
|
|
569
569
|
});
|
|
570
|
-
|
|
571
|
-
const
|
|
572
|
-
|
|
573
|
-
};
|
|
574
|
-
return /* @__PURE__ */
|
|
575
|
-
/* @__PURE__ */
|
|
576
|
-
/* @__PURE__ */
|
|
577
|
-
/* @__PURE__ */
|
|
570
|
+
props.action.current = () => suffix;
|
|
571
|
+
const onChange = /* @__PURE__ */ __name((v) => {
|
|
572
|
+
v !== void 0 && (suffixSet(v), props.onChange(v));
|
|
573
|
+
}, "onChange");
|
|
574
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
575
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: t("sheet.numfmt.dateType") }),
|
|
576
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { value: suffix, options, onChange }) }),
|
|
577
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.dateDes") })
|
|
578
578
|
] });
|
|
579
|
-
},
|
|
580
|
-
const
|
|
581
|
-
return
|
|
582
|
-
},
|
|
583
|
-
const
|
|
584
|
-
const
|
|
585
|
-
return (
|
|
586
|
-
}),
|
|
587
|
-
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
};
|
|
591
|
-
return
|
|
592
|
-
/* @__PURE__ */
|
|
593
|
-
/* @__PURE__ */
|
|
594
|
-
|
|
579
|
+
}, "DatePanel"), isGeneralPanel = /* @__PURE__ */ __name((pattern) => !pattern, "isGeneralPanel"), GeneralPanel = /* @__PURE__ */ __name((props) => {
|
|
580
|
+
const t = useDependency(LocaleService).t;
|
|
581
|
+
return props.action.current = () => "", /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: t("sheet.numfmt.generalDes") }) });
|
|
582
|
+
}, "GeneralPanel"), isThousandthPercentilePanel = /* @__PURE__ */ __name((pattern) => getNumberFormatOptions().some((item) => isPatternEqualWithoutDecimal(item.value, pattern)), "isThousandthPercentilePanel"), ThousandthPercentilePanel = /* @__PURE__ */ __name((props) => {
|
|
583
|
+
const localeService = useDependency(LocaleService), options = useMemo(getNumberFormatOptions, []), [decimal, decimalSet] = useState(() => getDecimalFromPattern(props.defaultPattern || "", 0)), [suffix, suffixSet] = useState(() => {
|
|
584
|
+
const item = options.find((item2) => isPatternEqualWithoutDecimal(item2.value, props.defaultPattern || ""));
|
|
585
|
+
return (item == null ? void 0 : item.value) || options[0].value;
|
|
586
|
+
}), pattern = useMemo(() => setPatternDecimal(suffix, Number(decimal || 0)), [suffix, decimal]), isInputDisable = useMemo(() => !isPatternHasDecimal(suffix), [suffix]), handleDecimalChange = /* @__PURE__ */ __name((decimal2) => {
|
|
587
|
+
decimalSet(decimal2 || 0), props.onChange(setPatternDecimal(suffix, Number(decimal2 || 0)));
|
|
588
|
+
}, "handleDecimalChange"), handleClick = /* @__PURE__ */ __name((v) => {
|
|
589
|
+
v !== void 0 && (decimalSet(getDecimalFromPattern(v, 0)), suffixSet(v), props.onChange(v));
|
|
590
|
+
}, "handleClick");
|
|
591
|
+
return props.action.current = () => pattern, /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
592
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-16 label", children: localeService.t("sheet.numfmt.decimalLength") }),
|
|
593
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
594
|
+
InputNumber,
|
|
595
595
|
{
|
|
596
|
-
disabled:
|
|
597
|
-
value:
|
|
596
|
+
disabled: isInputDisable,
|
|
597
|
+
value: decimal,
|
|
598
598
|
max: 20,
|
|
599
599
|
min: 0,
|
|
600
|
-
onChange:
|
|
600
|
+
onChange: handleDecimalChange
|
|
601
601
|
}
|
|
602
602
|
) }),
|
|
603
|
-
/* @__PURE__ */
|
|
603
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "m-t-16 label", children: [
|
|
604
604
|
" ",
|
|
605
|
-
|
|
605
|
+
localeService.t("sheet.numfmt.negType")
|
|
606
606
|
] }),
|
|
607
|
-
/* @__PURE__ */
|
|
608
|
-
/* @__PURE__ */
|
|
607
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectList, { onChange: handleClick, options, value: suffix }) }),
|
|
608
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "describe m-t-14", children: localeService.t("sheet.numfmt.thousandthPercentileDes") })
|
|
609
609
|
] });
|
|
610
|
-
},
|
|
611
|
-
|
|
610
|
+
}, "ThousandthPercentilePanel");
|
|
611
|
+
var __assign = function() {
|
|
612
|
+
return __assign = Object.assign || function(t) {
|
|
613
|
+
for (var s, i = 1, n2 = arguments.length; i < n2; i++) {
|
|
614
|
+
s = arguments[i];
|
|
615
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && (t[p2] = s[p2]);
|
|
616
|
+
}
|
|
617
|
+
return t;
|
|
618
|
+
}, __assign.apply(this, arguments);
|
|
619
|
+
}, __rest = function(s, e) {
|
|
620
|
+
var t = {};
|
|
621
|
+
for (var p2 in s) Object.prototype.hasOwnProperty.call(s, p2) && e.indexOf(p2) < 0 && (t[p2] = s[p2]);
|
|
622
|
+
if (s != null && typeof Object.getOwnPropertySymbols == "function")
|
|
623
|
+
for (var i = 0, p2 = Object.getOwnPropertySymbols(s); i < p2.length; i++)
|
|
624
|
+
e.indexOf(p2[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p2[i]) && (t[p2[i]] = s[p2[i]]);
|
|
625
|
+
return t;
|
|
626
|
+
}, IconBase = forwardRef(function(props, ref) {
|
|
627
|
+
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()));
|
|
628
|
+
return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
|
|
629
|
+
});
|
|
630
|
+
function render(node, id, runtimeProps, rootProps, extend) {
|
|
631
|
+
return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
|
|
632
|
+
return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
|
|
633
|
+
}));
|
|
634
|
+
}
|
|
635
|
+
__name(render, "render");
|
|
636
|
+
function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
|
|
637
|
+
var attrs = __assign({}, node.attrs);
|
|
638
|
+
extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
|
|
639
|
+
var defIds = runtimeProps.defIds;
|
|
640
|
+
return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a8) {
|
|
641
|
+
var key2 = _a8[0], value = _a8[1];
|
|
642
|
+
typeof value == "string" && (attrs[key2] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
|
|
643
|
+
})), attrs;
|
|
644
|
+
}
|
|
645
|
+
__name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
|
|
646
|
+
function replaceRuntimeIdsInDefs(node, runtimeProps) {
|
|
647
|
+
var _a8, defIds = runtimeProps.defIds;
|
|
648
|
+
return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a8 = node.children) === null || _a8 === void 0) && _a8.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
|
|
649
|
+
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;
|
|
650
|
+
}) }) : node;
|
|
651
|
+
}
|
|
652
|
+
__name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
|
|
653
|
+
function generateShortUuid() {
|
|
654
|
+
return Math.random().toString(36).substring(2, 8);
|
|
655
|
+
}
|
|
656
|
+
__name(generateShortUuid, "generateShortUuid");
|
|
657
|
+
IconBase.displayName = "UniverIcon";
|
|
658
|
+
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) {
|
|
659
|
+
return createElement(IconBase, Object.assign({}, props, {
|
|
660
|
+
id: "check-mark-single",
|
|
661
|
+
ref,
|
|
662
|
+
icon: element
|
|
663
|
+
}));
|
|
664
|
+
});
|
|
665
|
+
CheckMarkSingle.displayName = "CheckMarkSingle";
|
|
666
|
+
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 = {
|
|
667
|
+
customFormatTitle,
|
|
668
|
+
customFormatInput,
|
|
669
|
+
customFormatHistoryList,
|
|
670
|
+
customFormatHistoryListItem,
|
|
671
|
+
customFormatHistoryListItemIconWrap,
|
|
672
|
+
customFormatDes
|
|
673
|
+
}, key = "customFormat", historyPatternKey = "numfmt_custom_pattern";
|
|
674
|
+
function CustomFormat(props) {
|
|
675
|
+
const { defaultPattern, action, onChange } = props, userHabitController = useDependency(UserHabitController), localStorageService = useDependency(ILocalStorageService), localeService = useDependency(LocaleService), [pattern, patternSet] = useState(defaultPattern);
|
|
676
|
+
action.current = () => (userHabitController.markHabit(key, pattern), localStorageService.getItem(historyPatternKey).then((list = []) => {
|
|
677
|
+
const _list = [.../* @__PURE__ */ new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
|
|
678
|
+
localStorageService.setItem(historyPatternKey, _list);
|
|
679
|
+
}), pattern);
|
|
680
|
+
const [options, optionsSet] = useState([]);
|
|
681
|
+
useEffect(() => {
|
|
682
|
+
localStorageService.getItem(historyPatternKey).then((historyList) => {
|
|
683
|
+
const list = [
|
|
684
|
+
...CURRENCYFORMAT.map((item) => item.suffix("$")),
|
|
685
|
+
...DATEFMTLISG.map((item) => item.suffix),
|
|
686
|
+
...NUMBERFORMAT.map((item) => item.suffix)
|
|
687
|
+
];
|
|
688
|
+
list.push(...historyList || []), userHabitController.addHabit(key, []).finally(() => {
|
|
689
|
+
userHabitController.getHabit(key, list).then((list2) => {
|
|
690
|
+
optionsSet([...new Set(list2)]);
|
|
691
|
+
});
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
}, []);
|
|
695
|
+
const handleClick = /* @__PURE__ */ __name((p2) => {
|
|
696
|
+
patternSet(p2), onChange(p2);
|
|
697
|
+
}, "handleClick"), handleBlur = /* @__PURE__ */ __name(() => {
|
|
698
|
+
onChange(pattern);
|
|
699
|
+
}, "handleBlur");
|
|
700
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.customFormat, children: [
|
|
701
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatTitle, children: localeService.t("sheet.numfmt.customFormat") }),
|
|
702
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Input, { placeholder: localeService.t("sheet.numfmt.customFormat"), onBlur: handleBlur, value: pattern, onChange: patternSet, className: styles.customFormatInput }),
|
|
703
|
+
/* @__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: [
|
|
704
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatHistoryListItemIconWrap, children: pattern === p2 && /* @__PURE__ */ jsxRuntimeExports.jsx(CheckMarkSingle, {}) }),
|
|
705
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: p2 })
|
|
706
|
+
] }, p2)) }),
|
|
707
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.customFormatDes, children: localeService.t("sheet.numfmt.customFormatDes") })
|
|
708
|
+
] });
|
|
709
|
+
}
|
|
710
|
+
__name(CustomFormat, "CustomFormat");
|
|
711
|
+
const SheetNumfmtPanel = /* @__PURE__ */ __name((props) => {
|
|
712
|
+
const { defaultValue, defaultPattern, row, col } = props.value, localeService = useDependency(LocaleService), getCurrentPattern = useRef(() => ""), t = localeService.t, nextTick = useNextTick(), typeOptions = useMemo(
|
|
612
713
|
() => [
|
|
613
|
-
{ label: "sheet.numfmt.general", component:
|
|
614
|
-
{ label: "sheet.numfmt.accounting", component:
|
|
615
|
-
{ label: "sheet.numfmt.currency", component:
|
|
616
|
-
{ label: "sheet.numfmt.date", component:
|
|
617
|
-
{ label: "sheet.numfmt.thousandthPercentile", component:
|
|
618
|
-
|
|
714
|
+
{ label: "sheet.numfmt.general", component: GeneralPanel },
|
|
715
|
+
{ label: "sheet.numfmt.accounting", component: AccountingPanel },
|
|
716
|
+
{ label: "sheet.numfmt.currency", component: CurrencyPanel },
|
|
717
|
+
{ label: "sheet.numfmt.date", component: DatePanel },
|
|
718
|
+
{ label: "sheet.numfmt.thousandthPercentile", component: ThousandthPercentilePanel },
|
|
719
|
+
{ label: "sheet.numfmt.customFormat", component: CustomFormat }
|
|
720
|
+
].map((item) => ({ ...item, label: t(item.label) })),
|
|
619
721
|
[]
|
|
620
|
-
), [
|
|
621
|
-
var
|
|
622
|
-
return (
|
|
623
|
-
}, [
|
|
624
|
-
function
|
|
625
|
-
return [
|
|
722
|
+
), [type, typeSet] = useState(findDefaultType), [key2, keySet] = useState(() => `${row}_${col}`), { mark, userHabitCurrency } = useCurrencyOptions(() => keySet(`${row}_${col}_userCurrency'`)), BusinessComponent = useMemo(() => {
|
|
723
|
+
var _a8;
|
|
724
|
+
return (_a8 = typeOptions.find((item) => item.label === type)) == null ? void 0 : _a8.component;
|
|
725
|
+
}, [type]);
|
|
726
|
+
function findDefaultType() {
|
|
727
|
+
return [isGeneralPanel, isAccountingPanel, isCurrencyPanel, isDatePanel, isThousandthPercentilePanel].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
|
|
626
728
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
729
|
+
__name(findDefaultType, "findDefaultType");
|
|
730
|
+
const selectOptions = typeOptions.map((option) => ({
|
|
731
|
+
label: option.label,
|
|
732
|
+
value: option.label
|
|
733
|
+
})), handleSelect = /* @__PURE__ */ __name((value) => {
|
|
734
|
+
typeSet(value), nextTick(() => props.onChange({ type: "change", value: getCurrentPattern.current() || "" }));
|
|
735
|
+
}, "handleSelect"), handleChange = /* @__PURE__ */ __name((v) => {
|
|
736
|
+
props.onChange({ type: "change", value: v });
|
|
737
|
+
}, "handleChange"), handleConfirm = /* @__PURE__ */ __name(() => {
|
|
738
|
+
const pattern = getCurrentPattern.current() || "", currency = getCurrencyType(pattern);
|
|
739
|
+
currency && mark(currency), props.onChange({ type: "confirm", value: pattern });
|
|
740
|
+
}, "handleConfirm"), handleCancel = /* @__PURE__ */ __name(() => {
|
|
741
|
+
props.onChange({ type: "cancel", value: "" });
|
|
742
|
+
}, "handleCancel"), subProps = {
|
|
743
|
+
onChange: handleChange,
|
|
744
|
+
defaultValue,
|
|
745
|
+
defaultPattern,
|
|
746
|
+
action: getCurrentPattern
|
|
644
747
|
};
|
|
645
|
-
return
|
|
646
|
-
|
|
647
|
-
}, [
|
|
648
|
-
/* @__PURE__ */
|
|
649
|
-
/* @__PURE__ */
|
|
650
|
-
/* @__PURE__ */
|
|
651
|
-
/* @__PURE__ */
|
|
748
|
+
return useEffect(() => {
|
|
749
|
+
typeSet(findDefaultType()), keySet(`${row}_${col}`);
|
|
750
|
+
}, [row, col]), /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "numfmt-panel p-b-20", children: [
|
|
751
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
752
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "label m-t-14", children: t("sheet.numfmt.numfmtType") }),
|
|
753
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { onChange: handleSelect, options: selectOptions, value: type, style: { width: "100%" } }) }),
|
|
754
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: BusinessComponent && /* @__PURE__ */ jsxRuntimeExports.jsx(UserHabitCurrencyContext.Provider, { value: userHabitCurrency, children: /* @__PURE__ */ createElement(BusinessComponent, { ...subProps, key: key2 }) }) })
|
|
652
755
|
] }),
|
|
653
|
-
/* @__PURE__ */
|
|
654
|
-
/* @__PURE__ */
|
|
655
|
-
/* @__PURE__ */
|
|
756
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "btn-list m-t-14 m-b-20", children: [
|
|
757
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "small", onClick: handleCancel, className: "m-r-12", children: t("sheet.numfmt.cancel") }),
|
|
758
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: handleConfirm, children: t("sheet.numfmt.confirm") })
|
|
656
759
|
] })
|
|
657
760
|
] });
|
|
658
|
-
},
|
|
761
|
+
}, "SheetNumfmtPanel"), SetPercentCommand = {
|
|
659
762
|
id: "sheet.command.numfmt.set.percent",
|
|
660
|
-
type:
|
|
661
|
-
handler: async (
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
763
|
+
type: CommandType.COMMAND,
|
|
764
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
765
|
+
const commandService = accessor.get(ICommandService), selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
766
|
+
if (!selections || !selections.length)
|
|
664
767
|
return !1;
|
|
665
|
-
const
|
|
666
|
-
return
|
|
667
|
-
|
|
668
|
-
|
|
768
|
+
const values = [], suffix = "0%";
|
|
769
|
+
return selections.forEach((selection) => {
|
|
770
|
+
Range.foreach(selection.range, (row, col) => {
|
|
771
|
+
values.push({ row, col, pattern: suffix, type: "percent" });
|
|
669
772
|
});
|
|
670
|
-
}), await
|
|
671
|
-
}
|
|
773
|
+
}), await commandService.executeCommand(SetNumfmtCommand.id, { values });
|
|
774
|
+
}, "handler")
|
|
672
775
|
};
|
|
673
|
-
var
|
|
674
|
-
for (var
|
|
675
|
-
(
|
|
676
|
-
return
|
|
677
|
-
},
|
|
678
|
-
let
|
|
679
|
-
constructor(
|
|
776
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
777
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
778
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
779
|
+
return kind && result && __defProp$4(target, key2, result), result;
|
|
780
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$4"), _a3;
|
|
781
|
+
let NumfmtController = (_a3 = class extends Disposable {
|
|
782
|
+
constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService) {
|
|
680
783
|
super();
|
|
681
784
|
/**
|
|
682
785
|
* If _previewPattern is null ,the realTimeRenderingInterceptor will skip and if it is '',realTimeRenderingInterceptor will clear numfmt.
|
|
@@ -684,230 +787,231 @@ let le = class extends K {
|
|
|
684
787
|
* @type {(string | null)}
|
|
685
788
|
* @memberof NumfmtController
|
|
686
789
|
*/
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
this._sheetInterceptorService =
|
|
790
|
+
__publicField(this, "_previewPattern", "");
|
|
791
|
+
__publicField(this, "_sidebarDisposable", null);
|
|
792
|
+
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();
|
|
690
793
|
}
|
|
691
794
|
openPanel() {
|
|
692
|
-
var
|
|
693
|
-
const
|
|
694
|
-
if (!
|
|
795
|
+
var _a8;
|
|
796
|
+
const sidebarService = this._sidebarService, selectionManagerService = this._selectionManagerService, commandService = this._commandService, univerInstanceService = this._univerInstanceService, numfmtService = this._numfmtService, localeService = this._localeService, range = (((_a8 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a8.map((s) => s.range)) || [])[0];
|
|
797
|
+
if (!range)
|
|
695
798
|
return !1;
|
|
696
|
-
const
|
|
697
|
-
if (!
|
|
799
|
+
const workbook = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), sheet = workbook.getActiveSheet();
|
|
800
|
+
if (!sheet)
|
|
698
801
|
return !1;
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
802
|
+
const cellValue = sheet.getCellRaw(range.startRow, range.startColumn), numfmtValue = numfmtService.getValue(
|
|
803
|
+
workbook.getUnitId(),
|
|
804
|
+
sheet.getSheetId(),
|
|
805
|
+
range.startRow,
|
|
806
|
+
range.startColumn
|
|
704
807
|
);
|
|
705
|
-
let
|
|
706
|
-
|
|
707
|
-
const
|
|
708
|
-
onChange: (
|
|
709
|
-
var
|
|
710
|
-
if (
|
|
711
|
-
this._previewPattern =
|
|
712
|
-
else if (
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
row
|
|
718
|
-
col
|
|
719
|
-
pattern:
|
|
720
|
-
type:
|
|
808
|
+
let pattern = "";
|
|
809
|
+
numfmtValue && (pattern = numfmtValue.pattern);
|
|
810
|
+
const defaultValue = (cellValue == null ? void 0 : cellValue.t) === CellValueType.NUMBER ? cellValue.v : 12345678, props = {
|
|
811
|
+
onChange: /* @__PURE__ */ __name((config) => {
|
|
812
|
+
var _a9;
|
|
813
|
+
if (config.type === "change")
|
|
814
|
+
this._previewPattern = config.value, this._forceUpdate();
|
|
815
|
+
else if (config.type === "confirm") {
|
|
816
|
+
const selections2 = ((_a9 = selectionManagerService.getCurrentSelections()) == null ? void 0 : _a9.map((s) => s.range)) || [], params = { values: [] }, patternType = getPatternType(config.value);
|
|
817
|
+
selections2.forEach((rangeInfo) => {
|
|
818
|
+
Range.foreach(rangeInfo, (row, col) => {
|
|
819
|
+
params.values.push({
|
|
820
|
+
row,
|
|
821
|
+
col,
|
|
822
|
+
pattern: config.value,
|
|
823
|
+
type: patternType
|
|
721
824
|
});
|
|
722
825
|
});
|
|
723
|
-
}),
|
|
724
|
-
} else
|
|
725
|
-
},
|
|
726
|
-
value: { defaultPattern:
|
|
826
|
+
}), commandService.executeCommand(SetNumfmtCommand.id, params), sidebarService.close();
|
|
827
|
+
} else config.type === "cancel" && sidebarService.close();
|
|
828
|
+
}, "onChange"),
|
|
829
|
+
value: { defaultPattern: pattern, defaultValue, row: range.startRow, col: range.startColumn }
|
|
727
830
|
};
|
|
728
|
-
return this._sidebarDisposable =
|
|
729
|
-
header: { title:
|
|
831
|
+
return this._sidebarDisposable = sidebarService.open({
|
|
832
|
+
header: { title: localeService.t("sheet.numfmt.title") },
|
|
730
833
|
children: {
|
|
731
|
-
label:
|
|
732
|
-
...
|
|
834
|
+
label: SHEET_NUMFMT_PLUGIN,
|
|
835
|
+
...props
|
|
733
836
|
// need passthrough to react props.
|
|
734
837
|
},
|
|
735
|
-
onClose: () => {
|
|
736
|
-
this._forceUpdate(),
|
|
737
|
-
}
|
|
838
|
+
onClose: /* @__PURE__ */ __name(() => {
|
|
839
|
+
this._forceUpdate(), commandService.executeCommand(CloseNumfmtPanelOperator.id);
|
|
840
|
+
}, "onClose")
|
|
738
841
|
}), !0;
|
|
739
842
|
}
|
|
740
|
-
_forceUpdate(
|
|
741
|
-
var
|
|
742
|
-
const
|
|
743
|
-
|
|
843
|
+
_forceUpdate(unitId) {
|
|
844
|
+
var _a8;
|
|
845
|
+
const renderUnit = this._renderManagerService.getRenderById(
|
|
846
|
+
unitId != null ? unitId : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET).getUnitId()
|
|
744
847
|
);
|
|
745
|
-
|
|
848
|
+
renderUnit == null || renderUnit.with(SheetSkeletonManagerService).reCalculate(), (_a8 = renderUnit == null ? void 0 : renderUnit.mainComponent) == null || _a8.makeDirty();
|
|
746
849
|
}
|
|
747
850
|
_initCommands() {
|
|
748
851
|
[
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
].forEach((
|
|
757
|
-
this.disposeWithMe(this._commandService.registerCommand(
|
|
852
|
+
AddDecimalCommand,
|
|
853
|
+
SubtractDecimalCommand,
|
|
854
|
+
SetCurrencyCommand,
|
|
855
|
+
SetPercentCommand,
|
|
856
|
+
OpenNumfmtPanelOperator,
|
|
857
|
+
CloseNumfmtPanelOperator,
|
|
858
|
+
SetNumfmtCommand
|
|
859
|
+
].forEach((config) => {
|
|
860
|
+
this.disposeWithMe(this._commandService.registerCommand(config));
|
|
758
861
|
});
|
|
759
862
|
}
|
|
760
863
|
_initPanel() {
|
|
761
|
-
this._componentManager.register(
|
|
864
|
+
this._componentManager.register(SHEET_NUMFMT_PLUGIN, SheetNumfmtPanel);
|
|
762
865
|
}
|
|
763
866
|
_initRealTimeRenderingInterceptor() {
|
|
764
|
-
const
|
|
765
|
-
this._commandService.onCommandExecuted((
|
|
766
|
-
|
|
867
|
+
const isPanelOpenObserver = new Observable((subscriber) => {
|
|
868
|
+
this._commandService.onCommandExecuted((commandInfo) => {
|
|
869
|
+
commandInfo.id === OpenNumfmtPanelOperator.id && subscriber.next(!0), commandInfo.id === CloseNumfmtPanelOperator.id && subscriber.next(!1);
|
|
767
870
|
});
|
|
768
|
-
}),
|
|
769
|
-
|
|
871
|
+
}), combineOpenAndSelection$ = combineLatest([
|
|
872
|
+
isPanelOpenObserver,
|
|
770
873
|
this._selectionManagerService.selectionMoveEnd$.pipe(
|
|
771
|
-
|
|
874
|
+
map((selectionInfos) => selectionInfos ? selectionInfos.map((selectionInfo) => selectionInfo.range) : [])
|
|
772
875
|
)
|
|
773
876
|
]);
|
|
774
877
|
this.disposeWithMe(
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
([
|
|
779
|
-
const
|
|
780
|
-
return
|
|
781
|
-
|
|
878
|
+
toDisposable(
|
|
879
|
+
combineOpenAndSelection$.pipe(
|
|
880
|
+
switchMap$1(
|
|
881
|
+
([isOpen, selectionRanges]) => new Observable((subscribe) => {
|
|
882
|
+
const disposableCollection = new DisposableCollection();
|
|
883
|
+
return isOpen && selectionRanges.length && subscribe.next({ selectionRanges, disposableCollection }), () => {
|
|
884
|
+
disposableCollection.dispose();
|
|
782
885
|
};
|
|
783
886
|
})
|
|
784
887
|
),
|
|
785
|
-
|
|
888
|
+
tap(() => {
|
|
786
889
|
this._previewPattern = null;
|
|
787
890
|
})
|
|
788
|
-
).subscribe(({ disposableCollection
|
|
789
|
-
var
|
|
790
|
-
const
|
|
791
|
-
this.openPanel(),
|
|
792
|
-
this._sheetInterceptorService.intercept(
|
|
891
|
+
).subscribe(({ disposableCollection, selectionRanges }) => {
|
|
892
|
+
var _a8, _b;
|
|
893
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
894
|
+
this.openPanel(), disposableCollection.add(
|
|
895
|
+
this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
793
896
|
priority: 99,
|
|
794
|
-
handler: (
|
|
795
|
-
const { row
|
|
796
|
-
if (
|
|
797
|
-
(
|
|
897
|
+
handler: /* @__PURE__ */ __name((cell, location, next) => {
|
|
898
|
+
const { row, col } = location, defaultValue = next(cell) || {};
|
|
899
|
+
if (selectionRanges.find(
|
|
900
|
+
(range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row
|
|
798
901
|
)) {
|
|
799
|
-
const
|
|
800
|
-
if (
|
|
801
|
-
return
|
|
802
|
-
const
|
|
803
|
-
if (
|
|
804
|
-
const
|
|
902
|
+
const rawValue = location.worksheet.getCellRaw(row, col), value = rawValue == null ? void 0 : rawValue.v, type = rawValue == null ? void 0 : rawValue.t;
|
|
903
|
+
if (value == null || type !== CellValueType.NUMBER || this._previewPattern === null)
|
|
904
|
+
return defaultValue;
|
|
905
|
+
const info = getPatternPreview(this._previewPattern, value, this._localeService.getCurrentLocale());
|
|
906
|
+
if (info.color) {
|
|
907
|
+
const color = this._themeService.getCurrentTheme()[`${info.color}500`];
|
|
805
908
|
return {
|
|
806
|
-
...
|
|
807
|
-
v:
|
|
808
|
-
t:
|
|
809
|
-
s: { cl: { rgb:
|
|
909
|
+
...defaultValue,
|
|
910
|
+
v: info.result,
|
|
911
|
+
t: CellValueType.STRING,
|
|
912
|
+
s: { cl: { rgb: color } }
|
|
810
913
|
};
|
|
811
914
|
}
|
|
812
915
|
return {
|
|
813
|
-
...
|
|
814
|
-
v:
|
|
815
|
-
t:
|
|
916
|
+
...defaultValue,
|
|
917
|
+
v: info.result,
|
|
918
|
+
t: CellValueType.STRING
|
|
816
919
|
};
|
|
817
920
|
}
|
|
818
|
-
return
|
|
819
|
-
}
|
|
921
|
+
return defaultValue;
|
|
922
|
+
}, "handler")
|
|
820
923
|
})
|
|
821
|
-
), (
|
|
924
|
+
), (_b = (_a8 = this._renderManagerService.getRenderById(workbook.getUnitId())) == null ? void 0 : _a8.mainComponent) == null || _b.makeDirty();
|
|
822
925
|
})
|
|
823
926
|
)
|
|
824
927
|
);
|
|
825
928
|
}
|
|
826
929
|
_commandExecutedListener() {
|
|
827
|
-
const
|
|
930
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id];
|
|
828
931
|
this.disposeWithMe(
|
|
829
|
-
new
|
|
830
|
-
const
|
|
831
|
-
if (
|
|
832
|
-
const
|
|
833
|
-
|
|
932
|
+
new Observable((subscribe) => {
|
|
933
|
+
const disposable = this._commandService.onCommandExecuted((command) => {
|
|
934
|
+
if (commandList.includes(command.id)) {
|
|
935
|
+
const params = command.params;
|
|
936
|
+
subscribe.next(params.unitId);
|
|
834
937
|
}
|
|
835
938
|
});
|
|
836
|
-
return () =>
|
|
837
|
-
}).pipe(
|
|
939
|
+
return () => disposable.dispose();
|
|
940
|
+
}).pipe(debounceTime(16)).subscribe((unitId) => this._forceUpdate(unitId))
|
|
838
941
|
);
|
|
839
942
|
}
|
|
840
943
|
_initCloseListener() {
|
|
841
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
842
|
-
var
|
|
843
|
-
|
|
944
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
|
|
945
|
+
var _a8;
|
|
946
|
+
unit || ((_a8 = this._sidebarDisposable) == null || _a8.dispose(), this._sidebarDisposable = null);
|
|
844
947
|
});
|
|
845
948
|
}
|
|
846
|
-
};
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
],
|
|
860
|
-
var
|
|
861
|
-
for (var
|
|
862
|
-
(
|
|
863
|
-
return
|
|
864
|
-
},
|
|
865
|
-
const
|
|
866
|
-
let
|
|
949
|
+
}, __name(_a3, "NumfmtController"), _a3);
|
|
950
|
+
NumfmtController = __decorateClass$4([
|
|
951
|
+
OnLifecycle(LifecycleStages.Rendered, NumfmtController),
|
|
952
|
+
__decorateParam$4(0, Inject(SheetInterceptorService)),
|
|
953
|
+
__decorateParam$4(1, Inject(ThemeService)),
|
|
954
|
+
__decorateParam$4(2, IUniverInstanceService),
|
|
955
|
+
__decorateParam$4(3, ICommandService),
|
|
956
|
+
__decorateParam$4(4, Inject(SheetsSelectionsService)),
|
|
957
|
+
__decorateParam$4(5, IRenderManagerService),
|
|
958
|
+
__decorateParam$4(6, INumfmtService),
|
|
959
|
+
__decorateParam$4(7, Inject(ComponentManager)),
|
|
960
|
+
__decorateParam$4(8, ISidebarService),
|
|
961
|
+
__decorateParam$4(9, Inject(LocaleService))
|
|
962
|
+
], NumfmtController);
|
|
963
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
964
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
965
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
966
|
+
return kind && result && __defProp$3(target, key2, result), result;
|
|
967
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$3");
|
|
968
|
+
const createCollectEffectMutation = /* @__PURE__ */ __name(() => {
|
|
969
|
+
let list = [];
|
|
867
970
|
return {
|
|
868
|
-
add: (
|
|
869
|
-
getEffects: () =>
|
|
870
|
-
clean: () => {
|
|
871
|
-
|
|
872
|
-
}
|
|
971
|
+
add: /* @__PURE__ */ __name((unitId, subUnitId, row, col, value) => list.push({ unitId, subUnitId, row, col, value }), "add"),
|
|
972
|
+
getEffects: /* @__PURE__ */ __name(() => list, "getEffects"),
|
|
973
|
+
clean: /* @__PURE__ */ __name(() => {
|
|
974
|
+
list = [];
|
|
975
|
+
}, "clean")
|
|
873
976
|
};
|
|
874
|
-
};
|
|
875
|
-
|
|
876
|
-
|
|
977
|
+
}, "createCollectEffectMutation");
|
|
978
|
+
var _a4;
|
|
979
|
+
let NumfmtEditorController = (_a4 = class extends Disposable {
|
|
980
|
+
constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
|
|
877
981
|
super();
|
|
878
982
|
// collect effect mutations when edit end and push this to commands stack in next commands progress
|
|
879
|
-
|
|
880
|
-
this._sheetInterceptorService =
|
|
983
|
+
__publicField(this, "_collectEffectMutation", createCollectEffectMutation());
|
|
984
|
+
this._sheetInterceptorService = _sheetInterceptorService, this._numfmtService = _numfmtService, this._univerInstanceService = _univerInstanceService, this._injector = _injector, this._editorBridgeService = _editorBridgeService, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
|
|
881
985
|
}
|
|
882
986
|
_initInterceptorEditorStart() {
|
|
883
987
|
this._editorBridgeService && this.disposeWithMe(
|
|
884
|
-
|
|
988
|
+
toDisposable(
|
|
885
989
|
this._editorBridgeService.interceptor.intercept(
|
|
886
990
|
this._editorBridgeService.interceptor.getInterceptPoints().BEFORE_CELL_EDIT,
|
|
887
991
|
{
|
|
888
|
-
handler: (
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
992
|
+
handler: /* @__PURE__ */ __name((value, context, next) => {
|
|
993
|
+
const row = context.row, col = context.col, numfmtCell = this._numfmtService.getValue(
|
|
994
|
+
context.unitId,
|
|
995
|
+
context.subUnitId,
|
|
996
|
+
row,
|
|
997
|
+
col
|
|
894
998
|
);
|
|
895
|
-
if (
|
|
896
|
-
switch (
|
|
999
|
+
if (numfmtCell)
|
|
1000
|
+
switch (getPatternType(numfmtCell.pattern)) {
|
|
897
1001
|
case "scientific":
|
|
898
1002
|
case "percent":
|
|
899
1003
|
case "currency":
|
|
900
1004
|
case "grouped":
|
|
901
1005
|
case "number":
|
|
902
|
-
return
|
|
1006
|
+
return context.worksheet.getCellRaw(row, col);
|
|
903
1007
|
case "date":
|
|
904
1008
|
case "time":
|
|
905
1009
|
case "datetime":
|
|
906
1010
|
default:
|
|
907
|
-
return
|
|
1011
|
+
return next && next(value);
|
|
908
1012
|
}
|
|
909
|
-
return
|
|
910
|
-
}
|
|
1013
|
+
return next(value);
|
|
1014
|
+
}, "handler")
|
|
911
1015
|
}
|
|
912
1016
|
)
|
|
913
1017
|
)
|
|
@@ -920,108 +1024,108 @@ let ue = class extends K {
|
|
|
920
1024
|
*/
|
|
921
1025
|
_initInterceptorEditorEnd() {
|
|
922
1026
|
this._editorBridgeService && this.disposeWithMe(
|
|
923
|
-
|
|
1027
|
+
toDisposable(
|
|
924
1028
|
this._editorBridgeService.interceptor.intercept(
|
|
925
1029
|
this._editorBridgeService.interceptor.getInterceptPoints().AFTER_CELL_EDIT,
|
|
926
1030
|
{
|
|
927
|
-
handler: (
|
|
928
|
-
var
|
|
1031
|
+
handler: /* @__PURE__ */ __name((value, context, next) => {
|
|
1032
|
+
var _a8;
|
|
929
1033
|
this._collectEffectMutation.clean();
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
),
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1034
|
+
const currentNumfmtValue = this._numfmtService.getValue(
|
|
1035
|
+
context.unitId,
|
|
1036
|
+
context.subUnitId,
|
|
1037
|
+
context.row,
|
|
1038
|
+
context.col
|
|
1039
|
+
), currentNumfmtType = (_a8 = currentNumfmtValue && getPatternType(currentNumfmtValue.pattern)) != null ? _a8 : "", clean = /* @__PURE__ */ __name(() => {
|
|
1040
|
+
currentNumfmtValue && this._collectEffectMutation.add(
|
|
1041
|
+
context.unitId,
|
|
1042
|
+
context.subUnitId,
|
|
1043
|
+
context.row,
|
|
1044
|
+
context.col,
|
|
941
1045
|
null
|
|
942
1046
|
);
|
|
943
|
-
};
|
|
944
|
-
if (!(
|
|
945
|
-
return
|
|
946
|
-
const
|
|
947
|
-
if (!!
|
|
948
|
-
if (
|
|
949
|
-
const
|
|
1047
|
+
}, "clean");
|
|
1048
|
+
if (!(value != null && value.v))
|
|
1049
|
+
return next(value);
|
|
1050
|
+
const content = String(value.v), dateInfo = numfmt.parseDate(content) || numfmt.parseTime(content);
|
|
1051
|
+
if (!!dateInfo) {
|
|
1052
|
+
if (dateInfo && dateInfo.z) {
|
|
1053
|
+
const v = Number(dateInfo.v);
|
|
950
1054
|
return this._collectEffectMutation.add(
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
1055
|
+
context.unitId,
|
|
1056
|
+
context.subUnitId,
|
|
1057
|
+
context.row,
|
|
1058
|
+
context.col,
|
|
955
1059
|
{
|
|
956
|
-
pattern:
|
|
1060
|
+
pattern: dateInfo.z
|
|
957
1061
|
}
|
|
958
|
-
), { ...
|
|
1062
|
+
), { ...value, v, t: CellValueType.NUMBER };
|
|
959
1063
|
}
|
|
960
|
-
} else (["date", "time", "datetime"].includes(
|
|
961
|
-
return
|
|
962
|
-
}
|
|
1064
|
+
} else (["date", "time", "datetime"].includes(currentNumfmtType) || !isNumeric(content)) && clean();
|
|
1065
|
+
return next(value);
|
|
1066
|
+
}, "handler")
|
|
963
1067
|
}
|
|
964
1068
|
)
|
|
965
1069
|
)
|
|
966
1070
|
);
|
|
967
1071
|
}
|
|
968
1072
|
_initInterceptorCommands() {
|
|
969
|
-
const
|
|
1073
|
+
const self = this;
|
|
970
1074
|
this.disposeWithMe(
|
|
971
1075
|
this._sheetInterceptorService.interceptCommand({
|
|
972
|
-
getMutations(
|
|
973
|
-
var
|
|
974
|
-
switch (
|
|
975
|
-
case
|
|
976
|
-
const
|
|
977
|
-
if (!
|
|
1076
|
+
getMutations(command) {
|
|
1077
|
+
var _a8;
|
|
1078
|
+
switch (command.id) {
|
|
1079
|
+
case SetRangeValuesCommand.id: {
|
|
1080
|
+
const workbook = self._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), unitId = workbook.getUnitId(), subUnitId = (_a8 = workbook.getActiveSheet()) == null ? void 0 : _a8.getSheetId();
|
|
1081
|
+
if (!subUnitId)
|
|
978
1082
|
return {
|
|
979
1083
|
redos: [],
|
|
980
1084
|
undos: []
|
|
981
1085
|
};
|
|
982
|
-
const
|
|
983
|
-
if (!
|
|
1086
|
+
const list = self._collectEffectMutation.getEffects();
|
|
1087
|
+
if (!list.length)
|
|
984
1088
|
return {
|
|
985
1089
|
redos: [],
|
|
986
1090
|
undos: []
|
|
987
1091
|
};
|
|
988
|
-
const
|
|
989
|
-
var
|
|
990
|
-
return !!((
|
|
991
|
-
}).map((
|
|
992
|
-
row:
|
|
993
|
-
col:
|
|
994
|
-
pattern:
|
|
995
|
-
})),
|
|
996
|
-
var
|
|
997
|
-
return !((
|
|
998
|
-
}).map((
|
|
999
|
-
startRow:
|
|
1000
|
-
endColumn:
|
|
1001
|
-
startColumn:
|
|
1002
|
-
endRow:
|
|
1003
|
-
})),
|
|
1004
|
-
if (
|
|
1005
|
-
const
|
|
1006
|
-
id:
|
|
1007
|
-
params:
|
|
1092
|
+
const cells = list.filter((item) => {
|
|
1093
|
+
var _a9;
|
|
1094
|
+
return !!((_a9 = item.value) != null && _a9.pattern);
|
|
1095
|
+
}).map((item) => ({
|
|
1096
|
+
row: item.row,
|
|
1097
|
+
col: item.col,
|
|
1098
|
+
pattern: item.value.pattern
|
|
1099
|
+
})), removeCells = list.filter((item) => {
|
|
1100
|
+
var _a9;
|
|
1101
|
+
return !((_a9 = item.value) != null && _a9.pattern);
|
|
1102
|
+
}).map((item) => ({
|
|
1103
|
+
startRow: item.row,
|
|
1104
|
+
endColumn: item.col,
|
|
1105
|
+
startColumn: item.col,
|
|
1106
|
+
endRow: item.row
|
|
1107
|
+
})), redos = [], undos = [];
|
|
1108
|
+
if (cells) {
|
|
1109
|
+
const redo = {
|
|
1110
|
+
id: SetNumfmtMutation.id,
|
|
1111
|
+
params: transformCellsToRange(unitId, subUnitId, cells)
|
|
1008
1112
|
};
|
|
1009
|
-
|
|
1113
|
+
redos.push(redo), undos.push(...factorySetNumfmtUndoMutation(self._injector, redo.params));
|
|
1010
1114
|
}
|
|
1011
|
-
if (
|
|
1012
|
-
const
|
|
1013
|
-
id:
|
|
1115
|
+
if (removeCells) {
|
|
1116
|
+
const redo = {
|
|
1117
|
+
id: RemoveNumfmtMutation.id,
|
|
1014
1118
|
params: {
|
|
1015
|
-
unitId
|
|
1016
|
-
subUnitId
|
|
1017
|
-
ranges:
|
|
1119
|
+
unitId,
|
|
1120
|
+
subUnitId,
|
|
1121
|
+
ranges: removeCells
|
|
1018
1122
|
}
|
|
1019
1123
|
};
|
|
1020
|
-
|
|
1124
|
+
redos.push(redo), undos.push(...factoryRemoveNumfmtUndoMutation(self._injector, redo.params));
|
|
1021
1125
|
}
|
|
1022
1126
|
return {
|
|
1023
|
-
redos
|
|
1024
|
-
undos:
|
|
1127
|
+
redos,
|
|
1128
|
+
undos: undos.reverse()
|
|
1025
1129
|
};
|
|
1026
1130
|
}
|
|
1027
1131
|
}
|
|
@@ -1033,40 +1137,41 @@ let ue = class extends K {
|
|
|
1033
1137
|
})
|
|
1034
1138
|
);
|
|
1035
1139
|
}
|
|
1036
|
-
};
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
],
|
|
1045
|
-
function
|
|
1046
|
-
return /^-?\d+(\.\d+)?$/.test(
|
|
1140
|
+
}, __name(_a4, "NumfmtEditorController"), _a4);
|
|
1141
|
+
NumfmtEditorController = __decorateClass$3([
|
|
1142
|
+
OnLifecycle(LifecycleStages.Rendered, NumfmtEditorController),
|
|
1143
|
+
__decorateParam$3(0, Inject(SheetInterceptorService)),
|
|
1144
|
+
__decorateParam$3(1, Inject(INumfmtService)),
|
|
1145
|
+
__decorateParam$3(2, Inject(IUniverInstanceService)),
|
|
1146
|
+
__decorateParam$3(3, Inject(Injector)),
|
|
1147
|
+
__decorateParam$3(4, Optional(IEditorBridgeService))
|
|
1148
|
+
], NumfmtEditorController);
|
|
1149
|
+
function isNumeric(str) {
|
|
1150
|
+
return /^-?\d+(\.\d+)?$/.test(str);
|
|
1047
1151
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1152
|
+
__name(isNumeric, "isNumeric");
|
|
1153
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
1154
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1155
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1156
|
+
return kind && result && __defProp$2(target, key2, result), result;
|
|
1157
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$2"), _a5;
|
|
1158
|
+
let NumfmtI18nController = (_a5 = class extends Disposable {
|
|
1159
|
+
constructor(_localeService) {
|
|
1160
|
+
super(), this._localeService = _localeService;
|
|
1056
1161
|
}
|
|
1057
|
-
};
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
],
|
|
1062
|
-
const
|
|
1162
|
+
}, __name(_a5, "NumfmtI18nController"), _a5);
|
|
1163
|
+
NumfmtI18nController = __decorateClass$2([
|
|
1164
|
+
OnLifecycle(LifecycleStages.Rendered, NumfmtI18nController),
|
|
1165
|
+
__decorateParam$2(0, Inject(LocaleService))
|
|
1166
|
+
], NumfmtI18nController);
|
|
1167
|
+
const MENU_OPTIONS = [
|
|
1063
1168
|
{
|
|
1064
1169
|
label: "sheet.numfmt.general",
|
|
1065
1170
|
pattern: null
|
|
1066
1171
|
},
|
|
1067
1172
|
{
|
|
1068
1173
|
label: "sheet.numfmt.text",
|
|
1069
|
-
pattern:
|
|
1174
|
+
pattern: DEFAULT_TEXT_FORMAT
|
|
1070
1175
|
},
|
|
1071
1176
|
"|",
|
|
1072
1177
|
{
|
|
@@ -1112,185 +1217,186 @@ const de = [
|
|
|
1112
1217
|
label: "sheet.numfmt.moreFmt",
|
|
1113
1218
|
pattern: ""
|
|
1114
1219
|
}
|
|
1115
|
-
],
|
|
1116
|
-
var
|
|
1117
|
-
const
|
|
1118
|
-
return /* @__PURE__ */
|
|
1119
|
-
},
|
|
1120
|
-
const
|
|
1121
|
-
const
|
|
1122
|
-
if (!
|
|
1220
|
+
], MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType", OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options", MoreNumfmtType = /* @__PURE__ */ __name((props) => {
|
|
1221
|
+
var _a8;
|
|
1222
|
+
const localeService = useDependency(LocaleService), value = (_a8 = props.value) != null ? _a8 : localeService.t("sheet.numfmt.general");
|
|
1223
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "more-numfmt-type", children: value });
|
|
1224
|
+
}, "MoreNumfmtType"), Options = /* @__PURE__ */ __name(() => {
|
|
1225
|
+
const commandService = useDependency(ICommandService), localeService = useDependency(LocaleService), injector = useInjector(), selectionManagerService = useDependency(SheetsSelectionsService), setNumfmt = /* @__PURE__ */ __name((pattern) => {
|
|
1226
|
+
const selection = selectionManagerService.getCurrentLastSelection();
|
|
1227
|
+
if (!selection)
|
|
1123
1228
|
return;
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
}),
|
|
1128
|
-
},
|
|
1129
|
-
if (
|
|
1130
|
-
|
|
1131
|
-
else if (
|
|
1132
|
-
|
|
1229
|
+
const textSelectionRenderManager = injector.get(ITextSelectionRenderManager), range = selection.range, values = [];
|
|
1230
|
+
Range.foreach(range, (row, col) => {
|
|
1231
|
+
pattern ? values.push({ row, col, pattern, type: getPatternType(pattern) }) : values.push({ row, col });
|
|
1232
|
+
}), commandService.executeCommand(SetNumfmtCommand.id, { values }), textSelectionRenderManager.focus();
|
|
1233
|
+
}, "setNumfmt"), handleOnclick = /* @__PURE__ */ __name((index) => {
|
|
1234
|
+
if (index === 0)
|
|
1235
|
+
setNumfmt(null);
|
|
1236
|
+
else if (index === MENU_OPTIONS.length - 1)
|
|
1237
|
+
commandService.executeCommand(OpenNumfmtPanelOperator.id);
|
|
1133
1238
|
else {
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1239
|
+
const item = MENU_OPTIONS[index];
|
|
1240
|
+
item.pattern && setNumfmt(item.pattern);
|
|
1136
1241
|
}
|
|
1137
|
-
},
|
|
1138
|
-
return /* @__PURE__ */
|
|
1242
|
+
}, "handleOnclick"), defaultValue = 1220;
|
|
1243
|
+
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(
|
|
1139
1244
|
"div",
|
|
1140
1245
|
{
|
|
1141
1246
|
className: "option-item m-t-4",
|
|
1142
|
-
onClick: () => {
|
|
1143
|
-
|
|
1144
|
-
},
|
|
1247
|
+
onClick: /* @__PURE__ */ __name(() => {
|
|
1248
|
+
handleOnclick(index);
|
|
1249
|
+
}, "onClick"),
|
|
1145
1250
|
children: [
|
|
1146
|
-
/* @__PURE__ */
|
|
1147
|
-
/* @__PURE__ */
|
|
1251
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: localeService.t(item.label) }),
|
|
1252
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "m-l-26", children: item.pattern ? getPatternPreview(item.pattern || "", defaultValue, localeService.getCurrentLocale()).result : "" })
|
|
1148
1253
|
]
|
|
1149
1254
|
},
|
|
1150
|
-
|
|
1255
|
+
index
|
|
1151
1256
|
)) });
|
|
1152
|
-
},
|
|
1257
|
+
}, "Options"), CurrencyMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1153
1258
|
icon: "RmbSingle",
|
|
1154
|
-
id:
|
|
1259
|
+
id: SetCurrencyCommand.id,
|
|
1155
1260
|
title: "sheet.numfmt.currency",
|
|
1156
1261
|
tooltip: "sheet.numfmt.currency",
|
|
1157
|
-
type:
|
|
1158
|
-
group:
|
|
1159
|
-
positions: [
|
|
1160
|
-
hidden$:
|
|
1161
|
-
disabled$:
|
|
1162
|
-
}),
|
|
1262
|
+
type: MenuItemType.BUTTON,
|
|
1263
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1264
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1265
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1266
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1267
|
+
}), "CurrencyMenuItem"), AddDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1163
1268
|
icon: "AddDigitsSingle",
|
|
1164
|
-
id:
|
|
1269
|
+
id: AddDecimalCommand.id,
|
|
1165
1270
|
title: "sheet.numfmt.addDecimal",
|
|
1166
1271
|
tooltip: "sheet.numfmt.addDecimal",
|
|
1167
|
-
type:
|
|
1168
|
-
positions: [
|
|
1169
|
-
group:
|
|
1170
|
-
hidden$:
|
|
1171
|
-
disabled$:
|
|
1172
|
-
}),
|
|
1272
|
+
type: MenuItemType.BUTTON,
|
|
1273
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1274
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1275
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1276
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1277
|
+
}), "AddDecimalMenuItem"), SubtractDecimalMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1173
1278
|
icon: "ReduceDigitsSingle",
|
|
1174
|
-
id:
|
|
1279
|
+
id: SubtractDecimalCommand.id,
|
|
1175
1280
|
title: "sheet.numfmt.subtractDecimal",
|
|
1176
1281
|
tooltip: "sheet.numfmt.subtractDecimal",
|
|
1177
|
-
type:
|
|
1178
|
-
group:
|
|
1179
|
-
positions: [
|
|
1180
|
-
hidden$:
|
|
1181
|
-
disabled$:
|
|
1182
|
-
}),
|
|
1282
|
+
type: MenuItemType.BUTTON,
|
|
1283
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1284
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1285
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1286
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1287
|
+
}), "SubtractDecimalMenuItem"), PercentMenuItem = /* @__PURE__ */ __name((accessor) => ({
|
|
1183
1288
|
icon: "PercentSingle",
|
|
1184
|
-
id:
|
|
1289
|
+
id: SetPercentCommand.id,
|
|
1185
1290
|
title: "sheet.numfmt.percent",
|
|
1186
1291
|
tooltip: "sheet.numfmt.percent",
|
|
1187
|
-
type:
|
|
1188
|
-
group:
|
|
1189
|
-
positions: [
|
|
1190
|
-
hidden$:
|
|
1191
|
-
disabled$:
|
|
1192
|
-
}),
|
|
1193
|
-
const
|
|
1194
|
-
(
|
|
1195
|
-
|
|
1196
|
-
new
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1292
|
+
type: MenuItemType.BUTTON,
|
|
1293
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1294
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1295
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1296
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1297
|
+
}), "PercentMenuItem"), FactoryOtherMenuItem = /* @__PURE__ */ __name((accessor) => {
|
|
1298
|
+
const numfmtService = accessor.get(INumfmtService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), localeService = accessor.get(LocaleService), selectionManagerService = accessor.get(SheetsSelectionsService), value$ = deriveStateFromActiveSheet$(univerInstanceService, "", ({ workbook, worksheet }) => new Observable(
|
|
1299
|
+
(subscribe) => merge(
|
|
1300
|
+
selectionManagerService.selectionMoveEnd$,
|
|
1301
|
+
new Observable((commandSubscribe) => {
|
|
1302
|
+
const commandList = [RemoveNumfmtMutation.id, SetNumfmtMutation.id], disposable = commandService.onCommandExecuted((commandInfo) => {
|
|
1303
|
+
commandList.includes(commandInfo.id) && commandSubscribe.next(null);
|
|
1199
1304
|
});
|
|
1200
|
-
return () =>
|
|
1305
|
+
return () => disposable.dispose();
|
|
1201
1306
|
})
|
|
1202
1307
|
).subscribe(() => {
|
|
1203
|
-
const
|
|
1204
|
-
if (
|
|
1205
|
-
const
|
|
1206
|
-
let
|
|
1207
|
-
if (
|
|
1208
|
-
const
|
|
1209
|
-
(
|
|
1308
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
1309
|
+
if (selections && selections[0]) {
|
|
1310
|
+
const range = selections[0].range, row = range.startRow, col = range.startColumn, numfmtValue = numfmtService.getValue(workbook.getUnitId(), worksheet.getSheetId(), row, col), pattern = numfmtValue == null ? void 0 : numfmtValue.pattern;
|
|
1311
|
+
let value = localeService.t("sheet.numfmt.general");
|
|
1312
|
+
if (pattern) {
|
|
1313
|
+
const item = MENU_OPTIONS.filter((item2) => typeof item2 == "object" && item2.pattern).find(
|
|
1314
|
+
(item2) => isPatternEqualWithoutDecimal(pattern, item2.pattern)
|
|
1210
1315
|
);
|
|
1211
|
-
|
|
1316
|
+
item && typeof item == "object" && item.pattern ? value = localeService.t(item.label) : value = localeService.t("sheet.numfmt.moreFmt");
|
|
1212
1317
|
}
|
|
1213
|
-
|
|
1318
|
+
subscribe.next(value);
|
|
1214
1319
|
}
|
|
1215
1320
|
})
|
|
1216
1321
|
));
|
|
1217
1322
|
return {
|
|
1218
|
-
label:
|
|
1219
|
-
id:
|
|
1323
|
+
label: MORE_NUMFMT_TYPE_KEY,
|
|
1324
|
+
id: OpenNumfmtPanelOperator.id,
|
|
1220
1325
|
tooltip: "sheet.numfmt.title",
|
|
1221
|
-
type:
|
|
1222
|
-
group:
|
|
1223
|
-
positions: [
|
|
1326
|
+
type: MenuItemType.SELECTOR,
|
|
1327
|
+
group: MenuGroup.TOOLBAR_FORMULAS_INSERT,
|
|
1328
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
1224
1329
|
selections: [
|
|
1225
1330
|
{
|
|
1226
1331
|
label: {
|
|
1227
|
-
name:
|
|
1332
|
+
name: OPTIONS_KEY,
|
|
1228
1333
|
hoverable: !1
|
|
1229
1334
|
}
|
|
1230
1335
|
}
|
|
1231
1336
|
],
|
|
1232
|
-
value
|
|
1233
|
-
hidden$:
|
|
1234
|
-
disabled$:
|
|
1337
|
+
value$,
|
|
1338
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
1339
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetSetCellStylePermission, WorksheetEditPermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
1235
1340
|
};
|
|
1236
|
-
};
|
|
1237
|
-
var
|
|
1238
|
-
for (var
|
|
1239
|
-
(
|
|
1240
|
-
return
|
|
1241
|
-
},
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1341
|
+
}, "FactoryOtherMenuItem");
|
|
1342
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key2, kind) => {
|
|
1343
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1344
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1345
|
+
return kind && result && __defProp$1(target, key2, result), result;
|
|
1346
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key2) => decorator(target, key2, index), "__decorateParam$1");
|
|
1347
|
+
const DefaultSheetNumfmtConfig = {};
|
|
1348
|
+
var _a6;
|
|
1349
|
+
let NumfmtMenuController = (_a6 = class extends Disposable {
|
|
1350
|
+
constructor(_config, _injector, _componentManager, _menuService) {
|
|
1351
|
+
super(), this._config = _config, this._injector = _injector, this._componentManager = _componentManager, this._menuService = _menuService, this._initMenu();
|
|
1246
1352
|
}
|
|
1247
1353
|
_initMenu() {
|
|
1248
|
-
const { menu
|
|
1249
|
-
[
|
|
1250
|
-
this.disposeWithMe(this._menuService.addMenuItem(
|
|
1251
|
-
}), this.disposeWithMe(this._componentManager.register(
|
|
1354
|
+
const { menu = {} } = this._config;
|
|
1355
|
+
[PercentMenuItem, AddDecimalMenuItem, SubtractDecimalMenuItem, CurrencyMenuItem, FactoryOtherMenuItem].forEach((factory) => {
|
|
1356
|
+
this.disposeWithMe(this._menuService.addMenuItem(factory(this._injector), menu));
|
|
1357
|
+
}), this.disposeWithMe(this._componentManager.register(MORE_NUMFMT_TYPE_KEY, MoreNumfmtType)), this.disposeWithMe(this._componentManager.register(OPTIONS_KEY, Options));
|
|
1252
1358
|
}
|
|
1253
|
-
};
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
],
|
|
1260
|
-
var
|
|
1261
|
-
for (var
|
|
1262
|
-
(
|
|
1263
|
-
return
|
|
1264
|
-
},
|
|
1265
|
-
let
|
|
1266
|
-
constructor(
|
|
1267
|
-
super(), this._config =
|
|
1359
|
+
}, __name(_a6, "NumfmtMenuController"), _a6);
|
|
1360
|
+
NumfmtMenuController = __decorateClass$1([
|
|
1361
|
+
OnLifecycle(LifecycleStages.Rendered, NumfmtMenuController),
|
|
1362
|
+
__decorateParam$1(1, Inject(Injector)),
|
|
1363
|
+
__decorateParam$1(2, Inject(ComponentManager)),
|
|
1364
|
+
__decorateParam$1(3, Inject(IMenuService))
|
|
1365
|
+
], NumfmtMenuController);
|
|
1366
|
+
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) => {
|
|
1367
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key2) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1368
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key2, result) : decorator(result)) || result);
|
|
1369
|
+
return kind && result && __defProp2(target, key2, result), result;
|
|
1370
|
+
}, "__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"), _a7;
|
|
1371
|
+
let UniverSheetsNumfmtPlugin = (_a7 = class extends Plugin {
|
|
1372
|
+
constructor(_config = {}, _injector) {
|
|
1373
|
+
super(), this._config = _config, this._injector = _injector, this._config = Tools.deepMerge({}, DefaultSheetNumfmtConfig, this._config);
|
|
1268
1374
|
}
|
|
1269
1375
|
onStarting() {
|
|
1270
|
-
this._injector.add([
|
|
1376
|
+
this._injector.add([INumfmtController, { useClass: NumfmtController, lazy: !1 }]), this._injector.add([NumfmtEditorController]), this._injector.add([UserHabitController]), this._injector.add([SheetsNumfmtCellContentController]), this._injector.add([NumfmtI18nController]), this._injector.add(
|
|
1271
1377
|
[
|
|
1272
|
-
|
|
1378
|
+
NumfmtMenuController,
|
|
1273
1379
|
{
|
|
1274
|
-
useFactory: () => this._injector.createInstance(
|
|
1380
|
+
useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(NumfmtMenuController, this._config), "useFactory")
|
|
1275
1381
|
}
|
|
1276
1382
|
]
|
|
1277
1383
|
);
|
|
1278
1384
|
}
|
|
1279
|
-
};
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
],
|
|
1385
|
+
}, __name(_a7, "UniverSheetsNumfmtPlugin"), _a7);
|
|
1386
|
+
__publicField2(UniverSheetsNumfmtPlugin, "pluginName", SHEET_NUMFMT_PLUGIN);
|
|
1387
|
+
__publicField2(UniverSheetsNumfmtPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
1388
|
+
UniverSheetsNumfmtPlugin = __decorateClass([
|
|
1389
|
+
DependentOn(UniverSheetsPlugin, UniverSheetsUIPlugin),
|
|
1390
|
+
__decorateParam(1, Inject(Injector))
|
|
1391
|
+
], UniverSheetsNumfmtPlugin);
|
|
1286
1392
|
export {
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1393
|
+
AddDecimalCommand,
|
|
1394
|
+
CloseNumfmtPanelOperator,
|
|
1395
|
+
OpenNumfmtPanelOperator,
|
|
1396
|
+
SetCurrencyCommand,
|
|
1397
|
+
SetNumfmtCommand,
|
|
1398
|
+
SetPercentCommand,
|
|
1399
|
+
SubtractDecimalCommand,
|
|
1400
|
+
UniverSheetsNumfmtPlugin,
|
|
1401
|
+
getPatternPreview
|
|
1296
1402
|
};
|