first commit

This commit is contained in:
2025-06-17 11:53:18 +02:00
commit 9f0f7ba12b
8804 changed files with 1369176 additions and 0 deletions

View File

@ -0,0 +1,159 @@
import { JoomlaEditor, JoomlaEditorDecorator } from 'editor-api';
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
/**
* EditorNone Decorator for Joomla.Editor
*/
// eslint-disable-next-line max-classes-per-file
class EditorNoneDecorator extends JoomlaEditorDecorator {
/**
* @returns {string}
*/
getValue() {
return this.instance.getValue();
}
/**
* @param {string} value
* @returns {EditorNoneDecorator}
*/
setValue(value) {
this.instance.setValue(value);
return this;
}
/**
* @returns {string}
*/
getSelection() {
return this.instance.getSelection();
}
replaceSelection(value) {
this.instance.replaceSelection(value);
return this;
}
disable(enable) {
if (this.instance.editor) {
this.instance.editor.disabled = !enable;
this.instance.editor.readOnly = !enable;
}
return this;
}
}
class JoomlaEditorNone extends HTMLElement {
constructor() {
super();
// Properties
this.editor = '';
// Bindings
this.unregisterEditor = this.unregisterEditor.bind(this);
this.registerEditor = this.registerEditor.bind(this);
this.childrenChange = this.childrenChange.bind(this);
this.getSelection = this.getSelection.bind(this);
// Watch for children changes.
// eslint-disable-next-line no-return-assign
new MutationObserver(() => this.childrenChange()).observe(this, {
childList: true
});
// Find out when editor is interacted
this.interactionCallback = () => {
if (this.editor) {
JoomlaEditor.setActive(this.editor.id);
}
};
}
/**
* Lifecycle
*/
connectedCallback() {
// Note the mutation observer won't fire for initial contents,
// so childrenChange is also called here.
this.childrenChange();
this.addEventListener('click', this.interactionCallback);
}
/**
* Lifecycle
*/
disconnectedCallback() {
this.unregisterEditor();
this.removeEventListener('click', this.interactionCallback);
}
/**
* Get editor value
*/
getValue() {
return this.editor.value;
}
/**
* Set editor value
* @param {string} text
*/
setValue(text) {
this.editor.value = text;
}
/**
* Get the selected text
*/
getSelection() {
if (this.editor.selectionStart || this.editor.selectionStart === 0) {
return this.editor.value.substring(this.editor.selectionStart, this.editor.selectionEnd);
}
return this.editor.value;
}
/**
* Replace selected text
* @param {string} text
*/
replaceSelection(text) {
const ed = this.editor;
if (ed.selectionStart || ed.selectionStart === 0) {
ed.value = ed.value.substring(0, ed.selectionStart) + text + ed.value.substring(ed.selectionEnd, ed.value.length);
} else {
ed.value += text;
}
}
/**
* Register the editor
*/
registerEditor() {
const jEditor = new EditorNoneDecorator(this, 'none', this.editor.id);
JoomlaEditor.register(jEditor);
}
/**
* Remove the editor from the Joomla API
*/
unregisterEditor() {
if (this.editor) {
JoomlaEditor.unregister(this.editor.id);
}
}
/**
* Called when element's child list changes
*/
childrenChange() {
// Ensure the first child is an input with a textarea type.
if (this.firstElementChild && this.firstElementChild.tagName && this.firstElementChild.tagName.toLowerCase() === 'textarea' && this.firstElementChild.getAttribute('id')) {
this.editor = this.firstElementChild;
this.unregisterEditor();
this.registerEditor();
}
}
}
customElements.define('joomla-editor-none', JoomlaEditorNone);

View File

@ -0,0 +1 @@
import{JoomlaEditor,JoomlaEditorDecorator}from"editor-api";class EditorNoneDecorator extends JoomlaEditorDecorator{getValue(){return this.instance.getValue()}setValue(t){return this.instance.setValue(t),this}getSelection(){return this.instance.getSelection()}replaceSelection(t){return this.instance.replaceSelection(t),this}disable(t){return this.instance.editor&&(this.instance.editor.disabled=!t,this.instance.editor.readOnly=!t),this}}class JoomlaEditorNone extends HTMLElement{constructor(){super(),this.editor="",this.unregisterEditor=this.unregisterEditor.bind(this),this.registerEditor=this.registerEditor.bind(this),this.childrenChange=this.childrenChange.bind(this),this.getSelection=this.getSelection.bind(this),new MutationObserver((()=>this.childrenChange())).observe(this,{childList:!0}),this.interactionCallback=()=>{this.editor&&JoomlaEditor.setActive(this.editor.id)}}connectedCallback(){this.childrenChange(),this.addEventListener("click",this.interactionCallback)}disconnectedCallback(){this.unregisterEditor(),this.removeEventListener("click",this.interactionCallback)}getValue(){return this.editor.value}setValue(t){this.editor.value=t}getSelection(){return this.editor.selectionStart||0===this.editor.selectionStart?this.editor.value.substring(this.editor.selectionStart,this.editor.selectionEnd):this.editor.value}replaceSelection(t){const e=this.editor;e.selectionStart||0===e.selectionStart?e.value=e.value.substring(0,e.selectionStart)+t+e.value.substring(e.selectionEnd,e.value.length):e.value+=t}registerEditor(){const t=new EditorNoneDecorator(this,"none",this.editor.id);JoomlaEditor.register(t)}unregisterEditor(){this.editor&&JoomlaEditor.unregister(this.editor.id)}childrenChange(){this.firstElementChild&&this.firstElementChild.tagName&&"textarea"===this.firstElementChild.tagName.toLowerCase()&&this.firstElementChild.getAttribute("id")&&(this.editor=this.firstElementChild,this.unregisterEditor(),this.registerEditor())}}customElements.define("joomla-editor-none",JoomlaEditorNone);

Binary file not shown.