editorjs-layout
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.EditorJSLayout=e():t.EditorJSLayout=e()}(self,(function(){return(()=>{"use strict";var t={211:(t,e,n)=>{n.r(e),n.d(e,{LayoutBlockTool:()=>C});class o extends Error{constructor(...t){super(...t),Error.captureStackTrace&&Error.captureStackTrace(this,o),this.name="EditorJSLayoutError"}}var i,r=new Uint8Array(16);function a(){if(!i&&!(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(r)}const s=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,d=function(t){return"string"==typeof t&&s.test(t)};for(var c=[],l=0;l<256;++l)c.push((l+256).toString(16).substr(1));const u=function(t,e,n){var o=(t=t||{}).random||(t.rng||a)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,e){n=n||0;for(var i=0;i<16;++i)e[n+i]=o[i];return e}return function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(c[t[e+0]]+c[t[e+1]]+c[t[e+2]]+c[t[e+3]]+"-"+c[t[e+4]]+c[t[e+5]]+"-"+c[t[e+6]]+c[t[e+7]]+"-"+c[t[e+8]]+c[t[e+9]]+"-"+c[t[e+10]]+c[t[e+11]]+c[t[e+12]]+c[t[e+13]]+c[t[e+14]]+c[t[e+15]]).toLowerCase();if(!d(n))throw TypeError("Stringified UUID is invalid");return n}(o)};const p=({EditorJS:t,data:e,dispatchData:n,editorJSConfig:o,itemContentId:i})=>{const r=u(),a=document.createElement("div");return a.id=r,a.style.cursor="pointer",a.addEventListener("click",(()=>{const r=(({EditorJS:t,data:e,editorJSConfig:n,onClose:o})=>{const i=document.createElement("dialog");i.style.maxWidth="960px",i.style.padding="0",i.style.top="32px",i.style.width="calc(100% - 64px)";const r=document.createElement("div"),a=u();r.id=a,i.append(r);const s=new t(Object.assign(Object.assign({},n),{holder:a,data:e})),d=t=>{t.target instanceof Node&&t.target.isEqualNode(i)&&i.close()};i.addEventListener("click",d);const c=()=>{return t=void 0,e=void 0,r=function*(){const t=yield s.save();s.destroy(),i.removeEventListener("click",d),i.removeEventListener("close",c),i.remove(),null==o||o({editorJSData:t})},new((n=void 0)||(n=Promise))((function(o,i){function a(t){try{d(r.next(t))}catch(t){i(t)}}function s(t){try{d(r.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}d((r=r.apply(t,e||[])).next())}));var t,e,n,r};return i.addEventListener("close",c),i})({EditorJS:t,data:e,editorJSConfig:o,onClose:({editorJSData:t})=>{return e=void 0,o=void 0,a=function*(){return n((({itemContent:e,layout:n})=>({itemContent:Object.assign(Object.assign({},e),{[i]:{blocks:t.blocks}}),layout:n})))},new((r=void 0)||(r=Promise))((function(t,n){function i(t){try{d(a.next(t))}catch(t){n(t)}}function s(t){try{d(a.throw(t))}catch(t){n(t)}}function d(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(i,s)}d((a=a.apply(e,o||[])).next())}));var e,o,r,a}});document.body.append(r),r.showModal()})),new t(Object.assign(Object.assign({},o),{holder:r,data:e,minHeight:0,readOnly:!0})),a},h=({EditorJS:t,data:e,dispatchData:n,editorJSConfig:i,itemContentData:r})=>{const a=document.createElement("div");return a.id=e.id,a.className=e.className,a.style.cssText=e.style,e.children.forEach((e=>{let s;switch(e.type){case"container":s=h({EditorJS:t,data:e,dispatchData:n,editorJSConfig:i,itemContentData:r});break;case"item":s=(({EditorJS:t,data:e,dispatchData:n,editorJSConfig:o,itemContentData:i})=>{var r;const a=document.createElement("div");a.id=e.id,a.className=e.className,a.style.cssText=e.style;const s=null!==(r=i[e.itemContentId])&&void 0!==r?r:{blocks:[]};return a.append(p({EditorJS:t,data:s,dispatchData:n,editorJSConfig:o,itemContentId:e.itemContentId})),a})({EditorJS:t,data:e,dispatchData:n,editorJSConfig:i,itemContentData:r});break;default:throw new o}a.append(s)})),a};var f,y,m,v,g,w=function(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n},S=function(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)};class C{constructor({config:t,data:e}){f.set(this,void 0),y.set(this,void 0),m.set(this,void 0),v.set(this,void 0),g.set(this,(t=>{const e=t({itemContent:S(this,m),layout:S(this,v)});w(this,m,e.itemContent),w(this,v,e.layout),this.renderWrapper()})),w(this,y,document.createElement("div")),w(this,m,{}),w(this,v,{type:"container",id:"",className:"",style:"",children:[]}),t&&"EditorJS"in t&&(w(this,f,t),w(this,m,t.initialData.itemContent),t.initialData.layout&&w(this,v,t.initialData.layout)),e&&"itemContent"in e&&(w(this,m,e.itemContent),e.layout&&w(this,v,e.layout))}static get shortcut(){return"CMD+L"}static get toolbox(){return{icon:'\n <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512">\n <rect x="48" y="48" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n <rect x="288" y="48" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n <rect x="48" y="288" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n <rect x="288" y="288" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n </svg>\n ',title:"Layout"}}render(){return this.renderWrapper(),S(this,y)}save(){return{itemContent:S(this,m),layout:S(this,f).enableLayoutSaving?S(this,v):void 0}}validate(t){return!0}renderWrapper(){S(this,y).innerHTML="",S(this,y).append(h({EditorJS:S(this,f).EditorJS,data:S(this,v),dispatchData:S(this,g),editorJSConfig:S(this,f).editorJSConfig,itemContentData:S(this,m)}))}}f=new WeakMap,y=new WeakMap,m=new WeakMap,v=new WeakMap,g=new WeakMap}},e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}return n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(211)})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.EditorJSLayout=e():t.EditorJSLayout=e()}(self,(function(){return(()=>{"use strict";var t={579:(t,e,o)=>{o.r(e),o.d(e,{LayoutBlockTool:()=>R});class n extends Error{constructor(...t){super(...t),Error.captureStackTrace&&Error.captureStackTrace(this,n),this.name="EditorJSLayoutError"}}var i,a=new Uint8Array(16);function r(){if(!i&&!(i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return i(a)}const s=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,d=function(t){return"string"==typeof t&&s.test(t)};for(var l=[],c=0;c<256;++c)l.push((c+256).toString(16).substr(1));const u=function(t,e,o){var n=(t=t||{}).random||(t.rng||r)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){o=o||0;for(var i=0;i<16;++i)e[o+i]=n[i];return e}return function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=(l[t[e+0]]+l[t[e+1]]+l[t[e+2]]+l[t[e+3]]+"-"+l[t[e+4]]+l[t[e+5]]+"-"+l[t[e+6]]+l[t[e+7]]+"-"+l[t[e+8]]+l[t[e+9]]+"-"+l[t[e+10]]+l[t[e+11]]+l[t[e+12]]+l[t[e+13]]+l[t[e+14]]+l[t[e+15]]).toLowerCase();if(!d(o))throw TypeError("Stringified UUID is invalid");return o}(n)};var h=window.CustomEvent;function p(t,e){var o="on"+e.type.toLowerCase();return"function"==typeof t[o]&&t[o](e),t.dispatchEvent(e)}function m(t){for(;t;){if("dialog"===t.localName)return t;t=t.parentElement?t.parentElement:t.parentNode?t.parentNode.host:null}return null}function f(t){for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;t&&t.blur&&t!==document.body&&t.blur()}function g(t,e){for(var o=0;o<t.length;++o)if(t[o]===e)return!0;return!1}function y(t){return!(!t||!t.hasAttribute("method"))&&"dialog"===t.getAttribute("method").toLowerCase()}function v(t){var e=["button","input","keygen","select","textarea"].map((function(t){return t+":not([disabled])"}));e.push('[tabindex]:not([disabled]):not([tabindex=""])');var o=t.querySelector(e.join(", "));if(!o&&"attachShadow"in Element.prototype)for(var n=t.querySelectorAll("*"),i=0;i<n.length&&!(n[i].tagName&&n[i].shadowRoot&&(o=v(n[i].shadowRoot)));i++);return o}function b(t){return t.isConnected||document.body.contains(t)}function w(t){if(t.submitter)return t.submitter;var e=t.target;if(!(e instanceof HTMLFormElement))return null;var o=k.formSubmitter;if(!o){var n=t.target;o=("getRootNode"in n&&n.getRootNode()||document).activeElement}return o&&o.form===e?o:null}function E(t){if(!t.defaultPrevented){var e=t.target,o=k.imagemapUseValue,n=w(t);null===o&&n&&(o=n.value);var i=m(e);i&&"dialog"===(n&&n.getAttribute("formmethod")||e.getAttribute("method"))&&(t.preventDefault(),null!=o?i.close(o):i.close())}}function _(t){if(this.dialog_=t,this.replacedStyleTop_=!1,this.openAsModal_=!1,t.hasAttribute("role")||t.setAttribute("role","dialog"),t.show=this.show.bind(this),t.showModal=this.showModal.bind(this),t.close=this.close.bind(this),t.addEventListener("submit",E,!1),"returnValue"in t||(t.returnValue=""),"MutationObserver"in window)new MutationObserver(this.maybeHideModal.bind(this)).observe(t,{attributes:!0,attributeFilter:["open"]});else{var e,o=!1,n=function(){o?this.downgradeModal():this.maybeHideModal(),o=!1}.bind(this),i=function(i){if(i.target===t){var a="DOMNodeRemoved";o|=i.type.substr(0,a.length)===a,window.clearTimeout(e),e=window.setTimeout(n,0)}};["DOMAttrModified","DOMNodeRemoved","DOMNodeRemovedFromDocument"].forEach((function(e){t.addEventListener(e,i)}))}Object.defineProperty(t,"open",{set:this.setOpen.bind(this),get:t.hasAttribute.bind(t,"open")}),this.backdrop_=document.createElement("div"),this.backdrop_.className="backdrop",this.backdrop_.addEventListener("mouseup",this.backdropMouseEvent_.bind(this)),this.backdrop_.addEventListener("mousedown",this.backdropMouseEvent_.bind(this)),this.backdrop_.addEventListener("click",this.backdropMouseEvent_.bind(this))}h&&"object"!=typeof h||((h=function(t,e){e=e||{};var o=document.createEvent("CustomEvent");return o.initCustomEvent(t,!!e.bubbles,!!e.cancelable,e.detail||null),o}).prototype=window.Event.prototype),_.prototype={get dialog(){return this.dialog_},maybeHideModal:function(){this.dialog_.hasAttribute("open")&&b(this.dialog_)||this.downgradeModal()},downgradeModal:function(){this.openAsModal_&&(this.openAsModal_=!1,this.dialog_.style.zIndex="",this.replacedStyleTop_&&(this.dialog_.style.top="",this.replacedStyleTop_=!1),this.backdrop_.parentNode&&this.backdrop_.parentNode.removeChild(this.backdrop_),k.dm.removeDialog(this))},setOpen:function(t){t?this.dialog_.hasAttribute("open")||this.dialog_.setAttribute("open",""):(this.dialog_.removeAttribute("open"),this.maybeHideModal())},backdropMouseEvent_:function(t){if(this.dialog_.hasAttribute("tabindex"))this.dialog_.focus();else{var e=document.createElement("div");this.dialog_.insertBefore(e,this.dialog_.firstChild),e.tabIndex=-1,e.focus(),this.dialog_.removeChild(e)}var o=document.createEvent("MouseEvents");o.initMouseEvent(t.type,t.bubbles,t.cancelable,window,t.detail,t.screenX,t.screenY,t.clientX,t.clientY,t.ctrlKey,t.altKey,t.shiftKey,t.metaKey,t.button,t.relatedTarget),this.dialog_.dispatchEvent(o),t.stopPropagation()},focus_:function(){var t=this.dialog_.querySelector("[autofocus]:not([disabled])");!t&&this.dialog_.tabIndex>=0&&(t=this.dialog_),t||(t=v(this.dialog_)),f(document.activeElement),t&&t.focus()},updateZIndex:function(t,e){if(t<e)throw new Error("dialogZ should never be < backdropZ");this.dialog_.style.zIndex=t,this.backdrop_.style.zIndex=e},show:function(){this.dialog_.open||(this.setOpen(!0),this.focus_())},showModal:function(){if(this.dialog_.hasAttribute("open"))throw new Error("Failed to execute 'showModal' on dialog: The element is already open, and therefore cannot be opened modally.");if(!b(this.dialog_))throw new Error("Failed to execute 'showModal' on dialog: The element is not in a Document.");if(!k.dm.pushDialog(this))throw new Error("Failed to execute 'showModal' on dialog: There are too many open modal dialogs.");(function(t){for(;t&&t!==document.body;){var e=window.getComputedStyle(t),o=function(t,o){return!(void 0===e[t]||e[t]===o)};if(e.opacity<1||o("zIndex","auto")||o("transform","none")||o("mixBlendMode","normal")||o("filter","none")||o("perspective","none")||"isolate"===e.isolation||"fixed"===e.position||"touch"===e.webkitOverflowScrolling)return!0;t=t.parentElement}return!1})(this.dialog_.parentElement)&&console.warn("A dialog is being shown inside a stacking context. This may cause it to be unusable. For more information, see this link: https://github.com/GoogleChrome/dialog-polyfill/#stacking-context"),this.setOpen(!0),this.openAsModal_=!0,k.needsCentering(this.dialog_)?(k.reposition(this.dialog_),this.replacedStyleTop_=!0):this.replacedStyleTop_=!1,this.dialog_.parentNode.insertBefore(this.backdrop_,this.dialog_.nextSibling),this.focus_()},close:function(t){if(!this.dialog_.hasAttribute("open"))throw new Error("Failed to execute 'close' on dialog: The element does not have an 'open' attribute, and therefore cannot be closed.");this.setOpen(!1),void 0!==t&&(this.dialog_.returnValue=t);var e=new h("close",{bubbles:!1,cancelable:!1});p(this.dialog_,e)}};var k={reposition:function(t){var e=document.body.scrollTop||document.documentElement.scrollTop,o=e+(window.innerHeight-t.offsetHeight)/2;t.style.top=Math.max(e,o)+"px"},isInlinePositionSetByStylesheet:function(t){for(var e=0;e<document.styleSheets.length;++e){var o=document.styleSheets[e],n=null;try{n=o.cssRules}catch(t){}if(n)for(var i=0;i<n.length;++i){var a=n[i],r=null;try{r=document.querySelectorAll(a.selectorText)}catch(t){}if(r&&g(r,t)){var s=a.style.getPropertyValue("top"),d=a.style.getPropertyValue("bottom");if(s&&"auto"!==s||d&&"auto"!==d)return!0}}}return!1},needsCentering:function(t){return!("absolute"!==window.getComputedStyle(t).position||"auto"!==t.style.top&&""!==t.style.top||"auto"!==t.style.bottom&&""!==t.style.bottom||k.isInlinePositionSetByStylesheet(t))},forceRegisterDialog:function(t){if((window.HTMLDialogElement||t.showModal)&&console.warn("This browser already supports <dialog>, the polyfill may not work correctly",t),"dialog"!==t.localName)throw new Error("Failed to register dialog: The element is not a dialog.");new _(t)},registerDialog:function(t){t.showModal||k.forceRegisterDialog(t)},DialogManager:function(){this.pendingDialogStack=[];var t=this.checkDOM_.bind(this);this.overlay=document.createElement("div"),this.overlay.className="_dialog_overlay",this.overlay.addEventListener("click",function(e){this.forwardTab_=void 0,e.stopPropagation(),t([])}.bind(this)),this.handleKey_=this.handleKey_.bind(this),this.handleFocus_=this.handleFocus_.bind(this),this.zIndexLow_=1e5,this.zIndexHigh_=100150,this.forwardTab_=void 0,"MutationObserver"in window&&(this.mo_=new MutationObserver((function(e){var o=[];e.forEach((function(t){for(var e,n=0;e=t.removedNodes[n];++n)e instanceof Element&&("dialog"===e.localName&&o.push(e),o=o.concat(e.querySelectorAll("dialog")))})),o.length&&t(o)})))}};if(k.DialogManager.prototype.blockDocument=function(){document.documentElement.addEventListener("focus",this.handleFocus_,!0),document.addEventListener("keydown",this.handleKey_),this.mo_&&this.mo_.observe(document,{childList:!0,subtree:!0})},k.DialogManager.prototype.unblockDocument=function(){document.documentElement.removeEventListener("focus",this.handleFocus_,!0),document.removeEventListener("keydown",this.handleKey_),this.mo_&&this.mo_.disconnect()},k.DialogManager.prototype.updateStacking=function(){for(var t,e=this.zIndexHigh_,o=0;t=this.pendingDialogStack[o];++o)t.updateZIndex(--e,--e),0===o&&(this.overlay.style.zIndex=--e);var n=this.pendingDialogStack[0];n?(n.dialog.parentNode||document.body).appendChild(this.overlay):this.overlay.parentNode&&this.overlay.parentNode.removeChild(this.overlay)},k.DialogManager.prototype.containedByTopDialog_=function(t){for(;t=m(t);){for(var e,o=0;e=this.pendingDialogStack[o];++o)if(e.dialog===t)return 0===o;t=t.parentElement}return!1},k.DialogManager.prototype.handleFocus_=function(t){var e=t.composedPath?t.composedPath()[0]:t.target;if(!this.containedByTopDialog_(e)&&document.activeElement!==document.documentElement&&(t.preventDefault(),t.stopPropagation(),f(e),void 0!==this.forwardTab_)){var o=this.pendingDialogStack[0];return o.dialog.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING&&(this.forwardTab_?o.focus_():e!==document.documentElement&&document.documentElement.focus()),!1}},k.DialogManager.prototype.handleKey_=function(t){if(this.forwardTab_=void 0,27===t.keyCode){t.preventDefault(),t.stopPropagation();var e=new h("cancel",{bubbles:!1,cancelable:!0}),o=this.pendingDialogStack[0];o&&p(o.dialog,e)&&o.dialog.close()}else 9===t.keyCode&&(this.forwardTab_=!t.shiftKey)},k.DialogManager.prototype.checkDOM_=function(t){this.pendingDialogStack.slice().forEach((function(e){-1!==t.indexOf(e.dialog)?e.downgradeModal():e.maybeHideModal()}))},k.DialogManager.prototype.pushDialog=function(t){var e=(this.zIndexHigh_-this.zIndexLow_)/2-1;return!(this.pendingDialogStack.length>=e||(1===this.pendingDialogStack.unshift(t)&&this.blockDocument(),this.updateStacking(),0))},k.DialogManager.prototype.removeDialog=function(t){var e=this.pendingDialogStack.indexOf(t);-1!==e&&(this.pendingDialogStack.splice(e,1),0===this.pendingDialogStack.length&&this.unblockDocument(),this.updateStacking())},k.dm=new k.DialogManager,k.formSubmitter=null,k.imagemapUseValue=null,void 0===window.HTMLDialogElement){var S=document.createElement("form");if(S.setAttribute("method","dialog"),"dialog"!==S.method){var D=Object.getOwnPropertyDescriptor(HTMLFormElement.prototype,"method");if(D){var M=D.get;D.get=function(){return y(this)?"dialog":M.call(this)};var x=D.set;D.set=function(t){return"string"==typeof t&&"dialog"===t.toLowerCase()?this.setAttribute("method",t):x.call(this,t)},Object.defineProperty(HTMLFormElement.prototype,"method",D)}}document.addEventListener("click",(function(t){if(k.formSubmitter=null,k.imagemapUseValue=null,!t.defaultPrevented){var e=t.target;if("composedPath"in t&&(e=t.composedPath().shift()||e),e&&y(e.form)){if(!("submit"===e.type&&["button","input"].indexOf(e.localName)>-1)){if("input"!==e.localName||"image"!==e.type)return;k.imagemapUseValue=t.offsetX+","+t.offsetY}m(e)&&(k.formSubmitter=e)}}}),!1),document.addEventListener("submit",(function(t){var e=t.target;if(!m(e)){var o=w(t);"dialog"===(o&&o.getAttribute("formmethod")||e.getAttribute("method"))&&t.preventDefault()}}));var C=HTMLFormElement.prototype.submit;HTMLFormElement.prototype.submit=function(){if(!y(this))return C.call(this);var t=m(this);t&&t.close()}}const T=k;const L=({EditorJS:t,data:e,dispatchData:o,editorJSConfig:n,itemContentId:i})=>{const a=u(),r=document.createElement("div");return r.id=a,r.style.cursor="pointer",r.addEventListener("click",(()=>{const a=(({EditorJS:t,data:e,editorJSConfig:o,onClose:n})=>{const i=document.createElement("dialog");T.registerDialog(i),i.style.maxWidth="960px",i.style.padding="0",i.style.top="32px",i.style.width="calc(100% - 64px)";const a=document.createElement("div"),r=u();a.id=r,i.append(a);const s=new t(Object.assign(Object.assign({},o),{holder:r,data:e})),d=t=>{t.target instanceof Node&&t.target.isEqualNode(i)&&i.close()};i.addEventListener("click",d);const l=()=>{return t=void 0,e=void 0,a=function*(){const t=yield s.save();s.destroy(),i.removeEventListener("click",d),i.removeEventListener("close",l),i.remove(),null==n||n({editorJSData:t})},new((o=void 0)||(o=Promise))((function(n,i){function r(t){try{d(a.next(t))}catch(t){i(t)}}function s(t){try{d(a.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(r,s)}d((a=a.apply(t,e||[])).next())}));var t,e,o,a};return i.addEventListener("close",l),i})({EditorJS:t,data:e,editorJSConfig:n,onClose:({editorJSData:t})=>{return e=void 0,n=void 0,r=function*(){return o((({itemContent:e,layout:o})=>({itemContent:Object.assign(Object.assign({},e),{[i]:{blocks:t.blocks}}),layout:o})))},new((a=void 0)||(a=Promise))((function(t,o){function i(t){try{d(r.next(t))}catch(t){o(t)}}function s(t){try{d(r.throw(t))}catch(t){o(t)}}function d(e){var o;e.done?t(e.value):(o=e.value,o instanceof a?o:new a((function(t){t(o)}))).then(i,s)}d((r=r.apply(e,n||[])).next())}));var e,n,a,r}});document.body.append(a),a.showModal()})),new t(Object.assign(Object.assign({},n),{holder:a,data:e,minHeight:0,readOnly:!0})),r},O=({EditorJS:t,data:e,dispatchData:o,editorJSConfig:i,itemContentData:a})=>{const r=document.createElement("div");return r.id=e.id,r.className=e.className,r.style.cssText=e.style,e.children.forEach((e=>{let s;switch(e.type){case"container":s=O({EditorJS:t,data:e,dispatchData:o,editorJSConfig:i,itemContentData:a});break;case"item":s=(({EditorJS:t,data:e,dispatchData:o,editorJSConfig:n,itemContentData:i})=>{var a;const r=document.createElement("div");r.id=e.id,r.className=e.className,r.style.cssText=e.style;const s=null!==(a=i[e.itemContentId])&&void 0!==a?a:{blocks:[]};return r.append(L({EditorJS:t,data:s,dispatchData:o,editorJSConfig:n,itemContentId:e.itemContentId})),r})({EditorJS:t,data:e,dispatchData:o,editorJSConfig:i,itemContentData:a});break;default:throw new n}r.append(s)})),r};var N,A,J,P,I,j=function(t,e,o){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,o),o},H=function(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)};class R{constructor({config:t,data:e}){N.set(this,void 0),A.set(this,void 0),J.set(this,void 0),P.set(this,void 0),I.set(this,(t=>{const e=t({itemContent:H(this,J),layout:H(this,P)});j(this,J,e.itemContent),j(this,P,e.layout),this.renderWrapper()})),j(this,A,document.createElement("div")),j(this,J,{}),j(this,P,{type:"container",id:"",className:"",style:"",children:[]}),t&&"EditorJS"in t&&(j(this,N,t),j(this,J,t.initialData.itemContent),t.initialData.layout&&j(this,P,t.initialData.layout)),e&&"itemContent"in e&&(j(this,J,e.itemContent),e.layout&&j(this,P,e.layout))}static get shortcut(){return"CMD+L"}static get toolbox(){return{icon:'\n <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512">\n <rect x="48" y="48" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n <rect x="288" y="48" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n <rect x="48" y="288" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n <rect x="288" y="288" width="176" height="176" rx="20" ry="20" style="fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:32px"/>\n </svg>\n ',title:"Layout"}}render(){return this.renderWrapper(),H(this,A)}save(){return{itemContent:H(this,J),layout:H(this,N).enableLayoutSaving?H(this,P):void 0}}validate(t){return!0}renderWrapper(){H(this,A).innerHTML="",H(this,A).append(O({EditorJS:H(this,N).EditorJS,data:H(this,P),dispatchData:H(this,I),editorJSConfig:H(this,N).editorJSConfig,itemContentData:H(this,J)}))}}N=new WeakMap,A=new WeakMap,J=new WeakMap,P=new WeakMap,I=new WeakMap}},e={};function o(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n](i,i.exports,o),i.exports}return o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o(579)})()})); |
{ | ||
"name": "editorjs-layout", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Layout block tool for Editor.js. ", | ||
@@ -35,2 +35,3 @@ "keywords": [ | ||
"@types/uuid": "^8.3.0", | ||
"dialog-polyfill": "^0.5.6", | ||
"ionicons": "^5.3.0", | ||
@@ -37,0 +38,0 @@ "license-checker": "^25.0.1", |
@@ -51,5 +51,16 @@ <!-- markdownlint-disable first-line-h1 --> | ||
editorjs-layout uses `<dialog>` element. | ||
[GoogleChrome/dialog-polyfill](https://github.com/GoogleChrome/dialog-polyfill) can be used to improve the browser compatibility. | ||
editorjs-layout uses `<dialog>` element and [GoogleChrome/dialog-polyfill](https://github.com/GoogleChrome/dialog-polyfill). | ||
Please load `dialog-polyfill.css` in your document. | ||
```html | ||
<head> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/dialog-polyfill@0.5.6/dist/dialog-polyfill.css" | ||
integrity="sha256-hT0ET4tfm+7MyjeBepBgV2N5tOmsAVKcTWhH82jvoaA=" | ||
crossorigin="anonymous" | ||
/> | ||
</head> | ||
``` | ||
## Build | ||
@@ -56,0 +67,0 @@ |
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
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
29707
102
0
11