DMPRoadmap / roadmap

DCC/UC3 collaboration for a data management planning tool
MIT License
102 stars 109 forks source link

TinyMCE Related Console Warnings #3424

Open aaronskiba opened 2 weeks ago

aaronskiba commented 2 weeks ago

Please complete the following fields as applicable:

What version of the DMPRoadmap code are you running? (e.g. v2.2.0) v4.2.0 ("tinymce": "^6.4.1")

Description

aaronskiba commented 2 weeks ago

Testing forced_root_block:

forced_root_block: '' seems to default to forced_root_block: 'p', which is the same behaviour as not explicitly stating the forced_root_block: arg at all.

rails assets:clobber && rails assets:precompile was executed between code changes:

forced_root_block: ''

// app/javascript/src/superAdmin/notifications/edit.js
$(() => {
  Tinymce.init({ selector: '#notification_body', forced_root_block: '' });

Screenshot from 2024-06-12 15-40-28

3.0.5 :001 > Notification.last.body
  Notification Load (0.7ms)  SELECT "notifications".* FROM "notifications" ORDER BY "notifications"."id" DESC LIMIT $1  [["LIMIT", 1]]
 => "<p>Test 1</p>" 
3.0.5 :002 > 

forced_root_block: 'div'

// app/javascript/src/superAdmin/notifications/edit.js
$(() => {
  Tinymce.init({ selector: '#notification_body', forced_root_block: 'div' });

Screenshot from 2024-06-12 15-44-21

3.0.5 :002 > Notification.last.body
  Notification Load (1.9ms)  SELECT "notifications".* FROM "notifications" ORDER BY "notifications"."id" DESC LIMIT $1  [["LIMIT", 1]]
 => "<div>Test 2</div>" 
3.0.5 :003 > 

forced_root_block: 'p'

$(() => {
  Tinymce.init({ selector: '#notification_body', forced_root_block: 'p' });

Screenshot from 2024-06-12 15-46-38

3.0.5 :003 > Notification.last.body
  Notification Load (1.6ms)  SELECT "notifications".* FROM "notifications" ORDER BY "notifications"."id" DESC LIMIT $1  [["LIMIT", 1]]
 => "<p>Test 3</p>" 
3.0.5 :004 > 

Without forced_root_block: arg

$(() => {
  Tinymce.init({ selector: '#notification_body' });

Screenshot from 2024-06-12 15-50-02

3.0.5 :004 > Notification.last.body
  Notification Load (2.0ms)  SELECT "notifications".* FROM "notifications" ORDER BY "notifications"."id" DESC LIMIT $1  [["LIMIT", 1]]
 => "<p>Test 4</p>" 
3.0.5 :005 > 
aaronskiba commented 2 weeks ago

Testing autoresize_min_height:

tinymceEditor.settings is undefined

      container.find('.toggleable-field').find('.tinymce').each((_idx, el) => {
        const tinymceEditor = Tinymce.findEditorById($(el).attr('id'));
        if (tinymceEditor) {
          console.log('tinymceEditor: ', tinymceEditor);
          console.log('tinymceEditor.settings: ', tinymceEditor.settings);
          $(tinymceEditor.iframeElement).height(tinymceEditor.settings.autoresize_min_height);
        }
      });

Console Output:

tinymceEditor:  GD {plugins: {…}, contentCSS: Array(0), contentStyles: Array(0), loadedCSS: {…}, isNotDirty: true, …}
application.source.js:2 tinymceEditor.settings:  undefined
aaronskiba commented 2 weeks ago

After removing TinyMCE editor resize code from app/javascript/src/utils/conditionalFields.js: Screenshot from 2024-06-13 12-38-17 and experimenting with defaultOptions.min_height within app/javascript/src/utils/tinymce.js: Screenshot from 2024-06-13 12-40-22 Screenshot from 2024-06-13 12-41-50

(The same behaviour is observed even when we don't edit the code within app/javascript/src/utils/conditionalFields.js.)

aaronskiba commented 2 weeks ago

After removing TinyMCE editor resize code from app/javascript/src/utils/conditionalFields.js: Screenshot from 2024-06-13 12-38-17 and experimenting with defaultOptions.min_height within app/javascript/src/utils/tinymce.js: Screenshot from 2024-06-13 12-40-22 Screenshot from 2024-06-13 12-41-50

(The same behaviour is observed even when we don't edit the code within app/javascript/src/utils/conditionalFields.js.)

The following describes the observed behaviour:

https://www.tiny.cloud/docs/tinymce/latest/autoresize/#min_height

Screenshot from 2024-06-13 12-47-23

//app/javascript/src/utils/tinymce.js
export const defaultOptions = {
  selector: '.tinymce',
  statusbar: true,
  menubar: false,
  toolbar: 'bold italic | bullist numlist | link | table',
  plugins: 'table autoresize link advlist lists autolink',
  browser_spellcheck: true,
  advlist_bullet_styles: 'circle,disc,square', // Only disc bullets display on htmltoword
  target_list: false,
  elementpath: false,
  resize: true,
  min_height: 230,

Our codebase has 'autoresize' included within plugins: and min_height: 230. Thus, 230 is the minimum height that the editor can be shrunk down to.

Also, autoresize_min_height was replaced with min_height in tinymce v5:

https://www.tiny.cloud/blog/how-to-migrate-from-tinymce-4-to-tinymce-5/ Screenshot from 2024-06-13 13-18-16