@jpmorganchase/mosaic-store 0.1.0-beta.24 → 0.1.0-beta.26
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 +44 -0
- package/dist/{chunk-74B44ZUJ.js → chunk-5TVTLI2X.js} +1 -1
- package/dist/{chunk-SPCIWRRP.js → chunk-6PEKMIY4.js} +1 -1
- package/dist/chunk-AEFS63H5.js +1 -0
- package/dist/chunk-BWQLFNPL.js +1 -0
- package/dist/chunk-DVDAL7JW.js +1 -0
- package/dist/chunk-LAADEEXW.js +0 -0
- package/dist/{chunk-MSLRBBS3.js → chunk-OTD2Q7J6.js} +1 -1
- package/dist/chunk-OYLDWTGY.js +1 -0
- package/dist/chunk-QVHG25G2.js +1 -0
- package/dist/chunk-RHLTSSFF.js +1 -0
- package/dist/{chunk-MLBDLE43.js → chunk-SSINFAKX.js} +1 -1
- package/dist/chunk-TCTIPP3K.js +1 -0
- package/dist/chunk-THKJVARP.js +1 -0
- package/dist/chunk-V2SJ6GGH.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/store.d.ts +2 -1
- package/dist/store.js +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/navigation.d.ts +21 -0
- package/dist/types/navigation.js +1 -0
- package/dist/types/searchIndex.d.ts +12 -0
- 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/useNavigation.d.ts +2 -0
- package/dist/useNavigation.js +1 -0
- package/dist/useRoute.js +1 -1
- package/dist/useSearchIndex.d.ts +1 -0
- package/dist/useSearchIndex.js +1 -1
- 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 +12 -0
- package/src/__tests__/useSearchIndex.test.ts +29 -2
- package/src/index.ts +1 -1
- package/src/store.ts +4 -0
- package/src/types/index.ts +1 -0
- package/src/types/navigation.ts +23 -0
- package/src/types/searchIndex.ts +10 -0
- package/src/useNavigation.ts +10 -0
- package/src/useSearchIndex.ts +5 -2
- package/dist/chunk-23H66E6E.js +0 -1
- package/dist/chunk-2G7SPWFY.js +0 -1
- package/dist/chunk-4GIIWZ26.js +0 -1
- package/dist/chunk-6B3RGLQ6.js +0 -1
- package/dist/chunk-CI2QHT55.js +0 -1
- package/dist/chunk-FC2ZNWAP.js +0 -1
- package/dist/chunk-LS443IBF.js +0 -1
- package/dist/chunk-RK2QZ3ZO.js +0 -1
- package/dist/chunk-W6IABN6M.js +0 -1
- package/dist/useNextPrev.d.ts +0 -9
- package/dist/useNextPrev.js +0 -1
- package/src/useNextPrev.ts +0 -47
- /package/dist/{chunk-WCQXIIQB.js → chunk-BHW7CEID.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 a6f28688d270091d
|
|
2
2
|
@jpmorganchase/mosaic-store:build: $ npm-run-all --parallel build:*
|
|
3
3
|
@jpmorganchase/mosaic-store:build: $ tsc
|
|
4
4
|
@jpmorganchase/mosaic-store:build: $ node ../../scripts/bundle.js
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @jpmorganchase/mosaic-store
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.26
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 531c87a: ## Mosaic Theme
|
|
8
|
+
|
|
9
|
+
The theme variables are now globally scoped and prefixed with `mosaic`.
|
|
10
|
+
|
|
11
|
+
## BrokenLinksPlugin
|
|
12
|
+
|
|
13
|
+
The `BrokenLinksPlugin` uses a running instance of mosaic to verify that all links in the source pages are alive.
|
|
14
|
+
|
|
15
|
+
If mosaic is running behind a corporate proxy, the `proxyEndpoint` option is required to fetch external URLs.
|
|
16
|
+
|
|
17
|
+
Configuration:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
modulePath: '@jpmorganchase/mosaic-plugins/BrokenLinksPlugin',
|
|
22
|
+
priority: -1,
|
|
23
|
+
// Exclude this plugin in builds
|
|
24
|
+
runTimeOnly: true,
|
|
25
|
+
options: {
|
|
26
|
+
baseUrl: process.env.MOSAIC_ACTIVE_MODE_URL || 'http://localhost:8080',
|
|
27
|
+
proxyEndpoint: 'http://some-proxy-url'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Next/Prev button
|
|
33
|
+
|
|
34
|
+
The next and prev buttons are visible again on pages that have a layout that uses these buttons.
|
|
35
|
+
|
|
36
|
+
## 0.1.0-beta.25
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- 93e9b07: The theme contract provided by the `@jpmorganchase/mosaic-theme` package now uses locally scoped variable names via a Vanilla Extract [Theme Contract](https://vanilla-extract.style/documentation/api/create-theme-contract/). Previously the theme variables were globally scoped resulting in conflicts with other design systems.
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- a36219c: - Next/Prev page buttons were not appearing at the bottom of a page sequence
|
|
45
|
+
- Removed redundant snapshot page api
|
|
46
|
+
|
|
3
47
|
## 0.1.0-beta.24
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as t}from"./chunk-
|
|
1
|
+
import{d as t}from"./chunk-QVHG25G2.js";function o(){return{meta:t(e=>({description:e.description,breadcrumbs:e.breadcrumbs,title:e.title}))}}export{o as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e}from"./chunk-
|
|
1
|
+
import{d as e}from"./chunk-QVHG25G2.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 t}from"./chunk-QVHG25G2.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as c}from"./chunk-QVHG25G2.js";function t(){let e=c(r=>r.searchIndex),o=c(r=>r.searchConfig),n=o!==void 0&&e!==void 0&&e.length>0;return{searchEnabled:n,searchIndex:n?e:[],searchConfig:n?o:{}}}export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./chunk-QVHG25G2.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as t}from"./chunk-
|
|
1
|
+
import{d as t}from"./chunk-QVHG25G2.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 o}from"./chunk-QVHG25G2.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:[],navigation:{},searchIndex:[],searchConfig:{},sharedConfig:{},description:void 0,layout:void 0,route:void 0,title:void 0,colorMode:"light"}}var n=S(void 0),M=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{M as a,i as b,h as c,x as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as o}from"./chunk-QVHG25G2.js";function d(){return o(r=>r.colorMode)}export{d as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as s}from"./chunk-
|
|
1
|
+
import{a as s}from"./chunk-TCTIPP3K.js";import{a as o}from"./chunk-6PEKMIY4.js";import{d as t}from"./chunk-QVHG25G2.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 e}from"./chunk-QVHG25G2.js";function u(){return{route:e(t=>t.route)}}export{u as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as t}from"./chunk-QVHG25G2.js";function r(){let{next:o,prev:i}=t(n=>n.navigation)||{};return{next:o,prev:i}}export{r as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d as t}from"./chunk-QVHG25G2.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './useBreadcrumbs';
|
|
|
4
4
|
export * from './useColorMode';
|
|
5
5
|
export * from './useLayout';
|
|
6
6
|
export * from './useMeta';
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './useNavigation';
|
|
8
8
|
export * from './useRoute';
|
|
9
9
|
export * from './useSearchIndex';
|
|
10
10
|
export * from './useSidebar';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as c}from"./chunk-THKJVARP.js";import{a as g}from"./chunk-BWQLFNPL.js";import{a as h}from"./chunk-SSINFAKX.js";import{a as d}from"./chunk-TCTIPP3K.js";import{a as k}from"./chunk-OYLDWTGY.js";import{a as i}from"./chunk-V2SJ6GGH.js";import{a as p}from"./chunk-OTD2Q7J6.js";import"./chunk-BHW7CEID.js";import"./chunk-IS7TJ54I.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-LAADEEXW.js";import"./chunk-BHMVW2ZZ.js";import{a as m}from"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import{a as t}from"./chunk-6PEKMIY4.js";import{a as x}from"./chunk-RHLTSSFF.js";import{a as j}from"./chunk-DVDAL7JW.js";import{a}from"./chunk-AEFS63H5.js";import{a as b}from"./chunk-5TVTLI2X.js";import{a as o,b as r,c as e,d as f}from"./chunk-QVHG25G2.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,c as useNavigation,d as useRoute,g as useSearchIndex,h as useSidebar,f as useStore,k as useStoreActions,i as useTableOfContents};
|
package/dist/store.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import type { BreadcrumbsSlice } from './types/breadcrumbs';
|
|
|
4
4
|
import type { SearchIndexSlice } from './types/searchIndex';
|
|
5
5
|
import type { SharedConfigSlice } from './types/sharedConfig';
|
|
6
6
|
import type { LayoutSlice } from './types/layout';
|
|
7
|
+
import type { NavigationSlice } from './types/navigation';
|
|
7
8
|
import type { SidebarSlice } from './types/sidebar';
|
|
8
9
|
import type { TableOfContentsSlice } from './types/tableOfContents';
|
|
9
10
|
import type { ColorMode } from './types/colorMode';
|
|
10
|
-
export declare type SiteState = BreadcrumbsSlice & LayoutSlice & SidebarSlice & TableOfContentsSlice & SearchIndexSlice & SharedConfigSlice & {
|
|
11
|
+
export declare type SiteState = BreadcrumbsSlice & LayoutSlice & SidebarSlice & TableOfContentsSlice & NavigationSlice & SearchIndexSlice & SharedConfigSlice & {
|
|
11
12
|
/** Page metadata description, used by search */
|
|
12
13
|
description?: string;
|
|
13
14
|
/** 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-QVHG25G2.js";export{a as StoreProvider,b as initializeStore,c as useCreateStore,d as useStore};
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunk-
|
|
1
|
+
import"../chunk-BHW7CEID.js";import"../chunk-IS7TJ54I.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-LAADEEXW.js";import"../chunk-BHMVW2ZZ.js";import{a}from"../chunk-ZMWHBFUG.js";import"../chunk-VXYECVIB.js";export{a as MenuItemType};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page within a sequence
|
|
3
|
+
*/
|
|
4
|
+
export declare type NavigationLink = {
|
|
5
|
+
/** page title */
|
|
6
|
+
title: string;
|
|
7
|
+
/** page route */
|
|
8
|
+
route: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* [[`Navigation`]] specifies page navigation such as next or previous pages
|
|
12
|
+
*/
|
|
13
|
+
export declare type Navigation = {
|
|
14
|
+
/** next page in sequence */
|
|
15
|
+
next?: NavigationLink;
|
|
16
|
+
/** previous page in sequence */
|
|
17
|
+
prev?: NavigationLink;
|
|
18
|
+
};
|
|
19
|
+
export declare type NavigationSlice = {
|
|
20
|
+
navigation?: Navigation;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"../chunk-LAADEEXW.js";
|
|
@@ -4,7 +4,19 @@ declare type SearchDataPage = {
|
|
|
4
4
|
route: string;
|
|
5
5
|
};
|
|
6
6
|
export declare type SearchIndex = SearchDataPage[];
|
|
7
|
+
export declare type SearchConfig = {
|
|
8
|
+
includeScore?: boolean;
|
|
9
|
+
includeMatches?: boolean;
|
|
10
|
+
maxPatternLength?: number;
|
|
11
|
+
ignoreLocation?: boolean;
|
|
12
|
+
threshold?: number;
|
|
13
|
+
keys?: string[] | {
|
|
14
|
+
name: string;
|
|
15
|
+
weight: number;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
7
18
|
export declare type SearchIndexSlice = {
|
|
8
19
|
searchIndex?: SearchIndex;
|
|
20
|
+
searchConfig?: SearchConfig;
|
|
9
21
|
};
|
|
10
22
|
export {};
|
package/dist/useAppHeader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-OTD2Q7J6.js";import"./chunk-BHW7CEID.js";import"./chunk-IS7TJ54I.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-LAADEEXW.js";import"./chunk-BHMVW2ZZ.js";import"./chunk-ZMWHBFUG.js";import"./chunk-VXYECVIB.js";import"./chunk-QVHG25G2.js";export{a as useAppHeader};
|
package/dist/useBreadcrumbs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-6PEKMIY4.js";import"./chunk-QVHG25G2.js";export{a as useBreadcrumbs};
|
package/dist/useColorMode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-RHLTSSFF.js";import"./chunk-QVHG25G2.js";export{a as useColorMode};
|
package/dist/useFooter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-DVDAL7JW.js";import"./chunk-QVHG25G2.js";export{a as useFooter};
|
package/dist/useLayout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-AEFS63H5.js";import"./chunk-QVHG25G2.js";export{a as useLayout};
|
package/dist/useMeta.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-5TVTLI2X.js";import"./chunk-QVHG25G2.js";export{a as useMeta};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-THKJVARP.js";import"./chunk-QVHG25G2.js";export{a as useNavigation};
|
package/dist/useRoute.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-TCTIPP3K.js";import"./chunk-QVHG25G2.js";export{a as useRoute};
|
package/dist/useSearchIndex.d.ts
CHANGED
package/dist/useSearchIndex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-BWQLFNPL.js";import"./chunk-QVHG25G2.js";export{a as useSearchIndex};
|
package/dist/useSidebar.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-SSINFAKX.js";import"./chunk-TCTIPP3K.js";import"./chunk-6PEKMIY4.js";import"./chunk-QVHG25G2.js";export{a as useSidebar};
|
package/dist/useStoreActions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-OYLDWTGY.js";import"./chunk-QVHG25G2.js";export{a as useStoreActions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-V2SJ6GGH.js";import"./chunk-QVHG25G2.js";export{a as useTableOfContents};
|
package/package.json
CHANGED
|
@@ -14,9 +14,11 @@ describe('GIVEN the store initializer', () => {
|
|
|
14
14
|
const storeApi = initializeStore();
|
|
15
15
|
expect(getStateToVerify(storeApi.getState())).toEqual({
|
|
16
16
|
breadcrumbs: [],
|
|
17
|
+
navigation: {},
|
|
17
18
|
sidebarData: [],
|
|
18
19
|
tableOfContents: [],
|
|
19
20
|
searchIndex: [],
|
|
21
|
+
searchConfig: {},
|
|
20
22
|
sharedConfig: {},
|
|
21
23
|
description: undefined,
|
|
22
24
|
layout: undefined,
|
|
@@ -39,7 +41,9 @@ describe('GIVEN the store initializer', () => {
|
|
|
39
41
|
const storeApi = initializeStore(state);
|
|
40
42
|
expect(getStateToVerify(storeApi.getState())).toEqual({
|
|
41
43
|
breadcrumbs: [],
|
|
44
|
+
navigation: {},
|
|
42
45
|
searchIndex: [],
|
|
46
|
+
searchConfig: {},
|
|
43
47
|
sidebarData: [],
|
|
44
48
|
tableOfContents: [],
|
|
45
49
|
sharedConfig: {},
|
|
@@ -60,7 +64,9 @@ describe('GIVEN the `useCreateStore` hook', () => {
|
|
|
60
64
|
|
|
61
65
|
expect(getStateToVerify(currentState)).toEqual({
|
|
62
66
|
breadcrumbs: [],
|
|
67
|
+
navigation: {},
|
|
63
68
|
searchIndex: [],
|
|
69
|
+
searchConfig: {},
|
|
64
70
|
sidebarData: [],
|
|
65
71
|
tableOfContents: [],
|
|
66
72
|
sharedConfig: {},
|
|
@@ -78,8 +84,10 @@ describe('GIVEN the `useCreateStore` hook', () => {
|
|
|
78
84
|
currentState = result.current().getState();
|
|
79
85
|
expect(getStateToVerify(currentState)).toEqual({
|
|
80
86
|
breadcrumbs: [],
|
|
87
|
+
navigation: {},
|
|
81
88
|
sidebarData: [],
|
|
82
89
|
searchIndex: [],
|
|
90
|
+
searchConfig: {},
|
|
83
91
|
tableOfContents: [],
|
|
84
92
|
sharedConfig: {},
|
|
85
93
|
colorMode: 'light',
|
|
@@ -99,7 +107,9 @@ describe('GIVEN the `useCreateStore` hook', () => {
|
|
|
99
107
|
|
|
100
108
|
expect(getStateToVerify(currentState)).toEqual({
|
|
101
109
|
breadcrumbs: [],
|
|
110
|
+
navigation: {},
|
|
102
111
|
searchIndex: [],
|
|
112
|
+
searchConfig: {},
|
|
103
113
|
sidebarData: [],
|
|
104
114
|
tableOfContents: [],
|
|
105
115
|
sharedConfig: {},
|
|
@@ -118,8 +128,10 @@ describe('GIVEN the `useCreateStore` hook', () => {
|
|
|
118
128
|
|
|
119
129
|
expect(getStateToVerify(currentState)).toEqual({
|
|
120
130
|
breadcrumbs: [],
|
|
131
|
+
navigation: {},
|
|
121
132
|
sidebarData: [],
|
|
122
133
|
searchIndex: [],
|
|
134
|
+
searchConfig: {},
|
|
123
135
|
tableOfContents: [],
|
|
124
136
|
sharedConfig: {},
|
|
125
137
|
colorMode: 'light',
|
|
@@ -20,11 +20,21 @@ const index: SiteState['searchIndex'] = [
|
|
|
20
20
|
}
|
|
21
21
|
];
|
|
22
22
|
|
|
23
|
+
const config: SiteState['searchConfig'] = {
|
|
24
|
+
includeScore: false,
|
|
25
|
+
includeMatches: true,
|
|
26
|
+
maxPatternLength: 240,
|
|
27
|
+
ignoreLocation: true,
|
|
28
|
+
threshold: 0.3,
|
|
29
|
+
keys: ['title', 'content']
|
|
30
|
+
};
|
|
31
|
+
|
|
23
32
|
const state: Partial<SiteState> = {
|
|
24
|
-
searchIndex: index
|
|
33
|
+
searchIndex: index,
|
|
34
|
+
searchConfig: config
|
|
25
35
|
};
|
|
26
36
|
|
|
27
|
-
describe('GIVEN the
|
|
37
|
+
describe('GIVEN the useSearchIndex hook', () => {
|
|
28
38
|
describe('WHEN there is no search index in the store', () => {
|
|
29
39
|
test('THEN searchEnabled is set to false', () => {
|
|
30
40
|
const { result } = renderHook(() => useSearchIndex(), {
|
|
@@ -39,6 +49,13 @@ describe('GIVEN the `useSearchIndex` hook', () => {
|
|
|
39
49
|
expect(Array.isArray(result.current.searchIndex)).toBe(true);
|
|
40
50
|
expect(result.current.searchIndex.length).toBe(0);
|
|
41
51
|
});
|
|
52
|
+
test('AND searchConfig is set to an empty object', () => {
|
|
53
|
+
const { result } = renderHook(() => useSearchIndex(), {
|
|
54
|
+
wrapper: createWrapper()
|
|
55
|
+
});
|
|
56
|
+
expect(typeof result.current.searchConfig).toBe('object');
|
|
57
|
+
expect(Object.keys(result.current.searchConfig).length).toBe(0);
|
|
58
|
+
});
|
|
42
59
|
});
|
|
43
60
|
|
|
44
61
|
describe('WHEN there is a search index in the store', () => {
|
|
@@ -55,5 +72,15 @@ describe('GIVEN the `useSearchIndex` hook', () => {
|
|
|
55
72
|
expect(Array.isArray(result.current.searchIndex)).toBe(true);
|
|
56
73
|
expect(result.current.searchIndex.length).toBe(index.length);
|
|
57
74
|
});
|
|
75
|
+
test('AND searchIndex contains the search config', () => {
|
|
76
|
+
const { result } = renderHook(() => useSearchIndex(), {
|
|
77
|
+
wrapper: createWrapper({ ...state })
|
|
78
|
+
});
|
|
79
|
+
expect(typeof result.current.searchConfig).toBe('object');
|
|
80
|
+
expect(Object.keys(result.current.searchConfig).length).toBe(Object.keys(config).length);
|
|
81
|
+
expect(result.current.searchConfig.ignoreLocation).toBe(true);
|
|
82
|
+
expect(result.current.searchConfig.maxPatternLength).toBe(240);
|
|
83
|
+
expect(result.current.searchConfig.keys).toEqual(['title', 'content']);
|
|
84
|
+
});
|
|
58
85
|
});
|
|
59
86
|
});
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './useBreadcrumbs';
|
|
|
4
4
|
export * from './useColorMode';
|
|
5
5
|
export * from './useLayout';
|
|
6
6
|
export * from './useMeta';
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './useNavigation';
|
|
8
8
|
export * from './useRoute';
|
|
9
9
|
export * from './useSearchIndex';
|
|
10
10
|
export * from './useSidebar';
|
package/src/store.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { BreadcrumbsSlice } from './types/breadcrumbs';
|
|
|
6
6
|
import type { SearchIndexSlice } from './types/searchIndex';
|
|
7
7
|
import type { SharedConfigSlice } from './types/sharedConfig';
|
|
8
8
|
import type { LayoutSlice } from './types/layout';
|
|
9
|
+
import type { NavigationSlice } from './types/navigation';
|
|
9
10
|
import type { SidebarSlice } from './types/sidebar';
|
|
10
11
|
import type { TableOfContentsSlice } from './types/tableOfContents';
|
|
11
12
|
import type { ColorMode } from './types/colorMode';
|
|
@@ -16,6 +17,7 @@ export type SiteState = BreadcrumbsSlice &
|
|
|
16
17
|
LayoutSlice &
|
|
17
18
|
SidebarSlice &
|
|
18
19
|
TableOfContentsSlice &
|
|
20
|
+
NavigationSlice &
|
|
19
21
|
SearchIndexSlice &
|
|
20
22
|
SharedConfigSlice & {
|
|
21
23
|
/** Page metadata description, used by search */
|
|
@@ -38,7 +40,9 @@ function getDefaultInitialState(): DefaultSiteState {
|
|
|
38
40
|
breadcrumbs: [],
|
|
39
41
|
sidebarData: [],
|
|
40
42
|
tableOfContents: [],
|
|
43
|
+
navigation: {},
|
|
41
44
|
searchIndex: [],
|
|
45
|
+
searchConfig: {},
|
|
42
46
|
sharedConfig: {},
|
|
43
47
|
description: undefined,
|
|
44
48
|
layout: undefined,
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page within a sequence
|
|
3
|
+
*/
|
|
4
|
+
export type NavigationLink = {
|
|
5
|
+
/** page title */
|
|
6
|
+
title: string;
|
|
7
|
+
/** page route */
|
|
8
|
+
route: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* [[`Navigation`]] specifies page navigation such as next or previous pages
|
|
13
|
+
*/
|
|
14
|
+
export type Navigation = {
|
|
15
|
+
/** next page in sequence */
|
|
16
|
+
next?: NavigationLink;
|
|
17
|
+
/** previous page in sequence */
|
|
18
|
+
prev?: NavigationLink;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type NavigationSlice = {
|
|
22
|
+
navigation?: Navigation;
|
|
23
|
+
};
|
package/src/types/searchIndex.ts
CHANGED
|
@@ -6,6 +6,16 @@ type SearchDataPage = {
|
|
|
6
6
|
|
|
7
7
|
export type SearchIndex = SearchDataPage[];
|
|
8
8
|
|
|
9
|
+
export type SearchConfig = {
|
|
10
|
+
includeScore?: boolean;
|
|
11
|
+
includeMatches?: boolean;
|
|
12
|
+
maxPatternLength?: number;
|
|
13
|
+
ignoreLocation?: boolean;
|
|
14
|
+
threshold?: number;
|
|
15
|
+
keys?: string[] | { name: string; weight: number }[];
|
|
16
|
+
};
|
|
17
|
+
|
|
9
18
|
export type SearchIndexSlice = {
|
|
10
19
|
searchIndex?: SearchIndex;
|
|
20
|
+
searchConfig?: SearchConfig;
|
|
11
21
|
};
|
package/src/useSearchIndex.ts
CHANGED
|
@@ -4,11 +4,14 @@ export type { SearchIndexSlice } from './types';
|
|
|
4
4
|
|
|
5
5
|
export function useSearchIndex() {
|
|
6
6
|
const searchIndex = useStore(state => state.searchIndex);
|
|
7
|
+
const searchConfig = useStore(state => state.searchConfig);
|
|
7
8
|
|
|
8
|
-
const searchEnabled =
|
|
9
|
+
const searchEnabled =
|
|
10
|
+
searchConfig !== undefined && searchIndex !== undefined && searchIndex.length > 0;
|
|
9
11
|
|
|
10
12
|
return {
|
|
11
13
|
searchEnabled,
|
|
12
|
-
searchIndex: searchEnabled ? searchIndex : []
|
|
14
|
+
searchIndex: searchEnabled ? searchIndex : [],
|
|
15
|
+
searchConfig: searchEnabled ? searchConfig : {}
|
|
13
16
|
};
|
|
14
17
|
}
|
package/dist/chunk-23H66E6E.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./chunk-2G7SPWFY.js";var r=()=>o(t=>t.actions);export{r as a};
|
package/dist/chunk-2G7SPWFY.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/dist/chunk-4GIIWZ26.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/dist/chunk-6B3RGLQ6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./chunk-2G7SPWFY.js";function f(){return o(e=>e.sharedConfig?.footer)}export{f as a};
|
package/dist/chunk-CI2QHT55.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as t}from"./chunk-2G7SPWFY.js";function e(){return{layout:t(o=>o.layout)}}export{e as a};
|
package/dist/chunk-FC2ZNWAP.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as e}from"./chunk-2G7SPWFY.js";function u(){return{route:e(t=>t.route)}}export{u as a};
|
package/dist/chunk-LS443IBF.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as t}from"./chunk-2G7SPWFY.js";function s(){return{tableOfContents:t(e=>e.tableOfContents)||[]}}export{s as a};
|
package/dist/chunk-RK2QZ3ZO.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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};
|
package/dist/chunk-W6IABN6M.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as o}from"./chunk-2G7SPWFY.js";function d(){return o(r=>r.colorMode)}export{d as a};
|
package/dist/useNextPrev.d.ts
DELETED
package/dist/useNextPrev.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-4GIIWZ26.js";import"./chunk-FC2ZNWAP.js";import"./chunk-2G7SPWFY.js";export{a as useNextPrev};
|
package/src/useNextPrev.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useStore } from './store';
|
|
2
|
-
import { useRoute } from './useRoute';
|
|
3
|
-
import type { SidebarItem } from './types/sidebar';
|
|
4
|
-
|
|
5
|
-
type NextPrevItem = { link: string; text: string };
|
|
6
|
-
|
|
7
|
-
export function useNextPrev() {
|
|
8
|
-
const sidebarData = useStore(state => state.sidebarData) || [];
|
|
9
|
-
const { route } = useRoute();
|
|
10
|
-
const { next, prev } = findNextPrevForRoute(sidebarData, route || '');
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
next,
|
|
14
|
-
prev
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
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 }];
|
|
24
|
-
if (node.childNodes) {
|
|
25
|
-
nextResult = [...result, ...flatten(node.childNodes)];
|
|
26
|
-
}
|
|
27
|
-
return nextResult;
|
|
28
|
-
}, []);
|
|
29
|
-
return flattenedNode;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const nextExists = (index: number, length: number) => index >= 0 && index < length - 1;
|
|
33
|
-
|
|
34
|
-
const prevExists = (index: number, length: number) => index > 0 && index < length;
|
|
35
|
-
|
|
36
|
-
const findNextPrevNodes = (nodes: NextPrevItem[], route: string) => {
|
|
37
|
-
const index = nodes.map(e => e.link).indexOf(route);
|
|
38
|
-
const { length } = nodes;
|
|
39
|
-
const next = nextExists(index, length) ? nodes[index + 1] : null;
|
|
40
|
-
const prev = prevExists(index, length) ? nodes[index - 1] : null;
|
|
41
|
-
return { next, prev };
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const findNextPrevForRoute = (nodes: SidebarItem[], route: string) => {
|
|
45
|
-
const flattenedNodes = flatten(nodes);
|
|
46
|
-
return findNextPrevNodes(flattenedNodes, route);
|
|
47
|
-
};
|
|
File without changes
|