@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
- replaceWithChildren(previousSibling);
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"),l=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/utils"),q=require("lexical"),y=require("react");function z(b,f){for(let c=0;c<f.length;c++){let a=f[c](b);if(a)return a}return null}let A=/[.,;\s]/;function C(b){b=b.getPreviousSibling();q.$isElementNode(b)&&(b=b.getLastDescendant());var f;!(f=null===b||q.$isLineBreakNode(b))&&(f=q.$isTextNode(b))&&(b=b.getTextContent(),f=A.test(b[b.length-1]));return f}
8
- function D(b){b=b.getNextSibling();q.$isElementNode(b)&&(b=b.getFirstDescendant());return null===b||q.$isLineBreakNode(b)||q.$isTextNode(b)&&A.test(b.getTextContent()[0])}function E(b){let f=b.getChildren();var c=f.length;for(--c;0<=c;c--)b.insertAfter(f[c]);b.remove();return f.map(a=>a.getLatest())}
9
- function F(b,f,c){y.useEffect(()=>{if(!b.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.");return m.mergeRegister(b.registerNodeTransform(q.TextNode,a=>{var e=a.getParentOrThrow();if(h.$isAutoLinkNode(e))a:{a=e.getChildren();var d=a.length;for(var g=0;g<d;g++){var n=a[g];if(!q.$isTextNode(n)||!n.isSimpleText()){E(e);a=e.getURL();
10
- c&&c(null,a);break a}}d=e.getTextContent();a=z(d,f);null===a||a.text!==d?(E(e),a=e.getURL(),c&&c(null,a)):C(e)&&D(e)?(d=e.getURL(),d!==a.url&&(e.setURL(a.url),c&&c(a.url,d)),a.attributes&&(d=e.getRel(),d!==a.attributes.rel&&(e.setRel(a.attributes.rel||null),c&&c(a.attributes.rel||null,d)),d=e.getTarget(),d!==a.attributes.target&&(e.setTarget(a.attributes.target||null),c&&c(a.attributes.target||null,d)))):(E(e),a=e.getURL(),c&&c(null,a))}else if(!h.$isLinkNode(e)){if(a.isSimpleText()){n=e=a.getTextContent();
11
- let k=0,u=a;for(;(d=z(n,f))&&null!==d;){let r=d.index,v=d.length,w=r+v;var t=k+r,p=k+w,x=e,B=a;(0<t?A.test(x[t-1]):C(B))&&(p<x.length?A.test(x[p]):D(B))?(0===k+r?[g,u]=u.splitText(k+v):[,g,u]=u.splitText(k+r,k+r+v),t=h.$createAutoLinkNode(d.url,d.attributes),p=q.$createTextNode(d.text),p.setFormat(g.getFormat()),p.setDetail(g.getDetail()),t.append(p),g.replace(t),c&&c(d.url,null),k=0):k+=w;n=n.substring(w)}}g=a.getPreviousSibling();d=a.getNextSibling();a=a.getTextContent();h.$isAutoLinkNode(g)&&!A.test(a[0])&&
12
- (E(g),g=g.getURL(),c&&c(null,g));h.$isAutoLinkNode(d)&&!A.test(a[a.length-1])&&(E(d),a=d.getURL(),c&&c(null,a))}}))},[b,f,c])}exports.AutoLinkPlugin=function({matchers:b,onChange:f}){let [c]=l.useLexicalComposerContext();F(c,b,f);return null}
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 instanceof HTMLElement)) {
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 instanceof HTMLElement && (firstChild.tagName === 'UL' || firstChild.tagName === 'OL')) {
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 instanceof HTMLElement){var d=b.firstChild;null!=d&&d instanceof HTMLElement&&("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())}}
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}
@@ -23,6 +23,7 @@ export type Props = $ReadOnly<{
23
23
  ariaRequired?: HTMLDivElement['aria-required'],
24
24
  autoCapitalize?: HTMLDivElement['autocapitalize'],
25
25
  'data-testid'?: string | null,
26
+ ...
26
27
  }>;
27
28
 
28
29
  declare export function ContentEditable(props: Props): React$Node;
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.8.0",
11
+ "version": "0.8.1",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.8.0",
14
- "@lexical/code": "0.8.0",
15
- "@lexical/dragon": "0.8.0",
16
- "@lexical/hashtag": "0.8.0",
17
- "@lexical/history": "0.8.0",
18
- "@lexical/link": "0.8.0",
19
- "@lexical/list": "0.8.0",
20
- "@lexical/mark": "0.8.0",
21
- "@lexical/markdown": "0.8.0",
22
- "@lexical/overflow": "0.8.0",
23
- "@lexical/plain-text": "0.8.0",
24
- "@lexical/rich-text": "0.8.0",
25
- "@lexical/selection": "0.8.0",
26
- "@lexical/table": "0.8.0",
27
- "@lexical/text": "0.8.0",
28
- "@lexical/utils": "0.8.0",
29
- "@lexical/yjs": "0.8.0",
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.0",
33
+ "lexical": "0.8.1",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },