@dhaiwat10/react-link-preview
Advanced tools
Comparing version 1.10.1 to 1.11.0
import React from 'react'; | ||
import './linkPreview.scss'; | ||
export declare const placeholderImg = "https://raw.githubusercontent.com/Dhaiwat10/react-link-preview/master/src/assets/img-placeholder.jpg"; | ||
export interface LinkPreviewProps { | ||
@@ -4,0 +5,0 @@ url: string; |
@@ -1,2 +0,2 @@ | ||
import e,{useRef as n,useState as t,useEffect as r}from"react";import o from"react-loading-skeleton";function a(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}a("/* common */\n.Container {\n text-align: left;\n background-color: white;\n display: flex;\n flex-direction: column;\n border-radius: 7px;\n border: 1px solid #ccc;\n color: black;\n transition: 0.3s all ease;\n height: fit-content; }\n .Container:hover {\n background-color: #fafafa !important;\n cursor: pointer; }\n\n.Secondary {\n color: #646464; }\n\n.LowerContainer {\n padding: 10px; }\n\n.Title {\n margin-top: 0;\n margin-bottom: 10px; }\n\n.Image {\n width: 100%;\n border-top-left-radius: 7px;\n border-top-right-radius: 7px;\n background-size: cover;\n background-repeat: no-repeat;\n background-position: center;\n height: 30vh; }\n\n.SiteDetails {\n margin-top: 10px; }\n\n/* sm */\n@media (max-width: 640px) {\n .Description {\n display: none; } }\n\n/* md */\n@media (min-width: 641px) and (max-width: 768px) {\n .Description {\n display: none; } }\n");a(".skeleton-container {\n border-radius: 7px;\n border: 1px solid #eee; }\n\n.skeleton-lower-container {\n padding: 10px; }\n");var i=function(n){var t=n.width,r=void 0===t?"100%":t,a=n.imageHeight,i=void 0===a?"30vh":a,l=n.margin;return e.createElement("div",{className:"skeleton-container",style:{width:r,margin:l}},e.createElement(o,{width:r,height:i}),e.createElement("div",{className:"skeleton-lower-container"},e.createElement(o,{count:3})))};var l=function(o){var a=o.url,l=o.className,c=void 0===l?"":l,d=o.width,s=o.height,m=o.descriptionLength,u=o.borderRadius,h=o.imageHeight,p=o.textAlign,g=o.margin,f=o.fallback,v=void 0===f?null:f,b=o.backgroundColor,x=void 0===b?"white":b,w=o.primaryTextColor,k=void 0===w?"black":w,y=o.secondaryTextColor,E=void 0===y?"rgb(100, 100, 100)":y,N=o.borderColor,C=void 0===N?"#ccc":N,T=o.showLoader,L=void 0===T||T,S=o.customLoader,R=void 0===S?null:S,D=o.openInNewTab,I=void 0===D||D,A=o.fetcher,H=o.fallbackImageSrc,j=void 0===H?"https://raw.githubusercontent.com/Dhaiwat10/react-link-preview/master/src/assets/img-placeholder.jpg":H,B=n(!0),F=t(),U=F[0],_=F[1],z=t(!0),W=z[0],q=z[1];if(r((function(){return B.current=!0,q(!0),A?A(a).then((function(e){B.current&&(!function(e){return!!e&&null!==e.title&&null!==e.description&&null!==e.image&&null!==e.siteName&&null!==e.hostname&&void 0!==e.title&&void 0!==e.description&&void 0!==e.image&&void 0!==e.siteName&&void 0!==e.hostname&&"null"!==e.image&&!e.image.startsWith("/")}(e)?_(null):_(e),q(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),B.current&&(_(null),q(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+a).then((function(e){return e.json()})).then((function(e){B.current&&(_(e.metadata),q(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),B.current&&(_(null),q(!1))})),function(){B.current=!1}}),[a,A]),W&&L)return R?e.createElement(e.Fragment,null,R):e.createElement(i,{width:d,imageHeight:h,margin:g});if(!U)return e.createElement(e.Fragment,null,v);var G=U.image,J=U.description,K=U.title,M=U.siteName,O=U.hostname;return e.createElement("div",{"data-testid":"container",onClick:function(){var e=I?"_blank":"_self";window.open(a,e)},className:"Container "+c,style:{width:d,height:s,borderRadius:u,textAlign:p,margin:g,backgroundColor:x,borderColor:C}},e.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:u,borderTopRightRadius:u,backgroundImage:"url("+(G||j)+")",height:h},className:"Image"}),e.createElement("div",{className:"LowerContainer"},e.createElement("h3",{"data-testid":"title",className:"Title",style:{color:k}},K),J&&e.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:E}},m&&J.length>m?J.slice(0,m)+"...":J),e.createElement("div",{className:"Secondary SiteDetails",style:{color:E}},M&&e.createElement("span",null,M," • "),e.createElement("span",null,O))))};export{l as LinkPreview}; | ||
import e,{useRef as n,useState as t,useEffect as r}from"react";import o from"react-loading-skeleton";function a(e,n){void 0===n&&(n={});var t=n.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===t&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}a("/* common */\n.Container {\n text-align: left;\n background-color: white;\n display: flex;\n flex-direction: column;\n border-radius: 7px;\n border: 1px solid #ccc;\n color: black;\n transition: 0.3s all ease;\n height: fit-content; }\n .Container:hover {\n background-color: #fafafa !important;\n cursor: pointer; }\n\n.Secondary {\n color: #646464; }\n\n.LowerContainer {\n padding: 10px; }\n\n.Title {\n margin-top: 0;\n margin-bottom: 10px; }\n\n.Image {\n width: 100%;\n border-top-left-radius: 7px;\n border-top-right-radius: 7px;\n background-size: cover;\n background-repeat: no-repeat;\n background-position: center;\n height: 30vh; }\n\n.SiteDetails {\n margin-top: 10px; }\n\n/* sm */\n@media (max-width: 640px) {\n .Description {\n display: none; } }\n\n/* md */\n@media (min-width: 641px) and (max-width: 768px) {\n .Description {\n display: none; } }\n");a(".skeleton-container {\n border-radius: 7px;\n border: 1px solid #eee; }\n\n.skeleton-lower-container {\n padding: 10px; }\n");var i=function(n){var t=n.width,r=void 0===t?"100%":t,a=n.imageHeight,i=void 0===a?"30vh":a,l=n.margin;return e.createElement("div",{className:"skeleton-container",style:{width:r,margin:l}},e.createElement(o,{width:r,height:i}),e.createElement("div",{className:"skeleton-lower-container"},e.createElement(o,{count:3})))},l="https://raw.githubusercontent.com/Dhaiwat10/react-link-preview/master/src/assets/img-placeholder.jpg";var c=function(o){var a=o.url,c=o.className,d=void 0===c?"":c,s=o.width,m=o.height,u=o.descriptionLength,h=o.borderRadius,p=o.imageHeight,g=o.textAlign,f=o.margin,v=o.fallback,b=void 0===v?null:v,x=o.backgroundColor,w=void 0===x?"white":x,k=o.primaryTextColor,y=void 0===k?"black":k,E=o.secondaryTextColor,N=void 0===E?"rgb(100, 100, 100)":E,C=o.borderColor,T=void 0===C?"#ccc":C,L=o.showLoader,S=void 0===L||L,R=o.customLoader,D=void 0===R?null:R,I=o.openInNewTab,A=void 0===I||I,H=o.fetcher,j=o.fallbackImageSrc,B=void 0===j?l:j,F=n(!0),U=t(),_=U[0],z=U[1],W=t(!0),q=W[0],G=W[1];if(r((function(){return F.current=!0,G(!0),H?H(a).then((function(e){F.current&&(!function(e){return!!e&&null!==e.title&&null!==e.description&&null!==e.image&&null!==e.siteName&&null!==e.hostname&&void 0!==e.title&&void 0!==e.description&&void 0!==e.image&&void 0!==e.siteName&&void 0!==e.hostname&&"null"!==e.image&&!e.image.startsWith("/")}(e)?z(null):z(e),G(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),F.current&&(z(null),G(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+a).then((function(e){return e.json()})).then((function(e){F.current&&(z(e.metadata),G(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),F.current&&(z(null),G(!1))})),function(){F.current=!1}}),[a,H]),q&&S)return D?e.createElement(e.Fragment,null,D):e.createElement(i,{width:s,imageHeight:p,margin:f});if(!_)return e.createElement(e.Fragment,null,b);var J=_.image,K=_.description,M=_.title,O=_.siteName,P=_.hostname;return e.createElement("div",{"data-testid":"container",onClick:function(){var e=A?"_blank":"_self";window.open(a,e)},className:"Container "+d,style:{width:s,height:m,borderRadius:h,textAlign:g,margin:f,backgroundColor:w,borderColor:T}},e.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:h,borderTopRightRadius:h,backgroundImage:"url("+(J||B)+"), url("+B+")",height:p},className:"Image"}),e.createElement("div",{className:"LowerContainer"},e.createElement("h3",{"data-testid":"title",className:"Title",style:{color:y}},M),K&&e.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:N}},u&&K.length>u?K.slice(0,u)+"...":K),e.createElement("div",{className:"Secondary SiteDetails",style:{color:N}},O&&e.createElement("span",null,O," • "),e.createElement("span",null,P))))};export{c as LinkPreview,l as placeholderImg}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react-loading-skeleton");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e),a=n(t);function o(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===n&&r.firstChild?r.insertBefore(a,r.firstChild):r.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}o("/* common */\n.Container {\n text-align: left;\n background-color: white;\n display: flex;\n flex-direction: column;\n border-radius: 7px;\n border: 1px solid #ccc;\n color: black;\n transition: 0.3s all ease;\n height: fit-content; }\n .Container:hover {\n background-color: #fafafa !important;\n cursor: pointer; }\n\n.Secondary {\n color: #646464; }\n\n.LowerContainer {\n padding: 10px; }\n\n.Title {\n margin-top: 0;\n margin-bottom: 10px; }\n\n.Image {\n width: 100%;\n border-top-left-radius: 7px;\n border-top-right-radius: 7px;\n background-size: cover;\n background-repeat: no-repeat;\n background-position: center;\n height: 30vh; }\n\n.SiteDetails {\n margin-top: 10px; }\n\n/* sm */\n@media (max-width: 640px) {\n .Description {\n display: none; } }\n\n/* md */\n@media (min-width: 641px) and (max-width: 768px) {\n .Description {\n display: none; } }\n");o(".skeleton-container {\n border-radius: 7px;\n border: 1px solid #eee; }\n\n.skeleton-lower-container {\n padding: 10px; }\n");var i=function(e){var t=e.width,n=void 0===t?"100%":t,o=e.imageHeight,i=void 0===o?"30vh":o,l=e.margin;return r.default.createElement("div",{className:"skeleton-container",style:{width:n,margin:l}},r.default.createElement(a.default,{width:n,height:i}),r.default.createElement("div",{className:"skeleton-lower-container"},r.default.createElement(a.default,{count:3})))};exports.LinkPreview=function(t){var n=t.url,a=t.className,o=void 0===a?"":a,l=t.width,d=t.height,c=t.descriptionLength,s=t.borderRadius,u=t.imageHeight,m=t.textAlign,f=t.margin,h=t.fallback,p=void 0===h?null:h,g=t.backgroundColor,v=void 0===g?"white":g,b=t.primaryTextColor,x=void 0===b?"black":b,w=t.secondaryTextColor,y=void 0===w?"rgb(100, 100, 100)":w,k=t.borderColor,E=void 0===k?"#ccc":k,N=t.showLoader,C=void 0===N||N,S=t.customLoader,T=void 0===S?null:S,L=t.openInNewTab,R=void 0===L||L,D=t.fetcher,I=t.fallbackImageSrc,j=void 0===I?"https://raw.githubusercontent.com/Dhaiwat10/react-link-preview/master/src/assets/img-placeholder.jpg":I,_=e.useRef(!0),A=e.useState(),H=A[0],q=A[1],B=e.useState(!0),F=B[0],P=B[1];if(e.useEffect((function(){return _.current=!0,P(!0),D?D(n).then((function(e){_.current&&(!function(e){return!!e&&null!==e.title&&null!==e.description&&null!==e.image&&null!==e.siteName&&null!==e.hostname&&void 0!==e.title&&void 0!==e.description&&void 0!==e.image&&void 0!==e.siteName&&void 0!==e.hostname&&"null"!==e.image&&!e.image.startsWith("/")}(e)?q(null):q(e),P(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),_.current&&(q(null),P(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+n).then((function(e){return e.json()})).then((function(e){_.current&&(q(e.metadata),P(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),_.current&&(q(null),P(!1))})),function(){_.current=!1}}),[n,D]),F&&C)return T?r.default.createElement(r.default.Fragment,null,T):r.default.createElement(i,{width:l,imageHeight:u,margin:f});if(!H)return r.default.createElement(r.default.Fragment,null,p);var U=H.image,z=H.description,M=H.title,O=H.siteName,W=H.hostname;return r.default.createElement("div",{"data-testid":"container",onClick:function(){var e=R?"_blank":"_self";window.open(n,e)},className:"Container "+o,style:{width:l,height:d,borderRadius:s,textAlign:m,margin:f,backgroundColor:v,borderColor:E}},r.default.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:s,borderTopRightRadius:s,backgroundImage:"url("+(U||j)+")",height:u},className:"Image"}),r.default.createElement("div",{className:"LowerContainer"},r.default.createElement("h3",{"data-testid":"title",className:"Title",style:{color:x}},M),z&&r.default.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:y}},c&&z.length>c?z.slice(0,c)+"...":z),r.default.createElement("div",{className:"Secondary SiteDetails",style:{color:y}},O&&r.default.createElement("span",null,O," • "),r.default.createElement("span",null,W))))}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("react-loading-skeleton");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e),a=n(t);function o(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css","top"===n&&r.firstChild?r.insertBefore(a,r.firstChild):r.appendChild(a),a.styleSheet?a.styleSheet.cssText=e:a.appendChild(document.createTextNode(e))}}o("/* common */\n.Container {\n text-align: left;\n background-color: white;\n display: flex;\n flex-direction: column;\n border-radius: 7px;\n border: 1px solid #ccc;\n color: black;\n transition: 0.3s all ease;\n height: fit-content; }\n .Container:hover {\n background-color: #fafafa !important;\n cursor: pointer; }\n\n.Secondary {\n color: #646464; }\n\n.LowerContainer {\n padding: 10px; }\n\n.Title {\n margin-top: 0;\n margin-bottom: 10px; }\n\n.Image {\n width: 100%;\n border-top-left-radius: 7px;\n border-top-right-radius: 7px;\n background-size: cover;\n background-repeat: no-repeat;\n background-position: center;\n height: 30vh; }\n\n.SiteDetails {\n margin-top: 10px; }\n\n/* sm */\n@media (max-width: 640px) {\n .Description {\n display: none; } }\n\n/* md */\n@media (min-width: 641px) and (max-width: 768px) {\n .Description {\n display: none; } }\n");o(".skeleton-container {\n border-radius: 7px;\n border: 1px solid #eee; }\n\n.skeleton-lower-container {\n padding: 10px; }\n");var i=function(e){var t=e.width,n=void 0===t?"100%":t,o=e.imageHeight,i=void 0===o?"30vh":o,l=e.margin;return r.default.createElement("div",{className:"skeleton-container",style:{width:n,margin:l}},r.default.createElement(a.default,{width:n,height:i}),r.default.createElement("div",{className:"skeleton-lower-container"},r.default.createElement(a.default,{count:3})))},l="https://raw.githubusercontent.com/Dhaiwat10/react-link-preview/master/src/assets/img-placeholder.jpg";exports.LinkPreview=function(t){var n=t.url,a=t.className,o=void 0===a?"":a,d=t.width,c=t.height,s=t.descriptionLength,u=t.borderRadius,m=t.imageHeight,f=t.textAlign,h=t.margin,p=t.fallback,g=void 0===p?null:p,v=t.backgroundColor,b=void 0===v?"white":v,x=t.primaryTextColor,w=void 0===x?"black":x,y=t.secondaryTextColor,k=void 0===y?"rgb(100, 100, 100)":y,E=t.borderColor,N=void 0===E?"#ccc":E,C=t.showLoader,S=void 0===C||C,T=t.customLoader,L=void 0===T?null:T,R=t.openInNewTab,D=void 0===R||R,I=t.fetcher,j=t.fallbackImageSrc,_=void 0===j?l:j,A=e.useRef(!0),H=e.useState(),q=H[0],B=H[1],F=e.useState(!0),P=F[0],U=F[1];if(e.useEffect((function(){return A.current=!0,U(!0),I?I(n).then((function(e){A.current&&(!function(e){return!!e&&null!==e.title&&null!==e.description&&null!==e.image&&null!==e.siteName&&null!==e.hostname&&void 0!==e.title&&void 0!==e.description&&void 0!==e.image&&void 0!==e.siteName&&void 0!==e.hostname&&"null"!==e.image&&!e.image.startsWith("/")}(e)?B(null):B(e),U(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),A.current&&(B(null),U(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+n).then((function(e){return e.json()})).then((function(e){A.current&&(B(e.metadata),U(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),A.current&&(B(null),U(!1))})),function(){A.current=!1}}),[n,I]),P&&S)return L?r.default.createElement(r.default.Fragment,null,L):r.default.createElement(i,{width:d,imageHeight:m,margin:h});if(!q)return r.default.createElement(r.default.Fragment,null,g);var z=q.image,M=q.description,O=q.title,W=q.siteName,G=q.hostname;return r.default.createElement("div",{"data-testid":"container",onClick:function(){var e=D?"_blank":"_self";window.open(n,e)},className:"Container "+o,style:{width:d,height:c,borderRadius:u,textAlign:f,margin:h,backgroundColor:b,borderColor:N}},r.default.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:u,borderTopRightRadius:u,backgroundImage:"url("+(z||_)+"), url("+_+")",height:m},className:"Image"}),r.default.createElement("div",{className:"LowerContainer"},r.default.createElement("h3",{"data-testid":"title",className:"Title",style:{color:w}},O),M&&r.default.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:k}},s&&M.length>s?M.slice(0,s)+"...":M),r.default.createElement("div",{className:"Secondary SiteDetails",style:{color:k}},W&&r.default.createElement("span",null,W," • "),r.default.createElement("span",null,G))))},exports.placeholderImg=l; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dhaiwat10/react-link-preview", | ||
"license": "MIT", | ||
"version": "1.10.1", | ||
"version": "1.11.0", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "description": "React library to preview links.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37385
81