weg-shared-layout 0.0.45 → 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/docs/vanilla.md CHANGED
@@ -1,155 +1,159 @@
1
- # Plain HTML / vanilla JS
2
-
3
- ## What you get
4
-
5
- | Tag | Purpose |
6
- | --- | --- |
7
- | `<weg-header>` | Site header — bundled logo, CMS nav (signed out), built-in nav (signed in), Sign in / Manage Account / Sign out |
8
- | `<weg-footer>` | Site footer — social links, menu, credits, copyright |
9
-
10
- Both components are **presentational**: they do **not** fetch data. Pass the same `layout` payload to each.
11
-
12
- Payload shape: [`dummy-data.json`](../src/assets/dummy-data.json) (see [readme](../readme.md#how-it-works)).
13
-
14
- ## Install & register
15
-
16
- With a bundler that resolves `node_modules` and package **`exports`** (TypeScript: `resolveJsonModule` + `moduleResolution` `bundler` or `node16` — see [angular.md](./angular.md)):
17
-
18
- ```html
19
- <weg-header id="header"></weg-header>
20
- <main><!-- your content --></main>
21
- <weg-footer id="footer"></weg-footer>
22
-
23
- <script type="module">
24
- import { defineCustomElements } from 'weg-shared-layout/loader';
25
- import layout from 'weg-shared-layout/dummy-data.json';
26
-
27
- defineCustomElements();
28
-
29
- const header = document.getElementById('header');
30
- const footer = document.getElementById('footer');
31
-
32
- header.layout = layout;
33
- footer.layout = layout;
34
-
35
- function updateCurrentPath() {
36
- const { pathname, search } = window.location;
37
- header.currentPath = search ? `${pathname}${search}` : pathname;
38
- }
39
-
40
- updateCurrentPath();
41
- window.addEventListener('popstate', updateCurrentPath);
42
- </script>
43
- ```
44
-
45
- Side-effect imports (no loader) if you only need specific tags:
46
-
47
- ```js
48
- import 'weg-shared-layout/weg-header';
49
- import 'weg-shared-layout/weg-footer';
50
- ```
51
-
52
- ## `layout` property vs attribute
53
-
54
- Assign the **`layout` JavaScript property** (recommended):
55
-
56
- ```js
57
- element.layout = layoutObject;
58
- ```
59
-
60
- Or pass a JSON **string** on the `layout` attribute:
61
-
62
- ```html
63
- <weg-header layout='{"header":{"menu":[]}}'></weg-header>
64
- ```
65
-
66
- ## Header layout fields (signed out)
67
-
68
- | Field | Purpose |
69
- | --- | --- |
70
- | `header.logoSrc` | Logo image URL (bundled if omitted) |
71
- | `header.logoHref` | Logo link URL (WEG homepage if omitted) |
72
- | `header.menu` | Unified nav — groups with `items[]`, flat links with `href` (incl. Sign in) |
73
-
74
- See [`dummy-data.json`](../src/assets/dummy-data.json) for production URL examples.
75
-
76
- ## Header auth (Sign in / Sign out)
77
-
78
- ### Signed out
79
-
80
- Renders `header.menu` from `layout`. Add sign-in as a normal link — `{ "label": "Sign in", "href": "…" }` — like Register. The header recognizes it by label or login URL and follows `href` on click.
81
-
82
- ### Signed in
83
-
84
- Set **`signedIn`** and optionally **`userName`**. CMS nav is ignored; built-in links are shown (Find a job, Dashboard, Manage Account, Sign out). Set **`accountBaseUrl`** when account links should use a non-production portal.
85
-
86
- ```js
87
- header.signedIn = true;
88
- header.userName = 'Alex';
89
- // header.accountBaseUrl = 'https://account-staging.example.com';
90
- // or
91
- header.setAttribute('signed-in', '');
92
- header.setAttribute('user-name', 'Alex');
93
- ```
94
-
95
- Listen for **`wegAuthClick`** to handle sign-out (call your logout API, then redirect):
96
-
97
- ```js
98
- header.addEventListener('wegAuthClick', async (event) => {
99
- if (event.detail.action !== 'sign-out') return;
100
-
101
- event.preventDefault();
102
- header.signedIn = false;
103
- await logout();
104
- window.location.assign('/');
105
- });
106
- ```
107
-
108
- | `event.detail.action` | Default behaviour if not prevented |
109
- | --- | --- |
110
- | `'sign-in'` | Browser follows the link's `href` |
111
- | `'sign-out'` | Emits event only — no navigation (host handles logout) |
112
-
113
- ## Nav active state
114
-
115
- Set **`currentPath`** (property) or **`current-path`** (attribute) to the current pathname. Include `?query` when dropdown links use search params.
116
-
117
- ```js
118
- function syncCurrentPath() {
119
- const { pathname, search } = window.location;
120
- header.currentPath = search ? `${pathname}${search}` : pathname;
121
- }
122
-
123
- syncCurrentPath();
124
- window.addEventListener('popstate', syncCurrentPath);
125
- ```
126
-
127
- | Link type | Match rule |
128
- | --- | --- |
129
- | Flat nav link | Prefix match on pathname |
130
- | Dropdown child | Exact pathname (+ query when href has `?`) |
131
- | Dropdown parent | Active when any child matches |
132
- | Sign in / Sign out | Never highlighted |
133
-
134
- Active links use **`weg-purple-200`** (`#CDCFF8`).
135
-
136
- Logo **image** uses `header.logoSrc` (bundled if omitted). Logo **link** uses `header.logoHref` when provided; otherwise it goes to the WEG homepage.
137
-
138
- ## Without a bundler
139
-
140
- Copy `dummy-data.json` to your static assets, `fetch` it, parse JSON, then assign properties:
141
-
142
- ```js
143
- const res = await fetch('/assets/dummy-data.json');
144
- const layout = await res.json();
145
- document.getElementById('header').layout = layout;
146
- document.getElementById('footer').layout = layout;
147
- ```
148
-
149
- ## See also
150
-
151
- - **[Documentation index](./README.md)**
152
- - **[React SPA](./react.md)**
153
- - **[Next.js App Router](./nextjs.md)**
154
- - **[Angular](./angular.md)** · **[Angular 16 demo](../demo/angular16/README.md)**
155
- - **[Package readme](../readme.md)**
1
+ # Plain HTML / vanilla JS
2
+
3
+ ## What you get
4
+
5
+ | Tag | Purpose |
6
+ | --- | --- |
7
+ | `<weg-header>` | Site header — bundled logo, CMS nav (signed out), built-in nav (signed in), Sign in / Manage Account / Sign out |
8
+ | `<weg-footer>` | Site footer — social links, menu, credits, copyright |
9
+
10
+ Both components are **presentational**: they do **not** fetch data. Pass the same `layout` payload to each.
11
+
12
+ WEG21 API schema: [`weg21-bootstrap.json`](../src/assets/weg21-bootstrap.json), [`weg21-menus.json`](../src/assets/weg21-menus.json)
13
+
14
+ ## Install & register
15
+
16
+ With a bundler that resolves `node_modules` and package **`exports`** (TypeScript: `resolveJsonModule` + `moduleResolution` `bundler` or `node16` — see [angular.md](./angular.md)):
17
+
18
+ ```html
19
+ <weg-header id="header"></weg-header>
20
+ <main><!-- your content --></main>
21
+ <weg-footer id="footer"></weg-footer>
22
+
23
+ <script type="module">
24
+ import { defineCustomElements } from 'weg-shared-layout/loader';
25
+ import { dummyWeg21LayoutData } from 'weg-shared-layout/menus';
26
+ const layout = dummyWeg21LayoutData();
27
+
28
+ defineCustomElements();
29
+
30
+ const header = document.getElementById('header');
31
+ const footer = document.getElementById('footer');
32
+
33
+ header.layout = layout;
34
+ footer.layout = layout;
35
+
36
+ function updateCurrentPath() {
37
+ const { pathname, search } = window.location;
38
+ header.currentPath = search ? `${pathname}${search}` : pathname;
39
+ }
40
+
41
+ updateCurrentPath();
42
+ window.addEventListener('popstate', updateCurrentPath);
43
+ </script>
44
+ ```
45
+
46
+ Side-effect imports (no loader) if you only need specific tags:
47
+
48
+ ```js
49
+ import 'weg-shared-layout/weg-header';
50
+ import 'weg-shared-layout/weg-footer';
51
+ ```
52
+
53
+ ## `layout` property vs attribute
54
+
55
+ Assign the **`layout` JavaScript property** (recommended):
56
+
57
+ ```js
58
+ element.layout = layoutObject;
59
+ ```
60
+
61
+ Or pass a JSON **string** on the `layout` attribute:
62
+
63
+ ```html
64
+ <weg-header layout='{"header":{"menu":[]}}'></weg-header>
65
+ ```
66
+
67
+ ## Header layout fields (signed out)
68
+
69
+ | Field | Purpose |
70
+ | --- | --- |
71
+ | `header.logoSrc` | Logo image URL (bundled if omitted) |
72
+ | `header.logoHref` | Logo link URL (WEG homepage if omitted) |
73
+ | `header.menu` | Unified nav — groups with `items[]`, flat links with `href` (incl. Sign in) |
74
+
75
+ See [`weg21-menus.json`](../src/assets/weg21-menus.json) for absolute URL examples in menu links.
76
+
77
+ ## Header auth (Sign in / Sign out)
78
+
79
+ ### Signed out
80
+
81
+ Renders `header.menu` from `layout`. Add sign-in as a normal link — `{ "label": "Sign in", "href": "…" }` — like Register. The header recognizes it by label or login URL and follows `href` on click.
82
+
83
+ ### Signed in
84
+
85
+ Set **`signedIn`** and optionally **`userName`**. CMS nav is ignored; built-in links are shown (Find a job, Dashboard, Manage Account, Sign out). Set **`accountBaseUrl`** when account links should use a non-production portal.
86
+
87
+ ```js
88
+ header.signedIn = true;
89
+ header.userName = 'Alex';
90
+ // header.accountBaseUrl = 'https://account-staging.example.com';
91
+ // or
92
+ header.setAttribute('signed-in', '');
93
+ header.setAttribute('user-name', 'Alex');
94
+ ```
95
+
96
+ Listen for **`wegAuthClick`** to handle sign-out (call your logout API, then redirect):
97
+
98
+ ```js
99
+ header.addEventListener('wegAuthClick', async (event) => {
100
+ if (event.detail.action !== 'sign-out') return;
101
+
102
+ event.preventDefault();
103
+ header.signedIn = false;
104
+ await logout();
105
+ window.location.assign('/');
106
+ });
107
+ ```
108
+
109
+ | `event.detail.action` | Default behaviour if not prevented |
110
+ | --- | --- |
111
+ | `'sign-in'` | Browser follows the link's `href` |
112
+ | `'sign-out'` | Emits event only — no navigation (host handles logout) |
113
+
114
+ ## Nav active state
115
+
116
+ Set **`currentPath`** (property) or **`current-path`** (attribute) to the current pathname. Include `?query` when dropdown links use search params.
117
+
118
+ ```js
119
+ function syncCurrentPath() {
120
+ const { pathname, search } = window.location;
121
+ header.currentPath = search ? `${pathname}${search}` : pathname;
122
+ }
123
+
124
+ syncCurrentPath();
125
+ window.addEventListener('popstate', syncCurrentPath);
126
+ ```
127
+
128
+ | Link type | Match rule |
129
+ | --- | --- |
130
+ | Flat nav link | Prefix match on pathname |
131
+ | Dropdown child | Exact pathname (+ query when href has `?`) |
132
+ | Dropdown parent | Active when any child matches |
133
+ | Sign in / Sign out | Never highlighted |
134
+
135
+ Active links use **`weg-purple-200`** (`#CDCFF8`).
136
+
137
+ Logo **image** uses `header.logoSrc` (bundled if omitted). Logo **link** uses `header.logoHref` when provided; otherwise it goes to the WEG homepage.
138
+
139
+ ## Without a bundler
140
+
141
+ Fetch `weg21-bootstrap.json` and `weg21-menus.json`, map with the same logic as [`menusToLayoutData`](../src/utils/menus.ts), then assign properties:
142
+
143
+ ```js
144
+ const [bootstrapRes, menusRes] = await Promise.all([
145
+ fetch('/assets/weg21-bootstrap.json'),
146
+ fetch('/assets/weg21-menus.json'),
147
+ ]);
148
+ const layout = await res.json();
149
+ document.getElementById('header').layout = layout;
150
+ document.getElementById('footer').layout = layout;
151
+ ```
152
+
153
+ ## See also
154
+
155
+ - **[Documentation index](./README.md)**
156
+ - **[React SPA](./react.md)**
157
+ - **[Next.js App Router](./nextjs.md)**
158
+ - **[Angular](./angular.md)** · **[Angular 16 demo](../demo/angular16/README.md)**
159
+ - **[Package readme](../readme.md)**
package/package.json CHANGED
@@ -1,81 +1,93 @@
1
- {
2
- "name": "weg-shared-layout",
3
- "version": "0.0.45",
4
- "description": "Shared layout Web Components built with Stencil",
5
- "main": "dist/index.cjs.js",
6
- "module": "dist/index.js",
7
- "types": "dist/types/components.d.ts",
8
- "collection": "dist/collection/collection-manifest.json",
9
- "collection:main": "dist/collection/index.js",
10
- "unpkg": "dist/weg-shared-layout/weg-shared-layout.esm.js",
11
- "exports": {
12
- ".": {
13
- "types": "./dist/types/components.d.ts",
14
- "import": "./dist/weg-shared-layout/weg-shared-layout.esm.js",
15
- "require": "./dist/weg-shared-layout/weg-shared-layout.cjs.js"
16
- },
17
- "./weg-footer": {
18
- "types": "./dist/components/weg-footer.d.ts",
19
- "import": "./dist/components/weg-footer.js"
20
- },
21
- "./weg-header": {
22
- "types": "./dist/components/weg-header.d.ts",
23
- "import": "./dist/components/weg-header.js"
24
- },
25
- "./loader": {
26
- "types": "./loader/index.d.ts",
27
- "import": "./loader/index.js",
28
- "require": "./loader/index.cjs.js"
29
- },
30
- "./dummy-data.json": "./src/assets/dummy-data.json",
31
- "./layout-data": {
32
- "types": "./dist/types/types/layout-data.d.ts"
33
- },
34
- "./styles/container.css": "./src/styles/container.css"
35
- },
36
- "repository": {
37
- "type": "git",
38
- "url": "git+https://github.com/jobsac/weg-shared-layout.git"
39
- },
40
- "bugs": {
41
- "url": "https://github.com/jobsac/weg-shared-layout/issues"
42
- },
43
- "homepage": "https://github.com/jobsac/weg-shared-layout#readme",
44
- "files": [
45
- "dist/",
46
- "docs/",
47
- "loader/",
48
- "src/assets/dummy-data.json",
49
- "src/constants/",
50
- "src/styles/container.css"
51
- ],
52
- "scripts": {
53
- "prepack": "pnpm run build",
54
- "build": "stencil build",
55
- "start": "stencil build --dev --watch --serve",
56
- "test": "stencil-test --prod",
57
- "test:watch": "stencil-test --prod --watch",
58
- "generate": "stencil generate",
59
- "demo:angular16:install": "pnpm install --dir demo/angular16",
60
- "demo:angular16:build": "pnpm run build && pnpm run build --dir demo/angular16",
61
- "demo:angular16": "pnpm run build && pnpm run start --dir demo/angular16"
62
- },
63
- "devDependencies": {
64
- "@csstools/postcss-global-data": "~4.0.0",
65
- "@stencil-community/postcss": "~2.2.0",
66
- "@stencil/core": "~4.27.1 || ~5.0.0-0",
67
- "@stencil/vitest": "~1.8.3",
68
- "@types/node": "~22.13.5",
69
- "@vitest/browser-playwright": "~4.0.0",
70
- "axe-core": "~4.11.4",
71
- "playwright": "~1.52.0",
72
- "postcss-custom-media": "~12.0.1",
73
- "vitest": "~4.0.0"
74
- },
75
- "license": "MIT",
76
- "author": "WEG",
77
- "contributors": [
78
- "Tan Ahmed <tan.ahmed@warwick.ac.uk>",
79
- "Rakin Ahmed <rakin.ahmed@warwick.ac.uk>"
80
- ]
81
- }
1
+ {
2
+ "name": "weg-shared-layout",
3
+ "version": "0.0.47",
4
+ "description": "Shared layout Web Components built with Stencil",
5
+ "main": "dist/index.cjs.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/types/components.d.ts",
8
+ "collection": "dist/collection/collection-manifest.json",
9
+ "collection:main": "dist/collection/index.js",
10
+ "unpkg": "dist/weg-shared-layout/weg-shared-layout.esm.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/types/components.d.ts",
14
+ "import": "./dist/weg-shared-layout/weg-shared-layout.esm.js",
15
+ "require": "./dist/weg-shared-layout/weg-shared-layout.cjs.js"
16
+ },
17
+ "./weg-footer": {
18
+ "types": "./dist/components/weg-footer.d.ts",
19
+ "import": "./dist/components/weg-footer.js"
20
+ },
21
+ "./weg-header": {
22
+ "types": "./dist/components/weg-header.d.ts",
23
+ "import": "./dist/components/weg-header.js"
24
+ },
25
+ "./loader": {
26
+ "types": "./loader/index.d.ts",
27
+ "import": "./loader/index.js",
28
+ "require": "./loader/index.cjs.js"
29
+ },
30
+ "./weg21-bootstrap.json": "./src/assets/weg21-bootstrap.json",
31
+ "./weg21-menus.json": "./src/assets/weg21-menus.json",
32
+ "./layout-data": {
33
+ "types": "./dist/types/types/layout-data.d.ts"
34
+ },
35
+ "./menus-data": {
36
+ "types": "./dist/types/types/menus-data.d.ts"
37
+ },
38
+ "./menus": {
39
+ "types": "./src/utils/menus.ts",
40
+ "import": "./src/utils/menus.ts",
41
+ "default": "./src/utils/menus.ts"
42
+ },
43
+ "./styles/container.css": "./src/styles/container.css"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/jobsac/weg-shared-layout.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/jobsac/weg-shared-layout/issues"
51
+ },
52
+ "homepage": "https://github.com/jobsac/weg-shared-layout#readme",
53
+ "files": [
54
+ "dist/",
55
+ "docs/",
56
+ "loader/",
57
+ "src/assets/weg21-bootstrap.json",
58
+ "src/assets/weg21-menus.json",
59
+ "src/utils/menus.ts",
60
+ "src/types/menus-data.ts",
61
+ "src/constants/",
62
+ "src/styles/container.css"
63
+ ],
64
+ "scripts": {
65
+ "prepack": "pnpm run build",
66
+ "build": "stencil build",
67
+ "start": "stencil build --dev --watch --serve",
68
+ "test": "stencil-test --prod",
69
+ "test:watch": "stencil-test --prod --watch",
70
+ "generate": "stencil generate",
71
+ "demo:angular16:install": "pnpm install --dir demo/angular16",
72
+ "demo:angular16:build": "pnpm run build && pnpm run build --dir demo/angular16",
73
+ "demo:angular16": "pnpm run build && pnpm run start --dir demo/angular16"
74
+ },
75
+ "devDependencies": {
76
+ "@csstools/postcss-global-data": "~4.0.0",
77
+ "@stencil-community/postcss": "~2.2.0",
78
+ "@stencil/core": "~4.27.1 || ~5.0.0-0",
79
+ "@stencil/vitest": "~1.8.3",
80
+ "@types/node": "~22.13.5",
81
+ "@vitest/browser-playwright": "~4.0.0",
82
+ "axe-core": "~4.11.4",
83
+ "playwright": "~1.52.0",
84
+ "postcss-custom-media": "~12.0.1",
85
+ "vitest": "~4.0.0"
86
+ },
87
+ "license": "MIT",
88
+ "author": "WEG",
89
+ "contributors": [
90
+ "Tan Ahmed <tan.ahmed@warwick.ac.uk>",
91
+ "Rakin Ahmed <rakin.ahmed@warwick.ac.uk>"
92
+ ]
93
+ }