Compare commits
2 Commits
feature/da
...
v0.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9a8c4f615 | ||
|
|
f9c9467e6c |
@@ -170,7 +170,7 @@ fn row_heigh_increases_automatically() {
|
||||
model
|
||||
.set_user_input(0, 1, 1, "My home in Canada had horses\nAnd monkeys!")
|
||||
.unwrap();
|
||||
assert_eq!(model.get_row_height(0, 1), Ok(2.0 * DEFAULT_ROW_HEIGHT));
|
||||
assert_eq!(model.get_row_height(0, 1), Ok(40.5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -6,7 +6,7 @@ use csv::{ReaderBuilder, WriterBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
constants::{self, DEFAULT_ROW_HEIGHT, LAST_COLUMN, LAST_ROW},
|
||||
constants::{self, LAST_COLUMN, LAST_ROW},
|
||||
expressions::{
|
||||
types::{Area, CellReferenceIndex},
|
||||
utils::{is_valid_column_number, is_valid_row},
|
||||
@@ -430,10 +430,14 @@ impl UserModel {
|
||||
new_value: value.to_string(),
|
||||
old_value: Box::new(old_value),
|
||||
}];
|
||||
let style = self.model.get_style_for_cell(sheet, row, column)?;
|
||||
|
||||
let line_count = value.split('\n').count();
|
||||
let line_count = value.split('\n').count() as f64;
|
||||
let row_height = self.model.get_row_height(sheet, row)?;
|
||||
let cell_height = (line_count as f64) * DEFAULT_ROW_HEIGHT;
|
||||
// This is in sync with the front-end auto fit row
|
||||
let font_size = style.font.sz as f64;
|
||||
let line_height = font_size * 1.5;
|
||||
let cell_height = (line_count - 1.0) * line_height + 8.0 + font_size;
|
||||
if cell_height > row_height {
|
||||
diff_list.push(Diff::SetRowHeight {
|
||||
sheet,
|
||||
|
||||
@@ -497,7 +497,7 @@ export default class WorksheetCanvas {
|
||||
context.clip();
|
||||
|
||||
// Is there any better parameter?
|
||||
const lineHeight = 22;
|
||||
const lineHeight = fontSize * 1.5;
|
||||
const lines = fullText.split("\n");
|
||||
const lineCount = lines.length;
|
||||
|
||||
@@ -608,14 +608,16 @@ export default class WorksheetCanvas {
|
||||
const sheet = this.model.getSelectedSheet();
|
||||
const rows = this.model.getRowsWithData(sheet, column);
|
||||
let width = 0;
|
||||
// This is a bit of a HACK. We should use the actual font size and weather is bold or not
|
||||
const fontSize = 13;
|
||||
this.ctx.font = `${fontSize}px ${defaultCellFontFamily}`;
|
||||
for (const row of rows) {
|
||||
const fullText = this.model.getFormattedCellValue(sheet, row, column);
|
||||
if (fullText === "") {
|
||||
continue;
|
||||
}
|
||||
const style = this.model.getCellStyle(sheet, row, column);
|
||||
const fontSize = style.font.sz;
|
||||
let font = `${fontSize}px ${defaultCellFontFamily}`;
|
||||
font = style.font.b ? `bold ${font}` : `400 ${font}`;
|
||||
this.ctx.font = font;
|
||||
const lines = fullText.split("\n");
|
||||
for (const line of lines) {
|
||||
const textWidth = this.ctx.measureText(line).width;
|
||||
@@ -675,18 +677,20 @@ export default class WorksheetCanvas {
|
||||
const sheet = this.model.getSelectedSheet();
|
||||
const columns = this.model.getColumnsWithData(sheet, row);
|
||||
let height = 0;
|
||||
const lineHeight = 22;
|
||||
// This is a bit of a HACK. We should use the actual font size and weather is bold or not
|
||||
const fontSize = 13;
|
||||
this.ctx.font = `${fontSize}px ${defaultCellFontFamily}`;
|
||||
for (const column of columns) {
|
||||
const fullText = this.model.getFormattedCellValue(sheet, row, column);
|
||||
if (fullText === "") {
|
||||
continue;
|
||||
}
|
||||
const style = this.model.getCellStyle(sheet, row, column);
|
||||
const fontSize = style.font.sz;
|
||||
const lineHeight = fontSize * 1.5;
|
||||
let font = `${fontSize}px ${defaultCellFontFamily}`;
|
||||
font = style.font.b ? `bold ${font}` : `400 ${font}`;
|
||||
this.ctx.font = font;
|
||||
const lines = fullText.split("\n");
|
||||
const lineCount = lines.length;
|
||||
// This si computed so that the y position of the text is independent of the vertical alignment
|
||||
// This is computed so that the y position of the text is independent of the vertical alignment
|
||||
const textHeight = (lineCount - 1) * lineHeight + 8 + fontSize;
|
||||
height = Math.max(height, textHeight);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"@ironcalc/workbook": "file:../../IronCalc/",
|
||||
"@mui/material": "^6.4",
|
||||
"lucide-react": "^0.473.0",
|
||||
"qrcode.react": "^4.2.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
@@ -2487,6 +2488,14 @@
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
||||
},
|
||||
"node_modules/qrcode.react": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/qrcode.react/-/qrcode.react-4.2.0.tgz",
|
||||
"integrity": "sha512-QpgqWi8rD9DsS9EP3z7BT+5lY5SFhsqGjpgW5DY/i3mK4M9DTBNz3ErMi8BWYEfI3L0d8GIbGmcdFAS1uIRGjA==",
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react": {
|
||||
"version": "19.0.0",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-19.0.0.tgz",
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"@ironcalc/workbook": "file:../../IronCalc/",
|
||||
"@mui/material": "^6.4",
|
||||
"lucide-react": "^0.473.0",
|
||||
"qrcode.react": "^4.2.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0"
|
||||
},
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import styled from "@emotion/styled";
|
||||
import type { Model } from "@ironcalc/workbook";
|
||||
import { IronCalcIcon, IronCalcLogo } from "@ironcalc/workbook";
|
||||
import { CircleCheck } from "lucide-react";
|
||||
import { useRef, useState } from "react";
|
||||
// import { IronCalcIcon, IronCalcLogo } from "./../icons";
|
||||
import { FileMenu } from "./FileMenu";
|
||||
import { ShareButton } from "./ShareButton";
|
||||
import ShareWorkbookDialog from "./ShareWorkbookDialog";
|
||||
import { WorkbookTitle } from "./WorkbookTitle";
|
||||
import { downloadModel, shareModel } from "./rpc";
|
||||
import { downloadModel } from "./rpc";
|
||||
import { updateNameSelectedWorkbook } from "./storage";
|
||||
|
||||
export function FileBar(properties: {
|
||||
@@ -18,7 +17,8 @@ export function FileBar(properties: {
|
||||
onDelete: () => void;
|
||||
}) {
|
||||
const hiddenInputRef = useRef<HTMLInputElement>(null);
|
||||
const [toast, setToast] = useState(false);
|
||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<FileBarWrapper>
|
||||
<StyledDesktopLogo />
|
||||
@@ -53,37 +53,17 @@ export function FileBar(properties: {
|
||||
type="text"
|
||||
style={{ position: "absolute", left: -9999, top: -9999 }}
|
||||
/>
|
||||
<div style={{ marginLeft: "auto" }}>
|
||||
{toast ? (
|
||||
<Toast>
|
||||
<CircleCheck style={{ width: 12 }} />
|
||||
<span
|
||||
style={{ marginLeft: 8, marginRight: 12, fontFamily: "Inter" }}
|
||||
>
|
||||
URL copied to clipboard
|
||||
</span>
|
||||
</Toast>
|
||||
) : (
|
||||
""
|
||||
<div style={{ marginLeft: "auto" }} />
|
||||
<DialogContainer>
|
||||
<ShareButton onClick={() => setIsDialogOpen(true)} />
|
||||
{isDialogOpen && (
|
||||
<ShareWorkbookDialog
|
||||
onClose={() => setIsDialogOpen(false)}
|
||||
onModelUpload={properties.onModelUpload}
|
||||
model={properties.model}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<ShareButton
|
||||
onClick={async () => {
|
||||
const model = properties.model;
|
||||
const bytes = model.toBytes();
|
||||
const fileName = model.getName();
|
||||
const hash = await shareModel(bytes, fileName);
|
||||
const value = `${location.origin}/?model=${hash}`;
|
||||
if (hiddenInputRef.current) {
|
||||
hiddenInputRef.current.value = value;
|
||||
hiddenInputRef.current.select();
|
||||
document.execCommand("copy");
|
||||
setToast(true);
|
||||
setTimeout(() => setToast(false), 5000);
|
||||
}
|
||||
console.log(value);
|
||||
}}
|
||||
/>
|
||||
</DialogContainer>
|
||||
</FileBarWrapper>
|
||||
);
|
||||
}
|
||||
@@ -117,14 +97,6 @@ const HelpButton = styled("div")`
|
||||
}
|
||||
`;
|
||||
|
||||
const Toast = styled("div")`
|
||||
font-weight: 400;
|
||||
font-size: 12px;
|
||||
color: #9e9e9e;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
`;
|
||||
|
||||
const Divider = styled("div")`
|
||||
margin: 0px 8px 0px 16px;
|
||||
height: 12px;
|
||||
@@ -141,3 +113,17 @@ const FileBarWrapper = styled("div")`
|
||||
position: relative;
|
||||
justify-content: space-between;
|
||||
`;
|
||||
|
||||
const DialogContainer = styled("div")`
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
button {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.MuiDialog-root {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
transform: translateY(8px);
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
import type { Model } from "@ironcalc/workbook";
|
||||
import { Button, Dialog, TextField, styled } from "@mui/material";
|
||||
import { Check, Copy, GlobeLock } from "lucide-react";
|
||||
import { QRCodeSVG } from "qrcode.react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { shareModel } from "./rpc";
|
||||
|
||||
function ShareWorkbookDialog(properties: {
|
||||
onClose: () => void;
|
||||
onModelUpload: (blob: ArrayBuffer, fileName: string) => Promise<void>;
|
||||
model?: Model;
|
||||
}) {
|
||||
const [url, setUrl] = useState<string>("");
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const generateUrl = async () => {
|
||||
if (properties.model) {
|
||||
const bytes = properties.model.toBytes();
|
||||
const fileName = properties.model.getName();
|
||||
const hash = await shareModel(bytes, fileName);
|
||||
setUrl(`${location.origin}/?model=${hash}`);
|
||||
}
|
||||
};
|
||||
generateUrl();
|
||||
}, [properties.model]);
|
||||
|
||||
useEffect(() => {
|
||||
let timeoutId: ReturnType<typeof setTimeout>;
|
||||
if (copied) {
|
||||
timeoutId = setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 2000);
|
||||
}
|
||||
return () => {
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
}, [copied]);
|
||||
|
||||
const handleClose = () => {
|
||||
properties.onClose();
|
||||
};
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
setCopied(true);
|
||||
} catch (err) {
|
||||
console.error("Failed to copy text: ", err);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogWrapper
|
||||
open={true}
|
||||
tabIndex={0}
|
||||
onClose={handleClose}
|
||||
onKeyDown={(event) => {
|
||||
if (event.code === "Escape") {
|
||||
handleClose();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DialogContent>
|
||||
<QRCodeWrapper>
|
||||
<QRCodeSVG value={url} size={80} />{" "}
|
||||
</QRCodeWrapper>
|
||||
<URLWrapper>
|
||||
<StyledTextField
|
||||
hiddenLabel
|
||||
disabled
|
||||
value={url}
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
margin="normal"
|
||||
size="small"
|
||||
/>
|
||||
<StyledButton
|
||||
variant="contained"
|
||||
color="primary"
|
||||
size="small"
|
||||
onClick={handleCopy}
|
||||
>
|
||||
{copied ? <StyledCheck /> : <StyledCopy />}
|
||||
{copied ? "Copied!" : "Copy URL"}
|
||||
</StyledButton>
|
||||
</URLWrapper>
|
||||
</DialogContent>
|
||||
|
||||
<UploadFooter>
|
||||
<GlobeLock />
|
||||
Anyone with the link will be able to access a copy of this workbook
|
||||
</UploadFooter>
|
||||
</DialogWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
const DialogWrapper = styled(Dialog)`
|
||||
.MuiDialog-paper {
|
||||
width: 440px;
|
||||
position: absolute;
|
||||
top: 44px;
|
||||
right: 0px;
|
||||
margin: 10px;
|
||||
max-width: calc(100% - 20px);
|
||||
}
|
||||
.MuiBackdrop-root {
|
||||
background-color: transparent;
|
||||
}
|
||||
`;
|
||||
|
||||
const DialogContent = styled("div")`
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 12px;
|
||||
height: 80px;
|
||||
`;
|
||||
|
||||
const URLWrapper = styled("div")`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
`;
|
||||
|
||||
const StyledTextField = styled(TextField)`
|
||||
margin: 0px;
|
||||
.MuiInputBase-root {
|
||||
max-height: 36px;
|
||||
font-size: 14px;
|
||||
padding-top: 0px;
|
||||
}
|
||||
.MuiOutlinedInput-input {
|
||||
text-overflow: ellipsis;
|
||||
padding: 8px;
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledButton = styled(Button)`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 4px;
|
||||
background-color: #eeeeee;
|
||||
height: 36px;
|
||||
color: #616161;
|
||||
box-shadow: none;
|
||||
font-size: 14px;
|
||||
text-transform: capitalize;
|
||||
gap: 10px;
|
||||
&:hover {
|
||||
background-color: #e0e0e0;
|
||||
box-shadow: none;
|
||||
}
|
||||
&:active {
|
||||
background-color: #d4d4d4;
|
||||
box-shadow: none;
|
||||
}
|
||||
`;
|
||||
|
||||
const StyledCopy = styled(Copy)`
|
||||
width: 16px;
|
||||
`;
|
||||
|
||||
const StyledCheck = styled(Check)`
|
||||
width: 16px;
|
||||
`;
|
||||
|
||||
const QRCodeWrapper = styled("div")`
|
||||
min-height: 80px;
|
||||
min-width: 80px;
|
||||
background-color: grey;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
@media (max-width: 600px) {
|
||||
display: none;
|
||||
}
|
||||
`;
|
||||
|
||||
const UploadFooter = styled("div")`
|
||||
height: 44px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
color: #757575;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-family: Inter;
|
||||
gap: 8px;
|
||||
padding: 0px 12px;
|
||||
svg {
|
||||
max-width: 16px;
|
||||
}
|
||||
`;
|
||||
|
||||
export default ShareWorkbookDialog;
|
||||
Reference in New Issue
Block a user