Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 62 additions & 6 deletions shield-plugin-postgres/static/er.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,79 @@
if (erData) { fitToView(); applySvgTransform(); collabSendViewport(); }
};

window.exportERSvg = function() {
// Build a standalone, content-fitted SVG string shared by all export formats
function buildExportSvg() {
const svg = document.querySelector('#erCanvas svg');
if (!svg) return;
if (!svg) return null;
const bb = getContentBounds();
if (bb.w === 0 || bb.h === 0) return null;
const clone = svg.cloneNode(true);
const g = clone.querySelector('g');
if (g) g.removeAttribute('transform');
const bb = getContentBounds();
const p = 30;
clone.setAttribute('viewBox', (bb.x-p)+' '+(bb.y-p)+' '+(bb.w+p*2)+' '+(bb.h+p*2));
clone.setAttribute('width', bb.w + p * 2);
clone.setAttribute('height', bb.h + p * 2);
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
const blob = new Blob([clone.outerHTML], { type: 'image/svg+xml' });
clone.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
return { svgString: clone.outerHTML, bb: bb, padding: p };
}

function triggerDownload(blob, filename) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url; a.download = 'er-diagram.svg'; a.click();
URL.revokeObjectURL(url);
a.href = url;
a.download = filename;
a.click();
setTimeout(() => URL.revokeObjectURL(url), 0);
}

window.exportERSvg = function() {
const built = buildExportSvg();
if (!built) { showToast('Nothing to export', 'warning'); return; }
triggerDownload(new Blob([built.svgString], { type: 'image/svg+xml;charset=utf-8' }), 'er-diagram.svg');
showToast('SVG exported', 'success');
};

// Rasterize the diagram to PNG (transparent) or JPG (white background)
window.exportERImage = function(format) {
const built = buildExportSvg();
if (!built) { showToast('Nothing to export', 'warning'); return; }

const SCALE = 2; // retina-sharp bitmap
const w = (built.bb.w + built.padding * 2) * SCALE;
const h = (built.bb.h + built.padding * 2) * SCALE;

const url = URL.createObjectURL(new Blob([built.svgString], { type: 'image/svg+xml;charset=utf-8' }));
const img = new Image();

img.onload = function() {
const canvas = document.createElement('canvas');
canvas.width = Math.ceil(w);
canvas.height = Math.ceil(h);
const ctx = canvas.getContext('2d');
if (format === 'jpg') {
ctx.fillStyle = '#ffffff'; // JPG has no alpha — force a white backdrop
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
URL.revokeObjectURL(url);

const mime = format === 'jpg' ? 'image/jpeg' : 'image/png';
const quality = format === 'jpg' ? 0.92 : undefined; // ignored for PNG
canvas.toBlob(function(blob) {
if (!blob) { showToast('Export failed', 'error'); return; }
triggerDownload(blob, 'er-diagram.' + format);
showToast((format === 'jpg' ? 'JPG' : 'PNG') + ' exported', 'success');
}, mime, quality);
};

img.onerror = function() {
URL.revokeObjectURL(url);
showToast('Failed to render diagram', 'error');
};

img.src = url;
};

// ════════════════════════════════════════════
Expand Down
35 changes: 34 additions & 1 deletion shield-plugin-postgres/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@
<button class="btn btn-sm btn-secondary" onclick="erZoom(1/1.2)" title="Zoom Out">&#8722;</button>
<button class="btn btn-sm btn-secondary" onclick="erResetView()" title="Fit View">&#8634; Fit</button>
<button class="btn btn-sm btn-secondary" onclick="erClearLayout()" title="Clear saved layout and re-arrange">&#8635; Reset</button>
<button class="btn btn-sm btn-secondary" onclick="exportERSvg()" title="Export SVG">&#8615; SVG</button>
<button class="btn btn-sm btn-secondary" onclick="showERExportMenu(this)" title="Export diagram (SVG / PNG / JPG)">&#8615; Export</button>
<button class="btn btn-sm btn-secondary" onclick="showExportMenu(document.getElementById('erSchemaSelect').value,null,this)" title="Export SQL">&#8615; SQL</button>
<button class="btn btn-sm btn-secondary" onclick="toggleER()">&#10005; Close</button>
</div>
Expand Down Expand Up @@ -1988,6 +1988,7 @@ <h3>${esc(schema)}.${esc(table)}</h3>

function showExportMenu(schema, table, btn) {
closeExportMenu();
closeERExportMenu(); // keep the two dropdowns mutually exclusive
const menu = document.createElement('div');
menu.className = 'export-dropdown';
menu.id = 'exportDropdown';
Expand Down Expand Up @@ -2015,6 +2016,38 @@ <h3>${esc(schema)}.${esc(table)}</h3>
if (m) m.remove();
}

// ER diagram image export (SVG / PNG / JPG) — see exportERSvg/exportERImage in er.js
function showERExportMenu(btn) {
closeExportMenu(); // keep the two dropdowns mutually exclusive
if (document.getElementById('erExportDropdown')) { closeERExportMenu(); return; }
const menu = document.createElement('div');
menu.className = 'export-dropdown';
menu.id = 'erExportDropdown';
menu.innerHTML = `
<div class="export-dropdown-item" onclick="closeERExportMenu();exportERSvg()">
<span style="width:16px;display:inline-flex;opacity:.6">&#9638;</span> SVG (vector)
</div>
<div class="export-dropdown-item" onclick="closeERExportMenu();exportERImage('png')">
<span style="width:16px;display:inline-flex;opacity:.6">&#9635;</span> PNG (2x, transparent)
</div>
<div class="export-dropdown-item" onclick="closeERExportMenu();exportERImage('jpg')">
<span style="width:16px;display:inline-flex;opacity:.6">&#9634;</span> JPG (2x, white)
</div>
`;
const rect = btn.getBoundingClientRect();
menu.style.position = 'fixed';
menu.style.top = (rect.bottom + 2) + 'px';
menu.style.left = rect.left + 'px';
menu.style.zIndex = '9999';
document.body.appendChild(menu);
setTimeout(() => document.addEventListener('click', closeERExportMenu, {once: true}), 0);
}

function closeERExportMenu() {
const m = document.getElementById('erExportDropdown');
if (m) m.remove();
}

// ══════════════════════════════════════════════
// Modal System
// ══════════════════════════════════════════════
Expand Down
10 changes: 10 additions & 0 deletions shield-plugin-postgres/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

## [0.1.2] - 2026-10-10

### Added

- ER Diagram: PNG and JPG export. The toolbar `SVG` button is now an `Export`
dropdown offering SVG (vector), PNG (2x, transparent background) and
JPG (2x, white background).

## [0.1.1]

- Initial release
6 changes: 5 additions & 1 deletion shield-plugin-postgres/vscode-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Shield CLI – PostgreSQL Web Client with ER Diagram and Collaboration Features
- 💻 Execute SQL queries with syntax-aware results
- 🎨 Visual table/column/index management (create, drop)
- ✏️ Insert, edit, delete rows via Web UI
- 📊 **Interactive ER Diagram** — visual schema explorer with drag-and-drop FK management
- 📊 **Interactive ER Diagram** — visual schema explorer with drag-and-drop FK management; export to SVG, PNG, or JPG
- 🔒 Read-only mode with frontend + backend enforcement
- 📤 CSV export, cell copy, column sorting
- 🔌 Connection management (add, edit, remove connections)
Expand Down Expand Up @@ -86,6 +86,10 @@ npm test

## 📖 Release Notes

### Version 0.1.2

- ✅ PNG and JPG export for the ER Diagram (`Export` dropdown in the ER toolbar)

### Version 0.0.1 (Initial Release)

- ✅ Core PostgreSQL Web Client functionality
Expand Down
4 changes: 2 additions & 2 deletions shield-plugin-postgres/vscode-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shield-plugin-postgres/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "shield-postgresql",
"displayName": "Shield CLI PostgreSQL",
"description": "Shield CLI – PostgreSQL Web Client with ER Diagram and Collaboration Features for VS Code",
"version": "0.1.1",
"version": "0.1.2",
"publisher": "ShieldCLI",
"engines": {
"vscode": "^1.107.0"
Expand Down
Binary file not shown.
Loading