@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,197 +1,197 @@
1
- import { useEffect, useRef, useState } from "react";
2
-
3
- import type { ActionRegistry, EditAction } from "./types.js";
4
-
5
- interface HistoryState {
6
- past: EditAction[][];
7
- future: EditAction[][];
8
- }
9
-
10
- interface CurrentState {
11
- url: string;
12
- blob: Blob | null;
13
- /** True if `url` is an object URL we created and must eventually revoke. */
14
- generated: boolean;
15
- }
16
-
17
- export interface UseImageHistoryResult {
18
- currentImageUrl: string;
19
- currentBlob: Blob | null;
20
- /** Synchronous read of the current image URL — valid immediately after `applyActions`. */
21
- getCurrentImageUrl: () => string;
22
- /** Synchronous read of the current blob — valid immediately after `applyActions`. */
23
- getCurrentBlob: () => Blob | null;
24
- canUndo: boolean;
25
- canRedo: boolean;
26
- /** True while an async replay (undo/redo) is in progress. */
27
- replaying: boolean;
28
- /** Applies a new blob to the current state and records it in history. Returns the new object URL. */
29
- applyActions: (blob: Blob, actions: EditAction[]) => string;
30
- undo: () => void;
31
- redo: () => void;
32
- reset: () => void;
33
- }
34
-
35
- /**
36
- * Manages undo/redo history for the image editor using action replay.
37
- *
38
- * Only action lists are stored — no intermediate blobs. Undo/redo replays
39
- * all remaining actions from the source image, keeping memory usage minimal
40
- * regardless of history depth. Only one blob is in memory at a time.
41
- */
42
- export function useImageHistory(sourceUrl: string, registry: ActionRegistry): UseImageHistoryResult {
43
- let [history, setHistory] = useState<HistoryState>({ past: [], future: [] });
44
- let [current, setCurrent] = useState<CurrentState>({ url: sourceUrl, blob: null, generated: false });
45
- let [replaying, setReplaying] = useState(false);
46
-
47
- let historyRef = useRef(history);
48
- historyRef.current = history;
49
- // Written synchronously by `replaceCurrent` so imperative callers can read the current
50
- // image/blob before React has committed the corresponding render.
51
- let currentRef = useRef(current);
52
- let isReplaying = useRef(false);
53
- let replayAbort = useRef<AbortController | null>(null);
54
-
55
- function replaceCurrent(next: CurrentState) {
56
- let prev = currentRef.current;
57
- if (prev.generated && prev.url !== next.url) URL.revokeObjectURL(prev.url);
58
- currentRef.current = next;
59
- setCurrent(next);
60
- }
61
-
62
- // When source changes (e.g. component remount with new image), reset fully.
63
- useEffect(() => {
64
- replayAbort.current?.abort();
65
- isReplaying.current = false;
66
- setReplaying(false);
67
- replaceCurrent({ url: sourceUrl, blob: null, generated: false });
68
- setHistory({ past: [], future: [] });
69
- }, [sourceUrl]);
70
-
71
- useEffect(() => {
72
- return () => {
73
- if (currentRef.current.generated) URL.revokeObjectURL(currentRef.current.url);
74
- replayAbort.current?.abort();
75
- };
76
- }, []);
77
-
78
- function applyActions(blob: Blob, actions: EditAction[]) {
79
- // A direct apply always takes priority — abort any in-flight replay.
80
- replayAbort.current?.abort();
81
- isReplaying.current = false;
82
- setReplaying(false);
83
-
84
- let newUrl = URL.createObjectURL(blob);
85
- replaceCurrent({ url: newUrl, blob, generated: true });
86
- setHistory((prev) => ({ past: [...prev.past, actions], future: [] }));
87
-
88
- return newUrl;
89
- }
90
-
91
- async function doReplay(newPast: EditAction[][], newFuture: EditAction[][]) {
92
- replayAbort.current?.abort();
93
- let abort = new AbortController();
94
- replayAbort.current = abort;
95
- isReplaying.current = true;
96
- setReplaying(true);
97
-
98
- try {
99
- let result = await replayAll(sourceUrl, newPast, registry, abort.signal);
100
- if (abort.signal.aborted) return;
101
-
102
- if (result) {
103
- replaceCurrent({ url: result.url, blob: result.blob, generated: true });
104
- } else {
105
- replaceCurrent({ url: sourceUrl, blob: null, generated: false });
106
- }
107
- setHistory({ past: newPast, future: newFuture });
108
- } finally {
109
- if (!abort.signal.aborted) {
110
- isReplaying.current = false;
111
- setReplaying(false);
112
- }
113
- }
114
- }
115
-
116
- function undo() {
117
- if (isReplaying.current) return;
118
- let { past, future } = historyRef.current;
119
- if (past.length === 0) return;
120
- doReplay(past.slice(0, -1), [past.at(-1)!, ...future]);
121
- }
122
-
123
- function redo() {
124
- if (isReplaying.current) return;
125
- let { past, future } = historyRef.current;
126
- if (future.length === 0) return;
127
- doReplay([...past, future[0]], future.slice(1));
128
- }
129
-
130
- function reset() {
131
- replayAbort.current?.abort();
132
- isReplaying.current = false;
133
- setReplaying(false);
134
- replaceCurrent({ url: sourceUrl, blob: null, generated: false });
135
- setHistory({ past: [], future: [] });
136
- }
137
-
138
- return {
139
- currentImageUrl: current.url,
140
- currentBlob: current.blob,
141
- getCurrentImageUrl: () => currentRef.current.url,
142
- getCurrentBlob: () => currentRef.current.blob,
143
- canUndo: history.past.length > 0,
144
- canRedo: history.future.length > 0,
145
- replaying,
146
- applyActions,
147
- undo,
148
- redo,
149
- reset,
150
- };
151
- }
152
-
153
- /**
154
- * Replays a sequence of action groups from a source URL.
155
- * Intermediate object URLs are revoked as soon as a new step succeeds.
156
- * Returns the final `{ url, blob }` or `null` if there were no actions.
157
- */
158
- async function replayAll(
159
- sourceUrl: string,
160
- actionGroups: EditAction[][],
161
- registry: ActionRegistry,
162
- signal: AbortSignal,
163
- ): Promise<{ url: string; blob: Blob } | null> {
164
- let prevUrl = sourceUrl;
165
- let prevGenerated = false;
166
- let lastBlob: Blob | null = null;
167
-
168
- for (let group of actionGroups) {
169
- for (let action of group) {
170
- if (signal.aborted) {
171
- if (prevGenerated) URL.revokeObjectURL(prevUrl);
172
- return null;
173
- }
174
-
175
- let apply = registry.get(action.type);
176
- if (!apply) {
177
- console.warn(`[ImageHistory] No replay handler for action type "${action.type}" — skipping`);
178
- continue;
179
- }
180
-
181
- let blob = await apply(prevUrl, action.params);
182
-
183
- if (signal.aborted) {
184
- if (prevGenerated) URL.revokeObjectURL(prevUrl);
185
- return null;
186
- }
187
-
188
- if (prevGenerated) URL.revokeObjectURL(prevUrl);
189
- lastBlob = blob;
190
- prevUrl = URL.createObjectURL(blob);
191
- prevGenerated = true;
192
- }
193
- }
194
-
195
- if (!lastBlob || !prevGenerated) return null;
196
- return { url: prevUrl, blob: lastBlob };
197
- }
1
+ import { useEffect, useRef, useState } from "react";
2
+
3
+ import type { ActionRegistry, EditAction } from "./types.js";
4
+
5
+ interface HistoryState {
6
+ past: EditAction[][];
7
+ future: EditAction[][];
8
+ }
9
+
10
+ interface CurrentState {
11
+ url: string;
12
+ blob: Blob | null;
13
+ /** True if `url` is an object URL we created and must eventually revoke. */
14
+ generated: boolean;
15
+ }
16
+
17
+ export interface UseImageHistoryResult {
18
+ currentImageUrl: string;
19
+ currentBlob: Blob | null;
20
+ /** Synchronous read of the current image URL — valid immediately after `applyActions`. */
21
+ getCurrentImageUrl: () => string;
22
+ /** Synchronous read of the current blob — valid immediately after `applyActions`. */
23
+ getCurrentBlob: () => Blob | null;
24
+ canUndo: boolean;
25
+ canRedo: boolean;
26
+ /** True while an async replay (undo/redo) is in progress. */
27
+ replaying: boolean;
28
+ /** Applies a new blob to the current state and records it in history. Returns the new object URL. */
29
+ applyActions: (blob: Blob, actions: EditAction[]) => string;
30
+ undo: () => void;
31
+ redo: () => void;
32
+ reset: () => void;
33
+ }
34
+
35
+ /**
36
+ * Manages undo/redo history for the image editor using action replay.
37
+ *
38
+ * Only action lists are stored — no intermediate blobs. Undo/redo replays
39
+ * all remaining actions from the source image, keeping memory usage minimal
40
+ * regardless of history depth. Only one blob is in memory at a time.
41
+ */
42
+ export function useImageHistory(sourceUrl: string, registry: ActionRegistry): UseImageHistoryResult {
43
+ let [history, setHistory] = useState<HistoryState>({ past: [], future: [] });
44
+ let [current, setCurrent] = useState<CurrentState>({ url: sourceUrl, blob: null, generated: false });
45
+ let [replaying, setReplaying] = useState(false);
46
+
47
+ let historyRef = useRef(history);
48
+ historyRef.current = history;
49
+ // Written synchronously by `replaceCurrent` so imperative callers can read the current
50
+ // image/blob before React has committed the corresponding render.
51
+ let currentRef = useRef(current);
52
+ let isReplaying = useRef(false);
53
+ let replayAbort = useRef<AbortController | null>(null);
54
+
55
+ function replaceCurrent(next: CurrentState) {
56
+ let prev = currentRef.current;
57
+ if (prev.generated && prev.url !== next.url) URL.revokeObjectURL(prev.url);
58
+ currentRef.current = next;
59
+ setCurrent(next);
60
+ }
61
+
62
+ // When source changes (e.g. component remount with new image), reset fully.
63
+ useEffect(() => {
64
+ replayAbort.current?.abort();
65
+ isReplaying.current = false;
66
+ setReplaying(false);
67
+ replaceCurrent({ url: sourceUrl, blob: null, generated: false });
68
+ setHistory({ past: [], future: [] });
69
+ }, [sourceUrl]);
70
+
71
+ useEffect(() => {
72
+ return () => {
73
+ if (currentRef.current.generated) URL.revokeObjectURL(currentRef.current.url);
74
+ replayAbort.current?.abort();
75
+ };
76
+ }, []);
77
+
78
+ function applyActions(blob: Blob, actions: EditAction[]) {
79
+ // A direct apply always takes priority — abort any in-flight replay.
80
+ replayAbort.current?.abort();
81
+ isReplaying.current = false;
82
+ setReplaying(false);
83
+
84
+ let newUrl = URL.createObjectURL(blob);
85
+ replaceCurrent({ url: newUrl, blob, generated: true });
86
+ setHistory((prev) => ({ past: [...prev.past, actions], future: [] }));
87
+
88
+ return newUrl;
89
+ }
90
+
91
+ async function doReplay(newPast: EditAction[][], newFuture: EditAction[][]) {
92
+ replayAbort.current?.abort();
93
+ let abort = new AbortController();
94
+ replayAbort.current = abort;
95
+ isReplaying.current = true;
96
+ setReplaying(true);
97
+
98
+ try {
99
+ let result = await replayAll(sourceUrl, newPast, registry, abort.signal);
100
+ if (abort.signal.aborted) return;
101
+
102
+ if (result) {
103
+ replaceCurrent({ url: result.url, blob: result.blob, generated: true });
104
+ } else {
105
+ replaceCurrent({ url: sourceUrl, blob: null, generated: false });
106
+ }
107
+ setHistory({ past: newPast, future: newFuture });
108
+ } finally {
109
+ if (!abort.signal.aborted) {
110
+ isReplaying.current = false;
111
+ setReplaying(false);
112
+ }
113
+ }
114
+ }
115
+
116
+ function undo() {
117
+ if (isReplaying.current) return;
118
+ let { past, future } = historyRef.current;
119
+ if (past.length === 0) return;
120
+ doReplay(past.slice(0, -1), [past.at(-1)!, ...future]);
121
+ }
122
+
123
+ function redo() {
124
+ if (isReplaying.current) return;
125
+ let { past, future } = historyRef.current;
126
+ if (future.length === 0) return;
127
+ doReplay([...past, future[0]], future.slice(1));
128
+ }
129
+
130
+ function reset() {
131
+ replayAbort.current?.abort();
132
+ isReplaying.current = false;
133
+ setReplaying(false);
134
+ replaceCurrent({ url: sourceUrl, blob: null, generated: false });
135
+ setHistory({ past: [], future: [] });
136
+ }
137
+
138
+ return {
139
+ currentImageUrl: current.url,
140
+ currentBlob: current.blob,
141
+ getCurrentImageUrl: () => currentRef.current.url,
142
+ getCurrentBlob: () => currentRef.current.blob,
143
+ canUndo: history.past.length > 0,
144
+ canRedo: history.future.length > 0,
145
+ replaying,
146
+ applyActions,
147
+ undo,
148
+ redo,
149
+ reset,
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Replays a sequence of action groups from a source URL.
155
+ * Intermediate object URLs are revoked as soon as a new step succeeds.
156
+ * Returns the final `{ url, blob }` or `null` if there were no actions.
157
+ */
158
+ async function replayAll(
159
+ sourceUrl: string,
160
+ actionGroups: EditAction[][],
161
+ registry: ActionRegistry,
162
+ signal: AbortSignal,
163
+ ): Promise<{ url: string; blob: Blob } | null> {
164
+ let prevUrl = sourceUrl;
165
+ let prevGenerated = false;
166
+ let lastBlob: Blob | null = null;
167
+
168
+ for (let group of actionGroups) {
169
+ for (let action of group) {
170
+ if (signal.aborted) {
171
+ if (prevGenerated) URL.revokeObjectURL(prevUrl);
172
+ return null;
173
+ }
174
+
175
+ let apply = registry.get(action.type);
176
+ if (!apply) {
177
+ console.warn(`[ImageHistory] No replay handler for action type "${action.type}" — skipping`);
178
+ continue;
179
+ }
180
+
181
+ let blob = await apply(prevUrl, action.params);
182
+
183
+ if (signal.aborted) {
184
+ if (prevGenerated) URL.revokeObjectURL(prevUrl);
185
+ return null;
186
+ }
187
+
188
+ if (prevGenerated) URL.revokeObjectURL(prevUrl);
189
+ lastBlob = blob;
190
+ prevUrl = URL.createObjectURL(blob);
191
+ prevGenerated = true;
192
+ }
193
+ }
194
+
195
+ if (!lastBlob || !prevGenerated) return null;
196
+ return { url: prevUrl, blob: lastBlob };
197
+ }