@olenbetong/synergi-react 3.2.2 → 4.1.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.
Files changed (157) hide show
  1. package/es/chrome/AppShell/index.d.ts +10 -2
  2. package/es/chrome/AppShell/index.js +13 -97
  3. package/es/chrome/openReport.d.ts +22 -0
  4. package/es/chrome/openReport.js +21 -0
  5. package/es/colorScheme.d.ts +4 -4
  6. package/es/components/DateNavigator/index.js +1 -1
  7. package/es/components/FilePond.js +1 -1
  8. package/es/components/ImageEditor/ImageEditor.js +1 -1
  9. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +1 -1
  10. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +1 -1
  11. package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +1 -1
  12. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
  13. package/es/components/MergeProgressDialog/index.js +1 -1
  14. package/es/components/Toolbar/index.d.ts +20 -11
  15. package/es/components/Toolbar/index.js +47 -6
  16. package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
  17. package/es/elements/ElementDamage/DescriptionInput.js +1 -1
  18. package/es/elements/ElementDamage/DuplicateDamage/DesktopView.js +1 -1
  19. package/es/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.js +1 -1
  20. package/es/elements/ElementDamage/DuplicateDamage/PhoneView.js +1 -1
  21. package/es/elements/ElementDamage/ElementNumberTextField.js +1 -1
  22. package/es/elements/ElementDamage/RegisterFix.js +1 -1
  23. package/es/elements/ElementDamage/SubmitButtons.js +1 -1
  24. package/es/elements/ElementDamage/TransportElementSelect.js +1 -1
  25. package/es/elements/ElementLookup.d.ts +7 -2
  26. package/es/elements/ElementLookup.js +5 -7
  27. package/es/elements/ElementLookupDialog/BarcodeScanner/decoder.d.ts +32 -0
  28. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.d.ts +28 -0
  29. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.js +81 -0
  30. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.d.ts +26 -0
  31. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.js +70 -0
  32. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.d.ts +20 -0
  33. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +69 -0
  34. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +103 -0
  35. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.d.ts +6 -0
  36. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.js +19 -0
  37. package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +14 -7
  38. package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +11 -7
  39. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.d.ts +14 -12
  40. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.js +223 -117
  41. package/es/elements/ElementLookupDialog/HIDScanner/index.js +1 -1
  42. package/es/elements/ElementLookupDialog/Manual/ManualForm.js +1 -1
  43. package/es/elements/ElementLookupDialog/index.d.ts +6 -0
  44. package/es/elements/ElementLookupDialog/index.js +3 -3
  45. package/es/elements/ElementLookupDialog/utils/Giai.js +1 -1
  46. package/es/elements/ProjectSelect.js +1 -1
  47. package/es/i18n.d.ts +6 -0
  48. package/es/i18n.js +10 -0
  49. package/es/index.d.ts +3 -4
  50. package/es/index.js +5 -4
  51. package/package.json +9 -8
  52. package/src/chrome/AppShell/index.tsx +13 -134
  53. package/src/chrome/openReport.ts +34 -0
  54. package/src/colorScheme.ts +4 -4
  55. package/src/components/DateNavigator/index.tsx +1 -1
  56. package/src/components/FilePond.tsx +1 -1
  57. package/src/components/ImageEditor/ImageEditor.tsx +1 -1
  58. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +1 -1
  59. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +1 -1
  60. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +1 -1
  61. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +1 -1
  62. package/src/components/MergeProgressDialog/index.tsx +1 -1
  63. package/src/components/Toolbar/index.tsx +65 -14
  64. package/src/elements/ElementDamage/DamageFormButtons.tsx +1 -1
  65. package/src/elements/ElementDamage/DescriptionInput.tsx +1 -1
  66. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +1 -1
  67. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +1 -1
  68. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +1 -1
  69. package/src/elements/ElementDamage/ElementNumberTextField.tsx +1 -1
  70. package/src/elements/ElementDamage/RegisterFix.tsx +1 -1
  71. package/src/elements/ElementDamage/SubmitButtons.tsx +1 -1
  72. package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
  73. package/src/elements/ElementLookup.tsx +13 -6
  74. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -0
  75. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -0
  76. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -0
  77. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -0
  78. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -0
  79. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -0
  80. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +30 -15
  81. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +247 -137
  82. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +1 -1
  83. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +1 -1
  84. package/src/elements/ElementLookupDialog/index.tsx +13 -5
  85. package/src/elements/ElementLookupDialog/utils/Giai.ts +1 -1
  86. package/src/elements/ProjectSelect.tsx +1 -1
  87. package/src/i18n.ts +13 -0
  88. package/src/index.ts +6 -37
  89. package/es/chrome/AppMenu/AppMenu.css +0 -648
  90. package/es/chrome/AppMenu/AppMenu.d.ts +0 -56
  91. package/es/chrome/AppMenu/AppMenu.js +0 -145
  92. package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +0 -2
  93. package/es/chrome/AppMenu/AppMenuColorScheme.js +0 -18
  94. package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +0 -18
  95. package/es/chrome/AppMenu/AppMenuFavoriteButton.js +0 -11
  96. package/es/chrome/AppMenu/AppMenuHeader.d.ts +0 -24
  97. package/es/chrome/AppMenu/AppMenuHeader.js +0 -18
  98. package/es/chrome/AppMenu/AppMenuList.d.ts +0 -18
  99. package/es/chrome/AppMenu/AppMenuList.js +0 -39
  100. package/es/chrome/AppMenu/AppMenuRail.d.ts +0 -26
  101. package/es/chrome/AppMenu/AppMenuRail.js +0 -30
  102. package/es/chrome/AppMenu/AppMenuToggle.d.ts +0 -15
  103. package/es/chrome/AppMenu/AppMenuToggle.js +0 -14
  104. package/es/chrome/AppMenu/AppMenuUserMenu.d.ts +0 -32
  105. package/es/chrome/AppMenu/AppMenuUserMenu.js +0 -110
  106. package/es/chrome/AppMenu/developerCategories.d.ts +0 -24
  107. package/es/chrome/AppMenu/developerCategories.js +0 -116
  108. package/es/chrome/AppMenu/icons.d.ts +0 -15
  109. package/es/chrome/AppMenu/icons.js +0 -13
  110. package/es/chrome/AppMenu/index.d.ts +0 -12
  111. package/es/chrome/AppMenu/index.js +0 -10
  112. package/es/chrome/AppMenu/menuEntries.d.ts +0 -51
  113. package/es/chrome/AppMenu/menuEntries.js +0 -93
  114. package/es/chrome/AppMenu/types.d.ts +0 -43
  115. package/es/chrome/AppMenu/useFavorites.d.ts +0 -13
  116. package/es/chrome/AppMenu/useFavorites.js +0 -28
  117. package/es/chrome/AppMenu/useRovingTabIndex.d.ts +0 -28
  118. package/es/chrome/AppMenu/useRovingTabIndex.js +0 -114
  119. package/es/chrome/AppMenu/useServiceWorkerUpdate.d.ts +0 -16
  120. package/es/chrome/AppMenu/useServiceWorkerUpdate.js +0 -62
  121. package/es/report/ReportLauncher.css +0 -147
  122. package/es/report/ReportLauncher.d.ts +0 -55
  123. package/es/report/ReportLauncher.js +0 -142
  124. package/es/report/ReportLauncher.test.js +0 -231
  125. package/es/report/ReportParameters.css +0 -29
  126. package/es/report/ReportParameters.d.ts +0 -46
  127. package/es/report/ReportParameters.js +0 -65
  128. package/es/report/ReportParameters.test.d.ts +0 -1
  129. package/es/report/ReportParameters.test.js +0 -84
  130. package/es/report/index.d.ts +0 -2
  131. package/es/report/index.js +0 -2
  132. package/src/chrome/AppMenu/AppMenu.css +0 -648
  133. package/src/chrome/AppMenu/AppMenu.tsx +0 -285
  134. package/src/chrome/AppMenu/AppMenuColorScheme.tsx +0 -41
  135. package/src/chrome/AppMenu/AppMenuFavoriteButton.tsx +0 -47
  136. package/src/chrome/AppMenu/AppMenuHeader.tsx +0 -79
  137. package/src/chrome/AppMenu/AppMenuList.tsx +0 -89
  138. package/src/chrome/AppMenu/AppMenuRail.tsx +0 -117
  139. package/src/chrome/AppMenu/AppMenuToggle.tsx +0 -51
  140. package/src/chrome/AppMenu/AppMenuUserMenu.tsx +0 -190
  141. package/src/chrome/AppMenu/developerCategories.ts +0 -142
  142. package/src/chrome/AppMenu/icons.tsx +0 -76
  143. package/src/chrome/AppMenu/index.ts +0 -17
  144. package/src/chrome/AppMenu/menuEntries.ts +0 -128
  145. package/src/chrome/AppMenu/types.ts +0 -45
  146. package/src/chrome/AppMenu/useFavorites.ts +0 -40
  147. package/src/chrome/AppMenu/useRovingTabIndex.ts +0 -130
  148. package/src/chrome/AppMenu/useServiceWorkerUpdate.ts +0 -68
  149. package/src/report/ReportLauncher.css +0 -147
  150. package/src/report/ReportLauncher.test.tsx +0 -281
  151. package/src/report/ReportLauncher.tsx +0 -420
  152. package/src/report/ReportParameters.css +0 -29
  153. package/src/report/ReportParameters.test.tsx +0 -133
  154. package/src/report/ReportParameters.tsx +0 -198
  155. package/src/report/index.ts +0 -2
  156. /package/es/{chrome/AppMenu/types.js → elements/ElementLookupDialog/BarcodeScanner/decoder.js} +0 -0
  157. /package/es/{report/ReportLauncher.test.d.ts → elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts} +0 -0
@@ -1,135 +1,241 @@
1
- import { getLocalizedString } from "@olenbetong/appframe-core";
2
- // import BarcodeReader from "dynamsoft-javascript-barcode";
3
1
  import { useEffect, useRef, useState } from "react";
4
- // (window as any).BarcodeReader = BarcodeReader;
5
- const { BarcodeReader } = window;
6
- export function useScanner(rootRef, canvasRef, onRead) {
7
- const [isLoading, setIsLoading] = useState(true);
8
- const [error, setError] = useState(null);
9
- const [rects, setRects] = useState([]);
10
- const [devices, setDevices] = useState({
11
- all: [],
12
- current: { deviceId: "", label: "" },
13
- width: 0,
14
- height: 0,
15
- });
16
- const currentDevice = useRef(null);
17
- const onReadRef = useRef(onRead);
18
- const scanner = useRef(null);
2
+ import { createZxingDecoder } from "./decoders/zxing";
3
+ import { createDuplicateFilter } from "./duplicateFilter";
4
+ import { getLocalizedString } from "../../../i18n.js";
5
+ /** Longest side of the frame handed to the decoder. Larger frames cost decode time without helping DataMatrix reads. */
6
+ const MAX_FRAME_SIDE = 720;
7
+ /** Minimum time between two decode attempts. */
8
+ const DECODE_INTERVAL = 100;
9
+ /** A code that stays in view is reported again only after it has been gone this long. */
10
+ const DUPLICATE_FORGET_TIME = 1000;
11
+ /** How long the highlight of a detected code stays on the overlay. */
12
+ const HIGHLIGHT_TIME = 300;
13
+ const CAMERA_ERROR_NAMES = [
14
+ "NotAllowedError",
15
+ "NotFoundError",
16
+ "NotReadableError",
17
+ "OverconstrainedError",
18
+ "SecurityError",
19
+ "AbortError",
20
+ "TypeError",
21
+ ];
22
+ const defaultDecoder = createZxingDecoder();
23
+ function videoConstraints(deviceId) {
24
+ let iPhone = /iPhone|iPad/.test(navigator.userAgent);
25
+ let size = iPhone ? 1280 : 720;
26
+ return {
27
+ audio: false,
28
+ video: {
29
+ width: { ideal: size },
30
+ height: { ideal: size },
31
+ ...(deviceId ? { deviceId: { exact: deviceId } } : { facingMode: { ideal: "environment" } }),
32
+ },
33
+ };
34
+ }
35
+ function scheduleFrame(video, callback) {
36
+ if ("requestVideoFrameCallback" in video) {
37
+ video.requestVideoFrameCallback((now) => callback(now));
38
+ }
39
+ else {
40
+ requestAnimationFrame(callback);
41
+ }
42
+ }
43
+ /**
44
+ * Drives the camera and the decode loop behind `BarcodeScanner`. The decoder is created from the
45
+ * factory and replaced whenever a different factory is passed, so callers must pass a stable
46
+ * reference (a module-level constant or a memoised value) and change it only to switch engine.
47
+ */
48
+ export function useScanner(videoRef, canvasRef, onRead, decoderFactory = defaultDecoder) {
49
+ let [isLoading, setIsLoading] = useState(true);
50
+ let [error, setError] = useState(null);
51
+ let [devices, setDevices] = useState([]);
52
+ let [deviceId, setDeviceId] = useState(null);
53
+ let [engine, setEngine] = useState(null);
54
+ let [highlights, setHighlights] = useState([]);
55
+ let onReadRef = useRef(onRead);
56
+ let decoderRef = useRef(null);
57
+ let currentDeviceId = useRef(null);
58
+ let highlightTimeout = useRef(null);
19
59
  useEffect(() => {
20
60
  onReadRef.current = onRead;
21
61
  }, [onRead]);
62
+ // Create the decoder; replaced when a different factory is passed.
22
63
  useEffect(() => {
23
- if (!rootRef.current)
24
- return;
25
- let cancel = false;
26
- const iPhone = /iPhone|iPad/.test(navigator.userAgent);
27
- scanner.current = new BarcodeReader.Scanner({
28
- duplicateForgetTime: 1000,
29
- htmlElement: rootRef.current,
30
- videoSettings: {
31
- video: {
32
- width: { ideal: iPhone ? 1280 : 720 },
33
- height: { ideal: iPhone ? 1280 : 720 },
34
- facingMode: { ideal: "environment" },
35
- },
36
- },
37
- runtimeSettings: {
38
- mBarcodeFormatIds: BarcodeReader.EnumBarcodeFormat.DATAMATRIX,
39
- mAntiDamageLevel: 3,
40
- mDeblurLevel: 0,
41
- },
42
- onFrameRead: (results) => {
43
- const newRects = [];
44
- for (let result of results) {
45
- newRects.push(result.LocalizationResult);
46
- }
47
- if (newRects.length > 0) {
48
- setRects((rects) => [...rects, ...newRects]);
49
- setTimeout(() => {
50
- if (!cancel) {
51
- setRects((rects) => rects.slice(newRects.length));
52
- }
53
- }, 300);
54
- }
55
- },
56
- onNewCodeRead: (txt) => {
57
- if (txt) {
58
- onReadRef.current(txt);
59
- }
60
- },
61
- });
62
- scanner.current
63
- .open()
64
- .then((videoDeviceInfo) => {
65
- if (cancel === false) {
66
- const { all, current } = videoDeviceInfo;
67
- currentDevice.current = 0;
68
- if (current?.deviceId) {
69
- for (let i = 0; i < all.length; i++) {
70
- if (all[i].deviceId === current.deviceId) {
71
- currentDevice.current = i;
72
- }
73
- }
74
- }
75
- setDevices(videoDeviceInfo);
76
- setIsLoading(false);
64
+ let cancelled = false;
65
+ let created = null;
66
+ setEngine(null);
67
+ setError(null);
68
+ decoderFactory()
69
+ .then((decoder) => {
70
+ if (cancelled) {
71
+ decoder.dispose?.();
72
+ return;
77
73
  }
74
+ created = decoder;
75
+ decoderRef.current = decoder;
76
+ setEngine(decoder.name);
78
77
  })
79
78
  .catch((ex) => {
80
- if (cancel === false) {
81
- let error = ex.message || ex;
82
- setIsLoading(false);
83
- if (/Webassembly/.test(error)) {
84
- setError({
85
- icon: "unsupported",
86
- message: getLocalizedString("Your browser is not supported. A browser that supports WebAssembly is required."),
87
- });
88
- }
89
- else if (/Permission/i.test(error) ||
90
- /video/i.test(error) ||
91
- /device/i.test(error) ||
92
- /Media/i.test(error) ||
93
- /agent/.test(error) ||
94
- /found/.test(error))
95
- setError({
96
- icon: "camera",
97
- message: getLocalizedString("No camera available"),
98
- });
99
- else {
100
- setError({ icon: "generic", message: error });
101
- }
79
+ if (cancelled)
80
+ return;
81
+ let message = ex instanceof Error ? ex.message : String(ex);
82
+ setIsLoading(false);
83
+ if (/WebAssembly/i.test(message)) {
84
+ setError({
85
+ icon: "unsupported",
86
+ message: getLocalizedString("Your browser is not supported. A browser that supports WebAssembly is required."),
87
+ });
88
+ }
89
+ else {
90
+ setError({ icon: "generic", message });
102
91
  }
103
92
  });
104
93
  return () => {
105
- cancel = true;
106
- if (scanner.current && typeof scanner.current.close === "function") {
107
- scanner.current.close();
108
- }
94
+ cancelled = true;
95
+ decoderRef.current = null;
96
+ created?.dispose?.();
109
97
  };
110
- }, [rootRef]);
98
+ }, [decoderFactory]);
99
+ // Start the camera and the decode loop; restarted when the user switches camera.
111
100
  useEffect(() => {
112
- if (canvasRef.current) {
113
- const ctx = canvasRef.current.getContext("2d");
114
- ctx.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
115
- ctx.fillStyle = "rgba(254,180,32,0.3)";
116
- const { width, height } = canvasRef.current;
117
- const xRatio = width / devices.width;
118
- const yRatio = height / devices.height;
119
- for (let rect of rects) {
120
- const { X1, X2, X3, X4, Y1, Y2, Y3, Y4 } = rect;
121
- ctx.beginPath();
122
- ctx.moveTo(X1 * xRatio, Y1 * yRatio);
123
- ctx.lineTo(X2 * xRatio, Y2 * yRatio);
124
- ctx.lineTo(X3 * xRatio, Y3 * yRatio);
125
- ctx.lineTo(X4 * xRatio, Y4 * yRatio);
126
- ctx.fill();
101
+ let video = videoRef.current;
102
+ if (!video)
103
+ return;
104
+ let cancelled = false;
105
+ let stream = null;
106
+ let frame = document.createElement("canvas");
107
+ let frameContext = frame.getContext("2d", { willReadFrequently: true });
108
+ let isNew = createDuplicateFilter(DUPLICATE_FORGET_TIME);
109
+ let busy = false;
110
+ let lastDecode = 0;
111
+ function showHighlights(corners) {
112
+ setHighlights(corners);
113
+ if (highlightTimeout.current)
114
+ clearTimeout(highlightTimeout.current);
115
+ highlightTimeout.current = setTimeout(() => {
116
+ if (!cancelled)
117
+ setHighlights([]);
118
+ }, HIGHLIGHT_TIME);
119
+ }
120
+ async function decodeCurrentFrame(now) {
121
+ let decoder = decoderRef.current;
122
+ if (!decoder || !frameContext || !video || video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
123
+ return;
124
+ let scale = Math.min(1, MAX_FRAME_SIDE / Math.max(video.videoWidth, video.videoHeight));
125
+ let width = Math.round(video.videoWidth * scale);
126
+ let height = Math.round(video.videoHeight * scale);
127
+ if (width === 0 || height === 0)
128
+ return;
129
+ if (frame.width !== width || frame.height !== height) {
130
+ frame.width = width;
131
+ frame.height = height;
127
132
  }
133
+ frameContext.drawImage(video, 0, 0, width, height);
134
+ let results = await decoder.decodeFrame(frame);
135
+ if (cancelled || results.length === 0)
136
+ return;
137
+ // Highlights are drawn on an overlay sized like the video, so scale them back up.
138
+ let inverse = 1 / scale;
139
+ showHighlights(results.map((result) => result.corners.map((point) => ({
140
+ x: point.x * inverse,
141
+ y: point.y * inverse,
142
+ }))));
143
+ for (let result of results) {
144
+ if (result.text && isNew(result.text, now)) {
145
+ onReadRef.current(result.text);
146
+ }
147
+ }
148
+ }
149
+ function tick(now) {
150
+ if (cancelled || !video)
151
+ return;
152
+ if (!busy && now - lastDecode >= DECODE_INTERVAL) {
153
+ busy = true;
154
+ lastDecode = now;
155
+ decodeCurrentFrame(now)
156
+ .catch((ex) => {
157
+ console.warn("Barcode decode failed", ex);
158
+ })
159
+ .finally(() => {
160
+ busy = false;
161
+ });
162
+ }
163
+ scheduleFrame(video, tick);
164
+ }
165
+ async function start() {
166
+ if (!navigator.mediaDevices?.getUserMedia) {
167
+ throw new DOMException("Camera access is not available", "NotFoundError");
168
+ }
169
+ stream = await navigator.mediaDevices.getUserMedia(videoConstraints(deviceId));
170
+ if (cancelled || !video)
171
+ return;
172
+ video.srcObject = stream;
173
+ await video.play();
174
+ if (cancelled)
175
+ return;
176
+ let overlay = canvasRef.current;
177
+ if (overlay) {
178
+ overlay.width = video.videoWidth;
179
+ overlay.height = video.videoHeight;
180
+ }
181
+ currentDeviceId.current = stream.getVideoTracks()[0]?.getSettings().deviceId ?? deviceId;
182
+ // Labels and the full device list are only available once permission has been granted.
183
+ let all = await navigator.mediaDevices.enumerateDevices();
184
+ if (cancelled)
185
+ return;
186
+ setDevices(all.filter((device) => device.kind === "videoinput"));
187
+ setIsLoading(false);
188
+ scheduleFrame(video, tick);
189
+ }
190
+ start().catch((ex) => {
191
+ if (cancelled)
192
+ return;
193
+ setIsLoading(false);
194
+ let name = ex instanceof DOMException || ex instanceof Error ? ex.name : "";
195
+ let message = ex instanceof Error ? ex.message : String(ex);
196
+ if (CAMERA_ERROR_NAMES.includes(name) || /camera|video|device|media/i.test(message)) {
197
+ setError({ icon: "camera", message: getLocalizedString("No camera available") });
198
+ }
199
+ else {
200
+ setError({ icon: "generic", message });
201
+ }
202
+ });
203
+ return () => {
204
+ cancelled = true;
205
+ if (highlightTimeout.current)
206
+ clearTimeout(highlightTimeout.current);
207
+ stream?.getTracks().forEach((track) => track.stop());
208
+ if (video)
209
+ video.srcObject = null;
210
+ };
211
+ }, [videoRef, canvasRef, deviceId]);
212
+ // Draw the highlights of detected codes on the overlay canvas.
213
+ useEffect(() => {
214
+ let overlay = canvasRef.current;
215
+ if (!overlay)
216
+ return;
217
+ let context = overlay.getContext("2d");
218
+ if (!context)
219
+ return;
220
+ context.clearRect(0, 0, overlay.width, overlay.height);
221
+ context.fillStyle = "rgba(254,180,32,0.3)";
222
+ for (let corners of highlights) {
223
+ context.beginPath();
224
+ context.moveTo(corners[0].x, corners[0].y);
225
+ context.lineTo(corners[1].x, corners[1].y);
226
+ context.lineTo(corners[2].x, corners[2].y);
227
+ context.lineTo(corners[3].x, corners[3].y);
228
+ context.closePath();
229
+ context.fill();
128
230
  }
129
- }, [devices, canvasRef, rects]);
231
+ }, [canvasRef, highlights]);
130
232
  function setNextDevice() {
131
- currentDevice.current = ((currentDevice.current ?? 0) + 1) % devices.all.length;
132
- scanner.current?.play(devices.all[currentDevice.current].deviceId);
233
+ if (devices.length <= 1)
234
+ return;
235
+ let index = devices.findIndex((device) => device.deviceId === currentDeviceId.current);
236
+ let next = devices[(index + 1) % devices.length];
237
+ if (next)
238
+ setDeviceId(next.deviceId);
133
239
  }
134
- return { devices: devices.all, error, isLoading, setNextDevice };
240
+ return { devices, engine, error, isLoading, setNextDevice };
135
241
  }
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import "./index.css";
3
3
  import { Box, Button } from "@mui/material";
4
- import { getLocalizedString } from "@olenbetong/appframe-core";
5
4
  import { useEffect, useRef, useState } from "react";
6
5
  import { useHIDScanner } from "./useHIDScanner";
6
+ import { getLocalizedString } from "../../../i18n.js";
7
7
  export function AddElementHIDScanner({ onScan }) {
8
8
  let [enabled, setEnabled] = useState(false);
9
9
  let root = useRef(null);
@@ -1,10 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import Add from "@mui/icons-material/Add";
3
3
  import { Alert, Button, TextField } from "@mui/material";
4
- import { getLocalizedString } from "@olenbetong/appframe-core";
5
4
  import { useId, useRef, useState } from "react";
6
5
  import { ProjectSelect } from "../../ProjectSelect";
7
6
  import { getElement } from "../getElement";
7
+ import { getLocalizedString } from "../../../i18n.js";
8
8
  const isElementsOnly = /^([a-z]{2,4}[\s]*[0-9]{4,8}[\s,]*)+$/i;
9
9
  const matchElements = /([a-z]{2,4}[\s]*[0-9]{4,8})/gi;
10
10
  export function AddElementManualForm({ onAdd, mode, defaultProject, allowEmptyElement = false, }) {
@@ -1,3 +1,5 @@
1
+ import { type ReactNode } from "react";
2
+ import { type DecoderFactory } from "./BarcodeScanner";
1
3
  import { type AddElementSource, type ElementDetails } from "./getElement";
2
4
  export type AddElement = {
3
5
  element: ElementDetails;
@@ -11,6 +13,10 @@ export type ElementLookupDialogSharedProps = {
11
13
  initialTab?: InitialTabProps | null;
12
14
  useSearch?: boolean;
13
15
  allowEmptyElement?: boolean;
16
+ /** Engine for the camera tab. Defaults to zxing-wasm. */
17
+ decoder?: DecoderFactory;
18
+ /** Extra controls in the camera tab footer, e.g. an engine picker. */
19
+ scannerActions?: ReactNode;
14
20
  };
15
21
  export type ElementLookupDialogSingleModeProps = ElementLookupDialogSharedProps & {
16
22
  mode: "single" | "search";
@@ -5,7 +5,6 @@ import Edit from "@mui/icons-material/Edit";
5
5
  import QrCodeScanner from "@mui/icons-material/QrCodeScanner";
6
6
  import TapAndPlay from "@mui/icons-material/TapAndPlay";
7
7
  import { Alert, Box, Button, DialogActions, List, ListItem, ListItemText, Tab, Tabs } from "@mui/material";
8
- import { getLocalizedString, localize } from "@olenbetong/appframe-core";
9
8
  import { ResponsiveDialog } from "@olenbetong/appframe-mui";
10
9
  import { useEffect, useState } from "react";
11
10
  import { flushSync } from "react-dom";
@@ -15,8 +14,9 @@ import { AddElementHIDScanner } from "./HIDScanner";
15
14
  import { AddElementManualForm } from "./Manual/ManualForm";
16
15
  import { useBeeper } from "./utils/beep";
17
16
  import Giai from "./utils/Giai";
17
+ import { getLocalizedString, localize } from "../../i18n.js";
18
18
  export function ElementLookupDialog(props) {
19
- let { open, onClose, initialTab } = props;
19
+ let { open, onClose, initialTab, decoder, scannerActions } = props;
20
20
  let [tab, setTab] = useState("camera");
21
21
  let [elements, setElements] = useState([]);
22
22
  let [adding, setAdding] = useState(false);
@@ -72,7 +72,7 @@ export function ElementLookupDialog(props) {
72
72
  }
73
73
  return (_jsx(ResponsiveDialog, { open: open, onClose: onClose, slotProps: {
74
74
  paper: { sx: { overflow: "hidden" } },
75
- }, children: _jsxs(Box, { sx: { display: "flex", flexDirection: "column", maxHeight: "100%", overflow: "hidden", flexGrow: 1 }, children: [_jsxs(Tabs, { value: tab, onChange: (_, newTab) => setTab(newTab), variant: "fullWidth", sx: { flexShrink: 0 }, children: [props.mode !== "search" && _jsx(Tab, { icon: _jsx(Edit, {}), label: getLocalizedString("Manual"), value: "manual" }), _jsx(Tab, { icon: _jsx(TapAndPlay, {}), label: getLocalizedString("Scanner"), value: "scanner" }), _jsx(Tab, { icon: _jsx(QrCodeScanner, {}), label: getLocalizedString("Camera"), value: "camera" })] }), tab === "camera" && (_jsx(Box, { sx: { flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }, children: _jsx(BarcodeScanner, { onRead: (element) => handleElementAdd(element, "camera-barcode") }) })), tab === "manual" && (_jsx(Box, { sx: { p: 2 }, children: _jsx(AddElementManualForm, { onAdd: (element) => handleElementAdd(element, "manual"), allowEmptyElement: props.allowEmptyElement }) })), tab === "scanner" && (_jsx(Box, { sx: { flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }, children: _jsx(AddElementHIDScanner, { onScan: (element) => handleElementAdd(element, element.startsWith(Giai.BARCODE_PREFIX) ? "hid-barcode" : "hid-rfid") }) })), _jsxs(Box, { sx: { flex: "3 1 14rem", overflow: "auto" }, children: [props.mode === "multi" && (_jsx(Alert, { icon: false, severity: "info", sx: { justifyContent: "center", py: 0, position: "sticky", top: 0, zIndex: 1 }, slotProps: {
75
+ }, children: _jsxs(Box, { sx: { display: "flex", flexDirection: "column", maxHeight: "100%", overflow: "hidden", flexGrow: 1 }, children: [_jsxs(Tabs, { value: tab, onChange: (_, newTab) => setTab(newTab), variant: "fullWidth", sx: { flexShrink: 0 }, children: [props.mode !== "search" && _jsx(Tab, { icon: _jsx(Edit, {}), label: getLocalizedString("Manual"), value: "manual" }), _jsx(Tab, { icon: _jsx(TapAndPlay, {}), label: getLocalizedString("Scanner"), value: "scanner" }), _jsx(Tab, { icon: _jsx(QrCodeScanner, {}), label: getLocalizedString("Camera"), value: "camera" })] }), tab === "camera" && (_jsx(Box, { sx: { flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }, children: _jsx(BarcodeScanner, { decoder: decoder, actions: scannerActions, onRead: (element) => handleElementAdd(element, "camera-barcode") }) })), tab === "manual" && (_jsx(Box, { sx: { p: 2 }, children: _jsx(AddElementManualForm, { onAdd: (element) => handleElementAdd(element, "manual"), allowEmptyElement: props.allowEmptyElement }) })), tab === "scanner" && (_jsx(Box, { sx: { flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }, children: _jsx(AddElementHIDScanner, { onScan: (element) => handleElementAdd(element, element.startsWith(Giai.BARCODE_PREFIX) ? "hid-barcode" : "hid-rfid") }) })), _jsxs(Box, { sx: { flex: "3 1 14rem", overflow: "auto" }, children: [props.mode === "multi" && (_jsx(Alert, { icon: false, severity: "info", sx: { justifyContent: "center", py: 0, position: "sticky", top: 0, zIndex: 1 }, slotProps: {
76
76
  message: { sx: { py: 0.5 } },
77
77
  }, children: localize `${elements.length} elements selected` })), _jsx(List, { disablePadding: true, children: elements.map(({ element }) => (_jsx(ListItem, { "data-elementid": element.ElementID, secondaryAction: _jsx(Button, { color: "error", variant: "outlined", onClick: () => {
78
78
  setElements((current) => props.mode === "multi" ? current.filter((e) => e.element.ElementID !== element.ElementID) : []);
@@ -1,4 +1,4 @@
1
- import { getLocalizedString } from "@olenbetong/appframe-core";
1
+ import { getLocalizedString } from "../../../i18n.js";
2
2
  /**
3
3
  * GIAI-96 encoder and decoder as defined by the GS1 EPC Tag data standard
4
4
  */
@@ -1,10 +1,10 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Autocomplete, ListItem, ListItemText, TextField } from "@mui/material";
3
- import { getLocalizedString } from "@olenbetong/appframe-core";
4
3
  import { useDataWithFilter, useDebounce } from "@olenbetong/appframe-react";
5
4
  import { useMemo, useRef, useState } from "react";
6
5
  import { dsProjects } from "./data/dsProjects";
7
6
  import { dsReportProjects } from "./data/dsReportProjects";
7
+ import { getLocalizedString } from "../i18n.js";
8
8
  export function ProjectSelect({ className, disabled, id, names, onChange, readOnly, required, defaultValue, value, label, sx, report, }) {
9
9
  let [selected, setSelected] = useState(defaultValue ?? null);
10
10
  let [query, setQuery] = useState("");
package/es/i18n.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export declare const PROJECT = "synergi-react";
2
+ export declare const getLocalizedString: {
3
+ (string: undefined | null): undefined | null;
4
+ (string: string): string;
5
+ (string: string, wait: true): Promise<string>;
6
+ }, localize: (stringParts: TemplateStringsArray, ...args: unknown[]) => string;
package/es/i18n.js ADDED
@@ -0,0 +1,10 @@
1
+ /*
2
+ * The package's strings live in their own globalization project, `synergi-react`, so one
3
+ * translation covers every app and the package can word a term its own way. The templates
4
+ * render the dictionary as af.i18n["synergi-react"]; on a page that does not (a legacy
5
+ * template) the localizer falls back to the article's strings, exactly as before. See
6
+ * `createLocalizer` in @olenbetong/appframe-core.
7
+ */
8
+ import { createLocalizer } from "@olenbetong/appframe-core";
9
+ export const PROJECT = "synergi-react";
10
+ export const { getLocalizedString, localize } = createLocalizer(PROJECT);
package/es/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { AppMenu, type AppMenuArticle, type AppMenuCategory, AppMenuColorScheme, AppMenuFavoriteButton, type AppMenuFavoriteButtonProps, AppMenuHeader, type AppMenuHeaderProps, type AppMenuLink, type AppMenuLinkGroup, AppMenuList, type AppMenuListProps, type AppMenuProps, AppMenuRail, type AppMenuRailProps, type AppMenuSelection, AppMenuToggle, type AppMenuToggleProps, type AppMenuUser, AppMenuUserMenu, type AppMenuUserMenuProps, createDeveloperCategories, defaultUserMenuItems, type DeveloperCategoryOptions, useServiceWorkerUpdate, } from "./chrome/AppMenu/index.js";
2
- export { AppShell, type AppShellProps } from "./chrome/AppShell/index.js";
1
+ export { AppShell, type AppShellProps, hasSiteChrome } from "./chrome/AppShell/index.js";
3
2
  export { Checkbox, type CheckboxProps } from "./components/Checkbox/index.js";
4
3
  export { COLOR_SCHEME_CHANGE_EVENT, type ColorSchemePreference, getColorSchemePreference, setColorSchemePreference, useColorSchemePreference, } from "./colorScheme.js";
5
4
  export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
@@ -9,10 +8,10 @@ export * from "./components/ImageEditor/index.js";
9
8
  export { ChipListInput, type ChipListInputProps, FilterBuilder, type FilterBuilderProps, FilterEditor, type FilterEditorProps, type FilterEditorSize, FilterGroupEditor, type FilterGroupEditorProps, FilterNameDialog, type FilterNameDialogProps, FilterRow, type FilterRowProps, FilterShareDialog, type FilterShareDialogProps, FilterStringField, type FilterStringFieldProps, FilterValueEditor, type FilterValueEditorProps, type FilterValueOption, type GetFieldOptions, type SavedFilterSelection, type SavedFilterValues, SavedFilterTree, type SavedFilterTreeProps, } from "./filter/index.js";
10
9
  export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
11
10
  export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
12
- export { ReportLauncher, type ReportLauncherProps, type ReportLauncherTab, ReportParameterField, ReportParameters, type ReportParametersProps, } from "./report/index.js";
11
+ export { type OpenReportOptions, openReport } from "./chrome/openReport.js";
13
12
  export { BannerImage as PageBannerImage, type BannerImageProps, PageBanner, type PageBannerProps, Tab as PageBannerTab, TabList as PageBannerTabList, type TabListProps as PageBannerTabListProps, type TabProps as PageBannerTabProps, Title as PageBannerTitle, type TitleProps as PageBannerTitleProps, } from "./components/PageBanner/index.js";
14
13
  export { Portal } from "./components/Portal/index.js";
15
- export { ToolbarBreadcrumbs, ToolbarPortal, type BreadcrumbItem, type ToolbarBreadcrumbsProps, type ToolbarPortalProps, type ToolbarPortalSlot, } from "./components/Toolbar/index.js";
14
+ export { ToolbarBreadcrumbs, ToolbarDrawerToggle, ToolbarPortal, type BreadcrumbItem, type ToolbarBreadcrumbsProps, type ToolbarDrawerToggleProps, type ToolbarPortalProps, } from "./components/Toolbar/index.js";
16
15
  export { ProgressBar } from "./components/ProgressBar/index.js";
17
16
  export { Sidebar, type SidebarProps } from "./components/Sidebar/index.js";
18
17
  export { Spinner, type SpinnerProps } from "./components/Spinner/index.js";
package/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { AppMenu, AppMenuColorScheme, AppMenuFavoriteButton, AppMenuHeader, AppMenuList, AppMenuRail, AppMenuToggle, AppMenuUserMenu, createDeveloperCategories, defaultUserMenuItems, useServiceWorkerUpdate, } from "./chrome/AppMenu/index.js";
2
- export { AppShell } from "./chrome/AppShell/index.js";
1
+ // The app menu and the rest of the site chrome live in @olenbetong/synergi-chrome,
2
+ // loaded once per page by the site template rather than bundled into every app.
3
+ export { AppShell, hasSiteChrome } from "./chrome/AppShell/index.js";
3
4
  export { Checkbox } from "./components/Checkbox/index.js";
4
5
  export { COLOR_SCHEME_CHANGE_EVENT, getColorSchemePreference, setColorSchemePreference, useColorSchemePreference, } from "./colorScheme.js";
5
6
  export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard } from "./components/ColorCard/index.js";
@@ -9,14 +10,14 @@ export * from "./components/ImageEditor/index.js";
9
10
  export { ChipListInput, FilterBuilder, FilterEditor, FilterGroupEditor, FilterNameDialog, FilterRow, FilterShareDialog, FilterStringField, FilterValueEditor, SavedFilterTree, } from "./filter/index.js";
10
11
  export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
11
12
  export { MergeProgressDialog } from "./components/MergeProgressDialog/index.js";
12
- export { ReportLauncher, ReportParameterField, ReportParameters, } from "./report/index.js";
13
+ export { openReport } from "./chrome/openReport.js";
13
14
  export { BannerImage as PageBannerImage, PageBanner, Tab as PageBannerTab, TabList as PageBannerTabList, Title as PageBannerTitle, } from "./components/PageBanner/index.js";
14
15
  // PdfViewer is intentionally not re-exported here. It references the pdf.js worker
15
16
  // with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
16
17
  // asset for every app that touches this barrel, even when no PDF is ever rendered.
17
18
  // Import it from "@olenbetong/synergi-react/pdf" instead.
18
19
  export { Portal } from "./components/Portal/index.js";
19
- export { ToolbarBreadcrumbs, ToolbarPortal, } from "./components/Toolbar/index.js";
20
+ export { ToolbarBreadcrumbs, ToolbarDrawerToggle, ToolbarPortal, } from "./components/Toolbar/index.js";
20
21
  export { ProgressBar } from "./components/ProgressBar/index.js";
21
22
  export { Sidebar } from "./components/Sidebar/index.js";
22
23
  export { Spinner } from "./components/Spinner/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/synergi-react",
3
- "version": "3.2.2",
3
+ "version": "4.1.0",
4
4
  "description": "Standalone React component for SynergiWeb and Partner Portal",
5
5
  "type": "module",
6
6
  "exports": {
@@ -40,7 +40,6 @@
40
40
  "@mui/icons-material": "9.4.0",
41
41
  "@mui/material": "9.4.0",
42
42
  "clsx": "^2.1.1",
43
- "dynamsoft-javascript-barcode": "6.5.4",
44
43
  "filepond": "^4.32.12",
45
44
  "filepond-plugin-file-poster": "^2.5.2",
46
45
  "filepond-plugin-image-exif-orientation": "^1.0.11",
@@ -54,11 +53,12 @@
54
53
  "react": "19.3.0",
55
54
  "react-dom": "19.3.0",
56
55
  "react-pdf": "^10.5.0",
57
- "@olenbetong/appframe-core": "2.13.1",
58
- "@olenbetong/appframe-data": "1.7.1",
59
- "@olenbetong/appframe-mui": "7.0.2",
60
- "@olenbetong/appframe-react": "2.2.0",
61
- "@olenbetong/appframe-ds": "1.0.2"
56
+ "zxing-wasm": "3.1.4",
57
+ "@olenbetong/appframe-core": "2.14.0",
58
+ "@olenbetong/appframe-data": "1.7.2",
59
+ "@olenbetong/appframe-mui": "7.0.3",
60
+ "@olenbetong/appframe-react": "2.2.1",
61
+ "@olenbetong/appframe-ds": "1.1.0"
62
62
  },
63
63
  "repository": {
64
64
  "type": "git",
@@ -74,10 +74,11 @@
74
74
  "devDependencies": {
75
75
  "@digdir/designsystemet-react": "1.21.1",
76
76
  "@navikt/aksel-icons": "8.16.2",
77
- "@testing-library/jest-dom": "^7.0.1",
78
77
  "@testing-library/dom": "^10.4.1",
78
+ "@testing-library/jest-dom": "^7.0.1",
79
79
  "@testing-library/react": "16.3.3",
80
80
  "@testing-library/user-event": "^14.6.7",
81
+ "dynamsoft-javascript-barcode": "6.5.4",
81
82
  "happy-dom": "20.14.5",
82
83
  "replace-in-files": "^3.0.0"
83
84
  },