@vector-im/matrix-wysiwyg 2.40.0 → 2.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,4 @@
1
- (function(g,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react"),require("@vector-im/matrix-wysiwyg-wasm")):typeof define=="function"&&define.amd?define(["exports","react","@vector-im/matrix-wysiwyg-wasm"],_):(g=typeof globalThis<"u"?globalThis:g||self,_(g["Matrix wysiwyg"]={},g.React,g.matrixWysiwygWasm))})(this,function(g,_,y){"use strict";function k(e){return"inputType"in e}function A(e){return"clipboardData"in e}function M(e){return k(e)&&e.inputType==="insertSuggestion"}function ee(e){return k(e)&&e.inputType==="insertAtRoomSuggestion"}function te(e){return k(e)&&e.inputType=="insertLink"}function I(e,t,n,s){return s?s(e,t,n):e}function ne(e,t,n,s,r,o,u,l){const a=I(e,{actions:s,content:()=>t.get_content_as_html(),messageContent:()=>t.get_content_as_message_html()},r,u);if(!a)return;if(A(a)){const i=a.clipboardData,f=i?.getData("text/html"),m=i?.getData("text/plain")??"";if(f&&f!==m){const d=i?.types.includes("application/x-vnd.google-docs-document-slice-clip+wrapped")?y.HtmlSource.GoogleDoc:y.HtmlSource.UnknownExternal;return n(t.replace_html(f,d),"replace_html_paste")}return n(t.replace_text(m),"replace_text_paste")}switch(a.inputType){case"insertAtRoomSuggestion":{if(o&&ee(a)){const{attributes:i}=a.data;return i.has("data-mention-type")&&i.delete("data-mention-type"),n(t.insert_at_room_mention_at_suggestion(o,i),"insert_at_room_mention_at_suggestion")}break}case"insertSuggestion":{if(o&&M(a)){const{text:i,url:f,attributes:m}=a.data;return m.has("data-mention-type")&&m.delete("data-mention-type"),n(t.insert_mention_at_suggestion(f,i,o,m),"insert_mention_at_suggestion")}break}case"insertCommand":case"insertEmoji":{if(o&&a.data){const i=a.inputType==="insertCommand";return n(t.replace_text_suggestion(a.data,o,i),"replace_text_suggestion")}break}case"clear":return n(t.clear(),"clear");case"deleteContentBackward":return n(t.backspace(),"backspace");case"deleteWordBackward":return n(t.backspace_word(),"backspace_word");case"deleteSoftLineBackward":{const i=document.getSelection();return i&&(i.modify("extend","backward","lineboundary"),document.dispatchEvent(new CustomEvent("selectionchange"))),n(t.delete(),"backspace_line")}case"deleteContentForward":return n(t.delete(),"delete");case"deleteWordForward":return n(t.delete_word(),"delete_word");case"deleteByCut":return n(t.delete(),"delete");case"formatBold":return n(t.bold(),"bold");case"formatItalic":return n(t.italic(),"italic");case"formatStrikeThrough":return n(t.strike_through(),"strike_through");case"formatUnderline":return n(t.underline(),"underline");case"formatInlineCode":return n(t.inline_code(),"inline_code");case"historyRedo":return n(t.redo(),"redo");case"historyUndo":return n(t.undo(),"undo");case"insertCodeBlock":return n(t.code_block(),"code_block");case"insertQuote":return n(t.quote(),"quote");case"insertFromPaste":return;case"insertOrderedList":return n(t.ordered_list(),"ordered_list");case"insertLineBreak":case"insertParagraph":return c(t,o,l),n(t.enter(),"enter");case"insertReplacementText":{const i=r.innerHTML.slice(0,r.innerHTML.length-4);return n(t.set_content_from_html(i),"set_content_from_html",i)}case"insertCompositionText":case"insertFromComposition":case"insertText":if(a.data)return a.data==" "&&c(t,o,l),n(t.replace_text(a.data),"replace_text",a.data);break;case"insertUnorderedList":return n(t.unordered_list(),"unordered_list");case"insertLink":if(te(a)){const{text:i,url:f}=a.data;return n(i?t.set_link_with_text(f,i,new Map):t.set_link(f,new Map),"insertLink")}break;case"removeLinks":return n(t.remove_links(),"remove_links");case"formatIndent":return n(t.indent(),"indent");case"formatOutdent":return n(t.unindent(),"unindent");case"sendMessage":return null;default:return console.error(`Unknown input type: ${a.inputType}`),console.error(e),null}function c(i,f,m){if(m&&f&&f.key.key_type==3&&f.key.custom_key_value){const d=m.get(f.key.custom_key_value);d&&i.replace_text_suggestion(d,f,!1)}}}function se(e,t){e.innerHTML="";const n=t.document();let s=0;function r(u,l,a,c){const i=document.createElement(l);if(a&&(i.innerText=a.replace("​","~")),c)for(const[f,m]of c.entries()){const d=document.createAttribute(f);m!==null&&(d.value=m),i.setAttributeNode(d)}return u.appendChild(i),i}function o(u,l){const a=r(l,"ul");a.className=`group_${s%10}`;const c=u.children(t);let i;for(;i=c.next_child();){const f=i.node_type(t);if(f==="container"){const d=`dom_${s}`;s++;const h=r(a,"li");r(h,"input",null,new Map([["type","checkbox"],["id",d],["checked",null]])),r(h,"label",i.tag(t),new Map([["for",d]])),o(i,h)}else if(f==="line_break")r(a,"li","br");else if(f==="text"){const m=r(a,"li");r(m,"span",'"',new Map([["class","quote"]])),r(m,"span",`${i.text(t)}`),r(m,"span",'"',new Map([["class","quote"]]))}else if(f==="mention"){const m=r(a,"li");r(m,"span",'"Mention - ',new Map([["class","quote"]])),r(m,"span",`${i.text(t)}`),r(m,"span",'"',new Map([["class","quote"]]))}else console.error(`Unknown node type: ${f}`)}}o(n,e)}function re(e,t,n){const s=document.createRange();let r=L(e,t),o=L(e,n);if(r.node&&o.node){const l=r.node.compareDocumentPosition(o.node)&Node.DOCUMENT_POSITION_PRECEDING,a=r.node===o.node&&o.offset<r.offset;if((l||a)&&([r,o]=[o,r],!r.node||!o.node))throw new Error;s.setStart(r.node,r.offset),s.setEnd(o.node,o.offset)}else s.selectNodeContents(e),s.collapse();const u=document.getSelection();u&&(u.removeAllRanges(),u.addRange(s))}function O(e,t,n,s){e.innerHTML=t+"<br />",re(e,n,s)}function L(e,t,n){const s=e.nodeName==="LI"&&!e.hasChildNodes(),r=e.nodeType===Node.TEXT_NODE;if(r&&e.parentElement?.hasAttribute("data-mention-type")){const l=x(e)?1:0,a=t-l;return a<=1?a===0?e.previousSibling?{node:e.previousSibling,offset:S(e.previousSibling,1/0)}:{node:e.parentNode?.parentNode??null,offset:0}:{node:null,offset:0}:{node:null,offset:t-l-1}}else if(r){const l=x(e)?1:0;return P(e)?t===0?{node:e,offset:t}:{node:null,offset:t-l}:t<=(e.textContent?.length||0)?{node:e,offset:t}:{node:null,offset:t-(e.textContent?.length||0)-l}}else{if(s)return t<=(e.textContent?.length||0)?{node:e,offset:t}:{node:null,offset:t-(e.textContent?.length||0)};if(e.nodeName==="BR")return t===0?{node:e,offset:0}:{node:null,offset:t-1};if(ie(e)&&t===0)return{node:e,offset:t};for(const u of e.childNodes){const l=L(u,t);if(l.node)return{node:l.node,offset:l.offset};t=l.offset}return{node:null,offset:t}}}function R(e,t){const n=e.childNodes.length===1&&e.firstChild?.nodeName==="BR";if(!t||n)return[0,0];const s=t.anchorNode&&D(e,t.anchorNode,t.anchorOffset)||0,r=t.focusNode&&D(e,t.focusNode,t.focusOffset)||0;return[s,r]}function S(e,t){if(e.nodeType===Node.TEXT_NODE){const s=x(e)?1:0;return(e.textContent?.length??0)+s}else{if(e.nodeName==="BR")return t===0?0:1;{let n=0,s=0;for(const r of e.childNodes){if(s===t)break;n+=S(r,-1),s++}return n}}}function B(e,t,n){const s=e.nodeType===Node.TEXT_NODE,r=e.parentElement?.hasAttribute("data-mention-type");if(e===t)return s?n>(e.textContent?.length??0)?{found:!1,offset:0}:r?{found:!0,offset:n===0?0:1}:{found:!0,offset:n}:{found:!0,offset:S(e,n)};if(s){const u=x(e)?1:0;return P(e)?{found:!1,offset:u}:r?{found:!1,offset:1+u}:{found:!1,offset:(e.textContent?.length??0)+u}}else{if(e.nodeName==="BR")return{found:!1,offset:1};{let o=0;for(const u of e.childNodes){const l=B(u,t,n);if(l.found)return{found:!0,offset:o+l.offset};o+=l.offset}return{found:!1,offset:o}}}}function D(e,t,n){if(t===e&&n===e.childNodes.length-1)return S(e,-1)-1;const s=new Range;s.setStart(e,0),s.setEnd(e,e.childNodes.length);const r=s.comparePoint(t,0);if(r===-1)return 0;if(r===1)return S(e,-1)-1;const o=B(e,t,n);return o.found?o.offset:-1}function x(e){if(e===null)return!1;let t=e;const n=H(t.parentNode);for(;t;){const s=t.nextSibling;if(s&&H(s)||n&&s&&!U(s)||s&&s.nodeName==="BR")break;if(U(t))return!0;t=t.parentNode}return!1}const $=["EM","U","STRONG","DEL","CODE","A"],oe=["OL","UL","LI","PRE","BLOCKQUOTE","P"];function H(e){return e===null?!1:$.includes(e.nodeName||"")}function U(e){return oe.includes(e.nodeName||"")}function ie(e){return $.includes(e.nodeName)&&e.textContent?.length===0}function P(e){const t=e.parentNode?.childNodes.length===1,n=e.parentNode?.nodeName==="P",s=e.textContent===" ";return n&&t&&s}const ae=["bold","italic","strikeThrough","underline","undo","redo","orderedList","unorderedList","inlineCode","clear","link","codeBlock","quote","indent","unindent"],ue=["@","#","/","",":"];function ce(){return ae.reduce((e,t)=>(e[t]="enabled",e),{})}function F(e){const t={};for(const[n,s]of e)t[n.substring(0,1).toLowerCase()+n.substring(1)]=s.toLowerCase();return t}function le(){const e=navigator.userAgent.toLowerCase();return e.includes("iphone")||e.includes("ipad")?"iOS":e.includes("android")?"Android":e.includes("win")?"Windows":e.includes("mac")?"macOS":e.includes("linux")?"Linux":null}function j(e,t,n,s){n?.preventDefault(),n?.stopPropagation(),e.dispatchEvent(new CustomEvent("wysiwygInput",{detail:{blockType:t,data:s}}))}function fe(e,t,n,s,r){if(e.shiftKey&&e.altKey)switch(e.key){case"5":return"formatStrikeThrough"}const o=le();if((o==="Windows"||o==="Linux")&&e.ctrlKey)switch(e.key){case"Backspace":return"deleteWordBackward"}if(e.ctrlKey||e.metaKey)switch(e.key){case"b":return"formatBold";case"i":return"formatItalic";case"u":return"formatUnderline";case"e":return"formatInlineCode";case"y":return"historyRedo";case"z":return"historyUndo";case"Z":return"historyRedo";case"Enter":return"sendMessage";case"Backspace":return"deleteSoftLineBackward"}return I(e,{actions:n,content:()=>t.get_content_as_html(),messageContent:()=>t.get_content_as_message_html()},s,r),null}function de(e,t,n,s,r){const o=fe(e,n,s,t,r);o&&j(t,o,e)}function q(e){return F(e.action_states)}function me(e,t,n,s,r,o,u,l,a){const c=ne(e,n,r.traceAction,o,t,u,l,a);if(c){const i=c.text_update().replace_all;i&&(O(t,i.replacement_html,i.start_utf16_codeunit,i.end_utf16_codeunit),r.setEditorHtml(i.replacement_html)),t.focus(),s&&se(s,n);const f=c.menu_state().update(),m=c.menu_action().suggestion()?.suggestion_pattern,d=f?q(f):null,h=m||null;return{content:i?.replacement_html,actionStates:d,suggestion:h}}}function _e(e,t,{traceAction:n,getSelectionAccordingToActions:s}){const[r,o]=R(e,document.getSelection()),u=t.selection_start(),l=t.selection_end(),[a,c]=s();if(r===u&&r===a&&o===l&&o===c||r===l&&r===c&&o===u&&o===a)return;const i=t.select(r,o);n(null,"select",r,o);const f=i.menu_state().update();if(f)return q(f)}function pe(e,t,n,s,r,o,u,l){const[a,c]=_.useState({content:null,actionStates:ce(),suggestion:null}),i=_.useRef(void 0),[f,m]=_.useState(!1);return _.useEffect(()=>{n&&(c({content:n.get_content_as_html(),actionStates:F(n.action_states()),suggestion:null}),i.current=n.get_content_as_plain_text())},[n]),_.useEffect(()=>{const d=e.current;if(!n||!d)return;const h=p=>{try{const E=me(p,d,n,t.current,s,r,a.suggestion,u,l);E&&(c(T=>{const He=E.content!==void 0?E.content:T.content,Ue=E.actionStates||T.actionStates,Pe=E.suggestion;return{content:He,actionStates:Ue,suggestion:Pe}}),i.current=n.get_content_as_plain_text())}catch{o(i.current)}},b=p=>{k(p)&&!p.isComposing&&h(p)};d.addEventListener("input",b);const N=p=>{const E=k(p)&&p.inputType==="insertFromPaste"&&p.dataTransfer!==null;(A(p)||E)&&(p.preventDefault(),p.stopPropagation(),h(p))};d.addEventListener("paste",N);const Q=p=>{h({inputType:p.detail.blockType,data:p.detail.data})};d.addEventListener("wysiwygInput",Q);const Y=p=>{de(p,d,n,r,u)};d.addEventListener("keydown",Y);const J=()=>{try{const p=_e(d,n,s);p&&c(({content:E,suggestion:T})=>({content:E,actionStates:p,suggestion:T})),i.current=n.get_content_as_plain_text()}catch{o(i.current)}};document.addEventListener("selectionchange",J);const Z=p=>{if(!(k(p)&&p.isComposing))return N(p)};d.addEventListener("beforeinput",Z);const W=p=>{const E=new InputEvent("input",{data:p.data,inputType:"insertCompositionText"});b(E)};return d.addEventListener("compositionend",W),m(!0),()=>{m(!1),d.removeEventListener("input",b),d.removeEventListener("paste",N),d.removeEventListener("wysiwygInput",Q),d.removeEventListener("keydown",Y),d.removeEventListener("beforeinput",Z),d.removeEventListener("compositionend",W),document.removeEventListener("selectionchange",J)}},[e,l,n,r,t,s,u,o,i,a.suggestion]),{areListenersReady:f,...a}}function ge(e,t){return _.useMemo(()=>{const s=(r,o)=>{e.current&&j(e.current,r,void 0,o)};return{bold:()=>s("formatBold"),italic:()=>s("formatItalic"),strikeThrough:()=>s("formatStrikeThrough"),underline:()=>s("formatUnderline"),undo:()=>s("historyUndo"),redo:()=>s("historyRedo"),orderedList:()=>s("insertOrderedList"),unorderedList:()=>s("insertUnorderedList"),inlineCode:()=>s("formatInlineCode"),clear:()=>s("clear"),insertText:r=>s("insertText",r),link:(r,o)=>s("insertLink",{url:r,text:o}),removeLinks:()=>s("removeLinks"),getLink:()=>t?.get_link_action()?.edit_link?.url||"",codeBlock:()=>s("insertCodeBlock"),quote:()=>s("insertQuote"),indent:()=>s("formatIndent"),unindent:()=>s("formatOutdent"),mention:(r,o,u)=>s("insertSuggestion",{url:r,text:o,attributes:u}),command:r=>s("insertCommand",r),emoji:r=>s("insertEmoji",r),mentionAtRoom:r=>s("insertAtRoomSuggestion",{attributes:r})}},[e,t])}let K=!1,v=!1;async function w(){if(v)return Promise.resolve();if(K)return new Promise(e=>{function t(){v&&e(),setTimeout(t,200)}t()});K=!0,await y.initAsync(),v=!0}function he(e,t,n){const[s,r]=_.useState(null),o=_.useCallback(async u=>{await w();let l;if(u)try{const a=y.new_composer_model_from_html(u,0,u.length);if(l=a,e.current){const c=a.get_content_as_html();O(e.current,c,0,c.length)}}catch{l=y.new_composer_model()}else l=y.new_composer_model();r(l)},[r,e]);return _.useEffect(()=>{s&&n&&s.set_custom_suggestion_patterns(n)},[s,n]),_.useEffect(()=>{e.current&&o(t)},[e,o,t]),{composerModel:s,onError:o}}function G(e){return e[0]==="select"}function Ee(e,t,n){return(s,r,o,u)=>(!e||!n||(console.debug(u!==void 0?`composer_model.${r}(${o}, ${u})`:o!==void 0?`composer_model.${r}(${o})`:`composer_model.${r}()`),t.push([r,o,u]),V(e,n,s,t)),s)}function ye(e){return()=>{for(let t=e.length-1;t>=0;t--){const n=e[t];if(G(n))return[n[1],n[2]]}return[-1,-1]}}function V(e,t,n,s){n&&n.text_update(),e.innerText=ke(s,t.to_example_format()),e.scrollTo(0,e.scrollHeight-e.clientHeight)}function ke(e,t){let n="";function s(c,i,f){c==="select"?n+=`model.select(Location::from(${i}), Location::from(${f}));
2
- `:f!==void 0?n+=`model.${c}(${i??""}, ${f});
3
- `:c==="replace_text"?n+=`model.${c}("${i??""}");
4
- `:c==="send"?n+=`// Send: ${i??""}
5
- `:n+=`model.${c}(${i??""});
6
- `}function r(){const c=Se(l,a[0],a[1]);n+=`let mut model = cm("${c}");
7
- `}let o=null,u=!0,l="",a=[0,0];for(const c of e){const[i,f,m]=c;if(u)i==="replace_text"?l+=Te(f):G(c)?a=[c[1],c[2]]:(u=!1,r(),s(i,f,m));else if(o==="select"&&i==="select"){const d=n.lastIndexOf(`
8
- `,n.length-2);d>-1&&(n=n.substring(0,d)+`
9
- `,s(i,f,m))}else s(i,f,m);o=i}return u&&r(),n+=`assert_eq!(tx(&model), "${t}");
10
- `,n}function Se(e,t,n){const s=y.new_composer_model_from_html(e,-1,-1);return s.select(t,n),s.to_example_format()}function Ce(e,t,n,s){const[r,o]=R(e,document.getSelection()),u=[["replace_text",s],["select",r,o]];return V(t,n,null,u),u}function Te(e){if(!e)return"";const t=document.createElement("p");return t.appendChild(document.createTextNode(e.toString())),t.innerHTML}function xe(e,t){const n=_.useRef(null),[s,r]=_.useState([]),[o,u]=_.useState(""),l=_.useCallback(m=>{n.current&&u(m)},[n]),a=_.useMemo(()=>Ee(n.current,s,t),[n,s,t]),c=_.useMemo(()=>ye(s),[s]),i=_.useCallback(()=>e.current&&n.current&&t&&r(Ce(e.current,n.current,t,o)),[e,n,t,o]),f=_.useMemo(()=>({traceAction:a,getSelectionAccordingToActions:c,onResetTestCase:i,setEditorHtml:l}),[a,c,i,l]);return{testRef:n,utilities:f}}function we(e){return ue[e.key.key_type]||""}function be(e){switch(e.key.key_type){case 0:case 1:return"mention";case 2:return"command";case 3:return"custom";case 4:return"emoji";default:return"unknown"}}function Le(e){return e===null?e:{text:e.text,keyChar:we(e),type:be(e)}}const C=`
11
- `,ve=e=>{let t=e;return t.endsWith(C)&&(t=t.slice(0,-1)),t.replaceAll(/\\/g,"")};async function Ne(e,t){if(e.length===0)return"";await w();const n=y.new_composer_model();n.set_content_from_html(e);const s=t?n.get_content_as_message_markdown():n.get_content_as_markdown();return ve(s)}async function Ae(e,t){if(e.length===0)return"";await w();const n=Ie(e),s=y.new_composer_model();return s.set_content_from_markdown(n),t?s.get_content_as_message_html():s.get_content_as_html()}function Ie(e){const{body:t}=new DOMParser().parseFromString(e,"text/html"),n=document.createNodeIterator(t,void 0,Re);let s=n.nextNode(),r="";for(;s!==null;){const o=s.nodeName==="#text",u=s.nodeName==="A",l=s.nodeName==="DIV"&&s.childNodes.length===1&&s.firstChild?.nodeName==="BR",a=!Oe.includes(s.nodeName);if(l)r+=C;else if(o){let c=s.textContent;X(s)&&(c+=C),r+=c}else if(u){let c=s.firstChild?.parentElement?.outerHTML??"";X(s)&&(c+=C),r+=c}else a&&console.debug(`Converting unexpected node type ${s.nodeName}`);s=n.nextNode()}return r.endsWith(C.repeat(2))&&(r=r.slice(0,-1)),r}const Oe=["#text","BR","A","DIV","BODY"];function X(e){return(e.nextSibling||e.parentElement?.nextSibling)?.nodeName==="DIV"}function Re(e){return e.nodeName==="#text"&&e.parentElement?.hasAttribute("data-mention-type")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}function Be(e,t=!1){_.useEffect(()=>{if(t){const n=setTimeout(()=>e.current?.focus(),200);return()=>clearTimeout(n)}},[e,t])}function De(){const e=_.useRef(null);return _.useEffect(()=>{e.current?.childElementCount||e.current?.appendChild(document.createElement("br"))},[e]),e}function z(e){const t=e?.keys();return t?Array.from(t):[]}function $e(e){const t=De(),n=_.useRef(null),[s,r]=_.useState(z(e?.emojiSuggestions));_.useEffect(()=>{r(z(e?.emojiSuggestions))},[e?.emojiSuggestions]);const{composerModel:o,onError:u}=he(t,e?.initialContent,s),{testRef:l,utilities:a}=xe(t,o),c=ge(t,o),{content:i,actionStates:f,areListenersReady:m,suggestion:d}=pe(t,n,o,a,c,u,e?.inputEventProcessor,e?.emojiSuggestions);Be(t,e?.isAutoFocusEnabled);const h=_.useMemo(()=>Le(d),[d]);return{ref:t,isWysiwygReady:m,wysiwyg:c,content:i,actionStates:f,debug:{modelRef:n,testRef:l,resetTestCase:a.onResetTestCase,traceAction:a.traceAction},suggestion:h,messageContent:o?.get_content_as_message_html()??null}}g.initOnce=w,g.plainToRich=Ae,g.richToPlain=Ne,g.useWysiwyg=$e,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("@vector-im/matrix-wysiwyg-wasm")):typeof define==`function`&&define.amd?define([`exports`,`react`,`@vector-im/matrix-wysiwyg-wasm`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`Matrix wysiwyg`]={},e.React,e._vector_im_matrix_wysiwyg_wasm))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function r(e){return`inputType`in e}function i(e){return`clipboardData`in e}function a(e){return r(e)&&e.inputType===`insertSuggestion`}function o(e){return r(e)&&e.inputType===`insertAtRoomSuggestion`}function s(e){return r(e)&&e.inputType==`insertLink`}function c(e,t,n,r){return r?r(e,t,n):e}function l(e,t,r,l,u,d,f,p){let m=c(e,{actions:l,content:()=>t.get_content_as_html(),messageContent:()=>t.get_content_as_message_html()},u,f);if(!m)return;if(i(m)){let e=m.clipboardData,i=e?.getData(`text/html`),a=e?.getData(`text/plain`)??``;if(i&&i!==a){let a=e?.types.includes(`application/x-vnd.google-docs-document-slice-clip+wrapped`)?n.HtmlSource.GoogleDoc:n.HtmlSource.UnknownExternal;return r(t.replace_html(i,a),`replace_html_paste`)}return r(t.replace_text(a),`replace_text_paste`)}switch(m.inputType){case`insertAtRoomSuggestion`:if(d&&o(m)){let{attributes:e}=m.data;return e.has(`data-mention-type`)&&e.delete(`data-mention-type`),r(t.insert_at_room_mention_at_suggestion(d,e),`insert_at_room_mention_at_suggestion`)}break;case`insertSuggestion`:if(d&&a(m)){let{text:e,url:n,attributes:i}=m.data;return i.has(`data-mention-type`)&&i.delete(`data-mention-type`),r(t.insert_mention_at_suggestion(n,e,d,i),`insert_mention_at_suggestion`)}break;case`insertCommand`:case`insertEmoji`:if(d&&m.data){let e=m.inputType===`insertCommand`;return r(t.replace_text_suggestion(m.data,d,e),`replace_text_suggestion`)}break;case`clear`:return r(t.clear(),`clear`);case`deleteContentBackward`:return r(t.backspace(),`backspace`);case`deleteWordBackward`:return r(t.backspace_word(),`backspace_word`);case`deleteSoftLineBackward`:{let e=document.getSelection();return e&&(e.modify(`extend`,`backward`,`lineboundary`),document.dispatchEvent(new CustomEvent(`selectionchange`))),r(t.delete(),`backspace_line`)}case`deleteContentForward`:return r(t.delete(),`delete`);case`deleteWordForward`:return r(t.delete_word(),`delete_word`);case`deleteByCut`:return r(t.delete(),`delete`);case`formatBold`:return r(t.bold(),`bold`);case`formatItalic`:return r(t.italic(),`italic`);case`formatStrikeThrough`:return r(t.strike_through(),`strike_through`);case`formatUnderline`:return r(t.underline(),`underline`);case`formatInlineCode`:return r(t.inline_code(),`inline_code`);case`historyRedo`:return r(t.redo(),`redo`);case`historyUndo`:return r(t.undo(),`undo`);case`insertCodeBlock`:return r(t.code_block(),`code_block`);case`insertQuote`:return r(t.quote(),`quote`);case`insertFromPaste`:return;case`insertOrderedList`:return r(t.ordered_list(),`ordered_list`);case`insertLineBreak`:case`insertParagraph`:return h(t,d,p),r(t.enter(),`enter`);case`insertReplacementText`:{let e=u.innerHTML.slice(0,u.innerHTML.length-4);return r(t.set_content_from_html(e),`set_content_from_html`,e)}case`insertCompositionText`:case`insertFromComposition`:case`insertText`:if(m.data)return m.data==` `&&h(t,d,p),r(t.replace_text(m.data),`replace_text`,m.data);break;case`insertUnorderedList`:return r(t.unordered_list(),`unordered_list`);case`insertLink`:if(s(m)){let{text:e,url:n}=m.data;return r(e?t.set_link_with_text(n,e,new Map):t.set_link(n,new Map),`insertLink`)}break;case`removeLinks`:return r(t.remove_links(),`remove_links`);case`formatIndent`:return r(t.indent(),`indent`);case`formatOutdent`:return r(t.unindent(),`unindent`);case`sendMessage`:return null;default:return console.error(`Unknown input type: ${m.inputType}`),console.error(e),null}function h(e,t,n){if(n&&t&&t.key.key_type==3&&t.key.custom_key_value){let r=n.get(t.key.custom_key_value);r&&e.replace_text_suggestion(r,t,!1)}}}function u(e,t){e.innerHTML=``;let n=t.document(),r=0;function i(e,t,n,r){let i=document.createElement(t);if(n&&(i.innerText=n.replace(`​`,`~`)),r)for(let[e,t]of r.entries()){let n=document.createAttribute(e);t!==null&&(n.value=t),i.setAttributeNode(n)}return e.appendChild(i),i}function a(e,n){let o=i(n,`ul`);o.className=`group_${r%10}`;let s=e.children(t),c;for(;c=s.next_child();){let e=c.node_type(t);if(e===`container`){let e=`dom_${r}`;r++;let n=i(o,`li`);i(n,`input`,null,new Map([[`type`,`checkbox`],[`id`,e],[`checked`,null]])),i(n,`label`,c.tag(t),new Map([[`for`,e]])),a(c,n)}else if(e===`line_break`)i(o,`li`,`br`);else if(e===`text`){let e=i(o,`li`);i(e,`span`,`"`,new Map([[`class`,`quote`]])),i(e,`span`,`${c.text(t)}`),i(e,`span`,`"`,new Map([[`class`,`quote`]]))}else if(e===`mention`){let e=i(o,`li`);i(e,`span`,`"Mention - `,new Map([[`class`,`quote`]])),i(e,`span`,`${c.text(t)}`),i(e,`span`,`"`,new Map([[`class`,`quote`]]))}else console.error(`Unknown node type: ${e}`)}}a(n,e)}function d(e,t,n){let r=document.createRange(),i=p(e,t),a=p(e,n);if(i.node&&a.node){let e=i.node.compareDocumentPosition(a.node)&Node.DOCUMENT_POSITION_PRECEDING,t=i.node===a.node&&a.offset<i.offset;if((e||t)&&([i,a]=[a,i],!i.node||!a.node))throw Error();r.setStart(i.node,i.offset),r.setEnd(a.node,a.offset)}else r.selectNodeContents(e),r.collapse();let o=document.getSelection();o&&(o.removeAllRanges(),o.addRange(r))}function f(e,t,n,r){e.innerHTML=t+`<br />`,d(e,n,r)}function p(e,t,n){let r=e.nodeName===`LI`&&!e.hasChildNodes(),i=e.nodeType===Node.TEXT_NODE;if(i&&e.parentElement?.hasAttribute(`data-mention-type`)){let n=+!!v(e),r=t-n;return r<=1?r===0?e.previousSibling?{node:e.previousSibling,offset:h(e.previousSibling,1/0)}:{node:e.parentNode?.parentNode??null,offset:0}:{node:null,offset:0}:{node:null,offset:t-n-1}}else if(i){let n=+!!v(e);return w(e)?t===0?{node:e,offset:t}:{node:null,offset:t-n}:t<=(e.textContent?.length||0)?{node:e,offset:t}:{node:null,offset:t-(e.textContent?.length||0)-n}}else if(r)return t<=(e.textContent?.length||0)?{node:e,offset:t}:{node:null,offset:t-(e.textContent?.length||0)};else if(e.nodeName===`BR`)return t===0?{node:e,offset:0}:{node:null,offset:t-1};else{if(C(e)&&t===0)return{node:e,offset:t};for(let r of e.childNodes){let i=p(r,t,n||e);if(i.node)return{node:i.node,offset:i.offset};t=i.offset}return{node:null,offset:t}}}function m(e,t){let n=e.childNodes.length===1&&e.firstChild?.nodeName===`BR`;return!t||n?[0,0]:[t.anchorNode&&_(e,t.anchorNode,t.anchorOffset)||0,t.focusNode&&_(e,t.focusNode,t.focusOffset)||0]}function h(e,t){if(e.nodeType===Node.TEXT_NODE){let t=+!!v(e);return(e.textContent?.length??0)+t}else if(e.nodeName===`BR`)return t===0?0:1;else{let n=0,r=0;for(let i of e.childNodes){if(r===t)break;n+=h(i,-1),r++}return n}}function g(e,t,n){let r=e.nodeType===Node.TEXT_NODE,i=e.parentElement?.hasAttribute(`data-mention-type`);if(e===t)return r?n>(e.textContent?.length??0)?{found:!1,offset:0}:i?{found:!0,offset:n===0?0:1}:{found:!0,offset:n}:{found:!0,offset:h(e,n)};if(r){let t=+!!v(e);return w(e)?{found:!1,offset:t}:i?{found:!1,offset:1+t}:{found:!1,offset:(e.textContent?.length??0)+t}}else if(e.nodeName===`BR`)return{found:!1,offset:1};else{let r=0;for(let i of e.childNodes){let e=g(i,t,n);if(e.found)return{found:!0,offset:r+e.offset};r+=e.offset}return{found:!1,offset:r}}}function _(e,t,n){if(t===e&&n===e.childNodes.length-1)return h(e,-1)-1;let r=new Range;r.setStart(e,0),r.setEnd(e,e.childNodes.length);let i=r.comparePoint(t,0);if(i===-1)return 0;if(i===1)return h(e,-1)-1;let a=g(e,t,n);return a.found?a.offset:-1}function v(e){if(e===null)return!1;let t=e,n=x(t.parentNode);for(;t;){let e=t.nextSibling;if(e&&x(e)||n&&e&&!S(e)||e&&e.nodeName===`BR`)break;if(S(t))return!0;t=t.parentNode}return!1}var y=[`EM`,`U`,`STRONG`,`DEL`,`CODE`,`A`],b=[`OL`,`UL`,`LI`,`PRE`,`BLOCKQUOTE`,`P`];function x(e){return e===null?!1:y.includes(e.nodeName||``)}function S(e){return b.includes(e.nodeName||``)}function C(e){return y.includes(e.nodeName)&&e.textContent?.length===0}function w(e){let t=e.parentNode?.childNodes.length===1,n=e.parentNode?.nodeName===`P`,r=e.textContent===`\xA0`;return n&&t&&r}var T=[`bold`,`italic`,`strikeThrough`,`underline`,`undo`,`redo`,`orderedList`,`unorderedList`,`inlineCode`,`clear`,`link`,`codeBlock`,`quote`,`indent`,`unindent`],ee=[`@`,`#`,`/`,``,`:`];function E(){return T.reduce((e,t)=>(e[t]=`enabled`,e),{})}function D(e){let t={};for(let[n,r]of e)t[n.substring(0,1).toLowerCase()+n.substring(1)]=r.toLowerCase();return t}function O(){let e=navigator.userAgent.toLowerCase();return e.includes(`iphone`)||e.includes(`ipad`)?`iOS`:e.includes(`android`)?`Android`:e.includes(`win`)?`Windows`:e.includes(`mac`)?`macOS`:e.includes(`linux`)?`Linux`:null}function k(e,t,n,r){n?.preventDefault(),n?.stopPropagation(),e.dispatchEvent(new CustomEvent(`wysiwygInput`,{detail:{blockType:t,data:r}}))}function A(e,t,n,r,i){if(e.shiftKey&&e.altKey)switch(e.key){case`5`:return`formatStrikeThrough`}let a=O();if((a===`Windows`||a===`Linux`)&&e.ctrlKey)switch(e.key){case`Backspace`:return`deleteWordBackward`}if(e.ctrlKey||e.metaKey)switch(e.key){case`b`:return`formatBold`;case`i`:return`formatItalic`;case`u`:return`formatUnderline`;case`e`:return`formatInlineCode`;case`y`:return`historyRedo`;case`z`:return`historyUndo`;case`Z`:return`historyRedo`;case`Enter`:return`sendMessage`;case`Backspace`:return`deleteSoftLineBackward`}return c(e,{actions:n,content:()=>t.get_content_as_html(),messageContent:()=>t.get_content_as_message_html()},r,i),null}function te(e,t,n,r,i){let a=A(e,n,r,t,i);a&&k(t,a,e)}function j(e){return D(e.action_states)}function ne(e,t,n,r,i,a,o,s,c){let d=l(e,n,i.traceAction,a,t,o,s,c);if(d){let e=d.text_update().replace_all;e&&(f(t,e.replacement_html,e.start_utf16_codeunit,e.end_utf16_codeunit),i.setEditorHtml(e.replacement_html)),t.focus(),r&&u(r,n);let a=d.menu_state().update(),o=d.menu_action().suggestion()?.suggestion_pattern,s=a?j(a):null,c=o||null;return{content:e?.replacement_html,actionStates:s,suggestion:c}}}function M(e,t,{traceAction:n,getSelectionAccordingToActions:r}){let[i,a]=m(e,document.getSelection()),o=t.selection_start(),s=t.selection_end(),[c,l]=r();if(i===o&&i===c&&a===s&&a===l||i===s&&i===l&&a===o&&a===c)return;let u=t.select(i,a);n(null,`select`,i,a);let d=u.menu_state().update();if(d)return j(d)}function N(e,n,a,o,s,c,l,u){let[d,f]=(0,t.useState)({content:null,actionStates:E(),suggestion:null}),p=(0,t.useRef)(void 0),[m,h]=(0,t.useState)(!1);return(0,t.useEffect)(()=>{a&&(f({content:a.get_content_as_html(),actionStates:D(a.action_states()),suggestion:null}),p.current=a.get_content_as_plain_text())},[a]),(0,t.useEffect)(()=>{let t=e.current;if(!a||!t)return;let m=e=>{try{let r=ne(e,t,a,n.current,o,s,d.suggestion,l,u);r&&(f(e=>({content:r.content===void 0?e.content:r.content,actionStates:r.actionStates||e.actionStates,suggestion:r.suggestion})),p.current=a.get_content_as_plain_text())}catch{c(p.current)}},g=e=>{r(e)&&!e.isComposing&&m(e)};t.addEventListener(`input`,g);let _=e=>{let t=r(e)&&e.inputType===`insertFromPaste`&&e.dataTransfer!==null;(i(e)||t)&&(e.preventDefault(),e.stopPropagation(),m(e))};t.addEventListener(`paste`,_);let v=(e=>{m({inputType:e.detail.blockType,data:e.detail.data})});t.addEventListener(`wysiwygInput`,v);let y=e=>{te(e,t,a,s,l)};t.addEventListener(`keydown`,y);let b=()=>{try{let e=M(t,a,o);e&&f(({content:t,suggestion:n})=>({content:t,actionStates:e,suggestion:n})),p.current=a.get_content_as_plain_text()}catch{c(p.current)}};document.addEventListener(`selectionchange`,b);let x=e=>{if(!(r(e)&&e.isComposing))return _(e)};t.addEventListener(`beforeinput`,x);let S=e=>{g(new InputEvent(`input`,{data:e.data,inputType:`insertCompositionText`}))};return t.addEventListener(`compositionend`,S),h(!0),()=>{h(!1),t.removeEventListener(`input`,g),t.removeEventListener(`paste`,_),t.removeEventListener(`wysiwygInput`,v),t.removeEventListener(`keydown`,y),t.removeEventListener(`beforeinput`,x),t.removeEventListener(`compositionend`,S),document.removeEventListener(`selectionchange`,b)}},[e,u,a,s,n,o,l,c,p,d.suggestion]),{areListenersReady:m,...d}}function P(e,n){return(0,t.useMemo)(()=>{let t=(t,n)=>{e.current&&k(e.current,t,void 0,n)};return{bold:()=>t(`formatBold`),italic:()=>t(`formatItalic`),strikeThrough:()=>t(`formatStrikeThrough`),underline:()=>t(`formatUnderline`),undo:()=>t(`historyUndo`),redo:()=>t(`historyRedo`),orderedList:()=>t(`insertOrderedList`),unorderedList:()=>t(`insertUnorderedList`),inlineCode:()=>t(`formatInlineCode`),clear:()=>t(`clear`),insertText:e=>t(`insertText`,e),link:(e,n)=>t(`insertLink`,{url:e,text:n}),removeLinks:()=>t(`removeLinks`),getLink:()=>n?.get_link_action()?.edit_link?.url||``,codeBlock:()=>t(`insertCodeBlock`),quote:()=>t(`insertQuote`),indent:()=>t(`formatIndent`),unindent:()=>t(`formatOutdent`),mention:(e,n,r)=>t(`insertSuggestion`,{url:e,text:n,attributes:r}),command:e=>t(`insertCommand`,e),emoji:e=>t(`insertEmoji`,e),mentionAtRoom:e=>t(`insertAtRoomSuggestion`,{attributes:e})}},[e,n])}var F=null;async function I(){return F||=(0,n.initAsync)(),F}function L(e,r,i){let[a,o]=(0,t.useState)(null),s=(0,t.useCallback)(async t=>{await I();let r;if(t)try{let i=(0,n.new_composer_model_from_html)(t,0,t.length);if(r=i,e.current){let t=i.get_content_as_html();f(e.current,t,0,t.length)}}catch{r=(0,n.new_composer_model)()}else r=(0,n.new_composer_model)();o(r)},[o,e]);return(0,t.useEffect)(()=>{a&&i&&a.set_custom_suggestion_patterns(i)},[a,i]),(0,t.useEffect)(()=>{e.current&&s(r)},[e,s,r]),{composerModel:a,onError:s}}function R(e){return e[0]===`select`}function z(e,t,n){return(r,i,a,o)=>!e||!n?r:(console.debug(o===void 0?a===void 0?`composer_model.${i}()`:`composer_model.${i}(${a})`:`composer_model.${i}(${a}, ${o})`),t.push([i,a,o]),V(e,n,r,t),r)}function B(e){return()=>{for(let t=e.length-1;t>=0;t--){let n=e[t];if(R(n))return[n[1],n[2]]}return[-1,-1]}}function V(e,t,n,r){n&&n.text_update(),e.innerText=H(r,t.to_example_format()),e.scrollTo(0,e.scrollHeight-e.clientHeight)}function H(e,t){let n=``;function r(e,t,r){e===`select`?n+=`model.select(Location::from(${t}), Location::from(${r}));\n`:r===void 0?e===`replace_text`?n+=`model.${e}("${t??``}");\n`:e===`send`?n+=`// Send: ${t??``}\n`:n+=`model.${e}(${t??``});\n`:n+=`model.${e}(${t??``}, ${r});\n`}function i(){let e=U(s,c[0],c[1]);n+=`let mut model = cm("${e}");\n`}let a=null,o=!0,s=``,c=[0,0];for(let t of e){let[e,l,u]=t;if(o)e===`replace_text`?s+=G(l):R(t)?c=[t[1],t[2]]:(o=!1,i(),r(e,l,u));else if(a===`select`&&e===`select`){let t=n.lastIndexOf(`
2
+ `,n.length-2);t>-1&&(n=n.substring(0,t)+`
3
+ `,r(e,l,u))}else r(e,l,u);a=e}return o&&i(),n+=`assert_eq!(tx(&model), "${t}");\n`,n}function U(e,t,r){let i=(0,n.new_composer_model_from_html)(e,-1,-1);return i.select(t,r),i.to_example_format()}function W(e,t,n,r){let[i,a]=m(e,document.getSelection()),o=[[`replace_text`,r],[`select`,i,a]];return V(t,n,null,o),o}function G(e){if(!e)return``;let t=document.createElement(`p`);return t.appendChild(document.createTextNode(e.toString())),t.innerHTML}function K(e,n){let r=(0,t.useRef)(null),[i,a]=(0,t.useState)([]),[o,s]=(0,t.useState)(``),c=(0,t.useCallback)(e=>{r.current&&s(e)},[r]),l=(0,t.useMemo)(()=>z(r.current,i,n),[r,i,n]),u=(0,t.useMemo)(()=>B(i),[i]),d=(0,t.useCallback)(()=>e.current&&r.current&&n&&a(W(e.current,r.current,n,o)),[e,r,n,o]);return{testRef:r,utilities:(0,t.useMemo)(()=>({traceAction:l,getSelectionAccordingToActions:u,onResetTestCase:d,setEditorHtml:c}),[l,u,d,c])}}function q(e){return ee[e.key.key_type]||``}function J(e){switch(e.key.key_type){case 0:case 1:return`mention`;case 2:return`command`;case 3:return`custom`;case 4:return`emoji`;default:return`unknown`}}function Y(e){return e===null?e:{text:e.text,keyChar:q(e),type:J(e)}}var X=`
4
+ `,re=e=>{let t=e;return t.endsWith(X)&&(t=t.slice(0,-1)),t.replaceAll(/\\/g,``)};async function ie(e,t){if(e.length===0)return``;await I();let r=(0,n.new_composer_model)();return r.set_content_from_html(e),re(t?r.get_content_as_message_markdown():r.get_content_as_markdown())}async function ae(e,t){if(e.length===0)return``;await I();let r=oe(e),i=(0,n.new_composer_model)();return i.set_content_from_markdown(r),t?i.get_content_as_message_html():i.get_content_as_html()}function oe(e){let{body:t}=new DOMParser().parseFromString(e,`text/html`),n=document.createNodeIterator(t,void 0,Q),r=n.nextNode(),i=``;for(;r!==null;){let e=r.nodeName===`#text`,t=r.nodeName===`A`,a=r.nodeName===`DIV`&&r.childNodes.length===1&&r.firstChild?.nodeName===`BR`,o=!se.includes(r.nodeName);if(a)i+=X;else if(e){let e=r.textContent;Z(r)&&(e+=X),i+=e}else if(t){let e=r.firstChild?.parentElement?.outerHTML??``;Z(r)&&(e+=X),i+=e}else o&&console.debug(`Converting unexpected node type ${r.nodeName}`);r=n.nextNode()}return i.endsWith(X.repeat(2))&&(i=i.slice(0,-1)),i}var se=[`#text`,`BR`,`A`,`DIV`,`BODY`];function Z(e){return(e.nextSibling||e.parentElement?.nextSibling)?.nodeName===`DIV`}function Q(e){return e.nodeName===`#text`&&e.parentElement?.hasAttribute(`data-mention-type`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}function ce(e,n=!1){(0,t.useEffect)(()=>{if(n){let t=setTimeout(()=>e.current?.focus(),200);return()=>clearTimeout(t)}},[e,n])}function le(){let e=(0,t.useRef)(null);return(0,t.useEffect)(()=>{e.current?.childElementCount||e.current?.appendChild(document.createElement(`br`))},[e]),e}function $(e){let t=e?.keys();return t?Array.from(t):[]}function ue(e){let n=le(),r=(0,t.useRef)(null),[i,a]=(0,t.useState)($(e?.emojiSuggestions));(0,t.useEffect)(()=>{a($(e?.emojiSuggestions))},[e?.emojiSuggestions]);let{composerModel:o,onError:s}=L(n,e?.initialContent,i),{testRef:c,utilities:l}=K(n,o),u=P(n,o),{content:d,actionStates:f,areListenersReady:p,suggestion:m}=N(n,r,o,l,u,s,e?.inputEventProcessor,e?.emojiSuggestions);ce(n,e?.isAutoFocusEnabled);let h=(0,t.useMemo)(()=>Y(m),[m]);return{ref:n,isWysiwygReady:p,wysiwyg:u,content:d,actionStates:f,debug:{modelRef:r,testRef:c,resetTestCase:l.onResetTestCase,traceAction:l.traceAction},suggestion:h,messageContent:o?.get_content_as_message_html()??null}}e.initOnce=I,e.plainToRich=ae,e.richToPlain=ie,e.useWysiwyg=ue});
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vector-im/matrix-wysiwyg-wasm",
3
- "version": "2.40.0",
3
+ "version": "2.42.0",
4
4
  "homepage": "https://gitlab.com/andybalaam/wysiwyg-rust",
5
5
  "description": "WASM bindings for wysiwyg-rust",
6
6
  "license": "SEE LICENSE IN README.md",
@@ -52,11 +52,11 @@
52
52
  "devDependencies": {
53
53
  "@babel/cli": "^7.23.5",
54
54
  "@babel/plugin-transform-modules-commonjs": "^7.25.9",
55
- "@types/node": "^22.10.2",
56
- "jest": "^29.0.0",
55
+ "@types/node": "^24.0.0",
56
+ "jest": "^30.0.0",
57
57
  "typedoc": "^0.28.0",
58
- "typescript": "^5.7.2",
59
- "wasm-pack": "^0.13.1"
58
+ "typescript": "^6.0.0",
59
+ "wasm-pack": "^0.15.0"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">= 10"
@@ -69,5 +69,6 @@
69
69
  "lint": "tsc --noEmit",
70
70
  "test": "jest --verbose",
71
71
  "doc": "typedoc --tsconfig ."
72
- }
72
+ },
73
+ "packageManager": "yarn@4.16.0"
73
74
  }
@@ -54,73 +54,73 @@ export enum PatternKeyType {
54
54
  export class ComposerModel {
55
55
  private constructor();
56
56
  free(): void;
57
- static new(): ComposerModel;
58
- static from_example_format(text: string): ComposerModel;
59
- to_example_format(): string;
60
- get_content_as_html(): string;
61
- get_content_as_message_html(): string;
62
- get_content_as_markdown(): string;
63
- get_content_as_message_markdown(): string;
64
- get_content_as_plain_text(): string;
65
- document(): DomHandle;
57
+ code_block(): ComposerUpdate;
58
+ delete_word(): ComposerUpdate;
59
+ inline_code(): ComposerUpdate;
60
+ ordered_list(): ComposerUpdate;
61
+ remove_links(): ComposerUpdate;
62
+ replace_html(new_html: string, external_source: HtmlSource): ComposerUpdate;
63
+ replace_text(new_text: string): ComposerUpdate;
66
64
  action_states(): Map<any, any>;
67
- select(start_utf16_codeunit: number, end_utf16_codeunit: number): ComposerUpdate;
68
- selection_start(): number;
69
65
  selection_end(): number;
70
- replace_text(new_text: string): ComposerUpdate;
71
- replace_html(new_html: string, external_source: HtmlSource): ComposerUpdate;
72
- replace_text_suggestion(new_text: string, suggestion: SuggestionPattern, append_space: boolean): ComposerUpdate;
73
- set_content_from_html(text: string): ComposerUpdate;
74
- set_content_from_markdown(text: string): ComposerUpdate;
75
- clear(): ComposerUpdate;
76
- enter(): ComposerUpdate;
77
- backspace(): ComposerUpdate;
78
66
  backspace_word(): ComposerUpdate;
79
- delete(): ComposerUpdate;
80
- delete_word(): ComposerUpdate;
81
- bold(): ComposerUpdate;
82
- italic(): ComposerUpdate;
67
+ /**
68
+ * Creates a mention node and inserts it into the composer at the current selection
69
+ */
70
+ insert_mention(url: string, text: string, attributes: Map<any, any>): ComposerUpdate;
83
71
  strike_through(): ComposerUpdate;
84
- underline(): ComposerUpdate;
85
- quote(): ComposerUpdate;
86
- inline_code(): ComposerUpdate;
87
- code_block(): ComposerUpdate;
88
- undo(): ComposerUpdate;
89
- redo(): ComposerUpdate;
90
- ordered_list(): ComposerUpdate;
91
72
  unordered_list(): ComposerUpdate;
92
- indent(): ComposerUpdate;
93
- unindent(): ComposerUpdate;
94
73
  get_link_action(): LinkAction;
95
- set_link(url: string, attributes: Map<any, any>): ComposerUpdate;
74
+ selection_start(): number;
75
+ to_example_format(): string;
96
76
  set_link_with_text(url: string, text: string, attributes: Map<any, any>): ComposerUpdate;
97
- set_custom_suggestion_patterns(custom_suggestion_patterns: Array<any>): void;
77
+ static from_example_format(text: string): ComposerModel;
78
+ get_content_as_html(): string;
79
+ set_content_from_html(text: string): ComposerUpdate;
98
80
  /**
99
81
  * Creates an at-room mention node and inserts it into the composer at the current selection
100
82
  */
101
83
  insert_at_room_mention(attributes: Map<any, any>): ComposerUpdate;
84
+ get_content_as_markdown(): string;
85
+ replace_text_suggestion(new_text: string, suggestion: SuggestionPattern, append_space: boolean): ComposerUpdate;
86
+ get_content_as_plain_text(): string;
87
+ set_content_from_markdown(text: string): ComposerUpdate;
88
+ get_content_as_message_html(): string;
102
89
  /**
103
- * Creates a mention node and inserts it into the composer at the current selection
90
+ * Creates a mention node and inserts it into the composer, replacing the
91
+ * text content defined by the suggestion
104
92
  */
105
- insert_mention(url: string, text: string, attributes: Map<any, any>): ComposerUpdate;
93
+ insert_mention_at_suggestion(url: string, text: string, suggestion: SuggestionPattern, attributes: Map<any, any>): ComposerUpdate;
94
+ set_custom_suggestion_patterns(custom_suggestion_patterns: Array<any>): void;
95
+ get_content_as_message_markdown(): string;
106
96
  /**
107
97
  * Creates an at-room mention node and inserts it into the composer, replacing the
108
98
  * text content defined by the suggestion
109
99
  */
110
100
  insert_at_room_mention_at_suggestion(suggestion: SuggestionPattern, attributes: Map<any, any>): ComposerUpdate;
111
- /**
112
- * Creates a mention node and inserts it into the composer, replacing the
113
- * text content defined by the suggestion
114
- */
115
- insert_mention_at_suggestion(url: string, text: string, suggestion: SuggestionPattern, attributes: Map<any, any>): ComposerUpdate;
116
- remove_links(): ComposerUpdate;
101
+ static new(): ComposerModel;
102
+ bold(): ComposerUpdate;
103
+ redo(): ComposerUpdate;
104
+ undo(): ComposerUpdate;
105
+ clear(): ComposerUpdate;
106
+ enter(): ComposerUpdate;
107
+ quote(): ComposerUpdate;
108
+ delete(): ComposerUpdate;
109
+ indent(): ComposerUpdate;
110
+ italic(): ComposerUpdate;
111
+ select(start_utf16_codeunit: number, end_utf16_codeunit: number): ComposerUpdate;
112
+ document(): DomHandle;
113
+ set_link(url: string, attributes: Map<any, any>): ComposerUpdate;
114
+ unindent(): ComposerUpdate;
115
+ backspace(): ComposerUpdate;
116
+ underline(): ComposerUpdate;
117
117
  }
118
118
  export class ComposerUpdate {
119
119
  private constructor();
120
120
  free(): void;
121
- text_update(): TextUpdate;
122
121
  menu_state(): MenuState;
123
122
  menu_action(): MenuAction;
123
+ text_update(): TextUpdate;
124
124
  }
125
125
  export class Create {
126
126
  private constructor();
@@ -150,36 +150,36 @@ export class DomHandle {
150
150
  private constructor();
151
151
  free(): void;
152
152
  /**
153
- * Returns "container", "line_break", "text" or "zwsp" depending on the type of
154
- * node we refer to.
153
+ * Returns our tagname, or "-text-"/"-zwsp-" if we are a text/zwsp node.
155
154
  * Panics if we are not a valid reference (because the model has changed
156
155
  * since we were created, or because you passed in a different model
157
156
  * from the one that created us.)
158
157
  */
159
- node_type(model: ComposerModel): string;
158
+ tag(model: ComposerModel): string;
160
159
  /**
161
- * Returns a list of our children nodes, or an empty list if we refer
162
- * to a text or line break node.
160
+ * Returns the text of this node, or an empty string if this is a
161
+ * container or line break.
163
162
  * Panics if we are not a valid reference (because the model has changed
164
163
  * since we were created, or because you passed in a different model
165
164
  * from the one that created us.)
166
165
  */
167
- children(model: ComposerModel): DomChildren;
166
+ text(model: ComposerModel): string;
168
167
  /**
169
- * Returns the text of this node, or an empty string if this is a
170
- * container or line break.
168
+ * Returns a list of our children nodes, or an empty list if we refer
169
+ * to a text or line break node.
171
170
  * Panics if we are not a valid reference (because the model has changed
172
171
  * since we were created, or because you passed in a different model
173
172
  * from the one that created us.)
174
173
  */
175
- text(model: ComposerModel): string;
174
+ children(model: ComposerModel): DomChildren;
176
175
  /**
177
- * Returns our tagname, or "-text-"/"-zwsp-" if we are a text/zwsp node.
176
+ * Returns "container", "line_break", "text" or "zwsp" depending on the type of
177
+ * node we refer to.
178
178
  * Panics if we are not a valid reference (because the model has changed
179
179
  * since we were created, or because you passed in a different model
180
180
  * from the one that created us.)
181
181
  */
182
- tag(model: ComposerModel): string;
182
+ node_type(model: ComposerModel): string;
183
183
  }
184
184
  export class Edit {
185
185
  private constructor();
@@ -205,9 +205,9 @@ export class LinkAction {
205
205
  export class MenuAction {
206
206
  private constructor();
207
207
  free(): void;
208
+ suggestion(): MenuActionSuggestion | undefined;
208
209
  keep(): boolean;
209
210
  none(): boolean;
210
- suggestion(): MenuActionSuggestion | undefined;
211
211
  }
212
212
  export class MenuActionSuggestion {
213
213
  private constructor();