@knocklabs/react-core 0.5.0-rc.0 → 0.5.0-rc.2.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,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## 0.5.0-rc.0
3
+ ## 0.5.0-rc.2.0
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -9,7 +9,7 @@
9
9
  ### Patch Changes
10
10
 
11
11
  - Updated dependencies [0fc5f2d]
12
- - @knocklabs/client@0.12.0-rc.0
12
+ - @knocklabs/client@0.12.0-rc.2.0
13
13
 
14
14
  ## 0.4.0
15
15
 
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function r(e){return e.store}function u(e,t){const o=r(e)();return t?t(o):o}exports.default=u;exports.useCreateNotificationStore=r;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("zustand");function n(e,t){const o=i.useStore(e.store);return u=>{const r=u??t;return r?r(o):o}}function s(e,t){return n(e,t)}exports.default=s;exports.useCreateNotificationStore=n;
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\";\n\n// A hook designed to create a `UseBoundStore` instance.\n// We used to have to do some extra work to do this, but\n// with zustand updated we can just use the feedClient.store\n// directly.\nfunction useCreateNotificationStore(feedClient: Feed) {\n return feedClient.store;\n}\n\n/**\n * Below we do some typing to specify that if a selector is provided,\n * the return type will be the type returned by the selector.\n *\n * This is important because the store state type is not always the same as the\n * return type of the selector.\n *\n */\n\ntype StateSelector<T, U> = (state: T) => U;\ntype FeedStoreStateSelector<T> = StateSelector<FeedStoreState, T>;\n\n// Function overload for when no selector is provided\nfunction useNotificationStore(feedClient: Feed): FeedStoreState;\n\n// Function overload for when a selector is provided\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: FeedStoreStateSelector<T>,\n): T;\n\n/**\n * A hook used to access content within the notification store.\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<T>(\n feedClient: Feed,\n selector?: FeedStoreStateSelector<T>,\n): T | FeedStoreState {\n const useStore = useCreateNotificationStore(feedClient);\n const storeState = useStore();\n return selector ? selector(storeState) : storeState;\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","store","useNotificationStore","selector","storeState"],"mappings":"4GAMA,SAASA,EAA2BC,EAAkB,CACpD,OAAOA,EAAWC,KACpB,CAqCA,SAASC,EACPF,EACAG,EACoB,CAEpB,MAAMC,EADWL,EAA2BC,CAAU,EAC1B,EACrBG,OAAAA,EAAWA,EAASC,CAAU,EAAIA,CAC3C"}
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// A hook designed to create a `UseBoundStore` instance.\n// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\nfunction useCreateNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector: (state: FeedStoreState) => U,\n): U;\n/**\n * Access a Bounded Store instance\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, U = T>(\n feedClient: Feed,\n externalSelector?: (state: FeedStoreState) => U,\n) {\n const store = useStore(feedClient.store);\n\n return (selector?: (state: FeedStoreState) => U) => {\n const innerSelector = selector ?? externalSelector;\n return innerSelector ? innerSelector(store) : store;\n };\n}\n\n/**\n * A hook used to access content within the notification store.\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(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: (state: FeedStoreState) => T,\n): T;\nfunction useNotificationStore<T, U = T>(\n feedClient: Feed,\n selector?: (state: FeedStoreState) => U,\n) {\n return useCreateNotificationStore(feedClient, selector!);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","externalSelector","store","useStore","selector","innerSelector","useNotificationStore"],"mappings":"uIAiBA,SAASA,EACPC,EACAC,EACA,CACMC,MAAAA,EAAQC,EAAAA,SAASH,EAAWE,KAAK,EAEvC,OAAQE,GAA4C,CAClD,MAAMC,EAAgBD,GAAYH,EAC3BI,OAAAA,EAAgBA,EAAcH,CAAK,EAAIA,CAChD,CACF,CAuBA,SAASI,EACPN,EACAI,EACA,CACOL,OAAAA,EAA2BC,EAAYI,CAAS,CACzD"}
@@ -1,12 +1,16 @@
1
- function r(t) {
2
- return t.store;
3
- }
1
+ import { useStore as i } from "zustand";
4
2
  function u(t, e) {
5
- const o = r(t)();
6
- return e ? e(o) : o;
3
+ const o = i(t.store);
4
+ return (n) => {
5
+ const r = n ?? e;
6
+ return r ? r(o) : o;
7
+ };
8
+ }
9
+ function c(t, e) {
10
+ return u(t, e);
7
11
  }
8
12
  export {
9
- u as default,
10
- r as useCreateNotificationStore
13
+ c as default,
14
+ u as useCreateNotificationStore
11
15
  };
12
16
  //# 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\";\n\n// A hook designed to create a `UseBoundStore` instance.\n// We used to have to do some extra work to do this, but\n// with zustand updated we can just use the feedClient.store\n// directly.\nfunction useCreateNotificationStore(feedClient: Feed) {\n return feedClient.store;\n}\n\n/**\n * Below we do some typing to specify that if a selector is provided,\n * the return type will be the type returned by the selector.\n *\n * This is important because the store state type is not always the same as the\n * return type of the selector.\n *\n */\n\ntype StateSelector<T, U> = (state: T) => U;\ntype FeedStoreStateSelector<T> = StateSelector<FeedStoreState, T>;\n\n// Function overload for when no selector is provided\nfunction useNotificationStore(feedClient: Feed): FeedStoreState;\n\n// Function overload for when a selector is provided\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: FeedStoreStateSelector<T>,\n): T;\n\n/**\n * A hook used to access content within the notification store.\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<T>(\n feedClient: Feed,\n selector?: FeedStoreStateSelector<T>,\n): T | FeedStoreState {\n const useStore = useCreateNotificationStore(feedClient);\n const storeState = useStore();\n return selector ? selector(storeState) : storeState;\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","store","useNotificationStore","selector","storeState"],"mappings":"AAMA,SAASA,EAA2BC,GAAkB;AACpD,SAAOA,EAAWC;AACpB;AAqCA,SAASC,EACPF,GACAG,GACoB;AAEpB,QAAMC,IADWL,EAA2BC,CAAU,EAC1B;AACrBG,SAAAA,IAAWA,EAASC,CAAU,IAAIA;AAC3C;"}
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// A hook designed to create a `UseBoundStore` instance.\n// https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\nfunction useCreateNotificationStore(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useCreateNotificationStore<T, U = T>(\n feedClient: Feed,\n externalSelector: (state: FeedStoreState) => U,\n): U;\n/**\n * Access a Bounded Store instance\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, U = T>(\n feedClient: Feed,\n externalSelector?: (state: FeedStoreState) => U,\n) {\n const store = useStore(feedClient.store);\n\n return (selector?: (state: FeedStoreState) => U) => {\n const innerSelector = selector ?? externalSelector;\n return innerSelector ? innerSelector(store) : store;\n };\n}\n\n/**\n * A hook used to access content within the notification store.\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(\n feedClient: Feed,\n): UseBoundStore<StoreApi<FeedStoreState>>;\nfunction useNotificationStore<T>(\n feedClient: Feed,\n selector: (state: FeedStoreState) => T,\n): T;\nfunction useNotificationStore<T, U = T>(\n feedClient: Feed,\n selector?: (state: FeedStoreState) => U,\n) {\n return useCreateNotificationStore(feedClient, selector!);\n}\n\nexport { useCreateNotificationStore };\nexport default useNotificationStore;\n"],"names":["useCreateNotificationStore","feedClient","externalSelector","store","useStore","selector","innerSelector","useNotificationStore"],"mappings":";AAiBA,SAASA,EACPC,GACAC,GACA;AACMC,QAAAA,IAAQC,EAASH,EAAWE,KAAK;AAEvC,SAAO,CAACE,MAA4C;AAClD,UAAMC,IAAgBD,KAAYH;AAC3BI,WAAAA,IAAgBA,EAAcH,CAAK,IAAIA;AAAAA,EAChD;AACF;AAuBA,SAASI,EACPN,GACAI,GACA;AACOL,SAAAA,EAA2BC,GAAYI,CAAS;AACzD;"}
@@ -1,17 +1,23 @@
1
1
  import { Feed, FeedStoreState } from '@knocklabs/client';
2
- declare function useCreateNotificationStore(feedClient: Feed): import('zustand').UseBoundStore<import('zustand').StoreApi<FeedStoreState>>;
2
+ import { StoreApi, UseBoundStore } from 'zustand';
3
+ declare function useCreateNotificationStore(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
4
+ declare function useCreateNotificationStore<T, U = T>(feedClient: Feed, externalSelector: (state: FeedStoreState) => U): U;
3
5
  /**
4
- * Below we do some typing to specify that if a selector is provided,
5
- * the return type will be the type returned by the selector.
6
+ * A hook used to access content within the notification store.
6
7
  *
7
- * This is important because the store state type is not always the same as the
8
- * return type of the selector.
8
+ * A selector can be used to access a subset of the store state.
9
9
  *
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * const { items, metadata } = useNotificationStore(feedClient, (state) => ({
14
+ * items: state.items,
15
+ * metadata: state.metadata,
16
+ * }));
17
+ * ```
10
18
  */
11
- type StateSelector<T, U> = (state: T) => U;
12
- type FeedStoreStateSelector<T> = StateSelector<FeedStoreState, T>;
13
- declare function useNotificationStore(feedClient: Feed): FeedStoreState;
14
- declare function useNotificationStore<T>(feedClient: Feed, selector: FeedStoreStateSelector<T>): T;
19
+ declare function useNotificationStore(feedClient: Feed): UseBoundStore<StoreApi<FeedStoreState>>;
20
+ declare function useNotificationStore<T>(feedClient: Feed, selector: (state: FeedStoreState) => T): T;
15
21
  export { useCreateNotificationStore };
16
22
  export default useNotificationStore;
17
23
  //# 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;AAM9D,iBAAS,0BAA0B,CAAC,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C;AAQL,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.0",
5
+ "version": "0.5.0-rc.2.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.0",
52
+ "@knocklabs/client": "^0.12.0-rc.2.0",
53
53
  "date-fns": "^4.0.0",
54
54
  "swr": "^2.3.2",
55
55
  "zustand": "^4.5.6"
@@ -1,33 +1,31 @@
1
1
  import { Feed, type FeedStoreState } from "@knocklabs/client";
2
+ import { type StoreApi, type UseBoundStore, useStore } from "zustand";
2
3
 
3
4
  // A hook designed to create a `UseBoundStore` instance.
4
- // We used to have to do some extra work to do this, but
5
- // with zustand updated we can just use the feedClient.store
6
- // directly.
7
- function useCreateNotificationStore(feedClient: Feed) {
8
- return feedClient.store;
9
- }
10
-
5
+ // https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores
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;
11
13
  /**
12
- * Below we do some typing to specify that if a selector is provided,
13
- * the return type will be the type returned by the selector.
14
- *
15
- * This is important because the store state type is not always the same as the
16
- * return type of the selector.
17
- *
14
+ * Access a Bounded Store instance
15
+ * Allow passing a selector down from useCreateNotificationStore OR useNotificationStore
16
+ * We'll favor the the one passed later outside of useCreateNotificationStore instantiation
18
17
  */
19
-
20
- type StateSelector<T, U> = (state: T) => U;
21
- type FeedStoreStateSelector<T> = StateSelector<FeedStoreState, T>;
22
-
23
- // Function overload for when no selector is provided
24
- function useNotificationStore(feedClient: Feed): FeedStoreState;
25
-
26
- // Function overload for when a selector is provided
27
- function useNotificationStore<T>(
18
+ function useCreateNotificationStore<T, U = T>(
28
19
  feedClient: Feed,
29
- selector: FeedStoreStateSelector<T>,
30
- ): T;
20
+ externalSelector?: (state: FeedStoreState) => U,
21
+ ) {
22
+ const store = useStore(feedClient.store);
23
+
24
+ return (selector?: (state: FeedStoreState) => U) => {
25
+ const innerSelector = selector ?? externalSelector;
26
+ return innerSelector ? innerSelector(store) : store;
27
+ };
28
+ }
31
29
 
32
30
  /**
33
31
  * A hook used to access content within the notification store.
@@ -43,13 +41,18 @@ function useNotificationStore<T>(
43
41
  * }));
44
42
  * ```
45
43
  */
44
+ function useNotificationStore(
45
+ feedClient: Feed,
46
+ ): UseBoundStore<StoreApi<FeedStoreState>>;
46
47
  function useNotificationStore<T>(
47
48
  feedClient: Feed,
48
- selector?: FeedStoreStateSelector<T>,
49
- ): T | FeedStoreState {
50
- const useStore = useCreateNotificationStore(feedClient);
51
- const storeState = useStore();
52
- return selector ? selector(storeState) : storeState;
49
+ selector: (state: FeedStoreState) => T,
50
+ ): T;
51
+ function useNotificationStore<T, U = T>(
52
+ feedClient: Feed,
53
+ selector?: (state: FeedStoreState) => U,
54
+ ) {
55
+ return useCreateNotificationStore(feedClient, selector!);
53
56
  }
54
57
 
55
58
  export { useCreateNotificationStore };