@yangeditor/plugin-upload-attachment
Version:
2 lines • 16 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@wangeditor/editor")):"function"==typeof define&&define.amd?define(["@wangeditor/editor"],t):"object"==typeof exports?exports.WangEditorPluginUploadAttachment=t(require("@wangeditor/editor")):e.WangEditorPluginUploadAttachment=t(e.wangEditor)}(self,(function(e){return(()=>{"use strict";var t={857:t=>{t.exports=e}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{o.r(r),o.d(r,{default:()=>U});var e=o(857);(0,e.i18nAddResources)("en",{attachment:{upload:"Upload Attachment",download:"Download Attachment"}}),(0,e.i18nAddResources)("zh-CN",{attachment:{upload:"上传附件",download:"下载附件"}});function t(e,t,n,o,r){return{sel:e,data:t,children:n,text:o,elm:r,key:void 0===t?void 0:t.key}}const n=Array.isArray;function i(e){return"string"==typeof e||"number"==typeof e||e instanceof String||e instanceof Number}function a(e,t,n){if(e.ns="http://www.w3.org/2000/svg","foreignObject"!==n&&void 0!==t)for(let e=0;e<t.length;++e){const n=t[e];if("string"==typeof n)continue;const o=n.data;void 0!==o&&a(o,n.children,n.sel)}}function s(e,o,r){let s,l,c,u={};if(void 0!==r?(null!==o&&(u=o),n(r)?s=r:i(r)?l=r.toString():r&&r.sel&&(s=[r])):null!=o&&(n(o)?s=o:i(o)?l=o.toString():o&&o.sel?s=[o]:u=o),void 0!==s)for(c=0;c<s.length;++c)i(s[c])&&(s[c]=t(void 0,void 0,void 0,s[c],void 0));return"s"!==e[0]||"v"!==e[1]||"g"!==e[2]||3!==e.length&&"."!==e[3]&&"#"!==e[3]||a(u,s,e),t(e,u,s,l,void 0)}const l={type:"attachment",renderElem:function(t,n,o){var r=o.isDisabled(),i=e.DomEditor.isNodeSelected(o,t),a=t,l=a.fileName,c=void 0===l?"":l,u=a.link,d=void 0===u?"":u;return s("span",{props:{contentEditable:!1},style:{display:"inline-block",marginLeft:"3px",marginRight:"3px",border:i&&!r?"2px solid var(--w-e-textarea-selected-border-color)":"2px solid transparent",borderRadius:"3px",padding:"0 3px",backgroundColor:"#f1f1f1",cursor:r?"pointer":"inherit"},on:{click:function(){r&&d&&window.open(d,"_blank")}}},[s("img",{props:{src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAv5JREFUWEetl1nITVEUx3/fo5LkyRQeFA+SIS8eZHhQimRKMhMSoogyR5QxMs9DkplQEhFvxihCKUWkpCTP9P9a+1p3f2efe869367T3Xeftdf/v9e012mi9cZQYDzQBxgIfANeAO+BDSmYplbCX58HAnwFFgNXY7zWIHABmBQpfg10A9pH64OAZ36tUQLngClO4XVgC/DU1iYCF937N+aiylIjBM4A05xy+XljwqV/3bpkKjFRL4GTwMyU0gwSY4Abtn4NGBdk6iFwFJhbAjyI/gLaAR+BnvUSOATML2j22BCvgL7AbyPS/L6MBfYDC3NOrlS8BLzNcIGi/4mtPwSGlbXAHmBJDriCSgQU5UrJmIT8Ptb277OaUNgCu4BlBcCDSFWUGzFfCXV6WaEQge3A8hLgcSquBjbnBWxeDGwFVtXwuT9ZfHLtlY4wFB9xxUwGoViLfVGzxuCymqyXC57KAilb1wC44kVxUxM8i8Bs4HgJn8cnV6YoYwqBxwR6A/eBzrY7Vh5SLeUW1QjVisLgMQEFyQTbfQqY5ZTVAp8HHC4L7gnocrhiCj5ZpdKvxlJgd45b5gDHcsDzKmQlC3zUrwS2mcJ+wAPXWMRumQHIWimzh04pVSErBG4Do0zLaOCWzX2rpeZjqgPT/GwB8FTMNK+HQqSerZNJKgjVUGro9Go2NXwJnQycLwGebFYCgS9AF1PYEfhu8wXAQZurfh8AutcoMnGDGrvN8f5vAQVg6FJGAndNqq211SE1qzbb9evLaylw74I1wCbTvgLY4ZAGAzeBDhH6kYzmRARyfR6fILhAd7XubI0fQC/gpxNuY23YcOCDdbrP3fvSJw97/W14B5D5NR4DQ2K2if91g3sXaN4V+OxAlN+LgD8J4B7WbJTpjluoivuB6cBpJ6VquBd4BAST67tP1tHFIxKlfJ6KAb8+AriXcWqlarCUf60ashY4UdBlVWKpjkgRvzP6+MjSf9nA39UDHsdAlg7VhgFAf3sk89IefXq3+NotS+QfmNG0IS7jBhcAAAAASUVORK5CYII="},style:{width:"1em",marginRight:"0.1em",minWidth:"0",minHeight:"0"}}),c])}};function c(e){return null!==e&&"object"==typeof e&&"constructor"in e&&e.constructor===Object}function u(e={},t={}){Object.keys(t).forEach((n=>{void 0===e[n]?e[n]=t[n]:c(t[n])&&c(e[n])&&Object.keys(t[n]).length>0&&u(e[n],t[n])}))}const d={body:{},addEventListener(){},removeEventListener(){},activeElement:{blur(){},nodeName:""},querySelector:()=>null,querySelectorAll:()=>[],getElementById:()=>null,createEvent:()=>({initEvent(){}}),createElement:()=>({children:[],childNodes:[],style:{},setAttribute(){},getElementsByTagName:()=>[]}),createElementNS:()=>({}),importNode:()=>null,location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""}};function f(){const e="undefined"!=typeof document?document:{};return u(e,d),e}const p={document:d,navigator:{userAgent:""},location:{hash:"",host:"",hostname:"",href:"",origin:"",pathname:"",protocol:"",search:""},history:{replaceState(){},pushState(){},go(){},back(){}},CustomEvent:function(){return this},addEventListener(){},removeEventListener(){},getComputedStyle:()=>({getPropertyValue:()=>""}),Image(){},Date(){},screen:{},setTimeout(){},clearTimeout(){},matchMedia:()=>({}),requestAnimationFrame:e=>"undefined"==typeof setTimeout?(e(),null):setTimeout(e,0),cancelAnimationFrame(e){"undefined"!=typeof setTimeout&&clearTimeout(e)}};function h(){const e="undefined"!=typeof window?window:{};return u(e,p),e}class m extends Array{constructor(e){"number"==typeof e?super(e):(super(...e||[]),function(e){const t=e.__proto__;Object.defineProperty(e,"__proto__",{get:()=>t,set(e){t.__proto__=e}})}(this))}}function g(e,t){const n=h(),o=f();let r=[];if(!t&&e instanceof m)return e;if(!e)return new m(r);if("string"==typeof e){const n=e.trim();if(n.indexOf("<")>=0&&n.indexOf(">")>=0){let e="div";0===n.indexOf("<li")&&(e="ul"),0===n.indexOf("<tr")&&(e="tbody"),0!==n.indexOf("<td")&&0!==n.indexOf("<th")||(e="tr"),0===n.indexOf("<tbody")&&(e="table"),0===n.indexOf("<option")&&(e="select");const t=o.createElement(e);t.innerHTML=n;for(let e=0;e<t.childNodes.length;e+=1)r.push(t.childNodes[e])}else r=function(e,t){if("string"!=typeof e)return[e];const n=[],o=t.querySelectorAll(e);for(let e=0;e<o.length;e+=1)n.push(o[e]);return n}(e.trim(),t||o)}else if(e.nodeType||e===n||e===o)r.push(e);else if(Array.isArray(e)){if(e instanceof m)return e;r=e}return new m(function(e){const t=[];for(let n=0;n<e.length;n+=1)-1===t.indexOf(e[n])&&t.push(e[n]);return t}(r))}function y(...e){let[t,n,o,r]=e;function i(e){const t=e.target;if(!t)return;const r=e.target.dom7EventData||[];if(r.indexOf(e)<0&&r.unshift(e),g(t).is(n))o.apply(t,r);else{const e=g(t).parents();for(let t=0;t<e.length;t+=1)g(e[t]).is(n)&&o.apply(e[t],r)}}function a(e){const t=e&&e.target&&e.target.dom7EventData||[];t.indexOf(e)<0&&t.unshift(e),o.apply(this,t)}"function"==typeof e[1]&&([t,o,r]=e,n=void 0),r||(r=!1);const s=t.split(" ");let l;for(let e=0;e<this.length;e+=1){const t=this[e];if(n)for(l=0;l<s.length;l+=1){const e=s[l];t.dom7LiveListeners||(t.dom7LiveListeners={}),t.dom7LiveListeners[e]||(t.dom7LiveListeners[e]=[]),t.dom7LiveListeners[e].push({listener:o,proxyListener:i}),t.addEventListener(e,i,r)}else for(l=0;l<s.length;l+=1){const e=s[l];t.dom7Listeners||(t.dom7Listeners={}),t.dom7Listeners[e]||(t.dom7Listeners[e]=[]),t.dom7Listeners[e].push({listener:o,proxyListener:a}),t.addEventListener(e,a,r)}}return this}function v(){for(let e=0;e<this.length;e+=1)this[e].style.display="none";return this}function b(...e){let t;const n=f();for(let o=0;o<e.length;o+=1){t=e[o];for(let e=0;e<this.length;e+=1)if("string"==typeof t){const o=n.createElement("div");for(o.innerHTML=t;o.firstChild;)this[e].appendChild(o.firstChild)}else if(t instanceof m)for(let n=0;n<t.length;n+=1)this[e].appendChild(t[n]);else this[e].appendChild(t)}return this}g.fn=m.prototype;const A="resize scroll".split(" ");function w(e){return function(...t){if(void 0===t[0]){for(let t=0;t<this.length;t+=1)A.indexOf(e)<0&&(e in this[t]?this[t][e]():g(this[t]).trigger(e));return this}return this.on(e,...t)}}const x=w("click"),S=(w("blur"),w("focus"),w("focusin"),w("focusout"),w("keyup"),w("keydown"),w("keypress"),w("submit"),w("change"),w("mousedown"),w("mousemove"),w("mouseup"),w("mouseenter"),w("mouseleave"),w("mouseout"),w("mouseover"),w("touchstart"),w("touchend"),w("touchmove"),w("resize"),w("scroll"),g);v&&(S.fn.hide=v),b&&(S.fn.append=b),x&&(S.fn.click=x),y&&(S.fn.on=y);const E=S;globalThis.Node,globalThis.Comment,globalThis.Element,globalThis.Text,globalThis.Range,globalThis.Selection,globalThis.StaticRange;var L=function(){return L=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},L.apply(this,arguments)},N=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function s(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((o=o.apply(e,t||[])).next())}))},T=function(e,t){var n,o,r,i,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,o=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((r=(r=a.trys).length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){a.label=i[1];break}if(6===i[0]&&a.label<r[1]){a.label=r[1],r=i;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(i);break}r[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};function C(e){return e.getMenuConfig("uploadAttachment")}function B(e,t,n){if(t&&n){e.restoreSelection();var o={type:"attachment",fileName:t,link:n,children:[{text:""}]};e.insertNode(o),e.move(1);var r=C(e).onInsertedAttachment;r&&r(o)}}function k(t,n){return N(this,void 0,void 0,(function(){var o,r,i,a;return T(this,(function(s){switch(s.label){case 0:return o=function(t){var n=O.get(t);if(null!=n)return n;var o=C(t),r=o.onSuccess,i=o.onProgress,a=o.onFailed,s=o.customInsert,l=o.onError;return n=(0,e.createUploader)(L(L({},o),{onProgress:function(e){t.showProgressBar(e),i&&i(e)},onSuccess:function(e,n){if(s)s(n,e,(function(e,n){return B(t,e,n)}));else{var o=n.errno,i=void 0===o?1:o,l=n.data,c=void 0===l?{}:l;if(0!==i)return console.error("'".concat(e.name,"' upload failed"),n),void a(e,n);var u=c.url,d=void 0===u?"":u;B(t,e.name,d),r(e,n)}},onError:function(e,t,n){var o=e.name;console.error("'".concat(o," upload error"),t,n),l&&l(e,t,n)}})),O.set(t,n),n}(t),r=n.name,i=n.type,a=n.size,o.addFile({name:r,type:i,size:a,data:n}),[4,o.upload()];case 1:return s.sent(),[2]}}))}))}var O=new WeakMap;const D=function(){function t(){this.title=(0,e.t)("attachment.upload"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M665.821116 327.053068l-64.958782-64.926783-324.79391 324.729911c-53.822991 53.790991-53.822991 141.053355 0 194.844347s141.053355 53.790991 194.876346 0l389.752692-389.688693a229.531696 229.531696 0 0 0 0-324.729912 229.627694 229.627694 0 0 0-324.761911 0L126.727224 476.458266l-0.863984 0.831985c-125.085655 125.085655-125.085655 327.833853 0 452.887508 125.053655 125.053655 327.865853 125.053655 452.983507 0l0.831984-0.863984 0.031999 0.032 279.322763-279.290764-64.990781-64.926782-279.322763 279.258764-0.831984 0.831984a228.731711 228.731711 0 0 1-323.065943 0 228.603714 228.603714 0 0 1 0-322.969944l0.895983-0.831985-0.031999-0.063998L600.958332 132.208721c53.694993-53.726993 141.149353-53.726993 194.876346 0s53.694993 141.149353 0 194.844347L406.081986 716.741761c-17.919664 17.919664-47.039118 17.919664-64.958782 0a45.983138 45.983138 0 0 1 0-64.926783L665.917114 327.053068z"></path></svg>',this.tag="button"}return t.prototype.getValue=function(e){return""},t.prototype.isActive=function(e){return!1},t.prototype.exec=function(e,t){var n=this.getMenuConfig(e),o=n.allowedFileTypes,r=void 0===o?[]:o,i=n.customBrowseAndUpload;if(i)i((function(t,n){return B(e,t,n)}));else{var a="";r.length>0&&(a='accept="'.concat(r.join(", "),'"'));var s=E("body"),l=E('<input type="file" '.concat(a," multiple/>"));l.hide(),s.append(l),l.click(),l.on("change",(function(){var t=l[0].files;!function(e,t){var n,o;N(this,void 0,void 0,(function(){var r,i,a,s,l,c;return T(this,(function(u){switch(u.label){case 0:if(null==t)return[2];r=Array.prototype.slice.call(t),i=C(e).customUpload,u.label=1;case 1:u.trys.push([1,9,10,15]),a=function(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,n=e[Symbol.asyncIterator];return n?n.call(e):(e="function"==typeof __values?__values(e):e[Symbol.iterator](),t={},o("next"),o("throw"),o("return"),t[Symbol.asyncIterator]=function(){return this},t);function o(n){t[n]=e[n]&&function(t){return new Promise((function(o,r){!function(e,t,n,o){Promise.resolve(o).then((function(t){e({value:t,done:n})}),t)}(o,r,(t=e[n](t)).done,t.value)}))}}}(r),u.label=2;case 2:return[4,a.next()];case 3:return(s=u.sent()).done?[3,8]:(l=s.value,i?[4,i(l,(function(t,n){return B(e,t,n)}))]:[3,5]);case 4:return u.sent(),[3,7];case 5:return[4,k(e,l)];case 6:u.sent(),u.label=7;case 7:return[3,2];case 8:return[3,15];case 9:return c=u.sent(),n={error:c},[3,15];case 10:return u.trys.push([10,,13,14]),s&&!s.done&&(o=a.return)?[4,o.call(a)]:[3,12];case 11:u.sent(),u.label=12;case 12:return[3,14];case 13:if(n)throw n.error;return[7];case 14:return[7];case 15:return[2]}}))}))}(e,t)}))}},t.prototype.isDisabled=function(t){var n=t.selection;if(null==n)return!0;if(e.SlateRange.isExpanded(n))return!0;var o=e.DomEditor.getSelectedElems(t);return!!o.some((function(e){return t.isVoid(e)}))||!!o.some((function(t){return"pre"===e.DomEditor.getNodeType(t)}))},t.prototype.getMenuConfig=function(e){return e.getMenuConfig("uploadAttachment")},t}();const j=function(){function t(){this.title=(0,e.t)("attachment.download"),this.iconSvg='<svg viewBox="0 0 1024 1024"><path d="M736 448l-256 256-256-256h160V64h192v384z m-256 256H0v256h960v-256H480z m416 128h-128v-64h128v64z"></path></svg>',this.tag="button",this.alwaysEnable=!0}return t.prototype.getValue=function(e){var t=this.getSelectedElem(e);return null==t?"":t.link},t.prototype.isActive=function(e){return!1},t.prototype.exec=function(e,t){t&&"string"==typeof t&&window.open(t,"_blank")},t.prototype.isDisabled=function(t){var n=t.selection;return null==n||!!e.SlateRange.isExpanded(n)||null==this.getSelectedElem(t)},t.prototype.getSelectedElem=function(t){var n=e.DomEditor.getSelectedNodeByType(t,"attachment");return null==n?null:n},t}(),U={editorPlugin:function(t){var n=t.isInline,o=t.isVoid,r=t;return r.isInline=function(t){return"attachment"===e.DomEditor.getNodeType(t)||n(t)},r.isVoid=function(t){return"attachment"===e.DomEditor.getNodeType(t)||o(t)},r},renderElems:[l],elemsToHtml:[{type:"attachment",elemToHtml:function(e,t){var n=e,o=n.link,r=void 0===o?"":o,i=n.fileName,a=void 0===i?"":i;return'<span data-w-e-type="attachment" data-w-e-is-void data-w-e-is-inline data-link="'.concat(r,'" data-fileName="').concat(a,'">').concat(a,"</span>")}}],parseElemsHtml:[{selector:'span[data-w-e-type="attachment"]',parseElemHtml:function(e,t,n){return{type:"attachment",link:e.getAttribute("data-link")||"",fileName:e.getAttribute("data-fileName")||"",children:[{text:""}]}}}],menus:[{key:"uploadAttachment",factory:function(){return new D},config:{server:"",fieldName:"wangeditor-uploaded-attachment",maxFileSize:10485760,maxNumberOfFiles:5,allowedFileTypes:["*"],meta:{},metaWithUrl:!1,withCredentials:!1,timeout:3e4,onBeforeUpload:function(e){return e},onProgress:function(e){},onSuccess:function(e,t){},onFailed:function(e,t){},onError:function(e,t,n){},onInsertedAttachment:function(e){}}},{key:"downloadAttachment",factory:function(){return new j}}]}})(),r})()}));
//# sourceMappingURL=index.js.map