@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.
Files changed (62) hide show
  1. package/es/chrome/AppShell/index.d.ts +8 -0
  2. package/es/chrome/AppShell/index.js +10 -130
  3. package/es/components/ImageEditor/ImageEditor.css +10 -0
  4. package/es/components/ImageEditor/index.d.ts +1 -0
  5. package/es/components/ImageEditor/index.js +1 -0
  6. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +27 -5
  7. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +4 -3
  8. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.d.ts +20 -3
  9. package/es/components/ImageEditor/plugins/cropPlugin/useCropTool.js +216 -33
  10. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.d.ts +5 -0
  11. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomContext.js +7 -0
  12. package/es/components/ImageEditor/useEdgeDetection.d.ts +0 -2
  13. package/es/components/ImageEditor/useEdgeDetection.js +11 -30
  14. package/es/components/ImageEditor/useOpenCV.d.ts +26 -1
  15. package/es/components/ImageEditor/useOpenCV.js +108 -42
  16. package/es/components/SplitContainer/index.js +2 -4
  17. package/es/filter/index.d.ts +8 -0
  18. package/es/filter/index.js +8 -0
  19. package/es/index.d.ts +2 -1
  20. package/es/index.js +6 -1
  21. package/es/mui/MuiThemeProvider.d.ts +24 -0
  22. package/es/mui/MuiThemeProvider.js +152 -0
  23. package/es/mui/index.d.ts +1 -0
  24. package/es/mui/index.js +1 -0
  25. package/es/report/ReportLauncher.css +147 -0
  26. package/es/report/ReportLauncher.d.ts +55 -0
  27. package/es/report/ReportLauncher.js +142 -0
  28. package/es/report/ReportLauncher.test.d.ts +1 -0
  29. package/es/report/ReportLauncher.test.js +231 -0
  30. package/es/report/ReportParameters.css +29 -0
  31. package/es/report/ReportParameters.d.ts +46 -0
  32. package/es/report/ReportParameters.js +65 -0
  33. package/es/report/ReportParameters.test.d.ts +1 -0
  34. package/es/report/ReportParameters.test.js +84 -0
  35. package/es/report/index.d.ts +2 -0
  36. package/es/report/index.js +2 -0
  37. package/es/test/setup.d.ts +1 -0
  38. package/es/test/setup.js +6 -0
  39. package/package.json +22 -7
  40. package/src/chrome/AppShell/index.tsx +34 -171
  41. package/src/components/ImageEditor/ImageEditor.css +15 -5
  42. package/src/components/ImageEditor/ImageEditor.tsx +1 -1
  43. package/src/components/ImageEditor/index.ts +1 -0
  44. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +66 -20
  45. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +19 -3
  46. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +266 -39
  47. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +8 -0
  48. package/src/components/ImageEditor/useEdgeDetection.ts +11 -51
  49. package/src/components/ImageEditor/useOpenCV.ts +112 -62
  50. package/src/components/SplitContainer/index.tsx +3 -4
  51. package/src/filter/index.ts +34 -0
  52. package/src/index.ts +39 -1
  53. package/src/mui/MuiThemeProvider.tsx +174 -0
  54. package/src/mui/index.ts +1 -0
  55. package/src/report/ReportLauncher.css +147 -0
  56. package/src/report/ReportLauncher.test.tsx +281 -0
  57. package/src/report/ReportLauncher.tsx +420 -0
  58. package/src/report/ReportParameters.css +29 -0
  59. package/src/report/ReportParameters.test.tsx +133 -0
  60. package/src/report/ReportParameters.tsx +198 -0
  61. package/src/report/index.ts +2 -0
  62. package/src/test/setup.ts +8 -0
@@ -1,12 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import "./index.css";
3
+ import { createSettingsStore } from "@olenbetong/appframe-react";
3
4
  import clsx from "clsx";
4
- import localforage from "localforage";
5
5
  import { Children, forwardRef, useEffect, useRef, useState } from "react";
6
6
  const article = globalThis.af?.article?.id ?? globalThis.window?.location.pathname.substring(1).split("/")[0];
7
- const settingsStore = localforage.createInstance({
8
- name: `AfSplitContainers.${globalThis.af?.userSession.login ?? "anonymous"}`,
9
- });
7
+ const settingsStore = createSettingsStore(`AfSplitContainers.${globalThis.af?.userSession?.login ?? "anonymous"}`);
10
8
  const settingsCache = {};
11
9
  async function persistState(key, layoutVersion, fixedSize) {
12
10
  if (fixedSize != null) {
@@ -0,0 +1,8 @@
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 { ChipListInput, type ChipListInputProps, FilterBuilder, type FilterBuilderProps, FilterEditor, type FilterEditorProps, type FilterEditorSize, FilterGroupEditor, type FilterGroupEditorProps, FilterNameDialog, type FilterNameDialogProps, FilterRow, type FilterRowProps, FilterShareDialog, type FilterShareDialogProps, FilterStringField, type FilterStringFieldProps, FilterValueEditor, type FilterValueEditorProps, type FilterValueOption, type GetFieldOptions, type SavedFilterSelection, SavedFilterTree, type SavedFilterTreeProps, type SavedFilterValues, } from "@olenbetong/appframe-ds";
@@ -0,0 +1,8 @@
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 { ChipListInput, FilterBuilder, FilterEditor, FilterGroupEditor, FilterNameDialog, FilterRow, FilterShareDialog, FilterStringField, FilterValueEditor, SavedFilterTree, } from "@olenbetong/appframe-ds";
package/es/index.d.ts CHANGED
@@ -6,10 +6,11 @@ export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard }
6
6
  export { DateNavigator } from "./components/DateNavigator/index.js";
7
7
  export * from "./components/FilePond.js";
8
8
  export * from "./components/ImageEditor/index.js";
9
+ export { ChipListInput, type ChipListInputProps, FilterBuilder, type FilterBuilderProps, FilterEditor, type FilterEditorProps, type FilterEditorSize, FilterGroupEditor, type FilterGroupEditorProps, FilterNameDialog, type FilterNameDialogProps, FilterRow, type FilterRowProps, FilterShareDialog, type FilterShareDialogProps, FilterStringField, type FilterStringFieldProps, FilterValueEditor, type FilterValueEditorProps, type FilterValueOption, type GetFieldOptions, type SavedFilterSelection, type SavedFilterValues, SavedFilterTree, type SavedFilterTreeProps, } from "./filter/index.js";
9
10
  export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
10
11
  export { MergeProgressDialog, type MergeProgressDialogProps } from "./components/MergeProgressDialog/index.js";
12
+ export { ReportLauncher, type ReportLauncherProps, type ReportLauncherTab, ReportParameterField, ReportParameters, type ReportParametersProps, } from "./report/index.js";
11
13
  export { BannerImage as PageBannerImage, type BannerImageProps, PageBanner, type PageBannerProps, Tab as PageBannerTab, TabList as PageBannerTabList, type TabListProps as PageBannerTabListProps, type TabProps as PageBannerTabProps, Title as PageBannerTitle, type TitleProps as PageBannerTitleProps, } from "./components/PageBanner/index.js";
12
- export * from "./components/PdfViewer/index.js";
13
14
  export { Portal } from "./components/Portal/index.js";
14
15
  export { ToolbarBreadcrumbs, ToolbarPortal, type BreadcrumbItem, type ToolbarBreadcrumbsProps, type ToolbarPortalProps, type ToolbarPortalSlot, } from "./components/Toolbar/index.js";
15
16
  export { ProgressBar } from "./components/ProgressBar/index.js";
package/es/index.js CHANGED
@@ -6,10 +6,15 @@ export { CardColumn, CardDetail, CardLabel, CardStep, CardStepList, ColorCard }
6
6
  export { DateNavigator } from "./components/DateNavigator/index.js";
7
7
  export * from "./components/FilePond.js";
8
8
  export * from "./components/ImageEditor/index.js";
9
+ export { ChipListInput, FilterBuilder, FilterEditor, FilterGroupEditor, FilterNameDialog, FilterRow, FilterShareDialog, FilterStringField, FilterValueEditor, SavedFilterTree, } from "./filter/index.js";
9
10
  export { Card, LinkedList, LinkedListItem } from "./components/LinkedCardList/index.js";
10
11
  export { MergeProgressDialog } from "./components/MergeProgressDialog/index.js";
12
+ export { ReportLauncher, ReportParameterField, ReportParameters, } from "./report/index.js";
11
13
  export { BannerImage as PageBannerImage, PageBanner, Tab as PageBannerTab, TabList as PageBannerTabList, Title as PageBannerTitle, } from "./components/PageBanner/index.js";
12
- export * from "./components/PdfViewer/index.js";
14
+ // PdfViewer is intentionally not re-exported here. It references the pdf.js worker
15
+ // with `new URL(..., import.meta.url)`, which makes bundlers emit the 1.2 MB worker
16
+ // asset for every app that touches this barrel, even when no PDF is ever rendered.
17
+ // Import it from "@olenbetong/synergi-react/pdf" instead.
13
18
  export { Portal } from "./components/Portal/index.js";
14
19
  export { ToolbarBreadcrumbs, ToolbarPortal, } from "./components/Toolbar/index.js";
15
20
  export { ProgressBar } from "./components/ProgressBar/index.js";
@@ -0,0 +1,24 @@
1
+ import { type ReactNode } from "react";
2
+ export type MuiThemeProviderProps = {
3
+ children: ReactNode;
4
+ };
5
+ /**
6
+ * Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
7
+ * (most notably the data grid) follow Designsystemet instead of MUI defaults.
8
+ *
9
+ * This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
10
+ * that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
11
+ * into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
12
+ * that still render MUI components:
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { AppShell } from "@olenbetong/synergi-react";
17
+ * import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
18
+ *
19
+ * <MuiThemeProvider>
20
+ * <AppShell>{children}</AppShell>
21
+ * </MuiThemeProvider>
22
+ * ```
23
+ */
24
+ export declare function MuiThemeProvider({ children }: MuiThemeProviderProps): import("react").JSX.Element;
@@ -0,0 +1,152 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { StyledEngineProvider, ThemeProvider } from "@mui/material";
3
+ import { createTheme as muiCreateTheme } from "@mui/material/styles";
4
+ import { useEffect, useState } from "react";
5
+ function getColorScheme() {
6
+ let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
7
+ if (scheme === "auto") {
8
+ return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
9
+ }
10
+ return scheme === "dark" ? "dark" : "light";
11
+ }
12
+ /**
13
+ * Tracks the color scheme Designsystemet is rendering with. The article template
14
+ * sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
15
+ * OS preference (used when the scheme is `auto`).
16
+ */
17
+ function useColorScheme() {
18
+ let [scheme, setScheme] = useState(() => getColorScheme());
19
+ useEffect(() => {
20
+ function update() {
21
+ setScheme(getColorScheme());
22
+ }
23
+ update();
24
+ let observer = new MutationObserver(update);
25
+ observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
26
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
27
+ let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
28
+ media?.addEventListener("change", update);
29
+ return () => {
30
+ observer.disconnect();
31
+ media?.removeEventListener("change", update);
32
+ };
33
+ }, []);
34
+ return scheme;
35
+ }
36
+ function buildMuiTheme(mode) {
37
+ const s = getComputedStyle(document.body);
38
+ const get = (v) => s.getPropertyValue(v).trim();
39
+ const isDark = mode === "dark";
40
+ return muiCreateTheme({
41
+ palette: {
42
+ mode,
43
+ primary: {
44
+ main: get("--ds-color-brand-base-default") || "#116069",
45
+ dark: get("--ds-color-brand-base-hover") || "#0d4b52",
46
+ contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
47
+ },
48
+ secondary: {
49
+ main: get("--ds-color-brand-light-base-default") || "#1a95a2",
50
+ },
51
+ background: {
52
+ default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
53
+ paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
54
+ },
55
+ text: {
56
+ primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
57
+ secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
58
+ },
59
+ divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
60
+ },
61
+ typography: {
62
+ fontFamily: [
63
+ "-apple-system",
64
+ "BlinkMacSystemFont",
65
+ '"Segoe UI"',
66
+ "Roboto",
67
+ '"Helvetica Neue"',
68
+ "Arial",
69
+ "sans-serif",
70
+ '"Apple Color Emoji"',
71
+ '"Segoe UI Emoji"',
72
+ '"Segoe UI Symbol"',
73
+ ].join(","),
74
+ },
75
+ components: {
76
+ MuiTypography: {
77
+ styleOverrides: {
78
+ h1: { fontSize: "2.488rem" },
79
+ h2: { fontSize: "2.074rem" },
80
+ h3: { fontSize: "1.728rem" },
81
+ h4: { fontSize: "1.44rem" },
82
+ h5: { fontSize: "1.2rem" },
83
+ h6: { fontSize: "1rem" },
84
+ },
85
+ },
86
+ MuiAppBar: {
87
+ styleOverrides: {
88
+ root: {
89
+ "& .MuiTypography-h1": {
90
+ fontSize: "1.25rem",
91
+ fontWeight: "500",
92
+ },
93
+ },
94
+ },
95
+ },
96
+ MuiButton: {
97
+ styleOverrides: {
98
+ root: { borderRadius: 2 },
99
+ },
100
+ },
101
+ MuiDialogTitle: {
102
+ styleOverrides: {
103
+ root: {
104
+ fontSize: "1.2rem",
105
+ fontWeight: 500,
106
+ paddingLeft: 16,
107
+ paddingRight: 16,
108
+ },
109
+ },
110
+ },
111
+ MuiFormLabel: {
112
+ styleOverrides: {
113
+ root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
114
+ },
115
+ },
116
+ MuiTextField: { defaultProps: { variant: "filled" } },
117
+ MuiSelect: { defaultProps: { variant: "filled" } },
118
+ MuiFormControl: { defaultProps: { variant: "filled" } },
119
+ },
120
+ });
121
+ }
122
+ /**
123
+ * Bridges Designsystemet's colour tokens into a MUI theme, so MUI components
124
+ * (most notably the data grid) follow Designsystemet instead of MUI defaults.
125
+ *
126
+ * This lives in a separate entry point (`@olenbetong/synergi-react/mui`) so apps
127
+ * that have migrated to Designsystemet don't pull ~160 kB of MUI and Emotion
128
+ * into their bundle just by using `AppShell`. Wrap `AppShell` with it in apps
129
+ * that still render MUI components:
130
+ *
131
+ * @example
132
+ * ```tsx
133
+ * import { AppShell } from "@olenbetong/synergi-react";
134
+ * import { MuiThemeProvider } from "@olenbetong/synergi-react/mui";
135
+ *
136
+ * <MuiThemeProvider>
137
+ * <AppShell>{children}</AppShell>
138
+ * </MuiThemeProvider>
139
+ * ```
140
+ */
141
+ export function MuiThemeProvider({ children }) {
142
+ const colorScheme = useColorScheme();
143
+ // Rebuilt whenever the color scheme changes so MUI components (notably the
144
+ // data grid) follow Designsystemet instead of staying stuck in light mode.
145
+ // Also re-read after mount, since the stylesheets are imported from JS and
146
+ // the CSS variables aren't necessarily resolved during the first render.
147
+ const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
148
+ useEffect(() => {
149
+ setTheme(buildMuiTheme(colorScheme));
150
+ }, [colorScheme]);
151
+ return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(ThemeProvider, { theme: theme, children: children }) }));
152
+ }
@@ -0,0 +1 @@
1
+ export { MuiThemeProvider, type MuiThemeProviderProps } from "./MuiThemeProvider.js";
@@ -0,0 +1 @@
1
+ export { MuiThemeProvider } 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
+ }
@@ -0,0 +1,55 @@
1
+ import "./ReportLauncher.css";
2
+ import { type FieldMetadata } from "@olenbetong/appframe-core";
3
+ import { type FilterEditorSize, type GetFieldOptions } from "@olenbetong/appframe-ds";
4
+ export type ReportLauncherTab = "parameters" | "filter";
5
+ export type ReportLauncherProps = {
6
+ /** The report to run, e.g. `arpt_Personnel_Persons`. */
7
+ reportId: string;
8
+ /**
9
+ * `"dialog"` wraps the launcher in a modal, `"inline"` renders it in place.
10
+ * @default "dialog"
11
+ */
12
+ variant?: "dialog" | "inline";
13
+ /** Whether the dialog is open. Ignored when `variant` is `"inline"`. */
14
+ open?: boolean;
15
+ /** Called when the launcher is dismissed. */
16
+ onClose?: () => void;
17
+ /**
18
+ * Overrides the filter the report was designed with, as a criteria string.
19
+ * An empty string starts the launcher with no filter at all.
20
+ */
21
+ initialFilter?: string | null;
22
+ /**
23
+ * The fields the filter can be built from. Loaded from the report's view
24
+ * when not supplied.
25
+ */
26
+ fields?: FieldMetadata[];
27
+ /**
28
+ * The tab shown first.
29
+ * @default "parameters"
30
+ */
31
+ defaultTab?: ReportLauncherTab;
32
+ getFieldOptions?: GetFieldOptions;
33
+ className?: string;
34
+ "data-size"?: FilterEditorSize;
35
+ };
36
+ /**
37
+ * The web port of the Windows report launcher: the saved filters and criteria
38
+ * editor of the filter builder, the report's parameters, the report options,
39
+ * and the save/preview/print actions.
40
+ *
41
+ * Everything the launcher needs comes from the report itself, so a caller only
42
+ * has to name it. A report that does not resolve is one the current user has no
43
+ * access to — `sviw_WinClient_MyReports` is permission-resolved.
44
+ *
45
+ * @example
46
+ * ```jsx
47
+ * <ReportLauncher
48
+ * reportId="arpt_Production_ElementsDaily"
49
+ * open={open}
50
+ * initialFilter={`[ProjectID] = '${projectId}'`}
51
+ * onClose={() => setOpen(false)}
52
+ * />
53
+ * ```
54
+ */
55
+ export declare function ReportLauncher({ reportId, variant, open, onClose, initialFilter: initialFilterOverride, fields: fieldsOverride, defaultTab, getFieldOptions, className, "data-size": size, }: ReportLauncherProps): import("react").JSX.Element;
@@ -0,0 +1,142 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import "./ReportLauncher.css";
3
+ import { Button, Checkbox, Dialog, Dropdown, Heading, Tabs, Textfield } from "@digdir/designsystemet-react";
4
+ import { ChevronDownIcon, XMarkIcon } from "@navikt/aksel-icons";
5
+ import { convertFilter, createEmptyFilter, getLocalizedString, restoreParameterValues, serializeParameters, } from "@olenbetong/appframe-core";
6
+ import { useFilterFields, useReport, useReportRender } from "@olenbetong/appframe-react";
7
+ import clsx from "clsx";
8
+ import { useEffect, useId, useMemo, useState } from "react";
9
+ import { FilterBuilder } from "@olenbetong/appframe-ds";
10
+ import { ReportParameters } from "./ReportParameters.js";
11
+ /** The label shown on the save button for each format. */
12
+ const FORMAT_LABELS = {
13
+ CSV: "Save as CSV",
14
+ HTML: "Save as HTML",
15
+ IMAGE: "Save as image",
16
+ MHT: "Save as MHT",
17
+ PDF: "Save as PDF",
18
+ RTF: "Save as RTF",
19
+ TEXT: "Save as text",
20
+ XLS: "Save as XLS (Excel)",
21
+ XLSX: "Save as XLSX (Excel 2007)",
22
+ };
23
+ /**
24
+ * The web port of the Windows report launcher: the saved filters and criteria
25
+ * editor of the filter builder, the report's parameters, the report options,
26
+ * and the save/preview/print actions.
27
+ *
28
+ * Everything the launcher needs comes from the report itself, so a caller only
29
+ * has to name it. A report that does not resolve is one the current user has no
30
+ * access to — `sviw_WinClient_MyReports` is permission-resolved.
31
+ *
32
+ * @example
33
+ * ```jsx
34
+ * <ReportLauncher
35
+ * reportId="arpt_Production_ElementsDaily"
36
+ * open={open}
37
+ * initialFilter={`[ProjectID] = '${projectId}'`}
38
+ * onClose={() => setOpen(false)}
39
+ * />
40
+ * ```
41
+ */
42
+ export function ReportLauncher({ reportId, variant = "dialog", open = true, onClose, initialFilter: initialFilterOverride, fields: fieldsOverride, defaultTab = "parameters", getFieldOptions, className, "data-size": size = "sm", }) {
43
+ let { report, parameters, initialFilter, defaultValues, loading, error } = useReport(reportId, {
44
+ initialFilter: initialFilterOverride,
45
+ });
46
+ let viewName = report?.viewName ?? undefined;
47
+ let { fields: loadedFields } = useFilterFields(fieldsOverride ? null : viewName);
48
+ let fields = fieldsOverride ?? loadedFields;
49
+ let { open: openReport, print, download, isRendering, progress, error: renderError } = useReportRender(reportId);
50
+ let [filter, setFilter] = useState(createEmptyFilter);
51
+ let [filterString, setFilterString] = useState("");
52
+ let [values, setValues] = useState({});
53
+ let [reportTitle, setReportTitle] = useState("");
54
+ let [headerText, setHeaderText] = useState("");
55
+ let [hideFilterString, setHideFilterString] = useState(false);
56
+ let [tab, setTab] = useState(defaultTab);
57
+ let panelId = useId();
58
+ // The report's own defaults arrive in two rounds — the literal ones first,
59
+ // then the ones a stored procedure produces — so they are copied into the
60
+ // form whenever they change rather than only once.
61
+ useEffect(() => {
62
+ setValues(defaultValues);
63
+ }, [defaultValues]);
64
+ useEffect(() => {
65
+ setReportTitle(report?.title ?? "");
66
+ }, [report?.title]);
67
+ /*
68
+ * The initial filter is a criteria string, so it has to be parsed into a
69
+ * tree before the editor can show it.
70
+ */
71
+ useEffect(() => {
72
+ if (!initialFilter) {
73
+ setFilter(createEmptyFilter());
74
+ return;
75
+ }
76
+ let controller = new AbortController();
77
+ convertFilter({ filterString: initialFilter, viewName }, controller.signal)
78
+ .then((result) => {
79
+ if (!controller.signal.aborted)
80
+ setFilter(result.filterObject ?? createEmptyFilter());
81
+ })
82
+ .catch(() => {
83
+ // An initial filter the converter rejects is better dropped than
84
+ // blocking the launcher; the user can rebuild it.
85
+ });
86
+ return () => {
87
+ controller.abort();
88
+ };
89
+ }, [initialFilter, viewName]);
90
+ /** Selecting a saved filter restores the report options stored with it. */
91
+ function handleSelectFilter(saved) {
92
+ if (!saved) {
93
+ setValues(defaultValues);
94
+ setHeaderText("");
95
+ setHideFilterString(false);
96
+ setReportTitle(report?.title ?? "");
97
+ return;
98
+ }
99
+ setValues(restoreParameterValues(parameters, saved.parameters));
100
+ setHeaderText(saved.headerText ?? "");
101
+ setHideFilterString(saved.hideCriteria);
102
+ setReportTitle(saved.reportTitle ?? report?.title ?? "");
103
+ }
104
+ let saveValues = useMemo(() => ({
105
+ headerText: headerText || null,
106
+ hideCriteria: hideFilterString,
107
+ parameters: parameters.length > 0 ? serializeParameters(parameters, values) : null,
108
+ }), [headerText, hideFilterString, parameters, values]);
109
+ let formats = report?.formats ?? [];
110
+ // PDF is the only format worth previewing or printing in place; the rest are
111
+ // downloads whatever the browser is asked to do with them.
112
+ let canPreview = formats.includes("PDF");
113
+ function getRenderOptions(format) {
114
+ return {
115
+ format,
116
+ fileName: reportTitle || report?.title || reportId,
117
+ filter: filterString,
118
+ parameters: values,
119
+ headerText: report?.hasHeader ? headerText : null,
120
+ hideFilterString,
121
+ };
122
+ }
123
+ function run(action, format) {
124
+ void action(getRenderOptions(format));
125
+ }
126
+ /*
127
+ * The parameters and the criteria are too much to show at once, so they get
128
+ * a tab each. The report options stay below the tabs: they apply to the
129
+ * report whichever tab is open, and the hide-criteria flag in particular
130
+ * reads as belonging to both.
131
+ */
132
+ let options = (_jsxs("div", { className: "ObReportLauncher-options", children: [report?.hasTitle && (_jsx(Textfield, { "data-size": size, label: getLocalizedString("Report name"), description: getLocalizedString("Used as the file name when the report is saved."), value: reportTitle, onChange: (event) => setReportTitle(event.target.value) })), report?.hasHeader && (_jsx(Textfield, { "data-size": size, multiline: true, rows: 2, label: getLocalizedString("Optional text (at the top of every page)"), value: headerText, onChange: (event) => setHeaderText(event.target.value) })), _jsx(Checkbox, { "data-size": size, label: getLocalizedString("Do not show the filter criteria at the top of the pages"), checked: hideFilterString, onChange: (event) => setHideFilterString(event.currentTarget.checked) })] }));
133
+ let actions = (_jsxs("div", { className: "ObReportLauncher-actions", children: [isRendering && (_jsx("span", { className: "ObReportLauncher-progress", children: progress?.bytesReceived
134
+ ? `${Math.round(progress.bytesReceived / 1024)} kB`
135
+ : getLocalizedString("Rendering...") })), formats.length > 0 && (_jsxs("div", { className: "ObReportLauncher-saveGroup", children: [_jsx(Button, { type: "button", "data-size": size, disabled: isRendering, onClick: () => run(download, formats[0]), children: getLocalizedString(FORMAT_LABELS[formats[0]]) }), formats.length > 1 && (_jsxs(Dropdown.TriggerContext, { children: [_jsx(Dropdown.Trigger, { "data-size": size, icon: true, disabled: isRendering, "aria-label": getLocalizedString("More formats"), children: _jsx(ChevronDownIcon, { "aria-hidden": true }) }), _jsx(Dropdown, { children: _jsx(Dropdown.List, { children: formats.slice(1).map((format) => (_jsx(Dropdown.Item, { children: _jsx(Dropdown.Button, { onClick: () => run(download, format), children: getLocalizedString(FORMAT_LABELS[format]) }) }, format))) }) })] }))] })), _jsx(Button, { type: "button", variant: "secondary", "data-size": size, disabled: !canPreview || isRendering, onClick: () => run(openReport, "PDF"), children: getLocalizedString("Preview") }), _jsx(Button, { type: "button", variant: "secondary", "data-size": size, disabled: !canPreview || isRendering, onClick: () => run(print, "PDF"), children: getLocalizedString("Print") }), _jsx(Button, { type: "button", variant: "tertiary", "data-size": size, onClick: onClose, children: getLocalizedString("Close") })] }));
136
+ let content = (_jsxs("div", { className: clsx("ObReportLauncher-root", className), "data-size": size, children: [loading && _jsx("p", { className: "ObReportLauncher-status", children: getLocalizedString("Loading...") }), !loading && !report && (_jsx("p", { className: "ObReportLauncher-error", role: "alert", children: error
137
+ ? error.message
138
+ : getLocalizedString("The report does not exist, or you do not have access to run it.") })), report && (_jsx(FilterBuilder, { fields: fields, viewName: viewName, reportId: reportId, getFieldOptions: getFieldOptions, variant: "inline", value: filter, "data-size": size, actions: actions, saveValues: saveValues, onChange: setFilter, onFilterStringChange: setFilterString, onSelect: handleSelectFilter, renderMain: (editor) => (_jsxs("div", { className: "ObReportLauncher-main", children: [_jsx(Tabs, { value: tab, "data-size": size, className: "ObReportLauncher-tabs", onChange: (value) => setTab(value), children: _jsxs(Tabs.List, { children: [_jsx(Tabs.Tab, { value: "parameters", "aria-controls": `${panelId}-parameters`, children: parameters.length > 0 ? getLocalizedString("Parameters") : getLocalizedString("Report") }), _jsx(Tabs.Tab, { value: "filter", "aria-controls": `${panelId}-filter`, children: getLocalizedString("Filter") })] }) }), tab === "parameters" ? (_jsx("div", { role: "tabpanel", id: `${panelId}-parameters`, className: "ObReportLauncher-panel ObReportLauncher-panel--scroll", children: parameters.length > 0 ? (_jsx(ReportParameters, { parameters: parameters, values: values, onChange: setValues, legend: null, "data-size": size })) : (_jsx("p", { className: "ObReportLauncher-status", children: getLocalizedString("The report has no parameters.") })) })) : (_jsx("div", { role: "tabpanel", id: `${panelId}-filter`, className: "ObReportLauncher-panel", children: editor })), options] })) })), renderError && (_jsx("p", { className: "ObReportLauncher-error", role: "alert", children: renderError.message }))] }));
139
+ if (variant === "inline")
140
+ return content;
141
+ return (_jsxs(Dialog, { open: open, closedby: "closerequest", closeButton: false, "data-size": size, className: "ObReportLauncher-dialog", onClose: onClose, children: [_jsxs(Dialog.Block, { className: "ObReportLauncher-dialogHeader", children: [_jsxs(Heading, { level: 2, "data-size": "xs", children: [getLocalizedString("Report"), ": ", report?.title ?? reportId, report?.shortId !== null && report?.shortId !== undefined && ` (ID: ${report.shortId})`] }), _jsx(Button, { type: "button", variant: "tertiary", "data-color": "neutral", "data-size": size, icon: true, "aria-label": getLocalizedString("Close"), onClick: onClose, children: _jsx(XMarkIcon, { "aria-hidden": true }) })] }), _jsx(Dialog.Block, { className: "ObReportLauncher-dialogBody", children: content })] }));
142
+ }
@@ -0,0 +1 @@
1
+ export {};