Skip to content

Commit f06793d

Browse files
committed
TINY-11908: fix usage of a Utils function
1 parent b9342f5 commit f06793d

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/main/ts/components/Editor.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const Editor = defineComponent({
3636
let conf = props.init ? { ...props.init, ...defaultInitValues } : { ...defaultInitValues };
3737
const { disabled, readonly, modelValue, tagName } = toRefs(props);
3838
const element: Ref<Element | null> = ref(null);
39-
let vueEditor: any = null;
39+
let vueEditor: TinyMCEEditor | null = null;
4040
const elementId: string = props.id || uuid('tiny-vue');
4141
const inlineEditor: boolean = (props.init && props.init.inline) || props.inline;
4242
const modelBind = !!ctx.attrs['onUpdate:modelValue'];
@@ -74,33 +74,35 @@ export const Editor = defineComponent({
7474
mounting = false;
7575
};
7676
watch(readonly, (isReadonly) => {
77-
if (vueEditor !== null && isDisabledOptionSupported()) {
77+
if (vueEditor !== null && isDisabledOptionSupported(vueEditor)) {
7878
if (typeof vueEditor.mode?.set === 'function') {
7979
vueEditor.mode.set(isReadonly ? 'readonly' : 'design');
8080
} else {
81-
vueEditor.setMode(isReadonly ? 'readonly' : 'design');
81+
(vueEditor as any).setMode(isReadonly ? 'readonly' : 'design');
8282
}
8383
}
8484
});
8585
watch(disabled, (disable) => {
8686
if (vueEditor !== null) {
87-
if (isDisabledOptionSupported()) {
87+
if (isDisabledOptionSupported(vueEditor)) {
8888
vueEditor.options.set('disabled', disable);
8989
} else {
9090
if (typeof vueEditor.mode?.set === 'function') {
9191
vueEditor.mode.set(disable ? 'readonly' : 'design');
9292
} else {
93-
vueEditor.setMode(disable ? 'readonly' : 'design');
93+
(vueEditor as any).setMode(disable ? 'readonly' : 'design');
9494
}
9595
}
9696
}
9797
});
9898
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());
101105
}
102-
getTinymce()?.remove(vueEditor);
103-
nextTick(() => initWrapper());
104106
});
105107
onMounted(() => {
106108
if (getTinymce() !== null) {
@@ -130,17 +132,21 @@ export const Editor = defineComponent({
130132
}
131133
});
132134
onDeactivated(() => {
133-
if (!modelBind) {
134-
cache = vueEditor.getContent();
135+
if (vueEditor) {
136+
if (!modelBind) {
137+
cache = vueEditor.getContent();
138+
}
139+
getTinymce()?.remove(vueEditor);
135140
}
136-
getTinymce()?.remove(vueEditor);
137141
});
138142
}
139143
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+
}
144150
};
145151
ctx.expose({
146152
rerender,

0 commit comments

Comments
 (0)