@indiebacklink/react
Advanced tools
Comparing version 0.0.1 to 0.0.2
import '../../assets/index.css'; | ||
import { jsxs as B, jsx as u } from "react/jsx-runtime"; | ||
import { useState as g, useRef as m, useCallback as P, useEffect as k } from "react"; | ||
import { s as H, i as _, g as F, a as T } from "../../api-f2792e02.js"; | ||
import { jsxs as W, jsx as u } from "react/jsx-runtime"; | ||
import { useState as w, useRef as m, useCallback as E, useEffect as g } from "react"; | ||
import { s as _, i as F, g as H, a as T } from "../../api-e9860dda.js"; | ||
import { ProductItem as V } from "../ProductItem/index.js"; | ||
import { cn as w } from "../../utils/cn.js"; | ||
import { cn as k } from "../../utils/cn.js"; | ||
import { getPageInfo as R } from "../../modules/page.js"; | ||
@@ -13,51 +13,52 @@ const U = ({ | ||
id: r, | ||
className: y, | ||
className: P, | ||
noBorder: x, | ||
noShadow: N, | ||
noTitle: L, | ||
openSelf: M, | ||
theme: c = "light", | ||
title: S = "Top products", | ||
maxProducts: z = 3, | ||
noTitle: O, | ||
openSelf: z, | ||
theme: s = "light", | ||
title: L = "Top products", | ||
maxProducts: M = 3, | ||
debug: o = !1 | ||
}) => { | ||
const [i, A] = g([]), [l, v] = g(!0), [O, a] = g(1), d = m(null), h = m([]), p = m(null), b = m(/* @__PURE__ */ new Set()), W = (e) => { | ||
r && T(r, e, R(), { debug: o }); | ||
}, f = P( | ||
(e) => { | ||
!b.current.has(e) && r && (H(r, e, R(), { debug: o }), b.current.add(e), o && console.log(`Impression sent for product ${e}`)); | ||
const [i, S] = w([]), [c, v] = w(!0), [A, l] = w(1), a = m(null), p = m([]), h = m(null), b = m(/* @__PURE__ */ new Set()), $ = (t) => { | ||
r && T(r, t, R(), { debug: o }); | ||
}, d = E( | ||
(t) => { | ||
!b.current.has(t) && r && (_(r, t, R(), { debug: o }), b.current.add(t), o && console.log(`Impression sent for product ${t}`)); | ||
}, | ||
[r, o] | ||
), I = P( | ||
(e) => { | ||
e.forEach((n) => { | ||
if (n.isIntersecting) { | ||
const t = n.target.getAttribute("data-product-id"); | ||
t && f(t); | ||
), I = E( | ||
(t) => { | ||
t.forEach((e) => { | ||
if (e.isIntersecting) { | ||
const n = e.target.getAttribute("data-product-id"); | ||
n && d(n); | ||
} | ||
}); | ||
}, | ||
[f] | ||
), $ = (e) => { | ||
const n = e.getBoundingClientRect(); | ||
return n.top >= -50 && n.left >= -50 && n.bottom <= (window.innerHeight || document.documentElement.clientHeight) + 50 && n.right <= (window.innerWidth || document.documentElement.clientWidth) + 50; | ||
[d] | ||
), j = (t) => { | ||
const e = t.getBoundingClientRect(); | ||
return e.top >= -50 && e.left >= -50 && e.bottom <= (typeof window < "u" ? window.innerHeight : 0) + 50 && e.right <= (typeof window < "u" ? window.innerWidth : 0) + 50; | ||
}; | ||
if (k(() => { | ||
v(!0), _({ id: r, debug: o }), F(r, { debug: o }).then(A).finally(() => v(!1)); | ||
}, [r, o]), k(() => { | ||
const e = () => { | ||
if (d.current) { | ||
const s = d.current.offsetWidth; | ||
s >= 1024 ? a(4) : s >= 768 ? a(3) : s >= 512 ? a(2) : a(1); | ||
if (g(() => { | ||
v(!0), F({ id: r, debug: o }), H(r, { debug: o }).then(S).finally(() => v(!1)); | ||
}, [r, o]), g(() => { | ||
const t = () => { | ||
if (a.current) { | ||
const e = a.current.offsetWidth; | ||
e >= 1024 ? l(4) : e >= 768 ? l(3) : e >= 512 ? l(2) : l(1); | ||
} | ||
}; | ||
e(); | ||
const n = new ResizeObserver(e), t = d.current; | ||
return t && n.observe(t), () => { | ||
t && n.unobserve(t); | ||
}; | ||
}, [l, o, i]), k(() => { | ||
if (l) | ||
if (t(), typeof ResizeObserver < "u") { | ||
const e = new ResizeObserver(t), n = a.current; | ||
return n && e.observe(n), () => { | ||
n && e.unobserve(n); | ||
}; | ||
} | ||
}, [c, o, i]), g(() => { | ||
if (c || typeof IntersectionObserver > "u") | ||
return; | ||
const e = { | ||
const t = { | ||
root: null, | ||
@@ -67,27 +68,27 @@ rootMargin: "50px", | ||
}; | ||
p.current = new IntersectionObserver(I, e), h.current.forEach((t) => { | ||
var s; | ||
t && ((s = p.current) == null || s.observe(t)); | ||
h.current = new IntersectionObserver(I, t), p.current.forEach((n) => { | ||
var f; | ||
n && ((f = h.current) == null || f.observe(n)); | ||
}); | ||
const n = () => { | ||
h.current.forEach((t, s) => { | ||
var E; | ||
if (t && $(t)) { | ||
const C = (E = i[s]) == null ? void 0 : E.id; | ||
C && f(C); | ||
const e = () => { | ||
p.current.forEach((n, f) => { | ||
var y; | ||
if (n && j(n)) { | ||
const C = (y = i[f]) == null ? void 0 : y.id; | ||
C && d(C); | ||
} | ||
}); | ||
}; | ||
return window.addEventListener("scroll", n), n(), () => { | ||
var t; | ||
(t = p.current) == null || t.disconnect(), window.removeEventListener("scroll", n); | ||
return typeof window < "u" && (window.addEventListener("scroll", e), e()), () => { | ||
var n; | ||
(n = h.current) == null || n.disconnect(), typeof window < "u" && window.removeEventListener("scroll", e); | ||
}; | ||
}, [i, l, I, f]), l || i.length === 0) | ||
}, [i, c, I, d]), c || i.length === 0) | ||
return null; | ||
const j = Math.max(1, Math.min(10, z)); | ||
return /* @__PURE__ */ B( | ||
const B = Math.max(1, Math.min(10, M)); | ||
return /* @__PURE__ */ W( | ||
"div", | ||
{ | ||
ref: d, | ||
className: w( | ||
ref: a, | ||
className: k( | ||
"indiebacklink", | ||
@@ -97,17 +98,17 @@ "w-full flex flex-col gap-4", | ||
!x && !N && "shadow-lg", | ||
c === "dark" && "bg-gray-800 border-gray-700", | ||
y | ||
s === "dark" && "bg-gray-800 border-gray-700", | ||
P | ||
), | ||
children: [ | ||
!L && /* @__PURE__ */ u("h3", { className: w("text-xl font-bold m-0", c === "dark" && "text-white"), children: S }), | ||
/* @__PURE__ */ u("div", { className: `grid gap-4 grid-cols-${O}`, children: i.slice(0, j).map((e, n) => /* @__PURE__ */ u( | ||
!O && /* @__PURE__ */ u("h3", { className: k("text-xl font-bold m-0", s === "dark" && "text-white"), children: L }), | ||
/* @__PURE__ */ u("div", { className: `grid gap-4 grid-cols-${A}`, children: i.slice(0, B).map((t, e) => /* @__PURE__ */ u( | ||
V, | ||
{ | ||
ref: (t) => h.current[n] = t, | ||
product: e, | ||
theme: c, | ||
target: M ? "_self" : "_blank", | ||
onClick: () => W(e.id) | ||
ref: (n) => p.current[e] = n, | ||
product: t, | ||
theme: s, | ||
target: z ? "_self" : "_blank", | ||
onClick: () => $(t.id) | ||
}, | ||
`indie-backlink-product-${e.id}` | ||
`indie-backlink-product-${t.id}` | ||
)) }), | ||
@@ -118,5 +119,5 @@ /* @__PURE__ */ u( | ||
href: "https://indiebacklink.com", | ||
className: w( | ||
className: k( | ||
"text-sm text-gray-500 dark:text-gray-400 m-0", | ||
c === "dark" && "text-white hover:text-[#AA8720]" | ||
s === "dark" && "text-white hover:text-[#AA8720]" | ||
), | ||
@@ -123,0 +124,0 @@ children: "IndieBacklink.com" |
import { Product } from "../types/product"; | ||
import { PageData } from "./page"; | ||
export declare const isLocal: boolean; | ||
export declare const API_BASE_URL: string; | ||
export declare const API_FINGERPRINT_PATH = "/api/v1/track/initialize"; | ||
@@ -6,0 +4,0 @@ export declare const API_PRODUCTS_PATH = "/api/v1/user-product/tracking"; |
@@ -1,14 +0,13 @@ | ||
import { A as P, n as A, k as I, m as i, l as _, g as e, o as n, j as o, a as r, s as S } from "../api-f2792e02.js"; | ||
import { l as i, A, k as I, j as _, g as e, m as r, a as n, s as t } from "../api-e9860dda.js"; | ||
import "../index-f43737ab.js"; | ||
export { | ||
P as API_BASE_URL, | ||
A as API_CLICKS_PATH, | ||
I as API_FINGERPRINT_PATH, | ||
i as API_IMPRESSIONS_PATH, | ||
i as API_CLICKS_PATH, | ||
A as API_FINGERPRINT_PATH, | ||
I as API_IMPRESSIONS_PATH, | ||
_ as API_PRODUCTS_PATH, | ||
e as getProducts, | ||
n as initializeFingerprintApi, | ||
o as isLocal, | ||
r as sendClick, | ||
S as sendImpression | ||
r as initializeFingerprintApi, | ||
n as sendClick, | ||
t as sendImpression | ||
}; | ||
//# sourceMappingURL=api.js.map |
@@ -1,2 +0,2 @@ | ||
import { f as n, b as t, h as a, d, e as F, i as g, c as s } from "../api-f2792e02.js"; | ||
import { f as n, b as t, h as a, d, e as F, i as g, c as s } from "../api-e9860dda.js"; | ||
import "./ip.js"; | ||
@@ -3,0 +3,0 @@ export { |
@@ -1,2 +0,9 @@ | ||
export type PageData = { | ||
import { z } from "zod"; | ||
export declare const PageDataSchema: z.ZodObject<{ | ||
url: z.ZodString; | ||
title: z.ZodString; | ||
pathname: z.ZodString; | ||
hostname: z.ZodString; | ||
protocol: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
url: string; | ||
@@ -7,3 +14,10 @@ title: string; | ||
protocol: string; | ||
}; | ||
}, { | ||
url: string; | ||
title: string; | ||
pathname: string; | ||
hostname: string; | ||
protocol: string; | ||
}>; | ||
export type PageData = z.infer<typeof PageDataSchema>; | ||
export declare function getPageInfo(): PageData; |
@@ -1,3 +0,19 @@ | ||
function n() { | ||
return { | ||
import { z as t } from "../index-f43737ab.js"; | ||
const n = t.object({ | ||
url: t.string(), | ||
title: t.string(), | ||
pathname: t.string(), | ||
hostname: t.string(), | ||
protocol: t.string() | ||
}); | ||
function a() { | ||
if (typeof window > "u") | ||
return { | ||
url: "", | ||
title: "", | ||
pathname: "", | ||
hostname: "", | ||
protocol: "" | ||
}; | ||
const o = { | ||
url: window.location.href, | ||
@@ -9,6 +25,8 @@ title: document.title, | ||
}; | ||
return n.parse(o); | ||
} | ||
export { | ||
n as getPageInfo | ||
n as PageDataSchema, | ||
a as getPageInfo | ||
}; | ||
//# sourceMappingURL=page.js.map |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "main": "dist/main.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34
9608
1428219
7