add click-to-select for stock image table rows
Hunter
Wednesday, January 14th, 2026 at 11:48 AM
45 const images = Array.from(stockImages.values()).sort();
46 if (images.length === 0) return '<p>No images available</p>';
47 const rows = images.map(filename =>
- `<tr><td>${filename}</td><td style="text-align:center;"><img src="images/${filename}" style="max-width:100%;height:auto;"></td></tr>`
48 + `<tr class="stock-image-row" data-filename="${filename}" style="cursor:pointer;"><td>${filename}</td><td style="text-align:center;"><img src="images/${filename}" style="max-width:100%;height:auto;"></td></tr>`
49 ).join('');
- return `<table border="1" cellpadding="8" cellspacing="0" style="max-width:100%;box-sizing:border-box;table-layout:fixed;"><colgroup><col style="width:50%"><col style="width:50%"></colgroup>${rows}</table>`;
50 + return `<table class="stock-image-table" border="1" cellpadding="8" cellspacing="0" style="max-width:100%;box-sizing:border-box;table-layout:fixed;"><colgroup><col style="width:50%"><col style="width:50%"></colgroup>${rows}</table>`;
51 });
52 }
53 const editorPane = document.querySelector('.editor-pane');
203 doc.body.appendChild(button);
204 }
205
206 + // Add click handlers for stock image table rows
207 + const stockImageRows = doc.querySelectorAll('.stock-image-row');
208 + stockImageRows.forEach(row => {
209 + row.addEventListener('click', () => {
210 + const filename = row.getAttribute('data-filename');
211 + if (!filename) return;
212 +
213 + // Find and replace <img src="?"> in the editor
214 + const editorContent = editorView.state.doc.toString();
215 + const imgPattern = /<img\s+src\s*=\s*["']?\?["']?\s*\/?>/i;
216 + const match = editorContent.match(imgPattern);
217 +
218 + if (match) {
219 + const start = editorContent.indexOf(match[0]);
220 + const end = start + match[0].length;
221 + const replacement = `<img src="${filename}">`;
222 +
223 + editorView.dispatch({
224 + changes: { from: start, to: end, insert: replacement }
225 + });
226 + saveToStorage();
227 + updatePreview();
228 + }
229 + });
230 + });
231 +
232 // Restore scroll position
233 setTimeout(() => {
234 try {