@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.
- package/es/components/Checkbox/index.js +1 -9
- package/es/components/CodeEditor/CodeEditor.css +6 -6
- package/es/components/FilePond.js +3 -12
- package/es/components/ImageEditor/plugins/redactPlugin/useRedactTool.js +18 -14
- package/es/components/ImageEditor/useImageHistory.js +13 -1
- package/es/components/MergeProgressDialog/MergeProgressDialogDs.js +1 -1
- package/es/components/MergeProgressDialog/useMergeJob.js +5 -4
- package/es/components/Portal/index.js +20 -20
- package/es/components/SplitContainer/index.js +3 -1
- package/es/components/Toolbar/Toolbar.css +137 -137
- package/es/components/Toolbar/index.js +6 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.js +8 -0
- package/es/elements/ElementLookupDialog/HIDScanner/useHIDScanner.js +3 -1
- package/es/elements-ds/DescriptionInput.d.ts +16 -0
- package/es/elements-ds/DescriptionInput.js +41 -0
- package/es/elements-ds/DuplicateElementDamage.d.ts +40 -0
- package/es/elements-ds/DuplicateElementDamage.js +57 -0
- package/es/elements-ds/ElementLookup.d.ts +23 -0
- package/es/elements-ds/ElementLookup.js +35 -0
- package/es/elements-ds/ElementLookupDialog.d.ts +7 -0
- package/es/elements-ds/ElementLookupDialog.js +84 -0
- package/es/elements-ds/FormFields.d.ts +43 -0
- package/es/elements-ds/FormFields.js +67 -0
- package/es/elements-ds/HIDScanner.d.ts +7 -0
- package/es/elements-ds/HIDScanner.js +36 -0
- package/es/elements-ds/ManualForm.d.ts +7 -0
- package/es/elements-ds/ManualForm.js +70 -0
- package/es/elements-ds/ProjectSelect.d.ts +28 -0
- package/es/elements-ds/ProjectSelect.js +45 -0
- package/es/elements-ds/elements-ds.css +157 -0
- package/es/elements-ds/index.d.ts +12 -0
- package/es/elements-ds/index.js +14 -0
- package/es/useTranslation/index.js +5 -3
- package/package.json +15 -3
- package/src/chrome/AppShell/AppShell.test.tsx +48 -0
- package/src/chrome/AppShell/index.tsx +29 -29
- package/src/chrome/openReport.test.ts +50 -0
- package/src/chrome/openReport.ts +34 -34
- package/src/colorScheme.test.ts +188 -0
- package/src/colorScheme.ts +125 -125
- package/src/components/Checkbox/Checkbox.browser.test.tsx +116 -0
- package/src/components/Checkbox/index.tsx +1 -10
- package/src/components/CodeEditor/CodeEditor.css +6 -6
- package/src/components/CodeEditor/CodeEditor.tsx +173 -173
- package/src/components/CodeEditor/index.ts +1 -1
- package/src/components/ColorCard/ColorCard.test.tsx +34 -0
- package/src/components/DateNavigator/DateNavigator.test.tsx +175 -0
- package/src/components/DateNavigator/index.tsx +186 -186
- package/src/components/FilePond.browser.test.tsx +389 -0
- package/src/components/FilePond.tsx +303 -312
- package/src/components/ImageEditor/ImageEditor.browser.test.tsx +286 -0
- package/src/components/ImageEditor/ImageEditor.test.tsx +299 -0
- package/src/components/ImageEditor/ImageEditor.tsx +348 -348
- package/src/components/ImageEditor/index.ts +9 -9
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +165 -165
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +48 -48
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.test.ts +225 -0
- package/src/components/ImageEditor/plugins/cropPlugin/useCropTool.ts +405 -405
- package/src/components/ImageEditor/plugins/plugins.browser.test.ts +252 -0
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +47 -47
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.test.ts +89 -0
- package/src/components/ImageEditor/plugins/redactPlugin/useRedactTool.ts +16 -13
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomContext.tsx +23 -23
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +40 -40
- package/src/components/ImageEditor/plugins/zoomPlugin/useZoomPan.test.ts +154 -0
- package/src/components/ImageEditor/useActiveTool.ts +21 -21
- package/src/components/ImageEditor/useEdgeDetection.test.ts +96 -0
- package/src/components/ImageEditor/useEdgeDetection.ts +319 -319
- package/src/components/ImageEditor/useImageHistory.test.ts +409 -0
- package/src/components/ImageEditor/useImageHistory.ts +206 -197
- package/src/components/ImageEditor/useOpenCV.test.ts +208 -0
- package/src/components/ImageEditor/useOpenCV.ts +184 -184
- package/src/components/LinkedCardList/index.scss +95 -95
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.browser.test.tsx +156 -0
- package/src/components/MergeProgressDialog/MergeProgressDialogDs.tsx +1 -0
- package/src/components/MergeProgressDialog/useMergeJob.test.ts +326 -0
- package/src/components/MergeProgressDialog/useMergeJob.ts +4 -3
- package/src/components/PageBanner/index.tsx +80 -80
- package/src/components/PdfViewer/PdfViewer.browser.test.tsx +78 -0
- package/src/components/PdfViewer/PdfViewer.tsx +158 -158
- package/src/components/Portal/Portal.test.tsx +106 -0
- package/src/components/Portal/index.tsx +22 -25
- package/src/components/Sidebar/Sidebar.browser.test.tsx +57 -0
- package/src/components/Sidebar/Sidebar.test.tsx +123 -0
- package/src/components/SplitContainer/SplitContainer.browser.test.tsx +304 -0
- package/src/components/SplitContainer/index.tsx +335 -333
- package/src/components/Toolbar/Toolbar.css +137 -137
- package/src/components/Toolbar/Toolbar.test.tsx +216 -0
- package/src/components/Toolbar/ToolbarBreadcrumbs.browser.test.tsx +137 -0
- package/src/components/Toolbar/index.tsx +270 -265
- package/src/components/ValueToggleGroup/ValueToggleGroup.test.tsx +112 -0
- package/src/designsystemet-web-types.d.ts +24 -24
- package/src/elements/ElementDamage/DamageFormButtons.tsx +35 -35
- package/src/elements/ElementDamage/DescriptionInput.tsx +120 -120
- package/src/elements/ElementDamage/DuplicateDamage/DesktopView.tsx +82 -82
- package/src/elements/ElementDamage/DuplicateDamage/DublicateElementDamageDialog.tsx +67 -67
- package/src/elements/ElementDamage/DuplicateDamage/PhoneView.tsx +45 -45
- package/src/elements/ElementDamage/ElementNumberTextField.tsx +41 -41
- package/src/elements/ElementDamage/RegisterFix.tsx +100 -100
- package/src/elements/ElementDamage/SubmitButtons.tsx +40 -40
- package/src/elements/ElementDamage/TransportElementSelect.tsx +52 -52
- package/src/elements/ElementLookup.tsx +123 -123
- package/src/elements/ElementLookupDialog/BarcodeScanner/BarcodeScanner.browser.test.tsx +175 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/decoders/zxing.ts +8 -0
- package/src/elements/ElementLookupDialog/BarcodeScanner/engines.browser.test.ts +225 -0
- package/src/elements/ElementLookupDialog/HIDScanner/index.tsx +67 -67
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.test.ts +124 -0
- package/src/elements/ElementLookupDialog/HIDScanner/useHIDScanner.ts +2 -1
- package/src/elements/ElementLookupDialog/Manual/ManualForm.tsx +141 -141
- package/src/elements/ElementLookupDialog/getElement.test.ts +133 -0
- package/src/elements/ElementLookupDialog/index.tsx +226 -226
- package/src/elements/ElementLookupDialog/utils/Giai.test.ts +53 -0
- package/src/elements/ElementLookupDialog/utils/Giai.ts +209 -209
- package/src/elements/ProjectSelect.tsx +130 -130
- package/src/elements/index.ts +15 -15
- package/src/elements-ds/DamageForm.browser.test.tsx +530 -0
- package/src/elements-ds/DescriptionInput.tsx +114 -0
- package/src/elements-ds/DuplicateElementDamage.tsx +185 -0
- package/src/elements-ds/ElementLookup.tsx +114 -0
- package/src/elements-ds/ElementLookupDialog.browser.test.tsx +207 -0
- package/src/elements-ds/ElementLookupDialog.tsx +196 -0
- package/src/elements-ds/FormFields.tsx +176 -0
- package/src/elements-ds/HIDScanner.tsx +53 -0
- package/src/elements-ds/ManualForm.tsx +129 -0
- package/src/elements-ds/ProjectSelect.tsx +120 -0
- package/src/elements-ds/elements-ds.css +157 -0
- package/src/elements-ds/index.ts +16 -0
- package/src/filter/index.ts +34 -34
- package/src/i18n.test.ts +31 -0
- package/src/i18n.ts +13 -13
- package/src/mui/MuiThemeProvider.tsx +135 -135
- package/src/test/fakeCamera.ts +98 -0
- package/src/test/fakeDataApi.ts +90 -0
- package/src/test/setup.browser.ts +21 -0
- package/src/test/setup.ts +23 -23
- package/src/useTranslation/index.ts +5 -3
- package/src/useTranslation/useTranslation.test.ts +128 -0
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.d.ts +0 -1
- package/es/elements/ElementLookupDialog/BarcodeScanner/decoders.test.js +0 -103
- package/es/test/setup.d.ts +0 -6
- package/es/test/setup.js +0 -6
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
import clsx from "clsx";
|
|
2
|
-
import * as monaco from "monaco-editor";
|
|
3
|
-
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
4
|
-
|
|
5
|
-
import { useResolvedColorScheme } from "../../colorScheme.js";
|
|
6
|
-
import "./CodeEditor.css";
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Monaco on the 2026 templates comes from the platform bundle through the import map. The
|
|
10
|
-
* platform entry sets `MonacoEnvironment` (the editor and language workers, served next to it)
|
|
11
|
-
* and links Monaco's stylesheet on first import, so this component only drives the editor.
|
|
12
|
-
* Off the platform (the Vite dev server, a legacy template) Monaco is bundled from npm: its
|
|
13
|
-
* stylesheets come with it, and without `MonacoEnvironment` the language services run on the
|
|
14
|
-
* main thread with a console warning. That is fine for development; it is why this lives in its
|
|
15
|
-
* own entry point and is not re-exported from the package root.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export type CodeEditorHandle = {
|
|
19
|
-
/** The Monaco editor instance, once mounted. */
|
|
20
|
-
editor: monaco.editor.IStandaloneCodeEditor | null;
|
|
21
|
-
/** Replaces the selection (or inserts at the cursor) and focuses the editor. */
|
|
22
|
-
insertText(text: string): void;
|
|
23
|
-
focus(): void;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type CodeEditorProps = {
|
|
27
|
-
/** The text shown. The editor is controlled: `onChange` reports every edit. */
|
|
28
|
-
value: string;
|
|
29
|
-
onChange?: (value: string) => void;
|
|
30
|
-
/** Monaco language ID, e.g. `html`, `css`, `javascript`, `json`, `sql`, `xml`. */
|
|
31
|
-
language?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Identifies the document. When it changes, the editor gets a fresh model, so undo history
|
|
34
|
-
* does not leak from one record to the next. Without it, a new `value` is applied as an edit
|
|
35
|
-
* that can be undone.
|
|
36
|
-
*/
|
|
37
|
-
docKey?: string;
|
|
38
|
-
readOnly?: boolean;
|
|
39
|
-
/** Ctrl/Cmd+S inside the editor. */
|
|
40
|
-
onSave?: () => void;
|
|
41
|
-
/** Extra Monaco options, applied on mount and whenever the object changes. */
|
|
42
|
-
options?: monaco.editor.IEditorOptions;
|
|
43
|
-
className?: string;
|
|
44
|
-
style?: React.CSSProperties;
|
|
45
|
-
"aria-label"?: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Monaco code editor that follows the site's colour scheme. The element fills its parent's size
|
|
50
|
-
* through `className`/`style`; give it a height.
|
|
51
|
-
*/
|
|
52
|
-
export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(function CodeEditor(
|
|
53
|
-
{
|
|
54
|
-
value,
|
|
55
|
-
onChange,
|
|
56
|
-
language = "plaintext",
|
|
57
|
-
docKey,
|
|
58
|
-
readOnly = false,
|
|
59
|
-
onSave,
|
|
60
|
-
options,
|
|
61
|
-
className,
|
|
62
|
-
style,
|
|
63
|
-
"aria-label": ariaLabel,
|
|
64
|
-
},
|
|
65
|
-
ref,
|
|
66
|
-
) {
|
|
67
|
-
let container = useRef<HTMLDivElement>(null);
|
|
68
|
-
let editor = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
|
|
69
|
-
// Latest callbacks without re-creating the editor.
|
|
70
|
-
let callbacks = useRef({ onChange, onSave });
|
|
71
|
-
callbacks.current = { onChange, onSave };
|
|
72
|
-
// Set while the editor applies a `value` from props, so that edit is not reported back.
|
|
73
|
-
let applyingValue = useRef(false);
|
|
74
|
-
let shownDoc = useRef<string | undefined>(undefined);
|
|
75
|
-
let colorScheme = useResolvedColorScheme();
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (!container.current) return;
|
|
79
|
-
let instance = monaco.editor.create(container.current, {
|
|
80
|
-
value,
|
|
81
|
-
language,
|
|
82
|
-
theme: colorScheme === "dark" ? "vs-dark" : "vs",
|
|
83
|
-
automaticLayout: true,
|
|
84
|
-
minimap: { enabled: false },
|
|
85
|
-
scrollBeyondLastLine: false,
|
|
86
|
-
fixedOverflowWidgets: true,
|
|
87
|
-
ariaLabel,
|
|
88
|
-
readOnly,
|
|
89
|
-
...options,
|
|
90
|
-
});
|
|
91
|
-
editor.current = instance;
|
|
92
|
-
shownDoc.current = docKey;
|
|
93
|
-
let changeListener = instance.onDidChangeModelContent(() => {
|
|
94
|
-
if (!applyingValue.current) {
|
|
95
|
-
callbacks.current.onChange?.(instance.getValue());
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
instance.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => callbacks.current.onSave?.());
|
|
99
|
-
|
|
100
|
-
return () => {
|
|
101
|
-
changeListener.dispose();
|
|
102
|
-
instance.getModel()?.dispose();
|
|
103
|
-
instance.dispose();
|
|
104
|
-
editor.current = null;
|
|
105
|
-
};
|
|
106
|
-
// The editor is created once; every prop is synced by the effects below.
|
|
107
|
-
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
-
}, []);
|
|
109
|
-
|
|
110
|
-
useEffect(() => {
|
|
111
|
-
let instance = editor.current;
|
|
112
|
-
if (!instance) return;
|
|
113
|
-
|
|
114
|
-
applyingValue.current = true;
|
|
115
|
-
try {
|
|
116
|
-
if (shownDoc.current !== docKey) {
|
|
117
|
-
// New document: a new model, so undo history stays with the document it belongs to.
|
|
118
|
-
let old = instance.getModel();
|
|
119
|
-
instance.setModel(monaco.editor.createModel(value, language));
|
|
120
|
-
old?.dispose();
|
|
121
|
-
shownDoc.current = docKey;
|
|
122
|
-
} else if (instance.getValue() !== value) {
|
|
123
|
-
// Same document, changed from outside (cancel, reload): one undoable edit.
|
|
124
|
-
let model = instance.getModel();
|
|
125
|
-
if (model) {
|
|
126
|
-
instance.executeEdits("external", [{ range: model.getFullModelRange(), text: value }]);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
} finally {
|
|
130
|
-
applyingValue.current = false;
|
|
131
|
-
}
|
|
132
|
-
}, [docKey, value, language]);
|
|
133
|
-
|
|
134
|
-
useEffect(() => {
|
|
135
|
-
let model = editor.current?.getModel();
|
|
136
|
-
if (model && model.getLanguageId() !== language) {
|
|
137
|
-
monaco.editor.setModelLanguage(model, language);
|
|
138
|
-
}
|
|
139
|
-
}, [language]);
|
|
140
|
-
|
|
141
|
-
useEffect(() => {
|
|
142
|
-
editor.current?.updateOptions({ readOnly, ariaLabel, ...options });
|
|
143
|
-
}, [readOnly, ariaLabel, options]);
|
|
144
|
-
|
|
145
|
-
useEffect(() => {
|
|
146
|
-
// The theme is global to every editor on the page.
|
|
147
|
-
monaco.editor.setTheme(colorScheme === "dark" ? "vs-dark" : "vs");
|
|
148
|
-
}, [colorScheme]);
|
|
149
|
-
|
|
150
|
-
useImperativeHandle(ref, () => ({
|
|
151
|
-
get editor() {
|
|
152
|
-
return editor.current;
|
|
153
|
-
},
|
|
154
|
-
insertText(text: string) {
|
|
155
|
-
let instance = editor.current;
|
|
156
|
-
if (!instance) return;
|
|
157
|
-
let range = instance.getSelection() ?? new monaco.Range(1, 1, 1, 1);
|
|
158
|
-
instance.executeEdits("insert", [{ range, text, forceMoveMarkers: true }]);
|
|
159
|
-
instance.focus();
|
|
160
|
-
},
|
|
161
|
-
focus() {
|
|
162
|
-
editor.current?.focus();
|
|
163
|
-
},
|
|
164
|
-
}));
|
|
165
|
-
|
|
166
|
-
/*
|
|
167
|
-
* `monaco-component`: Monaco renders the context menu in a shadow root attached to this
|
|
168
|
-
* container, a parent of `.monaco-editor`. Its colours are theme variables Monaco defines on
|
|
169
|
-
* `.monaco-editor, .monaco-diff-editor, .monaco-component` only, so without the class the
|
|
170
|
-
* menu inherits none of them and has no background.
|
|
171
|
-
*/
|
|
172
|
-
return <div ref={container} className={clsx("ObCodeEditor-root", "monaco-component", className)} style={style} />;
|
|
173
|
-
});
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import * as monaco from "monaco-editor";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
import { useResolvedColorScheme } from "../../colorScheme.js";
|
|
6
|
+
import "./CodeEditor.css";
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Monaco on the 2026 templates comes from the platform bundle through the import map. The
|
|
10
|
+
* platform entry sets `MonacoEnvironment` (the editor and language workers, served next to it)
|
|
11
|
+
* and links Monaco's stylesheet on first import, so this component only drives the editor.
|
|
12
|
+
* Off the platform (the Vite dev server, a legacy template) Monaco is bundled from npm: its
|
|
13
|
+
* stylesheets come with it, and without `MonacoEnvironment` the language services run on the
|
|
14
|
+
* main thread with a console warning. That is fine for development; it is why this lives in its
|
|
15
|
+
* own entry point and is not re-exported from the package root.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export type CodeEditorHandle = {
|
|
19
|
+
/** The Monaco editor instance, once mounted. */
|
|
20
|
+
editor: monaco.editor.IStandaloneCodeEditor | null;
|
|
21
|
+
/** Replaces the selection (or inserts at the cursor) and focuses the editor. */
|
|
22
|
+
insertText(text: string): void;
|
|
23
|
+
focus(): void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type CodeEditorProps = {
|
|
27
|
+
/** The text shown. The editor is controlled: `onChange` reports every edit. */
|
|
28
|
+
value: string;
|
|
29
|
+
onChange?: (value: string) => void;
|
|
30
|
+
/** Monaco language ID, e.g. `html`, `css`, `javascript`, `json`, `sql`, `xml`. */
|
|
31
|
+
language?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Identifies the document. When it changes, the editor gets a fresh model, so undo history
|
|
34
|
+
* does not leak from one record to the next. Without it, a new `value` is applied as an edit
|
|
35
|
+
* that can be undone.
|
|
36
|
+
*/
|
|
37
|
+
docKey?: string;
|
|
38
|
+
readOnly?: boolean;
|
|
39
|
+
/** Ctrl/Cmd+S inside the editor. */
|
|
40
|
+
onSave?: () => void;
|
|
41
|
+
/** Extra Monaco options, applied on mount and whenever the object changes. */
|
|
42
|
+
options?: monaco.editor.IEditorOptions;
|
|
43
|
+
className?: string;
|
|
44
|
+
style?: React.CSSProperties;
|
|
45
|
+
"aria-label"?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Monaco code editor that follows the site's colour scheme. The element fills its parent's size
|
|
50
|
+
* through `className`/`style`; give it a height.
|
|
51
|
+
*/
|
|
52
|
+
export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(function CodeEditor(
|
|
53
|
+
{
|
|
54
|
+
value,
|
|
55
|
+
onChange,
|
|
56
|
+
language = "plaintext",
|
|
57
|
+
docKey,
|
|
58
|
+
readOnly = false,
|
|
59
|
+
onSave,
|
|
60
|
+
options,
|
|
61
|
+
className,
|
|
62
|
+
style,
|
|
63
|
+
"aria-label": ariaLabel,
|
|
64
|
+
},
|
|
65
|
+
ref,
|
|
66
|
+
) {
|
|
67
|
+
let container = useRef<HTMLDivElement>(null);
|
|
68
|
+
let editor = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
|
|
69
|
+
// Latest callbacks without re-creating the editor.
|
|
70
|
+
let callbacks = useRef({ onChange, onSave });
|
|
71
|
+
callbacks.current = { onChange, onSave };
|
|
72
|
+
// Set while the editor applies a `value` from props, so that edit is not reported back.
|
|
73
|
+
let applyingValue = useRef(false);
|
|
74
|
+
let shownDoc = useRef<string | undefined>(undefined);
|
|
75
|
+
let colorScheme = useResolvedColorScheme();
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!container.current) return;
|
|
79
|
+
let instance = monaco.editor.create(container.current, {
|
|
80
|
+
value,
|
|
81
|
+
language,
|
|
82
|
+
theme: colorScheme === "dark" ? "vs-dark" : "vs",
|
|
83
|
+
automaticLayout: true,
|
|
84
|
+
minimap: { enabled: false },
|
|
85
|
+
scrollBeyondLastLine: false,
|
|
86
|
+
fixedOverflowWidgets: true,
|
|
87
|
+
ariaLabel,
|
|
88
|
+
readOnly,
|
|
89
|
+
...options,
|
|
90
|
+
});
|
|
91
|
+
editor.current = instance;
|
|
92
|
+
shownDoc.current = docKey;
|
|
93
|
+
let changeListener = instance.onDidChangeModelContent(() => {
|
|
94
|
+
if (!applyingValue.current) {
|
|
95
|
+
callbacks.current.onChange?.(instance.getValue());
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
instance.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => callbacks.current.onSave?.());
|
|
99
|
+
|
|
100
|
+
return () => {
|
|
101
|
+
changeListener.dispose();
|
|
102
|
+
instance.getModel()?.dispose();
|
|
103
|
+
instance.dispose();
|
|
104
|
+
editor.current = null;
|
|
105
|
+
};
|
|
106
|
+
// The editor is created once; every prop is synced by the effects below.
|
|
107
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
let instance = editor.current;
|
|
112
|
+
if (!instance) return;
|
|
113
|
+
|
|
114
|
+
applyingValue.current = true;
|
|
115
|
+
try {
|
|
116
|
+
if (shownDoc.current !== docKey) {
|
|
117
|
+
// New document: a new model, so undo history stays with the document it belongs to.
|
|
118
|
+
let old = instance.getModel();
|
|
119
|
+
instance.setModel(monaco.editor.createModel(value, language));
|
|
120
|
+
old?.dispose();
|
|
121
|
+
shownDoc.current = docKey;
|
|
122
|
+
} else if (instance.getValue() !== value) {
|
|
123
|
+
// Same document, changed from outside (cancel, reload): one undoable edit.
|
|
124
|
+
let model = instance.getModel();
|
|
125
|
+
if (model) {
|
|
126
|
+
instance.executeEdits("external", [{ range: model.getFullModelRange(), text: value }]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} finally {
|
|
130
|
+
applyingValue.current = false;
|
|
131
|
+
}
|
|
132
|
+
}, [docKey, value, language]);
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
let model = editor.current?.getModel();
|
|
136
|
+
if (model && model.getLanguageId() !== language) {
|
|
137
|
+
monaco.editor.setModelLanguage(model, language);
|
|
138
|
+
}
|
|
139
|
+
}, [language]);
|
|
140
|
+
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
editor.current?.updateOptions({ readOnly, ariaLabel, ...options });
|
|
143
|
+
}, [readOnly, ariaLabel, options]);
|
|
144
|
+
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
// The theme is global to every editor on the page.
|
|
147
|
+
monaco.editor.setTheme(colorScheme === "dark" ? "vs-dark" : "vs");
|
|
148
|
+
}, [colorScheme]);
|
|
149
|
+
|
|
150
|
+
useImperativeHandle(ref, () => ({
|
|
151
|
+
get editor() {
|
|
152
|
+
return editor.current;
|
|
153
|
+
},
|
|
154
|
+
insertText(text: string) {
|
|
155
|
+
let instance = editor.current;
|
|
156
|
+
if (!instance) return;
|
|
157
|
+
let range = instance.getSelection() ?? new monaco.Range(1, 1, 1, 1);
|
|
158
|
+
instance.executeEdits("insert", [{ range, text, forceMoveMarkers: true }]);
|
|
159
|
+
instance.focus();
|
|
160
|
+
},
|
|
161
|
+
focus() {
|
|
162
|
+
editor.current?.focus();
|
|
163
|
+
},
|
|
164
|
+
}));
|
|
165
|
+
|
|
166
|
+
/*
|
|
167
|
+
* `monaco-component`: Monaco renders the context menu in a shadow root attached to this
|
|
168
|
+
* container, a parent of `.monaco-editor`. Its colours are theme variables Monaco defines on
|
|
169
|
+
* `.monaco-editor, .monaco-diff-editor, .monaco-component` only, so without the class the
|
|
170
|
+
* menu inherits none of them and has no background.
|
|
171
|
+
*/
|
|
172
|
+
return <div ref={container} className={clsx("ObCodeEditor-root", "monaco-component", className)} style={style} />;
|
|
173
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CodeEditor, type CodeEditorHandle, type CodeEditorProps } from "./CodeEditor.js";
|
|
1
|
+
export { CodeEditor, type CodeEditorHandle, type CodeEditorProps } from "./CodeEditor.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { CardDetail, ColorCard } from "./index";
|
|
5
|
+
|
|
6
|
+
describe("ColorCard", () => {
|
|
7
|
+
it("is a link when it has an address", () => {
|
|
8
|
+
render(<ColorCard href="/customers/12">Olen Betong AS</ColorCard>);
|
|
9
|
+
expect(screen.getByRole("link", { name: "Olen Betong AS" })).toHaveAttribute("href", "/customers/12");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("is a plain block without one", () => {
|
|
13
|
+
let { container } = render(<ColorCard className="mb-2">Olen Betong AS</ColorCard>);
|
|
14
|
+
expect(screen.queryByRole("link")).toBeNull();
|
|
15
|
+
expect(container.firstElementChild).toHaveClass("ObColorCard-root", "mb-2");
|
|
16
|
+
expect(container.firstElementChild!.tagName).toBe("DIV");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("renders as the element it is told to", () => {
|
|
20
|
+
render(<ColorCard as="button">Open</ColorCard>);
|
|
21
|
+
expect(screen.getByRole("button", { name: "Open" })).toHaveClass("ObColorCard-root");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("CardDetail", () => {
|
|
26
|
+
it("shows its label only when it has one", () => {
|
|
27
|
+
let { container, rerender } = render(<CardDetail label="Volume">12 m³</CardDetail>);
|
|
28
|
+
expect(screen.getByText("Volume")).toHaveClass("ObColorCard-detailLabel");
|
|
29
|
+
expect(screen.getByText("12 m³")).toHaveClass("ObColorCard-detailValue");
|
|
30
|
+
|
|
31
|
+
rerender(<CardDetail>12 m³</CardDetail>);
|
|
32
|
+
expect(container.querySelector(".ObColorCard-detailLabel")).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
vi.hoisted(() => {
|
|
5
|
+
// The page's Appframe globals; the navigator formats dates in the user's culture.
|
|
6
|
+
(globalThis as any).af ??= { userSession: { culture: "en-GB" } };
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
import { DateNavigator } from "./index";
|
|
10
|
+
|
|
11
|
+
/** The calendar day a date the navigator hands out stands for (it hands out UTC midnights). */
|
|
12
|
+
function day(date: Date) {
|
|
13
|
+
return date.toISOString().slice(0, 10);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function lastDay(onChange: ReturnType<typeof vi.fn>) {
|
|
17
|
+
return day(onChange.mock.lastCall![0] as Date);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The date as the navigator shows it (a live region repeats it for screen readers). */
|
|
21
|
+
function shown() {
|
|
22
|
+
return document.querySelector(".ObDateNavigator-date")?.textContent;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function navigator() {
|
|
26
|
+
return screen.getByLabelText("Date navigator");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
vi.useFakeTimers({ toFake: ["Date"] });
|
|
31
|
+
vi.setSystemTime(new Date(2026, 2, 10, 12));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
vi.useRealTimers();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("DateNavigator", () => {
|
|
39
|
+
it("names today, yesterday and tomorrow", () => {
|
|
40
|
+
let { rerender } = render(<DateNavigator date={new Date(2026, 2, 10)} />);
|
|
41
|
+
expect(shown()).toBe("Today, Tue, 10 Mar 2026");
|
|
42
|
+
|
|
43
|
+
rerender(<DateNavigator date={new Date(2026, 2, 9)} />);
|
|
44
|
+
expect(shown()).toMatch(/^Yesterday, .*9 Mar 2026$/);
|
|
45
|
+
|
|
46
|
+
rerender(<DateNavigator date={new Date(2026, 2, 11)} />);
|
|
47
|
+
expect(shown()).toMatch(/^Tomorrow, .*11 Mar 2026$/);
|
|
48
|
+
|
|
49
|
+
rerender(<DateNavigator date={new Date(2026, 2, 20)} />);
|
|
50
|
+
expect(shown()).toBe("Fri, 20 Mar 2026");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("accepts the date as a string or a timestamp", () => {
|
|
54
|
+
let { rerender } = render(<DateNavigator date="2026-03-20" />);
|
|
55
|
+
expect(shown()).toMatch(/20 Mar 2026/);
|
|
56
|
+
|
|
57
|
+
rerender(<DateNavigator date={new Date(2026, 3, 1).getTime()} />);
|
|
58
|
+
expect(shown()).toMatch(/1 Apr 2026/);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("refuses a date that is not a date", () => {
|
|
62
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
63
|
+
expect(() => render(<DateNavigator date="next tuesday" />)).toThrow("Invalid date value: next tuesday");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("steps a day back and forward with the arrows", () => {
|
|
67
|
+
let onChange = vi.fn();
|
|
68
|
+
render(<DateNavigator date={new Date(2026, 2, 10)} onChange={onChange} />);
|
|
69
|
+
|
|
70
|
+
fireEvent.click(screen.getByRole("button", { name: "Previous day" }));
|
|
71
|
+
expect(lastDay(onChange)).toBe("2026-03-09");
|
|
72
|
+
|
|
73
|
+
fireEvent.click(screen.getByRole("button", { name: "Next day" }));
|
|
74
|
+
expect(lastDay(onChange)).toBe("2026-03-11");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("crosses month and year ends", () => {
|
|
78
|
+
let onChange = vi.fn();
|
|
79
|
+
render(<DateNavigator date={new Date(2025, 11, 31)} onChange={onChange} />);
|
|
80
|
+
|
|
81
|
+
fireEvent.click(screen.getByRole("button", { name: "Next day" }));
|
|
82
|
+
expect(lastDay(onChange)).toBe("2026-01-01");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("keeps its own date when the app does not control it", () => {
|
|
86
|
+
render(<DateNavigator defaultDate={new Date(2026, 2, 20)} />);
|
|
87
|
+
|
|
88
|
+
fireEvent.click(screen.getByRole("button", { name: "Next day" }));
|
|
89
|
+
fireEvent.click(screen.getByRole("button", { name: "Next day" }));
|
|
90
|
+
|
|
91
|
+
expect(shown()).toMatch(/22 Mar 2026/);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("jumps back to today", () => {
|
|
95
|
+
let onChange = vi.fn();
|
|
96
|
+
render(<DateNavigator defaultDate={new Date(2026, 0, 5)} onChange={onChange} />);
|
|
97
|
+
|
|
98
|
+
fireEvent.click(screen.getByRole("button", { name: "Today" }));
|
|
99
|
+
|
|
100
|
+
expect(onChange).toHaveBeenCalledExactlyOnceWith(new Date(2026, 2, 10, 12));
|
|
101
|
+
expect(shown()).toBe("Today, Tue, 10 Mar 2026");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("can leave out the today button", () => {
|
|
105
|
+
render(<DateNavigator disableTodayButton />);
|
|
106
|
+
expect(screen.queryByRole("button", { name: "Today" })).toBeNull();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("moves by day, week, month and year from the keyboard", () => {
|
|
110
|
+
let onChange = vi.fn();
|
|
111
|
+
render(<DateNavigator date={new Date(2026, 2, 10)} onChange={onChange} />);
|
|
112
|
+
|
|
113
|
+
fireEvent.keyDown(navigator(), { key: "ArrowLeft" });
|
|
114
|
+
expect(lastDay(onChange)).toBe("2026-03-09");
|
|
115
|
+
|
|
116
|
+
fireEvent.keyDown(navigator(), { key: "ArrowRight", shiftKey: true });
|
|
117
|
+
expect(lastDay(onChange)).toBe("2026-03-17");
|
|
118
|
+
|
|
119
|
+
fireEvent.keyDown(navigator(), { key: "ArrowLeft", ctrlKey: true });
|
|
120
|
+
expect(lastDay(onChange)).toBe("2026-02-10");
|
|
121
|
+
|
|
122
|
+
fireEvent.keyDown(navigator(), { key: "ArrowRight", ctrlKey: true, shiftKey: true });
|
|
123
|
+
expect(lastDay(onChange)).toBe("2027-03-10");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("leaves other keys and alt or meta arrows to the browser", () => {
|
|
127
|
+
let onChange = vi.fn();
|
|
128
|
+
render(<DateNavigator date={new Date(2026, 2, 10)} onChange={onChange} />);
|
|
129
|
+
|
|
130
|
+
fireEvent.keyDown(navigator(), { key: "ArrowUp" });
|
|
131
|
+
fireEvent.keyDown(navigator(), { key: "ArrowLeft", altKey: true });
|
|
132
|
+
fireEvent.keyDown(navigator(), { key: "ArrowRight", metaKey: true });
|
|
133
|
+
|
|
134
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("does not go before the first or after the last allowed day", () => {
|
|
138
|
+
let onChange = vi.fn();
|
|
139
|
+
let { rerender } = render(
|
|
140
|
+
<DateNavigator date={new Date(2026, 2, 1)} minDate={new Date(2026, 2, 1)} onChange={onChange} />,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(screen.getByRole("button", { name: "Previous day" })).toBeDisabled();
|
|
144
|
+
fireEvent.keyDown(navigator(), { key: "ArrowLeft" });
|
|
145
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
146
|
+
|
|
147
|
+
rerender(<DateNavigator date={new Date(2026, 2, 31)} maxDate={new Date(2026, 2, 31)} onChange={onChange} />);
|
|
148
|
+
expect(screen.getByRole("button", { name: "Next day" })).toBeDisabled();
|
|
149
|
+
expect(screen.getByRole("button", { name: "Previous day" })).toBeEnabled();
|
|
150
|
+
fireEvent.keyDown(navigator(), { key: "ArrowRight" });
|
|
151
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("stops a long jump at the allowed range", () => {
|
|
155
|
+
let onChange = vi.fn();
|
|
156
|
+
let minDate = new Date(2026, 2, 1);
|
|
157
|
+
let maxDate = new Date(2026, 2, 31);
|
|
158
|
+
render(<DateNavigator date={new Date(2026, 2, 15)} minDate={minDate} maxDate={maxDate} onChange={onChange} />);
|
|
159
|
+
|
|
160
|
+
fireEvent.keyDown(navigator(), { key: "ArrowLeft", ctrlKey: true });
|
|
161
|
+
expect(onChange).toHaveBeenLastCalledWith(minDate);
|
|
162
|
+
|
|
163
|
+
fireEvent.keyDown(navigator(), { key: "ArrowRight", ctrlKey: true });
|
|
164
|
+
expect(onChange).toHaveBeenLastCalledWith(maxDate);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("announces the date to screen readers", () => {
|
|
168
|
+
let { container, rerender } = render(<DateNavigator date={new Date(2026, 2, 10)} />);
|
|
169
|
+
let live = container.querySelector("[aria-live=polite]")!;
|
|
170
|
+
expect(live).toHaveTextContent("Today, Tue, 10 Mar 2026");
|
|
171
|
+
|
|
172
|
+
rerender(<DateNavigator date={new Date(2026, 2, 20)} />);
|
|
173
|
+
expect(live).toHaveTextContent("Fri, 20 Mar 2026");
|
|
174
|
+
});
|
|
175
|
+
});
|