weg-shared-layout 0.0.46 → 0.0.47
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/dist/collection/types/menus-data.js +1 -0
- package/dist/collection/utils/menus.js +39 -0
- package/dist/test-utils/layout-fixtures.js +48 -0
- package/dist/types/Users/rakin/Documents/WEG/repos/weg-shared-layout/.stencil/test-utils/layout-fixtures.d.ts +8 -0
- package/dist/types/types/layout-data.d.ts +2 -1
- package/dist/types/types/menus-data.d.ts +37 -0
- package/dist/types/utils/menus.d.ts +18 -0
- package/docs/README.md +54 -51
- package/docs/angular.md +440 -451
- package/docs/nextjs.md +313 -312
- package/docs/publishing.md +65 -65
- package/docs/react.md +291 -287
- package/docs/vanilla.md +159 -155
- package/package.json +93 -81
- package/readme.md +121 -108
- package/src/assets/weg21-bootstrap.json +12 -0
- package/src/assets/weg21-menus.json +19 -0
- package/src/types/menus-data.ts +44 -0
- package/src/utils/menus.ts +65 -0
- package/src/assets/dummy-data.json +0 -221
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import bootstrapDummy from "../assets/weg21-bootstrap.json";
|
|
2
|
+
import menusDummy from "../assets/weg21-menus.json";
|
|
3
|
+
export const DEFAULT_WEG21_API_BASE = 'https://warwickemploymentgroup.com/api/v1/weg21';
|
|
4
|
+
export const WEG21_BOOTSTRAP_DUMMY = bootstrapDummy;
|
|
5
|
+
export const WEG21_MENUS_DUMMY = menusDummy;
|
|
6
|
+
export function menusToLayoutData(bootstrap, menus, options = {}) {
|
|
7
|
+
const headerMenu = options.headerMenu === 'int' ? menus.header.int : menus.header.ext;
|
|
8
|
+
const { credit, copyright, social_links } = bootstrap.footer;
|
|
9
|
+
return {
|
|
10
|
+
header: { menu: headerMenu },
|
|
11
|
+
footer: {
|
|
12
|
+
menu: menus.footer,
|
|
13
|
+
social: social_links,
|
|
14
|
+
credits: credit.trim() || undefined,
|
|
15
|
+
copyright: copyright.trim() || undefined,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Offline layout from package WEG21 dummy fixtures (`weg21-bootstrap.json` + `weg21-menus.json`). */
|
|
20
|
+
export function dummyWeg21LayoutData(options = {}) {
|
|
21
|
+
return menusToLayoutData(WEG21_BOOTSTRAP_DUMMY, WEG21_MENUS_DUMMY, options);
|
|
22
|
+
}
|
|
23
|
+
export async function fetchWeg21Layout(options = {}) {
|
|
24
|
+
const apiBase = (options.apiBase ?? DEFAULT_WEG21_API_BASE).replace(/\/$/, '');
|
|
25
|
+
const fetchFn = options.fetch ?? globalThis.fetch;
|
|
26
|
+
const headers = { accept: 'application/json' };
|
|
27
|
+
if (options.apiKey)
|
|
28
|
+
headers['wcms-api-key'] = options.apiKey;
|
|
29
|
+
const [bootstrapRes, menusRes] = await Promise.all([
|
|
30
|
+
fetchFn(apiBase, { headers }),
|
|
31
|
+
fetchFn(`${apiBase}/menus`, { headers }),
|
|
32
|
+
]);
|
|
33
|
+
if (!bootstrapRes.ok || !menusRes.ok) {
|
|
34
|
+
throw new Error(`WEG21 API error: bootstrap=${bootstrapRes.status} menus=${menusRes.status}`);
|
|
35
|
+
}
|
|
36
|
+
const bootstrap = (await bootstrapRes.json());
|
|
37
|
+
const menus = (await menusRes.json());
|
|
38
|
+
return menusToLayoutData(bootstrap, menus, options);
|
|
39
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Minimal layout for component tests and local fallback. */
|
|
2
|
+
export const SAMPLE_HEADER_LAYOUT = {
|
|
3
|
+
header: {
|
|
4
|
+
menu: [
|
|
5
|
+
{
|
|
6
|
+
label: 'Find a job',
|
|
7
|
+
items: [{ label: 'Graduates', href: '/search?category=graduates' }],
|
|
8
|
+
},
|
|
9
|
+
{ label: 'Career advice', href: '/career-advice' },
|
|
10
|
+
{ label: 'Sign in', href: '/account/login' },
|
|
11
|
+
],
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
/** Header with three dropdown groups (desktop nav interaction tests). */
|
|
15
|
+
export const MULTI_DROPDOWN_HEADER_LAYOUT = {
|
|
16
|
+
header: {
|
|
17
|
+
menu: [
|
|
18
|
+
{
|
|
19
|
+
label: 'Find a job',
|
|
20
|
+
items: [
|
|
21
|
+
{ label: 'Graduates', href: '/graduates' },
|
|
22
|
+
{ label: 'Senior roles', href: '/senior' },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
{ label: 'Hire talent', items: [{ label: 'Executive search', href: '/executive' }] },
|
|
26
|
+
{ label: 'HE solutions', items: [{ label: 'Franchise', href: '/franchise' }] },
|
|
27
|
+
{ label: 'Sign in', href: '/account/login' },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
export const SAMPLE_FOOTER_LAYOUT = {
|
|
32
|
+
footer: {
|
|
33
|
+
social: [{ platform: 'LinkedIn', href: 'https://www.linkedin.com/company/example/' }],
|
|
34
|
+
menu: [
|
|
35
|
+
[
|
|
36
|
+
{ label: 'Find a job', href: '/jobs' },
|
|
37
|
+
{ label: 'About WEG', href: '/about' },
|
|
38
|
+
],
|
|
39
|
+
],
|
|
40
|
+
credits: 'Example credits text.',
|
|
41
|
+
copyright: 'Copyright © Example.',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/** Combined layout for accessibility tests. */
|
|
45
|
+
export const FULL_LAYOUT_FIXTURE = {
|
|
46
|
+
header: MULTI_DROPDOWN_HEADER_LAYOUT.header,
|
|
47
|
+
footer: SAMPLE_FOOTER_LAYOUT.footer,
|
|
48
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LayoutData } from '../src/types/layout-data';
|
|
2
|
+
/** Minimal layout for component tests and local fallback. */
|
|
3
|
+
export declare const SAMPLE_HEADER_LAYOUT: LayoutData;
|
|
4
|
+
/** Header with three dropdown groups (desktop nav interaction tests). */
|
|
5
|
+
export declare const MULTI_DROPDOWN_HEADER_LAYOUT: LayoutData;
|
|
6
|
+
export declare const SAMPLE_FOOTER_LAYOUT: LayoutData;
|
|
7
|
+
/** Combined layout for accessibility tests. */
|
|
8
|
+
export declare const FULL_LAYOUT_FIXTURE: LayoutData;
|
|
@@ -23,7 +23,8 @@ export type LayoutFooterData = {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Layout payload accepted by `<weg-header>` and `<weg-footer>`.
|
|
26
|
-
* @see src/assets/
|
|
26
|
+
* @see src/assets/weg21-bootstrap.json and src/assets/weg21-menus.json (WEG21 API schema)
|
|
27
|
+
* @see src/utils/menus.ts (`menusToLayoutData`, `dummyWeg21LayoutData`)
|
|
27
28
|
*/
|
|
28
29
|
export type LayoutData = {
|
|
29
30
|
header?: Partial<LayoutHeaderData>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WEG21 API types — mirrors wegcms-v2 `src/weg-shared-layout/menus-types.ts`.
|
|
3
|
+
* @see GET /api/v1/weg21
|
|
4
|
+
* @see GET /api/v1/weg21/menus
|
|
5
|
+
*/
|
|
6
|
+
export type LayoutPlatform = 'LinkedIn' | 'Instagram' | 'TikTok' | 'YouTube';
|
|
7
|
+
export type LayoutSocialLink = {
|
|
8
|
+
platform: LayoutPlatform;
|
|
9
|
+
href: string;
|
|
10
|
+
};
|
|
11
|
+
export type MenuItemProps = {
|
|
12
|
+
label: string;
|
|
13
|
+
href?: string;
|
|
14
|
+
items?: MenuItemProps[];
|
|
15
|
+
};
|
|
16
|
+
export type HeaderMenuProps = {
|
|
17
|
+
ext: MenuItemProps[];
|
|
18
|
+
int: MenuItemProps[];
|
|
19
|
+
};
|
|
20
|
+
export type FooterMenuProps = MenuItemProps[][];
|
|
21
|
+
/** `GET /api/v1/weg21/menus` response body. */
|
|
22
|
+
export type MenusProps = {
|
|
23
|
+
header: HeaderMenuProps;
|
|
24
|
+
footer: FooterMenuProps;
|
|
25
|
+
};
|
|
26
|
+
export type Weg21FooterProps = {
|
|
27
|
+
social_links: LayoutSocialLink[];
|
|
28
|
+
credit: string;
|
|
29
|
+
copyright: string;
|
|
30
|
+
};
|
|
31
|
+
/** `GET /api/v1/weg21` response body. */
|
|
32
|
+
export type Weg21BootstrapProps = {
|
|
33
|
+
logo: string;
|
|
34
|
+
favicon: string;
|
|
35
|
+
menus: string;
|
|
36
|
+
footer: Weg21FooterProps;
|
|
37
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { LayoutData } from '../types/layout-data';
|
|
2
|
+
import type { MenusProps, Weg21BootstrapProps } from '../types/menus-data';
|
|
3
|
+
export declare const DEFAULT_WEG21_API_BASE = "https://warwickemploymentgroup.com/api/v1/weg21";
|
|
4
|
+
export declare const WEG21_BOOTSTRAP_DUMMY: Weg21BootstrapProps;
|
|
5
|
+
export declare const WEG21_MENUS_DUMMY: MenusProps;
|
|
6
|
+
export type MenusToLayoutOptions = {
|
|
7
|
+
/** Which header nav slice maps to `header.menu`. Default: `ext` (public marketing nav). */
|
|
8
|
+
headerMenu?: 'ext' | 'int';
|
|
9
|
+
};
|
|
10
|
+
export declare function menusToLayoutData(bootstrap: Pick<Weg21BootstrapProps, 'footer'>, menus: MenusProps, options?: MenusToLayoutOptions): LayoutData;
|
|
11
|
+
/** Offline layout from package WEG21 dummy fixtures (`weg21-bootstrap.json` + `weg21-menus.json`). */
|
|
12
|
+
export declare function dummyWeg21LayoutData(options?: MenusToLayoutOptions): LayoutData;
|
|
13
|
+
export type FetchWeg21LayoutOptions = MenusToLayoutOptions & {
|
|
14
|
+
apiBase?: string;
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
fetch?: typeof fetch;
|
|
17
|
+
};
|
|
18
|
+
export declare function fetchWeg21Layout(options?: FetchWeg21LayoutOptions): Promise<LayoutData>;
|
package/docs/README.md
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
-
# Documentation index
|
|
2
|
-
|
|
3
|
-
Guides for integrating **`weg-shared-layout`** (`<weg-header>`, `<weg-footer>`) in host applications.
|
|
4
|
-
|
|
5
|
-
Layout
|
|
6
|
-
|
|
7
|
-
**Nav active state:** pass **`current-path`** / **`currentPath`** on `<weg-header>` from your router (see framework guides below).
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Choose a guide
|
|
12
|
-
|
|
13
|
-
| Guide | Audience |
|
|
14
|
-
| --- | --- |
|
|
15
|
-
| **[../readme.md](../readme.md)** | Package overview, install,
|
|
16
|
-
| **[angular.md](./angular.md)** | **Angular 16** — step-by-step integration |
|
|
17
|
-
| **[../demo/angular16/README.md](../demo/angular16/README.md)** | Runnable Angular 16 demo (`npm run demo:angular16`) |
|
|
18
|
-
| **[react.md](./react.md)** | React 19+ SPA (Vite, CRA, etc.) |
|
|
19
|
-
| **[nextjs.md](./nextjs.md)** | Next.js 13+ App Router |
|
|
20
|
-
| **[vanilla.md](./vanilla.md)** | Plain HTML / vanilla JS + bundler |
|
|
21
|
-
| **[publishing.md](./publishing.md)** | Maintainers — npm publish, `prepack`, release checklist |
|
|
22
|
-
|
|
23
|
-
Newer Angular (signals): [weg-angular-demo](https://github.com/jobsac/weg-angular-demo).
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
## Package entry points
|
|
28
|
-
|
|
29
|
-
Published subpaths (see [`package.json` `exports`](../package.json)):
|
|
30
|
-
|
|
31
|
-
| Import | Purpose |
|
|
32
|
-
| --- | --- |
|
|
33
|
-
| `weg-shared-layout/loader` | **`defineCustomElements()`** — register all tags (recommended) |
|
|
34
|
-
| `weg-shared-layout/
|
|
35
|
-
| `weg-shared-layout/
|
|
36
|
-
| `weg-shared-layout/
|
|
37
|
-
| `weg-shared-layout/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
|
51
|
-
|
|
|
1
|
+
# Documentation index
|
|
2
|
+
|
|
3
|
+
Guides for integrating **`weg-shared-layout`** (`<weg-header>`, `<weg-footer>`) in host applications.
|
|
4
|
+
|
|
5
|
+
Layout data comes from the **WEG CMS WEG21 API** (`GET /api/v1/weg21` + `/menus`), mapped to `layout` via [`fetchWeg21Layout`](../src/utils/menus.ts). Schema reference: [`weg21-bootstrap.json`](../src/assets/weg21-bootstrap.json), [`weg21-menus.json`](../src/assets/weg21-menus.json).
|
|
6
|
+
|
|
7
|
+
**Nav active state:** pass **`current-path`** / **`currentPath`** on `<weg-header>` from your router (see framework guides below).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Choose a guide
|
|
12
|
+
|
|
13
|
+
| Guide | Audience |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| **[../readme.md](../readme.md)** | Package overview, install, WEG21 API |
|
|
16
|
+
| **[angular.md](./angular.md)** | **Angular 16** — step-by-step integration |
|
|
17
|
+
| **[../demo/angular16/README.md](../demo/angular16/README.md)** | Runnable Angular 16 demo (`npm run demo:angular16`) |
|
|
18
|
+
| **[react.md](./react.md)** | React 19+ SPA (Vite, CRA, etc.) |
|
|
19
|
+
| **[nextjs.md](./nextjs.md)** | Next.js 13+ App Router |
|
|
20
|
+
| **[vanilla.md](./vanilla.md)** | Plain HTML / vanilla JS + bundler |
|
|
21
|
+
| **[publishing.md](./publishing.md)** | Maintainers — npm publish, `prepack`, release checklist |
|
|
22
|
+
|
|
23
|
+
Newer Angular (signals): [weg-angular-demo](https://github.com/jobsac/weg-angular-demo).
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Package entry points
|
|
28
|
+
|
|
29
|
+
Published subpaths (see [`package.json` `exports`](../package.json)):
|
|
30
|
+
|
|
31
|
+
| Import | Purpose |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `weg-shared-layout/loader` | **`defineCustomElements()`** — register all tags (recommended) |
|
|
34
|
+
| `weg-shared-layout/menus` | **`fetchWeg21Layout`**, **`menusToLayoutData`** |
|
|
35
|
+
| `weg-shared-layout/menus-data` | WEG21 API types (`MenusProps`, `Weg21BootstrapProps`, …) |
|
|
36
|
+
| `weg-shared-layout/layout-data` | Types for `layout` prop (`LayoutData`, …) |
|
|
37
|
+
| `weg-shared-layout/weg21-bootstrap.json` | `Weg21BootstrapProps` sample (`GET /api/v1/weg21`) |
|
|
38
|
+
| `weg-shared-layout/weg21-menus.json` | `MenusProps` sample (`GET /api/v1/weg21/menus`) |
|
|
39
|
+
| `weg-shared-layout/weg-header` | Single-tag side-effect import (needs modern `moduleResolution`) |
|
|
40
|
+
| `weg-shared-layout/weg-footer` | Single-tag side-effect import |
|
|
41
|
+
|
|
42
|
+
TypeScript apps should set **`resolveJsonModule": true`** and **`moduleResolution": "bundler"`** (or `"node16"` / `"nodenext"`). See **[angular.md § Step 2](./angular.md#step-2--typescript-config)**.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Maintainer scripts
|
|
47
|
+
|
|
48
|
+
From repo root:
|
|
49
|
+
|
|
50
|
+
| Script | Action |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `npm run build` | Stencil build → `dist/`, `loader/` |
|
|
53
|
+
| `npm run demo:angular16` | Build library + `ng serve` in `demo/angular16` |
|
|
54
|
+
| `npm run demo:angular16:build` | Build library + production build of demo |
|