2026-01-05 14:57:30 +05:30
|
|
|
import { AddAttachmentState } from '@/types';
|
2025-12-11 19:34:14 +05:30
|
|
|
import { showLoader, hideLoader, showAlert } from '../ui.js';
|
|
|
|
|
import { downloadFile, formatBytes } from '../utils/helpers.js';
|
|
|
|
|
import { createIcons, icons } from 'lucide';
|
|
|
|
|
import { PDFDocument as PDFLibDocument } from 'pdf-lib';
|
2026-01-27 15:26:11 +05:30
|
|
|
import { isCpdfAvailable } from '../utils/cpdf-helper.js';
|
|
|
|
|
import {
|
|
|
|
|
showWasmRequiredDialog,
|
|
|
|
|
WasmProvider,
|
|
|
|
|
} from '../utils/wasm-provider.js';
|
2026-03-26 12:11:12 +05:30
|
|
|
import { loadPdfWithPasswordPrompt } from '../utils/password-prompt.js';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const worker = new Worker(
|
|
|
|
|
import.meta.env.BASE_URL + 'workers/add-attachments.worker.js'
|
|
|
|
|
);
|
2025-12-11 19:34:14 +05:30
|
|
|
|
|
|
|
|
const pageState: AddAttachmentState = {
|
2026-01-27 15:26:11 +05:30
|
|
|
file: null,
|
|
|
|
|
pdfDoc: null,
|
|
|
|
|
attachments: [],
|
2025-12-11 19:34:14 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function resetState() {
|
2026-01-27 15:26:11 +05:30
|
|
|
pageState.file = null;
|
|
|
|
|
pageState.pdfDoc = null;
|
|
|
|
|
pageState.attachments = [];
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const fileDisplayArea = document.getElementById('file-display-area');
|
|
|
|
|
if (fileDisplayArea) fileDisplayArea.innerHTML = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const toolOptions = document.getElementById('tool-options');
|
|
|
|
|
if (toolOptions) toolOptions.classList.add('hidden');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const attachmentFileList = document.getElementById('attachment-file-list');
|
|
|
|
|
if (attachmentFileList) attachmentFileList.innerHTML = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const attachmentInput = document.getElementById(
|
|
|
|
|
'attachment-files-input'
|
|
|
|
|
) as HTMLInputElement;
|
|
|
|
|
if (attachmentInput) attachmentInput.value = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const attachmentLevelOptions = document.getElementById(
|
|
|
|
|
'attachment-level-options'
|
|
|
|
|
);
|
|
|
|
|
if (attachmentLevelOptions) attachmentLevelOptions.classList.add('hidden');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const pageRangeWrapper = document.getElementById('page-range-wrapper');
|
|
|
|
|
if (pageRangeWrapper) pageRangeWrapper.classList.add('hidden');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const processBtn = document.getElementById('process-btn');
|
|
|
|
|
if (processBtn) processBtn.classList.add('hidden');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const fileInput = document.getElementById('file-input') as HTMLInputElement;
|
|
|
|
|
if (fileInput) fileInput.value = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const documentRadio = document.querySelector(
|
|
|
|
|
'input[name="attachment-level"][value="document"]'
|
|
|
|
|
) as HTMLInputElement;
|
|
|
|
|
if (documentRadio) documentRadio.checked = true;
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
worker.onmessage = function (e) {
|
2026-01-27 15:26:11 +05:30
|
|
|
const data = e.data;
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (data.status === 'success' && data.modifiedPDF !== undefined) {
|
|
|
|
|
hideLoader();
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const originalName =
|
|
|
|
|
pageState.file?.name.replace(/\.pdf$/i, '') || 'document';
|
|
|
|
|
downloadFile(
|
|
|
|
|
new Blob([new Uint8Array(data.modifiedPDF)], { type: 'application/pdf' }),
|
|
|
|
|
`${originalName}_with_attachments.pdf`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
showAlert(
|
|
|
|
|
'Success',
|
|
|
|
|
`${pageState.attachments.length} file(s) attached successfully.`,
|
|
|
|
|
'success',
|
|
|
|
|
function () {
|
|
|
|
|
resetState();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} else if (data.status === 'error') {
|
|
|
|
|
hideLoader();
|
|
|
|
|
showAlert('Error', data.message || 'Unknown error occurred.');
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
worker.onerror = function (error) {
|
2026-01-27 15:26:11 +05:30
|
|
|
hideLoader();
|
|
|
|
|
console.error('Worker error:', error);
|
|
|
|
|
showAlert('Error', 'Worker error occurred. Check console for details.');
|
2025-12-11 19:34:14 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function updateUI() {
|
2026-01-27 15:26:11 +05:30
|
|
|
const fileDisplayArea = document.getElementById('file-display-area');
|
|
|
|
|
const toolOptions = document.getElementById('tool-options');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (!fileDisplayArea) return;
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
fileDisplayArea.innerHTML = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (pageState.file) {
|
|
|
|
|
const fileDiv = document.createElement('div');
|
|
|
|
|
fileDiv.className =
|
|
|
|
|
'flex items-center justify-between bg-gray-700 p-3 rounded-lg text-sm';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const infoContainer = document.createElement('div');
|
|
|
|
|
infoContainer.className = 'flex flex-col overflow-hidden';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const nameSpan = document.createElement('div');
|
|
|
|
|
nameSpan.className = 'truncate font-medium text-gray-200 text-sm mb-1';
|
|
|
|
|
nameSpan.textContent = pageState.file.name;
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const metaSpan = document.createElement('div');
|
|
|
|
|
metaSpan.className = 'text-xs text-gray-400';
|
|
|
|
|
metaSpan.textContent = `${formatBytes(pageState.file.size)} • Loading...`;
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
infoContainer.append(nameSpan, metaSpan);
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const removeBtn = document.createElement('button');
|
|
|
|
|
removeBtn.className = 'ml-4 text-red-400 hover:text-red-300 flex-shrink-0';
|
|
|
|
|
removeBtn.innerHTML = '<i data-lucide="trash-2" class="w-4 h-4"></i>';
|
|
|
|
|
removeBtn.onclick = function () {
|
|
|
|
|
resetState();
|
|
|
|
|
};
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
fileDiv.append(infoContainer, removeBtn);
|
|
|
|
|
fileDisplayArea.appendChild(fileDiv);
|
|
|
|
|
createIcons({ icons });
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
try {
|
2026-03-26 12:11:12 +05:30
|
|
|
const result = await loadPdfWithPasswordPrompt(pageState.file);
|
|
|
|
|
if (!result) {
|
|
|
|
|
resetState();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
result.pdf.destroy();
|
|
|
|
|
pageState.file = result.file;
|
2026-01-27 15:26:11 +05:30
|
|
|
showLoader('Loading PDF...');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-03-26 12:11:12 +05:30
|
|
|
pageState.pdfDoc = await PDFLibDocument.load(result.bytes);
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const pageCount = pageState.pdfDoc.getPageCount();
|
|
|
|
|
metaSpan.textContent = `${formatBytes(pageState.file.size)} • ${pageCount} pages`;
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const totalPagesSpan = document.getElementById('attachment-total-pages');
|
|
|
|
|
if (totalPagesSpan) totalPagesSpan.textContent = pageCount.toString();
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
hideLoader();
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (toolOptions) toolOptions.classList.remove('hidden');
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error loading PDF:', error);
|
|
|
|
|
hideLoader();
|
|
|
|
|
showAlert('Error', 'Failed to load PDF file.');
|
|
|
|
|
resetState();
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
2026-01-27 15:26:11 +05:30
|
|
|
} else {
|
|
|
|
|
if (toolOptions) toolOptions.classList.add('hidden');
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateAttachmentList() {
|
2026-01-27 15:26:11 +05:30
|
|
|
const attachmentFileList = document.getElementById('attachment-file-list');
|
|
|
|
|
const attachmentLevelOptions = document.getElementById(
|
|
|
|
|
'attachment-level-options'
|
|
|
|
|
);
|
|
|
|
|
const processBtn = document.getElementById('process-btn');
|
|
|
|
|
|
|
|
|
|
if (!attachmentFileList) return;
|
|
|
|
|
|
|
|
|
|
attachmentFileList.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
pageState.attachments.forEach(function (file) {
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
div.className =
|
|
|
|
|
'flex justify-between items-center p-2 bg-gray-800 rounded-md text-white';
|
|
|
|
|
|
|
|
|
|
const nameSpan = document.createElement('span');
|
|
|
|
|
nameSpan.className = 'truncate text-sm';
|
|
|
|
|
nameSpan.textContent = file.name;
|
|
|
|
|
|
|
|
|
|
const sizeSpan = document.createElement('span');
|
|
|
|
|
sizeSpan.className = 'text-xs text-gray-400';
|
|
|
|
|
sizeSpan.textContent = formatBytes(file.size);
|
|
|
|
|
|
|
|
|
|
div.append(nameSpan, sizeSpan);
|
|
|
|
|
attachmentFileList.appendChild(div);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (pageState.attachments.length > 0) {
|
|
|
|
|
if (attachmentLevelOptions)
|
|
|
|
|
attachmentLevelOptions.classList.remove('hidden');
|
|
|
|
|
if (processBtn) processBtn.classList.remove('hidden');
|
|
|
|
|
} else {
|
|
|
|
|
if (attachmentLevelOptions) attachmentLevelOptions.classList.add('hidden');
|
|
|
|
|
if (processBtn) processBtn.classList.add('hidden');
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function addAttachments() {
|
2026-01-27 15:26:11 +05:30
|
|
|
if (!pageState.file || !pageState.pdfDoc) {
|
|
|
|
|
showAlert('Error', 'Please upload a PDF first.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pageState.attachments.length === 0) {
|
|
|
|
|
showAlert('No Files', 'Please select at least one file to attach.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if CPDF is configured
|
|
|
|
|
if (!isCpdfAvailable()) {
|
|
|
|
|
showWasmRequiredDialog('cpdf');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const attachmentLevel =
|
|
|
|
|
(
|
|
|
|
|
document.querySelector(
|
|
|
|
|
'input[name="attachment-level"]:checked'
|
|
|
|
|
) as HTMLInputElement
|
2025-12-11 19:34:14 +05:30
|
|
|
)?.value || 'document';
|
|
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
let pageRange: string = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (attachmentLevel === 'page') {
|
|
|
|
|
const pageRangeInput = document.getElementById(
|
|
|
|
|
'attachment-page-range'
|
|
|
|
|
) as HTMLInputElement;
|
|
|
|
|
pageRange = pageRangeInput?.value?.trim() || '';
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (!pageRange) {
|
|
|
|
|
showAlert(
|
|
|
|
|
'Error',
|
|
|
|
|
'Please specify a page range for page-level attachments.'
|
|
|
|
|
);
|
|
|
|
|
return;
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
2026-01-27 15:26:11 +05:30
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
showLoader('Embedding files into PDF...');
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
try {
|
|
|
|
|
const pdfBuffer = await pageState.file.arrayBuffer();
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const attachmentBuffers: ArrayBuffer[] = [];
|
|
|
|
|
const attachmentNames: string[] = [];
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
for (let i = 0; i < pageState.attachments.length; i++) {
|
|
|
|
|
const file = pageState.attachments[i];
|
|
|
|
|
showLoader(
|
|
|
|
|
`Reading ${file.name} (${i + 1}/${pageState.attachments.length})...`
|
|
|
|
|
);
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
const fileBuffer = await file.arrayBuffer();
|
|
|
|
|
attachmentBuffers.push(fileBuffer);
|
|
|
|
|
attachmentNames.push(file.name);
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
2026-01-27 15:26:11 +05:30
|
|
|
|
|
|
|
|
showLoader('Attaching files to PDF...');
|
|
|
|
|
|
|
|
|
|
const message = {
|
|
|
|
|
command: 'add-attachments',
|
|
|
|
|
pdfBuffer: pdfBuffer,
|
|
|
|
|
attachmentBuffers: attachmentBuffers,
|
|
|
|
|
attachmentNames: attachmentNames,
|
|
|
|
|
attachmentLevel: attachmentLevel,
|
|
|
|
|
pageRange: pageRange,
|
|
|
|
|
cpdfUrl: WasmProvider.getUrl('cpdf')! + 'coherentpdf.browser.min.js',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const transferables = [pdfBuffer, ...attachmentBuffers];
|
|
|
|
|
worker.postMessage(message, transferables);
|
2026-03-26 12:11:12 +05:30
|
|
|
} catch (error) {
|
2026-01-27 15:26:11 +05:30
|
|
|
console.error('Error attaching files:', error);
|
|
|
|
|
hideLoader();
|
2026-03-26 12:11:12 +05:30
|
|
|
showAlert(
|
|
|
|
|
'Error',
|
|
|
|
|
`Failed to attach files: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
|
|
|
);
|
2026-01-27 15:26:11 +05:30
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleFileSelect(files: FileList | null) {
|
2026-01-27 15:26:11 +05:30
|
|
|
if (files && files.length > 0) {
|
|
|
|
|
const file = files[0];
|
|
|
|
|
if (
|
|
|
|
|
file.type === 'application/pdf' ||
|
|
|
|
|
file.name.toLowerCase().endsWith('.pdf')
|
|
|
|
|
) {
|
|
|
|
|
pageState.file = file;
|
|
|
|
|
updateUI();
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
2026-01-27 15:26:11 +05:30
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleAttachmentSelect(files: FileList | null) {
|
2026-01-27 15:26:11 +05:30
|
|
|
if (files && files.length > 0) {
|
|
|
|
|
pageState.attachments = Array.from(files);
|
|
|
|
|
updateAttachmentList();
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
2026-01-27 15:26:11 +05:30
|
|
|
const fileInput = document.getElementById('file-input') as HTMLInputElement;
|
|
|
|
|
const dropZone = document.getElementById('drop-zone');
|
|
|
|
|
const attachmentInput = document.getElementById(
|
|
|
|
|
'attachment-files-input'
|
|
|
|
|
) as HTMLInputElement;
|
|
|
|
|
const attachmentDropZone = document.getElementById('attachment-drop-zone');
|
|
|
|
|
const processBtn = document.getElementById('process-btn');
|
|
|
|
|
const backBtn = document.getElementById('back-to-tools');
|
|
|
|
|
const pageRangeWrapper = document.getElementById('page-range-wrapper');
|
|
|
|
|
|
|
|
|
|
if (backBtn) {
|
|
|
|
|
backBtn.addEventListener('click', function () {
|
|
|
|
|
window.location.href = import.meta.env.BASE_URL;
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (fileInput && dropZone) {
|
|
|
|
|
fileInput.addEventListener('change', function (e) {
|
|
|
|
|
handleFileSelect((e.target as HTMLInputElement).files);
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
dropZone.addEventListener('dragover', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
dropZone.classList.add('bg-gray-700');
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
dropZone.addEventListener('dragleave', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
dropZone.classList.remove('bg-gray-700');
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
dropZone.addEventListener('drop', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
dropZone.classList.remove('bg-gray-700');
|
|
|
|
|
const files = e.dataTransfer?.files;
|
|
|
|
|
if (files && files.length > 0) {
|
|
|
|
|
const pdfFiles = Array.from(files).filter(function (f) {
|
|
|
|
|
return (
|
|
|
|
|
f.type === 'application/pdf' ||
|
|
|
|
|
f.name.toLowerCase().endsWith('.pdf')
|
|
|
|
|
);
|
2025-12-11 19:34:14 +05:30
|
|
|
});
|
2026-01-27 15:26:11 +05:30
|
|
|
if (pdfFiles.length > 0) {
|
|
|
|
|
const dataTransfer = new DataTransfer();
|
|
|
|
|
dataTransfer.items.add(pdfFiles[0]);
|
|
|
|
|
handleFileSelect(dataTransfer.files);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
fileInput.addEventListener('click', function () {
|
|
|
|
|
fileInput.value = '';
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (attachmentInput && attachmentDropZone) {
|
|
|
|
|
attachmentInput.addEventListener('change', function (e) {
|
|
|
|
|
handleAttachmentSelect((e.target as HTMLInputElement).files);
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
attachmentDropZone.addEventListener('dragover', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
attachmentDropZone.classList.add('bg-gray-700');
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
attachmentDropZone.addEventListener('dragleave', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
attachmentDropZone.classList.remove('bg-gray-700');
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
attachmentDropZone.addEventListener('drop', function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
attachmentDropZone.classList.remove('bg-gray-700');
|
|
|
|
|
const files = e.dataTransfer?.files;
|
|
|
|
|
if (files) {
|
|
|
|
|
handleAttachmentSelect(files);
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
attachmentInput.addEventListener('click', function () {
|
|
|
|
|
attachmentInput.value = '';
|
2025-12-11 19:34:14 +05:30
|
|
|
});
|
2026-01-27 15:26:11 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const attachmentLevelRadios = document.querySelectorAll(
|
|
|
|
|
'input[name="attachment-level"]'
|
|
|
|
|
);
|
|
|
|
|
attachmentLevelRadios.forEach(function (radio) {
|
|
|
|
|
radio.addEventListener('change', function (e) {
|
|
|
|
|
const value = (e.target as HTMLInputElement).value;
|
|
|
|
|
if (value === 'page' && pageRangeWrapper) {
|
|
|
|
|
pageRangeWrapper.classList.remove('hidden');
|
|
|
|
|
} else if (pageRangeWrapper) {
|
|
|
|
|
pageRangeWrapper.classList.add('hidden');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-12-11 19:34:14 +05:30
|
|
|
|
2026-01-27 15:26:11 +05:30
|
|
|
if (processBtn) {
|
|
|
|
|
processBtn.addEventListener('click', addAttachments);
|
|
|
|
|
}
|
2025-12-11 19:34:14 +05:30
|
|
|
});
|