@univerjs/sheets-numfmt 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +135 -14
- package/lib/es/index.js +134 -13
- package/lib/index.js +134 -13
- package/lib/types/base/const/date-format.d.ts +17 -0
- package/lib/types/utils/options.d.ts +2 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -644,7 +644,7 @@ const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
|
|
|
644
644
|
const defaultPluginConfig = {};
|
|
645
645
|
|
|
646
646
|
//#endregion
|
|
647
|
-
//#region \0@oxc-project+runtime@0.
|
|
647
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
648
648
|
function _typeof(o) {
|
|
649
649
|
"@babel/helpers - typeof";
|
|
650
650
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -655,7 +655,7 @@ function _typeof(o) {
|
|
|
655
655
|
}
|
|
656
656
|
|
|
657
657
|
//#endregion
|
|
658
|
-
//#region \0@oxc-project+runtime@0.
|
|
658
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
659
659
|
function toPrimitive(t, r) {
|
|
660
660
|
if ("object" != _typeof(t) || !t) return t;
|
|
661
661
|
var e = t[Symbol.toPrimitive];
|
|
@@ -668,14 +668,14 @@ function toPrimitive(t, r) {
|
|
|
668
668
|
}
|
|
669
669
|
|
|
670
670
|
//#endregion
|
|
671
|
-
//#region \0@oxc-project+runtime@0.
|
|
671
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
672
672
|
function toPropertyKey(t) {
|
|
673
673
|
var i = toPrimitive(t, "string");
|
|
674
674
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
675
675
|
}
|
|
676
676
|
|
|
677
677
|
//#endregion
|
|
678
|
-
//#region \0@oxc-project+runtime@0.
|
|
678
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
679
679
|
function _defineProperty(e, r, t) {
|
|
680
680
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
681
681
|
value: t,
|
|
@@ -686,7 +686,7 @@ function _defineProperty(e, r, t) {
|
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
//#endregion
|
|
689
|
-
//#region \0@oxc-project+runtime@0.
|
|
689
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
690
690
|
function __decorateParam(paramIndex, decorator) {
|
|
691
691
|
return function(target, key) {
|
|
692
692
|
decorator(target, key, paramIndex);
|
|
@@ -694,7 +694,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
694
694
|
}
|
|
695
695
|
|
|
696
696
|
//#endregion
|
|
697
|
-
//#region \0@oxc-project+runtime@0.
|
|
697
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
698
698
|
function __decorate(decorators, target, key, desc) {
|
|
699
699
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
700
700
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -832,7 +832,7 @@ SheetsNumfmtCellContentController = __decorate([
|
|
|
832
832
|
//#endregion
|
|
833
833
|
//#region package.json
|
|
834
834
|
var name = "@univerjs/sheets-numfmt";
|
|
835
|
-
var version = "1.0
|
|
835
|
+
var version = "1.1.0";
|
|
836
836
|
|
|
837
837
|
//#endregion
|
|
838
838
|
//#region src/base/const/plugin-name.ts
|
|
@@ -912,7 +912,7 @@ const getCurrencyType = (pattern) => {
|
|
|
912
912
|
};
|
|
913
913
|
|
|
914
914
|
//#endregion
|
|
915
|
-
//#region src/
|
|
915
|
+
//#region src/base/const/date-format.ts
|
|
916
916
|
/**
|
|
917
917
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
918
918
|
*
|
|
@@ -928,6 +928,117 @@ const getCurrencyType = (pattern) => {
|
|
|
928
928
|
* See the License for the specific language governing permissions and
|
|
929
929
|
* limitations under the License.
|
|
930
930
|
*/
|
|
931
|
+
const ISO_DATE_PROFILE = {
|
|
932
|
+
dates: ["yyyy/MM/dd", "MM-dd"],
|
|
933
|
+
shortDate: "MM-dd"
|
|
934
|
+
};
|
|
935
|
+
const MDY_DATE_PROFILE = {
|
|
936
|
+
dates: [
|
|
937
|
+
"m/d/yyyy",
|
|
938
|
+
"mm/dd/yyyy",
|
|
939
|
+
"mmm d, yyyy",
|
|
940
|
+
"m/d",
|
|
941
|
+
"mmmm d"
|
|
942
|
+
],
|
|
943
|
+
shortDate: "m/d"
|
|
944
|
+
};
|
|
945
|
+
const DMY_DATE_PROFILE = {
|
|
946
|
+
dates: [
|
|
947
|
+
"dd/mm/yyyy",
|
|
948
|
+
"d/m/yyyy",
|
|
949
|
+
"d mmm yyyy",
|
|
950
|
+
"dd/mm",
|
|
951
|
+
"d mmmm"
|
|
952
|
+
],
|
|
953
|
+
shortDate: "dd/mm"
|
|
954
|
+
};
|
|
955
|
+
const DMY_DOT_DATE_PROFILE = {
|
|
956
|
+
dates: [
|
|
957
|
+
"dd.mm.yyyy",
|
|
958
|
+
"d.m.yyyy",
|
|
959
|
+
"d mmm yyyy",
|
|
960
|
+
"dd.mm",
|
|
961
|
+
"d mmmm"
|
|
962
|
+
],
|
|
963
|
+
shortDate: "dd.mm"
|
|
964
|
+
};
|
|
965
|
+
const CJK_DATE_PROFILE = {
|
|
966
|
+
dates: [
|
|
967
|
+
"yyyy/MM/dd",
|
|
968
|
+
"yyyy\"年\"MM\"月\"dd\"日\"",
|
|
969
|
+
"MM-dd",
|
|
970
|
+
"M\"月\"d\"日\""
|
|
971
|
+
],
|
|
972
|
+
shortDate: "MM-dd",
|
|
973
|
+
periodBeforeTime: true
|
|
974
|
+
};
|
|
975
|
+
const DATE_FORMAT_PROFILES = {
|
|
976
|
+
[_univerjs_core.LocaleType.EN_US]: MDY_DATE_PROFILE,
|
|
977
|
+
[_univerjs_core.LocaleType.FR_FR]: DMY_DATE_PROFILE,
|
|
978
|
+
[_univerjs_core.LocaleType.ZH_CN]: CJK_DATE_PROFILE,
|
|
979
|
+
[_univerjs_core.LocaleType.RU_RU]: DMY_DOT_DATE_PROFILE,
|
|
980
|
+
[_univerjs_core.LocaleType.ZH_TW]: CJK_DATE_PROFILE,
|
|
981
|
+
[_univerjs_core.LocaleType.ZH_HK]: {
|
|
982
|
+
...CJK_DATE_PROFILE,
|
|
983
|
+
dates: ["dd/MM/yyyy", ...CJK_DATE_PROFILE.dates],
|
|
984
|
+
shortDate: "dd/MM"
|
|
985
|
+
},
|
|
986
|
+
[_univerjs_core.LocaleType.VI_VN]: DMY_DATE_PROFILE,
|
|
987
|
+
[_univerjs_core.LocaleType.FA_IR]: ISO_DATE_PROFILE,
|
|
988
|
+
[_univerjs_core.LocaleType.CA_ES]: {
|
|
989
|
+
dates: [
|
|
990
|
+
"dd/mm/yyyy",
|
|
991
|
+
"d/m/yyyy",
|
|
992
|
+
"dd/mm"
|
|
993
|
+
],
|
|
994
|
+
shortDate: "dd/mm"
|
|
995
|
+
},
|
|
996
|
+
[_univerjs_core.LocaleType.JA_JP]: CJK_DATE_PROFILE,
|
|
997
|
+
[_univerjs_core.LocaleType.KO_KR]: {
|
|
998
|
+
dates: [
|
|
999
|
+
"yyyy. mm. dd.",
|
|
1000
|
+
"yyyy\"년\" m\"월\" d\"일\"",
|
|
1001
|
+
"mm-dd",
|
|
1002
|
+
"m\"월\" d\"일\""
|
|
1003
|
+
],
|
|
1004
|
+
shortDate: "mm-dd",
|
|
1005
|
+
periodBeforeTime: true
|
|
1006
|
+
},
|
|
1007
|
+
[_univerjs_core.LocaleType.ES_ES]: DMY_DATE_PROFILE,
|
|
1008
|
+
[_univerjs_core.LocaleType.SK_SK]: DMY_DOT_DATE_PROFILE,
|
|
1009
|
+
[_univerjs_core.LocaleType.PT_BR]: DMY_DATE_PROFILE,
|
|
1010
|
+
[_univerjs_core.LocaleType.DE_DE]: DMY_DOT_DATE_PROFILE,
|
|
1011
|
+
[_univerjs_core.LocaleType.IT_IT]: DMY_DATE_PROFILE,
|
|
1012
|
+
[_univerjs_core.LocaleType.ID_ID]: DMY_DATE_PROFILE,
|
|
1013
|
+
[_univerjs_core.LocaleType.PL_PL]: DMY_DOT_DATE_PROFILE,
|
|
1014
|
+
[_univerjs_core.LocaleType.AR_SA]: {
|
|
1015
|
+
dates: [
|
|
1016
|
+
"dd/mm/yyyy",
|
|
1017
|
+
"d/m/yyyy",
|
|
1018
|
+
"dd/mm"
|
|
1019
|
+
],
|
|
1020
|
+
shortDate: "dd/mm"
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
function getDateFormatPatterns(locale) {
|
|
1024
|
+
const profile = DATE_FORMAT_PROFILES[locale] ?? ISO_DATE_PROFILE;
|
|
1025
|
+
const timePatterns = [
|
|
1026
|
+
"hh:mm",
|
|
1027
|
+
"h:mm",
|
|
1028
|
+
"h:mm:ss"
|
|
1029
|
+
].map((pattern) => profile.periodBeforeTime ? `AM/PM ${pattern}` : `${pattern} AM/PM`);
|
|
1030
|
+
return [.../* @__PURE__ */ new Set([
|
|
1031
|
+
"yyyy-MM-dd",
|
|
1032
|
+
...profile.dates,
|
|
1033
|
+
"h:mm:ss",
|
|
1034
|
+
"h:mm",
|
|
1035
|
+
...timePatterns,
|
|
1036
|
+
`${profile.shortDate} ${timePatterns[0]}`
|
|
1037
|
+
])];
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region src/utils/options.ts
|
|
931
1042
|
const getCurrencyOptions = () => _univerjs_core.currencySymbols.map((item) => ({
|
|
932
1043
|
label: item,
|
|
933
1044
|
value: item
|
|
@@ -937,10 +1048,20 @@ const getCurrencyFormatOptions = (suffix) => CURRENCYFORMAT.map((item) => ({
|
|
|
937
1048
|
value: item.suffix(suffix),
|
|
938
1049
|
color: item.color
|
|
939
1050
|
}));
|
|
940
|
-
const
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
1051
|
+
const DATE_FORMAT_PREVIEW_VALUE = (0, _univerjs_core.excelDateTimeSerial)(new Date(Date.UTC(1930, 7, 5, 13, 30, 30)));
|
|
1052
|
+
const getDateFormatOptions = (locale, currentPattern) => {
|
|
1053
|
+
if (locale === void 0) return DATEFMTLISG.map((item) => ({
|
|
1054
|
+
label: item.label,
|
|
1055
|
+
value: item.suffix
|
|
1056
|
+
}));
|
|
1057
|
+
const numfmtLocale = (0, _univerjs_core.getNumfmtLocaleTag)(locale);
|
|
1058
|
+
const patterns = getDateFormatPatterns(locale);
|
|
1059
|
+
if (currentPattern && !patterns.includes(currentPattern)) patterns.unshift(currentPattern);
|
|
1060
|
+
return patterns.map((pattern) => ({
|
|
1061
|
+
label: _univerjs_core.numfmt.format(pattern, DATE_FORMAT_PREVIEW_VALUE, { locale: numfmtLocale }),
|
|
1062
|
+
value: pattern
|
|
1063
|
+
}));
|
|
1064
|
+
};
|
|
944
1065
|
const getNumberFormatOptions = () => NUMBERFORMAT.map((item) => ({
|
|
945
1066
|
label: item.label,
|
|
946
1067
|
value: item.suffix,
|
|
@@ -956,14 +1077,14 @@ exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY = SHEETS_NUMFMT_PLUGIN_CONFIG_KEY;
|
|
|
956
1077
|
exports.SetCurrencyCommand = SetCurrencyCommand;
|
|
957
1078
|
exports.SetNumfmtCommand = SetNumfmtCommand;
|
|
958
1079
|
exports.SetPercentCommand = SetPercentCommand;
|
|
959
|
-
Object.defineProperty(exports,
|
|
1080
|
+
Object.defineProperty(exports, "SheetsNumfmtCellContentController", {
|
|
960
1081
|
enumerable: true,
|
|
961
1082
|
get: function () {
|
|
962
1083
|
return SheetsNumfmtCellContentController;
|
|
963
1084
|
}
|
|
964
1085
|
});
|
|
965
1086
|
exports.SubtractDecimalCommand = SubtractDecimalCommand;
|
|
966
|
-
Object.defineProperty(exports,
|
|
1087
|
+
Object.defineProperty(exports, "UniverSheetsNumfmtPlugin", {
|
|
967
1088
|
enumerable: true,
|
|
968
1089
|
get: function () {
|
|
969
1090
|
return UniverSheetsNumfmtPlugin;
|
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CellValueType, CommandType, DEFAULT_NUMBER_FORMAT, DependentOn, Disposable, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, LocaleType, ObjectMatrix, Plugin, Range, RegionService, ThemeService, UniverInstanceType, currencySymbols, getNumfmtLocaleTag, getNumfmtParseValueFilter, isDefaultFormat, isTextFormat, merge, numfmt, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
|
|
1
|
+
import { CellValueType, CommandType, DEFAULT_NUMBER_FORMAT, DependentOn, Disposable, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, LocaleType, ObjectMatrix, Plugin, Range, RegionService, ThemeService, UniverInstanceType, currencySymbols, excelDateTimeSerial, getNumfmtLocaleTag, getNumfmtParseValueFilter, isDefaultFormat, isTextFormat, merge, numfmt, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import { INTERCEPTOR_POINT, INumfmtService, InterceptCellContentPriority, RemoveNumfmtMutation, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, checkCellValueType, factoryRemoveNumfmtUndoMutation, factorySetNumfmtUndoMutation, getSheetCommandTarget, rangeMerge, transformCellsToRange } from "@univerjs/sheets";
|
|
3
3
|
import { stripErrorMargin } from "@univerjs/engine-formula";
|
|
4
4
|
import { BehaviorSubject, merge as merge$1, of, skip, switchMap } from "rxjs";
|
|
@@ -643,7 +643,7 @@ const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
|
|
|
643
643
|
const defaultPluginConfig = {};
|
|
644
644
|
|
|
645
645
|
//#endregion
|
|
646
|
-
//#region \0@oxc-project+runtime@0.
|
|
646
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
647
647
|
function _typeof(o) {
|
|
648
648
|
"@babel/helpers - typeof";
|
|
649
649
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -654,7 +654,7 @@ function _typeof(o) {
|
|
|
654
654
|
}
|
|
655
655
|
|
|
656
656
|
//#endregion
|
|
657
|
-
//#region \0@oxc-project+runtime@0.
|
|
657
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
658
658
|
function toPrimitive(t, r) {
|
|
659
659
|
if ("object" != _typeof(t) || !t) return t;
|
|
660
660
|
var e = t[Symbol.toPrimitive];
|
|
@@ -667,14 +667,14 @@ function toPrimitive(t, r) {
|
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
//#endregion
|
|
670
|
-
//#region \0@oxc-project+runtime@0.
|
|
670
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
671
671
|
function toPropertyKey(t) {
|
|
672
672
|
var i = toPrimitive(t, "string");
|
|
673
673
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
674
674
|
}
|
|
675
675
|
|
|
676
676
|
//#endregion
|
|
677
|
-
//#region \0@oxc-project+runtime@0.
|
|
677
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
678
678
|
function _defineProperty(e, r, t) {
|
|
679
679
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
680
680
|
value: t,
|
|
@@ -685,7 +685,7 @@ function _defineProperty(e, r, t) {
|
|
|
685
685
|
}
|
|
686
686
|
|
|
687
687
|
//#endregion
|
|
688
|
-
//#region \0@oxc-project+runtime@0.
|
|
688
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
689
689
|
function __decorateParam(paramIndex, decorator) {
|
|
690
690
|
return function(target, key) {
|
|
691
691
|
decorator(target, key, paramIndex);
|
|
@@ -693,7 +693,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
693
693
|
}
|
|
694
694
|
|
|
695
695
|
//#endregion
|
|
696
|
-
//#region \0@oxc-project+runtime@0.
|
|
696
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
697
697
|
function __decorate(decorators, target, key, desc) {
|
|
698
698
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
699
699
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -831,7 +831,7 @@ SheetsNumfmtCellContentController = __decorate([
|
|
|
831
831
|
//#endregion
|
|
832
832
|
//#region package.json
|
|
833
833
|
var name = "@univerjs/sheets-numfmt";
|
|
834
|
-
var version = "1.0
|
|
834
|
+
var version = "1.1.0";
|
|
835
835
|
|
|
836
836
|
//#endregion
|
|
837
837
|
//#region src/base/const/plugin-name.ts
|
|
@@ -911,7 +911,7 @@ const getCurrencyType = (pattern) => {
|
|
|
911
911
|
};
|
|
912
912
|
|
|
913
913
|
//#endregion
|
|
914
|
-
//#region src/
|
|
914
|
+
//#region src/base/const/date-format.ts
|
|
915
915
|
/**
|
|
916
916
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
917
917
|
*
|
|
@@ -927,6 +927,117 @@ const getCurrencyType = (pattern) => {
|
|
|
927
927
|
* See the License for the specific language governing permissions and
|
|
928
928
|
* limitations under the License.
|
|
929
929
|
*/
|
|
930
|
+
const ISO_DATE_PROFILE = {
|
|
931
|
+
dates: ["yyyy/MM/dd", "MM-dd"],
|
|
932
|
+
shortDate: "MM-dd"
|
|
933
|
+
};
|
|
934
|
+
const MDY_DATE_PROFILE = {
|
|
935
|
+
dates: [
|
|
936
|
+
"m/d/yyyy",
|
|
937
|
+
"mm/dd/yyyy",
|
|
938
|
+
"mmm d, yyyy",
|
|
939
|
+
"m/d",
|
|
940
|
+
"mmmm d"
|
|
941
|
+
],
|
|
942
|
+
shortDate: "m/d"
|
|
943
|
+
};
|
|
944
|
+
const DMY_DATE_PROFILE = {
|
|
945
|
+
dates: [
|
|
946
|
+
"dd/mm/yyyy",
|
|
947
|
+
"d/m/yyyy",
|
|
948
|
+
"d mmm yyyy",
|
|
949
|
+
"dd/mm",
|
|
950
|
+
"d mmmm"
|
|
951
|
+
],
|
|
952
|
+
shortDate: "dd/mm"
|
|
953
|
+
};
|
|
954
|
+
const DMY_DOT_DATE_PROFILE = {
|
|
955
|
+
dates: [
|
|
956
|
+
"dd.mm.yyyy",
|
|
957
|
+
"d.m.yyyy",
|
|
958
|
+
"d mmm yyyy",
|
|
959
|
+
"dd.mm",
|
|
960
|
+
"d mmmm"
|
|
961
|
+
],
|
|
962
|
+
shortDate: "dd.mm"
|
|
963
|
+
};
|
|
964
|
+
const CJK_DATE_PROFILE = {
|
|
965
|
+
dates: [
|
|
966
|
+
"yyyy/MM/dd",
|
|
967
|
+
"yyyy\"年\"MM\"月\"dd\"日\"",
|
|
968
|
+
"MM-dd",
|
|
969
|
+
"M\"月\"d\"日\""
|
|
970
|
+
],
|
|
971
|
+
shortDate: "MM-dd",
|
|
972
|
+
periodBeforeTime: true
|
|
973
|
+
};
|
|
974
|
+
const DATE_FORMAT_PROFILES = {
|
|
975
|
+
[LocaleType.EN_US]: MDY_DATE_PROFILE,
|
|
976
|
+
[LocaleType.FR_FR]: DMY_DATE_PROFILE,
|
|
977
|
+
[LocaleType.ZH_CN]: CJK_DATE_PROFILE,
|
|
978
|
+
[LocaleType.RU_RU]: DMY_DOT_DATE_PROFILE,
|
|
979
|
+
[LocaleType.ZH_TW]: CJK_DATE_PROFILE,
|
|
980
|
+
[LocaleType.ZH_HK]: {
|
|
981
|
+
...CJK_DATE_PROFILE,
|
|
982
|
+
dates: ["dd/MM/yyyy", ...CJK_DATE_PROFILE.dates],
|
|
983
|
+
shortDate: "dd/MM"
|
|
984
|
+
},
|
|
985
|
+
[LocaleType.VI_VN]: DMY_DATE_PROFILE,
|
|
986
|
+
[LocaleType.FA_IR]: ISO_DATE_PROFILE,
|
|
987
|
+
[LocaleType.CA_ES]: {
|
|
988
|
+
dates: [
|
|
989
|
+
"dd/mm/yyyy",
|
|
990
|
+
"d/m/yyyy",
|
|
991
|
+
"dd/mm"
|
|
992
|
+
],
|
|
993
|
+
shortDate: "dd/mm"
|
|
994
|
+
},
|
|
995
|
+
[LocaleType.JA_JP]: CJK_DATE_PROFILE,
|
|
996
|
+
[LocaleType.KO_KR]: {
|
|
997
|
+
dates: [
|
|
998
|
+
"yyyy. mm. dd.",
|
|
999
|
+
"yyyy\"년\" m\"월\" d\"일\"",
|
|
1000
|
+
"mm-dd",
|
|
1001
|
+
"m\"월\" d\"일\""
|
|
1002
|
+
],
|
|
1003
|
+
shortDate: "mm-dd",
|
|
1004
|
+
periodBeforeTime: true
|
|
1005
|
+
},
|
|
1006
|
+
[LocaleType.ES_ES]: DMY_DATE_PROFILE,
|
|
1007
|
+
[LocaleType.SK_SK]: DMY_DOT_DATE_PROFILE,
|
|
1008
|
+
[LocaleType.PT_BR]: DMY_DATE_PROFILE,
|
|
1009
|
+
[LocaleType.DE_DE]: DMY_DOT_DATE_PROFILE,
|
|
1010
|
+
[LocaleType.IT_IT]: DMY_DATE_PROFILE,
|
|
1011
|
+
[LocaleType.ID_ID]: DMY_DATE_PROFILE,
|
|
1012
|
+
[LocaleType.PL_PL]: DMY_DOT_DATE_PROFILE,
|
|
1013
|
+
[LocaleType.AR_SA]: {
|
|
1014
|
+
dates: [
|
|
1015
|
+
"dd/mm/yyyy",
|
|
1016
|
+
"d/m/yyyy",
|
|
1017
|
+
"dd/mm"
|
|
1018
|
+
],
|
|
1019
|
+
shortDate: "dd/mm"
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
function getDateFormatPatterns(locale) {
|
|
1023
|
+
const profile = DATE_FORMAT_PROFILES[locale] ?? ISO_DATE_PROFILE;
|
|
1024
|
+
const timePatterns = [
|
|
1025
|
+
"hh:mm",
|
|
1026
|
+
"h:mm",
|
|
1027
|
+
"h:mm:ss"
|
|
1028
|
+
].map((pattern) => profile.periodBeforeTime ? `AM/PM ${pattern}` : `${pattern} AM/PM`);
|
|
1029
|
+
return [.../* @__PURE__ */ new Set([
|
|
1030
|
+
"yyyy-MM-dd",
|
|
1031
|
+
...profile.dates,
|
|
1032
|
+
"h:mm:ss",
|
|
1033
|
+
"h:mm",
|
|
1034
|
+
...timePatterns,
|
|
1035
|
+
`${profile.shortDate} ${timePatterns[0]}`
|
|
1036
|
+
])];
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
//#endregion
|
|
1040
|
+
//#region src/utils/options.ts
|
|
930
1041
|
const getCurrencyOptions = () => currencySymbols.map((item) => ({
|
|
931
1042
|
label: item,
|
|
932
1043
|
value: item
|
|
@@ -936,10 +1047,20 @@ const getCurrencyFormatOptions = (suffix) => CURRENCYFORMAT.map((item) => ({
|
|
|
936
1047
|
value: item.suffix(suffix),
|
|
937
1048
|
color: item.color
|
|
938
1049
|
}));
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1050
|
+
const DATE_FORMAT_PREVIEW_VALUE = excelDateTimeSerial(new Date(Date.UTC(1930, 7, 5, 13, 30, 30)));
|
|
1051
|
+
const getDateFormatOptions = (locale, currentPattern) => {
|
|
1052
|
+
if (locale === void 0) return DATEFMTLISG.map((item) => ({
|
|
1053
|
+
label: item.label,
|
|
1054
|
+
value: item.suffix
|
|
1055
|
+
}));
|
|
1056
|
+
const numfmtLocale = getNumfmtLocaleTag(locale);
|
|
1057
|
+
const patterns = getDateFormatPatterns(locale);
|
|
1058
|
+
if (currentPattern && !patterns.includes(currentPattern)) patterns.unshift(currentPattern);
|
|
1059
|
+
return patterns.map((pattern) => ({
|
|
1060
|
+
label: numfmt.format(pattern, DATE_FORMAT_PREVIEW_VALUE, { locale: numfmtLocale }),
|
|
1061
|
+
value: pattern
|
|
1062
|
+
}));
|
|
1063
|
+
};
|
|
943
1064
|
const getNumberFormatOptions = () => NUMBERFORMAT.map((item) => ({
|
|
944
1065
|
label: item.label,
|
|
945
1066
|
value: item.suffix,
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CellValueType, CommandType, DEFAULT_NUMBER_FORMAT, DependentOn, Disposable, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, LocaleType, ObjectMatrix, Plugin, Range, RegionService, ThemeService, UniverInstanceType, currencySymbols, getNumfmtLocaleTag, getNumfmtParseValueFilter, isDefaultFormat, isTextFormat, merge, numfmt, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
|
|
1
|
+
import { CellValueType, CommandType, DEFAULT_NUMBER_FORMAT, DependentOn, Disposable, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, LocaleType, ObjectMatrix, Plugin, Range, RegionService, ThemeService, UniverInstanceType, currencySymbols, excelDateTimeSerial, getNumfmtLocaleTag, getNumfmtParseValueFilter, isDefaultFormat, isTextFormat, merge, numfmt, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
|
|
2
2
|
import { INTERCEPTOR_POINT, INumfmtService, InterceptCellContentPriority, RemoveNumfmtMutation, SetNumfmtMutation, SetRangeValuesMutation, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, checkCellValueType, factoryRemoveNumfmtUndoMutation, factorySetNumfmtUndoMutation, getSheetCommandTarget, rangeMerge, transformCellsToRange } from "@univerjs/sheets";
|
|
3
3
|
import { stripErrorMargin } from "@univerjs/engine-formula";
|
|
4
4
|
import { BehaviorSubject, merge as merge$1, of, skip, switchMap } from "rxjs";
|
|
@@ -643,7 +643,7 @@ const configSymbol = Symbol(SHEETS_NUMFMT_PLUGIN_CONFIG_KEY);
|
|
|
643
643
|
const defaultPluginConfig = {};
|
|
644
644
|
|
|
645
645
|
//#endregion
|
|
646
|
-
//#region \0@oxc-project+runtime@0.
|
|
646
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
|
|
647
647
|
function _typeof(o) {
|
|
648
648
|
"@babel/helpers - typeof";
|
|
649
649
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -654,7 +654,7 @@ function _typeof(o) {
|
|
|
654
654
|
}
|
|
655
655
|
|
|
656
656
|
//#endregion
|
|
657
|
-
//#region \0@oxc-project+runtime@0.
|
|
657
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
|
|
658
658
|
function toPrimitive(t, r) {
|
|
659
659
|
if ("object" != _typeof(t) || !t) return t;
|
|
660
660
|
var e = t[Symbol.toPrimitive];
|
|
@@ -667,14 +667,14 @@ function toPrimitive(t, r) {
|
|
|
667
667
|
}
|
|
668
668
|
|
|
669
669
|
//#endregion
|
|
670
|
-
//#region \0@oxc-project+runtime@0.
|
|
670
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
|
|
671
671
|
function toPropertyKey(t) {
|
|
672
672
|
var i = toPrimitive(t, "string");
|
|
673
673
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
674
674
|
}
|
|
675
675
|
|
|
676
676
|
//#endregion
|
|
677
|
-
//#region \0@oxc-project+runtime@0.
|
|
677
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
|
|
678
678
|
function _defineProperty(e, r, t) {
|
|
679
679
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
680
680
|
value: t,
|
|
@@ -685,7 +685,7 @@ function _defineProperty(e, r, t) {
|
|
|
685
685
|
}
|
|
686
686
|
|
|
687
687
|
//#endregion
|
|
688
|
-
//#region \0@oxc-project+runtime@0.
|
|
688
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
689
689
|
function __decorateParam(paramIndex, decorator) {
|
|
690
690
|
return function(target, key) {
|
|
691
691
|
decorator(target, key, paramIndex);
|
|
@@ -693,7 +693,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
693
693
|
}
|
|
694
694
|
|
|
695
695
|
//#endregion
|
|
696
|
-
//#region \0@oxc-project+runtime@0.
|
|
696
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
697
697
|
function __decorate(decorators, target, key, desc) {
|
|
698
698
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
699
699
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -831,7 +831,7 @@ SheetsNumfmtCellContentController = __decorate([
|
|
|
831
831
|
//#endregion
|
|
832
832
|
//#region package.json
|
|
833
833
|
var name = "@univerjs/sheets-numfmt";
|
|
834
|
-
var version = "1.0
|
|
834
|
+
var version = "1.1.0";
|
|
835
835
|
|
|
836
836
|
//#endregion
|
|
837
837
|
//#region src/base/const/plugin-name.ts
|
|
@@ -911,7 +911,7 @@ const getCurrencyType = (pattern) => {
|
|
|
911
911
|
};
|
|
912
912
|
|
|
913
913
|
//#endregion
|
|
914
|
-
//#region src/
|
|
914
|
+
//#region src/base/const/date-format.ts
|
|
915
915
|
/**
|
|
916
916
|
* Copyright 2023-present DreamNum Co., Ltd.
|
|
917
917
|
*
|
|
@@ -927,6 +927,117 @@ const getCurrencyType = (pattern) => {
|
|
|
927
927
|
* See the License for the specific language governing permissions and
|
|
928
928
|
* limitations under the License.
|
|
929
929
|
*/
|
|
930
|
+
const ISO_DATE_PROFILE = {
|
|
931
|
+
dates: ["yyyy/MM/dd", "MM-dd"],
|
|
932
|
+
shortDate: "MM-dd"
|
|
933
|
+
};
|
|
934
|
+
const MDY_DATE_PROFILE = {
|
|
935
|
+
dates: [
|
|
936
|
+
"m/d/yyyy",
|
|
937
|
+
"mm/dd/yyyy",
|
|
938
|
+
"mmm d, yyyy",
|
|
939
|
+
"m/d",
|
|
940
|
+
"mmmm d"
|
|
941
|
+
],
|
|
942
|
+
shortDate: "m/d"
|
|
943
|
+
};
|
|
944
|
+
const DMY_DATE_PROFILE = {
|
|
945
|
+
dates: [
|
|
946
|
+
"dd/mm/yyyy",
|
|
947
|
+
"d/m/yyyy",
|
|
948
|
+
"d mmm yyyy",
|
|
949
|
+
"dd/mm",
|
|
950
|
+
"d mmmm"
|
|
951
|
+
],
|
|
952
|
+
shortDate: "dd/mm"
|
|
953
|
+
};
|
|
954
|
+
const DMY_DOT_DATE_PROFILE = {
|
|
955
|
+
dates: [
|
|
956
|
+
"dd.mm.yyyy",
|
|
957
|
+
"d.m.yyyy",
|
|
958
|
+
"d mmm yyyy",
|
|
959
|
+
"dd.mm",
|
|
960
|
+
"d mmmm"
|
|
961
|
+
],
|
|
962
|
+
shortDate: "dd.mm"
|
|
963
|
+
};
|
|
964
|
+
const CJK_DATE_PROFILE = {
|
|
965
|
+
dates: [
|
|
966
|
+
"yyyy/MM/dd",
|
|
967
|
+
"yyyy\"年\"MM\"月\"dd\"日\"",
|
|
968
|
+
"MM-dd",
|
|
969
|
+
"M\"月\"d\"日\""
|
|
970
|
+
],
|
|
971
|
+
shortDate: "MM-dd",
|
|
972
|
+
periodBeforeTime: true
|
|
973
|
+
};
|
|
974
|
+
const DATE_FORMAT_PROFILES = {
|
|
975
|
+
[LocaleType.EN_US]: MDY_DATE_PROFILE,
|
|
976
|
+
[LocaleType.FR_FR]: DMY_DATE_PROFILE,
|
|
977
|
+
[LocaleType.ZH_CN]: CJK_DATE_PROFILE,
|
|
978
|
+
[LocaleType.RU_RU]: DMY_DOT_DATE_PROFILE,
|
|
979
|
+
[LocaleType.ZH_TW]: CJK_DATE_PROFILE,
|
|
980
|
+
[LocaleType.ZH_HK]: {
|
|
981
|
+
...CJK_DATE_PROFILE,
|
|
982
|
+
dates: ["dd/MM/yyyy", ...CJK_DATE_PROFILE.dates],
|
|
983
|
+
shortDate: "dd/MM"
|
|
984
|
+
},
|
|
985
|
+
[LocaleType.VI_VN]: DMY_DATE_PROFILE,
|
|
986
|
+
[LocaleType.FA_IR]: ISO_DATE_PROFILE,
|
|
987
|
+
[LocaleType.CA_ES]: {
|
|
988
|
+
dates: [
|
|
989
|
+
"dd/mm/yyyy",
|
|
990
|
+
"d/m/yyyy",
|
|
991
|
+
"dd/mm"
|
|
992
|
+
],
|
|
993
|
+
shortDate: "dd/mm"
|
|
994
|
+
},
|
|
995
|
+
[LocaleType.JA_JP]: CJK_DATE_PROFILE,
|
|
996
|
+
[LocaleType.KO_KR]: {
|
|
997
|
+
dates: [
|
|
998
|
+
"yyyy. mm. dd.",
|
|
999
|
+
"yyyy\"년\" m\"월\" d\"일\"",
|
|
1000
|
+
"mm-dd",
|
|
1001
|
+
"m\"월\" d\"일\""
|
|
1002
|
+
],
|
|
1003
|
+
shortDate: "mm-dd",
|
|
1004
|
+
periodBeforeTime: true
|
|
1005
|
+
},
|
|
1006
|
+
[LocaleType.ES_ES]: DMY_DATE_PROFILE,
|
|
1007
|
+
[LocaleType.SK_SK]: DMY_DOT_DATE_PROFILE,
|
|
1008
|
+
[LocaleType.PT_BR]: DMY_DATE_PROFILE,
|
|
1009
|
+
[LocaleType.DE_DE]: DMY_DOT_DATE_PROFILE,
|
|
1010
|
+
[LocaleType.IT_IT]: DMY_DATE_PROFILE,
|
|
1011
|
+
[LocaleType.ID_ID]: DMY_DATE_PROFILE,
|
|
1012
|
+
[LocaleType.PL_PL]: DMY_DOT_DATE_PROFILE,
|
|
1013
|
+
[LocaleType.AR_SA]: {
|
|
1014
|
+
dates: [
|
|
1015
|
+
"dd/mm/yyyy",
|
|
1016
|
+
"d/m/yyyy",
|
|
1017
|
+
"dd/mm"
|
|
1018
|
+
],
|
|
1019
|
+
shortDate: "dd/mm"
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
function getDateFormatPatterns(locale) {
|
|
1023
|
+
const profile = DATE_FORMAT_PROFILES[locale] ?? ISO_DATE_PROFILE;
|
|
1024
|
+
const timePatterns = [
|
|
1025
|
+
"hh:mm",
|
|
1026
|
+
"h:mm",
|
|
1027
|
+
"h:mm:ss"
|
|
1028
|
+
].map((pattern) => profile.periodBeforeTime ? `AM/PM ${pattern}` : `${pattern} AM/PM`);
|
|
1029
|
+
return [.../* @__PURE__ */ new Set([
|
|
1030
|
+
"yyyy-MM-dd",
|
|
1031
|
+
...profile.dates,
|
|
1032
|
+
"h:mm:ss",
|
|
1033
|
+
"h:mm",
|
|
1034
|
+
...timePatterns,
|
|
1035
|
+
`${profile.shortDate} ${timePatterns[0]}`
|
|
1036
|
+
])];
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
//#endregion
|
|
1040
|
+
//#region src/utils/options.ts
|
|
930
1041
|
const getCurrencyOptions = () => currencySymbols.map((item) => ({
|
|
931
1042
|
label: item,
|
|
932
1043
|
value: item
|
|
@@ -936,10 +1047,20 @@ const getCurrencyFormatOptions = (suffix) => CURRENCYFORMAT.map((item) => ({
|
|
|
936
1047
|
value: item.suffix(suffix),
|
|
937
1048
|
color: item.color
|
|
938
1049
|
}));
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1050
|
+
const DATE_FORMAT_PREVIEW_VALUE = excelDateTimeSerial(new Date(Date.UTC(1930, 7, 5, 13, 30, 30)));
|
|
1051
|
+
const getDateFormatOptions = (locale, currentPattern) => {
|
|
1052
|
+
if (locale === void 0) return DATEFMTLISG.map((item) => ({
|
|
1053
|
+
label: item.label,
|
|
1054
|
+
value: item.suffix
|
|
1055
|
+
}));
|
|
1056
|
+
const numfmtLocale = getNumfmtLocaleTag(locale);
|
|
1057
|
+
const patterns = getDateFormatPatterns(locale);
|
|
1058
|
+
if (currentPattern && !patterns.includes(currentPattern)) patterns.unshift(currentPattern);
|
|
1059
|
+
return patterns.map((pattern) => ({
|
|
1060
|
+
label: numfmt.format(pattern, DATE_FORMAT_PREVIEW_VALUE, { locale: numfmtLocale }),
|
|
1061
|
+
value: pattern
|
|
1062
|
+
}));
|
|
1063
|
+
};
|
|
943
1064
|
const getNumberFormatOptions = () => NUMBERFORMAT.map((item) => ({
|
|
944
1065
|
label: item.label,
|
|
945
1066
|
value: item.suffix,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { LocaleType } from '@univerjs/core';
|
|
17
|
+
export declare function getDateFormatPatterns(locale: LocaleType): string[];
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import type { LocaleType } from '@univerjs/core';
|
|
16
17
|
export declare const getCurrencyOptions: () => {
|
|
17
18
|
label: string;
|
|
18
19
|
value: string;
|
|
@@ -22,7 +23,7 @@ export declare const getCurrencyFormatOptions: (suffix: string) => {
|
|
|
22
23
|
value: string;
|
|
23
24
|
color: string | undefined;
|
|
24
25
|
}[];
|
|
25
|
-
export declare const getDateFormatOptions: () => {
|
|
26
|
+
export declare const getDateFormatOptions: (locale?: LocaleType, currentPattern?: string) => {
|
|
26
27
|
label: string;
|
|
27
28
|
value: string;
|
|
28
29
|
}[];
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-formula`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmt={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula,e.rxjs))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let a=new Map([[t.LocaleType.EN_US,`$`],[t.LocaleType.RU_RU,`₽`],[t.LocaleType.VI_VN,`₫`],[t.LocaleType.ZH_CN,`¥`],[t.LocaleType.ZH_TW,`NT$`],[t.LocaleType.ZH_HK,`HK$`],[t.LocaleType.FR_FR,`€`],[t.LocaleType.FA_IR,`﷼`],[t.LocaleType.KO_KR,`₩`],[t.LocaleType.ES_ES,`€`],[t.LocaleType.CA_ES,`€`],[t.LocaleType.SK_SK,`€`],[t.LocaleType.JA_JP,`¥`],[t.LocaleType.PT_BR,`R$`],[t.LocaleType.DE_DE,`€`],[t.LocaleType.IT_IT,`€`],[t.LocaleType.ID_ID,`Rp`],[t.LocaleType.PL_PL,`zł`],[t.LocaleType.AR_SA,`﷼`]]);function o(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.DE_DE:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.IT_IT:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:a.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:a.get(e)||`₽`,locale:e};case t.LocaleType.JA_JP:case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:a.get(e)||`¥`,locale:e};case t.LocaleType.VI_VN:return{icon:`DongIcon`,symbol:a.get(e)||`₫`,locale:e};case t.LocaleType.AR_SA:case t.LocaleType.FA_IR:return{icon:`RialIcon`,symbol:a.get(e)||`﷼`,locale:e};case t.LocaleType.KO_KR:return{icon:`WonIcon`,symbol:a.get(e)||`₩`,locale:e};case t.LocaleType.ID_ID:return{icon:`RupiahIcon`,symbol:a.get(e)||`Rp`,locale:e};case t.LocaleType.PL_PL:return{icon:`ZlotyIcon`,symbol:a.get(e)||`zł`,locale:e};case t.LocaleType.EN_US:case t.LocaleType.PT_BR:case t.LocaleType.ZH_HK:case t.LocaleType.ZH_TW:default:return{icon:`DollarIcon`,symbol:a.get(e)||`$`,locale:e}}}function s(e){return a.get(e)||`$`}function c(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${s(e)}"#,##0${r}_);[Red]("${s(e)}"#,##0${r})`}let l=[{label:`1930-08-05`,suffix:`yyyy-MM-dd`},{label:`1930/08/05`,suffix:`yyyy/MM/dd`},{label:`1930年08月05日`,suffix:`yyyy"年"MM"月"dd"日"`},{label:`08-05`,suffix:`MM-dd`},{label:`8月5日`,suffix:`M"月"d"日"`},{label:`13:30:30`,suffix:`h:mm:ss`},{label:`13:30`,suffix:`h:mm`},{label:`下午01:30`,suffix:`A/P hh:mm`},{label:`下午1:30`,suffix:`A/P h:mm`},{label:`下午1:30:30`,suffix:`A/P h:mm:ss`},{label:`08-05 下午 01:30`,suffix:`MM-dd A/P hh:mm`}],u=[{label:`(1,235)`,suffix:`#,##0_);(#,##0)`},{label:`(1,235) `,suffix:`#,##0_);[Red](#,##0)`,color:`red`},{label:`1,234.56`,suffix:`#,##0.00_);#,##0.00`},{label:`1,234.56`,suffix:`#,##0.00_);[Red]#,##0.00`,color:`red`},{label:`-1,234.56`,suffix:`#,##0.00_);-#,##0.00`},{label:`-1,234.56`,suffix:`#,##0.00_);[Red]-#,##0.00`,color:`red`}],d=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:`red`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:`red`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:`red`}],f=(e,n=0)=>e?t.numfmt.getFormatInfo(e).maxDecimals??n:n,p=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),m=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${p(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${p(Number(t||0))}$1`):e).join(`;`),h=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),g=e=>{let n=t.numfmt.getFormatInfo(e).type||`unknown`;return n===`general`&&t.numfmt.tokenize(e).some(e=>e.type===t.numfmt.tokenTypes.CONDITION)?`number`:n},_=(e,n,r=`en`,i)=>{try{let a=t.numfmt.formatColor(e,n),o=a?String(a):void 0,s=t.numfmt.format(e,n,{locale:r,dateSystem:i,throws:!1});return n<0?{result:s,color:o}:{result:s}}catch(t){console.warn(`getPatternPreview error:`,e,t)}return{result:String(n)}},v=(e,n,i,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,r.stripErrorMargin)(n))}:_(e,n,i,a);function y(e){return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&e.v!==void 0&&e.v!==null&&/e/i.test(String(e.v))}function b(e){let t=String(e==null?void 0:e.v),n=t.search(/e/i),r=t.indexOf(`.`),i=n>-1&&r>-1?n-r-1:0;return`0.${`0`.repeat(Math.max(2,i))}E+00`}function x(e){return(0,t.isDefaultFormat)(e)||(0,t.isTextFormat)(e)||g(e)===`scientific`}let S={id:`sheet.command.numfmt.set.numfmt`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),s=(0,n.getSheetCommandTarget)(a,r);if(!s)return!1;let{unitId:c,subUnitId:l,worksheet:u}=s,d=r.values.filter(e=>!y(u.getCellRaw(e.row,e.col))||x(e.pattern)),f=d.filter(e=>!!e.pattern),p=d.filter(e=>!e.pattern);if(!f.length&&!p.length)return!1;let m=(0,n.transformCellsToRange)(c,l,f),h={unitId:c,subUnitId:l,ranges:p.map(e=>({startColumn:e.col,startRow:e.row,endColumn:e.col,endRow:e.row}))},g=[],_=[];if(f.length){let r=f.reduce((e,r)=>{(0,t.isTextFormat)(r.pattern)&&e.setValue(r.row,r.col,{t:t.CellValueType.STRING});let i=u.getCellRaw(r.row,r.col);if(i){let t=(0,n.checkCellValueType)(i.v);t!==i.t&&e.setValue(r.row,r.col,{t})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),Object.keys(m.values).forEach(e=>{let t=m.values[e];t.ranges=(0,n.rangeMerge)(t.ranges)}),g.push({id:n.SetNumfmtMutation.id,params:m});let a=(0,n.factorySetNumfmtUndoMutation)(e,m);_.push(...a)}if(p.length){h.ranges=(0,n.rangeMerge)(h.ranges);let r=p.reduce((e,t)=>{let r=u.getCellRaw(t.row,t.col);if(r){let i=(0,n.checkCellValueType)(r.v);i!==r.t&&e.setValue(t.row,t.col,{t:i})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),g.push({id:n.RemoveNumfmtMutation.id,params:h},{id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:r}});let a=(0,n.factoryRemoveNumfmtUndoMutation)(e,h);_.push({id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:i.getMatrix()}},...a)}let v=(0,t.sequenceExecute)(g,i).result;return v&&o.pushUndoRedo({unitID:c,undoMutations:_,redoMutations:g}),v}},C={id:`sheet.command.numfmt.add.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(y(r)){d=Math.max(d,f(b(r)));return}if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d+1,h=m(`0${p>0?`.0`:``}`,p),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern)){let t=c.worksheet.getCellRaw(e,n);g.push({row:e,col:n,pattern:y(t)?m(b(t),p):h})}else{let t=f(r.pattern),i=m(r.pattern,t+1);i!==r.pattern&&g.push({row:e,col:n,pattern:i})}})}),g.length?await r.executeCommand(S.id,{values:g}):!1}},w={id:`sheet.command.numfmt.set.currency`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(t.RegionService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let l=[],u=c(o(a.getCurrentRegion()).locale);return s.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{l.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(S.id,{values:l})}},T={id:`sheet.command.numfmt.set.percent`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;let a=[];return i.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{a.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await r.executeCommand(S.id,{values:a})}},E={id:`sheet.command.numfmt.subtract.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(y(r)){d=Math.max(d,f(b(r)));return}if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d-1,h=m(`0${p>0?`.0`:`.`}`,p),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern)){let t=c.worksheet.getCellRaw(e,n);g.push({row:e,col:n,pattern:y(t)?m(b(t),p):h})}else{let t=f(r.pattern);g.push({row:e,col:n,pattern:m(r.pattern,t-1)})}})}),await r.executeCommand(S.id,{values:g})}},D=`sheets-numfmt.config`,O={};function k(e){"@babel/helpers - typeof";return k=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},k(e)}function A(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function j(e){var t=A(e,`string`);return k(t)==`symbol`?t:t+``}function M(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(e,t){return function(n,r){t(n,r,e)}}function P(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let F={tl:{size:6,color:`#409f11`}},I=class extends t.Disposable{constructor(e,t,n,r,a,o,s){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=r,this._numfmtService=a,this._localeService=o,this._configService=s,M(this,`_locale$`,new i.BehaviorSubject(null)),M(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){return this.getLocale()}getLocale(e){return this._locale$.getValue()??(0,t.getNumfmtLocaleTag)((e==null?void 0:e.getSnapshot().locale)??this._localeService.getCurrentLocale())}_initInterceptorCellContent(){let e=new t.ObjectMatrix;this.disposeWithMe((0,i.merge)(this._locale$,this._localeService.currentLocale$).subscribe(()=>{e.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,i,a)=>{if(!r||r.v===void 0||r.v===null||r.t===t.CellValueType.BOOLEAN||r.t===t.CellValueType.FORCE_STRING)return a(r);let o=i.unitId,s=i.subUnitId,c=this.getLocale(i.workbook),l=i.workbook.getDateSystem(),u;if(r!=null&&r.s){let e=i.workbook.getStyles().get(r.s);e!=null&&e.n&&(u=e.n)}if(u||=this._numfmtService.getValue(o,s,i.row,i.col),(0,t.isDefaultFormat)(u==null?void 0:u.pattern))return a(r);if(r.t!==t.CellValueType.NUMBER){var d;if((0,n.checkCellValueType)(r.v,r.t)!==t.CellValueType.NUMBER&&!((0,t.isTextFormat)(u==null?void 0:u.pattern)&&typeof r.v==`string`&&typeof((d=(0,t.getNumfmtParseValueFilter)(r.v,{locale:c,dateSystem:l}))==null?void 0:d.v)==`number`))return a(r)}let f=r;if((!r||r===i.rawData)&&(r={...i.rawData}),(0,t.isTextFormat)(u==null?void 0:u.pattern)){var p;return(p=this._configService.getConfig(`sheets-numfmt.config`))!=null&&p.disableTextFormatMark?(r.t=t.CellValueType.STRING,a(r)):(r.t=t.CellValueType.STRING,r.markers={...r==null?void 0:r.markers,...F},a(r))}let m=`${o}_${s}_${f.v}_${u==null?void 0:u.pattern}_${c}_${l}`,h=e.getValue(i.row,i.col);if(h&&h.parameters===m)return a({...r,...h.result});let g=v(u==null?void 0:u.pattern,Number(f.v),c,l),_=g.result,y={v:_,t:t.CellValueType.NUMBER};if(_===``&&(y.coverable=!1),g.color){let e=this._themeService.getColorFromTheme(`${g.color}.500`)??g.color;e&&(y.interceptorStyle={cl:{rgb:e}})}return e.setValue(i.row,i.col,{result:y,parameters:m}),Object.assign(r,y),a(r)},priority:n.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===n.SetNumfmtMutation.id){let n=r.params;Object.keys(n.values).forEach(r=>{n.values[r].ranges.forEach(n=>{t.Range.foreach(n,(t,n)=>{e.realDeleteValue(t,n)})})})}else if(r.id===n.SetRangeValuesMutation.id){let n=r.params;new t.ObjectMatrix(n.cellValue).forValue((t,n)=>{e.realDeleteValue(t,n)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,i.switchMap)(e=>(e==null?void 0:e.activeSheet$)??(0,i.of)(null)),(0,i.skip)(1)).subscribe(()=>e.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};I=P([N(0,t.IUniverInstanceService),N(1,(0,t.Inject)(n.SheetInterceptorService)),N(2,(0,t.Inject)(t.ThemeService)),N(3,(0,t.Inject)(t.ICommandService)),N(4,(0,t.Inject)(n.INumfmtService)),N(5,(0,t.Inject)(t.LocaleService)),N(6,t.IConfigService)],I);var L=`@univerjs/sheets-numfmt`,R=`1.0.3`;let z=class extends t.Plugin{constructor(e=O,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},O,this._config);this._configService.setConfig(D,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[I]]),(0,t.touchDependencies)(this._injector,[[I]]),[C,E,w,T,S].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};M(z,`pluginName`,`SHEET_NUMFMT_PLUGIN`),M(z,`packageName`,L),M(z,`version`,R),M(z,`type`,t.UniverInstanceType.UNIVER_SHEET),z=P([(0,t.DependentOn)(n.UniverSheetsPlugin),N(1,(0,t.Inject)(t.Injector)),N(2,t.IConfigService),N(3,t.ICommandService)],z),e.AddDecimalCommand=C,e.CURRENCYFORMAT=d,e.DATEFMTLISG=l,e.NUMBERFORMAT=u,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,e.SetCurrencyCommand=w,e.SetNumfmtCommand=S,e.SetPercentCommand=T,Object.defineProperty(e,"SheetsNumfmtCellContentController",{enumerable:!0,get:function(){return I}}),e.SubtractDecimalCommand=E,Object.defineProperty(e,"UniverSheetsNumfmtPlugin",{enumerable:!0,get:function(){return z}}),e.getCurrencyFormat=c,e.getCurrencyFormatOptions=e=>d.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),e.getCurrencyOptions=()=>t.currencySymbols.map(e=>({label:e,value:e})),e.getCurrencySymbolByLocale=s,e.getCurrencySymbolIconByLocale=o,e.getCurrencyType=e=>t.currencySymbols.find(t=>e.includes(t)),e.getDateFormatOptions=()=>l.map(e=>({label:e.label,value:e.suffix})),e.getDecimalFromPattern=f,e.getDecimalString=p,e.getNumberFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=_,e.getPatternPreviewIgnoreGeneral=v,e.getPatternType=g,e.isPatternHasDecimal=h,e.localeCurrencySymbolMap=a,e.setPatternDecimal=m});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("rxjs")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-formula`,`rxjs`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmt={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula,e.rxjs))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let a=/* @__PURE__ */ new Map([[t.LocaleType.EN_US,`$`],[t.LocaleType.RU_RU,`₽`],[t.LocaleType.VI_VN,`₫`],[t.LocaleType.ZH_CN,`¥`],[t.LocaleType.ZH_TW,`NT$`],[t.LocaleType.ZH_HK,`HK$`],[t.LocaleType.FR_FR,`€`],[t.LocaleType.FA_IR,`﷼`],[t.LocaleType.KO_KR,`₩`],[t.LocaleType.ES_ES,`€`],[t.LocaleType.CA_ES,`€`],[t.LocaleType.SK_SK,`€`],[t.LocaleType.JA_JP,`¥`],[t.LocaleType.PT_BR,`R$`],[t.LocaleType.DE_DE,`€`],[t.LocaleType.IT_IT,`€`],[t.LocaleType.ID_ID,`Rp`],[t.LocaleType.PL_PL,`zł`],[t.LocaleType.AR_SA,`﷼`]]);function o(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.DE_DE:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:case t.LocaleType.IT_IT:case t.LocaleType.SK_SK:return{icon:`EuroIcon`,symbol:a.get(e)||`€`,locale:e};case t.LocaleType.RU_RU:return{icon:`RoubleIcon`,symbol:a.get(e)||`₽`,locale:e};case t.LocaleType.JA_JP:case t.LocaleType.ZH_CN:return{icon:`RmbIcon`,symbol:a.get(e)||`¥`,locale:e};case t.LocaleType.VI_VN:return{icon:`DongIcon`,symbol:a.get(e)||`₫`,locale:e};case t.LocaleType.AR_SA:case t.LocaleType.FA_IR:return{icon:`RialIcon`,symbol:a.get(e)||`﷼`,locale:e};case t.LocaleType.KO_KR:return{icon:`WonIcon`,symbol:a.get(e)||`₩`,locale:e};case t.LocaleType.ID_ID:return{icon:`RupiahIcon`,symbol:a.get(e)||`Rp`,locale:e};case t.LocaleType.PL_PL:return{icon:`ZlotyIcon`,symbol:a.get(e)||`zł`,locale:e};case t.LocaleType.EN_US:case t.LocaleType.PT_BR:case t.LocaleType.ZH_HK:case t.LocaleType.ZH_TW:default:return{icon:`DollarIcon`,symbol:a.get(e)||`$`,locale:e}}}function s(e){return a.get(e)||`$`}function c(e,t=2){let n=t;t>127&&(n=127);let r=``;return n>0&&(r=`.${`0`.repeat(n)}`),`"${s(e)}"#,##0${r}_);[Red]("${s(e)}"#,##0${r})`}let l=[{label:`1930-08-05`,suffix:`yyyy-MM-dd`},{label:`1930/08/05`,suffix:`yyyy/MM/dd`},{label:`1930年08月05日`,suffix:`yyyy"年"MM"月"dd"日"`},{label:`08-05`,suffix:`MM-dd`},{label:`8月5日`,suffix:`M"月"d"日"`},{label:`13:30:30`,suffix:`h:mm:ss`},{label:`13:30`,suffix:`h:mm`},{label:`下午01:30`,suffix:`A/P hh:mm`},{label:`下午1:30`,suffix:`A/P h:mm`},{label:`下午1:30:30`,suffix:`A/P h:mm:ss`},{label:`08-05 下午 01:30`,suffix:`MM-dd A/P hh:mm`}],u=[{label:`(1,235)`,suffix:`#,##0_);(#,##0)`},{label:`(1,235) `,suffix:`#,##0_);[Red](#,##0)`,color:`red`},{label:`1,234.56`,suffix:`#,##0.00_);#,##0.00`},{label:`1,234.56`,suffix:`#,##0.00_);[Red]#,##0.00`,color:`red`},{label:`-1,234.56`,suffix:`#,##0.00_);-#,##0.00`},{label:`-1,234.56`,suffix:`#,##0.00_);[Red]-#,##0.00`,color:`red`}],d=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:`red`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:`red`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:`red`}],f=(e,n=0)=>e?t.numfmt.getFormatInfo(e).maxDecimals??n:n,p=e=>Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(``),m=(e,t)=>e.split(`;`).map(e=>/\.0?/.test(e)?e.replace(/\.0*/g,`${t>0?`.`:``}${p(Number(t||0))}`):/0([^0]?)|0$/.test(e)?e.replace(/0([^0]+)|0$/,`0${t>0?`.`:``}${p(Number(t||0))}$1`):e).join(`;`),h=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),g=e=>{let n=t.numfmt.getFormatInfo(e).type||`unknown`;return n===`general`&&t.numfmt.tokenize(e).some(e=>e.type===t.numfmt.tokenTypes.CONDITION)?`number`:n},_=(e,n,r=`en`,i)=>{try{let a=t.numfmt.formatColor(e,n),o=a?String(a):void 0,s=t.numfmt.format(e,n,{locale:r,dateSystem:i,throws:!1});return n<0?{result:s,color:o}:{result:s}}catch(t){console.warn(`getPatternPreview error:`,e,t)}return{result:String(n)}},v=(e,n,i,a)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String((0,r.stripErrorMargin)(n))}:_(e,n,i,a);function y(e){return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&e.v!==void 0&&e.v!==null&&/e/i.test(String(e.v))}function b(e){let t=String(e==null?void 0:e.v),n=t.search(/e/i),r=t.indexOf(`.`),i=n>-1&&r>-1?n-r-1:0;return`0.${`0`.repeat(Math.max(2,i))}E+00`}function x(e){return(0,t.isDefaultFormat)(e)||(0,t.isTextFormat)(e)||g(e)===`scientific`}let S={id:`sheet.command.numfmt.set.numfmt`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUniverInstanceService),o=e.get(t.IUndoRedoService),s=(0,n.getSheetCommandTarget)(a,r);if(!s)return!1;let{unitId:c,subUnitId:l,worksheet:u}=s,d=r.values.filter(e=>!y(u.getCellRaw(e.row,e.col))||x(e.pattern)),f=d.filter(e=>!!e.pattern),p=d.filter(e=>!e.pattern);if(!f.length&&!p.length)return!1;let m=(0,n.transformCellsToRange)(c,l,f),h={unitId:c,subUnitId:l,ranges:p.map(e=>({startColumn:e.col,startRow:e.row,endColumn:e.col,endRow:e.row}))},g=[],_=[];if(f.length){let r=f.reduce((e,r)=>{(0,t.isTextFormat)(r.pattern)&&e.setValue(r.row,r.col,{t:t.CellValueType.STRING});let i=u.getCellRaw(r.row,r.col);if(i){let t=(0,n.checkCellValueType)(i.v);t!==i.t&&e.setValue(r.row,r.col,{t})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),Object.keys(m.values).forEach(e=>{let t=m.values[e];t.ranges=(0,n.rangeMerge)(t.ranges)}),g.push({id:n.SetNumfmtMutation.id,params:m});let a=(0,n.factorySetNumfmtUndoMutation)(e,m);_.push(...a)}if(p.length){h.ranges=(0,n.rangeMerge)(h.ranges);let r=p.reduce((e,t)=>{let r=u.getCellRaw(t.row,t.col);if(r){let i=(0,n.checkCellValueType)(r.v);i!==r.t&&e.setValue(t.row,t.col,{t:i})}return e},new t.ObjectMatrix).getMatrix(),i=new t.ObjectMatrix;new t.ObjectMatrix(r).forValue((e,t)=>{let n=u.getCellRaw(e,t);n?i.setValue(e,t,{t:n.t}):i.setValue(e,t,{t:void 0})}),g.push({id:n.RemoveNumfmtMutation.id,params:h},{id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:r}});let a=(0,n.factoryRemoveNumfmtUndoMutation)(e,h);_.push({id:n.SetRangeValuesMutation.id,params:{unitId:c,subUnitId:l,cellValue:i.getMatrix()}},...a)}let v=(0,t.sequenceExecute)(g,i).result;return v&&o.pushUndoRedo({unitID:c,undoMutations:_,redoMutations:g}),v}},C={id:`sheet.command.numfmt.add.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(y(r)){d=Math.max(d,f(b(r)));return}if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d+1,h=m(`0${p>0?`.0`:``}`,p),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern)){let t=c.worksheet.getCellRaw(e,n);g.push({row:e,col:n,pattern:y(t)?m(b(t),p):h})}else{let t=f(r.pattern),i=m(r.pattern,t+1);i!==r.pattern&&g.push({row:e,col:n,pattern:i})}})}),g.length?await r.executeCommand(S.id,{values:g}):!1}},w={id:`sheet.command.numfmt.set.currency`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(t.RegionService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let l=[],u=c(o(a.getCurrentRegion()).locale);return s.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{l.push({row:e,col:t,pattern:u,type:`currency`})})}),await r.executeCommand(S.id,{values:l})}},T={id:`sheet.command.numfmt.set.percent`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService).getCurrentSelections();if(!i||!i.length)return!1;let a=[];return i.forEach(e=>{t.Range.foreach(e.range,(e,t)=>{a.push({row:e,col:t,pattern:`0%`,type:`percent`})})}),await r.executeCommand(S.id,{values:a})}},E={id:`sheet.command.numfmt.subtract.decimal.command`,type:t.CommandType.COMMAND,handler:async e=>{let r=e.get(t.ICommandService),i=e.get(n.SheetsSelectionsService),a=e.get(n.INumfmtService),o=e.get(t.IUniverInstanceService),s=i.getCurrentSelections();if(!s||!s.length)return!1;let c=(0,n.getSheetCommandTarget)(o);if(!c)return!1;let{unitId:l,subUnitId:u}=c,d=0;s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if(!r){let r=c.worksheet.getCellRaw(e,n);if(y(r)){d=Math.max(d,f(b(r)));return}if(!d&&r&&r.t===t.CellValueType.NUMBER&&r.v){let e=/\.(\d*)$/.exec(String(r.v));if(e){let t=e[1].length;if(!t)return;d=Math.max(d,t)}}return}let i=f(r.pattern);d=i>d?i:d})});let p=d-1,h=m(`0${p>0?`.0`:`.`}`,p),g=[];return s.forEach(e=>{t.Range.foreach(e.range,(e,n)=>{let r=a.getValue(l,u,e,n);if((0,t.isDefaultFormat)(r==null?void 0:r.pattern)){let t=c.worksheet.getCellRaw(e,n);g.push({row:e,col:n,pattern:y(t)?m(b(t),p):h})}else{let t=f(r.pattern);g.push({row:e,col:n,pattern:m(r.pattern,t-1)})}})}),await r.executeCommand(S.id,{values:g})}},D=`sheets-numfmt.config`,O={};function k(e){"@babel/helpers - typeof";return k=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},k(e)}function A(e,t){if(k(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(k(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function j(e){var t=A(e,`string`);return k(t)==`symbol`?t:t+``}function M(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(e,t){return function(n,r){t(n,r,e)}}function P(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let F={tl:{size:6,color:`#409f11`}},I=class extends t.Disposable{constructor(e,t,n,r,a,o,s){super(),this._instanceService=e,this._sheetInterceptorService=t,this._themeService=n,this._commandService=r,this._numfmtService=a,this._localeService=o,this._configService=s,M(this,`_locale$`,new i.BehaviorSubject(null)),M(this,`locale$`,this._locale$.asObservable()),this._initInterceptorCellContent()}get locale(){return this.getLocale()}getLocale(e){return this._locale$.getValue()??(0,t.getNumfmtLocaleTag)((e==null?void 0:e.getSnapshot().locale)??this._localeService.getCurrentLocale())}_initInterceptorCellContent(){let e=new t.ObjectMatrix;this.disposeWithMe((0,i.merge)(this._locale$,this._localeService.currentLocale$).subscribe(()=>{e.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(n.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(r,i,a)=>{if(!r||r.v===void 0||r.v===null||r.t===t.CellValueType.BOOLEAN||r.t===t.CellValueType.FORCE_STRING)return a(r);let o=i.unitId,s=i.subUnitId,c=this.getLocale(i.workbook),l=i.workbook.getDateSystem(),u;if(r!=null&&r.s){let e=i.workbook.getStyles().get(r.s);e!=null&&e.n&&(u=e.n)}if(u||=this._numfmtService.getValue(o,s,i.row,i.col),(0,t.isDefaultFormat)(u==null?void 0:u.pattern))return a(r);if(r.t!==t.CellValueType.NUMBER){var d;if((0,n.checkCellValueType)(r.v,r.t)!==t.CellValueType.NUMBER&&!((0,t.isTextFormat)(u==null?void 0:u.pattern)&&typeof r.v==`string`&&typeof((d=(0,t.getNumfmtParseValueFilter)(r.v,{locale:c,dateSystem:l}))==null?void 0:d.v)==`number`))return a(r)}let f=r;if((!r||r===i.rawData)&&(r={...i.rawData}),(0,t.isTextFormat)(u==null?void 0:u.pattern)){var p;return(p=this._configService.getConfig(`sheets-numfmt.config`))!=null&&p.disableTextFormatMark?(r.t=t.CellValueType.STRING,a(r)):(r.t=t.CellValueType.STRING,r.markers={...r==null?void 0:r.markers,...F},a(r))}let m=`${o}_${s}_${f.v}_${u==null?void 0:u.pattern}_${c}_${l}`,h=e.getValue(i.row,i.col);if(h&&h.parameters===m)return a({...r,...h.result});let g=v(u==null?void 0:u.pattern,Number(f.v),c,l),_=g.result,y={v:_,t:t.CellValueType.NUMBER};if(_===``&&(y.coverable=!1),g.color){let e=this._themeService.getColorFromTheme(`${g.color}.500`)??g.color;e&&(y.interceptorStyle={cl:{rgb:e}})}return e.setValue(i.row,i.col,{result:y,parameters:m}),Object.assign(r,y),a(r)},priority:n.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(r.id===n.SetNumfmtMutation.id){let n=r.params;Object.keys(n.values).forEach(r=>{n.values[r].ranges.forEach(n=>{t.Range.foreach(n,(t,n)=>{e.realDeleteValue(t,n)})})})}else if(r.id===n.SetRangeValuesMutation.id){let n=r.params;new t.ObjectMatrix(n.cellValue).forValue((t,n)=>{e.realDeleteValue(t,n)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,i.switchMap)(e=>(e==null?void 0:e.activeSheet$)??(0,i.of)(null)),(0,i.skip)(1)).subscribe(()=>e.reset()))}setNumfmtLocal(e){this._locale$.next(e)}};I=P([N(0,t.IUniverInstanceService),N(1,(0,t.Inject)(n.SheetInterceptorService)),N(2,(0,t.Inject)(t.ThemeService)),N(3,(0,t.Inject)(t.ICommandService)),N(4,(0,t.Inject)(n.INumfmtService)),N(5,(0,t.Inject)(t.LocaleService)),N(6,t.IConfigService)],I);var L=`@univerjs/sheets-numfmt`,R=`1.1.0`;let z=class extends t.Plugin{constructor(e=O,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._commandService=i;let{...a}=(0,t.merge)({},O,this._config);this._configService.setConfig(D,a)}onStarting(){(0,t.registerDependencies)(this._injector,[[I]]),(0,t.touchDependencies)(this._injector,[[I]]),[C,E,w,T,S].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}};M(z,`pluginName`,`SHEET_NUMFMT_PLUGIN`),M(z,`packageName`,L),M(z,`version`,R),M(z,`type`,t.UniverInstanceType.UNIVER_SHEET),z=P([(0,t.DependentOn)(n.UniverSheetsPlugin),N(1,(0,t.Inject)(t.Injector)),N(2,t.IConfigService),N(3,t.ICommandService)],z);let B=e=>t.currencySymbols.find(t=>e.includes(t)),V={dates:[`yyyy/MM/dd`,`MM-dd`],shortDate:`MM-dd`},H={dates:[`m/d/yyyy`,`mm/dd/yyyy`,`mmm d, yyyy`,`m/d`,`mmmm d`],shortDate:`m/d`},U={dates:[`dd/mm/yyyy`,`d/m/yyyy`,`d mmm yyyy`,`dd/mm`,`d mmmm`],shortDate:`dd/mm`},W={dates:[`dd.mm.yyyy`,`d.m.yyyy`,`d mmm yyyy`,`dd.mm`,`d mmmm`],shortDate:`dd.mm`},G={dates:[`yyyy/MM/dd`,`yyyy"年"MM"月"dd"日"`,`MM-dd`,`M"月"d"日"`],shortDate:`MM-dd`,periodBeforeTime:!0},K={[t.LocaleType.EN_US]:H,[t.LocaleType.FR_FR]:U,[t.LocaleType.ZH_CN]:G,[t.LocaleType.RU_RU]:W,[t.LocaleType.ZH_TW]:G,[t.LocaleType.ZH_HK]:{...G,dates:[`dd/MM/yyyy`,...G.dates],shortDate:`dd/MM`},[t.LocaleType.VI_VN]:U,[t.LocaleType.FA_IR]:V,[t.LocaleType.CA_ES]:{dates:[`dd/mm/yyyy`,`d/m/yyyy`,`dd/mm`],shortDate:`dd/mm`},[t.LocaleType.JA_JP]:G,[t.LocaleType.KO_KR]:{dates:[`yyyy. mm. dd.`,`yyyy"년" m"월" d"일"`,`mm-dd`,`m"월" d"일"`],shortDate:`mm-dd`,periodBeforeTime:!0},[t.LocaleType.ES_ES]:U,[t.LocaleType.SK_SK]:W,[t.LocaleType.PT_BR]:U,[t.LocaleType.DE_DE]:W,[t.LocaleType.IT_IT]:U,[t.LocaleType.ID_ID]:U,[t.LocaleType.PL_PL]:W,[t.LocaleType.AR_SA]:{dates:[`dd/mm/yyyy`,`d/m/yyyy`,`dd/mm`],shortDate:`dd/mm`}};function q(e){let t=K[e]??V,n=[`hh:mm`,`h:mm`,`h:mm:ss`].map(e=>t.periodBeforeTime?`AM/PM ${e}`:`${e} AM/PM`);return[.../* @__PURE__ */ new Set([`yyyy-MM-dd`,...t.dates,`h:mm:ss`,`h:mm`,...n,`${t.shortDate} ${n[0]}`])]}let J=()=>t.currencySymbols.map(e=>({label:e,value:e})),Y=e=>d.map(t=>({label:t.label(e),value:t.suffix(e),color:t.color})),X=(0,t.excelDateTimeSerial)(new Date(Date.UTC(1930,7,5,13,30,30)));e.AddDecimalCommand=C,e.CURRENCYFORMAT=d,e.DATEFMTLISG=l,e.NUMBERFORMAT=u,e.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D,e.SetCurrencyCommand=w,e.SetNumfmtCommand=S,e.SetPercentCommand=T,Object.defineProperty(e,"SheetsNumfmtCellContentController",{enumerable:!0,get:function(){return I}}),e.SubtractDecimalCommand=E,Object.defineProperty(e,"UniverSheetsNumfmtPlugin",{enumerable:!0,get:function(){return z}}),e.getCurrencyFormat=c,e.getCurrencyFormatOptions=Y,e.getCurrencyOptions=J,e.getCurrencySymbolByLocale=s,e.getCurrencySymbolIconByLocale=o,e.getCurrencyType=B,e.getDateFormatOptions=(e,n)=>{if(e===void 0)return l.map(e=>({label:e.label,value:e.suffix}));let r=(0,t.getNumfmtLocaleTag)(e),i=q(e);return n&&!i.includes(n)&&i.unshift(n),i.map(e=>({label:t.numfmt.format(e,X,{locale:r}),value:e}))},e.getDecimalFromPattern=f,e.getDecimalString=p,e.getNumberFormatOptions=()=>u.map(e=>({label:e.label,value:e.suffix,color:e.color})),e.getPatternPreview=_,e.getPatternPreviewIgnoreGeneral=v,e.getPatternType=g,e.isPatternHasDecimal=h,e.localeCurrencySymbolMap=a,e.setPatternDecimal=m});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Number format services and commands for Univer Sheets.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -62,15 +62,15 @@
|
|
|
62
62
|
"rxjs": ">=7.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@univerjs/core": "1.0
|
|
66
|
-
"@univerjs/engine-formula": "1.0
|
|
67
|
-
"@univerjs/sheets": "1.0
|
|
65
|
+
"@univerjs/core": "1.1.0",
|
|
66
|
+
"@univerjs/engine-formula": "1.1.0",
|
|
67
|
+
"@univerjs/sheets": "1.1.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@univerjs-infra/shared": "1.0
|
|
70
|
+
"@univerjs-infra/shared": "1.1.0",
|
|
71
71
|
"rxjs": "^7.8.2",
|
|
72
72
|
"typescript": "^6.0.3",
|
|
73
|
-
"vitest": "^5.0.
|
|
73
|
+
"vitest": "^5.0.4"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"test": "vitest run",
|