diff --git a/package.json b/package.json index b604316..44a328b 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ }, "dependencies": { "electron-squirrel-startup": "^1.0.0", + "electron-store": "^6.0.1", "jquery": "^3.5.1", "jsdom": "^16.4.0" }, diff --git a/src/css/index.css b/src/css/index.css index 5af259a..e425bf8 100644 --- a/src/css/index.css +++ b/src/css/index.css @@ -1,11 +1,12 @@ body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; - padding: 2rem; width: 100%; height: 100%; overflow: auto; } -#editor { + +.editor { + padding: 2rem; } #tables { @@ -37,3 +38,16 @@ td > textarea { height: 5em; margin: 5px; } + +::-webkit-scrollbar { + width: 8px; + height: 8px; +} + +::-webkit-scrollbar-track { + background: #dedede; +} + +::-webkit-scrollbar-thumb { + background: #888; +} diff --git a/src/index.html b/src/index.html index af92ccd..5191e28 100644 --- a/src/index.html +++ b/src/index.html @@ -1,57 +1,60 @@ - - Hello World! - - - - - - + + Web Editor + + + + + + - +
-
-

Table Data

- - - -
-

Column Data

- - -
- -
-
-

Cell Data

- -
+
+

Table Data

+ + + +
+

Column Data

+ + +
+ +
+
+

Cell Data

+ +
diff --git a/src/index.js b/src/index.js index 7678391..4c8c84f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,16 +1,19 @@ const { app, BrowserWindow, dialog, Menu } = require('electron'); const fs = require("fs"); -const {ipcMain} = require("electron") +const {ipcMain} = require("electron"); +const Store = require("electron-store"); var jsdom = require("jsdom"); const { JSDOM } = jsdom; const { window } = new JSDOM(); const { document } = (new JSDOM('')).window; +const store = new Store(); global.document = document; var $ = jQuery = require('jquery')(window); let mainWindow = null; +let splash_screen = null; let save_data = { file_path: null } @@ -35,26 +38,7 @@ let menu_template = [ { label: "Open", accelerator: "Ctrl+O", - click: function () { - let options = { - //Placeholder 1 - title: "Open website data", - - //Placeholder 2 - defaultPath : app.getPath("documents"), - - //Placeholder 3 - filters :[ - {name: 'json', extensions: ['json']}, - {name: 'All Files', extensions: ['*']} - ] - } - let file = dialog.showOpenDialogSync(options); - if (file) { - save_data.file_path = file[0]; - mainWindow.webContents.send("open", save_data.file_path); - } - } + click: openFile }, { label: "Exit", @@ -66,6 +50,40 @@ let menu_template = [ } ] +function openFile() { + let options = { + //Placeholder 1 + title: "Open website data", + + //Placeholder 2 + defaultPath : store.get("default_dir", app.getPath("documents")), + + //Placeholder 3 + filters :[ + {name: 'json', extensions: ['json']}, + {name: 'All Files', extensions: ['*']} + ] + } + let file = dialog.showOpenDialogSync(options); + if (file) { + store.set("default_dir", file[0]) + save_data.file_path = file[0]; + if (mainWindow) { + mainWindow.webContents.send("open", save_data.file_path); + } else { + loadFile(file[0]); + } + } +} + +function loadFile(file_name) { + createWindow(); + mainWindow.webContents.once("dom-ready", () => { + mainWindow.webContents.send("open", file_name); + splash_screen.close(); + }) +} + function sanitizeName(table_name) { let pattern = " !@#$%^&*()_+=/?.,<>;':\"[]{}\\`~|-" let new_name = table_name.toLowerCase(); @@ -174,6 +192,29 @@ ipcMain.on("save", (event, data, new_file) => { } }) +ipcMain.on("loadFile", (event, file_name) => { + loadFile(); +}) + +ipcMain.on("newFile", (event) => { + createWindow(); + mainWindow.webContents.once("dom-ready", () => { + splash_screen.close(); + }) +}) + +ipcMain.on("openFile", (event) => { + openFile(); +}) + +ipcMain.handle("getStoreValue", (event, key) => { + return store.get(key); +}) + +ipcMain.handle("setStoreValue", (event, key, value) => { + store.set(key, value); +}) + // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (require('electron-squirrel-startup')) { // eslint-disable-line global-require app.quit(); @@ -182,8 +223,8 @@ if (require('electron-squirrel-startup')) { // eslint-disable-line global-requir const createWindow = () => { // Create the browser window. mainWindow = new BrowserWindow({ - width: 800, - height: 600, + width: 900, + height: 700, webPreferences: { nodeIntegration: true } @@ -199,10 +240,38 @@ const createWindow = () => { // mainWindow.webContents.openDevTools(); }; +const splashScreen = () => { + // Create the browser window. + splash_screen = new BrowserWindow({ + width: 806, + height: 529, + webPreferences: { + nodeIntegration: true + }, + autoHideMenuBar: true, + resizable: false, + frame: true + }); + + let menu = Menu.buildFromTemplate(menu_template); + Menu.setApplicationMenu(menu); + + if (!store.has("recent_files")) { + store.set("recent_files", []); + } + + // and load the index.html of the app. + splash_screen.loadFile('src/splash.html'); + + // Open the DevTools. + // splash_screen.webContents.openDevTools(); + // store.openInEditor(); +}; + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on('ready', createWindow); +app.on('ready', splashScreen); // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits diff --git a/src/js/script.js b/src/js/script.js index df455bb..7233a8c 100644 --- a/src/js/script.js +++ b/src/js/script.js @@ -614,10 +614,21 @@ function openFile(file_path) { }); } +async function updateRecentFiles(new_file) { + let recent_files = await ipcRenderer.invoke("getStoreValue", "recent_files"); + if (recent_files.includes(new_file)) { + recent_files.splice(recent_files.indexOf(new_file), 1); + // delete recent_files[recent_files.indexOf(new_file)]; + } + recent_files.splice(0, 0, new_file); + ipcRenderer.invoke("setStoreValue", "recent_files", recent_files); +} + ipcRenderer.on("save", (event, new_file) => { saveFile(new_file); }) ipcRenderer.on("open", (event, file_path) => { + updateRecentFiles(file_path); openFile(file_path); }) \ No newline at end of file diff --git a/src/splash.html b/src/splash.html new file mode 100644 index 0000000..b45780b --- /dev/null +++ b/src/splash.html @@ -0,0 +1,53 @@ + + + + + Web Editor + + + + + + + + +
+
+
+

Web Editor

+
+ +
+ + + \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index b0a0653..06416d3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -355,6 +355,16 @@ acorn@^7.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A== +ajv@^6.12.2: + version "6.12.6" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" + integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== + dependencies: + fast-deep-equal "^3.1.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + ajv@^6.12.3: version "6.12.4" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.4.tgz#0614facc4522127fa713445c6bfd3ebd376e2234" @@ -474,6 +484,11 @@ at-least-node@^1.0.0: resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== +atomically@^1.3.1: + version "1.7.0" + resolved "https://registry.yarnpkg.com/atomically/-/atomically-1.7.0.tgz#c07a0458432ea6dbc9a3506fffa424b48bccaafe" + integrity sha512-Xcz9l0z7y9yQ9rdDaxlmaI4uJHf/T8g9hOEzJcsEqX2SjCj4J20uK7+ldkDHMbpJDK76wF7xEIgxc/vSlsfw5w== + author-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/author-regex/-/author-regex-1.0.0.tgz#d08885be6b9bbf9439fe087c76287245f0a81450" @@ -763,6 +778,22 @@ concat-stream@^1.6.2: readable-stream "^2.2.2" typedarray "^0.0.6" +conf@^7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/conf/-/conf-7.1.2.tgz#d9678a9d8f04de8bf5cd475105da8fdae49c2ec4" + integrity sha512-r8/HEoWPFn4CztjhMJaWNAe5n+gPUCSaJ0oufbqDLFKsA1V8JjAG7G+p0pgoDFAws9Bpk2VtVLLXqOBA7WxLeg== + dependencies: + ajv "^6.12.2" + atomically "^1.3.1" + debounce-fn "^4.0.0" + dot-prop "^5.2.0" + env-paths "^2.2.0" + json-schema-typed "^7.0.3" + make-dir "^3.1.0" + onetime "^5.1.0" + pkg-up "^3.1.0" + semver "^7.3.2" + config-chain@^1.1.11: version "1.1.12" resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa" @@ -858,6 +889,13 @@ data-urls@^2.0.0: whatwg-mimetype "^2.3.0" whatwg-url "^8.0.0" +debounce-fn@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/debounce-fn/-/debounce-fn-4.0.0.tgz#ed76d206d8a50e60de0dd66d494d82835ffe61c7" + integrity sha512-8pYCQiL9Xdcg0UPSD3d+0KMlOjp+KGU5EPwYddgzQ7DATsg4fuUDjQtsYLmWjnk2obnNHgV3vE2Y4jejSOJVBQ== + dependencies: + mimic-fn "^3.0.0" + debug@^2.1.3, debug@^2.2.0, debug@^2.5.1, debug@^2.6.8, debug@^2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -947,6 +985,13 @@ domexception@^2.0.1: dependencies: webidl-conversions "^5.0.0" +dot-prop@^5.2.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-5.3.0.tgz#90ccce708cd9cd82cc4dc8c3ddd9abdd55b20e88" + integrity sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q== + dependencies: + is-obj "^2.0.0" + duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" @@ -1069,6 +1114,14 @@ electron-squirrel-startup@^1.0.0: dependencies: debug "^2.2.0" +electron-store@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/electron-store/-/electron-store-6.0.1.tgz#2178b9dc37aeb749d99cf9d1d1bc090890b922dc" + integrity sha512-8rdM0XEmDGsLuZM2oRABzsLX+XmD5x3rwxPMEPv0MrN9/BWanyy3ilb2v+tCrKtIZVF3MxUiZ9Bfqe8e0popKQ== + dependencies: + conf "^7.1.2" + type-fest "^0.16.0" + electron-winstaller@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/electron-winstaller/-/electron-winstaller-4.0.1.tgz#69da2a439a6986210c3106305f921a522369207d" @@ -1696,6 +1749,11 @@ is-interactive@^1.0.0: resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e" integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w== +is-obj@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-obj/-/is-obj-2.0.0.tgz#473fb05d973705e3fd9620545018ca8e22ef4982" + integrity sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w== + is-potential-custom-element-name@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.0.tgz#0c52e54bcca391bb2c494b21e8626d7336c6e397" @@ -1807,6 +1865,11 @@ json-schema-traverse@^0.4.1: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== +json-schema-typed@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/json-schema-typed/-/json-schema-typed-7.0.3.tgz#23ff481b8b4eebcd2ca123b4fa0409e66469a2d9" + integrity sha512-7DE8mpG+/fVw+dTpjbxnx47TaMnDfOI1jwft9g1VybltZCduyRQPJPvc+zzKY9WPHxhPWczyFuYa6I8Mw4iU5A== + json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" @@ -1986,6 +2049,13 @@ lowercase-keys@^2.0.0: resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== +make-dir@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" + integrity sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw== + dependencies: + semver "^6.0.0" + map-age-cleaner@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" @@ -2052,6 +2122,11 @@ mimic-fn@^2.0.0, mimic-fn@^2.1.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== +mimic-fn@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-3.1.0.tgz#65755145bbf3e36954b949c16450427451d5ca74" + integrity sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ== + mimic-response@^1.0.0, mimic-response@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" @@ -2502,6 +2577,13 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +pkg-up@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5" + integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA== + dependencies: + find-up "^3.0.0" + plist@^3.0.0, plist@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.1.tgz#a9b931d17c304e8912ef0ba3bdd6182baf2e1f8c" @@ -2840,6 +2922,11 @@ semver-compare@^1.0.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== +semver@^6.0.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" + integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== + semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2: version "7.3.2" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" @@ -3274,6 +3361,11 @@ type-fest@^0.13.1: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.13.1.tgz#0172cb5bce80b0bd542ea348db50c7e21834d934" integrity sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg== +type-fest@^0.16.0: + version "0.16.0" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.16.0.tgz#3240b891a78b0deae910dbeb86553e552a148860" + integrity sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg== + typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"