@vector-im/matrix-wysiwyg 2.38.5 → 2.40.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.
- package/dist/index.d.ts +3 -2
- package/dist/matrix-wysiwyg.js +484 -485
- package/dist/matrix-wysiwyg.umd.cjs +11 -11
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/package.json +2 -2
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg.d.ts +7 -0
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.cjs +50 -9
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.js +40 -7
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm +0 -0
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm.d.ts +3 -2
- package/package.json +13 -13
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(function(p,_){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"],_):(p=typeof globalThis<"u"?globalThis:p||self,_(p["Matrix wysiwyg"]={},p.React,p.matrixWysiwygWasm))})(this,function(p,_,k){"use strict";function C(e){return"inputType"in e}function O(e){return"clipboardData"in e}function M(e){return C(e)&&e.inputType==="insertSuggestion"}function ee(e){return C(e)&&e.inputType==="insertAtRoomSuggestion"}function te(e){return C(e)&&e.inputType=="insertLink"}function y(e,t,n,s){return s?s(e,t,n):e}function ne(e,t,n,s,r,i,l,m){var c;const o=y(e,{actions:s,content:()=>t.get_content_as_html(),messageContent:()=>t.get_content_as_message_html()},r,l);if(!o)return;if(O(o)){const a=((c=o.clipboardData)==null?void 0:c.getData("text/plain"))??"";return n(t.replace_text(a),"paste")}switch(o.inputType){case"insertAtRoomSuggestion":{if(i&&ee(o)){const{attributes:a}=o.data;return a.has("data-mention-type")&&a.delete("data-mention-type"),n(t.insert_at_room_mention_at_suggestion(i,a),"insert_at_room_mention_at_suggestion")}break}case"insertSuggestion":{if(i&&M(o)){const{text:a,url:d,attributes:f}=o.data;return f.has("data-mention-type")&&f.delete("data-mention-type"),n(t.insert_mention_at_suggestion(d,a,i,f),"insert_mention_at_suggestion")}break}case"insertCommand":{if(i&&o.data)return n(t.replace_text_suggestion(o.data,i,!0),"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 a=document.getSelection();return a&&(a.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 u(t,i,m),n(t.enter(),"enter");case"insertReplacementText":{const a=r.innerHTML.slice(0,r.innerHTML.length-4);return n(t.set_content_from_html(a),"set_content_from_html",a)}case"insertCompositionText":case"insertFromComposition":case"insertText":if(o.data)return o.data==" "&&u(t,i,m),n(t.replace_text(o.data),"replace_text",o.data);break;case"insertUnorderedList":return n(t.unordered_list(),"unordered_list");case"insertLink":if(te(o)){const{text:a,url:d}=o.data;return n(a?t.set_link_with_text(d,a,new Map):t.set_link(d,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: ${o.inputType}`),console.error(e),null}function u(a,d,f){if(f&&d&&d.key.key_type==3&&d.key.custom_key_value){const g=f.get(d.key.custom_key_value);g&&a.replace_text_suggestion(g,d,!1)}}}function se(e,t){e.innerHTML="";const n=t.document();let s=0;function r(l,m,o,u){const c=document.createElement(m);if(o&&(c.innerText=o.replace("","~")),u)for(const[a,d]of u.entries()){const f=document.createAttribute(a);d!==null&&(f.value=d),c.setAttributeNode(f)}return l.appendChild(c),c}function i(l,m){const o=r(m,"ul");o.className=`group_${s%10}`;const u=l.children(t);let c;for(;c=u.next_child();){const a=c.node_type(t);if(a==="container"){const f=`dom_${s}`;s++;const g=r(o,"li");r(g,"input",null,new Map([["type","checkbox"],["id",f],["checked",null]])),r(g,"label",c.tag(t),new Map([["for",f]])),i(c,g)}else if(a==="line_break")r(o,"li","br");else if(a==="text"){const d=r(o,"li");r(d,"span",'"',new Map([["class","quote"]])),r(d,"span",`${c.text(t)}`),r(d,"span",'"',new Map([["class","quote"]]))}else if(a==="mention"){const d=r(o,"li");r(d,"span",'"Mention - ',new Map([["class","quote"]])),r(d,"span",`${c.text(t)}`),r(d,"span",'"',new Map([["class","quote"]]))}else console.error(`Unknown node type: ${a}`)}}i(n,e)}function re(e,t,n){const s=document.createRange();let r=A(e,t),i=A(e,n);if(r.node&&i.node){const m=r.node.compareDocumentPosition(i.node)&Node.DOCUMENT_POSITION_PRECEDING,o=r.node===i.node&&i.offset<r.offset;if((m||o)&&([r,i]=[i,r],!r.node||!i.node))throw new Error;s.setStart(r.node,r.offset),s.setEnd(i.node,i.offset)}else s.selectNodeContents(e),s.collapse();const l=document.getSelection();l&&(l.removeAllRanges(),l.addRange(s))}function R(e,t,n,s){e.innerHTML=t+"<br />",re(e,n,s)}function A(e,t,n){var l,m,o,u,c,a;const s=e.nodeName==="LI"&&!e.hasChildNodes(),r=e.nodeType===Node.TEXT_NODE;if(r&&((l=e.parentElement)==null?void 0:l.hasAttribute("data-mention-type"))){const f=b(e)?1:0,g=t-f;return g<=1?g===0?e.previousSibling?{node:e.previousSibling,offset:T(e.previousSibling,1/0)}:{node:((m=e.parentNode)==null?void 0:m.parentNode)??null,offset:0}:{node:null,offset:0}:{node:null,offset:t-f-1}}else if(r){const f=b(e)?1:0;return F(e)?t===0?{node:e,offset:t}:{node:null,offset:t-f}:t<=(((o=e.textContent)==null?void 0:o.length)||0)?{node:e,offset:t}:{node:null,offset:t-(((u=e.textContent)==null?void 0:u.length)||0)-f}}else{if(s)return t<=(((c=e.textContent)==null?void 0:c.length)||0)?{node:e,offset:t}:{node:null,offset:t-(((a=e.textContent)==null?void 0:a.length)||0)};if(e.nodeName==="BR")return t===0?{node:e,offset:0}:{node:null,offset:t-1};if(oe(e)&&t===0)return{node:e,offset:t};for(const d of e.childNodes){const f=A(d,t);if(f.node)return{node:f.node,offset:f.offset};t=f.offset}return{node:null,offset:t}}}function B(e,t){var i;const n=e.childNodes.length===1&&((i=e.firstChild)==null?void 0:i.nodeName)==="BR";if(!t||n)return[0,0];const s=t.anchorNode&&$(e,t.anchorNode,t.anchorOffset)||0,r=t.focusNode&&$(e,t.focusNode,t.focusOffset)||0;return[s,r]}function T(e,t){var n;if(e.nodeType===Node.TEXT_NODE){const r=b(e)?1:0;return(((n=e.textContent)==null?void 0:n.length)??0)+r}else{if(e.nodeName==="BR")return t===0?0:1;{let s=0,r=0;for(const i of e.childNodes){if(r===t)break;s+=T(i,-1),r++}return s}}}function D(e,t,n){var i,l,m;const s=e.nodeType===Node.TEXT_NODE,r=(i=e.parentElement)==null?void 0:i.hasAttribute("data-mention-type");if(e===t)return s?n>(((l=e.textContent)==null?void 0:l.length)??0)?{found:!1,offset:0}:r?{found:!0,offset:n===0?0:1}:{found:!0,offset:n}:{found:!0,offset:T(e,n)};if(s){const u=b(e)?1:0;return F(e)?{found:!1,offset:u}:r?{found:!1,offset:1+u}:{found:!1,offset:(((m=e.textContent)==null?void 0:m.length)??0)+u}}else{if(e.nodeName==="BR")return{found:!1,offset:1};{let o=0;for(const u of e.childNodes){const c=D(u,t,n);if(c.found)return{found:!0,offset:o+c.offset};o+=c.offset}return{found:!1,offset:o}}}}function $(e,t,n){if(t===e&&n===e.childNodes.length-1)return T(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 T(e,-1)-1;const i=D(e,t,n);return i.found?i.offset:-1}function b(e){if(e===null)return!1;let t=e;const n=U(t.parentNode);for(;t;){const s=t.nextSibling;if(s&&U(s)||n&&s&&!H(s)||s&&s.nodeName==="BR")break;if(H(t))return!0;t=t.parentNode}return!1}const w=["EM","U","STRONG","DEL","CODE","A"],ie=["OL","UL","LI","PRE","BLOCKQUOTE","P"];function U(e){return e===null?!1:w.includes(e.nodeName||"")}function H(e){return ie.includes(e.nodeName||"")}function oe(e){var t;return w.includes(e.nodeName)&&((t=e.textContent)==null?void 0:t.length)===0}function F(e){var r,i;const t=((r=e.parentNode)==null?void 0:r.childNodes.length)===1,n=((i=e.parentNode)==null?void 0:i.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 q(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 K(e,t,n,s){n==null||n.preventDefault(),n==null||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 i=le();if((i==="Windows"||i==="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 y(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 i=fe(e,n,s,t,r);i&&K(t,i,e)}function G(e){return q(e.action_states)}function me(e,t,n,s,r,i,l,m,o){var c;const u=ne(e,n,r.traceAction,i,t,l,m,o);if(u){const a=u.text_update().replace_all;a&&(R(t,a.replacement_html,a.start_utf16_codeunit,a.end_utf16_codeunit),r.setEditorHtml(a.replacement_html)),t.focus(),s&&se(s,n);const d=u.menu_state().update(),f=(c=u.menu_action().suggestion())==null?void 0:c.suggestion_pattern,g=d?G(d):null,S=f||null;return{content:a==null?void 0:a.replacement_html,actionStates:g,suggestion:S}}}function _e(e,t,{traceAction:n,getSelectionAccordingToActions:s}){const[r,i]=B(e,document.getSelection()),l=t.selection_start(),m=t.selection_end(),[o,u]=s();if(r===l&&r===o&&i===m&&i===u||r===m&&r===u&&i===l&&i===o)return;const c=t.select(r,i);n(null,"select",r,i);const a=c.menu_state().update();if(a)return G(a)}function he(e,t,n,s,r,i,l,m){const[o,u]=_.useState({content:null,actionStates:ce(),suggestion:null}),c=_.useRef(void 0),[a,d]=_.useState(!1);return _.useEffect(()=>{n&&(u({content:n.get_content_as_html(),actionStates:q(n.action_states()),suggestion:null}),c.current=n.get_content_as_plain_text())},[n]),_.useEffect(()=>{const f=e.current;if(!n||!f)return;const g=h=>{try{const E=me(h,f,n,t.current,s,r,o.suggestion,l,m);E&&(u(L=>{const Ue=E.content!==void 0?E.content:L.content,He=E.actionStates||L.actionStates,Fe=E.suggestion;return{content:Ue,actionStates:He,suggestion:Fe}}),c.current=n.get_content_as_plain_text())}catch{i(c.current)}},S=h=>{C(h)&&!h.isComposing&&g(h)};f.addEventListener("input",S);const N=h=>{const E=C(h)&&h.inputType==="insertFromPaste"&&h.dataTransfer!==null;(O(h)||E)&&(h.preventDefault(),h.stopPropagation(),g(h))};f.addEventListener("paste",N);const W=h=>{g({inputType:h.detail.blockType,data:h.detail.data})};f.addEventListener("wysiwygInput",W);const Y=h=>{de(h,f,n,r,l)};f.addEventListener("keydown",Y);const J=()=>{try{const h=_e(f,n,s);h&&u(({content:E,suggestion:L})=>({content:E,actionStates:h,suggestion:L})),c.current=n.get_content_as_plain_text()}catch{i(c.current)}};document.addEventListener("selectionchange",J);const Z=h=>{if(!(C(h)&&h.isComposing))return N(h)};f.addEventListener("beforeinput",Z);const P=h=>{const E=new InputEvent("input",{data:h.data,inputType:"insertCompositionText"});S(E)};return f.addEventListener("compositionend",P),d(!0),()=>{d(!1),f.removeEventListener("input",S),f.removeEventListener("paste",N),f.removeEventListener("wysiwygInput",W),f.removeEventListener("keydown",Y),f.removeEventListener("beforeinput",Z),f.removeEventListener("compositionend",P),document.removeEventListener("selectionchange",J)}},[e,m,n,r,t,s,l,i,c,o.suggestion]),{areListenersReady:a,...o}}function ge(e,t){return _.useMemo(()=>{const s=(r,i)=>{e.current&&K(e.current,r,void 0,i)};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,i)=>s("insertLink",{url:r,text:i}),removeLinks:()=>s("removeLinks"),getLink:()=>{var r,i;return((i=(r=t==null?void 0:t.get_link_action())==null?void 0:r.edit_link)==null?void 0:i.url)||""},codeBlock:()=>s("insertCodeBlock"),quote:()=>s("insertQuote"),indent:()=>s("formatIndent"),unindent:()=>s("formatOutdent"),mention:(r,i,l)=>s("insertSuggestion",{url:r,text:i,attributes:l}),command:r=>s("insertCommand",r),mentionAtRoom:r=>s("insertAtRoomSuggestion",{attributes:r})}},[e,t])}let j=!1,I=!1;async function v(){if(I)return Promise.resolve();if(j)return new Promise(e=>{function t(){I&&e(),setTimeout(t,200)}t()});j=!0,await k.initAsync(),I=!0}function pe(e,t,n){const[s,r]=_.useState(null),i=_.useCallback(async l=>{await v();let m;if(l)try{const o=k.new_composer_model_from_html(l,0,l.length);if(m=o,e.current){const u=o.get_content_as_html();R(e.current,u,0,u.length)}}catch{m=k.new_composer_model()}else m=k.new_composer_model();r(m)},[r,e]);return _.useEffect(()=>{s&&n&&s.set_custom_suggestion_patterns(n)},[s,n]),_.useEffect(()=>{e.current&&i(t)},[e,i,t]),{composerModel:s,onError:i}}function V(e){return e[0]==="select"}function Ee(e,t,n){return(s,r,i,l)=>(!e||!n||(console.debug(l!==void 0?`composer_model.${r}(${i}, ${l})`:i!==void 0?`composer_model.${r}(${i})`:`composer_model.${r}()`),t.push([r,i,l]),X(e,n,s,t)),s)}function ke(e){return()=>{for(let t=e.length-1;t>=0;t--){const n=e[t];if(V(n))return[n[1],n[2]]}return[-1,-1]}}function X(e,t,n,s){n&&n.text_update(),e.innerText=Ce(s,t.to_example_format()),e.scrollTo(0,e.scrollHeight-e.clientHeight)}function Ce(e,t){let n="";function s(u,c,a){u==="select"?n+=`model.select(Location::from(${c}), Location::from(${a}));
|
|
2
|
-
`:
|
|
3
|
-
`:
|
|
4
|
-
`:
|
|
5
|
-
`:n+=`model.${
|
|
6
|
-
`}function r(){const
|
|
7
|
-
`}let
|
|
8
|
-
`,n.length-2);
|
|
9
|
-
`,s(
|
|
10
|
-
`,n}function
|
|
11
|
-
`,
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vector-im/matrix-wysiwyg-wasm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.40.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",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@babel/plugin-transform-modules-commonjs": "^7.25.9",
|
|
55
55
|
"@types/node": "^22.10.2",
|
|
56
56
|
"jest": "^29.0.0",
|
|
57
|
-
"typedoc": "^0.
|
|
57
|
+
"typedoc": "^0.28.0",
|
|
58
58
|
"typescript": "^5.7.2",
|
|
59
59
|
"wasm-pack": "^0.13.1"
|
|
60
60
|
},
|
|
@@ -39,11 +39,17 @@ export enum DomCreationError {
|
|
|
39
39
|
HtmlParseError = 0,
|
|
40
40
|
MarkdownParseError = 1,
|
|
41
41
|
}
|
|
42
|
+
export enum HtmlSource {
|
|
43
|
+
Matrix = 0,
|
|
44
|
+
GoogleDoc = 1,
|
|
45
|
+
UnknownExternal = 2,
|
|
46
|
+
}
|
|
42
47
|
export enum PatternKeyType {
|
|
43
48
|
At = 0,
|
|
44
49
|
Hash = 1,
|
|
45
50
|
Slash = 2,
|
|
46
51
|
Custom = 3,
|
|
52
|
+
Colon = 4,
|
|
47
53
|
}
|
|
48
54
|
export class ComposerModel {
|
|
49
55
|
private constructor();
|
|
@@ -62,6 +68,7 @@ export class ComposerModel {
|
|
|
62
68
|
selection_start(): number;
|
|
63
69
|
selection_end(): number;
|
|
64
70
|
replace_text(new_text: string): ComposerUpdate;
|
|
71
|
+
replace_html(new_html: string, external_source: HtmlSource): ComposerUpdate;
|
|
65
72
|
replace_text_suggestion(new_text: string, suggestion: SuggestionPattern, append_space: boolean): ComposerUpdate;
|
|
66
73
|
set_content_from_html(text: string): ComposerUpdate;
|
|
67
74
|
set_content_from_markdown(text: string): ComposerUpdate;
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.TextUpdate = exports.SuggestionPattern = exports.Selection = exports.ReplaceAll = exports.PatternKeyType = exports.PatternKey = exports.MenuStateUpdate = exports.MenuState = exports.MenuActionSuggestion = exports.MenuAction = exports.LinkAction = exports.Keep = exports.Edit = exports.DomHandle = exports.DomCreationError = exports.DomChildren = exports.Disabled = exports.CreateWithText = exports.Create = exports.ComposerUpdate = exports.ComposerModel = exports.ComposerAction = exports.ActionState = void 0;
|
|
6
|
+
exports.TextUpdate = exports.SuggestionPattern = exports.Selection = exports.ReplaceAll = exports.PatternKeyType = exports.PatternKey = exports.MenuStateUpdate = exports.MenuState = exports.MenuActionSuggestion = exports.MenuAction = exports.LinkAction = exports.Keep = exports.HtmlSource = exports.Edit = exports.DomHandle = exports.DomCreationError = exports.DomChildren = exports.Disabled = exports.CreateWithText = exports.Create = exports.ComposerUpdate = exports.ComposerModel = exports.ComposerAction = exports.ActionState = void 0;
|
|
7
7
|
exports.__wbg_body_942ea927546a04ba = __wbg_body_942ea927546a04ba;
|
|
8
8
|
exports.__wbg_childNodes_c4423003f3a9441f = __wbg_childNodes_c4423003f3a9441f;
|
|
9
9
|
exports.__wbg_error_7534b8e9a36f1ab4 = __wbg_error_7534b8e9a36f1ab4;
|
|
10
10
|
exports.__wbg_forEach_d6a05ca96422eff9 = __wbg_forEach_d6a05ca96422eff9;
|
|
11
11
|
exports.__wbg_forEach_e1cf6f7c8ecb7dae = __wbg_forEach_e1cf6f7c8ecb7dae;
|
|
12
12
|
exports.__wbg_getAttribute_ea5166be2deba45e = __wbg_getAttribute_ea5166be2deba45e;
|
|
13
|
+
exports.__wbg_getPropertyValue_e623c23a05dfb30c = __wbg_getPropertyValue_e623c23a05dfb30c;
|
|
13
14
|
exports.__wbg_get_e27dfaeb6f46bd45 = __wbg_get_e27dfaeb6f46bd45;
|
|
14
15
|
exports.__wbg_hasAttribute_db31090c2e646f57 = __wbg_hasAttribute_db31090c2e646f57;
|
|
15
16
|
exports.__wbg_length_49b2ba67f0897e97 = __wbg_length_49b2ba67f0897e97;
|
|
@@ -23,6 +24,7 @@ exports.__wbg_parseFromString_91cbec9ba27a222a = __wbg_parseFromString_91cbec9ba
|
|
|
23
24
|
exports.__wbg_set_8fc6bf8a5b1071d1 = __wbg_set_8fc6bf8a5b1071d1;
|
|
24
25
|
exports.__wbg_set_wasm = __wbg_set_wasm;
|
|
25
26
|
exports.__wbg_stack_0ed75d68575b0f3c = __wbg_stack_0ed75d68575b0f3c;
|
|
27
|
+
exports.__wbg_style_fb30c14e5815805c = __wbg_style_fb30c14e5815805c;
|
|
26
28
|
exports.__wbindgen_init_externref_table = __wbindgen_init_externref_table;
|
|
27
29
|
exports.__wbindgen_number_new = __wbindgen_number_new;
|
|
28
30
|
exports.__wbindgen_string_get = __wbindgen_string_get;
|
|
@@ -152,11 +154,11 @@ function takeFromExternrefTable0(idx) {
|
|
|
152
154
|
wasm.__externref_table_dealloc(idx);
|
|
153
155
|
return value;
|
|
154
156
|
}
|
|
155
|
-
function
|
|
156
|
-
wasm.
|
|
157
|
+
function __wbg_adapter_124(arg0, arg1, arg2, arg3, arg4) {
|
|
158
|
+
wasm.closure102_externref_shim(arg0, arg1, arg2, arg3, arg4);
|
|
157
159
|
}
|
|
158
|
-
function
|
|
159
|
-
wasm.
|
|
160
|
+
function __wbg_adapter_127(arg0, arg1, arg2, arg3) {
|
|
161
|
+
wasm.closure105_externref_shim(arg0, arg1, arg2, arg3);
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
/**
|
|
@@ -224,7 +226,18 @@ const DomCreationError = exports.DomCreationError = Object.freeze({
|
|
|
224
226
|
"1": "MarkdownParseError"
|
|
225
227
|
});
|
|
226
228
|
/**
|
|
227
|
-
* @enum {0 | 1 | 2
|
|
229
|
+
* @enum {0 | 1 | 2}
|
|
230
|
+
*/
|
|
231
|
+
const HtmlSource = exports.HtmlSource = Object.freeze({
|
|
232
|
+
Matrix: 0,
|
|
233
|
+
"0": "Matrix",
|
|
234
|
+
GoogleDoc: 1,
|
|
235
|
+
"1": "GoogleDoc",
|
|
236
|
+
UnknownExternal: 2,
|
|
237
|
+
"2": "UnknownExternal"
|
|
238
|
+
});
|
|
239
|
+
/**
|
|
240
|
+
* @enum {0 | 1 | 2 | 3 | 4}
|
|
228
241
|
*/
|
|
229
242
|
const PatternKeyType = exports.PatternKeyType = Object.freeze({
|
|
230
243
|
At: 0,
|
|
@@ -234,7 +247,9 @@ const PatternKeyType = exports.PatternKeyType = Object.freeze({
|
|
|
234
247
|
Slash: 2,
|
|
235
248
|
"2": "Slash",
|
|
236
249
|
Custom: 3,
|
|
237
|
-
"3": "Custom"
|
|
250
|
+
"3": "Custom",
|
|
251
|
+
Colon: 4,
|
|
252
|
+
"4": "Colon"
|
|
238
253
|
});
|
|
239
254
|
const __wbindgen_enum_SupportedType = ["text/html", "text/xml", "application/xml", "application/xhtml+xml", "image/svg+xml"];
|
|
240
255
|
const ComposerModelFinalization = typeof FinalizationRegistry === 'undefined' ? {
|
|
@@ -413,6 +428,17 @@ class ComposerModel {
|
|
|
413
428
|
const ret = wasm.composermodel_replace_text(this.__wbg_ptr, ptr0, len0);
|
|
414
429
|
return ComposerUpdate.__wrap(ret);
|
|
415
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* @param {string} new_html
|
|
433
|
+
* @param {HtmlSource} external_source
|
|
434
|
+
* @returns {ComposerUpdate}
|
|
435
|
+
*/
|
|
436
|
+
replace_html(new_html, external_source) {
|
|
437
|
+
const ptr0 = passStringToWasm0(new_html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
438
|
+
const len0 = WASM_VECTOR_LEN;
|
|
439
|
+
const ret = wasm.composermodel_replace_html(this.__wbg_ptr, ptr0, len0, external_source);
|
|
440
|
+
return ComposerUpdate.__wrap(ret);
|
|
441
|
+
}
|
|
416
442
|
/**
|
|
417
443
|
* @param {string} new_text
|
|
418
444
|
* @param {SuggestionPattern} suggestion
|
|
@@ -1648,7 +1674,7 @@ function __wbg_forEach_d6a05ca96422eff9(arg0, arg1, arg2) {
|
|
|
1648
1674
|
const a = state0.a;
|
|
1649
1675
|
state0.a = 0;
|
|
1650
1676
|
try {
|
|
1651
|
-
return
|
|
1677
|
+
return __wbg_adapter_124(a, state0.b, arg0, arg1, arg2);
|
|
1652
1678
|
} finally {
|
|
1653
1679
|
state0.a = a;
|
|
1654
1680
|
}
|
|
@@ -1669,7 +1695,7 @@ function __wbg_forEach_e1cf6f7c8ecb7dae(arg0, arg1, arg2) {
|
|
|
1669
1695
|
const a = state0.a;
|
|
1670
1696
|
state0.a = 0;
|
|
1671
1697
|
try {
|
|
1672
|
-
return
|
|
1698
|
+
return __wbg_adapter_127(a, state0.b, arg0, arg1);
|
|
1673
1699
|
} finally {
|
|
1674
1700
|
state0.a = a;
|
|
1675
1701
|
}
|
|
@@ -1688,6 +1714,16 @@ function __wbg_getAttribute_ea5166be2deba45e(arg0, arg1, arg2, arg3) {
|
|
|
1688
1714
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1689
1715
|
}
|
|
1690
1716
|
;
|
|
1717
|
+
function __wbg_getPropertyValue_e623c23a05dfb30c() {
|
|
1718
|
+
return handleError(function (arg0, arg1, arg2, arg3) {
|
|
1719
|
+
const ret = arg1.getPropertyValue(getStringFromWasm0(arg2, arg3));
|
|
1720
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1721
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1722
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1723
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1724
|
+
}, arguments);
|
|
1725
|
+
}
|
|
1726
|
+
;
|
|
1691
1727
|
function __wbg_get_e27dfaeb6f46bd45(arg0, arg1) {
|
|
1692
1728
|
const ret = arg0[arg1 >>> 0];
|
|
1693
1729
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
@@ -1761,6 +1797,11 @@ function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
|
|
|
1761
1797
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1762
1798
|
}
|
|
1763
1799
|
;
|
|
1800
|
+
function __wbg_style_fb30c14e5815805c(arg0) {
|
|
1801
|
+
const ret = arg0.style;
|
|
1802
|
+
return ret;
|
|
1803
|
+
}
|
|
1804
|
+
;
|
|
1764
1805
|
function __wbindgen_init_externref_table() {
|
|
1765
1806
|
const table = wasm.__wbindgen_export_1;
|
|
1766
1807
|
const offset = table.grow(4);
|
|
@@ -146,12 +146,12 @@ function takeFromExternrefTable0(idx) {
|
|
|
146
146
|
wasm.__externref_table_dealloc(idx);
|
|
147
147
|
return value;
|
|
148
148
|
}
|
|
149
|
-
function
|
|
150
|
-
wasm.
|
|
149
|
+
function __wbg_adapter_124(arg0, arg1, arg2, arg3, arg4) {
|
|
150
|
+
wasm.closure102_externref_shim(arg0, arg1, arg2, arg3, arg4);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
function
|
|
154
|
-
wasm.
|
|
153
|
+
function __wbg_adapter_127(arg0, arg1, arg2, arg3) {
|
|
154
|
+
wasm.closure105_externref_shim(arg0, arg1, arg2, arg3);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
/**
|
|
@@ -200,13 +200,22 @@ export const DomCreationError = Object.freeze({
|
|
|
200
200
|
MarkdownParseError: 1, "1": "MarkdownParseError",
|
|
201
201
|
});
|
|
202
202
|
/**
|
|
203
|
-
* @enum {0 | 1 | 2
|
|
203
|
+
* @enum {0 | 1 | 2}
|
|
204
|
+
*/
|
|
205
|
+
export const HtmlSource = Object.freeze({
|
|
206
|
+
Matrix: 0, "0": "Matrix",
|
|
207
|
+
GoogleDoc: 1, "1": "GoogleDoc",
|
|
208
|
+
UnknownExternal: 2, "2": "UnknownExternal",
|
|
209
|
+
});
|
|
210
|
+
/**
|
|
211
|
+
* @enum {0 | 1 | 2 | 3 | 4}
|
|
204
212
|
*/
|
|
205
213
|
export const PatternKeyType = Object.freeze({
|
|
206
214
|
At: 0, "0": "At",
|
|
207
215
|
Hash: 1, "1": "Hash",
|
|
208
216
|
Slash: 2, "2": "Slash",
|
|
209
217
|
Custom: 3, "3": "Custom",
|
|
218
|
+
Colon: 4, "4": "Colon",
|
|
210
219
|
});
|
|
211
220
|
|
|
212
221
|
const __wbindgen_enum_SupportedType = ["text/html", "text/xml", "application/xml", "application/xhtml+xml", "image/svg+xml"];
|
|
@@ -390,6 +399,17 @@ export class ComposerModel {
|
|
|
390
399
|
const ret = wasm.composermodel_replace_text(this.__wbg_ptr, ptr0, len0);
|
|
391
400
|
return ComposerUpdate.__wrap(ret);
|
|
392
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* @param {string} new_html
|
|
404
|
+
* @param {HtmlSource} external_source
|
|
405
|
+
* @returns {ComposerUpdate}
|
|
406
|
+
*/
|
|
407
|
+
replace_html(new_html, external_source) {
|
|
408
|
+
const ptr0 = passStringToWasm0(new_html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
409
|
+
const len0 = WASM_VECTOR_LEN;
|
|
410
|
+
const ret = wasm.composermodel_replace_html(this.__wbg_ptr, ptr0, len0, external_source);
|
|
411
|
+
return ComposerUpdate.__wrap(ret);
|
|
412
|
+
}
|
|
393
413
|
/**
|
|
394
414
|
* @param {string} new_text
|
|
395
415
|
* @param {SuggestionPattern} suggestion
|
|
@@ -1674,7 +1694,7 @@ export function __wbg_forEach_d6a05ca96422eff9(arg0, arg1, arg2) {
|
|
|
1674
1694
|
const a = state0.a;
|
|
1675
1695
|
state0.a = 0;
|
|
1676
1696
|
try {
|
|
1677
|
-
return
|
|
1697
|
+
return __wbg_adapter_124(a, state0.b, arg0, arg1, arg2);
|
|
1678
1698
|
} finally {
|
|
1679
1699
|
state0.a = a;
|
|
1680
1700
|
}
|
|
@@ -1692,7 +1712,7 @@ export function __wbg_forEach_e1cf6f7c8ecb7dae(arg0, arg1, arg2) {
|
|
|
1692
1712
|
const a = state0.a;
|
|
1693
1713
|
state0.a = 0;
|
|
1694
1714
|
try {
|
|
1695
|
-
return
|
|
1715
|
+
return __wbg_adapter_127(a, state0.b, arg0, arg1);
|
|
1696
1716
|
} finally {
|
|
1697
1717
|
state0.a = a;
|
|
1698
1718
|
}
|
|
@@ -1711,6 +1731,14 @@ export function __wbg_getAttribute_ea5166be2deba45e(arg0, arg1, arg2, arg3) {
|
|
|
1711
1731
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1712
1732
|
};
|
|
1713
1733
|
|
|
1734
|
+
export function __wbg_getPropertyValue_e623c23a05dfb30c() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
1735
|
+
const ret = arg1.getPropertyValue(getStringFromWasm0(arg2, arg3));
|
|
1736
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1737
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1738
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
1739
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1740
|
+
}, arguments) };
|
|
1741
|
+
|
|
1714
1742
|
export function __wbg_get_e27dfaeb6f46bd45(arg0, arg1) {
|
|
1715
1743
|
const ret = arg0[arg1 >>> 0];
|
|
1716
1744
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
@@ -1780,6 +1808,11 @@ export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
|
|
|
1780
1808
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
1781
1809
|
};
|
|
1782
1810
|
|
|
1811
|
+
export function __wbg_style_fb30c14e5815805c(arg0) {
|
|
1812
|
+
const ret = arg0.style;
|
|
1813
|
+
return ret;
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1783
1816
|
export function __wbindgen_init_externref_table() {
|
|
1784
1817
|
const table = wasm.__wbindgen_export_1;
|
|
1785
1818
|
const offset = table.grow(4);
|
|
Binary file
|
|
@@ -18,6 +18,7 @@ export const composermodel_select: (a: number, b: number, c: number) => number;
|
|
|
18
18
|
export const composermodel_selection_start: (a: number) => number;
|
|
19
19
|
export const composermodel_selection_end: (a: number) => number;
|
|
20
20
|
export const composermodel_replace_text: (a: number, b: number, c: number) => number;
|
|
21
|
+
export const composermodel_replace_html: (a: number, b: number, c: number, d: number) => number;
|
|
21
22
|
export const composermodel_replace_text_suggestion: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
22
23
|
export const composermodel_set_content_from_html: (a: number, b: number, c: number) => [number, number, number];
|
|
23
24
|
export const composermodel_set_content_from_markdown: (a: number, b: number, c: number) => [number, number, number];
|
|
@@ -130,6 +131,6 @@ export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
|
130
131
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
131
132
|
export const __wbindgen_exn_store: (a: number) => void;
|
|
132
133
|
export const __externref_table_dealloc: (a: number) => void;
|
|
133
|
-
export const
|
|
134
|
-
export const
|
|
134
|
+
export const closure102_externref_shim: (a: number, b: number, c: any, d: number, e: any) => void;
|
|
135
|
+
export const closure105_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
135
136
|
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vector-im/matrix-wysiwyg",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.40.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Wysiwyg composer for Element Web using React",
|
|
6
6
|
"author": "New Vector Ltd.",
|
|
@@ -41,23 +41,23 @@
|
|
|
41
41
|
"react": "^18.2.0 || ^19.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@stylistic/eslint-plugin": "^
|
|
44
|
+
"@stylistic/eslint-plugin": "^5.0.0",
|
|
45
45
|
"@testing-library/dom": "^10.0.0",
|
|
46
46
|
"@testing-library/jest-dom": "^6.0.0",
|
|
47
47
|
"@testing-library/react": "^16.0.0",
|
|
48
48
|
"@testing-library/user-event": "^14.4.3",
|
|
49
|
-
"@types/jest": "^29.
|
|
49
|
+
"@types/jest": "^29.0.0",
|
|
50
50
|
"@types/react": "^19.0.0",
|
|
51
51
|
"@types/react-dom": "^19.0.0",
|
|
52
52
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
53
53
|
"@typescript-eslint/parser": "^8.0.0",
|
|
54
54
|
"@vitejs/plugin-react": "^4.2.1",
|
|
55
|
-
"@vitest/coverage-v8": "^
|
|
56
|
-
"@vitest/ui": "^
|
|
57
|
-
"cypress": "^
|
|
58
|
-
"eslint": "^
|
|
55
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
56
|
+
"@vitest/ui": "^3.0.0",
|
|
57
|
+
"cypress": "^14.0.0",
|
|
58
|
+
"eslint": "^9.20.0",
|
|
59
59
|
"eslint-config-google": "^0.14.0",
|
|
60
|
-
"eslint-config-prettier": "^
|
|
60
|
+
"eslint-config-prettier": "^10.0.0",
|
|
61
61
|
"eslint-plugin-deprecate": "^0.8.0",
|
|
62
62
|
"eslint-plugin-import": "^2.26.0",
|
|
63
63
|
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
@@ -65,15 +65,15 @@
|
|
|
65
65
|
"eslint-plugin-prettier": "^5.0.0",
|
|
66
66
|
"eslint-plugin-react": "^7.31.8",
|
|
67
67
|
"eslint-plugin-react-hooks": "^5.0.0",
|
|
68
|
-
"eslint-plugin-unicorn": "^
|
|
69
|
-
"jest-environment-jsdom": "^29.0.
|
|
70
|
-
"prettier": "3.
|
|
68
|
+
"eslint-plugin-unicorn": "^60.0.0",
|
|
69
|
+
"jest-environment-jsdom": "^29.0.0",
|
|
70
|
+
"prettier": "3.6.2",
|
|
71
71
|
"react": "^19.0.0",
|
|
72
72
|
"react-dom": "^19.0.0",
|
|
73
73
|
"typescript": "^5.0.0",
|
|
74
|
-
"vite": "
|
|
74
|
+
"vite": "7.0.6",
|
|
75
75
|
"vite-plugin-dts": "^4.3.0",
|
|
76
|
-
"vitest": "^
|
|
76
|
+
"vitest": "^3.0.0",
|
|
77
77
|
"vitest-sonar-reporter": "^2.0.0"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|