@yoopta/link 1.9.0-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.
- package/README.md +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/ui/Link.d.ts +3 -0
- package/dist/ui/LinkEditor.d.ts +5 -0
- package/dist/utils/addLink.d.ts +2 -0
- package/dist/utils/removeLink.d.ts +2 -0
- package/package.json +40 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { YoEditor } from '@yoopta/editor';
|
|
2
|
+
import { LinkElement } from './types';
|
|
3
|
+
import { Link } from './ui/Link';
|
|
4
|
+
declare module 'slate' {
|
|
5
|
+
interface CustomTypes {
|
|
6
|
+
Editor: YoEditor;
|
|
7
|
+
Element: LinkElement;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export default Link;
|
|
11
|
+
export { LinkElement };
|
package/dist/index.js
ADDED
|
@@ -0,0 +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,createYoptaPlugin as c,getElementByPath as u}from"@yoopta/editor";import{useState as m,useEffect as p}from"react";var f=function(e){if("string"!=typeof e)return!1;var t=e.match(h);if(!t)return!1;var n=t[1];if(!n)return!1;if(v.test(n)||y.test(n))return!0;return!1},h=/^(?:\w+:)?\/\/(\S+)$/,v=/^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/,y=/^[^\s\.]+\.\S{2,}$/;const g=(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 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 k="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 N=({attributes:t,element:n,children:r})=>{const[i,o]=m(!1),[a,s]=m(!1);return p((()=>{const e=e=>{d.isCmd(e)&&s(!0)};return i&&(null===document||void 0===document||document.addEventListener("keydown",e)),()=>{null===document||void 0===document||document.removeEventListener("keydown",e)}}),[i,a]),e("a",Object.assign({draggable:!1},t,{href:n.data.url||"",rel:"noreferrer",target:"_blank",className:l(k,{[E]:a&&i}),onClick:e=>{var t;if(!(a&&"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:()=>o(!0),onMouseLeave:()=>{s(!1),o(!1)}},{children:r}))};var x="WX97Rghx";w(".WX97Rghx{color:#007aff;cursor:pointer;font-style:normal;font-weight:400;position:relative;text-decoration-line:underline}");const b=({attributes:t,element:n,children:r})=>e("a",Object.assign({draggable:!1},t,{href:n.data.url||"",rel:"noreferrer",target:"_blank",className:x,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")}},{children:r}));b.displayName="Link";const D="link",C=c({type:D,renderer:{editor:()=>N,render:b},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===D||a(e),e.normalizeNode=n=>{var i,a;const[l,d]=n;r.isElement(l)&&l.type===D&&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===D}),s(n)},e.insertText=t=>{t&&f(t)?g(e,t):i(t)},e.insertData=t=>{const r=t.getData("text/plain");r&&f(r)?g(e,r):n(t)},e},events:{onKeyDown:(e,{hotkeys:i})=>o=>{if(!e.selection)return;if(u(e,e.selection.anchor.path).type!==D)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===D});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===D})):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===D})))}if(i.isSpace(o)){const i=n.above(e,{match:t=>r.isElement(t)&&n.isInline(e,t)&&t.type===D,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{C as default};
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yoopta/link",
|
|
3
|
+
"version": "1.9.0-rc",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"author": "Darginec05 <devopsbanda@gmail.com>",
|
|
6
|
+
"homepage": "https://github.com/Darginec05/Editor-Yopta#readme",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"private": false,
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"module": "dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/"
|
|
15
|
+
],
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@yoopta/editor": "1.9.0-rc",
|
|
18
|
+
"react": ">=17.0.2",
|
|
19
|
+
"react-dom": ">=17.0.2",
|
|
20
|
+
"slate": ">=0.72.3",
|
|
21
|
+
"slate-react": ">=0.72.4"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.yarnpkg.com"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/Darginec05/Editor-Yopta.git"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "node ./__tests__/yoopta-code.test.js"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/Darginec05/Editor-Yopta/issues"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"is-url": "^1.2.4",
|
|
38
|
+
"prismjs": "^1.29.0"
|
|
39
|
+
}
|
|
40
|
+
}
|