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

@lexical/code

Package Overview
Dependencies
Maintainers
4
Versions
191
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.2.5 to 0.2.6

14

LexicalCode.d.ts

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

*
* @flow strict
*/

@@ -27,3 +26,3 @@

constructor(key?: NodeKey);
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
createDOM(config: EditorConfig): HTMLElement;
updateDOM(prevNode: CodeNode, dom: HTMLElement): boolean;

@@ -38,3 +37,3 @@ insertNewAfter(

}
declare function $createCodeNode(): CodeNode;
declare function $createCodeNode(language?: string): CodeNode;
declare function $isCodeNode(

@@ -60,8 +59,7 @@ node: null | undefined | LexicalNode,

static clone(node: CodeHighlightNode): CodeHighlightNode;
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
updateDOM<EditorContext>(
// $FlowFixMe
createDOM(config: EditorConfig): HTMLElement;
updateDOM(
prevNode: CodeHighlightNode,
dom: HTMLElement,
config: EditorConfig<EditorContext>,
config: EditorConfig,
): boolean;

@@ -79,5 +77,5 @@ setFormat(format: number): this;

declare function $isCodeHighlightNode(
node: ?LexicalNode,
node: LexicalNode | null | undefined,
): node is CodeHighlightNode;
declare function registerCodeHighlighting(editor: LexicalEditor): () => void;

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

var Prism = require('prismjs/components/prism-core');
var Prism = require('prismjs');
require('prismjs/components/prism-clike');

@@ -31,3 +31,2 @@ require('prismjs/components/prism-javascript');

*
*
*/

@@ -37,2 +36,3 @@ const DEFAULT_CODE_LANGUAGE = 'javascript';

const mapToPrismLanguage = language => {
// eslint-disable-next-line no-prototype-builtins
return language != null && Prism.languages.hasOwnProperty(language) ? language : undefined;

@@ -157,4 +157,3 @@ };

table: node => {
// $FlowFixMe[incompatible-type] domNode is a <table> since we matched it by nodeName
const table = node;
const table = node; // domNode is a <table> since we matched it by nodeName

@@ -171,5 +170,4 @@ if (isGitHubCodeTable(table)) {

td: node => {
// $FlowFixMe[incompatible-type] element is a <td> since we matched it by nodeName
const td = node; // $FlowFixMe[incompatible-type] we know this will be a table, or null.
// element is a <td> since we matched it by nodeName
const td = node;
const table = td.closest('table');

@@ -196,5 +194,4 @@

tr: node => {
// $FlowFixMe[incompatible-type] element is a <tr> since we matched it by nodeName
const tr = node; // $FlowFixMe[incompatible-type] we know this will be a table, or null.
// element is a <tr> since we matched it by nodeName
const tr = node;
const table = tr.closest('table');

@@ -338,3 +335,3 @@

function convertDivElement(domNode) {
// $FlowFixMe[incompatible-type] domNode is a <div> since we matched it by nodeName
// domNode is a <div> since we matched it by nodeName
const div = domNode;

@@ -368,3 +365,3 @@ return {

function convertTableCellElement(domNode) {
// $FlowFixMe[incompatible-type] domNode is a <td> since we matched it by nodeName
// domNode is a <td> since we matched it by nodeName
const cell = domNode;

@@ -418,3 +415,3 @@ return {

const children = node.getChildren();
const childrenLength = children.length; // $FlowFixMe: internal field
const childrenLength = children.length; // @ts-ignore: internal field

@@ -424,3 +421,3 @@ if (childrenLength === codeElement.__cachedChildrenLength) {

return;
} // $FlowFixMe: internal field
} // @ts-ignore:: internal field

@@ -515,5 +512,5 @@

nodes.push($createCodeHighlightNode(content, token.type));
} else if (content.length === 1 && typeof content[0] === 'string') {
} else if (Array.isArray(content) && content.length === 1 && typeof content[0] === 'string') {
nodes.push($createCodeHighlightNode(content[0], token.type));
} else {
} else if (Array.isArray(content)) {
nodes.push(...getHighlightNodes(content));

@@ -520,0 +517,0 @@ }

@@ -7,23 +7,23 @@ /**

*/
var d=require("prismjs/components/prism-core");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-python");require("prismjs/components/prism-rust");require("prismjs/components/prism-swift");
var n=require("@lexical/utils"),r=require("lexical");const t=a=>null!=a&&d.languages.hasOwnProperty(a)?a:void 0;
class u extends r.TextNode{constructor(a,c,b){super(a,b);this.__highlightType=c}static getType(){return"code-highlight"}static clone(a){return new u(a.__text,a.__highlightType||void 0,a.__key)}createDOM(a){const c=super.createDOM(a);a=v(a.theme,this.__highlightType);n.addClassNamesToElement(c,a);return c}updateDOM(a,c,b){const e=super.updateDOM(a,c,b);a=v(b.theme,a.__highlightType);b=v(b.theme,this.__highlightType);a!==b&&(a&&n.removeClassNamesFromElement(c,a),b&&n.addClassNamesToElement(c,b));return e}setFormat(){return this}}
var e=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-python");require("prismjs/components/prism-rust");require("prismjs/components/prism-swift");
var n=require("@lexical/utils"),r=require("lexical");const t=a=>null!=a&&e.languages.hasOwnProperty(a)?a:void 0;
class u extends r.TextNode{constructor(a,c,b){super(a,b);this.__highlightType=c}static getType(){return"code-highlight"}static clone(a){return new u(a.__text,a.__highlightType||void 0,a.__key)}createDOM(a){const c=super.createDOM(a);a=v(a.theme,this.__highlightType);n.addClassNamesToElement(c,a);return c}updateDOM(a,c,b){const d=super.updateDOM(a,c,b);a=v(b.theme,a.__highlightType);b=v(b.theme,this.__highlightType);a!==b&&(a&&n.removeClassNamesFromElement(c,a),b&&n.addClassNamesToElement(c,b));return d}setFormat(){return this}}
function v(a,c){return c&&a&&a.codeHighlight&&a.codeHighlight[c]}function y(a,c){return new u(a,c)}function z(a){return a instanceof u}
class B extends r.ElementNode{static getType(){return"code"}static clone(a){return new B(a.__language,a.__key)}constructor(a,c){super(c);this.__language=t(a)}createDOM(a){const c=document.createElement("code");n.addClassNamesToElement(c,a.theme.code);c.setAttribute("spellcheck","false");(a=this.getLanguage())&&c.setAttribute("data-highlight-language",a);return c}updateDOM(a,c){const b=this.__language;a=a.__language;b?b!==a&&c.setAttribute("data-highlight-language",b):a&&c.removeAttribute("data-highlight-language");
return!1}static importDOM(){return{div:()=>({conversion:C,priority:1}),pre:()=>({conversion:D,priority:0}),table:a=>E(a)?{conversion:F,priority:4}:null,td:a=>{const c=a.closest("table");return a.classList.contains("js-file-line")?{conversion:G,priority:4}:c&&E(c)?{conversion:H,priority:4}:null},tr:a=>(a=a.closest("table"))&&E(a)?{conversion:H,priority:4}:null}}insertNewAfter(a){var c=this.getChildren(),b=c.length;if(2<=b&&"\n"===c[b-1].getTextContent()&&"\n"===c[b-2].getTextContent()&&a.isCollapsed()&&
a.anchor.key===this.__key&&a.anchor.offset===b)return c[b-1].remove(),c[b-2].remove(),a=r.$createParagraphNode(),this.insertAfter(a),a;c=a.anchor.getNode();var e=I(c);if(null!=e){b=0;for(e=e.getTextContent();b<e.length&&/[\t ]/.test(e[b]);)b+=1;if(0<b)return b=e.substring(0,b),b=y(b),c.insertAfter(b),a.insertNodes([r.$createLineBreakNode()]),b.select(),b}return null}canInsertTab(){const a=r.$getSelection();return r.$isRangeSelection(a)&&a.isCollapsed()?!0:!1}canIndent(){return!1}collapseAtStart(){const a=
a.anchor.key===this.__key&&a.anchor.offset===b)return c[b-1].remove(),c[b-2].remove(),a=r.$createParagraphNode(),this.insertAfter(a),a;c=a.anchor.getNode();var d=I(c);if(null!=d){b=0;for(d=d.getTextContent();b<d.length&&/[\t ]/.test(d[b]);)b+=1;if(0<b)return b=d.substring(0,b),b=y(b),c.insertAfter(b),a.insertNodes([r.$createLineBreakNode()]),b.select(),b}return null}canInsertTab(){const a=r.$getSelection();return r.$isRangeSelection(a)&&a.isCollapsed()?!0:!1}canIndent(){return!1}collapseAtStart(){const a=
r.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=t(a)}getLanguage(){return this.getLatest().__language}}function J(a){return new B(a)}function K(a){return a instanceof B}function I(a){let c=null;const b=a.getPreviousSiblings();for(b.push(a);0<b.length&&(a=b.pop(),z(a)&&(c=a),!r.$isLineBreakNode(a)););return c}
function L(a){let c=null;const b=a.getNextSiblings();for(b.unshift(a);0<b.length&&(a=b.shift(),z(a)&&(c=a),!r.$isLineBreakNode(a)););return c}function D(){return{node:J()}}function C(a){return{after:c=>{const b=a.parentNode;null!=b&&a!==b.lastChild&&c.push(r.$createLineBreakNode());return c},node:null!==a.style.fontFamily.match("monospace")?J():null}}function F(){return{node:J()}}function H(){return{node:null}}
function G(a){return{after:c=>{a.parentNode&&a.parentNode.nextSibling&&c.push(r.$createLineBreakNode());return c},node:null}}function E(a){return a.classList.contains("js-file-line-container")}function M(a,c){const b=a.getParent();K(b)?N(b,c):z(a)&&a.replace(r.$createTextNode(a.__text))}let O=!1;
function N(a,c){O||(O=!0,void 0===a.getLanguage()&&a.setLanguage("javascript"),c.update(()=>{P(a,()=>{var b=a.getTextContent();b=d.tokenize(b,d.languages[a.getLanguage()||""]||d.languages.javascript);b=R(b);var e=a.getChildren();let f=0;for(;f<e.length&&S(e[f],b[f]);)f++;var h=e.length;const m=b.length,g=Math.min(h,m)-f;let k=0;for(;k<g;)if(k++,!S(e[h-k],b[m-k])){k--;break}e=f;h-=k;b=b.slice(f,m-k);const {from:l,to:p,nodesForReplacement:w}={from:e,nodesForReplacement:b,to:h};return l!==p||w.length?
(a.splice(l,p-l,w),!0):!1})},{onUpdate:()=>{O=!1},skipTransforms:!0}))}function R(a){const c=[];a.forEach(b=>{if("string"===typeof b){b=b.split("\n");for(var e=0;e<b.length;e++){const f=b[e];f.length&&c.push(y(f));e<b.length-1&&c.push(r.$createLineBreakNode())}}else({content:e}=b),"string"===typeof e?c.push(y(e,b.type)):1===e.length&&"string"===typeof e[0]?c.push(y(e[0],b.type)):c.push(...R(e))});return c}
function P(a,c){var b=r.$getSelection();if(r.$isRangeSelection(b)&&b.anchor){b=b.anchor;var e=b.offset,f="element"===b.type&&r.$isLineBreakNode(a.getChildAtIndex(b.offset-1)),h=0;if(!f){const m=b.getNode();h=e+m.getPreviousSiblings().reduce((g,k)=>g+(r.$isLineBreakNode(k)?0:k.getTextContentSize()),0)}c()&&(f?b.getNode().select(e,e):a.getChildren().some(m=>{if(r.$isTextNode(m)){const g=m.getTextContentSize();if(g>=h)return m.select(h,h),!0;h-=g}return!1}))}}
function S(a,c){return z(a)&&z(c)?a.__text===c.__text&&a.__highlightType===c.__highlightType:r.$isLineBreakNode(a)&&r.$isLineBreakNode(c)?!0:!1}function T(a){var c=r.$getSelection();if(!r.$isRangeSelection(c)||c.isCollapsed())return!1;c=c.getNodes();for(var b=0;b<c.length;b++){var e=c[b];if(!z(e)&&!r.$isLineBreakNode(e))return!1}b=I(c[0]);null!=b&&U(b,a);for(b=1;b<c.length;b++)e=c[b],r.$isLineBreakNode(c[b-1])&&z(e)&&U(e,a);return!0}
function N(a,c){O||(O=!0,void 0===a.getLanguage()&&a.setLanguage("javascript"),c.update(()=>{P(a,()=>{var b=a.getTextContent();b=e.tokenize(b,e.languages[a.getLanguage()||""]||e.languages.javascript);b=R(b);var d=a.getChildren();let f=0;for(;f<d.length&&S(d[f],b[f]);)f++;var h=d.length;const m=b.length,g=Math.min(h,m)-f;let k=0;for(;k<g;)if(k++,!S(d[h-k],b[m-k])){k--;break}d=f;h-=k;b=b.slice(f,m-k);const {from:l,to:p,nodesForReplacement:w}={from:d,nodesForReplacement:b,to:h};return l!==p||w.length?
(a.splice(l,p-l,w),!0):!1})},{onUpdate:()=>{O=!1},skipTransforms:!0}))}function R(a){const c=[];a.forEach(b=>{if("string"===typeof b){b=b.split("\n");for(var d=0;d<b.length;d++){const f=b[d];f.length&&c.push(y(f));d<b.length-1&&c.push(r.$createLineBreakNode())}}else({content:d}=b),"string"===typeof d?c.push(y(d,b.type)):Array.isArray(d)&&1===d.length&&"string"===typeof d[0]?c.push(y(d[0],b.type)):Array.isArray(d)&&c.push(...R(d))});return c}
function P(a,c){var b=r.$getSelection();if(r.$isRangeSelection(b)&&b.anchor){b=b.anchor;var d=b.offset,f="element"===b.type&&r.$isLineBreakNode(a.getChildAtIndex(b.offset-1)),h=0;if(!f){const m=b.getNode();h=d+m.getPreviousSiblings().reduce((g,k)=>g+(r.$isLineBreakNode(k)?0:k.getTextContentSize()),0)}c()&&(f?b.getNode().select(d,d):a.getChildren().some(m=>{if(r.$isTextNode(m)){const g=m.getTextContentSize();if(g>=h)return m.select(h,h),!0;h-=g}return!1}))}}
function S(a,c){return z(a)&&z(c)?a.__text===c.__text&&a.__highlightType===c.__highlightType:r.$isLineBreakNode(a)&&r.$isLineBreakNode(c)?!0:!1}function T(a){var c=r.$getSelection();if(!r.$isRangeSelection(c)||c.isCollapsed())return!1;c=c.getNodes();for(var b=0;b<c.length;b++){var d=c[b];if(!z(d)&&!r.$isLineBreakNode(d))return!1}b=I(c[0]);null!=b&&U(b,a);for(b=1;b<c.length;b++)d=c[b],r.$isLineBreakNode(c[b-1])&&z(d)&&U(d,a);return!0}
function U(a,c){const b=a.getTextContent();c===r.INDENT_CONTENT_COMMAND?0<b.length&&/\s/.test(b[0])?a.setTextContent("\t"+b):(c=y("\t"),a.insertBefore(c)):0===b.indexOf("\t")&&(1===b.length?a.remove():a.setTextContent(b.substring(1)))}
function V(a,c){const b=r.$getSelection();if(!r.$isRangeSelection(b))return!1;const {anchor:e,focus:f}=b,h=e.offset,m=f.offset,g=e.getNode(),k=f.getNode();var l=a===r.KEY_ARROW_UP_COMMAND;if(!z(g)||!z(k))return!1;if(!c.altKey){if(b.isCollapsed())if(a=g.getParentOrThrow(),l&&0===h&&null===g.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),c.preventDefault(),!0}else if(!l&&h===g.getTextContentSize()&&null===g.getNextSibling()&&null===a.getNextSibling())return a.selectNext(),
function V(a,c){const b=r.$getSelection();if(!r.$isRangeSelection(b))return!1;const {anchor:d,focus:f}=b,h=d.offset,m=f.offset,g=d.getNode(),k=f.getNode();var l=a===r.KEY_ARROW_UP_COMMAND;if(!z(g)||!z(k))return!1;if(!c.altKey){if(b.isCollapsed())if(a=g.getParentOrThrow(),l&&0===h&&null===g.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),c.preventDefault(),!0}else if(!l&&h===g.getTextContentSize()&&null===g.getNextSibling()&&null===a.getNextSibling())return a.selectNext(),
c.preventDefault(),!0;return!1}var p=I(g);const w=L(k);if(null==p||null==w)return!1;const A=p.getNodesBetween(w);for(let q=0;q<A.length;q++){const Q=A[q];if(!z(Q)&&!r.$isLineBreakNode(Q))return!1}c.preventDefault();c.stopPropagation();c=l?p.getPreviousSibling():w.getNextSibling();if(!r.$isLineBreakNode(c))return!0;p=l?c.getPreviousSibling():c.getNextSibling();if(null==p)return!0;l=l?I(p):L(p);let x=null!=l?l:p;c.remove();A.forEach(q=>q.remove());a===r.KEY_ARROW_UP_COMMAND?(A.forEach(q=>x.insertBefore(q)),
x.insertBefore(c)):(x.insertAfter(c),x=c,A.forEach(q=>{x.insertAfter(q);x=q}));b.setTextNodeRange(g,h,k,m);return!0}exports.$createCodeHighlightNode=y;exports.$createCodeNode=J;exports.$isCodeHighlightNode=z;exports.$isCodeNode=K;exports.CodeHighlightNode=u;exports.CodeNode=B;exports.getCodeLanguages=()=>Object.keys(d.languages).filter(a=>"function"!==typeof d.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getFirstCodeHighlightNodeOfLine=I;
x.insertBefore(c)):(x.insertAfter(c),x=c,A.forEach(q=>{x.insertAfter(q);x=q}));b.setTextNodeRange(g,h,k,m);return!0}exports.$createCodeHighlightNode=y;exports.$createCodeNode=J;exports.$isCodeHighlightNode=z;exports.$isCodeNode=K;exports.CodeHighlightNode=u;exports.CodeNode=B;exports.getCodeLanguages=()=>Object.keys(e.languages).filter(a=>"function"!==typeof e.languages[a]).sort();exports.getDefaultCodeLanguage=()=>"javascript";exports.getFirstCodeHighlightNodeOfLine=I;
exports.getLastCodeHighlightNodeOfLine=L;
exports.registerCodeHighlighting=function(a){if(!a.hasNodes([B,u]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return n.mergeRegister(a.registerMutationListener(B,c=>{a.update(()=>{for(const [f,h]of c)if("destroyed"!==h){var b=r.$getNodeByKey(f);if(null!==b)a:{var e=b;b=a.getElementByKey(e.getKey());if(null===b)break a;e=e.getChildren();const m=e.length;if(m===b.__cachedChildrenLength)break a;b.__cachedChildrenLength=m;let g="1",k=1;for(let l=0;l<m;l++)r.$isLineBreakNode(e[l])&&
exports.registerCodeHighlighting=function(a){if(!a.hasNodes([B,u]))throw Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return n.mergeRegister(a.registerMutationListener(B,c=>{a.update(()=>{for(const [f,h]of c)if("destroyed"!==h){var b=r.$getNodeByKey(f);if(null!==b)a:{var d=b;b=a.getElementByKey(d.getKey());if(null===b)break a;d=d.getChildren();const m=d.length;if(m===b.__cachedChildrenLength)break a;b.__cachedChildrenLength=m;let g="1",k=1;for(let l=0;l<m;l++)r.$isLineBreakNode(d[l])&&
(g+="\n"+ ++k);b.setAttribute("data-gutter",g)}}})}),a.registerNodeTransform(B,c=>N(c,a)),a.registerNodeTransform(r.TextNode,c=>M(c,a)),a.registerNodeTransform(u,c=>M(c,a)),a.registerCommand(r.INDENT_CONTENT_COMMAND,()=>T(r.INDENT_CONTENT_COMMAND),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.OUTDENT_CONTENT_COMMAND,()=>T(r.OUTDENT_CONTENT_COMMAND),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.KEY_ARROW_UP_COMMAND,c=>V(r.KEY_ARROW_UP_COMMAND,c),r.COMMAND_PRIORITY_LOW),a.registerCommand(r.KEY_ARROW_DOWN_COMMAND,
c=>V(r.KEY_ARROW_DOWN_COMMAND,c),r.COMMAND_PRIORITY_LOW))};

@@ -11,9 +11,9 @@ {

"license": "MIT",
"version": "0.2.5",
"version": "0.2.6",
"main": "LexicalCode.js",
"peerDependencies": {
"lexical": "0.2.5"
"lexical": "0.2.6"
},
"dependencies": {
"@lexical/utils": "0.2.5",
"@lexical/utils": "0.2.6",
"prismjs": "^1.27.0"

@@ -25,3 +25,6 @@ },

"directory": "packages/lexical-code"
},
"devDependencies": {
"@types/prismjs": "^1.26.0"
}
}

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