Files
echo-nexus/node_modules/@lexical/rich-text/LexicalRichText.prod.mjs
T

10 lines
11 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import{$insertDataTransferForRichText as t,copyToClipboard as e}from"@lexical/clipboard";import{$isParentRTL as n,$shouldOverrideDefaultCharacterSelection as r,$moveCharacter as o}from"@lexical/selection";import{addClassNamesToElement as i,isHTMLElement as s,objectKlassEquals as a,mergeRegister as c,$findMatchingParent as u,$getNearestBlockElementAncestorOrThrow as l}from"@lexical/utils";import{createCommand as d,ElementNode as m,$createParagraphNode as f,$applyNodeReplacement as g,setNodeIndentFromDOM as p,CLICK_COMMAND as h,$getSelection as C,$isNodeSelection as v,COMMAND_PRIORITY_EDITOR as y,DELETE_CHARACTER_COMMAND as D,$isRangeSelection as x,DELETE_WORD_COMMAND as N,DELETE_LINE_COMMAND as w,CONTROLLED_TEXT_INSERTION_COMMAND as E,REMOVE_TEXT_COMMAND as O,FORMAT_TEXT_COMMAND as T,FORMAT_ELEMENT_COMMAND as _,$isElementNode as A,INSERT_LINE_BREAK_COMMAND as F,INSERT_PARAGRAPH_COMMAND as P,INSERT_TAB_COMMAND as S,$insertNodes as I,$createTabNode as M,INDENT_CONTENT_COMMAND as b,OUTDENT_CONTENT_COMMAND as K,KEY_ARROW_UP_COMMAND as k,$getAdjacentNode as J,$isDecoratorNode as L,KEY_ARROW_DOWN_COMMAND as R,KEY_ARROW_LEFT_COMMAND as W,KEY_ARROW_RIGHT_COMMAND as z,KEY_BACKSPACE_COMMAND as q,KEY_DELETE_COMMAND as X,KEY_ENTER_COMMAND as Y,KEY_ESCAPE_COMMAND as B,DROP_COMMAND as G,$getNearestNodeFromDOMNode as V,$createRangeSelection as j,$isTextNode as H,$normalizeSelection__EXPERIMENTAL as Q,$setSelection as U,DRAGSTART_COMMAND as Z,DRAGOVER_COMMAND as $,SELECT_ALL_COMMAND as tt,$selectAll as et,COPY_COMMAND as nt,CUT_COMMAND as rt,PASTE_COMMAND as ot,isDOMNode as it,isSelectionCapturedInDecoratorInput as st,KEY_SPACE_COMMAND as at,KEY_TAB_COMMAND as ct,PASTE_TAG as ut,$getRoot as lt,$isRootNode as dt}from"lexical";function mt(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const ft="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,gt=ft&&"documentMode"in document?document.documentMode:null,pt=!(!ft||!("InputEvent"in window)||gt)&&"getTargetRanges"in new window.InputEvent("input"),ht=ft&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),Ct=ft&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,vt=ft&&/^(?=.*Chrome).*/i.test(navigator.userAgent),yt=ft&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!vt,Dt=d("DRAG_DROP_PASTE_FILE");class xt extends m{static getType(){return"quote"}static clone(t){return new xt(t.__key)}createDOM(t){const e=document.createElement("blockquote");return i(e,t.theme.quote),e}updateDOM(t,e){return!1}static importDOM(){return{blockquote:t=>({conversion:_t,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(s(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();t&&(e.style.textAlign=t);const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){return Nt().updateFromJSON(t)}insertNewAfter(t,e){const n=f(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=f();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}canMergeWhenEmpty(){return!0}}function Nt(){return g(new xt)}function wt(t){return t instanceof xt}class Et extends m{static getType(){return"heading"}static clone(t){return new Et(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t}getTag(){return this.__tag}setTag(t){const e=this.getWritable();return this.__tag=t,e}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];i(n,t)}return n}updateDOM(t,e,n){return t.__tag!==this.__tag}static importDOM(){return{h1:t=>({conversion:Tt,priority:0}),h2:t=>({conversion:Tt,priority:0}),h3:t=>({conversion:Tt,priority:0}),h4:t=>({conversion:Tt,priority:0}),h5:t=>({conversion:Tt,priority:0}),h6:t=>({conversion:Tt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&Ot(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>Ot(t)?{conversion:t=>({node:At("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(s(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();t&&(e.style.textAlign=t);const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){return At(t.tag).updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setTag(t.tag)}exportJSON(){return{...super.exportJSON(),tag:this.getTag()}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=this.getLastDescendant(),o=!r||t&&t.anchor.key===r.getKey()&&n===r.getTextContentSize()||!t?f():At(this.getTag()),i=this.getDirection();if(o.setDirection(i),this.insertAfter(o,e),0===n&&!this.isEmpty()&&t){const t=f();t.select(),this.replace(t,!0)}return o}collapseAtStart(){const t=this.isEmpty()?f():At(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return!0}}function Ot(t){return"span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Tt(t){const e=t.nodeName.toLowerCase();let n=null;return"h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=At(e),null!==t.style&&(p(t,n),n.setFormat(t.style.textAlign))),{node:n}}function _t(t){const e=Nt();return null!==t.style&&(e.setFormat(t.style.textAlign),p(t,e)),{node:e}}function At(t="h1"){return g(new Et(t))}function Ft(t){return t instanceof Et}function Pt(t){let e=null;if(a(t,DragEvent)?e=t.dataTransfer:a(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(e.files),o]}function St(t){const e=C();if(!x(e))return!1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=u(o,(t=>A(t)&&!t.isInline()));if(null===s)continue;const a=s.getKey();s.canIndent()&&!n.has(a)&&(n.add(a),t(s))}return n.size>0}function It(t){const e=V(t);return L(e)}function Mt(t){for(const e of["lowercase","uppercase","capitalize"])t.hasFormat(e)&&t.toggleFormat(e)}function bt(i){return c(i.registerCommand(h,(t=>{const e=C();return!!v(e)&&(e.clear(),!0)}),y),i.registerCommand(D,(t=>{const e=C();return x(e)?(e.deleteCharacter(t),!0):!!v(e)&&(e.deleteNodes(),!0)}),y),i.registerCommand(N,(t=>{const e=C();return!!x(e)&&(e.deleteWord(t),!0)}),y),i.registerCommand(w,(t=>{const e=C();return!!x(e)&&(e.deleteLine(t),!0)}),y),i.registerCommand(E,(e=>{const n=C();if("string"==typeof e)null!==n&&n.insertText(e);else{if(null===n)return!1;const r=e.dataTransfer;if(null!=r)t(r,n,i);else if(x(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),i.registerCommand(O,(()=>{const t=C();return!!x(t)&&(t.removeText(),!0)}),y),i.registerCommand(T,(t=>{const e=C();return!!x(e)&&(e.formatText(t),!0)}),y),i.registerCommand(_,(t=>{const e=C();if(!x(e)&&!v(e))return!1;const n=e.getNodes();for(const e of n){const n=u(e,(t=>A(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),i.registerCommand(F,(t=>{const e=C();return!!x(e)&&(e.insertLineBreak(t),!0)}),y),i.registerCommand(P,(()=>{const t=C();return!!x(t)&&(t.insertParagraph(),!0)}),y),i.registerCommand(S,(()=>(I([M()]),!0)),y),i.registerCommand(b,(()=>St((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),i.registerCommand(K,(()=>St((t=>{const e=t.getIndent();e>0&&t.setIndent(Math.max(0,e-1))}))),y),i.registerCommand(k,(t=>{const e=C();if(v(e)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(x(e)){const n=J(e.focus,!0);if(!t.shiftKey&&L(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return!1}),y),i.registerCommand(R,(t=>{const e=C();if(v(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if(x(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===lt().getChildrenSize()}(e))return t.preventDefault(),!0;const n=J(e.focus,!1);if(!t.shiftKey&&L(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return!1}),y),i.registerCommand(W,(t=>{const e=C();if(v(e)){const r=e.getNodes();if(r.length>0)return t.preventDefault(),n(r[0])?r[0].selectNext(0,0):r[0].selectPrevious(),!0}if(!x(e))return!1;if(r(e,!0)){const n=t.shiftKey;return t.preventDefault(),o(e,n,!0),!0}return!1}),y),i.registerCommand(z,(t=>{const e=C();if(v(e)){const r=e.getNodes();if(r.length>0)return t.preventDefault(),n(r[0])?r[0].selectPrevious():r[0].selectNext(0,0),!0}if(!x(e))return!1;const i=t.shiftKey;return!!r(e,!1)&&(t.preventDefault(),o(e,i,!1),!0)}),y),i.registerCommand(q,(t=>{if(It(t.target))return!1;const e=C();if(x(e)){if(function(t){if(!t.isCollapsed())return!1;const{anchor:e}=t;if(0!==e.offset)return!1;const n=e.getNode();if(dt(n))return!1;const r=l(n);return r.getIndent()>0&&(r.is(n)||n.is(r.getFirstDescendant()))}(e))return t.preventDefault(),i.dispatchCommand(K,void 0);if(Ct&&"ko-KR"===navigator.language)return!1}else if(!v(e))return!1;return t.preventDefault(),i.dispatchCommand(D,!0)}),y),i.registerCommand(X,(t=>{if(It(t.target))return!1;const e=C();return!(!x(e)&&!v(e))&&(t.preventDefault(),i.dispatchCommand(D,!1))}),y),i.registerCommand(Y,(t=>{const e=C();if(!x(e))return!1;if(Mt(e),null!==t){if((Ct||ht||yt)&&pt)return!1;if(t.preventDefault(),t.shiftKey)return i.dispatchCommand(F,!1)}return i.dispatchCommand(P,void 0)}),y),i.registerCommand(B,(()=>{const t=C();return!!x(t)&&(i.blur(),!0)}),y),i.registerCommand(G,(t=>{const[,e]=Pt(t);if(e.length>0){const n=mt(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,o=V(r);if(null!==o){const e=j();if(H(o))e.anchor.set(o.getKey(),t,"text"),e.focus.set(o.getKey(),t,"text");else{const t=o.getParentOrThrow().getKey(),n=o.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element")}const n=Q(e);U(n)}i.dispatchCommand(Dt,e)}return t.preventDefault(),!0}const n=C();return!!x(n)}),y),i.registerCommand(Z,(t=>{const[e]=Pt(t),n=C();return!(e&&!x(n))}),y),i.registerCommand($,(t=>{const[e]=Pt(t),n=C();if(e&&!x(n))return!1;const r=mt(t.clientX,t.clientY);if(null!==r){const e=V(r.node);L(e)&&t.preventDefault()}return!0}),y),i.registerCommand(tt,(()=>(et(),!0)),y),i.registerCommand(nt,(t=>(e(i,a(t,ClipboardEvent)?t:null),!0)),y),i.registerCommand(rt,(t=>(async function(t,n){await e(n,a(t,ClipboardEvent)?t:null),n.update((()=>{const t=C();x(t)?t.removeText():v(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,i),!0)),y),i.registerCommand(ot,(e=>{const[,n,r]=Pt(e);if(n.length>0&&!r)return i.dispatchCommand(Dt,n),!0;if(it(e.target)&&st(e.target))return!1;return null!==C()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=C(),o=a(e,InputEvent)||a(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&t(o,r,n)}),{tag:ut})}(e,i),!0)}),y),i.registerCommand(at,(t=>{const e=C();return x(e)&&Mt(e),!1}),y),i.registerCommand(ct,(t=>{const e=C();return x(e)&&Mt(e),!1}),y))}export{At as $createHeadingNode,Nt as $createQuoteNode,Ft as $isHeadingNode,wt as $isQuoteNode,Dt as DRAG_DROP_PASTE,Et as HeadingNode,xt as QuoteNode,Pt as eventFiles,bt as registerRichText};