Preserve QExcell font families
This commit is contained in:
@@ -82,6 +82,7 @@ const horizontalAlignOptions = [
|
||||
{ value: "center", label: "По центру", icon: AlignCenter },
|
||||
{ value: "right", label: "По правому краю", icon: AlignRight }
|
||||
] as const;
|
||||
const fontFamilyOptions = ["Aptos", "Arial", "Courier New", "Times New Roman"];
|
||||
const fontSizeOptions = [10, 11, 12, 14, 16, 18, 20, 24];
|
||||
|
||||
function normalizedLinkInput(value: string | null) {
|
||||
@@ -111,12 +112,14 @@ function normalizedCellFormat(format: CellFormat): CellFormat | undefined {
|
||||
const horizontalAlign = normalizedHorizontalAlign(format.horizontalAlign);
|
||||
const numberFormat = format.numberFormat?.trim();
|
||||
const fontSize = normalizedFontSize(format.fontSize);
|
||||
const fontFamily = normalizedFontFamily(format.fontFamily);
|
||||
const normalized: CellFormat = {
|
||||
...(format.bold ? { bold: true } : {}),
|
||||
...(format.italics ? { italics: true } : {}),
|
||||
...(format.underline ? { underline: true } : {}),
|
||||
...(format.strike ? { strike: true } : {}),
|
||||
...(fontSize ? { fontSize } : {}),
|
||||
...(fontFamily ? { fontFamily } : {}),
|
||||
...(textColor ? { textColor } : {}),
|
||||
...(fillColor ? { fillColor } : {}),
|
||||
...(horizontalAlign ? { horizontalAlign } : {}),
|
||||
@@ -133,6 +136,7 @@ function cellInputStyle(format?: CellFormat): CSSProperties {
|
||||
...(format?.italics ? { fontStyle: "italic" } : {}),
|
||||
...(textDecoration ? { textDecoration } : {}),
|
||||
...(format?.fontSize ? { fontSize: `${format.fontSize}pt` } : {}),
|
||||
...(format?.fontFamily ? { fontFamily: format.fontFamily } : {}),
|
||||
...(format?.textColor ? { color: `#${format.textColor}` } : {}),
|
||||
...(format?.fillColor ? { backgroundColor: `#${format.fillColor}` } : {}),
|
||||
...(format?.horizontalAlign ? { textAlign: format.horizontalAlign } : {})
|
||||
@@ -152,6 +156,11 @@ function normalizedFontSize(value?: number) {
|
||||
return normalized === 11 ? undefined : normalized;
|
||||
}
|
||||
|
||||
function normalizedFontFamily(value?: string) {
|
||||
const normalized = value?.trim().replace(/["<>]/g, "").slice(0, 80) ?? "";
|
||||
return normalized && normalized.toLowerCase() !== "calibri" ? normalized : "";
|
||||
}
|
||||
|
||||
function normalizedChartRange(value: string) {
|
||||
const raw = value.trim().replace(/\$/g, "").toUpperCase();
|
||||
const [start, end = start] = raw.split(":");
|
||||
@@ -497,8 +506,8 @@ export function QExcell({ workbook, onChange }: QExcellProps) {
|
||||
className={`icon-button format-toggle ${selectedCellFormat.strike ? "is-active" : ""}`.trim()}
|
||||
type="button"
|
||||
onClick={() => toggleSelectedFormat("strike")}
|
||||
title="Зачеркнуть"
|
||||
aria-label="Зачеркнуть"
|
||||
title="Зачеркнуть"
|
||||
aria-label="Зачеркнуть"
|
||||
>
|
||||
<Strikethrough size={16} />
|
||||
</button>
|
||||
@@ -518,6 +527,19 @@ export function QExcell({ workbook, onChange }: QExcellProps) {
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
<select
|
||||
value={selectedCellFormat.fontFamily ?? ""}
|
||||
onChange={(event) => updateCellFormat(selectedCell, { fontFamily: event.target.value || undefined })}
|
||||
aria-label="Семейство шрифта"
|
||||
title="Семейство шрифта"
|
||||
>
|
||||
<option value="">Calibri</option>
|
||||
{fontFamilyOptions.map((fontFamily) => (
|
||||
<option key={fontFamily} value={fontFamily}>
|
||||
{fontFamily}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={selectedCellFormat.fontSize ?? ""}
|
||||
onChange={(event) =>
|
||||
|
||||
Reference in New Issue
Block a user