|
1 | 1 | import { Resolve, Obj, Fun, Global } from '@ephox/katamari'; |
2 | 2 | import { TinyMCE, Editor } from 'tinymce'; |
3 | 3 | import { ScriptLoader } from '../utils/ScriptLoader'; |
| 4 | +import { TinyVer } from '@tinymce/miniature'; |
4 | 5 | type EditorOptions = Parameters<TinyMCE['init']>[0]; |
5 | 6 | type EventHandler = Parameters<Editor['on']>[1]; |
6 | 7 |
|
@@ -80,10 +81,7 @@ const configRenames: Record<string, string> = {}; |
80 | 81 |
|
81 | 82 | // Function that checks if the disabled option is supported with the version used |
82 | 83 | const isDisabledOptionSupported = (tinymce: TinyMCE): boolean => { |
83 | | - const major = parseFloat(tinymce.majorVersion); |
84 | | - const minor = parseFloat(tinymce.minorVersion); |
85 | | - const version = major + minor / 10; |
86 | | - return version >= 7.6; |
| 84 | + return (!TinyVer.isLessThan(tinymce, '7.6.0')) |
87 | 85 | }; |
88 | 86 |
|
89 | 87 | class TinyMceEditor extends HTMLElement { |
@@ -258,18 +256,11 @@ class TinyMceEditor extends HTMLElement { |
258 | 256 | editor.on("init", (_e: unknown) => { |
259 | 257 | const tinymce = this._getTinymce(); |
260 | 258 | const isDisableSupported = isDisabledOptionSupported(tinymce); |
261 | | - if (isDisableSupported) { |
262 | | - if (this.hasAttribute('readonly')) { |
263 | | - this.setAttribute('readonly', ''); |
264 | | - } else { |
265 | | - this.removeAttribute('readonly'); |
266 | | - } |
267 | | - } else { |
268 | | - if (!this.hasAttribute('disabled')) { |
269 | | - this.setAttribute('disabled', ''); |
270 | | - } else { |
271 | | - this.removeAttribute('disabled'); |
272 | | - } |
| 259 | + if (isDisableSupported && this.hasAttribute('disabled')) { |
| 260 | + editor.options.set('disabled', true); |
| 261 | + } |
| 262 | + if (this.hasAttribute('readonly')) { |
| 263 | + editor.options.set('readonly', true); |
273 | 264 | } |
274 | 265 | this._status = Status.Ready; |
275 | 266 | }); |
@@ -358,46 +349,42 @@ class TinyMceEditor extends HTMLElement { |
358 | 349 |
|
359 | 350 | get readonly(): boolean { |
360 | 351 | if (this._editor) { |
361 | | - return this._editor.mode.get() === "readonly"; |
| 352 | + return this._editor.mode.get() === 'readonly'; |
362 | 353 | } else { |
363 | | - return this.hasAttribute("readonly"); |
| 354 | + return this.hasAttribute('readonly'); |
364 | 355 | } |
365 | 356 | } |
366 | 357 |
|
367 | 358 | set readonly(value: boolean) { |
368 | 359 | if (value) { |
369 | | - if (this._editor && this._editor.mode.get() !== "readonly") { |
370 | | - this._editor.mode.set("readonly"); |
| 360 | + if (this._editor && this._editor.mode.get() !== 'readonly') { |
| 361 | + this._editor.mode.set('readonly'); |
371 | 362 | } |
372 | | - if (!this.hasAttribute("readonly")) { |
373 | | - this.setAttribute("readonly", ""); |
| 363 | + if (!this.hasAttribute('readonly')) { |
| 364 | + this.setAttribute('readonly', ''); |
374 | 365 | } |
375 | 366 | } else { |
376 | | - if (this._editor && this._editor.mode.get() === "readonly") { |
377 | | - this._editor.mode.set("design"); |
| 367 | + if (this._editor && this._editor.mode.get() === 'readonly') { |
| 368 | + this._editor.mode.set('design'); |
378 | 369 | } |
379 | | - if (this.hasAttribute("readonly")) { |
380 | | - this.removeAttribute("readonly"); |
| 370 | + if (this.hasAttribute('readonly')) { |
| 371 | + this.removeAttribute('readonly'); |
381 | 372 | } |
382 | 373 | } |
383 | 374 | } |
384 | 375 |
|
385 | 376 | get disabled(): boolean { |
386 | 377 | return this._editor |
387 | | - ? this._editor.options.get("disabled") |
388 | | - : this.hasAttribute("disabled"); |
| 378 | + ? this._editor.options.get('disabled') |
| 379 | + : this.hasAttribute('disabled'); |
389 | 380 | } |
390 | 381 |
|
391 | 382 | set disabled(value: boolean) { |
392 | 383 | const tinymce = this._getTinymce?.(); |
393 | | - const isNew = tinymce ? isDisabledOptionSupported(tinymce) : true; |
| 384 | + const isVersionNewer = tinymce ? isDisabledOptionSupported(tinymce) : true; |
394 | 385 |
|
395 | | - if (this._editor && this._status === Status.Ready) { |
396 | | - if (isNew) { |
397 | | - this._editor.options.set('disabled', value); |
398 | | - } else { |
399 | | - this._editor.mode.set(value ? 'readonly' : 'design'); |
400 | | - } |
| 386 | + if (this._editor && this._status === Status.Ready && isVersionNewer) { |
| 387 | + this._editor.options.set('disabled', value); |
401 | 388 | } |
402 | 389 |
|
403 | 390 | if (value && !this.hasAttribute('disabled')) { |
|
0 commit comments