@olenbetong/synergi-react 4.2.4 → 4.2.6

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 (56) hide show
  1. package/package.json +5 -5
  2. package/src/chrome/AppShell/index.tsx +29 -29
  3. package/src/chrome/openReport.ts +34 -34
  4. package/src/colorScheme.ts +81 -81
  5. package/src/components/DateNavigator/index.tsx +186 -186
  6. package/src/components/FilePond.tsx +312 -312
  7. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  8. package/src/components/ImageEditor/index.ts +9 -9
  9. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  10. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  11. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  12. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  13. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  14. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  15. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  16. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  17. package/src/components/ImageEditor/useImageHistory.ts +197 -197
  18. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  19. package/src/components/LinkedCardList/index.scss +95 -95
  20. package/src/components/MergeProgressDialog/index.tsx +249 -249
  21. package/src/components/PageBanner/index.tsx +80 -80
  22. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  23. package/src/components/ProgressBar/index.scss +96 -96
  24. package/src/components/SplitContainer/index.tsx +333 -333
  25. package/src/components/Toolbar/index.tsx +232 -232
  26. package/src/designsystemet-web-types.d.ts +24 -24
  27. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  28. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  29. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  30. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  31. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  32. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  33. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  34. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  35. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  36. package/src/elements/ElementLookup.tsx +123 -123
  37. package/src/elements/ElementLookupDialog/BarcodeScanner/decoder.ts +32 -32
  38. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/dbr.ts +118 -118
  39. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/native.ts +103 -103
  40. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +95 -95
  41. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders.test.ts +118 -118
  42. package/src/elements/ElementLookupDialog/BarcodeScanner/duplicateFilter.ts +21 -21
  43. package/src/elements/ElementLookupDialog/BarcodeScanner/index.tsx +90 -90
  44. package/src/elements/ElementLookupDialog/BarcodeScanner/useScanner.ts +280 -280
  45. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  46. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  47. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  48. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  49. package/src/elements/ProjectSelect.tsx +130 -130
  50. package/src/elements/index.ts +15 -15
  51. package/src/filter/index.ts +34 -34
  52. package/src/i18n.ts +13 -13
  53. package/src/index.ts +77 -77
  54. package/src/mui/MuiThemeProvider.tsx +174 -174
  55. package/src/mui/index.ts +1 -1
  56. package/src/test/setup.ts +8 -8
@@ -1,186 +1,186 @@
1
- import "./index.css";
2
-
3
- import clsx from "clsx";
4
- import { useEffect, useRef, useState } from "react";
5
- import { getLocalizedString } from "../../i18n.js";
6
-
7
- function getUiCulture() {
8
- return af?.userSession?.culture ?? "default";
9
- }
10
-
11
- function Arrow({
12
- direction,
13
- ...rest
14
- }: { direction: "left" | "right" } & React.ButtonHTMLAttributes<HTMLButtonElement>) {
15
- return (
16
- <button
17
- className={clsx(
18
- "ObDateNavigator-arrow btn-reset",
19
- direction === "left" ? "ObDateNavigator-arrowLeft" : "ObDateNavigator-arrowRight",
20
- )}
21
- aria-label={direction === "left" ? getLocalizedString("Previous day") : getLocalizedString("Next day")}
22
- {...rest}
23
- >
24
- <span className="ObDateNavigator-icon">
25
- {direction === "left" ? (
26
- <svg aria-hidden="true" viewBox="0 0 320 512">
27
- <path
28
- fill="currentColor"
29
- d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"
30
- />
31
- </svg>
32
- ) : (
33
- <svg aria-hidden="true" viewBox="0 0 320 512">
34
- <path
35
- fill="currentColor"
36
- d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"
37
- />
38
- </svg>
39
- )}
40
- </span>
41
- </button>
42
- );
43
- }
44
-
45
- const formatter = new Intl.DateTimeFormat(getUiCulture(), {
46
- weekday: "short",
47
- day: "numeric",
48
- month: "short",
49
- year: "numeric",
50
- timeZone: "utc",
51
- });
52
-
53
- const oneDay = 24 * 60 * 60 * 1000;
54
-
55
- export type DateNavigatorProps = {
56
- date?: Date | string | number;
57
- defaultDate?: Date | string | number; // For default uncontrolled value
58
- disableTodayButton?: boolean;
59
- onChange?: (date: Date) => void;
60
- minDate?: Date | string | number;
61
- maxDate?: Date | string | number;
62
- };
63
-
64
- function sanitizeDate(date: Date | string | number): Date {
65
- if (typeof date === "string" || typeof date === "number") {
66
- let parsedDate = new Date(date);
67
- if (Number.isNaN(parsedDate.getTime())) {
68
- throw new Error(`Invalid date value: ${date}`);
69
- }
70
- return parsedDate;
71
- } else if (date instanceof Date) {
72
- if (Number.isNaN(date.getTime())) {
73
- throw new Error(`Invalid date object: ${date}`);
74
- }
75
- return new Date(date.getTime()); // Return a copy of the date
76
- } else {
77
- throw new Error(`Unsupported date type: ${typeof date}`);
78
- }
79
- }
80
-
81
- export function DateNavigator({
82
- date: dateProp,
83
- defaultDate,
84
- disableTodayButton,
85
- onChange,
86
- minDate: minDateProp,
87
- maxDate: maxDateProp,
88
- }: DateNavigatorProps) {
89
- let [internalDate, setInternalDate] = useState(() => (defaultDate ? sanitizeDate(defaultDate) : new Date()));
90
- let date = dateProp ? sanitizeDate(dateProp) : internalDate;
91
- let dateUtc = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
92
- let today = new Date();
93
- let todayUtc = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate());
94
- let liveRef = useRef<HTMLDivElement>(null);
95
-
96
- let text = (() => {
97
- let base = formatter.format(new Date(dateUtc));
98
- if (todayUtc === dateUtc) return `${getLocalizedString("Today")}, ${base}`;
99
- if (todayUtc === dateUtc + oneDay) return `${getLocalizedString("Yesterday")}, ${base}`;
100
- if (todayUtc === dateUtc - oneDay) return `${getLocalizedString("Tomorrow")}, ${base}`;
101
- return base;
102
- })();
103
-
104
- let minDate = minDateProp && sanitizeDate(minDateProp);
105
- let maxDate = maxDateProp && sanitizeDate(maxDateProp);
106
- let disablePrev = !!minDate && dateUtc <= Date.UTC(minDate.getFullYear(), minDate.getMonth(), minDate.getDate());
107
- let disableNext = !!maxDate && dateUtc >= Date.UTC(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate());
108
-
109
- function updateDate(newDate: Date) {
110
- if (minDate && newDate < minDate) {
111
- newDate = new Date(minDate); // Ensure we don't go below minDate
112
- } else if (maxDate && newDate > maxDate) {
113
- newDate = new Date(maxDate); // Ensure we don't go above maxDate
114
- }
115
-
116
- onChange?.(newDate);
117
- setInternalDate(newDate);
118
- }
119
-
120
- function jumpToToday() {
121
- updateDate(new Date());
122
- }
123
-
124
- useEffect(() => {
125
- if (liveRef.current) {
126
- liveRef.current.textContent = text;
127
- }
128
- }, [text]);
129
-
130
- function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
131
- if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
132
- if (event.defaultPrevented) return;
133
- if (event.altKey || event.metaKey) return; // Ignore if alt or meta key is pressed
134
-
135
- if (disablePrev && event.key === "ArrowLeft") return;
136
- if (disableNext && event.key === "ArrowRight") return;
137
-
138
- if (event.ctrlKey && event.shiftKey) {
139
- // If both ctrl and shift are pressed, navigate by 1 year
140
- let newDate = new Date(dateUtc);
141
- if (event.key === "ArrowLeft") {
142
- newDate.setFullYear(newDate.getFullYear() - 1);
143
- } else if (event.key === "ArrowRight") {
144
- newDate.setFullYear(newDate.getFullYear() + 1);
145
- }
146
- updateDate(newDate);
147
- return;
148
- }
149
-
150
- if (event.ctrlKey) {
151
- // Navigate by month
152
- let newDate = new Date(dateUtc);
153
- if (event.key === "ArrowLeft") {
154
- newDate.setMonth(newDate.getMonth() - 1);
155
- } else if (event.key === "ArrowRight") {
156
- newDate.setMonth(newDate.getMonth() + 1);
157
- }
158
- updateDate(newDate);
159
- return;
160
- }
161
-
162
- let modifier = event.shiftKey ? 7 : 1;
163
- if (event.key === "ArrowLeft") {
164
- updateDate(new Date(dateUtc - oneDay * modifier));
165
- } else if (event.key === "ArrowRight") {
166
- updateDate(new Date(dateUtc + oneDay * modifier));
167
- }
168
- }
169
-
170
- return (
171
- // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- I hate this component
172
- // oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- legacy component
173
- // oxlint-disable-next-line jsx-a11y/role-supports-aria-props -- legacy component
174
- <div className="ObDateNavigator-root" onKeyDown={handleKeyDown} tabIndex={0} aria-label="Date navigator">
175
- <Arrow direction="left" onClick={() => updateDate(new Date(dateUtc - oneDay))} disabled={disablePrev} />
176
- <div className="ObDateNavigator-date">{text}</div>
177
- <Arrow direction="right" onClick={() => updateDate(new Date(dateUtc + oneDay))} disabled={disableNext} />
178
- {!disableTodayButton && (
179
- <button type="button" className="ObDateNavigator-today btn-reset" onClick={jumpToToday}>
180
- {getLocalizedString("Today")}
181
- </button>
182
- )}
183
- <div aria-live="polite" ref={liveRef} style={{ position: "absolute", left: "-9999px" }} />
184
- </div>
185
- );
186
- }
1
+ import "./index.css";
2
+
3
+ import clsx from "clsx";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { getLocalizedString } from "../../i18n.js";
6
+
7
+ function getUiCulture() {
8
+ return af?.userSession?.culture ?? "default";
9
+ }
10
+
11
+ function Arrow({
12
+ direction,
13
+ ...rest
14
+ }: { direction: "left" | "right" } & React.ButtonHTMLAttributes<HTMLButtonElement>) {
15
+ return (
16
+ <button
17
+ className={clsx(
18
+ "ObDateNavigator-arrow btn-reset",
19
+ direction === "left" ? "ObDateNavigator-arrowLeft" : "ObDateNavigator-arrowRight",
20
+ )}
21
+ aria-label={direction === "left" ? getLocalizedString("Previous day") : getLocalizedString("Next day")}
22
+ {...rest}
23
+ >
24
+ <span className="ObDateNavigator-icon">
25
+ {direction === "left" ? (
26
+ <svg aria-hidden="true" viewBox="0 0 320 512">
27
+ <path
28
+ fill="currentColor"
29
+ d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"
30
+ />
31
+ </svg>
32
+ ) : (
33
+ <svg aria-hidden="true" viewBox="0 0 320 512">
34
+ <path
35
+ fill="currentColor"
36
+ d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"
37
+ />
38
+ </svg>
39
+ )}
40
+ </span>
41
+ </button>
42
+ );
43
+ }
44
+
45
+ const formatter = new Intl.DateTimeFormat(getUiCulture(), {
46
+ weekday: "short",
47
+ day: "numeric",
48
+ month: "short",
49
+ year: "numeric",
50
+ timeZone: "utc",
51
+ });
52
+
53
+ const oneDay = 24 * 60 * 60 * 1000;
54
+
55
+ export type DateNavigatorProps = {
56
+ date?: Date | string | number;
57
+ defaultDate?: Date | string | number; // For default uncontrolled value
58
+ disableTodayButton?: boolean;
59
+ onChange?: (date: Date) => void;
60
+ minDate?: Date | string | number;
61
+ maxDate?: Date | string | number;
62
+ };
63
+
64
+ function sanitizeDate(date: Date | string | number): Date {
65
+ if (typeof date === "string" || typeof date === "number") {
66
+ let parsedDate = new Date(date);
67
+ if (Number.isNaN(parsedDate.getTime())) {
68
+ throw new Error(`Invalid date value: ${date}`);
69
+ }
70
+ return parsedDate;
71
+ } else if (date instanceof Date) {
72
+ if (Number.isNaN(date.getTime())) {
73
+ throw new Error(`Invalid date object: ${date}`);
74
+ }
75
+ return new Date(date.getTime()); // Return a copy of the date
76
+ } else {
77
+ throw new Error(`Unsupported date type: ${typeof date}`);
78
+ }
79
+ }
80
+
81
+ export function DateNavigator({
82
+ date: dateProp,
83
+ defaultDate,
84
+ disableTodayButton,
85
+ onChange,
86
+ minDate: minDateProp,
87
+ maxDate: maxDateProp,
88
+ }: DateNavigatorProps) {
89
+ let [internalDate, setInternalDate] = useState(() => (defaultDate ? sanitizeDate(defaultDate) : new Date()));
90
+ let date = dateProp ? sanitizeDate(dateProp) : internalDate;
91
+ let dateUtc = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate());
92
+ let today = new Date();
93
+ let todayUtc = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate());
94
+ let liveRef = useRef<HTMLDivElement>(null);
95
+
96
+ let text = (() => {
97
+ let base = formatter.format(new Date(dateUtc));
98
+ if (todayUtc === dateUtc) return `${getLocalizedString("Today")}, ${base}`;
99
+ if (todayUtc === dateUtc + oneDay) return `${getLocalizedString("Yesterday")}, ${base}`;
100
+ if (todayUtc === dateUtc - oneDay) return `${getLocalizedString("Tomorrow")}, ${base}`;
101
+ return base;
102
+ })();
103
+
104
+ let minDate = minDateProp && sanitizeDate(minDateProp);
105
+ let maxDate = maxDateProp && sanitizeDate(maxDateProp);
106
+ let disablePrev = !!minDate && dateUtc <= Date.UTC(minDate.getFullYear(), minDate.getMonth(), minDate.getDate());
107
+ let disableNext = !!maxDate && dateUtc >= Date.UTC(maxDate.getFullYear(), maxDate.getMonth(), maxDate.getDate());
108
+
109
+ function updateDate(newDate: Date) {
110
+ if (minDate && newDate < minDate) {
111
+ newDate = new Date(minDate); // Ensure we don't go below minDate
112
+ } else if (maxDate && newDate > maxDate) {
113
+ newDate = new Date(maxDate); // Ensure we don't go above maxDate
114
+ }
115
+
116
+ onChange?.(newDate);
117
+ setInternalDate(newDate);
118
+ }
119
+
120
+ function jumpToToday() {
121
+ updateDate(new Date());
122
+ }
123
+
124
+ useEffect(() => {
125
+ if (liveRef.current) {
126
+ liveRef.current.textContent = text;
127
+ }
128
+ }, [text]);
129
+
130
+ function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>) {
131
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
132
+ if (event.defaultPrevented) return;
133
+ if (event.altKey || event.metaKey) return; // Ignore if alt or meta key is pressed
134
+
135
+ if (disablePrev && event.key === "ArrowLeft") return;
136
+ if (disableNext && event.key === "ArrowRight") return;
137
+
138
+ if (event.ctrlKey && event.shiftKey) {
139
+ // If both ctrl and shift are pressed, navigate by 1 year
140
+ let newDate = new Date(dateUtc);
141
+ if (event.key === "ArrowLeft") {
142
+ newDate.setFullYear(newDate.getFullYear() - 1);
143
+ } else if (event.key === "ArrowRight") {
144
+ newDate.setFullYear(newDate.getFullYear() + 1);
145
+ }
146
+ updateDate(newDate);
147
+ return;
148
+ }
149
+
150
+ if (event.ctrlKey) {
151
+ // Navigate by month
152
+ let newDate = new Date(dateUtc);
153
+ if (event.key === "ArrowLeft") {
154
+ newDate.setMonth(newDate.getMonth() - 1);
155
+ } else if (event.key === "ArrowRight") {
156
+ newDate.setMonth(newDate.getMonth() + 1);
157
+ }
158
+ updateDate(newDate);
159
+ return;
160
+ }
161
+
162
+ let modifier = event.shiftKey ? 7 : 1;
163
+ if (event.key === "ArrowLeft") {
164
+ updateDate(new Date(dateUtc - oneDay * modifier));
165
+ } else if (event.key === "ArrowRight") {
166
+ updateDate(new Date(dateUtc + oneDay * modifier));
167
+ }
168
+ }
169
+
170
+ return (
171
+ // oxlint-disable-next-line jsx-a11y/no-noninteractive-tabindex -- I hate this component
172
+ // oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- legacy component
173
+ // oxlint-disable-next-line jsx-a11y/role-supports-aria-props -- legacy component
174
+ <div className="ObDateNavigator-root" onKeyDown={handleKeyDown} tabIndex={0} aria-label="Date navigator">
175
+ <Arrow direction="left" onClick={() => updateDate(new Date(dateUtc - oneDay))} disabled={disablePrev} />
176
+ <div className="ObDateNavigator-date">{text}</div>
177
+ <Arrow direction="right" onClick={() => updateDate(new Date(dateUtc + oneDay))} disabled={disableNext} />
178
+ {!disableTodayButton && (
179
+ <button type="button" className="ObDateNavigator-today btn-reset" onClick={jumpToToday}>
180
+ {getLocalizedString("Today")}
181
+ </button>
182
+ )}
183
+ <div aria-live="polite" ref={liveRef} style={{ position: "absolute", left: "-9999px" }} />
184
+ </div>
185
+ );
186
+ }