From ba3280ee8a3ce271346b1f88169104d7295a52b3 Mon Sep 17 00:00:00 2001 From: reviewher <24845478+reviewher@users.noreply.github.com> Date: Sun, 6 Mar 2022 23:36:36 -0800 Subject: [PATCH] Demos [ci skip] --- demos/deno/README.md | 6 ++- demos/electron/.eslintrc | 1 + demos/electron/README.md | 18 +++++-- demos/electron/index.js | 2 +- demos/electron/main.js | 2 + demos/electron/package.json | 5 +- demos/parcel/Makefile | 4 +- demos/parcel/README.md | 4 +- demos/parcel/index.html | 2 +- demos/parcel/index.js | 2 +- demos/parcel/package.json | 1 + demos/rollup/README.md | 18 +++---- demos/rollup/app.js | 15 +++--- demos/rollup/main.js | 2 +- demos/rollup/rollup.config.js | 2 - demos/rollup/rollup.config.node.js | 4 +- demos/rollup/rollup.config.worker.js | 2 - demos/rollup/xlsxworker.js | 4 +- demos/server/Makefile | 4 ++ demos/server/README.md | 10 ++++ demos/server/drash.ts | 68 +++++++++++++++++++++++++++ demos/vue/{index.html => index2.html} | 0 22 files changed, 135 insertions(+), 41 deletions(-) create mode 100644 demos/parcel/package.json create mode 100644 demos/server/drash.ts rename demos/vue/{index.html => index2.html} (100%) diff --git a/demos/deno/README.md b/demos/deno/README.md index 87c8c0b..9975998 100644 --- a/demos/deno/README.md +++ b/demos/deno/README.md @@ -37,7 +37,7 @@ Deno.writeFileSync("test.xlsb", u8); ## Demos -**Complete Example** +**Complete Examples** `sheet2csv.ts` is a complete command-line tool for generating CSV text from workbooks. Building the application is incredibly straightforward: @@ -48,6 +48,10 @@ $ ./sheet2csv test.xlsx # print the first worksheet as CSV $ ./sheet2csv test.xlsx s5s # print worksheet "s5s" as CSV ``` +The [`server` demo](../server) includes a sample Deno server for parsing uploads +and generating HTML TABLE previews. + + **Module Import Scenarios** All demos attempt to read a file and write a new file. [`doit.ts`](./doit.ts) diff --git a/demos/electron/.eslintrc b/demos/electron/.eslintrc index 0d1231a..dd47106 100644 --- a/demos/electron/.eslintrc +++ b/demos/electron/.eslintrc @@ -1,5 +1,6 @@ { "env": { + "es6": true, "browser": true, "node": true }, diff --git a/demos/electron/README.md b/demos/electron/README.md index 7283aa7..316b283 100644 --- a/demos/electron/README.md +++ b/demos/electron/README.md @@ -1,13 +1,9 @@ # Electron This library is compatible with Electron and should just work out of the box. -The demonstration uses Electron 14.0.0. The library is added via `require` from +The demonstration uses Electron 17.1.0. The library is added via `require` from the renderer process. -Electron 9.0.0 and later require the preference `nodeIntegration: true` in order -to `require('XLSX')` in the renderer process. Electron 12.0.0 and later also -require `worldSafeExecuteJavascript: true` and `contextIsolation: true` - The library can also be required from the main process, as shown in this demo to render a version string in the About dialog on OSX. @@ -37,6 +33,18 @@ var o = dialog.showSaveDialog(); XLSX.writeFile(workbook, o); ``` +## Breaking Changes in Electron + +The first version of this demo used Electron 1.7.5. + +Electron 9.0.0 and later require the preference `nodeIntegration: true` in order +to `require('XLSX')` in the renderer process. + +Electron 12.0.0 and later also require `worldSafeExecuteJavascript: true` and +`contextIsolation: true`. + +Electron 14+ must use `@electron/remote` instead of `remote`. + [![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx) diff --git a/demos/electron/index.js b/demos/electron/index.js index 7ac4826..310cfec 100644 --- a/demos/electron/index.js +++ b/demos/electron/index.js @@ -1,6 +1,6 @@ /* xlsx.js (C) 2013-present SheetJS -- https://sheetjs.com */ const XLSX = require('xlsx'); -const electron = require('electron').remote; +const electron = require('@electron/remote'); const EXTENSIONS = "xls|xlsx|xlsm|xlsb|xml|csv|txt|dif|sylk|slk|prn|ods|fods|htm|html".split("|"); diff --git a/demos/electron/main.js b/demos/electron/main.js index be72259..cc015ea 100644 --- a/demos/electron/main.js +++ b/demos/electron/main.js @@ -3,6 +3,7 @@ var electron = require('electron'); var XLSX = require('xlsx'); var app = electron.app; +require('@electron/remote/main').initialize(); var win = null; @@ -18,6 +19,7 @@ function createWindow() { } }); win.loadURL("file://" + __dirname + "/index.html"); + require('@electron/remote/main').enable(win.webContents); win.webContents.openDevTools(); win.on('closed', function () { win = null; }); } diff --git a/demos/electron/package.json b/demos/electron/package.json index 9d1a50f..5277c11 100644 --- a/demos/electron/package.json +++ b/demos/electron/package.json @@ -4,8 +4,9 @@ "version": "0.0.0", "main": "main.js", "dependencies": { - "xlsx": "*", - "electron": "^9.0.5" + "@electron/remote": "^2.0.5", + "electron": "^17.1.0", + "xlsx": "^0.18.3" }, "scripts": { "start": "electron ." diff --git a/demos/parcel/Makefile b/demos/parcel/Makefile index b6678ae..2df336a 100644 --- a/demos/parcel/Makefile +++ b/demos/parcel/Makefile @@ -1,7 +1,7 @@ .PHONY: app app: - parcel build index.html --public-url ./ + npx parcel build index.html .PHONY: ctest ctest: - parcel index.html + npx parcel index.html diff --git a/demos/parcel/README.md b/demos/parcel/README.md index 9966785..12cd331 100644 --- a/demos/parcel/README.md +++ b/demos/parcel/README.md @@ -1,10 +1,10 @@ # Parcel Parcel Bundler starting from version 1.5.0 should play nice with this library -out of the box. The standard import form can be used in JS files: +out of the box: ```js -import XLSX from 'xlsx' +import { read, write, utils } from 'xlsx' ``` Errors of the form `Could not statically evaluate fs call` stem from a parcel diff --git a/demos/parcel/index.html b/demos/parcel/index.html index 11467f6..896a181 100644 --- a/demos/parcel/index.html +++ b/demos/parcel/index.html @@ -43,6 +43,6 @@ Output Format: + +Use the file input element to select a file, then click "Submit" + + + + + +`, + ); + } +} + +// Create and run your server +const server = new Drash.Server({ + hostname: "", + port: 3000, + protocol: "http", + resources: [ + HomeResource, + ], +}); + +server.run(); + +console.log(`Server running at ${server.address}.`); + diff --git a/demos/vue/index.html b/demos/vue/index2.html similarity index 100% rename from demos/vue/index.html rename to demos/vue/index2.html