@lexical/code-core 0.51.1-nightly.20260925.0 → 0.52.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/README.md +19 -0
- package/dist/LexicalCodeCore.prod.js +2 -2
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -5,3 +5,22 @@
|
|
|
5
5
|
This package contains the base functionality for the code blocks and code highlighting for Lexical. This package
|
|
6
6
|
is considered an implementation detail and is being used transitionally while the deprecated highlighting
|
|
7
7
|
functionality is still available in `@lexical/code`.
|
|
8
|
+
|
|
9
|
+
## Caret scrolling
|
|
10
|
+
|
|
11
|
+
When Lexical moves the caret itself, it scrolls the code block sideways to show the caret. That happens on the line
|
|
12
|
+
start and end keys in a code block (Home and End, or Cmd+Left and Cmd+Right on macOS), on Enter, on paste and on undo.
|
|
13
|
+
It also happens while you type in a highlighted code block, because the highlighter retokenizes the line and Lexical
|
|
14
|
+
puts the caret back. Plain arrow keys and clicks move the caret natively, and the browser scrolls for them. Extending a
|
|
15
|
+
selection with Shift does not scroll sideways.
|
|
16
|
+
|
|
17
|
+
When the block scrolls back toward the start of the line and the caret would also fit with it scrolled all the way back,
|
|
18
|
+
it goes all the way back. That shows the whole indentation, which Home and Enter leave the caret after. Otherwise it
|
|
19
|
+
scrolls just far enough, and keeps the caret out of the code element's `scroll-padding`. A gutter that stays in place
|
|
20
|
+
while the code scrolls should set that padding to its width, so the caret isn't left under it. A `float: left` gutter,
|
|
21
|
+
like the one the playground theme draws from `data-gutter`, is on the left in both directions, so use
|
|
22
|
+
`scroll-padding-left` for it.
|
|
23
|
+
|
|
24
|
+
At the end of the longest line the block is scrolled as far as it goes, and a browser can draw the caret a fraction of a
|
|
25
|
+
pixel past that edge. A few pixels of `padding-inline-end` on the code element leave room for it. The playground theme
|
|
26
|
+
(`PlaygroundEditorTheme.css`) does both.
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{sel as t,ImportOverlays as e,defineOverlayRules as n,CoreImportExtension as r,DOMImportExtension as i}from"@lexical/html";import{getTextDirection as o,$isElementNode as s,$isTabNode as l,$isLineBreakNode as c,tokenizeRawText as u,$createTabNode as a,$createLineBreakNode as g,$getSiblingCaret as f,getterTableOf as h,setterTableOf as d,setterDefaultOf as p,aliasTableOf as m,$create as _,ElementNode as x,$getDocument as y,addClassNamesToElement as S,setDOMStyleFromCSS as b,$getEditor as v,$isTextNode as C,$createParagraphNode as T,nodeSchema as N,withAccessors as A,optional as P,stringValue as
|
|
10
|
-
/*@__INLINE__*/function ft(t){return()=>{}}function ht(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.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.`)}function dt(t,e){let n=t;for(let r=f(t,e);r&&(Gt(r.origin)||l(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function pt(t){return dt(t,"previous")}function mt(t){return dt(t,"next")}function _t(t){const e=pt(t),n=mt(t);let r=e;for(;null!==r;){if(Gt(r)){const t=o(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(s(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function xt(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){const t=i.getPreviousSibling();if(null===t){i=null;break}if(Gt(t)||l(t)||c(t)||ht(167),i=t,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];Gt(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Gt(t)&&(u=t.getTextContent()[e]);else{const e=t.getNextSibling();Gt(e)&&(u=e.getTextContent()[0])}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!Gt(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Gt(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Gt(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function yt(t){const e=mt(t);return c(e)&&ht(168),e}function St(t){const e=[];return u(t,{linebreak:()=>e.push(g()),tab:()=>e.push(a()),text:t=>e.push(Vt(t))}),e}function bt(t,e,n){if(!Number.isInteger(e)||e<=0)return!1;const r=t.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(e,i[0].length),s=t.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,c=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return t.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==c&&n.focus.set(s,Math.max(0,c-o),"text"),!0}const vt=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function Ct(t,e){if("number"==typeof t)return Number.isFinite(t)?t:e;if("string"!=typeof t||!vt.test(t))return e;const n=Number(t);return Number.isFinite(n)?n:e}const Tt=t=>{const e=h(t,"format"),n=d(t,"format"),r=p(t,"format");return{exportJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles();return{children:[],language:t.__language,theme:t.__theme,direction:t.__dir,format:e[t.__format],indent:t.__indent,textFormat:0!==n&&i?n:void 0,textStyle:""!==r&&i?r:void 0,type:t.__type,version:1}},exportCompactJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles(),o={type:t.__type,children:[]},s=t.__language;void 0!==s&&(o.language=s);const l=t.__theme;void 0!==l&&(o.theme=l);const c=t.__dir;null!=c&&(o.direction=c);const u=e[t.__format];void 0!==u&&""!==u&&(o.format=u);const a=t.__indent;return void 0!==a&&0!==a&&(o.indent=a),void 0!==n&&0!==n&&i&&(o.textFormat=n),void 0!==r&&""!==r&&i&&(o.textStyle=r),o},updateFromJSON:function(t,e){const i=e.direction;t.__dir=null===i||"ltr"===i||"rtl"===i?i:null;const o=e.format;t.__format="string"==typeof o&&o in n?n[o]:r,t.__indent=function(t){const e=Ct(t,0);return e>=0&&e<=Infinity&&Number.isInteger(e)?e:0}(e.indent),t.__textFormat=Ct(e.textFormat,0);const s=e.textStyle;t.__textStyle="string"==typeof s?s:"";const l=e.language;t.setLanguage(null==l||"string"==typeof l?l:"");const c=e.theme;return t.setTheme(void 0===c?void 0:"string"==typeof c?c:""),t}}};function Nt(t,e){t.__highlightType=e.__highlightType}const At=t=>{const e=h(t,"mode"),n=m(t,"detail",0),r=m(t,"format",0),i=d(t,"mode"),o=p(t,"mode");return{exportJSON:function(t){return{highlightType:t.__highlightType,detail:t.__detail,format:t.__format,mode:e[t.__mode],style:t.__style,text:t.__text,type:t.__type,version:1}},exportCompactJSON:function(t){const n={type:t.__type},r=t.__highlightType;void 0!==r&&(n.highlightType=r);const i=t.__detail;void 0!==i&&0!==i&&(n.detail=i);const o=t.__format;void 0!==o&&0!==o&&(n.format=o);const s=e[t.__mode];void 0!==s&&"normal"!==s&&(n.mode=s);const l=t.__style;void 0!==l&&""!==l&&(n.style=l);const c=t.__text;return void 0!==c&&""!==c&&(n.text=c),n},updateFromJSON:function(t,e){const s=e.detail;t.__detail="string"==typeof s&&s in n?n[s]:Ct(s,0);const l=e.format;t.setFormat("string"==typeof l&&l in r?r[l]:Ct(l,0));const c=e.mode;t.__mode="string"==typeof c&&c in i?i[c]:o;const u=e.style;t.__style="string"==typeof u?u:"";const a=e.text;t.__text="string"==typeof a?a:"";const g=e.highlightType;return t.setHighlightType(null==g||"string"==typeof g?g:""),t},afterCloneFrom:Nt}},Pt=/* @__PURE__ */N()({language:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */w(/* @__PURE__ */F())),{getter:{field:"__language"}}),theme:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */F()),{getter:{field:"__theme"}})}),Ft="javascript",wt=()=>Ft;function Ot(t,e){for(const n of t.childNodes){if(O(n)&&n.tagName===e)return!0;if(Ot(n,e))return!0}return!1}const $t="data-language",Dt="data-highlight-language",Et="data-theme",Lt=/* @__PURE__ */ft();class Bt extends x{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:x,generated:Tt,importDOM:{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||Ot(t,"BR"))?{conversion:zt,priority:1}:null,div:()=>({conversion:Mt,priority:1}),pre:()=>({conversion:zt,priority:0}),table:t=>Rt(t)?{conversion:Kt,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&Rt(n)?{conversion:It,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&Rt(e)?{conversion:It,priority:3}:null}},json:Pt})}constructor(t=void 0,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),function(t,e){t.__language=e.__language,t.__theme=e.__theme}(this,t),this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=y().createElement("code");S(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute($t,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Dt,n));const r=this.getTheme();r&&e.setAttribute(Et,r);const i=this.getStyle();return i&&b(e.style,i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute($t,r):i&&e.removeAttribute($t);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(Dt,r):e.removeAttribute(Dt):o&&r&&e.setAttribute(Dt,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(Et,s):l&&e.removeAttribute(Et);const c=this.__style,u=t.__style;return c!==u&&b(e.style,c,u),!1}exportDOM(t){const e=y().createElement("pre");S(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute($t,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Dt,n));const r=this.getTheme();r&&e.setAttribute(Et,r);const i=this.getStyle();return i&&b(e.style,i),{element:e}}insertNewAfter(t,e=!0){if(!lt(v(),"@lexical/code")){Lt();const e=Wt(t);if(e)return e}const{anchor:n,focus:r}=t,i=(n.isBefore(r)?n:r).getNode();if(C(i)){let t=pt(i);const e=[];for(;;)if(l(t))e.push(a()),t=t.getNextSibling();else{if(!Gt(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(Vt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,c=i.getParentOrThrow(),u=[g(),...e];c.splice(s,0,u);const f=e[e.length-1];f?f.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(kt(i)){const{offset:e}=t.anchor;i.splice(e,0,[g()]),i.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=T();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function Ht(t,e){return _(Bt).setLanguage(t).setTheme(e)}function kt(t){return t instanceof Bt}function zt(t){return{node:Ht(t.getAttribute($t),t.getAttribute(Et))}}function Mt(t){const e=t,n=jt(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(jt(e))return!0;e=e.parentElement}return!1}(e)?{node:n?Ht():null}:{node:null}}function Kt(){return{node:Ht()}}function It(){return{node:null}}function jt(t){return null!==t.style.fontFamily.match("monospace")}function Rt(t){return t.classList.contains("js-file-line-container")}function Wt(t){const{anchor:e}=t;if(t.isCollapsed()&&"element"===e.type){const t=e.getNode();if(kt(t)){const n=t.getChildrenSize();if(n>=2&&e.offset===n){const e=t.getLastChild();if(c(e)&&c(e.getPreviousSibling())){const e=T();return t.splice(n-2,2,[]).insertAfter(e,!1),e.select(),e}}}}return null}const Jt=/* @__PURE__ */N()({highlightType:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */w(/* @__PURE__ */F())),{getter:{field:"__highlightType"}})});class qt extends D{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}$config(){return this.config("code-highlight",{extends:D,generated:At,json:Jt})}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const e=super.createDOM(t),n=Ut(t.theme,this.__highlightType);return S(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=Ut(n.theme,t.__highlightType),o=Ut(n.theme,this.__highlightType);return i!==o&&(i&&E(e,i),o&&S(e,o)),r}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return Ht()}}function Ut(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Vt(t="",e){return $(new qt(t,e))}function Gt(t){return t instanceof qt}const Qt="data-language",Xt="data-theme";function Yt(t){return null!==t.style.fontFamily.match("monospace")}function Zt(t){let e=t.parentElement;for(;null!==e;){if(Yt(e))return!0;e=e.parentElement}return!1}const te=/* @__PURE__ */n([{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"}]),ee={$import:(t,e)=>[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,t.$importChildren(e))],match:/* @__PURE__ */t.tag("pre"),name:"@lexical/code/pre"},ne={$import:(t,e,n)=>{const r=e.textContent||"";return/\r?\n/.test(r)||null!==e.querySelector("br")?[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,t.$importChildren(e))]:n()},match:/* @__PURE__ */t.tag("code"),name:"@lexical/code/code-multiline"};function re(t){if(!O(t))return!1;const e=t.style.fontFamily,n=t.style.whiteSpace;return"string"==typeof e&&/monospace/i.test(e)&&"string"==typeof n&&n.startsWith("pre")}function ie(t){let e=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(t.childNodes))if(O(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),e=!0):"BR"===s.tagName?(o(),n.push(""),e=!0):(r+=s.textContent||"",i=!0);else if(B(s)){const t=s.textContent||"";t.length>0&&(r+=t,i=!0)}return o(),e?n:null}function oe(t){for(const e of Array.from(t.children)){if(O(e)&&re(e)){if(null!==ie(e))return!0;const t=e.nextElementSibling;if(t&&re(t))return!0;continue}if(oe(e))return!0}return!1}const se=/* @__PURE__ */n([{$import:(t,e,n)=>{if(!re(e)||Zt(e))return n();const r=ie(e);return null===r||0===r.length?n():[Ht().splice(0,0,H(r.join("\n")))]},match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/vscode-wrapper"},{$import:(t,e,n)=>{if(!re(e)||Zt(e))return n();const r=e.previousElementSibling;if(r&&re(r))return[];const i=[];let o=e;for(;o&&re(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ht().splice(0,0,H(i.join("\n")))]},match:/* @__PURE__ */t.tag("div","br"),name:"@lexical/code/vscode-line-run"}]),le={$import:(t,e,n)=>Yt(e)?[Ht().splice(0,0,t.$importChildren(e))]:Zt(e)?t.$importChildren(e):n(),match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/div"},ce=[{$import:(t,e)=>[Ht().splice(0,0,t.$importChildren(e,{rules:te}))],match:/* @__PURE__ */t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"},{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"},ne,ee,le],ue={dependencies:[r,[i,{preprocess:[(t,n,r)=>{oe(L(t)?t.body:t)&&n.session.update(e,t=>[...t,se]),r()}],rules:ce}]],name:"@lexical/code",nodes:()=>[Bt,qt],register:t=>k(t.registerCommand(z,t=>{const e=M();return!(!K(e)||!Wt(e)||(null!==t&&t.preventDefault(),0))},I),t.registerNodeTransform(j,t=>{0!==t.getFormat()&&kt(t.getParent())&&t.setFormat(0)}))},ae={dependencies:[ue],name:"@lexical/code/Import"};function ge(t){const e=v().getElementByKey(t.getKey());if(null===e)return;const n=t.getChildren(),r=n.length;if(r===e.__cachedChildrenLength)return;e.__cachedChildrenLength=r;let i="1",o=1;for(let t=0;t<r;t++)c(n[t])&&(i+="\n"+ ++o);e.setAttribute("data-gutter",i)}function fe(t){return t._headless?()=>{}:t.registerMutationListener(Bt,e=>{t.read("latest",()=>{for(const[t,n]of e)if("destroyed"!==n){const e=R(t);null!==e&&ge(e)}})},{skipInitialization:!1})}function he(t){if(!K(t))return!1;const e=t.anchor.getNode(),n=kt(e)?e:e.getParent(),r=t.focus.getNode(),i=kt(r)?r:r.getParent();return kt(n)&&n.is(i)}function de(t){const e=t.getNodes(),n=[];if(1===e.length&&kt(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];Gt(i)||l(i)||c(i)||ht(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=et(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function pe(t,e){const n=M();if(!K(n)||!he(n))return!1;const r=de(n),i=r.length;if(0===i&&n.isCollapsed())return t===X?n.insertNodes([a()]):function(t,e){const n=t.anchor.getNode();if(!Gt(n)&&!l(n))return;const r=pt(n);l(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,t)}(n,e),!0;if(0===i&&t===X&&"\n"===n.getTextContent()){const t=a(),e=g(),r=n.isBackward()?"previous":"next";return n.insertNodes([t,e]),nt(rt(it(ot(t,"next",0),st(f(e,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=pt(r)),t===X){const t=a();if(r.insertBefore(t),0===o){const e=n.isBackward()?"focus":"anchor",i=et(r.getKey(),0,"text");n[e].is(i)&&n[e].set(t.getKey(),0,"text")}}else l(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,n)}}return!0}function me(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,u=r.getNode(),a=i.getNode(),g=t===q;if(!he(n)||!Gt(u)&&!l(u)||!Gt(a)&&!l(a))return!1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(g&&0===o&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!1}else if(!g&&o===u.getTextContentSize()&&null===u.getNextSibling()&&null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!1}return!1}let f,h;if(u.isBefore(a)?(f=pt(u),h=mt(a)):(f=pt(a),h=mt(u)),null==f||null==h)return!1;const d=f.getNodesBetween(h);for(let t=0;t<d.length;t++){const e=d[t];if(!Gt(e)&&!l(e)&&!c(e))return!1}e.preventDefault(),e.stopPropagation();const p=g?f.getPreviousSibling():h.getNextSibling();if(!c(p))return!0;const m=g?p.getPreviousSibling():p.getNextSibling();if(null==m)return!0;const _=c(m),x=_||!Gt(m)&&!l(m)?null:g?pt(m):mt(m);let y=null!=x?x:m;return p.remove(),d.forEach(t=>t.remove()),_?(d.forEach(t=>{y.insertAfter(t),y=t}),y.insertAfter(p)):t===q?(d.forEach(t=>y.insertBefore(t)),y.insertBefore(p)):(y.insertAfter(p),y=p,d.forEach(t=>{y.insertAfter(t),y=t})),n.setTextNodeRange(u,o,a,s),!0}function _e(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),u=t===Z;if(!he(n)||!Gt(o)&&!l(o)||!Gt(s)&&!l(s))return!1;const a=s,g="rtl"===_t(a)?!u:u,f=r.key,h=r.offset,d=r.type;if(g){const t=xt(a,i.offset);if(null!==t){const{node:e,offset:r}=t;c(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else a.getParentOrThrow().selectStart()}else yt(a).select();return e.shiftKey&&n.anchor.set(f,h,d),e.preventDefault(),e.stopPropagation(),!0}function xe(t,e,n){return k(...n?[t.registerCommand(W,t=>!t.altKey&&at(kt,t),I),t.registerCommand(J,t=>at(kt,t),I),t.registerCommand(q,t=>!t.altKey&>(kt,t),I),t.registerCommand(U,t=>gt(kt,t),I)]:[],t.registerCommand(V,e=>{const n=function(t){const e=M();if(!K(e)||!he(e))return null;const n=t?Y:X,r=t?Y:G,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=de(e);if(1!==s.length)return n;const l=s[0];let c,u;0===l.length&&ht(285),e.isBackward()?(c=o,u=i):(c=i,u=o);const a=pt(l[0]),g=mt(l[0]),f=et(a.getKey(),0,"text"),h=et(g.getKey(),g.getTextContentSize(),"text");return c.isBefore(f)||h.isBefore(u)?n:f.isBefore(c)||u.isBefore(h)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n),!0)},I),t.registerCommand(G,()=>!!he(M())&&(Q([a()]),!0),I),t.registerCommand(X,()=>pe(X),I),t.registerCommand(Y,()=>pe(Y,e),I),t.registerCommand(q,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();if(!he(e))return!1;const i=r.getParent();return e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&kt(i)&&null===i.getPreviousSibling()?(t.preventDefault(),!0):me(q,t)},I),t.registerCommand(W,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();return!!he(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&kt(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(t.preventDefault(),!0):me(W,t))},I),t.registerCommand(Z,t=>_e(Z,t),I),t.registerCommand(tt,t=>_e(tt,t),I))}const ye={build:(t,e)=>ut(e),config:{disabled:!1,escapeWithArrows:!1,tabSize:void 0},dependencies:[ue],name:"@lexical/code-indent",register:(t,e,n)=>{const r=n.getOutput();return ct(()=>{if(!r.disabled.value)return xe(t,r.tabSize.value,r.escapeWithArrows.value)})}};export{Vt as $createCodeHighlightNode,Ht as $createCodeNode,_t as $getCodeLineDirection,yt as $getEndOfCodeInLine,pt as $getFirstCodeNodeOfLine,mt as $getLastCodeNodeOfLine,xt as $getStartOfCodeInLine,Gt as $isCodeHighlightNode,kt as $isCodeNode,bt as $outdentLeadingSpaces,St as $plainifyCodeContent,ue as CodeExtension,qt as CodeHighlightNode,ae as CodeImportExtension,ce as CodeImportRules,ye as CodeIndentExtension,Bt as CodeNode,Ft as DEFAULT_CODE_LANGUAGE,wt as getDefaultCodeLanguage,fe as registerCodeGutter,xe as registerCodeIndentation};
|
|
9
|
+
import{sel as t,ImportOverlays as e,defineOverlayRules as n,CoreImportExtension as r,DOMImportExtension as i}from"@lexical/html";import{getTextDirection as o,$isElementNode as s,$isTabNode as l,$isLineBreakNode as c,tokenizeRawText as u,$createTabNode as a,$createLineBreakNode as g,$getSiblingCaret as f,getterTableOf as h,setterTableOf as d,setterDefaultOf as p,aliasTableOf as m,$create as _,ElementNode as x,$getDocument as y,addClassNamesToElement as S,setDOMStyleFromCSS as b,$getEditor as v,$isTextNode as C,$createParagraphNode as T,nodeSchema as N,withAccessors as A,optional as P,stringValue as w,nullable as F,isHTMLElement as O,$applyNodeReplacement as $,TextNode as D,removeClassNamesFromElement as E,isDOMDocumentNode as L,isDOMTextNode as B,$generateNodesFromRawText as H,mergeRegister as k,KEY_ENTER_COMMAND as z,$getSelection as M,$isRangeSelection as K,COMMAND_PRIORITY_LOW as I,TabNode as j,$getNodeByKey as R,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_RIGHT_COMMAND as J,KEY_ARROW_UP_COMMAND as q,KEY_ARROW_LEFT_COMMAND as U,KEY_TAB_COMMAND as V,INSERT_TAB_COMMAND as G,$insertNodes as Q,INDENT_CONTENT_COMMAND as X,OUTDENT_CONTENT_COMMAND as Y,MOVE_TO_START as Z,MOVE_TO_END as tt,$createPoint as et,$setSelectionFromCaretRange as nt,$getCaretRangeInDirection as rt,$getCaretRange as it,$getTextPointCaret as ot,$normalizeCaret as st}from"lexical";import{getPeerDependencyFromEditor as lt}from"@lexical/extension/getPeerDependencyFromEditor";import{effect as ct}from"@lexical/extension/signals";import{namedSignals as ut}from"@lexical/extension/namedSignals";import{$onEscapeDown as at,$onEscapeUp as gt}from"@lexical/utils";
|
|
10
|
+
/*@__INLINE__*/function ft(t){return()=>{}}function ht(t,...e){throw function(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);return n.search=r.toString(),new 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.`)}(t,...e)}function dt(t,e){let n=t;for(let r=f(t,e);r&&(Gt(r.origin)||l(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function pt(t){return dt(t,"previous")}function mt(t){return dt(t,"next")}function _t(t){const e=pt(t),n=mt(t);let r=e;for(;null!==r;){if(Gt(r)){const t=o(r.getTextContent());if(null!==t)return t}if(r===n)break;r=r.getNextSibling()}const i=e.getParent();if(s(i)){const t=i.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function xt(t,e){let n=null,r=null,i=t,o=e,s=t.getTextContent();for(;;){if(0===o){const t=i.getPreviousSibling();if(null===t){i=null;break}if(Gt(t)||l(t)||c(t)||ht(167),i=t,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const t=s[o];Gt(i)&&" "!==t&&(r={node:i,offset:o})}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Gt(t)&&(u=t.getTextContent()[e]);else{const e=t.getNextSibling();Gt(e)&&(u=e.getTextContent()[0])}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,i=t.getTextContent(),o=t.getTextContentSize();for(;;){if(!Gt(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Gt(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Gt(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(t,e);return null!==r?r:n}}function yt(t){const e=mt(t);return c(e)&&ht(168),e}function St(t){const e=[];return u(t,{linebreak:()=>e.push(g()),tab:()=>e.push(a()),text:t=>e.push(Vt(t))}),e}function bt(t,e,n){if(!Number.isInteger(e)||e<=0)return!1;const r=t.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(e,i[0].length),s=t.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,c=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return t.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==c&&n.focus.set(s,Math.max(0,c-o),"text"),!0}const vt=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;function Ct(t,e){if("number"==typeof t)return Number.isFinite(t)?t:e;if("string"!=typeof t||!vt.test(t))return e;const n=Number(t);return Number.isFinite(n)?n:e}const Tt=t=>{const e=h(t,"format"),n=d(t,"format"),r=p(t,"format");return{exportJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles();return{children:[],language:t.__language,theme:t.__theme,direction:t.__dir,format:e[t.__format],indent:t.__indent,textFormat:0!==n&&i?n:void 0,textStyle:""!==r&&i?r:void 0,type:t.__type,version:1}},exportCompactJSON:function(t){const n=t.__textFormat,r=t.__textStyle,i=(0!==n||""!==r)&&t.shouldSerializeTextStyles(),o={type:t.__type,children:[]},s=t.__language;void 0!==s&&(o.language=s);const l=t.__theme;void 0!==l&&(o.theme=l);const c=t.__dir;null!=c&&(o.direction=c);const u=e[t.__format];void 0!==u&&""!==u&&(o.format=u);const a=t.__indent;return void 0!==a&&0!==a&&(o.indent=a),void 0!==n&&0!==n&&i&&(o.textFormat=n),void 0!==r&&""!==r&&i&&(o.textStyle=r),o},updateFromJSON:function(t,e){const i=e.direction;t.__dir=null===i||"ltr"===i||"rtl"===i?i:null;const o=e.format;t.__format="string"==typeof o&&o in n?n[o]:r,t.__indent=function(t){const e=Ct(t,0);return e>=0&&e<=Infinity&&Number.isInteger(e)?e:0}(e.indent),t.__textFormat=Ct(e.textFormat,0);const s=e.textStyle;t.__textStyle="string"==typeof s?s:"";const l=e.language;t.setLanguage(null==l||"string"==typeof l?l:"");const c=e.theme;return t.setTheme(void 0===c?void 0:"string"==typeof c?c:""),t}}};function Nt(t,e){t.__highlightType=e.__highlightType}const At=t=>{const e=h(t,"mode"),n=m(t,"detail",0),r=m(t,"format",0),i=d(t,"mode"),o=p(t,"mode");return{exportJSON:function(t){return{highlightType:t.__highlightType,detail:t.__detail,format:t.__format,mode:e[t.__mode],style:t.__style,text:t.__text,type:t.__type,version:1}},exportCompactJSON:function(t){const n={type:t.__type},r=t.__highlightType;void 0!==r&&(n.highlightType=r);const i=t.__detail;void 0!==i&&0!==i&&(n.detail=i);const o=t.__format;void 0!==o&&0!==o&&(n.format=o);const s=e[t.__mode];void 0!==s&&"normal"!==s&&(n.mode=s);const l=t.__style;void 0!==l&&""!==l&&(n.style=l);const c=t.__text;return void 0!==c&&""!==c&&(n.text=c),n},updateFromJSON:function(t,e){const s=e.detail;t.__detail="string"==typeof s&&s in n?n[s]:Ct(s,0);const l=e.format;t.setFormat("string"==typeof l&&l in r?r[l]:Ct(l,0));const c=e.mode;t.__mode="string"==typeof c&&c in i?i[c]:o;const u=e.style;t.__style="string"==typeof u?u:"";const a=e.text;t.__text="string"==typeof a?a:"";const g=e.highlightType;return t.setHighlightType(null==g||"string"==typeof g?g:""),t},afterCloneFrom:Nt}},Pt=/* @__PURE__ */N()({language:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */F(/* @__PURE__ */w())),{getter:{field:"__language"}}),theme:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */w()),{getter:{field:"__theme"}})}),wt="javascript",Ft=()=>wt;function Ot(t,e){for(const n of t.childNodes){if(O(n)&&n.tagName===e)return!0;if(Ot(n,e))return!0}return!1}const $t="data-language",Dt="data-highlight-language",Et="data-theme",Lt=/* @__PURE__ */ft();class Bt extends x{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:x,generated:Tt,importDOM:{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||Ot(t,"BR"))?{conversion:zt,priority:1}:null,div:()=>({conversion:Mt,priority:1}),pre:()=>({conversion:zt,priority:0}),table:t=>Rt(t)?{conversion:Kt,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&Rt(n)?{conversion:It,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&Rt(e)?{conversion:It,priority:3}:null}},json:Pt})}constructor(t=void 0,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),function(t,e){t.__language=e.__language,t.__theme=e.__theme}(this,t),this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=y().createElement("code");S(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute($t,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Dt,n));const r=this.getTheme();r&&e.setAttribute(Et,r);const i=this.getStyle();return i&&b(e.style,i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute($t,r):i&&e.removeAttribute($t);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(Dt,r):e.removeAttribute(Dt):o&&r&&e.setAttribute(Dt,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(Et,s):l&&e.removeAttribute(Et);const c=this.__style,u=t.__style;return c!==u&&b(e.style,c,u),!1}exportDOM(t){const e=y().createElement("pre");S(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute($t,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(Dt,n));const r=this.getTheme();r&&e.setAttribute(Et,r);const i=this.getStyle();return i&&b(e.style,i),{element:e}}insertNewAfter(t,e=!0){if(!lt(v(),"@lexical/code")){Lt();const e=Wt(t);if(e)return e}const{anchor:n,focus:r}=t,i=(n.isBefore(r)?n:r).getNode();if(C(i)){let t=pt(i);const e=[];for(;;)if(l(t))e.push(a()),t=t.getNextSibling();else{if(!Gt(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(Vt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,c=i.getParentOrThrow(),u=[g(),...e];c.splice(s,0,u);const f=e[e.length-1];f?f.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(kt(i)){const{offset:e}=t.anchor;i.splice(e,0,[g()]),i.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=T();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function Ht(t,e){return _(Bt).setLanguage(t).setTheme(e)}function kt(t){return t instanceof Bt}function zt(t){return{node:Ht(t.getAttribute($t),t.getAttribute(Et))}}function Mt(t){const e=t,n=jt(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(jt(e))return!0;e=e.parentElement}return!1}(e)?{node:n?Ht():null}:{node:null}}function Kt(){return{node:Ht()}}function It(){return{node:null}}function jt(t){return null!==t.style.fontFamily.match("monospace")}function Rt(t){return t.classList.contains("js-file-line-container")}function Wt(t){const{anchor:e}=t;if(t.isCollapsed()&&"element"===e.type){const t=e.getNode();if(kt(t)){const n=t.getChildrenSize();if(n>=2&&e.offset===n){const e=t.getLastChild();if(c(e)&&c(e.getPreviousSibling())){const e=T();return t.splice(n-2,2,[]).insertAfter(e,!1),e.select(),e}}}}return null}const Jt=/* @__PURE__ */N()({highlightType:/* @__PURE__ */A(/* @__PURE__ */P(/* @__PURE__ */F(/* @__PURE__ */w())),{getter:{field:"__highlightType"}})});class qt extends D{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}$config(){return this.config("code-highlight",{extends:D,generated:At,json:Jt})}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const e=super.createDOM(t),n=Ut(t.theme,this.__highlightType);return S(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=Ut(n.theme,t.__highlightType),o=Ut(n.theme,this.__highlightType);return i!==o&&(i&&E(e,i),o&&S(e,o)),r}setFormat(t){return this}isParentRequired(){return!0}createParentElementNode(){return Ht()}}function Ut(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Vt(t="",e){return $(new qt(t,e))}function Gt(t){return t instanceof qt}const Qt="data-language",Xt="data-theme";function Yt(t){return null!==t.style.fontFamily.match("monospace")}function Zt(t){let e=t.parentElement;for(;null!==e;){if(Yt(e))return!0;e=e.parentElement}return!1}const te=/* @__PURE__ */n([{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"}]),ee={$import:(t,e)=>[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,t.$importChildren(e))],match:/* @__PURE__ */t.tag("pre"),name:"@lexical/code/pre"},ne={$import:(t,e,n)=>{const r=e.textContent||"";return/\r?\n/.test(r)||null!==e.querySelector("br")?[Ht(e.getAttribute(Qt),e.getAttribute(Xt)).splice(0,0,t.$importChildren(e))]:n()},match:/* @__PURE__ */t.tag("code"),name:"@lexical/code/code-multiline"};function re(t){if(!O(t))return!1;const e=t.style.fontFamily,n=t.style.whiteSpace;return"string"==typeof e&&/monospace/i.test(e)&&"string"==typeof n&&n.startsWith("pre")}function ie(t){let e=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(t.childNodes))if(O(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),e=!0):"BR"===s.tagName?(o(),n.push(""),e=!0):(r+=s.textContent||"",i=!0);else if(B(s)){const t=s.textContent||"";t.length>0&&(r+=t,i=!0)}return o(),e?n:null}function oe(t){for(const e of Array.from(t.children)){if(O(e)&&re(e)){if(null!==ie(e))return!0;const t=e.nextElementSibling;if(t&&re(t))return!0;continue}if(oe(e))return!0}return!1}const se=/* @__PURE__ */n([{$import:(t,e,n)=>{if(!re(e)||Zt(e))return n();const r=ie(e);return null===r||0===r.length?n():[Ht().splice(0,0,H(r.join("\n")))]},match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/vscode-wrapper"},{$import:(t,e,n)=>{if(!re(e)||Zt(e))return n();const r=e.previousElementSibling;if(r&&re(r))return[];const i=[];let o=e;for(;o&&re(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ht().splice(0,0,H(i.join("\n")))]},match:/* @__PURE__ */t.tag("div","br"),name:"@lexical/code/vscode-line-run"}]),le={$import:(t,e,n)=>Yt(e)?[Ht().splice(0,0,t.$importChildren(e))]:Zt(e)?t.$importChildren(e):n(),match:/* @__PURE__ */t.tag("div"),name:"@lexical/code/div"},ce=[{$import:(t,e)=>[Ht().splice(0,0,t.$importChildren(e,{rules:te}))],match:/* @__PURE__ */t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"},{$import:(t,e)=>t.$importChildren(e),match:/* @__PURE__ */t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"},ne,ee,le],ue={dependencies:[r,[i,{preprocess:[(t,n,r)=>{oe(L(t)?t.body:t)&&n.session.update(e,t=>[...t,se]),r()}],rules:ce}]],name:"@lexical/code",nodes:()=>[Bt,qt],register:t=>k(t.registerCommand(z,t=>{const e=M();return!(!K(e)||!Wt(e)||(null!==t&&t.preventDefault(),0))},I),t.registerNodeTransform(j,t=>{0!==t.getFormat()&&kt(t.getParent())&&t.setFormat(0)}))},ae={dependencies:[ue],name:"@lexical/code/Import"};function ge(t){const e=v().getElementByKey(t.getKey());if(null===e)return;const n=t.getChildren(),r=n.length;if(r===e.__cachedChildrenLength)return;e.__cachedChildrenLength=r;let i="1",o=1;for(let t=0;t<r;t++)c(n[t])&&(i+="\n"+ ++o);e.setAttribute("data-gutter",i)}function fe(t){return t._headless?()=>{}:t.registerMutationListener(Bt,e=>{t.read("latest",()=>{for(const[t,n]of e)if("destroyed"!==n){const e=R(t);null!==e&&ge(e)}})},{skipInitialization:!1})}function he(t){if(!K(t))return!1;const e=t.anchor.getNode(),n=kt(e)?e:e.getParent(),r=t.focus.getNode(),i=kt(r)?r:r.getParent();return kt(n)&&n.is(i)}function de(t){const e=t.getNodes(),n=[];if(1===e.length&&kt(e[0]))return n;let r=[];for(let t=0;t<e.length;t++){const i=e[t];Gt(i)||l(i)||c(i)||ht(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const e=t.isBackward()?t.anchor:t.focus,i=et(r[0].getKey(),0,"text");e.is(i)||n.push(r)}return n}function pe(t,e){const n=M();if(!K(n)||!he(n))return!1;const r=de(n),i=r.length;if(0===i&&n.isCollapsed())return t===X?n.insertNodes([a()]):function(t,e){const n=t.anchor.getNode();if(!Gt(n)&&!l(n))return;const r=pt(n);l(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,t)}(n,e),!0;if(0===i&&t===X&&"\n"===n.getTextContent()){const t=a(),e=g(),r=n.isBackward()?"previous":"next";return n.insertNodes([t,e]),nt(rt(it(ot(t,"next",0),st(f(e,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=pt(r)),t===X){const t=a();if(r.insertBefore(t),0===o){const e=n.isBackward()?"focus":"anchor",i=et(r.getKey(),0,"text");n[e].is(i)&&n[e].set(t.getKey(),0,"text")}}else l(r)?r.remove():void 0!==e&&Gt(r)&&bt(r,e,n)}}return!0}function me(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,u=r.getNode(),a=i.getNode(),g=t===q;if(!he(n)||!Gt(u)&&!l(u)||!Gt(a)&&!l(a))return!1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(g&&0===o&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!1}else if(!g&&o===u.getTextContentSize()&&null===u.getNextSibling()&&null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!1}return!1}let f,h;if(u.isBefore(a)?(f=pt(u),h=mt(a)):(f=pt(a),h=mt(u)),null==f||null==h)return!1;const d=f.getNodesBetween(h);for(let t=0;t<d.length;t++){const e=d[t];if(!Gt(e)&&!l(e)&&!c(e))return!1}e.preventDefault(),e.stopPropagation();const p=g?f.getPreviousSibling():h.getNextSibling();if(!c(p))return!0;const m=g?p.getPreviousSibling():p.getNextSibling();if(null==m)return!0;const _=c(m),x=_||!Gt(m)&&!l(m)?null:g?pt(m):mt(m);let y=null!=x?x:m;return p.remove(),d.forEach(t=>t.remove()),_?(d.forEach(t=>{y.insertAfter(t),y=t}),y.insertAfter(p)):t===q?(d.forEach(t=>y.insertBefore(t)),y.insertBefore(p)):(y.insertAfter(p),y=p,d.forEach(t=>{y.insertAfter(t),y=t})),n.setTextNodeRange(u,o,a,s),!0}function _e(t,e){const n=M();if(!K(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),u=t===Z;if(!he(n)||!Gt(o)&&!l(o)||!Gt(s)&&!l(s))return!1;const a=s,g="rtl"===_t(a)?!u:u,f=r.key,h=r.offset,d=r.type;if(g){const t=xt(a,i.offset);if(null!==t){const{node:e,offset:r}=t;c(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r)}else a.getParentOrThrow().selectStart()}else yt(a).select();return e.shiftKey&&n.anchor.set(f,h,d),e.preventDefault(),e.stopPropagation(),!0}function xe(t,e,n){return k(...n?[t.registerCommand(W,t=>!t.altKey&&at(kt,t),I),t.registerCommand(J,t=>at(kt,t),I),t.registerCommand(q,t=>!t.altKey&>(kt,t),I),t.registerCommand(U,t=>gt(kt,t),I)]:[],t.registerCommand(V,e=>{const n=function(t){const e=M();if(!K(e)||!he(e))return null;const n=t?Y:X,r=t?Y:G,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=de(e);if(1!==s.length)return n;const l=s[0];let c,u;0===l.length&&ht(285),e.isBackward()?(c=o,u=i):(c=i,u=o);const a=pt(l[0]),g=mt(l[0]),f=et(a.getKey(),0,"text"),h=et(g.getKey(),g.getTextContentSize(),"text");return c.isBefore(f)||h.isBefore(u)?n:f.isBefore(c)||u.isBefore(h)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n),!0)},I),t.registerCommand(G,()=>!!he(M())&&(Q([a()]),!0),I),t.registerCommand(X,()=>pe(X),I),t.registerCommand(Y,()=>pe(Y,e),I),t.registerCommand(q,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();if(!he(e))return!1;const i=r.getParent();return e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&kt(i)&&null===i.getPreviousSibling()?(t.preventDefault(),!0):me(q,t)},I),t.registerCommand(W,t=>{const e=M();if(!K(e))return!1;const{anchor:n}=e,r=n.getNode();return!!he(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&kt(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(t.preventDefault(),!0):me(W,t))},I),t.registerCommand(Z,t=>_e(Z,t),I),t.registerCommand(tt,t=>_e(tt,t),I))}const ye={build:(t,e)=>ut(e),config:{disabled:!1,escapeWithArrows:!1,tabSize:void 0},dependencies:[ue],name:"@lexical/code-indent",register:(t,e,n)=>{const r=n.getOutput();return ct(()=>{if(!r.disabled.value)return xe(t,r.tabSize.value,r.escapeWithArrows.value)})}};export{Vt as $createCodeHighlightNode,Ht as $createCodeNode,_t as $getCodeLineDirection,yt as $getEndOfCodeInLine,pt as $getFirstCodeNodeOfLine,mt as $getLastCodeNodeOfLine,xt as $getStartOfCodeInLine,Gt as $isCodeHighlightNode,kt as $isCodeNode,bt as $outdentLeadingSpaces,St as $plainifyCodeContent,ue as CodeExtension,qt as CodeHighlightNode,ae as CodeImportExtension,ce as CodeImportRules,ye as CodeIndentExtension,Bt as CodeNode,wt as DEFAULT_CODE_LANGUAGE,Ft as getDefaultCodeLanguage,fe as registerCodeGutter,xe as registerCodeIndentation};
|
package/package.json
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.52.0",
|
|
12
12
|
"main": "./dist/LexicalCodeCore.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.
|
|
16
|
-
"@lexical/html": "0.
|
|
17
|
-
"@lexical/internal": "0.
|
|
18
|
-
"@lexical/utils": "0.
|
|
19
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/extension": "0.52.0",
|
|
16
|
+
"@lexical/html": "0.52.0",
|
|
17
|
+
"@lexical/internal": "0.52.0",
|
|
18
|
+
"@lexical/utils": "0.52.0",
|
|
19
|
+
"lexical": "0.52.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|