12 |
- "use strict";(self.webpackChunk_twitter_responsive_web=self.webpackChunk_twitter_responsive_web||[]).push([["bundle.RichTextCompose","bundle.PlainTextCompose"],{85341:(e,t,n)=>{n.d(t,{Z:()=>h});n(6886),n(71372),n(36728);var o=n(2784),s=n(1503),r=n(93983),i=n(88027),a=n(32941),l=n(15236),d=n(80524);class c extends o.Component{constructor(...e){super(...e),this.state={queryContext:void 0,canShowTypeahead:!1},this._genericWrapperRef=o.createRef(),this.render=()=>{const{children:e,composeCommunityId:t,contextText:n,isInline:s,isInlineReply:a,onTypeaheadStateChange:l,source:d}=this.props,{canShowTypeahead:c,queryContext:h}=this.state,u=c&&h?{word:h.word,resultType:h.resultType}:void 0;return o.createElement(r.H1,{composeCommunityId:t,contextText:n,isInline:s,isInlineReply:a,onDismiss:this._handleDismiss,onSelectItem:this._handleSelectItem,onTypeaheadStateChange:l,query:u,ref:this._genericWrapperRef,source:d||i._4.Compose},e(this._handleInputChange))},this._getCaret=e=>e.getSelection().getStartOffset(),this._getPlaintextFromCurrentBlock=e=>{const t=e.getSelection().anchorKey;return e.getCurrentContent().getBlockForKey(t).getText()},this._handleSelectItem=e=>{const{onTextUpdated:t}=this.props,{queryContext:n}=this.state;if(n){const o=(0,d.k)(e,n.resultType);t(this._replaceToken(o,n))}this._setQueryContext(void 0)},this._handleInputChange=e=>{if(!(0,l.T)(e))throw new Error("RichTextTypeaheadComposeWrapper cannot handle plain text input changes");{const{queryContext:t}=this.state,n=t&&t.word,o=this._getPlaintextFromCurrentBlock(e),{end:s,start:r,word:i}=a.si(this._getCaret(e),o),l=a.bR(i||"","compose");if((null==l?void 0:l.q)===n)return;if(this._genericWrapperRef.current&&this._genericWrapperRef.current.resetSelectedItem(),-1===r)this._setQueryContext(void 0);else if(l){const{q:t,result_type:n}=l;this._setQueryContext({word:t,resultType:n,editorState:e,startIndex:r,endIndex:s})}else this._setQueryContext(void 0)}},this._setQueryContext=e=>this.setState({queryContext:e,canShowTypeahead:!!e}),this._handleDismiss=()=>this.setState({canShowTypeahead:!1})}_replaceToken(e,t){const{editorState:n,endIndex:o,startIndex:r}=t,i=n.getSelection().merge({anchorKey:n.getSelection().getFocusKey(),anchorOffset:r,focusOffset:o}),a=s.Modifier.replaceText(n.getCurrentContent(),i,e),l=s.EditorState.push(n,a,"insert-characters"),d=r+e.length,c=l.getSelection().merge({anchorOffset:d,focusOffset:d});return s.EditorState.forceSelection(l,c)}}const h=c},45181:(e,t,n)=>{n.r(t),n.d(t,{InlineComposeContainer:()=>d,default:()=>h});var o=n(2784),s=n(25686),r=n(70451),i=n(54044),a=n(73186),l=n(24306);const d=({history:e,location:t,parentTweetId:n,replyPressToggle:a,richTextInputContext:d,typeaheadWrapper:h})=>{const{isModal:u}=o.useContext(r.Z);return o.createElement(i.Z,null,(({containerWidth:r})=>o.createElement(s.Z,{style:c.root},o.createElement(l.Z,{history:e,isInline:!0,isModal:u,location:t,parentTweetId:n,replyPressToggle:a,richTextInputContext:d,typeaheadWrapper:h,windowWidth:r}))))},c=a.Z.create((e=>({root:{backgroundColor:e.colors.cellBackground,zIndex:1}}))),h=d},16457:(e,t,n)=>{n.r(t),n.d(t,{default:()=>s});n(2784);var o=n(45181);const s=(0,n(1482).Z)(o.default)},1482:(e,t,n)=>{n.d(t,{Z:()=>c});var o=n(7896),s=n(2784),r=n(20900),i=n(16259),a=n(85341),l=n(15973);const d={convertEmojiToEntities:r.Z.convertEmojiToEntities,element:i.Z,initEditorState:r.Z.initEditorState,insertTextAtCursor:r.Z.insertTextAtCursor,updateOverflowStyle:r.Z.updateOverflowStyle,dismissComposerCommandName:l.Bp,sendTweetCommandName:l.NF},c=e=>t=>s.createElement(e,(0,o.Z)({},t,{richTextInputContext:d,typeaheadWrapper:a.Z}))},59689:(e,t,n)=>{n.r(t),n.d(t,{default:()=>r});n(2784);var o=n(1482),s=n(53633);const r=(0,o.Z)(s.default)},16259:(e,t,n)=>{n.d(t,{Z:()=>m});var o=n(7896),s=(n(6886),n(36728),n(85940),n(2784)),r=n(1503),i=n(90601),a=n(1206),l=n(77934),d=n(26671),c=n(50829),h=n(73186),u=n(2753);const p=e=>(0,i.Z)("div",e),m=s.forwardRef(((e,t)=>{const n=l.wL();return s.createElement(C,(0,o.Z)({},e,{onFocus:t=>{e.onFocus&&e.onFocus(t),n("focus")},ref:t}))}));class C extends s.Component{constructor(...e){super(...e),this.state={containerClass:void 0},this._setSelectionToStart=()=>{const{editorState:e}=this.props,t=e.getCurrentContent().getFirstBlock().getKey();return r.EditorState.acceptSelection(e,new r.SelectionState({anchorKey:t,anchorOffset:0,focusKey:t,focusOffset:0,isBackward:!1}))},this._setFocusToStart=()=>{const e=this._setSelectionToStart();return r.EditorState.forceSelection(e,e.getSelection())},this._setFocusToEnd=()=>{const{autoFocus:e,editorState:t,onChange:n}=this.props;e?null==n||n(r.EditorState.moveFocusToEnd(t)):null==n||n(r.EditorState.moveSelectionToEnd(t))},this._setDraftJsStyle=()=>{const{placeholderTextColor:e}=this.props,t=u.w3({placeholderTextColor:e});this.setState({containerClass:t})},this.focus=()=>{this._editor&&this._editor.focus()},this.blur=()=>{this._editor&&this._editor.blur()},this.getValue=()=>this.props.editorState.getCurrentContent().getPlainText(),this.getOffsetHeight=()=>{const{editor:e}=this._editor||{};return e&&e.offsetHeight||0},this.clear=()=>{},this._setEditorRef=e=>{this._editor=e},this._handleViewClick=()=>this.focus(),this._onPastedFiles=e=>{const{onFilesAdded:t}=this.props,n=[];if(e.forEach((e=>{e instanceof File&&n.push(e)})),n.length){return(null==t?void 0:t(n))?"handled":"not-handled"}return"not-handled"},this._removeNewLines=(e,t)=>r.EditorState.push(t,r.Modifier.replaceText(t.getCurrentContent(),t.getSelection(),e.replace(/[\r\n]+/g," ")),"insert-characters"),this._onPastedText=(e,t,n)=>{const{multiline:o,onChange:s}=this.props;return s&&!o?(s(this._removeNewLines(e,n)),"handled"):"not-handled"},this._myKeyBindingFn=e=>{const{dismissComposerCommandName:t,keyBindingFn:n,sendTweetCommandName:o}=this.props,{hasCommandModifier:s}=r.KeyBindingUtil;return 13===e.keyCode&&s(e)?o:27===e.keyCode?t:(null==n?void 0:n(e))||(0,r.getDefaultKeyBinding)(e)},this._onKeyCommand=e=>{const{keyCommandHandlers:t}=this.props,n=t&&t[e];return n?(n(),"handled"):"not-handled"},this._onSingleLineReturn=(e,t)=>{const{handleReturn:n}=this.props;return null==n||n(e,t),"handled"},this._getContainerStyle=()=>{const{appTextSize:e,maxNumberOfLines:t,multiline:n,numberOfLines:o,withMaxHeight:s}=this.props,r=h.Z.theme.lineHeightsPx[{small:"subtext2",normal:"body",large:"headline1",subtext2:"subtext2",body:"body",headline1:"headline1"}[e]],i=(n&&o?o:1)*r;return s?{minHeight:i,maxHeight:(n&&t?t:1)*r}:{minHeight:i,height:"100%"}}}componentDidMount(){const{onChange:e,positionCursorAtBeginning:t,positionCursorAtEnd:n}=this.props;n?this._setFocusToEnd():t?null==e||e(this._setFocusToStart()):this.props.autoFocus&&this.focus(),this._setDraftJsStyle()}static getDerivedStateFromError(){return{}}componentDidCatch(e){d.Z.report(e,{tags:{userVisible:!0,draftJs:!0}})}render(){const{ariaActiveDescendant:e,ariaAutocomplete:t,ariaControls:n,ariaLabel:o,blockRenderMap:i,blockRendererFn:a,blockStyleFn:l,dragPlaceholder:d,editorState:m,handleReturn:C,multiline:g,onChange:f,onFocus:S,onKeyDown:_,onKeyPress:x,onKeyUp:T,placeholder:w,spellCheck:E,stripPastedStyles:F,style:b,testID:k}=this.props,{containerClass:v}=this.state;return s.createElement(p,{className:[g?void 0:u.YV,v].join(" ")},s.createElement(p,{onClick:this._handleViewClick,style:[this._getContainerStyle(),b],testID:k?`${k}RichTextInputContainer`:void 0},s.createElement(r.Editor,{ariaActiveDescendantID:e,ariaAutoComplete:t,ariaControls:n,ariaLabel:o,ariaMultiline:g,blockRenderMap:i,blockRendererFn:a,blockStyleFn:l,customAttrs:{[c.Z.NO_REFOCUS_ATTRIBUTE]:"true",onKeyPress:x,onKeyUp:T},customStyleMap:y(h.Z.theme),editorState:m,handleKeyCommand:this._onKeyCommand,handlePastedFiles:this._onPastedFiles,handlePastedText:this._onPastedText,handleReturn:g?C:this._onSingleLineReturn,keyBindingFn:this._myKeyBindingFn,onChange:f,onFocus:S,onKeyDown:_,placeholder:w,ref:this._setEditorRef,spellCheck:"false"!==E,stripPastedStyles:F,tabIndex:0,webDriverTestID:k}),d))}}C.defaultProps={appTextSize:"body",autoFocus:!1,keyCommandHandlers:{},maxNumberOfLines:30,multiline:!0,numberOfLines:6,onFocus:a.Z,positionCursorAtEnd:!1,spellCheck:"true",stripPastedStyles:!0,withMaxHeight:!0},C.propTypes={};const y=({colors:e})=>({overflow:{backgroundColor:e.red200}})}}]);
- //# sourceMappingURL=https://ton.local.twitter.com/responsive-web-internal/sourcemaps/client-web/bundle.RichTextCompose.535f23da.js.map
|