UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

31 lines 1.45 kB
/** * 2024-11-04: Copied from PhotoFormWebpart * Sample functions generated by ChatGPT for handling various types of file. * 2024-11-03: Currently tested and used in PasteFormForm.tsx in PhotoForm. * */ // eslint-disable-next-line @rushstack/no-new-null export function handleImagePaste(e, setImageData) { var _a; // Get the clipboard items from the event const clipboardItems = (_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.items; // Loop through each item in the clipboard if (clipboardItems) for (let i = 0; i < (clipboardItems === null || clipboardItems === void 0 ? void 0 : clipboardItems.length); i++) { // Check if the item is an image if (clipboardItems[i].type.indexOf('image') !== -1) { // Get the image file from the clipboard item const file = clipboardItems[i].getAsFile(); // Create a new FileReader instance const reader = new FileReader(); // Define what to do when the file has been read reader.onloadend = function () { // Store the base64 image data setImageData(reader.result); }; // Start reading the image file as a Data URL (base64 format) reader.readAsDataURL(file); } } } //# sourceMappingURL=handlePasteImage.js.map