first commit
This commit is contained in:
329
plugins/editors/codemirror/codemirror.xml
Normal file
329
plugins/editors/codemirror/codemirror.xml
Normal file
@@ -0,0 +1,329 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="editors" method="upgrade">
|
||||
<name>plg_editors_codemirror</name>
|
||||
<version>5.65.15</version>
|
||||
<creationDate>28 March 2011</creationDate>
|
||||
<author>Marijn Haverbeke</author>
|
||||
<authorEmail>marijnh@gmail.com</authorEmail>
|
||||
<authorUrl>https://codemirror.net/</authorUrl>
|
||||
<copyright>Copyright (C) 2014 - 2021 by Marijn Haverbeke <marijnh@gmail.com> and others</copyright>
|
||||
<license>MIT license: https://codemirror.net/LICENSE</license>
|
||||
<description>PLG_CODEMIRROR_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\Editors\CodeMirror</namespace>
|
||||
<files>
|
||||
<filename>fonts.json</filename>
|
||||
<folder>layouts</folder>
|
||||
<folder plugin="codemirror">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_editors_codemirror.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_editors_codemirror.sys.ini</language>
|
||||
</languages>
|
||||
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic">
|
||||
<field
|
||||
name="lineNumbers"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_CODEMIRROR_FIELD_LINENUMBERS_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="codeFolding"
|
||||
type="radio"
|
||||
label="PLG_CODEMIRROR_FIELD_CODEFOLDING_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="markerGutter"
|
||||
type="radio"
|
||||
label="PLG_CODEMIRROR_FIELD_MARKERGUTTER_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="lineWrapping"
|
||||
type="radio"
|
||||
label="PLG_CODEMIRROR_FIELD_LINEWRAPPING_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="activeLine"
|
||||
type="radio"
|
||||
label="PLG_CODEMIRROR_FIELD_ACTIVELINE_LABEL"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="selectionMatches"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_CODEMIRROR_FIELD_SELECTIONMATCHES_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="matchTags"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_CODEMIRROR_FIELD_MATCHTAGS_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="matchBrackets"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_CODEMIRROR_FIELD_MATCHBRACKETS_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="autoCloseTags"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_CODEMIRROR_FIELD_AUTOCLOSETAGS_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="autoCloseBrackets"
|
||||
type="radio"
|
||||
layout="joomla.form.field.radio.switcher"
|
||||
label="PLG_CODEMIRROR_FIELD_AUTOCLOSEBRACKET_LABEL"
|
||||
default="1"
|
||||
filter="integer"
|
||||
>
|
||||
<option value="0">JOFF</option>
|
||||
<option value="1">JON</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="keyMap"
|
||||
type="list"
|
||||
label="PLG_CODEMIRROR_FIELD_KEYMAP_LABEL"
|
||||
description="PLG_CODEMIRROR_FIELD_KEYMAP_DESC"
|
||||
default=""
|
||||
validate="options"
|
||||
>
|
||||
<option value="">JDEFAULT</option>
|
||||
<option value="emacs">PLG_CODEMIRROR_FIELD_KEYMAP_EMACS</option>
|
||||
<option value="sublime">PLG_CODEMIRROR_FIELD_KEYMAP_SUBLIME</option>
|
||||
<option value="vim">PLG_CODEMIRROR_FIELD_KEYMAP_VIM</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="fullScreen"
|
||||
type="list"
|
||||
label="PLG_CODEMIRROR_FIELD_FULLSCREEN_LABEL"
|
||||
default="F10"
|
||||
validate="options"
|
||||
>
|
||||
<option value="F1">F1</option>
|
||||
<option value="F2">F2</option>
|
||||
<option value="F3">F3</option>
|
||||
<option value="F4">F4</option>
|
||||
<option value="F5">F5</option>
|
||||
<option value="F6">F6</option>
|
||||
<option value="F7">F7</option>
|
||||
<option value="F8">F8</option>
|
||||
<option value="F9">F9</option>
|
||||
<option value="F10">F10</option>
|
||||
<option value="F11">F11</option>
|
||||
<option value="F12">F12</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="fullScreenMod"
|
||||
type="checkboxes"
|
||||
label="PLG_CODEMIRROR_FIELD_FULLSCREEN_MOD_LABEL"
|
||||
>
|
||||
<option value="Shift">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_SHIFT</option>
|
||||
<option value="Cmd">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_CMD</option>
|
||||
<option value="Ctrl">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_CTRL</option>
|
||||
<option value="Alt">PLG_CODEMIRROR_FIELD_VALUE_FULLSCREEN_MOD_ALT</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
|
||||
<fieldset
|
||||
name="appearance"
|
||||
label="PLG_CODEMIRROR_FIELDSET_APPEARANCE_OPTIONS_LABEL"
|
||||
addfieldprefix="Joomla\Plugin\Editors\CodeMirror\Field"
|
||||
>
|
||||
<field
|
||||
name="theme"
|
||||
type="filelist"
|
||||
label="PLG_CODEMIRROR_FIELD_THEME_LABEL"
|
||||
default=""
|
||||
fileFilter="\.css$"
|
||||
stripext="true"
|
||||
hide_none="true"
|
||||
hide_default="false"
|
||||
directory="media/vendor/codemirror/theme"
|
||||
validate="options"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="activeLineColor"
|
||||
type="color"
|
||||
label="PLG_CODEMIRROR_FIELD_ACTIVELINE_COLOR_LABEL"
|
||||
default="#a4c2eb"
|
||||
filter="color"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="highlightMatchColor"
|
||||
type="color"
|
||||
label="PLG_CODEMIRROR_FIELD_HIGHLIGHT_MATCH_COLOR_LABEL"
|
||||
default="#fa542f"
|
||||
filter="color"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="fontFamily"
|
||||
type="fonts"
|
||||
label="PLG_CODEMIRROR_FIELD_FONT_FAMILY_LABEL"
|
||||
default="0"
|
||||
>
|
||||
<option value="0">PLG_CODEMIRROR_FIELD_VALUE_FONT_FAMILY_DEFAULT</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="fontSize"
|
||||
type="integer"
|
||||
label="PLG_CODEMIRROR_FIELD_FONT_SIZE_LABEL"
|
||||
first="6"
|
||||
last="16"
|
||||
step="1"
|
||||
default="13"
|
||||
filter="integer"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="lineHeight"
|
||||
type="list"
|
||||
label="PLG_CODEMIRROR_FIELD_LINE_HEIGHT_LABEL"
|
||||
default="1.2"
|
||||
filter="float"
|
||||
validate="options"
|
||||
>
|
||||
<option value="1">1</option>
|
||||
<option value="1.1">1.1</option>
|
||||
<option value="1.2">1.2</option>
|
||||
<option value="1.3">1.3</option>
|
||||
<option value="1.4">1.4</option>
|
||||
<option value="1.5">1.5</option>
|
||||
<option value="1.6">1.6</option>
|
||||
<option value="1.7">1.7</option>
|
||||
<option value="1.8">1.8</option>
|
||||
<option value="1.9">1.9</option>
|
||||
<option value="2">2</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="scrollbarStyle"
|
||||
type="list"
|
||||
label="PLG_CODEMIRROR_FIELD_VALUE_SCROLLBARSTYLE_LABEL"
|
||||
default="native"
|
||||
validate="options"
|
||||
>
|
||||
<option value="native">PLG_CODEMIRROR_FIELD_VALUE_SCROLLBARSTYLE_DEFAULT</option>
|
||||
<option value="simple">PLG_CODEMIRROR_FIELD_VALUE_SCROLLBARSTYLE_SIMPLE</option>
|
||||
<option value="overlay">PLG_CODEMIRROR_FIELD_VALUE_SCROLLBARSTYLE_OVERLAY</option>
|
||||
</field>
|
||||
|
||||
<field
|
||||
name="preview"
|
||||
type="editor"
|
||||
label="PLG_CODEMIRROR_FIELD_PREVIEW_LABEL"
|
||||
editor="codemirror"
|
||||
filter="unset"
|
||||
buttons="false"
|
||||
>
|
||||
<default>
|
||||
<![CDATA[
|
||||
<script type="text/javascript">
|
||||
[].forEach.call(document.getElementsByClassName('hello'), function (el) {el.innerHtml = 'Hello World';});
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
h1 {
|
||||
background-clip: border-box;
|
||||
background-color: #cacaff;
|
||||
background-image: linear-gradient(45deg, transparent 0px, transparent 30px, #ababff 30px, #ababff 60px, transparent 60px);
|
||||
background-repeat: repeat-x;
|
||||
background-size: 90px 100%;
|
||||
border: 1px solid #8989ff;
|
||||
border-radius: 10px;
|
||||
color: #333;
|
||||
padding: 0 15px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam a ornare lectus, quis semper urna. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus interdum metus id elit rutrum sollicitudin. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam in fermentum risus, id facilisis nulla. Phasellus gravida erat sed ullamcorper accumsan. Donec blandit sem eget sem congue, a varius sapien semper.</p>
|
||||
<p>Integer euismod tempor convallis. Nullam porttitor et ex ac fringilla. Quisque facilisis est ac erat condimentum malesuada. Aenean commodo quam odio, tincidunt ultricies mauris suscipit et.</p>
|
||||
|
||||
<ul>
|
||||
<li>Vivamus ultrices ligula a odio lacinia pellentesque.</li>
|
||||
<li>Curabitur iaculis arcu pharetra, mollis turpis id, commodo erat.</li>
|
||||
<li>Etiam consequat enim quis faucibus interdum.</li>
|
||||
<li>Morbi in ipsum pulvinar, eleifend lorem sit amet, euismod magna.</li>
|
||||
<li>Donec consectetur lacus vitae eros euismod porta.</li>
|
||||
</ul>
|
||||
</div>
|
||||
]]>
|
||||
</default>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
107
plugins/editors/codemirror/fonts.json
Normal file
107
plugins/editors/codemirror/fonts.json
Normal file
@@ -0,0 +1,107 @@
|
||||
{
|
||||
"anonymous_pro": {
|
||||
"name": "Anonymous Pro",
|
||||
"url": "https://fonts.googleapis.com/css?family=Anonymous+Pro",
|
||||
"css": "'Anonymous Pro', monospace"
|
||||
},
|
||||
"cousine": {
|
||||
"name": "Cousine",
|
||||
"url": "https://fonts.googleapis.com/css?family=Cousine",
|
||||
"css": "Cousine, monospace"
|
||||
},
|
||||
"cutive_mono": {
|
||||
"name": "Cutive Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Cutive+Mono",
|
||||
"css": "'Cutive Mono', monospace"
|
||||
},
|
||||
"droid_sans_mono": {
|
||||
"name": "Droid Sans Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Droid+Sans+Mono",
|
||||
"css": "'Droid Sans Mono', monospace"
|
||||
},
|
||||
"fira_mono": {
|
||||
"name": "Fira Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Fira+Mono",
|
||||
"css": "'Fira Mono', monospace"
|
||||
},
|
||||
"ibm_plex_mono": {
|
||||
"name": "IBM Plex Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=IBM+Plex+Mono",
|
||||
"css": "'IBM Plex Mono', monospace;"
|
||||
},
|
||||
"inconsolata": {
|
||||
"name": "Inconsolata",
|
||||
"url": "https://fonts.googleapis.com/css?family=Inconsolata",
|
||||
"css": "Inconsolata, monospace"
|
||||
},
|
||||
"lekton": {
|
||||
"name": "Lekton",
|
||||
"url": "https://fonts.googleapis.com/css?family=Lekton",
|
||||
"css": "Lekton, monospace"
|
||||
},
|
||||
"nanum_gothic_coding": {
|
||||
"name": "Nanum Gothic Coding",
|
||||
"url": "https://fonts.googleapis.com/css?family=Nanum+Gothic+Coding",
|
||||
"css": "'Nanum Gothic Coding', monospace"
|
||||
},
|
||||
"nova_mono": {
|
||||
"name": "Nova Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Nova+Mono",
|
||||
"css": "'Nova Mono', monospace"
|
||||
},
|
||||
"overpass_mono": {
|
||||
"name": "Overpass Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Overpass+Mono",
|
||||
"css": "'Overpass Mono', monospace"
|
||||
},
|
||||
"oxygen_mono": {
|
||||
"name": "Oxygen Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Oxygen+Mono",
|
||||
"css": "'Oxygen Mono', monospace"
|
||||
},
|
||||
"press_start_2p": {
|
||||
"name": "Press Start 2P",
|
||||
"url": "https://fonts.googleapis.com/css?family=Press+Start+2P",
|
||||
"css": "'Press Start 2P', monospace"
|
||||
},
|
||||
"pt_mono": {
|
||||
"name": "PT Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=PT+Mono",
|
||||
"css": "'PT Mono', monospace"
|
||||
},
|
||||
"roboto_mono": {
|
||||
"name": "Roboto Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Roboto+Mono",
|
||||
"css": "'Roboto Mono', monospace"
|
||||
},
|
||||
"rubik_mono_one": {
|
||||
"name": "Rubik Mono One",
|
||||
"url": "https://fonts.googleapis.com/css?family=Rubik+Mono+One",
|
||||
"css": "'Rubik Mono One', monospace"
|
||||
},
|
||||
"share_tech_mono": {
|
||||
"name": "Share Tech Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Share+Tech+Mono",
|
||||
"css": "'Share Tech Mono', monospace"
|
||||
},
|
||||
"source_code_pro": {
|
||||
"name": "Source Code Pro",
|
||||
"url": "https://fonts.googleapis.com/css?family=Source+Code+Pro",
|
||||
"css": "'Source Code Pro', monospace"
|
||||
},
|
||||
"space_mono": {
|
||||
"name": "Space Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Space+Mono",
|
||||
"css": "'Space Mono', monospace"
|
||||
},
|
||||
"ubuntu_mono": {
|
||||
"name": "Ubuntu Mono",
|
||||
"url": "https://fonts.googleapis.com/css?family=Ubuntu+Mono",
|
||||
"css": "'Ubuntu Mono', monospace"
|
||||
},
|
||||
"vt323": {
|
||||
"name": "VT323",
|
||||
"url": "https://fonts.googleapis.com/css?family=VT323",
|
||||
"css": "'VT323', monospace"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Editors.codemirror
|
||||
*
|
||||
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
$options = $displayData->options;
|
||||
$params = $displayData->params;
|
||||
$name = $displayData->name;
|
||||
$id = $displayData->id;
|
||||
$cols = $displayData->cols;
|
||||
$rows = $displayData->rows;
|
||||
$content = $displayData->content;
|
||||
$extJS = JDEBUG ? '.js' : '.min.js';
|
||||
$modifier = $params->get('fullScreenMod', []) ? implode(' + ', $params->get('fullScreenMod', [])) . ' + ' : '';
|
||||
$basePath = $displayData->basePath;
|
||||
$modePath = $displayData->modePath;
|
||||
$modPath = 'mod-path="' . Uri::root() . $modePath . $extJS . '"';
|
||||
$fskeys = $params->get('fullScreenMod', []);
|
||||
$fskeys[] = $params->get('fullScreen', 'F10');
|
||||
$fullScreenCombo = implode('-', $fskeys);
|
||||
$fsCombo = 'fs-combo=' . json_encode($fullScreenCombo);
|
||||
$option = 'options=\'' . json_encode($options) . '\'';
|
||||
$mediaVersion = Factory::getDocument()->getMediaVersion();
|
||||
$editor = 'editor="' . ltrim(HTMLHelper::_('script', $basePath . 'lib/codemirror' . $extJS, ['version' => 'auto', 'pathOnly' => true]), '/') . '?' . $mediaVersion . '"';
|
||||
$addons = 'addons="' . ltrim(HTMLHelper::_('script', $basePath . 'lib/addons' . $extJS, ['version' => 'auto', 'pathOnly' => true]), '/') . '?' . $mediaVersion . '"';
|
||||
|
||||
// Remove the fullscreen message and option if readonly not null.
|
||||
if (isset($options->readOnly)) {
|
||||
$fsCombo = '';
|
||||
}
|
||||
|
||||
Factory::getDocument()->getWebAssetManager()
|
||||
->registerAndUseStyle('codemirror.lib.main', $basePath . 'lib/codemirror.css')
|
||||
->registerAndUseStyle('codemirror.lib.addons', $basePath . 'lib/addons.css', [], [], ['codemirror.lib.main'])
|
||||
->registerScript(
|
||||
'webcomponent.editor-codemirror-es5',
|
||||
'plg_editors_codemirror/joomla-editor-codemirror-es5.min.js',
|
||||
['dependencies' => ['wcpolyfill']],
|
||||
['defer' => true, 'nomodule' => true],
|
||||
['wcpolyfill']
|
||||
)
|
||||
->registerAndUseScript(
|
||||
'webcomponent.editor-codemirror',
|
||||
'plg_editors_codemirror/joomla-editor-codemirror.min.js',
|
||||
[],
|
||||
['type' => 'module'],
|
||||
['webcomponent.editor-codemirror-es5']
|
||||
);
|
||||
?>
|
||||
<joomla-editor-codemirror <?php echo $editor . ' ' . $addons . ' ' . $modPath . ' ' . $fsCombo . ' ' . $option; ?>>
|
||||
<?php echo '<textarea name="', $name, '" id="', $id, '" cols="', $cols, '" rows="', $rows, '">', $content, '</textarea>'; ?>
|
||||
<?php if ($fsCombo !== '') { ?>
|
||||
<p class="small float-end">
|
||||
<?php echo Text::sprintf('PLG_CODEMIRROR_TOGGLE_FULL_SCREEN', $fullScreenCombo); ?>
|
||||
</p>
|
||||
<?php }; ?>
|
||||
</joomla-editor-codemirror>
|
||||
<?php echo $displayData->buttons; ?>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Editors.codemirror
|
||||
*
|
||||
* @copyright (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
$params = $displayData->params;
|
||||
$fontFamily = $displayData->fontFamily ?? 'monospace';
|
||||
$fontSize = $params->get('fontSize', 13) . 'px;';
|
||||
$lineHeight = $params->get('lineHeight', 1.2) . 'em;';
|
||||
|
||||
// Set the active line color.
|
||||
$color = $params->get('activeLineColor', '#a4c2eb');
|
||||
$r = hexdec($color[1] . $color[2]);
|
||||
$g = hexdec($color[3] . $color[4]);
|
||||
$b = hexdec($color[5] . $color[6]);
|
||||
$activeLineColor = 'rgba(' . $r . ', ' . $g . ', ' . $b . ', .5)';
|
||||
|
||||
// Set the color for matched tags.
|
||||
$color = $params->get('highlightMatchColor', '#fa542f');
|
||||
$r = hexdec($color[1] . $color[2]);
|
||||
$g = hexdec($color[3] . $color[4]);
|
||||
$b = hexdec($color[5] . $color[6]);
|
||||
$highlightMatchColor = 'rgba(' . $r . ', ' . $g . ', ' . $b . ', .5)';
|
||||
|
||||
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
$wa->registerAndUseStyle('plg_editors_codemirror', 'plg_editors_codemirror/codemirror.css');
|
||||
$wa->addInlineStyle(
|
||||
<<<CSS
|
||||
.CodeMirror {
|
||||
font-family: $fontFamily;
|
||||
font-size: $fontSize;
|
||||
line-height: $lineHeight;
|
||||
height: calc(100vh - 600px);
|
||||
min-height: 400px;
|
||||
max-height: 800px;
|
||||
}
|
||||
.CodeMirror-activeline-background { background: $activeLineColor; }
|
||||
.CodeMirror-matchingtag { background: $highlightMatchColor; }
|
||||
.cm-matchhighlight {background-color: $highlightMatchColor; }
|
||||
.CodeMirror-selection-highlight-scrollbar {background-color: $highlightMatchColor; }
|
||||
CSS
|
||||
);
|
||||
48
plugins/editors/codemirror/services/provider.php
Normal file
48
plugins/editors/codemirror/services/provider.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Editors.codemirror
|
||||
*
|
||||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Extension\PluginInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\Editors\CodeMirror\Extension\Codemirror;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.3.0
|
||||
*/
|
||||
public function register(Container $container)
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$dispatcher = $container->get(DispatcherInterface::class);
|
||||
|
||||
$plugin = new Codemirror(
|
||||
$dispatcher,
|
||||
(array) PluginHelper::getPlugin('editors', 'codemirror')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
316
plugins/editors/codemirror/src/Extension/Codemirror.php
Normal file
316
plugins/editors/codemirror/src/Extension/Codemirror.php
Normal file
@@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Editors.codemirror
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Editors\CodeMirror\Extension;
|
||||
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Layout\LayoutHelper;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Event\Event;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* CodeMirror Editor Plugin.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
final class Codemirror extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Affects constructor behavior. If true, language files will be loaded automatically.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 3.1.4
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
/**
|
||||
* Mapping of syntax to CodeMirror modes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modeAlias = [];
|
||||
|
||||
/**
|
||||
* Base path for editor assets.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $basePath = 'media/vendor/codemirror/';
|
||||
|
||||
/**
|
||||
* Base path for editor modes.
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $modePath = 'media/vendor/codemirror/mode/%N/%N';
|
||||
|
||||
/**
|
||||
* Initialises the Editor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onInit()
|
||||
{
|
||||
static $done = false;
|
||||
|
||||
// Do this only once.
|
||||
if ($done) {
|
||||
return;
|
||||
}
|
||||
|
||||
$done = true;
|
||||
|
||||
// Most likely need this later
|
||||
$doc = $this->getApplication()->getDocument();
|
||||
|
||||
// Codemirror shall have its own group of plugins to modify and extend its behavior
|
||||
PluginHelper::importPlugin('editors_codemirror');
|
||||
|
||||
// At this point, params can be modified by a plugin before going to the layout renderer.
|
||||
$this->getApplication()->triggerEvent('onCodeMirrorBeforeInit', [&$this->params, &$this->basePath, &$this->modePath]);
|
||||
|
||||
$displayData = (object) ['params' => $this->params];
|
||||
$font = $this->params->get('fontFamily', '0');
|
||||
$fontInfo = $this->getFontInfo($font);
|
||||
|
||||
if (isset($fontInfo)) {
|
||||
if (isset($fontInfo->url)) {
|
||||
$doc->addStyleSheet($fontInfo->url);
|
||||
}
|
||||
|
||||
if (isset($fontInfo->css)) {
|
||||
$displayData->fontFamily = $fontInfo->css . '!important';
|
||||
}
|
||||
}
|
||||
|
||||
// We need to do output buffering here because layouts may actually 'echo' things which we do not want.
|
||||
ob_start();
|
||||
LayoutHelper::render('editors.codemirror.styles', $displayData, JPATH_PLUGINS . '/editors/codemirror/layouts');
|
||||
ob_end_clean();
|
||||
|
||||
$this->getApplication()->triggerEvent('onCodeMirrorAfterInit', [&$this->params, &$this->basePath, &$this->modePath]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the editor area.
|
||||
*
|
||||
* @param string $name The control name.
|
||||
* @param string $content The contents of the text area.
|
||||
* @param string $width The width of the text area (px or %).
|
||||
* @param string $height The height of the text area (px or %).
|
||||
* @param int $col The number of columns for the textarea.
|
||||
* @param int $row The number of rows for the textarea.
|
||||
* @param boolean $buttons True and the editor buttons will be displayed.
|
||||
* @param string $id An optional ID for the textarea (note: since 1.6). If not supplied the name is used.
|
||||
* @param string $asset Not used.
|
||||
* @param object $author Not used.
|
||||
* @param array $params Associative array of editor parameters.
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function onDisplay(
|
||||
$name,
|
||||
$content,
|
||||
$width,
|
||||
$height,
|
||||
$col,
|
||||
$row,
|
||||
$buttons = true,
|
||||
$id = null,
|
||||
$asset = null,
|
||||
$author = null,
|
||||
$params = []
|
||||
) {
|
||||
// True if a CodeMirror already has autofocus. Prevent multiple autofocuses.
|
||||
static $autofocused;
|
||||
|
||||
$id = empty($id) ? $name : $id;
|
||||
|
||||
// Must pass the field id to the buttons in this editor.
|
||||
$buttons = $this->displayButtons($id, $buttons, $asset, $author);
|
||||
|
||||
// Only add "px" to width and height if they are not given as a percentage.
|
||||
$width .= is_numeric($width) ? 'px' : '';
|
||||
$height .= is_numeric($height) ? 'px' : '';
|
||||
|
||||
// Options for the CodeMirror constructor.
|
||||
$options = new \stdClass();
|
||||
$keyMapUrl = '';
|
||||
|
||||
// Is field readonly?
|
||||
if (!empty($params['readonly'])) {
|
||||
$options->readOnly = 'nocursor';
|
||||
}
|
||||
|
||||
// Should we focus on the editor on load?
|
||||
if (!$autofocused) {
|
||||
$options->autofocus = isset($params['autofocus']) ? (bool) $params['autofocus'] : false;
|
||||
$autofocused = $options->autofocus;
|
||||
}
|
||||
// Set autorefresh to true - fixes issue when editor is not loaded in a focused tab
|
||||
$options->autoRefresh = true;
|
||||
|
||||
$options->lineWrapping = (bool) $this->params->get('lineWrapping', 1);
|
||||
|
||||
// Add styling to the active line.
|
||||
$options->styleActiveLine = (bool) $this->params->get('activeLine', 1);
|
||||
|
||||
// Do we highlight selection matches?
|
||||
if ($this->params->get('selectionMatches', 1)) {
|
||||
$options->highlightSelectionMatches = [
|
||||
'showToken' => true,
|
||||
'annotateScrollbar' => true,
|
||||
];
|
||||
}
|
||||
|
||||
// Do we use line numbering?
|
||||
if ($options->lineNumbers = (bool) $this->params->get('lineNumbers', 1)) {
|
||||
$options->gutters[] = 'CodeMirror-linenumbers';
|
||||
}
|
||||
|
||||
// Do we use code folding?
|
||||
if ($options->foldGutter = (bool) $this->params->get('codeFolding', 1)) {
|
||||
$options->gutters[] = 'CodeMirror-foldgutter';
|
||||
}
|
||||
|
||||
// Do we use a marker gutter?
|
||||
if ($options->markerGutter = (bool) $this->params->get('markerGutter', $this->params->get('marker-gutter', 1))) {
|
||||
$options->gutters[] = 'CodeMirror-markergutter';
|
||||
}
|
||||
|
||||
// Load the syntax mode.
|
||||
$syntax = !empty($params['syntax'])
|
||||
? $params['syntax']
|
||||
: $this->params->get('syntax', 'html');
|
||||
$options->mode = $this->modeAlias[$syntax] ?? $syntax;
|
||||
|
||||
// Load the theme if specified.
|
||||
if ($theme = $this->params->get('theme')) {
|
||||
$options->theme = $theme;
|
||||
|
||||
$this->getApplication()->getDocument()->getWebAssetManager()
|
||||
->registerAndUseStyle('codemirror.theme', $this->basePath . 'theme/' . $theme . '.css');
|
||||
}
|
||||
|
||||
// Special options for tagged modes (xml/html).
|
||||
if (in_array($options->mode, ['xml', 'html', 'php'])) {
|
||||
// Autogenerate closing tags (html/xml only).
|
||||
$options->autoCloseTags = (bool) $this->params->get('autoCloseTags', 1);
|
||||
|
||||
// Highlight the matching tag when the cursor is in a tag (html/xml only).
|
||||
$options->matchTags = (bool) $this->params->get('matchTags', 1);
|
||||
}
|
||||
|
||||
// Special options for non-tagged modes.
|
||||
if (!in_array($options->mode, ['xml', 'html'])) {
|
||||
// Autogenerate closing brackets.
|
||||
$options->autoCloseBrackets = (bool) $this->params->get('autoCloseBrackets', 1);
|
||||
|
||||
// Highlight the matching bracket.
|
||||
$options->matchBrackets = (bool) $this->params->get('matchBrackets', 1);
|
||||
}
|
||||
|
||||
$options->scrollbarStyle = $this->params->get('scrollbarStyle', 'native');
|
||||
|
||||
// KeyMap settings.
|
||||
$options->keyMap = $this->params->get('keyMap', false);
|
||||
|
||||
// Support for older settings.
|
||||
if ($options->keyMap === false) {
|
||||
$options->keyMap = $this->params->get('vimKeyBinding', 0) ? 'vim' : 'default';
|
||||
}
|
||||
|
||||
if ($options->keyMap !== 'default') {
|
||||
$keyMapUrl = HTMLHelper::_('script', $this->basePath . 'keymap/' . $options->keyMap . '.min.js', ['relative' => false, 'pathOnly' => true]);
|
||||
$keyMapUrl .= '?' . $this->getApplication()->getDocument()->getMediaVersion();
|
||||
}
|
||||
|
||||
$options->keyMapUrl = $keyMapUrl;
|
||||
|
||||
$displayData = (object) [
|
||||
'options' => $options,
|
||||
'params' => $this->params,
|
||||
'name' => $name,
|
||||
'id' => $id,
|
||||
'cols' => $col,
|
||||
'rows' => $row,
|
||||
'content' => $content,
|
||||
'buttons' => $buttons,
|
||||
'basePath' => $this->basePath,
|
||||
'modePath' => $this->modePath,
|
||||
];
|
||||
|
||||
// At this point, displayData can be modified by a plugin before going to the layout renderer.
|
||||
$results = $this->getApplication()->triggerEvent('onCodeMirrorBeforeDisplay', [&$displayData]);
|
||||
|
||||
$results[] = LayoutHelper::render('editors.codemirror.element', $displayData, JPATH_PLUGINS . '/editors/codemirror/layouts');
|
||||
|
||||
foreach ($this->getApplication()->triggerEvent('onCodeMirrorAfterDisplay', [&$displayData]) as $result) {
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
return implode("\n", $results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the editor buttons.
|
||||
*
|
||||
* @param string $name Button name.
|
||||
* @param mixed $buttons [array with button objects | boolean true to display buttons]
|
||||
* @param mixed $asset Unused.
|
||||
* @param mixed $author Unused.
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
protected function displayButtons($name, $buttons, $asset, $author)
|
||||
{
|
||||
if (is_array($buttons) || (is_bool($buttons) && $buttons)) {
|
||||
$buttonsEvent = new Event(
|
||||
'getButtons',
|
||||
[
|
||||
'editor' => $name,
|
||||
'buttons' => $buttons,
|
||||
]
|
||||
);
|
||||
|
||||
$buttonsResult = $this->getDispatcher()->dispatch('getButtons', $buttonsEvent);
|
||||
$buttons = $buttonsResult['result'];
|
||||
|
||||
return LayoutHelper::render('joomla.editors.buttons', $buttons);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets font info from the json data file
|
||||
*
|
||||
* @param string $font A key from the $fonts array.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected function getFontInfo($font)
|
||||
{
|
||||
static $fonts;
|
||||
|
||||
if (!$fonts) {
|
||||
$fonts = json_decode(file_get_contents(JPATH_PLUGINS . '/editors/codemirror/fonts.json'), true);
|
||||
}
|
||||
|
||||
return isset($fonts[$font]) ? (object) $fonts[$font] : null;
|
||||
}
|
||||
}
|
||||
56
plugins/editors/codemirror/src/Field/FontsField.php
Normal file
56
plugins/editors/codemirror/src/Field/FontsField.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Editors.codemirror
|
||||
*
|
||||
* @copyright (C) 2014 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\Editors\CodeMirror\Field;
|
||||
|
||||
use Joomla\CMS\Form\Field\ListField;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of fonts
|
||||
*
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Editors.codemirror
|
||||
* @since 3.4
|
||||
*/
|
||||
class FontsField extends ListField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.4
|
||||
*/
|
||||
protected $type = 'Fonts';
|
||||
|
||||
/**
|
||||
* Method to get the list of fonts field options.
|
||||
*
|
||||
* @return array The field option objects.
|
||||
*
|
||||
* @since 3.4
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$fonts = json_decode(file_get_contents(JPATH_PLUGINS . '/editors/codemirror/fonts.json'));
|
||||
$options = [];
|
||||
|
||||
foreach ($fonts as $key => $info) {
|
||||
$options[] = HTMLHelper::_('select.option', $key, $info->name);
|
||||
}
|
||||
|
||||
// Merge any additional options in the XML definition.
|
||||
return array_merge(parent::getOptions(), $options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user