mirror of
https://github.com/Karaka-Management/oms-Editor.git
synced 2026-02-06 21:58: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 {
|
||||
constructor (id)
|
||||
{
|
||||
this.id = id;
|
||||
this.editor = document.getElementById(id);
|
||||
this.markdown = new Markdown.Converter({extensions: [], sanitize: true});
|
||||
this.id = id;
|
||||
this.editor = document.getElementById(id);
|
||||
this.markdown = new Markdown.Converter({extensions: [], sanitize: true});
|
||||
this.editorContent = null;
|
||||
};
|
||||
|
||||
|
|
@ -51,29 +51,29 @@ export class Editor {
|
|||
|
||||
break;
|
||||
case 'bold':
|
||||
startOffset = 2;
|
||||
endOffset = 2;
|
||||
startOffset = 2;
|
||||
endOffset = 2;
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ '**' + textarea.value.slice(startPosition, endPosition) + '**'
|
||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||
break;
|
||||
case 'italic':
|
||||
startOffset = 1;
|
||||
endOffset = 1;
|
||||
startOffset = 1;
|
||||
endOffset = 1;
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ '*' + textarea.value.slice(startPosition, endPosition) + '*'
|
||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||
break;
|
||||
case 'underline':
|
||||
startOffset = 2;
|
||||
endOffset = 2;
|
||||
startOffset = 2;
|
||||
endOffset = 2;
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ '__' + textarea.value.slice(startPosition, endPosition) + '__'
|
||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||
break;
|
||||
case 'strikethrough':
|
||||
startOffset = 2;
|
||||
endOffset = 2;
|
||||
startOffset = 2;
|
||||
endOffset = 2;
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ '~~' + textarea.value.slice(startPosition, endPosition) + '~~'
|
||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||
|
|
@ -132,22 +132,22 @@ export class Editor {
|
|||
case 'link':
|
||||
startOffset = 1;
|
||||
endOffset = 0;
|
||||
let link = textarea.value.slice(startPosition, endPosition);
|
||||
let link = textarea.value.slice(startPosition, endPosition);
|
||||
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ ((link.startsWith('http') || link.startsWith('www')) ? '[' + link + ']' : '[' + link + '](https://www.website.com "' + link + '")')
|
||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||
break;
|
||||
case 'code':
|
||||
startOffset = 1;
|
||||
endOffset = 1;
|
||||
startOffset = 1;
|
||||
endOffset = 1;
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ '`' + textarea.value.slice(startPosition, endPosition) + '`'
|
||||
+ textarea.value.slice(endPosition, textarea.value.length);
|
||||
break;
|
||||
case 'quote':
|
||||
startOffset = 2;
|
||||
endOffset = 0;
|
||||
startOffset = 2;
|
||||
endOffset = 0;
|
||||
textarea.value = textarea.value.slice(0, startPosition)
|
||||
+ '> ' + textarea.value.slice(startPosition, textarea.value.length);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the content
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @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
|
||||
*
|
||||
|
|
@ -116,7 +120,9 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $plain
|
||||
* Set the plain text
|
||||
*
|
||||
* @param string $plain Plain text
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -128,6 +134,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the plain text
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -138,6 +146,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get created at
|
||||
*
|
||||
* @return \DateTime
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -148,6 +158,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
|
@ -158,6 +170,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get created by
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
|
@ -178,6 +194,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the title
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @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
|
||||
*
|
||||
|
|
@ -200,6 +220,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the path
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -31,6 +31,12 @@ use phpOMS\Views\View;
|
|||
*/
|
||||
class BaseView extends View
|
||||
{
|
||||
/**
|
||||
* Editor id
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $id = '';
|
||||
|
||||
/**
|
||||
|
|
@ -47,6 +53,13 @@ class BaseView extends View
|
|||
$this->addData('text', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the editor id
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderId() : string
|
||||
{
|
||||
return $this->printHtml($this->id);
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ use phpOMS\Views\View;
|
|||
*/
|
||||
class TextView extends View
|
||||
{
|
||||
private $id = '';
|
||||
private $name = '';
|
||||
private $form = '';
|
||||
private $plain = '';
|
||||
private $preview = '';
|
||||
private $tplText = '';
|
||||
private $tplValue = '';
|
||||
private string $id = '';
|
||||
private string $name = '';
|
||||
private string $form = '';
|
||||
private string $plain = '';
|
||||
private string $preview = '';
|
||||
private string $tplText = '';
|
||||
private string $tplValue = '';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -47,36 +47,87 @@ class TextView extends View
|
|||
$this->setTemplate('/Modules/Editor/Theme/Backend/Components/Editor/inline-editor');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the form id
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderId() : string
|
||||
{
|
||||
return $this->printHtml($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the form name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderName() : string
|
||||
{
|
||||
return $this->printHtml($this->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the form attribute name
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderForm() : string
|
||||
{
|
||||
return $this->printHtml($this->form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the preview
|
||||
*
|
||||
* Usually markdown
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderPreview() : string
|
||||
{
|
||||
return $this->preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the plain text
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderPlain() : string
|
||||
{
|
||||
return $this->printHtml($this->plain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render template text reference
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderTplText() : string
|
||||
{
|
||||
return $this->printHtml($this->tplText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render template value reference
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function renderTplValue() : string
|
||||
{
|
||||
return $this->printHtml($this->tplValue);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user