@lexical/helpers
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -1,17 +0,17 @@ | ||
'use strict';var e=require("lexical"),w=require("lexical/ListNode"),y=require("lexical/ListItemNode"),z=require("lexical/HeadingNode"),A=require("lexical/LinkNode"),B=require("lexical/CodeNode"); | ||
function C(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;e.$isElementNode(a)&&e.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):e.$isTextNode(a)&&e.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):e.$isDecoratorNode(a)&&e.$isDecoratorNode(b)&&(b.__state=a.__state);return b} | ||
function D(a,b,c,f,h){for(var d=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!e.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let g=h.get(k);const l=void 0===g;l&&(g=C(a),h.set(k,g));!e.$isTextNode(g)||g.isSegmented()||g.isToken()?e.$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(e.$isRootNode(b)){l&&f.push(k);break}}d=h.get(b.getKey());d=e.$isElementNode(d)? | ||
'use strict';var e=require("lexical"),w=require("@lexical/list"),y=require("lexical/HeadingNode"),z=require("lexical/LinkNode"),A=require("lexical/CodeNode"); | ||
function B(a){a=a.getLatest();const b=a.constructor.clone(a);b.__parent=a.__parent;e.$isElementNode(a)&&e.$isElementNode(b)?(b.__children=Array.from(a.__children),b.__format=a.__format,b.__indent=a.__indent,b.__dir=a.__dir):e.$isTextNode(a)&&e.$isTextNode(b)?(b.__format=a.__format,b.__style=a.__style,b.__mode=a.__mode,b.__detail=a.__detail):e.$isDecoratorNode(a)&&e.$isDecoratorNode(b)&&(b.__state=a.__state);return b} | ||
function C(a,b,c,f,h){for(var d=b;null!==a;){for(b=a.getParent();null!==b&&b.excludeFromCopy();)b=b.getParent();if(null===b)break;if(!e.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let g=h.get(k);const l=void 0===g;l&&(g=B(a),h.set(k,g));!e.$isTextNode(g)||g.isSegmented()||g.isToken()?e.$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(e.$isRootNode(b)){l&&f.push(k);break}}d=h.get(b.getKey());d=e.$isElementNode(d)? | ||
d.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=b}} | ||
const E={ul:()=>({node:w.$createListNode("ul")}),ol:()=>({node:w.$createListNode("ol")}),li:()=>({node:y.$createListItemNode()}),h1:()=>({node:z.$createHeadingNode("h1")}),h2:()=>({node:z.$createHeadingNode("h2")}),h3:()=>({node:z.$createHeadingNode("h3")}),h4:()=>({node:z.$createHeadingNode("h4")}),h5:()=>({node:z.$createHeadingNode("h5")}),p:()=>({node:e.$createParagraphNode()}),br:()=>({node:e.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?A.$createLinkNode(a.href):e.$createTextNode(a.textContent)}), | ||
const D={ul:()=>({node:w.$createListNode("ul")}),ol:()=>({node:w.$createListNode("ol")}),li:()=>({node:w.$createListItemNode()}),h1:()=>({node:y.$createHeadingNode("h1")}),h2:()=>({node:y.$createHeadingNode("h2")}),h3:()=>({node:y.$createHeadingNode("h3")}),h4:()=>({node:y.$createHeadingNode("h4")}),h5:()=>({node:y.$createHeadingNode("h5")}),p:()=>({node:e.$createParagraphNode()}),br:()=>({node:e.$createLineBreakNode()}),a:a=>({node:a instanceof HTMLAnchorElement?z.$createLinkNode(a.href):e.$createTextNode(a.textContent)}), | ||
u:()=>({node:null,forChild:a=>{e.$isTextNode(a)&&a.toggleFormat("underline")}}),b:a=>{const b="normal"===a.style.fontWeight;return{node:null,forChild:c=>{e.$isTextNode(c)&&!b&&c.toggleFormat("bold")}}},strong:()=>({node:null,forChild:a=>{e.$isTextNode(a)&&a.toggleFormat("bold")}}),i:()=>({node:null,forChild:a=>{e.$isTextNode(a)&&a.toggleFormat("italic")}}),em:()=>({node:null,forChild:a=>{e.$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(e.$createLineBreakNode());return c}}},table:a=>({node:a.classList.contains("js-file-line-container")?B.$createCodeNode():null}),span:a=>{const b="700"===a.style.fontWeight;return{node:null,forChild:c=>{e.$isTextNode(c)&&b&&c.toggleFormat("bold")}}},"#text":a=>({node:e.$createTextNode(a.textContent)}),pre:()=>({node:B.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?B.$createCodeNode():null,after:b=>{const c= | ||
after:c=>{b&&a.parentNode&&a.parentNode.nextSibling&&c.push(e.$createLineBreakNode());return c}}},table:a=>({node:a.classList.contains("js-file-line-container")?A.$createCodeNode():null}),span:a=>{const b="700"===a.style.fontWeight;return{node:null,forChild:c=>{e.$isTextNode(c)&&b&&c.toggleFormat("bold")}}},"#text":a=>({node:e.$createTextNode(a.textContent)}),pre:()=>({node:A.$createCodeNode()}),div:a=>({node:null!==a.style.fontFamily.match("monospace")?A.$createCodeNode():null,after:b=>{const c= | ||
a.parentNode;null!=c&&a!==c.lastChild&&b.push(e.$createLineBreakNode());return b}})}; | ||
function F(a,b,c,f=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(f.values());for(let m=0;m<n.length;m++)n[m](d)}null!=l.forChild&&f.set(k,l.forChild)}a=a.childNodes;k=[];for(l=0;l<a.length;l++)k.push(...F(a[l],b,c,f));null!=g&&(k=g(k));null==d?h=h.concat(k):e.$isElementNode(d)&&d.append(...k);return h} | ||
function G(a,b,c){var f=a.getData("application/x-lexical-editor");if(f){var h=c._config.namespace;try{const l=JSON.parse(f);if(l.namespace===h){const {range:n,nodeMap:m}=l.state;var d=new Map(m);f=[];for(h=0;h<n.length;h++){var k=d.get(n[h]);if(void 0!==k){var g=e.$createNodeFromParse(k,d);f.push(g)}}b.insertNodes(f);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++)f=F(d[g],E, | ||
c),null!==f&&(a=a.concat(f));c=a;a=[];d=null;for(k=0;k<c.length;k++)g=c[k],!e.$isElementNode(g)||g.isInline()?(null===d&&(d=e.$createParagraphNode(),a.push(d)),null!==d&&d.append(g)):(a.push(g),d=null);b.insertNodes(a)}else H(a,b)}function H(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)} | ||
function I(a,b){a.preventDefault();b.update(()=>{e.$log("onCopyForPlainText");const c=a.clipboardData,f=e.$getSelection();if(null!==f&&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",f.getTextContent())}}})} | ||
function J(a,b){a.preventDefault();b.update(()=>{e.$log("onCopyForRichText");const c=a.clipboardData;var f=e.$getSelection();if(null!==f&&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",f.getTextContent());h=b._config.namespace;d=c.setData;var k=JSON,g=k.stringify;{var l=f.anchor,n=f.focus;var m=l.getCharacterOffset();const x=n.getCharacterOffset(); | ||
var p=l.getNode(),t=n.getNode(),q=p.getParentOrThrow();if(p===t&&e.$isTextNode(p)&&(q.canBeEmpty()||1<q.getChildrenSize()))f=C(p),p=x>m,f.__text=f.__text.slice(p?m:x,p?x:m),m=f.getKey(),m={range:[m],nodeMap:[[m,f]]};else if(f=f.getNodes(),0===f.length)m={range:[],nodeMap:[]};else{p=f.length;t=f[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]!==f[v].__key){r=!1;break}r&&(p++,f.push(q))}}q=f[p-1];l=l.isBefore(n);n=new Map; | ||
u=[];D(t,l?m:x,!0,u,n);for(t=0;t<p;t++)if(r=f[t],v=r.getKey(),!(n.has(v)||e.$isElementNode(r)&&r.excludeFromCopy())){const K=C(r);e.$isRootNode(r.getParent())&&u.push(r.getKey());n.set(v,K)}D(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=F;exports.$insertDataTransferForPlainText=H;exports.$insertDataTransferForRichText=G; | ||
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 e.$isDecoratorNode(b)};exports.onCopyForPlainText=I;exports.onCopyForRichText=J;exports.onCutForPlainText=function(a,b){I(a,b);b.update(()=>{e.$log("onCutForPlainText");const c=e.$getSelection();null!==c&&c.removeText()})}; | ||
exports.onCutForRichText=function(a,b){J(a,b);b.update(()=>{e.$log("onCutForRichText");const c=e.$getSelection();null!==c&&c.removeText()})};exports.onPasteForPlainText=function(a,b){a.preventDefault();b.update(()=>{e.$log("onPasteForPlainText");const c=e.$getSelection(),f=a.clipboardData;null!=f&&null!==c&&H(f,c)})};exports.onPasteForRichText=function(a,b){a.preventDefault();b.update(()=>{e.$log("onPasteForRichText");const c=e.$getSelection(),f=a.clipboardData;null!=f&&null!==c&&G(f,c,b)})}; | ||
function E(a,b,c,f=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(f.values());for(let m=0;m<n.length;m++)n[m](d)}null!=l.forChild&&f.set(k,l.forChild)}a=a.childNodes;k=[];for(l=0;l<a.length;l++)k.push(...E(a[l],b,c,f));null!=g&&(k=g(k));null==d?h=h.concat(k):e.$isElementNode(d)&&d.append(...k);return h} | ||
function F(a,b,c){var f=a.getData("application/x-lexical-editor");if(f){var h=c._config.namespace;try{const l=JSON.parse(f);if(l.namespace===h){const {range:n,nodeMap:m}=l.state;var d=new Map(m);f=[];for(h=0;h<n.length;h++){var k=d.get(n[h]);if(void 0!==k){var g=e.$createNodeFromParse(k,d);f.push(g)}}b.insertNodes(f);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++)f=E(d[g],D, | ||
c),null!==f&&(a=a.concat(f));c=a;a=[];d=null;for(k=0;k<c.length;k++)g=c[k],!e.$isElementNode(g)||g.isInline()?(null===d&&(d=e.$createParagraphNode(),a.push(d)),null!==d&&d.append(g)):(a.push(g),d=null);b.insertNodes(a)}else G(a,b)}function G(a,b){a=a.getData("text/plain");null!=a&&b.insertRawText(a)} | ||
function H(a,b){a.preventDefault();b.update(()=>{e.$log("onCopyForPlainText");const c=a.clipboardData,f=e.$getSelection();if(null!==f&&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",f.getTextContent())}}})} | ||
function I(a,b){a.preventDefault();b.update(()=>{e.$log("onCopyForRichText");const c=a.clipboardData;var f=e.$getSelection();if(null!==f&&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",f.getTextContent());h=b._config.namespace;d=c.setData;var k=JSON,g=k.stringify;{var l=f.anchor,n=f.focus;var m=l.getCharacterOffset();const x=n.getCharacterOffset(); | ||
var p=l.getNode(),t=n.getNode(),q=p.getParentOrThrow();if(p===t&&e.$isTextNode(p)&&(q.canBeEmpty()||1<q.getChildrenSize()))f=B(p),p=x>m,f.__text=f.__text.slice(p?m:x,p?x:m),m=f.getKey(),m={range:[m],nodeMap:[[m,f]]};else if(f=f.getNodes(),0===f.length)m={range:[],nodeMap:[]};else{p=f.length;t=f[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]!==f[v].__key){r=!1;break}r&&(p++,f.push(q))}}q=f[p-1];l=l.isBefore(n);n=new Map; | ||
u=[];C(t,l?m:x,!0,u,n);for(t=0;t<p;t++)if(r=f[t],v=r.getKey(),!(n.has(v)||e.$isElementNode(r)&&r.excludeFromCopy())){const J=B(r);e.$isRootNode(r.getParent())&&u.push(r.getKey());n.set(v,J)}C(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=E;exports.$insertDataTransferForPlainText=G;exports.$insertDataTransferForRichText=F; | ||
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 e.$isDecoratorNode(b)};exports.onCopyForPlainText=H;exports.onCopyForRichText=I;exports.onCutForPlainText=function(a,b){H(a,b);b.update(()=>{e.$log("onCutForPlainText");const c=e.$getSelection();null!==c&&c.removeText()})}; | ||
exports.onCutForRichText=function(a,b){I(a,b);b.update(()=>{e.$log("onCutForRichText");const c=e.$getSelection();null!==c&&c.removeText()})};exports.onPasteForPlainText=function(a,b){a.preventDefault();b.update(()=>{e.$log("onPasteForPlainText");const c=e.$getSelection(),f=a.clipboardData;null!=f&&null!==c&&G(f,c)})};exports.onPasteForRichText=function(a,b){a.preventDefault();b.update(()=>{e.$log("onPasteForRichText");const c=e.$getSelection(),f=a.clipboardData;null!=f&&null!==c&&F(f,c,b)})}; |
'use strict';var e=require("lexical");function f(a){const b=document.createElement("input");b.type="file";b.accept=".lexical";b.addEventListener("change",c=>{c=c.target.files[0];const d=new FileReader;d.readAsText(c,"UTF-8");d.onload=g=>{a(g.target.result)}});b.click()} | ||
exports.exportFile=function(a,b={}){var c=new Date;a=a.getEditorState();a={source:b.source||"Lexical",version:e.VERSION,lastSaved:c.getTime(),editorState:a};{b=`${b.fileName||c.toISOString()}.lexical`;c=document.createElement("a");const d=document.body;null!==d&&(d.appendChild(c),c.style.display="none",a=JSON.stringify(a),a=new Blob([a],{type:"octet/stream"}),a=window.URL.createObjectURL(a),c.href=a,c.download=b,c.click(),window.URL.revokeObjectURL(a),c.remove())}}; | ||
exports.exportFile=function(a,b=Object.freeze({})){var c=new Date;a=a.getEditorState();a={source:b.source||"Lexical",version:e.VERSION,lastSaved:c.getTime(),editorState:a};{b=`${b.fileName||c.toISOString()}.lexical`;c=document.createElement("a");const d=document.body;null!==d&&(d.appendChild(c),c.style.display="none",a=JSON.stringify(a),a=new Blob([a],{type:"octet/stream"}),a=window.URL.createObjectURL(a),c.href=a,c.download=b,c.click(),window.URL.revokeObjectURL(a),c.remove())}}; | ||
exports.importFile=function(a){f(b=>{b=JSON.parse(b);b=a.parseEditorState(JSON.stringify(b.editorState));a.setEditorState(b);a.execCommand("clearHistory")})}; |
12
nodes.js
@@ -1,7 +0,5 @@ | ||
'use strict';var e=require("lexical/ListNode"),g=require("lexical/ListItemNode"),h=require("lexical"),k=require("lexical/TableNode"),l=require("lexical/TableRowNode"),m=require("lexical/TableCellNode");function n(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");} | ||
function p(a){let b=[];a=a.getChildren().filter(g.$isListItemNode);for(let c=0;c<a.length;c++){const d=a[c],f=d.getFirstChild();e.$isListNode(f)?b=b.concat(p(f)):b.push(d)}return b}function v(a,b){let c=null;var d=b[a.nodeName.toLowerCase()];if(d&&(c=d(a),h.$isElementNode(c)))for(a=a.childNodes,d=0;d<a.length;d++){const f=v(a[d],b);null!==f&&c.append(f)}return c} | ||
function w(a){a=a.getPreviousSibling();return null===a||h.$isLineBreakNode(a)||h.$isTextNode(a)&&a.isSimpleText()&&a.getTextContent().endsWith(" ")}function x(a){a=a.getNextSibling();return null===a||h.$isLineBreakNode(a)||h.$isTextNode(a)&&a.isSimpleText()&&a.getTextContent().startsWith(" ")}exports.$areSiblingsNullOrSpace=function(a){return w(a)&&x(a)};exports.$createLexicalNodeFromDOMNode=v; | ||
exports.$createTableNodeWithDimensions=function(a,b,c=!0){const d=k.$createTableNode();for(let f=0;f<a;f++){const q=l.$createTableRowNode();for(let r=0;r<b;r++){const t=m.$createTableCellNode(0===f&&c),u=h.$createParagraphNode();u.append(h.$createTextNode());t.append(u);q.append(t)}d.append(q)}return d}; | ||
exports.$dfs__DEPRECATED=function(a,b){for(b(a);null!==a;){if(h.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let c=null;for(;null===c&&null!==a;)c=a.getNextSibling(),a=null===c?a.getParent():c}null!==a&&(a=b(a))}};exports.$findMatchingParent=function(a,b){for(;a!==h.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$getAllListItems=p; | ||
exports.$getListDepth=function(a){let b=1;for(a=a.getParent();null!=a;){if(g.$isListItemNode(a)){a=a.getParent();if(e.$isListNode(a)){b++;a=a.getParent();continue}n(2)}break}return b};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.$getTopListNode=function(a){a=a.getParent();e.$isListNode(a)||n(2);let b=a;for(;null!==b;)b=b.getParent(),e.$isListNode(b)&&(a=b);return a}; | ||
exports.$isLastItemInList=function(a){let b=!0;const c=a.getFirstChild();if(e.$isListNode(c))return!1;for(;null!==a;)g.$isListItemNode(a)&&0<a.getNextSiblings().length&&(b=!1),a=a.getParent();return b};exports.$isNextSiblingNullOrSpace=x;exports.$isPreviousSiblingNullOrSpace=w; | ||
'use strict';var d=require("lexical"),g=require("lexical/TableNode"),h=require("lexical/TableRowNode"),k=require("lexical/TableCellNode");function q(a,b){let c=null;var e=b[a.nodeName.toLowerCase()];if(e&&(c=e(a),d.$isElementNode(c)))for(a=a.childNodes,e=0;e<a.length;e++){const f=q(a[e],b);null!==f&&c.append(f)}return c}function r(a){a=a.getPreviousSibling();return null===a||d.$isLineBreakNode(a)||d.$isTextNode(a)&&a.isSimpleText()&&a.getTextContent().endsWith(" ")} | ||
function t(a){a=a.getNextSibling();return null===a||d.$isLineBreakNode(a)||d.$isTextNode(a)&&a.isSimpleText()&&a.getTextContent().startsWith(" ")}exports.$areSiblingsNullOrSpace=function(a){return r(a)&&t(a)};exports.$createLexicalNodeFromDOMNode=q; | ||
exports.$createTableNodeWithDimensions=function(a,b,c=!0){const e=g.$createTableNode();for(let f=0;f<a;f++){const l=h.$createTableRowNode();for(let m=0;m<b;m++){const n=k.$createTableCellNode(0===f&&c),p=d.$createParagraphNode();p.append(d.$createTextNode());n.append(p);l.append(n)}e.append(l)}return e}; | ||
exports.$dfs__DEPRECATED=function(a,b){for(b(a);null!==a;){if(d.$isElementNode(a)&&0<a.getChildrenSize())a=a.getFirstChild();else{let c=null;for(;null===c&&null!==a;)c=a.getNextSibling(),a=null===c?a.getParent():c}null!==a&&(a=b(a))}};exports.$findMatchingParent=function(a,b){for(;a!==d.$getRoot()&&null!=a;){if(b(a))return a;a=a.getParent()}return null};exports.$getNearestNodeOfType=function(a,b){for(;null!=a&&!(a instanceof b);)a=a.getParent();return a};exports.$isNextSiblingNullOrSpace=t; | ||
exports.$isPreviousSiblingNullOrSpace=r; |
'use strict';var q=require("lexical"); | ||
class t{constructor(b,a,c=1){this._offsetMap=b;this._firstNode=a;this._blockOffsetSize=c}createSelectionFromOffsets(b,a,c){var e=this._firstNode;if(null===e)return null;var f=y(e,b,this._blockOffsetSize);let h=y(e,a,this._blockOffsetSize);void 0!==c&&(b=z(b,f,c,this,this._blockOffsetSize),f=y(e,b,this._blockOffsetSize),a=z(a,h,c,this,this._blockOffsetSize),h=y(e,a,this._blockOffsetSize));if(null===f||null===h)return null;c=f.key;e=h.key;const m=q.$getNodeByKey(c),k=q.$getNodeByKey(e);if(null===m|| | ||
null===k)return null;let l=0,d=0,g="element",n="element";"text"===f.type?(l=b-f.start,g="text",f=m.getNextSibling(),b!==a&&l===m.getTextContentSize()&&q.$isTextNode(f)&&(l=0,c=f.__key)):"inline"===f.type&&(c=m.getParentOrThrow().getKey(),l=a>f.start?f.end:f.start);"text"===h.type?(d=a-h.start,n="text"):"inline"===h.type&&(e=k.getParentOrThrow().getKey(),d=a>h.start?h.end:h.start);b=q.$createSelection();if(null===b)return null;b.anchor.set(c,l,g);b.focus.set(e,d,n);return b}getOffsetsFromSelection(b){var a= | ||
null===k)return null;let l=0,d=0,g="element",n="element";"text"===f.type?(l=b-f.start,g="text",f=m.getNextSibling(),b!==a&&l===m.getTextContentSize()&&q.$isTextNode(f)&&(l=0,c=f.__key)):"inline"===f.type&&(c=m.getParentOrThrow().getKey(),l=a>f.start?f.end:f.start);"text"===h.type?(d=a-h.start,n="text"):"inline"===h.type&&(e=k.getParentOrThrow().getKey(),d=a>h.start?h.end:h.start);b=q.$createRangeSelection();if(null===b)return null;b.anchor.set(c,l,g);b.focus.set(e,d,n);return b}getOffsetsFromSelection(b){var a= | ||
b.anchor,c=b.focus,e=this._offsetMap;const f=a.offset;var h=c.offset;let m=b=-1;if("text"===a.type)a=e.get(a.key),void 0!==a&&(b=a.start+f);else{a=a.getNode().getDescendantByIndex(f);const k=e.get(a.getKey());void 0!==k&&(b=a.getIndexWithinParent()!==f?k.end:k.start)}"text"===c.type?(h=e.get(c.key),void 0!==h&&(m=h.start+c.offset)):(c=c.getNode().getDescendantByIndex(h),e=e.get(c.getKey()),void 0!==e&&(m=c.getIndexWithinParent()!==h?e.end:e.start));return[b,m]}} | ||
@@ -5,0 +5,0 @@ function z(b,a,c,e,f){const h=c._offsetMap;e=e._offsetMap;const m=new Set;let k=b;for(;null!==a;){var l=a.key,d=h.get(l),g=a.end-a.start;m.add(l);void 0===d?k+=g:(l=d.end-d.start,l!==g&&(k+=g-l));g=a.prev;if(null!==g)a=g;else{for(a=a.parent;null!==a;)d=a.prev,null!==d&&(g=d.key,l=h.get(g),d=d.end-d.start,m.add(g),void 0===l?k+=d:(g=l.end-l.start,g!==d&&(k+=d-g))),a=a.parent;break}}c=c._firstNode;if(null!==c){a=y(c,b,f);for(b=!1;null!==a;){if(!m.has(a.key)){b=!0;break}a=a.parent}if(!b)for(;null!== |
@@ -16,5 +16,6 @@ { | ||
"license": "MIT", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"peerDependencies": { | ||
"lexical": "0.1.6" | ||
"lexical": "0.1.7", | ||
"@lexical/list": "0.1.7" | ||
}, | ||
@@ -21,0 +22,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21652
2
93