@olenbetong/synergi-react 4.1.0 → 4.1.1

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/es/components/PdfViewer/PdfViewer.js +22 -3
  2. package/package.json +7 -7
  3. package/src/chrome/AppShell/index.tsx +29 -29
  4. package/src/chrome/openReport.ts +34 -34
  5. package/src/colorScheme.ts +81 -81
  6. package/src/components/DateNavigator/index.tsx +186 -186
  7. package/src/components/FilePond.tsx +312 -312
  8. package/src/components/ImageEditor/ImageEditor.tsx +343 -343
  9. package/src/components/ImageEditor/index.ts +9 -9
  10. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  11. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  12. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +403 -403
  13. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  14. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  15. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  16. package/src/components/ImageEditor/useEdgeDetection.ts +127 -127
  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 -139
  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 +212 -212
  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
@@ -2,9 +2,28 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useMemo, useRef, useState } from "react";
3
3
  import { Document, Page, pdfjs } from "react-pdf";
4
4
  import "./PdfViewer.css";
5
- // Use new URL(..., import.meta.url) — understood by Rolldown/Rollup on all platforms,
6
- // including Windows where ?raw query strings are invalid in file paths.
7
- pdfjs.GlobalWorkerOptions.workerSrc = new URL("pdfjs-dist/build/pdf.worker.min.mjs", import.meta.url).toString();
5
+ /*
6
+ * pdf.js parses in a Web Worker that must be loaded from a URL on the page's origin. On the
7
+ * 2026 templates pdfjs-dist comes from the platform bundle through the import map, and the
8
+ * platform serves the worker next to it - so resolve the specifier the way the browser does
9
+ * and step up one level. This makes the viewer platform-only: off the platform (a legacy
10
+ * template bundling this package) the specifier does not resolve, pdf.js logs a warning and
11
+ * parses on the main thread. A `new URL(..., import.meta.url)` fallback would make Vite emit
12
+ * the 1.2 MB worker into every consumer's build output without anything ever serving it.
13
+ */
14
+ function platformWorkerUrl() {
15
+ try {
16
+ return new URL("../pdf.worker.min.js", import.meta.resolve("pdfjs-dist")).toString();
17
+ }
18
+ catch {
19
+ console.warn("PdfViewer: pdfjs-dist is not on the page's import map; pdf.js will parse on the main thread.");
20
+ return undefined;
21
+ }
22
+ }
23
+ let workerUrl = platformWorkerUrl();
24
+ if (workerUrl) {
25
+ pdfjs.GlobalWorkerOptions.workerSrc = workerUrl;
26
+ }
8
27
  export function PdfViewer({ url, file }) {
9
28
  let [numPages, setNumPages] = useState(0);
10
29
  let [error, setError] = useState(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/synergi-react",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Standalone React component for SynergiWeb and Partner Portal",
5
5
  "type": "module",
6
6
  "exports": {
@@ -48,17 +48,17 @@
48
48
  "filepond-plugin-image-transform": "^3.8.8",
49
49
  "localforage": "^1.10.0",
50
50
  "mitt": "^3.0.1",
51
- "pdf-lib": "^1.17.1",
51
+ "pdf-lib": "1.17.1",
52
52
  "pdfjs-dist": "5.7.284",
53
53
  "react": "19.3.0",
54
54
  "react-dom": "19.3.0",
55
- "react-pdf": "^10.5.0",
55
+ "react-pdf": "10.5.0",
56
56
  "zxing-wasm": "3.1.4",
57
57
  "@olenbetong/appframe-core": "2.14.0",
58
+ "@olenbetong/appframe-react": "2.2.1",
58
59
  "@olenbetong/appframe-data": "1.7.2",
59
60
  "@olenbetong/appframe-mui": "7.0.3",
60
- "@olenbetong/appframe-react": "2.2.1",
61
- "@olenbetong/appframe-ds": "1.1.0"
61
+ "@olenbetong/appframe-ds": "1.2.0"
62
62
  },
63
63
  "repository": {
64
64
  "type": "git",
@@ -72,9 +72,9 @@
72
72
  ]
73
73
  },
74
74
  "devDependencies": {
75
- "@digdir/designsystemet-react": "1.21.1",
75
+ "@digdir/designsystemet-react": "1.22.0",
76
76
  "@navikt/aksel-icons": "8.16.2",
77
- "@testing-library/dom": "^10.4.1",
77
+ "@testing-library/dom": "^10.4.2",
78
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",
@@ -1,29 +1,29 @@
1
- import { AppErrorBoundary } from "@olenbetong/appframe-ds";
2
- import type { ReactNode } from "react";
3
-
4
- export type AppShellProps = {
5
- children: ReactNode;
6
- };
7
-
8
- /**
9
- * Standard Synergi app shell: the error boundary around the app.
10
- *
11
- * The site chrome (app menu, user menu, colour scheme, service worker update)
12
- * is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
13
- * bundle the `ob.2026.application` template loads, which marks the page with
14
- * `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
15
- * `ToolbarPortal` and `ToolbarBreadcrumbs`.
16
- *
17
- * This component is Designsystemet-only. Apps that still render MUI components
18
- * should additionally wrap it in `MuiThemeProvider` from
19
- * `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
20
- * tokens into a MUI theme.
21
- */
22
- export function AppShell({ children }: AppShellProps) {
23
- return <AppErrorBoundary>{children}</AppErrorBoundary>;
24
- }
25
-
26
- /** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
27
- export function hasSiteChrome() {
28
- return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
29
- }
1
+ import { AppErrorBoundary } from "@olenbetong/appframe-ds";
2
+ import type { ReactNode } from "react";
3
+
4
+ export type AppShellProps = {
5
+ children: ReactNode;
6
+ };
7
+
8
+ /**
9
+ * Standard Synergi app shell: the error boundary around the app.
10
+ *
11
+ * The site chrome (app menu, user menu, colour scheme, service worker update)
12
+ * is no longer part of the app. It is rendered by the `@olenbetong/synergi-chrome`
13
+ * bundle the `ob.2026.application` template loads, which marks the page with
14
+ * `<html data-ob-chrome="1">`. Toolbar slots stay app owned through
15
+ * `ToolbarPortal` and `ToolbarBreadcrumbs`.
16
+ *
17
+ * This component is Designsystemet-only. Apps that still render MUI components
18
+ * should additionally wrap it in `MuiThemeProvider` from
19
+ * `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
20
+ * tokens into a MUI theme.
21
+ */
22
+ export function AppShell({ children }: AppShellProps) {
23
+ return <AppErrorBoundary>{children}</AppErrorBoundary>;
24
+ }
25
+
26
+ /** Whether the page's template loaded the site chrome (`<html data-ob-chrome="1">`). */
27
+ export function hasSiteChrome() {
28
+ return typeof document !== "undefined" && document.documentElement.dataset.obChrome !== undefined;
29
+ }
@@ -1,34 +1,34 @@
1
- export type OpenReportOptions = {
2
- /**
3
- * Overrides the filter the report was designed with, as a criteria string.
4
- * An empty string starts the launcher with no filter at all.
5
- */
6
- initialFilter?: string | null;
7
- /** The tab shown first. */
8
- defaultTab?: "parameters" | "filter";
9
- };
10
-
11
- type ChromeWithReports = {
12
- openReport?: (reportId: string, options?: OpenReportOptions) => void;
13
- };
14
-
15
- /**
16
- * Opens a report in the site chrome's report launcher, the way the app menu does.
17
- *
18
- * The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
19
- * so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
20
- * On a page without the chrome (a legacy template) the call is logged and ignored.
21
- *
22
- * @example
23
- * ```ts
24
- * openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
25
- * ```
26
- */
27
- export function openReport(reportId: string, options?: OpenReportOptions) {
28
- let chrome = (globalThis as { ob?: { chrome?: ChromeWithReports } }).ob?.chrome;
29
- if (chrome?.openReport) {
30
- chrome.openReport(reportId, options);
31
- } else {
32
- console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
33
- }
34
- }
1
+ export type OpenReportOptions = {
2
+ /**
3
+ * Overrides the filter the report was designed with, as a criteria string.
4
+ * An empty string starts the launcher with no filter at all.
5
+ */
6
+ initialFilter?: string | null;
7
+ /** The tab shown first. */
8
+ defaultTab?: "parameters" | "filter";
9
+ };
10
+
11
+ type ChromeWithReports = {
12
+ openReport?: (reportId: string, options?: OpenReportOptions) => void;
13
+ };
14
+
15
+ /**
16
+ * Opens a report in the site chrome's report launcher, the way the app menu does.
17
+ *
18
+ * The launcher lives in the `@olenbetong/synergi-chrome` bundle the 2026 templates load,
19
+ * so an app never bundles it; this only forwards to `window.ob.chrome.openReport`.
20
+ * On a page without the chrome (a legacy template) the call is logged and ignored.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * openReport("arpt_Production_ElementsDaily", { initialFilter: `[ProjectID] = '${projectId}'` });
25
+ * ```
26
+ */
27
+ export function openReport(reportId: string, options?: OpenReportOptions) {
28
+ let chrome = (globalThis as { ob?: { chrome?: ChromeWithReports } }).ob?.chrome;
29
+ if (chrome?.openReport) {
30
+ chrome.openReport(reportId, options);
31
+ } else {
32
+ console.warn(`openReport(${reportId}): the site chrome is not on this page, so there is no report launcher.`);
33
+ }
34
+ }
@@ -1,81 +1,81 @@
1
- import { useCallback, useEffect, useState } from "react";
2
-
3
- /**
4
- * Color scheme preference (system / light / dark).
5
- *
6
- * The preference lives in the `ob-color-scheme` cookie so the article template
7
- * can read it server side and render `data-color-scheme` on `<html>` and
8
- * `<body>` before the first paint. The site chrome bundle
9
- * (`@olenbetong/synergi-chrome`) owns the same cookie for the toolbar user menu
10
- * and app menu toggles, so all of them write the cookie, apply the attributes,
11
- * and dispatch `COLOR_SCHEME_CHANGE_EVENT` to keep every toggle on the page in sync.
12
- */
13
-
14
- export type ColorSchemePreference = "auto" | "light" | "dark";
15
-
16
- const COOKIE_NAME = "ob-color-scheme";
17
- const COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
18
- const DEFAULT_PREFERENCE: ColorSchemePreference = "auto";
19
- const PREFERENCES: ColorSchemePreference[] = ["auto", "light", "dark"];
20
-
21
- /** Dispatched on `window` whenever the preference changes. */
22
- export const COLOR_SCHEME_CHANGE_EVENT = "ob:colorschemechange";
23
-
24
- function isColorSchemePreference(value: unknown): value is ColorSchemePreference {
25
- return typeof value === "string" && PREFERENCES.includes(value as ColorSchemePreference);
26
- }
27
-
28
- export function getColorSchemePreference(): ColorSchemePreference {
29
- if (typeof document === "undefined") return DEFAULT_PREFERENCE;
30
-
31
- let match = document.cookie.match(new RegExp(`(?:^|;\\s*)${COOKIE_NAME}=([^;]*)`));
32
- let value = match ? decodeURIComponent(match[1]) : null;
33
-
34
- return isColorSchemePreference(value) ? value : DEFAULT_PREFERENCE;
35
- }
36
-
37
- export function setColorSchemePreference(preference: ColorSchemePreference) {
38
- if (typeof document === "undefined" || !isColorSchemePreference(preference)) return;
39
-
40
- let secure = window.location.protocol === "https:" ? ";secure" : "";
41
- document.cookie = `${COOKIE_NAME}=${preference};path=/;max-age=${COOKIE_MAX_AGE};samesite=lax${secure}`;
42
-
43
- /*
44
- * Both elements are updated: `<html>` so the browser applies `color-scheme`
45
- * to scrollbars and native controls, `<body>` because Designsystemet declares
46
- * the light tokens on `:root` as well (`:root, [data-color-scheme="light"]`).
47
- */
48
- document.documentElement.dataset.colorScheme = preference;
49
- if (document.body) document.body.dataset.colorScheme = preference;
50
-
51
- window.dispatchEvent(new CustomEvent(COLOR_SCHEME_CHANGE_EVENT, { detail: preference }));
52
- }
53
-
54
- /** Reads the stored preference and keeps it in sync with other toggles on the page. */
55
- export function useColorSchemePreference(): [ColorSchemePreference, (value: ColorSchemePreference) => void] {
56
- let [preference, setPreference] = useState<ColorSchemePreference>(() => getColorSchemePreference());
57
-
58
- useEffect(() => {
59
- function update() {
60
- setPreference(getColorSchemePreference());
61
- }
62
-
63
- update();
64
-
65
- window.addEventListener(COLOR_SCHEME_CHANGE_EVENT, update);
66
- // Cookies fire no change event, so also pick up changes made in another tab.
67
- document.addEventListener("visibilitychange", update);
68
-
69
- return () => {
70
- window.removeEventListener(COLOR_SCHEME_CHANGE_EVENT, update);
71
- document.removeEventListener("visibilitychange", update);
72
- };
73
- }, []);
74
-
75
- let setValue = useCallback((value: ColorSchemePreference) => {
76
- setColorSchemePreference(value);
77
- setPreference(value);
78
- }, []);
79
-
80
- return [preference, setValue];
81
- }
1
+ import { useCallback, useEffect, useState } from "react";
2
+
3
+ /**
4
+ * Color scheme preference (system / light / dark).
5
+ *
6
+ * The preference lives in the `ob-color-scheme` cookie so the article template
7
+ * can read it server side and render `data-color-scheme` on `<html>` and
8
+ * `<body>` before the first paint. The site chrome bundle
9
+ * (`@olenbetong/synergi-chrome`) owns the same cookie for the toolbar user menu
10
+ * and app menu toggles, so all of them write the cookie, apply the attributes,
11
+ * and dispatch `COLOR_SCHEME_CHANGE_EVENT` to keep every toggle on the page in sync.
12
+ */
13
+
14
+ export type ColorSchemePreference = "auto" | "light" | "dark";
15
+
16
+ const COOKIE_NAME = "ob-color-scheme";
17
+ const COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
18
+ const DEFAULT_PREFERENCE: ColorSchemePreference = "auto";
19
+ const PREFERENCES: ColorSchemePreference[] = ["auto", "light", "dark"];
20
+
21
+ /** Dispatched on `window` whenever the preference changes. */
22
+ export const COLOR_SCHEME_CHANGE_EVENT = "ob:colorschemechange";
23
+
24
+ function isColorSchemePreference(value: unknown): value is ColorSchemePreference {
25
+ return typeof value === "string" && PREFERENCES.includes(value as ColorSchemePreference);
26
+ }
27
+
28
+ export function getColorSchemePreference(): ColorSchemePreference {
29
+ if (typeof document === "undefined") return DEFAULT_PREFERENCE;
30
+
31
+ let match = document.cookie.match(new RegExp(`(?:^|;\\s*)${COOKIE_NAME}=([^;]*)`));
32
+ let value = match ? decodeURIComponent(match[1]) : null;
33
+
34
+ return isColorSchemePreference(value) ? value : DEFAULT_PREFERENCE;
35
+ }
36
+
37
+ export function setColorSchemePreference(preference: ColorSchemePreference) {
38
+ if (typeof document === "undefined" || !isColorSchemePreference(preference)) return;
39
+
40
+ let secure = window.location.protocol === "https:" ? ";secure" : "";
41
+ document.cookie = `${COOKIE_NAME}=${preference};path=/;max-age=${COOKIE_MAX_AGE};samesite=lax${secure}`;
42
+
43
+ /*
44
+ * Both elements are updated: `<html>` so the browser applies `color-scheme`
45
+ * to scrollbars and native controls, `<body>` because Designsystemet declares
46
+ * the light tokens on `:root` as well (`:root, [data-color-scheme="light"]`).
47
+ */
48
+ document.documentElement.dataset.colorScheme = preference;
49
+ if (document.body) document.body.dataset.colorScheme = preference;
50
+
51
+ window.dispatchEvent(new CustomEvent(COLOR_SCHEME_CHANGE_EVENT, { detail: preference }));
52
+ }
53
+
54
+ /** Reads the stored preference and keeps it in sync with other toggles on the page. */
55
+ export function useColorSchemePreference(): [ColorSchemePreference, (value: ColorSchemePreference) => void] {
56
+ let [preference, setPreference] = useState<ColorSchemePreference>(() => getColorSchemePreference());
57
+
58
+ useEffect(() => {
59
+ function update() {
60
+ setPreference(getColorSchemePreference());
61
+ }
62
+
63
+ update();
64
+
65
+ window.addEventListener(COLOR_SCHEME_CHANGE_EVENT, update);
66
+ // Cookies fire no change event, so also pick up changes made in another tab.
67
+ document.addEventListener("visibilitychange", update);
68
+
69
+ return () => {
70
+ window.removeEventListener(COLOR_SCHEME_CHANGE_EVENT, update);
71
+ document.removeEventListener("visibilitychange", update);
72
+ };
73
+ }, []);
74
+
75
+ let setValue = useCallback((value: ColorSchemePreference) => {
76
+ setColorSchemePreference(value);
77
+ setPreference(value);
78
+ }, []);
79
+
80
+ return [preference, setValue];
81
+ }