Skip to content

Commit 73abeb0

Browse files
committed
Check if protect config exists
1 parent 3152f91 commit 73abeb0

File tree

2 files changed

+73
-68
lines changed

2 files changed

+73
-68
lines changed

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 & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +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"
15-
/>
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+
/>
1616

17-
</template>
18-
</DefaultField>
17+
</template>
18+
</DefaultField>
1919
</template>
2020

2121
<script>
22-
import {DependentFormField, HandlesValidationErrors} from 'laravel-nova'
22+
import { DependentFormField, HandlesValidationErrors } from 'laravel-nova'
2323
import Editor from '@tinymce/tinymce-vue'
2424
2525
export default {
26-
mixins: [DependentFormField, HandlesValidationErrors],
26+
mixins: [DependentFormField, HandlesValidationErrors],
2727
28-
props: ['resourceName', 'resourceId', 'options'],
28+
props: ['resourceName', 'resourceId', 'options'],
2929
30-
components: {
31-
editor: Editor
32-
},
30+
components: {
31+
editor: Editor
32+
},
3333
34-
created() {
35-
this.setupProtectContent()
36-
this.setEditorTheme()
37-
},
34+
created () {
35+
this.setupProtectContent()
36+
this.setEditorTheme()
37+
},
3838
39-
methods: {
40-
setupProtectContent() {
41-
this.field.options.init.protect.map((regex, idx) => {
42-
const exp = regex.match(/^([/~@;%#'])(.*?)\1([gimsuy]*)$/);
43-
this.field.options.init.protect[idx] = exp ? new RegExp(exp[2], exp[3]) : new RegExp(regex.replace(/^\/+|\/+$/gm, ''));
44-
})
45-
},
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+
}
50+
},
4651
47-
setEditorTheme() {
48-
const selectedNovaTheme = localStorage.novaTheme
52+
setEditorTheme () {
53+
const selectedNovaTheme = localStorage.novaTheme
4954
50-
if (typeof selectedNovaTheme !== 'undefined') {
51-
if (selectedNovaTheme === 'system') {
52-
this.setSystemMode()
53-
} else if (selectedNovaTheme === 'dark') {
54-
this.field.options.init.skin = 'oxide-dark'
55-
this.field.options.init.content_css = 'dark'
56-
} else {
57-
this.field.options.init.skin = 'oxide'
58-
this.field.options.init.content_css = 'default'
59-
}
60-
} else {
61-
this.setSystemMode()
62-
}
63-
},
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+
},
6469
65-
setSystemMode() {
66-
this.field.options.init.skin =
67-
window.matchMedia('(prefers-color-scheme: dark)').matches ||
68-
document.querySelector('html').classList.contains('dark')
69-
? 'oxide-dark'
70-
: 'oxide'
71-
this.field.options.init.content_css =
72-
window.matchMedia('(prefers-color-scheme: dark)').matches ||
73-
document.querySelector('html').classList.contains('dark')
74-
? 'dark'
75-
: 'default'
76-
},
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+
},
7782
78-
/**
79-
* Fill the given FormData object with the field's internal value.
80-
*/
81-
fill(formData) {
82-
formData.append(this.field.attribute, this.value || '')
83-
}
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 || '')
8488
}
89+
}
8590
}
8691
</script>

0 commit comments

Comments
 (0)