@lexical/react 0.8.0 → 0.8.1
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.
|
@@ -141,16 +141,18 @@ function handleLinkEdit(linkNode, matchers, onChange) {
|
|
|
141
141
|
|
|
142
142
|
// Bad neighbours are edits in neighbor nodes that make AutoLinks incompatible.
|
|
143
143
|
// Given the creation preconditions, these can only be simple text nodes.
|
|
144
|
-
function handleBadNeighbors(textNode, onChange) {
|
|
144
|
+
function handleBadNeighbors(textNode, matchers, onChange) {
|
|
145
145
|
const previousSibling = textNode.getPreviousSibling();
|
|
146
146
|
const nextSibling = textNode.getNextSibling();
|
|
147
147
|
const text = textNode.getTextContent();
|
|
148
148
|
if (link.$isAutoLinkNode(previousSibling) && !startsWithSeparator(text)) {
|
|
149
|
-
|
|
149
|
+
previousSibling.append(textNode);
|
|
150
|
+
handleLinkEdit(previousSibling, matchers, onChange);
|
|
150
151
|
onChange(null, previousSibling.getURL());
|
|
151
152
|
}
|
|
152
153
|
if (link.$isAutoLinkNode(nextSibling) && !endsWithSeparator(text)) {
|
|
153
154
|
replaceWithChildren(nextSibling);
|
|
155
|
+
handleLinkEdit(nextSibling, matchers, onChange);
|
|
154
156
|
onChange(null, nextSibling.getURL());
|
|
155
157
|
}
|
|
156
158
|
}
|
|
@@ -177,13 +179,14 @@ function useAutoLink(editor, matchers, onChange) {
|
|
|
177
179
|
};
|
|
178
180
|
return utils.mergeRegister(editor.registerNodeTransform(lexical.TextNode, textNode => {
|
|
179
181
|
const parent = textNode.getParentOrThrow();
|
|
182
|
+
const previous = textNode.getPreviousSibling();
|
|
180
183
|
if (link.$isAutoLinkNode(parent)) {
|
|
181
184
|
handleLinkEdit(parent, matchers, onChangeWrapped);
|
|
182
185
|
} else if (!link.$isLinkNode(parent)) {
|
|
183
|
-
if (textNode.isSimpleText()) {
|
|
186
|
+
if (textNode.isSimpleText() && (startsWithSeparator(textNode.getTextContent()) || !link.$isAutoLinkNode(previous))) {
|
|
184
187
|
handleLinkCreation(textNode, matchers, onChangeWrapped);
|
|
185
188
|
}
|
|
186
|
-
handleBadNeighbors(textNode, onChangeWrapped);
|
|
189
|
+
handleBadNeighbors(textNode, matchers, onChangeWrapped);
|
|
187
190
|
}
|
|
188
191
|
}));
|
|
189
192
|
}, [editor, matchers, onChange]);
|
|
@@ -4,9 +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
|
-
'use strict';var h=require("@lexical/link"),
|
|
8
|
-
function
|
|
9
|
-
function F(b,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(
|
|
7
|
+
'use strict';var h=require("@lexical/link"),n=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),u=require("lexical"),w=require("react");function A(a,b){for(let c=0;c<b.length;c++){let d=b[c](a);if(d)return d}return null}let B=/[.,;\s]/;function C(a){a=a.getPreviousSibling();u.$isElementNode(a)&&(a=a.getLastDescendant());var b;!(b=null===a||u.$isLineBreakNode(a))&&(b=u.$isTextNode(a))&&(a=a.getTextContent(),b=B.test(a[a.length-1]));return b}
|
|
8
|
+
function E(a){a=a.getNextSibling();u.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||u.$isLineBreakNode(a)||u.$isTextNode(a)&&B.test(a.getTextContent()[0])}
|
|
9
|
+
function F(a,b,c){var d=a.getChildren();let e=d.length;for(let f=0;f<e;f++){let l=d[f];if(!u.$isTextNode(l)||!l.isSimpleText()){G(a);c(null,a.getURL());return}}d=a.getTextContent();b=A(d,b);null===b||b.text!==d?(G(a),c(null,a.getURL())):C(a)&&E(a)?(d=a.getURL(),d!==b.url&&(a.setURL(b.url),c(b.url,d)),b.attributes&&(d=a.getRel(),d!==b.attributes.rel&&(a.setRel(b.attributes.rel||null),c(b.attributes.rel||null,d)),d=a.getTarget(),d!==b.attributes.target&&(a.setTarget(b.attributes.target||null),c(b.attributes.target||
|
|
10
|
+
null,d)))):(G(a),c(null,a.getURL()))}function G(a){let b=a.getChildren();var c=b.length;for(--c;0<=c;c--)a.insertAfter(b[c]);a.remove();return b.map(d=>d.getLatest())}
|
|
11
|
+
function H(a,b,c){w.useEffect(()=>{if(!a.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #77; visit https://lexical.dev/docs/error?code=77 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let d=(e,f)=>{c&&c(e,f)};return p.mergeRegister(a.registerNodeTransform(u.TextNode,e=>{var f=e.getParentOrThrow(),l=e.getPreviousSibling();if(h.$isAutoLinkNode(f))F(f,b,d);else if(!h.$isLinkNode(f)){if(e.isSimpleText()&&(B.test(e.getTextContent()[0])||
|
|
12
|
+
!h.$isAutoLinkNode(l))){l=f=e.getTextContent();let m=0,v=e;for(var g;(g=A(l,b))&&null!==g;){let r=g.index,x=g.length,y=r+x;var t=m+r,q=m+y,z=f,D=e;if((0<t?B.test(z[t-1]):C(D))&&(q<z.length?B.test(z[q]):E(D))){var k=void 0;0===m+r?[k,v]=v.splitText(m+x):[,k,v]=v.splitText(m+r,m+r+x);t=h.$createAutoLinkNode(g.url,g.attributes);q=u.$createTextNode(g.text);q.setFormat(k.getFormat());q.setDetail(k.getDetail());t.append(q);k.replace(t);c&&c(g.url,null);m=0}else m+=y;l=l.substring(y)}}f=e.getPreviousSibling();
|
|
13
|
+
g=e.getNextSibling();k=e.getTextContent();h.$isAutoLinkNode(f)&&!B.test(k[0])&&(f.append(e),F(f,b,d),e=f.getURL(),c&&c(null,e));h.$isAutoLinkNode(g)&&!B.test(k[k.length-1])&&(G(g),F(g,b,d),e=g.getURL(),c&&c(null,e))}}))},[a,b,c])}exports.AutoLinkPlugin=function({matchers:a,onChange:b}){let [c]=n.useLexicalComposerContext();H(c,a,b);return null}
|
|
@@ -93,13 +93,13 @@ function CheckListPlugin() {
|
|
|
93
93
|
}
|
|
94
94
|
function handleCheckItemEvent(event, callback) {
|
|
95
95
|
const target = event.target;
|
|
96
|
-
if (!(target
|
|
96
|
+
if (target === null || !utils.isHTMLElement(target)) {
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
// Ignore clicks on LI that have nested lists
|
|
101
101
|
const firstChild = target.firstChild;
|
|
102
|
-
if (firstChild != null && firstChild
|
|
102
|
+
if (firstChild != null && utils.isHTMLElement(firstChild) && (firstChild.tagName === 'UL' || firstChild.tagName === 'OL')) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
const parentNode = target.parentNode;
|
|
@@ -4,7 +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
|
-
'use strict';var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");function n(a,c){let b=a.target;if(b
|
|
7
|
+
'use strict';var e=require("@lexical/list"),g=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");function n(a,c){let b=a.target;if(null!==b&&k.isHTMLElement(b)){var d=b.firstChild;(null==d||!k.isHTMLElement(d)||"UL"!==d.tagName&&"OL"!==d.tagName)&&(d=b.parentNode)&&"check"===d.__lexicalListType&&(a=a.pageX,d=b.getBoundingClientRect(),("rtl"===b.dir?a<d.right&&a>d.right-20:a>d.left&&a<d.left+20)&&c())}}
|
|
8
8
|
function p(a){n(a,()=>{let c=a.target,b=q(c);null!=b&&b.isEditable()&&b.update(()=>{if(a.target){let d=l.$getNearestNodeFromDOMNode(c);e.$isListItemNode(d)&&(c.focus(),d.toggleChecked())}})})}function r(a){n(a,()=>{a.preventDefault()})}function q(a){for(;a;){if(a.__lexicalEditor)return a.__lexicalEditor;a=a.parentNode}return null}function t(){let a=document.activeElement;return null!=a&&"LI"===a.tagName&&null!=a.parentNode&&"check"===a.parentNode.__lexicalListType?a:null}
|
|
9
9
|
function u(a,c){let b=c?a.getPreviousSibling():a.getNextSibling();for(;null==b&&e.$isListItemNode(a);)a=a.getParentOrThrow().getParent(),null!=a&&(b=c?a.getPreviousSibling():a.getNextSibling());for(;e.$isListItemNode(b);){a=c?b.getLastChild():b.getFirstChild();if(!e.$isListNode(a))return b;b=c?a.getLastChild():a.getFirstChild()}return null}
|
|
10
10
|
function v(a,c,b){let d=t();null!=d&&c.update(()=>{var f=l.$getNearestNodeFromDOMNode(d);if(e.$isListItemNode(f)&&(f=u(f,b),null!=f)){f.selectStart();let h=c.getElementByKey(f.__key);null!=h&&(a.preventDefault(),setTimeout(()=>{h.focus()},0))}});return!1}
|
package/package.json
CHANGED
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"rich-text"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.8.
|
|
11
|
+
"version": "0.8.1",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@lexical/clipboard": "0.8.
|
|
14
|
-
"@lexical/code": "0.8.
|
|
15
|
-
"@lexical/dragon": "0.8.
|
|
16
|
-
"@lexical/hashtag": "0.8.
|
|
17
|
-
"@lexical/history": "0.8.
|
|
18
|
-
"@lexical/link": "0.8.
|
|
19
|
-
"@lexical/list": "0.8.
|
|
20
|
-
"@lexical/mark": "0.8.
|
|
21
|
-
"@lexical/markdown": "0.8.
|
|
22
|
-
"@lexical/overflow": "0.8.
|
|
23
|
-
"@lexical/plain-text": "0.8.
|
|
24
|
-
"@lexical/rich-text": "0.8.
|
|
25
|
-
"@lexical/selection": "0.8.
|
|
26
|
-
"@lexical/table": "0.8.
|
|
27
|
-
"@lexical/text": "0.8.
|
|
28
|
-
"@lexical/utils": "0.8.
|
|
29
|
-
"@lexical/yjs": "0.8.
|
|
13
|
+
"@lexical/clipboard": "0.8.1",
|
|
14
|
+
"@lexical/code": "0.8.1",
|
|
15
|
+
"@lexical/dragon": "0.8.1",
|
|
16
|
+
"@lexical/hashtag": "0.8.1",
|
|
17
|
+
"@lexical/history": "0.8.1",
|
|
18
|
+
"@lexical/link": "0.8.1",
|
|
19
|
+
"@lexical/list": "0.8.1",
|
|
20
|
+
"@lexical/mark": "0.8.1",
|
|
21
|
+
"@lexical/markdown": "0.8.1",
|
|
22
|
+
"@lexical/overflow": "0.8.1",
|
|
23
|
+
"@lexical/plain-text": "0.8.1",
|
|
24
|
+
"@lexical/rich-text": "0.8.1",
|
|
25
|
+
"@lexical/selection": "0.8.1",
|
|
26
|
+
"@lexical/table": "0.8.1",
|
|
27
|
+
"@lexical/text": "0.8.1",
|
|
28
|
+
"@lexical/utils": "0.8.1",
|
|
29
|
+
"@lexical/yjs": "0.8.1",
|
|
30
30
|
"react-error-boundary": "^3.1.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"lexical": "0.8.
|
|
33
|
+
"lexical": "0.8.1",
|
|
34
34
|
"react": ">=17.x",
|
|
35
35
|
"react-dom": ">=17.x"
|
|
36
36
|
},
|