@knocklabs/react-core 0.5.0-rc.1.0 → 0.5.0-rc.3.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 +2 -2
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +7 -11
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -1
- package/dist/types/modules/feed/hooks/index.d.ts +1 -1
- package/dist/types/modules/feed/hooks/index.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +16 -4
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/modules/feed/hooks/index.ts +1 -0
- package/src/modules/feed/hooks/useNotificationStore.ts +23 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("zustand");function r(e){return u=>n.useStore(e.store,u??(t=>t))}function s(e,o){return r(e)(o??(t=>t))}exports.default=s;exports.useCreateNotificationStore=r;
|
|
2
2
|
//# sourceMappingURL=useNotificationStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\n
|
|
1
|
+
{"version":3,"file":"useNotificationStore.js","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\nexport type Selector<T> = (state: FeedStoreState) => T;\n\n/**\n * Access a Bounded Store instance by converting our vanilla store to a UseBoundStore\n * https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T>(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>> {\n // Keep selector optional for external use\n // useStore requires a selector so we'll pass in a default one when not provided\n const useBoundedStore = (selector?: Selector<T>) =>\n useStore(feedClient.store, selector ?? ((state) => state as T));\n return useBoundedStore as UseBoundStore<StoreApi<FeedStoreState>>;\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient);\n * ```\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(feedClient: Feed): FeedStoreState;\nfunction useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector?: Selector<T>,\n): T | FeedStoreState {\n const useStoreLocal = useCreateNotificationStore(feedClient);\n return useStoreLocal(selector ?? ((state) => state as T));\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","useBoundedStore","selector","useStore","store","state","useNotificationStore","useStoreLocal"],"mappings":"uIAWA,SAASA,EACPC,EACyC,CAKlCC,OAFkBC,GACvBC,WAASH,EAAWI,MAAOF,OAAwBG,EAAW,CAElE,CAwBA,SAASC,EACPN,EACAE,EACoB,CAEbK,OADeR,EAA2BC,CAAU,EACtCE,IAAcG,GAAUA,EAAW,CAC1D"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import { useStore as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
return (n) => {
|
|
5
|
-
const r = n ?? e;
|
|
6
|
-
return r ? r(o) : o;
|
|
7
|
-
};
|
|
1
|
+
import { useStore as u } from "zustand";
|
|
2
|
+
function n(e) {
|
|
3
|
+
return (r) => u(e.store, r ?? ((o) => o));
|
|
8
4
|
}
|
|
9
|
-
function
|
|
10
|
-
return
|
|
5
|
+
function i(e, t) {
|
|
6
|
+
return n(e)(t ?? ((o) => o));
|
|
11
7
|
}
|
|
12
8
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
i as default,
|
|
10
|
+
n as useCreateNotificationStore
|
|
15
11
|
};
|
|
16
12
|
//# sourceMappingURL=useNotificationStore.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\n
|
|
1
|
+
{"version":3,"file":"useNotificationStore.mjs","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"sourcesContent":["import { Feed, type FeedStoreState } from \"@knocklabs/client\";\nimport { type StoreApi, type UseBoundStore, useStore } from \"zustand\";\n\nexport type Selector<T> = (state: FeedStoreState) => T;\n\n/**\n * Access a Bounded Store instance by converting our vanilla store to a UseBoundStore\n * https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore\n * We'll favor the the one passed later outside of useCreateNotificationStore instantiation\n */\nfunction useCreateNotificationStore<T>(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>> {\n // Keep selector optional for external use\n // useStore requires a selector so we'll pass in a default one when not provided\n const useBoundedStore = (selector?: Selector<T>) =>\n useStore(feedClient.store, selector ?? ((state) => state as T));\n return useBoundedStore as UseBoundStore<StoreApi<FeedStoreState>>;\n}\n\n/**\n * A hook used to access content within the notification store.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient);\n * ```\n *\n * A selector can be used to access a subset of the store state.\n *\n * @example\n *\n * ```ts\n * const { items, metadata } = useNotificationStore(feedClient, (state) => ({\n * items: state.items,\n * metadata: state.metadata,\n * }));\n * ```\n */\nfunction useNotificationStore(feedClient: Feed): FeedStoreState;\nfunction useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector?: Selector<T>,\n): T | FeedStoreState {\n const useStoreLocal = useCreateNotificationStore(feedClient);\n return useStoreLocal(selector ?? ((state) => state as T));\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","useBoundedStore","selector","useStore","store","state","useNotificationStore","useStoreLocal"],"mappings":";AAWA,SAASA,EACPC,GACyC;AAKlCC,SAFiBA,CAACC,MACvBC,EAASH,EAAWI,OAAOF,MAAcG,OAAUA,EAAW;AAElE;AAwBA,SAASC,EACPN,GACAE,GACoB;AAEbK,SADeR,EAA2BC,CAAU,EACtCE,MAAcG,CAAAA,MAAUA,EAAW;AAC1D;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as useNotifications } from './useNotifications';
|
|
2
2
|
export { default as useFeedSettings } from './useFeedSettings';
|
|
3
|
-
export { default as useNotificationStore, useCreateNotificationStore, } from './useNotificationStore';
|
|
3
|
+
export { default as useNotificationStore, useCreateNotificationStore, type Selector, } from './useNotificationStore';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,OAAO,IAAI,oBAAoB,EAC/B,0BAA0B,EAC1B,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { Feed, FeedStoreState } from '@knocklabs/client';
|
|
2
2
|
import { StoreApi, UseBoundStore } from 'zustand';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export type Selector<T> = (state: FeedStoreState) => T;
|
|
4
|
+
/**
|
|
5
|
+
* Access a Bounded Store instance by converting our vanilla store to a UseBoundStore
|
|
6
|
+
* https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
7
|
+
* Allow passing a selector down from useCreateNotificationStore OR useNotificationStore
|
|
8
|
+
* We'll favor the the one passed later outside of useCreateNotificationStore instantiation
|
|
9
|
+
*/
|
|
10
|
+
declare function useCreateNotificationStore<T>(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
5
11
|
/**
|
|
6
12
|
* A hook used to access content within the notification store.
|
|
7
13
|
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* const { items, metadata } = useNotificationStore(feedClient);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
8
20
|
* A selector can be used to access a subset of the store state.
|
|
9
21
|
*
|
|
10
22
|
* @example
|
|
@@ -16,8 +28,8 @@ declare function useCreateNotificationStore<T, U = T>(feedClient: Feed, external
|
|
|
16
28
|
* }));
|
|
17
29
|
* ```
|
|
18
30
|
*/
|
|
19
|
-
declare function useNotificationStore(feedClient: Feed):
|
|
20
|
-
declare function useNotificationStore<T>(feedClient: Feed, selector:
|
|
31
|
+
declare function useNotificationStore(feedClient: Feed): FeedStoreState;
|
|
32
|
+
declare function useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;
|
|
21
33
|
export { useCreateNotificationStore };
|
|
22
34
|
export default useNotificationStore;
|
|
23
35
|
//# sourceMappingURL=useNotificationStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAY,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useNotificationStore.d.ts","sourceRoot":"","sources":["../../../../../src/modules/feed/hooks/useNotificationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAY,MAAM,SAAS,CAAC;AAEtE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,cAAc,KAAK,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,iBAAS,0BAA0B,CAAC,CAAC,EACnC,UAAU,EAAE,IAAI,GACf,aAAa,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAMzC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,oBAAoB,CAAC,UAAU,EAAE,IAAI,GAAG,cAAc,CAAC;AAChE,iBAAS,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAS7E,OAAO,EAAE,0BAA0B,EAAE,CAAC;AACtC,eAAe,oBAAoB,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.0-rc.
|
|
5
|
+
"version": "0.5.0-rc.3.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@knocklabs/client": "^0.12.0-rc.
|
|
52
|
+
"@knocklabs/client": "^0.12.0-rc.3.0",
|
|
53
53
|
"date-fns": "^4.0.0",
|
|
54
54
|
"swr": "^2.3.2",
|
|
55
55
|
"zustand": "^4.5.6"
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import { Feed, type FeedStoreState } from "@knocklabs/client";
|
|
2
2
|
import { type StoreApi, type UseBoundStore, useStore } from "zustand";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function useCreateNotificationStore(
|
|
7
|
-
feedClient: Feed,
|
|
8
|
-
): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
9
|
-
function useCreateNotificationStore<T, U = T>(
|
|
10
|
-
feedClient: Feed,
|
|
11
|
-
externalSelector: (state: FeedStoreState) => U,
|
|
12
|
-
): U;
|
|
4
|
+
export type Selector<T> = (state: FeedStoreState) => T;
|
|
5
|
+
|
|
13
6
|
/**
|
|
14
|
-
* Access a Bounded Store instance
|
|
7
|
+
* Access a Bounded Store instance by converting our vanilla store to a UseBoundStore
|
|
8
|
+
* https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
15
9
|
* Allow passing a selector down from useCreateNotificationStore OR useNotificationStore
|
|
16
10
|
* We'll favor the the one passed later outside of useCreateNotificationStore instantiation
|
|
17
11
|
*/
|
|
18
|
-
function useCreateNotificationStore<T
|
|
12
|
+
function useCreateNotificationStore<T>(
|
|
19
13
|
feedClient: Feed,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return innerSelector ? innerSelector(store) : store;
|
|
27
|
-
};
|
|
14
|
+
): UseBoundStore<StoreApi<FeedStoreState>> {
|
|
15
|
+
// Keep selector optional for external use
|
|
16
|
+
// useStore requires a selector so we'll pass in a default one when not provided
|
|
17
|
+
const useBoundedStore = (selector?: Selector<T>) =>
|
|
18
|
+
useStore(feedClient.store, selector ?? ((state) => state as T));
|
|
19
|
+
return useBoundedStore as UseBoundStore<StoreApi<FeedStoreState>>;
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
/**
|
|
31
23
|
* A hook used to access content within the notification store.
|
|
32
24
|
*
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const { items, metadata } = useNotificationStore(feedClient);
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
33
31
|
* A selector can be used to access a subset of the store state.
|
|
34
32
|
*
|
|
35
33
|
* @example
|
|
@@ -41,18 +39,14 @@ function useCreateNotificationStore<T, U = T>(
|
|
|
41
39
|
* }));
|
|
42
40
|
* ```
|
|
43
41
|
*/
|
|
44
|
-
function useNotificationStore(
|
|
45
|
-
|
|
46
|
-
): UseBoundStore<StoreApi<FeedStoreState>>;
|
|
42
|
+
function useNotificationStore(feedClient: Feed): FeedStoreState;
|
|
43
|
+
function useNotificationStore<T>(feedClient: Feed, selector: Selector<T>): T;
|
|
47
44
|
function useNotificationStore<T>(
|
|
48
45
|
feedClient: Feed,
|
|
49
|
-
selector
|
|
50
|
-
): T
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
selector?: (state: FeedStoreState) => U,
|
|
54
|
-
) {
|
|
55
|
-
return useCreateNotificationStore(feedClient, selector!);
|
|
46
|
+
selector?: Selector<T>,
|
|
47
|
+
): T | FeedStoreState {
|
|
48
|
+
const useStoreLocal = useCreateNotificationStore(feedClient);
|
|
49
|
+
return useStoreLocal(selector ?? ((state) => state as T));
|
|
56
50
|
}
|
|
57
51
|
|
|
58
52
|
export { useCreateNotificationStore };
|