Merge pull request #631 from Corbe30/feature/custom-number-fmt-v1

added: number format support - Volts, ampere, ohms
This commit is contained in:
Sanchit Agarwal 2024-11-25 21:54:30 +05:30 committed by GitHub
commit ae482085b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 63 additions and 19 deletions

View File

@ -11217,7 +11217,7 @@ export default {
{ name: "Iraqi Dinar", pos: "before", value: "din" },
{ name: "Iranian Rial", pos: "before", value: "Rial" },
{ name: "New Israeli Shekel", pos: "before", value: "?" },
{ name: "Indian Rupee", pos: "before", value: "?" },
{ name: "Indian Rupee", pos: "before", value: "" },
{ name: "Indonesian Rupiah", pos: "before", value: "Rp" },
{ name: "Jordanian Dinar", pos: "before", value: "din" },
{ name: "VND", pos: "after", value: "?" },
@ -11226,6 +11226,11 @@ export default {
{ name: "Chilean Peso", pos: "before", value: "$" },
{ name: "CFA Franc BEAC", pos: "before", value: "FCFA" },
],
numberFmtList: [
{ name: "Volts", pos: "after", value: "V" },
{ name: "Ampere", pos: "after", value: "A" },
{ name: "Ohms", pos: "after", value: "Ω" },
],
defaultFmt: (currency: string) => [
{ text: "Automatic", value: "General", example: "" },
{ text: "Plain text", value: "@", example: "" },

View File

@ -11199,6 +11199,11 @@ export default {
ChileanPeso: "Chilean Peso",
CFAFrancBEAC: "CFA Franc BEAC",
},
numberFmtList: [
{ name: "Volts", pos: "after", value: "V" },
{ name: "Ampere", pos: "after", value: "A" },
{ name: "Ohms", pos: "after", value: "Ω" },
],
defaultFmt: (currency: string) => [
{ text: "Automático", value: "General", example: "" },
{ text: "Texto", value: "@", example: "" },

View File

@ -11232,6 +11232,11 @@ export default {
{ name: "चिली पेसो", pos: "before", value: "$" },
{ name: "सीएफए फ्रैंक बीईएसी", pos: "before", value: "FCFA" },
],
numberFmtList: [
{ name: "Volts", pos: "after", value: "V" },
{ name: "Ampere", pos: "after", value: "A" },
{ name: "Ohms", pos: "after", value: "Ω" },
],
defaultFmt: (currency: string) => [
{ text: "स्वचालित", value: "General", example: "" },
{ text: "सादा टेक्स्ट", value: "@", example: "" },

View File

@ -11209,6 +11209,11 @@ export default {
{ name: "智利比索", pos: "before", value: "$" },
{ name: "中非金融合作法郎", pos: "before", value: "FCFA" },
],
numberFmtList: [
{ name: "Volts", pos: "after", value: "V" },
{ name: "Ampere", pos: "after", value: "A" },
{ name: "Ohms", pos: "after", value: "Ω" },
],
defaultFmt: (currency: string) => [
{ text: "自动", value: "General", example: "" },
{ text: "纯文本", value: "@", example: "" },

View File

@ -11176,6 +11176,11 @@ export default {
ChileanPeso: "智利比索",
CFAFrancBEAC: "中非金融合作法郎",
},
numberFmtList: [
{ name: "Volts", pos: "after", value: "V" },
{ name: "Ampere", pos: "after", value: "A" },
{ name: "Ohms", pos: "after", value: "Ω" },
],
defaultFmt: (currency: string) => [
{ text: "自動", value: "General", example: "" },
{ text: "純文字", value: "@", example: "" },

View File

@ -1418,7 +1418,7 @@ const make_ssf = function make_ssf(SSF) {
default:
// if ("¤฿BsBr₵₡₫ƒFtRs.₭kr£₤Lm₥₦₱PQRSkRp৲৳R$S/.〒₮₩¥NT¥zł₴₪៛руб,$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP".indexOf(c) === -1) throw new Error('unrecognized character ' + c + ' in ' + fmt);
if (
"¤฿BsBr₵₡₫ƒFtRs.₭kr£₤Lm₥₦₱PQRSkRp৲৳R$S/.〒₮₩¥NT¥zł₴₪៛руб€₹,$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP$¥LekdinAf$dhAflRial?£BirrKzMOPPGKRsGsB/R$ррlevkrKMzBsPNuFBuKPkrRD$NfkCFA?CVEGMDFrCDHTGNAfLFdjKGSFGGHSRielKCFknKshLSLL£LtRFRONArRfMWKRMMURsMROS/KMDLMTnRC$kr€GELCHFSLLSCRDbSZLSDGSOSSomFCFPTShT$VUVQUGXгрнsomWSTNT$FtDramRpZMWFCFA".indexOf(
"Ω¤฿BsBr₵₡₫ƒFtRs.₭kr£₤Lm₥₦₱PQRSkRp৲৳R$S/.〒₮₩¥NT¥zł₴₪៛руб€₹,$-+/():!^&'~{}<>=€acfijklopqrtuvwxzP$¥LekdinAf$dhAflRial?£BirrKzMOPPGKRsGsB/R$ррlevkrKMzBsPNuFBuKPkrRD$NfkCFA?CVEGMDFrCDHTGNAfLFdjKGSFGGHSRielKCFknKshLSLL£LtRFRONArRfMWKRMMURsMROS/KMDLMTnRC$kr€GELCHFSLLSCRDbSZLSDGSOSSomFCFPTShT$VUVQUGXгрнsomWSTNT$FtDramRpZMWFCFA".indexOf(
c
) === -1
)

View File

@ -21,15 +21,16 @@ export const FormatSearch: React.FC<{
} = useContext(WorkbookContext);
const [decimalPlace, setDecimalPlace] = useState(2);
const [selectedFormatIndex, setSelectedFormatIndex] = useState(0);
const { button, format, currencyDetail, dateFmtList } = locale(context);
const { button, format, currencyDetail, dateFmtList, numberFmtList } =
locale(context);
const { showDialog } = useDialog();
const toolbarFormatAll = useMemo(
() => ({
currency: currencyDetail,
date: dateFmtList,
number: [], // has not been defined
number: numberFmtList,
}),
[currencyDetail, dateFmtList]
[currencyDetail, dateFmtList, numberFmtList]
);
const toolbarFormat = useMemo(
() => toolbarFormatAll[type],
@ -46,7 +47,8 @@ export const FormatSearch: React.FC<{
setContext((ctx) => {
const index = getSheetIndex(ctx, ctx.currentSheetId);
if (_.isNil(index)) return;
const selectedFormat = toolbarFormat[selectedFormatIndex].value;
const selectedFormatVal = toolbarFormat[selectedFormatIndex].value;
const selectedFormatPos = toolbarFormat[selectedFormatIndex].pos;
_.forEach(ctx.luckysheet_select_save, (selection) => {
for (let r = selection.row[0]; r <= selection.row[1]; r += 1) {
for (let c = selection.column[0]; c <= selection.column[1]; c += 1) {
@ -55,12 +57,22 @@ export const FormatSearch: React.FC<{
ctx.luckysheetfile[index].data?.[r][c]?.ct?.t === "n"
) {
const zero = 0;
ctx.luckysheetfile[index].data![r][c]!.ct!.fa =
`${selectedFormat}`.concat(zero.toFixed(decimalPlace));
ctx.luckysheetfile[index].data![r][c]!.m = update(
`${selectedFormat}`.concat(zero.toFixed(decimalPlace)),
ctx.luckysheetfile[index].data![r][c]!.v
);
if (selectedFormatPos === "after") {
ctx.luckysheetfile[index].data![r][c]!.ct!.fa = zero
.toFixed(decimalPlace)
.concat(`${selectedFormatVal}`);
ctx.luckysheetfile[index].data![r][c]!.m = update(
zero.toFixed(decimalPlace).concat(`${selectedFormatVal}`),
ctx.luckysheetfile[index].data![r][c]!.v
);
} else {
ctx.luckysheetfile[index].data![r][c]!.ct!.fa =
`${selectedFormatVal}`.concat(zero.toFixed(decimalPlace));
ctx.luckysheetfile[index].data![r][c]!.m = update(
`${selectedFormatVal}`.concat(zero.toFixed(decimalPlace)),
ctx.luckysheetfile[index].data![r][c]!.v
);
}
}
}
}
@ -94,12 +106,7 @@ export const FormatSearch: React.FC<{
{tips}
{format.format}
</div>
<div
className="inpbox"
style={
type === "currency" ? { display: "block" } : { display: "none" }
}
>
<div className="inpbox" style={{ display: "block" }}>
{format.decimalPlaces}
<input
className="decimal-places-input"
@ -131,7 +138,7 @@ export const FormatSearch: React.FC<{
</div>
<div
className="fortune-dialog-box-button-container"
style={type === "currency" ? { marginTop: 40 } : { marginTop: 30 }}
style={{ marginTop: 40 }}
>
<div
className="fortune-message-box-button button-primary"

View File

@ -315,6 +315,18 @@ const Toolbar: React.FC<{
setOpen(false);
},
},
{
text: toolbarFormat.moreNumber,
onclick: () => {
showDialog(
<FormatSearch
onCancel={hideDialog}
type="number"
/>
);
setOpen(false);
},
},
].map((v) => (
<div
className="set-background-item fortune-toolbar-select-option"