Skip to content

TINY-11908: Add new readonly prop #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added
- The readonly prop now maps the the readonly editor option. See: https://www.tiny.cloud/docs/tinymce/latest/editor-important-options/#readonly

### Changed
- The disabled prop now maps the the disabled editor option. See: https://www.tiny.cloud/docs/tinymce/latest/editor-important-options/#disabled

## 6.1.0 - 2024-10-22

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This package is a thin wrapper around [TinyMCE](https://github.com/tinymce/tinym

### Support

Version 7.0 is intended to support the tinymce version 7.6 and above.
Version 4.0 is intended to support Vue 3. For Vue 2.x and below please use previous versions of the wrapper.

### Issues
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tinymce/tinymce-vue",
"version": "6.1.1-rc",
"version": "7.0.0-rc",
"description": "Official TinyMCE Vue 3 Component",
"private": false,
"repository": {
Expand Down
16 changes: 11 additions & 5 deletions src/main/ts/components/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Editor = defineComponent({
props: editorProps,
setup: (props: IPropTypes, ctx) => {
let conf = props.init ? { ...props.init, ...defaultInitValues } : { ...defaultInitValues };
const { disabled, modelValue, tagName } = toRefs(props);
const { disabled, readonly, modelValue, tagName } = toRefs(props);
const element: Ref<Element | null> = ref(null);
let vueEditor: any = null;
const elementId: string = props.id || uuid('tiny-vue');
Expand All @@ -52,7 +52,8 @@ export const Editor = defineComponent({
const content = getContent(mounting);
const finalInit = {
...conf,
readonly: props.disabled,
readonly: props.readonly,
disabled: props.disabled,
target: element.value,
plugins: mergePlugins(conf.plugins, props.plugins),
toolbar: props.toolbar || (conf.toolbar),
Expand All @@ -72,15 +73,20 @@ export const Editor = defineComponent({
getTinymce().init(finalInit);
mounting = false;
};
watch(disabled, (disable) => {
watch(readonly, (isReadonly) => {
if (vueEditor !== null) {
if (typeof vueEditor.mode?.set === 'function') {
vueEditor.mode.set(disable ? 'readonly' : 'design');
vueEditor.mode.set(isReadonly ? 'readonly' : 'design');
} else {
vueEditor.setMode(disable ? 'readonly' : 'design');
vueEditor.setMode(isReadonly ? 'readonly' : 'design');
}
}
});
watch(disabled, (disable) => {
if (vueEditor !== null) {
vueEditor.options.set('disabled', disable);
}
});
watch(tagName, (_) => {
if (!modelBind) {
cache = vueEditor.getContent();
Expand Down
2 changes: 2 additions & 0 deletions src/main/ts/components/EditorPropTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface IPropTypes {
toolbar: string[] | string;
modelValue: string;
disabled: boolean;
readonly: boolean;
tinymceScriptSrc: string;
}

Expand All @@ -43,6 +44,7 @@ export const editorProps: CopyProps<IPropTypes> = {
toolbar: [ String, Array ],
modelValue: String,
disabled: Boolean,
readonly: Boolean,
tinymceScriptSrc: String,
outputFormat: {
type: String,
Expand Down
12 changes: 10 additions & 2 deletions src/stories/Editor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Story } from '@storybook/vue3';
import { onBeforeMount, ref } from 'vue';
import { ScriptLoader } from '../main/ts/ScriptLoader';

import type { EditorEvent, Editor as TinyMCEEditor } from 'tinymce';
import { Editor } from '../main/ts/components/Editor';
import type { Editor as TinyMCEEditor, EditorEvent } from 'tinymce';

const apiKey = 'qagffr3pkuv17a8on1afax661irst1hbr4e6tbv888sz91jc';
const content = `
Expand Down Expand Up @@ -159,24 +159,32 @@ export const Disable: Story = (args) => ({
const cc = args.channel || lastChannel;
const conf = getConf(args.conf);
const disabled = ref(false);
const readonly = ref(false);
const toggleDisabled = (_) => {
disabled.value = !disabled.value;
}
const toggleReadonly = (_) => {
readonly.value = !readonly.value;
}
return {
apiKey,
content,
cloudChannel: cc,
conf,
disabled,
toggleDisabled
readonly,
toggleDisabled,
toggleReadonly
}
},
template: `
<div>
<button @click="toggleDisabled">{{ disabled ? 'enable' : 'disable' }}</button>
<button @click="toggleReadonly">{{ readonly ? 'design' : 'readonly' }}</button>
<editor
api-key="${apiKey}"
v-bind:disabled="disabled"
v-bind:readonly="readonly"
:init="conf"
v-model="content"
/>
Expand Down