You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
6.7 KiB
2 lines
6.7 KiB
(window.webpackJsonp=window.webpackJsonp||[]).push([[35],{1595:function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return R}));var o=n(130),a=n.n(o),r=n(132),i=n.n(r),c=n(120),s=n.n(c),l=n(126),d=n.n(l),m=n(928),u=n(121),b=n(123);function p(e){let{onCancelClick:t,onSaveClick:n,isSaveDisabled:o=!1}=e;return s.a.createElement("div",{className:"mx_EditWysiwygComposer_buttons"},s.a.createElement(b.a,{kind:"secondary",onClick:t},Object(u.a)("Cancel")),s.a.createElement(b.a,{kind:"primary",onClick:n,disabled:o},Object(u.a)("Save")))}var g=n(124),f=n(128),y=n(138),v=n(236),O=n(645),j=n(335),C=n(398),E=n(314);var h=n(133),_=n(399),w=n(936);var T=n(451),k=n(253),x=n(125);function S(e){const t=Object(y.c)(),n=Object(h.b)();return Object(c.useMemo)((()=>{if(e&&t.room)return function(e,t,n){const o=new k.a(t,n);let a;if(e.hasEditorState())a=e.getSerializedParts().map((e=>o.deserializePart(e)));else{if("org.matrix.custom.html"===e.getEvent().getContent().format)return function(e){var t;return(null===(t=e.getEvent().getContent().formatted_body)||void 0===t?void 0:t.replace(/<mx-reply>.*<\/mx-reply>/,""))||""}(e);a=Object(T.b)(e.getEvent(),o,{shouldEscape:x.b.getValue("MessageComposerInput.useMarkdown")})}return a.reduce(((e,t)=>e+t.text),"")}(e,t.room,n)}),[e,t,n])}const M=["editorStateTransfer","className"],P=Object(c.forwardRef)((function(e,t){let{disabled:n=!1,composerFunctions:o}=e;return function(e,t,n){const o=Object(y.c)(),a=Object(E.c)(),r=Object(c.useRef)(null),i=Object(c.useCallback)((i=>{var c;if(e||!t.current)return;const s=null!==(c=i.context)&&void 0!==c?c:y.a.Room;switch(i.action){case f.a.FocusEditMessageComposer:Object(O.a)(t,s,o,r);break;case f.a.ComposerInsert:if(i.timelineRenderingType!==o.timelineRenderingType)break;if(i.composerType!==j.a.Edit)break;i.text&&Object(C.d)(a.selection).then((()=>n.insertText(i.text)))}}),[e,t,n,r,o,a]);Object(v.a)(g.a,i)}(n,t,o),null}));function R(e){let{editorStateTransfer:t,className:n}=e,o=i()(e,M);const r=Object(c.useRef)(Object(E.b)({editorStateTransfer:t})),l=S(t),u=!t||void 0!==l,{editMessage:b,endEditing:g,onChange:f,isSaveDisabled:v}=function(e,t){const n=Object(y.c)(),o=Object(h.b)(),[a,r]=Object(c.useState)(!0),[i,s]=Object(c.useState)(t);return{onChange:Object(c.useCallback)((e=>{s(e),r((n=>n&&e===t))}),[t]),editMessage:Object(c.useCallback)((()=>void 0!==i&&Object(w.editMessage)(i,{roomContext:n,mxClient:o,editorStateTransfer:e})),[i,n,o,e]),endEditing:Object(c.useCallback)((()=>Object(_.b)(n)),[n]),isSaveDisabled:a}}(t,l);return u?s.a.createElement(E.a.Provider,{value:r.current},s.a.createElement(m.a,a()({className:d()("mx_EditWysiwygComposer",n),initialContent:l,onChange:f,onSend:b},o),((e,t)=>s.a.createElement(s.a.Fragment,null,s.a.createElement(P,{disabled:o.disabled,ref:e,composerFunctions:t}),s.a.createElement(p,{onCancelClick:g,onSaveClick:b,isSaveDisabled:v}))))):null}},936:function(e,t,n){"use strict";n.r(t),n.d(t,"sendMessage",(function(){return _})),n.d(t,"editMessage",(function(){return w}));var o=n(132),a=n.n(o),r=n(170),i=n(189),c=n(125),s=n(450),l=n(271),d=n(247),m=n(309),u=n(124),b=n(373),p=n(399),g=n(13),f=n.n(g),y=n(646),v=n(136),O=n(225);function j(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function C(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?j(Object(n),!0).forEach((function(t){f()(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):j(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}async function E(e,t,n){let{relation:o,replyToEvent:a,permalinkCreator:r,includeReplyLegacyFallback:i=!0,editedEvent:s}=n;const l=Boolean(s),d=l?Boolean(null==s?void 0:s.replyEventId):Boolean(a),m=l&&d,u=t?await Object(y.richToPlain)(e):e,b=m&&function(e){const t=e.getContent().body;if("string"!=typeof t)return"";const n=t.split("\n").map((e=>e.trim()));return n.length>2&&n[0].startsWith("> ")&&0===n[1].length?`${n[0]}\n\n`:""}(s)||"",p=m&&function(e){const t=e.getContent().formatted_body;if(!t)return"";const n=(new DOMParser).parseFromString(t,"text/html").body.querySelector("mx-reply");return n&&n.outerHTML||""}(s)||"",g={msgtype:v.MsgType.Text,body:l?`${b} * ${u}`:u},f=c.b.getValue("MessageComposerInput.useMarkdown"),j=t?e:f?await Object(y.plainToRich)(e):null;j&&(g.format="org.matrix.custom.html",g.formatted_body=l?`${p} * ${j}`:j),l&&(g["m.new_content"]={msgtype:g.msgtype,body:u},j&&(g["m.new_content"].format="org.matrix.custom.html",g["m.new_content"].formatted_body=j));return function(e,t){t&&(e["m.relates_to"]=C(C({},e["m.relates_to"]||{}),t))}(g,l?C(C({},o),{},{rel_type:"m.replace",event_id:s.getId()}):o),!l&&a&&r&&Object(O.a)(g,a,{permalinkCreator:r,includeLegacyFallback:i}),g}const h=["roomContext","mxClient"];async function _(e,t,n){let{roomContext:o,mxClient:b}=n,p=a()(n,h);const{relation:g,replyToEvent:f}=p,{room:y}=o,v=null==y?void 0:y.roomId;if(!v)return;const O={eventName:"Composer",isEditing:!1,isReply:Boolean(f),inThread:(null==g?void 0:g.rel_type)===r.d.name};i.a.instance.trackEvent(O);const j=await E(e,t,p);if(!j.body.trim())return;c.b.getValue("Performance.addSendMessageTimingMetadata")&&Object(s.a)(j);const C=null!=g&&g.event_id&&(null==g?void 0:g.rel_type)===r.d.name?g.event_id:null,_=Object(l.a)(v,(e=>b.sendMessage(e,C,j)),b);return f&&u.a.dispatch({action:"reply_to_event",event:null,context:o.timelineRenderingType}),u.a.dispatch({action:"message_sent"}),d.CHAT_EFFECTS.forEach((e=>{if(Object(m.containsEmoji)(j,e.emojis)){(null==g?void 0:g.rel_type)!==r.d.name&&u.a.dispatch({action:`effects.${e.command}`})}})),c.b.getValue("Performance.addSendMessageTimingMetadata")&&_.then((e=>{Object(s.b)(b,v,e.event_id)})),c.b.getValue("scrollToBottomOnMessageSent")&&u.a.dispatch({action:"scroll_to_bottom",timelineRenderingType:o.timelineRenderingType}),_}async function w(e,t){let{roomContext:n,mxClient:o,editorStateTransfer:a}=t;const r=a.getEvent();i.a.instance.trackEvent({eventName:"Composer",isEditing:!0,inThread:Boolean(null==r?void 0:r.getThread()),isReply:Boolean(r.replyEventId)});const c=await E(e,!0,{editedEvent:r}),s=c["m.new_content"];if(""===(null==s?void 0:s.body))return Object(p.a)(o,a),void Object(b.a)({mxEvent:r,onCloseDialog:()=>{Object(p.b)(n)}});let l;const d=r.getRoomId();if(function(e,t){const n=t.getEvent().getContent();return n.msgtype!==e.msgtype||n.body!==e.body||n.format!==e.format||n.formatted_body!==e.formatted_body}(s,a)&&d){Object(p.a)(o,a);const e=a.getEvent().threadRootId||null;l=o.sendMessage(d,e,c),u.a.dispatch({action:"message_sent"})}return Object(p.b)(n),l}}}]);
|
|
//# sourceMappingURL=35.js.map
|