@lexical/code 0.3.11 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CodeHighlightNode.d.ts +2 -0
- package/CodeNode.d.ts +2 -0
- package/LexicalCode.dev.js +10 -2
- package/LexicalCode.prod.js +1 -1
- package/index.d.ts +2 -0
- package/package.json +3 -3
package/CodeHighlightNode.d.ts
CHANGED
|
@@ -29,7 +29,9 @@ export declare function normalizeCodeLang(lang: string): string;
|
|
|
29
29
|
export declare function getLanguageFriendlyName(lang: string): string;
|
|
30
30
|
export declare const getDefaultCodeLanguage: () => string;
|
|
31
31
|
export declare const getCodeLanguages: () => Array<string>;
|
|
32
|
+
/** @noInheritDoc */
|
|
32
33
|
export declare class CodeHighlightNode extends TextNode {
|
|
34
|
+
/** @internal */
|
|
33
35
|
__highlightType: string | null | undefined;
|
|
34
36
|
constructor(text: string, highlightType?: string | null | undefined, key?: NodeKey);
|
|
35
37
|
static getType(): string;
|
package/CodeNode.d.ts
CHANGED
|
@@ -24,7 +24,9 @@ declare type SerializedCodeNode = Spread<{
|
|
|
24
24
|
type: 'code';
|
|
25
25
|
version: 1;
|
|
26
26
|
}, SerializedElementNode>;
|
|
27
|
+
/** @noInheritDoc */
|
|
27
28
|
export declare class CodeNode extends ElementNode {
|
|
29
|
+
/** @internal */
|
|
28
30
|
__language: string | null | undefined;
|
|
29
31
|
static getType(): string;
|
|
30
32
|
static clone(node: CodeNode): CodeNode;
|
package/LexicalCode.dev.js
CHANGED
|
@@ -63,7 +63,10 @@ const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
|
63
63
|
const getCodeLanguages = () => Object.keys(Prism.languages).filter( // Prism has several language helpers mixed into languages object
|
|
64
64
|
// so filtering them out here to get langs list
|
|
65
65
|
language => typeof Prism.languages[language] !== 'function').sort();
|
|
66
|
+
/** @noInheritDoc */
|
|
67
|
+
|
|
66
68
|
class CodeHighlightNode extends lexical.TextNode {
|
|
69
|
+
/** @internal */
|
|
67
70
|
constructor(text, highlightType, key) {
|
|
68
71
|
super(text, key);
|
|
69
72
|
this.__highlightType = highlightType;
|
|
@@ -194,7 +197,10 @@ const mapToPrismLanguage = language => {
|
|
|
194
197
|
};
|
|
195
198
|
|
|
196
199
|
const LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
|
|
200
|
+
/** @noInheritDoc */
|
|
201
|
+
|
|
197
202
|
class CodeNode extends lexical.ElementNode {
|
|
203
|
+
/** @internal */
|
|
198
204
|
static getType() {
|
|
199
205
|
return 'code';
|
|
200
206
|
}
|
|
@@ -741,9 +747,11 @@ function getHighlightNodes(tokens) {
|
|
|
741
747
|
|
|
742
748
|
|
|
743
749
|
function updateAndRetainSelection(node, updateFn) {
|
|
744
|
-
const selection = lexical.$getSelection();
|
|
750
|
+
const selection = lexical.$getSelection(); // If it's not range selection (or null selection) there's no need to change it,
|
|
751
|
+
// but we can still run highlighting logic
|
|
745
752
|
|
|
746
|
-
if (!lexical.$isRangeSelection(selection)
|
|
753
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
754
|
+
updateFn();
|
|
747
755
|
return;
|
|
748
756
|
}
|
|
749
757
|
|
package/LexicalCode.prod.js
CHANGED
|
@@ -19,7 +19,7 @@ function O(a){let b=null,c=-1;var d=a.getPreviousSiblings();for(d.push(a);0<d.le
|
|
|
19
19
|
function P(a){let b=null,c=-1;var d=a.getNextSiblings();for(d.unshift(a);0<d.length;){var f=d.shift();if(C(f)){var g=f.getTextContent();g=N(g,!1);-1!==g&&(b=f,c=g+1)}if(r.$isLineBreakNode(f))break}if(null===b)for(a=a.getPreviousSiblings();0<a.length;){d=a.pop();if(C(d)&&(f=d.getTextContent(),f=N(f,!1),-1!==f)){b=d;c=f+1;break}if(r.$isLineBreakNode(d))break}return{node:b,offset:c}}function Q(a,b){let c=a.getParent();M(c)?R(c,b):C(a)&&a.replace(r.$createTextNode(a.__text))}let S=!1;
|
|
20
20
|
function R(a,b){S||(S=!0,void 0===a.getLanguage()&&a.setLanguage("javascript"),b.update(()=>{ca(a,()=>{var c=a.getTextContent();c=e.tokenize(c,e.languages[a.getLanguage()||""]||e.languages.javascript);c=T(c);var d=a.getChildren();let f=0;for(;f<d.length&&U(d[f],c[f]);)f++;var g=d.length;let l=c.length,h=Math.min(g,l)-f,k=0;for(;k<h;)if(k++,!U(d[g-k],c[l-k])){k--;break}d=f;g-=k;c=c.slice(f,l-k);let {from:n,to:p,nodesForReplacement:w}={from:d,nodesForReplacement:c,to:g};return n!==p||w.length?(a.splice(n,
|
|
21
21
|
p-n,w),!0):!1})},{onUpdate:()=>{S=!1},skipTransforms:!0}))}function T(a){let b=[];a.forEach(c=>{if("string"===typeof c){c=c.split("\n");for(var d=0;d<c.length;d++){let f=c[d];f.length&&b.push(A(f));d<c.length-1&&b.push(r.$createLineBreakNode())}}else({content:d}=c),"string"===typeof d?b.push(A(d,c.type)):Array.isArray(d)&&1===d.length&&"string"===typeof d[0]?b.push(A(d[0],c.type)):Array.isArray(d)&&b.push(...T(d))});return b}
|
|
22
|
-
function ca(a,b){var c=r.$getSelection();if(r.$isRangeSelection(c)
|
|
22
|
+
function ca(a,b){var c=r.$getSelection();if(r.$isRangeSelection(c)){c=c.anchor;var d=c.offset,f="element"===c.type&&r.$isLineBreakNode(a.getChildAtIndex(c.offset-1)),g=0;if(!f){let l=c.getNode();g=d+l.getPreviousSiblings().reduce((h,k)=>h+(r.$isLineBreakNode(k)?0:k.getTextContentSize()),0)}b()&&(f?c.getNode().select(d,d):a.getChildren().some(l=>{if(r.$isTextNode(l)){let h=l.getTextContentSize();if(h>=g)return l.select(g,g),!0;g-=h}return!1}))}else b()}
|
|
23
23
|
function U(a,b){return C(a)&&C(b)?a.__text===b.__text&&a.__highlightType===b.__highlightType:r.$isLineBreakNode(a)&&r.$isLineBreakNode(b)?!0:!1}function V(a){var b=r.$getSelection();if(!r.$isRangeSelection(b)||b.isCollapsed())return!1;b=b.getNodes();for(var c=0;c<b.length;c++){var d=b[c];if(!C(d)&&!r.$isLineBreakNode(d))return!1}c=D(b[0]);null!=c&&W(c,a);for(c=1;c<b.length;c++)d=b[c],r.$isLineBreakNode(b[c-1])&&C(d)&&W(d,a);return!0}
|
|
24
24
|
function W(a,b){let c=a.getTextContent();b===r.INDENT_CONTENT_COMMAND?0<c.length&&/\s/.test(c[0])?a.setTextContent("\t"+c):(b=A("\t"),a.insertBefore(b)):0===c.indexOf("\t")&&(1===c.length?a.remove():a.setTextContent(c.substring(1)))}
|
|
25
25
|
function Y(a,b){let c=r.$getSelection();if(!r.$isRangeSelection(c))return!1;let {anchor:d,focus:f}=c,g=d.offset,l=f.offset,h=d.getNode(),k=f.getNode();var n=a===r.KEY_ARROW_UP_COMMAND;if(!C(h)||!C(k))return!1;if(!b.altKey){if(c.isCollapsed())if(a=h.getParentOrThrow(),n&&0===g&&null===h.getPreviousSibling()){if(null===a.getPreviousSibling())return a.selectPrevious(),b.preventDefault(),!0}else if(!n&&g===h.getTextContentSize()&&null===h.getNextSibling()&&null===a.getNextSibling())return a.selectNext(),
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/** @module @lexical/code */
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*
|
|
8
|
+
*
|
|
7
9
|
*/
|
|
8
10
|
export { getEndOfCodeInLine, getStartOfCodeInLine, registerCodeHighlighting, } from './CodeHighlighter';
|
|
9
11
|
export { $createCodeHighlightNode, $isCodeHighlightNode, CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, CodeHighlightNode, DEFAULT_CODE_LANGUAGE, getCodeLanguages, getDefaultCodeLanguage, getFirstCodeHighlightNodeOfLine, getLanguageFriendlyName, getLastCodeHighlightNodeOfLine, normalizeCodeLang, } from './CodeHighlightNode';
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.4.0",
|
|
12
12
|
"main": "LexicalCode.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.4.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.4.0",
|
|
18
18
|
"prismjs": "^1.27.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|