@olenbetong/synergi-react 4.3.0 → 5.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.
- package/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/components/CodeEditor/CodeEditor.css +6 -6
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.d.ts +7 -0
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +20 -0
- package/es/components/MergeProgressDialog/index.d.ts +3 -8
- package/es/components/MergeProgressDialog/index.js +4 -113
- package/es/components/MergeProgressDialog/useMergeJob.d.ts +36 -0
- package/es/components/MergeProgressDialog/useMergeJob.js +141 -0
- package/es/components/ProgressBar/index.css +1 -1
- package/es/components/Toolbar/Toolbar.css +137 -137
- package/es/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.d.ts +2 -2
- package/es/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.js +1 -2
- package/es/elements/ElementLookupDialog/BarcodeScanner/Error.js +3 -29
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.d.ts +1 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/index.js +3 -28
- package/es/index.css +1 -1
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/mui/index.d.ts +1 -0
- package/es/mui/index.js +1 -0
- package/es/test/setup.d.ts +5 -0
- package/package.json +21 -14
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.ts +125 -125
- package/src/components/CodeEditor/CodeEditor.css +6 -6
- package/src/components/CodeEditor/CodeEditor.tsx +173 -173
- package/src/components/CodeEditor/index.ts +1 -1
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.tsx +312 -312
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.ts +197 -197
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +91 -0
- package/src/components/MergeProgressDialog/index.tsx +5 -136
- package/src/components/MergeProgressDialog/useMergeJob.ts +169 -0
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/ProgressBar/index.scss +23 -54
- package/src/components/SplitContainer/index.tsx +333 -333
- package/src/components/Toolbar/Toolbar.css +137 -137
- package/src/components/Toolbar/index.tsx +265 -265
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.css +81 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/DeadIcon.tsx +4 -4
- package/src/elements/ElementLookupDialog/BarcodeScanner/Error.tsx +7 -36
- package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +20 -49
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/filter/index.ts +34 -34
- package/src/i18n.ts +13 -13
- package/src/index.ts +5 -1
- package/src/mui/MuiThemeProvider.tsx +135 -135
- package/src/mui/index.ts +1 -0
- package/src/test/setup.ts +23 -8
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import SearchIcon from "@mui/icons-material/Search";
|
|
2
|
-
import { IconButton, TextField } from "@mui/material";
|
|
3
|
-
import { type ReactNode, type RefObject, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
-
import { type AddElement, ElementLookupDialog } from "./ElementLookupDialog";
|
|
5
|
-
import type { DecoderFactory } from "./ElementLookupDialog/BarcodeScanner";
|
|
6
|
-
import { getLocalizedString } from "../i18n.js";
|
|
7
|
-
|
|
8
|
-
export type Element = {
|
|
9
|
-
Domain: string;
|
|
10
|
-
PrimKey: string;
|
|
11
|
-
ProjectID: string;
|
|
12
|
-
ProjectName: string;
|
|
13
|
-
ElementID: string | null;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type ElementLookupHandle = {
|
|
17
|
-
openDialog: () => void;
|
|
18
|
-
closeDialog: () => void;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type ElementLookupProps = {
|
|
22
|
-
value?: Element | null;
|
|
23
|
-
defaultValue?: Element | null;
|
|
24
|
-
ref?: RefObject<ElementLookupHandle | null>;
|
|
25
|
-
elementIDRequired?: boolean;
|
|
26
|
-
openLookupDialogIcon?: boolean;
|
|
27
|
-
onChange?: (value: Element | null) => void;
|
|
28
|
-
onDialogChange?: (open: boolean) => void;
|
|
29
|
-
/** Engine for the camera tab of the lookup dialog. Defaults to zxing-wasm. */
|
|
30
|
-
decoder?: DecoderFactory;
|
|
31
|
-
/** Extra controls in the camera tab footer, e.g. an engine picker. */
|
|
32
|
-
scannerActions?: ReactNode;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export function ElementLookup({
|
|
36
|
-
value,
|
|
37
|
-
defaultValue,
|
|
38
|
-
ref,
|
|
39
|
-
elementIDRequired = false,
|
|
40
|
-
openLookupDialogIcon,
|
|
41
|
-
onChange,
|
|
42
|
-
onDialogChange,
|
|
43
|
-
decoder,
|
|
44
|
-
scannerActions,
|
|
45
|
-
}: ElementLookupProps) {
|
|
46
|
-
let initializedRef = useRef<boolean>(false);
|
|
47
|
-
|
|
48
|
-
let [openElementLookupDialog, setOpenElementLookupDialog] = useState<boolean>(false);
|
|
49
|
-
let [element, setElement] = useState<Element | null>(defaultValue ?? null);
|
|
50
|
-
let elementValue = value === undefined ? element : value;
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (initializedRef.current) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (value === undefined && defaultValue) {
|
|
58
|
-
setElement(defaultValue);
|
|
59
|
-
initializedRef.current = true;
|
|
60
|
-
}
|
|
61
|
-
}, [defaultValue]); // oxlint-disable-line react-hooks/exhaustive-deps (intentionally skipping "value" dependency as this shouldn't run when "value" changes)
|
|
62
|
-
|
|
63
|
-
useImperativeHandle(ref, () => ({
|
|
64
|
-
openDialog: () => setOpenElementLookupDialog(true),
|
|
65
|
-
closeDialog: () => setOpenElementLookupDialog(false),
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
async function handleAddElement(addElement: AddElement) {
|
|
69
|
-
onChange?.(addElement.element);
|
|
70
|
-
setElement(addElement.element);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
onDialogChange?.(openElementLookupDialog);
|
|
75
|
-
}, [openElementLookupDialog]); // oxlint-disable-line react-hooks/exhaustive-deps (only run when openElementLookupDialog changes)
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<>
|
|
79
|
-
<ElementLookupDialog
|
|
80
|
-
open={openElementLookupDialog}
|
|
81
|
-
mode="single"
|
|
82
|
-
onClose={() => setOpenElementLookupDialog(false)}
|
|
83
|
-
onAdd={handleAddElement}
|
|
84
|
-
allowEmptyElement={!elementIDRequired}
|
|
85
|
-
decoder={decoder}
|
|
86
|
-
scannerActions={scannerActions}
|
|
87
|
-
/>
|
|
88
|
-
|
|
89
|
-
<input type="hidden" name="ProjectID" value={elementValue?.ProjectID ?? ""} />
|
|
90
|
-
<input type="hidden" name="ElementRef" value={elementValue?.PrimKey ?? ""} />
|
|
91
|
-
|
|
92
|
-
<TextField
|
|
93
|
-
id="NewElementDamge_Project"
|
|
94
|
-
value={elementValue ? `${elementValue.ProjectID}: ${elementValue.ProjectName}` : ""}
|
|
95
|
-
label={getLocalizedString("Project")}
|
|
96
|
-
fullWidth
|
|
97
|
-
required
|
|
98
|
-
autoComplete="off"
|
|
99
|
-
slotProps={{ htmlInput: { readOnly: true } }}
|
|
100
|
-
/>
|
|
101
|
-
<TextField
|
|
102
|
-
name="ElementID"
|
|
103
|
-
id="NewElementDamage_ElementID"
|
|
104
|
-
value={elementValue ? elementValue.ElementID : ""}
|
|
105
|
-
label={getLocalizedString("Element ID")}
|
|
106
|
-
fullWidth
|
|
107
|
-
required={elementIDRequired}
|
|
108
|
-
autoComplete="off"
|
|
109
|
-
slotProps={{
|
|
110
|
-
htmlInput: { readOnly: true },
|
|
111
|
-
input: {
|
|
112
|
-
endAdornment: openLookupDialogIcon ? (
|
|
113
|
-
<IconButton onClick={() => setOpenElementLookupDialog(true)}>
|
|
114
|
-
<SearchIcon />
|
|
115
|
-
</IconButton>
|
|
116
|
-
) : undefined,
|
|
117
|
-
},
|
|
118
|
-
inputLabel: { shrink: !!elementValue?.ElementID },
|
|
119
|
-
}}
|
|
120
|
-
/>
|
|
121
|
-
</>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
1
|
+
import SearchIcon from "@mui/icons-material/Search";
|
|
2
|
+
import { IconButton, TextField } from "@mui/material";
|
|
3
|
+
import { type ReactNode, type RefObject, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
+
import { type AddElement, ElementLookupDialog } from "./ElementLookupDialog";
|
|
5
|
+
import type { DecoderFactory } from "./ElementLookupDialog/BarcodeScanner";
|
|
6
|
+
import { getLocalizedString } from "../i18n.js";
|
|
7
|
+
|
|
8
|
+
export type Element = {
|
|
9
|
+
Domain: string;
|
|
10
|
+
PrimKey: string;
|
|
11
|
+
ProjectID: string;
|
|
12
|
+
ProjectName: string;
|
|
13
|
+
ElementID: string | null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type ElementLookupHandle = {
|
|
17
|
+
openDialog: () => void;
|
|
18
|
+
closeDialog: () => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type ElementLookupProps = {
|
|
22
|
+
value?: Element | null;
|
|
23
|
+
defaultValue?: Element | null;
|
|
24
|
+
ref?: RefObject<ElementLookupHandle | null>;
|
|
25
|
+
elementIDRequired?: boolean;
|
|
26
|
+
openLookupDialogIcon?: boolean;
|
|
27
|
+
onChange?: (value: Element | null) => void;
|
|
28
|
+
onDialogChange?: (open: boolean) => void;
|
|
29
|
+
/** Engine for the camera tab of the lookup dialog. Defaults to zxing-wasm. */
|
|
30
|
+
decoder?: DecoderFactory;
|
|
31
|
+
/** Extra controls in the camera tab footer, e.g. an engine picker. */
|
|
32
|
+
scannerActions?: ReactNode;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function ElementLookup({
|
|
36
|
+
value,
|
|
37
|
+
defaultValue,
|
|
38
|
+
ref,
|
|
39
|
+
elementIDRequired = false,
|
|
40
|
+
openLookupDialogIcon,
|
|
41
|
+
onChange,
|
|
42
|
+
onDialogChange,
|
|
43
|
+
decoder,
|
|
44
|
+
scannerActions,
|
|
45
|
+
}: ElementLookupProps) {
|
|
46
|
+
let initializedRef = useRef<boolean>(false);
|
|
47
|
+
|
|
48
|
+
let [openElementLookupDialog, setOpenElementLookupDialog] = useState<boolean>(false);
|
|
49
|
+
let [element, setElement] = useState<Element | null>(defaultValue ?? null);
|
|
50
|
+
let elementValue = value === undefined ? element : value;
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (initializedRef.current) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (value === undefined && defaultValue) {
|
|
58
|
+
setElement(defaultValue);
|
|
59
|
+
initializedRef.current = true;
|
|
60
|
+
}
|
|
61
|
+
}, [defaultValue]); // oxlint-disable-line react-hooks/exhaustive-deps (intentionally skipping "value" dependency as this shouldn't run when "value" changes)
|
|
62
|
+
|
|
63
|
+
useImperativeHandle(ref, () => ({
|
|
64
|
+
openDialog: () => setOpenElementLookupDialog(true),
|
|
65
|
+
closeDialog: () => setOpenElementLookupDialog(false),
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
async function handleAddElement(addElement: AddElement) {
|
|
69
|
+
onChange?.(addElement.element);
|
|
70
|
+
setElement(addElement.element);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
onDialogChange?.(openElementLookupDialog);
|
|
75
|
+
}, [openElementLookupDialog]); // oxlint-disable-line react-hooks/exhaustive-deps (only run when openElementLookupDialog changes)
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
<ElementLookupDialog
|
|
80
|
+
open={openElementLookupDialog}
|
|
81
|
+
mode="single"
|
|
82
|
+
onClose={() => setOpenElementLookupDialog(false)}
|
|
83
|
+
onAdd={handleAddElement}
|
|
84
|
+
allowEmptyElement={!elementIDRequired}
|
|
85
|
+
decoder={decoder}
|
|
86
|
+
scannerActions={scannerActions}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<input type="hidden" name="ProjectID" value={elementValue?.ProjectID ?? ""} />
|
|
90
|
+
<input type="hidden" name="ElementRef" value={elementValue?.PrimKey ?? ""} />
|
|
91
|
+
|
|
92
|
+
<TextField
|
|
93
|
+
id="NewElementDamge_Project"
|
|
94
|
+
value={elementValue ? `${elementValue.ProjectID}: ${elementValue.ProjectName}` : ""}
|
|
95
|
+
label={getLocalizedString("Project")}
|
|
96
|
+
fullWidth
|
|
97
|
+
required
|
|
98
|
+
autoComplete="off"
|
|
99
|
+
slotProps={{ htmlInput: { readOnly: true } }}
|
|
100
|
+
/>
|
|
101
|
+
<TextField
|
|
102
|
+
name="ElementID"
|
|
103
|
+
id="NewElementDamage_ElementID"
|
|
104
|
+
value={elementValue ? elementValue.ElementID : ""}
|
|
105
|
+
label={getLocalizedString("Element ID")}
|
|
106
|
+
fullWidth
|
|
107
|
+
required={elementIDRequired}
|
|
108
|
+
autoComplete="off"
|
|
109
|
+
slotProps={{
|
|
110
|
+
htmlInput: { readOnly: true },
|
|
111
|
+
input: {
|
|
112
|
+
endAdornment: openLookupDialogIcon ? (
|
|
113
|
+
<IconButton onClick={() => setOpenElementLookupDialog(true)}>
|
|
114
|
+
<SearchIcon />
|
|
115
|
+
</IconButton>
|
|
116
|
+
) : undefined,
|
|
117
|
+
},
|
|
118
|
+
inputLabel: { shrink: !!elementValue?.ElementID },
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
.ob-barcode-scanner {
|
|
2
|
+
position: relative;
|
|
3
|
+
height: 100%;
|
|
4
|
+
background-color: black;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.ob-barcode-scanner__frames {
|
|
8
|
+
height: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.ob-barcode-scanner__frame {
|
|
12
|
+
position: absolute;
|
|
13
|
+
inset: 0;
|
|
14
|
+
height: 100%;
|
|
15
|
+
width: 100%;
|
|
16
|
+
object-fit: contain;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.ob-barcode-scanner__footer {
|
|
20
|
+
position: absolute;
|
|
21
|
+
right: 0;
|
|
22
|
+
bottom: 0;
|
|
23
|
+
left: 0;
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: space-between;
|
|
27
|
+
padding: 0.5rem 1.5rem;
|
|
28
|
+
color: white;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.ob-barcode-scanner__actions {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 0.5rem;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.ob-barcode-scanner__engine {
|
|
38
|
+
font-size: 0.75rem;
|
|
39
|
+
opacity: 0.7;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.ob-barcode-scanner__icon-button {
|
|
43
|
+
display: inline-flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
justify-content: center;
|
|
46
|
+
padding: 0.75rem;
|
|
47
|
+
border: 0;
|
|
48
|
+
border-radius: 50%;
|
|
49
|
+
background: transparent;
|
|
50
|
+
color: inherit;
|
|
51
|
+
font-size: 1.75rem;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ob-barcode-scanner__icon-button:hover {
|
|
56
|
+
background-color: rgb(255 255 255 / 0.1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.ob-barcode-scanner__error {
|
|
60
|
+
position: absolute;
|
|
61
|
+
inset: 0;
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
justify-content: center;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.ob-barcode-scanner__error-box {
|
|
68
|
+
width: 335px;
|
|
69
|
+
max-width: 100%;
|
|
70
|
+
border: 1px solid #3e3e3e;
|
|
71
|
+
border-radius: 3px;
|
|
72
|
+
background: #111111;
|
|
73
|
+
color: white;
|
|
74
|
+
text-align: center;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.ob-barcode-scanner__error-icon {
|
|
78
|
+
margin: 1rem 0;
|
|
79
|
+
color: #eee;
|
|
80
|
+
font-size: 3.5rem;
|
|
81
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SVGProps } from "react";
|
|
2
2
|
|
|
3
|
-
export function Dead(props:
|
|
3
|
+
export function Dead(props: SVGProps<SVGSVGElement>) {
|
|
4
4
|
return (
|
|
5
|
-
<
|
|
5
|
+
<svg width="1em" height="1em" viewBox="0 0 24 24" fill="currentColor" aria-hidden focusable="false" {...props}>
|
|
6
6
|
<path
|
|
7
7
|
fill="currentColor"
|
|
8
8
|
d="M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2M6.76,8.82L7.82,7.76L8.88,8.82L9.94,7.76L11,8.82L9.94,9.88L11,10.94L9.94,12L8.88,10.94L7.82,12L6.76,10.94L7.82,9.88L6.76,8.82M6.89,17.5C7.69,15.46 9.67,14 12,14C14.33,14 16.31,15.46 17.11,17.5H6.89M17.24,10.94L16.18,12L15.12,10.94L14.06,12L13,10.94L14.06,9.88L13,8.82L14.06,7.76L15.12,8.82L16.18,7.76L17.24,8.82L16.18,9.88L17.24,10.94Z"
|
|
9
9
|
/>
|
|
10
|
-
</
|
|
10
|
+
</svg>
|
|
11
11
|
);
|
|
12
12
|
}
|
|
@@ -1,46 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Camera from "@mui/icons-material/Camera";
|
|
1
|
+
import { CameraIcon } from "@navikt/aksel-icons";
|
|
3
2
|
|
|
4
3
|
import { Dead as DeadIcon } from "./DeadIcon";
|
|
5
4
|
|
|
6
|
-
const BarcodeError = styled.div`
|
|
7
|
-
position: absolute;
|
|
8
|
-
bottom: 0;
|
|
9
|
-
left: 0;
|
|
10
|
-
right: 0;
|
|
11
|
-
top: 0;
|
|
12
|
-
|
|
13
|
-
display: flex;
|
|
14
|
-
align-items: center;
|
|
15
|
-
justify-content: center;
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
const ErrorBox = styled.div`
|
|
19
|
-
background: #111111;
|
|
20
|
-
border: 1px solid #3e3e3e;
|
|
21
|
-
border-radius: 3px;
|
|
22
|
-
|
|
23
|
-
max-width: 100%;
|
|
24
|
-
width: 335px;
|
|
25
|
-
|
|
26
|
-
color: white;
|
|
27
|
-
text-align: center;
|
|
28
|
-
`;
|
|
29
|
-
|
|
30
5
|
export function ErrorIcon({ icon, message }: { icon?: string; message: string }) {
|
|
31
|
-
let Icon
|
|
32
|
-
|
|
33
|
-
if (icon === "camera") {
|
|
34
|
-
Icon = Camera;
|
|
35
|
-
}
|
|
6
|
+
let Icon = icon === "camera" ? CameraIcon : DeadIcon;
|
|
36
7
|
|
|
37
8
|
return (
|
|
38
|
-
<
|
|
39
|
-
<
|
|
40
|
-
<Icon
|
|
9
|
+
<div className="ob-barcode-scanner__error">
|
|
10
|
+
<div className="ob-barcode-scanner__error-box">
|
|
11
|
+
<Icon aria-hidden className="ob-barcode-scanner__error-icon" />
|
|
41
12
|
<br />
|
|
42
13
|
<p>{message}</p>
|
|
43
|
-
</
|
|
44
|
-
</
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
45
16
|
);
|
|
46
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "./BarcodeScanner.css";
|
|
2
|
+
|
|
3
|
+
import { ArrowsCirclepathIcon } from "@navikt/aksel-icons";
|
|
3
4
|
import { type ReactNode, useRef } from "react";
|
|
4
5
|
import type { DecoderFactory } from "./decoder";
|
|
5
6
|
import { ErrorIcon } from "./Error";
|
|
@@ -22,69 +23,39 @@ export type BarcodeScannerProps = {
|
|
|
22
23
|
actions?: ReactNode;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
const frameSx: SxProps = {
|
|
26
|
-
position: "absolute",
|
|
27
|
-
bottom: 0,
|
|
28
|
-
left: 0,
|
|
29
|
-
right: 0,
|
|
30
|
-
top: 0,
|
|
31
|
-
height: "100%",
|
|
32
|
-
width: "100%",
|
|
33
|
-
objectFit: "contain",
|
|
34
|
-
};
|
|
35
|
-
|
|
36
26
|
export function BarcodeScanner({ onRead, decoder, actions }: BarcodeScannerProps) {
|
|
37
27
|
let video = useRef<HTMLVideoElement | null>(null);
|
|
38
28
|
let canvas = useRef<HTMLCanvasElement | null>(null);
|
|
39
29
|
let { devices, engine, error, setNextDevice } = useScanner(video, canvas, onRead, decoder);
|
|
40
30
|
|
|
41
31
|
return (
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
height: "100%",
|
|
47
|
-
}}
|
|
48
|
-
>
|
|
49
|
-
<Box sx={{ height: "100%" }}>
|
|
50
|
-
<Box component="video" playsInline muted autoPlay sx={frameSx} ref={video} />
|
|
51
|
-
<Box component="canvas" sx={frameSx} ref={canvas} />
|
|
32
|
+
<div className="ob-barcode-scanner">
|
|
33
|
+
<div className="ob-barcode-scanner__frames">
|
|
34
|
+
<video playsInline muted autoPlay className="ob-barcode-scanner__frame" ref={video} />
|
|
35
|
+
<canvas className="ob-barcode-scanner__frame" ref={canvas} />
|
|
52
36
|
{error && <ErrorIcon {...error} />}
|
|
53
|
-
</
|
|
54
|
-
<
|
|
55
|
-
sx={{
|
|
56
|
-
display: "flex",
|
|
57
|
-
alignItems: "center",
|
|
58
|
-
justifyContent: "space-between",
|
|
59
|
-
position: "absolute",
|
|
60
|
-
bottom: 0,
|
|
61
|
-
left: 0,
|
|
62
|
-
right: 0,
|
|
63
|
-
py: 1,
|
|
64
|
-
px: 3,
|
|
65
|
-
color: "white",
|
|
66
|
-
}}
|
|
67
|
-
>
|
|
37
|
+
</div>
|
|
38
|
+
<div className="ob-barcode-scanner__footer">
|
|
68
39
|
{devices.length <= 1 && <span />}
|
|
69
40
|
{devices.length > 1 && (
|
|
70
|
-
<
|
|
71
|
-
|
|
41
|
+
<button
|
|
42
|
+
type="button"
|
|
43
|
+
className="ob-barcode-scanner__icon-button"
|
|
72
44
|
aria-label={getLocalizedString("Switch camera")}
|
|
73
45
|
onClick={() => setNextDevice()}
|
|
74
|
-
size="large"
|
|
75
46
|
>
|
|
76
|
-
<
|
|
77
|
-
</
|
|
47
|
+
<ArrowsCirclepathIcon aria-hidden />
|
|
48
|
+
</button>
|
|
78
49
|
)}
|
|
79
|
-
<
|
|
50
|
+
<div className="ob-barcode-scanner__actions">
|
|
80
51
|
{engine && (
|
|
81
|
-
<
|
|
52
|
+
<span className="ob-barcode-scanner__engine" data-testid="barcode-engine">
|
|
82
53
|
{engine}
|
|
83
|
-
</
|
|
54
|
+
</span>
|
|
84
55
|
)}
|
|
85
56
|
{actions}
|
|
86
|
-
</
|
|
87
|
-
</
|
|
88
|
-
</
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
89
60
|
);
|
|
90
61
|
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import "./index.css";
|
|
2
|
-
|
|
3
|
-
import { Box, Button } from "@mui/material";
|
|
4
|
-
|
|
5
|
-
import { useEffect, useRef, useState } from "react";
|
|
6
|
-
|
|
7
|
-
import { useHIDScanner } from "./useHIDScanner";
|
|
8
|
-
import { getLocalizedString } from "../../../i18n.js";
|
|
9
|
-
|
|
10
|
-
export function AddElementHIDScanner({ onScan }: { onScan: (id: string) => void }) {
|
|
11
|
-
let [enabled, setEnabled] = useState(false);
|
|
12
|
-
let root = useRef<HTMLDivElement>(null);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (!root.current) return;
|
|
16
|
-
|
|
17
|
-
let rootElem = root.current;
|
|
18
|
-
|
|
19
|
-
function handleFocus() {
|
|
20
|
-
setEnabled(true);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function handleBlur() {
|
|
24
|
-
setEnabled(false);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
rootElem.addEventListener("focus", handleFocus);
|
|
28
|
-
rootElem.addEventListener("blur", handleBlur);
|
|
29
|
-
rootElem.focus();
|
|
30
|
-
|
|
31
|
-
return () => {
|
|
32
|
-
rootElem.removeEventListener("focus", handleFocus);
|
|
33
|
-
rootElem.removeEventListener("blur", handleBlur);
|
|
34
|
-
};
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
useHIDScanner(onScan, enabled);
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<Box
|
|
41
|
-
sx={{
|
|
42
|
-
height: "100%",
|
|
43
|
-
bgcolor: "#ddd",
|
|
44
|
-
display: "flex",
|
|
45
|
-
alignItems: "center",
|
|
46
|
-
justifyContent: "center",
|
|
47
|
-
backgroundImage: enabled ? "linear-gradient(var(--angle), #777, #bbb, #777)" : "none",
|
|
48
|
-
animation: enabled ? "MovingBackground 8s linear infinite" : "none",
|
|
49
|
-
}}
|
|
50
|
-
tabIndex={0}
|
|
51
|
-
ref={root}
|
|
52
|
-
>
|
|
53
|
-
{enabled ? (
|
|
54
|
-
<span>{getLocalizedString("Listening for scanned elements")}...</span>
|
|
55
|
-
) : (
|
|
56
|
-
<Button
|
|
57
|
-
variant="contained"
|
|
58
|
-
onClick={() => {
|
|
59
|
-
if (root.current) root.current.focus();
|
|
60
|
-
}}
|
|
61
|
-
>
|
|
62
|
-
{getLocalizedString("Start listening")}
|
|
63
|
-
</Button>
|
|
64
|
-
)}
|
|
65
|
-
</Box>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
1
|
+
import "./index.css";
|
|
2
|
+
|
|
3
|
+
import { Box, Button } from "@mui/material";
|
|
4
|
+
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
|
|
7
|
+
import { useHIDScanner } from "./useHIDScanner";
|
|
8
|
+
import { getLocalizedString } from "../../../i18n.js";
|
|
9
|
+
|
|
10
|
+
export function AddElementHIDScanner({ onScan }: { onScan: (id: string) => void }) {
|
|
11
|
+
let [enabled, setEnabled] = useState(false);
|
|
12
|
+
let root = useRef<HTMLDivElement>(null);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!root.current) return;
|
|
16
|
+
|
|
17
|
+
let rootElem = root.current;
|
|
18
|
+
|
|
19
|
+
function handleFocus() {
|
|
20
|
+
setEnabled(true);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function handleBlur() {
|
|
24
|
+
setEnabled(false);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
rootElem.addEventListener("focus", handleFocus);
|
|
28
|
+
rootElem.addEventListener("blur", handleBlur);
|
|
29
|
+
rootElem.focus();
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
rootElem.removeEventListener("focus", handleFocus);
|
|
33
|
+
rootElem.removeEventListener("blur", handleBlur);
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
useHIDScanner(onScan, enabled);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Box
|
|
41
|
+
sx={{
|
|
42
|
+
height: "100%",
|
|
43
|
+
bgcolor: "#ddd",
|
|
44
|
+
display: "flex",
|
|
45
|
+
alignItems: "center",
|
|
46
|
+
justifyContent: "center",
|
|
47
|
+
backgroundImage: enabled ? "linear-gradient(var(--angle), #777, #bbb, #777)" : "none",
|
|
48
|
+
animation: enabled ? "MovingBackground 8s linear infinite" : "none",
|
|
49
|
+
}}
|
|
50
|
+
tabIndex={0}
|
|
51
|
+
ref={root}
|
|
52
|
+
>
|
|
53
|
+
{enabled ? (
|
|
54
|
+
<span>{getLocalizedString("Listening for scanned elements")}...</span>
|
|
55
|
+
) : (
|
|
56
|
+
<Button
|
|
57
|
+
variant="contained"
|
|
58
|
+
onClick={() => {
|
|
59
|
+
if (root.current) root.current.focus();
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
{getLocalizedString("Start listening")}
|
|
63
|
+
</Button>
|
|
64
|
+
)}
|
|
65
|
+
</Box>
|
|
66
|
+
);
|
|
67
|
+
}
|