@jpmorganchase/mosaic-store 0.1.0-beta.8
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 +4 -0
- package/CHANGELOG.md +7 -0
- package/README.md +9 -0
- package/dist/chunk-5L7EI47O.js +0 -0
- package/dist/chunk-5TAZCOCH.js +1 -0
- package/dist/chunk-AA7IK7Y5.js +1 -0
- package/dist/chunk-ASPK4M5R.js +0 -0
- package/dist/chunk-BHMVW2ZZ.js +0 -0
- package/dist/chunk-BZYGOU7Y.js +0 -0
- package/dist/chunk-C62PIKZ5.js +1 -0
- package/dist/chunk-DGGPN6YK.js +1 -0
- package/dist/chunk-HUM6DWGV.js +1 -0
- package/dist/chunk-LYZGAQ5N.js +1 -0
- package/dist/chunk-MBLLQB7A.js +0 -0
- package/dist/chunk-OHN6TEOW.js +1 -0
- package/dist/chunk-PN7DOU52.js +1 -0
- package/dist/chunk-SD2G45FB.js +1 -0
- package/dist/chunk-TEDOG7PC.js +1 -0
- package/dist/chunk-UGD4MMRB.js +0 -0
- package/dist/chunk-UK5NIPTI.js +0 -0
- package/dist/chunk-UMYWSM5J.js +1 -0
- package/dist/chunk-VXYECVIB.js +0 -0
- package/dist/chunk-ZJYDN5YH.js +0 -0
- package/dist/chunk-ZYJGHEAC.js +0 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -0
- package/dist/store.d.ts +30 -0
- package/dist/store.js +1 -0
- package/dist/types/appHeader.d.ts +66 -0
- package/dist/types/appHeader.js +1 -0
- package/dist/types/breadcrumbs.d.ts +20 -0
- package/dist/types/breadcrumbs.js +1 -0
- package/dist/types/footer.d.ts +16 -0
- package/dist/types/footer.js +1 -0
- package/dist/types/helpLinks.d.ts +13 -0
- package/dist/types/helpLinks.js +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +1 -0
- package/dist/types/layout.d.ts +7 -0
- package/dist/types/layout.js +1 -0
- package/dist/types/meta.d.ts +12 -0
- package/dist/types/meta.js +1 -0
- package/dist/types/route.d.ts +7 -0
- package/dist/types/route.js +1 -0
- package/dist/types/sharedConfig.d.ts +14 -0
- package/dist/types/sharedConfig.js +1 -0
- package/dist/types/sidebar.d.ts +22 -0
- package/dist/types/sidebar.js +1 -0
- package/dist/types/tableOfContents.d.ts +18 -0
- package/dist/types/tableOfContents.js +1 -0
- package/dist/useAppHeader.d.ts +9 -0
- package/dist/useAppHeader.js +1 -0
- package/dist/useBreadcrumbs.d.ts +5 -0
- package/dist/useBreadcrumbs.js +1 -0
- package/dist/useFooter.d.ts +4 -0
- package/dist/useFooter.js +1 -0
- package/dist/useLayout.d.ts +4 -0
- package/dist/useLayout.js +1 -0
- package/dist/useMeta.d.ts +5 -0
- package/dist/useMeta.js +1 -0
- package/dist/useNextPrev.d.ts +4 -0
- package/dist/useNextPrev.js +1 -0
- package/dist/useRoute.d.ts +2 -0
- package/dist/useRoute.js +1 -0
- package/dist/useSidebar.d.ts +5 -0
- package/dist/useSidebar.js +1 -0
- package/dist/useTableOfContents.d.ts +4 -0
- package/dist/useTableOfContents.js +1 -0
- package/package.json +32 -0
- package/src/__tests__/store.test.ts +126 -0
- package/src/__tests__/test-utils/utils.tsx +25 -0
- package/src/__tests__/useAppHeader.test.ts +182 -0
- package/src/__tests__/useBreadcrumbs.test.ts +42 -0
- package/src/__tests__/useFooter.test.ts +64 -0
- package/src/__tests__/useLayout.test.ts +24 -0
- package/src/__tests__/useMeta.test.ts +35 -0
- package/src/__tests__/useRoute.test.ts +24 -0
- package/src/__tests__/useTableOfContents.test.ts +31 -0
- package/src/index.ts +13 -0
- package/src/store.ts +105 -0
- package/src/types/appHeader.ts +72 -0
- package/src/types/breadcrumbs.ts +21 -0
- package/src/types/footer.ts +17 -0
- package/src/types/helpLinks.ts +13 -0
- package/src/types/index.ts +10 -0
- package/src/types/layout.ts +7 -0
- package/src/types/meta.ts +13 -0
- package/src/types/route.ts +7 -0
- package/src/types/sharedConfig.ts +16 -0
- package/src/types/sidebar.ts +22 -0
- package/src/types/tableOfContents.ts +19 -0
- package/src/useAppHeader.ts +64 -0
- package/src/useBreadcrumbs.ts +11 -0
- package/src/useFooter.ts +10 -0
- package/src/useLayout.ts +9 -0
- package/src/useMeta.ts +17 -0
- package/src/useNextPrev.ts +43 -0
- package/src/useRoute.ts +9 -0
- package/src/useSidebar.ts +16 -0
- package/src/useTableOfContents.ts +10 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [[`MenuItemType`]] defines the type of App header Menu items
|
|
3
|
+
*/
|
|
4
|
+
export enum MenuItemType {
|
|
5
|
+
MENU = 'menu',
|
|
6
|
+
LINK = 'link'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* [[`Menu`]] defines App Header menus
|
|
11
|
+
*/
|
|
12
|
+
export type Menu = MenuLinksItem | MenuLinkItem;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* [[`MenuLinksItem`]] defines a menu of links
|
|
16
|
+
*/
|
|
17
|
+
export interface MenuLinksItem {
|
|
18
|
+
/** Collection of link options */
|
|
19
|
+
links: MenuLinkItem[];
|
|
20
|
+
/** Title of Tab */
|
|
21
|
+
title: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* [[`MenuLinksItem`]] defines a menu of links and includes a type
|
|
26
|
+
*/
|
|
27
|
+
export interface AppHeaderMenuLinksItem {
|
|
28
|
+
/** Collection of link options */
|
|
29
|
+
links: MenuLinkItem[];
|
|
30
|
+
/** Title of Tab */
|
|
31
|
+
title: string;
|
|
32
|
+
/** Type of Tab */
|
|
33
|
+
type: MenuItemType.MENU;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* [[`MenuLinkItem`]] define a menu link
|
|
38
|
+
*/
|
|
39
|
+
export interface MenuLinkItem {
|
|
40
|
+
/** URL linked by Tab */
|
|
41
|
+
link: string;
|
|
42
|
+
/** Title of Tab */
|
|
43
|
+
title?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* [[`MenuLinkItem`]] define a menu link and include a type
|
|
48
|
+
*/
|
|
49
|
+
export interface AppHeaderMenuLinkItem {
|
|
50
|
+
/** URL linked by Tab */
|
|
51
|
+
link: string;
|
|
52
|
+
/** Title of Tab */
|
|
53
|
+
title?: string;
|
|
54
|
+
/** Type of Tab */
|
|
55
|
+
type: MenuItemType.LINK;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* [[`AppHeaderSlice`]] specifies the contents of the AppHeader
|
|
60
|
+
*/
|
|
61
|
+
export type AppHeaderSlice = {
|
|
62
|
+
/** App logo/title */
|
|
63
|
+
title: string;
|
|
64
|
+
/** Link to the home page */
|
|
65
|
+
homeLink: string;
|
|
66
|
+
/** Logo URL */
|
|
67
|
+
logo?: string;
|
|
68
|
+
/** App Header menu */
|
|
69
|
+
menu: Menu[];
|
|
70
|
+
/** Search namespace, suffix used on env variable `process.env.SEARCH_ENDPOINT` to filter search results to a specific namespace. */
|
|
71
|
+
searchNamespace?: string;
|
|
72
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [[`Breadcrumb`]] defines the breadcrumb for a page
|
|
3
|
+
*/
|
|
4
|
+
export type Breadcrumb = {
|
|
5
|
+
/** The associated route/path of the breadcrumb */
|
|
6
|
+
path: string;
|
|
7
|
+
/** Whether the breadcrumb is hidden */
|
|
8
|
+
hidden: boolean;
|
|
9
|
+
/** UID */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Breadcrumb label */
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* [[`BreadcrumbsSlice`]] is the associated [[`Breadcrumb`]] items
|
|
17
|
+
*/
|
|
18
|
+
export type BreadcrumbsSlice = {
|
|
19
|
+
/** Path described in breadcrumbs */
|
|
20
|
+
breadcrumbs: Breadcrumb[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HelpLinks } from './helpLinks';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* [[`FooterSlice`]] specifies the footer props
|
|
5
|
+
*/
|
|
6
|
+
export type FooterSlice = {
|
|
7
|
+
/** Footer description/message */
|
|
8
|
+
description: string;
|
|
9
|
+
/** Footer title */
|
|
10
|
+
title: string;
|
|
11
|
+
/** Sign-up URL */
|
|
12
|
+
href: string;
|
|
13
|
+
/** Support channels */
|
|
14
|
+
helpLinks: HelpLinks;
|
|
15
|
+
/** Sign-up label */
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [[`HelpLinks`]] specifies the support channels
|
|
3
|
+
*/
|
|
4
|
+
export type HelpLinks = {
|
|
5
|
+
/** StackOverflow link label */
|
|
6
|
+
stackoverflowLabel: string;
|
|
7
|
+
/** StackOverflow URL for product support */
|
|
8
|
+
stackoverflowUrl: string;
|
|
9
|
+
/** Symphony link label */
|
|
10
|
+
symphonyLabel: string;
|
|
11
|
+
/** Symphony URL for product support */
|
|
12
|
+
symphonyUrl: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './appHeader';
|
|
2
|
+
export * from './breadcrumbs';
|
|
3
|
+
export * from './footer';
|
|
4
|
+
export * from './helpLinks';
|
|
5
|
+
export * from './layout';
|
|
6
|
+
export * from './meta';
|
|
7
|
+
export * from './route';
|
|
8
|
+
export * from './sharedConfig';
|
|
9
|
+
export * from './sidebar';
|
|
10
|
+
export * from './tableOfContents';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Breadcrumb } from './breadcrumbs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* [[`MetaSlice`]] specifies the page's head metadata
|
|
5
|
+
*/
|
|
6
|
+
export type MetaSlice = {
|
|
7
|
+
/** Page description */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Page breadcrumbs */
|
|
10
|
+
breadcrumbs?: Breadcrumb[];
|
|
11
|
+
/** Page title */
|
|
12
|
+
title?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AppHeaderSlice } from './appHeader';
|
|
2
|
+
import type { FooterSlice } from './footer';
|
|
3
|
+
import type { SidebarSlice } from './sidebar';
|
|
4
|
+
|
|
5
|
+
export type SharedConfig = {
|
|
6
|
+
/** Footer props */
|
|
7
|
+
footer?: FooterSlice;
|
|
8
|
+
/** Header props */
|
|
9
|
+
header?: AppHeaderSlice;
|
|
10
|
+
/** Sidebar props */
|
|
11
|
+
sidebar?: SidebarSlice;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type SharedConfigSlice = {
|
|
15
|
+
sharedConfig: SharedConfig;
|
|
16
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SidebarItem = {
|
|
2
|
+
/** The id of the item */
|
|
3
|
+
id: string;
|
|
4
|
+
/** The name of the item */
|
|
5
|
+
name: string;
|
|
6
|
+
/** Sidebar data */
|
|
7
|
+
data: {
|
|
8
|
+
/** The link of the item */
|
|
9
|
+
link: string;
|
|
10
|
+
};
|
|
11
|
+
/** Child nodes */
|
|
12
|
+
childNodes: SidebarItem[];
|
|
13
|
+
/** Whether the item is hidden */
|
|
14
|
+
hidden: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* [[`SidebarSlice`]] specifies sidebar content
|
|
18
|
+
*/
|
|
19
|
+
export type SidebarSlice = {
|
|
20
|
+
/** Sidebar items */
|
|
21
|
+
sidebarData: SidebarItem[];
|
|
22
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [[`TableOfContentsItem`]] defines a table of contents item
|
|
3
|
+
*/
|
|
4
|
+
export type TableOfContentsItem = {
|
|
5
|
+
/** The depth of the heading */
|
|
6
|
+
level: number;
|
|
7
|
+
/** The id attribute of the heading */
|
|
8
|
+
id: string;
|
|
9
|
+
/** The heading text */
|
|
10
|
+
text: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* [[`TableOfContentsSlice`]] defines the table of contents for a page
|
|
15
|
+
*/
|
|
16
|
+
export type TableOfContentsSlice = {
|
|
17
|
+
/** Path described in breadcrumbs */
|
|
18
|
+
tableOfContents: TableOfContentsItem[];
|
|
19
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useStore } from './store';
|
|
2
|
+
import { MenuItemType } from './types';
|
|
3
|
+
import type {
|
|
4
|
+
AppHeaderSlice,
|
|
5
|
+
AppHeaderMenuLinkItem,
|
|
6
|
+
AppHeaderMenuLinksItem,
|
|
7
|
+
MenuLinkItem,
|
|
8
|
+
MenuLinksItem
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
function isMenu(menu: MenuLinkItem | MenuLinksItem): menu is MenuLinksItem {
|
|
12
|
+
return (menu as MenuLinksItem).links !== undefined;
|
|
13
|
+
}
|
|
14
|
+
function isMenuLink(menu: MenuLinkItem | MenuLinksItem): menu is MenuLinkItem {
|
|
15
|
+
return (menu as MenuLinkItem).link !== undefined;
|
|
16
|
+
}
|
|
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
|
+
export type AppHeaderMenu = Array<AppHeaderMenuLinksItem | AppHeaderMenuLinkItem>;
|
|
25
|
+
|
|
26
|
+
export interface AppHeader extends Omit<AppHeaderSlice, 'searchNamespace | menu'> {
|
|
27
|
+
HeaderControlsProps?: {
|
|
28
|
+
searchEndpoint: string;
|
|
29
|
+
};
|
|
30
|
+
menu: AppHeaderMenu;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useAppHeader(): AppHeader | undefined {
|
|
34
|
+
const appHeader = useStore(state => state.sharedConfig?.header);
|
|
35
|
+
if (!appHeader) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
let additionalProps = {};
|
|
39
|
+
if (appHeader.searchNamespace) {
|
|
40
|
+
additionalProps = {
|
|
41
|
+
HeaderControlsProps: {
|
|
42
|
+
searchEndpoint: parseSearchEndpoint(appHeader.searchNamespace)
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const typedMenu: AppHeaderMenu = appHeader.menu.reduce<AppHeaderMenu>((result, menu) => {
|
|
47
|
+
if (isMenu(menu)) {
|
|
48
|
+
const linksItem: AppHeaderMenuLinksItem = { ...menu, type: MenuItemType.MENU };
|
|
49
|
+
return [...result, linksItem];
|
|
50
|
+
}
|
|
51
|
+
if (isMenuLink(menu)) {
|
|
52
|
+
const linkItem: AppHeaderMenuLinkItem = { ...menu, type: MenuItemType.LINK };
|
|
53
|
+
return [...result, linkItem];
|
|
54
|
+
}
|
|
55
|
+
console.error('Unknown menu type passed to useAppHeader, ignoring', menu);
|
|
56
|
+
return result;
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
...additionalProps,
|
|
61
|
+
...appHeader,
|
|
62
|
+
menu: typedMenu
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useStore } from './store';
|
|
2
|
+
|
|
3
|
+
export type { Breadcrumb } from './types';
|
|
4
|
+
|
|
5
|
+
export function useBreadcrumbs(minCrumbs = 1) {
|
|
6
|
+
const breadcrumbs = useStore(state => state.breadcrumbs);
|
|
7
|
+
return {
|
|
8
|
+
breadcrumbs: breadcrumbs || [],
|
|
9
|
+
enabled: breadcrumbs?.length > minCrumbs
|
|
10
|
+
};
|
|
11
|
+
}
|
package/src/useFooter.ts
ADDED
package/src/useLayout.ts
ADDED
package/src/useMeta.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useStore } from './store';
|
|
2
|
+
import type { MetaSlice } from './types';
|
|
3
|
+
|
|
4
|
+
export type Meta = {
|
|
5
|
+
meta: MetaSlice;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function useMeta(): Meta {
|
|
9
|
+
const meta = useStore(state => ({
|
|
10
|
+
description: state.description,
|
|
11
|
+
breadcrumbs: state.breadcrumbs,
|
|
12
|
+
title: state.title
|
|
13
|
+
}));
|
|
14
|
+
return {
|
|
15
|
+
meta
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useStore } from './store';
|
|
2
|
+
import { useRoute } from '.';
|
|
3
|
+
|
|
4
|
+
type NextPrevItem = { link: string; text: string };
|
|
5
|
+
|
|
6
|
+
export function useNextPrev() {
|
|
7
|
+
const sidebarData = useStore(state => state.sidebarData) || [];
|
|
8
|
+
const { route } = useRoute();
|
|
9
|
+
const { next, prev } = findNextPrevForRoute(sidebarData, route);
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
next,
|
|
13
|
+
prev
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const findNextPrevForRoute = (nodes, route) => {
|
|
18
|
+
const flattenedNodes = flatten(nodes);
|
|
19
|
+
return findNextPrevNodes(flattenedNodes, route);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const flatten = nodes => {
|
|
23
|
+
let flattenedNodes: NextPrevItem[] = [];
|
|
24
|
+
nodes.forEach(node => {
|
|
25
|
+
flattenedNodes.push({ link: node.data.link, text: node.name });
|
|
26
|
+
if (node.childNodes) {
|
|
27
|
+
flattenedNodes = flattenedNodes.concat(flatten(node.childNodes));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return flattenedNodes;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const findNextPrevNodes = (nodes, route) => {
|
|
34
|
+
const index = nodes.map(e => e.link).indexOf(route);
|
|
35
|
+
const { length } = nodes;
|
|
36
|
+
const next = nextExists(index, length) ? nodes[index + 1] : null;
|
|
37
|
+
const prev = prevExists(index, length) ? nodes[index - 1] : null;
|
|
38
|
+
return { next, prev };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const nextExists = (index, length) => index >= 0 && index < length - 1;
|
|
42
|
+
|
|
43
|
+
const prevExists = (index, length) => index > 0 && index < length;
|
package/src/useRoute.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useStore } from './store';
|
|
2
|
+
import { useRoute, useBreadcrumbs } from '.';
|
|
3
|
+
|
|
4
|
+
export function useSidebar() {
|
|
5
|
+
const sidebarData = useStore(state => state.sidebarData) || [];
|
|
6
|
+
const { route } = useRoute();
|
|
7
|
+
const { breadcrumbs } = useBreadcrumbs();
|
|
8
|
+
return {
|
|
9
|
+
sidebarData,
|
|
10
|
+
selectedNodeId: route,
|
|
11
|
+
expandedNodeIds: getIds(breadcrumbs)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getIds(breadcrumbs) {
|
|
15
|
+
return new Set(breadcrumbs.map(({ id }) => id.substr(0, id.lastIndexOf('.'))));
|
|
16
|
+
}
|