From 4a0889c7e5f83d701fb821fc25204020b3117f4c Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 24 Oct 2018 10:55:46 +0800 Subject: [PATCH] - Enhancement: For anyone visiting the ES6 modules entrance file without ESM support, redirect to non-modular vesion - Build: Add comment not to edit xdomain editor directly --- CHANGES.md | 3 + build-html.js | 65 +++++++++++++------ editor/extensions/imagelib/index-es.html | 1 + editor/extensions/imagelib/index.html | 1 + .../extensions/imagelib/openclipart-es.html | 1 + editor/extensions/imagelib/openclipart.html | 1 + editor/no-module-support-redirect.js | 8 +++ editor/svg-editor-es.html | 1 + editor/svg-editor.html | 1 + editor/xdomain-svg-editor-es.html | 2 + editor/xdomain-svg-editor.html | 1 + lgtm.yml | 1 + 12 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 editor/no-module-support-redirect.js diff --git a/CHANGES.md b/CHANGES.md index 9460e530..71d67bcb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,8 @@ global available to use (e.g., if using the modular editor) - Fix (Embedded editor): Add events only after load is complete and svgCanvas is available; also log blocked error objects +- Enhancement: For anyone visiting the ES6 modules entrance file without ESM + support, redirect to non-modular vesion - Enhancement: For PDF export, switch Chrome by default to "save" `outputType` - Refactoring (canvg): Better type-checking on `canvasRGBA_` (but set correctly by default anyways) @@ -19,6 +21,7 @@ - Docs: CHANGES clarifications - Docs (JSdoc): Denote optional arguments - Docs: More info on `importLocale` for extensions +- Build: Add comment not to edit xdomain editor directly - Build: Remove unused `Makefile` # 3.0.1 diff --git a/build-html.js b/build-html.js index 15709b35..0e9b5445 100644 --- a/build-html.js +++ b/build-html.js @@ -32,6 +32,22 @@ const filesAndReplacements = [ [ '', '' + ], + [ + '', + '' + ] + ] + }, + // Now that file has copied, we can replace the DOCTYPE in xdomain + { + input: 'editor/xdomain-svg-editor-es.html', + output: 'editor/xdomain-svg-editor-es.html', + replacements: [ + [ + '', + ` +` ] ] }, @@ -55,6 +71,10 @@ const filesAndReplacements = [ [ '', '' + ], + [ + '', + '' ] ] }, @@ -74,6 +94,10 @@ const filesAndReplacements = [ [ '', '' + ], + [ + '', + '' ] ] }, @@ -89,32 +113,35 @@ const filesAndReplacements = [ [ '', '' + ], + [ + '', + '' ] ] } ]; -filesAndReplacements.reduce((p, {input, output, replacements}) => { - return p.then(async () => { - let data; - try { - data = await fs.readFile(input, 'utf8'); - } catch (err) { - console.log(`Error reading ${input} file`, err); - } +filesAndReplacements.reduce(async (p, {input, output, replacements}) => { + await p; + let data; + try { + data = await fs.readFile(input, 'utf8'); + } catch (err) { + console.log(`Error reading ${input} file`, err); + } - data = replacements.reduce((s, [find, replacement]) => { - return s.replace(find, replacement); - }, data); + data = replacements.reduce((s, [find, replacement]) => { + return s.replace(find, replacement); + }, data); - try { - await fs.writeFile(output, data); - } catch (err) { - console.log(`Error writing file: ${err}`, err); - return; - } - console.log(`Completed file ${input} rewriting!`); - }); + try { + await fs.writeFile(output, data); + } catch (err) { + console.log(`Error writing file: ${err}`, err); + return; + } + console.log(`Completed file ${input} rewriting!`); }, Promise.resolve()).then(() => { console.log('Finished!'); }); diff --git a/editor/extensions/imagelib/index-es.html b/editor/extensions/imagelib/index-es.html index f70eca62..2cba3f4f 100644 --- a/editor/extensions/imagelib/index-es.html +++ b/editor/extensions/imagelib/index-es.html @@ -4,6 +4,7 @@ - + diff --git a/editor/extensions/imagelib/index.html b/editor/extensions/imagelib/index.html index aa775de3..522bad0b 100644 --- a/editor/extensions/imagelib/index.html +++ b/editor/extensions/imagelib/index.html @@ -5,6 +5,7 @@ - + diff --git a/editor/extensions/imagelib/openclipart-es.html b/editor/extensions/imagelib/openclipart-es.html index 04f58c56..02f1782e 100644 --- a/editor/extensions/imagelib/openclipart-es.html +++ b/editor/extensions/imagelib/openclipart-es.html @@ -4,6 +4,7 @@ - + diff --git a/editor/extensions/imagelib/openclipart.html b/editor/extensions/imagelib/openclipart.html index b0e12a2f..401100b6 100644 --- a/editor/extensions/imagelib/openclipart.html +++ b/editor/extensions/imagelib/openclipart.html @@ -5,6 +5,7 @@ - + diff --git a/editor/no-module-support-redirect.js b/editor/no-module-support-redirect.js new file mode 100644 index 00000000..512895f4 --- /dev/null +++ b/editor/no-module-support-redirect.js @@ -0,0 +1,8 @@ +// This file should only load if the user's browser doesn't support ESM +// This file will be stripped from the non-modular versions + +// We only need to replace the first instance +location.href = location.href + .replace(/(xdomain-)?svg-editor-es\.html/, 'svg-editor.html') + .replace('openclipart-es.html', 'openclipart.html') + .replace('imagelib/index-es.html', 'imagelib/index.html'); diff --git a/editor/svg-editor-es.html b/editor/svg-editor-es.html index e0262da3..a0c65866 100644 --- a/editor/svg-editor-es.html +++ b/editor/svg-editor-es.html @@ -15,6 +15,7 @@ + diff --git a/editor/svg-editor.html b/editor/svg-editor.html index 4fc83cc2..4bfc9031 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -16,6 +16,7 @@ + diff --git a/editor/xdomain-svg-editor-es.html b/editor/xdomain-svg-editor-es.html index 5994ecf7..28d5f860 100644 --- a/editor/xdomain-svg-editor-es.html +++ b/editor/xdomain-svg-editor-es.html @@ -1,4 +1,5 @@ + @@ -15,6 +16,7 @@ + diff --git a/editor/xdomain-svg-editor.html b/editor/xdomain-svg-editor.html index fa73dd8a..050599ee 100644 --- a/editor/xdomain-svg-editor.html +++ b/editor/xdomain-svg-editor.html @@ -16,6 +16,7 @@ + diff --git a/lgtm.yml b/lgtm.yml index c1d4ef7b..50535cf1 100644 --- a/lgtm.yml +++ b/lgtm.yml @@ -3,5 +3,6 @@ extraction: index: filters: - exclude: "editor/xdomain-svgedit-config-iife.js" + - exclude: "editor/no-module-support-redirect.js" - exclude: "svgedit-config-iife.js" - exclude: "dist"