@react-fabric/lexical 1.0.0-beta.5 → 1.0.0-beta.51
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/{src/editor/Lexical.module.css → css/_lexical.css} +4 -4
- package/css/styles.css +24 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
- package/dist/cjs/node_modules/prismjs/prism.js +1 -1
- package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +4 -5
- package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +81 -76
- package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/node_modules/prismjs/prism.js +1 -1
- package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +4 -5
- package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +82 -77
- package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +4 -6
- package/dist/types/hooks/useFormatWatcher.d.ts +2 -2
- package/dist/types/nodes/StickyNode.d.ts +0 -1
- package/package.json +13 -12
- package/src/components/StickyComponent.tsx +1 -1
- package/src/editor/LexicalEditor.tsx +28 -25
- package/src/hooks/useFormatWatcher.ts +28 -27
- package/src/plugins/ToolbarPlugin.tsx +22 -6
- package/dist/cjs/editor/Lexical.module.css +0 -1
- package/dist/esm/editor/Lexical.module.css +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
4
|
+
var lexical = require('lexical');
|
|
3
5
|
require('../../prismjs/prism.js');
|
|
4
6
|
require('../../prismjs/components/prism-clike.js');
|
|
5
7
|
require('../../prismjs/components/prism-javascript.js');
|
|
@@ -16,8 +18,6 @@ require('../../prismjs/components/prism-swift.js');
|
|
|
16
18
|
require('../../prismjs/components/prism-typescript.js');
|
|
17
19
|
require('../../prismjs/components/prism-java.js');
|
|
18
20
|
require('../../prismjs/components/prism-cpp.js');
|
|
19
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
20
|
-
var lexical = require('lexical');
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -27,24 +27,28 @@ var lexical = require('lexical');
|
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
function w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var P=w((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const k=t=>{try{return !!t&&window.Prism.languages.hasOwnProperty(t)}catch(t){return !1}};function L(e,n){for(const r of e.childNodes){if(LexicalUtils.isHTMLElement(r)&&r.tagName===n)return !0;L(r,n);}return !1}const A="data-language",O="data-highlight-language";class M extends lexical.ElementNode{static getType(){return "code"}static clone(t){return new M(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t,this.__isSyntaxHighlightSupported=k(t);}createDOM(t){const n=document.createElement("code");LexicalUtils.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(A,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(O,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(A,r),this.__isSyntaxHighlightSupported&&e.setAttribute(O,r)):o&&(e.removeAttribute(A),t.__isSyntaxHighlightSupported&&e.removeAttribute(O)),!1}exportDOM(t){const n=document.createElement("pre");LexicalUtils.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(A,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(O,r)),{element:n}}static importDOM(){return {code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||L(t,"BR"))?{conversion:z,priority:1}:null,div:()=>({conversion:E,priority:1}),pre:()=>({conversion:z,priority:0}),table:t=>R(t)?{conversion:B,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&R(n)?{conversion:I,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&R(e)?{conversion:I,priority:3}:null}}}static importJSON(t){const e=H(t.language);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return {...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}insertNewAfter(t,e=!0){const n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=lexical.$createParagraphNode();return this.insertAfter(t,e),t}const{anchor:o,focus:a}=t,g=(o.isBefore(a)?o:a).getNode();if(lexical.$isTextNode(g)){let t=Z(g);const e=[];for(;;)if(lexical.$isTabNode(t))e.push(lexical.$createTabNode()),t=t.getNextSibling();else {if(!Y(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(V(" ".repeat(n))),n!==o)break;t=t.getNextSibling();}}const n=g.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=g.getParentOrThrow(),a=[lexical.$createLineBreakNode(),...e];s.splice(i,0,a);const f=e[e.length-1];f?f.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0);}if(D(g)){const{offset:e}=t.anchor;g.splice(e,0,[lexical.$createLineBreakNode()]),g.select(e+1,e+1);}return null}canIndent(){return !1}collapseAtStart(){const t=lexical.$createParagraphNode();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}setLanguage(t){const e=this.getWritable();e.__language=t,e.__isSyntaxHighlightSupported=k(t);}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function H(t){return lexical.$applyNodeReplacement(new M(t))}function D(t){return t instanceof M}function z(t){return {node:H(t.getAttribute(A))}}function E(t){const e=t,n=J(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(J(e))return !0;e=e.parentElement;}return !1}(e)?{node:n?H():null}:{node:null}}function B(){return {node:H()}}function I(){return {node:null}}function J(t){return null!==t.style.fontFamily.match("monospace")}function R(t){return t.classList.contains("js-file-line-container")}const F="javascript",K={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},q={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function U(t){return q[t]||t}function W(t){const e=U(t);return K[e]||e}const $=()=>F,Q=()=>Object.keys(window.Prism.languages).filter((t=>"function"!=typeof window.Prism.languages[t])).sort();class X extends lexical.TextNode{constructor(t,e,n){super(t,n),this.__highlightType=e;}static getType(){return "code-highlight"}static clone(t){return new X(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return !1}createDOM(t){const n=super.createDOM(t),r=G(t.theme,this.__highlightType);return LexicalUtils.addClassNamesToElement(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=G(o.theme,t.__highlightType),l=G(o.theme,this.__highlightType);return s!==l&&(s&&LexicalUtils.removeClassNamesFromElement(r,s),l&&LexicalUtils.addClassNamesToElement(r,l)),i}static importJSON(t){const e=V(t.text,t.highlightType);return e.setFormat(t.format),e.setDetail(t.detail),e.setMode(t.mode),e.setStyle(t.style),e}exportJSON(){return {...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(t){return this}isParentRequired(){return !0}createParentElementNode(){return H()}}function G(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function V(t,e){return lexical.$applyNodeReplacement(new X(t,e))}function Y(t){return t instanceof X}function Z(t){let e=t,n=t;for(;Y(n)||lexical.$isTabNode(n);)e=n,n=n.getPreviousSibling();return e}function tt(t){let e=t,n=t;for(;Y(n)||lexical.$isTabNode(n);)e=n,n=n.getNextSibling();return e}const et={defaultLanguage:F,tokenize(t,e){return window.Prism.tokenize(t,window.Prism.languages[e||""]||window.Prism.languages[this.defaultLanguage])}};function nt(t,e){let n=null,r=null,o=t,i=e,s=t.getTextContent();for(;;){if(0===i){if(o=o.getPreviousSibling(),null===o)break;if(Y(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||P(167),lexical.$isLineBreakNode(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent();}else i--;const t=s[i];Y(o)&&" "!==t&&(r={node:o,offset:i});}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Y(t)&&(u=t.getTextContent()[e]);else {const e=t.getNextSibling();Y(e)&&(u=e.getTextContent()[0]);}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!Y(n)||r===i){if(n=n.getNextSibling(),null===n||lexical.$isLineBreakNode(n))return null;Y(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize());}if(Y(n)){if(" "!==o[r])return {node:n,offset:r};r++;}}}(t,e);return null!==r?r:n}}function rt(t){const e=tt(t);return lexical.$isLineBreakNode(e)&&P(168),e}function ot(t,e,n){const r=t.getParent();D(r)?lt(r,e,n):Y(t)&&t.replace(lexical.$createTextNode(t.__text));}function it(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let i="1",s=1;for(let t=0;t<o;t++)lexical.$isLineBreakNode(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i);}const st=new Set;function lt(t,e,n){const r=t.getKey();st.has(r)||(st.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=lexical.$getNodeByKey(t);if(!D(n)||!n.isAttached())return;const r=lexical.$getSelection();if(!lexical.$isRangeSelection(r))return void e();const o=r.anchor,i=o.offset,l="element"===o.type&&lexical.$isLineBreakNode(n.getChildAtIndex(o.offset-1));let u=0;if(!l){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0);}if(!e())return;if(l)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=lexical.$isTextNode(t);if(e||lexical.$isLineBreakNode(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n;}return !1}));}(r,(()=>{const e=lexical.$getNodeByKey(r);if(!D(e)||!e.isAttached())return !1;const o=e.getTextContent(),i=ut(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&ct(t[n],e[n]);)n++;const r=t.length,o=e.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!ct(t[r-s],e[o-s])){s--;break}const l=n,u=r-s,c=e.slice(n,o-s);return {from:l,nodesForReplacement:c,to:u}}(e.getChildren(),i),{from:l,to:u,nodesForReplacement:c}=s;return !(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)}));}),{onUpdate:()=>{st.delete(r);},skipTransforms:!0}));}function ut(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),o=t.length;for(let r=0;r<o;r++){const o=t[r];"\n"===o||"\r\n"===o?n.push(lexical.$createLineBreakNode()):"\t"===o?n.push(lexical.$createTabNode()):o.length>0&&n.push(V(o,e));}}else {const{content:t}=r;"string"==typeof t?n.push(...ut([t],r.type)):Array.isArray(t)&&n.push(...ut(t,r.type));}return n}function ct(t,e){return Y(t)&&Y(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||lexical.$isTabNode(t)&&lexical.$isTabNode(e)||lexical.$isLineBreakNode(t)&&lexical.$isLineBreakNode(e)}function at(t){if(!lexical.$isRangeSelection(t))return !1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&D(e))return !0;const r=e.getParent();return D(r)&&r.is(n.getParent())}function gt(t){const e=t.getNodes(),n=[[]];if(1===e.length&&D(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];Y(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||P(169),lexical.$isLineBreakNode(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o);}return n}function ft(t){const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e)||!at(e))return !1;const n=gt(e),r=n.length;if(n.length>1){for(let e=0;e<r;e++){const r=n[e];if(r.length>0){let n=r[0];0===e&&(n=Z(n)),null!==n&&(t===lexical.INDENT_CONTENT_COMMAND?n.insertBefore(lexical.$createTabNode()):lexical.$isTabNode(n)&&n.remove());}}return !0}const o=e.getNodes()[0];if(D(o)||Y(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||P(171),D(o))return t===lexical.INDENT_CONTENT_COMMAND&&e.insertNodes([lexical.$createTabNode()]),!0;const i=Z(o);return null===i&&P(172),t===lexical.INDENT_CONTENT_COMMAND?lexical.$isLineBreakNode(i)?i.insertAfter(lexical.$createTabNode()):i.insertBefore(lexical.$createTabNode()):lexical.$isTabNode(i)&&i.remove(),!0}function pt(t,e){const n=lexical.$getSelection();if(!lexical.$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,u=r.getNode(),c=o.getNode(),a=t===lexical.KEY_ARROW_UP_COMMAND;if(!at(n)||!Y(u)&&!lexical.$isTabNode(u)||!Y(c)&&!lexical.$isTabNode(c))return !1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(a&&0===i&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!a&&i===u.getTextContentSize()&&null===u.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return !1}let g,p;if(u.isBefore(c)?(g=Z(u),p=tt(c)):(g=Z(c),p=tt(u)),null==g||null==p)return !1;const h=g.getNodesBetween(p);for(let t=0;t<h.length;t++){const e=h[t];if(!Y(e)&&!lexical.$isTabNode(e)&&!lexical.$isLineBreakNode(e))return !1}e.preventDefault(),e.stopPropagation();const y=a?g.getPreviousSibling():p.getNextSibling();if(!lexical.$isLineBreakNode(y))return !0;const x=a?y.getPreviousSibling():y.getNextSibling();if(null==x)return !0;const S=Y(x)||lexical.$isTabNode(x)||lexical.$isLineBreakNode(x)?a?Z(x):tt(x):null;let v=null!=S?S:x;return y.remove(),h.forEach((t=>t.remove())),t===lexical.KEY_ARROW_UP_COMMAND?(h.forEach((t=>v.insertBefore(t))),v.insertBefore(y)):(v.insertAfter(y),v=y,h.forEach((t=>{v.insertAfter(t),v=t;}))),n.setTextNodeRange(u,i,c,s),!0}function ht(t,e){const n=lexical.$getSelection();if(!lexical.$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),u=t===lexical.MOVE_TO_START;if(!Y(i)&&!lexical.$isTabNode(i)||!Y(s)&&!lexical.$isTabNode(s))return !1;if(u){const t=nt(s,o.offset);if(null!==t){const{node:e,offset:r}=t;lexical.$isLineBreakNode(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r);}else s.getParentOrThrow().selectStart();}else {rt(s).select();}return e.preventDefault(),e.stopPropagation(),!0}function dt(t,e){if(!t.hasNodes([M,X]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=et),LexicalUtils.mergeRegister(t.registerMutationListener(M,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=lexical.$getNodeByKey(n);null!==e&&it(e,t);}}));}),{skipInitialization:!1}),t.registerNodeTransform(M,(n=>lt(n,t,e))),t.registerNodeTransform(lexical.TextNode,(n=>ot(n,t,e))),t.registerNodeTransform(X,(n=>ot(n,t,e))),t.registerCommand(lexical.KEY_TAB_COMMAND,(e=>{const n=function(t){const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e)||!at(e))return null;const n=t?lexical.OUTDENT_CONTENT_COMMAND:lexical.INDENT_CONTENT_COMMAND,r=t?lexical.OUTDENT_CONTENT_COMMAND:lexical.INSERT_TAB_COMMAND;if(gt(e).length>1)return n;const o=e.getNodes()[0];if(D(o)||Y(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||P(170),D(o))return n;const i=Z(o),s=tt(o),u=e.anchor,c=e.focus;let a,g;return c.isBefore(u)?(a=c,g=u):(a=u,g=c),null!==i&&null!==s&&a.key===i.getKey()&&0===a.offset&&g.key===s.getKey()&&g.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.INSERT_TAB_COMMAND,(()=>!!at(lexical.$getSelection())&&(lexical.$insertNodes([lexical.$createTabNode()]),!0)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.INDENT_CONTENT_COMMAND,(t=>ft(lexical.INDENT_CONTENT_COMMAND)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.OUTDENT_CONTENT_COMMAND,(t=>ft(lexical.OUTDENT_CONTENT_COMMAND)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.KEY_ARROW_UP_COMMAND,(t=>pt(lexical.KEY_ARROW_UP_COMMAND,t)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND,(t=>pt(lexical.KEY_ARROW_DOWN_COMMAND,t)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.MOVE_TO_END,(t=>ht(lexical.MOVE_TO_END,t)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.MOVE_TO_START,(t=>ht(lexical.MOVE_TO_START,t)),lexical.COMMAND_PRIORITY_LOW))}
|
|
30
|
+
function O(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.`)}const k=globalThis.Prism||window.Prism,L=t=>{try{return !!t&&k.languages.hasOwnProperty(t)}catch(t){return !1}};function A(e,n){for(const r of e.childNodes){if(LexicalUtils.isHTMLElement(r)&&r.tagName===n)return !0;A(r,n);}return !1}const H="data-language",D="data-highlight-language";class M extends lexical.ElementNode{static getType(){return "code"}static clone(t){return new M(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=L(t);}createDOM(t){const n=document.createElement("code");LexicalUtils.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(H,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(H,r),this.__isSyntaxHighlightSupported&&e.setAttribute(D,r)):o&&(e.removeAttribute(H),t.__isSyntaxHighlightSupported&&e.removeAttribute(D)),!1}exportDOM(t){const n=document.createElement("pre");LexicalUtils.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(H,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),{element:n}}static importDOM(){return {code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||A(t,"BR"))?{conversion:E,priority:1}:null,div:()=>({conversion:F,priority:1}),pre:()=>({conversion:E,priority:0}),table:t=>K(t)?{conversion:B,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&K(n)?{conversion:R,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&K(e)?{conversion:R,priority:3}:null}}}static importJSON(t){return z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language)}exportJSON(){return {...super.exportJSON(),language:this.getLanguage()}}insertNewAfter(t,e=!0){const n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=lexical.$createParagraphNode();return this.insertAfter(t,e),t}const{anchor:o,focus:i}=t,a=(o.isBefore(i)?o:i).getNode();if(lexical.$isTextNode(a)){let t=nt(a);const e=[];for(;;)if(lexical.$isTabNode(t))e.push(lexical.$createTabNode()),t=t.getNextSibling();else {if(!tt(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(Z(" ".repeat(n))),n!==o)break;t=t.getNextSibling();}}const n=a.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[lexical.$createLineBreakNode(),...e];s.splice(i,0,l);const p=e[e.length-1];p?p.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0);}if(J(a)){const{offset:e}=t.anchor;a.splice(e,0,[lexical.$createLineBreakNode()]),a.select(e+1,e+1);}return null}canIndent(){return !1}collapseAtStart(){const t=lexical.$createParagraphNode();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.__isSyntaxHighlightSupported=L(t),e}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function z(t){return lexical.$applyNodeReplacement(new M(t))}function J(t){return t instanceof M}function E(t){return {node:z(t.getAttribute(H))}}function F(t){const e=t,n=I(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(I(e))return !0;e=e.parentElement;}return !1}(e)?{node:n?z():null}:{node:null}}function B(){return {node:z()}}function R(){return {node:null}}function I(t){return null!==t.style.fontFamily.match("monospace")}function K(t){return t.classList.contains("js-file-line-container")}const q="javascript",U={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},W={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function $(t){return W[t]||t}function Q(t){const e=$(t);return U[e]||e}const X=()=>q,G=()=>Object.keys(k.languages).filter((t=>"function"!=typeof k.languages[t])).sort();class V extends lexical.TextNode{constructor(t="",e,n){super(t,n),this.__highlightType=e;}static getType(){return "code-highlight"}static clone(t){return new V(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return !1}createDOM(t){const n=super.createDOM(t),r=Y(t.theme,this.__highlightType);return LexicalUtils.addClassNamesToElement(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=Y(o.theme,t.__highlightType),l=Y(o.theme,this.__highlightType);return s!==l&&(s&&LexicalUtils.removeClassNamesFromElement(r,s),l&&LexicalUtils.addClassNamesToElement(r,l)),i}static importJSON(t){return Z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return {...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return !0}createParentElementNode(){return z()}}function Y(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Z(t="",e){return lexical.$applyNodeReplacement(new V(t,e))}function tt(t){return t instanceof V}function et(t,e){let n=t;for(let o=lexical.$getSiblingCaret(t,e);o&&(tt(o.origin)||lexical.$isTabNode(o.origin));o=LexicalUtils.$getAdjacentCaret(o))n=o.origin;return n}function nt(t){return et(t,"previous")}function rt(t){return et(t,"next")}const ot={defaultLanguage:q,tokenize(t,e){return k.tokenize(t,k.languages[e||""]||k.languages[this.defaultLanguage])}};function it(t,e){let n=null,r=null,o=t,i=e,s=t.getTextContent();for(;;){if(0===i){if(o=o.getPreviousSibling(),null===o)break;if(tt(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||O(167),lexical.$isLineBreakNode(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent();}else i--;const t=s[i];tt(o)&&" "!==t&&(r={node:o,offset:i});}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())tt(t)&&(l=t.getTextContent()[e]);else {const e=t.getNextSibling();tt(e)&&(l=e.getTextContent()[0]);}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!tt(n)||r===i){if(n=n.getNextSibling(),null===n||lexical.$isLineBreakNode(n))return null;tt(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize());}if(tt(n)){if(" "!==o[r])return {node:n,offset:r};r++;}}}(t,e);return null!==r?r:n}}function st(t){const e=rt(t);return lexical.$isLineBreakNode(e)&&O(168),e}function lt(t,e,n){const r=t.getParent();J(r)?gt(r,e,n):tt(t)&&t.replace(lexical.$createTextNode(t.__text));}function ut(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let i="1",s=1;for(let t=0;t<o;t++)lexical.$isLineBreakNode(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i);}const ct=new Set;function gt(t,e,n){const r=t.getKey();ct.has(r)||(ct.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=lexical.$getNodeByKey(t);if(!J(n)||!n.isAttached())return;const r=lexical.$getSelection();if(!lexical.$isRangeSelection(r))return void e();const o=r.anchor,i=o.offset,s="element"===o.type&&lexical.$isLineBreakNode(n.getChildAtIndex(o.offset-1));let u=0;if(!s){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0);}if(!e())return;if(s)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=lexical.$isTextNode(t);if(e||lexical.$isLineBreakNode(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n;}return !1}));}(r,(()=>{const e=lexical.$getNodeByKey(r);if(!J(e)||!e.isAttached())return !1;const o=e.getTextContent(),i=at(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&pt(t[n],e[n]);)n++;const r=t.length,o=e.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!pt(t[r-s],e[o-s])){s--;break}const l=n,u=r-s,c=e.slice(n,o-s);return {from:l,nodesForReplacement:c,to:u}}(e.getChildren(),i),{from:l,to:u,nodesForReplacement:c}=s;return !(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)}));}),{onUpdate:()=>{ct.delete(r);},skipTransforms:!0}));}function at(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),o=t.length;for(let r=0;r<o;r++){const o=t[r];"\n"===o||"\r\n"===o?n.push(lexical.$createLineBreakNode()):"\t"===o?n.push(lexical.$createTabNode()):o.length>0&&n.push(Z(o,e));}}else {const{content:t}=r;"string"==typeof t?n.push(...at([t],r.type)):Array.isArray(t)&&n.push(...at(t,r.type));}return n}function pt(t,e){return tt(t)&&tt(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||lexical.$isTabNode(t)&&lexical.$isTabNode(e)||lexical.$isLineBreakNode(t)&&lexical.$isLineBreakNode(e)}function ft(t){if(!lexical.$isRangeSelection(t))return !1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&J(e))return !0;const r=e.getParent();return J(r)&&r.is(n.getParent())}function ht(t){const e=t.getNodes(),n=[[]];if(1===e.length&&J(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];tt(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||O(169),lexical.$isLineBreakNode(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o);}return n}function dt(t){const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e)||!ft(e))return !1;const n=ht(e),r=n.length;if(n.length>1){for(let e=0;e<r;e++){const r=n[e];if(r.length>0){let n=r[0];0===e&&(n=nt(n)),null!==n&&(t===lexical.INDENT_CONTENT_COMMAND?n.insertBefore(lexical.$createTabNode()):lexical.$isTabNode(n)&&n.remove());}}return !0}const o=e.getNodes()[0];if(J(o)||tt(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||O(171),J(o))return t===lexical.INDENT_CONTENT_COMMAND&&e.insertNodes([lexical.$createTabNode()]),!0;const i=nt(o);return t===lexical.INDENT_CONTENT_COMMAND?lexical.$isLineBreakNode(i)?i.insertAfter(lexical.$createTabNode()):i.insertBefore(lexical.$createTabNode()):lexical.$isTabNode(i)&&i.remove(),!0}function mt(t,e){const n=lexical.$getSelection();if(!lexical.$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,l=r.getNode(),c=o.getNode(),g=t===lexical.KEY_ARROW_UP_COMMAND;if(!ft(n)||!tt(l)&&!lexical.$isTabNode(l)||!tt(c)&&!lexical.$isTabNode(c))return !1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===i&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&i===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return !1}let a,p;if(l.isBefore(c)?(a=nt(l),p=rt(c)):(a=nt(c),p=rt(l)),null==a||null==p)return !1;const f=a.getNodesBetween(p);for(let t=0;t<f.length;t++){const e=f[t];if(!tt(e)&&!lexical.$isTabNode(e)&&!lexical.$isLineBreakNode(e))return !1}e.preventDefault(),e.stopPropagation();const d=g?a.getPreviousSibling():p.getNextSibling();if(!lexical.$isLineBreakNode(d))return !0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return !0;const S=tt(m)||lexical.$isTabNode(m)||lexical.$isLineBreakNode(m)?g?nt(m):rt(m):null;let _=null!=S?S:m;return d.remove(),f.forEach((t=>t.remove())),t===lexical.KEY_ARROW_UP_COMMAND?(f.forEach((t=>_.insertBefore(t))),_.insertBefore(d)):(_.insertAfter(d),_=d,f.forEach((t=>{_.insertAfter(t),_=t;}))),n.setTextNodeRange(l,i,c,s),!0}function xt(t,e){const n=lexical.$getSelection();if(!lexical.$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),l=t===lexical.MOVE_TO_START;if(!ft(n)||!tt(i)&&!lexical.$isTabNode(i)||!tt(s)&&!lexical.$isTabNode(s))return !1;if(l){const t=it(s,o.offset);if(null!==t){const{node:e,offset:r}=t;lexical.$isLineBreakNode(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r);}else s.getParentOrThrow().selectStart();}else {st(s).select();}return e.preventDefault(),e.stopPropagation(),!0}function yt(t,e){if(!t.hasNodes([M,V]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=ot),LexicalUtils.mergeRegister(t.registerMutationListener(M,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=lexical.$getNodeByKey(n);null!==e&&ut(e,t);}}));}),{skipInitialization:!1}),t.registerNodeTransform(M,(n=>gt(n,t,e))),t.registerNodeTransform(lexical.TextNode,(n=>lt(n,t,e))),t.registerNodeTransform(V,(n=>lt(n,t,e))),t.registerCommand(lexical.KEY_TAB_COMMAND,(e=>{const n=function(t){const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e)||!ft(e))return null;const n=t?lexical.OUTDENT_CONTENT_COMMAND:lexical.INDENT_CONTENT_COMMAND,r=t?lexical.OUTDENT_CONTENT_COMMAND:lexical.INSERT_TAB_COMMAND;if(ht(e).length>1)return n;const o=e.getNodes()[0];if(J(o)||tt(o)||lexical.$isTabNode(o)||lexical.$isLineBreakNode(o)||O(170),J(o))return n;const i=nt(o),s=rt(o),l=e.anchor,c=e.focus;let g,a;return c.isBefore(l)?(g=c,a=l):(g=l,a=c),null!==i&&null!==s&&g.key===i.getKey()&&0===g.offset&&a.key===s.getKey()&&a.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.INSERT_TAB_COMMAND,(()=>!!ft(lexical.$getSelection())&&(lexical.$insertNodes([lexical.$createTabNode()]),!0)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.INDENT_CONTENT_COMMAND,(t=>dt(lexical.INDENT_CONTENT_COMMAND)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.OUTDENT_CONTENT_COMMAND,(t=>dt(lexical.OUTDENT_CONTENT_COMMAND)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.KEY_ARROW_UP_COMMAND,(t=>{const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e))return !1;const{anchor:n}=e,r=n.getNode();return !!ft(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&J(r.getParentOrThrow())?(t.preventDefault(),!0):mt(lexical.KEY_ARROW_UP_COMMAND,t))}),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND,(t=>{const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e))return !1;const{anchor:n}=e,r=n.getNode();return !!ft(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&J(r.getParentOrThrow())?(t.preventDefault(),!0):mt(lexical.KEY_ARROW_DOWN_COMMAND,t))}),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.MOVE_TO_START,(t=>xt(lexical.MOVE_TO_START,t)),lexical.COMMAND_PRIORITY_LOW),t.registerCommand(lexical.MOVE_TO_END,(t=>xt(lexical.MOVE_TO_END,t)),lexical.COMMAND_PRIORITY_LOW))}const St=nt,_t=rt,vt=st,Nt=it;
|
|
31
31
|
|
|
32
|
-
exports.$createCodeHighlightNode =
|
|
33
|
-
exports.$createCodeNode =
|
|
34
|
-
exports.$
|
|
35
|
-
exports.$
|
|
36
|
-
exports
|
|
37
|
-
exports
|
|
38
|
-
exports
|
|
32
|
+
exports.$createCodeHighlightNode = Z;
|
|
33
|
+
exports.$createCodeNode = z;
|
|
34
|
+
exports.$getEndOfCodeInLine = st;
|
|
35
|
+
exports.$getFirstCodeNodeOfLine = nt;
|
|
36
|
+
exports.$getLastCodeNodeOfLine = rt;
|
|
37
|
+
exports.$getStartOfCodeInLine = it;
|
|
38
|
+
exports.$isCodeHighlightNode = tt;
|
|
39
|
+
exports.$isCodeNode = J;
|
|
40
|
+
exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP = U;
|
|
41
|
+
exports.CODE_LANGUAGE_MAP = W;
|
|
42
|
+
exports.CodeHighlightNode = V;
|
|
39
43
|
exports.CodeNode = M;
|
|
40
|
-
exports.DEFAULT_CODE_LANGUAGE =
|
|
41
|
-
exports.PrismTokenizer =
|
|
42
|
-
exports.getCodeLanguages =
|
|
43
|
-
exports.getDefaultCodeLanguage =
|
|
44
|
-
exports.getEndOfCodeInLine =
|
|
45
|
-
exports.getFirstCodeNodeOfLine =
|
|
46
|
-
exports.getLanguageFriendlyName =
|
|
47
|
-
exports.getLastCodeNodeOfLine =
|
|
48
|
-
exports.getStartOfCodeInLine =
|
|
49
|
-
exports.normalizeCodeLang =
|
|
50
|
-
exports.registerCodeHighlighting =
|
|
44
|
+
exports.DEFAULT_CODE_LANGUAGE = q;
|
|
45
|
+
exports.PrismTokenizer = ot;
|
|
46
|
+
exports.getCodeLanguages = G;
|
|
47
|
+
exports.getDefaultCodeLanguage = X;
|
|
48
|
+
exports.getEndOfCodeInLine = vt;
|
|
49
|
+
exports.getFirstCodeNodeOfLine = St;
|
|
50
|
+
exports.getLanguageFriendlyName = Q;
|
|
51
|
+
exports.getLastCodeNodeOfLine = _t;
|
|
52
|
+
exports.getStartOfCodeInLine = Nt;
|
|
53
|
+
exports.normalizeCodeLang = $;
|
|
54
|
+
exports.registerCodeHighlighting = yt;
|
|
@@ -91,14 +91,18 @@ function $appendNodesToHTML(editor, currentNode, parentElement, selection = null
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
if (shouldInclude && !shouldExclude) {
|
|
94
|
-
if (LexicalUtils.isHTMLElement(element)) {
|
|
94
|
+
if (LexicalUtils.isHTMLElement(element) || lexical.isDocumentFragment(element)) {
|
|
95
95
|
element.append(fragment);
|
|
96
96
|
}
|
|
97
97
|
parentElement.append(element);
|
|
98
98
|
if (after) {
|
|
99
99
|
const newElement = after.call(target, element);
|
|
100
100
|
if (newElement) {
|
|
101
|
-
|
|
101
|
+
if (lexical.isDocumentFragment(element)) {
|
|
102
|
+
element.replaceChildren(newElement);
|
|
103
|
+
} else {
|
|
104
|
+
element.replaceWith(newElement);
|
|
105
|
+
}
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
} else {
|
|
@@ -115,7 +119,10 @@ function getConversionFunction(domNode, editor) {
|
|
|
115
119
|
if (cachedConversions !== undefined) {
|
|
116
120
|
for (const cachedConversion of cachedConversions) {
|
|
117
121
|
const domConversion = cachedConversion(domNode);
|
|
118
|
-
if (domConversion !== null && (currentConversion === null ||
|
|
122
|
+
if (domConversion !== null && (currentConversion === null ||
|
|
123
|
+
// Given equal priority, prefer the last registered importer
|
|
124
|
+
// which is typically an application custom node or HTMLConfig['import']
|
|
125
|
+
(currentConversion.priority || 0) <= (domConversion.priority || 0))) {
|
|
119
126
|
currentConversion = domConversion;
|
|
120
127
|
}
|
|
121
128
|
}
|
|
@@ -11,7 +11,7 @@ var LexicalHtml_prod = require('./LexicalHtml.prod.js');
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalHtml_dev : LexicalHtml_prod;
|
|
15
15
|
const $generateHtmlFromNodes = mod.$generateHtmlFromNodes;
|
|
16
16
|
const $generateNodesFromDOM = mod.$generateNodesFromDOM;
|
|
17
17
|
|
|
@@ -12,7 +12,7 @@ var lexical = require('lexical');
|
|
|
12
12
|
*
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function h(e,n){const t=n.body?n.body.childNodes:[];let o=[];const l=[];for(let n=0;n<t.length;n++){const r=t[n];if(!x.has(r.nodeName)){const n=y(r,e,l,!1);null!==n&&(o=o.concat(n));}}return function(e){for(const n of e)n.getNextSibling()instanceof lexical.ArtificialNode__DO_NOT_USE&&n.insertAfter(lexical.$createLineBreakNode());for(const n of e){const e=n.getChildren();for(const t of e)n.insertBefore(t);n.remove();}}(l),o}function m(e,n){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const t=document.createElement("div"),l=lexical.$getRoot().getChildren();for(let o=0;o<l.length;o++){g(e,l[o],t,n);}return t.innerHTML}function g(t,o,c,u=null){let f=null===u||o.isSelected(u);const a=lexical.$isElementNode(o)&&o.excludeFromCopy("html");let d=o;if(null!==u){let n=lexical.$cloneWithProperties(o);n=lexical.$isTextNode(n)&&null!==u?LexicalSelection.$sliceSelectedTextNodeContent(u,n):n,d=n;}const p=lexical.$isElementNode(d)?d.getChildren():[],h=t._nodes.get(d.getType());let m;m=h&&void 0!==h.exportDOM?h.exportDOM(t,d):d.exportDOM(t);const{element:x,after:y}=m;if(!x)return !1;const w=document.createDocumentFragment();for(let e=0;e<p.length;e++){const n=p[e],r=g(t,n,w,u);!f&&lexical.$isElementNode(o)&&r&&o.extractWithChild(n,u,"html")&&(f=!0);}if(f&&!a){if((LexicalUtils.isHTMLElement(x)||lexical.isDocumentFragment(x))&&x.append(w),c.append(x),y){const e=y.call(d,x);e&&(lexical.isDocumentFragment(x)?x.replaceChildren(e):x.replaceWith(e));}}else c.append(w);return f}const x=new Set(["STYLE","SCRIPT"]);function y(e,n,o,r,i=new Map,s){let h=[];if(x.has(e.nodeName))return h;let m=null;const g=function(e,n){const{nodeName:t}=e,o=n._htmlConversions.get(t.toLowerCase());let l=null;if(void 0!==o)for(const n of o){const t=n(e);null!==t&&(null===l||(l.priority||0)<=(t.priority||0))&&(l=t);}return null!==l?l.conversion:null}(e,n),b=g?g(e):null;let C=null;if(null!==b){C=b.after;const n=b.node;if(m=Array.isArray(n)?n[n.length-1]:n,null!==m){for(const[,e]of i)if(m=e(m,s),!m)break;m&&h.push(...Array.isArray(n)?n:[m]);}null!=b.forChild&&i.set(e.nodeName,b.forChild);}const S=e.childNodes;let v=[];const N=(null==m||!lexical.$isRootOrShadowRoot(m))&&(null!=m&&lexical.$isBlockElementNode(m)||r);for(let e=0;e<S.length;e++)v.push(...y(S[e],n,o,N,new Map(i),m));return null!=C&&(v=C(v)),LexicalUtils.isBlockDomNode(e)&&(v=w(e,v,N?()=>{const e=new lexical.ArtificialNode__DO_NOT_USE;return o.push(e),e}:lexical.$createParagraphNode)),null==m?v.length>0?h=h.concat(v):LexicalUtils.isBlockDomNode(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return !1;return lexical.isInlineDomNode(e.nextSibling)&&lexical.isInlineDomNode(e.previousSibling)}(e)&&(h=h.concat(lexical.$createLineBreakNode())):lexical.$isElementNode(m)&&m.append(...v),h}function w(e,n,t){const o=e.style.textAlign,l=[];let r=[];for(let e=0;e<n.length;e++){const i=n[e];if(lexical.$isBlockElementNode(i))o&&!i.getFormat()&&i.setFormat(o),l.push(i);else if(r.push(i),e===n.length-1||e<n.length-1&&lexical.$isBlockElementNode(n[e+1])){const e=t();e.setFormat(o),e.append(...r),l.push(e),r=[];}}return l}
|
|
16
16
|
|
|
17
|
-
exports.$generateHtmlFromNodes =
|
|
18
|
-
exports.$generateNodesFromDOM =
|
|
17
|
+
exports.$generateHtmlFromNodes = m;
|
|
18
|
+
exports.$generateNodesFromDOM = h;
|
|
@@ -20,6 +20,12 @@ var lexical = require('lexical');
|
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
24
|
+
|
|
25
|
+
function formatDevErrorMessage(message) {
|
|
26
|
+
throw new Error(message);
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
24
30
|
|
|
25
31
|
/** @noInheritDoc */
|
|
@@ -42,7 +48,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
42
48
|
title: node.__title
|
|
43
49
|
}, node.__key);
|
|
44
50
|
}
|
|
45
|
-
constructor(url, attributes = {}, key) {
|
|
51
|
+
constructor(url = '', attributes = {}, key) {
|
|
46
52
|
super(key);
|
|
47
53
|
const {
|
|
48
54
|
target = null,
|
|
@@ -70,7 +76,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
70
76
|
return element;
|
|
71
77
|
}
|
|
72
78
|
updateDOM(prevNode, anchor, config) {
|
|
73
|
-
if (anchor
|
|
79
|
+
if (LexicalUtils.isHTMLAnchorElement(anchor)) {
|
|
74
80
|
const url = this.__url;
|
|
75
81
|
const target = this.__target;
|
|
76
82
|
const rel = this.__rel;
|
|
@@ -111,15 +117,10 @@ class LinkNode extends lexical.ElementNode {
|
|
|
111
117
|
};
|
|
112
118
|
}
|
|
113
119
|
static importJSON(serializedNode) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
node.setFormat(serializedNode.format);
|
|
120
|
-
node.setIndent(serializedNode.indent);
|
|
121
|
-
node.setDirection(serializedNode.direction);
|
|
122
|
-
return node;
|
|
120
|
+
return $createLinkNode().updateFromJSON(serializedNode);
|
|
121
|
+
}
|
|
122
|
+
updateFromJSON(serializedNode) {
|
|
123
|
+
return super.updateFromJSON(serializedNode).setURL(serializedNode.url).setRel(serializedNode.rel || null).setTarget(serializedNode.target || null).setTitle(serializedNode.title || null);
|
|
123
124
|
}
|
|
124
125
|
sanitizeUrl(url) {
|
|
125
126
|
try {
|
|
@@ -139,9 +140,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
139
140
|
rel: this.getRel(),
|
|
140
141
|
target: this.getTarget(),
|
|
141
142
|
title: this.getTitle(),
|
|
142
|
-
|
|
143
|
-
url: this.getURL(),
|
|
144
|
-
version: 1
|
|
143
|
+
url: this.getURL()
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
146
|
getURL() {
|
|
@@ -150,6 +149,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
150
149
|
setURL(url) {
|
|
151
150
|
const writable = this.getWritable();
|
|
152
151
|
writable.__url = url;
|
|
152
|
+
return writable;
|
|
153
153
|
}
|
|
154
154
|
getTarget() {
|
|
155
155
|
return this.getLatest().__target;
|
|
@@ -157,6 +157,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
157
157
|
setTarget(target) {
|
|
158
158
|
const writable = this.getWritable();
|
|
159
159
|
writable.__target = target;
|
|
160
|
+
return writable;
|
|
160
161
|
}
|
|
161
162
|
getRel() {
|
|
162
163
|
return this.getLatest().__rel;
|
|
@@ -164,6 +165,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
164
165
|
setRel(rel) {
|
|
165
166
|
const writable = this.getWritable();
|
|
166
167
|
writable.__rel = rel;
|
|
168
|
+
return writable;
|
|
167
169
|
}
|
|
168
170
|
getTitle() {
|
|
169
171
|
return this.getLatest().__title;
|
|
@@ -171,6 +173,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
171
173
|
setTitle(title) {
|
|
172
174
|
const writable = this.getWritable();
|
|
173
175
|
writable.__title = title;
|
|
176
|
+
return writable;
|
|
174
177
|
}
|
|
175
178
|
insertNewAfter(_, restoreSelection = true) {
|
|
176
179
|
const linkNode = $createLinkNode(this.__url, {
|
|
@@ -231,7 +234,7 @@ function $convertAnchorElement(domNode) {
|
|
|
231
234
|
* @param attributes - Optional HTML a tag attributes \\{ target, rel, title \\}
|
|
232
235
|
* @returns The LinkNode.
|
|
233
236
|
*/
|
|
234
|
-
function $createLinkNode(url, attributes) {
|
|
237
|
+
function $createLinkNode(url = '', attributes) {
|
|
235
238
|
return lexical.$applyNodeReplacement(new LinkNode(url, attributes));
|
|
236
239
|
}
|
|
237
240
|
|
|
@@ -249,7 +252,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
249
252
|
/** @internal */
|
|
250
253
|
/** Indicates whether the autolink was ever unlinked. **/
|
|
251
254
|
|
|
252
|
-
constructor(url, attributes = {}, key) {
|
|
255
|
+
constructor(url = '', attributes = {}, key) {
|
|
253
256
|
super(url, attributes, key);
|
|
254
257
|
this.__isUnlinked = attributes.isUnlinked !== undefined && attributes.isUnlinked !== null ? attributes.isUnlinked : false;
|
|
255
258
|
}
|
|
@@ -283,16 +286,10 @@ class AutoLinkNode extends LinkNode {
|
|
|
283
286
|
return super.updateDOM(prevNode, anchor, config) || prevNode.__isUnlinked !== this.__isUnlinked;
|
|
284
287
|
}
|
|
285
288
|
static importJSON(serializedNode) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
title: serializedNode.title
|
|
291
|
-
});
|
|
292
|
-
node.setFormat(serializedNode.format);
|
|
293
|
-
node.setIndent(serializedNode.indent);
|
|
294
|
-
node.setDirection(serializedNode.direction);
|
|
295
|
-
return node;
|
|
289
|
+
return $createAutoLinkNode().updateFromJSON(serializedNode);
|
|
290
|
+
}
|
|
291
|
+
updateFromJSON(serializedNode) {
|
|
292
|
+
return super.updateFromJSON(serializedNode).setIsUnlinked(serializedNode.isUnlinked || false);
|
|
296
293
|
}
|
|
297
294
|
static importDOM() {
|
|
298
295
|
// TODO: Should link node should handle the import over autolink?
|
|
@@ -301,9 +298,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
301
298
|
exportJSON() {
|
|
302
299
|
return {
|
|
303
300
|
...super.exportJSON(),
|
|
304
|
-
isUnlinked: this.__isUnlinked
|
|
305
|
-
type: 'autolink',
|
|
306
|
-
version: 1
|
|
301
|
+
isUnlinked: this.__isUnlinked
|
|
307
302
|
};
|
|
308
303
|
}
|
|
309
304
|
insertNewAfter(selection, restoreSelection = true) {
|
|
@@ -329,7 +324,7 @@ class AutoLinkNode extends LinkNode {
|
|
|
329
324
|
* @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
|
|
330
325
|
* @returns The LinkNode.
|
|
331
326
|
*/
|
|
332
|
-
function $createAutoLinkNode(url, attributes) {
|
|
327
|
+
function $createAutoLinkNode(url = '', attributes) {
|
|
333
328
|
return lexical.$applyNodeReplacement(new AutoLinkNode(url, attributes));
|
|
334
329
|
}
|
|
335
330
|
|
|
@@ -342,6 +337,56 @@ function $isAutoLinkNode(node) {
|
|
|
342
337
|
return node instanceof AutoLinkNode;
|
|
343
338
|
}
|
|
344
339
|
const TOGGLE_LINK_COMMAND = lexical.createCommand('TOGGLE_LINK_COMMAND');
|
|
340
|
+
function $getPointNode(point, offset) {
|
|
341
|
+
if (point.type === 'element') {
|
|
342
|
+
const node = point.getNode();
|
|
343
|
+
if (!lexical.$isElementNode(node)) {
|
|
344
|
+
formatDevErrorMessage(`$getPointNode: element point is not an ElementNode`);
|
|
345
|
+
}
|
|
346
|
+
const childNode = node.getChildren()[point.offset + offset];
|
|
347
|
+
return childNode || null;
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Preserve the logical start/end of a RangeSelection in situations where
|
|
354
|
+
* the point is an element that may be reparented in the callback.
|
|
355
|
+
*
|
|
356
|
+
* @param $fn The function to run
|
|
357
|
+
* @returns The result of the callback
|
|
358
|
+
*/
|
|
359
|
+
function $withSelectedNodes($fn) {
|
|
360
|
+
const initialSelection = lexical.$getSelection();
|
|
361
|
+
if (!lexical.$isRangeSelection(initialSelection)) {
|
|
362
|
+
return $fn();
|
|
363
|
+
}
|
|
364
|
+
const normalized = lexical.$normalizeSelection__EXPERIMENTAL(initialSelection);
|
|
365
|
+
const isBackwards = normalized.isBackward();
|
|
366
|
+
const anchorNode = $getPointNode(normalized.anchor, isBackwards ? -1 : 0);
|
|
367
|
+
const focusNode = $getPointNode(normalized.focus, isBackwards ? 0 : -1);
|
|
368
|
+
const rval = $fn();
|
|
369
|
+
if (anchorNode || focusNode) {
|
|
370
|
+
const updatedSelection = lexical.$getSelection();
|
|
371
|
+
if (lexical.$isRangeSelection(updatedSelection)) {
|
|
372
|
+
const finalSelection = updatedSelection.clone();
|
|
373
|
+
if (anchorNode) {
|
|
374
|
+
const anchorParent = anchorNode.getParent();
|
|
375
|
+
if (anchorParent) {
|
|
376
|
+
finalSelection.anchor.set(anchorParent.getKey(), anchorNode.getIndexWithinParent() + (isBackwards ? 1 : 0), 'element');
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (focusNode) {
|
|
380
|
+
const focusParent = focusNode.getParent();
|
|
381
|
+
if (focusParent) {
|
|
382
|
+
finalSelection.focus.set(focusParent.getKey(), focusNode.getIndexWithinParent() + (isBackwards ? 0 : 1), 'element');
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
lexical.$setSelection(lexical.$normalizeSelection__EXPERIMENTAL(finalSelection));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return rval;
|
|
389
|
+
}
|
|
345
390
|
|
|
346
391
|
/**
|
|
347
392
|
* Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
|
|
@@ -363,92 +408,91 @@ function $toggleLink(url, attributes = {}) {
|
|
|
363
408
|
if (url === null) {
|
|
364
409
|
// Remove LinkNodes
|
|
365
410
|
nodes.forEach(node => {
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
368
|
-
const children =
|
|
411
|
+
const parentLink = LexicalUtils.$findMatchingParent(node, parent => !$isAutoLinkNode(parent) && $isLinkNode(parent));
|
|
412
|
+
if (parentLink) {
|
|
413
|
+
const children = parentLink.getChildren();
|
|
369
414
|
for (let i = 0; i < children.length; i++) {
|
|
370
|
-
|
|
415
|
+
parentLink.insertBefore(children[i]);
|
|
371
416
|
}
|
|
372
|
-
|
|
417
|
+
parentLink.remove();
|
|
373
418
|
}
|
|
374
419
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
if (title !== undefined) {
|
|
391
|
-
linkNode.setTitle(title);
|
|
392
|
-
}
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const updatedNodes = new Set();
|
|
423
|
+
const updateLinkNode = linkNode => {
|
|
424
|
+
if (updatedNodes.has(linkNode.getKey())) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
updatedNodes.add(linkNode.getKey());
|
|
428
|
+
linkNode.setURL(url);
|
|
429
|
+
if (target !== undefined) {
|
|
430
|
+
linkNode.setTarget(target);
|
|
431
|
+
}
|
|
432
|
+
if (rel !== undefined) {
|
|
433
|
+
linkNode.setRel(rel);
|
|
395
434
|
}
|
|
396
|
-
|
|
435
|
+
if (title !== undefined) {
|
|
436
|
+
linkNode.setTitle(title);
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
// Add or merge LinkNodes
|
|
440
|
+
if (nodes.length === 1) {
|
|
441
|
+
const firstNode = nodes[0];
|
|
442
|
+
// if the first node is a LinkNode or if its
|
|
443
|
+
// parent is a LinkNode, we update the URL, target and rel.
|
|
444
|
+
const linkNode = $getAncestor(firstNode, $isLinkNode);
|
|
445
|
+
if (linkNode !== null) {
|
|
446
|
+
return updateLinkNode(linkNode);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
$withSelectedNodes(() => {
|
|
397
450
|
let linkNode = null;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
return;
|
|
451
|
+
for (const node of nodes) {
|
|
452
|
+
if (!node.isAttached()) {
|
|
453
|
+
continue;
|
|
402
454
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
parent.setTarget(target);
|
|
408
|
-
}
|
|
409
|
-
if (rel !== null) {
|
|
410
|
-
linkNode.setRel(rel);
|
|
411
|
-
}
|
|
412
|
-
if (title !== undefined) {
|
|
413
|
-
linkNode.setTitle(title);
|
|
414
|
-
}
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
if (!parent.is(prevParent)) {
|
|
418
|
-
prevParent = parent;
|
|
419
|
-
linkNode = $createLinkNode(url, {
|
|
420
|
-
rel,
|
|
421
|
-
target,
|
|
422
|
-
title
|
|
423
|
-
});
|
|
424
|
-
if ($isLinkNode(parent)) {
|
|
425
|
-
if (node.getPreviousSibling() === null) {
|
|
426
|
-
parent.insertBefore(linkNode);
|
|
427
|
-
} else {
|
|
428
|
-
parent.insertAfter(linkNode);
|
|
429
|
-
}
|
|
430
|
-
} else {
|
|
431
|
-
node.insertBefore(linkNode);
|
|
432
|
-
}
|
|
455
|
+
const parentLinkNode = $getAncestor(node, $isLinkNode);
|
|
456
|
+
if (parentLinkNode) {
|
|
457
|
+
updateLinkNode(parentLinkNode);
|
|
458
|
+
continue;
|
|
433
459
|
}
|
|
434
|
-
if (
|
|
435
|
-
if (node.
|
|
436
|
-
|
|
460
|
+
if (lexical.$isElementNode(node)) {
|
|
461
|
+
if (!node.isInline()) {
|
|
462
|
+
// Ignore block nodes, if there are any children we will see them
|
|
463
|
+
// later and wrap in a new LinkNode
|
|
464
|
+
continue;
|
|
437
465
|
}
|
|
438
|
-
if (
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
466
|
+
if ($isLinkNode(node)) {
|
|
467
|
+
// If it's not an autolink node and we don't already have a LinkNode
|
|
468
|
+
// in this block then we can update it and re-use it
|
|
469
|
+
if (!$isAutoLinkNode(node) && (linkNode === null || !linkNode.getParentOrThrow().isParentOf(node))) {
|
|
470
|
+
updateLinkNode(node);
|
|
471
|
+
linkNode = node;
|
|
472
|
+
continue;
|
|
442
473
|
}
|
|
474
|
+
// Unwrap LinkNode, we already have one or it's an AutoLinkNode
|
|
475
|
+
for (const child of node.getChildren()) {
|
|
476
|
+
node.insertBefore(child);
|
|
477
|
+
}
|
|
478
|
+
node.remove();
|
|
479
|
+
continue;
|
|
443
480
|
}
|
|
444
|
-
node.remove();
|
|
445
|
-
return;
|
|
446
481
|
}
|
|
447
|
-
|
|
448
|
-
|
|
482
|
+
const prevLinkNode = node.getPreviousSibling();
|
|
483
|
+
if ($isLinkNode(prevLinkNode) && prevLinkNode.is(linkNode)) {
|
|
484
|
+
prevLinkNode.append(node);
|
|
485
|
+
continue;
|
|
449
486
|
}
|
|
450
|
-
|
|
451
|
-
|
|
487
|
+
linkNode = $createLinkNode(url, {
|
|
488
|
+
rel,
|
|
489
|
+
target,
|
|
490
|
+
title
|
|
491
|
+
});
|
|
492
|
+
node.insertAfter(linkNode);
|
|
493
|
+
linkNode.append(node);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
452
496
|
}
|
|
453
497
|
/** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
|
|
454
498
|
const toggleLink = $toggleLink;
|
|
@@ -11,7 +11,7 @@ var LexicalLink_prod = require('./LexicalLink.prod.js');
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalLink_dev : LexicalLink_prod;
|
|
15
15
|
const $isLinkNode = mod.$isLinkNode;
|
|
16
16
|
|
|
17
17
|
exports.$isLinkNode = $isLinkNode;
|
|
@@ -11,14 +11,14 @@ var lexical = require('lexical');
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const c=new Set(["http:","https:","mailto:","sms:","tel:"]);class h extends lexical.ElementNode{static getType(){return "link"}static clone(t){return new h(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},r){super(r);const{target:n=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=s;}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),LexicalUtils.addClassNamesToElement(r,e.theme.link),r}updateDOM(t,r,n){if(LexicalUtils.isHTMLAnchorElement(r)){const e=this.__url,n=this.__target,i=this.__rel,s=this.__title;e!==t.__url&&(r.href=e),n!==t.__target&&(n?r.target=n:r.removeAttribute("target")),i!==t.__rel&&(i?r.rel=i:r.removeAttribute("rel")),s!==t.__title&&(s?r.title=s:r.removeAttribute("title"));}return !1}static importDOM(){return {a:t=>({conversion:g,priority:1})}}static importJSON(t){return f().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){try{const e=new URL(t);if(!c.has(e.protocol))return "about:blank"}catch(e){return t}return t}exportJSON(){return {...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const r=f(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return !1}canInsertTextAfter(){return !1}canBeEmpty(){return !1}isInline(){return !0}extractWithChild(t,e,r){if(!lexical.$isRangeSelection(e))return !1;const n=e.anchor.getNode(),i=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(i)&&e.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function g(t){let r=null;if(LexicalUtils.isHTMLAnchorElement(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=f(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}));}return {node:r}}function f(t="",e){return lexical.$applyNodeReplacement(new h(t,e))}function d(t){return t instanceof h}class p extends h{constructor(t="",e={},r){super(t,e,r),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked;}static getType(){return "autolink"}static clone(t){return new p(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,r){return super.updateDOM(t,e,r)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return m().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return {...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if(lexical.$isElementNode(r)){const t=m(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function m(t="",e){return lexical.$applyNodeReplacement(new p(t,e))}function U(t){return t instanceof p}const O=lexical.createCommand("TOGGLE_LINK_COMMAND");function k(t,e){if("element"===t.type){const r=t.getNode();lexical.$isElementNode(r)||function(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return r.getChildren()[t.offset+e]||null}return null}function N(t,e={}){const{target:n,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,c=lexical.$getSelection();if(!lexical.$isRangeSelection(c))return;const h=c.extract();if(null===t)return void h.forEach((t=>{const e=LexicalUtils.$findMatchingParent(t,(t=>!U(t)&&d(t)));if(e){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove();}}));const g=new Set,p=e=>{g.has(e.getKey())||(g.add(e.getKey()),e.setURL(t),void 0!==n&&e.setTarget(n),void 0!==l&&e.setRel(l),void 0!==i&&e.setTitle(i));};if(1===h.length){const t=S(h[0],d);if(null!==t)return p(t)}!function(t){const e=lexical.$getSelection();if(!lexical.$isRangeSelection(e))return t();const r=lexical.$normalizeSelection__EXPERIMENTAL(e),n=r.isBackward(),i=k(r.anchor,n?-1:0),l=k(r.focus,n?0:-1);t();if(i||l){const t=lexical.$getSelection();if(lexical.$isRangeSelection(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(n?1:0),"element");}if(l){const t=l.getParent();t&&e.focus.set(t.getKey(),l.getIndexWithinParent()+(n?0:1),"element");}lexical.$setSelection(lexical.$normalizeSelection__EXPERIMENTAL(e));}}}((()=>{let e=null;for(const r of h){if(!r.isAttached())continue;const s=S(r,d);if(s){p(s);continue}if(lexical.$isElementNode(r)){if(!r.isInline())continue;if(d(r)){if(!(U(r)||null!==e&&e.getParentOrThrow().isParentOf(r))){p(r),e=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const u=r.getPreviousSibling();d(u)&&u.is(e)?u.append(r):(e=f(t,{rel:l,target:n,title:i}),r.insertAfter(e),e.append(r));}}));}const x=N;function S(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}
|
|
15
15
|
|
|
16
|
-
exports.$createAutoLinkNode =
|
|
17
|
-
exports.$createLinkNode =
|
|
18
|
-
exports.$isAutoLinkNode =
|
|
19
|
-
exports.$isLinkNode =
|
|
20
|
-
exports.$toggleLink =
|
|
21
|
-
exports.AutoLinkNode =
|
|
22
|
-
exports.LinkNode =
|
|
23
|
-
exports.TOGGLE_LINK_COMMAND =
|
|
24
|
-
exports.toggleLink =
|
|
16
|
+
exports.$createAutoLinkNode = m;
|
|
17
|
+
exports.$createLinkNode = f;
|
|
18
|
+
exports.$isAutoLinkNode = U;
|
|
19
|
+
exports.$isLinkNode = d;
|
|
20
|
+
exports.$toggleLink = N;
|
|
21
|
+
exports.AutoLinkNode = p;
|
|
22
|
+
exports.LinkNode = h;
|
|
23
|
+
exports.TOGGLE_LINK_COMMAND = O;
|
|
24
|
+
exports.toggleLink = x;
|