@olenbetong/synergi-react 2.9.0 → 3.1.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/es/chrome/AppShell/index.d.ts +8 -0
- package/es/chrome/AppShell/index.js +10 -130
- package/es/components/ImageEditor/ImageEditor.css +10 -0
- package/es/components/ImageEditor/index.d.ts +1 -0
- package/es/components/ImageEditor/index.js +1 -0
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
- package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
- package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
- package/es/components/ImageEditor/useEdgeDetection.js +11 -30
- package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
- package/es/components/ImageEditor/useOpenCV.js +108 -42
- package/es/components/SplitContainer/index.js +2 -4
- package/es/filter/index.d.ts +8 -0
- package/es/filter/index.js +8 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +6 -1
- package/es/mui/MuiThemeProvider.d.ts +24 -0
- package/es/mui/MuiThemeProvider.js +152 -0
- package/es/mui/index.d.ts +1 -0
- package/es/mui/index.js +1 -0
- package/es/report/ReportLauncher.css +147 -0
- package/es/report/ReportLauncher.d.ts +55 -0
- package/es/report/ReportLauncher.js +142 -0
- package/es/report/ReportLauncher.test.d.ts +1 -0
- package/es/report/ReportLauncher.test.js +231 -0
- package/es/report/ReportParameters.css +29 -0
- package/es/report/ReportParameters.d.ts +46 -0
- package/es/report/ReportParameters.js +65 -0
- package/es/report/ReportParameters.test.d.ts +1 -0
- package/es/report/ReportParameters.test.js +84 -0
- package/es/report/index.d.ts +2 -0
- package/es/report/index.js +2 -0
- package/es/test/setup.d.ts +1 -0
- package/es/test/setup.js +6 -0
- package/package.json +22 -7
- package/src/chrome/AppShell/index.tsx +34 -171
- package/src/components/ImageEditor/ImageEditor.css +15 -5
- package/src/components/ImageEditor/ImageEditor.tsx +1 -1
- package/src/components/ImageEditor/index.ts +1 -0
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
- package/src/components/ImageEditor/useOpenCV.ts +112 -62
- package/src/components/SplitContainer/index.tsx +3 -4
- package/src/filter/index.ts +34 -0
- package/src/index.ts +39 -1
- package/src/mui/MuiThemeProvider.tsx +174 -0
- package/src/mui/index.ts +1 -0
- package/src/report/ReportLauncher.css +147 -0
- package/src/report/ReportLauncher.test.tsx +281 -0
- package/src/report/ReportLauncher.tsx +420 -0
- package/src/report/ReportParameters.css +29 -0
- package/src/report/ReportParameters.test.tsx +133 -0
- package/src/report/ReportParameters.tsx +198 -0
- package/src/report/index.ts +2 -0
- package/src/test/setup.ts +8 -0
|
@@ -1,23 +1,53 @@
|
|
|
1
1
|
import { useEffect, useState } from "react";
|
|
2
2
|
|
|
3
|
-
let loadPromise: Promise<unknown> | null = null;
|
|
4
|
-
|
|
5
3
|
declare global {
|
|
6
4
|
interface Window {
|
|
5
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
|
|
7
6
|
cv: any;
|
|
8
7
|
}
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* OpenCV.js builds to try, in order. Both are single-file builds with the WASM embedded,
|
|
12
|
+
* so no companion `.wasm` request is needed.
|
|
13
|
+
*
|
|
14
|
+
* Note: opencv.org only publishes rolling branch builds — pinned version paths such as
|
|
15
|
+
* `/4.10.0/opencv.js` were removed upstream and now return 404. `5.x` is the current
|
|
16
|
+
* development line and `4.x` the stable line; the 4.x entry is a fallback for the case
|
|
17
|
+
* where the 5.x build is temporarily broken or unavailable.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_OPENCV_URLS = ["https://docs.opencv.org/5.x/opencv.js", "https://docs.opencv.org/4.x/opencv.js"];
|
|
20
|
+
|
|
21
|
+
/** Milliseconds to wait for the WASM runtime to initialise before giving up on a build. */
|
|
22
|
+
const INIT_TIMEOUT_MS = 60_000;
|
|
23
|
+
|
|
24
|
+
let scriptUrls = [...DEFAULT_OPENCV_URLS];
|
|
25
|
+
let loadPromise: Promise<void> | null = null;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Overrides which OpenCV.js build(s) to load — e.g. to self-host instead of using the CDN.
|
|
29
|
+
* Must be called before anything triggers a load; ignored once loading has started.
|
|
30
|
+
*/
|
|
31
|
+
export function configureOpenCV(urls: string | string[]) {
|
|
32
|
+
if (loadPromise) {
|
|
33
|
+
console.warn("[OpenCV] configureOpenCV() ignored — OpenCV is already loading or loaded");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
scriptUrls = Array.isArray(urls) ? [...urls] : [urls];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isReady() {
|
|
40
|
+
return typeof window.cv?.Mat !== "undefined";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Polls for cv.Mat, which signals that the WASM runtime has fully initialised. */
|
|
44
|
+
function waitForCvMat(timeoutMs: number): Promise<void> {
|
|
12
45
|
return new Promise((resolve, reject) => {
|
|
13
46
|
let elapsed = 0;
|
|
14
47
|
let interval = setInterval(() => {
|
|
15
|
-
|
|
16
|
-
// cv.Mat signals that the WASM runtime has fully initialised
|
|
17
|
-
if (window.cv?.Mat) {
|
|
48
|
+
if (isReady()) {
|
|
18
49
|
clearInterval(interval);
|
|
19
|
-
|
|
20
|
-
resolve(); // callers read window.cv directly
|
|
50
|
+
resolve();
|
|
21
51
|
return;
|
|
22
52
|
}
|
|
23
53
|
elapsed += 100;
|
|
@@ -29,76 +59,94 @@ function waitForCvMat(timeoutMs = 30_000): Promise<void> {
|
|
|
29
59
|
});
|
|
30
60
|
}
|
|
31
61
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Already initialised (e.g. hot-reload)
|
|
39
|
-
if (window.cv?.Mat) {
|
|
40
|
-
console.log("[OpenCV] already initialised on window.cv");
|
|
41
|
-
loadPromise = Promise.resolve(window.cv);
|
|
42
|
-
return loadPromise;
|
|
43
|
-
}
|
|
62
|
+
/** Loads a single OpenCV.js build, handling both the promise-based and polling Emscripten builds. */
|
|
63
|
+
function loadScript(url: string): Promise<void> {
|
|
64
|
+
return new Promise<void>((resolve, reject) => {
|
|
65
|
+
// A previous failed attempt may have left a half-initialised global behind.
|
|
66
|
+
if (!isReady()) window.cv = undefined;
|
|
44
67
|
|
|
45
|
-
console.log("[OpenCV] injecting script tag...");
|
|
46
|
-
loadPromise = new Promise<unknown>((resolve, reject) => {
|
|
47
68
|
let script = document.createElement("script");
|
|
48
|
-
script.src =
|
|
69
|
+
script.src = url;
|
|
49
70
|
script.async = true;
|
|
50
71
|
|
|
72
|
+
let settle = (err?: Error) => {
|
|
73
|
+
if (err) {
|
|
74
|
+
script.remove();
|
|
75
|
+
reject(err);
|
|
76
|
+
} else {
|
|
77
|
+
resolve();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
51
81
|
script.onload = () => {
|
|
52
|
-
console.log(
|
|
53
|
-
"[OpenCV] script onload fired. typeof window.cv=",
|
|
54
|
-
typeof window.cv,
|
|
55
|
-
"cv?.then=",
|
|
56
|
-
typeof window.cv?.then,
|
|
57
|
-
"cv?.Mat=",
|
|
58
|
-
typeof window.cv?.Mat,
|
|
59
|
-
);
|
|
60
82
|
if (typeof window.cv?.then === "function") {
|
|
61
|
-
console.log("[OpenCV] promise-based build detected, awaiting cv...");
|
|
62
83
|
// Emscripten promise-based build: cv itself is the promise.
|
|
63
|
-
// IMPORTANT:
|
|
64
|
-
//
|
|
65
|
-
// Instead
|
|
84
|
+
// IMPORTANT: never resolve *with* the instance — if the resolved value is
|
|
85
|
+
// itself thenable, the promise chain follows it forever and never settles.
|
|
86
|
+
// Instead mutate window.cv and signal readiness with undefined.
|
|
66
87
|
(window.cv as Promise<unknown>).then(
|
|
67
88
|
(instance) => {
|
|
68
|
-
console.log(
|
|
69
|
-
"[OpenCV] promise resolved, instance=",
|
|
70
|
-
typeof instance,
|
|
71
|
-
"hasReadMethod=",
|
|
72
|
-
typeof (instance as any)?.imread,
|
|
73
|
-
);
|
|
74
89
|
window.cv = instance;
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
(err) => {
|
|
78
|
-
console.error("[OpenCV] promise rejected", err);
|
|
79
|
-
reject(err);
|
|
90
|
+
settle();
|
|
80
91
|
},
|
|
92
|
+
(err: Error) => settle(err instanceof Error ? err : new Error(String(err))),
|
|
81
93
|
);
|
|
94
|
+
} else if (isReady()) {
|
|
95
|
+
settle();
|
|
82
96
|
} else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
waitForCvMat().then(() => resolve(undefined), reject);
|
|
97
|
+
// Polling build: the WASM initialises asynchronously after the script loads.
|
|
98
|
+
waitForCvMat(INIT_TIMEOUT_MS).then(() => settle(), settle);
|
|
86
99
|
}
|
|
87
100
|
};
|
|
88
101
|
|
|
89
|
-
script.onerror = (
|
|
90
|
-
console.error("[OpenCV] script load error", err);
|
|
91
|
-
loadPromise = null;
|
|
92
|
-
reject(new Error("Failed to load OpenCV.js"));
|
|
93
|
-
};
|
|
102
|
+
script.onerror = () => settle(new Error(`Failed to load OpenCV.js from ${url}`));
|
|
94
103
|
|
|
95
104
|
document.head.appendChild(script);
|
|
96
105
|
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Lazily loads OpenCV.js, trying each configured build in order.
|
|
110
|
+
* Rejects only when every candidate fails. Callers read `window.cv`.
|
|
111
|
+
*
|
|
112
|
+
* IMPORTANT: this promise must never resolve *with* the OpenCV module. Emscripten's
|
|
113
|
+
* module object has its own `.then` method, so it is thenable — resolving a promise
|
|
114
|
+
* with it makes the promise machinery try to adopt it and call `.then` forever, which
|
|
115
|
+
* wedges the whole tab in an infinite microtask loop. Always resolve with `undefined`
|
|
116
|
+
* and let callers read `window.cv`.
|
|
117
|
+
*/
|
|
118
|
+
export function loadOpenCV(): Promise<void> {
|
|
119
|
+
if (loadPromise) return loadPromise;
|
|
120
|
+
|
|
121
|
+
// Already initialised (e.g. hot-reload, or loaded by the host page)
|
|
122
|
+
if (isReady()) {
|
|
123
|
+
loadPromise = Promise.resolve();
|
|
124
|
+
return loadPromise;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
loadPromise = (async () => {
|
|
128
|
+
let errors: Error[] = [];
|
|
129
|
+
for (let url of scriptUrls) {
|
|
130
|
+
try {
|
|
131
|
+
await loadScript(url);
|
|
132
|
+
if (!isReady()) throw new Error(`OpenCV.js loaded from ${url} but exposes no cv.Mat`);
|
|
133
|
+
return; // never `return window.cv` — see the note above
|
|
134
|
+
} catch (err) {
|
|
135
|
+
let error = err instanceof Error ? err : new Error(String(err));
|
|
136
|
+
errors.push(error);
|
|
137
|
+
console.warn(`[OpenCV] Could not load ${url}:`, error.message);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Allow a later retry (e.g. after the network comes back) rather than caching the failure.
|
|
141
|
+
loadPromise = null;
|
|
142
|
+
throw new Error(`Failed to load OpenCV.js from: ${scriptUrls.join(", ")}`, { cause: errors });
|
|
143
|
+
})();
|
|
97
144
|
|
|
98
145
|
return loadPromise;
|
|
99
146
|
}
|
|
100
147
|
|
|
101
148
|
interface UseOpenCVResult {
|
|
149
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
|
|
102
150
|
cv: any | null;
|
|
103
151
|
ready: boolean;
|
|
104
152
|
error: Error | null;
|
|
@@ -106,28 +154,30 @@ interface UseOpenCVResult {
|
|
|
106
154
|
|
|
107
155
|
/** Lazily loads OpenCV.js from CDN. Starts loading only when `enabled` is true. */
|
|
108
156
|
export function useOpenCV(enabled = true): UseOpenCVResult {
|
|
157
|
+
// oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
|
|
109
158
|
let [cv, setCv] = useState<any | null>(null);
|
|
110
159
|
let [ready, setReady] = useState(false);
|
|
111
160
|
let [error, setError] = useState<Error | null>(null);
|
|
112
161
|
|
|
113
162
|
useEffect(() => {
|
|
114
163
|
if (!enabled) return;
|
|
115
|
-
|
|
164
|
+
let cancelled = false;
|
|
116
165
|
loadOpenCV()
|
|
117
166
|
.then(() => {
|
|
118
|
-
|
|
119
|
-
"[useOpenCV] loadOpenCV resolved. window.cv=",
|
|
120
|
-
typeof window.cv,
|
|
121
|
-
"imread=",
|
|
122
|
-
typeof window.cv?.imread,
|
|
123
|
-
);
|
|
167
|
+
if (cancelled) return;
|
|
124
168
|
setCv(window.cv);
|
|
125
169
|
setReady(true);
|
|
126
170
|
})
|
|
127
171
|
.catch((err: Error) => {
|
|
128
|
-
|
|
172
|
+
if (cancelled) return;
|
|
173
|
+
// OpenCV only powers optional features (border suggestion, perspective warp),
|
|
174
|
+
// so a load failure must never break the tools that depend on it.
|
|
175
|
+
console.warn("[useOpenCV] OpenCV failed to load — continuing without it:", err.message);
|
|
129
176
|
setError(err);
|
|
130
177
|
});
|
|
178
|
+
return () => {
|
|
179
|
+
cancelled = true;
|
|
180
|
+
};
|
|
131
181
|
}, [enabled]);
|
|
132
182
|
|
|
133
183
|
return { cv, ready, error };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import "./index.scss";
|
|
2
2
|
|
|
3
|
+
import { createSettingsStore } from "@olenbetong/appframe-react";
|
|
4
|
+
|
|
3
5
|
import clsx from "clsx";
|
|
4
|
-
import localforage from "localforage";
|
|
5
6
|
import type React from "react";
|
|
6
7
|
import { Children, forwardRef, useEffect, useRef, useState } from "react";
|
|
7
8
|
|
|
8
9
|
const article = globalThis.af?.article?.id ?? globalThis.window?.location.pathname.substring(1).split("/")[0];
|
|
9
|
-
const settingsStore =
|
|
10
|
-
name: `AfSplitContainers.${globalThis.af?.userSession.login ?? "anonymous"}`,
|
|
11
|
-
});
|
|
10
|
+
const settingsStore = createSettingsStore(`AfSplitContainers.${globalThis.af?.userSession?.login ?? "anonymous"}`);
|
|
12
11
|
|
|
13
12
|
type SplitContainerSettings = {
|
|
14
13
|
layoutVersion: string | number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The filter builder now lives in `@olenbetong/appframe-ds`, which is where the
|
|
3
|
+
* Designsystemet components it is built from live. Re-exported here so existing
|
|
4
|
+
* imports from `@olenbetong/synergi-react` keep working.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Import from `@olenbetong/appframe-ds` instead.
|
|
7
|
+
*/
|
|
8
|
+
export {
|
|
9
|
+
ChipListInput,
|
|
10
|
+
type ChipListInputProps,
|
|
11
|
+
FilterBuilder,
|
|
12
|
+
type FilterBuilderProps,
|
|
13
|
+
FilterEditor,
|
|
14
|
+
type FilterEditorProps,
|
|
15
|
+
type FilterEditorSize,
|
|
16
|
+
FilterGroupEditor,
|
|
17
|
+
type FilterGroupEditorProps,
|
|
18
|
+
FilterNameDialog,
|
|
19
|
+
type FilterNameDialogProps,
|
|
20
|
+
FilterRow,
|
|
21
|
+
type FilterRowProps,
|
|
22
|
+
FilterShareDialog,
|
|
23
|
+
type FilterShareDialogProps,
|
|
24
|
+
FilterStringField,
|
|
25
|
+
type FilterStringFieldProps,
|
|
26
|
+
FilterValueEditor,
|
|
27
|
+
type FilterValueEditorProps,
|
|
28
|
+
type FilterValueOption,
|
|
29
|
+
type GetFieldOptions,
|
|
30
|
+
type SavedFilterSelection,
|
|
31
|
+
SavedFilterTree,
|
|
32
|
+
type SavedFilterTreeProps,
|
|
33
|
+
type SavedFilterValues,
|
|
34
|
+
} from "@olenbetong/appframe-ds";
|
package/src/index.ts
CHANGED
|
@@ -38,8 +38,43 @@ export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard }
|
|
|
38
38
|
export { DateNavigator } from "./components/DateNavigator/index.js";
|
|
39
39
|
export * from "./components/FilePond.js";
|
|
40
40
|
export * from "./components/ImageEditor/index.js";
|
|
41
|
+
export {
|
|
42
|
+
ChipListInput,
|
|
43
|
+
type ChipListInputProps,
|
|
44
|
+
FilterBuilder,
|
|
45
|
+
type FilterBuilderProps,
|
|
46
|
+
FilterEditor,
|
|
47
|
+
type FilterEditorProps,
|
|
48
|
+
type FilterEditorSize,
|
|
49
|
+
FilterGroupEditor,
|
|
50
|
+
type FilterGroupEditorProps,
|
|
51
|
+
FilterNameDialog,
|
|
52
|
+
type FilterNameDialogProps,
|
|
53
|
+
FilterRow,
|
|
54
|
+
type FilterRowProps,
|
|
55
|
+
FilterShareDialog,
|
|
56
|
+
type FilterShareDialogProps,
|
|
57
|
+
FilterStringField,
|
|
58
|
+
type FilterStringFieldProps,
|
|
59
|
+
FilterValueEditor,
|
|
60
|
+
type FilterValueEditorProps,
|
|
61
|
+
type FilterValueOption,
|
|
62
|
+
type GetFieldOptions,
|
|
63
|
+
type SavedFilterSelection,
|
|
64
|
+
type SavedFilterValues,
|
|
65
|
+
SavedFilterTree,
|
|
66
|
+
type SavedFilterTreeProps,
|
|
67
|
+
} from "./filter/index.js";
|
|
41
68
|
export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
|
|
42
69
|
export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
|
|
70
|
+
export {
|
|
71
|
+
ReportLauncher,
|
|
72
|
+
type ReportLauncherProps,
|
|
73
|
+
type ReportLauncherTab,
|
|
74
|
+
ReportParameterField,
|
|
75
|
+
ReportParameters,
|
|
76
|
+
type ReportParametersProps,
|
|
77
|
+
} from "./report/index.js";
|
|
43
78
|
export {
|
|
44
79
|
BannerImage as PageBannerImage,
|
|
45
80
|
type BannerImageProps,
|
|
@@ -52,7 +87,10 @@ export {
|
|
|
52
87
|
Title as PageBannerTitle,
|
|
53
88
|
type TitleProps as PageBannerTitleProps,
|
|
54
89
|
} from "./components/PageBanner/index.js";
|
|
55
|
-
|
|
90
|
+
// PdfViewer is intentionally not re-exported here. It references the pdf.js worker
|
|
91
|
+
// with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
|
|
92
|
+
// asset for every app that touches this barrel, even when no PDF is ever rendered.
|
|
93
|
+
// Import it from "@olenbetong/synergi-react/pdf" instead.
|
|
56
94
|
export { Portal } from "./components/Portal/index.js";
|
|
57
95
|
export {
|
|
58
96
|
ToolbarBreadcrumbs,
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
|
|
2
|
+
import { createTheme as muiCreateTheme } from "@mui/material/styles";
|
|
3
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
function getColorScheme(): "light" | "dark" {
|
|
6
|
+
let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
|
|
7
|
+
|
|
8
|
+
if (scheme === "auto") {
|
|
9
|
+
return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return scheme === "dark" ? "dark" : "light";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tracks the color scheme Designsystemet is rendering with. The article template
|
|
17
|
+
* sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
|
|
18
|
+
* OS preference (used when the scheme is `auto`).
|
|
19
|
+
*/
|
|
20
|
+
function useColorScheme() {
|
|
21
|
+
let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
function update() {
|
|
25
|
+
setScheme(getColorScheme());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
update();
|
|
29
|
+
|
|
30
|
+
let observer = new MutationObserver(update);
|
|
31
|
+
observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
32
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
|
|
33
|
+
|
|
34
|
+
let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
|
|
35
|
+
media?.addEventListener("change", update);
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
observer.disconnect();
|
|
39
|
+
media?.removeEventListener("change", update);
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
return scheme;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function buildMuiTheme(mode: "light" | "dark") {
|
|
47
|
+
const s = getComputedStyle(document.body);
|
|
48
|
+
const get = (v: string) => s.getPropertyValue(v).trim();
|
|
49
|
+
const isDark = mode === "dark";
|
|
50
|
+
|
|
51
|
+
return muiCreateTheme({
|
|
52
|
+
palette: {
|
|
53
|
+
mode,
|
|
54
|
+
primary: {
|
|
55
|
+
main: get("--ds-color-brand-base-default") || "#116069",
|
|
56
|
+
dark: get("--ds-color-brand-base-hover") || "#0d4b52",
|
|
57
|
+
contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
|
|
58
|
+
},
|
|
59
|
+
secondary: {
|
|
60
|
+
main: get("--ds-color-brand-light-base-default") || "#1a95a2",
|
|
61
|
+
},
|
|
62
|
+
background: {
|
|
63
|
+
default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
64
|
+
paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
|
|
65
|
+
},
|
|
66
|
+
text: {
|
|
67
|
+
primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
|
|
68
|
+
secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
|
|
69
|
+
},
|
|
70
|
+
divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
|
|
71
|
+
},
|
|
72
|
+
typography: {
|
|
73
|
+
fontFamily: [
|
|
74
|
+
"-apple-system",
|
|
75
|
+
"BlinkMacSystemFont",
|
|
76
|
+
'"Segoe UI"',
|
|
77
|
+
"Roboto",
|
|
78
|
+
'"Helvetica Neue"',
|
|
79
|
+
"Arial",
|
|
80
|
+
"sans-serif",
|
|
81
|
+
'"Apple Color Emoji"',
|
|
82
|
+
'"Segoe UI Emoji"',
|
|
83
|
+
'"Segoe UI Symbol"',
|
|
84
|
+
].join(","),
|
|
85
|
+
},
|
|
86
|
+
components: {
|
|
87
|
+
MuiTypography: {
|
|
88
|
+
styleOverrides: {
|
|
89
|
+
h1: { fontSize: "2.488rem" },
|
|
90
|
+
h2: { fontSize: "2.074rem" },
|
|
91
|
+
h3: { fontSize: "1.728rem" },
|
|
92
|
+
h4: { fontSize: "1.44rem" },
|
|
93
|
+
h5: { fontSize: "1.2rem" },
|
|
94
|
+
h6: { fontSize: "1rem" },
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
MuiAppBar: {
|
|
98
|
+
styleOverrides: {
|
|
99
|
+
root: {
|
|
100
|
+
"& .MuiTypography-h1": {
|
|
101
|
+
fontSize: "1.25rem",
|
|
102
|
+
fontWeight: "500",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
MuiButton: {
|
|
108
|
+
styleOverrides: {
|
|
109
|
+
root: { borderRadius: 2 },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
MuiDialogTitle: {
|
|
113
|
+
styleOverrides: {
|
|
114
|
+
root: {
|
|
115
|
+
fontSize: "1.2rem",
|
|
116
|
+
fontWeight: 500,
|
|
117
|
+
paddingLeft: 16,
|
|
118
|
+
paddingRight: 16,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
MuiFormLabel: {
|
|
123
|
+
styleOverrides: {
|
|
124
|
+
root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
MuiTextField: { defaultProps: { variant: "filled" } },
|
|
128
|
+
MuiSelect: { defaultProps: { variant: "filled" } },
|
|
129
|
+
MuiFormControl: { defaultProps: { variant: "filled" } },
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type MuiThemeProviderProps = {
|
|
135
|
+
children: ReactNode;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
|
|
140
|
+
* (most notably the data grid) follow Designsystemet instead of MUI defaults.
|
|
141
|
+
*
|
|
142
|
+
* This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
|
|
143
|
+
* that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
|
|
144
|
+
* into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
|
|
145
|
+
* that still render MUI components:
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```tsx
|
|
149
|
+
* import { AppShell } from "@olenbetong/synergi-react";
|
|
150
|
+
* import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
|
|
151
|
+
*
|
|
152
|
+
* <MuiThemeProvider>
|
|
153
|
+
* <AppShell>{children}</AppShell>
|
|
154
|
+
* </MuiThemeProvider>
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function MuiThemeProvider({ children }: MuiThemeProviderProps) {
|
|
158
|
+
const colorScheme = useColorScheme();
|
|
159
|
+
|
|
160
|
+
// Rebuilt whenever the color scheme changes so MUI components (notably the
|
|
161
|
+
// data grid) follow Designsystemet instead of staying stuck in light mode.
|
|
162
|
+
// Also re-read after mount, since the stylesheets are imported from JS and
|
|
163
|
+
// the CSS variables aren't necessarily resolved during the first render.
|
|
164
|
+
const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
setTheme(buildMuiTheme(colorScheme));
|
|
167
|
+
}, [colorScheme]);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<StyledEngineProvider injectFirst>
|
|
171
|
+
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
|
172
|
+
</StyledEngineProvider>
|
|
173
|
+
);
|
|
174
|
+
}
|
package/src/mui/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Colours use the contextual `--ds-color-*` aliases so the launcher follows the
|
|
3
|
+
* active colour scheme. Never add hex fallbacks.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
.ObReportLauncher-root {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: var(--ds-size-4);
|
|
10
|
+
block-size: 100%;
|
|
11
|
+
min-block-size: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* The filter builder is the part that grows: its criteria editor scrolls, and
|
|
16
|
+
* the report fields it hosts keep their natural height.
|
|
17
|
+
*/
|
|
18
|
+
.ObReportLauncher-root > .ObFilterBuilder-root {
|
|
19
|
+
flex: 1 1 auto;
|
|
20
|
+
min-block-size: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* The tabs, the open panel and the report options share the column next to the
|
|
25
|
+
* saved-filter list. Only the panel grows; the tab list and the options keep
|
|
26
|
+
* their natural height.
|
|
27
|
+
*/
|
|
28
|
+
.ObReportLauncher-main {
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
gap: var(--ds-size-3);
|
|
32
|
+
min-block-size: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ObReportLauncher-tabs {
|
|
36
|
+
flex: 0 0 auto;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* The criteria editor scrolls its own conditions, so the panel holding it must
|
|
41
|
+
* not scroll as well. The parameters have no such arrangement and get their
|
|
42
|
+
* scrolling from the panel.
|
|
43
|
+
*/
|
|
44
|
+
.ObReportLauncher-panel {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
flex: 1 1 auto;
|
|
48
|
+
min-block-size: 0;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ObReportLauncher-panel--scroll {
|
|
53
|
+
gap: var(--ds-size-3);
|
|
54
|
+
overflow: auto;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.ObReportLauncher-panel > .ObFilterEditor-root {
|
|
58
|
+
flex: 1 1 auto;
|
|
59
|
+
min-block-size: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.ObReportLauncher-options {
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
flex: 0 0 auto;
|
|
66
|
+
gap: var(--ds-size-2);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.ObReportLauncher-status {
|
|
70
|
+
margin: 0;
|
|
71
|
+
color: var(--ds-color-text-subtle);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.ObReportLauncher-error {
|
|
75
|
+
margin: 0;
|
|
76
|
+
color: var(--ds-color-danger-text-default);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* The action row of the Windows dialog: save, preview, print, close. */
|
|
80
|
+
.ObReportLauncher-actions {
|
|
81
|
+
display: flex;
|
|
82
|
+
flex-wrap: wrap;
|
|
83
|
+
align-items: center;
|
|
84
|
+
justify-content: flex-end;
|
|
85
|
+
gap: var(--ds-size-2);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.ObReportLauncher-progress {
|
|
89
|
+
margin-inline-end: auto;
|
|
90
|
+
color: var(--ds-color-text-subtle);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* The save button and its format menu read as one control. */
|
|
94
|
+
.ObReportLauncher-saveGroup {
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: stretch;
|
|
97
|
+
gap: var(--ds-border-width-default);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.ObReportLauncher-saveGroup > :first-child {
|
|
101
|
+
border-start-end-radius: 0;
|
|
102
|
+
border-end-end-radius: 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.ObReportLauncher-saveGroup > :last-child:not(:first-child) {
|
|
106
|
+
border-start-start-radius: 0;
|
|
107
|
+
border-end-start-radius: 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/*
|
|
111
|
+
* As with the filter builder, `Dialog` caps itself at `--dsc-dialog-max-width`,
|
|
112
|
+
* so the variables have to be raised rather than the width set.
|
|
113
|
+
*/
|
|
114
|
+
.ObReportLauncher-dialog {
|
|
115
|
+
--dsc-dialog-max-width: 84rem;
|
|
116
|
+
--dsc-dialog-max-height: 90dvh;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* Taller than the filter builder: the column next to the saved-filter list has
|
|
121
|
+
* to fit the tabs, a panel worth scrolling and the report options below it.
|
|
122
|
+
*/
|
|
123
|
+
.ObReportLauncher-dialog[open] {
|
|
124
|
+
display: flex;
|
|
125
|
+
flex-direction: column;
|
|
126
|
+
block-size: min(58rem, 90dvh);
|
|
127
|
+
overflow: hidden;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.ObReportLauncher-dialogHeader {
|
|
131
|
+
display: flex;
|
|
132
|
+
align-items: center;
|
|
133
|
+
justify-content: space-between;
|
|
134
|
+
gap: var(--ds-size-2);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.ObReportLauncher-dialogBody {
|
|
138
|
+
flex: 1 1 auto;
|
|
139
|
+
min-block-size: 0;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (width < 48rem) {
|
|
144
|
+
.ObReportLauncher-dialogBody {
|
|
145
|
+
overflow: auto;
|
|
146
|
+
}
|
|
147
|
+
}
|