@jpmorganchase/mosaic-store 0.1.0-beta.11 → 0.1.0-beta.12

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.
Files changed (55) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/CHANGELOG.md +7 -0
  3. package/dist/chunk-5G75LNTO.js +1 -0
  4. package/dist/{chunk-HUOJOLKA.js → chunk-FTFVN4S3.js} +1 -1
  5. package/dist/{chunk-TESIWQVD.js → chunk-GG4KZ7Z6.js} +1 -1
  6. package/dist/chunk-N6Q3GQDQ.js +1 -0
  7. package/dist/chunk-NEIN7MAT.js +1 -0
  8. package/dist/chunk-OC2YQSBN.js +1 -0
  9. package/dist/chunk-PNYO3347.js +1 -0
  10. package/dist/{chunk-N4CAMXVV.js → chunk-T4F7TF3E.js} +1 -1
  11. package/dist/{chunk-GJU2RNS6.js → chunk-UMJOUVJQ.js} +1 -1
  12. package/dist/{chunk-SEY6KBKT.js → chunk-VFFDF2MZ.js} +1 -1
  13. package/dist/chunk-VRIJA4FE.js +1 -0
  14. package/dist/chunk-XXDRCMNC.js +1 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.js +1 -1
  17. package/dist/store.d.ts +29 -3
  18. package/dist/store.js +1 -1
  19. package/dist/types/colorMode.d.ts +3 -0
  20. package/dist/types/colorMode.js +1 -0
  21. package/dist/types/index.js +1 -1
  22. package/dist/useAppHeader.js +1 -1
  23. package/dist/useBreadcrumbs.js +1 -1
  24. package/dist/useColorMode.d.ts +2 -0
  25. package/dist/useColorMode.js +1 -0
  26. package/dist/useFooter.js +1 -1
  27. package/dist/useLayout.js +1 -1
  28. package/dist/useMeta.js +1 -1
  29. package/dist/useNextPrev.js +1 -1
  30. package/dist/useRoute.js +1 -1
  31. package/dist/useSidebar.js +1 -1
  32. package/dist/useStoreActions.d.ts +3 -0
  33. package/dist/useStoreActions.js +1 -0
  34. package/dist/useTableOfContents.js +1 -1
  35. package/package.json +13 -7
  36. package/src/__tests__/store.test.ts +31 -11
  37. package/src/__tests__/useAppHeader.test.ts +1 -1
  38. package/src/__tests__/useBreadcrumbs.test.ts +1 -1
  39. package/src/__tests__/useColorMode.test.ts +12 -0
  40. package/src/__tests__/useFooter.test.ts +1 -1
  41. package/src/__tests__/useLayout.test.ts +1 -1
  42. package/src/__tests__/useMeta.test.ts +1 -1
  43. package/src/__tests__/useRoute.test.ts +1 -1
  44. package/src/__tests__/useStoreActions.test.ts +35 -0
  45. package/src/__tests__/useTableOfContents.test.ts +3 -2
  46. package/src/index.ts +2 -0
  47. package/src/store.ts +35 -13
  48. package/src/types/colorMode.ts +4 -0
  49. package/src/useColorMode.ts +8 -0
  50. package/src/useStoreActions.ts +2 -0
  51. package/dist/chunk-62CYUXGR.js +0 -1
  52. package/dist/chunk-C6AHZ6P3.js +0 -1
  53. package/dist/chunk-IJYHRP3M.js +0 -1
  54. package/dist/chunk-JHTRJDHH.js +0 -1
  55. package/dist/chunk-QPSCMC27.js +0 -1
@@ -1,4 +1,4 @@
1
- @jpmorganchase/mosaic-store:build: cache hit, replaying output 3a949064c5eccbee
1
+ @jpmorganchase/mosaic-store:build: cache hit, replaying output bddcb64e07a19780
2
2
  @jpmorganchase/mosaic-store:build: $ npm-run-all --parallel build:*
3
- @jpmorganchase/mosaic-store:build: $ node ../../scripts/bundle.js
4
3
  @jpmorganchase/mosaic-store:build: $ tsc
4
+ @jpmorganchase/mosaic-store:build: $ node ../../scripts/bundle.js
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @jpmorganchase/mosaic-store
2
2
 
3
+ ## 0.1.0-beta.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 9ec358b: Upgrade React to version 18 and NextJs to version 13
8
+ - 3eb35bf: initial work to enable generators to run outside of the repo
9
+
3
10
  ## 0.1.0-beta.11
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1 @@
1
+ import{d as e}from"./chunk-VRIJA4FE.js";function u(){return{route:e(t=>t.route)}}export{u as a};
@@ -1 +1 @@
1
- import{d as i}from"./chunk-C6AHZ6P3.js";function u(e){return e.links!==void 0}function d(e){return e.link!==void 0}var o=e=>e?process.env[`SEARCH_ENDPOINT_${e}`]||"":process.env.SEARCH_ENDPOINT;function c(){let e=i(n=>n.sharedConfig?.header);if(!e)return;let t={};e.searchNamespace&&(t={HeaderControlsProps:{searchEndpoint:o(e.searchNamespace)}});let s=e.menu.reduce((n,r)=>{if(u(r)){let p={...r,type:"menu"};return[...n,p]}if(d(r)){let p={...r,type:"link"};return[...n,p]}return console.error("Unknown menu type passed to useAppHeader, ignoring",r),n},[]);return{...t,...e,menu:s}}export{c as a};
1
+ import{d as i}from"./chunk-VRIJA4FE.js";function u(e){return e.links!==void 0}function d(e){return e.link!==void 0}var o=e=>e?process.env[`SEARCH_ENDPOINT_${e}`]||"":process.env.SEARCH_ENDPOINT;function c(){let e=i(n=>n.sharedConfig?.header);if(!e)return;let t={};e.searchNamespace&&(t={HeaderControlsProps:{searchEndpoint:o(e.searchNamespace)}});let s=e.menu.reduce((n,r)=>{if(u(r)){let p={...r,type:"menu"};return[...n,p]}if(d(r)){let p={...r,type:"link"};return[...n,p]}return console.error("Unknown menu type passed to useAppHeader, ignoring",r),n},[]);return{...t,...e,menu:s}}export{c as a};
@@ -1 +1 @@
1
- import{a as i}from"./chunk-JHTRJDHH.js";import{d as o}from"./chunk-C6AHZ6P3.js";function N(){let t=o(s=>s.sidebarData)||[],{route:e}=i(),{next:r,prev:n}=d(t,e||"");return{next:r,prev:n}}var a=t=>{let e=[];return t.forEach(r=>{e.push({link:r.data.link,text:r.name}),r.childNodes&&(e=e.concat(a(r.childNodes)))}),e},u=(t,e)=>t>=0&&t<e-1,l=(t,e)=>t>0&&t<e,x=(t,e)=>{let r=t.map(m=>m.link).indexOf(e),{length:n}=t,s=u(r,n)?t[r+1]:null,c=l(r,n)?t[r-1]:null;return{next:s,prev:c}},d=(t,e)=>{let r=a(t);return x(r,e)};export{N as a};
1
+ import{a as i}from"./chunk-5G75LNTO.js";import{d as o}from"./chunk-VRIJA4FE.js";function N(){let t=o(s=>s.sidebarData)||[],{route:e}=i(),{next:r,prev:n}=d(t,e||"");return{next:r,prev:n}}var a=t=>{let e=[];return t.forEach(r=>{e.push({link:r.data.link,text:r.name}),r.childNodes&&(e=e.concat(a(r.childNodes)))}),e},u=(t,e)=>t>=0&&t<e-1,l=(t,e)=>t>0&&t<e,x=(t,e)=>{let r=t.map(m=>m.link).indexOf(e),{length:n}=t,s=u(r,n)?t[r+1]:null,c=l(r,n)?t[r-1]:null;return{next:s,prev:c}},d=(t,e)=>{let r=a(t);return x(r,e)};export{N as a};
@@ -0,0 +1 @@
1
+ import{d as t}from"./chunk-VRIJA4FE.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};
@@ -0,0 +1 @@
1
+ import{d as t}from"./chunk-VRIJA4FE.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
@@ -0,0 +1 @@
1
+ import{d as o}from"./chunk-VRIJA4FE.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
@@ -0,0 +1 @@
1
+ import{d as o}from"./chunk-VRIJA4FE.js";function d(){return o(r=>r.colorMode)}export{d as a};
@@ -1 +1 @@
1
- import{d as e}from"./chunk-C6AHZ6P3.js";function m(t=1){let r=e(b=>b.breadcrumbs);return{breadcrumbs:r||[],enabled:r?.length>t}}export{m as a};
1
+ import{d as e}from"./chunk-VRIJA4FE.js";function m(t=1){let r=e(b=>b.breadcrumbs);return{breadcrumbs:r||[],enabled:r?.length>t}}export{m as a};
@@ -1 +1 @@
1
- import{d as t}from"./chunk-C6AHZ6P3.js";function o(){return{meta:t(e=>({description:e.description,breadcrumbs:e.breadcrumbs,title:e.title}))}}export{o as a};
1
+ import{d as t}from"./chunk-VRIJA4FE.js";function o(){return{meta:t(e=>({description:e.description,breadcrumbs:e.breadcrumbs,title:e.title}))}}export{o as a};
@@ -1 +1 @@
1
- import{a as o}from"./chunk-N4CAMXVV.js";import{a as s}from"./chunk-JHTRJDHH.js";import{d as t}from"./chunk-C6AHZ6P3.js";function b(){let r=t(u=>u.sidebarData)||[],{route:e}=s(),{breadcrumbs:d}=o();return{sidebarData:r,selectedNodeId:e,expandedNodeIds:a(d)}}function a(r){return new Set(r.map(({id:e})=>e.substr(0,e.lastIndexOf("."))))}export{b as a};
1
+ import{a as s}from"./chunk-5G75LNTO.js";import{a as o}from"./chunk-T4F7TF3E.js";import{d as t}from"./chunk-VRIJA4FE.js";function b(){let r=t(u=>u.sidebarData)||[],{route:e}=s(),{breadcrumbs:d}=o();return{sidebarData:r,selectedNodeId:e,expandedNodeIds:a(d)}}function a(r){return new Set(r.map(({id:e})=>e.substr(0,e.lastIndexOf("."))))}export{b as a};
@@ -0,0 +1 @@
1
+ import{useLayoutEffect as s,createContext as S,useContext as d}from"react";import{createStore as l,useStore as c}from"zustand";import{devtools as f,persist as u}from"zustand/middleware";var r;function p(){return{breadcrumbs:[],sidebarData:[],tableOfContents:[],sharedConfig:{},description:void 0,layout:void 0,route:void 0,title:void 0,colorMode:"light"}}var n=S(void 0),g=n.Provider,m=e=>f(u(e,{name:"mosaic-theme-pref",partialize:t=>({colorMode:t.colorMode})})),i=(e={})=>l(m(o=>({...p(),...e,actions:{setColorMode:a=>o({colorMode:a})}})));function h(e,t=!1){if(typeof window>"u"||t)return()=>i(e);let o=Boolean(r);return r=r??i(e),s(()=>{e&&o&&r.setState({...r.getState(),...e},!0)}),()=>r}function P(e,t){let o=d(n);if(!o)throw new Error("Missing StoreProvider in the tree");return c(o,e,t)}export{g as a,i as b,h as c,P as d};
@@ -0,0 +1 @@
1
+ import{d as o}from"./chunk-VRIJA4FE.js";var r=()=>o(t=>t.actions);export{r as a};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './store';
2
2
  export * from './useAppHeader';
3
3
  export * from './useBreadcrumbs';
4
+ export * from './useColorMode';
4
5
  export * from './useLayout';
5
6
  export * from './useMeta';
6
7
  export * from './useNextPrev';
@@ -8,4 +9,5 @@ export * from './useRoute';
8
9
  export * from './useSidebar';
9
10
  export * from './useTableOfContents';
10
11
  export * from './useFooter';
12
+ export * from './useStoreActions';
11
13
  export * from './types';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as d}from"./chunk-SEY6KBKT.js";import{a as g}from"./chunk-QPSCMC27.js";import{a as p}from"./chunk-HUOJOLKA.js";import"./chunk-ASPK4M5R.js";import"./chunk-BZYGOU7Y.js";import"./chunk-UGD4MMRB.js";import"./chunk-BHMVW2ZZ.js";import"./chunk-5L7EI47O.js";import"./chunk-MBLLQB7A.js";import"./chunk-ZJYDN5YH.js";import{a as m}from"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import"./chunk-UK5NIPTI.js";import"./chunk-ZYJGHEAC.js";import{a as t}from"./chunk-N4CAMXVV.js";import{a as h}from"./chunk-62CYUXGR.js";import{a as x}from"./chunk-IJYHRP3M.js";import{a}from"./chunk-GJU2RNS6.js";import{a as c}from"./chunk-TESIWQVD.js";import{a as b}from"./chunk-JHTRJDHH.js";import{a as o,b as r,c as e,d as f}from"./chunk-C6AHZ6P3.js";export{m as MenuItemType,o as StoreProvider,r as initializeStore,p as useAppHeader,t as useBreadcrumbs,e as useCreateStore,h as useFooter,x as useLayout,a as useMeta,c as useNextPrev,b as useRoute,d as useSidebar,f as useStore,g as useTableOfContents};
1
+ import{a as d}from"./chunk-GG4KZ7Z6.js";import{a as g}from"./chunk-VFFDF2MZ.js";import{a as c}from"./chunk-5G75LNTO.js";import{a as j}from"./chunk-XXDRCMNC.js";import{a as h}from"./chunk-N6Q3GQDQ.js";import{a as p}from"./chunk-FTFVN4S3.js";import"./chunk-ASPK4M5R.js";import"./chunk-ZJYDN5YH.js";import"./chunk-UK5NIPTI.js";import"./chunk-ZYJGHEAC.js";import"./chunk-BZYGOU7Y.js";import"./chunk-UGD4MMRB.js";import"./chunk-BHMVW2ZZ.js";import"./chunk-5L7EI47O.js";import"./chunk-MBLLQB7A.js";import{a as m}from"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import{a as t}from"./chunk-T4F7TF3E.js";import{a as x}from"./chunk-PNYO3347.js";import{a as i}from"./chunk-OC2YQSBN.js";import{a}from"./chunk-NEIN7MAT.js";import{a as b}from"./chunk-UMJOUVJQ.js";import{a as o,b as r,c as e,d as f}from"./chunk-VRIJA4FE.js";export{m as MenuItemType,o as StoreProvider,r as initializeStore,p as useAppHeader,t as useBreadcrumbs,x as useColorMode,e as useCreateStore,i as useFooter,a as useLayout,b as useMeta,d as useNextPrev,c as useRoute,g as useSidebar,f as useStore,j as useStoreActions,h as useTableOfContents};
package/dist/store.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { SharedConfigSlice } from './types/sharedConfig';
5
5
  import type { LayoutSlice } from './types/layout';
6
6
  import type { SidebarSlice } from './types/sidebar';
7
7
  import type { TableOfContentsSlice } from './types/tableOfContents';
8
+ import type { ColorMode } from './types/colorMode';
8
9
  export declare type SiteState = BreadcrumbsSlice & LayoutSlice & SidebarSlice & TableOfContentsSlice & SharedConfigSlice & {
9
10
  /** Page metadata description, used by search */
10
11
  description?: string;
@@ -12,18 +13,43 @@ export declare type SiteState = BreadcrumbsSlice & LayoutSlice & SidebarSlice &
12
13
  route?: string;
13
14
  /** Page title */
14
15
  title?: string;
16
+ colorMode: ColorMode;
17
+ actions: {
18
+ setColorMode: (colorMode: ColorMode) => void;
19
+ };
15
20
  };
21
+ declare type PeristedStoreState = Pick<SiteState, 'colorMode'>;
16
22
  declare const StoreProvider: import("react").Provider<StoreApi<SiteState> | undefined>;
17
- declare const initializeStore: (preloadedState?: Partial<SiteState>) => Omit<StoreApi<SiteState>, "setState"> & {
23
+ declare const initializeStore: (preloadedState?: Partial<SiteState>) => Omit<Omit<StoreApi<SiteState>, "setState"> & {
18
24
  setState<A extends string | {
19
25
  type: unknown;
20
26
  }>(partial: SiteState | Partial<SiteState> | ((state: SiteState) => SiteState | Partial<SiteState>), replace?: boolean | undefined, action?: A | undefined): void;
27
+ }, "persist"> & {
28
+ persist: {
29
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SiteState, PeristedStoreState>>) => void;
30
+ clearStorage: () => void;
31
+ rehydrate: () => void | Promise<void>;
32
+ hasHydrated: () => boolean;
33
+ onHydrate: (fn: (state: SiteState) => void) => () => void;
34
+ onFinishHydration: (fn: (state: SiteState) => void) => () => void;
35
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<SiteState, PeristedStoreState>>;
36
+ };
21
37
  };
22
- declare function useCreateStore(serverInitialState: Partial<SiteState>, isSSR?: boolean): () => Omit<StoreApi<SiteState>, "setState"> & {
38
+ declare function useCreateStore(serverInitialState: Partial<SiteState>, isSSR?: boolean): (() => Omit<Omit<StoreApi<SiteState>, "setState"> & {
23
39
  setState<A extends string | {
24
40
  type: unknown;
25
41
  }>(partial: SiteState | Partial<SiteState> | ((state: SiteState) => SiteState | Partial<SiteState>), replace?: boolean | undefined, action?: A | undefined): void;
26
- };
42
+ }, "persist"> & {
43
+ persist: {
44
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SiteState, PeristedStoreState>>) => void;
45
+ clearStorage: () => void;
46
+ rehydrate: () => void | Promise<void>;
47
+ hasHydrated: () => boolean;
48
+ onHydrate: (fn: (state: SiteState) => void) => () => void;
49
+ onFinishHydration: (fn: (state: SiteState) => void) => () => void;
50
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<SiteState, PeristedStoreState>>;
51
+ };
52
+ }) | (() => StoreApi<SiteState>);
27
53
  /**
28
54
  * Hook providing access to state stored in the site store
29
55
  */
package/dist/store.js CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d}from"./chunk-C6AHZ6P3.js";export{a as StoreProvider,b as initializeStore,c as useCreateStore,d as useStore};
1
+ import{a,b,c,d}from"./chunk-VRIJA4FE.js";export{a as StoreProvider,b as initializeStore,c as useCreateStore,d as useStore};
@@ -0,0 +1,3 @@
1
+ export declare const lightMode = "light";
2
+ export declare const darkMode = "dark";
3
+ export declare type ColorMode = typeof lightMode | typeof darkMode;
@@ -0,0 +1 @@
1
+ var o="light",e="dark";export{e as darkMode,o as lightMode};
@@ -1 +1 @@
1
- import"../chunk-ASPK4M5R.js";import"../chunk-BZYGOU7Y.js";import"../chunk-UGD4MMRB.js";import"../chunk-BHMVW2ZZ.js";import"../chunk-5L7EI47O.js";import"../chunk-MBLLQB7A.js";import"../chunk-ZJYDN5YH.js";import{a}from"../chunk-ZMWHBFUG.js";import"../chunk-VXYECVIB.js";import"../chunk-UK5NIPTI.js";import"../chunk-ZYJGHEAC.js";export{a as MenuItemType};
1
+ import"../chunk-ASPK4M5R.js";import"../chunk-ZJYDN5YH.js";import"../chunk-UK5NIPTI.js";import"../chunk-ZYJGHEAC.js";import"../chunk-BZYGOU7Y.js";import"../chunk-UGD4MMRB.js";import"../chunk-BHMVW2ZZ.js";import"../chunk-5L7EI47O.js";import"../chunk-MBLLQB7A.js";import{a}from"../chunk-ZMWHBFUG.js";import"../chunk-VXYECVIB.js";export{a as MenuItemType};
@@ -1 +1 @@
1
- import{a}from"./chunk-HUOJOLKA.js";import"./chunk-ASPK4M5R.js";import"./chunk-BZYGOU7Y.js";import"./chunk-UGD4MMRB.js";import"./chunk-BHMVW2ZZ.js";import"./chunk-5L7EI47O.js";import"./chunk-MBLLQB7A.js";import"./chunk-ZJYDN5YH.js";import"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import"./chunk-UK5NIPTI.js";import"./chunk-ZYJGHEAC.js";import"./chunk-C6AHZ6P3.js";export{a as useAppHeader};
1
+ import{a}from"./chunk-FTFVN4S3.js";import"./chunk-ASPK4M5R.js";import"./chunk-ZJYDN5YH.js";import"./chunk-UK5NIPTI.js";import"./chunk-ZYJGHEAC.js";import"./chunk-BZYGOU7Y.js";import"./chunk-UGD4MMRB.js";import"./chunk-BHMVW2ZZ.js";import"./chunk-5L7EI47O.js";import"./chunk-MBLLQB7A.js";import"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import"./chunk-VRIJA4FE.js";export{a as useAppHeader};
@@ -1 +1 @@
1
- import{a}from"./chunk-N4CAMXVV.js";import"./chunk-C6AHZ6P3.js";export{a as useBreadcrumbs};
1
+ import{a}from"./chunk-T4F7TF3E.js";import"./chunk-VRIJA4FE.js";export{a as useBreadcrumbs};
@@ -0,0 +1,2 @@
1
+ import { ColorMode } from './types/colorMode';
2
+ export declare function useColorMode(): ColorMode;
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-PNYO3347.js";import"./chunk-VRIJA4FE.js";export{a as useColorMode};
package/dist/useFooter.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-62CYUXGR.js";import"./chunk-C6AHZ6P3.js";export{a as useFooter};
1
+ import{a}from"./chunk-OC2YQSBN.js";import"./chunk-VRIJA4FE.js";export{a as useFooter};
package/dist/useLayout.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-IJYHRP3M.js";import"./chunk-C6AHZ6P3.js";export{a as useLayout};
1
+ import{a}from"./chunk-NEIN7MAT.js";import"./chunk-VRIJA4FE.js";export{a as useLayout};
package/dist/useMeta.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-GJU2RNS6.js";import"./chunk-C6AHZ6P3.js";export{a as useMeta};
1
+ import{a}from"./chunk-UMJOUVJQ.js";import"./chunk-VRIJA4FE.js";export{a as useMeta};
@@ -1 +1 @@
1
- import{a}from"./chunk-TESIWQVD.js";import"./chunk-JHTRJDHH.js";import"./chunk-C6AHZ6P3.js";export{a as useNextPrev};
1
+ import{a}from"./chunk-GG4KZ7Z6.js";import"./chunk-5G75LNTO.js";import"./chunk-VRIJA4FE.js";export{a as useNextPrev};
package/dist/useRoute.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-JHTRJDHH.js";import"./chunk-C6AHZ6P3.js";export{a as useRoute};
1
+ import{a}from"./chunk-5G75LNTO.js";import"./chunk-VRIJA4FE.js";export{a as useRoute};
@@ -1 +1 @@
1
- import{a}from"./chunk-SEY6KBKT.js";import"./chunk-N4CAMXVV.js";import"./chunk-JHTRJDHH.js";import"./chunk-C6AHZ6P3.js";export{a as useSidebar};
1
+ import{a}from"./chunk-VFFDF2MZ.js";import"./chunk-5G75LNTO.js";import"./chunk-T4F7TF3E.js";import"./chunk-VRIJA4FE.js";export{a as useSidebar};
@@ -0,0 +1,3 @@
1
+ export declare const useStoreActions: () => {
2
+ setColorMode: (colorMode: import("./types/colorMode").ColorMode) => void;
3
+ };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-XXDRCMNC.js";import"./chunk-VRIJA4FE.js";export{a as useStoreActions};
@@ -1 +1 @@
1
- import{a}from"./chunk-QPSCMC27.js";import"./chunk-C6AHZ6P3.js";export{a as useTableOfContents};
1
+ import{a}from"./chunk-N6Q3GQDQ.js";import"./chunk-VRIJA4FE.js";export{a as useTableOfContents};
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-store",
3
3
  "description": "Mosaic - Store for site configuration",
4
- "version": "0.1.0-beta.11",
4
+ "version": "0.1.0-beta.12",
5
5
  "license": "Apache-2.0",
6
6
  "author": "",
7
+ "type": "module",
7
8
  "main": "./dist/index.js",
8
9
  "types": "./dist/index.d.ts",
9
- "style": "./dist/index.css",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "node": "./dist/index.js"
15
+ }
16
+ },
10
17
  "scripts": {
11
18
  "build": "npm-run-all --parallel build:*",
12
19
  "build:bundle": "node ../../scripts/bundle.js",
@@ -20,13 +27,12 @@
20
27
  "typescript": "^4.8.3"
21
28
  },
22
29
  "dependencies": {
23
- "@testing-library/react": "^12.1.5",
24
- "@testing-library/react-hooks": "8.0.1",
30
+ "@testing-library/react": "^13.4.0",
25
31
  "zustand": "^4.1.1"
26
32
  },
27
33
  "peerDependencies": {
28
- "@types/react": "^16.9.34",
29
- "react": "^16.8.0",
30
- "react-dom": "^16.9.0"
34
+ "@types/react": "^18.0.26",
35
+ "react": "^18.2.0",
36
+ "react-dom": "^18.2.0"
31
37
  }
32
38
  }
@@ -1,13 +1,18 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
- import { initializeStore, useCreateStore, useStore } from '../store';
4
+ import { initializeStore, SiteState, useCreateStore, useStore } from '../store';
5
+
6
+ function getStateToVerify(currentState: SiteState) {
7
+ let { actions, ...stateToVerify } = currentState;
8
+ return stateToVerify;
9
+ }
5
10
 
6
11
  describe('GIVEN the store initializer', () => {
7
12
  describe('WHEN no other state is provided', () => {
8
13
  test('THEN the store api provides the initial default state', () => {
9
14
  const storeApi = initializeStore();
10
- expect(storeApi.getState()).toEqual({
15
+ expect(getStateToVerify(storeApi.getState())).toEqual({
11
16
  breadcrumbs: [],
12
17
  sidebarData: [],
13
18
  tableOfContents: [],
@@ -15,7 +20,8 @@ describe('GIVEN the store initializer', () => {
15
20
  description: undefined,
16
21
  layout: undefined,
17
22
  route: undefined,
18
- title: undefined
23
+ title: undefined,
24
+ colorMode: 'light'
19
25
  });
20
26
  });
21
27
  });
@@ -30,11 +36,13 @@ describe('GIVEN the store initializer', () => {
30
36
  };
31
37
 
32
38
  const storeApi = initializeStore(state);
33
- expect(storeApi.getState()).toEqual({
39
+ expect(getStateToVerify(storeApi.getState())).toEqual({
34
40
  breadcrumbs: [],
35
41
  sidebarData: [],
36
42
  tableOfContents: [],
37
43
  sharedConfig: {},
44
+ colorMode: 'light',
45
+
38
46
  ...state
39
47
  });
40
48
  });
@@ -46,11 +54,14 @@ describe('GIVEN the `useCreateStore` hook', () => {
46
54
  test('THEN the store content is replaced', () => {
47
55
  const state = { layout: 'layout', description: 'des' };
48
56
  const { result, rerender } = renderHook(() => useCreateStore(state));
49
- expect(result.current().getState()).toEqual({
57
+ let currentState = result.current().getState();
58
+
59
+ expect(getStateToVerify(currentState)).toEqual({
50
60
  breadcrumbs: [],
51
61
  sidebarData: [],
52
62
  tableOfContents: [],
53
63
  sharedConfig: {},
64
+ colorMode: 'light',
54
65
  ...state,
55
66
  route: undefined,
56
67
  title: undefined
@@ -61,11 +72,13 @@ describe('GIVEN the `useCreateStore` hook', () => {
61
72
  state.description = 'description';
62
73
  rerender();
63
74
 
64
- expect(result.current().getState()).toEqual({
75
+ currentState = result.current().getState();
76
+ expect(getStateToVerify(currentState)).toEqual({
65
77
  breadcrumbs: [],
66
78
  sidebarData: [],
67
79
  tableOfContents: [],
68
80
  sharedConfig: {},
81
+ colorMode: 'light',
69
82
  description: 'description',
70
83
  layout: 'new',
71
84
  route: undefined,
@@ -78,11 +91,14 @@ describe('GIVEN the `useCreateStore` hook', () => {
78
91
  test('THEN the store is always reinitialized', () => {
79
92
  const state = { layout: 'layout', description: 'des' };
80
93
  const { result, rerender } = renderHook(() => useCreateStore(state, true));
81
- expect(result.current().getState()).toEqual({
94
+ let currentState = result.current().getState();
95
+
96
+ expect(getStateToVerify(currentState)).toEqual({
82
97
  breadcrumbs: [],
83
98
  sidebarData: [],
84
99
  tableOfContents: [],
85
100
  sharedConfig: {},
101
+ colorMode: 'light',
86
102
  ...state,
87
103
  route: undefined,
88
104
  title: undefined
@@ -93,11 +109,14 @@ describe('GIVEN the `useCreateStore` hook', () => {
93
109
  state.description = 'description';
94
110
  rerender();
95
111
 
96
- expect(result.current().getState()).toEqual({
112
+ currentState = result.current().getState();
113
+
114
+ expect(getStateToVerify(currentState)).toEqual({
97
115
  breadcrumbs: [],
98
116
  sidebarData: [],
99
117
  tableOfContents: [],
100
118
  sharedConfig: {},
119
+ colorMode: 'light',
101
120
  description: 'description',
102
121
  layout: 'new',
103
122
  route: undefined,
@@ -119,8 +138,9 @@ describe('GIVEN the `useStore` hook', () => {
119
138
 
120
139
  describe('WHEN rendered outside of the StoreContext', () => {
121
140
  test('THEN the hook throws an error', () => {
122
- const { result } = renderHook(() => useStore(state => state.title));
123
- expect(result.error?.message).toBe('Missing StoreProvider in the tree');
141
+ expect(() => renderHook(() => useStore(state => state.title))).toThrowError(
142
+ 'Missing StoreProvider in the tree'
143
+ );
124
144
  });
125
145
  });
126
146
  });
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
4
  import { useAppHeader } from '../useAppHeader';
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
4
  import { type Breadcrumb, useBreadcrumbs } from '../useBreadcrumbs';
@@ -0,0 +1,12 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import { createWrapper } from './test-utils/utils';
3
+ import { useColorMode } from '../useColorMode';
4
+
5
+ describe('GIVEN the `useColorMode` hook', () => {
6
+ test('THEN the hook returns the colorMode', () => {
7
+ const { result } = renderHook(() => useColorMode(), {
8
+ wrapper: createWrapper()
9
+ });
10
+ expect(result.current).toEqual('light');
11
+ });
12
+ });
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
4
  import { useFooter } from '../useFooter';
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
4
  import { useLayout } from '../useLayout';
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
4
  import { useMeta } from '../useMeta';
@@ -1,4 +1,4 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
4
  import { useRoute } from '../useRoute';
@@ -0,0 +1,35 @@
1
+ import { renderHook, act } from '@testing-library/react';
2
+ import { createWrapper } from './test-utils/utils';
3
+ import { useStoreActions } from '../useStoreActions';
4
+ import { useColorMode } from '../useColorMode';
5
+
6
+ describe('GIVEN the `useStoreActions` hook', () => {
7
+ test('THEN there is a setColorMode action', () => {
8
+ const { result } = renderHook(() => useStoreActions(), {
9
+ wrapper: createWrapper()
10
+ });
11
+ expect(result.current.setColorMode).not.toBeUndefined();
12
+ });
13
+
14
+ describe('AND WHEN the setColorMode action is used', () => {
15
+ test('THEN colorMode is updated', () => {
16
+ const { result: useStoreActionsResult } = renderHook(() => useStoreActions(), {
17
+ wrapper: createWrapper()
18
+ });
19
+
20
+ const { result: useColorModeResult, rerender } = renderHook(() => useColorMode(), {
21
+ wrapper: createWrapper()
22
+ });
23
+
24
+ expect(useColorModeResult.current).toEqual('light');
25
+
26
+ const { setColorMode } = useStoreActionsResult.current;
27
+
28
+ act(() => {
29
+ setColorMode('dark');
30
+ rerender();
31
+ });
32
+ expect(useColorModeResult.current).toEqual('dark');
33
+ });
34
+ });
35
+ });
@@ -1,7 +1,8 @@
1
- import { renderHook } from '@testing-library/react-hooks';
1
+ import { renderHook } from '@testing-library/react';
2
2
 
3
3
  import { createWrapper } from './test-utils/utils';
4
- import { TableOfContentsItem, useTableOfContents } from '../useTableOfContents';
4
+ import { useTableOfContents } from '../useTableOfContents';
5
+ import type { TableOfContentsItem } from '../types/tableOfContents';
5
6
 
6
7
  const tableOfContents: TableOfContentsItem[] = [
7
8
  { level: 2, id: 'what-is-analytics', text: 'What is Analytics' },
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './store';
2
2
  export * from './useAppHeader';
3
3
  export * from './useBreadcrumbs';
4
+ export * from './useColorMode';
4
5
  export * from './useLayout';
5
6
  export * from './useMeta';
6
7
  export * from './useNextPrev';
@@ -8,4 +9,5 @@ export * from './useRoute';
8
9
  export * from './useSidebar';
9
10
  export * from './useTableOfContents';
10
11
  export * from './useFooter';
12
+ export * from './useStoreActions';
11
13
  export * from './types';
package/src/store.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { useLayoutEffect, createContext, useContext } from 'react';
2
2
  import { createStore, StoreApi, useStore as useZustandStore } from 'zustand';
3
-
4
- import { devtools } from 'zustand/middleware';
3
+ import { devtools, persist } from 'zustand/middleware';
5
4
 
6
5
  import type { BreadcrumbsSlice } from './types/breadcrumbs';
7
6
  import type { SharedConfigSlice } from './types/sharedConfig';
8
7
  import type { LayoutSlice } from './types/layout';
9
8
  import type { SidebarSlice } from './types/sidebar';
10
9
  import type { TableOfContentsSlice } from './types/tableOfContents';
10
+ import type { ColorMode } from './types/colorMode';
11
11
 
12
12
  let store: StoreApi<SiteState>;
13
13
 
@@ -22,9 +22,16 @@ export type SiteState = BreadcrumbsSlice &
22
22
  route?: string;
23
23
  /** Page title */
24
24
  title?: string;
25
+ colorMode: ColorMode;
26
+ actions: {
27
+ setColorMode: (colorMode: ColorMode) => void;
28
+ };
25
29
  };
26
30
 
27
- function getDefaultInitialState(): SiteState {
31
+ type PeristedStoreState = Pick<SiteState, 'colorMode'>;
32
+ type DefaultSiteState = Omit<SiteState, 'actions'>;
33
+
34
+ function getDefaultInitialState(): DefaultSiteState {
28
35
  return {
29
36
  breadcrumbs: [],
30
37
  sidebarData: [],
@@ -33,22 +40,38 @@ function getDefaultInitialState(): SiteState {
33
40
  description: undefined,
34
41
  layout: undefined,
35
42
  route: undefined,
36
- title: undefined
43
+ title: undefined,
44
+ colorMode: 'light'
37
45
  };
38
46
  }
39
47
 
40
48
  const StoreContext = createContext<typeof store | undefined>(undefined);
41
49
  const StoreProvider = StoreContext.Provider;
42
50
 
43
- const initializeStore = (preloadedState: Partial<SiteState> = {}) =>
44
- createStore(
45
- devtools<SiteState>(() => ({
51
+ const storeMiddlewares = stateCreatorFn =>
52
+ devtools(
53
+ persist<SiteState, [], [], PeristedStoreState>(stateCreatorFn, {
54
+ name: 'mosaic-theme-pref',
55
+ partialize: (state: SiteState) => ({
56
+ colorMode: state.colorMode
57
+ })
58
+ })
59
+ );
60
+
61
+ const initializeStore = (preloadedState: Partial<SiteState> = {}) => {
62
+ const mosaicStore = createStore(
63
+ storeMiddlewares(set => ({
46
64
  ...getDefaultInitialState(),
47
- ...preloadedState
65
+ ...preloadedState,
66
+ actions: {
67
+ setColorMode: (colorMode: ColorMode) => set({ colorMode })
68
+ }
48
69
  }))
49
70
  );
71
+ return mosaicStore;
72
+ };
50
73
 
51
- function useCreateStore(serverInitialState: Partial<SiteState>, isSSR: boolean = false) {
74
+ function useCreateStore(serverInitialState: Partial<SiteState>, isSSR = false) {
52
75
  // Server side code: For SSR & SSG, always use a new store.
53
76
  if (typeof window === 'undefined' || isSSR) {
54
77
  return () => initializeStore(serverInitialState);
@@ -67,7 +90,6 @@ function useCreateStore(serverInitialState: Partial<SiteState>, isSSR: boolean =
67
90
  //
68
91
  // eslint complaining "React Hooks must be called in the exact same order in every component render"
69
92
  // is ignorable as this code runs in same order in a given environment (i.e. client or server)
70
- // eslint-disable-next-line react-hooks/rules-of-hooks
71
93
  useLayoutEffect(() => {
72
94
  // serverInitialState is undefined for CSR pages. It is up to you if you want to reset
73
95
  // states on CSR page navigation or not. I have chosen not to, but if you choose to,
@@ -95,11 +117,11 @@ function useStore<T>(
95
117
  selector: (state: SiteState) => T,
96
118
  equalityFn?: (left: T, right: T) => boolean
97
119
  ): T {
98
- const store = useContext(StoreContext);
99
- if (!store) {
120
+ const storeFromContext = useContext(StoreContext);
121
+ if (!storeFromContext) {
100
122
  throw new Error('Missing StoreProvider in the tree');
101
123
  }
102
- return useZustandStore(store, selector, equalityFn);
124
+ return useZustandStore(storeFromContext, selector, equalityFn);
103
125
  }
104
126
 
105
127
  export { useCreateStore, StoreProvider, useStore, initializeStore };
@@ -0,0 +1,4 @@
1
+ export const lightMode = 'light';
2
+ export const darkMode = 'dark';
3
+
4
+ export type ColorMode = typeof lightMode | typeof darkMode;
@@ -0,0 +1,8 @@
1
+ import { useStore } from './store';
2
+
3
+ import { ColorMode } from './types/colorMode';
4
+
5
+ export function useColorMode(): ColorMode {
6
+ const colorMode = useStore(state => state.colorMode);
7
+ return colorMode;
8
+ }
@@ -0,0 +1,2 @@
1
+ import { useStore } from './store';
2
+ export const useStoreActions = () => useStore(state => state.actions);
@@ -1 +0,0 @@
1
- import{d as o}from"./chunk-C6AHZ6P3.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
@@ -1 +0,0 @@
1
- import{useLayoutEffect as a,createContext as s,useContext as S}from"react";import{createStore as f,useStore as u}from"zustand";import{devtools as d}from"zustand/middleware";var t;function c(){return{breadcrumbs:[],sidebarData:[],tableOfContents:[],sharedConfig:{},description:void 0,layout:void 0,route:void 0,title:void 0}}var n=s(void 0),b=n.Provider,i=(e={})=>f(d(()=>({...c(),...e})));function g(e,r=!1){if(typeof window>"u"||r)return()=>i(e);let o=Boolean(t);return t=t??i(e),a(()=>{e&&o&&t.setState({...t.getState(),...e},!0)}),()=>t}function C(e,r){let o=S(n);if(!o)throw new Error("Missing StoreProvider in the tree");return u(o,e,r)}export{b as a,i as b,g as c,C as d};
@@ -1 +0,0 @@
1
- import{d as t}from"./chunk-C6AHZ6P3.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
@@ -1 +0,0 @@
1
- import{d as e}from"./chunk-C6AHZ6P3.js";function u(){return{route:e(t=>t.route)}}export{u as a};
@@ -1 +0,0 @@
1
- import{d as t}from"./chunk-C6AHZ6P3.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};