@lexical/markdown
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -202,2 +202,20 @@ /** | ||
*/ | ||
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'; | ||
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null; | ||
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform); | ||
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent); | ||
CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false; | ||
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent); | ||
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; // Keep these in case we need to use them in the future. | ||
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform); | ||
// export const IS_CHROME: boolean = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent); | ||
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode; | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
const MARKDOWN_EMPTY_LINE_REG_EXP = /^\s{0,3}$/; | ||
@@ -461,2 +479,3 @@ const CODE_BLOCK_REG_EXP = /^```(\w{1,10})?\s?$/; | ||
const openTagsRegExp = []; | ||
const escapeRegExp = `(?<![\\\\])`; | ||
@@ -470,3 +489,8 @@ for (const transformer of textTransformers) { | ||
openTagsRegExp.push(tagRegExp); | ||
fullMatchRegExpByTag[tag] = new RegExp(`(${tagRegExp})(?![${tagRegExp}\\s])(.*?[^${tagRegExp}\\s])${tagRegExp}(?!${tagRegExp})`); | ||
if (IS_SAFARI || IS_IOS) { | ||
fullMatchRegExpByTag[tag] = new RegExp(`(${tagRegExp})(?![${tagRegExp}\\s])(.*?[^${tagRegExp}\\s])${tagRegExp}(?!${tagRegExp})`); | ||
} else { | ||
fullMatchRegExpByTag[tag] = new RegExp(`(?<![\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)((?<!\\\\)|(?<=\\\\\\\\))(${tagRegExp})(?![\\\\${tagRegExp}])`); | ||
} | ||
} | ||
@@ -478,3 +502,3 @@ | ||
// Reg exp to find opening tags | ||
openTagsRegExp: new RegExp('(' + openTagsRegExp.join('|') + ')', 'g'), | ||
openTagsRegExp: new RegExp((IS_SAFARI || IS_IOS ? '' : `${escapeRegExp}`) + '(' + openTagsRegExp.join('|') + ')', 'g'), | ||
transformersByTag | ||
@@ -495,3 +519,3 @@ }; | ||
if (!lexical.$isRootNode(grandParentNode) || parentNode.getFirstChild() !== anchorNode) { | ||
if (!lexical.$isRootOrShadowRoot(grandParentNode) || parentNode.getFirstChild() !== anchorNode) { | ||
return false; | ||
@@ -801,3 +825,3 @@ } | ||
const replaceWithBlock = createNode => { | ||
const createBlockNode = createNode => { | ||
return (parentNode, children, match) => { | ||
@@ -877,3 +901,3 @@ const node = createNode(match); | ||
regExp: /^(#{1,6})\s/, | ||
replace: replaceWithBlock(match => { | ||
replace: createBlockNode(match => { | ||
const tag = 'h' + match[1].length; | ||
@@ -931,3 +955,3 @@ return richText.$createHeadingNode(tag); | ||
regExp: /^```(\w{1,10})?\s/, | ||
replace: replaceWithBlock(match => { | ||
replace: createBlockNode(match => { | ||
return code.$createCodeNode(match ? match[1] : undefined); | ||
@@ -934,0 +958,0 @@ }), |
@@ -10,21 +10,24 @@ /** | ||
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)}let da=/^\s{0,3}$/,O=/^```(\w{1,10})?\s?$/; | ||
function ea(a){let b=I(a),c=fa(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(O);if(u)for(var q=r,l=p.length;++q<l;)if(p[q].match(O)){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}P(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)&&da.test(f.getTextContent())):e=!1,e&&g.remove();d.selectEnd()}} | ||
function P(a,b,c){let d=a.getTextContent(),e=ha(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")||P(f,b,c);n&&P(n,b,c);r&&P(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 ha(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={},c={},d=[];for(let e of a){({tag:a}=e);b[a]=e;let f=a.replace(/(\*|\^)/g,"\\$1");d.push(f);c[a]=new RegExp(`(${f})(?![${f}\\s])(.*?[^${f}\\s])${f}(?!${f})`)}return{fullMatchRegExpByTag:c,openTagsRegExp:new RegExp("("+d.join("|")+")","g"),transformersByTag:b}}function Q(a,b,c){let d=c.length;for(;b>=d;b--){let e=b-d;if(R(a,e,c,0,d)&&" "!==a[e+d])return e}return-1}function R(a,b,c,d,e){for(let f=0;f<e;f++)if(a[b+f]!==c[d+f])return!1;return!0} | ||
let S=a=>(b,c,d)=>{d=a(d);d.append(...c);b.replace(d);d.select(0,0)},T=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)},U=(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(U(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")},V={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:S(a=>F.$createHeadingNode("h"+a[1].length)),type:"element"},W={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"},X={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:S(a=>t.$createCodeNode(a?a[1]:void 0)),type:"element"},Y={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)[-*+]\s/,replace:T("bullet"),type:"element"},ia={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:T("check"),type:"element"},ja={dependencies:[A.ListNode,A.ListItemNode],export:(a, | ||
b)=>A.$isListNode(a)?U(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:T("number"),type:"element"},ka={format:["code"],tag:"`",type:"text-format"},la={format:["bold","italic"],tag:"***",type:"text-format"},ma={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},na={format:["bold"],tag:"**",type:"text-format"},pa={format:["bold"],intraword:!1,tag:"__",type:"text-format"},qa={format:["strikethrough"],tag:"~~",type:"text-format"},ra={format:["italic"],tag:"*",type:"text-format"},sa={format:["italic"], | ||
intraword:!1,tag:"_",type:"text-format"},ta={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"}, | ||
ua=[V,W,X,Y,ja],va=[ka,la,ma,na,pa,ra,sa,qa],wa=[ta],Z=[...ua,...va,...wa];exports.$convertFromMarkdownString=function(a,b=Z){return ea(b)(a)};exports.$convertToMarkdownString=function(a=Z){return ba(a)()};exports.BOLD_ITALIC_STAR=la;exports.BOLD_ITALIC_UNDERSCORE=ma;exports.BOLD_STAR=na;exports.BOLD_UNDERSCORE=pa;exports.CHECK_LIST=ia;exports.CODE=X;exports.ELEMENT_TRANSFORMERS=ua;exports.HEADING=V;exports.INLINE_CODE=ka;exports.ITALIC_STAR=ra;exports.ITALIC_UNDERSCORE=sa;exports.LINK=ta; | ||
exports.ORDERED_LIST=ja;exports.QUOTE=W;exports.STRIKETHROUGH=qa;exports.TEXT_FORMAT_TRANSFORMERS=va;exports.TEXT_MATCH_TRANSFORMERS=wa;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=Y; | ||
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)} | ||
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 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.$isRootNode(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,oa]=q.splitText(x);E.remove();m=oa?[oa,...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&&!R(m,D,B,0,y)||" "===m[D-1])&&(w=m[x+1],!1!==C.intraword||!w||J.test(w))){l=w=q;g=Q(m,D,B);for(var z=l;0>g&&(z=z.getPreviousSibling())&&!h.$isLineBreakNode(z);)h.$isTextNode(z)&&(g=z.getTextContent(),l=z,g=Q(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(); | ||
{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}}}}}}}})}}})} |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import type { ElementNode, Klass, LexicalNode, TextFormatType, TextNode } from 'lexical'; | ||
import { ElementNode, Klass, LexicalNode, TextFormatType, TextNode } from 'lexical'; | ||
export declare type Transformer = ElementTransformer | TextFormatTransformer | TextMatchTransformer; | ||
@@ -11,0 +11,0 @@ export declare type ElementTransformer = { |
@@ -11,14 +11,14 @@ { | ||
"license": "MIT", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "LexicalMarkdown.js", | ||
"peerDependencies": { | ||
"lexical": "0.4.1" | ||
"lexical": "0.5.0" | ||
}, | ||
"dependencies": { | ||
"@lexical/utils": "0.4.1", | ||
"@lexical/code": "0.4.1", | ||
"@lexical/text": "0.4.1", | ||
"@lexical/rich-text": "0.4.1", | ||
"@lexical/list": "0.4.1", | ||
"@lexical/link": "0.4.1" | ||
"@lexical/utils": "0.5.0", | ||
"@lexical/code": "0.5.0", | ||
"@lexical/text": "0.5.0", | ||
"@lexical/rich-text": "0.5.0", | ||
"@lexical/list": "0.5.0", | ||
"@lexical/link": "0.5.0" | ||
}, | ||
@@ -25,0 +25,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
61459
1090
+ Added@lexical/clipboard@0.5.0(transitive)
+ Added@lexical/code@0.5.0(transitive)
+ Added@lexical/html@0.5.0(transitive)
+ Added@lexical/link@0.5.0(transitive)
+ Added@lexical/list@0.5.0(transitive)
+ Added@lexical/rich-text@0.5.0(transitive)
+ Added@lexical/selection@0.5.0(transitive)
+ Added@lexical/table@0.5.0(transitive)
+ Added@lexical/text@0.5.0(transitive)
+ Added@lexical/utils@0.5.0(transitive)
+ Addedlexical@0.5.0(transitive)
- Removed@lexical/clipboard@0.4.1(transitive)
- Removed@lexical/code@0.4.1(transitive)
- Removed@lexical/html@0.4.1(transitive)
- Removed@lexical/link@0.4.1(transitive)
- Removed@lexical/list@0.4.1(transitive)
- Removed@lexical/rich-text@0.4.1(transitive)
- Removed@lexical/selection@0.4.1(transitive)
- Removed@lexical/table@0.4.1(transitive)
- Removed@lexical/text@0.4.1(transitive)
- Removed@lexical/utils@0.4.1(transitive)
- Removedlexical@0.4.1(transitive)
Updated@lexical/code@0.5.0
Updated@lexical/link@0.5.0
Updated@lexical/list@0.5.0
Updated@lexical/rich-text@0.5.0
Updated@lexical/text@0.5.0
Updated@lexical/utils@0.5.0