Skip to content
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

OD-378 [Feature] Upgrade TinyMCE 4 to TinyMCE 5 for Form component #375

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
83 changes: 55 additions & 28 deletions js/components/wysiwyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Fliplet.FormBuilder.field('wysiwyg', {
},
computed: {
isInterface: function() {
return Fliplet.Env.get('interface');
return Fliplet.Env.get('interact') || Fliplet.Env.get('interface');
}
},
watch: {
Expand Down Expand Up @@ -132,46 +132,71 @@ Fliplet.FormBuilder.field('wysiwyg', {

var config = {
target: this.$refs.textarea,
theme: 'modern',
readonly: this.readonly,
mobile: {
theme: this.readonly
? 'silver'
: 'mobile',
plugins: [ 'autosave', 'lists', 'autolink' ],
toolbar: [ 'bold', 'italic', 'underline', 'bullist', 'numlist', 'removeformat' ]
height: lineHeight * this.rows,
menubar: false,
formats: {
removeformat: [
// Remove block containers
{
selector: 'div,main,article,aside,header,footer',
remove: 'all',
split: false,
expand: false,
block_expand: true,
deep: true
},
// Remove inline containers
{
selector: 'b,strong,em,i,font,u,strike,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins,span',
remove: 'all',
split: true,
expand: false,
deep: true
},
// Remove attributes
{
selector: '*',
attributes: ['style', 'class', 'id'],
split: false,
expand: false,
deep: true
}
]
},
plugins: [
'advlist autolink lists link directionality',
'autoresize fullscreen code paste'
].join(' '),
'advlist autolink lists link searchreplace print directionality',
'table paste pasteplaintext code'
],
statusbar: false,
toolbar: this.readonly
? false
: [
'bold italic underline',
'alignleft aligncenter alignright alignjustify | bullist numlist outdent indent',
'ltr rtl | link | removeformat code fullscreen'
].join(' | '),
image_advtab: true,
menubar: false,
statusbar: false,
: ['bold italic underline | alignleft aligncenter alignright alignjustify',
'bullist numlist outdent indent | ltr rtl',
'link | pasteplaintext removeformat | code | formatselect'].join(' | '),
mobile: {
toolbar_mode: 'sliding',
plugins: ''
},
paste_preprocess: function(plugin, args) {
// Clean up content before pasting
args.content = args.content
.replace(/ contenteditable="(true|false)"/g, '');
},
// Prevent URLs from being altered
// https://stackoverflow.com/questions/3796942
relative_urls: false,
remove_script_host: false,
convert_urls: true,
inline: false,
resize: false,
autoresize_bottom_margin: 0,
autoresize_max_height: lineHeight * this.rows,
autoresize_min_height: lineHeight * this.rows,
autofocus: false,
convert_urls: false,
branding: false,
setup: function(editor) {
$vm.editor = editor;

editor.on('init', function() {
$vm.addPlaceholder();
if ($vm.isInterface) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not interface, e.g. preview/live app, placeholder should also work as it currently does.

$vm.addPlaceholder();
}

$vm.addBulletedListShortcutsWindows();

if ($vm.defaultValueSource !== 'default') {
Expand Down Expand Up @@ -221,7 +246,9 @@ Fliplet.FormBuilder.field('wysiwyg', {
field: this,
config: config
}).then(function() {
tinymce.init(config);
if (!$vm.isInterface) {
tinymce.init(config);
}
});
});

Expand Down
78 changes: 0 additions & 78 deletions js/libs/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,56 +750,6 @@ new Vue({
this.accessRules.splice(accessRuleIndex, 1);
}
},
setupCodeEditor: function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like we're removing code editor from somewhere else in the form builder that's unrelated to the Rich Text field. It looks like the form submission confirmation HTML. We can't remove that.

What version of TinyMCE is running in the builder interface? If it's TinyMCE 4, then we can keep this running without having to change anything, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I returned setup for builder.

var $vm = this;

tinymce.init({
target: $vm.$refs.resulthtml,
theme: 'modern',
mobile: {
theme: 'mobile',
plugins: ['autosave', 'lists', 'autolink'],
toolbar: ['bold', 'italic', 'underline', 'bullist', 'numlist', 'removeformat']
},
plugins: [
'advlist autolink lists link directionality',
'autoresize fullscreen code paste'
].join(' '),
toolbar: [
'bold italic underline',
'alignleft aligncenter alignright alignjustify | bullist numlist outdent indent',
'ltr rtl | link | removeformat code fullscreen'
].join(' | '),
image_advtab: true,
menubar: false,
statusbar: false,
inline: false,
resize: false,
autoresize_bottom_margin: 5,
autofocus: false,
branding: false,
valid_elements: '*[*]',
allow_script_urls: true,
min_height: 200,
setup: function(editor) {
editor.on('init', function() {
$vm.resultEditor = editor;

// initialize value if it was set prior to initialization
if ($vm.settings.resultHtml) {
var updatedHtml = $vm.convertVueEventAttributes($vm.settings.resultHtml);

editor.setContent(updatedHtml, { format: 'raw' });
}
});

editor.on('change', function() {
$vm.settings.resultHtml = editor.getContent();
});
}
});
},

// Converts @event attributes to v-on:event
convertVueEventAttributes: function(html) {
var $html = $('<div/>').append(html);
Expand Down Expand Up @@ -869,13 +819,8 @@ new Vue({
}
},
'section': function(value) {
var $vm = this;

if (value === 'settings') {
$vm.setupCodeEditor();
changeSelectText();
} else {
tinymce.remove();
}
},
'settings.dataStore': function(value) {
Expand Down Expand Up @@ -983,29 +928,6 @@ new Vue({
$(selector).removeClass('is-loading');
}

$($vm.$refs.templateDescription).tinymce({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

plugins: [
'lists advlist image charmap hr code',
'searchreplace wordcount insertdatetime table textcolor colorpicker'
],
toolbar: [
'formatselect |',
'bold italic underline strikethrough |',
'forecolor backcolor |',
'alignleft aligncenter alignright alignjustify | bullist numlist outdent indent |',
'blockquote subscript superscript | table insertdatetime charmap hr |',
'removeformat | code'
].join(' '),
menubar: false,
statusbar: false,
min_height: 300,
setup: function(ed) {
$vm.editor = ed;
$vm.editor.on('keyup paste', function() {
$vm.settings.description = $vm.editor.getContent();
});
}
});

if ($vm.chooseTemplate && $vm.$refs.templateGallery) {
setTimeout(function() {
Expand Down
1 change: 1 addition & 0 deletions vendor/tinymce/icons/default/icons.min.js

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions vendor/tinymce/plugins/pasteplaintext/plugin.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Paste as Plain Text plugin
if (tinymce && tinymce.majorVersion === '5') {
tinymce.PluginManager.add('pasteplaintext', function (editor, url) {
var openDialog = function () {
return editor.windowManager.open({
title: 'Paste as Plain Text',
body: {
type: 'panel',
items: [
{
type: 'htmlpanel',
html: '<p>Please paste inside the following box using the keyboard (<strong style="font-weight:600">Cmd/Ctrl + V</strong>) and hit <strong style="font-weight:600">Paste</strong>.<br></p><style>.tox .tox-form__group--stretched { height: 240px; }</style>'
},
{
type: 'textarea',
name: 'text'
}
]
},
buttons: [
{
type: 'cancel',
text: 'Cancel'
},
{
type: 'submit',
text: 'Paste',
primary: true
}
],
onSubmit: function (api) {
var data = api.getData();

/* Insert content when the window form is submitted */
editor.insertContent(data.text.replace(/(?:\r\n|\r|\n)/g, '<br>'));
api.close();
}
});
};

/* Add a button that opens a window */
editor.ui.registry.addButton('pasteplaintext', {
icon: 'paste-text',
tooltip: 'Paste as Plain Text',
onAction: function () {
openDialog();
}
});

/* Return the metadata for the plugin */
return {
getMetadata: function () {
return {
name: 'Paste as Plain Text'
};
}
};
});
}
9 changes: 9 additions & 0 deletions vendor/tinymce/themes/silver/theme.min.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions widget.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"fliplet-datasources",
"codemirror",
"bootstrap",
"tinymce",
"moment"
],
"assets": [
Expand Down Expand Up @@ -93,7 +92,7 @@
"fliplet-media",
"font-awesome",
"moment",
"tinymce",
{ "name": "tinymce:5.7.0", "interact": false },
"fliplet-session"
],
"assets": [
Expand Down Expand Up @@ -130,6 +129,10 @@
"js/components/signature.js",
"js/components/wysiwyg.js",

"vendor/tinymce/icons/default/icons.min.js",
"vendor/tinymce/themes/silver/theme.min.js",
"vendor/tinymce/plugins/pasteplaintext/plugin.min.js",

"js/libs/form.js",
"css/form.css"
]
Expand Down