@eeacms/volto-eea-design-system 1.60.8 → 1.61.1
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/.gitleaks.toml +101 -0
- package/CHANGELOG.md +24 -1
- package/README.md +59 -0
- package/RELEASE.md +1 -1
- package/package.json +1 -1
- package/src/ui/Header/Header.jsx +7 -1
- package/src/ui/Header/Header.test.jsx +55 -0
- package/src/ui/Header/HeaderSearchPopUp.js +7 -1
- package/src/ui/Header/HeaderSearchPopUp.test.js +49 -0
- package/src/ui/Header/useAISummaryToggle.js +63 -0
package/.gitleaks.toml
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
title = "Betterleaks config"
|
|
2
|
+
|
|
3
|
+
[extend]
|
|
4
|
+
useDefault = true
|
|
5
|
+
|
|
6
|
+
[[rules]]
|
|
7
|
+
id = "secret-literal-assignment"
|
|
8
|
+
description = "Secret-like literal assignment in source, YAML, env and config files"
|
|
9
|
+
regex = '''(?i)([A-Za-z0-9_.-]*(?:password|passwd|pwd|api[_-]?key|apikey|access[_-]?key|secret[_-]?access[_-]?key|private[_-]?key|client[_-]?secret|consumer[_-]?key|consumer[_-]?secret|(?:auth|access|refresh|session|api|bearer|id|jwt|csrf|xsrf|oauth)[_-]?token|translate[_-]?auth|translation[_-]?auth|auth[_-]?password|auth[_-]?key|auth[_-]?credentials|database[_-]?url|connection[_-]?string)[A-Za-z0-9_.-]*)[ \t]*[:=][ \t]*["'']?([^"''[:space:]#{}$.][^"''\n#{}]{2,})["'']?'''
|
|
10
|
+
secretGroup = 2
|
|
11
|
+
keywords = [
|
|
12
|
+
"password",
|
|
13
|
+
"passwd",
|
|
14
|
+
"pwd",
|
|
15
|
+
"api_key",
|
|
16
|
+
"apikey",
|
|
17
|
+
"access_key",
|
|
18
|
+
"private_key",
|
|
19
|
+
"client_secret",
|
|
20
|
+
"consumer_key",
|
|
21
|
+
"consumer_secret",
|
|
22
|
+
"auth_token",
|
|
23
|
+
"access_token",
|
|
24
|
+
"refresh_token",
|
|
25
|
+
"session_token",
|
|
26
|
+
"api_token",
|
|
27
|
+
"bearer_token",
|
|
28
|
+
"id_token",
|
|
29
|
+
"jwt_token",
|
|
30
|
+
"csrf_token",
|
|
31
|
+
"xsrf_token",
|
|
32
|
+
"oauth_token",
|
|
33
|
+
"translate_auth",
|
|
34
|
+
"translation_auth",
|
|
35
|
+
"auth_password",
|
|
36
|
+
"auth_key",
|
|
37
|
+
"auth_credentials",
|
|
38
|
+
"database_url",
|
|
39
|
+
"connection_string"
|
|
40
|
+
]
|
|
41
|
+
tags = ["literal-secret"]
|
|
42
|
+
|
|
43
|
+
[[rules]]
|
|
44
|
+
id = "env-short-secret-assignment"
|
|
45
|
+
description = "Uppercase env-style PASS/TOKEN/SECRET assignment"
|
|
46
|
+
regex = '''\b((?:PASS|TOKEN|SECRET|[A-Z0-9_]*(?:_PASS|_TOKEN|_SECRET|PASS_|TOKEN_|SECRET_)[A-Z0-9_]*))[ \t]*[:=][ \t]*["'']?([^"''[:space:]#{}$.][^"''\n#{}]{2,})["'']?'''
|
|
47
|
+
secretGroup = 2
|
|
48
|
+
keywords = [
|
|
49
|
+
"PASS",
|
|
50
|
+
"TOKEN",
|
|
51
|
+
"SECRET"
|
|
52
|
+
]
|
|
53
|
+
tags = ["env", "literal-secret"]
|
|
54
|
+
|
|
55
|
+
[[rules]]
|
|
56
|
+
id = "standalone-sk-token"
|
|
57
|
+
description = "Standalone sk-* token not attached to a secret-like variable name"
|
|
58
|
+
regex = '''(?i)\b(sk-[A-Za-z0-9][A-Za-z0-9_-]{20,})\b'''
|
|
59
|
+
secretGroup = 1
|
|
60
|
+
entropy = 2.5
|
|
61
|
+
keywords = ["sk-"]
|
|
62
|
+
tags = ["standalone-token", "generic"]
|
|
63
|
+
|
|
64
|
+
[[rules]]
|
|
65
|
+
id = "dotenv-only-jest-setup"
|
|
66
|
+
description = ".env may only contain the committed Jest setup lines"
|
|
67
|
+
path = '''(?i)(^|/)\.env$'''
|
|
68
|
+
regex = '''(?m)^(.+)$'''
|
|
69
|
+
secretGroup = 1
|
|
70
|
+
tags = ["file", "dotenv"]
|
|
71
|
+
[[rules.allowlists]]
|
|
72
|
+
regexTarget = "match"
|
|
73
|
+
regexes = [
|
|
74
|
+
'''^JEST_USE_SETUP=OFF # Jest configuration variables: ON, OFF\r?$''',
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
[[rules]]
|
|
78
|
+
id = "forbidden-secret-file"
|
|
79
|
+
description = "Forbidden secret-bearing file committed to repository"
|
|
80
|
+
path = '''(?i)(^|/)(\.env\..*|\.npmrc|\.pypirc|id_rsa|id_ed25519|.*\.(pem|key|p12|pfx|jks|kubeconfig))$'''
|
|
81
|
+
regex = '''(?s).{1,}'''
|
|
82
|
+
tags = ["file", "secret-file"]
|
|
83
|
+
|
|
84
|
+
[[allowlists]]
|
|
85
|
+
description = "Allow Jenkins SonarQube token environment variable reference"
|
|
86
|
+
regexTarget = "match"
|
|
87
|
+
regexes = [
|
|
88
|
+
'''SONAR_AUTH_TOKEN''',
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
[[allowlists]]
|
|
92
|
+
description = "Allow generated documentation assets"
|
|
93
|
+
paths = [
|
|
94
|
+
'''^docs/assets/''',
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
[[allowlists]]
|
|
98
|
+
description = "Semantic UI flag stylesheet uses ISO country-code selectors like `.pw:before` (Palau), not credentials"
|
|
99
|
+
paths = [
|
|
100
|
+
'''(^|/)theme/themes/eea/elements/flag\.overrides$''',
|
|
101
|
+
]
|
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,30 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
-
### [1.
|
|
7
|
+
### [1.61.1](https://github.com/eea/volto-eea-design-system/compare/1.61.0...1.61.1) - 7 September 2026
|
|
8
|
+
|
|
9
|
+
#### :bug: Bug Fixes
|
|
10
|
+
|
|
11
|
+
- fix: make the AI summary toggle hook SSR-safe - refs #307513 [Miu Razvan - [`bc0afda`](https://github.com/eea/volto-eea-design-system/commit/bc0afdae8d934989dda8bde07714be4a545a3aac)]
|
|
12
|
+
|
|
13
|
+
#### :hammer_and_wrench: Others
|
|
14
|
+
|
|
15
|
+
- listing documentation [Dobricean Ioan Dorian - [`5785e17`](https://github.com/eea/volto-eea-design-system/commit/5785e175a1ee3fca2291607bf08736719cfe20f6)]
|
|
16
|
+
### [1.61.0](https://github.com/eea/volto-eea-design-system/compare/1.60.8...1.61.0) - 7 September 2026
|
|
17
|
+
|
|
18
|
+
#### :bug: Bug Fixes
|
|
19
|
+
|
|
20
|
+
- fix: Add betterleaks github action - refs #304517 [dobri1408 - [`dd4b4da`](https://github.com/eea/volto-eea-design-system/commit/dd4b4da5ef18454ac76c1cbff1e2a7d5baa5c550)]
|
|
21
|
+
|
|
22
|
+
#### :house: Internal changes
|
|
23
|
+
|
|
24
|
+
- chore(gitleaks): allowlist flag.overrides stylesheet [Claudia Ifrim - [`d3ac637`](https://github.com/eea/volto-eea-design-system/commit/d3ac637ed1396c04e600971abf50b26ae3bcdaa3)]
|
|
25
|
+
- chore: [JENKINSFILE] sanitize sonarqube command Refs #305084 [valentinab25 - [`c933e31`](https://github.com/eea/volto-eea-design-system/commit/c933e31abf8b564a4d11f860e8df93ad86edff51)]
|
|
26
|
+
|
|
27
|
+
#### :hammer_and_wrench: Others
|
|
28
|
+
|
|
29
|
+
- test: pin Chromium version 149 to work with Cypress [valentinab25 - [`0be5062`](https://github.com/eea/volto-eea-design-system/commit/0be5062d18dcff0350c7e37a2b42ae82be66cd63)]
|
|
30
|
+
### [1.60.8](https://github.com/eea/volto-eea-design-system/compare/1.60.7...1.60.8) - 11 June 2026
|
|
8
31
|
|
|
9
32
|
#### :bug: Bug Fixes
|
|
10
33
|
|
package/README.md
CHANGED
|
@@ -119,6 +119,65 @@ See [RELEASE.md](https://github.com/eea/volto-eea-design-system/blob/master/RELE
|
|
|
119
119
|
|
|
120
120
|
See [DEVELOP.md](https://github.com/eea/volto-eea-design-system/blob/master/DEVELOP.md).
|
|
121
121
|
|
|
122
|
+
## Secret Scanning
|
|
123
|
+
|
|
124
|
+
This repository uses the Betterleaks GitHub Action to scan the current
|
|
125
|
+
repository content on every push and pull request. The scan uses the rules in
|
|
126
|
+
`.gitleaks.toml` and uploads a `betterleaks-report` artifact when a finding is
|
|
127
|
+
detected.
|
|
128
|
+
|
|
129
|
+
If the optional SMTP secrets are configured, failed scans also send an email to
|
|
130
|
+
the last commit committer. The workflow expects these repository or
|
|
131
|
+
organization secrets:
|
|
132
|
+
|
|
133
|
+
- `SMTP_URL`
|
|
134
|
+
- `SMTP_PORT` (optional, defaults to `25`)
|
|
135
|
+
- `SMTP_EMAIL`
|
|
136
|
+
- `SMTP_PASSWORD` (optional if the SMTP server does not require authentication)
|
|
137
|
+
|
|
138
|
+
Port `465` is sent with direct TLS; other ports use the default SMTP handshake.
|
|
139
|
+
The email includes a short finding summary from the redacted Betterleaks report,
|
|
140
|
+
including the redacted matched line from each finding.
|
|
141
|
+
|
|
142
|
+
There are three common outcomes:
|
|
143
|
+
|
|
144
|
+
1. **Everything is OK.** The `Betterleaks / Scan for secrets` check is green and
|
|
145
|
+
no action is needed. Regular references to runtime values are OK, for example:
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
const tokenFromCookie = req.universalCookies.get('auth_token');
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
2. **A real secret was found.** The check is red and the workflow log asks you to
|
|
152
|
+
download the `betterleaks-report` artifact. Open the artifact from the GitHub
|
|
153
|
+
Actions run and check the reported file, line and rule. Remove the committed
|
|
154
|
+
value, move it to the proper secret store, and rotate it if it was exposed.
|
|
155
|
+
A report entry looks like this:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"RuleID": "secret-literal-assignment",
|
|
160
|
+
"File": "src/config.js",
|
|
161
|
+
"StartLine": 12,
|
|
162
|
+
"Secret": "[REDACTED]"
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
3. **The finding is a false positive.** Keep the value only if it is clearly not
|
|
167
|
+
sensitive, such as a test fixture, placeholder, or public example. Add
|
|
168
|
+
`betterleaks:allow` on the same line and include a short explanation in the
|
|
169
|
+
pull request.
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
const testPassword = 'admin'; //betterleaks:allow
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```yaml
|
|
176
|
+
password: "admin" #betterleaks:allow
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Do not add `betterleaks:allow` to real credentials.
|
|
180
|
+
|
|
122
181
|
## Copyright and license
|
|
123
182
|
|
|
124
183
|
The Initial Owner of the Original Code is European Environment Agency (EEA).
|
package/RELEASE.md
CHANGED
|
@@ -33,7 +33,7 @@ Release-it is a tool that automates 4 important steps in the release process:
|
|
|
33
33
|
To configure the authentification, you need to export GITHUB_TOKEN for [GitHub](https://github.com/settings/tokens)
|
|
34
34
|
|
|
35
35
|
```
|
|
36
|
-
export GITHUB_TOKEN=
|
|
36
|
+
export GITHUB_TOKEN="${GITHUB_TOKEN}"
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
To configure npm, you can use the `npm login` command or use a configuration file with a TOKEN :
|
package/package.json
CHANGED
package/src/ui/Header/Header.jsx
CHANGED
|
@@ -16,6 +16,7 @@ import burgerIcon from '@eeacms/volto-eea-design-system/../theme/themes/eea/asse
|
|
|
16
16
|
|
|
17
17
|
import HeaderSearchPopUp from './HeaderSearchPopUp';
|
|
18
18
|
import HeaderMenuPopUp from './HeaderMenuPopUp';
|
|
19
|
+
import { useAISummaryToggle } from './useAISummaryToggle';
|
|
19
20
|
import { findBestMatchingMenuItem, isMenuItemActive } from './utils';
|
|
20
21
|
import PropTypes from 'prop-types';
|
|
21
22
|
import omit from 'lodash/omit';
|
|
@@ -166,7 +167,12 @@ const Main = ({
|
|
|
166
167
|
state.reduxAsyncConnect?.headerSettings?.useAISearchIcon || false,
|
|
167
168
|
);
|
|
168
169
|
|
|
169
|
-
const
|
|
170
|
+
const [aiSummaryEnabled] = useAISummaryToggle();
|
|
171
|
+
|
|
172
|
+
// The AI sparkle only shows when the AI search icon is configured and
|
|
173
|
+
// the user has not opted out of AI summaries.
|
|
174
|
+
const searchIcon =
|
|
175
|
+
useAISearchIcon && aiSummaryEnabled ? aiSearchIcon : searchSVG;
|
|
170
176
|
|
|
171
177
|
const itemsLayouts =
|
|
172
178
|
menuItemsLayouts || config.settings?.menuItemsLayouts || {};
|
|
@@ -770,3 +770,58 @@ test('menu click outside behavior with different active states', async () => {
|
|
|
770
770
|
expect(burgerButton).toHaveAttribute('aria-expanded', 'false');
|
|
771
771
|
expect(searchButton).toHaveAttribute('aria-expanded', 'false');
|
|
772
772
|
});
|
|
773
|
+
|
|
774
|
+
describe('header search icon and AI summary state', () => {
|
|
775
|
+
const renderMain = () =>
|
|
776
|
+
renderWithProvider(
|
|
777
|
+
<Router history={createMemoryHistory()}>
|
|
778
|
+
<Header>
|
|
779
|
+
<Header.Main
|
|
780
|
+
pathname="/test"
|
|
781
|
+
menuItems={[
|
|
782
|
+
{ '@id': '/test', url: '/test', title: 'Test', items: [] },
|
|
783
|
+
]}
|
|
784
|
+
renderGlobalMenuItem={(item) => (
|
|
785
|
+
<a href={item.url} title={item.title}>
|
|
786
|
+
{item.title}
|
|
787
|
+
</a>
|
|
788
|
+
)}
|
|
789
|
+
/>
|
|
790
|
+
</Header>
|
|
791
|
+
</Router>,
|
|
792
|
+
);
|
|
793
|
+
|
|
794
|
+
beforeEach(() => {
|
|
795
|
+
window.localStorage.clear();
|
|
796
|
+
mockState.reduxAsyncConnect.headerSettings.useAISearchIcon = false;
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
it('shows the plain magnifier when useAISearchIcon is false', () => {
|
|
800
|
+
const { container } = renderMain();
|
|
801
|
+
expect(container.querySelector('img[alt="Global search"]')).toHaveAttribute(
|
|
802
|
+
'src',
|
|
803
|
+
'search-line.svg',
|
|
804
|
+
);
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
it('shows the AI sparkle when useAISearchIcon is true and AI summaries are enabled', () => {
|
|
808
|
+
mockState.reduxAsyncConnect.headerSettings.useAISearchIcon = true;
|
|
809
|
+
|
|
810
|
+
const { container } = renderMain();
|
|
811
|
+
expect(container.querySelector('img[alt="Global search"]')).toHaveAttribute(
|
|
812
|
+
'src',
|
|
813
|
+
'ai-search.svg',
|
|
814
|
+
);
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
it('shows the plain magnifier when useAISearchIcon is true but AI summaries are disabled', () => {
|
|
818
|
+
mockState.reduxAsyncConnect.headerSettings.useAISearchIcon = true;
|
|
819
|
+
window.localStorage.setItem('eea-ai-summary-enabled', '0');
|
|
820
|
+
|
|
821
|
+
const { container } = renderMain();
|
|
822
|
+
expect(container.querySelector('img[alt="Global search"]')).toHaveAttribute(
|
|
823
|
+
'src',
|
|
824
|
+
'search-line.svg',
|
|
825
|
+
);
|
|
826
|
+
});
|
|
827
|
+
});
|
|
@@ -9,6 +9,7 @@ import { handleEnterKeyPress } from '@eeacms/volto-eea-design-system/helpers';
|
|
|
9
9
|
|
|
10
10
|
import searchSVG from '@eeacms/volto-eea-design-system/../theme/themes/eea/assets/images/Header/search-line.svg';
|
|
11
11
|
import aiSearchIcon from '@eeacms/volto-eea-design-system/../theme/themes/eea/assets/images/Header/ai-search.svg';
|
|
12
|
+
import { useAISummaryToggle } from './useAISummaryToggle';
|
|
12
13
|
|
|
13
14
|
const getRandomItems = (arr, max) => {
|
|
14
15
|
return (
|
|
@@ -96,7 +97,12 @@ function HeaderSearchPopUp({
|
|
|
96
97
|
state.reduxAsyncConnect?.headerSettings?.useAISearchIcon || false,
|
|
97
98
|
);
|
|
98
99
|
|
|
99
|
-
const
|
|
100
|
+
const [aiSummaryEnabled] = useAISummaryToggle();
|
|
101
|
+
|
|
102
|
+
// The AI sparkle only shows when the AI search icon is configured and
|
|
103
|
+
// the user has not opted out of AI summaries.
|
|
104
|
+
const searchIcon =
|
|
105
|
+
useAISearchIcon && aiSummaryEnabled ? aiSearchIcon : searchSVG;
|
|
100
106
|
|
|
101
107
|
useEffect(() => {
|
|
102
108
|
setVisibileSuggestions(getRandomItems(suggestions, maxToShow));
|
|
@@ -248,4 +248,53 @@ describe('HeaderSearchPopUp', () => {
|
|
|
248
248
|
expect(screen.getByPlaceholderText('Search')).toBeInTheDocument();
|
|
249
249
|
expect(screen.queryByText('Suggestions Title')).not.toBeInTheDocument();
|
|
250
250
|
});
|
|
251
|
+
|
|
252
|
+
describe('search icon and AI summary state', () => {
|
|
253
|
+
beforeEach(() => {
|
|
254
|
+
window.localStorage.clear();
|
|
255
|
+
mockState.reduxAsyncConnect.headerSettings.useAISearchIcon = false;
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const renderPopup = () =>
|
|
259
|
+
render(
|
|
260
|
+
<Provider store={mockStore}>
|
|
261
|
+
<Router history={history}>
|
|
262
|
+
<HeaderSearchPopUp
|
|
263
|
+
headerSearchBox={sampleHeaderSearchBox}
|
|
264
|
+
onClose={mockOnClose}
|
|
265
|
+
triggerRefs={[]}
|
|
266
|
+
/>
|
|
267
|
+
</Router>
|
|
268
|
+
</Provider>,
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
it('shows the plain magnifier when useAISearchIcon is false', () => {
|
|
272
|
+
const { container } = renderPopup();
|
|
273
|
+
expect(container.querySelector('img')).toHaveAttribute(
|
|
274
|
+
'src',
|
|
275
|
+
'search-line.svg',
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('shows the AI sparkle when useAISearchIcon is true and AI summaries are enabled', () => {
|
|
280
|
+
mockState.reduxAsyncConnect.headerSettings.useAISearchIcon = true;
|
|
281
|
+
|
|
282
|
+
const { container } = renderPopup();
|
|
283
|
+
expect(container.querySelector('img')).toHaveAttribute(
|
|
284
|
+
'src',
|
|
285
|
+
'ai-search.svg',
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('shows the plain magnifier when useAISearchIcon is true but AI summaries are disabled', () => {
|
|
290
|
+
mockState.reduxAsyncConnect.headerSettings.useAISearchIcon = true;
|
|
291
|
+
window.localStorage.setItem('eea-ai-summary-enabled', '0');
|
|
292
|
+
|
|
293
|
+
const { container } = renderPopup();
|
|
294
|
+
expect(container.querySelector('img')).toHaveAttribute(
|
|
295
|
+
'src',
|
|
296
|
+
'search-line.svg',
|
|
297
|
+
);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
251
300
|
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AI Summary opt-in/opt-out state.
|
|
5
|
+
*
|
|
6
|
+
* Shared contract with the AI summary gating in
|
|
7
|
+
* @eeacms/volto-searchlib (lib/aiSummaryToggle):
|
|
8
|
+
* - the header search icons in this addon use the state to decide between
|
|
9
|
+
* the AI sparkle and the plain magnifier
|
|
10
|
+
* - the advanced-search AI Summary box (volto-searchlib) hosts the
|
|
11
|
+
* user-facing opt-in/opt-out controls
|
|
12
|
+
* - localStorage key: `eea-ai-summary-enabled` ("1" on, "0" off, default on)
|
|
13
|
+
* - CustomEvent `eea:ai-summary-toggle` (detail: boolean) for same-tab sync
|
|
14
|
+
* - native `storage` event for cross-tab sync
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const AI_SUMMARY_STORAGE_KEY = 'eea-ai-summary-enabled';
|
|
18
|
+
export const AI_SUMMARY_TOGGLE_EVENT = 'eea:ai-summary-toggle';
|
|
19
|
+
|
|
20
|
+
// The hooks render during SSR, where window/localStorage do not exist;
|
|
21
|
+
// storage access defaults to the enabled state until the client re-reads it.
|
|
22
|
+
const getStorage = () =>
|
|
23
|
+
typeof window === 'undefined' ? null : window.localStorage;
|
|
24
|
+
|
|
25
|
+
export const readAISummaryEnabled = (storage = getStorage()) =>
|
|
26
|
+
storage ? storage.getItem(AI_SUMMARY_STORAGE_KEY) !== '0' : true;
|
|
27
|
+
|
|
28
|
+
export const writeAISummaryEnabled = (enabled, storage = getStorage()) => {
|
|
29
|
+
if (!storage) return;
|
|
30
|
+
storage.setItem(AI_SUMMARY_STORAGE_KEY, enabled ? '1' : '0');
|
|
31
|
+
window.dispatchEvent(
|
|
32
|
+
new CustomEvent(AI_SUMMARY_TOGGLE_EVENT, { detail: enabled }),
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const useAISummaryToggle = () => {
|
|
37
|
+
const [enabled, setEnabled] = useState(readAISummaryEnabled);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const onToggleEvent = (event) => {
|
|
41
|
+
if (typeof event?.detail === 'boolean') setEnabled(event.detail);
|
|
42
|
+
};
|
|
43
|
+
const onStorageEvent = (event) => {
|
|
44
|
+
if (event.key === AI_SUMMARY_STORAGE_KEY) {
|
|
45
|
+
setEnabled(event.newValue !== '0');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
window.addEventListener(AI_SUMMARY_TOGGLE_EVENT, onToggleEvent);
|
|
49
|
+
window.addEventListener('storage', onStorageEvent);
|
|
50
|
+
return () => {
|
|
51
|
+
window.removeEventListener(AI_SUMMARY_TOGGLE_EVENT, onToggleEvent);
|
|
52
|
+
window.removeEventListener('storage', onStorageEvent);
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
|
|
56
|
+
const toggle = useCallback(() => {
|
|
57
|
+
const next = !readAISummaryEnabled();
|
|
58
|
+
writeAISummaryEnabled(next);
|
|
59
|
+
setEnabled(next);
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
return [enabled, toggle];
|
|
63
|
+
};
|