@olenbetong/synergi-react 2.8.0 → 3.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 (128) hide show
  1. package/dist/styles/styles.css.map +1 -1
  2. package/es/chrome/AppShell/index.d.ts +8 -0
  3. package/es/chrome/AppShell/index.js +10 -130
  4. package/es/components/ImageEditor/ImageEditor.css +10 -0
  5. package/es/components/ImageEditor/ImageEditor.d.ts +12 -0
  6. package/es/components/ImageEditor/ImageEditor.js +27 -6
  7. package/es/components/ImageEditor/index.d.ts +3 -0
  8. package/es/components/ImageEditor/index.js +3 -0
  9. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
  10. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
  11. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
  12. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
  13. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
  14. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
  15. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
  16. package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
  17. package/es/components/ImageEditor/useEdgeDetection.js +11 -30
  18. package/es/components/ImageEditor/useImageHistory.d.ts +6 -1
  19. package/es/components/ImageEditor/useImageHistory.js +21 -23
  20. package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
  21. package/es/components/ImageEditor/useOpenCV.js +108 -42
  22. package/es/components/SplitContainer/index.js +2 -4
  23. package/es/elements/ElementDamage/DamageFormButtons.d.ts +2 -3
  24. package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
  25. package/es/elements/ElementDamage/TransportElementSelect.d.ts +1 -2
  26. package/es/elements/index.d.ts +5 -0
  27. package/es/elements/index.js +5 -0
  28. package/es/filter/ChipListInput.d.ts +13 -0
  29. package/es/filter/ChipListInput.js +34 -0
  30. package/es/filter/FilterBuilder.css +152 -0
  31. package/es/filter/FilterBuilder.d.ts +115 -0
  32. package/es/filter/FilterBuilder.js +146 -0
  33. package/es/filter/FilterBuilder.test.d.ts +1 -0
  34. package/es/filter/FilterBuilder.test.js +120 -0
  35. package/es/filter/FilterEditor.css +231 -0
  36. package/es/filter/FilterEditor.d.ts +17 -0
  37. package/es/filter/FilterEditor.js +38 -0
  38. package/es/filter/FilterEditor.test.d.ts +1 -0
  39. package/es/filter/FilterEditor.test.js +183 -0
  40. package/es/filter/FilterGroupEditor.d.ts +22 -0
  41. package/es/filter/FilterGroupEditor.js +34 -0
  42. package/es/filter/FilterNameDialog.css +22 -0
  43. package/es/filter/FilterNameDialog.d.ts +18 -0
  44. package/es/filter/FilterNameDialog.js +32 -0
  45. package/es/filter/FilterRow.d.ts +14 -0
  46. package/es/filter/FilterRow.js +32 -0
  47. package/es/filter/FilterShareDialog.css +28 -0
  48. package/es/filter/FilterShareDialog.d.ts +23 -0
  49. package/es/filter/FilterShareDialog.js +63 -0
  50. package/es/filter/FilterStringField.d.ts +15 -0
  51. package/es/filter/FilterStringField.js +37 -0
  52. package/es/filter/FilterValueEditor.d.ts +16 -0
  53. package/es/filter/FilterValueEditor.js +85 -0
  54. package/es/filter/SavedFilterTree.css +107 -0
  55. package/es/filter/SavedFilterTree.d.ts +45 -0
  56. package/es/filter/SavedFilterTree.js +44 -0
  57. package/es/filter/SavedFilterTree.test.d.ts +1 -0
  58. package/es/filter/SavedFilterTree.test.js +75 -0
  59. package/es/filter/index.d.ts +11 -0
  60. package/es/filter/index.js +10 -0
  61. package/es/filter/types.d.ts +34 -0
  62. package/es/filter/types.js +1 -0
  63. package/es/index.d.ts +2 -1
  64. package/es/index.js +6 -1
  65. package/es/mui/MuiThemeProvider.d.ts +24 -0
  66. package/es/mui/MuiThemeProvider.js +152 -0
  67. package/es/mui/index.d.ts +1 -0
  68. package/es/mui/index.js +1 -0
  69. package/es/report/ReportLauncher.css +147 -0
  70. package/es/report/ReportLauncher.d.ts +55 -0
  71. package/es/report/ReportLauncher.js +142 -0
  72. package/es/report/ReportLauncher.test.d.ts +1 -0
  73. package/es/report/ReportLauncher.test.js +231 -0
  74. package/es/report/ReportParameters.css +29 -0
  75. package/es/report/ReportParameters.d.ts +46 -0
  76. package/es/report/ReportParameters.js +65 -0
  77. package/es/report/ReportParameters.test.d.ts +1 -0
  78. package/es/report/ReportParameters.test.js +84 -0
  79. package/es/report/index.d.ts +2 -0
  80. package/es/report/index.js +2 -0
  81. package/es/test/setup.d.ts +1 -0
  82. package/es/test/setup.js +6 -0
  83. package/package.json +22 -7
  84. package/src/chrome/AppShell/index.tsx +34 -171
  85. package/src/components/ImageEditor/ImageEditor.css +10 -0
  86. package/src/components/ImageEditor/ImageEditor.tsx +40 -5
  87. package/src/components/ImageEditor/index.ts +1 -0
  88. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
  89. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
  90. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
  91. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
  92. package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
  93. package/src/components/ImageEditor/useImageHistory.ts +27 -19
  94. package/src/components/ImageEditor/useOpenCV.ts +112 -62
  95. package/src/components/LinkedCardList/index.scss +4 -2
  96. package/src/components/ProgressBar/index.scss +4 -2
  97. package/src/components/SplitContainer/index.tsx +3 -4
  98. package/src/filter/ChipListInput.tsx +79 -0
  99. package/src/filter/FilterBuilder.css +152 -0
  100. package/src/filter/FilterBuilder.test.tsx +153 -0
  101. package/src/filter/FilterBuilder.tsx +435 -0
  102. package/src/filter/FilterEditor.css +231 -0
  103. package/src/filter/FilterEditor.test.tsx +259 -0
  104. package/src/filter/FilterEditor.tsx +74 -0
  105. package/src/filter/FilterGroupEditor.tsx +160 -0
  106. package/src/filter/FilterNameDialog.css +22 -0
  107. package/src/filter/FilterNameDialog.tsx +81 -0
  108. package/src/filter/FilterRow.tsx +117 -0
  109. package/src/filter/FilterShareDialog.css +28 -0
  110. package/src/filter/FilterShareDialog.tsx +201 -0
  111. package/src/filter/FilterStringField.tsx +77 -0
  112. package/src/filter/FilterValueEditor.tsx +220 -0
  113. package/src/filter/SavedFilterTree.css +107 -0
  114. package/src/filter/SavedFilterTree.test.tsx +94 -0
  115. package/src/filter/SavedFilterTree.tsx +222 -0
  116. package/src/filter/index.ts +11 -0
  117. package/src/filter/types.ts +38 -0
  118. package/src/index.ts +39 -1
  119. package/src/mui/MuiThemeProvider.tsx +174 -0
  120. package/src/mui/index.ts +1 -0
  121. package/src/report/ReportLauncher.css +147 -0
  122. package/src/report/ReportLauncher.test.tsx +281 -0
  123. package/src/report/ReportLauncher.tsx +421 -0
  124. package/src/report/ReportParameters.css +29 -0
  125. package/src/report/ReportParameters.test.tsx +133 -0
  126. package/src/report/ReportParameters.tsx +198 -0
  127. package/src/report/index.ts +2 -0
  128. package/src/test/setup.ts +8 -0
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "./ReportParameters.css";
3
+ import { Checkbox, Field, FieldDescription, Label, Select, Textfield } from "@digdir/designsystemet-react";
4
+ import { coerceParameterValue, getLocalizedString, } from "@olenbetong/appframe-core";
5
+ import { useParameterOptions } from "@olenbetong/appframe-react";
6
+ import { Combobox } from "@olenbetong/appframe-ds";
7
+ import clsx from "clsx";
8
+ import { useId } from "react";
9
+ /**
10
+ * The parameter form of the report launcher.
11
+ *
12
+ * Reports rarely have parameters, so this renders nothing at all when the list
13
+ * is empty and the launcher can include it unconditionally.
14
+ *
15
+ * Each parameter gets the editor its metadata asks for: a lookup combobox when
16
+ * it is backed by a record source, a select when it has a fixed item list, and
17
+ * otherwise an editor for its data type. Values are coerced to the parameter's
18
+ * type as they are entered, so what the caller holds is what gets sent to the
19
+ * report.
20
+ *
21
+ * @example
22
+ * ```jsx
23
+ * let { parameters, defaultValues } = useReport(reportId);
24
+ * let [values, setValues] = useState(defaultValues);
25
+ *
26
+ * <ReportParameters parameters={parameters} values={values} onChange={setValues} />
27
+ * ```
28
+ */
29
+ export function ReportParameters({ parameters, values, onChange, readOnly, legend = getLocalizedString("Parameters"), className, "data-size": size = "sm", }) {
30
+ if (parameters.length === 0)
31
+ return null;
32
+ function update(parameter, value) {
33
+ onChange({ ...values, [parameter.name]: value });
34
+ }
35
+ return (_jsxs("fieldset", { className: clsx("ObReportParameters-root", className), "data-size": size, children: [legend && _jsx("legend", { className: "ObReportParameters-legend", children: legend }), _jsx("div", { className: "ObReportParameters-grid", children: parameters.map((parameter) => (_jsx(ReportParameterField, { parameter: parameter, value: values[parameter.name] ?? null, onChange: (value) => update(parameter, value), readOnly: readOnly, size: size }, parameter.name))) })] }));
36
+ }
37
+ /** The editor for a single parameter. */
38
+ export function ReportParameterField({ parameter, value, onChange, readOnly, size }) {
39
+ // The hook returns nothing for parameters that are not lookups, so it can be
40
+ // called for every parameter.
41
+ let { options, loading } = useParameterOptions(parameter);
42
+ let id = useId();
43
+ let commonProps = {
44
+ "data-size": size,
45
+ label: parameter.label,
46
+ description: parameter.description ?? undefined,
47
+ readOnly,
48
+ };
49
+ switch (parameter.editor) {
50
+ case "boolean":
51
+ return (_jsx("div", { className: "ObReportParameters-field", children: _jsx(Checkbox, { "data-size": size, label: parameter.label, description: parameter.description ?? undefined, disabled: readOnly, checked: value === true, onChange: (event) => onChange(event.target.checked) }) }));
52
+ case "select":
53
+ return (_jsx("div", { className: "ObReportParameters-field", children: _jsxs(Field, { "data-size": size, children: [_jsx(Label, { htmlFor: id, children: parameter.label }), parameter.description && _jsx(FieldDescription, { children: parameter.description }), _jsxs(Select, { id: id, readOnly: readOnly, value: value === null ? "" : String(value), onChange: (event) => onChange(coerceParameterValue(parameter, event.currentTarget.value)), children: [_jsx(Select.Option, { value: "", children: getLocalizedString("Not selected") }), parameter.items.map((item) => (_jsx(Select.Option, { value: item, children: item }, item)))] })] }) }));
54
+ case "lookup":
55
+ return (_jsx("div", { className: "ObReportParameters-field", children: _jsx(Combobox, { ...commonProps, loading: loading, options: options, value: options.find((option) => option.value === String(value ?? "")) ?? null, getOptionLabel: (option) => option.label, getOptionKey: (option) => option.value, isOptionEqualToValue: (option, selected) => option.value === selected.value, onChange: (_event, option) => onChange(option ? coerceParameterValue(parameter, option.value) : null) }) }));
56
+ case "number":
57
+ return (_jsx("div", { className: "ObReportParameters-field", children: _jsx(Textfield, { ...commonProps, type: "number",
58
+ // The designer's `Double` parameters are free-form decimals.
59
+ step: parameter.type === "Integer" ? 1 : "any", value: value === null ? "" : String(value), onChange: (event) => onChange(coerceParameterValue(parameter, event.target.value)) }) }));
60
+ case "date":
61
+ return (_jsx("div", { className: "ObReportParameters-field", children: _jsx(Textfield, { ...commonProps, type: "date", value: value === null ? "" : String(value), onChange: (event) => onChange(event.target.value === "" ? null : event.target.value) }) }));
62
+ default:
63
+ return (_jsx("div", { className: "ObReportParameters-field", children: _jsx(Textfield, { ...commonProps, value: value === null ? "" : String(value), onChange: (event) => onChange(event.target.value === "" ? null : event.target.value) }) }));
64
+ }
65
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,84 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { describe, expect, it, vi } from "vitest";
5
+ let parameterOptions = [];
6
+ vi.mock("@olenbetong/appframe-react", async (importOriginal) => ({
7
+ ...(await importOriginal()),
8
+ useParameterOptions: () => ({ options: parameterOptions, loading: false, error: null }),
9
+ }));
10
+ const { ReportParameters } = await import("./ReportParameters.js");
11
+ function parameter(overrides) {
12
+ return {
13
+ label: overrides.name,
14
+ description: null,
15
+ type: "String",
16
+ editor: "text",
17
+ defaultValue: null,
18
+ items: [],
19
+ recordSource: null,
20
+ valueMember: null,
21
+ displayMember: null,
22
+ sortOrder: 0,
23
+ lookupWidth: null,
24
+ lookupHeight: null,
25
+ ...overrides,
26
+ };
27
+ }
28
+ describe("ReportParameters", () => {
29
+ it("renders nothing when the report has no parameters", () => {
30
+ let { container } = render(_jsx(ReportParameters, { parameters: [], values: {}, onChange: vi.fn() }));
31
+ expect(container).toBeEmptyDOMElement();
32
+ });
33
+ it("renders a labelled editor per parameter with the description as help text", () => {
34
+ render(_jsx(ReportParameters, { parameters: [
35
+ parameter({ name: "Period", label: "Periode", type: "Integer", editor: "number" }),
36
+ parameter({ name: "Comment", label: "Kommentar", description: "Vises på forsiden" }),
37
+ ], values: { Period: 202601, Comment: "" }, onChange: vi.fn() }));
38
+ expect(screen.getByLabelText("Periode")).toHaveValue(202601);
39
+ expect(screen.getByLabelText("Kommentar")).toBeInTheDocument();
40
+ expect(screen.getByText("Vises på forsiden")).toBeInTheDocument();
41
+ });
42
+ it("coerces numeric input to a number", async () => {
43
+ let onChange = vi.fn();
44
+ let user = userEvent.setup();
45
+ render(_jsx(ReportParameters, { parameters: [parameter({ name: "Period", type: "Integer", editor: "number" })], values: { Period: null }, onChange: onChange }));
46
+ await user.type(screen.getByLabelText("Period"), "7");
47
+ expect(onChange).toHaveBeenCalledWith({ Period: 7 });
48
+ });
49
+ it("renders a checkbox for boolean parameters", async () => {
50
+ let onChange = vi.fn();
51
+ let user = userEvent.setup();
52
+ render(_jsx(ReportParameters, { parameters: [parameter({ name: "IncludeClosed", type: "Boolean", editor: "boolean" })], values: { IncludeClosed: false }, onChange: onChange }));
53
+ await user.click(screen.getByLabelText("IncludeClosed"));
54
+ expect(onChange).toHaveBeenCalledWith({ IncludeClosed: true });
55
+ });
56
+ it("renders a select for parameters with a fixed item list", async () => {
57
+ let onChange = vi.fn();
58
+ let user = userEvent.setup();
59
+ render(_jsx(ReportParameters, { parameters: [parameter({ name: "Type", editor: "select", items: ["Alle", "Åpne"] })], values: { Type: "Alle" }, onChange: onChange }));
60
+ await user.selectOptions(screen.getByLabelText("Type"), "Åpne");
61
+ expect(onChange).toHaveBeenCalledWith({ Type: "Åpne" });
62
+ });
63
+ it("renders lookup options from the record source", () => {
64
+ parameterOptions = [
65
+ { value: "1", label: "1 - Første" },
66
+ { value: "2", label: "2 - Andre" },
67
+ ];
68
+ render(_jsx(ReportParameters, { parameters: [
69
+ parameter({
70
+ name: "Type",
71
+ editor: "lookup",
72
+ valueMember: "ID",
73
+ recordSource: {
74
+ viewName: "aviw_Test_Types",
75
+ columns: [{ name: "ID", type: "number" }],
76
+ whereClause: null,
77
+ filterString: null,
78
+ maxRecords: null,
79
+ },
80
+ }),
81
+ ], values: { Type: "2" }, onChange: vi.fn() }));
82
+ expect(screen.getByLabelText("Type")).toHaveValue("2 - Andre");
83
+ });
84
+ });
@@ -0,0 +1,2 @@
1
+ export { ReportLauncher, type ReportLauncherProps, type ReportLauncherTab } from "./ReportLauncher.js";
2
+ export { ReportParameterField, ReportParameters, type ReportParametersProps } from "./ReportParameters.js";
@@ -0,0 +1,2 @@
1
+ export { ReportLauncher } from "./ReportLauncher.js";
2
+ export { ReportParameterField, ReportParameters } from "./ReportParameters.js";
@@ -0,0 +1 @@
1
+ import "@testing-library/jest-dom/vitest";
@@ -0,0 +1,6 @@
1
+ import "@testing-library/jest-dom/vitest";
2
+ import { cleanup } from "@testing-library/react";
3
+ import { afterEach } from "vitest";
4
+ afterEach(() => {
5
+ cleanup();
6
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/synergi-react",
3
- "version": "2.8.0",
3
+ "version": "3.0.0",
4
4
  "description": "Standalone React component for SynergiWeb and Partner Portal",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,6 +11,14 @@
11
11
  "./elements": {
12
12
  "types": "./es/elements/index.d.ts",
13
13
  "import": "./es/elements/index.js"
14
+ },
15
+ "./mui": {
16
+ "types": "./es/mui/index.d.ts",
17
+ "import": "./es/mui/index.js"
18
+ },
19
+ "./pdf": {
20
+ "types": "./es/components/PdfViewer/index.d.ts",
21
+ "import": "./es/components/PdfViewer/index.js"
14
22
  }
15
23
  },
16
24
  "files": [
@@ -44,10 +52,11 @@
44
52
  "pdf-lib": "^1.17.1",
45
53
  "pdfjs-dist": "5.7.284",
46
54
  "react-pdf": "^10.4.1",
47
- "@olenbetong/appframe-core": "2.11.10",
48
- "@olenbetong/appframe-data": "1.5.0",
49
- "@olenbetong/appframe-react": "2.0.0",
50
- "@olenbetong/appframe-mui": "6.6.0"
55
+ "@olenbetong/appframe-core": "2.12.0",
56
+ "@olenbetong/appframe-ds": "0.8.0",
57
+ "@olenbetong/appframe-mui": "6.6.1",
58
+ "@olenbetong/appframe-react": "2.1.0",
59
+ "@olenbetong/appframe-data": "1.6.0"
51
60
  },
52
61
  "repository": {
53
62
  "type": "git",
@@ -63,16 +72,22 @@
63
72
  "devDependencies": {
64
73
  "@digdir/designsystemet-react": "1.18.0",
65
74
  "@navikt/aksel-icons": "8.16.1",
75
+ "@testing-library/jest-dom": "^7.0.1",
76
+ "@testing-library/dom": "^10.4.1",
77
+ "@testing-library/react": "16.3.2",
78
+ "@testing-library/user-event": "^14.6.3",
79
+ "happy-dom": "^20.11.2",
66
80
  "react": "19.2.8",
67
81
  "react-dom": "19.2.8",
68
82
  "replace-in-files": "^3.0.0"
69
83
  },
70
84
  "optionalDependencies": {},
71
85
  "scripts": {
72
- "build": "pnpm run build:tsc && pnpm run build:tsc:post && pnpm run build:sass && pnpm run build:sass:components",
86
+ "build": "pnpm run build:tsc && pnpm test && pnpm run build:tsc:post && pnpm run build:sass && pnpm run build:sass:components",
73
87
  "build:sass": "sass ./src/index.scss ./dist/styles/styles.css --source-map-urls=relative --style compressed",
74
88
  "build:sass:components": "node ./scripts/buildSassComponents.mjs",
75
89
  "build:tsc:post": "node ./scripts/replaceCss.mjs",
76
- "build:tsc": "node --no-warnings ../../scripts/clean.ts ./es tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json"
90
+ "build:tsc": "node --no-warnings ../../scripts/clean.ts ./es tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json",
91
+ "test": "vitest run"
77
92
  }
78
93
  }
@@ -1,8 +1,6 @@
1
- import { StyledEngineProvider, ThemeProvider } from "@mui/material";
2
- import { createTheme as muiCreateTheme } from "@mui/material/styles";
3
1
  import { getLocalizedString } from "@olenbetong/appframe-core";
4
- import { AppErrorBoundary } from "@olenbetong/appframe-mui";
5
- import { type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
2
+ import { AppErrorBoundary } from "@olenbetong/appframe-ds";
3
+ import { type ReactNode, useCallback, useMemo, useState } from "react";
6
4
  import { createPortal } from "react-dom";
7
5
 
8
6
  import { AppMenu, type AppMenuArticle } from "../AppMenu/AppMenu.js";
@@ -89,141 +87,19 @@ const dsAppMenuUser = af.data.generateApiDataObject<AppMenuUser>({
89
87
  },
90
88
  });
91
89
 
92
- function getColorScheme(): "light" | "dark" {
93
- let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
94
-
95
- if (scheme === "auto") {
96
- return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
97
- }
98
-
99
- return scheme === "dark" ? "dark" : "light";
100
- }
101
-
102
- /**
103
- * Tracks the color scheme Designsystemet is rendering with. The article template
104
- * sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
105
- * OS preference (used when the scheme is `auto`).
106
- */
107
- function useColorScheme() {
108
- let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
109
-
110
- useEffect(() => {
111
- function update() {
112
- setScheme(getColorScheme());
113
- }
114
-
115
- update();
116
-
117
- let observer = new MutationObserver(update);
118
- observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
119
- observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
120
-
121
- let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
122
- media?.addEventListener("change", update);
123
-
124
- return () => {
125
- observer.disconnect();
126
- media?.removeEventListener("change", update);
127
- };
128
- }, []);
129
-
130
- return scheme;
131
- }
132
-
133
- function buildMuiTheme(mode: "light" | "dark") {
134
- const s = getComputedStyle(document.body);
135
- const get = (v: string) => s.getPropertyValue(v).trim();
136
- const isDark = mode === "dark";
137
-
138
- return muiCreateTheme({
139
- palette: {
140
- mode,
141
- primary: {
142
- main: get("--ds-color-brand-base-default") || "#116069",
143
- dark: get("--ds-color-brand-base-hover") || "#0d4b52",
144
- contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
145
- },
146
- secondary: {
147
- main: get("--ds-color-brand-light-base-default") || "#1a95a2",
148
- },
149
- background: {
150
- default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
151
- paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
152
- },
153
- text: {
154
- primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
155
- secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
156
- },
157
- divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
158
- },
159
- typography: {
160
- fontFamily: [
161
- "-apple-system",
162
- "BlinkMacSystemFont",
163
- '"Segoe UI"',
164
- "Roboto",
165
- '"Helvetica Neue"',
166
- "Arial",
167
- "sans-serif",
168
- '"Apple Color Emoji"',
169
- '"Segoe UI Emoji"',
170
- '"Segoe UI Symbol"',
171
- ].join(","),
172
- },
173
- components: {
174
- MuiTypography: {
175
- styleOverrides: {
176
- h1: { fontSize: "2.488rem" },
177
- h2: { fontSize: "2.074rem" },
178
- h3: { fontSize: "1.728rem" },
179
- h4: { fontSize: "1.44rem" },
180
- h5: { fontSize: "1.2rem" },
181
- h6: { fontSize: "1rem" },
182
- },
183
- },
184
- MuiAppBar: {
185
- styleOverrides: {
186
- root: {
187
- "& .MuiTypography-h1": {
188
- fontSize: "1.25rem",
189
- fontWeight: "500",
190
- },
191
- },
192
- },
193
- },
194
- MuiButton: {
195
- styleOverrides: {
196
- root: { borderRadius: 2 },
197
- },
198
- },
199
- MuiDialogTitle: {
200
- styleOverrides: {
201
- root: {
202
- fontSize: "1.2rem",
203
- fontWeight: 500,
204
- paddingLeft: 16,
205
- paddingRight: 16,
206
- },
207
- },
208
- },
209
- MuiFormLabel: {
210
- styleOverrides: {
211
- root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
212
- },
213
- },
214
- MuiTextField: { defaultProps: { variant: "filled" } },
215
- MuiSelect: { defaultProps: { variant: "filled" } },
216
- MuiFormControl: { defaultProps: { variant: "filled" } },
217
- },
218
- });
219
- }
220
-
221
90
  export type AppShellProps = {
222
91
  children: ReactNode;
223
92
  };
224
93
 
94
+ /**
95
+ * Standard Synergi app chrome: error boundary, app menu and the toolbar toggle.
96
+ *
97
+ * This component is Designsystemet-only. Apps that still render MUI components
98
+ * should additionally wrap it in `MuiThemeProvider` from
99
+ * `@olenbetong/synergi-react/mui`, which bridges the Designsystemet colour
100
+ * tokens into a MUI theme.
101
+ */
225
102
  export function AppShell({ children }: AppShellProps) {
226
- const colorScheme = useColorScheme();
227
103
  const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
228
104
  const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
229
105
 
@@ -242,46 +118,33 @@ export function AppShell({ children }: AppShellProps) {
242
118
  await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
243
119
  }, []);
244
120
 
245
- // Rebuilt whenever the color scheme changes so MUI components (notably the
246
- // data grid) follow Designsystemet instead of staying stuck in light mode.
247
- // Also re-read after mount, since the stylesheets are imported from JS and
248
- // the CSS variables aren't necessarily resolved during the first render.
249
- const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
250
- useEffect(() => {
251
- setTheme(buildMuiTheme(colorScheme));
252
- }, [colorScheme]);
253
-
254
121
  const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
255
122
 
256
123
  return (
257
- <StyledEngineProvider injectFirst>
258
- <ThemeProvider theme={theme}>
259
- <AppErrorBoundary>
260
- {appMenuSlot &&
261
- createPortal(
262
- <AppMenuToggle
263
- open={isAppMenuOpen}
264
- hasUpdate={isUpdateAvailable}
265
- aria-controls="ob-app-menu"
266
- onClick={() => setIsAppMenuOpen((open) => !open)}
267
- />,
268
- appMenuSlot,
269
- )}
270
- <AppMenu
271
- id="ob-app-menu"
272
- dataObject={dsMenuArticles}
273
- userDataObject={dsAppMenuUser}
274
- categories={categories}
275
- homeLink={homeLink}
276
- onToggleFavorite={toggleFavorite}
277
- hasUpdate={isUpdateAvailable}
278
- onInstallUpdate={installUpdate}
124
+ <AppErrorBoundary>
125
+ {appMenuSlot &&
126
+ createPortal(
127
+ <AppMenuToggle
279
128
  open={isAppMenuOpen}
280
- onClose={() => setIsAppMenuOpen(false)}
281
- />
282
- {children}
283
- </AppErrorBoundary>
284
- </ThemeProvider>
285
- </StyledEngineProvider>
129
+ hasUpdate={isUpdateAvailable}
130
+ aria-controls="ob-app-menu"
131
+ onClick={() => setIsAppMenuOpen((open) => !open)}
132
+ />,
133
+ appMenuSlot,
134
+ )}
135
+ <AppMenu
136
+ id="ob-app-menu"
137
+ dataObject={dsMenuArticles}
138
+ userDataObject={dsAppMenuUser}
139
+ categories={categories}
140
+ homeLink={homeLink}
141
+ onToggleFavorite={toggleFavorite}
142
+ hasUpdate={isUpdateAvailable}
143
+ onInstallUpdate={installUpdate}
144
+ open={isAppMenuOpen}
145
+ onClose={() => setIsAppMenuOpen(false)}
146
+ />
147
+ {children}
148
+ </AppErrorBoundary>
286
149
  );
287
150
  }
@@ -167,6 +167,16 @@
167
167
  line-height: 0; /* remove gap under canvas */
168
168
  }
169
169
 
170
+ /* Transparent drawing surface for the rectangle crop mode. Sits above the canvas
171
+ but below the corner handles (which are hidden while this mode is active). */
172
+ .crop-draw-surface {
173
+ position: absolute;
174
+ inset: 0;
175
+ cursor: crosshair;
176
+ touch-action: none;
177
+ z-index: 8;
178
+ }
179
+
170
180
  /* ── Redact plugin ───────────────────────────────────────────── */
171
181
 
172
182
  .redact-root {
@@ -1,7 +1,7 @@
1
1
  import { Button, Spinner, Tooltip } from "@digdir/designsystemet-react";
2
2
  import { ArrowCirclepathIcon, ArrowLeftIcon, ArrowRedoIcon, ArrowUndoIcon, CheckmarkIcon } from "@navikt/aksel-icons";
3
3
  import { getLocalizedString } from "@olenbetong/appframe-core";
4
- import { forwardRef, useImperativeHandle, useMemo, useState } from "react";
4
+ import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
5
5
 
6
6
  import "./ImageEditor.css";
7
7
  import { ResponsiveButton } from "./ResponsiveButton.js";
@@ -13,6 +13,18 @@ import { useIsSmall } from "./useIsSmall.js";
13
13
  export type ImageEditorRef = {
14
14
  /** Returns the current edited blob, or null if no edits have been applied since the last source image. */
15
15
  getCurrentBlob: () => Blob | null;
16
+ /**
17
+ * Runs a registered action plugin (e.g. `"rotate-cw"`) against the current image.
18
+ * Use this instead of calling `plugin.execute()` directly so external toolbars and
19
+ * keyboard shortcuts share the editor's image state and undo history.
20
+ * Resolves once the resulting image has been applied.
21
+ */
22
+ executeAction: (pluginId: string) => Promise<void>;
23
+ /**
24
+ * Resolves once every queued action has been applied. Await this before `getCurrentBlob()`
25
+ * to be sure an action started moments earlier is included.
26
+ */
27
+ whenIdle: () => Promise<void>;
16
28
  };
17
29
 
18
30
  interface Props {
@@ -43,16 +55,39 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
43
55
  let disabled = busy || history.replaying;
44
56
  let isSmall = useIsSmall();
45
57
 
58
+ // Keeps async/imperative callers working against the latest history state instead of
59
+ // the snapshot captured when their closure was created.
60
+ let historyRef = useRef(history);
61
+ historyRef.current = history;
62
+ // Serialises every action (toolbar clicks and imperative calls alike) so rapid
63
+ // invocations each build on the previous result instead of racing on a stale image.
64
+ let actionQueueRef = useRef<Promise<void>>(Promise.resolve());
65
+
46
66
  useImperativeHandle(ref, () => ({
47
- getCurrentBlob: () => history.currentBlob,
67
+ getCurrentBlob: () => historyRef.current.getCurrentBlob(),
68
+ whenIdle: () => actionQueueRef.current,
69
+ executeAction: (pluginId: string) => {
70
+ let plugin = plugins.find((p): p is ActionPlugin => p.type === "action" && p.id === pluginId);
71
+ if (!plugin) {
72
+ console.warn(`[ImageEditor] No action plugin registered with id "${pluginId}"`);
73
+ return Promise.resolve();
74
+ }
75
+ return enqueueAction(plugin);
76
+ },
48
77
  }));
49
78
 
79
+ function enqueueAction(plugin: ActionPlugin) {
80
+ let next = actionQueueRef.current.then(() => executeAction(plugin));
81
+ actionQueueRef.current = next.catch(() => {});
82
+ return next;
83
+ }
84
+
50
85
  async function executeAction(plugin: ActionPlugin) {
51
86
  setBusy(true);
52
87
  try {
53
- let blob = await plugin.execute(history.currentImageUrl);
88
+ let blob = await plugin.execute(historyRef.current.getCurrentImageUrl());
54
89
  let actions: EditAction[] = [{ type: plugin.id, params: {} }];
55
- history.applyActions(blob, actions);
90
+ historyRef.current.applyActions(blob, actions);
56
91
  } finally {
57
92
  setBusy(false);
58
93
  }
@@ -186,7 +221,7 @@ export const ImageEditor = forwardRef<ImageEditorRef, Props>(function ImageEdito
186
221
  key={p.id}
187
222
  plugin={p}
188
223
  busy={disabled}
189
- onExecute={() => executeAction(p)}
224
+ onExecute={() => enqueueAction(p)}
190
225
  isSmall={isSmall}
191
226
  />
192
227
  ),
@@ -6,3 +6,4 @@ export { redactPlugin } from "./plugins/redactPlugin/index.js";
6
6
  export { zoomPlugin } from "./plugins/zoomPlugin/index.js";
7
7
  export { rotateCcwPlugin, rotateCwPlugin } from "./plugins/rotatePlugin.js";
8
8
  export type { ActionPlugin, EditAction, Plugin, ToolPlugin, ViewPlugin } from "./types.js";
9
+ export { configureOpenCV, DEFAULT_OPENCV_URLS, loadOpenCV } from "./useOpenCV.js";