@lexical/markdown
Advanced tools
Comparing version 0.18.1-nightly.20241016.0 to 0.18.1-nightly.20241017.0
@@ -290,7 +290,9 @@ /** | ||
function $importMultiline(lines, startLineIndex, multilineElementTransformers, rootNode) { | ||
for (const { | ||
regExpStart, | ||
regExpEnd, | ||
replace | ||
} of multilineElementTransformers) { | ||
for (const transformer of multilineElementTransformers) { | ||
const { | ||
handleImportAfterStartMatch, | ||
regExpEnd, | ||
regExpStart, | ||
replace | ||
} = transformer; | ||
const startMatch = lines[startLineIndex].match(regExpStart); | ||
@@ -300,2 +302,16 @@ if (!startMatch) { | ||
} | ||
if (handleImportAfterStartMatch) { | ||
const result = handleImportAfterStartMatch({ | ||
lines, | ||
rootNode, | ||
startLineIndex, | ||
startMatch, | ||
transformer | ||
}); | ||
if (result === null) { | ||
continue; | ||
} else if (result) { | ||
return result; | ||
} | ||
} | ||
const regexpEndRegex = typeof regExpEnd === 'object' && 'regExp' in regExpEnd ? regExpEnd.regExp : regExpEnd; | ||
@@ -302,0 +318,0 @@ const isEndOptional = regExpEnd && typeof regExpEnd === 'object' && 'optional' in regExpEnd ? regExpEnd.optional : !regExpEnd; |
@@ -9,35 +9,35 @@ /** | ||
'use strict';var n=require("lexical"),x=require("@lexical/list"),E=require("@lexical/rich-text"),aa=require("@lexical/utils"),F=require("@lexical/code"),G=require("@lexical/link");function H(a,c){let b={};for(let f of a)(a=c(f))&&(b[a]?b[a].push(f):b[a]=[f]);return b}function I(a){a=H(a,c=>c.type);return{element:a.element||[],multilineElement:a["multiline-element"]||[],textFormat:a["text-format"]||[],textMatch:a["text-match"]||[]}}let J=/[!-/:-@[-`{-~\s]/,ba=/^\s{0,3}$/; | ||
function K(a){if(!n.$isParagraphNode(a))return!1;let c=a.getFirstChild();return null==c||1===a.getChildrenSize()&&n.$isTextNode(c)&&ba.test(c.getTextContent())}function ca(a,c=!1){let b=I(a),f=[...b.multilineElement,...b.element],d=!c,e=b.textFormat.filter(g=>1===g.format.length);return g=>{let m=[];g=(g||n.$getRoot()).getChildren();for(let k=0;k<g.length;k++){let t=g[k],y=da(t,f,e,b.textMatch);null!=y&&m.push(d&&0<k&&!K(t)&&!K(g[k-1])?"\n".concat(y):y)}return m.join("\n")}} | ||
function da(a,c,b,f){for(let d of c)if(d.export&&(c=d.export(a,e=>L(e,b,f)),null!=c))return c;return n.$isElementNode(a)?L(a,b,f):n.$isDecoratorNode(a)?a.getTextContent():null} | ||
function L(a,c,b){let f=[];a=a.getChildren();a:for(let d of a){for(let e of b)if(e.export&&(a=e.export(d,g=>L(g,c,b),(g,m)=>M(g,m,c)),null!=a)){f.push(a);continue a}n.$isLineBreakNode(d)?f.push("\n"):n.$isTextNode(d)?f.push(M(d,d.getTextContent(),c)):n.$isElementNode(d)?f.push(L(d,c,b)):n.$isDecoratorNode(d)&&f.push(d.getTextContent())}return f.join("")} | ||
function M(a,c,b){let f=c.trim(),d=f,e=new Set;for(let m of b){b=m.format[0];let k=m.tag;if(O(a,b)&&!e.has(b)){e.add(b);var g=P(a,!0);O(g,b)||(d=k+d);g=P(a,!1);O(g,b)||(d+=k)}}return c.replace(f,()=>d)} | ||
function P(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();b||(a=a.getParentOrThrow(),a.isInline()&&(b=c?a.getPreviousSibling():a.getNextSibling()));for(;b;){if(n.$isElementNode(b)){if(!b.isInline())break;a=c?b.getLastDescendant():b.getFirstDescendant();if(n.$isTextNode(a))return a;b=c?b.getPreviousSibling():b.getNextSibling()}if(n.$isTextNode(b))return b;if(!n.$isElementNode(b))break}return null}function O(a,c){return n.$isTextNode(a)&&a.hasFormat(c)} | ||
'use strict';var p=require("lexical"),z=require("@lexical/list"),E=require("@lexical/rich-text"),aa=require("@lexical/utils"),F=require("@lexical/code"),G=require("@lexical/link");function I(a,c){let b={};for(let f of a)(a=c(f))&&(b[a]?b[a].push(f):b[a]=[f]);return b}function J(a){a=I(a,c=>c.type);return{element:a.element||[],multilineElement:a["multiline-element"]||[],textFormat:a["text-format"]||[],textMatch:a["text-match"]||[]}}let K=/[!-/:-@[-`{-~\s]/,ba=/^\s{0,3}$/; | ||
function L(a){if(!p.$isParagraphNode(a))return!1;let c=a.getFirstChild();return null==c||1===a.getChildrenSize()&&p.$isTextNode(c)&&ba.test(c.getTextContent())}function ca(a,c=!1){let b=J(a),f=[...b.multilineElement,...b.element],d=!c,e=b.textFormat.filter(g=>1===g.format.length);return g=>{let n=[];g=(g||p.$getRoot()).getChildren();for(let h=0;h<g.length;h++){let t=g[h],y=da(t,f,e,b.textMatch);null!=y&&n.push(d&&0<h&&!L(t)&&!L(g[h-1])?"\n".concat(y):y)}return n.join("\n")}} | ||
function da(a,c,b,f){for(let d of c)if(d.export&&(c=d.export(a,e=>M(e,b,f)),null!=c))return c;return p.$isElementNode(a)?M(a,b,f):p.$isDecoratorNode(a)?a.getTextContent():null} | ||
function M(a,c,b){let f=[];a=a.getChildren();a:for(let d of a){for(let e of b)if(e.export&&(a=e.export(d,g=>M(g,c,b),(g,n)=>N(g,n,c)),null!=a)){f.push(a);continue a}p.$isLineBreakNode(d)?f.push("\n"):p.$isTextNode(d)?f.push(N(d,d.getTextContent(),c)):p.$isElementNode(d)?f.push(M(d,c,b)):p.$isDecoratorNode(d)&&f.push(d.getTextContent())}return f.join("")} | ||
function N(a,c,b){let f=c.trim(),d=f,e=new Set;for(let n of b){b=n.format[0];let h=n.tag;if(O(a,b)&&!e.has(b)){e.add(b);var g=P(a,!0);O(g,b)||(d=h+d);g=P(a,!1);O(g,b)||(d+=h)}}return c.replace(f,()=>d)} | ||
function P(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();b||(a=a.getParentOrThrow(),a.isInline()&&(b=c?a.getPreviousSibling():a.getNextSibling()));for(;b;){if(p.$isElementNode(b)){if(!b.isInline())break;a=c?b.getLastDescendant():b.getFirstDescendant();if(p.$isTextNode(a))return a;b=c?b.getPreviousSibling():b.getNextSibling()}if(p.$isTextNode(b))return b;if(!p.$isElementNode(b))break}return null}function O(a,c){return p.$isTextNode(a)&&a.hasFormat(c)} | ||
let Q="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,ea=Q&&"documentMode"in document?document.documentMode:null;Q&&"InputEvent"in window&&!ea?"getTargetRanges"in new window.InputEvent("input"):!1; | ||
let R=Q&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),S=Q&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,fa=Q&&/^(?=.*Chrome).*/i.test(navigator.userAgent),T=Q&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!fa; | ||
function ha(a,c=!1){let b=I(a),f=ia(b.textFormat);return(d,e)=>{d=d.split("\n");let g=d.length;e=e||n.$getRoot();e.clear();for(let u=0;u<g;u++){var m=d[u];a:{var k=d;var t=u,y=b.multilineElement,w=e;for(let {regExpStart:A,regExpEnd:v,replace:C}of y)if(y=k[t].match(A)){var p="object"===typeof v&&"regExp"in v?v.regExp:v,r=v&&"object"===typeof v&&"optional"in v?v.optional:!v,h=t,l=k.length;for(;h<l;){var q=p?k[h].match(p):null;if(q||r&&!(r&&h<l-1))if(q&&t===h&&q.index===y.index)h++;else{p=[];if(q&&t=== | ||
h)p.push(k[t].slice(y[0].length,-q[0].length));else for(r=t;r<=h;r++)r===t?(l=k[r].slice(y[0].length),p.push(l)):r===h&&q?(l=k[r].slice(0,-q[0].length),p.push(l)):p.push(k[r]);if(!1!==C(w,null,y,q,p,!0)){k=[!0,h];break a}break}else h++}}k=[!1,t]}let [z,D]=k;if(z)u=D;else{k=m;h=e;q=b.element;t=f;w=b.textMatch;y=n.$createTextNode(k);m=n.$createParagraphNode();m.append(y);h.append(m);for(let {regExp:A,replace:v}of q)if(h=k.match(A))if(y.setTextContent(k.slice(h[0].length)),!1!==v(m,[y],h,!0))break;U(y, | ||
t,w);m.isAttached()&&0<k.length&&(k=m.getPreviousSibling(),n.$isParagraphNode(k)||E.$isQuoteNode(k)||x.$isListNode(k))&&(t=k,x.$isListNode(k)&&(k=k.getLastDescendant(),t=null==k?null:aa.$findMatchingParent(k,x.$isListItemNode)),null!=t&&0<t.getTextContentSize()&&(t.splice(t.getChildrenSize(),0,[n.$createLineBreakNode(),...m.getChildren()]),m.remove()))}}d=e.getChildren();for(let u of d)!c&&K(u)&&1<e.getChildrenSize()&&u.remove();null!==n.$getSelection()&&e.selectStart()}} | ||
function U(a,c,b){var f=a.getTextContent();let d=ja(f,c);if(d){var e,g;if(d[0]===f)var m=a;else{f=d.index||0;let k=f+d[0].length;0===f?[m,e]=a.splitText(k):[g,m,e]=a.splitText(f,k)}m.setTextContent(d[2]);if(a=c.transformersByTag[d[1]])for(let k of a.format)m.hasFormat(k)||m.toggleFormat(k);m.hasFormat("code")||U(m,c,b);g&&U(g,c,b);e&&U(e,c,b)}else ka(a,b)} | ||
function ka(a,c){a:for(;a;){for(let b of c){if(!b.replace||!b.importRegExp)continue;let f=a.getTextContent().match(b.importRegExp);if(!f)continue;let d=f.index||0,e=d+f[0].length,g,m;0===d?[g,a]=a.splitText(e):[,g,m]=a.splitText(d,e);m&&ka(m,c);b.replace(g,f);continue a}break}} | ||
function ja(a,c){var b=a.match(c.openTagsRegExp);if(null==b)return null;for(let e of b){var f=e.replace(/^\s/,"");b=c.fullMatchRegExpByTag[f];if(null!=b&&(b=a.match(b),f=c.transformersByTag[f],null!=b&&null!=f)){if(!1!==f.intraword)return b;var {index:d=0}=b;f=a[d-1];d=a[d+b[0].length];if(!(f&&!J.test(f)||d&&!J.test(d)))return b}}return null} | ||
function ha(a,c=!1){let b=J(a),f=ia(b.textFormat);return(d,e)=>{d=d.split("\n");let g=d.length;e=e||p.$getRoot();e.clear();for(let u=0;u<g;u++){var n=d[u];a:{var h=d;var t=u,y=b.multilineElement,w=e;for(var q of y){let {handleImportAfterStartMatch:B,regExpEnd:x,regExpStart:A,replace:H}=q;if(y=h[t].match(A)){if(B){var m=B({lines:h,rootNode:w,startLineIndex:t,startMatch:y,transformer:q});if(null===m)continue;else if(m){h=m;break a}}var l="object"===typeof x&&"regExp"in x?x.regExp:x,k=x&&"object"=== | ||
typeof x&&"optional"in x?x.optional:!x;m=t;for(var r=h.length;m<r;){var v=l?h[m].match(l):null;if(v||k&&!(k&&m<r-1))if(v&&t===m&&v.index===y.index)m++;else{l=[];if(v&&t===m)l.push(h[t].slice(y[0].length,-v[0].length));else for(k=t;k<=m;k++)k===t?(r=h[k].slice(y[0].length),l.push(r)):k===m&&v?(r=h[k].slice(0,-v[0].length),l.push(r)):l.push(h[k]);if(!1!==H(w,null,y,v,l,!0)){h=[!0,m];break a}break}else m++}}}h=[!1,t]}let [D,C]=h;if(D)u=C;else{h=n;m=e;v=b.element;t=f;w=b.textMatch;y=p.$createTextNode(h); | ||
n=p.$createParagraphNode();n.append(y);m.append(n);for(let {regExp:B,replace:x}of v)if(m=h.match(B))if(y.setTextContent(h.slice(m[0].length)),!1!==x(n,[y],m,!0))break;U(y,t,w);n.isAttached()&&0<h.length&&(h=n.getPreviousSibling(),p.$isParagraphNode(h)||E.$isQuoteNode(h)||z.$isListNode(h))&&(t=h,z.$isListNode(h)&&(h=h.getLastDescendant(),t=null==h?null:aa.$findMatchingParent(h,z.$isListItemNode)),null!=t&&0<t.getTextContentSize()&&(t.splice(t.getChildrenSize(),0,[p.$createLineBreakNode(),...n.getChildren()]), | ||
n.remove()))}}q=e.getChildren();for(let u of q)!c&&L(u)&&1<e.getChildrenSize()&&u.remove();null!==p.$getSelection()&&e.selectStart()}}function U(a,c,b){var f=a.getTextContent();let d=ja(f,c);if(d){var e,g;if(d[0]===f)var n=a;else{f=d.index||0;let h=f+d[0].length;0===f?[n,e]=a.splitText(h):[g,n,e]=a.splitText(f,h)}n.setTextContent(d[2]);if(a=c.transformersByTag[d[1]])for(let h of a.format)n.hasFormat(h)||n.toggleFormat(h);n.hasFormat("code")||U(n,c,b);g&&U(g,c,b);e&&U(e,c,b)}else ka(a,b)} | ||
function ka(a,c){a:for(;a;){for(let b of c){if(!b.replace||!b.importRegExp)continue;let f=a.getTextContent().match(b.importRegExp);if(!f)continue;let d=f.index||0,e=d+f[0].length,g,n;0===d?[g,a]=a.splitText(e):[,g,n]=a.splitText(d,e);n&&ka(n,c);b.replace(g,f);continue a}break}} | ||
function ja(a,c){var b=a.match(c.openTagsRegExp);if(null==b)return null;for(let e of b){var f=e.replace(/^\s/,"");b=c.fullMatchRegExpByTag[f];if(null!=b&&(b=a.match(b),f=c.transformersByTag[f],null!=b&&null!=f)){if(!1!==f.intraword)return b;var {index:d=0}=b;f=a[d-1];d=a[d+b[0].length];if(!(f&&!K.test(f)||d&&!K.test(d)))return b}}return null} | ||
function ia(a){let c={},b={},f=[];for(let d of a){({tag:a}=d);c[a]=d;let e=a.replace(/(\*|\^|\+)/g,"\\$1");f.push(e);b[a]=R||S||T?new RegExp(`(${e})(?![${e}\\s])(.*?[^${e}\\s])${e}(?!${e})`):new RegExp(`(?<![\\\\${e}])(${e})((\\\\${e})?.*?[^${e}\\s](\\\\${e})?)((?<!\\\\)|(?<=\\\\\\\\))(${e})(?![\\\\${e}])`)}return{fullMatchRegExpByTag:b,openTagsRegExp:new RegExp((R||S||T?"":"(?<![\\\\])")+"("+f.join("|")+")","g"),transformersByTag:c}}var la; | ||
function V(a){let c=new URLSearchParams;c.append("code",a);for(let b=1;b<arguments.length;b++)c.append("v",arguments[b]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${c} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}la=V&&V.__esModule&&Object.prototype.hasOwnProperty.call(V,"default")?V["default"]:V; | ||
function ma(a,c,b){let f=b.length;for(;c>=f;c--){let d=c-f;if(na(a,d,b,0,f)&&" "!==a[d+f])return d}return-1}function na(a,c,b,f,d){for(let e=0;e<d;e++)if(a[c+e]!==b[f+e])return!1;return!0} | ||
let oa=/^(\s*)(\d{1,})\.\s/,pa=/^(\s*)[-*+]\s/,qa=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,W=/^(#{1,6})\s/,ra=/^>\s/,sa=/^[ \t]*```(\w+)?/,ta=/[ \t]*```$/,ua=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,va=/^(?:\|)(.+)(?:\|)\s?$/,wa=/^(\| ?:?-*:? ?)+\|\s?$/,xa=a=>(c,b,f)=>{f=a(f);f.append(...b);c.replace(f);f.select(0,0)},X=a=>(c,b,f)=>{var d=c.getPreviousSibling(),e=c.getNextSibling();const g=x.$createListItemNode("check"===a?"x"===f[3]:void 0);x.$isListNode(e)&&e.getListType()===a?(d=e.getFirstChild(), | ||
null!==d?d.insertBefore(g):e.append(g),c.remove()):x.$isListNode(d)&&d.getListType()===a?(d.append(g),c.remove()):(e=x.$createListNode(a,"number"===a?Number(f[2]):void 0),e.append(g),c.replace(e));g.append(...b);g.select(0,0);b=f[1];c=b.match(/\t/g);b=b.match(/ /g);f=0;c&&(f+=c.length);b&&(f+=Math.floor(b.length/4));(c=f)&&g.setIndent(c)},Y=(a,c,b)=>{const f=[];var d=a.getChildren();let e=0;for(const m of d)if(x.$isListItemNode(m)){if(1===m.getChildrenSize()&&(d=m.getFirstChild(),x.$isListNode(d))){f.push(Y(d, | ||
c,b+1));continue}d=" ".repeat(4*b);var g=a.getListType();g="number"===g?`${a.getStart()+e}. `:"check"===g?`- [${m.getChecked()?"x":" "}] `:"- ";f.push(d+g+c(m));e++}return f.join("\n")},ya={dependencies:[E.HeadingNode],export:(a,c)=>{if(!E.$isHeadingNode(a))return null;const b=Number(a.getTag().slice(1));return"#".repeat(b)+" "+c(a)},regExp:W,replace:xa(a=>E.$createHeadingNode("h"+a[1].length)),type:"element"},za={dependencies:[E.QuoteNode],export:(a,c)=>{if(!E.$isQuoteNode(a))return null;a=c(a).split("\n"); | ||
c=[];for(const b of a)c.push("> "+b);return c.join("\n")},regExp:ra,replace:(a,c,b,f)=>{if(f&&(b=a.getPreviousSibling(),E.$isQuoteNode(b))){b.splice(b.getChildrenSize(),0,[n.$createLineBreakNode(),...c]);b.select(0,0);a.remove();return}b=E.$createQuoteNode();b.append(...c);a.replace(b);b.select(0,0)},type:"element"},Aa={dependencies:[F.CodeNode],export:a=>{if(!F.$isCodeNode(a))return null;const c=a.getTextContent();return"```"+(a.getLanguage()||"")+(c?"\n"+c:"")+"\n```"},regExpEnd:{optional:!0,regExp:ta}, | ||
regExpStart:sa,replace:(a,c,b,f,d,e)=>{if(!c&&d){if(1===d.length)f?(c=F.$createCodeNode(),b=b[1]+d[0]):(c=F.$createCodeNode(b[1]),b=d[0].startsWith(" ")?d[0].slice(1):d[0]);else{c=F.$createCodeNode(b[1]);if(0===d[0].trim().length)for(;0<d.length&&!d[0].length;)d.shift();else d[0]=d[0].startsWith(" ")?d[0].slice(1):d[0];for(;0<d.length&&!d[d.length-1].length;)d.pop();b=d.join("\n")}b=n.$createTextNode(b);c.append(b);a.append(c)}else c&&xa(g=>F.$createCodeNode(g?g[1]:void 0))(a,c,b,e)},type:"multiline-element"}, | ||
Ba={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:pa,replace:X("bullet"),type:"element"},Ca={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:qa,replace:X("check"),type:"element"},Da={dependencies:[x.ListNode,x.ListItemNode],export:(a,c)=>x.$isListNode(a)?Y(a,c,0):null,regExp:oa,replace:X("number"),type:"element"},Ea={format:["code"],tag:"`",type:"text-format"},Ga={format:["highlight"],tag:"==",type:"text-format"}, | ||
let oa=/^(\s*)(\d{1,})\.\s/,pa=/^(\s*)[-*+]\s/,qa=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,W=/^(#{1,6})\s/,ra=/^>\s/,sa=/^[ \t]*```(\w+)?/,ta=/[ \t]*```$/,ua=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,va=/^(?:\|)(.+)(?:\|)\s?$/,wa=/^(\| ?:?-*:? ?)+\|\s?$/,xa=a=>(c,b,f)=>{f=a(f);f.append(...b);c.replace(f);f.select(0,0)},X=a=>(c,b,f)=>{var d=c.getPreviousSibling(),e=c.getNextSibling();const g=z.$createListItemNode("check"===a?"x"===f[3]:void 0);z.$isListNode(e)&&e.getListType()===a?(d=e.getFirstChild(), | ||
null!==d?d.insertBefore(g):e.append(g),c.remove()):z.$isListNode(d)&&d.getListType()===a?(d.append(g),c.remove()):(e=z.$createListNode(a,"number"===a?Number(f[2]):void 0),e.append(g),c.replace(e));g.append(...b);g.select(0,0);b=f[1];c=b.match(/\t/g);b=b.match(/ /g);f=0;c&&(f+=c.length);b&&(f+=Math.floor(b.length/4));(c=f)&&g.setIndent(c)},Y=(a,c,b)=>{const f=[];var d=a.getChildren();let e=0;for(const n of d)if(z.$isListItemNode(n)){if(1===n.getChildrenSize()&&(d=n.getFirstChild(),z.$isListNode(d))){f.push(Y(d, | ||
c,b+1));continue}d=" ".repeat(4*b);var g=a.getListType();g="number"===g?`${a.getStart()+e}. `:"check"===g?`- [${n.getChecked()?"x":" "}] `:"- ";f.push(d+g+c(n));e++}return f.join("\n")},ya={dependencies:[E.HeadingNode],export:(a,c)=>{if(!E.$isHeadingNode(a))return null;const b=Number(a.getTag().slice(1));return"#".repeat(b)+" "+c(a)},regExp:W,replace:xa(a=>E.$createHeadingNode("h"+a[1].length)),type:"element"},za={dependencies:[E.QuoteNode],export:(a,c)=>{if(!E.$isQuoteNode(a))return null;a=c(a).split("\n"); | ||
c=[];for(const b of a)c.push("> "+b);return c.join("\n")},regExp:ra,replace:(a,c,b,f)=>{if(f&&(b=a.getPreviousSibling(),E.$isQuoteNode(b))){b.splice(b.getChildrenSize(),0,[p.$createLineBreakNode(),...c]);b.select(0,0);a.remove();return}b=E.$createQuoteNode();b.append(...c);a.replace(b);b.select(0,0)},type:"element"},Aa={dependencies:[F.CodeNode],export:a=>{if(!F.$isCodeNode(a))return null;const c=a.getTextContent();return"```"+(a.getLanguage()||"")+(c?"\n"+c:"")+"\n```"},regExpEnd:{optional:!0,regExp:ta}, | ||
regExpStart:sa,replace:(a,c,b,f,d,e)=>{if(!c&&d){if(1===d.length)f?(c=F.$createCodeNode(),b=b[1]+d[0]):(c=F.$createCodeNode(b[1]),b=d[0].startsWith(" ")?d[0].slice(1):d[0]);else{c=F.$createCodeNode(b[1]);if(0===d[0].trim().length)for(;0<d.length&&!d[0].length;)d.shift();else d[0]=d[0].startsWith(" ")?d[0].slice(1):d[0];for(;0<d.length&&!d[d.length-1].length;)d.pop();b=d.join("\n")}b=p.$createTextNode(b);c.append(b);a.append(c)}else c&&xa(g=>F.$createCodeNode(g?g[1]:void 0))(a,c,b,e)},type:"multiline-element"}, | ||
Ba={dependencies:[z.ListNode,z.ListItemNode],export:(a,c)=>z.$isListNode(a)?Y(a,c,0):null,regExp:pa,replace:X("bullet"),type:"element"},Ca={dependencies:[z.ListNode,z.ListItemNode],export:(a,c)=>z.$isListNode(a)?Y(a,c,0):null,regExp:qa,replace:X("check"),type:"element"},Da={dependencies:[z.ListNode,z.ListItemNode],export:(a,c)=>z.$isListNode(a)?Y(a,c,0):null,regExp:oa,replace:X("number"),type:"element"},Ea={format:["code"],tag:"`",type:"text-format"},Ga={format:["highlight"],tag:"==",type:"text-format"}, | ||
Ha={format:["bold","italic"],tag:"***",type:"text-format"},Ia={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Ja={format:["bold"],tag:"**",type:"text-format"},Ka={format:["bold"],intraword:!1,tag:"__",type:"text-format"},La={format:["strikethrough"],tag:"~~",type:"text-format"},Ma={format:["italic"],tag:"*",type:"text-format"},Na={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Oa={dependencies:[G.LinkNode],export:(a,c,b)=>{if(!G.$isLinkNode(a))return null;c=(c=a.getTitle())? | ||
`[${a.getTextContent()}](${a.getURL()} "${c}")`:`[${a.getTextContent()}](${a.getURL()})`;const f=a.getFirstChild();return 1===a.getChildrenSize()&&n.$isTextNode(f)?b(f,c):c},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(a,c)=>{const [,b,f,d]=c;c=G.$createLinkNode(f,{title:d});const e=n.$createTextNode(b);e.setFormat(a.getFormat());c.append(e);a.replace(c)},trigger:")",type:"text-match"}; | ||
`[${a.getTextContent()}](${a.getURL()} "${c}")`:`[${a.getTextContent()}](${a.getURL()})`;const f=a.getFirstChild();return 1===a.getChildrenSize()&&p.$isTextNode(f)?b(f,c):c},importRegExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[]+)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(a,c)=>{const [,b,f,d]=c;c=G.$createLinkNode(f,{title:d});const e=p.$createTextNode(b);e.setFormat(a.getFormat());c.append(e);a.replace(c)},trigger:")",type:"text-match"}; | ||
function Pa(a,c=!1){a=a.split("\n");let b=!1,f=[];for(let d=0;d<a.length;d++){let e=a[d],g=f[f.length-1];ua.test(e)?f.push(e):sa.test(e)||ta.test(e)?(b=!b,f.push(e)):b?f.push(e):""===e||""===g||!g||W.test(g)||W.test(e)||ra.test(e)||oa.test(e)||pa.test(e)||qa.test(e)||va.test(e)||wa.test(e)||!c?f.push(e):f[f.length-1]=g+e}return f.join("\n")}let Qa=[ya,za,Ba,Da],Ra=[Aa],Sa=[Ea,Ha,Ia,Ja,Ka,Ga,Ma,Na,La],Ta=[Oa],Z=[...Qa,...Ra,...Sa,...Ta]; | ||
exports.$convertFromMarkdownString=function(a,c=Z,b,f=!1,d=!1){a=f?a:Pa(a,d);return ha(c,f)(a,b)};exports.$convertToMarkdownString=function(a=Z,c,b=!1){return ca(a,b)(c)};exports.BOLD_ITALIC_STAR=Ha;exports.BOLD_ITALIC_UNDERSCORE=Ia;exports.BOLD_STAR=Ja;exports.BOLD_UNDERSCORE=Ka;exports.CHECK_LIST=Ca;exports.CODE=Aa;exports.ELEMENT_TRANSFORMERS=Qa;exports.HEADING=ya;exports.HIGHLIGHT=Ga;exports.INLINE_CODE=Ea;exports.ITALIC_STAR=Ma;exports.ITALIC_UNDERSCORE=Na;exports.LINK=Oa; | ||
exports.MULTILINE_ELEMENT_TRANSFORMERS=Ra;exports.ORDERED_LIST=Da;exports.QUOTE=za;exports.STRIKETHROUGH=La;exports.TEXT_FORMAT_TRANSFORMERS=Sa;exports.TEXT_MATCH_TRANSFORMERS=Ta;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=Ba; | ||
exports.registerMarkdownShortcuts=function(a,c=Z){let b=I(c),f=H(b.textFormat,({tag:e})=>e[e.length-1]),d=H(b.textMatch,({trigger:e})=>e);for(let e of c)if(c=e.type,"element"===c||"text-match"===c||"multiline-element"===c){c=e.dependencies;for(let g of c)a.hasNode(g)||la(173,g.getType())}return a.registerUpdateListener(({tags:e,dirtyLeaves:g,editorState:m,prevEditorState:k})=>{if(!e.has("collaboration")&&!e.has("historic")&&!a.isComposing()){var t=m.read(n.$getSelection);e=k.read(n.$getSelection); | ||
if(n.$isRangeSelection(e)&&n.$isRangeSelection(t)&&t.isCollapsed()){k=t.anchor.key;var y=t.anchor.offset,w=m._nodeMap.get(k);!n.$isTextNode(w)||!g.has(k)||1!==y&&y>e.anchor.offset+1||a.update(()=>{if(!w.hasFormat("code")){var p=w.getParent();if(null!==p&&!F.$isCodeNode(p)){var r=t.anchor.offset;b:{var h=b.element;var l=p.getParent();if(n.$isRootOrShadowRoot(l)&&p.getFirstChild()===w&&(l=w.getTextContent()," "===l[r-1]))for(let {regExp:v,replace:C}of h)if((h=l.match(v))&&h[0].length===(h[0].endsWith(" ")? | ||
r:r-1)){var q=w.getNextSiblings();let [B,N]=w.splitText(r);B.remove();q=N?[N,...q]:q;if(!1!==C(p,q,h,!1)){l=!0;break b}}l=!1}if(!l){b:{h=b.multilineElement;l=p.getParent();if(n.$isRootOrShadowRoot(l)&&p.getFirstChild()===w&&(l=w.getTextContent()," "===l[r-1]))for(let {regExpStart:v,replace:C,regExpEnd:B}of h)if(!(B&&!("optional"in B)||B&&"optional"in B&&!B.optional)&&(h=l.match(v))&&h[0].length===(h[0].endsWith(" ")?r:r-1)){q=w.getNextSiblings();let [N,Fa]=w.splitText(r);N.remove();q=Fa?[Fa,...q]: | ||
q;if(!1!==C(p,q,h,null,null,!1)){p=!0;break b}}p=!1}if(!p){b:{l=w.getTextContent();p=d[l[r-1]];if(null!=p){r<l.length&&(l=l.slice(0,r));for(z of p)if(z.replace&&z.regExp&&(p=l.match(z.regExp),null!==p)){l=p.index||0;h=l+p[0].length;var u=void 0;0===l?[u]=w.splitText(h):[,u]=w.splitText(l,h);u.selectNext(0,0);z.replace(u,p);var z=!0;break b}}z=!1}if(!z)b:if(h=w.getTextContent(),--r,q=h[r],z=f[q])for(let v of z){var {tag:D}=v;z=D.length;let C=r-z+1;if(!(1<z&&!na(h,C,D,0,z)||" "===h[C-1])&&(u=h[r+1], | ||
!1!==v.intraword||!u||J.test(u))){p=u=w;l=ma(h,C,D);for(var A=p;0>l&&(A=A.getPreviousSibling())&&!n.$isLineBreakNode(A);)n.$isTextNode(A)&&(l=A.getTextContent(),p=A,l=ma(l,l.length,D));if(!(0>l||p===u&&l+z===C||(D=p.getTextContent(),0<l&&D[l-1]===q||(A=D[l-1],!1===v.intraword&&A&&!J.test(A))))){h=u.getTextContent();h=h.slice(0,C)+h.slice(r+1);u.setTextContent(h);h=p===u?h:D;p.setTextContent(h.slice(0,l)+h.slice(l+z));h=n.$getSelection();q=n.$createRangeSelection();n.$setSelection(q);r=r-z*(p===u? | ||
2:1)+1;q.anchor.set(p.__key,l,"text");q.focus.set(u.__key,r,"text");for(let B of v.format)q.hasFormat(B)||q.formatText(B);q.anchor.set(q.focus.key,q.focus.offset,q.focus.type);for(let B of v.format)q.hasFormat(B)&&q.toggleFormat(B);n.$isRangeSelection(h)&&(q.format=h.format);break b}}}}}}}})}}})} | ||
exports.registerMarkdownShortcuts=function(a,c=Z){let b=J(c),f=I(b.textFormat,({tag:e})=>e[e.length-1]),d=I(b.textMatch,({trigger:e})=>e);for(let e of c)if(c=e.type,"element"===c||"text-match"===c||"multiline-element"===c){c=e.dependencies;for(let g of c)a.hasNode(g)||la(173,g.getType())}return a.registerUpdateListener(({tags:e,dirtyLeaves:g,editorState:n,prevEditorState:h})=>{if(!e.has("collaboration")&&!e.has("historic")&&!a.isComposing()){var t=n.read(p.$getSelection);e=h.read(p.$getSelection); | ||
if(p.$isRangeSelection(e)&&p.$isRangeSelection(t)&&t.isCollapsed()){h=t.anchor.key;var y=t.anchor.offset,w=n._nodeMap.get(h);!p.$isTextNode(w)||!g.has(h)||1!==y&&y>e.anchor.offset+1||a.update(()=>{if(!w.hasFormat("code")){var q=w.getParent();if(null!==q&&!F.$isCodeNode(q)){var m=t.anchor.offset;b:{var l=b.element;var k=q.getParent();if(p.$isRootOrShadowRoot(k)&&q.getFirstChild()===w&&(k=w.getTextContent()," "===k[m-1]))for(let {regExp:B,replace:x}of l)if((l=k.match(B))&&l[0].length===(l[0].endsWith(" ")? | ||
m:m-1)){var r=w.getNextSiblings();let [A,H]=w.splitText(m);A.remove();r=H?[H,...r]:r;if(!1!==x(q,r,l,!1)){k=!0;break b}}k=!1}if(!k){b:{l=b.multilineElement;k=q.getParent();if(p.$isRootOrShadowRoot(k)&&q.getFirstChild()===w&&(k=w.getTextContent()," "===k[m-1]))for(let {regExpStart:B,replace:x,regExpEnd:A}of l)if(!(A&&!("optional"in A)||A&&"optional"in A&&!A.optional)&&(l=k.match(B))&&l[0].length===(l[0].endsWith(" ")?m:m-1)){r=w.getNextSiblings();let [H,Fa]=w.splitText(m);H.remove();r=Fa?[Fa,...r]: | ||
r;if(!1!==x(q,r,l,null,null,!1)){q=!0;break b}}q=!1}if(!q){b:{k=w.getTextContent();q=d[k[m-1]];if(null!=q){m<k.length&&(k=k.slice(0,m));for(u of q)if(u.replace&&u.regExp&&(q=k.match(u.regExp),null!==q)){k=q.index||0;l=k+q[0].length;var v=void 0;0===k?[v]=w.splitText(l):[,v]=w.splitText(k,l);v.selectNext(0,0);u.replace(v,q);var u=!0;break b}}u=!1}if(!u)b:if(l=w.getTextContent(),--m,r=l[m],u=f[r])for(let B of u){var {tag:D}=B;u=D.length;let x=m-u+1;if(!(1<u&&!na(l,x,D,0,u)||" "===l[x-1])&&(v=l[m+1], | ||
!1!==B.intraword||!v||K.test(v))){q=v=w;k=ma(l,x,D);for(var C=q;0>k&&(C=C.getPreviousSibling())&&!p.$isLineBreakNode(C);)p.$isTextNode(C)&&(k=C.getTextContent(),q=C,k=ma(k,k.length,D));if(!(0>k||q===v&&k+u===x||(D=q.getTextContent(),0<k&&D[k-1]===r||(C=D[k-1],!1===B.intraword&&C&&!K.test(C))))){l=v.getTextContent();l=l.slice(0,x)+l.slice(m+1);v.setTextContent(l);l=q===v?l:D;q.setTextContent(l.slice(0,k)+l.slice(k+u));l=p.$getSelection();r=p.$createRangeSelection();p.$setSelection(r);m=m-u*(q===v? | ||
2:1)+1;r.anchor.set(q.__key,k,"text");r.focus.set(v.__key,m,"text");for(let A of B.format)r.hasFormat(A)||r.formatText(A);r.anchor.set(r.focus.key,r.focus.offset,r.focus.type);for(let A of B.format)r.hasFormat(A)&&r.toggleFormat(A);p.$isRangeSelection(l)&&(r.format=l.format);break b}}}}}}}})}}})} |
@@ -32,2 +32,15 @@ /** | ||
export type MultilineElementTransformer = { | ||
/** | ||
* Use this function to manually handle the import process, once the `regExpStart` has matched successfully. | ||
* Without providing this function, the default behavior is to match until `regExpEnd` is found, or until the end of the document if `regExpEnd.optional` is true. | ||
* | ||
* @returns a tuple or null. The first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed. If null is returned, the next multilineElementTransformer will be tried. If undefined is returned, the default behavior will be used. | ||
*/ | ||
handleImportAfterStartMatch?: (args: { | ||
lines: Array<string>; | ||
rootNode: ElementNode; | ||
startLineIndex: number; | ||
startMatch: RegExpMatchArray; | ||
transformer: MultilineElementTransformer; | ||
}) => [boolean, number] | null | undefined; | ||
dependencies: Array<Klass<LexicalNode>>; | ||
@@ -34,0 +47,0 @@ /** |
@@ -11,13 +11,13 @@ { | ||
"license": "MIT", | ||
"version": "0.18.1-nightly.20241016.0", | ||
"version": "0.18.1-nightly.20241017.0", | ||
"main": "LexicalMarkdown.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/code": "0.18.1-nightly.20241016.0", | ||
"@lexical/link": "0.18.1-nightly.20241016.0", | ||
"@lexical/list": "0.18.1-nightly.20241016.0", | ||
"@lexical/rich-text": "0.18.1-nightly.20241016.0", | ||
"@lexical/text": "0.18.1-nightly.20241016.0", | ||
"@lexical/utils": "0.18.1-nightly.20241016.0", | ||
"lexical": "0.18.1-nightly.20241016.0" | ||
"@lexical/code": "0.18.1-nightly.20241017.0", | ||
"@lexical/link": "0.18.1-nightly.20241017.0", | ||
"@lexical/list": "0.18.1-nightly.20241017.0", | ||
"@lexical/rich-text": "0.18.1-nightly.20241017.0", | ||
"@lexical/text": "0.18.1-nightly.20241017.0", | ||
"@lexical/utils": "0.18.1-nightly.20241017.0", | ||
"lexical": "0.18.1-nightly.20241017.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
152191
2867
+ Added@lexical/clipboard@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/code@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/html@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/link@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/list@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/rich-text@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/selection@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/table@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/text@0.18.1-nightly.20241017.0(transitive)
+ Added@lexical/utils@0.18.1-nightly.20241017.0(transitive)
+ Addedlexical@0.18.1-nightly.20241017.0(transitive)
- Removed@lexical/clipboard@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/code@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/html@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/link@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/list@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/rich-text@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/selection@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/table@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/text@0.18.1-nightly.20241016.0(transitive)
- Removed@lexical/utils@0.18.1-nightly.20241016.0(transitive)
- Removedlexical@0.18.1-nightly.20241016.0(transitive)