lexical 0.1.4 → 0.1.8
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/AutoLinkNode.js +9 -1
- package/CodeHighlightNode.js +9 -3
- package/CodeNode.js +9 -5
- package/HashtagNode.js +9 -3
- package/HeadingNode.js +9 -3
- package/Lexical.dev.js +7638 -0
- package/Lexical.js +9 -143
- package/Lexical.prod.js +153 -0
- package/LexicalAutoLinkNode.dev.js +58 -0
- package/LexicalAutoLinkNode.prod.js +7 -0
- package/LexicalCodeHighlightNode.dev.js +100 -0
- package/LexicalCodeHighlightNode.prod.js +9 -0
- package/LexicalCodeNode.dev.js +173 -0
- package/LexicalCodeNode.prod.js +11 -0
- package/LexicalExtendedNode.js +9 -0
- package/LexicalExtendedNodes.dev.js +32 -0
- package/LexicalExtendedNodes.prod.js +8 -0
- package/LexicalHashtagNode.dev.js +111 -0
- package/LexicalHashtagNode.prod.js +9 -0
- package/LexicalHeadingNode.dev.js +100 -0
- package/LexicalHeadingNode.prod.js +9 -0
- package/LexicalLinkNode.dev.js +115 -0
- package/LexicalLinkNode.prod.js +9 -0
- package/LexicalOverflowNode.dev.js +67 -0
- package/LexicalOverflowNode.js +9 -0
- package/LexicalOverflowNode.prod.js +8 -0
- package/LexicalQuoteNode.dev.js +86 -0
- package/LexicalQuoteNode.prod.js +9 -0
- package/LexicalTableCellNode.dev.js +81 -0
- package/LexicalTableCellNode.prod.js +9 -0
- package/LexicalTableNode.dev.js +638 -0
- package/LexicalTableNode.prod.js +21 -0
- package/LexicalTableRowNode.dev.js +76 -0
- package/LexicalTableRowNode.prod.js +8 -0
- package/LinkNode.js +9 -3
- package/QuoteNode.js +9 -3
- package/README.md +102 -4
- package/TableCellNode.js +9 -3
- package/TableNode.js +9 -10
- package/TableRowNode.js +9 -2
- package/package.json +2 -2
- package/ListItemNode.js +0 -8
- package/ListNode.js +0 -5
- package/ParagraphNode.js +0 -3
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
var LinkNode = require('lexical/LinkNode');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
// allow typing within the link
|
|
21
|
+
|
|
22
|
+
class AutoLinkNode extends LinkNode.LinkNode {
|
|
23
|
+
static getType() {
|
|
24
|
+
return 'autolink';
|
|
25
|
+
} // $FlowFixMe[incompatible-extend]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
static clone(node) {
|
|
29
|
+
return new AutoLinkNode(node.__url, node.__key);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
insertNewAfter(selection) {
|
|
33
|
+
const element = this.getParentOrThrow().insertNewAfter(selection);
|
|
34
|
+
|
|
35
|
+
if (lexical.$isElementNode(element)) {
|
|
36
|
+
const linkNode = $createAutoLinkNode(this.__url);
|
|
37
|
+
element.append(linkNode);
|
|
38
|
+
return linkNode;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
canInsertTextAfter() {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
function $createAutoLinkNode(url) {
|
|
50
|
+
return new AutoLinkNode(url);
|
|
51
|
+
}
|
|
52
|
+
function $isAutoLinkNode(node) {
|
|
53
|
+
return node instanceof AutoLinkNode;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.$createAutoLinkNode = $createAutoLinkNode;
|
|
57
|
+
exports.$isAutoLinkNode = $isAutoLinkNode;
|
|
58
|
+
exports.AutoLinkNode = AutoLinkNode;
|
|
@@ -0,0 +1,7 @@
|
|
|
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';var b=require("lexical"),c=require("lexical/LinkNode");class e extends c.LinkNode{static getType(){return"autolink"}static clone(a){return new e(a.__url,a.__key)}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(b.$isElementNode(a)){const d=f(this.__url);a.append(d);return d}return null}canInsertTextAfter(){return!0}}function f(a){return new e(a)}exports.$createAutoLinkNode=f;exports.$isAutoLinkNode=function(a){return a instanceof e};exports.AutoLinkNode=e;
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
function removeClassNamesFromElement(element, ...classNames) {
|
|
27
|
+
classNames.forEach(className => {
|
|
28
|
+
element.classList.remove(...className.split(' '));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
34
|
+
*
|
|
35
|
+
* This source code is licensed under the MIT license found in the
|
|
36
|
+
* LICENSE file in the root directory of this source tree.
|
|
37
|
+
*
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
class CodeHighlightNode extends lexical.TextNode {
|
|
41
|
+
constructor(text, highlightType, key) {
|
|
42
|
+
super(text, key);
|
|
43
|
+
this.__highlightType = highlightType;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static getType() {
|
|
47
|
+
return 'code-highlight';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static clone(node) {
|
|
51
|
+
return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
createDOM(config) {
|
|
55
|
+
const element = super.createDOM(config);
|
|
56
|
+
const className = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
57
|
+
addClassNamesToElement(element, className);
|
|
58
|
+
return element;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
updateDOM( // $FlowFixMe
|
|
62
|
+
prevNode, dom, config) {
|
|
63
|
+
const update = super.updateDOM(prevNode, dom, config);
|
|
64
|
+
const prevClassName = getHighlightThemeClass(config.theme, prevNode.__highlightType);
|
|
65
|
+
const nextClassName = getHighlightThemeClass(config.theme, this.__highlightType);
|
|
66
|
+
|
|
67
|
+
if (prevClassName !== nextClassName) {
|
|
68
|
+
if (prevClassName) {
|
|
69
|
+
removeClassNamesFromElement(dom, prevClassName);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (nextClassName) {
|
|
73
|
+
addClassNamesToElement(dom, nextClassName);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return update;
|
|
78
|
+
} // Prevent formatting (bold, underline, etc)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
setFormat(format) {
|
|
82
|
+
return this.getWritable();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getHighlightThemeClass(theme, highlightType) {
|
|
88
|
+
return highlightType && theme && theme.codeHighlight && theme.codeHighlight[highlightType];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function $createCodeHighlightNode(text, highlightType) {
|
|
92
|
+
return new CodeHighlightNode(text, highlightType);
|
|
93
|
+
}
|
|
94
|
+
function $isCodeHighlightNode(node) {
|
|
95
|
+
return node instanceof CodeHighlightNode;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.$createCodeHighlightNode = $createCodeHighlightNode;
|
|
99
|
+
exports.$isCodeHighlightNode = $isCodeHighlightNode;
|
|
100
|
+
exports.CodeHighlightNode = CodeHighlightNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
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';var d=require("lexical");function e(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})}function f(a,...b){b.forEach(c=>{a.classList.remove(...c.split(" "))})}
|
|
8
|
+
class g extends d.TextNode{constructor(a,b,c){super(a,c);this.__highlightType=b}static getType(){return"code-highlight"}static clone(a){return new g(a.__text,a.__highlightType||void 0,a.__key)}createDOM(a){const b=super.createDOM(a);a=h(a.theme,this.__highlightType);e(b,a);return b}updateDOM(a,b,c){const k=super.updateDOM(a,b,c);a=h(c.theme,a.__highlightType);c=h(c.theme,this.__highlightType);a!==c&&(a&&f(b,a),c&&e(b,c));return k}setFormat(){return this.getWritable()}}
|
|
9
|
+
function h(a,b){return b&&a&&a.codeHighlight&&a.codeHighlight[b]}exports.$createCodeHighlightNode=function(a,b){return new g(a,b)};exports.$isCodeHighlightNode=function(a){return a instanceof g};exports.CodeHighlightNode=g;
|
|
@@ -0,0 +1,173 @@
|
|
|
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
|
+
var CodeHighlightNode = require('lexical/CodeHighlightNode');
|
|
11
|
+
|
|
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
|
+
/**
|
|
29
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
30
|
+
*
|
|
31
|
+
* This source code is licensed under the MIT license found in the
|
|
32
|
+
* LICENSE file in the root directory of this source tree.
|
|
33
|
+
*
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
class CodeNode extends lexical.ElementNode {
|
|
37
|
+
static getType() {
|
|
38
|
+
return 'code';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static clone(node) {
|
|
42
|
+
return new CodeNode(node.__language, node.__key);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
constructor(language, key) {
|
|
46
|
+
super(key);
|
|
47
|
+
this.__language = language;
|
|
48
|
+
} // View
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
createDOM(config) {
|
|
52
|
+
const element = document.createElement('code');
|
|
53
|
+
addClassNamesToElement(element, config.theme.code);
|
|
54
|
+
element.setAttribute('spellcheck', 'false');
|
|
55
|
+
return element;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
updateDOM(prevNode, dom) {
|
|
59
|
+
return false;
|
|
60
|
+
} // Mutation
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
insertNewAfter(selection) {
|
|
64
|
+
const children = this.getChildren();
|
|
65
|
+
const childrenLength = children.length;
|
|
66
|
+
|
|
67
|
+
if (childrenLength >= 2 && children[childrenLength - 1].getTextContent() === '\n' && children[childrenLength - 2].getTextContent() === '\n' && selection.isCollapsed() && selection.anchor.key === this.__key && selection.anchor.offset === childrenLength) {
|
|
68
|
+
children[childrenLength - 1].remove();
|
|
69
|
+
children[childrenLength - 2].remove();
|
|
70
|
+
const newElement = lexical.$createParagraphNode();
|
|
71
|
+
this.insertAfter(newElement);
|
|
72
|
+
return newElement;
|
|
73
|
+
} // If the selection is within the codeblock, find all leading tabs and
|
|
74
|
+
// spaces of the current line. Create a new line that has all those
|
|
75
|
+
// tabs and spaces, such that leading indentation is preserved.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
const anchor = selection.anchor.getNode();
|
|
79
|
+
const firstNode = getFirstCodeHighlightNodeOfLine(anchor);
|
|
80
|
+
|
|
81
|
+
if (firstNode != null) {
|
|
82
|
+
let leadingWhitespace = 0;
|
|
83
|
+
const firstNodeText = firstNode.getTextContent();
|
|
84
|
+
|
|
85
|
+
while (leadingWhitespace < firstNodeText.length && /[\t ]/.test(firstNodeText[leadingWhitespace])) {
|
|
86
|
+
leadingWhitespace += 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (leadingWhitespace > 0) {
|
|
90
|
+
const whitespace = firstNodeText.substring(0, leadingWhitespace);
|
|
91
|
+
const indentedChild = CodeHighlightNode.$createCodeHighlightNode(whitespace);
|
|
92
|
+
anchor.insertAfter(indentedChild);
|
|
93
|
+
selection.insertNodes([lexical.$createLineBreakNode()]);
|
|
94
|
+
indentedChild.select();
|
|
95
|
+
return indentedChild;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
canInsertTab() {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
collapseAtStart() {
|
|
107
|
+
const paragraph = lexical.$createParagraphNode();
|
|
108
|
+
const children = this.getChildren();
|
|
109
|
+
children.forEach(child => paragraph.append(child));
|
|
110
|
+
this.replace(paragraph);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setLanguage(language) {
|
|
115
|
+
const writable = this.getWritable();
|
|
116
|
+
writable.__language = language;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getLanguage() {
|
|
120
|
+
return this.getLatest().__language;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
function $createCodeNode(language) {
|
|
125
|
+
return new CodeNode(language);
|
|
126
|
+
}
|
|
127
|
+
function $isCodeNode(node) {
|
|
128
|
+
return node instanceof CodeNode;
|
|
129
|
+
}
|
|
130
|
+
function getFirstCodeHighlightNodeOfLine(anchor) {
|
|
131
|
+
let currentNode = null;
|
|
132
|
+
const previousSiblings = anchor.getPreviousSiblings();
|
|
133
|
+
previousSiblings.push(anchor);
|
|
134
|
+
|
|
135
|
+
while (previousSiblings.length > 0) {
|
|
136
|
+
const node = previousSiblings.pop();
|
|
137
|
+
|
|
138
|
+
if (CodeHighlightNode.$isCodeHighlightNode(node)) {
|
|
139
|
+
currentNode = node;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (lexical.$isLineBreakNode(node)) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return currentNode;
|
|
148
|
+
}
|
|
149
|
+
function getLastCodeHighlightNodeOfLine(anchor) {
|
|
150
|
+
let currentNode = null;
|
|
151
|
+
const nextSiblings = anchor.getNextSiblings();
|
|
152
|
+
nextSiblings.unshift(anchor);
|
|
153
|
+
|
|
154
|
+
while (nextSiblings.length > 0) {
|
|
155
|
+
const node = nextSiblings.shift();
|
|
156
|
+
|
|
157
|
+
if (CodeHighlightNode.$isCodeHighlightNode(node)) {
|
|
158
|
+
currentNode = node;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (lexical.$isLineBreakNode(node)) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return currentNode;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
exports.$createCodeNode = $createCodeNode;
|
|
170
|
+
exports.$isCodeNode = $isCodeNode;
|
|
171
|
+
exports.CodeNode = CodeNode;
|
|
172
|
+
exports.getFirstCodeHighlightNodeOfLine = getFirstCodeHighlightNodeOfLine;
|
|
173
|
+
exports.getLastCodeHighlightNodeOfLine = getLastCodeHighlightNodeOfLine;
|
|
@@ -0,0 +1,11 @@
|
|
|
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';var d=require("lexical"),f=require("lexical/CodeHighlightNode");function g(a,...c){c.forEach(b=>{null!=b&&"string"===typeof b&&a.classList.add(...b.split(" "))})}
|
|
8
|
+
class h extends d.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");g(c,a.theme.code);c.setAttribute("spellcheck","false");return c}updateDOM(){return!1}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(),
|
|
9
|
+
c[b-2].remove(),a=d.$createParagraphNode(),this.insertAfter(a),a;c=a.anchor.getNode();var e=k(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=f.$createCodeHighlightNode(b),c.insertAfter(b),a.insertNodes([d.$createLineBreakNode()]),b.select(),b}return null}canInsertTab(){return!0}collapseAtStart(){const a=d.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}setLanguage(a){this.getWritable().__language=
|
|
10
|
+
a}getLanguage(){return this.getLatest().__language}}function k(a){let c=null;const b=a.getPreviousSiblings();for(b.push(a);0<b.length&&(a=b.pop(),f.$isCodeHighlightNode(a)&&(c=a),!d.$isLineBreakNode(a)););return c}exports.$createCodeNode=function(a){return new h(a)};exports.$isCodeNode=function(a){return a instanceof h};exports.CodeNode=h;exports.getFirstCodeHighlightNodeOfLine=k;
|
|
11
|
+
exports.getLastCodeHighlightNodeOfLine=function(a){let c=null;const b=a.getNextSiblings();for(b.unshift(a);0<b.length&&(a=b.shift(),f.$isCodeHighlightNode(a)&&(c=a),!d.$isLineBreakNode(a)););return c};
|
|
@@ -0,0 +1,9 @@
|
|
|
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 LexicalExtendedNodes = process.env.NODE_ENV === 'development' ? require('./LexicalExtendedNodes.dev.js') : require('./LexicalExtendedNodes.prod.js')
|
|
9
|
+
module.exports = LexicalExtendedNodes;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 list = require('@lexical/list');
|
|
10
|
+
var AutoLinkNode = require('lexical/AutoLinkNode');
|
|
11
|
+
var CodeHighlightNode = require('lexical/CodeHighlightNode');
|
|
12
|
+
var CodeNode = require('lexical/CodeNode');
|
|
13
|
+
var HashtagNode = require('lexical/HashtagNode');
|
|
14
|
+
var HeadingNode = require('lexical/HeadingNode');
|
|
15
|
+
var LinkNode = require('lexical/LinkNode');
|
|
16
|
+
var OverflowNode = require('lexical/OverflowNode');
|
|
17
|
+
var QuoteNode = require('lexical/QuoteNode');
|
|
18
|
+
var TableCellNode = require('lexical/TableCellNode');
|
|
19
|
+
var TableNode = require('lexical/TableNode');
|
|
20
|
+
var TableRowNode = require('lexical/TableRowNode');
|
|
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
|
+
const LexicalExtendedNodes = [HeadingNode.HeadingNode, list.ListNode, list.ListItemNode, QuoteNode.QuoteNode, CodeNode.CodeNode, TableNode.TableNode, TableCellNode.TableCellNode, TableRowNode.TableRowNode, HashtagNode.HashtagNode, CodeHighlightNode.CodeHighlightNode, AutoLinkNode.AutoLinkNode, LinkNode.LinkNode, OverflowNode.OverflowNode];
|
|
31
|
+
|
|
32
|
+
module.exports = LexicalExtendedNodes;
|
|
@@ -0,0 +1,8 @@
|
|
|
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';var a=require("@lexical/list"),b=require("lexical/AutoLinkNode"),c=require("lexical/CodeHighlightNode"),d=require("lexical/CodeNode"),e=require("lexical/HashtagNode"),f=require("lexical/HeadingNode"),g=require("lexical/LinkNode"),h=require("lexical/OverflowNode"),k=require("lexical/QuoteNode"),l=require("lexical/TableCellNode"),m=require("lexical/TableNode"),n=require("lexical/TableRowNode");
|
|
8
|
+
module.exports=[f.HeadingNode,a.ListNode,a.ListItemNode,k.QuoteNode,d.CodeNode,m.TableNode,l.TableCellNode,n.TableRowNode,e.HashtagNode,c.CodeHighlightNode,b.AutoLinkNode,g.LinkNode,h.OverflowNode];
|
|
@@ -0,0 +1,111 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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';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;
|
|
@@ -0,0 +1,100 @@
|
|
|
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 HeadingNode extends lexical.ElementNode {
|
|
36
|
+
static getType() {
|
|
37
|
+
return 'heading';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static clone(node) {
|
|
41
|
+
return new HeadingNode(node.__tag, node.__key);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
constructor(tag, key) {
|
|
45
|
+
super(key);
|
|
46
|
+
this.__tag = tag;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getTag() {
|
|
50
|
+
return this.__tag;
|
|
51
|
+
} // View
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
createDOM(config) {
|
|
55
|
+
const tag = this.__tag;
|
|
56
|
+
const element = document.createElement(tag);
|
|
57
|
+
const theme = config.theme;
|
|
58
|
+
const classNames = theme.heading;
|
|
59
|
+
|
|
60
|
+
if (classNames !== undefined) {
|
|
61
|
+
// $FlowFixMe: intentional cast
|
|
62
|
+
const className = classNames[tag];
|
|
63
|
+
addClassNamesToElement(element, className);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return element;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
updateDOM(prevNode, dom) {
|
|
70
|
+
return false;
|
|
71
|
+
} // Mutation
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
insertNewAfter() {
|
|
75
|
+
const newElement = lexical.$createParagraphNode();
|
|
76
|
+
const direction = this.getDirection();
|
|
77
|
+
newElement.setDirection(direction);
|
|
78
|
+
this.insertAfter(newElement);
|
|
79
|
+
return newElement;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
collapseAtStart() {
|
|
83
|
+
const paragraph = lexical.$createParagraphNode();
|
|
84
|
+
const children = this.getChildren();
|
|
85
|
+
children.forEach(child => paragraph.append(child));
|
|
86
|
+
this.replace(paragraph);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
function $createHeadingNode(headingTag) {
|
|
92
|
+
return new HeadingNode(headingTag);
|
|
93
|
+
}
|
|
94
|
+
function $isHeadingNode(node) {
|
|
95
|
+
return node instanceof HeadingNode;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
exports.$createHeadingNode = $createHeadingNode;
|
|
99
|
+
exports.$isHeadingNode = $isHeadingNode;
|
|
100
|
+
exports.HeadingNode = HeadingNode;
|
|
@@ -0,0 +1,9 @@
|
|
|
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';var d=require("lexical");function e(a,...b){b.forEach(c=>{null!=c&&"string"===typeof c&&a.classList.add(...c.split(" "))})}
|
|
8
|
+
class f extends d.ElementNode{static getType(){return"heading"}static clone(a){return new f(a.__tag,a.__key)}constructor(a,b){super(b);this.__tag=a}getTag(){return this.__tag}createDOM(a){const b=this.__tag,c=document.createElement(b);a=a.theme.heading;void 0!==a&&e(c,a[b]);return c}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=>
|
|
9
|
+
a.append(b));this.replace(a);return!0}}exports.$createHeadingNode=function(a){return new f(a)};exports.$isHeadingNode=function(a){return a instanceof f};exports.HeadingNode=f;
|