Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/react/src/components/SheetOverlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
fixRowStyleOverflowInFreeze,
fixColumnStyleOverflowInFreeze,
handleKeydownForZoom,
insertImage,
} from "@fortune-sheet/core";
import _ from "lodash";
import WorkbookContext, { SetContextOptions } from "../../context";
Expand Down Expand Up @@ -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"
Expand Down
29 changes: 1 addition & 28 deletions packages/react/src/components/Toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
handleBorder,
toolbarItemSelectedFunc,
handleFreeze,
insertImage,
showImgChooser,
updateFormat,
handleSort,
Expand Down Expand Up @@ -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") {
Expand Down