@dhaiwat10/react-link-preview
Advanced tools
Comparing version 1.12.2 to 1.13.1
@@ -25,2 +25,3 @@ import React from 'react'; | ||
explicitImageSrc?: string; | ||
showPlaceholderIfNoImage?: boolean; | ||
} | ||
@@ -27,0 +28,0 @@ export interface APIResponse { |
@@ -1,2 +0,2 @@ | ||
import e,{useRef as n,useState as t,useEffect as r}from"react";import o from"react-loading-skeleton";function i(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))}}i("/* 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");i(".skeleton-container {\n border-radius: 7px;\n border: 1px solid #eee; }\n\n.skeleton-lower-container {\n padding: 10px; }\n");var a=function(n){var t=n.width,r=void 0===t?"100%":t,i=n.imageHeight,a=void 0===i?"30vh":i,l=n.margin;return e.createElement("div",{className:"skeleton-container",style:{width:r,margin:l}},e.createElement(o,{width:r,height:a}),e.createElement("div",{className:"skeleton-lower-container"},e.createElement(o,{count:3})))},l="https://i.imgur.com/UeDNBNQ.jpeg";var c=function(o){var i=o.url,l=o.className,c=void 0===l?"":l,d=o.width,s=o.height,m=o.descriptionLength,u=o.borderRadius,p=o.imageHeight,h=o.textAlign,g=o.margin,f=o.fallback,v=void 0===f?null:f,b=o.backgroundColor,x=void 0===b?"white":b,y=o.primaryTextColor,N=void 0===y?"black":y,k=o.secondaryTextColor,w=void 0===k?"rgb(100, 100, 100)":k,E=o.borderColor,C=void 0===E?"#ccc":E,T=o.showLoader,S=void 0===T||T,L=o.customLoader,D=void 0===L?null:L,R=o.openInNewTab,I=void 0===R||R,B=o.fetcher,U=o.fallbackImageSrc,j=void 0===U?"https://i.imgur.com/UeDNBNQ.jpeg":U,A=o.explicitImageSrc,H=void 0===A?null:A,F=n(!0),Q=t(),_=Q[0],z=Q[1],W=t(!0),q=W[0],G=W[1];if(r((function(){return F.current=!0,G(!0),B?B(i).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="+i).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}}),[i,B]),q&&S)return D?e.createElement(e.Fragment,null,D):e.createElement(a,{width:d,imageHeight:p,margin:g});if(!_)return e.createElement(e.Fragment,null,v);var J=_.image,K=_.description,M=_.title,O=_.siteName,P=_.hostname;return e.createElement("div",{"data-testid":"container",onClick:function(){var e=I?"_blank":"_self";window.open(i,e)},className:"Container "+c,style:{width:d,height:s,borderRadius:u,textAlign:h,margin:g,backgroundColor:x,borderColor:C}},e.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:u,borderTopRightRadius:u,backgroundImage:"url("+(H||J||j)+"), url("+j+")",height:p},className:"Image"}),e.createElement("div",{className:"LowerContainer"},e.createElement("h3",{"data-testid":"title",className:"Title",style:{color:N}},M),K&&e.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:w}},m&&K.length>m?K.slice(0,m)+"...":K),e.createElement("div",{className:"Secondary SiteDetails",style:{color:w}},O&&e.createElement("span",null,O," • "),e.createElement("span",null,P))))};export{c as LinkPreview,l as placeholderImg}; | ||
import e,{useRef as n,useState as t,useEffect as r}from"react";import o from"react-loading-skeleton";function i(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))}}i("/* 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");i(".skeleton-container {\n border-radius: 7px;\n border: 1px solid #eee; }\n\n.skeleton-lower-container {\n padding: 10px; }\n");var a=function(n){var t=n.width,r=void 0===t?"100%":t,i=n.imageHeight,a=void 0===i?"30vh":i,l=n.margin;return e.createElement("div",{className:"skeleton-container",style:{width:r,margin:l}},e.createElement(o,{width:r,height:a}),e.createElement("div",{className:"skeleton-lower-container"},e.createElement(o,{count:3})))},l="https://i.imgur.com/UeDNBNQ.jpeg";var c=function(o){var i=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,N=o.primaryTextColor,w=void 0===N?"black":N,y=o.secondaryTextColor,k=void 0===y?"rgb(100, 100, 100)":y,E=o.borderColor,C=void 0===E?"#ccc":E,T=o.showLoader,S=void 0===T||T,I=o.customLoader,L=void 0===I?null:I,D=o.openInNewTab,R=void 0===D||D,B=o.fetcher,U=o.fallbackImageSrc,j=void 0===U?"https://i.imgur.com/UeDNBNQ.jpeg":U,A=o.explicitImageSrc,H=void 0===A?null:A,F=o.showPlaceholderIfNoImage,Q=void 0===F||F,_=n(!0),z=t(),P=z[0],W=z[1],q=t(!0),G=q[0],J=q[1];if(r((function(){return _.current=!0,J(!0),B?B(i).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)?W(null):W(e),J(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),_.current&&(W(null),J(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+i).then((function(e){return e.json()})).then((function(e){_.current&&(W(e.metadata),J(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),_.current&&(W(null),J(!1))})),function(){_.current=!1}}),[i,B]),G&&S)return L?e.createElement(e.Fragment,null,L):e.createElement(a,{width:d,imageHeight:h,margin:g});if(!P)return e.createElement(e.Fragment,null,v);var K=P.image,M=P.description,O=P.title,V=P.siteName,X=P.hostname;return e.createElement("div",{"data-testid":"container",onClick:function(){var e=R?"_blank":"_self";window.open(i,e)},className:"Container "+c,style:{width:d,height:s,borderRadius:u,textAlign:p,margin:g,backgroundColor:x,borderColor:C}},(K||j)&&Q&&e.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:u,borderTopRightRadius:u,backgroundImage:"url("+(H||K||j)+"), url("+j+")",height:h},className:"Image"}),e.createElement("div",{className:"LowerContainer"},e.createElement("h3",{"data-testid":"title",className:"Title",style:{color:w}},O),M&&e.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:k}},m&&M.length>m?M.slice(0,m)+"...":M),e.createElement("div",{className:"Secondary SiteDetails",style:{color:k}},V&&e.createElement("span",null,V," • "),e.createElement("span",null,X))))};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,u=t.borderRadius,s=t.imageHeight,m=t.textAlign,f=t.margin,p=t.fallback,h=void 0===p?null:p,g=t.backgroundColor,v=void 0===g?"white":g,b=t.primaryTextColor,x=void 0===b?"black":b,y=t.secondaryTextColor,k=void 0===y?"rgb(100, 100, 100)":y,w=t.borderColor,N=void 0===w?"#ccc":w,E=t.showLoader,C=void 0===E||E,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://i.imgur.com/UeDNBNQ.jpeg":I,B=t.explicitImageSrc,U=void 0===B?null:B,_=e.useRef(!0),A=e.useState(),H=A[0],q=A[1],F=e.useState(!0),P=F[0],Q=F[1];if(e.useEffect((function(){return _.current=!0,Q(!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),Q(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),_.current&&(q(null),Q(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+n).then((function(e){return e.json()})).then((function(e){_.current&&(q(e.metadata),Q(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),_.current&&(q(null),Q(!1))})),function(){_.current=!1}}),[n,D]),P&&C)return T?r.default.createElement(r.default.Fragment,null,T):r.default.createElement(i,{width:l,imageHeight:s,margin:f});if(!H)return r.default.createElement(r.default.Fragment,null,h);var z=H.image,M=H.description,O=H.title,W=H.siteName,G=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:u,textAlign:m,margin:f,backgroundColor:v,borderColor:N}},r.default.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:u,borderTopRightRadius:u,backgroundImage:"url("+(U||z||j)+"), url("+j+")",height:s},className:"Image"}),r.default.createElement("div",{className:"LowerContainer"},r.default.createElement("h3",{"data-testid":"title",className:"Title",style:{color:x}},O),M&&r.default.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:k}},c&&M.length>c?M.slice(0,c)+"...":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="https://i.imgur.com/UeDNBNQ.jpeg"; | ||
"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,p=t.fallback,h=void 0===p?null:p,g=t.backgroundColor,v=void 0===g?"white":g,b=t.primaryTextColor,x=void 0===b?"black":b,y=t.secondaryTextColor,w=void 0===y?"rgb(100, 100, 100)":y,N=t.borderColor,k=void 0===N?"#ccc":N,E=t.showLoader,C=void 0===E||E,S=t.customLoader,T=void 0===S?null:S,I=t.openInNewTab,L=void 0===I||I,R=t.fetcher,D=t.fallbackImageSrc,j=void 0===D?"https://i.imgur.com/UeDNBNQ.jpeg":D,B=t.explicitImageSrc,U=void 0===B?null:B,_=t.showPlaceholderIfNoImage,A=void 0===_||_,H=e.useRef(!0),P=e.useState(),q=P[0],F=P[1],Q=e.useState(!0),z=Q[0],M=Q[1];if(e.useEffect((function(){return H.current=!0,M(!0),R?R(n).then((function(e){H.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)?F(null):F(e),M(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),H.current&&(F(null),M(!1))})):fetch("https://rlp-proxy.herokuapp.com/v2?url="+n).then((function(e){return e.json()})).then((function(e){H.current&&(F(e.metadata),M(!1))})).catch((function(e){console.error(e),console.error("No metadata could be found for the given URL."),H.current&&(F(null),M(!1))})),function(){H.current=!1}}),[n,R]),z&&C)return T?r.default.createElement(r.default.Fragment,null,T):r.default.createElement(i,{width:l,imageHeight:u,margin:f});if(!q)return r.default.createElement(r.default.Fragment,null,h);var O=q.image,W=q.description,G=q.title,J=q.siteName,K=q.hostname;return r.default.createElement("div",{"data-testid":"container",onClick:function(){var e=L?"_blank":"_self";window.open(n,e)},className:"Container "+o,style:{width:l,height:d,borderRadius:s,textAlign:m,margin:f,backgroundColor:v,borderColor:k}},(O||j)&&A&&r.default.createElement("div",{"data-testid":"image-container",style:{borderTopLeftRadius:s,borderTopRightRadius:s,backgroundImage:"url("+(U||O||j)+"), url("+j+")",height:u},className:"Image"}),r.default.createElement("div",{className:"LowerContainer"},r.default.createElement("h3",{"data-testid":"title",className:"Title",style:{color:x}},G),W&&r.default.createElement("span",{"data-testid":"desc",className:"Description Secondary",style:{color:w}},c&&W.length>c?W.slice(0,c)+"...":W),r.default.createElement("div",{className:"Secondary SiteDetails",style:{color:w}},J&&r.default.createElement("span",null,J," • "),r.default.createElement("span",null,K))))},exports.placeholderImg="https://i.imgur.com/UeDNBNQ.jpeg"; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@dhaiwat10/react-link-preview", | ||
"license": "MIT", | ||
"version": "1.12.2", | ||
"version": "1.13.1", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "description": "React library to preview links.", |
@@ -178,2 +178,8 @@ # React Link Preview | ||
### `showPlaceholderIfNoImage?` (boolean) | ||
Whether the placeholder image is displayed in case no image could be scraped. | ||
___ | ||
Props marked with **?** are **optional**. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
38575
83
185