mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
b559d41bed
Summary: - The main purpose of this is to be able to properly register the editor for the markdown plugin (and any other plugins to come) - Refactors ComposerView and Contenteditable -> - Replaces Contenteditable with an InjectedComponent for a new region role: "Composer:Editor" - Creates a new component called ComposerEditor, which is the one that is being registered by default as "Composer:Editor" - I used this class to try to standardize the props that should be passed to any would be editor Component: - Renamed a bunch of the props which (I think) had a bit of confusing names - Added a bunch of docs for these in the source file, although I feel like those docs should live elsewhere, like in the ComponentRegion docs. - In the process, I ended up pulling some stuff out of ComposerView and some stuff out of the Contenteditable, namely: - The scrolling logic to ensure that the composer is visible while typing was moved outside of the Contenteditable -- this feels more like the ComposerEditor's responsibility, especially since the Contenteditable is meant to be used in other contexts as well. - The ComposerExtensions state; it feels less awkward for me if this is inside the ComposerEditor because 1) ComposerView does less things, 2) these are actually just being passed to the Contenteditable, 3) I feel like other plugins shouldn't need to mess around with ComposerExtensions, so we shouldn't pass them to the editor. If you register an editor different from our default one, any other ComposerExtension callbacks will be disabled, which I feel is expected behavior. - I think there is still some more refactoring to be done, and I left some TODOS here and there, but I think this diff is already big enough and its a minimal set of changes to get the markdown editor working in a not so duck tapish way. - New props for InjectedComponent: - `requiredMethods`: allows you to define a collection of methods that should be implemented by any Component that registers for your desired region. - It will throw an error if these are not implemented - It will automatically pass calls made on the InjectedComponent to these methods down to the instance of the actual registered component - Would love some comments on this approach and impl - `fallback`: allows you to define a default component to use if none were registered through the ComponentRegistry - Misc: - Added a new test case for the QuotedHTMLTransformer - Tests: - They were minimally updated so that they don't break, but a big TODO is to properly refactor them. I plan to do that in an upcoming diff. Test Plan: - Unit tests Reviewers: bengotow, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D2372
85 lines
2.3 KiB
CoffeeScript
85 lines
2.3 KiB
CoffeeScript
React = require 'react'
|
|
classNames = require 'classnames'
|
|
|
|
MessageItem = require './message-item'
|
|
|
|
{Utils,
|
|
DraftStore,
|
|
MessageStore} = require 'nylas-exports'
|
|
|
|
{InjectedComponent} = require 'nylas-component-kit'
|
|
|
|
class MessageItemContainer extends React.Component
|
|
@displayName = 'MessageItemContainer'
|
|
|
|
@propTypes =
|
|
thread: React.PropTypes.object.isRequired
|
|
message: React.PropTypes.object.isRequired
|
|
collapsed: React.PropTypes.bool
|
|
isLastMsg: React.PropTypes.bool
|
|
isBeforeReplyArea: React.PropTypes.bool
|
|
scrollTo: React.PropTypes.func
|
|
|
|
constructor: (@props) ->
|
|
@state = @_getStateFromStores()
|
|
|
|
componentWillReceiveProps: (newProps) ->
|
|
@setState(@_getStateFromStores())
|
|
|
|
componentDidMount: =>
|
|
if @props.message?.draft
|
|
@unlisten = DraftStore.listen @_onSendingStateChanged
|
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
|
not Utils.isEqualReact(nextProps, @props) or
|
|
not Utils.isEqualReact(nextState, @state)
|
|
|
|
componentWillUnmount: =>
|
|
@unlisten() if @unlisten
|
|
|
|
focus: => @refs.message.focus?()
|
|
|
|
render: =>
|
|
if @props.message.draft
|
|
if @state.isSending
|
|
@_renderMessage(pending: true)
|
|
else
|
|
@_renderComposer()
|
|
else
|
|
@_renderMessage(pending: false)
|
|
|
|
_renderMessage: ({pending}) =>
|
|
<MessageItem ref="message"
|
|
pending={pending}
|
|
thread={@props.thread}
|
|
message={@props.message}
|
|
className={@_classNames()}
|
|
collapsed={@props.collapsed}
|
|
isLastMsg={@props.isLastMsg} />
|
|
|
|
_renderComposer: =>
|
|
props =
|
|
mode: "inline"
|
|
draftClientId: @props.message.clientId
|
|
threadId: @props.thread.id
|
|
scrollTo: @props.scrollTo
|
|
|
|
<InjectedComponent ref="message"
|
|
matching={role: "Composer"}
|
|
className={@_classNames()}
|
|
exposedProps={props} />
|
|
|
|
_classNames: => classNames
|
|
"draft": @props.message.draft
|
|
"unread": @props.message.unread
|
|
"collapsed": @props.collapsed
|
|
"message-item-wrap": true
|
|
"before-reply-area": @props.isBeforeReplyArea
|
|
|
|
_onSendingStateChanged: (draftClientId) =>
|
|
@setState(@_getStateFromStores()) if draftClientId is @props.message.clientId
|
|
|
|
_getStateFromStores: ->
|
|
isSending: DraftStore.isSendingDraft(@props.message.clientId)
|
|
|
|
module.exports = MessageItemContainer
|