@olenbetong/synergi-react 3.2.2 → 4.0.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 (112) 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/Toolbar/index.d.ts +20 -11
  7. package/es/components/Toolbar/index.js +47 -6
  8. package/es/elements/ElementLookup.d.ts +7 -2
  9. package/es/elements/ElementLookup.js +4 -6
  10. package/es/elements/ElementLookupDialog/BarcodeScanner/decoder.d.ts +32 -0
  11. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.d.ts +28 -0
  12. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.js +81 -0
  13. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.d.ts +26 -0
  14. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/native.js +70 -0
  15. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.d.ts +20 -0
  16. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +69 -0
  17. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +103 -0
  18. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.d.ts +6 -0
  19. package/es/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.js +19 -0
  20. package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +14 -7
  21. package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +10 -6
  22. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.d.ts +14 -12
  23. package/es/elements/ElementLookupDialog/BarcodeScanner/useScanner.js +222 -116
  24. package/es/elements/ElementLookupDialog/index.d.ts +6 -0
  25. package/es/elements/ElementLookupDialog/index.js +2 -2
  26. package/es/index.d.ts +3 -4
  27. package/es/index.js +5 -4
  28. package/package.json +9 -8
  29. package/src/chrome/AppShell/index.tsx +13 -134
  30. package/src/chrome/openReport.ts +34 -0
  31. package/src/colorScheme.ts +4 -4
  32. package/src/components/Toolbar/index.tsx +65 -14
  33. package/src/elements/ElementLookup.tsx +12 -5
  34. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -0
  35. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -0
  36. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -0
  37. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -0
  38. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -0
  39. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -0
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +29 -14
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +246 -136
  42. package/src/elements/ElementLookupDialog/index.tsx +12 -4
  43. package/src/index.ts +6 -37
  44. package/es/chrome/AppMenu/AppMenu.css +0 -648
  45. package/es/chrome/AppMenu/AppMenu.d.ts +0 -56
  46. package/es/chrome/AppMenu/AppMenu.js +0 -145
  47. package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +0 -2
  48. package/es/chrome/AppMenu/AppMenuColorScheme.js +0 -18
  49. package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +0 -18
  50. package/es/chrome/AppMenu/AppMenuFavoriteButton.js +0 -11
  51. package/es/chrome/AppMenu/AppMenuHeader.d.ts +0 -24
  52. package/es/chrome/AppMenu/AppMenuHeader.js +0 -18
  53. package/es/chrome/AppMenu/AppMenuList.d.ts +0 -18
  54. package/es/chrome/AppMenu/AppMenuList.js +0 -39
  55. package/es/chrome/AppMenu/AppMenuRail.d.ts +0 -26
  56. package/es/chrome/AppMenu/AppMenuRail.js +0 -30
  57. package/es/chrome/AppMenu/AppMenuToggle.d.ts +0 -15
  58. package/es/chrome/AppMenu/AppMenuToggle.js +0 -14
  59. package/es/chrome/AppMenu/AppMenuUserMenu.d.ts +0 -32
  60. package/es/chrome/AppMenu/AppMenuUserMenu.js +0 -110
  61. package/es/chrome/AppMenu/developerCategories.d.ts +0 -24
  62. package/es/chrome/AppMenu/developerCategories.js +0 -116
  63. package/es/chrome/AppMenu/icons.d.ts +0 -15
  64. package/es/chrome/AppMenu/icons.js +0 -13
  65. package/es/chrome/AppMenu/index.d.ts +0 -12
  66. package/es/chrome/AppMenu/index.js +0 -10
  67. package/es/chrome/AppMenu/menuEntries.d.ts +0 -51
  68. package/es/chrome/AppMenu/menuEntries.js +0 -93
  69. package/es/chrome/AppMenu/types.d.ts +0 -43
  70. package/es/chrome/AppMenu/useFavorites.d.ts +0 -13
  71. package/es/chrome/AppMenu/useFavorites.js +0 -28
  72. package/es/chrome/AppMenu/useRovingTabIndex.d.ts +0 -28
  73. package/es/chrome/AppMenu/useRovingTabIndex.js +0 -114
  74. package/es/chrome/AppMenu/useServiceWorkerUpdate.d.ts +0 -16
  75. package/es/chrome/AppMenu/useServiceWorkerUpdate.js +0 -62
  76. package/es/report/ReportLauncher.css +0 -147
  77. package/es/report/ReportLauncher.d.ts +0 -55
  78. package/es/report/ReportLauncher.js +0 -142
  79. package/es/report/ReportLauncher.test.js +0 -231
  80. package/es/report/ReportParameters.css +0 -29
  81. package/es/report/ReportParameters.d.ts +0 -46
  82. package/es/report/ReportParameters.js +0 -65
  83. package/es/report/ReportParameters.test.d.ts +0 -1
  84. package/es/report/ReportParameters.test.js +0 -84
  85. package/es/report/index.d.ts +0 -2
  86. package/es/report/index.js +0 -2
  87. package/src/chrome/AppMenu/AppMenu.css +0 -648
  88. package/src/chrome/AppMenu/AppMenu.tsx +0 -285
  89. package/src/chrome/AppMenu/AppMenuColorScheme.tsx +0 -41
  90. package/src/chrome/AppMenu/AppMenuFavoriteButton.tsx +0 -47
  91. package/src/chrome/AppMenu/AppMenuHeader.tsx +0 -79
  92. package/src/chrome/AppMenu/AppMenuList.tsx +0 -89
  93. package/src/chrome/AppMenu/AppMenuRail.tsx +0 -117
  94. package/src/chrome/AppMenu/AppMenuToggle.tsx +0 -51
  95. package/src/chrome/AppMenu/AppMenuUserMenu.tsx +0 -190
  96. package/src/chrome/AppMenu/developerCategories.ts +0 -142
  97. package/src/chrome/AppMenu/icons.tsx +0 -76
  98. package/src/chrome/AppMenu/index.ts +0 -17
  99. package/src/chrome/AppMenu/menuEntries.ts +0 -128
  100. package/src/chrome/AppMenu/types.ts +0 -45
  101. package/src/chrome/AppMenu/useFavorites.ts +0 -40
  102. package/src/chrome/AppMenu/useRovingTabIndex.ts +0 -130
  103. package/src/chrome/AppMenu/useServiceWorkerUpdate.ts +0 -68
  104. package/src/report/ReportLauncher.css +0 -147
  105. package/src/report/ReportLauncher.test.tsx +0 -281
  106. package/src/report/ReportLauncher.tsx +0 -420
  107. package/src/report/ReportParameters.css +0 -29
  108. package/src/report/ReportParameters.test.tsx +0 -133
  109. package/src/report/ReportParameters.tsx +0 -198
  110. package/src/report/index.ts +0 -2
  111. /package/es/{chrome/AppMenu/types.js → elements/ElementLookupDialog/BarcodeScanner/decoder.js} +0 -0
  112. /package/es/{report/ReportLauncher.test.d.ts → elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts} +0 -0
@@ -1,170 +1,280 @@
1
1
  import { getLocalizedString } from "@olenbetong/appframe-core";
2
-
3
- import type BarcodeReaderType from "dynamsoft-javascript-barcode";
4
- // import BarcodeReader from "dynamsoft-javascript-barcode";
5
2
  import { type RefObject, useEffect, useRef, useState } from "react";
3
+ import type { BarcodeDecoder, DecodedBarcode, DecoderFactory } from "./decoder";
4
+ import { createZxingDecoder } from "./decoders/zxing";
5
+ import { createDuplicateFilter } from "./duplicateFilter";
6
6
 
7
- declare global {
8
- interface Window {
9
- BarcodeReader: typeof BarcodeReaderType;
10
- }
7
+ export type ScannerError = { message: string; icon: "unsupported" | "camera" | "generic" };
8
+
9
+ /** Longest side of the frame handed to the decoder. Larger frames cost decode time without helping DataMatrix reads. */
10
+ const MAX_FRAME_SIDE = 720;
11
+ /** Minimum time between two decode attempts. */
12
+ const DECODE_INTERVAL = 100;
13
+ /** A code that stays in view is reported again only after it has been gone this long. */
14
+ const DUPLICATE_FORGET_TIME = 1000;
15
+ /** How long the highlight of a detected code stays on the overlay. */
16
+ const HIGHLIGHT_TIME = 300;
17
+
18
+ const CAMERA_ERROR_NAMES = [
19
+ "NotAllowedError",
20
+ "NotFoundError",
21
+ "NotReadableError",
22
+ "OverconstrainedError",
23
+ "SecurityError",
24
+ "AbortError",
25
+ "TypeError",
26
+ ];
27
+
28
+ const defaultDecoder = createZxingDecoder();
29
+
30
+ function videoConstraints(deviceId: string | null): MediaStreamConstraints {
31
+ let iPhone = /iPhone|iPad/.test(navigator.userAgent);
32
+ let size = iPhone ? 1280 : 720;
33
+
34
+ return {
35
+ audio: false,
36
+ video: {
37
+ width: { ideal: size },
38
+ height: { ideal: size },
39
+ ...(deviceId ? { deviceId: { exact: deviceId } } : { facingMode: { ideal: "environment" } }),
40
+ },
41
+ };
11
42
  }
12
43
 
13
- // (window as any).BarcodeReader = BarcodeReader;
14
- const { BarcodeReader } = window;
44
+ function scheduleFrame(video: HTMLVideoElement, callback: (now: number) => void) {
45
+ if ("requestVideoFrameCallback" in video) {
46
+ video.requestVideoFrameCallback((now) => callback(now));
47
+ } else {
48
+ requestAnimationFrame(callback);
49
+ }
50
+ }
15
51
 
52
+ /**
53
+ * Drives the camera and the decode loop behind `BarcodeScanner`. The decoder is created from the
54
+ * factory and replaced whenever a different factory is passed, so callers must pass a stable
55
+ * reference (a module-level constant or a memoised value) and change it only to switch engine.
56
+ */
16
57
  export function useScanner(
17
- rootRef: RefObject<HTMLElement | null>,
58
+ videoRef: RefObject<HTMLVideoElement | null>,
18
59
  canvasRef: RefObject<HTMLCanvasElement | null>,
19
60
  onRead: (barcode: string) => void,
61
+ decoderFactory: DecoderFactory = defaultDecoder,
20
62
  ) {
21
- const [isLoading, setIsLoading] = useState(true);
22
- const [error, setError] = useState<{ message: string; icon: string } | null>(null);
23
- const [rects, setRects] = useState<Array<BarcodeReaderType.LocalizationResult>>([]);
24
- const [devices, setDevices] = useState<BarcodeReaderType.ScannerOpenCallbackInfo>({
25
- all: [],
26
- current: { deviceId: "", label: "" },
27
- width: 0,
28
- height: 0,
29
- });
30
- const currentDevice = useRef<number>(null);
31
- const onReadRef = useRef(onRead);
32
- const scanner = useRef<BarcodeReaderType.Scanner>(null);
63
+ let [isLoading, setIsLoading] = useState(true);
64
+ let [error, setError] = useState<ScannerError | null>(null);
65
+ let [devices, setDevices] = useState<MediaDeviceInfo[]>([]);
66
+ let [deviceId, setDeviceId] = useState<string | null>(null);
67
+ let [engine, setEngine] = useState<string | null>(null);
68
+ let [highlights, setHighlights] = useState<Array<DecodedBarcode["corners"]>>([]);
69
+
70
+ let onReadRef = useRef(onRead);
71
+ let decoderRef = useRef<BarcodeDecoder | null>(null);
72
+ let currentDeviceId = useRef<string | null>(null);
73
+ let highlightTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
33
74
 
34
75
  useEffect(() => {
35
76
  onReadRef.current = onRead;
36
77
  }, [onRead]);
37
78
 
79
+ // Create the decoder; replaced when a different factory is passed.
38
80
  useEffect(() => {
39
- if (!rootRef.current) return;
40
-
41
- let cancel = false;
42
- const iPhone = /iPhone|iPad/.test(navigator.userAgent);
43
- scanner.current = new BarcodeReader.Scanner({
44
- duplicateForgetTime: 1000,
45
- htmlElement: rootRef.current,
46
- videoSettings: {
47
- video: {
48
- width: { ideal: iPhone ? 1280 : 720 },
49
- height: { ideal: iPhone ? 1280 : 720 },
50
- facingMode: { ideal: "environment" },
51
- },
52
- },
53
- runtimeSettings: {
54
- mBarcodeFormatIds: BarcodeReader.EnumBarcodeFormat.DATAMATRIX,
55
- mAntiDamageLevel: 3,
56
- mDeblurLevel: 0,
57
- },
58
- onFrameRead: (results) => {
59
- const newRects: Array<BarcodeReaderType.LocalizationResult> = [];
60
-
61
- for (let result of results) {
62
- newRects.push(result.LocalizationResult);
63
- }
64
-
65
- if (newRects.length > 0) {
66
- setRects((rects) => [...rects, ...newRects]);
81
+ let cancelled = false;
82
+ let created: BarcodeDecoder | null = null;
83
+ setEngine(null);
84
+ setError(null);
67
85
 
68
- setTimeout(() => {
69
- if (!cancel) {
70
- setRects((rects) => rects.slice(newRects.length));
71
- }
72
- }, 300);
73
- }
74
- },
75
-
76
- onNewCodeRead: (txt) => {
77
- if (txt) {
78
- onReadRef.current(txt);
79
- }
80
- },
81
- });
82
-
83
- scanner.current
84
- .open()
85
- .then((videoDeviceInfo) => {
86
- if (cancel === false) {
87
- const { all, current } = videoDeviceInfo;
88
- currentDevice.current = 0;
89
-
90
- if (current?.deviceId) {
91
- for (let i = 0; i < all.length; i++) {
92
- if (all[i].deviceId === current.deviceId) {
93
- currentDevice.current = i;
94
- }
95
- }
96
- }
97
-
98
- setDevices(videoDeviceInfo);
99
- setIsLoading(false);
86
+ decoderFactory()
87
+ .then((decoder) => {
88
+ if (cancelled) {
89
+ decoder.dispose?.();
90
+ return;
100
91
  }
92
+ created = decoder;
93
+ decoderRef.current = decoder;
94
+ setEngine(decoder.name);
101
95
  })
102
- .catch((ex) => {
103
- if (cancel === false) {
104
- let error = ex.message || ex;
105
- setIsLoading(false);
106
-
107
- if (/Webassembly/.test(error)) {
108
- setError({
109
- icon: "unsupported",
110
- message: getLocalizedString(
111
- "Your browser is not supported. A browser that supports WebAssembly is required.",
112
- ),
113
- });
114
- } else if (
115
- /Permission/i.test(error) ||
116
- /video/i.test(error) ||
117
- /device/i.test(error) ||
118
- /Media/i.test(error) ||
119
- /agent/.test(error) ||
120
- /found/.test(error)
121
- )
122
- setError({
123
- icon: "camera",
124
- message: getLocalizedString("No camera available"),
125
- });
126
- else {
127
- setError({ icon: "generic", message: error });
128
- }
96
+ .catch((ex: unknown) => {
97
+ if (cancelled) return;
98
+ let message = ex instanceof Error ? ex.message : String(ex);
99
+ setIsLoading(false);
100
+
101
+ if (/WebAssembly/i.test(message)) {
102
+ setError({
103
+ icon: "unsupported",
104
+ message: getLocalizedString(
105
+ "Your browser is not supported. A browser that supports WebAssembly is required.",
106
+ ),
107
+ });
108
+ } else {
109
+ setError({ icon: "generic", message });
129
110
  }
130
111
  });
131
112
 
132
113
  return () => {
133
- cancel = true;
114
+ cancelled = true;
115
+ decoderRef.current = null;
116
+ created?.dispose?.();
117
+ };
118
+ }, [decoderFactory]);
119
+
120
+ // Start the camera and the decode loop; restarted when the user switches camera.
121
+ useEffect(() => {
122
+ let video = videoRef.current;
123
+ if (!video) return;
124
+
125
+ let cancelled = false;
126
+ let stream: MediaStream | null = null;
127
+ let frame = document.createElement("canvas");
128
+ let frameContext = frame.getContext("2d", { willReadFrequently: true });
129
+ let isNew = createDuplicateFilter(DUPLICATE_FORGET_TIME);
130
+ let busy = false;
131
+ let lastDecode = 0;
134
132
 
135
- if (scanner.current && typeof scanner.current.close === "function") {
136
- scanner.current.close();
133
+ function showHighlights(corners: Array<DecodedBarcode["corners"]>) {
134
+ setHighlights(corners);
135
+
136
+ if (highlightTimeout.current) clearTimeout(highlightTimeout.current);
137
+ highlightTimeout.current = setTimeout(() => {
138
+ if (!cancelled) setHighlights([]);
139
+ }, HIGHLIGHT_TIME);
140
+ }
141
+
142
+ async function decodeCurrentFrame(now: number) {
143
+ let decoder = decoderRef.current;
144
+ if (!decoder || !frameContext || !video || video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) return;
145
+
146
+ let scale = Math.min(1, MAX_FRAME_SIDE / Math.max(video.videoWidth, video.videoHeight));
147
+ let width = Math.round(video.videoWidth * scale);
148
+ let height = Math.round(video.videoHeight * scale);
149
+ if (width === 0 || height === 0) return;
150
+
151
+ if (frame.width !== width || frame.height !== height) {
152
+ frame.width = width;
153
+ frame.height = height;
137
154
  }
155
+ frameContext.drawImage(video, 0, 0, width, height);
156
+
157
+ let results = await decoder.decodeFrame(frame);
158
+ if (cancelled || results.length === 0) return;
159
+
160
+ // Highlights are drawn on an overlay sized like the video, so scale them back up.
161
+ let inverse = 1 / scale;
162
+ showHighlights(
163
+ results.map(
164
+ (result) =>
165
+ result.corners.map((point) => ({
166
+ x: point.x * inverse,
167
+ y: point.y * inverse,
168
+ })) as DecodedBarcode["corners"],
169
+ ),
170
+ );
171
+
172
+ for (let result of results) {
173
+ if (result.text && isNew(result.text, now)) {
174
+ onReadRef.current(result.text);
175
+ }
176
+ }
177
+ }
178
+
179
+ function tick(now: number) {
180
+ if (cancelled || !video) return;
181
+
182
+ if (!busy && now - lastDecode >= DECODE_INTERVAL) {
183
+ busy = true;
184
+ lastDecode = now;
185
+ decodeCurrentFrame(now)
186
+ .catch((ex: unknown) => {
187
+ console.warn("Barcode decode failed", ex);
188
+ })
189
+ .finally(() => {
190
+ busy = false;
191
+ });
192
+ }
193
+
194
+ scheduleFrame(video, tick);
195
+ }
196
+
197
+ async function start() {
198
+ if (!navigator.mediaDevices?.getUserMedia) {
199
+ throw new DOMException("Camera access is not available", "NotFoundError");
200
+ }
201
+
202
+ stream = await navigator.mediaDevices.getUserMedia(videoConstraints(deviceId));
203
+ if (cancelled || !video) return;
204
+
205
+ video.srcObject = stream;
206
+ await video.play();
207
+ if (cancelled) return;
208
+
209
+ let overlay = canvasRef.current;
210
+ if (overlay) {
211
+ overlay.width = video.videoWidth;
212
+ overlay.height = video.videoHeight;
213
+ }
214
+
215
+ currentDeviceId.current = stream.getVideoTracks()[0]?.getSettings().deviceId ?? deviceId;
216
+
217
+ // Labels and the full device list are only available once permission has been granted.
218
+ let all = await navigator.mediaDevices.enumerateDevices();
219
+ if (cancelled) return;
220
+
221
+ setDevices(all.filter((device) => device.kind === "videoinput"));
222
+ setIsLoading(false);
223
+ scheduleFrame(video, tick);
224
+ }
225
+
226
+ start().catch((ex: unknown) => {
227
+ if (cancelled) return;
228
+ setIsLoading(false);
229
+
230
+ let name = ex instanceof DOMException || ex instanceof Error ? ex.name : "";
231
+ let message = ex instanceof Error ? ex.message : String(ex);
232
+
233
+ if (CAMERA_ERROR_NAMES.includes(name) || /camera|video|device|media/i.test(message)) {
234
+ setError({ icon: "camera", message: getLocalizedString("No camera available") });
235
+ } else {
236
+ setError({ icon: "generic", message });
237
+ }
238
+ });
239
+
240
+ return () => {
241
+ cancelled = true;
242
+ if (highlightTimeout.current) clearTimeout(highlightTimeout.current);
243
+ stream?.getTracks().forEach((track) => track.stop());
244
+ if (video) video.srcObject = null;
138
245
  };
139
- }, [rootRef]);
246
+ }, [videoRef, canvasRef, deviceId]);
140
247
 
248
+ // Draw the highlights of detected codes on the overlay canvas.
141
249
  useEffect(() => {
142
- if (canvasRef.current) {
143
- const ctx = canvasRef.current.getContext("2d") as CanvasRenderingContext2D;
144
- ctx.clearRect(0, 0, canvasRef.current.width, canvasRef.current.height);
145
- ctx.fillStyle = "rgba(254,180,32,0.3)";
146
-
147
- const { width, height } = canvasRef.current;
148
- const xRatio = width / devices.width;
149
- const yRatio = height / devices.height;
150
-
151
- for (let rect of rects) {
152
- const { X1, X2, X3, X4, Y1, Y2, Y3, Y4 } = rect;
153
-
154
- ctx.beginPath();
155
- ctx.moveTo(X1 * xRatio, Y1 * yRatio);
156
- ctx.lineTo(X2 * xRatio, Y2 * yRatio);
157
- ctx.lineTo(X3 * xRatio, Y3 * yRatio);
158
- ctx.lineTo(X4 * xRatio, Y4 * yRatio);
159
- ctx.fill();
160
- }
250
+ let overlay = canvasRef.current;
251
+ if (!overlay) return;
252
+
253
+ let context = overlay.getContext("2d");
254
+ if (!context) return;
255
+
256
+ context.clearRect(0, 0, overlay.width, overlay.height);
257
+ context.fillStyle = "rgba(254,180,32,0.3)";
258
+
259
+ for (let corners of highlights) {
260
+ context.beginPath();
261
+ context.moveTo(corners[0].x, corners[0].y);
262
+ context.lineTo(corners[1].x, corners[1].y);
263
+ context.lineTo(corners[2].x, corners[2].y);
264
+ context.lineTo(corners[3].x, corners[3].y);
265
+ context.closePath();
266
+ context.fill();
161
267
  }
162
- }, [devices, canvasRef, rects]);
268
+ }, [canvasRef, highlights]);
163
269
 
164
270
  function setNextDevice() {
165
- currentDevice.current = ((currentDevice.current ?? 0) + 1) % devices.all.length;
166
- scanner.current?.play(devices.all[currentDevice.current].deviceId);
271
+ if (devices.length <= 1) return;
272
+
273
+ let index = devices.findIndex((device) => device.deviceId === currentDeviceId.current);
274
+ let next = devices[(index + 1) % devices.length];
275
+
276
+ if (next) setDeviceId(next.deviceId);
167
277
  }
168
278
 
169
- return { devices: devices.all, error, isLoading, setNextDevice };
279
+ return { devices, engine, error, isLoading, setNextDevice };
170
280
  }
@@ -6,9 +6,9 @@ import TapAndPlay from "@mui/icons-material/TapAndPlay";
6
6
  import { Alert, Box, Button, DialogActions, List, ListItem, ListItemText, Tab, Tabs } from "@mui/material";
7
7
  import { getLocalizedString, localize } from "@olenbetong/appframe-core";
8
8
  import { ResponsiveDialog } from "@olenbetong/appframe-mui";
9
- import { useEffect, useState } from "react";
9
+ import { type ReactNode, useEffect, useState } from "react";
10
10
  import { flushSync } from "react-dom";
11
- import { BarcodeScanner } from "./BarcodeScanner";
11
+ import { BarcodeScanner, type DecoderFactory } from "./BarcodeScanner";
12
12
  import { type AddElementSource, type ElementDetails, getElement } from "./getElement";
13
13
  import { AddElementHIDScanner } from "./HIDScanner";
14
14
  import { AddElementManualForm } from "./Manual/ManualForm";
@@ -29,6 +29,10 @@ export type ElementLookupDialogSharedProps = {
29
29
  initialTab?: InitialTabProps | null;
30
30
  useSearch?: boolean;
31
31
  allowEmptyElement?: boolean;
32
+ /** Engine for the camera tab. Defaults to zxing-wasm. */
33
+ decoder?: DecoderFactory;
34
+ /** Extra controls in the camera tab footer, e.g. an engine picker. */
35
+ scannerActions?: ReactNode;
32
36
  };
33
37
 
34
38
  export type ElementLookupDialogSingleModeProps = ElementLookupDialogSharedProps & {
@@ -44,7 +48,7 @@ export type ElementLookupDialogMultiModeProps = ElementLookupDialogSharedProps &
44
48
  export type ElementLookupDialogProps = ElementLookupDialogSingleModeProps | ElementLookupDialogMultiModeProps;
45
49
 
46
50
  export function ElementLookupDialog(props: ElementLookupDialogProps) {
47
- let { open, onClose, initialTab } = props;
51
+ let { open, onClose, initialTab, decoder, scannerActions } = props;
48
52
  let [tab, setTab] = useState<"camera" | "scanner" | "manual">("camera");
49
53
  let [elements, setElements] = useState<Array<AddElement>>([]);
50
54
  let [adding, setAdding] = useState(false);
@@ -124,7 +128,11 @@ export function ElementLookupDialog(props: ElementLookupDialogProps) {
124
128
  </Tabs>
125
129
  {tab === "camera" && (
126
130
  <Box sx={{ flexBasis: "12rem", flexGrow: 1, flexShrink: 2 }}>
127
- <BarcodeScanner onRead={(element) => handleElementAdd(element, "camera-barcode")} />
131
+ <BarcodeScanner
132
+ decoder={decoder}
133
+ actions={scannerActions}
134
+ onRead={(element) => handleElementAdd(element, "camera-barcode")}
135
+ />
128
136
  </Box>
129
137
  )}
130
138
  {tab === "manual" && (
package/src/index.ts CHANGED
@@ -1,31 +1,6 @@
1
- export {
2
- AppMenu,
3
- type AppMenuArticle,
4
- type AppMenuCategory,
5
- AppMenuColorScheme,
6
- AppMenuFavoriteButton,
7
- type AppMenuFavoriteButtonProps,
8
- AppMenuHeader,
9
- type AppMenuHeaderProps,
10
- type AppMenuLink,
11
- type AppMenuLinkGroup,
12
- AppMenuList,
13
- type AppMenuListProps,
14
- type AppMenuProps,
15
- AppMenuRail,
16
- type AppMenuRailProps,
17
- type AppMenuSelection,
18
- AppMenuToggle,
19
- type AppMenuToggleProps,
20
- type AppMenuUser,
21
- AppMenuUserMenu,
22
- type AppMenuUserMenuProps,
23
- createDeveloperCategories,
24
- defaultUserMenuItems,
25
- type DeveloperCategoryOptions,
26
- useServiceWorkerUpdate,
27
- } from "./chrome/AppMenu/index.js";
28
- export { AppShell, type AppShellProps } 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, type AppShellProps, hasSiteChrome } from "./chrome/AppShell/index.js";
29
4
  export { Checkbox, type CheckboxProps } from "./components/Checkbox/index.js";
30
5
  export {
31
6
  COLOR_SCHEME_CHANGE_EVENT,
@@ -67,14 +42,7 @@ export {
67
42
  } from "./filter/index.js";
68
43
  export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
69
44
  export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
70
- export {
71
- ReportLauncher,
72
- type ReportLauncherProps,
73
- type ReportLauncherTab,
74
- ReportParameterField,
75
- ReportParameters,
76
- type ReportParametersProps,
77
- } from "./report/index.js";
45
+ export { type OpenReportOptions, openReport } from "./chrome/openReport.js";
78
46
  export {
79
47
  BannerImage as PageBannerImage,
80
48
  type BannerImageProps,
@@ -94,11 +62,12 @@ export {
94
62
  export { Portal } from "./components/Portal/index.js";
95
63
  export {
96
64
  ToolbarBreadcrumbs,
65
+ ToolbarDrawerToggle,
97
66
  ToolbarPortal,
98
67
  type BreadcrumbItem,
99
68
  type ToolbarBreadcrumbsProps,
69
+ type ToolbarDrawerToggleProps,
100
70
  type ToolbarPortalProps,
101
- type ToolbarPortalSlot,
102
71
  } from "./components/Toolbar/index.js";
103
72
  export { ProgressBar } from "./components/ProgressBar/index.js";
104
73
  export { Sidebar, type SidebarProps } from "./components/Sidebar/index.js";