@@ -36,7 +36,7 @@ export const Editor = defineComponent({
36
36
let conf = props . init ? { ...props . init , ...defaultInitValues } : { ...defaultInitValues } ;
37
37
const { disabled, readonly, modelValue, tagName } = toRefs ( props ) ;
38
38
const element : Ref < Element | null > = ref ( null ) ;
39
- let vueEditor : any = null ;
39
+ let vueEditor : TinyMCEEditor | null = null ;
40
40
const elementId : string = props . id || uuid ( 'tiny-vue' ) ;
41
41
const inlineEditor : boolean = ( props . init && props . init . inline ) || props . inline ;
42
42
const modelBind = ! ! ctx . attrs [ 'onUpdate:modelValue' ] ;
@@ -74,33 +74,35 @@ export const Editor = defineComponent({
74
74
mounting = false ;
75
75
} ;
76
76
watch ( readonly , ( isReadonly ) => {
77
- if ( vueEditor !== null && isDisabledOptionSupported ( ) ) {
77
+ if ( vueEditor !== null && isDisabledOptionSupported ( vueEditor ) ) {
78
78
if ( typeof vueEditor . mode ?. set === 'function' ) {
79
79
vueEditor . mode . set ( isReadonly ? 'readonly' : 'design' ) ;
80
80
} else {
81
- vueEditor . setMode ( isReadonly ? 'readonly' : 'design' ) ;
81
+ ( vueEditor as any ) . setMode ( isReadonly ? 'readonly' : 'design' ) ;
82
82
}
83
83
}
84
84
} ) ;
85
85
watch ( disabled , ( disable ) => {
86
86
if ( vueEditor !== null ) {
87
- if ( isDisabledOptionSupported ( ) ) {
87
+ if ( isDisabledOptionSupported ( vueEditor ) ) {
88
88
vueEditor . options . set ( 'disabled' , disable ) ;
89
89
} else {
90
90
if ( typeof vueEditor . mode ?. set === 'function' ) {
91
91
vueEditor . mode . set ( disable ? 'readonly' : 'design' ) ;
92
92
} else {
93
- vueEditor . setMode ( disable ? 'readonly' : 'design' ) ;
93
+ ( vueEditor as any ) . setMode ( disable ? 'readonly' : 'design' ) ;
94
94
}
95
95
}
96
96
}
97
97
} ) ;
98
98
watch ( tagName , ( _ ) => {
99
- if ( ! modelBind ) {
100
- cache = vueEditor . getContent ( ) ;
99
+ if ( vueEditor ) {
100
+ if ( ! modelBind ) {
101
+ cache = vueEditor . getContent ( ) ;
102
+ }
103
+ getTinymce ( ) ?. remove ( vueEditor ) ;
104
+ nextTick ( ( ) => initWrapper ( ) ) ;
101
105
}
102
- getTinymce ( ) ?. remove ( vueEditor ) ;
103
- nextTick ( ( ) => initWrapper ( ) ) ;
104
106
} ) ;
105
107
onMounted ( ( ) => {
106
108
if ( getTinymce ( ) !== null ) {
@@ -130,17 +132,21 @@ export const Editor = defineComponent({
130
132
}
131
133
} ) ;
132
134
onDeactivated ( ( ) => {
133
- if ( ! modelBind ) {
134
- cache = vueEditor . getContent ( ) ;
135
+ if ( vueEditor ) {
136
+ if ( ! modelBind ) {
137
+ cache = vueEditor . getContent ( ) ;
138
+ }
139
+ getTinymce ( ) ?. remove ( vueEditor ) ;
135
140
}
136
- getTinymce ( ) ?. remove ( vueEditor ) ;
137
141
} ) ;
138
142
}
139
143
const rerender = ( init : EditorOptions ) => {
140
- cache = vueEditor . getContent ( ) ;
141
- getTinymce ( ) ?. remove ( vueEditor ) ;
142
- conf = { ...conf , ...init , ...defaultInitValues } ;
143
- nextTick ( ( ) => initWrapper ( ) ) ;
144
+ if ( vueEditor ) {
145
+ cache = vueEditor . getContent ( ) ;
146
+ getTinymce ( ) ?. remove ( vueEditor ) ;
147
+ conf = { ...conf , ...init , ...defaultInitValues } ;
148
+ nextTick ( ( ) => initWrapper ( ) ) ;
149
+ }
144
150
} ;
145
151
ctx . expose ( {
146
152
rerender,
0 commit comments