Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/code

Package Overview
Dependencies
Maintainers
5
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/code - npm Package Compare versions

Comparing version 0.17.2-nightly.20240920.0 to 0.17.2-nightly.20240923.0

1

CodeHighlighter.d.ts

@@ -9,3 +9,2 @@ /**

import type { LexicalEditor, LineBreakNode } from 'lexical';
import './CodeHighlighterPrism';
import { TabNode } from 'lexical';

@@ -12,0 +11,0 @@ import { CodeHighlightNode } from './CodeHighlightNode';

@@ -24,7 +24,2 @@ /**

import 'prismjs/components/prism-cpp';
declare global {
interface Window {
Prism: typeof import('prismjs');
}
}
export declare const Prism: typeof import('prismjs');

@@ -9,3 +9,2 @@ /**

import type { EditorConfig, LexicalNode, LineBreakNode, NodeKey, SerializedTextNode, Spread, TabNode } from 'lexical';
import './CodeHighlighterPrism';
import { ElementNode, TextNode } from 'lexical';

@@ -12,0 +11,0 @@ export declare const DEFAULT_CODE_LANGUAGE = "javascript";

40

LexicalCode.dev.js

@@ -11,2 +11,4 @@ /**

var utils = require('@lexical/utils');
var lexical = require('lexical');
require('prismjs');

@@ -28,4 +30,2 @@ require('prismjs/components/prism-clike');

require('prismjs/components/prism-cpp');
var utils = require('@lexical/utils');
var lexical = require('lexical');

@@ -40,3 +40,11 @@ /**

const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
// invariant(condition, message) will refine types based on "condition", and
// if "condition" is false will throw an error. This function is special-cased
// in flow itself, so we can't name it anything else.
function invariant(cond, message, ...args) {
if (cond) {
return;
}
throw new Error('Internal Lexical error: invariant() is meant to be replaced at compile ' + 'time. There is no runtime version. Error: ' + message);
}

@@ -51,3 +59,3 @@ /**

const Prism = CAN_USE_DOM ? window.Prism : global.Prism;
const Prism = globalThis.Prism || window.Prism;

@@ -62,20 +70,2 @@ /**

// invariant(condition, message) will refine types based on "condition", and
// if "condition" is false will throw an error. This function is special-cased
// in flow itself, so we can't name it anything else.
function invariant(cond, message, ...args) {
if (cond) {
return;
}
throw new Error('Internal Lexical error: invariant() is meant to be replaced at compile ' + 'time. There is no runtime version. Error: ' + message);
}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const isLanguageSupportedByPrism = language => {

@@ -435,6 +425,6 @@ try {

const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
const getCodeLanguages = () => Object.keys(window.Prism.languages).filter(
const getCodeLanguages = () => Object.keys(Prism.languages).filter(
// Prism has several language helpers mixed into languages object
// so filtering them out here to get langs list
language => typeof window.Prism.languages[language] !== 'function').sort();
language => typeof Prism.languages[language] !== 'function').sort();

@@ -549,3 +539,3 @@ /** @noInheritDoc */

tokenize(code, language) {
return window.Prism.tokenize(code, window.Prism.languages[language || ''] || window.Prism.languages[this.defaultLanguage]);
return Prism.tokenize(code, Prism.languages[language || ''] || Prism.languages[this.defaultLanguage]);
}

@@ -552,0 +542,0 @@ };

@@ -9,38 +9,38 @@ /**

'use strict';require("prismjs");require("prismjs/components/prism-clike");require("prismjs/components/prism-javascript");require("prismjs/components/prism-markup");require("prismjs/components/prism-markdown");require("prismjs/components/prism-c");require("prismjs/components/prism-css");require("prismjs/components/prism-objectivec");require("prismjs/components/prism-sql");require("prismjs/components/prism-powershell");require("prismjs/components/prism-python");require("prismjs/components/prism-rust");
require("prismjs/components/prism-swift");require("prismjs/components/prism-typescript");require("prismjs/components/prism-java");require("prismjs/components/prism-cpp");var d=require("@lexical/utils"),m=require("lexical");"use strict";var q;
function v(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}q=v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v["default"]:v;
let aa="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?window.Prism:global.Prism,x=a=>{try{return a?aa.languages.hasOwnProperty(a):!1}catch(b){return!1}};function y(a,b){for(let c of a.childNodes){if(d.isHTMLElement(c)&&c.tagName===b)return!0;y(c,b)}return!1}
class z extends m.ElementNode{static getType(){return"code"}static clone(a){return new z(a.__language,a.__key)}constructor(a,b){super(b);this.__language=a;this.__isSyntaxHighlightSupported=x(a)}createDOM(a){let b=document.createElement("code");d.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");if(a=this.getLanguage())b.setAttribute("data-language",a),this.getIsSyntaxHighlightSupported()&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language,
'use strict';var d=require("@lexical/utils"),m=require("lexical");require("prismjs");require("prismjs/components/prism-clike");require("prismjs/components/prism-javascript");require("prismjs/components/prism-markup");require("prismjs/components/prism-markdown");require("prismjs/components/prism-c");require("prismjs/components/prism-css");require("prismjs/components/prism-objectivec");require("prismjs/components/prism-sql");require("prismjs/components/prism-powershell");require("prismjs/components/prism-python");
require("prismjs/components/prism-rust");require("prismjs/components/prism-swift");require("prismjs/components/prism-typescript");require("prismjs/components/prism-java");require("prismjs/components/prism-cpp");"use strict";var q;
function v(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}q=v&&v.__esModule&&Object.prototype.hasOwnProperty.call(v,"default")?v["default"]:v;let x=globalThis.Prism||window.Prism,y=a=>{try{return a?x.languages.hasOwnProperty(a):!1}catch(b){return!1}};
function z(a,b){for(let c of a.childNodes){if(d.isHTMLElement(c)&&c.tagName===b)return!0;z(c,b)}return!1}
class A extends m.ElementNode{static getType(){return"code"}static clone(a){return new A(a.__language,a.__key)}constructor(a,b){super(b);this.__language=a;this.__isSyntaxHighlightSupported=y(a)}createDOM(a){let b=document.createElement("code");d.addClassNamesToElement(b,a.theme.code);b.setAttribute("spellcheck","false");if(a=this.getLanguage())b.setAttribute("data-language",a),this.getIsSyntaxHighlightSupported()&&b.setAttribute("data-highlight-language",a);return b}updateDOM(a,b){let c=this.__language,
e=a.__language;c?c!==e&&(b.setAttribute("data-language",c),this.__isSyntaxHighlightSupported&&b.setAttribute("data-highlight-language",c)):e&&(b.removeAttribute("data-language"),a.__isSyntaxHighlightSupported&&b.removeAttribute("data-highlight-language"));return!1}exportDOM(a){let b=document.createElement("pre");d.addClassNamesToElement(b,a._config.theme.code);b.setAttribute("spellcheck","false");if(a=this.getLanguage())b.setAttribute("data-language",a),this.getIsSyntaxHighlightSupported()&&b.setAttribute("data-highlight-language",
a);return{element:b}}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||y(a,"BR"))?{conversion:A,priority:1}:null,div:()=>({conversion:ba,priority:1}),pre:()=>({conversion:A,priority:0}),table:a=>B(a)?{conversion:ca,priority:3}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")||b&&B(b)?{conversion:C,priority:3}:null},tr:a=>(a=a.closest("table"))&&B(a)?{conversion:C,priority:3}:null}}static importJSON(a){let b=D(a.language);b.setFormat(a.format);
a);return{element:b}}static importDOM(){return{code:a=>null!=a.textContent&&(/\r?\n/.test(a.textContent)||z(a,"BR"))?{conversion:B,priority:1}:null,div:()=>({conversion:aa,priority:1}),pre:()=>({conversion:B,priority:0}),table:a=>C(a)?{conversion:ba,priority:3}:null,td:a=>{let b=a.closest("table");return a.classList.contains("js-file-line")||b&&C(b)?{conversion:D,priority:3}:null},tr:a=>(a=a.closest("table"))&&C(a)?{conversion:D,priority:3}:null}}static importJSON(a){let b=E(a.language);b.setFormat(a.format);
b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}insertNewAfter(a,b=!0){var c=this.getChildren(),e=c.length;if(2<=e&&"\n"===c[e-1].getTextContent()&&"\n"===c[e-2].getTextContent()&&a.isCollapsed()&&a.anchor.key===this.__key&&a.anchor.offset===e)return c[e-1].remove(),c[e-2].remove(),a=m.$createParagraphNode(),this.insertAfter(a,b),a;let {anchor:f,focus:g}=a;b=(f.isBefore(g)?f:g).getNode();if(m.$isTextNode(b)){e=
E(b);for(c=[];;)if(m.$isTabNode(e))c.push(m.$createTabNode()),e=e.getNextSibling();else if(F(e)){for(var h=0,k=e.getTextContent(),l=e.getTextContentSize();h<l&&" "===k[h];)h++;0!==h&&c.push(G(" ".repeat(h)));if(h!==l)break;e=e.getNextSibling()}else break;e=b.splitText(f.offset)[0];h=0===f.offset?0:1;h=e.getIndexWithinParent()+h;k=b.getParentOrThrow();l=[m.$createLineBreakNode(),...c];k.splice(h,0,l);(c=c[c.length-1])?c.select():0===f.offset?e.selectPrevious():e.getNextSibling().selectNext(0,0)}H(b)&&
({offset:a}=a.anchor,b.splice(a,0,[m.$createLineBreakNode()]),b.select(a+1,a+1));return null}canIndent(){return!1}collapseAtStart(){let a=m.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}setLanguage(a){let b=this.getWritable();b.__language=a;b.__isSyntaxHighlightSupported=x(a)}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}
function D(a){return m.$applyNodeReplacement(new z(a))}function H(a){return a instanceof z}function A(a){a=a.getAttribute("data-language");return{node:D(a)}}function ba(a){let b=null!==a.style.fontFamily.match("monospace");var c;if(c=!b){a:{for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace")){a=!0;break a}a=a.parentElement}a=!1}c=!a}return c?{node:null}:{node:b?D():null}}function ca(){return{node:D()}}function C(){return{node:null}}
function B(a){return a.classList.contains("js-file-line-container")}let I={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"},J={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function L(a){return J[a]||a}
class M extends m.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new M(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return!1}createDOM(a){let b=super.createDOM(a);a=N(a.theme,this.__highlightType);d.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let e=super.updateDOM(a,b,c);a=N(c.theme,a.__highlightType);c=N(c.theme,this.__highlightType);a!==
c&&(a&&d.removeClassNamesFromElement(b,a),c&&d.addClassNamesToElement(b,c));return e}static importJSON(a){let b=G(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(){return this}isParentRequired(){return!0}createParentElementNode(){return D()}}function N(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}
function G(a,b){return m.$applyNodeReplacement(new M(a,b))}function F(a){return a instanceof M}function E(a){let b=a;for(;F(a)||m.$isTabNode(a);)b=a,a=a.getPreviousSibling();return b}function O(a){let b=a;for(;F(a)||m.$isTabNode(a);)b=a,a=a.getNextSibling();return b}let P={defaultLanguage:"javascript",tokenize(a,b){return window.Prism.tokenize(a,window.Prism.languages[b||""]||window.Prism.languages[this.defaultLanguage])}};
function Q(a,b){let c=null;var e=null,f=a;let g=b,h=a.getTextContent();for(;;){if(0===g){f=f.getPreviousSibling();if(null===f)break;F(f)||m.$isTabNode(f)||m.$isLineBreakNode(f)||q(167);if(m.$isLineBreakNode(f)){c={node:f,offset:1};break}g=Math.max(0,f.getTextContentSize()-1);h=f.getTextContent()}else g--;let k=h[g];F(f)&&" "!==k&&(e={node:f,offset:g})}if(null!==e)return e;e=null;b<a.getTextContentSize()?F(a)&&(e=a.getTextContent()[b]):(f=a.getNextSibling(),F(f)&&(e=f.getTextContent()[0]));if(null!==
e&&" "!==e)return c;a:for(e=a,f=a.getTextContent(),a=a.getTextContentSize();;){if(!F(e)||b===a){e=e.getNextSibling();if(null===e||m.$isLineBreakNode(e)){a=null;break a}F(e)&&(b=0,f=e.getTextContent(),a=e.getTextContentSize())}if(F(e)){if(" "!==f[b]){a={node:e,offset:b};break a}b++}}return null!==a?a:c}function R(a){a=O(a);m.$isLineBreakNode(a)&&q(168);return a}function S(a,b,c){let e=a.getParent();H(e)?T(e,b,c):F(a)&&a.replace(m.$createTextNode(a.__text))}let U=new Set;
function T(a,b,c){let e=a.getKey();U.has(e)||(U.add(e),void 0===a.getLanguage()&&a.setLanguage(c.defaultLanguage),b.update(()=>{da(e,()=>{var f=m.$getNodeByKey(e);if(!H(f)||!f.isAttached())return!1;var g=f.getTextContent();g=c.tokenize(g,f.getLanguage()||c.defaultLanguage);g=V(g);var h=f.getChildren();for(f=0;f<h.length&&W(h[f],g[f]);)f++;var k=h.length;let l=g.length,r=Math.min(k,l)-f,n=0;for(;n<r;)if(n++,!W(h[k-n],g[l-n])){n--;break}h=f;k-=n;g=g.slice(f,l-n);let {from:p,to:w,nodesForReplacement:u}=
{from:h,nodesForReplacement:g,to:k};return p!==w||u.length?(a.splice(p,w-p,u),!0):!1})},{onUpdate:()=>{U.delete(e)},skipTransforms:!0}))}
function V(a,b){let c=[];for(let e of a)if("string"===typeof e){a=e.split(/(\n|\t)/);let f=a.length;for(let g=0;g<f;g++){let h=a[g];"\n"===h||"\r\n"===h?c.push(m.$createLineBreakNode()):"\t"===h?c.push(m.$createTabNode()):0<h.length&&c.push(G(h,b))}}else({content:a}=e),"string"===typeof a?c.push(...V([a],e.type)):Array.isArray(a)&&c.push(...V(a,e.type));return c}
function da(a,b){a=m.$getNodeByKey(a);if(H(a)&&a.isAttached()){var c=m.$getSelection();if(m.$isRangeSelection(c)){c=c.anchor;var e=c.offset,f="element"===c.type&&m.$isLineBreakNode(a.getChildAtIndex(c.offset-1)),g=0;if(!f){let h=c.getNode();g=e+h.getPreviousSiblings().reduce((k,l)=>k+l.getTextContentSize(),0)}b()&&(f?c.getNode().select(e,e):a.getChildren().some(h=>{let k=m.$isTextNode(h);if(k||m.$isLineBreakNode(h)){let l=h.getTextContentSize();if(k&&l>=g)return h.select(g,g),!0;g-=l}return!1}))}else b()}}
function W(a,b){return F(a)&&F(b)&&a.__text===b.__text&&a.__highlightType===b.__highlightType||m.$isTabNode(a)&&m.$isTabNode(b)||m.$isLineBreakNode(a)&&m.$isLineBreakNode(b)}function X(a){if(!m.$isRangeSelection(a))return!1;var b=a.anchor.getNode();a=a.focus.getNode();if(b.is(a)&&H(b))return!0;b=b.getParent();return H(b)&&b.is(a.getParent())}
function Y(a){a=a.getNodes();let b=[[]];if(1===a.length&&H(a[0]))return b;let c=b[0];for(let e=0;e<a.length;e++){let f=a[e];F(f)||m.$isTabNode(f)||m.$isLineBreakNode(f)||q(169);m.$isLineBreakNode(f)?0!==e&&0<c.length&&(c=[],b.push(c)):c.push(f)}return b}
function ea(a){var b=m.$getSelection();if(!m.$isRangeSelection(b)||!X(b))return null;let c=a?m.OUTDENT_CONTENT_COMMAND:m.INDENT_CONTENT_COMMAND;a=a?m.OUTDENT_CONTENT_COMMAND:m.INSERT_TAB_COMMAND;if(1<Y(b).length)return c;var e=b.getNodes()[0];H(e)||F(e)||m.$isTabNode(e)||m.$isLineBreakNode(e)||q(170);if(H(e))return c;let f=E(e);e=O(e);var g=b.anchor;let h=b.focus;h.isBefore(g)?b=h:(b=g,g=h);return null!==f&&null!==e&&b.key===f.getKey()&&0===b.offset&&g.key===e.getKey()&&g.offset===e.getTextContentSize()?
F(b);for(c=[];;)if(m.$isTabNode(e))c.push(m.$createTabNode()),e=e.getNextSibling();else if(G(e)){for(var h=0,k=e.getTextContent(),l=e.getTextContentSize();h<l&&" "===k[h];)h++;0!==h&&c.push(H(" ".repeat(h)));if(h!==l)break;e=e.getNextSibling()}else break;e=b.splitText(f.offset)[0];h=0===f.offset?0:1;h=e.getIndexWithinParent()+h;k=b.getParentOrThrow();l=[m.$createLineBreakNode(),...c];k.splice(h,0,l);(c=c[c.length-1])?c.select():0===f.offset?e.selectPrevious():e.getNextSibling().selectNext(0,0)}I(b)&&
({offset:a}=a.anchor,b.splice(a,0,[m.$createLineBreakNode()]),b.select(a+1,a+1));return null}canIndent(){return!1}collapseAtStart(){let a=m.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}setLanguage(a){let b=this.getWritable();b.__language=a;b.__isSyntaxHighlightSupported=y(a)}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}
function E(a){return m.$applyNodeReplacement(new A(a))}function I(a){return a instanceof A}function B(a){a=a.getAttribute("data-language");return{node:E(a)}}function aa(a){let b=null!==a.style.fontFamily.match("monospace");var c;if(c=!b){a:{for(a=a.parentElement;null!==a;){if(null!==a.style.fontFamily.match("monospace")){a=!0;break a}a=a.parentElement}a=!1}c=!a}return c?{node:null}:{node:b?E():null}}function ba(){return{node:E()}}function D(){return{node:null}}
function C(a){return a.classList.contains("js-file-line-container")}let J={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"},K={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function M(a){return K[a]||a}
class N extends m.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new N(a.__text,a.__highlightType||void 0,a.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return!1}createDOM(a){let b=super.createDOM(a);a=O(a.theme,this.__highlightType);d.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){let e=super.updateDOM(a,b,c);a=O(c.theme,a.__highlightType);c=O(c.theme,this.__highlightType);a!==
c&&(a&&d.removeClassNamesFromElement(b,a),c&&d.addClassNamesToElement(b,c));return e}static importJSON(a){let b=H(a.text,a.highlightType);b.setFormat(a.format);b.setDetail(a.detail);b.setMode(a.mode);b.setStyle(a.style);return b}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(){return this}isParentRequired(){return!0}createParentElementNode(){return E()}}function O(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}
function H(a,b){return m.$applyNodeReplacement(new N(a,b))}function G(a){return a instanceof N}function F(a){let b=a;for(;G(a)||m.$isTabNode(a);)b=a,a=a.getPreviousSibling();return b}function P(a){let b=a;for(;G(a)||m.$isTabNode(a);)b=a,a=a.getNextSibling();return b}let Q={defaultLanguage:"javascript",tokenize(a,b){return x.tokenize(a,x.languages[b||""]||x.languages[this.defaultLanguage])}};
function R(a,b){let c=null;var e=null,f=a;let g=b,h=a.getTextContent();for(;;){if(0===g){f=f.getPreviousSibling();if(null===f)break;G(f)||m.$isTabNode(f)||m.$isLineBreakNode(f)||q(167);if(m.$isLineBreakNode(f)){c={node:f,offset:1};break}g=Math.max(0,f.getTextContentSize()-1);h=f.getTextContent()}else g--;let k=h[g];G(f)&&" "!==k&&(e={node:f,offset:g})}if(null!==e)return e;e=null;b<a.getTextContentSize()?G(a)&&(e=a.getTextContent()[b]):(f=a.getNextSibling(),G(f)&&(e=f.getTextContent()[0]));if(null!==
e&&" "!==e)return c;a:for(e=a,f=a.getTextContent(),a=a.getTextContentSize();;){if(!G(e)||b===a){e=e.getNextSibling();if(null===e||m.$isLineBreakNode(e)){a=null;break a}G(e)&&(b=0,f=e.getTextContent(),a=e.getTextContentSize())}if(G(e)){if(" "!==f[b]){a={node:e,offset:b};break a}b++}}return null!==a?a:c}function S(a){a=P(a);m.$isLineBreakNode(a)&&q(168);return a}function T(a,b,c){let e=a.getParent();I(e)?U(e,b,c):G(a)&&a.replace(m.$createTextNode(a.__text))}let V=new Set;
function U(a,b,c){let e=a.getKey();V.has(e)||(V.add(e),void 0===a.getLanguage()&&a.setLanguage(c.defaultLanguage),b.update(()=>{ca(e,()=>{var f=m.$getNodeByKey(e);if(!I(f)||!f.isAttached())return!1;var g=f.getTextContent();g=c.tokenize(g,f.getLanguage()||c.defaultLanguage);g=W(g);var h=f.getChildren();for(f=0;f<h.length&&X(h[f],g[f]);)f++;var k=h.length;let l=g.length,r=Math.min(k,l)-f,n=0;for(;n<r;)if(n++,!X(h[k-n],g[l-n])){n--;break}h=f;k-=n;g=g.slice(f,l-n);let {from:p,to:w,nodesForReplacement:u}=
{from:h,nodesForReplacement:g,to:k};return p!==w||u.length?(a.splice(p,w-p,u),!0):!1})},{onUpdate:()=>{V.delete(e)},skipTransforms:!0}))}
function W(a,b){let c=[];for(let e of a)if("string"===typeof e){a=e.split(/(\n|\t)/);let f=a.length;for(let g=0;g<f;g++){let h=a[g];"\n"===h||"\r\n"===h?c.push(m.$createLineBreakNode()):"\t"===h?c.push(m.$createTabNode()):0<h.length&&c.push(H(h,b))}}else({content:a}=e),"string"===typeof a?c.push(...W([a],e.type)):Array.isArray(a)&&c.push(...W(a,e.type));return c}
function ca(a,b){a=m.$getNodeByKey(a);if(I(a)&&a.isAttached()){var c=m.$getSelection();if(m.$isRangeSelection(c)){c=c.anchor;var e=c.offset,f="element"===c.type&&m.$isLineBreakNode(a.getChildAtIndex(c.offset-1)),g=0;if(!f){let h=c.getNode();g=e+h.getPreviousSiblings().reduce((k,l)=>k+l.getTextContentSize(),0)}b()&&(f?c.getNode().select(e,e):a.getChildren().some(h=>{let k=m.$isTextNode(h);if(k||m.$isLineBreakNode(h)){let l=h.getTextContentSize();if(k&&l>=g)return h.select(g,g),!0;g-=l}return!1}))}else b()}}
function X(a,b){return G(a)&&G(b)&&a.__text===b.__text&&a.__highlightType===b.__highlightType||m.$isTabNode(a)&&m.$isTabNode(b)||m.$isLineBreakNode(a)&&m.$isLineBreakNode(b)}function Y(a){if(!m.$isRangeSelection(a))return!1;var b=a.anchor.getNode();a=a.focus.getNode();if(b.is(a)&&I(b))return!0;b=b.getParent();return I(b)&&b.is(a.getParent())}
function Z(a){a=a.getNodes();let b=[[]];if(1===a.length&&I(a[0]))return b;let c=b[0];for(let e=0;e<a.length;e++){let f=a[e];G(f)||m.$isTabNode(f)||m.$isLineBreakNode(f)||q(169);m.$isLineBreakNode(f)?0!==e&&0<c.length&&(c=[],b.push(c)):c.push(f)}return b}
function da(a){var b=m.$getSelection();if(!m.$isRangeSelection(b)||!Y(b))return null;let c=a?m.OUTDENT_CONTENT_COMMAND:m.INDENT_CONTENT_COMMAND;a=a?m.OUTDENT_CONTENT_COMMAND:m.INSERT_TAB_COMMAND;if(1<Z(b).length)return c;var e=b.getNodes()[0];I(e)||G(e)||m.$isTabNode(e)||m.$isLineBreakNode(e)||q(170);if(I(e))return c;let f=F(e);e=P(e);var g=b.anchor;let h=b.focus;h.isBefore(g)?b=h:(b=g,g=h);return null!==f&&null!==e&&b.key===f.getKey()&&0===b.offset&&g.key===e.getKey()&&g.offset===e.getTextContentSize()?
c:a}
function Z(a){var b=m.$getSelection();if(!m.$isRangeSelection(b)||!X(b))return!1;var c=Y(b);let e=c.length;if(1<c.length){for(b=0;b<e;b++){var f=c[b];0<f.length&&(f=f[0],0===b&&(f=E(f)),null!==f&&(a===m.INDENT_CONTENT_COMMAND?f.insertBefore(m.$createTabNode()):m.$isTabNode(f)&&f.remove()))}return!0}c=b.getNodes()[0];H(c)||F(c)||m.$isTabNode(c)||m.$isLineBreakNode(c)||q(171);if(H(c))return a===m.INDENT_CONTENT_COMMAND&&b.insertNodes([m.$createTabNode()]),!0;c=E(c);null===c&&q(172);a===m.INDENT_CONTENT_COMMAND?m.$isLineBreakNode(c)?
function ea(a){var b=m.$getSelection();if(!m.$isRangeSelection(b)||!Y(b))return!1;var c=Z(b);let e=c.length;if(1<c.length){for(b=0;b<e;b++){var f=c[b];0<f.length&&(f=f[0],0===b&&(f=F(f)),null!==f&&(a===m.INDENT_CONTENT_COMMAND?f.insertBefore(m.$createTabNode()):m.$isTabNode(f)&&f.remove()))}return!0}c=b.getNodes()[0];I(c)||G(c)||m.$isTabNode(c)||m.$isLineBreakNode(c)||q(171);if(I(c))return a===m.INDENT_CONTENT_COMMAND&&b.insertNodes([m.$createTabNode()]),!0;c=F(c);null===c&&q(172);a===m.INDENT_CONTENT_COMMAND?m.$isLineBreakNode(c)?
c.insertAfter(m.$createTabNode()):c.insertBefore(m.$createTabNode()):m.$isTabNode(c)&&c.remove();return!0}
function fa(a,b){let c=m.$getSelection();if(!m.$isRangeSelection(c))return!1;let {anchor:e,focus:f}=c,g=e.offset,h=f.offset,k=e.getNode(),l=f.getNode();var r=a===m.KEY_ARROW_UP_COMMAND;if(!X(c)||!F(k)&&!m.$isTabNode(k)||!F(l)&&!m.$isTabNode(l))return!1;if(!b.altKey){if(c.isCollapsed())if(a=k.getParentOrThrow(),r&&0===g&&null===k.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),b.preventDefault(),!0}else if(!r&&g===k.getTextContentSize()&&null===k.getNextSibling()&&
null===a.getNextSibling())return a.selectNext(),b.preventDefault(),!0;return!1}let n;if(k.isBefore(l)){var p=E(k);n=O(l)}else p=E(l),n=O(k);if(null==p||null==n)return!1;let w=p.getNodesBetween(n);for(let t=0;t<w.length;t++){let K=w[t];if(!F(K)&&!m.$isTabNode(K)&&!m.$isLineBreakNode(K))return!1}b.preventDefault();b.stopPropagation();b=r?p.getPreviousSibling():n.getNextSibling();if(!m.$isLineBreakNode(b))return!0;p=r?b.getPreviousSibling():b.getNextSibling();if(null==p)return!0;r=F(p)||m.$isTabNode(p)||
m.$isLineBreakNode(p)?r?E(p):O(p):null;let u=null!=r?r:p;b.remove();w.forEach(t=>t.remove());a===m.KEY_ARROW_UP_COMMAND?(w.forEach(t=>u.insertBefore(t)),u.insertBefore(b)):(u.insertAfter(b),u=b,w.forEach(t=>{u.insertAfter(t);u=t}));c.setTextNodeRange(k,g,l,h);return!0}
function ha(a,b){let c=m.$getSelection();if(!m.$isRangeSelection(c))return!1;let {anchor:e,focus:f}=c;var g=e.getNode();let h=f.getNode();a=a===m.MOVE_TO_START;if(!X(c)||!F(g)&&!m.$isTabNode(g)||!F(h)&&!m.$isTabNode(h))return!1;if(a)if(g=Q(h,f.offset),null!==g){let {node:k,offset:l}=g;m.$isLineBreakNode(k)?k.selectNext(0,0):c.setTextNodeRange(k,l,k,l)}else h.getParentOrThrow().selectStart();else R(h).select();b.preventDefault();b.stopPropagation();return!0}exports.$createCodeHighlightNode=G;
exports.$createCodeNode=D;exports.$isCodeHighlightNode=F;exports.$isCodeNode=H;exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=I;exports.CODE_LANGUAGE_MAP=J;exports.CodeHighlightNode=M;exports.CodeNode=z;exports.DEFAULT_CODE_LANGUAGE="javascript";exports.PrismTokenizer=P;exports.getCodeLanguages=()=>Object.keys(window.Prism.languages).filter(a=>"function"!==typeof window.Prism.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getEndOfCodeInLine=R;
exports.getFirstCodeNodeOfLine=E;exports.getLanguageFriendlyName=function(a){a=L(a);return I[a]||a};exports.getLastCodeNodeOfLine=O;exports.getStartOfCodeInLine=Q;exports.normalizeCodeLang=L;
exports.registerCodeHighlighting=function(a,b){if(!a.hasNodes([z,M]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==b&&(b=P);return d.mergeRegister(a.registerMutationListener(z,c=>{a.update(()=>{for(let [g,h]of c)if("destroyed"!==h){var e=m.$getNodeByKey(g);if(null!==e)a:{var f=e;e=a.getElementByKey(f.getKey());if(null===e)break a;f=f.getChildren();let k=f.length;if(k===e.__cachedChildrenLength)break a;e.__cachedChildrenLength=k;let l="1",r=1;for(let n=
0;n<k;n++)m.$isLineBreakNode(f[n])&&(l+="\n"+ ++r);e.setAttribute("data-gutter",l)}}})},{skipInitialization:!1}),a.registerNodeTransform(z,c=>T(c,a,b)),a.registerNodeTransform(m.TextNode,c=>S(c,a,b)),a.registerNodeTransform(M,c=>S(c,a,b)),a.registerCommand(m.KEY_TAB_COMMAND,c=>{let e=ea(c.shiftKey);if(null===e)return!1;c.preventDefault();a.dispatchCommand(e,void 0);return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.INSERT_TAB_COMMAND,()=>{let c=m.$getSelection();if(!X(c))return!1;m.$insertNodes([m.$createTabNode()]);
return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.INDENT_CONTENT_COMMAND,()=>Z(m.INDENT_CONTENT_COMMAND),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.OUTDENT_CONTENT_COMMAND,()=>Z(m.OUTDENT_CONTENT_COMMAND),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ARROW_UP_COMMAND,c=>fa(m.KEY_ARROW_UP_COMMAND,c),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ARROW_DOWN_COMMAND,c=>fa(m.KEY_ARROW_DOWN_COMMAND,c),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.MOVE_TO_END,c=>ha(m.MOVE_TO_END,c),m.COMMAND_PRIORITY_LOW),
function fa(a,b){let c=m.$getSelection();if(!m.$isRangeSelection(c))return!1;let {anchor:e,focus:f}=c,g=e.offset,h=f.offset,k=e.getNode(),l=f.getNode();var r=a===m.KEY_ARROW_UP_COMMAND;if(!Y(c)||!G(k)&&!m.$isTabNode(k)||!G(l)&&!m.$isTabNode(l))return!1;if(!b.altKey){if(c.isCollapsed())if(a=k.getParentOrThrow(),r&&0===g&&null===k.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),b.preventDefault(),!0}else if(!r&&g===k.getTextContentSize()&&null===k.getNextSibling()&&
null===a.getNextSibling())return a.selectNext(),b.preventDefault(),!0;return!1}let n;if(k.isBefore(l)){var p=F(k);n=P(l)}else p=F(l),n=P(k);if(null==p||null==n)return!1;let w=p.getNodesBetween(n);for(let t=0;t<w.length;t++){let L=w[t];if(!G(L)&&!m.$isTabNode(L)&&!m.$isLineBreakNode(L))return!1}b.preventDefault();b.stopPropagation();b=r?p.getPreviousSibling():n.getNextSibling();if(!m.$isLineBreakNode(b))return!0;p=r?b.getPreviousSibling():b.getNextSibling();if(null==p)return!0;r=G(p)||m.$isTabNode(p)||
m.$isLineBreakNode(p)?r?F(p):P(p):null;let u=null!=r?r:p;b.remove();w.forEach(t=>t.remove());a===m.KEY_ARROW_UP_COMMAND?(w.forEach(t=>u.insertBefore(t)),u.insertBefore(b)):(u.insertAfter(b),u=b,w.forEach(t=>{u.insertAfter(t);u=t}));c.setTextNodeRange(k,g,l,h);return!0}
function ha(a,b){let c=m.$getSelection();if(!m.$isRangeSelection(c))return!1;let {anchor:e,focus:f}=c;var g=e.getNode();let h=f.getNode();a=a===m.MOVE_TO_START;if(!Y(c)||!G(g)&&!m.$isTabNode(g)||!G(h)&&!m.$isTabNode(h))return!1;if(a)if(g=R(h,f.offset),null!==g){let {node:k,offset:l}=g;m.$isLineBreakNode(k)?k.selectNext(0,0):c.setTextNodeRange(k,l,k,l)}else h.getParentOrThrow().selectStart();else S(h).select();b.preventDefault();b.stopPropagation();return!0}exports.$createCodeHighlightNode=H;
exports.$createCodeNode=E;exports.$isCodeHighlightNode=G;exports.$isCodeNode=I;exports.CODE_LANGUAGE_FRIENDLY_NAME_MAP=J;exports.CODE_LANGUAGE_MAP=K;exports.CodeHighlightNode=N;exports.CodeNode=A;exports.DEFAULT_CODE_LANGUAGE="javascript";exports.PrismTokenizer=Q;exports.getCodeLanguages=()=>Object.keys(x.languages).filter(a=>"function"!==typeof x.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getEndOfCodeInLine=S;exports.getFirstCodeNodeOfLine=F;
exports.getLanguageFriendlyName=function(a){a=M(a);return J[a]||a};exports.getLastCodeNodeOfLine=P;exports.getStartOfCodeInLine=R;exports.normalizeCodeLang=M;
exports.registerCodeHighlighting=function(a,b){if(!a.hasNodes([A,N]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");null==b&&(b=Q);return d.mergeRegister(a.registerMutationListener(A,c=>{a.update(()=>{for(let [g,h]of c)if("destroyed"!==h){var e=m.$getNodeByKey(g);if(null!==e)a:{var f=e;e=a.getElementByKey(f.getKey());if(null===e)break a;f=f.getChildren();let k=f.length;if(k===e.__cachedChildrenLength)break a;e.__cachedChildrenLength=k;let l="1",r=1;for(let n=
0;n<k;n++)m.$isLineBreakNode(f[n])&&(l+="\n"+ ++r);e.setAttribute("data-gutter",l)}}})},{skipInitialization:!1}),a.registerNodeTransform(A,c=>U(c,a,b)),a.registerNodeTransform(m.TextNode,c=>T(c,a,b)),a.registerNodeTransform(N,c=>T(c,a,b)),a.registerCommand(m.KEY_TAB_COMMAND,c=>{let e=da(c.shiftKey);if(null===e)return!1;c.preventDefault();a.dispatchCommand(e,void 0);return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.INSERT_TAB_COMMAND,()=>{let c=m.$getSelection();if(!Y(c))return!1;m.$insertNodes([m.$createTabNode()]);
return!0},m.COMMAND_PRIORITY_LOW),a.registerCommand(m.INDENT_CONTENT_COMMAND,()=>ea(m.INDENT_CONTENT_COMMAND),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.OUTDENT_CONTENT_COMMAND,()=>ea(m.OUTDENT_CONTENT_COMMAND),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ARROW_UP_COMMAND,c=>fa(m.KEY_ARROW_UP_COMMAND,c),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.KEY_ARROW_DOWN_COMMAND,c=>fa(m.KEY_ARROW_DOWN_COMMAND,c),m.COMMAND_PRIORITY_LOW),a.registerCommand(m.MOVE_TO_END,c=>ha(m.MOVE_TO_END,c),m.COMMAND_PRIORITY_LOW),
a.registerCommand(m.MOVE_TO_START,c=>ha(m.MOVE_TO_START,c),m.COMMAND_PRIORITY_LOW))}

@@ -11,8 +11,8 @@ {

"license": "MIT",
"version": "0.17.2-nightly.20240920.0",
"version": "0.17.2-nightly.20240923.0",
"main": "LexicalCode.js",
"types": "index.d.ts",
"dependencies": {
"@lexical/utils": "0.17.2-nightly.20240920.0",
"lexical": "0.17.2-nightly.20240920.0",
"@lexical/utils": "0.17.2-nightly.20240923.0",
"lexical": "0.17.2-nightly.20240923.0",
"prismjs": "^1.27.0"

@@ -29,3 +29,3 @@ },

"module": "LexicalCode.mjs",
"sideEffects": false,
"sideEffects": true,
"exports": {

@@ -32,0 +32,0 @@ ".": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc