MCPcopy Create free account
hub / github.com/Sethispr/image-compressor / handleWindowPaste

Function handleWindowPaste

components/Dropzone.tsx:111–149  ·  view source on GitHub ↗
(e: ClipboardEvent)

Source from the content-addressed store, hash-verified

109 };
110
111 const handleWindowPaste = (e: ClipboardEvent) => {
112 const clipboardData = e.clipboardData;
113 if (!clipboardData) return;
114
115 const extractedFiles: File[] = [];
116
117 if (clipboardData.items) {
118 for (let i = 0; i < clipboardData.items.length; i++) {
119 const item = clipboardData.items[i];
120
121 if (item.kind === 'file') {
122 const file = item.getAsFile();
123 if (
124 file &&
125 (file.type.startsWith('image/') || file.type.includes('svg'))
126 ) {
127 if (
128 file.name === 'image.png' ||
129 file.name.startsWith('Screenshot')
130 ) {
131 const timestamp = new Date().getTime();
132 const ext = file.type.split('/')[1] || 'png';
133 const newName = `pasted_${timestamp}_${i}.${ext}`;
134 extractedFiles.push(
135 new File([file], newName, {type: file.type}),
136 );
137 } else {
138 extractedFiles.push(file);
139 }
140 }
141 }
142 }
143 }
144
145 if (extractedFiles.length > 0) {
146 e.preventDefault();
147 onFilesAdded(extractedFiles);
148 }
149 };
150
151 window.addEventListener('dragenter', handleWindowDragEnter);
152 window.addEventListener('dragleave', handleWindowDragLeave);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected