Skip to content

Commit 49b3bba

Browse files
authored
Merge pull request #21 from murdercode/Joemires/master
Protect feature
2 parents d4eaacc + 3e72bdf commit 49b3bba

File tree

3 files changed

+99
-62
lines changed

3 files changed

+99
-62
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ and dynamic editing capabilities.
2727
## Extra
2828

2929
> [!IMPORTANT]
30-
> Want some steroids for your TinyMCE? [Check out](https://github.com/The-3Labs-Team/tinymce-chatgpt-plugin) our new **ChatGTP for TinyMCE** plugin! 🚀🚀🚀
30+
> Want some steroids for your TinyMCE? [Check out](https://github.com/The-3Labs-Team/tinymce-chatgpt-plugin) our new *
31+
*ChatGTP for TinyMCE** plugin! 🚀🚀🚀
3132

3233
## Demo & Screenshots
3334

@@ -198,6 +199,30 @@ file `config/nova-tinymce-editor.php`:
198199

199200
Please be sure that `image` plugin and toolbar button are enabled in your config file.
200201

202+
## Protect code
203+
204+
You can to control what contents [should be protected](https://www.tiny.cloud/docs/tinymce/6/content-filtering/#protect)
205+
from editing while it gets passed
206+
into the editor. This is useful for example when you want to protect PHP code from been formatted.
207+
208+
To do this, you must publish the configuration file and add the following line:
209+
210+
```php
211+
<?php
212+
213+
return [
214+
'init' => [
215+
// ... Your awesome init config ...
216+
/**
217+
* Set what content should be protected while editing
218+
* This should be a regular expression
219+
* E.g "/<\?php.*?\?>/g" - Protect PHP code from been formatted
220+
*/
221+
'protect' => []
222+
];
223+
//...
224+
```
225+
201226
## Upgrade from 1.0.x to 1.1.x
202227

203228
The transition to 1.1 involves the use of a new configuration layout compatible with the previous version.

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,91 @@
11
<template>
2-
<DefaultField :errors="errors" :field="currentField" :full-width-content="fullWidthContent"
3-
:show-help-text="showHelpText">
4-
<template #field>
5-
<editor
6-
:id="currentField.attribute"
7-
v-model="value"
8-
:api-key="currentField.options.apiKey"
9-
:cloud-channel="currentField.options.cloudChannel ?? 6"
10-
:disabled="currentField.readonly"
11-
:init="currentField.options.init"
12-
:placeholder="currentField.name"
13-
:plugins="currentField.options.plugins"
14-
:toolbar="currentField.options.toolbar"
2+
<DefaultField :errors="errors" :field="currentField" :full-width-content="fullWidthContent"
3+
:show-help-text="showHelpText">
4+
<template #field>
5+
<editor
6+
:id="currentField.attribute"
7+
v-model="value"
8+
:api-key="currentField.options.apiKey"
9+
:cloud-channel="currentField.options.cloudChannel ?? 6"
10+
:disabled="currentField.readonly"
11+
:init="currentField.options.init"
12+
:placeholder="currentField.name"
13+
:plugins="currentField.options.plugins"
14+
:toolbar="currentField.options.toolbar"
15+
/>
1516

16-
/>
17-
18-
</template>
19-
</DefaultField>
17+
</template>
18+
</DefaultField>
2019
</template>
2120

2221
<script>
23-
import {DependentFormField, HandlesValidationErrors} from 'laravel-nova'
22+
import { DependentFormField, HandlesValidationErrors } from 'laravel-nova'
2423
import Editor from '@tinymce/tinymce-vue'
2524
2625
export default {
27-
mixins: [DependentFormField, HandlesValidationErrors],
26+
mixins: [DependentFormField, HandlesValidationErrors],
2827
29-
props: ['resourceName', 'resourceId', 'options'],
28+
props: ['resourceName', 'resourceId', 'options'],
3029
31-
components: {
32-
editor: Editor
33-
},
30+
components: {
31+
editor: Editor
32+
},
3433
35-
created() {
36-
this.setEditorTheme()
34+
created () {
35+
this.setupProtectContent()
36+
this.setEditorTheme()
37+
},
38+
39+
methods: {
40+
setupProtectContent () {
41+
if (this.field.options.init.protect) {
42+
this.field.options.init.protect = this.field.options.init.protect.map((regex) => {
43+
const exp = regex.match(/^([/~@;%#'])(.*?)\1([gimsuy]*)$/)
44+
if (exp) {
45+
return new RegExp(exp[2], exp[3])
46+
}
47+
return new RegExp(regex.replace(/^\/+|\/+$/gm, '')) // remove leading and trailing slashes
48+
})
49+
}
3750
},
3851
39-
methods: {
40-
setEditorTheme() {
41-
const selectedNovaTheme = localStorage.novaTheme
52+
setEditorTheme () {
53+
const selectedNovaTheme = localStorage.novaTheme
4254
43-
if (typeof selectedNovaTheme !== 'undefined') {
44-
if (selectedNovaTheme === 'system') {
45-
this.setSystemMode()
46-
} else if (selectedNovaTheme === 'dark') {
47-
this.field.options.init.skin = 'oxide-dark'
48-
this.field.options.init.content_css = 'dark'
49-
} else {
50-
this.field.options.init.skin = 'oxide'
51-
this.field.options.init.content_css = 'default'
52-
}
53-
} else {
54-
this.setSystemMode()
55-
}
56-
},
55+
if (typeof selectedNovaTheme !== 'undefined') {
56+
if (selectedNovaTheme === 'system') {
57+
this.setSystemMode()
58+
} else if (selectedNovaTheme === 'dark') {
59+
this.field.options.init.skin = 'oxide-dark'
60+
this.field.options.init.content_css = 'dark'
61+
} else {
62+
this.field.options.init.skin = 'oxide'
63+
this.field.options.init.content_css = 'default'
64+
}
65+
} else {
66+
this.setSystemMode()
67+
}
68+
},
5769
58-
setSystemMode() {
59-
this.field.options.init.skin =
60-
window.matchMedia('(prefers-color-scheme: dark)').matches ||
61-
document.querySelector('html').classList.contains('dark')
62-
? 'oxide-dark'
63-
: 'oxide'
64-
this.field.options.init.content_css =
65-
window.matchMedia('(prefers-color-scheme: dark)').matches ||
66-
document.querySelector('html').classList.contains('dark')
67-
? 'dark'
68-
: 'default'
69-
},
70+
setSystemMode () {
71+
this.field.options.init.skin =
72+
window.matchMedia('(prefers-color-scheme: dark)').matches ||
73+
document.querySelector('html').classList.contains('dark')
74+
? 'oxide-dark'
75+
: 'oxide'
76+
this.field.options.init.content_css =
77+
window.matchMedia('(prefers-color-scheme: dark)').matches ||
78+
document.querySelector('html').classList.contains('dark')
79+
? 'dark'
80+
: 'default'
81+
},
7082
71-
/**
72-
* Fill the given FormData object with the field's internal value.
73-
*/
74-
fill(formData) {
75-
formData.append(this.field.attribute, this.value || '')
76-
}
83+
/**
84+
* Fill the given FormData object with the field's internal value.
85+
*/
86+
fill (formData) {
87+
formData.append(this.field.attribute, this.value || '')
7788
}
89+
}
7890
}
7991
</script>

0 commit comments

Comments
 (0)