Skip to content

Commit

Permalink
Merge pull request #57 from mostafaznv/dev
Browse files Browse the repository at this point in the history
add general-html-support plugin to ckeditor bundle #56
  • Loading branch information
mostafaznv authored Jun 28, 2023
2 parents f5928e1 + bbc2b73 commit 69bc004
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 32 deletions.
67 changes: 36 additions & 31 deletions README.md

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions config/nova-ckeditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@
['title' => 'English', 'languageCode' => 'en']
],

/*
* General HTML Support
*
* @see https://ckeditor.com/docs/ckeditor5/latest/features/html/general-html-support.html#configuration
*/

'html-support' => [
'allow' => [
[
'name' => 'div',
'classes' => true,
],
[
'name' => '/^(div|section|article)$/'
]
],

'disallow' => []
],

'should-not-group-when-full' => false,

'browser' => [
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@ckeditor/ckeditor5-heading": "^35.0.0",
"@ckeditor/ckeditor5-horizontal-line": "^35.0.0",
"@ckeditor/ckeditor5-html-embed": "^35.0.0",
"@ckeditor/ckeditor5-html-support": "^35.0.0",
"@ckeditor/ckeditor5-image": "^35.0.0",
"@ckeditor/ckeditor5-indent": "^35.0.0",
"@ckeditor/ckeditor5-link": "^35.0.0",
Expand Down
2 changes: 2 additions & 0 deletions resources/js/ckeditor/ckeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefrom
import RemoveFormat from '@ckeditor/ckeditor5-remove-format/src/removeformat'
import StrikeThrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough'
import Code from '@ckeditor/ckeditor5-basic-styles/src/code'
import {GeneralHtmlSupport} from '@ckeditor/ckeditor5-html-support'
import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript'
import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript'
import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline'
Expand Down Expand Up @@ -107,6 +108,7 @@ export default class CkEditor extends ClassicEditorBase {
Superscript,
StrikeThrough,
Code,
GeneralHtmlSupport,
Image,
ImageStyle,
ImageUpload,
Expand Down
4 changes: 4 additions & 0 deletions resources/js/ckeditor/config/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ export default {
hasChanged: false
}
}
},
htmlSupport: {
allow: [],
disallow: []
}
}
48 changes: 48 additions & 0 deletions resources/js/components/editor-field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default {
imageBrowser: this.currentField.imageBrowser,
videoBrowser: this.currentField.videoBrowser,
snippetBrowser: this.currentField.snippetBrowser,
htmlSupport: this.normalizeHtmlSupportItems(this.currentField.htmlSupport),
isReadOnly: this.currentField.readonly,
language: {
ui: this.currentField.uiLanguage,
Expand Down Expand Up @@ -161,6 +162,53 @@ export default {
return providers
},
normalizeHtmlSupportItems(htmlSupport) {
if (htmlSupport) {
if (htmlSupport.allow) {
htmlSupport.allow.map(item => {
if (item.name) {
item.name = this.stringToRegex(item.name)
}
return item
})
}
else {
htmlSupport.allow = []
}
if (htmlSupport.disallow) {
htmlSupport.disallow.map(item => {
if (item.name) {
item.name = this.stringToRegex(item.name)
}
return item
})
}
else {
htmlSupport.disallow = []
}
return htmlSupport
}
return {
allow: [],
disallow: []
}
},
stringToRegex(string) {
if (typeof string === 'string' && string.startsWith('/') && string.endsWith('/')) {
const regexPattern = string.slice(1, -1)
return new RegExp(regexPattern)
}
return string
},
fill(formData) {
if (this.currentlyIsVisible) {
formData.append(this.currentField.attribute, this.value || '')
Expand Down
29 changes: 29 additions & 0 deletions src/CkEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CkEditor extends Field

/**
* Specifies the toolbar options
*
* @var array
*/
public array $toolbarOptions;
Expand Down Expand Up @@ -62,6 +63,13 @@ class CkEditor extends Field
*/
public array $textPartLanguage;

/**
* General HTML Support
*
* @var array
*/
public array $htmlSupport;

/**
* UI Language
*
Expand Down Expand Up @@ -183,6 +191,19 @@ public function textPartLanguage(array $languages): self
return $this;
}

/**
* Set General HTML Support
*
* @param array $htmlSupport
* @return $this
*/
public function htmlSupport(array $htmlSupport): self
{
$this->htmlSupport = $htmlSupport;

return $this;
}

/**
* Set Should Not Group When Full
*
Expand Down Expand Up @@ -252,6 +273,7 @@ public function jsonSerialize(): array
'indexLimit' => $this->indexLimit,
'contentLanguage' => $this->contentLanguage,
'textPartLanguage' => $this->textPartLanguage,
'htmlSupport' => $this->htmlSupport,
'uiLanguage' => $this->uiLanguage,
'shouldNotGroupWhenFull' => $this->shouldNotGroupWhenFull,
'shouldShow' => $this->shouldBeExpanded(),
Expand Down Expand Up @@ -294,11 +316,17 @@ protected function prepareSnippets(array $snippets): array
private function prepareToolbar(string $toolbar, array $items = null): void
{
$toolbar = config('nova-ckeditor.toolbars.' . $toolbar);

$defaultTextPartLanguage = [
['title' => 'Farsi', 'languageCode' => 'fa'],
['title' => 'English', 'languageCode' => 'en']
];

$defaultHtmlSupport = [
'allow' => [],
'disallow' => []
];

$this->toolbar = is_null($items) ? $toolbar['items'] : $items;
$this->toolbarOptions = $toolbar['options'];
$this->height = $toolbar['height'];
Expand All @@ -307,6 +335,7 @@ private function prepareToolbar(string $toolbar, array $items = null): void
$this->snippetBrowser = $this->prepareSnippets($toolbar['snippets']);
$this->contentLanguage = $toolbar['content-lang'];
$this->textPartLanguage = $toolbar['text-part-language'] ?? $defaultTextPartLanguage;
$this->htmlSupport = $toolbar['html-support'] ?? $defaultHtmlSupport;
$this->uiLanguage = $toolbar['ui-language']['name'] ?? 'en';
$this->shouldNotGroupWhenFull = $toolbar['should-not-group-when-full'];
}
Expand Down

0 comments on commit 69bc004

Please sign in to comment.