@olenbetong/synergi-react 2.5.7 → 2.6.0
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/es/colorScheme.d.ts +17 -0
- package/es/colorScheme.js +54 -0
- package/es/components/AppMenu/AppMenu.css +480 -92
- package/es/components/AppMenu/AppMenu.d.ts +47 -0
- package/es/components/AppMenu/AppMenu.js +224 -0
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +2 -0
- package/es/components/AppMenu/AppMenuColorScheme.js +18 -0
- package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
- package/es/components/AppMenu/AppMenuToggle.js +14 -0
- package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
- package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
- package/es/components/AppMenu/developerCategories.d.ts +24 -0
- package/es/components/AppMenu/developerCategories.js +116 -0
- package/es/components/AppMenu/index.d.ts +7 -12
- package/es/components/AppMenu/index.js +6 -85
- package/es/components/AppMenu/types.d.ts +33 -0
- package/es/components/AppMenu/types.js +1 -0
- package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
- package/es/components/AppMenu/useRovingTabIndex.js +103 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
- package/es/components/AppShell/index.js +107 -13
- package/es/components/ImageEditor/ImageEditor.css +22 -11
- package/es/components/ImageEditor/ImageEditor.js +12 -12
- package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
- package/es/components/ImageEditor/ResponsiveButton.js +5 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
- package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
- package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
- package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
- package/es/components/ImageEditor/useIsSmall.js +21 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/package.json +7 -3
- package/src/colorScheme.ts +81 -0
- package/src/components/AppMenu/AppMenu.css +480 -92
- package/src/components/AppMenu/AppMenu.tsx +478 -0
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
- package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
- package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
- package/src/components/AppMenu/developerCategories.ts +142 -0
- package/src/components/AppMenu/index.ts +12 -0
- package/src/components/AppMenu/types.ts +35 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +118 -0
- package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
- package/src/components/AppShell/index.tsx +140 -14
- package/src/components/ImageEditor/ImageEditor.css +22 -11
- package/src/components/ImageEditor/ImageEditor.tsx +38 -40
- package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
- package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
- package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
- package/src/components/ImageEditor/useIsSmall.ts +27 -0
- package/src/index.ts +25 -1
- package/src/components/AppMenu/index.tsx +0 -179
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
2
|
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
3
|
import { AppErrorBoundary } from "@olenbetong/appframe-mui";
|
|
4
|
-
import {
|
|
5
|
-
import { type ReactNode, useEffect, useState } from "react";
|
|
4
|
+
import { type ReactNode, useEffect, useMemo, useState } from "react";
|
|
6
5
|
import { createPortal } from "react-dom";
|
|
7
6
|
|
|
8
|
-
import { AppMenu, type AppMenuArticle } from "../AppMenu/
|
|
7
|
+
import { AppMenu, type AppMenuArticle } from "../AppMenu/AppMenu.js";
|
|
8
|
+
import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
|
|
9
|
+
import type { AppMenuUser } from "../AppMenu/AppMenuUserMenu.js";
|
|
10
|
+
import { createDeveloperCategories } from "../AppMenu/developerCategories.js";
|
|
11
|
+
import { useServiceWorkerUpdate } from "../AppMenu/useServiceWorkerUpdate.js";
|
|
12
|
+
|
|
13
|
+
const hostName = globalThis.af?.article?.hostName ?? globalThis.location?.hostname ?? "";
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* `aviw_WebShared_Articles` stores every published version of an article as its
|
|
17
|
+
* own row, and rows for all sites share the view. Without the host name filter
|
|
18
|
+
* and `ArticleVersion IS NULL` (which keeps only the development row, i.e. the
|
|
19
|
+
* canonical article) every app shows up once per published version.
|
|
20
|
+
*/
|
|
21
|
+
const menuArticlesWhereClause = [
|
|
22
|
+
`HostName = '${hostName.replace(/'/g, "''")}'`,
|
|
23
|
+
"ArticleVersion IS NULL",
|
|
24
|
+
"LastPublished IS NOT NULL",
|
|
25
|
+
"Authenticated = 1",
|
|
26
|
+
"ListOnFrontPage = 1",
|
|
27
|
+
"SysApp = 0",
|
|
28
|
+
"HideFromNav = 0",
|
|
29
|
+
"Hidden = 0",
|
|
30
|
+
"ISNULL(ParentArticleId, '') <> 'news'",
|
|
31
|
+
].join(" AND ");
|
|
9
32
|
|
|
10
33
|
// Created once — shared across all AppShell instances on a page.
|
|
11
|
-
const dsMenuArticles = generateApiDataObject<AppMenuArticle>({
|
|
34
|
+
const dsMenuArticles = af.data.generateApiDataObject<AppMenuArticle>({
|
|
12
35
|
resource: "aviw_WebShared_Articles",
|
|
13
36
|
id: "dsMenuArticles",
|
|
14
37
|
allowUpdate: false,
|
|
@@ -23,18 +46,83 @@ const dsMenuArticles = generateApiDataObject<AppMenuArticle>({
|
|
|
23
46
|
],
|
|
24
47
|
parameters: {
|
|
25
48
|
maxRecords: -1,
|
|
26
|
-
whereClause:
|
|
27
|
-
|
|
28
|
-
sortOrder: [{ MenuGroup: SortOrder.Asc }, { Title: SortOrder.Asc }],
|
|
49
|
+
whereClause: menuArticlesWhereClause,
|
|
50
|
+
sortOrder: [{ MenuGroup: af.data.SortOrder.Asc }, { Title: af.data.SortOrder.Asc }],
|
|
29
51
|
},
|
|
30
52
|
});
|
|
31
53
|
|
|
32
|
-
|
|
54
|
+
// The current user's employee record, used for the photo and full name.
|
|
55
|
+
const dsAppMenuUser = af.data.generateApiDataObject<AppMenuUser>({
|
|
56
|
+
resource: "aviw_Personnel_Employees_Lookup",
|
|
57
|
+
id: "dsAppMenuUser",
|
|
58
|
+
allowUpdate: false,
|
|
59
|
+
allowInsert: false,
|
|
60
|
+
allowDelete: false,
|
|
61
|
+
dynamicLoading: false,
|
|
62
|
+
fields: [
|
|
63
|
+
{ name: "PrimKey", type: "string", nullable: false },
|
|
64
|
+
{ name: "PersonID", type: "string", nullable: false },
|
|
65
|
+
{ name: "FirstName", type: "string", nullable: true },
|
|
66
|
+
{ name: "LastName", type: "string", nullable: true },
|
|
67
|
+
{ name: "Fullname", type: "string", nullable: true },
|
|
68
|
+
{ name: "ImageHash", type: "number", nullable: true },
|
|
69
|
+
],
|
|
70
|
+
parameters: {
|
|
71
|
+
maxRecords: 1,
|
|
72
|
+
// Resolved server side so it doesn't depend on the session being hydrated.
|
|
73
|
+
whereClause: "PersonID = SUSER_SNAME()",
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
function getColorScheme(): "light" | "dark" {
|
|
78
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
79
|
+
|
|
80
|
+
if (scheme === "auto") {
|
|
81
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return scheme === "dark" ? "dark" : "light";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
89
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
90
|
+
* OS preference (used when the scheme is `auto`).
|
|
91
|
+
*/
|
|
92
|
+
function useColorScheme() {
|
|
93
|
+
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
function update() {
|
|
97
|
+
setScheme(getColorScheme());
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
update();
|
|
101
|
+
|
|
102
|
+
let observer = new MutationObserver(update);
|
|
103
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
104
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
105
|
+
|
|
106
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
107
|
+
media?.addEventListener("change", update);
|
|
108
|
+
|
|
109
|
+
return () => {
|
|
110
|
+
observer.disconnect();
|
|
111
|
+
media?.removeEventListener("change", update);
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
|
|
115
|
+
return scheme;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function buildMuiTheme(mode: "light" | "dark") {
|
|
33
119
|
const s = getComputedStyle(document.body);
|
|
34
120
|
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
121
|
+
const isDark = mode === "dark";
|
|
35
122
|
|
|
36
123
|
return muiCreateTheme({
|
|
37
124
|
palette: {
|
|
125
|
+
mode,
|
|
38
126
|
primary: {
|
|
39
127
|
main: get("--ds-color-brand-base-default") || "#116069",
|
|
40
128
|
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
@@ -43,6 +131,15 @@ function buildMuiTheme() {
|
|
|
43
131
|
secondary: {
|
|
44
132
|
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
45
133
|
},
|
|
134
|
+
background: {
|
|
135
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
136
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
137
|
+
},
|
|
138
|
+
text: {
|
|
139
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
140
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
141
|
+
},
|
|
142
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
46
143
|
},
|
|
47
144
|
typography: {
|
|
48
145
|
fontFamily: [
|
|
@@ -96,7 +193,7 @@ function buildMuiTheme() {
|
|
|
96
193
|
},
|
|
97
194
|
MuiFormLabel: {
|
|
98
195
|
styleOverrides: {
|
|
99
|
-
root: { color: "rgba(0, 0, 0, 0.72)" },
|
|
196
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
100
197
|
},
|
|
101
198
|
},
|
|
102
199
|
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
@@ -111,12 +208,22 @@ export type AppShellProps = {
|
|
|
111
208
|
};
|
|
112
209
|
|
|
113
210
|
export function AppShell({ children }: AppShellProps) {
|
|
114
|
-
const
|
|
211
|
+
const colorScheme = useColorScheme();
|
|
212
|
+
const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
|
|
213
|
+
const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
|
|
214
|
+
|
|
215
|
+
// The developer tools are only reachable for developers, so hide them for
|
|
216
|
+
// everyone else instead of showing links that all return 403.
|
|
217
|
+
const categories = useMemo(() => (globalThis.af?.userSession?.isDeveloper ? createDeveloperCategories() : []), []);
|
|
115
218
|
|
|
116
|
-
//
|
|
219
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
220
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
221
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
222
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
223
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
117
224
|
useEffect(() => {
|
|
118
|
-
setTheme(buildMuiTheme());
|
|
119
|
-
}, []);
|
|
225
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
226
|
+
}, [colorScheme]);
|
|
120
227
|
|
|
121
228
|
const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
|
|
122
229
|
|
|
@@ -124,7 +231,26 @@ export function AppShell({ children }: AppShellProps) {
|
|
|
124
231
|
<StyledEngineProvider injectFirst>
|
|
125
232
|
<ThemeProvider theme={theme}>
|
|
126
233
|
<AppErrorBoundary>
|
|
127
|
-
{appMenuSlot &&
|
|
234
|
+
{appMenuSlot &&
|
|
235
|
+
createPortal(
|
|
236
|
+
<AppMenuToggle
|
|
237
|
+
open={isAppMenuOpen}
|
|
238
|
+
hasUpdate={isUpdateAvailable}
|
|
239
|
+
aria-controls="ob-app-menu"
|
|
240
|
+
onClick={() => setIsAppMenuOpen((open) => !open)}
|
|
241
|
+
/>,
|
|
242
|
+
appMenuSlot,
|
|
243
|
+
)}
|
|
244
|
+
<AppMenu
|
|
245
|
+
id="ob-app-menu"
|
|
246
|
+
dataObject={dsMenuArticles}
|
|
247
|
+
userDataObject={dsAppMenuUser}
|
|
248
|
+
categories={categories}
|
|
249
|
+
hasUpdate={isUpdateAvailable}
|
|
250
|
+
onInstallUpdate={installUpdate}
|
|
251
|
+
open={isAppMenuOpen}
|
|
252
|
+
onClose={() => setIsAppMenuOpen(false)}
|
|
253
|
+
/>
|
|
128
254
|
{children}
|
|
129
255
|
</AppErrorBoundary>
|
|
130
256
|
</ThemeProvider>
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
height: 100%;
|
|
3
3
|
display: flex;
|
|
4
4
|
flex-direction: column;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/* The root carries data-color-scheme="dark": the editor chrome is always dark
|
|
6
|
+
so the image stays the focus, and Designsystemet components inside pick up
|
|
7
|
+
matching dark tokens. */
|
|
8
|
+
background: var(--ds-color-neutral-background-default, #111);
|
|
9
|
+
color: var(--ds-color-neutral-text-default, white);
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
.image-editor__topbar {
|
|
@@ -12,8 +15,8 @@
|
|
|
12
15
|
justify-content: space-between;
|
|
13
16
|
gap: 1rem;
|
|
14
17
|
padding: 0.5rem 1rem;
|
|
15
|
-
background: rgba(0, 0, 0, 0.4);
|
|
16
|
-
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
|
|
18
|
+
background: var(--ds-color-neutral-background-tinted, rgba(0, 0, 0, 0.4));
|
|
19
|
+
border-bottom: 1px solid var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.08));
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
.image-editor__canvas {
|
|
@@ -32,11 +35,19 @@
|
|
|
32
35
|
align-items: center;
|
|
33
36
|
justify-content: center;
|
|
34
37
|
background: rgba(0, 0, 0, 0.4);
|
|
35
|
-
color: white;
|
|
38
|
+
color: var(--ds-color-neutral-text-default, white);
|
|
36
39
|
z-index: 10;
|
|
37
40
|
border-radius: 4px;
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
.image-editor__done {
|
|
44
|
+
position: absolute;
|
|
45
|
+
bottom: 1rem;
|
|
46
|
+
right: 1rem;
|
|
47
|
+
z-index: 5;
|
|
48
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
.image-editor__img {
|
|
41
52
|
max-width: 100%;
|
|
42
53
|
max-height: calc(100dvh - 160px); /* fallback when not inside zoom-canvas */
|
|
@@ -52,8 +63,8 @@
|
|
|
52
63
|
align-items: center;
|
|
53
64
|
justify-content: space-between;
|
|
54
65
|
padding: 0.75rem 1rem;
|
|
55
|
-
background: #1a1a1a;
|
|
56
|
-
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
|
66
|
+
background: var(--ds-color-neutral-background-tinted, #1a1a1a);
|
|
67
|
+
border-top: 1px solid var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.08));
|
|
57
68
|
}
|
|
58
69
|
|
|
59
70
|
.image-editor__toolbar-group {
|
|
@@ -66,13 +77,13 @@
|
|
|
66
77
|
.image-editor__topbar-divider {
|
|
67
78
|
width: 1px;
|
|
68
79
|
height: 1.5rem;
|
|
69
|
-
background: rgba(255, 255, 255, 0.15);
|
|
80
|
+
background: var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.15));
|
|
70
81
|
flex-shrink: 0;
|
|
71
82
|
}
|
|
72
83
|
|
|
73
84
|
.image-editor__zoom-level {
|
|
74
85
|
font-size: 0.8125rem;
|
|
75
|
-
color: rgba(255, 255, 255, 0.6);
|
|
86
|
+
color: var(--ds-color-neutral-text-subtle, rgba(255, 255, 255, 0.6));
|
|
76
87
|
min-width: 3.25ch;
|
|
77
88
|
text-align: center;
|
|
78
89
|
font-variant-numeric: tabular-nums;
|
|
@@ -146,7 +157,7 @@
|
|
|
146
157
|
so they're never clipped at the edges. */
|
|
147
158
|
padding: 16px;
|
|
148
159
|
box-sizing: border-box;
|
|
149
|
-
background: #111;
|
|
160
|
+
background: var(--ds-color-neutral-background-default, #111);
|
|
150
161
|
touch-action: none;
|
|
151
162
|
}
|
|
152
163
|
|
|
@@ -207,7 +218,7 @@
|
|
|
207
218
|
justify-content: center;
|
|
208
219
|
gap: 0.75rem;
|
|
209
220
|
padding: 0.75rem 1rem;
|
|
210
|
-
color: rgba(255, 255, 255, 0.7);
|
|
221
|
+
color: var(--ds-color-neutral-text-subtle, rgba(255, 255, 255, 0.7));
|
|
211
222
|
position: absolute;
|
|
212
223
|
inset: auto 0 0 0;
|
|
213
224
|
background: linear-gradient(0deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import RedoIcon from "@mui/icons-material/Redo";
|
|
4
|
-
import RestartAltIcon from "@mui/icons-material/RestartAlt";
|
|
5
|
-
import UndoIcon from "@mui/icons-material/Undo";
|
|
6
|
-
import { Button, CircularProgress, Fab, IconButton, Tooltip, useMediaQuery } from "@mui/material";
|
|
1
|
+
import { Button, Spinner, Tooltip } from "@digdir/designsystemet-react";
|
|
2
|
+
import { ArrowCirclepathIcon, ArrowLeftIcon, ArrowRedoIcon, ArrowUndoIcon, CheckmarkIcon } from "@navikt/aksel-icons";
|
|
7
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
8
4
|
import { forwardRef, useImperativeHandle, useMemo, useState } from "react";
|
|
9
5
|
|
|
@@ -12,6 +8,7 @@ import { ResponsiveButton } from "./ResponsiveButton.js";
|
|
|
12
8
|
import type { ActionPlugin, ActionRegistry, EditAction, Plugin, ToolPlugin, ViewPlugin } from "./types.js";
|
|
13
9
|
import { useActiveTool } from "./useActiveTool.js";
|
|
14
10
|
import { useImageHistory } from "./useImageHistory.js";
|
|
11
|
+
import { useIsSmall } from "./useIsSmall.js";
|
|
15
12
|
|
|
16
13
|
export type ImageEditorRef = {
|
|
17
14
|
/** Returns the current edited blob, or null if no edits have been applied since the last source image. */
|
|
@@ -44,7 +41,7 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
44
41
|
let { activePlugin, activateTool, deactivateTool } = useActiveTool(plugins);
|
|
45
42
|
let [busy, setBusy] = useState(false);
|
|
46
43
|
let disabled = busy || history.replaying;
|
|
47
|
-
let isSmall =
|
|
44
|
+
let isSmall = useIsSmall();
|
|
48
45
|
|
|
49
46
|
useImperativeHandle(ref, () => ({
|
|
50
47
|
getCurrentBlob: () => history.currentBlob,
|
|
@@ -81,14 +78,14 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
81
78
|
let TopBarControls = viewPlugin?.TopBarControls;
|
|
82
79
|
|
|
83
80
|
let inner = (
|
|
84
|
-
<div className="image-editor">
|
|
81
|
+
<div className="image-editor" data-color-scheme="dark">
|
|
85
82
|
{/* Top toolbar — always visible; undo/redo/reset disabled while a tool is active */}
|
|
86
83
|
<div className="image-editor__topbar">
|
|
87
84
|
<div className="image-editor__toolbar-group">
|
|
88
85
|
{onCancel && (
|
|
89
86
|
<>
|
|
90
87
|
<ResponsiveButton
|
|
91
|
-
icon={<
|
|
88
|
+
icon={<ArrowLeftIcon aria-hidden />}
|
|
92
89
|
label={getLocalizedString("Back")}
|
|
93
90
|
onClick={onCancel}
|
|
94
91
|
isSmall={isSmall}
|
|
@@ -97,21 +94,21 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
97
94
|
</>
|
|
98
95
|
)}
|
|
99
96
|
<ResponsiveButton
|
|
100
|
-
icon={<
|
|
97
|
+
icon={<ArrowUndoIcon aria-hidden />}
|
|
101
98
|
label={getLocalizedString("Undo")}
|
|
102
99
|
onClick={history.undo}
|
|
103
100
|
disabled={disabled || !history.canUndo || !!activePlugin}
|
|
104
101
|
isSmall={isSmall}
|
|
105
102
|
/>
|
|
106
103
|
<ResponsiveButton
|
|
107
|
-
icon={<
|
|
104
|
+
icon={<ArrowRedoIcon aria-hidden />}
|
|
108
105
|
label={getLocalizedString("Redo")}
|
|
109
106
|
onClick={history.redo}
|
|
110
107
|
disabled={disabled || !history.canRedo || !!activePlugin}
|
|
111
108
|
isSmall={isSmall}
|
|
112
109
|
/>
|
|
113
110
|
<ResponsiveButton
|
|
114
|
-
icon={<
|
|
111
|
+
icon={<ArrowCirclepathIcon aria-hidden />}
|
|
115
112
|
label={getLocalizedString("Reset")}
|
|
116
113
|
onClick={history.reset}
|
|
117
114
|
disabled={disabled || !history.canUndo || !!activePlugin}
|
|
@@ -148,22 +145,23 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
|
|
|
148
145
|
|
|
149
146
|
{/* Done button floats over the canvas, bottom-right — hidden when a tool is active or no onConfirm */}
|
|
150
147
|
{!activePlugin && onConfirm && (
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
variant=
|
|
148
|
+
<Button
|
|
149
|
+
className="image-editor__done"
|
|
150
|
+
variant="primary"
|
|
151
|
+
icon={isSmall}
|
|
152
|
+
aria-label={isSmall ? getLocalizedString("Done") : undefined}
|
|
154
153
|
onClick={confirm}
|
|
155
154
|
disabled={disabled}
|
|
156
|
-
sx={{ position: "absolute", bottom: "1rem", right: "1rem", zIndex: 5 }}
|
|
157
155
|
>
|
|
158
|
-
<
|
|
156
|
+
<CheckmarkIcon aria-hidden />
|
|
159
157
|
{!isSmall && getLocalizedString("Done")}
|
|
160
|
-
</
|
|
158
|
+
</Button>
|
|
161
159
|
)}
|
|
162
160
|
|
|
163
161
|
{/* Replay overlay covers the canvas and sits above the Done button */}
|
|
164
162
|
{history.replaying && (
|
|
165
163
|
<div className="image-editor__replay-overlay">
|
|
166
|
-
<
|
|
164
|
+
<Spinner aria-label={getLocalizedString("Loading")} />
|
|
167
165
|
</div>
|
|
168
166
|
)}
|
|
169
167
|
</div>
|
|
@@ -230,20 +228,22 @@ function ToolButton({
|
|
|
230
228
|
isSmall: boolean;
|
|
231
229
|
}) {
|
|
232
230
|
let Icon = plugin.Icon;
|
|
231
|
+
let label = getLocalizedString(plugin.label);
|
|
232
|
+
|
|
233
233
|
if (isSmall) {
|
|
234
234
|
return (
|
|
235
|
-
<Tooltip
|
|
236
|
-
<
|
|
237
|
-
<
|
|
238
|
-
|
|
239
|
-
</IconButton>
|
|
240
|
-
</span>
|
|
235
|
+
<Tooltip content={label}>
|
|
236
|
+
<Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onActivate} disabled={busy}>
|
|
237
|
+
<Icon />
|
|
238
|
+
</Button>
|
|
241
239
|
</Tooltip>
|
|
242
240
|
);
|
|
243
241
|
}
|
|
242
|
+
|
|
244
243
|
return (
|
|
245
|
-
<Button
|
|
246
|
-
|
|
244
|
+
<Button variant="secondary" data-size="sm" onClick={onActivate} disabled={busy}>
|
|
245
|
+
<Icon />
|
|
246
|
+
{label}
|
|
247
247
|
</Button>
|
|
248
248
|
);
|
|
249
249
|
}
|
|
@@ -260,25 +260,23 @@ function ActionButton({
|
|
|
260
260
|
isSmall: boolean;
|
|
261
261
|
}) {
|
|
262
262
|
let Icon = plugin.Icon;
|
|
263
|
+
let label = getLocalizedString(plugin.label);
|
|
264
|
+
let icon = busy ? <Spinner aria-hidden data-size="xs" /> : <Icon />;
|
|
265
|
+
|
|
263
266
|
if (isSmall) {
|
|
264
267
|
return (
|
|
265
|
-
<Tooltip
|
|
266
|
-
<
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
</IconButton>
|
|
270
|
-
</span>
|
|
268
|
+
<Tooltip content={label}>
|
|
269
|
+
<Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onExecute} disabled={busy}>
|
|
270
|
+
{icon}
|
|
271
|
+
</Button>
|
|
271
272
|
</Tooltip>
|
|
272
273
|
);
|
|
273
274
|
}
|
|
275
|
+
|
|
274
276
|
return (
|
|
275
|
-
<Button
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
disabled={busy}
|
|
279
|
-
color="inherit"
|
|
280
|
-
>
|
|
281
|
-
{getLocalizedString(plugin.label)}
|
|
277
|
+
<Button variant="tertiary" data-size="sm" onClick={onExecute} disabled={busy}>
|
|
278
|
+
{icon}
|
|
279
|
+
{label}
|
|
282
280
|
</Button>
|
|
283
281
|
);
|
|
284
282
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Button,
|
|
1
|
+
import { Button, Tooltip } from "@digdir/designsystemet-react";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
@@ -9,23 +9,21 @@ interface Props {
|
|
|
9
9
|
isSmall: boolean;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/** Renders a labelled
|
|
12
|
+
/** Renders a labelled button on large screens and a tooltipped icon button on small ones. */
|
|
13
13
|
export function ResponsiveButton({ icon, label, onClick, disabled, isSmall }: Props) {
|
|
14
14
|
if (isSmall) {
|
|
15
15
|
return (
|
|
16
|
-
<Tooltip
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{icon}
|
|
21
|
-
</IconButton>
|
|
22
|
-
</span>
|
|
16
|
+
<Tooltip content={label}>
|
|
17
|
+
<Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onClick} disabled={disabled}>
|
|
18
|
+
{icon}
|
|
19
|
+
</Button>
|
|
23
20
|
</Tooltip>
|
|
24
21
|
);
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
return (
|
|
28
|
-
<Button
|
|
25
|
+
<Button variant="tertiary" data-size="sm" onClick={onClick} disabled={disabled}>
|
|
26
|
+
{icon}
|
|
29
27
|
{label}
|
|
30
28
|
</Button>
|
|
31
29
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Alert,
|
|
1
|
+
import { Alert, Paragraph, Spinner } from "@digdir/designsystemet-react";
|
|
2
2
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
3
|
|
|
4
4
|
import { CropCanvas } from "../../CropCanvas.js";
|
|
@@ -92,13 +92,13 @@ export function CropOverlay() {
|
|
|
92
92
|
|
|
93
93
|
{!cvReady && !cvError && (
|
|
94
94
|
<div className="crop-loading">
|
|
95
|
-
<
|
|
96
|
-
<
|
|
95
|
+
<Spinner aria-hidden data-size="xs" />
|
|
96
|
+
<Paragraph data-size="sm">{getLocalizedString("Loading OpenCV…")}</Paragraph>
|
|
97
97
|
</div>
|
|
98
98
|
)}
|
|
99
99
|
{cvError && (
|
|
100
100
|
<div className="crop-loading">
|
|
101
|
-
<Alert
|
|
101
|
+
<Alert data-color="danger" data-size="sm">
|
|
102
102
|
{getLocalizedString("Crop tool failed to load")}
|
|
103
103
|
</Alert>
|
|
104
104
|
</div>
|
|
@@ -106,9 +106,9 @@ export function CropOverlay() {
|
|
|
106
106
|
{(error || cropping) && (
|
|
107
107
|
<div className="crop-loading">
|
|
108
108
|
{cropping ? (
|
|
109
|
-
<
|
|
109
|
+
<Spinner aria-hidden data-size="xs" />
|
|
110
110
|
) : (
|
|
111
|
-
<Alert
|
|
111
|
+
<Alert data-color="danger" data-size="sm">
|
|
112
112
|
{error}
|
|
113
113
|
</Alert>
|
|
114
114
|
)}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { Button, CircularProgress } from "@mui/material";
|
|
1
|
+
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
2
|
+
import { CheckmarkIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
4
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
5
4
|
|
|
6
5
|
import { useCropContext } from "./CropContext.js";
|
|
@@ -17,17 +16,14 @@ export function CropToolbar() {
|
|
|
17
16
|
return (
|
|
18
17
|
<>
|
|
19
18
|
<div className="image-editor__toolbar-group">
|
|
20
|
-
<Button
|
|
19
|
+
<Button variant="tertiary" data-size="sm" onClick={onCancel} disabled={cropping}>
|
|
20
|
+
<XMarkIcon aria-hidden />
|
|
21
21
|
{getLocalizedString("Cancel")}
|
|
22
22
|
</Button>
|
|
23
23
|
</div>
|
|
24
24
|
<div className="image-editor__toolbar-group">
|
|
25
|
-
<Button
|
|
26
|
-
|
|
27
|
-
startIcon={cropping ? <CircularProgress size={18} color="inherit" /> : <CheckIcon />}
|
|
28
|
-
onClick={handleApply}
|
|
29
|
-
disabled={cropping || !cvReady || !!cvError}
|
|
30
|
-
>
|
|
25
|
+
<Button variant="primary" data-size="sm" onClick={handleApply} disabled={cropping || !cvReady || !!cvError}>
|
|
26
|
+
{cropping ? <Spinner aria-hidden data-size="xs" /> : <CheckmarkIcon aria-hidden />}
|
|
31
27
|
{getLocalizedString("Apply crop")}
|
|
32
28
|
</Button>
|
|
33
29
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ExpandIcon } from "@navikt/aksel-icons";
|
|
2
2
|
|
|
3
3
|
import type { ToolPlugin } from "../../types.js";
|
|
4
4
|
import { CropProvider } from "./CropContext.js";
|
|
@@ -12,7 +12,7 @@ export const cropPlugin: ToolPlugin = {
|
|
|
12
12
|
type: "tool",
|
|
13
13
|
id: "crop",
|
|
14
14
|
label: "Crop",
|
|
15
|
-
Icon:
|
|
15
|
+
Icon: ExpandIcon,
|
|
16
16
|
Provider: CropProvider,
|
|
17
17
|
Overlay: CropOverlay,
|
|
18
18
|
Toolbar: CropToolbar,
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import DeleteSweepIcon from "@mui/icons-material/DeleteSweep";
|
|
4
|
-
import { Button, CircularProgress } from "@mui/material";
|
|
1
|
+
import { Button, Spinner } from "@digdir/designsystemet-react";
|
|
2
|
+
import { CheckmarkIcon, EraserIcon, XMarkIcon } from "@navikt/aksel-icons";
|
|
5
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
6
4
|
import { useState } from "react";
|
|
7
5
|
|
|
@@ -29,25 +27,18 @@ export function RedactToolbar() {
|
|
|
29
27
|
return (
|
|
30
28
|
<>
|
|
31
29
|
<div className="image-editor__toolbar-group">
|
|
32
|
-
<Button
|
|
30
|
+
<Button variant="tertiary" data-size="sm" onClick={onCancel} disabled={applying}>
|
|
31
|
+
<XMarkIcon aria-hidden />
|
|
33
32
|
{getLocalizedString("Cancel")}
|
|
34
33
|
</Button>
|
|
35
|
-
<Button
|
|
36
|
-
|
|
37
|
-
onClick={clearAll}
|
|
38
|
-
color="inherit"
|
|
39
|
-
disabled={applying || rects.length === 0}
|
|
40
|
-
>
|
|
34
|
+
<Button variant="tertiary" data-size="sm" onClick={clearAll} disabled={applying || rects.length === 0}>
|
|
35
|
+
<EraserIcon aria-hidden />
|
|
41
36
|
{getLocalizedString("Clear all")}
|
|
42
37
|
</Button>
|
|
43
38
|
</div>
|
|
44
39
|
<div className="image-editor__toolbar-group">
|
|
45
|
-
<Button
|
|
46
|
-
|
|
47
|
-
startIcon={applying ? <CircularProgress size={18} color="inherit" /> : <CheckIcon />}
|
|
48
|
-
onClick={handleApply}
|
|
49
|
-
disabled={applying}
|
|
50
|
-
>
|
|
40
|
+
<Button variant="primary" data-size="sm" onClick={handleApply} disabled={applying}>
|
|
41
|
+
{applying ? <Spinner aria-hidden data-size="xs" /> : <CheckmarkIcon aria-hidden />}
|
|
51
42
|
{rects.length === 0 ? getLocalizedString("Done") : getLocalizedString("Apply redact")}
|
|
52
43
|
</Button>
|
|
53
44
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EyeObfuscatedIcon } from "@navikt/aksel-icons";
|
|
2
2
|
|
|
3
3
|
import type { ToolPlugin } from "../../types.js";
|
|
4
4
|
import { RedactProvider } from "./RedactContext.js";
|
|
@@ -12,7 +12,7 @@ export const redactPlugin: ToolPlugin = {
|
|
|
12
12
|
type: "tool",
|
|
13
13
|
id: "redact",
|
|
14
14
|
label: "Redact",
|
|
15
|
-
Icon:
|
|
15
|
+
Icon: EyeObfuscatedIcon,
|
|
16
16
|
Provider: RedactProvider,
|
|
17
17
|
Overlay: RedactOverlay,
|
|
18
18
|
Toolbar: RedactToolbar,
|