@yoopta/link 1.9.7-rc → 1.9.9-rc

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import{Transforms as t,Editor as n,Element as r,Range as i,Node as o}from"slate";import{isElementActive as a,generateId as s,cx as l,HOTKEYS as d,createYooptaPlugin as c,getElementByPath as u,getElementClassname as m}from"@yoopta/editor";import{useState as p,useEffect as f}from"react";var h=function(e){if("string"!=typeof e)return!1;var t=e.match(v);if(!t)return!1;var n=t[1];if(!n)return!1;if(y.test(n)||g.test(n))return!0;return!1},v=/^(?:\w+:)?\/\/(\S+)$/,y=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,g=/^[^\s\.]+\.\S{2,}$/;const w=(e,o)=>{a(e,"link")&&(e=>{t.unwrapNodes(e,{match:e=>!n.isEditor(e)&&r.isElement(e)&&"link"===e.type})})(e);const{selection:l}=e,d=l&&i.isCollapsed(l),c={id:s(),type:"link",data:{url:o},children:d?[{text:o}]:[],nodeType:"inline"};d?t.insertNodes(e,c):(t.wrapNodes(e,c,{split:!0}),t.collapse(e,{edge:"end"}))};function k(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var E="RvZCjRoG",N="BcbwmZV8";k(".RvZCjRoG{color:#007aff;cursor:text;font-style:normal;font-weight:400;position:relative;text-decoration-line:underline}.BcbwmZV8{cursor:pointer}");const b=({attributes:t,element:n,children:r,HTMLAttributes:i})=>{const[o,a]=p(!1),[s,c]=p(!1);return f((()=>{const e=e=>{d.isCmd(e)&&c(!0)};return o&&(null===document||void 0===document||document.addEventListener("keydown",e)),()=>{null===document||void 0===document||document.removeEventListener("keydown",e)}}),[o,s]),e("a",Object.assign({draggable:!1,href:n.data.url||"",rel:"noreferrer",target:"_blank",className:l(E,{[N]:s&&o}),onClick:e=>{var t;if(!(s&&"string"==typeof n.data.url&&(null===(t=n.data.url)||void 0===t?void 0:t.length)>0))return e.preventDefault();window.open(n.data.url,"_blank")},onMouseEnter:()=>a(!0),onMouseLeave:()=>{c(!1),a(!1)}},i,t,{children:r}))};var x="WX97Rghx";k(".WX97Rghx{color:#007aff;cursor:pointer;font-style:normal;font-weight:400;position:relative;text-decoration-line:underline}");const D=({attributes:t,element:n,children:r,HTMLAttributes:i})=>e("a",Object.assign({draggable:!1,href:n.data.url||"",rel:"noreferrer",target:"_blank",onClick:e=>{if(e.preventDefault(),!n.data.url)return;new URL(n.data.url).host===window.location.host?window.open(n.data.url,"_self"):window.open(n.data.url,"_blank")}},i,{className:m({element:n,HTMLAttributes:i,className:x})},t,{children:r}));D.displayName="Link";const C="link",T=c({type:C,renderer:{editor:()=>b,render:D},defineElement:()=>({id:s(),type:"link",children:[{text:""}],nodeType:"inline",data:{url:null,skipDrag:!0}}),extendEditor(e){const{insertData:n,insertText:i,isInline:a,normalizeNode:s}=e;return e.isInline=e=>e.type===C||a(e),e.normalizeNode=n=>{var i,a;const[l,d]=n;r.isElement(l)&&l.type===C&&l.children.length>0&&0===(null===(a=null===(i=o.child(l,0))||void 0===i?void 0:i.text)||void 0===a?void 0:a.length)&&t.removeNodes(e,{at:n[1],match:e=>r.isElement(e)&&e.type===C}),s(n)},e.insertText=t=>{t&&h(t)?w(e,t):i(t)},e.insertData=t=>{const r=t.getData("text/plain");r&&h(r)?w(e,r):n(t)},e},events:{onKeyDown:(e,{hotkeys:i})=>o=>{if(!e.selection)return;if(u(e,e.selection.anchor.path).type!==C)return;const{anchor:a}=e.selection;if(i.isEnter(o)){const i=n.isEnd(e,a,a.path),l=n.isStart(e,a,a.path);if(console.log({isStart:l}),l){o.preventDefault();const i=n.above(e,{match:e=>r.isElement(e)&&e.type===C});if(!i)return;const[,a]=i,l=n.parent(e,a),[,d]=l;return t.splitNodes(e,{match:e=>r.isElement(e),mode:"highest",always:!0}),void t.setNodes(e,{id:s()},{at:d,match:e=>r.isElement(e),mode:"highest"})}return i?(o.preventDefault(),n.insertBreak(e),t.setNodes(e,{id:s()}),void t.removeNodes(e,{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===C})):void(i||l||(o.preventDefault(),t.splitNodes(e),t.setNodes(e,{id:s()}),t.setNodes(e,{id:s()},{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===C})))}if(i.isSpace(o)){const i=n.above(e,{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===C,mode:"highest"});if(i){const[,r]=i;if(n.isEnd(e,a,r)){const i=n.after(e,r);t.setSelection(e,{anchor:i,focus:i})}}}else;}},exports:{markdown:{serialize:(e,t)=>`[${t}](${e.data.url})`},html:{serialize:(e,t)=>`<a target="_blank" rel="noopener noreferrer" href="${e.data.url}">${t}</a>`,deserialize:{nodeName:"A",parse:e=>({url:e.getAttribute("href"),skipDrag:!0})}}}});export{T as default};
1
+ import{jsx as e}from"react/jsx-runtime";import{Transforms as t,Editor as n,Element as r,Range as i,Node as o}from"slate";import{isElementActive as a,generateId as s,cx as l,HOTKEYS as d,createYooptaPlugin as c,getElementByPath as u,getElementClassname as m}from"@yoopta/editor";import{useState as p,useEffect as f}from"react";var h=function(e){if("string"!=typeof e)return!1;var t=e.match(v);if(!t)return!1;var n=t[1];if(!n)return!1;if(g.test(n)||y.test(n))return!0;return!1},v=/^(?:\w+:)?\/\/(\S+)$/,g=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,y=/^[^\s\.]+\.\S{2,}$/;const k=(e,o)=>{a(e,"link")&&(e=>{console.log("removeLinkNode editor selection",e.selection),t.unwrapNodes(e,{match:e=>!n.isEditor(e)&&r.isElement(e)&&"link"===e.type})})(e);const{selection:l}=e,d=l&&i.isCollapsed(l),c={id:s(),type:"link",data:{url:o,skipDrag:!0},children:d?[{text:o}]:[],nodeType:"inline"};d?t.insertNodes(e,c):(t.wrapNodes(e,c,{split:!0}),t.collapse(e,{edge:"end"}))};function w(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&r.firstChild?r.insertBefore(i,r.firstChild):r.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}var N="RvZCjRoG",E="BcbwmZV8";w(".RvZCjRoG{color:#007aff;cursor:text;font-style:normal;font-weight:400;position:relative;text-decoration-line:underline}.BcbwmZV8{cursor:pointer}");const b=({attributes:t,element:n,children:r,HTMLAttributes:i})=>{const[o,a]=p(!1),[s,c]=p(!1);return f((()=>{const e=e=>{d.isCmd(e)&&c(!0)};return o&&(null===document||void 0===document||document.addEventListener("keydown",e)),()=>{null===document||void 0===document||document.removeEventListener("keydown",e)}}),[o,s]),e("a",Object.assign({draggable:!1,href:n.data.url||"",rel:"noreferrer",target:"_blank",className:l(N,{[E]:s&&o}),onClick:e=>{var t;if(!(s&&"string"==typeof n.data.url&&(null===(t=n.data.url)||void 0===t?void 0:t.length)>0))return e.preventDefault();window.open(n.data.url,"_blank")},onMouseEnter:()=>a(!0),onMouseLeave:()=>{c(!1),a(!1)}},i,t,{children:r}))};var x="WX97Rghx";w(".WX97Rghx{color:#007aff;cursor:pointer;font-style:normal;font-weight:400;position:relative;text-decoration-line:underline}");const D=({attributes:t,element:n,children:r,HTMLAttributes:i})=>e("a",Object.assign({draggable:!1,href:n.data.url||"",rel:"noreferrer",target:"_blank",onClick:e=>{if(e.preventDefault(),!n.data.url)return;new URL(n.data.url).host===window.location.host?window.open(n.data.url,"_self"):window.open(n.data.url,"_blank")}},i,{className:m({element:n,HTMLAttributes:i,className:x})},t,{children:r}));D.displayName="Link";const C="link",T=c({type:C,renderer:{editor:()=>b,render:D},defineElement:()=>({id:s(),type:"link",children:[{text:""}],nodeType:"inline",data:{url:null,skipDrag:!0}}),extendEditor(e){const{insertData:n,insertText:i,isInline:a,normalizeNode:s}=e;return e.isInline=e=>e.type===C||a(e),e.normalizeNode=n=>{var i,a;const[l,d]=n;r.isElement(l)&&l.type===C&&l.children.length>0&&0===(null===(a=null===(i=o.child(l,0))||void 0===i?void 0:i.text)||void 0===a?void 0:a.length)&&t.removeNodes(e,{at:n[1],match:e=>r.isElement(e)&&e.type===C}),s(n)},e.insertText=t=>{t&&h(t)?k(e,t):i(t)},e.insertData=t=>{const r=t.getData("text/plain");r&&h(r)?k(e,r):n(t)},e},events:{onKeyDown:(e,{hotkeys:i})=>o=>{if(!e.selection)return;if(u(e,e.selection.anchor.path).type!==C)return;const{anchor:a}=e.selection;if(i.isEnter(o)){const i=n.isEnd(e,a,a.path),l=n.isStart(e,a,a.path);if(console.log({isStart:l}),l){o.preventDefault();const i=n.above(e,{match:e=>r.isElement(e)&&e.type===C});if(!i)return;const[,a]=i,l=n.parent(e,a),[,d]=l;return t.splitNodes(e,{match:e=>r.isElement(e),mode:"highest",always:!0}),void t.setNodes(e,{id:s()},{at:d,match:e=>r.isElement(e),mode:"highest"})}return i?(o.preventDefault(),n.insertBreak(e),t.setNodes(e,{id:s()}),void t.removeNodes(e,{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===C})):void(i||l||(o.preventDefault(),t.splitNodes(e),t.setNodes(e,{id:s()}),t.setNodes(e,{id:s()},{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===C})))}if(i.isSpace(o)){const i=n.above(e,{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===C,mode:"highest"});if(i){const[,r]=i;if(n.isEnd(e,a,r)){const i=n.after(e,r);t.setSelection(e,{anchor:i,focus:i})}}}else;}},exports:{markdown:{serialize:(e,t)=>`[${t}](${e.data.url})`},html:{serialize:(e,t)=>`<a target="_blank" rel="noopener noreferrer" href="${e.data.url}">${t}</a>`,deserialize:{nodeName:"A",parse:e=>({url:e.getAttribute("href"),skipDrag:!0})}}}});export{T as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoopta/link",
3
- "version": "1.9.7-rc",
3
+ "version": "1.9.9-rc",
4
4
  "description": "> TODO: description",
5
5
  "author": "Darginec05 <devopsbanda@gmail.com>",
6
6
  "homepage": "https://github.com/Darginec05/Editor-Yoopta#readme",