From 9f7f7b973216263df2f3f50bc08bc2ac22cd6659 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Wed, 26 Sep 2018 16:44:56 +0800 Subject: [PATCH] - Openclipart API work (waiting on possibility of their adding a missing CORS header) --- dist/extensions/ext-locale/imagelib/de.js | 4 +- dist/extensions/ext-locale/imagelib/en.js | 18 +++--- dist/extensions/ext-locale/imagelib/fr.js | 4 +- dist/extensions/ext-locale/imagelib/pl.js | 4 +- dist/extensions/ext-locale/imagelib/pt-BR.js | 4 +- dist/extensions/ext-locale/imagelib/ro.js | 4 +- dist/extensions/ext-locale/imagelib/sk.js | 4 +- dist/extensions/ext-locale/imagelib/sl.js | 4 +- dist/extensions/ext-locale/imagelib/zh-CN.js | 4 +- dist/extensions/imagelib/openclipart.js | 60 ++++++++++++++++--- editor/extensions/ext-locale/imagelib/de.js | 4 +- editor/extensions/ext-locale/imagelib/en.js | 18 +++--- editor/extensions/ext-locale/imagelib/fr.js | 4 +- editor/extensions/ext-locale/imagelib/pl.js | 4 +- .../extensions/ext-locale/imagelib/pt-BR.js | 4 +- editor/extensions/ext-locale/imagelib/ro.js | 4 +- editor/extensions/ext-locale/imagelib/sk.js | 4 +- editor/extensions/ext-locale/imagelib/sl.js | 4 +- .../extensions/ext-locale/imagelib/zh-CN.js | 4 +- editor/extensions/imagelib/openclipart.js | 22 +++++-- 20 files changed, 123 insertions(+), 59 deletions(-) diff --git a/dist/extensions/ext-locale/imagelib/de.js b/dist/extensions/ext-locale/imagelib/de.js index 24451f1b..a57062cc 100644 --- a/dist/extensions/ext-locale/imagelib/de.js +++ b/dist/extensions/ext-locale/imagelib/de.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_de = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/en.js b/dist/extensions/ext-locale/imagelib/en.js index 6845618a..6513d199 100644 --- a/dist/extensions/ext-locale/imagelib/en.js +++ b/dist/extensions/ext-locale/imagelib/en.js @@ -18,16 +18,20 @@ var svgEditorExtensionLocale_imagelib_en = (function () { name: 'IAN Symbol Libraries', url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' - /* , - // Disabling until X-Frame-Options may be removed again (or allow cross-origin): + // The site is no longer using our API, and they have added an + // `X-Frame-Options` header which prevents our usage cross-origin: // Getting messages like this in console: - // Refused to display 'https://openclipart.org/detail/307176/sign-bike' in a frame - // because it set 'X-Frame-Options' to 'sameorigin'. + // Refused to display 'https://openclipart.org/detail/307176/sign-bike' in a frame + // because it set 'X-Frame-Options' to 'sameorigin'. + // url: 'https://openclipart.org/svgedit', + // However, they do have a custom API which we are using here: + /* { name: 'Openclipart', - url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' - } */ + url: '{path}imagelib/openclipart{modularVersion}.html', + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' + } + */ }] }; diff --git a/dist/extensions/ext-locale/imagelib/fr.js b/dist/extensions/ext-locale/imagelib/fr.js index 83855638..6d7098e4 100644 --- a/dist/extensions/ext-locale/imagelib/fr.js +++ b/dist/extensions/ext-locale/imagelib/fr.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_fr = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/pl.js b/dist/extensions/ext-locale/imagelib/pl.js index 5fae10ce..e75873a4 100644 --- a/dist/extensions/ext-locale/imagelib/pl.js +++ b/dist/extensions/ext-locale/imagelib/pl.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_pl = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/pt-BR.js b/dist/extensions/ext-locale/imagelib/pt-BR.js index c7ff9f16..08a4d0e4 100644 --- a/dist/extensions/ext-locale/imagelib/pt-BR.js +++ b/dist/extensions/ext-locale/imagelib/pt-BR.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_pt_BR = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/ro.js b/dist/extensions/ext-locale/imagelib/ro.js index a99e6f48..2c9de426 100644 --- a/dist/extensions/ext-locale/imagelib/ro.js +++ b/dist/extensions/ext-locale/imagelib/ro.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_ro = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/sk.js b/dist/extensions/ext-locale/imagelib/sk.js index 88c6e020..25194b26 100644 --- a/dist/extensions/ext-locale/imagelib/sk.js +++ b/dist/extensions/ext-locale/imagelib/sk.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_sk = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/sl.js b/dist/extensions/ext-locale/imagelib/sl.js index 81d34e79..f40a41a8 100644 --- a/dist/extensions/ext-locale/imagelib/sl.js +++ b/dist/extensions/ext-locale/imagelib/sl.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_sl = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/ext-locale/imagelib/zh-CN.js b/dist/extensions/ext-locale/imagelib/zh-CN.js index 76a9f434..9c1b077a 100644 --- a/dist/extensions/ext-locale/imagelib/zh-CN.js +++ b/dist/extensions/ext-locale/imagelib/zh-CN.js @@ -19,12 +19,12 @@ var svgEditorExtensionLocale_imagelib_zh_CN = (function () { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ }] diff --git a/dist/extensions/imagelib/openclipart.js b/dist/extensions/imagelib/openclipart.js index aae446fe..b572fa0e 100644 --- a/dist/extensions/imagelib/openclipart.js +++ b/dist/extensions/imagelib/openclipart.js @@ -42,6 +42,20 @@ } }; + var _extends = Object.assign || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + + return target; + }; + var inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); @@ -2182,7 +2196,7 @@ return ['div', [['button', { style: 'margin-right: 8px; border: 2px solid black;', dataset: { id: id, value: svgURL }, $on: { click: function () { var _ref3 = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(e) { - var _dataset, svgURL, id; + var _dataset, svgURL, id, post, result, svg; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { @@ -2192,14 +2206,39 @@ _dataset = this.dataset, svgURL = _dataset.value, id = _dataset.id; console.log('this', id, svgURL); - /* - const result = await fetch(svgURL); - const svg = await result.text(); - console.log('svg', svg); - */ - // Todo: Pass to our API - case 3: + post = function post(message) { + // Todo: Make origin customizable as set by opening window + // Todo: If dropping IE9, avoid stringifying + window.parent.postMessage(JSON.stringify(_extends({ + namespace: 'imagelib' + }, message)), '*'); + }; + // Send metadata (also indicates file is about to be sent) + + + post({ + name: title, + id: svgURL + }); + _context.next = 7; + return fetch(svgURL); + + case 7: + result = _context.sent; + _context.next = 10; + return result.text(); + + case 10: + svg = _context.sent; + + console.log('h', svgURL, svg); + post({ + href: svgURL, + data: svg + }); + + case 13: case 'end': return _context.stop(); } @@ -2213,7 +2252,10 @@ return click; }() - } }, [['img', { src: svgURL, style: 'width: ' + imgHW + '; height: ' + imgHW + ';' }]]], ['b', [title]], ' ', ['i', [description]], ' ', ['span', ['(ID: ', ['a', { + } }, [ + // If we wanted interactive versions despite security risk: + // ['object', {data: svgURL, type: 'image/svg+xml'}] + ['img', { src: svgURL, style: 'width: ' + imgHW + '; height: ' + imgHW + ';' }]]], ['b', [title]], ' ', ['i', [description]], ' ', ['span', ['(ID: ', ['a', { href: 'javascript: void(0);', dataset: { value: id }, $on: { diff --git a/editor/extensions/ext-locale/imagelib/de.js b/editor/extensions/ext-locale/imagelib/de.js index 1ee9c51d..184d0109 100644 --- a/editor/extensions/ext-locale/imagelib/de.js +++ b/editor/extensions/ext-locale/imagelib/de.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/en.js b/editor/extensions/ext-locale/imagelib/en.js index 55bbafa3..e3e0c311 100644 --- a/editor/extensions/ext-locale/imagelib/en.js +++ b/editor/extensions/ext-locale/imagelib/en.js @@ -20,15 +20,19 @@ export default { url: 'https://ian.umces.edu/symbols/catalog/svgedit/album_chooser.php?svgedit=3', description: 'Free library of illustrations' } - /* , - // Disabling until X-Frame-Options may be removed again (or allow cross-origin): + // The site is no longer using our API, and they have added an + // `X-Frame-Options` header which prevents our usage cross-origin: // Getting messages like this in console: - // Refused to display 'https://openclipart.org/detail/307176/sign-bike' in a frame - // because it set 'X-Frame-Options' to 'sameorigin'. + // Refused to display 'https://openclipart.org/detail/307176/sign-bike' in a frame + // because it set 'X-Frame-Options' to 'sameorigin'. + // url: 'https://openclipart.org/svgedit', + // However, they do have a custom API which we are using here: + /* { name: 'Openclipart', - url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' - } */ + url: '{path}imagelib/openclipart{modularVersion}.html', + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' + } + */ ] }; diff --git a/editor/extensions/ext-locale/imagelib/fr.js b/editor/extensions/ext-locale/imagelib/fr.js index b17a6aae..f2f5ba16 100644 --- a/editor/extensions/ext-locale/imagelib/fr.js +++ b/editor/extensions/ext-locale/imagelib/fr.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/pl.js b/editor/extensions/ext-locale/imagelib/pl.js index 00a88e57..035649d9 100644 --- a/editor/extensions/ext-locale/imagelib/pl.js +++ b/editor/extensions/ext-locale/imagelib/pl.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/pt-BR.js b/editor/extensions/ext-locale/imagelib/pt-BR.js index 26597722..155c7f3e 100644 --- a/editor/extensions/ext-locale/imagelib/pt-BR.js +++ b/editor/extensions/ext-locale/imagelib/pt-BR.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/ro.js b/editor/extensions/ext-locale/imagelib/ro.js index 29caf600..cb557f02 100644 --- a/editor/extensions/ext-locale/imagelib/ro.js +++ b/editor/extensions/ext-locale/imagelib/ro.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/sk.js b/editor/extensions/ext-locale/imagelib/sk.js index 5966085d..cf399c72 100644 --- a/editor/extensions/ext-locale/imagelib/sk.js +++ b/editor/extensions/ext-locale/imagelib/sk.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/sl.js b/editor/extensions/ext-locale/imagelib/sl.js index f6abd284..200d0770 100644 --- a/editor/extensions/ext-locale/imagelib/sl.js +++ b/editor/extensions/ext-locale/imagelib/sl.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/ext-locale/imagelib/zh-CN.js b/editor/extensions/ext-locale/imagelib/zh-CN.js index 058b88e9..b67094cb 100644 --- a/editor/extensions/ext-locale/imagelib/zh-CN.js +++ b/editor/extensions/ext-locale/imagelib/zh-CN.js @@ -21,12 +21,12 @@ export default { description: 'Free library of illustrations' } /* - // See message in "en" locale as to why disabling + // See message in "en" locale for further details , { name: 'Openclipart', url: 'https://openclipart.org/svgedit', - description: 'Share and Use Images. Over 50,000 Public Domain SVG Images and Growing.' + description: 'Share and Use Images. Over 100,000 Public Domain SVG Images and Growing.' } */ ] diff --git a/editor/extensions/imagelib/openclipart.js b/editor/extensions/imagelib/openclipart.js index 348201e9..fc776ca6 100644 --- a/editor/extensions/imagelib/openclipart.js +++ b/editor/extensions/imagelib/openclipart.js @@ -75,12 +75,26 @@ async function processResults (url) { e.preventDefault(); const {value: svgURL, id} = this.dataset; console.log('this', id, svgURL); - /* + const post = (message) => { + // Todo: Make origin customizable as set by opening window + // Todo: If dropping IE9, avoid stringifying + window.parent.postMessage(JSON.stringify({ + namespace: 'imagelib', + ...message + }), '*'); + }; + // Send metadata (also indicates file is about to be sent) + post({ + name: title, + id: svgURL + }); const result = await fetch(svgURL); const svg = await result.text(); - console.log('svg', svg); - */ - // Todo: Pass to our API + console.log('h', svgURL, svg); + post({ + href: svgURL, + data: svg + }); } }}, [ // If we wanted interactive versions despite security risk: