@react-fabric/lexical 1.0.0-beta.9 → 1.0.2
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} +79 -13
- package/css/styles.css +24 -0
- package/dist/cjs/{packages/lexical/src/editor → editor}/LexicalEditor.js +98 -45
- package/dist/cjs/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +147 -140
- package/dist/cjs/i18n/ar/lexical.json.js +30 -0
- package/dist/cjs/i18n/en/lexical.json.js +30 -0
- package/{src/plugins/StickyPlugin.ts → dist/cjs/i18n/index.js} +10 -15
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/plugins/CommentPlugin.js +481 -0
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +17 -20
- package/dist/cjs/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +58 -37
- package/dist/esm/{packages/lexical/src/editor → editor}/LexicalEditor.js +101 -48
- package/dist/esm/{packages/lexical/src/hooks → hooks}/useFormatWatcher.js +95 -88
- package/dist/esm/i18n/ar/lexical.json.js +25 -0
- package/dist/esm/i18n/en/lexical.json.js +25 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/plugins/CommentPlugin.js +481 -0
- package/dist/esm/{packages/lexical/src/plugins → plugins}/DraggableBlockPlugin.js +15 -18
- package/dist/esm/{packages/lexical/src/plugins → plugins}/ToolbarPlugin.js +59 -38
- package/dist/types/editor/LexicalEditor.d.ts +33 -4
- package/dist/types/hooks/useFormatWatcher.d.ts +7 -4
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/plugins/CommentPlugin.d.ts +5 -0
- package/dist/types/plugins/DraggableBlockPlugin.d.ts +3 -2
- package/dist/types/plugins/ToolbarPlugin.d.ts +1 -1
- package/dist/types/utils/index.d.ts +3 -6
- package/package.json +18 -18
- package/src/editor/LexicalEditor.tsx +95 -55
- package/src/hooks/useFormatWatcher.ts +50 -74
- package/src/i18n/ar/lexical.json +18 -0
- package/src/i18n/en/lexical.json +18 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +24 -17
- package/src/plugins/CommentPlugin.tsx +523 -0
- package/src/plugins/DraggableBlockPlugin.tsx +23 -68
- package/src/plugins/ToolbarPlugin.tsx +83 -131
- package/src/utils/index.ts +12 -108
- package/dist/cjs/_virtual/prism.js +0 -5
- package/dist/cjs/editor/Lexical.module.css +0 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -432
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -21
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -27
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +0 -1139
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +0 -25
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +0 -50
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +0 -245
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +0 -19
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +0 -18
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +0 -471
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +0 -24
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +0 -1275
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +0 -29
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -789
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +0 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -26
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -976
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +0 -35
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -35
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +0 -2792
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +0 -23
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +0 -55
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -888
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +0 -35
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -66
- package/dist/cjs/node_modules/@mdi/js/mdi.js +0 -8
- package/dist/cjs/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/cjs/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/cjs/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/cjs/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/cjs/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/cjs/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/cjs/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/cjs/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/cjs/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/cjs/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/cjs/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/cjs/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/cjs/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/cjs/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/cjs/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/cjs/node_modules/prismjs/prism.js +0 -1951
- package/dist/cjs/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/cjs/packages/lexical/src/index.js +0 -7
- package/dist/cjs/packages/lexical/src/nodes/StickyNode.js +0 -218
- package/dist/cjs/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/esm/_virtual/prism.js +0 -5
- package/dist/esm/editor/Lexical.module.css +0 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +0 -423
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +0 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +0 -1121
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +0 -21
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +0 -32
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +0 -244
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +0 -18
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +0 -463
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +0 -17
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +0 -1262
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +0 -23
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +0 -781
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +0 -23
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +0 -18
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +0 -957
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +0 -26
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +0 -16
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +0 -2754
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +0 -20
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +0 -17
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +0 -839
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +0 -26
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +0 -17
- package/dist/esm/node_modules/@mdi/js/mdi.js +0 -7
- package/dist/esm/node_modules/prismjs/components/prism-c.js +0 -82
- package/dist/esm/node_modules/prismjs/components/prism-clike.js +0 -33
- package/dist/esm/node_modules/prismjs/components/prism-cpp.js +0 -101
- package/dist/esm/node_modules/prismjs/components/prism-css.js +0 -66
- package/dist/esm/node_modules/prismjs/components/prism-java.js +0 -126
- package/dist/esm/node_modules/prismjs/components/prism-javascript.js +0 -174
- package/dist/esm/node_modules/prismjs/components/prism-markdown.js +0 -417
- package/dist/esm/node_modules/prismjs/components/prism-markup.js +0 -188
- package/dist/esm/node_modules/prismjs/components/prism-objectivec.js +0 -14
- package/dist/esm/node_modules/prismjs/components/prism-powershell.js +0 -60
- package/dist/esm/node_modules/prismjs/components/prism-python.js +0 -67
- package/dist/esm/node_modules/prismjs/components/prism-rust.js +0 -130
- package/dist/esm/node_modules/prismjs/components/prism-sql.js +0 -34
- package/dist/esm/node_modules/prismjs/components/prism-swift.js +0 -150
- package/dist/esm/node_modules/prismjs/components/prism-typescript.js +0 -62
- package/dist/esm/node_modules/prismjs/prism.js +0 -1951
- package/dist/esm/packages/lexical/src/components/StickyComponent.js +0 -221
- package/dist/esm/packages/lexical/src/index.js +0 -3
- package/dist/esm/packages/lexical/src/nodes/StickyNode.js +0 -216
- package/dist/esm/packages/lexical/src/plugins/StickyPlugin.js +0 -20
- package/dist/types/components/StickyComponent.d.ts +0 -9
- package/dist/types/nodes/StickyNode.d.ts +0 -35
- package/dist/types/plugins/StickyPlugin.d.ts +0 -1
- package/src/components/StickyComponent.tsx +0 -271
- package/src/nodes/StickyNode.tsx +0 -249
- /package/dist/cjs/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/cjs/{packages/lexical/src/utils → utils}/index.js +0 -0
- /package/dist/esm/{packages/lexical/src/editor → editor}/theme.js +0 -0
- /package/dist/esm/{packages/lexical/src/utils → utils}/index.js +0 -0
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalCode_dev = require('./LexicalCode.dev.js');
|
|
4
|
-
var LexicalCode_prod = require('./LexicalCode.prod.js');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const mod = process.env.NODE_ENV === 'development' ? LexicalCode_dev : LexicalCode_prod;
|
|
15
|
-
const $createCodeNode = mod.$createCodeNode;
|
|
16
|
-
const $isCodeNode = mod.$isCodeNode;
|
|
17
|
-
const CODE_LANGUAGE_MAP = mod.CODE_LANGUAGE_MAP;
|
|
18
|
-
const CodeHighlightNode = mod.CodeHighlightNode;
|
|
19
|
-
const CodeNode = mod.CodeNode;
|
|
20
|
-
|
|
21
|
-
exports.$createCodeNode = $createCodeNode;
|
|
22
|
-
exports.$isCodeNode = $isCodeNode;
|
|
23
|
-
exports.CODE_LANGUAGE_MAP = CODE_LANGUAGE_MAP;
|
|
24
|
-
exports.CodeHighlightNode = CodeHighlightNode;
|
|
25
|
-
exports.CodeNode = CodeNode;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
require('../../prismjs/prism.js');
|
|
4
|
-
require('../../prismjs/components/prism-clike.js');
|
|
5
|
-
require('../../prismjs/components/prism-javascript.js');
|
|
6
|
-
require('../../prismjs/components/prism-markup.js');
|
|
7
|
-
require('../../prismjs/components/prism-markdown.js');
|
|
8
|
-
require('../../prismjs/components/prism-c.js');
|
|
9
|
-
require('../../prismjs/components/prism-css.js');
|
|
10
|
-
require('../../prismjs/components/prism-objectivec.js');
|
|
11
|
-
require('../../prismjs/components/prism-sql.js');
|
|
12
|
-
require('../../prismjs/components/prism-powershell.js');
|
|
13
|
-
require('../../prismjs/components/prism-python.js');
|
|
14
|
-
require('../../prismjs/components/prism-rust.js');
|
|
15
|
-
require('../../prismjs/components/prism-swift.js');
|
|
16
|
-
require('../../prismjs/components/prism-typescript.js');
|
|
17
|
-
require('../../prismjs/components/prism-java.js');
|
|
18
|
-
require('../../prismjs/components/prism-cpp.js');
|
|
19
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
20
|
-
var lexical = require('lexical');
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24
|
-
*
|
|
25
|
-
* This source code is licensed under the MIT license found in the
|
|
26
|
-
* LICENSE file in the root directory of this source tree.
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
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))}
|
|
31
|
-
|
|
32
|
-
exports.$createCodeHighlightNode = V;
|
|
33
|
-
exports.$createCodeNode = H;
|
|
34
|
-
exports.$isCodeHighlightNode = Y;
|
|
35
|
-
exports.$isCodeNode = D;
|
|
36
|
-
exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP = K;
|
|
37
|
-
exports.CODE_LANGUAGE_MAP = q;
|
|
38
|
-
exports.CodeHighlightNode = X;
|
|
39
|
-
exports.CodeNode = M;
|
|
40
|
-
exports.DEFAULT_CODE_LANGUAGE = F;
|
|
41
|
-
exports.PrismTokenizer = et;
|
|
42
|
-
exports.getCodeLanguages = Q;
|
|
43
|
-
exports.getDefaultCodeLanguage = $;
|
|
44
|
-
exports.getEndOfCodeInLine = rt;
|
|
45
|
-
exports.getFirstCodeNodeOfLine = Z;
|
|
46
|
-
exports.getLanguageFriendlyName = W;
|
|
47
|
-
exports.getLastCodeNodeOfLine = tt;
|
|
48
|
-
exports.getStartOfCodeInLine = nt;
|
|
49
|
-
exports.normalizeCodeLang = U;
|
|
50
|
-
exports.registerCodeHighlighting = dt;
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalSelection = require('../selection/LexicalSelection.js');
|
|
4
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
5
|
-
var lexical = require('lexical');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the MIT license found in the
|
|
11
|
-
* LICENSE file in the root directory of this source tree.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the MIT license found in the
|
|
20
|
-
* LICENSE file in the root directory of this source tree.
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* How you parse your html string to get a document is left up to you. In the browser you can use the native
|
|
27
|
-
* DOMParser API to generate a document (see clipboard.ts), but to use in a headless environment you can use JSDom
|
|
28
|
-
* or an equivalent library and pass in the document here.
|
|
29
|
-
*/
|
|
30
|
-
function $generateNodesFromDOM(editor, dom) {
|
|
31
|
-
const elements = dom.body ? dom.body.childNodes : [];
|
|
32
|
-
let lexicalNodes = [];
|
|
33
|
-
const allArtificialNodes = [];
|
|
34
|
-
for (let i = 0; i < elements.length; i++) {
|
|
35
|
-
const element = elements[i];
|
|
36
|
-
if (!IGNORE_TAGS.has(element.nodeName)) {
|
|
37
|
-
const lexicalNode = $createNodesFromDOM(element, editor, allArtificialNodes, false);
|
|
38
|
-
if (lexicalNode !== null) {
|
|
39
|
-
lexicalNodes = lexicalNodes.concat(lexicalNode);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
$unwrapArtificalNodes(allArtificialNodes);
|
|
44
|
-
return lexicalNodes;
|
|
45
|
-
}
|
|
46
|
-
function $generateHtmlFromNodes(editor, selection) {
|
|
47
|
-
if (typeof document === 'undefined' || typeof window === 'undefined' && typeof global.window === 'undefined') {
|
|
48
|
-
throw new Error('To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.');
|
|
49
|
-
}
|
|
50
|
-
const container = document.createElement('div');
|
|
51
|
-
const root = lexical.$getRoot();
|
|
52
|
-
const topLevelChildren = root.getChildren();
|
|
53
|
-
for (let i = 0; i < topLevelChildren.length; i++) {
|
|
54
|
-
const topLevelNode = topLevelChildren[i];
|
|
55
|
-
$appendNodesToHTML(editor, topLevelNode, container, selection);
|
|
56
|
-
}
|
|
57
|
-
return container.innerHTML;
|
|
58
|
-
}
|
|
59
|
-
function $appendNodesToHTML(editor, currentNode, parentElement, selection = null) {
|
|
60
|
-
let shouldInclude = selection !== null ? currentNode.isSelected(selection) : true;
|
|
61
|
-
const shouldExclude = lexical.$isElementNode(currentNode) && currentNode.excludeFromCopy('html');
|
|
62
|
-
let target = currentNode;
|
|
63
|
-
if (selection !== null) {
|
|
64
|
-
let clone = lexical.$cloneWithProperties(currentNode);
|
|
65
|
-
clone = lexical.$isTextNode(clone) && selection !== null ? LexicalSelection.$sliceSelectedTextNodeContent(selection, clone) : clone;
|
|
66
|
-
target = clone;
|
|
67
|
-
}
|
|
68
|
-
const children = lexical.$isElementNode(target) ? target.getChildren() : [];
|
|
69
|
-
const registeredNode = editor._nodes.get(target.getType());
|
|
70
|
-
let exportOutput;
|
|
71
|
-
|
|
72
|
-
// Use HTMLConfig overrides, if available.
|
|
73
|
-
if (registeredNode && registeredNode.exportDOM !== undefined) {
|
|
74
|
-
exportOutput = registeredNode.exportDOM(editor, target);
|
|
75
|
-
} else {
|
|
76
|
-
exportOutput = target.exportDOM(editor);
|
|
77
|
-
}
|
|
78
|
-
const {
|
|
79
|
-
element,
|
|
80
|
-
after
|
|
81
|
-
} = exportOutput;
|
|
82
|
-
if (!element) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
const fragment = document.createDocumentFragment();
|
|
86
|
-
for (let i = 0; i < children.length; i++) {
|
|
87
|
-
const childNode = children[i];
|
|
88
|
-
const shouldIncludeChild = $appendNodesToHTML(editor, childNode, fragment, selection);
|
|
89
|
-
if (!shouldInclude && lexical.$isElementNode(currentNode) && shouldIncludeChild && currentNode.extractWithChild(childNode, selection, 'html')) {
|
|
90
|
-
shouldInclude = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (shouldInclude && !shouldExclude) {
|
|
94
|
-
if (LexicalUtils.isHTMLElement(element)) {
|
|
95
|
-
element.append(fragment);
|
|
96
|
-
}
|
|
97
|
-
parentElement.append(element);
|
|
98
|
-
if (after) {
|
|
99
|
-
const newElement = after.call(target, element);
|
|
100
|
-
if (newElement) {
|
|
101
|
-
element.replaceWith(newElement);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
parentElement.append(fragment);
|
|
106
|
-
}
|
|
107
|
-
return shouldInclude;
|
|
108
|
-
}
|
|
109
|
-
function getConversionFunction(domNode, editor) {
|
|
110
|
-
const {
|
|
111
|
-
nodeName
|
|
112
|
-
} = domNode;
|
|
113
|
-
const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
|
|
114
|
-
let currentConversion = null;
|
|
115
|
-
if (cachedConversions !== undefined) {
|
|
116
|
-
for (const cachedConversion of cachedConversions) {
|
|
117
|
-
const domConversion = cachedConversion(domNode);
|
|
118
|
-
if (domConversion !== null && (currentConversion === null || (currentConversion.priority || 0) < (domConversion.priority || 0))) {
|
|
119
|
-
currentConversion = domConversion;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return currentConversion !== null ? currentConversion.conversion : null;
|
|
124
|
-
}
|
|
125
|
-
const IGNORE_TAGS = new Set(['STYLE', 'SCRIPT']);
|
|
126
|
-
function $createNodesFromDOM(node, editor, allArtificialNodes, hasBlockAncestorLexicalNode, forChildMap = new Map(), parentLexicalNode) {
|
|
127
|
-
let lexicalNodes = [];
|
|
128
|
-
if (IGNORE_TAGS.has(node.nodeName)) {
|
|
129
|
-
return lexicalNodes;
|
|
130
|
-
}
|
|
131
|
-
let currentLexicalNode = null;
|
|
132
|
-
const transformFunction = getConversionFunction(node, editor);
|
|
133
|
-
const transformOutput = transformFunction ? transformFunction(node) : null;
|
|
134
|
-
let postTransform = null;
|
|
135
|
-
if (transformOutput !== null) {
|
|
136
|
-
postTransform = transformOutput.after;
|
|
137
|
-
const transformNodes = transformOutput.node;
|
|
138
|
-
currentLexicalNode = Array.isArray(transformNodes) ? transformNodes[transformNodes.length - 1] : transformNodes;
|
|
139
|
-
if (currentLexicalNode !== null) {
|
|
140
|
-
for (const [, forChildFunction] of forChildMap) {
|
|
141
|
-
currentLexicalNode = forChildFunction(currentLexicalNode, parentLexicalNode);
|
|
142
|
-
if (!currentLexicalNode) {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (currentLexicalNode) {
|
|
147
|
-
lexicalNodes.push(...(Array.isArray(transformNodes) ? transformNodes : [currentLexicalNode]));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (transformOutput.forChild != null) {
|
|
151
|
-
forChildMap.set(node.nodeName, transformOutput.forChild);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// If the DOM node doesn't have a transformer, we don't know what
|
|
156
|
-
// to do with it but we still need to process any childNodes.
|
|
157
|
-
const children = node.childNodes;
|
|
158
|
-
let childLexicalNodes = [];
|
|
159
|
-
const hasBlockAncestorLexicalNodeForChildren = currentLexicalNode != null && lexical.$isRootOrShadowRoot(currentLexicalNode) ? false : currentLexicalNode != null && lexical.$isBlockElementNode(currentLexicalNode) || hasBlockAncestorLexicalNode;
|
|
160
|
-
for (let i = 0; i < children.length; i++) {
|
|
161
|
-
childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, allArtificialNodes, hasBlockAncestorLexicalNodeForChildren, new Map(forChildMap), currentLexicalNode));
|
|
162
|
-
}
|
|
163
|
-
if (postTransform != null) {
|
|
164
|
-
childLexicalNodes = postTransform(childLexicalNodes);
|
|
165
|
-
}
|
|
166
|
-
if (LexicalUtils.isBlockDomNode(node)) {
|
|
167
|
-
if (!hasBlockAncestorLexicalNodeForChildren) {
|
|
168
|
-
childLexicalNodes = wrapContinuousInlines(node, childLexicalNodes, lexical.$createParagraphNode);
|
|
169
|
-
} else {
|
|
170
|
-
childLexicalNodes = wrapContinuousInlines(node, childLexicalNodes, () => {
|
|
171
|
-
const artificialNode = new lexical.ArtificialNode__DO_NOT_USE();
|
|
172
|
-
allArtificialNodes.push(artificialNode);
|
|
173
|
-
return artificialNode;
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (currentLexicalNode == null) {
|
|
178
|
-
if (childLexicalNodes.length > 0) {
|
|
179
|
-
// If it hasn't been converted to a LexicalNode, we hoist its children
|
|
180
|
-
// up to the same level as it.
|
|
181
|
-
lexicalNodes = lexicalNodes.concat(childLexicalNodes);
|
|
182
|
-
} else {
|
|
183
|
-
if (LexicalUtils.isBlockDomNode(node) && isDomNodeBetweenTwoInlineNodes(node)) {
|
|
184
|
-
// Empty block dom node that hasnt been converted, we replace it with a linebreak if its between inline nodes
|
|
185
|
-
lexicalNodes = lexicalNodes.concat(lexical.$createLineBreakNode());
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
} else {
|
|
189
|
-
if (lexical.$isElementNode(currentLexicalNode)) {
|
|
190
|
-
// If the current node is a ElementNode after conversion,
|
|
191
|
-
// we can append all the children to it.
|
|
192
|
-
currentLexicalNode.append(...childLexicalNodes);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return lexicalNodes;
|
|
196
|
-
}
|
|
197
|
-
function wrapContinuousInlines(domNode, nodes, createWrapperFn) {
|
|
198
|
-
const textAlign = domNode.style.textAlign;
|
|
199
|
-
const out = [];
|
|
200
|
-
let continuousInlines = [];
|
|
201
|
-
// wrap contiguous inline child nodes in para
|
|
202
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
203
|
-
const node = nodes[i];
|
|
204
|
-
if (lexical.$isBlockElementNode(node)) {
|
|
205
|
-
if (textAlign && !node.getFormat()) {
|
|
206
|
-
node.setFormat(textAlign);
|
|
207
|
-
}
|
|
208
|
-
out.push(node);
|
|
209
|
-
} else {
|
|
210
|
-
continuousInlines.push(node);
|
|
211
|
-
if (i === nodes.length - 1 || i < nodes.length - 1 && lexical.$isBlockElementNode(nodes[i + 1])) {
|
|
212
|
-
const wrapper = createWrapperFn();
|
|
213
|
-
wrapper.setFormat(textAlign);
|
|
214
|
-
wrapper.append(...continuousInlines);
|
|
215
|
-
out.push(wrapper);
|
|
216
|
-
continuousInlines = [];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return out;
|
|
221
|
-
}
|
|
222
|
-
function $unwrapArtificalNodes(allArtificialNodes) {
|
|
223
|
-
for (const node of allArtificialNodes) {
|
|
224
|
-
if (node.getNextSibling() instanceof lexical.ArtificialNode__DO_NOT_USE) {
|
|
225
|
-
node.insertAfter(lexical.$createLineBreakNode());
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// Replace artificial node with it's children
|
|
229
|
-
for (const node of allArtificialNodes) {
|
|
230
|
-
const children = node.getChildren();
|
|
231
|
-
for (const child of children) {
|
|
232
|
-
node.insertBefore(child);
|
|
233
|
-
}
|
|
234
|
-
node.remove();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
function isDomNodeBetweenTwoInlineNodes(node) {
|
|
238
|
-
if (node.nextSibling == null || node.previousSibling == null) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
return lexical.isInlineDomNode(node.nextSibling) && lexical.isInlineDomNode(node.previousSibling);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
exports.$generateHtmlFromNodes = $generateHtmlFromNodes;
|
|
245
|
-
exports.$generateNodesFromDOM = $generateNodesFromDOM;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalHtml_dev = require('./LexicalHtml.dev.js');
|
|
4
|
-
var LexicalHtml_prod = require('./LexicalHtml.prod.js');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the MIT license found in the
|
|
10
|
-
* LICENSE file in the root directory of this source tree.
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const mod = process.env.NODE_ENV === 'development' ? LexicalHtml_dev : LexicalHtml_prod;
|
|
15
|
-
const $generateHtmlFromNodes = mod.$generateHtmlFromNodes;
|
|
16
|
-
const $generateNodesFromDOM = mod.$generateNodesFromDOM;
|
|
17
|
-
|
|
18
|
-
exports.$generateHtmlFromNodes = $generateHtmlFromNodes;
|
|
19
|
-
exports.$generateNodesFromDOM = $generateNodesFromDOM;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var LexicalSelection = require('../selection/LexicalSelection.js');
|
|
4
|
-
var LexicalUtils = require('../utils/LexicalUtils.js');
|
|
5
|
-
var lexical = require('lexical');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
9
|
-
*
|
|
10
|
-
* This source code is licensed under the MIT license found in the
|
|
11
|
-
* LICENSE file in the root directory of this source tree.
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
function p(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(!g.has(r.nodeName)){const n=x(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 h(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++){m(e,l[o],t,n);}return t.innerHTML}function m(t,o,s,c=null){let u=null===c||o.isSelected(c);const f=lexical.$isElementNode(o)&&o.excludeFromCopy("html");let a=o;if(null!==c){let n=lexical.$cloneWithProperties(o);n=lexical.$isTextNode(n)&&null!==c?LexicalSelection.$sliceSelectedTextNodeContent(c,n):n,a=n;}const d=lexical.$isElementNode(a)?a.getChildren():[],p=t._nodes.get(a.getType());let h;h=p&&void 0!==p.exportDOM?p.exportDOM(t,a):a.exportDOM(t);const{element:g,after:x}=h;if(!g)return !1;const y=document.createDocumentFragment();for(let e=0;e<d.length;e++){const n=d[e],r=m(t,n,y,c);!u&&lexical.$isElementNode(o)&&r&&o.extractWithChild(n,c,"html")&&(u=!0);}if(u&&!f){if(LexicalUtils.isHTMLElement(g)&&g.append(y),s.append(g),x){const e=x.call(a,g);e&&g.replaceWith(e);}}else s.append(y);return u}const g=new Set(["STYLE","SCRIPT"]);function x(e,n,o,r,i=new Map,p){let h=[];if(g.has(e.nodeName))return h;let m=null;const w=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=w?w(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,p),!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(...x(S[e],n,o,N,new Map(i),m));return null!=C&&(v=C(v)),LexicalUtils.isBlockDomNode(e)&&(v=y(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 y(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
|
-
|
|
17
|
-
exports.$generateHtmlFromNodes = h;
|
|
18
|
-
exports.$generateNodesFromDOM = p;
|