|
1 | 1 | <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 | + /> |
15 | 16 |
|
16 | | - /> |
17 | | - |
18 | | - </template> |
19 | | - </DefaultField> |
| 17 | + </template> |
| 18 | + </DefaultField> |
20 | 19 | </template> |
21 | 20 |
|
22 | 21 | <script> |
23 | | -import {DependentFormField, HandlesValidationErrors} from 'laravel-nova' |
| 22 | +import { DependentFormField, HandlesValidationErrors } from 'laravel-nova' |
24 | 23 | import Editor from '@tinymce/tinymce-vue' |
25 | 24 |
|
26 | 25 | export default { |
27 | | - mixins: [DependentFormField, HandlesValidationErrors], |
| 26 | + mixins: [DependentFormField, HandlesValidationErrors], |
28 | 27 |
|
29 | | - props: ['resourceName', 'resourceId', 'options'], |
| 28 | + props: ['resourceName', 'resourceId', 'options'], |
30 | 29 |
|
31 | | - components: { |
32 | | - editor: Editor |
33 | | - }, |
| 30 | + components: { |
| 31 | + editor: Editor |
| 32 | + }, |
34 | 33 |
|
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 | + } |
37 | 50 | }, |
38 | 51 |
|
39 | | - methods: { |
40 | | - setEditorTheme() { |
41 | | - const selectedNovaTheme = localStorage.novaTheme |
| 52 | + setEditorTheme () { |
| 53 | + const selectedNovaTheme = localStorage.novaTheme |
42 | 54 |
|
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 | + }, |
57 | 69 |
|
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 | + }, |
70 | 82 |
|
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 || '') |
77 | 88 | } |
| 89 | + } |
78 | 90 | } |
79 | 91 | </script> |
0 commit comments