Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/helpers

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/helpers - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

31

events.js

@@ -1,16 +0,17 @@

'use strict';var g=require("lexical"),w=require("lexical/ListNode"),y=require("lexical/ListItemNode"),z=require("lexical/ParagraphNode"),A=require("lexical/HeadingNode"),B=require("lexical/LinkNode"),C=require("lexical/CodeNode");
function D(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;g.$isElementNode(a)&&g.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):g.$isTextNode(a)&&g.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):g.$isDecoratorNode(a)&&g.$isDecoratorNode(b)&&(b.__state=a.__state);return b}
function E(a,b,c,e,h){for(var d=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!g.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let f=h.get(k);const l=void 0===f;l&&(f=D(a),h.set(k,f));!g.$isTextNode(f)||f.isSegmented()||f.isToken()?g.$isElementNode(f)&&(f.__children=f.__children.slice(c?d:0,c?void 0:d+1)):f.__text=f.__text.slice(c?d:0,c?void 0:d);if(g.$isRootNode(b)){l&&e.push(k);break}}d=h.get(b.getKey());d=g.$isElementNode(d)?
'use strict';var f=require("lexical"),w=require("lexical/ListNode"),y=require("lexical/ListItemNode"),z=require("lexical/ParagraphNode"),A=require("lexical/HeadingNode"),B=require("lexical/LinkNode"),C=require("lexical/CodeNode");
function D(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;f.$isElementNode(a)&&f.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):f.$isTextNode(a)&&f.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):f.$isDecoratorNode(a)&&f.$isDecoratorNode(b)&&(b.__state=a.__state);return b}
function E(a,b,c,e,h){for(var d=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!f.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let g=h.get(k);const l=void 0===g;l&&(g=D(a),h.set(k,g));!f.$isTextNode(g)||g.isSegmented()||g.isToken()?f.$isElementNode(g)&&(g.__children=g.__children.slice(c?d:0,c?void 0:d+1)):g.__text=g.__text.slice(c?d:0,c?void 0:d);if(f.$isRootNode(b)){l&&e.push(k);break}}d=h.get(b.getKey());d=f.$isElementNode(d)?
d.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=b}}
const F={bold:1,underline:8,strikethrough:4,italic:2,code:16,subscript:32,superscript:64},G={ul:()=>({node:w.$createListNode("ul")}),ol:()=>({node:w.$createListNode("ol")}),li:()=>({node:y.$createListItemNode()}),h1:()=>({node:A.$createHeadingNode("h1")}),h2:()=>({node:A.$createHeadingNode("h2")}),h3:()=>({node:A.$createHeadingNode("h3")}),h4:()=>({node:A.$createHeadingNode("h4")}),h5:()=>({node:A.$createHeadingNode("h5")}),p:()=>({node:z.$createParagraphNode()}),br:()=>({node:g.$createLineBreakNode()}),
a:a=>({node:a instanceof HTMLAnchorElement?B.$createLinkNode(a.href):g.$createTextNode(a.textContent)}),u:()=>({node:null,format:"underline"}),b:a=>({node:null,format:"normal"===a.style.fontWeight?null:"bold"}),strong:()=>({node:null,format:"bold"}),i:()=>({node:null,format:"italic"}),em:()=>({node:null,format:"italic"}),td:a=>{const b=a.classList.contains("js-file-line");return{node:null,after:c=>{b&&a.parentNode&&a.parentNode.nextSibling&&c.push(g.$createLineBreakNode());return c}}},table:a=>({node:a.classList.contains("js-file-line-container")?
C.$createCodeNode():null}),span:a=>({node:null,format:"700"===a.style.fontWeight?"bold":null}),"#text":a=>({node:g.$createTextNode(a.textContent)}),pre:()=>({node:C.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?C.$createCodeNode():null,after:b=>{const c=a.parentNode;null!=c&&a!==c.lastChild&&b.push(g.$createLineBreakNode());return b}})};
function H(a,b,c,e){let h=[],d=null;var k=a.nodeName.toLowerCase(),f=(k=(c._config.htmlTransforms||{})[k]||b[k])?k(a):null;k=null;null!==f&&(k=f.after,d=f.node,f.format&&(f=F[f.format],e=e?e^f:f),null!==d&&(g.$isTextNode(d)&&void 0!==e&&d.setFormat(e),h.push(d)));a=a.childNodes;for(f=0;f<a.length;f++){const l=H(a[f],b,c,e);g.$isElementNode(d)?d.append(...l):null===d&&(h=h.concat(l))}null!=k&&(h=k(h,d));return h}
function I(a,b,c){var e=a.getData("application/x-lexical-editor");if(e){var h=c._config.namespace;try{const l=JSON.parse(e);if(l.namespace===h){const {range:n,nodeMap:m}=l.state;var d=new Map(m);e=[];for(h=0;h<n.length;h++){var k=d.get(n[h]);if(void 0!==k){var f=g.$createNodeFromParse(k,d);e.push(f)}}b.insertNodes(e);return}}catch(l){}}if(d=a.getData("text/html")){d=(new DOMParser).parseFromString(d,"text/html");a=[];d=d.body?Array.from(d.body.childNodes):[];k=d.length;for(f=0;f<k;f++)e=H(d[f],G,
c),null!==e&&(a=a.concat(e));c=a;a=[];d=null;for(k=0;k<c.length;k++)f=c[k],!g.$isElementNode(f)||f.isInline()?(null===d&&(d=z.$createParagraphNode(),a.push(d)),null!==d&&d.append(f)):(a.push(f),d=null);b.insertNodes(a)}else J(a,b)}function J(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)}
function K(a,b){a.preventDefault();b.update(()=>{g.$log("onCopyForPlainText");const c=a.clipboardData,e=g.$getSelection();if(null!==e&&null!=c){var h=window.getSelection();if(!h.isCollapsed){var d=h.getRangeAt(0);d&&(h=document.createElement("div"),d=d.cloneContents(),h.appendChild(d),c.setData("text/html",h.innerHTML));c.setData("text/plain",e.getTextContent())}}})}
function L(a,b){a.preventDefault();b.update(()=>{g.$log("onCopyForRichText");const c=a.clipboardData;var e=g.$getSelection();if(null!==e&&null!=c){var h=window.getSelection();if(!h.isCollapsed){var d=h.getRangeAt(0);d&&(h=document.createElement("div"),d=d.cloneContents(),h.appendChild(d),c.setData("text/html",h.innerHTML));c.setData("text/plain",e.getTextContent());h=b._config.namespace;d=c.setData;var k=JSON,f=k.stringify;{var l=e.anchor,n=e.focus;var m=l.getCharacterOffset();const x=n.getCharacterOffset();
var p=l.getNode(),t=n.getNode(),q=p.getParentOrThrow();if(p===t&&g.$isTextNode(p)&&(q.canBeEmpty()||1<q.getChildrenSize()))e=D(p),p=x>m,e.__text=e.__text.slice(p?m:x,p?x:m),m=e.getKey(),m={range:[m],nodeMap:[[m,e]]};else if(e=e.getNodes(),0===e.length)m={range:[],nodeMap:[]};else{p=e.length;t=e[0];q=t.getParent();if(null!==q&&!q.canBeEmpty()){var u=q.__children;if(u.length===p){var r=!0;for(var v=0;v<u.length;v++)if(u[v]!==e[v].__key){r=!1;break}r&&(p++,e.push(q))}}q=e[p-1];l=l.isBefore(n);n=new Map;
u=[];E(t,l?m:x,!0,u,n);for(t=0;t<p;t++)if(r=e[t],v=r.getKey(),!(n.has(v)||g.$isElementNode(r)&&r.excludeFromCopy())){const M=D(r);g.$isRootNode(r.getParent())&&u.push(r.getKey());n.set(v,M)}E(q,l?x:m,!1,u,n);m={range:u,nodeMap:Array.from(n.entries())}}}d.call(c,"application/x-lexical-editor",f.call(k,{namespace:h,state:m}))}}})}exports.$createNodesFromDOM=H;exports.$insertDataTransferForPlainText=J;exports.$insertDataTransferForRichText=I;
exports.$shouldOverrideDefaultCharacterSelection=function(a,b){var c=a.focus;a=c.offset;"element"===c.type?b=c.getNode().getChildAtIndex(b?a-1:a):(c=c.getNode(),b=b&&0===a||!b&&a===c.getTextContentSize()?b?c.getPreviousSibling():c.getNextSibling():null);return g.$isDecoratorNode(b)};exports.onCopyForPlainText=K;exports.onCopyForRichText=L;exports.onCutForPlainText=function(a,b){K(a,b);b.update(()=>{g.$log("onCutForPlainText");const c=g.$getSelection();null!==c&&c.removeText()})};
exports.onCutForRichText=function(a,b){L(a,b);b.update(()=>{g.$log("onCutForRichText");const c=g.$getSelection();null!==c&&c.removeText()})};exports.onPasteForPlainText=function(a,b){a.preventDefault();b.update(()=>{g.$log("onPasteForPlainText");const c=g.$getSelection(),e=a.clipboardData;null!=e&&null!==c&&J(e,c)})};exports.onPasteForRichText=function(a,b){a.preventDefault();b.update(()=>{g.$log("onPasteForRichText");const c=g.$getSelection(),e=a.clipboardData;null!=e&&null!==c&&I(e,c,b)})};
const F={ul:()=>({node:w.$createListNode("ul")}),ol:()=>({node:w.$createListNode("ol")}),li:()=>({node:y.$createListItemNode()}),h1:()=>({node:A.$createHeadingNode("h1")}),h2:()=>({node:A.$createHeadingNode("h2")}),h3:()=>({node:A.$createHeadingNode("h3")}),h4:()=>({node:A.$createHeadingNode("h4")}),h5:()=>({node:A.$createHeadingNode("h5")}),p:()=>({node:z.$createParagraphNode()}),br:()=>({node:f.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?B.$createLinkNode(a.href):f.$createTextNode(a.textContent)}),
u:()=>({node:null,forChild:a=>{f.$isTextNode(a)&&a.toggleFormat("underline")}}),b:a=>{const b="normal"===a.style.fontWeight;return{node:null,forChild:c=>{f.$isTextNode(c)&&!b&&c.toggleFormat("bold")}}},strong:()=>({node:null,forChild:a=>{f.$isTextNode(a)&&a.toggleFormat("bold")}}),i:()=>({node:null,forChild:a=>{f.$isTextNode(a)&&a.toggleFormat("italic")}}),em:()=>({node:null,forChild:a=>{f.$isTextNode(a)&&a.toggleFormat("italic")}}),td:a=>{const b=a.classList.contains("js-file-line");return{node:null,
after:c=>{b&&a.parentNode&&a.parentNode.nextSibling&&c.push(f.$createLineBreakNode());return c}}},table:a=>({node:a.classList.contains("js-file-line-container")?C.$createCodeNode():null}),span:a=>{const b="700"===a.style.fontWeight;return{node:null,forChild:c=>{f.$isTextNode(c)&&b&&c.toggleFormat("bold")}}},"#text":a=>({node:f.$createTextNode(a.textContent)}),pre:()=>({node:C.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?C.$createCodeNode():null,after:b=>{const c=
a.parentNode;null!=c&&a!==c.lastChild&&b.push(f.$createLineBreakNode());return b}})};
function G(a,b,c,e=new Map){let h=[],d=null;var k=a.nodeName.toLowerCase(),g=(c._config.htmlTransforms||{})[k]||b[k],l=g?g(a):null;g=null;if(null!==l){g=l.after;d=l.node;if(null!==d){h.push(d);const n=Array.from(e.values());for(let m=0;m<n.length;m++)n[m](d)}null!=l.forChild&&e.set(k,l.forChild)}a=a.childNodes;k=[];for(l=0;l<a.length;l++)k.push(...G(a[l],b,c,e));null!=g&&(k=g(k));null==d?h=h.concat(k):f.$isElementNode(d)&&d.append(...k);return h}
function H(a,b,c){var e=a.getData("application/x-lexical-editor");if(e){var h=c._config.namespace;try{const l=JSON.parse(e);if(l.namespace===h){const {range:n,nodeMap:m}=l.state;var d=new Map(m);e=[];for(h=0;h<n.length;h++){var k=d.get(n[h]);if(void 0!==k){var g=f.$createNodeFromParse(k,d);e.push(g)}}b.insertNodes(e);return}}catch(l){}}if(d=a.getData("text/html")){d=(new DOMParser).parseFromString(d,"text/html");a=[];d=d.body?Array.from(d.body.childNodes):[];k=d.length;for(g=0;g<k;g++)e=G(d[g],F,
c),null!==e&&(a=a.concat(e));c=a;a=[];d=null;for(k=0;k<c.length;k++)g=c[k],!f.$isElementNode(g)||g.isInline()?(null===d&&(d=z.$createParagraphNode(),a.push(d)),null!==d&&d.append(g)):(a.push(g),d=null);b.insertNodes(a)}else I(a,b)}function I(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)}
function J(a,b){a.preventDefault();b.update(()=>{f.$log("onCopyForPlainText");const c=a.clipboardData,e=f.$getSelection();if(null!==e&&null!=c){var h=window.getSelection();if(!h.isCollapsed){var d=h.getRangeAt(0);d&&(h=document.createElement("div"),d=d.cloneContents(),h.appendChild(d),c.setData("text/html",h.innerHTML));c.setData("text/plain",e.getTextContent())}}})}
function K(a,b){a.preventDefault();b.update(()=>{f.$log("onCopyForRichText");const c=a.clipboardData;var e=f.$getSelection();if(null!==e&&null!=c){var h=window.getSelection();if(!h.isCollapsed){var d=h.getRangeAt(0);d&&(h=document.createElement("div"),d=d.cloneContents(),h.appendChild(d),c.setData("text/html",h.innerHTML));c.setData("text/plain",e.getTextContent());h=b._config.namespace;d=c.setData;var k=JSON,g=k.stringify;{var l=e.anchor,n=e.focus;var m=l.getCharacterOffset();const x=n.getCharacterOffset();
var p=l.getNode(),t=n.getNode(),q=p.getParentOrThrow();if(p===t&&f.$isTextNode(p)&&(q.canBeEmpty()||1<q.getChildrenSize()))e=D(p),p=x>m,e.__text=e.__text.slice(p?m:x,p?x:m),m=e.getKey(),m={range:[m],nodeMap:[[m,e]]};else if(e=e.getNodes(),0===e.length)m={range:[],nodeMap:[]};else{p=e.length;t=e[0];q=t.getParent();if(null!==q&&!q.canBeEmpty()){var u=q.__children;if(u.length===p){var r=!0;for(var v=0;v<u.length;v++)if(u[v]!==e[v].__key){r=!1;break}r&&(p++,e.push(q))}}q=e[p-1];l=l.isBefore(n);n=new Map;
u=[];E(t,l?m:x,!0,u,n);for(t=0;t<p;t++)if(r=e[t],v=r.getKey(),!(n.has(v)||f.$isElementNode(r)&&r.excludeFromCopy())){const L=D(r);f.$isRootNode(r.getParent())&&u.push(r.getKey());n.set(v,L)}E(q,l?x:m,!1,u,n);m={range:u,nodeMap:Array.from(n.entries())}}}d.call(c,"application/x-lexical-editor",g.call(k,{namespace:h,state:m}))}}})}exports.$createNodesFromDOM=G;exports.$insertDataTransferForPlainText=I;exports.$insertDataTransferForRichText=H;
exports.$shouldOverrideDefaultCharacterSelection=function(a,b){var c=a.focus;a=c.offset;"element"===c.type?b=c.getNode().getChildAtIndex(b?a-1:a):(c=c.getNode(),b=b&&0===a||!b&&a===c.getTextContentSize()?b?c.getPreviousSibling():c.getNextSibling():null);return f.$isDecoratorNode(b)};exports.onCopyForPlainText=J;exports.onCopyForRichText=K;exports.onCutForPlainText=function(a,b){J(a,b);b.update(()=>{f.$log("onCutForPlainText");const c=f.$getSelection();null!==c&&c.removeText()})};
exports.onCutForRichText=function(a,b){K(a,b);b.update(()=>{f.$log("onCutForRichText");const c=f.$getSelection();null!==c&&c.removeText()})};exports.onPasteForPlainText=function(a,b){a.preventDefault();b.update(()=>{f.$log("onPasteForPlainText");const c=f.$getSelection(),e=a.clipboardData;null!=e&&null!==c&&I(e,c)})};exports.onPasteForRichText=function(a,b){a.preventDefault();b.update(()=>{f.$log("onPasteForRichText");const c=f.$getSelection(),e=a.clipboardData;null!=e&&null!==c&&H(e,c,b)})};

@@ -16,9 +16,5 @@ {

"license": "MIT",
"version": "0.1.3",
"dependencies": {
"lexical": "0.1.3"
},
"version": "0.1.4",
"peerDependencies": {
"react": ">=17.x",
"react-dom": ">=17.x"
"lexical": "0.1.4"
},

@@ -25,0 +21,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc