@siteping/widget 0.10.2 → 0.10.4

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.
@@ -0,0 +1,59 @@
1
+ import { SitepingConfig, SitepingInstance } from './siteping-core.cjs';
2
+
3
+ /**
4
+ * React helper for `@siteping/widget`.
5
+ *
6
+ * `useSiteping` initialises the widget once for the lifetime of the component
7
+ * tree, even under React.StrictMode's double-invoke effect dance. Returns the
8
+ * `SitepingInstance` so consumers can drive `open()` / `close()` / `refresh()`
9
+ * programmatically from anywhere in their tree.
10
+ *
11
+ * Why a dedicated entry instead of a snippet in the README:
12
+ * - StrictMode mounts every effect twice in dev, which the obvious
13
+ * `useEffect(() => { const i = initSiteping(...); return i.destroy }, [])`
14
+ * handles fine for *re-mount*, but not for the brief window where the
15
+ * second mount sees a still-alive widget (the widget's own singleton guard
16
+ * logs an info message and returns the existing instance — surprising
17
+ * noise for developers).
18
+ * - The hook also captures the latest `config` in a ref so callbacks (e.g.
19
+ * `onFeedbackSent`) read closure values without re-initialising the widget.
20
+ *
21
+ * Peer dep on react ≥ 18 (declared as optional in package.json), so projects
22
+ * that never import `@siteping/widget/react` don't need React installed.
23
+ */
24
+
25
+ /**
26
+ * Initialise the SitePing widget for the lifetime of the calling component.
27
+ *
28
+ * Safe to call from a Server Component file as long as the component itself
29
+ * is marked `"use client"` — the hook bails out cleanly on the server because
30
+ * `useEffect` never runs there.
31
+ *
32
+ * @example Next.js App Router
33
+ * ```tsx
34
+ * "use client"
35
+ * import { useSiteping } from "@siteping/widget/react"
36
+ *
37
+ * export function FeedbackProvider({ children }: { children: React.ReactNode }) {
38
+ * useSiteping({
39
+ * endpoint: "/api/siteping",
40
+ * projectName: "my-app",
41
+ * })
42
+ * return <>{children}</>
43
+ * }
44
+ * ```
45
+ *
46
+ * @example Driving the panel programmatically
47
+ * ```tsx
48
+ * "use client"
49
+ * import { useSiteping } from "@siteping/widget/react"
50
+ *
51
+ * export function HelpButton() {
52
+ * const widget = useSiteping({ endpoint: "/api/siteping", projectName: "my-app" })
53
+ * return <button onClick={() => widget?.open()}>Need help?</button>
54
+ * }
55
+ * ```
56
+ */
57
+ declare function useSiteping(config: SitepingConfig): SitepingInstance | null;
58
+
59
+ export { useSiteping };