@lexical/link 0.9.1 → 0.10.0

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.
@@ -10,13 +10,16 @@ var utils = require('@lexical/utils');
10
10
  var lexical = require('lexical');
11
11
 
12
12
  /** @module @lexical/link */
13
-
13
+ const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
14
14
  /** @noInheritDoc */
15
+
15
16
  class LinkNode extends lexical.ElementNode {
16
17
  /** @internal */
17
18
 
18
19
  /** @internal */
19
20
 
21
+ /** @internal */
22
+
20
23
  /** @internal */
21
24
  static getType() {
22
25
  return 'link';
@@ -25,7 +28,8 @@ class LinkNode extends lexical.ElementNode {
25
28
  static clone(node) {
26
29
  return new LinkNode(node.__url, {
27
30
  rel: node.__rel,
28
- target: node.__target
31
+ target: node.__target,
32
+ title: node.__title
29
33
  }, node.__key);
30
34
  }
31
35
 
@@ -33,16 +37,18 @@ class LinkNode extends lexical.ElementNode {
33
37
  super(key);
34
38
  const {
35
39
  target = null,
36
- rel = null
40
+ rel = null,
41
+ title = null
37
42
  } = attributes;
38
43
  this.__url = url;
39
44
  this.__target = target;
40
45
  this.__rel = rel;
46
+ this.__title = title;
41
47
  }
42
48
 
43
49
  createDOM(config) {
44
50
  const element = document.createElement('a');
45
- element.href = this.__url;
51
+ element.href = this.sanitizeUrl(this.__url);
46
52
 
47
53
  if (this.__target !== null) {
48
54
  element.target = this.__target;
@@ -52,6 +58,10 @@ class LinkNode extends lexical.ElementNode {
52
58
  element.rel = this.__rel;
53
59
  }
54
60
 
61
+ if (this.__title !== null) {
62
+ element.title = this.__title;
63
+ }
64
+
55
65
  utils.addClassNamesToElement(element, config.theme.link);
56
66
  return element;
57
67
  }
@@ -60,6 +70,7 @@ class LinkNode extends lexical.ElementNode {
60
70
  const url = this.__url;
61
71
  const target = this.__target;
62
72
  const rel = this.__rel;
73
+ const title = this.__title;
63
74
 
64
75
  if (url !== prevNode.__url) {
65
76
  anchor.href = url;
@@ -81,6 +92,14 @@ class LinkNode extends lexical.ElementNode {
81
92
  }
82
93
  }
83
94
 
95
+ if (title !== prevNode.__title) {
96
+ if (title) {
97
+ anchor.title = title;
98
+ } else {
99
+ anchor.removeAttribute('title');
100
+ }
101
+ }
102
+
84
103
  return false;
85
104
  }
86
105
 
@@ -96,7 +115,8 @@ class LinkNode extends lexical.ElementNode {
96
115
  static importJSON(serializedNode) {
97
116
  const node = $createLinkNode(serializedNode.url, {
98
117
  rel: serializedNode.rel,
99
- target: serializedNode.target
118
+ target: serializedNode.target,
119
+ title: serializedNode.title
100
120
  });
101
121
  node.setFormat(serializedNode.format);
102
122
  node.setIndent(serializedNode.indent);
@@ -104,10 +124,25 @@ class LinkNode extends lexical.ElementNode {
104
124
  return node;
105
125
  }
106
126
 
127
+ sanitizeUrl(url) {
128
+ try {
129
+ const parsedUrl = new URL(url); // eslint-disable-next-line no-script-url
130
+
131
+ if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
132
+ return 'about:blank';
133
+ }
134
+ } catch (e) {
135
+ return 'https://';
136
+ }
137
+
138
+ return url;
139
+ }
140
+
107
141
  exportJSON() {
108
142
  return { ...super.exportJSON(),
109
143
  rel: this.getRel(),
110
144
  target: this.getTarget(),
145
+ title: this.getTitle(),
111
146
  type: 'link',
112
147
  url: this.getURL(),
113
148
  version: 1
@@ -141,13 +176,23 @@ class LinkNode extends lexical.ElementNode {
141
176
  writable.__rel = rel;
142
177
  }
143
178
 
179
+ getTitle() {
180
+ return this.getLatest().__title;
181
+ }
182
+
183
+ setTitle(title) {
184
+ const writable = this.getWritable();
185
+ writable.__title = title;
186
+ }
187
+
144
188
  insertNewAfter(selection, restoreSelection = true) {
145
189
  const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection);
146
190
 
147
191
  if (lexical.$isElementNode(element)) {
148
192
  const linkNode = $createLinkNode(this.__url, {
149
193
  rel: this.__rel,
150
- target: this.__target
194
+ target: this.__target,
195
+ title: this.__title
151
196
  });
152
197
  element.append(linkNode);
153
198
  return linkNode;
@@ -193,7 +238,8 @@ function convertAnchorElement(domNode) {
193
238
  if (content !== null && content !== '') {
194
239
  node = $createLinkNode(domNode.getAttribute('href') || '', {
195
240
  rel: domNode.getAttribute('rel'),
196
- target: domNode.getAttribute('target')
241
+ target: domNode.getAttribute('target'),
242
+ title: domNode.getAttribute('title')
197
243
  });
198
244
  }
199
245
  }
@@ -202,10 +248,23 @@ function convertAnchorElement(domNode) {
202
248
  node
203
249
  };
204
250
  }
251
+ /**
252
+ * Takes a URL and creates a LinkNode.
253
+ * @param url - The URL the LinkNode should direct to.
254
+ * @param attributes - Optional HTML a tag attributes { target, rel, title }
255
+ * @returns The LinkNode.
256
+ */
257
+
205
258
 
206
259
  function $createLinkNode(url, attributes) {
207
260
  return lexical.$applyNodeReplacement(new LinkNode(url, attributes));
208
261
  }
262
+ /**
263
+ * Determines if node is a LinkNode.
264
+ * @param node - The node to be checked.
265
+ * @returns true if node is a LinkNode, false otherwise.
266
+ */
267
+
209
268
  function $isLinkNode(node) {
210
269
  return node instanceof LinkNode;
211
270
  }
@@ -219,14 +278,16 @@ class AutoLinkNode extends LinkNode {
219
278
  static clone(node) {
220
279
  return new AutoLinkNode(node.__url, {
221
280
  rel: node.__rel,
222
- target: node.__target
281
+ target: node.__target,
282
+ title: node.__title
223
283
  }, node.__key);
224
284
  }
225
285
 
226
286
  static importJSON(serializedNode) {
227
287
  const node = $createAutoLinkNode(serializedNode.url, {
228
288
  rel: serializedNode.rel,
229
- target: serializedNode.target
289
+ target: serializedNode.target,
290
+ title: serializedNode.title
230
291
  });
231
292
  node.setFormat(serializedNode.format);
232
293
  node.setIndent(serializedNode.indent);
@@ -252,7 +313,8 @@ class AutoLinkNode extends LinkNode {
252
313
  if (lexical.$isElementNode(element)) {
253
314
  const linkNode = $createAutoLinkNode(this.__url, {
254
315
  rel: this._rel,
255
- target: this.__target
316
+ target: this.__target,
317
+ title: this.__title
256
318
  });
257
319
  element.append(linkNode);
258
320
  return linkNode;
@@ -262,16 +324,38 @@ class AutoLinkNode extends LinkNode {
262
324
  }
263
325
 
264
326
  }
327
+ /**
328
+ * Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
329
+ * during typing, which is especially useful when a button to generate a LinkNode is not practical.
330
+ * @param url - The URL the LinkNode should direct to.
331
+ * @param attributes - Optional HTML a tag attributes. { target, rel, title }
332
+ * @returns The LinkNode.
333
+ */
334
+
265
335
  function $createAutoLinkNode(url, attributes) {
266
336
  return lexical.$applyNodeReplacement(new AutoLinkNode(url, attributes));
267
337
  }
338
+ /**
339
+ * Determines if node is an AutoLinkNode.
340
+ * @param node - The node to be checked.
341
+ * @returns true if node is an AutoLinkNode, false otherwise.
342
+ */
343
+
268
344
  function $isAutoLinkNode(node) {
269
345
  return node instanceof AutoLinkNode;
270
346
  }
271
347
  const TOGGLE_LINK_COMMAND = lexical.createCommand('TOGGLE_LINK_COMMAND');
348
+ /**
349
+ * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
350
+ * but saves any children and brings them up to the parent node.
351
+ * @param url - The URL the link directs to.
352
+ * @param attributes - Optional HTML a tag attributes. { target, rel, title }
353
+ */
354
+
272
355
  function toggleLink(url, attributes = {}) {
273
356
  const {
274
- target
357
+ target,
358
+ title
275
359
  } = attributes;
276
360
  const rel = attributes.rel === undefined ? 'noopener' : attributes.rel;
277
361
  const selection = lexical.$getSelection();
@@ -316,6 +400,10 @@ function toggleLink(url, attributes = {}) {
316
400
  linkNode.setRel(rel);
317
401
  }
318
402
 
403
+ if (title !== undefined) {
404
+ linkNode.setTitle(title);
405
+ }
406
+
319
407
  return;
320
408
  }
321
409
  }
@@ -341,6 +429,10 @@ function toggleLink(url, attributes = {}) {
341
429
  linkNode.setRel(rel);
342
430
  }
343
431
 
432
+ if (title !== undefined) {
433
+ linkNode.setTitle(title);
434
+ }
435
+
344
436
  return;
345
437
  }
346
438
 
@@ -387,7 +479,7 @@ function toggleLink(url, attributes = {}) {
387
479
  }
388
480
 
389
481
  function $getLinkAncestor(node) {
390
- return $getAncestor(node, ancestor => $isLinkNode(ancestor));
482
+ return $getAncestor(node, $isLinkNode);
391
483
  }
392
484
 
393
485
  function $getAncestor(node, predicate) {
@@ -19,21 +19,16 @@ import {$isElementNode, ElementNode} from 'lexical';
19
19
  export type LinkAttributes = {
20
20
  rel?: null | string,
21
21
  target?: null | string,
22
+ title?: null | string,
22
23
  };
23
24
  declare export class LinkNode extends ElementNode {
24
25
  __url: string;
25
26
  __target: null | string;
26
27
  __rel: null | string;
28
+ __title: null | string;
27
29
  static getType(): string;
28
30
  static clone(node: LinkNode): LinkNode;
29
- constructor(
30
- url: string,
31
- attributes?: {
32
- rel?: null | string,
33
- target?: null | string,
34
- },
35
- key?: NodeKey,
36
- ): void;
31
+ constructor(url: string, attributes?: LinkAttributes, key?: NodeKey): void;
37
32
  createDOM(config: EditorConfig): HTMLElement;
38
33
  updateDOM(
39
34
  prevNode: LinkNode,
@@ -47,6 +42,8 @@ declare export class LinkNode extends ElementNode {
47
42
  setTarget(target: null | string): void;
48
43
  getRel(): null | string;
49
44
  setRel(rel: null | string): void;
45
+ getTitle(): null | string;
46
+ setTitle(title: null | string): void;
50
47
  insertNewAfter(
51
48
  selection: RangeSelection,
52
49
  restoreSelection?: boolean,
@@ -85,5 +82,5 @@ declare export var TOGGLE_LINK_COMMAND: LexicalCommand<
85
82
  >;
86
83
  declare export function toggleLink(
87
84
  url: null | string,
88
- attributes: {target?: null | string, rel?: null | string},
85
+ attributes: LinkAttributes,
89
86
  ): void;
@@ -4,12 +4,13 @@
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 k=require("@lexical/utils"),m=require("lexical");
8
- class n extends m.ElementNode{static getType(){return"link"}static clone(a){return new n(a.__url,{rel:a.__rel,target:a.__target},a.__key)}constructor(a,b={},c){super(c);let {target:h=null,rel:e=null}=b;this.__url=a;this.__target=h;this.__rel=e}createDOM(a){let b=document.createElement("a");b.href=this.__url;null!==this.__target&&(b.target=this.__target);null!==this.__rel&&(b.rel=this.__rel);k.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){let c=this.__url,h=this.__target,e=this.__rel;
9
- c!==a.__url&&(b.href=c);h!==a.__target&&(h?b.target=h:b.removeAttribute("target"));e!==a.__rel&&(e?b.rel=e:b.removeAttribute("rel"));return!1}static importDOM(){return{a:()=>({conversion:p,priority:1})}}static importJSON(a){let b=q(a.url,{rel:a.rel,target:a.target});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=
10
- a}getTarget(){return this.getLatest().__target}setTarget(a){this.getWritable().__target=a}getRel(){return this.getLatest().__rel}setRel(a){this.getWritable().__rel=a}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return m.$isElementNode(a)?(b=q(this.__url,{rel:this.__rel,target:this.__target}),a.append(b),b):null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!m.$isRangeSelection(b))return!1;a=b.anchor.getNode();
11
- let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&0<b.getTextContent().length}}function p(a){let b=null;if(k.isHTMLAnchorElement(a)){let c=a.textContent;null!==c&&""!==c&&(b=q(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target")}))}return{node:b}}function q(a,b){return m.$applyNodeReplacement(new n(a,b))}function r(a){return a instanceof n}
12
- class u extends n{static getType(){return"autolink"}static clone(a){return new u(a.__url,{rel:a.__rel,target:a.__target},a.__key)}static importJSON(a){let b=v(a.url,{rel:a.rel,target:a.target});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),type:"autolink",version:1}}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return m.$isElementNode(a)?(b=v(this.__url,{rel:this._rel,
13
- target:this.__target}),a.append(b),b):null}}function v(a,b){return m.$applyNodeReplacement(new u(a,b))}let w=m.createCommand("TOGGLE_LINK_COMMAND");function x(a){return y(a,b=>r(b))}function y(a,b){for(;null!==a&&null!==(a=a.getParent())&&!b(a););return a}exports.$createAutoLinkNode=v;exports.$createLinkNode=q;exports.$isAutoLinkNode=function(a){return a instanceof u};exports.$isLinkNode=r;exports.AutoLinkNode=u;exports.LinkNode=n;exports.TOGGLE_LINK_COMMAND=w;
14
- exports.toggleLink=function(a,b={}){let {target:c}=b,h=void 0===b.rel?"noopener":b.rel;b=m.$getSelection();if(m.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(l=>{l=l.getParent();if(r(l)){let d=l.getChildren();for(let f=0;f<d.length;f++)l.insertBefore(d[f]);l.remove()}});else{if(1===b.length){var e=b[0];e=r(e)?e:x(e);if(null!==e){e.setURL(a);void 0!==c&&e.setTarget(c);null!==h&&e.setRel(h);return}}let l=null,d=null;b.forEach(f=>{var g=f.getParent();if(g!==d&&null!==g&&(!m.$isElementNode(f)||
15
- f.isInline()))if(r(g))d=g,g.setURL(a),void 0!==c&&g.setTarget(c),null!==h&&d.setRel(h);else if(g.is(l)||(l=g,d=q(a,{rel:h,target:c}),r(g)?null===f.getPreviousSibling()?g.insertBefore(d):g.insertAfter(d):f.insertBefore(d)),r(f)){if(!f.is(d)){if(null!==d){g=f.getChildren();for(let t=0;t<g.length;t++)d.append(g[t])}f.remove()}}else null!==d&&d.append(f)})}}
7
+ 'use strict';var k=require("@lexical/utils"),n=require("lexical");let p=new Set(["http:","https:","mailto:","sms:","tel:"]);
8
+ class q extends n.ElementNode{static getType(){return"link"}static clone(a){return new q(a.__url,{rel:a.__rel,target:a.__target,title:a.__title},a.__key)}constructor(a,b={},d){super(d);let {target:l=null,rel:h=null,title:e=null}=b;this.__url=a;this.__target=l;this.__rel=h;this.__title=e}createDOM(a){let b=document.createElement("a");b.href=this.sanitizeUrl(this.__url);null!==this.__target&&(b.target=this.__target);null!==this.__rel&&(b.rel=this.__rel);null!==this.__title&&(b.title=this.__title);k.addClassNamesToElement(b,
9
+ a.theme.link);return b}updateDOM(a,b){let d=this.__url,l=this.__target,h=this.__rel,e=this.__title;d!==a.__url&&(b.href=d);l!==a.__target&&(l?b.target=l:b.removeAttribute("target"));h!==a.__rel&&(h?b.rel=h:b.removeAttribute("rel"));e!==a.__title&&(e?b.title=e:b.removeAttribute("title"));return!1}static importDOM(){return{a:()=>({conversion:r,priority:1})}}static importJSON(a){let b=t(a.url,{rel:a.rel,target:a.target,title:a.title});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);
10
+ return b}sanitizeUrl(a){try{let b=new URL(a);if(!p.has(b.protocol))return"about:blank"}catch(b){return"https://"}return a}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}getTarget(){return this.getLatest().__target}setTarget(a){this.getWritable().__target=a}getRel(){return this.getLatest().__rel}setRel(a){this.getWritable().__rel=
11
+ a}getTitle(){return this.getLatest().__title}setTitle(a){this.getWritable().__title=a}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return n.$isElementNode(a)?(b=t(this.__url,{rel:this.__rel,target:this.__target,title:this.__title}),a.append(b),b):null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!n.$isRangeSelection(b))return!1;a=b.anchor.getNode();let d=b.focus.getNode();return this.isParentOf(a)&&
12
+ this.isParentOf(d)&&0<b.getTextContent().length}}function r(a){let b=null;if(k.isHTMLAnchorElement(a)){let d=a.textContent;null!==d&&""!==d&&(b=t(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target"),title:a.getAttribute("title")}))}return{node:b}}function t(a,b){return n.$applyNodeReplacement(new q(a,b))}function v(a){return a instanceof q}
13
+ class w extends q{static getType(){return"autolink"}static clone(a){return new w(a.__url,{rel:a.__rel,target:a.__target,title:a.__title},a.__key)}static importJSON(a){let b=x(a.url,{rel:a.rel,target:a.target,title:a.title});b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),type:"autolink",version:1}}insertNewAfter(a,b=!0){a=this.getParentOrThrow().insertNewAfter(a,b);return n.$isElementNode(a)?
14
+ (b=x(this.__url,{rel:this._rel,target:this.__target,title:this.__title}),a.append(b),b):null}}function x(a,b){return n.$applyNodeReplacement(new w(a,b))}let y=n.createCommand("TOGGLE_LINK_COMMAND");function z(a,b){for(;null!==a&&null!==(a=a.getParent())&&!b(a););return a}exports.$createAutoLinkNode=x;exports.$createLinkNode=t;exports.$isAutoLinkNode=function(a){return a instanceof w};exports.$isLinkNode=v;exports.AutoLinkNode=w;exports.LinkNode=q;exports.TOGGLE_LINK_COMMAND=y;
15
+ exports.toggleLink=function(a,b={}){let {target:d,title:l}=b,h=void 0===b.rel?"noopener":b.rel;b=n.$getSelection();if(n.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(m=>{m=m.getParent();if(v(m)){let c=m.getChildren();for(let f=0;f<c.length;f++)m.insertBefore(c[f]);m.remove()}});else{if(1===b.length){var e=b[0];e=v(e)?e:z(e,v);if(null!==e){e.setURL(a);void 0!==d&&e.setTarget(d);null!==h&&e.setRel(h);void 0!==l&&e.setTitle(l);return}}let m=null,c=null;b.forEach(f=>{var g=f.getParent();if(g!==
16
+ c&&null!==g&&(!n.$isElementNode(f)||f.isInline()))if(v(g))c=g,g.setURL(a),void 0!==d&&g.setTarget(d),null!==h&&c.setRel(h),void 0!==l&&c.setTitle(l);else if(g.is(m)||(m=g,c=t(a,{rel:h,target:d}),v(g)?null===f.getPreviousSibling()?g.insertBefore(c):g.insertAfter(c):f.insertBefore(c)),v(f)){if(!f.is(c)){if(null!==c){g=f.getChildren();for(let u=0;u<g.length;u++)c.append(g[u])}f.remove()}}else null!==c&&c.append(f)})}}
package/index.d.ts CHANGED
@@ -11,11 +11,10 @@ import { ElementNode, Spread } from 'lexical';
11
11
  export declare type LinkAttributes = {
12
12
  rel?: null | string;
13
13
  target?: null | string;
14
+ title?: null | string;
14
15
  };
15
16
  export declare type SerializedLinkNode = Spread<{
16
- type: 'link';
17
17
  url: string;
18
- version: 1;
19
18
  }, Spread<LinkAttributes, SerializedElementNode>>;
20
19
  /** @noInheritDoc */
21
20
  export declare class LinkNode extends ElementNode {
@@ -25,6 +24,8 @@ export declare class LinkNode extends ElementNode {
25
24
  __target: null | string;
26
25
  /** @internal */
27
26
  __rel: null | string;
27
+ /** @internal */
28
+ __title: null | string;
28
29
  static getType(): string;
29
30
  static clone(node: LinkNode): LinkNode;
30
31
  constructor(url: string, attributes?: LinkAttributes, key?: NodeKey);
@@ -32,6 +33,7 @@ export declare class LinkNode extends ElementNode {
32
33
  updateDOM(prevNode: LinkNode, anchor: HTMLAnchorElement, config: EditorConfig): boolean;
33
34
  static importDOM(): DOMConversionMap | null;
34
35
  static importJSON(serializedNode: SerializedLinkNode | SerializedAutoLinkNode): LinkNode;
36
+ sanitizeUrl(url: string): string;
35
37
  exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
36
38
  getURL(): string;
37
39
  setURL(url: string): void;
@@ -39,6 +41,8 @@ export declare class LinkNode extends ElementNode {
39
41
  setTarget(target: null | string): void;
40
42
  getRel(): null | string;
41
43
  setRel(rel: null | string): void;
44
+ getTitle(): null | string;
45
+ setTitle(title: null | string): void;
42
46
  insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
43
47
  canInsertTextBefore(): false;
44
48
  canInsertTextAfter(): false;
@@ -46,12 +50,20 @@ export declare class LinkNode extends ElementNode {
46
50
  isInline(): true;
47
51
  extractWithChild(child: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection, destination: 'clone' | 'html'): boolean;
48
52
  }
53
+ /**
54
+ * Takes a URL and creates a LinkNode.
55
+ * @param url - The URL the LinkNode should direct to.
56
+ * @param attributes - Optional HTML a tag attributes { target, rel, title }
57
+ * @returns The LinkNode.
58
+ */
49
59
  export declare function $createLinkNode(url: string, attributes?: LinkAttributes): LinkNode;
60
+ /**
61
+ * Determines if node is a LinkNode.
62
+ * @param node - The node to be checked.
63
+ * @returns true if node is a LinkNode, false otherwise.
64
+ */
50
65
  export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
51
- export declare type SerializedAutoLinkNode = Spread<{
52
- type: 'autolink';
53
- version: 1;
54
- }, SerializedLinkNode>;
66
+ export declare type SerializedAutoLinkNode = SerializedLinkNode;
55
67
  export declare class AutoLinkNode extends LinkNode {
56
68
  static getType(): string;
57
69
  static clone(node: AutoLinkNode): AutoLinkNode;
@@ -60,9 +72,27 @@ export declare class AutoLinkNode extends LinkNode {
60
72
  exportJSON(): SerializedAutoLinkNode;
61
73
  insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ElementNode;
62
74
  }
75
+ /**
76
+ * Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
77
+ * during typing, which is especially useful when a button to generate a LinkNode is not practical.
78
+ * @param url - The URL the LinkNode should direct to.
79
+ * @param attributes - Optional HTML a tag attributes. { target, rel, title }
80
+ * @returns The LinkNode.
81
+ */
63
82
  export declare function $createAutoLinkNode(url: string, attributes?: LinkAttributes): AutoLinkNode;
83
+ /**
84
+ * Determines if node is an AutoLinkNode.
85
+ * @param node - The node to be checked.
86
+ * @returns true if node is an AutoLinkNode, false otherwise.
87
+ */
64
88
  export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
65
89
  export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | ({
66
90
  url: string;
67
91
  } & LinkAttributes) | null>;
92
+ /**
93
+ * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
94
+ * but saves any children and brings them up to the parent node.
95
+ * @param url - The URL the link directs to.
96
+ * @param attributes - Optional HTML a tag attributes. { target, rel, title }
97
+ */
68
98
  export declare function toggleLink(url: null | string, attributes?: LinkAttributes): void;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.9.1",
11
+ "version": "0.10.0",
12
12
  "main": "LexicalLink.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.9.1"
14
+ "lexical": "0.10.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.9.1"
17
+ "@lexical/utils": "0.10.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",