@lexical/link 0.3.8 → 0.3.11

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.
@@ -22,28 +22,64 @@ class LinkNode extends lexical.ElementNode {
22
22
  }
23
23
 
24
24
  static clone(node) {
25
- return new LinkNode(node.__url, node.__key);
25
+ return new LinkNode(node.__url, {
26
+ rel: node.__rel,
27
+ target: node.__target
28
+ }, node.__key);
26
29
  }
27
30
 
28
- constructor(url, key) {
31
+ constructor(url, attributes = {}, key) {
29
32
  super(key);
33
+ const {
34
+ target = null,
35
+ rel = null
36
+ } = attributes;
30
37
  this.__url = url;
38
+ this.__target = target;
39
+ this.__rel = rel;
31
40
  }
32
41
 
33
42
  createDOM(config) {
34
43
  const element = document.createElement('a');
35
44
  element.href = this.__url;
45
+
46
+ if (this.__target !== null) {
47
+ element.target = this.__target;
48
+ }
49
+
50
+ if (this.__rel !== null) {
51
+ element.rel = this.__rel;
52
+ }
53
+
36
54
  utils.addClassNamesToElement(element, config.theme.link);
37
55
  return element;
38
56
  }
39
57
 
40
58
  updateDOM(prevNode, anchor, config) {
41
59
  const url = this.__url;
60
+ const target = this.__target;
61
+ const rel = this.__rel;
42
62
 
43
63
  if (url !== prevNode.__url) {
44
64
  anchor.href = url;
45
65
  }
46
66
 
67
+ if (target !== prevNode.__target) {
68
+ if (target) {
69
+ anchor.target = target;
70
+ } else {
71
+ anchor.removeAttribute('target');
72
+ }
73
+ }
74
+
75
+ if (rel !== prevNode.__rel) {
76
+ if (rel) {
77
+ anchor.rel = rel;
78
+ } else {
79
+ anchor.removeAttribute('rel');
80
+ }
81
+ }
82
+
47
83
  return false;
48
84
  }
49
85
 
@@ -57,7 +93,10 @@ class LinkNode extends lexical.ElementNode {
57
93
  }
58
94
 
59
95
  static importJSON(serializedNode) {
60
- const node = $createLinkNode(serializedNode.url);
96
+ const node = $createLinkNode(serializedNode.url, {
97
+ rel: serializedNode.rel,
98
+ target: serializedNode.target
99
+ });
61
100
  node.setFormat(serializedNode.format);
62
101
  node.setIndent(serializedNode.indent);
63
102
  node.setDirection(serializedNode.direction);
@@ -66,6 +105,8 @@ class LinkNode extends lexical.ElementNode {
66
105
 
67
106
  exportJSON() {
68
107
  return { ...super.exportJSON(),
108
+ rel: this.getRel(),
109
+ target: this.getTarget(),
69
110
  type: 'link',
70
111
  url: this.getURL(),
71
112
  version: 1
@@ -81,11 +122,32 @@ class LinkNode extends lexical.ElementNode {
81
122
  writable.__url = url;
82
123
  }
83
124
 
125
+ getTarget() {
126
+ return this.getLatest().__target;
127
+ }
128
+
129
+ setTarget(target) {
130
+ const writable = this.getWritable();
131
+ writable.__target = target;
132
+ }
133
+
134
+ getRel() {
135
+ return this.getLatest().__rel;
136
+ }
137
+
138
+ setRel(rel) {
139
+ const writable = this.getWritable();
140
+ writable.__rel = rel;
141
+ }
142
+
84
143
  insertNewAfter(selection) {
85
144
  const element = this.getParentOrThrow().insertNewAfter(selection);
86
145
 
87
146
  if (lexical.$isElementNode(element)) {
88
- const linkNode = $createLinkNode(this.__url);
147
+ const linkNode = $createLinkNode(this.__url, {
148
+ rel: this.__rel,
149
+ target: this.__target
150
+ });
89
151
  element.append(linkNode);
90
152
  return linkNode;
91
153
  }
@@ -125,7 +187,10 @@ function convertAnchorElement(domNode) {
125
187
  let node = null;
126
188
 
127
189
  if (domNode instanceof HTMLAnchorElement) {
128
- node = $createLinkNode(domNode.getAttribute('href') || '');
190
+ node = $createLinkNode(domNode.getAttribute('href') || '', {
191
+ rel: domNode.getAttribute('rel'),
192
+ target: domNode.getAttribute('target')
193
+ });
129
194
  }
130
195
 
131
196
  return {
@@ -133,8 +198,8 @@ function convertAnchorElement(domNode) {
133
198
  };
134
199
  }
135
200
 
136
- function $createLinkNode(url) {
137
- return new LinkNode(url);
201
+ function $createLinkNode(url, attributes) {
202
+ return new LinkNode(url, attributes);
138
203
  }
139
204
  function $isLinkNode(node) {
140
205
  return node instanceof LinkNode;
@@ -147,11 +212,17 @@ class AutoLinkNode extends LinkNode {
147
212
  }
148
213
 
149
214
  static clone(node) {
150
- return new AutoLinkNode(node.__url, node.__key);
215
+ return new AutoLinkNode(node.__url, {
216
+ rel: node.__rel,
217
+ target: node.__target
218
+ }, node.__key);
151
219
  }
152
220
 
153
221
  static importJSON(serializedNode) {
154
- const node = $createAutoLinkNode(serializedNode.url);
222
+ const node = $createAutoLinkNode(serializedNode.url, {
223
+ rel: serializedNode.rel,
224
+ target: serializedNode.target
225
+ });
155
226
  node.setFormat(serializedNode.format);
156
227
  node.setIndent(serializedNode.indent);
157
228
  node.setDirection(serializedNode.direction);
@@ -174,7 +245,10 @@ class AutoLinkNode extends LinkNode {
174
245
  const element = this.getParentOrThrow().insertNewAfter(selection);
175
246
 
176
247
  if (lexical.$isElementNode(element)) {
177
- const linkNode = $createAutoLinkNode(this.__url);
248
+ const linkNode = $createAutoLinkNode(this.__url, {
249
+ rel: this._rel,
250
+ target: this.__target
251
+ });
178
252
  element.append(linkNode);
179
253
  return linkNode;
180
254
  }
@@ -183,121 +257,142 @@ class AutoLinkNode extends LinkNode {
183
257
  }
184
258
 
185
259
  }
186
- function $createAutoLinkNode(url) {
187
- return new AutoLinkNode(url);
260
+ function $createAutoLinkNode(url, attributes) {
261
+ return new AutoLinkNode(url, attributes);
188
262
  }
189
263
  function $isAutoLinkNode(node) {
190
264
  return node instanceof AutoLinkNode;
191
265
  }
192
266
  const TOGGLE_LINK_COMMAND = lexical.createCommand();
193
- function toggleLink(url) {
267
+ function toggleLink(url, attributes = {}) {
268
+ const {
269
+ target,
270
+ rel
271
+ } = attributes;
194
272
  const selection = lexical.$getSelection();
195
273
 
196
- if (selection !== null) {
197
- lexical.$setSelection(selection);
274
+ if (!lexical.$isRangeSelection(selection)) {
275
+ return;
198
276
  }
199
277
 
200
- const sel = lexical.$getSelection();
278
+ const nodes = selection.extract();
201
279
 
202
- if (sel !== null) {
203
- const nodes = sel.extract();
280
+ if (url === null) {
281
+ // Remove LinkNodes
282
+ nodes.forEach(node => {
283
+ const parent = node.getParent();
204
284
 
205
- if (url === null) {
206
- // Remove LinkNodes
207
- nodes.forEach(node => {
208
- const parent = node.getParent();
285
+ if ($isLinkNode(parent)) {
286
+ const children = parent.getChildren();
209
287
 
210
- if ($isLinkNode(parent)) {
211
- const children = parent.getChildren();
288
+ for (let i = 0; i < children.length; i++) {
289
+ parent.insertBefore(children[i]);
290
+ }
212
291
 
213
- for (let i = 0; i < children.length; i++) {
214
- parent.insertBefore(children[i]);
215
- }
292
+ parent.remove();
293
+ }
294
+ });
295
+ } else {
296
+ // Add or merge LinkNodes
297
+ if (nodes.length === 1) {
298
+ const firstNode = nodes[0]; // if the first node is a LinkNode or if its
299
+ // parent is a LinkNode, we update the URL, target and rel.
300
+
301
+ const linkNode = $isLinkNode(firstNode) ? firstNode : $getLinkAncestor(firstNode);
216
302
 
217
- parent.remove();
303
+ if (linkNode !== null) {
304
+ linkNode.setURL(url);
305
+
306
+ if (target !== undefined) {
307
+ linkNode.setTarget(target);
218
308
  }
219
- });
220
- } else {
221
- // Add or merge LinkNodes
222
- if (lexical.$isRangeSelection(sel) && sel.isCollapsed()) {
309
+
310
+ if (rel !== undefined) {
311
+ linkNode.setRel(rel);
312
+ }
313
+
223
314
  return;
224
315
  }
316
+ }
225
317
 
226
- if (nodes.length === 1) {
227
- const firstNode = nodes[0]; // if the first node is a LinkNode or if its
228
- // parent is a LinkNode, we update the URL.
318
+ let prevParent = null;
319
+ let linkNode = null;
320
+ nodes.forEach(node => {
321
+ const parent = node.getParent();
229
322
 
230
- if ($isLinkNode(firstNode)) {
231
- firstNode.setURL(url);
232
- return;
233
- } else {
234
- const parent = firstNode.getParent();
235
-
236
- if ($isLinkNode(parent)) {
237
- // set parent to be the current linkNode
238
- // so that other nodes in the same parent
239
- // aren't handled separately below.
240
- parent.setURL(url);
241
- return;
242
- }
243
- }
323
+ if (parent === linkNode || parent === null || lexical.$isElementNode(node) && !node.isInline()) {
324
+ return;
244
325
  }
245
326
 
246
- let prevParent = null;
247
- let linkNode = null;
248
- nodes.forEach(node => {
249
- const parent = node.getParent();
327
+ if ($isLinkNode(parent)) {
328
+ linkNode = parent;
329
+ parent.setURL(url);
250
330
 
251
- if (parent === linkNode || parent === null || lexical.$isElementNode(node) && !node.isInline()) {
252
- return;
331
+ if (target !== undefined) {
332
+ parent.setTarget(target);
253
333
  }
254
334
 
255
- if ($isLinkNode(parent)) {
256
- linkNode = parent;
257
- parent.setURL(url);
258
- return;
335
+ if (rel !== undefined) {
336
+ parent.setRel(rel);
259
337
  }
260
338
 
261
- if (!parent.is(prevParent)) {
262
- prevParent = parent;
263
- linkNode = $createLinkNode(url);
339
+ return;
340
+ }
341
+
342
+ if (!parent.is(prevParent)) {
343
+ prevParent = parent;
344
+ linkNode = $createLinkNode(url, {
345
+ rel,
346
+ target
347
+ });
264
348
 
265
- if ($isLinkNode(parent)) {
266
- if (node.getPreviousSibling() === null) {
267
- parent.insertBefore(linkNode);
268
- } else {
269
- parent.insertAfter(linkNode);
270
- }
349
+ if ($isLinkNode(parent)) {
350
+ if (node.getPreviousSibling() === null) {
351
+ parent.insertBefore(linkNode);
271
352
  } else {
272
- node.insertBefore(linkNode);
353
+ parent.insertAfter(linkNode);
273
354
  }
355
+ } else {
356
+ node.insertBefore(linkNode);
274
357
  }
358
+ }
275
359
 
276
- if ($isLinkNode(node)) {
277
- if (node.is(linkNode)) {
278
- return;
279
- }
280
-
281
- if (linkNode !== null) {
282
- const children = node.getChildren();
283
-
284
- for (let i = 0; i < children.length; i++) {
285
- linkNode.append(children[i]);
286
- }
287
- }
288
-
289
- node.remove();
360
+ if ($isLinkNode(node)) {
361
+ if (node.is(linkNode)) {
290
362
  return;
291
363
  }
292
364
 
293
365
  if (linkNode !== null) {
294
- linkNode.append(node);
366
+ const children = node.getChildren();
367
+
368
+ for (let i = 0; i < children.length; i++) {
369
+ linkNode.append(children[i]);
370
+ }
295
371
  }
296
- });
297
- }
372
+
373
+ node.remove();
374
+ return;
375
+ }
376
+
377
+ if (linkNode !== null) {
378
+ linkNode.append(node);
379
+ }
380
+ });
298
381
  }
299
382
  }
300
383
 
384
+ function $getLinkAncestor(node) {
385
+ return $getAncestor(node, ancestor => $isLinkNode(ancestor));
386
+ }
387
+
388
+ function $getAncestor(node, predicate) {
389
+ let parent = node;
390
+
391
+ while (parent !== null && (parent = parent.getParent()) !== null && !predicate(parent));
392
+
393
+ return parent;
394
+ }
395
+
301
396
  exports.$createAutoLinkNode = $createAutoLinkNode;
302
397
  exports.$createLinkNode = $createLinkNode;
303
398
  exports.$isAutoLinkNode = $isAutoLinkNode;
@@ -18,9 +18,18 @@ import {addClassNamesToElement} from '@lexical/utils';
18
18
  import {$isElementNode, ElementNode} from 'lexical';
19
19
  declare export class LinkNode extends ElementNode {
20
20
  __url: string;
21
+ __target: null | string;
22
+ __rel: null | string;
21
23
  static getType(): string;
22
24
  static clone(node: LinkNode): LinkNode;
23
- constructor(url: string, key?: NodeKey): void;
25
+ constructor(
26
+ url: string,
27
+ attributes?: {
28
+ rel?: null | string,
29
+ target?: null | string,
30
+ },
31
+ key?: NodeKey,
32
+ ): void;
24
33
  createDOM(config: EditorConfig): HTMLElement;
25
34
  updateDOM(
26
35
  prevNode: LinkNode,
@@ -30,13 +39,23 @@ declare export class LinkNode extends ElementNode {
30
39
  static importDOM(): DOMConversionMap | null;
31
40
  getURL(): string;
32
41
  setURL(url: string): void;
42
+ getTarget(): null | string;
43
+ setTarget(target: null | string): void;
44
+ getRel(): null | string;
45
+ setRel(rel: null | string): void;
33
46
  insertNewAfter(selection: RangeSelection): null | ElementNode;
34
47
  canInsertTextBefore(): false;
35
48
  canInsertTextAfter(): false;
36
49
  canBeEmpty(): false;
37
50
  isInline(): true;
38
51
  }
39
- declare export function $createLinkNode(url: string): LinkNode;
52
+ declare export function $createLinkNode(
53
+ url: string,
54
+ attributes?: {
55
+ rel?: null | string,
56
+ target?: null | string,
57
+ },
58
+ ): LinkNode;
40
59
  declare export function $isLinkNode(
41
60
  node: ?LexicalNode,
42
61
  ): boolean %checks(node instanceof LinkNode);
@@ -51,5 +70,17 @@ declare export function $isAutoLinkNode(
51
70
  node: ?LexicalNode,
52
71
  ): boolean %checks(node instanceof AutoLinkNode);
53
72
 
54
- declare export var TOGGLE_LINK_COMMAND: LexicalCommand<string | null>;
55
- declare export function toggleLink(url: null | string): void;
73
+ declare export var TOGGLE_LINK_COMMAND: LexicalCommand<
74
+ | string
75
+ | {
76
+ url: string,
77
+ target?: null | string,
78
+ rel?: null | string,
79
+ }
80
+ | null,
81
+ >;
82
+ declare export function toggleLink(
83
+ url: null | string,
84
+ target?: null | string,
85
+ rel?: null | string,
86
+ ): void;
@@ -4,11 +4,12 @@
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 g=require("@lexical/utils"),h=require("lexical");
8
- class l extends h.ElementNode{static getType(){return"link"}static clone(a){return new l(a.__url,a.__key)}constructor(a,b){super(b);this.__url=a}createDOM(a){let b=document.createElement("a");b.href=this.__url;g.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){let d=this.__url;d!==a.__url&&(b.href=d);return!1}static importDOM(){return{a:()=>({conversion:m,priority:1})}}static importJSON(a){let b=n(a.url);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),
9
- type:"link",url:this.getURL(),version:1}}getURL(){return this.getLatest().__url}setURL(a){this.getWritable().__url=a}insertNewAfter(a){a=this.getParentOrThrow().insertNewAfter(a);if(h.$isElementNode(a)){let b=n(this.__url);a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let d=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(d)&&
10
- 0<b.getTextContent().length}}function m(a){let b=null;a instanceof HTMLAnchorElement&&(b=n(a.getAttribute("href")||""));return{node:b}}function n(a){return new l(a)}function p(a){return a instanceof l}
11
- class r extends l{static getType(){return"autolink"}static clone(a){return new r(a.__url,a.__key)}static importJSON(a){let b=t(a.url);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){a=this.getParentOrThrow().insertNewAfter(a);if(h.$isElementNode(a)){let b=t(this.__url);a.append(b);return b}return null}}function t(a){return new r(a)}let u=h.createCommand();
12
- exports.$createAutoLinkNode=t;exports.$createLinkNode=n;exports.$isAutoLinkNode=function(a){return a instanceof r};exports.$isLinkNode=p;exports.AutoLinkNode=r;exports.LinkNode=l;exports.TOGGLE_LINK_COMMAND=u;
13
- exports.toggleLink=function(a){var b=h.$getSelection();null!==b&&h.$setSelection(b);var d=h.$getSelection();if(null!==d)if(b=d.extract(),null===a)b.forEach(c=>{c=c.getParent();if(p(c)){let e=c.getChildren();for(let k=0;k<e.length;k++)c.insertBefore(e[k]);c.remove()}});else if(!h.$isRangeSelection(d)||!d.isCollapsed()){if(1===b.length){d=b[0];if(p(d)){d.setURL(a);return}d=d.getParent();if(p(d)){d.setURL(a);return}}var q=null,f=null;b.forEach(c=>{var e=c.getParent();if(e!==f&&null!==e&&(!h.$isElementNode(c)||
14
- c.isInline()))if(p(e))f=e,e.setURL(a);else if(e.is(q)||(q=e,f=n(a),p(e)?null===c.getPreviousSibling()?e.insertBefore(f):e.insertAfter(f):c.insertBefore(f)),p(c)){if(!c.is(f)){if(null!==f){e=c.getChildren();for(let k=0;k<e.length;k++)f.append(e[k])}c.remove()}}else null!==f&&f.append(c)})}}
7
+ 'use strict';var l=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={},g){super(g);let {target:h=null,rel:d=null}=b;this.__url=a;this.__target=h;this.__rel=d}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);l.addClassNamesToElement(b,a.theme.link);return b}updateDOM(a,b){let g=this.__url,h=this.__target,d=this.__rel;
9
+ g!==a.__url&&(b.href=g);h!==a.__target&&(h?b.target=h:b.removeAttribute("target"));d!==a.__rel&&(d?b.rel=d: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){a=this.getParentOrThrow().insertNewAfter(a);if(m.$isElementNode(a)){let b=q(this.__url,{rel:this.__rel,target:this.__target});a.append(b);return b}return null}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(a,b){if(!m.$isRangeSelection(b))return!1;
11
+ a=b.anchor.getNode();let g=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(g)&&0<b.getTextContent().length}}function p(a){let b=null;a instanceof HTMLAnchorElement&&(b=q(a.getAttribute("href")||"",{rel:a.getAttribute("rel"),target:a.getAttribute("target")}));return{node:b}}function q(a,b){return 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){a=this.getParentOrThrow().insertNewAfter(a);if(m.$isElementNode(a)){let b=v(this.__url,{rel:this._rel,target:this.__target});
13
+ a.append(b);return b}return null}}function v(a,b){return new u(a,b)}let w=m.createCommand();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:g,rel:h}=b;b=m.$getSelection();if(m.$isRangeSelection(b))if(b=b.extract(),null===a)b.forEach(k=>{k=k.getParent();if(r(k)){let e=k.getChildren();for(let f=0;f<e.length;f++)k.insertBefore(e[f]);k.remove()}});else{if(1===b.length){var d=b[0];d=r(d)?d:x(d);if(null!==d){d.setURL(a);void 0!==g&&d.setTarget(g);void 0!==h&&d.setRel(h);return}}let k=null,e=null;b.forEach(f=>{var c=f.getParent();if(c!==e&&null!==c&&(!m.$isElementNode(f)||f.isInline()))if(r(c))e=
15
+ c,c.setURL(a),void 0!==g&&c.setTarget(g),void 0!==h&&c.setRel(h);else if(c.is(k)||(k=c,e=q(a,{rel:h,target:g}),r(c)?null===f.getPreviousSibling()?c.insertBefore(e):c.insertAfter(e):f.insertBefore(e)),r(f)){if(!f.is(e)){if(null!==e){c=f.getChildren();for(let t=0;t<c.length;t++)e.append(c[t])}f.remove()}}else null!==e&&e.append(f)})}}
package/index.d.ts CHANGED
@@ -10,13 +10,20 @@ import { ElementNode, Spread } from 'lexical';
10
10
  export declare type SerializedLinkNode = Spread<{
11
11
  type: 'link';
12
12
  url: string;
13
+ target?: null | string;
14
+ rel?: null | string;
13
15
  version: 1;
14
16
  }, SerializedElementNode>;
15
17
  export declare class LinkNode extends ElementNode {
16
18
  __url: string;
19
+ __target: null | string;
20
+ __rel: null | string;
17
21
  static getType(): string;
18
22
  static clone(node: LinkNode): LinkNode;
19
- constructor(url: string, key?: NodeKey);
23
+ constructor(url: string, attributes?: {
24
+ target?: null | string;
25
+ rel?: null | string;
26
+ }, key?: NodeKey);
20
27
  createDOM(config: EditorConfig): HTMLAnchorElement;
21
28
  updateDOM(prevNode: LinkNode, anchor: HTMLAnchorElement, config: EditorConfig): boolean;
22
29
  static importDOM(): DOMConversionMap | null;
@@ -24,6 +31,10 @@ export declare class LinkNode extends ElementNode {
24
31
  exportJSON(): SerializedLinkNode | SerializedAutoLinkNode;
25
32
  getURL(): string;
26
33
  setURL(url: string): void;
34
+ getTarget(): null | string;
35
+ setTarget(target: null | string): void;
36
+ getRel(): null | string;
37
+ setRel(rel: null | string): void;
27
38
  insertNewAfter(selection: RangeSelection): null | ElementNode;
28
39
  canInsertTextBefore(): false;
29
40
  canInsertTextAfter(): false;
@@ -31,7 +42,10 @@ export declare class LinkNode extends ElementNode {
31
42
  isInline(): true;
32
43
  extractWithChild(child: LexicalNode, selection: RangeSelection | NodeSelection | GridSelection, destination: 'clone' | 'html'): boolean;
33
44
  }
34
- export declare function $createLinkNode(url: string): LinkNode;
45
+ export declare function $createLinkNode(url: string, attributes?: {
46
+ target?: null | string;
47
+ rel?: null | string;
48
+ }): LinkNode;
35
49
  export declare function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode;
36
50
  export declare type SerializedAutoLinkNode = Spread<{
37
51
  type: 'autolink';
@@ -45,7 +59,17 @@ export declare class AutoLinkNode extends LinkNode {
45
59
  exportJSON(): SerializedAutoLinkNode;
46
60
  insertNewAfter(selection: RangeSelection): null | ElementNode;
47
61
  }
48
- export declare function $createAutoLinkNode(url: string): AutoLinkNode;
62
+ export declare function $createAutoLinkNode(url: string, attributes?: {
63
+ target?: null | string;
64
+ rel?: null | string;
65
+ }): AutoLinkNode;
49
66
  export declare function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode;
50
- export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | null>;
51
- export declare function toggleLink(url: null | string): void;
67
+ export declare const TOGGLE_LINK_COMMAND: LexicalCommand<string | {
68
+ url: string;
69
+ target?: string;
70
+ rel?: string;
71
+ } | null>;
72
+ export declare function toggleLink(url: null | string, attributes?: {
73
+ target?: null | string;
74
+ rel?: null | string;
75
+ }): void;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "link"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.3.8",
11
+ "version": "0.3.11",
12
12
  "main": "LexicalLink.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.3.8"
14
+ "lexical": "0.3.11"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.3.8"
17
+ "@lexical/utils": "0.3.11"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",