@jpmorganchase/mosaic-store 0.1.0-beta.22 → 0.1.0-beta.23
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +10 -0
- package/dist/chunk-23H66E6E.js +1 -0
- package/dist/chunk-2G7SPWFY.js +1 -0
- package/dist/chunk-4GIIWZ26.js +1 -0
- package/dist/chunk-6B3RGLQ6.js +1 -0
- package/dist/{chunk-UMJOUVJQ.js → chunk-74B44ZUJ.js} +1 -1
- package/dist/chunk-CI2QHT55.js +1 -0
- package/dist/chunk-FC2ZNWAP.js +1 -0
- package/dist/chunk-LS443IBF.js +1 -0
- package/dist/{chunk-TTE3IDKD.js → chunk-MLBDLE43.js} +1 -1
- package/dist/chunk-MSLRBBS3.js +1 -0
- package/dist/chunk-RK2QZ3ZO.js +1 -0
- package/dist/{chunk-T4F7TF3E.js → chunk-SPCIWRRP.js} +1 -1
- package/dist/chunk-W6IABN6M.js +1 -0
- package/dist/chunk-WCQXIIQB.js +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/store.d.ts +2 -1
- package/dist/store.js +1 -1
- package/dist/types/appHeader.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/searchIndex.d.ts +10 -0
- package/dist/types/searchIndex.js +1 -0
- package/dist/useAppHeader.d.ts +1 -4
- package/dist/useAppHeader.js +1 -1
- package/dist/useBreadcrumbs.js +1 -1
- package/dist/useColorMode.js +1 -1
- package/dist/useFooter.js +1 -1
- package/dist/useLayout.js +1 -1
- package/dist/useMeta.js +1 -1
- package/dist/useNextPrev.js +1 -1
- package/dist/useRoute.js +1 -1
- package/dist/useSearchIndex.d.ts +5 -0
- package/dist/useSearchIndex.js +1 -0
- package/dist/useSidebar.js +1 -1
- package/dist/useStoreActions.js +1 -1
- package/dist/useTableOfContents.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/store.test.ts +6 -0
- package/src/__tests__/useAppHeader.test.ts +0 -25
- package/src/__tests__/useSearchIndex.test.ts +59 -0
- package/src/index.ts +1 -0
- package/src/store.ts +3 -0
- package/src/types/appHeader.ts +4 -0
- package/src/types/index.ts +1 -0
- package/src/types/searchIndex.ts +11 -0
- package/src/useAppHeader.ts +1 -19
- package/src/useNextPrev.ts +10 -7
- package/src/useSearchIndex.ts +14 -0
- package/dist/chunk-5G75LNTO.js +0 -1
- package/dist/chunk-FTFVN4S3.js +0 -1
- package/dist/chunk-GG4KZ7Z6.js +0 -1
- package/dist/chunk-N6Q3GQDQ.js +0 -1
- package/dist/chunk-NEIN7MAT.js +0 -1
- package/dist/chunk-OC2YQSBN.js +0 -1
- package/dist/chunk-PNYO3347.js +0 -1
- package/dist/chunk-VRIJA4FE.js +0 -1
- package/dist/chunk-XXDRCMNC.js +0 -1
- /package/dist/{chunk-ASPK4M5R.js → chunk-IS7TJ54I.js} +0 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@jpmorganchase/mosaic-store:build: cache hit, replaying output
|
|
1
|
+
@jpmorganchase/mosaic-store:build: cache hit, replaying output 92657758952da2fd
|
|
2
2
|
@jpmorganchase/mosaic-store:build: $ npm-run-all --parallel build:*
|
|
3
3
|
@jpmorganchase/mosaic-store:build: $ node ../../scripts/bundle.js
|
|
4
4
|
@jpmorganchase/mosaic-store:build: $ tsc
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @jpmorganchase/mosaic-store
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.23
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 513d45f: Sidebar behavior and styling changes.
|
|
8
|
+
Add Client-side search feature.
|
|
9
|
+
Relax node engine requirements.
|
|
10
|
+
Removal of patches from the site package.
|
|
11
|
+
Update site generator templates.
|
|
12
|
+
|
|
3
13
|
## 0.1.0-beta.22
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -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-
|
|
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-
|
|
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-
|
|
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
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d}from"./chunk-
|
|
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-
|
|
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
|
};
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunk-
|
|
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 @@
|
|
|
1
|
+
import"../chunk-IS7TJ54I.js";
|
package/dist/useAppHeader.d.ts
CHANGED
|
@@ -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, '
|
|
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;
|
package/dist/useAppHeader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
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};
|
package/dist/useBreadcrumbs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-SPCIWRRP.js";import"./chunk-2G7SPWFY.js";export{a as useBreadcrumbs};
|
package/dist/useColorMode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
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-
|
|
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-
|
|
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-
|
|
1
|
+
import{a}from"./chunk-74B44ZUJ.js";import"./chunk-2G7SPWFY.js";export{a as useMeta};
|
package/dist/useNextPrev.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
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-
|
|
1
|
+
import{a}from"./chunk-FC2ZNWAP.js";import"./chunk-2G7SPWFY.js";export{a as useRoute};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-RK2QZ3ZO.js";import"./chunk-2G7SPWFY.js";export{a as useSearchIndex};
|
package/dist/useSidebar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-MLBDLE43.js";import"./chunk-FC2ZNWAP.js";import"./chunk-SPCIWRRP.js";import"./chunk-2G7SPWFY.js";export{a as useSidebar};
|
package/dist/useStoreActions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-23H66E6E.js";import"./chunk-2G7SPWFY.js";export{a as useStoreActions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-LS443IBF.js";import"./chunk-2G7SPWFY.js";export{a as useTableOfContents};
|
package/package.json
CHANGED
|
@@ -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
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,
|
package/src/types/appHeader.ts
CHANGED
|
@@ -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
|
};
|
package/src/types/index.ts
CHANGED
package/src/useAppHeader.ts
CHANGED
|
@@ -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, '
|
|
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
|
};
|
package/src/useNextPrev.ts
CHANGED
|
@@ -15,15 +15,18 @@ export function useNextPrev() {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const flatten = (nodes: SidebarItem[]) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
+
nextResult = [...result, ...flatten(node.childNodes)];
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
package/dist/chunk-5G75LNTO.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as e}from"./chunk-VRIJA4FE.js";function u(){return{route:e(t=>t.route)}}export{u as a};
|
package/dist/chunk-FTFVN4S3.js
DELETED
|
@@ -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};
|
package/dist/chunk-GG4KZ7Z6.js
DELETED
|
@@ -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};
|
package/dist/chunk-N6Q3GQDQ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as t}from"./chunk-VRIJA4FE.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};
|
package/dist/chunk-NEIN7MAT.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as t}from"./chunk-VRIJA4FE.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
|
package/dist/chunk-OC2YQSBN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./chunk-VRIJA4FE.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
|
package/dist/chunk-PNYO3347.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./chunk-VRIJA4FE.js";function d(){return o(r=>r.colorMode)}export{d as a};
|
package/dist/chunk-VRIJA4FE.js
DELETED
|
@@ -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};
|
package/dist/chunk-XXDRCMNC.js
DELETED
|
@@ -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
|