Current File : /home/pacjaorg/.trash/media.1/plg_editors_codemirror/js/joomla-editor-codemirror.min.js |
import{JoomlaEditor as s,JoomlaEditorDecorator as n}from"editor-api";import{keymap as c,createFromTextarea as r,EditorState as l}from"codemirror";/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/class a extends n{getValue(){return this.instance.state.doc.toString()}setValue(e){const t=this.instance;return t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}}),this}getSelection(){const{state:e}=this.instance;return e.sliceDoc(e.selection.main.from,e.selection.main.to)}replaceSelection(e){const t=this.instance.state.replaceSelection(e);return this.instance.dispatch(t),this}disable(e){const t=this.instance;return t.state.config.compartments.forEach((d,i)=>{i.$j_name==="readOnly"&&t.dispatch({effects:i.reconfigure(l.readOnly.of(!e))})}),this}}class h extends HTMLElement{constructor(){super(),this.toggleFullScreen=()=>{this.classList.contains("fullscreen")?this.closeFullScreen():(this.classList.add("fullscreen"),document.documentElement.scrollTop=0,document.documentElement.style.overflow="hidden")},this.closeFullScreen=()=>{this.classList.remove("fullscreen"),document.documentElement.style.overflow=""},this.interactionCallback=()=>{s.setActive(this.element.id)}}get options(){return JSON.parse(this.getAttribute("options"))}get fsCombo(){return this.getAttribute("fs-combo")}async connectedCallback(){const{options:e}=this;this.fsCombo&&(e.customExtensions=e.customExtensions||[],e.customExtensions.push(()=>c.of([{key:this.fsCombo,run:this.toggleFullScreen},{key:"Escape",run:this.closeFullScreen}])),this.bsModals=this.querySelectorAll(".joomla-modal.modal"),this.bsModals.forEach(t=>document.body.appendChild(t))),this.element=this.querySelector("textarea"),this.instance=await r(this.element,e),this.jEditor=new a(this.instance,"codemirror",this.element.id),s.register(this.jEditor),this.addEventListener("click",this.interactionCallback)}disconnectedCallback(){this.instance&&(this.element.style.display="",this.instance.destroy()),s.unregister(this.element.id),this.removeEventListener("click",this.interactionCallback),this.bsModals&&this.bsModals.length&&this.bsModals.forEach(e=>this.appendChild(e))}}customElements.define("joomla-editor-codemirror",h);