@jpmorganchase/mosaic-store 0.1.0-beta.22 → 0.1.0-beta.24

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 (62) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +2 -0
  4. package/dist/chunk-23H66E6E.js +1 -0
  5. package/dist/chunk-2G7SPWFY.js +1 -0
  6. package/dist/chunk-4GIIWZ26.js +1 -0
  7. package/dist/chunk-6B3RGLQ6.js +1 -0
  8. package/dist/{chunk-UMJOUVJQ.js → chunk-74B44ZUJ.js} +1 -1
  9. package/dist/chunk-CI2QHT55.js +1 -0
  10. package/dist/chunk-FC2ZNWAP.js +1 -0
  11. package/dist/chunk-LS443IBF.js +1 -0
  12. package/dist/{chunk-TTE3IDKD.js → chunk-MLBDLE43.js} +1 -1
  13. package/dist/chunk-MSLRBBS3.js +1 -0
  14. package/dist/chunk-RK2QZ3ZO.js +1 -0
  15. package/dist/{chunk-T4F7TF3E.js → chunk-SPCIWRRP.js} +1 -1
  16. package/dist/chunk-W6IABN6M.js +1 -0
  17. package/dist/chunk-WCQXIIQB.js +0 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +1 -1
  20. package/dist/store.d.ts +2 -1
  21. package/dist/store.js +1 -1
  22. package/dist/types/appHeader.d.ts +3 -0
  23. package/dist/types/index.d.ts +1 -0
  24. package/dist/types/index.js +1 -1
  25. package/dist/types/searchIndex.d.ts +10 -0
  26. package/dist/types/searchIndex.js +1 -0
  27. package/dist/useAppHeader.d.ts +1 -4
  28. package/dist/useAppHeader.js +1 -1
  29. package/dist/useBreadcrumbs.js +1 -1
  30. package/dist/useColorMode.js +1 -1
  31. package/dist/useFooter.js +1 -1
  32. package/dist/useLayout.js +1 -1
  33. package/dist/useMeta.js +1 -1
  34. package/dist/useNextPrev.js +1 -1
  35. package/dist/useRoute.js +1 -1
  36. package/dist/useSearchIndex.d.ts +5 -0
  37. package/dist/useSearchIndex.js +1 -0
  38. package/dist/useSidebar.js +1 -1
  39. package/dist/useStoreActions.js +1 -1
  40. package/dist/useTableOfContents.js +1 -1
  41. package/package.json +6 -1
  42. package/src/__tests__/store.test.ts +6 -0
  43. package/src/__tests__/useAppHeader.test.ts +0 -25
  44. package/src/__tests__/useSearchIndex.test.ts +59 -0
  45. package/src/index.ts +1 -0
  46. package/src/store.ts +3 -0
  47. package/src/types/appHeader.ts +4 -0
  48. package/src/types/index.ts +1 -0
  49. package/src/types/searchIndex.ts +11 -0
  50. package/src/useAppHeader.ts +1 -19
  51. package/src/useNextPrev.ts +10 -7
  52. package/src/useSearchIndex.ts +14 -0
  53. package/dist/chunk-5G75LNTO.js +0 -1
  54. package/dist/chunk-FTFVN4S3.js +0 -1
  55. package/dist/chunk-GG4KZ7Z6.js +0 -1
  56. package/dist/chunk-N6Q3GQDQ.js +0 -1
  57. package/dist/chunk-NEIN7MAT.js +0 -1
  58. package/dist/chunk-OC2YQSBN.js +0 -1
  59. package/dist/chunk-PNYO3347.js +0 -1
  60. package/dist/chunk-VRIJA4FE.js +0 -1
  61. package/dist/chunk-XXDRCMNC.js +0 -1
  62. /package/dist/{chunk-ASPK4M5R.js → chunk-IS7TJ54I.js} +0 -0
@@ -1,4 +1,4 @@
1
- @jpmorganchase/mosaic-store:build: cache hit, replaying output a82a1b94b6d204fd
1
+ @jpmorganchase/mosaic-store:build: cache hit, replaying output ee8c91b3203438af
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,21 @@
1
1
  # @jpmorganchase/mosaic-store
2
2
 
3
+ ## 0.1.0-beta.24
4
+
5
+ ### Patch Changes
6
+
7
+ - 049d9af: 1. Pip Salt version 2. Issues 155, make 500 error more specific 3. button and sidebar styles 4. search opt-out
8
+
9
+ ## 0.1.0-beta.23
10
+
11
+ ### Patch Changes
12
+
13
+ - 513d45f: Sidebar behavior and styling changes.
14
+ Add Client-side search feature.
15
+ Relax node engine requirements.
16
+ Removal of patches from the site package.
17
+ Update site generator templates.
18
+
3
19
  ## 0.1.0-beta.22
4
20
 
5
21
  ### Patch Changes
package/README.md CHANGED
@@ -7,3 +7,5 @@ The Mosaic store is based on [Zustand](https://zustand-demo.pmnd.rs/).
7
7
  ## Installation
8
8
 
9
9
  `yarn add @jpmorganchase/mosaic-store`
10
+
11
+ The Redux DevTools chrome extension can be used to view the contents of the store if required.
@@ -0,0 +1 @@
1
+ import{d as o}from"./chunk-2G7SPWFY.js";var r=()=>o(t=>t.actions);export{r as a};
@@ -0,0 +1 @@
1
+ import{useLayoutEffect as s,createContext as S,useContext as d}from"react";import{createStore as c,useStore as l}from"zustand";import{devtools as f,persist as p}from"zustand/middleware";var r;function u(){return{breadcrumbs:[],sidebarData:[],tableOfContents:[],searchIndex:[],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(p(e,{name:"mosaic-theme-pref",partialize:t=>({colorMode:t.colorMode})})),i=(e={})=>c(m(o=>({...u(),...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 x(e,t){let o=d(n);if(!o)throw new Error("Missing StoreProvider in the tree");return l(o,e,t)}export{g as a,i as b,h as c,x as d};
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-FC2ZNWAP.js";import{d as i}from"./chunk-2G7SPWFY.js";function p(){let t=i(s=>s.sidebarData)||[],{route:r}=o(),{next:e,prev:n}=d(t,r||"");return{next:e,prev:n}}var m=t=>t.reduce((e,n)=>{if(!n)return e;let s=[...e,{link:n.data.link,text:n.name}];return n.childNodes&&(s=[...e,...m(n.childNodes)]),s},[]),c=(t,r)=>t>=0&&t<r-1,x=(t,r)=>t>0&&t<r,l=(t,r)=>{let e=t.map(a=>a.link).indexOf(r),{length:n}=t,s=c(e,n)?t[e+1]:null,u=x(e,n)?t[e-1]:null;return{next:s,prev:u}},d=(t,r)=>{let e=m(t);return l(e,r)};export{p as a};
@@ -0,0 +1 @@
1
+ import{d as o}from"./chunk-2G7SPWFY.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
@@ -1 +1 @@
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
+ import{d as t}from"./chunk-2G7SPWFY.js";function o(){return{meta:t(e=>({description:e.description,breadcrumbs:e.breadcrumbs,title:e.title}))}}export{o as a};
@@ -0,0 +1 @@
1
+ import{d as t}from"./chunk-2G7SPWFY.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
@@ -0,0 +1 @@
1
+ import{d as e}from"./chunk-2G7SPWFY.js";function u(){return{route:e(t=>t.route)}}export{u as a};
@@ -0,0 +1 @@
1
+ import{d as t}from"./chunk-2G7SPWFY.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};
@@ -1 +1 @@
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 p(){let r=t(d=>d.sidebarData)||[],{route:e}=s(),{breadcrumbs:u}=o();return{menu:r,selectedNodeId:e,expandedNodeIds:m(u)}}function m(r){return new Set(r.map(({id:e})=>e.substr(0,e.lastIndexOf("."))))}export{p as a};
1
+ import{a as s}from"./chunk-FC2ZNWAP.js";import{a as o}from"./chunk-SPCIWRRP.js";import{d as t}from"./chunk-2G7SPWFY.js";function p(){let r=t(d=>d.sidebarData)||[],{route:e}=s(),{breadcrumbs:u}=o();return{menu:r,selectedNodeId:e,expandedNodeIds:m(u)}}function m(r){return new Set(r.map(({id:e})=>e.substr(0,e.lastIndexOf("."))))}export{p as a};
@@ -0,0 +1 @@
1
+ import{d as t}from"./chunk-2G7SPWFY.js";function u(e){return e.links!==void 0}function d(e){return e.link!==void 0}function M(){let e=t(n=>n.sharedConfig?.header);if(!e)return;let i=e.menu.reduce((n,p)=>{if(u(p)){let r={...p,type:"menu"};return[...n,r]}if(d(p)){let r={...p,type:"link"};return[...n,r]}return console.error("Unknown menu type passed to useAppHeader, ignoring",p),n},[]);return{...e,menu:i}}export{M as a};
@@ -0,0 +1 @@
1
+ import{d as r}from"./chunk-2G7SPWFY.js";function o(){let e=r(t=>t.searchIndex),n=e!==void 0&&e.length>0;return{searchEnabled:n,searchIndex:n?e:[]}}export{o as a};
@@ -1 +1 @@
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
+ import{d as e}from"./chunk-2G7SPWFY.js";function m(t=1){let r=e(b=>b.breadcrumbs);return{breadcrumbs:r||[],enabled:r?.length>t}}export{m as a};
@@ -0,0 +1 @@
1
+ import{d as o}from"./chunk-2G7SPWFY.js";function d(){return o(r=>r.colorMode)}export{d as a};
File without changes
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './useLayout';
6
6
  export * from './useMeta';
7
7
  export * from './useNextPrev';
8
8
  export * from './useRoute';
9
+ export * from './useSearchIndex';
9
10
  export * from './useSidebar';
10
11
  export * from './useTableOfContents';
11
12
  export * from './useFooter';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as d}from"./chunk-GG4KZ7Z6.js";import{a as g}from"./chunk-TTE3IDKD.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};
1
+ import{a as d}from"./chunk-4GIIWZ26.js";import{a as g}from"./chunk-RK2QZ3ZO.js";import{a as h}from"./chunk-MLBDLE43.js";import{a as c}from"./chunk-FC2ZNWAP.js";import{a as k}from"./chunk-23H66E6E.js";import{a as i}from"./chunk-LS443IBF.js";import{a as p}from"./chunk-MSLRBBS3.js";import"./chunk-WCQXIIQB.js";import"./chunk-5L7EI47O.js";import"./chunk-MBLLQB7A.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-IS7TJ54I.js";import{a as m}from"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import{a as t}from"./chunk-SPCIWRRP.js";import{a as x}from"./chunk-W6IABN6M.js";import{a as j}from"./chunk-6B3RGLQ6.js";import{a}from"./chunk-CI2QHT55.js";import{a as b}from"./chunk-74B44ZUJ.js";import{a as o,b as r,c as e,d as f}from"./chunk-2G7SPWFY.js";export{m as MenuItemType,o as StoreProvider,r as initializeStore,p as useAppHeader,t as useBreadcrumbs,x as useColorMode,e as useCreateStore,j as useFooter,a as useLayout,b as useMeta,d as useNextPrev,c as useRoute,g as useSearchIndex,h as useSidebar,f as useStore,k as useStoreActions,i as useTableOfContents};
package/dist/store.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { StoreApi } from 'zustand';
3
3
  import type { BreadcrumbsSlice } from './types/breadcrumbs';
4
+ import type { SearchIndexSlice } from './types/searchIndex';
4
5
  import type { SharedConfigSlice } from './types/sharedConfig';
5
6
  import type { LayoutSlice } from './types/layout';
6
7
  import type { SidebarSlice } from './types/sidebar';
7
8
  import type { TableOfContentsSlice } from './types/tableOfContents';
8
9
  import type { ColorMode } from './types/colorMode';
9
- export declare type SiteState = BreadcrumbsSlice & LayoutSlice & SidebarSlice & TableOfContentsSlice & SharedConfigSlice & {
10
+ export declare type SiteState = BreadcrumbsSlice & LayoutSlice & SidebarSlice & TableOfContentsSlice & SearchIndexSlice & SharedConfigSlice & {
10
11
  /** Page metadata description, used by search */
11
12
  description?: string;
12
13
  /** Page route */
package/dist/store.js CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d}from"./chunk-VRIJA4FE.js";export{a as StoreProvider,b as initializeStore,c as useCreateStore,d as useStore};
1
+ import{a,b,c,d}from"./chunk-2G7SPWFY.js";export{a as StoreProvider,b as initializeStore,c as useCreateStore,d as useStore};
@@ -1,3 +1,4 @@
1
+ import { SearchIndexSlice } from './searchIndex';
1
2
  /**
2
3
  * [[`MenuItemType`]] defines the type of App header Menu items
3
4
  */
@@ -67,4 +68,6 @@ export declare type AppHeaderSlice = {
67
68
  menu: Menu[];
68
69
  /** Search namespace, suffix used on env variable `process.env.SEARCH_ENDPOINT` to filter search results to a specific namespace. */
69
70
  searchNamespace?: string;
71
+ /** Search index, created by SearchIndexPlugin */
72
+ searchIndex?: SearchIndexSlice;
70
73
  };
@@ -5,6 +5,7 @@ export * from './helpLinks';
5
5
  export * from './layout';
6
6
  export * from './meta';
7
7
  export * from './route';
8
+ export * from './searchIndex';
8
9
  export * from './sharedConfig';
9
10
  export * from './sidebar';
10
11
  export * from './tableOfContents';
@@ -1 +1 @@
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
+ import"../chunk-WCQXIIQB.js";import"../chunk-5L7EI47O.js";import"../chunk-MBLLQB7A.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-IS7TJ54I.js";import{a}from"../chunk-ZMWHBFUG.js";import"../chunk-VXYECVIB.js";export{a as MenuItemType};
@@ -0,0 +1,10 @@
1
+ declare type SearchDataPage = {
2
+ title: string;
3
+ content: string[];
4
+ route: string;
5
+ };
6
+ export declare type SearchIndex = SearchDataPage[];
7
+ export declare type SearchIndexSlice = {
8
+ searchIndex?: SearchIndex;
9
+ };
10
+ export {};
@@ -0,0 +1 @@
1
+ import"../chunk-IS7TJ54I.js";
@@ -1,9 +1,6 @@
1
1
  import type { AppHeaderSlice, AppHeaderMenuLinkItem, AppHeaderMenuLinksItem } from './types';
2
2
  export declare type AppHeaderMenu = Array<AppHeaderMenuLinksItem | AppHeaderMenuLinkItem>;
3
- export interface AppHeader extends Omit<AppHeaderSlice, 'searchNamespace | menu'> {
4
- HeaderControlsProps?: {
5
- searchEndpoint: string;
6
- };
3
+ export interface AppHeader extends Omit<AppHeaderSlice, 'menu'> {
7
4
  menu: AppHeaderMenu;
8
5
  }
9
6
  export declare function useAppHeader(): AppHeader | undefined;
@@ -1 +1 @@
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
+ import{a}from"./chunk-MSLRBBS3.js";import"./chunk-WCQXIIQB.js";import"./chunk-5L7EI47O.js";import"./chunk-MBLLQB7A.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-IS7TJ54I.js";import"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import"./chunk-2G7SPWFY.js";export{a as useAppHeader};
@@ -1 +1 @@
1
- import{a}from"./chunk-T4F7TF3E.js";import"./chunk-VRIJA4FE.js";export{a as useBreadcrumbs};
1
+ import{a}from"./chunk-SPCIWRRP.js";import"./chunk-2G7SPWFY.js";export{a as useBreadcrumbs};
@@ -1 +1 @@
1
- import{a}from"./chunk-PNYO3347.js";import"./chunk-VRIJA4FE.js";export{a as useColorMode};
1
+ import{a}from"./chunk-W6IABN6M.js";import"./chunk-2G7SPWFY.js";export{a as useColorMode};
package/dist/useFooter.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-OC2YQSBN.js";import"./chunk-VRIJA4FE.js";export{a as useFooter};
1
+ import{a}from"./chunk-6B3RGLQ6.js";import"./chunk-2G7SPWFY.js";export{a as useFooter};
package/dist/useLayout.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-NEIN7MAT.js";import"./chunk-VRIJA4FE.js";export{a as useLayout};
1
+ import{a}from"./chunk-CI2QHT55.js";import"./chunk-2G7SPWFY.js";export{a as useLayout};
package/dist/useMeta.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-UMJOUVJQ.js";import"./chunk-VRIJA4FE.js";export{a as useMeta};
1
+ import{a}from"./chunk-74B44ZUJ.js";import"./chunk-2G7SPWFY.js";export{a as useMeta};
@@ -1 +1 @@
1
- import{a}from"./chunk-GG4KZ7Z6.js";import"./chunk-5G75LNTO.js";import"./chunk-VRIJA4FE.js";export{a as useNextPrev};
1
+ import{a}from"./chunk-4GIIWZ26.js";import"./chunk-FC2ZNWAP.js";import"./chunk-2G7SPWFY.js";export{a as useNextPrev};
package/dist/useRoute.js CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-5G75LNTO.js";import"./chunk-VRIJA4FE.js";export{a as useRoute};
1
+ import{a}from"./chunk-FC2ZNWAP.js";import"./chunk-2G7SPWFY.js";export{a as useRoute};
@@ -0,0 +1,5 @@
1
+ export type { SearchIndexSlice } from './types';
2
+ export declare function useSearchIndex(): {
3
+ searchEnabled: boolean;
4
+ searchIndex: import("./types").SearchIndex;
5
+ };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-RK2QZ3ZO.js";import"./chunk-2G7SPWFY.js";export{a as useSearchIndex};
@@ -1 +1 @@
1
- import{a}from"./chunk-TTE3IDKD.js";import"./chunk-5G75LNTO.js";import"./chunk-T4F7TF3E.js";import"./chunk-VRIJA4FE.js";export{a as useSidebar};
1
+ import{a}from"./chunk-MLBDLE43.js";import"./chunk-FC2ZNWAP.js";import"./chunk-SPCIWRRP.js";import"./chunk-2G7SPWFY.js";export{a as useSidebar};
@@ -1 +1 @@
1
- import{a}from"./chunk-XXDRCMNC.js";import"./chunk-VRIJA4FE.js";export{a as useStoreActions};
1
+ import{a}from"./chunk-23H66E6E.js";import"./chunk-2G7SPWFY.js";export{a as useStoreActions};
@@ -1 +1 @@
1
- import{a}from"./chunk-N6Q3GQDQ.js";import"./chunk-VRIJA4FE.js";export{a as useTableOfContents};
1
+ import{a}from"./chunk-LS443IBF.js";import"./chunk-2G7SPWFY.js";export{a as useTableOfContents};
package/package.json CHANGED
@@ -1,9 +1,14 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-store",
3
3
  "description": "Mosaic - Store for site configuration",
4
- "version": "0.1.0-beta.22",
4
+ "version": "0.1.0-beta.24",
5
5
  "license": "Apache-2.0",
6
6
  "author": "",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git@github.com:jpmorganchase/mosaic.git",
10
+ "directory": "packages/store"
11
+ },
7
12
  "type": "module",
8
13
  "main": "./dist/index.js",
9
14
  "types": "./dist/index.d.ts",
@@ -16,6 +16,7 @@ describe('GIVEN the store initializer', () => {
16
16
  breadcrumbs: [],
17
17
  sidebarData: [],
18
18
  tableOfContents: [],
19
+ searchIndex: [],
19
20
  sharedConfig: {},
20
21
  description: undefined,
21
22
  layout: undefined,
@@ -38,6 +39,7 @@ describe('GIVEN the store initializer', () => {
38
39
  const storeApi = initializeStore(state);
39
40
  expect(getStateToVerify(storeApi.getState())).toEqual({
40
41
  breadcrumbs: [],
42
+ searchIndex: [],
41
43
  sidebarData: [],
42
44
  tableOfContents: [],
43
45
  sharedConfig: {},
@@ -58,6 +60,7 @@ describe('GIVEN the `useCreateStore` hook', () => {
58
60
 
59
61
  expect(getStateToVerify(currentState)).toEqual({
60
62
  breadcrumbs: [],
63
+ searchIndex: [],
61
64
  sidebarData: [],
62
65
  tableOfContents: [],
63
66
  sharedConfig: {},
@@ -76,6 +79,7 @@ describe('GIVEN the `useCreateStore` hook', () => {
76
79
  expect(getStateToVerify(currentState)).toEqual({
77
80
  breadcrumbs: [],
78
81
  sidebarData: [],
82
+ searchIndex: [],
79
83
  tableOfContents: [],
80
84
  sharedConfig: {},
81
85
  colorMode: 'light',
@@ -95,6 +99,7 @@ describe('GIVEN the `useCreateStore` hook', () => {
95
99
 
96
100
  expect(getStateToVerify(currentState)).toEqual({
97
101
  breadcrumbs: [],
102
+ searchIndex: [],
98
103
  sidebarData: [],
99
104
  tableOfContents: [],
100
105
  sharedConfig: {},
@@ -114,6 +119,7 @@ describe('GIVEN the `useCreateStore` hook', () => {
114
119
  expect(getStateToVerify(currentState)).toEqual({
115
120
  breadcrumbs: [],
116
121
  sidebarData: [],
122
+ searchIndex: [],
117
123
  tableOfContents: [],
118
124
  sharedConfig: {},
119
125
  colorMode: 'light',
@@ -137,31 +137,6 @@ describe('GIVEN the `useAppHeader` hook', () => {
137
137
  expect(result.current?.menu[3].type).toEqual('menu');
138
138
  });
139
139
 
140
- describe('AND WHEN a search namespace is *NOT* provided', () => {
141
- test('THEN the namespace endpoint env variable is used', () => {
142
- const { result } = renderHook(() => useAppHeader(), {
143
- wrapper: createWrapper({ ...state })
144
- });
145
- expect(result.current?.HeaderControlsProps?.searchEndpoint).toEqual(undefined);
146
- });
147
- });
148
-
149
- describe('AND WHEN a search namespace is provided', () => {
150
- beforeAll(() => {
151
- header.searchNamespace = 'namespace';
152
- process.env[`SEARCH_ENDPOINT_${header.searchNamespace}`] = 'namespace-endpoint';
153
- });
154
- afterAll(() => {
155
- process.env[`SEARCH_ENDPOINT_${header.searchNamespace}`] = undefined;
156
- });
157
- test('THEN the SEARCH_ENDPOINT env variable is used', () => {
158
- const { result } = renderHook(() => useAppHeader(), {
159
- wrapper: createWrapper({ ...state })
160
- });
161
- expect(result.current?.HeaderControlsProps?.searchEndpoint).toEqual('namespace-endpoint');
162
- });
163
- });
164
-
165
140
  describe('AND WHEN invalid menu items are provided', () => {
166
141
  let consoleError;
167
142
  beforeAll(() => {
@@ -0,0 +1,59 @@
1
+ import { renderHook } from '@testing-library/react';
2
+
3
+ import { createWrapper } from './test-utils/utils';
4
+ import { useSearchIndex } from '../useSearchIndex';
5
+ import { SiteState } from '../store';
6
+
7
+ const index: SiteState['searchIndex'] = [
8
+ {
9
+ title: 'Test item title',
10
+ content: ['test item content sentence 1', 'test item content sentence 2'],
11
+ route: 'test/page/route'
12
+ },
13
+ {
14
+ title: 'Second test item title',
15
+ content: [
16
+ 'Laborum deserunt laboris in quis dolor est laboris incididunt exercitation sunt voluptate.',
17
+ 'Nisi amet cupidatat ut laborum Lorem eu qui fugiat ad.'
18
+ ],
19
+ route: 'second/test/page/route'
20
+ }
21
+ ];
22
+
23
+ const state: Partial<SiteState> = {
24
+ searchIndex: index
25
+ };
26
+
27
+ describe('GIVEN the `useSearchIndex` hook', () => {
28
+ describe('WHEN there is no search index in the store', () => {
29
+ test('THEN searchEnabled is set to false', () => {
30
+ const { result } = renderHook(() => useSearchIndex(), {
31
+ wrapper: createWrapper()
32
+ });
33
+ expect(result.current.searchEnabled).toBe(false);
34
+ });
35
+ test('AND searchIndex is set to an empty array', () => {
36
+ const { result } = renderHook(() => useSearchIndex(), {
37
+ wrapper: createWrapper()
38
+ });
39
+ expect(Array.isArray(result.current.searchIndex)).toBe(true);
40
+ expect(result.current.searchIndex.length).toBe(0);
41
+ });
42
+ });
43
+
44
+ describe('WHEN there is a search index in the store', () => {
45
+ test('THEN searchEnabled is set to true', () => {
46
+ const { result } = renderHook(() => useSearchIndex(), {
47
+ wrapper: createWrapper({ ...state })
48
+ });
49
+ expect(result.current.searchEnabled).toBe(true);
50
+ });
51
+ test('AND searchIndex contains the index', () => {
52
+ const { result } = renderHook(() => useSearchIndex(), {
53
+ wrapper: createWrapper({ ...state })
54
+ });
55
+ expect(Array.isArray(result.current.searchIndex)).toBe(true);
56
+ expect(result.current.searchIndex.length).toBe(index.length);
57
+ });
58
+ });
59
+ });
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './useLayout';
6
6
  export * from './useMeta';
7
7
  export * from './useNextPrev';
8
8
  export * from './useRoute';
9
+ export * from './useSearchIndex';
9
10
  export * from './useSidebar';
10
11
  export * from './useTableOfContents';
11
12
  export * from './useFooter';
package/src/store.ts CHANGED
@@ -3,6 +3,7 @@ import { createStore, StoreApi, useStore as useZustandStore } from 'zustand';
3
3
  import { devtools, persist } from 'zustand/middleware';
4
4
 
5
5
  import type { BreadcrumbsSlice } from './types/breadcrumbs';
6
+ import type { SearchIndexSlice } from './types/searchIndex';
6
7
  import type { SharedConfigSlice } from './types/sharedConfig';
7
8
  import type { LayoutSlice } from './types/layout';
8
9
  import type { SidebarSlice } from './types/sidebar';
@@ -15,6 +16,7 @@ export type SiteState = BreadcrumbsSlice &
15
16
  LayoutSlice &
16
17
  SidebarSlice &
17
18
  TableOfContentsSlice &
19
+ SearchIndexSlice &
18
20
  SharedConfigSlice & {
19
21
  /** Page metadata description, used by search */
20
22
  description?: string;
@@ -36,6 +38,7 @@ function getDefaultInitialState(): DefaultSiteState {
36
38
  breadcrumbs: [],
37
39
  sidebarData: [],
38
40
  tableOfContents: [],
41
+ searchIndex: [],
39
42
  sharedConfig: {},
40
43
  description: undefined,
41
44
  layout: undefined,
@@ -1,3 +1,5 @@
1
+ import { SearchIndexSlice } from './searchIndex';
2
+
1
3
  /**
2
4
  * [[`MenuItemType`]] defines the type of App header Menu items
3
5
  */
@@ -73,4 +75,6 @@ export type AppHeaderSlice = {
73
75
  menu: Menu[];
74
76
  /** Search namespace, suffix used on env variable `process.env.SEARCH_ENDPOINT` to filter search results to a specific namespace. */
75
77
  searchNamespace?: string;
78
+ /** Search index, created by SearchIndexPlugin */
79
+ searchIndex?: SearchIndexSlice;
76
80
  };
@@ -5,6 +5,7 @@ export * from './helpLinks';
5
5
  export * from './layout';
6
6
  export * from './meta';
7
7
  export * from './route';
8
+ export * from './searchIndex';
8
9
  export * from './sharedConfig';
9
10
  export * from './sidebar';
10
11
  export * from './tableOfContents';
@@ -0,0 +1,11 @@
1
+ type SearchDataPage = {
2
+ title: string;
3
+ content: string[];
4
+ route: string;
5
+ };
6
+
7
+ export type SearchIndex = SearchDataPage[];
8
+
9
+ export type SearchIndexSlice = {
10
+ searchIndex?: SearchIndex;
11
+ };
@@ -15,18 +15,9 @@ function isMenuLink(menu: MenuLinkItem | MenuLinksItem): menu is MenuLinkItem {
15
15
  return (menu as MenuLinkItem).link !== undefined;
16
16
  }
17
17
 
18
- const parseSearchEndpoint = (searchNamespace: string): string | undefined => {
19
- if (!searchNamespace) return process.env.SEARCH_ENDPOINT;
20
- const endpoint = process.env[`SEARCH_ENDPOINT_${searchNamespace}`];
21
- return endpoint || '';
22
- };
23
-
24
18
  export type AppHeaderMenu = Array<AppHeaderMenuLinksItem | AppHeaderMenuLinkItem>;
25
19
 
26
- export interface AppHeader extends Omit<AppHeaderSlice, 'searchNamespace | menu'> {
27
- HeaderControlsProps?: {
28
- searchEndpoint: string;
29
- };
20
+ export interface AppHeader extends Omit<AppHeaderSlice, 'menu'> {
30
21
  menu: AppHeaderMenu;
31
22
  }
32
23
 
@@ -35,14 +26,6 @@ export function useAppHeader(): AppHeader | undefined {
35
26
  if (!appHeader) {
36
27
  return undefined;
37
28
  }
38
- let additionalProps = {};
39
- if (appHeader.searchNamespace) {
40
- additionalProps = {
41
- HeaderControlsProps: {
42
- searchEndpoint: parseSearchEndpoint(appHeader.searchNamespace)
43
- }
44
- };
45
- }
46
29
  const typedMenu: AppHeaderMenu = appHeader.menu.reduce<AppHeaderMenu>((result, menu) => {
47
30
  if (isMenu(menu)) {
48
31
  const linksItem: AppHeaderMenuLinksItem = { ...menu, type: MenuItemType.MENU };
@@ -57,7 +40,6 @@ export function useAppHeader(): AppHeader | undefined {
57
40
  }, []);
58
41
 
59
42
  return {
60
- ...additionalProps,
61
43
  ...appHeader,
62
44
  menu: typedMenu
63
45
  };
@@ -15,15 +15,18 @@ export function useNextPrev() {
15
15
  };
16
16
  }
17
17
 
18
- const flatten = (nodes: SidebarItem[]) => {
19
- let flattenedNodes: NextPrevItem[] = [];
20
- nodes.forEach(node => {
21
- flattenedNodes.push({ link: node.data.link, text: node.name });
18
+ const flatten = (nodes: SidebarItem[]): NextPrevItem[] => {
19
+ const flattenedNode = nodes.reduce<NextPrevItem[]>((result, node) => {
20
+ if (!node) {
21
+ return result;
22
+ }
23
+ let nextResult = [...result, { link: node.data.link, text: node.name }];
22
24
  if (node.childNodes) {
23
- flattenedNodes = flattenedNodes.concat(flatten(node.childNodes));
25
+ nextResult = [...result, ...flatten(node.childNodes)];
24
26
  }
25
- });
26
- return flattenedNodes;
27
+ return nextResult;
28
+ }, []);
29
+ return flattenedNode;
27
30
  };
28
31
 
29
32
  const nextExists = (index: number, length: number) => index >= 0 && index < length - 1;
@@ -0,0 +1,14 @@
1
+ import { useStore } from './store';
2
+
3
+ export type { SearchIndexSlice } from './types';
4
+
5
+ export function useSearchIndex() {
6
+ const searchIndex = useStore(state => state.searchIndex);
7
+
8
+ const searchEnabled = searchIndex !== undefined && searchIndex.length > 0;
9
+
10
+ return {
11
+ searchEnabled,
12
+ searchIndex: searchEnabled ? searchIndex : []
13
+ };
14
+ }
@@ -1 +0,0 @@
1
- import{d as e}from"./chunk-VRIJA4FE.js";function u(){return{route:e(t=>t.route)}}export{u as a};
@@ -1 +0,0 @@
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 +0,0 @@
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};
@@ -1 +0,0 @@
1
- import{d as t}from"./chunk-VRIJA4FE.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};
@@ -1 +0,0 @@
1
- import{d as t}from"./chunk-VRIJA4FE.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
@@ -1 +0,0 @@
1
- import{d as o}from"./chunk-VRIJA4FE.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
@@ -1 +0,0 @@
1
- import{d as o}from"./chunk-VRIJA4FE.js";function d(){return o(r=>r.colorMode)}export{d as a};
@@ -1 +0,0 @@
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};
@@ -1 +0,0 @@
1
- import{d as o}from"./chunk-VRIJA4FE.js";var r=()=>o(t=>t.actions);export{r as a};
File without changes