@lexical/markdown
Advanced tools
Comparing version 0.5.1-next.1 to 0.5.1-next.2
@@ -423,3 +423,3 @@ /** | ||
const endIndex = startIndex + match[0].length; | ||
let replaceNode; | ||
let replaceNode, leftTextNode, rightTextNode; | ||
@@ -429,5 +429,13 @@ if (startIndex === 0) { | ||
} else { | ||
[, replaceNode, textNode] = textNode.splitText(startIndex, endIndex); | ||
[leftTextNode, replaceNode, rightTextNode] = textNode.splitText(startIndex, endIndex); | ||
} | ||
if (leftTextNode) { | ||
importTextMatchTransformers(leftTextNode, textMatchTransformers); | ||
} | ||
if (rightTextNode) { | ||
textNode = rightTextNode; | ||
} | ||
transformer.replace(replaceNode, match); | ||
@@ -434,0 +442,0 @@ continue mainLoop; |
@@ -7,27 +7,28 @@ /** | ||
*/ | ||
'use strict';var h=require("lexical"),t=require("@lexical/code"),A=require("@lexical/list"),F=require("@lexical/rich-text"),aa=require("@lexical/utils"),G=require("@lexical/link");function H(a,b){let c={};for(let d of a)a=b(d),c[a]?c[a].push(d):c[a]=[d];return c}function I(a){a=H(a,b=>b.type);return{element:a.element||[],textFormat:a["text-format"]||[],textMatch:a["text-match"]||[]}}let J=/[!-/:-@[-`{-~\s]/; | ||
function ba(a){let b=I(a),c=b.textFormat.filter(d=>1===d.format.length);return()=>{let d=[];var e=h.$getRoot().getChildren();for(let f of e)e=ca(f,b.element,c,b.textMatch),null!=e&&d.push(e);return d.join("\n\n")}}function ca(a,b,c,d){for(let e of b)if(b=e.export(a,f=>K(f,c,d)),null!=b)return b;return h.$isElementNode(a)?K(a,c,d):null} | ||
function K(a,b,c){let d=[];a=a.getChildren();a:for(let e of a){for(let f of c)if(a=f.export(e,k=>K(k,b,c),(k,p)=>L(k,p,b)),null!=a){d.push(a);continue a}h.$isLineBreakNode(e)?d.push("\n"):h.$isTextNode(e)?d.push(L(e,e.getTextContent(),b)):h.$isElementNode(e)&&d.push(K(e,b,c))}return d.join("")}function L(a,b,c){let d=b.trim(),e=d,f=new Set;for(let p of c){c=p.format[0];let r=p.tag;if(M(a,c)&&!f.has(c)){f.add(c);var k=N(a,!0);M(k,c)||(e=r+e);k=N(a,!1);M(k,c)||(e+=r)}}return b.replace(d,e)} | ||
function N(a,b){let c=b?a.getPreviousSibling():a.getNextSibling();c||(a=a.getParentOrThrow(),a.isInline()&&(c=b?a.getPreviousSibling():a.getNextSibling()));for(;c;){if(h.$isElementNode(c)){if(!c.isInline())break;a=b?c.getLastDescendant():c.getFirstDescendant();if(h.$isTextNode(a))return a;c=b?c.getPreviousSibling():c.getNextSibling()}if(h.$isTextNode(c))return c;if(!h.$isElementNode(c))break}return null}function M(a,b){return h.$isTextNode(a)&&a.hasFormat(b)} | ||
'use strict';var k=require("lexical"),t=require("@lexical/code"),A=require("@lexical/list"),F=require("@lexical/rich-text"),aa=require("@lexical/utils"),G=require("@lexical/link");function H(a,b){let c={};for(let d of a)a=b(d),c[a]?c[a].push(d):c[a]=[d];return c}function I(a){a=H(a,b=>b.type);return{element:a.element||[],textFormat:a["text-format"]||[],textMatch:a["text-match"]||[]}}let J=/[!-/:-@[-`{-~\s]/; | ||
function ba(a){let b=I(a),c=b.textFormat.filter(d=>1===d.format.length);return()=>{let d=[];var e=k.$getRoot().getChildren();for(let f of e)e=ca(f,b.element,c,b.textMatch),null!=e&&d.push(e);return d.join("\n\n")}}function ca(a,b,c,d){for(let e of b)if(b=e.export(a,f=>K(f,c,d)),null!=b)return b;return k.$isElementNode(a)?K(a,c,d):null} | ||
function K(a,b,c){let d=[];a=a.getChildren();a:for(let e of a){for(let f of c)if(a=f.export(e,l=>K(l,b,c),(l,h)=>L(l,h,b)),null!=a){d.push(a);continue a}k.$isLineBreakNode(e)?d.push("\n"):k.$isTextNode(e)?d.push(L(e,e.getTextContent(),b)):k.$isElementNode(e)&&d.push(K(e,b,c))}return d.join("")}function L(a,b,c){let d=b.trim(),e=d,f=new Set;for(let h of c){c=h.format[0];let p=h.tag;if(M(a,c)&&!f.has(c)){f.add(c);var l=N(a,!0);M(l,c)||(e=p+e);l=N(a,!1);M(l,c)||(e+=p)}}return b.replace(d,e)} | ||
function N(a,b){let c=b?a.getPreviousSibling():a.getNextSibling();c||(a=a.getParentOrThrow(),a.isInline()&&(c=b?a.getPreviousSibling():a.getNextSibling()));for(;c;){if(k.$isElementNode(c)){if(!c.isInline())break;a=b?c.getLastDescendant():c.getFirstDescendant();if(k.$isTextNode(a))return a;c=b?c.getPreviousSibling():c.getNextSibling()}if(k.$isTextNode(c))return c;if(!k.$isElementNode(c))break}return null}function M(a,b){return k.$isTextNode(a)&&a.hasFormat(b)} | ||
let O="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,da=O&&"documentMode"in document?document.documentMode:null;O&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);O&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);O&&"InputEvent"in window&&!da?"getTargetRanges"in new window.InputEvent("input"):!1; | ||
let P=O&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),Q=O&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,ea=/^\s{0,3}$/,R=/^```(\w{1,10})?\s?$/; | ||
function fa(a){let b=I(a),c=ha(b.textFormat);return d=>{var e=d.split("\n"),f=e.length;d=h.$getRoot();d.clear();for(let g=0;g<f;g++){var k=e[g];a:{var p=e,r=g;var n=d;var u=p[r].match(R);if(u)for(var q=r,l=p.length;++q<l;)if(p[q].match(R)){u=t.$createCodeNode(u[1]);p=h.$createTextNode(p.slice(r+1,q).join("\n"));u.append(p);n.append(u);n=[u,q];break a}n=[null,r]}let [m,w]=n;if(null!=m)g=w;else{n=k;l=d;var x=b.element;q=c;p=b.textMatch;r=n.trim();u=h.$createTextNode(r);k=h.$createParagraphNode();k.append(u); | ||
l.append(k);for(let {regExp:y,replace:v}of x)if(l=n.match(y)){u.setTextContent(n.slice(l[0].length));v(k,[u],l,!0);break}S(u,q,p);k.isAttached()&&0<r.length&&(n=k.getPreviousSibling(),h.$isParagraphNode(n)||F.$isQuoteNode(n)||A.$isListNode(n))&&(q=n,A.$isListNode(n)&&(n=n.getLastDescendant(),q=null==n?null:aa.$findMatchingParent(n,A.$isListItemNode)),null!=q&&0<q.getTextContentSize()&&(q.splice(q.getChildrenSize(),0,[h.$createLineBreakNode(),...k.getChildren()]),k.remove()))}}e=d.getChildren();for(let g of e)e= | ||
g,h.$isParagraphNode(e)?(f=e.getFirstChild(),e=null==f||1===e.getChildrenSize()&&h.$isTextNode(f)&&ea.test(f.getTextContent())):e=!1,e&&g.remove();d.selectEnd()}} | ||
function S(a,b,c){let d=a.getTextContent(),e=ia(d,b);if(e){if(e[0]===d)var f=a;else{var k=e.index||0,p=k+e[0].length;0===k?[f,r]=a.splitText(p):[n,f,r]=a.splitText(k,p)}f.setTextContent(e[2]);if(k=b.transformersByTag[e[1]])for(let u of k.format)f.hasFormat(u)||f.toggleFormat(u);f.hasFormat("code")||S(f,b,c);n&&S(n,b,c);r&&S(r,b,c)}else a:for(b=a;b;){for(k of c)if(f=b.getTextContent().match(k.importRegExp)){var r=f.index||0;var n=r+f[0].length;0===r?[p,b]=b.splitText(n):[,p,b]=b.splitText(r,n);k.replace(p, | ||
f);continue a}break}}function ia(a,b){var c=a.match(b.openTagsRegExp);if(null==c)return null;for(let f of c){var d=f.replace(/^\s/,"");c=b.fullMatchRegExpByTag[d];if(null!=c&&(c=a.match(c),d=b.transformersByTag[d],null!=c&&null!=d)){if(!1!==d.intraword)return c;var {index:e=0}=c;d=a[e-1];e=a[e+c[0].length];if(!(d&&!J.test(d)||e&&!J.test(e)))return c}}return null} | ||
function fa(a){let b=I(a),c=ha(b.textFormat);return d=>{var e=d.split("\n"),f=e.length;d=k.$getRoot();d.clear();for(let g=0;g<f;g++){var l=e[g];a:{var h=e,p=g;var r=d;var y=h[p].match(R);if(y)for(var q=p,m=h.length;++q<m;)if(h[q].match(R)){y=t.$createCodeNode(y[1]);h=k.$createTextNode(h.slice(p+1,q).join("\n"));y.append(h);r.append(y);r=[y,q];break a}r=[null,p]}let [n,v]=r;if(null!=n)g=v;else{r=l;m=d;var w=b.element;q=c;h=b.textMatch;p=r.trim();y=k.$createTextNode(p);l=k.$createParagraphNode();l.append(y); | ||
m.append(l);for(let {regExp:x,replace:u}of w)if(m=r.match(x)){y.setTextContent(r.slice(m[0].length));u(l,[y],m,!0);break}S(y,q,h);l.isAttached()&&0<p.length&&(r=l.getPreviousSibling(),k.$isParagraphNode(r)||F.$isQuoteNode(r)||A.$isListNode(r))&&(q=r,A.$isListNode(r)&&(r=r.getLastDescendant(),q=null==r?null:aa.$findMatchingParent(r,A.$isListItemNode)),null!=q&&0<q.getTextContentSize()&&(q.splice(q.getChildrenSize(),0,[k.$createLineBreakNode(),...l.getChildren()]),l.remove()))}}e=d.getChildren();for(let g of e)e= | ||
g,k.$isParagraphNode(e)?(f=e.getFirstChild(),e=null==f||1===e.getChildrenSize()&&k.$isTextNode(f)&&ea.test(f.getTextContent())):e=!1,e&&g.remove();d.selectEnd()}} | ||
function S(a,b,c){var d=a.getTextContent();let e=ia(d,b);if(e){var f,l;if(e[0]===d)var h=a;else{d=e.index||0;let p=d+e[0].length;0===d?[h,f]=a.splitText(p):[l,h,f]=a.splitText(d,p)}h.setTextContent(e[2]);if(a=b.transformersByTag[e[1]])for(let p of a.format)h.hasFormat(p)||h.toggleFormat(p);h.hasFormat("code")||S(h,b,c);l&&S(l,b,c);f&&S(f,b,c)}else T(a,c)} | ||
function T(a,b){a:for(;a;){for(let c of b){let d=a.getTextContent().match(c.importRegExp);if(!d)continue;let e=d.index||0,f=e+d[0].length,l,h,p;0===e?[l,a]=a.splitText(f):[h,l,p]=a.splitText(e,f);h&&T(h,b);p&&(a=p);c.replace(l,d);continue a}break}} | ||
function ia(a,b){var c=a.match(b.openTagsRegExp);if(null==c)return null;for(let f of c){var d=f.replace(/^\s/,"");c=b.fullMatchRegExpByTag[d];if(null!=c&&(c=a.match(c),d=b.transformersByTag[d],null!=c&&null!=d)){if(!1!==d.intraword)return c;var {index:e=0}=c;d=a[e-1];e=a[e+c[0].length];if(!(d&&!J.test(d)||e&&!J.test(e)))return c}}return null} | ||
function ha(a){let b={},c={},d=[];for(let e of a){({tag:a}=e);b[a]=e;let f=a.replace(/(\*|\^)/g,"\\$1");d.push(f);c[a]=P||Q?new RegExp(`(${f})(?![${f}\\s])(.*?[^${f}\\s])${f}(?!${f})`):new RegExp(`(?<![\\\\${f}])(${f})((\\\\${f})?.*?[^${f}\\s](\\\\${f})?)((?<!\\\\)|(?<=\\\\\\\\))(${f})(?![\\\\${f}])`)}return{fullMatchRegExpByTag:c,openTagsRegExp:new RegExp((P||Q?"":"(?<![\\\\])")+"("+d.join("|")+")","g"),transformersByTag:b}} | ||
function T(a,b,c){let d=c.length;for(;b>=d;b--){let e=b-d;if(U(a,e,c,0,d)&&" "!==a[e+d])return e}return-1}function U(a,b,c,d,e){for(let f=0;f<e;f++)if(a[b+f]!==c[d+f])return!1;return!0} | ||
let V=a=>(b,c,d)=>{d=a(d);d.append(...c);b.replace(d);d.select(0,0)},W=a=>(b,c,d)=>{var e=b.getPreviousSibling();const f=A.$createListItemNode("check"===a?"x"===d[3]:void 0);A.$isListNode(e)&&e.getListType()===a?(e.append(f),b.remove()):(e=A.$createListNode(a,"number"===a?Number(d[2]):void 0),e.append(f),b.replace(e));f.append(...c);f.select(0,0);(b=Math.floor(d[1].length/4))&&f.setIndent(b)},X=(a,b,c)=>{const d=[];var e=a.getChildren();let f=0;for(const p of e)if(A.$isListItemNode(p)){if(1===p.getChildrenSize()&& | ||
(e=p.getFirstChild(),A.$isListNode(e))){d.push(X(e,b,c+1));continue}e=" ".repeat(4*c);var k=a.getListType();k="number"===k?`${a.getStart()+f}. `:"check"===k?`- [${p.getChecked()?"x":" "}] `:"- ";d.push(e+k+b(p));f++}return d.join("\n")},Y={dependencies:[F.HeadingNode],export:(a,b)=>{if(!F.$isHeadingNode(a))return null;const c=Number(a.getTag().slice(1));return"#".repeat(c)+" "+b(a)},regExp:/^(#{1,6})\s/,replace:V(a=>F.$createHeadingNode("h"+a[1].length)),type:"element"},ja={dependencies:[F.QuoteNode], | ||
export:(a,b)=>{if(!F.$isQuoteNode(a))return null;a=b(a).split("\n");b=[];for(const c of a)b.push("> "+c);return b.join("\n")},regExp:/^>\s/,replace:(a,b,c,d)=>{if(d&&(c=a.getPreviousSibling(),F.$isQuoteNode(c))){c.splice(c.getChildrenSize(),0,[h.$createLineBreakNode(),...b]);c.select(0,0);a.remove();return}c=F.$createQuoteNode();c.append(...b);a.replace(c);c.select(0,0)},type:"element"},ka={dependencies:[t.CodeNode],export:a=>{if(!t.$isCodeNode(a))return null;const b=a.getTextContent();return"```"+ | ||
(a.getLanguage()||"")+(b?"\n"+b:"")+"\n```"},regExp:/^```(\w{1,10})?\s/,replace:V(a=>t.$createCodeNode(a?a[1]:void 0)),type:"element"},la={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?X(a,b,0):null,regExp:/^(\s*)[-*+]\s/,replace:W("bullet"),type:"element"},ma={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?X(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:W("check"),type:"element"},na={dependencies:[A.ListNode,A.ListItemNode],export:(a, | ||
b)=>A.$isListNode(a)?X(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:W("number"),type:"element"},oa={format:["code"],tag:"`",type:"text-format"},pa={format:["bold","italic"],tag:"***",type:"text-format"},qa={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},sa={format:["bold"],tag:"**",type:"text-format"},ta={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ua={format:["strikethrough"],tag:"~~",type:"text-format"},va={format:["italic"],tag:"*",type:"text-format"},wa={format:["italic"], | ||
intraword:!1,tag:"_",type:"text-format"},xa={dependencies:[G.LinkNode],export:(a,b,c)=>{if(!G.$isLinkNode(a))return null;b=`[${a.getTextContent()}](${a.getURL()})`;const d=a.getFirstChild();return 1===a.getChildrenSize()&&h.$isTextNode(d)?c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))$/,replace:(a,b)=>{const [,c,d]=b;b=G.$createLinkNode(d);const e=h.$createTextNode(c);e.setFormat(a.getFormat());b.append(e);a.replace(b)},trigger:")",type:"text-match"}, | ||
ya=[Y,ja,ka,la,na],za=[oa,pa,qa,sa,ta,va,wa,ua],Aa=[xa],Z=[...ya,...za,...Aa];exports.$convertFromMarkdownString=function(a,b=Z){return fa(b)(a)};exports.$convertToMarkdownString=function(a=Z){return ba(a)()};exports.BOLD_ITALIC_STAR=pa;exports.BOLD_ITALIC_UNDERSCORE=qa;exports.BOLD_STAR=sa;exports.BOLD_UNDERSCORE=ta;exports.CHECK_LIST=ma;exports.CODE=ka;exports.ELEMENT_TRANSFORMERS=ya;exports.HEADING=Y;exports.INLINE_CODE=oa;exports.ITALIC_STAR=va;exports.ITALIC_UNDERSCORE=wa;exports.LINK=xa; | ||
exports.ORDERED_LIST=na;exports.QUOTE=ja;exports.STRIKETHROUGH=ua;exports.TEXT_FORMAT_TRANSFORMERS=za;exports.TEXT_MATCH_TRANSFORMERS=Aa;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=la; | ||
exports.registerMarkdownShortcuts=function(a,b=Z){let c=I(b),d=H(c.textFormat,({tag:f})=>f[f.length-1]),e=H(c.textMatch,({trigger:f})=>f);for(let f of b)if(b=f.type,("element"===b||"text-match"===b)&&!a.hasNodes(f.dependencies))throw Error("Minified Lexical error #79; visit https://lexical.dev/docs/error?code=79 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a.registerUpdateListener(({tags:f,dirtyLeaves:k,editorState:p,prevEditorState:r})=> | ||
{if(!f.has("historic")){var n=p.read(h.$getSelection);f=r.read(h.$getSelection);if(h.$isRangeSelection(f)&&h.$isRangeSelection(n)&&n.isCollapsed()){r=n.anchor.key;var u=n.anchor.offset,q=p._nodeMap.get(r);h.$isTextNode(q)&&k.has(r)&&(1===u||u===f.anchor.offset+1)&&a.update(()=>{if(!q.hasFormat("code")){var l=q.getParent();if(null!==l&&!t.$isCodeNode(l)){var x=n.anchor.offset;b:{var g=c.element,m=l.getParent();if(h.$isRootOrShadowRoot(m)&&l.getFirstChild()===q&&(m=q.getTextContent()," "===m[x-1]))for(let {regExp:C, | ||
replace:D}of g)if((g=m.match(C))&&g[0].length===x){m=q.getNextSiblings();let [E,ra]=q.splitText(x);E.remove();m=ra?[ra,...m]:m;D(l,m,g,!1);l=!0;break b}l=!1}if(!l){b:{g=q.getTextContent();l=e[g[x-1]];if(null!=l){x<g.length&&(g=g.slice(0,x));for(y of l)if(l=g.match(y.regExp),null!==l){g=l.index||0;m=g+l[0].length;var w=void 0;0===g?[w]=q.splitText(m):[,w]=q.splitText(g,m);w.selectNext(0,0);y.replace(w,l);var y=!0;break b}}y=!1}if(!y)b:{m=q.getTextContent();--x;var v=m[x];if(y=d[v])for(let C of y){var {tag:B}= | ||
C;y=B.length;let D=x-y+1;if(!(1<y&&!U(m,D,B,0,y)||" "===m[D-1])&&(w=m[x+1],!1!==C.intraword||!w||J.test(w))){l=w=q;g=T(m,D,B);for(var z=l;0>g&&(z=z.getPreviousSibling())&&!h.$isLineBreakNode(z);)h.$isTextNode(z)&&(g=z.getTextContent(),l=z,g=T(g,g.length,B));if(!(0>g||l===w&&g+y===D||(B=l.getTextContent(),0<g&&B[g-1]===v||(z=B[g-1],!1===C.intraword&&z&&!J.test(z))))){m=w.getTextContent();m=m.slice(0,D)+m.slice(x+1);w.setTextContent(m);m=l===w?m:B;l.setTextContent(m.slice(0,g)+m.slice(g+y));m=h.$getSelection(); | ||
v=h.$createRangeSelection();h.$setSelection(v);x=x-y*(l===w?2:1)+1;v.anchor.set(l.__key,g,"text");v.focus.set(w.__key,x,"text");for(let E of C.format)v.hasFormat(E)||v.formatText(E);v.anchor.set(v.focus.key,v.focus.offset,v.focus.type);for(let E of C.format)v.hasFormat(E)&&v.toggleFormat(E);h.$isRangeSelection(m)&&(v.format=m.format);break b}}}}}}}})}}})} | ||
function U(a,b,c){let d=c.length;for(;b>=d;b--){let e=b-d;if(V(a,e,c,0,d)&&" "!==a[e+d])return e}return-1}function V(a,b,c,d,e){for(let f=0;f<e;f++)if(a[b+f]!==c[d+f])return!1;return!0} | ||
let W=a=>(b,c,d)=>{d=a(d);d.append(...c);b.replace(d);d.select(0,0)},X=a=>(b,c,d)=>{var e=b.getPreviousSibling();const f=A.$createListItemNode("check"===a?"x"===d[3]:void 0);A.$isListNode(e)&&e.getListType()===a?(e.append(f),b.remove()):(e=A.$createListNode(a,"number"===a?Number(d[2]):void 0),e.append(f),b.replace(e));f.append(...c);f.select(0,0);(b=Math.floor(d[1].length/4))&&f.setIndent(b)},Y=(a,b,c)=>{const d=[];var e=a.getChildren();let f=0;for(const h of e)if(A.$isListItemNode(h)){if(1===h.getChildrenSize()&& | ||
(e=h.getFirstChild(),A.$isListNode(e))){d.push(Y(e,b,c+1));continue}e=" ".repeat(4*c);var l=a.getListType();l="number"===l?`${a.getStart()+f}. `:"check"===l?`- [${h.getChecked()?"x":" "}] `:"- ";d.push(e+l+b(h));f++}return d.join("\n")},ja={dependencies:[F.HeadingNode],export:(a,b)=>{if(!F.$isHeadingNode(a))return null;const c=Number(a.getTag().slice(1));return"#".repeat(c)+" "+b(a)},regExp:/^(#{1,6})\s/,replace:W(a=>F.$createHeadingNode("h"+a[1].length)),type:"element"},ka={dependencies:[F.QuoteNode], | ||
export:(a,b)=>{if(!F.$isQuoteNode(a))return null;a=b(a).split("\n");b=[];for(const c of a)b.push("> "+c);return b.join("\n")},regExp:/^>\s/,replace:(a,b,c,d)=>{if(d&&(c=a.getPreviousSibling(),F.$isQuoteNode(c))){c.splice(c.getChildrenSize(),0,[k.$createLineBreakNode(),...b]);c.select(0,0);a.remove();return}c=F.$createQuoteNode();c.append(...b);a.replace(c);c.select(0,0)},type:"element"},la={dependencies:[t.CodeNode],export:a=>{if(!t.$isCodeNode(a))return null;const b=a.getTextContent();return"```"+ | ||
(a.getLanguage()||"")+(b?"\n"+b:"")+"\n```"},regExp:/^```(\w{1,10})?\s/,replace:W(a=>t.$createCodeNode(a?a[1]:void 0)),type:"element"},ma={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)[-*+]\s/,replace:X("bullet"),type:"element"},na={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:X("check"),type:"element"},oa={dependencies:[A.ListNode,A.ListItemNode],export:(a, | ||
b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:X("number"),type:"element"},pa={format:["code"],tag:"`",type:"text-format"},qa={format:["bold","italic"],tag:"***",type:"text-format"},ra={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},ta={format:["bold"],tag:"**",type:"text-format"},ua={format:["bold"],intraword:!1,tag:"__",type:"text-format"},va={format:["strikethrough"],tag:"~~",type:"text-format"},wa={format:["italic"],tag:"*",type:"text-format"},xa={format:["italic"], | ||
intraword:!1,tag:"_",type:"text-format"},ya={dependencies:[G.LinkNode],export:(a,b,c)=>{if(!G.$isLinkNode(a))return null;b=`[${a.getTextContent()}](${a.getURL()})`;const d=a.getFirstChild();return 1===a.getChildrenSize()&&k.$isTextNode(d)?c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^(]+)\))$/,replace:(a,b)=>{const [,c,d]=b;b=G.$createLinkNode(d);const e=k.$createTextNode(c);e.setFormat(a.getFormat());b.append(e);a.replace(b)},trigger:")",type:"text-match"}, | ||
za=[ja,ka,la,ma,oa],Aa=[pa,qa,ra,ta,ua,wa,xa,va],Ba=[ya],Z=[...za,...Aa,...Ba];exports.$convertFromMarkdownString=function(a,b=Z){return fa(b)(a)};exports.$convertToMarkdownString=function(a=Z){return ba(a)()};exports.BOLD_ITALIC_STAR=qa;exports.BOLD_ITALIC_UNDERSCORE=ra;exports.BOLD_STAR=ta;exports.BOLD_UNDERSCORE=ua;exports.CHECK_LIST=na;exports.CODE=la;exports.ELEMENT_TRANSFORMERS=za;exports.HEADING=ja;exports.INLINE_CODE=pa;exports.ITALIC_STAR=wa;exports.ITALIC_UNDERSCORE=xa;exports.LINK=ya; | ||
exports.ORDERED_LIST=oa;exports.QUOTE=ka;exports.STRIKETHROUGH=va;exports.TEXT_FORMAT_TRANSFORMERS=Aa;exports.TEXT_MATCH_TRANSFORMERS=Ba;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=ma; | ||
exports.registerMarkdownShortcuts=function(a,b=Z){let c=I(b),d=H(c.textFormat,({tag:f})=>f[f.length-1]),e=H(c.textMatch,({trigger:f})=>f);for(let f of b)if(b=f.type,("element"===b||"text-match"===b)&&!a.hasNodes(f.dependencies))throw Error("Minified Lexical error #79; visit https://lexical.dev/docs/error?code=79 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a.registerUpdateListener(({tags:f,dirtyLeaves:l,editorState:h,prevEditorState:p})=> | ||
{if(!f.has("historic")){var r=h.read(k.$getSelection);f=p.read(k.$getSelection);if(k.$isRangeSelection(f)&&k.$isRangeSelection(r)&&r.isCollapsed()){p=r.anchor.key;var y=r.anchor.offset,q=h._nodeMap.get(p);k.$isTextNode(q)&&l.has(p)&&(1===y||y===f.anchor.offset+1)&&a.update(()=>{if(!q.hasFormat("code")){var m=q.getParent();if(null!==m&&!t.$isCodeNode(m)){var w=r.anchor.offset;b:{var g=c.element,n=m.getParent();if(k.$isRootOrShadowRoot(n)&&m.getFirstChild()===q&&(n=q.getTextContent()," "===n[w-1]))for(let {regExp:C, | ||
replace:D}of g)if((g=n.match(C))&&g[0].length===w){n=q.getNextSiblings();let [E,sa]=q.splitText(w);E.remove();n=sa?[sa,...n]:n;D(m,n,g,!1);m=!0;break b}m=!1}if(!m){b:{g=q.getTextContent();m=e[g[w-1]];if(null!=m){w<g.length&&(g=g.slice(0,w));for(x of m)if(m=g.match(x.regExp),null!==m){g=m.index||0;n=g+m[0].length;var v=void 0;0===g?[v]=q.splitText(n):[,v]=q.splitText(g,n);v.selectNext(0,0);x.replace(v,m);var x=!0;break b}}x=!1}if(!x)b:{n=q.getTextContent();--w;var u=n[w];if(x=d[u])for(let C of x){var {tag:B}= | ||
C;x=B.length;let D=w-x+1;if(!(1<x&&!V(n,D,B,0,x)||" "===n[D-1])&&(v=n[w+1],!1!==C.intraword||!v||J.test(v))){m=v=q;g=U(n,D,B);for(var z=m;0>g&&(z=z.getPreviousSibling())&&!k.$isLineBreakNode(z);)k.$isTextNode(z)&&(g=z.getTextContent(),m=z,g=U(g,g.length,B));if(!(0>g||m===v&&g+x===D||(B=m.getTextContent(),0<g&&B[g-1]===u||(z=B[g-1],!1===C.intraword&&z&&!J.test(z))))){n=v.getTextContent();n=n.slice(0,D)+n.slice(w+1);v.setTextContent(n);n=m===v?n:B;m.setTextContent(n.slice(0,g)+n.slice(g+x));n=k.$getSelection(); | ||
u=k.$createRangeSelection();k.$setSelection(u);w=w-x*(m===v?2:1)+1;u.anchor.set(m.__key,g,"text");u.focus.set(v.__key,w,"text");for(let E of C.format)u.hasFormat(E)||u.formatText(E);u.anchor.set(u.focus.key,u.focus.offset,u.focus.type);for(let E of C.format)u.hasFormat(E)&&u.toggleFormat(E);k.$isRangeSelection(n)&&(u.format=n.format);break b}}}}}}}})}}})} |
@@ -11,14 +11,14 @@ { | ||
"license": "MIT", | ||
"version": "0.5.1-next.1", | ||
"version": "0.5.1-next.2", | ||
"main": "LexicalMarkdown.js", | ||
"peerDependencies": { | ||
"lexical": "0.5.1-next.1" | ||
"lexical": "0.5.1-next.2" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.5.1-next.1", | ||
"@lexical/code": "0.5.1-next.1", | ||
"@lexical/text": "0.5.1-next.1", | ||
"@lexical/rich-text": "0.5.1-next.1", | ||
"@lexical/list": "0.5.1-next.1", | ||
"@lexical/link": "0.5.1-next.1" | ||
"@lexical/utils": "0.5.1-next.2", | ||
"@lexical/code": "0.5.1-next.2", | ||
"@lexical/text": "0.5.1-next.2", | ||
"@lexical/rich-text": "0.5.1-next.2", | ||
"@lexical/list": "0.5.1-next.2", | ||
"@lexical/link": "0.5.1-next.2" | ||
}, | ||
@@ -25,0 +25,0 @@ "repository": { |
@@ -82,4 +82,4 @@ # `@lexical/markdown` | ||
- `ELEMENT_TRANSFORMERS` - all built-in element transformers | ||
- `TEXT_FORMAT_TRANSFORMERS` - all built-in text format trasnformers | ||
- `TEXT_MATCH_TRANSFORMERS` - all built-in text match trasnformers | ||
- `TEXT_FORMAT_TRANSFORMERS` - all built-in text format transformers | ||
- `TEXT_MATCH_TRANSFORMERS` - all built-in text match transformers | ||
@@ -86,0 +86,0 @@ Transformers are explicitly passed to markdown API allowing application-specific subset of markdown or custom transformers. |
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
62013
1104
+ Added@lexical/clipboard@0.5.1-next.2(transitive)
+ Added@lexical/code@0.5.1-next.2(transitive)
+ Added@lexical/html@0.5.1-next.2(transitive)
+ Added@lexical/link@0.5.1-next.2(transitive)
+ Added@lexical/list@0.5.1-next.2(transitive)
+ Added@lexical/rich-text@0.5.1-next.2(transitive)
+ Added@lexical/selection@0.5.1-next.2(transitive)
+ Added@lexical/table@0.5.1-next.2(transitive)
+ Added@lexical/text@0.5.1-next.2(transitive)
+ Added@lexical/utils@0.5.1-next.2(transitive)
+ Addedlexical@0.5.1-next.2(transitive)
- Removed@lexical/clipboard@0.5.1-next.1(transitive)
- Removed@lexical/code@0.5.1-next.1(transitive)
- Removed@lexical/html@0.5.1-next.1(transitive)
- Removed@lexical/link@0.5.1-next.1(transitive)
- Removed@lexical/list@0.5.1-next.1(transitive)
- Removed@lexical/rich-text@0.5.1-next.1(transitive)
- Removed@lexical/selection@0.5.1-next.1(transitive)
- Removed@lexical/table@0.5.1-next.1(transitive)
- Removed@lexical/text@0.5.1-next.1(transitive)
- Removed@lexical/utils@0.5.1-next.1(transitive)
- Removedlexical@0.5.1-next.1(transitive)
Updated@lexical/code@0.5.1-next.2
Updated@lexical/link@0.5.1-next.2
Updated@lexical/list@0.5.1-next.2
Updated@lexical/text@0.5.1-next.2
Updated@lexical/utils@0.5.1-next.2