@lesjoursfr/edith 2.2.3 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/edith.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("CodeMirror"),require("Popper")):"function"==typeof define&&define.amd?define(["CodeMirror","Popper"],e):"object"==typeof exports?exports.Edith=e(require("CodeMirror"),require("Popper")):t.Edith=e(t.CodeMirror,t.Popper)}(self,(function(t,e){return function(){"use strict";var n={690:function(e){e.exports=t},74:function(t){t.exports=e}},i={};function o(t){var e=i[t];if(void 0!==e)return e.exports;var s=i[t]={exports:{}};return n[t](s,s.exports,o),s.exports}o.d=function(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=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)};var s={};return function(){function t(t,e){return n(t)&&t.tagName===e.toUpperCase()}function e(t){return t.nodeType===Node.TEXT_NODE}function n(t){return t.nodeType===Node.ELEMENT_NODE}function i(t,e){return t.getAttribute(e)}function r(t,e){return"string"==typeof e?t.tagName===e.toUpperCase():e.some((e=>t.tagName===e.toUpperCase()))}function a(t,e){return t.classList.contains(e)}function c(t,{innerHTML:e,textContent:n,attributes:i}={}){const o=document.createElement(t);if(i)for(const t in i)Object.hasOwnProperty.call(i,t)&&o.setAttribute(t,i[t]);return"string"==typeof e?o.innerHTML=e:"string"==typeof n&&(o.textContent=n),o}function l(t,e){return t.replaceWith(e),e}function d(t){const e=[...t.childNodes];return t.replaceWith(...e),e}function h(t){const e=document.createTextNode(t.textContent??"");return t.replaceWith(e),e}function u(t){return["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"].includes(t)}function p(t,e){for(const n of[...t.childNodes])e(n)&&n.remove()}function f(t,e){if(e(t))t.remove();else for(const n of[...t.childNodes])f(n,e)}function m(t){p(t,(t=>function(t){return t.nodeType===Node.COMMENT_NODE}(t)))}function b(t,e){for(const n of t.getAttributeNames())void 0===e[n]&&t.removeAttribute(n);for(const n of Object.keys(e))t.setAttribute(n,e[n])}function g(t){const e=t.getAttribute("style")||"";return(r(t,"b")&&e.match(/font-weight\s*:\s*(normal|400);/)||r(t,"i")&&e.match(/font-style\s*:\s*normal;/)||r(t,["u","s"])&&e.match(/text-decoration\s*:\s*none;/))&&(t=l(t,c("span",{attributes:{style:e},innerHTML:t.innerHTML}))),e.match(/font-weight\s*:\s*(bold|700|800|900);/)?t=l(t,c("b",{innerHTML:`<span style="${e.replace(/font-weight\s*:\s*(bold|700|800|900);/,"")}">${t.innerHTML}</span>`})):e.match(/font-style\s*:\s*italic;/)?t=l(t,c("i",{innerHTML:`<span style="${e.replace(/font-style\s*:\s*italic;/,"")}">${t.innerHTML}</span>`})):e.match(/text-decoration\s*:\s*underline;/)?t=l(t,c("u",{innerHTML:`<span style="${e.replace(/text-decoration\s*:\s*underline;/,"")}">${t.innerHTML}</span>`})):e.match(/text-decoration\s*:\s*line-through;/)&&(t=l(t,c("s",{innerHTML:`<span style="${e.replace(/text-decoration\s*:\s*line-through;/,"")}">${t.innerHTML}</span>`}))),t}function v(e,n){const i=e.childNodes;for(;i.length>0&&t(i[0],n);)i[0].remove();for(;i.length>0&&t(i[i.length-1],n);)i[i.length-1].remove()}o.d(s,{default:function(){return Z}});let y=0;function E(t){const[e,...n]=t.split(".");return{type:e,ns:n??null}}function w(t,e,n){void 0===t.ljbtEvents&&(t.ljbtEvents={});for(const i of e.split(" ")){const{type:e,ns:o}=E(i),s=(++y).toString(10);t.addEventListener(e,n),t.ljbtEvents[s]={type:e,ns:o,handler:n}}}function C(t,e,n){void 0===t.ljbtEvents&&(t.ljbtEvents={});for(const i of e.split(" ")){const{type:e,ns:o}=E(i);for(const[i,s]of Object.entries(t.ljbtEvents))s.type!==e&&"*"!==e||null!==o&&!s.ns?.includes(o[0])||void 0!==n&&("function"!=typeof n||n!==s.handler)||(delete t.ljbtEvents[i],t.removeEventListener(s.type,s.handler))}}function x(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)t[i]=n[i]}return t}var k;(function t(e,n){function i(t,i,o){if("undefined"!=typeof document){"number"==typeof(o=x({},n,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var r in o)o[r]&&(s+="; "+r,!0!==o[r]&&(s+="="+o[r].split(";")[0]));return document.cookie=t+"="+e.write(i,t)+s}}return Object.create({set:i,get:function(t){if("undefined"!=typeof document&&(!arguments.length||t)){for(var n=document.cookie?document.cookie.split("; "):[],i={},o=0;o<n.length;o++){var s=n[o].split("="),r=s.slice(1).join("=");try{var a=decodeURIComponent(s[0]);if(i[a]=e.read(r,a),t===a)break}catch(t){}}return t?i[t]:i}},remove:function(t,e){i(t,"",x({},e,{expires:-1}))},withAttributes:function(e){return t(this.converter,x({},this.attributes,e))},withConverter:function(e){return t(x({},this.converter,e),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(e)}})})({read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});!function(t){t[t.localStorage=1]="localStorage",t[t.cookies=2]="cookies"}(k||(k={}));function T(t,e,n={}){let i,o,s,r,a,c=0;const l=!!n.leading,d="maxWait"in n,h=d?Math.max(n.maxWait||0,e):void 0,u=!("trailing"in n)||!!n.trailing;function p(e){const n=i,r=o;return i=o=void 0,c=e,s=t.apply(r,n),s}function f(t,e){return setTimeout(t,e)}function m(t){const n=t-a;return void 0===a||n>=e||n<0||d&&t-c>=h}function b(){const t=Date.now();if(m(t))return function(t){if(r=void 0,u&&i)return p(t);return i=o=void 0,s}(t);r=f(b,function(t){const n=t-c,i=e-(t-a);return d?Math.min(i,h-n):i}(t))}return function(...t){const n=Date.now(),h=m(n);if(i=t,o=this,a=n,h){if(void 0===r)return function(t){return c=t,r=f(b,e),l?p(t):s}(a);if(d)return r=f(b,e),p(a)}return void 0===r&&(r=f(b,e)),s}}const N=/[&<>"']/g;RegExp(N.source),Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});function M(){const t=window.getSelection();return{sel:t,range:t.rangeCount?t.getRangeAt(0):void 0}}function A(t){const e=document.createRange(),n=window.getSelection();e.setStart(t,1),e.collapse(!0),n.removeAllRanges(),n.addRange(e)}function L(t){const e=document.createRange(),n=window.getSelection();e.setStartAfter(t),e.collapse(!0),n.removeAllRanges(),n.addRange(e)}function S(t){if(1===t.length&&n(t[0])&&u(t[0].tagName))return void L(t[0]);const e=document.createRange(),i=window.getSelection();e.setStartBefore(t[0]),e.setEndAfter(t[t.length-1]),i.removeAllRanges(),i.addRange(e)}function H(t){const{range:e}=M();return void 0!==e&&(t.contains(e.startContainer)&&t.contains(e.endContainer))}function R(t,e){const n=e.parentNode,i=t.cloneRange();i.setStart(n,0);const o=i.extractContents(),s=document.createTextNode("​");return o.append(s),n.prepend(o),A(s),s}function O(t,e){const i=e.parentNode,o=new Range;o.selectNodeContents(i),o.setEnd(t.startContainer,t.startOffset);const s=new Range;s.selectNodeContents(i),s.setStart(t.endContainer,t.endOffset);const r=o.extractContents(),a=s.extractContents();i.prepend(r),i.append(a);let c=n(t.commonAncestorContainer)?t.commonAncestorContainer:t.commonAncestorContainer.parentNode;for(;c.tagName!==e.tagName;)c=c.parentNode;const l=d(c);return S(l),l[0].parentNode}function I(t,e={}){const{sel:i,range:o}=M();if(void 0===o)return;if(o.collapsed){let n=i.anchorNode.parentNode;for(;!a(n,"edith-visual");){if(r(n,t))return R(o,n);n=n.parentNode}return function(t,e,n={}){const i=document.createElement(e);return"a"===e?i.textContent=n.textContent||"lien":i.innerHTML="​",t.insertNode(i),"a"===e&&i.insertAdjacentText("afterend"," "),A(i),i}(o,t,e)}let s=o.commonAncestorContainer;for(;!n(s)||!a(s,"edith-visual");){if(n(s)&&r(s,t))return O(o,s);s=s.parentNode}for(const e of[...s.getElementsByTagName(t)])if(i.containsNode(e,!0)){return S(d(e)),s.normalize(),s}const c=document.createElement(t);return c.appendChild(o.extractContents()),o.insertNode(c),p(s,(t=>n(t)&&!u(t.tagName)&&(null===t.textContent||0===t.textContent.length))),function(t){const e=document.createRange(),n=window.getSelection();e.selectNodeContents(t),e.collapse(!1),n.removeAllRanges(),n.addRange(e)}(c),c}function j(t,e){for(let n of[...t.children]){if(r(n,"span")&&a(n,"edith-nbsp")){b(n,{class:"edith-nbsp",contenteditable:"false"}),n.innerHTML="¶";continue}n.hasAttribute("style")&&(n=g(n)),e[n.tagName]&&(n=l(n,c("span",{attributes:{style:n.getAttribute("style")||""},innerHTML:n.innerHTML})));const t={...e};if(r(n,["b","i","q","u","s"])&&(t[n.tagName]=!0),j(n,t),r(n,"a")){const t={};n.hasAttribute("href")&&(t.href=n.getAttribute("href")),n.hasAttribute("target")&&(t.target=n.getAttribute("target")),b(n,t)}else if(r(n,["b","i","q","u","s","br","sup"]))b(n,{});else if(r(n,["style","meta","link"]))n.remove();else if(r(n,"p")){if(null===n.textContent||0===n.textContent.trim().length){n.remove();continue}b(n,{}),v(n,"br")}else d(n)}}function D(t,n){const i=document.createElement("div");return i.innerHTML=t,j(i,n),i.normalize(),p(i,(t=>e(t)&&(null===t.textContent||0===t.textContent.trim().length))),i.innerHTML=i.innerHTML.replace(/\s*&nbsp;\s*/g," ").replace(/\s+/g," ").replace(/(<\/b>[\n\r\s]*<b>|<\/i>[\n\r\s]*<i>|<\/u>[\n\r\s]*<u>|<\/s>[\n\r\s]*<s>)/g," "),m(i),i}var z,B;!function(t){t.modeChanged="edith-mode-changed",t.initialized="edith-initialized"}(z||(z={}));class V{buffer=[];constructor(){}push(t){this.buffer.push(t),this.buffer.length>20&&this.buffer.shift()}pop(){return 0===this.buffer.length?null:this.buffer.pop()}}!function(t){t[t.Visual=1]="Visual",t[t.Code=2]="Code"}(B||(B={}));const U={height:80,resizable:!1,toolbar:[["style",["bold","italic","underline","strikethrough"]]],buttons:{},initialContent:""};var $=o(74);class P{el;ctx;icon;title;onclick;showOnCodeView;popperEl;popper;constructor(t,e){this.ctx=t,this.icon=e.icon,this.title=e.title,this.onclick=e.onclick,this.showOnCodeView=!0===e.showOnCodeView}click(t){t.preventDefault(),this.onclick(this.ctx,t)}showTooltip(){if(void 0!==this.popper)return;this.popperEl=c("div",{textContent:this.title,attributes:{class:"edith-tooltip"}});const t=c("div",{attributes:{class:"arrow","data-popper-arrow":""}});this.popperEl.append(t),this.ctx.toolbar.append(this.popperEl),this.popper=(0,$.createPopper)(this.el,this.popperEl,{placement:"bottom",modifiers:[{name:"arrow",options:{padding:5}},{name:"offset",options:{offset:[0,8]}}]})}hideTooltip(){void 0!==this.popper&&(this.popper.destroy(),this.popper=void 0,this.popperEl?.remove())}onEditorModeChange(t){t.detail.mode===B.Code?this.el.setAttribute("disabled","disabled"):this.el.removeAttribute("disabled")}render(){return this.el=c("button",{attributes:{class:`edith-btn ${this.icon}`,type:"button"}}),this.el.onclick=this.click.bind(this),this.el.onmouseenter=this.showTooltip.bind(this),this.el.onmouseleave=this.hideTooltip.bind(this),!0!==this.showOnCodeView&&this.ctx.on(z.modeChanged,this.onEditorModeChange.bind(this)),this.el}}const q=Object.freeze({bold:t=>new P(t,{icon:"fa-solid fa-bold",title:"Gras",onclick:t=>{t.editor.wrapInsideTag("b")}}),italic:t=>new P(t,{icon:"fa-solid fa-italic",title:"Italique",onclick:t=>{t.editor.wrapInsideTag("i")}}),underline:t=>new P(t,{icon:"fa-solid fa-underline",title:"Souligner",onclick:t=>{t.editor.wrapInsideTag("u")}}),strikethrough:t=>new P(t,{icon:"fa-solid fa-strikethrough",title:"Barrer",onclick:t=>{t.editor.wrapInsideTag("s")}}),subscript:t=>new P(t,{icon:"fa-solid fa-subscript",title:"Indice",onclick:t=>{t.editor.wrapInsideTag("sub")}}),superscript:t=>new P(t,{icon:"fa-solid fa-superscript",title:"Exposant",onclick:t=>{t.editor.wrapInsideTag("sup")}}),nbsp:t=>new P(t,{icon:"edith-btn-nbsp",title:"Ajouter une espace insécable",onclick:t=>{t.editor.replaceByHtml('<span class="edith-nbsp" contenteditable="false">¶</span>')}}),clear:t=>new P(t,{icon:"fa-solid fa-eraser",title:"Effacer la mise en forme",onclick:t=>{t.editor.clearStyle()}}),link:t=>new P(t,{icon:"fa-solid fa-link",title:"Lien",onclick:t=>{t.editor.insertLink()}}),codeview:t=>new P(t,{icon:"fa-solid fa-code",title:"Afficher le code HTML",onclick:t=>{t.editor.toggleCodeView()},showOnCodeView:!0})});var K,W=o(690);function _(t){const e=document.createElement("div");e.setAttribute("class","edith-modal-input");const n=document.createElement("label");n.textContent=t.label;const i=document.createElement("input");return i.setAttribute("name",t.name),i.setAttribute("type","text"),null!==t.initialState&&(i.value=t.initialState.toString()),e.append(n),e.append(i),e}function F(t){const e=document.createElement("div");e.setAttribute("class","edith-modal-checkbox");const n=document.createElement("label");n.textContent=t.label;const i=document.createElement("input");return i.setAttribute("name",t.name),i.setAttribute("type","checkbox"),t.initialState&&(i.checked=!0),n.prepend(i),e.append(n),e}function G(t,e,n=null){return{fieldType:K.input,label:t,name:e,initialState:n}}function J(t,e,n=!1){return{fieldType:K.checkbox,label:t,name:e,initialState:n}}!function(t){t[t.input=1]="input",t[t.checkbox=2]="checkbox"}(K||(K={}));class Q{el;ctx;title;fields;callback;constructor(t,e){this.ctx=t,this.title=e.title,this.fields=e.fields||[],this.callback=e.callback}cancel(t){t.preventDefault(),this.callback(null),this.close()}submit(t){t.preventDefault();const e={};for(const t of this.el.querySelectorAll("input"))n="name",t.hasAttribute(n)&&(e[i(t,"name")]="checkbox"===i(t,"type")?t.checked:t.value);var n;this.callback(e),this.close()}close(){this.el.remove()}show(){this.el=c("div",{attributes:{class:"edith-modal"}});const t=c("div",{attributes:{class:"edith-modal-header"}}),e=c("span",{textContent:this.title,attributes:{class:"edith-modal-title"}});t.append(e);const n=c("div",{attributes:{class:"edith-modal-content"}});for(const t of this.fields)switch(t.fieldType){case K.input:n.append(_(t));break;case K.checkbox:n.append(F(t));break;default:throw new Error(`Unknown fieldType ${t.fieldType}`)}const i=c("div",{attributes:{class:"edith-modal-footer"}}),o=c("button",{textContent:"Annuler",attributes:{class:"edith-modal-cancel",type:"button"}});i.append(o);const s=c("button",{textContent:"Valider",attributes:{class:"edith-modal-submit",type:"button"}});return i.append(s),this.el.append(t),this.el.append(n),this.el.append(i),this.ctx.modals.append(this.el),o.onclick=this.cancel.bind(this),s.onclick=this.submit.bind(this),this.el}}class X{el;ctx;content;height;resizable;mode;visualEditor;codeEditor;codeMirror;history;throttledSnapshots;constructor(t,e){this.ctx=t,this.content=e.initialContent,this.height=e.height,this.resizable=e.resizable,this.mode=B.Visual,this.history=new V,this.throttledSnapshots=function(t,e,n={}){return T(t,e,{leading:!("leading"in n)||!!n.leading,trailing:!("trailing"in n)||!!n.trailing,maxWait:e})}((()=>this.takeSnapshot()),3e3,{leading:!1,trailing:!0}),this.content=this.content.replace(/&nbsp;/g,'<span class="edith-nbsp" contenteditable="false">¶</span>')}render(){this.el=c("div",{attributes:{class:"edith-editing-area",style:this.resizable?`min-height: ${this.height}px; resize: vertical`:`height: ${this.height}px`}}),this.visualEditor=c("div",{innerHTML:this.content,attributes:{class:"edith-visual",contenteditable:"true",style:this.resizable?`min-height: ${this.height-10}px`:`height: ${this.height-10}px`}}),this.el.append(this.visualEditor),this.codeEditor=c("div",{attributes:{class:"edith-code edith-hidden"}}),this.el.append(this.codeEditor);const t=this.onKeyEvent.bind(this);this.visualEditor.addEventListener("keydown",t),this.visualEditor.addEventListener("keyup",t);const e=this.onPasteEvent.bind(this);return this.visualEditor.addEventListener("paste",e),this.el}getVisualEditorElement(){return this.visualEditor}getCodeEditorElement(){return this.codeEditor}setContent(t){t=t.replace(/&nbsp;/g,'<span class="edith-nbsp" contenteditable="false">¶</span>'),this.mode===B.Visual?this.visualEditor.innerHTML=t:this.codeMirror.dispatch({changes:{from:0,to:this.codeMirror.state.doc.length,insert:t}})}getContent(){const t=this.mode===B.Visual?this.visualEditor.innerHTML:this.codeMirror.state.doc.toJSON().map((t=>t.trim())).join("\n");if("<p><br></p>"===t)return"";const e=c("div",{innerHTML:t});f(e,(t=>n(t)&&!u(t.tagName)&&(null===t.textContent||0===t.textContent.length)));for(const t of e.querySelectorAll("[style]"))t.removeAttribute("style");for(const t of e.querySelectorAll("span"))0===t.attributes.length&&d(t);return e.innerHTML.replace(/\u200B/gi,"").replace(/<\/p>\s*<p>/gi,"<br>").replace(/(<p>|<\/p>)/gi,"").replace(/<span[^>]+class="edith-nbsp"[^>]*>[^<]*<\/span>/gi,"&nbsp;").replace(/(?:<br\s?\/?>)+$/gi,"")}takeSnapshot(){this.history.push(this.visualEditor.innerHTML)}restoreSnapshot(){this.visualEditor.innerHTML=this.history.pop()??""}wrapInsideTag(t){H(this.visualEditor)&&(I(t),this.takeSnapshot())}replaceByHtml(t){H(this.visualEditor)&&(!function(t){const{sel:e,range:n}=M();if(void 0===n)return;const i=document.createDocumentFragment(),o=c("div",{innerHTML:t});i.append(...o.childNodes);const s=i.childNodes[i.childNodes.length-1];e.deleteFromDocument(),n.insertNode(i),L(s)}(t),this.takeSnapshot())}clearStyle(){!function(){const{sel:t,range:e}=M();if(void 0!==e&&n(e.commonAncestorContainer))for(const n of[...e.commonAncestorContainer.children])t.containsNode(n,!0)&&h(n)}(),this.takeSnapshot()}insertLink(){const{sel:t,range:e}=M();if(void 0===e)return;const i=new Q(this.ctx,{title:"Insérer un lien",fields:[G("Texte à afficher","text",e.toString()),G("URL du lien","href"),J("Ouvrir dans une nouvelle fenêtre","openInNewTab",!0)],callback:i=>{null!==i&&(function(t){const e=window.getSelection();e.removeAllRanges(),void 0!==t.range&&e.addRange(t.range)}({sel:t,range:e}),function(t,e,i){const o=I("a",{textContent:t});if(void 0!==o)n(o)&&(o.setAttribute("href",e),!0===i&&o.setAttribute("target","_blank"))}(i.text,i.href,i.openInNewTab))}});i.show()}toggleCodeView(){if(this.mode===B.Visual){this.mode=B.Code,this.visualEditor.classList.add("edith-hidden"),this.codeEditor.classList.remove("edith-hidden");const t=document.createElement("div");this.codeEditor.append(t),this.codeMirror=new W.EditorView({doc:this.visualEditor.innerHTML,extensions:[W.basicSetup,W.EditorView.lineWrapping,(0,W.html)({matchClosingTags:!0,autoCloseTags:!0})],parent:t})}else this.mode=B.Visual,this.codeEditor.classList.add("edith-hidden"),this.visualEditor.classList.remove("edith-hidden"),this.visualEditor.innerHTML=this.codeMirror.state.doc.toJSON().map((t=>t.trim())).join("\n"),this.codeMirror.destroy(),this.codeMirror=void 0,this.codeEditor.innerHTML="";this.ctx.trigger(z.modeChanged,{mode:this.mode})}onKeyEvent(t){(t.metaKey||t.ctrlKey?this._processKeyEventWithMeta(t):this._processKeyEvent(t))&&(t.preventDefault(),t.stopPropagation())}_processKeyEvent(t){return"Enter"===t.key?("keydown"===t.type&&this.replaceByHtml("<br />"),!0):(this.throttledSnapshots(),!1)}_processKeyEventWithMeta(t){switch(t.key){case"Enter":return"keydown"===t.type&&this.replaceByHtml("<br />"),!0;case" ":return"keydown"===t.type&&this.replaceByHtml('<span class="edith-nbsp" contenteditable="false">¶</span>'),!0;case"b":return"keydown"===t.type&&this.wrapInsideTag("b"),!0;case"i":return"keydown"===t.type&&this.wrapInsideTag("i"),!0;case"k":return"keydown"===t.type&&this.insertLink(),!0;case"u":return"keydown"===t.type&&this.wrapInsideTag("u"),!0;case"s":return"keydown"===t.type&&this.wrapInsideTag("s"),!0;case"z":return"keydown"===t.type&&this.restoreSnapshot(),!0}return!1}onPasteEvent(t){t.preventDefault(),t.stopPropagation();const{sel:n,range:i}=M();if(void 0===i||null===t.clipboardData)return;const o=document.createDocumentFragment();if(t.clipboardData.types.includes("text/html")){let i=e(n.anchorNode)?n.anchorNode.parentNode:n.anchorNode;const s={B:!1,I:!1,U:!1,S:!1,Q:!1};for(;null!==i&&!a(i,"edith-visual");)r(i,["b","i","u","s","q"])&&(s[(i.tagName,"Q")]=!0),i=i.parentNode;let c=t.clipboardData.getData("text/html").replace(/[\r\n]+/g," ");/^<html>\s*<body>/.test(c)||(c="<html><body>"+c+"</body></html>");const l=D(c,s);o.append(...l.childNodes)}else{const e=t.clipboardData.getData("text/plain").split(/[\r\n]+/g);for(let t=0;t<e.length;t++)0!==t&&o.append(document.createElement("br")),o.append(document.createTextNode(e[t]))}n.deleteFromDocument(),i.insertNode(o)}destroy(){this.codeMirror?.destroy(),this.codeMirror=void 0,this.el.remove()}}class Y{element;toolbar;editor;modals;constructor(t,e){var n,i;this.element=t,n=this.element,"string"==typeof(i="edith")?n.classList.add(i):n.classList.add(...i),this.toolbar=c("div",{attributes:{class:"edith-toolbar"}}),this.element.append(this.toolbar);const o=e.buttons??U.buttons,s=e.toolbar??U.toolbar;for(const{0:t,1:e}of s){const n=document.createElement("div");n.setAttribute("id",t),n.setAttribute("class","edith-btn-group"),this.toolbar.append(n);for(const t of e){const e=o[t]??q[t];n.append(e(this).render())}}this.editor=new X(this,{initialContent:e.initialContent??U.initialContent,height:e.height??U.height,resizable:e.resizable??U.resizable}),this.element.append(this.editor.render()),this.modals=c("div",{attributes:{class:"edith-modals"}}),this.element.append(this.modals),this.element.edith=this,this.trigger(z.initialized)}on(t,e){!function(t,e,n){if(t instanceof NodeList)for(const i of t)w(i,e,n);else w(t,e,n)}(this.element,t,e)}off(t,e){!function(t,e,n){if(t instanceof NodeList)for(const i of t)C(i,e,n);else C(t,e,n)}(this.element,t,e)}trigger(t,e){!function(t,e,n){t.dispatchEvent("string"==typeof e?new CustomEvent(e,{detail:n}):e)}(this.element,t,e)}setContent(t){this.editor.setContent(t)}getContent(){return this.editor.getContent()}destroy(){var t,e;t=this.element,"string"==typeof(e="edith")?t.classList.remove(e):t.classList.remove(...e),this.modals.remove(),this.editor.destroy(),this.toolbar.remove(),this.element.remove()}}Y.EdithButton=P;var Z=Y}(),s=s.default}()}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("CodeMirror"),require("Popper")):"function"==typeof define&&define.amd?define(["CodeMirror","Popper"],t):"object"==typeof exports?exports.Edith=t(require("CodeMirror"),require("Popper")):e.Edith=t(e.CodeMirror,e.Popper)}(self,(function(e,t){return function(){var n={838:function(e){e.exports=function(){"use strict";const{entries:e,setPrototypeOf:t,isFrozen:n,getPrototypeOf:o,getOwnPropertyDescriptor:i}=Object;let{freeze:r,seal:a,create:s}=Object,{apply:l,construct:c}="undefined"!=typeof Reflect&&Reflect;r||(r=function(e){return e}),a||(a=function(e){return e}),l||(l=function(e,t,n){return e.apply(t,n)}),c||(c=function(e,t){return new e(...t)});const d=A(Array.prototype.forEach),u=A(Array.prototype.pop),p=A(Array.prototype.push),f=A(String.prototype.toLowerCase),h=A(String.prototype.toString),m=A(String.prototype.match),g=A(String.prototype.replace),b=A(String.prototype.indexOf),y=A(String.prototype.trim),E=A(Object.prototype.hasOwnProperty),T=A(RegExp.prototype.test),v=N(TypeError);function A(e){return function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];return l(e,t,o)}}function N(e){return function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];return c(e,n)}}function w(e,o){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:f;t&&t(e,null);let r=o.length;for(;r--;){let t=o[r];if("string"==typeof t){const e=i(t);e!==t&&(n(o)||(o[r]=e),t=e)}e[t]=!0}return e}function C(e){for(let t=0;t<e.length;t++)E(e,t)||(e[t]=null);return e}function x(t){const n=s(null);for(const[o,i]of e(t))E(t,o)&&(Array.isArray(i)?n[o]=C(i):i&&"object"==typeof i&&i.constructor===Object?n[o]=x(i):n[o]=i);return n}function S(e,t){for(;null!==e;){const n=i(e,t);if(n){if(n.get)return A(n.get);if("function"==typeof n.value)return A(n.value)}e=o(e)}function n(){return null}return n}const k=r(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","section","select","shadow","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),L=r(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","filter","font","g","glyph","glyphref","hkern","image","line","lineargradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),_=r(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),R=r(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),M=r(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),O=r(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),D=r(["#text"]),I=r(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","face","for","headers","height","hidden","high","href","hreflang","id","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),H=r(["accent-height","accumulate","additive","alignment-baseline","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),U=r(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),P=r(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),z=a(/\{\{[\w\W]*|[\w\W]*\}\}/gm),F=a(/<%[\w\W]*|[\w\W]*%>/gm),B=a(/\${[\w\W]*}/gm),j=a(/^data-[\-\w.\u00B7-\uFFFF]/),W=a(/^aria-[\-\w]+$/),G=a(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),V=a(/^(?:\w+script|data):/i),q=a(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Y=a(/^html$/i),$=a(/^[a-z][.\w]*(-[.\w]+)+$/i);var K=Object.freeze({__proto__:null,MUSTACHE_EXPR:z,ERB_EXPR:F,TMPLIT_EXPR:B,DATA_ATTR:j,ARIA_ATTR:W,IS_ALLOWED_URI:G,IS_SCRIPT_OR_DATA:V,ATTR_WHITESPACE:q,DOCTYPE_NAME:Y,CUSTOM_ELEMENT:$});const X={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,progressingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},J=function(){return"undefined"==typeof window?null:window},Q=function(e,t){if("object"!=typeof e||"function"!=typeof e.createPolicy)return null;let n=null;const o="data-tt-policy-suffix";t&&t.hasAttribute(o)&&(n=t.getAttribute(o));const i="dompurify"+(n?"#"+n:"");try{return e.createPolicy(i,{createHTML:e=>e,createScriptURL:e=>e})}catch(e){return console.warn("TrustedTypes policy "+i+" could not be created."),null}};function Z(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:J();const n=e=>Z(e);if(n.version="3.1.6",n.removed=[],!t||!t.document||t.document.nodeType!==X.document)return n.isSupported=!1,n;let{document:o}=t;const i=o,a=i.currentScript,{DocumentFragment:l,HTMLTemplateElement:c,Node:A,Element:N,NodeFilter:C,NamedNodeMap:z=t.NamedNodeMap||t.MozNamedAttrMap,HTMLFormElement:F,DOMParser:B,trustedTypes:j}=t,W=N.prototype,V=S(W,"cloneNode"),q=S(W,"remove"),$=S(W,"nextSibling"),ee=S(W,"childNodes"),te=S(W,"parentNode");if("function"==typeof c){const e=o.createElement("template");e.content&&e.content.ownerDocument&&(o=e.content.ownerDocument)}let ne,oe="";const{implementation:ie,createNodeIterator:re,createDocumentFragment:ae,getElementsByTagName:se}=o,{importNode:le}=i;let ce={};n.isSupported="function"==typeof e&&"function"==typeof te&&ie&&void 0!==ie.createHTMLDocument;const{MUSTACHE_EXPR:de,ERB_EXPR:ue,TMPLIT_EXPR:pe,DATA_ATTR:fe,ARIA_ATTR:he,IS_SCRIPT_OR_DATA:me,ATTR_WHITESPACE:ge,CUSTOM_ELEMENT:be}=K;let{IS_ALLOWED_URI:ye}=K,Ee=null;const Te=w({},[...k,...L,..._,...M,...D]);let ve=null;const Ae=w({},[...I,...H,...U,...P]);let Ne=Object.seal(s(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),we=null,Ce=null,xe=!0,Se=!0,ke=!1,Le=!0,_e=!1,Re=!0,Me=!1,Oe=!1,De=!1,Ie=!1,He=!1,Ue=!1,Pe=!0,ze=!1;const Fe="user-content-";let Be=!0,je=!1,We={},Ge=null;const Ve=w({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let qe=null;const Ye=w({},["audio","video","img","source","image","track"]);let $e=null;const Ke=w({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),Xe="http://www.w3.org/1998/Math/MathML",Je="http://www.w3.org/2000/svg",Qe="http://www.w3.org/1999/xhtml";let Ze=Qe,et=!1,tt=null;const nt=w({},[Xe,Je,Qe],h);let ot=null;const it=["application/xhtml+xml","text/html"],rt="text/html";let at=null,st=null;const lt=o.createElement("form"),ct=function(e){return e instanceof RegExp||e instanceof Function},dt=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!st||st!==e){if(e&&"object"==typeof e||(e={}),e=x(e),ot=-1===it.indexOf(e.PARSER_MEDIA_TYPE)?rt:e.PARSER_MEDIA_TYPE,at="application/xhtml+xml"===ot?h:f,Ee=E(e,"ALLOWED_TAGS")?w({},e.ALLOWED_TAGS,at):Te,ve=E(e,"ALLOWED_ATTR")?w({},e.ALLOWED_ATTR,at):Ae,tt=E(e,"ALLOWED_NAMESPACES")?w({},e.ALLOWED_NAMESPACES,h):nt,$e=E(e,"ADD_URI_SAFE_ATTR")?w(x(Ke),e.ADD_URI_SAFE_ATTR,at):Ke,qe=E(e,"ADD_DATA_URI_TAGS")?w(x(Ye),e.ADD_DATA_URI_TAGS,at):Ye,Ge=E(e,"FORBID_CONTENTS")?w({},e.FORBID_CONTENTS,at):Ve,we=E(e,"FORBID_TAGS")?w({},e.FORBID_TAGS,at):{},Ce=E(e,"FORBID_ATTR")?w({},e.FORBID_ATTR,at):{},We=!!E(e,"USE_PROFILES")&&e.USE_PROFILES,xe=!1!==e.ALLOW_ARIA_ATTR,Se=!1!==e.ALLOW_DATA_ATTR,ke=e.ALLOW_UNKNOWN_PROTOCOLS||!1,Le=!1!==e.ALLOW_SELF_CLOSE_IN_ATTR,_e=e.SAFE_FOR_TEMPLATES||!1,Re=!1!==e.SAFE_FOR_XML,Me=e.WHOLE_DOCUMENT||!1,Ie=e.RETURN_DOM||!1,He=e.RETURN_DOM_FRAGMENT||!1,Ue=e.RETURN_TRUSTED_TYPE||!1,De=e.FORCE_BODY||!1,Pe=!1!==e.SANITIZE_DOM,ze=e.SANITIZE_NAMED_PROPS||!1,Be=!1!==e.KEEP_CONTENT,je=e.IN_PLACE||!1,ye=e.ALLOWED_URI_REGEXP||G,Ze=e.NAMESPACE||Qe,Ne=e.CUSTOM_ELEMENT_HANDLING||{},e.CUSTOM_ELEMENT_HANDLING&&ct(e.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(Ne.tagNameCheck=e.CUSTOM_ELEMENT_HANDLING.tagNameCheck),e.CUSTOM_ELEMENT_HANDLING&&ct(e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(Ne.attributeNameCheck=e.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),e.CUSTOM_ELEMENT_HANDLING&&"boolean"==typeof e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements&&(Ne.allowCustomizedBuiltInElements=e.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),_e&&(Se=!1),He&&(Ie=!0),We&&(Ee=w({},D),ve=[],!0===We.html&&(w(Ee,k),w(ve,I)),!0===We.svg&&(w(Ee,L),w(ve,H),w(ve,P)),!0===We.svgFilters&&(w(Ee,_),w(ve,H),w(ve,P)),!0===We.mathMl&&(w(Ee,M),w(ve,U),w(ve,P))),e.ADD_TAGS&&(Ee===Te&&(Ee=x(Ee)),w(Ee,e.ADD_TAGS,at)),e.ADD_ATTR&&(ve===Ae&&(ve=x(ve)),w(ve,e.ADD_ATTR,at)),e.ADD_URI_SAFE_ATTR&&w($e,e.ADD_URI_SAFE_ATTR,at),e.FORBID_CONTENTS&&(Ge===Ve&&(Ge=x(Ge)),w(Ge,e.FORBID_CONTENTS,at)),Be&&(Ee["#text"]=!0),Me&&w(Ee,["html","head","body"]),Ee.table&&(w(Ee,["tbody"]),delete we.tbody),e.TRUSTED_TYPES_POLICY){if("function"!=typeof e.TRUSTED_TYPES_POLICY.createHTML)throw v('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if("function"!=typeof e.TRUSTED_TYPES_POLICY.createScriptURL)throw v('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');ne=e.TRUSTED_TYPES_POLICY,oe=ne.createHTML("")}else void 0===ne&&(ne=Q(j,a)),null!==ne&&"string"==typeof oe&&(oe=ne.createHTML(""));r&&r(e),st=e}},ut=w({},["mi","mo","mn","ms","mtext"]),pt=w({},["foreignobject","annotation-xml"]),ft=w({},["title","style","font","a","script"]),ht=w({},[...L,..._,...R]),mt=w({},[...M,...O]),gt=function(e){let t=te(e);t&&t.tagName||(t={namespaceURI:Ze,tagName:"template"});const n=f(e.tagName),o=f(t.tagName);return!!tt[e.namespaceURI]&&(e.namespaceURI===Je?t.namespaceURI===Qe?"svg"===n:t.namespaceURI===Xe?"svg"===n&&("annotation-xml"===o||ut[o]):Boolean(ht[n]):e.namespaceURI===Xe?t.namespaceURI===Qe?"math"===n:t.namespaceURI===Je?"math"===n&&pt[o]:Boolean(mt[n]):e.namespaceURI===Qe?!(t.namespaceURI===Je&&!pt[o])&&!(t.namespaceURI===Xe&&!ut[o])&&!mt[n]&&(ft[n]||!ht[n]):!("application/xhtml+xml"!==ot||!tt[e.namespaceURI]))},bt=function(e){p(n.removed,{element:e});try{te(e).removeChild(e)}catch(t){q(e)}},yt=function(e,t){try{p(n.removed,{attribute:t.getAttributeNode(e),from:t})}catch(e){p(n.removed,{attribute:null,from:t})}if(t.removeAttribute(e),"is"===e&&!ve[e])if(Ie||He)try{bt(t)}catch(e){}else try{t.setAttribute(e,"")}catch(e){}},Et=function(e){let t=null,n=null;if(De)e="<remove></remove>"+e;else{const t=m(e,/^[\r\n\t ]+/);n=t&&t[0]}"application/xhtml+xml"===ot&&Ze===Qe&&(e='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+e+"</body></html>");const i=ne?ne.createHTML(e):e;if(Ze===Qe)try{t=(new B).parseFromString(i,ot)}catch(e){}if(!t||!t.documentElement){t=ie.createDocument(Ze,"template",null);try{t.documentElement.innerHTML=et?oe:i}catch(e){}}const r=t.body||t.documentElement;return e&&n&&r.insertBefore(o.createTextNode(n),r.childNodes[0]||null),Ze===Qe?se.call(t,Me?"html":"body")[0]:Me?t.documentElement:r},Tt=function(e){return re.call(e.ownerDocument||e,e,C.SHOW_ELEMENT|C.SHOW_COMMENT|C.SHOW_TEXT|C.SHOW_PROCESSING_INSTRUCTION|C.SHOW_CDATA_SECTION,null)},vt=function(e){return e instanceof F&&("string"!=typeof e.nodeName||"string"!=typeof e.textContent||"function"!=typeof e.removeChild||!(e.attributes instanceof z)||"function"!=typeof e.removeAttribute||"function"!=typeof e.setAttribute||"string"!=typeof e.namespaceURI||"function"!=typeof e.insertBefore||"function"!=typeof e.hasChildNodes)},At=function(e){return"function"==typeof A&&e instanceof A},Nt=function(e,t,o){ce[e]&&d(ce[e],(e=>{e.call(n,t,o,st)}))},wt=function(e){let t=null;if(Nt("beforeSanitizeElements",e,null),vt(e))return bt(e),!0;const o=at(e.nodeName);if(Nt("uponSanitizeElement",e,{tagName:o,allowedTags:Ee}),e.hasChildNodes()&&!At(e.firstElementChild)&&T(/<[/\w]/g,e.innerHTML)&&T(/<[/\w]/g,e.textContent))return bt(e),!0;if(e.nodeType===X.progressingInstruction)return bt(e),!0;if(Re&&e.nodeType===X.comment&&T(/<[/\w]/g,e.data))return bt(e),!0;if(!Ee[o]||we[o]){if(!we[o]&&xt(o)){if(Ne.tagNameCheck instanceof RegExp&&T(Ne.tagNameCheck,o))return!1;if(Ne.tagNameCheck instanceof Function&&Ne.tagNameCheck(o))return!1}if(Be&&!Ge[o]){const t=te(e)||e.parentNode,n=ee(e)||e.childNodes;if(n&&t)for(let o=n.length-1;o>=0;--o){const i=V(n[o],!0);i.__removalCount=(e.__removalCount||0)+1,t.insertBefore(i,$(e))}}return bt(e),!0}return e instanceof N&&!gt(e)?(bt(e),!0):"noscript"!==o&&"noembed"!==o&&"noframes"!==o||!T(/<\/no(script|embed|frames)/i,e.innerHTML)?(_e&&e.nodeType===X.text&&(t=e.textContent,d([de,ue,pe],(e=>{t=g(t,e," ")})),e.textContent!==t&&(p(n.removed,{element:e.cloneNode()}),e.textContent=t)),Nt("afterSanitizeElements",e,null),!1):(bt(e),!0)},Ct=function(e,t,n){if(Pe&&("id"===t||"name"===t)&&(n in o||n in lt))return!1;if(Se&&!Ce[t]&&T(fe,t));else if(xe&&T(he,t));else if(!ve[t]||Ce[t]){if(!(xt(e)&&(Ne.tagNameCheck instanceof RegExp&&T(Ne.tagNameCheck,e)||Ne.tagNameCheck instanceof Function&&Ne.tagNameCheck(e))&&(Ne.attributeNameCheck instanceof RegExp&&T(Ne.attributeNameCheck,t)||Ne.attributeNameCheck instanceof Function&&Ne.attributeNameCheck(t))||"is"===t&&Ne.allowCustomizedBuiltInElements&&(Ne.tagNameCheck instanceof RegExp&&T(Ne.tagNameCheck,n)||Ne.tagNameCheck instanceof Function&&Ne.tagNameCheck(n))))return!1}else if($e[t]);else if(T(ye,g(n,ge,"")));else if("src"!==t&&"xlink:href"!==t&&"href"!==t||"script"===e||0!==b(n,"data:")||!qe[e])if(ke&&!T(me,g(n,ge,"")));else if(n)return!1;return!0},xt=function(e){return"annotation-xml"!==e&&m(e,be)},St=function(e){Nt("beforeSanitizeAttributes",e,null);const{attributes:t}=e;if(!t)return;const o={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ve};let i=t.length;for(;i--;){const r=t[i],{name:a,namespaceURI:s,value:l}=r,c=at(a);let p="value"===a?l:y(l);if(o.attrName=c,o.attrValue=p,o.keepAttr=!0,o.forceKeepAttr=void 0,Nt("uponSanitizeAttribute",e,o),p=o.attrValue,Re&&T(/((--!?|])>)|<\/(style|title)/i,p)){yt(a,e);continue}if(o.forceKeepAttr)continue;if(yt(a,e),!o.keepAttr)continue;if(!Le&&T(/\/>/i,p)){yt(a,e);continue}_e&&d([de,ue,pe],(e=>{p=g(p,e," ")}));const f=at(e.nodeName);if(Ct(f,c,p)){if(!ze||"id"!==c&&"name"!==c||(yt(a,e),p=Fe+p),ne&&"object"==typeof j&&"function"==typeof j.getAttributeType)if(s);else switch(j.getAttributeType(f,c)){case"TrustedHTML":p=ne.createHTML(p);break;case"TrustedScriptURL":p=ne.createScriptURL(p)}try{s?e.setAttributeNS(s,a,p):e.setAttribute(a,p),vt(e)?bt(e):u(n.removed)}catch(e){}}}Nt("afterSanitizeAttributes",e,null)},kt=function e(t){let n=null;const o=Tt(t);for(Nt("beforeSanitizeShadowDOM",t,null);n=o.nextNode();)Nt("uponSanitizeShadowNode",n,null),wt(n)||(n.content instanceof l&&e(n.content),St(n));Nt("afterSanitizeShadowDOM",t,null)};return n.sanitize=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=null,r=null,a=null,s=null;if(et=!e,et&&(e="\x3c!--\x3e"),"string"!=typeof e&&!At(e)){if("function"!=typeof e.toString)throw v("toString is not a function");if("string"!=typeof(e=e.toString()))throw v("dirty is not a string, aborting")}if(!n.isSupported)return e;if(Oe||dt(t),n.removed=[],"string"==typeof e&&(je=!1),je){if(e.nodeName){const t=at(e.nodeName);if(!Ee[t]||we[t])throw v("root node is forbidden and cannot be sanitized in-place")}}else if(e instanceof A)o=Et("\x3c!----\x3e"),r=o.ownerDocument.importNode(e,!0),r.nodeType===X.element&&"BODY"===r.nodeName||"HTML"===r.nodeName?o=r:o.appendChild(r);else{if(!Ie&&!_e&&!Me&&-1===e.indexOf("<"))return ne&&Ue?ne.createHTML(e):e;if(o=Et(e),!o)return Ie?null:Ue?oe:""}o&&De&&bt(o.firstChild);const c=Tt(je?e:o);for(;a=c.nextNode();)wt(a)||(a.content instanceof l&&kt(a.content),St(a));if(je)return e;if(Ie){if(He)for(s=ae.call(o.ownerDocument);o.firstChild;)s.appendChild(o.firstChild);else s=o;return(ve.shadowroot||ve.shadowrootmode)&&(s=le.call(i,s,!0)),s}let u=Me?o.outerHTML:o.innerHTML;return Me&&Ee["!doctype"]&&o.ownerDocument&&o.ownerDocument.doctype&&o.ownerDocument.doctype.name&&T(Y,o.ownerDocument.doctype.name)&&(u="<!DOCTYPE "+o.ownerDocument.doctype.name+">\n"+u),_e&&d([de,ue,pe],(e=>{u=g(u,e," ")})),ne&&Ue?ne.createHTML(u):u},n.setConfig=function(){dt(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),Oe=!0},n.clearConfig=function(){st=null,Oe=!1},n.isValidAttribute=function(e,t,n){st||dt({});const o=at(e),i=at(t);return Ct(o,i,n)},n.addHook=function(e,t){"function"==typeof t&&(ce[e]=ce[e]||[],p(ce[e],t))},n.removeHook=function(e){if(ce[e])return u(ce[e])},n.removeHooks=function(e){ce[e]&&(ce[e]=[])},n.removeAllHooks=function(){ce={}},n}return Z()}()},690:function(t){"use strict";t.exports=e},74:function(e){"use strict";e.exports=t}},o={};function i(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e].call(r.exports,r,r.exports,i),r.exports}i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,{a:t}),t},i.d=function(e,t){for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var r={};return function(){"use strict";function e(e,t){return n(e)&&e.tagName===t.toUpperCase()}function t(e){return e.nodeType===Node.TEXT_NODE}function n(e){return e.nodeType===Node.ELEMENT_NODE}function o(e,t){return e.getAttribute(t)}function a(e,t){return"string"==typeof t?e.tagName===t.toUpperCase():t.some((t=>e.tagName===t.toUpperCase()))}function s(e,t){return e.classList.contains(t)}function l(e,{innerHTML:t,textContent:n,attributes:o}={}){const i=document.createElement(e);if(o)for(const e in o)Object.hasOwnProperty.call(o,e)&&i.setAttribute(e,o[e]);return"string"==typeof t?i.innerHTML=t:"string"==typeof n&&(i.textContent=n),i}function c(e,t){return e.replaceWith(t),t}function d(e){const t=[...e.childNodes];return e.replaceWith(...t),t}function u(e){const t=document.createTextNode(e.textContent??"");return e.replaceWith(t),t}function p(e){return["AREA","BASE","BR","COL","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"].includes(e)}function f(e,t){for(const n of[...e.childNodes])t(n)&&n.remove()}function h(e,t){if(t(e))e.remove();else for(const n of[...e.childNodes])h(n,t)}function m(e){f(e,(e=>function(e){return e.nodeType===Node.COMMENT_NODE}(e)))}function g(e,t){for(const n of e.getAttributeNames())void 0===t[n]&&e.removeAttribute(n);for(const n of Object.keys(t))e.setAttribute(n,t[n])}function b(e){const t=e.getAttribute("style")||"";return(a(e,"b")&&t.match(/font-weight\s*:\s*(normal|400);/)||a(e,"i")&&t.match(/font-style\s*:\s*normal;/)||a(e,["u","s"])&&t.match(/text-decoration\s*:\s*none;/))&&(e=c(e,l("span",{attributes:{style:t},innerHTML:e.innerHTML}))),t.match(/font-weight\s*:\s*(bold|700|800|900);/)?e=c(e,l("b",{innerHTML:`<span style="${t.replace(/font-weight\s*:\s*(bold|700|800|900);/,"")}">${e.innerHTML}</span>`})):t.match(/font-style\s*:\s*italic;/)?e=c(e,l("i",{innerHTML:`<span style="${t.replace(/font-style\s*:\s*italic;/,"")}">${e.innerHTML}</span>`})):t.match(/text-decoration\s*:\s*underline;/)?e=c(e,l("u",{innerHTML:`<span style="${t.replace(/text-decoration\s*:\s*underline;/,"")}">${e.innerHTML}</span>`})):t.match(/text-decoration\s*:\s*line-through;/)&&(e=c(e,l("s",{innerHTML:`<span style="${t.replace(/text-decoration\s*:\s*line-through;/,"")}">${e.innerHTML}</span>`}))),e}function y(t,n){const o=t.childNodes;for(;o.length>0&&e(o[0],n);)o[0].remove();for(;o.length>0&&e(o[o.length-1],n);)o[o.length-1].remove()}i.d(r,{default:function(){return te}});let E=0;function T(e){const[t,...n]=e.split(".");return{type:t,ns:n??null}}function v(e,t,n){void 0===e.ljbtEvents&&(e.ljbtEvents={});for(const o of t.split(" ")){const{type:t,ns:i}=T(o),r=(++E).toString(10);e.addEventListener(t,n),e.ljbtEvents[r]={type:t,ns:i,handler:n}}}function A(e,t,n){void 0===e.ljbtEvents&&(e.ljbtEvents={});for(const o of t.split(" ")){const{type:t,ns:i}=T(o);for(const[o,r]of Object.entries(e.ljbtEvents))r.type!==t&&"*"!==t||null!==i&&!r.ns?.includes(i[0])||void 0!==n&&("function"!=typeof n||n!==r.handler)||(delete e.ljbtEvents[o],e.removeEventListener(r.type,r.handler))}}function N(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}var w;(function e(t,n){function o(e,o,i){if("undefined"!=typeof document){"number"==typeof(i=N({},n,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var r="";for(var a in i)i[a]&&(r+="; "+a,!0!==i[a]&&(r+="="+i[a].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+r}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var n=document.cookie?document.cookie.split("; "):[],o={},i=0;i<n.length;i++){var r=n[i].split("="),a=r.slice(1).join("=");try{var s=decodeURIComponent(r[0]);if(o[s]=t.read(a,s),e===s)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",N({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,N({},this.attributes,t))},withConverter:function(t){return e(N({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})})({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});!function(e){e[e.localStorage=1]="localStorage",e[e.cookies=2]="cookies"}(w||(w={}));function C(e,t,n={}){let o,i,r,a,s,l=0;const c=!!n.leading,d="maxWait"in n,u=d?Math.max(n.maxWait||0,t):void 0,p=!("trailing"in n)||!!n.trailing;function f(t){const n=o,a=i;return o=i=void 0,l=t,r=e.apply(a,n),r}function h(e,t){return setTimeout(e,t)}function m(e){const n=e-s;return void 0===s||n>=t||n<0||d&&e-l>=u}function g(){const e=Date.now();if(m(e))return function(e){if(a=void 0,p&&o)return f(e);return o=i=void 0,r}(e);a=h(g,function(e){const n=e-l,o=t-(e-s);return d?Math.min(o,u-n):o}(e))}return function(...e){const n=Date.now(),u=m(n);if(o=e,i=this,s=n,u){if(void 0===a)return function(e){return l=e,a=h(g,t),c?f(e):r}(s);if(d)return a=h(g,t),f(s)}return void 0===a&&(a=h(g,t)),r}}const x=/[&<>"']/g;RegExp(x.source),Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"});var S,k,L=i(838),_=i.n(L);function R(){const e=window.getSelection();return{sel:e,range:e.rangeCount?e.getRangeAt(0):void 0}}function M(e){const t=document.createRange(),n=window.getSelection();t.setStart(e,1),t.collapse(!0),n.removeAllRanges(),n.addRange(t)}function O(e){const t=document.createRange(),n=window.getSelection();t.setStartAfter(e),t.collapse(!0),n.removeAllRanges(),n.addRange(t)}function D(e){if(1===e.length&&n(e[0])&&p(e[0].tagName))return void O(e[0]);const t=document.createRange(),o=window.getSelection();t.setStartBefore(e[0]),t.setEndAfter(e[e.length-1]),o.removeAllRanges(),o.addRange(t)}function I(e){const{range:t}=R();return void 0!==t&&(e.contains(t.startContainer)&&e.contains(t.endContainer))}function H(e,t){const n=t.parentNode,o=e.cloneRange();o.setStart(n,0);const i=o.extractContents(),r=document.createTextNode("​");return i.append(r),n.prepend(i),M(r),r}function U(e,t){const o=t.parentNode,i=new Range;i.selectNodeContents(o),i.setEnd(e.startContainer,e.startOffset);const r=new Range;r.selectNodeContents(o),r.setStart(e.endContainer,e.endOffset);const a=i.extractContents(),s=r.extractContents();o.prepend(a),o.append(s);let l=n(e.commonAncestorContainer)?e.commonAncestorContainer:e.commonAncestorContainer.parentNode;for(;l.tagName!==t.tagName;)l=l.parentNode;const c=d(l);return D(c),c[0].parentNode}function P(e,t={}){const{sel:o,range:i}=R();if(void 0===i)return;if(i.collapsed){let n=o.anchorNode.parentNode;for(;!s(n,"edith-visual");){if(a(n,e))return H(i,n);n=n.parentNode}return function(e,t,n={}){const o=document.createElement(t);return"a"===t?o.textContent=n.textContent||"lien":o.innerHTML="​",e.insertNode(o),"a"===t&&o.insertAdjacentText("afterend"," "),M(o),o}(i,e,t)}let r=i.commonAncestorContainer;for(;!n(r)||!s(r,"edith-visual");){if(n(r)&&a(r,e))return U(i,r);r=r.parentNode}for(const t of[...r.getElementsByTagName(e)])if(o.containsNode(t,!0)){return D(d(t)),r.normalize(),r}const l=document.createElement(e);return l.appendChild(i.extractContents()),i.insertNode(l),f(r,(e=>n(e)&&!p(e.tagName)&&(null===e.textContent||0===e.textContent.length))),function(e){const t=document.createRange(),n=window.getSelection();t.selectNodeContents(e),t.collapse(!1),n.removeAllRanges(),n.addRange(t)}(l),l}function z(e,t){for(let n of[...e.children]){if(a(n,"span")&&s(n,"edith-nbsp")){g(n,{class:"edith-nbsp",contenteditable:"false"}),n.innerHTML="¶";continue}n.hasAttribute("style")&&(n=b(n)),t[n.tagName]&&(n=c(n,l("span",{attributes:{style:n.getAttribute("style")||""},innerHTML:n.innerHTML})));const e={...t};if(a(n,["b","i","q","u","s"])&&(e[n.tagName]=!0),z(n,e),a(n,"a")){const e={};n.hasAttribute("href")&&(e.href=n.getAttribute("href")),n.hasAttribute("target")&&(e.target=n.getAttribute("target")),g(n,e)}else if(a(n,["b","i","q","u","s","br","sup"]))g(n,{});else if(a(n,["style","meta","link"]))n.remove();else if(a(n,"p")){if(null===n.textContent||0===n.textContent.trim().length){n.remove();continue}g(n,{}),y(n,"br")}else d(n)}}function F(e,n){const o=document.createElement("div");return o.innerHTML=_().sanitize(e,{USE_PROFILES:{html:!0}}),z(o,n),o.normalize(),f(o,(e=>t(e)&&(null===e.textContent||0===e.textContent.trim().length))),o.innerHTML=o.innerHTML.replace(/\s*&nbsp;\s*/g," ").replace(/\s+/g," ").replace(/(<\/b>[\n\r\s]*<b>|<\/i>[\n\r\s]*<i>|<\/u>[\n\r\s]*<u>|<\/s>[\n\r\s]*<s>)/g," "),m(o),o}!function(e){e.modeChanged="edith-mode-changed",e.initialized="edith-initialized"}(S||(S={}));class B{buffer=[];constructor(){}push(e){this.buffer.push(e),this.buffer.length>20&&this.buffer.shift()}pop(){return 0===this.buffer.length?null:this.buffer.pop()}}!function(e){e[e.Visual=1]="Visual",e[e.Code=2]="Code"}(k||(k={}));const j={height:80,resizable:!1,toolbar:[["style",["bold","italic","underline","strikethrough"]]],buttons:{},initialContent:""};var W=i(74);class G{el;ctx;icon;title;onclick;showOnCodeView;popperEl;popper;constructor(e,t){this.ctx=e,this.icon=t.icon,this.title=t.title,this.onclick=t.onclick,this.showOnCodeView=!0===t.showOnCodeView}click(e){e.preventDefault(),this.onclick(this.ctx,e)}showTooltip(){if(void 0!==this.popper)return;this.popperEl=l("div",{textContent:this.title,attributes:{class:"edith-tooltip"}});const e=l("div",{attributes:{class:"arrow","data-popper-arrow":""}});this.popperEl.append(e),this.ctx.toolbar.append(this.popperEl),this.popper=(0,W.createPopper)(this.el,this.popperEl,{placement:"bottom",modifiers:[{name:"arrow",options:{padding:5}},{name:"offset",options:{offset:[0,8]}}]})}hideTooltip(){void 0!==this.popper&&(this.popper.destroy(),this.popper=void 0,this.popperEl?.remove())}onEditorModeChange(e){e.detail.mode===k.Code?this.el.setAttribute("disabled","disabled"):this.el.removeAttribute("disabled")}render(){return this.el=l("button",{attributes:{class:`edith-btn ${this.icon}`,type:"button"}}),this.el.onclick=this.click.bind(this),this.el.onmouseenter=this.showTooltip.bind(this),this.el.onmouseleave=this.hideTooltip.bind(this),!0!==this.showOnCodeView&&this.ctx.on(S.modeChanged,this.onEditorModeChange.bind(this)),this.el}}const V=Object.freeze({bold:e=>new G(e,{icon:"fa-solid fa-bold",title:"Gras",onclick:e=>{e.editor.wrapInsideTag("b")}}),italic:e=>new G(e,{icon:"fa-solid fa-italic",title:"Italique",onclick:e=>{e.editor.wrapInsideTag("i")}}),underline:e=>new G(e,{icon:"fa-solid fa-underline",title:"Souligner",onclick:e=>{e.editor.wrapInsideTag("u")}}),strikethrough:e=>new G(e,{icon:"fa-solid fa-strikethrough",title:"Barrer",onclick:e=>{e.editor.wrapInsideTag("s")}}),subscript:e=>new G(e,{icon:"fa-solid fa-subscript",title:"Indice",onclick:e=>{e.editor.wrapInsideTag("sub")}}),superscript:e=>new G(e,{icon:"fa-solid fa-superscript",title:"Exposant",onclick:e=>{e.editor.wrapInsideTag("sup")}}),nbsp:e=>new G(e,{icon:"edith-btn-nbsp",title:"Ajouter une espace insécable",onclick:e=>{e.editor.replaceByHtml('<span class="edith-nbsp" contenteditable="false">¶</span>')}}),clear:e=>new G(e,{icon:"fa-solid fa-eraser",title:"Effacer la mise en forme",onclick:e=>{e.editor.clearStyle()}}),link:e=>new G(e,{icon:"fa-solid fa-link",title:"Lien",onclick:e=>{e.editor.insertLink()}}),codeview:e=>new G(e,{icon:"fa-solid fa-code",title:"Afficher le code HTML",onclick:e=>{e.editor.toggleCodeView()},showOnCodeView:!0})});var q,Y=i(690);function $(e){const t=document.createElement("div");t.setAttribute("class","edith-modal-input");const n=document.createElement("label");n.textContent=e.label;const o=document.createElement("input");return o.setAttribute("name",e.name),o.setAttribute("type","text"),null!==e.initialState&&(o.value=e.initialState.toString()),t.append(n),t.append(o),t}function K(e){const t=document.createElement("div");t.setAttribute("class","edith-modal-checkbox");const n=document.createElement("label");n.textContent=e.label;const o=document.createElement("input");return o.setAttribute("name",e.name),o.setAttribute("type","checkbox"),e.initialState&&(o.checked=!0),n.prepend(o),t.append(n),t}function X(e,t,n=null){return{fieldType:q.input,label:e,name:t,initialState:n}}function J(e,t,n=!1){return{fieldType:q.checkbox,label:e,name:t,initialState:n}}!function(e){e[e.input=1]="input",e[e.checkbox=2]="checkbox"}(q||(q={}));class Q{el;ctx;title;fields;callback;constructor(e,t){this.ctx=e,this.title=t.title,this.fields=t.fields||[],this.callback=t.callback}cancel(e){e.preventDefault(),this.callback(null),this.close()}submit(e){e.preventDefault();const t={};for(const e of this.el.querySelectorAll("input"))n="name",e.hasAttribute(n)&&(t[o(e,"name")]="checkbox"===o(e,"type")?e.checked:e.value);var n;this.callback(t),this.close()}close(){this.el.remove()}show(){this.el=l("div",{attributes:{class:"edith-modal"}});const e=l("div",{attributes:{class:"edith-modal-header"}}),t=l("span",{textContent:this.title,attributes:{class:"edith-modal-title"}});e.append(t);const n=l("div",{attributes:{class:"edith-modal-content"}});for(const e of this.fields)switch(e.fieldType){case q.input:n.append($(e));break;case q.checkbox:n.append(K(e));break;default:throw new Error(`Unknown fieldType ${e.fieldType}`)}const o=l("div",{attributes:{class:"edith-modal-footer"}}),i=l("button",{textContent:"Annuler",attributes:{class:"edith-modal-cancel",type:"button"}});o.append(i);const r=l("button",{textContent:"Valider",attributes:{class:"edith-modal-submit",type:"button"}});return o.append(r),this.el.append(e),this.el.append(n),this.el.append(o),this.ctx.modals.append(this.el),i.onclick=this.cancel.bind(this),r.onclick=this.submit.bind(this),this.el}}class Z{el;ctx;content;height;resizable;mode;visualEditor;codeEditor;codeMirror;history;throttledSnapshots;constructor(e,t){this.ctx=e,this.content=t.initialContent,this.height=t.height,this.resizable=t.resizable,this.mode=k.Visual,this.history=new B,this.throttledSnapshots=function(e,t,n={}){return C(e,t,{leading:!("leading"in n)||!!n.leading,trailing:!("trailing"in n)||!!n.trailing,maxWait:t})}((()=>this.takeSnapshot()),3e3,{leading:!1,trailing:!0}),this.content=this.content.replace(/&nbsp;/g,'<span class="edith-nbsp" contenteditable="false">¶</span>')}render(){this.el=l("div",{attributes:{class:"edith-editing-area",style:this.resizable?`min-height: ${this.height}px; resize: vertical`:`height: ${this.height}px`}}),this.visualEditor=l("div",{innerHTML:this.content,attributes:{class:"edith-visual",contenteditable:"true",style:this.resizable?`min-height: ${this.height-10}px`:`height: ${this.height-10}px`}}),this.el.append(this.visualEditor),this.codeEditor=l("div",{attributes:{class:"edith-code edith-hidden"}}),this.el.append(this.codeEditor);const e=this.onKeyEvent.bind(this);this.visualEditor.addEventListener("keydown",e),this.visualEditor.addEventListener("keyup",e);const t=this.onPasteEvent.bind(this);return this.visualEditor.addEventListener("paste",t),this.el}getVisualEditorElement(){return this.visualEditor}getCodeEditorElement(){return this.codeEditor}setContent(e){e=e.replace(/&nbsp;/g,'<span class="edith-nbsp" contenteditable="false">¶</span>'),this.mode===k.Visual?this.visualEditor.innerHTML=e:this.codeMirror.dispatch({changes:{from:0,to:this.codeMirror.state.doc.length,insert:e}})}getContent(){const e=this.mode===k.Visual?this.visualEditor.innerHTML:this.codeMirror.state.doc.toJSON().map((e=>e.trim())).join("\n");if("<p><br></p>"===e)return"";const t=l("div",{innerHTML:e});h(t,(e=>n(e)&&!p(e.tagName)&&(null===e.textContent||0===e.textContent.length)));for(const e of t.querySelectorAll("[style]"))e.removeAttribute("style");for(const e of t.querySelectorAll("span"))0===e.attributes.length&&d(e);return t.innerHTML.replace(/\u200B/gi,"").replace(/<\/p>\s*<p>/gi,"<br>").replace(/(<p>|<\/p>)/gi,"").replace(/<span[^>]+class="edith-nbsp"[^>]*>[^<]*<\/span>/gi,"&nbsp;").replace(/(?:<br\s?\/?>)+$/gi,"")}takeSnapshot(){this.history.push(this.visualEditor.innerHTML)}restoreSnapshot(){this.visualEditor.innerHTML=this.history.pop()??""}wrapInsideTag(e){I(this.visualEditor)&&(P(e),this.takeSnapshot())}replaceByHtml(e){I(this.visualEditor)&&(!function(e){const{sel:t,range:n}=R();if(void 0===n)return;const o=document.createDocumentFragment(),i=l("div",{innerHTML:e});o.append(...i.childNodes);const r=o.childNodes[o.childNodes.length-1];t.deleteFromDocument(),n.insertNode(o),O(r)}(e),this.takeSnapshot())}clearStyle(){!function(){const{sel:e,range:t}=R();if(void 0!==t&&n(t.commonAncestorContainer))for(const n of[...t.commonAncestorContainer.children])e.containsNode(n,!0)&&u(n)}(),this.takeSnapshot()}insertLink(){const{sel:e,range:t}=R();if(void 0===t)return;const o=new Q(this.ctx,{title:"Insérer un lien",fields:[X("Texte à afficher","text",t.toString()),X("URL du lien","href"),J("Ouvrir dans une nouvelle fenêtre","openInNewTab",!0)],callback:o=>{null!==o&&(function(e){const t=window.getSelection();t.removeAllRanges(),void 0!==e.range&&t.addRange(e.range)}({sel:e,range:t}),function(e,t,o){const i=P("a",{textContent:e});if(void 0!==i)n(i)&&(i.setAttribute("href",t),!0===o&&i.setAttribute("target","_blank"))}(o.text,o.href,o.openInNewTab))}});o.show()}toggleCodeView(){if(this.mode===k.Visual){this.mode=k.Code,this.visualEditor.classList.add("edith-hidden"),this.codeEditor.classList.remove("edith-hidden");const e=document.createElement("div");this.codeEditor.append(e),this.codeMirror=new Y.EditorView({doc:this.visualEditor.innerHTML,extensions:[Y.basicSetup,Y.EditorView.lineWrapping,(0,Y.html)({matchClosingTags:!0,autoCloseTags:!0})],parent:e})}else this.mode=k.Visual,this.codeEditor.classList.add("edith-hidden"),this.visualEditor.classList.remove("edith-hidden"),this.visualEditor.innerHTML=this.codeMirror.state.doc.toJSON().map((e=>e.trim())).join("\n"),this.codeMirror.destroy(),this.codeMirror=void 0,this.codeEditor.innerHTML="";this.ctx.trigger(S.modeChanged,{mode:this.mode})}onKeyEvent(e){(e.metaKey||e.ctrlKey?this._processKeyEventWithMeta(e):this._processKeyEvent(e))&&(e.preventDefault(),e.stopPropagation())}_processKeyEvent(e){return"Enter"===e.key?("keydown"===e.type&&this.replaceByHtml("<br />"),!0):(this.throttledSnapshots(),!1)}_processKeyEventWithMeta(e){switch(e.key){case"Enter":return"keydown"===e.type&&this.replaceByHtml("<br />"),!0;case" ":return"keydown"===e.type&&this.replaceByHtml('<span class="edith-nbsp" contenteditable="false">¶</span>'),!0;case"b":return"keydown"===e.type&&this.wrapInsideTag("b"),!0;case"i":return"keydown"===e.type&&this.wrapInsideTag("i"),!0;case"k":return"keydown"===e.type&&this.insertLink(),!0;case"u":return"keydown"===e.type&&this.wrapInsideTag("u"),!0;case"s":return"keydown"===e.type&&this.wrapInsideTag("s"),!0;case"z":return"keydown"===e.type&&this.restoreSnapshot(),!0}return!1}onPasteEvent(e){e.preventDefault(),e.stopPropagation();const{sel:n,range:o}=R();if(void 0===o||null===e.clipboardData)return;const i=document.createDocumentFragment();if(e.clipboardData.types.includes("text/html")){let o=t(n.anchorNode)?n.anchorNode.parentNode:n.anchorNode;const r={B:!1,I:!1,U:!1,S:!1,Q:!1};for(;null!==o&&!s(o,"edith-visual");)a(o,["b","i","u","s","q"])&&(r[(o.tagName,"Q")]=!0),o=o.parentNode;let l=e.clipboardData.getData("text/html").replace(/[\r\n]+/g," ");/^<html>\s*<body>/.test(l)||(l="<html><body>"+l+"</body></html>");const c=F(l,r);i.append(...c.childNodes)}else{const t=e.clipboardData.getData("text/plain").split(/[\r\n]+/g);for(let e=0;e<t.length;e++)0!==e&&i.append(document.createElement("br")),i.append(document.createTextNode(t[e]))}n.deleteFromDocument(),o.insertNode(i)}destroy(){this.codeMirror?.destroy(),this.codeMirror=void 0,this.el.remove()}}class ee{element;toolbar;editor;modals;constructor(e,t){var n,o;this.element=e,n=this.element,"string"==typeof(o="edith")?n.classList.add(o):n.classList.add(...o),this.toolbar=l("div",{attributes:{class:"edith-toolbar"}}),this.element.append(this.toolbar);const i=t.buttons??j.buttons,r=t.toolbar??j.toolbar;for(const{0:e,1:t}of r){const n=document.createElement("div");n.setAttribute("id",e),n.setAttribute("class","edith-btn-group"),this.toolbar.append(n);for(const e of t){const t=i[e]??V[e];n.append(t(this).render())}}this.editor=new Z(this,{initialContent:t.initialContent??j.initialContent,height:t.height??j.height,resizable:t.resizable??j.resizable}),this.element.append(this.editor.render()),this.modals=l("div",{attributes:{class:"edith-modals"}}),this.element.append(this.modals),this.element.edith=this,this.trigger(S.initialized)}on(e,t){!function(e,t,n){if(e instanceof NodeList)for(const o of e)v(o,t,n);else v(e,t,n)}(this.element,e,t)}off(e,t){!function(e,t,n){if(e instanceof NodeList)for(const o of e)A(o,t,n);else A(e,t,n)}(this.element,e,t)}trigger(e,t){!function(e,t,n){e.dispatchEvent("string"==typeof t?new CustomEvent(t,{detail:n}):t)}(this.element,e,t)}setContent(e){this.editor.setContent(e)}getContent(){return this.editor.getContent()}destroy(){var e,t;e=this.element,"string"==typeof(t="edith")?e.classList.remove(t):e.classList.remove(...t),this.modals.remove(),this.editor.destroy(),this.toolbar.remove(),this.element.remove()}}ee.EdithButton=G;var te=ee}(),r=r.default}()}));
package/dist/core/edit.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createNodeWith, hasClass, hasTagName, isHTMLElement, isSelfClosing, removeCommentNodes, removeEmptyTextNodes, removeNodes, replaceNodeStyleByTag, replaceNodeWith, resetAttributesTo, textifyNode, trimTag, unwrapNode, } from "@lesjoursfr/browser-tools";
2
+ import DOMPurify from "dompurify";
2
3
  import { getSelection, moveCursorAfterNode, moveCursorInsideNode, selectNodeContents, selectNodes } from "./range.js";
3
4
  /**
4
5
  * Split the node at the caret position.
@@ -307,7 +308,7 @@ export function cleanDomContent(root, style) {
307
308
  export function cleanPastedHtml(html, style) {
308
309
  // Create a new div with the HTML content
309
310
  const result = document.createElement("div");
310
- result.innerHTML = html;
311
+ result.innerHTML = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
311
312
  // Clean the HTML content
312
313
  cleanDomContent(result, style);
313
314
  result.normalize();
@@ -24,260 +24,260 @@ $color-modal-submit-color: #fff;
24
24
  $color-modal-submit-border: #0d6efd;
25
25
 
26
26
  .edith {
27
- background-color: $color-toolbar;
28
- border: 1px solid $color-toolbar-border;
29
- border-radius: 0.25rem;
30
- padding: 5px;
27
+ background-color: $color-toolbar;
28
+ border: 1px solid $color-toolbar-border;
29
+ border-radius: 0.25rem;
30
+ padding: 5px;
31
31
  }
32
32
 
33
33
  .edith-toolbar {
34
- background-color: $color-toolbar;
34
+ background-color: $color-toolbar;
35
35
  }
36
36
 
37
37
  .edith-btn {
38
- background-color: $color-button;
39
- border: 1px solid $color-button-border;
40
- border-radius: 0.25rem;
41
- color: $color-button-text;
42
- cursor: pointer;
43
- display: inline-block;
44
- font-size: 1rem;
45
- font-weight: 900;
46
- line-height: 1.5;
47
- padding: 0.375rem 0.75rem;
48
- text-align: center;
49
- text-decoration: none;
50
- user-select: none;
51
- vertical-align: middle;
52
-
53
- &:disabled {
54
- color: color.scale($color-button-text, $lightness: 70%);
55
- cursor: not-allowed;
56
- }
38
+ background-color: $color-button;
39
+ border: 1px solid $color-button-border;
40
+ border-radius: 0.25rem;
41
+ color: $color-button-text;
42
+ cursor: pointer;
43
+ display: inline-block;
44
+ font-size: 1rem;
45
+ font-weight: 900;
46
+ line-height: 1.5;
47
+ padding: 0.375rem 0.75rem;
48
+ text-align: center;
49
+ text-decoration: none;
50
+ user-select: none;
51
+ vertical-align: middle;
52
+
53
+ &:disabled {
54
+ color: color.scale($color-button-text, $lightness: 70%);
55
+ cursor: not-allowed;
56
+ }
57
57
  }
58
58
 
59
59
  .edith-btn-group {
60
- display: inline-flex;
61
- position: relative;
62
- vertical-align: middle;
63
-
64
- &:not(:first-child) {
65
- margin-left: 10px;
66
- }
67
-
68
- :not(:first-child) {
69
- margin-left: -1px;
70
- }
71
-
72
- .edith-btn:not(:last-child) {
73
- border-bottom-right-radius: 0;
74
- border-top-right-radius: 0;
75
- }
76
-
77
- .edith-btn:not(:first-child) {
78
- border-bottom-left-radius: 0;
79
- border-top-left-radius: 0;
80
- }
60
+ display: inline-flex;
61
+ position: relative;
62
+ vertical-align: middle;
63
+
64
+ &:not(:first-child) {
65
+ margin-left: 10px;
66
+ }
67
+
68
+ :not(:first-child) {
69
+ margin-left: -1px;
70
+ }
71
+
72
+ .edith-btn:not(:last-child) {
73
+ border-bottom-right-radius: 0;
74
+ border-top-right-radius: 0;
75
+ }
76
+
77
+ .edith-btn:not(:first-child) {
78
+ border-bottom-left-radius: 0;
79
+ border-top-left-radius: 0;
80
+ }
81
81
  }
82
82
 
83
83
  .edith-btn-nbsp {
84
- &::before {
85
- content: "\0020";
86
- display: block;
87
- height: 16px;
88
- width: 12px;
89
- }
84
+ &::before {
85
+ content: "\0020";
86
+ display: block;
87
+ height: 16px;
88
+ width: 12px;
89
+ }
90
90
  }
91
91
 
92
92
  .edith-tooltip {
93
- background: $color-tooltip;
94
- border-radius: 4px;
95
- color: $color-tooltip-text;
96
- font-size: 13px;
97
- font-weight: bold;
98
- padding: 4px 8px;
99
- z-index: 10;
100
-
101
- .arrow,
102
- .arrow::before {
103
- background: inherit;
104
- height: 8px;
105
- position: absolute;
106
- width: 8px;
107
- }
108
-
109
- .arrow {
110
- visibility: hidden;
111
- }
112
-
113
- .arrow::before {
114
- content: "";
115
- transform: rotate(45deg);
116
- visibility: visible;
117
- }
118
-
119
- &[data-popper-placement^="top"] > .arrow {
120
- bottom: -4px;
121
- }
122
-
123
- &[data-popper-placement^="bottom"] > .arrow {
124
- top: -4px;
125
- }
126
-
127
- &[data-popper-placement^="left"] > .arrow {
128
- right: -4px;
129
- }
130
-
131
- &[data-popper-placement^="right"] > .arrow {
132
- left: -4px;
133
- }
93
+ background: $color-tooltip;
94
+ border-radius: 4px;
95
+ color: $color-tooltip-text;
96
+ font-size: 13px;
97
+ font-weight: bold;
98
+ padding: 4px 8px;
99
+ z-index: 10;
100
+
101
+ .arrow,
102
+ .arrow::before {
103
+ background: inherit;
104
+ height: 8px;
105
+ position: absolute;
106
+ width: 8px;
107
+ }
108
+
109
+ .arrow {
110
+ visibility: hidden;
111
+ }
112
+
113
+ .arrow::before {
114
+ content: "";
115
+ transform: rotate(45deg);
116
+ visibility: visible;
117
+ }
118
+
119
+ &[data-popper-placement^="top"] > .arrow {
120
+ bottom: -4px;
121
+ }
122
+
123
+ &[data-popper-placement^="bottom"] > .arrow {
124
+ top: -4px;
125
+ }
126
+
127
+ &[data-popper-placement^="left"] > .arrow {
128
+ right: -4px;
129
+ }
130
+
131
+ &[data-popper-placement^="right"] > .arrow {
132
+ left: -4px;
133
+ }
134
134
  }
135
135
 
136
136
  .edith-editing-area {
137
- background-color: $color-editor;
138
- border-radius: 0.25rem;
139
- margin-top: 5px;
140
- padding: 5px;
137
+ background-color: $color-editor;
138
+ border-radius: 0.25rem;
139
+ margin-top: 5px;
140
+ padding: 5px;
141
141
  }
142
142
 
143
143
  .edith-visual,
144
144
  .edith-code {
145
- height: 100%;
146
- outline: none;
147
- overflow: auto;
145
+ height: 100%;
146
+ outline: none;
147
+ overflow: auto;
148
148
  }
149
149
 
150
150
  .edith-hidden {
151
- display: none;
151
+ display: none;
152
152
  }
153
153
 
154
154
  .edith-visual {
155
- color: $color-editor-text;
155
+ color: $color-editor-text;
156
156
 
157
- .edith-nbsp {
158
- color: color.scale($color-button-text, $lightness: 70%);
159
- }
157
+ .edith-nbsp {
158
+ color: color.scale($color-button-text, $lightness: 70%);
159
+ }
160
160
  }
161
161
 
162
162
  .edith-modal {
163
- background: $color-modal;
164
- border: 2px solid $color-modal-border;
165
- border-radius: 10px;
166
- left: calc(50% - 200px);
167
- position: fixed;
168
- top: 20%;
169
- width: 400px;
170
- z-index: 10;
171
-
172
- .edith-modal-header {
173
- border-bottom: 1px solid $color-modal-border;
174
- color: $color-modal-title;
175
- font-size: 20px;
176
- font-weight: 700;
177
- line-height: 1.4;
178
- padding: 5px 10px;
179
- }
180
-
181
- .edith-modal-content {
182
- color: $color-modal-text;
183
- margin: 10px;
184
- }
185
-
186
- .edith-modal-input {
187
- display: flex;
188
- flex-wrap: wrap;
189
- margin: 10px 0;
190
-
191
- label,
192
- input {
193
- width: 100%;
194
- }
195
-
196
- input {
197
- appearance: none;
198
- background-clip: padding-box;
199
- background-color: $color-modal;
200
- border: 1px solid $color-checkbox-border;
201
- border-radius: 0.25rem;
202
- font-size: 1rem;
203
- font-weight: 400;
204
- line-height: 1.5;
205
- outline: 0;
206
- padding: 0.375rem 0.75rem;
207
- width: 100%;
208
- }
209
-
210
- label {
211
- font-size: 16px;
212
- font-weight: 700;
213
- margin-bottom: 5px;
214
- }
215
- }
216
-
217
- .edith-modal-checkbox {
218
- margin: 10px 0;
219
-
220
- label {
221
- display: flex;
222
- }
223
-
224
- input {
225
- appearance: none;
226
- background-color: $color-modal;
227
- background-position: 50%;
228
- background-repeat: no-repeat;
229
- background-size: contain;
230
- border: 1px solid $color-checkbox-border;
231
- border-radius: 0.25em;
232
- height: 1em;
233
- margin-top: 0.25em;
234
- vertical-align: top;
235
- width: 1em;
236
-
237
- &:checked {
238
- background-color: $color-checkbox-background;
239
- background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3E%3C/svg%3E");
240
- border-color: $color-checkbox-background;
241
- }
242
- }
243
- }
244
-
245
- .edith-modal-footer {
246
- border-top: 1px solid $color-modal-border;
247
- display: flex;
248
- justify-content: flex-end;
249
- padding: 5px 10px;
250
-
251
- :not(:last-child) {
252
- margin-right: 10px;
253
- }
254
- }
255
-
256
- .edith-modal-cancel,
257
- .edith-modal-submit {
258
- border: 1px solid transparent;
259
- border-radius: 0.25rem;
260
- cursor: pointer;
261
- display: inline-block;
262
- font-size: 1rem;
263
- font-weight: 400;
264
- line-height: 1.5;
265
- padding: 0.375rem 0.75rem;
266
- text-align: center;
267
- text-decoration: none;
268
- user-select: none;
269
- vertical-align: middle;
270
- }
271
-
272
- .edith-modal-cancel {
273
- background-color: $color-modal-cancel-background;
274
- border-color: $color-modal-cancel-border;
275
- color: $color-modal-cancel-color;
276
- }
277
-
278
- .edith-modal-submit {
279
- background-color: $color-modal-submit-background;
280
- border-color: $color-modal-submit-border;
281
- color: $color-modal-submit-color;
282
- }
163
+ background: $color-modal;
164
+ border: 2px solid $color-modal-border;
165
+ border-radius: 10px;
166
+ left: calc(50% - 200px);
167
+ position: fixed;
168
+ top: 20%;
169
+ width: 400px;
170
+ z-index: 10;
171
+
172
+ .edith-modal-header {
173
+ border-bottom: 1px solid $color-modal-border;
174
+ color: $color-modal-title;
175
+ font-size: 20px;
176
+ font-weight: 700;
177
+ line-height: 1.4;
178
+ padding: 5px 10px;
179
+ }
180
+
181
+ .edith-modal-content {
182
+ color: $color-modal-text;
183
+ margin: 10px;
184
+ }
185
+
186
+ .edith-modal-input {
187
+ display: flex;
188
+ flex-wrap: wrap;
189
+ margin: 10px 0;
190
+
191
+ label,
192
+ input {
193
+ width: 100%;
194
+ }
195
+
196
+ input {
197
+ appearance: none;
198
+ background-clip: padding-box;
199
+ background-color: $color-modal;
200
+ border: 1px solid $color-checkbox-border;
201
+ border-radius: 0.25rem;
202
+ font-size: 1rem;
203
+ font-weight: 400;
204
+ line-height: 1.5;
205
+ outline: 0;
206
+ padding: 0.375rem 0.75rem;
207
+ width: 100%;
208
+ }
209
+
210
+ label {
211
+ font-size: 16px;
212
+ font-weight: 700;
213
+ margin-bottom: 5px;
214
+ }
215
+ }
216
+
217
+ .edith-modal-checkbox {
218
+ margin: 10px 0;
219
+
220
+ label {
221
+ display: flex;
222
+ }
223
+
224
+ input {
225
+ appearance: none;
226
+ background-color: $color-modal;
227
+ background-position: 50%;
228
+ background-repeat: no-repeat;
229
+ background-size: contain;
230
+ border: 1px solid $color-checkbox-border;
231
+ border-radius: 0.25em;
232
+ height: 1em;
233
+ margin-top: 0.25em;
234
+ vertical-align: top;
235
+ width: 1em;
236
+
237
+ &:checked {
238
+ background-color: $color-checkbox-background;
239
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3E%3C/svg%3E");
240
+ border-color: $color-checkbox-background;
241
+ }
242
+ }
243
+ }
244
+
245
+ .edith-modal-footer {
246
+ border-top: 1px solid $color-modal-border;
247
+ display: flex;
248
+ justify-content: flex-end;
249
+ padding: 5px 10px;
250
+
251
+ :not(:last-child) {
252
+ margin-right: 10px;
253
+ }
254
+ }
255
+
256
+ .edith-modal-cancel,
257
+ .edith-modal-submit {
258
+ border: 1px solid transparent;
259
+ border-radius: 0.25rem;
260
+ cursor: pointer;
261
+ display: inline-block;
262
+ font-size: 1rem;
263
+ font-weight: 400;
264
+ line-height: 1.5;
265
+ padding: 0.375rem 0.75rem;
266
+ text-align: center;
267
+ text-decoration: none;
268
+ user-select: none;
269
+ vertical-align: middle;
270
+ }
271
+
272
+ .edith-modal-cancel {
273
+ background-color: $color-modal-cancel-background;
274
+ border-color: $color-modal-cancel-border;
275
+ color: $color-modal-cancel-color;
276
+ }
277
+
278
+ .edith-modal-submit {
279
+ background-color: $color-modal-submit-background;
280
+ border-color: $color-modal-submit-border;
281
+ color: $color-modal-submit-color;
282
+ }
283
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lesjoursfr/edith",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "Simple WYSIWYG editor.",
5
5
  "license": "MIT",
6
6
  "repository": "lesjoursfr/edith",
@@ -12,7 +12,7 @@
12
12
  "access": "public"
13
13
  },
14
14
  "engines": {
15
- "node": "18.x || 20.x"
15
+ "node": "20.x || 22.x"
16
16
  },
17
17
  "browserslist": [
18
18
  "> 1%",
@@ -24,8 +24,8 @@
24
24
  "type": "module",
25
25
  "scripts": {
26
26
  "freshlock": "rm -rf node_modules/ && rm .yarn/install-state.gz && rm yarn.lock && yarn",
27
- "eslint-check": "eslint . --ext .js,.jsx,.ts,.tsx",
28
- "eslint-fix": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
27
+ "eslint-check": "eslint",
28
+ "eslint-fix": "eslint --fix",
29
29
  "stylelint-check": "stylelint **/*.scss",
30
30
  "stylelint-fix": "stylelint **/*.scss --fix",
31
31
  "prettier-check": "prettier --check .",
@@ -47,52 +47,55 @@
47
47
  "editor"
48
48
  ],
49
49
  "dependencies": {
50
- "@lesjoursfr/browser-tools": "^1.1.2"
50
+ "@lesjoursfr/browser-tools": "^1.1.4",
51
+ "dompurify": "^3.1.6"
51
52
  },
52
53
  "devDependencies": {
53
- "@babel/core": "^7.23.9",
54
- "@babel/preset-env": "^7.23.9",
55
- "@codemirror/lang-html": "^6.4.8",
56
- "@fortawesome/fontawesome-free": "^6.5.1",
54
+ "@babel/core": "^7.25.2",
55
+ "@babel/preset-env": "^7.25.4",
56
+ "@codemirror/lang-html": "^6.4.9",
57
+ "@eslint/js": "^9.10.0",
58
+ "@fortawesome/fontawesome-free": "^6.6.0",
57
59
  "@popperjs/core": "^2.11.8",
58
- "@tsconfig/next": "^2.0.1",
60
+ "@tsconfig/next": "^2.0.3",
59
61
  "@types/babel__core": "^7.20.5",
60
- "@types/babel__preset-env": "^7.9.6",
62
+ "@types/babel__preset-env": "^7.9.7",
61
63
  "@types/color": "^3.0.6",
62
- "@types/jsdom": "^21.1.6",
63
- "@types/mocha": "^10.0.6",
64
- "@types/node": "^20.11.20",
65
- "@typescript-eslint/eslint-plugin": "^7.1.0",
66
- "@typescript-eslint/parser": "^7.1.0",
64
+ "@types/dompurify": "^3.0.5",
65
+ "@types/jsdom": "^21.1.7",
66
+ "@types/mocha": "^10.0.8",
67
+ "@types/node": "^20.16.5",
67
68
  "babel-loader": "^9.1.3",
68
69
  "codemirror": "^6.0.1",
69
- "css-loader": "^6.10.0",
70
- "css-minimizer-webpack-plugin": "^6.0.0",
71
- "eslint": "^8.57.0",
70
+ "css-loader": "^7.1.2",
71
+ "css-minimizer-webpack-plugin": "^7.0.0",
72
+ "eslint": "^9.10.0",
72
73
  "eslint-config-prettier": "^9.1.0",
73
74
  "fs-extra": "^11.2.0",
74
- "jsdom": "^24.0.0",
75
- "mini-css-extract-plugin": "^2.8.0",
76
- "mocha": "^10.3.0",
77
- "postcss": "^8.4.35",
78
- "prettier": "^3.2.5",
79
- "sass": "^1.71.1",
80
- "sass-loader": "^14.1.1",
81
- "stylelint": "^16.2.1",
82
- "stylelint-config-sass-guidelines": "^11.0.0",
75
+ "globals": "^15.9.0",
76
+ "jsdom": "^25.0.0",
77
+ "mini-css-extract-plugin": "^2.9.1",
78
+ "mocha": "^10.7.3",
79
+ "postcss": "^8.4.45",
80
+ "prettier": "^3.3.3",
81
+ "sass": "^1.78.0",
82
+ "sass-loader": "^16.0.1",
83
+ "stylelint": "^16.9.0",
84
+ "stylelint-config-standard-scss": "^13.1.0",
83
85
  "terser-webpack-plugin": "^5.3.10",
84
86
  "ts-loader": "^9.5.1",
85
87
  "ts-node": "^10.9.2",
86
- "typescript": "^5.3.3",
87
- "webpack": "^5.90.3",
88
+ "typescript": "^5.6.2",
89
+ "typescript-eslint": "^8.5.0",
90
+ "webpack": "^5.94.0",
88
91
  "webpack-cli": "^5.1.4",
89
- "webpack-dev-server": "^5.0.2"
92
+ "webpack-dev-server": "^5.1.0"
90
93
  },
91
94
  "peerDependencies": {
92
- "@codemirror/lang-html": "^6.4.8",
93
- "@fortawesome/fontawesome-free": "^6.5.1",
95
+ "@codemirror/lang-html": "^6.4.9",
96
+ "@fortawesome/fontawesome-free": "^6.6.0",
94
97
  "@popperjs/core": "^2.11.8",
95
98
  "codemirror": "^6.0.1"
96
99
  },
97
- "packageManager": "yarn@4.1.0"
100
+ "packageManager": "yarn@4.4.1"
98
101
  }
package/src/core/edit.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  trimTag,
15
15
  unwrapNode,
16
16
  } from "@lesjoursfr/browser-tools";
17
+ import DOMPurify from "dompurify";
17
18
  import { getSelection, moveCursorAfterNode, moveCursorInsideNode, selectNodeContents, selectNodes } from "./range.js";
18
19
 
19
20
  /**
@@ -393,7 +394,7 @@ export function cleanDomContent(root: HTMLElement, style: { [keyof: string]: boo
393
394
  export function cleanPastedHtml(html: string, style: { [keyof: string]: boolean }): HTMLElement {
394
395
  // Create a new div with the HTML content
395
396
  const result = document.createElement("div");
396
- result.innerHTML = html;
397
+ result.innerHTML = DOMPurify.sanitize(html, { USE_PROFILES: { html: true } });
397
398
 
398
399
  // Clean the HTML content
399
400
  cleanDomContent(result, style);
@@ -24,260 +24,260 @@ $color-modal-submit-color: #fff;
24
24
  $color-modal-submit-border: #0d6efd;
25
25
 
26
26
  .edith {
27
- background-color: $color-toolbar;
28
- border: 1px solid $color-toolbar-border;
29
- border-radius: 0.25rem;
30
- padding: 5px;
27
+ background-color: $color-toolbar;
28
+ border: 1px solid $color-toolbar-border;
29
+ border-radius: 0.25rem;
30
+ padding: 5px;
31
31
  }
32
32
 
33
33
  .edith-toolbar {
34
- background-color: $color-toolbar;
34
+ background-color: $color-toolbar;
35
35
  }
36
36
 
37
37
  .edith-btn {
38
- background-color: $color-button;
39
- border: 1px solid $color-button-border;
40
- border-radius: 0.25rem;
41
- color: $color-button-text;
42
- cursor: pointer;
43
- display: inline-block;
44
- font-size: 1rem;
45
- font-weight: 900;
46
- line-height: 1.5;
47
- padding: 0.375rem 0.75rem;
48
- text-align: center;
49
- text-decoration: none;
50
- user-select: none;
51
- vertical-align: middle;
52
-
53
- &:disabled {
54
- color: color.scale($color-button-text, $lightness: 70%);
55
- cursor: not-allowed;
56
- }
38
+ background-color: $color-button;
39
+ border: 1px solid $color-button-border;
40
+ border-radius: 0.25rem;
41
+ color: $color-button-text;
42
+ cursor: pointer;
43
+ display: inline-block;
44
+ font-size: 1rem;
45
+ font-weight: 900;
46
+ line-height: 1.5;
47
+ padding: 0.375rem 0.75rem;
48
+ text-align: center;
49
+ text-decoration: none;
50
+ user-select: none;
51
+ vertical-align: middle;
52
+
53
+ &:disabled {
54
+ color: color.scale($color-button-text, $lightness: 70%);
55
+ cursor: not-allowed;
56
+ }
57
57
  }
58
58
 
59
59
  .edith-btn-group {
60
- display: inline-flex;
61
- position: relative;
62
- vertical-align: middle;
63
-
64
- &:not(:first-child) {
65
- margin-left: 10px;
66
- }
67
-
68
- :not(:first-child) {
69
- margin-left: -1px;
70
- }
71
-
72
- .edith-btn:not(:last-child) {
73
- border-bottom-right-radius: 0;
74
- border-top-right-radius: 0;
75
- }
76
-
77
- .edith-btn:not(:first-child) {
78
- border-bottom-left-radius: 0;
79
- border-top-left-radius: 0;
80
- }
60
+ display: inline-flex;
61
+ position: relative;
62
+ vertical-align: middle;
63
+
64
+ &:not(:first-child) {
65
+ margin-left: 10px;
66
+ }
67
+
68
+ :not(:first-child) {
69
+ margin-left: -1px;
70
+ }
71
+
72
+ .edith-btn:not(:last-child) {
73
+ border-bottom-right-radius: 0;
74
+ border-top-right-radius: 0;
75
+ }
76
+
77
+ .edith-btn:not(:first-child) {
78
+ border-bottom-left-radius: 0;
79
+ border-top-left-radius: 0;
80
+ }
81
81
  }
82
82
 
83
83
  .edith-btn-nbsp {
84
- &::before {
85
- content: "\0020";
86
- display: block;
87
- height: 16px;
88
- width: 12px;
89
- }
84
+ &::before {
85
+ content: "\0020";
86
+ display: block;
87
+ height: 16px;
88
+ width: 12px;
89
+ }
90
90
  }
91
91
 
92
92
  .edith-tooltip {
93
- background: $color-tooltip;
94
- border-radius: 4px;
95
- color: $color-tooltip-text;
96
- font-size: 13px;
97
- font-weight: bold;
98
- padding: 4px 8px;
99
- z-index: 10;
100
-
101
- .arrow,
102
- .arrow::before {
103
- background: inherit;
104
- height: 8px;
105
- position: absolute;
106
- width: 8px;
107
- }
108
-
109
- .arrow {
110
- visibility: hidden;
111
- }
112
-
113
- .arrow::before {
114
- content: "";
115
- transform: rotate(45deg);
116
- visibility: visible;
117
- }
118
-
119
- &[data-popper-placement^="top"] > .arrow {
120
- bottom: -4px;
121
- }
122
-
123
- &[data-popper-placement^="bottom"] > .arrow {
124
- top: -4px;
125
- }
126
-
127
- &[data-popper-placement^="left"] > .arrow {
128
- right: -4px;
129
- }
130
-
131
- &[data-popper-placement^="right"] > .arrow {
132
- left: -4px;
133
- }
93
+ background: $color-tooltip;
94
+ border-radius: 4px;
95
+ color: $color-tooltip-text;
96
+ font-size: 13px;
97
+ font-weight: bold;
98
+ padding: 4px 8px;
99
+ z-index: 10;
100
+
101
+ .arrow,
102
+ .arrow::before {
103
+ background: inherit;
104
+ height: 8px;
105
+ position: absolute;
106
+ width: 8px;
107
+ }
108
+
109
+ .arrow {
110
+ visibility: hidden;
111
+ }
112
+
113
+ .arrow::before {
114
+ content: "";
115
+ transform: rotate(45deg);
116
+ visibility: visible;
117
+ }
118
+
119
+ &[data-popper-placement^="top"] > .arrow {
120
+ bottom: -4px;
121
+ }
122
+
123
+ &[data-popper-placement^="bottom"] > .arrow {
124
+ top: -4px;
125
+ }
126
+
127
+ &[data-popper-placement^="left"] > .arrow {
128
+ right: -4px;
129
+ }
130
+
131
+ &[data-popper-placement^="right"] > .arrow {
132
+ left: -4px;
133
+ }
134
134
  }
135
135
 
136
136
  .edith-editing-area {
137
- background-color: $color-editor;
138
- border-radius: 0.25rem;
139
- margin-top: 5px;
140
- padding: 5px;
137
+ background-color: $color-editor;
138
+ border-radius: 0.25rem;
139
+ margin-top: 5px;
140
+ padding: 5px;
141
141
  }
142
142
 
143
143
  .edith-visual,
144
144
  .edith-code {
145
- height: 100%;
146
- outline: none;
147
- overflow: auto;
145
+ height: 100%;
146
+ outline: none;
147
+ overflow: auto;
148
148
  }
149
149
 
150
150
  .edith-hidden {
151
- display: none;
151
+ display: none;
152
152
  }
153
153
 
154
154
  .edith-visual {
155
- color: $color-editor-text;
155
+ color: $color-editor-text;
156
156
 
157
- .edith-nbsp {
158
- color: color.scale($color-button-text, $lightness: 70%);
159
- }
157
+ .edith-nbsp {
158
+ color: color.scale($color-button-text, $lightness: 70%);
159
+ }
160
160
  }
161
161
 
162
162
  .edith-modal {
163
- background: $color-modal;
164
- border: 2px solid $color-modal-border;
165
- border-radius: 10px;
166
- left: calc(50% - 200px);
167
- position: fixed;
168
- top: 20%;
169
- width: 400px;
170
- z-index: 10;
171
-
172
- .edith-modal-header {
173
- border-bottom: 1px solid $color-modal-border;
174
- color: $color-modal-title;
175
- font-size: 20px;
176
- font-weight: 700;
177
- line-height: 1.4;
178
- padding: 5px 10px;
179
- }
180
-
181
- .edith-modal-content {
182
- color: $color-modal-text;
183
- margin: 10px;
184
- }
185
-
186
- .edith-modal-input {
187
- display: flex;
188
- flex-wrap: wrap;
189
- margin: 10px 0;
190
-
191
- label,
192
- input {
193
- width: 100%;
194
- }
195
-
196
- input {
197
- appearance: none;
198
- background-clip: padding-box;
199
- background-color: $color-modal;
200
- border: 1px solid $color-checkbox-border;
201
- border-radius: 0.25rem;
202
- font-size: 1rem;
203
- font-weight: 400;
204
- line-height: 1.5;
205
- outline: 0;
206
- padding: 0.375rem 0.75rem;
207
- width: 100%;
208
- }
209
-
210
- label {
211
- font-size: 16px;
212
- font-weight: 700;
213
- margin-bottom: 5px;
214
- }
215
- }
216
-
217
- .edith-modal-checkbox {
218
- margin: 10px 0;
219
-
220
- label {
221
- display: flex;
222
- }
223
-
224
- input {
225
- appearance: none;
226
- background-color: $color-modal;
227
- background-position: 50%;
228
- background-repeat: no-repeat;
229
- background-size: contain;
230
- border: 1px solid $color-checkbox-border;
231
- border-radius: 0.25em;
232
- height: 1em;
233
- margin-top: 0.25em;
234
- vertical-align: top;
235
- width: 1em;
236
-
237
- &:checked {
238
- background-color: $color-checkbox-background;
239
- background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3E%3C/svg%3E");
240
- border-color: $color-checkbox-background;
241
- }
242
- }
243
- }
244
-
245
- .edith-modal-footer {
246
- border-top: 1px solid $color-modal-border;
247
- display: flex;
248
- justify-content: flex-end;
249
- padding: 5px 10px;
250
-
251
- :not(:last-child) {
252
- margin-right: 10px;
253
- }
254
- }
255
-
256
- .edith-modal-cancel,
257
- .edith-modal-submit {
258
- border: 1px solid transparent;
259
- border-radius: 0.25rem;
260
- cursor: pointer;
261
- display: inline-block;
262
- font-size: 1rem;
263
- font-weight: 400;
264
- line-height: 1.5;
265
- padding: 0.375rem 0.75rem;
266
- text-align: center;
267
- text-decoration: none;
268
- user-select: none;
269
- vertical-align: middle;
270
- }
271
-
272
- .edith-modal-cancel {
273
- background-color: $color-modal-cancel-background;
274
- border-color: $color-modal-cancel-border;
275
- color: $color-modal-cancel-color;
276
- }
277
-
278
- .edith-modal-submit {
279
- background-color: $color-modal-submit-background;
280
- border-color: $color-modal-submit-border;
281
- color: $color-modal-submit-color;
282
- }
163
+ background: $color-modal;
164
+ border: 2px solid $color-modal-border;
165
+ border-radius: 10px;
166
+ left: calc(50% - 200px);
167
+ position: fixed;
168
+ top: 20%;
169
+ width: 400px;
170
+ z-index: 10;
171
+
172
+ .edith-modal-header {
173
+ border-bottom: 1px solid $color-modal-border;
174
+ color: $color-modal-title;
175
+ font-size: 20px;
176
+ font-weight: 700;
177
+ line-height: 1.4;
178
+ padding: 5px 10px;
179
+ }
180
+
181
+ .edith-modal-content {
182
+ color: $color-modal-text;
183
+ margin: 10px;
184
+ }
185
+
186
+ .edith-modal-input {
187
+ display: flex;
188
+ flex-wrap: wrap;
189
+ margin: 10px 0;
190
+
191
+ label,
192
+ input {
193
+ width: 100%;
194
+ }
195
+
196
+ input {
197
+ appearance: none;
198
+ background-clip: padding-box;
199
+ background-color: $color-modal;
200
+ border: 1px solid $color-checkbox-border;
201
+ border-radius: 0.25rem;
202
+ font-size: 1rem;
203
+ font-weight: 400;
204
+ line-height: 1.5;
205
+ outline: 0;
206
+ padding: 0.375rem 0.75rem;
207
+ width: 100%;
208
+ }
209
+
210
+ label {
211
+ font-size: 16px;
212
+ font-weight: 700;
213
+ margin-bottom: 5px;
214
+ }
215
+ }
216
+
217
+ .edith-modal-checkbox {
218
+ margin: 10px 0;
219
+
220
+ label {
221
+ display: flex;
222
+ }
223
+
224
+ input {
225
+ appearance: none;
226
+ background-color: $color-modal;
227
+ background-position: 50%;
228
+ background-repeat: no-repeat;
229
+ background-size: contain;
230
+ border: 1px solid $color-checkbox-border;
231
+ border-radius: 0.25em;
232
+ height: 1em;
233
+ margin-top: 0.25em;
234
+ vertical-align: top;
235
+ width: 1em;
236
+
237
+ &:checked {
238
+ background-color: $color-checkbox-background;
239
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3E%3C/svg%3E");
240
+ border-color: $color-checkbox-background;
241
+ }
242
+ }
243
+ }
244
+
245
+ .edith-modal-footer {
246
+ border-top: 1px solid $color-modal-border;
247
+ display: flex;
248
+ justify-content: flex-end;
249
+ padding: 5px 10px;
250
+
251
+ :not(:last-child) {
252
+ margin-right: 10px;
253
+ }
254
+ }
255
+
256
+ .edith-modal-cancel,
257
+ .edith-modal-submit {
258
+ border: 1px solid transparent;
259
+ border-radius: 0.25rem;
260
+ cursor: pointer;
261
+ display: inline-block;
262
+ font-size: 1rem;
263
+ font-weight: 400;
264
+ line-height: 1.5;
265
+ padding: 0.375rem 0.75rem;
266
+ text-align: center;
267
+ text-decoration: none;
268
+ user-select: none;
269
+ vertical-align: middle;
270
+ }
271
+
272
+ .edith-modal-cancel {
273
+ background-color: $color-modal-cancel-background;
274
+ border-color: $color-modal-cancel-border;
275
+ color: $color-modal-cancel-color;
276
+ }
277
+
278
+ .edith-modal-submit {
279
+ background-color: $color-modal-submit-background;
280
+ border-color: $color-modal-submit-border;
281
+ color: $color-modal-submit-color;
282
+ }
283
283
  }