Skip to content

Commit

Permalink
Merge pull request #631 from Corbe30/feature/custom-number-fmt-v1
Browse files Browse the repository at this point in the history
added: number format support - Volts, ampere, ohms
  • Loading branch information
sanchit3008 authored Nov 25, 2024
2 parents 54f02ad + b7d852d commit ae48208
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 19 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "?" },
Expand All @@ -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: "" },
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/locale/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/locale/hi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/locale/zh_tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/ssf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
41 changes: 24 additions & 17 deletions packages/react/src/components/FormatSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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;

Check failure on line 51 in packages/react/src/components/FormatSearch/index.tsx

View workflow job for this annotation

GitHub Actions / test

Property 'pos' does not exist on type '{ name: string; pos: string; value: string; } | { name: string; pos: string; value: string; } | { name: string; value: string; }'.
_.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) {
Expand All @@ -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
);
}
}
}
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions packages/react/src/components/Toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ae48208

Please sign in to comment.