@olenbetong/synergi-react 4.1.1 → 4.1.2

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