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

WIP: Add "insert items" menu item to editor #5071

Merged
merged 16 commits into from
May 24, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion client/components/tinymce/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import contactFormPlugin from './plugins/contact-form/plugin';
import afterTheDeadlinePlugin from './plugins/after-the-deadline/plugin';
import wptextpatternPlugin from './plugins/wptextpattern/plugin';
import toolbarPinPlugin from './plugins/toolbar-pin/plugin';
import insertMenuPlugin from './plugins/insert-menu/plugin';

[
wpcomPlugin,
Expand All @@ -49,6 +50,7 @@ import toolbarPinPlugin from './plugins/toolbar-pin/plugin';
wpcomSourcecode,
wpeditimagePlugin,
wplinkPlugin,
insertMenuPlugin,
mediaPlugin,
advancedPlugin,
wpcomTabindexPlugin,
Expand Down Expand Up @@ -110,6 +112,7 @@ const PLUGINS = [
'wplink',
'AtD',
'wpcom/autoresize',
'wpcom/insertmenu',
'wpcom/media',
'wpcom/advanced',
'wpcom/help',
Expand Down Expand Up @@ -284,7 +287,9 @@ module.exports = React.createClass( {
// future, we should calculate from the rendered editor bounds.
autoresize_min_height: Math.max( document.documentElement.clientHeight - 300, 300 ),

toolbar1: 'wpcom_add_media,formatselect,bold,italic,bullist,numlist,link,blockquote,alignleft,aligncenter,alignright,spellchecker,wp_more,wpcom_add_contact_form,wpcom_advanced',
toolbar1: config.isEnabled( 'post-editor/insert-menu' )
? 'wpcom_insert_menu,formatselect,bold,italic,bullist,numlist,link,blockquote,alignleft,aligncenter,alignright,spellchecker,wp_more,wpcom_advanced'
: 'wpcom_add_media,formatselect,bold,italic,bullist,numlist,link,blockquote,alignleft,aligncenter,alignright,spellchecker,wp_more,wpcom_add_contact_form,wpcom_advanced',
toolbar2: 'strikethrough,underline,hr,alignjustify,forecolor,pastetext,removeformat,wp_charmap,outdent,indent,undo,redo,wp_help',
toolbar3: '',
toolbar4: '',
Expand Down
32 changes: 32 additions & 0 deletions client/components/tinymce/plugins/insert-menu/menu-items.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';

import Gridicon from 'components/gridicon';
import SocialLogo from 'components/social-logo';
import i18n from 'lib/mixins/i18n';

const GridiconButton = ( { icon, label } ) => (
<div>
<Gridicon className="wpcom-insert-menu__menu-icon" icon={ icon } />
<span className="wpcom-insert-menu__menu-label">{ label }</span>
</div>
);

const SocialLogoButton = ( { icon, label } ) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused? Or I guess anticipating future additions?

Copy link
Member Author

Choose a reason for hiding this comment

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

was used, then wasn't used in this current PR - it was put in for the Instagram widget and I just didn't take it out.

<div>
<SocialLogo className="wpcom-insert-menu__menu-icon" icon={ icon } />
<span className="wpcom-insert-menu__menu-label">{ label }</span>
</div>
);

export default [
{
name: 'insert_media_item',
item: <GridiconButton icon="image-multiple" label={ i18n.translate( 'Add Media' ) } />,
cmd: 'wpcomAddMedia'
},
{
name: 'insert_contact_form',
item: <GridiconButton icon="mention" label={ i18n.translate( 'Add Contact Form' ) } />,
cmd: 'wpcomContactForm'
}
];
44 changes: 44 additions & 0 deletions client/components/tinymce/plugins/insert-menu/plugin.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import ReactDOM from 'react-dom';
import tinymce from 'tinymce/tinymce';
import { renderToString } from 'react-dom/server';

import Gridicon from 'components/gridicon';
import config from 'config';
import i18n from 'lib/mixins/i18n';

import menuItems from './menu-items';

const initialize = editor => {
menuItems.forEach( item =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose these menu items and button is still being "added" (but not used) even when the feature flag is disabled? Worth a check to early return perhaps? (example)

Copy link
Member Author

Choose a reason for hiding this comment

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

this was part of the call on how many places to scatter the config flag check. I felt that adding was light-weight enough to leave it in. if you want, I'll hide it behind the flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

this was part of the call on how many places to scatter the config flag check. I felt that adding was light-weight enough to leave it in. if you want, I'll hide it behind the flag.

I think it's probably pretty safe, but would be easy to think in future iterations that the plugin code here doesn't run unless the feature flag is enabled, which is not true. Since you'll likely be the one to make said changes, it's not much of a concern. Personally, I'd add the condition and early return to feel safer, but I see your point and wouldn't be too bothered to leave it out.

Copy link
Member Author

Choose a reason for hiding this comment

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

hidden behind the flag now

editor.addMenuItem( item.name, {
classes: 'wpcom-insert-menu__menu-item',
cmd: item.cmd,
onPostRender() {
this.innerHtml( renderToString( item.item ) );
}
} )
);

editor.addButton( 'wpcom_insert_menu', {
type: 'splitbutton',
title: i18n.translate( 'Insert content' ),
classes: 'btn wpcom-insert-menu insert-menu',
Copy link
Contributor

Choose a reason for hiding this comment

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

We could drop one or the other of these two insert-menu classes and consolidate styles to apply to only one. I'd probably suggest keeping the wpcom- prefixed class, as I caught myself looking through the TinyMCE source to see whether insert-menu is a built-in type.

Copy link
Member Author

Choose a reason for hiding this comment

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

@drw158 I would appreciate your direction here. When I cut out the insert-menu class the dropdown button breaks.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is quite strange, since there isn't any insert-menu class in the CSS. Possibly not CSS related?

Copy link
Member Author

Choose a reason for hiding this comment

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

@drw158 it's the mcd-insert-menu classes, because TinyMCE decided that we don't know how to add classes properly and added the prefix for us 😉

cmd: menuItems[0].cmd,
menu: menuItems.map( ( { name } ) => editor.menuItems[ name ] ),
onPostRender() {
ReactDOM.render(
<Gridicon icon="add-image" />,
this.$el[0].children[0]
);
}
} );
};

export default () => {
if ( ! config.isEnabled( 'post-editor/insert-menu' ) ) {
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 good, thanks 👍

return;
}

tinymce.PluginManager.add( 'wpcom/insertmenu', initialize );
};
80 changes: 80 additions & 0 deletions client/components/tinymce/plugins/insert-menu/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.post-editor,
.mce-inline-toolbar-grp {

.mce-toolbar .mce-btn-group .mce-btn.mce-insert-menu {
margin: 0;

&:hover .mce-open i.mce-caret,
&:focus .mce-open i.mce-caret {
color: lighten( $gray, 10% );
}

&:hover .gridicons-add-image,
&:focus .gridicons-add-image {
fill: lighten( $gray, 10% );
}

.mce-open:hover i.mce-caret,
.mce-open:focus i.mce-caret {
color: $gray-dark;
}

.gridicons-add-image:hover,
.gridicons-add-image:focus {
fill: $gray-dark;
}
}
}

.post-editor .mce-toolbar .mce-btn.mce-insert-menu .gridicon,
.wpcom-insert-menu__menu-icon.gridicon {
height: 24px;
width: 24px;
}

.mce-toolbar .mce-btn.mce-insert-menu button:first-child {
padding: 6px;
}

.mce-splitbtn.mce-insert-menu .mce-open.mce-active {
background-color: $white;
outline: 0;
}

.mce-btn.mce-insert-menu span {
padding-left: 0;
}

.mce-toolbar .mce-btn.mce-insert-menu .mce-open {
padding: 8px 12px;
}

.mce-container .wpcom-insert-menu__menu-label {
color: darken( $gray, 30% );
display: inline-block;
font-family: $sans;
margin-left: 8px;
margin-top: 2px;
}

.wpcom-insert-menu__menu-icon {
fill: $gray;
}

.mce-container.mce-menu .mce-container-body .mce-wpcom-insert-menu__menu-item {
padding: 9px 16px;
margin: 0;
border: none;

&:hover,
&:focus {

.wpcom-insert-menu__menu-label {
color: $blue-medium;
}

.wpcom-insert-menu__menu-icon {
fill: $blue-medium;
}
}
}
12 changes: 9 additions & 3 deletions client/components/tinymce/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import 'plugins/wplink/style';
@import 'plugins/calypso-alert/style';
@import 'plugins/insert-menu/style';
@import 'plugins/wpcom-help/style';
@import 'plugins/wpcom-charmap/style';
@import 'plugins/contact-form/style';
Expand Down Expand Up @@ -95,11 +96,13 @@
margin: 0 2px 0 0;
padding: 0 8px;
vertical-align: top;
border-left: 1px solid lighten( $gray, 30% );
border-right: 1px solid lighten( $gray, 30% );
height: 36px;

@include breakpoint( "<660px" ) {
border-right-color: $white;
border-left-color: $white;
padding: 2px 0;
}
}
Expand Down Expand Up @@ -220,7 +223,6 @@

.mce-toolbar .mce-btn-group .mce-wpcom-icon-button.mce-media button {
@include breakpoint( ">660px" ) {
border-right: 1px solid lighten( $gray, 30% );
font-size: 13px;
}
}
Expand Down Expand Up @@ -590,7 +592,9 @@ div.mce-path {
}
}

.mce-toolbar-grp:not( .mce-inline-toolbar-grp ) .mce-btn-group .mce-btn.mce-first {
// [TODO]: Selector `:not( .mce-wpcom-insert-menu )` unnecessary when
// `post-editor/insert-menu` feature enabled in all environments
.mce-toolbar-grp:not( .mce-inline-toolbar-grp ) .mce-btn-group .mce-btn.mce-first:not( .mce-wpcom-insert-menu ) {
margin-left: 4px;
}

Expand Down Expand Up @@ -727,10 +731,12 @@ div.mce-path {

.post-editor .mce-toolbar .mce-btn-group .mce-btn.mce-listbox:hover {
background-image: none;
border-left-color: lighten( $gray, 30% );
border-right-color: lighten( $gray, 30% );

@include breakpoint( "<660px" ) {
border-right-color: $white;
border-left-color: $white;
}

i.mce-caret {
Expand Down Expand Up @@ -998,7 +1004,7 @@ div.mce-menu .mce-menu-item-sep,
.mce-toolbar .mce-btn:hover .mce-open,
.mce-toolbar .mce-btn:focus .mce-open,
.mce-toolbar .mce-btn.mce-active .mce-open {
border-left-color: lighten( $gray, 20% );
border-left-color: lighten( $gray, 30% );
}

i.mce-i-bold,
Expand Down
1 change: 1 addition & 0 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"phone_signup": true,
"post-editor-github-link": false,
"post-editor/image-editor": false,
"post-editor/insert-menu": true,
"post-editor/media-advanced": true,
"press-this": true,
"reader": true,
Expand Down
1 change: 1 addition & 0 deletions config/horizon.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"perfmon": true,
"persist-redux": true,
"phone_signup": false,
"post-editor/insert-menu": true,
"press-this": true,
"reader": true,
"resume-editing": true,
Expand Down
1 change: 1 addition & 0 deletions config/stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"olark": true,
"perfmon": true,
"persist-redux": true,
"post-editor/insert-menu": true,
"press-this": true,
"reader": true,
"reader/full-errors": true,
Expand Down
1 change: 1 addition & 0 deletions config/wpcalypso.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"perfmon": true,
"persist-redux": true,
"phone_signup": true,
"post-editor/insert-menu": true,
"press-this": true,
"reader": true,
"reader/full-errors": true,
Expand Down