@olenbetong/synergi-react 4.2.5 → 4.2.6

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.
Files changed (56) hide show
  1. package/package.json +5 -5
  2. package/src/chrome/AppShell/index.tsx +29 -29
  3. package/src/chrome/openReport.ts +34 -34
  4. package/src/colorScheme.ts +81 -81
  5. package/src/components/DateNavigator/index.tsx +186 -186
  6. package/src/components/FilePond.tsx +312 -312
  7. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  8. package/src/components/ImageEditor/index.ts +9 -9
  9. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  10. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  11. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  12. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  13. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  14. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  15. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  16. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  17. package/src/components/ImageEditor/useImageHistory.ts +197 -197
  18. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  19. package/src/components/LinkedCardList/index.scss +95 -95
  20. package/src/components/MergeProgressDialog/index.tsx +249 -249
  21. package/src/components/PageBanner/index.tsx +80 -80
  22. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  23. package/src/components/ProgressBar/index.scss +96 -96
  24. package/src/components/SplitContainer/index.tsx +333 -333
  25. package/src/components/Toolbar/index.tsx +232 -232
  26. package/src/designsystemet-web-types.d.ts +24 -24
  27. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  28. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  29. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  30. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  31. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  32. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  33. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  34. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  35. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  36. package/src/elements/ElementLookup.tsx +123 -123
  37. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
  38. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
  39. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
  42. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
  43. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
  44. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
  45. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  46. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  47. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  48. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  49. package/src/elements/ProjectSelect.tsx +130 -130
  50. package/src/elements/index.ts +15 -15
  51. package/src/filter/index.ts +34 -34
  52. package/src/i18n.ts +13 -13
  53. package/src/index.ts +77 -77
  54. package/src/mui/MuiThemeProvider.tsx +174 -174
  55. package/src/mui/index.ts +1 -1
  56. package/src/test/setup.ts +8 -8
@@ -1,348 +1,348 @@
1
- import { Button, Spinner, Tooltip } from "@digdir/designsystemet-react";
2
- import { ArrowCirclepathIcon, ArrowLeftIcon, ArrowRedoIcon, ArrowUndoIcon, CheckmarkIcon } from "@navikt/aksel-icons";
3
- import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
4
-
5
- import "./ImageEditor.css";
6
- import { ResponsiveButton } from "./ResponsiveButton.js";
7
- import type { ActionPlugin, ActionRegistry, EditAction, Plugin, ToolPlugin, ViewPlugin } from "./types.js";
8
- import { useActiveTool } from "./useActiveTool.js";
9
- import { useImageHistory } from "./useImageHistory.js";
10
- import { useIsSmall } from "./useIsSmall.js";
11
- import { getLocalizedString } from "../../i18n.js";
12
-
13
- export type ImageEditorRef = {
14
- /** Returns the current edited blob, or null if no edits have been applied since the last source image. */
15
- getCurrentBlob: () => Blob | null;
16
- /**
17
- * Runs a registered action plugin (e.g. `"rotate-cw"`) against the current image.
18
- * Use this instead of calling `plugin.execute()` directly so external toolbars and
19
- * keyboard shortcuts share the editor's image state and undo history.
20
- * Resolves once the resulting image has been applied.
21
- */
22
- executeAction: (pluginId: string) => Promise<void>;
23
- /**
24
- * Resolves once every queued action has been applied. Await this before `getCurrentBlob()`
25
- * to be sure an action started moments earlier is included.
26
- */
27
- whenIdle: () => Promise<void>;
28
- };
29
-
30
- interface Props {
31
- imageUrl: string;
32
- /** Called when the user clicks the Done button. When omitted, the Done button is not shown. */
33
- onConfirm?: (blob: Blob) => void;
34
- /** Called when the user wants to exit without saving. Shows a back button in the top bar. */
35
- onCancel?: () => void;
36
- plugins: Plugin[];
37
- /** Optional view plugin (e.g. zoom/pan) that wraps the canvas and contributes top-bar controls. */
38
- viewPlugin?: ViewPlugin;
39
- /**
40
- * Id of a tool plugin (e.g. `"crop"`) to open as soon as the editor mounts, instead of the
41
- * plain image. Cancelling the tool returns to the plain image as usual.
42
- */
43
- initialTool?: string;
44
- }
45
-
46
- /**
47
- * Full-screen image editor shell.
48
- * Does not know about specific tools — behaviour is entirely driven by the `plugins` prop.
49
- * Tool plugins contribute an overlay and toolbar; action plugins execute immediately.
50
- * Supports undo/redo: each applied transformation is recorded with its EditAction list.
51
- */
52
- export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEditor(
53
- { imageUrl, onConfirm, onCancel, plugins, viewPlugin, initialTool }: Props,
54
- ref,
55
- ) {
56
- let registry = useMemo(() => buildActionRegistry(plugins), [plugins]);
57
- let history = useImageHistory(imageUrl, registry);
58
- let { activePlugin, activateTool, deactivateTool } = useActiveTool(plugins, initialTool ?? null);
59
- let [busy, setBusy] = useState(false);
60
- let disabled = busy || history.replaying;
61
- let isSmall = useIsSmall();
62
-
63
- // Keeps async/imperative callers working against the latest history state instead of
64
- // the snapshot captured when their closure was created.
65
- let historyRef = useRef(history);
66
- historyRef.current = history;
67
- // Serialises every action (toolbar clicks and imperative calls alike) so rapid
68
- // invocations each build on the previous result instead of racing on a stale image.
69
- let actionQueueRef = useRef<Promise<void>>(Promise.resolve());
70
-
71
- useImperativeHandle(ref, () => ({
72
- getCurrentBlob: () => historyRef.current.getCurrentBlob(),
73
- whenIdle: () => actionQueueRef.current,
74
- executeAction: (pluginId: string) => {
75
- let plugin = plugins.find((p): p is ActionPlugin => p.type === "action" && p.id === pluginId);
76
- if (!plugin) {
77
- console.warn(`[ImageEditor] No action plugin registered with id "${pluginId}"`);
78
- return Promise.resolve();
79
- }
80
- return enqueueAction(plugin);
81
- },
82
- }));
83
-
84
- function enqueueAction(plugin: ActionPlugin) {
85
- let next = actionQueueRef.current.then(() => executeAction(plugin));
86
- actionQueueRef.current = next.catch(() => {});
87
- return next;
88
- }
89
-
90
- async function executeAction(plugin: ActionPlugin) {
91
- setBusy(true);
92
- try {
93
- let blob = await plugin.execute(historyRef.current.getCurrentImageUrl());
94
- let actions: EditAction[] = [{ type: plugin.id, params: {} }];
95
- historyRef.current.applyActions(blob, actions);
96
- } finally {
97
- setBusy(false);
98
- }
99
- }
100
-
101
- function handleToolApply(blob: Blob, actions: EditAction[]) {
102
- history.applyActions(blob, actions);
103
- deactivateTool();
104
- }
105
-
106
- function confirm() {
107
- if (!onConfirm) return;
108
- if (history.currentBlob) {
109
- onConfirm(history.currentBlob);
110
- return;
111
- }
112
- fetch(history.currentImageUrl)
113
- .then((r) => r.blob())
114
- .then(onConfirm);
115
- }
116
-
117
- let CanvasWrapper = viewPlugin?.CanvasWrapper;
118
- let TopBarControls = viewPlugin?.TopBarControls;
119
-
120
- let inner = (
121
- <div className="image-editor">
122
- {/* Top toolbar — always visible; undo/redo/reset disabled while a tool is active */}
123
- <div className="image-editor__topbar">
124
- <div className="image-editor__toolbar-group">
125
- {onCancel && (
126
- <>
127
- <ResponsiveButton
128
- icon={<ArrowLeftIcon aria-hidden />}
129
- label={getLocalizedString("Back")}
130
- onClick={onCancel}
131
- isSmall={isSmall}
132
- />
133
- <span className="image-editor__topbar-divider" aria-hidden />
134
- </>
135
- )}
136
- <ResponsiveButton
137
- icon={<ArrowUndoIcon aria-hidden />}
138
- label={getLocalizedString("Undo")}
139
- onClick={history.undo}
140
- disabled={disabled || !history.canUndo || !!activePlugin}
141
- isSmall={isSmall}
142
- />
143
- <ResponsiveButton
144
- icon={<ArrowRedoIcon aria-hidden />}
145
- label={getLocalizedString("Redo")}
146
- onClick={history.redo}
147
- disabled={disabled || !history.canRedo || !!activePlugin}
148
- isSmall={isSmall}
149
- />
150
- <ResponsiveButton
151
- icon={<ArrowCirclepathIcon aria-hidden />}
152
- label={getLocalizedString("Reset")}
153
- onClick={history.reset}
154
- disabled={disabled || !history.canUndo || !!activePlugin}
155
- isSmall={isSmall}
156
- />
157
- </div>
158
-
159
- {TopBarControls && (
160
- <div className="image-editor__toolbar-group">
161
- <TopBarControls disabled={disabled} isSmall={isSmall} />
162
- </div>
163
- )}
164
- </div>
165
-
166
- {/* Canvas area */}
167
- <div className="image-editor__canvas">
168
- {CanvasWrapper ? (
169
- <CanvasWrapper panEnabled={!activePlugin}>
170
- {activePlugin ? (
171
- <ActiveOverlay plugin={activePlugin} />
172
- ) : (
173
- <img
174
- src={history.currentImageUrl}
175
- alt={getLocalizedString("Image to edit")}
176
- className="image-editor__img"
177
- />
178
- )}
179
- </CanvasWrapper>
180
- ) : activePlugin ? (
181
- <ActiveOverlay plugin={activePlugin} />
182
- ) : (
183
- <img src={history.currentImageUrl} alt={getLocalizedString("Image to edit")} className="image-editor__img" />
184
- )}
185
-
186
- {/* Done button floats over the canvas, bottom-right — hidden when a tool is active or no onConfirm */}
187
- {!activePlugin && onConfirm && (
188
- <Button
189
- className="image-editor__done"
190
- variant="primary"
191
- icon={isSmall}
192
- aria-label={isSmall ? getLocalizedString("Done") : undefined}
193
- onClick={confirm}
194
- disabled={disabled}
195
- >
196
- <CheckmarkIcon aria-hidden />
197
- {!isSmall && getLocalizedString("Done")}
198
- </Button>
199
- )}
200
-
201
- {/* Replay overlay covers the canvas and sits above the Done button */}
202
- {history.replaying && (
203
- <div className="image-editor__replay-overlay">
204
- <Spinner aria-label={getLocalizedString("Loading")} />
205
- </div>
206
- )}
207
- </div>
208
-
209
- {/* Bottom toolbar — tool/action plugin buttons */}
210
- <div className="image-editor__toolbar">
211
- {activePlugin ? (
212
- <ActiveToolbar plugin={activePlugin} />
213
- ) : (
214
- <div className="image-editor__toolbar-group">
215
- {plugins.map((p) =>
216
- p.type === "tool" ? (
217
- <ToolButton
218
- key={p.id}
219
- plugin={p}
220
- busy={disabled}
221
- onActivate={() => activateTool(p.id)}
222
- isSmall={isSmall}
223
- />
224
- ) : (
225
- <ActionButton
226
- key={p.id}
227
- plugin={p}
228
- busy={disabled}
229
- onExecute={() => enqueueAction(p)}
230
- isSmall={isSmall}
231
- />
232
- ),
233
- )}
234
- </div>
235
- )}
236
- </div>
237
- </div>
238
- );
239
-
240
- // Wrap with the active tool's provider so Overlay and Toolbar share context.
241
- if (activePlugin) {
242
- let ActiveProvider = activePlugin.Provider;
243
- inner = (
244
- <ActiveProvider imageUrl={history.currentImageUrl} onApply={handleToolApply} onCancel={deactivateTool}>
245
- {inner}
246
- </ActiveProvider>
247
- );
248
- }
249
-
250
- // Wrap with the view plugin's provider (outermost) so both CanvasWrapper and TopBarControls share state.
251
- if (viewPlugin) {
252
- let ViewProvider = viewPlugin.Provider;
253
- return <ViewProvider>{inner}</ViewProvider>;
254
- }
255
-
256
- return inner;
257
- });
258
-
259
- function ToolButton({
260
- plugin,
261
- busy,
262
- onActivate,
263
- isSmall,
264
- }: {
265
- plugin: ToolPlugin;
266
- busy: boolean;
267
- onActivate: () => void;
268
- isSmall: boolean;
269
- }) {
270
- let Icon = plugin.Icon;
271
- let label = getLocalizedString(plugin.label);
272
-
273
- if (isSmall) {
274
- return (
275
- <Tooltip content={label}>
276
- <Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onActivate} disabled={busy}>
277
- <Icon />
278
- </Button>
279
- </Tooltip>
280
- );
281
- }
282
-
283
- return (
284
- <Button variant="tertiary" data-size="sm" onClick={onActivate} disabled={busy}>
285
- <Icon />
286
- {label}
287
- </Button>
288
- );
289
- }
290
-
291
- function ActionButton({
292
- plugin,
293
- busy,
294
- onExecute,
295
- isSmall,
296
- }: {
297
- plugin: ActionPlugin;
298
- busy: boolean;
299
- onExecute: () => void;
300
- isSmall: boolean;
301
- }) {
302
- let Icon = plugin.Icon;
303
- let label = getLocalizedString(plugin.label);
304
- let icon = busy ? <Spinner aria-hidden data-size="xs" /> : <Icon />;
305
-
306
- if (isSmall) {
307
- return (
308
- <Tooltip content={label}>
309
- <Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onExecute} disabled={busy}>
310
- {icon}
311
- </Button>
312
- </Tooltip>
313
- );
314
- }
315
-
316
- return (
317
- <Button variant="tertiary" data-size="sm" onClick={onExecute} disabled={busy}>
318
- {icon}
319
- {label}
320
- </Button>
321
- );
322
- }
323
-
324
- function ActiveOverlay({ plugin }: { plugin: ToolPlugin }) {
325
- let Overlay = plugin.Overlay;
326
- return <Overlay />;
327
- }
328
-
329
- function ActiveToolbar({ plugin }: { plugin: ToolPlugin }) {
330
- let Toolbar = plugin.Toolbar;
331
- return <Toolbar />;
332
- }
333
-
334
- /** Builds the action registry from all registered plugins. */
335
- function buildActionRegistry(plugins: Plugin[]): ActionRegistry {
336
- let registry: ActionRegistry = new Map();
337
- for (let plugin of plugins) {
338
- if (plugin.type === "action") {
339
- // Action plugins have no params — their execute function IS the replay handler.
340
- registry.set(plugin.id, (imageUrl, _params) => plugin.execute(imageUrl));
341
- } else {
342
- for (let action of plugin.actions) {
343
- registry.set(action.type, action.apply);
344
- }
345
- }
346
- }
347
- return registry;
348
- }
1
+ import { Button, Spinner, Tooltip } from "@digdir/designsystemet-react";
2
+ import { ArrowCirclepathIcon, ArrowLeftIcon, ArrowRedoIcon, ArrowUndoIcon, CheckmarkIcon } from "@navikt/aksel-icons";
3
+ import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
4
+
5
+ import "./ImageEditor.css";
6
+ import { ResponsiveButton } from "./ResponsiveButton.js";
7
+ import type { ActionPlugin, ActionRegistry, EditAction, Plugin, ToolPlugin, ViewPlugin } from "./types.js";
8
+ import { useActiveTool } from "./useActiveTool.js";
9
+ import { useImageHistory } from "./useImageHistory.js";
10
+ import { useIsSmall } from "./useIsSmall.js";
11
+ import { getLocalizedString } from "../../i18n.js";
12
+
13
+ export type ImageEditorRef = {
14
+ /** Returns the current edited blob, or null if no edits have been applied since the last source image. */
15
+ getCurrentBlob: () => Blob | null;
16
+ /**
17
+ * Runs a registered action plugin (e.g. `"rotate-cw"`) against the current image.
18
+ * Use this instead of calling `plugin.execute()` directly so external toolbars and
19
+ * keyboard shortcuts share the editor's image state and undo history.
20
+ * Resolves once the resulting image has been applied.
21
+ */
22
+ executeAction: (pluginId: string) => Promise<void>;
23
+ /**
24
+ * Resolves once every queued action has been applied. Await this before `getCurrentBlob()`
25
+ * to be sure an action started moments earlier is included.
26
+ */
27
+ whenIdle: () => Promise<void>;
28
+ };
29
+
30
+ interface Props {
31
+ imageUrl: string;
32
+ /** Called when the user clicks the Done button. When omitted, the Done button is not shown. */
33
+ onConfirm?: (blob: Blob) => void;
34
+ /** Called when the user wants to exit without saving. Shows a back button in the top bar. */
35
+ onCancel?: () => void;
36
+ plugins: Plugin[];
37
+ /** Optional view plugin (e.g. zoom/pan) that wraps the canvas and contributes top-bar controls. */
38
+ viewPlugin?: ViewPlugin;
39
+ /**
40
+ * Id of a tool plugin (e.g. `"crop"`) to open as soon as the editor mounts, instead of the
41
+ * plain image. Cancelling the tool returns to the plain image as usual.
42
+ */
43
+ initialTool?: string;
44
+ }
45
+
46
+ /**
47
+ * Full-screen image editor shell.
48
+ * Does not know about specific tools — behaviour is entirely driven by the `plugins` prop.
49
+ * Tool plugins contribute an overlay and toolbar; action plugins execute immediately.
50
+ * Supports undo/redo: each applied transformation is recorded with its EditAction list.
51
+ */
52
+ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEditor(
53
+ { imageUrl, onConfirm, onCancel, plugins, viewPlugin, initialTool }: Props,
54
+ ref,
55
+ ) {
56
+ let registry = useMemo(() => buildActionRegistry(plugins), [plugins]);
57
+ let history = useImageHistory(imageUrl, registry);
58
+ let { activePlugin, activateTool, deactivateTool } = useActiveTool(plugins, initialTool ?? null);
59
+ let [busy, setBusy] = useState(false);
60
+ let disabled = busy || history.replaying;
61
+ let isSmall = useIsSmall();
62
+
63
+ // Keeps async/imperative callers working against the latest history state instead of
64
+ // the snapshot captured when their closure was created.
65
+ let historyRef = useRef(history);
66
+ historyRef.current = history;
67
+ // Serialises every action (toolbar clicks and imperative calls alike) so rapid
68
+ // invocations each build on the previous result instead of racing on a stale image.
69
+ let actionQueueRef = useRef<Promise<void>>(Promise.resolve());
70
+
71
+ useImperativeHandle(ref, () => ({
72
+ getCurrentBlob: () => historyRef.current.getCurrentBlob(),
73
+ whenIdle: () => actionQueueRef.current,
74
+ executeAction: (pluginId: string) => {
75
+ let plugin = plugins.find((p): p is ActionPlugin => p.type === "action" && p.id === pluginId);
76
+ if (!plugin) {
77
+ console.warn(`[ImageEditor] No action plugin registered with id "${pluginId}"`);
78
+ return Promise.resolve();
79
+ }
80
+ return enqueueAction(plugin);
81
+ },
82
+ }));
83
+
84
+ function enqueueAction(plugin: ActionPlugin) {
85
+ let next = actionQueueRef.current.then(() => executeAction(plugin));
86
+ actionQueueRef.current = next.catch(() => {});
87
+ return next;
88
+ }
89
+
90
+ async function executeAction(plugin: ActionPlugin) {
91
+ setBusy(true);
92
+ try {
93
+ let blob = await plugin.execute(historyRef.current.getCurrentImageUrl());
94
+ let actions: EditAction[] = [{ type: plugin.id, params: {} }];
95
+ historyRef.current.applyActions(blob, actions);
96
+ } finally {
97
+ setBusy(false);
98
+ }
99
+ }
100
+
101
+ function handleToolApply(blob: Blob, actions: EditAction[]) {
102
+ history.applyActions(blob, actions);
103
+ deactivateTool();
104
+ }
105
+
106
+ function confirm() {
107
+ if (!onConfirm) return;
108
+ if (history.currentBlob) {
109
+ onConfirm(history.currentBlob);
110
+ return;
111
+ }
112
+ fetch(history.currentImageUrl)
113
+ .then((r) => r.blob())
114
+ .then(onConfirm);
115
+ }
116
+
117
+ let CanvasWrapper = viewPlugin?.CanvasWrapper;
118
+ let TopBarControls = viewPlugin?.TopBarControls;
119
+
120
+ let inner = (
121
+ <div className="image-editor">
122
+ {/* Top toolbar — always visible; undo/redo/reset disabled while a tool is active */}
123
+ <div className="image-editor__topbar">
124
+ <div className="image-editor__toolbar-group">
125
+ {onCancel && (
126
+ <>
127
+ <ResponsiveButton
128
+ icon={<ArrowLeftIcon aria-hidden />}
129
+ label={getLocalizedString("Back")}
130
+ onClick={onCancel}
131
+ isSmall={isSmall}
132
+ />
133
+ <span className="image-editor__topbar-divider" aria-hidden />
134
+ </>
135
+ )}
136
+ <ResponsiveButton
137
+ icon={<ArrowUndoIcon aria-hidden />}
138
+ label={getLocalizedString("Undo")}
139
+ onClick={history.undo}
140
+ disabled={disabled || !history.canUndo || !!activePlugin}
141
+ isSmall={isSmall}
142
+ />
143
+ <ResponsiveButton
144
+ icon={<ArrowRedoIcon aria-hidden />}
145
+ label={getLocalizedString("Redo")}
146
+ onClick={history.redo}
147
+ disabled={disabled || !history.canRedo || !!activePlugin}
148
+ isSmall={isSmall}
149
+ />
150
+ <ResponsiveButton
151
+ icon={<ArrowCirclepathIcon aria-hidden />}
152
+ label={getLocalizedString("Reset")}
153
+ onClick={history.reset}
154
+ disabled={disabled || !history.canUndo || !!activePlugin}
155
+ isSmall={isSmall}
156
+ />
157
+ </div>
158
+
159
+ {TopBarControls && (
160
+ <div className="image-editor__toolbar-group">
161
+ <TopBarControls disabled={disabled} isSmall={isSmall} />
162
+ </div>
163
+ )}
164
+ </div>
165
+
166
+ {/* Canvas area */}
167
+ <div className="image-editor__canvas">
168
+ {CanvasWrapper ? (
169
+ <CanvasWrapper panEnabled={!activePlugin}>
170
+ {activePlugin ? (
171
+ <ActiveOverlay plugin={activePlugin} />
172
+ ) : (
173
+ <img
174
+ src={history.currentImageUrl}
175
+ alt={getLocalizedString("Image to edit")}
176
+ className="image-editor__img"
177
+ />
178
+ )}
179
+ </CanvasWrapper>
180
+ ) : activePlugin ? (
181
+ <ActiveOverlay plugin={activePlugin} />
182
+ ) : (
183
+ <img src={history.currentImageUrl} alt={getLocalizedString("Image to edit")} className="image-editor__img" />
184
+ )}
185
+
186
+ {/* Done button floats over the canvas, bottom-right — hidden when a tool is active or no onConfirm */}
187
+ {!activePlugin && onConfirm && (
188
+ <Button
189
+ className="image-editor__done"
190
+ variant="primary"
191
+ icon={isSmall}
192
+ aria-label={isSmall ? getLocalizedString("Done") : undefined}
193
+ onClick={confirm}
194
+ disabled={disabled}
195
+ >
196
+ <CheckmarkIcon aria-hidden />
197
+ {!isSmall && getLocalizedString("Done")}
198
+ </Button>
199
+ )}
200
+
201
+ {/* Replay overlay covers the canvas and sits above the Done button */}
202
+ {history.replaying && (
203
+ <div className="image-editor__replay-overlay">
204
+ <Spinner aria-label={getLocalizedString("Loading")} />
205
+ </div>
206
+ )}
207
+ </div>
208
+
209
+ {/* Bottom toolbar — tool/action plugin buttons */}
210
+ <div className="image-editor__toolbar">
211
+ {activePlugin ? (
212
+ <ActiveToolbar plugin={activePlugin} />
213
+ ) : (
214
+ <div className="image-editor__toolbar-group">
215
+ {plugins.map((p) =>
216
+ p.type === "tool" ? (
217
+ <ToolButton
218
+ key={p.id}
219
+ plugin={p}
220
+ busy={disabled}
221
+ onActivate={() => activateTool(p.id)}
222
+ isSmall={isSmall}
223
+ />
224
+ ) : (
225
+ <ActionButton
226
+ key={p.id}
227
+ plugin={p}
228
+ busy={disabled}
229
+ onExecute={() => enqueueAction(p)}
230
+ isSmall={isSmall}
231
+ />
232
+ ),
233
+ )}
234
+ </div>
235
+ )}
236
+ </div>
237
+ </div>
238
+ );
239
+
240
+ // Wrap with the active tool's provider so Overlay and Toolbar share context.
241
+ if (activePlugin) {
242
+ let ActiveProvider = activePlugin.Provider;
243
+ inner = (
244
+ <ActiveProvider imageUrl={history.currentImageUrl} onApply={handleToolApply} onCancel={deactivateTool}>
245
+ {inner}
246
+ </ActiveProvider>
247
+ );
248
+ }
249
+
250
+ // Wrap with the view plugin's provider (outermost) so both CanvasWrapper and TopBarControls share state.
251
+ if (viewPlugin) {
252
+ let ViewProvider = viewPlugin.Provider;
253
+ return <ViewProvider>{inner}</ViewProvider>;
254
+ }
255
+
256
+ return inner;
257
+ });
258
+
259
+ function ToolButton({
260
+ plugin,
261
+ busy,
262
+ onActivate,
263
+ isSmall,
264
+ }: {
265
+ plugin: ToolPlugin;
266
+ busy: boolean;
267
+ onActivate: () => void;
268
+ isSmall: boolean;
269
+ }) {
270
+ let Icon = plugin.Icon;
271
+ let label = getLocalizedString(plugin.label);
272
+
273
+ if (isSmall) {
274
+ return (
275
+ <Tooltip content={label}>
276
+ <Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onActivate} disabled={busy}>
277
+ <Icon />
278
+ </Button>
279
+ </Tooltip>
280
+ );
281
+ }
282
+
283
+ return (
284
+ <Button variant="tertiary" data-size="sm" onClick={onActivate} disabled={busy}>
285
+ <Icon />
286
+ {label}
287
+ </Button>
288
+ );
289
+ }
290
+
291
+ function ActionButton({
292
+ plugin,
293
+ busy,
294
+ onExecute,
295
+ isSmall,
296
+ }: {
297
+ plugin: ActionPlugin;
298
+ busy: boolean;
299
+ onExecute: () => void;
300
+ isSmall: boolean;
301
+ }) {
302
+ let Icon = plugin.Icon;
303
+ let label = getLocalizedString(plugin.label);
304
+ let icon = busy ? <Spinner aria-hidden data-size="xs" /> : <Icon />;
305
+
306
+ if (isSmall) {
307
+ return (
308
+ <Tooltip content={label}>
309
+ <Button icon variant="tertiary" data-size="sm" aria-label={label} onClick={onExecute} disabled={busy}>
310
+ {icon}
311
+ </Button>
312
+ </Tooltip>
313
+ );
314
+ }
315
+
316
+ return (
317
+ <Button variant="tertiary" data-size="sm" onClick={onExecute} disabled={busy}>
318
+ {icon}
319
+ {label}
320
+ </Button>
321
+ );
322
+ }
323
+
324
+ function ActiveOverlay({ plugin }: { plugin: ToolPlugin }) {
325
+ let Overlay = plugin.Overlay;
326
+ return <Overlay />;
327
+ }
328
+
329
+ function ActiveToolbar({ plugin }: { plugin: ToolPlugin }) {
330
+ let Toolbar = plugin.Toolbar;
331
+ return <Toolbar />;
332
+ }
333
+
334
+ /** Builds the action registry from all registered plugins. */
335
+ function buildActionRegistry(plugins: Plugin[]): ActionRegistry {
336
+ let registry: ActionRegistry = new Map();
337
+ for (let plugin of plugins) {
338
+ if (plugin.type === "action") {
339
+ // Action plugins have no params — their execute function IS the replay handler.
340
+ registry.set(plugin.id, (imageUrl, _params) => plugin.execute(imageUrl));
341
+ } else {
342
+ for (let action of plugin.actions) {
343
+ registry.set(action.type, action.apply);
344
+ }
345
+ }
346
+ }
347
+ return registry;
348
+ }