@olenbetong/synergi-react 5.0.0 → 5.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 (141) hide show
  1. package/es/components/Checkbox/index.js +1 -9
  2. package/es/components/CodeEditor/CodeEditor.css +6 -6
  3. package/es/components/FilePond.js +3 -12
  4. package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
  5. package/es/components/ImageEditor/useImageHistory.js +13 -1
  6. package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +1 -1
  7. package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
  8. package/es/components/Portal/index.js +20 -20
  9. package/es/components/SplitContainer/index.js +3 -1
  10. package/es/components/Toolbar/Toolbar.css +137 -137
  11. package/es/components/Toolbar/index.js +6 -1
  12. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
  13. package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
  14. package/es/elements-ds/DescriptionInput.d.ts +16 -0
  15. package/es/elements-ds/DescriptionInput.js +41 -0
  16. package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
  17. package/es/elements-ds/DuplicateElementDamage.js +57 -0
  18. package/es/elements-ds/ElementLookup.d.ts +23 -0
  19. package/es/elements-ds/ElementLookup.js +35 -0
  20. package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
  21. package/es/elements-ds/ElementLookupDialog.js +84 -0
  22. package/es/elements-ds/FormFields.d.ts +43 -0
  23. package/es/elements-ds/FormFields.js +67 -0
  24. package/es/elements-ds/HIDScanner.d.ts +7 -0
  25. package/es/elements-ds/HIDScanner.js +36 -0
  26. package/es/elements-ds/ManualForm.d.ts +7 -0
  27. package/es/elements-ds/ManualForm.js +70 -0
  28. package/es/elements-ds/ProjectSelect.d.ts +28 -0
  29. package/es/elements-ds/ProjectSelect.js +45 -0
  30. package/es/elements-ds/elements-ds.css +157 -0
  31. package/es/elements-ds/index.d.ts +12 -0
  32. package/es/elements-ds/index.js +14 -0
  33. package/es/useTranslation/index.js +5 -3
  34. package/package.json +15 -3
  35. package/src/chrome/AppShell/AppShell.test.tsx +48 -0
  36. package/src/chrome/AppShell/index.tsx +29 -29
  37. package/src/chrome/openReport.test.ts +50 -0
  38. package/src/chrome/openReport.ts +34 -34
  39. package/src/colorScheme.test.ts +188 -0
  40. package/src/colorScheme.ts +125 -125
  41. package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
  42. package/src/components/Checkbox/index.tsx +1 -10
  43. package/src/components/CodeEditor/CodeEditor.css +6 -6
  44. package/src/components/CodeEditor/CodeEditor.tsx +173 -173
  45. package/src/components/CodeEditor/index.ts +1 -1
  46. package/src/components/ColorCard/ColorCard.test.tsx +34 -0
  47. package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
  48. package/src/components/DateNavigator/index.tsx +186 -186
  49. package/src/components/FilePond.browser.test.tsx +389 -0
  50. package/src/components/FilePond.tsx +303 -312
  51. package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
  52. package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
  53. package/src/components/ImageEditor/ImageEditor.tsx +348 -348
  54. package/src/components/ImageEditor/index.ts +9 -9
  55. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
  56. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
  57. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
  58. package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
  59. package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
  60. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
  61. package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
  62. package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
  63. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
  64. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
  65. package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
  66. package/src/components/ImageEditor/useActiveTool.ts +21 -21
  67. package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
  68. package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
  69. package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
  70. package/src/components/ImageEditor/useImageHistory.ts +206 -197
  71. package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
  72. package/src/components/ImageEditor/useOpenCV.ts +184 -184
  73. package/src/components/LinkedCardList/index.scss +95 -95
  74. package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
  75. package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +1 -0
  76. package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
  77. package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
  78. package/src/components/PageBanner/index.tsx +80 -80
  79. package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
  80. package/src/components/PdfViewer/PdfViewer.tsx +158 -158
  81. package/src/components/Portal/Portal.test.tsx +106 -0
  82. package/src/components/Portal/index.tsx +22 -25
  83. package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
  84. package/src/components/Sidebar/Sidebar.test.tsx +123 -0
  85. package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
  86. package/src/components/SplitContainer/index.tsx +335 -333
  87. package/src/components/Toolbar/Toolbar.css +137 -137
  88. package/src/components/Toolbar/Toolbar.test.tsx +216 -0
  89. package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
  90. package/src/components/Toolbar/index.tsx +270 -265
  91. package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
  92. package/src/designsystemet-web-types.d.ts +24 -24
  93. package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
  94. package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
  95. package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
  96. package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
  97. package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
  98. package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
  99. package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
  100. package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
  101. package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
  102. package/src/elements/ElementLookup.tsx +123 -123
  103. package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
  104. package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
  105. package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
  106. package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
  107. package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
  108. package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
  109. package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
  110. package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
  111. package/src/elements/ElementLookupDialog/index.tsx +226 -226
  112. package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
  113. package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
  114. package/src/elements/ProjectSelect.tsx +130 -130
  115. package/src/elements/index.ts +15 -15
  116. package/src/elements-ds/DamageForm.browser.test.tsx +530 -0
  117. package/src/elements-ds/DescriptionInput.tsx +114 -0
  118. package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
  119. package/src/elements-ds/ElementLookup.tsx +114 -0
  120. package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
  121. package/src/elements-ds/ElementLookupDialog.tsx +196 -0
  122. package/src/elements-ds/FormFields.tsx +176 -0
  123. package/src/elements-ds/HIDScanner.tsx +53 -0
  124. package/src/elements-ds/ManualForm.tsx +129 -0
  125. package/src/elements-ds/ProjectSelect.tsx +120 -0
  126. package/src/elements-ds/elements-ds.css +157 -0
  127. package/src/elements-ds/index.ts +16 -0
  128. package/src/filter/index.ts +34 -34
  129. package/src/i18n.test.ts +31 -0
  130. package/src/i18n.ts +13 -13
  131. package/src/mui/MuiThemeProvider.tsx +135 -135
  132. package/src/test/fakeCamera.ts +98 -0
  133. package/src/test/fakeDataApi.ts +90 -0
  134. package/src/test/setup.browser.ts +21 -0
  135. package/src/test/setup.ts +23 -23
  136. package/src/useTranslation/index.ts +5 -3
  137. package/src/useTranslation/useTranslation.test.ts +128 -0
  138. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
  139. package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
  140. package/es/test/setup.d.ts +0 -6
  141. package/es/test/setup.js +0 -6
@@ -8,7 +8,6 @@ function Mark(props) {
8
8
  export const Checkbox = forwardRef(function Checkbox({ className, disabled = false, id, onChange = () => null, label, title, reverse, value, ...other }, ref) {
9
9
  let inputId = useId();
10
10
  inputId = id ?? inputId;
11
- let inputIdRef = `#${inputId}`;
12
11
  let input = useRef(null);
13
12
  // oxlint-disable-next-line react-hooks/exhaustive-deps -- Ref object
14
13
  useEffect(() => {
@@ -19,13 +18,6 @@ export const Checkbox = forwardRef(function Checkbox({ className, disabled = fal
19
18
  ref.current = input.current;
20
19
  }
21
20
  }, []);
22
- function handleClick() {
23
- let elem = input.current;
24
- if (elem) {
25
- elem.focus();
26
- elem.click();
27
- }
28
- }
29
21
  function handleInputChanged(evt) {
30
22
  if (!disabled) {
31
23
  onChange(evt);
@@ -40,5 +32,5 @@ export const Checkbox = forwardRef(function Checkbox({ className, disabled = fal
40
32
  }
41
33
  }
42
34
  }
43
- return (_jsxs("div", { className: clsx("ObCheckbox-root", disabled && "Ob-disabled", reverse && "Ob-reverse", className), title: title, children: [_jsx("input", { className: "ObCheckbox-input", id: inputId, type: "checkbox", onChange: handleInputChanged, checked: value, disabled: disabled, ref: input, ...other }), _jsxs("label", { htmlFor: inputIdRef, className: "ObCheckbox-label", onKeyDown: handleKeyDown, onClick: handleClick, children: [_jsx("div", { className: "ObCheckbox-box", children: _jsx(Mark, { className: "ObCheckbox-mark" }) }), label && _jsx("div", { className: "ObCheckbox-label-text", children: label })] })] }));
35
+ return (_jsxs("div", { className: clsx("ObCheckbox-root", disabled && "Ob-disabled", reverse && "Ob-reverse", className), title: title, children: [_jsx("input", { className: "ObCheckbox-input", id: inputId, type: "checkbox", onChange: handleInputChanged, checked: value, disabled: disabled, ref: input, ...other }), _jsxs("label", { htmlFor: inputId, className: "ObCheckbox-label", onKeyDown: handleKeyDown, children: [_jsx("div", { className: "ObCheckbox-box", children: _jsx(Mark, { className: "ObCheckbox-mark" }) }), label && _jsx("div", { className: "ObCheckbox-label-text", children: label })] })] }));
44
36
  });
@@ -1,6 +1,6 @@
1
- .ObCodeEditor-root {
2
- min-height: 10rem;
3
- border: 1px solid var(--ds-color-neutral-border-subtle);
4
- border-radius: var(--ds-border-radius-md);
5
- overflow: hidden;
6
- }
1
+ .ObCodeEditor-root {
2
+ min-height: 10rem;
3
+ border: 1px solid var(--ds-color-neutral-border-subtle);
4
+ border-radius: var(--ds-border-radius-md);
5
+ overflow: hidden;
6
+ }
@@ -77,7 +77,6 @@ export function FilePond({ dataObject, fields, onUploadStart, onFileUploaded, on
77
77
  }
78
78
  return filesData;
79
79
  }, [whereClause, filesFetched, filesData]);
80
- let clearFilesRef = useRef(false);
81
80
  useEffect(() => {
82
81
  return () => {
83
82
  pondRef.current?.destroy();
@@ -86,12 +85,6 @@ export function FilePond({ dataObject, fields, onUploadStart, onFileUploaded, on
86
85
  }, []);
87
86
  useEffect(() => {
88
87
  async function removeUploadedFile(source, load, error) {
89
- // this method is also called when we clear the files on data object
90
- // refresh. Haven't found any elegant way to work around that, so instead
91
- // we set this ref to true when we remove the files to have a way
92
- // to discover why the files are being removed
93
- if (clearFilesRef.current)
94
- return;
95
88
  let { dataHandler } = dataObject;
96
89
  try {
97
90
  let result = await dataHandler.destroy({
@@ -194,11 +187,9 @@ export function FilePond({ dataObject, fields, onUploadStart, onFileUploaded, on
194
187
  });
195
188
  }
196
189
  return () => {
197
- // Indicate that we are clearing the files because data has changed,
198
- // to prevent the remove callback from deleting the files
199
- clearFilesRef.current = true;
200
- pondRef.current?.removeFiles();
201
- clearFilesRef.current = false;
190
+ // The data has changed: clear the list without deleting the files on the server
191
+ // (`remove: false` keeps FilePond from calling `server.remove` for them).
192
+ pondRef.current?.removeFiles({ remove: false });
202
193
  };
203
194
  }, [files]);
204
195
  return (_jsxs("div", { className: "filepond--wrapper", children: [attachmentPrimKeys && _jsx("input", { type: "hidden", name: "AttachmentPrimkeys", value: attachmentPrimKeys }), _jsx("input", { type: "file", ...props, name: "File", ref: inputRefProp ?? inputRef })] }));
@@ -6,29 +6,33 @@ export function useRedactTool(imageUrl) {
6
6
  let [displaySize, setDisplaySize] = useState({ width: 0, height: 0 });
7
7
  let imageUrlRef = useRef(imageUrl);
8
8
  imageUrlRef.current = imageUrl;
9
+ // Mirrors `drawing` so finishing a drag never reads a stale render closure, and so the
10
+ // new rect is added outside a state updater (React may call updaters more than once).
11
+ let drawingRef = useRef(null);
9
12
  let handleImageLoad = useCallback((e) => {
10
13
  let img = e.currentTarget;
11
14
  setDisplaySize({ width: img.clientWidth, height: img.clientHeight });
12
15
  }, []);
13
16
  function startDrawing(x, y) {
14
- setDrawing({ startX: x, startY: y, currentX: x, currentY: y });
17
+ drawingRef.current = { startX: x, startY: y, currentX: x, currentY: y };
18
+ setDrawing(drawingRef.current);
15
19
  }
16
20
  function updateDrawing(x, y) {
17
- setDrawing((d) => (d ? { ...d, currentX: x, currentY: y } : null));
21
+ if (!drawingRef.current)
22
+ return;
23
+ drawingRef.current = { ...drawingRef.current, currentX: x, currentY: y };
24
+ setDrawing(drawingRef.current);
18
25
  }
19
26
  function finishDrawing() {
20
- setDrawing((d) => {
21
- if (!d)
22
- return null;
23
- let x = Math.min(d.startX, d.currentX);
24
- let y = Math.min(d.startY, d.currentY);
25
- let w = Math.abs(d.currentX - d.startX);
26
- let h = Math.abs(d.currentY - d.startY);
27
- if (w > 4 && h > 4) {
28
- setRects((prev) => [...prev, { x, y, w, h }]);
29
- }
30
- return null;
31
- });
27
+ let d = drawingRef.current;
28
+ drawingRef.current = null;
29
+ setDrawing(null);
30
+ if (!d)
31
+ return;
32
+ let rect = normRect(d);
33
+ if (rect.w > 4 && rect.h > 4) {
34
+ setRects((prev) => [...prev, rect]);
35
+ }
32
36
  }
33
37
  function deleteRect(index) {
34
38
  setRects((prev) => prev.filter((_, i) => i !== index));
@@ -67,6 +67,10 @@ export function useImageHistory(sourceUrl, registry) {
67
67
  }
68
68
  setHistory({ past: newPast, future: newFuture });
69
69
  }
70
+ catch (err) {
71
+ // Leave image and history as they were, so the user can simply try again.
72
+ console.warn("[ImageHistory] Could not replay the edit history:", err);
73
+ }
70
74
  finally {
71
75
  if (!abort.signal.aborted) {
72
76
  isReplaying.current = false;
@@ -132,7 +136,15 @@ async function replayAll(sourceUrl, actionGroups, registry, signal) {
132
136
  console.warn(`[ImageHistory] No replay handler for action type "${action.type}" — skipping`);
133
137
  continue;
134
138
  }
135
- let blob = await apply(prevUrl, action.params);
139
+ let blob;
140
+ try {
141
+ blob = await apply(prevUrl, action.params);
142
+ }
143
+ catch (err) {
144
+ if (prevGenerated)
145
+ URL.revokeObjectURL(prevUrl);
146
+ throw err;
147
+ }
136
148
  if (signal.aborted) {
137
149
  if (prevGenerated)
138
150
  URL.revokeObjectURL(prevUrl);
@@ -10,7 +10,7 @@ const subtle = { color: "var(--ds-color-neutral-text-subtle)" };
10
10
  */
11
11
  export function MergeProgressDialogDs(props) {
12
12
  let { phase, pct, remaining, title, canClose, handleClose } = useMergeJob(props);
13
- return (_jsxs(ResponsiveDialog, { open: props.open, onClose: handleClose, closedby: canClose ? "any" : "none", title: title, maxWidth: "sm", children: [_jsxs(Dialog.Block, { children: [(phase.kind === "preparing" || phase.kind === "processing") && (_jsx(LinearProgress, { value: phase.kind === "processing" && phase.total > 0 ? pct : undefined, style: { marginBottom: "0.75rem" } })), phase.kind === "preparing" && (_jsx(Paragraph, { "data-size": "sm", style: subtle, children: getLocalizedString("Starting merge job…") })), phase.kind === "processing" && (_jsxs(_Fragment, { children: [_jsxs(Paragraph, { "data-size": "sm", children: [phase.completed, " / ", phase.total, " ", getLocalizedString("files"), remaining && _jsxs("span", { style: subtle, children: [" \u2014 ", remaining] })] }), phase.currentFile && (_jsx(Paragraph, { "data-size": "sm", title: phase.currentFile, style: {
13
+ return (_jsxs(ResponsiveDialog, { open: props.open, onClose: handleClose, closedby: canClose ? "any" : "none", closeButton: canClose ? undefined : false, title: title, maxWidth: "sm", children: [_jsxs(Dialog.Block, { children: [(phase.kind === "preparing" || phase.kind === "processing") && (_jsx(LinearProgress, { value: phase.kind === "processing" && phase.total > 0 ? pct : undefined, style: { marginBottom: "0.75rem" } })), phase.kind === "preparing" && (_jsx(Paragraph, { "data-size": "sm", style: subtle, children: getLocalizedString("Starting merge job…") })), phase.kind === "processing" && (_jsxs(_Fragment, { children: [_jsxs(Paragraph, { "data-size": "sm", children: [phase.completed, " / ", phase.total, " ", getLocalizedString("files"), remaining && _jsxs("span", { style: subtle, children: [" \u2014 ", remaining] })] }), phase.currentFile && (_jsx(Paragraph, { "data-size": "sm", title: phase.currentFile, style: {
14
14
  ...subtle,
15
15
  marginTop: "0.25rem",
16
16
  overflow: "hidden",
@@ -3,10 +3,11 @@ import { getLocalizedString } from "../../i18n.js";
3
3
  /** Waits between reconnects; together they cover a server restart of about half a minute. */
4
4
  const RECONNECT_DELAYS_MS = [1000, 2000, 3000, 5000, 8000, 13000];
5
5
  function formatRemaining(ms) {
6
- if (ms < 60_000)
7
- return `~${Math.ceil(ms / 1000)}s`;
8
- let mins = Math.floor(ms / 60_000);
9
- let secs = Math.ceil((ms % 60_000) / 1000);
6
+ let total = Math.ceil(ms / 1000);
7
+ if (total < 60)
8
+ return `~${total}s`;
9
+ let mins = Math.floor(total / 60);
10
+ let secs = total % 60;
10
11
  return secs > 0 ? `~${mins}m ${secs}s` : `~${mins}m`;
11
12
  }
12
13
  /**
@@ -1,30 +1,30 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { createPortal } from "react-dom";
4
- function useForceUpdate() {
5
- const [, setVal] = useState(false);
6
- return () => setVal((val) => !val);
7
- }
8
4
  export function Portal({ children, root, type = "div" }) {
9
- const forceUpdate = useForceUpdate();
10
5
  const mountNode = useRef(null);
11
- const portalNode = useRef(null);
12
- // oxlint-disable-next-line react-hooks/exhaustive-deps -- because reasons
6
+ const ownerDocument = useRef(null);
7
+ const [portalNode, setPortalNode] = useState(null);
8
+ /*
9
+ * The element is created after mount, in the document the placeholder was rendered in, and
10
+ * held in state: a remount (StrictMode) or a new root/type creates a fresh one and renders
11
+ * into it, rather than into the element the previous run removed.
12
+ */
13
13
  useEffect(() => {
14
- const ownerDocument = mountNode.current?.ownerDocument;
15
- if (ownerDocument && !portalNode.current) {
16
- let parent = root ? ownerDocument.querySelector(root) || ownerDocument.body : ownerDocument.body;
17
- const node = ownerDocument.createElement(type);
18
- portalNode.current = node;
19
- parent.appendChild(node);
20
- forceUpdate();
21
- return () => {
22
- parent.removeChild(node);
23
- };
24
- }
14
+ let doc = mountNode.current?.ownerDocument ?? ownerDocument.current ?? globalThis.document;
15
+ if (!doc)
16
+ return;
17
+ ownerDocument.current = doc;
18
+ let parent = (root ? doc.querySelector(root) : null) ?? doc.body;
19
+ let node = doc.createElement(type);
20
+ parent.appendChild(node);
21
+ setPortalNode(node);
22
+ return () => {
23
+ parent.removeChild(node);
24
+ };
25
25
  }, [root, type]);
26
- if (!portalNode.current) {
26
+ if (!portalNode) {
27
27
  return _jsx("div", { ref: mountNode });
28
28
  }
29
- return createPortal(children, portalNode.current);
29
+ return createPortal(children, portalNode);
30
30
  }
@@ -92,7 +92,9 @@ export function SplitContainer({ className, children, direction = "vertical", fi
92
92
  };
93
93
  let movingPanel = (fixedPanel === 1 ? divider.previousElementSibling : divider.nextElementSibling);
94
94
  function clampSize(size) {
95
- let adjustedContainerSize = containerSize - 10; // make sure divider will not be stuck outside the container
95
+ // Leave room for the divider itself, so it is never pushed out of the container.
96
+ let dividerSize = divider ? (direction === "horizontal" ? divider.offsetWidth : divider.offsetHeight) : 0;
97
+ let adjustedContainerSize = containerSize - Math.max(dividerSize, 10);
96
98
  let maxSize = Math.min(max ?? adjustedContainerSize, adjustedContainerSize);
97
99
  if (size < min) {
98
100
  size = min;
@@ -1,137 +1,137 @@
1
- .ob-breadcrumbs {
2
- display: flex;
3
- align-items: center;
4
- overflow: hidden;
5
- width: 100%;
6
- height: 100%;
7
- }
8
-
9
- .ob-breadcrumbs__list {
10
- display: flex;
11
- align-items: center;
12
- list-style: none;
13
- margin: 0;
14
- padding: 0;
15
- gap: var(--ds-space-100, 0.25rem);
16
- flex-wrap: nowrap;
17
- overflow: hidden;
18
- }
19
-
20
- .ob-breadcrumbs__item {
21
- display: flex;
22
- flex: 0 0 auto;
23
- align-items: center;
24
- font-size: var(--ds-font-size-100, 0.875rem);
25
- white-space: nowrap;
26
- color: var(--ds-text-subtle, currentColor);
27
-
28
- a {
29
- color: var(--ds-link-default, var(--ds-text-subtle, currentColor));
30
- text-decoration: none;
31
-
32
- &:hover {
33
- text-decoration: underline;
34
- color: var(--ds-link-default-hovered, var(--ds-text, currentColor));
35
- }
36
-
37
- &:focus-visible {
38
- outline: 2px solid var(--ds-border-focused, currentColor);
39
- outline-offset: 2px;
40
- border-radius: var(--ds-border-radius-100, 2px);
41
- }
42
- }
43
-
44
- &:not(:last-child)::after {
45
- content: "/";
46
- margin-inline-start: var(--ds-space-100, 0.25rem);
47
- color: var(--ds-text-disabled, currentColor);
48
- opacity: 0.5;
49
- }
50
-
51
- span[aria-current="page"] {
52
- color: var(--ds-text, currentColor);
53
- font-weight: var(--ds-font-weight-semibold, 500);
54
- }
55
- }
56
-
57
- .ob-breadcrumbs__overflow {
58
- button {
59
- background: none;
60
- border: 1px solid transparent;
61
- border-radius: var(--ds-border-radius-100, 2px);
62
- color: var(--ds-text-subtle, currentColor);
63
- cursor: pointer;
64
- font-size: var(--ds-font-size-100, 0.875rem);
65
- line-height: 1;
66
- padding: var(--ds-space-050, 0.125rem) var(--ds-space-150, 0.375rem);
67
-
68
- &:hover {
69
- background: var(--ds-background-neutral-default, rgba(0, 0, 0, 0.06));
70
- border-color: var(--ds-border-default, transparent);
71
- color: var(--ds-text, currentColor);
72
- }
73
-
74
- &:focus-visible {
75
- outline: 2px solid var(--ds-border-focused, currentColor);
76
- outline-offset: 2px;
77
- }
78
- }
79
-
80
- &::after {
81
- content: "/";
82
- margin-inline-start: var(--ds-space-100, 0.25rem);
83
- color: var(--ds-text-disabled, currentColor);
84
- opacity: 0.5;
85
- }
86
- }
87
-
88
- /*
89
- * The crumbs there is no room for, behind the "…" button. A popover, so it sits in the top
90
- * layer where the toolbar cannot clip it; placed under the button by the component. The
91
- * toolbar's contrast colour is inherited through the DOM even there, so the menu sets its own.
92
- */
93
- .ob-breadcrumbs__overflow-menu {
94
- position: fixed;
95
- inset: auto;
96
- box-sizing: border-box;
97
- min-width: 10rem;
98
- max-width: calc(100vw - 1rem);
99
- margin: 0;
100
- padding: var(--ds-size-1, 0.25rem) 0;
101
- list-style: none;
102
- border: 1px solid var(--ds-color-neutral-border-subtle, #cbd0d6);
103
- border-radius: var(--ds-border-radius-md, 4px);
104
- background: var(--ds-color-neutral-background-default, #fff);
105
- color: var(--ds-color-neutral-text-default, #1e2b3c);
106
- box-shadow: var(--ds-shadow-md, 0 4px 8px rgb(0 0 0 / 16%));
107
- font-size: var(--ds-body-sm-font-size, 0.875rem);
108
-
109
- li {
110
- a,
111
- span {
112
- display: block;
113
- padding: var(--ds-size-2, 0.5rem) var(--ds-size-4, 1rem);
114
- overflow: hidden;
115
- color: inherit;
116
- text-decoration: none;
117
- text-overflow: ellipsis;
118
- white-space: nowrap;
119
- }
120
-
121
- a:hover {
122
- background: var(--ds-color-neutral-surface-hover, rgb(0 0 0 / 6%));
123
- }
124
-
125
- a:focus-visible {
126
- outline: 2px solid var(--ds-color-focus-outer, currentColor);
127
- outline-offset: -2px;
128
- }
129
- }
130
-
131
- /* Touch sized rows where there is no pointer to aim with. */
132
- @media (pointer: coarse) {
133
- li :is(a, span) {
134
- padding-block: var(--ds-size-3, 0.75rem);
135
- }
136
- }
137
- }
1
+ .ob-breadcrumbs {
2
+ display: flex;
3
+ align-items: center;
4
+ overflow: hidden;
5
+ width: 100%;
6
+ height: 100%;
7
+ }
8
+
9
+ .ob-breadcrumbs__list {
10
+ display: flex;
11
+ align-items: center;
12
+ list-style: none;
13
+ margin: 0;
14
+ padding: 0;
15
+ gap: var(--ds-space-100, 0.25rem);
16
+ flex-wrap: nowrap;
17
+ overflow: hidden;
18
+ }
19
+
20
+ .ob-breadcrumbs__item {
21
+ display: flex;
22
+ flex: 0 0 auto;
23
+ align-items: center;
24
+ font-size: var(--ds-font-size-100, 0.875rem);
25
+ white-space: nowrap;
26
+ color: var(--ds-text-subtle, currentColor);
27
+
28
+ a {
29
+ color: var(--ds-link-default, var(--ds-text-subtle, currentColor));
30
+ text-decoration: none;
31
+
32
+ &:hover {
33
+ text-decoration: underline;
34
+ color: var(--ds-link-default-hovered, var(--ds-text, currentColor));
35
+ }
36
+
37
+ &:focus-visible {
38
+ outline: 2px solid var(--ds-border-focused, currentColor);
39
+ outline-offset: 2px;
40
+ border-radius: var(--ds-border-radius-100, 2px);
41
+ }
42
+ }
43
+
44
+ &:not(:last-child)::after {
45
+ content: "/";
46
+ margin-inline-start: var(--ds-space-100, 0.25rem);
47
+ color: var(--ds-text-disabled, currentColor);
48
+ opacity: 0.5;
49
+ }
50
+
51
+ span[aria-current="page"] {
52
+ color: var(--ds-text, currentColor);
53
+ font-weight: var(--ds-font-weight-semibold, 500);
54
+ }
55
+ }
56
+
57
+ .ob-breadcrumbs__overflow {
58
+ button {
59
+ background: none;
60
+ border: 1px solid transparent;
61
+ border-radius: var(--ds-border-radius-100, 2px);
62
+ color: var(--ds-text-subtle, currentColor);
63
+ cursor: pointer;
64
+ font-size: var(--ds-font-size-100, 0.875rem);
65
+ line-height: 1;
66
+ padding: var(--ds-space-050, 0.125rem) var(--ds-space-150, 0.375rem);
67
+
68
+ &:hover {
69
+ background: var(--ds-background-neutral-default, rgba(0, 0, 0, 0.06));
70
+ border-color: var(--ds-border-default, transparent);
71
+ color: var(--ds-text, currentColor);
72
+ }
73
+
74
+ &:focus-visible {
75
+ outline: 2px solid var(--ds-border-focused, currentColor);
76
+ outline-offset: 2px;
77
+ }
78
+ }
79
+
80
+ &::after {
81
+ content: "/";
82
+ margin-inline-start: var(--ds-space-100, 0.25rem);
83
+ color: var(--ds-text-disabled, currentColor);
84
+ opacity: 0.5;
85
+ }
86
+ }
87
+
88
+ /*
89
+ * The crumbs there is no room for, behind the "…" button. A popover, so it sits in the top
90
+ * layer where the toolbar cannot clip it; placed under the button by the component. The
91
+ * toolbar's contrast colour is inherited through the DOM even there, so the menu sets its own.
92
+ */
93
+ .ob-breadcrumbs__overflow-menu {
94
+ position: fixed;
95
+ inset: auto;
96
+ box-sizing: border-box;
97
+ min-width: 10rem;
98
+ max-width: calc(100vw - 1rem);
99
+ margin: 0;
100
+ padding: var(--ds-size-1, 0.25rem) 0;
101
+ list-style: none;
102
+ border: 1px solid var(--ds-color-neutral-border-subtle, #cbd0d6);
103
+ border-radius: var(--ds-border-radius-md, 4px);
104
+ background: var(--ds-color-neutral-background-default, #fff);
105
+ color: var(--ds-color-neutral-text-default, #1e2b3c);
106
+ box-shadow: var(--ds-shadow-md, 0 4px 8px rgb(0 0 0 / 16%));
107
+ font-size: var(--ds-body-sm-font-size, 0.875rem);
108
+
109
+ li {
110
+ a,
111
+ span {
112
+ display: block;
113
+ padding: var(--ds-size-2, 0.5rem) var(--ds-size-4, 1rem);
114
+ overflow: hidden;
115
+ color: inherit;
116
+ text-decoration: none;
117
+ text-overflow: ellipsis;
118
+ white-space: nowrap;
119
+ }
120
+
121
+ a:hover {
122
+ background: var(--ds-color-neutral-surface-hover, rgb(0 0 0 / 6%));
123
+ }
124
+
125
+ a:focus-visible {
126
+ outline: 2px solid var(--ds-color-focus-outer, currentColor);
127
+ outline-offset: -2px;
128
+ }
129
+ }
130
+
131
+ /* Touch sized rows where there is no pointer to aim with. */
132
+ @media (pointer: coarse) {
133
+ li :is(a, span) {
134
+ padding-block: var(--ds-size-3, 0.75rem);
135
+ }
136
+ }
137
+ }
@@ -87,6 +87,8 @@ function BreadcrumbLink({ item }) {
87
87
  function BreadcrumbsInner({ items }) {
88
88
  let [firstVisible, setFirstVisible] = useState(0);
89
89
  let [menuOpen, setMenuOpen] = useState(false);
90
+ // Bumped on resize, so the trail is measured again even when nothing was collapsed.
91
+ let [, setMeasuredWidth] = useState(0);
90
92
  let navRef = useRef(null);
91
93
  let listRef = useRef(null);
92
94
  let buttonRef = useRef(null);
@@ -114,7 +116,9 @@ function BreadcrumbsInner({ items }) {
114
116
  }
115
117
  });
116
118
  // ResizeObserver resets firstVisible to 0 on container resize so that the
117
- // overflow calculation starts fresh at the new container width.
119
+ // overflow calculation starts fresh at the new container width. The width is kept in
120
+ // state as well: when nothing was collapsed, resetting firstVisible alone would not
121
+ // re-render, and a narrowed toolbar would clip the trail instead of collapsing it.
118
122
  useEffect(() => {
119
123
  let nav = navRef.current;
120
124
  if (!nav)
@@ -126,6 +130,7 @@ function BreadcrumbsInner({ items }) {
126
130
  return;
127
131
  width = nav.clientWidth;
128
132
  setFirstVisible(0);
133
+ setMeasuredWidth(width);
129
134
  });
130
135
  observer.observe(nav);
131
136
  return () => observer.disconnect();
@@ -1,5 +1,12 @@
1
+ /*
2
+ * `textMode: "Plain"` returns the symbol's content as encoded, with GS1 separators as U+001D -
3
+ * what `Giai.fromString` parses and the other engines return. zxing's own default ("HRI") gives
4
+ * the human-readable form instead: `(8004)7043210...` for a GS1 label and `<GS>` for a separator,
5
+ * neither of which resolves to an element.
6
+ */
1
7
  const defaultFrameOptions = {
2
8
  formats: ["DataMatrix"],
9
+ textMode: "Plain",
3
10
  tryHarder: false,
4
11
  tryRotate: true,
5
12
  tryInvert: false,
@@ -8,6 +15,7 @@ const defaultFrameOptions = {
8
15
  };
9
16
  const defaultImageOptions = {
10
17
  formats: ["DataMatrix"],
18
+ textMode: "Plain",
11
19
  tryHarder: true,
12
20
  tryRotate: true,
13
21
  tryInvert: true,
@@ -15,7 +15,9 @@ export function useHIDScanner(onRead, enabled = false) {
15
15
  }, 500);
16
16
  }
17
17
  else if (event.key === "Enter") {
18
- onRead(buffer);
18
+ // An Enter with nothing scanned (a stray key press) is not a read.
19
+ if (buffer)
20
+ onRead(buffer);
19
21
  buffer = "";
20
22
  }
21
23
  }
@@ -0,0 +1,16 @@
1
+ import type { DescriptionInputType } from "../elements/ElementDamage/DescriptionInput.js";
2
+ export type { DescriptionInputType };
3
+ export type DescriptionInputProps = {
4
+ value?: DescriptionInputType | null;
5
+ defaultValue?: DescriptionInputType | null;
6
+ descriptionOptions?: string[];
7
+ storageNamespace?: string;
8
+ onCopyPrevDamage?: (value: DescriptionInputType) => void;
9
+ onChange?: (value: DescriptionInputType) => void;
10
+ };
11
+ /**
12
+ * Date, description (with suggestions), cause and action of an element damage, plus a button that
13
+ * copies the last registered damage's texts. Designsystemet version of `DescriptionInput` in
14
+ * `@olenbetong/synergi-react/elements`.
15
+ */
16
+ export declare function DescriptionInput({ value, defaultValue, descriptionOptions, storageNamespace, onCopyPrevDamage, onChange, }: DescriptionInputProps): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Textfield } from "@digdir/designsystemet-react";
3
+ import { ArrowUndoIcon } from "@navikt/aksel-icons";
4
+ import { Autocomplete } from "@olenbetong/appframe-ds";
5
+ import { useState } from "react";
6
+ import { getLocalizedString } from "../i18n.js";
7
+ /**
8
+ * Date, description (with suggestions), cause and action of an element damage, plus a button that
9
+ * copies the last registered damage's texts. Designsystemet version of `DescriptionInput` in
10
+ * `@olenbetong/synergi-react/elements`.
11
+ */
12
+ export function DescriptionInput({ value, defaultValue, descriptionOptions = [
13
+ getLocalizedString("Tear in element"),
14
+ getLocalizedString("Damage around lifting anchor"),
15
+ getLocalizedString("Damage on underside"),
16
+ ], storageNamespace = "ElementDamage", onCopyPrevDamage, onChange, }) {
17
+ let [input, setInput] = useState(defaultValue ?? null);
18
+ let [initialDefault, setInitialDefault] = useState(defaultValue);
19
+ let [today] = useState(() => new Date());
20
+ let inputValue = value === undefined ? input : value;
21
+ // A default value that arrives after the first render (loader data) is taken once.
22
+ if (defaultValue && !initialDefault) {
23
+ setInitialDefault(defaultValue);
24
+ if (value === undefined)
25
+ setInput(defaultValue);
26
+ }
27
+ function handleCopyPrevDamage() {
28
+ let copied = {
29
+ Description: localStorage.getItem(`${storageNamespace}_Description`) ?? "",
30
+ Cause: localStorage.getItem(`${storageNamespace}_Cause`) ?? "",
31
+ Action: localStorage.getItem(`${storageNamespace}_Action`) ?? "",
32
+ };
33
+ onCopyPrevDamage?.(copied);
34
+ setInput({ ...inputValue, ...copied });
35
+ }
36
+ function handleOnChange(value) {
37
+ onChange?.(value);
38
+ setInput(value);
39
+ }
40
+ return (_jsxs(_Fragment, { children: [_jsx(Textfield, { name: "Date", type: "date", id: "NewElementDamage_Date", label: getLocalizedString("Date"), required: true, value: (inputValue?.Date ?? today).toISOString().split("T")[0], onChange: (event) => event.target.value && handleOnChange({ ...inputValue, Date: new Date(event.target.value) }) }), _jsx("div", { children: _jsxs(Button, { variant: "secondary", onClick: handleCopyPrevDamage, children: [_jsx(ArrowUndoIcon, { "aria-hidden": true }), getLocalizedString("Copy previous damage")] }) }), _jsx("input", { type: "hidden", name: "Description", value: inputValue?.Description ?? "" }), _jsx(Autocomplete, { freeSolo: true, id: "NewElementDamage_Description", required: true, label: getLocalizedString("Description"), options: descriptionOptions, value: inputValue?.Description ?? "", inputValue: inputValue?.Description ?? "", onInputChange: (_event, text) => handleOnChange({ ...inputValue, Description: text }), onChange: (_event, value) => handleOnChange({ ...inputValue, Description: value ?? "" }) }), _jsx(Textfield, { name: "Cause", id: "NewElementDamage_Cause", label: getLocalizedString("Cause"), value: inputValue?.Cause ?? "", onChange: (event) => handleOnChange({ ...inputValue, Cause: event.currentTarget.value }) }), _jsx(Textfield, { name: "Action", id: "NewElementDamage_Action", label: getLocalizedString("Action"), value: inputValue?.Action ?? "", onChange: (event) => handleOnChange({ ...inputValue, Action: event.currentTarget.value }) })] }));
41
+ }