fix: Right-click menu insert image option doesn't work

This commit is contained in:
ice_win_linux 2023-06-16 09:39:59 +08:00
parent b5b5a530c7
commit 6fa630c22f
2 changed files with 27 additions and 28 deletions

View File

@ -31,6 +31,7 @@ import {
fixRowStyleOverflowInFreeze,
fixColumnStyleOverflowInFreeze,
handleKeydownForZoom,
insertImage,
} from "@fortune-sheet/core";
import _ from "lodash";
import WorkbookContext, { SetContextOptions } from "../../context";
@ -428,6 +429,31 @@ const SheetOverlay: React.FC = () => {
<RowHeader />
<ScrollBar axis="x" />
<ScrollBar axis="y" />
<input
id="fortune-img-upload"
type="file"
accept="image/*"
style={{ display: "none" }}
onChange={(e) => {
const file = e.currentTarget.files?.[0];
if (!file) return;
const render = new FileReader();
render.readAsDataURL(file);
render.onload = (event) => {
if (event.target == null) return;
const src = event.target?.result;
const image = new Image();
image.onload = () => {
setContext((draftCtx) => {
insertImage(draftCtx, image);
});
};
image.src = src as string;
};
e.currentTarget.value = "";
}}
/>
<div
ref={refs.cellArea}
className="fortune-cell-area"

View File

@ -24,7 +24,6 @@ import {
handleBorder,
toolbarItemSelectedFunc,
handleFreeze,
insertImage,
showImgChooser,
updateFormat,
handleSort,
@ -846,33 +845,7 @@ const Toolbar: React.FC<{
if (context.allowEdit === false) return;
showImgChooser();
}}
>
<input
id="fortune-img-upload"
type="file"
accept="image/*"
style={{ display: "none" }}
onChange={(e) => {
const file = e.currentTarget.files?.[0];
if (!file) return;
const render = new FileReader();
render.readAsDataURL(file);
render.onload = (event) => {
if (event.target == null) return;
const src = event.target?.result;
const image = new Image();
image.onload = () => {
setContext((draftCtx) => {
insertImage(draftCtx, image);
});
};
image.src = src as string;
};
e.currentTarget.value = "";
}}
/>
</Button>
/>
);
}
if (name === "comment") {