@knocklabs/react 0.9.1 → 0.9.3
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.
- package/CHANGELOG.md +15 -0
- package/dist/cjs/modules/core/utils.js +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/next/KnockGuideLocationSensor.js +2 -0
- package/dist/cjs/next/KnockGuideLocationSensor.js.map +1 -0
- package/dist/cjs/next.js +2 -0
- package/dist/cjs/next.js.map +1 -0
- package/dist/cjs/tanstack/KnockGuideLocationSensor.js +2 -0
- package/dist/cjs/tanstack/KnockGuideLocationSensor.js.map +1 -0
- package/dist/cjs/tanstack.js +2 -0
- package/dist/cjs/tanstack.js.map +1 -0
- package/dist/esm/modules/core/utils.mjs +6 -2
- package/dist/esm/modules/core/utils.mjs.map +1 -1
- package/dist/esm/next/KnockGuideLocationSensor.mjs +39 -0
- package/dist/esm/next/KnockGuideLocationSensor.mjs.map +1 -0
- package/dist/esm/next.mjs +5 -0
- package/dist/esm/next.mjs.map +1 -0
- package/dist/esm/tanstack/KnockGuideLocationSensor.mjs +21 -0
- package/dist/esm/tanstack/KnockGuideLocationSensor.mjs.map +1 -0
- package/dist/esm/tanstack.mjs +5 -0
- package/dist/esm/tanstack.mjs.map +1 -0
- package/dist/types/next/KnockGuideLocationSensor.d.ts +6 -0
- package/dist/types/next/KnockGuideLocationSensor.d.ts.map +1 -0
- package/dist/types/next/index.d.ts +2 -0
- package/dist/types/next/index.d.ts.map +1 -0
- package/dist/types/tanstack/KnockGuideLocationSensor.d.ts +3 -0
- package/dist/types/tanstack/KnockGuideLocationSensor.d.ts.map +1 -0
- package/dist/types/tanstack/index.d.ts +2 -0
- package/dist/types/tanstack/index.d.ts.map +1 -0
- package/package.json +29 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 79d7608: [guide] add KnockGuideLocationSensor helper component for Tanstack Router
|
|
8
|
+
|
|
9
|
+
## 0.9.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1e538b9: [guide] add a secondary entry point for nextjs specific helpers for guide location detection
|
|
14
|
+
- Updated dependencies [1e538b9]
|
|
15
|
+
- @knocklabs/client@0.19.2
|
|
16
|
+
- @knocklabs/react-core@0.11.2
|
|
17
|
+
|
|
3
18
|
## 0.9.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=e=>{const n=window.screenLeft??window.screenX,t=window.screenTop??window.screenY,o=window.innerWidth??document.documentElement.clientWidth??screen.width,i=window.innerHeight??document.documentElement.clientHeight??screen.height,c=o/2-600/2+n,d=`width=600,height=800,top=${i/2-800/2+t},left=${c}`;window.open(e,"_blank",d)},h=()=>{if(typeof window<"u")return window};exports.checkForWindow=h;exports.openPopupWindow=w;
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open"],"mappings":"gFAAaA,MAAAA,EAAmBC,GAAgB,CAIxCC,MAAAA,EAAaC,OAAOD,YAAcC,OAAOC,QACzCC,EAAYF,OAAOE,WAAaF,OAAOG,QAEvCC,EACJJ,OAAOI,YAAcC,SAASC,gBAAgBC,aAAeC,OAAOC,MAChEC,EACJV,OAAOU,aACPL,SAASC,gBAAgBK,cACzBH,OAAOI,OAEHC,EAAOT,EAAa,EAAIK,IAAQ,EAAIV,EAIpCe,EAAW,4BAHLJ,EAAc,EAAIE,IAAS,EAAIV,CAGgB,SAASW,CAAI,GAEjEE,OAAAA,KAAKjB,EAAK,SAAUgB,CAAQ,CACrC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","checkForWindow"],"mappings":"gFAAaA,MAAAA,EAAmBC,GAAgB,CAIxCC,MAAAA,EAAaC,OAAOD,YAAcC,OAAOC,QACzCC,EAAYF,OAAOE,WAAaF,OAAOG,QAEvCC,EACJJ,OAAOI,YAAcC,SAASC,gBAAgBC,aAAeC,OAAOC,MAChEC,EACJV,OAAOU,aACPL,SAASC,gBAAgBK,cACzBH,OAAOI,OAEHC,EAAOT,EAAa,EAAIK,IAAQ,EAAIV,EAIpCe,EAAW,4BAHLJ,EAAc,EAAIE,IAAS,EAAIV,CAGgB,SAASW,CAAI,GAEjEE,OAAAA,KAAKjB,EAAK,SAAUgB,CAAQ,CACrC,EAEaE,EAAiBA,IAAM,CAC9B,GAAA,OAAOhB,OAAW,IACbA,OAAAA,MAEX"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@knocklabs/react-core"),c=require("next/navigation.js"),i=require("next/router.js"),l=require("react"),u=require("../modules/core/utils.js"),f=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},s=f(l),d=()=>{const e=i.useRouter(),{client:o}=a.useGuideContext();return s.default.useEffect(()=>{const n=u.checkForWindow();if(!n)return;o.store.state.location||o.setLocation(n.location.href),o.removeLocationChangeEventListeners();const t=r=>{o.setLocation(n.location.origin+r)};return e.events.on("routeChangeComplete",t),()=>{e.events.off("routeChangeComplete",t)}},[o]),null},h=()=>{const e=c.usePathname(),n=c.useSearchParams().toString(),{client:t}=a.useGuideContext();return s.default.useEffect(()=>{t.removeLocationChangeEventListeners()},[t]),s.default.useEffect(()=>{const r=u.checkForWindow();r&&t.setLocation(r.location.href)},[t,e,n]),null},m={PagesRouter:d,AppRouter:h};exports.KnockGuideLocationSensor=m;
|
|
2
|
+
//# sourceMappingURL=KnockGuideLocationSensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockGuideLocationSensor.js","sources":["../../../src/next/KnockGuideLocationSensor.tsx"],"sourcesContent":["\"use client\";\n\nimport { useGuideContext } from \"@knocklabs/react-core\";\n// Note the .js suffix for Next 15 ESM friendliness:\nimport { usePathname, useSearchParams } from \"next/navigation.js\";\nimport { useRouter } from \"next/router.js\";\nimport React from \"react\";\n\nimport { checkForWindow } from \"../modules/core/utils\";\n\nconst PagesRouter: React.FC = () => {\n const router = useRouter();\n const { client } = useGuideContext();\n\n React.useEffect(() => {\n const win = checkForWindow();\n if (!win) return;\n\n // Set the initial location if not yet set.\n if (!client.store.state.location) {\n client.setLocation(win.location.href);\n }\n\n // If you are using this helper module, then that means we are detecting\n // route changes from next's router rather than from the global history\n // object which the guide client does by default, so ensure we don't have\n // any event listeners hanging around unnecessarily.\n client.removeLocationChangeEventListeners();\n\n // Attach a route change event listener to the nextjs router. Note, here url\n // is the pathname and any query parameters of the new route but does not\n // include the domain or origin.\n const handleRouteChangeComplete = (url: string) => {\n client.setLocation(win.location.origin + url);\n };\n router.events.on(\"routeChangeComplete\", handleRouteChangeComplete);\n\n return () => {\n router.events.off(\"routeChangeComplete\", handleRouteChangeComplete);\n };\n // We want to run this effect once per client instance and `router` is not\n // guaranteed to be referentially stable.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client]);\n\n return null;\n};\n\nconst AppRouter: React.FC = () => {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const queryStr = searchParams.toString();\n\n const { client } = useGuideContext();\n\n React.useEffect(() => {\n // Same here, remove any location change event listeners on the window\n // object in case they are attached.\n client.removeLocationChangeEventListeners();\n }, [client]);\n\n React.useEffect(() => {\n const win = checkForWindow();\n if (!win) return;\n\n client.setLocation(win.location.href);\n }, [client, pathname, queryStr]);\n\n return null;\n};\n\nexport const KnockGuideLocationSensor = {\n PagesRouter,\n AppRouter,\n};\n"],"names":["PagesRouter","router","useRouter","client","useGuideContext","React","useEffect","win","checkForWindow","store","state","location","setLocation","href","removeLocationChangeEventListeners","handleRouteChangeComplete","url","origin","events","on","off","AppRouter","pathname","usePathname","queryStr","useSearchParams","toString","KnockGuideLocationSensor"],"mappings":"0TAUMA,EAAwBA,IAAM,CAClC,MAAMC,EAASC,EAAAA,UAAU,EACnB,CAAEC,OAAAA,GAAWC,kBAAgB,EAEnCC,OAAAA,EAAAA,QAAMC,UAAU,IAAM,CACpB,MAAMC,EAAMC,EAAAA,eAAe,EAC3B,GAAI,CAACD,EAAK,OAGLJ,EAAOM,MAAMC,MAAMC,UACfC,EAAAA,YAAYL,EAAII,SAASE,IAAI,EAOtCV,EAAOW,mCAAmC,EAKpCC,MAAAA,EAA6BC,GAAgB,CACjDb,EAAOS,YAAYL,EAAII,SAASM,OAASD,CAAG,CAC9C,EACOE,OAAAA,EAAAA,OAAOC,GAAG,sBAAuBJ,CAAyB,EAE1D,IAAM,CACJG,EAAAA,OAAOE,IAAI,sBAAuBL,CAAyB,CACpE,CAAA,EAIC,CAACZ,CAAM,CAAC,EAEJ,IACT,EAEMkB,EAAsBA,IAAM,CAChC,MAAMC,EAAWC,EAAAA,YAAY,EAEvBC,EADeC,EAAAA,gBAAgB,EACPC,SAAS,EAEjC,CAAEvB,OAAAA,GAAWC,kBAAgB,EAEnCC,OAAAA,EAAAA,QAAMC,UAAU,IAAM,CAGpBH,EAAOW,mCAAmC,CAAA,EACzC,CAACX,CAAM,CAAC,EAEXE,EAAAA,QAAMC,UAAU,IAAM,CACpB,MAAMC,EAAMC,EAAAA,eAAe,EACtBD,GAEEK,EAAAA,YAAYL,EAAII,SAASE,IAAI,CACnC,EAAA,CAACV,EAAQmB,EAAUE,CAAQ,CAAC,EAExB,IACT,EAEaG,EAA2B,CACtC3B,YAAAA,EACAqB,UAAAA,CACF"}
|
package/dist/cjs/next.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@knocklabs/react-core"),r=require("@tanstack/react-router"),i=require("react"),u=require("../modules/core/utils.js"),s=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},n=s(i),a=()=>{const{href:e}=r.useLocation(),{client:t}=c.useGuideContext();return n.default.useEffect(()=>{t.removeLocationChangeEventListeners()},[t]),n.default.useEffect(()=>{const o=u.checkForWindow();o&&t.setLocation(o.location.origin+e)},[t,e]),null};exports.KnockGuideLocationSensor=a;
|
|
2
|
+
//# sourceMappingURL=KnockGuideLocationSensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockGuideLocationSensor.js","sources":["../../../src/tanstack/KnockGuideLocationSensor.tsx"],"sourcesContent":["import { useGuideContext } from \"@knocklabs/react-core\";\nimport { useLocation } from \"@tanstack/react-router\";\nimport React from \"react\";\n\nimport { checkForWindow } from \"../modules/core/utils\";\n\nexport const KnockGuideLocationSensor: React.FC = () => {\n const { href } = useLocation();\n const { client } = useGuideContext();\n\n React.useEffect(() => {\n client.removeLocationChangeEventListeners();\n }, [client]);\n\n React.useEffect(() => {\n const win = checkForWindow();\n if (!win) return;\n\n // href here is the full path of the location, including pathname, search,\n // and hash but does not include the origin.\n client.setLocation(win.location.origin + href);\n }, [client, href]);\n\n return null;\n};\n"],"names":["KnockGuideLocationSensor","href","useLocation","client","useGuideContext","React","useEffect","removeLocationChangeEventListeners","win","checkForWindow","setLocation","location","origin"],"mappings":"qRAMaA,EAAqCA,IAAM,CAChD,KAAA,CAAEC,KAAAA,GAASC,cAAY,EACvB,CAAEC,OAAAA,GAAWC,kBAAgB,EAEnCC,OAAAA,EAAAA,QAAMC,UAAU,IAAM,CACpBH,EAAOI,mCAAmC,CAAA,EACzC,CAACJ,CAAM,CAAC,EAEXE,EAAAA,QAAMC,UAAU,IAAM,CACpB,MAAME,EAAMC,EAAAA,eAAe,EACtBD,GAILL,EAAOO,YAAYF,EAAIG,SAASC,OAASX,CAAI,CAAA,EAC5C,CAACE,EAAQF,CAAI,CAAC,EAEV,IACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
const r = (e) => {
|
|
2
|
-
const n = window.screenLeft ?? window.screenX, t = window.screenTop ?? window.screenY, o = window.innerWidth ?? document.documentElement.clientWidth ?? screen.width, i = window.innerHeight ?? document.documentElement.clientHeight ?? screen.height, c = o / 2 - 600 / 2 + n,
|
|
3
|
-
window.open(e, "_blank",
|
|
2
|
+
const n = window.screenLeft ?? window.screenX, t = window.screenTop ?? window.screenY, o = window.innerWidth ?? document.documentElement.clientWidth ?? screen.width, i = window.innerHeight ?? document.documentElement.clientHeight ?? screen.height, c = o / 2 - 600 / 2 + n, d = `width=600,height=800,top=${i / 2 - 800 / 2 + t},left=${c}`;
|
|
3
|
+
window.open(e, "_blank", d);
|
|
4
|
+
}, p = () => {
|
|
5
|
+
if (typeof window < "u")
|
|
6
|
+
return window;
|
|
4
7
|
};
|
|
5
8
|
export {
|
|
9
|
+
p as checkForWindow,
|
|
6
10
|
r as openPopupWindow
|
|
7
11
|
};
|
|
8
12
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open"],"mappings":"AAAaA,MAAAA,IAAkBA,CAACC,MAAgB;AAIxCC,QAAAA,IAAaC,OAAOD,cAAcC,OAAOC,SACzCC,IAAYF,OAAOE,aAAaF,OAAOG,SAEvCC,IACJJ,OAAOI,cAAcC,SAASC,gBAAgBC,eAAeC,OAAOC,OAChEC,IACJV,OAAOU,eACPL,SAASC,gBAAgBK,gBACzBH,OAAOI,QAEHC,IAAOT,IAAa,IAAIK,MAAQ,IAAIV,GAIpCe,IAAW,4BAHLJ,IAAc,IAAIE,MAAS,IAAIV,CAGgB,SAASW,CAAI;AAEjEE,SAAAA,KAAKjB,GAAK,UAAUgB,CAAQ;AACrC;"}
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/modules/core/utils.ts"],"sourcesContent":["export const openPopupWindow = (url: string) => {\n const width = 600;\n const height = 800;\n // Calculate the position to center the window\n const screenLeft = window.screenLeft ?? window.screenX;\n const screenTop = window.screenTop ?? window.screenY;\n\n const innerWidth =\n window.innerWidth ?? document.documentElement.clientWidth ?? screen.width;\n const innerHeight =\n window.innerHeight ??\n document.documentElement.clientHeight ??\n screen.height;\n\n const left = innerWidth / 2 - width / 2 + screenLeft;\n const top = innerHeight / 2 - height / 2 + screenTop;\n\n // Window features\n const features = `width=${width},height=${height},top=${top},left=${left}`;\n\n window.open(url, \"_blank\", features);\n};\n\nexport const checkForWindow = () => {\n if (typeof window !== \"undefined\") {\n return window;\n }\n};\n"],"names":["openPopupWindow","url","screenLeft","window","screenX","screenTop","screenY","innerWidth","document","documentElement","clientWidth","screen","width","innerHeight","clientHeight","height","left","features","open","checkForWindow"],"mappings":"AAAaA,MAAAA,IAAkBA,CAACC,MAAgB;AAIxCC,QAAAA,IAAaC,OAAOD,cAAcC,OAAOC,SACzCC,IAAYF,OAAOE,aAAaF,OAAOG,SAEvCC,IACJJ,OAAOI,cAAcC,SAASC,gBAAgBC,eAAeC,OAAOC,OAChEC,IACJV,OAAOU,eACPL,SAASC,gBAAgBK,gBACzBH,OAAOI,QAEHC,IAAOT,IAAa,IAAIK,MAAQ,IAAIV,GAIpCe,IAAW,4BAHLJ,IAAc,IAAIE,MAAS,IAAIV,CAGgB,SAASW,CAAI;AAEjEE,SAAAA,KAAKjB,GAAK,UAAUgB,CAAQ;AACrC,GAEaE,IAAiBA,MAAM;AAC9B,MAAA,OAAOhB,SAAW;AACbA,WAAAA;AAEX;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useGuideContext as c } from "@knocklabs/react-core";
|
|
3
|
+
import { usePathname as i, useSearchParams as u } from "next/navigation.js";
|
|
4
|
+
import { useRouter as m } from "next/router.js";
|
|
5
|
+
import s from "react";
|
|
6
|
+
import { checkForWindow as a } from "../modules/core/utils.mjs";
|
|
7
|
+
const f = () => {
|
|
8
|
+
const n = m(), {
|
|
9
|
+
client: t
|
|
10
|
+
} = c();
|
|
11
|
+
return s.useEffect(() => {
|
|
12
|
+
const o = a();
|
|
13
|
+
if (!o) return;
|
|
14
|
+
t.store.state.location || t.setLocation(o.location.href), t.removeLocationChangeEventListeners();
|
|
15
|
+
const e = (r) => {
|
|
16
|
+
t.setLocation(o.location.origin + r);
|
|
17
|
+
};
|
|
18
|
+
return n.events.on("routeChangeComplete", e), () => {
|
|
19
|
+
n.events.off("routeChangeComplete", e);
|
|
20
|
+
};
|
|
21
|
+
}, [t]), null;
|
|
22
|
+
}, l = () => {
|
|
23
|
+
const n = i(), o = u().toString(), {
|
|
24
|
+
client: e
|
|
25
|
+
} = c();
|
|
26
|
+
return s.useEffect(() => {
|
|
27
|
+
e.removeLocationChangeEventListeners();
|
|
28
|
+
}, [e]), s.useEffect(() => {
|
|
29
|
+
const r = a();
|
|
30
|
+
r && e.setLocation(r.location.href);
|
|
31
|
+
}, [e, n, o]), null;
|
|
32
|
+
}, v = {
|
|
33
|
+
PagesRouter: f,
|
|
34
|
+
AppRouter: l
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
v as KnockGuideLocationSensor
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=KnockGuideLocationSensor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockGuideLocationSensor.mjs","sources":["../../../src/next/KnockGuideLocationSensor.tsx"],"sourcesContent":["\"use client\";\n\nimport { useGuideContext } from \"@knocklabs/react-core\";\n// Note the .js suffix for Next 15 ESM friendliness:\nimport { usePathname, useSearchParams } from \"next/navigation.js\";\nimport { useRouter } from \"next/router.js\";\nimport React from \"react\";\n\nimport { checkForWindow } from \"../modules/core/utils\";\n\nconst PagesRouter: React.FC = () => {\n const router = useRouter();\n const { client } = useGuideContext();\n\n React.useEffect(() => {\n const win = checkForWindow();\n if (!win) return;\n\n // Set the initial location if not yet set.\n if (!client.store.state.location) {\n client.setLocation(win.location.href);\n }\n\n // If you are using this helper module, then that means we are detecting\n // route changes from next's router rather than from the global history\n // object which the guide client does by default, so ensure we don't have\n // any event listeners hanging around unnecessarily.\n client.removeLocationChangeEventListeners();\n\n // Attach a route change event listener to the nextjs router. Note, here url\n // is the pathname and any query parameters of the new route but does not\n // include the domain or origin.\n const handleRouteChangeComplete = (url: string) => {\n client.setLocation(win.location.origin + url);\n };\n router.events.on(\"routeChangeComplete\", handleRouteChangeComplete);\n\n return () => {\n router.events.off(\"routeChangeComplete\", handleRouteChangeComplete);\n };\n // We want to run this effect once per client instance and `router` is not\n // guaranteed to be referentially stable.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client]);\n\n return null;\n};\n\nconst AppRouter: React.FC = () => {\n const pathname = usePathname();\n const searchParams = useSearchParams();\n const queryStr = searchParams.toString();\n\n const { client } = useGuideContext();\n\n React.useEffect(() => {\n // Same here, remove any location change event listeners on the window\n // object in case they are attached.\n client.removeLocationChangeEventListeners();\n }, [client]);\n\n React.useEffect(() => {\n const win = checkForWindow();\n if (!win) return;\n\n client.setLocation(win.location.href);\n }, [client, pathname, queryStr]);\n\n return null;\n};\n\nexport const KnockGuideLocationSensor = {\n PagesRouter,\n AppRouter,\n};\n"],"names":["PagesRouter","router","useRouter","client","useGuideContext","React","useEffect","win","checkForWindow","store","state","location","setLocation","href","removeLocationChangeEventListeners","handleRouteChangeComplete","url","origin","events","on","off","AppRouter","pathname","usePathname","queryStr","useSearchParams","toString","KnockGuideLocationSensor"],"mappings":";;;;;;AAUA,MAAMA,IAAwBA,MAAM;AAClC,QAAMC,IAASC,EAAU,GACnB;AAAA,IAAEC,QAAAA;AAAAA,MAAWC,EAAgB;AAEnCC,SAAAA,EAAMC,UAAU,MAAM;AACpB,UAAMC,IAAMC,EAAe;AAC3B,QAAI,CAACD,EAAK;AAGV,IAAKJ,EAAOM,MAAMC,MAAMC,YACfC,EAAAA,YAAYL,EAAII,SAASE,IAAI,GAOtCV,EAAOW,mCAAmC;AAKpCC,UAAAA,IAA4BA,CAACC,MAAgB;AACjDb,MAAAA,EAAOS,YAAYL,EAAII,SAASM,SAASD,CAAG;AAAA,IAC9C;AACOE,WAAAA,EAAAA,OAAOC,GAAG,uBAAuBJ,CAAyB,GAE1D,MAAM;AACJG,MAAAA,EAAAA,OAAOE,IAAI,uBAAuBL,CAAyB;AAAA,IACpE;AAAA,EAAA,GAIC,CAACZ,CAAM,CAAC,GAEJ;AACT,GAEMkB,IAAsBA,MAAM;AAChC,QAAMC,IAAWC,EAAY,GAEvBC,IADeC,EAAgB,EACPC,SAAS,GAEjC;AAAA,IAAEvB,QAAAA;AAAAA,MAAWC,EAAgB;AAEnCC,SAAAA,EAAMC,UAAU,MAAM;AAGpBH,IAAAA,EAAOW,mCAAmC;AAAA,EAAA,GACzC,CAACX,CAAM,CAAC,GAEXE,EAAMC,UAAU,MAAM;AACpB,UAAMC,IAAMC,EAAe;AAC3B,IAAKD,KAEEK,EAAAA,YAAYL,EAAII,SAASE,IAAI;AAAA,EACnC,GAAA,CAACV,GAAQmB,GAAUE,CAAQ,CAAC,GAExB;AACT,GAEaG,IAA2B;AAAA,EACtC3B,aAAAA;AAAAA,EACAqB,WAAAA;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useGuideContext as r } from "@knocklabs/react-core";
|
|
2
|
+
import { useLocation as i } from "@tanstack/react-router";
|
|
3
|
+
import n from "react";
|
|
4
|
+
import { checkForWindow as c } from "../modules/core/utils.mjs";
|
|
5
|
+
const a = () => {
|
|
6
|
+
const {
|
|
7
|
+
href: t
|
|
8
|
+
} = i(), {
|
|
9
|
+
client: o
|
|
10
|
+
} = r();
|
|
11
|
+
return n.useEffect(() => {
|
|
12
|
+
o.removeLocationChangeEventListeners();
|
|
13
|
+
}, [o]), n.useEffect(() => {
|
|
14
|
+
const e = c();
|
|
15
|
+
e && o.setLocation(e.location.origin + t);
|
|
16
|
+
}, [o, t]), null;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
a as KnockGuideLocationSensor
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=KnockGuideLocationSensor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockGuideLocationSensor.mjs","sources":["../../../src/tanstack/KnockGuideLocationSensor.tsx"],"sourcesContent":["import { useGuideContext } from \"@knocklabs/react-core\";\nimport { useLocation } from \"@tanstack/react-router\";\nimport React from \"react\";\n\nimport { checkForWindow } from \"../modules/core/utils\";\n\nexport const KnockGuideLocationSensor: React.FC = () => {\n const { href } = useLocation();\n const { client } = useGuideContext();\n\n React.useEffect(() => {\n client.removeLocationChangeEventListeners();\n }, [client]);\n\n React.useEffect(() => {\n const win = checkForWindow();\n if (!win) return;\n\n // href here is the full path of the location, including pathname, search,\n // and hash but does not include the origin.\n client.setLocation(win.location.origin + href);\n }, [client, href]);\n\n return null;\n};\n"],"names":["KnockGuideLocationSensor","href","useLocation","client","useGuideContext","React","useEffect","removeLocationChangeEventListeners","win","checkForWindow","setLocation","location","origin"],"mappings":";;;;AAMO,MAAMA,IAAqCA,MAAM;AAChD,QAAA;AAAA,IAAEC,MAAAA;AAAAA,MAASC,EAAY,GACvB;AAAA,IAAEC,QAAAA;AAAAA,MAAWC,EAAgB;AAEnCC,SAAAA,EAAMC,UAAU,MAAM;AACpBH,IAAAA,EAAOI,mCAAmC;AAAA,EAAA,GACzC,CAACJ,CAAM,CAAC,GAEXE,EAAMC,UAAU,MAAM;AACpB,UAAME,IAAMC,EAAe;AAC3B,IAAKD,KAILL,EAAOO,YAAYF,EAAIG,SAASC,SAASX,CAAI;AAAA,EAAA,GAC5C,CAACE,GAAQF,CAAI,CAAC,GAEV;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tanstack.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockGuideLocationSensor.d.ts","sourceRoot":"","sources":["../../../src/next/KnockGuideLocationSensor.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,OAAO,CAAC;AAiE1B,eAAO,MAAM,wBAAwB;;;CAGpC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KnockGuideLocationSensor.d.ts","sourceRoot":"","sources":["../../../src/tanstack/KnockGuideLocationSensor.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,eAAO,MAAM,wBAAwB,EAAE,KAAK,CAAC,EAkB5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tanstack/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@knocklabs/react",
|
|
3
3
|
"description": "A set of React components to build notification experiences powered by Knock",
|
|
4
4
|
"author": "@knocklabs",
|
|
5
|
-
"version": "0.9.
|
|
5
|
+
"version": "0.9.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -16,6 +16,18 @@
|
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"import": "./dist/esm/index.mjs",
|
|
18
18
|
"default": "./dist/cjs/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./next": {
|
|
21
|
+
"require": "./dist/cjs/next.js",
|
|
22
|
+
"types": "./dist/types/next/index.d.ts",
|
|
23
|
+
"import": "./dist/esm/next.mjs",
|
|
24
|
+
"default": "./dist/cjs/next.js"
|
|
25
|
+
},
|
|
26
|
+
"./tanstack": {
|
|
27
|
+
"require": "./dist/cjs/tanstack.js",
|
|
28
|
+
"types": "./dist/types/tanstack/index.d.ts",
|
|
29
|
+
"import": "./dist/esm/tanstack.mjs",
|
|
30
|
+
"default": "./dist/cjs/tanstack.js"
|
|
19
31
|
}
|
|
20
32
|
},
|
|
21
33
|
"files": [
|
|
@@ -46,12 +58,22 @@
|
|
|
46
58
|
"url": "https://github.com/knocklabs/javascript/issues"
|
|
47
59
|
},
|
|
48
60
|
"peerDependencies": {
|
|
61
|
+
"@tanstack/react-router": "^1.0.0",
|
|
62
|
+
"next": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
49
63
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
50
64
|
"react-dom": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
51
65
|
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"@tanstack/react-router": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"next": {
|
|
71
|
+
"optional": true
|
|
72
|
+
}
|
|
73
|
+
},
|
|
52
74
|
"dependencies": {
|
|
53
|
-
"@knocklabs/client": "^0.19.
|
|
54
|
-
"@knocklabs/react-core": "^0.11.
|
|
75
|
+
"@knocklabs/client": "^0.19.2",
|
|
76
|
+
"@knocklabs/react-core": "^0.11.2",
|
|
55
77
|
"@popperjs/core": "^2.11.8",
|
|
56
78
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
57
79
|
"@telegraph/combobox": "^0.1.16",
|
|
@@ -64,7 +86,8 @@
|
|
|
64
86
|
},
|
|
65
87
|
"devDependencies": {
|
|
66
88
|
"@codecov/vite-plugin": "^1.9.1",
|
|
67
|
-
"@
|
|
89
|
+
"@tanstack/react-router": "1.134.12",
|
|
90
|
+
"@testing-library/dom": "^10.4.1",
|
|
68
91
|
"@testing-library/react": "^16.3.0",
|
|
69
92
|
"@types/eslint-plugin-jsx-a11y": "^6",
|
|
70
93
|
"@types/lodash.debounce": "^4.0.9",
|
|
@@ -78,7 +101,8 @@
|
|
|
78
101
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
79
102
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
80
103
|
"eslint-plugin-react-refresh": "^0.4.14",
|
|
81
|
-
"jsdom": "^27.
|
|
104
|
+
"jsdom": "^27.1.0",
|
|
105
|
+
"next": "15.3.3",
|
|
82
106
|
"react": "^19.0.0",
|
|
83
107
|
"react-dom": "^19.0.0",
|
|
84
108
|
"rimraf": "^6.0.1",
|