@@ -10,8 +10,8 @@ import { ScriptLoader } from '../ScriptLoader';
10
10
import { getTinymce } from '../TinyMCE' ;
11
11
import { isTextarea , mergePlugins , uuid , isNullOrUndefined , initEditor } from '../Utils' ;
12
12
import { editorProps } from './EditorPropTypes' ;
13
- import { h , defineComponent , onMounted , ref , Ref , toRefs , watch , onBeforeUnmount , onActivated , onDeactivated } from 'vue' ;
14
- import { Editor as TinyMCEEditor , EditorEvent } from 'tinymce' ;
13
+ import { h , defineComponent , onMounted , ref , Ref , toRefs , nextTick , watch , onBeforeUnmount , onActivated , onDeactivated } from 'vue' ;
14
+ import { Editor as TinyMCEEditor , EditorEvent , RawEditorSettings } from 'tinymce' ;
15
15
16
16
const renderInline = ( ce : any , id : string , elementRef : Ref < Element | null > , tagName ?: string ) =>
17
17
ce ( tagName ? tagName : 'div' , {
@@ -29,7 +29,8 @@ const renderIframe = (ce: any, id: string, elementRef: Ref<Element | null>) =>
29
29
export const Editor = defineComponent ( {
30
30
props : editorProps ,
31
31
setup : ( props , ctx ) => {
32
- const { disabled, modelValue } = toRefs ( props ) ;
32
+ let conf = props . init ? { ...props . init } : { } ;
33
+ const { disabled, modelValue, tagName } = toRefs ( props ) ;
33
34
const element : Ref < Element | null > = ref ( null ) ;
34
35
let vueEditor : any = null ;
35
36
const elementId : string = props . id || uuid ( 'tiny-vue' ) ;
@@ -46,17 +47,17 @@ export const Editor = defineComponent({
46
47
const initWrapper = ( ) : void => {
47
48
const content = getContent ( mounting ) ;
48
49
const finalInit = {
49
- ...props . init ,
50
+ ...conf ,
50
51
readonly : props . disabled ,
51
52
selector : `#${ elementId } ` ,
52
- plugins : mergePlugins ( props . init && props . init . plugins , props . plugins ) ,
53
- toolbar : props . toolbar || ( props . init && props . init . toolbar ) ,
53
+ plugins : mergePlugins ( conf . plugins , props . plugins ) ,
54
+ toolbar : props . toolbar || ( conf . toolbar ) ,
54
55
inline : inlineEditor ,
55
56
setup : ( editor : TinyMCEEditor ) => {
56
57
vueEditor = editor ;
57
58
editor . on ( 'init' , ( e : EditorEvent < any > ) => initEditor ( e , props , ctx , editor , modelValue , content ) ) ;
58
- if ( props . init && typeof props . init . setup === 'function' ) {
59
- props . init . setup ( editor ) ;
59
+ if ( typeof conf . setup === 'function' ) {
60
+ conf . setup ( editor ) ;
60
61
}
61
62
}
62
63
} ;
@@ -71,6 +72,13 @@ export const Editor = defineComponent({
71
72
vueEditor . setMode ( disable ? 'readonly' : 'design' ) ;
72
73
}
73
74
} ) ;
75
+ watch ( tagName , ( tagName ) => {
76
+ if ( ! modelBind ) {
77
+ cache = vueEditor . getContent ( ) ;
78
+ }
79
+ getTinymce ( ) ?. remove ( vueEditor ) ;
80
+ nextTick ( ( ) => initWrapper ( ) ) ;
81
+ } ) ;
74
82
onMounted ( ( ) => {
75
83
if ( getTinymce ( ) !== null ) {
76
84
initWrapper ( ) ;
@@ -105,6 +113,15 @@ export const Editor = defineComponent({
105
113
getTinymce ( ) ?. remove ( vueEditor ) ;
106
114
} ) ;
107
115
}
116
+ const rerender = ( init : RawEditorSettings ) => {
117
+ cache = vueEditor . getContent ( ) ;
118
+ getTinymce ( ) ?. remove ( vueEditor ) ;
119
+ conf = { ...conf , ...init } ;
120
+ nextTick ( ( ) => initWrapper ( ) ) ;
121
+ } ;
122
+ ctx . expose ( {
123
+ rerender
124
+ } ) ;
108
125
return ( ) => inlineEditor ?
109
126
renderInline ( h , elementId , element , props . tagName ) :
110
127
renderIframe ( h , elementId , element ) ;
0 commit comments