@knocklabs/react-core 0.7.5 → 0.8.1
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 +21 -0
- package/dist/cjs/modules/guide/context/KnockGuideProvider.js +1 -1
- package/dist/cjs/modules/guide/context/KnockGuideProvider.js.map +1 -1
- package/dist/cjs/modules/guide/hooks/useGuide.js +1 -1
- package/dist/cjs/modules/guide/hooks/useGuide.js.map +1 -1
- package/dist/esm/modules/guide/context/KnockGuideProvider.mjs +20 -14
- package/dist/esm/modules/guide/context/KnockGuideProvider.mjs.map +1 -1
- package/dist/esm/modules/guide/hooks/useGuide.mjs +8 -8
- package/dist/esm/modules/guide/hooks/useGuide.mjs.map +1 -1
- package/dist/types/modules/guide/context/KnockGuideProvider.d.ts +2 -0
- package/dist/types/modules/guide/context/KnockGuideProvider.d.ts.map +1 -1
- package/dist/types/modules/guide/hooks/useGuides.d.ts +8 -0
- package/dist/types/modules/guide/hooks/useGuides.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/modules/guide/context/KnockGuideProvider.tsx +16 -1
- package/src/modules/guide/hooks/useGuide.ts +4 -4
- package/src/modules/guide/hooks/useGuides.ts +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [35b5445]
|
|
8
|
+
- Updated dependencies [5d758d7]
|
|
9
|
+
- Updated dependencies [d2fd092]
|
|
10
|
+
- @knocklabs/client@0.16.1
|
|
11
|
+
|
|
12
|
+
## 0.8.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 48e9c77: - Support guides ordering and throttle settings
|
|
17
|
+
- Add `useGuides` hook
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [48e9c77]
|
|
22
|
+
- @knocklabs/client@0.16.0
|
|
23
|
+
|
|
3
24
|
## 0.7.5
|
|
4
25
|
|
|
5
26
|
### 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 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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
4
|
+
import K from "../../core/hooks/useStableOptions.mjs";
|
|
5
5
|
import "date-fns";
|
|
6
|
-
const
|
|
6
|
+
const a = t.createContext(void 0), w = ({
|
|
7
7
|
channelId: o,
|
|
8
8
|
readyToTarget: i,
|
|
9
9
|
listenForUpdates: n = !0,
|
|
10
|
-
colorMode:
|
|
11
|
-
targetParams:
|
|
10
|
+
colorMode: f = "light",
|
|
11
|
+
targetParams: k = {},
|
|
12
12
|
trackLocationFromWindow: c = !0,
|
|
13
|
-
|
|
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
|
|
22
|
-
trackLocationFromWindow: c
|
|
23
|
-
|
|
24
|
-
|
|
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:
|
|
27
|
-
} },
|
|
32
|
+
colorMode: f
|
|
33
|
+
} }, p);
|
|
28
34
|
};
|
|
29
35
|
export {
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
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
|
|
1
|
+
import { useStore as u } from "@tanstack/react-store";
|
|
2
2
|
import { useGuideContext as c } from "./useGuideContext.mjs";
|
|
3
|
-
const
|
|
3
|
+
const g = (e) => {
|
|
4
4
|
const r = c();
|
|
5
5
|
if (!e.key && !e.type)
|
|
6
|
-
throw new Error("useGuide must be
|
|
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:
|
|
10
|
-
} = r,
|
|
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:
|
|
13
|
+
colorMode: n,
|
|
14
14
|
guide: o,
|
|
15
|
-
step:
|
|
15
|
+
step: s
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
export {
|
|
19
|
-
|
|
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
|
|
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;
|
|
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.
|
|
5
|
+
"version": "0.8.1",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@knocklabs/client": "^0.
|
|
50
|
+
"@knocklabs/client": "^0.16.1",
|
|
51
51
|
"@tanstack/react-store": "^0.7.3",
|
|
52
52
|
"date-fns": "^4.0.0",
|
|
53
53
|
"fast-deep-equal": "^3.1.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
|
-
}, [
|
|
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
|
|
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
|
|
27
|
-
client.
|
|
26
|
+
const guide = useStore(client.store, (state) =>
|
|
27
|
+
client.selectGuide(state, filters),
|
|
28
28
|
);
|
|
29
29
|
|
|
30
|
-
const step = guide && guide.
|
|
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
|
+
};
|