UNPKG

@freedom-editor/preact-code-block

Version:
2 lines (1 loc) 9.2 kB
"use strict";var e,t,n,_,l,o=e=>e?e.data.code:"",r={},u=[],i=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function s(e,t){for(var n in t)e[n]=t[n];return e}function c(e){var t=e.parentNode;t&&t.removeChild(e)}function p(e,t,n){var _,l=arguments,o={};for(_ in t)"key"!==_&&"ref"!==_&&(o[_]=t[_]);if(arguments.length>3)for(n=[n],_=3;_<arguments.length;_++)n.push(l[_]);if(null!=n&&(o.children=n),"function"==typeof e&&null!=e.defaultProps)for(_ in e.defaultProps)void 0===o[_]&&(o[_]=e.defaultProps[_]);return a(e,o,t&&t.key,t&&t.ref,null)}function a(t,n,_,l,o){var r={type:t,props:n,key:_,ref:l,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,constructor:void 0,__v:o};return null==o&&(r.__v=r),e.vnode&&e.vnode(r),r}function f(e){return e.children}function d(e,t){this.props=e,this.context=t}function h(e,t){if(null==t)return e.__?h(e.__,e.__.__k.indexOf(e)+1):null;for(var n;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e)return n.__e;return"function"==typeof e.type?h(e):null}function v(e){var t,n;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if(null!=(n=e.__k[t])&&null!=n.__e){e.__e=e.__c.base=n.__e;break}return v(e)}}function y(l){(!l.__d&&(l.__d=!0)&&t.push(l)&&!m.__r++||_!==e.debounceRendering)&&((_=e.debounceRendering)||n)(m)}function m(){for(var e;m.__r=t.length;)e=t.sort((function(e,t){return e.__v.__b-t.__v.__b})),t=[],e.some((function(e){var t,n,_,l,o,r,u;e.__d&&(r=(o=(t=e).__v).__e,(u=t.__P)&&(n=[],(_=s({},o)).__v=_,l=C(u,o,_,t.__n,void 0!==u.ownerSVGElement,null,n,null==r?h(o):r),P(n,o),l!=r&&v(o)))}))}function k(e,t,n,_,l,o,i,s,p,d){var v,y,m,k,b,w,S,x=_&&_.__k||u,P=x.length;for(p==r&&(p=null!=i?i[0]:P?h(_,0):null),n.__k=[],v=0;v<t.length;v++)if(null!=(k=n.__k[v]=null==(k=t[v])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k?a(null,k,null,null,k):Array.isArray(k)?a(f,{children:k},null,null,null):null!=k.__e||null!=k.__c?a(k.type,k.props,k.key,null,k.__v):k)){if(k.__=n,k.__b=n.__b+1,null===(m=x[v])||m&&k.key==m.key&&k.type===m.type)x[v]=void 0;else for(y=0;y<P;y++){if((m=x[y])&&k.key==m.key&&k.type===m.type){x[y]=void 0;break}m=null}b=C(e,k,m=m||r,l,o,i,s,p,d),(y=k.ref)&&m.ref!=y&&(S||(S=[]),m.ref&&S.push(m.ref,null,k),S.push(y,k.__c||b,k)),null!=b?(null==w&&(w=b),p=g(e,k,m,x,i,b,p),"option"==n.type?e.value="":"function"==typeof n.type&&(n.__d=p)):p&&m.__e==p&&p.parentNode!=e&&(p=h(m))}if(n.__e=w,null!=i&&"function"!=typeof n.type)for(v=i.length;v--;)null!=i[v]&&c(i[v]);for(v=P;v--;)null!=x[v]&&E(x[v],x[v]);if(S)for(v=0;v<S.length;v++)D(S[v],S[++v],S[++v])}function g(e,t,n,_,l,o,r){var u,i,s;if(void 0!==t.__d)u=t.__d,t.__d=void 0;else if(l==n||o!=r||null==o.parentNode)e:if(null==r||r.parentNode!==e)e.appendChild(o),u=null;else{for(i=r,s=0;(i=i.nextSibling)&&s<_.length;s+=2)if(i==o)break e;e.insertBefore(o,r),u=r}return void 0!==u?u:o.nextSibling}function b(e,t,n){"-"===t[0]?e.setProperty(t,n):e[t]="number"==typeof n&&!1===i.test(t)?n+"px":null==n?"":n}function w(e,t,n,_,l){var o,r,u,i,s;if(l?"className"===t&&(t="class"):"class"===t&&(t="className"),"style"===t)if(o=e.style,"string"==typeof n)o.cssText=n;else{if("string"==typeof _&&(o.cssText="",_=null),_)for(i in _)n&&i in n||b(o,i,"");if(n)for(s in n)_&&n[s]===_[s]||b(o,s,n[s])}else"o"===t[0]&&"n"===t[1]?(r=t!==(t=t.replace(/Capture$/,"")),u=t.toLowerCase(),t=(u in e?u:t).slice(2),n?(_||e.addEventListener(t,S,r),(e.l||(e.l={}))[t]=n):e.removeEventListener(t,S,r)):"list"!==t&&"tagName"!==t&&"form"!==t&&"type"!==t&&"size"!==t&&!l&&t in e?e[t]=null==n?"":n:"function"!=typeof n&&"dangerouslySetInnerHTML"!==t&&(t!==(t=t.replace(/^xlink:?/,""))?null==n||!1===n?e.removeAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase()):e.setAttributeNS("http://www.w3.org/1999/xlink",t.toLowerCase(),n):null==n||!1===n&&!/^ar/.test(t)?e.removeAttribute(t):e.setAttribute(t,n))}function S(t){this.l[t.type](e.event?e.event(t):t)}function x(e,t,n){var _,l;for(_=0;_<e.__k.length;_++)(l=e.__k[_])&&(l.__=e,l.__e&&("function"==typeof l.type&&l.__k.length>1&&x(l,t,n),t=g(n,l,l,e.__k,null,l.__e,t),"function"==typeof e.type&&(e.__d=t)))}function C(t,n,_,l,o,r,u,i,c){var p,a,h,v,y,m,g,b,w,S,C,P=n.type;if(void 0!==n.constructor)return null;(p=e.__b)&&p(n);try{e:if("function"==typeof P){if(b=n.props,w=(p=P.contextType)&&l[p.__c],S=p?w?w.props.value:p.__:l,_.__c?g=(a=n.__c=_.__c).__=a.__E:("prototype"in P&&P.prototype.render?n.__c=a=new P(b,S):(n.__c=a=new d(b,S),a.constructor=P,a.render=U),w&&w.sub(a),a.props=b,a.state||(a.state={}),a.context=S,a.__n=l,h=a.__d=!0,a.__h=[]),null==a.__s&&(a.__s=a.state),null!=P.getDerivedStateFromProps&&(a.__s==a.state&&(a.__s=s({},a.__s)),s(a.__s,P.getDerivedStateFromProps(b,a.__s))),v=a.props,y=a.state,h)null==P.getDerivedStateFromProps&&null!=a.componentWillMount&&a.componentWillMount(),null!=a.componentDidMount&&a.__h.push(a.componentDidMount);else{if(null==P.getDerivedStateFromProps&&b!==v&&null!=a.componentWillReceiveProps&&a.componentWillReceiveProps(b,S),!a.__e&&null!=a.shouldComponentUpdate&&!1===a.shouldComponentUpdate(b,a.__s,S)||n.__v===_.__v){a.props=b,a.state=a.__s,n.__v!==_.__v&&(a.__d=!1),a.__v=n,n.__e=_.__e,n.__k=_.__k,a.__h.length&&u.push(a),x(n,i,t);break e}null!=a.componentWillUpdate&&a.componentWillUpdate(b,a.__s,S),null!=a.componentDidUpdate&&a.__h.push((function(){a.componentDidUpdate(v,y,m)}))}a.context=S,a.props=b,a.state=a.__s,(p=e.__r)&&p(n),a.__d=!1,a.__v=n,a.__P=t,p=a.render(a.props,a.state,a.context),a.state=a.__s,null!=a.getChildContext&&(l=s(s({},l),a.getChildContext())),h||null==a.getSnapshotBeforeUpdate||(m=a.getSnapshotBeforeUpdate(v,y)),C=null!=p&&p.type==f&&null==p.key?p.props.children:p,k(t,Array.isArray(C)?C:[C],n,_,l,o,r,u,i,c),a.base=n.__e,a.__h.length&&u.push(a),g&&(a.__E=a.__=null),a.__e=!1}else null==r&&n.__v===_.__v?(n.__k=_.__k,n.__e=_.__e):n.__e=N(_.__e,n,_,l,o,r,u,c);(p=e.diffed)&&p(n)}catch(t){n.__v=null,e.__e(t,n,_)}return n.__e}function P(t,n){e.__c&&e.__c(n,t),t.some((function(n){try{t=n.__h,n.__h=[],t.some((function(e){e.call(n)}))}catch(t){e.__e(t,n.__v)}}))}function N(e,t,n,_,l,o,i,s){var c,p,a,f,d,h=n.props,v=t.props;if(l="svg"===t.type||l,null!=o)for(c=0;c<o.length;c++)if(null!=(p=o[c])&&((null===t.type?3===p.nodeType:p.localName===t.type)||e==p)){e=p,o[c]=null;break}if(null==e){if(null===t.type)return document.createTextNode(v);e=l?document.createElementNS("http://www.w3.org/2000/svg",t.type):document.createElement(t.type,v.is&&{is:v.is}),o=null,s=!1}if(null===t.type)h!==v&&e.data!=v&&(e.data=v);else{if(null!=o&&(o=u.slice.call(e.childNodes)),a=(h=n.props||r).dangerouslySetInnerHTML,f=v.dangerouslySetInnerHTML,!s){if(null!=o)for(h={},d=0;d<e.attributes.length;d++)h[e.attributes[d].name]=e.attributes[d].value;(f||a)&&(f&&a&&f.__html==a.__html||(e.innerHTML=f&&f.__html||""))}(function(e,t,n,_,l){var o;for(o in n)"children"===o||"key"===o||o in t||w(e,o,null,n[o],_);for(o in t)l&&"function"!=typeof t[o]||"children"===o||"key"===o||"value"===o||"checked"===o||n[o]===t[o]||w(e,o,t[o],n[o],_)})(e,v,h,l,s),f?t.__k=[]:(c=t.props.children,k(e,Array.isArray(c)?c:[c],t,n,_,"foreignObject"!==t.type&&l,o,i,r,s)),s||("value"in v&&void 0!==(c=v.value)&&c!==e.value&&w(e,"value",c,h.value,!1),"checked"in v&&void 0!==(c=v.checked)&&c!==e.checked&&w(e,"checked",c,h.checked,!1))}return e}function D(t,n,_){try{"function"==typeof t?t(n):t.current=n}catch(t){e.__e(t,_)}}function E(t,n,_){var l,o,r;if(e.unmount&&e.unmount(t),(l=t.ref)&&(l.current&&l.current!==t.__e||D(l,null,n)),_||"function"==typeof t.type||(_=null!=(o=t.__e)),t.__e=t.__d=void 0,null!=(l=t.__c)){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(t){e.__e(t,n)}l.base=l.__P=null}if(l=t.__k)for(r=0;r<l.length;r++)l[r]&&E(l[r],n,_);null!=o&&c(o)}function U(e,t,n){return this.constructor(e,n)}e={__e:function(e,t){for(var n,_;t=t.__;)if((n=t.__c)&&!n.__)try{if(n.constructor&&null!=n.constructor.getDerivedStateFromError&&(_=!0,n.setState(n.constructor.getDerivedStateFromError(e))),null!=n.componentDidCatch&&(_=!0,n.componentDidCatch(e)),_)return y(n.__E=n)}catch(t){e=t}throw e}},d.prototype.setState=function(e,t){var n;n=this.__s!==this.state?this.__s:this.__s=s({},this.state),"function"==typeof e&&(e=e(n,this.props)),e&&s(n,e),null!=e&&this.__v&&(t&&this.__h.push(t),y(this))},d.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),y(this))},d.prototype.render=f,t=[],n="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,m.__r=0,l=r;module.exports={Code:class{constructor(e){this.options={i18n:{locale:"en-US",rtl:"ltr",translations:{}},controllers:[],...e}}render(t,n){const _=document.createElement("div");return _.classList.add("freedom-editor-blocks",this.constructor.name+"-block"),_.dataset.blockType=this.constructor.name,function(t,n,_){var o,i,s;e.__&&e.__(t,n),i=(o=_===l)?null:_&&_.__k||n.__k,t=p(f,null,[t]),s=[],C(n,(o?n:_||n).__k=t,i||r,r,void 0!==n.ownerSVGElement,_&&!o?[_]:i?null:n.childNodes.length?u.slice.call(n.childNodes):null,s,_||r,o),P(s,t)}(p("pre",null,p("code",{contenteditable:!0},o(n))),_),_}save(e){const t=e.querySelector("code");if(""!==t.textContent)return{type:this.constructor.name,data:{code:t.textContent}}}}};