Skip to content

Commit b6a2d1f

Browse files
skeptrunedevcdxker
authored andcommitted
feature: examples + drag and drop fle functionality
1 parent 4e92c58 commit b6a2d1f

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

pdf2md/server/src/templates/demo-ui.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
</div>
113113
</div>
114114
<div
115+
id="drop-zone"
115116
class="mt-4 flex justify-center rounded-lg border border-dashed border-gray-900/25 px-6 py-10"
116117
>
117118
<div class="text-center">
@@ -147,6 +148,35 @@
147148
<p class="text-xs/5 text-gray-600">PDF</p>
148149
</div>
149150
</div>
151+
<div
152+
id="example-buttons-container"
153+
class="flex flex-wrap gap-2 mt-2 w-full justify-center items-center"
154+
>
155+
<button class="hover:border-magenta-500 border">
156+
<img
157+
src="https://cdn.trieve.ai/pdf2md/satellite-market-data-statista.webp"
158+
class="w-28"
159+
/>
160+
</button>
161+
<button class="hover:border-magenta-500 border">
162+
<img
163+
src="https://cdn.trieve.ai/pdf2md/bitcoin-whitepaper-diagram.webp"
164+
class="w-28"
165+
/>
166+
</button>
167+
<button class="hover:border-magenta-500 border">
168+
<img
169+
src="https://cdn.trieve.ai/pdf2md/clutch-install-guide-sscycle.webp"
170+
class="w-28"
171+
/>
172+
</button>
173+
<button class="hover:border-magenta-500 border">
174+
<img
175+
src="https://cdn.trieve.ai/pdf2md/xerox-ui-patent-pg15.webp"
176+
class="w-28"
177+
/>
178+
</button>
179+
</div>
150180
</form>
151181
</div>
152182
<div class="px-4 mt-10 sm:mt-14 md:mt-24 max-w-screen-2xl mx-auto">

pdf2md/server/static/output.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,10 @@ video {
698698
width: 3rem;
699699
}
700700

701+
.w-28 {
702+
width: 7rem;
703+
}
704+
701705
.w-full {
702706
width: 100%;
703707
}
@@ -1172,6 +1176,11 @@ video {
11721176
--tw-ring-offset-width: 2px;
11731177
}
11741178

1179+
.hover\:border-magenta-500:hover {
1180+
--tw-border-opacity: 1;
1181+
border-color: rgb(163 62 181 / var(--tw-border-opacity));
1182+
}
1183+
11751184
.hover\:bg-magenta-500:hover {
11761185
--tw-bg-opacity: 1;
11771186
background-color: rgb(163 62 181 / var(--tw-bg-opacity));

pdf2md/server/static/pdf2md.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,70 @@ copyButton.addEventListener("click", (e) => {
254254
});
255255

256256
const fileUploadInput = document.getElementById("file-upload");
257+
const exampleButtonsContainer = document.getElementById(
258+
"example-buttons-container"
259+
);
260+
exampleButtonsContainer.querySelectorAll("button").forEach((button) => {
261+
button.addEventListener("click", (e) => {
262+
e.preventDefault();
263+
e.stopPropagation();
264+
const imgSrc = button.querySelector("img").getAttribute("src");
265+
const pdfSrc = imgSrc.replace(".webp", ".pdf");
266+
fetch(pdfSrc).then((response) => {
267+
response.blob().then((blob) => {
268+
const file = new File([blob], pdfSrc.split("/").pop(), {
269+
type: "application/pdf",
270+
});
271+
const dataTransfer = new DataTransfer();
272+
dataTransfer.items.add(file);
273+
fileUploadInput.files = dataTransfer.files;
274+
275+
const event = new Event("change", { bubbles: true });
276+
fileUploadInput.dispatchEvent(event);
277+
});
278+
});
279+
});
280+
});
281+
282+
const dropZone = document.getElementById("drop-zone");
283+
const fileInput = document.getElementById("file-upload");
284+
dropZone.addEventListener("dragover", (e) => {
285+
e.preventDefault();
286+
e.stopPropagation();
287+
dropZone.style.borderColor = "#a33eb5";
288+
});
289+
290+
dropZone.addEventListener("dragleave", (e) => {
291+
e.preventDefault();
292+
e.stopPropagation();
293+
dropZone.style.borderColor = "rgba(17, 24, 39, 0.25)";
294+
});
295+
296+
dropZone.addEventListener("drop", handleDrop);
297+
298+
function handleDrop(e) {
299+
e.preventDefault();
300+
e.stopPropagation();
301+
dropZone.style.borderColor = "rgba(17, 24, 39, 0.25)";
302+
303+
const dt = e.dataTransfer;
304+
const files = dt.files;
305+
306+
if (files.length) {
307+
const file = files[0];
308+
309+
if (file.type === "application/pdf") {
310+
const dataTransfer = new DataTransfer();
311+
dataTransfer.items.add(file);
312+
fileInput.files = dataTransfer.files;
313+
314+
const event = new Event("change", { bubbles: true });
315+
fileInput.dispatchEvent(event);
316+
} else {
317+
alert("Please upload a PDF file.");
318+
}
319+
}
320+
}
257321

258322
fileUploadInput.addEventListener("change", (event) => {
259323
const file = event.target.files[0];

0 commit comments

Comments
 (0)