@yoopta/link 2.0.1 → 4.0.0-rc.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/dist/index.d.ts CHANGED
@@ -1,11 +1,4 @@
1
- import { YooEditor } from '@yoopta/editor';
2
- import { LinkElement } from './types';
3
- import { Link } from './ui/Link';
4
- declare module 'slate' {
5
- interface CustomTypes {
6
- Editor: YooEditor;
7
- Element: LinkElement;
8
- }
9
- }
1
+ import { Link } from './plugin';
2
+ import './styles.css';
10
3
  export default Link;
11
- export { LinkElement };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,cAAc,CAAC;AAQtB,eAAe,IAAI,CAAC"}
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(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};
1
+ import{YooptaPlugin as e}from"@yoopta/editor";import{jsx as t}from"react/jsx-runtime";const n=new e({type:"LinkPlugin",elements:{link:{render:e=>{const{url:n,target:r,rel:i}=e.element.props;return t("a",Object.assign({draggable:!1,href:n,rel:i,target:r,onClick:e=>{e.preventDefault()},className:"underline underline-offset-4 text-[#007AFF] hover:text-[#3b82f6]"},e.attributes,{children:e.children}))},props:{url:null,target:"_blank",rel:"noreferrer",nodeType:"inline"}}},options:{displayLabel:"Link"}});!function(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))}}(".inline{display:inline}.text-\\[\\#007AFF\\]{--tw-text-opacity:1;color:rgb(0 122 255/var(--tw-text-opacity))}.underline{text-decoration-line:underline}.underline-offset-4{text-underline-offset:4px}.hover\\:text-\\[\\#3b82f6\\]:hover{--tw-text-opacity:1;color:rgb(59 130 246/var(--tw-text-opacity))}");export{n as default};
@@ -0,0 +1,9 @@
1
+ import { YooptaPlugin } from '@yoopta/editor';
2
+ type LinkElementProps = {
3
+ url: string | null;
4
+ target?: string;
5
+ rel?: string;
6
+ };
7
+ declare const Link: YooptaPlugin<LinkElementProps, import("slate").Descendant, Record<string, unknown>>;
8
+ export { Link };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,QAAA,MAAM,IAAI,qFAgBR,CAAC;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,9 +1,2 @@
1
- import { Modify, YooptaBaseElement } from '@yoopta/editor';
2
- type LinkOptions = {
3
- url: null | string | undefined;
4
- skipDrag: boolean;
5
- };
6
- export type LinkElement = Modify<YooptaBaseElement<'link'>, {
7
- data: LinkOptions;
8
- }>;
9
1
  export {};
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { RenderElementProps } from 'slate-react';
3
+ declare const LinkRender: (props: RenderElementProps) => JSX.Element;
4
+ export { LinkRender };
5
+ //# sourceMappingURL=LinkRender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkRender.d.ts","sourceRoot":"","sources":["../../src/ui/LinkRender.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,QAAA,MAAM,UAAU,UAAW,kBAAkB,gBAoB5C,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoopta/link",
3
- "version": "2.0.1",
3
+ "version": "4.0.0-rc.0",
4
4
  "description": "> TODO: description",
5
5
  "author": "Darginec05 <devopsbanda@gmail.com>",
6
6
  "homepage": "https://github.com/Darginec05/Editor-Yoopta#readme",
@@ -14,7 +14,7 @@
14
14
  "dist/"
15
15
  ],
16
16
  "peerDependencies": {
17
- "@yoopta/editor": ">=1.9.18-rc",
17
+ "@yoopta/editor": ">=4.0.0-rc.0",
18
18
  "react": ">=17.0.2",
19
19
  "react-dom": ">=17.0.2",
20
20
  "slate": ">=0.72.3",
@@ -28,13 +28,12 @@
28
28
  "url": "git+https://github.com/Darginec05/Editor-Yoopta.git"
29
29
  },
30
30
  "scripts": {
31
- "test": "node ./__tests__/yoopta-code.test.js"
31
+ "test": "node ./__tests__/yoopta-link.test.js",
32
+ "start": "rollup --config rollup.config.js --watch --bundleConfigAsCjs --environment NODE_ENV:development",
33
+ "prepublishOnly": "yarn build",
34
+ "build": "rollup --config rollup.config.js --bundleConfigAsCjs --environment NODE_ENV:production"
32
35
  },
33
36
  "bugs": {
34
37
  "url": "https://github.com/Darginec05/Editor-Yoopta/issues"
35
- },
36
- "dependencies": {
37
- "is-url": "^1.2.4",
38
- "prismjs": "^1.29.0"
39
38
  }
40
39
  }
package/README.md DELETED
@@ -1,11 +0,0 @@
1
- # `@yoopta/code`
2
-
3
- > TODO: description
4
-
5
- ## Usage
6
-
7
- ```
8
- const blockquote = require('@yoopta/code');
9
-
10
- // TODO: DEMONSTRATE API
11
- ```
package/dist/ui/Link.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { LinkElement } from '../types';
2
- declare const Link: import("@yoopta/editor").YooptaPlugin<any, LinkElement>;
3
- export { Link, LinkElement };
@@ -1,5 +0,0 @@
1
- /// <reference types="react" />
2
- import { RenderYooptaElementProps } from '@yoopta/editor';
3
- import { LinkElement } from '../types';
4
- declare const LinkEditor: ({ attributes, element, children, HTMLAttributes }: RenderYooptaElementProps<LinkElement>) => JSX.Element;
5
- export { LinkEditor };
@@ -1,2 +0,0 @@
1
- import { YooEditor } from '@yoopta/editor';
2
- export declare const addLinkNode: (editor: YooEditor, url: string) => void;
@@ -1,2 +0,0 @@
1
- import { YooEditor } from '@yoopta/editor';
2
- export declare const removeLinkNode: (editor: YooEditor) => void;