@vector-im/matrix-wysiwyg 2.39.0 → 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 +16 -10
- package/dist/matrix-wysiwyg.umd.cjs +3 -3
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/package.json +1 -1
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg.d.ts +1 -0
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.cjs +4 -2
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.js +2 -1
- package/node_modules/@vector-im/matrix-wysiwyg-wasm/pkg/wysiwyg_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare type FormattingFunctions = Record<Exclude<ActionTypes, 'link'>, (
|
|
|
19
19
|
mention: (url: string, text: string, attributes: AllowedMentionAttributes) => void;
|
|
20
20
|
mentionAtRoom: (attributes: AllowedMentionAttributes) => void;
|
|
21
21
|
command: (text: string) => void;
|
|
22
|
+
emoji: (text: string) => void;
|
|
22
23
|
removeLinks: () => void;
|
|
23
24
|
getLink: () => string;
|
|
24
25
|
};
|
|
@@ -50,9 +51,9 @@ export declare function richToPlain(richText: string, inMessageFormat: boolean):
|
|
|
50
51
|
|
|
51
52
|
export declare type SuggestionChar = (typeof SUGGESTIONS)[number] | '';
|
|
52
53
|
|
|
53
|
-
export declare const SUGGESTIONS: readonly ["@", "#", "/", ""];
|
|
54
|
+
export declare const SUGGESTIONS: readonly ["@", "#", "/", "", ":"];
|
|
54
55
|
|
|
55
|
-
export declare type SuggestionType = 'mention' | 'command' | 'custom' | 'unknown';
|
|
56
|
+
export declare type SuggestionType = 'mention' | 'command' | 'custom' | 'emoji' | 'unknown';
|
|
56
57
|
|
|
57
58
|
export declare type TraceAction = (update: ComposerUpdate | null, name: string, value1?: string | number, value2?: string | number) => ComposerUpdate | null;
|
|
58
59
|
|
package/dist/matrix-wysiwyg.js
CHANGED
|
@@ -76,16 +76,19 @@ function fe(e, t, n, s, r, i, c, l) {
|
|
|
76
76
|
}
|
|
77
77
|
break;
|
|
78
78
|
}
|
|
79
|
-
case "insertCommand":
|
|
80
|
-
|
|
79
|
+
case "insertCommand":
|
|
80
|
+
case "insertEmoji": {
|
|
81
|
+
if (i && a.data) {
|
|
82
|
+
const o = a.inputType === "insertCommand";
|
|
81
83
|
return n(
|
|
82
84
|
t.replace_text_suggestion(
|
|
83
85
|
a.data,
|
|
84
86
|
i,
|
|
85
|
-
|
|
87
|
+
o
|
|
86
88
|
),
|
|
87
89
|
"replace_text_suggestion"
|
|
88
90
|
);
|
|
91
|
+
}
|
|
89
92
|
break;
|
|
90
93
|
}
|
|
91
94
|
case "clear":
|
|
@@ -421,7 +424,7 @@ const pe = [
|
|
|
421
424
|
"quote",
|
|
422
425
|
"indent",
|
|
423
426
|
"unindent"
|
|
424
|
-
], he = ["@", "#", "/", ""];
|
|
427
|
+
], he = ["@", "#", "/", "", ":"];
|
|
425
428
|
function ye() {
|
|
426
429
|
return pe.reduce((e, t) => (e[t] = "enabled", e), {});
|
|
427
430
|
}
|
|
@@ -678,6 +681,7 @@ function we(e, t) {
|
|
|
678
681
|
unindent: () => s("formatOutdent"),
|
|
679
682
|
mention: (r, i, c) => s("insertSuggestion", { url: r, text: i, attributes: c }),
|
|
680
683
|
command: (r) => s("insertCommand", r),
|
|
684
|
+
emoji: (r) => s("insertEmoji", r),
|
|
681
685
|
mentionAtRoom: (r) => s("insertAtRoomSuggestion", { attributes: r })
|
|
682
686
|
};
|
|
683
687
|
}, [e, t]);
|
|
@@ -859,6 +863,8 @@ function De(e) {
|
|
|
859
863
|
return "command";
|
|
860
864
|
case 3:
|
|
861
865
|
return "custom";
|
|
866
|
+
case 4:
|
|
867
|
+
return "emoji";
|
|
862
868
|
default:
|
|
863
869
|
return "unknown";
|
|
864
870
|
}
|
|
@@ -907,17 +913,17 @@ function He(e) {
|
|
|
907
913
|
r += x;
|
|
908
914
|
else if (i) {
|
|
909
915
|
let u = s.textContent;
|
|
910
|
-
|
|
916
|
+
j(s) && (u += x), r += u;
|
|
911
917
|
} else if (c) {
|
|
912
918
|
let u = s.firstChild?.parentElement?.outerHTML ?? "";
|
|
913
|
-
|
|
919
|
+
j(s) && (u += x), r += u;
|
|
914
920
|
} else a && console.debug(`Converting unexpected node type ${s.nodeName}`);
|
|
915
921
|
s = n.nextNode();
|
|
916
922
|
}
|
|
917
923
|
return r.endsWith(x.repeat(2)) && (r = r.slice(0, -1)), r;
|
|
918
924
|
}
|
|
919
925
|
const Fe = ["#text", "BR", "A", "DIV", "BODY"];
|
|
920
|
-
function
|
|
926
|
+
function j(e) {
|
|
921
927
|
return (e.nextSibling || e.parentElement?.nextSibling)?.nodeName === "DIV";
|
|
922
928
|
}
|
|
923
929
|
function Pe(e) {
|
|
@@ -937,16 +943,16 @@ function We() {
|
|
|
937
943
|
e.current?.childElementCount || e.current?.appendChild(document.createElement("br"));
|
|
938
944
|
}, [e]), e;
|
|
939
945
|
}
|
|
940
|
-
function
|
|
946
|
+
function q(e) {
|
|
941
947
|
const t = e?.keys();
|
|
942
948
|
return t ? Array.from(t) : [];
|
|
943
949
|
}
|
|
944
950
|
function Xe(e) {
|
|
945
951
|
const t = We(), n = b(null), [s, r] = E(
|
|
946
|
-
|
|
952
|
+
q(e?.emojiSuggestions)
|
|
947
953
|
);
|
|
948
954
|
h(() => {
|
|
949
|
-
r(
|
|
955
|
+
r(q(e?.emojiSuggestions));
|
|
950
956
|
}, [e?.emojiSuggestions]);
|
|
951
957
|
const { composerModel: i, onError: c } = Le(
|
|
952
958
|
t,
|
|
@@ -1,4 +1,4 @@
|
|
|
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,_,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":{if(o&&a.data)return n(t.replace_text_suggestion(a.data,o,!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 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 q(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&&q(t,o,e)}function K(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?K(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 K(f)}function ge(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=g=>{try{const E=me(g,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=g=>{k(g)&&!g.isComposing&&h(g)};d.addEventListener("input",b);const N=g=>{const E=k(g)&&g.inputType==="insertFromPaste"&&g.dataTransfer!==null;(A(g)||E)&&(g.preventDefault(),g.stopPropagation(),h(g))};d.addEventListener("paste",N);const Q=g=>{h({inputType:g.detail.blockType,data:g.detail.data})};d.addEventListener("wysiwygInput",Q);const Y=g=>{de(g,d,n,r,u)};d.addEventListener("keydown",Y);const J=()=>{try{const g=_e(d,n,s);g&&c(({content:E,suggestion:T})=>({content:E,actionStates:g,suggestion:T})),i.current=n.get_content_as_plain_text()}catch{o(i.current)}};document.addEventListener("selectionchange",J);const Z=g=>{if(!(k(g)&&g.isComposing))return N(g)};d.addEventListener("beforeinput",Z);const W=g=>{const E=new InputEvent("input",{data:g.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 pe(e,t){return _.useMemo(()=>{const s=(r,o)=>{e.current&&q(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),mentionAtRoom:r=>s("insertAtRoomSuggestion",{attributes:r})}},[e,t])}let j=!1,v=!1;async function w(){if(v)return Promise.resolve();if(j)return new Promise(e=>{function t(){v&&e(),setTimeout(t,200)}t()});j=!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}));
|
|
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
2
|
`:f!==void 0?n+=`model.${c}(${i??""}, ${f});
|
|
3
3
|
`:c==="replace_text"?n+=`model.${c}("${i??""}");
|
|
4
4
|
`:c==="send"?n+=`// Send: ${i??""}
|
|
@@ -7,5 +7,5 @@
|
|
|
7
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
8
|
`,n.length-2);d>-1&&(n=n.substring(0,d)+`
|
|
9
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";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=
|
|
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"})});
|
|
@@ -237,7 +237,7 @@ const HtmlSource = exports.HtmlSource = Object.freeze({
|
|
|
237
237
|
"2": "UnknownExternal"
|
|
238
238
|
});
|
|
239
239
|
/**
|
|
240
|
-
* @enum {0 | 1 | 2 | 3}
|
|
240
|
+
* @enum {0 | 1 | 2 | 3 | 4}
|
|
241
241
|
*/
|
|
242
242
|
const PatternKeyType = exports.PatternKeyType = Object.freeze({
|
|
243
243
|
At: 0,
|
|
@@ -247,7 +247,9 @@ const PatternKeyType = exports.PatternKeyType = Object.freeze({
|
|
|
247
247
|
Slash: 2,
|
|
248
248
|
"2": "Slash",
|
|
249
249
|
Custom: 3,
|
|
250
|
-
"3": "Custom"
|
|
250
|
+
"3": "Custom",
|
|
251
|
+
Colon: 4,
|
|
252
|
+
"4": "Colon"
|
|
251
253
|
});
|
|
252
254
|
const __wbindgen_enum_SupportedType = ["text/html", "text/xml", "application/xml", "application/xhtml+xml", "image/svg+xml"];
|
|
253
255
|
const ComposerModelFinalization = typeof FinalizationRegistry === 'undefined' ? {
|
|
@@ -208,13 +208,14 @@ export const HtmlSource = Object.freeze({
|
|
|
208
208
|
UnknownExternal: 2, "2": "UnknownExternal",
|
|
209
209
|
});
|
|
210
210
|
/**
|
|
211
|
-
* @enum {0 | 1 | 2 | 3}
|
|
211
|
+
* @enum {0 | 1 | 2 | 3 | 4}
|
|
212
212
|
*/
|
|
213
213
|
export const PatternKeyType = Object.freeze({
|
|
214
214
|
At: 0, "0": "At",
|
|
215
215
|
Hash: 1, "1": "Hash",
|
|
216
216
|
Slash: 2, "2": "Slash",
|
|
217
217
|
Custom: 3, "3": "Custom",
|
|
218
|
+
Colon: 4, "4": "Colon",
|
|
218
219
|
});
|
|
219
220
|
|
|
220
221
|
const __wbindgen_enum_SupportedType = ["text/html", "text/xml", "application/xml", "application/xhtml+xml", "image/svg+xml"];
|
|
Binary file
|