diff --git a/README.md b/README.md index b6cb1799..7b0fe507 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,22 @@ monsieurbiz_sylius_richeditor: tags: ['product'] ``` +### Deactivate an available element + +Here is what really happens when deactivating an Ui Element: +- it's not displayed anymore in frontend +- it's still editable in backend for old contents but you can't add a new one +- if the element has an alias, the alias is treated the same way + +Define the overload of a proposed UiElement in your configuration folder, let's say in `config/packages/monsieurbiz_sylius_richeditor_plugin.yaml` as example. + +```yaml +monsieurbiz_sylius_richeditor: + ui_elements: + monsieurbiz.youtube: + enabled: false +``` + ## Available elements The plugin already contains some simple elements. diff --git a/assets/js/app.js b/assets/js/app.js index fe358f7f..7d08b88a 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -275,7 +275,8 @@ global.MonsieurBizRichEditorManager = class { elementWrapper.innerHTML = Mustache.render(this.config.elementHtml, { 'title': element.title, 'icon': element.icon, - 'preview': element.previewHtml + 'preview': element.previewHtml, + 'disabled': !element.enabled }); let uiElement = elementWrapper.firstElementChild; uiElement.element = element; @@ -340,7 +341,10 @@ global.MonsieurBizRichEditorManager = class { let cardsContainer = this.selectionPanel.dialog.querySelector('.js-uie-cards-container'); cardsContainer.innerHTML = ''; for (let elementCode in this.config.uielements) { - if (this.config.uielements[elementCode].ignored) { // duplicates using aliases + if ( + this.config.uielements[elementCode].ignored // duplicates using aliases + || !this.config.uielements[elementCode].enabled // avoid disabled elements to show up! + ) { continue; } if (this.tags.length > 0) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index db28c3bd..f5f24d1e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -59,6 +59,7 @@ private function addUiElements(ArrayNodeDefinition $rootNode): void ->scalarNode('description')->isRequired()->cannotBeEmpty()->end() ->scalarNode('alias')->end() ->scalarNode('icon')->isRequired()->cannotBeEmpty()->end() + ->booleanNode('enabled')->defaultTrue()->end() ->arrayNode('classes') ->addDefaultsIfNotSet() ->children() diff --git a/src/Resources/public/js/rich-editor-js.js b/src/Resources/public/js/rich-editor-js.js index 73813cd6..6e35cd00 100644 --- a/src/Resources/public/js/rich-editor-js.js +++ b/src/Resources/public/js/rich-editor-js.js @@ -2,4 +2,4 @@ /*! * mustache.js - Logic-less {{mustache}} templates with JavaScript * http://github.com/janl/mustache.js - */var e=Object.prototype.toString,t=Array.isArray||function(t){return"[object Array]"===e.call(t)};function i(e){return"function"==typeof e}function n(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(e,t){return null!=e&&"object"==typeof e&&t in e}var s=RegExp.prototype.test,o=/\S/;function a(e){return!function(e,t){return s.call(e,t)}(o,e)}var l={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},c=/\s*/,u=/\s+/,h=/\s*=/,d=/\s*\}/,f=/#|\^|\/|>|\{|&|=|!/;function p(e){this.string=e,this.tail=e,this.pos=0}function m(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function g(){this.templateCache={_cache:{},set:function(e,t){this._cache[e]=t},get:function(e){return this._cache[e]},clear:function(){this._cache={}}}}p.prototype.eos=function(){return""===this.tail},p.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var i=t[0];return this.tail=this.tail.substring(i.length),this.pos+=i.length,i},p.prototype.scanUntil=function(e){var t,i=this.tail.search(e);switch(i){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,i),this.tail=this.tail.substring(i)}return this.pos+=t.length,t},m.prototype.push=function(e){return new m(e,this)},m.prototype.lookup=function(e){var t,n,s,o=this.cache;if(o.hasOwnProperty(e))t=o[e];else{for(var a,l,c,u=this,h=!1;u;){if(e.indexOf(".")>0)for(a=u.view,l=e.split("."),c=0;null!=a&&c0?r[r.length-1][4]:i;break;default:n.push(t)}return i}(function(e){for(var t,i,n=[],r=0,s=e.length;r"===o?a=this.renderPartial(s,t,i,r):"&"===o?a=this.unescapedValue(s,t):"name"===o?a=this.escapedValue(s,t):"text"===o&&(a=this.rawValue(s)),void 0!==a&&(l+=a);return l},g.prototype.renderSection=function(e,n,r,s){var o=this,a="",l=n.lookup(e[1]);if(l){if(t(l))for(var c=0,u=l.length;c0||!i)&&(r[s]=n+r[s]);return r.join("\n")},g.prototype.renderPartial=function(e,t,n,r){if(n){var s=i(n)?n(e[1]):n[e[1]];if(null!=s){var o=e[6],a=e[5],l=e[4],c=s;return 0==a&&l&&(c=this.indentPartial(s,l,o)),this.renderTokens(this.parse(c,r),t,n,c,r)}}},g.prototype.unescapedValue=function(e,t){var i=t.lookup(e[1]);if(null!=i)return i},g.prototype.escapedValue=function(e,t){var i=t.lookup(e[1]);if(null!=i)return v.escape(i)},g.prototype.rawValue=function(e){return e[1]};var v={name:"mustache.js",version:"4.0.1",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(e){y.templateCache=e},get templateCache(){return y.templateCache}},y=new g;return v.clearCache=function(){return y.clearCache()},v.parse=function(e,t){return y.parse(e,t)},v.render=function(e,i,n,r){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string" but "'+(t(s=e)?"array":typeof s)+'" was given as the first argument for mustache#render(template, view, partials)');var s;return y.render(e,i,n,r)},v.escape=function(e){return String(e).replace(/[&<>"'`=\/]/g,(function(e){return l[e]}))},v.Scanner=p,v.Context=m,v.Writer=g,v}()},mf8f:function(e,t,i){"use strict";var n={documentSelector:".js-document",documentDisabledClass:"is-disabled",openingTriggerActiveClass:"is-active",delay:200},r=['[href]:not([tabindex^="-"])','input:not([disabled]):not([type="hidden"]):not([tabindex^="-"]):not([type="radio"])','input[type="radio"]:checked','select:not([disabled]):not([tabindex^="-"])','textarea:not([disabled]):not([tabindex^="-"])','button:not([disabled]):not([tabindex^="-"])','[tabindex]:not([tabindex^="-"])','[contenteditable="true"]:not([tabindex^="-"])'],s="Escape",o="Tab",a="F6";function l(e,t){let i=e;for(;i!==t&&i;)i=i.parentNode;return!!i}const c=Symbol("onClick"),u=Symbol("onKeydown"),h=Symbol("addEventDelegation"),d=Symbol("addEventListeners"),f=Symbol("removeEventListeners"),p=Symbol("addAttributes"),m=Symbol("removeAttributes"),g=Symbol("setAttributes"),v=Symbol("setFocusableElements"),y=Symbol("setFocus"),b=Symbol("restoreFocus"),E=Symbol("switchFocus"),w=Symbol("maintainFocus"),k=Symbol("addObserver"),S=Symbol("removeObserver");let T=n;t.a=class{constructor(e,{onOpen:t=(()=>{}),onClose:i=(()=>{}),openingSelector:n,closingSelector:r,backdropSelector:s,helperSelector:o,labelledby:a,describedby:l,isModal:d=!0,isTooltip:f=!1,isOpen:p=!1,isCreated:m=!0,disableScroll:g=!0,enableAutoFocus:y=!0,openingTriggerActiveClass:b=T.openingTriggerActiveClass,delay:w=T.delay}={}){document.querySelector(e)?(this.config={dialogSelector:e,onOpen:t,onClose:i,openingSelector:n,closingSelector:r,backdropSelector:s,helperSelector:o,labelledby:a,describedby:l,isModal:d,isTooltip:f,isCreated:m,isOpen:p,disableScroll:g,enableAutoFocus:y,documentSelector:T.documentSelector,documentDisabledClass:T.documentDisabledClass,openingTriggerActiveClass:b,delay:w},this.dialog=document.querySelector(e),this.dialogArea=`${e}, ${n}`,this.openingTriggers=document.querySelectorAll(n),this.backdropTrigger=document.querySelector(s),this.helpers=document.querySelectorAll(o),this.document=document.querySelector(this.config.documentSelector)||document.querySelector("html"),this.documentIsAlreadyDisabled=!1,this.focusableElements=[],this.firstFocusableElement=null,this.lastFocusableElement=null,this.openingTrigger=null,this.closingTrigger=null,this.isCreated=!1,this.isOpen=!1,this.close=this.close.bind(this),this.toggle=this.toggle.bind(this),this[c]=this[c].bind(this),this[u]=this[u].bind(this),this[h]=this[h].bind(this),this[E]=this[E].bind(this),this.observer=new MutationObserver(e=>e.forEach(()=>this[v]())),this.isInitialized=!0,m&&this.create()):this.isInitialized=!1}[c](e){this.config.isTooltip&&!e.target.closest(this.dialogArea)&&this.close(e),e.target===this.backdropTrigger&&this.close(e)}[u](e){switch(e.key){case s:e.stopPropagation(),this.close(e);break;case a:this.config.isModal||(this.config.isTooltip?this.close(e):this[b]());break;case o:this[w](e)}}[h](e){document.querySelectorAll(this.config.openingSelector).forEach(t=>{l(e.target,t)&&(this.openingTrigger=t,this.toggle(e))}),document.querySelectorAll(this.config.closingSelector).forEach(t=>{l(e.target,t)&&(this.closingTrigger=t,this.close())})}[d](){document.addEventListener("click",this[c],{capture:!0}),this.dialog.addEventListener("keydown",this[u])}[f](){document.removeEventListener("click",this[c],{capture:!0}),this.dialog.removeEventListener("keydown",this[u]),this.openingTrigger&&this.openingTrigger.removeEventListener("keydown",this[E])}[p](){this.dialog.setAttribute("role","dialog"),this.dialog.setAttribute("tabindex",-1),this.dialog.setAttribute("aria-hidden",!0),this.config.labelledby&&this.dialog.setAttribute("aria-labelledby",this.config.labelledby),this.config.describedby&&this.dialog.setAttribute("aria-describedby",this.config.describedby),this.config.isModal&&this.dialog.setAttribute("aria-modal",!0),this.openingTriggers.forEach(e=>e.setAttribute("aria-haspopup","dialog"))}[m](){this.dialog.removeAttribute("role"),this.dialog.removeAttribute("tabindex"),this.dialog.removeAttribute("aria-hidden"),this.dialog.removeAttribute("aria-labelledby"),this.dialog.removeAttribute("aria-describedby"),this.dialog.removeAttribute("aria-modal"),this.config.disableScroll&&this.isOpen&&!this.documentIsAlreadyDisabled&&this.document.classList.remove(this.config.documentDisabledClass),this.openingTriggers.forEach(e=>e.removeAttribute("aria-haspopup")),this.openingTrigger&&this.openingTrigger.classList.remove(this.config.openingTriggerActiveClass),this.helpers.forEach(e=>e.classList.remove(this.config.openingTriggerActiveClass))}[g](){this.dialog.setAttribute("aria-hidden",!this.isOpen),this.config.disableScroll&&!this.documentIsAlreadyDisabled&&(this.isOpen?this.document.classList.add(this.config.documentDisabledClass):this.document.classList.remove(this.config.documentDisabledClass)),this.openingTrigger&&(this.isOpen?this.openingTrigger.classList.add(this.config.openingTriggerActiveClass):this.openingTrigger.classList.remove(this.config.openingTriggerActiveClass)),this.helpers.forEach(e=>{this.isOpen?e.classList.add(this.config.openingTriggerActiveClass):e.classList.remove(this.config.openingTriggerActiveClass)})}[v](){const e=function(e){const t=[];return e.forEach(e=>{const i=e.getBoundingClientRect();(i.width>0||i.height>0)&&t.push(e)}),t}(this.dialog.querySelectorAll(r)),t=function(e,t,i){const n=e.querySelectorAll(t),r=[];let s=!1;return 0===n.length?i:(i.forEach(e=>{n.forEach(t=>{t.contains(e)&&(s=!0)}),s||r.push(e),s=!1}),r)}(this.dialog,'[role="dialog"]',e);this.focusableElements=t.length>0?t:[this.dialog],[this.firstFocusableElement]=this.focusableElements,this.lastFocusableElement=this.focusableElements[this.focusableElements.length-1]}[y](){this.config.enableAutoFocus&&window.setTimeout(()=>this.firstFocusableElement.focus(),this.config.delay)}[b](){this.config.enableAutoFocus&&window.setTimeout(()=>this.openingTrigger.focus(),this.config.delay),this.isOpen&&this.openingTrigger.addEventListener("keydown",this[E])}[E](e){e.key===a&&(this.openingTrigger.removeEventListener("keydown",this[E]),this[y]())}[w](e){e.shiftKey&&e.target===this.firstFocusableElement&&(e.preventDefault(),this.lastFocusableElement.focus()),e.shiftKey||e.target!==this.lastFocusableElement||(e.preventDefault(),this.firstFocusableElement.focus())}[k](){this.observer.observe(this.dialog,{childList:!0,attributes:!0,subtree:!0})}[S](){this.observer.disconnect()}open(){this.isInitialized&&this.isCreated&&!this.isOpen&&(this.isOpen=!0,this.documentIsAlreadyDisabled=this.document.classList.contains(this.config.documentDisabledClass),this[g](),this[d](),this[y](),this.config.onOpen(this.dialog,this.openingTrigger))}close(e){this.isInitialized&&this.isCreated&&this.isOpen&&(this.isOpen=!1,e&&e.preventDefault(),this[g](),this[f](),this.openingTrigger&&(!this.config.isTooltip||this.config.isTooltip&&e&&"click"!==e.type)&&this[b](),this.config.onClose(this.dialog,this.closingTrigger))}toggle(e){this.isInitialized&&this.isCreated&&(e&&e.preventDefault(),this.isOpen?this.close():this.open())}create(){this.isInitialized&&!this.isCreated&&(this.isCreated=!0,this[p](),this[v](),this[k](),this.config.isOpen&&this.open(),document.addEventListener("click",this[h],{capture:!0}))}destroy(){this.isInitialized&&this.isCreated&&(this.close(),this.isCreated=!1,this[m](),this[f](),this[S](),document.removeEventListener("click",this[h],{capture:!0}))}}},ng4s:function(e,t,i){"use strict";i.r(t),function(e){var t=i("P50k"),n=i.n(t),r=i("mf8f"),s=i("W4wD"),o=i.n(s);function a(e,t){var i;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(i=function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);"Object"===i&&e.constructor&&(i=e.constructor.name);if("Map"===i||"Set"===i)return Array.from(e);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return l(e,t)}(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,o=!0,a=!1;return{s:function(){i=e[Symbol.iterator]()},n:function(){var e=i.next();return o=e.done,e},e:function(e){a=!0,s=e},f:function(){try{o||null==i.return||i.return()}finally{if(a)throw s}}}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i0){for(var n in this.tags)if(0<=this.config.uielements[i].tags.indexOf(this.tags[n])){t.append(this.getNewUiElementCard(this.config.uielements[i],e));break}}else t.append(this.getNewUiElementCard(this.config.uielements[i],e));this.newPanel.close(),this.selectionPanel.open()}},{key:"drawNewForm",value:function(e,t){this.newPanel.dialog.innerHTML=e;var i=this.newPanel.dialog;this.wysiwyg.load(i),this.dispatchInitFormEvent(i);var n=i.querySelector("form");n.manager=this,n.position=t,n.addEventListener("submit",(function(e){e.preventDefault();var t=e.currentTarget;return t.manager.submitUiElementForm(t,(function(){if(200===this.status){var e=JSON.parse(this.responseText);e.error?this.form.manager.drawNewForm(e.form_html,this.form.position):(this.form.manager.create(e.code,e.data,e.previewHtml,this.form.position),this.form.manager.newPanel.close(),this.form.manager.selectionPanel.close())}})),!1}));var r=i.querySelector(".js-uie-cancel");r.panel=this.newPanel,r.addEventListener("click",(function(e){e.currentTarget.panel.close()}));var s=i.querySelector(".js-uie-save");s.panel=this.newPanel,s.addEventListener("click",(function(e){e.currentTarget.panel.dialog.querySelector("form").dispatchEvent(new Event("submit",{cancelable:!0}))}))}},{key:"openNewPanel",value:function(e,t,i){this.newPanel.dialog.manager=this,this.newPanel.dialog.position=i,this.drawNewForm(e,i),this.newPanel.open()}},{key:"editUiElement",value:function(e){this.loadUiElementEditForm(e,(function(t){if(200===this.status){var i=JSON.parse(this.responseText);e.manager.openEditPanel(i.form_html,e)}}))}},{key:"drawEditForm",value:function(e,t){this.editPanel.dialog.querySelector(".js-uie-content").innerHTML=e;var i=this.editPanel.dialog;this.wysiwyg.load(i),this.dispatchInitFormEvent(i);var n=i.querySelector("form");n.manager=this,n.uiElement=t,n.addEventListener("submit",(function(e){e.preventDefault();var t=e.currentTarget;return t.manager.submitUiElementForm(t,(function(){if(200===this.status){var e=JSON.parse(this.responseText);e.error?this.form.manager.drawEditForm(e.form_html,this.form.uiElement):(this.form.uiElement.data=e.data,this.form.uiElement.previewHtml=e.previewHtml,this.form.manager.write(),this.form.manager.editPanel.close())}})),!1}));var r=i.querySelector(".js-uie-cancel");r.panel=this.editPanel,r.addEventListener("click",(function(e){e.currentTarget.panel.close()}));var s=i.querySelector(".js-uie-save");s.panel=this.editPanel,s.addEventListener("click",(function(e){e.currentTarget.panel.dialog.querySelector("form").dispatchEvent(new Event("submit",{cancelable:!0}))}))}},{key:"openEditPanel",value:function(e,t){this.editPanel.dialog.manager=this,this.editPanel.dialog.uiElement=t,this.drawEditForm(e,t),this.editPanel.open()}},{key:"write",value:function(){this.input.value=this.uiElements.length>0?JSON.stringify(this.uiElements):"",this.drawUiElements()}},{key:"create",value:function(e,t,i,n){var r=new MonsieurBizRichEditorUiElement(this.config,e,t,i);return this.uiElements.splice(n,0,r),this.write(),r}},{key:"moveUp",value:function(e){var t=this.uiElements.indexOf(e);0!==t&&(this.uiElements.splice(t,1),this.uiElements.splice(t-1,0,e),this.write())}},{key:"moveDown",value:function(e){var t=this.uiElements.indexOf(e);t!==this.uiElements.length-1&&(this.uiElements.splice(t,1),this.uiElements.splice(t+1,0,e),this.write())}},{key:"delete",value:function(e){var t=this.uiElements.indexOf(e);this.uiElements.splice(t,1),this.write()}},{key:"loadUiElementCreateForm",value:function(e,t){var i=new XMLHttpRequest;i.onload=t;var n=this.config.createElementFormUrl;i.open("get",n.replace("__CODE__",e.code),!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send()}},{key:"loadUiElementEditForm",value:function(e,t){var i=new XMLHttpRequest;i.onload=t;var n=this.config.editElementFormUrl;i.open("post",n.replace("__CODE__",e.code),!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),i.send(new URLSearchParams({data:JSON.stringify(e.data)}).toString())}},{key:"submitUiElementForm",value:function(e,t){var i=new XMLHttpRequest;i.onload=t,i.form=e,i.open("post",e.action,!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(new FormData(e))}},{key:"requestUiElementsHtml",value:function(e,t){var i=new XMLHttpRequest;i.onload=t,i.open("post",this.config.renderElementsUrl,!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest");var n=new FormData;n.append("ui_elements",JSON.stringify(e)),i.uiElements=e,i.manager=this,i.send(n)}},{key:"dispatchInitFormEvent",value:function(e){document.dispatchEvent(new CustomEvent("monsieurBizRichEditorInitForm",{detail:{form:e}}))}},{key:"input",get:function(){return this.config.input}},{key:"wysiwyg",get:function(){return this.config.wysiwyg}}]),e}()}.call(this,i("2mad"))}}); \ No newline at end of file + */var e=Object.prototype.toString,t=Array.isArray||function(t){return"[object Array]"===e.call(t)};function i(e){return"function"==typeof e}function n(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(e,t){return null!=e&&"object"==typeof e&&t in e}var s=RegExp.prototype.test,o=/\S/;function a(e){return!function(e,t){return s.call(e,t)}(o,e)}var l={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},c=/\s*/,u=/\s+/,h=/\s*=/,d=/\s*\}/,f=/#|\^|\/|>|\{|&|=|!/;function p(e){this.string=e,this.tail=e,this.pos=0}function m(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function g(){this.templateCache={_cache:{},set:function(e,t){this._cache[e]=t},get:function(e){return this._cache[e]},clear:function(){this._cache={}}}}p.prototype.eos=function(){return""===this.tail},p.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var i=t[0];return this.tail=this.tail.substring(i.length),this.pos+=i.length,i},p.prototype.scanUntil=function(e){var t,i=this.tail.search(e);switch(i){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,i),this.tail=this.tail.substring(i)}return this.pos+=t.length,t},m.prototype.push=function(e){return new m(e,this)},m.prototype.lookup=function(e){var t,n,s,o=this.cache;if(o.hasOwnProperty(e))t=o[e];else{for(var a,l,c,u=this,h=!1;u;){if(e.indexOf(".")>0)for(a=u.view,l=e.split("."),c=0;null!=a&&c0?r[r.length-1][4]:i;break;default:n.push(t)}return i}(function(e){for(var t,i,n=[],r=0,s=e.length;r"===o?a=this.renderPartial(s,t,i,r):"&"===o?a=this.unescapedValue(s,t):"name"===o?a=this.escapedValue(s,t):"text"===o&&(a=this.rawValue(s)),void 0!==a&&(l+=a);return l},g.prototype.renderSection=function(e,n,r,s){var o=this,a="",l=n.lookup(e[1]);if(l){if(t(l))for(var c=0,u=l.length;c0||!i)&&(r[s]=n+r[s]);return r.join("\n")},g.prototype.renderPartial=function(e,t,n,r){if(n){var s=i(n)?n(e[1]):n[e[1]];if(null!=s){var o=e[6],a=e[5],l=e[4],c=s;return 0==a&&l&&(c=this.indentPartial(s,l,o)),this.renderTokens(this.parse(c,r),t,n,c,r)}}},g.prototype.unescapedValue=function(e,t){var i=t.lookup(e[1]);if(null!=i)return i},g.prototype.escapedValue=function(e,t){var i=t.lookup(e[1]);if(null!=i)return v.escape(i)},g.prototype.rawValue=function(e){return e[1]};var v={name:"mustache.js",version:"4.0.1",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(e){y.templateCache=e},get templateCache(){return y.templateCache}},y=new g;return v.clearCache=function(){return y.clearCache()},v.parse=function(e,t){return y.parse(e,t)},v.render=function(e,i,n,r){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string" but "'+(t(s=e)?"array":typeof s)+'" was given as the first argument for mustache#render(template, view, partials)');var s;return y.render(e,i,n,r)},v.escape=function(e){return String(e).replace(/[&<>"'`=\/]/g,(function(e){return l[e]}))},v.Scanner=p,v.Context=m,v.Writer=g,v}()},mf8f:function(e,t,i){"use strict";var n={documentSelector:".js-document",documentDisabledClass:"is-disabled",openingTriggerActiveClass:"is-active",delay:200},r=['[href]:not([tabindex^="-"])','input:not([disabled]):not([type="hidden"]):not([tabindex^="-"]):not([type="radio"])','input[type="radio"]:checked','select:not([disabled]):not([tabindex^="-"])','textarea:not([disabled]):not([tabindex^="-"])','button:not([disabled]):not([tabindex^="-"])','[tabindex]:not([tabindex^="-"])','[contenteditable="true"]:not([tabindex^="-"])'],s="Escape",o="Tab",a="F6";function l(e,t){let i=e;for(;i!==t&&i;)i=i.parentNode;return!!i}const c=Symbol("onClick"),u=Symbol("onKeydown"),h=Symbol("addEventDelegation"),d=Symbol("addEventListeners"),f=Symbol("removeEventListeners"),p=Symbol("addAttributes"),m=Symbol("removeAttributes"),g=Symbol("setAttributes"),v=Symbol("setFocusableElements"),y=Symbol("setFocus"),b=Symbol("restoreFocus"),E=Symbol("switchFocus"),w=Symbol("maintainFocus"),k=Symbol("addObserver"),S=Symbol("removeObserver");let T=n;t.a=class{constructor(e,{onOpen:t=(()=>{}),onClose:i=(()=>{}),openingSelector:n,closingSelector:r,backdropSelector:s,helperSelector:o,labelledby:a,describedby:l,isModal:d=!0,isTooltip:f=!1,isOpen:p=!1,isCreated:m=!0,disableScroll:g=!0,enableAutoFocus:y=!0,openingTriggerActiveClass:b=T.openingTriggerActiveClass,delay:w=T.delay}={}){document.querySelector(e)?(this.config={dialogSelector:e,onOpen:t,onClose:i,openingSelector:n,closingSelector:r,backdropSelector:s,helperSelector:o,labelledby:a,describedby:l,isModal:d,isTooltip:f,isCreated:m,isOpen:p,disableScroll:g,enableAutoFocus:y,documentSelector:T.documentSelector,documentDisabledClass:T.documentDisabledClass,openingTriggerActiveClass:b,delay:w},this.dialog=document.querySelector(e),this.dialogArea=`${e}, ${n}`,this.openingTriggers=document.querySelectorAll(n),this.backdropTrigger=document.querySelector(s),this.helpers=document.querySelectorAll(o),this.document=document.querySelector(this.config.documentSelector)||document.querySelector("html"),this.documentIsAlreadyDisabled=!1,this.focusableElements=[],this.firstFocusableElement=null,this.lastFocusableElement=null,this.openingTrigger=null,this.closingTrigger=null,this.isCreated=!1,this.isOpen=!1,this.close=this.close.bind(this),this.toggle=this.toggle.bind(this),this[c]=this[c].bind(this),this[u]=this[u].bind(this),this[h]=this[h].bind(this),this[E]=this[E].bind(this),this.observer=new MutationObserver(e=>e.forEach(()=>this[v]())),this.isInitialized=!0,m&&this.create()):this.isInitialized=!1}[c](e){this.config.isTooltip&&!e.target.closest(this.dialogArea)&&this.close(e),e.target===this.backdropTrigger&&this.close(e)}[u](e){switch(e.key){case s:e.stopPropagation(),this.close(e);break;case a:this.config.isModal||(this.config.isTooltip?this.close(e):this[b]());break;case o:this[w](e)}}[h](e){document.querySelectorAll(this.config.openingSelector).forEach(t=>{l(e.target,t)&&(this.openingTrigger=t,this.toggle(e))}),document.querySelectorAll(this.config.closingSelector).forEach(t=>{l(e.target,t)&&(this.closingTrigger=t,this.close())})}[d](){document.addEventListener("click",this[c],{capture:!0}),this.dialog.addEventListener("keydown",this[u])}[f](){document.removeEventListener("click",this[c],{capture:!0}),this.dialog.removeEventListener("keydown",this[u]),this.openingTrigger&&this.openingTrigger.removeEventListener("keydown",this[E])}[p](){this.dialog.setAttribute("role","dialog"),this.dialog.setAttribute("tabindex",-1),this.dialog.setAttribute("aria-hidden",!0),this.config.labelledby&&this.dialog.setAttribute("aria-labelledby",this.config.labelledby),this.config.describedby&&this.dialog.setAttribute("aria-describedby",this.config.describedby),this.config.isModal&&this.dialog.setAttribute("aria-modal",!0),this.openingTriggers.forEach(e=>e.setAttribute("aria-haspopup","dialog"))}[m](){this.dialog.removeAttribute("role"),this.dialog.removeAttribute("tabindex"),this.dialog.removeAttribute("aria-hidden"),this.dialog.removeAttribute("aria-labelledby"),this.dialog.removeAttribute("aria-describedby"),this.dialog.removeAttribute("aria-modal"),this.config.disableScroll&&this.isOpen&&!this.documentIsAlreadyDisabled&&this.document.classList.remove(this.config.documentDisabledClass),this.openingTriggers.forEach(e=>e.removeAttribute("aria-haspopup")),this.openingTrigger&&this.openingTrigger.classList.remove(this.config.openingTriggerActiveClass),this.helpers.forEach(e=>e.classList.remove(this.config.openingTriggerActiveClass))}[g](){this.dialog.setAttribute("aria-hidden",!this.isOpen),this.config.disableScroll&&!this.documentIsAlreadyDisabled&&(this.isOpen?this.document.classList.add(this.config.documentDisabledClass):this.document.classList.remove(this.config.documentDisabledClass)),this.openingTrigger&&(this.isOpen?this.openingTrigger.classList.add(this.config.openingTriggerActiveClass):this.openingTrigger.classList.remove(this.config.openingTriggerActiveClass)),this.helpers.forEach(e=>{this.isOpen?e.classList.add(this.config.openingTriggerActiveClass):e.classList.remove(this.config.openingTriggerActiveClass)})}[v](){const e=function(e){const t=[];return e.forEach(e=>{const i=e.getBoundingClientRect();(i.width>0||i.height>0)&&t.push(e)}),t}(this.dialog.querySelectorAll(r)),t=function(e,t,i){const n=e.querySelectorAll(t),r=[];let s=!1;return 0===n.length?i:(i.forEach(e=>{n.forEach(t=>{t.contains(e)&&(s=!0)}),s||r.push(e),s=!1}),r)}(this.dialog,'[role="dialog"]',e);this.focusableElements=t.length>0?t:[this.dialog],[this.firstFocusableElement]=this.focusableElements,this.lastFocusableElement=this.focusableElements[this.focusableElements.length-1]}[y](){this.config.enableAutoFocus&&window.setTimeout(()=>this.firstFocusableElement.focus(),this.config.delay)}[b](){this.config.enableAutoFocus&&window.setTimeout(()=>this.openingTrigger.focus(),this.config.delay),this.isOpen&&this.openingTrigger.addEventListener("keydown",this[E])}[E](e){e.key===a&&(this.openingTrigger.removeEventListener("keydown",this[E]),this[y]())}[w](e){e.shiftKey&&e.target===this.firstFocusableElement&&(e.preventDefault(),this.lastFocusableElement.focus()),e.shiftKey||e.target!==this.lastFocusableElement||(e.preventDefault(),this.firstFocusableElement.focus())}[k](){this.observer.observe(this.dialog,{childList:!0,attributes:!0,subtree:!0})}[S](){this.observer.disconnect()}open(){this.isInitialized&&this.isCreated&&!this.isOpen&&(this.isOpen=!0,this.documentIsAlreadyDisabled=this.document.classList.contains(this.config.documentDisabledClass),this[g](),this[d](),this[y](),this.config.onOpen(this.dialog,this.openingTrigger))}close(e){this.isInitialized&&this.isCreated&&this.isOpen&&(this.isOpen=!1,e&&e.preventDefault(),this[g](),this[f](),this.openingTrigger&&(!this.config.isTooltip||this.config.isTooltip&&e&&"click"!==e.type)&&this[b](),this.config.onClose(this.dialog,this.closingTrigger))}toggle(e){this.isInitialized&&this.isCreated&&(e&&e.preventDefault(),this.isOpen?this.close():this.open())}create(){this.isInitialized&&!this.isCreated&&(this.isCreated=!0,this[p](),this[v](),this[k](),this.config.isOpen&&this.open(),document.addEventListener("click",this[h],{capture:!0}))}destroy(){this.isInitialized&&this.isCreated&&(this.close(),this.isCreated=!1,this[m](),this[f](),this[S](),document.removeEventListener("click",this[h],{capture:!0}))}}},ng4s:function(e,t,i){"use strict";i.r(t),function(e){var t=i("P50k"),n=i.n(t),r=i("mf8f"),s=i("W4wD"),o=i.n(s);function a(e,t){var i;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(i=function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);"Object"===i&&e.constructor&&(i=e.constructor.name);if("Map"===i||"Set"===i)return Array.from(e);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return l(e,t)}(e))||t&&e&&"number"==typeof e.length){i&&(e=i);var n=0,r=function(){};return{s:r,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,o=!0,a=!1;return{s:function(){i=e[Symbol.iterator]()},n:function(){var e=i.next();return o=e.done,e},e:function(e){a=!0,s=e},f:function(){try{o||null==i.return||i.return()}finally{if(a)throw s}}}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i0){for(var n in this.tags)if(0<=this.config.uielements[i].tags.indexOf(this.tags[n])){t.append(this.getNewUiElementCard(this.config.uielements[i],e));break}}else t.append(this.getNewUiElementCard(this.config.uielements[i],e));this.newPanel.close(),this.selectionPanel.open()}},{key:"drawNewForm",value:function(e,t){this.newPanel.dialog.innerHTML=e;var i=this.newPanel.dialog;this.wysiwyg.load(i),this.dispatchInitFormEvent(i);var n=i.querySelector("form");n.manager=this,n.position=t,n.addEventListener("submit",(function(e){e.preventDefault();var t=e.currentTarget;return t.manager.submitUiElementForm(t,(function(){if(200===this.status){var e=JSON.parse(this.responseText);e.error?this.form.manager.drawNewForm(e.form_html,this.form.position):(this.form.manager.create(e.code,e.data,e.previewHtml,this.form.position),this.form.manager.newPanel.close(),this.form.manager.selectionPanel.close())}})),!1}));var r=i.querySelector(".js-uie-cancel");r.panel=this.newPanel,r.addEventListener("click",(function(e){e.currentTarget.panel.close()}));var s=i.querySelector(".js-uie-save");s.panel=this.newPanel,s.addEventListener("click",(function(e){e.currentTarget.panel.dialog.querySelector("form").dispatchEvent(new Event("submit",{cancelable:!0}))}))}},{key:"openNewPanel",value:function(e,t,i){this.newPanel.dialog.manager=this,this.newPanel.dialog.position=i,this.drawNewForm(e,i),this.newPanel.open()}},{key:"editUiElement",value:function(e){this.loadUiElementEditForm(e,(function(t){if(200===this.status){var i=JSON.parse(this.responseText);e.manager.openEditPanel(i.form_html,e)}}))}},{key:"drawEditForm",value:function(e,t){this.editPanel.dialog.querySelector(".js-uie-content").innerHTML=e;var i=this.editPanel.dialog;this.wysiwyg.load(i),this.dispatchInitFormEvent(i);var n=i.querySelector("form");n.manager=this,n.uiElement=t,n.addEventListener("submit",(function(e){e.preventDefault();var t=e.currentTarget;return t.manager.submitUiElementForm(t,(function(){if(200===this.status){var e=JSON.parse(this.responseText);e.error?this.form.manager.drawEditForm(e.form_html,this.form.uiElement):(this.form.uiElement.data=e.data,this.form.uiElement.previewHtml=e.previewHtml,this.form.manager.write(),this.form.manager.editPanel.close())}})),!1}));var r=i.querySelector(".js-uie-cancel");r.panel=this.editPanel,r.addEventListener("click",(function(e){e.currentTarget.panel.close()}));var s=i.querySelector(".js-uie-save");s.panel=this.editPanel,s.addEventListener("click",(function(e){e.currentTarget.panel.dialog.querySelector("form").dispatchEvent(new Event("submit",{cancelable:!0}))}))}},{key:"openEditPanel",value:function(e,t){this.editPanel.dialog.manager=this,this.editPanel.dialog.uiElement=t,this.drawEditForm(e,t),this.editPanel.open()}},{key:"write",value:function(){this.input.value=this.uiElements.length>0?JSON.stringify(this.uiElements):"",this.drawUiElements()}},{key:"create",value:function(e,t,i,n){var r=new MonsieurBizRichEditorUiElement(this.config,e,t,i);return this.uiElements.splice(n,0,r),this.write(),r}},{key:"moveUp",value:function(e){var t=this.uiElements.indexOf(e);0!==t&&(this.uiElements.splice(t,1),this.uiElements.splice(t-1,0,e),this.write())}},{key:"moveDown",value:function(e){var t=this.uiElements.indexOf(e);t!==this.uiElements.length-1&&(this.uiElements.splice(t,1),this.uiElements.splice(t+1,0,e),this.write())}},{key:"delete",value:function(e){var t=this.uiElements.indexOf(e);this.uiElements.splice(t,1),this.write()}},{key:"loadUiElementCreateForm",value:function(e,t){var i=new XMLHttpRequest;i.onload=t;var n=this.config.createElementFormUrl;i.open("get",n.replace("__CODE__",e.code),!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send()}},{key:"loadUiElementEditForm",value:function(e,t){var i=new XMLHttpRequest;i.onload=t;var n=this.config.editElementFormUrl;i.open("post",n.replace("__CODE__",e.code),!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),i.send(new URLSearchParams({data:JSON.stringify(e.data)}).toString())}},{key:"submitUiElementForm",value:function(e,t){var i=new XMLHttpRequest;i.onload=t,i.form=e,i.open("post",e.action,!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(new FormData(e))}},{key:"requestUiElementsHtml",value:function(e,t){var i=new XMLHttpRequest;i.onload=t,i.open("post",this.config.renderElementsUrl,!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest");var n=new FormData;n.append("ui_elements",JSON.stringify(e)),i.uiElements=e,i.manager=this,i.send(n)}},{key:"dispatchInitFormEvent",value:function(e){document.dispatchEvent(new CustomEvent("monsieurBizRichEditorInitForm",{detail:{form:e}}))}},{key:"input",get:function(){return this.config.input}},{key:"wysiwyg",get:function(){return this.config.wysiwyg}}]),e}()}.call(this,i("2mad"))}}); \ No newline at end of file diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 1f47e75c..390e3bf5 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -119,3 +119,5 @@ monsieurbiz_richeditor_plugin: cannot_parse_json: 'Cannot parse the current content' cannot_find_type: 'Cannot find type for some UI Elements' cannot_upload_image: 'Cannot upload the image. The file may be too large or have incorrect format.' + ui: + disabled: 'Disabled' diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index ec4e901e..d7c97527 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -119,3 +119,5 @@ monsieurbiz_richeditor_plugin: cannot_parse_json: 'Impossible d''analyser le contenu actuel.' cannot_find_type: 'Impossible de trouver le type pour certains éléments' cannot_upload_file: 'Impossible de charger le fichier. Il est possible qu''il soit trop lourd ou son format incorrect.' + ui: + disabled: 'Désactivé' diff --git a/src/Resources/views/Admin/app.html.twig b/src/Resources/views/Admin/app.html.twig index dddc3218..e936d6be 100644 --- a/src/Resources/views/Admin/app.html.twig +++ b/src/Resources/views/Admin/app.html.twig @@ -20,6 +20,7 @@

{{title}} + {{#disabled}}{% endverbatim %}{{ 'monsieurbiz_richeditor_plugin.ui.disabled'|trans }}{% verbatim %}{{/disabled}}