@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
@@ -1,15 +1,40 @@
1
1
  import { useEffect, useState } from "react";
2
+ /**
3
+ * OpenCV.js builds to try, in order. Both are single-file builds with the WASM embedded,
4
+ * so no companion `.wasm` request is needed.
5
+ *
6
+ * Note: opencv.org only publishes rolling branch builds — pinned version paths such as
7
+ * `/4.10.0/opencv.js` were removed upstream and now return 404. `5.x` is the current
8
+ * development line and `4.x` the stable line; the 4.x entry is a fallback for the case
9
+ * where the 5.x build is temporarily broken or unavailable.
10
+ */
11
+ export const DEFAULT_OPENCV_URLS = ["https://docs.opencv.org/5.x/opencv.js", "https://docs.opencv.org/4.x/opencv.js"];
12
+ /** Milliseconds to wait for the WASM runtime to initialise before giving up on a build. */
13
+ const INIT_TIMEOUT_MS = 60_000;
14
+ let scriptUrls = [...DEFAULT_OPENCV_URLS];
2
15
  let loadPromise = null;
3
- function waitForCvMat(timeoutMs = 30_000) {
16
+ /**
17
+ * Overrides which OpenCV.js build(s) to load — e.g. to self-host instead of using the CDN.
18
+ * Must be called before anything triggers a load; ignored once loading has started.
19
+ */
20
+ export function configureOpenCV(urls) {
21
+ if (loadPromise) {
22
+ console.warn("[OpenCV] configureOpenCV() ignored — OpenCV is already loading or loaded");
23
+ return;
24
+ }
25
+ scriptUrls = Array.isArray(urls) ? [...urls] : [urls];
26
+ }
27
+ function isReady() {
28
+ return typeof window.cv?.Mat !== "undefined";
29
+ }
30
+ /** Polls for cv.Mat, which signals that the WASM runtime has fully initialised. */
31
+ function waitForCvMat(timeoutMs) {
4
32
  return new Promise((resolve, reject) => {
5
33
  let elapsed = 0;
6
34
  let interval = setInterval(() => {
7
- console.log("[OpenCV] polling... cv=", typeof window.cv, "cv.Mat=", typeof window.cv?.Mat);
8
- // cv.Mat signals that the WASM runtime has fully initialised
9
- if (window.cv?.Mat) {
35
+ if (isReady()) {
10
36
  clearInterval(interval);
11
- console.log("[OpenCV] cv.Mat found — ready!");
12
- resolve(); // callers read window.cv directly
37
+ resolve();
13
38
  return;
14
39
  }
15
40
  elapsed += 100;
@@ -20,73 +45,114 @@ function waitForCvMat(timeoutMs = 30_000) {
20
45
  }, 100);
21
46
  });
22
47
  }
23
- export function loadOpenCV() {
24
- if (loadPromise) {
25
- console.log("[OpenCV] loadOpenCV() — reusing existing promise");
26
- return loadPromise;
27
- }
28
- // Already initialised (e.g. hot-reload)
29
- if (window.cv?.Mat) {
30
- console.log("[OpenCV] already initialised on window.cv");
31
- loadPromise = Promise.resolve(window.cv);
32
- return loadPromise;
33
- }
34
- console.log("[OpenCV] injecting script tag...");
35
- loadPromise = new Promise((resolve, reject) => {
48
+ /** Loads a single OpenCV.js build, handling both the promise-based and polling Emscripten builds. */
49
+ function loadScript(url) {
50
+ return new Promise((resolve, reject) => {
51
+ // A previous failed attempt may have left a half-initialised global behind.
52
+ if (!isReady())
53
+ window.cv = undefined;
36
54
  let script = document.createElement("script");
37
- script.src = "https://docs.opencv.org/4.10.0/opencv.js";
55
+ script.src = url;
38
56
  script.async = true;
57
+ let settle = (err) => {
58
+ if (err) {
59
+ script.remove();
60
+ reject(err);
61
+ }
62
+ else {
63
+ resolve();
64
+ }
65
+ };
39
66
  script.onload = () => {
40
- console.log("[OpenCV] script onload fired. typeof window.cv=", typeof window.cv, "cv?.then=", typeof window.cv?.then, "cv?.Mat=", typeof window.cv?.Mat);
41
67
  if (typeof window.cv?.then === "function") {
42
- console.log("[OpenCV] promise-based build detected, awaiting cv...");
43
68
  // Emscripten promise-based build: cv itself is the promise.
44
- // IMPORTANT: we must NOT pass `instance` into resolve() — if the resolved
45
- // value is itself thenable, Promise will follow it forever and never settle.
46
- // Instead we mutate window.cv and signal readiness with undefined.
69
+ // IMPORTANT: never resolve *with* the instance — if the resolved value is
70
+ // itself thenable, the promise chain follows it forever and never settles.
71
+ // Instead mutate window.cv and signal readiness with undefined.
47
72
  window.cv.then((instance) => {
48
- console.log("[OpenCV] promise resolved, instance=", typeof instance, "hasReadMethod=", typeof instance?.imread);
49
73
  window.cv = instance;
50
- resolve(undefined); // signal only; callers read window.cv
51
- }, (err) => {
52
- console.error("[OpenCV] promise rejected", err);
53
- reject(err);
54
- });
74
+ settle();
75
+ }, (err) => settle(err instanceof Error ? err : new Error(String(err))));
76
+ }
77
+ else if (isReady()) {
78
+ settle();
55
79
  }
56
80
  else {
57
- console.log("[OpenCV] polling-based build, starting waitForCvMat...");
58
- // Polling build: WASM initialises asynchronously after script loads
59
- waitForCvMat().then(() => resolve(undefined), reject);
81
+ // Polling build: the WASM initialises asynchronously after the script loads.
82
+ waitForCvMat(INIT_TIMEOUT_MS).then(() => settle(), settle);
60
83
  }
61
84
  };
62
- script.onerror = (err) => {
63
- console.error("[OpenCV] script load error", err);
64
- loadPromise = null;
65
- reject(new Error("Failed to load OpenCV.js"));
66
- };
85
+ script.onerror = () => settle(new Error(`Failed to load OpenCV.js from ${url}`));
67
86
  document.head.appendChild(script);
68
87
  });
88
+ }
89
+ /**
90
+ * Lazily loads OpenCV.js, trying each configured build in order.
91
+ * Rejects only when every candidate fails. Callers read `window.cv`.
92
+ *
93
+ * IMPORTANT: this promise must never resolve *with* the OpenCV module. Emscripten's
94
+ * module object has its own `.then` method, so it is thenable — resolving a promise
95
+ * with it makes the promise machinery try to adopt it and call `.then` forever, which
96
+ * wedges the whole tab in an infinite microtask loop. Always resolve with `undefined`
97
+ * and let callers read `window.cv`.
98
+ */
99
+ export function loadOpenCV() {
100
+ if (loadPromise)
101
+ return loadPromise;
102
+ // Already initialised (e.g. hot-reload, or loaded by the host page)
103
+ if (isReady()) {
104
+ loadPromise = Promise.resolve();
105
+ return loadPromise;
106
+ }
107
+ loadPromise = (async () => {
108
+ let errors = [];
109
+ for (let url of scriptUrls) {
110
+ try {
111
+ await loadScript(url);
112
+ if (!isReady())
113
+ throw new Error(`OpenCV.js loaded from ${url} but exposes no cv.Mat`);
114
+ return; // never `return window.cv` — see the note above
115
+ }
116
+ catch (err) {
117
+ let error = err instanceof Error ? err : new Error(String(err));
118
+ errors.push(error);
119
+ console.warn(`[OpenCV] Could not load ${url}:`, error.message);
120
+ }
121
+ }
122
+ // Allow a later retry (e.g. after the network comes back) rather than caching the failure.
123
+ loadPromise = null;
124
+ throw new Error(`Failed to load OpenCV.js from: ${scriptUrls.join(", ")}`, { cause: errors });
125
+ })();
69
126
  return loadPromise;
70
127
  }
71
128
  /** Lazily loads OpenCV.js from CDN. Starts loading only when `enabled` is true. */
72
129
  export function useOpenCV(enabled = true) {
130
+ // oxlint-disable-next-line typescript/no-explicit-any -- OpenCV.js has no bundled types
73
131
  let [cv, setCv] = useState(null);
74
132
  let [ready, setReady] = useState(false);
75
133
  let [error, setError] = useState(null);
76
134
  useEffect(() => {
77
135
  if (!enabled)
78
136
  return;
79
- console.log("[useOpenCV] enabled=true, calling loadOpenCV()");
137
+ let cancelled = false;
80
138
  loadOpenCV()
81
139
  .then(() => {
82
- console.log("[useOpenCV] loadOpenCV resolved. window.cv=", typeof window.cv, "imread=", typeof window.cv?.imread);
140
+ if (cancelled)
141
+ return;
83
142
  setCv(window.cv);
84
143
  setReady(true);
85
144
  })
86
145
  .catch((err) => {
87
- console.error("[useOpenCV] loadOpenCV rejected:", err);
146
+ if (cancelled)
147
+ return;
148
+ // OpenCV only powers optional features (border suggestion, perspective warp),
149
+ // so a load failure must never break the tools that depend on it.
150
+ console.warn("[useOpenCV] OpenCV failed to load — continuing without it:", err.message);
88
151
  setError(err);
89
152
  });
153
+ return () => {
154
+ cancelled = true;
155
+ };
90
156
  }, [enabled]);
91
157
  return { cv, ready, error };
92
158
  }
@@ -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) {
@@ -1,9 +1,8 @@
1
- type DamageFormButtonsProps = {
1
+ export type DamageFormButtonsProps = {
2
2
  isEdit: boolean;
3
3
  loading: boolean;
4
4
  uploadingFile: boolean;
5
5
  handleDelete: () => void;
6
6
  handleCancel: () => void;
7
7
  };
8
- export declare function DamageFormButtonsProps({ isEdit, loading, uploadingFile, handleDelete, handleCancel, }: DamageFormButtonsProps): import("react").JSX.Element;
9
- export {};
8
+ export declare function DamageFormButtons({ isEdit, loading, uploadingFile, handleDelete, handleCancel, }: DamageFormButtonsProps): import("react").JSX.Element;
@@ -2,6 +2,6 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  import Add from "@mui/icons-material/Add";
3
3
  import { Button } from "@mui/material";
4
4
  import { getLocalizedString } from "@olenbetong/appframe-core";
5
- export function DamageFormButtonsProps({ isEdit, loading, uploadingFile, handleDelete, handleCancel, }) {
5
+ export function DamageFormButtons({ isEdit, loading, uploadingFile, handleDelete, handleCancel, }) {
6
6
  return (_jsxs(_Fragment, { children: [isEdit && _jsx(Button, { onClick: handleDelete, children: getLocalizedString("Delete") }), _jsx(Button, { onClick: handleCancel, children: getLocalizedString("Cancel") }), _jsx(Button, { loading: loading || uploadingFile, loadingPosition: "start", startIcon: _jsx(Add, {}), type: "submit", variant: "contained", children: isEdit ? getLocalizedString("Save changes") : getLocalizedString("Register damage") })] }));
7
7
  }
@@ -1,7 +1,6 @@
1
1
  import type { TransportElementsRecord } from "../data/dsTransportElements.js";
2
- type TransportElementSelectProps = {
2
+ export type TransportElementSelectProps = {
3
3
  elements: TransportElementsRecord[];
4
4
  onSelect: (element: TransportElementsRecord) => void;
5
5
  };
6
6
  export declare function TransportElementSelect({ elements, onSelect }: TransportElementSelectProps): import("react").JSX.Element;
7
- export {};
@@ -1,10 +1,15 @@
1
1
  export * from "./data/index.js";
2
+ export * from "./ElementDamage/DamageFormButtons.js";
2
3
  export * from "./ElementDamage/DescriptionInput.js";
3
4
  export * from "./ElementDamage/DuplicateDamage/index.js";
4
5
  export * from "./ElementDamage/ElementNumberTextField.js";
5
6
  export * from "./ElementDamage/HiddenDamageFields.js";
6
7
  export * from "./ElementDamage/RegisterFix.js";
7
8
  export * from "./ElementDamage/SubmitButtons.js";
9
+ export * from "./ElementDamage/TransportElementSelect.js";
8
10
  export * from "./ElementLookup.js";
11
+ export * from "./ElementLookupDialog/BarcodeScanner/index.js";
12
+ export * from "./ElementLookupDialog/HIDScanner/index.js";
9
13
  export * from "./ElementLookupDialog/index.js";
14
+ export * from "./ElementLookupDialog/Manual/ManualForm.js";
10
15
  export * from "./ProjectSelect.js";
@@ -1,10 +1,15 @@
1
1
  export * from "./data/index.js";
2
+ export * from "./ElementDamage/DamageFormButtons.js";
2
3
  export * from "./ElementDamage/DescriptionInput.js";
3
4
  export * from "./ElementDamage/DuplicateDamage/index.js";
4
5
  export * from "./ElementDamage/ElementNumberTextField.js";
5
6
  export * from "./ElementDamage/HiddenDamageFields.js";
6
7
  export * from "./ElementDamage/RegisterFix.js";
7
8
  export * from "./ElementDamage/SubmitButtons.js";
9
+ export * from "./ElementDamage/TransportElementSelect.js";
8
10
  export * from "./ElementLookup.js";
11
+ export * from "./ElementLookupDialog/BarcodeScanner/index.js";
12
+ export * from "./ElementLookupDialog/HIDScanner/index.js";
9
13
  export * from "./ElementLookupDialog/index.js";
14
+ export * from "./ElementLookupDialog/Manual/ManualForm.js";
10
15
  export * from "./ProjectSelect.js";
@@ -0,0 +1,13 @@
1
+ export type ChipListInputProps = {
2
+ value: string[];
3
+ onChange: (value: string[]) => void;
4
+ readOnly?: boolean;
5
+ "aria-label": string;
6
+ "data-size"?: "sm" | "md" | "lg";
7
+ type?: "text" | "number" | "date" | "datetime-local";
8
+ };
9
+ /**
10
+ * Free text editor for the list operators. Values are added with Enter and
11
+ * rendered as removable chips.
12
+ */
13
+ export declare function ChipListInput({ value, onChange, readOnly, type, "aria-label": ariaLabel, "data-size": size, }: ChipListInputProps): import("react").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChipRemovable, Textfield } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString } from "@olenbetong/appframe-core";
4
+ import { useState } from "react";
5
+ /**
6
+ * Free text editor for the list operators. Values are added with Enter and
7
+ * rendered as removable chips.
8
+ */
9
+ export function ChipListInput({ value, onChange, readOnly, type = "text", "aria-label": ariaLabel, "data-size": size, }) {
10
+ let [draft, setDraft] = useState("");
11
+ function commit() {
12
+ let trimmed = draft.trim();
13
+ if (!trimmed || value.includes(trimmed)) {
14
+ setDraft("");
15
+ return;
16
+ }
17
+ onChange([...value, trimmed]);
18
+ setDraft("");
19
+ }
20
+ function handleKeyDown(event) {
21
+ if (event.key === "Enter") {
22
+ // The editor is often rendered inside a dialog; committing a value
23
+ // must not submit or close it.
24
+ event.preventDefault();
25
+ commit();
26
+ }
27
+ else if (event.key === "Backspace" && draft === "" && value.length > 0) {
28
+ onChange(value.slice(0, -1));
29
+ }
30
+ }
31
+ return (_jsxs("div", { className: "ObFilterEditor-chipList", children: [value.map((item, index) => (_jsx(ChipRemovable
32
+ // Values are deduplicated on add, so the value is a stable key.
33
+ , { "data-size": size, disabled: readOnly, "aria-label": `${getLocalizedString("Remove")} ${item}`, onClick: () => onChange(value.filter((_, i) => i !== index)), children: item }, item))), !readOnly && (_jsx(Textfield, { className: "ObFilterEditor-chipListInput", "aria-label": ariaLabel, "data-size": size, type: type, value: draft, placeholder: getLocalizedString("Add value"), onChange: (event) => setDraft(event.target.value), onKeyDown: handleKeyDown, onBlur: commit }))] }));
34
+ }
@@ -0,0 +1,152 @@
1
+ /*
2
+ * Colours use the contextual `--ds-color-*` aliases so the builder follows the
3
+ * active colour scheme. Never add hex fallbacks.
4
+ */
5
+
6
+ .ObFilterBuilder-root {
7
+ display: grid;
8
+ gap: var(--ds-size-4);
9
+ /*
10
+ * The saved-filter list sits beside the editor. The buttons acting on the
11
+ * selected filter share the bottom row with OK/Cancel rather than being
12
+ * confined to the list's column, so they have room to stay on one line.
13
+ * On narrow viewports everything stacks.
14
+ */
15
+ grid-template:
16
+ "sidebar main" 1fr
17
+ "error error" auto
18
+ "footer footer" auto
19
+ / minmax(14rem, 22rem) minmax(0, 1fr);
20
+ block-size: 100%;
21
+ min-block-size: 0;
22
+ }
23
+
24
+ .ObFilterBuilder-sidebar {
25
+ grid-area: sidebar;
26
+ overflow: auto;
27
+ padding: var(--ds-size-2);
28
+ border: var(--ds-border-width-default) solid var(--ds-color-border-subtle);
29
+ border-radius: var(--ds-border-radius-md);
30
+ }
31
+
32
+ /*
33
+ * The editor manages its own scrolling — the conditions scroll, the filter
34
+ * string stays put — so this only has to hand it the available height. A caller
35
+ * that replaces the editor through `renderMain` gets the same treatment.
36
+ */
37
+ .ObFilterBuilder-main {
38
+ grid-area: main;
39
+ display: flex;
40
+ flex-direction: column;
41
+ gap: var(--ds-size-3);
42
+ min-inline-size: 0;
43
+ min-block-size: 0;
44
+ }
45
+
46
+ .ObFilterBuilder-main > * {
47
+ flex: 1 1 auto;
48
+ min-inline-size: 0;
49
+ min-block-size: 0;
50
+ }
51
+
52
+ .ObFilterBuilder-error {
53
+ grid-area: error;
54
+ margin: 0;
55
+ color: var(--ds-color-danger-text-default);
56
+ }
57
+
58
+ .ObFilterBuilder-footer {
59
+ grid-area: footer;
60
+ display: flex;
61
+ flex-wrap: wrap;
62
+ align-items: center;
63
+ justify-content: space-between;
64
+ gap: var(--ds-size-4);
65
+ }
66
+
67
+ .ObFilterBuilder-toolbar,
68
+ .ObFilterBuilder-actions {
69
+ display: flex;
70
+ flex-wrap: wrap;
71
+ align-items: center;
72
+ gap: var(--ds-size-2);
73
+ }
74
+
75
+ .ObFilterBuilder-actions {
76
+ margin-inline-start: auto;
77
+ }
78
+
79
+ /*
80
+ * Without the saved-filter list there are no buttons acting on one either, so
81
+ * the editor takes the full width.
82
+ */
83
+ .ObFilterBuilder-root--noSavedFilters {
84
+ grid-template:
85
+ "main" 1fr
86
+ "error" auto
87
+ "footer" auto
88
+ / minmax(0, 1fr);
89
+ }
90
+
91
+ /*
92
+ * `Dialog` caps itself at `--dsc-dialog-max-width` (40rem), so setting a width
93
+ * here would have no effect — the variable has to be raised instead. It needs
94
+ * to be wide enough that a condition — field, operator, value and the group
95
+ * buttons — fits on one line next to the saved-filter column.
96
+ */
97
+ .ObFilterBuilder-dialog {
98
+ --dsc-dialog-max-width: 84rem;
99
+ --dsc-dialog-max-height: 90dvh;
100
+ }
101
+
102
+ /*
103
+ * A fixed height keeps the dialog from resizing as conditions are added and
104
+ * removed, and gives the saved-filter column and the editor a height to fill.
105
+ * The dialog itself must not scroll — the body does — or the heading would
106
+ * scroll away and the OK/Cancel row would not stay at the bottom.
107
+ */
108
+ .ObFilterBuilder-dialog[open] {
109
+ display: flex;
110
+ flex-direction: column;
111
+ block-size: 48rem;
112
+ overflow: hidden;
113
+ }
114
+
115
+ /*
116
+ * The heading and the close button share the header row.
117
+ */
118
+ .ObFilterBuilder-dialogHeader {
119
+ display: flex;
120
+ align-items: center;
121
+ justify-content: space-between;
122
+ gap: var(--ds-size-2);
123
+ }
124
+
125
+ .ObFilterBuilder-dialogBody {
126
+ flex: 1 1 auto;
127
+ min-block-size: 0;
128
+ overflow: hidden;
129
+ }
130
+
131
+ @media (width < 48rem) {
132
+ .ObFilterBuilder-root:not(.ObFilterBuilder-root--noSavedFilters) {
133
+ grid-template:
134
+ "sidebar" auto
135
+ "main" 1fr
136
+ "error" auto
137
+ "footer" auto
138
+ / minmax(0, 1fr);
139
+ }
140
+
141
+ /*
142
+ * Stacked, the dialog body is the scroll container: the editor cannot give
143
+ * both the list and the conditions a useful height in the space left over.
144
+ */
145
+ .ObFilterBuilder-dialogBody {
146
+ overflow: auto;
147
+ }
148
+
149
+ .ObFilterBuilder-sidebar {
150
+ max-block-size: 12rem;
151
+ }
152
+ }
@@ -0,0 +1,115 @@
1
+ import "./FilterBuilder.css";
2
+ import { type FilterTree, type SavedFilter } from "@olenbetong/appframe-core";
3
+ import { type NamedFilterType } from "@olenbetong/appframe-react";
4
+ import type { SaveFilterInput } from "@olenbetong/appframe-react";
5
+ import type { DataObject } from "@olenbetong/appframe-data";
6
+ import { type ReactNode } from "react";
7
+ import type { FilterEditorSize, GetFieldOptions } from "./types.js";
8
+ import type { FieldMetadata } from "@olenbetong/appframe-core";
9
+ export type FilterBuilderProps = {
10
+ /** The fields the user can filter on. Fields with `excludeFromFilter` are hidden. */
11
+ fields: FieldMetadata[];
12
+ /**
13
+ * The view the filter applies to. Used both for conversion and, unless
14
+ * `dbObjectId` is set, as the key saved filters are stored under.
15
+ */
16
+ viewName?: string;
17
+ /** Overrides `viewName` as the key saved filters are stored under. */
18
+ dbObjectId?: string;
19
+ /** Loads the filters saved for a report instead of for a view. */
20
+ reportId?: string;
21
+ getFieldOptions?: GetFieldOptions;
22
+ /**
23
+ * `"dialog"` wraps the builder in a modal, `"inline"` renders it in place.
24
+ * @default "dialog"
25
+ */
26
+ variant?: "dialog" | "inline";
27
+ /** Whether the dialog is open. Ignored when `variant` is `"inline"`. */
28
+ open?: boolean;
29
+ /** Called when the dialog is dismissed, and after the filter is applied. */
30
+ onClose?: () => void;
31
+ /** The filter tree. Use together with `onChange` for a controlled component. */
32
+ value?: FilterTree | null;
33
+ /** The initial filter tree when uncontrolled. */
34
+ defaultValue?: FilterTree | null;
35
+ /** Called on every edit. */
36
+ onChange?: (filter: FilterTree) => void;
37
+ /**
38
+ * Called when the user applies the filter. The tree is pruned, so incomplete
39
+ * conditions are dropped and an empty filter is reported as `null`.
40
+ */
41
+ onApply?: (filter: FilterTree | null, filterString: string) => void;
42
+ /**
43
+ * Applies the filter to a data object when the user confirms. The filter is
44
+ * written to a named slot, so it composes with other filter providers on the
45
+ * same data object instead of overwriting them.
46
+ */
47
+ dataObject?: DataObject<any>;
48
+ /**
49
+ * Parameter the filter is applied to.
50
+ * @default "filterObject"
51
+ */
52
+ filterType?: NamedFilterType;
53
+ /**
54
+ * Name of the slot the filter is applied to.
55
+ * @default "filterBuilder"
56
+ */
57
+ slotName?: string;
58
+ /**
59
+ * Shows the filter string below the tree.
60
+ * @default true
61
+ */
62
+ showFilterString?: boolean;
63
+ /** Called whenever the filter string is reconverted. */
64
+ onFilterStringChange?: (filterString: string) => void;
65
+ /** Called when a saved filter is selected, and with `null` for "New Filter". */
66
+ onSelect?: (filter: SavedFilter | null) => void;
67
+ /**
68
+ * Extra columns written along with the filter when it is saved. The report
69
+ * launcher stores its header text, its hide-criteria flag and its parameter
70
+ * values here.
71
+ */
72
+ saveValues?: SavedFilterValues;
73
+ /**
74
+ * Hides the OK/Cancel row, for callers that supply their own actions. The
75
+ * saved-filter toolbar stays.
76
+ */
77
+ hideActions?: boolean;
78
+ /**
79
+ * Replaces the OK/Cancel buttons, so a caller's own actions share the row
80
+ * with the buttons acting on the selected saved filter.
81
+ */
82
+ actions?: ReactNode;
83
+ /**
84
+ * Wraps the criteria editor, for callers that put it beside content of their
85
+ * own — the report launcher puts it in a tab next to the report parameters.
86
+ * Whatever is returned fills the column next to the saved-filter list.
87
+ */
88
+ renderMain?: (editor: ReactNode) => ReactNode;
89
+ /** Hides the saved-filter list, leaving just the criteria editor. */
90
+ hideSavedFilters?: boolean;
91
+ className?: string;
92
+ "data-size"?: FilterEditorSize;
93
+ };
94
+ /** The parts of a saved filter the builder writes on behalf of a caller. */
95
+ export type SavedFilterValues = Pick<SaveFilterInput, "headerText" | "hideCriteria" | "parameters">;
96
+ /**
97
+ * The web port of the Windows filter builder: the saved-filter list, the
98
+ * criteria editor and the save/share toolbar.
99
+ *
100
+ * Saved filters are stored as criteria strings, so selecting one round-trips
101
+ * through the conversion endpoint to rebuild the tree, and saving converts the
102
+ * tree back.
103
+ *
104
+ * @example
105
+ * ```jsx
106
+ * <FilterBuilder
107
+ * open={open}
108
+ * fields={dsPersons.getFields()}
109
+ * viewName="aviw_Personnel_Persons"
110
+ * dataObject={dsPersons}
111
+ * onClose={() => setOpen(false)}
112
+ * />
113
+ * ```
114
+ */
115
+ export declare function FilterBuilder({ fields, viewName, dbObjectId, reportId, getFieldOptions, variant, open, onClose, value, defaultValue, onChange, onApply, dataObject, filterType, slotName, showFilterString, onFilterStringChange, onSelect, saveValues, hideActions, actions, renderMain, hideSavedFilters, className, "data-size": size, }: FilterBuilderProps): import("react").JSX.Element;