@lexical/react 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/DEPRECATED_useLexicalAutoFormatter.dev.js +283 -295
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -21
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +3 -72
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +11 -63
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +6 -7
- package/DEPRECATED_useLexicalPlainText.dev.js +16 -41
- package/DEPRECATED_useLexicalPlainText.prod.js +13 -14
- package/DEPRECATED_useLexicalRichText.dev.js +24 -49
- package/DEPRECATED_useLexicalRichText.prod.js +15 -15
- package/LexicalAutoFormatterPlugin.dev.js +283 -295
- package/LexicalAutoFormatterPlugin.prod.js +19 -21
- package/LexicalAutoLinkPlugin.dev.js +2 -2
- package/LexicalAutoLinkPlugin.prod.js +2 -2
- package/LexicalCharacterLimitPlugin.dev.js +11 -63
- package/LexicalCharacterLimitPlugin.prod.js +8 -9
- package/LexicalCollaborationPlugin.d.ts +5 -1
- package/LexicalCollaborationPlugin.dev.js +77 -14
- package/LexicalCollaborationPlugin.js.flow +7 -2
- package/LexicalCollaborationPlugin.prod.js +9 -7
- package/LexicalHashtagPlugin.dev.js +61 -3
- package/LexicalHashtagPlugin.prod.js +7 -4
- package/LexicalOnChangePlugin.dev.js +15 -2
- package/LexicalOnChangePlugin.prod.js +2 -1
- package/LexicalPlainTextPlugin.dev.js +20 -113
- package/LexicalPlainTextPlugin.prod.js +11 -12
- package/LexicalRichTextPlugin.dev.js +28 -121
- package/LexicalRichTextPlugin.prod.js +12 -13
- package/LexicalTablePlugin.dev.js +9 -5
- package/LexicalTablePlugin.prod.js +2 -2
- package/package.json +10 -7
- package/useLexicalIsTextContentEmpty.dev.js +3 -32
- package/useLexicalIsTextContentEmpty.prod.js +1 -2
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var hashtag = require('@lexical/hashtag');
|
|
9
10
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
11
|
var lexical = require('lexical');
|
|
11
|
-
var
|
|
12
|
+
var OverflowNode = require('lexical/OverflowNode');
|
|
12
13
|
var react = require('react');
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -105,6 +106,18 @@ function getHashtagRegexString() {
|
|
|
105
106
|
|
|
106
107
|
const REGEX = new RegExp(getHashtagRegexString(), 'ig');
|
|
107
108
|
|
|
109
|
+
function isValidCharacter(character) {
|
|
110
|
+
return character === '' || character.search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/) > -1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function startsWithValidChar(string) {
|
|
114
|
+
return isValidCharacter(string[0]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function endsWithValidChar(string) {
|
|
118
|
+
return isValidCharacter(string[string.length - 1]);
|
|
119
|
+
}
|
|
120
|
+
|
|
108
121
|
function textNodeTransform(node) {
|
|
109
122
|
if (!node.isSimpleText()) {
|
|
110
123
|
return;
|
|
@@ -117,13 +130,30 @@ function textNodeTransform(node) {
|
|
|
117
130
|
while (true) {
|
|
118
131
|
const matchArr = REGEX.exec(text);
|
|
119
132
|
|
|
133
|
+
if (currentNode == null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const nextSibling = currentNode.getNextSibling();
|
|
138
|
+
|
|
120
139
|
if (matchArr === null) {
|
|
140
|
+
if (hashtag.$isHashtagNode(nextSibling) && !endsWithValidChar(text) && !isNextNodeValid(currentNode)) {
|
|
141
|
+
hashtag.$toggleHashtag(nextSibling);
|
|
142
|
+
}
|
|
143
|
+
|
|
121
144
|
return;
|
|
122
145
|
}
|
|
123
146
|
|
|
124
147
|
const hashtagLength = matchArr[3].length + 1;
|
|
125
148
|
const startOffset = matchArr.index + matchArr[1].length - adjustedOffset;
|
|
126
149
|
const endOffset = startOffset + hashtagLength;
|
|
150
|
+
const prevChar = text[startOffset - 1] || '';
|
|
151
|
+
const nextChar = text[endOffset] || '';
|
|
152
|
+
|
|
153
|
+
if (startOffset === 0 && hashtag.$isHashtagNode(currentNode.getPreviousSibling()) || !isValidCharacter(prevChar) || !isValidCharacter(nextChar) || nextChar === '' && lexical.$isTextNode(nextSibling) && !nextSibling.isSimpleText()) {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
127
157
|
let targetNode;
|
|
128
158
|
|
|
129
159
|
if (startOffset === 0) {
|
|
@@ -133,13 +163,41 @@ function textNodeTransform(node) {
|
|
|
133
163
|
}
|
|
134
164
|
|
|
135
165
|
adjustedOffset += endOffset;
|
|
136
|
-
|
|
166
|
+
hashtag.$toggleHashtag(targetNode);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function isPreviousNodeValid(node) {
|
|
171
|
+
const previousNode = node.getPreviousSibling();
|
|
172
|
+
return previousNode === null || lexical.$isLineBreakNode(previousNode) || OverflowNode.$isOverflowNode(previousNode) || lexical.$isTextNode(previousNode) && !hashtag.$isHashtagNode(previousNode) && endsWithValidChar(previousNode.getTextContent());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function isNextNodeValid(node) {
|
|
176
|
+
const nextNode = node.getNextSibling();
|
|
177
|
+
return nextNode === null || lexical.$isLineBreakNode(nextNode) || OverflowNode.$isOverflowNode(nextNode) || lexical.$isTextNode(nextNode) && !hashtag.$isHashtagNode(nextNode) && startsWithValidChar(nextNode.getTextContent());
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function $hashtagToPlainTextTransform(hashtagNode) {
|
|
181
|
+
// Check neighbors
|
|
182
|
+
if (!isPreviousNodeValid(hashtagNode) || !isNextNodeValid(hashtagNode)) {
|
|
183
|
+
$convertHashtagNodeToPlainTextNode(hashtagNode);
|
|
184
|
+
return;
|
|
137
185
|
}
|
|
138
186
|
}
|
|
139
187
|
|
|
188
|
+
function $convertHashtagNodeToPlainTextNode(node) {
|
|
189
|
+
const textNode = lexical.$createTextNode(node.getTextContent());
|
|
190
|
+
node.replace(textNode);
|
|
191
|
+
}
|
|
192
|
+
|
|
140
193
|
function useHashtags(editor) {
|
|
141
194
|
react.useEffect(() => {
|
|
142
|
-
|
|
195
|
+
const removePlainTextTransform = editor.addNodeTransform(lexical.TextNode, textNodeTransform);
|
|
196
|
+
const removeHashtagToPlainTextTransform = editor.addNodeTransform(hashtag.HashtagNode, $hashtagToPlainTextTransform);
|
|
197
|
+
return () => {
|
|
198
|
+
removePlainTextTransform();
|
|
199
|
+
removeHashtagToPlainTextTransform();
|
|
200
|
+
};
|
|
143
201
|
}, [editor]);
|
|
144
202
|
}
|
|
145
203
|
|
|
@@ -4,7 +4,10 @@
|
|
|
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
|
-
const
|
|
9
|
-
"-"+
|
|
10
|
-
|
|
7
|
+
var e=require("@lexical/hashtag"),f=require("@lexical/react/LexicalComposerContext"),g=require("lexical"),h=require("lexical/OverflowNode"),n=require("react"),p=RegExp;
|
|
8
|
+
const q=String.fromCharCode,r="A-Za-z\u00aa\u00b5\u00ba\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u0241\u0250-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ee\u037a\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03f5\u03f7-\u0481\u048a-\u04ce\u04d0-\u04f9\u0500-\u050f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0621-\u063a\u0640-\u064a\u066e-\u066f\u0671-\u06d3\u06d5\u06e5-\u06e6\u06ee-\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u076d\u0780-\u07a5\u07b1\u0904-\u0939\u093d\u0950\u0958-\u0961\u097d\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0-\u0ae1\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32-\u0b33\u0b35-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0-\u0ce1\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32-\u0e33\u0e40-\u0e46\u0e81-\u0e82\u0e84\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa-\u0eab\u0ead-\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edd\u0f00\u0f40-\u0f47\u0f49-\u0f6a\u0f88-\u0f8b\u1000-\u1021\u1023-\u1027\u1029-\u102a\u1050-\u1055\u10a0-\u10c5\u10d0-\u10fa\u10fc\u1100-\u1159\u115f-\u11a2\u11a8-\u11f9\u1200-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u1676\u1681-\u169a\u16a0-\u16ea\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19a9\u19c1-\u19c7\u1a00-\u1a16\u1d00-\u1dbf\u1e00-\u1e9b\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u2094\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2131\u2133-\u2139\u213c-\u213f\u2145-\u2149\u2c00-\u2c2e\u2c30-\u2c5e\u2c80-\u2ce4\u2d00-\u2d25\u2d30-\u2d65\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3006\u3031-\u3035\u303b-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312c\u3131-\u318e\u31a0-\u31b7\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fbb\ua000-\ua48c\ua800-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\uac00-\ud7a3\uf900-\ufa2d\ufa30-\ufa6a\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc\u0300-\u036f\u0483-\u0486\u0591-\u05b9\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u0615\u064b-\u065e\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u0901-\u0903\u093c\u093e-\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0b01-\u0b03\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d82-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2-\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f3e-\u0f3f\u0f71-\u0f84\u0f86-\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102c-\u1032\u1036-\u1039\u1056-\u1059\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b6-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u192b\u1930-\u193b\u19b0-\u19c0\u19c8-\u19c9\u1a17-\u1a1b\u1dc0-\u1dc3\u20d0-\u20dc\u20e1\u20e5-\u20eb\u302a-\u302f\u3099-\u309a\ua802\ua806\ua80b\ua823-\ua827\ufb1e\ufe00-\ufe0f\ufe20-\ufe23\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0100-\u024f\u0253-\u0254\u0256-\u0257\u0259\u025b\u0263\u0268\u026f\u0272\u0289\u028b\u02bb\u0300-\u036f\u1e00-\u1eff\u0400-\u04ff\u0500-\u0527\u2de0-\u2dff\ua640-\ua69f\u0591-\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u05d0-\u05ea\u05f0-\u05f4\ufb12-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4f\u0610-\u061a\u0620-\u065f\u066e-\u06d3\u06d5-\u06dc\u06de-\u06e8\u06ea-\u06ef\u06fa-\u06fc\u06ff\u0750-\u077f\u08a0\u08a2-\u08ac\u08e4-\u08fe\ufb50-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\u200c-\u200c\u0e01-\u0e3a\u0e40-\u0e4e\u1100-\u11ff\u3130-\u3185\ua960-\ua97f\uac00-\ud7af\ud7b0-\ud7ff\uffa1-\uffdc\u30a1-\u30fa\u30fc-\u30fe\uff66-\uff9f\uff10-\uff19\uff21-\uff3a\uff41-\uff5a\u3041-\u3096\u3099-\u309e\u3400-\u4dbf\u4e00-\u9fff"+(q(173824)+
|
|
9
|
+
"-"+q(177983)+q(177984)+"-"+q(178207)+q(194560)+"-"+q(195103)+"\u3003\u3005\u303b"),{alpha:t,alphanumeric:v,hashChars:w}={alpha:r,alphanumeric:r+"0-9\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be6-\u0bef\u0c66-\u0c6f\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29\u1040-\u1049\u17e0-\u17e9\u1810-\u1819\u1946-\u194f\u19d0-\u19d9\uff10-\uff19_",hashChars:"#\\uFF03"},x="["+v+"]",y=new p("(^|$|[^&/"+(v+"])([")+(w+"])(")+x+"*["+(t+"]")+
|
|
10
|
+
x+"*)","ig");function z(a){return""===a||-1<a.search(/[\s.,\\\/#!$%\^&\*;:{}=\-`~()@]/)}
|
|
11
|
+
function A(a){if(a.isSimpleText())for(var b=a.getTextContent(),c=0;;){var d=y.exec(b);if(null==a)break;const l=a.getNextSibling();if(null===d){!e.$isHashtagNode(l)||z(b[b.length-1])||B(a)||e.$toggleHashtag(l);break}const k=d.index+d[1].length-c;d=k+(d[3].length+1);const C=b[k-1]||"",u=b[d]||"";if(0===k&&e.$isHashtagNode(a.getPreviousSibling())||!z(C)||!z(u)||""===u&&g.$isTextNode(l)&&!l.isSimpleText())continue;let m;0===k?[m,a]=a.splitText(d):[,m,a]=a.splitText(k,d);c+=d;e.$toggleHashtag(m)}}
|
|
12
|
+
function B(a){a=a.getNextSibling();return null===a||g.$isLineBreakNode(a)||h.$isOverflowNode(a)||g.$isTextNode(a)&&!e.$isHashtagNode(a)&&z(a.getTextContent()[0])}function D(a){var b=a.getPreviousSibling(),c;!(c=null===b||g.$isLineBreakNode(b)||h.$isOverflowNode(b))&&(c=g.$isTextNode(b)&&!e.$isHashtagNode(b))&&(b=b.getTextContent(),c=z(b[b.length-1]));c&&B(a)||(b=g.$createTextNode(a.getTextContent()),a.replace(b))}
|
|
13
|
+
function E(a){n.useEffect(()=>{const b=a.addNodeTransform(g.TextNode,A),c=a.addNodeTransform(e.HashtagNode,D);return()=>{b();c()}},[a])}module.exports=function(){const [a]=f.useLexicalComposerContext();E(a);return null};
|
|
@@ -39,18 +39,31 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
39
39
|
*
|
|
40
40
|
*/
|
|
41
41
|
function OnChangePlugin({
|
|
42
|
+
ignoreInitialChange = true,
|
|
43
|
+
ignoreSelectionChange = false,
|
|
42
44
|
onChange
|
|
43
45
|
}) {
|
|
44
46
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
45
47
|
useLayoutEffect(() => {
|
|
46
48
|
if (onChange) {
|
|
47
49
|
return editor.addListener('update', ({
|
|
48
|
-
editorState
|
|
50
|
+
editorState,
|
|
51
|
+
dirtyElements,
|
|
52
|
+
dirtyLeaves,
|
|
53
|
+
prevEditorState
|
|
49
54
|
}) => {
|
|
55
|
+
if (ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (ignoreInitialChange && prevEditorState.isEmpty()) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
50
63
|
onChange(editorState, editor);
|
|
51
64
|
});
|
|
52
65
|
}
|
|
53
|
-
}, [editor, onChange]);
|
|
66
|
+
}, [editor, ignoreInitialChange, ignoreSelectionChange, onChange]);
|
|
54
67
|
return null;
|
|
55
68
|
}
|
|
56
69
|
|
|
@@ -4,4 +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 c=require("@lexical/react/LexicalComposerContext"),
|
|
7
|
+
var c=require("@lexical/react/LexicalComposerContext"),f=require("react"),g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
|
|
8
|
+
module.exports=function({ignoreInitialChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){const [b]=c.useLexicalComposerContext();g(()=>{if(a)return b.addListener("update",({editorState:h,dirtyElements:k,dirtyLeaves:l,prevEditorState:m})=>{e&&0===k.size&&0===l.size||d&&m.isEmpty()||a(h,b)})},[b,d,e,a]);return null};
|
|
@@ -8,78 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
10
|
var React = require('react');
|
|
11
|
-
var
|
|
11
|
+
var text = require('@lexical/text');
|
|
12
12
|
var reactDom = require('react-dom');
|
|
13
13
|
var clipboard = require('@lexical/clipboard');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17
|
-
*
|
|
18
|
-
* This source code is licensed under the MIT license found in the
|
|
19
|
-
* LICENSE file in the root directory of this source tree.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
function $textContent() {
|
|
24
|
-
const root = lexical.$getRoot();
|
|
25
|
-
return root.getTextContent();
|
|
26
|
-
}
|
|
27
|
-
function $isTextContentEmpty(isEditorComposing, trim = true) {
|
|
28
|
-
if (isEditorComposing) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let text = $textContent();
|
|
33
|
-
|
|
34
|
-
if (trim) {
|
|
35
|
-
text = text.trim();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return text === '';
|
|
39
|
-
}
|
|
40
|
-
function $canShowPlaceholder(isComposing) {
|
|
41
|
-
if (!$isTextContentEmpty(isComposing, false)) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const root = lexical.$getRoot();
|
|
46
|
-
const children = root.getChildren();
|
|
47
|
-
const childrenLength = children.length;
|
|
48
|
-
|
|
49
|
-
if (childrenLength > 1) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < childrenLength; i++) {
|
|
54
|
-
const topBlock = children[i];
|
|
55
|
-
|
|
56
|
-
if (lexical.$isElementNode(topBlock)) {
|
|
57
|
-
if (topBlock.__type !== 'paragraph') {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (topBlock.__indent !== 0) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const topBlockChildren = topBlock.getChildren();
|
|
66
|
-
const topBlockChildrenLength = topBlockChildren.length;
|
|
67
|
-
|
|
68
|
-
for (let s = 0; s < topBlockChildrenLength; s++) {
|
|
69
|
-
const child = topBlockChildren[i];
|
|
70
|
-
|
|
71
|
-
if (!lexical.$isTextNode(child)) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
function $canShowPlaceholderCurry(isEditorComposing) {
|
|
81
|
-
return () => $canShowPlaceholder(isEditorComposing);
|
|
82
|
-
}
|
|
14
|
+
var selection = require('@lexical/selection');
|
|
15
|
+
var lexical = require('lexical');
|
|
83
16
|
|
|
84
17
|
/**
|
|
85
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -111,13 +44,13 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
111
44
|
*
|
|
112
45
|
*/
|
|
113
46
|
function useLexicalCanShowPlaceholder(editor) {
|
|
114
|
-
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(
|
|
47
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
|
|
115
48
|
useLayoutEffect(() => {
|
|
116
49
|
return editor.addListener('update', ({
|
|
117
50
|
editorState
|
|
118
51
|
}) => {
|
|
119
52
|
const isComposing = editor.isComposing();
|
|
120
|
-
const currentCanShowPlaceholder = editorState.read(
|
|
53
|
+
const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
|
|
121
54
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
122
55
|
});
|
|
123
56
|
}, [editor]);
|
|
@@ -161,32 +94,6 @@ function useDecorators(editor) {
|
|
|
161
94
|
}, [decorators, editor]);
|
|
162
95
|
}
|
|
163
96
|
|
|
164
|
-
/**
|
|
165
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
166
|
-
*
|
|
167
|
-
* This source code is licensed under the MIT license found in the
|
|
168
|
-
* LICENSE file in the root directory of this source tree.
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
|
|
174
|
-
selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
|
|
175
|
-
}
|
|
176
|
-
function $isParentElementRTL(selection) {
|
|
177
|
-
const anchorNode = selection.anchor.getNode();
|
|
178
|
-
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
179
|
-
return parent.getDirection() === 'rtl';
|
|
180
|
-
}
|
|
181
|
-
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
182
|
-
const isRTL = $isParentElementRTL(selection);
|
|
183
|
-
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
184
|
-
}
|
|
185
|
-
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
186
|
-
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
187
|
-
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
97
|
/**
|
|
191
98
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
192
99
|
*
|
|
@@ -391,9 +298,9 @@ function useLexicalDragonSupport(editor) {
|
|
|
391
298
|
function usePlainTextSetup(editor, initialEditorState) {
|
|
392
299
|
useLayoutEffect(() => {
|
|
393
300
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
394
|
-
const selection = lexical.$getSelection();
|
|
301
|
+
const selection$1 = lexical.$getSelection();
|
|
395
302
|
|
|
396
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
303
|
+
if (!lexical.$isRangeSelection(selection$1)) {
|
|
397
304
|
return false;
|
|
398
305
|
}
|
|
399
306
|
|
|
@@ -401,21 +308,21 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
401
308
|
case 'deleteCharacter':
|
|
402
309
|
{
|
|
403
310
|
const isBackward = payload;
|
|
404
|
-
selection.deleteCharacter(isBackward);
|
|
311
|
+
selection$1.deleteCharacter(isBackward);
|
|
405
312
|
return true;
|
|
406
313
|
}
|
|
407
314
|
|
|
408
315
|
case 'deleteWord':
|
|
409
316
|
{
|
|
410
317
|
const isBackward = payload;
|
|
411
|
-
selection.deleteWord(isBackward);
|
|
318
|
+
selection$1.deleteWord(isBackward);
|
|
412
319
|
return true;
|
|
413
320
|
}
|
|
414
321
|
|
|
415
322
|
case 'deleteLine':
|
|
416
323
|
{
|
|
417
324
|
const isBackward = payload;
|
|
418
|
-
selection.deleteLine(isBackward);
|
|
325
|
+
selection$1.deleteLine(isBackward);
|
|
419
326
|
return true;
|
|
420
327
|
}
|
|
421
328
|
|
|
@@ -424,17 +331,17 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
424
331
|
const eventOrText = payload;
|
|
425
332
|
|
|
426
333
|
if (typeof eventOrText === 'string') {
|
|
427
|
-
selection.insertText(eventOrText);
|
|
334
|
+
selection$1.insertText(eventOrText);
|
|
428
335
|
} else {
|
|
429
336
|
const dataTransfer = eventOrText.dataTransfer;
|
|
430
337
|
|
|
431
338
|
if (dataTransfer != null) {
|
|
432
|
-
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
|
|
339
|
+
clipboard.$insertDataTransferForPlainText(dataTransfer, selection$1);
|
|
433
340
|
} else {
|
|
434
341
|
const data = eventOrText.data;
|
|
435
342
|
|
|
436
343
|
if (data) {
|
|
437
|
-
selection.insertText(data);
|
|
344
|
+
selection$1.insertText(data);
|
|
438
345
|
}
|
|
439
346
|
}
|
|
440
347
|
}
|
|
@@ -443,16 +350,16 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
443
350
|
}
|
|
444
351
|
|
|
445
352
|
case 'removeText':
|
|
446
|
-
selection.removeText();
|
|
353
|
+
selection$1.removeText();
|
|
447
354
|
return true;
|
|
448
355
|
|
|
449
356
|
case 'insertLineBreak':
|
|
450
357
|
const selectStart = payload;
|
|
451
|
-
selection.insertLineBreak(selectStart);
|
|
358
|
+
selection$1.insertLineBreak(selectStart);
|
|
452
359
|
return true;
|
|
453
360
|
|
|
454
361
|
case 'insertParagraph':
|
|
455
|
-
selection.insertLineBreak();
|
|
362
|
+
selection$1.insertLineBreak();
|
|
456
363
|
return true;
|
|
457
364
|
|
|
458
365
|
case 'indentContent':
|
|
@@ -471,9 +378,9 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
471
378
|
const event = payload;
|
|
472
379
|
const isHoldingShift = event.shiftKey;
|
|
473
380
|
|
|
474
|
-
if (
|
|
381
|
+
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
|
|
475
382
|
event.preventDefault();
|
|
476
|
-
|
|
383
|
+
selection.$moveCharacter(selection$1, isHoldingShift, true);
|
|
477
384
|
return true;
|
|
478
385
|
}
|
|
479
386
|
|
|
@@ -485,9 +392,9 @@ function usePlainTextSetup(editor, initialEditorState) {
|
|
|
485
392
|
const event = payload;
|
|
486
393
|
const isHoldingShift = event.shiftKey;
|
|
487
394
|
|
|
488
|
-
if (
|
|
395
|
+
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
|
|
489
396
|
event.preventDefault();
|
|
490
|
-
|
|
397
|
+
selection.$moveCharacter(selection$1, isHoldingShift, false);
|
|
491
398
|
return true;
|
|
492
399
|
}
|
|
493
400
|
|
|
@@ -4,15 +4,14 @@
|
|
|
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 g=require("@lexical/react/LexicalComposerContext"),h=require("react"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function D(a
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=A(c);M(c,e);e=C(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
|
|
7
|
+
var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("@lexical/text"),u=require("react-dom"),v=require("@lexical/clipboard"),w=require("@lexical/selection"),x=require("lexical"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
8
|
+
function z(a){const [d,e]=h.useState(a.getEditorState().read(r.$canShowPlaceholderCurry(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(r.$canShowPlaceholderCurry(b));e(c)}),[a]);return d}
|
|
9
|
+
function B(a){const [d,e]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{e(c)})}),[a]);return h.useMemo(()=>{const c=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const t=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(t,f))}return c},[d,a])}function C(a,d){a.preventDefault();d.update(()=>{const e=x.$getSelection(),c=a.clipboardData;null!=c&&x.$isRangeSelection(e)&&v.$insertDataTransferForPlainText(c,e)})}
|
|
10
|
+
function D(a,d){E(a,d);d.update(()=>{const e=x.$getSelection();x.$isRangeSelection(e)&&e.removeText()})}function E(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=x.$getSelection();if(null!==c&&null!=e){const b=v.getHtmlContent(d);null!==b&&e.setData("text/html",b);e.setData("text/plain",c.getTextContent())}})}const F={tag:"history-merge"};
|
|
11
|
+
function G(a,d){if(null!==d)if(void 0===d)a.update(()=>{var e=x.$getRoot();if(null===e.getFirstChild()){const c=x.$createParagraphNode();e.append(c);e=document.activeElement;(null!==x.$getSelection()||null!==e&&e===a.getRootElement())&&c.select()}},F);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,F);break;case "object":a.setEditorState(d,F);break;case "function":a.update(d,F)}}
|
|
12
|
+
function H(a){h.useEffect(()=>{const d=e=>{var c=a.getRootElement();if(document.activeElement===c&&(c=e.data,"string"===typeof c)){try{var b=JSON.parse(c)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,t,A,I]=b;a.update(()=>{const q=x.$getSelection();if(x.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;x.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
|
|
13
|
+
t)q.insertRawText(t),k=n.getNode();x.$isTextNode(k)&&(l=A,m=A+I,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
|
|
14
|
+
function J(a,d){y(()=>{const e=a.addListener("command",(c,b)=>{const f=x.$getSelection();if(!x.$isRangeSelection(f))return!1;switch(c){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(c=b.dataTransfer,null!=c?v.$insertDataTransferForPlainText(c,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
|
|
15
|
+
!0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(f,!0))return b.preventDefault(),w.$moveCharacter(f,c,!0),!0;break;case "keyArrowRight":c=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(f,!1))return b.preventDefault(),w.$moveCharacter(f,c,!1),!0;break;
|
|
16
|
+
case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return E(b,a),!0;case "cut":return D(b,a),!0;case "paste":return C(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);G(a,d);return e},[a]);H(a)}
|
|
17
|
+
module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=z(c);J(c,e);e=B(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
|