@indiebacklink/react
Advanced tools
Comparing version 0.0.7 to 1.0.1
@@ -21,5 +21,7 @@ /// <reference types="react" /> | ||
direction?: "vertical" | "horizontal"; | ||
permanent?: boolean; | ||
owned?: boolean; | ||
debug?: boolean; | ||
}; | ||
export declare const IndieBacklink: ({ id, className, noBorder, noShadow, noTitle, openSelf, theme, title, maxProducts, maxColumns, direction, debug, }: IndieBacklinkProps) => JSX.Element | null; | ||
export declare const IndieBacklink: ({ id, className, noBorder, noShadow, noTitle, openSelf, theme, title, maxProducts, maxColumns, direction, permanent, owned, debug, }: IndieBacklinkProps) => JSX.Element | null; | ||
export default IndieBacklink; |
@@ -1,32 +0,34 @@ | ||
import { jsxs as _, jsx as w } from "react/jsx-runtime"; | ||
import { useLayoutEffect as D, useEffect as k, useState as b, useRef as c, useCallback as C } from "react"; | ||
import { s as H, i as V, g as q, a as J } from "../../api-cca55e3d.js"; | ||
import { ProductItem as K } from "../ProductItem/index.js"; | ||
import { jsxs as H, jsx as h } from "react/jsx-runtime"; | ||
import { useLayoutEffect as V, useEffect as k, useState as b, useRef as c, useCallback as N } from "react"; | ||
import { s as q, i as J, g as K, a as Q } from "../../api-a4c1a3f6.js"; | ||
import { ProductItem as U } from "../ProductItem/index.js"; | ||
import { cn as v } from "../../utils/cn.js"; | ||
import { getPageInfo as P } from "../../modules/page.js"; | ||
var h = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, Q = typeof h == "object" && h && h.Object === Object && h, U = typeof self == "object" && self && self.Object === Object && self; | ||
Q || U || Function("return this")(); | ||
var X = typeof window < "u" ? D : k; | ||
const oe = ({ | ||
import { getPageInfo as S } from "../../modules/page.js"; | ||
var w = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, X = typeof w == "object" && w && w.Object === Object && w, Y = typeof self == "object" && self && self.Object === Object && self; | ||
X || Y || Function("return this")(); | ||
var Z = typeof window < "u" ? V : k; | ||
const se = ({ | ||
id: r, | ||
className: N, | ||
className: A, | ||
noBorder: y, | ||
noShadow: S, | ||
noTitle: A, | ||
openSelf: M, | ||
noShadow: M, | ||
noTitle: T, | ||
openSelf: $, | ||
theme: l = "light", | ||
title: T = "Top products", | ||
maxProducts: $ = 3, | ||
title: B = "Top products", | ||
maxProducts: F = 3, | ||
maxColumns: f = 3, | ||
direction: x = "horizontal", | ||
permanent: I = !1, | ||
owned: E = !1, | ||
debug: o = !1 | ||
}) => { | ||
const [i, B] = b([]), [d, I] = b(!0), [F, s] = b(1), a = c(null), m = c([]), g = c(null), E = c(/* @__PURE__ */ new Set()), j = c(!1), z = Math.max(1, Math.min(10, $)), G = (t) => { | ||
r && J(r, t, P(), { debug: o }); | ||
}, u = C( | ||
const [i, G] = b([]), [a, j] = b(!0), [W, s] = b(1), d = c(null), m = c([]), g = c(null), z = c(/* @__PURE__ */ new Set()), O = c(!1), L = Math.max(1, Math.min(10, F)), _ = (t) => { | ||
r && Q(r, t, S(), { debug: o }); | ||
}, u = N( | ||
(t) => { | ||
!E.current.has(t) && r && (H(r, t, P(), { debug: o }), E.current.add(t), o && console.log(`Impression sent for product ${t}`)); | ||
!z.current.has(t) && r && (q(r, t, S(), { debug: o }), z.current.add(t), o && console.log(`Impression sent for product ${t}`)); | ||
}, | ||
[r, o] | ||
), O = C( | ||
), R = N( | ||
(t) => { | ||
@@ -41,3 +43,3 @@ t.forEach((e) => { | ||
[u] | ||
), W = (t) => { | ||
), D = (t) => { | ||
const e = t.getBoundingClientRect(); | ||
@@ -47,7 +49,7 @@ 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; | ||
return k(() => { | ||
I(!0), V({ id: r, debug: o }), q(r, { debug: o }).then(B).finally(() => I(!1)); | ||
}, [r, o]), k(() => { | ||
j(!0), J({ id: r, debug: o }), K(r, { permanent: I, owned: E, debug: o }).then(G).finally(() => j(!1)); | ||
}, [r, I, E, o]), k(() => { | ||
const t = () => { | ||
if (a.current) { | ||
const e = a.current.offsetWidth; | ||
if (d.current) { | ||
const e = d.current.offsetWidth; | ||
x === "horizontal" ? e >= 1024 && f >= 4 ? s(4) : e >= 768 && f >= 3 ? s(3) : e >= 512 && f >= 2 ? s(2) : s(1) : s(1); | ||
@@ -57,3 +59,3 @@ } | ||
if (t(), typeof ResizeObserver < "u") { | ||
const e = new ResizeObserver(t), n = a.current; | ||
const e = new ResizeObserver(t), n = d.current; | ||
return n && e.observe(n), () => { | ||
@@ -63,4 +65,4 @@ n && e.unobserve(n); | ||
} | ||
}, [d, o, i, f, x, z]), X(() => { | ||
if (d || typeof IntersectionObserver > "u") | ||
}, [a, o, i, f, x, L]), Z(() => { | ||
if (a || typeof IntersectionObserver > "u") | ||
return; | ||
@@ -72,3 +74,3 @@ const t = { | ||
}; | ||
g.current = new IntersectionObserver(O, t), m.current.forEach((n) => { | ||
g.current = new IntersectionObserver(R, t), m.current.forEach((n) => { | ||
var p; | ||
@@ -79,17 +81,17 @@ n && ((p = g.current) == null || p.observe(n)); | ||
m.current.forEach((n, p) => { | ||
var L; | ||
if (n && W(n)) { | ||
const R = (L = i[p]) == null ? void 0 : L.id; | ||
R && u(R); | ||
var C; | ||
if (n && D(n)) { | ||
const P = (C = i[p]) == null ? void 0 : C.id; | ||
P && u(P); | ||
} | ||
}); | ||
}; | ||
return typeof window < "u" && (window.addEventListener("scroll", e), window.addEventListener("resize", e), j.current || (e(), j.current = !0)), () => { | ||
return typeof window < "u" && (window.addEventListener("scroll", e), window.addEventListener("resize", e), O.current || (e(), O.current = !0)), () => { | ||
var n; | ||
(n = g.current) == null || n.disconnect(), typeof window < "u" && (window.removeEventListener("scroll", e), window.removeEventListener("resize", e)); | ||
}; | ||
}, [i, d, O, u]), d || i.length === 0 ? null : /* @__PURE__ */ _( | ||
}, [i, a, R, u]), a || i.length === 0 ? null : /* @__PURE__ */ H( | ||
"div", | ||
{ | ||
ref: a, | ||
ref: d, | ||
className: v( | ||
@@ -99,10 +101,10 @@ "indiebacklink", | ||
!y && "border border-gray-200 rounded-2xl p-4", | ||
!y && !S && "shadow-lg", | ||
!y && !M && "shadow-lg", | ||
l === "dark" && "bg-gray-800 border-gray-700", | ||
N | ||
A | ||
), | ||
children: [ | ||
!A && /* @__PURE__ */ w("h3", { className: v("text-xl font-bold m-0", l === "dark" && "text-white"), children: T }), | ||
/* @__PURE__ */ w("div", { className: `grid gap-4 grid-cols-${F}`, children: i.slice(0, z).map((t, e) => /* @__PURE__ */ w( | ||
K, | ||
!T && /* @__PURE__ */ h("h3", { className: v("text-xl font-bold m-0", l === "dark" && "text-white"), children: B }), | ||
/* @__PURE__ */ h("div", { className: `grid gap-4 grid-cols-${W}`, children: i.slice(0, L).map((t, e) => /* @__PURE__ */ h( | ||
U, | ||
{ | ||
@@ -112,8 +114,8 @@ ref: (n) => m.current[e] = n, | ||
theme: l, | ||
target: M ? "_self" : "_blank", | ||
onClick: () => G(t.id) | ||
target: $ ? "_self" : "_blank", | ||
onClick: () => _(t.id) | ||
}, | ||
`indie-backlink-product-${t.id}` | ||
)) }), | ||
/* @__PURE__ */ w( | ||
/* @__PURE__ */ h( | ||
"a", | ||
@@ -134,5 +136,5 @@ { | ||
export { | ||
oe as IndieBacklink, | ||
oe as default | ||
se as IndieBacklink, | ||
se as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,4 @@ import { Product } from "../types/product"; | ||
export declare function getProducts(id: string, options?: { | ||
permanent?: boolean; | ||
owned?: boolean; | ||
debug?: boolean; | ||
@@ -15,0 +17,0 @@ }): Promise<Product[]>; |
@@ -1,2 +0,2 @@ | ||
import { l as i, A, k as I, j as _, g as e, m as r, a as n, s as t } from "../api-cca55e3d.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-a4c1a3f6.js"; | ||
import "../index-f43737ab.js"; | ||
@@ -3,0 +3,0 @@ export { |
@@ -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-cca55e3d.js"; | ||
import { f as n, b as t, h as a, d, e as F, i as g, c as s } from "../api-a4c1a3f6.js"; | ||
import "./ip.js"; | ||
@@ -3,0 +3,0 @@ export { |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.0.7", | ||
"version": "1.0.1", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "main": "dist/main.js", |
@@ -53,4 +53,12 @@ # IndieBacklink React Component | ||
- `direction`: Layout direction, either `horizontal` (default) or `vertical`. | ||
- `permanent`: If `true`, the products will be displayed permanently (life-time). | ||
- `owned`: If `true`, the products will be displayed as owned by the current channel's user. | ||
- `debug`: If `true`, enables debug mode with additional console logging. | ||
## Examples | ||
```javascript | ||
<IndieBacklink id="TRACKINGID" maxProducts={5} direction="vertical" permanent /> | ||
``` | ||
## Development | ||
@@ -57,0 +65,0 @@ |
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
633409
5851
2
101