mirror of
https://github.com/Karaka-Management/oms-Editor.git
synced 2026-02-16 10:18:41 +00:00
cleanup and tests added for ci/cd
This commit is contained in:
parent
99687a2fee
commit
81581f6103
|
|
@ -3,9 +3,9 @@ import { Markdown } from '../../../jsOMS/Utils/Parser/Markdown.js';
|
||||||
export class Editor {
|
export class Editor {
|
||||||
constructor (id)
|
constructor (id)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.editor = document.getElementById(id);
|
this.editor = document.getElementById(id);
|
||||||
this.markdown = new Markdown.Converter({extensions: [], sanitize: true});
|
this.markdown = new Markdown.Converter({extensions: [], sanitize: true});
|
||||||
this.editorContent = null;
|
this.editorContent = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -51,29 +51,29 @@ export class Editor {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'bold':
|
case 'bold':
|
||||||
startOffset = 2;
|
startOffset = 2;
|
||||||
endOffset = 2;
|
endOffset = 2;
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ '**' + textarea.value.slice(startPosition, endPosition) + '**'
|
+ '**' + textarea.value.slice(startPosition, endPosition) + '**'
|
||||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||||
break;
|
break;
|
||||||
case 'italic':
|
case 'italic':
|
||||||
startOffset = 1;
|
startOffset = 1;
|
||||||
endOffset = 1;
|
endOffset = 1;
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ '*' + textarea.value.slice(startPosition, endPosition) + '*'
|
+ '*' + textarea.value.slice(startPosition, endPosition) + '*'
|
||||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||||
break;
|
break;
|
||||||
case 'underline':
|
case 'underline':
|
||||||
startOffset = 2;
|
startOffset = 2;
|
||||||
endOffset = 2;
|
endOffset = 2;
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ '__' + textarea.value.slice(startPosition, endPosition) + '__'
|
+ '__' + textarea.value.slice(startPosition, endPosition) + '__'
|
||||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||||
break;
|
break;
|
||||||
case 'strikethrough':
|
case 'strikethrough':
|
||||||
startOffset = 2;
|
startOffset = 2;
|
||||||
endOffset = 2;
|
endOffset = 2;
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ '~~' + textarea.value.slice(startPosition, endPosition) + '~~'
|
+ '~~' + textarea.value.slice(startPosition, endPosition) + '~~'
|
||||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||||
|
|
@ -132,22 +132,22 @@ export class Editor {
|
||||||
case 'link':
|
case 'link':
|
||||||
startOffset = 1;
|
startOffset = 1;
|
||||||
endOffset = 0;
|
endOffset = 0;
|
||||||
let link = textarea.value.slice(startPosition, endPosition);
|
let link = textarea.value.slice(startPosition, endPosition);
|
||||||
|
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ ((link.startsWith('http') || link.startsWith('www')) ? '[' + link + ']' : '[' + link + '](https://www.website.com "' + link + '")')
|
+ ((link.startsWith('http') || link.startsWith('www')) ? '[' + link + ']' : '[' + link + '](https://www.website.com "' + link + '")')
|
||||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||||
break;
|
break;
|
||||||
case 'code':
|
case 'code':
|
||||||
startOffset = 1;
|
startOffset = 1;
|
||||||
endOffset = 1;
|
endOffset = 1;
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ '`' + textarea.value.slice(startPosition, endPosition) + '`'
|
+ '`' + textarea.value.slice(startPosition, endPosition) + '`'
|
||||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||||
break;
|
break;
|
||||||
case 'quote':
|
case 'quote':
|
||||||
startOffset = 2;
|
startOffset = 2;
|
||||||
endOffset = 0;
|
endOffset = 0;
|
||||||
textarea.value = textarea.value.slice(0, startPosition)
|
textarea.value = textarea.value.slice(0, startPosition)
|
||||||
+ '> ' + textarea.value.slice(startPosition, textarea.value.length);
|
+ '> ' + textarea.value.slice(startPosition, textarea.value.length);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the content
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -104,7 +106,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $content
|
* Set the content
|
||||||
|
*
|
||||||
|
* @param string $content Content
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -116,7 +120,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $plain
|
* Set the plain text
|
||||||
|
*
|
||||||
|
* @param string $plain Plain text
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
|
|
@ -128,6 +134,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the plain text
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -138,6 +146,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get created at
|
||||||
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -148,6 +158,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the id
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -158,6 +170,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get created by
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -168,7 +182,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* Set created by
|
||||||
|
*
|
||||||
|
* @param int $id Creator
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -178,6 +194,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the title
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -188,7 +206,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $title
|
* Set the title
|
||||||
|
*
|
||||||
|
* @param string $title Title
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
|
|
@ -200,6 +220,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the path
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -210,7 +232,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* Set the path if file
|
||||||
|
*
|
||||||
|
* @param string $path Path to file
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ use phpOMS\Views\View;
|
||||||
*/
|
*/
|
||||||
class BaseView extends View
|
class BaseView extends View
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Editor id
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
private $id = '';
|
private $id = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,6 +53,13 @@ class BaseView extends View
|
||||||
$this->addData('text', $view);
|
$this->addData('text', $view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the editor id
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderId() : string
|
public function renderId() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->id);
|
return $this->printHtml($this->id);
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ use phpOMS\Views\View;
|
||||||
*/
|
*/
|
||||||
class TextView extends View
|
class TextView extends View
|
||||||
{
|
{
|
||||||
private $id = '';
|
private string $id = '';
|
||||||
private $name = '';
|
private string $name = '';
|
||||||
private $form = '';
|
private string $form = '';
|
||||||
private $plain = '';
|
private string $plain = '';
|
||||||
private $preview = '';
|
private string $preview = '';
|
||||||
private $tplText = '';
|
private string $tplText = '';
|
||||||
private $tplValue = '';
|
private string $tplValue = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
|
@ -47,36 +47,87 @@ class TextView extends View
|
||||||
$this->setTemplate('/Modules/Editor/Theme/Backend/Components/Editor/inline-editor');
|
$this->setTemplate('/Modules/Editor/Theme/Backend/Components/Editor/inline-editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the form id
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderId() : string
|
public function renderId() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->id);
|
return $this->printHtml($this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the form name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderName() : string
|
public function renderName() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->name);
|
return $this->printHtml($this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the form attribute name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderForm() : string
|
public function renderForm() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->form);
|
return $this->printHtml($this->form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the preview
|
||||||
|
*
|
||||||
|
* Usually markdown
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderPreview() : string
|
public function renderPreview() : string
|
||||||
{
|
{
|
||||||
return $this->preview;
|
return $this->preview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the plain text
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderPlain() : string
|
public function renderPlain() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->plain);
|
return $this->printHtml($this->plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render template text reference
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderTplText() : string
|
public function renderTplText() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->tplText);
|
return $this->printHtml($this->tplText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render template value reference
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
public function renderTplValue() : string
|
public function renderTplValue() : string
|
||||||
{
|
{
|
||||||
return $this->printHtml($this->tplValue);
|
return $this->printHtml($this->tplValue);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user