@lexical/markdown 0.43.0 → 0.43.1-nightly.20260413.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalMarkdown.dev.js +18 -11
- package/LexicalMarkdown.dev.mjs +18 -11
- package/LexicalMarkdown.prod.js +1 -1
- package/LexicalMarkdown.prod.mjs +1 -1
- package/package.json +8 -8
package/LexicalMarkdown.dev.js
CHANGED
|
@@ -301,11 +301,14 @@ function findOutermostTextFormatTransformer(textNode, textFormatTransformersInde
|
|
|
301
301
|
const globalRegex = new RegExp(codeRegex.source, 'g');
|
|
302
302
|
const matches = Array.from(textContent.matchAll(globalRegex));
|
|
303
303
|
for (const match of matches) {
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
// Group 1 captures the character preceding the opening backtick (or an
|
|
305
|
+
// empty string when the span starts at position 0). Offset past it so
|
|
306
|
+
// startIndex points to the backtick itself.
|
|
307
|
+
const startIndex = match.index + match[1].length;
|
|
308
|
+
const endIndex = match.index + match[0].length;
|
|
306
309
|
if (!codeMatch) {
|
|
307
310
|
codeMatch = {
|
|
308
|
-
content: match[
|
|
311
|
+
content: match[3],
|
|
309
312
|
endIndex,
|
|
310
313
|
startIndex,
|
|
311
314
|
tag: '`'
|
|
@@ -871,7 +874,6 @@ function createTextFormatTransformersIndex(textTransformers) {
|
|
|
871
874
|
const transformersByTag = {};
|
|
872
875
|
const fullMatchRegExpByTag = {};
|
|
873
876
|
const openTagsRegExp = [];
|
|
874
|
-
const escapeRegExp = `(?<![\\\\])`;
|
|
875
877
|
for (const transformer of textTransformers) {
|
|
876
878
|
const {
|
|
877
879
|
tag
|
|
@@ -880,24 +882,29 @@ function createTextFormatTransformersIndex(textTransformers) {
|
|
|
880
882
|
const tagRegExp = tag.replace(/(\*|\^|\+)/g, '\\$1');
|
|
881
883
|
openTagsRegExp.push(tagRegExp);
|
|
882
884
|
|
|
883
|
-
// Single-char tag (e.g. "*")
|
|
885
|
+
// Single-char tag (e.g. "*")
|
|
884
886
|
if (tag.length === 1) {
|
|
885
887
|
if (tag === '`') {
|
|
886
|
-
//
|
|
887
|
-
|
|
888
|
+
// Capture the preceding character in group 1 (empty string at start-of-string
|
|
889
|
+
// via the ^ branch) rather than using a negative lookbehind, which is not
|
|
890
|
+
// supported in Safari < 16.4. Consumers must add match[1].length to
|
|
891
|
+
// match.index to find the real start of the span (see importTextFormatTransformer.ts).
|
|
892
|
+
fullMatchRegExpByTag[tag] = new RegExp(`(^|[^\\\\\`])(\`)((?:\\\\\`|[^\`])+?)(\`)(?!\`)`);
|
|
888
893
|
} else {
|
|
889
|
-
fullMatchRegExpByTag[tag] = new RegExp(`(
|
|
894
|
+
fullMatchRegExpByTag[tag] = new RegExp(`(^|[^\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)(${tagRegExp})(?![\\\\${tagRegExp}])`);
|
|
890
895
|
}
|
|
891
896
|
} else {
|
|
892
|
-
// Multi
|
|
893
|
-
fullMatchRegExpByTag[tag] = new RegExp(`(
|
|
897
|
+
// Multi-char tags (e.g. "**")
|
|
898
|
+
fullMatchRegExpByTag[tag] = new RegExp(`(^|[^\\\\])(${tagRegExp})((\\\\${tagRegExp})?.*?[^\\s](\\\\${tagRegExp})?)(${tagRegExp})(?!\\\\)`);
|
|
894
899
|
}
|
|
895
900
|
}
|
|
896
901
|
return {
|
|
897
902
|
// Reg exp to find open tag + content + close tag
|
|
898
903
|
fullMatchRegExpByTag,
|
|
899
904
|
// Regexp to locate *any* potential opening tag (longest first).
|
|
900
|
-
|
|
905
|
+
// The former (?<!\\) escape guard has been removed — the delimiter
|
|
906
|
+
// scanner's isEscaped() check handles escape filtering at match time.
|
|
907
|
+
openTagsRegExp: new RegExp(`(${openTagsRegExp.join('|')})`, 'g'),
|
|
901
908
|
transformersByTag
|
|
902
909
|
};
|
|
903
910
|
}
|
package/LexicalMarkdown.dev.mjs
CHANGED
|
@@ -299,11 +299,14 @@ function findOutermostTextFormatTransformer(textNode, textFormatTransformersInde
|
|
|
299
299
|
const globalRegex = new RegExp(codeRegex.source, 'g');
|
|
300
300
|
const matches = Array.from(textContent.matchAll(globalRegex));
|
|
301
301
|
for (const match of matches) {
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
// Group 1 captures the character preceding the opening backtick (or an
|
|
303
|
+
// empty string when the span starts at position 0). Offset past it so
|
|
304
|
+
// startIndex points to the backtick itself.
|
|
305
|
+
const startIndex = match.index + match[1].length;
|
|
306
|
+
const endIndex = match.index + match[0].length;
|
|
304
307
|
if (!codeMatch) {
|
|
305
308
|
codeMatch = {
|
|
306
|
-
content: match[
|
|
309
|
+
content: match[3],
|
|
307
310
|
endIndex,
|
|
308
311
|
startIndex,
|
|
309
312
|
tag: '`'
|
|
@@ -869,7 +872,6 @@ function createTextFormatTransformersIndex(textTransformers) {
|
|
|
869
872
|
const transformersByTag = {};
|
|
870
873
|
const fullMatchRegExpByTag = {};
|
|
871
874
|
const openTagsRegExp = [];
|
|
872
|
-
const escapeRegExp = `(?<![\\\\])`;
|
|
873
875
|
for (const transformer of textTransformers) {
|
|
874
876
|
const {
|
|
875
877
|
tag
|
|
@@ -878,24 +880,29 @@ function createTextFormatTransformersIndex(textTransformers) {
|
|
|
878
880
|
const tagRegExp = tag.replace(/(\*|\^|\+)/g, '\\$1');
|
|
879
881
|
openTagsRegExp.push(tagRegExp);
|
|
880
882
|
|
|
881
|
-
// Single-char tag (e.g. "*")
|
|
883
|
+
// Single-char tag (e.g. "*")
|
|
882
884
|
if (tag.length === 1) {
|
|
883
885
|
if (tag === '`') {
|
|
884
|
-
//
|
|
885
|
-
|
|
886
|
+
// Capture the preceding character in group 1 (empty string at start-of-string
|
|
887
|
+
// via the ^ branch) rather than using a negative lookbehind, which is not
|
|
888
|
+
// supported in Safari < 16.4. Consumers must add match[1].length to
|
|
889
|
+
// match.index to find the real start of the span (see importTextFormatTransformer.ts).
|
|
890
|
+
fullMatchRegExpByTag[tag] = new RegExp(`(^|[^\\\\\`])(\`)((?:\\\\\`|[^\`])+?)(\`)(?!\`)`);
|
|
886
891
|
} else {
|
|
887
|
-
fullMatchRegExpByTag[tag] = new RegExp(`(
|
|
892
|
+
fullMatchRegExpByTag[tag] = new RegExp(`(^|[^\\\\${tagRegExp}])(${tagRegExp})((\\\\${tagRegExp})?.*?[^${tagRegExp}\\s](\\\\${tagRegExp})?)(${tagRegExp})(?![\\\\${tagRegExp}])`);
|
|
888
893
|
}
|
|
889
894
|
} else {
|
|
890
|
-
// Multi
|
|
891
|
-
fullMatchRegExpByTag[tag] = new RegExp(`(
|
|
895
|
+
// Multi-char tags (e.g. "**")
|
|
896
|
+
fullMatchRegExpByTag[tag] = new RegExp(`(^|[^\\\\])(${tagRegExp})((\\\\${tagRegExp})?.*?[^\\s](\\\\${tagRegExp})?)(${tagRegExp})(?!\\\\)`);
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
899
|
return {
|
|
895
900
|
// Reg exp to find open tag + content + close tag
|
|
896
901
|
fullMatchRegExpByTag,
|
|
897
902
|
// Regexp to locate *any* potential opening tag (longest first).
|
|
898
|
-
|
|
903
|
+
// The former (?<!\\) escape guard has been removed — the delimiter
|
|
904
|
+
// scanner's isEscaped() check handles escape filtering at match time.
|
|
905
|
+
openTagsRegExp: new RegExp(`(${openTagsRegExp.join('|')})`, 'g'),
|
|
899
906
|
transformersByTag
|
|
900
907
|
};
|
|
901
908
|
}
|
package/LexicalMarkdown.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/list"),n=require("@lexical/rich-text"),o=require("@lexical/utils"),r=require("@lexical/code-core"),s=require("@lexical/link");function i(e,t){const n={};for(const o of e){const e=t(o);e&&(n[e]?n[e].push(o):n[e]=[o])}return n}function c(e){const t=i(e,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}const l=/[!-/:-@[-`{-~\s]/,a=/[ \t\n\r\f]/,d=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,f=/^\s{0,3}$/;function g(t){if(!e.$isParagraphNode(t))return!1;const n=t.getFirstChild();return null==n||1===t.getChildrenSize()&&e.$isTextNode(n)&&f.test(n.getTextContent())}function u(e){return e.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}function p(t,n,o,r,s){for(const e of n){if(!e.export)continue;const n=e.export(t,e=>x(e,o,r,void 0,void 0,s));if(null!=n)return n}return e.$isElementNode(t)?x(t,o,r,void 0,void 0,s):e.$isDecoratorNode(t)?t.getTextContent():null}function x(t,n,o,r,s,i=!1){const c=[],l=t.getChildren();r||(r=[]),s||(s=[]);e:for(const t of l){for(const e of o){if(!e.export)continue;const l=e.export(t,e=>x(e,n,o,r,[...s,...r],i),(e,t)=>h(e,t,n,r,s,i));if(null!=l){c.push(l);continue e}}e.$isLineBreakNode(t)?c.push("\n"):e.$isTextNode(t)?c.push(h(t,t.getTextContent(),n,r,s,i)):e.$isElementNode(t)?c.push(x(t,n,o,r,s,i)):e.$isDecoratorNode(t)&&c.push(t.getTextContent())}return c.join("")}function h(e,t,n,o,r,s=!1){let i=t;e.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const c=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],l=c[1],a=c[2],d=c[3],f=""===a;let g="",u="",p="";const x=m(e,!0),h=m(e,!1),T=new Set;for(const t of n){const n=t.format[0],r=t.tag;N(e,n)&&!T.has(n)&&(T.add(n),N(x,n)&&o.find(e=>e.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let t=0;t<o.length;t++){const n=$(e,o[t].format),s=$(h,o[t].format);if(n&&s)continue;const i=[...o];for(;i.length>t;){const e=i.pop();r&&e&&r.find(t=>t.tag===e.tag)||(e&&"string"==typeof e.tag&&(n?s||(p+=e.tag):u+=e.tag),o.pop())}break}return f&&!e.hasFormat("code")?u+i:u+l+g+a+p+d}function m(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e.$isTextNode(o)?o:null}function $(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function N(e,t){return!!$(e,t)&&("code"===t||(!e||!/^\s*$/.test(e.getTextContent())))}function T(e,t){const n=e.getTextContent(),o=t.fullMatchRegExpByTag["`"],r=t.transformersByTag["`"],s=[];let i=null;if(o&&r){const e=new RegExp(o.source,"g"),t=Array.from(n.matchAll(e));for(const e of t){const t=e.index,n=t+e[0].length;i||(i={content:e[2],endIndex:n,startIndex:t,tag:"`"}),s.push({end:n,start:t})}}const c=function(e,t,n=[]){const o=[],r=new Set(Object.keys(t.transformersByTag).filter(e=>"`"!==e[0]).map(e=>e[0])),s=t=>{let n=0;for(let o=t-1;o>=0&&"\\"===e[o];o--)n++;return n%2==1},i=e=>n.some(t=>e>=t.start&&e<t.end);let c=0;for(;c<e.length;){const t=e[c];if(!r.has(t)||s(c)||i(c)){c++;continue}let n=1;for(;c+n<e.length&&e[c+n]===t;)n++;const l=E(t,e,c,n,!0),a=E(t,e,c,n,!1);(l||a)&&o.push({active:!0,canClose:a,canOpen:l,char:t,index:c,length:n,originalLength:n}),c+=n}return o}(n,t,s),l=c.length>0?function(e,t,n){const o={};let r=0,s=null;for(;r<t.length;){const i=t[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const c=`${i.char}${i.canOpen}`,l=o[c]??-1;let a=!1;for(let o=r-1;o>l;o--){const c=t[o];if(!c.active||!c.canOpen||0===c.length||c.char!==i.char)continue;if(c.canClose||i.canOpen){if((c.originalLength+i.originalLength)%3==0&&c.originalLength%3!=0&&i.originalLength%3!=0)continue}const l=Math.min(c.length,i.length),d=Object.keys(n.transformersByTag).filter(e=>e[0]===c.char&&e.length<=l).sort((e,t)=>t.length-e.length)[0];if(!d)continue;a=!0;const f=d.length,g={content:e.slice(c.index+c.length,i.index),endIndex:i.index+f,startIndex:c.index+(c.length-f),tag:d};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);for(let e=o+1;e<r;e++)t[e].active=!1;c.length-=f,i.length-=f,c.active=c.length>0,i.length>0?i.index+=f:(i.active=!1,r++);break}a||(o[c]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,c,t):null;let a=null,d=null;if(i&&l?l.startIndex<=i.startIndex&&l.endIndex>=i.endIndex?(a=l,d=t.transformersByTag[l.tag]):(a=i,d=r):i?(a=i,d=r):l&&(a=l,d=t.transformersByTag[l.tag]),!a||!d)return null;const f=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return f.index=a.startIndex,f.input=n,{endIndex:a.endIndex,match:f,startIndex:a.startIndex,transformer:d}}function E(e,t,n,o,r){if(!C(t,n,o,r))return!1;if("*"===e)return!0;if("_"===e){if(!C(t,n,o,!r))return!0;const e=r?t[n-1]:t[n+o];return void 0!==e&&d.test(e)}return!0}function C(e,t,n,o){const r=e[t-1],s=e[t+n],[i,c]=o?[s,r]:[r,s];return void 0!==i&&!a.test(i)&&(!d.test(i)||(void 0===c||a.test(c)||d.test(c)))}function S(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function I(e,t,n){let o=T(e,t),r=function(e,t){const n=e;let o,r,s,i;for(const e of t){if(!e.replace||!e.importRegExp)continue;const t=n.getTextContent().match(e.importRegExp);if(!t)continue;const c=t.index||0,l=e.getEndIndex?e.getEndIndex(n,t):c+t[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&(l>r||l<=o))&&(o=c,r=l,s=e,i=t)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(e,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(e,t,n,o,r){const s=e.getTextContent();let i,c,l;if(r[0]===s?i=e:0===t?[i,c]=e.splitText(n):[l,i,c]=e.splitText(t,n),i.setTextContent(r[2]),o)for(const e of o.format)i.hasFormat(e)||i.toggleFormat(e);return{nodeAfter:c,nodeBefore:l,transformedNode:i}}(e,o.startIndex,o.endIndex,o.transformer,o.match);S(r.nodeAfter)&&I(r.nodeAfter,t,n),S(r.nodeBefore)&&I(r.nodeBefore,t,n),S(r.transformedNode)&&I(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let s,i,c;return 0===t?[s,i]=e.splitText(n):[c,s,i]=e.splitText(t,n),o.replace?{nodeAfter:i,nodeBefore:c,transformedNode:o.replace(s,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;S(o.nodeAfter)&&I(o.nodeAfter,t,n),S(o.nodeBefore)&&I(o.nodeBefore,t,n),S(o.transformedNode)&&I(o.transformedNode,t,n)}const s=u(e.getTextContent());e.setTextContent(s)}function L(t,n=!1){const o=c(t),r=function(e){const t={},n={},o=[],r="(?<![\\\\])";for(const r of e){const{tag:e}=r;t[e]=r;const s=e.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===e.length?n[e]="`"===e?new RegExp("(?<![\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(?<![\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?![\\\\${s}])`):n[e]=new RegExp(`(?<!\\\\)(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:t}}(o.textFormat);return(t,s)=>{const i=t.split("\n"),c=i.length,l=s||e.$getRoot();l.clear();for(let e=0;e<c;e++){const t=i[e],[s,c]=R(i,e,o.multilineElement,l);s?e=c:v(t,l,o.element,r,o.textMatch,n)}const a=l.getChildren();for(const t of a)if(!n&&g(t)&&l.getChildrenSize()>1)t.remove();else if(e.$isElementNode(t))for(const e of t.getAllTextNodes())y(e);null!==e.$getSelection()&&l.selectStart()}}function R(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:c}=r,l=e[t].match(i);if(!l)continue;if(n){const s=n({lines:e,rootNode:o,startLineIndex:t,startMatch:l,transformer:r});if(null===s)continue;if(s)return s}const a="object"==typeof s&&"regExp"in s?s.regExp:s,d=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let f=t;const g=e.length;for(;f<g;){const n=a?e[f].match(a):null;if(!n&&(!d||d&&f<g-1)){f++;continue}if(n&&t===f&&n.index===l.index){f++;continue}const r=[];if(n&&t===f)r.push(e[t].slice(l[0].length,-n[0].length));else for(let o=t;o<=f;o++)if(o===t){const t=e[o].slice(l[0].length);r.push(t)}else if(o===f&&n){const t=e[o].slice(0,-n[0].length);r.push(t)}else r.push(e[o]);if(!1!==c(o,null,l,n,r,!0))return[!0,f];break}}return[!1,t]}function v(r,s,i,c,l,a){const d=e.$createTextNode(r),f=e.$createParagraphNode();f.append(d),s.append(f);for(const{regExp:e,replace:t}of i){const n=r.match(e);if(n&&(d.setTextContent(r.slice(n[0].length)),!1!==t(f,[d],n,!0)))break}if(I(d,c,l),f.isAttached()&&r.length>0){const r=f.getPreviousSibling();if(!a&&(e.$isParagraphNode(r)||n.$isQuoteNode(r)||t.$isListNode(r))){let n=r;if(t.$isListNode(r)){const e=r.getLastDescendant();n=null==e?null:o.$findMatchingParent(e,t.$isListItemNode)}if(null!=n&&n.getTextContentSize()>0){const t=n.getLastChild();if(e.$isTextNode(t)){const e=t.getTextContent();e.endsWith("\\")?t.setTextContent(e.slice(0,-1)):/ {2,}$/.test(e)&&t.setTextContent(e.replace(/ {2,}$/,""))}n.splice(n.getChildrenSize(),0,[e.$createLineBreakNode(),...f.getChildren()]),f.remove()}}}}function y(t){const n=new Set,o=t.getTextContent();let r=o.indexOf("\t");for(;-1!==r;)n.add(r),n.add(r+1),r=o.indexOf("\t",r+1);t.splitText(...n).forEach(t=>{"\t"===t.getTextContent()&&t.replace(e.$createTabNode())})}function O(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const _=/^(\s*)(\d{1,})\.\s/,M=/^(\s*)[-*+]\s/,A=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,b=/^(#{1,6})\s/,k=/^>\s/,F=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,w=/^[ \t]*`{3,}$/,B=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,D=/^(?:\|)(.+)(?:\|)\s?$/,P=/^(\| ?:?-*:? ?)+\|\s?$/,j=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,H=/^<\/[a-z_][\w-]*\s*>/i,U=e=>new RegExp(`(?:${e.source})$`,e.flags),z=e.createState("mdListMarker",{parse:e=>"string"==typeof e&&/^[-*+]$/.test(e)?e:"-",resetOnCopyNode:!0}),q=e.createState("mdCodeFence",{parse:e=>"string"==typeof e&&/^`{3,}$/.test(e)?e:"```",resetOnCopyNode:!0}),G=e=>(t,n,o,r)=>{const s=e(o);s.append(...n),t.replace(s),r||s.select(0,0)};const Q=n=>(o,r,s,i)=>{const c=o.getPreviousSibling(),l=o.getNextSibling(),a=t.$createListItemNode("check"===n?"x"===s[3]:void 0),d=s[0].trim()[0],f="bullet"!==n&&"check"!==n||d!==z.parse(d)?void 0:d;if(t.$isListNode(l)&&l.getListType()===n){f&&e.$setState(l,z,f);const t=l.getFirstChild();null!==t?t.insertBefore(a):l.append(a),o.remove()}else if(t.$isListNode(c)&&c.getListType()===n)f&&e.$setState(c,z,f),c.append(a),o.remove();else{const r=t.$createListNode(n,"number"===n?Number(s[2]):void 0);f&&e.$setState(r,z,f),r.append(a),o.replace(r)}a.append(...r),i||a.select(0,0);const g=function(e){const t=e.match(/\t/g),n=e.match(/ /g);let o=0;return t&&(o+=t.length),n&&(o+=Math.floor(n.length/4)),o}(s[1]);g&&a.setIndent(g)},W=(n,o,r)=>{const s=[],i=n.getChildren();let c=0;for(const l of i)if(t.$isListItemNode(l)){if(1===l.getChildrenSize()){const e=l.getFirstChild();if(t.$isListNode(e)){s.push(W(e,o,r+1));continue}}const i=" ".repeat(4*r),a=n.getListType(),d=e.$getState(n,z),f="number"===a?`${n.getStart()+c}. `:"check"===a?`${d} [${l.getChecked()?"x":" "}] `:d+" ";s.push(i+f+o(l)),c++}return s.join("\n")},K={dependencies:[n.HeadingNode],export:(e,t)=>{if(!n.$isHeadingNode(e))return null;const o=Number(e.getTag().slice(1));return"#".repeat(o)+" "+t(e)},regExp:b,replace:G(e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)}),type:"element"},X={dependencies:[n.QuoteNode],export:(e,t)=>{if(!n.$isQuoteNode(e))return null;const o=t(e).split("\n"),r=[];for(const e of o)r.push("> "+e);return r.join("\n")},regExp:k,replace:(t,o,r,s)=>{if(s){const r=t.getPreviousSibling();if(n.$isQuoteNode(r))return r.splice(r.getChildrenSize(),0,[e.$createLineBreakNode(),...o]),void t.remove()}const i=n.$createQuoteNode();i.append(...o),t.replace(i),s||i.select(0,0)},type:"element"},Y={dependencies:[r.CodeNode],export:t=>{if(!r.$isCodeNode(t))return null;const n=t.getTextContent();let o=e.$getState(t,q);if(n.indexOf(o)>-1){const e=n.match(/`{3,}/g);if(e){const t=Math.max(...e.map(e=>e.length));o="`".repeat(t+1)}}return o+(t.getLanguage()||"")+(n?"\n"+n:"")+"\n"+o},handleImportAfterStartMatch:({lines:e,rootNode:t,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=e[n],c=o.index+r.length,l=i.slice(c),a=new RegExp(`\`{${s},}$`);if(a.test(l)){const e=l.match(a),r=l.slice(0,l.lastIndexOf(e[0])),s=[...o];return s[2]="",Y.replace(t,null,s,e,[r],!0),[!0,n]}const d=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<e.length;r++){const s=e[r];if(d.test(s)){const c=s.match(d),l=e.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&l.unshift(a),Y.replace(t,null,o,c,l,!0),[!0,r]}}const f=e.slice(n+1),g=i.slice(o[0].length);return g.length>0&&f.unshift(g),Y.replace(t,null,o,null,f,!0),[!0,e.length-1]},regExpEnd:{optional:!0,regExp:w},regExpStart:F,replace:(t,n,o,s,i,c)=>{let l,a;const d=o[1]?o[1].trim():"```",f=o[2]||void 0;if(!n&&i){if(1===i.length)s?(l=r.$createCodeNode(f),a=i[0]):(l=r.$createCodeNode(f),a=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(l=r.$createCodeNode(f),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();a=i.join("\n")}e.$setState(l,q,d);const n=e.$createTextNode(a);l.append(n),t.append(l)}else n&&G(e=>r.$createCodeNode(e?e[2]:void 0))(t,n,o,c)},type:"multiline-element"},J={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:M,replace:Q("bullet"),type:"element"},V={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:A,replace:Q("check"),type:"element"},Z={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:_,replace:Q("number"),type:"element"},ee={format:["code"],tag:"`",type:"text-format"},te={format:["highlight"],tag:"==",type:"text-format"},ne={format:["bold","italic"],tag:"***",type:"text-format"},oe={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},re={format:["bold"],tag:"**",type:"text-format"},se={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ie={format:["strikethrough"],tag:"~~",type:"text-format"},ce={format:["italic"],tag:"*",type:"text-format"},le={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ae={dependencies:[s.LinkNode],export:(e,t,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o=t(e);let r=e.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${e.getURL()} "${r}")`:`[${o}](${e.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{if(e.$findMatchingParent(t,s.$isLinkNode))return;const[,o,r,i]=n,c=null!=r?u(r):void 0,l=null!=i?u(i):void 0,a=s.$createLinkNode(c,{title:l}),d=o.split("[").length-1,f=o.split("]").length-1;let g=o,p="";if(d<f)return;if(d>f){const e=o.split("[");p="["+e[0],g=e.slice(1).join("[")}const x=e.$createTextNode(g);return x.setFormat(t.getFormat()),a.append(x),t.replace(a),p&&a.insertBefore(e.$createTextNode(p)),x},trigger:")",type:"text-match"},de=[K,X,J,Z],fe=[Y],ge=[ee,ne,oe,re,se,te,ce,le,ie],ue=[ae],pe=[...de,...fe,...ge,...ue];function xe(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const c=n.getTextContent();if(!s&&" "!==c[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:l}of r){if(l&&!("optional"in l)||l&&"optional"in l&&!l.optional)continue;const r=c.match(e);if(r){const e=s||r[0].endsWith(" ")?o:o-1;if(r[0].length!==e)continue;const c=n.getNextSiblings(),[l,a]=n.splitText(o);if(!1!==i(t,a?[a,...c]:c,r,null,null,!1))return l.remove(),!0}}return!1}function he(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(me(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function me(e,t,n,o,r){for(let s=0;s<r;s++)if(e[t+s]!==n[o+s])return!1;return!0}exports.$convertFromMarkdownString=function(e,t=pe,n,o=!1,r=!1){const s=o?e:function(e,t=!1){const n=e.split("\n");let o=!1;const r=[];for(let e=0;e<n.length;e++){const s=n[e],i=s.trimEnd(),c=r[r.length-1];B.test(i)?r.push(i):F.test(i)||w.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===c||!c||b.test(c)||b.test(i)||k.test(i)||_.test(i)||M.test(i)||A.test(i)||D.test(i)||P.test(i)||!t||j.test(i)||H.test(i)||U(H).test(c)||U(j).test(c)||w.test(c)?r.push(t||""===i?i:s):r[r.length-1]=c+" "+i.trimStart()}return r.join("\n")}(e,r);return L(t,o)(s,n)},exports.$convertToMarkdownString=function(t=pe,n,o=!1){return function(t,n=!1){const o=c(t),r=[...o.multilineElement,...o.element],s=!n,i=o.textFormat.filter(e=>1===e.format.length).sort((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code")));return t=>{const c=[],l=(t||e.$getRoot()).getChildren();for(let e=0;e<l.length;e++){const t=l[e],a=p(t,r,i,o.textMatch,n);null!=a&&c.push(s&&e>0&&!g(t)&&!g(l[e-1])?"\n".concat(a):a)}return c.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=ne,exports.BOLD_ITALIC_UNDERSCORE=oe,exports.BOLD_STAR=re,exports.BOLD_UNDERSCORE=se,exports.CHECK_LIST=V,exports.CODE=Y,exports.ELEMENT_TRANSFORMERS=de,exports.HEADING=K,exports.HIGHLIGHT=te,exports.INLINE_CODE=ee,exports.ITALIC_STAR=ce,exports.ITALIC_UNDERSCORE=le,exports.LINK=ae,exports.MULTILINE_ELEMENT_TRANSFORMERS=fe,exports.ORDERED_LIST=Z,exports.QUOTE=X,exports.STRIKETHROUGH=ie,exports.TEXT_FORMAT_TRANSFORMERS=ge,exports.TEXT_MATCH_TRANSFORMERS=ue,exports.TRANSFORMERS=pe,exports.UNORDERED_LIST=J,exports.registerMarkdownShortcuts=function(t,n=pe){const o=c(n),s=i(o.textFormat,({tag:e})=>e[e.length-1]),a=i(o.textMatch,({trigger:e})=>e);for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||O(173,e.getType())}}const d=(t,n,r)=>{(function(t,n,o,r){const s=t.getParent();if(!e.$isRootOrShadowRoot(s)||t.getFirstChild()!==n)return!1;const i=n.getTextContent();if(" "!==i[o-1])return!1;for(const{regExp:e,replace:s}of r){const r=i.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[i,c]=n.splitText(o);if(!1!==s(t,c?[c,...e]:e,r,!1))return i.remove(),!0}}return!1})(t,n,r,o.element)||xe(t,n,r,o.multilineElement)||function(e,t,n){let o=e.getTextContent();const r=n[o[t-1]];if(null==r)return!1;t<o.length&&(o=o.slice(0,t));for(const t of r){if(!t.replace||!t.regExp)continue;const n=o.match(t.regExp);if(null===n)continue;const r=n.index||0,s=r+n[0].length;let i;return 0===r?[i]=e.splitText(s):[,i]=e.splitText(r,s),i.selectNext(0,0),t.replace(i,n),!0}return!1}(n,r,a)||function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],c=o[i];if(!c)return!1;for(const n of c){const{tag:o}=n,c=o.length,a=s-c+1;if(c>1&&!me(r,a,o,0,c))continue;if(" "===r[a-1])continue;const d=r[s+1];if(!1===n.intraword&&d&&!l.test(d))continue;const f=t;let g=f,u=he(r,a,o),p=g;for(;u<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();g=p,u=he(e,e.length,o)}if(u<0)continue;if(g===f&&u+c===a)continue;const x=g.getTextContent();if(u>0&&x[u-1]===i)continue;const h=x[u-1];if(!1===n.intraword&&h&&!l.test(h))continue;const m=f.getTextContent(),$=m.slice(0,a)+m.slice(s+1);f.setTextContent($);const N=g===f?$:x;g.setTextContent(N.slice(0,u)+N.slice(u+c));const T=e.$getSelection(),E=e.$createRangeSelection();e.$setSelection(E);const C=s-c*(g===f?2:1)+1;E.anchor.set(g.__key,u,"text"),E.focus.set(f.__key,C,"text");for(const e of n.format)E.hasFormat(e)||E.formatText(e);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const e of n.format)E.hasFormat(e)&&E.toggleFormat(e);return e.$isRangeSelection(T)&&(E.format=T.format),!0}}(n,r,s)};return e.mergeRegister(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:s,prevEditorState:i})=>{if(n.has(e.COLLABORATION_TAG)||n.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const c=s.read(e.$getSelection),l=i.read(e.$getSelection);if(!e.$isRangeSelection(l)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(l))return;const a=c.anchor.key,f=c.anchor.offset,g=s._nodeMap.get(a);!e.$isTextNode(g)||!o.has(a)||1!==f&&f>l.anchor.offset+1||t.update(()=>{if(!S(g))return;const e=g.getParent();null===e||r.$isCodeNode(e)||d(e,g,c.anchor.offset)})}),t.registerCommand(e.KEY_ENTER_COMMAND,t=>{if(null!==t&&t.shiftKey)return!1;const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e.$isTextNode(i)||!S(i))return!1;const c=i.getParent();if(null===c||r.$isCodeNode(c))return!1;return s===i.getTextContent().length&&(!!xe(c,i,s,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},e.COMMAND_PRIORITY_LOW))};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/list"),n=require("@lexical/rich-text"),o=require("@lexical/utils"),r=require("@lexical/code-core"),s=require("@lexical/link");function i(e,t){const n={};for(const o of e){const e=t(o);e&&(n[e]?n[e].push(o):n[e]=[o])}return n}function c(e){const t=i(e,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}const l=/[!-/:-@[-`{-~\s]/,a=/[ \t\n\r\f]/,d=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,f=/^\s{0,3}$/;function g(t){if(!e.$isParagraphNode(t))return!1;const n=t.getFirstChild();return null==n||1===t.getChildrenSize()&&e.$isTextNode(n)&&f.test(n.getTextContent())}function u(e){return e.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(e,t)=>String.fromCodePoint(Number(t)))}function p(t,n,o,r,s){for(const e of n){if(!e.export)continue;const n=e.export(t,e=>x(e,o,r,void 0,void 0,s));if(null!=n)return n}return e.$isElementNode(t)?x(t,o,r,void 0,void 0,s):e.$isDecoratorNode(t)?t.getTextContent():null}function x(t,n,o,r,s,i=!1){const c=[],l=t.getChildren();r||(r=[]),s||(s=[]);e:for(const t of l){for(const e of o){if(!e.export)continue;const l=e.export(t,e=>x(e,n,o,r,[...s,...r],i),(e,t)=>h(e,t,n,r,s,i));if(null!=l){c.push(l);continue e}}e.$isLineBreakNode(t)?c.push("\n"):e.$isTextNode(t)?c.push(h(t,t.getTextContent(),n,r,s,i)):e.$isElementNode(t)?c.push(x(t,n,o,r,s,i)):e.$isDecoratorNode(t)&&c.push(t.getTextContent())}return c.join("")}function h(e,t,n,o,r,s=!1){let i=t;e.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const c=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],l=c[1],a=c[2],d=c[3],f=""===a;let g="",u="",p="";const x=m(e,!0),h=m(e,!1),T=new Set;for(const t of n){const n=t.format[0],r=t.tag;N(e,n)&&!T.has(n)&&(T.add(n),N(x,n)&&o.find(e=>e.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let t=0;t<o.length;t++){const n=$(e,o[t].format),s=$(h,o[t].format);if(n&&s)continue;const i=[...o];for(;i.length>t;){const e=i.pop();r&&e&&r.find(t=>t.tag===e.tag)||(e&&"string"==typeof e.tag&&(n?s||(p+=e.tag):u+=e.tag),o.pop())}break}return f&&!e.hasFormat("code")?u+i:u+l+g+a+p+d}function m(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e.$isTextNode(o)?o:null}function $(t,n){return e.$isTextNode(t)&&t.hasFormat(n)}function N(e,t){return!!$(e,t)&&("code"===t||(!e||!/^\s*$/.test(e.getTextContent())))}function T(e,t){const n=e.getTextContent(),o=t.fullMatchRegExpByTag["`"],r=t.transformersByTag["`"],s=[];let i=null;if(o&&r){const e=new RegExp(o.source,"g"),t=Array.from(n.matchAll(e));for(const e of t){const t=e.index+e[1].length,n=e.index+e[0].length;i||(i={content:e[3],endIndex:n,startIndex:t,tag:"`"}),s.push({end:n,start:t})}}const c=function(e,t,n=[]){const o=[],r=new Set(Object.keys(t.transformersByTag).filter(e=>"`"!==e[0]).map(e=>e[0])),s=t=>{let n=0;for(let o=t-1;o>=0&&"\\"===e[o];o--)n++;return n%2==1},i=e=>n.some(t=>e>=t.start&&e<t.end);let c=0;for(;c<e.length;){const t=e[c];if(!r.has(t)||s(c)||i(c)){c++;continue}let n=1;for(;c+n<e.length&&e[c+n]===t;)n++;const l=E(t,e,c,n,!0),a=E(t,e,c,n,!1);(l||a)&&o.push({active:!0,canClose:a,canOpen:l,char:t,index:c,length:n,originalLength:n}),c+=n}return o}(n,t,s),l=c.length>0?function(e,t,n){const o={};let r=0,s=null;for(;r<t.length;){const i=t[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const c=`${i.char}${i.canOpen}`,l=o[c]??-1;let a=!1;for(let o=r-1;o>l;o--){const c=t[o];if(!c.active||!c.canOpen||0===c.length||c.char!==i.char)continue;if(c.canClose||i.canOpen){if((c.originalLength+i.originalLength)%3==0&&c.originalLength%3!=0&&i.originalLength%3!=0)continue}const l=Math.min(c.length,i.length),d=Object.keys(n.transformersByTag).filter(e=>e[0]===c.char&&e.length<=l).sort((e,t)=>t.length-e.length)[0];if(!d)continue;a=!0;const f=d.length,g={content:e.slice(c.index+c.length,i.index),endIndex:i.index+f,startIndex:c.index+(c.length-f),tag:d};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);for(let e=o+1;e<r;e++)t[e].active=!1;c.length-=f,i.length-=f,c.active=c.length>0,i.length>0?i.index+=f:(i.active=!1,r++);break}a||(o[c]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,c,t):null;let a=null,d=null;if(i&&l?l.startIndex<=i.startIndex&&l.endIndex>=i.endIndex?(a=l,d=t.transformersByTag[l.tag]):(a=i,d=r):i?(a=i,d=r):l&&(a=l,d=t.transformersByTag[l.tag]),!a||!d)return null;const f=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return f.index=a.startIndex,f.input=n,{endIndex:a.endIndex,match:f,startIndex:a.startIndex,transformer:d}}function E(e,t,n,o,r){if(!C(t,n,o,r))return!1;if("*"===e)return!0;if("_"===e){if(!C(t,n,o,!r))return!0;const e=r?t[n-1]:t[n+o];return void 0!==e&&d.test(e)}return!0}function C(e,t,n,o){const r=e[t-1],s=e[t+n],[i,c]=o?[s,r]:[r,s];return void 0!==i&&!a.test(i)&&(!d.test(i)||(void 0===c||a.test(c)||d.test(c)))}function S(t){return e.$isTextNode(t)&&!t.hasFormat("code")}function I(e,t,n){let o=T(e,t),r=function(e,t){const n=e;let o,r,s,i;for(const e of t){if(!e.replace||!e.importRegExp)continue;const t=n.getTextContent().match(e.importRegExp);if(!t)continue;const c=t.index||0,l=e.getEndIndex?e.getEndIndex(n,t):c+t[0].length;!1!==l&&(void 0===o||void 0===r||c<o&&(l>r||l<=o))&&(o=c,r=l,s=e,i=t)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(e,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(e,t,n,o,r){const s=e.getTextContent();let i,c,l;if(r[0]===s?i=e:0===t?[i,c]=e.splitText(n):[l,i,c]=e.splitText(t,n),i.setTextContent(r[2]),o)for(const e of o.format)i.hasFormat(e)||i.toggleFormat(e);return{nodeAfter:c,nodeBefore:l,transformedNode:i}}(e,o.startIndex,o.endIndex,o.transformer,o.match);S(r.nodeAfter)&&I(r.nodeAfter,t,n),S(r.nodeBefore)&&I(r.nodeBefore,t,n),S(r.transformedNode)&&I(r.transformedNode,t,n)}else if(r){const o=function(e,t,n,o,r){let s,i,c;return 0===t?[s,i]=e.splitText(n):[c,s,i]=e.splitText(t,n),o.replace?{nodeAfter:i,nodeBefore:c,transformedNode:o.replace(s,r)||void 0}:null}(e,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;S(o.nodeAfter)&&I(o.nodeAfter,t,n),S(o.nodeBefore)&&I(o.nodeBefore,t,n),S(o.transformedNode)&&I(o.transformedNode,t,n)}const s=u(e.getTextContent());e.setTextContent(s)}function L(t,n=!1){const o=c(t),r=function(e){const t={},n={},o=[];for(const r of e){const{tag:e}=r;t[e]=r;const s=e.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===e.length?n[e]="`"===e?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[e]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:t}}(o.textFormat);return(t,s)=>{const i=t.split("\n"),c=i.length,l=s||e.$getRoot();l.clear();for(let e=0;e<c;e++){const t=i[e],[s,c]=R(i,e,o.multilineElement,l);s?e=c:v(t,l,o.element,r,o.textMatch,n)}const a=l.getChildren();for(const t of a)if(!n&&g(t)&&l.getChildrenSize()>1)t.remove();else if(e.$isElementNode(t))for(const e of t.getAllTextNodes())y(e);null!==e.$getSelection()&&l.selectStart()}}function R(e,t,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:c}=r,l=e[t].match(i);if(!l)continue;if(n){const s=n({lines:e,rootNode:o,startLineIndex:t,startMatch:l,transformer:r});if(null===s)continue;if(s)return s}const a="object"==typeof s&&"regExp"in s?s.regExp:s,d=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let f=t;const g=e.length;for(;f<g;){const n=a?e[f].match(a):null;if(!n&&(!d||d&&f<g-1)){f++;continue}if(n&&t===f&&n.index===l.index){f++;continue}const r=[];if(n&&t===f)r.push(e[t].slice(l[0].length,-n[0].length));else for(let o=t;o<=f;o++)if(o===t){const t=e[o].slice(l[0].length);r.push(t)}else if(o===f&&n){const t=e[o].slice(0,-n[0].length);r.push(t)}else r.push(e[o]);if(!1!==c(o,null,l,n,r,!0))return[!0,f];break}}return[!1,t]}function v(r,s,i,c,l,a){const d=e.$createTextNode(r),f=e.$createParagraphNode();f.append(d),s.append(f);for(const{regExp:e,replace:t}of i){const n=r.match(e);if(n&&(d.setTextContent(r.slice(n[0].length)),!1!==t(f,[d],n,!0)))break}if(I(d,c,l),f.isAttached()&&r.length>0){const r=f.getPreviousSibling();if(!a&&(e.$isParagraphNode(r)||n.$isQuoteNode(r)||t.$isListNode(r))){let n=r;if(t.$isListNode(r)){const e=r.getLastDescendant();n=null==e?null:o.$findMatchingParent(e,t.$isListItemNode)}if(null!=n&&n.getTextContentSize()>0){const t=n.getLastChild();if(e.$isTextNode(t)){const e=t.getTextContent();e.endsWith("\\")?t.setTextContent(e.slice(0,-1)):/ {2,}$/.test(e)&&t.setTextContent(e.replace(/ {2,}$/,""))}n.splice(n.getChildrenSize(),0,[e.$createLineBreakNode(),...f.getChildren()]),f.remove()}}}}function y(t){const n=new Set,o=t.getTextContent();let r=o.indexOf("\t");for(;-1!==r;)n.add(r),n.add(r+1),r=o.indexOf("\t",r+1);t.splitText(...n).forEach(t=>{"\t"===t.getTextContent()&&t.replace(e.$createTabNode())})}function O(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const _=/^(\s*)(\d{1,})\.\s/,M=/^(\s*)[-*+]\s/,A=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,b=/^(#{1,6})\s/,k=/^>\s/,F=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,w=/^[ \t]*`{3,}$/,B=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,D=/^(?:\|)(.+)(?:\|)\s?$/,P=/^(\| ?:?-*:? ?)+\|\s?$/,j=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,H=/^<\/[a-z_][\w-]*\s*>/i,U=e=>new RegExp(`(?:${e.source})$`,e.flags),z=e.createState("mdListMarker",{parse:e=>"string"==typeof e&&/^[-*+]$/.test(e)?e:"-",resetOnCopyNode:!0}),q=e.createState("mdCodeFence",{parse:e=>"string"==typeof e&&/^`{3,}$/.test(e)?e:"```",resetOnCopyNode:!0}),G=e=>(t,n,o,r)=>{const s=e(o);s.append(...n),t.replace(s),r||s.select(0,0)};const Q=n=>(o,r,s,i)=>{const c=o.getPreviousSibling(),l=o.getNextSibling(),a=t.$createListItemNode("check"===n?"x"===s[3]:void 0),d=s[0].trim()[0],f="bullet"!==n&&"check"!==n||d!==z.parse(d)?void 0:d;if(t.$isListNode(l)&&l.getListType()===n){f&&e.$setState(l,z,f);const t=l.getFirstChild();null!==t?t.insertBefore(a):l.append(a),o.remove()}else if(t.$isListNode(c)&&c.getListType()===n)f&&e.$setState(c,z,f),c.append(a),o.remove();else{const r=t.$createListNode(n,"number"===n?Number(s[2]):void 0);f&&e.$setState(r,z,f),r.append(a),o.replace(r)}a.append(...r),i||a.select(0,0);const g=function(e){const t=e.match(/\t/g),n=e.match(/ /g);let o=0;return t&&(o+=t.length),n&&(o+=Math.floor(n.length/4)),o}(s[1]);g&&a.setIndent(g)},W=(n,o,r)=>{const s=[],i=n.getChildren();let c=0;for(const l of i)if(t.$isListItemNode(l)){if(1===l.getChildrenSize()){const e=l.getFirstChild();if(t.$isListNode(e)){s.push(W(e,o,r+1));continue}}const i=" ".repeat(4*r),a=n.getListType(),d=e.$getState(n,z),f="number"===a?`${n.getStart()+c}. `:"check"===a?`${d} [${l.getChecked()?"x":" "}] `:d+" ";s.push(i+f+o(l)),c++}return s.join("\n")},K={dependencies:[n.HeadingNode],export:(e,t)=>{if(!n.$isHeadingNode(e))return null;const o=Number(e.getTag().slice(1));return"#".repeat(o)+" "+t(e)},regExp:b,replace:G(e=>{const t="h"+e[1].length;return n.$createHeadingNode(t)}),type:"element"},X={dependencies:[n.QuoteNode],export:(e,t)=>{if(!n.$isQuoteNode(e))return null;const o=t(e).split("\n"),r=[];for(const e of o)r.push("> "+e);return r.join("\n")},regExp:k,replace:(t,o,r,s)=>{if(s){const r=t.getPreviousSibling();if(n.$isQuoteNode(r))return r.splice(r.getChildrenSize(),0,[e.$createLineBreakNode(),...o]),void t.remove()}const i=n.$createQuoteNode();i.append(...o),t.replace(i),s||i.select(0,0)},type:"element"},Y={dependencies:[r.CodeNode],export:t=>{if(!r.$isCodeNode(t))return null;const n=t.getTextContent();let o=e.$getState(t,q);if(n.indexOf(o)>-1){const e=n.match(/`{3,}/g);if(e){const t=Math.max(...e.map(e=>e.length));o="`".repeat(t+1)}}return o+(t.getLanguage()||"")+(n?"\n"+n:"")+"\n"+o},handleImportAfterStartMatch:({lines:e,rootNode:t,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=e[n],c=o.index+r.length,l=i.slice(c),a=new RegExp(`\`{${s},}$`);if(a.test(l)){const e=l.match(a),r=l.slice(0,l.lastIndexOf(e[0])),s=[...o];return s[2]="",Y.replace(t,null,s,e,[r],!0),[!0,n]}const d=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<e.length;r++){const s=e[r];if(d.test(s)){const c=s.match(d),l=e.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&l.unshift(a),Y.replace(t,null,o,c,l,!0),[!0,r]}}const f=e.slice(n+1),g=i.slice(o[0].length);return g.length>0&&f.unshift(g),Y.replace(t,null,o,null,f,!0),[!0,e.length-1]},regExpEnd:{optional:!0,regExp:w},regExpStart:F,replace:(t,n,o,s,i,c)=>{let l,a;const d=o[1]?o[1].trim():"```",f=o[2]||void 0;if(!n&&i){if(1===i.length)s?(l=r.$createCodeNode(f),a=i[0]):(l=r.$createCodeNode(f),a=i[0].startsWith(" ")?i[0].slice(1):i[0]);else{for(l=r.$createCodeNode(f),i.length>0&&(0===i[0].trim().length?i.shift():i[0].startsWith(" ")&&(i[0]=i[0].slice(1)));i.length>0&&!i[i.length-1].length;)i.pop();a=i.join("\n")}e.$setState(l,q,d);const n=e.$createTextNode(a);l.append(n),t.append(l)}else n&&G(e=>r.$createCodeNode(e?e[2]:void 0))(t,n,o,c)},type:"multiline-element"},J={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:M,replace:Q("bullet"),type:"element"},V={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:A,replace:Q("check"),type:"element"},Z={dependencies:[t.ListNode,t.ListItemNode],export:(e,n)=>t.$isListNode(e)?W(e,n,0):null,regExp:_,replace:Q("number"),type:"element"},ee={format:["code"],tag:"`",type:"text-format"},te={format:["highlight"],tag:"==",type:"text-format"},ne={format:["bold","italic"],tag:"***",type:"text-format"},oe={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},re={format:["bold"],tag:"**",type:"text-format"},se={format:["bold"],intraword:!1,tag:"__",type:"text-format"},ie={format:["strikethrough"],tag:"~~",type:"text-format"},ce={format:["italic"],tag:"*",type:"text-format"},le={format:["italic"],intraword:!1,tag:"_",type:"text-format"},ae={dependencies:[s.LinkNode],export:(e,t,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o=t(e);let r=e.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${e.getURL()} "${r}")`:`[${o}](${e.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,n)=>{if(e.$findMatchingParent(t,s.$isLinkNode))return;const[,o,r,i]=n,c=null!=r?u(r):void 0,l=null!=i?u(i):void 0,a=s.$createLinkNode(c,{title:l}),d=o.split("[").length-1,f=o.split("]").length-1;let g=o,p="";if(d<f)return;if(d>f){const e=o.split("[");p="["+e[0],g=e.slice(1).join("[")}const x=e.$createTextNode(g);return x.setFormat(t.getFormat()),a.append(x),t.replace(a),p&&a.insertBefore(e.$createTextNode(p)),x},trigger:")",type:"text-match"},de=[K,X,J,Z],fe=[Y],ge=[ee,ne,oe,re,se,te,ce,le,ie],ue=[ae],pe=[...de,...fe,...ge,...ue];function xe(t,n,o,r,s){const i=t.getParent();if(!e.$isRootOrShadowRoot(i)||t.getFirstChild()!==n)return!1;const c=n.getTextContent();if(!s&&" "!==c[o-1])return!1;for(const{regExpStart:e,replace:i,regExpEnd:l}of r){if(l&&!("optional"in l)||l&&"optional"in l&&!l.optional)continue;const r=c.match(e);if(r){const e=s||r[0].endsWith(" ")?o:o-1;if(r[0].length!==e)continue;const c=n.getNextSiblings(),[l,a]=n.splitText(o);if(!1!==i(t,a?[a,...c]:c,r,null,null,!1))return l.remove(),!0}}return!1}function he(e,t,n){const o=n.length;for(let r=t;r>=o;r--){const t=r-o;if(me(e,t,n,0,o)&&" "!==e[t+o])return t}return-1}function me(e,t,n,o,r){for(let s=0;s<r;s++)if(e[t+s]!==n[o+s])return!1;return!0}exports.$convertFromMarkdownString=function(e,t=pe,n,o=!1,r=!1){const s=o?e:function(e,t=!1){const n=e.split("\n");let o=!1;const r=[];for(let e=0;e<n.length;e++){const s=n[e],i=s.trimEnd(),c=r[r.length-1];B.test(i)?r.push(i):F.test(i)||w.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===c||!c||b.test(c)||b.test(i)||k.test(i)||_.test(i)||M.test(i)||A.test(i)||D.test(i)||P.test(i)||!t||j.test(i)||H.test(i)||U(H).test(c)||U(j).test(c)||w.test(c)?r.push(t||""===i?i:s):r[r.length-1]=c+" "+i.trimStart()}return r.join("\n")}(e,r);return L(t,o)(s,n)},exports.$convertToMarkdownString=function(t=pe,n,o=!1){return function(t,n=!1){const o=c(t),r=[...o.multilineElement,...o.element],s=!n,i=o.textFormat.filter(e=>1===e.format.length).sort((e,t)=>Number(e.format.includes("code"))-Number(t.format.includes("code")));return t=>{const c=[],l=(t||e.$getRoot()).getChildren();for(let e=0;e<l.length;e++){const t=l[e],a=p(t,r,i,o.textMatch,n);null!=a&&c.push(s&&e>0&&!g(t)&&!g(l[e-1])?"\n".concat(a):a)}return c.join("\n")}}(t,o)(n)},exports.BOLD_ITALIC_STAR=ne,exports.BOLD_ITALIC_UNDERSCORE=oe,exports.BOLD_STAR=re,exports.BOLD_UNDERSCORE=se,exports.CHECK_LIST=V,exports.CODE=Y,exports.ELEMENT_TRANSFORMERS=de,exports.HEADING=K,exports.HIGHLIGHT=te,exports.INLINE_CODE=ee,exports.ITALIC_STAR=ce,exports.ITALIC_UNDERSCORE=le,exports.LINK=ae,exports.MULTILINE_ELEMENT_TRANSFORMERS=fe,exports.ORDERED_LIST=Z,exports.QUOTE=X,exports.STRIKETHROUGH=ie,exports.TEXT_FORMAT_TRANSFORMERS=ge,exports.TEXT_MATCH_TRANSFORMERS=ue,exports.TRANSFORMERS=pe,exports.UNORDERED_LIST=J,exports.registerMarkdownShortcuts=function(t,n=pe){const o=c(n),s=i(o.textFormat,({tag:e})=>e[e.length-1]),a=i(o.textMatch,({trigger:e})=>e);for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||O(173,e.getType())}}const d=(t,n,r)=>{(function(t,n,o,r){const s=t.getParent();if(!e.$isRootOrShadowRoot(s)||t.getFirstChild()!==n)return!1;const i=n.getTextContent();if(" "!==i[o-1])return!1;for(const{regExp:e,replace:s}of r){const r=i.match(e);if(r&&r[0].length===(r[0].endsWith(" ")?o:o-1)){const e=n.getNextSiblings(),[i,c]=n.splitText(o);if(!1!==s(t,c?[c,...e]:e,r,!1))return i.remove(),!0}}return!1})(t,n,r,o.element)||xe(t,n,r,o.multilineElement)||function(e,t,n){let o=e.getTextContent();const r=n[o[t-1]];if(null==r)return!1;t<o.length&&(o=o.slice(0,t));for(const t of r){if(!t.replace||!t.regExp)continue;const n=o.match(t.regExp);if(null===n)continue;const r=n.index||0,s=r+n[0].length;let i;return 0===r?[i]=e.splitText(s):[,i]=e.splitText(r,s),i.selectNext(0,0),t.replace(i,n),!0}return!1}(n,r,a)||function(t,n,o){const r=t.getTextContent(),s=n-1,i=r[s],c=o[i];if(!c)return!1;for(const n of c){const{tag:o}=n,c=o.length,a=s-c+1;if(c>1&&!me(r,a,o,0,c))continue;if(" "===r[a-1])continue;const d=r[s+1];if(!1===n.intraword&&d&&!l.test(d))continue;const f=t;let g=f,u=he(r,a,o),p=g;for(;u<0&&(p=p.getPreviousSibling())&&!e.$isLineBreakNode(p);)if(e.$isTextNode(p)){if(p.hasFormat("code"))continue;const e=p.getTextContent();g=p,u=he(e,e.length,o)}if(u<0)continue;if(g===f&&u+c===a)continue;const x=g.getTextContent();if(u>0&&x[u-1]===i)continue;const h=x[u-1];if(!1===n.intraword&&h&&!l.test(h))continue;const m=f.getTextContent(),$=m.slice(0,a)+m.slice(s+1);f.setTextContent($);const N=g===f?$:x;g.setTextContent(N.slice(0,u)+N.slice(u+c));const T=e.$getSelection(),E=e.$createRangeSelection();e.$setSelection(E);const C=s-c*(g===f?2:1)+1;E.anchor.set(g.__key,u,"text"),E.focus.set(f.__key,C,"text");for(const e of n.format)E.hasFormat(e)||E.formatText(e);E.anchor.set(E.focus.key,E.focus.offset,E.focus.type);for(const e of n.format)E.hasFormat(e)&&E.toggleFormat(e);return e.$isRangeSelection(T)&&(E.format=T.format),!0}}(n,r,s)};return e.mergeRegister(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:s,prevEditorState:i})=>{if(n.has(e.COLLABORATION_TAG)||n.has(e.HISTORIC_TAG))return;if(t.isComposing())return;const c=s.read(e.$getSelection),l=i.read(e.$getSelection);if(!e.$isRangeSelection(l)||!e.$isRangeSelection(c)||!c.isCollapsed()||c.is(l))return;const a=c.anchor.key,f=c.anchor.offset,g=s._nodeMap.get(a);!e.$isTextNode(g)||!o.has(a)||1!==f&&f>l.anchor.offset+1||t.update(()=>{if(!S(g))return;const e=g.getParent();null===e||r.$isCodeNode(e)||d(e,g,c.anchor.offset)})}),t.registerCommand(e.KEY_ENTER_COMMAND,t=>{if(null!==t&&t.shiftKey)return!1;const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed())return!1;const s=n.anchor.offset,i=n.anchor.getNode();if(!e.$isTextNode(i)||!S(i))return!1;const c=i.getParent();if(null===c||r.$isCodeNode(c))return!1;return s===i.getTextContent().length&&(!!xe(c,i,s,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},e.COMMAND_PRIORITY_LOW))};
|
package/LexicalMarkdown.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$isParagraphNode as t,$isTextNode as e,$getRoot as n,$isElementNode as o,$isDecoratorNode as r,$isLineBreakNode as s,$getSelection as i,$createTextNode as l,$createParagraphNode as c,$createLineBreakNode as a,$createTabNode as f,createState as u,$setState as g,$getState as d,$findMatchingParent as p,mergeRegister as h,COLLABORATION_TAG as x,HISTORIC_TAG as m,$isRangeSelection as C,KEY_ENTER_COMMAND as T,COMMAND_PRIORITY_LOW as $,$isRootOrShadowRoot as v,$createRangeSelection as y,$setSelection as E}from"lexical";import{$isListNode as I,$isListItemNode as S,ListNode as b,ListItemNode as w,$createListItemNode as N,$createListNode as F}from"@lexical/list";import{$isQuoteNode as L,HeadingNode as k,QuoteNode as R,$isHeadingNode as M,$createQuoteNode as _,$createHeadingNode as B}from"@lexical/rich-text";import{$findMatchingParent as O}from"@lexical/utils";import{CodeNode as j,$createCodeNode as A,$isCodeNode as P}from"@lexical/code-core";import{LinkNode as z,$isLinkNode as U,$createLinkNode as W,$isAutoLinkNode as D}from"@lexical/link";function K(t,e){const n={};for(const o of t){const t=e(o);t&&(n[t]?n[t].push(o):n[t]=[o])}return n}function q(t){const e=K(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const G=/[!-/:-@[-`{-~\s]/,H=/[ \t\n\r\f]/,J=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,Q=/^\s{0,3}$/;function V(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&Q.test(o.getTextContent())}function X(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}function Y(t,e,n,s,i){for(const o of e){if(!o.export)continue;const e=o.export(t,t=>Z(t,n,s,void 0,void 0,i));if(null!=e)return e}return o(t)?Z(t,n,s,void 0,void 0,i):r(t)?t.getTextContent():null}function Z(t,n,i,l,c,a=!1){const f=[],u=t.getChildren();l||(l=[]),c||(c=[]);t:for(const t of u){for(const e of i){if(!e.export)continue;const o=e.export(t,t=>Z(t,n,i,l,[...c,...l],a),(t,e)=>tt(t,e,n,l,c,a));if(null!=o){f.push(o);continue t}}s(t)?f.push("\n"):e(t)?f.push(tt(t,t.getTextContent(),n,l,c,a)):o(t)?f.push(Z(t,n,i,l,c,a)):r(t)&&f.push(t.getTextContent())}return f.join("")}function tt(t,e,n,o,r,s=!1){let i=e;t.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const l=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],c=l[1],a=l[2],f=l[3],u=""===a;let g="",d="",p="";const h=et(t,!0),x=et(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;ot(t,n)&&!m.has(n)&&(m.add(n),ot(h,n)&&o.find(t=>t.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let e=0;e<o.length;e++){const n=nt(t,o[e].format),s=nt(x,o[e].format);if(n&&s)continue;const i=[...o];for(;i.length>e;){const t=i.pop();r&&t&&r.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?s||(p+=t.tag):d+=t.tag),o.pop())}break}return u&&!t.hasFormat("code")?d+i:d+c+g+a+p+f}function et(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function nt(t,n){return e(t)&&t.hasFormat(n)}function ot(t,e){return!!nt(t,e)&&("code"===e||(!t||!/^\s*$/.test(t.getTextContent())))}function rt(t,e){const n=t.getTextContent(),o=e.fullMatchRegExpByTag["`"],r=e.transformersByTag["`"],s=[];let i=null;if(o&&r){const t=new RegExp(o.source,"g"),e=Array.from(n.matchAll(t));for(const t of e){const e=t.index,n=e+t[0].length;i||(i={content:t[2],endIndex:n,startIndex:e,tag:"`"}),s.push({end:n,start:e})}}const l=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),s=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},i=t=>n.some(e=>t>=e.start&&t<e.end);let l=0;for(;l<t.length;){const e=t[l];if(!r.has(e)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=st(e,t,l,n,!0),a=st(e,t,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,s),c=l.length>0?function(t,e,n){const o={};let r=0,s=null;for(;r<e.length;){const i=e[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const l=`${i.char}${i.canOpen}`,c=o[l]??-1;let a=!1;for(let o=r-1;o>c;o--){const l=e[o];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if(l.canClose||i.canOpen){if((l.originalLength+i.originalLength)%3==0&&l.originalLength%3!=0&&i.originalLength%3!=0)continue}const c=Math.min(l.length,i.length),f=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!f)continue;a=!0;const u=f.length,g={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:f};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);for(let t=o+1;t<r;t++)e[t].active=!1;l.length-=u,i.length-=u,l.active=l.length>0,i.length>0?i.index+=u:(i.active=!1,r++);break}a||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,l,e):null;let a=null,f=null;if(i&&c?c.startIndex<=i.startIndex&&c.endIndex>=i.endIndex?(a=c,f=e.transformersByTag[c.tag]):(a=i,f=r):i?(a=i,f=r):c&&(a=c,f=e.transformersByTag[c.tag]),!a||!f)return null;const u=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return u.index=a.startIndex,u.input=n,{endIndex:a.endIndex,match:u,startIndex:a.startIndex,transformer:f}}function st(t,e,n,o,r){if(!it(e,n,o,r))return!1;if("*"===t)return!0;if("_"===t){if(!it(e,n,o,!r))return!0;const t=r?e[n-1]:e[n+o];return void 0!==t&&J.test(t)}return!0}function it(t,e,n,o){const r=t[e-1],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!H.test(i)&&(!J.test(i)||(void 0===l||H.test(l)||J.test(l)))}function lt(t){return e(t)&&!t.hasFormat("code")}function ct(t,e,n){let o=rt(t,e),r=function(t,e){const n=t;let o,r,s,i;for(const t of e){if(!t.replace||!t.importRegExp)continue;const e=n.getTextContent().match(t.importRegExp);if(!e)continue;const l=e.index||0,c=t.getEndIndex?t.getEndIndex(n,e):l+e[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&(c>r||c<=o))&&(o=l,r=c,s=t,i=e)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(t,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(t,e,n,o,r){const s=t.getTextContent();let i,l,c;if(r[0]===s?i=t:0===e?[i,l]=t.splitText(n):[c,i,l]=t.splitText(e,n),i.setTextContent(r[2]),o)for(const t of o.format)i.hasFormat(t)||i.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(t,o.startIndex,o.endIndex,o.transformer,o.match);lt(r.nodeAfter)&&ct(r.nodeAfter,e,n),lt(r.nodeBefore)&&ct(r.nodeBefore,e,n),lt(r.transformedNode)&&ct(r.transformedNode,e,n)}else if(r){const o=function(t,e,n,o,r){let s,i,l;return 0===e?[s,i]=t.splitText(n):[l,s,i]=t.splitText(e,n),o.replace?{nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;lt(o.nodeAfter)&&ct(o.nodeAfter,e,n),lt(o.nodeBefore)&&ct(o.nodeBefore,e,n),lt(o.transformedNode)&&ct(o.transformedNode,e,n)}const s=X(t.getTextContent());t.setTextContent(s)}function at(t,e=!1){const r=q(t),s=function(t){const e={},n={},o=[],r="(?<![\\\\])";for(const r of t){const{tag:t}=r;e[t]=r;const s=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===t.length?n[t]="`"===t?new RegExp("(?<![\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(?<![\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?![\\\\${s}])`):n[t]=new RegExp(`(?<!\\\\)(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)((?<!\\\\)|(?<=\\\\\\\\))(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:e}}(r.textFormat);return(t,l)=>{const c=t.split("\n"),a=c.length,f=l||n();f.clear();for(let t=0;t<a;t++){const n=c[t],[o,i]=ft(c,t,r.multilineElement,f);o?t=i:ut(n,f,r.element,s,r.textMatch,e)}const u=f.getChildren();for(const t of u)if(!e&&V(t)&&f.getChildrenSize()>1)t.remove();else if(o(t))for(const e of t.getAllTextNodes())gt(e);null!==i()&&f.selectStart()}}function ft(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=r,c=t[e].match(i);if(!c)continue;if(n){const s=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===s)continue;if(s)return s}const a="object"==typeof s&&"regExp"in s?s.regExp:s,f=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const g=t.length;for(;u<g;){const n=a?t[u].match(a):null;if(!n&&(!f||f&&u<g-1)){u++;continue}if(n&&e===u&&n.index===c.index){u++;continue}const r=[];if(n&&e===u)r.push(t[e].slice(c[0].length,-n[0].length));else for(let o=e;o<=u;o++)if(o===e){const e=t[o].slice(c[0].length);r.push(e)}else if(o===u&&n){const e=t[o].slice(0,-n[0].length);r.push(e)}else r.push(t[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,u];break}}return[!1,e]}function ut(n,o,r,s,i,f){const u=l(n),g=c();g.append(u),o.append(g);for(const{regExp:t,replace:e}of r){const o=n.match(t);if(o&&(u.setTextContent(n.slice(o[0].length)),!1!==e(g,[u],o,!0)))break}if(ct(u,s,i),g.isAttached()&&n.length>0){const n=g.getPreviousSibling();if(!f&&(t(n)||L(n)||I(n))){let t=n;if(I(n)){const e=n.getLastDescendant();t=null==e?null:O(e,S)}if(null!=t&&t.getTextContentSize()>0){const n=t.getLastChild();if(e(n)){const t=n.getTextContent();t.endsWith("\\")?n.setTextContent(t.slice(0,-1)):/ {2,}$/.test(t)&&n.setTextContent(t.replace(/ {2,}$/,""))}t.splice(t.getChildrenSize(),0,[a(),...g.getChildren()]),g.remove()}}}}function gt(t){const e=new Set,n=t.getTextContent();let o=n.indexOf("\t");for(;-1!==o;)e.add(o),e.add(o+1),o=n.indexOf("\t",o+1);t.splitText(...e).forEach(t=>{"\t"===t.getTextContent()&&t.replace(f())})}function dt(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const pt=/^(\s*)(\d{1,})\.\s/,ht=/^(\s*)[-*+]\s/,xt=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,mt=/^(#{1,6})\s/,Ct=/^>\s/,Tt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,$t=/^[ \t]*`{3,}$/,vt=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,yt=/^(?:\|)(.+)(?:\|)\s?$/,Et=/^(\| ?:?-*:? ?)+\|\s?$/,It=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,St=/^<\/[a-z_][\w-]*\s*>/i,bt=t=>new RegExp(`(?:${t.source})$`,t.flags),wt=u("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Nt=u("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),Ft=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};const Lt=t=>(e,n,o,r)=>{const s=e.getPreviousSibling(),i=e.getNextSibling(),l=N("check"===t?"x"===o[3]:void 0),c=o[0].trim()[0],a="bullet"!==t&&"check"!==t||c!==wt.parse(c)?void 0:c;if(I(i)&&i.getListType()===t){a&&g(i,wt,a);const t=i.getFirstChild();null!==t?t.insertBefore(l):i.append(l),e.remove()}else if(I(s)&&s.getListType()===t)a&&g(s,wt,a),s.append(l),e.remove();else{const n=F(t,"number"===t?Number(o[2]):void 0);a&&g(n,wt,a),n.append(l),e.replace(n)}l.append(...n),r||l.select(0,0);const f=function(t){const e=t.match(/\t/g),n=t.match(/ /g);let o=0;return e&&(o+=e.length),n&&(o+=Math.floor(n.length/4)),o}(o[1]);f&&l.setIndent(f)},kt=(t,e,n)=>{const o=[],r=t.getChildren();let s=0;for(const i of r)if(S(i)){if(1===i.getChildrenSize()){const t=i.getFirstChild();if(I(t)){o.push(kt(t,e,n+1));continue}}const r=" ".repeat(4*n),l=t.getListType(),c=d(t,wt),a="number"===l?`${t.getStart()+s}. `:"check"===l?`${c} [${i.getChecked()?"x":" "}] `:c+" ";o.push(r+a+e(i)),s++}return o.join("\n")},Rt={dependencies:[k],export:(t,e)=>{if(!M(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:mt,replace:Ft(t=>{const e="h"+t[1].length;return B(e)}),type:"element"},Mt={dependencies:[R],export:(t,e)=>{if(!L(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:Ct,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(L(n))return n.splice(n.getChildrenSize(),0,[a(),...e]),void t.remove()}const r=_();r.append(...e),t.replace(r),o||r.select(0,0)},type:"element"},_t={dependencies:[j],export:t=>{if(!P(t))return null;const e=t.getTextContent();let n=d(t,Nt);if(e.indexOf(n)>-1){const t=e.match(/`{3,}/g);if(t){const e=Math.max(...t.map(t=>t.length));n="`".repeat(e+1)}}return n+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n"+n},handleImportAfterStartMatch:({lines:t,rootNode:e,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=t[n],l=o.index+r.length,c=i.slice(l),a=new RegExp(`\`{${s},}$`);if(a.test(c)){const t=c.match(a),r=c.slice(0,c.lastIndexOf(t[0])),s=[...o];return s[2]="",_t.replace(e,null,s,t,[r],!0),[!0,n]}const f=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(f.test(s)){const l=s.match(f),c=t.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&c.unshift(a),_t.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),g=i.slice(o[0].length);return g.length>0&&u.unshift(g),_t.replace(e,null,o,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:$t},regExpStart:Tt,replace:(t,e,n,o,r,s)=>{let i,c;const a=n[1]?n[1].trim():"```",f=n[2]||void 0;if(!e&&r){if(1===r.length)o?(i=A(f),c=r[0]):(i=A(f),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{for(i=A(f),r.length>0&&(0===r[0].trim().length?r.shift():r[0].startsWith(" ")&&(r[0]=r[0].slice(1)));r.length>0&&!r[r.length-1].length;)r.pop();c=r.join("\n")}g(i,Nt,a);const e=l(c);i.append(e),t.append(i)}else e&&Ft(t=>A(t?t[2]:void 0))(t,e,n,s)},type:"multiline-element"},Bt={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:ht,replace:Lt("bullet"),type:"element"},Ot={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:xt,replace:Lt("check"),type:"element"},jt={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:pt,replace:Lt("number"),type:"element"},At={format:["code"],tag:"`",type:"text-format"},Pt={format:["highlight"],tag:"==",type:"text-format"},zt={format:["bold","italic"],tag:"***",type:"text-format"},Ut={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Wt={format:["bold"],tag:"**",type:"text-format"},Dt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Kt={format:["strikethrough"],tag:"~~",type:"text-format"},qt={format:["italic"],tag:"*",type:"text-format"},Gt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Ht={dependencies:[z],export:(t,e,n)=>{if(!U(t)||D(t))return null;const o=e(t);let r=t.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${t.getURL()} "${r}")`:`[${o}](${t.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,e)=>{if(p(t,U))return;const[,n,o,r]=e,s=null!=o?X(o):void 0,i=null!=r?X(r):void 0,c=W(s,{title:i}),a=n.split("[").length-1,f=n.split("]").length-1;let u=n,g="";if(a<f)return;if(a>f){const t=n.split("[");g="["+t[0],u=t.slice(1).join("[")}const d=l(u);return d.setFormat(t.getFormat()),c.append(d),t.replace(c),g&&c.insertBefore(l(g)),d},trigger:")",type:"text-match"},Jt=[Rt,Mt,Bt,jt],Qt=[_t],Vt=[At,zt,Ut,Wt,Dt,Pt,qt,Gt,Kt],Xt=[Ht],Yt=[...Jt,...Qt,...Vt,...Xt];function Zt(t,e,n,o,r){const s=t.getParent();if(!v(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!r&&" "!==i[n-1])return!1;for(const{regExpStart:s,replace:l,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=i.match(s);if(o){const s=r||o[0].endsWith(" ")?n:n-1;if(o[0].length!==s)continue;const i=e.getNextSiblings(),[c,a]=e.splitText(n);if(!1!==l(t,a?[a,...i]:i,o,null,null,!1))return c.remove(),!0}}return!1}function te(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(ee(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function ee(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function ne(t,n=Yt){const o=q(n),r=K(o.textFormat,({tag:t})=>t[t.length-1]),l=K(o.textMatch,({trigger:t})=>t);for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||dt(173,e.getType())}}const c=(t,n,c)=>{(function(t,e,n,o){const r=t.getParent();if(!v(r)||t.getFirstChild()!==e)return!1;const s=e.getTextContent();if(" "!==s[n-1])return!1;for(const{regExp:r,replace:i}of o){const o=s.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[s,l]=e.splitText(n);if(!1!==i(t,l?[l,...r]:r,o,!1))return s.remove(),!0}}return!1})(t,n,c,o.element)||Zt(t,n,c,o.multilineElement)||function(t,e,n){let o=t.getTextContent();const r=n[o[e-1]];if(null==r)return!1;e<o.length&&(o=o.slice(0,e));for(const e of r){if(!e.replace||!e.regExp)continue;const n=o.match(e.regExp);if(null===n)continue;const r=n.index||0,s=r+n[0].length;let i;return 0===r?[i]=t.splitText(s):[,i]=t.splitText(r,s),i.selectNext(0,0),e.replace(i,n),!0}return!1}(n,c,l)||function(t,n,o){const r=t.getTextContent(),l=n-1,c=r[l],a=o[c];if(!a)return!1;for(const n of a){const{tag:o}=n,a=o.length,f=l-a+1;if(a>1&&!ee(r,f,o,0,a))continue;if(" "===r[f-1])continue;const u=r[l+1];if(!1===n.intraword&&u&&!G.test(u))continue;const g=t;let d=g,p=te(r,f,o),h=d;for(;p<0&&(h=h.getPreviousSibling())&&!s(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,p=te(t,t.length,o)}if(p<0)continue;if(d===g&&p+a===f)continue;const x=d.getTextContent();if(p>0&&x[p-1]===c)continue;const m=x[p-1];if(!1===n.intraword&&m&&!G.test(m))continue;const T=g.getTextContent(),$=T.slice(0,f)+T.slice(l+1);g.setTextContent($);const v=d===g?$:x;d.setTextContent(v.slice(0,p)+v.slice(p+a));const I=i(),S=y();E(S);const b=l-a*(d===g?2:1)+1;S.anchor.set(d.__key,p,"text"),S.focus.set(g.__key,b,"text");for(const t of n.format)S.hasFormat(t)||S.formatText(t);S.anchor.set(S.focus.key,S.focus.offset,S.focus.type);for(const t of n.format)S.hasFormat(t)&&S.toggleFormat(t);return C(I)&&(S.format=I.format),!0}}(n,c,r)};return h(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:s})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const l=r.read(i),a=s.read(i);if(!C(a)||!C(l)||!l.isCollapsed()||l.is(a))return;const f=l.anchor.key,u=l.anchor.offset,g=r._nodeMap.get(f);!e(g)||!o.has(f)||1!==u&&u>a.anchor.offset+1||t.update(()=>{if(!lt(g))return;const t=g.getParent();null===t||P(t)||c(t,g,l.anchor.offset)})}),t.registerCommand(T,t=>{if(null!==t&&t.shiftKey)return!1;const n=i();if(!C(n)||!n.isCollapsed())return!1;const r=n.anchor.offset,s=n.anchor.getNode();if(!e(s)||!lt(s))return!1;const l=s.getParent();if(null===l||P(l))return!1;return r===s.getTextContent().length&&(!!Zt(l,s,r,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},$))}function oe(t,e=Yt,n,o=!1,r=!1){const s=o?t:function(t,e=!1){const n=t.split("\n");let o=!1;const r=[];for(let t=0;t<n.length;t++){const s=n[t],i=s.trimEnd(),l=r[r.length-1];vt.test(i)?r.push(i):Tt.test(i)||$t.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===l||!l||mt.test(l)||mt.test(i)||Ct.test(i)||pt.test(i)||ht.test(i)||xt.test(i)||yt.test(i)||Et.test(i)||!e||It.test(i)||St.test(i)||bt(St).test(l)||bt(It).test(l)||$t.test(l)?r.push(e||""===i?i:s):r[r.length-1]=l+" "+i.trimStart()}return r.join("\n")}(t,r);return at(e,o)(s,n)}function re(t=Yt,e,o=!1){const r=function(t,e=!1){const o=q(t),r=[...o.multilineElement,...o.element],s=!e,i=o.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const l=[],c=(t||n()).getChildren();for(let t=0;t<c.length;t++){const n=c[t],a=Y(n,r,i,o.textMatch,e);null!=a&&l.push(s&&t>0&&!V(n)&&!V(c[t-1])?"\n".concat(a):a)}return l.join("\n")}}(t,o);return r(e)}export{oe as $convertFromMarkdownString,re as $convertToMarkdownString,zt as BOLD_ITALIC_STAR,Ut as BOLD_ITALIC_UNDERSCORE,Wt as BOLD_STAR,Dt as BOLD_UNDERSCORE,Ot as CHECK_LIST,_t as CODE,Jt as ELEMENT_TRANSFORMERS,Rt as HEADING,Pt as HIGHLIGHT,At as INLINE_CODE,qt as ITALIC_STAR,Gt as ITALIC_UNDERSCORE,Ht as LINK,Qt as MULTILINE_ELEMENT_TRANSFORMERS,jt as ORDERED_LIST,Mt as QUOTE,Kt as STRIKETHROUGH,Vt as TEXT_FORMAT_TRANSFORMERS,Xt as TEXT_MATCH_TRANSFORMERS,Yt as TRANSFORMERS,Bt as UNORDERED_LIST,ne as registerMarkdownShortcuts};
|
|
9
|
+
import{$isParagraphNode as t,$isTextNode as e,$getRoot as n,$isElementNode as o,$isDecoratorNode as r,$isLineBreakNode as s,$getSelection as i,$createTextNode as l,$createParagraphNode as c,$createLineBreakNode as a,$createTabNode as f,createState as u,$setState as g,$getState as d,$findMatchingParent as p,mergeRegister as h,COLLABORATION_TAG as x,HISTORIC_TAG as m,$isRangeSelection as C,KEY_ENTER_COMMAND as T,COMMAND_PRIORITY_LOW as v,$isRootOrShadowRoot as $,$createRangeSelection as y,$setSelection as E}from"lexical";import{$isListNode as I,$isListItemNode as S,ListNode as b,ListItemNode as w,$createListItemNode as N,$createListNode as F}from"@lexical/list";import{$isQuoteNode as L,HeadingNode as k,QuoteNode as R,$isHeadingNode as M,$createQuoteNode as _,$createHeadingNode as B}from"@lexical/rich-text";import{$findMatchingParent as O}from"@lexical/utils";import{CodeNode as j,$createCodeNode as A,$isCodeNode as P}from"@lexical/code-core";import{LinkNode as z,$isLinkNode as U,$createLinkNode as W,$isAutoLinkNode as D}from"@lexical/link";function K(t,e){const n={};for(const o of t){const t=e(o);t&&(n[t]?n[t].push(o):n[t]=[o])}return n}function q(t){const e=K(t,t=>t.type);return{element:e.element||[],multilineElement:e["multiline-element"]||[],textFormat:e["text-format"]||[],textMatch:e["text-match"]||[]}}const G=/[!-/:-@[-`{-~\s]/,H=/[ \t\n\r\f]/,J=/[!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~]/,Q=/^\s{0,3}$/;function V(n){if(!t(n))return!1;const o=n.getFirstChild();return null==o||1===n.getChildrenSize()&&e(o)&&Q.test(o.getTextContent())}function X(t){return t.replace(/\\([!-/:-@[-`{-~])/g,"$1").replace(/&#(\d+);/g,(t,e)=>String.fromCodePoint(Number(e)))}function Y(t,e,n,s,i){for(const o of e){if(!o.export)continue;const e=o.export(t,t=>Z(t,n,s,void 0,void 0,i));if(null!=e)return e}return o(t)?Z(t,n,s,void 0,void 0,i):r(t)?t.getTextContent():null}function Z(t,n,i,l,c,a=!1){const f=[],u=t.getChildren();l||(l=[]),c||(c=[]);t:for(const t of u){for(const e of i){if(!e.export)continue;const o=e.export(t,t=>Z(t,n,i,l,[...c,...l],a),(t,e)=>tt(t,e,n,l,c,a));if(null!=o){f.push(o);continue t}}s(t)?f.push("\n"):e(t)?f.push(tt(t,t.getTextContent(),n,l,c,a)):o(t)?f.push(Z(t,n,i,l,c,a)):r(t)&&f.push(t.getTextContent())}return f.join("")}function tt(t,e,n,o,r,s=!1){let i=e;t.hasFormat("code")||(i=s?i.replace(/([*_`~])/g,"\\$1"):i.replace(/([*_`~\\])/g,"\\$1"));const l=i.match(/^(\s*)(.*?)(\s*)$/s)||["","",i,""],c=l[1],a=l[2],f=l[3],u=""===a;let g="",d="",p="";const h=et(t,!0),x=et(t,!1),m=new Set;for(const e of n){const n=e.format[0],r=e.tag;ot(t,n)&&!m.has(n)&&(m.add(n),ot(h,n)&&o.find(t=>t.tag===r)||(o.push({format:n,tag:r}),g+=r))}for(let e=0;e<o.length;e++){const n=nt(t,o[e].format),s=nt(x,o[e].format);if(n&&s)continue;const i=[...o];for(;i.length>e;){const t=i.pop();r&&t&&r.find(e=>e.tag===t.tag)||(t&&"string"==typeof t.tag&&(n?s||(p+=t.tag):d+=t.tag),o.pop())}break}return u&&!t.hasFormat("code")?d+i:d+c+g+a+p+f}function et(t,n){const o=n?t.getPreviousSibling():t.getNextSibling();return e(o)?o:null}function nt(t,n){return e(t)&&t.hasFormat(n)}function ot(t,e){return!!nt(t,e)&&("code"===e||(!t||!/^\s*$/.test(t.getTextContent())))}function rt(t,e){const n=t.getTextContent(),o=e.fullMatchRegExpByTag["`"],r=e.transformersByTag["`"],s=[];let i=null;if(o&&r){const t=new RegExp(o.source,"g"),e=Array.from(n.matchAll(t));for(const t of e){const e=t.index+t[1].length,n=t.index+t[0].length;i||(i={content:t[3],endIndex:n,startIndex:e,tag:"`"}),s.push({end:n,start:e})}}const l=function(t,e,n=[]){const o=[],r=new Set(Object.keys(e.transformersByTag).filter(t=>"`"!==t[0]).map(t=>t[0])),s=e=>{let n=0;for(let o=e-1;o>=0&&"\\"===t[o];o--)n++;return n%2==1},i=t=>n.some(e=>t>=e.start&&t<e.end);let l=0;for(;l<t.length;){const e=t[l];if(!r.has(e)||s(l)||i(l)){l++;continue}let n=1;for(;l+n<t.length&&t[l+n]===e;)n++;const c=st(e,t,l,n,!0),a=st(e,t,l,n,!1);(c||a)&&o.push({active:!0,canClose:a,canOpen:c,char:e,index:l,length:n,originalLength:n}),l+=n}return o}(n,e,s),c=l.length>0?function(t,e,n){const o={};let r=0,s=null;for(;r<e.length;){const i=e[r];if(!i.active||!i.canClose||0===i.length){r++;continue}const l=`${i.char}${i.canOpen}`,c=o[l]??-1;let a=!1;for(let o=r-1;o>c;o--){const l=e[o];if(!l.active||!l.canOpen||0===l.length||l.char!==i.char)continue;if(l.canClose||i.canOpen){if((l.originalLength+i.originalLength)%3==0&&l.originalLength%3!=0&&i.originalLength%3!=0)continue}const c=Math.min(l.length,i.length),f=Object.keys(n.transformersByTag).filter(t=>t[0]===l.char&&t.length<=c).sort((t,e)=>e.length-t.length)[0];if(!f)continue;a=!0;const u=f.length,g={content:t.slice(l.index+l.length,i.index),endIndex:i.index+u,startIndex:l.index+(l.length-u),tag:f};(!s||g.startIndex<s.startIndex||g.startIndex===s.startIndex&&g.endIndex>s.endIndex)&&(s=g);for(let t=o+1;t<r;t++)e[t].active=!1;l.length-=u,i.length-=u,l.active=l.length>0,i.length>0?i.index+=u:(i.active=!1,r++);break}a||(o[l]=r-1,i.canOpen||(i.active=!1),r++)}return s}(n,l,e):null;let a=null,f=null;if(i&&c?c.startIndex<=i.startIndex&&c.endIndex>=i.endIndex?(a=c,f=e.transformersByTag[c.tag]):(a=i,f=r):i?(a=i,f=r):c&&(a=c,f=e.transformersByTag[c.tag]),!a||!f)return null;const u=[n.slice(a.startIndex,a.endIndex),a.tag,a.content];return u.index=a.startIndex,u.input=n,{endIndex:a.endIndex,match:u,startIndex:a.startIndex,transformer:f}}function st(t,e,n,o,r){if(!it(e,n,o,r))return!1;if("*"===t)return!0;if("_"===t){if(!it(e,n,o,!r))return!0;const t=r?e[n-1]:e[n+o];return void 0!==t&&J.test(t)}return!0}function it(t,e,n,o){const r=t[e-1],s=t[e+n],[i,l]=o?[s,r]:[r,s];return void 0!==i&&!H.test(i)&&(!J.test(i)||(void 0===l||H.test(l)||J.test(l)))}function lt(t){return e(t)&&!t.hasFormat("code")}function ct(t,e,n){let o=rt(t,e),r=function(t,e){const n=t;let o,r,s,i;for(const t of e){if(!t.replace||!t.importRegExp)continue;const e=n.getTextContent().match(t.importRegExp);if(!e)continue;const l=e.index||0,c=t.getEndIndex?t.getEndIndex(n,e):l+e[0].length;!1!==c&&(void 0===o||void 0===r||l<o&&(c>r||c<=o))&&(o=l,r=c,s=t,i=e)}return void 0===o||void 0===r||void 0===s||void 0===i?null:{endIndex:r,match:i,startIndex:o,transformer:s}}(t,n);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex||r.startIndex>o.endIndex?r=null:o=null),o){const r=function(t,e,n,o,r){const s=t.getTextContent();let i,l,c;if(r[0]===s?i=t:0===e?[i,l]=t.splitText(n):[c,i,l]=t.splitText(e,n),i.setTextContent(r[2]),o)for(const t of o.format)i.hasFormat(t)||i.toggleFormat(t);return{nodeAfter:l,nodeBefore:c,transformedNode:i}}(t,o.startIndex,o.endIndex,o.transformer,o.match);lt(r.nodeAfter)&&ct(r.nodeAfter,e,n),lt(r.nodeBefore)&&ct(r.nodeBefore,e,n),lt(r.transformedNode)&&ct(r.transformedNode,e,n)}else if(r){const o=function(t,e,n,o,r){let s,i,l;return 0===e?[s,i]=t.splitText(n):[l,s,i]=t.splitText(e,n),o.replace?{nodeAfter:i,nodeBefore:l,transformedNode:o.replace(s,r)||void 0}:null}(t,r.startIndex,r.endIndex,r.transformer,r.match);if(!o)return;lt(o.nodeAfter)&&ct(o.nodeAfter,e,n),lt(o.nodeBefore)&&ct(o.nodeBefore,e,n),lt(o.transformedNode)&&ct(o.transformedNode,e,n)}const s=X(t.getTextContent());t.setTextContent(s)}function at(t,e=!1){const r=q(t),s=function(t){const e={},n={},o=[];for(const r of t){const{tag:t}=r;e[t]=r;const s=t.replace(/(\*|\^|\+)/g,"\\$1");o.push(s),1===t.length?n[t]="`"===t?new RegExp("(^|[^\\\\`])(`)((?:\\\\`|[^`])+?)(`)(?!`)"):new RegExp(`(^|[^\\\\${s}])(${s})((\\\\${s})?.*?[^${s}\\s](\\\\${s})?)(${s})(?![\\\\${s}])`):n[t]=new RegExp(`(^|[^\\\\])(${s})((\\\\${s})?.*?[^\\s](\\\\${s})?)(${s})(?!\\\\)`)}return{fullMatchRegExpByTag:n,openTagsRegExp:new RegExp(`(${o.join("|")})`,"g"),transformersByTag:e}}(r.textFormat);return(t,l)=>{const c=t.split("\n"),a=c.length,f=l||n();f.clear();for(let t=0;t<a;t++){const n=c[t],[o,i]=ft(c,t,r.multilineElement,f);o?t=i:ut(n,f,r.element,s,r.textMatch,e)}const u=f.getChildren();for(const t of u)if(!e&&V(t)&&f.getChildrenSize()>1)t.remove();else if(o(t))for(const e of t.getAllTextNodes())gt(e);null!==i()&&f.selectStart()}}function ft(t,e,n,o){for(const r of n){const{handleImportAfterStartMatch:n,regExpEnd:s,regExpStart:i,replace:l}=r,c=t[e].match(i);if(!c)continue;if(n){const s=n({lines:t,rootNode:o,startLineIndex:e,startMatch:c,transformer:r});if(null===s)continue;if(s)return s}const a="object"==typeof s&&"regExp"in s?s.regExp:s,f=s&&"object"==typeof s&&"optional"in s?s.optional:!s;let u=e;const g=t.length;for(;u<g;){const n=a?t[u].match(a):null;if(!n&&(!f||f&&u<g-1)){u++;continue}if(n&&e===u&&n.index===c.index){u++;continue}const r=[];if(n&&e===u)r.push(t[e].slice(c[0].length,-n[0].length));else for(let o=e;o<=u;o++)if(o===e){const e=t[o].slice(c[0].length);r.push(e)}else if(o===u&&n){const e=t[o].slice(0,-n[0].length);r.push(e)}else r.push(t[o]);if(!1!==l(o,null,c,n,r,!0))return[!0,u];break}}return[!1,e]}function ut(n,o,r,s,i,f){const u=l(n),g=c();g.append(u),o.append(g);for(const{regExp:t,replace:e}of r){const o=n.match(t);if(o&&(u.setTextContent(n.slice(o[0].length)),!1!==e(g,[u],o,!0)))break}if(ct(u,s,i),g.isAttached()&&n.length>0){const n=g.getPreviousSibling();if(!f&&(t(n)||L(n)||I(n))){let t=n;if(I(n)){const e=n.getLastDescendant();t=null==e?null:O(e,S)}if(null!=t&&t.getTextContentSize()>0){const n=t.getLastChild();if(e(n)){const t=n.getTextContent();t.endsWith("\\")?n.setTextContent(t.slice(0,-1)):/ {2,}$/.test(t)&&n.setTextContent(t.replace(/ {2,}$/,""))}t.splice(t.getChildrenSize(),0,[a(),...g.getChildren()]),g.remove()}}}}function gt(t){const e=new Set,n=t.getTextContent();let o=n.indexOf("\t");for(;-1!==o;)e.add(o),e.add(o+1),o=n.indexOf("\t",o+1);t.splitText(...e).forEach(t=>{"\t"===t.getTextContent()&&t.replace(f())})}function dt(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const pt=/^(\s*)(\d{1,})\.\s/,ht=/^(\s*)[-*+]\s/,xt=/^(\s*)(?:[-*+]\s)?\s?(\[(\s|x)?\])\s/i,mt=/^(#{1,6})\s/,Ct=/^>\s/,Tt=/^([ \t]*`{3,})([\w-]+)?[ \t]?/,vt=/^[ \t]*`{3,}$/,$t=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,yt=/^(?:\|)(.+)(?:\|)\s?$/,Et=/^(\| ?:?-*:? ?)+\|\s?$/,It=/^<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,St=/^<\/[a-z_][\w-]*\s*>/i,bt=t=>new RegExp(`(?:${t.source})$`,t.flags),wt=u("mdListMarker",{parse:t=>"string"==typeof t&&/^[-*+]$/.test(t)?t:"-",resetOnCopyNode:!0}),Nt=u("mdCodeFence",{parse:t=>"string"==typeof t&&/^`{3,}$/.test(t)?t:"```",resetOnCopyNode:!0}),Ft=t=>(e,n,o,r)=>{const s=t(o);s.append(...n),e.replace(s),r||s.select(0,0)};const Lt=t=>(e,n,o,r)=>{const s=e.getPreviousSibling(),i=e.getNextSibling(),l=N("check"===t?"x"===o[3]:void 0),c=o[0].trim()[0],a="bullet"!==t&&"check"!==t||c!==wt.parse(c)?void 0:c;if(I(i)&&i.getListType()===t){a&&g(i,wt,a);const t=i.getFirstChild();null!==t?t.insertBefore(l):i.append(l),e.remove()}else if(I(s)&&s.getListType()===t)a&&g(s,wt,a),s.append(l),e.remove();else{const n=F(t,"number"===t?Number(o[2]):void 0);a&&g(n,wt,a),n.append(l),e.replace(n)}l.append(...n),r||l.select(0,0);const f=function(t){const e=t.match(/\t/g),n=t.match(/ /g);let o=0;return e&&(o+=e.length),n&&(o+=Math.floor(n.length/4)),o}(o[1]);f&&l.setIndent(f)},kt=(t,e,n)=>{const o=[],r=t.getChildren();let s=0;for(const i of r)if(S(i)){if(1===i.getChildrenSize()){const t=i.getFirstChild();if(I(t)){o.push(kt(t,e,n+1));continue}}const r=" ".repeat(4*n),l=t.getListType(),c=d(t,wt),a="number"===l?`${t.getStart()+s}. `:"check"===l?`${c} [${i.getChecked()?"x":" "}] `:c+" ";o.push(r+a+e(i)),s++}return o.join("\n")},Rt={dependencies:[k],export:(t,e)=>{if(!M(t))return null;const n=Number(t.getTag().slice(1));return"#".repeat(n)+" "+e(t)},regExp:mt,replace:Ft(t=>{const e="h"+t[1].length;return B(e)}),type:"element"},Mt={dependencies:[R],export:(t,e)=>{if(!L(t))return null;const n=e(t).split("\n"),o=[];for(const t of n)o.push("> "+t);return o.join("\n")},regExp:Ct,replace:(t,e,n,o)=>{if(o){const n=t.getPreviousSibling();if(L(n))return n.splice(n.getChildrenSize(),0,[a(),...e]),void t.remove()}const r=_();r.append(...e),t.replace(r),o||r.select(0,0)},type:"element"},_t={dependencies:[j],export:t=>{if(!P(t))return null;const e=t.getTextContent();let n=d(t,Nt);if(e.indexOf(n)>-1){const t=e.match(/`{3,}/g);if(t){const e=Math.max(...t.map(t=>t.length));n="`".repeat(e+1)}}return n+(t.getLanguage()||"")+(e?"\n"+e:"")+"\n"+n},handleImportAfterStartMatch:({lines:t,rootNode:e,startLineIndex:n,startMatch:o})=>{const r=o[1],s=r.trim().length,i=t[n],l=o.index+r.length,c=i.slice(l),a=new RegExp(`\`{${s},}$`);if(a.test(c)){const t=c.match(a),r=c.slice(0,c.lastIndexOf(t[0])),s=[...o];return s[2]="",_t.replace(e,null,s,t,[r],!0),[!0,n]}const f=new RegExp(`^[ \\t]*\`{${s},}$`);for(let r=n+1;r<t.length;r++){const s=t[r];if(f.test(s)){const l=s.match(f),c=t.slice(n+1,r),a=i.slice(o[0].length);return a.length>0&&c.unshift(a),_t.replace(e,null,o,l,c,!0),[!0,r]}}const u=t.slice(n+1),g=i.slice(o[0].length);return g.length>0&&u.unshift(g),_t.replace(e,null,o,null,u,!0),[!0,t.length-1]},regExpEnd:{optional:!0,regExp:vt},regExpStart:Tt,replace:(t,e,n,o,r,s)=>{let i,c;const a=n[1]?n[1].trim():"```",f=n[2]||void 0;if(!e&&r){if(1===r.length)o?(i=A(f),c=r[0]):(i=A(f),c=r[0].startsWith(" ")?r[0].slice(1):r[0]);else{for(i=A(f),r.length>0&&(0===r[0].trim().length?r.shift():r[0].startsWith(" ")&&(r[0]=r[0].slice(1)));r.length>0&&!r[r.length-1].length;)r.pop();c=r.join("\n")}g(i,Nt,a);const e=l(c);i.append(e),t.append(i)}else e&&Ft(t=>A(t?t[2]:void 0))(t,e,n,s)},type:"multiline-element"},Bt={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:ht,replace:Lt("bullet"),type:"element"},Ot={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:xt,replace:Lt("check"),type:"element"},jt={dependencies:[b,w],export:(t,e)=>I(t)?kt(t,e,0):null,regExp:pt,replace:Lt("number"),type:"element"},At={format:["code"],tag:"`",type:"text-format"},Pt={format:["highlight"],tag:"==",type:"text-format"},zt={format:["bold","italic"],tag:"***",type:"text-format"},Ut={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},Wt={format:["bold"],tag:"**",type:"text-format"},Dt={format:["bold"],intraword:!1,tag:"__",type:"text-format"},Kt={format:["strikethrough"],tag:"~~",type:"text-format"},qt={format:["italic"],tag:"*",type:"text-format"},Gt={format:["italic"],intraword:!1,tag:"_",type:"text-format"},Ht={dependencies:[z],export:(t,e,n)=>{if(!U(t)||D(t))return null;const o=e(t);let r=t.getTitle();null!=r&&(r=r.replace(/([\\"])/g,"\\$1"));return r?`[${o}](${t.getURL()} "${r}")`:`[${o}](${t.getURL()})`},importRegExp:/(?:\[(.+?)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))/,regExp:/(?:\[([^[\]]*(?:\[[^[\]]*\][^[\]]*)*)\])(?:\((?:([^()\s]+)(?:\s"((?:[^"]*\\")*[^"]*)"\s*)?)\))$/,replace:(t,e)=>{if(p(t,U))return;const[,n,o,r]=e,s=null!=o?X(o):void 0,i=null!=r?X(r):void 0,c=W(s,{title:i}),a=n.split("[").length-1,f=n.split("]").length-1;let u=n,g="";if(a<f)return;if(a>f){const t=n.split("[");g="["+t[0],u=t.slice(1).join("[")}const d=l(u);return d.setFormat(t.getFormat()),c.append(d),t.replace(c),g&&c.insertBefore(l(g)),d},trigger:")",type:"text-match"},Jt=[Rt,Mt,Bt,jt],Qt=[_t],Vt=[At,zt,Ut,Wt,Dt,Pt,qt,Gt,Kt],Xt=[Ht],Yt=[...Jt,...Qt,...Vt,...Xt];function Zt(t,e,n,o,r){const s=t.getParent();if(!$(s)||t.getFirstChild()!==e)return!1;const i=e.getTextContent();if(!r&&" "!==i[n-1])return!1;for(const{regExpStart:s,replace:l,regExpEnd:c}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;const o=i.match(s);if(o){const s=r||o[0].endsWith(" ")?n:n-1;if(o[0].length!==s)continue;const i=e.getNextSiblings(),[c,a]=e.splitText(n);if(!1!==l(t,a?[a,...i]:i,o,null,null,!1))return c.remove(),!0}}return!1}function te(t,e,n){const o=n.length;for(let r=e;r>=o;r--){const e=r-o;if(ee(t,e,n,0,o)&&" "!==t[e+o])return e}return-1}function ee(t,e,n,o,r){for(let s=0;s<r;s++)if(t[e+s]!==n[o+s])return!1;return!0}function ne(t,n=Yt){const o=q(n),r=K(o.textFormat,({tag:t})=>t[t.length-1]),l=K(o.textMatch,({trigger:t})=>t);for(const e of n){const n=e.type;if("element"===n||"text-match"===n||"multiline-element"===n){const n=e.dependencies;for(const e of n)t.hasNode(e)||dt(173,e.getType())}}const c=(t,n,c)=>{(function(t,e,n,o){const r=t.getParent();if(!$(r)||t.getFirstChild()!==e)return!1;const s=e.getTextContent();if(" "!==s[n-1])return!1;for(const{regExp:r,replace:i}of o){const o=s.match(r);if(o&&o[0].length===(o[0].endsWith(" ")?n:n-1)){const r=e.getNextSiblings(),[s,l]=e.splitText(n);if(!1!==i(t,l?[l,...r]:r,o,!1))return s.remove(),!0}}return!1})(t,n,c,o.element)||Zt(t,n,c,o.multilineElement)||function(t,e,n){let o=t.getTextContent();const r=n[o[e-1]];if(null==r)return!1;e<o.length&&(o=o.slice(0,e));for(const e of r){if(!e.replace||!e.regExp)continue;const n=o.match(e.regExp);if(null===n)continue;const r=n.index||0,s=r+n[0].length;let i;return 0===r?[i]=t.splitText(s):[,i]=t.splitText(r,s),i.selectNext(0,0),e.replace(i,n),!0}return!1}(n,c,l)||function(t,n,o){const r=t.getTextContent(),l=n-1,c=r[l],a=o[c];if(!a)return!1;for(const n of a){const{tag:o}=n,a=o.length,f=l-a+1;if(a>1&&!ee(r,f,o,0,a))continue;if(" "===r[f-1])continue;const u=r[l+1];if(!1===n.intraword&&u&&!G.test(u))continue;const g=t;let d=g,p=te(r,f,o),h=d;for(;p<0&&(h=h.getPreviousSibling())&&!s(h);)if(e(h)){if(h.hasFormat("code"))continue;const t=h.getTextContent();d=h,p=te(t,t.length,o)}if(p<0)continue;if(d===g&&p+a===f)continue;const x=d.getTextContent();if(p>0&&x[p-1]===c)continue;const m=x[p-1];if(!1===n.intraword&&m&&!G.test(m))continue;const T=g.getTextContent(),v=T.slice(0,f)+T.slice(l+1);g.setTextContent(v);const $=d===g?v:x;d.setTextContent($.slice(0,p)+$.slice(p+a));const I=i(),S=y();E(S);const b=l-a*(d===g?2:1)+1;S.anchor.set(d.__key,p,"text"),S.focus.set(g.__key,b,"text");for(const t of n.format)S.hasFormat(t)||S.formatText(t);S.anchor.set(S.focus.key,S.focus.offset,S.focus.type);for(const t of n.format)S.hasFormat(t)&&S.toggleFormat(t);return C(I)&&(S.format=I.format),!0}}(n,c,r)};return h(t.registerUpdateListener(({tags:n,dirtyLeaves:o,editorState:r,prevEditorState:s})=>{if(n.has(x)||n.has(m))return;if(t.isComposing())return;const l=r.read(i),a=s.read(i);if(!C(a)||!C(l)||!l.isCollapsed()||l.is(a))return;const f=l.anchor.key,u=l.anchor.offset,g=r._nodeMap.get(f);!e(g)||!o.has(f)||1!==u&&u>a.anchor.offset+1||t.update(()=>{if(!lt(g))return;const t=g.getParent();null===t||P(t)||c(t,g,l.anchor.offset)})}),t.registerCommand(T,t=>{if(null!==t&&t.shiftKey)return!1;const n=i();if(!C(n)||!n.isCollapsed())return!1;const r=n.anchor.offset,s=n.anchor.getNode();if(!e(s)||!lt(s))return!1;const l=s.getParent();if(null===l||P(l))return!1;return r===s.getTextContent().length&&(!!Zt(l,s,r,o.multilineElement,!0)&&(null!==t&&t.preventDefault(),!0))},v))}function oe(t,e=Yt,n,o=!1,r=!1){const s=o?t:function(t,e=!1){const n=t.split("\n");let o=!1;const r=[];for(let t=0;t<n.length;t++){const s=n[t],i=s.trimEnd(),l=r[r.length-1];$t.test(i)?r.push(i):Tt.test(i)||vt.test(i)?(o=!o,r.push(i)):o?r.push(s):""===i||""===l||!l||mt.test(l)||mt.test(i)||Ct.test(i)||pt.test(i)||ht.test(i)||xt.test(i)||yt.test(i)||Et.test(i)||!e||It.test(i)||St.test(i)||bt(St).test(l)||bt(It).test(l)||vt.test(l)?r.push(e||""===i?i:s):r[r.length-1]=l+" "+i.trimStart()}return r.join("\n")}(t,r);return at(e,o)(s,n)}function re(t=Yt,e,o=!1){const r=function(t,e=!1){const o=q(t),r=[...o.multilineElement,...o.element],s=!e,i=o.textFormat.filter(t=>1===t.format.length).sort((t,e)=>Number(t.format.includes("code"))-Number(e.format.includes("code")));return t=>{const l=[],c=(t||n()).getChildren();for(let t=0;t<c.length;t++){const n=c[t],a=Y(n,r,i,o.textMatch,e);null!=a&&l.push(s&&t>0&&!V(n)&&!V(c[t-1])?"\n".concat(a):a)}return l.join("\n")}}(t,o);return r(e)}export{oe as $convertFromMarkdownString,re as $convertToMarkdownString,zt as BOLD_ITALIC_STAR,Ut as BOLD_ITALIC_UNDERSCORE,Wt as BOLD_STAR,Dt as BOLD_UNDERSCORE,Ot as CHECK_LIST,_t as CODE,Jt as ELEMENT_TRANSFORMERS,Rt as HEADING,Pt as HIGHLIGHT,At as INLINE_CODE,qt as ITALIC_STAR,Gt as ITALIC_UNDERSCORE,Ht as LINK,Qt as MULTILINE_ELEMENT_TRANSFORMERS,jt as ORDERED_LIST,Mt as QUOTE,Kt as STRIKETHROUGH,Vt as TEXT_FORMAT_TRANSFORMERS,Xt as TEXT_MATCH_TRANSFORMERS,Yt as TRANSFORMERS,Bt as UNORDERED_LIST,ne as registerMarkdownShortcuts};
|
package/package.json
CHANGED
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.43.0",
|
|
11
|
+
"version": "0.43.1-nightly.20260413.0",
|
|
12
12
|
"main": "LexicalMarkdown.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/code-core": "0.43.0",
|
|
16
|
-
"@lexical/link": "0.43.0",
|
|
17
|
-
"@lexical/list": "0.43.0",
|
|
18
|
-
"@lexical/rich-text": "0.43.0",
|
|
19
|
-
"@lexical/text": "0.43.0",
|
|
20
|
-
"@lexical/utils": "0.43.0",
|
|
21
|
-
"lexical": "0.43.0"
|
|
15
|
+
"@lexical/code-core": "0.43.1-nightly.20260413.0",
|
|
16
|
+
"@lexical/link": "0.43.1-nightly.20260413.0",
|
|
17
|
+
"@lexical/list": "0.43.1-nightly.20260413.0",
|
|
18
|
+
"@lexical/rich-text": "0.43.1-nightly.20260413.0",
|
|
19
|
+
"@lexical/text": "0.43.1-nightly.20260413.0",
|
|
20
|
+
"@lexical/utils": "0.43.1-nightly.20260413.0",
|
|
21
|
+
"lexical": "0.43.1-nightly.20260413.0"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|