import fs from "fs"; import { clipboard, getCurrentWindow, nativeImage } from "@electron/remote"; import React from "react"; import { observer } from "mobx-react"; import { makeObservable, observable, runInAction } from "mobx"; import { dialog } from "@electron/remote"; import { pathToFileURL } from "url"; import * as notification from "eez-studio-ui/notification"; import type { PropertyProps } from "project-editor/core/object"; import { ProjectContext } from "project-editor/project/context"; import { Icon } from "eez-studio-ui/icon"; export const ImageProperty = observer( class ImageProperty extends React.Component< PropertyProps & { value: any; changeValue: (newValue: any) => void } > { static contextType = ProjectContext; declare context: React.ContextType; constructor(props: any) { super(props); makeObservable(this, { hasClipboardImage: observable }); } interval: any; hasClipboardImage: boolean; componentDidMount(): void { this.interval = setInterval(() => { runInAction(() => { this.hasClipboardImage = clipboard .availableFormats() .find(format => format.indexOf("image/") != -1) != undefined; }); }, 100); } componentWillUnmount(): void { clearInterval(this.interval); } render() { const { propertyInfo, readOnly, value, changeValue } = this.props; const imageValue = value || ""; const embeddedImage = imageValue.startsWith("data:image"); return (
" : imageValue } readOnly /> {embeddedImage && ( )} {this.hasClipboardImage && ( )} {!readOnly && ( )} {imageValue && ( )}
{imageValue && !this.props.propertyInfo.disableBitmapPreview && ( )}
); } } );