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

Media: Implement WIP advanced image settings dialog #2085

Merged
merged 1 commit into from
Jan 14, 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
5 changes: 5 additions & 0 deletions client/components/tinymce/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ module.exports = React.createClass( {
onTogglePin: React.PropTypes.func
},

contextTypes: {
store: React.PropTypes.object
},

getDefaultProps: function() {
return {
mode: 'tinymce',
Expand Down Expand Up @@ -256,6 +260,7 @@ module.exports = React.createClass( {
entity_encoding: 'raw',
keep_styles: false,
wpeditimage_html5_captions: true,
redux_store: this.context.store,

// Limit the preview styles in the menu/toolbar
preview_styles: 'font-family font-size font-weight font-style text-decoration text-transform',
Expand Down
38 changes: 38 additions & 0 deletions client/components/tinymce/plugins/media/advanced/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* External dependencies
*/
import React from 'react';
import ReactDomServer from 'react-dom/server';

/**
* Internal dependencies
*/
import i18n from 'lib/mixins/i18n';
import config from 'config';
import { toggleEditorMediaAdvanced } from 'state/ui/editor/media/actions';
import Gridicon from 'components/gridicon';

export default function( editor ) {
const store = editor.getParam( 'redux_store' );
if ( ! config.isEnabled( 'post-editor/media-advanced' ) || ! store ) {
return;
}

editor.addButton( 'wp_img_advanced', {
tooltip: i18n.translate( 'Edit', { context: 'verb' } ),

classes: 'toolbar-segment-start',

onPostRender() {
this.innerHtml( ReactDomServer.renderToStaticMarkup(
<button type="button" role="presentation" tabIndex="-1">
<Gridicon icon="pencil" size={ 18 } />
</button>
) );
},

onClick() {
store.dispatch( toggleEditorMediaAdvanced() );
}
} );
}
2 changes: 2 additions & 0 deletions client/components/tinymce/plugins/media/plugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var sites = require( 'lib/sites-list' )(),
notices = require( 'notices' ),
TinyMCEDropZone = require( './drop-zone' ),
restrictSize = require( './restrict-size' ),
advanced = require( './advanced' ),
Gridicon = require( 'components/gridicon' ),
config = require( 'config' );

Expand Down Expand Up @@ -647,6 +648,7 @@ function mediaButton( editor ) {
} );

restrictSize( editor );
advanced( editor );
}

module.exports = function() {
Expand Down
1 change: 1 addition & 0 deletions client/components/tinymce/plugins/wpeditimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function wpEditImage( editor ) {
'wpcom_img_size_decrease',
'wpcom_img_size_increase',
'wp_img_caption', // See plugins/media
'wp_img_advanced', // See plugins/media/advanced
'wp_img_remove'
] );
} );
Expand Down
9 changes: 9 additions & 0 deletions client/components/tinymce/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
color: darken( $gray, 20% );
}

.mce-toolbar .mce-btn .gridicon {
fill: darken( $gray, 20% );
}

.mce-colorbutton .mce-preview {
background-color: $gray-dark;
}
Expand Down Expand Up @@ -94,6 +98,11 @@
.mce-toolbar .mce-btn-group .mce-btn:focus .mce-ico {
color: $gray-dark;
}

.mce-toolbar .mce-btn-group .mce-btn:hover .gridicon,
.mce-toolbar .mce-btn-group .mce-btn:focus .gridicon {
fill: $gray-dark;
}
}

.mce-toolbar .mce-btn-group .mce-btn.mce-toolbar-segment-start:not( :first-child )::before,
Expand Down
43 changes: 43 additions & 0 deletions client/post-editor/editor-media-advanced/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* External depencencies
*/
import React, { PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

/**
* Internal dependencies
*/
import { toggleEditorMediaAdvanced } from 'state/ui/editor/media/actions';
import Dialog from 'components/dialog';

function EditorMediaAdvanced( { visible, toggleVisible } ) {
return (
<Dialog isVisible={ visible } onClose={ toggleVisible }>
WIP
</Dialog>
);
}

EditorMediaAdvanced.propTypes = {
visible: PropTypes.bool,
toggleVisible: PropTypes.func
};

EditorMediaAdvanced.defaultProps = {
visible: false,
toggleVisible: () => {}
};
Copy link
Member

Choose a reason for hiding this comment

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

why put these here when we are already using destructuring in the function declaration?

function EditorMediaAdvanced( { visible = false, toggleVisible = noop } ) {
    
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why put these here when we are already using destructuring in the function declaration?

You know, that's an interesting question. One has to wonder why defaultProps was one of the two properties that the React team chose to support for stateless functional components. Perhaps there's some semantics of defaultProps that wouldn't be reflected with the destructured default values? I couldn't find much discussion on the topic, though this commenter appears to prefer default arguments from a function purity perspective. On the flip-side, it does make the function declaration line a bit longer.

Do you have a strong preference either way? I'm inclined to keep it as is, mostly for aesthetics to this last point and for proximity to the propTypes declaration for quick scanning. Additionally, it may be that this is easier for static analysis if we choose to pursue some automated documentation of components.

Copy link
Member

Choose a reason for hiding this comment

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

Do you have a strong preference either way?

not at all 😄


export default connect(
( state ) => {
return {
visible: state.ui.editor.media.advanced
};
},
( dispatch ) => {
return bindActionCreators( {
toggleVisible: toggleEditorMediaAdvanced
}, dispatch );
}
)( EditorMediaAdvanced );
4 changes: 4 additions & 0 deletions client/post-editor/post-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var actions = require( 'lib/posts/actions' ),
EditorDrawer = require( 'post-editor/editor-drawer' ),
FeaturedImage = require( 'post-editor/editor-featured-image' ),
EditorGroundControl = require( 'post-editor/editor-ground-control' ),
EditorMediaAdvanced = require( 'post-editor/editor-media-advanced' ),
EditorTitleContainer = require( 'post-editor/editor-title/container' ),
EditorPageSlug = require( 'post-editor/editor-page-slug' ),
Button = require( 'components/button' ),
Expand Down Expand Up @@ -286,6 +287,9 @@ var PostEditor = React.createClass( {

return (
<div className="post-editor">
{ config.isEnabled( 'post-editor/media-advanced' ) && (
<EditorMediaAdvanced />
) }
<div className="post-editor__inner">
<div className="post-editor__content">
<EditorMobileNavigation site={ site } onClose={ this.onClose } />
Expand Down
1 change: 1 addition & 0 deletions client/post-editor/test/post-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mockery.registerMock( 'components/tinymce', MOCK_COMPONENT );
mockery.registerMock( 'components/popover', MOCK_COMPONENT );
mockery.registerMock( 'components/forms/clipboard-button', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-mobile-navigation', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-media-advanced', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-ground-control', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-drawer', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-author', MOCK_COMPONENT );
Expand Down
1 change: 1 addition & 0 deletions client/state/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export const COMPLETE_EXPORT = 'COMPLETE_EXPORT';
export const CURRENT_USER_ID_SET = 'CURRENT_USER_ID_SET';
export const EDITOR_MEDIA_ADVANCED_TOGGLE = 'EDITOR_MEDIA_ADVANCED_TOGGLE';
export const FAIL_EXPORT = 'FAIL_EXPORT';
export const FETCH_SITE_PLANS = 'FETCH_SITE_PLANS';
export const FETCH_SITE_PLANS_COMPLETED = 'FETCH_SITE_PLANS_COMPLETED';
Expand Down
10 changes: 10 additions & 0 deletions client/state/ui/editor/media/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Internal dependencies
*/
import { EDITOR_MEDIA_ADVANCED_TOGGLE } from 'state/action-types';

export function toggleEditorMediaAdvanced() {
return {
type: EDITOR_MEDIA_ADVANCED_TOGGLE
};
}
23 changes: 23 additions & 0 deletions client/state/ui/editor/media/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* External dependencies
*/
import { combineReducers } from 'redux';

/**
* Internal dependencies
*/
import { EDITOR_MEDIA_ADVANCED_TOGGLE } from 'state/action-types';

function advanced( state = false, action ) {
switch ( action.type ) {
case EDITOR_MEDIA_ADVANCED_TOGGLE:
state = ! state;
break;
}

return state;
}

export default combineReducers( {
advanced
} );
13 changes: 13 additions & 0 deletions client/state/ui/editor/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* External dependencies
*/
import { combineReducers } from 'redux';

/**
* Internal dependencies
*/
import media from './media/reducer';

export default combineReducers( {
media
} );
4 changes: 3 additions & 1 deletion client/state/ui/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SET_SECTION,
CURRENT_USER_ID_SET
} from 'state/action-types';
import editor from './editor/reducer';

/**
* Tracks the currently selected site ID.
Expand Down Expand Up @@ -72,5 +73,6 @@ export default combineReducers( {
isLoading,
hasSidebar,
selectedSiteId,
currentUserId
currentUserId,
editor
} );
1 change: 1 addition & 0 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"post-editor-github-link": false,
"post-editor/post-type-switch": false,
"post-editor/contact-form": true,
"post-editor/media-advanced": true,

"manage/media": true,
"manage/posts": true,
Expand Down