lexical 0.1.13 → 0.1.16
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/Lexical.d.ts +13 -13
- package/Lexical.dev.js +177 -57
- package/Lexical.js.flow +14 -24
- package/Lexical.prod.js +152 -148
- package/LexicalCodeHighlightNode.dev.js +4 -24
- package/LexicalCodeHighlightNode.prod.js +3 -3
- package/LexicalCodeNode.dev.js +2 -17
- package/LexicalCodeNode.prod.js +6 -6
- package/LexicalExtendedNodes.dev.js +2 -2
- package/LexicalExtendedNodes.prod.js +2 -2
- package/LexicalHeadingNode.dev.js +2 -17
- package/LexicalHeadingNode.prod.js +4 -3
- package/LexicalLinkNode.dev.js +2 -17
- package/LexicalLinkNode.prod.js +3 -3
- package/LexicalQuoteNode.dev.js +2 -17
- package/LexicalQuoteNode.prod.js +3 -3
- package/README.md +1 -1
- package/package.json +1 -1
- package/HashtagNode.js +0 -9
- package/HashtagNode.js.flow +0 -27
- package/LexicalHashtagNode.dev.js +0 -111
- package/LexicalHashtagNode.prod.js +0 -9
|
@@ -6,29 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var utils = require('@lexical/utils');
|
|
9
10
|
var lexical = require('lexical');
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the MIT license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
20
|
-
classNames.forEach(className => {
|
|
21
|
-
if (className != null && typeof className === 'string') {
|
|
22
|
-
element.classList.add(...className.split(' '));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
function removeClassNamesFromElement(element, ...classNames) {
|
|
27
|
-
classNames.forEach(className => {
|
|
28
|
-
element.classList.remove(...className.split(' '));
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
12
|
/**
|
|
33
13
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
34
14
|
*
|
|
@@ -54,7 +34,7 @@ class CodeHighlightNode extends lexical.TextNode {
|
|
|
54
34
|
createDOM(config) {
|
|
55
35
|
const element = super.createDOM(config);
|
|
56
36
|
const className = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
57
|
-
addClassNamesToElement(element, className);
|
|
37
|
+
utils.addClassNamesToElement(element, className);
|
|
58
38
|
return element;
|
|
59
39
|
}
|
|
60
40
|
|
|
@@ -66,11 +46,11 @@ class CodeHighlightNode extends lexical.TextNode {
|
|
|
66
46
|
|
|
67
47
|
if (prevClassName !== nextClassName) {
|
|
68
48
|
if (prevClassName) {
|
|
69
|
-
removeClassNamesFromElement(dom, prevClassName);
|
|
49
|
+
utils.removeClassNamesFromElement(dom, prevClassName);
|
|
70
50
|
}
|
|
71
51
|
|
|
72
52
|
if (nextClassName) {
|
|
73
|
-
addClassNamesToElement(dom, nextClassName);
|
|
53
|
+
utils.addClassNamesToElement(dom, nextClassName);
|
|
74
54
|
}
|
|
75
55
|
}
|
|
76
56
|
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var d=require("lexical")
|
|
8
|
-
class
|
|
9
|
-
function
|
|
7
|
+
var d=require("@lexical/utils"),e=require("lexical");
|
|
8
|
+
class f extends e.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new f(a.__text,a.__highlightType||void 0,a.__key)}createDOM(a){const b=super.createDOM(a);a=g(a.theme,this.__highlightType);d.addClassNamesToElement(b,a);return b}updateDOM(a,b,c){const h=super.updateDOM(a,b,c);a=g(c.theme,a.__highlightType);c=g(c.theme,this.__highlightType);a!==c&&(a&&d.removeClassNamesFromElement(b,a),c&&d.addClassNamesToElement(b,c));return h}setFormat(){return this.getWritable()}}
|
|
9
|
+
function g(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}exports.$createCodeHighlightNode=function(a,b){return new f(a,b)};exports.$isCodeHighlightNode=function(a){return a instanceof f};exports.CodeHighlightNode=f;
|
package/LexicalCodeNode.dev.js
CHANGED
|
@@ -6,25 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var utils = require('@lexical/utils');
|
|
9
10
|
var lexical = require('lexical');
|
|
10
11
|
var CodeHighlightNode = require('lexical/CodeHighlightNode');
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
21
|
-
classNames.forEach(className => {
|
|
22
|
-
if (className != null && typeof className === 'string') {
|
|
23
|
-
element.classList.add(...className.split(' '));
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
13
|
/**
|
|
29
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
30
15
|
*
|
|
@@ -50,7 +35,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
50
35
|
|
|
51
36
|
createDOM(config) {
|
|
52
37
|
const element = document.createElement('code');
|
|
53
|
-
addClassNamesToElement(element, config.theme.code);
|
|
38
|
+
utils.addClassNamesToElement(element, config.theme.code);
|
|
54
39
|
element.setAttribute('spellcheck', 'false');
|
|
55
40
|
return element;
|
|
56
41
|
}
|
package/LexicalCodeNode.prod.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var d=require("lexical"),f=require("lexical
|
|
8
|
-
class h extends
|
|
9
|
-
{conversion:n,priority:1}: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=
|
|
10
|
-
a.insertNodes([
|
|
11
|
-
function l(){return{node:q()}}function k(a){return{after:c=>{const b=a.parentNode;null!=b&&a!==b.lastChild&&c.push(
|
|
12
|
-
exports.getFirstCodeHighlightNodeOfLine=p;exports.getLastCodeHighlightNodeOfLine=function(a){let c=null;const b=a.getNextSiblings();for(b.unshift(a);0<b.length&&(a=b.shift(),
|
|
7
|
+
var d=require("@lexical/utils"),f=require("lexical"),g=require("lexical/CodeHighlightNode");
|
|
8
|
+
class h extends f.ElementNode{static getType(){return"code"}static clone(a){return new h(a.__language,a.__key)}constructor(a,c){super(c);this.__language=a}createDOM(a){const c=document.createElement("code");d.addClassNamesToElement(c,a.theme.code);c.setAttribute("spellcheck","false");return c}updateDOM(){return!1}static convertDOM(){return{div:()=>({conversion:k,priority:1}),pre:()=>({conversion:l,priority:0}),table:a=>a.classList.contains("js-file-line-container")?{conversion:m,priority:1}:null,
|
|
9
|
+
td:a=>a.classList.contains("js-file-line")?{conversion:n,priority:1}: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=f.$createParagraphNode(),this.insertAfter(a),a;c=a.anchor.getNode();var e=p(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=g.$createCodeHighlightNode(b),
|
|
10
|
+
c.insertAfter(b),a.insertNodes([f.$createLineBreakNode()]),b.select(),b}return null}canInsertTab(){return!0}collapseAtStart(){const a=f.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=a}getLanguage(){return this.getLatest().__language}}function q(a){return new h(a)}
|
|
11
|
+
function p(a){let c=null;const b=a.getPreviousSiblings();for(b.push(a);0<b.length&&(a=b.pop(),g.$isCodeHighlightNode(a)&&(c=a),!f.$isLineBreakNode(a)););return c}function l(){return{node:q()}}function k(a){return{after:c=>{const b=a.parentNode;null!=b&&a!==b.lastChild&&c.push(f.$createLineBreakNode());return c},node:null!==a.style.fontFamily.match("monospace")?q():null}}function m(){return{node:q()}}
|
|
12
|
+
function n(a){return{after:c=>{a.parentNode&&a.parentNode.nextSibling&&c.push(f.$createLineBreakNode());return c},node:null}}exports.$createCodeNode=q;exports.$isCodeNode=function(a){return a instanceof h};exports.CodeNode=h;exports.getFirstCodeHighlightNodeOfLine=p;exports.getLastCodeHighlightNodeOfLine=function(a){let c=null;const b=a.getNextSiblings();for(b.unshift(a);0<b.length&&(a=b.shift(),g.$isCodeHighlightNode(a)&&(c=a),!f.$isLineBreakNode(a)););return c};
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var hashtag = require('@lexical/hashtag');
|
|
9
10
|
var list = require('@lexical/list');
|
|
10
11
|
var table = require('@lexical/table');
|
|
11
12
|
var AutoLinkNode = require('lexical/AutoLinkNode');
|
|
12
13
|
var CodeHighlightNode = require('lexical/CodeHighlightNode');
|
|
13
14
|
var CodeNode = require('lexical/CodeNode');
|
|
14
|
-
var HashtagNode = require('lexical/HashtagNode');
|
|
15
15
|
var HeadingNode = require('lexical/HeadingNode');
|
|
16
16
|
var LinkNode = require('lexical/LinkNode');
|
|
17
17
|
var OverflowNode = require('lexical/OverflowNode');
|
|
@@ -25,6 +25,6 @@ var QuoteNode = require('lexical/QuoteNode');
|
|
|
25
25
|
*
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
|
-
const LexicalExtendedNodes = [HeadingNode.HeadingNode, list.ListNode, list.ListItemNode, QuoteNode.QuoteNode, CodeNode.CodeNode, table.TableNode, table.TableCellNode, table.TableRowNode,
|
|
28
|
+
const LexicalExtendedNodes = [HeadingNode.HeadingNode, list.ListNode, list.ListItemNode, QuoteNode.QuoteNode, CodeNode.CodeNode, table.TableNode, table.TableCellNode, table.TableRowNode, hashtag.HashtagNode, CodeHighlightNode.CodeHighlightNode, AutoLinkNode.AutoLinkNode, LinkNode.LinkNode, OverflowNode.OverflowNode];
|
|
29
29
|
|
|
30
30
|
module.exports = LexicalExtendedNodes;
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var a=require("@lexical/
|
|
8
|
-
module.exports=[g.HeadingNode,
|
|
7
|
+
var a=require("@lexical/hashtag"),b=require("@lexical/list"),c=require("@lexical/table"),d=require("lexical/AutoLinkNode"),e=require("lexical/CodeHighlightNode"),f=require("lexical/CodeNode"),g=require("lexical/HeadingNode"),h=require("lexical/LinkNode"),k=require("lexical/OverflowNode"),l=require("lexical/QuoteNode");
|
|
8
|
+
module.exports=[g.HeadingNode,b.ListNode,b.ListItemNode,l.QuoteNode,f.CodeNode,c.TableNode,c.TableCellNode,c.TableRowNode,a.HashtagNode,e.CodeHighlightNode,d.AutoLinkNode,h.LinkNode,k.OverflowNode];
|
|
@@ -6,24 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var utils = require('@lexical/utils');
|
|
9
10
|
var lexical = require('lexical');
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the MIT license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
20
|
-
classNames.forEach(className => {
|
|
21
|
-
if (className != null && typeof className === 'string') {
|
|
22
|
-
element.classList.add(...className.split(' '));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
12
|
/**
|
|
28
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
14
|
*
|
|
@@ -60,7 +45,7 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
60
45
|
if (classNames !== undefined) {
|
|
61
46
|
// $FlowFixMe: intentional cast
|
|
62
47
|
const className = classNames[tag];
|
|
63
|
-
addClassNamesToElement(element, className);
|
|
48
|
+
utils.addClassNamesToElement(element, className);
|
|
64
49
|
}
|
|
65
50
|
|
|
66
51
|
return element;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
class
|
|
9
|
-
d.$createParagraphNode(),b=this.getDirection();a.setDirection(b);this.insertAfter(a);return a}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}}function g(a){a=a.nodeName.toLowerCase();let b=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a)b=h(a);return{node:b}}function h(a){return new
|
|
7
|
+
var c=require("@lexical/utils"),d=require("lexical");
|
|
8
|
+
class e extends d.ElementNode{static getType(){return"heading"}static clone(a){return new e(a.__tag,a.__key)}constructor(a,b){super(b);this.__tag=a}getTag(){return this.__tag}createDOM(a){const b=this.__tag,f=document.createElement(b);a=a.theme.heading;void 0!==a&&c.addClassNamesToElement(f,a[b]);return f}updateDOM(){return!1}static convertDOM(){return{h1:()=>({conversion:g,priority:0}),h2:()=>({conversion:g,priority:0}),h3:()=>({conversion:g,priority:0}),h4:()=>({conversion:g,priority:0}),h5:()=>
|
|
9
|
+
({conversion:g,priority:0})}}insertNewAfter(){const a=d.$createParagraphNode(),b=this.getDirection();a.setDirection(b);this.insertAfter(a);return a}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}}function g(a){a=a.nodeName.toLowerCase();let b=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a)b=h(a);return{node:b}}function h(a){return new e(a)}exports.$createHeadingNode=h;
|
|
10
|
+
exports.$isHeadingNode=function(a){return a instanceof e};exports.HeadingNode=e;
|
package/LexicalLinkNode.dev.js
CHANGED
|
@@ -6,24 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var utils = require('@lexical/utils');
|
|
9
10
|
var lexical = require('lexical');
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the MIT license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
20
|
-
classNames.forEach(className => {
|
|
21
|
-
if (className != null && typeof className === 'string') {
|
|
22
|
-
element.classList.add(...className.split(' '));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
12
|
/**
|
|
28
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
14
|
*
|
|
@@ -49,7 +34,7 @@ class LinkNode extends lexical.ElementNode {
|
|
|
49
34
|
createDOM(config) {
|
|
50
35
|
const element = document.createElement('a');
|
|
51
36
|
element.href = this.__url;
|
|
52
|
-
addClassNamesToElement(element, config.theme.link);
|
|
37
|
+
utils.addClassNamesToElement(element, config.theme.link);
|
|
53
38
|
return element;
|
|
54
39
|
}
|
|
55
40
|
|
package/LexicalLinkNode.prod.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
class
|
|
9
|
-
if(d.$isElementNode(a)){const b=h(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}}function g(a){let b=null;a instanceof HTMLAnchorElement&&(b=h(a.href));return{node:b}}function h(a){return new
|
|
7
|
+
var c=require("@lexical/utils"),d=require("lexical");
|
|
8
|
+
class e extends d.ElementNode{static getType(){return"link"}static clone(a){return new e(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){const b=document.createElement("a");b.href=this.__url;c.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){const f=this.__url;f!==a.__url&&(b.href=f);return!1}static convertDOM(){return{a:()=>({conversion:g,priority:1})}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);
|
|
9
|
+
if(d.$isElementNode(a)){const b=h(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}}function g(a){let b=null;a instanceof HTMLAnchorElement&&(b=h(a.href));return{node:b}}function h(a){return new e(a)}exports.$createLinkNode=h;exports.$isLinkNode=function(a){return a instanceof e};exports.LinkNode=e;
|
package/LexicalQuoteNode.dev.js
CHANGED
|
@@ -6,24 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var utils = require('@lexical/utils');
|
|
9
10
|
var lexical = require('lexical');
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the MIT license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
20
|
-
classNames.forEach(className => {
|
|
21
|
-
if (className != null && typeof className === 'string') {
|
|
22
|
-
element.classList.add(...className.split(' '));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
12
|
/**
|
|
28
13
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
14
|
*
|
|
@@ -48,7 +33,7 @@ class QuoteNode extends lexical.ElementNode {
|
|
|
48
33
|
|
|
49
34
|
createDOM(config) {
|
|
50
35
|
const element = document.createElement('blockquote');
|
|
51
|
-
addClassNamesToElement(element, config.theme.quote);
|
|
36
|
+
utils.addClassNamesToElement(element, config.theme.quote);
|
|
52
37
|
return element;
|
|
53
38
|
}
|
|
54
39
|
|
package/LexicalQuoteNode.prod.js
CHANGED
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var c=require("lexical")
|
|
8
|
-
class
|
|
9
|
-
exports.$isQuoteNode=function(a){return a instanceof
|
|
7
|
+
var c=require("@lexical/utils"),d=require("lexical");
|
|
8
|
+
class e extends d.ElementNode{static getType(){return"quote"}static clone(a){return new e(a.__key)}constructor(a){super(a)}createDOM(a){const b=document.createElement("blockquote");c.addClassNamesToElement(b,a.theme.quote);return b}updateDOM(){return!1}insertNewAfter(){const a=d.$createParagraphNode(),b=this.getDirection();a.setDirection(b);this.insertAfter(a);return a}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(b=>a.append(b));this.replace(a);return!0}}
|
|
9
|
+
exports.$createQuoteNode=function(){return new e};exports.$isQuoteNode=function(a){return a instanceof e};exports.QuoteNode=e;
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ There are a few ways to update an editor instance:
|
|
|
89
89
|
|
|
90
90
|
- Trigger an update with `editor.update()`
|
|
91
91
|
- Setting the editor state via `editor.setEditorState()`
|
|
92
|
-
- Applying a change as part of an existing update via `editor.
|
|
92
|
+
- Applying a change as part of an existing update via `editor.addNodeTransform()`
|
|
93
93
|
- Using a command listener with `editor.addListener('command', () => {...}, priority)`
|
|
94
94
|
|
|
95
95
|
The most common way to update the editor is to use `editor.update()`. Calling this function
|
package/package.json
CHANGED
package/HashtagNode.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
'use strict'
|
|
8
|
-
const LexicalHashtagNode = process.env.NODE_ENV === 'development' ? require('./LexicalHashtagNode.dev.js') : require('./LexicalHashtagNode.prod.js')
|
|
9
|
-
module.exports = LexicalHashtagNode;
|
package/HashtagNode.js.flow
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type {EditorConfig, LexicalNode, NodeKey} from 'lexical';
|
|
11
|
-
|
|
12
|
-
import {TextNode} from 'lexical';
|
|
13
|
-
|
|
14
|
-
declare export class HashtagNode extends TextNode {
|
|
15
|
-
static getType(): string;
|
|
16
|
-
static clone(node: HashtagNode): HashtagNode;
|
|
17
|
-
constructor(text: string, key?: NodeKey): void;
|
|
18
|
-
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
19
|
-
setTextContent(text: string): TextNode;
|
|
20
|
-
canInsertTextBefore(): boolean;
|
|
21
|
-
canInsertTextAfter(): boolean;
|
|
22
|
-
}
|
|
23
|
-
declare export function $toggleHashtag(node: TextNode): TextNode;
|
|
24
|
-
declare export function $createHashtagNode(text?: string): TextNode;
|
|
25
|
-
declare export function $isHashtagNode(
|
|
26
|
-
node: ?LexicalNode,
|
|
27
|
-
): boolean %checks(node instanceof HashtagNode);
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
var lexical = require('lexical');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the MIT license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
20
|
-
classNames.forEach(className => {
|
|
21
|
-
if (className != null && typeof className === 'string') {
|
|
22
|
-
element.classList.add(...className.split(' '));
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
29
|
-
*
|
|
30
|
-
* This source code is licensed under the MIT license found in the
|
|
31
|
-
* LICENSE file in the root directory of this source tree.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
class HashtagNode extends lexical.TextNode {
|
|
36
|
-
static getType() {
|
|
37
|
-
return 'hashtag';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static clone(node) {
|
|
41
|
-
return new HashtagNode(node.__text, node.__key);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
constructor(text, key) {
|
|
45
|
-
super(text, key);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
createDOM(config) {
|
|
49
|
-
const element = super.createDOM(config);
|
|
50
|
-
addClassNamesToElement(element, config.theme.hashtag);
|
|
51
|
-
return element;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
setTextContent(text) {
|
|
55
|
-
let targetNode = super.setTextContent(text); // Handle hashtags
|
|
56
|
-
|
|
57
|
-
if (targetNode.getParent() !== null && !targetNode.isComposing()) {
|
|
58
|
-
const indexOfHash = text.indexOf('#');
|
|
59
|
-
|
|
60
|
-
if (indexOfHash === -1 || targetNode.getTextContent() === '#') {
|
|
61
|
-
targetNode = $toggleHashtag(targetNode);
|
|
62
|
-
} else if (indexOfHash > 0) {
|
|
63
|
-
[targetNode] = targetNode.splitText(indexOfHash);
|
|
64
|
-
targetNode = $toggleHashtag(targetNode);
|
|
65
|
-
} // Check for invalid characters
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (lexical.$isTextNode(targetNode) && targetNode.isAttached()) {
|
|
69
|
-
const targetTextContent = targetNode.getTextContent().slice(1);
|
|
70
|
-
const indexOfInvalidChar = targetTextContent.search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/);
|
|
71
|
-
|
|
72
|
-
if (indexOfInvalidChar === 0) {
|
|
73
|
-
targetNode = $toggleHashtag(targetNode);
|
|
74
|
-
} else if (indexOfInvalidChar > 0) {
|
|
75
|
-
[targetNode] = targetNode.splitText(indexOfInvalidChar + 1);
|
|
76
|
-
targetNode = $toggleHashtag(targetNode);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return targetNode;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
canInsertTextBefore() {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
canInsertTextAfter() {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
function $toggleHashtag(node) {
|
|
96
|
-
const text = node.getTextContent();
|
|
97
|
-
const replacement = !$isHashtagNode(node) ? $createHashtagNode(text) : lexical.$createTextNode(text);
|
|
98
|
-
node.replace(replacement);
|
|
99
|
-
return replacement;
|
|
100
|
-
}
|
|
101
|
-
function $createHashtagNode(text = '') {
|
|
102
|
-
return new HashtagNode(text);
|
|
103
|
-
}
|
|
104
|
-
function $isHashtagNode(node) {
|
|
105
|
-
return node instanceof HashtagNode;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
exports.$createHashtagNode = $createHashtagNode;
|
|
109
|
-
exports.$isHashtagNode = $isHashtagNode;
|
|
110
|
-
exports.$toggleHashtag = $toggleHashtag;
|
|
111
|
-
exports.HashtagNode = HashtagNode;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
var c=require("lexical");function d(b,...a){a.forEach(f=>{null!=f&&"string"===typeof f&&b.classList.add(...f.split(" "))})}
|
|
8
|
-
class e extends c.TextNode{static getType(){return"hashtag"}static clone(b){return new e(b.__text,b.__key)}constructor(b,a){super(b,a)}createDOM(b){const a=super.createDOM(b);d(a,b.theme.hashtag);return a}setTextContent(b){let a=super.setTextContent(b);return null===a.getParent()||a.isComposing()?this:(b=b.indexOf("#"),-1===b||"#"===a.getTextContent()?a=g(a):0<b&&([a]=a.splitText(b),a=g(a)),c.$isTextNode(a)&&a.isAttached()&&(b=a.getTextContent().slice(1).search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/),
|
|
9
|
-
0===b?a=g(a):0<b&&([a]=a.splitText(b+1),a=g(a))),a)}canInsertTextBefore(){return!1}canInsertTextAfter(){return!0}}function g(b){var a=b.getTextContent();a=h(b)?c.$createTextNode(a):k(a);b.replace(a);return a}function k(b=""){return new e(b)}function h(b){return b instanceof e}exports.$createHashtagNode=k;exports.$isHashtagNode=h;exports.$toggleHashtag=g;exports.HashtagNode=e;
|