codex.editor.image
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,1 +0,31 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ImageTool=t():e.ImageTool=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=1)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.make=void 0;var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=a(n(7)),i=a(n(8));function a(e){return e&&e.__esModule?e:{default:e}}var u=function(){function e(t){var n=t.api,r=t.config,o=t.onUpload;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.api=n,this.config=r,this.onUpload=o,this.nodes={wrapper:s("div",[this.CSS.baseClass,this.CSS.wrapper]),imageContainer:s("div",[this.CSS.imageContainer]),fileButton:this.createFileButton(),imageEl:void 0,imagePreloader:s("div",this.CSS.imagePreloader),caption:s("div",[this.CSS.input,this.CSS.caption],{contentEditable:!0})},this.nodes.caption.dataset.placeholder=this.config.captionPlaceholder,this.nodes.imageContainer.appendChild(this.nodes.imagePreloader),this.nodes.wrapper.appendChild(this.nodes.imageContainer),this.nodes.wrapper.appendChild(this.nodes.caption),this.nodes.wrapper.appendChild(this.nodes.fileButton)}return r(e,[{key:"render",value:function(t){return t.file&&0!==Object.keys(t.file).length?this.toggleStatus(e.status.UPLOADING):this.toggleStatus(e.status.EMPTY),this.nodes.wrapper}},{key:"createFileButton",value:function(){var e=this,t=s("div",[this.CSS.button]);return t.innerHTML=o.default+" Select an Image",t.addEventListener("click",function(){e.selectFile()}),t}},{key:"selectFile",value:function(){var e=this;i.default.transport({url:this.config.url,accept:this.config.types,beforeSend:function(t){e.beforeSend(t[0])},fieldName:this.config.field}).then(function(t){t.success&&t.file?e.onUpload(t):e.uploadingError("incorrect response: "+JSON.stringify(t))}).catch(function(t){e.uploadingError(t)})}},{key:"uploadingError",value:function(t){console.log("Image Tool: uploading failed because of",t),this.nodes.imagePreloader.style.backgroundImage="",this.toggleStatus(e.status.EMPTY)}},{key:"beforeSend",value:function(e){var t=this,n=new FileReader;n.readAsDataURL(e),n.onload=function(e){t.showPreloader(e.target.result)}}},{key:"showPreloader",value:function(t){this.nodes.imagePreloader.style.backgroundImage="url("+t+")",this.toggleStatus(e.status.UPLOADING)}},{key:"fillImage",value:function(t){var n=this;this.nodes.imageEl=s("img",this.CSS.imageEl,{src:t}),this.nodes.imageContainer.appendChild(this.nodes.imageEl),this.nodes.imageEl.addEventListener("load",function(){n.toggleStatus(e.status.FILLED),n.nodes.imagePreloader&&(n.nodes.imagePreloader.style.backgroundImage="")})}},{key:"fillCaption",value:function(e){this.nodes.caption&&(this.nodes.caption.innerHTML=e)}},{key:"toggleStatus",value:function(t){for(var n in e.status)e.status.hasOwnProperty(n)&&this.nodes.wrapper.classList.toggle(this.CSS.wrapper+"--"+e.status[n],t===e.status[n])}},{key:"applyTune",value:function(e,t){this.nodes.wrapper.classList.toggle(this.CSS.wrapper+"--"+e,t)}},{key:"CSS",get:function(){return{baseClass:this.api.styles.block,loading:this.api.styles.loader,input:this.api.styles.input,button:this.api.styles.button,wrapper:"image-tool",imageContainer:"image-tool__image",imagePreloader:"image-tool__image-preloader",imageEl:"image-tool__image-picture",caption:"image-tool__caption"}}}],[{key:"status",get:function(){return{EMPTY:"empty",UPLOADING:"loading",FILLED:"filled"}}}]),e}();t.default=u;var s=t.make=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=document.createElement(e);Array.isArray(n)?(t=o.classList).add.apply(t,function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(n)):n&&o.classList.add(n);for(var i in r)o[i]=r[i];return o}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=(s(n(2)),s(n(0))),i=s(n(9)),a=s(n(13)),u=s(n(14));function s(e){return e&&e.__esModule?e:{default:e}}var c=function(){function e(t){var n=this,r=t.data,a=t.config,u=t.api;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.api=u,this.config={url:a.url||"",field:a.field||"image",types:a.types||"image/*",captionPlaceholder:a.captionPlaceholder||"Caption"},this.ui=new o.default({api:u,config:this.config,onUpload:function(e){return n.onUpload(e)}}),this.tunes=new i.default({api:u,onChange:function(e){return n.tuneToggled(e)}}),this._data={},this.data=r}return r(e,null,[{key:"displayInToolbox",get:function(){return!0}},{key:"toolboxIcon",get:function(){return a.default}}]),r(e,[{key:"render",value:function(){return this.ui.render(this.data)}},{key:"save",value:function(){var e=this.ui.nodes.caption;return this._data.caption=e.innerHTML,this.data}},{key:"renderSettings",value:function(){return this.tunes.render(this.data)}},{key:"appendCallback",value:function(){this.ui.nodes.fileButton.click()}},{key:"onUpload",value:function(e){this.image=e.file}},{key:"tuneToggled",value:function(e){this.setTune(e,!this._data[e])}},{key:"setTune",value:function(e,t){var n=this;if(this._data[e]=t,this.ui.applyTune(e,t),"stretched"===e){var r=this.api.blocks.getCurrentBlockIndex();setTimeout(function(){n.api.blocks.stretchBlock(r,t)},0)}}},{key:"data",set:function(e){var t=this;this.image=e.file,this._data.caption=e.caption||"",this.ui.fillCaption(this._data.caption),i.default.tunes.forEach(function(n){var r=n.name;t.setTune(r,void 0!==e[r]&&e[r])})},get:function(){return this._data}},{key:"image",set:function(e){this._data.file=e||{},e&&e.url&&this.ui.fillImage(e.url)}}],[{key:"onPaste",get:function(){return{tags:["img"],handler:u.default.fromHtml,files:{mimeTypes:["image/*"]},fileHandler:u.default.fromDroppedFile,patterns:{image:/https?:\/\/\S+\.(gif|jpe?g|tiff|png)$/i},patternHandler:u.default.fromPastedUrl}}}]),e}();t.default=c},function(e,t,n){var r=n(3);"string"==typeof r&&(r=[[e.i,r,""]]);var o={hmr:!0,transform:void 0,insertInto:void 0};n(5)(r,o);r.locals&&(e.exports=r.locals)},function(e,t,n){(e.exports=n(4)(!1)).push([e.i,".image-tool {\n --bg-color: #CDD1E0;\n --front-color: #388AE5;\n --border-color: #E8E8EB;\n}\n\n .image-tool__image {\n border-radius: 3px;\n overflow: hidden;\n margin-bottom: 10px;\n }\n\n .image-tool__image-picture {\n max-width: 100%;\n vertical-align: bottom;\n display: block;\n }\n\n .image-tool__image-preloader {\n width: 50px;\n height: 50px;\n border-radius: 50%;\n background-size: cover;\n margin: auto;\n position: relative;\n background-color: var(--bg-color);\n }\n\n .image-tool__image-preloader::after {\n content: '';\n position: absolute;\n z-index: 3;\n width: 60px;\n height: 60px;\n border-radius: 50%;\n border: 2px solid var(--bg-color);\n border-top-color: var(--front-color);\n left: 50%;\n top: 50%;\n margin-top: -30px;\n margin-left: -30px;\n animation: image-preloader-spin 2s infinite linear;\n box-sizing: border-box;\n }\n\n .image-tool--empty .image-tool__image {\n display: none;\n }\n\n .image-tool--empty .image-tool__caption, .image-tool--loading .image-tool__caption {\n display: none;\n }\n\n .image-tool--filled .cdx-button {\n display: none;\n }\n\n .image-tool--filled .image-tool__image-preloader {\n display: none;\n }\n\n .image-tool--loading .image-tool__image {\n min-height: 200px;\n display: flex;\n border: 1px solid var(--border-color);\n background-color: #fff;\n }\n\n .image-tool--loading .image-tool__image-picture {\n display: none;\n }\n\n .image-tool--loading .cdx-button {\n display: none;\n }\n\n /**\n * Tunes\n * ----------------\n */\n\n .image-tool--withBorder .image-tool__image {\n border: 1px solid var(--border-color);\n }\n\n .image-tool--withBackground .image-tool__image {\n padding: 15px;\n background: var(--bg-color);\n }\n\n .image-tool--withBackground .image-tool__image-picture {\n max-width: 60%;\n margin: 0 auto;\n }\n\n .image-tool--stretched .image-tool__image-picture {\n width: 100%;\n }\n\n@keyframes image-preloader-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",r=e[3];if(!r)return n;if(t&&"function"==typeof btoa){var o=function(e){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e))))+" */"}(r),i=r.sources.map(function(e){return"/*# sourceURL="+r.sourceRoot+e+" */"});return[n].concat(i).concat([o]).join("\n")}return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var r={},o=0;o<this.length;o++){var i=this[o][0];"number"==typeof i&&(r[i]=!0)}for(o=0;o<e.length;o++){var a=e[o];"number"==typeof a[0]&&r[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),t.push(a))}},t}},function(e,t,n){var r={},o=function(e){var t;return function(){return void 0===t&&(t=e.apply(this,arguments)),t}}(function(){return window&&document&&document.all&&!window.atob}),i=function(e){var t={};return function(e){if("function"==typeof e)return e();if(void 0===t[e]){var n=function(e){return document.querySelector(e)}.call(this,e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}}(),a=null,u=0,s=[],c=n(6);function l(e,t){for(var n=0;n<e.length;n++){var o=e[n],i=r[o.id];if(i){i.refs++;for(var a=0;a<i.parts.length;a++)i.parts[a](o.parts[a]);for(;a<o.parts.length;a++)i.parts.push(g(o.parts[a],t))}else{var u=[];for(a=0;a<o.parts.length;a++)u.push(g(o.parts[a],t));r[o.id]={id:o.id,refs:1,parts:u}}}}function f(e,t){for(var n=[],r={},o=0;o<e.length;o++){var i=e[o],a=t.base?i[0]+t.base:i[0],u={css:i[1],media:i[2],sourceMap:i[3]};r[a]?r[a].parts.push(u):n.push(r[a]={id:a,parts:[u]})}return n}function d(e,t){var n=i(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var r=s[s.length-1];if("top"===e.insertAt)r?r.nextSibling?n.insertBefore(t,r.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),s.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var o=i(e.insertInto+" "+e.insertAt.before);n.insertBefore(t,o)}}function p(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=s.indexOf(e);t>=0&&s.splice(t,1)}function h(e){var t=document.createElement("style");return void 0===e.attrs.type&&(e.attrs.type="text/css"),m(t,e.attrs),d(e,t),t}function m(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}function g(e,t){var n,r,o,i;if(t.transform&&e.css){if(!(i=t.transform(e.css)))return function(){};e.css=i}if(t.singleton){var s=u++;n=a||(a=h(t)),r=y.bind(null,n,s,!1),o=y.bind(null,n,s,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",m(t,e.attrs),d(e,t),t}(t),r=function(e,t,n){var r=n.css,o=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&o;(t.convertToAbsoluteUrls||i)&&(r=c(r));o&&(r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var a=new Blob([r],{type:"text/css"}),u=e.href;e.href=URL.createObjectURL(a),u&&URL.revokeObjectURL(u)}.bind(null,n,t),o=function(){p(n),n.href&&URL.revokeObjectURL(n.href)}):(n=h(t),r=function(e,t){var n=t.css,r=t.media;r&&e.setAttribute("media",r);if(e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}.bind(null,n),o=function(){p(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=o()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=f(e,t);return l(n,t),function(e){for(var o=[],i=0;i<n.length;i++){var a=n[i];(u=r[a.id]).refs--,o.push(u)}e&&l(f(e,t),t);for(i=0;i<o.length;i++){var u;if(0===(u=o[i]).refs){for(var s=0;s<u.parts.length;s++)u.parts[s]();delete r[u.id]}}}};var v=function(){var e=[];return function(t,n){return e[t]=n,e.filter(Boolean).join("\n")}}();function y(e,t,n,r){var o=n?"":r.css;if(e.styleSheet)e.styleSheet.cssText=v(t,o);else{var i=document.createTextNode(o),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,r=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(e,t){var o,i=t.trim().replace(/^"(.*)"$/,function(e,t){return t}).replace(/^'(.*)'$/,function(e,t){return t});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(o=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:r+i.replace(/^\.\//,""),"url("+JSON.stringify(o)+")")})}},function(e,t){e.exports='<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path fill-rule="evenodd" d="M3.15 13.628A7.749 7.749 0 0 0 10 17.75a7.74 7.74 0 0 0 6.305-3.242l-2.387-2.127-2.765 2.244-4.389-4.496-3.614 3.5zm-.787-2.303l4.446-4.371 4.52 4.63 2.534-2.057 3.533 2.797c.23-.734.354-1.514.354-2.324a7.75 7.75 0 1 0-15.387 1.325zM10 20C4.477 20 0 15.523 0 10S4.477 0 10 0s10 4.477 10 10-4.477 10-10 10z" id="a"></path></svg>'},function(e,t,n){window,e.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";(function(e){var r=n(2),o=setTimeout;function i(){}function a(e){if(!(this instanceof a))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],f(e,this)}function u(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,a._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var r;try{r=n(e._value)}catch(e){return void c(t.promise,e)}s(t.promise,r)}else(1===e._state?s:c)(t.promise,e._value)})):e._deferreds.push(t)}function s(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof a)return e._state=3,e._value=t,void l(e);if("function"==typeof n)return void f(function(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,l(e)}catch(t){c(e,t)}}function c(e,t){e._state=2,e._value=t,l(e)}function l(e){2===e._state&&0===e._deferreds.length&&a._immediateFn(function(){e._handled||a._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)u(e,e._deferreds[t]);e._deferreds=null}function f(e,t){var n=!1;try{e(function(e){n||(n=!0,s(t,e))},function(e){n||(n=!0,c(t,e))})}catch(e){if(n)return;n=!0,c(t,e)}}a.prototype.catch=function(e){return this.then(null,e)},a.prototype.then=function(e,t){var n=new this.constructor(i);return u(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},a.prototype.finally=r.a,a.all=function(e){return new a(function(t,n){if(!e||void 0===e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);if(0===r.length)return t([]);var o=r.length;function i(e,a){try{if(a&&("object"==typeof a||"function"==typeof a)){var u=a.then;if("function"==typeof u)return void u.call(a,function(t){i(e,t)},n)}r[e]=a,0==--o&&t(r)}catch(e){n(e)}}for(var a=0;a<r.length;a++)i(a,r[a])})},a.resolve=function(e){return e&&"object"==typeof e&&e.constructor===a?e:new a(function(t){t(e)})},a.reject=function(e){return new a(function(t,n){n(e)})},a.race=function(e){return new a(function(t,n){for(var r=0,o=e.length;r<o;r++)e[r].then(t,n)})},a._immediateFn="function"==typeof e&&function(t){e(t)}||function(e){o(e,0)},a._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},t.a=a}).call(this,n(5).setImmediate)},function(e,t,n){"use strict";t.a=function(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}},function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n(4);var o=n(8),i=function(){var e={URLENCODED:"application/x-www-form-urlencoded; charset=utf-8",FORM:"multipart/form-data",JSON:"application/json; charset=utf-8"},t=function(e){return new Promise(function(t,n){e=a(e),e=u(e);var r=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");r.open(e.method,e.url),r.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(e.headers).forEach(function(t){var n=e.headers[t];r.setRequestHeader(t,n)});var o=e.ratio;r.upload.addEventListener("progress",function(t){var n=Math.round(t.loaded/t.total*100),r=Math.ceil(n*o/100);e.progress(r)},!1),r.addEventListener("progress",function(t){var n=Math.round(t.loaded/t.total*100),r=Math.ceil(n*(100-o)/100)+o;e.progress(r)},!1),r.onreadystatechange=function(){if(4===r.readyState){var e=r.response;try{e=JSON.parse(e)}catch(e){}200===r.status?t(e):n(e)}},r.send(e.data)})},n=function(e){return e.method="POST",t(e)},a=function(t){if(!t.url||"string"!=typeof t.url)throw new Error("Url must be a non-empty string");if(t.method&&"string"!=typeof t.method)throw new Error("`method` must be a string or null");if(t.method=t.method?t.method.toUpperCase():"GET",t.headers&&"object"!==r(t.headers))throw new Error("`headers` must be an object or null");if(t.headers=t.headers||{},t.type&&("string"!=typeof t.type||!Object.values(e).includes(t.type)))throw new Error("`type` must be taken from module's «contentType» library");if(t.progress&&"function"!=typeof t.progress)throw new Error("`progress` must be a function or null");if(t.progress=t.progress||function(e){},t.beforeSend=t.beforeSend||function(e){},t.ratio&&"number"!=typeof t.ratio)throw new Error("`ratio` must be a number");if(t.ratio<0||t.ratio>100)throw new Error("`ratio` must be in a 0-100 interval");if(t.ratio=t.ratio||90,t.accept&&"string"!=typeof t.accept)throw new Error("`accept` must be a string with a list of allowed mime-types");if(t.accept=t.accept||"*/*",t.multiple&&"boolean"!=typeof t.multiple)throw new Error("`multiple` must be a true or false");if(t.multiple=t.multiple||!1,t.fieldName&&"string"!=typeof t.fieldName)throw new Error("`fieldName` must be a string");return t.fieldName=t.fieldName||"files",t},u=function(t){switch(t.method){case"GET":var n=s(t.data,e.URLENCODED);delete t.data,t.url=/\?/.test(t.url)?t.url+"&"+n:t.url+"?"+n;break;case"POST":case"PUT":case"DELETE":case"UPDATE":var r=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).type||e.JSON}(t);(o.isFormData(t.data)||o.isFormElement(t.data))&&(r=e.FORM),t.data=s(t.data,r),r!==i.contentType.FORM&&(t.headers["content-type"]=r)}return t},s=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};switch(arguments.length>1?arguments[1]:void 0){case e.URLENCODED:return o.urlEncode(t);case e.JSON:return o.jsonEncode(t);case e.FORM:return o.formEncode(t);default:return t}};return{contentType:e,request:t,get:function(e){return e.method="GET",t(e)},post:n,transport:function(e){return e=a(e),o.transport(e).then(function(t){return o.isObject(e.data)&&Object.keys(e.data).forEach(function(n){var r=e.data[n];t.append(n,r)}),e.data=t,n(e)})}}}();e.exports=i},function(e,t,n){"use strict";n.r(t);var r=n(1);window.Promise=window.Promise||r.a},function(e,t,n){(function(e){var r=void 0!==e&&e||"undefined"!=typeof self&&self||window,o=Function.prototype.apply;function i(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new i(o.call(setTimeout,r,arguments),clearTimeout)},t.setInterval=function(){return new i(o.call(setInterval,r,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(r,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(6),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n(0))},function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var r,o=1,i={},a=!1,u=e.document,s=Object.getPrototypeOf&&Object.getPrototypeOf(e);s=s&&s.setTimeout?s:e,"[object process]"==={}.toString.call(e.process)?r=function(e){t.nextTick(function(){l(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?function(){var t="setImmediate$"+Math.random()+"$",n=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&l(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),r=function(n){e.postMessage(t+n,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){l(e.data)},r=function(t){e.port2.postMessage(t)}}():u&&"onreadystatechange"in u.createElement("script")?function(){var e=u.documentElement;r=function(t){var n=u.createElement("script");n.onreadystatechange=function(){l(t),n.onreadystatechange=null,e.removeChild(n),n=null},e.appendChild(n)}}():r=function(e){setTimeout(l,0,e)},s.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var a={callback:e,args:t};return i[o]=a,r(o),o++},s.clearImmediate=c}function c(e){delete i[e]}function l(e){if(a)setTimeout(l,0,e);else{var t=i[e];if(t){a=!0;try{!function(e){var t=e.callback,r=e.args;switch(r.length){case 0:t();break;case 1:t(r[0]);break;case 2:t(r[0],r[1]);break;case 3:t(r[0],r[1],r[2]);break;default:t.apply(n,r)}}(t)}finally{c(e),a=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n(0),n(7))},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var s,c=[],l=!1,f=-1;function d(){l&&s&&(l=!1,s.length?c=s.concat(c):f=-1,c.length&&p())}function p(){if(!l){var e=u(d);l=!0;for(var t=c.length;t;){for(s=c,c=[];++f<t;)s&&s[f].run();f=-1,t=c.length}s=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function h(e,t){this.fun=e,this.array=t}function m(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new h(e,t)),1!==c.length||l||u(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=m,o.addListener=m,o.once=m,o.off=m,o.removeListener=m,o.removeAllListeners=m,o.emit=m,o.prependListener=m,o.prependOnceListener=m,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var o=n(9);e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return function(e,t,n){n&&r(e,n)}(e,0,[{key:"urlEncode",value:function(e){return o(e)}},{key:"jsonEncode",value:function(e){return JSON.stringify(e)}},{key:"formEncode",value:function(e){if(this.isFormData(e))return e;if(this.isFormElement(e))return new FormData(e);if(this.isObject(e)){var t=new FormData;return Object.keys(e).forEach(function(n){var r=e[n];t.append(n,r)}),t}throw new Error("`data` must be an instance of Object, FormData or <FORM> HTMLElement")}},{key:"isObject",value:function(e){return"[object Object]"===Object.prototype.toString.call(e)}},{key:"isFormData",value:function(e){return e instanceof FormData}},{key:"isFormElement",value:function(e){return e instanceof HTMLFormElement}},{key:"transport",value:function(e){return new Promise(function(t,n){var r=document.createElement("INPUT");r.type="file",e.multiple&&r.setAttribute("multiple","multiple"),e.accept&&r.setAttribute("accept",e.accept),r.addEventListener("change",function(n){for(var r=n.target.files,o=new FormData,i=0;i<r.length;i++)o.append(e.fieldName,r[i],r[i].name);e.beforeSend(r),t(o)},!1),r.click()})}}]),e}()},function(e,t){var n=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,escape).replace(/%20/g,"+")},r=function(e,t,o,i){return t=t||null,o=o||"&",i=i||null,e?function(e){for(var t=new Array,n=0;n<e.length;n++)e[n]&&t.push(e[n]);return t}(Object.keys(e).map(function(a){var u,s=a;if(i&&(s=i+"["+s+"]"),"object"==typeof e[a]&&null!==e[a])u=r(e[a],null,o,s);else{t&&(s=function(e){return!isNaN(parseFloat(e))&&isFinite(e)}(s)?t+Number(s):s);var c=e[a];c=(c=0===(c=!1===(c=!0===c?"1":c)?"0":c)?"0":c)||"",u=n(s)+"="+n(c)}return u})).join(o).replace(/[!'()*]/g,""):""};e.exports=r}])},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=n(0),i=s(n(10)),a=s(n(11)),u=s(n(12));function s(e){return e&&e.__esModule?e:{default:e}}var c=function(){function e(t){var n=t.api,r=t.onChange;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.api=n,this.onChange=r,this.buttons=[]}return r(e,[{key:"render",value:function(t){var n=this,r=(0,o.make)("div",this.CSS.wrapper);return this.buttons=[],e.tunes.forEach(function(e){var i=(0,o.make)("div",[n.CSS.buttonBase,n.CSS.button],{innerHTML:e.icon,title:e.title});i.addEventListener("click",function(){n.tuneClicked(e.name)}),i.dataset.tune=e.name,i.classList.toggle(n.CSS.buttonActive,t[e.name]),n.buttons.push(i),r.appendChild(i)}),r}},{key:"tuneClicked",value:function(e){var t=this.buttons.find(function(t){return t.dataset.tune===e});t.classList.toggle(this.CSS.buttonActive,!t.classList.contains(this.CSS.buttonActive)),this.onChange(e)}},{key:"CSS",get:function(){return{wrapper:"",buttonBase:this.api.styles.settingsButton,button:"image-tool__tune",buttonActive:this.api.styles.settingsButtonActive}}}],[{key:"tunes",get:function(){return[{name:"withBorder",icon:a.default,title:"With border"},{name:"stretched",icon:u.default,title:"Stretch image"},{name:"withBackground",icon:i.default,title:"With background"}]}}]),e}();t.default=c},function(e,t){e.exports='<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10.043 8.265l3.183-3.183h-2.924L4.75 10.636v2.923l4.15-4.15v2.351l-2.158 2.159H8.9v2.137H4.7c-1.215 0-2.2-.936-2.2-2.09v-8.93c0-1.154.985-2.09 2.2-2.09h10.663l.033-.033.034.034c1.178.04 2.12.96 2.12 2.089v3.23H15.3V5.359l-2.906 2.906h-2.35zM7.951 5.082H4.75v3.201l3.201-3.2zm5.099 7.078v3.04h4.15v-3.04h-4.15zm-1.1-2.137h6.35c.635 0 1.15.489 1.15 1.092v5.13c0 .603-.515 1.092-1.15 1.092h-6.35c-.635 0-1.15-.489-1.15-1.092v-5.13c0-.603.515-1.092 1.15-1.092z"></path></svg>'},function(e,t){e.exports='<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M15.8 10.592v2.043h2.35v2.138H15.8v2.232h-2.25v-2.232h-2.4v-2.138h2.4v-2.28h2.25v.237h1.15-1.15zM1.9 8.455v-3.42c0-1.154.985-2.09 2.2-2.09h4.2v2.137H4.15v3.373H1.9zm0 2.137h2.25v3.325H8.3v2.138H4.1c-1.215 0-2.2-.936-2.2-2.09v-3.373zm15.05-2.137H14.7V5.082h-4.15V2.945h4.2c1.215 0 2.2.936 2.2 2.09v3.42z"></path></svg>'},function(e,t){e.exports='<svg width="17" height="10" viewBox="0 0 17 10" xmlns="http://www.w3.org/2000/svg"><path d="M13.568 5.925H4.056l1.703 1.703a1.125 1.125 0 0 1-1.59 1.591L.962 6.014A1.069 1.069 0 0 1 .588 4.26L4.38.469a1.069 1.069 0 0 1 1.512 1.511L4.084 3.787h9.606l-1.85-1.85a1.069 1.069 0 1 1 1.512-1.51l3.792 3.791a1.069 1.069 0 0 1-.475 1.788L13.514 9.16a1.125 1.125 0 0 1-1.59-1.591l1.644-1.644z"></path></svg>'},function(e,t){e.exports='<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150.242V79c0-18.778-15.222-34-34-34H79c-18.778 0-34 15.222-34 34v42.264l67.179-44.192 80.398 71.614 56.686-29.14L291 150.242zm-.345 51.622l-42.3-30.246-56.3 29.884-80.773-66.925L45 174.187V197c0 18.778 15.222 34 34 34h178c17.126 0 31.295-12.663 33.655-29.136zM79 0h178c43.63 0 79 35.37 79 79v118c0 43.63-35.37 79-79 79H79c-43.63 0-79-35.37-79-79V79C0 35.37 35.37 0 79 0z"></path></svg>'},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return r(e,null,[{key:"fromDroppedFile",value:function(e){var t=new FileReader;return t.readAsDataURL(e),new Promise(function(n){t.onload=function(t){n({file:{url:t.target.result},caption:e.name})}})}},{key:"fromHtml",value:function(e){return{file:{url:e.getAttribute("src")},caption:e.hasAttribute("title")?e.getAttribute("title"):""}}},{key:"fromPastedUrl",value:function(e){return{file:{url:e}}}}]),e}();t.default=o}]).default}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ImageTool=t():e.ImageTool=t()}(window,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=1)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.make=void 0;var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=function(e){return e&&e.__esModule?e:{default:e}}(n(7));var i=function(){function e(t){var n=t.api,o=t.config,r=t.onSelectFile;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.api=n,this.config=o,this.onSelectFile=r,this.nodes={wrapper:a("div",[this.CSS.baseClass,this.CSS.wrapper]),imageContainer:a("div",[this.CSS.imageContainer]),fileButton:this.createFileButton(),imageEl:void 0,imagePreloader:a("div",this.CSS.imagePreloader),caption:a("div",[this.CSS.input,this.CSS.caption],{contentEditable:!0})},this.nodes.caption.dataset.placeholder=this.config.captionPlaceholder,this.nodes.imageContainer.appendChild(this.nodes.imagePreloader),this.nodes.wrapper.appendChild(this.nodes.imageContainer),this.nodes.wrapper.appendChild(this.nodes.caption),this.nodes.wrapper.appendChild(this.nodes.fileButton)}return o(e,[{key:"render",value:function(t){return t.file&&0!==Object.keys(t.file).length?this.toggleStatus(e.status.UPLOADING):this.toggleStatus(e.status.EMPTY),this.nodes.wrapper}},{key:"createFileButton",value:function(){var e=this,t=a("div",[this.CSS.button]);return t.innerHTML=this.config.buttonContent||r.default+" Select an Image",t.addEventListener("click",function(){e.onSelectFile()}),t}},{key:"showPreloader",value:function(t){this.nodes.imagePreloader.style.backgroundImage="url("+t+")",this.toggleStatus(e.status.UPLOADING)}},{key:"hidePreloader",value:function(){this.nodes.imagePreloader.style.backgroundImage="",this.toggleStatus(e.status.EMPTY)}},{key:"fillImage",value:function(t){var n=this;this.nodes.imageEl=a("img",this.CSS.imageEl,{src:t}),this.nodes.imageContainer.appendChild(this.nodes.imageEl),this.nodes.imageEl.addEventListener("load",function(){n.toggleStatus(e.status.FILLED),n.nodes.imagePreloader&&(n.nodes.imagePreloader.style.backgroundImage="")})}},{key:"fillCaption",value:function(e){this.nodes.caption&&(this.nodes.caption.innerHTML=e)}},{key:"toggleStatus",value:function(t){for(var n in e.status)e.status.hasOwnProperty(n)&&this.nodes.wrapper.classList.toggle(this.CSS.wrapper+"--"+e.status[n],t===e.status[n])}},{key:"applyTune",value:function(e,t){this.nodes.wrapper.classList.toggle(this.CSS.wrapper+"--"+e,t)}},{key:"CSS",get:function(){return{baseClass:this.api.styles.block,loading:this.api.styles.loader,input:this.api.styles.input,button:this.api.styles.button,wrapper:"image-tool",imageContainer:"image-tool__image",imagePreloader:"image-tool__image-preloader",imageEl:"image-tool__image-picture",caption:"image-tool__caption"}}}],[{key:"status",get:function(){return{EMPTY:"empty",UPLOADING:"loading",FILLED:"filled"}}}]),e}();t.default=i;var a=t.make=function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=document.createElement(e);Array.isArray(n)?(t=r.classList).add.apply(t,function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}(n)):n&&r.classList.add(n);for(var i in o)r[i]=o[i];return r}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=(s(n(2)),s(n(0))),i=s(n(8)),a=s(n(12)),u=s(n(13)); | ||
/** | ||
* Image Tool for the CodeX Editor | ||
* @author CodeX <team@ifmo.su> | ||
* @license MIT | ||
* @see {@link https://github.com/codex-editor/image} | ||
* | ||
* To developers. | ||
* To simplify Tool structure, we split it to 4 parts: | ||
* 1) index.js — main Tool's interface, public API and methods for working with data | ||
* 2) uploader.js — module that has methods for sending files via AJAX: from device, by URL or File pasting | ||
* 3) ui.js — module for UI manipulations: render, showing preloader, etc | ||
* 4) tunes.js — working with Block Tunes: render buttons, handle clicks | ||
* | ||
* For debug purposes there is a testing server | ||
* that can save uploaded files and return a Response {@link UploadResponseFormat} | ||
* | ||
* $ node dev/server.js | ||
* | ||
* It will expose 8008 port, so you can pass http://localhost:8008 with the Tools config: | ||
* | ||
* image: { | ||
* class: ImageTool, | ||
* config: { | ||
* endpoints: { | ||
* byFile: 'http://localhost:8008/uploadFile', | ||
* byUrl: 'http://localhost:8008/fetchUrl', | ||
* } | ||
* }, | ||
* }, | ||
*/function s(e){return e&&e.__esModule?e:{default:e}}var c=function(){function e(t){var n=this,o=t.data,a=t.config,s=t.api;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.api=s,this.config={endpoints:a.endpoints||"",additionalRequestData:a.additionalRequestData||{},additionalRequestHeaders:a.additionalRequestHeaders||{},field:a.field||"image",types:a.types||"image/*",captionPlaceholder:a.captionPlaceholder||"Caption",buttonContent:a.buttonContent||""},this.uploader=new u.default({config:this.config,onUpload:function(e){return n.onUpload(e)},onError:function(e){return n.uploadingFailed(e)}}),this.ui=new r.default({api:s,config:this.config,onSelectFile:function(){n.uploader.uploadSelectedFile({onPreview:function(e){n.ui.showPreloader(e)}})}}),this.tunes=new i.default({api:s,onChange:function(e){return n.tuneToggled(e)}}),this._data={},this.data=o}return o(e,null,[{key:"displayInToolbox",get:function(){return!0}},{key:"toolboxIcon",get:function(){return a.default}}]),o(e,[{key:"render",value:function(){return this.ui.render(this.data)}},{key:"save",value:function(){var e=this.ui.nodes.caption;return this._data.caption=e.innerHTML,this.data}},{key:"renderSettings",value:function(){return this.tunes.render(this.data)}},{key:"appendCallback",value:function(){this.ui.nodes.fileButton.click()}},{key:"onPaste",value:function(e){var t=this;switch(e.type){case"tag":var n=e.detail.data;this.ui.showPreloader(n.src),this.uploader.uploadByUrl(n.src);break;case"pattern":var o=e.detail.data;this.ui.showPreloader(o),this.uploader.uploadByUrl(o);break;case"file":var r=e.detail.file;this.uploader.uploadByFile(r,{onPreview:function(e){t.ui.showPreloader(e)}})}}},{key:"onUpload",value:function(e){e.success&&e.file?this.image=e.file:this.uploadingFailed("incorrect response: "+JSON.stringify(e))}},{key:"uploadingFailed",value:function(e){console.log("Image Tool: uploading failed because of",e),this.api.notifier.show({message:"Can not upload an image, try another",style:"error"}),this.ui.hidePreloader()}},{key:"tuneToggled",value:function(e){this.setTune(e,!this._data[e])}},{key:"setTune",value:function(e,t){var n=this;if(this._data[e]=t,this.ui.applyTune(e,t),"stretched"===e){var o=this.api.blocks.getCurrentBlockIndex();setTimeout(function(){n.api.blocks.stretchBlock(o,t)},0)}}},{key:"data",set:function(e){var t=this;this.image=e.file,this._data.caption=e.caption||"",this.ui.fillCaption(this._data.caption),i.default.tunes.forEach(function(n){var o=n.name,r=void 0!==e[o]&&e[o];t.setTune(o,r)})},get:function(){return this._data}},{key:"image",set:function(e){this._data.file=e||{},e&&e.url&&this.ui.fillImage(e.url)}}],[{key:"pasteConfig",get:function(){return{tags:["img"],patterns:{image:/https?:\/\/\S+\.(gif|jpe?g|tiff|png)$/i},files:{mimeTypes:["image/*"]}}}}]),e}();t.default=c},function(e,t,n){var o=n(3);"string"==typeof o&&(o=[[e.i,o,""]]);var r={hmr:!0,transform:void 0,insertInto:void 0};n(5)(o,r);o.locals&&(e.exports=o.locals)},function(e,t,n){(e.exports=n(4)(!1)).push([e.i,".image-tool {\n --bg-color: #CDD1E0;\n --front-color: #388AE5;\n --border-color: #E8E8EB;\n}\n\n .image-tool__image {\n border-radius: 3px;\n overflow: hidden;\n margin-bottom: 10px;\n }\n\n .image-tool__image-picture {\n max-width: 100%;\n vertical-align: bottom;\n display: block;\n }\n\n .image-tool__image-preloader {\n width: 50px;\n height: 50px;\n border-radius: 50%;\n background-size: cover;\n margin: auto;\n position: relative;\n background-color: var(--bg-color);\n background-position: center center;\n }\n\n .image-tool__image-preloader::after {\n content: '';\n position: absolute;\n z-index: 3;\n width: 60px;\n height: 60px;\n border-radius: 50%;\n border: 2px solid var(--bg-color);\n border-top-color: var(--front-color);\n left: 50%;\n top: 50%;\n margin-top: -30px;\n margin-left: -30px;\n animation: image-preloader-spin 2s infinite linear;\n box-sizing: border-box;\n }\n\n .image-tool--empty .image-tool__image {\n display: none;\n }\n\n .image-tool--empty .image-tool__caption, .image-tool--loading .image-tool__caption {\n display: none;\n }\n\n .image-tool--filled .cdx-button {\n display: none;\n }\n\n .image-tool--filled .image-tool__image-preloader {\n display: none;\n }\n\n .image-tool--loading .image-tool__image {\n min-height: 200px;\n display: flex;\n border: 1px solid var(--border-color);\n background-color: #fff;\n }\n\n .image-tool--loading .image-tool__image-picture {\n display: none;\n }\n\n .image-tool--loading .cdx-button {\n display: none;\n }\n\n /**\n * Tunes\n * ----------------\n */\n\n .image-tool--withBorder .image-tool__image {\n border: 1px solid var(--border-color);\n }\n\n .image-tool--withBackground .image-tool__image {\n padding: 15px;\n background: var(--bg-color);\n }\n\n .image-tool--withBackground .image-tool__image-picture {\n max-width: 60%;\n margin: 0 auto;\n }\n\n .image-tool--stretched .image-tool__image-picture {\n width: 100%;\n }\n\n@keyframes image-preloader-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}",""])},function(e,t){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=function(e,t){var n=e[1]||"",o=e[3];if(!o)return n;if(t&&"function"==typeof btoa){var r=function(e){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e))))+" */"}(o),i=o.sources.map(function(e){return"/*# sourceURL="+o.sourceRoot+e+" */"});return[n].concat(i).concat([r]).join("\n")}return[n].join("\n")}(t,e);return t[2]?"@media "+t[2]+"{"+n+"}":n}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},r=0;r<this.length;r++){var i=this[r][0];"number"==typeof i&&(o[i]=!0)}for(r=0;r<e.length;r++){var a=e[r];"number"==typeof a[0]&&o[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),t.push(a))}},t}},function(e,t,n){var o={},r=function(e){var t;return function(){return void 0===t&&(t=e.apply(this,arguments)),t}}(function(){return window&&document&&document.all&&!window.atob}),i=function(e){var t={};return function(e){if("function"==typeof e)return e();if(void 0===t[e]){var n=function(e){return document.querySelector(e)}.call(this,e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}t[e]=n}return t[e]}}(),a=null,u=0,s=[],c=n(6);function l(e,t){for(var n=0;n<e.length;n++){var r=e[n],i=o[r.id];if(i){i.refs++;for(var a=0;a<i.parts.length;a++)i.parts[a](r.parts[a]);for(;a<r.parts.length;a++)i.parts.push(g(r.parts[a],t))}else{var u=[];for(a=0;a<r.parts.length;a++)u.push(g(r.parts[a],t));o[r.id]={id:r.id,refs:1,parts:u}}}}function f(e,t){for(var n=[],o={},r=0;r<e.length;r++){var i=e[r],a=t.base?i[0]+t.base:i[0],u={css:i[1],media:i[2],sourceMap:i[3]};o[a]?o[a].parts.push(u):n.push(o[a]={id:a,parts:[u]})}return n}function d(e,t){var n=i(e.insertInto);if(!n)throw new Error("Couldn't find a style target. This probably means that the value for the 'insertInto' parameter is invalid.");var o=s[s.length-1];if("top"===e.insertAt)o?o.nextSibling?n.insertBefore(t,o.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),s.push(t);else if("bottom"===e.insertAt)n.appendChild(t);else{if("object"!=typeof e.insertAt||!e.insertAt.before)throw new Error("[Style Loader]\n\n Invalid value for parameter 'insertAt' ('options.insertAt') found.\n Must be 'top', 'bottom', or Object.\n (https://github.com/webpack-contrib/style-loader#insertat)\n");var r=i(e.insertInto+" "+e.insertAt.before);n.insertBefore(t,r)}}function p(e){if(null===e.parentNode)return!1;e.parentNode.removeChild(e);var t=s.indexOf(e);t>=0&&s.splice(t,1)}function h(e){var t=document.createElement("style");return void 0===e.attrs.type&&(e.attrs.type="text/css"),m(t,e.attrs),d(e,t),t}function m(e,t){Object.keys(t).forEach(function(n){e.setAttribute(n,t[n])})}function g(e,t){var n,o,r,i;if(t.transform&&e.css){if(!(i=t.transform(e.css)))return function(){};e.css=i}if(t.singleton){var s=u++;n=a||(a=h(t)),o=y.bind(null,n,s,!1),r=y.bind(null,n,s,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",m(t,e.attrs),d(e,t),t}(t),o=function(e,t,n){var o=n.css,r=n.sourceMap,i=void 0===t.convertToAbsoluteUrls&&r;(t.convertToAbsoluteUrls||i)&&(o=c(o));r&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([o],{type:"text/css"}),u=e.href;e.href=URL.createObjectURL(a),u&&URL.revokeObjectURL(u)}.bind(null,n,t),r=function(){p(n),n.href&&URL.revokeObjectURL(n.href)}):(n=h(t),o=function(e,t){var n=t.css,o=t.media;o&&e.setAttribute("media",o);if(e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}.bind(null,n),r=function(){p(n)});return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else r()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=r()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=f(e,t);return l(n,t),function(e){for(var r=[],i=0;i<n.length;i++){var a=n[i];(u=o[a.id]).refs--,r.push(u)}e&&l(f(e,t),t);for(i=0;i<r.length;i++){var u;if(0===(u=r[i]).refs){for(var s=0;s<u.parts.length;s++)u.parts[s]();delete o[u.id]}}}};var v=function(){var e=[];return function(t,n){return e[t]=n,e.filter(Boolean).join("\n")}}();function y(e,t,n,o){var r=n?"":o.css;if(e.styleSheet)e.styleSheet.cssText=v(t,r);else{var i=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}},function(e,t){e.exports=function(e){var t="undefined"!=typeof window&&window.location;if(!t)throw new Error("fixUrls requires window.location");if(!e||"string"!=typeof e)return e;var n=t.protocol+"//"+t.host,o=n+t.pathname.replace(/\/[^\/]*$/,"/");return e.replace(/url\s*\(((?:[^)(]|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gi,function(e,t){var r,i=t.trim().replace(/^"(.*)"$/,function(e,t){return t}).replace(/^'(.*)'$/,function(e,t){return t});return/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(i)?e:(r=0===i.indexOf("//")?i:0===i.indexOf("/")?n+i:o+i.replace(/^\.\//,""),"url("+JSON.stringify(r)+")")})}},function(e,t){e.exports='<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M3.15 13.628A7.749 7.749 0 0 0 10 17.75a7.74 7.74 0 0 0 6.305-3.242l-2.387-2.127-2.765 2.244-4.389-4.496-3.614 3.5zm-.787-2.303l4.446-4.371 4.52 4.63 2.534-2.057 3.533 2.797c.23-.734.354-1.514.354-2.324a7.75 7.75 0 1 0-15.387 1.325zM10 20C4.477 20 0 15.523 0 10S4.477 0 10 0s10 4.477 10 10-4.477 10-10 10z"></path></svg>'},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),r=n(0),i=s(n(9)),a=s(n(10)),u=s(n(11));function s(e){return e&&e.__esModule?e:{default:e}}var c=function(){function e(t){var n=t.api,o=t.onChange;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.api=n,this.onChange=o,this.buttons=[]}return o(e,[{key:"render",value:function(t){var n=this,o=(0,r.make)("div",this.CSS.wrapper);return this.buttons=[],e.tunes.forEach(function(e){var i=(0,r.make)("div",[n.CSS.buttonBase,n.CSS.button],{innerHTML:e.icon,title:e.title});i.addEventListener("click",function(){n.tuneClicked(e.name)}),i.dataset.tune=e.name,i.classList.toggle(n.CSS.buttonActive,t[e.name]),n.buttons.push(i),o.appendChild(i)}),o}},{key:"tuneClicked",value:function(e){var t=this.buttons.find(function(t){return t.dataset.tune===e});t.classList.toggle(this.CSS.buttonActive,!t.classList.contains(this.CSS.buttonActive)),this.onChange(e)}},{key:"CSS",get:function(){return{wrapper:"",buttonBase:this.api.styles.settingsButton,button:"image-tool__tune",buttonActive:this.api.styles.settingsButtonActive}}}],[{key:"tunes",get:function(){return[{name:"withBorder",icon:a.default,title:"With border"},{name:"stretched",icon:u.default,title:"Stretch image"},{name:"withBackground",icon:i.default,title:"With background"}]}}]),e}();t.default=c},function(e,t){e.exports='<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10.043 8.265l3.183-3.183h-2.924L4.75 10.636v2.923l4.15-4.15v2.351l-2.158 2.159H8.9v2.137H4.7c-1.215 0-2.2-.936-2.2-2.09v-8.93c0-1.154.985-2.09 2.2-2.09h10.663l.033-.033.034.034c1.178.04 2.12.96 2.12 2.089v3.23H15.3V5.359l-2.906 2.906h-2.35zM7.951 5.082H4.75v3.201l3.201-3.2zm5.099 7.078v3.04h4.15v-3.04h-4.15zm-1.1-2.137h6.35c.635 0 1.15.489 1.15 1.092v5.13c0 .603-.515 1.092-1.15 1.092h-6.35c-.635 0-1.15-.489-1.15-1.092v-5.13c0-.603.515-1.092 1.15-1.092z"></path></svg>'},function(e,t){e.exports='<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M15.8 10.592v2.043h2.35v2.138H15.8v2.232h-2.25v-2.232h-2.4v-2.138h2.4v-2.28h2.25v.237h1.15-1.15zM1.9 8.455v-3.42c0-1.154.985-2.09 2.2-2.09h4.2v2.137H4.15v3.373H1.9zm0 2.137h2.25v3.325H8.3v2.138H4.1c-1.215 0-2.2-.936-2.2-2.09v-3.373zm15.05-2.137H14.7V5.082h-4.15V2.945h4.2c1.215 0 2.2.936 2.2 2.09v3.42z"></path></svg>'},function(e,t){e.exports='<svg width="17" height="10" viewBox="0 0 17 10" xmlns="http://www.w3.org/2000/svg"><path d="M13.568 5.925H4.056l1.703 1.703a1.125 1.125 0 0 1-1.59 1.591L.962 6.014A1.069 1.069 0 0 1 .588 4.26L4.38.469a1.069 1.069 0 0 1 1.512 1.511L4.084 3.787h9.606l-1.85-1.85a1.069 1.069 0 1 1 1.512-1.51l3.792 3.791a1.069 1.069 0 0 1-.475 1.788L13.514 9.16a1.125 1.125 0 0 1-1.59-1.591l1.644-1.644z"></path></svg>'},function(e,t){e.exports='<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150.242V79c0-18.778-15.222-34-34-34H79c-18.778 0-34 15.222-34 34v42.264l67.179-44.192 80.398 71.614 56.686-29.14L291 150.242zm-.345 51.622l-42.3-30.246-56.3 29.884-80.773-66.925L45 174.187V197c0 18.778 15.222 34 34 34h178c17.126 0 31.295-12.663 33.655-29.136zM79 0h178c43.63 0 79 35.37 79 79v118c0 43.63-35.37 79-79 79H79c-43.63 0-79-35.37-79-79V79C0 35.37 35.37 0 79 0z"></path></svg>'},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var n=[],o=!0,r=!1,i=void 0;try{for(var a,u=e[Symbol.iterator]();!(o=(a=u.next()).done)&&(n.push(a.value),!t||n.length!==t);o=!0);}catch(e){r=!0,i=e}finally{try{!o&&u.return&&u.return()}finally{if(r)throw i}}return n}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),i=function(e){return e&&e.__esModule?e:{default:e}}(n(14));var a=function(){function e(t){var n=t.config,o=t.onUpload,r=t.onError;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=n,this.onUpload=o,this.onError=r}return r(e,[{key:"uploadSelectedFile",value:function(e){var t=this,n=e.onPreview;i.default.transport({url:this.config.endpoints.byFile,data:this.config.additionalRequestData,accept:this.config.types,headers:this.config.additionalRequestHeaders,beforeSend:function(e){var t=new FileReader;t.readAsDataURL(e[0]),t.onload=function(e){n(e.target.result)}},fieldName:this.config.field}).then(function(e){t.onUpload(e)}).catch(function(e){t.onError(e)})}},{key:"uploadByUrl",value:function(e){var t=this;i.default.post({url:this.config.endpoints.byUrl,data:Object.assign({url:e},this.config.additionalRequestData),type:i.default.contentType.JSON,headers:this.config.additionalRequestHeaders}).then(function(e){t.onUpload(e)}).catch(function(e){t.onError(e)})}},{key:"uploadByFile",value:function(e,t){var n=this,r=t.onPreview,a=new FileReader;a.readAsDataURL(e),a.onload=function(e){r(e.target.result)};var u=new FormData;u.append(this.config.field,e),this.config.additionalRequestData&&Object.keys(this.config.additionalRequestData).length&&Object.entries(this.config.additionalRequestData).forEach(function(e){var t=o(e,2),n=t[0],r=t[1];u.append(n,r)}),i.default.post({url:this.config.endpoints.byFile,data:u,type:i.default.contentType.JSON,headers:this.config.additionalRequestHeaders}).then(function(e){n.onUpload(e)}).catch(function(e){n.onError(e)})}}]),e}();t.default=a},function(e,t,n){window,e.exports=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";(function(e){var o=n(2),r=setTimeout;function i(){}function a(e){if(!(this instanceof a))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],f(e,this)}function u(e,t){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,a._immediateFn(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null!==n){var o;try{o=n(e._value)}catch(e){return void c(t.promise,e)}s(t.promise,o)}else(1===e._state?s:c)(t.promise,e._value)})):e._deferreds.push(t)}function s(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof a)return e._state=3,e._value=t,void l(e);if("function"==typeof n)return void f(function(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,l(e)}catch(t){c(e,t)}}function c(e,t){e._state=2,e._value=t,l(e)}function l(e){2===e._state&&0===e._deferreds.length&&a._immediateFn(function(){e._handled||a._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)u(e,e._deferreds[t]);e._deferreds=null}function f(e,t){var n=!1;try{e(function(e){n||(n=!0,s(t,e))},function(e){n||(n=!0,c(t,e))})}catch(e){if(n)return;n=!0,c(t,e)}}a.prototype.catch=function(e){return this.then(null,e)},a.prototype.then=function(e,t){var n=new this.constructor(i);return u(this,new function(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}(e,t,n)),n},a.prototype.finally=o.a,a.all=function(e){return new a(function(t,n){if(!e||void 0===e.length)throw new TypeError("Promise.all accepts an array");var o=Array.prototype.slice.call(e);if(0===o.length)return t([]);var r=o.length;function i(e,a){try{if(a&&("object"==typeof a||"function"==typeof a)){var u=a.then;if("function"==typeof u)return void u.call(a,function(t){i(e,t)},n)}o[e]=a,0==--r&&t(o)}catch(e){n(e)}}for(var a=0;a<o.length;a++)i(a,o[a])})},a.resolve=function(e){return e&&"object"==typeof e&&e.constructor===a?e:new a(function(t){t(e)})},a.reject=function(e){return new a(function(t,n){n(e)})},a.race=function(e){return new a(function(t,n){for(var o=0,r=e.length;o<r;o++)e[o].then(t,n)})},a._immediateFn="function"==typeof e&&function(t){e(t)}||function(e){r(e,0)},a._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},t.a=a}).call(this,n(5).setImmediate)},function(e,t,n){"use strict";t.a=function(e){var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){return t.reject(n)})})}},function(e,t,n){"use strict";function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n(4);var r=n(8),i=function(){var e={URLENCODED:"application/x-www-form-urlencoded; charset=utf-8",FORM:"multipart/form-data",JSON:"application/json; charset=utf-8"},t=function(e){return new Promise(function(t,n){e=a(e),e=u(e);var o=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");o.open(e.method,e.url),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(e.headers).forEach(function(t){var n=e.headers[t];o.setRequestHeader(t,n)});var r=e.ratio;o.upload.addEventListener("progress",function(t){var n=Math.round(t.loaded/t.total*100),o=Math.ceil(n*r/100);e.progress(o)},!1),o.addEventListener("progress",function(t){var n=Math.round(t.loaded/t.total*100),o=Math.ceil(n*(100-r)/100)+r;e.progress(o)},!1),o.onreadystatechange=function(){if(4===o.readyState){var e=o.response;try{e=JSON.parse(e)}catch(e){}200===o.status?t(e):n(e)}},o.send(e.data)})},n=function(e){return e.method="POST",t(e)},a=function(t){if(!t.url||"string"!=typeof t.url)throw new Error("Url must be a non-empty string");if(t.method&&"string"!=typeof t.method)throw new Error("`method` must be a string or null");if(t.method=t.method?t.method.toUpperCase():"GET",t.headers&&"object"!==o(t.headers))throw new Error("`headers` must be an object or null");if(t.headers=t.headers||{},t.type&&("string"!=typeof t.type||!Object.values(e).includes(t.type)))throw new Error("`type` must be taken from module's «contentType» library");if(t.progress&&"function"!=typeof t.progress)throw new Error("`progress` must be a function or null");if(t.progress=t.progress||function(e){},t.beforeSend=t.beforeSend||function(e){},t.ratio&&"number"!=typeof t.ratio)throw new Error("`ratio` must be a number");if(t.ratio<0||t.ratio>100)throw new Error("`ratio` must be in a 0-100 interval");if(t.ratio=t.ratio||90,t.accept&&"string"!=typeof t.accept)throw new Error("`accept` must be a string with a list of allowed mime-types");if(t.accept=t.accept||"*/*",t.multiple&&"boolean"!=typeof t.multiple)throw new Error("`multiple` must be a true or false");if(t.multiple=t.multiple||!1,t.fieldName&&"string"!=typeof t.fieldName)throw new Error("`fieldName` must be a string");return t.fieldName=t.fieldName||"files",t},u=function(t){switch(t.method){case"GET":var n=s(t.data,e.URLENCODED);delete t.data,t.url=/\?/.test(t.url)?t.url+"&"+n:t.url+"?"+n;break;case"POST":case"PUT":case"DELETE":case"UPDATE":var o=function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).type||e.JSON}(t);(r.isFormData(t.data)||r.isFormElement(t.data))&&(o=e.FORM),t.data=s(t.data,o),o!==i.contentType.FORM&&(t.headers["content-type"]=o)}return t},s=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};switch(arguments.length>1?arguments[1]:void 0){case e.URLENCODED:return r.urlEncode(t);case e.JSON:return r.jsonEncode(t);case e.FORM:return r.formEncode(t);default:return t}};return{contentType:e,request:t,get:function(e){return e.method="GET",t(e)},post:n,transport:function(e){return e=a(e),r.transport(e).then(function(t){return r.isObject(e.data)&&Object.keys(e.data).forEach(function(n){var o=e.data[n];t.append(n,o)}),e.data=t,n(e)})}}}();e.exports=i},function(e,t,n){"use strict";n.r(t);var o=n(1);window.Promise=window.Promise||o.a},function(e,t,n){(function(e){var o=void 0!==e&&e||"undefined"!=typeof self&&self||window,r=Function.prototype.apply;function i(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new i(r.call(setTimeout,o,arguments),clearTimeout)},t.setInterval=function(){return new i(r.call(setInterval,o,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(o,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(6),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n(0))},function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var o,r=1,i={},a=!1,u=e.document,s=Object.getPrototypeOf&&Object.getPrototypeOf(e);s=s&&s.setTimeout?s:e,"[object process]"==={}.toString.call(e.process)?o=function(e){t.nextTick(function(){l(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?function(){var t="setImmediate$"+Math.random()+"$",n=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&l(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),o=function(n){e.postMessage(t+n,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){l(e.data)},o=function(t){e.port2.postMessage(t)}}():u&&"onreadystatechange"in u.createElement("script")?function(){var e=u.documentElement;o=function(t){var n=u.createElement("script");n.onreadystatechange=function(){l(t),n.onreadystatechange=null,e.removeChild(n),n=null},e.appendChild(n)}}():o=function(e){setTimeout(l,0,e)},s.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var a={callback:e,args:t};return i[r]=a,o(r),r++},s.clearImmediate=c}function c(e){delete i[e]}function l(e){if(a)setTimeout(l,0,e);else{var t=i[e];if(t){a=!0;try{!function(e){var t=e.callback,o=e.args;switch(o.length){case 0:t();break;case 1:t(o[0]);break;case 2:t(o[0],o[1]);break;case 3:t(o[0],o[1],o[2]);break;default:t.apply(n,o)}}(t)}finally{c(e),a=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n(0),n(7))},function(e,t){var n,o,r=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function u(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(e){o=a}}();var s,c=[],l=!1,f=-1;function d(){l&&s&&(l=!1,s.length?c=s.concat(c):f=-1,c.length&&p())}function p(){if(!l){var e=u(d);l=!0;for(var t=c.length;t;){for(s=c,c=[];++f<t;)s&&s[f].run();f=-1,t=c.length}s=null,l=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function h(e,t){this.fun=e,this.array=t}function m(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new h(e,t)),1!==c.length||l||u(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=m,r.addListener=m,r.once=m,r.off=m,r.removeListener=m,r.removeAllListeners=m,r.emit=m,r.prependListener=m,r.prependOnceListener=m,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},function(e,t,n){function o(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var r=n(9);e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return function(e,t,n){n&&o(e,n)}(e,0,[{key:"urlEncode",value:function(e){return r(e)}},{key:"jsonEncode",value:function(e){return JSON.stringify(e)}},{key:"formEncode",value:function(e){if(this.isFormData(e))return e;if(this.isFormElement(e))return new FormData(e);if(this.isObject(e)){var t=new FormData;return Object.keys(e).forEach(function(n){var o=e[n];t.append(n,o)}),t}throw new Error("`data` must be an instance of Object, FormData or <FORM> HTMLElement")}},{key:"isObject",value:function(e){return"[object Object]"===Object.prototype.toString.call(e)}},{key:"isFormData",value:function(e){return e instanceof FormData}},{key:"isFormElement",value:function(e){return e instanceof HTMLFormElement}},{key:"transport",value:function(e){return new Promise(function(t,n){var o=document.createElement("INPUT");o.type="file",e.multiple&&o.setAttribute("multiple","multiple"),e.accept&&o.setAttribute("accept",e.accept),o.addEventListener("change",function(n){for(var o=n.target.files,r=new FormData,i=0;i<o.length;i++)r.append(e.fieldName,o[i],o[i].name);e.beforeSend(o),t(r)},!1),o.click()})}}]),e}()},function(e,t){var n=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,escape).replace(/%20/g,"+")},o=function(e,t,r,i){return t=t||null,r=r||"&",i=i||null,e?function(e){for(var t=new Array,n=0;n<e.length;n++)e[n]&&t.push(e[n]);return t}(Object.keys(e).map(function(a){var u,s=a;if(i&&(s=i+"["+s+"]"),"object"==typeof e[a]&&null!==e[a])u=o(e[a],null,r,s);else{t&&(s=function(e){return!isNaN(parseFloat(e))&&isFinite(e)}(s)?t+Number(s):s);var c=e[a];c=(c=0===(c=!1===(c=!0===c?"1":c)?"0":c)?"0":c)||"",u=n(s)+"="+n(c)}return u})).join(r).replace(/[!'()*]/g,""):""};e.exports=o}])}]).default}); |
{ | ||
"name": "codex.editor.image", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
@@ -26,2 +26,5 @@ "codex editor", | ||
"css-loader": "^1.0.0", | ||
"eslint": "^5.9.0", | ||
"eslint-config-codex": "github:codex-team/eslint-config", | ||
"eslint-loader": "^2.1.1", | ||
"formidable": "^1.2.1", | ||
@@ -31,2 +34,3 @@ "postcss-loader": "^3.0.0", | ||
"postcss-nested-ancestors": "^2.0.0", | ||
"request": "^2.88.0", | ||
"style-loader": "^0.21.0", | ||
@@ -33,0 +37,0 @@ "svg-inline-loader": "^0.8.0", |
@@ -14,7 +14,8 @@ ![](https://badgen.net/badge/CodeX%20Editor/v2.0/blue) | ||
- Pasting images by drag-n-drop | ||
- Pasting files and screenshots from Clipboard | ||
- Allows to add border, background | ||
- Allows to stretch image to the container's full-width | ||
- Allows to stretch image to the container's full-width | ||
**Note** This Tool requires server-side implementation for file uploading. See [backend response format](#server-format) for more details. | ||
## Installation | ||
@@ -56,3 +57,3 @@ | ||
... | ||
tools: { | ||
@@ -63,7 +64,10 @@ ... | ||
config: { | ||
url: 'http://localhost:8008/', // Your backend uploader endpoint | ||
endpoints: { | ||
byFile: 'http://localhost:8008/uploadFile', // Your backend file uploader endpoint | ||
byUrl: 'http://localhost:8008/fetchUrl', // Your endpoint that provides uploading by Url | ||
} | ||
} | ||
} | ||
} | ||
... | ||
@@ -73,10 +77,15 @@ }); | ||
## Config Params | ||
## Config Params | ||
Image Tool supports these configuration parameters: | ||
| Field | Type | Description | | ||
| ----- | -------- | ------------------ | | ||
| url | `string` | **Required** Path for file uploading | | ||
| endpoints | `{byFile: string, byUrl: string}` | **Required** Endpoints for file uploading. <br> Contains 2 fields: <br> __byFile__ - for file uploading <br> __byUrl__ - for uploading by URL | | ||
| field | `string` | (default: `image`) Name of uploaded image field in POST request | | ||
| types | `string` | (default: `image/*`) Mime-types of files that can be [accepted with file selection](https://github.com/codex-team/ajax#accept-string).| | ||
| additionalRequestData | `object` | Object with any data you want to send with uploading requests | | ||
| additionalRequestHeaders | `object` | Object with any custom headers which will be added to request. [See example](https://github.com/codex-team/ajax/blob/e5bc2a2391a18574c88b7ecd6508c29974c3e27f/README.md#headers-object) | | ||
| captionPlaceholder | `string` | (default: `Caption`) Placeholder for Caption input | | ||
| buttonContent | `string` | Allows to override HTML content of «Select file» button | | ||
@@ -123,6 +132,15 @@ ## Tool's settings | ||
This Tool works by following scheme: | ||
This Tool works by one of the following schemes: | ||
1. Uploading files from the device | ||
2. Uploading by URL (handle image-like URL's pasting) | ||
3. Uploading by drag-n-drop file | ||
4. Uploading by pasting from Clipboard | ||
### Uploading files from device <a name="from-device"></a> | ||
Scenario: | ||
1. User select file from the device | ||
2. Tool sends it to **your** backend | ||
2. Tool sends it to **your** backend (on `config.endpoint.byFile` route) | ||
3. Your backend should save file and return file data with JSON at specified format. | ||
@@ -148,6 +166,22 @@ 4. Image tool shows saved image and stores server answer | ||
**file** - uploaded file data. **Must** contain an `url` field with full public path to the uploaded image. | ||
Also, can contain any additional fields you want to store. For example, width, height, id etc. | ||
All additional fields will be saved at the `file` object of output data. | ||
**file** - uploaded file data. **Must** contain an `url` field with full public path to the uploaded image. | ||
Also, can contain any additional fields you want to store. For example, width, height, id etc. | ||
All additional fields will be saved at the `file` object of output data. | ||
### Uploading by pasted URL | ||
Scenario: | ||
1. User pastes an URL of the image file to the Editor | ||
2. Editor pass pasted string to the Image Tool | ||
3. Tool sends it to **your** backend (on `config.endpoint.byUrl` route) via 'url' POST-parameter | ||
3. Your backend should accept URL, **download and save the original file by passed URL** and return file data with JSON at specified format. | ||
4. Image tool shows saved image and stores server answer | ||
Response of your uploader should be at the same format as described at «[Uploading files from device](#from-device)» section | ||
### Uploading by drag-n-drop or from Clipboard | ||
Your backend will accept file as FormData object in field name, specified by `config.field` (by default, «`image`»). | ||
You should save it and return the same response format as described above. |
146
src/index.js
@@ -10,5 +10,5 @@ /** | ||
* 1) index.js — main Tool's interface, public API and methods for working with data | ||
* 2) ui.js — module for UI manipulations: render, showing preloader and file-select handlers (including AJAX transport) | ||
* 3) tunes.js — working with Block Tunes: render buttons, handle clicks | ||
* 4) converter.js — utils for extracting Image Tool Data from pasted content | ||
* 2) uploader.js — module that has methods for sending files via AJAX: from device, by URL or File pasting | ||
* 3) ui.js — module for UI manipulations: render, showing preloader, etc | ||
* 4) tunes.js — working with Block Tunes: render buttons, handle clicks | ||
* | ||
@@ -18,3 +18,3 @@ * For debug purposes there is a testing server | ||
* | ||
* $ node tests/server.js | ||
* $ node dev/server.js | ||
* | ||
@@ -26,3 +26,6 @@ * It will expose 8008 port, so you can pass http://localhost:8008 with the Tools config: | ||
* config: { | ||
* url: 'http://localhost:8008' | ||
* endpoints: { | ||
* byFile: 'http://localhost:8008/uploadFile', | ||
* byUrl: 'http://localhost:8008/fetchUrl', | ||
* } | ||
* }, | ||
@@ -43,2 +46,3 @@ * }, | ||
// eslint-disable-next-line | ||
import css from './index.css'; | ||
@@ -48,3 +52,3 @@ import Ui from './ui'; | ||
import ToolboxIcon from './svg/toolbox.svg'; | ||
import Converter from './converter'; | ||
import Uploader from './uploader'; | ||
@@ -54,6 +58,11 @@ /** | ||
* @description Config supported by Tool | ||
* @property {string} url - upload endpoint | ||
* @property {object} endpoints - upload endpoints | ||
* @property {string} endpoints.byFile - upload by file | ||
* @property {string} endpoints.byUrl - upload by URL | ||
* @property {string} field - field name for uploaded image | ||
* @property {string} types - available mime-types | ||
* @property {string} captionPlaceholder - placeholder for Caption field | ||
* @property {object} additionalRequestData - any data to send with requests | ||
* @property {object} additionalRequestHeaders - allows to pass custom headers with Request | ||
* @property {string} buttonContent - overrides for Select File button | ||
*/ | ||
@@ -99,14 +108,38 @@ | ||
this.config = { | ||
url: config.url || '', | ||
endpoints: config.endpoints || '', | ||
additionalRequestData: config.additionalRequestData || {}, | ||
additionalRequestHeaders: config.additionalRequestHeaders || {}, | ||
field: config.field || 'image', | ||
types: config.types || 'image/*', | ||
captionPlaceholder: config.captionPlaceholder || 'Caption' | ||
captionPlaceholder: config.captionPlaceholder || 'Caption', | ||
buttonContent: config.buttonContent || '' | ||
}; | ||
/** | ||
* Module for file uploading | ||
*/ | ||
this.uploader = new Uploader({ | ||
config: this.config, | ||
onUpload: (response) => this.onUpload(response), | ||
onError: (error) => this.uploadingFailed(error) | ||
}); | ||
/** | ||
* Module for working with UI | ||
*/ | ||
this.ui = new Ui({ | ||
api, | ||
config: this.config, | ||
onUpload: (response) => this.onUpload(response) | ||
onSelectFile: () => { | ||
this.uploader.uploadSelectedFile({ | ||
onPreview: (src) => { | ||
this.ui.showPreloader(src); | ||
} | ||
}); | ||
} | ||
}); | ||
/** | ||
* Module for working with tunes | ||
*/ | ||
this.tunes = new Tunes({ | ||
@@ -142,2 +175,3 @@ api, | ||
const caption = this.ui.nodes.caption; | ||
this._data.caption = caption.innerHTML; | ||
@@ -167,10 +201,8 @@ | ||
/** | ||
* Specify paste substitutes | ||
* @public | ||
* | ||
* @see {@link ../../../docs/tools.md#paste-handling} | ||
* @see {@link https://github.com/codex-team/codex.editor/blob/master/docs/tools.md#paste-handling} | ||
*/ | ||
static get onPaste() { | ||
static get pasteConfig() { | ||
return { | ||
@@ -180,20 +212,49 @@ /** | ||
*/ | ||
tags: ['img'], | ||
handler: Converter.fromHtml, | ||
tags: [ 'img' ], | ||
/** | ||
* Drag n drop file from into the Editor | ||
* Paste URL of image into the Editor | ||
*/ | ||
files: { | ||
mimeTypes: ['image/*'] | ||
patterns: { | ||
image: /https?:\/\/\S+\.(gif|jpe?g|tiff|png)$/i | ||
}, | ||
fileHandler: Converter.fromDroppedFile, | ||
/** | ||
* Paste URL of image into the Editor | ||
* Drag n drop file from into the Editor | ||
*/ | ||
patterns: { | ||
image: /https?:\/\/\S+\.(gif|jpe?g|tiff|png)$/i | ||
}, | ||
patternHandler: Converter.fromPastedUrl, | ||
files: { | ||
mimeTypes: [ 'image/*' ] | ||
} | ||
}; | ||
} | ||
/** | ||
* Specify paste handlers | ||
* @public | ||
* | ||
* @see {@link https://github.com/codex-team/codex.editor/blob/master/docs/tools.md#paste-handling} | ||
*/ | ||
onPaste(event) { | ||
switch (event.type) { | ||
case 'tag': | ||
const image = event.detail.data; | ||
this.ui.showPreloader(image.src); | ||
this.uploader.uploadByUrl(image.src); | ||
break; | ||
case 'pattern': | ||
const url = event.detail.data; | ||
this.ui.showPreloader(url); | ||
this.uploader.uploadByUrl(url); | ||
break; | ||
case 'file': | ||
const file = event.detail.file; | ||
this.uploader.uploadByFile(file, { | ||
onPreview: (src) => { | ||
this.ui.showPreloader(src); | ||
} | ||
}); | ||
break; | ||
} | ||
@@ -213,3 +274,3 @@ } | ||
*/ | ||
set data(data){ | ||
set data(data) { | ||
this.image = data.file; | ||
@@ -220,5 +281,6 @@ | ||
Tunes.tunes.forEach( ({name: tune}) => { | ||
Tunes.tunes.forEach(({name: tune}) => { | ||
const value = data[tune] !== undefined ? data[tune] : false; | ||
this.setTune(tune, value) | ||
this.setTune(tune, value); | ||
}); | ||
@@ -233,3 +295,3 @@ } | ||
*/ | ||
get data(){ | ||
get data() { | ||
return this._data; | ||
@@ -253,3 +315,3 @@ } | ||
/** | ||
* Field uploading callback | ||
* File uploading callback | ||
* @private | ||
@@ -260,6 +322,26 @@ * | ||
onUpload(response) { | ||
this.image = response.file; | ||
if (response.success && response.file) { | ||
this.image = response.file; | ||
} else { | ||
this.uploadingFailed('incorrect response: ' + JSON.stringify(response)); | ||
} | ||
} | ||
/** | ||
* Handle uploader errors | ||
* @private | ||
* | ||
* @param {string} errorText | ||
*/ | ||
uploadingFailed(errorText) { | ||
console.log('Image Tool: uploading failed because of', errorText); | ||
this.api.notifier.show({ | ||
message: 'Can not upload an image, try another', | ||
style: 'error' | ||
}); | ||
this.ui.hidePreloader(); | ||
} | ||
/** | ||
* Callback fired when Block Tune is activated | ||
@@ -285,3 +367,3 @@ * @private | ||
if (tuneName === 'stretched'){ | ||
if (tuneName === 'stretched') { | ||
const blockId = this.api.blocks.getCurrentBlockIndex(); | ||
@@ -288,0 +370,0 @@ |
@@ -10,3 +10,7 @@ import {make} from './ui'; | ||
export default class Tunes { | ||
constructor({api, onChange}){ | ||
/** | ||
* @param {object} api - Editor API | ||
* @param {function} onChange - tune toggling callback | ||
*/ | ||
constructor({api, onChange}) { | ||
this.api = api; | ||
@@ -20,3 +24,3 @@ this.onChange = onChange; | ||
*/ | ||
static get tunes(){ | ||
static get tunes() { | ||
return [ | ||
@@ -37,6 +41,10 @@ { | ||
title: 'With background' | ||
}, | ||
] | ||
} | ||
]; | ||
} | ||
/** | ||
* Styles | ||
* @return {{wrapper: string, buttonBase: *, button: string, buttonActive: *}} | ||
*/ | ||
get CSS() { | ||
@@ -47,4 +55,4 @@ return { | ||
button: 'image-tool__tune', | ||
buttonActive: this.api.styles.settingsButtonActive, | ||
} | ||
buttonActive: this.api.styles.settingsButtonActive | ||
}; | ||
} | ||
@@ -62,3 +70,3 @@ | ||
Tunes.tunes.forEach( tune => { | ||
Tunes.tunes.forEach(tune => { | ||
let el = make('div', [this.CSS.buttonBase, this.CSS.button], { | ||
@@ -88,3 +96,3 @@ innerHTML: tune.icon, | ||
*/ | ||
tuneClicked(tuneName){ | ||
tuneClicked(tuneName) { | ||
let button = this.buttons.find(el => el.dataset.tune === tuneName); | ||
@@ -91,0 +99,0 @@ |
126
src/ui.js
import buttonIcon from './svg/button-icon.svg'; | ||
import ajax from '@codexteam/ajax'; | ||
@@ -7,12 +6,18 @@ /** | ||
* - rendering base structure | ||
* - handle files selection and sending | ||
* - show/hide preview | ||
* - apply tune view | ||
*/ | ||
export default class Ui { | ||
constructor({api, config, onUpload}){ | ||
/** | ||
* @param {object} api - Editor.js API | ||
* @param {ImageConfig} config - user config | ||
* @param {function} onSelectFile - callback for clicks on Select file buttor | ||
*/ | ||
constructor({api, config, onSelectFile}) { | ||
this.api = api; | ||
this.config = config; | ||
this.onUpload = onUpload; | ||
this.onSelectFile = onSelectFile; | ||
this.nodes = { | ||
wrapper: make('div', [this.CSS.baseClass, this.CSS.wrapper]), | ||
imageContainer: make('div', [this.CSS.imageContainer]), | ||
imageContainer: make('div', [ this.CSS.imageContainer ]), | ||
fileButton: this.createFileButton(), | ||
@@ -23,3 +28,3 @@ imageEl: undefined, | ||
contentEditable: true | ||
}), | ||
}) | ||
}; | ||
@@ -43,2 +48,7 @@ | ||
} | ||
/** | ||
* CSS classes | ||
* @constructor | ||
*/ | ||
get CSS() { | ||
@@ -58,4 +68,4 @@ return { | ||
imageEl: 'image-tool__image-picture', | ||
caption: 'image-tool__caption', | ||
} | ||
caption: 'image-tool__caption' | ||
}; | ||
}; | ||
@@ -70,8 +80,8 @@ | ||
*/ | ||
static get status(){ | ||
static get status() { | ||
return { | ||
EMPTY: 'empty', | ||
UPLOADING: 'loading', | ||
FILLED: 'filled', | ||
} | ||
FILLED: 'filled' | ||
}; | ||
} | ||
@@ -84,3 +94,3 @@ | ||
render(toolData) { | ||
if (!toolData.file || Object.keys(toolData.file).length === 0){ | ||
if (!toolData.file || Object.keys(toolData.file).length === 0) { | ||
this.toggleStatus(Ui.status.EMPTY); | ||
@@ -98,9 +108,9 @@ } else { | ||
*/ | ||
createFileButton(){ | ||
let button = make('div', [this.CSS.button]); | ||
createFileButton() { | ||
let button = make('div', [ this.CSS.button ]); | ||
button.innerHTML = `${buttonIcon} Select an Image`; | ||
button.innerHTML = this.config.buttonContent || `${buttonIcon} Select an Image`; | ||
button.addEventListener('click', () => { | ||
this.selectFile(); | ||
this.onSelectFile(); | ||
}); | ||
@@ -112,36 +122,15 @@ | ||
/** | ||
* Handle clicks on the upload file button | ||
* @fires ajax.transport() | ||
* @fires this.onUpload() - callback passed to the constructor | ||
* Shows uploading preloader | ||
* @param {string} src - preview source | ||
*/ | ||
selectFile(){ | ||
ajax.transport({ | ||
url: this.config.url, | ||
accept: this.config.types, | ||
beforeSend: (files) => { | ||
this.beforeSend(files[0]); | ||
}, | ||
fieldName: this.config.field | ||
}) | ||
.then((response) => { | ||
if (response.success && response.file){ | ||
this.onUpload(response); | ||
} else { | ||
this.uploadingError('incorrect response: ' + JSON.stringify(response)); | ||
} | ||
}) | ||
.catch((error) => { | ||
this.uploadingError(error); | ||
}); | ||
showPreloader(src) { | ||
this.nodes.imagePreloader.style.backgroundImage = `url(${src})`; | ||
this.toggleStatus(Ui.status.UPLOADING); | ||
} | ||
/** | ||
* Failed uploading handler | ||
* @param {string} message | ||
* Hide uploading preloader | ||
*/ | ||
uploadingError(message){ | ||
console.log('Image Tool: uploading failed because of', message); | ||
/** | ||
* @todo show notify through the Notify API | ||
*/ | ||
hidePreloader() { | ||
this.nodes.imagePreloader.style.backgroundImage = ''; | ||
@@ -152,31 +141,6 @@ this.toggleStatus(Ui.status.EMPTY); | ||
/** | ||
* Called before sending, accepts uploaded file | ||
* Uses to sho preview and loader | ||
* @param {File} fileUploaded | ||
*/ | ||
beforeSend(fileUploaded){ | ||
const reader = new FileReader(); | ||
reader.readAsDataURL(fileUploaded); | ||
reader.onload = (e) => { | ||
this.showPreloader(e.target.result); | ||
}; | ||
} | ||
/** | ||
* Shows uploading preloader | ||
* @param {string} src - preview source | ||
*/ | ||
showPreloader(src){ | ||
this.nodes.imagePreloader.style.backgroundImage = `url(${src})`; | ||
this.toggleStatus(Ui.status.UPLOADING); | ||
} | ||
/** | ||
* Shows an image | ||
* @param {string} url | ||
*/ | ||
fillImage(url){ | ||
fillImage(url) { | ||
this.nodes.imageEl = make('img', this.CSS.imageEl, { | ||
@@ -194,3 +158,3 @@ src: url | ||
} | ||
}) | ||
}); | ||
} | ||
@@ -202,4 +166,4 @@ | ||
*/ | ||
fillCaption(text){ | ||
if (this.nodes.caption){ | ||
fillCaption(text) { | ||
if (this.nodes.caption) { | ||
this.nodes.caption.innerHTML = text; | ||
@@ -213,5 +177,5 @@ } | ||
*/ | ||
toggleStatus(status){ | ||
for (const statusType in Ui.status){ | ||
if (Ui.status.hasOwnProperty(statusType)){ | ||
toggleStatus(status) { | ||
for (const statusType in Ui.status) { | ||
if (Ui.status.hasOwnProperty(statusType)) { | ||
this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${Ui.status[statusType]}`, status === Ui.status[statusType]); | ||
@@ -227,3 +191,3 @@ } | ||
*/ | ||
applyTune(tuneName, status){ | ||
applyTune(tuneName, status) { | ||
this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${tuneName}`, status); | ||
@@ -241,8 +205,8 @@ } | ||
*/ | ||
export const make = function make (tagName, classNames = null, attributes = {}) { | ||
export const make = function make(tagName, classNames = null, attributes = {}) { | ||
let el = document.createElement(tagName); | ||
if ( Array.isArray(classNames) ) { | ||
if (Array.isArray(classNames)) { | ||
el.classList.add(...classNames); | ||
} else if( classNames ) { | ||
} else if (classNames) { | ||
el.classList.add(classNames); | ||
@@ -249,0 +213,0 @@ } |
@@ -0,1 +1,3 @@ | ||
const path = require('path'); | ||
module.exports = { | ||
@@ -7,3 +9,3 @@ module: { | ||
exclude: /node_modules/, | ||
use: ['babel-loader'] | ||
use: ['babel-loader', 'eslint-loader'] | ||
}, | ||
@@ -13,10 +15,10 @@ { | ||
use: [ | ||
"style-loader", | ||
"css-loader", | ||
'style-loader', | ||
'css-loader', | ||
{ | ||
loader: "postcss-loader", | ||
loader: 'postcss-loader', | ||
options: { | ||
plugins: [ | ||
require('postcss-nested-ancestors'), | ||
require('postcss-nested'), | ||
require('postcss-nested') | ||
] | ||
@@ -34,6 +36,6 @@ } | ||
output: { | ||
path: __dirname + '/dist', | ||
path: path.join(__dirname, '/dist'), | ||
publicPath: '/', | ||
filename: 'bundle.js', | ||
library: "ImageTool", | ||
library: 'ImageTool', | ||
libraryTarget: 'umd', | ||
@@ -40,0 +42,0 @@ libraryExport: 'default' |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
862134
25
1061
182
17
2
2