editorjs-toggle-block
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -0,1 +1,5 @@ | ||
## 0.2.2 (13.07.2022) | ||
* Replace `crypto.randomUUID()` with `uuid.v4()` to avoid incompatibilities between different browser's versions. | ||
## 0.2.1 (29.06.2022) | ||
@@ -2,0 +6,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.Toggle=e():t.Toggle=e()}(self,(function(){return(()=>{var t={424:(t,e,s)=>{"use strict";s.d(e,{Z:()=>l});var i=s(81),o=s.n(i),r=s(645),n=s.n(r)()(o());n.push([t.id,".toggle-block__selector > div {\n vertical-align: middle;\n display: inline-block;\n padding: 1% 0 1% 0;\n outline: none;\n border: none;\n width: 90%;\n}\n\n.toggle-block__selector br {\n display: none;\n}\n\n.toggle-block__icon > svg {\n vertical-align: middle;\n width: 15px;\n height: auto;\n}\n\n.toggle-block__icon:hover {\n color: #388ae5;\n cursor: pointer;\n}\n\n.bi-play-fill {\n width: 34px;\n height: 34px;\n}\n\n.toggle-block__input {\n margin-left: 5px;\n}\n\n.toggle-block__input:empty:before {\n content: attr(placeholder);\n position: absolute;\n color: gray;\n background-color: transparent;\n}\n\n.toggle-block__content-default {\n margin-left: 20px;\n}\n\n.toggle-block__item {\n margin-left: 39px;\n}\n\n.toggle-block__content-default {\n color: gray;\n border-radius: 5px;\n}\n\n.toggle-block__content-default:hover {\n cursor: pointer;\n background: rgba(55, 53, 47, 0.08);\n}\n\ndiv.toggle-block__hidden {\n display: none;\n}\n",""]);const l=n},645:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var s="",i=void 0!==e[5];return e[4]&&(s+="@supports (".concat(e[4],") {")),e[2]&&(s+="@media ".concat(e[2]," {")),i&&(s+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),s+=t(e),i&&(s+="}"),e[2]&&(s+="}"),e[4]&&(s+="}"),s})).join("")},e.i=function(t,s,i,o,r){"string"==typeof t&&(t=[[null,t,void 0]]);var n={};if(i)for(var l=0;l<this.length;l++){var c=this[l][0];null!=c&&(n[c]=!0)}for(var d=0;d<t.length;d++){var a=[].concat(t[d]);i&&n[a[0]]||(void 0!==r&&(void 0===a[5]||(a[1]="@layer".concat(a[5].length>0?" ".concat(a[5]):""," {").concat(a[1],"}")),a[5]=r),s&&(a[2]?(a[1]="@media ".concat(a[2]," {").concat(a[1],"}"),a[2]=s):a[2]=s),o&&(a[4]?(a[1]="@supports (".concat(a[4],") {").concat(a[1],"}"),a[4]=o):a[4]="".concat(o)),e.push(a))}},e}},81:t=>{"use strict";t.exports=function(t){return t[1]}},379:t=>{"use strict";var e=[];function s(t){for(var s=-1,i=0;i<e.length;i++)if(e[i].identifier===t){s=i;break}return s}function i(t,i){for(var r={},n=[],l=0;l<t.length;l++){var c=t[l],d=i.base?c[0]+i.base:c[0],a=r[d]||0,h="".concat(d," ").concat(a);r[d]=a+1;var g=s(h),u={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==g)e[g].references++,e[g].updater(u);else{var p=o(u,i);i.byIndex=l,e.splice(l,0,{identifier:h,updater:p,references:1})}n.push(h)}return n}function o(t,e){var s=e.domAPI(e);return s.update(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer)return;s.update(t=e)}else s.remove()}}t.exports=function(t,o){var r=i(t=t||[],o=o||{});return function(t){t=t||[];for(var n=0;n<r.length;n++){var l=s(r[n]);e[l].references--}for(var c=i(t,o),d=0;d<r.length;d++){var a=s(r[d]);0===e[a].references&&(e[a].updater(),e.splice(a,1))}r=c}}},569:t=>{"use strict";var e={};t.exports=function(t,s){var i=function(t){if(void 0===e[t]){var s=document.querySelector(t);if(window.HTMLIFrameElement&&s instanceof window.HTMLIFrameElement)try{s=s.contentDocument.head}catch(t){s=null}e[t]=s}return e[t]}(t);if(!i)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");i.appendChild(s)}},216:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},565:(t,e,s)=>{"use strict";t.exports=function(t){var e=s.nc;e&&t.setAttribute("nonce",e)}},795:t=>{"use strict";t.exports=function(t){var e=t.insertStyleElement(t);return{update:function(s){!function(t,e,s){var i="";s.supports&&(i+="@supports (".concat(s.supports,") {")),s.media&&(i+="@media ".concat(s.media," {"));var o=void 0!==s.layer;o&&(i+="@layer".concat(s.layer.length>0?" ".concat(s.layer):""," {")),i+=s.css,o&&(i+="}"),s.media&&(i+="}"),s.supports&&(i+="}");var r=s.sourceMap;r&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleTagTransform(i,t,e.options)}(e,t,s)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},589:t=>{"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}},370:t=>{t.exports='<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="bi bi-play-fill" viewBox="0 0 16 16"><path d="m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393z"></path></svg>'}},e={};function s(i){var o=e[i];if(void 0!==o)return o.exports;var r=e[i]={id:i,exports:{}};return t[i](r,r.exports,s),r.exports}s.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return s.d(e,{a:e}),e},s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var i={};return(()=>{"use strict";s.d(i,{default:()=>k});var t=s(379),e=s.n(t),o=s(795),r=s.n(o),n=s(569),l=s.n(n),c=s(565),d=s.n(c),a=s(216),h=s.n(a),g=s(589),u=s.n(g),p=s(424),f={};f.styleTagTransform=u(),f.setAttributes=d(),f.insert=l().bind(null,"head"),f.domAPI=r(),f.insertStyleElement=h(),e()(p.Z,f),p.Z&&p.Z.locals&&p.Z.locals;var b=s(370),m=s.n(b);class k{static get toolbox(){return{title:"Toggle",icon:m()}}static get enableLineBreaks(){return!0}static get isReadOnlySupported(){return!0}constructor({data:t,api:e,readOnly:s}){this.data={text:t.text||"",status:t.status||"open",fk:t.fk||`fk-${crypto.randomUUID()}`,items:t.items||0},this.itemsId=[],this.api=e;const{toolbar:{close:i},blocks:{getCurrentBlockIndex:o,getBlockByIndex:r,getBlocksCount:n,move:l}}=this.api;this.close=i,this.getCurrentBlockIndex=o,this.getBlocksCount=n,this.getBlockByIndex=r,this.move=l,this.wrapper=void 0,this.readOnly=s||!1,this.addListeners(),this.addSupportForUndoAndRedoActions(),this.addSupportForDragAndDropActions()}createParagraphFromToggleRoot(t){if("Enter"===t.code){const t=document.getSelection().focusOffset,e=this.api.blocks.getCurrentBlockIndex(),s=this.api.blocks.getBlockByIndex(e),{holder:i}=s,o=i.firstChild.firstChild,r=o.children[1].innerHTML,n=r.indexOf("<br>"),l=-1===n?r.length:n;"closed"===this.data.status&&(this.resolveToggleAction(),this.hideAndShowBlocks());const c=r.slice(l+4,t.focusOffset);o.children[1].innerHTML=r.slice(t.focusOffset,l),this.api.blocks.insert("paragraph",{text:c},{},e+1,1),this.setAttributesToNewBlock()}}createParagraphFromIt(){this.setAttributesToNewBlock()}setAttributesToNewBlock(t=null,e=this.wrapper.id){const s=null===t?this.api.blocks.getCurrentBlockIndex():t,i=crypto.randomUUID(),o=this.api.blocks.getBlockByIndex(s);this.itemsId.includes(o.id)||this.itemsId.splice(s-1,0,o.id);const{holder:r}=o,n=r.firstChild.firstChild;r.setAttribute("foreignKey",e),r.setAttribute("id",i),r.classList.add("toggle-block__item"),this.readOnly||(r.onkeydown=this.setEventsToNestedBlock.bind(this),n.focus())}setEventsToNestedBlock(t){if("Enter"===t.code)this.createParagraphFromIt();else{const e=this.api.blocks.getCurrentBlockIndex(),s=this.api.blocks.getBlockByIndex(e),{holder:i}=s;if("Tab"===t.code&&t.shiftKey&&this.extractBlock(e),"Backspace"===t.code){const t=document.getSelection().focusOffset;this.removeBlock(i,s.id,t)}}}removeBlock(t,e,s){if(0===s){const s=t.nextSibling.firstChild.firstChild.innerHTML;t.firstChild.firstChild.children[1].innerHTML+=s;const i=this.itemsId.indexOf(e);this.itemsId.splice(i,1);const o=this.api.blocks.getCurrentBlockIndex();this.api.blocks.delete(o+1)}}removeAttributesFromNewBlock(t){const e=this.api.blocks.getBlockByIndex(t),{holder:s}=e;if(!this.itemsId.includes(e.id)){const t=this.itemsId.indexOf(e.id);this.itemsId.splice(t,1)}s.removeAttribute("foreignKey"),s.removeAttribute("id"),s.onkeydown={},s.onkeyup={},s.classList.remove("toggle-block__item")}createToggle(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("toggle-block__selector"),this.wrapper.id=this.data.fk;const t=document.createElement("span"),e=document.createElement("div"),s=document.createElement("div");t.classList.add("toggle-block__icon"),t.innerHTML=m(),e.classList.add("toggle-block__input"),e.setAttribute("contentEditable",!this.readOnly),e.innerHTML=this.data.text||"",this.readOnly||(e.addEventListener("keyup",this.createParagraphFromToggleRoot.bind(this)),e.addEventListener("keydown",this.removeToggle.bind(this)),e.addEventListener("focusin",(()=>this.setFocusToggleRootAtTheEnd())),e.addEventListener("keyup",this.setPlaceHolder.bind(this)),e.setAttribute("placeholder","Toggle"),e.addEventListener("focus",this.setDefaultContent.bind(this)),e.addEventListener("focusout",this.setDefaultContent.bind(this)),s.addEventListener("click",this.clickInDefaultContent.bind(this)),e.addEventListener("focus",this.setNestedBlockAttributes.bind(this))),s.classList.add("toggle-block__content-default","toggle-block__hidden"),s.innerHTML="Empty toggle. Click or drop blocks inside.",this.wrapper.appendChild(t),this.wrapper.appendChild(e),this.wrapper.appendChild(s)}setFocusToggleRootAtTheEnd(){const t=document.activeElement,e=window.getSelection(),s=document.createRange();e.removeAllRanges(),s.selectNodeContents(t),s.collapse(!1),e.addRange(s),t.focus()}clickInDefaultContent(){this.api.blocks.insert(),this.setAttributesToNewBlock(),this.setDefaultContent()}setDefaultContent(){const t=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`),{firstChild:e,lastChild:s}=this.wrapper,{status:i}=this.data,o=t.length>0||"closed"===i;s.classList.toggle("toggle-block__hidden",o),e.style.color=0===t.length?"gray":"black"}removeToggle(t){if("Backspace"===t.code){const{children:t}=this.wrapper,e=t[1].innerHTML;if(0===document.getSelection().focusOffset){const t=this.api.blocks.getCurrentBlockIndex(),s=e.indexOf("<br>"),i=-1===s?e.length:s,o=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`);for(let e=1;e<o.length+1;e+=1)this.removeAttributesFromNewBlock(t+e);this.api.blocks.delete(t),this.api.blocks.insert("paragraph",{text:e.slice(0,i)},{},t,1),this.api.caret.setToBlock(t)}}}extractBlock(t){const e=this.wrapper.children[1];let s,i={};for(;i[1]!==e;){this.api.caret.setToPreviousBlock("end",0),s=this.api.blocks.getCurrentBlockIndex();const t=this.api.blocks.getBlockByIndex(s),{holder:e}=t;i=e.firstChild.firstChild.children}const o=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`),r=s+o.length;this.api.caret.setToBlock(t),o.length>1&&this.api.blocks.move(r),setTimeout((()=>this.removeAttributesFromNewBlock(r)),200),this.api.toolbar.close()}setPlaceHolder(t){if("Backspace"===t.code||"Enter"===t.code){const{children:t}=this.wrapper,{length:e}=t[1].textContent;0===e&&(t[1].textContent="")}}render(){return this.createToggle(),setTimeout((()=>this.renderItems())),setTimeout((()=>this.setInitialTransition())),this.wrapper}setInitialTransition(){const{status:t}=this.data,e=this.wrapper.firstChild.firstChild;e.style.transition="0.1s",e.style.transform=`rotate(${"closed"===t?0:90}deg)`}renderItems(){const t=this.api.blocks.getBlocksCount(),e=this.wrapper.firstChild;let s;if(this.readOnly){const t=document.getElementsByClassName("codex-editor__redactor")[0],{children:e}=t,{length:i}=e;for(let t=0;t<i;t+=1){const i=e[t].firstChild.firstChild,{id:o}=i;if(o===this.wrapper.id){s=t;break}}}else{const t=this.wrapper.children[1];let e={};for(;e[1]!==t;){s=this.api.blocks.getCurrentBlockIndex();const t=this.api.blocks.getBlockByIndex(s),{holder:i}=t;e=i.firstChild.firstChild.children,this.api.caret.setToNextBlock("end",0)}}if(s+this.data.items<t)for(let t=s+1,e=0;t<=s+this.data.items;t+=1){const s=this.api.blocks.getBlockByIndex(t),{holder:i}=s,o=i.firstChild.firstChild;if(this.isPartOfAToggle(o)){this.data.items=e;break}this.setAttributesToNewBlock(t),e+=1}else this.data.items=0;e.addEventListener("click",(()=>{this.resolveToggleAction(),setTimeout((()=>{this.hideAndShowBlocks()}))})),this.hideAndShowBlocks()}resolveToggleAction(){const t=this.wrapper.firstChild.firstChild;"closed"===this.data.status?(this.data.status="open",t.style.transform="rotate(90deg)"):(this.data.status="closed",t.style.transform="rotate(0deg)"),this.api.blocks.getBlockByIndex(this.api.blocks.getCurrentBlockIndex()).holder.setAttribute("status",this.data.status)}hideAndShowBlocks(t=this.wrapper.id,e=this.data.status){const s=document.querySelectorAll(`div[foreignKey="${t}"]`),{length:i}=s;if(i>0)s.forEach((t=>{t.hidden="closed"===e;const s=t.querySelectorAll(".toggle-block__selector");if(s.length>0){const i="closed"===e?e:t.getAttribute("status");this.hideAndShowBlocks(s[0].getAttribute("id"),i)}}));else if(t===this.wrapper.id){const{lastChild:t}=this.wrapper;t.classList.toggle("toggle-block__hidden",e)}}save(t){const{children:e}=t,s=e[1].innerHTML,i=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`);return Object.assign(this.data,{text:s,items:i.length})}getDecendentsNumber(t){let e=0;return document.querySelectorAll(`div[foreignKey="${t}"]`).forEach((t=>{if(t.hasAttribute("status")){const s=t.querySelector(".toggle-block__selector").getAttribute("id");e+=this.getDecendentsNumber(s)}e+=1})),e}highlightToggleItems(t){document.querySelectorAll(`div[foreignKey="${t}"]`).forEach((t=>{if(t.classList.add("ce-block--selected"),t.hasAttribute("status")){const e=t.querySelector(".toggle-block__selector").getAttribute("id");this.highlightToggleItems(e)}}))}renderSettings(){const t=document.getElementsByClassName("ce-settings--opened")[0].lastChild,e=this.api.blocks.getCurrentBlockIndex();this.highlightToggleItems(this.wrapper.id),setTimeout((()=>{this.addEventsMoveButtons("ce-tune-move-down",0,t,e),this.addEventsMoveButtons("ce-tune-move-up",1,t,e);const s=t.getElementsByClassName("ce-settings__button--delete")[0];s&&s.addEventListener("click",(()=>{const t=s.classList;-1===Object.values(t).indexOf("clicked-to-destroy-toggle")?s.classList.add("clicked-to-destroy-toggle"):this.removeFullToggle(e)}))}))}addEventsMoveButtons(t,e,s,i){const o=s.getElementsByClassName(t);if(!o.length)return;const r=o[0];r&&r.addEventListener("click",(()=>{this.moveToggle(i,e)}))}moveToggle(t,e){if(!this.readOnly){this.close();const s=this.getCurrentBlockIndex(),i=this.getDecendentsNumber(this.wrapper.id),o=this.getBlocksCount(),r=t+i;this.move(t,s),t>=0&&r<=o-1&&(0===e?this.moveDown(t,r):this.moveUp(t,r))}}moveDown(t,e){const s=e+1,i=this.getBlockByIndex(s),{holder:o}=i;if(this.move(t,s),"toggle"===i.name){const e=o.querySelector(".toggle-block__selector").getAttribute("id"),i=this.getDecendentsNumber(e);this.moveDecendents(i,t+1,s+1,0)}}moveUp(t,e){const s=t-1,i=this.getBlockByIndex(s);if("toggle"===i.name)return;const{holder:o}=i;if(o.hasAttribute("foreignKey")){const s=this.getBlockByIndex(t).holder.getAttribute("foreignKey"),i=o.getAttribute("foreignKey");if(i!==s){const o=this.findIndexOfParentBlock(s,i,t),r=this.getBlockByIndex(o).holder.querySelector(".toggle-block__selector").getAttribute("id"),n=this.getDecendentsNumber(r);return this.move(e,o),void this.moveDecendents(n,e,o,1)}}this.move(e,s)}findIndexOfParentBlock(t,e,s){const i=s-(this.getDecendentsNumber(e)+1),o=this.getBlockByIndex(i).holder;if(o.hasAttribute("foreignKey")){const e=o.getAttribute("foreignKey");if(e!==t){const s=this.getBlockByIndex(i-1).holder;if(s.hasAttribute("foreignKey")){const o=s.getAttribute("foreignKey");if(o!==e)return this.findIndexOfParentBlock(t,o,i)}}}return i}moveDecendents(t,e,s,i){let o=s,r=e;for(;t;)this.move(r,o),0===i&&(o+=1,r+=1),t-=1}removeFullToggle(t){const e=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`),{length:s}=e;for(let e=t;e<t+s;e+=1)this.api.blocks.delete(t)}addListeners(){this.readOnly||document.activeElement.addEventListener("keyup",(t=>{const e=document.activeElement,s=this.api.blocks.getCurrentBlockIndex(),i=e.parentElement.parentElement;"Space"===t.code?this.createToggleWithShortcut(e):s>0&&!this.isPartOfAToggle(e)&&!this.isPartOfAToggle(i)&&"Tab"===t.code&&this.nestBlock(e)}))}addSupportForUndoAndRedoActions(){if(!this.readOnly){const t=document.querySelector("div.codex-editor__redactor"),e={attributes:!0,childList:!0,characterData:!0};new MutationObserver((t=>{t.forEach((t=>{"childList"===t.type&&setTimeout(this.restoreItemAttributes.bind(this,t))}))})).observe(t,e)}}getIndex=t=>Array.from(t.parentNode.children).indexOf(t);isChild=(t,e)=>!(!t||!e)&&(t===e||[...document.querySelectorAll(`div[foreignKey="${t}"]`)].some((t=>{const s=t.querySelector(".toggle-block__selector");return!!s&&this.isChild(s.getAttribute("id"),e)})));addSupportForDragAndDropActions(){if(!this.readOnly){if(void 0===this.wrapper)return void setTimeout((()=>this.addSupportForDragAndDropActions()),250);document.querySelector(`#${this.wrapper.id}`).parentNode.parentNode.setAttribute("status",this.data.status);const t=document.querySelector(".ce-toolbar__settings-btn");t.setAttribute("draggable","true"),t.addEventListener("dragstart",(()=>{this.startBlock=this.api.blocks.getCurrentBlockIndex(),this.nameDragged=this.api.blocks.getBlockByIndex(this.startBlock).name,this.holderDragged=this.api.blocks.getBlockByIndex(this.startBlock).holder})),document.addEventListener("drop",(t=>{const{target:e}=t;if(document.contains(e)){const t=e.classList.contains("ce-block")?e:e.closest(".ce-block");if(t&&t!==this.holderDragged){let e=this.getIndex(t);e=this.startBlock<e?e+1:e;const s=t.querySelectorAll(".toggle-block__selector").length>0||null!==t.getAttribute("foreignKey");setTimeout((()=>{if("toggle"===this.nameDragged){const i=this.holderDragged.querySelector(`#${this.wrapper.id}`);if(i)if(this.isChild(i.getAttribute("id"),t.getAttribute("foreignKey"))){if(this.startBlock===e?this.api.blocks.move(this.startBlock+1,e):this.api.blocks.move(this.startBlock,e),!s){const t=this.getIndex(this.holderDragged);this.removeAttributesFromNewBlock(t)}}else{if(s){const e=t.getAttribute("foreignKey")??t.querySelector(".toggle-block__selector").getAttribute("id"),s=this.getIndex(this.holderDragged);this.setAttributesToNewBlock(s,e)}this.moveChildren(e)}}if(!s){const t=this.getIndex(this.holderDragged);this.removeAttributesFromNewBlock(t)}}))}}}))}}moveChildren(t,e=this.wrapper.id){let s=document.querySelectorAll(`div[foreignKey="${e}"]`);s=this.startBlock>=t?[...s].reverse():s,s.forEach((e=>{const s=this.getIndex(e);this.api.blocks.move(t,s);const i=e.querySelectorAll(".toggle-block__selector");if(i.length>0){const s=this.getIndex(e),o=this.startBlock<t?0:1;i.forEach((t=>this.moveChildren(s+o,t.getAttribute("id"))));const r=Math.abs(t-s);t=this.startBlock<t?t+r:t-r}}))}restoreItemAttributes(t){if(void 0!==this.wrapper){const e=this.api.blocks.getCurrentBlockIndex(),s=this.api.blocks.getBlockByIndex(e),{holder:i}=s,o=!this.isPartOfAToggle(i),r=t.removedNodes[0];if(this.itemsId.includes(s.id)&&o)this.setAttributesToNewBlock(e);else if(r&&this.isPartOfAToggle(r)&&o){const t=i.firstChild.firstChild;this.isPartOfAToggle(t)||(this.setAttributesToNewBlock(e),this.itemsId[e]=s.id)}}}createToggleWithShortcut(t){const e=t.textContent;if(">"===e[0]&&!this.isPartOfAToggle(t)){const t=this.api.blocks.getCurrentBlockIndex();this.api.blocks.insert("toggle",{text:e.slice(2)},this.api,t,!0),this.api.blocks.delete(t+1),this.api.caret.setToBlock(t)}}nestBlock(t){const e=t.parentElement.parentElement,s=e.previousElementSibling,i=s.firstChild.firstChild;if(this.isPartOfAToggle(i)||this.isPartOfAToggle(s)){const t=s.getAttribute("foreignKey"),o=i.getAttribute("id"),r=t||o;e.setAttribute("will-be-a-nested-block",!0),document.getElementById(r).children[1].focus()}}setNestedBlockAttributes(){const t=this.api.blocks.getCurrentBlockIndex(),e=this.api.blocks.getBlockByIndex(t),{holder:s}=e;s.getAttribute("will-be-a-nested-block")&&(s.removeAttribute("will-be-a-nested-block"),this.setAttributesToNewBlock(t),this.api.toolbar.close())}isPartOfAToggle(t){const e=Array.from(t.classList);return e.includes("toggle-block__item")||e.includes("toggle-block__input")||e.includes("toggle-block__selector")}}})(),i.default})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Toggle=e():t.Toggle=e()}(self,(function(){return(()=>{var t={424:(t,e,o)=>{"use strict";o.d(e,{Z:()=>l});var s=o(81),i=o.n(s),r=o(645),n=o.n(r)()(i());n.push([t.id,".toggle-block__selector > div {\n vertical-align: middle;\n display: inline-block;\n padding: 1% 0 1% 0;\n outline: none;\n border: none;\n width: 90%;\n}\n\n.toggle-block__selector br {\n display: none;\n}\n\n.toggle-block__icon > svg {\n vertical-align: middle;\n width: 15px;\n height: auto;\n}\n\n.toggle-block__icon:hover {\n color: #388ae5;\n cursor: pointer;\n}\n\n.bi-play-fill {\n width: 34px;\n height: 34px;\n}\n\n.toggle-block__input {\n margin-left: 5px;\n}\n\n.toggle-block__input:empty:before {\n content: attr(placeholder);\n position: absolute;\n color: gray;\n background-color: transparent;\n}\n\n.toggle-block__content-default {\n margin-left: 20px;\n}\n\n.toggle-block__item {\n margin-left: 39px;\n}\n\n.toggle-block__content-default {\n color: gray;\n border-radius: 5px;\n}\n\n.toggle-block__content-default:hover {\n cursor: pointer;\n background: rgba(55, 53, 47, 0.08);\n}\n\ndiv.toggle-block__hidden {\n display: none;\n}\n",""]);const l=n},645:t=>{"use strict";t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var o="",s=void 0!==e[5];return e[4]&&(o+="@supports (".concat(e[4],") {")),e[2]&&(o+="@media ".concat(e[2]," {")),s&&(o+="@layer".concat(e[5].length>0?" ".concat(e[5]):""," {")),o+=t(e),s&&(o+="}"),e[2]&&(o+="}"),e[4]&&(o+="}"),o})).join("")},e.i=function(t,o,s,i,r){"string"==typeof t&&(t=[[null,t,void 0]]);var n={};if(s)for(var l=0;l<this.length;l++){var c=this[l][0];null!=c&&(n[c]=!0)}for(var a=0;a<t.length;a++){var d=[].concat(t[a]);s&&n[d[0]]||(void 0!==r&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=r),o&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=o):d[2]=o),i&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=i):d[4]="".concat(i)),e.push(d))}},e}},81:t=>{"use strict";t.exports=function(t){return t[1]}},379:t=>{"use strict";var e=[];function o(t){for(var o=-1,s=0;s<e.length;s++)if(e[s].identifier===t){o=s;break}return o}function s(t,s){for(var r={},n=[],l=0;l<t.length;l++){var c=t[l],a=s.base?c[0]+s.base:c[0],d=r[a]||0,h="".concat(a," ").concat(d);r[a]=d+1;var u=o(h),g={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==u)e[u].references++,e[u].updater(g);else{var p=i(g,s);s.byIndex=l,e.splice(l,0,{identifier:h,updater:p,references:1})}n.push(h)}return n}function i(t,e){var o=e.domAPI(e);return o.update(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer)return;o.update(t=e)}else o.remove()}}t.exports=function(t,i){var r=s(t=t||[],i=i||{});return function(t){t=t||[];for(var n=0;n<r.length;n++){var l=o(r[n]);e[l].references--}for(var c=s(t,i),a=0;a<r.length;a++){var d=o(r[a]);0===e[d].references&&(e[d].updater(),e.splice(d,1))}r=c}}},569:t=>{"use strict";var e={};t.exports=function(t,o){var s=function(t){if(void 0===e[t]){var o=document.querySelector(t);if(window.HTMLIFrameElement&&o instanceof window.HTMLIFrameElement)try{o=o.contentDocument.head}catch(t){o=null}e[t]=o}return e[t]}(t);if(!s)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");s.appendChild(o)}},216:t=>{"use strict";t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},565:(t,e,o)=>{"use strict";t.exports=function(t){var e=o.nc;e&&t.setAttribute("nonce",e)}},795:t=>{"use strict";t.exports=function(t){var e=t.insertStyleElement(t);return{update:function(o){!function(t,e,o){var s="";o.supports&&(s+="@supports (".concat(o.supports,") {")),o.media&&(s+="@media ".concat(o.media," {"));var i=void 0!==o.layer;i&&(s+="@layer".concat(o.layer.length>0?" ".concat(o.layer):""," {")),s+=o.css,i&&(s+="}"),o.media&&(s+="}"),o.supports&&(s+="}");var r=o.sourceMap;r&&"undefined"!=typeof btoa&&(s+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(r))))," */")),e.styleTagTransform(s,t,e.options)}(e,t,o)},remove:function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(e)}}}},589:t=>{"use strict";t.exports=function(t,e){if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}},370:t=>{t.exports='<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="bi bi-play-fill" viewBox="0 0 16 16"><path d="m11.596 8.697-6.363 3.692c-.54.313-1.233-.066-1.233-.697V4.308c0-.63.692-1.01 1.233-.696l6.363 3.692a.802.802 0 0 1 0 1.393z"></path></svg>'}},e={};function o(s){var i=e[s];if(void 0!==i)return i.exports;var r=e[s]={id:s,exports:{}};return t[s](r,r.exports,o),r.exports}o.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return o.d(e,{a:e}),e},o.d=(t,e)=>{for(var s in e)o.o(e,s)&&!o.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var s={};return(()=>{"use strict";o.d(s,{default:()=>T});var t=o(379),e=o.n(t),i=o(795),r=o.n(i),n=o(569),l=o.n(n),c=o(565),a=o.n(c),d=o(216),h=o.n(d),u=o(589),g=o.n(u),p=o(424),f={};f.styleTagTransform=g(),f.setAttributes=a(),f.insert=l().bind(null,"head"),f.domAPI=r(),f.insertStyleElement=h(),e()(p.Z,f),p.Z&&p.Z.locals&&p.Z.locals;var b,m=new Uint8Array(16);function k(){if(!b&&!(b="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 b(m)}const v=/^(?:[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,y=function(t){return"string"==typeof t&&v.test(t)};for(var B=[],A=0;A<256;++A)B.push((A+256).toString(16).substr(1));const x=function(t,e,o){var s=(t=t||{}).random||(t.rng||k)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e){o=o||0;for(var i=0;i<16;++i)e[o+i]=s[i];return e}return function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=(B[t[e+0]]+B[t[e+1]]+B[t[e+2]]+B[t[e+3]]+"-"+B[t[e+4]]+B[t[e+5]]+"-"+B[t[e+6]]+B[t[e+7]]+"-"+B[t[e+8]]+B[t[e+9]]+"-"+B[t[e+10]]+B[t[e+11]]+B[t[e+12]]+B[t[e+13]]+B[t[e+14]]+B[t[e+15]]).toLowerCase();if(!y(o))throw TypeError("Stringified UUID is invalid");return o}(s)};var C=o(370),w=o.n(C);class T{static get toolbox(){return{title:"Toggle",icon:w()}}static get enableLineBreaks(){return!0}static get isReadOnlySupported(){return!0}constructor({data:t,api:e,readOnly:o}){this.data={text:t.text||"",status:t.status||"open",fk:t.fk||`fk-${x()}`,items:t.items||0},this.itemsId=[],this.api=e;const{toolbar:{close:s},blocks:{getCurrentBlockIndex:i,getBlockByIndex:r,getBlocksCount:n,move:l}}=this.api;this.close=s,this.getCurrentBlockIndex=i,this.getBlocksCount=n,this.getBlockByIndex=r,this.move=l,this.wrapper=void 0,this.readOnly=o||!1,this.addListeners(),this.addSupportForUndoAndRedoActions(),this.addSupportForDragAndDropActions()}createParagraphFromToggleRoot(t){if("Enter"===t.code){const t=document.getSelection().focusOffset,e=this.api.blocks.getCurrentBlockIndex(),o=this.api.blocks.getBlockByIndex(e),{holder:s}=o,i=s.firstChild.firstChild,r=i.children[1].innerHTML,n=r.indexOf("<br>"),l=-1===n?r.length:n;"closed"===this.data.status&&(this.resolveToggleAction(),this.hideAndShowBlocks());const c=r.slice(l+4,t.focusOffset);i.children[1].innerHTML=r.slice(t.focusOffset,l),this.api.blocks.insert("paragraph",{text:c},{},e+1,1),this.setAttributesToNewBlock()}}createParagraphFromIt(){this.setAttributesToNewBlock()}setAttributesToNewBlock(t=null,e=this.wrapper.id){const o=null===t?this.api.blocks.getCurrentBlockIndex():t,s=x(),i=this.api.blocks.getBlockByIndex(o);this.itemsId.includes(i.id)||this.itemsId.splice(o-1,0,i.id);const{holder:r}=i,n=r.firstChild.firstChild;r.setAttribute("foreignKey",e),r.setAttribute("id",s),r.classList.add("toggle-block__item"),this.readOnly||(r.onkeydown=this.setEventsToNestedBlock.bind(this),n.focus())}setEventsToNestedBlock(t){if("Enter"===t.code)this.createParagraphFromIt();else{const e=this.api.blocks.getCurrentBlockIndex(),o=this.api.blocks.getBlockByIndex(e),{holder:s}=o;if("Tab"===t.code&&t.shiftKey&&this.extractBlock(e),"Backspace"===t.code){const t=document.getSelection().focusOffset;this.removeBlock(s,o.id,t)}}}removeBlock(t,e,o){if(0===o){const o=t.nextSibling.firstChild.firstChild.innerHTML;t.firstChild.firstChild.children[1].innerHTML+=o;const s=this.itemsId.indexOf(e);this.itemsId.splice(s,1);const i=this.api.blocks.getCurrentBlockIndex();this.api.blocks.delete(i+1)}}removeAttributesFromNewBlock(t){const e=this.api.blocks.getBlockByIndex(t),{holder:o}=e;if(!this.itemsId.includes(e.id)){const t=this.itemsId.indexOf(e.id);this.itemsId.splice(t,1)}o.removeAttribute("foreignKey"),o.removeAttribute("id"),o.onkeydown={},o.onkeyup={},o.classList.remove("toggle-block__item")}createToggle(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("toggle-block__selector"),this.wrapper.id=this.data.fk;const t=document.createElement("span"),e=document.createElement("div"),o=document.createElement("div");t.classList.add("toggle-block__icon"),t.innerHTML=w(),e.classList.add("toggle-block__input"),e.setAttribute("contentEditable",!this.readOnly),e.innerHTML=this.data.text||"",this.readOnly||(e.addEventListener("keyup",this.createParagraphFromToggleRoot.bind(this)),e.addEventListener("keydown",this.removeToggle.bind(this)),e.addEventListener("focusin",(()=>this.setFocusToggleRootAtTheEnd())),e.addEventListener("keyup",this.setPlaceHolder.bind(this)),e.setAttribute("placeholder","Toggle"),e.addEventListener("focus",this.setDefaultContent.bind(this)),e.addEventListener("focusout",this.setDefaultContent.bind(this)),o.addEventListener("click",this.clickInDefaultContent.bind(this)),e.addEventListener("focus",this.setNestedBlockAttributes.bind(this))),o.classList.add("toggle-block__content-default","toggle-block__hidden"),o.innerHTML="Empty toggle. Click or drop blocks inside.",this.wrapper.appendChild(t),this.wrapper.appendChild(e),this.wrapper.appendChild(o)}setFocusToggleRootAtTheEnd(){const t=document.activeElement,e=window.getSelection(),o=document.createRange();e.removeAllRanges(),o.selectNodeContents(t),o.collapse(!1),e.addRange(o),t.focus()}clickInDefaultContent(){this.api.blocks.insert(),this.setAttributesToNewBlock(),this.setDefaultContent()}setDefaultContent(){const t=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`),{firstChild:e,lastChild:o}=this.wrapper,{status:s}=this.data,i=t.length>0||"closed"===s;o.classList.toggle("toggle-block__hidden",i),e.style.color=0===t.length?"gray":"black"}removeToggle(t){if("Backspace"===t.code){const{children:t}=this.wrapper,e=t[1].innerHTML;if(0===document.getSelection().focusOffset){const t=this.api.blocks.getCurrentBlockIndex(),o=e.indexOf("<br>"),s=-1===o?e.length:o,i=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`);for(let e=1;e<i.length+1;e+=1)this.removeAttributesFromNewBlock(t+e);this.api.blocks.delete(t),this.api.blocks.insert("paragraph",{text:e.slice(0,s)},{},t,1),this.api.caret.setToBlock(t)}}}extractBlock(t){const e=this.wrapper.children[1];let o,s={};for(;s[1]!==e;){this.api.caret.setToPreviousBlock("end",0),o=this.api.blocks.getCurrentBlockIndex();const t=this.api.blocks.getBlockByIndex(o),{holder:e}=t;s=e.firstChild.firstChild.children}const i=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`),r=o+i.length;this.api.caret.setToBlock(t),i.length>1&&this.api.blocks.move(r),setTimeout((()=>this.removeAttributesFromNewBlock(r)),200),this.api.toolbar.close()}setPlaceHolder(t){if("Backspace"===t.code||"Enter"===t.code){const{children:t}=this.wrapper,{length:e}=t[1].textContent;0===e&&(t[1].textContent="")}}render(){return this.createToggle(),setTimeout((()=>this.renderItems())),setTimeout((()=>this.setInitialTransition())),this.wrapper}setInitialTransition(){const{status:t}=this.data,e=this.wrapper.firstChild.firstChild;e.style.transition="0.1s",e.style.transform=`rotate(${"closed"===t?0:90}deg)`}renderItems(){const t=this.api.blocks.getBlocksCount(),e=this.wrapper.firstChild;let o;if(this.readOnly){const t=document.getElementsByClassName("codex-editor__redactor")[0],{children:e}=t,{length:s}=e;for(let t=0;t<s;t+=1){const s=e[t].firstChild.firstChild,{id:i}=s;if(i===this.wrapper.id){o=t;break}}}else{const t=this.wrapper.children[1];let e={};for(;e[1]!==t;){o=this.api.blocks.getCurrentBlockIndex();const t=this.api.blocks.getBlockByIndex(o),{holder:s}=t;e=s.firstChild.firstChild.children,this.api.caret.setToNextBlock("end",0)}}if(o+this.data.items<t)for(let t=o+1,e=0;t<=o+this.data.items;t+=1){const o=this.api.blocks.getBlockByIndex(t),{holder:s}=o,i=s.firstChild.firstChild;if(this.isPartOfAToggle(i)){this.data.items=e;break}this.setAttributesToNewBlock(t),e+=1}else this.data.items=0;e.addEventListener("click",(()=>{this.resolveToggleAction(),setTimeout((()=>{this.hideAndShowBlocks()}))})),this.hideAndShowBlocks()}resolveToggleAction(){const t=this.wrapper.firstChild.firstChild;"closed"===this.data.status?(this.data.status="open",t.style.transform="rotate(90deg)"):(this.data.status="closed",t.style.transform="rotate(0deg)"),this.api.blocks.getBlockByIndex(this.api.blocks.getCurrentBlockIndex()).holder.setAttribute("status",this.data.status)}hideAndShowBlocks(t=this.wrapper.id,e=this.data.status){const o=document.querySelectorAll(`div[foreignKey="${t}"]`),{length:s}=o;if(s>0)o.forEach((t=>{t.hidden="closed"===e;const o=t.querySelectorAll(".toggle-block__selector");if(o.length>0){const s="closed"===e?e:t.getAttribute("status");this.hideAndShowBlocks(o[0].getAttribute("id"),s)}}));else if(t===this.wrapper.id){const{lastChild:t}=this.wrapper;t.classList.toggle("toggle-block__hidden",e)}}save(t){const{children:e}=t,o=e[1].innerHTML,s=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`);return Object.assign(this.data,{text:o,items:s.length})}getDecendentsNumber(t){let e=0;return document.querySelectorAll(`div[foreignKey="${t}"]`).forEach((t=>{if(t.hasAttribute("status")){const o=t.querySelector(".toggle-block__selector").getAttribute("id");e+=this.getDecendentsNumber(o)}e+=1})),e}highlightToggleItems(t){document.querySelectorAll(`div[foreignKey="${t}"]`).forEach((t=>{if(t.classList.add("ce-block--selected"),t.hasAttribute("status")){const e=t.querySelector(".toggle-block__selector").getAttribute("id");this.highlightToggleItems(e)}}))}renderSettings(){const t=document.getElementsByClassName("ce-settings--opened")[0].lastChild,e=this.api.blocks.getCurrentBlockIndex();this.highlightToggleItems(this.wrapper.id),setTimeout((()=>{this.addEventsMoveButtons("ce-tune-move-down",0,t,e),this.addEventsMoveButtons("ce-tune-move-up",1,t,e);const o=t.getElementsByClassName("ce-settings__button--delete")[0];o&&o.addEventListener("click",(()=>{const t=o.classList;-1===Object.values(t).indexOf("clicked-to-destroy-toggle")?o.classList.add("clicked-to-destroy-toggle"):this.removeFullToggle(e)}))}))}addEventsMoveButtons(t,e,o,s){const i=o.getElementsByClassName(t);if(!i.length)return;const r=i[0];r&&r.addEventListener("click",(()=>{this.moveToggle(s,e)}))}moveToggle(t,e){if(!this.readOnly){this.close();const o=this.getCurrentBlockIndex(),s=this.getDecendentsNumber(this.wrapper.id),i=this.getBlocksCount(),r=t+s;this.move(t,o),t>=0&&r<=i-1&&(0===e?this.moveDown(t,r):this.moveUp(t,r))}}moveDown(t,e){const o=e+1,s=this.getBlockByIndex(o),{holder:i}=s;if(this.move(t,o),"toggle"===s.name){const e=i.querySelector(".toggle-block__selector").getAttribute("id"),s=this.getDecendentsNumber(e);this.moveDecendents(s,t+1,o+1,0)}}moveUp(t,e){const o=t-1,s=this.getBlockByIndex(o);if("toggle"===s.name)return;const{holder:i}=s;if(i.hasAttribute("foreignKey")){const o=this.getBlockByIndex(t).holder.getAttribute("foreignKey"),s=i.getAttribute("foreignKey");if(s!==o){const i=this.findIndexOfParentBlock(o,s,t),r=this.getBlockByIndex(i).holder.querySelector(".toggle-block__selector").getAttribute("id"),n=this.getDecendentsNumber(r);return this.move(e,i),void this.moveDecendents(n,e,i,1)}}this.move(e,o)}findIndexOfParentBlock(t,e,o){const s=o-(this.getDecendentsNumber(e)+1),i=this.getBlockByIndex(s).holder;if(i.hasAttribute("foreignKey")){const e=i.getAttribute("foreignKey");if(e!==t){const o=this.getBlockByIndex(s-1).holder;if(o.hasAttribute("foreignKey")){const i=o.getAttribute("foreignKey");if(i!==e)return this.findIndexOfParentBlock(t,i,s)}}}return s}moveDecendents(t,e,o,s){let i=o,r=e;for(;t;)this.move(r,i),0===s&&(i+=1,r+=1),t-=1}removeFullToggle(t){const e=document.querySelectorAll(`div[foreignKey="${this.wrapper.id}"]`),{length:o}=e;for(let e=t;e<t+o;e+=1)this.api.blocks.delete(t)}addListeners(){this.readOnly||document.activeElement.addEventListener("keyup",(t=>{const e=document.activeElement,o=this.api.blocks.getCurrentBlockIndex(),s=e.parentElement.parentElement;"Space"===t.code?this.createToggleWithShortcut(e):o>0&&!this.isPartOfAToggle(e)&&!this.isPartOfAToggle(s)&&"Tab"===t.code&&this.nestBlock(e)}))}addSupportForUndoAndRedoActions(){if(!this.readOnly){const t=document.querySelector("div.codex-editor__redactor"),e={attributes:!0,childList:!0,characterData:!0};new MutationObserver((t=>{t.forEach((t=>{"childList"===t.type&&setTimeout(this.restoreItemAttributes.bind(this,t))}))})).observe(t,e)}}getIndex=t=>Array.from(t.parentNode.children).indexOf(t);isChild=(t,e)=>!(!t||!e)&&(t===e||[...document.querySelectorAll(`div[foreignKey="${t}"]`)].some((t=>{const o=t.querySelector(".toggle-block__selector");return!!o&&this.isChild(o.getAttribute("id"),e)})));addSupportForDragAndDropActions(){if(!this.readOnly){if(void 0===this.wrapper)return void setTimeout((()=>this.addSupportForDragAndDropActions()),250);document.querySelector(`#${this.wrapper.id}`).parentNode.parentNode.setAttribute("status",this.data.status);const t=document.querySelector(".ce-toolbar__settings-btn");t.setAttribute("draggable","true"),t.addEventListener("dragstart",(()=>{this.startBlock=this.api.blocks.getCurrentBlockIndex(),this.nameDragged=this.api.blocks.getBlockByIndex(this.startBlock).name,this.holderDragged=this.api.blocks.getBlockByIndex(this.startBlock).holder})),document.addEventListener("drop",(t=>{const{target:e}=t;if(document.contains(e)){const t=e.classList.contains("ce-block")?e:e.closest(".ce-block");if(t&&t!==this.holderDragged){let e=this.getIndex(t);e=this.startBlock<e?e+1:e;const o=t.querySelectorAll(".toggle-block__selector").length>0||null!==t.getAttribute("foreignKey");setTimeout((()=>{if("toggle"===this.nameDragged){const s=this.holderDragged.querySelector(`#${this.wrapper.id}`);if(s)if(this.isChild(s.getAttribute("id"),t.getAttribute("foreignKey"))){if(this.startBlock===e?this.api.blocks.move(this.startBlock+1,e):this.api.blocks.move(this.startBlock,e),!o){const t=this.getIndex(this.holderDragged);this.removeAttributesFromNewBlock(t)}}else{if(o){const e=t.getAttribute("foreignKey")??t.querySelector(".toggle-block__selector").getAttribute("id"),o=this.getIndex(this.holderDragged);this.setAttributesToNewBlock(o,e)}this.moveChildren(e)}}if(!o){const t=this.getIndex(this.holderDragged);this.removeAttributesFromNewBlock(t)}}))}}}))}}moveChildren(t,e=this.wrapper.id){let o=document.querySelectorAll(`div[foreignKey="${e}"]`);o=this.startBlock>=t?[...o].reverse():o,o.forEach((e=>{const o=this.getIndex(e);this.api.blocks.move(t,o);const s=e.querySelectorAll(".toggle-block__selector");if(s.length>0){const o=this.getIndex(e),i=this.startBlock<t?0:1;s.forEach((t=>this.moveChildren(o+i,t.getAttribute("id"))));const r=Math.abs(t-o);t=this.startBlock<t?t+r:t-r}}))}restoreItemAttributes(t){if(void 0!==this.wrapper){const e=this.api.blocks.getCurrentBlockIndex(),o=this.api.blocks.getBlockByIndex(e),{holder:s}=o,i=!this.isPartOfAToggle(s),r=t.removedNodes[0];if(this.itemsId.includes(o.id)&&i)this.setAttributesToNewBlock(e);else if(r&&this.isPartOfAToggle(r)&&i){const t=s.firstChild.firstChild;this.isPartOfAToggle(t)||(this.setAttributesToNewBlock(e),this.itemsId[e]=o.id)}}}createToggleWithShortcut(t){const e=t.textContent;if(">"===e[0]&&!this.isPartOfAToggle(t)){const t=this.api.blocks.getCurrentBlockIndex();this.api.blocks.insert("toggle",{text:e.slice(2)},this.api,t,!0),this.api.blocks.delete(t+1),this.api.caret.setToBlock(t)}}nestBlock(t){const e=t.parentElement.parentElement,o=e.previousElementSibling,s=o.firstChild.firstChild;if(this.isPartOfAToggle(s)||this.isPartOfAToggle(o)){const t=o.getAttribute("foreignKey"),i=s.getAttribute("id"),r=t||i;e.setAttribute("will-be-a-nested-block",!0),document.getElementById(r).children[1].focus()}}setNestedBlockAttributes(){const t=this.api.blocks.getCurrentBlockIndex(),e=this.api.blocks.getBlockByIndex(t),{holder:o}=e;o.getAttribute("will-be-a-nested-block")&&(o.removeAttribute("will-be-a-nested-block"),this.setAttributesToNewBlock(t),this.api.toolbar.close())}isPartOfAToggle(t){const e=Array.from(t.classList);return e.includes("toggle-block__item")||e.includes("toggle-block__input")||e.includes("toggle-block__selector")}}})(),s.default})()})); |
{ | ||
"name": "editorjs-toggle-block", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Toogle block tool for Editor.js", | ||
@@ -48,2 +48,3 @@ "main": "./dist/bundle.js", | ||
"svg-inline-loader": "^0.8.2", | ||
"typescript": "^4.7.4", | ||
"webpack": "^5.66.0", | ||
@@ -61,3 +62,6 @@ "webpack-cli": "^4.9.1" | ||
} | ||
}, | ||
"dependencies": { | ||
"uuid": "^8.3.2" | ||
} | ||
} |
import './index.css'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import toggleIcon from '../assets/toggleIcon.svg'; | ||
@@ -57,3 +58,3 @@ | ||
status: data.status || 'open', | ||
fk: data.fk || `fk-${crypto.randomUUID()}`, | ||
fk: data.fk || `fk-${uuidv4()}`, | ||
items: data.items || 0, | ||
@@ -136,3 +137,3 @@ }; | ||
const index = entryIndex === null ? this.api.blocks.getCurrentBlockIndex() : entryIndex; | ||
const id = crypto.randomUUID(); | ||
const id = uuidv4(); | ||
@@ -139,0 +140,0 @@ const newBlock = this.api.blocks.getBlockByIndex(index); |
@@ -0,1 +1,3 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
export function getHiddenAttribute(redactor) { | ||
@@ -11,3 +13,3 @@ const children = redactor.querySelectorAll('div[hidden="true"]'); | ||
newBlock.setAttribute('foreignKey', toggleBlock.wrapper.id); | ||
newBlock.setAttribute('id', crypto.randomUUID()); | ||
newBlock.setAttribute('id', uuidv4()); | ||
@@ -131,3 +133,3 @@ if (toggleBlock.data.status === 'closed') { | ||
block.setAttribute('foreignKey', toggle.id); | ||
block.setAttribute('id', crypto.randomUUID()); | ||
block.setAttribute('id', uuidv4()); | ||
@@ -134,0 +136,0 @@ content.classList.add('toggle-block__item'); |
@@ -10,4 +10,2 @@ import ToggleBlock from '../src'; | ||
global.crypto = require('crypto'); | ||
describe('ToggleBlock', () => { | ||
@@ -14,0 +12,0 @@ let toggleBlock; |
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
1204262
1503
1
17
+ Addeduuid@^8.3.2
+ Addeduuid@8.3.2(transitive)