@lexical/link 0.26.0 → 0.27.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.
- package/LexicalLink.dev.js +7 -1
- package/LexicalLink.dev.mjs +7 -1
- package/LexicalLink.prod.js +1 -1
- package/LexicalLink.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalLink.dev.js
CHANGED
|
@@ -19,6 +19,12 @@ var lexical = require('lexical');
|
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
23
|
+
|
|
24
|
+
function formatDevErrorMessage(message) {
|
|
25
|
+
throw new Error(message);
|
|
26
|
+
}
|
|
27
|
+
|
|
22
28
|
const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
23
29
|
|
|
24
30
|
/** @noInheritDoc */
|
|
@@ -334,7 +340,7 @@ function $getPointNode(point, offset) {
|
|
|
334
340
|
if (point.type === 'element') {
|
|
335
341
|
const node = point.getNode();
|
|
336
342
|
if (!lexical.$isElementNode(node)) {
|
|
337
|
-
|
|
343
|
+
formatDevErrorMessage(`$getPointNode: element point is not an ElementNode`);
|
|
338
344
|
}
|
|
339
345
|
const childNode = node.getChildren()[point.offset + offset];
|
|
340
346
|
return childNode || null;
|
package/LexicalLink.dev.mjs
CHANGED
|
@@ -17,6 +17,12 @@ import { createCommand, ElementNode, $isRangeSelection, $applyNodeReplacement, $
|
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
21
|
+
|
|
22
|
+
function formatDevErrorMessage(message) {
|
|
23
|
+
throw new Error(message);
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
const SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
|
|
21
27
|
|
|
22
28
|
/** @noInheritDoc */
|
|
@@ -332,7 +338,7 @@ function $getPointNode(point, offset) {
|
|
|
332
338
|
if (point.type === 'element') {
|
|
333
339
|
const node = point.getNode();
|
|
334
340
|
if (!$isElementNode(node)) {
|
|
335
|
-
|
|
341
|
+
formatDevErrorMessage(`$getPointNode: element point is not an ElementNode`);
|
|
336
342
|
}
|
|
337
343
|
const childNode = node.getChildren()[point.offset + offset];
|
|
338
344
|
return childNode || null;
|
package/LexicalLink.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var t=require("@lexical/utils"),e=require("lexical");
|
|
9
|
+
"use strict";var t=require("@lexical/utils"),e=require("lexical");const r=new Set(["http:","https:","mailto:","sms:","tel:"]);class n extends e.ElementNode{static getType(){return"link"}static clone(t){return new n(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},r){super(r);const{target:n=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=s}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t.addClassNamesToElement(r,e.theme.link),r}updateDOM(e,r,n){if(t.isHTMLAnchorElement(r)){const t=this.__url,n=this.__target,i=this.__rel,s=this.__title;t!==e.__url&&(r.href=t),n!==e.__target&&(n?r.target=n:r.removeAttribute("target")),i!==e.__rel&&(i?r.rel=i:r.removeAttribute("rel")),s!==e.__title&&(s?r.title=s:r.removeAttribute("title"))}return!1}static importDOM(){return{a:t=>({conversion:i,priority:1})}}static importJSON(t){return s().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){try{const e=new URL(t);if(!r.has(e.protocol))return"about:blank"}catch(e){return t}return t}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const r=s(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,r,n){if(!e.$isRangeSelection(r))return!1;const i=r.anchor.getNode(),s=r.focus.getNode();return this.isParentOf(i)&&this.isParentOf(s)&&r.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function i(e){let r=null;if(t.isHTMLAnchorElement(e)){const t=e.textContent;(null!==t&&""!==t||e.children.length>0)&&(r=s(e.getAttribute("href")||"",{rel:e.getAttribute("rel"),target:e.getAttribute("target"),title:e.getAttribute("title")}))}return{node:r}}function s(t="",r){return e.$applyNodeReplacement(new n(t,r))}function l(t){return t instanceof n}class o extends n{constructor(t="",e={},r){super(t,e,r),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}static getType(){return"autolink"}static clone(t){return new o(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,r){return super.updateDOM(t,e,r)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return u().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,r=!0){const n=this.getParentOrThrow().insertNewAfter(t,r);if(e.$isElementNode(n)){const t=u(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return n.append(t),t}return null}}function u(t="",r){return e.$applyNodeReplacement(new o(t,r))}function a(t){return t instanceof o}const c=e.createCommand("TOGGLE_LINK_COMMAND");function _(t,r){if("element"===t.type){const n=t.getNode();e.$isElementNode(n)||function(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return n.getChildren()[t.offset+r]||null}return null}function g(r,n={}){const{target:i,title:o}=n,u=void 0===n.rel?"noreferrer":n.rel,c=e.$getSelection();if(!e.$isRangeSelection(c))return;const g=c.extract();if(null===r)return void g.forEach((e=>{const r=t.$findMatchingParent(e,(t=>!a(t)&&l(t)));if(r){const t=r.getChildren();for(let e=0;e<t.length;e++)r.insertBefore(t[e]);r.remove()}}));const h=new Set,f=t=>{h.has(t.getKey())||(h.add(t.getKey()),t.setURL(r),void 0!==i&&t.setTarget(i),void 0!==u&&t.setRel(u),void 0!==o&&t.setTitle(o))};if(1===g.length){const t=d(g[0],l);if(null!==t)return f(t)}!function(t){const r=e.$getSelection();if(!e.$isRangeSelection(r))return t();const n=e.$normalizeSelection__EXPERIMENTAL(r),i=n.isBackward(),s=_(n.anchor,i?-1:0),l=_(n.focus,i?0:-1),o=t();if(s||l){const t=e.$getSelection();if(e.$isRangeSelection(t)){const r=t.clone();if(s){const t=s.getParent();t&&r.anchor.set(t.getKey(),s.getIndexWithinParent()+(i?1:0),"element")}if(l){const t=l.getParent();t&&r.focus.set(t.getKey(),l.getIndexWithinParent()+(i?0:1),"element")}e.$setSelection(e.$normalizeSelection__EXPERIMENTAL(r))}}}((()=>{let t=null;for(const n of g){if(!n.isAttached())continue;const c=d(n,l);if(c){f(c);continue}if(e.$isElementNode(n)){if(!n.isInline())continue;if(l(n)){if(!(a(n)||null!==t&&t.getParentOrThrow().isParentOf(n))){f(n),t=n;continue}for(const t of n.getChildren())n.insertBefore(t);n.remove();continue}}const _=n.getPreviousSibling();l(_)&&_.is(t)?_.append(n):(t=s(r,{rel:u,target:i,title:o}),n.insertAfter(t),t.append(n))}}))}const h=g;function d(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}exports.$createAutoLinkNode=u,exports.$createLinkNode=s,exports.$isAutoLinkNode=a,exports.$isLinkNode=l,exports.$toggleLink=g,exports.AutoLinkNode=o,exports.LinkNode=n,exports.TOGGLE_LINK_COMMAND=c,exports.toggleLink=h;
|
package/LexicalLink.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{addClassNamesToElement as t,isHTMLAnchorElement as e,$findMatchingParent as r}from"@lexical/utils";import{createCommand as n,ElementNode as i,$isRangeSelection as
|
|
9
|
+
import{addClassNamesToElement as t,isHTMLAnchorElement as e,$findMatchingParent as r}from"@lexical/utils";import{createCommand as n,ElementNode as i,$isRangeSelection as s,$applyNodeReplacement as l,$isElementNode as o,$getSelection as u,$normalizeSelection__EXPERIMENTAL as a,$setSelection as _}from"lexical";const c=new Set(["http:","https:","mailto:","sms:","tel:"]);class h extends i{static getType(){return"link"}static clone(t){return new h(t.__url,{rel:t.__rel,target:t.__target,title:t.__title},t.__key)}constructor(t="",e={},r){super(r);const{target:n=null,rel:i=null,title:s=null}=e;this.__url=t,this.__target=n,this.__rel=i,this.__title=s}createDOM(e){const r=document.createElement("a");return r.href=this.sanitizeUrl(this.__url),null!==this.__target&&(r.target=this.__target),null!==this.__rel&&(r.rel=this.__rel),null!==this.__title&&(r.title=this.__title),t(r,e.theme.link),r}updateDOM(t,r,n){if(e(r)){const e=this.__url,n=this.__target,i=this.__rel,s=this.__title;e!==t.__url&&(r.href=e),n!==t.__target&&(n?r.target=n:r.removeAttribute("target")),i!==t.__rel&&(i?r.rel=i:r.removeAttribute("rel")),s!==t.__title&&(s?r.title=s:r.removeAttribute("title"))}return!1}static importDOM(){return{a:t=>({conversion:g,priority:1})}}static importJSON(t){return f().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setURL(t.url).setRel(t.rel||null).setTarget(t.target||null).setTitle(t.title||null)}sanitizeUrl(t){try{const e=new URL(t);if(!c.has(e.protocol))return"about:blank"}catch(e){return t}return t}exportJSON(){return{...super.exportJSON(),rel:this.getRel(),target:this.getTarget(),title:this.getTitle(),url:this.getURL()}}getURL(){return this.getLatest().__url}setURL(t){const e=this.getWritable();return e.__url=t,e}getTarget(){return this.getLatest().__target}setTarget(t){const e=this.getWritable();return e.__target=t,e}getRel(){return this.getLatest().__rel}setRel(t){const e=this.getWritable();return e.__rel=t,e}getTitle(){return this.getLatest().__title}setTitle(t){const e=this.getWritable();return e.__title=t,e}insertNewAfter(t,e=!0){const r=f(this.__url,{rel:this.__rel,target:this.__target,title:this.__title});return this.insertAfter(r,e),r}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}canBeEmpty(){return!1}isInline(){return!0}extractWithChild(t,e,r){if(!s(e))return!1;const n=e.anchor.getNode(),i=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(i)&&e.getTextContent().length>0}isEmailURI(){return this.__url.startsWith("mailto:")}isWebSiteURI(){return this.__url.startsWith("https://")||this.__url.startsWith("http://")}}function g(t){let r=null;if(e(t)){const e=t.textContent;(null!==e&&""!==e||t.children.length>0)&&(r=f(t.getAttribute("href")||"",{rel:t.getAttribute("rel"),target:t.getAttribute("target"),title:t.getAttribute("title")}))}return{node:r}}function f(t="",e){return l(new h(t,e))}function d(t){return t instanceof h}class p extends h{constructor(t="",e={},r){super(t,e,r),this.__isUnlinked=void 0!==e.isUnlinked&&null!==e.isUnlinked&&e.isUnlinked}static getType(){return"autolink"}static clone(t){return new p(t.__url,{isUnlinked:t.__isUnlinked,rel:t.__rel,target:t.__target,title:t.__title},t.__key)}getIsUnlinked(){return this.__isUnlinked}setIsUnlinked(t){const e=this.getWritable();return e.__isUnlinked=t,e}createDOM(t){return this.__isUnlinked?document.createElement("span"):super.createDOM(t)}updateDOM(t,e,r){return super.updateDOM(t,e,r)||t.__isUnlinked!==this.__isUnlinked}static importJSON(t){return m().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setIsUnlinked(t.isUnlinked||!1)}static importDOM(){return null}exportJSON(){return{...super.exportJSON(),isUnlinked:this.__isUnlinked}}insertNewAfter(t,e=!0){const r=this.getParentOrThrow().insertNewAfter(t,e);if(o(r)){const t=m(this.__url,{isUnlinked:this.__isUnlinked,rel:this.__rel,target:this.__target,title:this.__title});return r.append(t),t}return null}}function m(t="",e){return l(new p(t,e))}function U(t){return t instanceof p}const O=n("TOGGLE_LINK_COMMAND");function k(t,e){if("element"===t.type){const r=t.getNode();o(r)||function(t,...e){const r=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",t);for(const t of e)n.append("v",t);throw r.search=n.toString(),Error(`Minified Lexical error #${t}; visit ${r.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(252);return r.getChildren()[t.offset+e]||null}return null}function N(t,e={}){const{target:n,title:i}=e,l=void 0===e.rel?"noreferrer":e.rel,c=u();if(!s(c))return;const h=c.extract();if(null===t)return void h.forEach((t=>{const e=r(t,(t=>!U(t)&&d(t)));if(e){const t=e.getChildren();for(let r=0;r<t.length;r++)e.insertBefore(t[r]);e.remove()}}));const g=new Set,p=e=>{g.has(e.getKey())||(g.add(e.getKey()),e.setURL(t),void 0!==n&&e.setTarget(n),void 0!==l&&e.setRel(l),void 0!==i&&e.setTitle(i))};if(1===h.length){const t=S(h[0],d);if(null!==t)return p(t)}!function(t){const e=u();if(!s(e))return t();const r=a(e),n=r.isBackward(),i=k(r.anchor,n?-1:0),l=k(r.focus,n?0:-1),o=t();if(i||l){const t=u();if(s(t)){const e=t.clone();if(i){const t=i.getParent();t&&e.anchor.set(t.getKey(),i.getIndexWithinParent()+(n?1:0),"element")}if(l){const t=l.getParent();t&&e.focus.set(t.getKey(),l.getIndexWithinParent()+(n?0:1),"element")}_(a(e))}}}((()=>{let e=null;for(const r of h){if(!r.isAttached())continue;const s=S(r,d);if(s){p(s);continue}if(o(r)){if(!r.isInline())continue;if(d(r)){if(!(U(r)||null!==e&&e.getParentOrThrow().isParentOf(r))){p(r),e=r;continue}for(const t of r.getChildren())r.insertBefore(t);r.remove();continue}}const u=r.getPreviousSibling();d(u)&&u.is(e)?u.append(r):(e=f(t,{rel:l,target:n,title:i}),r.insertAfter(e),e.append(r))}}))}const x=N;function S(t,e){let r=t;for(;null!==r&&null!==r.getParent()&&!e(r);)r=r.getParentOrThrow();return e(r)?r:null}export{m as $createAutoLinkNode,f as $createLinkNode,U as $isAutoLinkNode,d as $isLinkNode,N as $toggleLink,p as AutoLinkNode,h as LinkNode,O as TOGGLE_LINK_COMMAND,x as toggleLink};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"link"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.27.0",
|
|
12
12
|
"main": "LexicalLink.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/utils": "0.
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/utils": "0.27.0",
|
|
16
|
+
"lexical": "0.27.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|