@knocklabs/react-core 0.7.4 → 0.8.0

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 48e9c77: - Support guides ordering and throttle settings
8
+ - Add `useGuides` hook
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [48e9c77]
13
+ - @knocklabs/client@0.16.0
14
+
15
+ ## 0.7.5
16
+
17
+ ### Patch Changes
18
+
19
+ - d7e5371: chore(deps): bump @tanstack/react-store from 0.7.1 to 0.7.3
20
+ - Updated dependencies [fb68ce1]
21
+ - @knocklabs/client@0.15.2
22
+
3
23
  ## 0.7.4
4
24
 
5
25
  ### Patch Changes
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@knocklabs/client"),b=require("react"),k=require("../../core/context/KnockProvider.js"),p=require("../../core/hooks/useStableOptions.js");require("date-fns");function v(e){if(e&&typeof e=="object"&&"default"in e)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const c=v(b),a=c.createContext(void 0),K=({channelId:e,readyToTarget:r,listenForUpdates:t=!0,colorMode:o="light",targetParams:l={},trackLocationFromWindow:u=!0,children:d})=>{let i;try{i=k.useKnockClient()}catch{throw new Error("KnockGuideProvider must be used within a KnockProvider")}const s=p(l),n=c.useMemo(()=>new f.KnockGuideClient(i,e,s,{trackLocationFromWindow:u}),[i,e,s,u]);return c.useEffect(()=>(r&&(n.fetch(),t&&n.subscribe()),()=>n.cleanup()),[r,t,n]),c.createElement(a.Provider,{value:{client:n,colorMode:o}},d)};exports.KnockGuideContext=a;exports.KnockGuideProvider=K;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@knocklabs/client"),p=require("react"),K=require("../../core/context/KnockProvider.js"),P=require("../../core/hooks/useStableOptions.js");require("date-fns");function m(e){if(e&&typeof e=="object"&&"default"in e)return e;const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const c=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,c.get?c:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const o=m(p),l=o.createContext(void 0),v=({channelId:e,readyToTarget:r,listenForUpdates:t=!0,colorMode:c="light",targetParams:f={},trackLocationFromWindow:u=!0,orderResolutionDuration:s=0,throttleCheckInterval:a,children:b})=>{let i;try{i=K.useKnockClient()}catch{throw new Error("KnockGuideProvider must be used within a KnockProvider")}const d=P(f),n=o.useMemo(()=>new k.KnockGuideClient(i,e,d,{trackLocationFromWindow:u,orderResolutionDuration:s,throttleCheckInterval:a}),[i,e,d,u,s,a]);return o.useEffect(()=>(r&&(n.fetch(),t&&n.subscribe()),()=>n.cleanup()),[r,t,n]),o.createElement(l.Provider,{value:{client:n,colorMode:c}},b)};exports.KnockGuideContext=l;exports.KnockGuideProvider=v;
2
2
  //# sourceMappingURL=KnockGuideProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockGuideProvider.js","sources":["../../../../../src/modules/guide/context/KnockGuideProvider.tsx"],"sourcesContent":["import Knock, {\n KnockGuideClient,\n KnockGuideTargetParams,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\n\nimport { useKnockClient, useStableOptions } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\n\ntype KnockGuideProviderValue = {\n client: KnockGuideClient;\n colorMode: ColorMode;\n};\n\nexport const KnockGuideContext = React.createContext<\n KnockGuideProviderValue | undefined\n>(undefined);\n\ntype Props = {\n channelId: string;\n readyToTarget: boolean;\n listenForUpdates?: boolean;\n colorMode?: ColorMode;\n targetParams?: KnockGuideTargetParams;\n trackLocationFromWindow?: boolean;\n};\n\nexport const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({\n channelId,\n readyToTarget,\n listenForUpdates = true,\n colorMode = \"light\",\n targetParams = {},\n trackLocationFromWindow = true,\n children,\n}) => {\n let knock: Knock;\n\n try {\n knock = useKnockClient();\n } catch (_) {\n throw new Error(\"KnockGuideProvider must be used within a KnockProvider\");\n }\n\n const stableTargetParams = useStableOptions(targetParams);\n\n const knockGuideClient = React.useMemo(() => {\n return new KnockGuideClient(knock, channelId, stableTargetParams, {\n trackLocationFromWindow,\n });\n }, [knock, channelId, stableTargetParams, trackLocationFromWindow]);\n\n React.useEffect(() => {\n if (readyToTarget) {\n knockGuideClient.fetch();\n if (listenForUpdates) knockGuideClient.subscribe();\n }\n\n return () => knockGuideClient.cleanup();\n }, [readyToTarget, listenForUpdates, knockGuideClient]);\n\n return (\n <KnockGuideContext.Provider\n value={{\n client: knockGuideClient,\n colorMode,\n }}\n >\n {children}\n </KnockGuideContext.Provider>\n );\n};\n"],"names":["KnockGuideContext","React","createContext","undefined","KnockGuideProvider","channelId","readyToTarget","listenForUpdates","colorMode","targetParams","trackLocationFromWindow","children","knock","useKnockClient","Error","stableTargetParams","useStableOptions","knockGuideClient","useMemo","KnockGuideClient","useEffect","fetch","subscribe","cleanup","client"],"mappings":"0kBAcaA,EAAoBC,EAAMC,cAErCC,MAAS,EAWEC,EAA+DA,CAAC,CAC3EC,UAAAA,EACAC,cAAAA,EACAC,iBAAAA,EAAmB,GACnBC,UAAAA,EAAY,QACZC,aAAAA,EAAe,CAAC,EAChBC,wBAAAA,EAA0B,GAC1BC,SAAAA,CACF,IAAM,CACAC,IAAAA,EAEA,GAAA,CACFA,EAAQC,EAAAA,eAAe,OACb,CACJ,MAAA,IAAIC,MAAM,wDAAwD,CAAA,CAGpEC,MAAAA,EAAqBC,EAAiBP,CAAY,EAElDQ,EAAmBhB,EAAMiB,QAAQ,IAC9B,IAAIC,EAAAA,iBAAiBP,EAAOP,EAAWU,EAAoB,CAChEL,wBAAAA,CAAAA,CACD,EACA,CAACE,EAAOP,EAAWU,EAAoBL,CAAuB,CAAC,EAElET,OAAAA,EAAMmB,UAAU,KACVd,IACFW,EAAiBI,MAAM,EACnBd,KAAmCe,UAAU,GAG5C,IAAML,EAAiBM,QAAQ,GACrC,CAACjB,EAAeC,EAAkBU,CAAgB,CAAC,EAGnDhB,EAAA,cAAAD,EAAkB,SAAlB,CACC,MAAO,CACLwB,OAAQP,EACRT,UAAAA,IAGDG,CACH,CAEJ"}
1
+ {"version":3,"file":"KnockGuideProvider.js","sources":["../../../../../src/modules/guide/context/KnockGuideProvider.tsx"],"sourcesContent":["import Knock, {\n KnockGuideClient,\n KnockGuideTargetParams,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\n\nimport { useKnockClient, useStableOptions } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\n\ntype KnockGuideProviderValue = {\n client: KnockGuideClient;\n colorMode: ColorMode;\n};\n\nexport const KnockGuideContext = React.createContext<\n KnockGuideProviderValue | undefined\n>(undefined);\n\ntype Props = {\n channelId: string;\n readyToTarget: boolean;\n listenForUpdates?: boolean;\n colorMode?: ColorMode;\n targetParams?: KnockGuideTargetParams;\n trackLocationFromWindow?: boolean;\n orderResolutionDuration?: number; // in milliseconds\n throttleCheckInterval?: number; // in milliseconds\n};\n\nexport const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({\n channelId,\n readyToTarget,\n listenForUpdates = true,\n colorMode = \"light\",\n targetParams = {},\n trackLocationFromWindow = true,\n // Default to 0 which works well for react apps as this \"yields\" to react for\n // one render cyle first and close the group stage.\n orderResolutionDuration = 0,\n throttleCheckInterval,\n children,\n}) => {\n let knock: Knock;\n\n try {\n knock = useKnockClient();\n } catch (_) {\n throw new Error(\"KnockGuideProvider must be used within a KnockProvider\");\n }\n\n const stableTargetParams = useStableOptions(targetParams);\n\n const knockGuideClient = React.useMemo(() => {\n return new KnockGuideClient(knock, channelId, stableTargetParams, {\n trackLocationFromWindow,\n orderResolutionDuration,\n throttleCheckInterval,\n });\n }, [\n knock,\n channelId,\n stableTargetParams,\n trackLocationFromWindow,\n orderResolutionDuration,\n throttleCheckInterval,\n ]);\n\n React.useEffect(() => {\n if (readyToTarget) {\n knockGuideClient.fetch();\n if (listenForUpdates) knockGuideClient.subscribe();\n }\n\n return () => knockGuideClient.cleanup();\n }, [readyToTarget, listenForUpdates, knockGuideClient]);\n\n return (\n <KnockGuideContext.Provider\n value={{\n client: knockGuideClient,\n colorMode,\n }}\n >\n {children}\n </KnockGuideContext.Provider>\n );\n};\n"],"names":["KnockGuideContext","React","createContext","undefined","KnockGuideProvider","channelId","readyToTarget","listenForUpdates","colorMode","targetParams","trackLocationFromWindow","orderResolutionDuration","throttleCheckInterval","children","knock","useKnockClient","Error","stableTargetParams","useStableOptions","knockGuideClient","useMemo","KnockGuideClient","useEffect","fetch","subscribe","cleanup","client"],"mappings":"0kBAcaA,EAAoBC,EAAMC,cAErCC,MAAS,EAaEC,EAA+DA,CAAC,CAC3EC,UAAAA,EACAC,cAAAA,EACAC,iBAAAA,EAAmB,GACnBC,UAAAA,EAAY,QACZC,aAAAA,EAAe,CAAC,EAChBC,wBAAAA,EAA0B,GAG1BC,wBAAAA,EAA0B,EAC1BC,sBAAAA,EACAC,SAAAA,CACF,IAAM,CACAC,IAAAA,EAEA,GAAA,CACFA,EAAQC,EAAAA,eAAe,OACb,CACJ,MAAA,IAAIC,MAAM,wDAAwD,CAAA,CAGpEC,MAAAA,EAAqBC,EAAiBT,CAAY,EAElDU,EAAmBlB,EAAMmB,QAAQ,IAC9B,IAAIC,EAAAA,iBAAiBP,EAAOT,EAAWY,EAAoB,CAChEP,wBAAAA,EACAC,wBAAAA,EACAC,sBAAAA,CAAAA,CACD,EACA,CACDE,EACAT,EACAY,EACAP,EACAC,EACAC,CAAqB,CACtB,EAEDX,OAAAA,EAAMqB,UAAU,KACVhB,IACFa,EAAiBI,MAAM,EACnBhB,KAAmCiB,UAAU,GAG5C,IAAML,EAAiBM,QAAQ,GACrC,CAACnB,EAAeC,EAAkBY,CAAgB,CAAC,EAGnDlB,EAAA,cAAAD,EAAkB,SAAlB,CACC,MAAO,CACL0B,OAAQP,EACRX,UAAAA,IAGDK,CACH,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@tanstack/react-store"),c=require("./useGuideContext.js"),d=e=>{const u=c.useGuideContext();if(!e.key&&!e.type)throw new Error("useGuide must be used with at least one filter: either a guide key or a guide type");const{client:t,colorMode:r}=u,[o]=n.useStore(t.store,s=>t.select(s,e)),i=o&&o.steps.find(s=>!s.message.archived_at);return{client:t,colorMode:r,guide:o,step:i}};exports.useGuide=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@tanstack/react-store"),c=require("./useGuideContext.js"),d=e=>{const r=c.useGuideContext();if(!e.key&&!e.type)throw new Error("useGuide must be given at least one filter: { key?: string; type?: string; }");const{client:t,colorMode:s}=r,o=i.useStore(t.store,n=>t.selectGuide(n,e)),u=o&&o.getStep();return{client:t,colorMode:s,guide:o,step:u}};exports.useGuide=d;
2
2
  //# sourceMappingURL=useGuide.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGuide.js","sources":["../../../../../src/modules/guide/hooks/useGuide.ts"],"sourcesContent":["import {\n KnockGuide,\n KnockGuideFilterParams,\n KnockGuideStep,\n} from \"@knocklabs/client\";\nimport { useStore } from \"@tanstack/react-store\";\n\nimport { UseGuideContextReturn, useGuideContext } from \"./useGuideContext\";\n\ninterface UseGuideReturn extends UseGuideContextReturn {\n guide: KnockGuide | undefined;\n step: KnockGuideStep | undefined;\n}\n\nexport const useGuide = (filters: KnockGuideFilterParams): UseGuideReturn => {\n const context = useGuideContext();\n\n if (!filters.key && !filters.type) {\n throw new Error(\n \"useGuide must be used with at least one filter: either a guide key or a guide type\",\n );\n }\n\n const { client, colorMode } = context;\n\n const [guide] = useStore(client.store, (state) =>\n client.select(state, filters),\n );\n\n const step = guide && guide.steps.find((s) => !s.message.archived_at);\n\n return { client, colorMode, guide, step };\n};\n"],"names":["useGuide","filters","context","useGuideContext","key","type","Error","client","colorMode","guide","useStore","store","state","select","step","steps","find","s","message","archived_at"],"mappings":"2JAcaA,EAAYC,GAAoD,CAC3E,MAAMC,EAAUC,EAAAA,gBAAgB,EAEhC,GAAI,CAACF,EAAQG,KAAO,CAACH,EAAQI,KACrB,MAAA,IAAIC,MACR,oFACF,EAGI,KAAA,CAAEC,OAAAA,EAAQC,UAAAA,CAAAA,EAAcN,EAExB,CAACO,CAAK,EAAIC,EAASH,SAAAA,EAAOI,MAAQC,GACtCL,EAAOM,OAAOD,EAAOX,CAAO,CAC9B,EAEMa,EAAOL,GAASA,EAAMM,MAAMC,KAAY,GAAA,CAACC,EAAEC,QAAQC,WAAW,EAE7D,MAAA,CAAEZ,OAAAA,EAAQC,UAAAA,EAAWC,MAAAA,EAAOK,KAAAA,CAAK,CAC1C"}
1
+ {"version":3,"file":"useGuide.js","sources":["../../../../../src/modules/guide/hooks/useGuide.ts"],"sourcesContent":["import {\n KnockGuide,\n KnockGuideFilterParams,\n KnockGuideStep,\n} from \"@knocklabs/client\";\nimport { useStore } from \"@tanstack/react-store\";\n\nimport { UseGuideContextReturn, useGuideContext } from \"./useGuideContext\";\n\ninterface UseGuideReturn extends UseGuideContextReturn {\n guide: KnockGuide | undefined;\n step: KnockGuideStep | undefined;\n}\n\nexport const useGuide = (filters: KnockGuideFilterParams): UseGuideReturn => {\n const context = useGuideContext();\n\n if (!filters.key && !filters.type) {\n throw new Error(\n \"useGuide must be given at least one filter: { key?: string; type?: string; }\",\n );\n }\n\n const { client, colorMode } = context;\n\n const guide = useStore(client.store, (state) =>\n client.selectGuide(state, filters),\n );\n\n const step = guide && guide.getStep();\n\n return { client, colorMode, guide, step };\n};\n"],"names":["useGuide","filters","context","useGuideContext","key","type","Error","client","colorMode","guide","useStore","store","selectGuide","state","step","getStep"],"mappings":"2JAcaA,EAAYC,GAAoD,CAC3E,MAAMC,EAAUC,EAAAA,gBAAgB,EAEhC,GAAI,CAACF,EAAQG,KAAO,CAACH,EAAQI,KACrB,MAAA,IAAIC,MACR,8EACF,EAGI,KAAA,CAAEC,OAAAA,EAAQC,UAAAA,CAAAA,EAAcN,EAExBO,EAAQC,EAAAA,SAASH,EAAOI,SAC5BJ,EAAOK,YAAYC,EAAOZ,CAAO,CACnC,EAEMa,EAAOL,GAASA,EAAMM,QAAQ,EAE7B,MAAA,CAAER,OAAAA,EAAQC,UAAAA,EAAWC,MAAAA,EAAOK,KAAAA,CAAK,CAC1C"}
@@ -1,16 +1,20 @@
1
- import { KnockGuideClient as k } from "@knocklabs/client";
1
+ import { KnockGuideClient as d } from "@knocklabs/client";
2
2
  import * as t from "react";
3
3
  import { useKnockClient as l } from "../../core/context/KnockProvider.mjs";
4
- import a from "../../core/hooks/useStableOptions.mjs";
4
+ import K from "../../core/hooks/useStableOptions.mjs";
5
5
  import "date-fns";
6
- const d = t.createContext(void 0), G = ({
6
+ const a = t.createContext(void 0), w = ({
7
7
  channelId: o,
8
8
  readyToTarget: i,
9
9
  listenForUpdates: n = !0,
10
- colorMode: s = "light",
11
- targetParams: m = {},
10
+ colorMode: f = "light",
11
+ targetParams: k = {},
12
12
  trackLocationFromWindow: c = !0,
13
- children: f
13
+ // Default to 0 which works well for react apps as this "yields" to react for
14
+ // one render cyle first and close the group stage.
15
+ orderResolutionDuration: u = 0,
16
+ throttleCheckInterval: s,
17
+ children: p
14
18
  }) => {
15
19
  let r;
16
20
  try {
@@ -18,16 +22,18 @@ const d = t.createContext(void 0), G = ({
18
22
  } catch {
19
23
  throw new Error("KnockGuideProvider must be used within a KnockProvider");
20
24
  }
21
- const u = a(m), e = t.useMemo(() => new k(r, o, u, {
22
- trackLocationFromWindow: c
23
- }), [r, o, u, c]);
24
- return t.useEffect(() => (i && (e.fetch(), n && e.subscribe()), () => e.cleanup()), [i, n, e]), /* @__PURE__ */ t.createElement(d.Provider, { value: {
25
+ const m = K(k), e = t.useMemo(() => new d(r, o, m, {
26
+ trackLocationFromWindow: c,
27
+ orderResolutionDuration: u,
28
+ throttleCheckInterval: s
29
+ }), [r, o, m, c, u, s]);
30
+ return t.useEffect(() => (i && (e.fetch(), n && e.subscribe()), () => e.cleanup()), [i, n, e]), /* @__PURE__ */ t.createElement(a.Provider, { value: {
25
31
  client: e,
26
- colorMode: s
27
- } }, f);
32
+ colorMode: f
33
+ } }, p);
28
34
  };
29
35
  export {
30
- d as KnockGuideContext,
31
- G as KnockGuideProvider
36
+ a as KnockGuideContext,
37
+ w as KnockGuideProvider
32
38
  };
33
39
  //# sourceMappingURL=KnockGuideProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockGuideProvider.mjs","sources":["../../../../../src/modules/guide/context/KnockGuideProvider.tsx"],"sourcesContent":["import Knock, {\n KnockGuideClient,\n KnockGuideTargetParams,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\n\nimport { useKnockClient, useStableOptions } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\n\ntype KnockGuideProviderValue = {\n client: KnockGuideClient;\n colorMode: ColorMode;\n};\n\nexport const KnockGuideContext = React.createContext<\n KnockGuideProviderValue | undefined\n>(undefined);\n\ntype Props = {\n channelId: string;\n readyToTarget: boolean;\n listenForUpdates?: boolean;\n colorMode?: ColorMode;\n targetParams?: KnockGuideTargetParams;\n trackLocationFromWindow?: boolean;\n};\n\nexport const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({\n channelId,\n readyToTarget,\n listenForUpdates = true,\n colorMode = \"light\",\n targetParams = {},\n trackLocationFromWindow = true,\n children,\n}) => {\n let knock: Knock;\n\n try {\n knock = useKnockClient();\n } catch (_) {\n throw new Error(\"KnockGuideProvider must be used within a KnockProvider\");\n }\n\n const stableTargetParams = useStableOptions(targetParams);\n\n const knockGuideClient = React.useMemo(() => {\n return new KnockGuideClient(knock, channelId, stableTargetParams, {\n trackLocationFromWindow,\n });\n }, [knock, channelId, stableTargetParams, trackLocationFromWindow]);\n\n React.useEffect(() => {\n if (readyToTarget) {\n knockGuideClient.fetch();\n if (listenForUpdates) knockGuideClient.subscribe();\n }\n\n return () => knockGuideClient.cleanup();\n }, [readyToTarget, listenForUpdates, knockGuideClient]);\n\n return (\n <KnockGuideContext.Provider\n value={{\n client: knockGuideClient,\n colorMode,\n }}\n >\n {children}\n </KnockGuideContext.Provider>\n );\n};\n"],"names":["KnockGuideContext","React","createContext","undefined","KnockGuideProvider","channelId","readyToTarget","listenForUpdates","colorMode","targetParams","trackLocationFromWindow","children","knock","useKnockClient","Error","stableTargetParams","useStableOptions","knockGuideClient","useMemo","KnockGuideClient","useEffect","fetch","subscribe","cleanup","client"],"mappings":";;;;;AAcaA,MAAAA,IAAoBC,EAAMC,cAErCC,MAAS,GAWEC,IAA+DA,CAAC;AAAA,EAC3EC,WAAAA;AAAAA,EACAC,eAAAA;AAAAA,EACAC,kBAAAA,IAAmB;AAAA,EACnBC,WAAAA,IAAY;AAAA,EACZC,cAAAA,IAAe,CAAC;AAAA,EAChBC,yBAAAA,IAA0B;AAAA,EAC1BC,UAAAA;AACF,MAAM;AACAC,MAAAA;AAEA,MAAA;AACFA,IAAAA,IAAQC,EAAe;AAAA,UACb;AACJ,UAAA,IAAIC,MAAM,wDAAwD;AAAA,EAAA;AAGpEC,QAAAA,IAAqBC,EAAiBP,CAAY,GAElDQ,IAAmBhB,EAAMiB,QAAQ,MAC9B,IAAIC,EAAiBP,GAAOP,GAAWU,GAAoB;AAAA,IAChEL,yBAAAA;AAAAA,EAAAA,CACD,GACA,CAACE,GAAOP,GAAWU,GAAoBL,CAAuB,CAAC;AAElET,SAAAA,EAAMmB,UAAU,OACVd,MACFW,EAAiBI,MAAM,GACnBd,OAAmCe,UAAU,IAG5C,MAAML,EAAiBM,QAAQ,IACrC,CAACjB,GAAeC,GAAkBU,CAAgB,CAAC,GAGnD,gBAAAhB,EAAA,cAAAD,EAAkB,UAAlB,EACC,OAAO;AAAA,IACLwB,QAAQP;AAAAA,IACRT,WAAAA;AAAAA,OAGDG,CACH;AAEJ;"}
1
+ {"version":3,"file":"KnockGuideProvider.mjs","sources":["../../../../../src/modules/guide/context/KnockGuideProvider.tsx"],"sourcesContent":["import Knock, {\n KnockGuideClient,\n KnockGuideTargetParams,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\n\nimport { useKnockClient, useStableOptions } from \"../../core\";\nimport { ColorMode } from \"../../core/constants\";\n\ntype KnockGuideProviderValue = {\n client: KnockGuideClient;\n colorMode: ColorMode;\n};\n\nexport const KnockGuideContext = React.createContext<\n KnockGuideProviderValue | undefined\n>(undefined);\n\ntype Props = {\n channelId: string;\n readyToTarget: boolean;\n listenForUpdates?: boolean;\n colorMode?: ColorMode;\n targetParams?: KnockGuideTargetParams;\n trackLocationFromWindow?: boolean;\n orderResolutionDuration?: number; // in milliseconds\n throttleCheckInterval?: number; // in milliseconds\n};\n\nexport const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({\n channelId,\n readyToTarget,\n listenForUpdates = true,\n colorMode = \"light\",\n targetParams = {},\n trackLocationFromWindow = true,\n // Default to 0 which works well for react apps as this \"yields\" to react for\n // one render cyle first and close the group stage.\n orderResolutionDuration = 0,\n throttleCheckInterval,\n children,\n}) => {\n let knock: Knock;\n\n try {\n knock = useKnockClient();\n } catch (_) {\n throw new Error(\"KnockGuideProvider must be used within a KnockProvider\");\n }\n\n const stableTargetParams = useStableOptions(targetParams);\n\n const knockGuideClient = React.useMemo(() => {\n return new KnockGuideClient(knock, channelId, stableTargetParams, {\n trackLocationFromWindow,\n orderResolutionDuration,\n throttleCheckInterval,\n });\n }, [\n knock,\n channelId,\n stableTargetParams,\n trackLocationFromWindow,\n orderResolutionDuration,\n throttleCheckInterval,\n ]);\n\n React.useEffect(() => {\n if (readyToTarget) {\n knockGuideClient.fetch();\n if (listenForUpdates) knockGuideClient.subscribe();\n }\n\n return () => knockGuideClient.cleanup();\n }, [readyToTarget, listenForUpdates, knockGuideClient]);\n\n return (\n <KnockGuideContext.Provider\n value={{\n client: knockGuideClient,\n colorMode,\n }}\n >\n {children}\n </KnockGuideContext.Provider>\n );\n};\n"],"names":["KnockGuideContext","React","createContext","undefined","KnockGuideProvider","channelId","readyToTarget","listenForUpdates","colorMode","targetParams","trackLocationFromWindow","orderResolutionDuration","throttleCheckInterval","children","knock","useKnockClient","Error","stableTargetParams","useStableOptions","knockGuideClient","useMemo","KnockGuideClient","useEffect","fetch","subscribe","cleanup","client"],"mappings":";;;;;AAcaA,MAAAA,IAAoBC,EAAMC,cAErCC,MAAS,GAaEC,IAA+DA,CAAC;AAAA,EAC3EC,WAAAA;AAAAA,EACAC,eAAAA;AAAAA,EACAC,kBAAAA,IAAmB;AAAA,EACnBC,WAAAA,IAAY;AAAA,EACZC,cAAAA,IAAe,CAAC;AAAA,EAChBC,yBAAAA,IAA0B;AAAA;AAAA;AAAA,EAG1BC,yBAAAA,IAA0B;AAAA,EAC1BC,uBAAAA;AAAAA,EACAC,UAAAA;AACF,MAAM;AACAC,MAAAA;AAEA,MAAA;AACFA,IAAAA,IAAQC,EAAe;AAAA,UACb;AACJ,UAAA,IAAIC,MAAM,wDAAwD;AAAA,EAAA;AAGpEC,QAAAA,IAAqBC,EAAiBT,CAAY,GAElDU,IAAmBlB,EAAMmB,QAAQ,MAC9B,IAAIC,EAAiBP,GAAOT,GAAWY,GAAoB;AAAA,IAChEP,yBAAAA;AAAAA,IACAC,yBAAAA;AAAAA,IACAC,uBAAAA;AAAAA,EAAAA,CACD,GACA,CACDE,GACAT,GACAY,GACAP,GACAC,GACAC,CAAqB,CACtB;AAEDX,SAAAA,EAAMqB,UAAU,OACVhB,MACFa,EAAiBI,MAAM,GACnBhB,OAAmCiB,UAAU,IAG5C,MAAML,EAAiBM,QAAQ,IACrC,CAACnB,GAAeC,GAAkBY,CAAgB,CAAC,GAGnD,gBAAAlB,EAAA,cAAAD,EAAkB,UAAlB,EACC,OAAO;AAAA,IACL0B,QAAQP;AAAAA,IACRX,WAAAA;AAAAA,OAGDK,CACH;AAEJ;"}
@@ -1,21 +1,21 @@
1
- import { useStore as n } from "@tanstack/react-store";
1
+ import { useStore as u } from "@tanstack/react-store";
2
2
  import { useGuideContext as c } from "./useGuideContext.mjs";
3
- const p = (e) => {
3
+ const g = (e) => {
4
4
  const r = c();
5
5
  if (!e.key && !e.type)
6
- throw new Error("useGuide must be used with at least one filter: either a guide key or a guide type");
6
+ throw new Error("useGuide must be given at least one filter: { key?: string; type?: string; }");
7
7
  const {
8
8
  client: t,
9
- colorMode: i
10
- } = r, [o] = n(t.store, (s) => t.select(s, e)), u = o && o.steps.find((s) => !s.message.archived_at);
9
+ colorMode: n
10
+ } = r, o = u(t.store, (i) => t.selectGuide(i, e)), s = o && o.getStep();
11
11
  return {
12
12
  client: t,
13
- colorMode: i,
13
+ colorMode: n,
14
14
  guide: o,
15
- step: u
15
+ step: s
16
16
  };
17
17
  };
18
18
  export {
19
- p as useGuide
19
+ g as useGuide
20
20
  };
21
21
  //# sourceMappingURL=useGuide.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGuide.mjs","sources":["../../../../../src/modules/guide/hooks/useGuide.ts"],"sourcesContent":["import {\n KnockGuide,\n KnockGuideFilterParams,\n KnockGuideStep,\n} from \"@knocklabs/client\";\nimport { useStore } from \"@tanstack/react-store\";\n\nimport { UseGuideContextReturn, useGuideContext } from \"./useGuideContext\";\n\ninterface UseGuideReturn extends UseGuideContextReturn {\n guide: KnockGuide | undefined;\n step: KnockGuideStep | undefined;\n}\n\nexport const useGuide = (filters: KnockGuideFilterParams): UseGuideReturn => {\n const context = useGuideContext();\n\n if (!filters.key && !filters.type) {\n throw new Error(\n \"useGuide must be used with at least one filter: either a guide key or a guide type\",\n );\n }\n\n const { client, colorMode } = context;\n\n const [guide] = useStore(client.store, (state) =>\n client.select(state, filters),\n );\n\n const step = guide && guide.steps.find((s) => !s.message.archived_at);\n\n return { client, colorMode, guide, step };\n};\n"],"names":["useGuide","filters","context","useGuideContext","key","type","Error","client","colorMode","guide","useStore","store","state","select","step","steps","find","s","message","archived_at"],"mappings":";;AAcaA,MAAAA,IAAWA,CAACC,MAAoD;AAC3E,QAAMC,IAAUC,EAAgB;AAEhC,MAAI,CAACF,EAAQG,OAAO,CAACH,EAAQI;AACrB,UAAA,IAAIC,MACR,oFACF;AAGI,QAAA;AAAA,IAAEC,QAAAA;AAAAA,IAAQC,WAAAA;AAAAA,EAAAA,IAAcN,GAExB,CAACO,CAAK,IAAIC,EAASH,EAAOI,OAAQC,CAAAA,MACtCL,EAAOM,OAAOD,GAAOX,CAAO,CAC9B,GAEMa,IAAOL,KAASA,EAAMM,MAAMC,KAAMC,CAAM,MAAA,CAACA,EAAEC,QAAQC,WAAW;AAE7D,SAAA;AAAA,IAAEZ,QAAAA;AAAAA,IAAQC,WAAAA;AAAAA,IAAWC,OAAAA;AAAAA,IAAOK,MAAAA;AAAAA,EAAK;AAC1C;"}
1
+ {"version":3,"file":"useGuide.mjs","sources":["../../../../../src/modules/guide/hooks/useGuide.ts"],"sourcesContent":["import {\n KnockGuide,\n KnockGuideFilterParams,\n KnockGuideStep,\n} from \"@knocklabs/client\";\nimport { useStore } from \"@tanstack/react-store\";\n\nimport { UseGuideContextReturn, useGuideContext } from \"./useGuideContext\";\n\ninterface UseGuideReturn extends UseGuideContextReturn {\n guide: KnockGuide | undefined;\n step: KnockGuideStep | undefined;\n}\n\nexport const useGuide = (filters: KnockGuideFilterParams): UseGuideReturn => {\n const context = useGuideContext();\n\n if (!filters.key && !filters.type) {\n throw new Error(\n \"useGuide must be given at least one filter: { key?: string; type?: string; }\",\n );\n }\n\n const { client, colorMode } = context;\n\n const guide = useStore(client.store, (state) =>\n client.selectGuide(state, filters),\n );\n\n const step = guide && guide.getStep();\n\n return { client, colorMode, guide, step };\n};\n"],"names":["useGuide","filters","context","useGuideContext","key","type","Error","client","colorMode","guide","useStore","store","state","selectGuide","step","getStep"],"mappings":";;AAcaA,MAAAA,IAAWA,CAACC,MAAoD;AAC3E,QAAMC,IAAUC,EAAgB;AAEhC,MAAI,CAACF,EAAQG,OAAO,CAACH,EAAQI;AACrB,UAAA,IAAIC,MACR,8EACF;AAGI,QAAA;AAAA,IAAEC,QAAAA;AAAAA,IAAQC,WAAAA;AAAAA,EAAAA,IAAcN,GAExBO,IAAQC,EAASH,EAAOI,OAAQC,OACpCL,EAAOM,YAAYD,GAAOX,CAAO,CACnC,GAEMa,IAAOL,KAASA,EAAMM,QAAQ;AAE7B,SAAA;AAAA,IAAER,QAAAA;AAAAA,IAAQC,WAAAA;AAAAA,IAAWC,OAAAA;AAAAA,IAAOK,MAAAA;AAAAA,EAAK;AAC1C;"}
@@ -13,6 +13,8 @@ type Props = {
13
13
  colorMode?: ColorMode;
14
14
  targetParams?: KnockGuideTargetParams;
15
15
  trackLocationFromWindow?: boolean;
16
+ orderResolutionDuration?: number;
17
+ throttleCheckInterval?: number;
16
18
  };
17
19
  export declare const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>>;
18
20
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"KnockGuideProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/guide/context/KnockGuideProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EACZ,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,iBAAiB,oDAElB,CAAC;AAEb,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CA4CvE,CAAC"}
1
+ {"version":3,"file":"KnockGuideProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/guide/context/KnockGuideProvider.tsx"],"names":[],"mappings":"AAAA,OAAc,EACZ,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE,gBAAgB,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,iBAAiB,oDAElB,CAAC;AAEb,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,YAAY,CAAC,EAAE,sBAAsB,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAyDvE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { KnockGuide, KnockGuideFilterParams } from '@knocklabs/client';
2
+ import { UseGuideContextReturn } from './useGuideContext';
3
+ interface UseGuidesReturn extends UseGuideContextReturn {
4
+ guides: KnockGuide[];
5
+ }
6
+ export declare const useGuides: (filters: KnockGuideFilterParams) => UseGuidesReturn;
7
+ export {};
8
+ //# sourceMappingURL=useGuides.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGuides.d.ts","sourceRoot":"","sources":["../../../../../src/modules/guide/hooks/useGuides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAGvE,OAAO,EAAE,qBAAqB,EAAmB,MAAM,mBAAmB,CAAC;AAE3E,UAAU,eAAgB,SAAQ,qBAAqB;IACrD,MAAM,EAAE,UAAU,EAAE,CAAC;CACtB;AAED,eAAO,MAAM,SAAS,GAAI,SAAS,sBAAsB,KAAG,eAS3D,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@knocklabs/react-core",
3
3
  "description": "A set of React components to build notification experiences powered by Knock",
4
4
  "author": "@knocklabs",
5
- "version": "0.7.4",
5
+ "version": "0.8.0",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.mjs",
@@ -47,8 +47,8 @@
47
47
  "react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
48
48
  },
49
49
  "dependencies": {
50
- "@knocklabs/client": "^0.15.1",
51
- "@tanstack/react-store": "^0.7.1",
50
+ "@knocklabs/client": "^0.16.0",
51
+ "@tanstack/react-store": "^0.7.3",
52
52
  "date-fns": "^4.0.0",
53
53
  "fast-deep-equal": "^3.1.3",
54
54
  "swr": "^2.3.3"
@@ -23,6 +23,8 @@ type Props = {
23
23
  colorMode?: ColorMode;
24
24
  targetParams?: KnockGuideTargetParams;
25
25
  trackLocationFromWindow?: boolean;
26
+ orderResolutionDuration?: number; // in milliseconds
27
+ throttleCheckInterval?: number; // in milliseconds
26
28
  };
27
29
 
28
30
  export const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({
@@ -32,6 +34,10 @@ export const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({
32
34
  colorMode = "light",
33
35
  targetParams = {},
34
36
  trackLocationFromWindow = true,
37
+ // Default to 0 which works well for react apps as this "yields" to react for
38
+ // one render cyle first and close the group stage.
39
+ orderResolutionDuration = 0,
40
+ throttleCheckInterval,
35
41
  children,
36
42
  }) => {
37
43
  let knock: Knock;
@@ -47,8 +53,17 @@ export const KnockGuideProvider: React.FC<React.PropsWithChildren<Props>> = ({
47
53
  const knockGuideClient = React.useMemo(() => {
48
54
  return new KnockGuideClient(knock, channelId, stableTargetParams, {
49
55
  trackLocationFromWindow,
56
+ orderResolutionDuration,
57
+ throttleCheckInterval,
50
58
  });
51
- }, [knock, channelId, stableTargetParams, trackLocationFromWindow]);
59
+ }, [
60
+ knock,
61
+ channelId,
62
+ stableTargetParams,
63
+ trackLocationFromWindow,
64
+ orderResolutionDuration,
65
+ throttleCheckInterval,
66
+ ]);
52
67
 
53
68
  React.useEffect(() => {
54
69
  if (readyToTarget) {
@@ -17,17 +17,17 @@ export const useGuide = (filters: KnockGuideFilterParams): UseGuideReturn => {
17
17
 
18
18
  if (!filters.key && !filters.type) {
19
19
  throw new Error(
20
- "useGuide must be used with at least one filter: either a guide key or a guide type",
20
+ "useGuide must be given at least one filter: { key?: string; type?: string; }",
21
21
  );
22
22
  }
23
23
 
24
24
  const { client, colorMode } = context;
25
25
 
26
- const [guide] = useStore(client.store, (state) =>
27
- client.select(state, filters),
26
+ const guide = useStore(client.store, (state) =>
27
+ client.selectGuide(state, filters),
28
28
  );
29
29
 
30
- const step = guide && guide.steps.find((s) => !s.message.archived_at);
30
+ const step = guide && guide.getStep();
31
31
 
32
32
  return { client, colorMode, guide, step };
33
33
  };
@@ -0,0 +1,19 @@
1
+ import { KnockGuide, KnockGuideFilterParams } from "@knocklabs/client";
2
+ import { useStore } from "@tanstack/react-store";
3
+
4
+ import { UseGuideContextReturn, useGuideContext } from "./useGuideContext";
5
+
6
+ interface UseGuidesReturn extends UseGuideContextReturn {
7
+ guides: KnockGuide[];
8
+ }
9
+
10
+ export const useGuides = (filters: KnockGuideFilterParams): UseGuidesReturn => {
11
+ const context = useGuideContext();
12
+ const { client, colorMode } = context;
13
+
14
+ const guides = useStore(client.store, (state) =>
15
+ client.selectGuides(state, filters),
16
+ );
17
+
18
+ return { client, colorMode, guides };
19
+ };