diff --git a/js/components/command-bar.js b/js/components/command-bar.js index a712511..b183bac 100644 --- a/js/components/command-bar.js +++ b/js/components/command-bar.js @@ -35,6 +35,13 @@ class CommandBar extends HTMLElement { d="M 720 393.027344 C 720 222.207031 576.439941 79.882813 400 79.882813 C 223.559998 79.882813 80 222.207031 80 393.027344 L 80 662.363281 C 80 684.414063 97.919998 703.339844 120 703.339844 C 142.080002 703.339844 160 686.484375 160 664.453125 C 160 642.363281 177.919998 626.582031 200 626.582031 C 222.080002 626.582031 240 648.59375 240 670.644531 C 240 692.714844 257.919983 718.886719 280 718.886719 L 320 718.886719 C 342.080017 718.886719 360 694.804688 360 672.714844 C 360 650.664063 377.919983 626.582031 400 626.582031 C 422.080017 626.582031 440 648.59375 440 670.644531 C 440 692.714844 457.919983 718.886719 480 718.886719 L 520 718.886719 C 542.080017 718.886719 560 692.714844 560 670.644531 C 560 648.59375 577.919983 622.421875 600 622.421875 C 622.080017 622.421875 640 640.3125 640 662.363281 C 640 684.414063 657.919983 702.304688 680 702.304688 C 702.080017 702.304688 720 684.414063 720 662.363281 L 720 393.027344 Z M 800 393.027344 L 800 702.304688 C 800 746.40625 764.199951 798.75 720 798.75 L 689.559998 798.75 C 667.47998 798.75 644.52002 785.527344 630.440002 768.554688 C 623.200012 759.824219 612.279968 748.027344 600 748.027344 C 587.720032 748.027344 576.799988 757.734375 569.559998 766.484375 C 555.47998 783.457031 532.52002 798.75 510.440002 798.75 L 489.559998 798.75 C 467.480011 798.75 444.519989 785.527344 430.440002 768.554688 C 423.200012 759.824219 412.279999 748.027344 400 748.027344 C 387.720001 748.027344 376.799988 757.734375 369.559998 766.484375 C 330.639984 813.339844 263.839996 808.457031 230.839996 768.046875 C 223.52002 759.140625 212.440002 747.1875 200 747.1875 C 187.559998 747.1875 176.47998 757.050781 169.160004 765.957031 C 155.039993 783.300781 131.800003 798.75 109.440002 798.75 L 80 798.75 C 35.799999 798.75 0 746.40625 0 702.304688 L 0 393.027344 C 0 177.851563 179.080017 0 400 0 C 620.920044 0 800 177.851563 800 393.027344 L 800 393.027344 Z M 560 342.871094 L 560 422.734375 C 560 444.785156 577.919983 462.675781 600 462.675781 C 622.080017 462.675781 640 444.785156 640 422.734375 L 640 342.871094 C 640 320.820313 622.080017 302.929688 600 302.929688 C 577.919983 302.929688 560 320.820313 560 342.871094 L 560 342.871094 Z M 240 342.871094 L 240 422.734375 C 240 444.785156 222.080002 462.675781 200 462.675781 C 177.919998 462.675781 160 444.785156 160 422.734375 L 160 342.871094 C 160 320.820313 177.919998 302.929688 200 302.929688 C 222.080002 302.929688 240 320.820313 240 342.871094 L 240 342.871094 Z" /> ask AI + +`; } } diff --git a/js/components/sqlime-editor.js b/js/components/sqlime-editor.js index e3e9109..30bab63 100644 --- a/js/components/sqlime-editor.js +++ b/js/components/sqlime-editor.js @@ -12,6 +12,7 @@ class SqlimeEditor extends HTMLElement { render() { this.contentEditable = "true"; + this.spellcheck = false; } listen() { diff --git a/js/index.js b/js/index.js index 3115bb4..545db78 100644 --- a/js/index.js +++ b/js/index.js @@ -5,6 +5,7 @@ import locator from "./locator.js"; import manager from "./sqlite/manager.js"; import storage from "./storage.js"; import timeit from "./timeit.js"; +import dumper from "./sqlite/dumper.js"; import { actionButton } from "./components/action-button.js"; import { ActionController } from "./controllers/actions.js"; @@ -36,6 +37,7 @@ const actions = { showTables: showTables, showTable: showTable, visit: visit, + downloadSnippet: downloadSnippet, }; const shortcuts = { @@ -157,6 +159,21 @@ function execute(sql) { } } +// Downloads the current snippet as a .sql file, with DB name and +// the current time +function downloadSnippet(){ + const anchorBlob = document.createElement('a'); + const dump = dumper.toSql(database, ui.editor.query); + const query = ui.editor.query; + const textBlob = new Blob([`${dump}\n${query}`], {type: 'text/plain'}); + anchorBlob.href = window.URL.createObjectURL(textBlob); + //make filenames shell- and fs-friendly + anchorBlob.download = `${ui.name.value}_${(new Date()).toISOString().replaceAll(':', '_')}.sql`; + anchorBlob.click(); + console.log(ui); + return Promise.resolve(); +} + // askAi queries the AI assistant using the contents of the editor // as a query and prints the answer. function askAi() {